diff --git a/CHANGELOG.md b/CHANGELOG.md index 4aafb3e58..dea91e45e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ All notable changes to Bambuddy will be documented in this file. - **Leftover Web Push code and the unused `pywebpush` dependency are gone (#3171)** — Browser push notifications were removed earlier, but the service worker still carried their push handlers and `pywebpush` was still installed, pulling in `py-vapid` and `http_ece`. Both are removed. `aiohttp` stays, now listed as the direct dependency it is for external cameras, with the same version floor. ### Fixed +- **Turning off "Check printer firmware" stops every firmware lookup** — With the setting off, opening the Printers page still asked bambulab.com once per printer: the page decided before its settings had loaded, and the server answered the request without looking at the setting. The page now waits for the setting, and the server enforces it as well, for both the per-printer and the all-printers check. The lookups could also take a long time on a fresh start (30-second timeouts with fallbacks); on a connection without HTTP/2, which includes a plain `http://` address on the local network, they could hold the browser's few connections and delay the rest of the page. - **The stream overlay's camera recovers from a frozen picture on its own (#3205, reported and contributed by @adamspicedev in #3213)** — When a printer stopped sending frames, Bambuddy ended the camera stream, but the overlay kept showing the last frame and only reconnected if the browser reported an image error, which it doesn't in that case. An unattended overlay in OBS or Meld Studio then stayed frozen until its browser source was refreshed, while the printers page, which checks the camera status, reconnected by itself. The overlay now renews its camera connection every 60 seconds, and still retries 3 seconds after an image error. A renewal joins the camera stream Bambuddy already has open for that printer and shows the latest frame at once, so a working picture doesn't flicker. The overlay URL, token, FPS and rotation are kept. With `camera=false` the overlay makes no camera requests. - **Stream overlay and Cam Wall links keep working after a reload (#3204, reported and contributed by @adamspicedev in #3212)** — Opening an `/overlay/…?token=…` or `/camwall?token=…` link treated the token as a login: Bambuddy removed it from the address bar and tried to sign in with it, which a streaming token can't do. The page worked the first time, but a reload (or an OBS or Meld browser source restarting) had no token left and stayed on **Loading…**. In a browser that was already signed in, the failed attempt also signed the user out. The token now stays in the link and is used only by the overlay or Cam Wall, and an existing login is left alone. SpoolBuddy kiosk links still sign in with their API key as before. - **The File Manager reaches the bottom of the window again (#3215, reported by @koder-guy)** — On desktop the File Manager and the G-code viewer were sized as if a 64px top bar sat above them, but that bar only exists in the mobile layout, so both pages stopped 64px short and left an empty band under the file browser. They now fill the full window height. diff --git a/backend/app/api/routes/firmware.py b/backend/app/api/routes/firmware.py index 49beb6d80..f8bbc312e 100644 --- a/backend/app/api/routes/firmware.py +++ b/backend/app/api/routes/firmware.py @@ -16,6 +16,7 @@ from backend.app.core.auth import RequirePermissionIfAuthEnabled from backend.app.core.database import get_db from backend.app.core.permissions import Permission from backend.app.models.printer import Printer +from backend.app.models.settings import Settings from backend.app.models.user import User from backend.app.services.firmware_check import get_firmware_service from backend.app.services.firmware_update import ( @@ -70,6 +71,37 @@ class LatestFirmwareInfo(BaseModel): release_notes: str | None = None +async def _checks_enabled(db: AsyncSession) -> bool: + """The "Check printer firmware" setting (default on). + + Enforced here and not only in the UI: the printers page asks before its + settings have loaded, so a check switched off still went out to bambulab.com + once per printer on every page load. + """ + value = ( + await db.execute(select(Settings.value).where(Settings.key == "check_printer_firmware")) + ).scalar_one_or_none() + return (value or "true").lower() != "false" + + +def _current_version(printer_id: int) -> str | None: + mqtt_client = printer_manager.get_client(printer_id) + if mqtt_client and mqtt_client.state: + return mqtt_client.state.firmware_version + return None + + +def _not_checked(printer: Printer) -> FirmwareUpdateInfo: + return FirmwareUpdateInfo( + printer_id=printer.id, + printer_name=printer.name, + model=printer.model or "Unknown", + current_version=_current_version(printer.id), + latest_version=None, + update_available=False, + ) + + @router.get("/updates", response_model=FirmwareUpdatesResponse) async def check_firmware_updates( db: AsyncSession = Depends(get_db), @@ -90,6 +122,9 @@ async def check_firmware_updates( result = await db.execute(select(Printer).where(Printer.is_active.is_(True))) printers = result.scalars().all() + if not await _checks_enabled(db): + return FirmwareUpdatesResponse(updates=[_not_checked(p) for p in printers], updates_available=0) + updates = [] updates_available = 0 @@ -142,11 +177,10 @@ async def check_printer_firmware( if not printer: raise HTTPException(status_code=404, detail="Printer not found") - # Get current firmware version from MQTT state - current_version = None - mqtt_client = printer_manager.get_client(printer.id) - if mqtt_client and mqtt_client.state: - current_version = mqtt_client.state.firmware_version + if not await _checks_enabled(db): + return _not_checked(printer) + + current_version = _current_version(printer.id) # Check for update model = printer.model or "Unknown" diff --git a/backend/tests/integration/test_firmware_check_setting.py b/backend/tests/integration/test_firmware_check_setting.py new file mode 100644 index 000000000..d85b14252 --- /dev/null +++ b/backend/tests/integration/test_firmware_check_setting.py @@ -0,0 +1,78 @@ +"""The "Check printer firmware" setting is enforced by the API, not only the UI. + +The printers page asked before its settings had loaded, so with the check +switched off Bambuddy still went out to bambulab.com once per printer on every +page load. Off has to mean no request at all. +""" + +from unittest.mock import AsyncMock, MagicMock, patch + +import pytest +from httpx import AsyncClient + +from backend.app.models.settings import Settings + +UPDATE = { + "update_available": True, + "latest_version": "01.09.00.00", + "download_url": "https://example.com/fw.bin", + "release_notes": None, + "available_versions": [], +} + + +def _service() -> MagicMock: + service = MagicMock() + service.check_for_update = AsyncMock(return_value=UPDATE) + return service + + +async def _switch_off(db) -> None: + db.add(Settings(key="check_printer_firmware", value="false")) + await db.commit() + + +@pytest.mark.integration +class TestFirmwareCheckSetting: + @pytest.mark.asyncio + async def test_on_by_default(self, async_client: AsyncClient, printer_factory): + printer = await printer_factory() + service = _service() + with patch("backend.app.api.routes.firmware.get_firmware_service", return_value=service): + r = await async_client.get(f"/api/v1/firmware/updates/{printer.id}") + assert r.status_code == 200, r.text + assert r.json()["update_available"] is True + service.check_for_update.assert_awaited_once() + + @pytest.mark.asyncio + async def test_off_asks_nobody(self, async_client: AsyncClient, db_session, printer_factory): + printer = await printer_factory(name="Garage") + await _switch_off(db_session) + service = _service() + with patch("backend.app.api.routes.firmware.get_firmware_service", return_value=service): + r = await async_client.get(f"/api/v1/firmware/updates/{printer.id}") + assert r.status_code == 200, r.text + body = r.json() + assert body["printer_id"] == printer.id and body["printer_name"] == "Garage" + assert body["update_available"] is False and body["latest_version"] is None + service.check_for_update.assert_not_called() + + @pytest.mark.asyncio + async def test_off_still_404s_an_unknown_printer(self, async_client: AsyncClient, db_session): + await _switch_off(db_session) + assert (await async_client.get("/api/v1/firmware/updates/9999")).status_code == 404 + + @pytest.mark.asyncio + async def test_off_covers_the_all_printers_check(self, async_client: AsyncClient, db_session, printer_factory): + await printer_factory() + await printer_factory() + await _switch_off(db_session) + service = _service() + with patch("backend.app.api.routes.firmware.get_firmware_service", return_value=service): + r = await async_client.get("/api/v1/firmware/updates") + assert r.status_code == 200, r.text + body = r.json() + assert body["updates_available"] == 0 + assert len(body["updates"]) == 2 + assert all(u["update_available"] is False for u in body["updates"]) + service.check_for_update.assert_not_called() diff --git a/frontend/src/__tests__/pages/PrintersPage.test.tsx b/frontend/src/__tests__/pages/PrintersPage.test.tsx index cbe1b75e0..f07a42814 100644 --- a/frontend/src/__tests__/pages/PrintersPage.test.tsx +++ b/frontend/src/__tests__/pages/PrintersPage.test.tsx @@ -1036,6 +1036,36 @@ describe('PrintersPage', () => { expect(screen.queryByText('01.08.00.00')).not.toBeInTheDocument(); }); + it('never asks for firmware when the check is off, not even before preferences load', async () => { + // The page used to decide on `undefined` while the preferences were still + // loading, so a check switched off still went out once per printer. + let firmwareRequests = 0; + let releasePreferences: () => void = () => {}; + const preferencesHeld = new Promise((resolve) => { + releasePreferences = resolve; + }); + server.use( + http.get('/api/v1/firmware/updates/:id', () => { + firmwareRequests += 1; + return HttpResponse.json(firmwareUpdateAvailable); + }), + http.get('/api/v1/settings/ui-preferences', async () => { + await preferencesHeld; + return HttpResponse.json({ check_printer_firmware: false }); + }) + ); + + render(); + + await waitFor(() => { + expect(screen.getByText('X1 Carbon')).toBeInTheDocument(); + }); + releasePreferences(); + // Long enough for a query that was going to fire to have fired. + await new Promise((resolve) => setTimeout(resolve, 100)); + expect(firmwareRequests).toBe(0); + }); + it('hides badge when API has no firmware data for the model', async () => { const firmwareNoData = { printer_id: 1, diff --git a/frontend/src/pages/PrintersPage.tsx b/frontend/src/pages/PrintersPage.tsx index e60da51c2..9eb1c3d5e 100644 --- a/frontend/src/pages/PrintersPage.tsx +++ b/frontend/src/pages/PrintersPage.tsx @@ -8915,6 +8915,9 @@ export function PrintersPage() { queryKey: ['ui-preferences'], queryFn: api.getUiPreferences, }); + // Only once the preferences are in: deciding on `undefined` meant a check + // switched off still went out once per printer on every page load. + const firmwareChecksOn = settings !== undefined && settings.check_printer_firmware !== false; // Parse user-configured temperature/fan presets once, with defensive fallback // to built-in defaults on parse failure (validators on the backend already @@ -9969,7 +9972,7 @@ export function PrintersPage() { cameraViewMode={cameraViewMode} onOpenEmbeddedCamera={(id, name) => setEmbeddedCameraPrinters(prev => new Map(prev).set(id, { id, name }))} onSelectCameraViewMode={selectCameraViewMode} - checkPrinterFirmware={settings?.check_printer_firmware !== false} + checkPrinterFirmware={firmwareChecksOn} dryingPresets={effectiveDryingPresets} nozzleTempPresets={effectiveNozzleTempPresets} bedTempPresets={effectiveBedTempPresets} @@ -10022,7 +10025,7 @@ export function PrintersPage() { cameraViewMode={cameraViewMode} onOpenEmbeddedCamera={(id, name) => setEmbeddedCameraPrinters(prev => new Map(prev).set(id, { id, name }))} onSelectCameraViewMode={selectCameraViewMode} - checkPrinterFirmware={settings?.check_printer_firmware !== false} + checkPrinterFirmware={firmwareChecksOn} dryingPresets={effectiveDryingPresets} nozzleTempPresets={effectiveNozzleTempPresets} bedTempPresets={effectiveBedTempPresets} diff --git a/static/assets/ImagePreviewModal-C-WFsOtq.js b/static/assets/ImagePreviewModal-DRfunMYn.js similarity index 98% rename from static/assets/ImagePreviewModal-C-WFsOtq.js rename to static/assets/ImagePreviewModal-DRfunMYn.js index 269d5edac..595afeb1f 100644 --- a/static/assets/ImagePreviewModal-C-WFsOtq.js +++ b/static/assets/ImagePreviewModal-DRfunMYn.js @@ -1 +1 @@ -import{i as e}from"./chunk-aKtaBQYM.js";import{a as t,c as n,d as r,g as i,i as a,l as o,n as s,o as c,r as l,s as u,t as d,u as f,v as p,y as m}from"./index-Bc3Y2a4o.js";var h=e(m(),1),g=i(),_=.4,v=8,y=1.25,b=30,x=Math.log(y)/b,S=e=>Math.min(v,Math.max(_,e)),C={x:0,y:0};function w(e){return e.deltaMode===1?e.deltaY*16:e.deltaMode===2?e.deltaY*100:e.deltaY}function T({libraryFileId:e,filename:i,fileSize:m,onClose:_}){let{t:v}=p(),T=d(),{isFullscreen:E,toggleFullscreen:D}=T,O=(0,h.useRef)(null),k=(0,h.useRef)(null),[A,j]=(0,h.useState)(null),[M,N]=(0,h.useState)(!1),[P,F]=(0,h.useState)(null),[I,L]=(0,h.useState)(1),[R,z]=(0,h.useState)(C),[B,V]=(0,h.useState)(!1),H=(0,h.useRef)(1),U=(0,h.useRef)(C),W=(0,h.useRef)(new Map),G=(0,h.useRef)(null),K=(0,h.useCallback)((e,t)=>{let n=O.current,r=k.current;if(!n||!r)return e;let i=Math.max(0,(r.offsetWidth*t-n.clientWidth)/2),a=Math.max(0,(r.offsetHeight*t-n.clientHeight)/2);return{x:Math.min(i,Math.max(-i,e.x)),y:Math.min(a,Math.max(-a,e.y))}},[]),q=(0,h.useCallback)((e,t)=>{H.current=e,U.current=t,L(e),z(t)},[]),J=(0,h.useCallback)((e,t,n)=>{let r=H.current,i=S(r*e);if(i===r)return;let a=O.current,o=U.current,s={x:o.x*(i/r),y:o.y*(i/r)};if(a){let e=a.getBoundingClientRect(),c=(t??e.left+e.width/2)-(e.left+e.width/2),l=(n??e.top+e.height/2)-(e.top+e.height/2),u=i/r;s={x:c-(c-o.x)*u,y:l-(l-o.y)*u}}q(i,K(s,i))},[K,q]),Y=(0,h.useCallback)(()=>q(1,C),[q]);(0,h.useEffect)(()=>{let n=!1,r=null;if(j(null),N(!1),F(null),q(1,C),m>52428800){F(v(`fileManager.preview.tooLarge`,{size:a(m)}));return}let i={},o=c();return o&&(i.Authorization=`Bearer ${o}`),(async()=>{let a=await fetch(t.getLibraryFileDownloadUrl(e),{headers:i});if(!a.ok)throw Error(`HTTP ${a.status}`);let o=await a.blob();n||(r=URL.createObjectURL(o),j(r))})().catch(e=>{console.error(`[image-preview] load failed`,e),n||F(v(`fileManager.preview.error`))}),()=>{n=!0,r&&URL.revokeObjectURL(r)}},[e,m,v,q]),(0,h.useEffect)(()=>{let e=e=>{e.ctrlKey||e.metaKey||e.altKey||(e.key===`+`||e.key===`=`?(e.preventDefault(),J(y)):e.key===`-`?(e.preventDefault(),J(1/y)):e.key===`0`&&(e.preventDefault(),Y()))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[Y,J]),(0,h.useEffect)(()=>{let e=O.current;if(!e)return;let t=e=>{e.preventDefault();let t=Math.max(-30,Math.min(b,w(e)));J(Math.exp(-t*x),e.clientX,e.clientY)};return e.addEventListener(`wheel`,t,{passive:!1}),()=>e.removeEventListener(`wheel`,t)},[J,A]);let X=e=>{W.current.set(e.pointerId,{x:e.clientX,y:e.clientY}),G.current=null,W.current.size===1&&H.current>1&&(e.currentTarget.setPointerCapture(e.pointerId),V(!0))},Z=e=>{W.current.delete(e.pointerId),G.current=null,W.current.size===0&&V(!1)},Q=e=>{let t=W.current,n=t.get(e.pointerId);if(!n)return;if(e.pointerType===`mouse`&&e.buttons===0){Z(e);return}if(t.set(e.pointerId,{x:e.clientX,y:e.clientY}),t.size===1){if(H.current<=1)return;let t={x:U.current.x+(e.clientX-n.x),y:U.current.y+(e.clientY-n.y)};q(H.current,K(t,H.current));return}if(t.size!==2)return;let[r,i]=Array.from(t.values()),a=Math.hypot(r.x-i.x,r.y-i.y),o=G.current;G.current=a,o!=null&&o>0&&a>0&&J(a/o,(r.x+i.x)/2,(r.y+i.y)/2)},$=I>1;return(0,g.jsx)(s,{title:i,fullscreen:T,onClose:_,icon:(0,g.jsx)(r,{className:`w-5 h-5 text-bambu-green flex-shrink-0`}),actions:A?(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(`button`,{onClick:()=>J(1/y),className:l,"aria-label":v(`fileManager.preview.zoomOut`),children:(0,g.jsx)(u,{className:`w-4 h-4`})}),(0,g.jsx)(`button`,{onClick:()=>J(y),className:l,"aria-label":v(`fileManager.preview.zoomIn`),children:(0,g.jsx)(n,{className:`w-4 h-4`})}),(0,g.jsx)(`button`,{onClick:Y,className:l,"aria-label":v(`fileManager.preview.resetZoom`),children:(0,g.jsx)(o,{className:`w-4 h-4`})})]}):void 0,children:(0,g.jsx)(`div`,{ref:O,"data-testid":`image-preview-content`,className:`relative flex-1 min-h-0 overflow-hidden bg-bambu-dark flex items-center justify-center touch-none ${E?``:`rounded-b-lg`} ${$?B?`cursor-grabbing`:`cursor-grab`:``}`,onDoubleClick:D,onPointerDown:X,onPointerMove:Q,onPointerUp:Z,onPointerCancel:Z,onPointerLeave:Z,children:P?(0,g.jsx)(`p`,{className:`text-bambu-gray text-center p-6`,children:P}):(0,g.jsxs)(g.Fragment,{children:[A&&(0,g.jsx)(`img`,{ref:k,src:A,alt:i,draggable:!1,onLoad:()=>N(!0),onError:()=>F(v(`fileManager.preview.error`)),style:{transform:`translate(${R.x}px, ${R.y}px) scale(${I})`},className:`max-w-full max-h-full object-contain select-none`}),!M&&(0,g.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center pointer-events-none`,children:(0,g.jsx)(f,{className:`w-8 h-8 text-bambu-green animate-spin`})})]})})})}export{T as ImagePreviewModal}; \ No newline at end of file +import{i as e}from"./chunk-aKtaBQYM.js";import{a as t,c as n,d as r,g as i,i as a,l as o,n as s,o as c,r as l,s as u,t as d,u as f,v as p,y as m}from"./index-7qfiHY5t.js";var h=e(m(),1),g=i(),_=.4,v=8,y=1.25,b=30,x=Math.log(y)/b,S=e=>Math.min(v,Math.max(_,e)),C={x:0,y:0};function w(e){return e.deltaMode===1?e.deltaY*16:e.deltaMode===2?e.deltaY*100:e.deltaY}function T({libraryFileId:e,filename:i,fileSize:m,onClose:_}){let{t:v}=p(),T=d(),{isFullscreen:E,toggleFullscreen:D}=T,O=(0,h.useRef)(null),k=(0,h.useRef)(null),[A,j]=(0,h.useState)(null),[M,N]=(0,h.useState)(!1),[P,F]=(0,h.useState)(null),[I,L]=(0,h.useState)(1),[R,z]=(0,h.useState)(C),[B,V]=(0,h.useState)(!1),H=(0,h.useRef)(1),U=(0,h.useRef)(C),W=(0,h.useRef)(new Map),G=(0,h.useRef)(null),K=(0,h.useCallback)((e,t)=>{let n=O.current,r=k.current;if(!n||!r)return e;let i=Math.max(0,(r.offsetWidth*t-n.clientWidth)/2),a=Math.max(0,(r.offsetHeight*t-n.clientHeight)/2);return{x:Math.min(i,Math.max(-i,e.x)),y:Math.min(a,Math.max(-a,e.y))}},[]),q=(0,h.useCallback)((e,t)=>{H.current=e,U.current=t,L(e),z(t)},[]),J=(0,h.useCallback)((e,t,n)=>{let r=H.current,i=S(r*e);if(i===r)return;let a=O.current,o=U.current,s={x:o.x*(i/r),y:o.y*(i/r)};if(a){let e=a.getBoundingClientRect(),c=(t??e.left+e.width/2)-(e.left+e.width/2),l=(n??e.top+e.height/2)-(e.top+e.height/2),u=i/r;s={x:c-(c-o.x)*u,y:l-(l-o.y)*u}}q(i,K(s,i))},[K,q]),Y=(0,h.useCallback)(()=>q(1,C),[q]);(0,h.useEffect)(()=>{let n=!1,r=null;if(j(null),N(!1),F(null),q(1,C),m>52428800){F(v(`fileManager.preview.tooLarge`,{size:a(m)}));return}let i={},o=c();return o&&(i.Authorization=`Bearer ${o}`),(async()=>{let a=await fetch(t.getLibraryFileDownloadUrl(e),{headers:i});if(!a.ok)throw Error(`HTTP ${a.status}`);let o=await a.blob();n||(r=URL.createObjectURL(o),j(r))})().catch(e=>{console.error(`[image-preview] load failed`,e),n||F(v(`fileManager.preview.error`))}),()=>{n=!0,r&&URL.revokeObjectURL(r)}},[e,m,v,q]),(0,h.useEffect)(()=>{let e=e=>{e.ctrlKey||e.metaKey||e.altKey||(e.key===`+`||e.key===`=`?(e.preventDefault(),J(y)):e.key===`-`?(e.preventDefault(),J(1/y)):e.key===`0`&&(e.preventDefault(),Y()))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[Y,J]),(0,h.useEffect)(()=>{let e=O.current;if(!e)return;let t=e=>{e.preventDefault();let t=Math.max(-30,Math.min(b,w(e)));J(Math.exp(-t*x),e.clientX,e.clientY)};return e.addEventListener(`wheel`,t,{passive:!1}),()=>e.removeEventListener(`wheel`,t)},[J,A]);let X=e=>{W.current.set(e.pointerId,{x:e.clientX,y:e.clientY}),G.current=null,W.current.size===1&&H.current>1&&(e.currentTarget.setPointerCapture(e.pointerId),V(!0))},Z=e=>{W.current.delete(e.pointerId),G.current=null,W.current.size===0&&V(!1)},Q=e=>{let t=W.current,n=t.get(e.pointerId);if(!n)return;if(e.pointerType===`mouse`&&e.buttons===0){Z(e);return}if(t.set(e.pointerId,{x:e.clientX,y:e.clientY}),t.size===1){if(H.current<=1)return;let t={x:U.current.x+(e.clientX-n.x),y:U.current.y+(e.clientY-n.y)};q(H.current,K(t,H.current));return}if(t.size!==2)return;let[r,i]=Array.from(t.values()),a=Math.hypot(r.x-i.x,r.y-i.y),o=G.current;G.current=a,o!=null&&o>0&&a>0&&J(a/o,(r.x+i.x)/2,(r.y+i.y)/2)},$=I>1;return(0,g.jsx)(s,{title:i,fullscreen:T,onClose:_,icon:(0,g.jsx)(r,{className:`w-5 h-5 text-bambu-green flex-shrink-0`}),actions:A?(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(`button`,{onClick:()=>J(1/y),className:l,"aria-label":v(`fileManager.preview.zoomOut`),children:(0,g.jsx)(u,{className:`w-4 h-4`})}),(0,g.jsx)(`button`,{onClick:()=>J(y),className:l,"aria-label":v(`fileManager.preview.zoomIn`),children:(0,g.jsx)(n,{className:`w-4 h-4`})}),(0,g.jsx)(`button`,{onClick:Y,className:l,"aria-label":v(`fileManager.preview.resetZoom`),children:(0,g.jsx)(o,{className:`w-4 h-4`})})]}):void 0,children:(0,g.jsx)(`div`,{ref:O,"data-testid":`image-preview-content`,className:`relative flex-1 min-h-0 overflow-hidden bg-bambu-dark flex items-center justify-center touch-none ${E?``:`rounded-b-lg`} ${$?B?`cursor-grabbing`:`cursor-grab`:``}`,onDoubleClick:D,onPointerDown:X,onPointerMove:Q,onPointerUp:Z,onPointerCancel:Z,onPointerLeave:Z,children:P?(0,g.jsx)(`p`,{className:`text-bambu-gray text-center p-6`,children:P}):(0,g.jsxs)(g.Fragment,{children:[A&&(0,g.jsx)(`img`,{ref:k,src:A,alt:i,draggable:!1,onLoad:()=>N(!0),onError:()=>F(v(`fileManager.preview.error`)),style:{transform:`translate(${R.x}px, ${R.y}px) scale(${I})`},className:`max-w-full max-h-full object-contain select-none`}),!M&&(0,g.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center pointer-events-none`,children:(0,g.jsx)(f,{className:`w-8 h-8 text-bambu-green animate-spin`})})]})})})}export{T as ImagePreviewModal}; \ No newline at end of file diff --git a/static/assets/PdfPreviewModal-AgMs-G9b.js b/static/assets/PdfPreviewModal-C4ar5SVt.js similarity index 97% rename from static/assets/PdfPreviewModal-AgMs-G9b.js rename to static/assets/PdfPreviewModal-C4ar5SVt.js index 8c03d1810..0fe0db8af 100644 --- a/static/assets/PdfPreviewModal-AgMs-G9b.js +++ b/static/assets/PdfPreviewModal-C4ar5SVt.js @@ -1,2 +1,2 @@ -const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/pdf-4oiL9bye.js","assets/index-Bc3Y2a4o.js","assets/chunk-aKtaBQYM.js","assets/index-CyW_3l56.css"])))=>i.map(i=>d[i]); -import{i as e}from"./chunk-aKtaBQYM.js";import{_ as t,a as n,c as r,f as i,g as a,h as o,i as s,m as c,n as l,o as u,r as d,s as ee,t as te,u as ne,v as re,y as f}from"./index-Bc3Y2a4o.js";var p=e(f(),1),m=a(),h=.4,g=4,_=1.25,v=30,ie=Math.log(_)/v,ae=150,y=16*1024*1024,b=`/assets/pdfjs/`,oe=e=>Math.min(g,Math.max(h,e));function x(e){let t=document.createElement(`canvas`);t.width=256,t.height=256;let n=t.getContext(`2d`);if(!n)return Promise.resolve(null);n.fillStyle=`#ffffff`,n.fillRect(0,0,256,256);let r=256/Math.max(e.width,e.height),i=e.width*r,a=e.height*r;return n.drawImage(e,(256-i)/2,(256-a)/2,i,a),new Promise(e=>t.toBlob(e,`image/png`))}function S(e){return e.deltaMode===1?e.deltaY*16:e.deltaMode===2?e.deltaY*100:e.deltaY}function C({libraryFileId:e,filename:a,fileSize:f,onClose:h,onSnapshot:g}){let{t:C}=re(),w=te(),{panelRef:T,isFullscreen:E,toggleFullscreen:D}=w,O=(0,p.useRef)(null),k=(0,p.useRef)(null),A=(0,p.useRef)(null),j=(0,p.useRef)(!1),M=(0,p.useRef)(g);(0,p.useEffect)(()=>{M.current=g});let[N,P]=(0,p.useState)(null),[F,I]=(0,p.useState)(1),[L,R]=(0,p.useState)(1),[z,se]=(0,p.useState)(1),[B,ce]=(0,p.useState)(0),[V,H]=(0,p.useState)(null),[U,W]=(0,p.useState)(!0),G=(0,p.useRef)(L),K=(0,p.useRef)(null),q=(0,p.useRef)(null),J=(0,p.useRef)(new Map),Y=(0,p.useRef)(null),X=(0,p.useCallback)((e,t,n)=>{let r=O.current,i=k.current;if(r&&i){let e=r.getBoundingClientRect(),a=i.getBoundingClientRect(),o=t==null?e.width/2:t-e.left,s=n==null?e.height/2:n-e.top;q.current=a.width>0&&a.height>0?{fx:(o+e.left-a.left)/a.width,fy:(s+e.top-a.top)/a.height,px:o,py:s}:null}R(t=>oe(t*e))},[]);(0,p.useEffect)(()=>{let e=e=>{e.ctrlKey||e.metaKey||e.altKey||(e.key===`+`||e.key===`=`?(e.preventDefault(),X(_)):e.key===`-`?(e.preventDefault(),X(1/_)):e.key===`0`&&(e.preventDefault(),q.current=null,R(1)))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[X]),(0,p.useEffect)(()=>{let e=O.current;if(!e)return;let t=t=>{if(!k.current||!K.current||!(t.ctrlKey||t.metaKey)&&!(e.scrollHeight<=e.clientHeight&&e.scrollWidth<=e.clientWidth))return;t.preventDefault();let n=Math.max(-30,Math.min(v,S(t)));X(Math.exp(-n*ie),t.clientX,t.clientY)};return e.addEventListener(`wheel`,t,{passive:!1}),()=>e.removeEventListener(`wheel`,t)},[X]);let le=e=>{e.pointerType===`touch`&&(J.current.set(e.pointerId,{x:e.clientX,y:e.clientY}),Y.current=null)},ue=e=>{if(e.pointerType!==`touch`)return;let t=J.current,n=t.get(e.pointerId);if(!n)return;if(t.set(e.pointerId,{x:e.clientX,y:e.clientY}),t.size===1){let t=O.current;t&&(t.scrollLeft-=e.clientX-n.x,t.scrollTop-=e.clientY-n.y);return}if(t.size!==2)return;let[r,i]=Array.from(t.values()),a=Math.hypot(r.x-i.x,r.y-i.y),o=Y.current;Y.current=a,o!=null&&o>0&&a>0&&X(a/o,(r.x+i.x)/2,(r.y+i.y)/2)},Z=e=>{e.pointerType===`touch`&&(J.current.delete(e.pointerId),Y.current=null)};(0,p.useLayoutEffect)(()=>{G.current=L;let e=k.current,t=O.current,n=K.current;if(!e||!t||!n)return;e.style.width=`${n.width*L}px`,e.style.height=`${n.height*L}px`;let r=q.current;q.current=null,r&&(t.scrollLeft=e.offsetLeft+r.fx*e.offsetWidth-r.px,t.scrollTop=e.offsetTop+r.fy*e.offsetHeight-r.py)},[L]),(0,p.useEffect)(()=>{if(L===z)return;let e=window.setTimeout(()=>se(L),ae);return()=>window.clearTimeout(e)},[L,z]),(0,p.useEffect)(()=>{let e=T.current;if(!e)return;let t=new ResizeObserver(()=>ce(e=>e+1));return t.observe(e),()=>t.disconnect()},[T]),(0,p.useEffect)(()=>{let r=!1,i=null;if(P(null),H(null),I(1),W(!0),f>52428800){H(C(`fileManager.preview.tooLarge`,{size:s(f)})),W(!1);return}let a={},o=u();return o&&(a.Authorization=`Bearer ${o}`),(async()=>{let o=await fetch(n.getLibraryFileDownloadUrl(e),{headers:a});if(!o.ok)throw Error(`HTTP ${o.status}`);let s=await o.arrayBuffer(),c=await t(()=>import(`./pdf-4oiL9bye.js`),__vite__mapDeps([0,1,2,3]));if(c.GlobalWorkerOptions.workerSrc||(c.GlobalWorkerOptions.workerSrc=(await t(async()=>{let{default:e}=await import(`./pdf.worker.min-DpOxPwGP.js`);return{default:e}},[])).default),i=c.getDocument({data:new Uint8Array(s),cMapUrl:`${b}cmaps/`,iccUrl:`${b}iccs/`,standardFontDataUrl:`${b}standard_fonts/`,wasmUrl:`${b}wasm/`}),r){i.destroy();return}let l=await i.promise;r||P(l)})().catch(e=>{console.error(`[pdf-preview] load failed`,e),r||(H(C(`fileManager.preview.error`)),W(!1))}),()=>{r=!0,A.current?.cancel(),A.current=null,i?.destroy()}},[e,f,C]),(0,p.useEffect)(()=>{if(!N)return;let e=!1;return W(!0),(async()=>{let t=await N.getPage(F),n=k.current,r=O.current;if(!n||!r||e)return;let i=t.getViewport({scale:1}),a=Math.max((r.clientWidth-32)/i.width,.1),o=Math.min(window.devicePixelRatio||1,2),s=a*z*o,c=i.width*s*(i.height*s),l=c>y?s*Math.sqrt(y/c):s,u=t.getViewport({scale:l});n.width=u.width,n.height=u.height,K.current={width:i.width*a,height:i.height*a},n.style.width=`${K.current.width*G.current}px`,n.style.height=`${K.current.height*G.current}px`,A.current?.cancel();let d=t.render({canvas:n,viewport:u});if(A.current=d,await d.promise,!e&&(W(!1),F===1&&M.current&&!j.current)){j.current=!0;let t=await x(n);t&&!e&&M.current?.(t)}})().catch(t=>{!e&&t?.name!==`RenderingCancelledException`&&(console.error(`[pdf-preview] render failed`,t),H(C(`fileManager.preview.error`)),W(!1))}),()=>{e=!0}},[N,F,z,B,C]);let Q=N?.numPages??0,$=d;return(0,m.jsx)(l,{title:a,fullscreen:w,onClose:h,icon:(0,m.jsx)(i,{className:`w-5 h-5 text-bambu-green flex-shrink-0`}),actions:(0,m.jsxs)(m.Fragment,{children:[N&&Q>1&&(0,m.jsxs)(`div`,{className:`flex items-center gap-1 mr-2`,children:[(0,m.jsx)(`button`,{onClick:()=>I(e=>Math.max(1,e-1)),disabled:F<=1,className:`${$} disabled:opacity-40 disabled:cursor-not-allowed`,"aria-label":C(`fileManager.preview.prevPage`),children:(0,m.jsx)(c,{className:`w-4 h-4`})}),(0,m.jsx)(`span`,{className:`text-sm text-bambu-gray whitespace-nowrap`,children:C(`fileManager.preview.page`,{current:F,total:Q})}),(0,m.jsx)(`button`,{onClick:()=>I(e=>Math.min(Q,e+1)),disabled:F>=Q,className:`${$} disabled:opacity-40 disabled:cursor-not-allowed`,"aria-label":C(`fileManager.preview.nextPage`),children:(0,m.jsx)(o,{className:`w-4 h-4`})})]}),N&&(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(`button`,{onClick:()=>X(1/_),className:$,"aria-label":C(`fileManager.preview.zoomOut`),children:(0,m.jsx)(ee,{className:`w-4 h-4`})}),(0,m.jsx)(`button`,{onClick:()=>X(_),className:$,"aria-label":C(`fileManager.preview.zoomIn`),children:(0,m.jsx)(r,{className:`w-4 h-4`})})]})]}),children:(0,m.jsxs)(`div`,{ref:O,"data-testid":`pdf-preview-page`,className:`relative flex-1 min-h-0 overflow-auto bg-bambu-dark p-4 touch-none ${E?``:`rounded-b-lg`}`,onDoubleClick:D,onPointerDown:le,onPointerMove:ue,onPointerUp:Z,onPointerCancel:Z,onPointerLeave:Z,children:[V?(0,m.jsx)(`div`,{className:`h-full flex items-center justify-center`,children:(0,m.jsx)(`p`,{className:`text-bambu-gray text-center`,children:V})}):(0,m.jsx)(`div`,{className:`flex justify-center min-w-fit`,children:(0,m.jsx)(`canvas`,{ref:k,className:`shadow-lg`})}),!V&&U&&(0,m.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center pointer-events-none`,children:(0,m.jsx)(ne,{className:`w-8 h-8 text-bambu-green animate-spin`})})]})})}export{C as PdfPreviewModal}; \ No newline at end of file +const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/pdf-DG3KNKaP.js","assets/index-7qfiHY5t.js","assets/chunk-aKtaBQYM.js","assets/index-CyW_3l56.css"])))=>i.map(i=>d[i]); +import{i as e}from"./chunk-aKtaBQYM.js";import{_ as t,a as n,c as r,f as i,g as a,h as o,i as s,m as c,n as l,o as u,r as d,s as ee,t as te,u as ne,v as re,y as f}from"./index-7qfiHY5t.js";var p=e(f(),1),m=a(),h=.4,g=4,_=1.25,v=30,ie=Math.log(_)/v,ae=150,y=16*1024*1024,b=`/assets/pdfjs/`,oe=e=>Math.min(g,Math.max(h,e));function x(e){let t=document.createElement(`canvas`);t.width=256,t.height=256;let n=t.getContext(`2d`);if(!n)return Promise.resolve(null);n.fillStyle=`#ffffff`,n.fillRect(0,0,256,256);let r=256/Math.max(e.width,e.height),i=e.width*r,a=e.height*r;return n.drawImage(e,(256-i)/2,(256-a)/2,i,a),new Promise(e=>t.toBlob(e,`image/png`))}function S(e){return e.deltaMode===1?e.deltaY*16:e.deltaMode===2?e.deltaY*100:e.deltaY}function C({libraryFileId:e,filename:a,fileSize:f,onClose:h,onSnapshot:g}){let{t:C}=re(),w=te(),{panelRef:T,isFullscreen:E,toggleFullscreen:D}=w,O=(0,p.useRef)(null),k=(0,p.useRef)(null),A=(0,p.useRef)(null),j=(0,p.useRef)(!1),M=(0,p.useRef)(g);(0,p.useEffect)(()=>{M.current=g});let[N,P]=(0,p.useState)(null),[F,I]=(0,p.useState)(1),[L,R]=(0,p.useState)(1),[z,se]=(0,p.useState)(1),[B,ce]=(0,p.useState)(0),[V,H]=(0,p.useState)(null),[U,W]=(0,p.useState)(!0),G=(0,p.useRef)(L),K=(0,p.useRef)(null),q=(0,p.useRef)(null),J=(0,p.useRef)(new Map),Y=(0,p.useRef)(null),X=(0,p.useCallback)((e,t,n)=>{let r=O.current,i=k.current;if(r&&i){let e=r.getBoundingClientRect(),a=i.getBoundingClientRect(),o=t==null?e.width/2:t-e.left,s=n==null?e.height/2:n-e.top;q.current=a.width>0&&a.height>0?{fx:(o+e.left-a.left)/a.width,fy:(s+e.top-a.top)/a.height,px:o,py:s}:null}R(t=>oe(t*e))},[]);(0,p.useEffect)(()=>{let e=e=>{e.ctrlKey||e.metaKey||e.altKey||(e.key===`+`||e.key===`=`?(e.preventDefault(),X(_)):e.key===`-`?(e.preventDefault(),X(1/_)):e.key===`0`&&(e.preventDefault(),q.current=null,R(1)))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[X]),(0,p.useEffect)(()=>{let e=O.current;if(!e)return;let t=t=>{if(!k.current||!K.current||!(t.ctrlKey||t.metaKey)&&!(e.scrollHeight<=e.clientHeight&&e.scrollWidth<=e.clientWidth))return;t.preventDefault();let n=Math.max(-30,Math.min(v,S(t)));X(Math.exp(-n*ie),t.clientX,t.clientY)};return e.addEventListener(`wheel`,t,{passive:!1}),()=>e.removeEventListener(`wheel`,t)},[X]);let le=e=>{e.pointerType===`touch`&&(J.current.set(e.pointerId,{x:e.clientX,y:e.clientY}),Y.current=null)},ue=e=>{if(e.pointerType!==`touch`)return;let t=J.current,n=t.get(e.pointerId);if(!n)return;if(t.set(e.pointerId,{x:e.clientX,y:e.clientY}),t.size===1){let t=O.current;t&&(t.scrollLeft-=e.clientX-n.x,t.scrollTop-=e.clientY-n.y);return}if(t.size!==2)return;let[r,i]=Array.from(t.values()),a=Math.hypot(r.x-i.x,r.y-i.y),o=Y.current;Y.current=a,o!=null&&o>0&&a>0&&X(a/o,(r.x+i.x)/2,(r.y+i.y)/2)},Z=e=>{e.pointerType===`touch`&&(J.current.delete(e.pointerId),Y.current=null)};(0,p.useLayoutEffect)(()=>{G.current=L;let e=k.current,t=O.current,n=K.current;if(!e||!t||!n)return;e.style.width=`${n.width*L}px`,e.style.height=`${n.height*L}px`;let r=q.current;q.current=null,r&&(t.scrollLeft=e.offsetLeft+r.fx*e.offsetWidth-r.px,t.scrollTop=e.offsetTop+r.fy*e.offsetHeight-r.py)},[L]),(0,p.useEffect)(()=>{if(L===z)return;let e=window.setTimeout(()=>se(L),ae);return()=>window.clearTimeout(e)},[L,z]),(0,p.useEffect)(()=>{let e=T.current;if(!e)return;let t=new ResizeObserver(()=>ce(e=>e+1));return t.observe(e),()=>t.disconnect()},[T]),(0,p.useEffect)(()=>{let r=!1,i=null;if(P(null),H(null),I(1),W(!0),f>52428800){H(C(`fileManager.preview.tooLarge`,{size:s(f)})),W(!1);return}let a={},o=u();return o&&(a.Authorization=`Bearer ${o}`),(async()=>{let o=await fetch(n.getLibraryFileDownloadUrl(e),{headers:a});if(!o.ok)throw Error(`HTTP ${o.status}`);let s=await o.arrayBuffer(),c=await t(()=>import(`./pdf-DG3KNKaP.js`),__vite__mapDeps([0,1,2,3]));if(c.GlobalWorkerOptions.workerSrc||(c.GlobalWorkerOptions.workerSrc=(await t(async()=>{let{default:e}=await import(`./pdf.worker.min-DpOxPwGP.js`);return{default:e}},[])).default),i=c.getDocument({data:new Uint8Array(s),cMapUrl:`${b}cmaps/`,iccUrl:`${b}iccs/`,standardFontDataUrl:`${b}standard_fonts/`,wasmUrl:`${b}wasm/`}),r){i.destroy();return}let l=await i.promise;r||P(l)})().catch(e=>{console.error(`[pdf-preview] load failed`,e),r||(H(C(`fileManager.preview.error`)),W(!1))}),()=>{r=!0,A.current?.cancel(),A.current=null,i?.destroy()}},[e,f,C]),(0,p.useEffect)(()=>{if(!N)return;let e=!1;return W(!0),(async()=>{let t=await N.getPage(F),n=k.current,r=O.current;if(!n||!r||e)return;let i=t.getViewport({scale:1}),a=Math.max((r.clientWidth-32)/i.width,.1),o=Math.min(window.devicePixelRatio||1,2),s=a*z*o,c=i.width*s*(i.height*s),l=c>y?s*Math.sqrt(y/c):s,u=t.getViewport({scale:l});n.width=u.width,n.height=u.height,K.current={width:i.width*a,height:i.height*a},n.style.width=`${K.current.width*G.current}px`,n.style.height=`${K.current.height*G.current}px`,A.current?.cancel();let d=t.render({canvas:n,viewport:u});if(A.current=d,await d.promise,!e&&(W(!1),F===1&&M.current&&!j.current)){j.current=!0;let t=await x(n);t&&!e&&M.current?.(t)}})().catch(t=>{!e&&t?.name!==`RenderingCancelledException`&&(console.error(`[pdf-preview] render failed`,t),H(C(`fileManager.preview.error`)),W(!1))}),()=>{e=!0}},[N,F,z,B,C]);let Q=N?.numPages??0,$=d;return(0,m.jsx)(l,{title:a,fullscreen:w,onClose:h,icon:(0,m.jsx)(i,{className:`w-5 h-5 text-bambu-green flex-shrink-0`}),actions:(0,m.jsxs)(m.Fragment,{children:[N&&Q>1&&(0,m.jsxs)(`div`,{className:`flex items-center gap-1 mr-2`,children:[(0,m.jsx)(`button`,{onClick:()=>I(e=>Math.max(1,e-1)),disabled:F<=1,className:`${$} disabled:opacity-40 disabled:cursor-not-allowed`,"aria-label":C(`fileManager.preview.prevPage`),children:(0,m.jsx)(c,{className:`w-4 h-4`})}),(0,m.jsx)(`span`,{className:`text-sm text-bambu-gray whitespace-nowrap`,children:C(`fileManager.preview.page`,{current:F,total:Q})}),(0,m.jsx)(`button`,{onClick:()=>I(e=>Math.min(Q,e+1)),disabled:F>=Q,className:`${$} disabled:opacity-40 disabled:cursor-not-allowed`,"aria-label":C(`fileManager.preview.nextPage`),children:(0,m.jsx)(o,{className:`w-4 h-4`})})]}),N&&(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(`button`,{onClick:()=>X(1/_),className:$,"aria-label":C(`fileManager.preview.zoomOut`),children:(0,m.jsx)(ee,{className:`w-4 h-4`})}),(0,m.jsx)(`button`,{onClick:()=>X(_),className:$,"aria-label":C(`fileManager.preview.zoomIn`),children:(0,m.jsx)(r,{className:`w-4 h-4`})})]})]}),children:(0,m.jsxs)(`div`,{ref:O,"data-testid":`pdf-preview-page`,className:`relative flex-1 min-h-0 overflow-auto bg-bambu-dark p-4 touch-none ${E?``:`rounded-b-lg`}`,onDoubleClick:D,onPointerDown:le,onPointerMove:ue,onPointerUp:Z,onPointerCancel:Z,onPointerLeave:Z,children:[V?(0,m.jsx)(`div`,{className:`h-full flex items-center justify-center`,children:(0,m.jsx)(`p`,{className:`text-bambu-gray text-center`,children:V})}):(0,m.jsx)(`div`,{className:`flex justify-center min-w-fit`,children:(0,m.jsx)(`canvas`,{ref:k,className:`shadow-lg`})}),!V&&U&&(0,m.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center pointer-events-none`,children:(0,m.jsx)(ne,{className:`w-8 h-8 text-bambu-green animate-spin`})})]})})}export{C as PdfPreviewModal}; \ No newline at end of file diff --git a/static/assets/SpreadsheetPreviewModal-D3re3Dlf.js b/static/assets/SpreadsheetPreviewModal-Dt2h99YI.js similarity index 97% rename from static/assets/SpreadsheetPreviewModal-D3re3Dlf.js rename to static/assets/SpreadsheetPreviewModal-Dt2h99YI.js index c57a1892a..9a50f836e 100644 --- a/static/assets/SpreadsheetPreviewModal-D3re3Dlf.js +++ b/static/assets/SpreadsheetPreviewModal-Dt2h99YI.js @@ -1,2 +1,2 @@ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/papaparse.min-CR43Mv99.js","assets/chunk-aKtaBQYM.js"])))=>i.map(i=>d[i]); -import{i as e}from"./chunk-aKtaBQYM.js";import{_ as t,a as n,g as r,i,n as a,o,p as s,t as c,u as l,v as u,y as d}from"./index-Bc3Y2a4o.js";var f=e(d(),1),p=r(),m=500,h=40;function g(e){let t=``,n=e;for(;n>=0;)t=String.fromCharCode(65+n%26)+t,n=Math.floor(n/26)-1;return t}function _(e){let t=document.createElement(`canvas`);t.width=256,t.height=256;let n=t.getContext(`2d`);if(!n)return Promise.resolve(null);let r=256/5,i=256/9;n.fillStyle=`#1a1a1a`,n.fillRect(0,0,256,256),n.fillStyle=`rgba(0, 174, 66, 0.25)`,n.fillRect(0,0,256,i),n.strokeStyle=`#333333`,n.lineWidth=1;for(let e=1;e<5;e++)n.beginPath(),n.moveTo(e*r+.5,0),n.lineTo(e*r+.5,256),n.stroke();for(let e=1;e<9;e++)n.beginPath(),n.moveTo(0,e*i+.5),n.lineTo(256,e*i+.5),n.stroke();n.fillStyle=`#d4d4d4`,n.font=`11px sans-serif`,n.textBaseline=`middle`;for(let t=0;t<9;t++)for(let a=0;a<5;a++){let o=e[t]?.[a];o&&n.fillText(String(o),a*r+4,t*i+i/2,r-8)}return new Promise(e=>t.toBlob(e,`image/png`))}function v({libraryFileId:r,filename:d,fileType:v,fileSize:y,onClose:b,onSnapshot:x}){let{t:S}=u(),[C,w]=(0,f.useState)(null),[T,E]=(0,f.useState)(0),[D,O]=(0,f.useState)(null),k=(0,f.useRef)(!1),A=(0,f.useRef)(x);(0,f.useEffect)(()=>{A.current=x});let j=c(),{isFullscreen:M,toggleFullscreen:N}=j;(0,f.useEffect)(()=>{let a=!1;if(w(null),O(null),E(0),y>20971520){O(S(`fileManager.preview.tooLarge`,{size:i(y)}));return}let s={},c=o();return c&&(s.Authorization=`Bearer ${c}`),(async()=>{let i=await fetch(n.getLibraryFileDownloadUrl(r),{headers:s});if(!i.ok)throw Error(`HTTP ${i.status}`);let o=await i.arrayBuffer(),c;if(v===`csv`){let n=(await t(async()=>{let{default:t}=await import(`./papaparse.min-CR43Mv99.js`).then(t=>e(t.default,1));return{default:t}},__vite__mapDeps([0,1]))).default,r=new TextDecoder().decode(o),i=[],a=0,s=0,l=[],u=e=>{a+=1,s=Math.max(s,e.length),i.lengthe??``))};n.parse(r,{skipEmptyLines:!1,step:({data:e})=>{if(Array.isArray(e)){if(e.every(e=>!e)){l.push(e);return}l.forEach(u),l=[],u(e)}}}),c=[{name:d,rows:i,totalRows:a,totalCols:s}]}else{let e=await t(()=>import(`./xlsx-CKkngM-o.js`),[]),n=e.read(o,{dense:!0});c=n.SheetNames.map(t=>{let r=n.Sheets[t],i=r?.[`!ref`];if(!r||!i)return{name:t,rows:[],totalRows:0,totalCols:0};let a=e.utils.decode_range(i),o=a.e.r-a.s.r+1,s=a.e.c-a.s.c+1,c={s:a.s,e:{r:Math.min(a.e.r,a.s.r+m-1),c:Math.min(a.e.c,a.s.c+h-1)}};return{name:t,rows:e.utils.sheet_to_json(r,{header:1,raw:!1,defval:``,range:e.utils.encode_range(c)}),totalRows:o,totalCols:s}})}if(!a&&(w(c),A.current&&!k.current)){let e=c.find(e=>e.rows.length>0);if(e){k.current=!0;let t=await _(e.rows);t&&!a&&A.current?.(t)}}})().catch(e=>{console.error(`[sheet-preview] load failed`,e),a||O(S(`fileManager.preview.error`))}),()=>{a=!0}},[r,v,y,d,S]);let P=C?.[T]??null,F=P!=null&&P.totalRows>P.rows.length,I=P!=null&&P.totalCols>h,L=P==null?0:Math.min(P.totalCols,h);return(0,p.jsxs)(a,{title:d,fullscreen:j,onClose:b,icon:(0,p.jsx)(s,{className:`w-5 h-5 text-bambu-green flex-shrink-0`}),children:[C&&C.length>1&&(0,p.jsx)(`div`,{className:`flex gap-1 px-4 pt-2 overflow-x-auto flex-shrink-0`,children:C.map((e,t)=>(0,p.jsx)(`button`,{onClick:()=>E(t),className:`px-3 py-1.5 text-sm rounded-t whitespace-nowrap transition-colors ${t===T?`bg-bambu-dark text-white border border-b-0 border-bambu-dark-tertiary`:`text-bambu-gray hover:text-white hover:bg-bambu-dark/50`}`,children:e.name},`${e.name}-${t}`))}),(0,p.jsx)(`div`,{"data-testid":`spreadsheet-preview-content`,className:`flex-1 min-h-0 overflow-auto bg-bambu-dark ${M?``:`rounded-b-lg`}`,onDoubleClick:N,children:D?(0,p.jsx)(`div`,{className:`h-full flex items-center justify-center p-6`,children:(0,p.jsx)(`p`,{className:`text-bambu-gray text-center`,children:D})}):C?!P||P.rows.length===0?(0,p.jsx)(`div`,{className:`h-full flex items-center justify-center p-6`,children:(0,p.jsx)(`p`,{className:`text-bambu-gray`,children:S(`fileManager.preview.emptySheet`)})}):(0,p.jsxs)(`table`,{className:`border-collapse text-xs min-w-full`,children:[(0,p.jsx)(`thead`,{children:(0,p.jsxs)(`tr`,{children:[(0,p.jsx)(`th`,{className:`sticky top-0 bg-bambu-dark-secondary border border-bambu-dark-tertiary px-2 py-1 text-bambu-gray font-medium w-10`}),Array.from({length:L},(e,t)=>(0,p.jsx)(`th`,{className:`sticky top-0 bg-bambu-dark-secondary border border-bambu-dark-tertiary px-2 py-1 text-bambu-gray font-medium text-left min-w-[80px]`,children:g(t)},t))]})}),(0,p.jsx)(`tbody`,{children:P.rows.map((e,t)=>(0,p.jsxs)(`tr`,{children:[(0,p.jsx)(`td`,{className:`border border-bambu-dark-tertiary px-2 py-1 text-bambu-gray text-right bg-bambu-dark-secondary/50`,children:t+1}),Array.from({length:L},(t,n)=>(0,p.jsx)(`td`,{className:`border border-bambu-dark-tertiary px-2 py-1 text-bambu-gray-light whitespace-nowrap max-w-[280px] overflow-hidden text-ellipsis`,title:e[n]||void 0,children:e[n]??``},n))]},t))})]}):(0,p.jsx)(`div`,{className:`h-full flex items-center justify-center`,children:(0,p.jsx)(l,{className:`w-8 h-8 text-bambu-green animate-spin`})})}),(F||I)&&P&&(0,p.jsxs)(`div`,{className:`px-4 py-2 border-t border-bambu-dark-tertiary text-xs text-bambu-gray flex gap-4 flex-shrink-0`,children:[F&&(0,p.jsx)(`span`,{children:S(`fileManager.preview.truncatedRows`,{shown:P.rows.length,total:P.totalRows})}),I&&(0,p.jsx)(`span`,{children:S(`fileManager.preview.truncatedCols`,{shown:L,total:P.totalCols})})]})]})}export{v as SpreadsheetPreviewModal}; \ No newline at end of file +import{i as e}from"./chunk-aKtaBQYM.js";import{_ as t,a as n,g as r,i,n as a,o,p as s,t as c,u as l,v as u,y as d}from"./index-7qfiHY5t.js";var f=e(d(),1),p=r(),m=500,h=40;function g(e){let t=``,n=e;for(;n>=0;)t=String.fromCharCode(65+n%26)+t,n=Math.floor(n/26)-1;return t}function _(e){let t=document.createElement(`canvas`);t.width=256,t.height=256;let n=t.getContext(`2d`);if(!n)return Promise.resolve(null);let r=256/5,i=256/9;n.fillStyle=`#1a1a1a`,n.fillRect(0,0,256,256),n.fillStyle=`rgba(0, 174, 66, 0.25)`,n.fillRect(0,0,256,i),n.strokeStyle=`#333333`,n.lineWidth=1;for(let e=1;e<5;e++)n.beginPath(),n.moveTo(e*r+.5,0),n.lineTo(e*r+.5,256),n.stroke();for(let e=1;e<9;e++)n.beginPath(),n.moveTo(0,e*i+.5),n.lineTo(256,e*i+.5),n.stroke();n.fillStyle=`#d4d4d4`,n.font=`11px sans-serif`,n.textBaseline=`middle`;for(let t=0;t<9;t++)for(let a=0;a<5;a++){let o=e[t]?.[a];o&&n.fillText(String(o),a*r+4,t*i+i/2,r-8)}return new Promise(e=>t.toBlob(e,`image/png`))}function v({libraryFileId:r,filename:d,fileType:v,fileSize:y,onClose:b,onSnapshot:x}){let{t:S}=u(),[C,w]=(0,f.useState)(null),[T,E]=(0,f.useState)(0),[D,O]=(0,f.useState)(null),k=(0,f.useRef)(!1),A=(0,f.useRef)(x);(0,f.useEffect)(()=>{A.current=x});let j=c(),{isFullscreen:M,toggleFullscreen:N}=j;(0,f.useEffect)(()=>{let a=!1;if(w(null),O(null),E(0),y>20971520){O(S(`fileManager.preview.tooLarge`,{size:i(y)}));return}let s={},c=o();return c&&(s.Authorization=`Bearer ${c}`),(async()=>{let i=await fetch(n.getLibraryFileDownloadUrl(r),{headers:s});if(!i.ok)throw Error(`HTTP ${i.status}`);let o=await i.arrayBuffer(),c;if(v===`csv`){let n=(await t(async()=>{let{default:t}=await import(`./papaparse.min-CR43Mv99.js`).then(t=>e(t.default,1));return{default:t}},__vite__mapDeps([0,1]))).default,r=new TextDecoder().decode(o),i=[],a=0,s=0,l=[],u=e=>{a+=1,s=Math.max(s,e.length),i.lengthe??``))};n.parse(r,{skipEmptyLines:!1,step:({data:e})=>{if(Array.isArray(e)){if(e.every(e=>!e)){l.push(e);return}l.forEach(u),l=[],u(e)}}}),c=[{name:d,rows:i,totalRows:a,totalCols:s}]}else{let e=await t(()=>import(`./xlsx-CKkngM-o.js`),[]),n=e.read(o,{dense:!0});c=n.SheetNames.map(t=>{let r=n.Sheets[t],i=r?.[`!ref`];if(!r||!i)return{name:t,rows:[],totalRows:0,totalCols:0};let a=e.utils.decode_range(i),o=a.e.r-a.s.r+1,s=a.e.c-a.s.c+1,c={s:a.s,e:{r:Math.min(a.e.r,a.s.r+m-1),c:Math.min(a.e.c,a.s.c+h-1)}};return{name:t,rows:e.utils.sheet_to_json(r,{header:1,raw:!1,defval:``,range:e.utils.encode_range(c)}),totalRows:o,totalCols:s}})}if(!a&&(w(c),A.current&&!k.current)){let e=c.find(e=>e.rows.length>0);if(e){k.current=!0;let t=await _(e.rows);t&&!a&&A.current?.(t)}}})().catch(e=>{console.error(`[sheet-preview] load failed`,e),a||O(S(`fileManager.preview.error`))}),()=>{a=!0}},[r,v,y,d,S]);let P=C?.[T]??null,F=P!=null&&P.totalRows>P.rows.length,I=P!=null&&P.totalCols>h,L=P==null?0:Math.min(P.totalCols,h);return(0,p.jsxs)(a,{title:d,fullscreen:j,onClose:b,icon:(0,p.jsx)(s,{className:`w-5 h-5 text-bambu-green flex-shrink-0`}),children:[C&&C.length>1&&(0,p.jsx)(`div`,{className:`flex gap-1 px-4 pt-2 overflow-x-auto flex-shrink-0`,children:C.map((e,t)=>(0,p.jsx)(`button`,{onClick:()=>E(t),className:`px-3 py-1.5 text-sm rounded-t whitespace-nowrap transition-colors ${t===T?`bg-bambu-dark text-white border border-b-0 border-bambu-dark-tertiary`:`text-bambu-gray hover:text-white hover:bg-bambu-dark/50`}`,children:e.name},`${e.name}-${t}`))}),(0,p.jsx)(`div`,{"data-testid":`spreadsheet-preview-content`,className:`flex-1 min-h-0 overflow-auto bg-bambu-dark ${M?``:`rounded-b-lg`}`,onDoubleClick:N,children:D?(0,p.jsx)(`div`,{className:`h-full flex items-center justify-center p-6`,children:(0,p.jsx)(`p`,{className:`text-bambu-gray text-center`,children:D})}):C?!P||P.rows.length===0?(0,p.jsx)(`div`,{className:`h-full flex items-center justify-center p-6`,children:(0,p.jsx)(`p`,{className:`text-bambu-gray`,children:S(`fileManager.preview.emptySheet`)})}):(0,p.jsxs)(`table`,{className:`border-collapse text-xs min-w-full`,children:[(0,p.jsx)(`thead`,{children:(0,p.jsxs)(`tr`,{children:[(0,p.jsx)(`th`,{className:`sticky top-0 bg-bambu-dark-secondary border border-bambu-dark-tertiary px-2 py-1 text-bambu-gray font-medium w-10`}),Array.from({length:L},(e,t)=>(0,p.jsx)(`th`,{className:`sticky top-0 bg-bambu-dark-secondary border border-bambu-dark-tertiary px-2 py-1 text-bambu-gray font-medium text-left min-w-[80px]`,children:g(t)},t))]})}),(0,p.jsx)(`tbody`,{children:P.rows.map((e,t)=>(0,p.jsxs)(`tr`,{children:[(0,p.jsx)(`td`,{className:`border border-bambu-dark-tertiary px-2 py-1 text-bambu-gray text-right bg-bambu-dark-secondary/50`,children:t+1}),Array.from({length:L},(t,n)=>(0,p.jsx)(`td`,{className:`border border-bambu-dark-tertiary px-2 py-1 text-bambu-gray-light whitespace-nowrap max-w-[280px] overflow-hidden text-ellipsis`,title:e[n]||void 0,children:e[n]??``},n))]},t))})]}):(0,p.jsx)(`div`,{className:`h-full flex items-center justify-center`,children:(0,p.jsx)(l,{className:`w-8 h-8 text-bambu-green animate-spin`})})}),(F||I)&&P&&(0,p.jsxs)(`div`,{className:`px-4 py-2 border-t border-bambu-dark-tertiary text-xs text-bambu-gray flex gap-4 flex-shrink-0`,children:[F&&(0,p.jsx)(`span`,{children:S(`fileManager.preview.truncatedRows`,{shown:P.rows.length,total:P.totalRows})}),I&&(0,p.jsx)(`span`,{children:S(`fileManager.preview.truncatedCols`,{shown:L,total:P.totalCols})})]})]})}export{v as SpreadsheetPreviewModal}; \ No newline at end of file diff --git a/static/assets/index-Bc3Y2a4o.js b/static/assets/index-7qfiHY5t.js similarity index 99% rename from static/assets/index-Bc3Y2a4o.js rename to static/assets/index-7qfiHY5t.js index 1c1eb2963..ca1c01a64 100644 --- a/static/assets/index-Bc3Y2a4o.js +++ b/static/assets/index-7qfiHY5t.js @@ -1,4 +1,4 @@ -const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/PdfPreviewModal-AgMs-G9b.js","assets/chunk-aKtaBQYM.js","assets/SpreadsheetPreviewModal-D3re3Dlf.js","assets/ImagePreviewModal-C-WFsOtq.js"])))=>i.map(i=>d[i]); +const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/PdfPreviewModal-C4ar5SVt.js","assets/chunk-aKtaBQYM.js","assets/SpreadsheetPreviewModal-Dt2h99YI.js","assets/ImagePreviewModal-DRfunMYn.js"])))=>i.map(i=>d[i]); import{i as e,n as t,r as n,t as r}from"./chunk-aKtaBQYM.js";(function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),e.crossOrigin===`use-credentials`?t.credentials=`include`:e.crossOrigin===`anonymous`?t.credentials=`omit`:t.credentials=`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();var i=r((e=>{var t=Symbol.for(`react.transitional.element`),n=Symbol.for(`react.portal`),r=Symbol.for(`react.fragment`),i=Symbol.for(`react.strict_mode`),a=Symbol.for(`react.profiler`),o=Symbol.for(`react.consumer`),s=Symbol.for(`react.context`),c=Symbol.for(`react.forward_ref`),l=Symbol.for(`react.suspense`),u=Symbol.for(`react.memo`),d=Symbol.for(`react.lazy`),f=Symbol.for(`react.activity`),p=Symbol.iterator;function m(e){return typeof e!=`object`||!e?null:(e=p&&e[p]||e[`@@iterator`],typeof e==`function`?e:null)}var h={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},g=Object.assign,_={};function v(e,t,n){this.props=e,this.context=t,this.refs=_,this.updater=n||h}v.prototype.isReactComponent={},v.prototype.setState=function(e,t){if(typeof e!=`object`&&typeof e!=`function`&&e!=null)throw Error(`takes an object of state variables to update or a function which returns an object of state variables.`);this.updater.enqueueSetState(this,e,t,`setState`)},v.prototype.forceUpdate=function(e){this.updater.enqueueForceUpdate(this,e,`forceUpdate`)};function y(){}y.prototype=v.prototype;function b(e,t,n){this.props=e,this.context=t,this.refs=_,this.updater=n||h}var x=b.prototype=new y;x.constructor=b,g(x,v.prototype),x.isPureReactComponent=!0;var S=Array.isArray;function C(){}var w={H:null,A:null,T:null,S:null},T=Object.prototype.hasOwnProperty;function E(e,n,r){var i=r.ref;return{$$typeof:t,type:e,key:n,ref:i===void 0?null:i,props:r}}function D(e,t){return E(e.type,t,e.props)}function O(e){return typeof e==`object`&&!!e&&e.$$typeof===t}function k(e){var t={"=":`=0`,":":`=2`};return`$`+e.replace(/[=:]/g,function(e){return t[e]})}var A=/\/+/g;function j(e,t){return typeof e==`object`&&e&&e.key!=null?k(``+e.key):t.toString(36)}function M(e){switch(e.status){case`fulfilled`:return e.value;case`rejected`:throw e.reason;default:switch(typeof e.status==`string`?e.then(C,C):(e.status=`pending`,e.then(function(t){e.status===`pending`&&(e.status=`fulfilled`,e.value=t)},function(t){e.status===`pending`&&(e.status=`rejected`,e.reason=t)})),e.status){case`fulfilled`:return e.value;case`rejected`:throw e.reason}}throw e}function N(e,r,i,a,o){var s=typeof e;(s===`undefined`||s===`boolean`)&&(e=null);var c=!1;if(e===null)c=!0;else switch(s){case`bigint`:case`string`:case`number`:c=!0;break;case`object`:switch(e.$$typeof){case t:case n:c=!0;break;case d:return c=e._init,N(c(e._payload),r,i,a,o)}}if(c)return o=o(e),c=a===``?`.`+j(e,0):a,S(o)?(i=``,c!=null&&(i=c.replace(A,`$&/`)+`/`),N(o,r,i,``,function(e){return e})):o!=null&&(O(o)&&(o=D(o,i+(o.key==null||e&&e.key===o.key?``:(``+o.key).replace(A,`$&/`)+`/`)+c)),r.push(o)),1;c=0;var l=a===``?`.`:a+`:`;if(S(e))for(var u=0;u{t.exports=i()})),o=r((e=>{function t(e,t){var n=e.length;e.push(t);a:for(;0>>1,a=e[r];if(0>>1;ri(c,n))li(u,c)?(e[r]=u,e[l]=n,r=l):(e[r]=c,e[s]=n,r=s);else if(li(u,n))e[r]=u,e[l]=n,r=l;else break a}}return t}function i(e,t){var n=e.sortIndex-t.sortIndex;return n===0?e.id-t.id:n}if(e.unstable_now=void 0,typeof performance==`object`&&typeof performance.now==`function`){var a=performance;e.unstable_now=function(){return a.now()}}else{var o=Date,s=o.now();e.unstable_now=function(){return o.now()-s}}var c=[],l=[],u=1,d=null,f=3,p=!1,m=!1,h=!1,g=!1,_=typeof setTimeout==`function`?setTimeout:null,v=typeof clearTimeout==`function`?clearTimeout:null,y=typeof setImmediate<`u`?setImmediate:null;function b(e){for(var i=n(l);i!==null;){if(i.callback===null)r(l);else if(i.startTime<=e)r(l),i.sortIndex=i.expirationTime,t(c,i);else break;i=n(l)}}function x(e){if(h=!1,b(e),!m)if(n(c)!==null)m=!0,S||(S=!0,O());else{var t=n(l);t!==null&&j(x,t.startTime-e)}}var S=!1,C=-1,w=5,T=-1;function E(){return g?!0:!(e.unstable_now()-Tt&&E());){var o=d.callback;if(typeof o==`function`){d.callback=null,f=d.priorityLevel;var s=o(d.expirationTime<=t);if(t=e.unstable_now(),typeof s==`function`){d.callback=s,b(t),i=!0;break b}d===n(c)&&r(c),b(t)}else r(c);d=n(c)}if(d!==null)i=!0;else{var u=n(l);u!==null&&j(x,u.startTime-t),i=!1}}break a}finally{d=null,f=a,p=!1}i=void 0}}finally{i?O():S=!1}}}var O;if(typeof y==`function`)O=function(){y(D)};else if(typeof MessageChannel<`u`){var k=new MessageChannel,A=k.port2;k.port1.onmessage=D,O=function(){A.postMessage(null)}}else O=function(){_(D,0)};function j(t,n){C=_(function(){t(e.unstable_now())},n)}e.unstable_IdlePriority=5,e.unstable_ImmediatePriority=1,e.unstable_LowPriority=4,e.unstable_NormalPriority=3,e.unstable_Profiling=null,e.unstable_UserBlockingPriority=2,e.unstable_cancelCallback=function(e){e.callback=null},e.unstable_forceFrameRate=function(e){0>e||125o?(r.sortIndex=a,t(l,r),n(c)===null&&r===n(l)&&(h?(v(C),C=-1):h=!0,j(x,a-o))):(r.sortIndex=s,t(c,r),m||p||(m=!0,S||(S=!0,O()))),r},e.unstable_shouldYield=E,e.unstable_wrapCallback=function(e){var t=f;return function(){var n=f;f=t;try{return e.apply(this,arguments)}finally{f=n}}}})),s=r(((e,t)=>{t.exports=o()})),c=r((e=>{var t=a();function n(e){var t=`https://react.dev/errors/`+e;if(1{function n(){if(!(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__>`u`||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!=`function`))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(n)}catch(e){console.error(e)}}n(),t.exports=c()})),u=r((e=>{var t=s(),n=a(),r=l();function i(e){var t=`https://react.dev/errors/`+e;if(1B||(e.current=z[B],z[B]=null,B--)}function te(e,t){B++,z[B]=e.current,e.current=t}var ne=V(null),re=V(null),ie=V(null),ae=V(null);function oe(e,t){switch(te(ie,t),te(re,e),te(ne,null),t.nodeType){case 9:case 11:e=(e=t.documentElement)&&(e=e.namespaceURI)?Ud(e):0;break;default:if(e=t.tagName,t=t.namespaceURI)t=Ud(t),e=Wd(t,e);else switch(e){case`svg`:e=1;break;case`math`:e=2;break;default:e=0}}ee(ne),te(ne,e)}function se(){ee(ne),ee(re),ee(ie)}function H(e){e.memoizedState!==null&&te(ae,e);var t=ne.current,n=Wd(t,e.type);t!==n&&(te(re,e),te(ne,n))}function ce(e){re.current===e&&(ee(ne),ee(re)),ae.current===e&&(ee(ae),$f._currentValue=R)}var le,ue;function de(e){if(le===void 0)try{throw Error()}catch(e){var t=e.stack.trim().match(/\n( *(at )?)/);le=t&&t[1]||``,ue=-1)`:-1{let e=!r||i||!z(`printers:control`);return(0,G.jsxs)(`button`,{onClick:()=>Ee(!0),disabled:e,className:` ${s} ${e?a:`bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400 hover:bg-red-500/30`} - `,title:z(`printers:control`)?F(`printers.stop`):F(`printers.permission.noControl`),children:[(0,G.jsx)(_u,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)]`}),F(`printers.stop`)]})})()]})]})]})})(),(Dn?.length>0||W.vt_tray.length>0)&&r===`expanded`&&(()=>{let t=Dn.filter(e=>e.tray.length>1),n=Dn.filter(e=>e.tray.length===1),r=Dn.length>0&&W.vt_tray.length>0,f=!(r&&Se),_=e.nozzle_count===2||W?.temperatures?.nozzle_2!==void 0,v=fW[i]??1,y=e=>`${Math.round(e*v*1e3)/1e3}rem`,b=`3.5rem`,x={minWidth:b},S={minWidth:b,maxWidth:y(7.25)},C=e=>({gridTemplateColumns:`repeat(${e}, minmax(${b}, 1fr))`}),w=(W.state===`RUNNING`||W.state===`PAUSE`)&&Array.isArray(W.ams_mapping)?W.ams_mapping:[],T=e=>{let t=Math.max(1,e),n=`calc(${t} * ${b} + ${Math.max(0,t-1)} * 0.25rem + 1rem)`;return{flex:`1 1 ${n}`,minWidth:n}};return(0,G.jsxs)(`div`,{className:`mt-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,G.jsx)(`span`,{className:`text-[length:var(--pc-t10,10px)] uppercase tracking-wider text-bambu-gray font-medium`,children:F(`printers.filaments`)}),(0,G.jsx)(oje,{state:W.ams_filament_backup,onClick:()=>xe(!0)}),(0,G.jsx)(`div`,{className:`flex-1 h-[2px] bg-bambu-dark-tertiary`}),r&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(sje,{hidden:Se,onClick:we}),(0,G.jsx)(`div`,{className:`w-3 h-[2px] bg-bambu-dark-tertiary`})]})]}),(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[t.map(t=>{let n=ZU(t.id,Sn,Tn,wn);return(0,G.jsxs)(`div`,{style:T(4),className:`min-w-0 p-2 bg-bambu-dark rounded-[10px] space-y-1`,children:[(0,G.jsxs)(`div`,{className:`flex w-full min-h-7 items-center justify-between gap-2 rounded-lg bg-bambu-dark-secondary px-2 py-1`,children:[(0,G.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center gap-1.5`,children:[(0,G.jsx)(uW,{ams:t,printerId:e.id,label:Cp(t.id,t.tray.length),amsLabels:mn,canEdit:z(`printers:update`),onSaved:hn,children:(0,G.jsx)(`span`,{className:`block truncate text-[length:var(--pc-t10,10px)] text-white font-medium cursor-default select-none`,children:mn?.[t.id]||Cp(t.id,t.tray.length)})}),n?.kind===`inlet`?(0,G.jsx)(XU,{inlet:n.inlet,title:F(`printers.amsSwitchInletTooltip`,{inlet:n.inlet,side:bp[n.inlet]})}):_&&n?.kind===`nozzle`?(0,G.jsx)(YU,{side:n.side}):null]}),(t.humidity!=null||t.temp!=null)&&(0,G.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1.5`,children:[t.humidity!=null&&(0,G.jsx)(nW,{humidity:t.humidity,goodThreshold:a?.humidityGood,fairThreshold:a?.humidityFair,onClick:()=>Pt({amsId:t.id,amsLabel:Cp(t.id,t.tray.length),mode:`humidity`}),compact:!0}),t.temp!=null&&(0,G.jsx)(`div`,{className:`mr-1`,children:(0,G.jsx)(rW,{temp:t.temp,goodThreshold:a?.tempGood,fairThreshold:a?.tempFair,onClick:()=>Pt({amsId:t.id,amsLabel:Cp(t.id,t.tray.length),mode:`temperature`}),compact:!0})}),(W.supports_drying||W.drying_screen_only)&&(t.module_type===`n3f`||t.module_type===`n3s`)&&z(`printers:control`)&&(0,G.jsx)(`button`,{disabled:W.drying_screen_only||!!(t.dry_sf_reason?.length&&t.dry_time===0),onClick:e=>{t.dry_time>0?lr.mutate(t.id):Qe===t.id?$e(null):bt(t,e.currentTarget)},className:`ml-1 flex items-center gap-0.5 px-1 py-0.5 rounded text-[length:var(--pc-t9,9px)] transition-colors ${t.dry_time>0?`bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-400`:W.drying_screen_only||t.dry_sf_reason?.length?`bg-bambu-dark text-bambu-gray/50 cursor-not-allowed`:`bg-bambu-dark text-bambu-gray hover:text-white hover:bg-bambu-dark/80`}`,title:W.drying_screen_only?F(`printers.drying.screenOnly`):t.dry_time>0?F(`printers.drying.stop`):t.dry_sf_reason?.length?F(YAe(t.dry_sf_reason)):F(`printers.drying.start`),children:(0,G.jsx)(uc,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)]`})})]})]}),t.dry_time>0&&t.dry_countdown_stalled&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2 rounded-lg bg-slate-100 dark:bg-slate-500/10 px-2 py-1 text-[length:var(--pc-t9,9px)]`,title:F(`printers.drying.notRunningHint`),children:[(0,G.jsx)(Fc,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)] text-slate-500 dark:text-slate-400 shrink-0`}),(0,G.jsx)(`span`,{className:`text-slate-600 dark:text-slate-300 font-medium`,children:F(`printers.drying.notRunning`)}),t.dry_filament&&(0,G.jsx)(`span`,{className:`text-slate-500/90 dark:text-slate-400/80`,children:t.dry_target_temp==null?t.dry_filament:F(`printers.drying.targetSummary`,{filament:t.dry_filament,temp:t.dry_target_temp})}),!W.drying_screen_only&&(0,G.jsx)(`button`,{onClick:()=>lr.mutate(t.id),disabled:lr.isPending,className:`ml-auto text-slate-500 dark:text-slate-400 hover:text-slate-700 dark:hover:text-slate-200 transition-colors disabled:opacity-50`,title:F(`printers.drying.stop`),children:(0,G.jsx)(nd,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)]`})})]}),t.dry_time>0&&!t.dry_countdown_stalled&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2 rounded-lg bg-amber-50 dark:bg-amber-500/10 px-2 py-1 text-[length:var(--pc-t9,9px)]`,children:[(0,G.jsx)(uc,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)] text-amber-600 dark:text-amber-400 shrink-0`}),(0,G.jsx)(`span`,{className:`text-amber-700 dark:text-amber-400 font-medium`,children:F(`printers.drying.active`)}),t.dry_filament&&(0,G.jsx)(`span`,{className:`text-amber-700/80 dark:text-amber-300/70`,children:t.dry_target_temp==null?t.dry_filament:F(`printers.drying.targetSummary`,{filament:t.dry_filament,temp:t.dry_target_temp})}),(0,G.jsx)(`span`,{className:`text-amber-700/80 dark:text-amber-300/70`,children:F(`printers.drying.timeRemaining`,{time:t.dry_time>=60?`${Math.floor(t.dry_time/60)}h ${t.dry_time%60}m`:`${t.dry_time}m`})}),!W.drying_screen_only&&(0,G.jsx)(`button`,{onClick:()=>lr.mutate(t.id),disabled:lr.isPending,className:`ml-auto text-amber-700 dark:text-amber-400 hover:text-amber-900 dark:hover:text-amber-300 transition-colors disabled:opacity-50`,title:F(`printers.drying.stop`),children:(0,G.jsx)(nd,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)]`})})]}),(0,G.jsx)(`div`,{className:`grid w-full gap-1`,style:C(4),children:[0,1,2,3].map(n=>{let r=t.tray[n]||t.tray.find(e=>e.id===n),i=r?.tray_type&&r.remain>=0,a=!r?.tray_type,f=Fp(r),_=t.id*4+n,v=jn===_,y=Mn!==null&&Mn===_,b=Nn!==null&&Nn===_,S=r?.tray_info_idx?ln?.[r.tray_info_idx]:null,C=un?.[_],T=Xp(C?.preset_id,r?.tray_info_idx)?C?.preset_name:void 0,E=(r?.tray_uuid||r?.tag_uid||Vp(e.serial_number,t.id,n))?.toUpperCase(),D=E?s?.[E]:void 0,O=zp(D),k=o&&!h?m?.find(r=>r.printer_id===e.id&&r.ams_id===t.id&&r.tray_id===n):void 0,A=k?p?.find(e=>e.id===k.spoolman_spool_id):void 0,j=A&&(A.label_weight??0)>0?Math.round(Math.max(0,(A.label_weight??0)-A.weight_used)/(A.label_weight??1)*100):null,M=u?.(e.id,t.id,n),N=(()=>{let e=M?.spool;return e&&e.label_weight>0&&e.weight_used!=null?Math.round(Math.max(0,e.label_weight-e.weight_used)/e.label_weight*100):null})(),P=N===0&&i&&r.remain>0?null:N,I=O??j??P??(i?r.remain:null),L=O!==null||j!==null?`spoolman`:P===null?i?`ams`:void 0:`inventory`,R=r?.tray_type?{vendor:Yp(r)?`Bambu Lab`:`Generic`,profile:T||(A?[A.brand,A.slicer_filament_name?.split(`@`)[0].trim()||A.material].filter(Boolean).join(` `).trim():null)||M?.spool?.slicer_filament_name||S?.name||r.tray_sub_brands||r.tray_type,colorName:jf(r.tray_color||``,r.tray_sub_brands),colorHex:r.tray_color||null,kFactor:qU(r.k),fillLevel:I,trayUuid:r.tray_uuid||null,tagUid:r.tag_uid||null,fillSource:L}:null,B=Vr?.amsId===t.id&&Vr?.slotId===n,V=w.indexOf(_),ee=V>=0?`P${V+1}`:null,te=(0,G.jsxs)(`div`,{className:`relative w-full bg-bambu-dark-secondary rounded-lg p-1 text-center ${a?`opacity-50`:``} ${y?`ring-2 ring-amber-400 ring-offset-1 ring-offset-bambu-dark animate-pulse`:b?`ring-2 ring-red-500/60 ring-offset-1 ring-offset-bambu-dark`:v?`ring-2 ring-bambu-green ring-offset-1 ring-offset-bambu-dark`:``}`,children:[y&&(0,G.jsx)(`span`,{"aria-label":F(`printers.expectedSlot.ariaLabel`,{n:n+1}),title:F(`printers.expectedSlot.title`),className:`absolute top-0.5 left-0.5 px-1 py-px text-[length:var(--pc-t8,8px)] font-bold text-bambu-dark bg-amber-400 rounded pointer-events-none leading-none`,children:`↓`}),ee&&(0,G.jsx)(`span`,{"aria-label":F(`printers.activeJobSlot.ariaLabel`,{n:V+1}),title:F(`printers.activeJobSlot.title`,{n:V+1}),className:`absolute top-0.5 right-0.5 px-1 py-px text-[length:var(--pc-t8,8px)] font-bold text-bambu-dark bg-bambu-green rounded pointer-events-none leading-none`,children:ee}),(0,G.jsx)(WU,{trayColor:r?.tray_color,trayType:r?.tray_type,isEmpty:a,emptyKind:f,slotNumber:n+1}),(0,G.jsx)(`div`,{className:`text-[length:var(--pc-t9,9px)] text-white font-bold truncate`,children:r?.tray_type||F(f===`reset`?`ams.slotUnconfigured`:`ams.slotEmpty`)}),(0,G.jsx)(JU,{k:R?r?.k:null,reserve:On}),(0,G.jsx)(`div`,{className:`mt-1 h-1.5 bg-black/30 rounded-full overflow-hidden`,children:I!==null&&I>=0&&!a&&r&&(0,G.jsx)(`div`,{className:`h-full rounded-full transition-all`,style:{width:`${I}%`,backgroundColor:Rp(I)}})})]});return(0,G.jsxs)(`div`,{className:`relative group w-full`,style:x,children:[B&&(0,G.jsx)(`div`,{className:`absolute inset-0 bg-bambu-dark-tertiary/80 rounded flex items-center justify-center z-20`,children:(0,G.jsx)(zl,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)] text-bambu-green animate-spin`})}),R?(0,G.jsx)(GH,{data:R,actions:Ei({amsId:t.id,slotId:n,loadTrayId:t.id*4+n,isRefreshing:B}),spoolman:{enabled:o,linkedSpoolId:k?.spoolman_spool_id??(E?s?.[E]?.id:void 0),spoolmanUrl:c,syncMode:l,onLinkSpool:o&&!k&&!M?()=>{let r=(R.trayUuid||R.tagUid||Vp(e.serial_number,t.id,n)).toUpperCase();Rt({tagUid:R.tagUid||r,trayUuid:R.trayUuid||``,printerId:e.id,amsId:t.id,trayId:n})}:void 0,onUnlinkSpool:D?.id?()=>or.mutate(D.id):void 0},inventory:(()=>{if(o){if(h)return;let i=k,a=A;return{assignedSpool:a?{id:a.id,material:a.material,subtype:a.subtype,brand:a.brand??null,color_name:a.color_name??null,color_name_is_synthesized:a.color_name_is_synthesized,rgba:a.rgba??null,extra_colors:a.extra_colors??null,effect_type:a.effect_type??null,remainingWeightGrams:a.label_weight?Math.max(0,Math.round(a.label_weight-a.weight_used)):void 0}:null,onAssignSpool:()=>Bt({printerId:e.id,amsId:t.id,trayId:n,trayInfo:{type:r?.tray_type||R.profile,material:r?.tray_type??void 0,profile:R.profile,color:R.colorHex||``,location:`${Cp(t.id,t.tray.length)} Slot ${n+1}`}}),onUnassignSpool:a&&!Yp(r)?()=>g?.(a.id):void 0,isAssigned:!!i||Yp(r)}}let i=u?.(e.id,t.id,n);return{assignedSpool:i?.spool?{id:i.spool.id,material:i.spool.material,subtype:i.spool.subtype,brand:i.spool.brand,color_name:i.spool.color_name,rgba:i.spool.rgba??null,extra_colors:i.spool.extra_colors??null,effect_type:i.spool.effect_type??null,remainingWeightGrams:Math.max(0,Math.round(i.spool.label_weight-i.spool.weight_used))}:null,onAssignSpool:()=>Bt({printerId:e.id,amsId:t.id,trayId:n,trayInfo:{type:r?.tray_type||R.profile,material:r?.tray_type??void 0,profile:R.profile,color:R.colorHex||``,location:`${Cp(t.id,t.tray.length)} Slot ${n+1}`}}),onUnassignSpool:i&&!Yp(r)?()=>d?.(e.id,t.id,n):void 0,isAssigned:!!i||Yp(r)}})(),configureSlot:{enabled:z(`printers:control`),onConfigure:()=>Ht({amsId:t.id,trayId:n,trayCount:t.tray.length,trayType:r?.tray_type||void 0,trayColor:r?.tray_color||void 0,traySubBrands:r?.tray_sub_brands||void 0,trayInfoIdx:r?.tray_info_idx||void 0,extruderId:Sp(t.id,r?.id??0,Sn,Tn),caliIdx:r?.cali_idx,savedPresetId:C?.preset_id})},children:te}):(0,G.jsx)(KH,{kind:f??void 0,actions:Ei({amsId:t.id,slotId:n,loadTrayId:t.id*4+n,isRefreshing:B}),configureSlot:{enabled:z(`printers:control`),onConfigure:()=>Ht({amsId:t.id,trayId:n,trayCount:t.tray.length,extruderId:Sp(t.id,r?.id??0,Sn,Tn)})},onAssignSpool:()=>Bt({printerId:e.id,amsId:t.id,trayId:n,trayInfo:{type:``,material:void 0,profile:``,color:``,location:`${Cp(t.id,t.tray.length)} Slot ${n+1}`}}),children:te})]},n)})})]},t.id)}),n.map(t=>{let n=ZU(t.id,Sn,Tn,wn),r=t.tray[0],i=r?.tray_type&&r.remain>=0,f=!r?.tray_type,v=Fp(r),x=Lp(t.id,r?.id??0,!1),C=jn===x,T=Mn!==null&&Mn===x,E=Nn!==null&&Nn===x,D=r?.tray_info_idx?ln?.[r.tray_info_idx]:null,O=un?.[x],k=Xp(O?.preset_id,r?.tray_info_idx)?O?.preset_name:void 0,A=r?.id??0,j=(r?.tray_uuid||r?.tag_uid||Vp(e.serial_number,t.id,A))?.toUpperCase(),M=j?s?.[j]:void 0,N=zp(M),P=u?.(e.id,t.id,A),I=(()=>{let e=P?.spool;return e&&e.label_weight>0&&e.weight_used!=null?Math.round(Math.max(0,e.label_weight-e.weight_used)/e.label_weight*100):null})(),L=I===0&&i&&r.remain>0?null:I,R=o&&!h?m?.find(n=>n.printer_id===e.id&&n.ams_id===t.id&&n.tray_id===A):void 0,B=R?p?.find(e=>e.id===R.spoolman_spool_id):void 0,V=B&&(B.label_weight??0)>0?Math.round(Math.max(0,(B.label_weight??0)-B.weight_used)/(B.label_weight??1)*100):null,ee=N??V??L??(i?r.remain:null),te=N!==null||V!==null?`spoolman`:L===null?i?`ams`:void 0:`inventory`,ne=r?.tray_type?{vendor:Yp(r)?`Bambu Lab`:`Generic`,profile:k||(B?[B.brand,B.slicer_filament_name?.split(`@`)[0].trim()||B.material].filter(Boolean).join(` `).trim():null)||P?.spool?.slicer_filament_name||D?.name||r.tray_sub_brands||r.tray_type,colorName:jf(r.tray_color||``,r.tray_sub_brands),colorHex:r.tray_color||null,kFactor:qU(r.k),fillLevel:ee,trayUuid:r.tray_uuid||null,tagUid:r.tag_uid||null,fillSource:te}:null,re=Vr?.amsId===t.id&&Vr?.slotId===A,ie=w.indexOf(x),ae=ie>=0?`P${ie+1}`:null,oe=(0,G.jsxs)(`div`,{className:`relative w-full bg-bambu-dark-secondary rounded-lg p-1 text-center ${f?`opacity-50`:``} ${T?`ring-2 ring-amber-400 ring-offset-1 ring-offset-bambu-dark animate-pulse`:E?`ring-2 ring-red-500/60 ring-offset-1 ring-offset-bambu-dark`:C?`ring-2 ring-bambu-green ring-offset-1 ring-offset-bambu-dark`:``}`,children:[T&&(0,G.jsx)(`span`,{"aria-label":F(`printers.expectedSlot.ariaLabel`,{n:1}),title:F(`printers.expectedSlot.title`),className:`absolute top-0.5 left-0.5 px-1 py-px text-[length:var(--pc-t8,8px)] font-bold text-bambu-dark bg-amber-400 rounded pointer-events-none leading-none`,children:`↓`}),ae&&(0,G.jsx)(`span`,{"aria-label":F(`printers.activeJobSlot.ariaLabel`,{n:ie+1}),title:F(`printers.activeJobSlot.title`,{n:ie+1}),className:`absolute top-0.5 right-0.5 px-1 py-px text-[length:var(--pc-t8,8px)] font-bold text-bambu-dark bg-bambu-green rounded pointer-events-none leading-none`,children:ae}),(0,G.jsx)(WU,{trayColor:r?.tray_color,trayType:r?.tray_type,isEmpty:f,emptyKind:v,slotNumber:1}),(0,G.jsx)(`div`,{className:`text-[length:var(--pc-t9,9px)] text-white font-bold truncate`,children:r?.tray_type||F(v===`reset`?`ams.slotUnconfigured`:`ams.slotEmpty`)}),(0,G.jsx)(JU,{k:ne?r?.k:null,reserve:On}),(0,G.jsx)(`div`,{className:`mt-1 h-1.5 bg-black/30 rounded-full overflow-hidden`,children:ee!==null&&ee>=0&&!f&&(0,G.jsx)(`div`,{className:`h-full rounded-full transition-all`,style:{width:`${ee}%`,backgroundColor:Rp(ee)}})})]}),se=y(11);return(0,G.jsxs)(`div`,{style:{flex:`1 1 ${se}`,minWidth:se,maxWidth:`calc(4 * ${b} + 3 * 0.25rem + 1rem)`},className:`min-w-0 p-2 bg-bambu-dark rounded-[10px] space-y-1`,children:[(0,G.jsxs)(`div`,{className:`flex w-full min-h-7 items-center gap-1.5 rounded-lg bg-bambu-dark-secondary px-2 py-1`,children:[(0,G.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center gap-1.5`,children:[(0,G.jsx)(uW,{ams:t,printerId:e.id,label:Cp(t.id,t.tray.length),amsLabels:mn,canEdit:z(`printers:update`),onSaved:hn,children:(0,G.jsx)(`span`,{className:`block truncate text-[length:var(--pc-t10,10px)] text-white font-medium cursor-default select-none`,children:mn?.[t.id]||Cp(t.id,t.tray.length)})}),n?.kind===`inlet`?(0,G.jsx)(XU,{inlet:n.inlet,title:F(`printers.amsSwitchInletTooltip`,{inlet:n.inlet,side:bp[n.inlet]})}):_&&n?.kind===`nozzle`?(0,G.jsx)(YU,{side:n.side}):null]}),(W.supports_drying||W.drying_screen_only)&&(t.module_type===`n3f`||t.module_type===`n3s`)&&z(`printers:control`)&&(0,G.jsx)(`div`,{className:`relative ml-auto`,children:(0,G.jsx)(`button`,{disabled:W.drying_screen_only,onClick:e=>{t.dry_time>0?lr.mutate(t.id):Qe===t.id?$e(null):bt(t,e.currentTarget)},className:`flex items-center gap-0.5 px-1 py-0.5 rounded text-[length:var(--pc-t9,9px)] transition-colors ${t.dry_time>0?`bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-400`:W.drying_screen_only?`bg-bambu-dark text-bambu-gray/50 cursor-not-allowed`:`bg-bambu-dark text-bambu-gray hover:text-white hover:bg-bambu-dark/80`}`,title:W.drying_screen_only?F(`printers.drying.screenOnly`):t.dry_time>0?F(`printers.drying.stop`):F(`printers.drying.start`),children:(0,G.jsx)(uc,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)]`})})})]}),t.dry_time>0&&(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 overflow-hidden whitespace-nowrap rounded-lg px-2 py-1 text-[length:var(--pc-t9,9px)] ${t.dry_countdown_stalled?`bg-slate-100 dark:bg-slate-500/10`:`bg-amber-50 dark:bg-amber-500/10`}`,title:t.dry_countdown_stalled?F(`printers.drying.notRunningHint`):void 0,children:[t.dry_countdown_stalled?(0,G.jsx)(Fc,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)] text-slate-500 dark:text-slate-400 shrink-0`}):(0,G.jsx)(uc,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)] text-amber-600 dark:text-amber-400 shrink-0`}),t.dry_countdown_stalled&&(0,G.jsx)(`span`,{className:`text-slate-600 dark:text-slate-300 text-[length:var(--pc-t8,8px)] font-medium truncate`,children:F(`printers.drying.notRunning`)}),t.dry_filament&&(0,G.jsx)(`span`,{className:`${t.dry_countdown_stalled?`text-slate-500/90 dark:text-slate-400/80`:`text-amber-700/80 dark:text-amber-300/70`} text-[length:var(--pc-t8,8px)] truncate`,children:t.dry_target_temp==null?t.dry_filament:F(`printers.drying.targetSummary`,{filament:t.dry_filament,temp:t.dry_target_temp})}),!t.dry_countdown_stalled&&(0,G.jsx)(`span`,{className:`text-amber-700/80 dark:text-amber-300/70 text-[length:var(--pc-t8,8px)] truncate`,children:t.dry_time>=60?`${Math.floor(t.dry_time/60)}h ${t.dry_time%60}m`:`${t.dry_time}m`}),!W.drying_screen_only&&(0,G.jsx)(`button`,{onClick:()=>lr.mutate(t.id),disabled:lr.isPending,className:`ml-auto text-amber-700 dark:text-amber-400 hover:text-amber-900 dark:hover:text-amber-300 transition-colors disabled:opacity-50 shrink-0`,title:F(`printers.drying.stop`),children:(0,G.jsx)(nd,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)]`})})]}),(0,G.jsxs)(`div`,{className:`flex gap-1.5 max-[550px]:flex-col max-[550px]:items-start`,children:[(0,G.jsxs)(`div`,{className:`relative group flex-1`,style:S,children:[re&&(0,G.jsx)(`div`,{className:`absolute inset-0 bg-bambu-dark-tertiary/80 rounded flex items-center justify-center z-20`,children:(0,G.jsx)(zl,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)] text-bambu-green animate-spin`})}),ne?(0,G.jsx)(GH,{data:ne,actions:Ei({amsId:t.id,slotId:A,loadTrayId:t.id*4+A,isRefreshing:re}),spoolman:{enabled:o,linkedSpoolId:R?.spoolman_spool_id??(j?s?.[j]?.id:void 0),spoolmanUrl:c,syncMode:l,onLinkSpool:o&&!R&&!P?()=>{let n=(ne.trayUuid||ne.tagUid||Vp(e.serial_number,t.id,A)).toUpperCase();Rt({tagUid:ne.tagUid||n,trayUuid:ne.trayUuid||``,printerId:e.id,amsId:t.id,trayId:A})}:void 0,onUnlinkSpool:M?.id?()=>or.mutate(M.id):void 0},inventory:(()=>{if(o){if(h)return;let n=R,i=B;return{assignedSpool:i?{id:i.id,material:i.material,subtype:i.subtype,brand:i.brand??null,color_name:i.color_name??null,color_name_is_synthesized:i.color_name_is_synthesized,rgba:i.rgba??null,extra_colors:i.extra_colors??null,effect_type:i.effect_type??null,remainingWeightGrams:i.label_weight?Math.max(0,Math.round(i.label_weight-i.weight_used)):void 0}:null,onAssignSpool:()=>Bt({printerId:e.id,amsId:t.id,trayId:A,trayInfo:{type:r?.tray_type||ne.profile,material:r?.tray_type??void 0,profile:ne.profile,color:ne.colorHex||``,location:Cp(t.id,t.tray.length)}}),onUnassignSpool:i&&!Yp(r)?()=>g?.(i.id):void 0,isAssigned:!!n||Yp(r)}}let n=u?.(e.id,t.id,A);return{assignedSpool:n?.spool?{id:n.spool.id,material:n.spool.material,subtype:n.spool.subtype,brand:n.spool.brand,color_name:n.spool.color_name,rgba:n.spool.rgba??null,extra_colors:n.spool.extra_colors??null,effect_type:n.spool.effect_type??null,remainingWeightGrams:Math.max(0,Math.round(n.spool.label_weight-n.spool.weight_used))}:null,onAssignSpool:()=>Bt({printerId:e.id,amsId:t.id,trayId:A,trayInfo:{type:r?.tray_type||ne.profile,material:r?.tray_type??void 0,profile:ne.profile,color:ne.colorHex||``,location:Cp(t.id,t.tray.length)}}),onUnassignSpool:n&&!Yp(r)?()=>d?.(e.id,t.id,A):void 0,isAssigned:!!n||Yp(r)}})(),configureSlot:{enabled:z(`printers:control`),onConfigure:()=>Ht({amsId:t.id,trayId:A,trayCount:t.tray.length,trayType:r?.tray_type||void 0,trayColor:r?.tray_color||void 0,traySubBrands:r?.tray_sub_brands||void 0,trayInfoIdx:r?.tray_info_idx||void 0,extruderId:Sp(t.id,r?.id??0,Sn,Tn),caliIdx:r?.cali_idx,savedPresetId:O?.preset_id})},children:oe}):(0,G.jsx)(KH,{kind:v??void 0,actions:Ei({amsId:t.id,slotId:A,loadTrayId:t.id*4+A,isRefreshing:re}),configureSlot:{enabled:z(`printers:control`),onConfigure:()=>Ht({amsId:t.id,trayId:A,trayCount:t.tray.length,extruderId:Sp(t.id,r?.id??0,Sn,Tn)})},onAssignSpool:()=>Bt({printerId:e.id,amsId:t.id,trayId:A,trayInfo:{type:``,material:void 0,profile:``,color:``,location:Cp(t.id,t.tray.length)}}),children:oe})]}),(t.humidity!=null||t.temp!=null)&&(0,G.jsxs)(`div`,{className:`flex flex-col justify-center gap-1 shrink-0 max-[550px]:w-full`,children:[t.temp!=null&&(0,G.jsx)(rW,{temp:t.temp,goodThreshold:a?.tempGood,fairThreshold:a?.tempFair,onClick:()=>Pt({amsId:t.id,amsLabel:Cp(t.id,t.tray.length),mode:`temperature`}),compact:!0}),t.humidity!=null&&(0,G.jsx)(nW,{humidity:t.humidity,goodThreshold:a?.humidityGood,fairThreshold:a?.humidityFair,onClick:()=>Pt({amsId:t.id,amsLabel:Cp(t.id,t.tray.length),mode:`humidity`}),compact:!0})]})]})]},t.id)}),W.vt_tray.length>0&&f&&(0,G.jsxs)(`div`,{style:T(W.vt_tray.length),className:`min-w-0 p-2 bg-bambu-dark rounded-[10px] space-y-1`,children:[(0,G.jsx)(`div`,{className:`flex w-full min-h-7 items-center gap-1.5 rounded-lg bg-bambu-dark-secondary px-2 py-1`,children:(0,G.jsx)(`span`,{className:`block min-w-0 flex-1 truncate text-[length:var(--pc-t10,10px)] text-white font-medium`,children:F(`printers.external`)})}),(0,G.jsx)(`div`,{className:`grid w-full gap-1`,style:C(W.vt_tray.length>1?2:1),children:[...W.vt_tray].sort((e,t)=>(e.id??254)-(t.id??254)).map(t=>{let n=t.id??254,r=_&&jn===254?n===254&&W.active_extruder===1||n===255&&W.active_extruder===0:jn===n,i=n-254,a=_?F(n===254?`printers.extL`:`printers.extR`):``,f=t.tray_info_idx?ln?.[t.tray_info_idx]:null,v=un?.[1020+i],y=Xp(v?.preset_id,t.tray_info_idx)?v?.preset_name:void 0,b=(t.tray_uuid||t.tag_uid||Vp(e.serial_number,255,i))?.toUpperCase(),S=b?s?.[b]:void 0,C=zp(S),w=u?.(e.id,255,i),T=(()=>{let e=w?.spool;return e&&e.label_weight>0&&e.weight_used!=null?Math.round(Math.max(0,e.label_weight-e.weight_used)/e.label_weight*100):null})(),E=t.tray_type&&t.remain>=0,D=T===0&&E&&t.remain>0?null:T,O=o&&!h?m?.find(t=>t.printer_id===e.id&&t.ams_id===255&&t.tray_id===i):void 0,k=O?p?.find(e=>e.id===O.spoolman_spool_id):void 0,A=k&&(k.label_weight??0)>0?Math.round(Math.max(0,(k.label_weight??0)-k.weight_used)/(k.label_weight??1)*100):null,j=C??A??D??(E?t.remain:null),M=C!==null||A!==null?`spoolman`:D===null?E?`ams`:void 0:`inventory`,N={vendor:Yp(t)?`Bambu Lab`:`Generic`,profile:y||(k?[k.brand,k.slicer_filament_name?.split(`@`)[0].trim()||k.material].filter(Boolean).join(` `).trim():null)||w?.spool?.slicer_filament_name||f?.name||t.tray_sub_brands||t.tray_type||`Unknown`,colorName:jf(t.tray_color||``,t.tray_sub_brands),colorHex:t.tray_color||null,kFactor:qU(t.k),fillLevel:j,trayUuid:t.tray_uuid||null,tagUid:t.tag_uid||null,fillSource:M},P=!t.tray_type,I=Fp(t),L=(0,G.jsxs)(`div`,{className:`w-full bg-bambu-dark-secondary rounded-lg p-1 text-center ${P?`opacity-50`:``} ${r?`ring-2 ring-bambu-green ring-offset-1 ring-offset-bambu-dark`:``}`,children:[(0,G.jsx)(WU,{trayColor:t.tray_color,trayType:t.tray_type,isEmpty:P,emptyKind:I,slotNumber:_?n===254?`L`:`R`:i+1}),(0,G.jsx)(`div`,{className:`text-[length:var(--pc-t9,9px)] font-bold truncate ${P?`text-white/40`:`text-white`}`,children:t.tray_type||F(`ams.slotEmpty`)}),(0,G.jsx)(JU,{k:P?null:t.k,reserve:On}),(0,G.jsx)(`div`,{className:`mt-1 h-1.5 bg-black/30 rounded-full overflow-hidden`,children:j!==null&&j>=0&&!P&&(0,G.jsx)(`div`,{className:`h-full rounded-full transition-all`,style:{width:`${j}%`,backgroundColor:Rp(j)}})})]});return(0,G.jsx)(`div`,{className:`relative group w-full`,style:x,children:P?(0,G.jsx)(KH,{kind:I??void 0,actions:Ei({amsId:255,slotId:i,loadTrayId:n,includeRfid:!1}),configureSlot:{enabled:z(`printers:control`),onConfigure:()=>Ht({amsId:255,trayId:i,trayCount:1,extruderId:_?+(n===254):void 0})},onAssignSpool:()=>Bt({printerId:e.id,amsId:255,trayId:i,trayInfo:{type:``,material:void 0,profile:``,color:``,location:`External Slot ${i+1}`}}),children:L}):(0,G.jsx)(GH,{data:N,actions:Ei({amsId:255,slotId:i,loadTrayId:n,includeRfid:!1}),spoolman:{enabled:o,linkedSpoolId:O?.spoolman_spool_id??(b?s?.[b]?.id:void 0),spoolmanUrl:c,syncMode:l,onLinkSpool:o&&!O&&!w?()=>{let t=(N.trayUuid||N.tagUid||Vp(e.serial_number,255,i)).toUpperCase();Rt({tagUid:N.tagUid||t,trayUuid:N.trayUuid||``,printerId:e.id,amsId:255,trayId:i})}:void 0,onUnlinkSpool:S?.id?()=>or.mutate(S.id):void 0},inventory:(()=>{if(o){if(h)return;let n=O,r=k;return{assignedSpool:r?{id:r.id,material:r.material,subtype:r.subtype,brand:r.brand??null,color_name:r.color_name??null,color_name_is_synthesized:r.color_name_is_synthesized,rgba:r.rgba??null,extra_colors:r.extra_colors??null,effect_type:r.effect_type??null,remainingWeightGrams:r.label_weight?Math.max(0,Math.round(r.label_weight-r.weight_used)):void 0}:null,onAssignSpool:()=>Bt({printerId:e.id,amsId:255,trayId:i,trayInfo:{type:t.tray_type||N.profile,material:t.tray_type??void 0,profile:N.profile,color:N.colorHex||``,location:a||F(`printers.external`)}}),onUnassignSpool:r&&!Yp(t)?()=>g?.(r.id):void 0,isAssigned:!!n||Yp(t)}}let n=u?.(e.id,255,i);return{assignedSpool:n?.spool?{id:n.spool.id,material:n.spool.material,subtype:n.spool.subtype,brand:n.spool.brand,color_name:n.spool.color_name,rgba:n.spool.rgba??null,extra_colors:n.spool.extra_colors??null,effect_type:n.spool.effect_type??null,remainingWeightGrams:Math.max(0,Math.round(n.spool.label_weight-n.spool.weight_used))}:null,onAssignSpool:()=>Bt({printerId:e.id,amsId:255,trayId:i,trayInfo:{type:t.tray_type||N.profile,material:t.tray_type??void 0,profile:N.profile,color:N.colorHex||``,location:a||F(`printers.external`)}}),onUnassignSpool:n&&!Yp(t)?()=>d?.(e.id,255,i):void 0,isAssigned:!!n||Yp(t)}})(),configureSlot:{enabled:z(`printers:control`),onConfigure:()=>Ht({amsId:255,trayId:i,trayCount:1,trayType:t.tray_type||void 0,trayColor:t.tray_color||void 0,traySubBrands:t.tray_sub_brands||void 0,trayInfoIdx:t.tray_info_idx||void 0,extruderId:_?+(n===254):void 0,caliIdx:t.cali_idx,savedPresetId:v?.preset_id})},children:L})},n)})})]})]})]})})()]}),e.is_active!==!1&&!W?.connected&&r===`expanded`&&Yn&&xr,r===`expanded`&&(0,G.jsxs)(`div`,{className:`mt-auto`,children:[In&&(0,G.jsxs)(`div`,{className:`pt-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,G.jsx)(`span`,{className:`text-[length:var(--pc-t10,10px)] uppercase tracking-wider text-bambu-gray font-medium`,children:F(`printers.power`,`Power`)}),(0,G.jsx)(`div`,{className:`flex-1 h-[2px] bg-bambu-dark-tertiary`})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 rounded-[10px] bg-bambu-dark p-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0 pl-1`,children:[(0,G.jsx)(id,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)] text-bambu-gray flex-shrink-0`}),(0,G.jsx)(`span`,{className:`text-sm text-white truncate`,children:In.name}),(0,G.jsx)(`span`,{className:`px-1.5 py-0.5 rounded-full bg-bambu-dark-tertiary text-bambu-gray text-[length:var(--pc-t10,10px)] font-medium flex-shrink-0`,title:F(`smartPlugs.power`),children:Rn?.energy?.power!==null&&Rn?.energy?.power!==void 0?`${Math.round(Rn.energy.power)}W`:`--`})]}),(0,G.jsx)(`div`,{className:`flex-1`}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`button`,{onClick:()=>fr.mutate(!In.auto_off),disabled:fr.isPending||In.auto_off_executed||!z(`smart_plugs:control`),title:z(`smart_plugs:control`)?In.auto_off_executed?F(`printers.autoOffExecuted`):F(`printers.autoOffAfterPrint`):F(`printers.permission.noSmartPlugControl`),className:`flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-lg text-xs font-bold transition-colors disabled:opacity-50 disabled:cursor-not-allowed ${z(`smart_plugs:control`)?In.auto_off||In.auto_off_executed?`bg-bambu-green/20 text-bambu-green hover:bg-bambu-green/30`:`bg-bambu-dark-tertiary text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary/80`:`bg-bambu-dark-tertiary/50 text-bambu-gray/50`}`,children:(0,G.jsx)(Ts,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)]`})}),(0,G.jsx)(`button`,{onClick:()=>{Rn?.state===`ON`?pe(!0):de(!0)},disabled:dr.isPending||!z(`smart_plugs:control`),className:`flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-lg text-xs transition-colors disabled:opacity-50 disabled:cursor-not-allowed ${z(`smart_plugs:control`)?Rn?.state===`ON`?`bg-bambu-green/20 text-bambu-green hover:bg-bambu-green/30`:`bg-bambu-dark-tertiary text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary/80`:`bg-bambu-dark-tertiary/50 text-bambu-gray/50`}`,title:z(`smart_plugs:control`)?Rn?.state===`ON`?`Turn off`:`Turn on`:F(`printers.permission.noSmartPlugControl`),children:(0,G.jsx)(id,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)]`})})]})]}),Ln&&Ln.length>0&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mt-2`,children:[(0,G.jsx)(Ic,{className:`w-[var(--pc-i35,0.875rem)] h-[var(--pc-i35,0.875rem)] text-blue-600 dark:text-blue-400 flex-shrink-0`}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:`HA:`}),(0,G.jsx)(`div`,{className:`h-[2px] w-5 bg-bambu-dark-tertiary/50`}),(0,G.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:Ln.map(e=>{let t=e.ha_entity_id?.startsWith(`script.`);return(0,G.jsxs)(`button`,{onClick:()=>{t?pr.mutate({id:e.id,action:`on`}):he(e)},disabled:pr.isPending,title:`${t?`Run`:`Toggle`} ${e.ha_entity_id}`,className:`px-2 py-0.5 text-xs bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400 hover:bg-blue-500/30 rounded transition-colors flex items-center gap-1`,children:[(0,G.jsx)(Al,{className:`w-[var(--pc-i25,0.625rem)] h-[var(--pc-i25,0.625rem)]`}),e.name]},e.id)})})]})]}),(0,G.jsx)(zle,{printerId:e.id}),(0,G.jsxs)(`div`,{className:`pt-4`,children:[(0,G.jsx)(`div`,{className:`mb-3 h-[2px] bg-bambu-dark-tertiary`}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[Di,(0,G.jsxs)(`div`,{className:`flex items-center justify-end gap-2 flex-wrap`,children:[(0,G.jsxs)(`div`,{className:`flex items-center flex-shrink-0`,children:[(0,G.jsx)(Q,{variant:`secondary`,size:`sm`,onClick:()=>wi(v),disabled:!W?.connected||!z(`camera:view`),title:z(`camera:view`)?F(v===`embedded`?`printers.openCameraOverlay`:`printers.openCameraWindow`):F(`printers.permission.noCamera`),className:`${Ci} !rounded-r-none`,children:(0,G.jsx)(Gu,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)]`})}),(0,G.jsx)(Q,{variant:`secondary`,size:`sm`,onClick:e=>{let t=e.currentTarget.getBoundingClientRect();jt({x:t.left,y:t.bottom+4})},disabled:!W?.connected||!z(`camera:view`),title:z(`camera:view`)?F(`settings.cameraViewMode`):F(`printers.permission.noCamera`),"aria-label":F(`settings.cameraViewMode`),className:`!h-8 !min-h-8 !w-6 !px-0 !py-0 !rounded-l-none border-l border-bambu-dark`,children:(0,G.jsx)(ss,{className:`w-3 h-3`})})]}),At&&(0,G.jsx)(JT,{x:At.x,y:At.y,items:Ti,onClose:()=>jt(null)}),(0,G.jsx)(Q,{variant:`secondary`,size:`sm`,onClick:()=>H(!0),disabled:!z(`printers:files`),title:z(`printers:files`)?F(`printers.browseFiles`):F(`printers.permission.noFiles`),className:Ci,children:(0,G.jsx)(kc,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)]`})}),(0,G.jsxs)(Q,{size:`sm`,onClick:()=>We(!0),disabled:!z(`library:upload`)||!z(`queue:create`),title:z(`library:upload`)?z(`queue:create`)?F(`common.print`):F(`fileManager.noPermissionAddToQueue`):F(`fileManager.noPermissionUpload`),className:`!h-8 !min-h-8 !px-2 !py-0 !bg-bambu-green hover:!bg-bambu-green/80 !text-white`,children:[(0,G.jsx)(Fl,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)]`}),F(`common.print`)]})]})]})]})]}),(0,G.jsx)(_je,{printerId:e.id,dryingActive:Dn.some(e=>(e.dry_time??0)>0),timeFormat:_})]}),se&&(0,G.jsx)(ble,{printerId:e.id,printerName:e.name,onClose:()=>H(!1)}),Ue&&(0,G.jsx)(BU,{folderId:null,onClose:()=>We(!1),onUploadComplete:()=>{},autoUpload:!0,accept:`.gcode,.3mf`,validateFile:e=>{let t=e.name.toLowerCase();if(!t.endsWith(`.gcode`)&&!t.includes(`.gcode.`))return F(`printers.dropNotPrintable`,`Only .gcode and .gcode.3mf files can be printed`)},onFileUploaded:t=>{let n=t.metadata?.sliced_for_model,r=ah(e.model);if(n&&r&&n.toLowerCase()!==r.toLowerCase())return Z.deleteLibraryFile(t.id).catch(()=>{}),F(`printers.incompatibleFile`,`This file was sliced for {{slicedFor}}, but this printer is a {{printerModel}}`,{slicedFor:n,printerModel:r});Ze({id:t.id,filename:t.filename})}}),Xe&&(0,G.jsx)(Lm,{mode:`create`,libraryFileId:Xe.id,archiveName:Xe.filename,initialSelectedPrinterIds:[e.id],onClose:()=>Ze(null),onSuccess:()=>Ze(null),cleanupLibraryAfterDispatch:!0}),ce&&(0,G.jsx)(Fle,{printerId:e.id,printerName:e.name,onClose:()=>le(!1)}),qe&&(0,G.jsx)(Bm,{printerId:e.id,printerName:e.name,onClose:()=>Je(!1)}),Ge&&(0,G.jsx)(zAe,{printer:e,status:W,totalPrintHours:n?.total_print_hours,onClose:Ye}),Gt&&(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,onClick:()=>oi(),children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl shadow-2xl max-w-lg w-full`,onClick:e=>e.stopPropagation(),children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[Gt.needs_calibration?(0,G.jsx)(ql,{className:`w-[var(--pc-i5,1.25rem)] h-[var(--pc-i5,1.25rem)] text-blue-500`}):Gt.is_empty?(0,G.jsx)(hs,{className:`w-[var(--pc-i5,1.25rem)] h-[var(--pc-i5,1.25rem)] text-green-500`}):(0,G.jsx)(xs,{className:`w-[var(--pc-i5,1.25rem)] h-[var(--pc-i5,1.25rem)] text-yellow-500`}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:`Build Plate Check`}),Gt.reference_count!==void 0&&Gt.max_references&&(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray bg-bambu-dark-tertiary px-2 py-1 rounded`,children:[Gt.reference_count,`/`,Gt.max_references,` refs`]})]}),(0,G.jsx)(`button`,{onClick:()=>oi(),className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,G.jsx)(nd,{className:`w-[var(--pc-i5,1.25rem)] h-[var(--pc-i5,1.25rem)]`})})]}),(0,G.jsxs)(`div`,{className:`p-4 space-y-4`,children:[Gt.needs_calibration?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`p-3 rounded-lg bg-blue-100 dark:bg-blue-500/20 border border-blue-300 dark:border-blue-500/50`,children:[(0,G.jsx)(`p`,{className:`font-medium text-blue-700 dark:text-blue-400`,children:F(`printers.plateDetection.calibrationRequired`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,dangerouslySetInnerHTML:{__html:F(`printers.plateDetection.calibrationInstructions`)}})]}),(0,G.jsxs)(`div`,{className:`text-sm text-bambu-gray space-y-2`,children:[(0,G.jsx)(`p`,{children:F(`printers.plateDetection.calibrationDescription`)}),(0,G.jsx)(`p`,{dangerouslySetInnerHTML:{__html:F(`printers.plateDetection.calibrationTip`)}})]})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`p-3 rounded-lg ${Gt.is_empty?`bg-green-100 dark:bg-green-500/20 border border-green-300 dark:border-green-500/50`:`bg-yellow-100 dark:bg-yellow-500/20 border border-yellow-300 dark:border-yellow-500/50`}`,children:[(0,G.jsx)(`p`,{className:`font-medium ${Gt.is_empty?`text-green-700 dark:text-green-400`:`text-yellow-700 dark:text-yellow-400`}`,children:Gt.is_empty?F(`printers.plateDetection.plateEmpty`):F(`printers.plateDetection.objectsDetected`)}),(0,G.jsxs)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:[F(`printers.plateDetection.confidence`),`: `,Math.round(Gt.confidence*100),`% | `,F(`printers.plateDetection.difference`),`: `,Gt.difference_percent.toFixed(1),`%`]})]}),Gt.debug_image_url&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mb-2`,children:F(`printers.plateDetection.analysisPreview`)}),(0,G.jsx)(`img`,{src:Gt.debug_image_url,alt:F(`printers.plateDetection.analysisPreview`),className:`w-full rounded-lg border border-bambu-dark-tertiary`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-2`,children:F(`printers.plateDetection.analysisLegend`)})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:Gt.message})]}),$r&&$r.references.length>0&&(0,G.jsxs)(`div`,{className:`mt-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,G.jsx)(`p`,{className:`text-sm font-medium text-white shrink-0`,children:F(`printers.plateDetection.savedReferences`,{count:$r.references.length,max:$r.max_references})}),(0,G.jsx)(`div`,{className:`flex-1 h-[2px] bg-bambu-dark-tertiary`})]}),(0,G.jsx)(`div`,{className:`grid grid-cols-5 gap-2`,children:$r.references.map(t=>(0,G.jsxs)(`div`,{className:`relative group`,children:[(0,G.jsx)(`img`,{src:Z.getPlateReferenceThumbnailUrl(e.id,t.index),alt:t.label||`Reference ${t.index+1}`,className:`w-full aspect-video object-cover rounded border border-bambu-dark-tertiary`}),(0,G.jsx)(`button`,{onClick:()=>li(t.index),className:`absolute top-1 right-1 p-0.5 bg-red-500/80 rounded can-hover:opacity-0 group-hover:opacity-100 focus-visible:opacity-100 transition-opacity`,title:F(`printers.plateDetection.deleteReference`),children:(0,G.jsx)(nd,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)] text-white`})}),ti?.index===t.index?(0,G.jsx)(`input`,{type:`text`,value:ti.label,onChange:e=>ni({...ti,label:e.target.value}),onBlur:()=>ci(t.index,ti.label),onKeyDown:e=>{e.key===`Enter`&&ci(t.index,ti.label),e.key===`Escape`&&ni(null)},className:`w-full mt-1 px-1 py-0.5 text-xs bg-bambu-dark-tertiary border border-bambu-green rounded text-white`,autoFocus:!0,placeholder:F(`printers.plateDetection.labelPlaceholder`)}):(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1 truncate cursor-pointer hover:text-white`,onClick:()=>ni({index:t.index,label:t.label}),title:t.label?F(`printers.plateDetection.clickToEdit`,{label:t.label}):F(`printers.plateDetection.clickToAddLabel`),children:t.label||(0,G.jsx)(`span`,{className:`italic opacity-50`,children:F(`printers.noLabel`)})}),(0,G.jsx)(`p`,{className:`text-[length:var(--pc-t10,10px)] text-bambu-gray/60`,children:t.timestamp?sp(t.timestamp)?.toLocaleDateString()??``:``})]},t.index))})]}),!Gt.needs_calibration&&(0,G.jsxs)(`div`,{className:`mt-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,G.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center gap-2`,children:[(0,G.jsx)(`p`,{className:`text-sm font-medium text-white shrink-0`,children:F(`printers.roi.title`)}),(0,G.jsx)(`div`,{className:`flex-1 h-[2px] bg-bambu-dark-tertiary`})]}),Zt?(0,G.jsxs)(`div`,{className:`flex gap-1`,children:[(0,G.jsx)(Q,{variant:`ghost`,size:`sm`,onClick:()=>Qt(null),disabled:$t,children:F(`common.cancel`)}),(0,G.jsx)(Q,{size:`sm`,onClick:ui,disabled:$t,children:$t?(0,G.jsx)(Y,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)] animate-spin`}):F(`common.save`)})]}):(0,G.jsxs)(Q,{variant:`ghost`,size:`sm`,onClick:()=>Qt(Gt.roi||{x:.15,y:.35,w:.7,h:.55}),children:[(0,G.jsx)(Dl,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)] mr-1`}),F(`common.edit`)]})]}),Zt?(0,G.jsxs)(`div`,{className:`space-y-3 bg-bambu-dark-tertiary/50 p-3 rounded-lg`,children:[(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`text-xs text-bambu-gray`,children:F(`printers.roi.xStart`)}),(0,G.jsx)(`input`,{type:`range`,min:`0`,max:`0.9`,step:`0.01`,value:Zt.x,onChange:e=>Qt({...Zt,x:parseFloat(e.target.value)}),className:`w-full h-1.5 bg-bambu-dark-tertiary rounded-lg cursor-pointer accent-green-500`}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[Math.round(Zt.x*100),`%`]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`text-xs text-bambu-gray`,children:F(`printers.roi.yStart`)}),(0,G.jsx)(`input`,{type:`range`,min:`0`,max:`0.9`,step:`0.01`,value:Zt.y,onChange:e=>Qt({...Zt,y:parseFloat(e.target.value)}),className:`w-full h-1.5 bg-bambu-dark-tertiary rounded-lg cursor-pointer accent-green-500`}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[Math.round(Zt.y*100),`%`]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`text-xs text-bambu-gray`,children:F(`printers.width`)}),(0,G.jsx)(`input`,{type:`range`,min:`0.1`,max:`1`,step:`0.01`,value:Zt.w,onChange:e=>Qt({...Zt,w:parseFloat(e.target.value)}),className:`w-full h-1.5 bg-bambu-dark-tertiary rounded-lg cursor-pointer accent-green-500`}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[Math.round(Zt.w*100),`%`]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`text-xs text-bambu-gray`,children:F(`printers.height`)}),(0,G.jsx)(`input`,{type:`range`,min:`0.1`,max:`1`,step:`0.01`,value:Zt.h,onChange:e=>Qt({...Zt,h:parseFloat(e.target.value)}),className:`w-full h-1.5 bg-bambu-dark-tertiary rounded-lg cursor-pointer accent-green-500`}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[Math.round(Zt.h*100),`%`]})]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:F(`printers.roi.instruction`)})]}):(0,G.jsxs)(`p`,{className:`text-xs text-bambu-gray`,children:[`Current: X=`,Math.round((Gt.roi?.x||.15)*100),`%, Y=`,Math.round((Gt.roi?.y||.35)*100),`%, W=`,Math.round((Gt.roi?.w||.7)*100),`%, H=`,Math.round((Gt.roi?.h||.55)*100),`%`]})]})]}),(0,G.jsx)(`div`,{className:`flex justify-end gap-2 p-4`,children:Gt.needs_calibration?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Q,{variant:`ghost`,onClick:()=>oi(),children:F(`common.cancel`)}),(0,G.jsx)(Q,{onClick:()=>si(),disabled:Yt,children:Yt?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)] mr-2 animate-spin`}),`Calibrating...`]}):`Calibrate Empty Plate`})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Q,{variant:`ghost`,onClick:()=>si(),disabled:Yt,children:Yt?`Adding...`:`Add Reference (${$r?.references.length||0}/${$r?.max_references||5})`}),(0,G.jsx)(Q,{onClick:()=>oi(),children:`Close`})]})})]})}),ue&&In&&(0,G.jsx)(uf,{title:F(`printers.confirm.powerOnTitle`),message:F(`printers.confirm.powerOnMessage`,{name:e.name}),confirmText:F(`printers.confirm.powerOnButton`),variant:`default`,onConfirm:()=>{dr.mutate(`on`),de(!1)},onCancel:()=>de(!1)}),Ir&&(0,G.jsx)(uf,{title:F(`printers.maintenance.confirmMidPrintTitle`),message:F(`printers.maintenance.confirmMidPrintMessage`,{name:e.name}),confirmText:F(`printers.maintenance.menuEnter`),variant:`danger`,onConfirm:()=>{Fr.mutate(!1),Lr(!1)},onCancel:()=>Lr(!1)}),fe&&In&&(0,G.jsx)(uf,{title:F(`printers.confirm.powerOffTitle`),message:W?.state===`RUNNING`?F(`printers.confirm.powerOffWarning`,{name:e.name}):F(`printers.confirm.powerOffMessage`,{name:e.name}),confirmText:F(`printers.confirm.powerOffButton`),variant:`danger`,onConfirm:()=>{dr.mutate(`off`),pe(!1)},onCancel:()=>pe(!1)}),me&&(0,G.jsx)(uf,{title:F(`printers.confirm.haToggleTitle`,{name:me.name}),message:W?.state===`RUNNING`?F(`printers.confirm.haToggleWarning`,{name:e.name,entity:me.ha_entity_id||me.name}):F(`printers.confirm.haToggleMessage`,{entity:me.ha_entity_id||me.name}),confirmText:F(`printers.confirm.haToggleButton`),variant:W?.state===`RUNNING`?`danger`:`default`,onConfirm:()=>{pr.mutate({id:me.id,action:`toggle`}),he(null)},onCancel:()=>he(null)}),Te&&(0,G.jsx)(uf,{title:F(`printers.confirm.stopTitle`),message:F(`printers.confirm.stopMessage`,{name:e.name}),confirmText:F(`printers.confirm.stopButton`),variant:`danger`,onConfirm:()=>{mr.mutate(),Ee(!1)},onCancel:()=>Ee(!1)}),De&&(0,G.jsx)(uf,{title:F(`printers.confirm.pauseTitle`),message:F(`printers.confirm.pauseMessage`,{name:e.name}),confirmText:F(`printers.confirm.pauseButton`),variant:`default`,onConfirm:()=>{hr.mutate(),Oe(!1)},onCancel:()=>Oe(!1)}),ze&&(0,G.jsx)(uf,{title:F(`printers.confirm.resumeTitle`),message:F(`printers.confirm.resumeMessage`,{name:e.name}),confirmText:F(`printers.confirm.resumeButton`),variant:`default`,onConfirm:()=>{gr.mutate(),Be(!1)},onCancel:()=>Be(!1)}),(0,G.jsx)(zT,{printerId:e.id,isOpen:Ve,onClose:()=>He(!1)}),ge&&(0,G.jsx)(zte,{printerName:e.name,errors:W?.hms_errors||[],onClose:()=>_e(!1),printerId:e.id,hasPermission:z,runoutGuidance:Fn}),ve&&(0,G.jsx)(Lle,{printerName:e.name,detection:N,lastError:P,onClose:()=>ye(!1)}),be&&W&&(0,G.jsx)(hAe,{isOpen:be,state:W.ams_filament_backup,amsUnits:W.ams,amsExtruderMap:W.ams_extruder_map,isDualNozzle:e.nozzle_count===2||W?.temperatures?.nozzle_2!==void 0,canToggle:z(`printers:control`),pending:ur.isPending,onToggle:e=>ur.mutate(e),onClose:()=>xe(!1)}),Nt&&(0,G.jsx)(dAe,{isOpen:!!Nt,onClose:()=>Pt(null),printerId:e.id,printerName:e.name,amsId:Nt.amsId,amsLabel:Nt.amsLabel,initialMode:Nt.mode,thresholds:a}),Ft&&(0,G.jsx)(_Ae,{isOpen:!!Ft,onClose:()=>It(null),printerId:e.id,printerName:e.name,initialKind:Ft.initialKind,availableKinds:Ft.availableKinds}),Lt&&(0,G.jsx)(qH,{isOpen:!!Lt,onClose:()=>Rt(null),tagUid:Lt.tagUid,trayUuid:Lt.trayUuid,printerId:Lt.printerId,amsId:Lt.amsId,trayId:Lt.trayId}),zt&&(0,G.jsx)(YH,{isOpen:!!zt,onClose:()=>Bt(null),printerId:zt.printerId,amsId:zt.amsId,trayId:zt.trayId,trayInfo:zt.trayInfo,spoolmanEnabled:!!o}),Vt&&(0,G.jsx)(RU,{isOpen:!!Vt,onClose:()=>Ht(null),printerId:e.id,slotInfo:Vt,printerModel:ah(e.model)||void 0,nozzleDiameter:Jp(W,Vt.amsId),onSuccess:()=>{I.invalidateQueries({queryKey:[`slotPresets`,e.id]}),I.invalidateQueries({queryKey:[`printerStatus`,e.id]})}}),Yr&&(0,G.jsx)(BAe,{slotLabel:Yr.slotLabel,amsId:Yr.amsId,slotId:Yr.slotId,extruderSlots:W?.extruder_slots??{},isLoading:qr.isPending,onConfirm:e=>qr.mutate({trayId:Yr.trayId,extruderId:e}),onCancel:()=>Xr(null)}),ae&&(0,G.jsx)(bje,{printer:e,onClose:()=>oe(!1)}),Ut&&rn&&(0,G.jsx)(yje,{printer:e,firmwareInfo:rn,onClose:()=>Wt(!1)}),Qe!==null&>&&(()=>{let e=et===`n3s`?85:65,t=e+10;return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`fixed inset-0 z-[100]`,"data-testid":`drying-popover-backdrop`,onMouseDown:()=>{St.current=xt.current!==null&&document.activeElement===xt.current},onClick:()=>{if(St.current){St.current=!1;return}$e(null)}}),(0,G.jsxs)(`div`,{className:`fixed z-[101] flex flex-col w-[240px] bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl shadow-2xl overflow-hidden`,style:{left:gt.left,...gt.placement===`above`?{bottom:`calc(100dvh - ${gt.anchorY}px)`,maxHeight:`${gt.anchorY-8}px`}:{top:gt.top,maxHeight:`calc(100dvh - ${gt.top}px - 8px)`}},onClick:e=>e.stopPropagation(),children:[(0,G.jsxs)(`div`,{className:`shrink-0 flex items-center justify-center gap-2 px-3 py-2.5`,children:[(0,G.jsx)(uc,{className:`w-[var(--pc-i35,0.875rem)] h-[var(--pc-i35,0.875rem)] text-bambu-green`}),(0,G.jsx)(`span`,{className:`text-sm text-white font-medium text-center`,children:F(`printers.drying.start`)})]}),(0,G.jsx)(`div`,{className:`shrink-0 h-px bg-bambu-dark-tertiary`}),(0,G.jsxs)(`div`,{className:`px-3 py-2.5 space-y-2.5 overflow-y-auto min-h-0`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`text-[length:var(--pc-t10,10px)] text-white/70 font-medium mb-1 block`,children:F(`printers.filaments`)}),(0,G.jsx)(iW,{value:nt,options:Object.keys(S).map(e=>({value:e,label:e})),onChange:e=>{rt(e);let t=S[e];t&&(at(t[et===`n3s`?`n3s`:`n3f`]),st(et===`n3s`?t.n3s_hours:t.n3f_hours))},fullWidth:!0})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-1`,children:[(0,G.jsx)(`label`,{className:`text-[length:var(--pc-t10,10px)] text-white/70 font-medium`,children:F(`printers.drying.temperature`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(nm,{min:45,max:e,value:it,onChange:at,fallback:45,className:`w-12 px-1 py-0.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-[length:var(--pc-t11,11px)] text-center focus:outline-none focus:border-bambu-green [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none`}),(0,G.jsx)(`span`,{className:`text-[length:var(--pc-t10,10px)] text-bambu-gray`,children:`°C`})]})]}),(0,G.jsx)(`input`,{type:`range`,min:35,max:t,value:it,onChange:t=>at(Math.min(e,Math.max(45,Number(t.target.value)))),className:`w-full h-1 accent-bambu-green cursor-pointer`}),(0,G.jsxs)(`div`,{className:`flex justify-between text-[length:var(--pc-t9,9px)] text-bambu-gray/50 mt-0.5`,children:[(0,G.jsx)(`span`,{children:`45°C`}),(0,G.jsxs)(`span`,{children:[e,`°C`]})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-1`,children:[(0,G.jsx)(`label`,{className:`text-[length:var(--pc-t10,10px)] text-white/70 font-medium`,children:F(`printers.drying.duration`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(nm,{min:1,max:24,value:ot,onChange:st,fallback:1,className:`w-10 px-1 py-0.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-[length:var(--pc-t11,11px)] text-center focus:outline-none focus:border-bambu-green [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none`}),(0,G.jsx)(`span`,{className:`text-[length:var(--pc-t10,10px)] text-bambu-gray`,children:F(`printers.drying.hours`)})]})]}),(0,G.jsx)(`input`,{type:`range`,min:1,max:24,value:ot,onChange:e=>st(Number(e.target.value)),className:`w-full h-1 accent-bambu-green cursor-pointer`}),(0,G.jsxs)(`div`,{className:`flex justify-between text-[length:var(--pc-t9,9px)] text-bambu-gray/50 mt-0.5`,children:[(0,G.jsx)(`span`,{children:`1h`}),(0,G.jsx)(`span`,{children:`24h`})]})]}),(()=>{let e=((Qe===null?void 0:Dn.find(e=>e.id===Qe))?.tray??[]).some(e=>e.state===11),t=ct&&!e;return(0,G.jsx)(`button`,{type:`button`,onClick:()=>lt(e=>!e),"aria-pressed":t,disabled:e,title:e?F(`printers.drying.rotateUnavailableReason`):void 0,className:`h-8 w-full rounded-lg border px-2 text-sm font-medium transition-colors disabled:cursor-not-allowed disabled:opacity-50 ${t?`bg-bambu-green border-bambu-green text-white`:`bg-bambu-dark border-bambu-dark-tertiary text-white hover:bg-bambu-dark-tertiary disabled:hover:bg-bambu-dark`}`,children:F(`printers.drying.rotateTray`)})})(),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`text-[10px] text-white/70 font-medium mb-1 block`,children:F(`printers.drying.startMode`)}),(0,G.jsx)(`div`,{className:`grid grid-cols-3 gap-1`,children:[`now`,`delay`,`at_time`].map(e=>(0,G.jsx)(`button`,{type:`button`,onClick:()=>dt(e),className:`py-1 rounded-lg border text-[10px] font-medium transition-colors ${ut===e?`bg-bambu-green border-bambu-green text-white`:`bg-bambu-dark border-bambu-dark-tertiary text-white hover:bg-bambu-dark-tertiary`}`,children:F(e===`now`?`printers.drying.modeNow`:e===`delay`?`printers.drying.modeDelay`:`printers.drying.modeAtTime`)},e))}),ut===`delay`&&(0,G.jsx)(`div`,{className:`mt-1.5 grid grid-cols-4 gap-1`,children:WAe.map(e=>(0,G.jsx)(`button`,{type:`button`,"aria-pressed":ft===e,onClick:()=>pt(e),className:`py-1 rounded-lg border text-[10px] font-medium transition-colors ${ft===e?`bg-bambu-green border-bambu-green text-white`:`bg-bambu-dark border-bambu-dark-tertiary text-white hover:bg-bambu-dark-tertiary`}`,children:gp(e/60)},e))}),ut===`at_time`&&(0,G.jsx)(`input`,{ref:xt,type:`datetime-local`,"data-testid":`drying-start-at`,value:mt,onChange:e=>ht(e.target.value),className:`mt-1.5 w-full px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-[11px] focus:outline-none focus:border-bambu-green [color-scheme:dark]`})]})]}),(0,G.jsx)(`div`,{className:`shrink-0 h-px bg-bambu-dark-tertiary`}),(0,G.jsx)(`div`,{className:`shrink-0 px-3 pt-2.5 pb-3`,children:(0,G.jsx)(`button`,{onClick:()=>{if(Qe!==null){let e=(Dn.find(e=>e.id===Qe)?.tray??[]).some(e=>e.state===11),t=ct&&!e;if(ut===`now`)sr.mutate({amsId:Qe,temp:it,duration:ot,filament:nt,rotateTray:t});else{let e=kte(ut,ft,mt);e&&cr.mutate({amsId:Qe,temp:it,duration:ot,filament:nt,rotateTray:t,startAfter:e})}}},disabled:sr.isPending||cr.isPending||ut===`at_time`&&!mt,"data-testid":`drying-start-confirm`,className:`w-full py-1.5 bg-bambu-green hover:bg-bambu-green/80 text-white text-xs font-medium rounded-lg transition-colors disabled:opacity-50`,children:ut===`now`?sr.isPending?F(`printers.drying.startingDrying`):F(`printers.drying.start`):F(`printers.drying.schedule`)})})]}),(0,G.jsx)(`div`,{className:`fixed z-[102] w-2.5 h-2.5 rotate-45 bg-bambu-dark-secondary border-bambu-dark-tertiary pointer-events-none`,style:{left:gt.left+gt.arrowLeft-5,top:gt.anchorY-5,...gt.placement===`above`?{borderRightWidth:1,borderBottomWidth:1}:{borderLeftWidth:1,borderTopWidth:1}}})]})})()]})}function vje({onClose:e,onAdd:t,existingSerials:n}){let{t:r}=U(),[i,a]=(0,f.useState)({name:``,serial_number:``,ip_address:``,access_code:``,model:``,location:``,auto_archive:!0}),[o,s]=(0,f.useState)(!1),[c,l]=(0,f.useState)([]),[u,d]=(0,f.useState)(``),[p,m]=(0,f.useState)(!1),[h,g]=(0,f.useState)(!1),[_,v]=(0,f.useState)([]),[y,b]=(0,f.useState)(``),[x,S]=(0,f.useState)(``),[C,w]=(0,f.useState)(!1),[T,E]=(0,f.useState)({scanned:0,total:0}),[D,O]=(0,f.useState)(!1),[k,A]=(0,f.useState)(!1),[j,M]=(0,f.useState)(null);(0,f.useEffect)(()=>{Td.getInfo().then(e=>{g(e.is_docker),e.subnets.length>0&&(v(e.subnets),b(e.subnets[0]))}).catch(()=>{});try{let e=localStorage.getItem(`bambuddy.discovery.customSubnet`);e&&S(e)}catch{}},[]);let N=c.filter(e=>!n.includes(e.serial)),P=async e=>{e.preventDefault(),A(!0);try{let e=await Z.diagnoseConnection({ip_address:i.ip_address.trim(),serial_number:i.serial_number.trim()||void 0,access_code:i.access_code||void 0});if(e.checks.some(e=>e.status===`fail`)){M(e);return}}catch{}finally{A(!1)}t(i)},F=async()=>{d(``),l([]),s(!0),m(!1),E({scanned:0,total:0});let e=C?x.trim():y,t=h||C;if(t&&C)try{localStorage.setItem(`bambuddy.discovery.customSubnet`,e)}catch{}try{if(t){await Td.startSubnetScan(e);let t=setInterval(async()=>{try{let e=await Td.getScanStatus();E({scanned:e.scanned,total:e.total}),l(await Td.getDiscoveredPrinters()),e.running||(clearInterval(t),s(!1),m(!0))}catch(e){console.error(`Failed to get scan status:`,e)}},500)}else{await Td.startDiscovery(10);let e=setInterval(async()=>{try{l(await Td.getDiscoveredPrinters())}catch(e){console.error(`Failed to get discovered printers:`,e)}},1e3);setTimeout(async()=>{clearInterval(e);try{await Td.stopDiscovery()}catch{}s(!1),m(!0);try{l(await Td.getDiscoveredPrinters())}catch(e){console.error(`Failed to get final discovered printers:`,e)}},1e4)}}catch(e){console.error(`Failed to start discovery:`,e),d(e instanceof Error?e.message:r(`printers.discovery.failedToStart`)),s(!1),m(!0)}},I=e=>{let t=e.serial.startsWith(`unknown-`)?``:e.serial;a({...i,name:e.name||``,serial_number:t,ip_address:e.ip_address,model:ah(e.model)}),l([])};return(0,f.useEffect)(()=>()=>{Td.stopDiscovery().catch(()=>{}),Td.stopSubnetScan().catch(()=>{})},[]),(0,f.useEffect)(()=>{let t=t=>{t.key===`Escape`&&e()};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e]),(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-start sm:items-center justify-center z-50 p-4 overflow-y-auto`,onClick:e,children:(0,G.jsx)(Ud,{className:`w-full max-w-md my-auto max-h-[calc(100vh-2rem)] overflow-y-auto`,onClick:e=>e.stopPropagation(),children:(0,G.jsxs)(Gd,{children:[(0,G.jsx)(`h2`,{className:`text-xl font-semibold mb-4`,children:r(`printers.addPrinter`)}),(0,G.jsxs)(`div`,{className:`mb-4 pb-4 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`mb-3`,children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`printers.discovery.subnetToScan`)}),_.length>0?(0,G.jsxs)(`select`,{className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none text-sm`,value:C?`__custom__`:y,onChange:e=>{e.target.value===`__custom__`?w(!0):(w(!1),b(e.target.value))},disabled:o,children:[_.map(e=>(0,G.jsx)(`option`,{value:e,children:e},e)),(0,G.jsx)(`option`,{value:`__custom__`,children:r(`printers.discovery.customSubnetOption`)})]}):(0,G.jsx)(`input`,{type:`text`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none text-sm`,value:y,onChange:e=>b(e.target.value),placeholder:`192.168.1.0/24`,disabled:o}),C&&(0,G.jsx)(`input`,{type:`text`,"aria-label":r(`printers.discovery.customSubnetLabel`),className:`mt-2 w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none text-sm`,value:x,onChange:e=>S(e.target.value),placeholder:`10.1.1.0/24`,disabled:o}),(0,G.jsx)(`p`,{className:`mt-1 text-xs text-bambu-gray`,children:r(h?`printers.discovery.dockerNote`:`printers.discovery.customSubnetNote`)})]}),(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:F,disabled:o,className:`w-full`,children:o?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),(h||C)&&T.total>0?r(`printers.discovery.scanProgress`,{scanned:T.scanned,total:T.total}):r(`printers.discovery.scanning`)]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Yl,{className:`w-4 h-4`}),r(h||C?`printers.discovery.scanSubnet`:`printers.discovery.discoverNetwork`)]})}),u&&(0,G.jsx)(`div`,{className:`mt-2 text-sm text-red-700 dark:text-red-400`,children:u}),N.length>0&&(0,G.jsx)(`div`,{className:`mt-3 space-y-2 max-h-40 overflow-y-auto`,children:N.map(e=>(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-2 bg-bambu-dark rounded-lg hover:bg-bambu-dark-secondary cursor-pointer transition-colors`,onClick:()=>I(e),children:[(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,G.jsx)(`p`,{className:`font-medium text-white text-sm truncate`,children:e.name||e.serial}),(0,G.jsxs)(`p`,{className:`text-xs text-bambu-gray truncate`,children:[ah(e.model)||r(`printers.discovery.unknown`),` • `,e.ip_address,e.serial.startsWith(`unknown-`)&&(0,G.jsxs)(`span`,{className:`text-yellow-500`,children:[` • `,r(`printers.discovery.serialRequired`)]})]})]}),(0,G.jsx)(ss,{className:`w-4 h-4 text-bambu-gray -rotate-90 flex-shrink-0 ml-2`})]},e.serial))}),o&&(0,G.jsx)(`p`,{className:`mt-2 text-sm text-bambu-gray text-center`,children:r(h||C?`printers.discovery.scanningSubnet`:`printers.discovery.scanningNetwork`)}),p&&!o&&c.length===0&&(0,G.jsx)(`p`,{className:`mt-2 text-sm text-bambu-gray text-center`,children:r(h||C?`printers.discovery.noPrintersFoundSubnet`:`printers.discovery.noPrintersFoundNetwork`)}),p&&!o&&c.length>0&&N.length===0&&(0,G.jsx)(`p`,{className:`mt-2 text-sm text-bambu-gray text-center`,children:r(`printers.discovery.allConfigured`)})]}),(0,G.jsxs)(`form`,{onSubmit:P,className:`space-y-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`printers.name`)}),(0,G.jsx)(`input`,{type:`text`,required:!0,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,value:i.name,onChange:e=>a({...i,name:e.target.value}),placeholder:r(`printers.modal.myPrinter`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`printers.ipAddress`)}),(0,G.jsx)(`input`,{type:`text`,required:!0,pattern:`(\\d{1,3}(\\.\\d{1,3}){3}|[a-zA-Z0-9]([a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9])?(\\.[a-zA-Z0-9]([a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9])?)*)`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,value:i.ip_address,onChange:e=>a({...i,ip_address:e.target.value}),placeholder:`192.168.1.100 or printer.local`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`printers.serialNumber`)}),(0,G.jsx)(`input`,{type:`text`,required:!0,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,value:i.serial_number,onChange:e=>a({...i,serial_number:e.target.value}),placeholder:`01P00A000000000`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`printers.accessCode`)}),(0,G.jsx)(`input`,{type:`password`,required:!0,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,value:i.access_code,onChange:e=>a({...i,access_code:e.target.value}),placeholder:r(`printers.modal.fromPrinterSettings`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`printers.modal.modelOptional`)}),(0,G.jsxs)(`select`,{className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,value:i.model||``,onChange:e=>a({...i,model:e.target.value}),children:[(0,G.jsx)(`option`,{value:``,children:r(`printers.modal.selectModel`)}),(0,G.jsxs)(`optgroup`,{label:`A1 Series`,children:[(0,G.jsx)(`option`,{value:`A1`,children:`A1`}),(0,G.jsx)(`option`,{value:`A1 Mini`,children:`A1 Mini`})]}),(0,G.jsx)(`optgroup`,{label:`A2 Series`,children:(0,G.jsx)(`option`,{value:`A2L`,children:`A2L`})}),(0,G.jsxs)(`optgroup`,{label:`H2 Series`,children:[(0,G.jsx)(`option`,{value:`H2C`,children:`H2C`}),(0,G.jsx)(`option`,{value:`H2D`,children:`H2D`}),(0,G.jsx)(`option`,{value:`H2D Pro`,children:`H2D Pro`}),(0,G.jsx)(`option`,{value:`H2S`,children:`H2S`})]}),(0,G.jsxs)(`optgroup`,{label:`P Series`,children:[(0,G.jsx)(`option`,{value:`P1P`,children:`P1P`}),(0,G.jsx)(`option`,{value:`P1S`,children:`P1S`}),(0,G.jsx)(`option`,{value:`P2S`,children:`P2S`})]}),(0,G.jsxs)(`optgroup`,{label:`X1 Series`,children:[(0,G.jsx)(`option`,{value:`X1`,children:`X1`}),(0,G.jsx)(`option`,{value:`X1C`,children:`X1 Carbon`}),(0,G.jsx)(`option`,{value:`X1E`,children:`X1E`})]}),(0,G.jsx)(`optgroup`,{label:`X2 Series`,children:(0,G.jsx)(`option`,{value:`X2D`,children:`X2D`})})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`printers.modal.locationGroup`)}),(0,G.jsx)(`input`,{type:`text`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,value:i.location||``,onChange:e=>a({...i,location:e.target.value}),placeholder:r(`printers.modal.locationPlaceholder`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:r(`printers.locationHelp`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`input`,{type:`checkbox`,id:`auto_archive`,checked:i.auto_archive,onChange:e=>a({...i,auto_archive:e.target.checked}),className:`rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,G.jsx)(`label`,{htmlFor:`auto_archive`,className:`text-sm text-bambu-gray`,children:r(`printers.modal.autoArchiveLabel`)})]}),(0,G.jsxs)(`button`,{type:`button`,onClick:()=>O(!0),disabled:!i.ip_address.trim(),className:`w-full flex items-center justify-center gap-2 px-3 py-2 text-sm text-bambu-gray hover:text-white disabled:opacity-40 disabled:cursor-not-allowed border border-bambu-dark-tertiary rounded-lg transition-colors`,children:[(0,G.jsx)(yu,{className:`w-4 h-4`}),r(`diagnostic.runButton`)]}),j?(0,G.jsxs)(`div`,{className:`rounded-lg bg-amber-50 dark:bg-amber-500/10 border border-amber-300 dark:border-amber-500/30 p-3 space-y-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,G.jsx)(Lu,{className:`w-4 h-4 mt-0.5 flex-shrink-0 text-amber-600 dark:text-amber-400`}),(0,G.jsx)(`p`,{className:`text-sm text-amber-700 dark:text-amber-300`,children:r(`printers.addPreflight.warning`)})]}),(0,G.jsx)(zm,{result:j}),(0,G.jsxs)(`div`,{className:`flex gap-3`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:()=>M(null),className:`flex-1`,children:r(`printers.addPreflight.back`)}),(0,G.jsx)(Q,{type:`button`,onClick:()=>t(i),className:`flex-1`,children:r(`printers.addPreflight.saveAnyway`)})]})]}):(0,G.jsxs)(`div`,{className:`flex gap-3 pt-2`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:e,className:`flex-1`,children:r(`common.cancel`)}),(0,G.jsx)(Q,{type:`submit`,disabled:k,className:`flex-1`,children:r(k?`printers.addPreflight.checking`:`printers.addPrinter`)})]})]})]})})}),D&&(0,G.jsx)(Bm,{connection:{ip_address:i.ip_address.trim(),serial_number:i.serial_number.trim()||void 0,access_code:i.access_code||void 0},printerName:i.name||null,onClose:()=>O(!1)})]})}function yje({printer:e,firmwareInfo:t,onClose:n}){let{t:r}=U(),i=no(),{showToast:a}=Zd(),{hasPermission:o}=Ld(),s=o(`firmware:update`),[c,l]=(0,f.useState)(null),[u,d]=(0,f.useState)(!1),[p,m]=(0,f.useState)(null),[h,g]=(0,f.useState)(t.update_available?t.latest_version:null),{data:_,isLoading:v}=K({queryKey:[`firmwarePrepare`,e.id,h],queryFn:()=>kd.prepareUpload(e.id,h??void 0),staleTime:3e4,enabled:!!h&&s&&!u}),y=q({mutationFn:()=>kd.startUpload(e.id,h??void 0),onSuccess:()=>{d(!0);let t=setInterval(async()=>{try{let n=await kd.getUploadStatus(e.id);l(n),(n.status===`complete`||n.status===`error`)&&(clearInterval(t),m(null),d(!1),n.status===`complete`&&(a(r(`printers.firmwareModal.uploadedToast`),`success`),i.invalidateQueries({queryKey:[`firmwareUpdate`,e.id]})))}catch{}},2e3);m(t)},onError:e=>{a(r(`printers.firmwareModal.uploadFailed`,{error:e.message}),`error`),d(!1)}});return(0,f.useEffect)(()=>()=>{p&&clearInterval(p)},[p]),(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50`,children:(0,G.jsx)(Ud,{className:`w-full max-w-md mx-4`,children:(0,G.jsxs)(Gd,{children:[(0,G.jsxs)(`div`,{className:`flex items-start gap-3 mb-4`,children:[(0,G.jsx)(`div`,{className:`p-2 rounded-full ${t.update_available?`bg-orange-100 dark:bg-orange-500/20`:`bg-status-ok/20`}`,children:t.update_available?(0,G.jsx)(Gs,{className:`w-5 h-5 text-orange-600 dark:text-orange-400`}):(0,G.jsx)(hs,{className:`w-5 h-5 text-status-ok`})}),(0,G.jsxs)(`div`,{className:`flex-1`,children:[(0,G.jsx)(`h3`,{className:`text-lg font-semibold text-white`,children:t.update_available?r(`printers.firmwareModal.title`):r(`printers.firmwareModal.titleUpToDate`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:e.name})]})]}),(()=>{let e=h?t.available_versions?.find(e=>e.version===h):null,n=h??t.latest_version,i=e?.release_notes??t.release_notes,a=!!n&&n!==t.current_version;return(0,G.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-3 mb-4`,children:[(0,G.jsxs)(`div`,{className:`flex justify-between items-center text-sm`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:r(`printers.firmwareModal.currentVersion`)}),(0,G.jsx)(`span`,{className:`font-mono ${a?`text-white`:`text-status-ok`}`,children:t.current_version||r(`common.unknown`)})]}),a&&(0,G.jsxs)(`div`,{className:`flex justify-between items-center text-sm mt-1`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:r(`printers.firmwareModal.latestVersion`)}),(0,G.jsx)(`span`,{className:`text-orange-700 dark:text-orange-400 font-mono`,children:n})]}),i&&(0,G.jsxs)(`details`,{className:`mt-3 text-sm`,open:!a,children:[(0,G.jsx)(`summary`,{className:`cursor-pointer hover:underline ${a?`text-orange-700 dark:text-orange-400`:`text-status-ok`}`,children:r(`printers.firmwareModal.releaseNotes`)}),(0,G.jsx)(`div`,{className:`mt-2 text-bambu-gray text-xs max-h-40 overflow-y-auto whitespace-pre-wrap`,children:i})]},n??`none`)]})})(),t.available_versions&&t.available_versions.length>0&&!u&&c?.status!==`complete`&&(0,G.jsxs)(`div`,{className:`mb-4`,children:[(0,G.jsx)(`div`,{className:`text-xs text-bambu-gray mb-2`,children:r(`printers.firmwareModal.availableVersions`)}),(0,G.jsx)(`div`,{className:`max-h-56 overflow-y-auto border border-bambu-dark-tertiary rounded-lg divide-y divide-bambu-dark-tertiary`,children:t.available_versions.map(e=>{let n=t.current_version===e.version,i=h===e.version,a=t.current_version?yte(e.version,t.current_version):0,o=r(n?`printers.firmwareModal.currentBadge`:a>0?`printers.firmwareModal.newerBadge`:`printers.firmwareModal.olderBadge`),c=n?`text-bambu-gray`:a>0?`text-orange-700 dark:text-orange-400`:`text-blue-700 dark:text-blue-400`;return(0,G.jsxs)(`button`,{type:`button`,disabled:!e.file_available||!s||n,onClick:()=>g(e.version),className:`w-full text-left px-3 py-2 text-sm flex items-center justify-between gap-2 transition-colors ${i?`bg-orange-50 dark:bg-orange-500/10`:`hover:bg-bambu-dark`} ${!e.file_available||!s||n?`opacity-60 cursor-not-allowed`:`cursor-pointer`}`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,G.jsx)(`span`,{className:`font-mono text-white`,children:e.version}),(0,G.jsx)(`span`,{className:`text-xs ${c}`,children:o})]}),(0,G.jsx)(`span`,{className:`text-xs px-2 py-0.5 rounded-full ${n?`bg-blue-50 dark:bg-blue-500/15 text-blue-700 dark:text-blue-400 border border-blue-300 dark:border-blue-500/30`:e.file_available?`bg-bambu-green/15 text-bambu-green border border-bambu-green/30`:`bg-bambu-gray/10 text-bambu-gray border border-bambu-gray/30`}`,children:n?r(`printers.firmwareModal.installed`):e.file_available?r(`printers.firmwareModal.usable`):r(`printers.firmwareModal.unavailable`)})]},e.version)})})]}),h?v?(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray text-sm mb-4`,children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),r(`printers.firmwareModal.checkingPrereqs`)]}):_&&!u&&!c?(0,G.jsx)(`div`,{className:`mb-4`,children:_.can_proceed?(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-green text-sm`,children:[(0,G.jsx)(Wo,{className:`w-4 h-4`}),r(`printers.firmwareModal.sdCardReady`)]}):(0,G.jsx)(`div`,{className:`space-y-1`,children:_.errors.map((e,t)=>(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-red-700 dark:text-red-400 text-sm`,children:[(0,G.jsx)(ps,{className:`w-4 h-4 flex-shrink-0`}),e]},t))})}):null:null,(u||c)&&c&&(0,G.jsxs)(`div`,{className:`mb-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between text-sm mb-1`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray capitalize`,children:c.status}),(0,G.jsxs)(`span`,{className:`text-white`,children:[c.progress,`%`]})]}),(0,G.jsx)(`div`,{className:`w-full bg-bambu-dark-tertiary rounded-full h-2`,children:(0,G.jsx)(`div`,{className:`h-2 rounded-full transition-all ${c.status===`error`?`bg-status-error`:c.status===`complete`?`bg-status-ok`:`bg-orange-500`} ${c.status===`uploading`?`animate-pulse`:``}`,style:{width:`${c.progress}%`}})}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:c.message}),c.error&&(0,G.jsx)(`p`,{className:`text-xs text-red-700 dark:text-red-400 mt-1`,children:c.error})]}),c?.status===`complete`&&(0,G.jsxs)(`div`,{className:`bg-bambu-green/10 border border-bambu-green/30 rounded-lg p-3 mb-4`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-green font-medium mb-2`,children:r(`printers.firmwareModal.uploadedSuccess`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:r(`printers.firmwareModal.applyInstructions`)}),(0,G.jsxs)(`ol`,{className:`text-xs text-bambu-gray mt-1 list-decimal list-inside space-y-1`,children:[(0,G.jsx)(`li`,{dangerouslySetInnerHTML:{__html:r(`printers.firmwareModal.step1`)}}),(0,G.jsx)(`li`,{dangerouslySetInnerHTML:{__html:r(`printers.firmwareModal.step2`)}}),(0,G.jsx)(`li`,{dangerouslySetInnerHTML:{__html:r(`printers.firmwareModal.step3`)}}),(0,G.jsx)(`li`,{children:r(`printers.firmwareModal.step4`)})]})]}),(0,G.jsxs)(`div`,{className:`flex gap-2 justify-end`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:n,children:c?.status===`complete`?r(`printers.firmwareModal.done`):r(`common.cancel`)}),_?.can_proceed&&!u&&c?.status!==`complete`&&s&&(0,G.jsx)(Q,{onClick:()=>{l(null),y.mutate()},disabled:y.isPending,children:y.isPending?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin mr-2`}),r(`printers.firmwareModal.starting`)]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Gs,{className:`w-4 h-4 mr-2`}),r(`printers.firmwareModal.uploadFirmware`)]})})]})]})})})}function bje({printer:e,onClose:t}){let{t:n}=U(),r=no(),{showToast:i}=Zd(),[a,o]=(0,f.useState)({name:e.name,ip_address:e.ip_address,access_code:``,model:e.model||``,location:e.location||``,auto_archive:e.auto_archive,is_active:e.is_active}),[s,c]=(0,f.useState)(!1),[l,u]=(0,f.useState)(null),d=q({mutationFn:t=>Z.updatePrinter(e.id,t),onSuccess:()=>{r.invalidateQueries({queryKey:[`printers`]}),r.invalidateQueries({queryKey:[`printerStatus`,e.id]}),t()},onError:e=>i(e.message||n(`printers.toast.failedToUpdate`),`error`)});(0,f.useEffect)(()=>{let e=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]);let p=()=>{let e={name:a.name,ip_address:a.ip_address,model:a.model||void 0,location:a.location||void 0,auto_archive:a.auto_archive,is_active:a.is_active};a.access_code&&(e.access_code=a.access_code),d.mutate(e)};return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-start sm:items-center justify-center z-50 p-4 overflow-y-auto`,onClick:t,children:(0,G.jsx)(Ud,{className:`w-full max-w-md my-auto max-h-[calc(100vh-2rem)] overflow-y-auto`,onClick:e=>e.stopPropagation(),children:(0,G.jsxs)(Gd,{children:[(0,G.jsx)(`h2`,{className:`text-xl font-semibold mb-4`,children:n(`printers.editPrinter`)}),(0,G.jsxs)(`form`,{onSubmit:async t=>{t.preventDefault(),c(!0);try{let t=await Z.diagnoseConnection({ip_address:a.ip_address.trim(),serial_number:e.serial_number,access_code:a.access_code||void 0});if(t.checks.some(e=>e.status===`fail`)){u(t);return}}catch{}finally{c(!1)}p()},className:`space-y-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`printers.name`)}),(0,G.jsx)(`input`,{type:`text`,required:!0,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,value:a.name,onChange:e=>o({...a,name:e.target.value}),placeholder:n(`printers.modal.myPrinter`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`printers.ipAddress`)}),(0,G.jsx)(`input`,{type:`text`,required:!0,pattern:`(\\d{1,3}(\\.\\d{1,3}){3}|[a-zA-Z0-9]([a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9])?(\\.[a-zA-Z0-9]([a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9])?)*)`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,value:a.ip_address,onChange:e=>o({...a,ip_address:e.target.value}),placeholder:`192.168.1.100 or printer.local`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`printers.serialNumber`)}),(0,G.jsx)(`input`,{type:`text`,disabled:!0,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray cursor-not-allowed`,value:e.serial_number}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(`printers.serialCannotBeChanged`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`printers.accessCode`)}),(0,G.jsx)(`input`,{type:`password`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,value:a.access_code,onChange:e=>o({...a,access_code:e.target.value}),placeholder:n(`printers.accessCodePlaceholder`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`printers.model`)}),(0,G.jsxs)(`select`,{className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,value:a.model,onChange:e=>o({...a,model:e.target.value}),children:[(0,G.jsx)(`option`,{value:``,children:n(`printers.modal.selectModel`)}),(0,G.jsxs)(`optgroup`,{label:`A1 Series`,children:[(0,G.jsx)(`option`,{value:`A1`,children:`A1`}),(0,G.jsx)(`option`,{value:`A1 Mini`,children:`A1 Mini`})]}),(0,G.jsx)(`optgroup`,{label:`A2 Series`,children:(0,G.jsx)(`option`,{value:`A2L`,children:`A2L`})}),(0,G.jsxs)(`optgroup`,{label:`H2 Series`,children:[(0,G.jsx)(`option`,{value:`H2C`,children:`H2C`}),(0,G.jsx)(`option`,{value:`H2D`,children:`H2D`}),(0,G.jsx)(`option`,{value:`H2D Pro`,children:`H2D Pro`}),(0,G.jsx)(`option`,{value:`H2S`,children:`H2S`})]}),(0,G.jsxs)(`optgroup`,{label:`P Series`,children:[(0,G.jsx)(`option`,{value:`P1P`,children:`P1P`}),(0,G.jsx)(`option`,{value:`P1S`,children:`P1S`}),(0,G.jsx)(`option`,{value:`P2S`,children:`P2S`})]}),(0,G.jsxs)(`optgroup`,{label:`X1 Series`,children:[(0,G.jsx)(`option`,{value:`X1`,children:`X1`}),(0,G.jsx)(`option`,{value:`X1C`,children:`X1 Carbon`}),(0,G.jsx)(`option`,{value:`X1E`,children:`X1E`})]}),(0,G.jsx)(`optgroup`,{label:`X2 Series`,children:(0,G.jsx)(`option`,{value:`X2D`,children:`X2D`})})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:`Location / Group`}),(0,G.jsx)(`input`,{type:`text`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,value:a.location,onChange:e=>o({...a,location:e.target.value}),placeholder:n(`printers.modal.locationPlaceholder`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(`printers.locationHelp`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`input`,{type:`checkbox`,id:`edit_auto_archive`,checked:a.auto_archive,onChange:e=>o({...a,auto_archive:e.target.checked}),className:`rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,G.jsx)(`label`,{htmlFor:`edit_auto_archive`,className:`text-sm text-bambu-gray`,children:n(`printers.modal.autoArchiveLabel`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`input`,{type:`checkbox`,id:`edit_maintenance_mode`,checked:!a.is_active,onChange:e=>o({...a,is_active:!e.target.checked}),className:`rounded border-bambu-dark-tertiary bg-bambu-dark text-amber-400 focus:ring-amber-400`}),(0,G.jsxs)(`label`,{htmlFor:`edit_maintenance_mode`,className:`text-sm text-bambu-gray flex items-center gap-1.5`,children:[(0,G.jsx)(td,{className:`w-3.5 h-3.5 text-amber-600 dark:text-amber-400`}),n(`printers.maintenance.editFieldLabel`)]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray/70 mt-1 ml-6`,children:n(`printers.maintenance.editFieldHelp`)})]}),l?(0,G.jsxs)(`div`,{className:`rounded-lg bg-amber-50 dark:bg-amber-500/10 border border-amber-300 dark:border-amber-500/30 p-3 space-y-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,G.jsx)(Lu,{className:`w-4 h-4 mt-0.5 flex-shrink-0 text-amber-600 dark:text-amber-400`}),(0,G.jsx)(`p`,{className:`text-sm text-amber-700 dark:text-amber-300`,children:n(`printers.addPreflight.warning`)})]}),(0,G.jsx)(zm,{result:l}),(0,G.jsxs)(`div`,{className:`flex gap-3`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:()=>u(null),className:`flex-1`,children:n(`printers.addPreflight.back`)}),(0,G.jsx)(Q,{type:`button`,onClick:p,className:`flex-1`,disabled:d.isPending,children:n(`printers.addPreflight.saveAnyway`)})]})]}):(0,G.jsxs)(`div`,{className:`flex gap-3 pt-4`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:t,className:`flex-1`,children:n(`common.cancel`)}),(0,G.jsx)(Q,{type:`submit`,className:`flex-1`,disabled:d.isPending||s,children:s?n(`printers.addPreflight.checking`):d.isPending?n(`common.saving`):n(`printers.modal.saveChanges`)})]})]})]})})})}function xje(e){let{data:t}=K({queryKey:[`printerStatus`,e],queryFn:()=>Z.getPrinterStatus(e),refetchInterval:3e4});return!t?.connected}function Sje({printer:e,plug:t,onPowerOn:n,isPowering:r}){let i=xje(e.id),{data:a}=K({queryKey:[`smartPlugStatus`,t.id],queryFn:()=>Z.getSmartPlugStatus(t.id),refetchInterval:1e4});return i?(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-2 hover:bg-gray-100 dark:hover:bg-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,G.jsx)(`span`,{className:`text-sm text-white truncate`,children:e.name}),a&&(0,G.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded ${a.state===`ON`?`bg-bambu-green/20 text-bambu-green`:`bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400`}`,children:a.state||`?`})]}),(0,G.jsxs)(`button`,{onClick:()=>n(t.id),disabled:r||a?.state===`ON`,className:`px-2 py-1 text-xs rounded transition-colors flex items-center gap-1 ${a?.state===`ON`?`bg-bambu-green/20 text-bambu-green cursor-default`:`bg-bambu-green/20 text-bambu-green hover:bg-bambu-green hover:text-white`}`,children:[(0,G.jsx)(Pl,{className:`w-3 h-3`}),r?`...`:`On`]})]}):null}function Cje(){let{t:e}=U(),{resolvedMode:t,darkAccent:n,lightAccent:r}=Bd(),i={green:`bg-green-500 text-white hover:bg-green-400 border-green-400/60`,teal:`bg-teal-500 text-white hover:bg-teal-400 border-teal-400/60`,blue:`bg-blue-500 text-white hover:bg-blue-400 border-blue-400/60`,orange:`bg-orange-500 text-white hover:bg-orange-400 border-orange-400/60`,purple:`bg-purple-500 text-white hover:bg-purple-400 border-purple-400/60`,red:`bg-red-500 text-white hover:bg-red-400 border-red-400/60`}[t===`dark`?n:r],[a,o]=(0,f.useState)(!1),[s,c]=(0,f.useState)(()=>localStorage.getItem(`hideDisconnectedPrinters`)===`true`),[l,u]=(0,f.useState)(!1),[d,p]=(0,f.useState)(null),[m,h]=(0,f.useState)(()=>localStorage.getItem(`printerSortBy`)||`name`),[g,_]=(0,f.useState)(()=>localStorage.getItem(`printerSortAsc`)!==`false`),[v,y]=(0,f.useState)(()=>{let e=localStorage.getItem(`printerCardSize`);return e?parseInt(e,10):2}),[b,x]=(0,f.useState)(()=>localStorage.getItem(`printerPageView`)===`camwall`?`camwall`:`cards`),[S,C]=(0,f.useState)(()=>{let e=parseInt(localStorage.getItem(`camWallMaxLive`)||``,10);return Number.isFinite(e)&&e>0?e:4}),[w,T]=(0,f.useState)(()=>{let e=parseInt(localStorage.getItem(`camWallSnapshotSec`)||``,10);return Number.isFinite(e)&&e>0?e:8}),[E,D]=(0,f.useState)(()=>{let e=localStorage.getItem(`camWallStatusMode`);return e===`off`||e===`compact`||e===`full`?e:`full`}),O=v===1?`compact`:`expanded`,[k,A]=(0,f.useState)(null),j=(0,f.useCallback)(e=>{requestAnimationFrame(()=>{requestAnimationFrame(()=>{let t=document.getElementById(`printer-card-${e}`);if(!t)return;let n=document.querySelector(`header`)?.getBoundingClientRect().height??56,r=t.getBoundingClientRect().top+window.scrollY-n-16;window.scrollTo({top:Math.max(0,r),behavior:`smooth`})})})},[]),M=(0,f.useCallback)(e=>{A(e),y(2),localStorage.setItem(`printerCardSize`,`2`),j(e)},[j]),N=(0,f.useCallback)(()=>{let e=k;A(null),y(1),localStorage.setItem(`printerCardSize`,`1`),e!=null&&j(e)},[k,j]),[P,F]=(0,f.useState)(``),[I,L]=(0,f.useState)(()=>{let e=localStorage.getItem(`printerStatusFilter`);return XAe(e)?e:`all`}),[R,z]=(0,f.useState)(()=>localStorage.getItem(`printerLocationFilter`)||`all`),[B,V]=(0,f.useState)(0),[ee,te]=(0,f.useState)(()=>{try{let e=localStorage.getItem(`printerCollapsedSections`);return e?JSON.parse(e):{}}catch{return{}}}),ne=no(),{showToast:re}=Zd(),{hasPermission:ie}=Ld(),[ae,oe]=(0,f.useState)(()=>Tte()),[se,H]=(0,f.useState)(()=>{let e=localStorage.getItem(`openEmbeddedCameras`);if(e)try{let t=JSON.parse(e);return new Map(t.map(e=>[e.id,e]))}catch{return new Map}return new Map});(0,f.useEffect)(()=>{let e=Array.from(se.values());e.length>0?localStorage.setItem(`openEmbeddedCameras`,JSON.stringify(e)):localStorage.removeItem(`openEmbeddedCameras`)},[se]);let{data:ce,isLoading:le}=K({queryKey:[`printers`],queryFn:Z.getPrinters}),{data:ue}=K({queryKey:[`ui-preferences`],queryFn:Z.getUiPreferences}),de=(0,f.useMemo)(()=>ph(ue?.nozzle_temp_presets,lh,0,320),[ue?.nozzle_temp_presets]),fe=(0,f.useMemo)(()=>ph(ue?.bed_temp_presets,uh,0,140),[ue?.bed_temp_presets]),pe=(0,f.useMemo)(()=>ph(ue?.chamber_temp_presets,dh,0,65),[ue?.chamber_temp_presets]),me=(0,f.useMemo)(()=>ph(ue?.fan_speed_presets,fh,0,100),[ue?.fan_speed_presets]),he=(0,f.useMemo)(()=>{if(ue?.drying_presets)try{let e=JSON.parse(ue.drying_presets);if(typeof e==`object`&&e&&Object.keys(e).length>0)return{...dW,...e}}catch{}return dW},[ue?.drying_presets]),ge=ae??(ue?.camera_view_mode===`embedded`?`embedded`:`window`),_e=(0,f.useCallback)(e=>{Ete(e),oe(e),ie(`settings:update`)&&Z.updateSettings({camera_view_mode:e}).then(()=>ne.invalidateQueries({queryKey:[`ui-preferences`]})).catch(e=>console.warn(`Could not save camera view mode as the default:`,e))},[ie,ne]),{data:ve}=K({queryKey:[`smart-plugs`],queryFn:Z.getSmartPlugs}),{data:ye}=K({queryKey:[`maintenanceOverview`],queryFn:Z.getMaintenanceOverview,staleTime:60*1e3}),{data:be}=K({queryKey:[`obico-printer-status`],queryFn:Z.getObicoPrinterStatus,refetchInterval:1e4}),xe=(0,f.useCallback)(e=>be?.enabled===!0&&(be.monitored_printers===null||be.monitored_printers.includes(e)),[be]),{data:Se}=K({queryKey:[`spoolman-status`],queryFn:Z.getSpoolmanStatus,staleTime:60*1e3}),Ce=Se?.enabled&&Se?.connected,{data:we}=K({queryKey:[`spoolman-settings`],queryFn:Z.getSpoolmanSettings,enabled:!!Ce,staleTime:60*1e3}),Te=we?.spoolman_sync_mode,{data:Ee}=K({queryKey:[`unlinked-spools`],queryFn:Z.getUnlinkedSpools,enabled:!!Ce,staleTime:30*1e3}),De=Ee&&Ee.length>0,{data:Oe}=K({queryKey:[`linked-spools`],queryFn:Z.getLinkedSpools,enabled:!!Ce,staleTime:30*1e3}),ke=Oe?.linked,{data:Ae}=K({queryKey:[`spool-assignments`],queryFn:()=>Z.getAssignments(),enabled:ie(`inventory:view_assignments`),staleTime:30*1e3}),je=q({mutationFn:({printerId:e,amsId:t,trayId:n})=>Z.unassignSpool(e,t,n),onSuccess:()=>{ne.invalidateQueries({queryKey:[`spool-assignments`]})}}),{data:Me,isLoading:Ne}=K({queryKey:[`spoolman-inventory-spools`],queryFn:()=>Z.getSpoolmanInventorySpools(!1),enabled:!!Ce,staleTime:30*1e3}),{data:Pe,isLoading:Fe}=K({queryKey:[`spoolman-slot-assignments`],queryFn:()=>Z.getSpoolmanSlotAssignments(),enabled:!!Ce,staleTime:30*1e3}),Ie=q({mutationFn:e=>Z.unassignSpoolmanSlot(e),onSuccess:()=>{ne.invalidateQueries({queryKey:[`spoolman-inventory-spools`]}),ne.invalidateQueries({queryKey:[`spoolman-slot-assignments`]})}}),Le=(e,t,n)=>Ae?.find(r=>r.printer_id===e&&r.ams_id===Number(t)&&r.tray_id===Number(n)),Re=ye?.reduce((e,t)=>(e[t.printer_id]={due_count:t.due_count,warning_count:t.warning_count,total_print_hours:t.total_print_hours},e),{})||{},ze=ve?.reduce((e,t)=>(t.printer_id&&(e[t.printer_id]=t),e),{})||{},Be=q({mutationFn:Z.createPrinter,onSuccess:()=>{ne.invalidateQueries({queryKey:[`printers`]}),ne.invalidateQueries({queryKey:[`maintenanceOverview`]}),o(!1)},onError:t=>{if(t instanceof sd&&t.code===`printer_connection_failed`){re(e(`printers.toast.connectionFailedNotAdded`),`error`);return}re(t.message||e(`printers.toast.failedToAdd`),`error`)}}),Ve=q({mutationFn:e=>Z.controlSmartPlug(e,`on`),onSuccess:()=>{ne.invalidateQueries({queryKey:[`smart-plugs`]}),p(null)},onError:()=>{p(null)}}),[He,Ue]=(0,f.useState)(new Set),[We,Ge]=(0,f.useState)(!1),[Ke,qe]=(0,f.useState)(null),[Je,Ye]=(0,f.useState)(!1),Xe=We||He.size>0,Ze=(0,f.useCallback)(e=>{Ue(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),Qe=(0,f.useCallback)(()=>{Ue(new Set),Ge(!1)},[]);(0,f.useEffect)(()=>{let e=e=>{e.key===`Escape`&&Xe&&Qe()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[Xe,Qe]);let $e=(0,f.useCallback)(async t=>{Ye(!0);let n=Array.from(He).filter(e=>{let n=ne.getQueryData([`printerStatus`,e]);if(t===`clearPlate`)return!!n?.awaiting_plate_clear;if(!n?.connected)return!1;switch(t){case`stop`:return n.state===`RUNNING`||n.state===`PAUSE`;case`pause`:return n.state===`RUNNING`;case`resume`:return n.state===`PAUSE`;case`clearHMS`:return n.hms_errors&&bh(n.hms_errors).length>0;default:return!1}});if(n.length===0){re(e(`printers.bulk.noneApplicable`),`error`),Ye(!1),qe(null);return}let r={stop:Z.stopPrint,pause:Z.pausePrint,resume:Z.resumePrint,clearPlate:Z.clearPlate,clearHMS:Z.clearHMSErrors}[t],i=await Promise.allSettled(n.map(e=>r(e))),a=i.filter(e=>e.status===`fulfilled`).length,o=i.filter(e=>e.status===`rejected`).length;o===0?re(e(`printers.bulk.success`,{action:e(`printers.bulk.actions.${t}`),count:a})):re(e(`printers.bulk.partial`,{succeeded:a,failed:o}),`error`),n.forEach(e=>{ne.invalidateQueries({queryKey:[`printerStatus`,e]})}),Ye(!1),qe(null)},[He,ne,re,e]),et=(0,f.useCallback)(e=>{e===`stop`||e===`pause`||e===`clearPlate`?qe(e):$e(e)},[$e]),tt=()=>{let e=!s;c(e),localStorage.setItem(`hideDisconnectedPrinters`,String(e))},nt=e=>{h(e),localStorage.setItem(`printerSortBy`,e)},rt=e=>{L(e),localStorage.setItem(`printerStatusFilter`,e)},it=e=>{z(e),localStorage.setItem(`printerLocationFilter`,e)},at=()=>{let e=!g;_(e),localStorage.setItem(`printerSortAsc`,String(e))},ot=()=>{switch(v){case 1:return`grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5`;case 2:return`grid-cols-1 md:grid-cols-2 xl:grid-cols-3`;case 3:return`grid-cols-1 lg:grid-cols-2`;case 4:return`grid-cols-1`;default:return`grid-cols-1 md:grid-cols-2 xl:grid-cols-3`}},st=[`S`,`M`,`L`,`XL`];(0,f.useEffect)(()=>ne.getQueryCache().subscribe(e=>{e.type===`updated`&&Array.isArray(e.query.queryKey)&&e.query.queryKey[0]===`printerStatus`&&V(e=>e+1)}),[ne]);let ct=(0,f.useMemo)(()=>{if(!ce)return[];let e=ce;if(P.trim()){let t=P.trim().toLowerCase();e=e.filter(e=>e.name.toLowerCase().includes(t)||(e.model||``).toLowerCase().includes(t)||(e.location||``).toLowerCase().includes(t)||(e.serial_number||``).toLowerCase().includes(t))}return R!==`all`&&(e=e.filter(e=>(e.location||``)===R)),I!==`all`&&(e=e.filter(e=>{let t=ne.getQueryData([`printerStatus`,e.id]);if(!t?.connected)return I===`offline`;let n=t.hms_errors?bh(t.hms_errors):[];switch(I){case`printing`:return t.state===`RUNNING`;case`paused`:return t.state===`PAUSE`;case`finished`:return t.state===`FINISH`;case`error`:return t.state===`FAILED`||n.length>0;case`idle`:return t.state!==`RUNNING`&&t.state!==`PAUSE`&&t.state!==`FINISH`&&t.state!==`FAILED`&&n.length===0;case`offline`:return!1;default:return!0}})),e},[ce,P,I,R,ne,B]),lt=(0,f.useMemo)(()=>ce?[...new Set(ce.map(e=>e.location||``).filter(Boolean))].sort():[],[ce]);(0,f.useEffect)(()=>{!ce||R===`all`||lt.includes(R)||(z(`all`),localStorage.setItem(`printerLocationFilter`,`all`))},[ce,lt,R]);let ut=(0,f.useMemo)(()=>{let e=[...ct];switch(m){case`name`:e.sort((e,t)=>e.name.localeCompare(t.name));break;case`model`:e.sort((e,t)=>(e.model||``).localeCompare(t.model||``));break;case`location`:e.sort((e,t)=>{let n=e.location||``,r=t.location||``;return!n&&r?1:n&&!r?-1:n.localeCompare(r)||e.name.localeCompare(t.name)});break;case`status`:e.sort((e,t)=>{let n=ne.getQueryData([`printerStatus`,e.id]),r=ne.getQueryData([`printerStatus`,t.id]),i=e=>e?.connected?(e.hms_errors?bh(e.hms_errors):[]).length>0?0:e.state===`RUNNING`?1:2:3;return i(n)-i(r)});break;case`eta`:e.sort((e,t)=>{let n=ne.getQueryData([`printerStatus`,e.id]),r=ne.getQueryData([`printerStatus`,t.id]),i=e=>e?.connected?e.state===`RUNNING`&&e.remaining_time!=null&&e.remaining_time>0?0:e.state===`RUNNING`?1:2:3,a=i(n),o=i(r);if(a!==o)return a-o;if(a===0){let e=(n.remaining_time??0)-(r.remaining_time??0);if(e!==0)return e}return e.name.localeCompare(t.name)});break}return g||e.reverse(),e},[ct,m,g,ne]),dt=(0,f.useCallback)(()=>{Ue(new Set(ut.map(e=>e.id))),Ge(!0)},[ut]),ft=(0,f.useCallback)(e=>{Ue(t=>{let n=new Set(t);return ut.forEach(t=>{lW(ne.getQueryData([`printerStatus`,t.id]))===e&&n.add(t.id)}),n}),Ge(!0)},[ut,ne]),pt=(0,f.useCallback)(e=>{Ue(t=>{let n=new Set(t);return ut.filter(t=>(t.location||``)===e).forEach(e=>n.add(e.id)),n}),Ge(!0)},[ut]),mt=(0,f.useCallback)(e=>{Ue(t=>{let n=new Set(t);return ut.filter(t=>(t.model||`Unknown`)===e).forEach(e=>n.add(e.id)),n}),Ge(!0)},[ut]),ht=(0,f.useCallback)(e=>{te(t=>{let n={...t,[e]:!t[e]};try{localStorage.setItem(`printerCollapsedSections`,JSON.stringify(n))}catch{}return n})},[]),gt=(0,f.useMemo)(()=>{if(m===`name`||m===`eta`)return null;let e={};return m===`location`?ut.forEach(t=>{let n=t.location||`Ungrouped`;e[n]||(e[n]=[]),e[n].push(t)}):m===`model`?ut.forEach(t=>{let n=t.model||`Unknown`;e[n]||(e[n]=[]),e[n].push(t)}):m===`status`&&ut.forEach(t=>{let n=lW(ne.getQueryData([`printerStatus`,t.id]));e[n]||(e[n]=[]),e[n].push(t)}),e},[m,ut,ne,B]),_t=(0,f.useRef)(null),vt=(0,f.useRef)(null),yt=(0,f.useRef)(0),[bt,xt]=(0,f.useState)(!1),St=(0,f.useCallback)(()=>{let e=_t.current;if(!e)return;let t=vt.current?.offsetWidth;t&&(yt.current=t);let n=yt.current>0&&e.clientWidthe===n?e:n)},[]),Ct=Object.keys(ze).length;(0,f.useLayoutEffect)(()=>{St();let e=_t.current;if(!e)return;if(typeof ResizeObserver>`u`)return window.addEventListener(`resize`,St),()=>window.removeEventListener(`resize`,St);let t=new ResizeObserver(()=>St());return t.observe(e),window.addEventListener(`resize`,St),()=>{t.disconnect(),window.removeEventListener(`resize`,St)}},[St,ce?.length,lt.length,s,Ct]);let wt=(t=!1)=>(0,G.jsxs)(G.Fragment,{children:[ce&&ce.length>0&&(0,G.jsx)(iW,{value:I,onChange:rt,fullWidth:t,options:KU.map(t=>({value:t.value,label:e(t.labelKey)}))}),ce&&ce.length>0&<.length>0&&(0,G.jsx)(iW,{value:R,onChange:it,fullWidth:t,options:[{value:`all`,label:e(`printers.filter.allLocations`)},...lt.map(e=>({value:e,label:e}))]}),(0,G.jsx)(`button`,{type:`button`,onClick:tt,"aria-pressed":s,className:`h-8 px-2 rounded-lg border text-sm font-medium transition-colors ${t?`w-full`:``} ${s?`bg-bambu-green border-bambu-green text-white`:`bg-bambu-dark border-bambu-dark-tertiary text-white hover:bg-bambu-dark-tertiary`}`,children:e(`printers.hideOffline`)})]}),Tt=(t=!1)=>(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1 ${t?`w-full`:``}`,children:[(0,G.jsx)(iW,{value:m,onChange:nt,fullWidth:t,options:[{value:`name`,label:e(`printers.sort.name`)},{value:`status`,label:e(`printers.sort.status`)},{value:`model`,label:e(`printers.sort.model`)},{value:`location`,label:e(`printers.sort.location`)},{value:`eta`,label:e(`printers.sort.eta`)}]}),(0,G.jsx)(`button`,{onClick:at,className:`h-8 shrink-0 px-2 rounded-lg border bg-bambu-dark border-bambu-dark-tertiary text-white hover:bg-bambu-dark-tertiary transition-colors flex items-center justify-center`,title:e(g?`printers.sort.descending`:`printers.sort.ascending`),children:g?(0,G.jsx)(Io,{className:`w-4 h-4 text-white`}):(0,G.jsx)(Ao,{className:`w-4 h-4 text-white`})})]}),(0,G.jsxs)(`div`,{className:`flex h-8 items-center bg-bambu-dark rounded-lg border border-bambu-dark-tertiary ${t?`w-full`:``}`,children:[(0,G.jsxs)(`button`,{type:`button`,onClick:()=>{x(`cards`),localStorage.setItem(`printerPageView`,`cards`)},className:`flex h-full items-center gap-1 rounded-l-lg px-2 text-xs font-medium transition-colors ${t?`flex-1 justify-center`:``} ${b===`cards`?`bg-bambu-green text-white`:`text-white hover:bg-bambu-dark-tertiary`}`,title:e(`printers.pageView.cards`),"aria-pressed":b===`cards`,children:[(0,G.jsx)(Gc,{className:`w-3.5 h-3.5`}),t&&(0,G.jsx)(`span`,{children:e(`printers.pageView.cards`)})]}),(0,G.jsxs)(`button`,{type:`button`,onClick:()=>{x(`camwall`),localStorage.setItem(`printerPageView`,`camwall`)},className:`flex h-full items-center gap-1 rounded-r-lg px-2 text-xs font-medium transition-colors ${t?`flex-1 justify-center`:``} ${b===`camwall`?`bg-bambu-green text-white`:`text-white hover:bg-bambu-dark-tertiary`}`,title:e(`printers.pageView.camWall`),"aria-pressed":b===`camwall`,disabled:!ie(`camera:view`),children:[(0,G.jsx)(fl,{className:`w-3.5 h-3.5`}),t&&(0,G.jsx)(`span`,{children:e(`printers.pageView.camWall`)})]})]}),b===`camwall`&&ie(`camera:view`)&&(0,G.jsxs)(Ci,{to:`/camwall`,className:`flex h-8 items-center gap-1 rounded-lg border border-bambu-dark-tertiary bg-bambu-dark px-2 text-xs font-medium text-white transition-colors hover:bg-bambu-dark-tertiary ${t?`w-full justify-center`:``}`,title:e(`printers.pageView.openCamWallPage`),children:[(0,G.jsx)(Qs,{className:`w-3.5 h-3.5`}),t&&(0,G.jsx)(`span`,{children:e(`printers.pageView.openCamWallPage`)})]}),(0,G.jsx)(`div`,{className:`flex h-8 items-center bg-bambu-dark rounded-lg border border-bambu-dark-tertiary ${b===`camwall`?`opacity-40 pointer-events-none`:``} ${t?`w-full`:``}`,children:st.map((n,r)=>{let i=r+1,a=v===i;return(0,G.jsx)(`button`,{onClick:()=>{A(null),y(i),localStorage.setItem(`printerCardSize`,String(i))},className:`h-full px-2 text-xs font-medium transition-colors ${t?`flex-1`:``} ${r===0?`rounded-l-lg`:``} ${r===st.length-1?`rounded-r-lg`:``} ${a?`bg-bambu-green text-white`:`text-white hover:bg-bambu-dark-tertiary`}`,title:e(n===`S`?`printers.cardSize.small`:n===`M`?`printers.cardSize.medium`:n===`L`?`printers.cardSize.large`:`printers.cardSize.extraLarge`),children:n},n)})})]}),Et=(t=!1)=>(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`button`,{onClick:()=>{Xe?Qe():Ge(!0)},className:`h-8 px-2 rounded-lg border transition-colors ${t?`w-full justify-center gap-1.5 text-sm font-medium flex items-center`:``} ${Xe?`bg-bambu-green border-bambu-green text-white`:`bg-bambu-dark border-bambu-dark-tertiary text-white hover:bg-bambu-dark-tertiary`}`,title:e(`printers.bulk.select`),disabled:!ie(`printers:control`),children:[(0,G.jsx)(hu,{className:`w-4 h-4`}),t&&(0,G.jsx)(`span`,{children:e(`printers.bulk.select`)})]}),s&&Object.keys(ze).length>0&&(0,G.jsxs)(`div`,{className:`relative ${t?`w-full`:``}`,children:[(0,G.jsxs)(`button`,{onClick:()=>u(!l),className:`h-8 flex items-center gap-1.5 px-2 text-sm rounded-lg border transition-colors ${t?`w-full justify-between bg-bambu-dark border-bambu-dark-tertiary text-white hover:bg-bambu-dark-tertiary hover:text-white`:`bg-bambu-dark border-bambu-dark-tertiary text-white hover:bg-bambu-dark-tertiary`}`,children:[(0,G.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,G.jsx)(Pl,{className:`w-4 h-4`}),e(`printers.powerOn`)]}),(0,G.jsx)(ss,{className:`w-3 h-3 transition-transform ${l?`rotate-180`:``}`})]}),l&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`fixed inset-0 z-10`,onClick:()=>u(!1)}),(0,G.jsxs)(`div`,{className:`absolute right-0 mt-2 w-56 bg-white dark:bg-bambu-dark-secondary border border-gray-200 dark:border-bambu-dark-tertiary rounded-lg shadow-lg z-20 py-1`,children:[(0,G.jsx)(`div`,{className:`px-3 py-2 text-xs text-gray-500 dark:text-bambu-gray border-b border-gray-200 dark:border-bambu-dark-tertiary`,children:e(`printers.offlinePrintersWithPlugs`)}),ce?.filter(e=>ze[e.id]).map(e=>(0,G.jsx)(Sje,{printer:e,plug:ze[e.id],onPowerOn:e=>{p(e),Ve.mutate(e)},isPowering:d===ze[e.id]?.id},e.id)),ce?.filter(e=>ze[e.id]).length===0&&(0,G.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:`No printers with smart plugs`})]})]})]}),(0,G.jsxs)(Q,{onClick:()=>o(!0),disabled:!ie(`printers:create`),title:ie(`printers:create`)?void 0:e(`printers.permission.noAdd`),className:`!h-8 !min-h-8 px-2 py-0 ${t?`w-full`:``}`,children:[(0,G.jsx)(Ml,{className:`w-4 h-4`}),e(`printers.addPrinter`)]})]});return(0,G.jsxs)(`div`,{className:`p-4 md:p-8`,children:[(0,G.jsxs)(`div`,{className:`space-y-3 mb-6`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,G.jsx)(Fl,{className:`w-7 h-7 text-bambu-green`}),e(`printers.title`)]}),(0,G.jsx)(uje,{printers:ce})]}),(0,G.jsxs)(`div`,{ref:_t,className:`relative flex items-center gap-2`,children:[ce&&ce.length>0&&(0,G.jsxs)(`div`,{className:`relative min-w-0 flex-1`,children:[(0,G.jsx)(Yl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50`}),(0,G.jsx)(`input`,{type:`search`,name:`printer-search`,autoComplete:`off`,"data-1p-ignore":!0,"data-lpignore":`true`,value:P,onChange:e=>F(e.target.value),placeholder:e(`printers.search`),"aria-label":e(`printers.search`),className:`w-full h-8 pl-9 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`}),P&&(0,G.jsx)(`button`,{type:`button`,"aria-label":e(`common.clear`),onClick:()=>F(``),className:`absolute right-3 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white`,children:(0,G.jsx)(nd,{className:`w-4 h-4`})})]}),(0,G.jsxs)(`div`,{ref:vt,"aria-hidden":bt,inert:bt,className:`${bt?`absolute -left-[9999px] top-0 flex w-max pointer-events-none opacity-0`:`flex`} ml-auto items-center justify-end gap-2 flex-nowrap [&>*]:shrink-0`,children:[(0,G.jsx)(`div`,{className:`h-6 w-px bg-bambu-dark-tertiary`}),(0,G.jsx)(`div`,{className:`flex items-center gap-2`,children:wt()}),(0,G.jsx)(`div`,{className:`h-6 w-px bg-bambu-dark-tertiary`}),(0,G.jsx)(`div`,{className:`flex items-center gap-2`,children:Tt()}),(0,G.jsx)(`div`,{className:`h-6 w-px bg-bambu-dark-tertiary`}),(0,G.jsx)(`div`,{className:`flex items-center gap-2`,children:Et()})]}),bt&&(0,G.jsxs)(`div`,{className:`ml-auto flex items-center justify-end gap-1`,children:[(0,G.jsx)(aW,{label:e(`printers.toolbar.filters`,`Filters`),icon:(0,G.jsx)(yc,{className:`w-4 h-4`}),children:(0,G.jsx)(`div`,{className:`flex w-48 flex-col gap-2`,children:wt(!0)})}),(0,G.jsx)(aW,{label:e(`printers.toolbar.view`,`View`),icon:(0,G.jsx)(lu,{className:`w-4 h-4`}),children:(0,G.jsx)(`div`,{className:`flex w-48 flex-col gap-2`,children:Tt(!0)})}),(0,G.jsx)(aW,{label:e(`printers.toolbar.actions`,`Actions`),icon:(0,G.jsx)(Ys,{className:`w-4 h-4`}),children:(0,G.jsx)(`div`,{className:`flex w-48 flex-col gap-2`,children:Et(!0)})})]})]})]}),le?(0,G.jsx)(`div`,{className:`text-center py-12 text-bambu-gray`,children:e(`common.loading`)}):ce?.length===0?(0,G.jsx)(Ud,{children:(0,G.jsxs)(Gd,{className:`text-center py-12`,children:[(0,G.jsx)(`p`,{className:`text-bambu-gray mb-4`,children:e(`printers.noPrintersConfigured`)}),(0,G.jsxs)(Q,{onClick:()=>o(!0),disabled:!ie(`printers:create`),title:ie(`printers:create`)?void 0:e(`printers.permission.noAdd`),children:[(0,G.jsx)(Ml,{className:`w-4 h-4`}),e(`printers.addPrinter`)]})]})}):ut.length===0&&(P.trim()||I!==`all`||R!==`all`)?(0,G.jsx)(Ud,{children:(0,G.jsx)(Gd,{className:`text-center py-12`,children:(0,G.jsx)(`p`,{className:`text-bambu-gray`,children:e(`printers.noSearchResults`)})})}):b===`camwall`?(0,G.jsx)(qT,{printers:ut,maxLive:S,snapshotIntervalSec:w,onTileClick:(e,t)=>{ge===`embedded`?H(n=>new Map(n).set(e,{id:e,name:t})):ch(e)},statusMode:E,onChangeMaxLive:e=>{C(e),localStorage.setItem(`camWallMaxLive`,String(e))},onChangeSnapshotIntervalSec:e=>{T(e),localStorage.setItem(`camWallSnapshotSec`,String(e))},onChangeStatusMode:e=>{D(e),localStorage.setItem(`camWallStatusMode`,e)}}):gt?(0,G.jsx)(`div`,{className:`space-y-6`,children:(()=>{let e=m===`status`?fje.filter(e=>gt[e]?.length>0):Object.keys(gt);return g?e:[...e].reverse()})().map(t=>{let n=gt[t],r=`${m}:${t}`,i=!ee[r],a=m===`status`&&cW[t]?.dot||`bg-bambu-green`,o=m===`status`?e(cW[t]?.labelKey||t):t;return(0,G.jsx)(Vm,{open:i,onToggle:()=>ht(r),summaryClassName:`py-1`,summary:(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`w-2 h-2 rounded-full ${a}`}),o,(0,G.jsxs)(`span`,{className:`text-sm font-normal text-bambu-gray`,children:[`(`,n.length,`)`]}),Xe&&(0,G.jsx)(`button`,{onClick:e=>{e.stopPropagation(),m===`location`?pt(t===`Ungrouped`?``:t):m===`status`?ft(t):m===`model`&&mt(t)},className:`text-xs text-bambu-green hover:text-bambu-green-light transition-colors ml-1`,children:e(`printers.bulk.selectAll`)})]}),children:(0,G.jsx)(`div`,{className:`grid gap-4 ${v>=3?`gap-6`:``} ${ot()}`,children:n.map(e=>(0,G.jsx)(pW,{printer:e,hideIfDisconnected:s,maintenanceInfo:Re[e.id],viewMode:O,cardSize:v,amsThresholds:ue?{humidityGood:Number(ue.ams_humidity_good)||40,humidityFair:Number(ue.ams_humidity_fair)||60,tempGood:Number(ue.ams_temp_good)||28,tempFair:Number(ue.ams_temp_fair)||35}:void 0,spoolmanEnabled:Ce,hasUnlinkedSpools:De,linkedSpools:ke,spoolmanUrl:Se?.url,spoolmanSyncMode:Te,onGetAssignment:Le,onUnassignSpool:(e,t,n)=>je.mutate({printerId:e,amsId:t,trayId:n}),spoolmanSpools:Me,spoolmanSlotAssignments:Pe,spoolmanLoading:Ne||Fe,onUnassignSpoolmanSpool:e=>Ie.mutate(e),timeFormat:ue?.time_format||`system`,cameraViewMode:ge,onOpenEmbeddedCamera:(e,t)=>H(n=>new Map(n).set(e,{id:e,name:t})),onSelectCameraViewMode:_e,checkPrinterFirmware:ue?.check_printer_firmware!==!1,dryingPresets:he,nozzleTempPresets:de,bedTempPresets:fe,chamberTempPresets:pe,fanSpeedPresets:me,requirePlateClear:ue?.require_plate_clear===!0,selectionMode:Xe,isSelected:He.has(e.id),onToggleSelect:Ze,onOpenCompactCard:M,aiDetectionEnabled:xe(e.id),aiDetection:be?.enabled?be.per_printer[String(e.id)]:void 0,aiLastError:be?.last_error??null},e.id))})},t)})}):(0,G.jsx)(`div`,{className:`grid gap-4 ${v>=3?`gap-6`:``} ${ot()}`,children:ut.map(e=>(0,G.jsx)(pW,{printer:e,hideIfDisconnected:s,maintenanceInfo:Re[e.id],viewMode:O,cardSize:v,spoolmanEnabled:Ce,hasUnlinkedSpools:De,linkedSpools:ke,spoolmanUrl:Se?.url,spoolmanSyncMode:Te,onGetAssignment:Le,onUnassignSpool:(e,t,n)=>je.mutate({printerId:e,amsId:t,trayId:n}),spoolmanSpools:Me,spoolmanSlotAssignments:Pe,spoolmanLoading:Ne||Fe,onUnassignSpoolmanSpool:e=>Ie.mutate(e),amsThresholds:ue?{humidityGood:Number(ue.ams_humidity_good)||40,humidityFair:Number(ue.ams_humidity_fair)||60,tempGood:Number(ue.ams_temp_good)||28,tempFair:Number(ue.ams_temp_fair)||35}:void 0,timeFormat:ue?.time_format||`system`,cameraViewMode:ge,onOpenEmbeddedCamera:(e,t)=>H(n=>new Map(n).set(e,{id:e,name:t})),onSelectCameraViewMode:_e,checkPrinterFirmware:ue?.check_printer_firmware!==!1,dryingPresets:he,nozzleTempPresets:de,bedTempPresets:fe,chamberTempPresets:pe,fanSpeedPresets:me,requirePlateClear:ue?.require_plate_clear===!0,selectionMode:Xe,isSelected:He.has(e.id),onToggleSelect:Ze,onOpenCompactCard:M,aiDetectionEnabled:xe(e.id),aiDetection:be?.enabled?be.per_printer[String(e.id)]:void 0,aiLastError:be?.last_error??null},e.id))}),v===2&&k!=null&&(0,G.jsxs)(`button`,{type:`button`,onClick:N,className:`fixed bottom-5 left-1/2 z-40 inline-flex -translate-x-1/2 items-center gap-2 rounded-full border px-4 py-2 text-sm font-medium shadow-xl transition-colors ${i}`,title:e(`common.back`,`Back`),children:[(0,G.jsx)(jo,{className:`w-4 h-4`}),e(`common.back`,`Back`)]}),a&&(0,G.jsx)(vje,{onClose:()=>o(!1),onAdd:e=>Be.mutate(e),existingSerials:ce?.map(e=>e.serial_number)||[]}),Xe&&ce&&(0,G.jsx)(Vte,{selectedIds:He,printers:ce,onClose:Qe,onSelectAll:dt,onSelectByLocation:pt,onSelectByState:ft,onAction:et,actionPending:Je}),Ke===`stop`&&(0,G.jsx)(uf,{title:e(`printers.bulk.confirm.stopTitle`,{count:He.size}),message:e(`printers.bulk.confirm.stopMessage`,{count:He.size}),confirmText:e(`printers.bulk.confirm.stopButton`),variant:`danger`,isLoading:Je,onConfirm:()=>$e(`stop`),onCancel:()=>qe(null)}),Ke===`pause`&&(0,G.jsx)(uf,{title:e(`printers.bulk.confirm.pauseTitle`,{count:He.size}),message:e(`printers.bulk.confirm.pauseMessage`,{count:He.size}),confirmText:e(`printers.bulk.confirm.pauseButton`),isLoading:Je,onConfirm:()=>$e(`pause`),onCancel:()=>qe(null)}),Ke===`clearPlate`&&(0,G.jsx)(uf,{title:e(`printers.bulk.confirm.clearPlateTitle`,{count:He.size}),message:e(`printers.bulk.confirm.clearPlateMessage`,{count:He.size}),confirmText:e(`printers.bulk.confirm.clearPlateButton`),isLoading:Je,onConfirm:()=>$e(`clearPlate`),onCancel:()=>qe(null)}),Array.from(se.values()).map((e,t)=>(0,G.jsx)(Ole,{printerId:e.id,printerName:e.name,viewerIndex:t,onClose:()=>H(t=>{let n=new Map(t);return n.delete(e.id),n})},e.id))]})}function wje({title:e,message:t,subtitle:n,closeText:r,variant:i=`error`,onClose:a}){let{t:o}=U(),s=r??o(`common.close`);return(0,f.useEffect)(()=>{let e=e=>{e.key===`Escape`&&a()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[a]),(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center p-4 z-[120]`,onClick:a,children:(0,G.jsx)(Ud,{className:`w-full max-w-md`,onClick:e=>e.stopPropagation(),children:(0,G.jsxs)(Gd,{className:`p-6`,children:[(0,G.jsxs)(`div`,{className:`flex items-start gap-4`,children:[(0,G.jsx)(`div`,{className:`p-2 rounded-full bg-bambu-dark ${i===`warning`?`text-yellow-600 dark:text-yellow-400`:`text-red-600 dark:text-red-400`}`,children:(0,G.jsx)(Lu,{className:`w-6 h-6`})}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`h3`,{className:`text-lg font-semibold text-white mb-1`,children:e}),n&&(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2 truncate`,children:n}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-sm whitespace-pre-line break-words`,children:t})]})]}),(0,G.jsx)(`div`,{className:`flex mt-6`,children:(0,G.jsx)(Q,{onClick:a,className:`flex-1`,children:s})})]})})})}var mW=(0,f.createContext)(null),Tje=1500,Eje=1e3,hW=e=>`slice-job-${e}`;function gW(e){try{return decodeURIComponent(e)}catch{return e}}function Dje(e){let t=Math.max(0,Math.floor(e));if(t<60)return`${t}s`;let n=Math.floor(t/60),r=t%60;return n<60?`${n}m ${r}s`:`${Math.floor(n/60)}h ${n%60}m`}function Oje({children:e}){let{t}=U(),{showToast:n,showPersistentToast:r,dismissToast:i}=Zd(),a=no(),[o,s]=(0,f.useState)([]),[c,l]=(0,f.useState)(null),u=(0,f.useRef)([]);u.current=o;let d=(0,f.useRef)(new Map),p=(0,f.useRef)(new Map),m=(0,f.useRef)(new Map),h=(0,f.useRef)(new Set),g=(0,f.useCallback)(e=>{let n=d.current.get(e.id);if(n==null)return;let i=(Date.now()-n)/1e3,a=p.current.get(e.id)??`pending`,o=Dje(i),s=m.current.get(e.id)??null,c=s&&s.stage&&s.total_percent>0;if(a===`running`&&c){let n=gW(e.sourceName),i=s.stage,a=Math.min(100,Math.max(0,Math.round(s.total_percent))),c=typeof s.multi_plate_index==`number`&&typeof s.multi_plate_count==`number`&&s.multi_plate_count>1?t(`slice.runningWithProgressMultiPlate`,`Plate {{plateIndex}} of {{plateCount}} • {{name}} — {{stage}} ({{percent}}%) — {{elapsed}}`,{plateIndex:s.multi_plate_index,plateCount:s.multi_plate_count,name:n,stage:i,percent:a,elapsed:o}):t(`slice.runningWithProgress`,`{{name}} — {{stage}} ({{percent}}%) — {{elapsed}}`,{name:n,stage:i,percent:a,elapsed:o});r(hW(e.id),c,`loading`);return}let l=a===`pending`?`slice.queuedToast`:`slice.runningToast`,u=a===`pending`?`Queued: {{name}} — {{elapsed}}`:`Slicing {{name}} — {{elapsed}}`;r(hW(e.id),t(l,u,{name:gW(e.sourceName),elapsed:o}),`loading`)},[r,t]),_=(0,f.useCallback)((e,t,n)=>{s(r=>r.some(t=>t.id===e)?r:[...r,{id:e,kind:t,sourceName:n}]),h.current.delete(e),d.current.set(e,Date.now()),p.current.set(e,`pending`),m.current.set(e,null),g({id:e,kind:t,sourceName:n})},[g]),v=(0,f.useCallback)((e,r)=>{h.current.has(e.id)||(h.current.add(e.id),s(t=>t.filter(t=>t.id!==e.id)),d.current.delete(e.id),p.current.delete(e.id),m.current.delete(e.id),i(hW(e.id)),r.status===`completed`?(n(t(`slice.completedToast`,`Sliced {{name}}`,{name:gW(e.sourceName)}),`success`),r.result&&`external_write_fallback`in r.result&&r.result.external_write_fallback&&n(t(`slice.externalWriteFallbackToast`,`Saved to the internal library: the external folder could not be written to`),`warning`)):r.status===`failed`&&l({name:gW(e.sourceName),detail:r.error_detail||t(`slice.failed`)}),a.invalidateQueries({queryKey:[`library-files`]}),a.invalidateQueries({queryKey:[`archives`]}))},[i,a,n,t]);return(0,f.useEffect)(()=>{if(o.length===0)return;let e=!1,t=!1,n=setInterval(async()=>{if(!(e||t)){t=!0;try{let t=[...u.current];for(let n of t)try{let t=await Z.getSliceJob(n.id);if(e)return;p.current.set(n.id,t.status),t.progress&&m.current.set(n.id,t.progress),(t.status===`completed`||t.status===`failed`)&&v(n,t)}catch{}}finally{t=!1}}},Tje);return()=>{e=!0,clearInterval(n)}},[o.length,v]),(0,f.useEffect)(()=>{if(o.length===0)return;let e=setInterval(()=>{for(let e of u.current)g(e)},Eje);return()=>clearInterval(e)},[o.length,g]),(0,G.jsxs)(mW.Provider,{value:{trackJob:_,activeJobs:o},children:[e,c&&(0,G.jsx)(wje,{title:t(`slice.failedTitle`),subtitle:c.name,message:c.detail,onClose:()=>l(null)})]})}function _W(){let e=(0,f.useContext)(mW);if(!e)throw Error(`useSliceJobTracker must be used inside SliceJobTrackerProvider`);return e}var vW=1024;function kje(){let[e,t]=(0,f.useState)(()=>typeof window<`u`?window.innerWidth>=vW:!1);return(0,f.useEffect)(()=>{let e=window.matchMedia(`(min-width: ${vW}px)`),n=e=>{t(e.matches)};return t(e.matches),e.addEventListener(`change`,n),()=>e.removeEventListener(`change`,n)},[]),e}function yW({plates:e,onSelect:t,onClose:n}){let{t:r}=U();return(0,G.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-4`,onClick:n,children:(0,G.jsxs)(`div`,{className:`w-full max-w-3xl max-h-[85vh] flex flex-col rounded-lg bg-bambu-dark-secondary border border-bambu-dark-tertiary/60`,onClick:e=>e.stopPropagation(),children:[(0,G.jsxs)(`div`,{className:`flex-shrink-0 flex items-start justify-between gap-3 px-4 pt-4 pb-3 border-b border-bambu-dark-tertiary/40`,children:[(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsx)(`h3`,{className:`text-white font-medium`,children:r(`archives.platePicker.title`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:r(`archives.platePicker.hint`)})]}),(0,G.jsx)(`button`,{onClick:n,className:`flex-shrink-0 text-bambu-gray hover:text-white transition-colors`,"aria-label":r(`common.close`,`Close`),children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]}),(0,G.jsx)(`div`,{className:`flex-1 overflow-y-auto p-4`,children:(0,G.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-2`,children:e.map(e=>(0,G.jsxs)(`button`,{type:`button`,onClick:()=>t(e.index),className:`flex items-center gap-2 p-2 rounded-lg border border-bambu-dark-tertiary bg-bambu-dark hover:border-bambu-gray transition-colors text-left`,children:[e.has_thumbnail&&e.thumbnail_url!=null?(0,G.jsx)(`img`,{src:vd(e.thumbnail_url),alt:`Plate ${e.index}`,className:`w-12 h-12 rounded object-cover bg-bambu-dark-tertiary flex-shrink-0`}):(0,G.jsx)(`div`,{className:`w-12 h-12 rounded bg-bambu-dark-tertiary flex items-center justify-center flex-shrink-0`,children:(0,G.jsx)(Wc,{className:`w-5 h-5 text-bambu-gray`})}),(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,G.jsx)(`p`,{className:`text-sm text-white font-medium truncate`,children:e.name?`${r(`archives.platePicker.plateLabel`,{index:e.index})} — ${e.name}`:r(`archives.platePicker.plateLabel`,{index:e.index})}),(0,G.jsxs)(`p`,{className:`text-xs text-bambu-gray truncate`,children:[e.objects.length>0?e.objects.slice(0,3).join(`, `)+(e.objects.length>3?`…`:``):e.object_count!=null&&e.object_count>0?r(`archives.platePicker.objectCount`,{count:e.object_count}):`${e.filaments.length} filament${e.filaments.length===1?``:`s`}`,e.print_time_seconds==null?``:` • ${pp(e.print_time_seconds)}`]})]})]},e.index))})})]})})}var bW=e=>typeof e==`object`&&!!e&&`enumKey`in e,xW=`enum:`;function SW(e){if(typeof e==`number`)return e;if(typeof e==`boolean`)return+!!e;if(typeof e!=`string`)return;let t=Number.parseFloat(e);return Number.isFinite(t)?t:void 0}function CW(e){if(typeof e==`boolean`)return e;if(typeof e==`number`)return e!==0;if(e===`1`||e===`true`)return!0;if(e===`0`||e===`false`)return!1}function Aje(e,t){return{get:n=>{let r=e[n];if((r===void 0||r===``)&&(r=t[n]?.default),Array.isArray(r)&&(r=r[0]),typeof r==`boolean`||typeof r==`number`||typeof r==`string`)return r},has:e=>e in t}}var jje=[`->`,`||`,`&&`,`==`,`!=`,`<=`,`>=`,`(`,`)`,`,`,`<`,`>`,`!`];function Mje(e){let t=[],n=0;for(;n0||W.vt_tray.length>0)&&r===`expanded`&&(()=>{let t=Dn.filter(e=>e.tray.length>1),n=Dn.filter(e=>e.tray.length===1),r=Dn.length>0&&W.vt_tray.length>0,f=!(r&&Se),_=e.nozzle_count===2||W?.temperatures?.nozzle_2!==void 0,v=fW[i]??1,y=e=>`${Math.round(e*v*1e3)/1e3}rem`,b=`3.5rem`,x={minWidth:b},S={minWidth:b,maxWidth:y(7.25)},C=e=>({gridTemplateColumns:`repeat(${e}, minmax(${b}, 1fr))`}),w=(W.state===`RUNNING`||W.state===`PAUSE`)&&Array.isArray(W.ams_mapping)?W.ams_mapping:[],T=e=>{let t=Math.max(1,e),n=`calc(${t} * ${b} + ${Math.max(0,t-1)} * 0.25rem + 1rem)`;return{flex:`1 1 ${n}`,minWidth:n}};return(0,G.jsxs)(`div`,{className:`mt-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,G.jsx)(`span`,{className:`text-[length:var(--pc-t10,10px)] uppercase tracking-wider text-bambu-gray font-medium`,children:F(`printers.filaments`)}),(0,G.jsx)(oje,{state:W.ams_filament_backup,onClick:()=>xe(!0)}),(0,G.jsx)(`div`,{className:`flex-1 h-[2px] bg-bambu-dark-tertiary`}),r&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(sje,{hidden:Se,onClick:we}),(0,G.jsx)(`div`,{className:`w-3 h-[2px] bg-bambu-dark-tertiary`})]})]}),(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[t.map(t=>{let n=ZU(t.id,Sn,Tn,wn);return(0,G.jsxs)(`div`,{style:T(4),className:`min-w-0 p-2 bg-bambu-dark rounded-[10px] space-y-1`,children:[(0,G.jsxs)(`div`,{className:`flex w-full min-h-7 items-center justify-between gap-2 rounded-lg bg-bambu-dark-secondary px-2 py-1`,children:[(0,G.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center gap-1.5`,children:[(0,G.jsx)(uW,{ams:t,printerId:e.id,label:Cp(t.id,t.tray.length),amsLabels:mn,canEdit:z(`printers:update`),onSaved:hn,children:(0,G.jsx)(`span`,{className:`block truncate text-[length:var(--pc-t10,10px)] text-white font-medium cursor-default select-none`,children:mn?.[t.id]||Cp(t.id,t.tray.length)})}),n?.kind===`inlet`?(0,G.jsx)(XU,{inlet:n.inlet,title:F(`printers.amsSwitchInletTooltip`,{inlet:n.inlet,side:bp[n.inlet]})}):_&&n?.kind===`nozzle`?(0,G.jsx)(YU,{side:n.side}):null]}),(t.humidity!=null||t.temp!=null)&&(0,G.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1.5`,children:[t.humidity!=null&&(0,G.jsx)(nW,{humidity:t.humidity,goodThreshold:a?.humidityGood,fairThreshold:a?.humidityFair,onClick:()=>Pt({amsId:t.id,amsLabel:Cp(t.id,t.tray.length),mode:`humidity`}),compact:!0}),t.temp!=null&&(0,G.jsx)(`div`,{className:`mr-1`,children:(0,G.jsx)(rW,{temp:t.temp,goodThreshold:a?.tempGood,fairThreshold:a?.tempFair,onClick:()=>Pt({amsId:t.id,amsLabel:Cp(t.id,t.tray.length),mode:`temperature`}),compact:!0})}),(W.supports_drying||W.drying_screen_only)&&(t.module_type===`n3f`||t.module_type===`n3s`)&&z(`printers:control`)&&(0,G.jsx)(`button`,{disabled:W.drying_screen_only||!!(t.dry_sf_reason?.length&&t.dry_time===0),onClick:e=>{t.dry_time>0?lr.mutate(t.id):Qe===t.id?$e(null):bt(t,e.currentTarget)},className:`ml-1 flex items-center gap-0.5 px-1 py-0.5 rounded text-[length:var(--pc-t9,9px)] transition-colors ${t.dry_time>0?`bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-400`:W.drying_screen_only||t.dry_sf_reason?.length?`bg-bambu-dark text-bambu-gray/50 cursor-not-allowed`:`bg-bambu-dark text-bambu-gray hover:text-white hover:bg-bambu-dark/80`}`,title:W.drying_screen_only?F(`printers.drying.screenOnly`):t.dry_time>0?F(`printers.drying.stop`):t.dry_sf_reason?.length?F(YAe(t.dry_sf_reason)):F(`printers.drying.start`),children:(0,G.jsx)(uc,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)]`})})]})]}),t.dry_time>0&&t.dry_countdown_stalled&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2 rounded-lg bg-slate-100 dark:bg-slate-500/10 px-2 py-1 text-[length:var(--pc-t9,9px)]`,title:F(`printers.drying.notRunningHint`),children:[(0,G.jsx)(Fc,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)] text-slate-500 dark:text-slate-400 shrink-0`}),(0,G.jsx)(`span`,{className:`text-slate-600 dark:text-slate-300 font-medium`,children:F(`printers.drying.notRunning`)}),t.dry_filament&&(0,G.jsx)(`span`,{className:`text-slate-500/90 dark:text-slate-400/80`,children:t.dry_target_temp==null?t.dry_filament:F(`printers.drying.targetSummary`,{filament:t.dry_filament,temp:t.dry_target_temp})}),!W.drying_screen_only&&(0,G.jsx)(`button`,{onClick:()=>lr.mutate(t.id),disabled:lr.isPending,className:`ml-auto text-slate-500 dark:text-slate-400 hover:text-slate-700 dark:hover:text-slate-200 transition-colors disabled:opacity-50`,title:F(`printers.drying.stop`),children:(0,G.jsx)(nd,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)]`})})]}),t.dry_time>0&&!t.dry_countdown_stalled&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2 rounded-lg bg-amber-50 dark:bg-amber-500/10 px-2 py-1 text-[length:var(--pc-t9,9px)]`,children:[(0,G.jsx)(uc,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)] text-amber-600 dark:text-amber-400 shrink-0`}),(0,G.jsx)(`span`,{className:`text-amber-700 dark:text-amber-400 font-medium`,children:F(`printers.drying.active`)}),t.dry_filament&&(0,G.jsx)(`span`,{className:`text-amber-700/80 dark:text-amber-300/70`,children:t.dry_target_temp==null?t.dry_filament:F(`printers.drying.targetSummary`,{filament:t.dry_filament,temp:t.dry_target_temp})}),(0,G.jsx)(`span`,{className:`text-amber-700/80 dark:text-amber-300/70`,children:F(`printers.drying.timeRemaining`,{time:t.dry_time>=60?`${Math.floor(t.dry_time/60)}h ${t.dry_time%60}m`:`${t.dry_time}m`})}),!W.drying_screen_only&&(0,G.jsx)(`button`,{onClick:()=>lr.mutate(t.id),disabled:lr.isPending,className:`ml-auto text-amber-700 dark:text-amber-400 hover:text-amber-900 dark:hover:text-amber-300 transition-colors disabled:opacity-50`,title:F(`printers.drying.stop`),children:(0,G.jsx)(nd,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)]`})})]}),(0,G.jsx)(`div`,{className:`grid w-full gap-1`,style:C(4),children:[0,1,2,3].map(n=>{let r=t.tray[n]||t.tray.find(e=>e.id===n),i=r?.tray_type&&r.remain>=0,a=!r?.tray_type,f=Fp(r),_=t.id*4+n,v=jn===_,y=Mn!==null&&Mn===_,b=Nn!==null&&Nn===_,S=r?.tray_info_idx?ln?.[r.tray_info_idx]:null,C=un?.[_],T=Xp(C?.preset_id,r?.tray_info_idx)?C?.preset_name:void 0,E=(r?.tray_uuid||r?.tag_uid||Vp(e.serial_number,t.id,n))?.toUpperCase(),D=E?s?.[E]:void 0,O=zp(D),k=o&&!h?m?.find(r=>r.printer_id===e.id&&r.ams_id===t.id&&r.tray_id===n):void 0,A=k?p?.find(e=>e.id===k.spoolman_spool_id):void 0,j=A&&(A.label_weight??0)>0?Math.round(Math.max(0,(A.label_weight??0)-A.weight_used)/(A.label_weight??1)*100):null,M=u?.(e.id,t.id,n),N=(()=>{let e=M?.spool;return e&&e.label_weight>0&&e.weight_used!=null?Math.round(Math.max(0,e.label_weight-e.weight_used)/e.label_weight*100):null})(),P=N===0&&i&&r.remain>0?null:N,I=O??j??P??(i?r.remain:null),L=O!==null||j!==null?`spoolman`:P===null?i?`ams`:void 0:`inventory`,R=r?.tray_type?{vendor:Yp(r)?`Bambu Lab`:`Generic`,profile:T||(A?[A.brand,A.slicer_filament_name?.split(`@`)[0].trim()||A.material].filter(Boolean).join(` `).trim():null)||M?.spool?.slicer_filament_name||S?.name||r.tray_sub_brands||r.tray_type,colorName:jf(r.tray_color||``,r.tray_sub_brands),colorHex:r.tray_color||null,kFactor:qU(r.k),fillLevel:I,trayUuid:r.tray_uuid||null,tagUid:r.tag_uid||null,fillSource:L}:null,B=Vr?.amsId===t.id&&Vr?.slotId===n,V=w.indexOf(_),ee=V>=0?`P${V+1}`:null,te=(0,G.jsxs)(`div`,{className:`relative w-full bg-bambu-dark-secondary rounded-lg p-1 text-center ${a?`opacity-50`:``} ${y?`ring-2 ring-amber-400 ring-offset-1 ring-offset-bambu-dark animate-pulse`:b?`ring-2 ring-red-500/60 ring-offset-1 ring-offset-bambu-dark`:v?`ring-2 ring-bambu-green ring-offset-1 ring-offset-bambu-dark`:``}`,children:[y&&(0,G.jsx)(`span`,{"aria-label":F(`printers.expectedSlot.ariaLabel`,{n:n+1}),title:F(`printers.expectedSlot.title`),className:`absolute top-0.5 left-0.5 px-1 py-px text-[length:var(--pc-t8,8px)] font-bold text-bambu-dark bg-amber-400 rounded pointer-events-none leading-none`,children:`↓`}),ee&&(0,G.jsx)(`span`,{"aria-label":F(`printers.activeJobSlot.ariaLabel`,{n:V+1}),title:F(`printers.activeJobSlot.title`,{n:V+1}),className:`absolute top-0.5 right-0.5 px-1 py-px text-[length:var(--pc-t8,8px)] font-bold text-bambu-dark bg-bambu-green rounded pointer-events-none leading-none`,children:ee}),(0,G.jsx)(WU,{trayColor:r?.tray_color,trayType:r?.tray_type,isEmpty:a,emptyKind:f,slotNumber:n+1}),(0,G.jsx)(`div`,{className:`text-[length:var(--pc-t9,9px)] text-white font-bold truncate`,children:r?.tray_type||F(f===`reset`?`ams.slotUnconfigured`:`ams.slotEmpty`)}),(0,G.jsx)(JU,{k:R?r?.k:null,reserve:On}),(0,G.jsx)(`div`,{className:`mt-1 h-1.5 bg-black/30 rounded-full overflow-hidden`,children:I!==null&&I>=0&&!a&&r&&(0,G.jsx)(`div`,{className:`h-full rounded-full transition-all`,style:{width:`${I}%`,backgroundColor:Rp(I)}})})]});return(0,G.jsxs)(`div`,{className:`relative group w-full`,style:x,children:[B&&(0,G.jsx)(`div`,{className:`absolute inset-0 bg-bambu-dark-tertiary/80 rounded flex items-center justify-center z-20`,children:(0,G.jsx)(zl,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)] text-bambu-green animate-spin`})}),R?(0,G.jsx)(GH,{data:R,actions:Ei({amsId:t.id,slotId:n,loadTrayId:t.id*4+n,isRefreshing:B}),spoolman:{enabled:o,linkedSpoolId:k?.spoolman_spool_id??(E?s?.[E]?.id:void 0),spoolmanUrl:c,syncMode:l,onLinkSpool:o&&!k&&!M?()=>{let r=(R.trayUuid||R.tagUid||Vp(e.serial_number,t.id,n)).toUpperCase();Rt({tagUid:R.tagUid||r,trayUuid:R.trayUuid||``,printerId:e.id,amsId:t.id,trayId:n})}:void 0,onUnlinkSpool:D?.id?()=>or.mutate(D.id):void 0},inventory:(()=>{if(o){if(h)return;let i=k,a=A;return{assignedSpool:a?{id:a.id,material:a.material,subtype:a.subtype,brand:a.brand??null,color_name:a.color_name??null,color_name_is_synthesized:a.color_name_is_synthesized,rgba:a.rgba??null,extra_colors:a.extra_colors??null,effect_type:a.effect_type??null,remainingWeightGrams:a.label_weight?Math.max(0,Math.round(a.label_weight-a.weight_used)):void 0}:null,onAssignSpool:()=>Bt({printerId:e.id,amsId:t.id,trayId:n,trayInfo:{type:r?.tray_type||R.profile,material:r?.tray_type??void 0,profile:R.profile,color:R.colorHex||``,location:`${Cp(t.id,t.tray.length)} Slot ${n+1}`}}),onUnassignSpool:a&&!Yp(r)?()=>g?.(a.id):void 0,isAssigned:!!i||Yp(r)}}let i=u?.(e.id,t.id,n);return{assignedSpool:i?.spool?{id:i.spool.id,material:i.spool.material,subtype:i.spool.subtype,brand:i.spool.brand,color_name:i.spool.color_name,rgba:i.spool.rgba??null,extra_colors:i.spool.extra_colors??null,effect_type:i.spool.effect_type??null,remainingWeightGrams:Math.max(0,Math.round(i.spool.label_weight-i.spool.weight_used))}:null,onAssignSpool:()=>Bt({printerId:e.id,amsId:t.id,trayId:n,trayInfo:{type:r?.tray_type||R.profile,material:r?.tray_type??void 0,profile:R.profile,color:R.colorHex||``,location:`${Cp(t.id,t.tray.length)} Slot ${n+1}`}}),onUnassignSpool:i&&!Yp(r)?()=>d?.(e.id,t.id,n):void 0,isAssigned:!!i||Yp(r)}})(),configureSlot:{enabled:z(`printers:control`),onConfigure:()=>Ht({amsId:t.id,trayId:n,trayCount:t.tray.length,trayType:r?.tray_type||void 0,trayColor:r?.tray_color||void 0,traySubBrands:r?.tray_sub_brands||void 0,trayInfoIdx:r?.tray_info_idx||void 0,extruderId:Sp(t.id,r?.id??0,Sn,Tn),caliIdx:r?.cali_idx,savedPresetId:C?.preset_id})},children:te}):(0,G.jsx)(KH,{kind:f??void 0,actions:Ei({amsId:t.id,slotId:n,loadTrayId:t.id*4+n,isRefreshing:B}),configureSlot:{enabled:z(`printers:control`),onConfigure:()=>Ht({amsId:t.id,trayId:n,trayCount:t.tray.length,extruderId:Sp(t.id,r?.id??0,Sn,Tn)})},onAssignSpool:()=>Bt({printerId:e.id,amsId:t.id,trayId:n,trayInfo:{type:``,material:void 0,profile:``,color:``,location:`${Cp(t.id,t.tray.length)} Slot ${n+1}`}}),children:te})]},n)})})]},t.id)}),n.map(t=>{let n=ZU(t.id,Sn,Tn,wn),r=t.tray[0],i=r?.tray_type&&r.remain>=0,f=!r?.tray_type,v=Fp(r),x=Lp(t.id,r?.id??0,!1),C=jn===x,T=Mn!==null&&Mn===x,E=Nn!==null&&Nn===x,D=r?.tray_info_idx?ln?.[r.tray_info_idx]:null,O=un?.[x],k=Xp(O?.preset_id,r?.tray_info_idx)?O?.preset_name:void 0,A=r?.id??0,j=(r?.tray_uuid||r?.tag_uid||Vp(e.serial_number,t.id,A))?.toUpperCase(),M=j?s?.[j]:void 0,N=zp(M),P=u?.(e.id,t.id,A),I=(()=>{let e=P?.spool;return e&&e.label_weight>0&&e.weight_used!=null?Math.round(Math.max(0,e.label_weight-e.weight_used)/e.label_weight*100):null})(),L=I===0&&i&&r.remain>0?null:I,R=o&&!h?m?.find(n=>n.printer_id===e.id&&n.ams_id===t.id&&n.tray_id===A):void 0,B=R?p?.find(e=>e.id===R.spoolman_spool_id):void 0,V=B&&(B.label_weight??0)>0?Math.round(Math.max(0,(B.label_weight??0)-B.weight_used)/(B.label_weight??1)*100):null,ee=N??V??L??(i?r.remain:null),te=N!==null||V!==null?`spoolman`:L===null?i?`ams`:void 0:`inventory`,ne=r?.tray_type?{vendor:Yp(r)?`Bambu Lab`:`Generic`,profile:k||(B?[B.brand,B.slicer_filament_name?.split(`@`)[0].trim()||B.material].filter(Boolean).join(` `).trim():null)||P?.spool?.slicer_filament_name||D?.name||r.tray_sub_brands||r.tray_type,colorName:jf(r.tray_color||``,r.tray_sub_brands),colorHex:r.tray_color||null,kFactor:qU(r.k),fillLevel:ee,trayUuid:r.tray_uuid||null,tagUid:r.tag_uid||null,fillSource:te}:null,re=Vr?.amsId===t.id&&Vr?.slotId===A,ie=w.indexOf(x),ae=ie>=0?`P${ie+1}`:null,oe=(0,G.jsxs)(`div`,{className:`relative w-full bg-bambu-dark-secondary rounded-lg p-1 text-center ${f?`opacity-50`:``} ${T?`ring-2 ring-amber-400 ring-offset-1 ring-offset-bambu-dark animate-pulse`:E?`ring-2 ring-red-500/60 ring-offset-1 ring-offset-bambu-dark`:C?`ring-2 ring-bambu-green ring-offset-1 ring-offset-bambu-dark`:``}`,children:[T&&(0,G.jsx)(`span`,{"aria-label":F(`printers.expectedSlot.ariaLabel`,{n:1}),title:F(`printers.expectedSlot.title`),className:`absolute top-0.5 left-0.5 px-1 py-px text-[length:var(--pc-t8,8px)] font-bold text-bambu-dark bg-amber-400 rounded pointer-events-none leading-none`,children:`↓`}),ae&&(0,G.jsx)(`span`,{"aria-label":F(`printers.activeJobSlot.ariaLabel`,{n:ie+1}),title:F(`printers.activeJobSlot.title`,{n:ie+1}),className:`absolute top-0.5 right-0.5 px-1 py-px text-[length:var(--pc-t8,8px)] font-bold text-bambu-dark bg-bambu-green rounded pointer-events-none leading-none`,children:ae}),(0,G.jsx)(WU,{trayColor:r?.tray_color,trayType:r?.tray_type,isEmpty:f,emptyKind:v,slotNumber:1}),(0,G.jsx)(`div`,{className:`text-[length:var(--pc-t9,9px)] text-white font-bold truncate`,children:r?.tray_type||F(v===`reset`?`ams.slotUnconfigured`:`ams.slotEmpty`)}),(0,G.jsx)(JU,{k:ne?r?.k:null,reserve:On}),(0,G.jsx)(`div`,{className:`mt-1 h-1.5 bg-black/30 rounded-full overflow-hidden`,children:ee!==null&&ee>=0&&!f&&(0,G.jsx)(`div`,{className:`h-full rounded-full transition-all`,style:{width:`${ee}%`,backgroundColor:Rp(ee)}})})]}),se=y(11);return(0,G.jsxs)(`div`,{style:{flex:`1 1 ${se}`,minWidth:se,maxWidth:`calc(4 * ${b} + 3 * 0.25rem + 1rem)`},className:`min-w-0 p-2 bg-bambu-dark rounded-[10px] space-y-1`,children:[(0,G.jsxs)(`div`,{className:`flex w-full min-h-7 items-center gap-1.5 rounded-lg bg-bambu-dark-secondary px-2 py-1`,children:[(0,G.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center gap-1.5`,children:[(0,G.jsx)(uW,{ams:t,printerId:e.id,label:Cp(t.id,t.tray.length),amsLabels:mn,canEdit:z(`printers:update`),onSaved:hn,children:(0,G.jsx)(`span`,{className:`block truncate text-[length:var(--pc-t10,10px)] text-white font-medium cursor-default select-none`,children:mn?.[t.id]||Cp(t.id,t.tray.length)})}),n?.kind===`inlet`?(0,G.jsx)(XU,{inlet:n.inlet,title:F(`printers.amsSwitchInletTooltip`,{inlet:n.inlet,side:bp[n.inlet]})}):_&&n?.kind===`nozzle`?(0,G.jsx)(YU,{side:n.side}):null]}),(W.supports_drying||W.drying_screen_only)&&(t.module_type===`n3f`||t.module_type===`n3s`)&&z(`printers:control`)&&(0,G.jsx)(`div`,{className:`relative ml-auto`,children:(0,G.jsx)(`button`,{disabled:W.drying_screen_only,onClick:e=>{t.dry_time>0?lr.mutate(t.id):Qe===t.id?$e(null):bt(t,e.currentTarget)},className:`flex items-center gap-0.5 px-1 py-0.5 rounded text-[length:var(--pc-t9,9px)] transition-colors ${t.dry_time>0?`bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-400`:W.drying_screen_only?`bg-bambu-dark text-bambu-gray/50 cursor-not-allowed`:`bg-bambu-dark text-bambu-gray hover:text-white hover:bg-bambu-dark/80`}`,title:W.drying_screen_only?F(`printers.drying.screenOnly`):t.dry_time>0?F(`printers.drying.stop`):F(`printers.drying.start`),children:(0,G.jsx)(uc,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)]`})})})]}),t.dry_time>0&&(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 overflow-hidden whitespace-nowrap rounded-lg px-2 py-1 text-[length:var(--pc-t9,9px)] ${t.dry_countdown_stalled?`bg-slate-100 dark:bg-slate-500/10`:`bg-amber-50 dark:bg-amber-500/10`}`,title:t.dry_countdown_stalled?F(`printers.drying.notRunningHint`):void 0,children:[t.dry_countdown_stalled?(0,G.jsx)(Fc,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)] text-slate-500 dark:text-slate-400 shrink-0`}):(0,G.jsx)(uc,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)] text-amber-600 dark:text-amber-400 shrink-0`}),t.dry_countdown_stalled&&(0,G.jsx)(`span`,{className:`text-slate-600 dark:text-slate-300 text-[length:var(--pc-t8,8px)] font-medium truncate`,children:F(`printers.drying.notRunning`)}),t.dry_filament&&(0,G.jsx)(`span`,{className:`${t.dry_countdown_stalled?`text-slate-500/90 dark:text-slate-400/80`:`text-amber-700/80 dark:text-amber-300/70`} text-[length:var(--pc-t8,8px)] truncate`,children:t.dry_target_temp==null?t.dry_filament:F(`printers.drying.targetSummary`,{filament:t.dry_filament,temp:t.dry_target_temp})}),!t.dry_countdown_stalled&&(0,G.jsx)(`span`,{className:`text-amber-700/80 dark:text-amber-300/70 text-[length:var(--pc-t8,8px)] truncate`,children:t.dry_time>=60?`${Math.floor(t.dry_time/60)}h ${t.dry_time%60}m`:`${t.dry_time}m`}),!W.drying_screen_only&&(0,G.jsx)(`button`,{onClick:()=>lr.mutate(t.id),disabled:lr.isPending,className:`ml-auto text-amber-700 dark:text-amber-400 hover:text-amber-900 dark:hover:text-amber-300 transition-colors disabled:opacity-50 shrink-0`,title:F(`printers.drying.stop`),children:(0,G.jsx)(nd,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)]`})})]}),(0,G.jsxs)(`div`,{className:`flex gap-1.5 max-[550px]:flex-col max-[550px]:items-start`,children:[(0,G.jsxs)(`div`,{className:`relative group flex-1`,style:S,children:[re&&(0,G.jsx)(`div`,{className:`absolute inset-0 bg-bambu-dark-tertiary/80 rounded flex items-center justify-center z-20`,children:(0,G.jsx)(zl,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)] text-bambu-green animate-spin`})}),ne?(0,G.jsx)(GH,{data:ne,actions:Ei({amsId:t.id,slotId:A,loadTrayId:t.id*4+A,isRefreshing:re}),spoolman:{enabled:o,linkedSpoolId:R?.spoolman_spool_id??(j?s?.[j]?.id:void 0),spoolmanUrl:c,syncMode:l,onLinkSpool:o&&!R&&!P?()=>{let n=(ne.trayUuid||ne.tagUid||Vp(e.serial_number,t.id,A)).toUpperCase();Rt({tagUid:ne.tagUid||n,trayUuid:ne.trayUuid||``,printerId:e.id,amsId:t.id,trayId:A})}:void 0,onUnlinkSpool:M?.id?()=>or.mutate(M.id):void 0},inventory:(()=>{if(o){if(h)return;let n=R,i=B;return{assignedSpool:i?{id:i.id,material:i.material,subtype:i.subtype,brand:i.brand??null,color_name:i.color_name??null,color_name_is_synthesized:i.color_name_is_synthesized,rgba:i.rgba??null,extra_colors:i.extra_colors??null,effect_type:i.effect_type??null,remainingWeightGrams:i.label_weight?Math.max(0,Math.round(i.label_weight-i.weight_used)):void 0}:null,onAssignSpool:()=>Bt({printerId:e.id,amsId:t.id,trayId:A,trayInfo:{type:r?.tray_type||ne.profile,material:r?.tray_type??void 0,profile:ne.profile,color:ne.colorHex||``,location:Cp(t.id,t.tray.length)}}),onUnassignSpool:i&&!Yp(r)?()=>g?.(i.id):void 0,isAssigned:!!n||Yp(r)}}let n=u?.(e.id,t.id,A);return{assignedSpool:n?.spool?{id:n.spool.id,material:n.spool.material,subtype:n.spool.subtype,brand:n.spool.brand,color_name:n.spool.color_name,rgba:n.spool.rgba??null,extra_colors:n.spool.extra_colors??null,effect_type:n.spool.effect_type??null,remainingWeightGrams:Math.max(0,Math.round(n.spool.label_weight-n.spool.weight_used))}:null,onAssignSpool:()=>Bt({printerId:e.id,amsId:t.id,trayId:A,trayInfo:{type:r?.tray_type||ne.profile,material:r?.tray_type??void 0,profile:ne.profile,color:ne.colorHex||``,location:Cp(t.id,t.tray.length)}}),onUnassignSpool:n&&!Yp(r)?()=>d?.(e.id,t.id,A):void 0,isAssigned:!!n||Yp(r)}})(),configureSlot:{enabled:z(`printers:control`),onConfigure:()=>Ht({amsId:t.id,trayId:A,trayCount:t.tray.length,trayType:r?.tray_type||void 0,trayColor:r?.tray_color||void 0,traySubBrands:r?.tray_sub_brands||void 0,trayInfoIdx:r?.tray_info_idx||void 0,extruderId:Sp(t.id,r?.id??0,Sn,Tn),caliIdx:r?.cali_idx,savedPresetId:O?.preset_id})},children:oe}):(0,G.jsx)(KH,{kind:v??void 0,actions:Ei({amsId:t.id,slotId:A,loadTrayId:t.id*4+A,isRefreshing:re}),configureSlot:{enabled:z(`printers:control`),onConfigure:()=>Ht({amsId:t.id,trayId:A,trayCount:t.tray.length,extruderId:Sp(t.id,r?.id??0,Sn,Tn)})},onAssignSpool:()=>Bt({printerId:e.id,amsId:t.id,trayId:A,trayInfo:{type:``,material:void 0,profile:``,color:``,location:Cp(t.id,t.tray.length)}}),children:oe})]}),(t.humidity!=null||t.temp!=null)&&(0,G.jsxs)(`div`,{className:`flex flex-col justify-center gap-1 shrink-0 max-[550px]:w-full`,children:[t.temp!=null&&(0,G.jsx)(rW,{temp:t.temp,goodThreshold:a?.tempGood,fairThreshold:a?.tempFair,onClick:()=>Pt({amsId:t.id,amsLabel:Cp(t.id,t.tray.length),mode:`temperature`}),compact:!0}),t.humidity!=null&&(0,G.jsx)(nW,{humidity:t.humidity,goodThreshold:a?.humidityGood,fairThreshold:a?.humidityFair,onClick:()=>Pt({amsId:t.id,amsLabel:Cp(t.id,t.tray.length),mode:`humidity`}),compact:!0})]})]})]},t.id)}),W.vt_tray.length>0&&f&&(0,G.jsxs)(`div`,{style:T(W.vt_tray.length),className:`min-w-0 p-2 bg-bambu-dark rounded-[10px] space-y-1`,children:[(0,G.jsx)(`div`,{className:`flex w-full min-h-7 items-center gap-1.5 rounded-lg bg-bambu-dark-secondary px-2 py-1`,children:(0,G.jsx)(`span`,{className:`block min-w-0 flex-1 truncate text-[length:var(--pc-t10,10px)] text-white font-medium`,children:F(`printers.external`)})}),(0,G.jsx)(`div`,{className:`grid w-full gap-1`,style:C(W.vt_tray.length>1?2:1),children:[...W.vt_tray].sort((e,t)=>(e.id??254)-(t.id??254)).map(t=>{let n=t.id??254,r=_&&jn===254?n===254&&W.active_extruder===1||n===255&&W.active_extruder===0:jn===n,i=n-254,a=_?F(n===254?`printers.extL`:`printers.extR`):``,f=t.tray_info_idx?ln?.[t.tray_info_idx]:null,v=un?.[1020+i],y=Xp(v?.preset_id,t.tray_info_idx)?v?.preset_name:void 0,b=(t.tray_uuid||t.tag_uid||Vp(e.serial_number,255,i))?.toUpperCase(),S=b?s?.[b]:void 0,C=zp(S),w=u?.(e.id,255,i),T=(()=>{let e=w?.spool;return e&&e.label_weight>0&&e.weight_used!=null?Math.round(Math.max(0,e.label_weight-e.weight_used)/e.label_weight*100):null})(),E=t.tray_type&&t.remain>=0,D=T===0&&E&&t.remain>0?null:T,O=o&&!h?m?.find(t=>t.printer_id===e.id&&t.ams_id===255&&t.tray_id===i):void 0,k=O?p?.find(e=>e.id===O.spoolman_spool_id):void 0,A=k&&(k.label_weight??0)>0?Math.round(Math.max(0,(k.label_weight??0)-k.weight_used)/(k.label_weight??1)*100):null,j=C??A??D??(E?t.remain:null),M=C!==null||A!==null?`spoolman`:D===null?E?`ams`:void 0:`inventory`,N={vendor:Yp(t)?`Bambu Lab`:`Generic`,profile:y||(k?[k.brand,k.slicer_filament_name?.split(`@`)[0].trim()||k.material].filter(Boolean).join(` `).trim():null)||w?.spool?.slicer_filament_name||f?.name||t.tray_sub_brands||t.tray_type||`Unknown`,colorName:jf(t.tray_color||``,t.tray_sub_brands),colorHex:t.tray_color||null,kFactor:qU(t.k),fillLevel:j,trayUuid:t.tray_uuid||null,tagUid:t.tag_uid||null,fillSource:M},P=!t.tray_type,I=Fp(t),L=(0,G.jsxs)(`div`,{className:`w-full bg-bambu-dark-secondary rounded-lg p-1 text-center ${P?`opacity-50`:``} ${r?`ring-2 ring-bambu-green ring-offset-1 ring-offset-bambu-dark`:``}`,children:[(0,G.jsx)(WU,{trayColor:t.tray_color,trayType:t.tray_type,isEmpty:P,emptyKind:I,slotNumber:_?n===254?`L`:`R`:i+1}),(0,G.jsx)(`div`,{className:`text-[length:var(--pc-t9,9px)] font-bold truncate ${P?`text-white/40`:`text-white`}`,children:t.tray_type||F(`ams.slotEmpty`)}),(0,G.jsx)(JU,{k:P?null:t.k,reserve:On}),(0,G.jsx)(`div`,{className:`mt-1 h-1.5 bg-black/30 rounded-full overflow-hidden`,children:j!==null&&j>=0&&!P&&(0,G.jsx)(`div`,{className:`h-full rounded-full transition-all`,style:{width:`${j}%`,backgroundColor:Rp(j)}})})]});return(0,G.jsx)(`div`,{className:`relative group w-full`,style:x,children:P?(0,G.jsx)(KH,{kind:I??void 0,actions:Ei({amsId:255,slotId:i,loadTrayId:n,includeRfid:!1}),configureSlot:{enabled:z(`printers:control`),onConfigure:()=>Ht({amsId:255,trayId:i,trayCount:1,extruderId:_?+(n===254):void 0})},onAssignSpool:()=>Bt({printerId:e.id,amsId:255,trayId:i,trayInfo:{type:``,material:void 0,profile:``,color:``,location:`External Slot ${i+1}`}}),children:L}):(0,G.jsx)(GH,{data:N,actions:Ei({amsId:255,slotId:i,loadTrayId:n,includeRfid:!1}),spoolman:{enabled:o,linkedSpoolId:O?.spoolman_spool_id??(b?s?.[b]?.id:void 0),spoolmanUrl:c,syncMode:l,onLinkSpool:o&&!O&&!w?()=>{let t=(N.trayUuid||N.tagUid||Vp(e.serial_number,255,i)).toUpperCase();Rt({tagUid:N.tagUid||t,trayUuid:N.trayUuid||``,printerId:e.id,amsId:255,trayId:i})}:void 0,onUnlinkSpool:S?.id?()=>or.mutate(S.id):void 0},inventory:(()=>{if(o){if(h)return;let n=O,r=k;return{assignedSpool:r?{id:r.id,material:r.material,subtype:r.subtype,brand:r.brand??null,color_name:r.color_name??null,color_name_is_synthesized:r.color_name_is_synthesized,rgba:r.rgba??null,extra_colors:r.extra_colors??null,effect_type:r.effect_type??null,remainingWeightGrams:r.label_weight?Math.max(0,Math.round(r.label_weight-r.weight_used)):void 0}:null,onAssignSpool:()=>Bt({printerId:e.id,amsId:255,trayId:i,trayInfo:{type:t.tray_type||N.profile,material:t.tray_type??void 0,profile:N.profile,color:N.colorHex||``,location:a||F(`printers.external`)}}),onUnassignSpool:r&&!Yp(t)?()=>g?.(r.id):void 0,isAssigned:!!n||Yp(t)}}let n=u?.(e.id,255,i);return{assignedSpool:n?.spool?{id:n.spool.id,material:n.spool.material,subtype:n.spool.subtype,brand:n.spool.brand,color_name:n.spool.color_name,rgba:n.spool.rgba??null,extra_colors:n.spool.extra_colors??null,effect_type:n.spool.effect_type??null,remainingWeightGrams:Math.max(0,Math.round(n.spool.label_weight-n.spool.weight_used))}:null,onAssignSpool:()=>Bt({printerId:e.id,amsId:255,trayId:i,trayInfo:{type:t.tray_type||N.profile,material:t.tray_type??void 0,profile:N.profile,color:N.colorHex||``,location:a||F(`printers.external`)}}),onUnassignSpool:n&&!Yp(t)?()=>d?.(e.id,255,i):void 0,isAssigned:!!n||Yp(t)}})(),configureSlot:{enabled:z(`printers:control`),onConfigure:()=>Ht({amsId:255,trayId:i,trayCount:1,trayType:t.tray_type||void 0,trayColor:t.tray_color||void 0,traySubBrands:t.tray_sub_brands||void 0,trayInfoIdx:t.tray_info_idx||void 0,extruderId:_?+(n===254):void 0,caliIdx:t.cali_idx,savedPresetId:v?.preset_id})},children:L})},n)})})]})]})]})})()]}),e.is_active!==!1&&!W?.connected&&r===`expanded`&&Yn&&xr,r===`expanded`&&(0,G.jsxs)(`div`,{className:`mt-auto`,children:[In&&(0,G.jsxs)(`div`,{className:`pt-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,G.jsx)(`span`,{className:`text-[length:var(--pc-t10,10px)] uppercase tracking-wider text-bambu-gray font-medium`,children:F(`printers.power`,`Power`)}),(0,G.jsx)(`div`,{className:`flex-1 h-[2px] bg-bambu-dark-tertiary`})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 rounded-[10px] bg-bambu-dark p-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0 pl-1`,children:[(0,G.jsx)(id,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)] text-bambu-gray flex-shrink-0`}),(0,G.jsx)(`span`,{className:`text-sm text-white truncate`,children:In.name}),(0,G.jsx)(`span`,{className:`px-1.5 py-0.5 rounded-full bg-bambu-dark-tertiary text-bambu-gray text-[length:var(--pc-t10,10px)] font-medium flex-shrink-0`,title:F(`smartPlugs.power`),children:Rn?.energy?.power!==null&&Rn?.energy?.power!==void 0?`${Math.round(Rn.energy.power)}W`:`--`})]}),(0,G.jsx)(`div`,{className:`flex-1`}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`button`,{onClick:()=>fr.mutate(!In.auto_off),disabled:fr.isPending||In.auto_off_executed||!z(`smart_plugs:control`),title:z(`smart_plugs:control`)?In.auto_off_executed?F(`printers.autoOffExecuted`):F(`printers.autoOffAfterPrint`):F(`printers.permission.noSmartPlugControl`),className:`flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-lg text-xs font-bold transition-colors disabled:opacity-50 disabled:cursor-not-allowed ${z(`smart_plugs:control`)?In.auto_off||In.auto_off_executed?`bg-bambu-green/20 text-bambu-green hover:bg-bambu-green/30`:`bg-bambu-dark-tertiary text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary/80`:`bg-bambu-dark-tertiary/50 text-bambu-gray/50`}`,children:(0,G.jsx)(Ts,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)]`})}),(0,G.jsx)(`button`,{onClick:()=>{Rn?.state===`ON`?pe(!0):de(!0)},disabled:dr.isPending||!z(`smart_plugs:control`),className:`flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-lg text-xs transition-colors disabled:opacity-50 disabled:cursor-not-allowed ${z(`smart_plugs:control`)?Rn?.state===`ON`?`bg-bambu-green/20 text-bambu-green hover:bg-bambu-green/30`:`bg-bambu-dark-tertiary text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary/80`:`bg-bambu-dark-tertiary/50 text-bambu-gray/50`}`,title:z(`smart_plugs:control`)?Rn?.state===`ON`?`Turn off`:`Turn on`:F(`printers.permission.noSmartPlugControl`),children:(0,G.jsx)(id,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)]`})})]})]}),Ln&&Ln.length>0&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mt-2`,children:[(0,G.jsx)(Ic,{className:`w-[var(--pc-i35,0.875rem)] h-[var(--pc-i35,0.875rem)] text-blue-600 dark:text-blue-400 flex-shrink-0`}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:`HA:`}),(0,G.jsx)(`div`,{className:`h-[2px] w-5 bg-bambu-dark-tertiary/50`}),(0,G.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:Ln.map(e=>{let t=e.ha_entity_id?.startsWith(`script.`);return(0,G.jsxs)(`button`,{onClick:()=>{t?pr.mutate({id:e.id,action:`on`}):he(e)},disabled:pr.isPending,title:`${t?`Run`:`Toggle`} ${e.ha_entity_id}`,className:`px-2 py-0.5 text-xs bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400 hover:bg-blue-500/30 rounded transition-colors flex items-center gap-1`,children:[(0,G.jsx)(Al,{className:`w-[var(--pc-i25,0.625rem)] h-[var(--pc-i25,0.625rem)]`}),e.name]},e.id)})})]})]}),(0,G.jsx)(zle,{printerId:e.id}),(0,G.jsxs)(`div`,{className:`pt-4`,children:[(0,G.jsx)(`div`,{className:`mb-3 h-[2px] bg-bambu-dark-tertiary`}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[Di,(0,G.jsxs)(`div`,{className:`flex items-center justify-end gap-2 flex-wrap`,children:[(0,G.jsxs)(`div`,{className:`flex items-center flex-shrink-0`,children:[(0,G.jsx)(Q,{variant:`secondary`,size:`sm`,onClick:()=>wi(v),disabled:!W?.connected||!z(`camera:view`),title:z(`camera:view`)?F(v===`embedded`?`printers.openCameraOverlay`:`printers.openCameraWindow`):F(`printers.permission.noCamera`),className:`${Ci} !rounded-r-none`,children:(0,G.jsx)(Gu,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)]`})}),(0,G.jsx)(Q,{variant:`secondary`,size:`sm`,onClick:e=>{let t=e.currentTarget.getBoundingClientRect();jt({x:t.left,y:t.bottom+4})},disabled:!W?.connected||!z(`camera:view`),title:z(`camera:view`)?F(`settings.cameraViewMode`):F(`printers.permission.noCamera`),"aria-label":F(`settings.cameraViewMode`),className:`!h-8 !min-h-8 !w-6 !px-0 !py-0 !rounded-l-none border-l border-bambu-dark`,children:(0,G.jsx)(ss,{className:`w-3 h-3`})})]}),At&&(0,G.jsx)(JT,{x:At.x,y:At.y,items:Ti,onClose:()=>jt(null)}),(0,G.jsx)(Q,{variant:`secondary`,size:`sm`,onClick:()=>H(!0),disabled:!z(`printers:files`),title:z(`printers:files`)?F(`printers.browseFiles`):F(`printers.permission.noFiles`),className:Ci,children:(0,G.jsx)(kc,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)]`})}),(0,G.jsxs)(Q,{size:`sm`,onClick:()=>We(!0),disabled:!z(`library:upload`)||!z(`queue:create`),title:z(`library:upload`)?z(`queue:create`)?F(`common.print`):F(`fileManager.noPermissionAddToQueue`):F(`fileManager.noPermissionUpload`),className:`!h-8 !min-h-8 !px-2 !py-0 !bg-bambu-green hover:!bg-bambu-green/80 !text-white`,children:[(0,G.jsx)(Fl,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)]`}),F(`common.print`)]})]})]})]})]}),(0,G.jsx)(_je,{printerId:e.id,dryingActive:Dn.some(e=>(e.dry_time??0)>0),timeFormat:_})]}),se&&(0,G.jsx)(ble,{printerId:e.id,printerName:e.name,onClose:()=>H(!1)}),Ue&&(0,G.jsx)(BU,{folderId:null,onClose:()=>We(!1),onUploadComplete:()=>{},autoUpload:!0,accept:`.gcode,.3mf`,validateFile:e=>{let t=e.name.toLowerCase();if(!t.endsWith(`.gcode`)&&!t.includes(`.gcode.`))return F(`printers.dropNotPrintable`,`Only .gcode and .gcode.3mf files can be printed`)},onFileUploaded:t=>{let n=t.metadata?.sliced_for_model,r=ah(e.model);if(n&&r&&n.toLowerCase()!==r.toLowerCase())return Z.deleteLibraryFile(t.id).catch(()=>{}),F(`printers.incompatibleFile`,`This file was sliced for {{slicedFor}}, but this printer is a {{printerModel}}`,{slicedFor:n,printerModel:r});Ze({id:t.id,filename:t.filename})}}),Xe&&(0,G.jsx)(Lm,{mode:`create`,libraryFileId:Xe.id,archiveName:Xe.filename,initialSelectedPrinterIds:[e.id],onClose:()=>Ze(null),onSuccess:()=>Ze(null),cleanupLibraryAfterDispatch:!0}),ce&&(0,G.jsx)(Fle,{printerId:e.id,printerName:e.name,onClose:()=>le(!1)}),qe&&(0,G.jsx)(Bm,{printerId:e.id,printerName:e.name,onClose:()=>Je(!1)}),Ge&&(0,G.jsx)(zAe,{printer:e,status:W,totalPrintHours:n?.total_print_hours,onClose:Ye}),Gt&&(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,onClick:()=>oi(),children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl shadow-2xl max-w-lg w-full`,onClick:e=>e.stopPropagation(),children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[Gt.needs_calibration?(0,G.jsx)(ql,{className:`w-[var(--pc-i5,1.25rem)] h-[var(--pc-i5,1.25rem)] text-blue-500`}):Gt.is_empty?(0,G.jsx)(hs,{className:`w-[var(--pc-i5,1.25rem)] h-[var(--pc-i5,1.25rem)] text-green-500`}):(0,G.jsx)(xs,{className:`w-[var(--pc-i5,1.25rem)] h-[var(--pc-i5,1.25rem)] text-yellow-500`}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:`Build Plate Check`}),Gt.reference_count!==void 0&&Gt.max_references&&(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray bg-bambu-dark-tertiary px-2 py-1 rounded`,children:[Gt.reference_count,`/`,Gt.max_references,` refs`]})]}),(0,G.jsx)(`button`,{onClick:()=>oi(),className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,G.jsx)(nd,{className:`w-[var(--pc-i5,1.25rem)] h-[var(--pc-i5,1.25rem)]`})})]}),(0,G.jsxs)(`div`,{className:`p-4 space-y-4`,children:[Gt.needs_calibration?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`p-3 rounded-lg bg-blue-100 dark:bg-blue-500/20 border border-blue-300 dark:border-blue-500/50`,children:[(0,G.jsx)(`p`,{className:`font-medium text-blue-700 dark:text-blue-400`,children:F(`printers.plateDetection.calibrationRequired`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,dangerouslySetInnerHTML:{__html:F(`printers.plateDetection.calibrationInstructions`)}})]}),(0,G.jsxs)(`div`,{className:`text-sm text-bambu-gray space-y-2`,children:[(0,G.jsx)(`p`,{children:F(`printers.plateDetection.calibrationDescription`)}),(0,G.jsx)(`p`,{dangerouslySetInnerHTML:{__html:F(`printers.plateDetection.calibrationTip`)}})]})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`p-3 rounded-lg ${Gt.is_empty?`bg-green-100 dark:bg-green-500/20 border border-green-300 dark:border-green-500/50`:`bg-yellow-100 dark:bg-yellow-500/20 border border-yellow-300 dark:border-yellow-500/50`}`,children:[(0,G.jsx)(`p`,{className:`font-medium ${Gt.is_empty?`text-green-700 dark:text-green-400`:`text-yellow-700 dark:text-yellow-400`}`,children:Gt.is_empty?F(`printers.plateDetection.plateEmpty`):F(`printers.plateDetection.objectsDetected`)}),(0,G.jsxs)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:[F(`printers.plateDetection.confidence`),`: `,Math.round(Gt.confidence*100),`% | `,F(`printers.plateDetection.difference`),`: `,Gt.difference_percent.toFixed(1),`%`]})]}),Gt.debug_image_url&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mb-2`,children:F(`printers.plateDetection.analysisPreview`)}),(0,G.jsx)(`img`,{src:Gt.debug_image_url,alt:F(`printers.plateDetection.analysisPreview`),className:`w-full rounded-lg border border-bambu-dark-tertiary`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-2`,children:F(`printers.plateDetection.analysisLegend`)})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:Gt.message})]}),$r&&$r.references.length>0&&(0,G.jsxs)(`div`,{className:`mt-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,G.jsx)(`p`,{className:`text-sm font-medium text-white shrink-0`,children:F(`printers.plateDetection.savedReferences`,{count:$r.references.length,max:$r.max_references})}),(0,G.jsx)(`div`,{className:`flex-1 h-[2px] bg-bambu-dark-tertiary`})]}),(0,G.jsx)(`div`,{className:`grid grid-cols-5 gap-2`,children:$r.references.map(t=>(0,G.jsxs)(`div`,{className:`relative group`,children:[(0,G.jsx)(`img`,{src:Z.getPlateReferenceThumbnailUrl(e.id,t.index),alt:t.label||`Reference ${t.index+1}`,className:`w-full aspect-video object-cover rounded border border-bambu-dark-tertiary`}),(0,G.jsx)(`button`,{onClick:()=>li(t.index),className:`absolute top-1 right-1 p-0.5 bg-red-500/80 rounded can-hover:opacity-0 group-hover:opacity-100 focus-visible:opacity-100 transition-opacity`,title:F(`printers.plateDetection.deleteReference`),children:(0,G.jsx)(nd,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)] text-white`})}),ti?.index===t.index?(0,G.jsx)(`input`,{type:`text`,value:ti.label,onChange:e=>ni({...ti,label:e.target.value}),onBlur:()=>ci(t.index,ti.label),onKeyDown:e=>{e.key===`Enter`&&ci(t.index,ti.label),e.key===`Escape`&&ni(null)},className:`w-full mt-1 px-1 py-0.5 text-xs bg-bambu-dark-tertiary border border-bambu-green rounded text-white`,autoFocus:!0,placeholder:F(`printers.plateDetection.labelPlaceholder`)}):(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1 truncate cursor-pointer hover:text-white`,onClick:()=>ni({index:t.index,label:t.label}),title:t.label?F(`printers.plateDetection.clickToEdit`,{label:t.label}):F(`printers.plateDetection.clickToAddLabel`),children:t.label||(0,G.jsx)(`span`,{className:`italic opacity-50`,children:F(`printers.noLabel`)})}),(0,G.jsx)(`p`,{className:`text-[length:var(--pc-t10,10px)] text-bambu-gray/60`,children:t.timestamp?sp(t.timestamp)?.toLocaleDateString()??``:``})]},t.index))})]}),!Gt.needs_calibration&&(0,G.jsxs)(`div`,{className:`mt-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,G.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center gap-2`,children:[(0,G.jsx)(`p`,{className:`text-sm font-medium text-white shrink-0`,children:F(`printers.roi.title`)}),(0,G.jsx)(`div`,{className:`flex-1 h-[2px] bg-bambu-dark-tertiary`})]}),Zt?(0,G.jsxs)(`div`,{className:`flex gap-1`,children:[(0,G.jsx)(Q,{variant:`ghost`,size:`sm`,onClick:()=>Qt(null),disabled:$t,children:F(`common.cancel`)}),(0,G.jsx)(Q,{size:`sm`,onClick:ui,disabled:$t,children:$t?(0,G.jsx)(Y,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)] animate-spin`}):F(`common.save`)})]}):(0,G.jsxs)(Q,{variant:`ghost`,size:`sm`,onClick:()=>Qt(Gt.roi||{x:.15,y:.35,w:.7,h:.55}),children:[(0,G.jsx)(Dl,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)] mr-1`}),F(`common.edit`)]})]}),Zt?(0,G.jsxs)(`div`,{className:`space-y-3 bg-bambu-dark-tertiary/50 p-3 rounded-lg`,children:[(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`text-xs text-bambu-gray`,children:F(`printers.roi.xStart`)}),(0,G.jsx)(`input`,{type:`range`,min:`0`,max:`0.9`,step:`0.01`,value:Zt.x,onChange:e=>Qt({...Zt,x:parseFloat(e.target.value)}),className:`w-full h-1.5 bg-bambu-dark-tertiary rounded-lg cursor-pointer accent-green-500`}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[Math.round(Zt.x*100),`%`]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`text-xs text-bambu-gray`,children:F(`printers.roi.yStart`)}),(0,G.jsx)(`input`,{type:`range`,min:`0`,max:`0.9`,step:`0.01`,value:Zt.y,onChange:e=>Qt({...Zt,y:parseFloat(e.target.value)}),className:`w-full h-1.5 bg-bambu-dark-tertiary rounded-lg cursor-pointer accent-green-500`}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[Math.round(Zt.y*100),`%`]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`text-xs text-bambu-gray`,children:F(`printers.width`)}),(0,G.jsx)(`input`,{type:`range`,min:`0.1`,max:`1`,step:`0.01`,value:Zt.w,onChange:e=>Qt({...Zt,w:parseFloat(e.target.value)}),className:`w-full h-1.5 bg-bambu-dark-tertiary rounded-lg cursor-pointer accent-green-500`}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[Math.round(Zt.w*100),`%`]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`text-xs text-bambu-gray`,children:F(`printers.height`)}),(0,G.jsx)(`input`,{type:`range`,min:`0.1`,max:`1`,step:`0.01`,value:Zt.h,onChange:e=>Qt({...Zt,h:parseFloat(e.target.value)}),className:`w-full h-1.5 bg-bambu-dark-tertiary rounded-lg cursor-pointer accent-green-500`}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[Math.round(Zt.h*100),`%`]})]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:F(`printers.roi.instruction`)})]}):(0,G.jsxs)(`p`,{className:`text-xs text-bambu-gray`,children:[`Current: X=`,Math.round((Gt.roi?.x||.15)*100),`%, Y=`,Math.round((Gt.roi?.y||.35)*100),`%, W=`,Math.round((Gt.roi?.w||.7)*100),`%, H=`,Math.round((Gt.roi?.h||.55)*100),`%`]})]})]}),(0,G.jsx)(`div`,{className:`flex justify-end gap-2 p-4`,children:Gt.needs_calibration?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Q,{variant:`ghost`,onClick:()=>oi(),children:F(`common.cancel`)}),(0,G.jsx)(Q,{onClick:()=>si(),disabled:Yt,children:Yt?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)] mr-2 animate-spin`}),`Calibrating...`]}):`Calibrate Empty Plate`})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Q,{variant:`ghost`,onClick:()=>si(),disabled:Yt,children:Yt?`Adding...`:`Add Reference (${$r?.references.length||0}/${$r?.max_references||5})`}),(0,G.jsx)(Q,{onClick:()=>oi(),children:`Close`})]})})]})}),ue&&In&&(0,G.jsx)(uf,{title:F(`printers.confirm.powerOnTitle`),message:F(`printers.confirm.powerOnMessage`,{name:e.name}),confirmText:F(`printers.confirm.powerOnButton`),variant:`default`,onConfirm:()=>{dr.mutate(`on`),de(!1)},onCancel:()=>de(!1)}),Ir&&(0,G.jsx)(uf,{title:F(`printers.maintenance.confirmMidPrintTitle`),message:F(`printers.maintenance.confirmMidPrintMessage`,{name:e.name}),confirmText:F(`printers.maintenance.menuEnter`),variant:`danger`,onConfirm:()=>{Fr.mutate(!1),Lr(!1)},onCancel:()=>Lr(!1)}),fe&&In&&(0,G.jsx)(uf,{title:F(`printers.confirm.powerOffTitle`),message:W?.state===`RUNNING`?F(`printers.confirm.powerOffWarning`,{name:e.name}):F(`printers.confirm.powerOffMessage`,{name:e.name}),confirmText:F(`printers.confirm.powerOffButton`),variant:`danger`,onConfirm:()=>{dr.mutate(`off`),pe(!1)},onCancel:()=>pe(!1)}),me&&(0,G.jsx)(uf,{title:F(`printers.confirm.haToggleTitle`,{name:me.name}),message:W?.state===`RUNNING`?F(`printers.confirm.haToggleWarning`,{name:e.name,entity:me.ha_entity_id||me.name}):F(`printers.confirm.haToggleMessage`,{entity:me.ha_entity_id||me.name}),confirmText:F(`printers.confirm.haToggleButton`),variant:W?.state===`RUNNING`?`danger`:`default`,onConfirm:()=>{pr.mutate({id:me.id,action:`toggle`}),he(null)},onCancel:()=>he(null)}),Te&&(0,G.jsx)(uf,{title:F(`printers.confirm.stopTitle`),message:F(`printers.confirm.stopMessage`,{name:e.name}),confirmText:F(`printers.confirm.stopButton`),variant:`danger`,onConfirm:()=>{mr.mutate(),Ee(!1)},onCancel:()=>Ee(!1)}),De&&(0,G.jsx)(uf,{title:F(`printers.confirm.pauseTitle`),message:F(`printers.confirm.pauseMessage`,{name:e.name}),confirmText:F(`printers.confirm.pauseButton`),variant:`default`,onConfirm:()=>{hr.mutate(),Oe(!1)},onCancel:()=>Oe(!1)}),ze&&(0,G.jsx)(uf,{title:F(`printers.confirm.resumeTitle`),message:F(`printers.confirm.resumeMessage`,{name:e.name}),confirmText:F(`printers.confirm.resumeButton`),variant:`default`,onConfirm:()=>{gr.mutate(),Be(!1)},onCancel:()=>Be(!1)}),(0,G.jsx)(zT,{printerId:e.id,isOpen:Ve,onClose:()=>He(!1)}),ge&&(0,G.jsx)(zte,{printerName:e.name,errors:W?.hms_errors||[],onClose:()=>_e(!1),printerId:e.id,hasPermission:z,runoutGuidance:Fn}),ve&&(0,G.jsx)(Lle,{printerName:e.name,detection:N,lastError:P,onClose:()=>ye(!1)}),be&&W&&(0,G.jsx)(hAe,{isOpen:be,state:W.ams_filament_backup,amsUnits:W.ams,amsExtruderMap:W.ams_extruder_map,isDualNozzle:e.nozzle_count===2||W?.temperatures?.nozzle_2!==void 0,canToggle:z(`printers:control`),pending:ur.isPending,onToggle:e=>ur.mutate(e),onClose:()=>xe(!1)}),Nt&&(0,G.jsx)(dAe,{isOpen:!!Nt,onClose:()=>Pt(null),printerId:e.id,printerName:e.name,amsId:Nt.amsId,amsLabel:Nt.amsLabel,initialMode:Nt.mode,thresholds:a}),Ft&&(0,G.jsx)(_Ae,{isOpen:!!Ft,onClose:()=>It(null),printerId:e.id,printerName:e.name,initialKind:Ft.initialKind,availableKinds:Ft.availableKinds}),Lt&&(0,G.jsx)(qH,{isOpen:!!Lt,onClose:()=>Rt(null),tagUid:Lt.tagUid,trayUuid:Lt.trayUuid,printerId:Lt.printerId,amsId:Lt.amsId,trayId:Lt.trayId}),zt&&(0,G.jsx)(YH,{isOpen:!!zt,onClose:()=>Bt(null),printerId:zt.printerId,amsId:zt.amsId,trayId:zt.trayId,trayInfo:zt.trayInfo,spoolmanEnabled:!!o}),Vt&&(0,G.jsx)(RU,{isOpen:!!Vt,onClose:()=>Ht(null),printerId:e.id,slotInfo:Vt,printerModel:ah(e.model)||void 0,nozzleDiameter:Jp(W,Vt.amsId),onSuccess:()=>{I.invalidateQueries({queryKey:[`slotPresets`,e.id]}),I.invalidateQueries({queryKey:[`printerStatus`,e.id]})}}),Yr&&(0,G.jsx)(BAe,{slotLabel:Yr.slotLabel,amsId:Yr.amsId,slotId:Yr.slotId,extruderSlots:W?.extruder_slots??{},isLoading:qr.isPending,onConfirm:e=>qr.mutate({trayId:Yr.trayId,extruderId:e}),onCancel:()=>Xr(null)}),ae&&(0,G.jsx)(bje,{printer:e,onClose:()=>oe(!1)}),Ut&&rn&&(0,G.jsx)(yje,{printer:e,firmwareInfo:rn,onClose:()=>Wt(!1)}),Qe!==null&>&&(()=>{let e=et===`n3s`?85:65,t=e+10;return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`fixed inset-0 z-[100]`,"data-testid":`drying-popover-backdrop`,onMouseDown:()=>{St.current=xt.current!==null&&document.activeElement===xt.current},onClick:()=>{if(St.current){St.current=!1;return}$e(null)}}),(0,G.jsxs)(`div`,{className:`fixed z-[101] flex flex-col w-[240px] bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl shadow-2xl overflow-hidden`,style:{left:gt.left,...gt.placement===`above`?{bottom:`calc(100dvh - ${gt.anchorY}px)`,maxHeight:`${gt.anchorY-8}px`}:{top:gt.top,maxHeight:`calc(100dvh - ${gt.top}px - 8px)`}},onClick:e=>e.stopPropagation(),children:[(0,G.jsxs)(`div`,{className:`shrink-0 flex items-center justify-center gap-2 px-3 py-2.5`,children:[(0,G.jsx)(uc,{className:`w-[var(--pc-i35,0.875rem)] h-[var(--pc-i35,0.875rem)] text-bambu-green`}),(0,G.jsx)(`span`,{className:`text-sm text-white font-medium text-center`,children:F(`printers.drying.start`)})]}),(0,G.jsx)(`div`,{className:`shrink-0 h-px bg-bambu-dark-tertiary`}),(0,G.jsxs)(`div`,{className:`px-3 py-2.5 space-y-2.5 overflow-y-auto min-h-0`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`text-[length:var(--pc-t10,10px)] text-white/70 font-medium mb-1 block`,children:F(`printers.filaments`)}),(0,G.jsx)(iW,{value:nt,options:Object.keys(S).map(e=>({value:e,label:e})),onChange:e=>{rt(e);let t=S[e];t&&(at(t[et===`n3s`?`n3s`:`n3f`]),st(et===`n3s`?t.n3s_hours:t.n3f_hours))},fullWidth:!0})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-1`,children:[(0,G.jsx)(`label`,{className:`text-[length:var(--pc-t10,10px)] text-white/70 font-medium`,children:F(`printers.drying.temperature`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(nm,{min:45,max:e,value:it,onChange:at,fallback:45,className:`w-12 px-1 py-0.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-[length:var(--pc-t11,11px)] text-center focus:outline-none focus:border-bambu-green [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none`}),(0,G.jsx)(`span`,{className:`text-[length:var(--pc-t10,10px)] text-bambu-gray`,children:`°C`})]})]}),(0,G.jsx)(`input`,{type:`range`,min:35,max:t,value:it,onChange:t=>at(Math.min(e,Math.max(45,Number(t.target.value)))),className:`w-full h-1 accent-bambu-green cursor-pointer`}),(0,G.jsxs)(`div`,{className:`flex justify-between text-[length:var(--pc-t9,9px)] text-bambu-gray/50 mt-0.5`,children:[(0,G.jsx)(`span`,{children:`45°C`}),(0,G.jsxs)(`span`,{children:[e,`°C`]})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-1`,children:[(0,G.jsx)(`label`,{className:`text-[length:var(--pc-t10,10px)] text-white/70 font-medium`,children:F(`printers.drying.duration`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(nm,{min:1,max:24,value:ot,onChange:st,fallback:1,className:`w-10 px-1 py-0.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-[length:var(--pc-t11,11px)] text-center focus:outline-none focus:border-bambu-green [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none`}),(0,G.jsx)(`span`,{className:`text-[length:var(--pc-t10,10px)] text-bambu-gray`,children:F(`printers.drying.hours`)})]})]}),(0,G.jsx)(`input`,{type:`range`,min:1,max:24,value:ot,onChange:e=>st(Number(e.target.value)),className:`w-full h-1 accent-bambu-green cursor-pointer`}),(0,G.jsxs)(`div`,{className:`flex justify-between text-[length:var(--pc-t9,9px)] text-bambu-gray/50 mt-0.5`,children:[(0,G.jsx)(`span`,{children:`1h`}),(0,G.jsx)(`span`,{children:`24h`})]})]}),(()=>{let e=((Qe===null?void 0:Dn.find(e=>e.id===Qe))?.tray??[]).some(e=>e.state===11),t=ct&&!e;return(0,G.jsx)(`button`,{type:`button`,onClick:()=>lt(e=>!e),"aria-pressed":t,disabled:e,title:e?F(`printers.drying.rotateUnavailableReason`):void 0,className:`h-8 w-full rounded-lg border px-2 text-sm font-medium transition-colors disabled:cursor-not-allowed disabled:opacity-50 ${t?`bg-bambu-green border-bambu-green text-white`:`bg-bambu-dark border-bambu-dark-tertiary text-white hover:bg-bambu-dark-tertiary disabled:hover:bg-bambu-dark`}`,children:F(`printers.drying.rotateTray`)})})(),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`text-[10px] text-white/70 font-medium mb-1 block`,children:F(`printers.drying.startMode`)}),(0,G.jsx)(`div`,{className:`grid grid-cols-3 gap-1`,children:[`now`,`delay`,`at_time`].map(e=>(0,G.jsx)(`button`,{type:`button`,onClick:()=>dt(e),className:`py-1 rounded-lg border text-[10px] font-medium transition-colors ${ut===e?`bg-bambu-green border-bambu-green text-white`:`bg-bambu-dark border-bambu-dark-tertiary text-white hover:bg-bambu-dark-tertiary`}`,children:F(e===`now`?`printers.drying.modeNow`:e===`delay`?`printers.drying.modeDelay`:`printers.drying.modeAtTime`)},e))}),ut===`delay`&&(0,G.jsx)(`div`,{className:`mt-1.5 grid grid-cols-4 gap-1`,children:WAe.map(e=>(0,G.jsx)(`button`,{type:`button`,"aria-pressed":ft===e,onClick:()=>pt(e),className:`py-1 rounded-lg border text-[10px] font-medium transition-colors ${ft===e?`bg-bambu-green border-bambu-green text-white`:`bg-bambu-dark border-bambu-dark-tertiary text-white hover:bg-bambu-dark-tertiary`}`,children:gp(e/60)},e))}),ut===`at_time`&&(0,G.jsx)(`input`,{ref:xt,type:`datetime-local`,"data-testid":`drying-start-at`,value:mt,onChange:e=>ht(e.target.value),className:`mt-1.5 w-full px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-[11px] focus:outline-none focus:border-bambu-green [color-scheme:dark]`})]})]}),(0,G.jsx)(`div`,{className:`shrink-0 h-px bg-bambu-dark-tertiary`}),(0,G.jsx)(`div`,{className:`shrink-0 px-3 pt-2.5 pb-3`,children:(0,G.jsx)(`button`,{onClick:()=>{if(Qe!==null){let e=(Dn.find(e=>e.id===Qe)?.tray??[]).some(e=>e.state===11),t=ct&&!e;if(ut===`now`)sr.mutate({amsId:Qe,temp:it,duration:ot,filament:nt,rotateTray:t});else{let e=kte(ut,ft,mt);e&&cr.mutate({amsId:Qe,temp:it,duration:ot,filament:nt,rotateTray:t,startAfter:e})}}},disabled:sr.isPending||cr.isPending||ut===`at_time`&&!mt,"data-testid":`drying-start-confirm`,className:`w-full py-1.5 bg-bambu-green hover:bg-bambu-green/80 text-white text-xs font-medium rounded-lg transition-colors disabled:opacity-50`,children:ut===`now`?sr.isPending?F(`printers.drying.startingDrying`):F(`printers.drying.start`):F(`printers.drying.schedule`)})})]}),(0,G.jsx)(`div`,{className:`fixed z-[102] w-2.5 h-2.5 rotate-45 bg-bambu-dark-secondary border-bambu-dark-tertiary pointer-events-none`,style:{left:gt.left+gt.arrowLeft-5,top:gt.anchorY-5,...gt.placement===`above`?{borderRightWidth:1,borderBottomWidth:1}:{borderLeftWidth:1,borderTopWidth:1}}})]})})()]})}function vje({onClose:e,onAdd:t,existingSerials:n}){let{t:r}=U(),[i,a]=(0,f.useState)({name:``,serial_number:``,ip_address:``,access_code:``,model:``,location:``,auto_archive:!0}),[o,s]=(0,f.useState)(!1),[c,l]=(0,f.useState)([]),[u,d]=(0,f.useState)(``),[p,m]=(0,f.useState)(!1),[h,g]=(0,f.useState)(!1),[_,v]=(0,f.useState)([]),[y,b]=(0,f.useState)(``),[x,S]=(0,f.useState)(``),[C,w]=(0,f.useState)(!1),[T,E]=(0,f.useState)({scanned:0,total:0}),[D,O]=(0,f.useState)(!1),[k,A]=(0,f.useState)(!1),[j,M]=(0,f.useState)(null);(0,f.useEffect)(()=>{Td.getInfo().then(e=>{g(e.is_docker),e.subnets.length>0&&(v(e.subnets),b(e.subnets[0]))}).catch(()=>{});try{let e=localStorage.getItem(`bambuddy.discovery.customSubnet`);e&&S(e)}catch{}},[]);let N=c.filter(e=>!n.includes(e.serial)),P=async e=>{e.preventDefault(),A(!0);try{let e=await Z.diagnoseConnection({ip_address:i.ip_address.trim(),serial_number:i.serial_number.trim()||void 0,access_code:i.access_code||void 0});if(e.checks.some(e=>e.status===`fail`)){M(e);return}}catch{}finally{A(!1)}t(i)},F=async()=>{d(``),l([]),s(!0),m(!1),E({scanned:0,total:0});let e=C?x.trim():y,t=h||C;if(t&&C)try{localStorage.setItem(`bambuddy.discovery.customSubnet`,e)}catch{}try{if(t){await Td.startSubnetScan(e);let t=setInterval(async()=>{try{let e=await Td.getScanStatus();E({scanned:e.scanned,total:e.total}),l(await Td.getDiscoveredPrinters()),e.running||(clearInterval(t),s(!1),m(!0))}catch(e){console.error(`Failed to get scan status:`,e)}},500)}else{await Td.startDiscovery(10);let e=setInterval(async()=>{try{l(await Td.getDiscoveredPrinters())}catch(e){console.error(`Failed to get discovered printers:`,e)}},1e3);setTimeout(async()=>{clearInterval(e);try{await Td.stopDiscovery()}catch{}s(!1),m(!0);try{l(await Td.getDiscoveredPrinters())}catch(e){console.error(`Failed to get final discovered printers:`,e)}},1e4)}}catch(e){console.error(`Failed to start discovery:`,e),d(e instanceof Error?e.message:r(`printers.discovery.failedToStart`)),s(!1),m(!0)}},I=e=>{let t=e.serial.startsWith(`unknown-`)?``:e.serial;a({...i,name:e.name||``,serial_number:t,ip_address:e.ip_address,model:ah(e.model)}),l([])};return(0,f.useEffect)(()=>()=>{Td.stopDiscovery().catch(()=>{}),Td.stopSubnetScan().catch(()=>{})},[]),(0,f.useEffect)(()=>{let t=t=>{t.key===`Escape`&&e()};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e]),(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-start sm:items-center justify-center z-50 p-4 overflow-y-auto`,onClick:e,children:(0,G.jsx)(Ud,{className:`w-full max-w-md my-auto max-h-[calc(100vh-2rem)] overflow-y-auto`,onClick:e=>e.stopPropagation(),children:(0,G.jsxs)(Gd,{children:[(0,G.jsx)(`h2`,{className:`text-xl font-semibold mb-4`,children:r(`printers.addPrinter`)}),(0,G.jsxs)(`div`,{className:`mb-4 pb-4 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`mb-3`,children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`printers.discovery.subnetToScan`)}),_.length>0?(0,G.jsxs)(`select`,{className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none text-sm`,value:C?`__custom__`:y,onChange:e=>{e.target.value===`__custom__`?w(!0):(w(!1),b(e.target.value))},disabled:o,children:[_.map(e=>(0,G.jsx)(`option`,{value:e,children:e},e)),(0,G.jsx)(`option`,{value:`__custom__`,children:r(`printers.discovery.customSubnetOption`)})]}):(0,G.jsx)(`input`,{type:`text`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none text-sm`,value:y,onChange:e=>b(e.target.value),placeholder:`192.168.1.0/24`,disabled:o}),C&&(0,G.jsx)(`input`,{type:`text`,"aria-label":r(`printers.discovery.customSubnetLabel`),className:`mt-2 w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none text-sm`,value:x,onChange:e=>S(e.target.value),placeholder:`10.1.1.0/24`,disabled:o}),(0,G.jsx)(`p`,{className:`mt-1 text-xs text-bambu-gray`,children:r(h?`printers.discovery.dockerNote`:`printers.discovery.customSubnetNote`)})]}),(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:F,disabled:o,className:`w-full`,children:o?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),(h||C)&&T.total>0?r(`printers.discovery.scanProgress`,{scanned:T.scanned,total:T.total}):r(`printers.discovery.scanning`)]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Yl,{className:`w-4 h-4`}),r(h||C?`printers.discovery.scanSubnet`:`printers.discovery.discoverNetwork`)]})}),u&&(0,G.jsx)(`div`,{className:`mt-2 text-sm text-red-700 dark:text-red-400`,children:u}),N.length>0&&(0,G.jsx)(`div`,{className:`mt-3 space-y-2 max-h-40 overflow-y-auto`,children:N.map(e=>(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-2 bg-bambu-dark rounded-lg hover:bg-bambu-dark-secondary cursor-pointer transition-colors`,onClick:()=>I(e),children:[(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,G.jsx)(`p`,{className:`font-medium text-white text-sm truncate`,children:e.name||e.serial}),(0,G.jsxs)(`p`,{className:`text-xs text-bambu-gray truncate`,children:[ah(e.model)||r(`printers.discovery.unknown`),` • `,e.ip_address,e.serial.startsWith(`unknown-`)&&(0,G.jsxs)(`span`,{className:`text-yellow-500`,children:[` • `,r(`printers.discovery.serialRequired`)]})]})]}),(0,G.jsx)(ss,{className:`w-4 h-4 text-bambu-gray -rotate-90 flex-shrink-0 ml-2`})]},e.serial))}),o&&(0,G.jsx)(`p`,{className:`mt-2 text-sm text-bambu-gray text-center`,children:r(h||C?`printers.discovery.scanningSubnet`:`printers.discovery.scanningNetwork`)}),p&&!o&&c.length===0&&(0,G.jsx)(`p`,{className:`mt-2 text-sm text-bambu-gray text-center`,children:r(h||C?`printers.discovery.noPrintersFoundSubnet`:`printers.discovery.noPrintersFoundNetwork`)}),p&&!o&&c.length>0&&N.length===0&&(0,G.jsx)(`p`,{className:`mt-2 text-sm text-bambu-gray text-center`,children:r(`printers.discovery.allConfigured`)})]}),(0,G.jsxs)(`form`,{onSubmit:P,className:`space-y-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`printers.name`)}),(0,G.jsx)(`input`,{type:`text`,required:!0,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,value:i.name,onChange:e=>a({...i,name:e.target.value}),placeholder:r(`printers.modal.myPrinter`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`printers.ipAddress`)}),(0,G.jsx)(`input`,{type:`text`,required:!0,pattern:`(\\d{1,3}(\\.\\d{1,3}){3}|[a-zA-Z0-9]([a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9])?(\\.[a-zA-Z0-9]([a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9])?)*)`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,value:i.ip_address,onChange:e=>a({...i,ip_address:e.target.value}),placeholder:`192.168.1.100 or printer.local`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`printers.serialNumber`)}),(0,G.jsx)(`input`,{type:`text`,required:!0,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,value:i.serial_number,onChange:e=>a({...i,serial_number:e.target.value}),placeholder:`01P00A000000000`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`printers.accessCode`)}),(0,G.jsx)(`input`,{type:`password`,required:!0,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,value:i.access_code,onChange:e=>a({...i,access_code:e.target.value}),placeholder:r(`printers.modal.fromPrinterSettings`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`printers.modal.modelOptional`)}),(0,G.jsxs)(`select`,{className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,value:i.model||``,onChange:e=>a({...i,model:e.target.value}),children:[(0,G.jsx)(`option`,{value:``,children:r(`printers.modal.selectModel`)}),(0,G.jsxs)(`optgroup`,{label:`A1 Series`,children:[(0,G.jsx)(`option`,{value:`A1`,children:`A1`}),(0,G.jsx)(`option`,{value:`A1 Mini`,children:`A1 Mini`})]}),(0,G.jsx)(`optgroup`,{label:`A2 Series`,children:(0,G.jsx)(`option`,{value:`A2L`,children:`A2L`})}),(0,G.jsxs)(`optgroup`,{label:`H2 Series`,children:[(0,G.jsx)(`option`,{value:`H2C`,children:`H2C`}),(0,G.jsx)(`option`,{value:`H2D`,children:`H2D`}),(0,G.jsx)(`option`,{value:`H2D Pro`,children:`H2D Pro`}),(0,G.jsx)(`option`,{value:`H2S`,children:`H2S`})]}),(0,G.jsxs)(`optgroup`,{label:`P Series`,children:[(0,G.jsx)(`option`,{value:`P1P`,children:`P1P`}),(0,G.jsx)(`option`,{value:`P1S`,children:`P1S`}),(0,G.jsx)(`option`,{value:`P2S`,children:`P2S`})]}),(0,G.jsxs)(`optgroup`,{label:`X1 Series`,children:[(0,G.jsx)(`option`,{value:`X1`,children:`X1`}),(0,G.jsx)(`option`,{value:`X1C`,children:`X1 Carbon`}),(0,G.jsx)(`option`,{value:`X1E`,children:`X1E`})]}),(0,G.jsx)(`optgroup`,{label:`X2 Series`,children:(0,G.jsx)(`option`,{value:`X2D`,children:`X2D`})})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`printers.modal.locationGroup`)}),(0,G.jsx)(`input`,{type:`text`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,value:i.location||``,onChange:e=>a({...i,location:e.target.value}),placeholder:r(`printers.modal.locationPlaceholder`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:r(`printers.locationHelp`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`input`,{type:`checkbox`,id:`auto_archive`,checked:i.auto_archive,onChange:e=>a({...i,auto_archive:e.target.checked}),className:`rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,G.jsx)(`label`,{htmlFor:`auto_archive`,className:`text-sm text-bambu-gray`,children:r(`printers.modal.autoArchiveLabel`)})]}),(0,G.jsxs)(`button`,{type:`button`,onClick:()=>O(!0),disabled:!i.ip_address.trim(),className:`w-full flex items-center justify-center gap-2 px-3 py-2 text-sm text-bambu-gray hover:text-white disabled:opacity-40 disabled:cursor-not-allowed border border-bambu-dark-tertiary rounded-lg transition-colors`,children:[(0,G.jsx)(yu,{className:`w-4 h-4`}),r(`diagnostic.runButton`)]}),j?(0,G.jsxs)(`div`,{className:`rounded-lg bg-amber-50 dark:bg-amber-500/10 border border-amber-300 dark:border-amber-500/30 p-3 space-y-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,G.jsx)(Lu,{className:`w-4 h-4 mt-0.5 flex-shrink-0 text-amber-600 dark:text-amber-400`}),(0,G.jsx)(`p`,{className:`text-sm text-amber-700 dark:text-amber-300`,children:r(`printers.addPreflight.warning`)})]}),(0,G.jsx)(zm,{result:j}),(0,G.jsxs)(`div`,{className:`flex gap-3`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:()=>M(null),className:`flex-1`,children:r(`printers.addPreflight.back`)}),(0,G.jsx)(Q,{type:`button`,onClick:()=>t(i),className:`flex-1`,children:r(`printers.addPreflight.saveAnyway`)})]})]}):(0,G.jsxs)(`div`,{className:`flex gap-3 pt-2`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:e,className:`flex-1`,children:r(`common.cancel`)}),(0,G.jsx)(Q,{type:`submit`,disabled:k,className:`flex-1`,children:r(k?`printers.addPreflight.checking`:`printers.addPrinter`)})]})]})]})})}),D&&(0,G.jsx)(Bm,{connection:{ip_address:i.ip_address.trim(),serial_number:i.serial_number.trim()||void 0,access_code:i.access_code||void 0},printerName:i.name||null,onClose:()=>O(!1)})]})}function yje({printer:e,firmwareInfo:t,onClose:n}){let{t:r}=U(),i=no(),{showToast:a}=Zd(),{hasPermission:o}=Ld(),s=o(`firmware:update`),[c,l]=(0,f.useState)(null),[u,d]=(0,f.useState)(!1),[p,m]=(0,f.useState)(null),[h,g]=(0,f.useState)(t.update_available?t.latest_version:null),{data:_,isLoading:v}=K({queryKey:[`firmwarePrepare`,e.id,h],queryFn:()=>kd.prepareUpload(e.id,h??void 0),staleTime:3e4,enabled:!!h&&s&&!u}),y=q({mutationFn:()=>kd.startUpload(e.id,h??void 0),onSuccess:()=>{d(!0);let t=setInterval(async()=>{try{let n=await kd.getUploadStatus(e.id);l(n),(n.status===`complete`||n.status===`error`)&&(clearInterval(t),m(null),d(!1),n.status===`complete`&&(a(r(`printers.firmwareModal.uploadedToast`),`success`),i.invalidateQueries({queryKey:[`firmwareUpdate`,e.id]})))}catch{}},2e3);m(t)},onError:e=>{a(r(`printers.firmwareModal.uploadFailed`,{error:e.message}),`error`),d(!1)}});return(0,f.useEffect)(()=>()=>{p&&clearInterval(p)},[p]),(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50`,children:(0,G.jsx)(Ud,{className:`w-full max-w-md mx-4`,children:(0,G.jsxs)(Gd,{children:[(0,G.jsxs)(`div`,{className:`flex items-start gap-3 mb-4`,children:[(0,G.jsx)(`div`,{className:`p-2 rounded-full ${t.update_available?`bg-orange-100 dark:bg-orange-500/20`:`bg-status-ok/20`}`,children:t.update_available?(0,G.jsx)(Gs,{className:`w-5 h-5 text-orange-600 dark:text-orange-400`}):(0,G.jsx)(hs,{className:`w-5 h-5 text-status-ok`})}),(0,G.jsxs)(`div`,{className:`flex-1`,children:[(0,G.jsx)(`h3`,{className:`text-lg font-semibold text-white`,children:t.update_available?r(`printers.firmwareModal.title`):r(`printers.firmwareModal.titleUpToDate`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:e.name})]})]}),(()=>{let e=h?t.available_versions?.find(e=>e.version===h):null,n=h??t.latest_version,i=e?.release_notes??t.release_notes,a=!!n&&n!==t.current_version;return(0,G.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-3 mb-4`,children:[(0,G.jsxs)(`div`,{className:`flex justify-between items-center text-sm`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:r(`printers.firmwareModal.currentVersion`)}),(0,G.jsx)(`span`,{className:`font-mono ${a?`text-white`:`text-status-ok`}`,children:t.current_version||r(`common.unknown`)})]}),a&&(0,G.jsxs)(`div`,{className:`flex justify-between items-center text-sm mt-1`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:r(`printers.firmwareModal.latestVersion`)}),(0,G.jsx)(`span`,{className:`text-orange-700 dark:text-orange-400 font-mono`,children:n})]}),i&&(0,G.jsxs)(`details`,{className:`mt-3 text-sm`,open:!a,children:[(0,G.jsx)(`summary`,{className:`cursor-pointer hover:underline ${a?`text-orange-700 dark:text-orange-400`:`text-status-ok`}`,children:r(`printers.firmwareModal.releaseNotes`)}),(0,G.jsx)(`div`,{className:`mt-2 text-bambu-gray text-xs max-h-40 overflow-y-auto whitespace-pre-wrap`,children:i})]},n??`none`)]})})(),t.available_versions&&t.available_versions.length>0&&!u&&c?.status!==`complete`&&(0,G.jsxs)(`div`,{className:`mb-4`,children:[(0,G.jsx)(`div`,{className:`text-xs text-bambu-gray mb-2`,children:r(`printers.firmwareModal.availableVersions`)}),(0,G.jsx)(`div`,{className:`max-h-56 overflow-y-auto border border-bambu-dark-tertiary rounded-lg divide-y divide-bambu-dark-tertiary`,children:t.available_versions.map(e=>{let n=t.current_version===e.version,i=h===e.version,a=t.current_version?yte(e.version,t.current_version):0,o=r(n?`printers.firmwareModal.currentBadge`:a>0?`printers.firmwareModal.newerBadge`:`printers.firmwareModal.olderBadge`),c=n?`text-bambu-gray`:a>0?`text-orange-700 dark:text-orange-400`:`text-blue-700 dark:text-blue-400`;return(0,G.jsxs)(`button`,{type:`button`,disabled:!e.file_available||!s||n,onClick:()=>g(e.version),className:`w-full text-left px-3 py-2 text-sm flex items-center justify-between gap-2 transition-colors ${i?`bg-orange-50 dark:bg-orange-500/10`:`hover:bg-bambu-dark`} ${!e.file_available||!s||n?`opacity-60 cursor-not-allowed`:`cursor-pointer`}`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,G.jsx)(`span`,{className:`font-mono text-white`,children:e.version}),(0,G.jsx)(`span`,{className:`text-xs ${c}`,children:o})]}),(0,G.jsx)(`span`,{className:`text-xs px-2 py-0.5 rounded-full ${n?`bg-blue-50 dark:bg-blue-500/15 text-blue-700 dark:text-blue-400 border border-blue-300 dark:border-blue-500/30`:e.file_available?`bg-bambu-green/15 text-bambu-green border border-bambu-green/30`:`bg-bambu-gray/10 text-bambu-gray border border-bambu-gray/30`}`,children:n?r(`printers.firmwareModal.installed`):e.file_available?r(`printers.firmwareModal.usable`):r(`printers.firmwareModal.unavailable`)})]},e.version)})})]}),h?v?(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray text-sm mb-4`,children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),r(`printers.firmwareModal.checkingPrereqs`)]}):_&&!u&&!c?(0,G.jsx)(`div`,{className:`mb-4`,children:_.can_proceed?(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-green text-sm`,children:[(0,G.jsx)(Wo,{className:`w-4 h-4`}),r(`printers.firmwareModal.sdCardReady`)]}):(0,G.jsx)(`div`,{className:`space-y-1`,children:_.errors.map((e,t)=>(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-red-700 dark:text-red-400 text-sm`,children:[(0,G.jsx)(ps,{className:`w-4 h-4 flex-shrink-0`}),e]},t))})}):null:null,(u||c)&&c&&(0,G.jsxs)(`div`,{className:`mb-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between text-sm mb-1`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray capitalize`,children:c.status}),(0,G.jsxs)(`span`,{className:`text-white`,children:[c.progress,`%`]})]}),(0,G.jsx)(`div`,{className:`w-full bg-bambu-dark-tertiary rounded-full h-2`,children:(0,G.jsx)(`div`,{className:`h-2 rounded-full transition-all ${c.status===`error`?`bg-status-error`:c.status===`complete`?`bg-status-ok`:`bg-orange-500`} ${c.status===`uploading`?`animate-pulse`:``}`,style:{width:`${c.progress}%`}})}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:c.message}),c.error&&(0,G.jsx)(`p`,{className:`text-xs text-red-700 dark:text-red-400 mt-1`,children:c.error})]}),c?.status===`complete`&&(0,G.jsxs)(`div`,{className:`bg-bambu-green/10 border border-bambu-green/30 rounded-lg p-3 mb-4`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-green font-medium mb-2`,children:r(`printers.firmwareModal.uploadedSuccess`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:r(`printers.firmwareModal.applyInstructions`)}),(0,G.jsxs)(`ol`,{className:`text-xs text-bambu-gray mt-1 list-decimal list-inside space-y-1`,children:[(0,G.jsx)(`li`,{dangerouslySetInnerHTML:{__html:r(`printers.firmwareModal.step1`)}}),(0,G.jsx)(`li`,{dangerouslySetInnerHTML:{__html:r(`printers.firmwareModal.step2`)}}),(0,G.jsx)(`li`,{dangerouslySetInnerHTML:{__html:r(`printers.firmwareModal.step3`)}}),(0,G.jsx)(`li`,{children:r(`printers.firmwareModal.step4`)})]})]}),(0,G.jsxs)(`div`,{className:`flex gap-2 justify-end`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:n,children:c?.status===`complete`?r(`printers.firmwareModal.done`):r(`common.cancel`)}),_?.can_proceed&&!u&&c?.status!==`complete`&&s&&(0,G.jsx)(Q,{onClick:()=>{l(null),y.mutate()},disabled:y.isPending,children:y.isPending?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin mr-2`}),r(`printers.firmwareModal.starting`)]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Gs,{className:`w-4 h-4 mr-2`}),r(`printers.firmwareModal.uploadFirmware`)]})})]})]})})})}function bje({printer:e,onClose:t}){let{t:n}=U(),r=no(),{showToast:i}=Zd(),[a,o]=(0,f.useState)({name:e.name,ip_address:e.ip_address,access_code:``,model:e.model||``,location:e.location||``,auto_archive:e.auto_archive,is_active:e.is_active}),[s,c]=(0,f.useState)(!1),[l,u]=(0,f.useState)(null),d=q({mutationFn:t=>Z.updatePrinter(e.id,t),onSuccess:()=>{r.invalidateQueries({queryKey:[`printers`]}),r.invalidateQueries({queryKey:[`printerStatus`,e.id]}),t()},onError:e=>i(e.message||n(`printers.toast.failedToUpdate`),`error`)});(0,f.useEffect)(()=>{let e=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]);let p=()=>{let e={name:a.name,ip_address:a.ip_address,model:a.model||void 0,location:a.location||void 0,auto_archive:a.auto_archive,is_active:a.is_active};a.access_code&&(e.access_code=a.access_code),d.mutate(e)};return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-start sm:items-center justify-center z-50 p-4 overflow-y-auto`,onClick:t,children:(0,G.jsx)(Ud,{className:`w-full max-w-md my-auto max-h-[calc(100vh-2rem)] overflow-y-auto`,onClick:e=>e.stopPropagation(),children:(0,G.jsxs)(Gd,{children:[(0,G.jsx)(`h2`,{className:`text-xl font-semibold mb-4`,children:n(`printers.editPrinter`)}),(0,G.jsxs)(`form`,{onSubmit:async t=>{t.preventDefault(),c(!0);try{let t=await Z.diagnoseConnection({ip_address:a.ip_address.trim(),serial_number:e.serial_number,access_code:a.access_code||void 0});if(t.checks.some(e=>e.status===`fail`)){u(t);return}}catch{}finally{c(!1)}p()},className:`space-y-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`printers.name`)}),(0,G.jsx)(`input`,{type:`text`,required:!0,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,value:a.name,onChange:e=>o({...a,name:e.target.value}),placeholder:n(`printers.modal.myPrinter`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`printers.ipAddress`)}),(0,G.jsx)(`input`,{type:`text`,required:!0,pattern:`(\\d{1,3}(\\.\\d{1,3}){3}|[a-zA-Z0-9]([a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9])?(\\.[a-zA-Z0-9]([a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9])?)*)`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,value:a.ip_address,onChange:e=>o({...a,ip_address:e.target.value}),placeholder:`192.168.1.100 or printer.local`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`printers.serialNumber`)}),(0,G.jsx)(`input`,{type:`text`,disabled:!0,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray cursor-not-allowed`,value:e.serial_number}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(`printers.serialCannotBeChanged`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`printers.accessCode`)}),(0,G.jsx)(`input`,{type:`password`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,value:a.access_code,onChange:e=>o({...a,access_code:e.target.value}),placeholder:n(`printers.accessCodePlaceholder`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`printers.model`)}),(0,G.jsxs)(`select`,{className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,value:a.model,onChange:e=>o({...a,model:e.target.value}),children:[(0,G.jsx)(`option`,{value:``,children:n(`printers.modal.selectModel`)}),(0,G.jsxs)(`optgroup`,{label:`A1 Series`,children:[(0,G.jsx)(`option`,{value:`A1`,children:`A1`}),(0,G.jsx)(`option`,{value:`A1 Mini`,children:`A1 Mini`})]}),(0,G.jsx)(`optgroup`,{label:`A2 Series`,children:(0,G.jsx)(`option`,{value:`A2L`,children:`A2L`})}),(0,G.jsxs)(`optgroup`,{label:`H2 Series`,children:[(0,G.jsx)(`option`,{value:`H2C`,children:`H2C`}),(0,G.jsx)(`option`,{value:`H2D`,children:`H2D`}),(0,G.jsx)(`option`,{value:`H2D Pro`,children:`H2D Pro`}),(0,G.jsx)(`option`,{value:`H2S`,children:`H2S`})]}),(0,G.jsxs)(`optgroup`,{label:`P Series`,children:[(0,G.jsx)(`option`,{value:`P1P`,children:`P1P`}),(0,G.jsx)(`option`,{value:`P1S`,children:`P1S`}),(0,G.jsx)(`option`,{value:`P2S`,children:`P2S`})]}),(0,G.jsxs)(`optgroup`,{label:`X1 Series`,children:[(0,G.jsx)(`option`,{value:`X1`,children:`X1`}),(0,G.jsx)(`option`,{value:`X1C`,children:`X1 Carbon`}),(0,G.jsx)(`option`,{value:`X1E`,children:`X1E`})]}),(0,G.jsx)(`optgroup`,{label:`X2 Series`,children:(0,G.jsx)(`option`,{value:`X2D`,children:`X2D`})})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:`Location / Group`}),(0,G.jsx)(`input`,{type:`text`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,value:a.location,onChange:e=>o({...a,location:e.target.value}),placeholder:n(`printers.modal.locationPlaceholder`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(`printers.locationHelp`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`input`,{type:`checkbox`,id:`edit_auto_archive`,checked:a.auto_archive,onChange:e=>o({...a,auto_archive:e.target.checked}),className:`rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,G.jsx)(`label`,{htmlFor:`edit_auto_archive`,className:`text-sm text-bambu-gray`,children:n(`printers.modal.autoArchiveLabel`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`input`,{type:`checkbox`,id:`edit_maintenance_mode`,checked:!a.is_active,onChange:e=>o({...a,is_active:!e.target.checked}),className:`rounded border-bambu-dark-tertiary bg-bambu-dark text-amber-400 focus:ring-amber-400`}),(0,G.jsxs)(`label`,{htmlFor:`edit_maintenance_mode`,className:`text-sm text-bambu-gray flex items-center gap-1.5`,children:[(0,G.jsx)(td,{className:`w-3.5 h-3.5 text-amber-600 dark:text-amber-400`}),n(`printers.maintenance.editFieldLabel`)]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray/70 mt-1 ml-6`,children:n(`printers.maintenance.editFieldHelp`)})]}),l?(0,G.jsxs)(`div`,{className:`rounded-lg bg-amber-50 dark:bg-amber-500/10 border border-amber-300 dark:border-amber-500/30 p-3 space-y-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,G.jsx)(Lu,{className:`w-4 h-4 mt-0.5 flex-shrink-0 text-amber-600 dark:text-amber-400`}),(0,G.jsx)(`p`,{className:`text-sm text-amber-700 dark:text-amber-300`,children:n(`printers.addPreflight.warning`)})]}),(0,G.jsx)(zm,{result:l}),(0,G.jsxs)(`div`,{className:`flex gap-3`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:()=>u(null),className:`flex-1`,children:n(`printers.addPreflight.back`)}),(0,G.jsx)(Q,{type:`button`,onClick:p,className:`flex-1`,disabled:d.isPending,children:n(`printers.addPreflight.saveAnyway`)})]})]}):(0,G.jsxs)(`div`,{className:`flex gap-3 pt-4`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:t,className:`flex-1`,children:n(`common.cancel`)}),(0,G.jsx)(Q,{type:`submit`,className:`flex-1`,disabled:d.isPending||s,children:s?n(`printers.addPreflight.checking`):d.isPending?n(`common.saving`):n(`printers.modal.saveChanges`)})]})]})]})})})}function xje(e){let{data:t}=K({queryKey:[`printerStatus`,e],queryFn:()=>Z.getPrinterStatus(e),refetchInterval:3e4});return!t?.connected}function Sje({printer:e,plug:t,onPowerOn:n,isPowering:r}){let i=xje(e.id),{data:a}=K({queryKey:[`smartPlugStatus`,t.id],queryFn:()=>Z.getSmartPlugStatus(t.id),refetchInterval:1e4});return i?(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-2 hover:bg-gray-100 dark:hover:bg-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,G.jsx)(`span`,{className:`text-sm text-white truncate`,children:e.name}),a&&(0,G.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded ${a.state===`ON`?`bg-bambu-green/20 text-bambu-green`:`bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400`}`,children:a.state||`?`})]}),(0,G.jsxs)(`button`,{onClick:()=>n(t.id),disabled:r||a?.state===`ON`,className:`px-2 py-1 text-xs rounded transition-colors flex items-center gap-1 ${a?.state===`ON`?`bg-bambu-green/20 text-bambu-green cursor-default`:`bg-bambu-green/20 text-bambu-green hover:bg-bambu-green hover:text-white`}`,children:[(0,G.jsx)(Pl,{className:`w-3 h-3`}),r?`...`:`On`]})]}):null}function Cje(){let{t:e}=U(),{resolvedMode:t,darkAccent:n,lightAccent:r}=Bd(),i={green:`bg-green-500 text-white hover:bg-green-400 border-green-400/60`,teal:`bg-teal-500 text-white hover:bg-teal-400 border-teal-400/60`,blue:`bg-blue-500 text-white hover:bg-blue-400 border-blue-400/60`,orange:`bg-orange-500 text-white hover:bg-orange-400 border-orange-400/60`,purple:`bg-purple-500 text-white hover:bg-purple-400 border-purple-400/60`,red:`bg-red-500 text-white hover:bg-red-400 border-red-400/60`}[t===`dark`?n:r],[a,o]=(0,f.useState)(!1),[s,c]=(0,f.useState)(()=>localStorage.getItem(`hideDisconnectedPrinters`)===`true`),[l,u]=(0,f.useState)(!1),[d,p]=(0,f.useState)(null),[m,h]=(0,f.useState)(()=>localStorage.getItem(`printerSortBy`)||`name`),[g,_]=(0,f.useState)(()=>localStorage.getItem(`printerSortAsc`)!==`false`),[v,y]=(0,f.useState)(()=>{let e=localStorage.getItem(`printerCardSize`);return e?parseInt(e,10):2}),[b,x]=(0,f.useState)(()=>localStorage.getItem(`printerPageView`)===`camwall`?`camwall`:`cards`),[S,C]=(0,f.useState)(()=>{let e=parseInt(localStorage.getItem(`camWallMaxLive`)||``,10);return Number.isFinite(e)&&e>0?e:4}),[w,T]=(0,f.useState)(()=>{let e=parseInt(localStorage.getItem(`camWallSnapshotSec`)||``,10);return Number.isFinite(e)&&e>0?e:8}),[E,D]=(0,f.useState)(()=>{let e=localStorage.getItem(`camWallStatusMode`);return e===`off`||e===`compact`||e===`full`?e:`full`}),O=v===1?`compact`:`expanded`,[k,A]=(0,f.useState)(null),j=(0,f.useCallback)(e=>{requestAnimationFrame(()=>{requestAnimationFrame(()=>{let t=document.getElementById(`printer-card-${e}`);if(!t)return;let n=document.querySelector(`header`)?.getBoundingClientRect().height??56,r=t.getBoundingClientRect().top+window.scrollY-n-16;window.scrollTo({top:Math.max(0,r),behavior:`smooth`})})})},[]),M=(0,f.useCallback)(e=>{A(e),y(2),localStorage.setItem(`printerCardSize`,`2`),j(e)},[j]),N=(0,f.useCallback)(()=>{let e=k;A(null),y(1),localStorage.setItem(`printerCardSize`,`1`),e!=null&&j(e)},[k,j]),[P,F]=(0,f.useState)(``),[I,L]=(0,f.useState)(()=>{let e=localStorage.getItem(`printerStatusFilter`);return XAe(e)?e:`all`}),[R,z]=(0,f.useState)(()=>localStorage.getItem(`printerLocationFilter`)||`all`),[B,V]=(0,f.useState)(0),[ee,te]=(0,f.useState)(()=>{try{let e=localStorage.getItem(`printerCollapsedSections`);return e?JSON.parse(e):{}}catch{return{}}}),ne=no(),{showToast:re}=Zd(),{hasPermission:ie}=Ld(),[ae,oe]=(0,f.useState)(()=>Tte()),[se,H]=(0,f.useState)(()=>{let e=localStorage.getItem(`openEmbeddedCameras`);if(e)try{let t=JSON.parse(e);return new Map(t.map(e=>[e.id,e]))}catch{return new Map}return new Map});(0,f.useEffect)(()=>{let e=Array.from(se.values());e.length>0?localStorage.setItem(`openEmbeddedCameras`,JSON.stringify(e)):localStorage.removeItem(`openEmbeddedCameras`)},[se]);let{data:ce,isLoading:le}=K({queryKey:[`printers`],queryFn:Z.getPrinters}),{data:ue}=K({queryKey:[`ui-preferences`],queryFn:Z.getUiPreferences}),de=ue!==void 0&&ue.check_printer_firmware!==!1,fe=(0,f.useMemo)(()=>ph(ue?.nozzle_temp_presets,lh,0,320),[ue?.nozzle_temp_presets]),pe=(0,f.useMemo)(()=>ph(ue?.bed_temp_presets,uh,0,140),[ue?.bed_temp_presets]),me=(0,f.useMemo)(()=>ph(ue?.chamber_temp_presets,dh,0,65),[ue?.chamber_temp_presets]),he=(0,f.useMemo)(()=>ph(ue?.fan_speed_presets,fh,0,100),[ue?.fan_speed_presets]),ge=(0,f.useMemo)(()=>{if(ue?.drying_presets)try{let e=JSON.parse(ue.drying_presets);if(typeof e==`object`&&e&&Object.keys(e).length>0)return{...dW,...e}}catch{}return dW},[ue?.drying_presets]),_e=ae??(ue?.camera_view_mode===`embedded`?`embedded`:`window`),ve=(0,f.useCallback)(e=>{Ete(e),oe(e),ie(`settings:update`)&&Z.updateSettings({camera_view_mode:e}).then(()=>ne.invalidateQueries({queryKey:[`ui-preferences`]})).catch(e=>console.warn(`Could not save camera view mode as the default:`,e))},[ie,ne]),{data:ye}=K({queryKey:[`smart-plugs`],queryFn:Z.getSmartPlugs}),{data:be}=K({queryKey:[`maintenanceOverview`],queryFn:Z.getMaintenanceOverview,staleTime:60*1e3}),{data:xe}=K({queryKey:[`obico-printer-status`],queryFn:Z.getObicoPrinterStatus,refetchInterval:1e4}),Se=(0,f.useCallback)(e=>xe?.enabled===!0&&(xe.monitored_printers===null||xe.monitored_printers.includes(e)),[xe]),{data:Ce}=K({queryKey:[`spoolman-status`],queryFn:Z.getSpoolmanStatus,staleTime:60*1e3}),we=Ce?.enabled&&Ce?.connected,{data:Te}=K({queryKey:[`spoolman-settings`],queryFn:Z.getSpoolmanSettings,enabled:!!we,staleTime:60*1e3}),Ee=Te?.spoolman_sync_mode,{data:De}=K({queryKey:[`unlinked-spools`],queryFn:Z.getUnlinkedSpools,enabled:!!we,staleTime:30*1e3}),Oe=De&&De.length>0,{data:ke}=K({queryKey:[`linked-spools`],queryFn:Z.getLinkedSpools,enabled:!!we,staleTime:30*1e3}),Ae=ke?.linked,{data:je}=K({queryKey:[`spool-assignments`],queryFn:()=>Z.getAssignments(),enabled:ie(`inventory:view_assignments`),staleTime:30*1e3}),Me=q({mutationFn:({printerId:e,amsId:t,trayId:n})=>Z.unassignSpool(e,t,n),onSuccess:()=>{ne.invalidateQueries({queryKey:[`spool-assignments`]})}}),{data:Ne,isLoading:Pe}=K({queryKey:[`spoolman-inventory-spools`],queryFn:()=>Z.getSpoolmanInventorySpools(!1),enabled:!!we,staleTime:30*1e3}),{data:Fe,isLoading:Ie}=K({queryKey:[`spoolman-slot-assignments`],queryFn:()=>Z.getSpoolmanSlotAssignments(),enabled:!!we,staleTime:30*1e3}),Le=q({mutationFn:e=>Z.unassignSpoolmanSlot(e),onSuccess:()=>{ne.invalidateQueries({queryKey:[`spoolman-inventory-spools`]}),ne.invalidateQueries({queryKey:[`spoolman-slot-assignments`]})}}),Re=(e,t,n)=>je?.find(r=>r.printer_id===e&&r.ams_id===Number(t)&&r.tray_id===Number(n)),ze=be?.reduce((e,t)=>(e[t.printer_id]={due_count:t.due_count,warning_count:t.warning_count,total_print_hours:t.total_print_hours},e),{})||{},Be=ye?.reduce((e,t)=>(t.printer_id&&(e[t.printer_id]=t),e),{})||{},Ve=q({mutationFn:Z.createPrinter,onSuccess:()=>{ne.invalidateQueries({queryKey:[`printers`]}),ne.invalidateQueries({queryKey:[`maintenanceOverview`]}),o(!1)},onError:t=>{if(t instanceof sd&&t.code===`printer_connection_failed`){re(e(`printers.toast.connectionFailedNotAdded`),`error`);return}re(t.message||e(`printers.toast.failedToAdd`),`error`)}}),He=q({mutationFn:e=>Z.controlSmartPlug(e,`on`),onSuccess:()=>{ne.invalidateQueries({queryKey:[`smart-plugs`]}),p(null)},onError:()=>{p(null)}}),[Ue,We]=(0,f.useState)(new Set),[Ge,Ke]=(0,f.useState)(!1),[qe,Je]=(0,f.useState)(null),[Ye,Xe]=(0,f.useState)(!1),Ze=Ge||Ue.size>0,Qe=(0,f.useCallback)(e=>{We(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),$e=(0,f.useCallback)(()=>{We(new Set),Ke(!1)},[]);(0,f.useEffect)(()=>{let e=e=>{e.key===`Escape`&&Ze&&$e()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[Ze,$e]);let et=(0,f.useCallback)(async t=>{Xe(!0);let n=Array.from(Ue).filter(e=>{let n=ne.getQueryData([`printerStatus`,e]);if(t===`clearPlate`)return!!n?.awaiting_plate_clear;if(!n?.connected)return!1;switch(t){case`stop`:return n.state===`RUNNING`||n.state===`PAUSE`;case`pause`:return n.state===`RUNNING`;case`resume`:return n.state===`PAUSE`;case`clearHMS`:return n.hms_errors&&bh(n.hms_errors).length>0;default:return!1}});if(n.length===0){re(e(`printers.bulk.noneApplicable`),`error`),Xe(!1),Je(null);return}let r={stop:Z.stopPrint,pause:Z.pausePrint,resume:Z.resumePrint,clearPlate:Z.clearPlate,clearHMS:Z.clearHMSErrors}[t],i=await Promise.allSettled(n.map(e=>r(e))),a=i.filter(e=>e.status===`fulfilled`).length,o=i.filter(e=>e.status===`rejected`).length;o===0?re(e(`printers.bulk.success`,{action:e(`printers.bulk.actions.${t}`),count:a})):re(e(`printers.bulk.partial`,{succeeded:a,failed:o}),`error`),n.forEach(e=>{ne.invalidateQueries({queryKey:[`printerStatus`,e]})}),Xe(!1),Je(null)},[Ue,ne,re,e]),tt=(0,f.useCallback)(e=>{e===`stop`||e===`pause`||e===`clearPlate`?Je(e):et(e)},[et]),nt=()=>{let e=!s;c(e),localStorage.setItem(`hideDisconnectedPrinters`,String(e))},rt=e=>{h(e),localStorage.setItem(`printerSortBy`,e)},it=e=>{L(e),localStorage.setItem(`printerStatusFilter`,e)},at=e=>{z(e),localStorage.setItem(`printerLocationFilter`,e)},ot=()=>{let e=!g;_(e),localStorage.setItem(`printerSortAsc`,String(e))},st=()=>{switch(v){case 1:return`grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5`;case 2:return`grid-cols-1 md:grid-cols-2 xl:grid-cols-3`;case 3:return`grid-cols-1 lg:grid-cols-2`;case 4:return`grid-cols-1`;default:return`grid-cols-1 md:grid-cols-2 xl:grid-cols-3`}},ct=[`S`,`M`,`L`,`XL`];(0,f.useEffect)(()=>ne.getQueryCache().subscribe(e=>{e.type===`updated`&&Array.isArray(e.query.queryKey)&&e.query.queryKey[0]===`printerStatus`&&V(e=>e+1)}),[ne]);let lt=(0,f.useMemo)(()=>{if(!ce)return[];let e=ce;if(P.trim()){let t=P.trim().toLowerCase();e=e.filter(e=>e.name.toLowerCase().includes(t)||(e.model||``).toLowerCase().includes(t)||(e.location||``).toLowerCase().includes(t)||(e.serial_number||``).toLowerCase().includes(t))}return R!==`all`&&(e=e.filter(e=>(e.location||``)===R)),I!==`all`&&(e=e.filter(e=>{let t=ne.getQueryData([`printerStatus`,e.id]);if(!t?.connected)return I===`offline`;let n=t.hms_errors?bh(t.hms_errors):[];switch(I){case`printing`:return t.state===`RUNNING`;case`paused`:return t.state===`PAUSE`;case`finished`:return t.state===`FINISH`;case`error`:return t.state===`FAILED`||n.length>0;case`idle`:return t.state!==`RUNNING`&&t.state!==`PAUSE`&&t.state!==`FINISH`&&t.state!==`FAILED`&&n.length===0;case`offline`:return!1;default:return!0}})),e},[ce,P,I,R,ne,B]),ut=(0,f.useMemo)(()=>ce?[...new Set(ce.map(e=>e.location||``).filter(Boolean))].sort():[],[ce]);(0,f.useEffect)(()=>{!ce||R===`all`||ut.includes(R)||(z(`all`),localStorage.setItem(`printerLocationFilter`,`all`))},[ce,ut,R]);let dt=(0,f.useMemo)(()=>{let e=[...lt];switch(m){case`name`:e.sort((e,t)=>e.name.localeCompare(t.name));break;case`model`:e.sort((e,t)=>(e.model||``).localeCompare(t.model||``));break;case`location`:e.sort((e,t)=>{let n=e.location||``,r=t.location||``;return!n&&r?1:n&&!r?-1:n.localeCompare(r)||e.name.localeCompare(t.name)});break;case`status`:e.sort((e,t)=>{let n=ne.getQueryData([`printerStatus`,e.id]),r=ne.getQueryData([`printerStatus`,t.id]),i=e=>e?.connected?(e.hms_errors?bh(e.hms_errors):[]).length>0?0:e.state===`RUNNING`?1:2:3;return i(n)-i(r)});break;case`eta`:e.sort((e,t)=>{let n=ne.getQueryData([`printerStatus`,e.id]),r=ne.getQueryData([`printerStatus`,t.id]),i=e=>e?.connected?e.state===`RUNNING`&&e.remaining_time!=null&&e.remaining_time>0?0:e.state===`RUNNING`?1:2:3,a=i(n),o=i(r);if(a!==o)return a-o;if(a===0){let e=(n.remaining_time??0)-(r.remaining_time??0);if(e!==0)return e}return e.name.localeCompare(t.name)});break}return g||e.reverse(),e},[lt,m,g,ne]),ft=(0,f.useCallback)(()=>{We(new Set(dt.map(e=>e.id))),Ke(!0)},[dt]),pt=(0,f.useCallback)(e=>{We(t=>{let n=new Set(t);return dt.forEach(t=>{lW(ne.getQueryData([`printerStatus`,t.id]))===e&&n.add(t.id)}),n}),Ke(!0)},[dt,ne]),mt=(0,f.useCallback)(e=>{We(t=>{let n=new Set(t);return dt.filter(t=>(t.location||``)===e).forEach(e=>n.add(e.id)),n}),Ke(!0)},[dt]),ht=(0,f.useCallback)(e=>{We(t=>{let n=new Set(t);return dt.filter(t=>(t.model||`Unknown`)===e).forEach(e=>n.add(e.id)),n}),Ke(!0)},[dt]),gt=(0,f.useCallback)(e=>{te(t=>{let n={...t,[e]:!t[e]};try{localStorage.setItem(`printerCollapsedSections`,JSON.stringify(n))}catch{}return n})},[]),_t=(0,f.useMemo)(()=>{if(m===`name`||m===`eta`)return null;let e={};return m===`location`?dt.forEach(t=>{let n=t.location||`Ungrouped`;e[n]||(e[n]=[]),e[n].push(t)}):m===`model`?dt.forEach(t=>{let n=t.model||`Unknown`;e[n]||(e[n]=[]),e[n].push(t)}):m===`status`&&dt.forEach(t=>{let n=lW(ne.getQueryData([`printerStatus`,t.id]));e[n]||(e[n]=[]),e[n].push(t)}),e},[m,dt,ne,B]),vt=(0,f.useRef)(null),yt=(0,f.useRef)(null),bt=(0,f.useRef)(0),[xt,St]=(0,f.useState)(!1),Ct=(0,f.useCallback)(()=>{let e=vt.current;if(!e)return;let t=yt.current?.offsetWidth;t&&(bt.current=t);let n=bt.current>0&&e.clientWidthe===n?e:n)},[]),wt=Object.keys(Be).length;(0,f.useLayoutEffect)(()=>{Ct();let e=vt.current;if(!e)return;if(typeof ResizeObserver>`u`)return window.addEventListener(`resize`,Ct),()=>window.removeEventListener(`resize`,Ct);let t=new ResizeObserver(()=>Ct());return t.observe(e),window.addEventListener(`resize`,Ct),()=>{t.disconnect(),window.removeEventListener(`resize`,Ct)}},[Ct,ce?.length,ut.length,s,wt]);let Tt=(t=!1)=>(0,G.jsxs)(G.Fragment,{children:[ce&&ce.length>0&&(0,G.jsx)(iW,{value:I,onChange:it,fullWidth:t,options:KU.map(t=>({value:t.value,label:e(t.labelKey)}))}),ce&&ce.length>0&&ut.length>0&&(0,G.jsx)(iW,{value:R,onChange:at,fullWidth:t,options:[{value:`all`,label:e(`printers.filter.allLocations`)},...ut.map(e=>({value:e,label:e}))]}),(0,G.jsx)(`button`,{type:`button`,onClick:nt,"aria-pressed":s,className:`h-8 px-2 rounded-lg border text-sm font-medium transition-colors ${t?`w-full`:``} ${s?`bg-bambu-green border-bambu-green text-white`:`bg-bambu-dark border-bambu-dark-tertiary text-white hover:bg-bambu-dark-tertiary`}`,children:e(`printers.hideOffline`)})]}),Et=(t=!1)=>(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1 ${t?`w-full`:``}`,children:[(0,G.jsx)(iW,{value:m,onChange:rt,fullWidth:t,options:[{value:`name`,label:e(`printers.sort.name`)},{value:`status`,label:e(`printers.sort.status`)},{value:`model`,label:e(`printers.sort.model`)},{value:`location`,label:e(`printers.sort.location`)},{value:`eta`,label:e(`printers.sort.eta`)}]}),(0,G.jsx)(`button`,{onClick:ot,className:`h-8 shrink-0 px-2 rounded-lg border bg-bambu-dark border-bambu-dark-tertiary text-white hover:bg-bambu-dark-tertiary transition-colors flex items-center justify-center`,title:e(g?`printers.sort.descending`:`printers.sort.ascending`),children:g?(0,G.jsx)(Io,{className:`w-4 h-4 text-white`}):(0,G.jsx)(Ao,{className:`w-4 h-4 text-white`})})]}),(0,G.jsxs)(`div`,{className:`flex h-8 items-center bg-bambu-dark rounded-lg border border-bambu-dark-tertiary ${t?`w-full`:``}`,children:[(0,G.jsxs)(`button`,{type:`button`,onClick:()=>{x(`cards`),localStorage.setItem(`printerPageView`,`cards`)},className:`flex h-full items-center gap-1 rounded-l-lg px-2 text-xs font-medium transition-colors ${t?`flex-1 justify-center`:``} ${b===`cards`?`bg-bambu-green text-white`:`text-white hover:bg-bambu-dark-tertiary`}`,title:e(`printers.pageView.cards`),"aria-pressed":b===`cards`,children:[(0,G.jsx)(Gc,{className:`w-3.5 h-3.5`}),t&&(0,G.jsx)(`span`,{children:e(`printers.pageView.cards`)})]}),(0,G.jsxs)(`button`,{type:`button`,onClick:()=>{x(`camwall`),localStorage.setItem(`printerPageView`,`camwall`)},className:`flex h-full items-center gap-1 rounded-r-lg px-2 text-xs font-medium transition-colors ${t?`flex-1 justify-center`:``} ${b===`camwall`?`bg-bambu-green text-white`:`text-white hover:bg-bambu-dark-tertiary`}`,title:e(`printers.pageView.camWall`),"aria-pressed":b===`camwall`,disabled:!ie(`camera:view`),children:[(0,G.jsx)(fl,{className:`w-3.5 h-3.5`}),t&&(0,G.jsx)(`span`,{children:e(`printers.pageView.camWall`)})]})]}),b===`camwall`&&ie(`camera:view`)&&(0,G.jsxs)(Ci,{to:`/camwall`,className:`flex h-8 items-center gap-1 rounded-lg border border-bambu-dark-tertiary bg-bambu-dark px-2 text-xs font-medium text-white transition-colors hover:bg-bambu-dark-tertiary ${t?`w-full justify-center`:``}`,title:e(`printers.pageView.openCamWallPage`),children:[(0,G.jsx)(Qs,{className:`w-3.5 h-3.5`}),t&&(0,G.jsx)(`span`,{children:e(`printers.pageView.openCamWallPage`)})]}),(0,G.jsx)(`div`,{className:`flex h-8 items-center bg-bambu-dark rounded-lg border border-bambu-dark-tertiary ${b===`camwall`?`opacity-40 pointer-events-none`:``} ${t?`w-full`:``}`,children:ct.map((n,r)=>{let i=r+1,a=v===i;return(0,G.jsx)(`button`,{onClick:()=>{A(null),y(i),localStorage.setItem(`printerCardSize`,String(i))},className:`h-full px-2 text-xs font-medium transition-colors ${t?`flex-1`:``} ${r===0?`rounded-l-lg`:``} ${r===ct.length-1?`rounded-r-lg`:``} ${a?`bg-bambu-green text-white`:`text-white hover:bg-bambu-dark-tertiary`}`,title:e(n===`S`?`printers.cardSize.small`:n===`M`?`printers.cardSize.medium`:n===`L`?`printers.cardSize.large`:`printers.cardSize.extraLarge`),children:n},n)})})]}),Dt=(t=!1)=>(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`button`,{onClick:()=>{Ze?$e():Ke(!0)},className:`h-8 px-2 rounded-lg border transition-colors ${t?`w-full justify-center gap-1.5 text-sm font-medium flex items-center`:``} ${Ze?`bg-bambu-green border-bambu-green text-white`:`bg-bambu-dark border-bambu-dark-tertiary text-white hover:bg-bambu-dark-tertiary`}`,title:e(`printers.bulk.select`),disabled:!ie(`printers:control`),children:[(0,G.jsx)(hu,{className:`w-4 h-4`}),t&&(0,G.jsx)(`span`,{children:e(`printers.bulk.select`)})]}),s&&Object.keys(Be).length>0&&(0,G.jsxs)(`div`,{className:`relative ${t?`w-full`:``}`,children:[(0,G.jsxs)(`button`,{onClick:()=>u(!l),className:`h-8 flex items-center gap-1.5 px-2 text-sm rounded-lg border transition-colors ${t?`w-full justify-between bg-bambu-dark border-bambu-dark-tertiary text-white hover:bg-bambu-dark-tertiary hover:text-white`:`bg-bambu-dark border-bambu-dark-tertiary text-white hover:bg-bambu-dark-tertiary`}`,children:[(0,G.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,G.jsx)(Pl,{className:`w-4 h-4`}),e(`printers.powerOn`)]}),(0,G.jsx)(ss,{className:`w-3 h-3 transition-transform ${l?`rotate-180`:``}`})]}),l&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`fixed inset-0 z-10`,onClick:()=>u(!1)}),(0,G.jsxs)(`div`,{className:`absolute right-0 mt-2 w-56 bg-white dark:bg-bambu-dark-secondary border border-gray-200 dark:border-bambu-dark-tertiary rounded-lg shadow-lg z-20 py-1`,children:[(0,G.jsx)(`div`,{className:`px-3 py-2 text-xs text-gray-500 dark:text-bambu-gray border-b border-gray-200 dark:border-bambu-dark-tertiary`,children:e(`printers.offlinePrintersWithPlugs`)}),ce?.filter(e=>Be[e.id]).map(e=>(0,G.jsx)(Sje,{printer:e,plug:Be[e.id],onPowerOn:e=>{p(e),He.mutate(e)},isPowering:d===Be[e.id]?.id},e.id)),ce?.filter(e=>Be[e.id]).length===0&&(0,G.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:`No printers with smart plugs`})]})]})]}),(0,G.jsxs)(Q,{onClick:()=>o(!0),disabled:!ie(`printers:create`),title:ie(`printers:create`)?void 0:e(`printers.permission.noAdd`),className:`!h-8 !min-h-8 px-2 py-0 ${t?`w-full`:``}`,children:[(0,G.jsx)(Ml,{className:`w-4 h-4`}),e(`printers.addPrinter`)]})]});return(0,G.jsxs)(`div`,{className:`p-4 md:p-8`,children:[(0,G.jsxs)(`div`,{className:`space-y-3 mb-6`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,G.jsx)(Fl,{className:`w-7 h-7 text-bambu-green`}),e(`printers.title`)]}),(0,G.jsx)(uje,{printers:ce})]}),(0,G.jsxs)(`div`,{ref:vt,className:`relative flex items-center gap-2`,children:[ce&&ce.length>0&&(0,G.jsxs)(`div`,{className:`relative min-w-0 flex-1`,children:[(0,G.jsx)(Yl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50`}),(0,G.jsx)(`input`,{type:`search`,name:`printer-search`,autoComplete:`off`,"data-1p-ignore":!0,"data-lpignore":`true`,value:P,onChange:e=>F(e.target.value),placeholder:e(`printers.search`),"aria-label":e(`printers.search`),className:`w-full h-8 pl-9 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`}),P&&(0,G.jsx)(`button`,{type:`button`,"aria-label":e(`common.clear`),onClick:()=>F(``),className:`absolute right-3 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white`,children:(0,G.jsx)(nd,{className:`w-4 h-4`})})]}),(0,G.jsxs)(`div`,{ref:yt,"aria-hidden":xt,inert:xt,className:`${xt?`absolute -left-[9999px] top-0 flex w-max pointer-events-none opacity-0`:`flex`} ml-auto items-center justify-end gap-2 flex-nowrap [&>*]:shrink-0`,children:[(0,G.jsx)(`div`,{className:`h-6 w-px bg-bambu-dark-tertiary`}),(0,G.jsx)(`div`,{className:`flex items-center gap-2`,children:Tt()}),(0,G.jsx)(`div`,{className:`h-6 w-px bg-bambu-dark-tertiary`}),(0,G.jsx)(`div`,{className:`flex items-center gap-2`,children:Et()}),(0,G.jsx)(`div`,{className:`h-6 w-px bg-bambu-dark-tertiary`}),(0,G.jsx)(`div`,{className:`flex items-center gap-2`,children:Dt()})]}),xt&&(0,G.jsxs)(`div`,{className:`ml-auto flex items-center justify-end gap-1`,children:[(0,G.jsx)(aW,{label:e(`printers.toolbar.filters`,`Filters`),icon:(0,G.jsx)(yc,{className:`w-4 h-4`}),children:(0,G.jsx)(`div`,{className:`flex w-48 flex-col gap-2`,children:Tt(!0)})}),(0,G.jsx)(aW,{label:e(`printers.toolbar.view`,`View`),icon:(0,G.jsx)(lu,{className:`w-4 h-4`}),children:(0,G.jsx)(`div`,{className:`flex w-48 flex-col gap-2`,children:Et(!0)})}),(0,G.jsx)(aW,{label:e(`printers.toolbar.actions`,`Actions`),icon:(0,G.jsx)(Ys,{className:`w-4 h-4`}),children:(0,G.jsx)(`div`,{className:`flex w-48 flex-col gap-2`,children:Dt(!0)})})]})]})]}),le?(0,G.jsx)(`div`,{className:`text-center py-12 text-bambu-gray`,children:e(`common.loading`)}):ce?.length===0?(0,G.jsx)(Ud,{children:(0,G.jsxs)(Gd,{className:`text-center py-12`,children:[(0,G.jsx)(`p`,{className:`text-bambu-gray mb-4`,children:e(`printers.noPrintersConfigured`)}),(0,G.jsxs)(Q,{onClick:()=>o(!0),disabled:!ie(`printers:create`),title:ie(`printers:create`)?void 0:e(`printers.permission.noAdd`),children:[(0,G.jsx)(Ml,{className:`w-4 h-4`}),e(`printers.addPrinter`)]})]})}):dt.length===0&&(P.trim()||I!==`all`||R!==`all`)?(0,G.jsx)(Ud,{children:(0,G.jsx)(Gd,{className:`text-center py-12`,children:(0,G.jsx)(`p`,{className:`text-bambu-gray`,children:e(`printers.noSearchResults`)})})}):b===`camwall`?(0,G.jsx)(qT,{printers:dt,maxLive:S,snapshotIntervalSec:w,onTileClick:(e,t)=>{_e===`embedded`?H(n=>new Map(n).set(e,{id:e,name:t})):ch(e)},statusMode:E,onChangeMaxLive:e=>{C(e),localStorage.setItem(`camWallMaxLive`,String(e))},onChangeSnapshotIntervalSec:e=>{T(e),localStorage.setItem(`camWallSnapshotSec`,String(e))},onChangeStatusMode:e=>{D(e),localStorage.setItem(`camWallStatusMode`,e)}}):_t?(0,G.jsx)(`div`,{className:`space-y-6`,children:(()=>{let e=m===`status`?fje.filter(e=>_t[e]?.length>0):Object.keys(_t);return g?e:[...e].reverse()})().map(t=>{let n=_t[t],r=`${m}:${t}`,i=!ee[r],a=m===`status`&&cW[t]?.dot||`bg-bambu-green`,o=m===`status`?e(cW[t]?.labelKey||t):t;return(0,G.jsx)(Vm,{open:i,onToggle:()=>gt(r),summaryClassName:`py-1`,summary:(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`w-2 h-2 rounded-full ${a}`}),o,(0,G.jsxs)(`span`,{className:`text-sm font-normal text-bambu-gray`,children:[`(`,n.length,`)`]}),Ze&&(0,G.jsx)(`button`,{onClick:e=>{e.stopPropagation(),m===`location`?mt(t===`Ungrouped`?``:t):m===`status`?pt(t):m===`model`&&ht(t)},className:`text-xs text-bambu-green hover:text-bambu-green-light transition-colors ml-1`,children:e(`printers.bulk.selectAll`)})]}),children:(0,G.jsx)(`div`,{className:`grid gap-4 ${v>=3?`gap-6`:``} ${st()}`,children:n.map(e=>(0,G.jsx)(pW,{printer:e,hideIfDisconnected:s,maintenanceInfo:ze[e.id],viewMode:O,cardSize:v,amsThresholds:ue?{humidityGood:Number(ue.ams_humidity_good)||40,humidityFair:Number(ue.ams_humidity_fair)||60,tempGood:Number(ue.ams_temp_good)||28,tempFair:Number(ue.ams_temp_fair)||35}:void 0,spoolmanEnabled:we,hasUnlinkedSpools:Oe,linkedSpools:Ae,spoolmanUrl:Ce?.url,spoolmanSyncMode:Ee,onGetAssignment:Re,onUnassignSpool:(e,t,n)=>Me.mutate({printerId:e,amsId:t,trayId:n}),spoolmanSpools:Ne,spoolmanSlotAssignments:Fe,spoolmanLoading:Pe||Ie,onUnassignSpoolmanSpool:e=>Le.mutate(e),timeFormat:ue?.time_format||`system`,cameraViewMode:_e,onOpenEmbeddedCamera:(e,t)=>H(n=>new Map(n).set(e,{id:e,name:t})),onSelectCameraViewMode:ve,checkPrinterFirmware:de,dryingPresets:ge,nozzleTempPresets:fe,bedTempPresets:pe,chamberTempPresets:me,fanSpeedPresets:he,requirePlateClear:ue?.require_plate_clear===!0,selectionMode:Ze,isSelected:Ue.has(e.id),onToggleSelect:Qe,onOpenCompactCard:M,aiDetectionEnabled:Se(e.id),aiDetection:xe?.enabled?xe.per_printer[String(e.id)]:void 0,aiLastError:xe?.last_error??null},e.id))})},t)})}):(0,G.jsx)(`div`,{className:`grid gap-4 ${v>=3?`gap-6`:``} ${st()}`,children:dt.map(e=>(0,G.jsx)(pW,{printer:e,hideIfDisconnected:s,maintenanceInfo:ze[e.id],viewMode:O,cardSize:v,spoolmanEnabled:we,hasUnlinkedSpools:Oe,linkedSpools:Ae,spoolmanUrl:Ce?.url,spoolmanSyncMode:Ee,onGetAssignment:Re,onUnassignSpool:(e,t,n)=>Me.mutate({printerId:e,amsId:t,trayId:n}),spoolmanSpools:Ne,spoolmanSlotAssignments:Fe,spoolmanLoading:Pe||Ie,onUnassignSpoolmanSpool:e=>Le.mutate(e),amsThresholds:ue?{humidityGood:Number(ue.ams_humidity_good)||40,humidityFair:Number(ue.ams_humidity_fair)||60,tempGood:Number(ue.ams_temp_good)||28,tempFair:Number(ue.ams_temp_fair)||35}:void 0,timeFormat:ue?.time_format||`system`,cameraViewMode:_e,onOpenEmbeddedCamera:(e,t)=>H(n=>new Map(n).set(e,{id:e,name:t})),onSelectCameraViewMode:ve,checkPrinterFirmware:de,dryingPresets:ge,nozzleTempPresets:fe,bedTempPresets:pe,chamberTempPresets:me,fanSpeedPresets:he,requirePlateClear:ue?.require_plate_clear===!0,selectionMode:Ze,isSelected:Ue.has(e.id),onToggleSelect:Qe,onOpenCompactCard:M,aiDetectionEnabled:Se(e.id),aiDetection:xe?.enabled?xe.per_printer[String(e.id)]:void 0,aiLastError:xe?.last_error??null},e.id))}),v===2&&k!=null&&(0,G.jsxs)(`button`,{type:`button`,onClick:N,className:`fixed bottom-5 left-1/2 z-40 inline-flex -translate-x-1/2 items-center gap-2 rounded-full border px-4 py-2 text-sm font-medium shadow-xl transition-colors ${i}`,title:e(`common.back`,`Back`),children:[(0,G.jsx)(jo,{className:`w-4 h-4`}),e(`common.back`,`Back`)]}),a&&(0,G.jsx)(vje,{onClose:()=>o(!1),onAdd:e=>Ve.mutate(e),existingSerials:ce?.map(e=>e.serial_number)||[]}),Ze&&ce&&(0,G.jsx)(Vte,{selectedIds:Ue,printers:ce,onClose:$e,onSelectAll:ft,onSelectByLocation:mt,onSelectByState:pt,onAction:tt,actionPending:Ye}),qe===`stop`&&(0,G.jsx)(uf,{title:e(`printers.bulk.confirm.stopTitle`,{count:Ue.size}),message:e(`printers.bulk.confirm.stopMessage`,{count:Ue.size}),confirmText:e(`printers.bulk.confirm.stopButton`),variant:`danger`,isLoading:Ye,onConfirm:()=>et(`stop`),onCancel:()=>Je(null)}),qe===`pause`&&(0,G.jsx)(uf,{title:e(`printers.bulk.confirm.pauseTitle`,{count:Ue.size}),message:e(`printers.bulk.confirm.pauseMessage`,{count:Ue.size}),confirmText:e(`printers.bulk.confirm.pauseButton`),isLoading:Ye,onConfirm:()=>et(`pause`),onCancel:()=>Je(null)}),qe===`clearPlate`&&(0,G.jsx)(uf,{title:e(`printers.bulk.confirm.clearPlateTitle`,{count:Ue.size}),message:e(`printers.bulk.confirm.clearPlateMessage`,{count:Ue.size}),confirmText:e(`printers.bulk.confirm.clearPlateButton`),isLoading:Ye,onConfirm:()=>et(`clearPlate`),onCancel:()=>Je(null)}),Array.from(se.values()).map((e,t)=>(0,G.jsx)(Ole,{printerId:e.id,printerName:e.name,viewerIndex:t,onClose:()=>H(t=>{let n=new Map(t);return n.delete(e.id),n})},e.id))]})}function wje({title:e,message:t,subtitle:n,closeText:r,variant:i=`error`,onClose:a}){let{t:o}=U(),s=r??o(`common.close`);return(0,f.useEffect)(()=>{let e=e=>{e.key===`Escape`&&a()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[a]),(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center p-4 z-[120]`,onClick:a,children:(0,G.jsx)(Ud,{className:`w-full max-w-md`,onClick:e=>e.stopPropagation(),children:(0,G.jsxs)(Gd,{className:`p-6`,children:[(0,G.jsxs)(`div`,{className:`flex items-start gap-4`,children:[(0,G.jsx)(`div`,{className:`p-2 rounded-full bg-bambu-dark ${i===`warning`?`text-yellow-600 dark:text-yellow-400`:`text-red-600 dark:text-red-400`}`,children:(0,G.jsx)(Lu,{className:`w-6 h-6`})}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`h3`,{className:`text-lg font-semibold text-white mb-1`,children:e}),n&&(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2 truncate`,children:n}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-sm whitespace-pre-line break-words`,children:t})]})]}),(0,G.jsx)(`div`,{className:`flex mt-6`,children:(0,G.jsx)(Q,{onClick:a,className:`flex-1`,children:s})})]})})})}var mW=(0,f.createContext)(null),Tje=1500,Eje=1e3,hW=e=>`slice-job-${e}`;function gW(e){try{return decodeURIComponent(e)}catch{return e}}function Dje(e){let t=Math.max(0,Math.floor(e));if(t<60)return`${t}s`;let n=Math.floor(t/60),r=t%60;return n<60?`${n}m ${r}s`:`${Math.floor(n/60)}h ${n%60}m`}function Oje({children:e}){let{t}=U(),{showToast:n,showPersistentToast:r,dismissToast:i}=Zd(),a=no(),[o,s]=(0,f.useState)([]),[c,l]=(0,f.useState)(null),u=(0,f.useRef)([]);u.current=o;let d=(0,f.useRef)(new Map),p=(0,f.useRef)(new Map),m=(0,f.useRef)(new Map),h=(0,f.useRef)(new Set),g=(0,f.useCallback)(e=>{let n=d.current.get(e.id);if(n==null)return;let i=(Date.now()-n)/1e3,a=p.current.get(e.id)??`pending`,o=Dje(i),s=m.current.get(e.id)??null,c=s&&s.stage&&s.total_percent>0;if(a===`running`&&c){let n=gW(e.sourceName),i=s.stage,a=Math.min(100,Math.max(0,Math.round(s.total_percent))),c=typeof s.multi_plate_index==`number`&&typeof s.multi_plate_count==`number`&&s.multi_plate_count>1?t(`slice.runningWithProgressMultiPlate`,`Plate {{plateIndex}} of {{plateCount}} • {{name}} — {{stage}} ({{percent}}%) — {{elapsed}}`,{plateIndex:s.multi_plate_index,plateCount:s.multi_plate_count,name:n,stage:i,percent:a,elapsed:o}):t(`slice.runningWithProgress`,`{{name}} — {{stage}} ({{percent}}%) — {{elapsed}}`,{name:n,stage:i,percent:a,elapsed:o});r(hW(e.id),c,`loading`);return}let l=a===`pending`?`slice.queuedToast`:`slice.runningToast`,u=a===`pending`?`Queued: {{name}} — {{elapsed}}`:`Slicing {{name}} — {{elapsed}}`;r(hW(e.id),t(l,u,{name:gW(e.sourceName),elapsed:o}),`loading`)},[r,t]),_=(0,f.useCallback)((e,t,n)=>{s(r=>r.some(t=>t.id===e)?r:[...r,{id:e,kind:t,sourceName:n}]),h.current.delete(e),d.current.set(e,Date.now()),p.current.set(e,`pending`),m.current.set(e,null),g({id:e,kind:t,sourceName:n})},[g]),v=(0,f.useCallback)((e,r)=>{h.current.has(e.id)||(h.current.add(e.id),s(t=>t.filter(t=>t.id!==e.id)),d.current.delete(e.id),p.current.delete(e.id),m.current.delete(e.id),i(hW(e.id)),r.status===`completed`?(n(t(`slice.completedToast`,`Sliced {{name}}`,{name:gW(e.sourceName)}),`success`),r.result&&`external_write_fallback`in r.result&&r.result.external_write_fallback&&n(t(`slice.externalWriteFallbackToast`,`Saved to the internal library: the external folder could not be written to`),`warning`)):r.status===`failed`&&l({name:gW(e.sourceName),detail:r.error_detail||t(`slice.failed`)}),a.invalidateQueries({queryKey:[`library-files`]}),a.invalidateQueries({queryKey:[`archives`]}))},[i,a,n,t]);return(0,f.useEffect)(()=>{if(o.length===0)return;let e=!1,t=!1,n=setInterval(async()=>{if(!(e||t)){t=!0;try{let t=[...u.current];for(let n of t)try{let t=await Z.getSliceJob(n.id);if(e)return;p.current.set(n.id,t.status),t.progress&&m.current.set(n.id,t.progress),(t.status===`completed`||t.status===`failed`)&&v(n,t)}catch{}}finally{t=!1}}},Tje);return()=>{e=!0,clearInterval(n)}},[o.length,v]),(0,f.useEffect)(()=>{if(o.length===0)return;let e=setInterval(()=>{for(let e of u.current)g(e)},Eje);return()=>clearInterval(e)},[o.length,g]),(0,G.jsxs)(mW.Provider,{value:{trackJob:_,activeJobs:o},children:[e,c&&(0,G.jsx)(wje,{title:t(`slice.failedTitle`),subtitle:c.name,message:c.detail,onClose:()=>l(null)})]})}function _W(){let e=(0,f.useContext)(mW);if(!e)throw Error(`useSliceJobTracker must be used inside SliceJobTrackerProvider`);return e}var vW=1024;function kje(){let[e,t]=(0,f.useState)(()=>typeof window<`u`?window.innerWidth>=vW:!1);return(0,f.useEffect)(()=>{let e=window.matchMedia(`(min-width: ${vW}px)`),n=e=>{t(e.matches)};return t(e.matches),e.addEventListener(`change`,n),()=>e.removeEventListener(`change`,n)},[]),e}function yW({plates:e,onSelect:t,onClose:n}){let{t:r}=U();return(0,G.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-4`,onClick:n,children:(0,G.jsxs)(`div`,{className:`w-full max-w-3xl max-h-[85vh] flex flex-col rounded-lg bg-bambu-dark-secondary border border-bambu-dark-tertiary/60`,onClick:e=>e.stopPropagation(),children:[(0,G.jsxs)(`div`,{className:`flex-shrink-0 flex items-start justify-between gap-3 px-4 pt-4 pb-3 border-b border-bambu-dark-tertiary/40`,children:[(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsx)(`h3`,{className:`text-white font-medium`,children:r(`archives.platePicker.title`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:r(`archives.platePicker.hint`)})]}),(0,G.jsx)(`button`,{onClick:n,className:`flex-shrink-0 text-bambu-gray hover:text-white transition-colors`,"aria-label":r(`common.close`,`Close`),children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]}),(0,G.jsx)(`div`,{className:`flex-1 overflow-y-auto p-4`,children:(0,G.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-2`,children:e.map(e=>(0,G.jsxs)(`button`,{type:`button`,onClick:()=>t(e.index),className:`flex items-center gap-2 p-2 rounded-lg border border-bambu-dark-tertiary bg-bambu-dark hover:border-bambu-gray transition-colors text-left`,children:[e.has_thumbnail&&e.thumbnail_url!=null?(0,G.jsx)(`img`,{src:vd(e.thumbnail_url),alt:`Plate ${e.index}`,className:`w-12 h-12 rounded object-cover bg-bambu-dark-tertiary flex-shrink-0`}):(0,G.jsx)(`div`,{className:`w-12 h-12 rounded bg-bambu-dark-tertiary flex items-center justify-center flex-shrink-0`,children:(0,G.jsx)(Wc,{className:`w-5 h-5 text-bambu-gray`})}),(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,G.jsx)(`p`,{className:`text-sm text-white font-medium truncate`,children:e.name?`${r(`archives.platePicker.plateLabel`,{index:e.index})} — ${e.name}`:r(`archives.platePicker.plateLabel`,{index:e.index})}),(0,G.jsxs)(`p`,{className:`text-xs text-bambu-gray truncate`,children:[e.objects.length>0?e.objects.slice(0,3).join(`, `)+(e.objects.length>3?`…`:``):e.object_count!=null&&e.object_count>0?r(`archives.platePicker.objectCount`,{count:e.object_count}):`${e.filaments.length} filament${e.filaments.length===1?``:`s`}`,e.print_time_seconds==null?``:` • ${pp(e.print_time_seconds)}`]})]})]},e.index))})})]})})}var bW=e=>typeof e==`object`&&!!e&&`enumKey`in e,xW=`enum:`;function SW(e){if(typeof e==`number`)return e;if(typeof e==`boolean`)return+!!e;if(typeof e!=`string`)return;let t=Number.parseFloat(e);return Number.isFinite(t)?t:void 0}function CW(e){if(typeof e==`boolean`)return e;if(typeof e==`number`)return e!==0;if(e===`1`||e===`true`)return!0;if(e===`0`||e===`false`)return!1}function Aje(e,t){return{get:n=>{let r=e[n];if((r===void 0||r===``)&&(r=t[n]?.default),Array.isArray(r)&&(r=r[0]),typeof r==`boolean`||typeof r==`number`||typeof r==`string`)return r},has:e=>e in t}}var jje=[`->`,`||`,`&&`,`==`,`!=`,`<=`,`>=`,`(`,`)`,`,`,`<`,`>`,`!`];function Mje(e){let t=[],n=0;for(;ne.startsWith(t,n));if(a){t.push({kind:`op`,value:a}),n+=a.length;continue}let o=/^[A-Za-z_][A-Za-z0-9_]*(::[A-Za-z_][A-Za-z0-9_]*)*/.exec(e.slice(n));if(o){t.push({kind:`id`,value:o[0]}),n+=o[0].length;continue}return}return t}var Nje=new Set([`opt_bool`,`opt_int`,`opt_float`,`opt_float_nullable`,`opt_int_nullable`,`opt_bool_nullable`,`opt_enum`,`opt_string`,`option`,`has`]),Pje=class e{tokens=[];pos=0;cfg;locals;schema;resolving;memo;constructor(e,t,n,r,i){this.cfg=e,this.locals=t,this.schema=n,this.resolving=r,this.memo=i}evaluate(e){let t=Mje(e);if(!t||t.length===0)return;this.tokens=t,this.pos=0;let n=this.parseOr();if(this.pos===this.tokens.length)return n}peek(){return this.tokens[this.pos]}eatOp(e){let t=this.peek();return t&&t.kind===`op`&&t.value===e?(this.pos+=1,!0):!1}parseOr(){let e=this.parseAnd();for(;this.eatOp(`||`);){let t=this.parseAnd(),n=CW(e),r=CW(t);e=n===!0||r===!0?!0:n===void 0||r===void 0?void 0:n||r}return e}parseAnd(){let e=this.parseComparison();for(;this.eatOp(`&&`);){let t=this.parseComparison(),n=CW(e),r=CW(t);e=n===!1||r===!1?!1:n===void 0||r===void 0?void 0:n&&r}return e}parseComparison(){let e=this.parseUnary();for(let t of[`==`,`!=`,`<=`,`>=`,`<`,`>`])if(this.eatOp(t))return Fje(e,this.parseUnary(),t,this.schema);return e}parseUnary(){if(this.eatOp(`!`)){let e=CW(this.parseUnary());return e===void 0?void 0:!e}return this.parsePrimary()}parsePrimary(){let e=this.peek();if(!e)return;if(e.kind===`num`||e.kind===`str`)return this.pos+=1,e.value;if(e.kind===`op`&&e.value===`(`){this.pos+=1;let e=this.parseOr();return this.eatOp(`)`)?e:void 0}if(e.kind!==`id`)return;if(this.pos+=1,e.value===`true`)return!0;if(e.value===`false`)return!1;if(e.value===`config`)return this.parseConfigAccess();let t=this.locals[e.value];return t===void 0?`${xW}${e.value}`:this.resolveLocal(e.value,t)}parseConfigAccess(){if(!this.eatOp(`->`))return;let e=this.peek();if(!e||e.kind!==`id`||!Nje.has(e.value))return;if(this.pos+=1,this.eatOp(`<`)){let e=1;for(;e>0;){let t=this.peek();if(!t)return;this.pos+=1,t.kind===`op`&&t.value===`<`&&(e+=1),t.kind===`op`&&t.value===`>`&&--e}}if(!this.eatOp(`(`))return;let t=this.peek();if(!t||t.kind!==`str`)return;this.pos+=1;let n=t.value;for(;this.eatOp(`,`);){let e=0;for(;;){let t=this.peek();if(!t)return;if(t.kind===`op`&&t.value===`(`&&(e+=1),t.kind===`op`&&t.value===`)`){if(e===0)break;--e}if(t.kind===`op`&&t.value===`,`&&e===0)break;this.pos+=1}}if(!this.eatOp(`)`))return;if(this.eatOp(`->`)){let e=this.peek();if(!e||e.kind!==`id`)return;this.pos+=1}if(e.value===`has`)return this.cfg.has(n);let r=this.cfg.get(n);return this.schema[n]?.enum_values?{enumKey:n,value:typeof r==`string`?r:void 0}:r}resolveLocal(t,n){let r=this.memo.get(t);if(r!==void 0||this.memo.has(t))return r;if(this.resolving.has(t))return;this.resolving.add(t);let i=new e(this.cfg,this.locals,this.schema,this.resolving,this.memo).evaluate(n);return this.resolving.delete(t),this.memo.set(t,i),i}};function Fje(e,t,n,r){let i=typeof e==`string`&&e.startsWith(xW)?e:typeof t==`string`&&t.startsWith(xW)?t:void 0;if(i!==void 0){if(n!==`==`&&n!==`!=`)return;let a=i===e?t:e;if(!bW(a))return;let o=r[a.enumKey]?.enum_values;if(!o||a.value===void 0)return;let s=Ije(i.slice(5)).filter(e=>o.includes(e));if(s.length!==1)return;let c=s[0]===a.value;return n===`==`?c:!c}let a=bW(e)?e.value:e,o=bW(t)?t.value:t;if(n===`==`||n===`!=`){if(a===void 0||o===void 0)return;let e=typeof a==`string`||typeof o==`string`?String(a)===String(o):SW(a)===SW(o);return n===`==`?e:!e}let s=SW(a),c=SW(o);if(!(s===void 0||c===void 0)){if(n===`<`)return s`)return s>c;if(n===`>=`)return s>=c}}function Ije(e){let t=e.includes(`::`)?e.slice(e.lastIndexOf(`::`)+2):e,n=[t,/^[a-z]+([A-Z].*)$/.exec(t)?.[1]].filter(e=>!!e),r=new Set;for(let e of n){let t=e.replace(/([a-z0-9])([A-Z])/g,`$1_$2`).toLowerCase();r.add(t),r.add(t.replace(/_/g,` `)),r.add(t.replace(/_/g,``))}return[...r]}function Lje(e,t,n){let r=Aje(e,t),i=new Map,a=new Set;for(let e of n.rules){let o=Rje(e.enable_if);if(o&&CW(new Pje(r,n.locals,t,new Set,i).evaluate(o))===!1)for(let t of e.fields)a.add(t)}return a}function Rje(e){let t=0;for(let n=0;nzje.has(e.type);function wW(e){if(typeof e==`number`)return Number.isFinite(e)?e:void 0;if(typeof e!=`string`)return;let t=Number.parseFloat(e);return Number.isFinite(t)?t:void 0}function Vje(e){let t=e.sidetext;if(!(!t||t.includes(`->`)||t.includes(`::`)))return t}function TW(e,t){let n=t===void 0?e.default:t;return n===void 0?``:Array.isArray(n)?n.map(String).join(`, `):typeof n==`boolean`?n?`1`:`0`:String(n)}function EW(e,t){if(Bje(e))return(Array.isArray(t)?t.map(String):String(t).split(`,`)).map(e=>e.trim()).filter(e=>e!==``);if(e.type===`coBool`)return typeof t==`boolean`?t?`1`:`0`:t===`1`||t===`true`||t===1?`1`:`0`;let n=String(t).trim();return e.type===`coPercent`?n.endsWith(`%`)?n:`${n}%`:n}function Hje(e,t){let n={};for(let[r,i]of Object.entries(e)){let e=t[r];e&&(n[r]=EW(e,i))}return n}function DW(e,t,n){if(t===void 0||t===``)return!1;let r=t=>{let n=EW(e,Array.isArray(t)?t.map(String).join(`, `):t);return Array.isArray(n)?n.join(`, `):n},i=r(t),a=n===void 0?e.default:n;return a===void 0?i!==``:i!==r(a)}var Uje=new Set([`support_filament`,`support_interface_filament`,`outer_wall_filament_id`,`inner_wall_filament_id`,`top_surface_filament_id`,`bottom_surface_filament_id`,`internal_solid_filament_id`,`sparse_infill_filament_id`]),Wje=[`simple`,`advanced`,`expert`],OW={simple:0,advanced:1,expert:2,develop:3};function Gje({values:e,onChange:t,disabled:n=!1,sourceOverrides:r=[],sourceSelected:i,onToggleSource:a,filamentChoices:o,presetValues:s,presetValuesResolved:c=!0,presetValuesReason:l}){let{t:u}=U(),[d,p]=(0,f.useState)(null),[m,h]=(0,f.useState)(`simple`),[g,_]=(0,f.useState)(null),[v,y]=(0,f.useState)(``);(0,f.useEffect)(()=>{let e=!1;return Promise.all([Dt(()=>import(`./process-schema-CzfeynAH.js`),[]),Dt(()=>import(`./process-ui-tree-BWrKRLV6.js`),[]),Dt(()=>import(`./process-toggle-rules-DDBax3G5.js`),[])]).then(([t,n,r])=>{e||p({schema:t.default??t,tree:n.default??n,toggles:r.default??r})}),()=>{e=!0}},[]);let b=(0,f.useMemo)(()=>{let t={...s??{}};for(let e of r)i?.has(e.key)&&(t[e.key]=e.value);for(let[n,r]of Object.entries(e))r!==void 0&&r!==``&&(t[n]=r);return t},[s,r,i,e]),x=(0,f.useMemo)(()=>d?Lje(b,d.schema,d.toggles):new Set,[d,b]),S=(0,f.useMemo)(()=>new Map(r.map(e=>[e.key,e])),[r]),C=(0,f.useMemo)(()=>r.filter(e=>!e.printer_coupled&&!e.preset_defining),[r]),w=(0,f.useMemo)(()=>r.filter(e=>i?.has(e.key)).length,[r,i]),T=(0,f.useMemo)(()=>d?r.filter(e=>!d.schema[e.key]):[],[d,r]),E=e=>{if(!d)return;let n={};for(let[t,r]of Object.entries(e))d.schema[t]&&DW(d.schema[t],r,s?.[t])&&(n[t]=r);t(e,Hje(n,d.schema))},D=(t,n)=>{let r={...e};n===void 0?delete r[t]:r[t]=n,E(r)},O=(0,f.useMemo)(()=>{if(!d)return[];let e=e=>e.toLowerCase().replace(/[_\s]+/g,` `).trim(),t=e(v),n=e=>OW[d.schema[e]?.mode??`expert`]<=OW[m],r=(n,r,i)=>{if(!t)return!0;let a=d.schema[n];return[n,a?.label??``,a?.tooltip??``,r,i].some(n=>e(n).includes(t))};return d.tree.map(e=>({...e,groups:e.groups.map(t=>({...t,options:t.options.filter(i=>n(i)&&r(i,t.group,e.page))})).filter(e=>e.options.length>0)})).filter(e=>e.groups.length>0)},[d,m,v]),k=(0,f.useMemo)(()=>O.length===0||v.trim()?null:O.find(e=>e.page===g)??O[0],[O,g,v]),A=(0,f.useMemo)(()=>d?Object.keys(e).filter(t=>d.schema[t]&&DW(d.schema[t],e[t],s?.[t])).length:0,[d,e,s]);if(!d)return(0,G.jsxs)(`div`,{className:`flex items-center justify-center gap-2 py-8 text-sm text-bambu-gray`,children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),u(`slicerSettings.loading`,`Loading slicer settings...`)]});let j=k?[k]:O;return(0,G.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,G.jsx)(`div`,{className:`flex overflow-hidden rounded border border-bambu-dark-tertiary`,children:Wje.map(e=>(0,G.jsx)(`button`,{type:`button`,onClick:()=>h(e),disabled:n,className:`px-2.5 py-1 text-xs capitalize transition-colors ${m===e?`bg-bambu-green text-white`:`text-bambu-gray hover:text-white`}`,children:u(`slicerSettings.mode.${e}`,e)},e))}),(0,G.jsxs)(`div`,{className:`relative flex-1 min-w-[10rem]`,children:[(0,G.jsx)(Yl,{className:`absolute left-2 top-1/2 -translate-y-1/2 w-3.5 h-3.5 text-bambu-gray`}),(0,G.jsx)(`input`,{type:`search`,value:v,onChange:e=>y(e.target.value),disabled:n,placeholder:u(`slicerSettings.searchPlaceholder`,`Search settings`),className:`w-full rounded border border-bambu-dark-tertiary bg-bambu-dark pl-7 pr-2 py-1 text-xs text-white placeholder:text-bambu-gray/60 focus:border-bambu-green focus:outline-none disabled:opacity-40`})]}),A>0&&(0,G.jsxs)(`button`,{type:`button`,onClick:()=>E({}),disabled:n,className:`flex items-center gap-1 text-xs text-bambu-gray hover:text-white`,children:[(0,G.jsx)(Vl,{className:`w-3 h-3`}),u(`slicerSettings.resetAll`,`Reset {{count}}`,{count:A})]})]}),!c&&(0,G.jsx)(`p`,{className:`rounded border border-amber-300 bg-amber-50 px-2 py-1 text-[0.7rem] text-amber-800 dark:border-amber-700/40 dark:bg-amber-900/20 dark:text-amber-200`,children:l===`sidecar_outdated`?u(`slicerSettings.presetValuesOutdatedSidecar`,`Showing slicer defaults: your slicer sidecar is older than this feature and can't report a preset's values. Update the sidecar image to see them. Anything you don't change still uses the preset.`):l===`not_configured`?u(`slicerSettings.presetValuesNotConfigured`,`Showing slicer defaults: no slicer sidecar is configured, so a preset's values can't be read. Anything you don't change still uses the preset.`):l===`sidecar_unavailable`?u(`slicerSettings.presetValuesSidecarUnavailable`,`Showing slicer defaults: the slicer sidecar did not answer, so a preset's values can't be read. Anything you don't change still uses the preset.`):u(`slicerSettings.presetValuesUnavailable`,`Showing slicer defaults: the picked preset's own values could not be read. Anything you don't change still uses the preset.`)}),r.length>0&&a&&(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 rounded border border-bambu-dark-tertiary px-2 py-1.5 text-[0.7rem] text-bambu-gray`,children:[(0,G.jsx)(`span`,{className:`min-w-0 flex-1`,children:u(`slicerSettings.fromFileSummary`,`The designer changed {{count}} process settings in this file. Only the ones you tick are used.`,{count:r.length})}),(0,G.jsx)(`button`,{type:`button`,disabled:n,onClick:()=>C.forEach(e=>a(e.key,!0)),title:u(`slicerSettings.fromFileUseAllHint`,`Ticks the settings that carry across printers. The ones tuned for the designer's own printer, and the ones that define the preset you picked, stay off.`),className:`shrink-0 rounded border border-bambu-dark-tertiary px-1.5 py-0.5 hover:text-white disabled:opacity-40`,children:u(`slicerSettings.fromFileUseAll`,`Use the designer's settings`)}),w>0&&(0,G.jsx)(`button`,{type:`button`,disabled:n,onClick:()=>r.forEach(e=>a(e.key,!1)),className:`shrink-0 rounded border border-bambu-dark-tertiary px-1.5 py-0.5 hover:text-white disabled:opacity-40`,children:u(`slicerSettings.fromFileClear`,`Clear {{count}}`,{count:w})})]}),!v.trim()&&(0,G.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:O.map(e=>(0,G.jsx)(`button`,{type:`button`,onClick:()=>_(e.page),disabled:n,className:`px-2 py-1 text-xs rounded transition-colors ${k?.page===e.page?`bg-bambu-dark-tertiary text-white`:`text-bambu-gray hover:text-white`}`,children:e.page},e.page))}),j.length===0?(0,G.jsx)(`p`,{className:`py-6 text-center text-xs text-bambu-gray`,children:u(`slicerSettings.noMatches`,`No settings match this search.`)}):(0,G.jsxs)(`div`,{className:`flex flex-col gap-4 max-h-[22rem] lg:max-h-[58vh] overflow-y-auto pr-1`,children:[j.map(t=>(0,G.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[v.trim()&&(0,G.jsx)(`p`,{className:`text-[0.7rem] uppercase tracking-wide text-bambu-gray/70`,children:t.page}),t.groups.map(r=>(0,G.jsxs)(`fieldset`,{className:`flex flex-col gap-1.5`,children:[(0,G.jsx)(`legend`,{className:`mb-1 text-xs font-medium text-white`,children:r.group}),r.options.map(t=>(0,G.jsx)(Kje,{optionKey:t,option:d.schema[t],value:e[t],onChange:e=>D(t,e),disabled:n||x.has(t),disabledBySlicer:x.has(t),formDisabled:n,source:S.get(t),sourceOn:i?.has(t)??!1,onToggleSource:a,filamentChoices:Uje.has(t)?o:void 0,presetValue:s?.[t]},t))]},`${t.page}:${r.group}`))]},t.page)),T.length>0&&!v.trim()&&(0,G.jsxs)(`fieldset`,{className:`flex flex-col gap-1.5`,children:[(0,G.jsx)(`legend`,{className:`mb-1 text-xs font-medium text-white`,children:u(`slicerSettings.otherFromFile`,`Other settings from this file`)}),T.map(e=>(0,G.jsxs)(`label`,{className:`flex items-center gap-2 text-xs cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:i?.has(e.key)??!1,disabled:n||!a,onChange:t=>a?.(e.key,t.target.checked),className:`shrink-0 cursor-pointer disabled:opacity-40`}),(0,G.jsxs)(`span`,{className:`min-w-0 flex-1 truncate`,children:[(0,G.jsx)(`span`,{className:`font-mono text-bambu-gray`,children:e.key}),(0,G.jsx)(`span`,{className:`ml-1.5 text-white`,children:kW(e.value)})]}),(e.printer_coupled||e.preset_defining)&&(0,G.jsx)(`span`,{className:`shrink-0 rounded bg-amber-100 px-1 py-0.5 text-[10px] text-amber-700 dark:bg-amber-500/20 dark:text-amber-400`,children:e.printer_coupled?u(`slicerSettings.fromFilePrinterCoupled`,`designer's printer`):u(`slicerSettings.fromFileOverridesPreset`,`overrides preset`)})]},e.key))]})]})]})}function Kje({optionKey:e,option:t,value:n,onChange:r,disabled:i,disabledBySlicer:a,formDisabled:o,source:s,sourceOn:c=!1,onToggleSource:l,filamentChoices:u,presetValue:d}){let{t:f}=U(),p=DW(t,n,d),m=Vje(t),h=n===void 0?c&&s?kW(s.value):TW(t,d):String(n);return(0,G.jsxs)(`div`,{className:`flex items-center gap-2 group`,title:t.tooltip,children:[(0,G.jsxs)(`label`,{htmlFor:`slicer-opt-${e}`,className:`flex min-w-0 flex-1 items-center gap-1 text-xs ${a?`text-bambu-gray/40`:`text-bambu-gray`}`,children:[(0,G.jsx)(`span`,{className:`truncate`,title:t.label||e,children:t.label||e}),p&&(0,G.jsx)(`span`,{className:`shrink-0 text-bambu-green`,"aria-hidden":`true`,children:`•`}),s&&(0,G.jsx)(`span`,{className:`shrink-0 rounded px-1 py-0.5 text-[10px] ${s.printer_coupled||s.preset_defining?`bg-amber-100 text-amber-700 dark:bg-amber-500/20 dark:text-amber-400`:`bg-bambu-green/15 text-bambu-green`}`,title:s.printer_coupled?f(`slicerSettings.fromFilePrinterCoupledHint`,`Tuned for the printer this file was designed for -- may be wrong or out of range on yours.`):s.preset_defining?f(`slicerSettings.fromFileOverridesPresetHint`,`The file sets this to {{value}} where the preset you picked uses {{preset}}. Tick it only if the file should win.`,{value:kW(s.value),preset:TW(t,d)}):f(`slicerSettings.fromFileHint`,`The designer changed this in the source file. Its value is {{value}}.`,{value:kW(s.value)}),children:s.printer_coupled?f(`slicerSettings.fromFilePrinterCoupled`,`designer's printer`):s.preset_defining?f(`slicerSettings.fromFileOverridesPreset`,`overrides preset`):f(`slicerSettings.fromFile`,`from file`)})]}),(0,G.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1.5`,children:[(0,G.jsx)(`span`,{className:`flex w-3 shrink-0 justify-center`,children:s&&l&&(0,G.jsx)(`input`,{type:`checkbox`,checked:c,disabled:o,onChange:t=>l(e,t.target.checked),"aria-label":f(`slicerSettings.useFromFile`,`Use the source file's value for {{option}}`,{option:t.label||e}),title:f(`slicerSettings.useFromFile`,`Use the source file's value for {{option}}`,{option:t.label||e}),className:`w-3 h-3 cursor-pointer disabled:opacity-40`})}),(0,G.jsx)(`div`,{className:`w-40`,children:(0,G.jsx)(qje,{id:`slicer-opt-${e}`,option:t,current:h,onChange:r,disabled:i,filamentChoices:u})}),(0,G.jsx)(`span`,{className:`w-16 shrink-0 whitespace-nowrap text-[0.65rem] text-bambu-gray/60`,children:m??``}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>r(void 0),disabled:i||!p,"aria-label":f(`slicerSettings.resetOption`,`Reset to default`),className:`p-0.5 transition-opacity ${p?`text-bambu-gray hover:text-white`:`opacity-0 pointer-events-none`}`,children:(0,G.jsx)(Vl,{className:`w-3 h-3`})})]})]})}function kW(e){return Array.isArray(e)?e.map(e=>String(e)).join(`, `):e==null?``:String(e)}function qje({id:e,option:t,current:n,onChange:r,disabled:i,filamentChoices:a}){let{t:o}=U(),s=`w-full rounded border border-bambu-dark-tertiary bg-bambu-dark px-1.5 py-0.5 text-xs text-white focus:border-bambu-green focus:outline-none disabled:opacity-40`;if(a&&a.length>0){let t=a.find(e=>String(e.index)===n);return(0,G.jsxs)(`div`,{className:`relative w-full`,children:[(0,G.jsxs)(`select`,{id:e,value:n,onChange:e=>r(e.target.value),disabled:i,className:`${s} w-full cursor-pointer appearance-none pr-5`,title:t?.label,children:[(0,G.jsx)(`option`,{value:`0`,children:o(`slicerSettings.filamentDefault`,`Default`)}),a.map(e=>(0,G.jsxs)(`option`,{value:String(e.index),children:[e.index,`: `,e.label]},e.index))]}),(0,G.jsx)(ss,{className:`pointer-events-none absolute right-1.5 top-1/2 h-3 w-3 -translate-y-1/2 text-bambu-gray`})]})}return t.type===`coBool`?(0,G.jsx)(`input`,{id:e,type:`checkbox`,checked:n===`1`||n===`true`,onChange:e=>r(e.target.checked),disabled:i,className:`w-3.5 h-3.5 cursor-pointer disabled:opacity-40`}):t.type===`coEnum`&&t.enum_values?(0,G.jsxs)(`div`,{className:`relative w-full`,children:[(0,G.jsx)(`select`,{id:e,value:n,onChange:e=>r(e.target.value),disabled:i,className:`${s} w-full cursor-pointer appearance-none pr-5`,children:t.enum_values.map((e,n)=>(0,G.jsx)(`option`,{value:e,children:t.enum_labels?.[n]??e},e))}),(0,G.jsx)(ss,{className:`pointer-events-none absolute right-1.5 top-1/2 h-3 w-3 -translate-y-1/2 text-bambu-gray`})]}):t.type===`coInt`||t.type===`coFloat`||t.type===`coPercent`?(0,G.jsx)(`input`,{id:e,type:`number`,value:n.replace(`%`,``),min:wW(t.min),max:wW(t.max),step:t.type===`coInt`?1:`any`,onChange:e=>r(e.target.value),disabled:i,className:s}):(0,G.jsx)(`input`,{id:e,type:`text`,value:n,onChange:e=>r(e.target.value),disabled:i,className:s})}var AW=[`local`,`orca_cloud`,`cloud`,`standard`],Jje={local:1.75,orca_cloud:1.5,cloud:1,standard:.5};function jW(e,t){for(let n of AW){let r=e[n][t];if(r.length>0)return{source:r[0].source,id:r[0].id}}return null}function MW(e,t,n){return t?e[t.source][n].find(e=>e.id===t.id)??null:null}function NW(e,t,n){if(!n)return null;for(let r of AW){let i=e[r][t].find(e=>e.name===n);if(i)return{source:i.source,id:i.id}}return null}function Yje(e,t,n,r){let i=NW(e,`process`,r);if(i){let r=MW(e,i,`process`);if(r&&iU(r,`process`,t,n)!==`mismatch`)return i}for(let r of[`match`,`unknown`])for(let i of AW){let a=Qje(e[i].process.filter(e=>iU(e,`process`,t,n)===r));if(a)return{source:a.source,id:a.id}}return jW(e,`process`)}var Xje=.2,Zje=/^\s*([\d.]+)\s*mm\b/i;function Qje(e){let t=null,n=1/0,r=-1/0;for(let i of e){let e=Zje.exec(i.name),a=e?Number.parseFloat(e[1]):NaN,o=Number.isFinite(a)&&a>0,s=o?Math.abs(a-Xje):1/0;(t==null||sr)&&(t=i,n=s,r=o?a:-1/0)}return t}function PW(e,t){let n=t.trim().toUpperCase(),r=(e.filament_type??``).trim().toUpperCase();return!!n&&!!r&&n!==r}function $je(e,t,n,r){let i=t.type.trim().toUpperCase(),a=yp(t.color),o=null,s=null,c=null;for(let l of AW)for(let u of e[l].filament){let e=0,d=(u.filament_type??``).trim().toUpperCase(),f=yp(u.filament_colour??``);i&&d&&i===d&&(e+=10),a&&f&&(f===a?e+=5:Op(u.filament_colour??``,t.color)&&(e+=2)),e+=Jje[l];let p={source:u.source,id:u.id};PW(u,i)?(c==null||e>c.score)&&(c={ref:p,score:e}):iU(u,`filament`,n,r)===`mismatch`?(s==null||e>s.score)&&(s={ref:p,score:e}):(o==null||e>o.score)&&(o={ref:p,score:e})}return o==null?s==null?c==null?jW(e,`filament`):c.ref:s.ref:o.ref}function FW(e){return e?`${e.source}:${e.id}`:``}function eMe(e){if(!e)return null;let t=e.indexOf(`:`);if(t<0)return null;let n=e.slice(0,t),r=e.slice(t+1);return n!==`orca_cloud`&&n!==`cloud`&&n!==`local`&&n!==`standard`?null:{source:n,id:r}}function tMe({requestId:e,sourceName:t}){let{t:n}=U(),{showPersistentToast:r,dismissToast:i}=Zd(),[a,o]=(0,f.useState)(0),[s,c]=(0,f.useState)(null),l=t;try{l=decodeURIComponent(t)}catch{}(0,f.useEffect)(()=>{let e=Date.now(),t=setInterval(()=>o(Math.floor((Date.now()-e)/1e3)),1e3);return()=>clearInterval(t)},[]),(0,f.useEffect)(()=>{let t=!1,n=setInterval(async()=>{if(t)return;let n=await Z.getPreviewSliceProgress(e);!t&&n&&c(n)},1e3);return()=>{t=!0,clearInterval(n)}},[e]);let u=`slice-preview-${e}`;(0,f.useEffect)(()=>{let e=s&&s.stage&&s.total_percent>0,t=nMe(a);return e?r(u,n(`slice.previewWithProgress`,`Analyzing {{name}} — {{stage}} ({{percent}}%) — {{elapsed}}`,{name:l,stage:s.stage,percent:Math.min(100,Math.max(0,Math.round(s.total_percent))),elapsed:t}),`loading`):r(u,n(`slice.previewToast`,{name:l,elapsed:t}),`loading`),()=>{i(u)}},[a,s,l,r,i,n,u]);let d=s?.stage,p=s?.total_percent,m=d&&typeof p==`number`&&p>0?`${d} (${Math.min(100,Math.max(0,Math.round(p)))}%)`:n(`slice.analyzingPlateFilaments`);return(0,G.jsxs)(`div`,{className:`flex flex-col gap-1 text-bambu-gray text-sm py-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),m,(0,G.jsxs)(`span`,{className:`text-xs tabular-nums`,children:[a,`s`]})]}),a>=5&&(0,G.jsx)(`div`,{className:`text-xs text-bambu-gray/70 pl-6`,children:n(`slice.analyzingPlateFilamentsHint`,`Running a preview slice to discover which AMS slots this plate uses. Cached after — re-opening is instant.`)})]})}function nMe(e){let t=Math.max(0,Math.floor(e));if(t<60)return`${t}s`;let n=Math.floor(t/60),r=t%60;return n<60?`${n}m ${r}s`:`${Math.floor(n/60)}h ${n%60}m`}var rMe=`#00AE42`;function IW(e){let t=(e||``).trim();return/^#[0-9a-fA-F]{6}([0-9a-fA-F]{2})?$/.test(t)?t.slice(0,7).toUpperCase():rMe}function LW({source:e,onClose:t,defaultAutoArrange:n=!1}){let{t:r}=U(),{trackJob:i}=_W(),a=no(),[o,s]=(0,f.useState)(null),[c,l]=(0,f.useState)(null),[u,d]=(0,f.useState)([]),p=(0,f.useRef)(new Set),[m,h]=(0,f.useState)([]),[g,_]=(0,f.useState)(null),[v,y]=(0,f.useState)(null),[b,x]=(0,f.useState)(!1),[S,C]=(0,f.useState)(null),[w,T]=(0,f.useState)(!1),[E,D]=(0,f.useState)(!1),[O,k]=(0,f.useState)(n),[A,j]=(0,f.useState)(new Set),[M,N]=(0,f.useState)({}),[P,F]=(0,f.useState)({}),[I,L]=(0,f.useState)(!1),R=kje(),z=R||I,B=K({queryKey:[`slicer-pipelines`],queryFn:()=>Z.listSlicerPipelines(),staleTime:6e4}),[V,ee]=(0,f.useState)(!1),[te,ne]=(0,f.useState)(``),{showToast:re}=Zd(),ie=q({mutationFn:e=>Z.createSlicerPipeline(e),onSuccess:()=>{a.invalidateQueries({queryKey:[`slicer-pipelines`]}),re(r(`slice.pipelines.toast.saved`,`Pipeline saved`),`success`),ee(!1),ne(``)},onError:e=>{re(e.message||r(`slice.pipelines.toast.saveFailed`,`Save failed`),`error`)}}),ae=K({queryKey:[`slicePlates`,e.kind,e.id],queryFn:async()=>e.kind===`libraryFile`?Z.getLibraryFilePlates(e.id):Z.getArchivePlates(e.id),staleTime:6e4}),oe=!!ae.data?.is_multi_plate&&(ae.data?.plates?.length??0)>1,se=oe&&v==null,H=v??1,ce=(0,f.useMemo)(()=>{let t=typeof crypto<`u`&&`randomUUID`in crypto?crypto.randomUUID():`${Date.now()}-${Math.random().toString(36).slice(2)}`;return`${e.kind}-${e.id}-p${H}-${t}`},[e.kind,e.id,H]),le=K({queryKey:[`sliceFilamentReqs`,e.kind,e.id,H],queryFn:async()=>e.kind===`libraryFile`?Z.getLibraryFileFilamentRequirements(e.id,H,ce,!0):Z.getArchiveFilamentRequirements(e.id,H,ce,!0),enabled:!se,staleTime:6e4}),ue=(0,f.useMemo)(()=>{let e=le.data?.filaments??[],t=e.length>0?e:[{slot_id:1,type:``,color:``,used_grams:0,used_meters:0}];return b?t.map(e=>({...e,used_in_plate:!0})):t},[b,le.data]),de=K({queryKey:[`slicerPresets`],queryFn:()=>Z.getSlicerPresets(),staleTime:6e4,enabled:!ae.isLoading&&!se}),[fe,pe]=(0,f.useState)(!1),me=async()=>{if(!fe){pe(!0);try{let e=await Z.getSlicerPresets({refresh:!0});a.setQueryData([`slicerPresets`],e)}catch{a.invalidateQueries({queryKey:[`slicerPresets`]})}finally{pe(!1)}}},he=K({queryKey:[`slicerPrinterModels`],queryFn:Z.getSlicerPrinterModels,staleTime:1/0}),ge=(0,f.useMemo)(()=>!de.data||!o?null:MW(de.data,o,`printer`)?.name??null,[de.data,o]),_e=(0,f.useMemo)(()=>QH(he.data??{}),[he.data]),ve=K({queryKey:[`slicer-preset-values`,c?.source,c?.id],queryFn:()=>Z.getSlicerPresetValues(c),enabled:c!=null,staleTime:5*6e4}),ye=ve.data?.values,be=ve.data?.resolved??ve.isLoading,xe=ve.data?.reason??(ve.isError?`sidecar_unavailable`:void 0),Se=(0,f.useMemo)(()=>{let e=de.data;return ue.map((t,n)=>{let i=u[n]??null,a=e&&i?MW(e,i,`filament`):null;return{index:n+1,label:a?.name||t.type||r(`slice.filamentSlotUnset`,`not set`),color:t.color||void 0}})},[ue,u,de.data,r]),Ce=ae.data?.embedded_printer??null,we=(0,f.useMemo)(()=>ae.data?.design_overrides??[],[ae.data]),Te=ae.data?.embedded_process??null,Ee=(0,f.useMemo)(()=>{if(!Ce||!Te||!ge)return!1;let e=e=>e.replace(/^#\s*/,``).trim().toLowerCase();return e(ge)===e(Ce)},[Ce,Te,ge]);(0,f.useEffect)(()=>{Ee||T(!1)},[Ee]),(0,f.useEffect)(()=>{j(w?new Set(we.map(e=>e.key)):new Set)},[we,w]),(0,f.useEffect)(()=>{let e=de.data;e&&(o??s(NW(e,`printer`,Ce)??jW(e,`printer`)))},[de.data,Ce]),(0,f.useEffect)(()=>{let e=de.data;e&&l(t=>{if(t){let n=MW(e,t,`process`);if(n&&iU(n,`process`,ge,_e)!==`mismatch`)return t}return Yje(e,ge,_e,Te)})},[de.data,ge,_e,Te]),(0,f.useEffect)(()=>{let e=de.data;e&&d(t=>ue.map((n,r)=>{let i=t[r]??null;if(i){let t=MW(e,i,`filament`),a=t&&!p.current.has(r)&&PW(t,n.type);if(t&&!a&&iU(t,`filament`,ge,_e)!==`mismatch`)return i}return $je(e,{type:n.type,color:n.color},ge,_e)}))},[de.data,ue,ge,_e]),(0,f.useEffect)(()=>{h(e=>e.length===ue.length?e:(p.current=new Set,ue.map(()=>null)))},[ue]);let De=q({mutationFn:async t=>{let n=Oe(t);return e.kind===`libraryFile`?Z.sliceLibraryFile(e.id,n):Z.sliceArchive(e.id,n)},onSuccess:n=>{i(n.job_id,e.kind,e.filename),t()},onError:e=>{_(e instanceof Error?e.message:String(e))}});function Oe(e){if(!o||!c||u.length===0||u.some(e=>e==null))throw Error(r(`slice.allPresetsRequired`));return{printer_preset:o,process_preset:c,filament_preset:u[0],filament_presets:u,filament_colours:ue.map((e,t)=>m[t]??e.color??``),...e==null?{}:{plate:e},...S==null?{}:{bed_type:S},...w&&Ee?{use_embedded_settings:!0}:{},...!w&&we.length>0?{design_overrides:[...A]}:{},...!w&&Object.keys(M).length>0?{process_overrides:P}:{},...E?{auto_orient:!0}:{},...O?{auto_arrange:!0}:{}}}let ke=o!=null&&c!=null&&le.isSuccess&&u.length>0&&u.every(e=>e!=null),Ae=De.isPending,je=ae.data?.plates?.length??0,Me=oe&&je>1&&!se;return se&&ae.data?(0,G.jsx)(yW,{plates:ae.data.plates,onSelect:e=>y(e),onClose:t}):(0,G.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-4`,onClick:()=>{Ae||t()},children:(0,G.jsxs)(`div`,{className:`w-full max-w-xl lg:max-w-5xl xl:max-w-7xl 2xl:max-w-[96rem] max-h-[85vh] flex flex-col rounded-lg bg-bambu-dark-secondary border border-bambu-dark-tertiary/60`,onClick:e=>e.stopPropagation(),children:[(0,G.jsxs)(`div`,{className:`flex-shrink-0 flex items-start justify-between gap-3 px-4 pt-4 pb-3 border-b border-bambu-dark-tertiary/40`,children:[(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsxs)(`h3`,{className:`text-white font-medium flex items-center gap-2`,children:[(0,G.jsx)(Ms,{className:`w-4 h-4`}),r(`slice.title`)]}),(0,G.jsxs)(`p`,{className:`text-xs text-bambu-gray mt-1 truncate`,title:e.filename,children:[e.filename,v==null?``:` • ${r(`archives.platePicker.plateLabel`,{index:v})}`]})]}),(0,G.jsx)(`button`,{onClick:t,disabled:Ae,className:`flex-shrink-0 text-bambu-gray hover:text-white transition-colors disabled:opacity-50`,"aria-label":r(`common.close`),children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]}),(0,G.jsxs)(`div`,{className:`flex-1 overflow-y-auto p-4 space-y-4`,children:[(ae.isLoading||de.isLoading)&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray text-sm`,children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),r(`slice.loadingPresets`)]}),de.isError&&(0,G.jsx)(`div`,{className:`text-sm text-red-700 dark:text-red-400`,role:`alert`,children:r(`slice.presetsLoadFailed`,`Failed to load presets. Open Settings → Profiles to import them, or sign in to Bambu Cloud.`)}),de.data&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,G.jsxs)(`div`,{className:`flex-1 space-y-2`,children:[(0,G.jsx)(RW,{status:de.data.cloud_status,cloudName:`bambu`}),(0,G.jsx)(RW,{status:de.data.orca_cloud_status,cloudName:`orca`})]}),(0,G.jsxs)(`button`,{type:`button`,onClick:me,disabled:fe||Ae,className:`flex-shrink-0 inline-flex items-center gap-1 px-2 py-1 rounded-md text-xs text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary/40 disabled:opacity-50 disabled:cursor-not-allowed transition-colors`,title:r(`slice.refreshPresetsTitle`),"aria-label":r(`slice.refreshPresets`),children:[(0,G.jsx)(zl,{className:`w-3.5 h-3.5 ${fe?`animate-spin`:``}`}),r(`slice.refreshPresets`)]})]}),(0,G.jsxs)(`div`,{className:`lg:grid lg:grid-cols-[minmax(20rem,2fr)_minmax(0,3fr)] lg:gap-5 lg:items-start`,children:[(0,G.jsxs)(`div`,{className:`space-y-4 min-w-0`,children:[(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 px-2 py-1.5 rounded-md bg-bambu-dark/40 border border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`span`,{className:`text-xs font-medium text-bambu-gray flex items-center gap-1`,children:[(0,G.jsx)(Ms,{className:`w-3.5 h-3.5`}),` `,r(`slice.pipelines.label`,`Pipeline`)]}),(0,G.jsxs)(`select`,{value:``,disabled:Ae||(B.data?.pipelines.length??0)===0,onChange:e=>{let t=parseInt(e.target.value,10);if(Number.isNaN(t))return;let n=B.data?.pipelines.find(e=>e.id===t);n&&(s(n.printer_preset),l(n.process_preset),C(n.bed_type),d(e=>{let t=e.length>0?[...e]:n.filament_presets.map(()=>null);for(let e=0;e(0,G.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),V?(0,G.jsxs)(`div`,{className:`flex items-center gap-1 flex-1 min-w-[16ch]`,children:[(0,G.jsx)(`input`,{autoFocus:!0,value:te,onChange:e=>ne(e.target.value),placeholder:r(`slice.pipelines.namePlaceholder`,`Pipeline name`),"aria-label":r(`slice.pipelines.nameAria`,`New pipeline name`),className:`flex-1 text-xs px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white`}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>{let e=te.trim();if(!e||!o||!c)return;let t=u.filter(e=>e!==null);t.length!==0&&ie.mutate({name:e,printer_preset:o,process_preset:c,filament_presets:t,bed_type:S})},disabled:ie.isPending||!te.trim(),className:`text-xs px-2 py-1 bg-bambu-green hover:bg-bambu-green/80 text-white rounded disabled:opacity-50`,children:ie.isPending?(0,G.jsx)(Y,{className:`w-3 h-3 animate-spin`}):r(`common.save`,`Save`)}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>{ee(!1),ne(``)},className:`text-xs px-2 py-1 text-bambu-gray hover:text-white`,children:r(`common.cancel`,`Cancel`)})]}):(0,G.jsx)(`button`,{type:`button`,onClick:()=>{ne(``),ee(!0)},disabled:Ae||!o||!c||u.length===0||u.some(e=>e===null),className:`text-xs px-2 py-1 bg-bambu-green/20 hover:bg-bambu-green/30 text-bambu-green border border-bambu-green/40 rounded disabled:opacity-50 disabled:cursor-not-allowed`,title:r(`slice.pipelines.saveTitle`,`Save the current four-slot selection as a reusable pipeline`),children:r(`slice.pipelines.saveButton`,`Save as pipeline`)})]}),(0,G.jsx)(zW,{label:r(`slice.printer`),slot:`printer`,data:de.data,value:o,onChange:s,disabled:Ae||w}),Ee&&(0,G.jsxs)(`label`,{className:`flex items-start gap-2 text-sm text-bambu-gray cursor-pointer select-none`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:w,onChange:e=>T(e.target.checked),disabled:Ae,className:`mt-0.5 cursor-pointer`}),(0,G.jsxs)(`span`,{children:[r(`slice.useEmbedded`),(0,G.jsx)(`span`,{className:`block text-xs text-bambu-gray/70`,children:r(`slice.useEmbeddedHint`)})]})]}),(0,G.jsx)(zW,{label:r(`slice.process`),slot:`process`,data:de.data,value:c,onChange:l,disabled:Ae||w,selectedPrinterName:ge,compatIndex:_e}),(0,G.jsx)(aMe,{value:S,onChange:C,disabled:Ae||w}),(0,G.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,G.jsxs)(`label`,{className:`flex items-start gap-2 text-sm text-bambu-gray cursor-pointer select-none`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:E,onChange:e=>D(e.target.checked),disabled:Ae,className:`mt-0.5 cursor-pointer`}),(0,G.jsxs)(`span`,{children:[r(`slice.autoOrient`),(0,G.jsx)(`span`,{className:`block text-xs text-bambu-gray/70`,children:r(`slice.autoOrientHint`)})]})]}),(0,G.jsxs)(`label`,{className:`flex items-start gap-2 text-sm text-bambu-gray cursor-pointer select-none`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:O,onChange:e=>k(e.target.checked),disabled:Ae,className:`mt-0.5 cursor-pointer`}),(0,G.jsxs)(`span`,{children:[r(`slice.autoArrange`),(0,G.jsx)(`span`,{className:`block text-xs text-bambu-gray/70`,children:r(`slice.autoArrangeHint`)})]})]})]}),le.isLoading?(0,G.jsx)(tMe,{requestId:ce,sourceName:e.filename}):ue.map((e,t)=>{let n=e.used_in_plate!==!1,i=ue.length>1?r(`slice.filamentSlot`,{index:t+1,type:e.type}):r(`slice.filament`);return(0,G.jsx)(zW,{label:n?i:`${i} ${r(`slice.notUsedByPlate`)}`,slot:`filament`,data:de.data,value:u[t]??null,onChange:e=>{p.current.add(t),d(n=>{let r=n.length===ue.length?[...n]:ue.map((e,t)=>n[t]??null);return r[t]=e,r})},disabled:Ae||!n||w,swatchColor:m[t]??e.color,swatchColorLabel:r(`slice.filamentColour`),onSwatchColorChange:e=>h(n=>{let r=n.length===ue.length?[...n]:ue.map((e,t)=>n[t]??null);return r[t]=e,r}),selectedPrinterName:ge,compatIndex:_e},`filament-${t}`)})]}),(0,G.jsx)(`div`,{className:`mt-4 lg:mt-0 min-w-0`,children:(0,G.jsxs)(`div`,{className:`rounded border border-bambu-dark-tertiary p-3 ${w?`opacity-60`:``}`,children:[(0,G.jsxs)(`button`,{type:`button`,onClick:()=>L(e=>!e),"aria-expanded":z,disabled:R,className:`flex w-full items-center justify-between gap-2 text-left lg:cursor-default`,children:[(0,G.jsxs)(`span`,{className:`text-sm text-white`,children:[r(`slice.processSettings`,`Process settings`),(0,G.jsx)(`span`,{className:`block text-xs text-bambu-gray/70`,children:w?r(`slice.processSettingsEmbedded`,`Not used while "Use the file's built-in settings" is on -- the file's own settings drive this slice.`):r(`slice.processSettingsHint`,`Adjust the picked preset for this slice. Anything you don't touch stays as the preset defines it.`)})]}),(0,G.jsx)(`span`,{className:`shrink-0 text-xs text-bambu-gray`,children:w?r(`slice.processSettingsInactive`,`Inactive`):Object.keys(P).length>0?r(`slice.processSettingsChanged`,`{{count}} changed`,{count:Object.keys(P).length}):r(`slice.processSettingsUnchanged`,`Preset defaults`)})]}),z&&(0,G.jsx)(`div`,{className:`mt-3 border-t border-bambu-dark-tertiary pt-3`,children:(0,G.jsx)(Gje,{values:M,onChange:(e,t)=>{N(e),F(t)},disabled:Ae||w,filamentChoices:Se,presetValues:ye,presetValuesResolved:be,presetValuesReason:xe,sourceOverrides:we,sourceSelected:A,onToggleSource:(e,t)=>j(n=>{let r=new Set(n);return t?r.add(e):r.delete(e),r})})})]})})]})]}),g&&(0,G.jsx)(`div`,{className:`text-sm text-red-700 dark:text-red-400 bg-red-900/20 border border-red-900/40 rounded p-2`,role:`alert`,children:g})]}),(0,G.jsxs)(`div`,{className:`flex-shrink-0 flex justify-end gap-2 px-4 py-3 border-t border-bambu-dark-tertiary/40`,children:[(0,G.jsx)(`button`,{type:`button`,onClick:t,disabled:Ae,className:`px-3 py-1.5 text-sm rounded-md border border-bambu-dark-tertiary text-bambu-gray hover:text-white hover:border-bambu-gray transition-colors disabled:opacity-50`,children:r(`common.cancel`)}),Me&&(0,G.jsxs)(`label`,{className:`flex items-center gap-2 mr-auto text-sm text-bambu-gray cursor-pointer select-none`,title:r(`slice.actionAllTitle`,{count:je}),children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:b,onChange:e=>x(e.target.checked),disabled:Ae,className:`cursor-pointer`}),r(`slice.allPlatesToggle`,{count:je})]}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>{_(null);let e=b?0:v;De.mutate(e)},disabled:!ke||Ae,className:`px-3 py-1.5 text-sm rounded-md bg-bambu-green hover:bg-bambu-green/90 text-bambu-dark font-medium transition-colors disabled:opacity-50 disabled:cursor-not-allowed flex items-center gap-2`,children:Ae?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),r(`slice.enqueuing`)]}):b?r(`slice.actionAll`,{count:je}):r(`slice.action`)})]})]})})}function RW({status:e,cloudName:t=`bambu`}){let{t:n}=U();if(e===`ok`||e===`not_authenticated`)return null;let r=t===`orca`?{expired:{key:`slice.orcaCloud.expired`,fallback:`Orca Cloud session expired — sign in again to refresh your Orca presets.`},unreachable:{key:`slice.orcaCloud.unreachable`,fallback:`Orca Cloud is unreachable right now. Other presets still work.`}}:{expired:{key:`slice.cloud.expired`,fallback:`Bambu Cloud session expired — sign in again to refresh your cloud presets.`},unreachable:{key:`slice.cloud.unreachable`,fallback:`Bambu Cloud is unreachable right now. Local and standard presets still work.`}},{tone:i,icon:a}={expired:{tone:`border-amber-300 dark:border-amber-700/40 bg-amber-50 dark:bg-amber-900/20 text-amber-800 dark:text-amber-200`,icon:Es},unreachable:{tone:`border-bambu-dark-tertiary/40 bg-bambu-dark text-bambu-gray`,icon:Es}}[e],{key:o,fallback:s}=r[e];return(0,G.jsxs)(`div`,{className:`flex items-start gap-2 text-xs rounded-md border p-2 ${i}`,role:`status`,children:[(0,G.jsx)(a,{className:`w-4 h-4 flex-shrink-0 mt-0.5`}),(0,G.jsx)(`span`,{children:n(o,s)})]})}var iMe=[{value:`Cool Plate`,labelKey:`slice.bedType.coolPlate`,fallback:`Cool Plate`},{value:`Cool Plate (SuperTack)`,labelKey:`slice.bedType.coolPlateSuperTack`,fallback:`Cool Plate SuperTack`},{value:`Engineering Plate`,labelKey:`slice.bedType.engineering`,fallback:`Engineering Plate`},{value:`High Temp Plate`,labelKey:`slice.bedType.highTemp`,fallback:`High Temp Plate`},{value:`Textured PEI Plate`,labelKey:`slice.bedType.texturedPEI`,fallback:`Textured PEI Plate`},{value:`Smooth PEI Plate`,labelKey:`slice.bedType.smoothPEI`,fallback:`Smooth PEI Plate`}];function aMe({value:e,onChange:t,disabled:n}){let{t:r}=U();return(0,G.jsxs)(`label`,{className:`block`,children:[(0,G.jsx)(`span`,{className:`block text-xs text-bambu-gray mb-1`,children:r(`slice.bedType.label`)}),(0,G.jsxs)(`select`,{value:e??``,onChange:e=>t(e.target.value===``?null:e.target.value),disabled:n,className:`flex-1 min-w-0 px-3 py-2 rounded-md bg-bambu-dark border border-bambu-dark-tertiary text-white text-sm focus:outline-none focus:border-bambu-gray disabled:opacity-50`,children:[(0,G.jsx)(`option`,{value:``,children:r(`slice.bedType.auto`)}),iMe.map(e=>(0,G.jsx)(`option`,{value:e.value,children:r(e.labelKey,e.fallback)},e.value))]})]})}function zW({label:e,slot:t,data:n,value:r,onChange:i,disabled:a,swatchColor:o,onSwatchColorChange:s,swatchColorLabel:c,selectedPrinterName:l,compatIndex:u}){let{t:d}=U(),[p,m]=(0,f.useState)(!1),h=(0,f.useId)(),g=`${h}-colour`,{sections:_,otherEntries:v}=(0,f.useMemo)(()=>{let e=[{key:`local`,label:`slice.tier.local`,fallback:`Imported`},{key:`orca_cloud`,label:`slice.tier.orcaCloud`,fallback:`Orca Cloud`},{key:`cloud`,label:`slice.tier.cloud`,fallback:`Bambu Cloud`},{key:`standard`,label:`slice.tier.standard`,fallback:`Standard`}],r=t!==`printer`,i=[],a=[],o=[];for(let{key:s,label:c,fallback:f}of e){let e=n[s][t];if(e.length>0&&a.push({tierLabel:d(c,f),entries:e}),!r){e.length>0&&i.push({tierLabel:d(c,f),entries:e});continue}let p=[];for(let n of e)iU(n,t,l??null,u??yAe)===`mismatch`?o.push(n):p.push(n);p.length>0&&i.push({tierLabel:d(c,f),entries:p})}return i.length===0&&o.length>0?{sections:a,otherEntries:[]}:{sections:i,otherEntries:o}},[n,t,d,l,u]),y=FW(r),b=(0,f.useMemo)(()=>p?v:v.filter(e=>`${e.source}:${e.id}`===y),[p,v,y]),x=v.length-b.length,S=_.reduce((e,t)=>e+t.entries.length,0)+b.length;return(0,G.jsxs)(`div`,{className:`block`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-bambu-gray mb-1`,children:[!s&&o&&(0,G.jsx)(`span`,{className:`inline-block w-3 h-3 rounded-full border border-bambu-dark-tertiary`,style:{backgroundColor:o},"aria-hidden":!0}),(0,G.jsx)(`label`,{htmlFor:h,children:e}),(x>0||p)&&(0,G.jsxs)(`span`,{className:`ml-auto flex items-center gap-1.5 font-normal`,children:[x>0&&(0,G.jsx)(`span`,{className:`text-bambu-gray/60`,children:d(`slice.presetsHidden`,`{{count}} hidden`,{count:x})}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>m(e=>!e),disabled:a,className:`text-bambu-green hover:underline disabled:opacity-50 disabled:no-underline`,children:p?d(`slice.showFewerPresets`,`Show fewer`):d(`slice.showAllPresets`,`Show all`)})]})]}),(0,G.jsxs)(`div`,{className:`flex items-stretch gap-2`,children:[(0,G.jsxs)(`select`,{id:h,value:FW(r),onChange:e=>i(eMe(e.target.value)),disabled:a||S===0,className:`w-full px-3 py-2 rounded-md bg-bambu-dark border border-bambu-dark-tertiary text-white text-sm focus:outline-none focus:border-bambu-gray disabled:opacity-50`,children:[(0,G.jsx)(`option`,{value:``,children:d(S===0?`slice.noPresetsForSlot`:`slice.selectPreset`)}),_.map(e=>(0,G.jsx)(`optgroup`,{label:e.tierLabel,children:e.entries.map(e=>(0,G.jsx)(`option`,{value:`${e.source}:${e.id}`,children:e.name},`${e.source}:${e.id}`))},e.tierLabel)),b.length>0&&(0,G.jsx)(`optgroup`,{label:d(`slice.otherPrinters`),children:b.map(e=>(0,G.jsx)(`option`,{value:`${e.source}:${e.id}`,children:e.name},`${e.source}:${e.id}`))})]}),s&&(0,G.jsxs)(`label`,{htmlFor:g,title:c,className:`flex items-center gap-2 px-2.5 rounded-md bg-bambu-dark border border-bambu-dark-tertiary text-sm ${a?`opacity-50 cursor-not-allowed`:`cursor-pointer hover:border-bambu-gray transition-colors`}`,children:[(0,G.jsx)(`input`,{id:g,type:`color`,value:IW(o),onChange:e=>s(e.target.value.toUpperCase()),disabled:a,"aria-label":c,style:{backgroundColor:IW(o)},className:`slice-colour-swatch w-4 h-4 shrink-0 rounded-full border border-bambu-dark-tertiary p-0 disabled:cursor-not-allowed enabled:cursor-pointer`}),(0,G.jsx)(`span`,{className:`font-mono text-xs text-white tracking-tight`,children:IW(o)})]})]})]})}function BW({source:e,onClose:t}){let{t:n}=U(),r=no(),{showToast:i}=Zd(),[a,o]=(0,f.useState)(null),[s,c]=(0,f.useState)(null),[l,u]=(0,f.useState)(1),{trackJob:d}=_W(),{data:p,isLoading:m}=K({queryKey:[`slicer-pipelines`],queryFn:()=>Z.listSlicerPipelines()}),{data:h}=K({queryKey:[`printers`],queryFn:()=>Z.getPrinters()}),{data:g}=K({queryKey:[`app-settings`],queryFn:()=>Z.getSettings()}),_=g?.pipeline_max_copies??50,v={kind:e.kind,id:e.id},y=q({mutationFn:e=>Z.checkPipelineEligibility(e,v)}),b=q({mutationFn:({pipelineId:e,force:t})=>Z.runPipeline(e,v,t,l),onSuccess:a=>{r.invalidateQueries({queryKey:[`slicer-pipelines`]}),r.invalidateQueries({queryKey:[`pipeline-runs`]}),a.slice_job_id&&d(a.slice_job_id,e.kind,e.filename),i(n(`library.runWithPipeline.toast.started`,`Pipeline run started`),`success`),t()},onError:e=>{i(e.message||n(`library.runWithPipeline.toast.failed`,`Could not start run`),`error`)}}),x=p?.pipelines??[],S=(h??[]).reduce((e,t)=>(e[t.id]=t,e),{});return(0,G.jsx)(`div`,{className:`fixed inset-0 z-50 bg-black/60 flex items-center justify-center p-4`,onClick:t,role:`dialog`,"aria-modal":`true`,"aria-label":n(`library.runWithPipeline.modalTitle`,`Run with pipeline`),children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-2xl w-full max-w-md max-h-[80vh] flex flex-col overflow-hidden`,onClick:e=>e.stopPropagation(),children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`h3`,{className:`text-sm font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(Al,{className:`w-4 h-4 text-bambu-green`}),a&&s?n(`library.runWithPipeline.confirmTitle`,`Confirm run`):n(`library.runWithPipeline.modalTitle`,`Run with pipeline`)]}),(0,G.jsx)(`button`,{type:`button`,onClick:t,"aria-label":n(`common.close`,`Close`),className:`text-bambu-gray hover:text-white`,children:(0,G.jsx)(nd,{className:`w-4 h-4`})})]}),(0,G.jsx)(`div`,{className:`flex-1 overflow-y-auto p-4 space-y-3`,children:a&&s?(0,G.jsx)(sMe,{pipeline:a,report:s,source:e,onBack:()=>{o(null),c(null)},onConfirm:()=>{a&&b.mutate({pipelineId:a.id,force:!0})},running:b.isPending}):(0,G.jsx)(oMe,{source:e,pipelines:x,printerById:S,loading:m||y.isPending,onPick:async e=>{if(!(e.target_printer_id||e.target_kind===`printer_class`&&e.target_model_class)){i(n(`library.runWithPipeline.noTargetMessage`,`This pipeline has no target printer set. Open it in Settings to pick one.`),`error`);return}o(e);try{let t=await y.mutateAsync(e.id);c(t),t.ok&&b.mutate({pipelineId:e.id,force:!1})}catch{o(null)}},copies:l,maxCopies:_,onCopiesChange:u})})]})})}function oMe({source:e,pipelines:t,printerById:n,loading:r,onPick:i,copies:a,maxCopies:o,onCopiesChange:s}){let{t:c}=U();return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`p`,{className:`text-xs text-bambu-gray`,children:[c(`library.runWithPipeline.sourceHint`,`Source`),`:`,` `,(0,G.jsx)(`span`,{className:`text-white`,children:e.filename})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`label`,{className:`text-xs text-bambu-gray`,htmlFor:`run-pipeline-copies`,children:[c(`library.runWithPipeline.copies`,`Copies`),`:`]}),(0,G.jsx)(`input`,{id:`run-pipeline-copies`,type:`number`,min:1,max:o,value:a,onChange:e=>{let t=parseInt(e.target.value,10);Number.isNaN(t)||s(Math.max(1,Math.min(o,t)))},"aria-label":c(`library.runWithPipeline.copies`,`Copies`),className:`w-20 px-2 py-1 text-xs bg-bambu-dark border border-bambu-dark-tertiary rounded text-white`}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray/60`,children:c(`library.runWithPipeline.copiesHint`,`max {{n}}`,{n:o})})]}),r&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-bambu-gray`,children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),c(`library.runWithPipeline.loading`,`Loading…`)]}),!r&&t.length===0&&(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:c(`library.runWithPipeline.empty`,`No pipelines saved yet. Open the Slice dialog and click "Save as pipeline" to create one.`)}),!r&&t.length>0&&(0,G.jsx)(`ul`,{className:`space-y-1.5`,"aria-label":c(`library.runWithPipeline.pipelineListAria`,`Available pipelines`),children:t.map(e=>{let t=e.target_kind===`printer_class`,r=e.target_printer_id?n[e.target_printer_id]?.name:null,a=t&&e.target_model_class?c(`library.runWithPipeline.classTarget`,`Any {{model}}`,{model:e.target_model_class}):null;return(0,G.jsx)(`li`,{children:(0,G.jsxs)(`button`,{type:`button`,onClick:()=>i(e),disabled:!(e.target_printer_id||t&&e.target_model_class),className:`w-full text-left px-3 py-2 rounded-md border border-bambu-dark-tertiary bg-bambu-dark/40 hover:bg-bambu-dark-tertiary disabled:opacity-50 disabled:cursor-not-allowed transition-colors`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Ms,{className:`w-3.5 h-3.5 text-bambu-green flex-shrink-0`}),(0,G.jsx)(`span`,{className:`text-sm font-medium text-white truncate`,children:e.name})]}),(0,G.jsxs)(`div`,{className:`mt-1 text-xs text-bambu-gray flex items-center gap-1`,children:[(0,G.jsx)(Fl,{className:`w-3 h-3`}),a?(0,G.jsx)(`span`,{children:a}):r?(0,G.jsx)(`span`,{children:r}):(0,G.jsx)(`span`,{className:`text-amber-700 dark:text-amber-400`,children:c(`library.runWithPipeline.noTarget`,`No target printer set`)})]})]})},e.id)})})]})}function sMe({pipeline:e,report:t,source:n,onBack:r,onConfirm:i,running:a}){let{t:o}=U();return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`text-xs text-bambu-gray`,children:[(0,G.jsxs)(`p`,{children:[o(`library.runWithPipeline.confirmIntro`,`Pre-flight found issues with this run`),`:`]}),(0,G.jsxs)(`p`,{className:`mt-1`,children:[(0,G.jsxs)(`span`,{className:`text-bambu-gray/70`,children:[o(`library.runWithPipeline.sourceHint`,`Source`),`: `]}),(0,G.jsx)(`span`,{className:`text-white`,children:n.filename})]}),(0,G.jsxs)(`p`,{children:[(0,G.jsxs)(`span`,{className:`text-bambu-gray/70`,children:[o(`library.runWithPipeline.pipelineHint`,`Pipeline`),`: `]}),(0,G.jsx)(`span`,{className:`text-white`,children:e.name})]}),t.target_printer_name&&(0,G.jsxs)(`p`,{children:[(0,G.jsxs)(`span`,{className:`text-bambu-gray/70`,children:[o(`library.runWithPipeline.targetHint`,`Target`),`: `]}),(0,G.jsx)(`span`,{className:`text-white`,children:t.target_printer_name})]})]}),(0,G.jsx)(`ul`,{className:`space-y-1.5`,children:t.issues.map((e,t)=>(0,G.jsxs)(`li`,{className:`flex items-start gap-2 text-xs`,children:[(0,G.jsx)(Lu,{className:`w-3.5 h-3.5 text-amber-600 dark:text-amber-400 flex-shrink-0 mt-0.5`}),(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:(0,G.jsx)(cMe,{issue:e})})]},t))}),(0,G.jsxs)(`div`,{className:`flex items-center justify-end gap-2 pt-2 border-t border-bambu-dark-tertiary`,children:[(0,G.jsx)(`button`,{type:`button`,onClick:r,disabled:a,className:`px-3 py-1.5 text-xs text-bambu-gray hover:text-white`,children:o(`common.back`,`Back`)}),(0,G.jsxs)(`button`,{type:`button`,onClick:i,disabled:a,className:`px-3 py-1.5 text-xs bg-amber-500 hover:bg-amber-600 text-white rounded disabled:opacity-50 flex items-center gap-1`,children:[a?(0,G.jsx)(Y,{className:`w-3 h-3 animate-spin`}):(0,G.jsx)(Al,{className:`w-3 h-3`}),o(`library.runWithPipeline.runAnyway`,`Run anyway`)]})]})]})}function cMe({issue:e}){let{t}=U();switch(e.kind){case`printer_not_set`:return(0,G.jsx)(G.Fragment,{children:t(`library.runWithPipeline.issue.printerNotSet`,`No target printer set on this pipeline.`)});case`printer_not_found`:return(0,G.jsx)(G.Fragment,{children:t(`library.runWithPipeline.issue.printerNotFound`,`Target printer no longer exists.`)});case`printer_disabled`:return(0,G.jsx)(G.Fragment,{children:t(`library.runWithPipeline.issue.printerDisabled`,`Target printer is disabled.`)});case`printer_offline`:return(0,G.jsx)(G.Fragment,{children:t(`library.runWithPipeline.issue.printerOffline`,`Target printer is offline.`)});case`filament_type_mismatch`:return(0,G.jsx)(G.Fragment,{children:t(`library.runWithPipeline.issue.filamentType`,`Filament slot {{slot}}: expected {{expected}}, AMS has {{actual}}`,{slot:(e.slot_index??0)+1,expected:e.expected??`?`,actual:e.actual??`?`})});case`filament_color_mismatch`:return(0,G.jsx)(G.Fragment,{children:t(`library.runWithPipeline.issue.filamentColor`,`Filament slot {{slot}}: colour differs (expected {{expected}}, AMS has {{actual}})`,{slot:(e.slot_index??0)+1,expected:e.expected??`?`,actual:e.actual??`?`})});case`ams_slot_missing`:return(0,G.jsx)(G.Fragment,{children:t(`library.runWithPipeline.issue.amsSlotMissing`,`AMS slot {{slot}} not available on this printer`,{slot:(e.slot_index??0)+1})});case`filament_unverified`:return(0,G.jsx)(G.Fragment,{children:t(`library.runWithPipeline.issue.filamentUnverified`,`Filament slot {{slot}} comes from a cloud / standard preset and could not be statically verified.`,{slot:(e.slot_index??0)+1})});default:return(0,G.jsx)(G.Fragment,{children:e.kind})}}function VW(e,t){return e??t??`bambu_studio`}var HW={bambu_studio:[`3mf`],orcaslicer:[`3mf`,`stl`,`step`,`stp`]};function UW(e){return HW[e]??HW.bambu_studio}var WW=[`3mf`,`stl`];function lMe(e,t){let n=(e||``).toLowerCase();return UW(t).includes(n)}function uMe(e,t){let n=e.toLowerCase();return n.endsWith(`.gcode`)||n.endsWith(`.gcode.3mf`)?!1:UW(t).some(e=>n.endsWith(`.${e}`))}function dMe(e){let t=e.toLowerCase();return t.endsWith(`.gcode`)||t.endsWith(`.gcode.3mf`)?!1:WW.some(e=>t.endsWith(`.${e}`))}function fMe(){let e=navigator.userAgent.toLowerCase(),t=navigator.platform?.toLowerCase()||``;return e.includes(`win`)||t.includes(`win`)?`windows`:e.includes(`mac`)||t.includes(`mac`)?`macos`:e.includes(`linux`)||t.includes(`linux`)?`linux`:`unknown`}function GW(e,t=`bambu_studio`){let n,r=encodeURIComponent(e);n=t===`orcaslicer`?`orcaslicer://open?file=${r}`:fMe()===`macos`?`bambustudioopen://${r}`:`bambustudio://open?file=${r}`;let i=document.createElement(`a`);i.href=n,i.style.display=`none`,document.body.appendChild(i),i.click(),document.body.removeChild(i)}function pMe(e){let t=(e||``).toLowerCase();return WW.includes(t)}function KW({onFiles:e,onRejected:t,extensions:n,disabled:r=!1}){let[i,a]=(0,f.useState)(!1),o=(0,f.useRef)(e),s=(0,f.useRef)(t),c=(0,f.useRef)(n);(0,f.useEffect)(()=>{o.current=e},[e]),(0,f.useEffect)(()=>{s.current=t},[t]),(0,f.useEffect)(()=>{c.current=n},[n]);let l=(0,f.useCallback)(e=>{r||(e.preventDefault(),e.dataTransfer.types.includes(`Files`)&&a(!0))},[r]),u=(0,f.useCallback)(e=>{r||(e.preventDefault(),e.dataTransfer.types.includes(`Files`)&&a(!0))},[r]),d=(0,f.useCallback)(e=>{if(r)return;e.preventDefault();let t=e.currentTarget,n=e.relatedTarget;(!n||!t.contains(n))&&a(!1)},[r]),p=(0,f.useCallback)(e=>{if(r)return;e.preventDefault(),a(!1);let t=Array.from(e.dataTransfer.files);if(t.length===0)return;let n=c.current,i=n&&n.length>0?t.filter(e=>n.some(t=>e.name.toLowerCase().endsWith(t))):t;i.length>0?o.current(i):s.current?.()},[r]);return(0,f.useEffect)(()=>{if(!i)return;let e=()=>a(!1),t=t=>{t.key===`Escape`&&e()};return document.addEventListener(`drop`,e),document.addEventListener(`dragend`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`drop`,e),document.removeEventListener(`dragend`,e),document.removeEventListener(`keydown`,t)}},[i]),{isDraggingOver:i,dragHandlers:{onDragOver:l,onDragEnter:u,onDragLeave:d,onDrop:p}}}function mMe({onClose:e,initialFiles:t}){let{t:n}=U(),r=no(),{showToast:i}=Zd(),a=(0,f.useRef)(null),[o,s]=(0,f.useState)(()=>t?.filter(e=>e.name.endsWith(`.3mf`)).map(e=>({file:e,status:`pending`}))||[]),[c,l]=(0,f.useState)(!1),[u,d]=(0,f.useState)(null);(0,f.useEffect)(()=>{let t=t=>{t.key===`Escape`&&e()};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e]);let p=q({mutationFn:e=>Z.uploadArchivesBulk(e),onSuccess:e=>{d(e),r.invalidateQueries({queryKey:[`archives`]}),r.invalidateQueries({queryKey:[`archiveStats`]}),s(t=>t.map(t=>{let n=e.results.find(e=>e.filename===t.file.name),r=e.errors.find(e=>e.filename===t.file.name);return n?{...t,status:`success`,archiveId:n.id}:r?{...t,status:`error`,error:r.error}:t})),e.failed===0?i(`${e.uploaded} file${e.uploaded===1?``:`s`} uploaded`):e.uploaded===0?i(`Failed to upload ${e.failed} file${e.failed===1?``:`s`}`,`error`):i(`${e.uploaded} uploaded, ${e.failed} failed`,`warning`)},onError:()=>{s(e=>e.map(e=>({...e,status:`error`,error:`Upload failed`}))),i(`Upload failed`,`error`)}}),m=(0,f.useCallback)(e=>{e.preventDefault(),l(!0)},[]),h=(0,f.useCallback)(e=>{e.preventDefault(),l(!1)},[]),g=(0,f.useCallback)(e=>{e.preventDefault(),l(!1);let t=Array.from(e.dataTransfer.files).filter(e=>e.name.endsWith(`.3mf`));t.length>0&&s(e=>[...e,...t.map(e=>({file:e,status:`pending`}))])},[]),_=(0,f.useCallback)(e=>{let t=Array.from(e.target.files||[]).filter(e=>e.name.endsWith(`.3mf`));t.length>0&&s(e=>[...e,...t.map(e=>({file:e,status:`pending`}))]),a.current&&(a.current.value=``)},[]),v=(0,f.useCallback)(e=>{s(t=>t.filter((t,n)=>n!==e))},[]),y=()=>{if(o.length===0)return;let e=o.filter(e=>e.status===`pending`);e.length!==0&&(s(e=>e.map(e=>e.status===`pending`?{...e,status:`uploading`}:e)),p.mutate(e.map(e=>e.file)))},b=o.filter(e=>e.status===`pending`).length,x=p.isPending;return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,children:(0,G.jsx)(Ud,{className:`w-full max-w-2xl max-h-[90vh] flex flex-col`,children:(0,G.jsxs)(Gd,{className:`p-0 flex flex-col h-full`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,G.jsx)(`h2`,{className:`text-xl font-semibold text-white`,children:n(`uploadModal.title`)}),(0,G.jsx)(`button`,{onClick:e,className:`text-bambu-gray hover:text-white transition-colors`,children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]}),(0,G.jsx)(`div`,{className:`p-4`,children:(0,G.jsxs)(`div`,{className:`border-2 border-dashed rounded-lg p-8 text-center transition-colors ${c?`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary hover:border-bambu-gray`}`,onDragOver:m,onDragLeave:h,onDrop:g,children:[(0,G.jsx)(Vu,{className:`w-12 h-12 mx-auto mb-4 text-bambu-gray`}),(0,G.jsx)(`p`,{className:`text-white mb-2`,children:n(`uploadModal.dragDrop`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-sm mb-4`,children:n(`uploadModal.or`)}),(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>a.current?.click(),disabled:x,children:n(`uploadModal.browseFiles`)}),(0,G.jsx)(`input`,{ref:a,type:`file`,accept:`.3mf`,multiple:!0,className:`hidden`,onChange:_})]})}),(0,G.jsx)(`div`,{className:`px-4 pb-4`,children:(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`uploadModal.extractionInfo`)})}),o.length>0&&(0,G.jsx)(`div`,{className:`px-4 pb-4 max-h-60 overflow-y-auto`,children:(0,G.jsx)(`div`,{className:`space-y-2`,children:o.map((e,t)=>(0,G.jsxs)(`div`,{className:`flex items-center gap-3 p-3 bg-bambu-dark rounded-lg`,children:[(0,G.jsx)(cc,{className:`w-5 h-5 text-bambu-gray flex-shrink-0`}),(0,G.jsx)(`span`,{className:`flex-1 text-white text-sm truncate`,children:e.file.name}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[(e.file.size/(1024*1024)).toFixed(1),` MB`]}),e.status===`pending`&&(0,G.jsx)(`button`,{onClick:()=>v(t),className:`text-bambu-gray hover:text-red-600 dark:hover:text-red-400 transition-colors`,disabled:x,children:(0,G.jsx)(nd,{className:`w-4 h-4`})}),e.status===`uploading`&&(0,G.jsx)(Y,{className:`w-4 h-4 text-bambu-green animate-spin`}),e.status===`success`&&(0,G.jsx)(hs,{className:`w-4 h-4 text-bambu-green`}),e.status===`error`&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-xs text-red-700 dark:text-red-400`,children:e.error}),(0,G.jsx)(ps,{className:`w-4 h-4 text-red-600 dark:text-red-400`})]})]},`${e.file.name}-${t}`))})}),u&&(0,G.jsx)(`div`,{className:`px-4 pb-4`,children:(0,G.jsx)(`div`,{className:`p-3 bg-bambu-dark rounded-lg`,children:(0,G.jsxs)(`p`,{className:`text-sm text-white`,children:[(0,G.jsx)(`span`,{className:`text-bambu-green`,children:u.uploaded}),` `,n(`uploadModal.uploaded`),u.failed>0&&(0,G.jsxs)(G.Fragment,{children:[`, `,(0,G.jsx)(`span`,{className:`text-red-700 dark:text-red-400`,children:u.failed}),` `,n(`uploadModal.failed`)]})]})})}),(0,G.jsxs)(`div`,{className:`flex gap-3 p-4 border-t border-bambu-dark-tertiary`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:e,className:`flex-1`,children:n(u?`common.close`:`common.cancel`)}),!u&&(0,G.jsx)(Q,{onClick:y,disabled:b===0||x,className:`flex-1`,children:x?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),n(`uploadModal.uploading`)]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Vu,{className:`w-4 h-4`}),n(`uploadModal.upload`),` `,b>0&&`(${b})`]})})]})]})})})}var hMe=365;function gMe({onClose:e,initialDays:t}){let{t:n}=U(),r=no(),{showToast:i}=Zd(),[a,o]=(0,f.useState)(t??hMe),[s,c]=(0,f.useState)(!1),[l,u]=(0,f.useState)(a);(0,f.useEffect)(()=>{let e=window.setTimeout(()=>u(a),300);return()=>window.clearTimeout(e)},[a]);let d=K({queryKey:[`archive-purge-preview`,l,s],queryFn:()=>Z.previewArchivePurge(l,s),enabled:l>=1}),p=q({mutationFn:()=>Z.executeArchivePurge(a,s),onSuccess:t=>{i(n(`archivePurge.toast.success`,{count:t.deleted}),`success`),r.invalidateQueries({queryKey:[`archives`]}),r.invalidateQueries({queryKey:[`archive-stats`]}),e()},onError:e=>i(e.message||n(`archivePurge.toast.failed`),`error`)});(0,f.useEffect)(()=>{let t=t=>{t.key===`Escape`&&!p.isPending&&e()};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e,p.isPending]);let m=d.data,h=m?.count??0,g=m?.total_bytes??0,_=h>0&&!p.isPending;return(0,G.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4`,children:(0,G.jsxs)(`div`,{className:`bg-white dark:bg-gray-900 rounded-lg shadow-xl max-w-lg w-full`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-gray-200 dark:border-gray-700`,children:[(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-gray-900 dark:text-gray-100 flex items-center gap-2`,children:[(0,G.jsx)(Pu,{className:`w-5 h-5`}),n(`archivePurge.title`)]}),(0,G.jsx)(`button`,{onClick:e,className:`text-gray-400 hover:text-gray-600 dark:hover:text-gray-200`,"aria-label":n(`common.close`),disabled:p.isPending,children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]}),(0,G.jsxs)(`div`,{className:`p-4 space-y-4`,children:[(0,G.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400`,children:n(`archivePurge.description`)}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{htmlFor:`archive-purge-days`,className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:n(`archivePurge.ageLabel`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`input`,{id:`archive-purge-days`,type:`number`,min:1,max:3650,value:a,onChange:e=>o(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,G.jsx)(`span`,{className:`text-sm text-gray-600 dark:text-gray-400`,children:n(`archivePurge.days`)})]})]}),(0,G.jsxs)(`div`,{className:`rounded border border-gray-200 dark:border-gray-700 bg-gray-50 dark:bg-gray-800/30 p-3`,children:[(0,G.jsx)(`div`,{className:`text-xs font-semibold uppercase tracking-wide text-gray-600 dark:text-gray-300 mb-2`,children:n(`archivePurge.effectsTitle`)}),(0,G.jsxs)(`ul`,{className:`text-xs text-gray-700 dark:text-gray-300 space-y-1 list-disc pl-4`,children:[(0,G.jsx)(`li`,{children:n(`archivePurge.effect1`)}),(0,G.jsx)(`li`,{children:n(`archivePurge.effect2`)}),(0,G.jsx)(`li`,{children:n(`archivePurge.effect3`)}),(0,G.jsx)(`li`,{children:n(`archivePurge.effect4`)})]})]}),(0,G.jsx)(`div`,{className:`rounded border border-gray-200 dark:border-gray-700 bg-gray-50 dark:bg-gray-800/50 p-3`,children:d.isLoading||d.isFetching?(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-gray-500 dark:text-gray-400`,children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),` `,n(`archivePurge.previewLoading`)]}):d.isError?(0,G.jsx)(`div`,{className:`text-sm text-red-600 dark:text-red-400`,children:d.error?.message??n(`archivePurge.previewFailed`)}):(0,G.jsxs)(`div`,{className:`text-sm text-gray-900 dark:text-gray-100`,children:[(0,G.jsx)(`div`,{className:`font-medium`,children:n(`archivePurge.previewSummary`,{count:h,size:Yd(g)})}),m?.sample_filenames&&m.sample_filenames.length>0&&(0,G.jsxs)(`ul`,{className:`mt-2 text-xs text-gray-600 dark:text-gray-400 space-y-0.5 list-disc pl-4`,children:[m.sample_filenames.map(e=>(0,G.jsx)(`li`,{className:`truncate`,children:e},e)),h>m.sample_filenames.length&&(0,G.jsx)(`li`,{className:`list-none italic text-gray-500`,children:n(`archivePurge.andMore`,{count:h-m.sample_filenames.length})})]})]})}),(0,G.jsxs)(`label`,{className:`flex gap-2 items-start rounded border border-gray-200 dark:border-gray-700 px-3 py-2 cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-800/50`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:s,onChange:e=>c(e.target.checked),disabled:p.isPending,className:`mt-0.5 shrink-0`}),(0,G.jsxs)(`span`,{className:`text-xs text-gray-700 dark:text-gray-300`,children:[(0,G.jsx)(`span`,{className:`font-medium block mb-0.5`,children:n(`archivePurge.purgeStatsLabel`)}),(0,G.jsx)(`span`,{className:`text-gray-500 dark:text-gray-400`,children:n(`archivePurge.purgeStatsHint`)})]})]}),(0,G.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,G.jsx)(Lu,{className:`w-4 h-4 mt-0.5 shrink-0`}),(0,G.jsx)(`span`,{children:n(`archivePurge.warning`)})]})]}),(0,G.jsxs)(`div`,{className:`flex justify-end gap-2 p-4 border-t border-gray-200 dark:border-gray-700`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:e,disabled:p.isPending,children:n(`common.cancel`)}),(0,G.jsx)(Q,{variant:`danger`,disabled:!_,onClick:()=>p.mutate(),children:p.isPending?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin mr-1`}),n(`archivePurge.purging`)]}):n(`archivePurge.confirmCta`,{count:h})})]})]})})}function qW({archiveId:e,archiveName:t,onClose:n}){let{t:r}=U();return(0,f.useEffect)(()=>{let e=e=>{e.key===`Escape`&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[n]),(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:n,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-2xl max-h-[85vh] flex flex-col`,onClick:e=>e.stopPropagation(),children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,G.jsx)(Pc,{className:`w-5 h-5 text-bambu-green flex-shrink-0`}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white truncate`,title:t||``,children:r(`archives.runLog.modalTitle`,{name:t||r(`archives.runLog.modalTitleFallback`)})})]}),(0,G.jsx)(`button`,{onClick:n,className:`text-bambu-gray hover:text-white transition-colors`,title:r(`common.close`),children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]}),(0,G.jsx)(`div`,{className:`p-6 overflow-y-auto flex-1`,children:(0,G.jsx)(Qp,{archiveId:e})})]})})}function JW({isOpen:e,onClose:t,columns:n,defaultColumns:r,onSave:i}){let{t:a}=U(),[o,s]=(0,f.useState)(n),[c,l]=(0,f.useState)(null),u=(0,f.useRef)(null);if((0,f.useEffect)(()=>{e&&s(n.map(e=>({...e})))},[e,n]),(0,f.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))},p=(e,t)=>{t<0||t>=o.length||s(n=>{let r=[...n],[i]=r.splice(e,1);return r.splice(t,0,i),r})},m=(e,t)=>{u.current=t,l(t),e.dataTransfer.effectAllowed=`move`},h=(e,t)=>{e.preventDefault(),e.dataTransfer.dropEffect=`move`;let n=u.current;n!==null&&n!==t&&(p(n,t),u.current=t,l(t))},g=e=>{e.preventDefault()},_=()=>{u.current=null,l(null)},v=()=>{s(r.map(e=>({...e})))},y=()=>{i(o),t()},b=o.filter(e=>e.visible).length;return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,onClick:t,children:(0,G.jsx)(Ud,{className:`w-full max-w-md max-h-[80vh] flex flex-col`,onClick:e=>e.stopPropagation(),children:(0,G.jsxs)(Gd,{className:`p-6 flex flex-col min-h-0`,children:[(0,G.jsx)(`h3`,{className:`text-lg font-semibold text-white mb-2`,children:a(`inventory.configureColumns`)}),(0,G.jsxs)(`p`,{className:`text-sm text-bambu-gray mb-4`,children:[a(`inventory.configureColumnsDesc`),(0,G.jsxs)(`span`,{className:`ml-2 text-bambu-gray/60`,children:[`(`,b,` `,a(`inventory.of`),` `,o.length,` `,a(`inventory.visible`),`)`]})]}),(0,G.jsx)(`div`,{className:`space-y-1 overflow-y-auto flex-1 min-h-0 pr-1`,children:o.map((e,t)=>(0,G.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=>m(e,t),onDragOver:e=>h(e,t),onDrop:g,onDragEnd:_,children:[(0,G.jsx)(`div`,{className:`cursor-grab text-bambu-gray/50 hover:text-bambu-gray`,children:(0,G.jsx)(Ec,{className:`w-4 h-4`})}),(0,G.jsx)(`span`,{className:`flex-1 font-medium text-sm text-white`,children:e.label}),(0,G.jsxs)(`div`,{className:`flex items-center gap-0.5`,children:[(0,G.jsx)(`button`,{onClick:()=>p(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,G.jsx)(us,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:()=>p(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,G.jsx)(ss,{className:`w-4 h-4`})})]}),(0,G.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,G.jsx)(ec,{className:`w-4 h-4`}):(0,G.jsx)($s,{className:`w-4 h-4`})})]},e.id))}),(0,G.jsxs)(`div`,{className:`flex items-center gap-3 mt-4 pt-4 border-t border-bambu-dark-tertiary`,children:[(0,G.jsxs)(Q,{variant:`secondary`,onClick:v,className:`mr-auto`,children:[(0,G.jsx)(Vl,{className:`w-4 h-4`}),a(`inventory.reset`)]}),(0,G.jsx)(Q,{variant:`secondary`,onClick:t,children:a(`inventory.cancel`)}),(0,G.jsx)(Q,{onClick:y,children:a(`inventory.applyChanges`)})]})]})})})}function _Me({selectedIds:e,existingTags:t,onClose:n}){let r=no(),{showToast:i}=Zd(),[a,o]=(0,f.useState)(``),[s,c]=(0,f.useState)(new Set),[l,u]=(0,f.useState)(`add`);(0,f.useEffect)(()=>{let e=e=>{e.key===`Escape`&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[n]);let d=q({mutationFn:async()=>{let t=Array.from(s),n=0;for(let r of e)try{let e=await Z.getArchive(r),i=e.tags?e.tags.split(`,`).map(e=>e.trim()).filter(Boolean):[],a;a=l===`add`?[...new Set([...i,...t])]:i.filter(e=>!s.has(e)),await Z.updateArchive(r,{tags:a.join(`, `)}),n++}catch(e){throw console.error(`Failed to update archive ${r}:`,e),Error(`Failed on archive ${r}: ${e instanceof Error?e.message:`Unknown error`}`)}return{count:n,mode:l,tags:t}},onSuccess:({count:e,mode:t,tags:a})=>{r.invalidateQueries({queryKey:[`archives`]}),i(`${t===`add`?`Added`:`Removed`} ${a.length} tag${a.length===1?``:`s`} ${t===`add`?`to`:`from`} ${e} archive${e===1?``:`s`}`),n()},onError:e=>{i(e.message||`Failed to update tags`,`error`)}}),p=e=>{c(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},m=()=>{a.trim()&&!s.has(a.trim())&&(c(e=>new Set([...e,a.trim()])),o(``))};return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,children:(0,G.jsx)(Ud,{className:`w-full max-w-md`,children:(0,G.jsxs)(Gd,{className:`p-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(wu,{className:`w-5 h-5 text-bambu-green`}),(0,G.jsx)(`h2`,{className:`text-xl font-semibold text-white`,children:l===`add`?`Add Tags`:`Remove Tags`})]}),(0,G.jsx)(`button`,{onClick:n,className:`text-bambu-gray hover:text-white transition-colors`,children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]}),(0,G.jsxs)(`div`,{className:`p-4 space-y-4`,children:[(0,G.jsxs)(`p`,{className:`text-sm text-bambu-gray`,children:[l===`add`?`Add`:`Remove`,` tags for `,e.length,` selected archive`,e.length===1?``:`s`]}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsx)(Q,{size:`sm`,variant:l===`add`?`primary`:`secondary`,onClick:()=>u(`add`),children:`Add Tags`}),(0,G.jsx)(Q,{size:`sm`,variant:l===`remove`?`primary`:`secondary`,onClick:()=>u(`remove`),children:`Remove Tags`})]}),l===`add`&&(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsx)(`input`,{type:`text`,placeholder:`Enter new tag...`,className:`flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),m())}}),(0,G.jsx)(Q,{size:`sm`,variant:`secondary`,onClick:m,disabled:!a.trim(),children:(0,G.jsx)(Ml,{className:`w-4 h-4`})})]}),t.length>0&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:`Existing tags:`}),(0,G.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:t.map(e=>(0,G.jsx)(`button`,{onClick:()=>p(e),className:`px-2 py-1 rounded text-sm transition-colors ${s.has(e)?`bg-bambu-green text-white`:`bg-bambu-dark-tertiary text-bambu-gray-light hover:bg-bambu-dark`}`,children:e},e))})]}),s.size>0&&(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:[`Tags to `,l===`add`?`add`:`remove`,`:`]}),(0,G.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:Array.from(s).map(e=>(0,G.jsxs)(`span`,{className:`px-2 py-1 rounded text-sm flex items-center gap-1 ${l===`add`?`bg-green-100 dark:bg-green-500/20 text-green-700 dark:text-green-400`:`bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400`}`,children:[e,(0,G.jsx)(`button`,{onClick:()=>p(e),className:`hover:opacity-70`,children:(0,G.jsx)(nd,{className:`w-3 h-3`})})]},e))})]})]}),(0,G.jsxs)(`div`,{className:`flex gap-3 p-4 border-t border-bambu-dark-tertiary`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:n,className:`flex-1`,children:`Cancel`}),(0,G.jsx)(Q,{onClick:()=>d.mutate(),disabled:s.size===0||d.isPending,className:`flex-1`,children:d.isPending?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),`Processing...`]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(wu,{className:`w-4 h-4`}),l===`add`?`Add Tags`:`Remove Tags`]})})]})]})})})}function vMe({selectedIds:e,onClose:t}){let{t:n}=U(),r=no(),{showToast:i}=Zd(),[a,o]=(0,f.useState)(``),{data:s,isLoading:c}=K({queryKey:[`projects`],queryFn:()=>Z.getProjects()}),l=(0,f.useMemo)(()=>s?em([...s].sort((e,t)=>e.name.localeCompare(t.name))):void 0,[s]),u=a.trim().toLowerCase(),d=u?l?.filter(e=>e.name.toLowerCase().includes(u)):l,p=(l?.length??0)>5;(0,f.useEffect)(()=>{let e=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]);let m=()=>$p(r),h=q({mutationFn:async t=>(await Z.addArchivesToProject(t,e),t),onSuccess:n=>{let r=s?.find(e=>e.id===n);m(),i(`Added ${e.length} archive${e.length===1?``:`s`} to "${r?.name}"`),t()},onError:()=>{i(`Failed to assign project`,`error`)}}),g=q({mutationFn:async()=>{for(let t of e)await Z.updateArchive(t,{project_id:null});return e.length},onSuccess:e=>{m(),i(`Removed ${e} archive${e===1?``:`s`} from project`),t()},onError:()=>{i(`Failed to remove from project`,`error`)}}),_=h.isPending||g.isPending;return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,children:(0,G.jsx)(Ud,{className:`w-full max-w-md max-h-[80vh] flex flex-col`,children:(0,G.jsxs)(Gd,{className:`p-0 flex flex-col min-h-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary shrink-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(fc,{className:`w-5 h-5 text-bambu-green`}),(0,G.jsx)(`h2`,{className:`text-xl font-semibold text-white`,children:`Assign to Project`})]}),(0,G.jsx)(`button`,{onClick:t,className:`text-bambu-gray hover:text-white transition-colors`,disabled:_,children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]}),(0,G.jsxs)(`div`,{className:`p-4 space-y-3 overflow-y-auto min-h-0`,children:[(0,G.jsxs)(`p`,{className:`text-sm text-bambu-gray`,children:[`Assign `,e.length,` selected archive`,e.length===1?``:`s`,` to a project`]}),c?(0,G.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,G.jsx)(Y,{className:`w-6 h-6 animate-spin text-bambu-gray`})}):(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsxs)(`button`,{onClick:()=>g.mutate(),disabled:_,className:`w-full flex items-center gap-3 p-3 rounded-lg bg-bambu-dark hover:bg-bambu-dark-tertiary border border-bambu-dark-tertiary transition-colors text-left disabled:opacity-50`,children:[(0,G.jsx)(`div`,{className:`w-8 h-8 rounded-full bg-red-500/20 flex items-center justify-center shrink-0`,children:(0,G.jsx)(xs,{className:`w-4 h-4 text-red-600 dark:text-red-400`})}),(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,G.jsx)(`p`,{className:`text-white font-medium`,children:`Remove from project`}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray truncate`,children:`Clear project assignment`})]}),g.isPending&&(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin text-bambu-gray shrink-0`})]}),l&&l.length>0&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2 py-2`,children:[(0,G.jsx)(`div`,{className:`flex-1 h-px bg-bambu-dark-tertiary`}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:`or assign to`}),(0,G.jsx)(`div`,{className:`flex-1 h-px bg-bambu-dark-tertiary`})]}),p&&(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(Yl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`}),(0,G.jsx)(`input`,{type:`text`,value:a,onChange:e=>o(e.target.value),placeholder:n(`archives.menu.searchProjects`),className:`w-full pl-9 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray text-sm focus:border-bambu-green focus:outline-none`})]}),d?.map(e=>(0,G.jsxs)(`button`,{onClick:()=>h.mutate(e.id),disabled:_,className:`w-full flex items-center gap-3 p-3 rounded-lg bg-bambu-dark hover:bg-bambu-dark-tertiary border border-bambu-dark-tertiary transition-colors text-left disabled:opacity-50`,children:[(0,G.jsx)(`div`,{className:`w-8 h-8 rounded-full flex items-center justify-center shrink-0`,style:{backgroundColor:e.color?`${e.color}20`:`rgb(var(--bambu-green) / 0.2)`},children:(0,G.jsx)(fc,{className:`w-4 h-4`,style:{color:e.color||`rgb(var(--bambu-green))`}})}),(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,G.jsx)(`p`,{className:`text-white font-medium truncate`,children:e.name}),(0,G.jsxs)(`p`,{className:`text-sm text-bambu-gray truncate`,children:[e.archive_count,` archive`,e.archive_count===1?``:`s`,e.status&&` • ${e.status}`]})]}),h.isPending&&h.variables===e.id&&(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin text-bambu-gray shrink-0`})]},e.id)),(!l||l.length===0)&&(0,G.jsx)(`p`,{className:`text-center text-bambu-gray py-4`,children:`No projects yet. Create one from the Projects page.`}),l&&l.length>0&&d?.length===0&&(0,G.jsx)(`p`,{className:`text-center text-bambu-gray text-sm py-4`,children:`—`})]})]}),(0,G.jsx)(`div`,{className:`flex gap-3 p-4 border-t border-bambu-dark-tertiary shrink-0`,children:(0,G.jsx)(Q,{variant:`secondary`,onClick:t,className:`flex-1`,disabled:_,children:`Cancel`})})]})})})}function yMe(e,t){return new Date(e,t+1,0).getDate()}function bMe(e,t){return new Date(e,t,1).getDay()}var xMe=[`January`,`February`,`March`,`April`,`May`,`June`,`July`,`August`,`September`,`October`,`November`,`December`],SMe=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`];function CMe({archives:e,onArchiveClick:t,highlightedArchiveId:n}){let r=new Date,[i,a]=(0,f.useState)(r.getMonth()),[o,s]=(0,f.useState)(r.getFullYear()),[c,l]=(0,f.useState)(null),[u,d]=(0,f.useState)(null),p=(0,f.useMemo)(()=>{let t=new Map;return e.forEach(e=>{let n=sp(e.completed_at||e.created_at)||new Date,r=`${n.getFullYear()}-${String(n.getMonth()+1).padStart(2,`0`)}-${String(n.getDate()).padStart(2,`0`)}`,i=t.get(r)||[];i.push(e),t.set(r,i)}),t},[e]),m=yMe(o,i),h=bMe(o,i),g=()=>{i===0?(a(11),s(o-1)):a(i-1)},_=()=>{i===11?(a(0),s(o+1)):a(i+1)},v=()=>{a(r.getMonth()),s(r.getFullYear())},y=[];for(let e=0;e{e!==c&&d(null),l(e)};return(0,G.jsxs)(`div`,{className:`flex flex-col lg:flex-row gap-6`,children:[(0,G.jsxs)(`div`,{className:`flex-1`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-4`,children:[(0,G.jsx)(`button`,{onClick:g,className:`p-2 hover:bg-bambu-dark-tertiary rounded-lg transition-colors`,children:(0,G.jsx)(ls,{className:`w-5 h-5 text-bambu-gray`})}),(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white`,children:[xMe[i],` `,o]}),(0,G.jsx)(`button`,{onClick:v,className:`px-2 py-1 text-xs bg-bambu-dark-tertiary hover:bg-bambu-green/20 text-bambu-gray hover:text-white rounded transition-colors`,children:`Today`})]}),(0,G.jsx)(`button`,{onClick:_,className:`p-2 hover:bg-bambu-dark-tertiary rounded-lg transition-colors`,children:(0,G.jsx)(cs,{className:`w-5 h-5 text-bambu-gray`})})]}),(0,G.jsx)(`div`,{className:`grid grid-cols-7 gap-1 mb-1`,children:SMe.map(e=>(0,G.jsx)(`div`,{className:`text-center text-xs text-bambu-gray py-2`,children:e},e))}),(0,G.jsx)(`div`,{className:`grid grid-cols-7 gap-1`,children:y.map((e,t)=>{if(e===null)return(0,G.jsx)(`div`,{className:`aspect-square`},`empty-${t}`);let n=`${o}-${String(i+1).padStart(2,`0`)}-${String(e).padStart(2,`0`)}`,a=p.get(n)||[],s=a.length>0,l=e===r.getDate()&&i===r.getMonth()&&o===r.getFullYear(),u=n===c,d=a.filter(e=>e.status===`completed`).length,f=a.filter(e=>e.status===`failed`).length;return(0,G.jsxs)(`button`,{onClick:()=>x(u?null:n),className:`aspect-square rounded-lg p-1 flex flex-col items-center justify-center transition-colors relative ${u?`bg-bambu-green text-white`:l?`bg-bambu-green/20 text-white ring-2 ring-bambu-green`:s?`bg-bambu-dark-tertiary hover:bg-bambu-dark-tertiary/70 text-white`:`hover:bg-bambu-dark-tertiary/50 text-bambu-gray`}`,children:[(0,G.jsx)(`span`,{className:`text-sm font-medium ${l&&!u?`text-bambu-green`:``}`,children:e}),s&&(0,G.jsxs)(`div`,{className:`absolute bottom-1 left-1/2 -translate-x-1/2 flex items-center gap-1`,children:[(0,G.jsx)(`div`,{className:`w-2 h-2 rounded-full ${f>0&&d===0?`bg-red-400`:f>0?`bg-yellow-400`:`bg-green-400`}`}),(0,G.jsx)(`span`,{className:`text-xs font-medium`,children:a.length})]})]},e)})}),(0,G.jsx)(`div`,{className:`mt-4 pt-4 border-t border-bambu-dark-tertiary`,children:(0,G.jsxs)(`div`,{className:`grid grid-cols-3 gap-4 text-center`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`div`,{className:`text-2xl font-bold text-white`,children:e.filter(e=>{let t=sp(e.completed_at||e.created_at)||new Date;return t.getMonth()===i&&t.getFullYear()===o}).length}),(0,G.jsx)(`div`,{className:`text-xs text-bambu-gray`,children:`Prints this month`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`div`,{className:`text-2xl font-bold text-green-700 dark:text-green-400`,children:e.filter(e=>{let t=sp(e.completed_at||e.created_at)||new Date;return t.getMonth()===i&&t.getFullYear()===o&&e.status===`completed`}).length}),(0,G.jsx)(`div`,{className:`text-xs text-bambu-gray`,children:`Successful`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`div`,{className:`text-2xl font-bold text-red-700 dark:text-red-400`,children:e.filter(e=>{let t=sp(e.completed_at||e.created_at)||new Date;return t.getMonth()===i&&t.getFullYear()===o&&e.status===`failed`}).length}),(0,G.jsx)(`div`,{className:`text-xs text-bambu-gray`,children:`Failed`})]})]})})]}),(0,G.jsx)(`div`,{className:`lg:w-80 bg-bambu-dark rounded-xl p-4`,children:c?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`h3`,{className:`text-sm font-medium text-bambu-gray mb-3`,children:new Date(c+`T12:00:00`).toLocaleDateString(`en-US`,{weekday:`long`,month:`long`,day:`numeric`,year:`numeric`})}),b.length>0?(0,G.jsx)(`div`,{className:`calendar-scroll space-y-2 max-h-96 overflow-y-auto`,children:b.map(e=>{let r=e.id===u||e.id===n;return(0,G.jsxs)(`button`,{onClick:()=>{d(e.id),t?.(e)},className:`w-full flex items-center gap-3 p-2 rounded-lg transition-colors text-left ${r?``:`hover:bg-bambu-dark-tertiary`}`,style:r?{outline:`4px solid #facc15`,outlineOffset:`2px`}:void 0,children:[e.thumbnail_path?(0,G.jsx)(`img`,{src:Z.getArchiveThumbnail(e.id),alt:``,className:`w-12 h-12 rounded object-cover`}):(0,G.jsx)(`div`,{className:`w-12 h-12 rounded bg-bambu-dark-tertiary flex items-center justify-center`,children:(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:`3MF`})}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`p`,{className:`text-sm text-white truncate`,children:e.print_name||e.filename}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-xs`,children:[(0,G.jsx)(`span`,{className:e.status===`failed`?`text-red-700 dark:text-red-400`:`text-green-700 dark:text-green-400`,children:e.status===`failed`?`Failed`:`Completed`}),e.filament_color&&(0,G.jsx)(`div`,{className:`flex gap-0.5`,children:e.filament_color.split(`,`).map((e,t)=>(0,G.jsx)(`div`,{className:`w-3 h-3 rounded-full border border-black/20`,style:{backgroundColor:e}},t))})]})]})]},e.id)})}):(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:`No prints on this day`})]}):(0,G.jsx)(`div`,{className:`text-center py-8`,children:(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:`Select a day to see prints`})})})]})}function YW({archiveId:e,archiveName:t,onClose:n}){let r=Z.getArchiveQRCodeUrl(e,300);return(0,f.useEffect)(()=>{let e=e=>{e.key===`Escape`&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[n]),(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:n,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-sm`,onClick:e=>e.stopPropagation(),children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:`QR Code`}),(0,G.jsx)(`button`,{onClick:n,className:`text-bambu-gray hover:text-white transition-colors`,children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]}),(0,G.jsxs)(`div`,{className:`p-6 flex flex-col items-center`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4 text-center truncate max-w-full`,children:t}),(0,G.jsx)(`div`,{className:`bg-white p-4 rounded-lg mb-4`,children:(0,G.jsx)(`img`,{src:r,alt:`QR Code`,className:`w-64 h-64`})}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mb-4 text-center`,children:`Scan to open this archive`}),(0,G.jsxs)(Q,{onClick:()=>{let e=document.createElement(`a`);e.href=r,e.download=`${t}_qrcode.png`,e.click()},className:`w-full`,children:[(0,G.jsx)(Gs,{className:`w-4 h-4`}),`Download QR Code`]})]})]})})}function XW(e){let{archiveName:t,photos:n,initialIndex:r,onClose:i,onDelete:a}=e,[o,s]=(0,f.useState)(()=>Math.min(Math.max(r??0,0),Math.max(n.length-1,0))),[c,l]=(0,f.useState)(!1);if((0,f.useEffect)(()=>{if(c)return;let e=e=>{e.key===`Escape`&&i(),e.key===`ArrowLeft`&&s(e=>Math.max(0,e-1)),e.key===`ArrowRight`&&s(e=>Math.min(n.length-1,e+1))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[i,n.length,c]),(0,f.useEffect)(()=>{o>=n.length&&s(Math.max(0,n.length-1))},[n.length,o]),n.length===0)return i(),null;let u=t=>e.getPhotoUrl?e.getPhotoUrl(t):Z.getArchivePhotoUrl(e.archiveId,t),d=n[o],p=u(d);return(0,G.jsxs)(`div`,{className:`fixed inset-0 bg-black/90 flex items-center justify-center z-50`,onClick:e=>{e.stopPropagation(),i()},children:[(0,G.jsxs)(`div`,{className:`relative w-full h-full flex flex-col`,onClick:e=>e.stopPropagation(),children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 bg-black/50`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:t}),(0,G.jsxs)(`p`,{className:`text-sm text-bambu-gray`,children:[`Photo `,o+1,` of `,n.length]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:()=>{let e=document.createElement(`a`);e.href=p,e.download=`${t}_photo_${o+1}.jpg`,e.click()},children:[(0,G.jsx)(Gs,{className:`w-4 h-4`}),`Download`]}),a&&(0,G.jsx)(Q,{variant:`secondary`,size:`sm`,onClick:()=>{a&&l(!0)},className:`text-red-400 hover:text-red-300`,children:(0,G.jsx)(Pu,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:i,className:`p-2 text-bambu-gray hover:text-white transition-colors`,children:(0,G.jsx)(nd,{className:`w-6 h-6`})})]})]}),(0,G.jsxs)(`div`,{className:`flex-1 min-h-0 flex items-center justify-center p-4 relative overflow-hidden`,children:[o>0&&(0,G.jsx)(`button`,{onClick:()=>s(e=>e-1),className:`absolute left-4 z-10 p-3 bg-black/50 hover:bg-black/70 rounded-full transition-colors`,children:(0,G.jsx)(ls,{className:`w-8 h-8 text-white`})}),(0,G.jsx)(`img`,{src:p,alt:`Photo ${o+1}`,className:`max-w-full max-h-full object-contain rounded-lg`,style:{maxHeight:`calc(100vh - 200px)`}}),os(e=>e+1),className:`absolute right-4 z-10 p-3 bg-black/50 hover:bg-black/70 rounded-full transition-colors`,children:(0,G.jsx)(cs,{className:`w-8 h-8 text-white`})})]}),n.length>1&&(0,G.jsx)(`div`,{className:`flex justify-center gap-2 p-4 bg-black/50`,children:n.map((e,t)=>(0,G.jsx)(`button`,{onClick:()=>s(t),className:`w-16 h-16 rounded-lg overflow-hidden border-2 transition-colors ${t===o?`border-bambu-green`:`border-transparent hover:border-bambu-gray`}`,children:(0,G.jsx)(`img`,{src:u(e),alt:`Thumbnail ${t+1}`,className:`w-full h-full object-cover`})},e))})]}),c&&(0,G.jsx)(`div`,{onClick:e=>e.stopPropagation(),children:(0,G.jsx)(uf,{title:`Delete Photo`,message:`Delete this photo? This cannot be undone.`,confirmText:`Delete`,variant:`danger`,onConfirm:()=>{a?.(d),l(!1)},onCancel:()=>l(!1)})})]})}function ZW(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n`u`?null:xG(BigInt.prototype.toString),gG=typeof Symbol>`u`?null:xG(Symbol.prototype.toString),_G=xG(Object.prototype.hasOwnProperty),vG=xG(Object.prototype.toString),yG=xG(RegExp.prototype.test),bG=LMe(TypeError);function xG(e){return function(t){t instanceof RegExp&&(t.lastIndex=0);var n=[...arguments].slice(1);return iG(e,t,n)}}function LMe(e){return function(){return aG(e,[...arguments])}}function SG(e,t){let n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:uG;if($W&&$W(e,null),!lG(t))return e;let r=t.length;for(;r--;){let i=t[r];if(typeof i==`string`){let e=n(i);e!==i&&(kMe(t)||(t[r]=e),i=e)}e[i]=!0}return e}function RMe(e){for(let t=0;t/g),GMe=tG(/\${[\w\W]*/g),KMe=tG(/^data-[\-\w.\u00B7-\uFFFF]+$/),qMe=tG(/^aria-[\-\w]+$/),PG=tG(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i),JMe=tG(/^(?:\w+script|data):/i),YMe=tG(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g),XMe=tG(/^html$/i),ZMe=tG(/^[a-z][.\w]*(-[.\w]+)+$/i),FG=tG(/<[/\w!]/g),IG=tG(/<[/\w]/g),QMe=tG(/<\/no(script|embed|frames)/i),$Me=tG(/\/>/i),LG={element:1,attribute:2,text:3,cdataSection:4,entityReference:5,entityNode:6,processingInstruction:7,comment:8,document:9,documentType:10,documentFragment:11,notation:12},eNe=function(){return typeof window>`u`?null:window},tNe=function(e,t){if(typeof e!=`object`||typeof e.createPolicy!=`function`)return null;let n=null,r=`data-tt-policy-suffix`;t&&t.hasAttribute(r)&&(n=t.getAttribute(r));let i=`dompurify`+(n?`#`+n:``);try{return e.createPolicy(i,{createHTML(e){return e},createScriptURL(e){return e}})}catch{return console.warn(`TrustedTypes policy `+i+` could not be created.`),null}},RG=function(){return{afterSanitizeAttributes:[],afterSanitizeElements:[],afterSanitizeShadowDOM:[],beforeSanitizeAttributes:[],beforeSanitizeElements:[],beforeSanitizeShadowDOM:[],uponSanitizeAttribute:[],uponSanitizeElement:[],uponSanitizeShadowNode:[]}},zG=function(e,t,n,r){return _G(e,t)&&lG(e[t])?SG(r.base?CG(r.base):{},e[t],r.transform):n};function BG(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:eNe(),t=e=>BG(e);if(t.version=`3.4.13`,t.removed=[],!e||!e.document||e.document.nodeType!==LG.document||!e.Element)return t.isSupported=!1,t;let n=e.document,r=n,i=r.currentScript;e.DocumentFragment;let a=e.HTMLTemplateElement,o=e.Node,s=e.Element,c=e.NodeFilter;e.NamedNodeMap===void 0&&(e.NamedNodeMap||e.MozNamedAttrMap),e.HTMLFormElement;let l=e.DOMParser,u=e.trustedTypes,d=s.prototype,f=wG(d,`cloneNode`),p=wG(d,`remove`),m=wG(d,`nextSibling`),h=wG(d,`childNodes`),g=wG(d,`parentNode`),_=wG(d,`shadowRoot`),v=wG(d,`attributes`),y=o&&o.prototype?wG(o.prototype,`nodeType`):null,b=o&&o.prototype?wG(o.prototype,`nodeName`):null,x=o&&o.prototype?wG(o.prototype,`ownerDocument`):null;if(typeof a==`function`){let e=n.createElement(`template`);e.content&&e.content.ownerDocument&&(n=e.content.ownerDocument)}let S,C=``,w,T=!1,E=0,D=function(){if(E>0)throw bG(`A configured TRUSTED_TYPES_POLICY callback (createHTML or createScriptURL) must not call DOMPurify.sanitize, as that causes infinite recursion. Do not pass a policy whose callbacks wrap DOMPurify as TRUSTED_TYPES_POLICY; see the "DOMPurify and Trusted Types" section of the README.`)},O=function(e){D(),E++;try{return S.createHTML(e)}finally{E--}},k=function(e){D(),E++;try{return S.createScriptURL(e)}finally{E--}},A=function(){return T||=(w=tNe(u,i),!0),w},j=n,M=j.implementation,N=j.createNodeIterator,P=j.createDocumentFragment,F=j.getElementsByTagName,I=r.importNode,L=RG();t.isSupported=typeof QW==`function`&&typeof g==`function`&&M&&M.createHTMLDocument!==void 0;let R=UMe,z=WMe,B=GMe,V=KMe,ee=qMe,te=JMe,ne=YMe,re=ZMe,ie=PG,ae=null,oe=SG({},[...TG,...EG,...DG,...OG,...kG]),se=null,H=SG({},[...AG,...jG,...MG,...NG]),ce=Object.seal(nG(null,{tagNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},allowCustomizedBuiltInElements:{writable:!0,configurable:!1,enumerable:!0,value:!1}})),le=null,ue=null,de=Object.seal(nG(null,{tagCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeCheck:{writable:!0,configurable:!1,enumerable:!0,value:null}})),fe=!0,pe=!0,me=!1,he=!0,ge=!1,_e=!0,ve=!1,ye=!1,be=null,xe=null,Se=!1,Ce=!1,we=!1,Te=!1,Ee=!0,De=!1,Oe=`user-content-`,ke=!0,Ae=!1,je={},Me=null,Ne=SG({},`annotation-xml.audio.colgroup.desc.foreignobject.head.iframe.math.mi.mn.mo.ms.mtext.noembed.noframes.noscript.plaintext.script.selectedcontent.style.svg.template.thead.title.video.xmp`.split(`.`)),Pe=null,Fe=SG({},[`audio`,`video`,`img`,`source`,`image`,`track`]),Ie=null,Le=SG({},[`alt`,`class`,`for`,`id`,`label`,`name`,`pattern`,`placeholder`,`role`,`summary`,`title`,`value`,`style`,`xmlns`]),Re=`http://www.w3.org/1998/Math/MathML`,ze=`http://www.w3.org/2000/svg`,Be=`http://www.w3.org/1999/xhtml`,Ve=Be,He=!1,Ue=null,We=SG({},[Re,ze,Be],dG),Ge=eG([`mi`,`mo`,`mn`,`ms`,`mtext`]),Ke=SG({},Ge),qe=eG([`annotation-xml`]),U=SG({},qe),Je=SG({},[`title`,`style`,`font`,`a`,`script`]),Ye=null,Xe=[`application/xhtml+xml`,`text/html`],Ze=null,Qe=null,$e=n.createElement(`form`),et=function(e){return e instanceof RegExp||e instanceof Function},tt=function(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if(Qe&&Qe===e)return;(!e||typeof e!=`object`)&&(e={}),e=CG(e),Ye=Xe.indexOf(e.PARSER_MEDIA_TYPE)===-1?`text/html`:e.PARSER_MEDIA_TYPE,Ze=Ye===`application/xhtml+xml`?dG:uG,ae=zG(e,`ALLOWED_TAGS`,oe,{transform:Ze}),se=zG(e,`ALLOWED_ATTR`,H,{transform:Ze}),Ue=zG(e,`ALLOWED_NAMESPACES`,We,{transform:dG}),Ie=zG(e,`ADD_URI_SAFE_ATTR`,Le,{transform:Ze,base:Le}),Pe=zG(e,`ADD_DATA_URI_TAGS`,Fe,{transform:Ze,base:Fe}),Me=zG(e,`FORBID_CONTENTS`,Ne,{transform:Ze}),le=zG(e,`FORBID_TAGS`,CG({}),{transform:Ze}),ue=zG(e,`FORBID_ATTR`,CG({}),{transform:Ze}),je=_G(e,`USE_PROFILES`)?e.USE_PROFILES&&typeof e.USE_PROFILES==`object`?CG(e.USE_PROFILES):e.USE_PROFILES:!1,fe=e.ALLOW_ARIA_ATTR!==!1,pe=e.ALLOW_DATA_ATTR!==!1,me=e.ALLOW_UNKNOWN_PROTOCOLS||!1,he=e.ALLOW_SELF_CLOSE_IN_ATTR!==!1,ge=e.SAFE_FOR_TEMPLATES||!1,_e=e.SAFE_FOR_XML!==!1,ve=e.WHOLE_DOCUMENT||!1,Ce=e.RETURN_DOM||!1,we=e.RETURN_DOM_FRAGMENT||!1,Te=e.RETURN_TRUSTED_TYPE||!1,Se=e.FORCE_BODY||!1,Ee=e.SANITIZE_DOM!==!1,De=e.SANITIZE_NAMED_PROPS||!1,ke=e.KEEP_CONTENT!==!1,Ae=e.IN_PLACE||!1,ie=BMe(e.ALLOWED_URI_REGEXP)?e.ALLOWED_URI_REGEXP:PG,Ve=typeof e.NAMESPACE==`string`?e.NAMESPACE:Be,Ke=_G(e,`MATHML_TEXT_INTEGRATION_POINTS`)&&e.MATHML_TEXT_INTEGRATION_POINTS&&typeof e.MATHML_TEXT_INTEGRATION_POINTS==`object`?CG(e.MATHML_TEXT_INTEGRATION_POINTS):SG({},Ge),U=_G(e,`HTML_INTEGRATION_POINTS`)&&e.HTML_INTEGRATION_POINTS&&typeof e.HTML_INTEGRATION_POINTS==`object`?CG(e.HTML_INTEGRATION_POINTS):SG({},qe);let t=_G(e,`CUSTOM_ELEMENT_HANDLING`)&&e.CUSTOM_ELEMENT_HANDLING&&typeof e.CUSTOM_ELEMENT_HANDLING==`object`?CG(e.CUSTOM_ELEMENT_HANDLING):nG(null);if(ce=nG(null),_G(t,`tagNameCheck`)&&et(t.tagNameCheck)&&(ce.tagNameCheck=t.tagNameCheck),_G(t,`attributeNameCheck`)&&et(t.attributeNameCheck)&&(ce.attributeNameCheck=t.attributeNameCheck),_G(t,`allowCustomizedBuiltInElements`)&&typeof t.allowCustomizedBuiltInElements==`boolean`&&(ce.allowCustomizedBuiltInElements=t.allowCustomizedBuiltInElements),tG(ce),ge&&(pe=!1),we&&(Ce=!0),je&&(ae=SG({},kG),se=nG(null),je.html===!0&&(SG(ae,TG),SG(se,AG)),je.svg===!0&&(SG(ae,EG),SG(se,jG),SG(se,NG)),je.svgFilters===!0&&(SG(ae,DG),SG(se,jG),SG(se,NG)),je.mathMl===!0&&(SG(ae,OG),SG(se,MG),SG(se,NG))),de.tagCheck=null,de.attributeCheck=null,_G(e,`ADD_TAGS`)&&(typeof e.ADD_TAGS==`function`?de.tagCheck=e.ADD_TAGS:lG(e.ADD_TAGS)&&(ae===oe&&(ae=CG(ae)),SG(ae,e.ADD_TAGS,Ze))),_G(e,`ADD_ATTR`)&&(typeof e.ADD_ATTR==`function`?de.attributeCheck=e.ADD_ATTR:lG(e.ADD_ATTR)&&(se===H&&(se=CG(se)),SG(se,e.ADD_ATTR,Ze))),_G(e,`ADD_URI_SAFE_ATTR`)&&lG(e.ADD_URI_SAFE_ATTR)&&SG(Ie,e.ADD_URI_SAFE_ATTR,Ze),_G(e,`FORBID_CONTENTS`)&&lG(e.FORBID_CONTENTS)&&(Me===Ne&&(Me=CG(Me)),SG(Me,e.FORBID_CONTENTS,Ze)),_G(e,`ADD_FORBID_CONTENTS`)&&lG(e.ADD_FORBID_CONTENTS)&&(Me===Ne&&(Me=CG(Me)),SG(Me,e.ADD_FORBID_CONTENTS,Ze)),ke&&(ae[`#text`]=!0),ve&&SG(ae,[`html`,`head`,`body`]),ae.table&&(SG(ae,[`tbody`]),delete le.tbody),e.TRUSTED_TYPES_POLICY){if(typeof e.TRUSTED_TYPES_POLICY.createHTML!=`function`)throw bG(`TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.`);if(typeof e.TRUSTED_TYPES_POLICY.createScriptURL!=`function`)throw bG(`TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.`);let t=S;S=e.TRUSTED_TYPES_POLICY;try{C=O(``)}catch(e){throw S=t,e}}else e.TRUSTED_TYPES_POLICY===null?(S=void 0,C=``):(S===void 0&&(S=A()),S&&typeof C==`string`&&(C=O(``)));eG&&eG(e),Qe=e},nt=SG({},[...EG,...DG,...VMe]),rt=SG({},[...OG,...HMe]),it=function(e,t,n){return t.namespaceURI===Be?e===`svg`:t.namespaceURI===Re?e===`svg`&&(n===`annotation-xml`||Ke[n]):!!nt[e]},at=function(e,t,n){return t.namespaceURI===Be?e===`math`:t.namespaceURI===ze?e===`math`&&U[n]:!!rt[e]},ot=function(e,t,n){return t.namespaceURI===ze&&!U[n]||t.namespaceURI===Re&&!Ke[n]?!1:!rt[e]&&(Je[e]||!nt[e])},st=function(e){let t=g(e);(!t||!t.tagName)&&(t={namespaceURI:Ve,tagName:`template`});let n=uG(e.tagName),r=uG(t.tagName);return Ue[e.namespaceURI]?e.namespaceURI===ze?it(n,t,r):e.namespaceURI===Re?at(n,t,r):e.namespaceURI===Be?ot(n,t,r):!!(Ye===`application/xhtml+xml`&&Ue[e.namespaceURI]):!1},ct=function(e){cG(t.removed,{element:e});try{g(e).removeChild(e)}catch{if(p(e),!g(e))throw bG(`a node selected for removal could not be detached from its tree and cannot be safely returned; refusing to sanitize in place`)}},lt=function(e){ft(e);let t=h(e);if(t){let e=[];oG(t,t=>{cG(e,t)}),oG(e,e=>{try{p(e)}catch{}})}let n=v(e);if(n)for(let t=n.length-1;t>=0;--t){let r=n[t],i=r&&r.name;if(typeof i==`string`)try{e.removeAttribute(i)}catch{}}},ut=function(e,n){try{cG(t.removed,{attribute:n.getAttributeNode(e),from:n})}catch{cG(t.removed,{attribute:null,from:n})}if(n.removeAttribute(e),e===`is`)if(Ce||we)try{ct(n)}catch{}else try{n.setAttribute(e,``)}catch{}},dt=function(e){let t=v(e);if(t)for(let n=t.length-1;n>=0;--n){let r=t[n],i=r&&r.name;if(!(typeof i!=`string`||se[Ze(i)]))try{e.removeAttribute(i)}catch{}}},ft=function(e){let t=[e];for(;t.length>0;){let e=t.pop();(y?y(e):e.nodeType)===LG.element&&dt(e);let n=h(e);if(n)for(let e=n.length-1;e>=0;--e)t.push(n[e])}},pt=function(e){if(!_e)return;let t=[e];for(;t.length>0;){let e=t.pop(),n=y?y(e):e.nodeType;if(n===LG.processingInstruction||n===LG.comment&&yG(IG,e.data)){try{p(e)}catch{}continue}if(n===LG.element){let t=e,n=Ze(b?b(e):e.nodeName);try{t.hasAttribute&&t.hasAttribute(`patchsrc`)&&t.removeAttribute(`patchsrc`),t.hasAttribute&&t.hasAttribute(`for`)&&n!==`label`&&n!==`output`&&t.removeAttribute(`for`)}catch{}}let r=h(e);if(r)for(let e=r.length-1;e>=0;--e)t.push(r[e])}},mt=function(e){let t=null,r=null;if(Se)e=``+e;else{let t=fG(e,/^[\r\n\t ]+/);r=t&&t[0]}Ye===`application/xhtml+xml`&&Ve===Be&&(e=``+e+``);let i=S?O(e):e;if(Ve===Be)try{t=new l().parseFromString(i,Ye)}catch{}if(!t||!t.documentElement){t=M.createDocument(Ve,`template`,null);try{t.documentElement.innerHTML=He?C:i}catch{}}let a=t.body||t.documentElement;return e&&r&&a.insertBefore(n.createTextNode(r),a.childNodes[0]||null),Ve===Be?F.call(t,ve?`html`:`body`)[0]:ve?t.documentElement:a},ht=function(e){let t=x?x(e):e.ownerDocument;return N.call(t||e,e,c.SHOW_ELEMENT|c.SHOW_COMMENT|c.SHOW_TEXT|c.SHOW_PROCESSING_INSTRUCTION|c.SHOW_CDATA_SECTION,null)},gt=function(e){return e=pG(e,R,` `),e=pG(e,z,` `),e=pG(e,B,` `),e},_t=function(e){e.normalize();let t=x?x(e):e.ownerDocument,n=N.call(t||e,e,c.SHOW_TEXT|c.SHOW_COMMENT|c.SHOW_CDATA_SECTION|c.SHOW_PROCESSING_INSTRUCTION,null),r=n.nextNode();for(;r;)r.data=gt(r.data),r=n.nextNode();let i=e.querySelectorAll?.call(e,`template`);i&&oG(i,e=>{yt(e.content)&&_t(e.content)})},vt=function(e){let t=b?b(e):null;return typeof t!=`string`||Ze(t)!==`form`?!1:typeof e.nodeName!=`string`||typeof e.textContent!=`string`||typeof e.removeChild!=`function`||e.attributes!==v(e)||typeof e.removeAttribute!=`function`||typeof e.setAttribute!=`function`||typeof e.namespaceURI!=`string`||typeof e.insertBefore!=`function`||typeof e.hasChildNodes!=`function`||e.nodeType!==y(e)||e.childNodes!==h(e)},yt=function(e){if(!y||typeof e!=`object`||!e)return!1;try{return y(e)===LG.documentFragment}catch{return!1}},bt=function(e){if(!y||typeof e!=`object`||!e)return!1;try{return typeof y(e)==`number`}catch{return!1}};function xt(e,n,r){e.length!==0&&oG(e,e=>{e.call(t,n,r,Qe)})}let St=function(e,t){return!!(_e&&e.hasChildNodes()&&!bt(e.firstElementChild)&&yG(FG,e.textContent)&&yG(FG,e.innerHTML)||_e&&e.namespaceURI===Be&&t===`style`&&bt(e.firstElementChild)||e.nodeType===LG.processingInstruction||_e&&e.nodeType===LG.comment&&yG(IG,e.data))},Ct=function(e,t,n){if(!le[t]&&Ot(t)&&(ce.tagNameCheck instanceof RegExp&&yG(ce.tagNameCheck,t)||ce.tagNameCheck instanceof Function&&ce.tagNameCheck(t)))return!1;if(ke&&!Me[t]){let t=g(e),r=h(e);if(r&&t){let i=r.length;for(let a=i-1;a>=0;--a){let i=e===n?f(r[a],!0):r[a];t.insertBefore(i,m(e))}}}return ct(e),!0},wt=function(e,t,n,r){return e.length===0?t:t===n||t===r?CG(t):t},Tt=function(e,n){if(xt(L.beforeSanitizeElements,e,null),e!==n&&g(e)===null)return Ae&&ft(e),!0;if(vt(e))return ct(e),!0;let r=Ze(b?b(e):e.nodeName);if(ae=wt(L.uponSanitizeElement,ae,oe,be),xt(L.uponSanitizeElement,e,{tagName:r,allowedTags:ae}),e!==n&&g(e)===null)return Ae&&ft(e),!0;if(St(e,r))return ct(e),!0;if(le[r]||!(de.tagCheck instanceof Function&&de.tagCheck(r))&&!ae[r]){let t=Ct(e,r,n);return t===!1&&xt(L.afterSanitizeElements,e,null),t}if((y?y(e):e.nodeType)===LG.element&&!st(e)||(r===`noscript`||r===`noembed`||r===`noframes`)&&yG(QMe,e.innerHTML))return ct(e),!0;if(ge&&e.nodeType===LG.text){let n=gt(e.textContent);e.textContent!==n&&(cG(t.removed,{element:e.cloneNode()}),e.textContent=n)}return xt(L.afterSanitizeElements,e,null),!1},Et=function(e,t,r){if(ue[t]||_e&&t===`patchsrc`||_e&&t===`for`&&e!==`label`&&e!==`output`||Ee&&(t===`id`||t===`name`)&&(r in n||r in $e))return!1;let i=se[t]||de.attributeCheck instanceof Function&&de.attributeCheck(t,e);if(!(pe&&yG(V,t))&&!(fe&&yG(ee,t))){if(!i){if(!(Ot(e)&&(ce.tagNameCheck instanceof RegExp&&yG(ce.tagNameCheck,e)||ce.tagNameCheck instanceof Function&&ce.tagNameCheck(e))&&(ce.attributeNameCheck instanceof RegExp&&yG(ce.attributeNameCheck,t)||ce.attributeNameCheck instanceof Function&&ce.attributeNameCheck(t,e))||t===`is`&&ce.allowCustomizedBuiltInElements&&(ce.tagNameCheck instanceof RegExp&&yG(ce.tagNameCheck,r)||ce.tagNameCheck instanceof Function&&ce.tagNameCheck(r))))return!1}else if(!Ie[t]&&!yG(ie,pG(r,ne,``))&&!((t===`src`||t===`xlink:href`||t===`href`)&&e!==`script`&&mG(r,`data:`)===0&&Pe[e])&&!(me&&!yG(te,pG(r,ne,``)))&&r)return!1}return!0},Dt=SG({},[`annotation-xml`,`color-profile`,`font-face`,`font-face-format`,`font-face-name`,`font-face-src`,`font-face-uri`,`missing-glyph`]),Ot=function(e){return!Dt[uG(e)]&&yG(re,e)},kt=function(e,t,n,r){if(S&&typeof u==`object`&&typeof u.getAttributeType==`function`&&!n)switch(u.getAttributeType(e,t)){case`TrustedHTML`:return O(r);case`TrustedScriptURL`:return k(r)}return r},At=function(e,n,r,i){try{r?e.setAttributeNS(r,n,i):e.setAttribute(n,i),vt(e)?ct(e):sG(t.removed)}catch{ut(n,e)}},jt=function(e){xt(L.beforeSanitizeAttributes,e,null);let t=e.attributes;if(!t||vt(e))return;se=wt(L.uponSanitizeAttribute,se,H,xe);let n={attrName:``,attrValue:``,keepAttr:!0,allowedAttributes:se,forceKeepAttr:void 0},r=t.length,i=Ze(e.nodeName);for(;r--;){let a=t[r],o=a.name,s=a.namespaceURI,c=a.value,l=Ze(o),u=c,d=o===`value`?u:PMe(u);if(n.attrName=l,n.attrValue=d,n.keepAttr=!0,n.forceKeepAttr=void 0,xt(L.uponSanitizeAttribute,e,n),d=n.attrValue,De&&(l===`id`||l===`name`)&&mG(d,Oe)!==0&&(ut(o,e),d=Oe+d),_e&&yG(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i,d)){ut(o,e);continue}if(l===`attributename`&&fG(d,`href`)){ut(o,e);continue}if(!n.forceKeepAttr){if(!n.keepAttr){ut(o,e);continue}if(!he&&yG($Me,d)){ut(o,e);continue}if(ge&&(d=gt(d)),!Et(i,l,d)){ut(o,e);continue}d=kt(i,l,s,d),d!==u&&At(e,o,s,d)}}xt(L.afterSanitizeAttributes,e,null)},Mt=function(e){let t=null,n=ht(e);for(xt(L.beforeSanitizeShadowDOM,e,null);t=n.nextNode();)if(xt(L.uponSanitizeShadowNode,t,null),Tt(t,e),jt(t),yt(t.content)&&Mt(t.content),(y?y(t):t.nodeType)===LG.element){let e=_(t);yt(e)&&(Nt(e),Mt(e))}xt(L.afterSanitizeShadowDOM,e,null)},Nt=function(e){let t=[{node:e,shadow:null}];for(;t.length>0;){let e=t.pop();if(e.shadow){Mt(e.shadow);continue}let n=e.node,r=(y?y(n):n.nodeType)===LG.element,i=h(n);if(i)for(let e=i.length-1;e>=0;--e)t.push({node:i[e],shadow:null});if(r){let e=b?b(n):null;if(typeof e==`string`&&Ze(e)===`template`){let e=n.content;yt(e)&&t.push({node:e,shadow:null})}}if(r){let e=_(n);yt(e)&&t.push({node:null,shadow:e},{node:e,shadow:null})}}};return t.sanitize=function(e){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},i=null,a=null,o=null,s=null;if(He=!e,He&&(e=``),typeof e!=`string`&&!bt(e)&&(e=zMe(e),typeof e!=`string`))throw bG(`dirty is not a string, aborting`);if(!t.isSupported)return e;ye?(ae=be,se=xe):tt(n),(L.uponSanitizeElement.length>0||L.uponSanitizeAttribute.length>0)&&(ae=CG(ae)),L.uponSanitizeAttribute.length>0&&(se=CG(se)),t.removed=[];let c=Ae&&typeof e!=`string`&&bt(e);if(c){pt(e);let t=b?b(e):e.nodeName;if(typeof t==`string`){let n=Ze(t);if(!ae[n]||le[n])throw lt(e),bG(`root node is forbidden and cannot be sanitized in-place`)}if(vt(e))throw lt(e),bG(`root node is clobbered and cannot be sanitized in-place`);try{Nt(e)}catch(t){throw lt(e),t}}else if(bt(e))i=mt(``),a=i.ownerDocument.importNode(e,!0),a.nodeType===LG.element&&a.nodeName===`BODY`||a.nodeName===`HTML`?i=a:i.appendChild(a),Nt(a);else{if(!Ce&&!ge&&!ve&&e.indexOf(`<`)===-1)return S&&Te?O(e):e;if(i=mt(e),!i)return Ce?null:Te?C:``}i&&Se&&ct(i.firstChild);let l=c?e:i;try{let e=ht(l);for(;o=e.nextNode();)Tt(o,l),jt(o),yt(o.content)&&Mt(o.content)}catch(n){throw c&&(lt(e),oG(t.removed,e=>{e.element&&ft(e.element)})),n}if(c)return oG(t.removed,e=>{e.element&&ft(e.element)}),ge&&_t(e),e;if(Ce){if(ge&&_t(i),we)for(s=P.call(i.ownerDocument);i.firstChild;)s.appendChild(i.firstChild);else s=i;return(se.shadowroot||se.shadowrootmode)&&(s=I.call(r,s,!0)),s}let u=ve?i.outerHTML:i.innerHTML;return ve&&ae[`!doctype`]&&i.ownerDocument&&i.ownerDocument.doctype&&i.ownerDocument.doctype.name&&yG(XMe,i.ownerDocument.doctype.name)&&(u=` `+u),ge&&(u=gt(u)),S&&Te?O(u):u},t.setConfig=function(){tt(arguments.length>0&&arguments[0]!==void 0?arguments[0]:{}),ye=!0,be=ae,xe=se},t.clearConfig=function(){Qe=null,ye=!1,be=null,xe=null,S=w,C=``},t.isValidAttribute=function(e,t,n){return Qe||tt({}),Et(Ze(e),Ze(t),n)},t.addHook=function(e,t){typeof t==`function`&&_G(L,e)&&cG(L[e],t)},t.removeHook=function(e,t){if(_G(L,e)){if(t!==void 0){let n=MMe(L[e],t);return n===-1?void 0:NMe(L[e],n,1)[0]}return sG(L[e])}},t.removeHooks=function(e){_G(L,e)&&(L[e]=[])},t.removeAllHooks=function(){L=RG()},t}var VG=BG(),HG=Object.defineProperty,nNe=(e,t)=>{let n={};for(var r in e)HG(n,r,{get:e[r],enumerable:!0});return t||HG(n,Symbol.toStringTag,{value:`Module`}),n};function UG(e){this.content=e}UG.prototype={constructor:UG,find:function(e){for(var t=0;t>1}},UG.from=function(e){if(e instanceof UG)return e;var t=[];if(e)for(var n in e)t.push(n,e[n]);return new UG(t)};function WG(e,t,n){for(let r=0;;r++){if(r==e.childCount||r==t.childCount)return e.childCount==t.childCount?null:n;let i=e.child(r),a=t.child(r);if(i==a){n+=i.nodeSize;continue}if(!i.sameMarkup(a))return n;if(i.isText&&i.text!=a.text){let e=i.text,t=a.text,r=0;for(;e[r]==t[r];r++)n++;return r&&r0&&a>0&&e[i-1]==t[a-1];)i--,a--,n--,r--;return i&&a&&i=56320&&e<57344}function qG(e){return e>=55296&&e<56320}var JG=class e{constructor(e,t){if(this.content=e,this.size=t||0,t==null)for(let t=0;te&&n(s,r+o,i||null,a)!==!1&&s.content.size){let i=o+1;s.nodesBetween(Math.max(0,e-i),Math.min(s.content.size,t-i),n,r+i)}o=c}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,n,r){let i=``,a=!0;return this.nodesBetween(e,t,(o,s)=>{let c=o.isText?o.text.slice(Math.max(e,s)-s,t-s):o.isLeaf?r?typeof r==`function`?r(o):r:o.type.spec.leafText?o.type.spec.leafText(o):``:``;o.isBlock&&(o.isLeaf&&c||o.isTextblock)&&n&&(a?a=!1:i+=n),i+=c},0),i}append(t){if(!t.size)return this;if(!this.size)return t;let n=this.lastChild,r=t.firstChild,i=this.content.slice(),a=0;for(n.isText&&n.sameMarkup(r)&&(i[i.length-1]=n.withText(n.text+r.text),a=1);at)for(let e=0,a=0;at&&((an)&&(o=o.isText?o.cut(Math.max(0,t-a),Math.min(o.text.length,n-a)):o.cut(Math.max(0,t-a-1),Math.min(o.content.size,n-a-1))),r.push(o),i+=o.nodeSize),a=s}return new e(r,i)}cutByIndex(t,n){return t==n?e.empty:t==0&&n==this.content.length?this:new e(this.content.slice(t,n))}replaceChild(t,n){let r=this.content[t];if(r==n)return this;let i=this.content.slice(),a=this.size+n.nodeSize-r.nodeSize;return i[t]=n,new e(i,a)}addToStart(t){return new e([t].concat(this.content),this.size+t.nodeSize)}addToEnd(t){return new e(this.content.concat(t),this.size+t.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let t=0;tthis.size||e<0)throw RangeError(`Position ${e} outside of fragment (${this})`);for(let t=0,n=0;;t++){let r=this.child(t),i=n+r.nodeSize;if(i>=e)return i==e?XG(t+1,i):XG(t,n);n=i}}toString(){return`<`+this.toStringInner()+`>`}toStringInner(){return this.content.join(`, `)}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(t,n){if(!n)return e.empty;if(!Array.isArray(n))throw RangeError(`Invalid input for Fragment.fromJSON`);return e.fromArray(n.map(t.nodeFromJSON))}static fromArray(t){if(!t.length)return e.empty;let n,r=0;for(let e=0;ethis.type.rank&&(t||=e.slice(0,r),t.push(this),n=!0),t&&t.push(i)}return t||=e.slice(),n||t.push(this),t}removeFromSet(e){for(let t=0;te.type.rank-t.type.rank),n}};QG.none=[];var $G=class extends Error{},eK=class e{constructor(e,t,n){this.content=e,this.openStart=t,this.openEnd=n}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(t,n){let r=nK(this.content,t+this.openStart,n,this.openStart+1,this.openEnd+1);return r&&new e(r,this.openStart,this.openEnd)}removeBetween(t,n){return new e(tK(this.content,t+this.openStart,n+this.openStart),this.openStart,this.openEnd)}eq(e){return this.content.eq(e.content)&&this.openStart==e.openStart&&this.openEnd==e.openEnd}toString(){return this.content+`(`+this.openStart+`,`+this.openEnd+`)`}toJSON(){if(!this.content.size)return null;let e={content:this.content.toJSON()};return this.openStart>0&&(e.openStart=this.openStart),this.openEnd>0&&(e.openEnd=this.openEnd),e}static fromJSON(t,n){if(!n)return e.empty;let r=n.openStart||0,i=n.openEnd||0;if(typeof r!=`number`||typeof i!=`number`)throw RangeError(`Invalid input for Slice.fromJSON`);return new e(JG.fromJSON(t,n.content),r,i)}static maxOpen(t,n=!0){let r=0,i=0;for(let e=t.firstChild;e&&!e.isLeaf&&(n||!e.type.spec.isolating);e=e.firstChild)r++;for(let e=t.lastChild;e&&!e.isLeaf&&(n||!e.type.spec.isolating);e=e.lastChild)i++;return new e(t,r,i)}};eK.empty=new eK(JG.empty,0,0);function tK(e,t,n){let{index:r,offset:i}=e.findIndex(t),a=e.maybeChild(r),{index:o,offset:s}=e.findIndex(n);if(i==t||a.isText){if(s!=n&&!e.child(o).isText)throw RangeError(`Removing non-flat range`);return e.cut(0,t).append(e.cut(n))}if(r!=o)throw RangeError(`Removing non-flat range`);return e.replaceChild(r,a.copy(tK(a.content,t-i-1,n-i-1)))}function nK(e,t,n,r,i,a){let{index:o,offset:s}=e.findIndex(t),c=e.maybeChild(o);if(s==t||c.isText)return a&&r<=0&&i<=0&&!a.canReplace(o,o,n)?null:e.cut(0,t).append(n).append(e.cut(t));let l=nK(c.content,t-s-1,n,o==0?r-1:0,o==e.childCount-1?i-1:0,c);return l&&e.replaceChild(o,c.copy(l))}function rNe(e,t,n){if(n.openStart>e.depth)throw new $G(`Inserted content deeper than insertion position`);if(e.depth-n.openStart!=t.depth-n.openEnd)throw new $G(`Inconsistent open depths`);return rK(e,t,n,0)}function rK(e,t,n,r){let i=e.index(r),a=e.node(r);if(i==t.index(r)&&r=0&&e.isText&&e.sameMarkup(t[n])?t[n]=e.withText(t[n].text+e.text):t.push(e)}function sK(e,t,n,r){let i=(t||e).node(n),a=0,o=t?t.index(n):i.childCount;e&&(a=e.index(n),e.depth>n?a++:e.textOffset&&(oK(e.nodeAfter,r),a++));for(let e=a;ei&&aK(e,t,i+1),o=r.depth>i&&aK(n,r,i+1),s=[];return sK(null,e,i,s),a&&o&&t.index(i)==n.index(i)?(iK(a,o),oK(cK(a,lK(e,t,n,r,i+1)),s)):(a&&oK(cK(a,uK(e,t,i+1)),s),sK(t,n,i,s),o&&oK(cK(o,uK(n,r,i+1)),s)),sK(r,null,i,s),new JG(s)}function uK(e,t,n){let r=[];return sK(null,e,n,r),e.depth>n&&oK(cK(aK(e,t,n+1),uK(e,t,n+1)),r),sK(t,null,n,r),new JG(r)}function iNe(e,t){let n=t.depth-e.openStart,r=t.node(n).copy(e.content);for(let e=n-1;e>=0;e--)r=t.node(e).copy(JG.from(r));return{start:r.resolveNoCache(e.openStart+n),end:r.resolveNoCache(r.content.size-e.openEnd-n)}}var dK=class e{constructor(e,t,n){this.pos=e,this.path=t,this.parentOffset=n,this.depth=t.length/3-1}resolveDepth(e){return e==null?this.depth:e<0?this.depth+e:e}get parent(){return this.node(this.depth)}get doc(){return this.node(0)}node(e){return this.path[this.resolveDepth(e)*3]}index(e){return this.path[this.resolveDepth(e)*3+1]}indexAfter(e){return e=this.resolveDepth(e),this.index(e)+(e==this.depth&&!this.textOffset?0:1)}start(e){return e=this.resolveDepth(e),e==0?0:this.path[e*3-1]+1}end(e){return e=this.resolveDepth(e),this.start(e)+this.node(e).content.size}before(e){if(e=this.resolveDepth(e),!e)throw RangeError(`There is no position before the top-level node`);return e==this.depth+1?this.pos:this.path[e*3-1]}after(e){if(e=this.resolveDepth(e),!e)throw RangeError(`There is no position after the top-level node`);return e==this.depth+1?this.pos:this.path[e*3-1]+this.path[e*3].nodeSize}get textOffset(){return this.pos-this.path[this.path.length-1]}get nodeAfter(){let e=this.parent,t=this.index(this.depth);if(t==e.childCount)return null;let n=this.pos-this.path[this.path.length-1],r=e.child(t);return n?e.child(t).cut(n):r}get nodeBefore(){let e=this.index(this.depth),t=this.pos-this.path[this.path.length-1];return t?this.parent.child(e).cut(0,t):e==0?null:this.parent.child(e-1)}posAtIndex(e,t){t=this.resolveDepth(t);let n=this.path[t*3],r=t==0?0:this.path[t*3-1]+1;for(let t=0;t0;t--)if(this.start(t)<=e&&this.end(t)>=e)return t;return 0}blockRange(e=this,t){if(e.pos=0;n--)if(e.pos<=this.end(n)&&(!t||t(this.node(n))))return new pK(this,e,n);return null}sameParent(e){return this.pos-this.parentOffset==e.pos-e.parentOffset}max(e){return e.pos>this.pos?e:this}min(e){return e.pos=0&&n<=t.content.size))throw RangeError(`Position `+n+` out of range`);let r=[],i=0,a=n;for(let e=t;;){let{index:t,offset:n}=e.content.findIndex(a),o=a-n;if(r.push(e,t,i+n),!o||(e=e.child(t),e.isText))break;a=o-1,i+=n+1}return new e(n,r,a)}static resolveCached(t,n){let r=fK.get(t);if(r)for(let e=0;ee&&this.nodesBetween(e,t,e=>(n.isInSet(e.marks)&&(r=!0),!r)),r}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let e=this.type.name;return this.content.size&&(e+=`(`+this.content.toStringInner()+`)`),hK(this.marks,e)}contentMatchAt(e){let t=this.type.contentMatch.matchFragment(this.content,0,e);if(!t)throw Error(`Called contentMatchAt on a node with invalid content`);return t}canReplace(e,t,n=JG.empty,r=0,i=n.childCount){let a=this.contentMatchAt(e).matchFragment(n,r,i),o=a&&a.matchFragment(this.content,t);if(!o||!o.validEnd)return!1;for(let e=r;ee.type.name)}`);this.content.forEach(e=>e.check())}toJSON(){let e={type:this.type.name};for(let t in this.attrs){e.attrs=this.attrs;break}return this.content.size&&(e.content=this.content.toJSON()),this.marks.length&&(e.marks=this.marks.map(e=>e.toJSON())),e}static fromJSON(e,t){if(!t)throw RangeError(`Invalid input for Node.fromJSON`);let n;if(t.marks){if(!Array.isArray(t.marks))throw RangeError(`Invalid mark data for Node.fromJSON`);n=t.marks.map(e.markFromJSON)}if(t.type==`text`){if(typeof t.text!=`string`)throw RangeError(`Invalid text node in JSON`);return e.text(t.text,n)}let r=JG.fromJSON(e,t.content),i=e.nodeType(t.type).create(t.attrs,r,n);return i.type.checkAttrs(i.attrs),i}};mK.prototype.text=void 0;var cNe=class e extends mK{constructor(e,t,n,r){if(super(e,t,null,r),!n)throw RangeError(`Empty text nodes are not allowed`);this.text=n}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):hK(this.marks,JSON.stringify(this.text))}get textContent(){return this.text}textBetween(e,t){return this.text.slice(e,t)}get nodeSize(){return this.text.length}mark(t){return t==this.marks?this:new e(this.type,this.attrs,this.text,t)}withText(t){return t==this.text?this:new e(this.type,this.attrs,t,this.marks)}cut(e=0,t=this.text.length){return e==0&&t==this.text.length?this:this.withText(this.text.slice(e,t))}eq(e){return this.sameMarkup(e)&&this.text==e.text}toJSON(){let e=super.toJSON();return e.text=this.text,e}};function hK(e,t){for(let n=e.length-1;n>=0;n--)t=e[n].type.name+`(`+t+`)`;return t}var gK=class e{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(t,n){let r=new lNe(t,n);if(r.next==null)return e.empty;let i=_K(r);r.next&&r.err(`Unexpected trailing text`);let a=gNe(hNe(i));return _Ne(a,r),a}matchType(e){for(let t=0;te.createAndFill()));for(let e=0;e=this.next.length)throw RangeError(`There's no ${e}th edge in this content match`);return this.next[e]}toString(){let e=[];function t(n){e.push(n);for(let r=0;r{let r=n+(t.validEnd?`*`:` `)+` `;for(let n=0;n`+e.indexOf(t.next[n].next);return r}).join(` @@ -4399,7 +4399,7 @@ img.ProseMirror-separator { `});++r0&&n.push({type:`text`,value:` `}),n}function VQe(e){let t=0,n=e.charCodeAt(t);for(;n===9||n===32;)t++,n=e.charCodeAt(t);return e.slice(t)}function HQe(e,t){let n=IQe(e,t),r=n.one(e,void 0),i=CQe(n),a=Array.isArray(r)?{type:`root`,children:r}:r||{type:`root`,children:[]};return i&&(`children`in a,a.children.push({type:`text`,value:` -`},i)),a}function UQe(e,t){return e&&`run`in e?async function(n,r){let i=HQe(n,{file:r,...t});await e.run(i,r)}:function(n,r){return HQe(n,{file:r,...e||t})}}function WQe(e){if(e)throw e}var GQe=r(((e,t)=>{var n=Object.prototype.hasOwnProperty,r=Object.prototype.toString,i=Object.defineProperty,a=Object.getOwnPropertyDescriptor,o=function(e){return typeof Array.isArray==`function`?Array.isArray(e):r.call(e)===`[object Array]`},s=function(e){if(!e||r.call(e)!==`[object Object]`)return!1;var t=n.call(e,`constructor`),i=e.constructor&&e.constructor.prototype&&n.call(e.constructor.prototype,`isPrototypeOf`);if(e.constructor&&!t&&!i)return!1;for(var a in e);return a===void 0||n.call(e,a)},c=function(e,t){i&&t.name===`__proto__`?i(e,t.name,{enumerable:!0,configurable:!0,value:t.newValue,writable:!0}):e[t.name]=t.newValue},l=function(e,t){if(t===`__proto__`){if(!n.call(e,t))return;if(a)return a(e,t).value}return e[t]};t.exports=function e(){var t,n,r,i,a,u,d=arguments[0],f=1,p=arguments.length,m=!1;for(typeof d==`boolean`&&(m=d,d=arguments[1]||{},f=2),(d==null||typeof d!=`object`&&typeof d!=`function`)&&(d={});ft.length,o;r&&t.push(i);try{o=e.apply(this,t)}catch(e){let t=e;if(r&&n)throw t;return i(t)}r||(o&&o.then&&typeof o.then==`function`?o.then(a,i):o instanceof Error?i(o):a(o))}function i(e,...r){n||(n=!0,t(e,...r))}function a(e){i(null,e)}}var I7={basename:JQe,dirname:YQe,extname:XQe,join:ZQe,sep:`/`};function JQe(e,t){if(t!==void 0&&typeof t!=`string`)throw TypeError(`"ext" argument must be a string`);L7(e);let n=0,r=-1,i=e.length,a;if(t===void 0||t.length===0||t.length>e.length){for(;i--;)if(e.codePointAt(i)===47){if(a){n=i+1;break}}else r<0&&(a=!0,r=i+1);return r<0?``:e.slice(n,r)}if(t===e)return``;let o=-1,s=t.length-1;for(;i--;)if(e.codePointAt(i)===47){if(a){n=i+1;break}}else o<0&&(a=!0,o=i+1),s>-1&&(e.codePointAt(i)===t.codePointAt(s--)?s<0&&(r=i):(s=-1,r=o));return n===r?r=o:r<0&&(r=e.length),e.slice(n,r)}function YQe(e){if(L7(e),e.length===0)return`.`;let t=-1,n=e.length,r;for(;--n;)if(e.codePointAt(n)===47){if(r){t=n;break}}else r||=!0;return t<0?e.codePointAt(0)===47?`/`:`.`:t===1&&e.codePointAt(0)===47?`//`:e.slice(0,t)}function XQe(e){L7(e);let t=e.length,n=-1,r=0,i=-1,a=0,o;for(;t--;){let s=e.codePointAt(t);if(s===47){if(o){r=t+1;break}continue}n<0&&(o=!0,n=t+1),s===46?i<0?i=t:a!==1&&(a=1):i>-1&&(a=-1)}return i<0||n<0||a===0||a===1&&i===n-1&&i===r+1?``:e.slice(i,n)}function ZQe(...e){let t=-1,n;for(;++t0&&e.codePointAt(e.length-1)===47&&(n+=`/`),t?`/`+n:n}function $Qe(e,t){let n=``,r=0,i=-1,a=0,o=-1,s,c;for(;++o<=e.length;){if(o2){if(c=n.lastIndexOf(`/`),c!==n.length-1){c<0?(n=``,r=0):(n=n.slice(0,c),r=n.length-1-n.lastIndexOf(`/`)),i=o,a=0;continue}}else if(n.length>0){n=``,r=0,i=o,a=0;continue}}t&&(n=n.length>0?n+`/..`:`..`,r=2)}else n.length>0?n+=`/`+e.slice(i+1,o):n=e.slice(i+1,o),r=o-i-1;i=o,a=0}else s===46&&a>-1?a++:a=-1}return n}function L7(e){if(typeof e!=`string`)throw TypeError(`Path must be a string. Received `+JSON.stringify(e))}var e$e={cwd:t$e};function t$e(){return`/`}function R7(e){return!!(typeof e==`object`&&e&&`href`in e&&e.href&&`protocol`in e&&e.protocol&&e.auth===void 0)}function n$e(e){if(typeof e==`string`)e=new URL(e);else if(!R7(e)){let t=TypeError('The "path" argument must be of type string or an instance of URL. Received `'+e+"`");throw t.code=`ERR_INVALID_ARG_TYPE`,t}if(e.protocol!==`file:`){let e=TypeError(`The URL must be of scheme file`);throw e.code=`ERR_INVALID_URL_SCHEME`,e}return r$e(e)}function r$e(e){if(e.hostname!==``){let e=TypeError(`File URL host must be "localhost" or empty on darwin`);throw e.code=`ERR_INVALID_FILE_URL_HOST`,e}let t=e.pathname,n=-1;for(;++n0){let[r,...a]=t,o=n[i][1];F7(o)&&F7(r)&&(r=(0,H7.default)(!0,o,r)),n[i]=[e,r,...a]}}}}().freeze();function U7(e,t){if(typeof t!=`function`)throw TypeError("Cannot `"+e+"` without `parser`")}function W7(e,t){if(typeof t!=`function`)throw TypeError("Cannot `"+e+"` without `compiler`")}function G7(e,t){if(t)throw Error("Cannot call `"+e+"` on a frozen processor.\nCreate a new processor first, by calling it: use `processor()` instead of `processor`.")}function u$e(e){if(!F7(e)||typeof e.type!=`string`)throw TypeError("Expected node, got `"+e+"`")}function d$e(e,t,n){if(!n)throw Error("`"+e+"` finished async. Use `"+t+"` instead")}function K7(e){return f$e(e)?e:new i$e(e)}function f$e(e){return!!(e&&typeof e==`object`&&`message`in e&&`messages`in e)}function p$e(e){return typeof e==`string`||m$e(e)}function m$e(e){return!!(e&&typeof e==`object`&&`byteLength`in e&&`byteOffset`in e)}var q7=[],h$e={allowDangerousHtml:!0},g$e=/^(https?|ircs?|mailto|xmpp)$/i,_$e=[{from:`astPlugins`,id:`remove-buggy-html-in-markdown-parser`},{from:`allowDangerousHtml`,id:`remove-buggy-html-in-markdown-parser`},{from:`allowNode`,id:`replace-allownode-allowedtypes-and-disallowedtypes`,to:`allowElement`},{from:`allowedTypes`,id:`replace-allownode-allowedtypes-and-disallowedtypes`,to:`allowedElements`},{from:`disallowedTypes`,id:`replace-allownode-allowedtypes-and-disallowedtypes`,to:`disallowedElements`},{from:`escapeHtml`,id:`remove-buggy-html-in-markdown-parser`},{from:`includeElementIndex`,id:`#remove-includeelementindex`},{from:`includeNodeIndex`,id:`change-includenodeindex-to-includeelementindex`},{from:`linkTarget`,id:`remove-linktarget`},{from:`plugins`,id:`change-plugins-to-remarkplugins`,to:`remarkPlugins`},{from:`rawSourcePos`,id:`#remove-rawsourcepos`},{from:`renderers`,id:`change-renderers-to-components`,to:`components`},{from:`source`,id:`change-source-to-children`,to:`children`},{from:`sourcePos`,id:`#remove-sourcepos`},{from:`transformImageUri`,id:`#add-urltransform`,to:`urlTransform`},{from:`transformLinkUri`,id:`#add-urltransform`,to:`urlTransform`}];function v$e(e){let t=y$e(e),n=b$e(e);return x$e(t.runSync(t.parse(n),n),e)}function y$e(e){let t=e.rehypePlugins||q7,n=e.remarkPlugins||q7,r=e.remarkRehypeOptions?{...e.remarkRehypeOptions,...h$e}:h$e;return l$e().use(FZe).use(n).use(UQe,r).use(t)}function b$e(e){let t=e.children||``,n=new i$e;return typeof t==`string`?n.value=t:``+t,n}function x$e(e,t){let n=t.allowedElements,r=t.allowElement,i=t.components,a=t.disallowedElements,o=t.skipHtml,s=t.unwrapDisallowed,c=t.urlTransform||S$e;for(let e of _$e)Object.hasOwn(t,e.from)&&``+e.from+(e.to?"use `"+e.to+"` instead":`remove it`)+e.id;return t.className&&(e={type:`element`,tagName:`div`,properties:{className:t.className},children:e.type===`root`?e.children:[e]}),PQe(e,l),VJe(e,{Fragment:G.Fragment,components:i,ignoreInvalidStyle:!0,jsx:G.jsx,jsxs:G.jsxs,passKeys:!0,passNode:!0});function l(e,t,i){if(e.type===`raw`&&i&&typeof t==`number`)return o?i.children.splice(t,1):i.children[t]={type:`text`,value:e.value},t;if(e.type===`element`){let t;for(t in t7)if(Object.hasOwn(t7,t)&&Object.hasOwn(e.properties,t)){let n=e.properties[t],r=t7[t];(r===null||r.includes(e.tagName))&&(e.properties[t]=c(String(n||``),t,e))}}if(e.type===`element`){let o=n?!n.includes(e.tagName):a?a.includes(e.tagName):!1;if(!o&&r&&typeof t==`number`&&(o=!r(e,t,i)),o&&i&&typeof t==`number`)return s&&e.children?i.children.splice(t,1,...e.children):i.children.splice(t,1),t}}}function S$e(e){let t=e.indexOf(`:`),n=e.indexOf(`?`),r=e.indexOf(`#`),i=e.indexOf(`/`);return t===-1||i!==-1&&t>i||n!==-1&&t>n||r!==-1&&t>r||g$e.test(e.slice(0,t))?e:``}M$e.peek=j$e;function C$e(){this.buffer()}function w$e(e){this.enter({type:`footnoteReference`,identifier:``,label:``},e)}function T$e(){this.buffer()}function E$e(e){this.enter({type:`footnoteDefinition`,identifier:``,label:``,children:[]},e)}function D$e(e){let t=this.resume(),n=this.stack[this.stack.length-1];n.type,n.identifier=a7(this.sliceSerialize(e)).toLowerCase(),n.label=t}function O$e(e){this.exit(e)}function k$e(e){let t=this.resume(),n=this.stack[this.stack.length-1];n.type,n.identifier=a7(this.sliceSerialize(e)).toLowerCase(),n.label=t}function A$e(e){this.exit(e)}function j$e(){return`[`}function M$e(e,t,n,r){let i=n.createTracker(r),a=i.move(`[^`),o=n.enter(`footnoteReference`),s=n.enter(`reference`);return a+=i.move(n.safe(n.associationId(e),{after:`]`,before:a})),s(),o(),a+=i.move(`]`),a}function N$e(){return{enter:{gfmFootnoteCallString:C$e,gfmFootnoteCall:w$e,gfmFootnoteDefinitionLabelString:T$e,gfmFootnoteDefinition:E$e},exit:{gfmFootnoteCallString:D$e,gfmFootnoteCall:O$e,gfmFootnoteDefinitionLabelString:k$e,gfmFootnoteDefinition:A$e}}}L$e.peek=R$e;function P$e(){return{canContainEols:[`delete`],enter:{strikethrough:F$e},exit:{strikethrough:I$e}}}function F$e(e){this.enter({type:`delete`,children:[]},e)}function I$e(e){this.exit(e)}function L$e(e,t,n,r){let i=n.createTracker(r),a=n.enter(`strikethrough`),o=i.move(`~~`);return o+=n.containerPhrasing(e,{...i.current(),before:o,after:`~`}),o+=i.move(`~~`),a(),o}function R$e(){return`~`}function z$e(){return{enter:{table:B$e,tableData:U$e,tableHeader:U$e,tableRow:H$e},exit:{codeText:W$e,table:V$e,tableData:J7,tableHeader:J7,tableRow:J7}}}function B$e(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 V$e(e){this.exit(e),this.data.inTable=void 0}function H$e(e){this.enter({type:`tableRow`,children:[]},e)}function J7(e){this.exit(e)}function U$e(e){this.enter({type:`tableCell`,children:[]},e)}function W$e(e){let t=this.resume();this.data.inTable&&(t=t.replace(/\\([\\|])/g,G$e));let n=this.stack[this.stack.length-1];n.type,n.value=t,this.exit(e)}function G$e(e,t){return t===`|`?t:e}function K$e(){return{exit:{taskListCheckValueChecked:q$e,taskListCheckValueUnchecked:q$e,paragraph:J$e}}}function q$e(e){let t=this.stack[this.stack.length-2];t.type,t.checked=e.type===`taskListCheckValueChecked`}function J$e(e){let t=this.stack[this.stack.length-2];if(t&&t.type===`listItem`&&typeof t.checked==`boolean`){let e=this.stack[this.stack.length-1];e.type;let n=e.children[0];if(n&&n.type===`text`){let r=t.children,i=-1,a;for(;++i999||s===93&&!o||s===null||s===91||d7(s))return n(s);if(s===93){e.exit(`chunkString`);let a=e.exit(`gfmFootnoteCallString`);return i.includes(a7(r.sliceSerialize(a)))?(e.enter(`gfmFootnoteCallLabelMarker`),e.consume(s),e.exit(`gfmFootnoteCallLabelMarker`),e.exit(`gfmFootnoteCall`),t):n(s)}return d7(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 e1e(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||d7(t))return n(t);if(t===93){e.exit(`chunkString`);let n=e.exit(`gfmFootnoteDefinitionLabelString`);return a=a7(r.sliceSerialize(n)),e.enter(`gfmFootnoteDefinitionLabelMarker`),e.consume(t),e.exit(`gfmFootnoteDefinitionLabelMarker`),e.exit(`gfmFootnoteDefinitionLabel`),f}return d7(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),h7(e,p,`gfmFootnoteDefinitionWhitespace`)):n(t)}function p(e){return t(e)}}function t1e(e,t,n){return e.check(y7,t,e.attempt(Y$e,t,n))}function n1e(e){e.exit(`gfmFootnoteDefinition`)}function r1e(e,t,n){let r=this;return h7(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 i1e(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=g7(a);return l._open=!u||u===2&&!!s,l._close=!s||s===2&&!!u,n(a)}}}var a1e=class{constructor(){this.map=[]}add(e,t,n){o1e(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 o1e(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):u7(t)?a>1?(a=0,r.interrupt=!0,e.exit(`tableRow`),e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),p):n(t):f7(t)?h7(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||d7(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,f7(t)?h7(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 f7(t)?h7(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||u7(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 f7(t)?h7(e,b,`whitespace`)(t):b(t)}function b(n){return n===124?m(n):n===null||u7(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||u7(n)?(e.exit(`tableRow`),t(n)):f7(n)?h7(e,C,`whitespace`)(n):(e.enter(`data`),w(n))}function w(t){return t===null||t===124||d7(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 u1e(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 a1e;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({},X7(t.events,i)),e.add(i,0,[[`exit`,a,t]]),a=void 0),a}function d1e(e,t,n,r,i){let a=[],o=X7(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 X7(e,t){let n=e[t],r=n[0]===`enter`?`start`:`end`;return n[1][r]}var f1e={name:`tasklistCheck`,tokenize:m1e};function p1e(){return{text:{91:f1e}}}function m1e(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 d7(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 u7(r)?t(r):f7(r)?e.check({tokenize:h1e},t,n)(r):n(r)}}function h1e(e,t,n){return h7(e,r,`whitespace`);function r(e){return e===null?n(e):t(e)}}function g1e(){let e=this.data(),t=e.micromarkExtensions||=[],n=e.fromMarkdownExtensions||=[];t.push(X$e(),i1e(),c1e(),p1e()),n.push(N$e(),P$e(),z$e(),K$e())}var _1e=`fileManager.readmeCollapsed`;function v1e({folderId:e}){let{t}=U(),[n,r]=(0,f.useState)(()=>localStorage.getItem(_1e)===`1`);(0,f.useEffect)(()=>{localStorage.setItem(_1e,n?`1`:`0`)},[n]);let{data:i,isLoading:a,error:o}=K({queryKey:[`folder-readme`,e],queryFn:()=>Z.getLibraryFolderReadme(e),retry:!1,staleTime:3e4});return a||o||!i?null:n?(0,G.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,G.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,G.jsx)(sc,{className:`w-4 h-4 text-bambu-green flex-shrink-0`}),(0,G.jsx)(`span`,{className:`text-sm font-medium text-white truncate`,children:i.filename}),(0,G.jsx)(Cl,{className:`w-4 h-4 text-bambu-gray flex-shrink-0 ml-auto`})]}),(0,G.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,G.jsx)(Cl,{className:`w-4 h-4 text-bambu-green flex-shrink-0`}),(0,G.jsx)(`span`,{className:`text-xs font-medium text-bambu-gray [writing-mode:vertical-rl] rotate-180 select-none`,children:t(`fileManager.readme.label`)})]})]}):(0,G.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,G.jsxs)(`div`,{className:`flex items-center justify-between gap-2 px-3 py-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,G.jsx)(sc,{className:`w-4 h-4 text-bambu-green flex-shrink-0`}),(0,G.jsx)(`span`,{className:`text-sm font-medium text-white truncate`,title:i.filename,children:i.filename}),i.truncated&&(0,G.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,G.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,G.jsx)(Sl,{className:`w-4 h-4`})})]}),(0,G.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,G.jsx)(v$e,{remarkPlugins:[g1e],components:{h1:({children:e})=>(0,G.jsx)(`h1`,{className:`text-lg font-semibold text-white mt-2 mb-1`,children:e}),h2:({children:e})=>(0,G.jsx)(`h2`,{className:`text-base font-semibold text-white mt-2 mb-1`,children:e}),h3:({children:e})=>(0,G.jsx)(`h3`,{className:`text-sm font-semibold text-white mt-2 mb-1`,children:e}),p:({children:e})=>(0,G.jsx)(`p`,{className:`my-1`,children:e}),ul:({children:e})=>(0,G.jsx)(`ul`,{className:`list-disc list-inside space-y-0.5 ml-2`,children:e}),ol:({children:e})=>(0,G.jsx)(`ol`,{className:`list-decimal list-inside space-y-0.5 ml-2`,children:e}),li:({children:e})=>(0,G.jsx)(`li`,{children:e}),code:({children:e,...t})=>t.className?(0,G.jsx)(`code`,{className:`block p-2 bg-bambu-dark rounded text-xs font-mono text-bambu-gray-light overflow-x-auto`,children:e}):(0,G.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,G.jsx)(`pre`,{className:`my-2`,children:e}),blockquote:({children:e})=>(0,G.jsx)(`blockquote`,{className:`border-l-2 border-bambu-dark-tertiary pl-3 text-bambu-gray italic`,children:e}),a:({children:e,href:t})=>(0,G.jsx)(`a`,{href:t,target:`_blank`,rel:`noopener noreferrer`,className:`text-bambu-green hover:underline`,children:e}),table:({children:e})=>(0,G.jsx)(`div`,{className:`overflow-x-auto`,children:(0,G.jsx)(`table`,{className:`min-w-full text-xs border-collapse`,children:e})}),th:({children:e})=>(0,G.jsx)(`th`,{className:`border border-bambu-dark-tertiary px-2 py-1 text-left font-semibold text-white`,children:e}),td:({children:e})=>(0,G.jsx)(`td`,{className:`border border-bambu-dark-tertiary px-2 py-1`,children:e}),hr:()=>(0,G.jsx)(`hr`,{className:`border-bambu-dark-tertiary my-2`})},children:i.content})})]})}function y1e({open:e,onClose:t,onPickTag:n}){let{t:r}=U(),i=no(),{showToast:a}=Zd(),[o,s]=(0,f.useState)(!1),[c,l]=(0,f.useState)(null),[u,d]=(0,f.useState)(``),[p,m]=(0,f.useState)(null),{data:h=[],isLoading:g}=K({queryKey:A5,queryFn:Z.getLibraryTags,enabled:e}),_=()=>{i.invalidateQueries({queryKey:A5}),i.invalidateQueries({queryKey:[`library-files`]})},v=q({mutationFn:async()=>{let e=u.trim();if(!e)throw Error(r(`fileManager.tags.nameRequired`));return c?Z.updateLibraryTag(c.id,e):Z.createLibraryTag(e)},onSuccess:()=>{a(r(c?`fileManager.tags.updated`:`fileManager.tags.created`),`success`),s(!1),l(null),d(``),_()},onError:e=>{a(e.message||r(`fileManager.tags.saveFailed`),`error`)}}),y=q({mutationFn:e=>Z.deleteLibraryTag(e),onSuccess:()=>{a(r(`fileManager.tags.deleted`),`success`),m(null),_()},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,f.useCallback)(()=>{v.isPending||(s(!1),l(null),d(``))},[v.isPending]);(0,f.useEffect)(()=>{if(!e)return;let n=e=>{e.key===`Escape`&&(v.isPending||y.isPending||(o?S():p||t()))};return document.addEventListener(`keydown`,n),()=>document.removeEventListener(`keydown`,n)},[e,o,p,v.isPending,y.isPending,S,t]);let C=e=>{e.preventDefault(),v.mutate()};if(!e)return null;let w=`library-tags-modal-title`,T=`library-tag-editor-title`;return(0,G.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[(0,G.jsx)(`div`,{className:`absolute inset-0 bg-black/60`,onClick:()=>{v.isPending||y.isPending||t()}}),(0,G.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,G.jsxs)(`div`,{className:`flex items-center justify-between gap-4 px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,G.jsxs)(`h2`,{id:w,className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(wu,{className:`w-5 h-5 text-bambu-green`}),r(`fileManager.tags.title`)]}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-sm mt-0.5`,children:r(`fileManager.tags.subtitle`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(Q,{onClick:b,children:[(0,G.jsx)(Ml,{className:`w-4 h-4`}),r(`fileManager.tags.add`)]}),(0,G.jsx)(`button`,{type:`button`,className:`p-1.5 text-bambu-gray hover:text-white rounded`,onClick:t,"aria-label":r(`common.close`),children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]})]}),(0,G.jsx)(`div`,{className:`overflow-y-auto`,children:g?(0,G.jsxs)(`div`,{className:`flex items-center justify-center py-16 text-bambu-gray`,children:[(0,G.jsx)(Y,{className:`w-6 h-6 animate-spin mr-2`}),r(`common.loading`)]}):h.length===0?(0,G.jsx)(`div`,{className:`py-16 text-center text-bambu-gray`,children:r(`fileManager.tags.empty`)}):(0,G.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,G.jsx)(`thead`,{children:(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary text-left text-bambu-gray`,children:[(0,G.jsx)(`th`,{className:`px-4 py-3 font-medium`,children:r(`fileManager.tags.name`)}),(0,G.jsx)(`th`,{className:`px-4 py-3 font-medium text-right`,children:r(`fileManager.tags.fileCount`)}),(0,G.jsx)(`th`,{className:`px-4 py-3 font-medium text-right w-32`,children:r(`common.actions`)})]})}),(0,G.jsx)(`tbody`,{children:h.map(e=>(0,G.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,G.jsx)(`td`,{className:`px-4 py-3 text-white font-medium`,children:e.name}),(0,G.jsx)(`td`,{className:`px-4 py-3 text-right text-bambu-gray`,children:e.file_count}),(0,G.jsx)(`td`,{className:`px-4 py-3 text-right`,onClick:e=>e.stopPropagation(),children:(0,G.jsxs)(`div`,{className:`flex items-center justify-end gap-1`,children:[(0,G.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,G.jsx)(Dl,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{type:`button`,className:`p-1.5 text-bambu-gray hover:text-red-600 dark:hover:text-red-400 rounded`,onClick:()=>m(e),title:r(`common.delete`),"aria-label":r(`fileManager.tags.deleteAria`,{name:e.name}),children:(0,G.jsx)(Pu,{className:`w-4 h-4`})})]})})]},e.id))})]})})]}),o&&(0,G.jsxs)(`div`,{className:`fixed inset-0 z-[60] flex items-center justify-center`,children:[(0,G.jsx)(`div`,{className:`absolute inset-0 bg-black/60`,onClick:S}),(0,G.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,G.jsx)(`h3`,{id:T,className:`text-lg font-semibold text-white mb-4`,children:r(c?`fileManager.tags.edit`:`fileManager.tags.add`)}),(0,G.jsxs)(`form`,{onSubmit:C,children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,htmlFor:`library-tag-name`,children:r(`fileManager.tags.name`)}),(0,G.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,G.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:S,children:r(`common.cancel`)}),(0,G.jsxs)(Q,{type:`submit`,disabled:v.isPending||!u.trim(),children:[v.isPending&&(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),r(`common.save`)]})]})]})]})]}),p&&(0,G.jsx)(uf,{title:r(`fileManager.tags.confirmDelete`,{name:p.name}),message:p.file_count>0?r(`fileManager.tags.confirmDeleteInUseMessage`,{count:p.file_count}):r(`fileManager.tags.confirmDeleteMessage`),confirmText:r(`common.delete`),variant:`danger`,isLoading:y.isPending,onConfirm:()=>y.mutate(p.id),onCancel:()=>m(null)})]})}function b1e({file:e,canEdit:t,onClose:n}){let{t:r}=U(),{showToast:i}=Zd(),a=no(),{data:o}=K({queryKey:[`library-file`,e.id],queryFn:()=>Z.getLibraryFile(e.id)}),[s,c]=(0,f.useState)(``),[l,u]=(0,f.useState)(``),[d,p]=(0,f.useState)([]),[m,h]=(0,f.useState)(!1),[g,_]=(0,f.useState)(null),v=(0,f.useRef)(null),y=(0,f.useRef)(null);(0,f.useEffect)(()=>{!o||y.current===o.id||(y.current=o.id,c(o.notes??``),u(o.external_url??``),p(o.photos??[]))},[o]),(0,f.useEffect)(()=>{if(g!==null)return;let e=e=>{e.key===`Escape`&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[g,n]);let b=()=>{a.invalidateQueries({queryKey:[`library-files`]}),a.invalidateQueries({queryKey:[`library-file`,e.id]})},x=q({mutationFn:()=>Z.updateLibraryFile(e.id,{notes:s,external_url:l.trim()}),onSuccess:()=>{b(),i(r(`fileManager.details.saved`),`success`),n()},onError:()=>{i(r(`fileManager.details.saveFailed`),`error`)}}),S=!!o&&(s!==(o.notes??``)||l.trim()!==(o.external_url??``)),C=async t=>{let n=t.target.files?.[0];if(n){h(!0);try{p((await Z.uploadLibraryFilePhoto(e.id,n)).photos),b()}catch{i(r(`fileManager.details.uploadFailed`),`error`)}finally{h(!1),v.current&&(v.current.value=``)}}},w=async t=>{try{let n=(await Z.deleteLibraryFilePhoto(e.id,t)).photos??[];p(n),n.length===0&&_(null),b()}catch{i(r(`fileManager.details.deleteFailed`),`error`)}},T=e=>{e.preventDefault(),!(!t||!S)&&x.mutate()},E=l.trim(),D=[{label:r(`fileManager.details.size`),value:Yd(e.file_size)},{label:r(`fileManager.details.type`),value:e.file_type.toUpperCase()}];return o?.print_name&&D.push({label:r(`fileManager.details.printName`),value:o.print_name}),o?.print_time_seconds&&D.push({label:r(`fileManager.details.printTime`),value:pp(o.print_time_seconds)}),o?.filament_used_grams&&D.push({label:r(`fileManager.details.filament`),value:`${o.filament_used_grams.toFixed(1)} g`}),o?.sliced_for_model&&D.push({label:r(`fileManager.details.slicedFor`),value:o.sliced_for_model}),o?.source_url&&D.push({label:r(`fileManager.details.source`),value:(0,G.jsxs)(`a`,{href:o.source_url,target:`_blank`,rel:`noopener noreferrer`,className:`text-bambu-green hover:underline inline-flex items-center gap-1 min-w-0`,children:[(0,G.jsx)(`span`,{className:`truncate`,children:o.source_url}),(0,G.jsx)(Qs,{className:`w-3 h-3 flex-shrink-0`})]})}),D.push({label:r(`fileManager.details.created`),value:cp(e.created_at)}),D.push({label:r(`fileManager.details.modified`),value:cp(e.fs_modified_at??o?.updated_at??e.created_at)}),(0,G.jsxs)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:n,children:[(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-lg max-h-[90vh] flex flex-col`,onClick:e=>e.stopPropagation(),children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-3 px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:r(`fileManager.details.title`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white truncate`,title:e.filename,children:e.filename}),(0,G.jsx)(`span`,{className:`flex-shrink-0 text-xs px-1.5 py-0.5 rounded font-medium bg-bambu-dark-tertiary text-bambu-gray`,children:e.file_type.toUpperCase()})]})]}),(0,G.jsx)(`button`,{type:`button`,onClick:n,className:`text-bambu-gray hover:text-white transition-colors flex-shrink-0`,"aria-label":r(`common.close`),children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]}),(0,G.jsxs)(`form`,{onSubmit:T,className:`p-6 space-y-4 overflow-y-auto flex-1`,children:[(0,G.jsx)(`dl`,{className:`grid grid-cols-[auto_1fr] gap-x-4 gap-y-1 text-sm`,children:D.map(e=>(0,G.jsxs)(`div`,{className:`contents`,children:[(0,G.jsx)(`dt`,{className:`text-bambu-gray whitespace-nowrap`,children:e.label}),(0,G.jsx)(`dd`,{className:`text-white min-w-0 truncate`,children:e.value})]},e.label))}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[(0,G.jsx)(bu,{className:`w-4 h-4 inline mr-1`}),r(`fileManager.details.notes`)]}),(0,G.jsx)(`textarea`,{value:s,onChange:e=>c(e.target.value),rows:3,disabled:!t,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none resize-none disabled:opacity-60`,placeholder:r(`fileManager.details.notesPlaceholder`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[(0,G.jsx)(qc,{className:`w-4 h-4 inline mr-1`}),r(`fileManager.details.externalLink`)]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`input`,{type:`url`,value:l,onChange:e=>u(e.target.value),disabled:!t,className:`flex-1 min-w-0 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none disabled:opacity-60`,placeholder:r(`fileManager.details.externalLinkPlaceholder`)}),E&&(0,G.jsx)(`a`,{href:E,target:`_blank`,rel:`noopener noreferrer`,className:`p-2 rounded-lg text-bambu-gray hover:text-bambu-green hover:bg-bambu-dark transition-colors`,title:r(`fileManager.details.openLink`),"aria-label":r(`fileManager.details.openLink`),children:(0,G.jsx)(Qs,{className:`w-4 h-4`})})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[(0,G.jsx)(es,{className:`w-4 h-4 inline mr-1`}),r(`fileManager.details.photos`)]}),(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[d.map((n,i)=>(0,G.jsxs)(`div`,{className:`relative group`,children:[(0,G.jsx)(`button`,{type:`button`,onClick:()=>_(i),className:`block w-20 h-20 rounded-lg overflow-hidden border border-bambu-dark-tertiary hover:border-bambu-green transition-colors`,children:(0,G.jsx)(`img`,{src:Z.getLibraryFilePhotoUrl(e.id,n),alt:r(`fileManager.details.photos`),className:`w-full h-full object-cover`})}),t&&(0,G.jsx)(`button`,{type:`button`,onClick:()=>w(n),className:`absolute -top-1 -right-1 p-1 bg-red-500 rounded-full can-hover:opacity-0 group-hover:opacity-100 focus-visible:opacity-100 transition-opacity`,title:r(`fileManager.details.deletePhoto`),"aria-label":r(`fileManager.details.deletePhoto`),children:(0,G.jsx)(Pu,{className:`w-3 h-3 text-white`})})]},n)),t&&(0,G.jsxs)(`label`,{className:`w-20 h-20 flex items-center justify-center border-2 border-dashed border-bambu-dark-tertiary rounded-lg cursor-pointer hover:border-bambu-green transition-colors`,title:r(`fileManager.details.addPhoto`),children:[(0,G.jsx)(`input`,{ref:v,type:`file`,accept:`image/jpeg,image/png,image/webp`,onChange:C,className:`hidden`,disabled:m,"aria-label":r(`fileManager.details.addPhoto`)}),m?(0,G.jsx)(Y,{className:`w-6 h-6 text-bambu-gray animate-spin`}):(0,G.jsx)(Ml,{className:`w-6 h-6 text-bambu-gray`})]}),d.length===0&&!t&&(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:r(`fileManager.details.noPhotos`)})]})]}),(0,G.jsxs)(`div`,{className:`flex gap-3 pt-2`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:n,className:`flex-1`,children:r(`common.close`)}),t&&(0,G.jsxs)(Q,{type:`submit`,variant:`primary`,className:`flex-1`,disabled:!S||x.isPending,children:[x.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Wl,{className:`w-4 h-4`}),r(`fileManager.details.save`)]})]})]})]}),g!==null&&d.length>0&&(0,G.jsx)(XW,{archiveName:e.filename,photos:d,initialIndex:g,getPhotoUrl:t=>Z.getLibraryFilePhotoUrl(e.id,t),onClose:()=>_(null),onDelete:t?w:void 0})]})}var x1e=90;function S1e({onClose:e}){let{t}=U(),n=no(),{showToast:r}=Zd(),[i,a]=(0,f.useState)(x1e),[o,s]=(0,f.useState)(!0),[c,l]=(0,f.useState)(i);(0,f.useEffect)(()=>{let e=window.setTimeout(()=>l(i),300);return()=>window.clearTimeout(e)},[i]);let u=K({queryKey:[`library-purge-preview`,c,o],queryFn:()=>Z.previewLibraryPurge(c,o),enabled:c>=1}),d=q({mutationFn:()=>Z.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,f.useEffect)(()=>{let t=t=>{t.key===`Escape`&&!d.isPending&&e()};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e,d.isPending]);let p=u.data,m=p?.count??0,h=p?.total_bytes??0,g=m>0&&!d.isPending;return(0,G.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4`,children:(0,G.jsxs)(`div`,{className:`bg-white dark:bg-gray-900 rounded-lg shadow-xl max-w-lg w-full`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-gray-200 dark:border-gray-700`,children:[(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-gray-900 dark:text-gray-100 flex items-center gap-2`,children:[(0,G.jsx)(Pu,{className:`w-5 h-5`}),t(`libraryPurge.title`)]}),(0,G.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,G.jsx)(nd,{className:`w-5 h-5`})})]}),(0,G.jsxs)(`div`,{className:`p-4 space-y-4`,children:[(0,G.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400`,children:t(`libraryPurge.description`)}),(0,G.jsxs)(`div`,{children:[(0,G.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,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.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,G.jsx)(`span`,{className:`text-sm text-gray-600 dark:text-gray-400`,children:t(`libraryPurge.days`)})]})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-gray-700 dark:text-gray-300`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:o,onChange:e=>s(e.target.checked),className:`rounded border-gray-300`}),t(`libraryPurge.includeNeverPrinted`)]}),(0,G.jsxs)(`div`,{className:`rounded border border-gray-200 dark:border-gray-700 bg-gray-50 dark:bg-gray-800/30 p-3`,children:[(0,G.jsx)(`div`,{className:`text-xs font-semibold uppercase tracking-wide text-gray-600 dark:text-gray-300 mb-2`,children:t(`libraryPurge.effectsTitle`)}),(0,G.jsxs)(`ul`,{className:`text-xs text-gray-700 dark:text-gray-300 space-y-1 list-disc pl-4`,children:[(0,G.jsx)(`li`,{children:t(`libraryPurge.effect1`)}),(0,G.jsx)(`li`,{children:t(`libraryPurge.effect2`)}),(0,G.jsx)(`li`,{children:t(`libraryPurge.effect3`)}),(0,G.jsx)(`li`,{children:t(`libraryPurge.effect4`)})]})]}),(0,G.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,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-gray-500 dark:text-gray-400`,children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),` `,t(`libraryPurge.previewLoading`)]}):u.isError?(0,G.jsx)(`div`,{className:`text-sm text-red-600 dark:text-red-400`,children:u.error?.message??t(`libraryPurge.previewFailed`)}):(0,G.jsxs)(`div`,{className:`text-sm text-gray-900 dark:text-gray-100`,children:[(0,G.jsx)(`div`,{className:`font-medium`,children:t(`libraryPurge.previewSummary`,{count:m,size:Yd(h)})}),p?.sample_filenames&&p.sample_filenames.length>0&&(0,G.jsxs)(`ul`,{className:`mt-2 text-xs text-gray-600 dark:text-gray-400 space-y-0.5 list-disc pl-4`,children:[p.sample_filenames.map(e=>(0,G.jsx)(`li`,{className:`truncate`,children:e},e)),m>p.sample_filenames.length&&(0,G.jsx)(`li`,{className:`list-none italic text-gray-500`,children:t(`libraryPurge.andMore`,{count:m-p.sample_filenames.length})})]})]})}),(0,G.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,G.jsx)(Lu,{className:`w-4 h-4 mt-0.5 shrink-0`}),(0,G.jsx)(`span`,{children:t(`libraryPurge.warning`)})]})]}),(0,G.jsxs)(`div`,{className:`flex justify-end gap-2 p-4 border-t border-gray-200 dark:border-gray-700`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:e,disabled:d.isPending,children:t(`common.cancel`)}),(0,G.jsx)(Q,{variant:`danger`,disabled:!g,onClick:()=>d.mutate(),children:d.isPending?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin mr-1`}),t(`libraryPurge.purging`)]}):t(`libraryPurge.confirmCta`,{count:m})})]})]})})}var C1e=(0,f.lazy)(()=>Dt(()=>import(`./PdfPreviewModal-AgMs-G9b.js`).then(e=>({default:e.PdfPreviewModal})),__vite__mapDeps([0,1]))),w1e=(0,f.lazy)(()=>Dt(()=>import(`./SpreadsheetPreviewModal-D3re3Dlf.js`).then(e=>({default:e.SpreadsheetPreviewModal})),__vite__mapDeps([2,1]))),T1e=(0,f.lazy)(()=>Dt(()=>import(`./ImagePreviewModal-C-WFsOtq.js`).then(e=>({default:e.ImagePreviewModal})),__vite__mapDeps([3,1])));function Z7(e){return e===`csv`||e===`xlsx`||e===`ods`}function Q7(e){return e===`step`||e===`stp`}var E1e=new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`bmp`,`tiff`,`tif`]),D1e=new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`bmp`]);function O1e(e){return E1e.has(e.toLowerCase())}function k1e(e){return D1e.has(e.toLowerCase())}function $7(e){let t=e.file_type;return w5(e)||t===`3mf`||t===`stl`||Q7(t)||t===`pdf`||Z7(t)||k1e(t)}var e9={onClick:e=>e.stopPropagation(),onDoubleClick:e=>e.stopPropagation()};function t9(e){return w5(e)||e.file_type===`3mf`||e.file_type===`stl`||Q7(e.file_type)}function A1e(e){return e===`pdf`?(0,G.jsx)(sc,{className:`w-4 h-4`}):Z7(e)?(0,G.jsx)(oc,{className:`w-4 h-4`}):(0,G.jsx)(Rc,{className:`w-4 h-4`})}function j1e(e){return e===`stl`||e===`pdf`}function M1e({parentId:e,onClose:t,onSave:n,isLoading:r,t:i}){let[a,o]=(0,f.useState)(``);return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg w-full max-w-sm border border-bambu-dark-tertiary`,children:[(0,G.jsx)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary`,children:(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(`fileManager.newFolder`)})}),(0,G.jsxs)(`form`,{onSubmit:t=>{t.preventDefault(),n({name:a.trim(),parent_id:e})},className:`p-4 space-y-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:i(`fileManager.folderName`)}),(0,G.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,G.jsxs)(`div`,{className:`flex justify-end gap-2 pt-2`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:t,children:i(`common.cancel`)}),(0,G.jsx)(Q,{type:`submit`,disabled:!a.trim()||r,children:r?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):i(`common.create`)})]})]})]})})}function N1e({onClose:e,onSave:t,isLoading:n,t:r}){let[i,a]=(0,f.useState)(``),[o,s]=(0,f.useState)(``),[c,l]=(0,f.useState)(!0),[u,d]=(0,f.useState)(!1);return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg w-full max-w-md border border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(hc,{className:`w-5 h-5 text-bambu-green`}),r(`fileManager.linkExternalFolder`)]}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:r(`fileManager.linkExternalFolderDescription`)})]}),(0,G.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,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:r(`fileManager.folderName`)}),(0,G.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,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:r(`fileManager.externalPath`)}),(0,G.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,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:r(`fileManager.externalPathHelp`)})]}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,G.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,G.jsx)(`span`,{className:`text-sm text-white`,children:r(`fileManager.readOnly`)}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[`(`,r(`fileManager.readOnlyHelp`),`)`]})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,G.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,G.jsx)(`span`,{className:`text-sm text-white`,children:r(`fileManager.showHiddenFiles`)})]})]}),(0,G.jsxs)(`div`,{className:`flex justify-end gap-2 pt-2`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:e,children:r(`common.cancel`)}),(0,G.jsx)(Q,{type:`submit`,disabled:!i.trim()||!o.trim()||n,children:n?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):r(`fileManager.linkFolder`)})]})]})]})})}var P1e=`<>:"/\\|?*`;function F1e(e){for(let t of e)if(P1e.includes(t)||t.charCodeAt(0)<32)return t;return null}function I1e({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,f.useState)(s),u=e===`file`?F1e(c):null,d=u?a(`fileManager.invalidFilenameChar`,{char:u}):null;return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg w-full max-w-sm border border-bambu-dark-tertiary`,children:[(0,G.jsx)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary`,children:(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:a(e===`file`?`fileManager.renameFile`:`fileManager.renameFolder`)})}),(0,G.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,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`common.name`)}),(0,G.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,G.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,G.jsx)(`span`,{className:`pr-3 text-bambu-gray text-sm select-none whitespace-nowrap`,children:o})]}),d&&(0,G.jsx)(`p`,{className:`mt-1 text-xs text-red-700 dark:text-red-400`,children:d})]}),(0,G.jsxs)(`div`,{className:`flex justify-end gap-2 pt-2`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:n,children:a(`common.cancel`)}),(0,G.jsx)(Q,{type:`submit`,disabled:!c.trim()||c.trim()===s||!!d||i,children:i?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):a(`common.rename`)})]})]})]})})}function L1e({folders:e,selectedFiles:t,currentFolderId:n,onClose:r,onMove:i,isLoading:a,t:o}){let[s,c]=(0,f.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,G.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg w-full max-w-sm border border-bambu-dark-tertiary`,children:[(0,G.jsx)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary`,children:(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:o(`fileManager.moveFiles`,{count:t.length})})}),(0,G.jsxs)(`div`,{className:`p-4 space-y-4`,children:[(0,G.jsx)(`div`,{className:`max-h-64 overflow-y-auto space-y-1`,children:u.map(e=>(0,G.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,G.jsx)(pc,{className:`w-4 h-4`}),e.name,e.id===n&&(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray ml-auto`,children:[`(`,o(`fileManager.current`),`)`]})]},e.id??`root`))}),(0,G.jsxs)(`div`,{className:`flex justify-end gap-2 pt-2`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:r,children:o(`common.cancel`)}),(0,G.jsx)(Q,{onClick:()=>i(s),disabled:a,children:a?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):o(`common.move`)})]})]})]})})}function R1e({folder:e,onClose:t,onLink:n,isLoading:r,t:i}){let[a,o]=(0,f.useState)(`project`),[s,c]=(0,f.useState)(e.project_id||e.archive_id||null);(0,f.useState)(()=>{e.archive_id&&o(`archive`)});let{data:l}=K({queryKey:[`projects`],queryFn:()=>Z.getProjects(),select:t=>em([...t].sort((e,t)=>e.name.localeCompare(t.name)),e.project_id)}),{data:u}=K({queryKey:[`archives-for-link`],queryFn:()=>Z.getArchives(void 0,void 0,100)}),d=()=>{n(a===`project`?{project_id:s,archive_id:0}:{project_id:0,archive_id:s})},p=()=>{n({project_id:0,archive_id:0})},m=e.project_id||e.archive_id;return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg w-full max-w-md border border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary flex items-center justify-between`,children:[(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(Kc,{className:`w-5 h-5 text-bambu-green`}),i(`fileManager.linkFolder`)]}),(0,G.jsx)(`button`,{onClick:t,className:`p-1 hover:bg-bambu-dark rounded`,children:(0,G.jsx)(nd,{className:`w-5 h-5 text-bambu-gray`})})]}),(0,G.jsxs)(`div`,{className:`p-4 space-y-4`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`fileManager.linkFolderDescription`,{name:e.name})}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.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,G.jsx)(Go,{className:`w-4 h-4`}),i(`fileManager.project`)]}),(0,G.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,G.jsx)(Oo,{className:`w-4 h-4`}),i(`fileManager.archive`)]})]}),(0,G.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,G.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,G.jsx)(`div`,{className:`w-3 h-3 rounded-full flex-shrink-0`,style:{backgroundColor:e.color||`#00ae42`}}),(0,G.jsx)(`span`,{className:`truncate`,children:e.name})]},e.id)):(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray text-center py-4`,children:i(`fileManager.noProjectsFound`)}):u&&u.length>0?u.map(e=>(0,G.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,G.jsx)(nc,{className:`w-4 h-4 text-bambu-gray flex-shrink-0`}),(0,G.jsx)(`span`,{className:`truncate`,children:e.print_name||e.filename})]},e.id)):(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray text-center py-4`,children:i(`fileManager.noArchivesFound`)})})]}),(0,G.jsxs)(`div`,{className:`p-4 border-t border-bambu-dark-tertiary flex justify-between`,children:[m&&(0,G.jsxs)(Q,{variant:`danger`,onClick:p,disabled:r,children:[(0,G.jsx)(Bu,{className:`w-4 h-4 mr-2`}),i(`fileManager.unlink`)]}),(0,G.jsxs)(`div`,{className:`flex gap-2 ${m?``:`ml-auto`}`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:t,children:i(`common.cancel`)}),(0,G.jsx)(Q,{onClick:d,disabled:!s||r,children:r?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):i(`fileManager.link`)})]})]})]})})}function z1e({folder:e,selectedFolderId:t,onSelect:n,onDelete:r,onLink:i,onRename:a,depth:o=0,wrapNames:s=!1,defaultExpanded:c=!0,showModified:l=!1,hasPermission:u,t:d}){let[p,m]=(0,f.useState)(c),[h,g]=(0,f.useState)(!1),_=e.children.length>0,v=e.project_id||e.archive_id,y=e.is_external,b=u(`library:delete_all`)||u(`library:delete_own`)&&e.file_count===0&&!_&&!y&&!v,x=b?void 0:u(`library:delete_own`)&&!y&&!v?d(`fileManager.onlyEmptyFoldersDeletable`):d(`fileManager.noPermissionDeleteFolder`);return(0,G.jsxs)(`div`,{children:[(0,G.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:[_?(0,G.jsx)(`button`,{onClick:e=>{e.stopPropagation(),m(!p)},className:`p-0.5 hover:bg-bambu-dark-tertiary rounded`,children:(0,G.jsx)(cs,{className:`w-3.5 h-3.5 transition-transform ${p?`rotate-90`:``}`})}):(0,G.jsx)(`div`,{className:`w-4.5`}),y?(0,G.jsx)(hc,{className:`w-4 h-4 text-purple-600 dark:text-purple-400 flex-shrink-0`}):(0,G.jsx)(pc,{className:`w-4 h-4 text-bambu-green flex-shrink-0`}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`span`,{className:`block text-sm ${s?`break-all`:`truncate`}`,title:e.name,children:e.name}),l&&e.latest_activity_at&&(0,G.jsxs)(`span`,{className:`mt-0.5 flex items-center gap-1 text-xs text-bambu-gray`,title:d(`fileManager.lastActivity`),children:[(0,G.jsx)(Xo,{className:`w-3 h-3 flex-shrink-0`}),(0,G.jsx)(`span`,{className:`truncate`,children:cp(e.latest_activity_at)})]})]}),v&&(0,G.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,G.jsx)(Kc,{className:`w-3 h-3`}),e.project_name?(0,G.jsx)(Go,{className:`w-3 h-3`}):(0,G.jsx)(Oo,{className:`w-3 h-3`})]}),y&&e.external_readonly&&(0,G.jsx)(`span`,{title:d(`fileManager.readOnly`),children:(0,G.jsx)(Qc,{className:`w-3 h-3 text-amber-600 dark:text-amber-400 flex-shrink-0`})}),e.file_count>0&&(0,G.jsx)(`span`,{className:`flex-shrink-0 text-xs text-bambu-gray`,children:e.file_count}),!v&&!y&&(0,G.jsx)(`button`,{onClick:t=>{t.stopPropagation(),i(e)},className:`flex-shrink-0 p-1 rounded hover:bg-bambu-dark-tertiary`,title:d(`fileManager.linkToProjectOrArchive`),children:(0,G.jsx)(Kc,{className:`w-3.5 h-3.5 text-bambu-gray hover:text-bambu-green`})}),(0,G.jsx)(`div`,{className:`flex-shrink-0 flex items-center gap-0.5 transition-opacity ${s?``:`can-hover:opacity-0 group-hover:opacity-100 group-focus-within:opacity-100`}`,onClick:e=>e.stopPropagation(),children:(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(`button`,{onClick:()=>g(!h),className:`p-1 rounded hover:bg-bambu-dark-tertiary`,children:(0,G.jsx)(Js,{className:`w-3.5 h-3.5 text-bambu-gray`})}),h&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`fixed inset-0 z-10`,onClick:()=>g(!1)}),(0,G.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,G.jsxs)(`button`,{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${u(`library:update_all`)?`text-white hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{u(`library:update_all`)&&(a(e),g(!1))},disabled:!u(`library:update_all`),title:u(`library:update_all`)?void 0:d(`fileManager.noPermissionRenameFolder`),children:[(0,G.jsx)(Dl,{className:`w-3.5 h-3.5`}),d(`common.rename`)]}),(0,G.jsxs)(`button`,{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${u(`library:update_all`)?`text-white hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{u(`library:update_all`)&&(i(e),g(!1))},disabled:!u(`library:update_all`),title:u(`library:update_all`)?void 0:d(`fileManager.noPermissionLinkFolder`),children:[(0,G.jsx)(Kc,{className:`w-3.5 h-3.5`}),d(v?`fileManager.changeLink`:`fileManager.linkTo`)]}),(0,G.jsxs)(`button`,{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${b?`text-red-700 dark:text-red-400 hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{b&&(r(e.id),g(!1))},disabled:!b,title:x,children:[(0,G.jsx)(Pu,{className:`w-3.5 h-3.5`}),d(`common.delete`)]})]})]})]})})]}),_&&p&&(0,G.jsx)(`div`,{children:e.children.map(e=>(0,G.jsx)(z1e,{folder:e,selectedFolderId:t,onSelect:n,onDelete:r,onLink:i,onRename:a,depth:o+1,wrapNames:s,defaultExpanded:c,showModified:l,hasPermission:u,t:d},e.id))})]})}function B1e({file:e,isSelected:t,onSelect:n,onDelete:r,onDownload:i,onPrint:a,onSlice:o,onOpenInSlicer:s,onRunPipeline:c,useSlicerApi:l,desktopSlicer:u,canSlice:d,onPreview:p,onRename:m,onDetails:h,onGenerateThumbnail:g,onTagClick:_,thumbnailVersion:v,hasPermission:y,canModify:b,authEnabled:x,showModified:S,t:C}){let[w,T]=(0,f.useState)(null),E=y(`library:read`),D=b(`library`,`update`,e.created_by_id),O=b(`library`,`delete`,e.created_by_id),k=[];if(a&&w5(e)&&k.push({label:C(`common.print`),icon:(0,G.jsx)(Fl,{className:`w-4 h-4 text-bambu-green`}),onClick:()=>a(e),disabled:!y(`queue:create`),title:y(`queue:create`)?void 0:C(`fileManager.noPermissionAddToQueue`)}),T5(e,!!l,u)&&(l?o:s)&&k.push({label:C(`slice.action`),icon:l?(0,G.jsx)(Ms,{className:`w-4 h-4`}):(0,G.jsx)(Qs,{className:`w-4 h-4`}),onClick:()=>{l?o?.(e):s?.(e)},disabled:!d,title:d?void 0:C(l?`fileManager.noPermissionSlice`:`fileManager.noPermissionDownload`)}),c&&l&&T5(e,!0,u)&&k.push({label:C(`library.runWithPipeline.actionLabel`),icon:(0,G.jsx)(Al,{className:`w-4 h-4`}),onClick:()=>c(e),disabled:!y(`pipelines:run`),title:y(`pipelines:run`)?void 0:C(`library.runWithPipeline.noPermission`)}),p&&$7(e)){let t=t9(e);k.push({label:C(t?`fileManager.preview3d`:`fileManager.preview.open`),icon:t?(0,G.jsx)(Wo,{className:`w-4 h-4`}):A1e(e.file_type),onClick:()=>p(e),disabled:!E,title:E?void 0:C(`fileManager.noPermissionPreview`)})}return k.push({label:C(`common.download`),icon:(0,G.jsx)(Gs,{className:`w-4 h-4`}),onClick:()=>i(e.id),disabled:!y(`library:read`),title:y(`library:read`)?void 0:C(`fileManager.noPermissionDownload`)}),m&&k.push({label:C(`common.rename`),icon:(0,G.jsx)(Dl,{className:`w-4 h-4`}),onClick:()=>m(e),disabled:!D,title:D?void 0:C(`fileManager.noPermissionRenameFile`)}),h&&k.push({label:C(`fileManager.details.title`),icon:(0,G.jsx)(Bc,{className:`w-4 h-4`}),onClick:()=>h(e),disabled:!E,title:E?void 0:C(`fileManager.noPermissionPreview`)}),e.external_url&&k.push({label:C(`fileManager.details.openLink`),icon:(0,G.jsx)(Tc,{className:`w-4 h-4`}),onClick:()=>window.open(e.external_url,`_blank`,`noopener,noreferrer`)}),g&&j1e(e.file_type)&&k.push({label:C(`fileManager.generateThumbnail`),icon:(0,G.jsx)(Rc,{className:`w-4 h-4`}),onClick:()=>g(e),disabled:!D,title:D?void 0:C(`fileManager.noPermissionGenerateThumbnail`)}),k.push({label:C(`common.delete`),icon:(0,G.jsx)(Pu,{className:`w-4 h-4`}),onClick:()=>r(e.id),danger:!0,disabled:!O,title:O?void 0:C(`fileManager.noPermissionDeleteFile`)}),(0,G.jsxs)(`div`,{className:`group relative bg-bambu-dark-secondary rounded-lg border transition-all cursor-pointer ${t?`border-bambu-green ring-1 ring-bambu-green`:`border-bambu-dark-tertiary hover:border-bambu-green/50`}`,onClick:()=>n(e.id),onDoubleClick:()=>p?.(e),children:[(0,G.jsxs)(`div`,{className:`aspect-square bg-bambu-dark flex items-center justify-center overflow-hidden rounded-t-lg`,children:[e.thumbnail_path?(0,G.jsx)(`img`,{src:`${Z.getLibraryFileThumbnailUrl(e.id)}${v?(Z.getLibraryFileThumbnailUrl(e.id).includes(`?`)?`&`:`?`)+`v=${v}`:``}`,alt:e.filename,className:`w-full h-full object-cover`}):e.file_type===`pdf`?(0,G.jsx)(sc,{className:`w-12 h-12 text-bambu-gray/30`}):Z7(e.file_type)?(0,G.jsx)(oc,{className:`w-12 h-12 text-bambu-gray/30`}):O1e(e.file_type)?(0,G.jsx)(Rc,{className:`w-12 h-12 text-bambu-gray/30`}):(0,G.jsx)(nc,{className:`w-12 h-12 text-bambu-gray/30`}),(0,G.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`:Q7(e.file_type)?`bg-amber-500/90 text-white`:e.file_type===`pdf`?`bg-red-500/90 text-white`:Z7(e.file_type)?`bg-teal-500/90 text-white`:`bg-bambu-gray/90 text-white`}`,children:e.file_type.toUpperCase()})]}),(0,G.jsxs)(`div`,{className:`p-3`,children:[(0,G.jsx)(`h3`,{className:`text-sm font-medium text-white truncate`,title:e.print_name||e.filename,children:e.print_name||e.filename}),(0,G.jsxs)(`div`,{className:`flex items-center gap-3 mt-1 text-xs text-bambu-gray`,children:[(0,G.jsx)(`span`,{children:Yd(e.file_size)}),e.print_time_seconds&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(Ts,{className:`w-3 h-3`}),pp(e.print_time_seconds)]})]}),e.sliced_for_model&&(0,G.jsxs)(`div`,{className:`mt-1 text-xs text-bambu-gray flex items-center gap-1`,children:[(0,G.jsx)(Fl,{className:`w-3 h-3`}),e.sliced_for_model]}),(e.variant_count??0)>1&&(0,G.jsxs)(`div`,{className:`mt-1 text-xs text-bambu-green flex items-center gap-1`,children:[(0,G.jsx)(Wc,{className:`w-3 h-3`}),C(`fileManager.variants.badge`,{count:e.variant_count})]}),e.print_count>0&&(0,G.jsx)(`div`,{className:`mt-1 text-xs text-bambu-green`,children:C(`fileManager.printedCount`,{count:e.print_count})}),(e.external_url||e.has_notes||(e.photo_count??0)>0)&&(0,G.jsxs)(`div`,{className:`mt-1 flex items-center gap-2 text-xs text-bambu-gray`,...e9,children:[e.external_url&&(0,G.jsx)(`a`,{href:e.external_url,target:`_blank`,rel:`noopener noreferrer`,className:`p-0.5 rounded hover:text-bambu-green`,title:C(`fileManager.details.openLink`),"aria-label":C(`fileManager.details.openLink`),children:(0,G.jsx)(Tc,{className:`w-3.5 h-3.5`})}),e.has_notes&&(0,G.jsx)(`button`,{type:`button`,onClick:()=>h?.(e),className:`p-0.5 rounded hover:text-bambu-green`,title:C(`fileManager.details.hasNotes`),"aria-label":C(`fileManager.details.hasNotes`),children:(0,G.jsx)(bu,{className:`w-3.5 h-3.5`})}),(e.photo_count??0)>0&&(0,G.jsxs)(`button`,{type:`button`,onClick:()=>h?.(e),className:`flex items-center gap-0.5 p-0.5 rounded hover:text-bambu-green`,title:C(`fileManager.details.photoCount`,{count:e.photo_count}),"aria-label":C(`fileManager.details.photoCount`,{count:e.photo_count}),children:[(0,G.jsx)(es,{className:`w-3.5 h-3.5`}),(0,G.jsx)(`span`,{children:e.photo_count})]})]}),x&&e.created_by_username&&(0,G.jsxs)(`div`,{className:`mt-1 text-xs text-bambu-gray flex items-center gap-1`,children:[(0,G.jsx)(Hu,{className:`w-3 h-3`}),e.created_by_username]}),S&&(0,G.jsxs)(`div`,{className:`mt-1 text-xs text-bambu-gray flex items-center gap-1`,title:C(`fileManager.lastModified`),children:[(0,G.jsx)(Xo,{className:`w-3 h-3`}),cp(e.fs_modified_at??e.created_at)]}),(e.tags?.length??0)>0&&(0,G.jsx)(`div`,{className:`mt-2 flex flex-wrap gap-1`,...e9,children:e.tags.map(e=>(0,G.jsxs)(`button`,{type:`button`,onClick:()=>_?.(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,G.jsx)(wu,{className:`w-2.5 h-2.5 flex-shrink-0`}),(0,G.jsx)(`span`,{className:`truncate`,children:e.name})]},e.id))})]}),(0,G.jsxs)(`div`,{className:`absolute bottom-2 right-2 transition-opacity can-hover:opacity-0 group-hover:opacity-100 group-focus-within:opacity-100`,...e9,children:[(0,G.jsx)(`button`,{onClick:e=>{let t=e.currentTarget.getBoundingClientRect();T({x:t.left,y:t.bottom+4})},className:`p-1.5 rounded bg-bambu-dark-secondary/90 hover:bg-bambu-dark-tertiary`,children:(0,G.jsx)(Js,{className:`w-4 h-4 text-bambu-gray`})}),w&&(0,G.jsx)(JT,{x:w.x,y:w.y,items:k,onClose:()=>T(null)})]}),(0,G.jsx)(`div`,{className:`absolute top-2 left-2 w-5 h-5 rounded border-2 flex items-center justify-center transition-all ${t?`bg-bambu-green border-bambu-green`:`border-white/30 bg-black/30 can-hover:opacity-0 group-hover:opacity-100 group-focus-within:opacity-100`}`,children:t&&(0,G.jsx)(`div`,{className:`w-2 h-2 bg-white rounded-sm`})})]})}function V1e(){let{t:e}=U(),t=no(),{showToast:n}=Zd(),{hasPermission:r,hasAnyPermission:i,canModify:a,authEnabled:o}=Ld(),[s]=ji(),c=$n(),l=s.get(`folder`),[u,d]=(0,f.useState)(l?parseInt(l,10):null),[p,m]=(0,f.useState)(`internal`),[h,g]=(0,f.useState)([]),[_,v]=(0,f.useState)(!1),[y,b]=(0,f.useState)(!1),[x,S]=(0,f.useState)(!1),[C,w]=(0,f.useState)(!1),[T,E]=(0,f.useState)([]),[D,O]=(0,f.useState)(!1),[k,A]=(0,f.useState)(!1),[j,M]=(0,f.useState)(!1),[N,P]=(0,f.useState)([]),[F,I]=(0,f.useState)(null),[L,R]=(0,f.useState)(null),[z,B]=(0,f.useState)(null),[V,ee]=(0,f.useState)(null),[te,ne]=(0,f.useState)(!1),[re,ie]=(0,f.useState)(null),[ae,oe]=(0,f.useState)(null),[se,H]=(0,f.useState)(null),[ce,le]=(0,f.useState)({}),[ue,de]=(0,f.useState)(null),[fe,pe]=(0,f.useState)(null),[me,he]=(0,f.useState)(null),[ge,_e]=(0,f.useState)(null),[ve,ye]=(0,f.useState)(null),[be,xe]=(0,f.useState)(()=>localStorage.getItem(`library-view-mode`)||`grid`),[Se,Ce]=(0,f.useState)(()=>localStorage.getItem(`library-wrap-folders`)===`true`),[we,Te]=(0,f.useState)(()=>localStorage.getItem(`library-collapse-folders`)===`true`),[Ee,De]=(0,f.useState)(()=>localStorage.getItem(`library-folder-sort-field`)===`activity`?`activity`:`name`),[Oe,ke]=(0,f.useState)(()=>localStorage.getItem(`library-folder-sort-direction`)===`desc`?`desc`:`asc`),[Ae,je]=(0,f.useState)(()=>{let e=localStorage.getItem(`library-sidebar-width`);return e?parseInt(e,10):256}),[Me,Ne]=(0,f.useState)(!1),Pe=(0,f.useRef)(null);(0,f.useEffect)(()=>{if(!Me)return;document.body.style.userSelect=`none`,document.body.style.cursor=`col-resize`;let e=e=>{if(!Pe.current)return;let t=Pe.current.parentElement?.getBoundingClientRect();if(!t)return;let n=e.clientX-t.left;je(Math.min(500,Math.max(200,n)))},t=()=>{Ne(!1),document.body.style.userSelect=``,document.body.style.cursor=``,localStorage.setItem(`library-sidebar-width`,String(Ae))};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=``}},[Me,Ae]);let[Fe,Ie]=(0,f.useState)(``),[Le,Re]=(0,f.useState)(`all`),[ze,Be]=(0,f.useState)(``),[Ve,He]=(0,f.useState)(()=>localStorage.getItem(`library-sort-field`)||`name`),[Ue,We]=(0,f.useState)(()=>localStorage.getItem(`library-sort-direction`)||`asc`),[Ge,Ke]=(0,f.useState)(()=>localStorage.getItem(`library-show-modified`)===`true`);(0,f.useEffect)(()=>{let e=s.get(`folder`);e&&d(parseInt(e,10))},[s]);let{data:qe}=K({queryKey:[`settings`],queryFn:()=>Z.getSettings()}),Je=VW(qe?.open_in_slicer,qe?.preferred_slicer),Ye=(0,f.useCallback)(async t=>{try{let{token:e}=await Z.createLibrarySlicerToken(t.id),n=Z.getLibrarySlicerDownloadUrl(t.id,e,t.filename);GW(`${window.location.origin}${n}`,Je)}catch{n(e(`fileManager.toast.openInSlicerFailed`),`error`);let r=Z.getLibraryFileDownloadUrl(t.id);GW(`${window.location.origin}${r}`,Je)}},[Je,n,e]),Xe=(0,f.useCallback)(()=>qe?.use_slicer_api?r(`library:upload`):i(`library:read_all`,`library:read_own`),[qe?.use_slicer_api,r,i]),{data:Ze,isLoading:Qe}=K({queryKey:[`library-folders`],queryFn:()=>Z.getLibraryFolders()}),$e=(0,f.useMemo)(()=>{if(!Ze)return Ze;let e=t=>[...t].sort((e,t)=>{let n=0;if(Ee===`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 Oe===`asc`?n:-n}).map(t=>({...t,children:e(t.children)}));return e(Ze)},[Ze,Ee,Oe]),{data:et}=K({queryKey:[`library-trash-count`],queryFn:async()=>{try{return(await Z.listLibraryTrash(1,0)).total}catch{return 0}},staleTime:3e4}),tt=u!==null&&Fe.trim().length>0,nt=(0,f.useMemo)(()=>[...N].sort((e,t)=>e-t),[N]),{data:rt=[]}=K({queryKey:[`library-tags`],queryFn:Z.getLibraryTags}),it=(0,f.useMemo)(()=>{let e=new Map;for(let t of rt)e.set(t.id,t.name);return e},[rt]);(0,f.useEffect)(()=>{rt.length!==0&&P(e=>{let t=e.filter(e=>it.has(e));return t.length===e.length?e:t})},[rt.length,it]);let at=(0,f.useCallback)(e=>{P(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},[]),{data:ot,isLoading:st}=K({queryKey:[`library-files`,u,p,tt,nt],queryFn:()=>Z.getLibraryFiles(u,!1,void 0,u===null?p:void 0,tt,nt)}),{data:ct}=K({queryKey:[`library-stats`],queryFn:()=>Z.getLibraryStats()}),{data:lt}=K({queryKey:[`users`,`slim`],queryFn:()=>Z.getUsersSlim()}),ut=(0,f.useMemo)(()=>{if(!ot)return[];let e=new Set(ot.map(e=>e.file_type));return Array.from(e).sort()},[ot]),dt=(0,f.useMemo)(()=>{if(!ot)return[];let e=[...ot];if(Fe.trim()){let t=Fe.toLowerCase();e=e.filter(e=>e.filename.toLowerCase().includes(t)||e.print_name&&e.print_name.toLowerCase().includes(t))}if(Le!==`all`&&(e=e.filter(e=>e.file_type===Le)),ze.trim()){let t=ze.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(Ve){case`name`:n=(e.print_name||e.filename).localeCompare(t.print_name||t.filename);break;case`date`:n=(sp(e.fs_modified_at??e.created_at)?.getTime()??0)-(sp(t.fs_modified_at??t.created_at)?.getTime()??0);break;case`size`:n=e.file_size-t.file_size;break;case`type`:n=e.file_type.localeCompare(t.file_type);break;case`prints`:n=e.print_count-t.print_count;break}return Ue===`asc`?n:-n}),e},[ot,Fe,Le,ze,Ve,Ue]),ft=(0,f.useMemo)(()=>{if(!ct||!qe)return!1;let e=(qe.library_disk_warning_gb||5)*1024*1024*1024;return ct.disk_free_bytesZ.createLibraryFolder(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`library-folders`]}),v(!1),n(e(`fileManager.toast.folderCreated`),`success`)},onError:e=>n(e.message,`error`)}),mt=q({mutationFn:async e=>{let t=await Z.createExternalFolder(e);return await Z.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`)}),ht=q({mutationFn:e=>Z.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`)}),gt=q({mutationFn:e=>Z.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`)}}),_t=q({mutationFn:e=>Z.deleteLibraryFile(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`library-stats`]}),t.invalidateQueries({queryKey:[`library-trash-count`]}),g(e=>e.filter(e=>e!==L?.id)),R(null),n(e(`fileManager.toast.fileDeleted`),`success`)},onError:e=>{R(null),n(e.message,`error`)}}),vt=q({mutationFn:e=>Z.createVariantGroup(e.map(e=>({library_file_id:e}))),onSuccess:r=>{t.invalidateQueries({queryKey:[`library-files`]}),n(e(`fileManager.variants.grouped`,{count:r.members.length}),`success`),g([])},onError:e=>n(e.message,`error`)}),yt=q({mutationFn:e=>Z.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`),g([]),R(null)},onError:e=>{R(null),n(e.message,`error`)}}),bt=q({mutationFn:({fileIds:e,folderId:t})=>Z.moveLibraryFiles(e,t),onSuccess:()=>{t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`library-folders`]}),g([]),S(!1),n(e(`fileManager.toast.filesMoved`),`success`)},onError:e=>n(e.message,`error`)}),xt=q({mutationFn:({id:e,data:t})=>Z.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`)}),St=q({mutationFn:({id:e,filename:t})=>Z.updateLibraryFile(e,{filename:t}),onSuccess:()=>{t.invalidateQueries({queryKey:[`library-files`]}),H(null),n(e(`fileManager.toast.fileRenamed`),`success`)},onError:e=>{H(null),n(e.message,`error`)}}),Ct=q({mutationFn:({id:e,name:t})=>Z.updateLibraryFolder(e,{name:t}),onSuccess:()=>{t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`library-files`]}),H(null),n(e(`fileManager.toast.folderRenamed`),`success`)},onError:e=>{H(null),n(e.message,`error`)}}),wt=q({mutationFn:()=>Z.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)}),le(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`)}),Tt=q({mutationFn:e=>Z.batchGenerateStlThumbnails({file_ids:[e]}),onSuccess:r=>{if(t.invalidateQueries({queryKey:[`library-files`]}),r.succeeded>0){let t=r.results[0]?.file_id;t&&le(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`)}),Et=(0,f.useCallback)(e=>{r(`library:read`)&&(w5(e)?c(`/gcode-viewer?library_file=${e.id}`):e.file_type===`3mf`||e.file_type===`stl`||Q7(e.file_type)?de(e):e.file_type===`pdf`?pe(e):Z7(e.file_type)?he(e):k1e(e.file_type)&&ye(e))},[r,c]),Dt=(0,f.useMemo)(()=>{if(!ot||h.length!==1)return null;let e=ot.find(e=>e.id===h[0]);return e&&$7(e)?e:null},[ot,h]),Ot=(0,f.useMemo)(()=>ot?ot.filter(e=>h.includes(e.id)&&w5(e)):[],[ot,h]),kt=(0,f.useMemo)(()=>{if(!ot)return[];let e=ot.filter(e=>h.includes(e.id)&&e.filename.toLowerCase().endsWith(`.stl`));return e.length===h.length?e:[]},[ot,h]),{data:At}=K({queryKey:[`variant-group`,z?.variant_group_id],queryFn:()=>Z.getVariantGroup(z.variant_group_id),enabled:!!z?.variant_group_id}),jt=(0,f.useMemo)(()=>{if(z){if(Ot.length>1)return Ot.map(e=>({id:e.id,filename:e.filename,sliced_for_model:e.sliced_for_model}));if(At&&At.members.length>1)return At.members.map(e=>({id:e.library_file_id,filename:e.filename,sliced_for_model:e.target_model}))}},[z,Ot,At]),Mt=(0,f.useCallback)(e=>{g(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},[]),Nt=(0,f.useCallback)(()=>{dt.length>0&&g(dt.map(e=>e.id))},[dt]),Pt=(0,f.useCallback)(()=>{g([])},[]),Ft=()=>{t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`library-stats`]})},{isDraggingOver:It,dragHandlers:Lt}=KW({disabled:!r(`library:upload`)||C,onFiles:e=>{E(e),w(!0)}}),Rt=(0,f.useCallback)(e=>{if(!e.thumbnail_path&&a(`library`,`update`,e.created_by_id))return n=>{Z.uploadLibraryPreviewThumbnail(e.id,n).then(n=>{n.updated&&(le(t=>({...t,[e.id]:(t[e.id]||0)+1})),t.invalidateQueries({queryKey:[`library-files`]}))}).catch(()=>{})}},[a,t]),zt=e=>{Z.downloadLibraryFile(e).catch(e=>{console.error(`Library file download failed:`,e)})},Bt=()=>{L&&(L.type===`file`?_t.mutate(L.id):L.type===`folder`?gt.mutate(L.id):L.type===`bulk`&&yt.mutate(h))},Vt=gt.isPending||_t.isPending||yt.isPending,Ht=e=>{xe(e),localStorage.setItem(`library-view-mode`,e)},Ut=Qe||st,Wt=(0,f.useMemo)(()=>{if(!u||!Ze)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(Ze)},[u,Ze]);return(0,G.jsxs)(`div`,{className:`p-4 md:p-8 min-h-[calc(100vh-64px)] lg:h-screen flex flex-col relative`,...Lt,children:[It&&(0,G.jsx)(`div`,{className:`fixed inset-0 z-50 bg-bambu-dark/90 flex items-center justify-center pointer-events-none`,children:(0,G.jsxs)(`div`,{className:`border-4 border-dashed border-bambu-green rounded-xl p-12 text-center`,children:[(0,G.jsx)(Vu,{className:`w-16 h-16 mx-auto mb-4 text-bambu-green`}),(0,G.jsx)(`p`,{className:`text-2xl font-semibold text-white mb-2`,children:e(`fileManager.dropFilesHere`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray`,children:e(`fileManager.releaseToUpload`)})]})}),(0,G.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between gap-4 mb-6`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,G.jsx)(pc,{className:`w-7 h-7 text-bambu-green`}),e(`fileManager.title`)]}),(0,G.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:e(`fileManager.subtitle`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center bg-bambu-dark rounded-lg p-1`,children:[(0,G.jsx)(`button`,{onClick:()=>Ht(`grid`),className:`p-1.5 rounded transition-colors ${be===`grid`?`bg-bambu-dark-secondary text-white`:`text-bambu-gray hover:text-white`}`,title:e(`fileManager.gridView`),children:(0,G.jsx)(Gc,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:()=>Ht(`list`),className:`p-1.5 rounded transition-colors ${be===`list`?`bg-bambu-dark-secondary text-white`:`text-bambu-gray hover:text-white`}`,title:e(`fileManager.listView`),children:(0,G.jsx)(Xc,{className:`w-4 h-4`})})]}),(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>wt.mutate(),disabled:wt.isPending||!i(`library:update_own`,`library:update_all`),title:i(`library:update_own`,`library:update_all`)?e(`fileManager.generateThumbnailsForMissing`):e(`fileManager.noPermissionGenerateThumbnail`),children:[wt.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 mr-2 animate-spin`}):(0,G.jsx)(Rc,{className:`w-4 h-4 mr-2`}),e(`fileManager.generateThumbnails`)]}),(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>b(!0),disabled:!r(`library:upload`),title:r(`library:upload`)?e(`fileManager.linkExternalFolder`):e(`fileManager.noPermissionCreateFolder`),children:[(0,G.jsx)(hc,{className:`w-4 h-4 mr-2`}),e(`fileManager.linkExternal`)]}),(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>v(!0),disabled:!r(`library:upload`),title:r(`library:upload`)?void 0:e(`fileManager.noPermissionCreateFolder`),children:[(0,G.jsx)(mc,{className:`w-4 h-4 mr-2`}),e(`fileManager.newFolder`)]}),(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>A(!0),title:e(`fileManager.tags.manageTitle`),children:[(0,G.jsx)(wu,{className:`w-4 h-4 mr-2`}),e(`fileManager.tags.manage`)]}),r(`library:purge`)&&(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>O(!0),title:e(`libraryPurge.headerTooltip`),children:[(0,G.jsx)(Pu,{className:`w-4 h-4 mr-2`}),e(`libraryPurge.headerButton`)]}),i(`library:delete_own`,`library:delete_all`)&&(0,G.jsxs)(Ci,{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,G.jsx)(Pu,{className:`w-4 h-4 mr-2`}),e(`libraryTrash.headerButton`),typeof et==`number`&&et>0&&(0,G.jsx)(`span`,{className:`ml-1.5 px-1.5 py-0.5 text-xs rounded-full bg-bambu-green/20 text-bambu-green`,children:et})]}),(0,G.jsxs)(Q,{onClick:()=>w(!0),disabled:!r(`library:upload`),title:r(`library:upload`)?void 0:e(`fileManager.noPermissionUpload`),children:[(0,G.jsx)(Vu,{className:`w-4 h-4 mr-2`}),e(`common.upload`)]})]})]}),ft&&ct&&qe&&(0,G.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,G.jsx)(Lu,{className:`w-5 h-5 text-amber-500 flex-shrink-0`}),(0,G.jsxs)(`div`,{className:`flex-1`,children:[(0,G.jsx)(`p`,{className:`text-sm text-amber-500 font-medium`,children:e(`fileManager.lowDiskSpaceWarning`)}),(0,G.jsx)(`p`,{className:`text-xs text-amber-500/80`,children:e(`fileManager.lowDiskSpaceDetails`,{free:Yd(ct.disk_free_bytes),total:Yd(ct.disk_total_bytes),threshold:qe.library_disk_warning_gb})})]})]}),ct&&(0,G.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,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,G.jsx)(cc,{className:`w-4 h-4 text-bambu-green`}),(0,G.jsxs)(`span`,{className:`text-bambu-gray`,children:[e(`fileManager.files`),`:`]}),(0,G.jsx)(`span`,{className:`text-white font-medium`,children:ct.total_files})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,G.jsx)(pc,{className:`w-4 h-4 text-blue-600 dark:text-blue-400`}),(0,G.jsxs)(`span`,{className:`text-bambu-gray`,children:[e(`fileManager.folders`),`:`]}),(0,G.jsx)(`span`,{className:`text-white font-medium`,children:ct.total_folders})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,G.jsx)(kc,{className:`w-4 h-4 text-amber-600 dark:text-amber-400`}),(0,G.jsxs)(`span`,{className:`text-bambu-gray`,children:[e(`fileManager.size`),`:`]}),(0,G.jsx)(`span`,{className:`text-white font-medium`,children:Yd(ct.total_size_bytes)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm sm:ml-auto`,children:[(0,G.jsxs)(`span`,{className:`text-bambu-gray`,children:[e(`fileManager.free`),`:`]}),(0,G.jsx)(`span`,{className:`font-medium ${ft?`text-amber-500`:`text-white`}`,children:Yd(ct.disk_free_bytes)})]})]}),(0,G.jsxs)(`div`,{className:`flex-1 flex flex-col lg:flex-row gap-4 lg:gap-6 min-h-0`,children:[(0,G.jsx)(`div`,{className:`lg:hidden`,children:(0,G.jsxs)(`select`,{value:u===null?`__top:${p}`:String(u),onChange:e=>{let t=e.target.value;t.startsWith(`__top:`)?(d(null),m(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,G.jsxs)(`option`,{value:`__top:internal`,children:[`📁 `,e(`fileManager.allFiles`)]}),Ze?.some(e=>e.is_external)&&(0,G.jsxs)(`option`,{value:`__top:external`,children:[`🔗 `,e(`fileManager.allExternal`)]}),$e&&(()=>{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($e).map(e=>(0,G.jsxs)(`option`,{value:e.id,children:[`│ `.repeat(e.depth),`📂 `,e.name,` `,e.fileCount>0?`(${e.fileCount})`:``]},e.id))})()]})}),(0,G.jsxs)(`div`,{ref:Pe,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:`${Ae}px`},children:[(0,G.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 ${Me?`bg-bambu-green`:`hover:bg-bambu-green/50`}`,onMouseDown:e=>{e.preventDefault(),Ne(!0)},onDoubleClick:()=>{je(256),localStorage.setItem(`library-sidebar-width`,`256`)},title:e(`fileManager.dragToResizeTooltip`),children:(0,G.jsxs)(`div`,{className:`flex flex-col gap-1 opacity-0 group-hover/resize:opacity-100 transition-opacity ${Me?`opacity-100`:``}`,children:[(0,G.jsx)(`div`,{className:`w-0.5 h-0.5 rounded-full bg-white/70`}),(0,G.jsx)(`div`,{className:`w-0.5 h-0.5 rounded-full bg-white/70`}),(0,G.jsx)(`div`,{className:`w-0.5 h-0.5 rounded-full bg-white/70`})]})}),(0,G.jsxs)(`div`,{className:`p-3 border-b border-bambu-dark-tertiary flex items-center justify-between`,children:[(0,G.jsx)(`h2`,{className:`text-sm font-medium text-white`,children:e(`fileManager.folders`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,G.jsxs)(`select`,{value:Ee,onChange:e=>{let t=e.target.value===`activity`?`activity`:`name`;De(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,G.jsx)(`option`,{value:`name`,children:e(`fileManager.folderSortByName`)}),(0,G.jsx)(`option`,{value:`activity`,children:e(`fileManager.folderSortByActivity`)})]}),(0,G.jsx)(`button`,{onClick:()=>{let e=Oe===`asc`?`desc`:`asc`;ke(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(Oe===`asc`?`fileManager.ascending`:`fileManager.descending`),"aria-label":e(Oe===`asc`?`fileManager.ascending`:`fileManager.descending`),children:Oe===`asc`?(0,G.jsx)(Fo,{className:`w-3.5 h-3.5`}):(0,G.jsx)(ko,{className:`w-3.5 h-3.5`})}),(0,G.jsx)(`button`,{onClick:()=>{let e=!we;Te(e),localStorage.setItem(`library-collapse-folders`,String(e))},className:`text-xs px-1.5 py-0.5 rounded transition-colors ${we?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:text-white hover:bg-bambu-dark`}`,title:e(we?`fileManager.expandFoldersByDefault`:`fileManager.collapseFoldersByDefault`),children:e(`fileManager.collapse`)}),(0,G.jsx)(`button`,{onClick:()=>{let e=!Se;Ce(e),localStorage.setItem(`library-wrap-folders`,String(e))},className:`text-xs px-1.5 py-0.5 rounded transition-colors ${Se?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:text-white hover:bg-bambu-dark`}`,title:e(Se?`fileManager.disableTextWrapping`:`fileManager.enableTextWrapping`),children:e(`fileManager.wrap`)})]})]}),(0,G.jsxs)(`div`,{className:`flex-1 overflow-y-auto p-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-1.5 rounded cursor-pointer transition-colors ${u===null&&p===`internal`?`bg-bambu-green/20 text-bambu-green`:`hover:bg-bambu-dark text-white`}`,onClick:()=>{d(null),m(`internal`)},children:[(0,G.jsx)(nc,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`text-sm`,children:e(`fileManager.allFiles`)})]}),Ze?.some(e=>e.is_external)&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-1.5 rounded cursor-pointer transition-colors ${u===null&&p===`external`?`bg-bambu-green/20 text-bambu-green`:`hover:bg-bambu-dark text-white`}`,onClick:()=>{d(null),m(`external`)},children:[(0,G.jsx)(hc,{className:`w-4 h-4 text-purple-600 dark:text-purple-400`}),(0,G.jsx)(`span`,{className:`text-sm`,children:e(`fileManager.allExternal`)})]}),$e?.map(t=>(0,G.jsx)(z1e,{folder:t,selectedFolderId:u,onSelect:d,onDelete:e=>R({type:`folder`,id:e}),onLink:I,onRename:e=>H({type:`folder`,id:e.id,name:e.name}),wrapNames:Se,defaultExpanded:!we,showModified:Ge,hasPermission:r,t:e},`${t.id}-${we?`c`:`e`}`))]})]}),(0,G.jsxs)(`div`,{className:`flex-1 flex flex-col lg:flex-row min-w-0 min-h-0 gap-4 lg:gap-6`,children:[(0,G.jsxs)(`div`,{className:`flex-1 flex flex-col min-w-0 min-h-0`,children:[rt.length>0&&(0,G.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,G.jsx)(`span`,{className:`text-xs text-bambu-gray font-medium shrink-0`,children:e(`fileManager.tags.filterLabel`)}),rt.map(e=>{let t=N.includes(e.id);return(0,G.jsxs)(`button`,{type:`button`,onClick:()=>at(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,G.jsx)(wu,{className:`w-3 h-3`}),(0,G.jsx)(`span`,{children:e.name}),t&&(0,G.jsx)(nd,{className:`w-3 h-3`})]},e.id)}),N.length>0&&(0,G.jsx)(`button`,{type:`button`,onClick:()=>P([]),className:`ml-auto text-xs text-bambu-gray hover:text-white shrink-0`,children:e(`fileManager.tags.clearAll`)})]}),Wt?.is_external&&(0,G.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,G.jsx)(hc,{className:`w-5 h-5 text-purple-600 dark:text-purple-400 flex-shrink-0`}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-sm font-medium text-purple-700 dark:text-purple-300`,children:e(`fileManager.externalFolder`)}),Wt.external_readonly&&(0,G.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,G.jsx)(Qc,{className:`w-3 h-3`}),e(`fileManager.readOnly`)]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray truncate font-mono`,title:Wt.external_path||``,children:Wt.external_path})]}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:()=>u&&ht.mutate(u),disabled:ht.isPending,title:e(`fileManager.scanFolder`),children:[ht.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(zl,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`ml-1.5`,children:e(`fileManager.scanFolder`)})]})]}),ot&&ot.length>0&&(0,G.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,G.jsxs)(`div`,{className:`relative w-full sm:w-auto sm:flex-1 sm:max-w-xs`,children:[(0,G.jsx)(Yl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,G.jsx)(`input`,{type:`text`,placeholder:e(`fileManager.searchFiles`),value:Fe,onChange:e=>Ie(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`}),tt&&(0,G.jsx)(`span`,{className:`absolute -bottom-4 left-0 text-[10px] text-bambu-gray whitespace-nowrap`,title:e(`fileManager.searchSubfoldersHint`),children:e(`fileManager.searchSubfoldersHint`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(yc,{className:`w-4 h-4 text-bambu-gray hidden sm:block`}),(0,G.jsxs)(`select`,{value:Le,onChange:e=>Re(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,G.jsx)(`option`,{value:`all`,children:e(`fileManager.allTypes`)}),ut.map(e=>(0,G.jsx)(`option`,{value:e,children:e.toUpperCase()},e))]})]}),o&&(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(`input`,{type:`text`,placeholder:e(`fileManager.filterByUser`,{defaultValue:`Filter by user`}),value:ze,onChange:e=>Be(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 ${ze?`pr-7`:``}`,style:ze?{WebkitAppearance:`none`,MozAppearance:`textfield`}:void 0}),ze&&(0,G.jsx)(`button`,{onClick:()=>Be(``),className:`absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white z-10`,children:(0,G.jsx)(nd,{className:`w-3 h-3`})}),(0,G.jsx)(`datalist`,{id:`usernames-list`,children:lt?.map(e=>(0,G.jsx)(`option`,{value:e.username},e.id))})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`select`,{value:Ve,onChange:e=>{let t=e.target.value;He(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,G.jsx)(`option`,{value:`name`,children:e(`common.name`)}),(0,G.jsx)(`option`,{value:`date`,children:e(`common.date`)}),(0,G.jsx)(`option`,{value:`size`,children:e(`fileManager.size`)}),(0,G.jsx)(`option`,{value:`type`,children:e(`common.type`)}),(0,G.jsx)(`option`,{value:`prints`,children:e(`fileManager.prints`)})]}),(0,G.jsx)(`button`,{onClick:()=>We(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(Ue===`asc`?`fileManager.ascending`:`fileManager.descending`),children:Ue===`asc`?(0,G.jsx)(Fo,{className:`w-4 h-4 text-white`}):(0,G.jsx)(ko,{className:`w-4 h-4 text-white`})}),(0,G.jsx)(`button`,{onClick:()=>Ke(e=>{let t=!e;return localStorage.setItem(`library-show-modified`,String(t)),t}),className:`p-1.5 rounded bg-bambu-dark border transition-colors ${Ge?`border-bambu-green text-bambu-green`:`border-bambu-dark-tertiary text-white hover:border-bambu-green`}`,title:e(Ge?`fileManager.hideModified`:`fileManager.showModified`),"aria-pressed":Ge,children:(0,G.jsx)(Xo,{className:`w-4 h-4`})})]}),(Fe||Le!==`all`||ze)&&(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray hidden sm:inline`,children:e(`fileManager.resultsCount`,{showing:dt.length,total:ot.length})})]}),dt.length>0&&(0,G.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:[h.length===dt.length&&h.length>0?(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:Pt,children:[(0,G.jsx)(_u,{className:`w-4 h-4 sm:mr-1`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`fileManager.deselectAll`)})]}):(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:Nt,children:[(0,G.jsx)(hu,{className:`w-4 h-4 sm:mr-1`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`fileManager.selectAll`)})]}),h.length>0&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray ml-2`,children:e(`fileManager.selected`,{count:h.length})}),(0,G.jsx)(`div`,{className:`hidden sm:block flex-1`}),(0,G.jsxs)(`div`,{className:`w-full sm:w-auto flex flex-wrap items-center gap-2 mt-2 sm:mt-0`,children:[Dt&&(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:()=>Et(Dt),disabled:!r(`library:read`),title:r(`library:read`)?void 0:e(`fileManager.noPermissionPreview`),children:[(0,G.jsx)(ec,{className:`w-4 h-4 sm:mr-1`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`fileManager.preview.open`)})]}),Ot.length>=1&&(0,G.jsxs)(Q,{variant:`primary`,size:`sm`,onClick:()=>B(Ot[0]),disabled:!r(`queue:create`),title:r(`queue:create`)?void 0:e(`fileManager.noPermissionAddToQueue`),children:[(0,G.jsx)(Fl,{className:`w-4 h-4 sm:mr-1`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:Ot.length>1?e(`fileManager.variants.printAlternatives`,{count:Ot.length}):e(`common.print`)})]}),Ot.length>=2&&!Ot.some(e=>e.variant_group_id)&&(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:()=>vt.mutate(Ot.map(e=>e.id)),disabled:vt.isPending||!i(`library:update_own`,`library:update_all`),title:e(`fileManager.variants.groupTooltip`),children:[(0,G.jsx)(Wc,{className:`w-4 h-4 sm:mr-1`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`fileManager.variants.groupAction`)})]}),kt.length>=1&&(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:()=>ne(!0),disabled:!r(`library:upload`),title:e(`fileManager.combine.tooltip`),children:[(0,G.jsx)(Ps,{className:`w-4 h-4 sm:mr-1`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`fileManager.combine.action`)})]}),(0,G.jsxs)(Q,{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,G.jsx)(hl,{className:`w-4 h-4 sm:mr-1`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.move`)})]}),(0,G.jsxs)(Q,{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,G.jsx)(wu,{className:`w-4 h-4 sm:mr-1`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`fileManager.tags.tagAction`)})]}),(0,G.jsxs)(Q,{variant:`danger`,size:`sm`,onClick:()=>{h.length===1?R({type:`file`,id:h[0]}):R({type:`bulk`,id:0,count:h.length})},disabled:!i(`library:delete_own`,`library:delete_all`),title:i(`library:delete_own`,`library:delete_all`)?void 0:e(`fileManager.noPermissionDeleteFiles`),children:[(0,G.jsx)(Pu,{className:`w-4 h-4 sm:mr-1`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.delete`)})]}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:Pt,children:[(0,G.jsx)(nd,{className:`w-4 h-4 sm:mr-1`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.clear`)})]})]})]})]}),Ut?(0,G.jsx)(`div`,{className:`flex-1 flex items-center justify-center`,children:(0,G.jsxs)(`div`,{className:`flex flex-col items-center gap-3`,children:[(0,G.jsx)(Y,{className:`w-8 h-8 animate-spin text-bambu-green`}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`fileManager.loadingFiles`)})]})}):ot?.length===0?(0,G.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center`,children:[(0,G.jsx)(`div`,{className:`p-4 bg-bambu-dark rounded-2xl mb-4`,children:(0,G.jsx)(nc,{className:`w-12 h-12 text-bambu-gray/50`})}),(0,G.jsx)(`h3`,{className:`text-lg font-medium text-white mb-2`,children:e(u===null?p===`external`?`fileManager.externalIsEmpty`:`fileManager.noFilesYet`:`fileManager.folderIsEmpty`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-center max-w-md mb-6`,children:e(u===null?p===`external`?`fileManager.externalEmptyDescription`:`fileManager.noFilesDescription`:`fileManager.folderEmptyDescription`)}),(0,G.jsxs)(Q,{onClick:()=>w(!0),disabled:!r(`library:upload`),title:r(`library:upload`)?void 0:e(`fileManager.noPermissionUpload`),children:[(0,G.jsx)(Ml,{className:`w-4 h-4 mr-2`}),e(`fileManager.uploadFiles`)]})]}):dt.length===0?(0,G.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center`,children:[(0,G.jsx)(`div`,{className:`p-4 bg-bambu-dark rounded-2xl mb-4`,children:(0,G.jsx)(Yl,{className:`w-12 h-12 text-bambu-gray/50`})}),(0,G.jsx)(`h3`,{className:`text-lg font-medium text-white mb-2`,children:e(`fileManager.noMatchingFiles`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-center max-w-md mb-6`,children:e(`fileManager.noMatchingFilesDescription`)}),(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>{Ie(``),Re(`all`)},children:e(`fileManager.clearFilters`)})]}):be===`grid`?(0,G.jsx)(`div`,{className:`flex-1 lg:overflow-y-auto`,children:(0,G.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:dt.map(t=>(0,G.jsx)(B1e,{file:t,isSelected:h.includes(t.id),t:e,onSelect:Mt,onDelete:e=>R({type:`file`,id:e}),onDownload:zt,onPrint:B,onSlice:ee,onOpenInSlicer:Ye,desktopSlicer:Je,onRunPipeline:oe,useSlicerApi:qe?.use_slicer_api??!1,canSlice:Xe(),onPreview:Et,onRename:e=>H({type:`file`,id:e.id,name:e.filename}),onDetails:_e,onGenerateThumbnail:e=>Tt.mutate(e.id),onTagClick:at,thumbnailVersion:ce[t.id],hasPermission:r,canModify:a,authEnabled:o,showModified:Ge},t.id))})}):(0,G.jsx)(`div`,{className:`flex-1 lg:overflow-y-auto`,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary overflow-x-auto`,children:[(0,G.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,G.jsx)(`div`,{className:`w-6`}),(0,G.jsx)(`div`,{children:e(`common.name`)}),o&&(0,G.jsx)(`div`,{children:e(`fileManager.uploadedBy`,{defaultValue:`Uploaded By`})}),(0,G.jsx)(`div`,{children:e(`common.type`)}),(0,G.jsx)(`div`,{children:e(`fileManager.size`)}),(0,G.jsx)(`div`,{children:e(`fileManager.prints`)}),(0,G.jsx)(`div`,{children:e(`fileManager.tags.title`)}),(0,G.jsx)(`div`,{})]}),dt.map(t=>(0,G.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 ${h.includes(t.id)?`bg-bambu-green/10`:``}`,onClick:()=>Mt(t.id),onDoubleClick:()=>Et(t),children:[(0,G.jsx)(`div`,{className:`w-5 h-5 rounded border-2 flex items-center justify-center ${h.includes(t.id)?`bg-bambu-green border-bambu-green`:`border-bambu-gray/50`}`,children:h.includes(t.id)&&(0,G.jsx)(`div`,{className:`w-2 h-2 bg-white rounded-sm`})}),(0,G.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0`,children:[(0,G.jsxs)(`div`,{className:`relative group/thumb`,children:[(0,G.jsx)(`div`,{className:`w-10 h-10 rounded bg-bambu-dark flex-shrink-0 overflow-hidden`,children:t.thumbnail_path?(0,G.jsx)(`img`,{src:`${Z.getLibraryFileThumbnailUrl(t.id)}${ce[t.id]?(Z.getLibraryFileThumbnailUrl(t.id).includes(`?`)?`&`:`?`)+`v=${ce[t.id]}`:``}`,alt:``,className:`w-full h-full object-cover`}):(0,G.jsx)(`div`,{className:`w-full h-full flex items-center justify-center`,children:t.file_type===`pdf`?(0,G.jsx)(sc,{className:`w-5 h-5 text-bambu-gray/50`}):Z7(t.file_type)?(0,G.jsx)(oc,{className:`w-5 h-5 text-bambu-gray/50`}):O1e(t.file_type)?(0,G.jsx)(Rc,{className:`w-5 h-5 text-bambu-gray/50`}):(0,G.jsx)(nc,{className:`w-5 h-5 text-bambu-gray/50`})})}),t.thumbnail_path&&(0,G.jsx)(`div`,{className:`absolute left-0 top-full mt-2 z-50 hidden group-hover/thumb:block`,children:(0,G.jsx)(`div`,{className:`w-48 h-48 rounded-lg bg-bambu-dark-secondary border border-bambu-dark-tertiary shadow-xl overflow-hidden`,children:(0,G.jsx)(`img`,{src:`${Z.getLibraryFileThumbnailUrl(t.id)}${ce[t.id]?(Z.getLibraryFileThumbnailUrl(t.id).includes(`?`)?`&`:`?`)+`v=${ce[t.id]}`:``}`,alt:t.filename,className:`w-full h-full object-contain`})})})]}),(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[(0,G.jsx)(`span`,{className:`text-sm text-white truncate`,children:t.print_name||t.filename}),t.external_url&&(0,G.jsx)(`a`,{href:t.external_url,target:`_blank`,rel:`noopener noreferrer`,...e9,className:`flex-shrink-0 text-bambu-gray hover:text-bambu-green`,title:e(`fileManager.details.openLink`),"aria-label":e(`fileManager.details.openLink`),children:(0,G.jsx)(Tc,{className:`w-3.5 h-3.5`})}),t.has_notes&&(0,G.jsx)(`span`,{className:`flex-shrink-0 text-bambu-gray`,title:e(`fileManager.details.hasNotes`),"aria-label":e(`fileManager.details.hasNotes`),children:(0,G.jsx)(bu,{className:`w-3.5 h-3.5`})}),(t.photo_count??0)>0&&(0,G.jsxs)(`span`,{className:`flex-shrink-0 flex items-center gap-0.5 text-xs text-bambu-gray`,title:e(`fileManager.details.photoCount`,{count:t.photo_count}),children:[(0,G.jsx)(es,{className:`w-3.5 h-3.5`}),t.photo_count]})]}),Ge&&(0,G.jsxs)(`div`,{className:`text-xs text-bambu-gray flex items-center gap-1 mt-0.5`,title:e(`fileManager.lastModified`),children:[(0,G.jsx)(Xo,{className:`w-3 h-3 flex-shrink-0`}),(0,G.jsx)(`span`,{className:`truncate`,children:cp(t.fs_modified_at??t.created_at)})]})]})]}),o&&(0,G.jsx)(`div`,{className:`text-sm text-bambu-gray flex items-center gap-1`,children:t.created_by_username?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Hu,{className:`w-3 h-3`}),(0,G.jsx)(`span`,{className:`truncate`,children:t.created_by_username})]}):`-`}),(0,G.jsx)(`div`,{children:(0,G.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`:Q7(t.file_type)?`bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-400`:t.file_type===`pdf`?`bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400`:Z7(t.file_type)?`bg-teal-100 dark:bg-teal-500/20 text-teal-700 dark:text-teal-400`:`bg-bambu-gray/20 text-bambu-gray`}`,children:t.file_type.toUpperCase()})}),(0,G.jsx)(`div`,{className:`text-sm text-bambu-gray`,children:Yd(t.file_size)}),(0,G.jsx)(`div`,{className:`text-sm text-bambu-gray`,children:t.print_count>0?`${t.print_count}x`:`-`}),(0,G.jsx)(`div`,{className:`min-w-0`,...e9,children:!t.tags||t.tags.length===0?(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray/50`,children:`-`}):(0,G.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:t.tags.map(e=>(0,G.jsxs)(`button`,{type:`button`,onClick:()=>at(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,G.jsx)(wu,{className:`w-2.5 h-2.5 flex-shrink-0`}),(0,G.jsx)(`span`,{className:`truncate`,children:e.name})]},e.id))})}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,...e9,children:[w5(t)&&(0,G.jsx)(G.Fragment,{children:(0,G.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,G.jsx)(Fl,{className:`w-4 h-4`})})}),T5(t,!!qe?.use_slicer_api,Je)&&(0,G.jsx)(`button`,{onClick:()=>{Xe()&&(qe?.use_slicer_api?ee:Ye)(t)},className:`p-1.5 rounded transition-colors ${Xe()?`hover:bg-bambu-dark text-bambu-gray hover:text-bambu-green`:`text-bambu-gray/50 cursor-not-allowed`}`,title:Xe()?e(`slice.action`):qe?.use_slicer_api?e(`fileManager.noPermissionSlice`):e(`fileManager.noPermissionDownload`),disabled:!Xe(),children:qe?.use_slicer_api?(0,G.jsx)(Ms,{className:`w-4 h-4`}):(0,G.jsx)(Qs,{className:`w-4 h-4`})}),(qe?.use_slicer_api??!1)&&T5(t,!0,Je)&&(0,G.jsx)(`button`,{onClick:()=>r(`pipelines:run`)&&oe(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,G.jsx)(Al,{className:`w-4 h-4`})}),t9(t)&&(0,G.jsx)(`button`,{onClick:()=>Et(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`)?e(`fileManager.preview3d`):e(`fileManager.noPermissionPreview`),disabled:!r(`library:read`),children:(0,G.jsx)(Wo,{className:`w-4 h-4`})}),!t9(t)&&$7(t)&&(0,G.jsx)(`button`,{onClick:()=>Et(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`)?e(`fileManager.preview.open`):e(`fileManager.noPermissionPreview`),disabled:!r(`library:read`),children:A1e(t.file_type)}),(0,G.jsx)(`button`,{onClick:()=>r(`library:read`)&&zt(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,G.jsx)(Gs,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:()=>r(`library:read`)&&_e(t),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(`fileManager.details.title`):e(`fileManager.noPermissionPreview`),disabled:!r(`library:read`),children:(0,G.jsx)(Bc,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:()=>a(`library`,`update`,t.created_by_id)&&H({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,G.jsx)(Dl,{className:`w-4 h-4`})}),j1e(t.file_type)&&(0,G.jsx)(`button`,{onClick:()=>a(`library`,`update`,t.created_by_id)&&Tt.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:Tt.isPending||!a(`library`,`update`,t.created_by_id),children:(0,G.jsx)(Rc,{className:`w-4 h-4`})}),(0,G.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,G.jsx)(Pu,{className:`w-4 h-4`})})]})]},t.id))]})})]}),u!==null&&(0,G.jsx)(v1e,{folderId:u})]})]}),_&&(0,G.jsx)(M1e,{parentId:u,onClose:()=>v(!1),onSave:e=>pt.mutate(e),isLoading:pt.isPending,t:e}),y&&(0,G.jsx)(N1e,{onClose:()=>b(!1),onSave:e=>mt.mutate(e),isLoading:mt.isPending,t:e}),x&&Ze&&(0,G.jsx)(L1e,{folders:Ze,selectedFiles:h,currentFolderId:u,onClose:()=>S(!1),onMove:e=>bt.mutate({fileIds:h,folderId:e}),isLoading:bt.isPending,t:e}),C&&(0,G.jsx)(BU,{folderId:u,onClose:()=>{w(!1),E([])},onUploadComplete:Ft,initialFiles:T.length>0?T:void 0}),D&&(0,G.jsx)(S1e,{onClose:()=>O(!1)}),(0,G.jsx)(y1e,{open:k,onClose:()=>A(!1),onPickTag:e=>{N.includes(e)||P(t=>[...t,e])}}),(0,G.jsx)(Qqe,{open:j,fileIds:h,onClose:()=>M(!1)}),F&&(0,G.jsx)(R1e,{folder:F,onClose:()=>I(null),onLink:e=>xt.mutate({id:F.id,data:e}),isLoading:xt.isPending,t:e}),L&&(0,G.jsx)(uf,{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:Bt,onCancel:()=>R(null)}),z&&(!z.variant_group_id||At!==void 0)&&(0,G.jsx)(Lm,{mode:`create`,libraryFileId:jt?.[0]?.id??z.id,variantFiles:jt,archiveName:jt&&jt.length>1?`${jt[0].filename} ${e(`common.plusNMore`,{count:jt.length-1})}`:z.print_name||z.filename,onClose:()=>B(null),onSuccess:()=>{B(null),g([]),t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`queue`]}),t.invalidateQueries({queryKey:[`archives`]})}}),V&&(0,G.jsx)(LW,{source:{kind:`libraryFile`,id:V.id,filename:V.filename},onClose:()=>ee(null)}),te&&kt.length>0&&(0,G.jsx)(Zqe,{files:kt,folderId:u,canSlice:!!qe?.use_slicer_api&&Xe(),onClose:()=>ne(!1),onCombined:(e,t)=>{ne(!1),g([]),t&&ie({id:e.id,filename:e.filename})}}),re&&(0,G.jsx)(LW,{source:{kind:`libraryFile`,id:re.id,filename:re.filename},onClose:()=>ie(null),defaultAutoArrange:!0}),ae&&(0,G.jsx)(BW,{source:{kind:`libraryFile`,id:ae.id,filename:ae.filename},onClose:()=>oe(null)}),ue&&(0,G.jsx)(Yqe,{libraryFileId:ue.id,title:ue.print_name||ue.filename,fileType:ue.file_type,onClose:()=>de(null),onSnapshot:Q7(ue.file_type)?Rt(ue):void 0,onSliceWithBambuddy:T5(ue,!0,Je)&&r(`library:upload`)?()=>{let e=ue;de(null),ee(e)}:void 0}),(fe||me||ve)&&(0,G.jsxs)(f.Suspense,{fallback:null,children:[fe&&(0,G.jsx)(C1e,{libraryFileId:fe.id,filename:fe.print_name||fe.filename,fileSize:fe.file_size,onClose:()=>pe(null),onSnapshot:Rt(fe)}),me&&(0,G.jsx)(w1e,{libraryFileId:me.id,filename:me.print_name||me.filename,fileType:me.file_type,fileSize:me.file_size,onClose:()=>he(null),onSnapshot:Rt(me)}),ve&&(0,G.jsx)(T1e,{libraryFileId:ve.id,filename:ve.print_name||ve.filename,fileSize:ve.file_size,onClose:()=>ye(null)})]}),ge&&(0,G.jsx)(b1e,{file:ge,canEdit:a(`library`,`update`,ge.created_by_id),onClose:()=>_e(null)}),se&&(0,G.jsx)(I1e,{type:se.type,currentName:se.name,onClose:()=>H(null),onSave:e=>{se.type===`file`?St.mutate({id:se.id,filename:e}):Ct.mutate({id:se.id,name:e})},isLoading:St.isPending||Ct.isPending,t:e})]})}function H1e(e){let t=sp(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 U1e(e){let t=sp(e);return t?t.toLocaleString():e}function W1e(){let{t:e}=U(),t=$n(),n=no(),{showToast:r}=Zd(),{hasPermission:i,authEnabled:a}=Ld(),[o,s]=(0,f.useState)(null),[c,l]=(0,f.useState)(new Set),u=!a||i(`library:purge`),d=K({queryKey:[`library-trash`],queryFn:()=>Z.listLibraryTrash(200,0)}),p=K({queryKey:[`library-trash-settings`],queryFn:()=>Z.getLibraryTrashSettings(),enabled:u}),[m,h]=(0,f.useState)(null);(0,f.useEffect)(()=>{p.data&&m===null&&h(p.data.retention_days)},[p.data,m]);let g=q({mutationFn:e=>{let t=p.data;return Z.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`)}),_=q({mutationFn:e=>Z.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`)}),v=q({mutationFn:e=>Z.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`)}),y=q({mutationFn:()=>Z.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=q({mutationFn:e=>Promise.all(e.map(e=>Z.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=q({mutationFn:e=>Promise.all(e.map(e=>Z.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,f.useMemo)(()=>d.data?.items??[],[d.data?.items]),C=d.data?.retention_days??30,w=(0,f.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,G.jsxs)(`div`,{className:`p-6 max-w-screen-2xl mx-auto`,children:[(0,G.jsx)(`div`,{className:`flex items-center gap-3 mb-4`,children:(0,G.jsxs)(Ci,{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,G.jsx)(jo,{className:`w-4 h-4`}),` `,e(`libraryTrash.backToFiles`)]})}),(0,G.jsxs)(`div`,{className:`flex items-start justify-between mb-6 gap-4 flex-wrap`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h1`,{className:`text-2xl font-bold text-gray-900 dark:text-gray-100`,children:e(`libraryTrash.title`)}),(0,G.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,G.jsxs)(Q,{variant:`secondary`,onClick:()=>s({type:`empty`}),className:`text-red-600 dark:text-red-400`,children:[(0,G.jsx)(Pu,{className:`w-4 h-4 mr-1`}),e(`libraryTrash.emptyTrash`)]})]}),u&&p.data&&(0,G.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,G.jsx)(`label`,{htmlFor:`retention-days`,className:`text-sm font-medium text-gray-700 dark:text-gray-300`,children:e(`libraryTrash.retentionLabel`)}),(0,G.jsx)(`input`,{id:`retention-days`,type:`number`,min:1,max:365,value:m??p.data.retention_days,onChange:e=>h(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,G.jsx)(`span`,{className:`text-sm text-gray-600 dark:text-gray-400`,children:e(`libraryTrash.days`)}),(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>m!=null&&g.mutate(m),disabled:g.isPending||m==null||m===p.data.retention_days,className:`ml-auto`,children:[(0,G.jsx)(Wl,{className:`w-4 h-4 mr-1`}),e(`common.save`)]})]}),d.isLoading?(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-gray-500 dark:text-gray-400`,children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),` `,e(`libraryTrash.loading`)]}):S.length===0?(0,G.jsx)(`div`,{className:`border border-dashed border-gray-300 dark:border-gray-700 rounded-lg p-12 text-center`,children:(0,G.jsx)(`p`,{className:`text-gray-500 dark:text-gray-400`,children:e(`libraryTrash.empty`)})}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,G.jsx)(`div`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:e(`libraryTrash.summary`,{count:S.length,size:Yd(w)})}),c.size>0&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,G.jsx)(`span`,{className:`text-gray-600 dark:text-gray-400`,children:e(`libraryTrash.selectionCount`,{count:c.size})}),(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>b.mutate(Array.from(c)),disabled:b.isPending,children:[(0,G.jsx)(Vl,{className:`w-4 h-4 mr-1`}),e(`libraryTrash.bulkRestore`)]}),(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>s({type:`bulkDelete`,count:c.size}),disabled:x.isPending,className:`text-red-600 dark:text-red-400`,children:[(0,G.jsx)(Pu,{className:`w-4 h-4 mr-1`}),e(`libraryTrash.bulkPurge`)]})]})]}),(0,G.jsx)(`div`,{className:`border border-gray-200 dark:border-gray-700 rounded-lg overflow-x-auto`,children:(0,G.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,G.jsx)(`thead`,{className:`bg-gray-50 dark:bg-gray-800 text-left text-gray-600 dark:text-gray-300`,children:(0,G.jsxs)(`tr`,{children:[(0,G.jsx)(`th`,{className:`px-3 py-2 w-10`,children:(0,G.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,G.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:e(`libraryTrash.col.filename`)}),(0,G.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:e(`libraryTrash.col.folder`)}),(0,G.jsx)(`th`,{className:`px-3 py-2 font-medium text-right`,children:e(`libraryTrash.col.size`)}),(0,G.jsx)(`th`,{className:`px-3 py-2 font-medium whitespace-nowrap`,children:e(`libraryTrash.col.deleted`)}),(0,G.jsx)(`th`,{className:`px-3 py-2 font-medium whitespace-nowrap`,children:e(`libraryTrash.col.autoPurge`)}),u&&(0,G.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:e(`libraryTrash.col.owner`)}),(0,G.jsx)(`th`,{className:`px-3 py-2 font-medium text-right`,children:e(`libraryTrash.col.actions`)})]})}),(0,G.jsx)(`tbody`,{className:`divide-y divide-gray-100 dark:divide-gray-800`,children:S.map(t=>(0,G.jsxs)(`tr`,{className:`hover:bg-gray-50 dark:hover:bg-gray-800/50`,children:[(0,G.jsx)(`td`,{className:`px-3 py-2`,children:(0,G.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,G.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,G.jsx)(`td`,{className:`px-3 py-2 text-gray-600 dark:text-gray-400`,children:t.folder_name??`—`}),(0,G.jsx)(`td`,{className:`px-3 py-2 text-right text-gray-600 dark:text-gray-400 tabular-nums whitespace-nowrap`,children:Yd(t.file_size)}),(0,G.jsx)(`td`,{className:`px-3 py-2 text-gray-600 dark:text-gray-400 whitespace-nowrap`,children:U1e(t.deleted_at)}),(0,G.jsx)(`td`,{className:`px-3 py-2 text-gray-600 dark:text-gray-400 whitespace-nowrap`,children:(0,G.jsx)(`span`,{title:U1e(t.auto_purge_at),children:e(`libraryTrash.autoPurgeIn`,{when:H1e(t.auto_purge_at)})})}),u&&(0,G.jsx)(`td`,{className:`px-3 py-2 text-gray-600 dark:text-gray-400`,children:t.created_by_username??`—`}),(0,G.jsxs)(`td`,{className:`px-3 py-2 text-right whitespace-nowrap`,children:[(0,G.jsxs)(`button`,{onClick:()=>_.mutate(t.id),disabled:_.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,G.jsx)(Vl,{className:`w-3.5 h-3.5`}),e(`libraryTrash.restore`)]}),(0,G.jsxs)(`button`,{onClick:()=>s({type:`delete`,id:t.id,filename:t.filename}),disabled:v.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,G.jsx)(Pu,{className:`w-3.5 h-3.5`}),e(`libraryTrash.purgeNow`)]})]})]},t.id))})]})})]}),o&&(0,G.jsx)(uf,{onCancel:()=>s(null),onConfirm:()=>{o&&(o.type===`delete`?v.mutate(o.id):o.type===`bulkDelete`?x.mutate(Array.from(c)):y.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,G.jsxs)(`div`,{className:`mt-4 text-sm text-red-600 dark:text-red-400`,children:[d.error?.message??e(`libraryTrash.loadError`),(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>t(`/files`),className:`ml-3`,children:e(`libraryTrash.backToFiles`)})]})]})}function G1e(e){return e.includes(`/camera/`)}function K1e(e,t,n){let r=0;return e.querySelectorAll(`img[src*="/api/v1/"], video[src*="/api/v1/"]`).forEach(e=>{let i=e.getAttribute(`src`)||``,a=G1e(i)?n:t;if(!a)return;let o=`token=${encodeURIComponent(a)}`;if(i.includes(o))return;let s=i.replace(/([?&])token=[^&]*(&|$)/,(e,t,n)=>n===`&`?t:``);e.src=`${s}${s.includes(`?`)?`&`:`?`}${o}`,r+=1}),r}function q1e(){let{authEnabled:e,user:t,loading:n,hasPermission:r}=Ld(),i=no(),a=(0,f.useRef)(!1),o=!n&&(!e||t!==null),{data:s}=K({queryKey:[`media-token`,t?.id??null],queryFn:()=>Z.getMediaToken(),enabled:o,staleTime:3e3*1e3,refetchInterval:3e3*1e3}),c=!e||r(`camera:view`),{data:l}=K({queryKey:[`camera-stream-token`,t?.id??null],queryFn:()=>Z.getCameraStreamToken(),enabled:o&&c,staleTime:3e3*1e3,refetchInterval:3e3*1e3}),u=s?.token??null,d=l?.token??null;(0,f.useEffect)(()=>(hd(u),pd(d),(u||d)&&K1e(document,u,d),()=>{hd(null),pd(null)}),[u,d]),(0,f.useEffect)(()=>{if(!e)return;let t=e=>{let t=e.target;if(!(t instanceof HTMLImageElement||t instanceof HTMLVideoElement))return;let n=t.src||``,r=G1e(n),o=r?md():gd();!o||!n.includes(`token=${encodeURIComponent(o)}`)||a.current||(a.current=!0,i.invalidateQueries({queryKey:r?[`camera-stream-token`]:[`media-token`]}),setTimeout(()=>{a.current=!1},5e3))};return document.addEventListener(`error`,t,!0),()=>document.removeEventListener(`error`,t,!0)},[e,i])}var n9=5,J1e=2e3,Y1e=3e4,X1e=5e3;function Z1e(){let{t:e}=U(),t=no(),{showToast:n}=Zd(),{hasPermission:r,authEnabled:i,user:a}=Ld(),{printerId:o}=ir(),s=parseInt(o||`0`,10),[c]=ji(),l=parseInt(c.get(`fps`)||`15`,10),u=Math.min(Math.max(isNaN(l)?15:l,1),30);q1e();let{data:d,isPending:p}=K({queryKey:[`camera-stream-token`,a?.id??null],queryFn:()=>Z.getCameraStreamToken(),enabled:i?!!a:!0,staleTime:3e3*1e3}),m=d?.token??md(),[h,g]=(0,f.useState)(`stream`),[_,v]=(0,f.useState)(!1),[y,b]=(0,f.useState)(!1),[x,S]=(0,f.useState)(!1),[C,w]=(0,f.useState)(!0),[T,E]=(0,f.useState)(Date.now()),[D,O]=(0,f.useState)(!1),[k,A]=(0,f.useState)(!1),[j,M]=(0,f.useState)(0),[N,P]=(0,f.useState)(!1),[F,I]=(0,f.useState)(0),[L,R]=(0,f.useState)(1),[z,B]=(0,f.useState)({x:0,y:0}),[V,ee]=(0,f.useState)(!1),[te,ne]=(0,f.useState)({x:0,y:0}),[re,ie]=(0,f.useState)(null),[ae,oe]=(0,f.useState)(null),se=(0,f.useRef)(null),H=(0,f.useRef)(null),ce=(0,f.useRef)(null),le=(0,f.useRef)(null),ue=(0,f.useRef)(null),de=(0,f.useRef)(0),{data:fe}=K({queryKey:[`printer`,s],queryFn:()=>Z.getPrinter(s),enabled:s>0}),{data:pe}=K({queryKey:[`printerStatus`,s],queryFn:()=>Z.getPrinterStatus(s),refetchInterval:3e4,enabled:s>0}),me=q({mutationFn:e=>Z.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`)}}),he=(pe?.state===`RUNNING`||pe?.state===`PAUSE`)&&(pe?.printable_objects_count??0)>=2;(0,f.useEffect)(()=>(fe&&(document.title=`${fe.name} - Camera`),()=>{document.title=`Bambuddy`}),[fe]);let ge=(0,f.useRef)(!1);(0,f.useEffect)(()=>{let e=`/api/v1/printers/${s}/camera/stop`;ge.current=!1;let t=()=>{if(s>0&&!ge.current){ge.current=!0;let t={},n=ud();n&&(t.Authorization=`Bearer ${n}`),fetch(e,{method:`POST`,keepalive:!0,headers:t}).catch(()=>{})}},n=()=>{t()};window.addEventListener(`beforeunload`,n);let r=se.current;return()=>{window.removeEventListener(`beforeunload`,n),r&&(r.src=``),t()}},[s]),(0,f.useEffect)(()=>{if(C&&!D){let e=setTimeout(()=>{w(!1)},h===`stream`?3e3:2e4);return()=>clearTimeout(e)}},[h,C,T,D]),(0,f.useEffect)(()=>{let e=()=>{A(!!document.fullscreenElement),R(1),B({x:0,y:0}),h===`stream`&&!D&&(se.current&&(se.current.src=``),setTimeout(()=>{w(!0),E(Date.now())},200))};return document.addEventListener(`fullscreenchange`,e),()=>document.removeEventListener(`fullscreenchange`,e)},[h,D]),(0,f.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,f.useEffect)(()=>()=>{ce.current&&clearTimeout(ce.current),le.current&&clearInterval(le.current),ue.current&&clearInterval(ue.current)},[]);let _e=(0,f.useCallback)(()=>{if(j>=n9){P(!1),S(!0);return}let e=Math.min(J1e*2**j,Y1e);P(!0),I(Math.ceil(e/1e3)),le.current=setInterval(()=>{I(e=>e<=1?(le.current&&clearInterval(le.current),0):e-1)},1e3),ce.current=setTimeout(()=>{M(e=>e+1),P(!1),w(!0),S(!1),se.current&&(se.current.src=``),E(Date.now())},e)},[j]);(0,f.useEffect)(()=>{if(h!==`stream`||C||N||D){ue.current&&=(clearInterval(ue.current),null);return}return de.current=0,ue.current=setInterval(async()=>{try{let e=await Z.getCameraStatus(s);if(!(e.stalled||!e.active&&!x)){de.current=0;return}if(de.current+=1,de.current<2)return;de.current=0,console.log(`Stream issue detected: stalled=${e.stalled}, active=${e.active}, reconnecting...`),ue.current&&=(clearInterval(ue.current),null),w(!1),_e()}catch{}},X1e),()=>{ue.current&&=(clearInterval(ue.current),null)}},[h,C,x,N,D,s,_e]);let ve=()=>{w(!1),h===`stream`&&j{if(w(!1),S(!1),M(0),de.current=0,P(!1),ce.current&&clearTimeout(ce.current),le.current&&clearInterval(le.current),se.current&&!localStorage.getItem(`cameraWindowState`)){let e=se.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{}}}},be=()=>{if(s>0){let e={},t=ud();t&&(e.Authorization=`Bearer ${t}`),fetch(`/api/v1/printers/${s}/camera/stop`,{method:`POST`,headers:e}).catch(()=>{})}},xe=e=>{h===e||D||(O(!0),w(!0),S(!1),M(0),P(!1),R(1),B({x:0,y:0}),ce.current&&clearTimeout(ce.current),le.current&&clearInterval(le.current),se.current&&(se.current.src=``),h===`stream`&&be(),setTimeout(()=>{g(e),E(Date.now()),O(!1)},100))},Se=()=>{D||(O(!0),w(!0),S(!1),M(0),P(!1),ce.current&&clearTimeout(ce.current),le.current&&clearInterval(le.current),se.current&&(se.current.src=``),h===`stream`&&be(),setTimeout(()=>{E(Date.now()),O(!1)},100))},Ce=()=>{H.current&&(document.fullscreenElement?document.exitFullscreen():H.current.requestFullscreen())},we=()=>{R(e=>Math.min(e+.5,4))},Te=()=>{R(e=>{let t=Math.max(e-.5,1);return t===1&&B({x:0,y:0}),t})},Ee=e=>{e.preventDefault(),e.deltaY<0?we():Te()},De=e=>{L>1&&(e.preventDefault(),ee(!0),ne({x:e.clientX-z.x,y:e.clientY-z.y}))},Oe=(0,f.useCallback)(()=>{if(!H.current)return{x:300,y:200};let e=H.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]),ke=e=>{if(V&&L>1){let t=e.clientX-te.x,n=e.clientY-te.y,r=Oe();B({x:Math.max(-r.x,Math.min(r.x,t)),y:Math.max(-r.y,Math.min(r.y,n))})}},Ae=()=>{ee(!1)},je=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)},Me=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},Ne=e=>{e.touches.length===2?(e.preventDefault(),ie(je(e.touches)),oe(Me(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}))},Pe=e=>{if(e.touches.length===2&&re!==null){e.preventDefault();let t=je(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=Me(e.touches);if(ae){let e=Oe();B(t=>({x:Math.max(-e.x,Math.min(e.x,t.x+(r.x-ae.x))),y:Math.max(-e.y,Math.min(e.y,t.y+(r.y-ae.y)))}))}oe(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=Oe();B({x:Math.max(-r.x,Math.min(r.x,t)),y:Math.max(-r.y,Math.min(r.y,n))})}},Fe=e=>{e.touches.length<2&&(ie(null),oe(null)),e.touches.length===0&&ee(!1)},Ie=()=>{R(1),B({x:0,y:0})},Le=D||!m&&(i||p)?``:(e=>m?`${e}&token=${encodeURIComponent(m)}`:_d(e))(h===`stream`?`/api/v1/printers/${s}/camera/stream?fps=${u}&t=${T}`:`/api/v1/printers/${s}/camera/snapshot?t=${T}`),Re=C||D||N;return s?(0,G.jsxs)(`div`,{ref:H,className:`min-h-screen bg-black flex flex-col`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2 bg-bambu-dark-secondary border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`h1`,{className:`text-sm font-medium text-white flex items-center gap-2`,children:[(0,G.jsx)(es,{className:`w-4 h-4`}),fe?.name||`Printer ${s}`]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`div`,{className:`flex bg-bambu-dark rounded p-0.5`,children:[(0,G.jsx)(`button`,{onClick:()=>xe(`stream`),disabled:Re,className:`px-3 py-1 text-xs rounded transition-colors ${h===`stream`?`bg-bambu-green text-white`:`text-bambu-gray hover:text-white disabled:opacity-50`}`,children:e(`camera.live`)}),(0,G.jsx)(`button`,{onClick:()=>xe(`snapshot`),disabled:Re,className:`px-3 py-1 text-xs rounded transition-colors ${h===`snapshot`?`bg-bambu-green text-white`:`text-bambu-gray hover:text-white disabled:opacity-50`}`,children:e(`camera.snapshot`)})]}),(0,G.jsx)(`button`,{onClick:()=>me.mutate(!pe?.chamber_light),disabled:!pe?.connected||me.isPending||!r(`printers:control`),className:`p-1.5 rounded disabled:opacity-50 ${pe?.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,G.jsx)(LT,{on:pe?.chamber_light??!1,className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:()=>v(!0),disabled:!he||!r(`printers:control`),className:`p-1.5 rounded disabled:opacity-50 ${he&&r(`printers:control`)?`hover:bg-bambu-dark-tertiary`:``}`,title:r(`printers:control`)?e(he?`printers.skipObjects.tooltip`:`printers.skipObjects.onlyWhilePrinting`):e(`printers.permission.noControl`),children:(0,G.jsx)(RT,{className:`w-4 h-4 text-bambu-gray`})}),(0,G.jsx)(`button`,{onClick:Se,disabled:Re,className:`p-1.5 hover:bg-bambu-dark-tertiary rounded disabled:opacity-50`,title:e(h===`stream`?`camera.restartStream`:`camera.refreshSnapshot`),children:(0,G.jsx)(zl,{className:`w-4 h-4 text-bambu-gray ${Re?`animate-spin`:``}`})}),(0,G.jsx)(`button`,{onClick:()=>b(!0),className:`p-1.5 hover:bg-bambu-dark-tertiary rounded`,title:e(`camera.diagnose.button`),children:(0,G.jsx)(yu,{className:`w-4 h-4 text-bambu-gray`})}),(0,G.jsx)(`button`,{onClick:Ce,className:`p-1.5 hover:bg-bambu-dark-tertiary rounded`,title:e(k?`camera.exitFullscreen`:`camera.fullscreen`),children:k?(0,G.jsx)(ul,{className:`w-4 h-4 text-bambu-gray`}):(0,G.jsx)(al,{className:`w-4 h-4 text-bambu-gray`})})]})]}),(0,G.jsx)(`div`,{className:`flex-1 flex items-center justify-center p-2 overflow-hidden`,onWheel:Ee,onMouseMove:ke,onMouseUp:Ae,onMouseLeave:Ae,onTouchStart:Ne,onTouchMove:Pe,onTouchEnd:Fe,style:{touchAction:`none`},children:(0,G.jsxs)(`div`,{className:`relative w-full h-full flex items-center justify-center`,children:[(C||D)&&!N&&(0,G.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-black/50 z-10`,children:(0,G.jsxs)(`div`,{className:`text-center`,children:[(0,G.jsx)(zl,{className:`w-8 h-8 text-bambu-gray animate-spin mx-auto mb-2`}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(h===`stream`?`camera.connectingToCamera`:`camera.capturingSnapshot`)})]})}),N&&(0,G.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-black/80 z-10`,children:(0,G.jsxs)(`div`,{className:`text-center p-4`,children:[(0,G.jsx)(Zu,{className:`w-10 h-10 text-orange-400 mx-auto mb-3`}),(0,G.jsx)(`p`,{className:`text-white mb-2`,children:e(`camera.connectionLost`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mb-3`,children:e(`camera.reconnecting`,{countdown:F,attempt:Math.min(j+1,n9),max:n9})}),(0,G.jsx)(`button`,{onClick:Se,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,G.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-black z-10`,children:(0,G.jsxs)(`div`,{className:`text-center p-4`,children:[(0,G.jsx)(Lu,{className:`w-12 h-12 text-orange-400 mx-auto mb-3`}),(0,G.jsx)(`p`,{className:`text-white mb-2`,children:e(`camera.cameraUnavailable`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mb-4 max-w-md`,children:e(`camera.cameraUnavailableDesc`)}),(0,G.jsxs)(`div`,{className:`flex gap-2 justify-center`,children:[(0,G.jsx)(`button`,{onClick:Se,className:`px-4 py-2 bg-bambu-green text-white rounded hover:bg-bambu-green/80 transition-colors`,children:e(`camera.retry`)}),(0,G.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,G.jsx)(`img`,{ref:se,src:Le,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(${fe?.camera_rotation||0}deg)`,...fe?.camera_rotation===90||fe?.camera_rotation===270?{maxWidth:`100vh`,maxHeight:`100vw`}:{},cursor:L>1?V?`grabbing`:`grab`:`default`},onError:Le?ve:void 0,onLoad:Le?ye:void 0,onMouseDown:De,draggable:!1},T),(0,G.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,G.jsx)(`button`,{onClick:Te,disabled:L<=1,className:`p-1.5 hover:bg-white/10 rounded disabled:opacity-30`,title:e(`camera.zoomOut`),children:(0,G.jsx)(ad,{className:`w-4 h-4 text-white`})}),(0,G.jsxs)(`button`,{onClick:Ie,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,G.jsx)(`button`,{onClick:we,disabled:L>=4,className:`p-1.5 hover:bg-white/10 rounded disabled:opacity-30`,title:e(`camera.zoomIn`),children:(0,G.jsx)(rd,{className:`w-4 h-4 text-white`})})]})]})}),(0,G.jsx)(zT,{printerId:s,isOpen:_,onClose:()=>v(!1)}),y&&(0,G.jsx)(BT,{printerId:s,printerName:fe?.name||null,onClose:()=>b(!1)})]}):(0,G.jsx)(`div`,{className:`min-h-screen bg-black flex items-center justify-center`,children:(0,G.jsx)(`p`,{className:`text-white`,children:e(`camera.invalidPrinterId`)})})}var Q1e=5e3,$1e=4,e0e=8,t0e=1,n0e=16,r0e=2,i0e=60;function a0e(e,t,n,r){let i=parseInt(e??``,10);return Number.isFinite(i)?Math.min(r,Math.max(n,i)):t}function o0e(e,t,n,r,i,a){return e.has(t)?a0e(e.get(t),r,i,a):a0e(localStorage.getItem(n),r,i,a)}function s0e(){let{t:e}=U(),t=Xn(),{authEnabled:n,loading:r,user:i}=Ld(),[a]=ji(),o=a.get(`token`),s=o!=null&&o!==``,[c,l]=(0,f.useState)(()=>o0e(a,`maxLive`,`camWallMaxLive`,$1e,t0e,n0e)),[u,d]=(0,f.useState)(()=>o0e(a,`interval`,`camWallSnapshotSec`,e0e,r0e,i0e)),[p,m]=(0,f.useState)(()=>{let e=a.get(`status`)??localStorage.getItem(`camWallStatusMode`);return(s?[`off`,`compact`]:[`off`,`compact`,`full`]).includes(e)?e:`compact`});(0,f.useEffect)(()=>{if(s)return pd(o),()=>pd(null)},[s,o]);let h=K({queryKey:[`camwall-printers`,o],queryFn:()=>Z.getCamWallPrinters(o??void 0),enabled:s,refetchInterval:Q1e}),g=K({queryKey:[`printers`],queryFn:()=>Z.getPrinters(),enabled:!s&&!r&&(!n||i!==null),refetchInterval:Q1e}),_=(0,f.useMemo)(()=>{let e=new Map;for(let t of h.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},[h.data]);if(!s&&r)return(0,G.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,G.jsx)(Or,{to:`/login`,replace:!0,state:{from:t}});let v=s?h:g,y=s?h.data??[]:g.data??[];return v.isError?(0,G.jsx)(`div`,{className:`flex min-h-screen items-center justify-center bg-bambu-dark p-6 text-center`,children:(0,G.jsx)(`p`,{className:`max-w-md text-sm text-red-400`,children:e(s?`printers.camWall.page.tokenRejected`:`printers.camWall.page.loadFailed`)})}):(0,G.jsx)(`div`,{className:`min-h-screen bg-bambu-dark p-4`,children:(0,G.jsx)(qT,{printers:y,maxLive:c,snapshotIntervalSec:u,statusMode:p,statuses:s?_: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=>{m(e),localStorage.setItem(`camWallStatusMode`,e)}})})}function c0e(e,t){let[n,r]=(0,f.useState)(null);return(0,f.useLayoutEffect)(()=>{let n=e.current;if(!t||!n)return;let i=()=>{let{width:e,height:t}=n.getBoundingClientRect();e>0&&t>0&&r(n=>n&&n.width===e&&n.height===t?n:{width:e,height:t})};if(i(),typeof ResizeObserver>`u`)return window.addEventListener(`resize`,i),()=>window.removeEventListener(`resize`,i);let a=new ResizeObserver(i);return a.observe(n),()=>a.disconnect()},[e,t]),t?n:null}function l0e(e){let{t}=U(),{camera:n,name:r,model:i,filename:a,status:o,state:s,progress:c,layers:l,remaining:u,eta:d,temperatures:p}=e,m=a||o||c!=null||l||u||d||p.length>0,h=n?.rotation??0,g=Math.abs(h%180)===90,_=(0,f.useRef)(null),v=c0e(_,g&&n!=null),y=[{key:`layers`,icon:(0,G.jsx)(Wc,{}),label:t(`streamOverlay.layer`),value:l},{key:`remaining`,icon:(0,G.jsx)(Nu,{}),label:t(`streamOverlay.remaining`),value:u},{key:`eta`,icon:(0,G.jsx)(Ts,{}),label:t(`streamOverlay.eta`),value:d}].filter(e=>e.value!=null);return(0,G.jsxs)(`div`,{className:`updated-overlay`,"data-size":e.size,"data-state":s,children:[(0,G.jsxs)(`header`,{className:`updated-overlay__header`,children:[(r||i)&&(0,G.jsxs)(`div`,{className:`updated-overlay__identity`,children:[(0,G.jsx)(Fl,{"aria-hidden":`true`}),(0,G.jsxs)(`div`,{children:[r&&(0,G.jsx)(`strong`,{children:r}),i&&(0,G.jsx)(`span`,{children:i})]})]}),(0,G.jsx)(`a`,{className:`updated-overlay__logo`,href:`https://github.com/maziggy/bambuddy`,target:`_blank`,rel:`noopener noreferrer`,children:(0,G.jsx)(`img`,{src:`/img/bambuddy_logo_powered_by.png`,alt:`Bambuddy`})})]}),n&&(0,G.jsx)(`div`,{className:`updated-overlay__camera`,ref:_,children:(0,G.jsx)(`img`,{src:n.url,alt:t(`streamOverlay.cameraStream`),style:{transform:`translate(-50%, -50%) rotate(${h}deg)`,...g&&v?{width:v.height,height:v.width}:{}},onError:n.onError},n.url)}),m&&(0,G.jsxs)(`section`,{className:`updated-overlay__panel`,children:[(a||o)&&(0,G.jsxs)(`div`,{className:`updated-overlay__summary`,children:[a&&(0,G.jsx)(`h1`,{children:a}),o&&(0,G.jsxs)(`div`,{className:`updated-overlay__status`,children:[(0,G.jsx)(`span`,{"aria-hidden":`true`}),o]})]}),c!=null&&(0,G.jsxs)(`div`,{className:`updated-overlay__progress`,children:[(0,G.jsx)(`span`,{children:t(`streamOverlay.progress`)}),(0,G.jsx)(`div`,{role:`progressbar`,"aria-label":t(`streamOverlay.progress`),"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":c,children:(0,G.jsx)(`div`,{style:{width:`${c}%`}})}),(0,G.jsxs)(`strong`,{children:[Math.round(c),`%`]})]}),(y.length>0||p.length>0)&&(0,G.jsxs)(`div`,{className:`updated-overlay__readings`,children:[y.length>0&&(0,G.jsx)(`div`,{className:`updated-overlay__stats`,children:y.map(e=>(0,G.jsxs)(`div`,{className:`updated-overlay__reading`,children:[e.icon,(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{children:e.label}),(0,G.jsx)(`strong`,{children:e.value})]})]},e.key))}),p.length>0&&(0,G.jsx)(`div`,{className:`updated-overlay__temperatures`,children:p.map(e=>(0,G.jsxs)(`div`,{className:`updated-overlay__reading`,children:[e.icon,(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{children:e.label}),(0,G.jsxs)(`strong`,{children:[Math.round(e.current),`°C`,e.target!=null&&e.target>0&&Math.round(e.target)!==Math.round(e.current)&&(0,G.jsxs)(`small`,{children:[` / `,Math.round(e.target),`°C`]})]})]})]},e.key))})]})]})]})}var u0e=6e4,d0e=3e3;function f0e(e){let[t,n]=(0,f.useState)(Date.now),r=(0,f.useRef)(null),i=(0,f.useCallback)(()=>{r.current!==null&&(clearTimeout(r.current),r.current=null),n(e=>e+1)},[]);return(0,f.useEffect)(()=>{if(!e)return;let t=setTimeout(i,u0e);return()=>{clearTimeout(t),r.current!==null&&(clearTimeout(r.current),r.current=null)}},[e,t,i]),{imageKey:t,handleStreamError:(0,f.useCallback)(()=>{!e||r.current!==null||(r.current=setTimeout(i,d0e))},[e,i])}}function p0e(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 m0e(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,updatedArtwork:e.get(`artwork`)===`2`,showCamera:a,showProgress:t.includes(`progress`),showLayers:t.includes(`layers`),showEta:t.includes(`eta`),showFilename:t.includes(`filename`),showStatus:t.includes(`status`),showPrinter:t.includes(`printer`),showModel:t.includes(`model`),showNozzle:t.includes(`nozzle`),showBed:t.includes(`bed`),showChamber:t.includes(`chamber`)}}function h0e(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 r9(e,t){let n=e[t];return typeof n==`number`?n:null}function g0e({icon:e,label:t,current:n,target:r,sizes:i}){let a=r!=null&&r>0&&Math.round(r)!==Math.round(n);return(0,G.jsxs)(`div`,{className:`flex items-center ${i.gap} text-white/70`,children:[e,(0,G.jsxs)(`span`,{className:i.text,children:[(0,G.jsx)(`span`,{className:`mr-1`,children:t}),(0,G.jsxs)(`span`,{className:`text-white`,children:[Math.round(n),`°C`]}),a&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`span`,{className:`mx-1`,children:`/`}),(0,G.jsxs)(`span`,{children:[Math.round(r),`°C`]})]})]})]})}function _0e(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 v0e(){let{printerId:e}=ir(),[t]=ji(),{t:n}=U(),r=no(),i=parseInt(e||`0`,10),a=(0,f.useMemo)(()=>m0e(t),[t]),o=_0e(a.size),s=t.get(`token`),c=s!=null&&s!==``,{data:l}=K({queryKey:[`overlayStatus`,i,s],queryFn:()=>Z.getOverlayStatus(i,s??void 0),enabled:i>0&&c,refetchInterval:2e3}),{data:u}=K({queryKey:[`printer`,i],queryFn:()=>Z.getPrinter(i),enabled:i>0&&!c}),{data:d}=K({queryKey:[`printerStatus`,i],queryFn:()=>Z.getPrinterStatus(i),enabled:i>0&&!c,refetchInterval:2e3}),{data:p}=K({queryKey:[`settings`],queryFn:Z.getSettings,enabled:!c}),m=(0,f.useMemo)(()=>c?l&&{name:l.name,model:l.model,camera_rotation:l.camera_rotation}:u,[c,l,u]),h=[a.showPrinter?m?.name:null,a.showModel?ah(m?.model??null):null].filter(Boolean).join(` · `),g=c?l:d,{imageKey:_,handleStreamError:v}=f0e(i>0&&a.showCamera&&g!=null),y=(c?l?.time_format:p?.time_format)||`system`;if((0,f.useEffect)(()=>{if(!i||c)return;let e=null,t=!1;return(async()=>{let n;try{n=(await Z.getWebSocketToken()).token}catch(e){let t=e instanceof sd?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,c,r]),(0,f.useEffect)(()=>(document.title=m?`${m.name} - ${n(`streamOverlay.title`)}`:n(`streamOverlay.title`),()=>{document.title=`Bambuddy`}),[m,n]),!i)return(0,G.jsx)(`div`,{className:`min-h-screen bg-black flex items-center justify-center`,children:(0,G.jsx)(`p`,{className:`text-white`,children:n(`streamOverlay.invalidPrinterId`)})});if(!g)return(0,G.jsx)(`div`,{className:`min-h-screen bg-black flex items-center justify-center`,children:(0,G.jsx)(`p`,{className:`text-gray-400`,children:n(`common.loading`)})});let b=g.state===`RUNNING`||g.state===`PAUSE`,x=g.progress||0,S=g.temperatures??{},C=[];if(a.showNozzle){let e=r9(S,`nozzle`),t=r9(S,`nozzle_2`);e!=null&&C.push({key:`nozzle`,icon:(0,G.jsx)(uc,{className:o.icon}),label:n(`printers.heaterHistory.nozzle`,`Nozzle`),current:e,target:r9(S,`nozzle_target`)}),t!=null&&C.push({key:`nozzle_2`,icon:(0,G.jsx)(uc,{className:o.icon}),label:n(`printers.heaterHistory.nozzle2`,`Nozzle 2`),current:t,target:r9(S,`nozzle_2_target`)})}if(a.showBed){let e=r9(S,`bed`);e!=null&&C.push({key:`bed`,icon:(0,G.jsx)(_u,{className:o.icon}),label:n(`printers.heaterHistory.bed`,`Bed`),current:e,target:r9(S,`bed_target`)})}if(a.showChamber){let e=r9(S,`chamber`);e!=null&&C.push({key:`chamber`,icon:(0,G.jsx)(Wo,{className:o.icon}),label:n(`printers.heaterHistory.chamber`,`Chamber`),current:e,target:r9(S,`chamber_target`)})}let w=`/api/v1/printers/${i}/camera/stream?fps=${a.fps}&t=${_}`,T=c&&s?`${w}&token=${encodeURIComponent(s)}`:_d(w);if(a.updatedArtwork){let e=g.connected&&b,t=g.remaining_time,r=e&&a.showEta&&t!=null&&t>0;return(0,G.jsx)(l0e,{size:a.size,camera:a.showCamera?{url:T,rotation:m?.camera_rotation??0,onError:v}:null,name:a.showPrinter?m?.name??null:null,model:a.showModel&&ah(m?.model??null)||null,filename:a.showFilename&&g.current_print?p0e(g.current_print.replace(/\.gcode\.3mf$|\.3mf$|\.gcode$/i,``),g.gcode_file,n):null,status:a.showStatus?g.connected?h0e(g,n):n(`streamOverlay.printerOffline`):null,state:g.connected?g.state:null,progress:e&&a.showProgress?Math.min(100,Math.max(0,Number.isFinite(x)?x:0)):null,layers:e&&a.showLayers&&g.layer_num!=null&&g.total_layers!=null&&g.total_layers>0?`${g.layer_num} / ${g.total_layers}`:null,remaining:r?pp(t*60):null,eta:r?fp(t,y,n):null,temperatures:g.connected?C:[]})}return(0,G.jsxs)(`div`,{className:`min-h-screen bg-black relative overflow-hidden`,children:[a.showCamera&&(0,G.jsx)(`img`,{src:T,alt:n(`streamOverlay.cameraStream`),className:`absolute inset-0 w-full h-full object-contain`,style:m?.camera_rotation?{transform:`rotate(${m.camera_rotation}deg)`}:void 0,onError:v},_),(0,G.jsx)(`a`,{href:`https://github.com/maziggy/bambuddy`,target:`_blank`,rel:`noopener noreferrer`,className:`absolute top-4 right-4 z-10`,children:(0,G.jsx)(`img`,{src:`/img/bambuddy_logo_dark_transparent.png`,alt:`Bambuddy`,className:`${o.logoHeight} object-contain drop-shadow-lg hover:scale-105 transition-transform`})}),(0,G.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,G.jsxs)(`div`,{className:`${o.container}`,children:[h&&(0,G.jsxs)(`div`,{className:`flex items-center ${o.gap} mb-2`,children:[(0,G.jsx)(Fl,{className:`${o.icon} shrink-0 text-white/70`}),(0,G.jsx)(`span`,{className:`${o.text} min-w-0 truncate text-white font-medium`,children:h})]}),a.showFilename&&g.current_print&&(0,G.jsx)(`div`,{className:`${o.textLarge} text-white font-semibold mb-2 truncate drop-shadow-md`,children:p0e(g.current_print.replace(/\.gcode\.3mf$|\.3mf$|\.gcode$/i,``),g.gcode_file,n)}),a.showStatus&&(0,G.jsx)(`div`,{className:`${o.text} text-white/70 mb-2`,children:h0e(g,n)}),a.showProgress&&b&&(0,G.jsxs)(`div`,{className:`mb-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-1 ${o.text}`,children:[(0,G.jsx)(`span`,{className:`text-white/70`,children:n(`streamOverlay.progress`)}),(0,G.jsxs)(`span`,{className:`text-white font-bold`,children:[Math.round(x),`%`]})]}),(0,G.jsx)(`div`,{className:`w-full bg-white/20 rounded-full ${o.progressHeight}`,children:(0,G.jsx)(`div`,{className:`bg-bambu-green ${o.progressHeight} rounded-full transition-all duration-500`,style:{width:`${x}%`}})})]}),b&&(a.showLayers||a.showEta)&&(0,G.jsxs)(`div`,{className:`flex items-center ${o.gap} flex-wrap`,children:[a.showLayers&&g.layer_num!=null&&g.total_layers!=null&&g.total_layers>0&&(0,G.jsxs)(`div`,{className:`flex items-center ${o.gap} text-white/70`,children:[(0,G.jsx)(Wc,{className:o.icon}),(0,G.jsxs)(`span`,{className:o.text,children:[(0,G.jsx)(`span`,{className:`text-white`,children:g.layer_num}),(0,G.jsx)(`span`,{className:`mx-1`,children:`/`}),(0,G.jsx)(`span`,{children:g.total_layers})]})]}),a.showEta&&g.remaining_time!=null&&g.remaining_time>0&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`flex items-center ${o.gap} text-white/70`,children:[(0,G.jsx)(Nu,{className:o.icon}),(0,G.jsx)(`span`,{className:`${o.text} text-white`,children:pp(g.remaining_time*60)})]}),(0,G.jsxs)(`div`,{className:`flex items-center ${o.gap} text-white/70`,children:[(0,G.jsx)(Ts,{className:o.icon}),(0,G.jsxs)(`span`,{className:`${o.text} text-white`,children:[n(`streamOverlay.eta`),` `,fp(g.remaining_time,y,n)]})]})]})]}),!b&&(0,G.jsx)(`div`,{className:`${o.text} text-white/70 py-2`,children:g.connected?n(`streamOverlay.printerIdle`):n(`streamOverlay.printerOffline`)}),C.length>0&&(0,G.jsx)(`div`,{className:`flex items-center ${o.gap} flex-wrap mt-2`,children:C.map(e=>(0,G.jsx)(g0e,{icon:e.icon,label:e.label,current:e.current,target:e.target,sizes:o},e.key))})]})})]})}function y0e(){let{t:e}=U(),{id:t}=ir(),{mode:n}=Bd(),r=(0,f.useRef)(null),i=b0e(r),{data:a,isLoading:o,error:s}=K({queryKey:[`external-link`,t],queryFn:()=>Z.getExternalLink(Number(t)),enabled:!!t});return o?(0,G.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,G.jsx)(Y,{className:`w-8 h-8 text-bambu-green animate-spin`})}):s||!a?(0,G.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-4 text-bambu-gray`,children:[(0,G.jsx)(Lu,{className:`w-12 h-12`}),(0,G.jsx)(`p`,{children:e(`common.linkNotFound`)})]}):(0,G.jsx)(`iframe`,{ref:r,src:a.url,onLoad:i,className:`h-full w-full border-0`,style:{colorScheme:n},title:a.name,sandbox:`allow-scripts allow-same-origin allow-forms allow-popups allow-popups-to-escape-sandbox`})}function b0e(e){let{resolvedMode:t,darkStyle:n,darkBackground:r,darkAccent:i,lightStyle:a,lightBackground:o,lightAccent:s}=Bd(),c=t===`dark`,l=c?n:a,u=c?r:o,d=c?i:s,p=(0,f.useCallback)(()=>{let n=e.current;if(!n?.contentWindow)return;let r;try{r=new URL(n.src).origin}catch{return}n.contentWindow.postMessage({type:`bambuddy:theme`,mode:t,style:l,background:u,accent:d},r)},[e,t,l,u,d]);return(0,f.useEffect)(()=>p(),[p]),(0,f.useEffect)(()=>{let t=t=>{t.source===e.current?.contentWindow&&t.data?.type===`bambuddy:theme-request`&&p()};return window.addEventListener(`message`,t),()=>window.removeEventListener(`message`,t)},[e,p]),p}function x0e(){let{id:e}=ir(),t=$n(),n=no(),{t:r}=U(),{showToast:i}=Zd(),a=!!e,[o,s]=(0,f.useState)(``),[c,l]=(0,f.useState)(``),[u,d]=(0,f.useState)([]),[p,m]=(0,f.useState)(``),[h,g]=(0,f.useState)(!1),{data:_,isLoading:v}=K({queryKey:[`group`,e],queryFn:()=>Z.getGroup(Number(e)),enabled:a}),{data:y,isLoading:b}=K({queryKey:[`permissions`],queryFn:()=>Z.getPermissions()});a&&_&&!h&&(s(_.name),l(_.description||``),d(_.permissions),g(!0));let x=q({mutationFn:e=>Z.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=q({mutationFn:t=>Z.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===_?.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{y&&d(y.all_permissions)},A=()=>{d([])},j=p.toLowerCase(),M=(0,f.useMemo)(()=>y?j?y.categories.map(e=>({...e,permissions:e.permissions.filter(e=>e.label.toLowerCase().includes(j))})).filter(e=>e.permissions.length>0):y.categories:[],[y,j]),N=y?.all_permissions.length??0;return v||b?(0,G.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,G.jsx)(Y,{className:`w-8 h-8 text-bambu-green animate-spin`})}):(0,G.jsxs)(`div`,{className:`space-y-6 max-w-5xl mx-auto`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.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,G.jsx)(jo,{className:`w-5 h-5`})}),(0,G.jsx)(`h1`,{className:`text-xl font-bold text-white`,children:r(a?`groups.editor.title`:`groups.editor.createTitle`)})]}),a&&_?.is_system&&(0,G.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,G.jsx)(Lu,{className:`w-4 h-4 shrink-0`}),r(`groups.form.systemGroupWarning`)]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:r(`groups.form.groupName`)}),(0,G.jsx)(`input`,{type:`text`,value:o,onChange:e=>s(e.target.value),disabled:a&&_?.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,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:r(`groups.form.description`)}),(0,G.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,G.jsxs)(`div`,{className:`flex items-center justify-between flex-wrap gap-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[r(`groups.editor.permissionsSelected`,{count:u.length}),` / `,N]}),(0,G.jsx)(Q,{size:`sm`,variant:`ghost`,onClick:k,children:r(`groups.editor.selectAll`)}),(0,G.jsx)(Q,{size:`sm`,variant:`ghost`,onClick:A,children:r(`groups.editor.clearAll`)})]}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(Yl,{className:`w-4 h-4 absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray`}),(0,G.jsx)(`input`,{type:`text`,value:p,onChange:e=>m(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,G.jsx)(`div`,{className:`text-center py-12 text-bambu-gray`,children:r(`groups.editor.noResults`)}):(0,G.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:M.map(e=>{let t=y.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,G.jsxs)(Ud,{children:[(0,G.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,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.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,G.jsx)(as,{className:`w-3 h-3 text-white`}),o&&!a&&(0,G.jsx)(dl,{className:`w-3 h-3 text-white`})]}),(0,G.jsx)(iu,{className:`w-4 h-4 text-bambu-gray shrink-0`}),(0,G.jsx)(`span`,{className:`text-white font-medium text-sm`,children:e.name})]}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray tabular-nums`,children:[n,`/`,i]})]}),(0,G.jsx)(`div`,{className:`p-3 space-y-1`,children:e.permissions.map(e=>(0,G.jsxs)(`label`,{className:`flex items-center gap-3 px-2 py-1.5 rounded hover:bg-bambu-dark-secondary cursor-pointer`,children:[(0,G.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,G.jsxs)(`span`,{className:`flex flex-col`,children:[(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.label}),e.value===`websocket:connect`&&(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray/60`,children:r(`groups.editor.websocketHint`)})]})]},e.value))})]},e.name)})}),(0,G.jsx)(`div`,{className:`h-16`}),(0,G.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,G.jsx)(Q,{variant:`secondary`,onClick:()=>t(`/settings?tab=users`),children:r(`common.cancel`)}),(0,G.jsx)(Q,{onClick:w,disabled:C||!o.trim(),children:C?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),r(`common.saving`)]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Wl,{className:`w-4 h-4`}),r(`common.save`)]})})]})]})}var S0e=1.65,C0e=[`#1DB954`,`#3B82F6`,`#F59E0B`,`#EF4444`,`#8B5CF6`];function i9(e,t,n,r){return`${e}||${t??``}||${n??``}||${r??``}`}function a9(e,t){let n=new Date(e);return n.setDate(n.getDate()+Math.round(t)),n}function o9(e){return e.toLocaleDateString(void 0,{month:`short`,day:`numeric`,year:`numeric`})}function s9(e){return e.toLocaleDateString(void 0,{month:`short`,day:`numeric`})}function w0e(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 T0e(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 nZ.getAllUsageHistory(5e3),staleTime:6e4,enabled:o}),{data:O=[]}=K({queryKey:[`shopping-list`],queryFn:Z.getShoppingList,staleTime:3e4,enabled:o}),k=T?.forecast_global_lead_time_days??0,A=(0,f.useMemo)(()=>{let e=new Map;for(let t of E)e.set(i9(t.material,t.subtype,t.brand,t.color_name),t);return e},[E]),j=(0,f.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,f.useMemo)(()=>{let t=new Map;for(let n of e){if(n.archived_at)continue;let e=i9(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,f.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(i9(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=w0e(u);if(m!==null)d=m.rate,f=m.stdDev,p=`history`;else{let e=T0e(t.spools);e!==null&&(d=e,p=`delta`)}let h=S0e*(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:a9(e,_),y=d&&d>0?Math.floor((s-g)/d):null,b=y===null?null:a9(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,f.useMemo)(()=>[...new Set(M.map(e=>e.material))].sort(),[M]),F=(0,f.useMemo)(()=>[...new Set(M.map(e=>e.brand).filter(Boolean))].sort(),[M]),I=(0,f.useMemo)(()=>{let e=[...N];return h&&(e=e.filter(e=>e.group.material===h)),_&&(e=e.filter(e=>e.group.brand===_)),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 p===`asc`?i:-i}),e},[N,u,p,h,_]),L=(0,f.useMemo)(()=>N.filter(e=>!e.settings?.alerts_snoozed&&(e.stockBreakAlert||e.reorderAlert)),[N]),R=(0,f.useMemo)(()=>[...N].filter(e=>e.dailyRateG!==null).sort((e,t)=>t.totalUsedG-e.totalUsedG).slice(0,5),[N]);if(!o)return(0,G.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-16 text-bambu-gray gap-3`,children:[(0,G.jsx)(Qc,{className:`w-8 h-8 opacity-40`}),(0,G.jsx)(`p`,{className:`text-sm`,children:r(`forecast.noReadAccess`)})]});function z(e){u===e?m(e=>e===`asc`?`desc`:`asc`):(d(e),m(e===`days_left`?`asc`:`desc`))}let B=O.length>0?O.length:null;return(0,G.jsxs)(`div`,{className:`space-y-5`,children:[(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[L.length>0&&(0,G.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,G.jsx)(Lu,{className:`w-4 h-4`}),r(`forecast.alertCount`,{count:L.length}),c?(0,G.jsx)(us,{className:`w-3.5 h-3.5`}):(0,G.jsx)(ss,{className:`w-3.5 h-3.5`})]}),s&&(0,G.jsx)(j0e,{value:k,onSave:e=>{Z.updateSettings({forecast_global_lead_time_days:e}).then(()=>{t.invalidateQueries({queryKey:[`settings`]}),n(r(`forecast.globalLeadTimeSaved`),`success`)})}}),(0,G.jsxs)(`select`,{value:h,onChange:e=>g(e.target.value),className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${h?`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,G.jsx)(`option`,{value:``,children:r(`inventory.material`)}),P.map(e=>(0,G.jsx)(`option`,{value:e,children:e},e))]}),(0,G.jsxs)(`select`,{value:_,onChange:e=>v(e.target.value),className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${_?`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,G.jsx)(`option`,{value:``,children:r(`inventory.brand`)}),F.map(e=>(0,G.jsx)(`option`,{value:e,children:e},e))]}),(0,G.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,G.jsx)(au,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:r(`forecast.shoppingList`)}),B&&(0,G.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,G.jsx)(`div`,{className:`space-y-2`,children:L.map(e=>(0,G.jsx)(O0e,{forecast:e,onCart:()=>b(e)},e.group.key))}),x&&(0,G.jsx)(I0e,{items:O,forecasts:N,globalLeadTime:k,canWrite:s,onClose:()=>S(!1),onRemove:e=>{Z.removeFromShoppingList(e).then(()=>t.invalidateQueries({queryKey:[`shopping-list`]})).catch(()=>n(r(`forecast.failedSaveSettings`),`error`))},onClear:()=>{Z.clearShoppingList().then(()=>t.invalidateQueries({queryKey:[`shopping-list`]})).catch(()=>n(r(`forecast.failedSaveSettings`),`error`))}}),R.length>0&&(0,G.jsx)(A0e,{forecasts:R,days:C,onDaysChange:w}),N.length===0?(0,G.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-16 text-bambu-gray`,children:[(0,G.jsx)(Fu,{className:`w-10 h-10 mb-3 opacity-40`}),(0,G.jsx)(`p`,{className:`text-sm`,children:r(`forecast.noSpools`)})]}):(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg overflow-hidden border border-bambu-dark-tertiary`,children:[(0,G.jsx)(`div`,{className:`overflow-x-auto`,children:(0,G.jsxs)(`table`,{className:`w-full`,children:[(0,G.jsx)(`thead`,{children:(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary bg-bambu-dark-tertiary/30`,children:[(0,G.jsx)(`th`,{className:`w-8 px-4 py-3`}),(0,G.jsx)(c9,{col:`material`,active:u,dir:p,onSort:z,children:r(`forecast.sku`)}),(0,G.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:r(`locations.spools`)}),(0,G.jsx)(c9,{col:`stock`,active:u,dir:p,onSort:z,children:r(`forecast.stock`)}),(0,G.jsx)(c9,{col:`used`,active:u,dir:p,onSort:z,children:r(`forecast.dailyRate`)}),(0,G.jsx)(c9,{col:`days_left`,active:u,dir:p,onSort:z,children:r(`forecast.daysLeft`)}),(0,G.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:r(`forecast.emptyBy`)}),(0,G.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:r(`forecast.reorderBy`)}),(0,G.jsx)(`th`,{className:`w-24 px-4 py-3`})]})}),(0,G.jsx)(`tbody`,{className:`divide-y divide-bambu-dark-tertiary`,children:I.map(e=>(0,G.jsx)(M0e,{forecast:e,globalLeadTime:k,canWrite:s,onSaved:()=>t.invalidateQueries({queryKey:[`sku-settings`]}),onCart:()=>b(e),showToast:n},e.group.key))})]})}),(0,G.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,G.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,G.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-bambu-green inline-block`}),r(`forecast.trendLegend`)]}),(0,G.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,G.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-blue-400 inline-block`}),r(`forecast.estimatedLegend`)]}),(0,G.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,G.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-bambu-gray/40 inline-block`}),r(`forecast.noDataLegend`)]})]})]}),y&&(0,G.jsx)(R0e,{forecast:y,onClose:()=>b(null),onAdd:e=>{Z.addToShoppingList(e).then(()=>{t.invalidateQueries({queryKey:[`shopping-list`]}),n(r(`forecast.addedToCart`),`success`),b(null),S(!0)}).catch(()=>n(r(`forecast.failedAddItem`),`error`))}})]})}function c9({col:e,active:t,dir:n,onSort:r,children:i}){return(0,G.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,G.jsxs)(`span`,{className:`inline-flex items-center`,children:[i,t===e?n===`asc`?(0,G.jsx)(Io,{className:`w-3 h-3 ml-1 text-bambu-green`}):(0,G.jsx)(Ao,{className:`w-3 h-3 ml-1 text-bambu-green`}):(0,G.jsx)(Po,{className:`w-3 h-3 ml-1 opacity-40`})]})})}function O0e({forecast:e,onCart:t}){let{t:n}=U(),r=[e.group.brand,e.group.material,e.group.subtype,e.group.colorName].filter(Boolean).join(` `),i=e.stockBreakAlert;return(0,G.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,G.jsx)(Lu,{className:`w-4 h-4 flex-shrink-0`}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`span`,{className:`font-medium`,children:r}),i?(0,G.jsxs)(`span`,{className:`ml-2 text-xs opacity-80`,children:[n(`forecast.stockBreakRisk`),` — `,n(`forecast.stockBreakDetail`,{days:e.daysRemaining,lt:e.effectiveLeadTimeDays})]}):(0,G.jsxs)(`span`,{className:`ml-2 text-xs opacity-80`,children:[n(`forecast.reorderNow`),` — `,n(`forecast.reorderTriggerPassed`,{date:e.reorderTriggerDate?o9(e.reorderTriggerDate):`—`})]})]}),(0,G.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,G.jsx)(au,{className:`w-3 h-3`}),` `,n(`forecast.order`)]})]})}var k0e=[{label:`1W`,value:7},{label:`1M`,value:30},{label:`6M`,value:180}];function A0e({forecasts:e,days:t,onDaysChange:n}){let{t:r}=U(),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:C0e[n%C0e.length],rop:e.reorderPointG,points:E0e(e,t)})),o=i.map(e=>{let t={day:e,label:s9(a9(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,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg overflow-hidden border border-bambu-dark-tertiary p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-4`,children:[(0,G.jsx)(Fu,{className:`w-4 h-4 text-bambu-green`}),(0,G.jsx)(`h3`,{className:`text-sm font-semibold text-white`,children:r(`forecast.chartTitle`)}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray ml-1 hidden sm:inline`,children:r(`forecast.dashedLinesROP`)}),(0,G.jsx)(`div`,{className:`ml-auto flex items-center bg-bambu-dark-tertiary rounded-lg p-0.5`,children:k0e.map(e=>(0,G.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,G.jsx)(KA,{width:`100%`,height:220,children:(0,G.jsxs)(BH,{data:c,margin:{top:4,right:8,bottom:0,left:0},children:[(0,G.jsx)(`defs`,{children:a.map(e=>(0,G.jsxs)(`linearGradient`,{id:`grad-${e.key}`,x1:`0`,y1:`0`,x2:`0`,y2:`1`,children:[(0,G.jsx)(`stop`,{offset:`5%`,stopColor:e.color,stopOpacity:.25}),(0,G.jsx)(`stop`,{offset:`95%`,stopColor:e.color,stopOpacity:.02})]},e.key))}),(0,G.jsx)(aV,{strokeDasharray:`3 3`,stroke:`#374151`,strokeOpacity:.5}),(0,G.jsx)(XV,{dataKey:`label`,tick:{fill:`#6B7280`,fontSize:10},interval:Math.max(0,Math.ceil(s/8)-1),axisLine:!1,tickLine:!1}),(0,G.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,G.jsx)(kz,{content:({label:e,payload:t})=>t?.length?(0,G.jsxs)(`div`,{style:{background:`#1a1a2e`,border:`1px solid #374151`,borderRadius:8,fontSize:12,padding:`8px 12px`},children:[(0,G.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,G.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:6,color:`#E5E7EB`,marginBottom:2},children:[(0,G.jsx)(`span`,{style:{color:t?.color??`#9CA3AF`,fontSize:10},children:`●`}),(0,G.jsx)(`span`,{children:t?.label??String(e.dataKey)}),(0,G.jsxs)(`span`,{style:{color:`#9CA3AF`,marginLeft:4},children:[e.value,`g`]})]},String(e.dataKey)):null})]}):null}),(0,G.jsx)(Rj,{formatter:e=>(0,G.jsx)(`span`,{style:{color:`#9CA3AF`,fontSize:11},children:a.find(t=>t.key===e)?.label??e})}),a.map(e=>(0,G.jsx)(OV,{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,G.jsx)(JB,{y:e.rop,stroke:e.color,strokeDasharray:`4 3`,strokeOpacity:.6},`rop-${e.key}`))]})})]})}function j0e({value:e,onSave:t}){let{t:n}=U(),[r,i]=(0,f.useState)(!1),[a,o]=(0,f.useState)(String(e));function s(){let e=parseInt(a,10);isNaN(e)||e<0||(t(e),i(!1))}return(0,G.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,G.jsx)(Bc,{className:`w-3.5 h-3.5 flex-shrink-0`,"aria-label":n(`forecast.globalLeadTimeHint`)}),(0,G.jsxs)(`span`,{className:`hidden sm:inline`,children:[n(`forecast.globalLeadTime`),`:`]}),r?(0,G.jsxs)(`form`,{className:`flex items-center gap-1.5`,onSubmit:e=>{e.preventDefault(),s()},children:[(0,G.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,G.jsx)(`span`,{className:`text-bambu-gray`,children:`d`}),(0,G.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,G.jsx)(`button`,{type:`button`,onClick:()=>i(!1),className:`text-xs text-bambu-gray hover:text-white`,children:`✕`})]}):(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,G.jsxs)(`span`,{className:`font-semibold text-white`,children:[e,`d`]}),(0,G.jsx)(`button`,{onClick:()=>{o(String(e)),i(!0)},className:`p-0.5 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,G.jsx)(El,{className:`w-3 h-3`})})]})]})}function M0e({forecast:e,globalLeadTime:t,canWrite:n,onSaved:r,onCart:i,showToast:a}){let{t:o}=U(),[s,c]=(0,f.useState)(!1),[l,u]=(0,f.useState)(!1),[d,p]=(0,f.useState)(!1),[m,h]=(0,f.useState)(String(e.settings?.lead_time_days??0)),[g,_]=(0,f.useState)(String(e.settings?.safety_margin_value??14)),[v,y]=(0,f.useState)(e.settings?.safety_margin_unit??`days`);(0,f.useEffect)(()=>{l||h(String(e.settings?.lead_time_days??0))},[e.settings?.lead_time_days,l]),(0,f.useEffect)(()=>{d||(_(String(e.settings?.safety_margin_value??14)),y(e.settings?.safety_margin_unit??`days`))},[e.settings?.safety_margin_value,e.settings?.safety_margin_unit,d]);let b=q({mutationFn:Z.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?If(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,G.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,G.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-bambu-green`}),o(`forecast.trend`)]}):e.rateTier===`delta`?(0,G.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,G.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-blue-400`}),o(`forecast.estimated`)]}):(0,G.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,G.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-bambu-gray/40`}),o(`forecast.noData`)]});return(0,G.jsxs)(G.Fragment,{children:[(0,G.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,G.jsx)(`td`,{className:`px-4 py-3`,children:(0,G.jsx)(`span`,{className:`block w-5 h-5 rounded-full border border-black/20`,style:C})}),(0,G.jsx)(`td`,{className:`px-4 py-3`,children:(0,G.jsx)(`span`,{className:`text-sm text-white`,children:S})}),(0,G.jsx)(`td`,{className:`px-4 py-3`,children:(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.totalSpools})}),(0,G.jsx)(`td`,{className:`px-4 py-3 min-w-[140px]`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`div`,{className:`flex-1 h-2 bg-bambu-dark-tertiary rounded-full overflow-hidden`,children:(0,G.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,G.jsxs)(`span`,{className:`text-xs text-bambu-gray min-w-[40px] text-right`,children:[Math.round(e.totalRemainingG),`g`]})]})}),(0,G.jsx)(`td`,{className:`px-4 py-3`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 flex-wrap`,children:[(0,G.jsx)(`span`,{className:`text-sm text-white`,children:e.dailyRateG===null?`—`:`${e.dailyRateG.toFixed(1)}g/d`}),O]})}),(0,G.jsx)(`td`,{className:`px-4 py-3`,children:(0,G.jsx)(`span`,{className:`text-sm font-semibold ${T}`,children:e.daysRemaining===null?(0,G.jsx)(`span`,{className:`text-bambu-gray font-normal`,children:`—`}):`${e.daysRemaining}d`})}),(0,G.jsx)(`td`,{className:`px-4 py-3`,children:(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.projectedEmptyDate?o9(e.projectedEmptyDate):`—`})}),(0,G.jsx)(`td`,{className:`px-4 py-3`,children:(0,G.jsx)(`span`,{className:`text-sm ${!x&&e.reorderAlert?`text-yellow-700 dark:text-yellow-400`:`text-bambu-gray`}`,children:e.reorderTriggerDate?o9(e.reorderTriggerDate):`—`})}),(0,G.jsx)(`td`,{className:`px-4 py-3`,onClick:e=>e.stopPropagation(),children:(0,G.jsxs)(`div`,{className:`flex items-center justify-end gap-1`,children:[n&&(0,G.jsx)(`button`,{onClick:i,className:`p-1.5 text-bambu-gray hover:text-bambu-green rounded transition-colors`,title:o(`forecast.addToCart`),children:(0,G.jsx)(au,{className:`w-4 h-4`})}),!x&&(e.stockBreakAlert?(0,G.jsx)(Lu,{className:`w-4 h-4 text-red-600 dark:text-red-400`,"aria-label":o(`forecast.stockBreakRisk`)}):e.reorderAlert?(0,G.jsx)(Lu,{className:`w-4 h-4 text-yellow-600 dark:text-yellow-400`,"aria-label":o(`forecast.reorderNow`)}):e.daysRemaining===null?null:(0,G.jsx)(as,{className:`w-4 h-4 text-bambu-green/50`})),n&&(0,G.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,G.jsx)(Bo,{className:`w-3.5 h-3.5`})}),(0,G.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,G.jsx)(us,{className:`w-4 h-4`}):(0,G.jsx)(ss,{className:`w-4 h-4`})})]})})]}),s&&(0,G.jsx)(`tr`,{className:`bg-bambu-dark-tertiary/10`,children:(0,G.jsx)(`td`,{colSpan:9,className:`px-6 py-4`,children:(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{className:`grid gap-2 ${n?`grid-cols-2 sm:grid-cols-4`:`grid-cols-2`}`,children:[(0,G.jsx)(N0e,{label:o(`forecast.effectiveLeadTime`),value:`${e.effectiveLeadTimeDays}d`,hint:o(`forecast.effectiveLeadTimeHint`,{global:t,sku:e.settings?.lead_time_days??0})}),(0,G.jsx)(N0e,{label:o(`forecast.reorderPoint`),value:`${Math.round(e.reorderPointG)}g`,hint:o(`forecast.reorderPointHint`)}),n&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(P0e,{label:o(`forecast.skuLeadTimeOverride`),hint:o(`forecast.skuLeadTimeHint`),unit:o(`forecast.leadTime`),editing:l,value:e.settings?.lead_time_days??0,inputValue:m,onInputChange:h,onEdit:()=>{h(String(e.settings?.lead_time_days??0)),u(!0)},onSave:()=>{let t=parseInt(m,10);!isNaN(t)&&t>=0&&(E(t,e.settings?.safety_margin_value??14,v),u(!1))},onCancel:()=>u(!1),isPending:b.isPending,saveLabel:o(`forecast.save`),cancelLabel:o(`forecast.cancel`)}),(0,G.jsx)(F0e,{value:e.settings?.safety_margin_value??14,unit:v,editing:d,inputValue:g,dailyRateG:e.dailyRateG,onInputChange:_,onUnitChange:e=>y(e),onEdit:()=>{_(String(e.settings?.safety_margin_value??14)),y(e.settings?.safety_margin_unit??`days`),p(!0)},onSave:()=>{let t=parseInt(g,10);!isNaN(t)&&t>=0&&(E(e.settings?.lead_time_days??0,t,v),p(!1))},onCancel:()=>p(!1),isPending:b.isPending,saveLabel:o(`forecast.save`),cancelLabel:o(`forecast.cancel`),safetyMarginLabel:o(`forecast.safetyMarginLabel`)})]})]}),e.group.spools.length>1&&(0,G.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary pt-3`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:o(`forecast.individualSpools`)}),(0,G.jsx)(`div`,{className:`bg-bambu-dark-secondary rounded-lg overflow-hidden border border-bambu-dark-tertiary`,children:(0,G.jsxs)(`table`,{className:`w-full`,children:[(0,G.jsx)(`thead`,{children:(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary bg-bambu-dark-tertiary/30`,children:[(0,G.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:`#`}),(0,G.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:o(`inventory.remaining`)}),(0,G.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:o(`inventory.used`)}),(0,G.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:o(`forecast.labelWeight`)})]})}),(0,G.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,G.jsxs)(`tr`,{className:`hover:bg-bambu-dark-tertiary/30 transition-colors`,children:[(0,G.jsx)(`td`,{className:`px-4 py-2`,children:(0,G.jsxs)(`span`,{className:`text-xs font-mono text-bambu-gray/70`,children:[`#`,e.id]})}),(0,G.jsx)(`td`,{className:`px-4 py-2`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`w-24 h-1.5 bg-bambu-dark-tertiary rounded-full overflow-hidden flex-shrink-0`,children:(0,G.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,G.jsxs)(`span`,{className:`text-sm text-white`,children:[Math.round(t),`g`]})]})}),(0,G.jsx)(`td`,{className:`px-4 py-2`,children:(0,G.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[Math.round(Math.max(0,e.weight_used-(e.weight_used_baseline??0))),`g`]})}),(0,G.jsx)(`td`,{className:`px-4 py-2`,children:(0,G.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[e.label_weight,`g`]})})]},e.id)})})]})})]})]})})})]})}function N0e({label:e,value:t,hint:n}){return(0,G.jsxs)(`div`,{className:`bg-bambu-dark-tertiary/40 rounded-lg p-3`,title:n,children:[(0,G.jsx)(`div`,{className:`text-xs font-medium text-white mb-1`,children:e}),(0,G.jsx)(`div`,{className:`text-lg font-semibold text-white`,children:t})]})}function P0e({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,G.jsxs)(`div`,{className:`bg-bambu-dark-tertiary/40 rounded-lg p-3 space-y-1`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,G.jsx)(`span`,{className:`text-xs font-medium text-white`,children:e}),(0,G.jsx)(`span`,{title:t,children:(0,G.jsx)(Bc,{className:`w-3 h-3 text-bambu-gray/50`})})]}),r?(0,G.jsxs)(`form`,{className:`flex items-center gap-2`,onSubmit:e=>{e.preventDefault(),c()},children:[(0,G.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,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:n}),(0,G.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,G.jsx)(`button`,{type:`button`,onClick:l,disabled:u,className:`px-2 py-1 text-xs text-bambu-gray hover:text-white`,children:f})]}):(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-lg font-semibold text-white`,children:i}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:n}),(0,G.jsx)(`button`,{onClick:s,className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,G.jsx)(El,{className:`w-3 h-3`})})]})]})}function F0e({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}=U(),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,G.jsxs)(`div`,{className:`bg-bambu-dark-tertiary/40 rounded-lg p-3 space-y-1`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,G.jsx)(`span`,{className:`text-xs font-medium text-white`,children:p}),(0,G.jsx)(`span`,{title:g,children:(0,G.jsx)(Bc,{className:`w-3 h-3 text-bambu-gray/50`})})]}),n?(0,G.jsxs)(`form`,{className:`flex items-center gap-2 flex-wrap`,onSubmit:e=>{e.preventDefault(),c()},children:[(0,G.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,G.jsxs)(`div`,{className:`flex bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded overflow-hidden text-xs`,children:[(0,G.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,G.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,G.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,G.jsx)(`button`,{type:`button`,onClick:l,disabled:u,className:`px-2 py-1 text-xs text-bambu-gray hover:text-white`,children:f})]}):(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-lg font-semibold text-white`,children:e}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:t}),h!==null&&t===`days`&&(0,G.jsxs)(`span`,{className:`text-lg font-semibold text-white`,children:[`≈ `,h,`g`]}),t===`g`&&i!==null&&(0,G.jsxs)(`span`,{className:`text-lg font-semibold text-white`,children:[`≈ `,Math.round(e/i),`d`]}),(0,G.jsx)(`button`,{onClick:s,className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,G.jsx)(El,{className:`w-3 h-3`})})]})]})}function I0e({items:e,forecasts:t,globalLeadTime:n,canWrite:r,onClose:i,onRemove:a,onClear:o}){let{t:s}=U(),c=no(),[l,u]=(0,f.useState)(`list`),d=q({mutationFn:async({id:e,status:t,item:n,avgSpoolG:r})=>{if(await Z.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,material_number:null};await Z.bulkCreateSpools(i,n.quantity_spools),await Z.removeFromShoppingList(e)}},onSuccess:()=>{c.invalidateQueries({queryKey:[`shopping-list`]}),c.invalidateQueries({queryKey:[`spools`]})}}),p=(0,f.useMemo)(()=>{let e=new Map;for(let n of t)e.set(n.group.key,n);return e},[t]),m=(0,f.useMemo)(()=>e.map(e=>({item:e,forecast:p.get(i9(e.material,e.subtype,e.brand,e.color_name))??null})),[e,p]),h=(0,f.useMemo)(()=>m.filter(({forecast:e})=>!e||e.dailyRateG===null?!1:e.stockBreakAlert||e.daysRemaining!==null&&e.daysRemaining<=e.effectiveLeadTimeDays),[m]);function g(){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=p.get(i9(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?o9(a9(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(` +`},i)),a}function UQe(e,t){return e&&`run`in e?async function(n,r){let i=HQe(n,{file:r,...t});await e.run(i,r)}:function(n,r){return HQe(n,{file:r,...e||t})}}function WQe(e){if(e)throw e}var GQe=r(((e,t)=>{var n=Object.prototype.hasOwnProperty,r=Object.prototype.toString,i=Object.defineProperty,a=Object.getOwnPropertyDescriptor,o=function(e){return typeof Array.isArray==`function`?Array.isArray(e):r.call(e)===`[object Array]`},s=function(e){if(!e||r.call(e)!==`[object Object]`)return!1;var t=n.call(e,`constructor`),i=e.constructor&&e.constructor.prototype&&n.call(e.constructor.prototype,`isPrototypeOf`);if(e.constructor&&!t&&!i)return!1;for(var a in e);return a===void 0||n.call(e,a)},c=function(e,t){i&&t.name===`__proto__`?i(e,t.name,{enumerable:!0,configurable:!0,value:t.newValue,writable:!0}):e[t.name]=t.newValue},l=function(e,t){if(t===`__proto__`){if(!n.call(e,t))return;if(a)return a(e,t).value}return e[t]};t.exports=function e(){var t,n,r,i,a,u,d=arguments[0],f=1,p=arguments.length,m=!1;for(typeof d==`boolean`&&(m=d,d=arguments[1]||{},f=2),(d==null||typeof d!=`object`&&typeof d!=`function`)&&(d={});ft.length,o;r&&t.push(i);try{o=e.apply(this,t)}catch(e){let t=e;if(r&&n)throw t;return i(t)}r||(o&&o.then&&typeof o.then==`function`?o.then(a,i):o instanceof Error?i(o):a(o))}function i(e,...r){n||(n=!0,t(e,...r))}function a(e){i(null,e)}}var I7={basename:JQe,dirname:YQe,extname:XQe,join:ZQe,sep:`/`};function JQe(e,t){if(t!==void 0&&typeof t!=`string`)throw TypeError(`"ext" argument must be a string`);L7(e);let n=0,r=-1,i=e.length,a;if(t===void 0||t.length===0||t.length>e.length){for(;i--;)if(e.codePointAt(i)===47){if(a){n=i+1;break}}else r<0&&(a=!0,r=i+1);return r<0?``:e.slice(n,r)}if(t===e)return``;let o=-1,s=t.length-1;for(;i--;)if(e.codePointAt(i)===47){if(a){n=i+1;break}}else o<0&&(a=!0,o=i+1),s>-1&&(e.codePointAt(i)===t.codePointAt(s--)?s<0&&(r=i):(s=-1,r=o));return n===r?r=o:r<0&&(r=e.length),e.slice(n,r)}function YQe(e){if(L7(e),e.length===0)return`.`;let t=-1,n=e.length,r;for(;--n;)if(e.codePointAt(n)===47){if(r){t=n;break}}else r||=!0;return t<0?e.codePointAt(0)===47?`/`:`.`:t===1&&e.codePointAt(0)===47?`//`:e.slice(0,t)}function XQe(e){L7(e);let t=e.length,n=-1,r=0,i=-1,a=0,o;for(;t--;){let s=e.codePointAt(t);if(s===47){if(o){r=t+1;break}continue}n<0&&(o=!0,n=t+1),s===46?i<0?i=t:a!==1&&(a=1):i>-1&&(a=-1)}return i<0||n<0||a===0||a===1&&i===n-1&&i===r+1?``:e.slice(i,n)}function ZQe(...e){let t=-1,n;for(;++t0&&e.codePointAt(e.length-1)===47&&(n+=`/`),t?`/`+n:n}function $Qe(e,t){let n=``,r=0,i=-1,a=0,o=-1,s,c;for(;++o<=e.length;){if(o2){if(c=n.lastIndexOf(`/`),c!==n.length-1){c<0?(n=``,r=0):(n=n.slice(0,c),r=n.length-1-n.lastIndexOf(`/`)),i=o,a=0;continue}}else if(n.length>0){n=``,r=0,i=o,a=0;continue}}t&&(n=n.length>0?n+`/..`:`..`,r=2)}else n.length>0?n+=`/`+e.slice(i+1,o):n=e.slice(i+1,o),r=o-i-1;i=o,a=0}else s===46&&a>-1?a++:a=-1}return n}function L7(e){if(typeof e!=`string`)throw TypeError(`Path must be a string. Received `+JSON.stringify(e))}var e$e={cwd:t$e};function t$e(){return`/`}function R7(e){return!!(typeof e==`object`&&e&&`href`in e&&e.href&&`protocol`in e&&e.protocol&&e.auth===void 0)}function n$e(e){if(typeof e==`string`)e=new URL(e);else if(!R7(e)){let t=TypeError('The "path" argument must be of type string or an instance of URL. Received `'+e+"`");throw t.code=`ERR_INVALID_ARG_TYPE`,t}if(e.protocol!==`file:`){let e=TypeError(`The URL must be of scheme file`);throw e.code=`ERR_INVALID_URL_SCHEME`,e}return r$e(e)}function r$e(e){if(e.hostname!==``){let e=TypeError(`File URL host must be "localhost" or empty on darwin`);throw e.code=`ERR_INVALID_FILE_URL_HOST`,e}let t=e.pathname,n=-1;for(;++n0){let[r,...a]=t,o=n[i][1];F7(o)&&F7(r)&&(r=(0,H7.default)(!0,o,r)),n[i]=[e,r,...a]}}}}().freeze();function U7(e,t){if(typeof t!=`function`)throw TypeError("Cannot `"+e+"` without `parser`")}function W7(e,t){if(typeof t!=`function`)throw TypeError("Cannot `"+e+"` without `compiler`")}function G7(e,t){if(t)throw Error("Cannot call `"+e+"` on a frozen processor.\nCreate a new processor first, by calling it: use `processor()` instead of `processor`.")}function u$e(e){if(!F7(e)||typeof e.type!=`string`)throw TypeError("Expected node, got `"+e+"`")}function d$e(e,t,n){if(!n)throw Error("`"+e+"` finished async. Use `"+t+"` instead")}function K7(e){return f$e(e)?e:new i$e(e)}function f$e(e){return!!(e&&typeof e==`object`&&`message`in e&&`messages`in e)}function p$e(e){return typeof e==`string`||m$e(e)}function m$e(e){return!!(e&&typeof e==`object`&&`byteLength`in e&&`byteOffset`in e)}var q7=[],h$e={allowDangerousHtml:!0},g$e=/^(https?|ircs?|mailto|xmpp)$/i,_$e=[{from:`astPlugins`,id:`remove-buggy-html-in-markdown-parser`},{from:`allowDangerousHtml`,id:`remove-buggy-html-in-markdown-parser`},{from:`allowNode`,id:`replace-allownode-allowedtypes-and-disallowedtypes`,to:`allowElement`},{from:`allowedTypes`,id:`replace-allownode-allowedtypes-and-disallowedtypes`,to:`allowedElements`},{from:`disallowedTypes`,id:`replace-allownode-allowedtypes-and-disallowedtypes`,to:`disallowedElements`},{from:`escapeHtml`,id:`remove-buggy-html-in-markdown-parser`},{from:`includeElementIndex`,id:`#remove-includeelementindex`},{from:`includeNodeIndex`,id:`change-includenodeindex-to-includeelementindex`},{from:`linkTarget`,id:`remove-linktarget`},{from:`plugins`,id:`change-plugins-to-remarkplugins`,to:`remarkPlugins`},{from:`rawSourcePos`,id:`#remove-rawsourcepos`},{from:`renderers`,id:`change-renderers-to-components`,to:`components`},{from:`source`,id:`change-source-to-children`,to:`children`},{from:`sourcePos`,id:`#remove-sourcepos`},{from:`transformImageUri`,id:`#add-urltransform`,to:`urlTransform`},{from:`transformLinkUri`,id:`#add-urltransform`,to:`urlTransform`}];function v$e(e){let t=y$e(e),n=b$e(e);return x$e(t.runSync(t.parse(n),n),e)}function y$e(e){let t=e.rehypePlugins||q7,n=e.remarkPlugins||q7,r=e.remarkRehypeOptions?{...e.remarkRehypeOptions,...h$e}:h$e;return l$e().use(FZe).use(n).use(UQe,r).use(t)}function b$e(e){let t=e.children||``,n=new i$e;return typeof t==`string`?n.value=t:``+t,n}function x$e(e,t){let n=t.allowedElements,r=t.allowElement,i=t.components,a=t.disallowedElements,o=t.skipHtml,s=t.unwrapDisallowed,c=t.urlTransform||S$e;for(let e of _$e)Object.hasOwn(t,e.from)&&``+e.from+(e.to?"use `"+e.to+"` instead":`remove it`)+e.id;return t.className&&(e={type:`element`,tagName:`div`,properties:{className:t.className},children:e.type===`root`?e.children:[e]}),PQe(e,l),VJe(e,{Fragment:G.Fragment,components:i,ignoreInvalidStyle:!0,jsx:G.jsx,jsxs:G.jsxs,passKeys:!0,passNode:!0});function l(e,t,i){if(e.type===`raw`&&i&&typeof t==`number`)return o?i.children.splice(t,1):i.children[t]={type:`text`,value:e.value},t;if(e.type===`element`){let t;for(t in t7)if(Object.hasOwn(t7,t)&&Object.hasOwn(e.properties,t)){let n=e.properties[t],r=t7[t];(r===null||r.includes(e.tagName))&&(e.properties[t]=c(String(n||``),t,e))}}if(e.type===`element`){let o=n?!n.includes(e.tagName):a?a.includes(e.tagName):!1;if(!o&&r&&typeof t==`number`&&(o=!r(e,t,i)),o&&i&&typeof t==`number`)return s&&e.children?i.children.splice(t,1,...e.children):i.children.splice(t,1),t}}}function S$e(e){let t=e.indexOf(`:`),n=e.indexOf(`?`),r=e.indexOf(`#`),i=e.indexOf(`/`);return t===-1||i!==-1&&t>i||n!==-1&&t>n||r!==-1&&t>r||g$e.test(e.slice(0,t))?e:``}M$e.peek=j$e;function C$e(){this.buffer()}function w$e(e){this.enter({type:`footnoteReference`,identifier:``,label:``},e)}function T$e(){this.buffer()}function E$e(e){this.enter({type:`footnoteDefinition`,identifier:``,label:``,children:[]},e)}function D$e(e){let t=this.resume(),n=this.stack[this.stack.length-1];n.type,n.identifier=a7(this.sliceSerialize(e)).toLowerCase(),n.label=t}function O$e(e){this.exit(e)}function k$e(e){let t=this.resume(),n=this.stack[this.stack.length-1];n.type,n.identifier=a7(this.sliceSerialize(e)).toLowerCase(),n.label=t}function A$e(e){this.exit(e)}function j$e(){return`[`}function M$e(e,t,n,r){let i=n.createTracker(r),a=i.move(`[^`),o=n.enter(`footnoteReference`),s=n.enter(`reference`);return a+=i.move(n.safe(n.associationId(e),{after:`]`,before:a})),s(),o(),a+=i.move(`]`),a}function N$e(){return{enter:{gfmFootnoteCallString:C$e,gfmFootnoteCall:w$e,gfmFootnoteDefinitionLabelString:T$e,gfmFootnoteDefinition:E$e},exit:{gfmFootnoteCallString:D$e,gfmFootnoteCall:O$e,gfmFootnoteDefinitionLabelString:k$e,gfmFootnoteDefinition:A$e}}}L$e.peek=R$e;function P$e(){return{canContainEols:[`delete`],enter:{strikethrough:F$e},exit:{strikethrough:I$e}}}function F$e(e){this.enter({type:`delete`,children:[]},e)}function I$e(e){this.exit(e)}function L$e(e,t,n,r){let i=n.createTracker(r),a=n.enter(`strikethrough`),o=i.move(`~~`);return o+=n.containerPhrasing(e,{...i.current(),before:o,after:`~`}),o+=i.move(`~~`),a(),o}function R$e(){return`~`}function z$e(){return{enter:{table:B$e,tableData:U$e,tableHeader:U$e,tableRow:H$e},exit:{codeText:W$e,table:V$e,tableData:J7,tableHeader:J7,tableRow:J7}}}function B$e(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 V$e(e){this.exit(e),this.data.inTable=void 0}function H$e(e){this.enter({type:`tableRow`,children:[]},e)}function J7(e){this.exit(e)}function U$e(e){this.enter({type:`tableCell`,children:[]},e)}function W$e(e){let t=this.resume();this.data.inTable&&(t=t.replace(/\\([\\|])/g,G$e));let n=this.stack[this.stack.length-1];n.type,n.value=t,this.exit(e)}function G$e(e,t){return t===`|`?t:e}function K$e(){return{exit:{taskListCheckValueChecked:q$e,taskListCheckValueUnchecked:q$e,paragraph:J$e}}}function q$e(e){let t=this.stack[this.stack.length-2];t.type,t.checked=e.type===`taskListCheckValueChecked`}function J$e(e){let t=this.stack[this.stack.length-2];if(t&&t.type===`listItem`&&typeof t.checked==`boolean`){let e=this.stack[this.stack.length-1];e.type;let n=e.children[0];if(n&&n.type===`text`){let r=t.children,i=-1,a;for(;++i999||s===93&&!o||s===null||s===91||d7(s))return n(s);if(s===93){e.exit(`chunkString`);let a=e.exit(`gfmFootnoteCallString`);return i.includes(a7(r.sliceSerialize(a)))?(e.enter(`gfmFootnoteCallLabelMarker`),e.consume(s),e.exit(`gfmFootnoteCallLabelMarker`),e.exit(`gfmFootnoteCall`),t):n(s)}return d7(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 e1e(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||d7(t))return n(t);if(t===93){e.exit(`chunkString`);let n=e.exit(`gfmFootnoteDefinitionLabelString`);return a=a7(r.sliceSerialize(n)),e.enter(`gfmFootnoteDefinitionLabelMarker`),e.consume(t),e.exit(`gfmFootnoteDefinitionLabelMarker`),e.exit(`gfmFootnoteDefinitionLabel`),f}return d7(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),h7(e,p,`gfmFootnoteDefinitionWhitespace`)):n(t)}function p(e){return t(e)}}function t1e(e,t,n){return e.check(y7,t,e.attempt(Y$e,t,n))}function n1e(e){e.exit(`gfmFootnoteDefinition`)}function r1e(e,t,n){let r=this;return h7(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 i1e(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=g7(a);return l._open=!u||u===2&&!!s,l._close=!s||s===2&&!!u,n(a)}}}var a1e=class{constructor(){this.map=[]}add(e,t,n){o1e(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 o1e(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):u7(t)?a>1?(a=0,r.interrupt=!0,e.exit(`tableRow`),e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),p):n(t):f7(t)?h7(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||d7(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,f7(t)?h7(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 f7(t)?h7(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||u7(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 f7(t)?h7(e,b,`whitespace`)(t):b(t)}function b(n){return n===124?m(n):n===null||u7(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||u7(n)?(e.exit(`tableRow`),t(n)):f7(n)?h7(e,C,`whitespace`)(n):(e.enter(`data`),w(n))}function w(t){return t===null||t===124||d7(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 u1e(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 a1e;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({},X7(t.events,i)),e.add(i,0,[[`exit`,a,t]]),a=void 0),a}function d1e(e,t,n,r,i){let a=[],o=X7(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 X7(e,t){let n=e[t],r=n[0]===`enter`?`start`:`end`;return n[1][r]}var f1e={name:`tasklistCheck`,tokenize:m1e};function p1e(){return{text:{91:f1e}}}function m1e(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 d7(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 u7(r)?t(r):f7(r)?e.check({tokenize:h1e},t,n)(r):n(r)}}function h1e(e,t,n){return h7(e,r,`whitespace`);function r(e){return e===null?n(e):t(e)}}function g1e(){let e=this.data(),t=e.micromarkExtensions||=[],n=e.fromMarkdownExtensions||=[];t.push(X$e(),i1e(),c1e(),p1e()),n.push(N$e(),P$e(),z$e(),K$e())}var _1e=`fileManager.readmeCollapsed`;function v1e({folderId:e}){let{t}=U(),[n,r]=(0,f.useState)(()=>localStorage.getItem(_1e)===`1`);(0,f.useEffect)(()=>{localStorage.setItem(_1e,n?`1`:`0`)},[n]);let{data:i,isLoading:a,error:o}=K({queryKey:[`folder-readme`,e],queryFn:()=>Z.getLibraryFolderReadme(e),retry:!1,staleTime:3e4});return a||o||!i?null:n?(0,G.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,G.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,G.jsx)(sc,{className:`w-4 h-4 text-bambu-green flex-shrink-0`}),(0,G.jsx)(`span`,{className:`text-sm font-medium text-white truncate`,children:i.filename}),(0,G.jsx)(Cl,{className:`w-4 h-4 text-bambu-gray flex-shrink-0 ml-auto`})]}),(0,G.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,G.jsx)(Cl,{className:`w-4 h-4 text-bambu-green flex-shrink-0`}),(0,G.jsx)(`span`,{className:`text-xs font-medium text-bambu-gray [writing-mode:vertical-rl] rotate-180 select-none`,children:t(`fileManager.readme.label`)})]})]}):(0,G.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,G.jsxs)(`div`,{className:`flex items-center justify-between gap-2 px-3 py-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,G.jsx)(sc,{className:`w-4 h-4 text-bambu-green flex-shrink-0`}),(0,G.jsx)(`span`,{className:`text-sm font-medium text-white truncate`,title:i.filename,children:i.filename}),i.truncated&&(0,G.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,G.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,G.jsx)(Sl,{className:`w-4 h-4`})})]}),(0,G.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,G.jsx)(v$e,{remarkPlugins:[g1e],components:{h1:({children:e})=>(0,G.jsx)(`h1`,{className:`text-lg font-semibold text-white mt-2 mb-1`,children:e}),h2:({children:e})=>(0,G.jsx)(`h2`,{className:`text-base font-semibold text-white mt-2 mb-1`,children:e}),h3:({children:e})=>(0,G.jsx)(`h3`,{className:`text-sm font-semibold text-white mt-2 mb-1`,children:e}),p:({children:e})=>(0,G.jsx)(`p`,{className:`my-1`,children:e}),ul:({children:e})=>(0,G.jsx)(`ul`,{className:`list-disc list-inside space-y-0.5 ml-2`,children:e}),ol:({children:e})=>(0,G.jsx)(`ol`,{className:`list-decimal list-inside space-y-0.5 ml-2`,children:e}),li:({children:e})=>(0,G.jsx)(`li`,{children:e}),code:({children:e,...t})=>t.className?(0,G.jsx)(`code`,{className:`block p-2 bg-bambu-dark rounded text-xs font-mono text-bambu-gray-light overflow-x-auto`,children:e}):(0,G.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,G.jsx)(`pre`,{className:`my-2`,children:e}),blockquote:({children:e})=>(0,G.jsx)(`blockquote`,{className:`border-l-2 border-bambu-dark-tertiary pl-3 text-bambu-gray italic`,children:e}),a:({children:e,href:t})=>(0,G.jsx)(`a`,{href:t,target:`_blank`,rel:`noopener noreferrer`,className:`text-bambu-green hover:underline`,children:e}),table:({children:e})=>(0,G.jsx)(`div`,{className:`overflow-x-auto`,children:(0,G.jsx)(`table`,{className:`min-w-full text-xs border-collapse`,children:e})}),th:({children:e})=>(0,G.jsx)(`th`,{className:`border border-bambu-dark-tertiary px-2 py-1 text-left font-semibold text-white`,children:e}),td:({children:e})=>(0,G.jsx)(`td`,{className:`border border-bambu-dark-tertiary px-2 py-1`,children:e}),hr:()=>(0,G.jsx)(`hr`,{className:`border-bambu-dark-tertiary my-2`})},children:i.content})})]})}function y1e({open:e,onClose:t,onPickTag:n}){let{t:r}=U(),i=no(),{showToast:a}=Zd(),[o,s]=(0,f.useState)(!1),[c,l]=(0,f.useState)(null),[u,d]=(0,f.useState)(``),[p,m]=(0,f.useState)(null),{data:h=[],isLoading:g}=K({queryKey:A5,queryFn:Z.getLibraryTags,enabled:e}),_=()=>{i.invalidateQueries({queryKey:A5}),i.invalidateQueries({queryKey:[`library-files`]})},v=q({mutationFn:async()=>{let e=u.trim();if(!e)throw Error(r(`fileManager.tags.nameRequired`));return c?Z.updateLibraryTag(c.id,e):Z.createLibraryTag(e)},onSuccess:()=>{a(r(c?`fileManager.tags.updated`:`fileManager.tags.created`),`success`),s(!1),l(null),d(``),_()},onError:e=>{a(e.message||r(`fileManager.tags.saveFailed`),`error`)}}),y=q({mutationFn:e=>Z.deleteLibraryTag(e),onSuccess:()=>{a(r(`fileManager.tags.deleted`),`success`),m(null),_()},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,f.useCallback)(()=>{v.isPending||(s(!1),l(null),d(``))},[v.isPending]);(0,f.useEffect)(()=>{if(!e)return;let n=e=>{e.key===`Escape`&&(v.isPending||y.isPending||(o?S():p||t()))};return document.addEventListener(`keydown`,n),()=>document.removeEventListener(`keydown`,n)},[e,o,p,v.isPending,y.isPending,S,t]);let C=e=>{e.preventDefault(),v.mutate()};if(!e)return null;let w=`library-tags-modal-title`,T=`library-tag-editor-title`;return(0,G.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[(0,G.jsx)(`div`,{className:`absolute inset-0 bg-black/60`,onClick:()=>{v.isPending||y.isPending||t()}}),(0,G.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,G.jsxs)(`div`,{className:`flex items-center justify-between gap-4 px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,G.jsxs)(`h2`,{id:w,className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(wu,{className:`w-5 h-5 text-bambu-green`}),r(`fileManager.tags.title`)]}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-sm mt-0.5`,children:r(`fileManager.tags.subtitle`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(Q,{onClick:b,children:[(0,G.jsx)(Ml,{className:`w-4 h-4`}),r(`fileManager.tags.add`)]}),(0,G.jsx)(`button`,{type:`button`,className:`p-1.5 text-bambu-gray hover:text-white rounded`,onClick:t,"aria-label":r(`common.close`),children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]})]}),(0,G.jsx)(`div`,{className:`overflow-y-auto`,children:g?(0,G.jsxs)(`div`,{className:`flex items-center justify-center py-16 text-bambu-gray`,children:[(0,G.jsx)(Y,{className:`w-6 h-6 animate-spin mr-2`}),r(`common.loading`)]}):h.length===0?(0,G.jsx)(`div`,{className:`py-16 text-center text-bambu-gray`,children:r(`fileManager.tags.empty`)}):(0,G.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,G.jsx)(`thead`,{children:(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary text-left text-bambu-gray`,children:[(0,G.jsx)(`th`,{className:`px-4 py-3 font-medium`,children:r(`fileManager.tags.name`)}),(0,G.jsx)(`th`,{className:`px-4 py-3 font-medium text-right`,children:r(`fileManager.tags.fileCount`)}),(0,G.jsx)(`th`,{className:`px-4 py-3 font-medium text-right w-32`,children:r(`common.actions`)})]})}),(0,G.jsx)(`tbody`,{children:h.map(e=>(0,G.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,G.jsx)(`td`,{className:`px-4 py-3 text-white font-medium`,children:e.name}),(0,G.jsx)(`td`,{className:`px-4 py-3 text-right text-bambu-gray`,children:e.file_count}),(0,G.jsx)(`td`,{className:`px-4 py-3 text-right`,onClick:e=>e.stopPropagation(),children:(0,G.jsxs)(`div`,{className:`flex items-center justify-end gap-1`,children:[(0,G.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,G.jsx)(Dl,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{type:`button`,className:`p-1.5 text-bambu-gray hover:text-red-600 dark:hover:text-red-400 rounded`,onClick:()=>m(e),title:r(`common.delete`),"aria-label":r(`fileManager.tags.deleteAria`,{name:e.name}),children:(0,G.jsx)(Pu,{className:`w-4 h-4`})})]})})]},e.id))})]})})]}),o&&(0,G.jsxs)(`div`,{className:`fixed inset-0 z-[60] flex items-center justify-center`,children:[(0,G.jsx)(`div`,{className:`absolute inset-0 bg-black/60`,onClick:S}),(0,G.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,G.jsx)(`h3`,{id:T,className:`text-lg font-semibold text-white mb-4`,children:r(c?`fileManager.tags.edit`:`fileManager.tags.add`)}),(0,G.jsxs)(`form`,{onSubmit:C,children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,htmlFor:`library-tag-name`,children:r(`fileManager.tags.name`)}),(0,G.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,G.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:S,children:r(`common.cancel`)}),(0,G.jsxs)(Q,{type:`submit`,disabled:v.isPending||!u.trim(),children:[v.isPending&&(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),r(`common.save`)]})]})]})]})]}),p&&(0,G.jsx)(uf,{title:r(`fileManager.tags.confirmDelete`,{name:p.name}),message:p.file_count>0?r(`fileManager.tags.confirmDeleteInUseMessage`,{count:p.file_count}):r(`fileManager.tags.confirmDeleteMessage`),confirmText:r(`common.delete`),variant:`danger`,isLoading:y.isPending,onConfirm:()=>y.mutate(p.id),onCancel:()=>m(null)})]})}function b1e({file:e,canEdit:t,onClose:n}){let{t:r}=U(),{showToast:i}=Zd(),a=no(),{data:o}=K({queryKey:[`library-file`,e.id],queryFn:()=>Z.getLibraryFile(e.id)}),[s,c]=(0,f.useState)(``),[l,u]=(0,f.useState)(``),[d,p]=(0,f.useState)([]),[m,h]=(0,f.useState)(!1),[g,_]=(0,f.useState)(null),v=(0,f.useRef)(null),y=(0,f.useRef)(null);(0,f.useEffect)(()=>{!o||y.current===o.id||(y.current=o.id,c(o.notes??``),u(o.external_url??``),p(o.photos??[]))},[o]),(0,f.useEffect)(()=>{if(g!==null)return;let e=e=>{e.key===`Escape`&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[g,n]);let b=()=>{a.invalidateQueries({queryKey:[`library-files`]}),a.invalidateQueries({queryKey:[`library-file`,e.id]})},x=q({mutationFn:()=>Z.updateLibraryFile(e.id,{notes:s,external_url:l.trim()}),onSuccess:()=>{b(),i(r(`fileManager.details.saved`),`success`),n()},onError:()=>{i(r(`fileManager.details.saveFailed`),`error`)}}),S=!!o&&(s!==(o.notes??``)||l.trim()!==(o.external_url??``)),C=async t=>{let n=t.target.files?.[0];if(n){h(!0);try{p((await Z.uploadLibraryFilePhoto(e.id,n)).photos),b()}catch{i(r(`fileManager.details.uploadFailed`),`error`)}finally{h(!1),v.current&&(v.current.value=``)}}},w=async t=>{try{let n=(await Z.deleteLibraryFilePhoto(e.id,t)).photos??[];p(n),n.length===0&&_(null),b()}catch{i(r(`fileManager.details.deleteFailed`),`error`)}},T=e=>{e.preventDefault(),!(!t||!S)&&x.mutate()},E=l.trim(),D=[{label:r(`fileManager.details.size`),value:Yd(e.file_size)},{label:r(`fileManager.details.type`),value:e.file_type.toUpperCase()}];return o?.print_name&&D.push({label:r(`fileManager.details.printName`),value:o.print_name}),o?.print_time_seconds&&D.push({label:r(`fileManager.details.printTime`),value:pp(o.print_time_seconds)}),o?.filament_used_grams&&D.push({label:r(`fileManager.details.filament`),value:`${o.filament_used_grams.toFixed(1)} g`}),o?.sliced_for_model&&D.push({label:r(`fileManager.details.slicedFor`),value:o.sliced_for_model}),o?.source_url&&D.push({label:r(`fileManager.details.source`),value:(0,G.jsxs)(`a`,{href:o.source_url,target:`_blank`,rel:`noopener noreferrer`,className:`text-bambu-green hover:underline inline-flex items-center gap-1 min-w-0`,children:[(0,G.jsx)(`span`,{className:`truncate`,children:o.source_url}),(0,G.jsx)(Qs,{className:`w-3 h-3 flex-shrink-0`})]})}),D.push({label:r(`fileManager.details.created`),value:cp(e.created_at)}),D.push({label:r(`fileManager.details.modified`),value:cp(e.fs_modified_at??o?.updated_at??e.created_at)}),(0,G.jsxs)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:n,children:[(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-lg max-h-[90vh] flex flex-col`,onClick:e=>e.stopPropagation(),children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-3 px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:r(`fileManager.details.title`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white truncate`,title:e.filename,children:e.filename}),(0,G.jsx)(`span`,{className:`flex-shrink-0 text-xs px-1.5 py-0.5 rounded font-medium bg-bambu-dark-tertiary text-bambu-gray`,children:e.file_type.toUpperCase()})]})]}),(0,G.jsx)(`button`,{type:`button`,onClick:n,className:`text-bambu-gray hover:text-white transition-colors flex-shrink-0`,"aria-label":r(`common.close`),children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]}),(0,G.jsxs)(`form`,{onSubmit:T,className:`p-6 space-y-4 overflow-y-auto flex-1`,children:[(0,G.jsx)(`dl`,{className:`grid grid-cols-[auto_1fr] gap-x-4 gap-y-1 text-sm`,children:D.map(e=>(0,G.jsxs)(`div`,{className:`contents`,children:[(0,G.jsx)(`dt`,{className:`text-bambu-gray whitespace-nowrap`,children:e.label}),(0,G.jsx)(`dd`,{className:`text-white min-w-0 truncate`,children:e.value})]},e.label))}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[(0,G.jsx)(bu,{className:`w-4 h-4 inline mr-1`}),r(`fileManager.details.notes`)]}),(0,G.jsx)(`textarea`,{value:s,onChange:e=>c(e.target.value),rows:3,disabled:!t,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none resize-none disabled:opacity-60`,placeholder:r(`fileManager.details.notesPlaceholder`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[(0,G.jsx)(qc,{className:`w-4 h-4 inline mr-1`}),r(`fileManager.details.externalLink`)]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`input`,{type:`url`,value:l,onChange:e=>u(e.target.value),disabled:!t,className:`flex-1 min-w-0 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none disabled:opacity-60`,placeholder:r(`fileManager.details.externalLinkPlaceholder`)}),E&&(0,G.jsx)(`a`,{href:E,target:`_blank`,rel:`noopener noreferrer`,className:`p-2 rounded-lg text-bambu-gray hover:text-bambu-green hover:bg-bambu-dark transition-colors`,title:r(`fileManager.details.openLink`),"aria-label":r(`fileManager.details.openLink`),children:(0,G.jsx)(Qs,{className:`w-4 h-4`})})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[(0,G.jsx)(es,{className:`w-4 h-4 inline mr-1`}),r(`fileManager.details.photos`)]}),(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[d.map((n,i)=>(0,G.jsxs)(`div`,{className:`relative group`,children:[(0,G.jsx)(`button`,{type:`button`,onClick:()=>_(i),className:`block w-20 h-20 rounded-lg overflow-hidden border border-bambu-dark-tertiary hover:border-bambu-green transition-colors`,children:(0,G.jsx)(`img`,{src:Z.getLibraryFilePhotoUrl(e.id,n),alt:r(`fileManager.details.photos`),className:`w-full h-full object-cover`})}),t&&(0,G.jsx)(`button`,{type:`button`,onClick:()=>w(n),className:`absolute -top-1 -right-1 p-1 bg-red-500 rounded-full can-hover:opacity-0 group-hover:opacity-100 focus-visible:opacity-100 transition-opacity`,title:r(`fileManager.details.deletePhoto`),"aria-label":r(`fileManager.details.deletePhoto`),children:(0,G.jsx)(Pu,{className:`w-3 h-3 text-white`})})]},n)),t&&(0,G.jsxs)(`label`,{className:`w-20 h-20 flex items-center justify-center border-2 border-dashed border-bambu-dark-tertiary rounded-lg cursor-pointer hover:border-bambu-green transition-colors`,title:r(`fileManager.details.addPhoto`),children:[(0,G.jsx)(`input`,{ref:v,type:`file`,accept:`image/jpeg,image/png,image/webp`,onChange:C,className:`hidden`,disabled:m,"aria-label":r(`fileManager.details.addPhoto`)}),m?(0,G.jsx)(Y,{className:`w-6 h-6 text-bambu-gray animate-spin`}):(0,G.jsx)(Ml,{className:`w-6 h-6 text-bambu-gray`})]}),d.length===0&&!t&&(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:r(`fileManager.details.noPhotos`)})]})]}),(0,G.jsxs)(`div`,{className:`flex gap-3 pt-2`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:n,className:`flex-1`,children:r(`common.close`)}),t&&(0,G.jsxs)(Q,{type:`submit`,variant:`primary`,className:`flex-1`,disabled:!S||x.isPending,children:[x.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Wl,{className:`w-4 h-4`}),r(`fileManager.details.save`)]})]})]})]}),g!==null&&d.length>0&&(0,G.jsx)(XW,{archiveName:e.filename,photos:d,initialIndex:g,getPhotoUrl:t=>Z.getLibraryFilePhotoUrl(e.id,t),onClose:()=>_(null),onDelete:t?w:void 0})]})}var x1e=90;function S1e({onClose:e}){let{t}=U(),n=no(),{showToast:r}=Zd(),[i,a]=(0,f.useState)(x1e),[o,s]=(0,f.useState)(!0),[c,l]=(0,f.useState)(i);(0,f.useEffect)(()=>{let e=window.setTimeout(()=>l(i),300);return()=>window.clearTimeout(e)},[i]);let u=K({queryKey:[`library-purge-preview`,c,o],queryFn:()=>Z.previewLibraryPurge(c,o),enabled:c>=1}),d=q({mutationFn:()=>Z.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,f.useEffect)(()=>{let t=t=>{t.key===`Escape`&&!d.isPending&&e()};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e,d.isPending]);let p=u.data,m=p?.count??0,h=p?.total_bytes??0,g=m>0&&!d.isPending;return(0,G.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4`,children:(0,G.jsxs)(`div`,{className:`bg-white dark:bg-gray-900 rounded-lg shadow-xl max-w-lg w-full`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-gray-200 dark:border-gray-700`,children:[(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-gray-900 dark:text-gray-100 flex items-center gap-2`,children:[(0,G.jsx)(Pu,{className:`w-5 h-5`}),t(`libraryPurge.title`)]}),(0,G.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,G.jsx)(nd,{className:`w-5 h-5`})})]}),(0,G.jsxs)(`div`,{className:`p-4 space-y-4`,children:[(0,G.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400`,children:t(`libraryPurge.description`)}),(0,G.jsxs)(`div`,{children:[(0,G.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,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.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,G.jsx)(`span`,{className:`text-sm text-gray-600 dark:text-gray-400`,children:t(`libraryPurge.days`)})]})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-gray-700 dark:text-gray-300`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:o,onChange:e=>s(e.target.checked),className:`rounded border-gray-300`}),t(`libraryPurge.includeNeverPrinted`)]}),(0,G.jsxs)(`div`,{className:`rounded border border-gray-200 dark:border-gray-700 bg-gray-50 dark:bg-gray-800/30 p-3`,children:[(0,G.jsx)(`div`,{className:`text-xs font-semibold uppercase tracking-wide text-gray-600 dark:text-gray-300 mb-2`,children:t(`libraryPurge.effectsTitle`)}),(0,G.jsxs)(`ul`,{className:`text-xs text-gray-700 dark:text-gray-300 space-y-1 list-disc pl-4`,children:[(0,G.jsx)(`li`,{children:t(`libraryPurge.effect1`)}),(0,G.jsx)(`li`,{children:t(`libraryPurge.effect2`)}),(0,G.jsx)(`li`,{children:t(`libraryPurge.effect3`)}),(0,G.jsx)(`li`,{children:t(`libraryPurge.effect4`)})]})]}),(0,G.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,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-gray-500 dark:text-gray-400`,children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),` `,t(`libraryPurge.previewLoading`)]}):u.isError?(0,G.jsx)(`div`,{className:`text-sm text-red-600 dark:text-red-400`,children:u.error?.message??t(`libraryPurge.previewFailed`)}):(0,G.jsxs)(`div`,{className:`text-sm text-gray-900 dark:text-gray-100`,children:[(0,G.jsx)(`div`,{className:`font-medium`,children:t(`libraryPurge.previewSummary`,{count:m,size:Yd(h)})}),p?.sample_filenames&&p.sample_filenames.length>0&&(0,G.jsxs)(`ul`,{className:`mt-2 text-xs text-gray-600 dark:text-gray-400 space-y-0.5 list-disc pl-4`,children:[p.sample_filenames.map(e=>(0,G.jsx)(`li`,{className:`truncate`,children:e},e)),m>p.sample_filenames.length&&(0,G.jsx)(`li`,{className:`list-none italic text-gray-500`,children:t(`libraryPurge.andMore`,{count:m-p.sample_filenames.length})})]})]})}),(0,G.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,G.jsx)(Lu,{className:`w-4 h-4 mt-0.5 shrink-0`}),(0,G.jsx)(`span`,{children:t(`libraryPurge.warning`)})]})]}),(0,G.jsxs)(`div`,{className:`flex justify-end gap-2 p-4 border-t border-gray-200 dark:border-gray-700`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:e,disabled:d.isPending,children:t(`common.cancel`)}),(0,G.jsx)(Q,{variant:`danger`,disabled:!g,onClick:()=>d.mutate(),children:d.isPending?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin mr-1`}),t(`libraryPurge.purging`)]}):t(`libraryPurge.confirmCta`,{count:m})})]})]})})}var C1e=(0,f.lazy)(()=>Dt(()=>import(`./PdfPreviewModal-C4ar5SVt.js`).then(e=>({default:e.PdfPreviewModal})),__vite__mapDeps([0,1]))),w1e=(0,f.lazy)(()=>Dt(()=>import(`./SpreadsheetPreviewModal-Dt2h99YI.js`).then(e=>({default:e.SpreadsheetPreviewModal})),__vite__mapDeps([2,1]))),T1e=(0,f.lazy)(()=>Dt(()=>import(`./ImagePreviewModal-DRfunMYn.js`).then(e=>({default:e.ImagePreviewModal})),__vite__mapDeps([3,1])));function Z7(e){return e===`csv`||e===`xlsx`||e===`ods`}function Q7(e){return e===`step`||e===`stp`}var E1e=new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`bmp`,`tiff`,`tif`]),D1e=new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`bmp`]);function O1e(e){return E1e.has(e.toLowerCase())}function k1e(e){return D1e.has(e.toLowerCase())}function $7(e){let t=e.file_type;return w5(e)||t===`3mf`||t===`stl`||Q7(t)||t===`pdf`||Z7(t)||k1e(t)}var e9={onClick:e=>e.stopPropagation(),onDoubleClick:e=>e.stopPropagation()};function t9(e){return w5(e)||e.file_type===`3mf`||e.file_type===`stl`||Q7(e.file_type)}function A1e(e){return e===`pdf`?(0,G.jsx)(sc,{className:`w-4 h-4`}):Z7(e)?(0,G.jsx)(oc,{className:`w-4 h-4`}):(0,G.jsx)(Rc,{className:`w-4 h-4`})}function j1e(e){return e===`stl`||e===`pdf`}function M1e({parentId:e,onClose:t,onSave:n,isLoading:r,t:i}){let[a,o]=(0,f.useState)(``);return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg w-full max-w-sm border border-bambu-dark-tertiary`,children:[(0,G.jsx)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary`,children:(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(`fileManager.newFolder`)})}),(0,G.jsxs)(`form`,{onSubmit:t=>{t.preventDefault(),n({name:a.trim(),parent_id:e})},className:`p-4 space-y-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:i(`fileManager.folderName`)}),(0,G.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,G.jsxs)(`div`,{className:`flex justify-end gap-2 pt-2`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:t,children:i(`common.cancel`)}),(0,G.jsx)(Q,{type:`submit`,disabled:!a.trim()||r,children:r?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):i(`common.create`)})]})]})]})})}function N1e({onClose:e,onSave:t,isLoading:n,t:r}){let[i,a]=(0,f.useState)(``),[o,s]=(0,f.useState)(``),[c,l]=(0,f.useState)(!0),[u,d]=(0,f.useState)(!1);return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg w-full max-w-md border border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(hc,{className:`w-5 h-5 text-bambu-green`}),r(`fileManager.linkExternalFolder`)]}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:r(`fileManager.linkExternalFolderDescription`)})]}),(0,G.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,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:r(`fileManager.folderName`)}),(0,G.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,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:r(`fileManager.externalPath`)}),(0,G.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,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:r(`fileManager.externalPathHelp`)})]}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,G.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,G.jsx)(`span`,{className:`text-sm text-white`,children:r(`fileManager.readOnly`)}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[`(`,r(`fileManager.readOnlyHelp`),`)`]})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,G.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,G.jsx)(`span`,{className:`text-sm text-white`,children:r(`fileManager.showHiddenFiles`)})]})]}),(0,G.jsxs)(`div`,{className:`flex justify-end gap-2 pt-2`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:e,children:r(`common.cancel`)}),(0,G.jsx)(Q,{type:`submit`,disabled:!i.trim()||!o.trim()||n,children:n?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):r(`fileManager.linkFolder`)})]})]})]})})}var P1e=`<>:"/\\|?*`;function F1e(e){for(let t of e)if(P1e.includes(t)||t.charCodeAt(0)<32)return t;return null}function I1e({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,f.useState)(s),u=e===`file`?F1e(c):null,d=u?a(`fileManager.invalidFilenameChar`,{char:u}):null;return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg w-full max-w-sm border border-bambu-dark-tertiary`,children:[(0,G.jsx)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary`,children:(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:a(e===`file`?`fileManager.renameFile`:`fileManager.renameFolder`)})}),(0,G.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,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`common.name`)}),(0,G.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,G.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,G.jsx)(`span`,{className:`pr-3 text-bambu-gray text-sm select-none whitespace-nowrap`,children:o})]}),d&&(0,G.jsx)(`p`,{className:`mt-1 text-xs text-red-700 dark:text-red-400`,children:d})]}),(0,G.jsxs)(`div`,{className:`flex justify-end gap-2 pt-2`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:n,children:a(`common.cancel`)}),(0,G.jsx)(Q,{type:`submit`,disabled:!c.trim()||c.trim()===s||!!d||i,children:i?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):a(`common.rename`)})]})]})]})})}function L1e({folders:e,selectedFiles:t,currentFolderId:n,onClose:r,onMove:i,isLoading:a,t:o}){let[s,c]=(0,f.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,G.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg w-full max-w-sm border border-bambu-dark-tertiary`,children:[(0,G.jsx)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary`,children:(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:o(`fileManager.moveFiles`,{count:t.length})})}),(0,G.jsxs)(`div`,{className:`p-4 space-y-4`,children:[(0,G.jsx)(`div`,{className:`max-h-64 overflow-y-auto space-y-1`,children:u.map(e=>(0,G.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,G.jsx)(pc,{className:`w-4 h-4`}),e.name,e.id===n&&(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray ml-auto`,children:[`(`,o(`fileManager.current`),`)`]})]},e.id??`root`))}),(0,G.jsxs)(`div`,{className:`flex justify-end gap-2 pt-2`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:r,children:o(`common.cancel`)}),(0,G.jsx)(Q,{onClick:()=>i(s),disabled:a,children:a?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):o(`common.move`)})]})]})]})})}function R1e({folder:e,onClose:t,onLink:n,isLoading:r,t:i}){let[a,o]=(0,f.useState)(`project`),[s,c]=(0,f.useState)(e.project_id||e.archive_id||null);(0,f.useState)(()=>{e.archive_id&&o(`archive`)});let{data:l}=K({queryKey:[`projects`],queryFn:()=>Z.getProjects(),select:t=>em([...t].sort((e,t)=>e.name.localeCompare(t.name)),e.project_id)}),{data:u}=K({queryKey:[`archives-for-link`],queryFn:()=>Z.getArchives(void 0,void 0,100)}),d=()=>{n(a===`project`?{project_id:s,archive_id:0}:{project_id:0,archive_id:s})},p=()=>{n({project_id:0,archive_id:0})},m=e.project_id||e.archive_id;return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg w-full max-w-md border border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary flex items-center justify-between`,children:[(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(Kc,{className:`w-5 h-5 text-bambu-green`}),i(`fileManager.linkFolder`)]}),(0,G.jsx)(`button`,{onClick:t,className:`p-1 hover:bg-bambu-dark rounded`,children:(0,G.jsx)(nd,{className:`w-5 h-5 text-bambu-gray`})})]}),(0,G.jsxs)(`div`,{className:`p-4 space-y-4`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`fileManager.linkFolderDescription`,{name:e.name})}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.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,G.jsx)(Go,{className:`w-4 h-4`}),i(`fileManager.project`)]}),(0,G.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,G.jsx)(Oo,{className:`w-4 h-4`}),i(`fileManager.archive`)]})]}),(0,G.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,G.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,G.jsx)(`div`,{className:`w-3 h-3 rounded-full flex-shrink-0`,style:{backgroundColor:e.color||`#00ae42`}}),(0,G.jsx)(`span`,{className:`truncate`,children:e.name})]},e.id)):(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray text-center py-4`,children:i(`fileManager.noProjectsFound`)}):u&&u.length>0?u.map(e=>(0,G.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,G.jsx)(nc,{className:`w-4 h-4 text-bambu-gray flex-shrink-0`}),(0,G.jsx)(`span`,{className:`truncate`,children:e.print_name||e.filename})]},e.id)):(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray text-center py-4`,children:i(`fileManager.noArchivesFound`)})})]}),(0,G.jsxs)(`div`,{className:`p-4 border-t border-bambu-dark-tertiary flex justify-between`,children:[m&&(0,G.jsxs)(Q,{variant:`danger`,onClick:p,disabled:r,children:[(0,G.jsx)(Bu,{className:`w-4 h-4 mr-2`}),i(`fileManager.unlink`)]}),(0,G.jsxs)(`div`,{className:`flex gap-2 ${m?``:`ml-auto`}`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:t,children:i(`common.cancel`)}),(0,G.jsx)(Q,{onClick:d,disabled:!s||r,children:r?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):i(`fileManager.link`)})]})]})]})})}function z1e({folder:e,selectedFolderId:t,onSelect:n,onDelete:r,onLink:i,onRename:a,depth:o=0,wrapNames:s=!1,defaultExpanded:c=!0,showModified:l=!1,hasPermission:u,t:d}){let[p,m]=(0,f.useState)(c),[h,g]=(0,f.useState)(!1),_=e.children.length>0,v=e.project_id||e.archive_id,y=e.is_external,b=u(`library:delete_all`)||u(`library:delete_own`)&&e.file_count===0&&!_&&!y&&!v,x=b?void 0:u(`library:delete_own`)&&!y&&!v?d(`fileManager.onlyEmptyFoldersDeletable`):d(`fileManager.noPermissionDeleteFolder`);return(0,G.jsxs)(`div`,{children:[(0,G.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:[_?(0,G.jsx)(`button`,{onClick:e=>{e.stopPropagation(),m(!p)},className:`p-0.5 hover:bg-bambu-dark-tertiary rounded`,children:(0,G.jsx)(cs,{className:`w-3.5 h-3.5 transition-transform ${p?`rotate-90`:``}`})}):(0,G.jsx)(`div`,{className:`w-4.5`}),y?(0,G.jsx)(hc,{className:`w-4 h-4 text-purple-600 dark:text-purple-400 flex-shrink-0`}):(0,G.jsx)(pc,{className:`w-4 h-4 text-bambu-green flex-shrink-0`}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`span`,{className:`block text-sm ${s?`break-all`:`truncate`}`,title:e.name,children:e.name}),l&&e.latest_activity_at&&(0,G.jsxs)(`span`,{className:`mt-0.5 flex items-center gap-1 text-xs text-bambu-gray`,title:d(`fileManager.lastActivity`),children:[(0,G.jsx)(Xo,{className:`w-3 h-3 flex-shrink-0`}),(0,G.jsx)(`span`,{className:`truncate`,children:cp(e.latest_activity_at)})]})]}),v&&(0,G.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,G.jsx)(Kc,{className:`w-3 h-3`}),e.project_name?(0,G.jsx)(Go,{className:`w-3 h-3`}):(0,G.jsx)(Oo,{className:`w-3 h-3`})]}),y&&e.external_readonly&&(0,G.jsx)(`span`,{title:d(`fileManager.readOnly`),children:(0,G.jsx)(Qc,{className:`w-3 h-3 text-amber-600 dark:text-amber-400 flex-shrink-0`})}),e.file_count>0&&(0,G.jsx)(`span`,{className:`flex-shrink-0 text-xs text-bambu-gray`,children:e.file_count}),!v&&!y&&(0,G.jsx)(`button`,{onClick:t=>{t.stopPropagation(),i(e)},className:`flex-shrink-0 p-1 rounded hover:bg-bambu-dark-tertiary`,title:d(`fileManager.linkToProjectOrArchive`),children:(0,G.jsx)(Kc,{className:`w-3.5 h-3.5 text-bambu-gray hover:text-bambu-green`})}),(0,G.jsx)(`div`,{className:`flex-shrink-0 flex items-center gap-0.5 transition-opacity ${s?``:`can-hover:opacity-0 group-hover:opacity-100 group-focus-within:opacity-100`}`,onClick:e=>e.stopPropagation(),children:(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(`button`,{onClick:()=>g(!h),className:`p-1 rounded hover:bg-bambu-dark-tertiary`,children:(0,G.jsx)(Js,{className:`w-3.5 h-3.5 text-bambu-gray`})}),h&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`fixed inset-0 z-10`,onClick:()=>g(!1)}),(0,G.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,G.jsxs)(`button`,{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${u(`library:update_all`)?`text-white hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{u(`library:update_all`)&&(a(e),g(!1))},disabled:!u(`library:update_all`),title:u(`library:update_all`)?void 0:d(`fileManager.noPermissionRenameFolder`),children:[(0,G.jsx)(Dl,{className:`w-3.5 h-3.5`}),d(`common.rename`)]}),(0,G.jsxs)(`button`,{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${u(`library:update_all`)?`text-white hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{u(`library:update_all`)&&(i(e),g(!1))},disabled:!u(`library:update_all`),title:u(`library:update_all`)?void 0:d(`fileManager.noPermissionLinkFolder`),children:[(0,G.jsx)(Kc,{className:`w-3.5 h-3.5`}),d(v?`fileManager.changeLink`:`fileManager.linkTo`)]}),(0,G.jsxs)(`button`,{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${b?`text-red-700 dark:text-red-400 hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{b&&(r(e.id),g(!1))},disabled:!b,title:x,children:[(0,G.jsx)(Pu,{className:`w-3.5 h-3.5`}),d(`common.delete`)]})]})]})]})})]}),_&&p&&(0,G.jsx)(`div`,{children:e.children.map(e=>(0,G.jsx)(z1e,{folder:e,selectedFolderId:t,onSelect:n,onDelete:r,onLink:i,onRename:a,depth:o+1,wrapNames:s,defaultExpanded:c,showModified:l,hasPermission:u,t:d},e.id))})]})}function B1e({file:e,isSelected:t,onSelect:n,onDelete:r,onDownload:i,onPrint:a,onSlice:o,onOpenInSlicer:s,onRunPipeline:c,useSlicerApi:l,desktopSlicer:u,canSlice:d,onPreview:p,onRename:m,onDetails:h,onGenerateThumbnail:g,onTagClick:_,thumbnailVersion:v,hasPermission:y,canModify:b,authEnabled:x,showModified:S,t:C}){let[w,T]=(0,f.useState)(null),E=y(`library:read`),D=b(`library`,`update`,e.created_by_id),O=b(`library`,`delete`,e.created_by_id),k=[];if(a&&w5(e)&&k.push({label:C(`common.print`),icon:(0,G.jsx)(Fl,{className:`w-4 h-4 text-bambu-green`}),onClick:()=>a(e),disabled:!y(`queue:create`),title:y(`queue:create`)?void 0:C(`fileManager.noPermissionAddToQueue`)}),T5(e,!!l,u)&&(l?o:s)&&k.push({label:C(`slice.action`),icon:l?(0,G.jsx)(Ms,{className:`w-4 h-4`}):(0,G.jsx)(Qs,{className:`w-4 h-4`}),onClick:()=>{l?o?.(e):s?.(e)},disabled:!d,title:d?void 0:C(l?`fileManager.noPermissionSlice`:`fileManager.noPermissionDownload`)}),c&&l&&T5(e,!0,u)&&k.push({label:C(`library.runWithPipeline.actionLabel`),icon:(0,G.jsx)(Al,{className:`w-4 h-4`}),onClick:()=>c(e),disabled:!y(`pipelines:run`),title:y(`pipelines:run`)?void 0:C(`library.runWithPipeline.noPermission`)}),p&&$7(e)){let t=t9(e);k.push({label:C(t?`fileManager.preview3d`:`fileManager.preview.open`),icon:t?(0,G.jsx)(Wo,{className:`w-4 h-4`}):A1e(e.file_type),onClick:()=>p(e),disabled:!E,title:E?void 0:C(`fileManager.noPermissionPreview`)})}return k.push({label:C(`common.download`),icon:(0,G.jsx)(Gs,{className:`w-4 h-4`}),onClick:()=>i(e.id),disabled:!y(`library:read`),title:y(`library:read`)?void 0:C(`fileManager.noPermissionDownload`)}),m&&k.push({label:C(`common.rename`),icon:(0,G.jsx)(Dl,{className:`w-4 h-4`}),onClick:()=>m(e),disabled:!D,title:D?void 0:C(`fileManager.noPermissionRenameFile`)}),h&&k.push({label:C(`fileManager.details.title`),icon:(0,G.jsx)(Bc,{className:`w-4 h-4`}),onClick:()=>h(e),disabled:!E,title:E?void 0:C(`fileManager.noPermissionPreview`)}),e.external_url&&k.push({label:C(`fileManager.details.openLink`),icon:(0,G.jsx)(Tc,{className:`w-4 h-4`}),onClick:()=>window.open(e.external_url,`_blank`,`noopener,noreferrer`)}),g&&j1e(e.file_type)&&k.push({label:C(`fileManager.generateThumbnail`),icon:(0,G.jsx)(Rc,{className:`w-4 h-4`}),onClick:()=>g(e),disabled:!D,title:D?void 0:C(`fileManager.noPermissionGenerateThumbnail`)}),k.push({label:C(`common.delete`),icon:(0,G.jsx)(Pu,{className:`w-4 h-4`}),onClick:()=>r(e.id),danger:!0,disabled:!O,title:O?void 0:C(`fileManager.noPermissionDeleteFile`)}),(0,G.jsxs)(`div`,{className:`group relative bg-bambu-dark-secondary rounded-lg border transition-all cursor-pointer ${t?`border-bambu-green ring-1 ring-bambu-green`:`border-bambu-dark-tertiary hover:border-bambu-green/50`}`,onClick:()=>n(e.id),onDoubleClick:()=>p?.(e),children:[(0,G.jsxs)(`div`,{className:`aspect-square bg-bambu-dark flex items-center justify-center overflow-hidden rounded-t-lg`,children:[e.thumbnail_path?(0,G.jsx)(`img`,{src:`${Z.getLibraryFileThumbnailUrl(e.id)}${v?(Z.getLibraryFileThumbnailUrl(e.id).includes(`?`)?`&`:`?`)+`v=${v}`:``}`,alt:e.filename,className:`w-full h-full object-cover`}):e.file_type===`pdf`?(0,G.jsx)(sc,{className:`w-12 h-12 text-bambu-gray/30`}):Z7(e.file_type)?(0,G.jsx)(oc,{className:`w-12 h-12 text-bambu-gray/30`}):O1e(e.file_type)?(0,G.jsx)(Rc,{className:`w-12 h-12 text-bambu-gray/30`}):(0,G.jsx)(nc,{className:`w-12 h-12 text-bambu-gray/30`}),(0,G.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`:Q7(e.file_type)?`bg-amber-500/90 text-white`:e.file_type===`pdf`?`bg-red-500/90 text-white`:Z7(e.file_type)?`bg-teal-500/90 text-white`:`bg-bambu-gray/90 text-white`}`,children:e.file_type.toUpperCase()})]}),(0,G.jsxs)(`div`,{className:`p-3`,children:[(0,G.jsx)(`h3`,{className:`text-sm font-medium text-white truncate`,title:e.print_name||e.filename,children:e.print_name||e.filename}),(0,G.jsxs)(`div`,{className:`flex items-center gap-3 mt-1 text-xs text-bambu-gray`,children:[(0,G.jsx)(`span`,{children:Yd(e.file_size)}),e.print_time_seconds&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(Ts,{className:`w-3 h-3`}),pp(e.print_time_seconds)]})]}),e.sliced_for_model&&(0,G.jsxs)(`div`,{className:`mt-1 text-xs text-bambu-gray flex items-center gap-1`,children:[(0,G.jsx)(Fl,{className:`w-3 h-3`}),e.sliced_for_model]}),(e.variant_count??0)>1&&(0,G.jsxs)(`div`,{className:`mt-1 text-xs text-bambu-green flex items-center gap-1`,children:[(0,G.jsx)(Wc,{className:`w-3 h-3`}),C(`fileManager.variants.badge`,{count:e.variant_count})]}),e.print_count>0&&(0,G.jsx)(`div`,{className:`mt-1 text-xs text-bambu-green`,children:C(`fileManager.printedCount`,{count:e.print_count})}),(e.external_url||e.has_notes||(e.photo_count??0)>0)&&(0,G.jsxs)(`div`,{className:`mt-1 flex items-center gap-2 text-xs text-bambu-gray`,...e9,children:[e.external_url&&(0,G.jsx)(`a`,{href:e.external_url,target:`_blank`,rel:`noopener noreferrer`,className:`p-0.5 rounded hover:text-bambu-green`,title:C(`fileManager.details.openLink`),"aria-label":C(`fileManager.details.openLink`),children:(0,G.jsx)(Tc,{className:`w-3.5 h-3.5`})}),e.has_notes&&(0,G.jsx)(`button`,{type:`button`,onClick:()=>h?.(e),className:`p-0.5 rounded hover:text-bambu-green`,title:C(`fileManager.details.hasNotes`),"aria-label":C(`fileManager.details.hasNotes`),children:(0,G.jsx)(bu,{className:`w-3.5 h-3.5`})}),(e.photo_count??0)>0&&(0,G.jsxs)(`button`,{type:`button`,onClick:()=>h?.(e),className:`flex items-center gap-0.5 p-0.5 rounded hover:text-bambu-green`,title:C(`fileManager.details.photoCount`,{count:e.photo_count}),"aria-label":C(`fileManager.details.photoCount`,{count:e.photo_count}),children:[(0,G.jsx)(es,{className:`w-3.5 h-3.5`}),(0,G.jsx)(`span`,{children:e.photo_count})]})]}),x&&e.created_by_username&&(0,G.jsxs)(`div`,{className:`mt-1 text-xs text-bambu-gray flex items-center gap-1`,children:[(0,G.jsx)(Hu,{className:`w-3 h-3`}),e.created_by_username]}),S&&(0,G.jsxs)(`div`,{className:`mt-1 text-xs text-bambu-gray flex items-center gap-1`,title:C(`fileManager.lastModified`),children:[(0,G.jsx)(Xo,{className:`w-3 h-3`}),cp(e.fs_modified_at??e.created_at)]}),(e.tags?.length??0)>0&&(0,G.jsx)(`div`,{className:`mt-2 flex flex-wrap gap-1`,...e9,children:e.tags.map(e=>(0,G.jsxs)(`button`,{type:`button`,onClick:()=>_?.(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,G.jsx)(wu,{className:`w-2.5 h-2.5 flex-shrink-0`}),(0,G.jsx)(`span`,{className:`truncate`,children:e.name})]},e.id))})]}),(0,G.jsxs)(`div`,{className:`absolute bottom-2 right-2 transition-opacity can-hover:opacity-0 group-hover:opacity-100 group-focus-within:opacity-100`,...e9,children:[(0,G.jsx)(`button`,{onClick:e=>{let t=e.currentTarget.getBoundingClientRect();T({x:t.left,y:t.bottom+4})},className:`p-1.5 rounded bg-bambu-dark-secondary/90 hover:bg-bambu-dark-tertiary`,children:(0,G.jsx)(Js,{className:`w-4 h-4 text-bambu-gray`})}),w&&(0,G.jsx)(JT,{x:w.x,y:w.y,items:k,onClose:()=>T(null)})]}),(0,G.jsx)(`div`,{className:`absolute top-2 left-2 w-5 h-5 rounded border-2 flex items-center justify-center transition-all ${t?`bg-bambu-green border-bambu-green`:`border-white/30 bg-black/30 can-hover:opacity-0 group-hover:opacity-100 group-focus-within:opacity-100`}`,children:t&&(0,G.jsx)(`div`,{className:`w-2 h-2 bg-white rounded-sm`})})]})}function V1e(){let{t:e}=U(),t=no(),{showToast:n}=Zd(),{hasPermission:r,hasAnyPermission:i,canModify:a,authEnabled:o}=Ld(),[s]=ji(),c=$n(),l=s.get(`folder`),[u,d]=(0,f.useState)(l?parseInt(l,10):null),[p,m]=(0,f.useState)(`internal`),[h,g]=(0,f.useState)([]),[_,v]=(0,f.useState)(!1),[y,b]=(0,f.useState)(!1),[x,S]=(0,f.useState)(!1),[C,w]=(0,f.useState)(!1),[T,E]=(0,f.useState)([]),[D,O]=(0,f.useState)(!1),[k,A]=(0,f.useState)(!1),[j,M]=(0,f.useState)(!1),[N,P]=(0,f.useState)([]),[F,I]=(0,f.useState)(null),[L,R]=(0,f.useState)(null),[z,B]=(0,f.useState)(null),[V,ee]=(0,f.useState)(null),[te,ne]=(0,f.useState)(!1),[re,ie]=(0,f.useState)(null),[ae,oe]=(0,f.useState)(null),[se,H]=(0,f.useState)(null),[ce,le]=(0,f.useState)({}),[ue,de]=(0,f.useState)(null),[fe,pe]=(0,f.useState)(null),[me,he]=(0,f.useState)(null),[ge,_e]=(0,f.useState)(null),[ve,ye]=(0,f.useState)(null),[be,xe]=(0,f.useState)(()=>localStorage.getItem(`library-view-mode`)||`grid`),[Se,Ce]=(0,f.useState)(()=>localStorage.getItem(`library-wrap-folders`)===`true`),[we,Te]=(0,f.useState)(()=>localStorage.getItem(`library-collapse-folders`)===`true`),[Ee,De]=(0,f.useState)(()=>localStorage.getItem(`library-folder-sort-field`)===`activity`?`activity`:`name`),[Oe,ke]=(0,f.useState)(()=>localStorage.getItem(`library-folder-sort-direction`)===`desc`?`desc`:`asc`),[Ae,je]=(0,f.useState)(()=>{let e=localStorage.getItem(`library-sidebar-width`);return e?parseInt(e,10):256}),[Me,Ne]=(0,f.useState)(!1),Pe=(0,f.useRef)(null);(0,f.useEffect)(()=>{if(!Me)return;document.body.style.userSelect=`none`,document.body.style.cursor=`col-resize`;let e=e=>{if(!Pe.current)return;let t=Pe.current.parentElement?.getBoundingClientRect();if(!t)return;let n=e.clientX-t.left;je(Math.min(500,Math.max(200,n)))},t=()=>{Ne(!1),document.body.style.userSelect=``,document.body.style.cursor=``,localStorage.setItem(`library-sidebar-width`,String(Ae))};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=``}},[Me,Ae]);let[Fe,Ie]=(0,f.useState)(``),[Le,Re]=(0,f.useState)(`all`),[ze,Be]=(0,f.useState)(``),[Ve,He]=(0,f.useState)(()=>localStorage.getItem(`library-sort-field`)||`name`),[Ue,We]=(0,f.useState)(()=>localStorage.getItem(`library-sort-direction`)||`asc`),[Ge,Ke]=(0,f.useState)(()=>localStorage.getItem(`library-show-modified`)===`true`);(0,f.useEffect)(()=>{let e=s.get(`folder`);e&&d(parseInt(e,10))},[s]);let{data:qe}=K({queryKey:[`settings`],queryFn:()=>Z.getSettings()}),Je=VW(qe?.open_in_slicer,qe?.preferred_slicer),Ye=(0,f.useCallback)(async t=>{try{let{token:e}=await Z.createLibrarySlicerToken(t.id),n=Z.getLibrarySlicerDownloadUrl(t.id,e,t.filename);GW(`${window.location.origin}${n}`,Je)}catch{n(e(`fileManager.toast.openInSlicerFailed`),`error`);let r=Z.getLibraryFileDownloadUrl(t.id);GW(`${window.location.origin}${r}`,Je)}},[Je,n,e]),Xe=(0,f.useCallback)(()=>qe?.use_slicer_api?r(`library:upload`):i(`library:read_all`,`library:read_own`),[qe?.use_slicer_api,r,i]),{data:Ze,isLoading:Qe}=K({queryKey:[`library-folders`],queryFn:()=>Z.getLibraryFolders()}),$e=(0,f.useMemo)(()=>{if(!Ze)return Ze;let e=t=>[...t].sort((e,t)=>{let n=0;if(Ee===`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 Oe===`asc`?n:-n}).map(t=>({...t,children:e(t.children)}));return e(Ze)},[Ze,Ee,Oe]),{data:et}=K({queryKey:[`library-trash-count`],queryFn:async()=>{try{return(await Z.listLibraryTrash(1,0)).total}catch{return 0}},staleTime:3e4}),tt=u!==null&&Fe.trim().length>0,nt=(0,f.useMemo)(()=>[...N].sort((e,t)=>e-t),[N]),{data:rt=[]}=K({queryKey:[`library-tags`],queryFn:Z.getLibraryTags}),it=(0,f.useMemo)(()=>{let e=new Map;for(let t of rt)e.set(t.id,t.name);return e},[rt]);(0,f.useEffect)(()=>{rt.length!==0&&P(e=>{let t=e.filter(e=>it.has(e));return t.length===e.length?e:t})},[rt.length,it]);let at=(0,f.useCallback)(e=>{P(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},[]),{data:ot,isLoading:st}=K({queryKey:[`library-files`,u,p,tt,nt],queryFn:()=>Z.getLibraryFiles(u,!1,void 0,u===null?p:void 0,tt,nt)}),{data:ct}=K({queryKey:[`library-stats`],queryFn:()=>Z.getLibraryStats()}),{data:lt}=K({queryKey:[`users`,`slim`],queryFn:()=>Z.getUsersSlim()}),ut=(0,f.useMemo)(()=>{if(!ot)return[];let e=new Set(ot.map(e=>e.file_type));return Array.from(e).sort()},[ot]),dt=(0,f.useMemo)(()=>{if(!ot)return[];let e=[...ot];if(Fe.trim()){let t=Fe.toLowerCase();e=e.filter(e=>e.filename.toLowerCase().includes(t)||e.print_name&&e.print_name.toLowerCase().includes(t))}if(Le!==`all`&&(e=e.filter(e=>e.file_type===Le)),ze.trim()){let t=ze.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(Ve){case`name`:n=(e.print_name||e.filename).localeCompare(t.print_name||t.filename);break;case`date`:n=(sp(e.fs_modified_at??e.created_at)?.getTime()??0)-(sp(t.fs_modified_at??t.created_at)?.getTime()??0);break;case`size`:n=e.file_size-t.file_size;break;case`type`:n=e.file_type.localeCompare(t.file_type);break;case`prints`:n=e.print_count-t.print_count;break}return Ue===`asc`?n:-n}),e},[ot,Fe,Le,ze,Ve,Ue]),ft=(0,f.useMemo)(()=>{if(!ct||!qe)return!1;let e=(qe.library_disk_warning_gb||5)*1024*1024*1024;return ct.disk_free_bytesZ.createLibraryFolder(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`library-folders`]}),v(!1),n(e(`fileManager.toast.folderCreated`),`success`)},onError:e=>n(e.message,`error`)}),mt=q({mutationFn:async e=>{let t=await Z.createExternalFolder(e);return await Z.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`)}),ht=q({mutationFn:e=>Z.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`)}),gt=q({mutationFn:e=>Z.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`)}}),_t=q({mutationFn:e=>Z.deleteLibraryFile(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`library-stats`]}),t.invalidateQueries({queryKey:[`library-trash-count`]}),g(e=>e.filter(e=>e!==L?.id)),R(null),n(e(`fileManager.toast.fileDeleted`),`success`)},onError:e=>{R(null),n(e.message,`error`)}}),vt=q({mutationFn:e=>Z.createVariantGroup(e.map(e=>({library_file_id:e}))),onSuccess:r=>{t.invalidateQueries({queryKey:[`library-files`]}),n(e(`fileManager.variants.grouped`,{count:r.members.length}),`success`),g([])},onError:e=>n(e.message,`error`)}),yt=q({mutationFn:e=>Z.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`),g([]),R(null)},onError:e=>{R(null),n(e.message,`error`)}}),bt=q({mutationFn:({fileIds:e,folderId:t})=>Z.moveLibraryFiles(e,t),onSuccess:()=>{t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`library-folders`]}),g([]),S(!1),n(e(`fileManager.toast.filesMoved`),`success`)},onError:e=>n(e.message,`error`)}),xt=q({mutationFn:({id:e,data:t})=>Z.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`)}),St=q({mutationFn:({id:e,filename:t})=>Z.updateLibraryFile(e,{filename:t}),onSuccess:()=>{t.invalidateQueries({queryKey:[`library-files`]}),H(null),n(e(`fileManager.toast.fileRenamed`),`success`)},onError:e=>{H(null),n(e.message,`error`)}}),Ct=q({mutationFn:({id:e,name:t})=>Z.updateLibraryFolder(e,{name:t}),onSuccess:()=>{t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`library-files`]}),H(null),n(e(`fileManager.toast.folderRenamed`),`success`)},onError:e=>{H(null),n(e.message,`error`)}}),wt=q({mutationFn:()=>Z.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)}),le(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`)}),Tt=q({mutationFn:e=>Z.batchGenerateStlThumbnails({file_ids:[e]}),onSuccess:r=>{if(t.invalidateQueries({queryKey:[`library-files`]}),r.succeeded>0){let t=r.results[0]?.file_id;t&&le(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`)}),Et=(0,f.useCallback)(e=>{r(`library:read`)&&(w5(e)?c(`/gcode-viewer?library_file=${e.id}`):e.file_type===`3mf`||e.file_type===`stl`||Q7(e.file_type)?de(e):e.file_type===`pdf`?pe(e):Z7(e.file_type)?he(e):k1e(e.file_type)&&ye(e))},[r,c]),Dt=(0,f.useMemo)(()=>{if(!ot||h.length!==1)return null;let e=ot.find(e=>e.id===h[0]);return e&&$7(e)?e:null},[ot,h]),Ot=(0,f.useMemo)(()=>ot?ot.filter(e=>h.includes(e.id)&&w5(e)):[],[ot,h]),kt=(0,f.useMemo)(()=>{if(!ot)return[];let e=ot.filter(e=>h.includes(e.id)&&e.filename.toLowerCase().endsWith(`.stl`));return e.length===h.length?e:[]},[ot,h]),{data:At}=K({queryKey:[`variant-group`,z?.variant_group_id],queryFn:()=>Z.getVariantGroup(z.variant_group_id),enabled:!!z?.variant_group_id}),jt=(0,f.useMemo)(()=>{if(z){if(Ot.length>1)return Ot.map(e=>({id:e.id,filename:e.filename,sliced_for_model:e.sliced_for_model}));if(At&&At.members.length>1)return At.members.map(e=>({id:e.library_file_id,filename:e.filename,sliced_for_model:e.target_model}))}},[z,Ot,At]),Mt=(0,f.useCallback)(e=>{g(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},[]),Nt=(0,f.useCallback)(()=>{dt.length>0&&g(dt.map(e=>e.id))},[dt]),Pt=(0,f.useCallback)(()=>{g([])},[]),Ft=()=>{t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`library-stats`]})},{isDraggingOver:It,dragHandlers:Lt}=KW({disabled:!r(`library:upload`)||C,onFiles:e=>{E(e),w(!0)}}),Rt=(0,f.useCallback)(e=>{if(!e.thumbnail_path&&a(`library`,`update`,e.created_by_id))return n=>{Z.uploadLibraryPreviewThumbnail(e.id,n).then(n=>{n.updated&&(le(t=>({...t,[e.id]:(t[e.id]||0)+1})),t.invalidateQueries({queryKey:[`library-files`]}))}).catch(()=>{})}},[a,t]),zt=e=>{Z.downloadLibraryFile(e).catch(e=>{console.error(`Library file download failed:`,e)})},Bt=()=>{L&&(L.type===`file`?_t.mutate(L.id):L.type===`folder`?gt.mutate(L.id):L.type===`bulk`&&yt.mutate(h))},Vt=gt.isPending||_t.isPending||yt.isPending,Ht=e=>{xe(e),localStorage.setItem(`library-view-mode`,e)},Ut=Qe||st,Wt=(0,f.useMemo)(()=>{if(!u||!Ze)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(Ze)},[u,Ze]);return(0,G.jsxs)(`div`,{className:`p-4 md:p-8 min-h-[calc(100vh-64px)] lg:h-screen flex flex-col relative`,...Lt,children:[It&&(0,G.jsx)(`div`,{className:`fixed inset-0 z-50 bg-bambu-dark/90 flex items-center justify-center pointer-events-none`,children:(0,G.jsxs)(`div`,{className:`border-4 border-dashed border-bambu-green rounded-xl p-12 text-center`,children:[(0,G.jsx)(Vu,{className:`w-16 h-16 mx-auto mb-4 text-bambu-green`}),(0,G.jsx)(`p`,{className:`text-2xl font-semibold text-white mb-2`,children:e(`fileManager.dropFilesHere`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray`,children:e(`fileManager.releaseToUpload`)})]})}),(0,G.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between gap-4 mb-6`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,G.jsx)(pc,{className:`w-7 h-7 text-bambu-green`}),e(`fileManager.title`)]}),(0,G.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:e(`fileManager.subtitle`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center bg-bambu-dark rounded-lg p-1`,children:[(0,G.jsx)(`button`,{onClick:()=>Ht(`grid`),className:`p-1.5 rounded transition-colors ${be===`grid`?`bg-bambu-dark-secondary text-white`:`text-bambu-gray hover:text-white`}`,title:e(`fileManager.gridView`),children:(0,G.jsx)(Gc,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:()=>Ht(`list`),className:`p-1.5 rounded transition-colors ${be===`list`?`bg-bambu-dark-secondary text-white`:`text-bambu-gray hover:text-white`}`,title:e(`fileManager.listView`),children:(0,G.jsx)(Xc,{className:`w-4 h-4`})})]}),(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>wt.mutate(),disabled:wt.isPending||!i(`library:update_own`,`library:update_all`),title:i(`library:update_own`,`library:update_all`)?e(`fileManager.generateThumbnailsForMissing`):e(`fileManager.noPermissionGenerateThumbnail`),children:[wt.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 mr-2 animate-spin`}):(0,G.jsx)(Rc,{className:`w-4 h-4 mr-2`}),e(`fileManager.generateThumbnails`)]}),(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>b(!0),disabled:!r(`library:upload`),title:r(`library:upload`)?e(`fileManager.linkExternalFolder`):e(`fileManager.noPermissionCreateFolder`),children:[(0,G.jsx)(hc,{className:`w-4 h-4 mr-2`}),e(`fileManager.linkExternal`)]}),(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>v(!0),disabled:!r(`library:upload`),title:r(`library:upload`)?void 0:e(`fileManager.noPermissionCreateFolder`),children:[(0,G.jsx)(mc,{className:`w-4 h-4 mr-2`}),e(`fileManager.newFolder`)]}),(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>A(!0),title:e(`fileManager.tags.manageTitle`),children:[(0,G.jsx)(wu,{className:`w-4 h-4 mr-2`}),e(`fileManager.tags.manage`)]}),r(`library:purge`)&&(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>O(!0),title:e(`libraryPurge.headerTooltip`),children:[(0,G.jsx)(Pu,{className:`w-4 h-4 mr-2`}),e(`libraryPurge.headerButton`)]}),i(`library:delete_own`,`library:delete_all`)&&(0,G.jsxs)(Ci,{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,G.jsx)(Pu,{className:`w-4 h-4 mr-2`}),e(`libraryTrash.headerButton`),typeof et==`number`&&et>0&&(0,G.jsx)(`span`,{className:`ml-1.5 px-1.5 py-0.5 text-xs rounded-full bg-bambu-green/20 text-bambu-green`,children:et})]}),(0,G.jsxs)(Q,{onClick:()=>w(!0),disabled:!r(`library:upload`),title:r(`library:upload`)?void 0:e(`fileManager.noPermissionUpload`),children:[(0,G.jsx)(Vu,{className:`w-4 h-4 mr-2`}),e(`common.upload`)]})]})]}),ft&&ct&&qe&&(0,G.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,G.jsx)(Lu,{className:`w-5 h-5 text-amber-500 flex-shrink-0`}),(0,G.jsxs)(`div`,{className:`flex-1`,children:[(0,G.jsx)(`p`,{className:`text-sm text-amber-500 font-medium`,children:e(`fileManager.lowDiskSpaceWarning`)}),(0,G.jsx)(`p`,{className:`text-xs text-amber-500/80`,children:e(`fileManager.lowDiskSpaceDetails`,{free:Yd(ct.disk_free_bytes),total:Yd(ct.disk_total_bytes),threshold:qe.library_disk_warning_gb})})]})]}),ct&&(0,G.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,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,G.jsx)(cc,{className:`w-4 h-4 text-bambu-green`}),(0,G.jsxs)(`span`,{className:`text-bambu-gray`,children:[e(`fileManager.files`),`:`]}),(0,G.jsx)(`span`,{className:`text-white font-medium`,children:ct.total_files})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,G.jsx)(pc,{className:`w-4 h-4 text-blue-600 dark:text-blue-400`}),(0,G.jsxs)(`span`,{className:`text-bambu-gray`,children:[e(`fileManager.folders`),`:`]}),(0,G.jsx)(`span`,{className:`text-white font-medium`,children:ct.total_folders})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,G.jsx)(kc,{className:`w-4 h-4 text-amber-600 dark:text-amber-400`}),(0,G.jsxs)(`span`,{className:`text-bambu-gray`,children:[e(`fileManager.size`),`:`]}),(0,G.jsx)(`span`,{className:`text-white font-medium`,children:Yd(ct.total_size_bytes)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm sm:ml-auto`,children:[(0,G.jsxs)(`span`,{className:`text-bambu-gray`,children:[e(`fileManager.free`),`:`]}),(0,G.jsx)(`span`,{className:`font-medium ${ft?`text-amber-500`:`text-white`}`,children:Yd(ct.disk_free_bytes)})]})]}),(0,G.jsxs)(`div`,{className:`flex-1 flex flex-col lg:flex-row gap-4 lg:gap-6 min-h-0`,children:[(0,G.jsx)(`div`,{className:`lg:hidden`,children:(0,G.jsxs)(`select`,{value:u===null?`__top:${p}`:String(u),onChange:e=>{let t=e.target.value;t.startsWith(`__top:`)?(d(null),m(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,G.jsxs)(`option`,{value:`__top:internal`,children:[`📁 `,e(`fileManager.allFiles`)]}),Ze?.some(e=>e.is_external)&&(0,G.jsxs)(`option`,{value:`__top:external`,children:[`🔗 `,e(`fileManager.allExternal`)]}),$e&&(()=>{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($e).map(e=>(0,G.jsxs)(`option`,{value:e.id,children:[`│ `.repeat(e.depth),`📂 `,e.name,` `,e.fileCount>0?`(${e.fileCount})`:``]},e.id))})()]})}),(0,G.jsxs)(`div`,{ref:Pe,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:`${Ae}px`},children:[(0,G.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 ${Me?`bg-bambu-green`:`hover:bg-bambu-green/50`}`,onMouseDown:e=>{e.preventDefault(),Ne(!0)},onDoubleClick:()=>{je(256),localStorage.setItem(`library-sidebar-width`,`256`)},title:e(`fileManager.dragToResizeTooltip`),children:(0,G.jsxs)(`div`,{className:`flex flex-col gap-1 opacity-0 group-hover/resize:opacity-100 transition-opacity ${Me?`opacity-100`:``}`,children:[(0,G.jsx)(`div`,{className:`w-0.5 h-0.5 rounded-full bg-white/70`}),(0,G.jsx)(`div`,{className:`w-0.5 h-0.5 rounded-full bg-white/70`}),(0,G.jsx)(`div`,{className:`w-0.5 h-0.5 rounded-full bg-white/70`})]})}),(0,G.jsxs)(`div`,{className:`p-3 border-b border-bambu-dark-tertiary flex items-center justify-between`,children:[(0,G.jsx)(`h2`,{className:`text-sm font-medium text-white`,children:e(`fileManager.folders`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,G.jsxs)(`select`,{value:Ee,onChange:e=>{let t=e.target.value===`activity`?`activity`:`name`;De(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,G.jsx)(`option`,{value:`name`,children:e(`fileManager.folderSortByName`)}),(0,G.jsx)(`option`,{value:`activity`,children:e(`fileManager.folderSortByActivity`)})]}),(0,G.jsx)(`button`,{onClick:()=>{let e=Oe===`asc`?`desc`:`asc`;ke(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(Oe===`asc`?`fileManager.ascending`:`fileManager.descending`),"aria-label":e(Oe===`asc`?`fileManager.ascending`:`fileManager.descending`),children:Oe===`asc`?(0,G.jsx)(Fo,{className:`w-3.5 h-3.5`}):(0,G.jsx)(ko,{className:`w-3.5 h-3.5`})}),(0,G.jsx)(`button`,{onClick:()=>{let e=!we;Te(e),localStorage.setItem(`library-collapse-folders`,String(e))},className:`text-xs px-1.5 py-0.5 rounded transition-colors ${we?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:text-white hover:bg-bambu-dark`}`,title:e(we?`fileManager.expandFoldersByDefault`:`fileManager.collapseFoldersByDefault`),children:e(`fileManager.collapse`)}),(0,G.jsx)(`button`,{onClick:()=>{let e=!Se;Ce(e),localStorage.setItem(`library-wrap-folders`,String(e))},className:`text-xs px-1.5 py-0.5 rounded transition-colors ${Se?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:text-white hover:bg-bambu-dark`}`,title:e(Se?`fileManager.disableTextWrapping`:`fileManager.enableTextWrapping`),children:e(`fileManager.wrap`)})]})]}),(0,G.jsxs)(`div`,{className:`flex-1 overflow-y-auto p-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-1.5 rounded cursor-pointer transition-colors ${u===null&&p===`internal`?`bg-bambu-green/20 text-bambu-green`:`hover:bg-bambu-dark text-white`}`,onClick:()=>{d(null),m(`internal`)},children:[(0,G.jsx)(nc,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`text-sm`,children:e(`fileManager.allFiles`)})]}),Ze?.some(e=>e.is_external)&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-1.5 rounded cursor-pointer transition-colors ${u===null&&p===`external`?`bg-bambu-green/20 text-bambu-green`:`hover:bg-bambu-dark text-white`}`,onClick:()=>{d(null),m(`external`)},children:[(0,G.jsx)(hc,{className:`w-4 h-4 text-purple-600 dark:text-purple-400`}),(0,G.jsx)(`span`,{className:`text-sm`,children:e(`fileManager.allExternal`)})]}),$e?.map(t=>(0,G.jsx)(z1e,{folder:t,selectedFolderId:u,onSelect:d,onDelete:e=>R({type:`folder`,id:e}),onLink:I,onRename:e=>H({type:`folder`,id:e.id,name:e.name}),wrapNames:Se,defaultExpanded:!we,showModified:Ge,hasPermission:r,t:e},`${t.id}-${we?`c`:`e`}`))]})]}),(0,G.jsxs)(`div`,{className:`flex-1 flex flex-col lg:flex-row min-w-0 min-h-0 gap-4 lg:gap-6`,children:[(0,G.jsxs)(`div`,{className:`flex-1 flex flex-col min-w-0 min-h-0`,children:[rt.length>0&&(0,G.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,G.jsx)(`span`,{className:`text-xs text-bambu-gray font-medium shrink-0`,children:e(`fileManager.tags.filterLabel`)}),rt.map(e=>{let t=N.includes(e.id);return(0,G.jsxs)(`button`,{type:`button`,onClick:()=>at(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,G.jsx)(wu,{className:`w-3 h-3`}),(0,G.jsx)(`span`,{children:e.name}),t&&(0,G.jsx)(nd,{className:`w-3 h-3`})]},e.id)}),N.length>0&&(0,G.jsx)(`button`,{type:`button`,onClick:()=>P([]),className:`ml-auto text-xs text-bambu-gray hover:text-white shrink-0`,children:e(`fileManager.tags.clearAll`)})]}),Wt?.is_external&&(0,G.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,G.jsx)(hc,{className:`w-5 h-5 text-purple-600 dark:text-purple-400 flex-shrink-0`}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-sm font-medium text-purple-700 dark:text-purple-300`,children:e(`fileManager.externalFolder`)}),Wt.external_readonly&&(0,G.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,G.jsx)(Qc,{className:`w-3 h-3`}),e(`fileManager.readOnly`)]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray truncate font-mono`,title:Wt.external_path||``,children:Wt.external_path})]}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:()=>u&&ht.mutate(u),disabled:ht.isPending,title:e(`fileManager.scanFolder`),children:[ht.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(zl,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`ml-1.5`,children:e(`fileManager.scanFolder`)})]})]}),ot&&ot.length>0&&(0,G.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,G.jsxs)(`div`,{className:`relative w-full sm:w-auto sm:flex-1 sm:max-w-xs`,children:[(0,G.jsx)(Yl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,G.jsx)(`input`,{type:`text`,placeholder:e(`fileManager.searchFiles`),value:Fe,onChange:e=>Ie(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`}),tt&&(0,G.jsx)(`span`,{className:`absolute -bottom-4 left-0 text-[10px] text-bambu-gray whitespace-nowrap`,title:e(`fileManager.searchSubfoldersHint`),children:e(`fileManager.searchSubfoldersHint`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(yc,{className:`w-4 h-4 text-bambu-gray hidden sm:block`}),(0,G.jsxs)(`select`,{value:Le,onChange:e=>Re(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,G.jsx)(`option`,{value:`all`,children:e(`fileManager.allTypes`)}),ut.map(e=>(0,G.jsx)(`option`,{value:e,children:e.toUpperCase()},e))]})]}),o&&(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(`input`,{type:`text`,placeholder:e(`fileManager.filterByUser`,{defaultValue:`Filter by user`}),value:ze,onChange:e=>Be(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 ${ze?`pr-7`:``}`,style:ze?{WebkitAppearance:`none`,MozAppearance:`textfield`}:void 0}),ze&&(0,G.jsx)(`button`,{onClick:()=>Be(``),className:`absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white z-10`,children:(0,G.jsx)(nd,{className:`w-3 h-3`})}),(0,G.jsx)(`datalist`,{id:`usernames-list`,children:lt?.map(e=>(0,G.jsx)(`option`,{value:e.username},e.id))})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`select`,{value:Ve,onChange:e=>{let t=e.target.value;He(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,G.jsx)(`option`,{value:`name`,children:e(`common.name`)}),(0,G.jsx)(`option`,{value:`date`,children:e(`common.date`)}),(0,G.jsx)(`option`,{value:`size`,children:e(`fileManager.size`)}),(0,G.jsx)(`option`,{value:`type`,children:e(`common.type`)}),(0,G.jsx)(`option`,{value:`prints`,children:e(`fileManager.prints`)})]}),(0,G.jsx)(`button`,{onClick:()=>We(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(Ue===`asc`?`fileManager.ascending`:`fileManager.descending`),children:Ue===`asc`?(0,G.jsx)(Fo,{className:`w-4 h-4 text-white`}):(0,G.jsx)(ko,{className:`w-4 h-4 text-white`})}),(0,G.jsx)(`button`,{onClick:()=>Ke(e=>{let t=!e;return localStorage.setItem(`library-show-modified`,String(t)),t}),className:`p-1.5 rounded bg-bambu-dark border transition-colors ${Ge?`border-bambu-green text-bambu-green`:`border-bambu-dark-tertiary text-white hover:border-bambu-green`}`,title:e(Ge?`fileManager.hideModified`:`fileManager.showModified`),"aria-pressed":Ge,children:(0,G.jsx)(Xo,{className:`w-4 h-4`})})]}),(Fe||Le!==`all`||ze)&&(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray hidden sm:inline`,children:e(`fileManager.resultsCount`,{showing:dt.length,total:ot.length})})]}),dt.length>0&&(0,G.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:[h.length===dt.length&&h.length>0?(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:Pt,children:[(0,G.jsx)(_u,{className:`w-4 h-4 sm:mr-1`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`fileManager.deselectAll`)})]}):(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:Nt,children:[(0,G.jsx)(hu,{className:`w-4 h-4 sm:mr-1`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`fileManager.selectAll`)})]}),h.length>0&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray ml-2`,children:e(`fileManager.selected`,{count:h.length})}),(0,G.jsx)(`div`,{className:`hidden sm:block flex-1`}),(0,G.jsxs)(`div`,{className:`w-full sm:w-auto flex flex-wrap items-center gap-2 mt-2 sm:mt-0`,children:[Dt&&(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:()=>Et(Dt),disabled:!r(`library:read`),title:r(`library:read`)?void 0:e(`fileManager.noPermissionPreview`),children:[(0,G.jsx)(ec,{className:`w-4 h-4 sm:mr-1`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`fileManager.preview.open`)})]}),Ot.length>=1&&(0,G.jsxs)(Q,{variant:`primary`,size:`sm`,onClick:()=>B(Ot[0]),disabled:!r(`queue:create`),title:r(`queue:create`)?void 0:e(`fileManager.noPermissionAddToQueue`),children:[(0,G.jsx)(Fl,{className:`w-4 h-4 sm:mr-1`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:Ot.length>1?e(`fileManager.variants.printAlternatives`,{count:Ot.length}):e(`common.print`)})]}),Ot.length>=2&&!Ot.some(e=>e.variant_group_id)&&(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:()=>vt.mutate(Ot.map(e=>e.id)),disabled:vt.isPending||!i(`library:update_own`,`library:update_all`),title:e(`fileManager.variants.groupTooltip`),children:[(0,G.jsx)(Wc,{className:`w-4 h-4 sm:mr-1`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`fileManager.variants.groupAction`)})]}),kt.length>=1&&(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:()=>ne(!0),disabled:!r(`library:upload`),title:e(`fileManager.combine.tooltip`),children:[(0,G.jsx)(Ps,{className:`w-4 h-4 sm:mr-1`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`fileManager.combine.action`)})]}),(0,G.jsxs)(Q,{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,G.jsx)(hl,{className:`w-4 h-4 sm:mr-1`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.move`)})]}),(0,G.jsxs)(Q,{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,G.jsx)(wu,{className:`w-4 h-4 sm:mr-1`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`fileManager.tags.tagAction`)})]}),(0,G.jsxs)(Q,{variant:`danger`,size:`sm`,onClick:()=>{h.length===1?R({type:`file`,id:h[0]}):R({type:`bulk`,id:0,count:h.length})},disabled:!i(`library:delete_own`,`library:delete_all`),title:i(`library:delete_own`,`library:delete_all`)?void 0:e(`fileManager.noPermissionDeleteFiles`),children:[(0,G.jsx)(Pu,{className:`w-4 h-4 sm:mr-1`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.delete`)})]}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:Pt,children:[(0,G.jsx)(nd,{className:`w-4 h-4 sm:mr-1`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.clear`)})]})]})]})]}),Ut?(0,G.jsx)(`div`,{className:`flex-1 flex items-center justify-center`,children:(0,G.jsxs)(`div`,{className:`flex flex-col items-center gap-3`,children:[(0,G.jsx)(Y,{className:`w-8 h-8 animate-spin text-bambu-green`}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`fileManager.loadingFiles`)})]})}):ot?.length===0?(0,G.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center`,children:[(0,G.jsx)(`div`,{className:`p-4 bg-bambu-dark rounded-2xl mb-4`,children:(0,G.jsx)(nc,{className:`w-12 h-12 text-bambu-gray/50`})}),(0,G.jsx)(`h3`,{className:`text-lg font-medium text-white mb-2`,children:e(u===null?p===`external`?`fileManager.externalIsEmpty`:`fileManager.noFilesYet`:`fileManager.folderIsEmpty`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-center max-w-md mb-6`,children:e(u===null?p===`external`?`fileManager.externalEmptyDescription`:`fileManager.noFilesDescription`:`fileManager.folderEmptyDescription`)}),(0,G.jsxs)(Q,{onClick:()=>w(!0),disabled:!r(`library:upload`),title:r(`library:upload`)?void 0:e(`fileManager.noPermissionUpload`),children:[(0,G.jsx)(Ml,{className:`w-4 h-4 mr-2`}),e(`fileManager.uploadFiles`)]})]}):dt.length===0?(0,G.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center`,children:[(0,G.jsx)(`div`,{className:`p-4 bg-bambu-dark rounded-2xl mb-4`,children:(0,G.jsx)(Yl,{className:`w-12 h-12 text-bambu-gray/50`})}),(0,G.jsx)(`h3`,{className:`text-lg font-medium text-white mb-2`,children:e(`fileManager.noMatchingFiles`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-center max-w-md mb-6`,children:e(`fileManager.noMatchingFilesDescription`)}),(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>{Ie(``),Re(`all`)},children:e(`fileManager.clearFilters`)})]}):be===`grid`?(0,G.jsx)(`div`,{className:`flex-1 lg:overflow-y-auto`,children:(0,G.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:dt.map(t=>(0,G.jsx)(B1e,{file:t,isSelected:h.includes(t.id),t:e,onSelect:Mt,onDelete:e=>R({type:`file`,id:e}),onDownload:zt,onPrint:B,onSlice:ee,onOpenInSlicer:Ye,desktopSlicer:Je,onRunPipeline:oe,useSlicerApi:qe?.use_slicer_api??!1,canSlice:Xe(),onPreview:Et,onRename:e=>H({type:`file`,id:e.id,name:e.filename}),onDetails:_e,onGenerateThumbnail:e=>Tt.mutate(e.id),onTagClick:at,thumbnailVersion:ce[t.id],hasPermission:r,canModify:a,authEnabled:o,showModified:Ge},t.id))})}):(0,G.jsx)(`div`,{className:`flex-1 lg:overflow-y-auto`,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary overflow-x-auto`,children:[(0,G.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,G.jsx)(`div`,{className:`w-6`}),(0,G.jsx)(`div`,{children:e(`common.name`)}),o&&(0,G.jsx)(`div`,{children:e(`fileManager.uploadedBy`,{defaultValue:`Uploaded By`})}),(0,G.jsx)(`div`,{children:e(`common.type`)}),(0,G.jsx)(`div`,{children:e(`fileManager.size`)}),(0,G.jsx)(`div`,{children:e(`fileManager.prints`)}),(0,G.jsx)(`div`,{children:e(`fileManager.tags.title`)}),(0,G.jsx)(`div`,{})]}),dt.map(t=>(0,G.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 ${h.includes(t.id)?`bg-bambu-green/10`:``}`,onClick:()=>Mt(t.id),onDoubleClick:()=>Et(t),children:[(0,G.jsx)(`div`,{className:`w-5 h-5 rounded border-2 flex items-center justify-center ${h.includes(t.id)?`bg-bambu-green border-bambu-green`:`border-bambu-gray/50`}`,children:h.includes(t.id)&&(0,G.jsx)(`div`,{className:`w-2 h-2 bg-white rounded-sm`})}),(0,G.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0`,children:[(0,G.jsxs)(`div`,{className:`relative group/thumb`,children:[(0,G.jsx)(`div`,{className:`w-10 h-10 rounded bg-bambu-dark flex-shrink-0 overflow-hidden`,children:t.thumbnail_path?(0,G.jsx)(`img`,{src:`${Z.getLibraryFileThumbnailUrl(t.id)}${ce[t.id]?(Z.getLibraryFileThumbnailUrl(t.id).includes(`?`)?`&`:`?`)+`v=${ce[t.id]}`:``}`,alt:``,className:`w-full h-full object-cover`}):(0,G.jsx)(`div`,{className:`w-full h-full flex items-center justify-center`,children:t.file_type===`pdf`?(0,G.jsx)(sc,{className:`w-5 h-5 text-bambu-gray/50`}):Z7(t.file_type)?(0,G.jsx)(oc,{className:`w-5 h-5 text-bambu-gray/50`}):O1e(t.file_type)?(0,G.jsx)(Rc,{className:`w-5 h-5 text-bambu-gray/50`}):(0,G.jsx)(nc,{className:`w-5 h-5 text-bambu-gray/50`})})}),t.thumbnail_path&&(0,G.jsx)(`div`,{className:`absolute left-0 top-full mt-2 z-50 hidden group-hover/thumb:block`,children:(0,G.jsx)(`div`,{className:`w-48 h-48 rounded-lg bg-bambu-dark-secondary border border-bambu-dark-tertiary shadow-xl overflow-hidden`,children:(0,G.jsx)(`img`,{src:`${Z.getLibraryFileThumbnailUrl(t.id)}${ce[t.id]?(Z.getLibraryFileThumbnailUrl(t.id).includes(`?`)?`&`:`?`)+`v=${ce[t.id]}`:``}`,alt:t.filename,className:`w-full h-full object-contain`})})})]}),(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[(0,G.jsx)(`span`,{className:`text-sm text-white truncate`,children:t.print_name||t.filename}),t.external_url&&(0,G.jsx)(`a`,{href:t.external_url,target:`_blank`,rel:`noopener noreferrer`,...e9,className:`flex-shrink-0 text-bambu-gray hover:text-bambu-green`,title:e(`fileManager.details.openLink`),"aria-label":e(`fileManager.details.openLink`),children:(0,G.jsx)(Tc,{className:`w-3.5 h-3.5`})}),t.has_notes&&(0,G.jsx)(`span`,{className:`flex-shrink-0 text-bambu-gray`,title:e(`fileManager.details.hasNotes`),"aria-label":e(`fileManager.details.hasNotes`),children:(0,G.jsx)(bu,{className:`w-3.5 h-3.5`})}),(t.photo_count??0)>0&&(0,G.jsxs)(`span`,{className:`flex-shrink-0 flex items-center gap-0.5 text-xs text-bambu-gray`,title:e(`fileManager.details.photoCount`,{count:t.photo_count}),children:[(0,G.jsx)(es,{className:`w-3.5 h-3.5`}),t.photo_count]})]}),Ge&&(0,G.jsxs)(`div`,{className:`text-xs text-bambu-gray flex items-center gap-1 mt-0.5`,title:e(`fileManager.lastModified`),children:[(0,G.jsx)(Xo,{className:`w-3 h-3 flex-shrink-0`}),(0,G.jsx)(`span`,{className:`truncate`,children:cp(t.fs_modified_at??t.created_at)})]})]})]}),o&&(0,G.jsx)(`div`,{className:`text-sm text-bambu-gray flex items-center gap-1`,children:t.created_by_username?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Hu,{className:`w-3 h-3`}),(0,G.jsx)(`span`,{className:`truncate`,children:t.created_by_username})]}):`-`}),(0,G.jsx)(`div`,{children:(0,G.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`:Q7(t.file_type)?`bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-400`:t.file_type===`pdf`?`bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400`:Z7(t.file_type)?`bg-teal-100 dark:bg-teal-500/20 text-teal-700 dark:text-teal-400`:`bg-bambu-gray/20 text-bambu-gray`}`,children:t.file_type.toUpperCase()})}),(0,G.jsx)(`div`,{className:`text-sm text-bambu-gray`,children:Yd(t.file_size)}),(0,G.jsx)(`div`,{className:`text-sm text-bambu-gray`,children:t.print_count>0?`${t.print_count}x`:`-`}),(0,G.jsx)(`div`,{className:`min-w-0`,...e9,children:!t.tags||t.tags.length===0?(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray/50`,children:`-`}):(0,G.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:t.tags.map(e=>(0,G.jsxs)(`button`,{type:`button`,onClick:()=>at(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,G.jsx)(wu,{className:`w-2.5 h-2.5 flex-shrink-0`}),(0,G.jsx)(`span`,{className:`truncate`,children:e.name})]},e.id))})}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,...e9,children:[w5(t)&&(0,G.jsx)(G.Fragment,{children:(0,G.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,G.jsx)(Fl,{className:`w-4 h-4`})})}),T5(t,!!qe?.use_slicer_api,Je)&&(0,G.jsx)(`button`,{onClick:()=>{Xe()&&(qe?.use_slicer_api?ee:Ye)(t)},className:`p-1.5 rounded transition-colors ${Xe()?`hover:bg-bambu-dark text-bambu-gray hover:text-bambu-green`:`text-bambu-gray/50 cursor-not-allowed`}`,title:Xe()?e(`slice.action`):qe?.use_slicer_api?e(`fileManager.noPermissionSlice`):e(`fileManager.noPermissionDownload`),disabled:!Xe(),children:qe?.use_slicer_api?(0,G.jsx)(Ms,{className:`w-4 h-4`}):(0,G.jsx)(Qs,{className:`w-4 h-4`})}),(qe?.use_slicer_api??!1)&&T5(t,!0,Je)&&(0,G.jsx)(`button`,{onClick:()=>r(`pipelines:run`)&&oe(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,G.jsx)(Al,{className:`w-4 h-4`})}),t9(t)&&(0,G.jsx)(`button`,{onClick:()=>Et(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`)?e(`fileManager.preview3d`):e(`fileManager.noPermissionPreview`),disabled:!r(`library:read`),children:(0,G.jsx)(Wo,{className:`w-4 h-4`})}),!t9(t)&&$7(t)&&(0,G.jsx)(`button`,{onClick:()=>Et(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`)?e(`fileManager.preview.open`):e(`fileManager.noPermissionPreview`),disabled:!r(`library:read`),children:A1e(t.file_type)}),(0,G.jsx)(`button`,{onClick:()=>r(`library:read`)&&zt(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,G.jsx)(Gs,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:()=>r(`library:read`)&&_e(t),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(`fileManager.details.title`):e(`fileManager.noPermissionPreview`),disabled:!r(`library:read`),children:(0,G.jsx)(Bc,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:()=>a(`library`,`update`,t.created_by_id)&&H({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,G.jsx)(Dl,{className:`w-4 h-4`})}),j1e(t.file_type)&&(0,G.jsx)(`button`,{onClick:()=>a(`library`,`update`,t.created_by_id)&&Tt.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:Tt.isPending||!a(`library`,`update`,t.created_by_id),children:(0,G.jsx)(Rc,{className:`w-4 h-4`})}),(0,G.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,G.jsx)(Pu,{className:`w-4 h-4`})})]})]},t.id))]})})]}),u!==null&&(0,G.jsx)(v1e,{folderId:u})]})]}),_&&(0,G.jsx)(M1e,{parentId:u,onClose:()=>v(!1),onSave:e=>pt.mutate(e),isLoading:pt.isPending,t:e}),y&&(0,G.jsx)(N1e,{onClose:()=>b(!1),onSave:e=>mt.mutate(e),isLoading:mt.isPending,t:e}),x&&Ze&&(0,G.jsx)(L1e,{folders:Ze,selectedFiles:h,currentFolderId:u,onClose:()=>S(!1),onMove:e=>bt.mutate({fileIds:h,folderId:e}),isLoading:bt.isPending,t:e}),C&&(0,G.jsx)(BU,{folderId:u,onClose:()=>{w(!1),E([])},onUploadComplete:Ft,initialFiles:T.length>0?T:void 0}),D&&(0,G.jsx)(S1e,{onClose:()=>O(!1)}),(0,G.jsx)(y1e,{open:k,onClose:()=>A(!1),onPickTag:e=>{N.includes(e)||P(t=>[...t,e])}}),(0,G.jsx)(Qqe,{open:j,fileIds:h,onClose:()=>M(!1)}),F&&(0,G.jsx)(R1e,{folder:F,onClose:()=>I(null),onLink:e=>xt.mutate({id:F.id,data:e}),isLoading:xt.isPending,t:e}),L&&(0,G.jsx)(uf,{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:Bt,onCancel:()=>R(null)}),z&&(!z.variant_group_id||At!==void 0)&&(0,G.jsx)(Lm,{mode:`create`,libraryFileId:jt?.[0]?.id??z.id,variantFiles:jt,archiveName:jt&&jt.length>1?`${jt[0].filename} ${e(`common.plusNMore`,{count:jt.length-1})}`:z.print_name||z.filename,onClose:()=>B(null),onSuccess:()=>{B(null),g([]),t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`queue`]}),t.invalidateQueries({queryKey:[`archives`]})}}),V&&(0,G.jsx)(LW,{source:{kind:`libraryFile`,id:V.id,filename:V.filename},onClose:()=>ee(null)}),te&&kt.length>0&&(0,G.jsx)(Zqe,{files:kt,folderId:u,canSlice:!!qe?.use_slicer_api&&Xe(),onClose:()=>ne(!1),onCombined:(e,t)=>{ne(!1),g([]),t&&ie({id:e.id,filename:e.filename})}}),re&&(0,G.jsx)(LW,{source:{kind:`libraryFile`,id:re.id,filename:re.filename},onClose:()=>ie(null),defaultAutoArrange:!0}),ae&&(0,G.jsx)(BW,{source:{kind:`libraryFile`,id:ae.id,filename:ae.filename},onClose:()=>oe(null)}),ue&&(0,G.jsx)(Yqe,{libraryFileId:ue.id,title:ue.print_name||ue.filename,fileType:ue.file_type,onClose:()=>de(null),onSnapshot:Q7(ue.file_type)?Rt(ue):void 0,onSliceWithBambuddy:T5(ue,!0,Je)&&r(`library:upload`)?()=>{let e=ue;de(null),ee(e)}:void 0}),(fe||me||ve)&&(0,G.jsxs)(f.Suspense,{fallback:null,children:[fe&&(0,G.jsx)(C1e,{libraryFileId:fe.id,filename:fe.print_name||fe.filename,fileSize:fe.file_size,onClose:()=>pe(null),onSnapshot:Rt(fe)}),me&&(0,G.jsx)(w1e,{libraryFileId:me.id,filename:me.print_name||me.filename,fileType:me.file_type,fileSize:me.file_size,onClose:()=>he(null),onSnapshot:Rt(me)}),ve&&(0,G.jsx)(T1e,{libraryFileId:ve.id,filename:ve.print_name||ve.filename,fileSize:ve.file_size,onClose:()=>ye(null)})]}),ge&&(0,G.jsx)(b1e,{file:ge,canEdit:a(`library`,`update`,ge.created_by_id),onClose:()=>_e(null)}),se&&(0,G.jsx)(I1e,{type:se.type,currentName:se.name,onClose:()=>H(null),onSave:e=>{se.type===`file`?St.mutate({id:se.id,filename:e}):Ct.mutate({id:se.id,name:e})},isLoading:St.isPending||Ct.isPending,t:e})]})}function H1e(e){let t=sp(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 U1e(e){let t=sp(e);return t?t.toLocaleString():e}function W1e(){let{t:e}=U(),t=$n(),n=no(),{showToast:r}=Zd(),{hasPermission:i,authEnabled:a}=Ld(),[o,s]=(0,f.useState)(null),[c,l]=(0,f.useState)(new Set),u=!a||i(`library:purge`),d=K({queryKey:[`library-trash`],queryFn:()=>Z.listLibraryTrash(200,0)}),p=K({queryKey:[`library-trash-settings`],queryFn:()=>Z.getLibraryTrashSettings(),enabled:u}),[m,h]=(0,f.useState)(null);(0,f.useEffect)(()=>{p.data&&m===null&&h(p.data.retention_days)},[p.data,m]);let g=q({mutationFn:e=>{let t=p.data;return Z.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`)}),_=q({mutationFn:e=>Z.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`)}),v=q({mutationFn:e=>Z.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`)}),y=q({mutationFn:()=>Z.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=q({mutationFn:e=>Promise.all(e.map(e=>Z.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=q({mutationFn:e=>Promise.all(e.map(e=>Z.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,f.useMemo)(()=>d.data?.items??[],[d.data?.items]),C=d.data?.retention_days??30,w=(0,f.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,G.jsxs)(`div`,{className:`p-6 max-w-screen-2xl mx-auto`,children:[(0,G.jsx)(`div`,{className:`flex items-center gap-3 mb-4`,children:(0,G.jsxs)(Ci,{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,G.jsx)(jo,{className:`w-4 h-4`}),` `,e(`libraryTrash.backToFiles`)]})}),(0,G.jsxs)(`div`,{className:`flex items-start justify-between mb-6 gap-4 flex-wrap`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h1`,{className:`text-2xl font-bold text-gray-900 dark:text-gray-100`,children:e(`libraryTrash.title`)}),(0,G.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,G.jsxs)(Q,{variant:`secondary`,onClick:()=>s({type:`empty`}),className:`text-red-600 dark:text-red-400`,children:[(0,G.jsx)(Pu,{className:`w-4 h-4 mr-1`}),e(`libraryTrash.emptyTrash`)]})]}),u&&p.data&&(0,G.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,G.jsx)(`label`,{htmlFor:`retention-days`,className:`text-sm font-medium text-gray-700 dark:text-gray-300`,children:e(`libraryTrash.retentionLabel`)}),(0,G.jsx)(`input`,{id:`retention-days`,type:`number`,min:1,max:365,value:m??p.data.retention_days,onChange:e=>h(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,G.jsx)(`span`,{className:`text-sm text-gray-600 dark:text-gray-400`,children:e(`libraryTrash.days`)}),(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>m!=null&&g.mutate(m),disabled:g.isPending||m==null||m===p.data.retention_days,className:`ml-auto`,children:[(0,G.jsx)(Wl,{className:`w-4 h-4 mr-1`}),e(`common.save`)]})]}),d.isLoading?(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-gray-500 dark:text-gray-400`,children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),` `,e(`libraryTrash.loading`)]}):S.length===0?(0,G.jsx)(`div`,{className:`border border-dashed border-gray-300 dark:border-gray-700 rounded-lg p-12 text-center`,children:(0,G.jsx)(`p`,{className:`text-gray-500 dark:text-gray-400`,children:e(`libraryTrash.empty`)})}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,G.jsx)(`div`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:e(`libraryTrash.summary`,{count:S.length,size:Yd(w)})}),c.size>0&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,G.jsx)(`span`,{className:`text-gray-600 dark:text-gray-400`,children:e(`libraryTrash.selectionCount`,{count:c.size})}),(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>b.mutate(Array.from(c)),disabled:b.isPending,children:[(0,G.jsx)(Vl,{className:`w-4 h-4 mr-1`}),e(`libraryTrash.bulkRestore`)]}),(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>s({type:`bulkDelete`,count:c.size}),disabled:x.isPending,className:`text-red-600 dark:text-red-400`,children:[(0,G.jsx)(Pu,{className:`w-4 h-4 mr-1`}),e(`libraryTrash.bulkPurge`)]})]})]}),(0,G.jsx)(`div`,{className:`border border-gray-200 dark:border-gray-700 rounded-lg overflow-x-auto`,children:(0,G.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,G.jsx)(`thead`,{className:`bg-gray-50 dark:bg-gray-800 text-left text-gray-600 dark:text-gray-300`,children:(0,G.jsxs)(`tr`,{children:[(0,G.jsx)(`th`,{className:`px-3 py-2 w-10`,children:(0,G.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,G.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:e(`libraryTrash.col.filename`)}),(0,G.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:e(`libraryTrash.col.folder`)}),(0,G.jsx)(`th`,{className:`px-3 py-2 font-medium text-right`,children:e(`libraryTrash.col.size`)}),(0,G.jsx)(`th`,{className:`px-3 py-2 font-medium whitespace-nowrap`,children:e(`libraryTrash.col.deleted`)}),(0,G.jsx)(`th`,{className:`px-3 py-2 font-medium whitespace-nowrap`,children:e(`libraryTrash.col.autoPurge`)}),u&&(0,G.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:e(`libraryTrash.col.owner`)}),(0,G.jsx)(`th`,{className:`px-3 py-2 font-medium text-right`,children:e(`libraryTrash.col.actions`)})]})}),(0,G.jsx)(`tbody`,{className:`divide-y divide-gray-100 dark:divide-gray-800`,children:S.map(t=>(0,G.jsxs)(`tr`,{className:`hover:bg-gray-50 dark:hover:bg-gray-800/50`,children:[(0,G.jsx)(`td`,{className:`px-3 py-2`,children:(0,G.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,G.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,G.jsx)(`td`,{className:`px-3 py-2 text-gray-600 dark:text-gray-400`,children:t.folder_name??`—`}),(0,G.jsx)(`td`,{className:`px-3 py-2 text-right text-gray-600 dark:text-gray-400 tabular-nums whitespace-nowrap`,children:Yd(t.file_size)}),(0,G.jsx)(`td`,{className:`px-3 py-2 text-gray-600 dark:text-gray-400 whitespace-nowrap`,children:U1e(t.deleted_at)}),(0,G.jsx)(`td`,{className:`px-3 py-2 text-gray-600 dark:text-gray-400 whitespace-nowrap`,children:(0,G.jsx)(`span`,{title:U1e(t.auto_purge_at),children:e(`libraryTrash.autoPurgeIn`,{when:H1e(t.auto_purge_at)})})}),u&&(0,G.jsx)(`td`,{className:`px-3 py-2 text-gray-600 dark:text-gray-400`,children:t.created_by_username??`—`}),(0,G.jsxs)(`td`,{className:`px-3 py-2 text-right whitespace-nowrap`,children:[(0,G.jsxs)(`button`,{onClick:()=>_.mutate(t.id),disabled:_.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,G.jsx)(Vl,{className:`w-3.5 h-3.5`}),e(`libraryTrash.restore`)]}),(0,G.jsxs)(`button`,{onClick:()=>s({type:`delete`,id:t.id,filename:t.filename}),disabled:v.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,G.jsx)(Pu,{className:`w-3.5 h-3.5`}),e(`libraryTrash.purgeNow`)]})]})]},t.id))})]})})]}),o&&(0,G.jsx)(uf,{onCancel:()=>s(null),onConfirm:()=>{o&&(o.type===`delete`?v.mutate(o.id):o.type===`bulkDelete`?x.mutate(Array.from(c)):y.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,G.jsxs)(`div`,{className:`mt-4 text-sm text-red-600 dark:text-red-400`,children:[d.error?.message??e(`libraryTrash.loadError`),(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>t(`/files`),className:`ml-3`,children:e(`libraryTrash.backToFiles`)})]})]})}function G1e(e){return e.includes(`/camera/`)}function K1e(e,t,n){let r=0;return e.querySelectorAll(`img[src*="/api/v1/"], video[src*="/api/v1/"]`).forEach(e=>{let i=e.getAttribute(`src`)||``,a=G1e(i)?n:t;if(!a)return;let o=`token=${encodeURIComponent(a)}`;if(i.includes(o))return;let s=i.replace(/([?&])token=[^&]*(&|$)/,(e,t,n)=>n===`&`?t:``);e.src=`${s}${s.includes(`?`)?`&`:`?`}${o}`,r+=1}),r}function q1e(){let{authEnabled:e,user:t,loading:n,hasPermission:r}=Ld(),i=no(),a=(0,f.useRef)(!1),o=!n&&(!e||t!==null),{data:s}=K({queryKey:[`media-token`,t?.id??null],queryFn:()=>Z.getMediaToken(),enabled:o,staleTime:3e3*1e3,refetchInterval:3e3*1e3}),c=!e||r(`camera:view`),{data:l}=K({queryKey:[`camera-stream-token`,t?.id??null],queryFn:()=>Z.getCameraStreamToken(),enabled:o&&c,staleTime:3e3*1e3,refetchInterval:3e3*1e3}),u=s?.token??null,d=l?.token??null;(0,f.useEffect)(()=>(hd(u),pd(d),(u||d)&&K1e(document,u,d),()=>{hd(null),pd(null)}),[u,d]),(0,f.useEffect)(()=>{if(!e)return;let t=e=>{let t=e.target;if(!(t instanceof HTMLImageElement||t instanceof HTMLVideoElement))return;let n=t.src||``,r=G1e(n),o=r?md():gd();!o||!n.includes(`token=${encodeURIComponent(o)}`)||a.current||(a.current=!0,i.invalidateQueries({queryKey:r?[`camera-stream-token`]:[`media-token`]}),setTimeout(()=>{a.current=!1},5e3))};return document.addEventListener(`error`,t,!0),()=>document.removeEventListener(`error`,t,!0)},[e,i])}var n9=5,J1e=2e3,Y1e=3e4,X1e=5e3;function Z1e(){let{t:e}=U(),t=no(),{showToast:n}=Zd(),{hasPermission:r,authEnabled:i,user:a}=Ld(),{printerId:o}=ir(),s=parseInt(o||`0`,10),[c]=ji(),l=parseInt(c.get(`fps`)||`15`,10),u=Math.min(Math.max(isNaN(l)?15:l,1),30);q1e();let{data:d,isPending:p}=K({queryKey:[`camera-stream-token`,a?.id??null],queryFn:()=>Z.getCameraStreamToken(),enabled:i?!!a:!0,staleTime:3e3*1e3}),m=d?.token??md(),[h,g]=(0,f.useState)(`stream`),[_,v]=(0,f.useState)(!1),[y,b]=(0,f.useState)(!1),[x,S]=(0,f.useState)(!1),[C,w]=(0,f.useState)(!0),[T,E]=(0,f.useState)(Date.now()),[D,O]=(0,f.useState)(!1),[k,A]=(0,f.useState)(!1),[j,M]=(0,f.useState)(0),[N,P]=(0,f.useState)(!1),[F,I]=(0,f.useState)(0),[L,R]=(0,f.useState)(1),[z,B]=(0,f.useState)({x:0,y:0}),[V,ee]=(0,f.useState)(!1),[te,ne]=(0,f.useState)({x:0,y:0}),[re,ie]=(0,f.useState)(null),[ae,oe]=(0,f.useState)(null),se=(0,f.useRef)(null),H=(0,f.useRef)(null),ce=(0,f.useRef)(null),le=(0,f.useRef)(null),ue=(0,f.useRef)(null),de=(0,f.useRef)(0),{data:fe}=K({queryKey:[`printer`,s],queryFn:()=>Z.getPrinter(s),enabled:s>0}),{data:pe}=K({queryKey:[`printerStatus`,s],queryFn:()=>Z.getPrinterStatus(s),refetchInterval:3e4,enabled:s>0}),me=q({mutationFn:e=>Z.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`)}}),he=(pe?.state===`RUNNING`||pe?.state===`PAUSE`)&&(pe?.printable_objects_count??0)>=2;(0,f.useEffect)(()=>(fe&&(document.title=`${fe.name} - Camera`),()=>{document.title=`Bambuddy`}),[fe]);let ge=(0,f.useRef)(!1);(0,f.useEffect)(()=>{let e=`/api/v1/printers/${s}/camera/stop`;ge.current=!1;let t=()=>{if(s>0&&!ge.current){ge.current=!0;let t={},n=ud();n&&(t.Authorization=`Bearer ${n}`),fetch(e,{method:`POST`,keepalive:!0,headers:t}).catch(()=>{})}},n=()=>{t()};window.addEventListener(`beforeunload`,n);let r=se.current;return()=>{window.removeEventListener(`beforeunload`,n),r&&(r.src=``),t()}},[s]),(0,f.useEffect)(()=>{if(C&&!D){let e=setTimeout(()=>{w(!1)},h===`stream`?3e3:2e4);return()=>clearTimeout(e)}},[h,C,T,D]),(0,f.useEffect)(()=>{let e=()=>{A(!!document.fullscreenElement),R(1),B({x:0,y:0}),h===`stream`&&!D&&(se.current&&(se.current.src=``),setTimeout(()=>{w(!0),E(Date.now())},200))};return document.addEventListener(`fullscreenchange`,e),()=>document.removeEventListener(`fullscreenchange`,e)},[h,D]),(0,f.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,f.useEffect)(()=>()=>{ce.current&&clearTimeout(ce.current),le.current&&clearInterval(le.current),ue.current&&clearInterval(ue.current)},[]);let _e=(0,f.useCallback)(()=>{if(j>=n9){P(!1),S(!0);return}let e=Math.min(J1e*2**j,Y1e);P(!0),I(Math.ceil(e/1e3)),le.current=setInterval(()=>{I(e=>e<=1?(le.current&&clearInterval(le.current),0):e-1)},1e3),ce.current=setTimeout(()=>{M(e=>e+1),P(!1),w(!0),S(!1),se.current&&(se.current.src=``),E(Date.now())},e)},[j]);(0,f.useEffect)(()=>{if(h!==`stream`||C||N||D){ue.current&&=(clearInterval(ue.current),null);return}return de.current=0,ue.current=setInterval(async()=>{try{let e=await Z.getCameraStatus(s);if(!(e.stalled||!e.active&&!x)){de.current=0;return}if(de.current+=1,de.current<2)return;de.current=0,console.log(`Stream issue detected: stalled=${e.stalled}, active=${e.active}, reconnecting...`),ue.current&&=(clearInterval(ue.current),null),w(!1),_e()}catch{}},X1e),()=>{ue.current&&=(clearInterval(ue.current),null)}},[h,C,x,N,D,s,_e]);let ve=()=>{w(!1),h===`stream`&&j{if(w(!1),S(!1),M(0),de.current=0,P(!1),ce.current&&clearTimeout(ce.current),le.current&&clearInterval(le.current),se.current&&!localStorage.getItem(`cameraWindowState`)){let e=se.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{}}}},be=()=>{if(s>0){let e={},t=ud();t&&(e.Authorization=`Bearer ${t}`),fetch(`/api/v1/printers/${s}/camera/stop`,{method:`POST`,headers:e}).catch(()=>{})}},xe=e=>{h===e||D||(O(!0),w(!0),S(!1),M(0),P(!1),R(1),B({x:0,y:0}),ce.current&&clearTimeout(ce.current),le.current&&clearInterval(le.current),se.current&&(se.current.src=``),h===`stream`&&be(),setTimeout(()=>{g(e),E(Date.now()),O(!1)},100))},Se=()=>{D||(O(!0),w(!0),S(!1),M(0),P(!1),ce.current&&clearTimeout(ce.current),le.current&&clearInterval(le.current),se.current&&(se.current.src=``),h===`stream`&&be(),setTimeout(()=>{E(Date.now()),O(!1)},100))},Ce=()=>{H.current&&(document.fullscreenElement?document.exitFullscreen():H.current.requestFullscreen())},we=()=>{R(e=>Math.min(e+.5,4))},Te=()=>{R(e=>{let t=Math.max(e-.5,1);return t===1&&B({x:0,y:0}),t})},Ee=e=>{e.preventDefault(),e.deltaY<0?we():Te()},De=e=>{L>1&&(e.preventDefault(),ee(!0),ne({x:e.clientX-z.x,y:e.clientY-z.y}))},Oe=(0,f.useCallback)(()=>{if(!H.current)return{x:300,y:200};let e=H.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]),ke=e=>{if(V&&L>1){let t=e.clientX-te.x,n=e.clientY-te.y,r=Oe();B({x:Math.max(-r.x,Math.min(r.x,t)),y:Math.max(-r.y,Math.min(r.y,n))})}},Ae=()=>{ee(!1)},je=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)},Me=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},Ne=e=>{e.touches.length===2?(e.preventDefault(),ie(je(e.touches)),oe(Me(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}))},Pe=e=>{if(e.touches.length===2&&re!==null){e.preventDefault();let t=je(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=Me(e.touches);if(ae){let e=Oe();B(t=>({x:Math.max(-e.x,Math.min(e.x,t.x+(r.x-ae.x))),y:Math.max(-e.y,Math.min(e.y,t.y+(r.y-ae.y)))}))}oe(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=Oe();B({x:Math.max(-r.x,Math.min(r.x,t)),y:Math.max(-r.y,Math.min(r.y,n))})}},Fe=e=>{e.touches.length<2&&(ie(null),oe(null)),e.touches.length===0&&ee(!1)},Ie=()=>{R(1),B({x:0,y:0})},Le=D||!m&&(i||p)?``:(e=>m?`${e}&token=${encodeURIComponent(m)}`:_d(e))(h===`stream`?`/api/v1/printers/${s}/camera/stream?fps=${u}&t=${T}`:`/api/v1/printers/${s}/camera/snapshot?t=${T}`),Re=C||D||N;return s?(0,G.jsxs)(`div`,{ref:H,className:`min-h-screen bg-black flex flex-col`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2 bg-bambu-dark-secondary border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`h1`,{className:`text-sm font-medium text-white flex items-center gap-2`,children:[(0,G.jsx)(es,{className:`w-4 h-4`}),fe?.name||`Printer ${s}`]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`div`,{className:`flex bg-bambu-dark rounded p-0.5`,children:[(0,G.jsx)(`button`,{onClick:()=>xe(`stream`),disabled:Re,className:`px-3 py-1 text-xs rounded transition-colors ${h===`stream`?`bg-bambu-green text-white`:`text-bambu-gray hover:text-white disabled:opacity-50`}`,children:e(`camera.live`)}),(0,G.jsx)(`button`,{onClick:()=>xe(`snapshot`),disabled:Re,className:`px-3 py-1 text-xs rounded transition-colors ${h===`snapshot`?`bg-bambu-green text-white`:`text-bambu-gray hover:text-white disabled:opacity-50`}`,children:e(`camera.snapshot`)})]}),(0,G.jsx)(`button`,{onClick:()=>me.mutate(!pe?.chamber_light),disabled:!pe?.connected||me.isPending||!r(`printers:control`),className:`p-1.5 rounded disabled:opacity-50 ${pe?.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,G.jsx)(LT,{on:pe?.chamber_light??!1,className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:()=>v(!0),disabled:!he||!r(`printers:control`),className:`p-1.5 rounded disabled:opacity-50 ${he&&r(`printers:control`)?`hover:bg-bambu-dark-tertiary`:``}`,title:r(`printers:control`)?e(he?`printers.skipObjects.tooltip`:`printers.skipObjects.onlyWhilePrinting`):e(`printers.permission.noControl`),children:(0,G.jsx)(RT,{className:`w-4 h-4 text-bambu-gray`})}),(0,G.jsx)(`button`,{onClick:Se,disabled:Re,className:`p-1.5 hover:bg-bambu-dark-tertiary rounded disabled:opacity-50`,title:e(h===`stream`?`camera.restartStream`:`camera.refreshSnapshot`),children:(0,G.jsx)(zl,{className:`w-4 h-4 text-bambu-gray ${Re?`animate-spin`:``}`})}),(0,G.jsx)(`button`,{onClick:()=>b(!0),className:`p-1.5 hover:bg-bambu-dark-tertiary rounded`,title:e(`camera.diagnose.button`),children:(0,G.jsx)(yu,{className:`w-4 h-4 text-bambu-gray`})}),(0,G.jsx)(`button`,{onClick:Ce,className:`p-1.5 hover:bg-bambu-dark-tertiary rounded`,title:e(k?`camera.exitFullscreen`:`camera.fullscreen`),children:k?(0,G.jsx)(ul,{className:`w-4 h-4 text-bambu-gray`}):(0,G.jsx)(al,{className:`w-4 h-4 text-bambu-gray`})})]})]}),(0,G.jsx)(`div`,{className:`flex-1 flex items-center justify-center p-2 overflow-hidden`,onWheel:Ee,onMouseMove:ke,onMouseUp:Ae,onMouseLeave:Ae,onTouchStart:Ne,onTouchMove:Pe,onTouchEnd:Fe,style:{touchAction:`none`},children:(0,G.jsxs)(`div`,{className:`relative w-full h-full flex items-center justify-center`,children:[(C||D)&&!N&&(0,G.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-black/50 z-10`,children:(0,G.jsxs)(`div`,{className:`text-center`,children:[(0,G.jsx)(zl,{className:`w-8 h-8 text-bambu-gray animate-spin mx-auto mb-2`}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(h===`stream`?`camera.connectingToCamera`:`camera.capturingSnapshot`)})]})}),N&&(0,G.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-black/80 z-10`,children:(0,G.jsxs)(`div`,{className:`text-center p-4`,children:[(0,G.jsx)(Zu,{className:`w-10 h-10 text-orange-400 mx-auto mb-3`}),(0,G.jsx)(`p`,{className:`text-white mb-2`,children:e(`camera.connectionLost`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mb-3`,children:e(`camera.reconnecting`,{countdown:F,attempt:Math.min(j+1,n9),max:n9})}),(0,G.jsx)(`button`,{onClick:Se,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,G.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-black z-10`,children:(0,G.jsxs)(`div`,{className:`text-center p-4`,children:[(0,G.jsx)(Lu,{className:`w-12 h-12 text-orange-400 mx-auto mb-3`}),(0,G.jsx)(`p`,{className:`text-white mb-2`,children:e(`camera.cameraUnavailable`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mb-4 max-w-md`,children:e(`camera.cameraUnavailableDesc`)}),(0,G.jsxs)(`div`,{className:`flex gap-2 justify-center`,children:[(0,G.jsx)(`button`,{onClick:Se,className:`px-4 py-2 bg-bambu-green text-white rounded hover:bg-bambu-green/80 transition-colors`,children:e(`camera.retry`)}),(0,G.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,G.jsx)(`img`,{ref:se,src:Le,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(${fe?.camera_rotation||0}deg)`,...fe?.camera_rotation===90||fe?.camera_rotation===270?{maxWidth:`100vh`,maxHeight:`100vw`}:{},cursor:L>1?V?`grabbing`:`grab`:`default`},onError:Le?ve:void 0,onLoad:Le?ye:void 0,onMouseDown:De,draggable:!1},T),(0,G.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,G.jsx)(`button`,{onClick:Te,disabled:L<=1,className:`p-1.5 hover:bg-white/10 rounded disabled:opacity-30`,title:e(`camera.zoomOut`),children:(0,G.jsx)(ad,{className:`w-4 h-4 text-white`})}),(0,G.jsxs)(`button`,{onClick:Ie,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,G.jsx)(`button`,{onClick:we,disabled:L>=4,className:`p-1.5 hover:bg-white/10 rounded disabled:opacity-30`,title:e(`camera.zoomIn`),children:(0,G.jsx)(rd,{className:`w-4 h-4 text-white`})})]})]})}),(0,G.jsx)(zT,{printerId:s,isOpen:_,onClose:()=>v(!1)}),y&&(0,G.jsx)(BT,{printerId:s,printerName:fe?.name||null,onClose:()=>b(!1)})]}):(0,G.jsx)(`div`,{className:`min-h-screen bg-black flex items-center justify-center`,children:(0,G.jsx)(`p`,{className:`text-white`,children:e(`camera.invalidPrinterId`)})})}var Q1e=5e3,$1e=4,e0e=8,t0e=1,n0e=16,r0e=2,i0e=60;function a0e(e,t,n,r){let i=parseInt(e??``,10);return Number.isFinite(i)?Math.min(r,Math.max(n,i)):t}function o0e(e,t,n,r,i,a){return e.has(t)?a0e(e.get(t),r,i,a):a0e(localStorage.getItem(n),r,i,a)}function s0e(){let{t:e}=U(),t=Xn(),{authEnabled:n,loading:r,user:i}=Ld(),[a]=ji(),o=a.get(`token`),s=o!=null&&o!==``,[c,l]=(0,f.useState)(()=>o0e(a,`maxLive`,`camWallMaxLive`,$1e,t0e,n0e)),[u,d]=(0,f.useState)(()=>o0e(a,`interval`,`camWallSnapshotSec`,e0e,r0e,i0e)),[p,m]=(0,f.useState)(()=>{let e=a.get(`status`)??localStorage.getItem(`camWallStatusMode`);return(s?[`off`,`compact`]:[`off`,`compact`,`full`]).includes(e)?e:`compact`});(0,f.useEffect)(()=>{if(s)return pd(o),()=>pd(null)},[s,o]);let h=K({queryKey:[`camwall-printers`,o],queryFn:()=>Z.getCamWallPrinters(o??void 0),enabled:s,refetchInterval:Q1e}),g=K({queryKey:[`printers`],queryFn:()=>Z.getPrinters(),enabled:!s&&!r&&(!n||i!==null),refetchInterval:Q1e}),_=(0,f.useMemo)(()=>{let e=new Map;for(let t of h.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},[h.data]);if(!s&&r)return(0,G.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,G.jsx)(Or,{to:`/login`,replace:!0,state:{from:t}});let v=s?h:g,y=s?h.data??[]:g.data??[];return v.isError?(0,G.jsx)(`div`,{className:`flex min-h-screen items-center justify-center bg-bambu-dark p-6 text-center`,children:(0,G.jsx)(`p`,{className:`max-w-md text-sm text-red-400`,children:e(s?`printers.camWall.page.tokenRejected`:`printers.camWall.page.loadFailed`)})}):(0,G.jsx)(`div`,{className:`min-h-screen bg-bambu-dark p-4`,children:(0,G.jsx)(qT,{printers:y,maxLive:c,snapshotIntervalSec:u,statusMode:p,statuses:s?_: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=>{m(e),localStorage.setItem(`camWallStatusMode`,e)}})})}function c0e(e,t){let[n,r]=(0,f.useState)(null);return(0,f.useLayoutEffect)(()=>{let n=e.current;if(!t||!n)return;let i=()=>{let{width:e,height:t}=n.getBoundingClientRect();e>0&&t>0&&r(n=>n&&n.width===e&&n.height===t?n:{width:e,height:t})};if(i(),typeof ResizeObserver>`u`)return window.addEventListener(`resize`,i),()=>window.removeEventListener(`resize`,i);let a=new ResizeObserver(i);return a.observe(n),()=>a.disconnect()},[e,t]),t?n:null}function l0e(e){let{t}=U(),{camera:n,name:r,model:i,filename:a,status:o,state:s,progress:c,layers:l,remaining:u,eta:d,temperatures:p}=e,m=a||o||c!=null||l||u||d||p.length>0,h=n?.rotation??0,g=Math.abs(h%180)===90,_=(0,f.useRef)(null),v=c0e(_,g&&n!=null),y=[{key:`layers`,icon:(0,G.jsx)(Wc,{}),label:t(`streamOverlay.layer`),value:l},{key:`remaining`,icon:(0,G.jsx)(Nu,{}),label:t(`streamOverlay.remaining`),value:u},{key:`eta`,icon:(0,G.jsx)(Ts,{}),label:t(`streamOverlay.eta`),value:d}].filter(e=>e.value!=null);return(0,G.jsxs)(`div`,{className:`updated-overlay`,"data-size":e.size,"data-state":s,children:[(0,G.jsxs)(`header`,{className:`updated-overlay__header`,children:[(r||i)&&(0,G.jsxs)(`div`,{className:`updated-overlay__identity`,children:[(0,G.jsx)(Fl,{"aria-hidden":`true`}),(0,G.jsxs)(`div`,{children:[r&&(0,G.jsx)(`strong`,{children:r}),i&&(0,G.jsx)(`span`,{children:i})]})]}),(0,G.jsx)(`a`,{className:`updated-overlay__logo`,href:`https://github.com/maziggy/bambuddy`,target:`_blank`,rel:`noopener noreferrer`,children:(0,G.jsx)(`img`,{src:`/img/bambuddy_logo_powered_by.png`,alt:`Bambuddy`})})]}),n&&(0,G.jsx)(`div`,{className:`updated-overlay__camera`,ref:_,children:(0,G.jsx)(`img`,{src:n.url,alt:t(`streamOverlay.cameraStream`),style:{transform:`translate(-50%, -50%) rotate(${h}deg)`,...g&&v?{width:v.height,height:v.width}:{}},onError:n.onError},n.url)}),m&&(0,G.jsxs)(`section`,{className:`updated-overlay__panel`,children:[(a||o)&&(0,G.jsxs)(`div`,{className:`updated-overlay__summary`,children:[a&&(0,G.jsx)(`h1`,{children:a}),o&&(0,G.jsxs)(`div`,{className:`updated-overlay__status`,children:[(0,G.jsx)(`span`,{"aria-hidden":`true`}),o]})]}),c!=null&&(0,G.jsxs)(`div`,{className:`updated-overlay__progress`,children:[(0,G.jsx)(`span`,{children:t(`streamOverlay.progress`)}),(0,G.jsx)(`div`,{role:`progressbar`,"aria-label":t(`streamOverlay.progress`),"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":c,children:(0,G.jsx)(`div`,{style:{width:`${c}%`}})}),(0,G.jsxs)(`strong`,{children:[Math.round(c),`%`]})]}),(y.length>0||p.length>0)&&(0,G.jsxs)(`div`,{className:`updated-overlay__readings`,children:[y.length>0&&(0,G.jsx)(`div`,{className:`updated-overlay__stats`,children:y.map(e=>(0,G.jsxs)(`div`,{className:`updated-overlay__reading`,children:[e.icon,(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{children:e.label}),(0,G.jsx)(`strong`,{children:e.value})]})]},e.key))}),p.length>0&&(0,G.jsx)(`div`,{className:`updated-overlay__temperatures`,children:p.map(e=>(0,G.jsxs)(`div`,{className:`updated-overlay__reading`,children:[e.icon,(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{children:e.label}),(0,G.jsxs)(`strong`,{children:[Math.round(e.current),`°C`,e.target!=null&&e.target>0&&Math.round(e.target)!==Math.round(e.current)&&(0,G.jsxs)(`small`,{children:[` / `,Math.round(e.target),`°C`]})]})]})]},e.key))})]})]})]})}var u0e=6e4,d0e=3e3;function f0e(e){let[t,n]=(0,f.useState)(Date.now),r=(0,f.useRef)(null),i=(0,f.useCallback)(()=>{r.current!==null&&(clearTimeout(r.current),r.current=null),n(e=>e+1)},[]);return(0,f.useEffect)(()=>{if(!e)return;let t=setTimeout(i,u0e);return()=>{clearTimeout(t),r.current!==null&&(clearTimeout(r.current),r.current=null)}},[e,t,i]),{imageKey:t,handleStreamError:(0,f.useCallback)(()=>{!e||r.current!==null||(r.current=setTimeout(i,d0e))},[e,i])}}function p0e(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 m0e(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,updatedArtwork:e.get(`artwork`)===`2`,showCamera:a,showProgress:t.includes(`progress`),showLayers:t.includes(`layers`),showEta:t.includes(`eta`),showFilename:t.includes(`filename`),showStatus:t.includes(`status`),showPrinter:t.includes(`printer`),showModel:t.includes(`model`),showNozzle:t.includes(`nozzle`),showBed:t.includes(`bed`),showChamber:t.includes(`chamber`)}}function h0e(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 r9(e,t){let n=e[t];return typeof n==`number`?n:null}function g0e({icon:e,label:t,current:n,target:r,sizes:i}){let a=r!=null&&r>0&&Math.round(r)!==Math.round(n);return(0,G.jsxs)(`div`,{className:`flex items-center ${i.gap} text-white/70`,children:[e,(0,G.jsxs)(`span`,{className:i.text,children:[(0,G.jsx)(`span`,{className:`mr-1`,children:t}),(0,G.jsxs)(`span`,{className:`text-white`,children:[Math.round(n),`°C`]}),a&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`span`,{className:`mx-1`,children:`/`}),(0,G.jsxs)(`span`,{children:[Math.round(r),`°C`]})]})]})]})}function _0e(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 v0e(){let{printerId:e}=ir(),[t]=ji(),{t:n}=U(),r=no(),i=parseInt(e||`0`,10),a=(0,f.useMemo)(()=>m0e(t),[t]),o=_0e(a.size),s=t.get(`token`),c=s!=null&&s!==``,{data:l}=K({queryKey:[`overlayStatus`,i,s],queryFn:()=>Z.getOverlayStatus(i,s??void 0),enabled:i>0&&c,refetchInterval:2e3}),{data:u}=K({queryKey:[`printer`,i],queryFn:()=>Z.getPrinter(i),enabled:i>0&&!c}),{data:d}=K({queryKey:[`printerStatus`,i],queryFn:()=>Z.getPrinterStatus(i),enabled:i>0&&!c,refetchInterval:2e3}),{data:p}=K({queryKey:[`settings`],queryFn:Z.getSettings,enabled:!c}),m=(0,f.useMemo)(()=>c?l&&{name:l.name,model:l.model,camera_rotation:l.camera_rotation}:u,[c,l,u]),h=[a.showPrinter?m?.name:null,a.showModel?ah(m?.model??null):null].filter(Boolean).join(` · `),g=c?l:d,{imageKey:_,handleStreamError:v}=f0e(i>0&&a.showCamera&&g!=null),y=(c?l?.time_format:p?.time_format)||`system`;if((0,f.useEffect)(()=>{if(!i||c)return;let e=null,t=!1;return(async()=>{let n;try{n=(await Z.getWebSocketToken()).token}catch(e){let t=e instanceof sd?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,c,r]),(0,f.useEffect)(()=>(document.title=m?`${m.name} - ${n(`streamOverlay.title`)}`:n(`streamOverlay.title`),()=>{document.title=`Bambuddy`}),[m,n]),!i)return(0,G.jsx)(`div`,{className:`min-h-screen bg-black flex items-center justify-center`,children:(0,G.jsx)(`p`,{className:`text-white`,children:n(`streamOverlay.invalidPrinterId`)})});if(!g)return(0,G.jsx)(`div`,{className:`min-h-screen bg-black flex items-center justify-center`,children:(0,G.jsx)(`p`,{className:`text-gray-400`,children:n(`common.loading`)})});let b=g.state===`RUNNING`||g.state===`PAUSE`,x=g.progress||0,S=g.temperatures??{},C=[];if(a.showNozzle){let e=r9(S,`nozzle`),t=r9(S,`nozzle_2`);e!=null&&C.push({key:`nozzle`,icon:(0,G.jsx)(uc,{className:o.icon}),label:n(`printers.heaterHistory.nozzle`,`Nozzle`),current:e,target:r9(S,`nozzle_target`)}),t!=null&&C.push({key:`nozzle_2`,icon:(0,G.jsx)(uc,{className:o.icon}),label:n(`printers.heaterHistory.nozzle2`,`Nozzle 2`),current:t,target:r9(S,`nozzle_2_target`)})}if(a.showBed){let e=r9(S,`bed`);e!=null&&C.push({key:`bed`,icon:(0,G.jsx)(_u,{className:o.icon}),label:n(`printers.heaterHistory.bed`,`Bed`),current:e,target:r9(S,`bed_target`)})}if(a.showChamber){let e=r9(S,`chamber`);e!=null&&C.push({key:`chamber`,icon:(0,G.jsx)(Wo,{className:o.icon}),label:n(`printers.heaterHistory.chamber`,`Chamber`),current:e,target:r9(S,`chamber_target`)})}let w=`/api/v1/printers/${i}/camera/stream?fps=${a.fps}&t=${_}`,T=c&&s?`${w}&token=${encodeURIComponent(s)}`:_d(w);if(a.updatedArtwork){let e=g.connected&&b,t=g.remaining_time,r=e&&a.showEta&&t!=null&&t>0;return(0,G.jsx)(l0e,{size:a.size,camera:a.showCamera?{url:T,rotation:m?.camera_rotation??0,onError:v}:null,name:a.showPrinter?m?.name??null:null,model:a.showModel&&ah(m?.model??null)||null,filename:a.showFilename&&g.current_print?p0e(g.current_print.replace(/\.gcode\.3mf$|\.3mf$|\.gcode$/i,``),g.gcode_file,n):null,status:a.showStatus?g.connected?h0e(g,n):n(`streamOverlay.printerOffline`):null,state:g.connected?g.state:null,progress:e&&a.showProgress?Math.min(100,Math.max(0,Number.isFinite(x)?x:0)):null,layers:e&&a.showLayers&&g.layer_num!=null&&g.total_layers!=null&&g.total_layers>0?`${g.layer_num} / ${g.total_layers}`:null,remaining:r?pp(t*60):null,eta:r?fp(t,y,n):null,temperatures:g.connected?C:[]})}return(0,G.jsxs)(`div`,{className:`min-h-screen bg-black relative overflow-hidden`,children:[a.showCamera&&(0,G.jsx)(`img`,{src:T,alt:n(`streamOverlay.cameraStream`),className:`absolute inset-0 w-full h-full object-contain`,style:m?.camera_rotation?{transform:`rotate(${m.camera_rotation}deg)`}:void 0,onError:v},_),(0,G.jsx)(`a`,{href:`https://github.com/maziggy/bambuddy`,target:`_blank`,rel:`noopener noreferrer`,className:`absolute top-4 right-4 z-10`,children:(0,G.jsx)(`img`,{src:`/img/bambuddy_logo_dark_transparent.png`,alt:`Bambuddy`,className:`${o.logoHeight} object-contain drop-shadow-lg hover:scale-105 transition-transform`})}),(0,G.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,G.jsxs)(`div`,{className:`${o.container}`,children:[h&&(0,G.jsxs)(`div`,{className:`flex items-center ${o.gap} mb-2`,children:[(0,G.jsx)(Fl,{className:`${o.icon} shrink-0 text-white/70`}),(0,G.jsx)(`span`,{className:`${o.text} min-w-0 truncate text-white font-medium`,children:h})]}),a.showFilename&&g.current_print&&(0,G.jsx)(`div`,{className:`${o.textLarge} text-white font-semibold mb-2 truncate drop-shadow-md`,children:p0e(g.current_print.replace(/\.gcode\.3mf$|\.3mf$|\.gcode$/i,``),g.gcode_file,n)}),a.showStatus&&(0,G.jsx)(`div`,{className:`${o.text} text-white/70 mb-2`,children:h0e(g,n)}),a.showProgress&&b&&(0,G.jsxs)(`div`,{className:`mb-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-1 ${o.text}`,children:[(0,G.jsx)(`span`,{className:`text-white/70`,children:n(`streamOverlay.progress`)}),(0,G.jsxs)(`span`,{className:`text-white font-bold`,children:[Math.round(x),`%`]})]}),(0,G.jsx)(`div`,{className:`w-full bg-white/20 rounded-full ${o.progressHeight}`,children:(0,G.jsx)(`div`,{className:`bg-bambu-green ${o.progressHeight} rounded-full transition-all duration-500`,style:{width:`${x}%`}})})]}),b&&(a.showLayers||a.showEta)&&(0,G.jsxs)(`div`,{className:`flex items-center ${o.gap} flex-wrap`,children:[a.showLayers&&g.layer_num!=null&&g.total_layers!=null&&g.total_layers>0&&(0,G.jsxs)(`div`,{className:`flex items-center ${o.gap} text-white/70`,children:[(0,G.jsx)(Wc,{className:o.icon}),(0,G.jsxs)(`span`,{className:o.text,children:[(0,G.jsx)(`span`,{className:`text-white`,children:g.layer_num}),(0,G.jsx)(`span`,{className:`mx-1`,children:`/`}),(0,G.jsx)(`span`,{children:g.total_layers})]})]}),a.showEta&&g.remaining_time!=null&&g.remaining_time>0&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`flex items-center ${o.gap} text-white/70`,children:[(0,G.jsx)(Nu,{className:o.icon}),(0,G.jsx)(`span`,{className:`${o.text} text-white`,children:pp(g.remaining_time*60)})]}),(0,G.jsxs)(`div`,{className:`flex items-center ${o.gap} text-white/70`,children:[(0,G.jsx)(Ts,{className:o.icon}),(0,G.jsxs)(`span`,{className:`${o.text} text-white`,children:[n(`streamOverlay.eta`),` `,fp(g.remaining_time,y,n)]})]})]})]}),!b&&(0,G.jsx)(`div`,{className:`${o.text} text-white/70 py-2`,children:g.connected?n(`streamOverlay.printerIdle`):n(`streamOverlay.printerOffline`)}),C.length>0&&(0,G.jsx)(`div`,{className:`flex items-center ${o.gap} flex-wrap mt-2`,children:C.map(e=>(0,G.jsx)(g0e,{icon:e.icon,label:e.label,current:e.current,target:e.target,sizes:o},e.key))})]})})]})}function y0e(){let{t:e}=U(),{id:t}=ir(),{mode:n}=Bd(),r=(0,f.useRef)(null),i=b0e(r),{data:a,isLoading:o,error:s}=K({queryKey:[`external-link`,t],queryFn:()=>Z.getExternalLink(Number(t)),enabled:!!t});return o?(0,G.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,G.jsx)(Y,{className:`w-8 h-8 text-bambu-green animate-spin`})}):s||!a?(0,G.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-4 text-bambu-gray`,children:[(0,G.jsx)(Lu,{className:`w-12 h-12`}),(0,G.jsx)(`p`,{children:e(`common.linkNotFound`)})]}):(0,G.jsx)(`iframe`,{ref:r,src:a.url,onLoad:i,className:`h-full w-full border-0`,style:{colorScheme:n},title:a.name,sandbox:`allow-scripts allow-same-origin allow-forms allow-popups allow-popups-to-escape-sandbox`})}function b0e(e){let{resolvedMode:t,darkStyle:n,darkBackground:r,darkAccent:i,lightStyle:a,lightBackground:o,lightAccent:s}=Bd(),c=t===`dark`,l=c?n:a,u=c?r:o,d=c?i:s,p=(0,f.useCallback)(()=>{let n=e.current;if(!n?.contentWindow)return;let r;try{r=new URL(n.src).origin}catch{return}n.contentWindow.postMessage({type:`bambuddy:theme`,mode:t,style:l,background:u,accent:d},r)},[e,t,l,u,d]);return(0,f.useEffect)(()=>p(),[p]),(0,f.useEffect)(()=>{let t=t=>{t.source===e.current?.contentWindow&&t.data?.type===`bambuddy:theme-request`&&p()};return window.addEventListener(`message`,t),()=>window.removeEventListener(`message`,t)},[e,p]),p}function x0e(){let{id:e}=ir(),t=$n(),n=no(),{t:r}=U(),{showToast:i}=Zd(),a=!!e,[o,s]=(0,f.useState)(``),[c,l]=(0,f.useState)(``),[u,d]=(0,f.useState)([]),[p,m]=(0,f.useState)(``),[h,g]=(0,f.useState)(!1),{data:_,isLoading:v}=K({queryKey:[`group`,e],queryFn:()=>Z.getGroup(Number(e)),enabled:a}),{data:y,isLoading:b}=K({queryKey:[`permissions`],queryFn:()=>Z.getPermissions()});a&&_&&!h&&(s(_.name),l(_.description||``),d(_.permissions),g(!0));let x=q({mutationFn:e=>Z.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=q({mutationFn:t=>Z.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===_?.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{y&&d(y.all_permissions)},A=()=>{d([])},j=p.toLowerCase(),M=(0,f.useMemo)(()=>y?j?y.categories.map(e=>({...e,permissions:e.permissions.filter(e=>e.label.toLowerCase().includes(j))})).filter(e=>e.permissions.length>0):y.categories:[],[y,j]),N=y?.all_permissions.length??0;return v||b?(0,G.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,G.jsx)(Y,{className:`w-8 h-8 text-bambu-green animate-spin`})}):(0,G.jsxs)(`div`,{className:`space-y-6 max-w-5xl mx-auto`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.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,G.jsx)(jo,{className:`w-5 h-5`})}),(0,G.jsx)(`h1`,{className:`text-xl font-bold text-white`,children:r(a?`groups.editor.title`:`groups.editor.createTitle`)})]}),a&&_?.is_system&&(0,G.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,G.jsx)(Lu,{className:`w-4 h-4 shrink-0`}),r(`groups.form.systemGroupWarning`)]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:r(`groups.form.groupName`)}),(0,G.jsx)(`input`,{type:`text`,value:o,onChange:e=>s(e.target.value),disabled:a&&_?.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,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:r(`groups.form.description`)}),(0,G.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,G.jsxs)(`div`,{className:`flex items-center justify-between flex-wrap gap-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[r(`groups.editor.permissionsSelected`,{count:u.length}),` / `,N]}),(0,G.jsx)(Q,{size:`sm`,variant:`ghost`,onClick:k,children:r(`groups.editor.selectAll`)}),(0,G.jsx)(Q,{size:`sm`,variant:`ghost`,onClick:A,children:r(`groups.editor.clearAll`)})]}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(Yl,{className:`w-4 h-4 absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray`}),(0,G.jsx)(`input`,{type:`text`,value:p,onChange:e=>m(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,G.jsx)(`div`,{className:`text-center py-12 text-bambu-gray`,children:r(`groups.editor.noResults`)}):(0,G.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:M.map(e=>{let t=y.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,G.jsxs)(Ud,{children:[(0,G.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,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.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,G.jsx)(as,{className:`w-3 h-3 text-white`}),o&&!a&&(0,G.jsx)(dl,{className:`w-3 h-3 text-white`})]}),(0,G.jsx)(iu,{className:`w-4 h-4 text-bambu-gray shrink-0`}),(0,G.jsx)(`span`,{className:`text-white font-medium text-sm`,children:e.name})]}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray tabular-nums`,children:[n,`/`,i]})]}),(0,G.jsx)(`div`,{className:`p-3 space-y-1`,children:e.permissions.map(e=>(0,G.jsxs)(`label`,{className:`flex items-center gap-3 px-2 py-1.5 rounded hover:bg-bambu-dark-secondary cursor-pointer`,children:[(0,G.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,G.jsxs)(`span`,{className:`flex flex-col`,children:[(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.label}),e.value===`websocket:connect`&&(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray/60`,children:r(`groups.editor.websocketHint`)})]})]},e.value))})]},e.name)})}),(0,G.jsx)(`div`,{className:`h-16`}),(0,G.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,G.jsx)(Q,{variant:`secondary`,onClick:()=>t(`/settings?tab=users`),children:r(`common.cancel`)}),(0,G.jsx)(Q,{onClick:w,disabled:C||!o.trim(),children:C?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),r(`common.saving`)]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Wl,{className:`w-4 h-4`}),r(`common.save`)]})})]})]})}var S0e=1.65,C0e=[`#1DB954`,`#3B82F6`,`#F59E0B`,`#EF4444`,`#8B5CF6`];function i9(e,t,n,r){return`${e}||${t??``}||${n??``}||${r??``}`}function a9(e,t){let n=new Date(e);return n.setDate(n.getDate()+Math.round(t)),n}function o9(e){return e.toLocaleDateString(void 0,{month:`short`,day:`numeric`,year:`numeric`})}function s9(e){return e.toLocaleDateString(void 0,{month:`short`,day:`numeric`})}function w0e(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 T0e(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 nZ.getAllUsageHistory(5e3),staleTime:6e4,enabled:o}),{data:O=[]}=K({queryKey:[`shopping-list`],queryFn:Z.getShoppingList,staleTime:3e4,enabled:o}),k=T?.forecast_global_lead_time_days??0,A=(0,f.useMemo)(()=>{let e=new Map;for(let t of E)e.set(i9(t.material,t.subtype,t.brand,t.color_name),t);return e},[E]),j=(0,f.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,f.useMemo)(()=>{let t=new Map;for(let n of e){if(n.archived_at)continue;let e=i9(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,f.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(i9(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=w0e(u);if(m!==null)d=m.rate,f=m.stdDev,p=`history`;else{let e=T0e(t.spools);e!==null&&(d=e,p=`delta`)}let h=S0e*(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:a9(e,_),y=d&&d>0?Math.floor((s-g)/d):null,b=y===null?null:a9(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,f.useMemo)(()=>[...new Set(M.map(e=>e.material))].sort(),[M]),F=(0,f.useMemo)(()=>[...new Set(M.map(e=>e.brand).filter(Boolean))].sort(),[M]),I=(0,f.useMemo)(()=>{let e=[...N];return h&&(e=e.filter(e=>e.group.material===h)),_&&(e=e.filter(e=>e.group.brand===_)),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 p===`asc`?i:-i}),e},[N,u,p,h,_]),L=(0,f.useMemo)(()=>N.filter(e=>!e.settings?.alerts_snoozed&&(e.stockBreakAlert||e.reorderAlert)),[N]),R=(0,f.useMemo)(()=>[...N].filter(e=>e.dailyRateG!==null).sort((e,t)=>t.totalUsedG-e.totalUsedG).slice(0,5),[N]);if(!o)return(0,G.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-16 text-bambu-gray gap-3`,children:[(0,G.jsx)(Qc,{className:`w-8 h-8 opacity-40`}),(0,G.jsx)(`p`,{className:`text-sm`,children:r(`forecast.noReadAccess`)})]});function z(e){u===e?m(e=>e===`asc`?`desc`:`asc`):(d(e),m(e===`days_left`?`asc`:`desc`))}let B=O.length>0?O.length:null;return(0,G.jsxs)(`div`,{className:`space-y-5`,children:[(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[L.length>0&&(0,G.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,G.jsx)(Lu,{className:`w-4 h-4`}),r(`forecast.alertCount`,{count:L.length}),c?(0,G.jsx)(us,{className:`w-3.5 h-3.5`}):(0,G.jsx)(ss,{className:`w-3.5 h-3.5`})]}),s&&(0,G.jsx)(j0e,{value:k,onSave:e=>{Z.updateSettings({forecast_global_lead_time_days:e}).then(()=>{t.invalidateQueries({queryKey:[`settings`]}),n(r(`forecast.globalLeadTimeSaved`),`success`)})}}),(0,G.jsxs)(`select`,{value:h,onChange:e=>g(e.target.value),className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${h?`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,G.jsx)(`option`,{value:``,children:r(`inventory.material`)}),P.map(e=>(0,G.jsx)(`option`,{value:e,children:e},e))]}),(0,G.jsxs)(`select`,{value:_,onChange:e=>v(e.target.value),className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${_?`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,G.jsx)(`option`,{value:``,children:r(`inventory.brand`)}),F.map(e=>(0,G.jsx)(`option`,{value:e,children:e},e))]}),(0,G.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,G.jsx)(au,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:r(`forecast.shoppingList`)}),B&&(0,G.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,G.jsx)(`div`,{className:`space-y-2`,children:L.map(e=>(0,G.jsx)(O0e,{forecast:e,onCart:()=>b(e)},e.group.key))}),x&&(0,G.jsx)(I0e,{items:O,forecasts:N,globalLeadTime:k,canWrite:s,onClose:()=>S(!1),onRemove:e=>{Z.removeFromShoppingList(e).then(()=>t.invalidateQueries({queryKey:[`shopping-list`]})).catch(()=>n(r(`forecast.failedSaveSettings`),`error`))},onClear:()=>{Z.clearShoppingList().then(()=>t.invalidateQueries({queryKey:[`shopping-list`]})).catch(()=>n(r(`forecast.failedSaveSettings`),`error`))}}),R.length>0&&(0,G.jsx)(A0e,{forecasts:R,days:C,onDaysChange:w}),N.length===0?(0,G.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-16 text-bambu-gray`,children:[(0,G.jsx)(Fu,{className:`w-10 h-10 mb-3 opacity-40`}),(0,G.jsx)(`p`,{className:`text-sm`,children:r(`forecast.noSpools`)})]}):(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg overflow-hidden border border-bambu-dark-tertiary`,children:[(0,G.jsx)(`div`,{className:`overflow-x-auto`,children:(0,G.jsxs)(`table`,{className:`w-full`,children:[(0,G.jsx)(`thead`,{children:(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary bg-bambu-dark-tertiary/30`,children:[(0,G.jsx)(`th`,{className:`w-8 px-4 py-3`}),(0,G.jsx)(c9,{col:`material`,active:u,dir:p,onSort:z,children:r(`forecast.sku`)}),(0,G.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:r(`locations.spools`)}),(0,G.jsx)(c9,{col:`stock`,active:u,dir:p,onSort:z,children:r(`forecast.stock`)}),(0,G.jsx)(c9,{col:`used`,active:u,dir:p,onSort:z,children:r(`forecast.dailyRate`)}),(0,G.jsx)(c9,{col:`days_left`,active:u,dir:p,onSort:z,children:r(`forecast.daysLeft`)}),(0,G.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:r(`forecast.emptyBy`)}),(0,G.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:r(`forecast.reorderBy`)}),(0,G.jsx)(`th`,{className:`w-24 px-4 py-3`})]})}),(0,G.jsx)(`tbody`,{className:`divide-y divide-bambu-dark-tertiary`,children:I.map(e=>(0,G.jsx)(M0e,{forecast:e,globalLeadTime:k,canWrite:s,onSaved:()=>t.invalidateQueries({queryKey:[`sku-settings`]}),onCart:()=>b(e),showToast:n},e.group.key))})]})}),(0,G.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,G.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,G.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-bambu-green inline-block`}),r(`forecast.trendLegend`)]}),(0,G.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,G.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-blue-400 inline-block`}),r(`forecast.estimatedLegend`)]}),(0,G.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,G.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-bambu-gray/40 inline-block`}),r(`forecast.noDataLegend`)]})]})]}),y&&(0,G.jsx)(R0e,{forecast:y,onClose:()=>b(null),onAdd:e=>{Z.addToShoppingList(e).then(()=>{t.invalidateQueries({queryKey:[`shopping-list`]}),n(r(`forecast.addedToCart`),`success`),b(null),S(!0)}).catch(()=>n(r(`forecast.failedAddItem`),`error`))}})]})}function c9({col:e,active:t,dir:n,onSort:r,children:i}){return(0,G.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,G.jsxs)(`span`,{className:`inline-flex items-center`,children:[i,t===e?n===`asc`?(0,G.jsx)(Io,{className:`w-3 h-3 ml-1 text-bambu-green`}):(0,G.jsx)(Ao,{className:`w-3 h-3 ml-1 text-bambu-green`}):(0,G.jsx)(Po,{className:`w-3 h-3 ml-1 opacity-40`})]})})}function O0e({forecast:e,onCart:t}){let{t:n}=U(),r=[e.group.brand,e.group.material,e.group.subtype,e.group.colorName].filter(Boolean).join(` `),i=e.stockBreakAlert;return(0,G.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,G.jsx)(Lu,{className:`w-4 h-4 flex-shrink-0`}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`span`,{className:`font-medium`,children:r}),i?(0,G.jsxs)(`span`,{className:`ml-2 text-xs opacity-80`,children:[n(`forecast.stockBreakRisk`),` — `,n(`forecast.stockBreakDetail`,{days:e.daysRemaining,lt:e.effectiveLeadTimeDays})]}):(0,G.jsxs)(`span`,{className:`ml-2 text-xs opacity-80`,children:[n(`forecast.reorderNow`),` — `,n(`forecast.reorderTriggerPassed`,{date:e.reorderTriggerDate?o9(e.reorderTriggerDate):`—`})]})]}),(0,G.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,G.jsx)(au,{className:`w-3 h-3`}),` `,n(`forecast.order`)]})]})}var k0e=[{label:`1W`,value:7},{label:`1M`,value:30},{label:`6M`,value:180}];function A0e({forecasts:e,days:t,onDaysChange:n}){let{t:r}=U(),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:C0e[n%C0e.length],rop:e.reorderPointG,points:E0e(e,t)})),o=i.map(e=>{let t={day:e,label:s9(a9(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,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg overflow-hidden border border-bambu-dark-tertiary p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-4`,children:[(0,G.jsx)(Fu,{className:`w-4 h-4 text-bambu-green`}),(0,G.jsx)(`h3`,{className:`text-sm font-semibold text-white`,children:r(`forecast.chartTitle`)}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray ml-1 hidden sm:inline`,children:r(`forecast.dashedLinesROP`)}),(0,G.jsx)(`div`,{className:`ml-auto flex items-center bg-bambu-dark-tertiary rounded-lg p-0.5`,children:k0e.map(e=>(0,G.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,G.jsx)(KA,{width:`100%`,height:220,children:(0,G.jsxs)(BH,{data:c,margin:{top:4,right:8,bottom:0,left:0},children:[(0,G.jsx)(`defs`,{children:a.map(e=>(0,G.jsxs)(`linearGradient`,{id:`grad-${e.key}`,x1:`0`,y1:`0`,x2:`0`,y2:`1`,children:[(0,G.jsx)(`stop`,{offset:`5%`,stopColor:e.color,stopOpacity:.25}),(0,G.jsx)(`stop`,{offset:`95%`,stopColor:e.color,stopOpacity:.02})]},e.key))}),(0,G.jsx)(aV,{strokeDasharray:`3 3`,stroke:`#374151`,strokeOpacity:.5}),(0,G.jsx)(XV,{dataKey:`label`,tick:{fill:`#6B7280`,fontSize:10},interval:Math.max(0,Math.ceil(s/8)-1),axisLine:!1,tickLine:!1}),(0,G.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,G.jsx)(kz,{content:({label:e,payload:t})=>t?.length?(0,G.jsxs)(`div`,{style:{background:`#1a1a2e`,border:`1px solid #374151`,borderRadius:8,fontSize:12,padding:`8px 12px`},children:[(0,G.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,G.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:6,color:`#E5E7EB`,marginBottom:2},children:[(0,G.jsx)(`span`,{style:{color:t?.color??`#9CA3AF`,fontSize:10},children:`●`}),(0,G.jsx)(`span`,{children:t?.label??String(e.dataKey)}),(0,G.jsxs)(`span`,{style:{color:`#9CA3AF`,marginLeft:4},children:[e.value,`g`]})]},String(e.dataKey)):null})]}):null}),(0,G.jsx)(Rj,{formatter:e=>(0,G.jsx)(`span`,{style:{color:`#9CA3AF`,fontSize:11},children:a.find(t=>t.key===e)?.label??e})}),a.map(e=>(0,G.jsx)(OV,{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,G.jsx)(JB,{y:e.rop,stroke:e.color,strokeDasharray:`4 3`,strokeOpacity:.6},`rop-${e.key}`))]})})]})}function j0e({value:e,onSave:t}){let{t:n}=U(),[r,i]=(0,f.useState)(!1),[a,o]=(0,f.useState)(String(e));function s(){let e=parseInt(a,10);isNaN(e)||e<0||(t(e),i(!1))}return(0,G.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,G.jsx)(Bc,{className:`w-3.5 h-3.5 flex-shrink-0`,"aria-label":n(`forecast.globalLeadTimeHint`)}),(0,G.jsxs)(`span`,{className:`hidden sm:inline`,children:[n(`forecast.globalLeadTime`),`:`]}),r?(0,G.jsxs)(`form`,{className:`flex items-center gap-1.5`,onSubmit:e=>{e.preventDefault(),s()},children:[(0,G.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,G.jsx)(`span`,{className:`text-bambu-gray`,children:`d`}),(0,G.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,G.jsx)(`button`,{type:`button`,onClick:()=>i(!1),className:`text-xs text-bambu-gray hover:text-white`,children:`✕`})]}):(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,G.jsxs)(`span`,{className:`font-semibold text-white`,children:[e,`d`]}),(0,G.jsx)(`button`,{onClick:()=>{o(String(e)),i(!0)},className:`p-0.5 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,G.jsx)(El,{className:`w-3 h-3`})})]})]})}function M0e({forecast:e,globalLeadTime:t,canWrite:n,onSaved:r,onCart:i,showToast:a}){let{t:o}=U(),[s,c]=(0,f.useState)(!1),[l,u]=(0,f.useState)(!1),[d,p]=(0,f.useState)(!1),[m,h]=(0,f.useState)(String(e.settings?.lead_time_days??0)),[g,_]=(0,f.useState)(String(e.settings?.safety_margin_value??14)),[v,y]=(0,f.useState)(e.settings?.safety_margin_unit??`days`);(0,f.useEffect)(()=>{l||h(String(e.settings?.lead_time_days??0))},[e.settings?.lead_time_days,l]),(0,f.useEffect)(()=>{d||(_(String(e.settings?.safety_margin_value??14)),y(e.settings?.safety_margin_unit??`days`))},[e.settings?.safety_margin_value,e.settings?.safety_margin_unit,d]);let b=q({mutationFn:Z.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?If(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,G.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,G.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-bambu-green`}),o(`forecast.trend`)]}):e.rateTier===`delta`?(0,G.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,G.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-blue-400`}),o(`forecast.estimated`)]}):(0,G.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,G.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-bambu-gray/40`}),o(`forecast.noData`)]});return(0,G.jsxs)(G.Fragment,{children:[(0,G.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,G.jsx)(`td`,{className:`px-4 py-3`,children:(0,G.jsx)(`span`,{className:`block w-5 h-5 rounded-full border border-black/20`,style:C})}),(0,G.jsx)(`td`,{className:`px-4 py-3`,children:(0,G.jsx)(`span`,{className:`text-sm text-white`,children:S})}),(0,G.jsx)(`td`,{className:`px-4 py-3`,children:(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.totalSpools})}),(0,G.jsx)(`td`,{className:`px-4 py-3 min-w-[140px]`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`div`,{className:`flex-1 h-2 bg-bambu-dark-tertiary rounded-full overflow-hidden`,children:(0,G.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,G.jsxs)(`span`,{className:`text-xs text-bambu-gray min-w-[40px] text-right`,children:[Math.round(e.totalRemainingG),`g`]})]})}),(0,G.jsx)(`td`,{className:`px-4 py-3`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 flex-wrap`,children:[(0,G.jsx)(`span`,{className:`text-sm text-white`,children:e.dailyRateG===null?`—`:`${e.dailyRateG.toFixed(1)}g/d`}),O]})}),(0,G.jsx)(`td`,{className:`px-4 py-3`,children:(0,G.jsx)(`span`,{className:`text-sm font-semibold ${T}`,children:e.daysRemaining===null?(0,G.jsx)(`span`,{className:`text-bambu-gray font-normal`,children:`—`}):`${e.daysRemaining}d`})}),(0,G.jsx)(`td`,{className:`px-4 py-3`,children:(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.projectedEmptyDate?o9(e.projectedEmptyDate):`—`})}),(0,G.jsx)(`td`,{className:`px-4 py-3`,children:(0,G.jsx)(`span`,{className:`text-sm ${!x&&e.reorderAlert?`text-yellow-700 dark:text-yellow-400`:`text-bambu-gray`}`,children:e.reorderTriggerDate?o9(e.reorderTriggerDate):`—`})}),(0,G.jsx)(`td`,{className:`px-4 py-3`,onClick:e=>e.stopPropagation(),children:(0,G.jsxs)(`div`,{className:`flex items-center justify-end gap-1`,children:[n&&(0,G.jsx)(`button`,{onClick:i,className:`p-1.5 text-bambu-gray hover:text-bambu-green rounded transition-colors`,title:o(`forecast.addToCart`),children:(0,G.jsx)(au,{className:`w-4 h-4`})}),!x&&(e.stockBreakAlert?(0,G.jsx)(Lu,{className:`w-4 h-4 text-red-600 dark:text-red-400`,"aria-label":o(`forecast.stockBreakRisk`)}):e.reorderAlert?(0,G.jsx)(Lu,{className:`w-4 h-4 text-yellow-600 dark:text-yellow-400`,"aria-label":o(`forecast.reorderNow`)}):e.daysRemaining===null?null:(0,G.jsx)(as,{className:`w-4 h-4 text-bambu-green/50`})),n&&(0,G.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,G.jsx)(Bo,{className:`w-3.5 h-3.5`})}),(0,G.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,G.jsx)(us,{className:`w-4 h-4`}):(0,G.jsx)(ss,{className:`w-4 h-4`})})]})})]}),s&&(0,G.jsx)(`tr`,{className:`bg-bambu-dark-tertiary/10`,children:(0,G.jsx)(`td`,{colSpan:9,className:`px-6 py-4`,children:(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{className:`grid gap-2 ${n?`grid-cols-2 sm:grid-cols-4`:`grid-cols-2`}`,children:[(0,G.jsx)(N0e,{label:o(`forecast.effectiveLeadTime`),value:`${e.effectiveLeadTimeDays}d`,hint:o(`forecast.effectiveLeadTimeHint`,{global:t,sku:e.settings?.lead_time_days??0})}),(0,G.jsx)(N0e,{label:o(`forecast.reorderPoint`),value:`${Math.round(e.reorderPointG)}g`,hint:o(`forecast.reorderPointHint`)}),n&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(P0e,{label:o(`forecast.skuLeadTimeOverride`),hint:o(`forecast.skuLeadTimeHint`),unit:o(`forecast.leadTime`),editing:l,value:e.settings?.lead_time_days??0,inputValue:m,onInputChange:h,onEdit:()=>{h(String(e.settings?.lead_time_days??0)),u(!0)},onSave:()=>{let t=parseInt(m,10);!isNaN(t)&&t>=0&&(E(t,e.settings?.safety_margin_value??14,v),u(!1))},onCancel:()=>u(!1),isPending:b.isPending,saveLabel:o(`forecast.save`),cancelLabel:o(`forecast.cancel`)}),(0,G.jsx)(F0e,{value:e.settings?.safety_margin_value??14,unit:v,editing:d,inputValue:g,dailyRateG:e.dailyRateG,onInputChange:_,onUnitChange:e=>y(e),onEdit:()=>{_(String(e.settings?.safety_margin_value??14)),y(e.settings?.safety_margin_unit??`days`),p(!0)},onSave:()=>{let t=parseInt(g,10);!isNaN(t)&&t>=0&&(E(e.settings?.lead_time_days??0,t,v),p(!1))},onCancel:()=>p(!1),isPending:b.isPending,saveLabel:o(`forecast.save`),cancelLabel:o(`forecast.cancel`),safetyMarginLabel:o(`forecast.safetyMarginLabel`)})]})]}),e.group.spools.length>1&&(0,G.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary pt-3`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:o(`forecast.individualSpools`)}),(0,G.jsx)(`div`,{className:`bg-bambu-dark-secondary rounded-lg overflow-hidden border border-bambu-dark-tertiary`,children:(0,G.jsxs)(`table`,{className:`w-full`,children:[(0,G.jsx)(`thead`,{children:(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary bg-bambu-dark-tertiary/30`,children:[(0,G.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:`#`}),(0,G.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:o(`inventory.remaining`)}),(0,G.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:o(`inventory.used`)}),(0,G.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:o(`forecast.labelWeight`)})]})}),(0,G.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,G.jsxs)(`tr`,{className:`hover:bg-bambu-dark-tertiary/30 transition-colors`,children:[(0,G.jsx)(`td`,{className:`px-4 py-2`,children:(0,G.jsxs)(`span`,{className:`text-xs font-mono text-bambu-gray/70`,children:[`#`,e.id]})}),(0,G.jsx)(`td`,{className:`px-4 py-2`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`w-24 h-1.5 bg-bambu-dark-tertiary rounded-full overflow-hidden flex-shrink-0`,children:(0,G.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,G.jsxs)(`span`,{className:`text-sm text-white`,children:[Math.round(t),`g`]})]})}),(0,G.jsx)(`td`,{className:`px-4 py-2`,children:(0,G.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[Math.round(Math.max(0,e.weight_used-(e.weight_used_baseline??0))),`g`]})}),(0,G.jsx)(`td`,{className:`px-4 py-2`,children:(0,G.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[e.label_weight,`g`]})})]},e.id)})})]})})]})]})})})]})}function N0e({label:e,value:t,hint:n}){return(0,G.jsxs)(`div`,{className:`bg-bambu-dark-tertiary/40 rounded-lg p-3`,title:n,children:[(0,G.jsx)(`div`,{className:`text-xs font-medium text-white mb-1`,children:e}),(0,G.jsx)(`div`,{className:`text-lg font-semibold text-white`,children:t})]})}function P0e({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,G.jsxs)(`div`,{className:`bg-bambu-dark-tertiary/40 rounded-lg p-3 space-y-1`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,G.jsx)(`span`,{className:`text-xs font-medium text-white`,children:e}),(0,G.jsx)(`span`,{title:t,children:(0,G.jsx)(Bc,{className:`w-3 h-3 text-bambu-gray/50`})})]}),r?(0,G.jsxs)(`form`,{className:`flex items-center gap-2`,onSubmit:e=>{e.preventDefault(),c()},children:[(0,G.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,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:n}),(0,G.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,G.jsx)(`button`,{type:`button`,onClick:l,disabled:u,className:`px-2 py-1 text-xs text-bambu-gray hover:text-white`,children:f})]}):(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-lg font-semibold text-white`,children:i}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:n}),(0,G.jsx)(`button`,{onClick:s,className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,G.jsx)(El,{className:`w-3 h-3`})})]})]})}function F0e({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}=U(),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,G.jsxs)(`div`,{className:`bg-bambu-dark-tertiary/40 rounded-lg p-3 space-y-1`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,G.jsx)(`span`,{className:`text-xs font-medium text-white`,children:p}),(0,G.jsx)(`span`,{title:g,children:(0,G.jsx)(Bc,{className:`w-3 h-3 text-bambu-gray/50`})})]}),n?(0,G.jsxs)(`form`,{className:`flex items-center gap-2 flex-wrap`,onSubmit:e=>{e.preventDefault(),c()},children:[(0,G.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,G.jsxs)(`div`,{className:`flex bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded overflow-hidden text-xs`,children:[(0,G.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,G.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,G.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,G.jsx)(`button`,{type:`button`,onClick:l,disabled:u,className:`px-2 py-1 text-xs text-bambu-gray hover:text-white`,children:f})]}):(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-lg font-semibold text-white`,children:e}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:t}),h!==null&&t===`days`&&(0,G.jsxs)(`span`,{className:`text-lg font-semibold text-white`,children:[`≈ `,h,`g`]}),t===`g`&&i!==null&&(0,G.jsxs)(`span`,{className:`text-lg font-semibold text-white`,children:[`≈ `,Math.round(e/i),`d`]}),(0,G.jsx)(`button`,{onClick:s,className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,G.jsx)(El,{className:`w-3 h-3`})})]})]})}function I0e({items:e,forecasts:t,globalLeadTime:n,canWrite:r,onClose:i,onRemove:a,onClear:o}){let{t:s}=U(),c=no(),[l,u]=(0,f.useState)(`list`),d=q({mutationFn:async({id:e,status:t,item:n,avgSpoolG:r})=>{if(await Z.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,material_number:null};await Z.bulkCreateSpools(i,n.quantity_spools),await Z.removeFromShoppingList(e)}},onSuccess:()=>{c.invalidateQueries({queryKey:[`shopping-list`]}),c.invalidateQueries({queryKey:[`spools`]})}}),p=(0,f.useMemo)(()=>{let e=new Map;for(let n of t)e.set(n.group.key,n);return e},[t]),m=(0,f.useMemo)(()=>e.map(e=>({item:e,forecast:p.get(i9(e.material,e.subtype,e.brand,e.color_name))??null})),[e,p]),h=(0,f.useMemo)(()=>m.filter(({forecast:e})=>!e||e.dailyRateG===null?!1:e.stockBreakAlert||e.daysRemaining!==null&&e.daysRemaining<=e.effectiveLeadTimeDays),[m]);function g(){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=p.get(i9(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?o9(a9(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,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg overflow-hidden border border-bambu-dark-tertiary`,children:[(0,G.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,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(au,{className:`w-4 h-4 text-bambu-green`}),(0,G.jsx)(`h3`,{className:`text-sm font-semibold text-white`,children:s(`forecast.shoppingList`)}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:s(`forecast.shoppingListItems`,{count:e.length})}),e.length>0&&(0,G.jsxs)(`div`,{className:`flex bg-bambu-dark-tertiary rounded-md p-0.5 ml-1`,children:[(0,G.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,G.jsx)(bl,{className:`w-3 h-3`}),s(`forecast.listView`)]}),(0,G.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,G.jsx)(rs,{className:`w-3 h-3`}),s(`forecast.logisticsView`),h.length>0&&(0,G.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:h.length})]})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.length>0&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`button`,{onClick:g,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,G.jsx)(Gs,{className:`w-3 h-3`}),s(`forecast.downloadCsv`)]}),r&&(0,G.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,G.jsx)(`button`,{onClick:i,className:`p-1 text-bambu-gray hover:text-white transition-colors`,children:(0,G.jsx)(nd,{className:`w-4 h-4`})})]})]}),e.length===0?(0,G.jsxs)(`div`,{className:`flex flex-col items-center py-8 text-bambu-gray`,children:[(0,G.jsx)(bl,{className:`w-8 h-8 mb-2 opacity-30`}),(0,G.jsx)(`p`,{className:`text-sm`,children:s(`forecast.shoppingListEmpty`)})]}):l===`list`?(0,G.jsx)(`div`,{className:`overflow-x-auto`,children:(0,G.jsxs)(`table`,{className:`w-full`,children:[(0,G.jsx)(`thead`,{children:(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary bg-bambu-dark-tertiary/20`,children:[(0,G.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:s(`forecast.qty`)}),(0,G.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:s(`forecast.material`)}),(0,G.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:s(`forecast.weight`)}),(0,G.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:s(`forecast.leadTime`)}),(0,G.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:s(`forecast.expectedRestock`)}),(0,G.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:s(`forecast.status`)}),(0,G.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:s(`forecast.note`)}),(0,G.jsx)(`th`,{className:`px-4 py-2 text-right text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:s(`forecast.actions`)})]})}),(0,G.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=h.some(t=>t.item.id===e.id),o=p.get(i9(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,f=u>0?a9(new Date,u):null,m=e.status===`purchased`||e.status===`received`,g=e.status===`received`,_=d.isPending;return(0,G.jsxs)(`tr`,{className:`hover:bg-bambu-dark-tertiary/30 transition-colors ${i&&!m?`bg-red-500/5`:``}`,children:[(0,G.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,G.jsxs)(`span`,{className:`text-sm font-semibold text-bambu-green`,children:[e.quantity_spools,`×`]})}),(0,G.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-sm text-white`,children:t}),i&&!m&&(0,G.jsx)(Lu,{className:`w-3.5 h-3.5 text-red-600 dark:text-red-400 flex-shrink-0`,"aria-label":s(`forecast.stockBreakBefore`)})]})}),(0,G.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,G.jsx)(`span`,{className:`text-sm text-white`,children:l>=1e3?`${(l/1e3).toFixed(1)}kg`:`${l}g`})}),(0,G.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:u>0?`${u}d`:`—`})}),(0,G.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:f?o9(f):`—`})}),(0,G.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,G.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`:m?`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`:m?`forecast.purchased`:`forecast.pending`)})}),(0,G.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:e.note||`—`})}),(0,G.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,G.jsx)(`div`,{className:`flex items-center justify-end gap-1`,children:r&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`button`,{onClick:()=>d.mutate({id:e.id,status:m?`pending`:`purchased`}),disabled:_||g,title:s(m?`forecast.resetToPending`:`forecast.markPurchased`),className:`p-1.5 rounded transition-colors disabled:opacity-30 ${m?`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:m?(0,G.jsx)(Vl,{className:`w-4 h-4`}):(0,G.jsx)(Rs,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:()=>d.mutate({id:e.id,status:`received`,item:e,avgSpoolG:c}),disabled:_||!m||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,G.jsx)(vl,{className:`w-4 h-4`})}),(0,G.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,G.jsx)(Pu,{className:`w-3.5 h-3.5`})})]})})})]},e.id)})})]})}):(0,G.jsx)(`div`,{className:`divide-y divide-bambu-dark-tertiary`,children:m.filter(({item:e})=>e.status!==`received`).map(({item:e,forecast:t})=>(0,G.jsx)(L0e,{item:e,forecast:t,globalLeadTime:n,canWrite:r,onRemove:()=>a(e.id)},e.id))})]})}function L0e({item:e,forecast:t,globalLeadTime:n,canWrite:r,onRemove:i}){let{t:a}=U(),o=[e.brand,e.material,e.subtype,e.color_name].filter(Boolean).join(` `),s=(0,f.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=s9(a9(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,G.jsx)(kz,{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,G.jsx)(OV,{type:`linear`,dataKey:`stock`,stroke:`#1DB954`,strokeWidth:2,fill:`url(#cart-post-${e.id})`,dot:!1,activeDot:{r:3}}),t.reorderPointG>0&&(0,G.jsx)(JB,{y:t.reorderPointG,stroke:`#F59E0B`,strokeDasharray:`5 3`,strokeOpacity:.8,label:{value:`ROP`,position:`insideTopRight`,fill:`#F59E0B`,fontSize:9}}),t.safetyStockG>0&&(0,G.jsx)(JB,{y:t.safetyStockG,stroke:`#6B7280`,strokeDasharray:`3 3`,strokeOpacity:.6,label:{value:`SS`,position:`insideTopRight`,fill:`#6B7280`,fontSize:9}}),(0,G.jsx)(JB,{x:s9(a9(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,G.jsx)(JB,{x:s9(a9(new Date,c)),stroke:`#EF4444`,strokeWidth:1.5,strokeOpacity:.9,label:{value:`OUT`,position:`insideTopLeft`,fill:`#EF4444`,fontSize:9}})]})}),(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 mt-2 text-[10px] text-bambu-gray`,children:[(0,G.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(`span`,{className:`inline-block w-4 border-t-2 border-yellow-400 border-dashed`}),` `,a(`forecast.ropLabel`)]}),(0,G.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(`span`,{className:`inline-block w-4 border-t border-bambu-gray border-dashed`}),` `,a(`forecast.safetyStockLegend`)]}),(0,G.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(`span`,{className:`inline-block w-4 border-t-2 border-blue-400 border-dashed`}),` `,a(`forecast.stockArrivalLegend`)]}),l&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-red-700 dark:text-red-400`,children:[(0,G.jsx)(`span`,{className:`inline-block w-4 border-t-2 border-red-400`}),` `,a(`forecast.stockoutLegend`)]})]})]}):null]})}function R0e({forecast:e,onClose:t,onAdd:n}){let{t:r}=U(),i=[e.group.brand,e.group.material,e.group.subtype,e.group.colorName].filter(Boolean).join(` `),[a,o]=(0,f.useState)(`qty`),[s,c]=(0,f.useState)(`1`),[l,u]=(0,f.useState)(`30`),[d,p]=(0,f.useState)(``),m=(0,f.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]),h=a===`qty`?parseInt(s,10)||1:m??1;function g(t){t.preventDefault(),n({material:e.group.material,subtype:e.group.subtype,brand:e.group.brand,color_name:e.group.colorName,quantity_spools:h,note:d||null})}return(0,G.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm p-4`,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-2xl border border-bambu-dark-tertiary w-full max-w-sm shadow-2xl`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-5 pt-5 pb-4 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(au,{className:`w-5 h-5 text-bambu-green`}),(0,G.jsx)(`h2`,{className:`text-base font-semibold text-white`,children:r(`forecast.addToCartTitle`)})]}),(0,G.jsx)(`button`,{onClick:t,className:`p-1 text-bambu-gray hover:text-white transition-colors`,children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]}),(0,G.jsxs)(`form`,{onSubmit:g,className:`p-5 space-y-4`,children:[(0,G.jsx)(`div`,{className:`text-sm text-bambu-gray`,children:i}),(0,G.jsxs)(`div`,{className:`flex bg-bambu-dark-tertiary rounded-lg p-0.5`,children:[(0,G.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,G.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,G.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,G.jsx)(`label`,{className:`text-xs text-bambu-gray`,children:r(`forecast.numberOfSpools`)}),(0,G.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,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,G.jsx)(`label`,{className:`text-xs text-bambu-gray`,children:r(`forecast.lastHowManyDays`)}),(0,G.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,G.jsx)(`div`,{className:`text-xs text-yellow-700 dark:text-yellow-400 px-1`,children:r(`forecast.noUsageQty`)}):(0,G.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2 bg-bambu-dark-tertiary/50 rounded-lg`,children:[(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:`≈`}),(0,G.jsx)(`span`,{className:`text-sm font-semibold text-bambu-green`,children:r(`forecast.spoolCount`,{count:m??0})}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[`at `,e.dailyRateG.toFixed(1),`g/day`]})]})]}),(0,G.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,G.jsx)(`label`,{className:`text-xs text-bambu-gray`,children:r(`forecast.noteOptional`)}),(0,G.jsx)(`input`,{type:`text`,maxLength:200,value:d,onChange:e=>p(e.target.value),placeholder:r(`forecast.notePlaceholder`),className:`w-full px-3 py-2 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/40 focus:outline-none focus:border-bambu-green`})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-3 pt-1`,children:[(0,G.jsx)(`button`,{type:`submit`,className:`flex-1 py-2 bg-bambu-green text-white text-sm font-medium rounded-lg hover:bg-bambu-green/80 transition-colors`,children:r(`forecast.addNSpools`,{count:h})}),(0,G.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 l9={material:``,subtype:``,brand:``,color_name:``,rgba:`808080FF`,extra_colors:``,effect_type:``,label_weight:1e3,core_weight:250,core_weight_catalog_id:null,weight_used:0,slicer_filament:``,note:``,cost_per_kg:null,category:``,low_stock_threshold_pct:null,material_number:``,location_id:null,spoolman_filament_id:null},z0e=new Set([`material`,`subtype`,`brand`,`rgba`,`color_name`,`label_weight`]);function B0e(e,t=!1,n=!1,r=`create`){let i={};return t||n||r!==`create`?(!e.material&&!e.spoolman_filament_id&&(i.material=`Material is required`),{isValid:Object.keys(i).length===0,errors:i}):(e.slicer_filament||(i.slicer_filament=`Slicer preset is required`),e.material||(i.material=`Material is required`),e.brand||(i.brand=`Brand is required`),e.subtype||(i.subtype=`Subtype is required`),{isValid:Object.keys(i).length===0,errors:i})}var V0e={local:`bg-green-100 dark:bg-green-500/20 text-green-700 dark:text-green-400`,orca_cloud:`bg-purple-100 dark:bg-purple-500/20 text-purple-700 dark:text-purple-400`,cloud:`bg-bambu-blue/20 text-bambu-blue`,builtin:`bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-400`};function u9({source:e}){let{t}=U(),n={local:t(`profiles.localProfiles.badge`),orca_cloud:t(`configureAmsSlot.orcaCloud`),cloud:t(`configureAmsSlot.bambuCloud`),builtin:t(`configureAmsSlot.builtin`)}[e];return(0,G.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded whitespace-nowrap ${V0e[e]}`,children:n})}function H0e({value:e,options:t,inheritLabel:n,onChange:r,disabled:i=!1,ariaLabel:a}){let{t:o}=U(),[s,c]=(0,f.useState)(!1),[l,u]=(0,f.useState)(``),d=(0,f.useRef)(null),p=t.find(t=>t.code===e);(0,f.useEffect)(()=>{if(!s)return;let e=e=>{d.current&&!d.current.contains(e.target)&&c(!1)},t=e=>{e.key===`Escape`&&(e.stopPropagation(),c(!1))};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t,!0),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t,!0)}},[s]);let m=l.trim().toLowerCase(),h=m?t.filter(e=>e.displayName.toLowerCase().includes(m)):t,g=e=>{r(e),c(!1),u(``)};return(0,G.jsxs)(`div`,{className:`relative`,ref:d,children:[(0,G.jsxs)(`button`,{type:`button`,"aria-label":a,"aria-haspopup":`listbox`,"aria-expanded":s,disabled:i,onClick:()=>c(e=>!e),className:`w-full flex items-center gap-2 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-sm text-left focus:outline-none focus:border-bambu-green disabled:opacity-50`,children:[(0,G.jsx)(`span`,{className:`flex-1 min-w-0 truncate ${p?`text-white`:`text-bambu-gray italic`}`,children:p?p.displayName:n}),p&&(0,G.jsx)(u9,{source:p.source}),(0,G.jsx)(ss,{className:`w-3.5 h-3.5 text-bambu-gray shrink-0`})]}),s&&(0,G.jsxs)(`div`,{className:`absolute z-50 mt-1 w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl`,children:[(0,G.jsx)(`div`,{className:`p-2 border-b border-bambu-dark-tertiary`,children:(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(Yl,{className:`w-3.5 h-3.5 text-bambu-gray absolute left-2 top-1/2 -translate-y-1/2`}),(0,G.jsx)(`input`,{autoFocus:!0,type:`text`,value:l,onChange:e=>u(e.target.value),placeholder:o(`inventory.searchPresets`),className:`w-full pl-7 pr-7 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded-md text-sm text-white placeholder:text-bambu-gray/60 focus:outline-none focus:border-bambu-green`}),l&&(0,G.jsx)(`button`,{type:`button`,"aria-label":o(`common.clear`),onClick:()=>u(``),className:`absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white`,children:(0,G.jsx)(nd,{className:`w-3.5 h-3.5`})})]})}),(0,G.jsxs)(`div`,{className:`max-h-56 overflow-y-auto p-1`,role:`listbox`,"aria-label":a,children:[(0,G.jsx)(`button`,{type:`button`,role:`option`,"aria-selected":!p,onClick:()=>g(null),className:`w-full text-left px-2 py-1.5 rounded-md text-sm italic ${p?`text-bambu-gray hover:bg-bambu-dark`:`bg-bambu-green/15 text-bambu-green`}`,children:n}),h.length===0?(0,G.jsx)(`p`,{className:`px-2 py-2 text-sm text-bambu-gray`,children:o(`inventory.noResults`)}):h.map(t=>(0,G.jsxs)(`button`,{type:`button`,role:`option`,"aria-selected":t.code===e,onClick:()=>g(t),className:`w-full flex items-center gap-2 text-left px-2 py-1.5 rounded-md text-sm ${t.code===e?`bg-bambu-green/15 text-bambu-green`:`text-white hover:bg-bambu-dark`}`,children:[(0,G.jsx)(`span`,{className:`flex-1 min-w-0 truncate`,title:t.displayName,children:t.displayName}),(0,G.jsx)(u9,{source:t.source})]},t.code))]})]})]})}function U0e(e,t){if(t.length===0)return{top:[],rest:e};let n=new Set(t.map(e=>e.toLowerCase()));return{top:e.filter(e=>n.has(e.toLowerCase())),rest:e.filter(e=>!n.has(e.toLowerCase()))}}function d9({label:e}){return(0,G.jsx)(`div`,{className:`px-3 py-1 text-[11px] font-semibold uppercase tracking-wide text-bambu-gray/70 bg-bambu-dark-tertiary/40`,children:e})}function W0e({formData:e,updateField:t,cloudAuthenticated:n,loadingCloudPresets:r,presetInputValue:i,setPresetInputValue:a,selectedPresetOption:o,filamentOptions:s,availableBrands:c,availableMaterials:l,suggestedBrands:u,suggestedMaterials:d,quickAdd:p,detailsRequired:m,quantity:h,onQuantityChange:g,errors:_}){let{t:v}=U(),[y,b]=(0,f.useState)(!1),[x,S]=(0,f.useState)(!1),[C,w]=(0,f.useState)(!1),[T,E]=(0,f.useState)(!1),[D,O]=(0,f.useState)(``),[k,A]=(0,f.useState)(``),[j,M]=(0,f.useState)(``),[N,P]=(0,f.useState)(String(e.label_weight)),[F,I]=(0,f.useState)(!1),[L,R]=(0,f.useState)(new Set),z=(0,f.useRef)(null),B=(0,f.useRef)(null),V=(0,f.useRef)(null),ee=(0,f.useRef)(null);(0,f.useEffect)(()=>{let e=e=>{z.current&&!z.current.contains(e.target)&&b(!1),ee.current&&!ee.current.contains(e.target)&&E(!1),B.current&&!B.current.contains(e.target)&&S(!1),V.current&&!V.current.contains(e.target)&&w(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[]);let te=(0,f.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]),ne=(0,f.useMemo)(()=>{if(!D)return c;let e=D.toLowerCase();return c.filter(t=>t.toLowerCase().includes(e)).sort((t,n)=>{let r=t.toLowerCase()===e,i=n.toLowerCase()===e;return r&&!i?-1:!r&&i?1:t.localeCompare(n)})},[c,D]),re=(0,f.useMemo)(()=>{if(!k)return cU;let e=k.toLowerCase();return cU.filter(t=>t.toLowerCase().includes(e))},[k]),ie=(0,f.useMemo)(()=>{if(!j)return l;let e=j.toLowerCase();return l.filter(t=>t.toLowerCase().includes(e)).sort((t,n)=>{let r=t.toLowerCase()===e,i=n.toLowerCase()===e;return r&&!i?-1:!r&&i?1:t.localeCompare(n)})},[j,l]),ae=(0,f.useMemo)(()=>U0e(ne,u),[ne,u]),oe=(0,f.useMemo)(()=>U0e(ie,d),[ie,d]);(0,f.useEffect)(()=>{F||P(String(e.label_weight))},[e.label_weight,F]);let se=n=>{t(`slicer_filament`,n.code),a(n.displayName),b(!1);let r=mU(n.name),i=new Set,o=[[`material`,r.material],[`brand`,r.brand],[`subtype`,r.variant]];for(let[n,r]of o)r&&(e[n]&&!L.has(n)||(t(n,r),i.add(n)));R(i)},H=(e,n)=>{L.has(e)&&R(t=>{let n=new Set(t);return n.delete(e),n}),t(e,n)},ce=t=>(0,G.jsx)(`button`,{type:`button`,className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${e.brand===t?`bg-bambu-green/10 text-bambu-green`:`text-white`}`,onClick:()=>{H(`brand`,t),S(!1),O(``)},children:t},t),le=t=>(0,G.jsx)(`button`,{type:`button`,className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${e.material===t?`bg-bambu-green/10 text-bambu-green`:`text-white`}`,onClick:()=>{H(`material`,t),E(!1),M(``)},children:t},t);return(0,G.jsxs)(`div`,{className:`space-y-4`,children:[!p&&(0,G.jsx)(`div`,{className:`flex items-center gap-2 text-xs text-bambu-gray`,children:r?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-3 h-3 animate-spin`}),` `,v(`inventory.loadingPresets`)]}):n?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Os,{className:`w-3 h-3 text-bambu-green`}),` `,v(`inventory.cloudConnected`)]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Es,{className:`w-3 h-3`}),` `,v(`inventory.cloudNotConnected`)]})}),!p&&(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:[v(`inventory.slicerPreset`),m&&` *`]}),(0,G.jsxs)(`div`,{className:`relative`,ref:z,children:[(0,G.jsx)(Yl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50 pointer-events-none`}),(0,G.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:v(`inventory.searchPresets`),value:i,onChange:e=>{a(e.target.value),b(!0)},onFocus:()=>{b(!0),a(``)}}),y&&(0,G.jsx)(`div`,{className:`absolute z-50 w-full mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-64 overflow-y-auto`,children:te.length===0?(0,G.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:v(`inventory.noPresetsFound`)}):te.map(e=>(0,G.jsxs)(`button`,{type:`button`,className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary flex items-center gap-2 ${o?.code===e.code?`bg-bambu-green/10 text-bambu-green`:`text-white`}`,onClick:()=>se(e),children:[(0,G.jsx)(`span`,{className:`flex-1 min-w-0 truncate`,title:e.displayName,children:e.displayName}),(0,G.jsx)(u9,{source:e.source})]},`${e.code}::${e.name}`))})]}),o&&(0,G.jsxs)(`div`,{className:`mt-1 text-xs text-bambu-gray`,children:[v(`inventory.selectedPreset`),`: `,(0,G.jsx)(`span`,{className:`font-mono text-bambu-green`,children:o.code})]}),_?.slicer_filament&&(0,G.jsx)(`p`,{className:`mt-1 text-xs text-red-700 dark:text-red-400`,children:_.slicer_filament})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:[v(`inventory.material`),` *`]}),(0,G.jsxs)(`div`,{className:`relative`,ref:ee,children:[(0,G.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:v(`inventory.selectMaterial`),value:T?j:e.material,onChange:e=>{M(e.target.value),E(!0)},onFocus:()=>{E(!0),M(``)}}),(0,G.jsx)(ss,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50 pointer-events-none`}),T&&(0,G.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:[ie.length===0?(0,G.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:v(`inventory.noResults`)}):(0,G.jsxs)(G.Fragment,{children:[oe.top.length>0&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(d9,{label:v(`inventory.suggestedOptions`)}),oe.top.map(le)]}),oe.rest.length>0&&(0,G.jsxs)(G.Fragment,{children:[oe.top.length>0&&(0,G.jsx)(d9,{label:v(`inventory.allOptions`)}),oe.rest.map(le)]})]}),j&&!ie.includes(j)&&(0,G.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:()=>{H(`material`,j),E(!1),M(``)},children:v(`inventory.useCustomMaterial`,{material:j})})]})]}),_?.material&&(0,G.jsx)(`p`,{className:`mt-1 text-xs text-red-700 dark:text-red-400`,children:_.material})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:[v(`inventory.brand`),m&&` *`]}),(0,G.jsxs)(`div`,{className:`relative`,ref:B,children:[(0,G.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:v(`inventory.searchBrand`),value:x?D:e.brand,onChange:e=>{O(e.target.value),S(!0)},onFocus:()=>{S(!0),O(``)}}),(0,G.jsx)(ss,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50 pointer-events-none`}),x&&(0,G.jsxs)(`div`,{className:`absolute z-50 w-full mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-48 overflow-y-auto`,children:[ne.length===0?(0,G.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:v(`inventory.noResults`)}):(0,G.jsxs)(G.Fragment,{children:[ae.top.length>0&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(d9,{label:v(`inventory.suggestedOptions`)}),ae.top.map(ce)]}),ae.rest.length>0&&(0,G.jsxs)(G.Fragment,{children:[ae.top.length>0&&(0,G.jsx)(d9,{label:v(`inventory.allOptions`)}),ae.rest.map(ce)]})]}),D&&!ne.includes(D)&&(0,G.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:()=>{H(`brand`,D),S(!1),O(``)},children:v(`inventory.useCustomBrand`,{brand:D})})]})]}),_?.brand&&(0,G.jsx)(`p`,{className:`mt-1 text-xs text-red-700 dark:text-red-400`,children:_.brand})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:[v(`inventory.subtype`),m&&` *`]}),(0,G.jsxs)(`div`,{className:`relative`,ref:V,children:[(0,G.jsx)(`input`,{type:`text`,value:C?k:e.subtype,onChange:e=>{A(e.target.value),w(!0)},onFocus:()=>{w(!0),A(``)},placeholder:`Basic, Matte, Silk...`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`}),(0,G.jsx)(ss,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50 pointer-events-none`}),C&&(0,G.jsxs)(`div`,{className:`absolute z-50 w-full mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-48 overflow-y-auto`,children:[re.length===0?(0,G.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:v(`inventory.noResults`)}):re.map(t=>(0,G.jsx)(`button`,{type:`button`,className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${e.subtype===t?`bg-bambu-green/10 text-bambu-green`:`text-white`}`,onClick:()=>{H(`subtype`,t),w(!1),A(``)},children:t},t)),k&&!cU.some(e=>e.toLowerCase()===k.toLowerCase().trim())&&(0,G.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:()=>{H(`subtype`,k),w(!1),A(``)},children:v(`inventory.useCustomBrand`,{brand:k})})]})]}),_?.subtype&&(0,G.jsx)(`p`,{className:`mt-1 text-xs text-red-700 dark:text-red-400`,children:_.subtype})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:v(`inventory.labelWeight`)}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(`input`,{type:`number`,className:`w-full px-3 py-2 pr-7 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`,value:N,min:0,onFocus:()=>I(!0),onChange:e=>P(e.target.value),onBlur:()=>{I(!1);let n=N.trim(),r=Number(n);if(!n||!Number.isFinite(r)||r<0){P(String(e.label_weight));return}let i=Math.round(r);t(`label_weight`,i),P(String(i))}}),(0,G.jsx)(`span`,{className:`absolute right-2 top-1/2 -translate-y-1/2 text-xs text-bambu-gray`,children:`g`})]})]}),p&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:v(`inventory.quantity`)}),(0,G.jsx)(nm,{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:h,min:1,max:100,onChange:g,fallback:1})]})]})}function G0e(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 K0e({formData:e,updateField:t,recentColors:n,onColorUsed:r,catalogColors:i}){let{t:a}=U(),[o,s]=(0,f.useState)(!1),[c,l]=(0,f.useState)(``),u=(e.rgba.replace(`#`,``)+`FF`).substring(0,8).toUpperCase(),d=u.substring(0,6),p=u.substring(6,8)===`00`,[m,h]=(0,f.useState)(p?u:d);(0,f.useEffect)(()=>{h(p?u:d)},[d,u,p]);let g=e=>u===(e.replace(`#`,``)+`FF`).substring(0,8).toUpperCase(),_=e=>If(e),v=(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})},y=(0,f.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,f.useMemo)(()=>{if(!c)return y;if(y.length===0)return[];let e=c.toLowerCase();return y.filter(t=>t.name.toLowerCase().includes(e)||(t.manufacturer?.toLowerCase().includes(e)??!1)||(t.material?.toLowerCase().includes(e)??!1))},[c,y]),x=y.length>0,S=(0,f.useMemo)(()=>c?uU.filter(e=>e.name.toLowerCase().includes(c.toLowerCase())):o?uU:lU,[c,o]),[C,w]=(0,f.useState)(e.extra_colors),[T,E]=(0,f.useState)([]),D=(0,f.useRef)(e.extra_colors);(0,f.useEffect)(()=>{e.extra_colors!==D.current&&(w(e.extra_colors),E([]),D.current=e.extra_colors)},[e.extra_colors]);let O=(0,f.useMemo)(()=>Em({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}=G0e(e);E(r),D.current=n,t(`extra_colors`,n)};return(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsx)(`div`,{className:`h-10 rounded-lg border border-bambu-dark-tertiary`,style:O,"data-testid":`color-preview-banner`}),n.length>0&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 text-xs text-bambu-gray shrink-0`,children:[(0,G.jsx)(Ts,{className:`w-3 h-3`}),(0,G.jsx)(`span`,{children:a(`inventory.recentColors`)})]}),(0,G.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:n.map(e=>(0,G.jsx)(`button`,{type:`button`,onClick:()=>v(e.hex,e.name),className:`w-6 h-6 rounded border-2 transition-all hover:scale-110 ${g(e.hex)?`border-bambu-green ring-1 ring-bambu-green/30 scale-110`:`border-bambu-dark-tertiary`}`,style:_(e.hex),title:e.name},e.hex))})]}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(Yl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50 pointer-events-none`}),(0,G.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,G.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:c?a(`inventory.searchResults`):`${e.brand}${e.material?` ${e.material}`:``}`}),(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-1.5`,children:[b.map(e=>(0,G.jsx)(`button`,{type:`button`,onClick:()=>v(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 ${g(e.hex)?`border-bambu-green ring-1 ring-bambu-green/30 scale-110`:`border-bambu-dark-tertiary`}`,style:_(e.hex),title:e.manufacturer&&e.material?`${e.name} (${e.manufacturer} — ${e.material})`:e.manufacturer?`${e.name} (${e.manufacturer})`:e.name,children:(0,G.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,G.jsx)(`p`,{className:`text-sm text-bambu-gray py-1`,children:a(`inventory.noColorsFound`)})]})]}):(0,G.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between text-xs text-bambu-gray`,children:[(0,G.jsx)(`span`,{children:a(c?`inventory.searchResults`:o?`inventory.allColors`:`inventory.commonColors`)}),!c&&(0,G.jsx)(`button`,{type:`button`,onClick:()=>s(!o),className:`flex items-center gap-1 hover:text-white transition-colors`,children:o?(0,G.jsxs)(G.Fragment,{children:[a(`inventory.showLess`),` `,(0,G.jsx)(us,{className:`w-3 h-3`})]}):(0,G.jsxs)(G.Fragment,{children:[a(`inventory.showAll`),` `,(0,G.jsx)(ss,{className:`w-3 h-3`})]})})]}),(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-1.5`,children:[S.map(e=>(0,G.jsx)(`button`,{type:`button`,onClick:()=>v(e.hex,e.name),className:`w-6 h-6 rounded border-2 transition-all hover:scale-110 hover:z-20 relative group ${g(e.hex)?`border-bambu-green ring-1 ring-bambu-green/30 scale-110`:`border-bambu-dark-tertiary`}`,style:_(e.hex),title:e.name,children:(0,G.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,G.jsx)(`p`,{className:`text-sm text-bambu-gray py-1`,children:a(`inventory.noColorsFound`)})]})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:a(`inventory.colorName`)}),(0,G.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,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:a(`inventory.hexColor`)}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsxs)(`div`,{className:`relative flex-1`,children:[(0,G.jsx)(`span`,{className:`absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray`,children:`#`}),(0,G.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:m.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;h(r),r.length===6?t(`rgba`,r+`FF`):r.length===8&&t(`rgba`,r)},onBlur:()=>{if(m.length===7){let e=m+`0`;h(e),t(`rgba`,e)}else if(m.length>0&&m.length<6){let e=m.padEnd(6,`0`);h(e),t(`rgba`,e+`FF`)}}})]}),(0,G.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,G.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3 pt-2 border-t border-bambu-dark-tertiary/50`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:a(`inventory.extraColorsLabel`)}),(0,G.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,G.jsx)(`p`,{className:`text-xs text-red-700 dark:text-red-400 mt-1`,children:a(`inventory.extraColorsInvalid`,{tokens:T.join(`, `)})}),!T.length&&(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray/70 mt-1`,children:a(`inventory.extraColorsHint`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1 flex items-center gap-1.5`,children:[(0,G.jsx)(mu,{className:`w-3.5 h-3.5`}),a(`inventory.colorEffectLabel`)]}),(0,G.jsxs)(`div`,{className:`flex gap-2 items-stretch`,children:[(0,G.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:Cm.map(e=>(0,G.jsx)(`option`,{value:e.value,children:a(e.labelKey)},e.value||`none`))}),(0,G.jsx)(Dm,{rgba:e.rgba,extraColors:e.extra_colors,effectType:e.effect_type,subtype:e.subtype,effectSize:`preview`,className:`w-10 h-10`,shape:`square`})]})]})]})]})}function q0e({catalog:e,value:t,onChange:n,catalogId:r,onCatalogIdChange:i}){let{t:a}=U(),[o,s]=(0,f.useState)(!1),[c,l]=(0,f.useState)(``),u=(0,f.useRef)(null),d=(0,f.useRef)(null);(0,f.useEffect)(()=>{let e=e=>{u.current&&!u.current.contains(e.target)&&s(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[]),(0,f.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 p=(0,f.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]),m=(0,f.useMemo)(()=>e.filter(e=>e.weight===t),[e,t]),h=(0,f.useMemo)(()=>{if(o)return c;if(r){let t=e.find(e=>e.id===r);if(t)return t.name}return m.length>0?m[0].name:``},[o,c,r,e,m]);return(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:(0,G.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Gl,{className:`w-3.5 h-3.5 text-bambu-gray`}),a(`inventory.coreWeight`)]})}),(0,G.jsxs)(`div`,{className:`flex gap-2 items-center`,children:[(0,G.jsxs)(`div`,{className:`flex-1 min-w-0 relative`,ref:u,children:[(0,G.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:h,onFocus:()=>{s(!0),l(``)},onChange:e=>{l(e.target.value),s(!0)}}),o&&(0,G.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:p.length===0?(0,G.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:a(`inventory.noResults`)}):p.map(e=>(0,G.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,G.jsx)(`span`,{className:`truncate`,children:e.name}),(0,G.jsxs)(`span`,{className:`font-mono text-xs text-bambu-gray ml-2 shrink-0`,children:[e.weight,`g`]})]},e.id))})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[(0,G.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,G.jsx)(`span`,{className:`text-bambu-gray text-sm`,children:`g`})]})]})]})}function J0e({formData:e,updateField:t,spoolCatalog:n,currencySymbol:r,availableCategories:i,availableMaterialNumbers:a,availableLocations:o=[],onCreateLocation:s,globalLowStockThreshold:c,spoolmanMode:l=!1}){let{t:u}=U(),{showToast:d}=Zd(),[p,m]=(0,f.useState)(``),[h,g]=(0,f.useState)(!1),[_,v]=(0,f.useState)(``),[y,b]=(0,f.useState)(!1),[x,S]=(0,f.useState)(``),[C,w]=(0,f.useState)(!1),T=Math.max(0,e.label_weight-e.weight_used),E=e.core_weight+T;return(0,f.useEffect)(()=>{h||m(String(E))},[h,E]),(0,f.useEffect)(()=>{y||v(String(T))},[y,T]),(0,G.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-x-4 gap-y-4`,children:[(0,G.jsx)(`div`,{className:`sm:col-span-2`,children:(0,G.jsx)(q0e,{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,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:u(`inventory.currentWeight`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`div`,{className:`relative flex-1`,children:[(0,G.jsx)(`input`,{type:`number`,value:_,min:0,max:e.label_weight,onFocus:()=>b(!0),onChange:e=>{v(e.target.value)},onBlur:()=>{b(!1);let n=_.trim(),r=Number(n);if(!n||!Number.isFinite(r)||r<0||r>e.label_weight){v(String(T));return}let i=Math.round(r);t(`weight_used`,Math.max(0,e.label_weight-i)),v(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,G.jsx)(`span`,{className:`absolute right-2 top-1/2 -translate-y-1/2 text-xs text-bambu-gray`,children:`g`})]}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray shrink-0`,children:[`/ `,e.label_weight,`g`]})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:u(`inventory.measuredWeight`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`div`,{className:`relative flex-1`,children:[(0,G.jsx)(`input`,{type:`number`,value:p,min:0,onFocus:()=>g(!0),onChange:e=>{m(e.target.value)},onBlur:()=>{g(!1);let n=p.trim(),r=Number(n),i=e.core_weight,a=e.core_weight+e.label_weight;if(!n||!Number.isFinite(r)||ra){d(u(`inventory.measuredWeightError`,{min:i,max:a}),`error`),m(String(E));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)),m(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,G.jsx)(`span`,{className:`absolute right-2 top-1/2 -translate-y-1/2 text-xs text-bambu-gray`,children:`g`})]}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray shrink-0`,children:[`/ `,e.core_weight+e.label_weight,`g`]})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:u(`inventory.costPerKg`,`Cost per kg`)}),(0,G.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,G.jsxs)(`div`,{className:`relative flex-1`,children:[(0,G.jsx)(`span`,{className:`absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray text-sm pointer-events-none`,children:r}),(0,G.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`})]})})]}),!l&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,htmlFor:`spool-material-number`,children:u(`inventory.materialNumber`)}),(0,G.jsx)(`input`,{id:`spool-material-number`,type:`text`,list:`spool-material-number-options`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`,placeholder:u(`inventory.materialNumberPlaceholder`),value:e.material_number,maxLength:64,onChange:e=>t(`material_number`,e.target.value)}),a.length>0&&(0,G.jsx)(`datalist`,{id:`spool-material-number-options`,children:a.map(e=>(0,G.jsx)(`option`,{value:e},e))}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:u(`inventory.materialNumberHelp`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,htmlFor:`spool-category`,children:u(`inventory.category`)}),(0,G.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:u(`inventory.categoryPlaceholder`),value:e.category,maxLength:50,onChange:e=>t(`category`,e.target.value)}),i.length>0&&(0,G.jsx)(`datalist`,{id:`spool-category-options`,children:i.map(e=>(0,G.jsx)(`option`,{value:e},e))})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,htmlFor:`spool-low-stock-threshold`,children:u(`inventory.lowStockThresholdOverride`)}),(0,G.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,G.jsxs)(`div`,{className:`relative flex-1`,children:[(0,G.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(c),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,G.jsx)(`span`,{className:`absolute right-3 top-1/2 -translate-y-1/2 text-xs text-bambu-gray pointer-events-none`,children:`%`})]})}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:u(`inventory.lowStockThresholdOverrideHelp`,{global:c})})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,htmlFor:`spool-storage-location`,children:u(`inventory.storageLocation`)}),(0,G.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,G.jsx)(`option`,{value:``,children:u(`inventory.storageLocationNone`)}),o.map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),s&&(0,G.jsxs)(`div`,{className:`mt-2 flex gap-2`,children:[(0,G.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:u(`locations.createPlaceholder`),value:x,onChange:e=>S(e.target.value)}),(0,G.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:!x.trim()||C,onClick:async()=>{let e=x.trim();if(!(!e||!s)){w(!0);try{let n=await s(e);n&&(t(`location_id`,n.id),S(``))}finally{w(!1)}}},children:u(`locations.addShort`)})]})]}),(0,G.jsxs)(`div`,{className:`sm:col-span-2`,children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:u(`inventory.note`)}),(0,G.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:u(`inventory.notePlaceholder`),value:e.note,onChange:e=>t(`note`,e.target.value)})]})]})}function Y0e({links:e,onChange:t,currencySymbol:n}){let{t:r}=U(),{showToast:i}=Zd(),a=no(),o=(0,f.useRef)(null),[s,c]=(0,f.useState)(!1),[l,u]=(0,f.useState)(``),[d,p]=(0,f.useState)(!1),{data:m=[],isLoading:h,isError:g}=K({queryKey:m6,queryFn:Z.getSuppliers});(0,f.useEffect)(()=>{if(!s)return;let e=e=>{o.current&&!o.current.contains(e.target)&&(c(!1),u(``))};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[s]);let _=(0,f.useMemo)(()=>new Set(e.map(e=>e.supplier_id)),[e]),v=(0,f.useMemo)(()=>m.filter(e=>!_.has(e.id)).filter(e=>e.name.toLowerCase().includes(l.trim().toLowerCase())),[m,_,l]),y=m.some(e=>e.name.toLowerCase()===l.trim().toLowerCase()),b=n=>{t([...e,{supplier_id:n.id,supplier_name:n.name,supplier_article_number:``,quoted_price_per_kg:null,is_purchase_source:!1}]),c(!1),u(``)},x=async()=>{let e=l.trim();if(e){p(!0);try{let t=await Z.createSupplier({name:e});await h6(a),b(t)}catch(e){console.error(`SupplierSection.createAndAdd failed:`,e),i(r(e instanceof sd&&e.status===409?`inventory.suppliers.duplicateName`:`inventory.suppliers.createFailed`),`error`)}finally{p(!1)}}},S=(n,r)=>{t(e.map(e=>e.supplier_id===n?{...e,...r}:r.is_purchase_source?{...e,is_purchase_source:!1}:e))},C=n=>{t(e.filter(e=>e.supplier_id!==n))};return(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:r(`inventory.suppliers.label`)}),e.length>0&&(0,G.jsx)(`div`,{className:`space-y-2 mb-2`,children:e.map(e=>(0,G.jsxs)(`div`,{className:`p-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs bg-bambu-green/10 text-bambu-green`,children:[(0,G.jsx)(xu,{className:`w-3 h-3`}),e.supplier_name]}),(0,G.jsxs)(`label`,{className:`ml-auto flex items-center gap-1.5 text-xs text-bambu-gray cursor-pointer`,title:r(`inventory.suppliers.purchaseSourceHelp`),children:[(0,G.jsx)(`input`,{type:`checkbox`,className:`w-3.5 h-3.5 accent-bambu-green`,checked:e.is_purchase_source,onChange:t=>S(e.supplier_id,{is_purchase_source:t.target.checked})}),r(`inventory.suppliers.purchaseSource`)]}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>C(e.supplier_id),className:`p-1 rounded text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary`,"aria-label":r(`common.remove`),children:(0,G.jsx)(nd,{className:`w-3.5 h-3.5`})})]}),(0,G.jsxs)(`div`,{className:`flex gap-2 mt-2`,children:[(0,G.jsx)(`input`,{type:`text`,className:`flex-1 min-w-0 px-2 py-1.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-xs placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`,placeholder:r(`inventory.suppliers.articleNumberPlaceholder`),value:e.supplier_article_number,maxLength:100,onChange:t=>S(e.supplier_id,{supplier_article_number:t.target.value})}),(0,G.jsxs)(`div`,{className:`relative w-28`,children:[(0,G.jsx)(`span`,{className:`absolute left-2 top-1/2 -translate-y-1/2 text-xs text-bambu-gray pointer-events-none`,children:n}),(0,G.jsx)(`input`,{type:`number`,className:`w-full pl-6 pr-2 py-1.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-xs text-right placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`,placeholder:r(`inventory.suppliers.pricePlaceholder`),title:r(`inventory.suppliers.priceHelp`),min:0,step:.01,value:e.quoted_price_per_kg??``,onChange:t=>S(e.supplier_id,{quoted_price_per_kg:t.target.value===``?null:parseFloat(t.target.value)})})]})]})]},e.supplier_id))}),(0,G.jsxs)(`div`,{className:`relative`,ref:o,children:[(0,G.jsxs)(`button`,{type:`button`,onClick:()=>c(e=>!e),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-sm text-bambu-gray hover:text-white flex items-center justify-between transition-colors focus:outline-none focus:border-bambu-green`,children:[(0,G.jsx)(`span`,{children:r(`inventory.suppliers.addSupplier`)}),(0,G.jsx)(ss,{className:`w-4 h-4 transition-transform ${s?`rotate-180`:``}`})]}),s&&(0,G.jsxs)(`div`,{className:`absolute z-50 w-full mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg`,children:[(0,G.jsx)(`div`,{className:`p-2 border-b border-bambu-dark-tertiary`,children:(0,G.jsx)(`input`,{type:`text`,autoFocus:!0,className:`w-full px-2 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`,placeholder:r(`inventory.suppliers.searchPlaceholder`),value:l,onChange:e=>u(e.target.value)})}),(0,G.jsx)(`div`,{className:`max-h-48 overflow-y-auto py-1`,children:h?(0,G.jsxs)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray flex items-center gap-2`,children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),r(`common.loading`)]}):g?(0,G.jsxs)(`div`,{className:`px-3 py-2 text-sm text-red-400 flex items-center gap-2`,children:[(0,G.jsx)(Lu,{className:`w-4 h-4`}),r(`inventory.suppliers.loadFailed`)]}):(0,G.jsxs)(G.Fragment,{children:[v.map(e=>(0,G.jsx)(`button`,{type:`button`,onClick:()=>b(e),className:`w-full px-3 py-2 text-left text-sm text-white hover:bg-bambu-dark-tertiary`,children:e.name},e.id)),v.length===0&&!l.trim()&&(0,G.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:r(`inventory.suppliers.noneLeft`)}),l.trim()&&!y&&(0,G.jsxs)(`button`,{type:`button`,onClick:x,disabled:d,className:`w-full px-3 py-2 text-left text-sm text-bambu-green hover:bg-bambu-dark-tertiary flex items-center gap-1.5`,children:[d?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Ml,{className:`w-4 h-4`}),r(`inventory.suppliers.createNew`,{name:l.trim()})]})]})})]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:r(`inventory.suppliers.help`)})]})}function X0e({filaments:e,isLoading:t,selectedId:n,onSelect:r}){let{t:i}=U(),[a,o]=(0,f.useState)(!1),[s,c]=(0,f.useState)(``),l=(0,f.useRef)(null),u=(0,f.useRef)(null),d=(0,f.useMemo)(()=>e.find(e=>e.id===n)??null,[e,n]);(0,f.useEffect)(()=>{let e=e=>{l.current&&!l.current.contains(e.target)&&(o(!1),c(``))};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[]);let p=(0,f.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,f.useEffect)(()=>{a&&u.current?.focus()},[a]);let m=()=>{o(!0),c(``)},h=e=>{r(e),o(!1),c(``)};return(0,G.jsxs)(`div`,{ref:l,className:`relative`,children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:i(`inventory.pickFromSpoolmanCatalog`)}),(0,G.jsxs)(`button`,{type:`button`,onClick:m,className:`w-full flex items-center gap-2 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-left focus:outline-none focus:border-bambu-green hover:border-bambu-gray transition-colors`,children:[t?(0,G.jsx)(Y,{className:`w-4 h-4 text-bambu-gray animate-spin shrink-0`}):d?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`span`,{className:`w-4 h-4 rounded-full shrink-0 border border-white/20`,style:If(d.color_hex),"aria-label":i(`inventory.spoolmanFilamentColorSwatch`)}),(0,G.jsxs)(`span`,{className:`text-white text-sm truncate flex-1`,children:[d.vendor?.name?`${d.vendor.name} — `:``,d.name]})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(bl,{className:`w-4 h-4 text-bambu-gray shrink-0`}),(0,G.jsx)(`span`,{className:`text-bambu-gray text-sm flex-1`,children:i(`inventory.spoolmanFilamentCatalog`)})]}),(0,G.jsx)(ss,{className:`w-4 h-4 text-bambu-gray shrink-0 ml-auto`})]}),a&&(0,G.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,G.jsx)(`div`,{className:`p-2 border-b border-bambu-dark-tertiary`,children:(0,G.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,G.jsx)(`ul`,{className:`max-h-56 overflow-y-auto py-1`,children:t?(0,G.jsxs)(`li`,{className:`flex items-center justify-center gap-2 py-4 text-bambu-gray text-sm`,children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),(0,G.jsx)(`span`,{children:i(`common.loading`,`Loading…`)})]}):p.length===0?(0,G.jsx)(`li`,{className:`py-4 text-center text-bambu-gray text-sm`,children:i(`inventory.noSpoolmanFilaments`)}):p.map(e=>(0,G.jsx)(`li`,{children:(0,G.jsxs)(`button`,{type:`button`,onClick:()=>h(e),className:`w-full flex items-center gap-2 px-3 py-2 text-left hover:bg-bambu-dark-tertiary transition-colors ${e.id===n?`bg-bambu-dark-tertiary`:``}`,children:[(0,G.jsx)(`span`,{className:`w-4 h-4 rounded-full shrink-0 border border-white/20`,style:If(e.color_hex),"aria-label":i(`inventory.spoolmanFilamentColorSwatch`)}),(0,G.jsxs)(`span`,{className:`flex-1 min-w-0`,children:[(0,G.jsxs)(`span`,{className:`block text-white text-sm truncate`,children:[e.vendor?.name?`${e.vendor.name} — `:``,e.name]}),(0,G.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 f9(e){let t=(e??``).trim().toUpperCase().slice(0,2);return t===`HH`||t===`HS`?t:null}function p9(e){return e?e===`HH`?`HF`:`S`:null}function Z0e(e,t){let n=e.nozzles??[];return f9(n[(e.printer.nozzle_count??1)>1&&t>0?t:0]?.nozzle_type)??f9(n[0]?.nozzle_type)}function Q0e(e){let t=new Set;for(let n of e.nozzles??[]){let e=(n?.nozzle_diameter??``).trim();e&&parseFloat(e)>0&&t.add(e)}for(let n of e.calibrations){let e=(n.nozzle_diameter??``).trim();e&&parseFloat(e)>0&&t.add(e)}return Array.from(t).sort((e,t)=>parseFloat(e)-parseFloat(t))}function $0e(e,t){return(e.printer.nozzle_count??1)>1?[{extruder:1,label:t.left},{extruder:0,label:t.right}]:[{extruder:0,label:t.single}]}function e2e({formData:e,printersWithCalibrations:t,filamentOptions:n,modelPresets:r,setModelPresets:i,selectedProfiles:a,setSelectedProfiles:o,selectedGroupId:s,setSelectedGroupId:c,printerModels:l,isLoading:u=!1}){let{t:d}=U(),p=(0,f.useMemo)(()=>{let e=new Map,n=[];for(let r of t){let t=(r.printer.model||``).trim();if(!t){n.push(r);continue}let i=e.get(t);i?i.push(r):e.set(t,[r])}return[...Array.from(e.entries()).map(([e,t])=>({id:`m:${e}`,model:e,printers:t,diameters:Array.from(new Set([...fU,...t.flatMap(Q0e)])).sort((e,t)=>parseFloat(e)-parseFloat(t))})).sort((e,t)=>e.model.localeCompare(t.model)),...n.map(e=>({id:`p:${e.printer.id}`,model:``,printers:[e],diameters:Array.from(new Set([...fU,...Q0e(e)])).sort((e,t)=>parseFloat(e)-parseFloat(t))}))]},[t]),m=p.find(e=>e.id===s)??p[0],h=(0,f.useMemo)(()=>{let e=new Map;return(t,r)=>{if(!t)return n;let i=e.get(t);if(i||(i=n.filter(e=>{let n=aU(e.name,l??{});return!n||ZH(n,t)}),e.set(t,i)),r&&!i.some(e=>e.code===r)){let e=n.find(e=>e.code===r);if(e)return[e,...i]}return i}},[n,l]),g=[e.brand,e.material,e.subtype].map(e=>e.trim()).filter(Boolean).join(` `),_=/^[0-9A-Fa-f]{6,8}$/.test(e.rgba)?`#${e.rgba.slice(0,6)}`:`var(--bambu-gray, #808080)`,v=e=>$0e(e,{left:d(`inventory.leftNozzle`),right:d(`inventory.rightNozzle`),single:d(`inventory.nozzle`)}),y=t=>t.printer.connected?t.calibrations.filter(t=>EU(t,e)):[],b=e=>{let t=0;for(let n of e.printers){let r=y(n);for(let i of v(n))for(let o of e.diameters)r.some(e=>(e.extruder_id??0)===i.extruder&&((e.nozzle_diameter??``).trim()||`0.4`)===o)&&(a.get(wU(n.printer.id,i.extruder,o))||t++)}return t},x=(e,t,n)=>{i(r=>{let i=new Map(r),a=TU(e,t);return n?i.set(a,{code:n.code,name:n.name}):i.delete(a),i})},S=(e,t,n,r)=>{o(i=>{let a=new Map(i),o=wU(e,t,n);return r?a.set(o,r):a.delete(o),a})},C=()=>{let t=n.find(t=>t.code===e.slicer_filament);if(!t)return;let r=t.name.split(`@`)[0].trim().toLowerCase();r&&i(e=>{let t=new Map(e);for(let e of p){if(!e.model)continue;let n=h(e.model,void 0).filter(e=>e.name.toLowerCase().startsWith(r)&&aU(e.name,l??{})!==null);if(n.length!==0)for(let r of e.diameters){let i=n.find(e=>RegExp(`\\b${r.replace(`.`,`\\.`)}\\s*nozzle\\b`,`i`).test(e.name)),a=n.find(e=>!/\b[\d.]+\s*nozzle\b/i.test(e.name)),o=i??a;o&&t.set(TU(e.model,r),{code:o.code,name:o.name})}}return t})};if(t.length===0)return(0,G.jsx)(`div`,{className:`p-6 bg-bambu-dark rounded-lg text-center`,children:(0,G.jsxs)(`p`,{className:`text-bambu-gray flex items-center justify-center gap-2`,children:[u&&(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),d(u?`common.loading`:`inventory.noPrintersConfigured`)]})});let w=(e,t,n)=>{let i=TU(e,t),a=r.get(i),o=h(e,a?.code);return(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,G.jsx)(H0e,{ariaLabel:`${e} ${t}mm ${d(`inventory.filamentPreset`)}`,value:a?.code??``,options:o,inheritLabel:n,disabled:!e,onChange:n=>x(e,t,n)})}),(0,G.jsx)(`span`,{className:`text-[10px] font-semibold uppercase tracking-wide px-2 py-1 rounded-full shrink-0 ${a?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark-tertiary text-bambu-gray`}`,children:d(a?`inventory.presetOverride`:`inventory.presetInherited`)})]})};return(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(g||e.color_name)&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2.5 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg`,children:[(0,G.jsx)(`span`,{className:`w-5 h-5 rounded-full border border-white/15 shrink-0`,style:{background:_},"aria-hidden":`true`}),g&&(0,G.jsx)(`span`,{className:`text-sm text-white truncate`,children:g}),e.color_name&&(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray truncate`,children:e.color_name})]}),(0,G.jsxs)(`div`,{className:`flex flex-col md:flex-row gap-4`,children:[(0,G.jsx)(`div`,{role:`tablist`,"aria-label":d(`inventory.printersTab`),"aria-orientation":`vertical`,className:`md:w-52 md:shrink-0 md:self-start md:sticky md:top-0 flex md:flex-col gap-1.5 overflow-x-auto md:overflow-x-visible`,children:p.map(e=>{let t=e===m,n=b(e);return(0,G.jsxs)(`button`,{type:`button`,role:`tab`,onClick:()=>c(e.id),"aria-selected":t,className:`flex items-center gap-2 px-3 py-2 rounded-lg border text-left transition-colors shrink-0 md:shrink ${t?`bg-bambu-green/10 border-bambu-green/40 text-white`:`bg-transparent border-transparent text-bambu-gray hover:bg-bambu-dark hover:text-white`}`,children:[(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,G.jsx)(`div`,{className:`text-sm font-semibold truncate`,children:e.model||d(`inventory.unknownModel`)}),(0,G.jsx)(`div`,{className:`text-[11px] text-bambu-gray`,children:e.printers.length===1?d(`inventory.onePrinter`):d(`inventory.nPrinters`,{n:e.printers.length})})]}),n>0?(0,G.jsx)(`span`,{className:`text-[10px] font-mono px-1.5 py-0.5 rounded-full bg-bambu-dark-tertiary text-bambu-gray shrink-0`,children:n}):(0,G.jsx)(as,{className:`w-3.5 h-3.5 text-bambu-green shrink-0`})]},e.id)})}),(0,G.jsx)(`div`,{className:`flex-1 min-w-0`,children:m&&(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsx)(`h4`,{className:`text-base font-semibold text-white truncate`,children:m.model||d(`inventory.unknownModel`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:m.printers.map(e=>e.printer.name).join(`, `)})]}),e.slicer_filament&&(0,G.jsxs)(`button`,{type:`button`,onClick:C,title:d(`inventory.autoMatchPresetsHint`),className:`flex items-center gap-1.5 px-2 py-1 text-xs bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray hover:text-white hover:border-bambu-green transition-colors shrink-0`,children:[(0,G.jsx)(mu,{className:`w-3.5 h-3.5`}),d(`inventory.autoMatchPresets`)]})]}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`p`,{className:`text-xs font-semibold text-bambu-gray uppercase tracking-wide`,children:d(`inventory.filamentPreset`)}),m.model?(0,G.jsx)(`div`,{className:`space-y-2`,children:m.diameters.map(e=>(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsxs)(`span`,{className:`text-xs font-mono text-bambu-gray w-14 shrink-0`,children:[e,`mm`]}),(0,G.jsx)(`div`,{className:`flex-1 min-w-0`,children:w(m.model,e,d(`inventory.presetUseSpoolDefault`))})]},e))}):(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray italic`,children:d(`inventory.presetNeedsModel`)})]}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`p`,{className:`text-xs font-semibold text-bambu-gray uppercase tracking-wide`,children:d(`inventory.kProfilesPerPrinter`)}),e.material?m.printers.map(e=>{let t=y(e);return(0,G.jsxs)(`div`,{className:`p-3 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,G.jsx)(Fl,{className:`w-3.5 h-3.5 text-bambu-gray shrink-0`}),(0,G.jsx)(`span`,{className:`text-sm font-semibold text-white truncate`,children:e.printer.name}),(0,G.jsx)(`span`,{className:`text-[10px] font-semibold uppercase tracking-wide px-2 py-0.5 rounded-full shrink-0 ${e.printer.connected?`bg-green-500/20 text-green-500`:`bg-bambu-dark-tertiary text-bambu-gray`}`,children:e.printer.connected?d(`inventory.connected`):d(`inventory.offline`)})]}),e.printer.connected?t.length===0?(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray italic py-1`,children:d(`inventory.noKProfilesMatch`)}):(0,G.jsxs)(`div`,{className:`grid gap-x-3 gap-y-1.5 items-center`,style:{gridTemplateColumns:`3.5rem repeat(${v(e).length}, minmax(0, 1fr))`},children:[(0,G.jsx)(`span`,{}),v(e).map(e=>(0,G.jsx)(`span`,{className:`text-[11px] font-semibold uppercase tracking-wide text-bambu-gray`,children:e.label},e.extruder)),m.diameters.map(n=>(0,G.jsxs)(f.Fragment,{children:[(0,G.jsxs)(`span`,{className:`text-xs font-mono text-bambu-gray`,children:[n,`mm`]}),v(e).map(r=>{let i=t.filter(e=>(e.extruder_id??0)===r.extruder&&((e.nozzle_diameter??``).trim()||`0.4`)===n),o=wU(e.printer.id,r.extruder,n),s=a.get(o);if(i.length===0)return(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray/50 px-2 py-1.5`,title:d(`inventory.noKProfilesMatch`),children:`—`},o);let c=Z0e(e,r.extruder),l=f9(s?.nozzle_id),u=!!(c&&l&&c!==l);return(0,G.jsxs)(`select`,{title:u?d(`inventory.kProfileFlowMismatch`,{profile:p9(l),fitted:p9(c)}):void 0,"aria-label":`${e.printer.name} ${r.label} ${n}mm`,value:s?String(s.cali_idx):``,onChange:t=>{let a=i.find(e=>String(e.cali_idx)===t.target.value)??null;S(e.printer.id,r.extruder,n,a)},className:`min-w-0 px-2 py-1.5 bg-bambu-dark-secondary border rounded-lg text-sm text-white focus:outline-none focus:border-bambu-green ${u?`border-amber-500/60`:`border-bambu-dark-tertiary`}`,children:[(0,G.jsx)(`option`,{value:``,children:d(`inventory.kProfileNotSet`)}),i.map(e=>{let t=p9(f9(e.nozzle_id));return(0,G.jsx)(`option`,{value:e.cali_idx,children:`${t?`[${t}] `:``}${e.name||e.filament_id} K=${e.k_value.toFixed(3)}`},e.cali_idx)})]},o)})]},n))]}):(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray italic py-1`,children:d(`inventory.printerOffline`)})]},e.printer.id)}):(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray italic`,children:d(`inventory.selectMaterialFirst`)})]})]})})]})]})}function t2e(e){let t=sp(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 n2e={completed:`text-bambu-green`,failed:`text-red-700 dark:text-red-400`,aborted:`text-yellow-700 dark:text-yellow-400`};function r2e({spoolId:e}){let{t}=U(),n=no(),{showToast:r}=Zd(),{data:i,isLoading:a}=K({queryKey:[`spool-usage`,e],queryFn:()=>Z.getSpoolUsageHistory(e)}),o=q({mutationFn:()=>Z.clearSpoolUsageHistory(e),onSuccess:()=>{n.invalidateQueries({queryKey:[`spool-usage`,e]}),r(t(`inventory.historyCleared`),`success`)}});return a?(0,G.jsx)(`div`,{className:`flex justify-center py-4`,children:(0,G.jsx)(Y,{className:`w-5 h-5 animate-spin text-bambu-green`})}):!i||i.length===0?(0,G.jsxs)(`div`,{className:`text-center py-4 text-bambu-gray text-sm`,children:[(0,G.jsx)(Ts,{className:`w-5 h-5 mx-auto mb-2 opacity-50`}),t(`inventory.noUsageHistory`)]}):(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`h4`,{className:`text-sm font-medium text-white`,children:t(`inventory.usageHistory`)}),(0,G.jsxs)(Q,{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,G.jsx)(Pu,{className:`w-3 h-3 mr-1`}),t(`inventory.clearHistory`)]})]}),(0,G.jsx)(`div`,{className:`max-h-48 overflow-y-auto space-y-1`,children:i.map(e=>(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-2 rounded bg-bambu-dark/50 text-xs`,children:[(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:t2e(e.created_at)}),e.print_name&&(0,G.jsx)(`span`,{className:`text-white ml-2 truncate`,title:e.print_name,children:e.print_name})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0 ml-2`,children:[(0,G.jsxs)(`span`,{className:`text-white font-medium`,children:[e.weight_used.toFixed(1),`g`]}),(0,G.jsxs)(`span`,{className:`text-bambu-gray`,children:[`(`,e.percent_used,`%)`]}),(0,G.jsx)(`span`,{className:n2e[e.status]||`text-bambu-gray`,children:e.status})]})]},e.id))})]})}function i2e(e){return e?`#${e.slice(0,6)}`:`#808080`}function a2e(e){return!e.tray_type||e.tray_type===``}function o2e(e){return e<=3?`AMS ${String.fromCharCode(65+e)}`:e>=128&&e<=135?`AMS HT ${String.fromCharCode(65+e-128)}`:`AMS ${e}`}function s2e({className:e}){return(0,G.jsx)(`svg`,{className:e,viewBox:`0 0 36 54`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:(0,G.jsx)(`path`,{d:`M17.8131 0.00538C18.4463 -0.15091 20.3648 3.14642 20.8264 3.84781C25.4187 10.816 35.3089 26.9368 35.9383 34.8694C37.4182 53.5822 11.882 61.3357 2.53721 45.3789C-1.73471 38.0791 0.016 32.2049 3.178 25.0232C6.99221 16.3662 12.6411 7.90372 17.8131 0.00538ZM18.3738 7.24807L17.5881 7.48441C14.4452 12.9431 10.917 18.2341 8.19369 23.9368C4.6808 31.29 1.18317 38.5479 7.69403 45.5657C17.3058 55.9228 34.9847 46.8808 31.4604 32.8681C29.2558 24.0969 22.4207 15.2913 18.3776 7.24807H18.3738Z`,fill:`#C3C2C1`})})}function c2e({className:e}){return(0,G.jsxs)(`svg`,{className:e,viewBox:`0 0 35 53`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:[(0,G.jsx)(`path`,{d:`M17.3165 0.0038C17.932 -0.14959 19.7971 3.08645 20.2458 3.77481C24.7103 10.6135 34.3251 26.4346 34.937 34.2198C36.3757 52.5848 11.5505 60.1942 2.46584 44.534C-1.68714 37.3735 0.0148 31.6085 3.08879 24.5603C6.79681 16.0605 12.2884 7.75907 17.3165 0.0038ZM17.8615 7.11561L17.0977 7.34755C14.0423 12.7048 10.6124 17.8974 7.96483 23.4941C4.54975 30.7107 1.14949 37.8337 7.47908 44.721C16.8233 54.8856 34.01 46.0117 30.5838 32.2595C28.4405 23.6512 21.7957 15.0093 17.8652 7.11561H17.8615Z`,fill:`#C3C2C1`}),(0,G.jsx)(`path`,{d:`M5.03547 30.112C9.64453 30.4936 11.632 35.7985 16.4154 35.791C19.6339 35.7873 20.2161 33.2283 22.3853 31.6197C31.6776 24.7286 33.5835 37.4894 27.9881 44.4254C18.1878 56.5653 -1.16063 44.6013 5.03917 30.1158L5.03547 30.112Z`,fill:`#1F8FEB`})]})}function l2e({className:e}){return(0,G.jsxs)(`svg`,{className:e,viewBox:`0 0 36 54`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:[(0,G.jsx)(`path`,{d:`M17.9625 4.48059L4.77216 26.3154L2.08228 40.2175L10.0224 50.8414H23.1594L33.3246 42.1693V30.2455L17.9625 4.48059Z`,fill:`#1F8FEB`}),(0,G.jsx)(`path`,{d:`M17.7948 0.00538C18.4273 -0.15091 20.3438 3.14642 20.8048 3.84781C25.3921 10.816 35.2715 26.9368 35.9001 34.8694C37.3784 53.5822 11.8702 61.3357 2.53562 45.3789C-1.73163 38.0829 0.0134 32.2087 3.1757 25.027C6.98574 16.3662 12.6284 7.90372 17.7948 0.00538ZM18.3549 7.24807L17.57 7.48441C14.4306 12.9431 10.9063 18.2341 8.1859 23.9368C4.67686 31.29 1.18305 38.5479 7.68679 45.5657C17.2881 55.9228 34.9476 46.8808 31.4271 32.8681C29.2249 24.0969 22.3974 15.2913 18.3587 7.24807H18.3549Z`,fill:`#C3C2C1`})]})}function u2e({className:e}){return(0,G.jsxs)(`svg`,{className:e,viewBox:`0 0 12 20`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:[(0,G.jsx)(`path`,{d:`M6 0.5C4.6 0.5 3.5 1.6 3.5 3V12.1C2.6 12.8 2 13.9 2 15C2 17.2 3.8 19 6 19C8.2 19 10 17.2 10 15C10 13.9 9.4 12.8 8.5 12.1V3C8.5 1.6 7.4 0.5 6 0.5Z`,stroke:`#C3C2C1`,strokeWidth:`1`,fill:`none`}),(0,G.jsx)(`circle`,{cx:`6`,cy:`15`,r:`2.5`,stroke:`#C3C2C1`,strokeWidth:`1`,fill:`none`})]})}function d2e({className:e}){return(0,G.jsxs)(`svg`,{className:e,viewBox:`0 0 12 20`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:[(0,G.jsx)(`rect`,{x:`4.5`,y:`8`,width:`3`,height:`4.5`,fill:`#d4a017`,rx:`0.5`}),(0,G.jsx)(`circle`,{cx:`6`,cy:`15`,r:`2`,fill:`#d4a017`}),(0,G.jsx)(`path`,{d:`M6 0.5C4.6 0.5 3.5 1.6 3.5 3V12.1C2.6 12.8 2 13.9 2 15C2 17.2 3.8 19 6 19C8.2 19 10 17.2 10 15C10 13.9 9.4 12.8 8.5 12.1V3C8.5 1.6 7.4 0.5 6 0.5Z`,stroke:`#C3C2C1`,strokeWidth:`1`,fill:`none`})]})}function f2e({className:e}){return(0,G.jsxs)(`svg`,{className:e,viewBox:`0 0 12 20`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:[(0,G.jsx)(`rect`,{x:`4.5`,y:`3`,width:`3`,height:`9.5`,fill:`#c62828`,rx:`0.5`}),(0,G.jsx)(`circle`,{cx:`6`,cy:`15`,r:`2`,fill:`#c62828`}),(0,G.jsx)(`path`,{d:`M6 0.5C4.6 0.5 3.5 1.6 3.5 3V12.1C2.6 12.8 2 13.9 2 15C2 17.2 3.8 19 6 19C8.2 19 10 17.2 10 15C10 13.9 9.4 12.8 8.5 12.1V3C8.5 1.6 7.4 0.5 6 0.5Z`,stroke:`#C3C2C1`,strokeWidth:`1`,fill:`none`})]})}function p2e({humidity:e,goodThreshold:t=40,fairThreshold:n=60}){let r,i;return e<=t?(r=`#22a352`,i=s2e):e<=n?(r=`#d4a017`,i=c2e):(r=`#c62828`,i=l2e),(0,G.jsxs)(`div`,{className:`flex items-center gap-0.5`,children:[(0,G.jsx)(i,{className:`w-3 h-3.5`}),(0,G.jsxs)(`span`,{className:`font-medium tabular-nums text-xs`,style:{color:r},children:[e,`%`]})]})}function m2e({temp:e,goodThreshold:t=28,fairThreshold:n=35}){let r,i;return e<=t?(r=`#22a352`,i=u2e):e<=n?(r=`#d4a017`,i=d2e):(r=`#c62828`,i=f2e),(0,G.jsxs)(`div`,{className:`flex items-center gap-0.5`,children:[(0,G.jsx)(i,{className:`w-3 h-3.5`}),(0,G.jsxs)(`span`,{className:`font-medium tabular-nums text-xs`,style:{color:r},children:[e,`°C`]})]})}function m9({side:e}){return(0,G.jsx)(`span`,{className:`inline-flex items-center justify-center w-4 h-4 text-[9px] font-bold rounded`,style:{backgroundColor:`#1a4d2e`,color:`#00ae42`},children:e})}function h2e({tray:e,slotIndex:t,isActive:n,fillOverride:r,spoolmanFill:i,accessibleLabel:a,onClick:o}){let s=a2e(e),c=Fp(e),l=i2e(e.tray_color),u=e.remain!==null&&e.remain!==void 0&&e.remain>=0?e.remain:null,d=i??(r===0&&u!==null&&u>0?null:r)??u;return(0,G.jsxs)(`div`,{className:`relative flex flex-col items-center p-2.5 rounded-lg border transition-all ${n?`ring-2 ring-bambu-green border-bambu-green bg-bambu-green/10`:`border-transparent`} ${o?`cursor-pointer hover:border-bambu-gray hover:bg-bambu-dark-tertiary`:``}`,onClick:o,onKeyDown:o?e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),o())}:void 0,role:o?`button`:void 0,tabIndex:o?0:void 0,"aria-pressed":o?n:void 0,"aria-label":o?a:void 0,title:o?a:void 0,"data-testid":o?`ams-slot`:void 0,children:[(0,G.jsxs)(`div`,{className:`relative w-16 h-16 mb-1`,children:[s?(0,G.jsx)(`div`,{className:`w-full h-full rounded-full border-2 border-dashed border-gray-500 flex items-center justify-center`,children:(0,G.jsx)(`div`,{className:`w-3 h-3 rounded-full bg-gray-600`})}):(0,G.jsxs)(`svg`,{viewBox:`0 0 56 56`,className:`w-full h-full`,children:[(0,G.jsx)(`circle`,{cx:`28`,cy:`28`,r:`26`,fill:l}),(0,G.jsx)(`circle`,{cx:`28`,cy:`28`,r:`20`,fill:l,style:{filter:`brightness(0.85)`}}),(0,G.jsx)(`ellipse`,{cx:`20`,cy:`20`,rx:`6`,ry:`4`,fill:`white`,opacity:`0.3`}),(0,G.jsx)(`circle`,{cx:`28`,cy:`28`,r:`8`,fill:`#2d2d2d`}),(0,G.jsx)(`circle`,{cx:`28`,cy:`28`,r:`5`,fill:`#1a1a1a`})]}),n&&(0,G.jsx)(`div`,{className:`absolute -bottom-1 left-1/2 -translate-x-1/2 w-2.5 h-2.5 bg-bambu-green rounded-full`})]}),(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray-light truncate max-w-full`,title:c===`reset`?`Spool loaded — slot not configured`:void 0,children:s?c===`reset`?`?`:`Empty`:e.tray_type||`Unknown`}),!s&&d!==null&&d>=0&&(0,G.jsx)(`div`,{className:`w-full h-1 bg-bambu-dark-tertiary rounded-full overflow-hidden mt-1`,children:(0,G.jsx)(`div`,{className:`h-full rounded-full transition-all`,style:{width:`${d}%`,backgroundColor:Rp(d)}})}),(0,G.jsx)(`span`,{className:`absolute top-1 right-1 rounded bg-bambu-dark-tertiary px-1.5 py-0.5 text-[10px] font-semibold text-bambu-gray-light`,children:t+1})]})}function g2e({unit:e,activeSlot:t,onConfigureSlot:n,isDualNozzle:r,nozzleSide:i,thresholds:a,fillOverrides:o,spoolmanFillOverrides:s}){let{t:c}=U(),l=e.tray||[],u=e.is_ams_ht,d=u?1:4,f=o2e(e.id);return(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-[var(--border-color)] p-3 shadow-sm`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,G.jsx)(`span`,{className:`text-white font-medium text-base`,children:f}),r&&i&&(0,G.jsx)(m9,{side:i})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.temp!=null&&(0,G.jsx)(m2e,{temp:e.temp,goodThreshold:a?.tempGood,fairThreshold:a?.tempFair}),e.humidity!=null&&(0,G.jsx)(p2e,{humidity:e.humidity,goodThreshold:a?.humidityGood,fairThreshold:a?.humidityFair})]})]}),(0,G.jsx)(`div`,{className:`grid ${u?`grid-cols-1 max-w-[100px] mx-auto`:`grid-cols-4`} gap-2`,children:Array.from({length:d}).map((r,i)=>{let a=l[i]||{id:i,tray_color:null,tray_type:``,tray_sub_brands:null,tray_id_name:null,tray_info_idx:null,remain:-1,k:null,cali_idx:null,tag_uid:null,tray_uuid:null,nozzle_temp_min:null,nozzle_temp_max:null};return(0,G.jsx)(h2e,{tray:a,slotIndex:i,isActive:t===i,fillOverride:o?.[`${e.id}-${i}`]??null,spoolmanFill:s?.[`${e.id}-${i}`]??null,accessibleLabel:c(`configureAmsSlot.slotLabel`,{ams:f,slot:i+1}),onClick:n?()=>n(e.id,i,a2e(a)?null:a):void 0},i)})})]})}function h9(e){return!!e&&(Tm(e.extra_colors).length>0||!!e.effect_type)}function g9(e,t=`table`){return h9(e)?{...Em({effectSize:t,rgba:e.rgba,extraColors:e.extra_colors,effectType:e.effect_type,subtype:e.subtype}),backgroundPosition:`center`}:null}function _9(e){return e<=3?`AMS ${String.fromCharCode(65+e)}`:e>=128&&e<=135?`AMS HT ${String.fromCharCode(65+e-128)}`:`AMS ${e}`}function v9(e){return!e.tray_type||e.tray_type===``}function _2e(e){return e?`#${e.slice(0,6)}`:`#808080`}var v2e=[`a[href]`,`button:not([disabled])`,`input:not([disabled]):not([type="hidden"])`,`select:not([disabled])`,`textarea:not([disabled])`,`[tabindex]:not([tabindex="-1"])`].join(`,`);function y2e(e){return Array.from(e.querySelectorAll(v2e)).filter(e=>!e.hasAttribute(`hidden`)&&e.getAttribute(`aria-hidden`)!==`true`)}var y9=e=>(e??``).trim().toUpperCase();function b2e(e,t){let n=y9(e),r=y9(t);return!n||!r?`none`:n===r?`exact`:r.includes(n)||n.includes(r)?`partial`:`none`}function x2e(e,t){let n=y9(e),r=y9(t);return!n||!r?!1:n===r}function b9({isOpen:e,onClose:t,spool:n,printerId:r,variant:i=`dialog`,spoolmanMode:a=!1}){let{t:o}=U(),s=no(),c=(0,f.useRef)(null),[l,u]=(0,f.useState)(r),[d,p]=(0,f.useState)(null),[m,h]=(0,f.useState)(null),[g,_]=(0,f.useState)(null),[v,y]=(0,f.useState)(!1),[b,x]=(0,f.useState)(null),[S,C]=(0,f.useState)(null);(0,f.useEffect)(()=>{e&&(u(r),p(null),h(null),_(null),y(!1),x(null),C(null))},[e,r,n.id]);let w=r===null,T=w,E=r??l,{data:D=[],isLoading:O}=K({queryKey:[`printers`],queryFn:()=>Z.getPrinters(),enabled:e&&w}),k=(0,f.useMemo)(()=>D.filter(e=>e.is_active!==!1),[D]);(0,f.useEffect)(()=>{if(!e)return;let t=document.body.style.overflow,n=document.activeElement instanceof HTMLElement?document.activeElement:null;document.body.style.overflow=`hidden`;let r=c.current;return((r?y2e(r)[0]:null)??r)?.focus(),()=>{document.body.style.overflow=t,n?.isConnected&&n.focus()}},[e]);let A=(0,f.useCallback)(e=>{if(v)return;if(e.key===`Escape`){e.preventDefault(),t();return}if(e.key!==`Tab`)return;let n=c.current;if(!n)return;let r=y2e(n);if(r.length===0){e.preventDefault(),n.focus();return}let i=r[0],a=r[r.length-1],o=document.activeElement;e.shiftKey&&(o===i||!n.contains(o))?(e.preventDefault(),a.focus()):!e.shiftKey&&(o===a||!n.contains(o))&&(e.preventDefault(),i.focus())},[t,v]);(0,f.useEffect)(()=>{if(e)return document.addEventListener(`keydown`,A),()=>document.removeEventListener(`keydown`,A)},[e,A]);let{data:j,isLoading:M}=K({queryKey:[`printerStatus`,E],queryFn:()=>Z.getPrinterStatus(E),enabled:e&&E!==null,refetchInterval:5e3}),{data:N}=K({queryKey:[`printer`,E],queryFn:()=>Z.getPrinter(E),enabled:e&&E!==null}),{data:P}=K({queryKey:[`settings`],queryFn:()=>Z.getSettings(),enabled:e,staleTime:300*1e3}),{data:F}=K({queryKey:[`spool-assignments`,E],queryFn:()=>Z.getAssignments(E),enabled:e&&E!==null,staleTime:30*1e3}),{data:I=[]}=K({queryKey:[`spoolman-slot-assignments`,E],queryFn:()=>Z.getSpoolmanSlotAssignments(E??void 0),enabled:e&&!!a&&E!==null,staleTime:30*1e3}),L=a?I.find(e=>e.spoolman_spool_id===n.id):void 0,R=(0,f.useMemo)(()=>{let e={};if(!F)return e;for(let t of F){let n=t.spool;if(n&&n.label_weight>0&&n.weight_used!=null){let r=Math.round(Math.max(0,n.label_weight-n.weight_used)/n.label_weight*100);e[`${t.ams_id}-${t.tray_id}`]=r}}return e},[F]),z=P?{humidityGood:Number(P.ams_humidity_good)||40,humidityFair:Number(P.ams_humidity_fair)||60,tempGood:Number(P.ams_temp_good)||28,tempFair:Number(P.ams_temp_fair)||35}:void 0,B=j?.connected??!1,V=(0,f.useMemo)(()=>j?.ams??[],[j?.ams]),ee=(0,f.useMemo)(()=>V.filter(e=>!e.is_ams_ht),[V]),te=(0,f.useMemo)(()=>V.filter(e=>e.is_ams_ht),[V]),ne=(0,f.useMemo)(()=>[...j?.vt_tray??[]].sort((e,t)=>(e.id??254)-(t.id??254)),[j?.vt_tray]),re=N?.nozzle_count===2||j?.temperatures?.nozzle_2!==void 0,ie=(0,f.useRef)({});(0,f.useEffect)(()=>{ie.current={}},[E]),(0,f.useEffect)(()=>{j?.ams_extruder_map&&Object.keys(j.ams_extruder_map).length>0&&(ie.current=j.ams_extruder_map)},[j?.ams_extruder_map]);let ae=j?.ams_extruder_map&&Object.keys(j.ams_extruder_map).length>0?j.ams_extruder_map:ie.current,oe=j?.fila_switch?.installed===!0,se=(0,f.useCallback)(e=>{if(!re)return null;let t=ae[String(e)];return t===void 0?oe?null:(e>=128?e-128:e)===1?`L`:`R`:t===1?`L`:`R`},[re,ae,oe]),H=q({mutationFn:async({amsId:e,trayId:t})=>{if(!E)throw Error(`No printer selected`);return a?await Z.assignSpoolmanSlot({spoolman_spool_id:n.id,printer_id:E,ams_id:e,tray_id:t}):await Z.assignSpool({spool_id:n.id,printer_id:E,ams_id:e,tray_id:t})},onSuccess:e=>{_(`success`);let n=e&&`pending_config`in e&&e.pending_config;h(n?o(`spoolbuddy.modal.assignPendingInsert`,`Assigned. Slot will configure when you insert the spool.`):o(`spoolbuddy.modal.assignSuccess`,`Assigned!`)),s.invalidateQueries({queryKey:[`slotPresets`]}),s.invalidateQueries({queryKey:[`spool-assignments`]}),s.invalidateQueries({queryKey:[`spoolman-slot-assignments`]}),s.invalidateQueries({queryKey:[`spoolman-slot-assignments-all`]}),s.invalidateQueries({queryKey:[`inventory-spools`]}),s.invalidateQueries({queryKey:[`spoolman-inventory-spools`]}),setTimeout(()=>t(),n?2500:1500)},onError:e=>{_(`error`),h(e instanceof Error?e.message:o(`spoolbuddy.modal.assignError`,`Failed to assign spool.`))}}),ce=H.isPending,le=(0,f.useCallback)((e,t)=>{if(e===254||e===255){let n=e===254?254:254+t;return ne.find(e=>(e.id??254)===n)||null}return V.find(t=>t.id===e)?.tray?.find(e=>e.id===t)||null},[V,ne]),ue=(0,f.useCallback)((e,t)=>e<=3?`${_9(e)} ${o(`ams.slot`,`Slot`)} ${t+1}`:e>=128&&e<=135?_9(e):re?e===254||e===255&&t===0?o(`printers.extL`,`Ext-L`):o(`printers.extR`,`Ext-R`):o(`printers.ext`,`Ext`),[o,re]),de=(0,f.useCallback)((e,t)=>{_(`info`),h(o(`spoolbuddy.modal.assigning`,`Configuring slot...`)),H.mutate({amsId:e,trayId:t})},[H,o]),fe=(0,f.useCallback)((e,t)=>{if(!ce){if(!P?.disable_filament_warnings){let r=le(e,t);if(r&&!v9(r)){let i=r.tray_sub_brands||r.tray_type||``,a=b2e(n.material,i),o=n.slicer_filament_name||n.slicer_filament,s=r.tray_type||``,c=x2e(o,s);if(a!==`exact`){let r;r=a===`none`&&!c?`material_profile`:a===`partial`&&!c?`partial_profile`:a===`none`?`material`:`partial`;let l=ue(e,t);C({amsId:e,trayId:t}),x({type:r,spoolMaterial:n.material||``,trayMaterial:i||``,spoolProfile:o||void 0,trayProfile:s||void 0,location:l}),y(!0);return}}}de(e,t)}},[ce,P?.disable_filament_warnings,n,le,ue,de]),pe=(0,f.useCallback)((e,t)=>{if(!ce){if(T){p({amsId:e,trayId:t}),h(null),_(null);return}fe(e,t)}},[T,ce,fe]),me=(0,f.useCallback)(()=>{d&&fe(d.amsId,d.trayId)},[fe,d]),he=(0,f.useCallback)(()=>{S&&(y(!1),x(null),de(S.amsId,S.trayId),C(null))},[S,de]),ge=(0,f.useMemo)(()=>{let e=[];for(let t of te){let n=t.tray?.[0]||{id:0,tray_color:null,tray_type:``,tray_sub_brands:null,tray_id_name:null,tray_info_idx:null,remain:-1,k:null,cali_idx:null,tag_uid:null,tray_uuid:null,nozzle_temp_min:null,nozzle_temp_max:null},r=R[`${t.id}-0`]??null,i=n.remain!=null&&n.remain>=0?n.remain:null,a=r===0&&i!==null&&i>0?null:r;e.push({key:`ht-${t.id}`,label:_9(t.id),amsId:t.id,trayId:0,tray:n,isEmpty:v9(n),nozzleSide:se(t.id),effectiveFill:a??i})}for(let t of ne){let n=t.id??254,r=n-254,i=R[`255-${r}`]??null,a=t.remain!=null&&t.remain>=0?t.remain:null,s=i===0&&a!==null&&a>0?null:i;e.push({key:`ext-${n}`,label:re?n===254?o(`printers.extL`,`Ext-L`):o(`printers.extR`,`Ext-R`):o(`printers.ext`,`Ext`),amsId:255,trayId:r,tray:t,isEmpty:v9(t),nozzleSide:re?n===254?`L`:`R`:null,effectiveFill:s??a})}return e},[te,ne,re,o,se,R]);if(!e)return null;let _e=g9(n)??If(n.rgba),ve=d?ue(d.amsId,d.trayId):null,ye=i===`dialog`;return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:ye?`fixed inset-0 z-[60] flex items-center justify-center bg-black/45 dark:bg-black/70 p-2 sm:p-4 backdrop-blur-sm animate-fade-in`:`fixed inset-0 z-[60] bg-bambu-dark`,onClick:ye&&!ce?t:void 0,children:(0,G.jsxs)(`div`,{ref:c,role:`dialog`,"aria-modal":`true`,"aria-labelledby":`assign-to-ams-title`,tabIndex:-1,className:ye?`bg-bambu-dark-secondary text-white font-sans w-full max-w-3xl h-[calc(100vh-1rem)] sm:h-[calc(100vh-2rem)] max-h-[820px] border border-[var(--border-color)] rounded-xl sm:rounded-2xl shadow-2xl flex flex-col overflow-hidden animate-slide-up`:`w-full h-full bg-bambu-dark flex flex-col`,onClick:e=>e.stopPropagation(),children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between bg-bambu-dark-secondary px-5 py-3 border-b border-[var(--border-color)] shrink-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0`,children:[(0,G.jsx)(`div`,{className:`w-7 h-7 rounded-full shrink-0`,style:_e}),(0,G.jsx)(`div`,{className:`min-w-0`,children:(0,G.jsxs)(`h2`,{id:`assign-to-ams-title`,className:`text-sm font-semibold text-white truncate`,children:[o(`spoolbuddy.modal.assignToAmsTitle`,`Assign to AMS`),(0,G.jsxs)(`span`,{className:`font-normal text-bambu-gray-light ml-2`,children:[Nf(n.color_name,n.rgba,n.color_name_is_synthesized)||o(`spoolbuddy.spool.unknownColor`),` • `,n.brand,` `,n.material,n.subtype&&` ${n.subtype}`]}),(0,G.jsxs)(`span`,{className:`text-[10px] font-mono text-bambu-gray ml-2 shrink-0`,children:[`#`,n.id]})]})})]}),(0,G.jsx)(`button`,{onClick:t,disabled:ce,"aria-label":o(`common.close`,`Close`),className:`p-2 rounded-lg text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary transition-colors shrink-0 disabled:opacity-50`,children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]}),w&&(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary px-5 py-3 border-b border-[var(--border-color)] shrink-0`,children:[(0,G.jsxs)(`label`,{htmlFor:`assign-spool-printer`,className:`flex items-center gap-2 text-sm font-medium text-white mb-2`,children:[(0,G.jsx)(`span`,{className:`inline-flex h-5 w-5 items-center justify-center rounded-full bg-bambu-green text-[11px] font-bold text-[#ffffff]`,children:`1`}),o(`printModal.selectPrinter`)]}),(0,G.jsxs)(`select`,{id:`assign-spool-printer`,"aria-label":o(`printModal.selectPrinter`),value:l??``,onChange:e=>{u(e.target.value?Number(e.target.value):null),p(null),h(null),_(null)},disabled:ce||O,className:`w-full bg-bambu-dark border border-[var(--border-color)] rounded-lg px-3 py-2.5 text-sm text-white focus:outline-none focus:border-bambu-green disabled:opacity-50`,children:[(0,G.jsx)(`option`,{value:``,children:O?o(`common.loading`):k.length===0?o(`common.noPrinters`):o(`printModal.selectPrinter`)}),k.map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),m&&(0,G.jsxs)(`div`,{className:`mx-5 mt-3 p-3 rounded-lg flex items-center gap-3 border shrink-0 ${g===`info`?`bg-blue-50 border-blue-300 dark:bg-blue-500/10 dark:border-blue-500/40`:g===`success`?`bg-green-50 border-green-300 dark:bg-green-500/10 dark:border-green-500/40`:`bg-red-50 border-red-300 dark:bg-red-500/10 dark:border-red-500/40`}`,children:[g===`info`&&(0,G.jsx)(Y,{className:`w-4 h-4 text-blue-600 dark:text-blue-400 animate-spin shrink-0`}),g===`success`&&(0,G.jsx)(hs,{className:`w-4 h-4 text-green-600 dark:text-green-400 shrink-0`}),g===`error`&&(0,G.jsx)(xs,{className:`w-4 h-4 text-red-600 dark:text-red-400 shrink-0`}),(0,G.jsx)(`span`,{className:`text-sm ${g===`info`?`text-blue-700 dark:text-blue-300`:g===`success`?`text-green-700 dark:text-green-300`:`text-red-700 dark:text-red-300`}`,children:m})]}),(0,G.jsx)(`div`,{className:`flex-1 min-h-0 flex flex-col`,children:(0,G.jsxs)(`section`,{className:`flex min-h-[18rem] flex-col gap-3 bg-bambu-dark p-4 lg:min-h-0 lg:overflow-y-auto`,children:[w&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-medium text-white shrink-0`,children:[(0,G.jsx)(`span`,{className:`inline-flex h-5 w-5 items-center justify-center rounded-full bg-bambu-green text-[11px] font-bold text-[#ffffff]`,children:`2`}),o(`printModal.selectSlot`)]}),E?M?(0,G.jsxs)(`div`,{className:`flex flex-1 items-center justify-center text-bambu-gray-light`,children:[(0,G.jsx)(Y,{className:`mr-2 h-5 w-5 animate-spin text-bambu-green`}),o(`common.loading`)]}):B?V.length===0&&ne.length===0?(0,G.jsx)(`div`,{className:`flex flex-1 items-center justify-center rounded-xl border border-dashed border-[var(--border-color)] bg-bambu-dark-secondary p-8`,children:(0,G.jsxs)(`div`,{className:`text-center text-bambu-gray`,children:[(0,G.jsx)(Wc,{className:`w-12 h-12 mx-auto mb-3 opacity-60`}),(0,G.jsx)(`p`,{className:`text-base text-bambu-gray-light mb-1`,children:o(`spoolbuddy.ams.noData`,`No AMS detected`)}),(0,G.jsx)(`p`,{className:`text-sm`,children:o(`spoolbuddy.ams.connectAms`,`Connect an AMS to see filament slots`)})]})}):(0,G.jsxs)(G.Fragment,{children:[ee.length>0&&(0,G.jsx)(`div`,{className:`grid grid-cols-1 xl:grid-cols-2 gap-3`,children:ee.map(e=>(0,G.jsx)(g2e,{unit:e,activeSlot:d?.amsId===e.id?d.trayId:L?.ams_id===e.id?L.tray_id??null:null,onConfigureSlot:(t,n)=>pe(e.id,n),isDualNozzle:re,nozzleSide:se(e.id),thresholds:z,fillOverrides:R},e.id))}),ge.length>0&&(0,G.jsx)(`div`,{className:`flex flex-wrap gap-2 shrink-0`,children:ge.map(({key:e,label:t,amsId:n,trayId:r,tray:i,isEmpty:a,nozzleSide:s,effectiveFill:c})=>{let l=_2e(i.tray_color),u=d?d.amsId===n&&d.trayId===r:!!L&&L.ams_id===n&&L.tray_id===r;return(0,G.jsxs)(`button`,{type:`button`,"aria-pressed":u,title:ue(n,r),onClick:()=>pe(n,r),className:`bg-bambu-dark-secondary border rounded-lg px-3 py-2 hover:bg-bambu-dark-tertiary transition-all flex items-center gap-2 ${u?`ring-2 ring-bambu-green border-bambu-green bg-bambu-green/10`:`border-[var(--border-color)]`} ${ce?`opacity-50 pointer-events-none`:``}`,children:[(0,G.jsx)(`div`,{className:`relative w-10 h-10 shrink-0`,children:a?(0,G.jsx)(`div`,{className:`w-full h-full rounded-full border-2 border-dashed border-gray-500 flex items-center justify-center`,children:(0,G.jsx)(`div`,{className:`w-1.5 h-1.5 rounded-full bg-gray-600`})}):(0,G.jsxs)(`svg`,{viewBox:`0 0 56 56`,className:`w-full h-full`,children:[(0,G.jsx)(`circle`,{cx:`28`,cy:`28`,r:`26`,fill:l}),(0,G.jsx)(`circle`,{cx:`28`,cy:`28`,r:`20`,fill:l,style:{filter:`brightness(0.85)`}}),(0,G.jsx)(`ellipse`,{cx:`20`,cy:`20`,rx:`6`,ry:`4`,fill:`white`,opacity:`0.3`}),(0,G.jsx)(`circle`,{cx:`28`,cy:`28`,r:`8`,fill:`#2d2d2d`}),(0,G.jsx)(`circle`,{cx:`28`,cy:`28`,r:`5`,fill:`#1a1a1a`})]})}),(0,G.jsxs)(`div`,{className:`min-w-0 text-left`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray font-medium`,children:t}),s&&(0,G.jsx)(m9,{side:s})]}),(0,G.jsx)(`div`,{className:`text-sm text-white truncate`,children:a?o(`ams.empty`):i.tray_type||`?`})]}),!a&&c!=null&&c>=0&&(0,G.jsx)(`div`,{className:`w-1.5 h-8 bg-bambu-dark-tertiary rounded-full overflow-hidden shrink-0 flex flex-col-reverse`,children:(0,G.jsx)(`div`,{className:`w-full rounded-full`,style:{height:`${c}%`,backgroundColor:Rp(c)}})})]},e)})})]}):(0,G.jsx)(`div`,{className:`flex flex-1 items-center justify-center rounded-xl border border-red-300 bg-red-50 p-8 dark:border-red-500/30 dark:bg-red-500/5`,children:(0,G.jsx)(`p`,{className:`text-base text-red-700 dark:text-red-300`,children:o(`spoolbuddy.ams.printerDisconnected`,`Printer disconnected`)})}):(0,G.jsx)(`div`,{className:`flex flex-1 items-center justify-center rounded-xl border border-dashed border-[var(--border-color)] bg-bambu-dark-secondary p-8`,children:(0,G.jsxs)(`div`,{className:`text-center text-bambu-gray`,children:[(0,G.jsx)(Wc,{className:`w-12 h-12 mx-auto mb-3 opacity-60`}),(0,G.jsx)(`p`,{className:`text-base text-bambu-gray-light`,children:o(`printModal.selectPrinter`)})]})})]})}),(0,G.jsxs)(`div`,{className:`flex items-center gap-3 bg-bambu-dark-secondary px-5 py-3 border-t border-[var(--border-color)] shrink-0`,children:[T&&(0,G.jsxs)(`div`,{className:`min-w-0 flex-1 text-sm`,children:[(0,G.jsxs)(`span`,{className:`text-bambu-gray`,children:[o(`printModal.selectSlot`),`: `]}),(0,G.jsx)(`span`,{className:ve?`font-medium text-white`:`text-bambu-gray`,children:ve||`—`})]}),(0,G.jsx)(`button`,{onClick:t,disabled:ce,className:`px-5 py-2.5 rounded-lg border border-[var(--border-color)] text-sm font-medium bg-bambu-dark-tertiary text-white hover:bg-bambu-dark transition-colors min-h-[44px] disabled:opacity-50`,children:o(g===`success`?`common.close`:`common.cancel`)}),T&&(0,G.jsxs)(`button`,{type:`button`,onClick:me,disabled:!E||!d||ce||g===`success`,className:`inline-flex min-h-[44px] items-center gap-2 rounded-lg bg-bambu-green px-5 py-2.5 text-sm font-semibold text-[#ffffff] transition-colors hover:bg-bambu-green-dark disabled:cursor-not-allowed disabled:opacity-40`,children:[ce?(0,G.jsx)(Y,{className:`h-4 w-4 animate-spin`}):(0,G.jsx)(as,{className:`h-4 w-4`}),o(`inventory.assignSpool`)]})]})]})}),v&&b&&(()=>{let e=``;return b.type===`material`?e=o(`inventory.assignMismatchMessage`,{spoolMaterial:b.spoolMaterial,trayMaterial:b.trayMaterial,location:b.location}):b.type===`partial`?e=o(`inventory.assignPartialMismatchMessage`,{spoolMaterial:b.spoolMaterial,trayMaterial:b.trayMaterial,location:b.location}):b.type===`material_profile`?e=`${o(`inventory.assignMismatchMessage`,{spoolMaterial:b.spoolMaterial,trayMaterial:b.trayMaterial,location:b.location})}\n\n${o(`inventory.assignProfileMismatchMessage`,{spoolProfile:b.spoolProfile||o(`common.unknown`),trayProfile:b.trayProfile||o(`common.unknown`),location:b.location})}`:b.type===`partial_profile`&&(e=`${o(`inventory.assignPartialMismatchMessage`,{spoolMaterial:b.spoolMaterial,trayMaterial:b.trayMaterial,location:b.location})}\n\n${o(`inventory.assignProfileMismatchMessage`,{spoolProfile:b.spoolProfile||o(`common.unknown`),trayProfile:b.trayProfile||o(`common.unknown`),location:b.location})}`),e=`${e}\n\n${o(`inventory.assignReconfigureNote`)}`,(0,G.jsx)(uf,{title:o(`inventory.assignMismatchTitle`),message:e,confirmText:o(`inventory.assignMismatchConfirm`),variant:`warning`,overlayZIndex:`z-[70]`,isLoading:H.isPending,onConfirm:he,onCancel:()=>{H.isPending||(y(!1),C(null),x(null))}})})()]})}var S2e={tag_uid:null,tray_uuid:null,tag_type:null,data_origin:null};function C2e({isOpen:e,onClose:t,spool:n,mode:r,printersWithCalibrations:i=[],currencySymbol:a,onSpoolsCreated:o,spoolmanMode:s=!1,spoolsQueryKey:c=[`inventory-spools`]}){let{t:l}=U(),u=no(),{showToast:d}=Zd(),p=()=>g6(u,c),m=r===`edit`,h=r===`copy`,[g,_]=(0,f.useState)(l9),[v,y]=(0,f.useState)({}),[b,x]=(0,f.useState)(`filament`),[S,C]=(0,f.useState)(!1),[w,T]=(0,f.useState)(!1),[E,D]=(0,f.useState)(!1),[O,k]=(0,f.useState)([]),[A,j]=(0,f.useState)(!1),[M,N]=(0,f.useState)(!1),[P,F]=(0,f.useState)(1),[I,L]=(0,f.useState)(!1);(0,f.useEffect)(()=>{L(!1)},[e,n?.id]);let[R,z]=(0,f.useState)(!1),[B,V]=(0,f.useState)(!1),[ee,te]=(0,f.useState)([]),[ne,re]=(0,f.useState)(new Set),[ie,ae]=(0,f.useState)(``),[oe,se]=(0,f.useState)([]),[H,ce]=(0,f.useState)([]),[le,ue]=(0,f.useState)([]),[de,fe]=(0,f.useState)([]),[pe,me]=(0,f.useState)([]),[he,ge]=(0,f.useState)([]),[_e,ve]=(0,f.useState)([]),[ye,be]=(0,f.useState)(!1),[xe,Se]=(0,f.useState)(new Map),[Ce,we]=(0,f.useState)(new Map),[Te,Ee]=(0,f.useState)(``),De=i.length>0?i:_e,Oe=xe.size+Ce.size,{data:ke=[],isLoading:Ae,error:je}=K({queryKey:[`spoolman-inventory-filaments`],queryFn:()=>Z.getSpoolmanInventoryFilaments(),enabled:s&&e,staleTime:6e4,retry:!1});(0,f.useEffect)(()=>{ge(bU())},[]),(0,f.useEffect)(()=>{let t=!1;return e&&((async()=>{V(!0);try{let[e,n]=await Promise.allSettled([(async()=>(await Z.getCloudStatus()).is_authenticated?{connected:!0,presets:await Z.getFilamentPresets()}:{connected:!1,presets:[]})(),(async()=>(await Z.orcaCloudStatus()).connected?{connected:!0,presets:(await Z.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:[];z(r||i),te([...a,...o]),re(new Set(o.map(e=>e.setting_id)))}catch(e){if(t)return;console.error(`Failed to fetch cloud presets:`,e),z(!1)}finally{t||V(!1)}})(),Z.getSpoolCatalog().then(se).catch(console.error),Z.getColorCatalog().then(me).catch(console.error),Z.getLocalPresets().then(e=>ue(e.filament)).catch(console.error),Z.getBuiltinFilaments().then(fe).catch(console.error),Z.getLocations().then(e=>ce(e.map(e=>({id:e.id,name:e.name})))).catch(console.error),i.length===0&&(async()=>{be(!0);try{let e=await Z.getPrinters(),n=await Promise.all(e.map(e=>Z.getPrinterStatus(e.id).catch(()=>null))),r=await Promise.all(e.map(async(e,t)=>{let r=n[t],i=r?.connected??!1,a=[];return i&&(a=await pU(e.id,r)),{printer:{...e,connected:i},calibrations:a,nozzles:r?.nozzles}}));t||ve(r)}catch(e){console.error(`Failed to fetch printer calibrations:`,e)}finally{t||be(!1)}})()),()=>{t=!0}},[e,i.length]);let Me=(0,f.useMemo)(()=>gU(ee,new Set,le,de,ne),[ee,le,de,ne]),Ne=(0,f.useMemo)(()=>{let e=hU(ee,le),t=pe.map(e=>e.manufacturer?.trim()).filter(e=>!!e),n=new Set([...e,...t]);return Array.from(n).sort((e,t)=>e.localeCompare(t))},[ee,le,pe]),Pe=(0,f.useMemo)(()=>{let e=pe.map(e=>e.material?.trim()).filter(e=>!!e),t=new Set([...oU,...e]);return Array.from(t).sort((e,t)=>e.localeCompare(t))},[pe]),Fe=(0,f.useMemo)(()=>{let e=[];for(let t of pe){let n=t.manufacturer?.trim(),r=t.material?.trim();n&&r&&e.push({brand:n,material:r})}for(let t of ee){let n=mU(t.name);n.brand&&n.material&&e.push({brand:n.brand,material:n.material})}for(let t of le){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},[ee,pe,le]),Ie=(0,f.useMemo)(()=>{let e=new Map;for(let t of Fe){let n=t.brand.toLowerCase(),r=t.material.toLowerCase();e.has(n)||e.set(n,new Set),e.get(n).add(r)}return e},[Fe]),Le=(0,f.useMemo)(()=>{let e=new Map;for(let t of Fe){let n=t.brand.toLowerCase(),r=t.material.toLowerCase();e.has(r)||e.set(r,new Set),e.get(r).add(n)}return e},[Fe]),Re=(0,f.useMemo)(()=>vU(Ne,g.brand),[Ne,g.brand]),ze=(0,f.useMemo)(()=>vU(Pe,g.material),[Pe,g.material]),Be=(0,f.useMemo)(()=>yU(Re,g.material,Le),[Re,g.material,Le]),Ve=(0,f.useMemo)(()=>yU(ze,g.brand,Ie),[ze,g.brand,Ie]),He=(0,f.useMemo)(()=>_U(g.slicer_filament,Me),[g.slicer_filament,Me]);(0,f.useEffect)(()=>{if(e){if(n){let e=n.rgba&&/^[0-9A-Fa-f]{8}$/.test(n.rgba)?n.rgba:`808080FF`;if(_({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:h?0:n.weight_used||0,slicer_filament:n.slicer_filament||``,note:n.note||``,cost_per_kg:n.cost_per_kg??null,category:n.category||``,low_stock_threshold_pct:n.low_stock_threshold_pct??null,material_number:n.material_number||``,location_id:n.location_id??null,spoolman_filament_id:null}),ae(n.slicer_filament_name||n.slicer_filament||``),n.k_profiles&&n.k_profiles.length>0){let e=new Map;for(let t of n.k_profiles){if(t.cali_idx===null||t.cali_idx===void 0)continue;let n=(t.nozzle_diameter||``).trim()||`0.4`,r=t.extruder??0;e.set(wU(t.printer_id,r,n),{cali_idx:t.cali_idx,filament_id:``,setting_id:t.setting_id||``,name:t.name||``,k_value:t.k_value,n_coef:0,extruder_id:r,nozzle_diameter:n,nozzle_id:t.nozzle_type||``})}Se(e)}else Se(new Map);k((n.suppliers??[]).map(e=>({supplier_id:e.supplier_id,supplier_name:e.supplier_name,supplier_article_number:e.supplier_article_number??``,quoted_price_per_kg:e.quoted_price_per_kg,is_purchase_source:h?!1:e.is_purchase_source})))}else _(l9),ae(``),Se(new Map),k([]);N(!1),F(1),y({}),x(`filament`),Ee(``),we(new Map),C(!1),T(h&&n?.core_weight_is_inherited===!1),D(!1),j(!1)}},[e,n,r,h]),(0,f.useEffect)(()=>{if(!e||!n)return;let t=!1;return(s?Z.getSpoolmanFilamentPresets:Z.getSpoolFilamentPresets)(n.id).then(e=>{if(t)return;let n=new Map;for(let t of e)n.set(TU(t.printer_model,t.nozzle_diameter||``),{code:t.slicer_filament||``,name:t.slicer_filament_name||``});we(n)}).catch(e=>{t||(console.error(`Failed to load filament preset overrides:`,e),d(l(`inventory.filamentPresetsLoadFailed`),`warning`))}),()=>{t=!0}},[e,n?.id,s]),(0,f.useEffect)(()=>{if(!e||!n||E||g.location_id!=null)return;let t=n.storage_location?.trim();if(!t||H.length===0)return;let r=H.find(e=>e.name.toLowerCase()===t.toLowerCase());r&&_(e=>e.location_id===r.id?e:{...e,location_id:r.id})},[e,n,H,g.location_id,E]);let Ue=(e,t)=>{let n=z0e.has(e);s&&n&&g.spoolman_filament_id!==null&&d(l(`inventory.spoolmanFilamentUnlinked`),`info`),_(r=>({...r,[e]:t,...s&&n&&r.spoolman_filament_id!==null?{spoolman_filament_id:null}:{}})),e===`weight_used`&&C(!0),e===`core_weight`&&T(!0),e===`location_id`&&D(!0),v[e]&&y(t=>({...t,[e]:void 0}))},We=e=>{let t=e.material||``,n=e.name||``,r=t&&n.startsWith(t)?n.slice(t.length).trim():n,i=(e.color_hex??``).replace(`#`,``).toUpperCase(),a=/^[0-9A-F]{6}(?:[0-9A-F]{2})?$/.test(i)?i:`808080`,o=a.length===8?a:`${a}FF`;_(n=>({...n,spoolman_filament_id:e.id,material:t,subtype:r,brand:e.vendor?.name||``,rgba:o,color_name:e.color_name||``,label_weight:e.weight??n.label_weight})),d(l(`inventory.spoolmanFilamentSelected`),`success`)},Ge=e=>{ge(t=>xU(e,t))},Ke=q({mutationFn:e=>s?Z.createSpoolmanInventorySpool(e):Z.createSpool(e),onSuccess:async e=>{e?.id&&(!await dt(e.id)||!await ut(e.id))||(await p(),o&&o([e]),d(l(`inventory.spoolCreated`),`success`),t())},onError:e=>{e instanceof sd&&e.status===503?d(l(`inventory.spoolmanUnreachable`),`error`):d(l(`inventory.saveFailed`),`error`)}}),qe=q({mutationFn:({data:e,qty:t})=>s?Z.bulkCreateSpoolmanInventorySpools(e,t):Z.bulkCreateSpools(e,t),onSuccess:async e=>{let n=s&&`created`in e?e:null,r=n?n.created:e;if(xe.size>0||Ce.size>0)for(let e of r)await dt(e.id);if(lt)for(let e of r)await ut(e.id);await p(),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 sd&&e.status===503?d(l(`inventory.spoolmanUnreachable`),`error`):d(l(`inventory.saveFailed`),`error`)}}),Je=q({mutationFn:e=>s?Z.updateSpoolmanInventorySpool(n.id,e):Z.updateSpool(n.id,e),onSuccess:async()=>{n?.id&&(!await dt(n.id)||!await ut(n.id))||(await p(),d(l(`inventory.spoolUpdated`),`success`),t())},onError:e=>{e instanceof sd&&e.status===503?d(l(`inventory.spoolmanUnreachable`),`error`):d(l(`inventory.saveFailed`),`error`)}}),Ye=q({mutationFn:()=>s?Z.updateSpoolmanInventorySpool(n.id,S2e):Z.updateSpool(n.id,S2e),onSuccess:async()=>{await p(),d(l(`inventory.rfidCleared`,`RFID tag cleared`),`success`),t()},onError:e=>{e instanceof sd&&e.status===503?d(l(`inventory.spoolmanUnreachable`),`error`):d(l(`inventory.tagClearFailed`),`error`)}}),{data:Xe,isLoading:Ze}=K({queryKey:[`spool-assignments`],queryFn:()=>Z.getAssignments(),enabled:e&&m&&!s}),{data:Qe,isLoading:$e}=K({queryKey:[`spoolman-slot-assignments-all`],queryFn:()=>Z.getSpoolmanSlotAssignments(),enabled:e&&m&&s}),et=(()=>{if(n)return s?Qe?.find(e=>e.spoolman_spool_id===n.id):Xe?.find(e=>e.spool_id===n.id)})(),tt=s?$e:Ze,{data:nt}=K({queryKey:[`inventory-spools`],queryFn:()=>Z.getSpools(!0),enabled:e}),{data:rt}=K({queryKey:[`settings`],queryFn:Z.getSettings,enabled:e}),{data:it}=K({queryKey:[`slicerPrinterModels`],queryFn:Z.getSlicerPrinterModels,enabled:e,staleTime:1/0}),at=(()=>{let e=new Set;for(let t of nt??[]){let n=t.category?.trim();n&&e.add(n)}return Array.from(e).sort((e,t)=>e.localeCompare(t))})(),ot=(()=>{let e=new Set;for(let t of nt??[]){let n=t.material_number?.trim();n&&e.add(n)}return Array.from(e).sort((e,t)=>e.localeCompare(t,void 0,{numeric:!0}))})(),st=rt?.low_stock_threshold??20,ct=q({mutationFn:async()=>{if(!et)throw Error(`No assignment`);if(s){if(!n)throw Error(`No spool`);await Z.unassignSpoolmanSlot(n.id);return}await Z.unassignSpool(et.printer_id,et.ams_id,et.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`)}}),lt=A||h,ut=async e=>{if(!lt)return!0;let t=s?Z.setSpoolmanSpoolSuppliers:Z.setSpoolSuppliers;try{return await t(e,O.map(e=>({supplier_id:e.supplier_id,supplier_article_number:e.supplier_article_number.trim()||null,quoted_price_per_kg:e.quoted_price_per_kg,is_purchase_source:e.is_purchase_source}))),!0}catch(e){return console.error(`SpoolFormModal.saveSupplierLinks failed:`,e),d(l(`inventory.suppliers.saveFailed`),`error`),!1}},dt=async e=>{let t=s?Z.saveSpoolmanKProfiles:Z.saveSpoolKProfiles,n=s?Z.saveSpoolmanFilamentPresets:Z.saveSpoolFilamentPresets,r=[];for(let[e,t]of xe){let[n,i,a]=e.split(`:`);r.push({printer_id:parseInt(n),extruder:parseInt(i),nozzle_diameter:a||`0.4`,nozzle_type:f9(t.nozzle_id),k_value:t.k_value,name:t.name||null,cali_idx:t.cali_idx,setting_id:t.setting_id||null})}let i=[];for(let[e,t]of Ce){let{model:n,diameter:r}=IAe(e);n&&i.push({printer_model:n,nozzle_diameter:r,slicer_filament:t.code||null,slicer_filament_name:t.name||null})}try{await t(e,r)}catch(e){return console.error(`Failed to save K-profiles:`,e),d(l(`inventory.kProfileSaveFailed`),`warning`),!1}try{await n(e,i)}catch(e){return console.error(`Failed to save filament preset overrides:`,e),d(l(`inventory.filamentPresetSaveFailed`),`warning`),!1}return!0};if((0,f.useEffect)(()=>{if(!e)return;let n=e=>{e.key===`Escape`&&!I&&t()};return document.addEventListener(`keydown`,n),()=>document.removeEventListener(`keydown`,n)},[e,t,I]),!e)return null;let ft=()=>{let e=B0e(g,M,s,r);if(!e.isValid){y(e.errors),(e.errors.slicer_filament||e.errors.material||e.errors.brand||e.errors.subtype)&&x(`filament`);return}let t=He?.displayName||ie||null,n={material:g.material||null,subtype:g.subtype||null,brand:g.brand||null,color_name:g.color_name||null,rgba:g.rgba||null,extra_colors:g.extra_colors||null,effect_type:g.effect_type||null,label_weight:g.label_weight,...s?w?{core_weight:g.core_weight}:{}:{core_weight:g.core_weight,core_weight_catalog_id:g.core_weight_catalog_id},slicer_filament:g.slicer_filament||null,slicer_filament_name:t,nozzle_temp_min:null,nozzle_temp_max:null,note:g.note||null,cost_per_kg:g.cost_per_kg,category:g.category.trim()||null,low_stock_threshold_pct:g.low_stock_threshold_pct,material_number:g.material_number.trim()||null,...s?{spoolman_filament_id:g.spoolman_filament_id}:{}};(!m||S)&&(n.weight_used=g.weight_used),(!m||E)&&(n.location_id=g.location_id),m?Je.mutate(n):P>1?qe.mutate({data:n,qty:P}):Ke.mutate(n)},pt=Ke.isPending||qe.isPending||Je.isPending||Ye.isPending||ct.isPending;return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[(0,G.jsx)(`div`,{className:`absolute inset-0 bg-black/60 backdrop-blur-sm`,onClick:t}),(0,G.jsxs)(`div`,{className:`relative w-full max-w-5xl mx-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl shadow-2xl max-h-[90vh] flex flex-col`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary flex-shrink-0`,children:[(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-baseline gap-2`,children:[l(m?`inventory.editSpool`:h?`inventory.copySpool`:`inventory.addSpool`),m&&n&&(0,G.jsxs)(`span`,{className:`text-sm font-mono text-bambu-gray`,children:[`#`,n.id]})]}),(0,G.jsx)(`button`,{onClick:t,className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]}),r===`create`&&(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2 border-b border-bambu-dark-tertiary flex-shrink-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(id,{className:`w-4 h-4 text-amber-600 dark:text-amber-400`}),(0,G.jsx)(`span`,{className:`text-sm text-white`,children:l(`inventory.quickAdd`)})]}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>{N(!M),M||x(`filament`)},className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors ${M?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,children:(0,G.jsx)(`span`,{className:`inline-block h-3.5 w-3.5 rounded-full bg-white transition-transform ${M?`translate-x-4`:`translate-x-0.5`}`})})]}),(0,G.jsxs)(`div`,{className:`flex border-b border-bambu-dark-tertiary flex-shrink-0`,children:[(0,G.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,G.jsx)(zo,{className:`w-4 h-4`}),l(`inventory.filamentInfoTab`)]}),!M&&(0,G.jsxs)(`button`,{onClick:()=>x(`appearance`),className:`flex-1 px-4 py-2.5 text-sm font-medium flex items-center justify-center gap-2 transition-colors ${b===`appearance`?`text-bambu-green border-b-2 border-bambu-green`:`text-bambu-gray hover:text-white`}`,children:[(0,G.jsx)(xl,{className:`w-4 h-4`}),l(`inventory.colorAndCostTab`)]}),!M&&(0,G.jsxs)(`button`,{onClick:()=>x(`printers`),className:`flex-1 px-4 py-2.5 text-sm font-medium flex items-center justify-center gap-2 transition-colors ${b===`printers`?`text-bambu-green border-b-2 border-bambu-green`:`text-bambu-gray hover:text-white`}`,children:[(0,G.jsx)(id,{className:`w-4 h-4`}),l(`inventory.printersTab`),Oe>0&&(0,G.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded-full bg-bambu-green/20 text-bambu-green`,children:Oe})]})]}),(0,G.jsx)(`div`,{className:`p-4 overflow-y-auto flex-1`,style:{scrollbarGutter:`stable`},children:b===`filament`?(0,G.jsxs)(`div`,{className:`space-y-6`,children:[s&&!m&&(0,G.jsx)(`div`,{children:je?(0,G.jsx)(`p`,{className:`text-sm text-red-700 dark:text-red-400 px-1`,children:l(`inventory.spoolmanCatalogLoadFailed`)}):(0,G.jsx)(X0e,{filaments:ke,isLoading:Ae,selectedId:g.spoolman_filament_id,onSelect:We})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`text-sm font-semibold text-bambu-gray uppercase tracking-wide mb-3`,children:l(`inventory.filamentInfo`)}),(0,G.jsx)(W0e,{formData:g,updateField:Ue,cloudAuthenticated:R,loadingCloudPresets:B,presetInputValue:ie,setPresetInputValue:ae,selectedPresetOption:He,filamentOptions:Me,availableBrands:Re,availableMaterials:ze,suggestedBrands:Be,suggestedMaterials:Ve,quickAdd:M,detailsRequired:!M&&!s&&r===`create`,quantity:P,onQuantityChange:F,errors:v})]})]}):b===`appearance`?(0,G.jsxs)(`div`,{className:`space-y-6`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`text-sm font-semibold text-bambu-gray uppercase tracking-wide mb-3`,children:l(`inventory.color`)}),(0,G.jsx)(K0e,{formData:g,updateField:Ue,recentColors:he,onColorUsed:Ge,catalogColors:pe})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`text-sm font-semibold text-bambu-gray uppercase tracking-wide mb-3`,children:l(`inventory.additional`)}),(0,G.jsx)(J0e,{formData:g,updateField:Ue,spoolCatalog:oe,currencySymbol:a,availableCategories:at,availableMaterialNumbers:ot,availableLocations:H,onCreateLocation:async e=>{try{let t=await Z.createLocation({name:e});return ce(e=>[...e,{id:t.id,name:t.name}].sort((e,t)=>e.name.localeCompare(t.name))),await p6(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:st,spoolmanMode:s})]}),(0,G.jsx)(`div`,{children:(0,G.jsx)(Y0e,{links:O,onChange:e=>{k(e),j(!0)},currencySymbol:a})}),m&&n&&!s&&(0,G.jsx)(`div`,{children:(0,G.jsx)(r2e,{spoolId:n.id})})]}):(0,G.jsx)(e2e,{formData:g,printersWithCalibrations:De,filamentOptions:Me,modelPresets:Ce,setModelPresets:we,selectedProfiles:xe,setSelectedProfiles:Se,selectedGroupId:Te,setSelectedGroupId:Ee,printerModels:it,isLoading:ye})}),(0,G.jsxs)(`div`,{className:`flex gap-2 p-4 border-t border-bambu-dark-tertiary flex-shrink-0`,children:[m&&(0,G.jsxs)(`div`,{className:`flex gap-2 mr-auto`,children:[(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>Ye.mutate(),disabled:pt||!(n?.tag_uid||n?.tray_uuid),children:[(0,G.jsx)(wu,{className:`w-4 h-4`}),l(`inventory.clearRfid`,`Clear RFID Tag`)]}),et?(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>ct.mutate(),disabled:pt||tt,children:[(0,G.jsx)(Bu,{className:`w-4 h-4`}),l(`inventory.unassignSpool`,`Unassign`)]}):(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>L(!0),disabled:pt||tt,children:[(0,G.jsx)(Kc,{className:`w-4 h-4`}),l(`inventory.assignSpool`,`Assign Spool`)]})]}),(0,G.jsxs)(`div`,{className:`flex gap-2 ml-auto`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:t,children:l(`common.cancel`)}),(0,G.jsx)(Q,{onClick:ft,disabled:pt,children:pt?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),l(`common.saving`)]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Wl,{className:`w-4 h-4`}),l(m?`common.save`:h?`inventory.copySpool`:`inventory.addSpool`)]})})]})]})]})]}),m&&n&&(0,G.jsx)(b9,{isOpen:I,onClose:()=>L(!1),spool:n,printerId:null,variant:`dialog`,spoolmanMode:s})]})}var x9=[{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.`}],w2e={avery_l7160:21,avery_5160:30},T2e=[203,300,600],E2e={brand:{i18nKey:`brand`,fallback:`Brand`},material:{i18nKey:`material`,fallback:`Material and subtype`},hex:{i18nKey:`hex`,fallback:`Colour code`},name:{i18nKey:`name`,fallback:`Colour or filament name`},location:{i18nKey:`location`,fallback:`Storage location`},material_number:{i18nKey:`materialNumber`,fallback:`Material number`},temps:{i18nKey:`temps`,fallback:`Nozzle temperature`},weight:{i18nKey:`weight`,fallback:`Net weight`},note:{i18nKey:`note`,fallback:`Note`},added:{i18nKey:`added`,fallback:`Date added`},qr:{i18nKey:`qr`,fallback:`QR code`},spool_id:{i18nKey:`spoolId`,fallback:`Spool ID`}},D2e=`bambuddy-label-print-options`,S9={template:x9[0].value,fields:{},monochrome:!1,format:`pdf`,dpi:300};function O2e(){let e;try{e=JSON.parse(localStorage.getItem(D2e)??`null`)}catch{return S9}if(!e||typeof e!=`object`)return S9;let t=e,n=x9.map(e=>e.value),r={};if(t.fields&&typeof t.fields==`object`)for(let[e,i]of Object.entries(t.fields))!n.includes(e)||!Array.isArray(i)||(r[e]=i.filter(e=>Cd.includes(e)));return{template:n.includes(t.template)?t.template:S9.template,fields:r,monochrome:t.monochrome===!0,format:t.format===`png`?`png`:`pdf`,dpi:T2e.includes(t.dpi)?t.dpi:S9.dpi}}function k2e(e){try{localStorage.setItem(D2e,JSON.stringify(e))}catch{}}function A2e(e,t){return e.fields[t]??wd}function j2e(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 M2e(e,t){let n=window.URL.createObjectURL(e),r=document.createElement(`a`);r.href=n,r.download=`bambuddy-labels-${t}.${e.type===`application/zip`?`zip`:`png`}`,document.body.appendChild(r),r.click(),document.body.removeChild(r),setTimeout(()=>window.URL.revokeObjectURL(n),6e4)}function N2e(e){return If(e)}function P2e(e){return Nf(e.color_name,e.rgba,e.color_name_is_synthesized)}function F2e(e){return`${P2e(e)??`${e.material}${e.subtype?` ${e.subtype}`:``}`}${e.brand?` · ${e.brand}`:``}`}function I2e(e){return[P2e(e),e.color_name,e.material,e.subtype,e.brand,`#${e.id}`].filter(Boolean).join(` `).toLowerCase()}function L2e(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 R2e({isOpen:e,onClose:t,availableSpools:n,initialSelectedIds:r,spoolmanMode:i}){let{t:a}=U(),o=zf(),{showToast:s}=Zd(),[c,l]=(0,f.useState)(!1),[u,d]=(0,f.useState)(new Set),[p,m]=(0,f.useState)(``),[h,g]=(0,f.useState)(``),[_,v]=(0,f.useState)(`id`),[y,b]=(0,f.useState)(S9),[x,S]=(0,f.useState)(`1`),[C,w]=(0,f.useState)(null),[T,E]=(0,f.useState)(!1),[D,O]=(0,f.useState)(null),k=(0,f.useRef)(null);(0,f.useEffect)(()=>{if(e){let e=new Set(n.map(e=>e.id));d(new Set(r.filter(t=>e.has(t)))),m(``),g(``),v(`id`),b(O2e()),S(`1`),l(!1)}},[e]);let A=(0,f.useMemo)(()=>{let e=[...n];return _===`color`?(e.sort((e,t)=>{let n=L2e(e.rgba),r=L2e(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,_]),j=(0,f.useMemo)(()=>{let e=new Set;for(let t of A)t.material&&e.add(t.material.toUpperCase());return[...e].sort()},[A]),M=(0,f.useMemo)(()=>{let e=p.trim().toLowerCase();return A.filter(t=>!(h&&(t.material||``).toUpperCase()!==h||e&&!I2e(t).includes(e)))},[A,p,h,o]),N=M.length>0&&M.every(e=>u.has(e.id)),P=y.template,F=A2e(y,P),I=F.join(`,`),L=A.find(e=>u.has(e.id))?.id??null;function R(e){k.current&&window.URL.revokeObjectURL(k.current),k.current=e,w(e)}if((0,f.useEffect)(()=>{if(!e||L===null){R(null),O(null),E(!1);return}let t=new AbortController;E(!0);let n=window.setTimeout(async()=>{let e={spool_id:L,template:P,monochrome:y.monochrome,fields:I?I.split(`,`):[]};try{let n=i?await Z.previewSpoolmanSpoolLabel(e,t.signal):await Z.previewSpoolLabel(e,t.signal);if(t.signal.aborted)return;R(window.URL.createObjectURL(n)),O(null)}catch(e){if(t.signal.aborted)return;R(null),O(e instanceof Error?e.message:String(e))}finally{t.signal.aborted||E(!1)}},250);return()=>{window.clearTimeout(n),t.abort()}},[e,L,P,I,y.monochrome,i]),(0,f.useEffect)(()=>()=>{k.current&&window.URL.revokeObjectURL(k.current)},[]),!e)return null;let z=u.size,B=z===0,V=w2e[P],ee=Number(x),te=V===void 0||Number.isInteger(ee)&&ee>=1&&ee<=V,ne=x9.find(e=>e.value===P)??x9[0];function re(e){b(t=>{let n={...t,...e};return k2e(n),n})}function ie(e){let t=Cd.filter(t=>e.includes(t));re({fields:{...y.fields,[P]:t}})}function ae(e){ie(F.includes(e)?F.filter(t=>t!==e):[...F,e])}function oe(e){d(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function se(){d(e=>{let t=new Set(e);for(let e of M)t.add(e.id);return t})}function H(){d(e=>{let t=new Set(e);for(let e of M)t.delete(e.id);return t})}function ce(){d(new Set)}async function le(){if(B||c||!te)return;let e={spool_ids:A.filter(e=>u.has(e.id)).map(e=>e.id),template:P,monochrome:y.monochrome,starting_position:V===void 0?1:ee,fields:F,format:y.format,dpi:y.dpi};l(!0);try{let n=i?await Z.printSpoolmanSpoolLabels(e):await Z.printSpoolLabels(e);y.format===`pdf`?j2e(n):M2e(n,P),t()}catch(e){s(a(`inventory.labels.error`,`Could not generate labels: {{msg}}`,{msg:e instanceof Error?e.message:String(e)}),`error`)}finally{l(!1)}}let ue=e=>`px-2 py-0.5 text-xs rounded-full border transition ${e?`bg-bambu-green text-bambu-dark border-bambu-green`:`bg-bambu-dark text-bambu-gray border-bambu-dark-tertiary hover:border-bambu-gray`}`;return(0,G.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-start sm:items-center justify-center p-4 overflow-y-auto`,children:[(0,G.jsx)(`div`,{className:`absolute inset-0 bg-black/60 backdrop-blur-sm`,onClick:t}),(0,G.jsxs)(`div`,{"data-testid":`label-template-picker-panel`,className:`relative w-full max-w-5xl bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl shadow-2xl max-h-[90vh] overflow-clip flex flex-col my-auto`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Fl,{className:`w-5 h-5 text-bambu-green`}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:a(`inventory.labels.title`,`Print spool labels`)}),z>0&&(0,G.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[`(`,a(`inventory.labels.selectedCount`,`{{count}} selected`,{count:z}),`)`]})]}),(0,G.jsx)(`button`,{onClick:t,className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,"aria-label":a(`common.close`,`Close`),children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]}),(0,G.jsxs)(`div`,{className:`flex-1 min-h-0 overflow-y-auto md:overflow-hidden grid grid-cols-1 md:grid-cols-2`,children:[(0,G.jsxs)(`div`,{className:`flex flex-col min-h-0 md:border-r border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`p-4 space-y-2 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(Yl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`}),(0,G.jsx)(`input`,{type:`search`,value:p,onChange:e=>m(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`})]}),j.length>1&&(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray mr-1`,children:a(`inventory.labels.filterByMaterial`,`Material:`)}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>g(``),className:`px-2 py-0.5 text-xs rounded-full border transition ${h===``?`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`)}),j.map(e=>(0,G.jsx)(`button`,{type:`button`,onClick:()=>g(e),className:`px-2 py-0.5 text-xs rounded-full border transition ${h===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,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray mr-1`,children:a(`inventory.labels.sortBy.label`)}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>v(`id`),className:`px-2 py-0.5 text-xs rounded-full border transition ${_===`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,G.jsx)(`button`,{type:`button`,onClick:()=>v(`color`),className:`px-2 py-0.5 text-xs rounded-full border transition ${_===`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,G.jsxs)(`div`,{className:`px-4 pt-3 pb-2 flex items-center justify-between gap-3 flex-wrap`,children:[(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:a(`inventory.labels.pickSpools`,`Pick which spools to print labels for:`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-3 text-xs`,children:[(0,G.jsx)(`button`,{type:`button`,onClick:N?H:se,disabled:M.length===0,className:`text-bambu-green hover:underline disabled:opacity-50 disabled:no-underline disabled:cursor-not-allowed`,children:N?a(`inventory.labels.deselectVisible`,`Deselect visible`):a(`inventory.labels.selectVisible`,`Select all visible ({{count}})`,{count:M.length})}),(0,G.jsx)(`button`,{type:`button`,onClick:ce,disabled:z===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,G.jsx)(`div`,{className:`flex-1 overflow-y-auto px-2 pb-2 min-h-0 max-h-72 md:max-h-none`,children:M.length===0?(0,G.jsx)(`div`,{className:`text-center text-sm text-bambu-gray py-6`,children:A.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,G.jsx)(`ul`,{className:`space-y-0.5`,children:M.map(e=>{let t=u.has(e.id);return(0,G.jsx)(`li`,{children:(0,G.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,G.jsx)(hu,{className:`w-4 h-4 text-bambu-green shrink-0`}):(0,G.jsx)(_u,{className:`w-4 h-4 text-bambu-gray shrink-0`}),(0,G.jsx)(`input`,{type:`checkbox`,checked:t,onChange:()=>oe(e.id),className:`sr-only`}),(0,G.jsx)(`span`,{className:`w-4 h-4 rounded border border-black/20 shrink-0`,style:N2e(e.rgba)}),(0,G.jsx)(`span`,{className:`flex-1 min-w-0 truncate text-sm text-white`,children:F2e(e)}),(0,G.jsxs)(`span`,{className:`text-xs font-mono text-bambu-gray shrink-0`,children:[`#`,e.id]})]})},e.id)})})})]}),(0,G.jsxs)(`div`,{className:`md:overflow-y-auto p-4 space-y-4 border-t md:border-t-0 border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`space-y-1`,children:[(0,G.jsx)(`label`,{htmlFor:`label-template`,className:`text-sm font-medium text-white`,children:a(`inventory.labels.template`,`Label size`)}),(0,G.jsx)(`select`,{id:`label-template`,"data-testid":`label-template-select`,value:P,onChange:e=>re({template:e.target.value}),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`,children:x9.map(e=>(0,G.jsx)(`option`,{value:e.value,children:a(`inventory.labels.templates.${e.i18nKey}.label`,e.fallbackLabel)},e.value))}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:a(`inventory.labels.templates.${ne.i18nKey}.hint`,ne.fallbackHint)})]}),(0,G.jsxs)(`div`,{className:`space-y-1`,children:[(0,G.jsx)(`div`,{className:`text-sm font-medium text-white`,children:L===null?a(`inventory.labels.preview`,`Preview`):a(`inventory.labels.previewOf`,`Preview of #{{id}}`,{id:L})}),(0,G.jsxs)(`div`,{"data-testid":`label-preview`,className:`relative flex items-center justify-center min-h-40 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary`,children:[L===null?(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray text-center`,children:a(`inventory.labels.previewNoSelection`,`Select a spool to see its label.`)}):D?(0,G.jsx)(`span`,{className:`text-sm text-red-400 text-center`,children:a(`inventory.labels.previewError`,`Could not render the preview: {{msg}}`,{msg:D})}):C?(0,G.jsx)(`img`,{src:C,alt:a(`inventory.labels.previewAlt`,`Label preview`),className:`max-h-56 max-w-full object-contain bg-white shadow`}):null,T&&(0,G.jsx)(Y,{className:`absolute top-2 right-2 w-4 h-4 animate-spin text-bambu-green`})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:a(`inventory.labels.previewHint`,`Lines that don't fit on this label size are left out.`)})]}),(0,G.jsxs)(`fieldset`,{className:`space-y-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,G.jsx)(`legend`,{className:`text-sm font-medium text-white`,children:a(`inventory.labels.content`,`Print on the label`)}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>ie(wd),className:`text-xs text-bambu-green hover:underline`,children:a(`inventory.labels.resetFields`,`Reset to default`)})]}),(0,G.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-x-3 gap-y-1`,children:Cd.map(e=>{let t=F.includes(e),{i18nKey:n,fallback:r}=E2e[e];return(0,G.jsxs)(`label`,{className:`flex items-center gap-2 py-0.5 cursor-pointer select-none`,children:[t?(0,G.jsx)(hu,{className:`w-4 h-4 text-bambu-green shrink-0`}):(0,G.jsx)(_u,{className:`w-4 h-4 text-bambu-gray shrink-0`}),(0,G.jsx)(`input`,{type:`checkbox`,"data-testid":`label-field-${e}`,checked:t,onChange:()=>ae(e),className:`sr-only`}),(0,G.jsx)(`span`,{className:`text-sm text-white`,children:a(`inventory.labels.fields.${n}`,r)})]},e)})})]}),(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(`label`,{className:`inline-flex items-center gap-2 cursor-pointer select-none`,children:[y.monochrome?(0,G.jsx)(hu,{className:`w-4 h-4 text-bambu-green shrink-0`}):(0,G.jsx)(_u,{className:`w-4 h-4 text-bambu-gray shrink-0`}),(0,G.jsx)(`input`,{type:`checkbox`,checked:y.monochrome,onChange:e=>re({monochrome:e.target.checked}),className:`sr-only`}),(0,G.jsx)(`span`,{className:`text-sm text-white`,children:a(`inventory.labels.monochrome`,`Monochrome (black & white printer)`)}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:a(`inventory.labels.monochromeHint`,`Drops the colour swatch and widens the text`)})]}),V!==void 0&&(0,G.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,G.jsx)(`label`,{htmlFor:`label-starting-position`,className:`text-sm text-white whitespace-nowrap pt-1.5`,children:a(`inventory.labels.startingPosition`,`Starting label position`)}),(0,G.jsx)(`input`,{id:`label-starting-position`,"data-testid":`label-starting-position`,type:`number`,min:1,max:V,step:1,value:x,onChange:e=>S(e.target.value),"aria-describedby":`label-starting-position-help`,className:`w-20 px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:outline-none focus:border-bambu-green`}),(0,G.jsx)(`div`,{id:`label-starting-position-help`,"data-testid":`label-starting-position-status`,className:`text-xs pt-1.5 ${te?`text-bambu-gray`:`text-red-400`}`,children:te?ee===1?a(`inventory.labels.startingPositionFirst`,`Printing starts at position 1.`):a(`inventory.labels.startingPositionSkipped`,`Positions 1 through {{lastPosition}} will be left blank on the first sheet.`,{lastPosition:ee-1}):a(`inventory.labels.startingPositionInvalid`,`Enter a whole number from 1 to {{capacity}}.`,{capacity:V})})]}),(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,G.jsx)(`span`,{className:`text-sm text-white mr-1`,children:a(`inventory.labels.format`,`Output:`)}),(0,G.jsx)(`button`,{type:`button`,"data-testid":`label-format-pdf`,"aria-pressed":y.format===`pdf`,onClick:()=>re({format:`pdf`}),className:ue(y.format===`pdf`),children:`PDF`}),(0,G.jsx)(`button`,{type:`button`,"data-testid":`label-format-png`,"aria-pressed":y.format===`png`,onClick:()=>re({format:`png`}),className:ue(y.format===`png`),children:`PNG`}),y.format===`png`&&(0,G.jsx)(`select`,{"data-testid":`label-dpi-select`,"aria-label":a(`inventory.labels.dpi`,`Resolution`),value:y.dpi,onChange:e=>re({dpi:Number(e.target.value)}),className:`ml-2 px-2 py-0.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-xs focus:outline-none focus:border-bambu-green`,children:T2e.map(e=>(0,G.jsxs)(`option`,{value:e,children:[e,` dpi`]},e))})]}),y.format===`png`&&(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:a(`inventory.labels.pngHint`,`For label printer software that takes images. Match your printer's resolution; several labels come as a ZIP.`)})]})]})]}),(0,G.jsxs)(`div`,{className:`flex justify-end gap-2 px-5 py-3 border-t border-bambu-dark-tertiary`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:t,disabled:c,children:a(`common.cancel`,`Cancel`)}),(0,G.jsxs)(Q,{"data-testid":`label-print-button`,onClick:le,disabled:B||c||!te,children:[c?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):y.format===`pdf`?(0,G.jsx)(Fl,{className:`w-4 h-4`}):(0,G.jsx)(Gs,{className:`w-4 h-4`}),y.format===`pdf`?a(`inventory.labels.createPdf`,`Create PDF`):a(`inventory.labels.downloadPng`,`Download PNG`)]})]})]})]})}function z2e({onClose:e,onImported:t}){let{t:n}=U(),[r,i]=(0,f.useState)(null),[a,o]=(0,f.useState)(!1),[s,c]=(0,f.useState)(null),[l,u]=(0,f.useState)(!1),[d,p]=(0,f.useState)(!1),[m,h]=(0,f.useState)(null),g=(0,f.useRef)(null),_=async e=>{i(e),c(null),h(null),u(!0);try{c(await Z.importSpoolsCsvPreview(e))}catch(e){h(e instanceof Error?e.message:n(`inventory.csv.previewError`,`Could not read the CSV file`))}finally{u(!1)}},v=e=>{let t=e.target.files?.[0];t&&_(t)},y=e=>{e.preventDefault(),o(!1);let t=e.dataTransfer.files?.[0];t&&_(t)},b=async()=>{if(r){p(!0),h(null);try{t((await Z.importSpoolsCsv(r)).created)}catch(e){h(e instanceof Error?e.message:n(`inventory.csv.importError`,`Import failed`)),p(!1)}}},x=e=>e===`valid`?(0,G.jsx)(hs,{className:`w-4 h-4 text-green-500 flex-shrink-0`}):e===`error`?(0,G.jsx)(xs,{className:`w-4 h-4 text-red-500 flex-shrink-0`}):(0,G.jsx)(vs,{className:`w-4 h-4 text-bambu-gray flex-shrink-0`}),S=s?.valid_count??0;return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,G.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,G.jsxs)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary flex items-center justify-between`,children:[(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:n(`inventory.csv.modalTitle`,`Import spools from CSV`)}),(0,G.jsx)(`button`,{onClick:e,className:`p-1 hover:bg-bambu-dark rounded`,children:(0,G.jsx)(nd,{className:`w-5 h-5 text-bambu-gray`})})]}),(0,G.jsxs)(`div`,{className:`p-4 space-y-4 overflow-y-auto flex-1`,children:[(0,G.jsxs)(`div`,{onDragOver:e=>{e.preventDefault(),o(!0)},onDragLeave:e=>{e.preventDefault(),o(!1)},onDrop:y,onClick:()=>g.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,G.jsx)(Vu,{className:`w-9 h-9 mx-auto mb-2 ${a?`text-bambu-green`:`text-bambu-gray`}`}),r?(0,G.jsxs)(`p`,{className:`text-white font-medium flex items-center justify-center gap-2`,children:[(0,G.jsx)(sc,{className:`w-4 h-4`}),` `,r.name]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`p`,{className:`text-white font-medium`,children:n(`inventory.csv.selectFile`,`Choose a CSV file or drag it here`)}),(0,G.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,G.jsx)(`input`,{ref:g,type:`file`,accept:`.csv,text/csv`,className:`hidden`,onChange:v}),l&&(0,G.jsxs)(`div`,{className:`flex items-center justify-center gap-2 text-bambu-gray py-4`,children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),n(`inventory.csv.parsing`,`Reading file…`)]}),m&&(0,G.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,G.jsx)(xs,{className:`w-5 h-5 text-red-600 dark:text-red-400 mt-0.5 flex-shrink-0`}),(0,G.jsx)(`p`,{className:`text-sm text-red-700 dark:text-red-300 break-words`,children:m})]}),s&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-3 text-sm`,children:[(0,G.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,G.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,G.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,G.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,G.jsx)(`p`,{className:`text-xs text-yellow-700 dark:text-yellow-300`,children:e},t))}),s.rows.length>0&&(0,G.jsx)(`div`,{className:`border border-bambu-dark-tertiary rounded-lg overflow-hidden`,children:(0,G.jsx)(`div`,{className:`max-h-72 overflow-y-auto`,children:(0,G.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,G.jsx)(`thead`,{className:`bg-bambu-dark sticky top-0`,children:(0,G.jsxs)(`tr`,{className:`text-left text-bambu-gray`,children:[(0,G.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:n(`inventory.csv.colRow`,`Row`)}),(0,G.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:n(`inventory.csv.colStatus`,`Status`)}),(0,G.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:n(`inventory.material`,`Material`)}),(0,G.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:n(`inventory.brand`,`Brand`)}),(0,G.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:n(`inventory.csv.colColor`,`Color`)})]})}),(0,G.jsx)(`tbody`,{children:s.rows.map(e=>(0,G.jsxs)(`tr`,{className:`border-t border-bambu-dark-tertiary`,children:[(0,G.jsx)(`td`,{className:`px-3 py-2 text-bambu-gray`,children:e.row_number}),(0,G.jsx)(`td`,{className:`px-3 py-2`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[x(e.status),e.status===`error`&&e.reason&&(0,G.jsx)(`span`,{className:`text-xs text-red-700 dark:text-red-400 break-words`,children:e.reason})]})}),(0,G.jsx)(`td`,{className:`px-3 py-2 text-white`,children:e.material||`—`}),(0,G.jsx)(`td`,{className:`px-3 py-2 text-white`,children:e.brand||`—`}),(0,G.jsx)(`td`,{className:`px-3 py-2`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.rgba&&(0,G.jsx)(`span`,{className:`inline-block w-4 h-4 rounded-full border border-bambu-dark-tertiary flex-shrink-0`,style:If(e.rgba)}),(0,G.jsx)(`span`,{className:`text-white`,children:e.color_name||`—`}),e.resolved_color&&!e.cross_material_color&&(0,G.jsx)(`span`,{title:n(`inventory.csv.colorResolved`,`Color filled from catalog`),children:(0,G.jsx)(Yu,{className:`w-3.5 h-3.5 text-bambu-green flex-shrink-0`})}),e.cross_material_color&&(0,G.jsx)(`span`,{title:n(`inventory.csv.colorCrossMaterial`,`Color taken from a different material — no exact match in catalog`),children:(0,G.jsx)(Lu,{className:`w-3.5 h-3.5 text-yellow-500 flex-shrink-0`})}),e.duplicate_of_existing&&(0,G.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,G.jsx)(Is,{className:`w-3.5 h-3.5 text-amber-600 dark:text-amber-400 flex-shrink-0`})})]})})]},e.row_number))})]})})})]})]}),(0,G.jsxs)(`div`,{className:`p-4 border-t border-bambu-dark-tertiary flex justify-end gap-2`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:e,disabled:d,children:n(`common.cancel`)}),(0,G.jsx)(Q,{onClick:b,disabled:!s||S===0||d,children:d?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{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 B2e({open:e,onClose:t}){let{t:n}=U(),{showToast:r}=Zd(),i=no(),{data:a=[],isLoading:o,isError:s}=K({queryKey:m6,queryFn:Z.getSuppliers,enabled:e}),[c,l]=(0,f.useState)(``),[u,d]=(0,f.useState)(!1),[p,m]=(0,f.useState)(null),[h,g]=(0,f.useState)(``),[_,v]=(0,f.useState)(``),[y,b]=(0,f.useState)(``),[x,S]=(0,f.useState)(``),[C,w]=(0,f.useState)(!1),[T,E]=(0,f.useState)(null);if((0,f.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=a.filter(e=>e.name.toLowerCase().includes(c.toLowerCase())),O=()=>{g(``),v(``),b(``),S(``)},k=()=>({name:h.trim(),website:_.trim()||null,customer_number:y.trim()||null,note:x.trim()||null}),A=async()=>{if(!h.trim()){r(n(`inventory.suppliers.nameRequired`),`error`);return}w(!0);try{await Z.createSupplier(k()),await h6(i),d(!1),O(),r(n(`inventory.suppliers.added`),`success`)}catch(e){console.error(`SuppliersModal.handleAdd failed:`,e),r(n(e instanceof sd&&e.status===409?`inventory.suppliers.duplicateName`:`inventory.suppliers.addFailed`),`error`)}finally{w(!1)}},j=e=>{m(e.id),g(e.name),v(e.website??``),b(e.customer_number??``),S(e.note??``)},M=()=>{m(null),O()},N=async e=>{if(!h.trim()){r(n(`inventory.suppliers.nameRequired`),`error`);return}w(!0);try{await Z.updateSupplier(e,k()),await h6(i),M(),r(n(`inventory.suppliers.updated`),`success`)}catch(e){console.error(`SuppliersModal.handleUpdate failed:`,e),r(n(e instanceof sd&&e.status===409?`inventory.suppliers.duplicateName`:`inventory.suppliers.updateFailed`),`error`)}finally{w(!1)}},P=async()=>{if(T)try{await Z.deleteSupplier(T.id),await h6(i),r(n(`inventory.suppliers.deleted`),`success`)}catch(e){console.error(`SuppliersModal.handleDelete failed:`,e),e instanceof sd&&e.status===409?r(n(`inventory.suppliers.deleteBlocked`,{count:T.spool_count}),`error`):r(n(`inventory.suppliers.deleteFailed`),`error`)}finally{E(null)}},F=(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`input`,{type:`text`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`,placeholder:n(`inventory.suppliers.namePlaceholder`),value:h,maxLength:200,onChange:e=>g(e.target.value)}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsx)(`input`,{type:`text`,className:`flex-1 min-w-0 px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`,placeholder:n(`inventory.suppliers.websitePlaceholder`),value:_,maxLength:500,onChange:e=>v(e.target.value)}),(0,G.jsx)(`input`,{type:`text`,className:`w-40 px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`,placeholder:n(`inventory.suppliers.customerNumberPlaceholder`),value:y,maxLength:100,onChange:e=>b(e.target.value)})]}),(0,G.jsx)(`input`,{type:`text`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`,placeholder:n(`inventory.suppliers.notePlaceholder`),value:x,maxLength:500,onChange:e=>S(e.target.value)})]});return(0,G.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[(0,G.jsx)(`div`,{className:`absolute inset-0 bg-black/60`,onClick:t}),(0,G.jsxs)(`div`,{className:`relative w-full max-w-3xl mx-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl shadow-2xl max-h-[90vh] flex flex-col`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":`suppliers-modal-title`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-4 px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(xu,{className:`w-5 h-5 text-bambu-gray`}),(0,G.jsx)(`h2`,{id:`suppliers-modal-title`,className:`text-lg font-semibold text-white`,children:n(`inventory.suppliers.title`)}),(0,G.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[`(`,a.length,`)`]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`button`,{onClick:()=>{d(!0),m(null),O()},className:`px-3 py-1.5 text-sm bg-bambu-green text-white rounded-lg hover:bg-bambu-green/80 transition-colors flex items-center gap-1.5`,children:[(0,G.jsx)(Ml,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:n(`common.add`)})]}),(0,G.jsx)(`button`,{onClick:t,className:`p-1.5 rounded hover:bg-bambu-dark text-bambu-gray hover:text-white transition-colors`,"aria-label":n(`common.close`),children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]})]}),(0,G.jsxs)(`div`,{className:`flex-1 min-h-0 overflow-y-auto px-6 py-4 space-y-4`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`inventory.suppliers.description`)}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(Yl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,G.jsx)(`input`,{type:`text`,className:`w-full pl-10 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`,placeholder:n(`inventory.suppliers.search`),value:c,onChange:e=>l(e.target.value)})]}),u&&(0,G.jsxs)(`div`,{className:`p-4 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary space-y-3`,children:[(0,G.jsx)(`h3`,{className:`text-sm font-medium text-white`,children:n(`inventory.suppliers.addNew`)}),F,(0,G.jsxs)(`div`,{className:`flex gap-2 justify-end`,children:[(0,G.jsx)(`button`,{onClick:()=>{d(!1),O()},className:`px-3 py-2 rounded-lg text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary`,children:n(`common.cancel`)}),(0,G.jsxs)(`button`,{onClick:A,disabled:C,className:`px-3 py-2 bg-bambu-green text-white rounded-lg hover:bg-bambu-green/80 flex items-center gap-1`,children:[C?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(as,{className:`w-4 h-4`}),n(`common.add`)]})]})]}),o?(0,G.jsxs)(`div`,{className:`flex items-center justify-center py-8 text-bambu-gray`,children:[(0,G.jsx)(Y,{className:`w-5 h-5 animate-spin mr-2`}),n(`common.loading`)]}):s?(0,G.jsxs)(`div`,{className:`flex items-center justify-center gap-2 py-8 text-sm text-red-400`,children:[(0,G.jsx)(Lu,{className:`w-4 h-4`}),n(`inventory.suppliers.loadFailed`)]}):(0,G.jsx)(`div`,{className:`border border-bambu-dark-tertiary rounded-lg`,children:(0,G.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,G.jsx)(`thead`,{className:`bg-bambu-dark sticky top-0`,children:(0,G.jsxs)(`tr`,{children:[(0,G.jsx)(`th`,{className:`px-4 py-2 text-left text-bambu-gray font-medium`,children:n(`common.name`)}),(0,G.jsx)(`th`,{className:`px-4 py-2 text-left text-bambu-gray font-medium hidden sm:table-cell`,children:n(`inventory.suppliers.customerNumber`)}),(0,G.jsx)(`th`,{className:`px-4 py-2 text-right text-bambu-gray font-medium w-20`,children:n(`inventory.suppliers.spools`)}),(0,G.jsx)(`th`,{className:`px-4 py-2 w-24`})]})}),(0,G.jsx)(`tbody`,{children:D.length===0?(0,G.jsx)(`tr`,{children:(0,G.jsx)(`td`,{colSpan:4,className:`px-4 py-8 text-center text-bambu-gray`,children:n(c?`inventory.suppliers.noMatch`:`inventory.suppliers.empty`)})}):D.map(e=>(0,G.jsx)(`tr`,{className:`border-t border-bambu-dark-tertiary hover:bg-bambu-dark align-top`,children:p===e.id?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`td`,{className:`px-4 py-2`,colSpan:3,children:F}),(0,G.jsx)(`td`,{className:`px-4 py-2`,children:(0,G.jsxs)(`div`,{className:`flex justify-end gap-1`,children:[(0,G.jsx)(`button`,{onClick:()=>N(e.id),disabled:C,className:`p-1.5 rounded hover:bg-green-500/20 text-green-500`,children:C?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(as,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:M,className:`p-1.5 rounded hover:bg-bambu-dark-tertiary text-bambu-gray`,children:(0,G.jsx)(nd,{className:`w-4 h-4`})})]})})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`td`,{className:`px-4 py-2 text-white`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,G.jsx)(`span`,{children:e.name}),e.website&&(0,G.jsx)(`a`,{href:e.website,target:`_blank`,rel:`noopener noreferrer`,className:`text-bambu-gray hover:text-bambu-green`,title:e.website,children:(0,G.jsx)(Qs,{className:`w-3.5 h-3.5`})})]}),e.note&&(0,G.jsx)(`div`,{className:`text-xs text-bambu-gray mt-0.5`,children:e.note})]}),(0,G.jsx)(`td`,{className:`px-4 py-2 text-bambu-gray hidden sm:table-cell`,children:e.customer_number||`-`}),(0,G.jsx)(`td`,{className:`px-4 py-2 text-right font-mono text-bambu-gray`,children:e.spool_count}),(0,G.jsx)(`td`,{className:`px-4 py-2`,children:(0,G.jsxs)(`div`,{className:`flex justify-end gap-1`,children:[(0,G.jsx)(`button`,{onClick:()=>{j(e),d(!1)},className:`p-1.5 rounded hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white`,children:(0,G.jsx)(Dl,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:()=>E(e),className:`p-1.5 rounded bg-red-500/10 hover:bg-red-500/20 text-red-500`,children:(0,G.jsx)(Pu,{className:`w-4 h-4`})})]})})]})},e.id))})]})})]})]}),T&&(0,G.jsx)(uf,{title:n(`inventory.suppliers.deleteTitle`),message:T.spool_count>0?n(`inventory.suppliers.deleteConfirmReferenced`,{name:T.name,count:T.spool_count}):n(`inventory.suppliers.deleteConfirm`,{name:T.name}),confirmText:n(`common.delete`),variant:`danger`,onConfirm:P,onCancel:()=>E(null)})]})}var V2e=[{id:`material`,type:`searchable`,labelKey:`inventory.material`},{id:`subtype`,type:`searchable`,labelKey:`inventory.subtype`},{id:`brand`,type:`searchable`,labelKey:`inventory.brand`},{id:`color_name`,type:`text`,labelKey:`inventory.colorName`},{id:`rgba`,type:`color`,labelKey:`inventory.color`,pattern:`^[0-9A-Fa-f]{6}([0-9A-Fa-f]{2})?$`},{id:`location_id`,type:`searchableClosed`,labelKey:`inventory.storageLocation`},{id:`slicer_filament_name`,type:`searchable`,labelKey:`inventory.slicerFilamentName`},{id:`slicer_filament`,type:`searchable`,labelKey:`inventory.slicerFilament`},{id:`cost_per_kg`,type:`number`,labelKey:`inventory.costPerKg`,min:0,step:.01},{id:`note`,type:`textarea`,labelKey:`inventory.note`},{id:`label_weight`,type:`number`,labelKey:`inventory.labelWeight`,min:1,step:1},{id:`core_weight`,type:`number`,labelKey:`inventory.coreWeight`,min:0,step:1},{id:`category`,type:`searchable`,labelKey:`inventory.category`,internalOnly:!0},{id:`low_stock_threshold_pct`,type:`number`,labelKey:`inventory.lowStockThresholdOverride`,min:1,max:99,step:1,internalOnly:!0},{id:`material_number`,type:`searchable`,labelKey:`inventory.materialNumber`,internalOnly:!0}];function H2e({value:e,onChange:t,options:n,allowCustom:r,placeholderKey:i,disabled:a}){let{t:o}=U(),s=(0,f.useRef)(null),[c,l]=(0,f.useState)(!1),[u,d]=(0,f.useState)(``);(0,f.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 p=c?u:n.find(t=>t.value===e)?.label??e,m=(0,f.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]),h=c&&u.trim()&&!n.some(e=>e.value.toLowerCase()===u.trim().toLowerCase());return(0,G.jsxs)(`div`,{className:`relative`,ref:s,children:[(0,G.jsx)(`input`,{type:`text`,disabled:a,value:p,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,G.jsx)(ss,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50 pointer-events-none`}),c&&(0,G.jsxs)(`div`,{className:`absolute z-50 left-0 right-0 mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-64 overflow-y-auto`,children:[m.length===0&&!r&&(0,G.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:o(`inventory.noResults`)}),m.map(n=>(0,G.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&&h&&(0,G.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 C9(...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 U2e({isOpen:e,selectedCount:t,isPending:n,availableLocations:r,availableMaterials:i,availableSubtypes:a,availableBrands:o,availableCategories:s,availableMaterialNumbers:c,availableSlicerFilaments:l,availableSlicerFilamentNames:u,spoolmanMode:d=!1,onClose:p,onApply:m}){let{t:h}=U(),g=(0,f.useMemo)(()=>V2e.filter(e=>!(d&&e.internalOnly)),[d]),{data:_=[]}=K({queryKey:[`bulk-edit-cloud-presets`],enabled:e,staleTime:300*1e3,queryFn:async()=>{let e=[];try{if((await Z.getCloudStatus()).is_authenticated){let t=await Z.getFilamentPresets();e.push(...t)}}catch{}try{if((await Z.orcaCloudStatus()).connected){let t=await Z.orcaCloudListProfiles();e.push(...t.filament)}}catch{}return e}}),{data:v}=K({queryKey:[`bulk-edit-local-presets`],enabled:e,staleTime:300*1e3,queryFn:Z.getLocalPresets}),{data:y=[]}=K({queryKey:[`builtin-filaments`],enabled:e,staleTime:300*1e3,queryFn:Z.getBuiltinFilaments}),b=(0,f.useMemo)(()=>gU(_,new Set,v?.filament??[],y),[_,v,y]),[x,S]=(0,f.useState)({}),C=(0,f.useMemo)(()=>C9(oU,i).map(e=>({value:e,label:e})),[i]),w=(0,f.useMemo)(()=>C9(cU,a).map(e=>({value:e,label:e})),[a]),T=(0,f.useMemo)(()=>C9(sU,o).map(e=>({value:e,label:e})),[o]),E=(0,f.useMemo)(()=>C9(s).map(e=>({value:e,label:e})),[s]),D=(0,f.useMemo)(()=>C9(c).map(e=>({value:e,label:e})),[c]),O=(0,f.useMemo)(()=>{let e=b.map(e=>({value:e.code,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))},[b,l]),k=(0,f.useMemo)(()=>{let e=b.map(e=>({value:e.displayName,label:e.displayName})),t=u.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))},[b,u]),A=(0,f.useMemo)(()=>r.map(e=>({value:String(e.id),label:e.name})),[r]);if(!e)return null;let j=(e,t)=>{S(n=>({...n,[e]:t}))},M=e=>{S(t=>{let n={...t};return delete n[e],n})},N=(()=>{let e={};for(let t of g){let n=x[t.id];if(n===void 0)continue;let r=typeof n==`string`?n.trim():n;if(!(r===``||r===null))if(t.type===`number`){let n=Number(r);Number.isFinite(n)&&(e[t.id]=n)}else if(t.id===`location_id`){let n=Number(r);Number.isFinite(n)&&n>0&&(e[t.id]=n)}else if(t.id===`rgba`){let n=String(r).replace(/^#/,``),i=n.length===6?`${n}FF`:n;/^[0-9A-Fa-f]{8}$/.test(i)&&(e[t.id]=i.toUpperCase())}else e[t.id]=String(r)}return e})(),P=Object.keys(N).length>0,F=g.some(e=>{let t=x[e.id];return t===void 0||t.trim()===``?!1:N[e.id]===void 0}),I=e=>e===`material`?C:e===`subtype`?w:e===`brand`?T:e===`category`?E:e===`material_number`?D:e===`slicer_filament`?O:e===`slicer_filament_name`?k:e===`location_id`?A:[],L=e=>{let t=x[e.id]??``;if(e.type===`searchable`||e.type===`searchableClosed`)return(0,G.jsx)(H2e,{value:t,onChange:t=>{t===``?M(e.id):j(e.id,t)},options:I(e.id),allowCustom:e.type===`searchable`,disabled:n});if(e.type===`textarea`)return(0,G.jsx)(`textarea`,{disabled:n,value:t,onChange:t=>j(e.id,t.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray/50 focus:border-bambu-green focus:outline-none resize-none min-h-[60px]`});if(e.type===`color`){let r=t.trim().replace(/^#/,``),i=r.length===6?`${r}FF`:r,a=t.trim()!==``&&!/^[0-9A-Fa-f]{8}$/.test(i);return(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`input`,{type:`color`,disabled:n,value:`#${(t||`808080`).replace(/^#/,``).slice(0,6)}`,onChange:t=>j(e.id,t.target.value.replace(/^#/,``).toUpperCase()),className:`h-9 w-12 rounded cursor-pointer`}),(0,G.jsx)(`input`,{type:`text`,disabled:n,value:t,onChange:t=>j(e.id,t.target.value.replace(/^#/,``).toUpperCase()),placeholder:`RRGGBB or RRGGBBAA`,className:`flex-1 px-3 py-2 bg-bambu-dark border rounded-lg text-white placeholder-bambu-gray/50 focus:outline-none ${a?`border-red-500 focus:border-red-500`:`border-bambu-dark-tertiary focus:border-bambu-green`}`,pattern:e.pattern})]}),a&&(0,G.jsx)(`p`,{className:`mt-1 text-xs text-red-600 dark:text-red-400`,children:h(`inventory.bulk.invalidHex`)})]})}return(0,G.jsx)(`input`,{type:e.type===`number`?`number`:`text`,disabled:n,value:t,onChange:t=>j(e.id,t.target.value),min:e.min,max:e.max,step:e.step,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray/50 focus:border-bambu-green focus:outline-none`})};return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center p-4 z-50`,onClick:n?void 0:p,children:(0,G.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,G.jsxs)(`div`,{className:`flex items-center justify-between p-5 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:h(`inventory.bulk.editTitle`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-0.5`,children:h(`inventory.bulk.editSubtitle`,{count:t})})]}),(0,G.jsx)(`button`,{onClick:p,disabled:n,className:`p-1 text-bambu-gray hover:text-white transition-colors`,"aria-label":h(`common.close`),children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]}),(0,G.jsx)(`p`,{className:`px-5 pt-4 text-xs text-bambu-gray`,children:h(`inventory.bulk.editHint`)}),(0,G.jsx)(`div`,{className:`flex-1 overflow-y-auto p-5 space-y-3`,children:g.map(e=>{let t=x[e.id]!==void 0;return(0,G.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,G.jsx)(`div`,{className:`pt-2`,children:(0,G.jsx)(`input`,{type:`checkbox`,className:`h-4 w-4 cursor-pointer`,checked:t,onChange:t=>{t.target.checked?j(e.id,``):M(e.id)},"aria-label":h(`inventory.bulk.toggleField`)})}),(0,G.jsxs)(`div`,{className:`flex-1`,children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:h(e.labelKey)}),L(e)]})]},e.id)})}),(0,G.jsxs)(`div`,{className:`flex items-center gap-3 p-5 border-t border-bambu-dark-tertiary`,children:[(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:h(`inventory.bulk.changeCount`,{count:Object.keys(N).length})}),(0,G.jsxs)(`div`,{className:`ml-auto flex gap-2`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:p,disabled:n,children:h(`common.cancel`)}),(0,G.jsx)(Q,{onClick:()=>m(N),disabled:!P||n||F,children:n?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 mr-2 animate-spin`}),h(`inventory.bulk.applyPending`)]}):h(`inventory.bulk.applyButton`,{count:t})})]})]})]})})}function W2e(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 w9(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 G2e(e){return`${e.material}|${e.subtype||``}|${e.brand||``}|${e.color_name||``}|${e.rgba||``}|${e.extra_colors||``}|${e.effect_type||``}|${e.label_weight}`}var K2e=`bambuddy-inventory-columns`,q2e=`none`.padStart(65,`_`);function J2e(e){return(e||``).toLowerCase().replace(/\d+/g,e=>e.padStart(64,`0`))}var T9=[{id:`id`,label:`#`,visible:!0},{id:`added_time`,label:`Added`,visible:!0},{id:`encode_time`,label:`Encoded`,visible:!1},{id:`last_used_time`,label:`Last Used`,visible:!1},{id:`rgba`,label:`Color`,visible:!0},{id:`material`,label:`Material`,visible:!0},{id:`subtype`,label:`Subtype`,visible:!0},{id:`color_name`,label:`Color Name`,visible:!1},{id:`brand`,label:`Brand`,visible:!0},{id:`slicer_filament`,label:`Slicer Filament`,visible:!1},{id:`location`,label:`Location`,visible:!0},{id:`storage_location`,label:`Storage Location`,visible:!1},{id:`temperature`,label:`Temperature`,visible:!1},{id:`humidity`,label:`Humidity`,visible:!1},{id:`battery`,label:`Battery`,visible:!1},{id:`label_weight`,label:`Label`,visible:!0},{id:`net`,label:`Net`,visible:!0},{id:`gross`,label:`Gross`,visible:!1},{id:`added_full`,label:`Full`,visible:!1},{id:`used`,label:`Used`,visible:!1},{id:`printed_total`,label:`Printed Total`,visible:!1},{id:`printed_since_weight`,label:`Printed Since Weight`,visible:!1},{id:`note`,label:`Note`,visible:!1},{id:`material_number`,label:`Material No.`,visible:!1},{id:`suppliers`,label:`Suppliers`,visible:!1},{id:`pa_k`,label:`PA(K)`,visible:!0},{id:`tag_id`,label:`Tag ID`,visible:!1},{id:`data_origin`,label:`Data Origin`,visible:!1},{id:`tag_type`,label:`Linked Tag Type`,visible:!1},{id:`stock`,label:`Stock`,visible:!1},{id:`remaining`,label:`Remaining`,visible:!0},{id:`spool_name`,label:`Spool`,visible:!1},{id:`cost_per_kg`,label:`Cost/kg`,visible:!1},{id:`weight_check`,label:`Weight Check`,visible:!1}];function Y2e(){try{let e=localStorage.getItem(K2e);if(e){let t=JSON.parse(e),n=new Set(T9.map(e=>e.id)),r=new Set(t.map(e=>e.id)),i=[...t.filter(e=>n.has(e.id))];for(let e of T9){if(r.has(e.id))continue;let t=T9.indexOf(e),n=i.length;for(let e=t-1;e>=0;e--){let t=i.findIndex(t=>t.id===T9[e].id);if(t!==-1){n=t+1;break}}i.splice(n,0,e)}return i}}catch{}return T9.map(e=>({...e}))}function X2e(e){try{localStorage.setItem(K2e,JSON.stringify(e))}catch{}}function E9(e,t=!1){return t&&e>=1e3?`${(e/1e3).toFixed(1)}kg`:`${Math.round(e)}g`}var Z2e={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 D9(e,t=`system`){if(!e)return`-`;let n=sp(e);return n?$f(n,t):`-`}var Q2e={id:()=>`#`,added_time:()=>`Added`,encode_time:()=>`Encoded`,last_used_time:()=>`Last Used`,rgba:e=>e(`inventory.color`),material:e=>e(`inventory.material`),subtype:e=>e(`inventory.subtype`),color_name:e=>e(`inventory.colorName`),brand:e=>e(`inventory.brand`),slicer_filament:e=>e(`inventory.slicerFilament`),location:()=>`Location`,storage_location:e=>e(`inventory.storageLocation`),temperature:e=>e(`inventory.temperature`),humidity:e=>e(`inventory.humidity`),battery:e=>e(`inventory.battery`),label_weight:e=>e(`inventory.labelWeight`),net:e=>e(`inventory.net`),gross:()=>`Gross`,added_full:()=>`Full`,used:e=>e(`inventory.weightUsed`),printed_total:()=>`Printed Total`,printed_since_weight:()=>`Printed Since Weight`,note:e=>e(`inventory.note`),material_number:e=>e(`inventory.materialNumber`),suppliers:e=>e(`inventory.suppliers.label`),pa_k:()=>`PA(K)`,tag_id:()=>`Tag ID`,data_origin:()=>`Data Origin`,tag_type:()=>`Linked Tag Type`,stock:e=>e(`inventory.stock`),remaining:e=>e(`inventory.remaining`),spool_name:e=>e(`inventory.spoolName`),cost_per_kg:e=>e(`inventory.costPerKg`),weight_check:e=>e(`inventory.weightCheck`)},O9={id:({spool:e})=>(0,G.jsx)(`span`,{className:`text-sm font-medium text-white`,children:e.id}),added_time:({spool:e,dateFormat:t})=>(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:D9(e.created_at,t)}),encode_time:({spool:e,dateFormat:t})=>(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:D9(e.encode_time,t)}),last_used_time:({spool:e,dateFormat:t})=>(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.last_used?D9(e.last_used,t):`Never`}),rgba:({spool:e})=>(0,G.jsx)(`div`,{className:`flex items-center justify-center`,children:(0,G.jsx)(Dm,{rgba:e.rgba,extraColors:e.extra_colors,effectType:e.effect_type,effectSize:`table`,subtype:e.subtype})}),material:({spool:e})=>(0,G.jsx)(`span`,{className:`text-sm text-white`,children:e.material}),subtype:({spool:e})=>(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.subtype||`-`}),color_name:({spool:e})=>(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:Nf(e.color_name,e.rgba,e.color_name_is_synthesized)||`-`}),brand:({spool:e})=>(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.brand||`-`}),slicer_filament:({spool:e})=>(0,G.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,G.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,G.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,` `,Ip(n.ams_id,n.tray_id,a,i),n.ams_label?` (${n.ams_label})`:``]})},storage_location:({spool:e})=>e.storage_location?(0,G.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,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:`-`}),temperature:({spool:e,locationReadingsMap:t,t:n,colorizeLocationSensors:r,locationSensorAboveColor:i,locationSensorBelowColor:a,locationSensorOptimalColor:o})=>{let s=e.location_id?t[e.location_id]?.find(e=>e.device_class===`temperature`):void 0;return s?(0,G.jsx)(`span`,{title:s.name,className:`text-sm ${M9(s,r,i,a,o)}`,children:j9(s,n)}):(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray/50`,children:`-`})},humidity:({spool:e,locationReadingsMap:t,t:n,colorizeLocationSensors:r,locationSensorAboveColor:i,locationSensorBelowColor:a,locationSensorOptimalColor:o})=>{let s=e.location_id?t[e.location_id]?.find(e=>e.device_class===`humidity`):void 0;return s?(0,G.jsx)(`span`,{title:s.name,className:`text-sm ${M9(s,r,i,a,o)}`,children:j9(s,n)}):(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray/50`,children:`-`})},battery:({spool:e,locationReadingsMap:t,t:n,colorizeLocationSensors:r,locationSensorAboveColor:i,locationSensorBelowColor:a,locationSensorOptimalColor:o})=>{let s=e.location_id?t[e.location_id]?.find(e=>e.device_class===`battery`):void 0;return s?(0,G.jsx)(`span`,{title:s.name,className:`text-sm ${M9(s,r,i,a,o)}`,children:j9(s,n)}):(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray/50`,children:`-`})},label_weight:({spool:e})=>(0,G.jsx)(`span`,{className:`text-sm text-white`,children:E9(e.label_weight)}),net:({remaining:e})=>(0,G.jsx)(`span`,{className:`text-sm text-white`,children:E9(e)}),gross:({spool:e,remaining:t})=>(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:E9(t+e.core_weight)}),added_full:({spool:e})=>(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.added_full==null?`-`:e.added_full?`Yes`:`No`}),used:({spool:e})=>(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.weight_used>0?E9(e.weight_used):`-`}),printed_total:()=>(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray/50`,children:`-`}),printed_since_weight:()=>(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray/50`,children:`-`}),note:({spool:e})=>(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray max-w-[150px] truncate block`,title:e.note||void 0,children:e.note||`-`}),material_number:({spool:e})=>(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.material_number||`-`}),suppliers:({spool:e})=>{let t=e.suppliers??[];return t.length===0?(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:`-`}):(0,G.jsx)(`div`,{className:`flex flex-wrap gap-1 max-w-[220px]`,children:[...t].sort((e,t)=>Number(t.is_purchase_source)-Number(e.is_purchase_source)).map(e=>(0,G.jsx)(`span`,{title:e.supplier_article_number||void 0,className:`inline-flex items-center px-1.5 py-0.5 rounded-full text-[10px] font-medium ${e.is_purchase_source?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-gray/10 text-bambu-gray`}`,children:e.supplier_name},e.id))})},pa_k:({spool:e})=>(e.k_profiles?.length??0)===0?(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:`-`}):(0,G.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,G.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,G.jsx)(`span`,{className:`text-sm text-bambu-gray/50`,children:`-`})},data_origin:({spool:e})=>(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.data_origin||`-`}),tag_type:({spool:e})=>(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.tag_type||`-`}),stock:({spool:e,t})=>e.slicer_filament?(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:`-`}):(0,G.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,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`div`,{className:`flex-1 h-2 bg-bambu-dark-tertiary rounded-full overflow-hidden`,children:(0,G.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,G.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,G.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,G.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,G.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,G.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,G.jsxs)(`span`,{children:[Math.round(n),`g`]}),o?(0,G.jsx)(as,{className:`w-3 h-3`}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Lu,{className:`w-3 h-3`}),t&&(0,G.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,G.jsx)(zl,{className:`w-3.5 h-3.5`})})]})]})}},k9={id:e=>e.id,added_time:e=>e.created_at||``,encode_time:e=>e.encode_time||``,last_used_time:e=>e.last_used||``,material:e=>(e.material||``).toLowerCase(),subtype:e=>(e.subtype||``).toLowerCase(),color_name:e=>(e.color_name||``).toLowerCase(),rgba:e=>Af(e.rgba),brand:e=>(e.brand||``).toLowerCase(),slicer_filament:e=>(e.slicer_filament_name||e.slicer_filament||``).toLowerCase(),location:(e,t)=>{let n=t[e.id];if(!n)return``;let r=n.ams_id===254||n.ams_id===255,i=!r&&n.ams_id>=128,a=n.ams_label?` (${n.ams_label})`:``;return`${n.printer_name||``} ${Ip(n.ams_id,n.tray_id,i,r)}${a}`},storage_location:e=>(e.storage_location||``).toLowerCase(),label_weight:e=>e.label_weight,net:e=>Math.max(0,e.label_weight-e.weight_used),gross:e=>Math.max(0,e.label_weight-e.weight_used)+e.core_weight,used:e=>e.weight_used,remaining:e=>e.label_weight>0?Math.max(0,e.label_weight-e.weight_used)/e.label_weight:0,note:e=>(e.note||``).toLowerCase(),material_number:e=>J2e(e.material_number),suppliers:e=>{let t=e.suppliers??[];return((t.find(e=>e.is_purchase_source)??t[0])?.supplier_name||``).toLowerCase()},data_origin:e=>(e.data_origin||``).toLowerCase(),tag_type:e=>(e.tag_type||``).toLowerCase(),stock:e=>+!!e.slicer_filament,spool_name:e=>e.core_weight_catalog_id??0,cost_per_kg:e=>e.cost_per_kg??0,weight_check:e=>{if(e.last_scale_weight==null)return-1;let t=Math.max(0,e.label_weight-e.weight_used)+e.core_weight;return Math.abs(e.last_scale_weight-t)},temperature:(e,t,n)=>(e.location_id?n[e.location_id]:void 0)?.find(e=>e.device_class===`temperature`)?.value??-1/0,humidity:(e,t,n)=>(e.location_id?n[e.location_id]:void 0)?.find(e=>e.device_class===`humidity`)?.value??-1/0,battery:(e,t,n)=>(e.location_id?n[e.location_id]:void 0)?.find(e=>e.device_class===`battery`)?.value??-1/0},A9=`bambuddy-inventory-sort`;function $2e(){try{let e=localStorage.getItem(A9);if(e)return JSON.parse(e)}catch{}return null}function e4e(e){try{e?localStorage.setItem(A9,JSON.stringify(e)):localStorage.removeItem(A9)}catch{}}function t4e(){let{data:e}=K({queryKey:[`spoolman-settings`],queryFn:Z.getSpoolmanSettings,staleTime:300*1e3}),t=e!==void 0;return(0,G.jsx)(n4e,{spoolmanMode:e?.spoolman_enabled===`true`&&!!e?.spoolman_url,spoolmanModeReady:t})}function n4e({spoolmanMode:e=!1,spoolmanModeReady:t=!0}){let{t:n}=U(),r=zf(),i=no(),{showToast:a}=Zd(),{hasPermission:o,loading:s}=Ld(),c=!s&&o(`inventory:forecast_read`),[l,u]=ji(),[d,p]=(0,f.useState)(null),m=(0,f.useRef)(!1),[h,g]=(0,f.useState)(null),[_,v]=(0,f.useState)(null),[y,b]=(0,f.useState)(!1),[x,S]=(0,f.useState)(!1),[C,w]=(0,f.useState)(!1),[T,E]=(0,f.useState)(!1),[D,O]=(0,f.useState)(`active`),[k,A]=(0,f.useState)(`all`),[j,M]=(0,f.useState)(``),[N,P]=(0,f.useState)(``),[F,I]=(0,f.useState)(``),[L,R]=(0,f.useState)(``),[z,B]=(0,f.useState)(``),[V,ee]=(0,f.useState)(``),[te,ne]=(0,f.useState)(`all`),[re,ie]=(0,f.useState)(``),[ae,oe]=(0,f.useState)(`table`),[se,H]=(0,f.useState)($2e),[ce,le]=(0,f.useState)(Y2e),[ue,de]=(0,f.useState)(!1),[fe,pe]=(0,f.useState)(()=>{try{return localStorage.getItem(`bambuddy-inventory-group`)===`true`}catch{return!1}}),[me,he]=(0,f.useState)(new Set),[ge,_e]=(0,f.useState)(new Set),[ve,ye]=(0,f.useState)(!1),[be,xe]=(0,f.useState)(null),Se=(0,f.useCallback)(e=>{_e(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),Ce=(0,f.useCallback)(()=>_e(new Set),[]);(0,f.useEffect)(()=>{_e(new Set)},[D,k,j,N,F,L,z,V,te,re]);let[we,Te]=(0,f.useState)(0),[Ee,De]=(0,f.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:Oe}=K({queryKey:[`settings`],queryFn:Z.getSettings}),ke=Oe?.date_format||`system`,Ae=(Oe?.location_sensor_poll_interval||120)*1e3,{colorize:je,aboveColor:Me,belowColor:Ne,optimalColor:Pe}=P6(),Fe=e?[`spoolman-inventory-spools`]:[`inventory-spools`],Ie=()=>g6(i,Fe),{data:Le,isLoading:Re}=K({queryKey:Fe,queryFn:()=>e?Z.getSpoolmanInventorySpools(!0):Z.getSpools(!0),refetchInterval:3e4}),ze=(0,f.useCallback)(async()=>{S(!0);try{await Z.exportSpoolsCsv()}catch(e){a(e instanceof Error?e.message:n(`inventory.csv.exportError`,`Export failed`),`error`)}finally{S(!1)}},[a,n]),Be=e?n(`inventory.csv.spoolmanHint`,`In Spoolman mode, use Spoolman's built-in CSV import/export.`):void 0,{data:Ve=[]}=K({queryKey:f6,queryFn:Z.getLocations}),He=l.get(`location_id`),Ue=He===`__none__`?`__none__`:He&&/^\d+$/.test(He)&&Number(He)>0?He:``,We=l.get(`spool`),Ge=We&&/^\d+$/.test(We)&&Number(We)>0?Number(We):null,Ke=Le?.find(e=>e.id===Ge)??null,qe=(0,f.useCallback)(()=>{m.current=!0,u(e=>(e.delete(`spool`),e),{replace:!0})},[u]),{data:Je,isError:Ye,error:Xe}=K({queryKey:e?[`spoolman-inventory-spool`,Ge]:[`inventory-spool`,Ge],queryFn:()=>e?Z.getSpoolmanInventorySpool(Ge):Z.getSpool(Ge),enabled:t&&Ge!==null&&Ke===null,staleTime:1/0,retry:(e,t)=>e<2&&!(t instanceof sd&&t.status===404)});(0,f.useEffect)(()=>{if(!m.current){if(t&&Ge&&Ke){qe(),p({spool:Ke,mode:`edit`});return}if(Je){qe(),p({spool:Je,mode:`edit`});return}Ye&&(qe(),a(n(Xe instanceof sd&&Xe.status===404?`inventory.deepLinkSpoolNotFound`:`inventory.deepLinkFetchFailed`),`error`))}},[t,Ge,Ke,Je,Ye,Xe,qe,a,n]);let{data:Ze}=K({queryKey:[`spool-assignments`],queryFn:()=>Z.getAssignments(),refetchInterval:3e4}),{data:Qe=[],isError:$e}=K({queryKey:[`spoolman-slot-assignments-all`],queryFn:()=>Z.getSpoolmanSlotAssignments(),enabled:e,refetchInterval:3e4,staleTime:1e4,retry:1}),et=(0,f.useRef)(!1);(0,f.useEffect)(()=>{$e&&!et.current?(et.current=!0,a(n(`inventory.spoolmanUnreachable`),`error`)):$e||(et.current=!1)},[$e,a,n]);let{data:tt}=K({queryKey:[`spool-catalog`],queryFn:()=>Z.getSpoolCatalog()}),nt=q({mutationFn:t=>e?Z.deleteSpoolmanInventorySpool(t):Z.deleteSpool(t),onSuccess:()=>{Ie(),a(n(`inventory.spoolDeleted`),`success`)},onError:e=>{e instanceof sd&&e.status===404?a(n(`inventory.deleteSpoolNotFound`),`error`):e instanceof sd&&e.status===503?a(n(`inventory.spoolmanUnreachable`),`error`):a(n(`inventory.deleteFailed`),`error`)}}),rt=q({mutationFn:t=>e?Z.archiveSpoolmanInventorySpool(t):Z.archiveSpool(t),onSuccess:()=>{Ie(),a(n(`inventory.spoolArchived`),`success`)},onError:e=>{e instanceof sd&&e.status===404?a(n(`inventory.archiveSpoolNotFound`),`error`):e instanceof sd&&e.status===503?a(n(`inventory.spoolmanUnreachable`),`error`):a(n(`inventory.archiveFailed`),`error`)}}),it=q({mutationFn:t=>e?Z.restoreSpoolmanInventorySpool(t):Z.restoreSpool(t),onSuccess:()=>{Ie(),a(n(`inventory.spoolRestored`),`success`)},onError:e=>{e instanceof sd&&e.status===404?a(n(`inventory.restoreSpoolNotFound`),`error`):e instanceof sd&&e.status===503?a(n(`inventory.spoolmanUnreachable`),`error`):a(n(`inventory.restoreFailed`),`error`)}}),at=q({mutationFn:t=>e?Z.resetSpoolmanInventorySpoolConsumedCounter(t):Z.resetSpoolConsumedCounter(t),onSuccess:()=>{i.invalidateQueries({queryKey:Fe}),a(n(`inventory.consumedCounterReset`),`success`)},onError:()=>{a(n(`inventory.resetConsumedCounterFailed`),`error`)}}),ot=q({mutationFn:t=>e?Z.bulkResetSpoolmanInventorySpoolConsumedCounter(t):Z.bulkResetSpoolConsumedCounter(t),onSuccess:e=>{i.invalidateQueries({queryKey:Fe}),a(n(`inventory.allConsumedCountersReset`,{count:e.reset}),`success`),xe(null),Ce()},onError:()=>{a(n(`inventory.resetConsumedCounterFailed`),`error`)}}),st=e=>(e.not_found?.length??0)+(e.errors?.length??0),ct=q({mutationFn:async({ids:t,update:n})=>e?Z.bulkUpdateSpoolmanInventorySpools(t,n):Z.bulkUpdateSpools(t,n),onSuccess:e=>{Ie();let t=st(e);if(e.updated===0){a(n(`inventory.bulk.updateAllFailed`,{count:t}),`error`);return}t>0?a(n(`inventory.bulk.updatePartial`,{ok:e.updated,failed:t}),`warning`):a(n(`inventory.bulk.updateSuccess`,{count:e.updated}),`success`),ye(!1),Ce()},onError:e=>{a(e.message||n(`inventory.bulk.updateFailed`),`error`)}}),lt=q({mutationFn:async t=>e?Z.bulkDeleteSpoolmanInventorySpools(t):Z.bulkDeleteSpools(t),onSuccess:e=>{Ie();let t=st(e);if(e.deleted===0){a(n(`inventory.bulk.deleteAllFailed`,{count:t}),`error`);return}t>0?a(n(`inventory.bulk.deletePartial`,{ok:e.deleted,failed:t}),`warning`):a(n(`inventory.bulk.deleteSuccess`,{count:e.deleted}),`success`),xe(null),Ce()},onError:e=>{a(e.message||n(`inventory.bulk.deleteFailed`),`error`)}}),ut=q({mutationFn:async t=>e?Z.bulkArchiveSpoolmanInventorySpools(t):Z.bulkArchiveSpools(t),onSuccess:e=>{Ie();let t=st(e);if(e.archived===0&&t>0){a(n(`inventory.bulk.archiveAllFailed`,{count:t}),`error`);return}t>0?a(n(`inventory.bulk.archivePartial`,{ok:e.archived,failed:t}),`warning`):a(n(`inventory.bulk.archiveSuccess`,{count:e.archived}),`success`),xe(null),Ce()},onError:e=>{a(e.message||n(`inventory.bulk.archiveFailed`),`error`)}}),dt=q({mutationFn:async t=>e?Z.bulkRestoreSpoolmanInventorySpools(t):Z.bulkRestoreSpools(t),onSuccess:e=>{Ie();let t=st(e);if(e.restored===0&&t>0){a(n(`inventory.bulk.restoreAllFailed`,{count:t}),`error`);return}t>0?a(n(`inventory.bulk.restorePartial`,{ok:e.restored,failed:t}),`warning`):a(n(`inventory.bulk.restoreSuccess`,{count:e.restored}),`success`),xe(null),Ce()},onError:e=>{a(e.message||n(`inventory.bulk.restoreFailed`),`error`)}}),ft=(0,f.useMemo)(()=>(Le??[]).map(e=>e.id),[Le]),pt=async t=>{if(t.last_scale_weight!=null)try{e?await Z.syncSpoolmanSpoolWeight(t.id,t.last_scale_weight):await jd.updateSpoolWeight(t.id,t.last_scale_weight),i.invalidateQueries({queryKey:Fe}),a(`Synced "${[t.brand,t.material,Nf(t.color_name,t.rgba,t.color_name_is_synthesized)].filter(Boolean).join(` `)}" to scale weight`,`success`)}catch(e){let t=e instanceof sd&&e.status===404,r=e instanceof sd&&e.status===503;a(n(t?`inventory.syncWeightSpoolNotFound`:r?`inventory.syncWeightSpoolmanUnreachable`:`inventory.syncWeightFailed`),`error`)}},mt=Oe?.low_stock_threshold??20,[ht,gt]=(0,f.useState)(!1),[_t,vt]=(0,f.useState)(mt.toString());(0,f.useEffect)(()=>{ht||vt(mt.toString())},[mt,ht]);let yt=q({mutationFn:e=>Z.updateSettings({low_stock_threshold:e}),onSuccess:()=>{i.invalidateQueries({queryKey:[`settings`]}),a(n(`common.saved`),`success`),gt(!1)},onError:()=>{a(n(`inventory.lowStockThresholdError`),`error`)}}),bt=(0,f.useMemo)(()=>{if(!Le)return null;let e=0,t=0,n=0,r=0,i={};for(let a of Le){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??mt)&&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}},[Le,mt]),xt=(Ze?.length??0)+(e?Qe.length:0),St=Vf(Oe?.currency||`USD`),Ct=(0,f.useMemo)(()=>{let e={};for(let t of Ze||[])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 Qe)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},[Ze,Qe]),wt=(0,f.useMemo)(()=>{let e={};for(let t of tt||[])e[t.id]=t;return e},[tt]),{data:Tt}=K({queryKey:[`locationHaSensors`],queryFn:()=>Z.getLocationHASensors()}),Et=(0,f.useMemo)(()=>new Set((Tt??[]).map(e=>e.location_id)),[Tt]),Dt=(0,f.useMemo)(()=>{let e=new Set;for(let t of Le||[])t.location_id&&Et.has(t.location_id)&&e.add(t.location_id);return Array.from(e)},[Le,Et]),Ot=ae===`cards`||ae===`table`&&ce.some(e=>e.visible&&(e.id===`temperature`||e.id===`humidity`||e.id===`battery`)),kt=_o({queries:Dt.map(e=>({queryKey:[`locationHaSensorReadings`,e],queryFn:()=>Z.getLocationHASensorReadings(e,!1),refetchInterval:Ae,enabled:Ot}))}),At=(0,f.useMemo)(()=>{let e={};return Dt.forEach((t,n)=>{let r=kt[n]?.data;r&&(e[t]=r)}),e},[Dt,kt]),jt=(0,f.useMemo)(()=>bt?Object.entries(bt.byMaterial).sort((e,t)=>t[1].weight-e[1].weight).slice(0,4):[],[bt]),Mt=(0,f.useMemo)(()=>{let e=Le||[];if(e=D===`active`?e.filter(e=>!e.archived_at):e.filter(e=>!!e.archived_at),k===`used`?e=e.filter(e=>e.weight_used>0):k===`new`?e=e.filter(e=>e.weight_used===0):k===`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??mt)})),j&&(e=e.filter(e=>e.material===j)),N&&(e=e.filter(e=>e.brand===N)),F&&(e=F===`__none__`?e.filter(e=>!e.category):e.filter(e=>e.category===F)),L&&(e=L===q2e?e.filter(e=>!e.material_number?.trim()):e.filter(e=>e.material_number===L)),z)if(z===`__none__`)e=e.filter(e=>(e.suppliers??[]).length===0);else{let t=Number(z);e=e.filter(e=>(e.suppliers??[]).some(e=>e.supplier_id===t))}if(V){let t=Number(V);e=e.filter(e=>e.core_weight_catalog_id===t)}if(Ue)if(Ue===`__none__`)e=e.filter(e=>!e.location_id&&!e.storage_location?.trim());else{let t=Number(Ue),n=Ve.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 te===`stock`?e=e.filter(e=>!e.slicer_filament):te===`configured`&&(e=e.filter(e=>!!e.slicer_filament)),re&&(e=JH(e,re)),e},[Le,D,k,j,N,F,L,z,V,te,Ue,re,mt,Ve,r]),Nt=()=>Te(0),Pt=(0,f.useCallback)(e=>{u(t=>(t.delete(`location_id`),e&&t.set(`location_id`,e),t),{replace:!0}),Nt()},[u]),Ft=[...new Set(Le?.map(e=>e.material)||[])].sort(),It=[...new Set(Le?.map(e=>e.brand).filter(Boolean)||[])].sort(),Lt=[...new Set(Le?.map(e=>e.category?.trim()).filter(Boolean)||[])].sort(),Rt=(Le??[]).some(e=>!e.category),zt=[...new Set(Le?.map(e=>e.material_number?.trim()).filter(Boolean)||[])].sort((e,t)=>e.localeCompare(t,void 0,{numeric:!0})),Bt=(Le??[]).some(e=>!e.material_number?.trim()),Vt=(0,f.useMemo)(()=>{let e=new Map;for(let t of Le??[])for(let n of t.suppliers??[])e.set(n.supplier_id,n.supplier_name);return[...e.entries()].map(([e,t])=>({id:e,name:t})).sort((e,t)=>e.name.localeCompare(t.name))},[Le]),Ht=(Le??[]).some(e=>(e.suppliers??[]).length===0),Ut=[...new Set(Le?.map(e=>e.core_weight_catalog_id).filter(e=>e!=null)||[])].sort((e,t)=>{let n=(wt[e]?.name||``).toLowerCase(),r=(wt[t]?.name||``).toLowerCase();return n.localeCompare(r)}),Wt=(Le??[]).some(e=>!e.location_id&&!e.storage_location?.trim()),Gt=D!==`active`||k!==`all`||!!j||!!N||!!F||!!L||!!z||!!V||!!Ue||te!==`all`||!!re,Kt=e=>{le(e),X2e(e)},qt=(0,f.useMemo)(()=>ce.filter(e=>e.visible).map(e=>e.id),[ce]),Jt=e=>{k9[e]&&(H(t=>{let n;return n=t?.column===e?t.direction===`asc`?{column:e,direction:`desc`}:null:{column:e,direction:`asc`},e4e(n),n}),Nt())},Yt=(0,f.useMemo)(()=>{if(!se)return Mt;let e=k9[se.column];return e?[...Mt].sort((t,n)=>{let r=e(t,Ct,At),i=e(n,Ct,At);return ri?se.direction===`asc`?1:-1:0}):Mt},[Mt,se,Ct,At]),Xt=(0,f.useMemo)(()=>{if(!fe)return Yt.map(e=>({type:`single`,spool:e}));let e=new Map;for(let t of Yt)if(!(t.weight_used>0||Ct[t.id])){let n=G2e(t),r=e.get(n);r?r.push(t):e.set(n,[t])}let t=[],n=new Set;for(let r of Yt){if(r.weight_used>0||Ct[r.id]){t.push({type:`single`,spool:r});continue}let i=G2e(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},[Yt,fe,Ct]),Zt=Ee===-1,Qt=Xt.length,$t=Zt?Qt||1:Ee,en=Math.max(1,Math.ceil(Qt/$t)),tn=Zt?0:Math.min(we,en-1),nn=Zt?Xt:Xt.slice(tn*$t,(tn+1)*$t),W=()=>{let e=!fe;pe(e),he(new Set),Nt();try{localStorage.setItem(`bambuddy-inventory-group`,String(e))}catch{}},rn=e=>{he(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},an=e=>{De(e),Te(0);try{localStorage.setItem(`bambuddy-inventory-pageSize`,String(e))}catch{}};return(0,G.jsxs)(`div`,{className:`p-4 md:p-8 space-y-6`,children:[(0,G.jsxs)(`div`,{className:`flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,G.jsx)(bl,{className:`w-7 h-7 text-bambu-green`}),n(`inventory.title`)]}),(0,G.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:n(`inventory.subtitle`)})]}),(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,G.jsxs)(Q,{variant:`secondary`,disabled:e,onClick:()=>b(!0),title:Be,children:[(0,G.jsx)(Vu,{className:`w-4 h-4`}),n(`inventory.csv.importButton`,`Import CSV`)]}),(0,G.jsxs)(Q,{variant:`secondary`,disabled:e||x,onClick:ze,title:Be,children:[x?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Gs,{className:`w-4 h-4`}),n(`inventory.csv.exportButton`,`Export CSV`)]}),(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>w(!0),children:[(0,G.jsx)(nl,{className:`w-4 h-4`}),n(`locations.manage`)]}),(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>E(!0),children:[(0,G.jsx)(xu,{className:`w-4 h-4`}),n(`inventory.suppliers.title`)]}),(0,G.jsxs)(Q,{variant:`secondary`,disabled:Mt.length===0,onClick:()=>v(ge.size>0?[...ge]:Mt.map(e=>e.id)),title:Mt.length===0?n(`inventory.labels.noSpoolsTitle`,`No spools to label`):ge.size>0?n(`inventory.labels.selectedTitle`,`Print labels for the {{count}} selected spools`,{count:ge.size}):n(`inventory.labels.bulkTitle`,`Pick spools to print labels for from the {{count}} currently shown`,{count:Mt.length}),children:[(0,G.jsx)(Fl,{className:`w-4 h-4`}),n(`inventory.labels.printLabels`,`Print labels…`)]}),(0,G.jsxs)(Q,{onClick:()=>p({spool:null,mode:`create`}),children:[(0,G.jsx)(Ml,{className:`w-4 h-4`}),n(`inventory.addSpool`)]})]})]}),bt&&!Re&&(0,G.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-3 lg:grid-cols-5 gap-3`,children:[(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,G.jsx)(bl,{className:`w-4 h-4 text-bambu-green`}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray font-medium uppercase tracking-wide`,children:n(`inventory.totalInventory`)})]}),(0,G.jsx)(`div`,{className:`text-xl font-bold text-white`,children:E9(bt.totalWeight,!0)}),(0,G.jsxs)(`div`,{className:`text-xs text-bambu-gray mt-1`,children:[bt.totalSpools,` `,bt.totalSpools===1?n(`inventory.spool`):n(`inventory.spools`)]})]}),(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-2 mb-1`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Fu,{className:`w-4 h-4 text-blue-600 dark:text-blue-400`}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray font-medium uppercase tracking-wide`,children:n(`inventory.totalConsumed`)})]}),bt.totalConsumed>0&&ft.length>0&&(0,G.jsx)(`button`,{onClick:()=>g({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,G.jsx)(Zs,{className:`w-3.5 h-3.5`})})]}),(0,G.jsx)(`div`,{className:`text-xl font-bold text-white`,children:E9(bt.totalConsumed,!0)}),(0,G.jsx)(`div`,{className:`text-xs text-bambu-gray mt-1`,children:n(`inventory.sinceTracking`)})]}),(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,G.jsx)(Wc,{className:`w-4 h-4 text-green-600 dark:text-green-400`}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray font-medium uppercase tracking-wide`,children:n(`inventory.byMaterial`)})]}),(0,G.jsx)(`div`,{className:`flex flex-wrap gap-1.5 mt-1`,children:jt.map(([e,t])=>(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-medium ${Z2e[e]||`bg-bambu-dark-tertiary text-bambu-gray`}`,children:[e,` `,(0,G.jsx)(`span`,{className:`opacity-70`,children:E9(t.weight,!0)})]},e))})]}),(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,G.jsx)(Fl,{className:`w-4 h-4 text-purple-600 dark:text-purple-400`}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray font-medium uppercase tracking-wide`,children:n(`inventory.inPrinter`)})]}),(0,G.jsx)(`div`,{className:`text-xl font-bold text-white`,children:xt}),(0,G.jsx)(`div`,{className:`text-xs text-bambu-gray mt-1`,children:n(`inventory.loadedInAms`)})]}),(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,G.jsx)(Lu,{className:`w-4 h-4 text-yellow-600 dark:text-yellow-400`}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray font-medium uppercase tracking-wide`,children:n(`inventory.lowStock`)})]}),(0,G.jsx)(`div`,{className:`text-xl font-bold ${bt.lowStock>0?`text-yellow-700 dark:text-yellow-400`:`text-white`}`,children:bt.lowStock}),(0,G.jsx)(`div`,{className:`text-xs text-bambu-gray mt-1 flex items-center gap-2`,children:ht?(0,G.jsxs)(`form`,{onSubmit:e=>{e.preventDefault();let t=parseFloat(_t);!isNaN(t)&&t>=.1&&t<=99.9?yt.mutate(t):a(n(`inventory.lowStockThresholdError`),`error`)},className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:`<`}),(0,G.jsx)(`input`,{type:`text`,inputMode:`decimal`,pattern:`^\\d{0,2}(\\.\\d?)?$`,maxLength:4,value:_t,onChange:e=>{let t=e.target.value.replace(/[^\d.]/g,``);/^\d{0,2}(\.\d?)?$/.test(t)&&vt(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:yt.isPending}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:`%`}),(0,G.jsx)(Q,{type:`submit`,size:`sm`,disabled:yt.isPending,children:n(`common.save`)}),(0,G.jsx)(Q,{type:`button`,size:`sm`,variant:`ghost`,onClick:()=>gt(!1),disabled:yt.isPending,children:n(`common.cancel`)})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`span`,{className:`text-bambu-gray`,children:[`< `,mt,`%`]}),(0,G.jsx)(`button`,{className:`p-1.5 text-bambu-gray hover:text-white rounded transition-colors`,title:n(`common.edit`),onClick:()=>{vt(mt.toString()),gt(!0)},children:(0,G.jsx)(El,{className:`w-4 h-4`})})]})})]})]}),(0,G.jsxs)(`div`,{className:`flex flex-col sm:flex-row gap-3 items-start sm:items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`relative flex-1 max-w-md ${ae===`forecast`?`invisible pointer-events-none`:``}`,children:[(0,G.jsx)(Yl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50`}),(0,G.jsx)(`input`,{type:`text`,value:re,onChange:e=>{ie(e.target.value),Nt()},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`}),re&&(0,G.jsx)(`button`,{onClick:()=>{ie(``),Nt()},className:`absolute right-3 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white`,children:(0,G.jsx)(nd,{className:`w-4 h-4`})})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[ae===`table`&&(0,G.jsxs)(`button`,{onClick:()=>de(!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,G.jsx)(Ns,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:n(`inventory.columns`)})]}),ae!==`forecast`&&(0,G.jsxs)(`button`,{onClick:W,className:`flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium border rounded-lg transition-colors ${fe?`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,G.jsx)(Dc,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:n(`inventory.groupSimilar`)})]}),(0,G.jsxs)(`div`,{className:`flex bg-bambu-dark-primary border border-bambu-dark-tertiary rounded-lg overflow-hidden`,children:[(0,G.jsxs)(`button`,{onClick:()=>oe(`table`),className:`flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium transition-colors ${ae===`table`?`bg-bambu-green text-white`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:[(0,G.jsx)(Cu,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:n(`inventory.table`)})]}),(0,G.jsxs)(`button`,{onClick:()=>oe(`cards`),className:`flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium transition-colors ${ae===`cards`?`bg-bambu-green text-white`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:[(0,G.jsx)(Gc,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:n(`inventory.cards`)})]}),(0,G.jsxs)(`button`,{onClick:()=>c&&oe(`forecast`),disabled:!c,title:c?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 ${ae===`forecast`?`bg-bambu-green text-white`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:[c?(0,G.jsx)(Iu,{className:`w-4 h-4`}):(0,G.jsx)(Qc,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:n(`forecast.title`)})]})]})]})]}),(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 ${ae===`forecast`?`hidden`:``}`,children:[(0,G.jsxs)(`div`,{className:`flex items-center rounded-lg border border-bambu-dark-tertiary overflow-hidden`,children:[(0,G.jsxs)(`button`,{onClick:()=>{O(`active`),Nt()},className:`flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium transition-colors ${D===`active`?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:[(0,G.jsx)(bl,{className:`w-3.5 h-3.5`}),n(`inventory.active`)]}),(0,G.jsxs)(`button`,{onClick:()=>{O(`archived`),Nt()},className:`flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium transition-colors ${D===`archived`?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:[(0,G.jsx)(Oo,{className:`w-3.5 h-3.5`}),n(`inventory.archived`)]})]}),(0,G.jsx)(`div`,{className:`w-px h-5 bg-bambu-dark-tertiary`}),(0,G.jsxs)(`div`,{className:`flex items-center rounded-lg border border-bambu-dark-tertiary overflow-hidden`,children:[(0,G.jsx)(`button`,{onClick:()=>{A(`all`),Nt()},className:`px-3 py-1.5 text-xs font-medium transition-colors ${k===`all`?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:n(`inventory.all`)}),(0,G.jsxs)(`button`,{onClick:()=>{A(`used`),Nt()},className:`flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium transition-colors ${k===`used`?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:[(0,G.jsx)(Ts,{className:`w-3.5 h-3.5`}),n(`inventory.used`)]}),(0,G.jsx)(`button`,{onClick:()=>{A(`new`),Nt()},className:`px-3 py-1.5 text-xs font-medium transition-colors ${k===`new`?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:n(`inventory.new`)}),(0,G.jsxs)(`button`,{onClick:()=>{A(`lowstock`),Nt()},className:`flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium transition-colors ${k===`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,G.jsx)(Lu,{className:`w-3.5 h-3.5`}),n(`inventory.lowStock`)]})]}),(0,G.jsxs)(`div`,{className:`flex items-center rounded-lg border border-bambu-dark-tertiary overflow-hidden`,children:[(0,G.jsx)(`button`,{onClick:()=>{ne(`all`),Nt()},className:`px-3 py-1.5 text-xs font-medium transition-colors ${te===`all`?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:n(`inventory.all`)}),(0,G.jsx)(`button`,{onClick:()=>{ne(`stock`),Nt()},className:`px-3 py-1.5 text-xs font-medium transition-colors ${te===`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,G.jsx)(`button`,{onClick:()=>{ne(`configured`),Nt()},className:`px-3 py-1.5 text-xs font-medium transition-colors ${te===`configured`?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:n(`inventory.configured`)})]}),(0,G.jsx)(`div`,{className:`w-px h-5 bg-bambu-dark-tertiary`}),(0,G.jsxs)(`select`,{value:j,onChange:e=>{M(e.target.value),Nt()},className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${j?`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,G.jsx)(`option`,{value:``,children:n(`inventory.material`)}),Ft.map(e=>(0,G.jsx)(`option`,{value:e,children:e},e))]}),(0,G.jsxs)(`select`,{value:N,onChange:e=>{P(e.target.value),Nt()},className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${N?`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,G.jsx)(`option`,{value:``,children:n(`inventory.brand`)}),It.map(e=>(0,G.jsx)(`option`,{value:e,children:e},e))]}),(Lt.length>0||F)&&(0,G.jsxs)(`select`,{value:F,onChange:e=>{I(e.target.value),Nt()},className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${F?`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,G.jsx)(`option`,{value:``,children:n(`inventory.category`)}),Lt.map(e=>(0,G.jsx)(`option`,{value:e,children:e},e)),Rt&&(0,G.jsx)(`option`,{value:`__none__`,children:n(`inventory.categoryNone`)})]}),(zt.length>0||L)&&(0,G.jsxs)(`select`,{value:L,onChange:e=>{R(e.target.value),Nt()},className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${L?`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,G.jsx)(`option`,{value:``,children:n(`inventory.materialNumber`)}),zt.map(e=>(0,G.jsx)(`option`,{value:e,children:e},e)),Bt&&(0,G.jsx)(`option`,{value:q2e,children:n(`inventory.materialNumberNone`)})]}),(Vt.length>0||z)&&(0,G.jsxs)(`select`,{value:z,onChange:e=>{B(e.target.value),Nt()},className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${z?`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,G.jsx)(`option`,{value:``,children:n(`inventory.suppliers.label`)}),Vt.map(e=>(0,G.jsx)(`option`,{value:String(e.id),children:e.name},e.id)),Ht&&(0,G.jsx)(`option`,{value:`__none__`,children:n(`inventory.suppliers.none`)})]}),Ut.length>0&&(0,G.jsxs)(`select`,{value:V,onChange:e=>{ee(e.target.value),Nt()},className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${V?`bg-bambu-green/20 text-bambu-green border-bambu-green/30`:`bg-transparent text-bambu-gray border-bambu-dark-tertiary hover:bg-bambu-dark-tertiary`}`,children:[(0,G.jsx)(`option`,{value:``,children:n(`inventory.spoolName`)}),Ut.map(e=>(0,G.jsx)(`option`,{value:e,children:wt[e]?.name||`#${e}`},e))]}),(Ve.length>0||Ue)&&(0,G.jsxs)(`select`,{value:Ue,onChange:e=>{Pt(e.target.value)},className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${Ue?`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,G.jsx)(`option`,{value:``,children:n(`inventory.storageLocation`)}),Ve.map(e=>(0,G.jsx)(`option`,{value:String(e.id),children:e.name},e.id)),Wt&&(0,G.jsx)(`option`,{value:`__none__`,children:n(`inventory.storageLocationNone`)})]}),Gt&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`w-px h-5 bg-bambu-dark-tertiary`}),(0,G.jsxs)(`button`,{onClick:()=>{O(`active`),A(`all`),M(``),P(``),I(``),R(``),B(``),ee(``),ne(`all`),ie(``),u(e=>(e.delete(`location_id`),e),{replace:!0}),Nt()},className:`flex items-center gap-1 text-xs text-bambu-gray hover:text-bambu-green transition-colors`,children:[(0,G.jsx)(nd,{className:`w-3.5 h-3.5`}),n(`inventory.clearFilters`)]})]}),ae!==`forecast`&&(0,G.jsxs)(`span`,{className:`ml-auto text-xs text-bambu-gray`,children:[Yt.length,` `,Yt.length===1?n(`inventory.spool`):n(`inventory.spools`),fe&&Qt0&&ae!==`forecast`&&(0,G.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,G.jsx)(`span`,{className:`text-sm text-bambu-green font-medium`,children:n(`inventory.bulk.selectionCount`,{count:ge.size})}),(0,G.jsxs)(`div`,{className:`ml-auto flex flex-wrap items-center gap-2`,children:[(0,G.jsxs)(Q,{size:`sm`,variant:`secondary`,onClick:()=>ye(!0),children:[(0,G.jsx)(El,{className:`w-3.5 h-3.5 mr-1.5`}),n(`inventory.bulk.edit`)]}),(0,G.jsxs)(Q,{size:`sm`,variant:`secondary`,onClick:()=>v([...ge]),children:[(0,G.jsx)(Fl,{className:`w-3.5 h-3.5 mr-1.5`}),n(`inventory.bulk.printLabels`)]}),(0,G.jsxs)(Q,{size:`sm`,variant:`secondary`,onClick:()=>xe(`reset-consumed-counter`),children:[(0,G.jsx)(Zs,{className:`w-3.5 h-3.5 mr-1.5`}),n(`inventory.bulk.resetUsage`)]}),D===`archived`?(0,G.jsxs)(Q,{size:`sm`,variant:`secondary`,onClick:()=>xe(`restore`),children:[(0,G.jsx)(Vl,{className:`w-3.5 h-3.5 mr-1.5`}),n(`inventory.bulk.restore`)]}):(0,G.jsxs)(Q,{size:`sm`,variant:`secondary`,onClick:()=>xe(`archive`),children:[(0,G.jsx)(Oo,{className:`w-3.5 h-3.5 mr-1.5`}),n(`inventory.bulk.archive`)]}),(0,G.jsxs)(Q,{size:`sm`,variant:`danger`,onClick:()=>xe(`delete`),children:[(0,G.jsx)(Pu,{className:`w-3.5 h-3.5 mr-1.5`}),n(`inventory.bulk.delete`)]}),(0,G.jsx)(`button`,{className:`p-1.5 text-bambu-gray hover:text-white rounded transition-colors`,onClick:Ce,title:n(`inventory.bulk.clearSelection`),"aria-label":n(`inventory.bulk.clearSelection`),children:(0,G.jsx)(nd,{className:`w-4 h-4`})})]})]}),Re?(0,G.jsx)(`div`,{className:`flex justify-center py-16`,children:(0,G.jsx)(Y,{className:`w-8 h-8 text-bambu-green animate-spin`})}):ae===`forecast`?(0,G.jsx)(D0e,{spools:Le||[]}):ae===`cards`?nn.length>0?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4`,children:nn.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=Em({rgba:i.rgba,extraColors:i.extra_colors,effectType:i.effect_type,subtype:i.subtype,effectSize:`groupheader`}),s=me.has(t);return(0,G.jsxs)(`div`,{className:`col-span-full`,children:[(0,G.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:()=>rn(t),children:[(0,G.jsx)(`div`,{className:`h-10 flex items-center px-4 gap-3`,style:o,children:(0,G.jsx)(`span`,{className:`bg-white/90 text-gray-800 px-3 py-0.5 rounded-full text-sm font-medium`,children:Nf(i.color_name,i.rgba,i.color_name_is_synthesized)||`-`})}),(0,G.jsxs)(`div`,{className:`px-4 py-3 flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(ss,{className:`w-4 h-4 text-bambu-gray transition-transform ${s?``:`-rotate-90`}`}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`h3`,{className:`font-semibold text-white`,children:[i.material,i.subtype?` ${i.subtype}`:``]}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i.brand||`-`})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,title:n(`inventory.remaining`),children:E9(a)}),(0,G.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,G.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,G.jsx)(i4e,{spool:e,remaining:t,pct:e.label_weight>0?t/e.label_weight*100:0,onClick:()=>p({spool:e,mode:`edit`}),onPrintLabel:()=>v([e.id]),onCopy:()=>p({spool:e,mode:`copy`}),t:n,colorizeLocationSensors:je,locationSensorAboveColor:Me,locationSensorBelowColor:Ne,locationSensorOptimalColor:Pe},e.id)})})]},`group-${t}`)}let t=e.spool,r=Math.max(0,t.label_weight-t.weight_used);return(0,G.jsx)(i4e,{spool:t,remaining:r,pct:t.label_weight>0?r/t.label_weight*100:0,onClick:()=>p({spool:t,mode:`edit`}),onPrintLabel:()=>v([t.id]),onCopy:()=>p({spool:t,mode:`copy`}),t:n,colorizeLocationSensors:je,locationSensorAboveColor:Me,locationSensorBelowColor:Ne,locationSensorOptimalColor:Pe},t.id)})}),(0,G.jsx)(r4e,{pageIndex:tn,pageSize:Ee,totalRows:Qt,totalPages:en,onPageChange:Te,onPageSizeChange:an,t:n})]}):(0,G.jsx)(u4e,{hasFilters:Gt,onAddSpool:()=>p({spool:null,mode:`create`}),t:n}):nn.length>0?(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg overflow-hidden border border-bambu-dark-tertiary`,children:[(0,G.jsx)(`div`,{className:`overflow-x-auto`,children:(0,G.jsxs)(`table`,{className:`w-full`,children:[(0,G.jsx)(`thead`,{children:(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary bg-bambu-dark-tertiary/30`,children:[(0,G.jsx)(`th`,{className:`w-10 px-3 py-3`,children:(0,G.jsx)(`input`,{type:`checkbox`,className:`h-4 w-4 cursor-pointer`,"aria-label":n(`inventory.bulk.selectAllVisible`),checked:nn.length>0&&nn.every(e=>(e.type===`group`?e.spools.map(e=>e.id):[e.spool.id]).every(e=>ge.has(e))),onChange:e=>{if(e.target.checked){let e=new Set(ge);for(let t of nn){let n=t.type===`group`?t.spools.map(e=>e.id):[t.spool.id];for(let t of n)e.add(t)}_e(e)}else{let e=new Set(ge);for(let t of nn){let n=t.type===`group`?t.spools.map(e=>e.id):[t.spool.id];for(let t of n)e.delete(t)}_e(e)}}})}),qt.map(e=>{let t=!!k9[e],r=se?.column===e;return(0,G.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?()=>Jt(e):void 0,children:(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[Q2e[e]?.(n)??e,t&&(r?se.direction===`asc`?(0,G.jsx)(Io,{className:`w-3 h-3`}):(0,G.jsx)(Ao,{className:`w-3 h-3`}):(0,G.jsx)(Po,{className:`w-3 h-3 opacity-30`}))]})},e)}),(0,G.jsx)(`th`,{className:`text-right py-3 px-4 text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:n(`common.actions`)})]})}),(0,G.jsx)(`tbody`,{children:nn.map(e=>{if(e.type===`group`){let{key:t,spools:r}=e,i=me.has(t),a=W2e(r),o=Math.max(0,a.label_weight-a.weight_used);return(0,G.jsx)(l4e,{spools:r,headerSpool:a,remaining:o,pct:a.label_weight>0?o/a.label_weight*100:0,isExpanded:i,onToggle:()=>rn(t),selectedIds:ge,onToggleSelected:Se,onToggleGroupSelected:(e,t)=>{_e(n=>{let r=new Set(n);for(let n of e)t?r.add(n):r.delete(n);return r})},onEdit:e=>p({spool:e,mode:`edit`}),onCopy:e=>p({spool:e,mode:`copy`}),onArchive:e=>g({type:`archive`,spoolId:e}),onDelete:e=>g({type:`delete`,spoolId:e}),onPrintLabel:e=>v([e]),onResetConsumedCounter:e=>g({type:`reset-consumed-counter`,spoolId:e}),visibleColumns:qt,assignmentMap:Ct,catalogMap:wt,locationReadingsMap:At,currencySymbol:St,dateFormat:ke,t:n,onSyncWeight:pt,colorizeLocationSensors:je,locationSensorAboveColor:Me,locationSensorBelowColor:Ne,locationSensorOptimalColor:Pe},`group-${t}`)}let t=e.spool,r=Math.max(0,t.label_weight-t.weight_used);return(0,G.jsx)(c4e,{spool:t,remaining:r,pct:t.label_weight>0?r/t.label_weight*100:0,isSelected:ge.has(t.id),onToggleSelected:()=>Se(t.id),onEdit:()=>p({spool:t,mode:`edit`}),onCopy:()=>p({spool:t,mode:`copy`}),onRestore:()=>it.mutate(t.id),onArchive:()=>g({type:`archive`,spoolId:t.id}),onDelete:()=>g({type:`delete`,spoolId:t.id}),onPrintLabel:()=>v([t.id]),onResetConsumedCounter:()=>g({type:`reset-consumed-counter`,spoolId:t.id}),visibleColumns:qt,assignmentMap:Ct,catalogMap:wt,locationReadingsMap:At,currencySymbol:St,dateFormat:ke,t:n,onSyncWeight:pt,colorizeLocationSensors:je,locationSensorAboveColor:Me,locationSensorBelowColor:Ne,locationSensorOptimalColor:Pe},t.id)})})]})}),(0,G.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,G.jsx)(`span`,{className:`text-bambu-gray`,children:Zt?`${Qt} ${n(Qt===1?`inventory.spool`:`inventory.spools`)}`:(0,G.jsxs)(G.Fragment,{children:[n(`inventory.showing`),` `,tn*$t+1,` `,n(`inventory.to`),` `,Math.min((tn+1)*$t,Qt),` `,n(`inventory.of`),` `,Qt,` `,n(`inventory.spools`)]})}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:n(`inventory.show`)}),(0,G.jsxs)(`select`,{value:Ee,onChange:e=>an(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,G.jsx)(`option`,{value:e,children:e},e)),(0,G.jsx)(`option`,{value:-1,children:n(`inventory.all`)})]}),!Zt&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`button`,{onClick:()=>Te(0),disabled:tn===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,G.jsx)(ds,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:()=>Te(e=>Math.max(0,e-1)),disabled:tn===0,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,children:(0,G.jsx)(ls,{className:`w-4 h-4`})}),(0,G.jsxs)(`span`,{className:`text-bambu-gray px-2 whitespace-nowrap`,children:[n(`inventory.page`),` `,tn+1,` `,n(`inventory.of`),` `,en]}),(0,G.jsx)(`button`,{onClick:()=>Te(e=>Math.min(en-1,e+1)),disabled:tn>=en-1,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,children:(0,G.jsx)(cs,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:()=>Te(en-1),disabled:tn>=en-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,G.jsx)(fs,{className:`w-4 h-4`})})]})]})]})]}):(0,G.jsx)(u4e,{hasFilters:Gt,onAddSpool:()=>p({spool:null,mode:`create`}),t:n}),d!==null&&(0,G.jsx)(C2e,{isOpen:!0,onClose:()=>p(null),spool:d.spool,mode:d.mode,currencySymbol:St,spoolmanMode:e,spoolsQueryKey:Fe}),h&&(0,G.jsx)(uf,{title:h.type===`delete`?n(`common.delete`):h.type===`archive`?n(`inventory.archive`):h.type===`reset-consumed-counter`?n(`inventory.resetConsumedCounter`):n(`inventory.resetAllConsumedCounters`),message:h.type===`delete`?n(`inventory.deleteConfirm`):h.type===`archive`?n(`inventory.archiveConfirm`):h.type===`reset-consumed-counter`?n(`inventory.resetConsumedCounterConfirm`):n(`inventory.resetAllConsumedCountersConfirm`,{count:ft.length}),confirmText:h.type===`delete`?n(`common.delete`):h.type===`archive`?n(`inventory.archive`):n(`inventory.resetConsumedCounter`),variant:h.type===`archive`?`warning`:`danger`,onConfirm:()=>{h.type===`delete`?nt.mutate(h.spoolId):h.type===`archive`?rt.mutate(h.spoolId):h.type===`reset-consumed-counter`?at.mutate(h.spoolId):ot.mutate(ft),g(null)},onCancel:()=>g(null)}),(0,G.jsx)(JW,{isOpen:ue,onClose:()=>de(!1),columns:ce,defaultColumns:T9,onSave:Kt}),(0,G.jsx)(R2e,{isOpen:_!==null,onClose:()=>v(null),availableSpools:Mt,initialSelectedIds:_??[],spoolmanMode:e}),(0,G.jsx)(U2e,{isOpen:ve,selectedCount:ge.size,isPending:ct.isPending,availableLocations:Ve.map(e=>({id:e.id,name:e.name})),availableMaterials:w9((Le??[]).map(e=>e.material)),availableSubtypes:w9((Le??[]).map(e=>e.subtype)),availableBrands:w9((Le??[]).map(e=>e.brand)),availableCategories:w9((Le??[]).map(e=>e.category)),availableMaterialNumbers:w9((Le??[]).map(e=>e.material_number)),availableSlicerFilaments:w9((Le??[]).map(e=>e.slicer_filament)),availableSlicerFilamentNames:w9((Le??[]).map(e=>e.slicer_filament_name)),spoolmanMode:e,onClose:()=>ye(!1),onApply:e=>ct.mutate({ids:[...ge],update:e})}),be&&(0,G.jsx)(uf,{title:n(be===`delete`?`inventory.bulk.deleteTitle`:be===`archive`?`inventory.bulk.archiveTitle`:be===`restore`?`inventory.bulk.restoreTitle`:`inventory.bulk.resetUsageTitle`),message:n(be===`delete`?`inventory.bulk.deleteMessage`:be===`archive`?`inventory.bulk.archiveMessage`:be===`restore`?`inventory.bulk.restoreMessage`:`inventory.bulk.resetUsageMessage`,{count:ge.size}),confirmText:n(be===`delete`?`common.delete`:be===`archive`?`inventory.archive`:be===`restore`?`inventory.restore`:`inventory.resetConsumedCounter`),variant:be===`delete`?`danger`:`warning`,isLoading:lt.isPending||ut.isPending||dt.isPending||ot.isPending,onConfirm:()=>{let e=[...ge];be===`delete`?lt.mutate(e):be===`archive`?ut.mutate(e):be===`restore`?dt.mutate(e):ot.mutate(e)},onCancel:()=>xe(null)}),y&&(0,G.jsx)(z2e,{onClose:()=>b(!1),onImported:e=>{b(!1),i.invalidateQueries({queryKey:Fe}),a(n(`inventory.csv.importSuccess`,`{{count}} spools imported`,{count:e}),`success`)}}),(0,G.jsx)(Y6,{open:C,onClose:()=>w(!1),onPickLocation:e=>Pt(String(e))}),(0,G.jsx)(B2e,{open:T,onClose:()=>E(!1)})]})}function r4e({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,G.jsxs)(`div`,{className:`flex items-center justify-between pt-2 text-sm`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:s?`${n} ${o(n===1?`inventory.spool`:`inventory.spools`)}`:(0,G.jsxs)(G.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,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:o(`inventory.show`)}),(0,G.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,G.jsx)(`option`,{value:e,children:e},e)),(0,G.jsx)(`option`,{value:-1,children:o(`inventory.all`)})]}),!s&&(0,G.jsxs)(G.Fragment,{children:[(0,G.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,G.jsx)(ds,{className:`w-4 h-4`})}),(0,G.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,G.jsx)(ls,{className:`w-4 h-4`})}),(0,G.jsxs)(`span`,{className:`text-bambu-gray px-2 whitespace-nowrap`,children:[o(`inventory.page`),` `,e+1,` `,o(`inventory.of`),` `,r]}),(0,G.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,G.jsx)(cs,{className:`w-4 h-4`})}),(0,G.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,G.jsx)(fs,{className:`w-4 h-4`})})]})]})]})}function i4e({spool:e,remaining:t,pct:n,onClick:r,onPrintLabel:i,onCopy:a,t:o,colorizeLocationSensors:s,locationSensorAboveColor:c,locationSensorBelowColor:l,locationSensorOptimalColor:u}){let d=Em({rgba:e.rgba,extraColors:e.extra_colors,effectType:e.effect_type,subtype:e.subtype,effectSize:`card`});return(0,G.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,G.jsxs)(`div`,{className:`h-14 flex items-center justify-center`,style:d,children:[(0,G.jsx)(`span`,{className:`bg-white/90 text-gray-800 px-3 py-0.5 rounded-full text-sm font-medium`,children:Nf(e.color_name,e.rgba,e.color_name_is_synthesized)||`-`}),a&&(0,G.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,G.jsx)(Is,{className:`w-3.5 h-3.5`})})]}),(0,G.jsxs)(`div`,{className:`p-4 space-y-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`h3`,{className:`font-semibold text-white`,children:[e.material,e.subtype?` ${e.subtype}`:``]}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e.brand||`-`})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[i&&(0,G.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,G.jsx)(Fl,{className:`w-4 h-4`})}),(0,G.jsxs)(`span`,{className:`text-xs font-mono text-bambu-gray bg-bambu-dark-tertiary px-2 py-1 rounded`,children:[`#`,e.id]})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex justify-between text-xs text-bambu-gray mb-1`,children:[(0,G.jsx)(`span`,{children:o(`inventory.remaining`)}),(0,G.jsxs)(`span`,{children:[Math.round(n),`%`]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`div`,{className:`flex-1 h-2 bg-bambu-dark-tertiary rounded-full overflow-hidden`,children:(0,G.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,G.jsxs)(`span`,{className:`text-xs text-bambu-gray min-w-[40px] text-right`,children:[Math.round(t),`g`]})]})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-2 text-xs`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`span`,{className:`text-bambu-gray/60`,children:[o(`inventory.labelWeight`),`: `]}),(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:E9(e.label_weight)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`span`,{className:`text-bambu-gray/60`,children:[o(`inventory.weightUsed`),`: `]}),(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:e.weight_used>0?E9(e.weight_used):`-`})]})]}),e.location_id&&(0,G.jsx)(s4e,{locationId:e.location_id,locationName:e.storage_location??null,isLast:!e.note,colorize:s,aboveColor:c,belowColor:l,optimalColor:u}),e.note&&(0,G.jsx)(`div`,{className:`text-xs text-bambu-gray/60 pt-3 border-t border-bambu-dark-tertiary truncate`,title:e.note,children:e.note})]})]})}var a4e={temperature:0,humidity:1,battery:2};function o4e(e){return e===`humidity`?`mr-[2px]`:e===`battery`?`mr-[3px]`:``}function j9(e,t){return $T(e,t,{decimals:2})}function M9(e,t,n,r,i){return t&&I6(F6(e),n,r,i)||`text-bambu-gray`}function s4e({locationId:e,locationName:t,isLast:n,colorize:r,aboveColor:i,belowColor:a,optimalColor:o}){let{t:s}=U(),{data:c}=K({queryKey:[`settings`],queryFn:Z.getSettings}),l=(c?.location_sensor_poll_interval||120)*1e3,{data:u}=K({queryKey:[`locationHaSensors`],queryFn:()=>Z.getLocationHASensors()}),d=(u??[]).some(t=>t.location_id===e),{data:f}=K({queryKey:[`locationHaSensorReadings`,e],queryFn:()=>Z.getLocationHASensorReadings(e,!1),refetchInterval:l,enabled:d}),p=f?.filter(e=>e.show_on_card);if(!p?.length)return null;let m=p.find(e=>e.device_class===`battery`),h=p.filter(e=>e.device_class!==`battery`).sort((e,t)=>(a4e[e.device_class??``]??99)-(a4e[t.device_class??``]??99));return(0,G.jsxs)(`div`,{className:`flex items-center gap-2 pt-3 border-t border-bambu-dark-tertiary text-xs text-bambu-gray ${n?`-mb-1`:``}`,children:[t&&(0,G.jsx)(`span`,{className:`truncate`,children:t}),(0,G.jsx)(`span`,{className:`text-bambu-gray/40`,children:`|`}),(0,G.jsx)(`div`,{className:`flex items-center gap-3`,children:h.map((e,t)=>{let n=eE(e),c=t===0?`ml-[-3.6px]`:``;return(0,G.jsxs)(`span`,{title:e.name,className:`flex items-center gap-[3px]`,children:[(0,G.jsx)(n,{className:`w-3 h-3 ${o4e(e.device_class)} ${c}`}),(0,G.jsx)(`span`,{className:M9(e,r,i,a,o),children:j9(e,s)})]},e.id)})}),m&&(()=>{let e=eE(m);return(0,G.jsxs)(`span`,{title:m.name,className:`flex items-center gap-[3px] ml-auto`,children:[(0,G.jsx)(e,{className:`w-3 h-3 ${o4e(m.device_class)}`}),(0,G.jsx)(`span`,{className:M9(m,r,i,a,o),children:j9(m,s)})]},m.id)})()]})}function c4e({spool:e,remaining:t,pct:n,isSelected:r,onToggleSelected:i,onEdit:a,onCopy:o,onRestore:s,onArchive:c,onDelete:l,onPrintLabel:u,onResetConsumedCounter:d,visibleColumns:f,assignmentMap:p,catalogMap:m,locationReadingsMap:h,currencySymbol:g,dateFormat:_,t:v,onSyncWeight:y,colorizeLocationSensors:b,locationSensorAboveColor:x,locationSensorBelowColor:S,locationSensorOptimalColor:C}){return(0,G.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,G.jsx)(`td`,{className:`w-10 px-3 py-3`,onClick:e=>e.stopPropagation(),children:i&&(0,G.jsx)(`input`,{type:`checkbox`,className:`h-4 w-4 cursor-pointer`,"aria-label":v(`inventory.bulk.selectRow`),checked:!!r,onChange:i})}),f.map(r=>(0,G.jsx)(`td`,{className:`py-3 px-4`,children:O9[r]?.({spool:e,remaining:t,pct:n,assignmentMap:p,catalogMap:m,locationReadingsMap:h,currencySymbol:g,dateFormat:_,t:v,onSyncWeight:y,colorizeLocationSensors:b,locationSensorAboveColor:x,locationSensorBelowColor:S,locationSensorOptimalColor:C})},r)),(0,G.jsx)(`td`,{className:`py-3 px-4`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-end gap-1`,onClick:e=>e.stopPropagation(),children:[(0,G.jsx)(`button`,{onClick:a,className:`p-1.5 text-bambu-gray hover:text-white rounded transition-colors`,title:v(`common.edit`),children:(0,G.jsx)(El,{className:`w-4 h-4`})}),o&&(0,G.jsx)(`button`,{onClick:o,className:`p-1.5 text-bambu-gray hover:text-bambu-green rounded transition-colors`,title:v(`inventory.copySpool`),children:(0,G.jsx)(Is,{className:`w-4 h-4`})}),u&&(0,G.jsx)(`button`,{onClick:u,className:`p-1.5 text-bambu-gray hover:text-white rounded transition-colors`,title:v(`inventory.labels.printOne`),children:(0,G.jsx)(Fl,{className:`w-4 h-4`})}),d&&e.weight_used>0&&(0,G.jsx)(`button`,{onClick:d,className:`p-1.5 text-bambu-gray hover:text-orange-600 dark:hover:text-orange-400 rounded transition-colors`,title:v(`inventory.resetConsumedCounterTooltip`),children:(0,G.jsx)(Zs,{className:`w-4 h-4`})}),e.archived_at?(0,G.jsx)(`button`,{onClick:s,className:`p-1.5 text-bambu-gray hover:text-bambu-green rounded transition-colors`,title:v(`inventory.restore`),children:(0,G.jsx)(Vl,{className:`w-4 h-4`})}):(0,G.jsx)(`button`,{onClick:c,className:`p-1.5 text-bambu-gray hover:text-yellow-600 dark:hover:text-yellow-400 rounded transition-colors`,title:v(`inventory.archive`),children:(0,G.jsx)(Oo,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:l,className:`p-1.5 text-bambu-gray hover:text-red-600 dark:hover:text-red-400 rounded transition-colors`,title:v(`common.delete`),children:(0,G.jsx)(Pu,{className:`w-4 h-4`})})]})})]})}function l4e({spools:e,headerSpool:t,remaining:n,pct:r,isExpanded:i,onToggle:a,onEdit:o,onCopy:s,onArchive:c,onDelete:l,onPrintLabel:u,onResetConsumedCounter:d,visibleColumns:f,assignmentMap:p,catalogMap:m,locationReadingsMap:h,currencySymbol:g,dateFormat:_,t:v,onSyncWeight:y,colorizeLocationSensors:b,locationSensorAboveColor:x,locationSensorBelowColor:S,locationSensorOptimalColor:C,selectedIds:w,onToggleSelected:T,onToggleGroupSelected:E}){let D=!!w&&e.every(e=>w.has(e.id));return(0,G.jsxs)(G.Fragment,{children:[(0,G.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,G.jsx)(`td`,{className:`w-10 px-3 py-3`,onClick:e=>e.stopPropagation(),children:E&&(0,G.jsx)(`input`,{type:`checkbox`,className:`h-4 w-4 cursor-pointer`,"aria-label":v(`inventory.bulk.selectGroup`),checked:D,onChange:t=>E(e.map(e=>e.id),t.target.checked)})}),f.map((a,o)=>(0,G.jsx)(`td`,{className:`py-3 px-4`,children:o===0?(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(ss,{className:`w-4 h-4 text-bambu-gray transition-transform ${i?``:`-rotate-90`}`}),O9[a]?.({spool:t,remaining:n,pct:r,assignmentMap:p,catalogMap:m,locationReadingsMap:h,currencySymbol:g,dateFormat:_,t:v,onSyncWeight:y,colorizeLocationSensors:b,locationSensorAboveColor:x,locationSensorBelowColor:S,locationSensorOptimalColor:C})]}):a===`id`?(0,G.jsx)(`span`,{className:`text-xs font-medium bg-bambu-green/20 text-bambu-green px-2 py-0.5 rounded-full`,children:v(`inventory.groupedSpools`,{count:e.length})}):O9[a]?.({spool:t,remaining:n,pct:r,assignmentMap:p,catalogMap:m,locationReadingsMap:h,currencySymbol:g,dateFormat:_,t:v,onSyncWeight:y,colorizeLocationSensors:b,locationSensorAboveColor:x,locationSensorBelowColor:S,locationSensorOptimalColor:C})},a)),(0,G.jsx)(`td`,{className:`py-3 px-4`,children:(0,G.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,G.jsx)(c4e,{spool:e,remaining:t,pct:e.label_weight>0?t/e.label_weight*100:0,isSelected:w?.has(e.id),onToggleSelected:T?()=>T(e.id):void 0,onEdit:()=>o(e),onCopy:s?()=>s(e):void 0,onRestore:()=>{},onArchive:()=>c(e.id),onDelete:()=>l(e.id),onPrintLabel:u?()=>u(e.id):void 0,onResetConsumedCounter:d?()=>d(e.id):void 0,visibleColumns:f,assignmentMap:p,catalogMap:m,locationReadingsMap:h,currencySymbol:g,dateFormat:_,t:v,onSyncWeight:y,colorizeLocationSensors:b,locationSensorAboveColor:x,locationSensorBelowColor:S,locationSensorOptimalColor:C},e.id)})]})}function u4e({hasFilters:e,onAddSpool:t,t:n}){return(0,G.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-16 px-4`,children:[(0,G.jsxs)(`div`,{className:`relative mb-6`,children:[(0,G.jsx)(`div`,{className:`absolute inset-0 -m-4 bg-bambu-green/5 rounded-full blur-2xl`}),(0,G.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,G.jsx)(`div`,{className:`absolute -top-1 -right-1 w-3 h-3 rounded-full bg-bambu-green/30`}),(0,G.jsx)(`div`,{className:`absolute -bottom-2 -left-2 w-2 h-2 rounded-full bg-bambu-green/20`}),e?(0,G.jsx)(Yl,{className:`w-10 h-10 text-bambu-gray/40`,strokeWidth:1.5}):(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(`div`,{className:`w-14 h-14 rounded-full border-4 border-bambu-gray/20 flex items-center justify-center`,children:(0,G.jsx)(`div`,{className:`w-6 h-6 rounded-full bg-bambu-gray/10 border-2 border-bambu-gray/20`})}),(0,G.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,G.jsx)(`span`,{className:`text-white text-lg font-bold leading-none`,children:`+`})})]})]})]}),(0,G.jsx)(`h3`,{className:`text-lg font-semibold text-white mb-2 text-center`,children:e?n(`inventory.noSpoolsMatch`):n(`inventory.noSpools`).split(`.`)[0]}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray text-center max-w-sm mb-6`,children:n(e?`inventory.noSpoolsMatchDesc`:`inventory.noSpools`)}),!e&&(0,G.jsxs)(Q,{onClick:t,children:[(0,G.jsx)(bl,{className:`w-4 h-4`}),n(`inventory.addSpool`)]})]})}function N9(e,t){let n=e?.[t];return typeof n==`string`?n:``}function d4e(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 f4e(e,t){let n=e?.[t];return n&&typeof n==`object`&&!Array.isArray(n)?n:void 0}function p4e(e,t=0,n=[]){n.push({folder:e,depth:t});for(let r of e.children??[])p4e(r,t+1,n);return n}function m4e(e,t){return t(e<1?`makerworld.phaseResolving`:`makerworld.phaseDownloading`)}function h4e(e){let[t,n]=(0,f.useState)(0);return(0,f.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 g4e(){let{t:e}=U(),{hasPermission:t}=Ld(),{showToast:n}=Zd(),r=no(),i=t(`makerworld:import`),[a,o]=(0,f.useState)(``),[s,c]=(0,f.useState)(null),[l,u]=(0,f.useState)(null),[d,p]=(0,f.useState)(null),[m,h]=(0,f.useState)(null),[g,_]=(0,f.useState)(null),[v,y]=(0,f.useState)(``),[b,x]=(0,f.useState)({}),S=K({queryKey:[`makerworld-status`],queryFn:()=>Z.getMakerworldStatus()}),C=K({queryKey:[`library-folders`],queryFn:()=>Z.getLibraryFolders()}),w=K({queryKey:[`makerworld-recent-imports`],queryFn:()=>Z.getMakerworldRecentImports(10)}),T=K({queryKey:[`settings`],queryFn:()=>Z.getSettings()}),E=T.data?.use_slicer_api??!1,D=T.data?.preferred_slicer||`bambu_studio`,O=VW(T.data?.open_in_slicer,T.data?.preferred_slicer),k=E?D:O,A=k===`orcaslicer`?`OrcaSlicer`:`Bambu Studio`,[j,M]=(0,f.useState)(null),N=(e,t)=>{M({kind:`libraryFile`,id:e,filename:t})},P=q({mutationFn:e=>Z.resolveMakerworldUrl(e),onSuccess:(e,t)=>{c(e),y(t),x({})},onError:t=>n(t.message||e(`makerworld.errors.resolveFailed`),`error`)});(0,f.useEffect)(()=>{s!==null&&a.trim()!==v.trim()&&(c(null),y(``),x({}))},[a,s,v]);let F=q({mutationFn:({instanceId:e,profileId:t})=>Z.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=q({mutationFn:({libraryFileId:e})=>Z.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}),h(null),n(e(`makerworld.importDeleted`),`success`)},onError:t=>{h(null),n(t.message||e(`makerworld.errors.deleteFailed`),`error`)}}),L=q({mutationFn:({instanceId:e,profileId:t})=>Z.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=h4e(F.isPending||L.isPending),z=m4e(R,e),B=e=>{e?.preventDefault();let t=a.trim();t&&P.mutate(t)};(0,f.useEffect)(()=>{if(!g)return;let e=e=>{e.key===`Escape`?_(null):e.key===`ArrowLeft`?_(e=>e&&e.index>0?{...e,index:e.index-1}:e):e.key===`ArrowRight`&&_(e=>e&&e.indexwindow.removeEventListener(`keydown`,e)},[g]);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){p({current:0,total:e.length});try{for(let t=0;t{try{let{token:r}=await Z.createLibrarySlicerToken(e),i=Z.getLibrarySlicerDownloadUrl(e,r,t);GW(`${window.location.origin}${i}`,n)}catch{let t=Z.getLibraryFileDownloadUrl(e);GW(`${window.location.origin}${t}`,n)}},ne=s?.design,re=f4e(ne,`designCreator`),ie=s?.instances??[],ae=(s?.already_imported_library_ids.length??0)>0,oe=S.data?.can_download??!1,se=S.data?.sign_in_expired??!1,H=(0,f.useMemo)(()=>N9(ne,`coverUrl`),[ne]),ce=N9(ne,`title`),le=N9(ne,`summary`),ue=N9(ne,`license`),de=F9(ne,`downloadCount`);return(0,G.jsxs)(`div`,{className:`p-4 md:p-8 max-w-screen-2xl space-y-6`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,G.jsx)(Tc,{className:`w-7 h-7 text-bambu-green`}),e(`makerworld.title`)]}),(0,G.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:e(`makerworld.description`)})]}),(0,G.jsxs)(`div`,{className:`grid gap-6 lg:grid-cols-[1fr_20rem]`,children:[(0,G.jsxs)(`div`,{className:`space-y-6 min-w-0`,children:[!oe&&(0,G.jsx)(Ud,{className:`border-amber-300 dark:border-amber-700 bg-amber-50 dark:bg-amber-900/20`,children:(0,G.jsx)(Gd,{children:(0,G.jsxs)(`div`,{className:`flex items-start gap-3 py-2`,children:[(0,G.jsx)(ps,{className:`w-5 h-5 text-amber-600 dark:text-amber-400 mt-0.5 shrink-0`}),(0,G.jsxs)(`div`,{className:`text-sm`,children:[(0,G.jsx)(`p`,{className:`font-medium text-amber-900 dark:text-amber-100`,children:e(se?`makerworld.signInExpiredTitle`:`makerworld.signInRequiredTitle`)}),(0,G.jsxs)(`p`,{className:`text-amber-800 dark:text-amber-200 mt-1`,children:[e(se?`makerworld.signInExpiredBody`:`makerworld.signInRequiredBody`),` `,(0,G.jsx)(Ci,{to:`/profiles`,className:`underline`,children:e(`makerworld.openCloudSettings`)})]})]})]})})}),(0,G.jsxs)(Ud,{children:[(0,G.jsx)(Wd,{children:(0,G.jsx)(`h2`,{className:`text-lg font-semibold`,children:e(`makerworld.pasteUrlHeader`)})}),(0,G.jsx)(Gd,{children:(0,G.jsxs)(`form`,{onSubmit:B,className:`flex gap-2`,children:[(0,G.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,G.jsxs)(Q,{type:`submit`,variant:`primary`,disabled:!a.trim()||P.isPending,children:[P.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(No,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`ml-2`,children:e(`makerworld.resolveButton`)})]})]})})]}),s&&(0,G.jsx)(Ud,{children:(0,G.jsx)(Gd,{children:(0,G.jsxs)(`div`,{className:`flex gap-4 py-2`,children:[H&&(0,G.jsx)(`img`,{src:P9(H),alt:ce,className:`w-32 h-32 object-cover rounded`,loading:`lazy`}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`h3`,{className:`text-xl font-semibold truncate`,children:ce||e(`makerworld.untitledModel`)}),re&&(0,G.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400 mt-1`,children:e(`makerworld.byCreator`,{name:N9(re,`name`)})}),(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-3 mt-2 text-xs text-gray-500 dark:text-gray-400`,children:[de!==null&&(0,G.jsx)(`span`,{children:e(`makerworld.downloadsCount`,{count:de})}),ue&&(0,G.jsxs)(`span`,{children:[e(`makerworld.licensePrefix`),`: `,ue]}),ae&&(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-emerald-600 dark:text-emerald-400`,children:[(0,G.jsx)(as,{className:`w-3 h-3`}),` `,e(`makerworld.alreadyImported`)]})]}),le&&(0,G.jsx)(`div`,{className:`mt-3 text-sm prose prose-sm max-w-none dark:prose-invert line-clamp-3`,dangerouslySetInnerHTML:{__html:VG.sanitize(d4e(le))}}),s&&(0,G.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,G.jsx)(Qs,{className:`w-3 h-3`}),` `,e(`makerworld.openOnMakerworld`)]})]})]})})}),s&&ie.length>0&&(0,G.jsxs)(Ud,{children:[(0,G.jsx)(Wd,{children:(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,G.jsx)(`h2`,{className:`text-lg font-semibold`,children:e(`makerworld.platesHeader`,{count:ie.length})}),(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,G.jsx)(`label`,{className:`text-xs text-gray-600 dark:text-gray-400`,children:e(`makerworld.importTo`)}),(0,G.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,G.jsx)(`option`,{value:``,children:e(`makerworld.folderAuto`)}),(C.data??[]).filter(e=>!(e.is_external&&e.external_readonly)).flatMap(e=>p4e(e)).map(({folder:e,depth:t})=>(0,G.jsx)(`option`,{value:e.id,children:`${`— `.repeat(t)}${e.name}`},e.id))]}),(0,G.jsx)(Q,{variant:`primary`,size:`sm`,disabled:!i||!oe||d!==null||F.isPending||L.isPending,onClick:ee,children:d===null?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Gs,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`ml-2`,children:e(`makerworld.importAll`)})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),(0,G.jsxs)(`span`,{className:`ml-2`,children:[e(`makerworld.importAllProgress`,{current:d.current,total:d.total}),R>0&&` · ${z} · ${R}s`]})]})})]})]})}),(0,G.jsx)(Gd,{children:(0,G.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,m=f?.devProductName??null,g=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,G.jsxs)(`div`,{className:`flex flex-col gap-2 p-3 border rounded border-gray-200 dark:border-gray-700`,children:[(0,G.jsxs)(`div`,{className:`flex gap-3 items-center`,children:[(()=>{let n=V(t),r=n.length>0;return(0,G.jsxs)(`button`,{type:`button`,disabled:!r,onClick:()=>r&&_({images:n,index:0}),className:`relative w-16 h-16 shrink-0 rounded overflow-hidden group`,"aria-label":e(`makerworld.openGallery`),children:[s?(0,G.jsx)(`img`,{src:P9(s),alt:``,className:`w-16 h-16 object-cover`,loading:`lazy`}):(0,G.jsx)(`div`,{className:`w-16 h-16 bg-gray-100 dark:bg-gray-800`}),n.length>1&&(0,G.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,G.jsx)(zc,{className:`w-2.5 h-2.5`}),n.length]})]})})(),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`p`,{className:`font-medium truncate`,children:o||e(`makerworld.plateDefaultName`,{n:n+1})}),(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-3 text-xs text-gray-500 dark:text-gray-400 mt-1`,children:[m&&(0,G.jsx)(`span`,{className:`font-medium text-gray-700 dark:text-gray-300`,children:e(`makerworld.slicedFor`,{printer:m,defaultValue:`Sliced for {{printer}}`})}),c!==null&&(0,G.jsx)(`span`,{children:e(`makerworld.materialCount`,{count:c})}),l&&(0,G.jsx)(`span`,{children:e(`makerworld.amsRequired`)}),u!==null&&(0,G.jsx)(`span`,{children:e(`makerworld.downloadsCount`,{count:u})})]}),g.length>0&&(0,G.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mt-1`,title:g.join(`, `),children:e(`makerworld.alsoCompatible`,{printers:g.slice(0,6).join(`, `)+(g.length>6?`…`:``),defaultValue:`Also marked compatible: {{printers}}`})})]}),(0,G.jsxs)(`div`,{className:`flex gap-2 shrink-0`,children:[(0,G.jsx)(Q,{variant:`ghost`,size:`sm`,disabled:!i||!oe||v||y||d!==null,onClick:()=>F.mutate({instanceId:r,profileId:a}),title:oe?void 0:e(`makerworld.signInRequiredTitle`),children:v?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),(0,G.jsxs)(`span`,{className:`ml-2`,children:[z,R>0&&` · ${R}s`]})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Gs,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`ml-2`,children:e(`makerworld.importToLibrary`)})]})}),(0,G.jsx)(Q,{variant:`primary`,size:`sm`,disabled:!i||!oe||v||y||d!==null,onClick:()=>L.mutate({instanceId:r,profileId:a}),title:oe?void 0:e(`makerworld.signInRequiredTitle`),children:y?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),(0,G.jsxs)(`span`,{className:`ml-2`,children:[z,R>0&&` · ${R}s`]})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Qs,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`ml-2`,children:e(`makerworld.sliceIn`,{slicer:A})})]})})]})]}),x&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2 pl-20 text-xs`,children:[(0,G.jsx)(as,{className:`w-3.5 h-3.5 text-emerald-600 dark:text-emerald-400 shrink-0`}),(0,G.jsx)(`span`,{className:`text-emerald-700 dark:text-emerald-300`,children:x.was_existing?e(`makerworld.lastImportAlreadyInLibrary`):e(`makerworld.lastImportSuccess`)}),(0,G.jsxs)(Q,{variant:`ghost`,size:`sm`,onClick:()=>{let e=x.folder_id?`/files?folder=${x.folder_id}`:`/files`;window.location.assign(e)},children:[(0,G.jsx)(pc,{className:`w-3.5 h-3.5`}),(0,G.jsx)(`span`,{className:`ml-1.5`,children:e(`makerworld.viewInLibrary`)})]}),E?(0,G.jsxs)(Q,{variant:`ghost`,size:`sm`,onClick:()=>N(x.library_file_id,x.filename),children:[(0,G.jsx)(Ms,{className:`w-3.5 h-3.5`}),(0,G.jsx)(`span`,{className:`ml-1.5`,children:e(`slice.action`,`Slice`)})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(Q,{variant:`ghost`,size:`sm`,onClick:()=>te(x.library_file_id,x.filename,`bambu_studio`),children:[(0,G.jsx)(Qs,{className:`w-3.5 h-3.5`}),(0,G.jsx)(`span`,{className:`ml-1.5`,children:e(`makerworld.openInBambuStudio`)})]}),(0,G.jsxs)(Q,{variant:`ghost`,size:`sm`,onClick:()=>te(x.library_file_id,x.filename,`orcaslicer`),children:[(0,G.jsx)(Qs,{className:`w-3.5 h-3.5`}),(0,G.jsx)(`span`,{className:`ml-1.5`,children:e(`makerworld.openInOrcaSlicer`)})]})]}),(0,G.jsx)(`div`,{className:`ml-auto`,children:(0,G.jsx)(Q,{variant:`ghost`,size:`sm`,disabled:I.isPending&&I.variables?.profileId===a,onClick:()=>{a!==null&&h({libraryFileId:x.library_file_id,profileId:a,filename:x.filename})},title:e(`makerworld.deleteImport`),children:I.isPending&&I.variables?.profileId===a?(0,G.jsx)(Y,{className:`w-3.5 h-3.5 animate-spin`}):(0,G.jsx)(Pu,{className:`w-3.5 h-3.5 text-red-500`})})})]})]},r)})})})]})]}),(0,G.jsx)(`aside`,{className:`lg:sticky lg:top-6 lg:self-start min-w-0`,children:w.data&&w.data.length>0&&(0,G.jsxs)(Ud,{children:[(0,G.jsx)(Wd,{children:(0,G.jsx)(`h2`,{className:`text-base font-semibold`,children:e(`makerworld.recentImportsHeader`)})}),(0,G.jsx)(Gd,{children:(0,G.jsx)(`div`,{className:`flex flex-col gap-2 max-h-[28rem] overflow-y-auto -mx-2 px-2`,children:w.data.map(t=>(0,G.jsxs)(`div`,{className:`flex gap-2 p-2 border rounded border-gray-200 dark:border-gray-700`,children:[t.thumbnail_path?(0,G.jsx)(`img`,{src:Z.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,G.jsx)(`div`,{className:`w-12 h-12 shrink-0 rounded bg-gray-100 dark:bg-gray-800`}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0 flex flex-col gap-1`,children:[(0,G.jsx)(`p`,{className:`text-xs font-medium truncate`,title:t.filename,children:t.filename}),(0,G.jsxs)(`div`,{className:`flex gap-0.5`,children:[(0,G.jsx)(Q,{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,G.jsx)(pc,{className:`w-3.5 h-3.5`})}),E?(0,G.jsx)(Q,{variant:`ghost`,size:`sm`,onClick:()=>N(t.library_file_id,t.filename),title:e(`slice.action`,`Slice`),children:(0,G.jsx)(Ms,{className:`w-3.5 h-3.5`})}):(0,G.jsx)(Q,{variant:`ghost`,size:`sm`,onClick:()=>te(t.library_file_id,t.filename,`bambu_studio`),title:e(`makerworld.openInBambuStudio`),children:(0,G.jsx)(Qs,{className:`w-3.5 h-3.5`})}),t.source_url&&(0,G.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,G.jsx)(Tc,{className:`w-3.5 h-3.5`})})]})]})]},t.library_file_id))})})]})})]}),(0,G.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`)}),m&&(0,G.jsx)(uf,{title:e(`makerworld.deleteImport`),message:e(`makerworld.confirmDelete`,{filename:m.filename}),confirmText:e(`makerworld.deleteImport`),variant:`danger`,isLoading:I.isPending,loadingText:e(`makerworld.importDeleting`),onCancel:()=>h(null),onConfirm:()=>I.mutate({libraryFileId:m.libraryFileId,profileId:m.profileId})}),j&&(0,G.jsx)(LW,{source:j,onClose:()=>M(null)}),g&&(0,G.jsxs)(`div`,{className:`fixed inset-0 bg-black/90 flex items-center justify-center z-50`,onClick:()=>_(null),role:`dialog`,"aria-modal":`true`,children:[(0,G.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(),_(null)},"aria-label":e(`common.close`,`Close`),children:(0,G.jsx)(nd,{className:`w-5 h-5`})}),g.images.length>1&&(0,G.jsxs)(G.Fragment,{children:[(0,G.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:g.index===0,onClick:e=>{e.stopPropagation(),_(e=>e&&{...e,index:Math.max(0,e.index-1)})},"aria-label":e(`makerworld.galleryPrev`),children:(0,G.jsx)(ls,{className:`w-6 h-6`})}),(0,G.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:g.index>=g.images.length-1,onClick:e=>{e.stopPropagation(),_(e=>e&&{...e,index:Math.min(e.images.length-1,e.index+1)})},"aria-label":e(`makerworld.galleryNext`),children:(0,G.jsx)(cs,{className:`w-6 h-6`})})]}),(0,G.jsx)(`img`,{src:P9(g.images[g.index].url),alt:g.images[g.index].name,className:`max-w-[90vw] max-h-[90vh] object-contain`,onClick:e=>e.stopPropagation()}),g.images.length>1&&(0,G.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:[g.index+1,` / `,g.images.length]})]})]})}var _4e=[`DEBUG`,`INFO`,`WARNING`,`ERROR`],I9={DEBUG:`text-gray-400`,INFO:`text-blue-400`,WARNING:`text-yellow-400`,ERROR:`text-red-400`},v4e={DEBUG:Ko,INFO:Bc,WARNING:Lu,ERROR:ps};function y4e(){let e=no(),[t,n]=(0,f.useState)(!0),[r,i]=(0,f.useState)(new Set),[a,o]=(0,f.useState)(``),[s,c]=(0,f.useState)(`ALL`),[l,u]=(0,f.useState)(!1),[d,p]=(0,f.useState)(!1),m=(0,f.useRef)(null),{data:h,isLoading:g,refetch:_}=K({queryKey:[`application-logs`,s,a],queryFn:()=>Ad.getLogs({limit:200,level:s===`ALL`?void 0:s,search:a||void 0}),refetchInterval:d?2e3:!1,enabled:l});(0,f.useEffect)(()=>{l||p(!1)},[l]);let v=q({mutationFn:()=>Ad.clearLogs(),onSuccess:()=>{e.invalidateQueries({queryKey:[`application-logs`]})}});(0,f.useEffect)(()=>{t&&m.current&&h?.entries&&(m.current.scrollTop=m.current.scrollHeight)},[h?.entries,t]);let y=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,f.useMemo)(()=>h?.entries??[],[h?.entries]),S=(0,f.useMemo)(()=>[...x].reverse(),[x]),C=({level:e})=>(0,G.jsx)(v4e[e]||Bc,{className:`w-3.5 h-3.5 ${I9[e]||`text-gray-400`}`});return(0,G.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg overflow-hidden`,children:[(0,G.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,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`p-2 rounded-lg ${d?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark-tertiary text-bambu-gray`}`,children:(0,G.jsx)(Ko,{className:`w-5 h-5`})}),(0,G.jsxs)(`div`,{className:`text-left`,children:[(0,G.jsx)(`p`,{className:`font-medium text-white`,children:`Application Logs`}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:d?`Live streaming - ${h?.filtered_count??0} entries`:`View and filter application logs`})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[d&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1.5 px-2 py-1 bg-bambu-green/20 rounded text-bambu-green text-xs`,children:[(0,G.jsx)(`span`,{className:`w-1.5 h-1.5 bg-bambu-green rounded-full animate-pulse`}),`Live`]}),l?(0,G.jsx)(us,{className:`w-5 h-5 text-bambu-gray`}):(0,G.jsx)(ss,{className:`w-5 h-5 text-bambu-gray`})]})]}),l&&(0,G.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex flex-col gap-2 p-4 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[d?(0,G.jsxs)(`button`,{onClick:e=>{e.stopPropagation(),p(!1)},className:`flex items-center gap-1.5 px-3 py-1.5 text-sm bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400 hover:bg-red-200 dark:hover:bg-red-500/30 rounded transition-colors`,children:[(0,G.jsx)(_u,{className:`w-4 h-4`}),`Stop`]}):(0,G.jsxs)(`button`,{onClick:e=>{e.stopPropagation(),p(!0),_()},className:`flex items-center gap-1.5 px-3 py-1.5 text-sm bg-bambu-green/20 text-bambu-green hover:bg-bambu-green/30 rounded transition-colors`,children:[(0,G.jsx)(Al,{className:`w-4 h-4`}),`Start`]}),(0,G.jsxs)(`button`,{onClick:()=>v.mutate(),disabled:v.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,G.jsx)(Pu,{className:`w-4 h-4`}),`Clear`]}),(0,G.jsx)(`button`,{onClick:()=>_(),disabled:g,className:`flex items-center gap-1.5 px-3 py-1.5 text-sm bg-bambu-dark-tertiary text-bambu-gray hover:text-white hover:bg-bambu-dark-secondary rounded transition-colors disabled:opacity-50`,children:(0,G.jsx)(zl,{className:`w-4 h-4 ${g?`animate-spin`:``}`})}),(0,G.jsx)(`div`,{className:`flex-1`}),(0,G.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-bambu-gray cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:t,onChange:e=>n(e.target.checked),className:`rounded border-bambu-dark-tertiary bg-bambu-dark-tertiary`}),`Auto-scroll`]}),(0,G.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[h?.filtered_count??0,`/`,h?.total_in_file??0]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`div`,{className:`relative flex-1`,children:[(0,G.jsx)(Yl,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,G.jsx)(`input`,{type:`text`,placeholder:`Search message or logger name...`,value: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,G.jsx)(`button`,{onClick:()=>o(``),className:`absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white`,children:(0,G.jsx)(nd,{className:`w-4 h-4`})})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1 bg-bambu-dark-secondary rounded border border-bambu-dark-tertiary`,children:[(0,G.jsx)(`button`,{onClick:()=>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`}),_4e.map((e,t)=>(0,G.jsx)(`button`,{onClick:()=>c(e),className:`px-2 py-1.5 text-xs transition-colors flex items-center gap-1 ${t===_4e.length-1?`rounded-r`:``} ${s===e?`${I9[e]} bg-bambu-dark-tertiary`:`text-bambu-gray hover:text-white`}`,children:e},e))]})]})]}),(0,G.jsx)(`div`,{ref:m,className:`overflow-auto font-mono text-xs bg-black min-h-[300px] max-h-[500px]`,children:x.length===0?(0,G.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-[300px] text-bambu-gray`,children:[(0,G.jsx)(`p`,{className:`mb-2`,children:`No log entries found`}),(0,G.jsx)(`p`,{className:`text-sm`,children:`Log file may be empty or cleared`})]}):(0,G.jsx)(`div`,{className:`divide-y divide-bambu-dark-tertiary/30`,children:S.map((e,t)=>{let n=r.has(t),i=e.message.includes(` `);return(0,G.jsx)(`div`,{className:`p-2 cursor-pointer hover:bg-bambu-dark-secondary/50 transition-colors ${n?`bg-bambu-dark-secondary/30`:``}`,onClick:()=>i&&y(t),children:(0,G.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray/70 shrink-0 w-20`,children:b(e.timestamp)}),(0,G.jsx)(`span`,{className:`shrink-0`,children:(0,G.jsx)(C,{level:e.level})}),(0,G.jsxs)(`span`,{className:`text-purple-400/80 shrink-0 max-w-[200px] truncate`,title:e.logger_name,children:[`[`,e.logger_name,`]`]}),(0,G.jsx)(`span`,{className:`flex-1 ${I9[e.level]||`text-white/80`} ${!n&&i?`truncate`:``}`,children:n?(0,G.jsx)(`pre`,{className:`whitespace-pre-wrap break-all`,children:e.message}):e.message.split(` `)[0]}),i&&(0,G.jsx)(`span`,{className:`text-bambu-gray/50 shrink-0`,children:n?(0,G.jsx)(us,{className:`w-3.5 h-3.5`}):(0,G.jsx)(ss,{className:`w-3.5 h-3.5`})})]})},t)})})}),(0,G.jsx)(`div`,{className:`flex items-center justify-between p-3 border-t border-bambu-dark-tertiary text-sm text-bambu-gray`,children:d?(0,G.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`w-2 h-2 bg-green-500 rounded-full animate-pulse`}),`Auto-refreshing every 2 seconds`]}):(0,G.jsx)(`span`,{children:`Click Start to enable live log streaming`})})]})]})}function b4e(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,G.jsxs)(`div`,{className:`flex items-start gap-3 p-4 bg-bambu-dark rounded-lg`,children:[(0,G.jsx)(`div`,{className:`p-2 rounded-lg bg-bambu-dark-tertiary ${i}`,children:(0,G.jsx)(e,{className:`w-5 h-5`})}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:t}),(0,G.jsx)(`p`,{className:`text-lg font-semibold text-white truncate`,children:n}),r&&(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:r})]})]})}function x4e({percent:e,color:t=`bg-bambu-green`}){return(0,G.jsx)(`div`,{className:`w-full h-2 bg-bambu-dark rounded-full overflow-hidden`,children:(0,G.jsx)(`div`,{className:`h-full ${t} transition-all duration-300`,style:{width:`${Math.min(100,e)}%`}})})}function R9({title:e,icon:t,children:n}){return(0,G.jsxs)(Ud,{className:`p-6`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-4`,children:[(0,G.jsx)(t,{className:`w-5 h-5 text-bambu-green`}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e})]}),n]})}function S4e(){let{t:e}=U(),t=no(),[n,r]=(0,f.useState)(null),[i,a]=(0,f.useState)(!1),[o,s]=(0,f.useState)(!1),[c,l]=(0,f.useState)(null),{data:u,isLoading:d,refetch:p,isFetching:m}=K({queryKey:[`systemInfo`],queryFn:Z.getSystemInfo,refetchInterval:3e4}),{data:h}=K({queryKey:[`debugLogging`],queryFn:Ad.getDebugLoggingState,staleTime:10*1e3,refetchInterval:10*1e3}),{data:g}=K({queryKey:[`settings`],queryFn:Z.getSettings}),{data:_}=K({queryKey:[`library-stats`],queryFn:Z.getLibraryStats}),{data:v}=K({queryKey:[`printers`],queryFn:Z.getPrinters}),{data:y,refetch:b,isFetching:x}=K({queryKey:[`systemHealth`],queryFn:Z.getSystemHealth,staleTime:60*1e3}),S=g?.time_format||`system`,C=async()=>{s(!0);try{let e=await Ad.setDebugLogging(!h?.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 Ad.downloadSupportBundle()}catch(e){r(e instanceof Error?e.message:`Failed to download support bundle`)}finally{a(!1)}};if(d)return(0,G.jsx)(`div`,{className:`flex items-center justify-center h-64`,children:(0,G.jsx)(Y,{className:`w-8 h-8 text-bambu-green animate-spin`})});if(!u)return(0,G.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,G.jsxs)(`div`,{className:`p-6 space-y-6`,children:[(0,G.jsxs)(`div`,{className:`flex flex-col items-start gap-4 sm:flex-row sm:items-center sm:justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h1`,{className:`text-2xl font-bold text-white`,children:e(`system.title`,`System Information`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:e(`system.subtitle`,`Monitor system resources and database statistics`)})]}),(0,G.jsxs)(`button`,{onClick:()=>p(),disabled:m,className:`flex items-center gap-2 px-4 py-2 bg-bambu-dark-secondary hover:bg-bambu-dark-tertiary rounded-lg transition-colors disabled:opacity-50`,children:[(0,G.jsx)(zl,{className:`w-4 h-4 ${m?`animate-spin`:``}`}),e(`common.refresh`,`Refresh`)]})]}),(0,G.jsx)(R9,{title:e(`system.application`,`Application`),icon:Ql,children:(0,G.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-4`,children:[(0,G.jsx)(L9,{icon:Ql,label:e(`system.version`,`Version`),value:`v${u.app.version}`}),(0,G.jsx)(L9,{icon:Ts,label:e(`system.uptime`,`System Uptime`),value:u.system.uptime_formatted}),(0,G.jsx)(L9,{icon:Ql,label:e(`system.hostname`,`Hostname`),value:u.system.hostname})]})}),(0,G.jsx)(R9,{title:e(`support.title`,`Support & Troubleshooting`),icon:jc,children:(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`support.description`,`Enable debug logging to capture detailed information, then download a support bundle to share when reporting issues.`)}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-4 bg-bambu-dark rounded-lg`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`p-2 rounded-lg ${h?.enabled?`bg-amber-500/20 text-amber-500`:`bg-bambu-dark-tertiary text-bambu-gray`}`,children:(0,G.jsx)(Ko,{className:`w-5 h-5`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`font-medium text-white`,children:e(`support.debugLogging`,`Debug Logging`)}),(0,G.jsxs)(`p`,{className:`text-sm text-bambu-gray`,children:[h?.enabled?e(`support.debugLoggingEnabled`,`Capturing detailed logs`):e(`support.debugLoggingDisabled`,`Normal logging level`),h?.enabled&&h.duration_seconds!==null&&(0,G.jsxs)(`span`,{className:`text-amber-700 dark:text-amber-400 ml-2`,children:[`(`,Math.floor(h.duration_seconds/60),`m `,h.duration_seconds%60,`s)`]})]})]})]}),(0,G.jsxs)(`button`,{onClick:C,disabled:o,className:`px-4 py-2 rounded-lg font-medium transition-colors flex items-center gap-2 ${h?.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,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),h?.enabled?e(`support.disableDebug`,`Disable`):e(`support.enableDebug`,`Enable`)]})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-4 bg-bambu-dark rounded-lg`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`p-2 rounded-lg bg-bambu-dark-tertiary text-bambu-green`,children:(0,G.jsx)(Gs,{className:`w-5 h-5`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`font-medium text-white`,children:e(`support.supportBundle`,`Support Bundle`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`support.supportBundleDescription`,`Download system info and logs as a ZIP file`)})]})]}),(0,G.jsxs)(`button`,{onClick:w,disabled:i||!h?.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:h?.enabled?void 0:e(`support.enableDebugFirst`,`Enable debug logging first`),children:[i&&(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),i?e(`support.bundleGenerating`,`Generating...`):e(`common.download`,`Download`)]})]}),i&&(0,G.jsxs)(`div`,{className:`p-3 bg-bambu-dark-tertiary/40 rounded-lg space-y-1`,children:[(0,G.jsxs)(`p`,{className:`text-sm font-medium text-white flex items-center gap-2`,children:[(0,G.jsx)(Y,{className:`w-3.5 h-3.5 animate-spin text-bambu-green`}),e(`support.bundleGenerating`,`Generating...`)]}),(0,G.jsxs)(`ul`,{className:`text-xs text-bambu-gray list-disc list-inside space-y-0.5 pl-1`,children:[(0,G.jsx)(`li`,{children:e(`support.bundleStepConnection`,`Running printer connectivity checks`)}),(0,G.jsx)(`li`,{children:e(`support.bundleStepVirtualPrinters`,`Running virtual-printer setup checks`)}),(0,G.jsx)(`li`,{children:e(`support.bundleStepLogScan`,`Scanning recent logs for known issues`)}),(0,G.jsx)(`li`,{children:e(`support.bundleStepBuild`,`Building the support bundle ZIP`)})]})]}),n&&(0,G.jsx)(`div`,{className:`p-3 bg-red-100 border border-red-300 rounded-lg text-red-700 dark:bg-red-500/20 dark:border-red-500/30 dark:text-red-400 text-sm`,children:n}),!h?.enabled&&(0,G.jsx)(`div`,{className:`p-4 bg-bambu-dark-tertiary/50 rounded-lg`,children:(0,G.jsxs)(`p`,{className:`text-sm text-bambu-gray`,children:[(0,G.jsx)(`span`,{className:`text-amber-700 dark:text-amber-400 font-medium`,children:e(`support.instructions`,`To report an issue:`)}),(0,G.jsx)(`br`,{}),`1. `,e(`support.step1`,`Enable debug logging`),(0,G.jsx)(`br`,{}),`2. `,e(`support.step2`,`Reproduce the issue`),(0,G.jsx)(`br`,{}),`3. `,e(`support.step3`,`Download the support bundle`),(0,G.jsx)(`br`,{}),`4. `,e(`support.step4`,`Attach the ZIP file to your issue report`)]})}),(0,G.jsxs)(`div`,{className:`p-4 bg-bambu-dark rounded-lg space-y-3`,children:[(0,G.jsx)(`p`,{className:`text-sm font-medium text-white`,children:e(`support.privacyTitle`,`What's in the support bundle?`)}),(0,G.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4 text-sm`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-bambu-green font-medium mb-1`,children:e(`support.collected`,`Collected:`)}),(0,G.jsxs)(`ul`,{className:`text-bambu-gray space-y-0.5`,children:[(0,G.jsxs)(`li`,{children:[`• `,e(`support.collectItem1`,`App version and debug mode`)]}),(0,G.jsxs)(`li`,{children:[`• `,e(`support.collectItem2`,`OS, architecture, Python version`)]}),(0,G.jsxs)(`li`,{children:[`• `,e(`support.collectItem3`,`Database statistics (counts only)`)]}),(0,G.jsxs)(`li`,{children:[`• `,e(`support.collectItem4`,`Printer models and nozzle counts`)]}),(0,G.jsxs)(`li`,{children:[`• `,e(`support.collectItem5`,`Non-sensitive settings (themes, formats)`)]}),(0,G.jsxs)(`li`,{children:[`• `,e(`support.collectItem6`,`Debug logs (sanitized)`)]}),(0,G.jsxs)(`li`,{children:[`• `,e(`support.collectItem7`,`Printer connectivity and firmware versions`)]}),(0,G.jsxs)(`li`,{children:[`• `,e(`support.collectItem8`,`Integration status (Spoolman, MQTT, HA)`)]}),(0,G.jsxs)(`li`,{children:[`• `,e(`support.collectItem9`,`Network interfaces (subnets only)`)]}),(0,G.jsxs)(`li`,{children:[`• `,e(`support.collectItem10`,`Python package versions`)]}),(0,G.jsxs)(`li`,{children:[`• `,e(`support.collectItem11`,`Database health checks`)]}),(0,G.jsxs)(`li`,{children:[`• `,e(`support.collectItem12`,`Docker environment details`)]})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-red-700 dark:text-red-400 font-medium mb-1`,children:e(`support.notCollected`,`NOT collected:`)}),(0,G.jsxs)(`ul`,{className:`text-bambu-gray space-y-0.5`,children:[(0,G.jsxs)(`li`,{children:[`• `,e(`support.notItem1`,`Printer names and serial numbers`)]}),(0,G.jsxs)(`li`,{children:[`• `,e(`support.notItem2`,`Access codes and passwords`)]}),(0,G.jsxs)(`li`,{children:[`• `,e(`support.notItem3`,`Email addresses`)]}),(0,G.jsxs)(`li`,{children:[`• `,e(`support.notItem4`,`API keys and tokens`)]}),(0,G.jsxs)(`li`,{children:[`• `,e(`support.notItem5`,`Webhook URLs`)]}),(0,G.jsxs)(`li`,{children:[`• `,e(`support.notItem6`,`Your hostname or username`)]}),(0,G.jsxs)(`li`,{children:[`• `,e(`support.notItem7`,`IP addresses`)]})]})]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray/70`,children:e(`support.privacyNote`,`Email addresses in logs are replaced with [EMAIL], printer names with [PRINTER], serial numbers with [SERIAL], and IP addresses with [IP].`)})]}),(0,G.jsx)(y4e,{})]})}),(0,G.jsxs)(R9,{title:e(`diagnostic.sectionTitle`,`Connection Diagnostic`),icon:yu,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4`,children:e(`diagnostic.sectionDescription`,`Check why a printer won't connect or won't print — port reachability, LAN developer mode, Docker network mode, and credentials.`)}),v&&v.length>0?(0,G.jsx)(`div`,{className:`space-y-2`,children:v.map(t=>(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-3 bg-bambu-dark rounded-lg`,children:[(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsx)(`span`,{className:`font-medium text-white`,children:t.name}),(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray ml-2`,children:t.ip_address})]}),(0,G.jsxs)(`button`,{onClick:()=>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,G.jsx)(yu,{className:`w-4 h-4`}),e(`diagnostic.runButton`,`Run diagnostic`)]})]},t.id))}):(0,G.jsx)(`p`,{className:`text-bambu-gray`,children:e(`diagnostic.noPrinters`,`No printers configured.`)})]}),(0,G.jsxs)(R9,{title:e(`systemHealth.sectionTitle`),icon:Mc,children:[(0,G.jsxs)(`div`,{className:`flex items-start justify-between gap-3 mb-3`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`systemHealth.sectionDescription`)}),(0,G.jsxs)(`button`,{onClick:()=>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,G.jsx)(zl,{className:`w-4 h-4 ${x?`animate-spin`:``}`}),e(`systemHealth.rescan`)]})]}),y?(0,G.jsx)(nte,{result:y}):(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`common.loading`)})]}),(0,G.jsxs)(R9,{title:e(`system.database`,`Database`),icon:Bs,children:[(0,G.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4 mb-4`,children:[(0,G.jsx)(L9,{icon:Bs,label:e(`system.dbEngine`,`Database Engine`),value:u.database.engine||`SQLite`}),(0,G.jsx)(L9,{icon:Bs,label:e(`system.dbVersion`,`Version`),value:u.database.version||`unknown`})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-4 mb-4`,children:[(0,G.jsx)(L9,{icon:Oo,label:e(`system.totalArchives`,`Total Archives`),value:u.database.archives}),(0,G.jsx)(L9,{icon:gs,label:e(`system.completed`,`Completed`),value:u.database.archives_completed,color:`text-green-500`}),(0,G.jsx)(L9,{icon:xs,label:e(`system.failed`,`Failed`),value:u.database.archives_failed,color:`text-red-500`}),(0,G.jsx)(L9,{icon:Y,label:e(`system.printing`,`Printing`),value:u.database.archives_printing,color:`text-yellow-500`})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-4`,children:[(0,G.jsx)(L9,{icon:Fl,label:e(`system.printers`,`Printers`),value:u.database.printers}),(0,G.jsx)(L9,{icon:xl,label:e(`system.filaments`,`Filaments`),value:u.database.filaments}),(0,G.jsx)(L9,{icon:fc,label:e(`system.projects`,`Projects`),value:u.database.projects}),(0,G.jsx)(L9,{icon:jl,label:e(`system.smartPlugs`,`Smart Plugs`),value:u.database.smart_plugs})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4 mt-4`,children:[(0,G.jsx)(L9,{icon:Ts,label:e(`system.totalPrintTime`,`Total Print Time`),value:u.database.total_print_time_formatted}),(0,G.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,G.jsxs)(R9,{title:e(`system.connectedPrinters`,`Connected Printers`),icon:Fl,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-4 mb-4`,children:[(0,G.jsx)(`div`,{className:`text-3xl font-bold text-bambu-green`,children:u.printers.connected}),(0,G.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,G.jsx)(`div`,{className:`space-y-2`,children:u.printers.connected_list.map(e=>(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-3 bg-bambu-dark rounded-lg`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`w-2 h-2 rounded-full bg-bambu-green`}),(0,G.jsx)(`span`,{className:`font-medium text-white`,children:e.name})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-4 text-sm text-bambu-gray`,children:[(0,G.jsx)(`span`,{children:e.model}),(0,G.jsx)(`span`,{className:`px-2 py-0.5 rounded ${e.state===`RUNNING`?`bg-bambu-green/20 text-bambu-green`:e.state===`IDLE`?`bg-blue-100 text-blue-700 dark:bg-blue-500/20 dark:text-blue-400`:`bg-bambu-dark-tertiary`}`,children:e.state})]})]},e.id))}):(0,G.jsx)(`p`,{className:`text-bambu-gray`,children:e(`system.noPrintersConnected`,`No printers connected`)})]}),(0,G.jsx)(R9,{title:e(`system.storage`,`Storage`),icon:kc,children:(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex justify-between text-sm mb-1`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:e(`system.diskUsage`,`Disk Usage`)}),(0,G.jsxs)(`span`,{className:`text-white`,children:[u.storage.disk_used_formatted,` / `,u.storage.disk_total_formatted]})]}),(0,G.jsx)(x4e,{percent:u.storage.disk_percent_used,color:T}),(0,G.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,G.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-4`,children:[(0,G.jsx)(L9,{icon:Oo,label:e(`system.archiveStorage`,`Archive Storage`),value:u.storage.archive_size_formatted}),(0,G.jsx)(L9,{icon:Bs,label:e(`system.databaseSize`,`Database Size`),value:u.storage.database_size_formatted}),_&&(0,G.jsx)(L9,{icon:pc,label:e(`system.fileManagerStorage`,`File Manager`),value:b4e(_.total_size_bytes),subValue:`${_.total_files} files, ${_.total_folders} folders`})]})]})}),(0,G.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-6`,children:[(0,G.jsx)(R9,{title:e(`system.memory`,`Memory`),icon:sl,children:(0,G.jsx)(`div`,{className:`space-y-4`,children:(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex justify-between text-sm mb-1`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:e(`system.memoryUsage`,`Memory Usage`)}),(0,G.jsxs)(`span`,{className:`text-white`,children:[u.memory.used_formatted,` / `,u.memory.total_formatted]})]}),(0,G.jsx)(x4e,{percent:u.memory.percent_used,color:E}),(0,G.jsxs)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:[u.memory.available_formatted,` `,e(`system.available`,`available`)]})]})})}),(0,G.jsx)(R9,{title:e(`system.cpu`,`CPU`),icon:Ls,children:(0,G.jsx)(`div`,{className:`space-y-4`,children:(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,G.jsx)(L9,{icon:Ls,label:e(`system.cores`,`Cores`),value:u.cpu.count,subValue:`${u.cpu.count_logical} logical`}),(0,G.jsx)(L9,{icon:Ls,label:e(`system.usage`,`Usage`),value:`${u.cpu.percent}%`})]})})})]}),(0,G.jsx)(R9,{title:e(`system.systemDetails`,`System Details`),icon:Ql,children:(0,G.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-4`,children:[(0,G.jsx)(L9,{icon:Ql,label:e(`system.os`,`Operating System`),value:u.system.platform,subValue:u.system.platform_release}),(0,G.jsx)(L9,{icon:Ls,label:e(`system.architecture`,`Architecture`),value:u.system.architecture}),(0,G.jsx)(L9,{icon:Ql,label:e(`system.python`,`Python`),value:u.system.python_version}),(0,G.jsx)(L9,{icon:Ts,label:e(`system.bootTime`,`Boot Time`),value:up(u.system.boot_time,S)})]})}),c&&(0,G.jsx)(Bm,{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 C4e(){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 w4e(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 T4e(){try{let e=sessionStorage.getItem(B9);return sessionStorage.removeItem(B9),H9(e)}catch(e){return console.warn(`consumePostLoginRedirect: sessionStorage unavailable`,e),null}}function E4e({provider:e,onClick:t,disabled:n}){let{t:r}=U(),[i,a]=(0,f.useState)(!1);return(0,G.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,G.jsx)(`img`,{src:Z.oidcProviderIconUrl(e.id),alt:``,className:`w-5 h-5 object-contain`,onError:()=>a(!0)}):(0,G.jsx)(iu,{className:`w-5 h-5 text-bambu-green`}),r(`login.twoFA.signInWith`,{provider:e.name})]})}function D4e(){let e=$n(),t=Xn(),[n]=ji(),{t:r}=U(),{login:i,loginWithToken:a,user:o,loading:s}=Ld(),{showToast:c}=Zd(),{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 T4e()??`/`}let[d,p]=(0,f.useState)(``),[m,h]=(0,f.useState)(``),[g,_]=(0,f.useState)(!1),[v,y]=(0,f.useState)(``),[b,x]=(0,f.useState)(`credentials`),[S,C]=(0,f.useState)(``),[w,T]=(0,f.useState)([]),[E,D]=(0,f.useState)(`totp`),[O,k]=(0,f.useState)(``),[A,j]=(0,f.useState)(!1),M=(0,f.useRef)(null),[N,P]=(0,f.useState)(!1),[F,I]=(0,f.useState)(``),[L,R]=(0,f.useState)(``),[z,B]=(0,f.useState)(``),{data:V}=K({queryKey:[`advancedAuthStatus`],queryFn:()=>Z.getAdvancedAuthStatus()}),{data:ee}=K({queryKey:[`oidcProviders`],queryFn:()=>Z.getOIDCProviders()}),[te,ne]=(0,f.useState)(!1);(0,f.useEffect)(()=>{!s&&o&&b===`credentials`&&e(`/`,{replace:!0})},[s,o,b,e]);let re=(0,f.useRef)(!1);(0,f.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,r=new Promise((e,t)=>setTimeout(()=>t(Error(`autologin timeout`)),5e3));Promise.race([Z.getOIDCAuthorizeUrl(e),r]).then(e=>{let n=t.state?.from;n?.pathname&&w4e(`${n.pathname}${n.search??``}`),window.location.href=e.auth_url}).catch(()=>{ne(!0)})},[V,n,t.state]);let ie=V?.local_login_enabled!==!1,ae=te&&V?.autologin_provider_id!=null;(0,f.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,f.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=C4e();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&&Z.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 oe=q({mutationFn:()=>i(d,m,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`)}}),se=q({mutationFn:e=>Z.forgotPassword({email:e}),onSuccess:e=>{c(e.message,`success`),_(!1),y(``)},onError:e=>{c(e.message,`error`)}}),H=q({mutationFn:()=>Z.forgotPasswordConfirm(F,L),onSuccess:e=>{c(e.message,`success`),x(`credentials`),I(``),R(``),B(``)},onError:e=>{c(e.message||r(`login.resetPassword.resetFailed`),`error`)}}),ce=q({mutationFn:()=>Z.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`)}}),le=q({mutationFn:()=>Z.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(``)}}),ue=q({mutationFn:e=>Z.getOIDCAuthorizeUrl(e),onSuccess:e=>{try{N?sessionStorage.setItem(z9,`1`):sessionStorage.removeItem(z9)}catch(e){console.warn(`setItem/removeItem auth_remember_me failed, Remember Me will not carry through OIDC redirect`,e)}let n=t.state?.from;n?.pathname&&w4e(`${n.pathname}${n.search??``}`),window.location.href=e.auth_url},onError:e=>{c(e.message||r(`login.oidcLoginFailed`),`error`)}}),de=e=>{if(e.preventDefault(),!d||!m){c(r(`login.enterCredentials`),`error`);return}oe.mutate()},fe=e=>{if(e.preventDefault(),!O.trim()){c(r(`login.twoFA.enterCode`),`error`);return}le.mutate()},pe=e=>{if(e.preventDefault(),!v){c(r(`login.enterEmail`),`error`);return}se.mutate(v)},me=e=>{D(e),k(``),j(!1),setTimeout(()=>M.current?.focus(),0)};return b===`reset-password`?(0,G.jsx)(`div`,{className:`min-h-screen flex items-center justify-center bg-bambu-dark p-4`,children:(0,G.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,G.jsxs)(`div`,{className:`text-center`,children:[(0,G.jsx)(`div`,{className:`flex items-center justify-center mb-4`,children:(0,G.jsx)(`div`,{className:`w-14 h-14 rounded-full bg-bambu-green/20 flex items-center justify-center`,children:(0,G.jsx)(Hc,{className:`w-7 h-7 text-bambu-green`})})}),(0,G.jsx)(`h2`,{className:`text-2xl font-bold text-white`,children:r(`login.resetPassword.title`)}),(0,G.jsx)(`p`,{className:`mt-2 text-sm text-bambu-gray`,children:r(`login.resetPassword.subtitle`)})]}),(0,G.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}H.mutate()},className:`space-y-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{htmlFor:`new-password`,className:`block text-sm font-medium text-white mb-2`,children:r(`login.resetPassword.newPassword`)}),(0,G.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,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{htmlFor:`confirm-password`,className:`block text-sm font-medium text-white mb-2`,children:r(`login.resetPassword.confirmPassword`)}),(0,G.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,G.jsx)(`button`,{type:`submit`,disabled:H.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:H.isPending?r(`login.resetPassword.saving`):r(`login.resetPassword.submit`)})]}),(0,G.jsx)(`div`,{className:`text-center`,children:(0,G.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,G.jsx)(`div`,{className:`min-h-screen flex items-center justify-center bg-bambu-dark p-4`,children:(0,G.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,G.jsxs)(`div`,{className:`text-center`,children:[(0,G.jsx)(`div`,{className:`flex items-center justify-center mb-4`,children:(0,G.jsx)(`div`,{className:`w-14 h-14 rounded-full bg-bambu-green/20 flex items-center justify-center`,children:(0,G.jsx)(iu,{className:`w-7 h-7 text-bambu-green`})})}),(0,G.jsx)(`h2`,{className:`text-2xl font-bold text-white`,children:r(`login.twoFA.title`)}),(0,G.jsx)(`p`,{className:`mt-2 text-sm text-bambu-gray`,children:r(`login.twoFA.subtitle`)})]}),w.length>1&&(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[w.includes(`totp`)&&(0,G.jsxs)(`button`,{type:`button`,onClick:()=>me(`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,G.jsx)(du,{className:`w-4 h-4`}),r(`login.twoFA.methodAuthenticator`)]}),w.includes(`email`)&&(0,G.jsxs)(`button`,{type:`button`,onClick:()=>me(`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,G.jsx)(tl,{className:`w-4 h-4`}),r(`login.twoFA.methodEmail`)]}),w.includes(`backup`)&&(0,G.jsxs)(`button`,{type:`button`,onClick:()=>me(`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,G.jsx)(Hc,{className:`w-4 h-4`}),r(`login.twoFA.methodBackup`)]})]}),(0,G.jsxs)(`form`,{onSubmit:fe,className:`space-y-4`,children:[E===`totp`&&(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:r(`login.twoFA.instructionsTotp`)}),E===`email`&&(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:r(A?`login.twoFA.instructionsEmail`:`login.twoFA.instructionsEmailNotSent`)}),!A&&(0,G.jsx)(Q,{type:`button`,variant:`secondary`,className:`w-full`,onClick:()=>ce.mutate(),disabled:ce.isPending,children:ce.isPending?r(`login.twoFA.sendingCode`):r(`login.twoFA.sendCodeButton`)}),A&&(0,G.jsx)(`button`,{type:`button`,onClick:()=>{j(!1),ce.mutate()},className:`text-xs text-bambu-gray hover:text-bambu-green transition-colors`,children:r(`login.twoFA.resendCode`)})]}),E===`backup`&&(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:r(`login.twoFA.instructionsBackup`)}),(0,G.jsxs)(`div`,{children:[(0,G.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,G.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,G.jsx)(`button`,{type:`submit`,disabled:le.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:le.isPending?r(`login.twoFA.verifyingButton`):r(`login.twoFA.verifyButton`)})]}),(0,G.jsx)(`div`,{className:`text-center`,children:(0,G.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,G.jsxs)(`div`,{className:`min-h-screen flex items-center justify-center bg-bambu-dark p-4`,children:[(0,G.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,G.jsxs)(`div`,{className:`text-center`,children:[(0,G.jsx)(`div`,{className:`flex items-center justify-center mb-6`,children:(0,G.jsx)(`img`,{src:l===`dark`?`/img/bambuddy_logo_dark_transparent.png`:`/img/bambuddy_logo_light.png`,alt:`Bambuddy`,className:`h-16`})}),(0,G.jsx)(`h2`,{className:`text-3xl font-bold text-white`,children:r(`login.title`)}),(0,G.jsx)(`p`,{className:`mt-2 text-sm text-bambu-gray`,children:r(`login.subtitle`)})]}),ae&&(0,G.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,G.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,G.jsxs)(`form`,{className:`mt-8 space-y-6`,onSubmit:de,children:[(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.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,G.jsx)(`input`,{id:`username`,type:`text`,required:!0,value:d,onChange:e=>p(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,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{htmlFor:`password`,className:`block text-sm font-medium text-white mb-2`,children:r(`login.password`)||`Password`}),(0,G.jsx)(`input`,{id:`password`,type:`password`,required:!0,value:m,onChange:e=>h(e.target.value),className:`block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:r(`login.passwordPlaceholder`),autoComplete:`current-password`})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.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,G.jsx)(`label`,{htmlFor:`remember-me`,className:`text-sm text-bambu-gray cursor-pointer`,children:r(`login.rememberMe`)})]}),(0,G.jsx)(`div`,{children:(0,G.jsx)(`button`,{type:`submit`,disabled:oe.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:oe.isPending?r(`login.signingIn`):r(`login.signIn`)})}),(0,G.jsx)(`div`,{className:`text-center`,children:(0,G.jsx)(`button`,{type:`button`,onClick:()=>_(!0),className:`text-sm text-bambu-gray hover:text-bambu-green transition-colors`,children:r(`login.forgotPassword`)})})]}),ee&&ee.length>0&&(0,G.jsxs)(`div`,{className:`space-y-3`,children:[ie&&(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(`div`,{className:`absolute inset-0 flex items-center`,children:(0,G.jsx)(`div`,{className:`w-full border-t border-bambu-dark-tertiary`})}),(0,G.jsx)(`div`,{className:`relative flex justify-center text-sm`,children:(0,G.jsx)(`span`,{className:`px-2 bg-bambu-dark-secondary text-bambu-gray`,children:r(`login.twoFA.orContinueWith`)})})]}),!ie&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.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,G.jsx)(`label`,{htmlFor:`remember-me`,className:`text-sm text-bambu-gray cursor-pointer`,children:r(`login.rememberMe`)})]}),(0,G.jsx)(`div`,{className:`space-y-2`,children:ee.map(e=>(0,G.jsx)(E4e,{provider:e,onClick:()=>ue.mutate(e.id),disabled:ue.isPending},e.id))})]})]}),g&&(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:()=>_(!1),children:(0,G.jsxs)(Ud,{className:`w-full max-w-md`,onClick:e=>e.stopPropagation(),children:[(0,G.jsx)(Wd,{children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(tl,{className:`w-5 h-5 text-bambu-green`}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:r(`login.forgotPasswordTitle`)})]}),(0,G.jsx)(Q,{variant:`ghost`,size:`sm`,onClick:()=>{_(!1),y(``)},children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]})}),(0,G.jsx)(Gd,{children:V?.advanced_auth_enabled?(0,G.jsxs)(`form`,{onSubmit:pe,className:`space-y-4`,children:[(0,G.jsx)(`p`,{className:`text-bambu-gray text-sm`,children:r(`login.forgotPasswordEmailMessage`)}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{htmlFor:`forgot-email`,className:`block text-sm font-medium text-white mb-2`,children:r(`login.emailAddress`)}),(0,G.jsx)(`input`,{id:`forgot-email`,type:`email`,required:!0,value:v,onChange:e=>y(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,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,className:`flex-1`,onClick:()=>{_(!1),y(``)},children:r(`login.cancel`)}),(0,G.jsx)(Q,{type:`submit`,className:`flex-1`,disabled:se.isPending,children:se.isPending?r(`login.sending`):r(`login.sendResetEmail`)})]})]}):(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsx)(`p`,{className:`text-bambu-gray`,children:r(`login.forgotPasswordMessage`)}),(0,G.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4 space-y-2`,children:[(0,G.jsx)(`p`,{className:`text-sm text-white font-medium`,children:r(`login.howToReset`)}),(0,G.jsxs)(`ol`,{className:`text-sm text-bambu-gray space-y-1 list-decimal list-inside`,children:[(0,G.jsx)(`li`,{children:r(`login.resetStep1`)}),(0,G.jsx)(`li`,{children:r(`login.resetStep2`)}),(0,G.jsx)(`li`,{children:r(`login.resetStep3`)}),(0,G.jsx)(`li`,{children:r(`login.resetStep4`)})]})]}),(0,G.jsx)(Q,{variant:`secondary`,className:`w-full`,onClick:()=>_(!1),children:r(`login.gotIt`)})]})})]})})]})}function O4e(e,t){let n=new URL(e);for(let[e,r]of Object.entries(t))r&&n.searchParams.set(e,r);return n.toString()}function k4e(){let{t:e}=U(),{authEnabled:t,loading:n}=Ld(),[r]=ji(),[i,a]=(0,f.useState)({kind:`loading`}),o=(0,f.useRef)(!1),s=r.get(`client_id`)??``,c=r.get(`redirect_uri`)??``,l=r.get(`state`)??``,u=r.get(`code_challenge`)??``,d=r.get(`code_challenge_method`)??``,p=async()=>{a({kind:`redirecting`});try{let e=await Z.connectAuthorize({client_id:s,redirect_uri:c,code_challenge:u,code_challenge_method:`S256`});window.location.replace(O4e(e.redirect_uri,{code:e.code,state:l}))}catch(t){a({kind:`error`,message:t instanceof Error?t.message:e(`connectedApps.authorize.failed`)})}};return(0,f.useEffect)(()=>{if(!(n||o.current)){if(o.current=!0,!t){a({kind:`error`,message:e(`connectedApps.authorize.authDisabled`)});return}if(!s||!c||!u||d!==`S256`){a({kind:`error`,message:e(`connectedApps.authorize.invalidRequest`)});return}Z.getConnectAuthorizeInfo(s,c).then(e=>{e.already_granted?p():a({kind:`consent`,info:e})}).catch(t=>{a({kind:`error`,message:t instanceof sd&&t.status===409?e(`connectedApps.authorize.authDisabled`):e(`connectedApps.authorize.invalidRequest`)})})}},[n,t]),(0,G.jsx)(`div`,{className:`min-h-screen flex items-center justify-center bg-bambu-dark p-4`,children:(0,G.jsxs)(`div`,{className:`max-w-md w-full space-y-6 p-8 bg-gradient-to-br from-bambu-card to-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary shadow-lg`,children:[(i.kind===`loading`||i.kind===`redirecting`)&&(0,G.jsxs)(`div`,{className:`flex flex-col items-center gap-3 text-bambu-gray`,role:`status`,children:[(0,G.jsx)(Y,{className:`w-8 h-8 animate-spin text-bambu-green`}),(0,G.jsx)(`p`,{children:i.kind===`loading`?e(`connectedApps.authorize.checking`):e(`connectedApps.authorize.redirecting`)})]}),i.kind===`error`&&(0,G.jsxs)(`div`,{className:`text-center space-y-3`,children:[(0,G.jsx)(Lu,{className:`w-10 h-10 mx-auto text-yellow-600 dark:text-yellow-400`}),(0,G.jsx)(`h1`,{className:`text-xl font-semibold text-white`,children:e(`connectedApps.authorize.errorTitle`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i.message})]}),i.kind===`consent`&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`text-center space-y-3`,children:[(0,G.jsx)(`div`,{className:`w-14 h-14 mx-auto rounded-full bg-bambu-green/20 flex items-center justify-center`,children:(0,G.jsx)(Kc,{className:`w-7 h-7 text-bambu-green`})}),(0,G.jsx)(`h1`,{className:`text-xl font-semibold text-white text-balance`,children:e(`connectedApps.authorize.title`,{app:i.info.app_name})}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`connectedApps.authorize.signedInAs`,{username:i.info.username})})]}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`connectedApps.authorize.sharedData`,{app:i.info.app_name})}),(0,G.jsxs)(`div`,{className:`flex gap-3`,children:[(0,G.jsx)(`button`,{type:`button`,onClick:()=>{window.location.replace(O4e(c,{error:`access_denied`,state:l}))},className:`flex-1 px-4 py-2 bg-bambu-dark-tertiary text-white rounded-md hover:bg-bambu-dark-tertiary/80 focus:outline-none focus-visible:ring-2 focus-visible:ring-bambu-green`,children:e(`connectedApps.authorize.deny`)}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>void p(),className:`flex-1 px-4 py-2 bg-bambu-green text-white rounded-md hover:bg-bambu-green/90 focus:outline-none focus-visible:ring-2 focus-visible:ring-white`,children:e(`connectedApps.authorize.allow`)})]})]})]})})}function A4e(){let e=$n(),{t}=U(),{showToast:n}=Zd(),{mode:r}=Bd(),{refreshAuth:i}=Ld(),[a,o]=(0,f.useState)(!1),[s,c]=(0,f.useState)(``),[l,u]=(0,f.useState)(``),[d,p]=(0,f.useState)(``),m=q({mutationFn:()=>Z.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,G.jsx)(`div`,{className:`min-h-screen flex items-center justify-center bg-bambu-dark p-4`,children:(0,G.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,G.jsxs)(`div`,{className:`text-center`,children:[(0,G.jsx)(`div`,{className:`flex items-center justify-center mb-6`,children:(0,G.jsx)(`img`,{src:r===`dark`?`/img/bambuddy_logo_dark_transparent.png`:`/img/bambuddy_logo_light.png`,alt:`Bambuddy`,className:`h-16`})}),(0,G.jsx)(`h2`,{className:`text-3xl font-bold text-white`,children:t(`setup.title`)}),(0,G.jsx)(`p`,{className:`mt-2 text-sm text-bambu-gray`,children:t(`setup.subtitle`)})]}),(0,G.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}}m.mutate()},children:[(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center p-4 bg-bambu-dark-secondary/50 rounded-lg border border-bambu-dark-tertiary`,children:[(0,G.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,G.jsx)(`label`,{htmlFor:`auth-enabled`,className:`ml-3 block text-sm font-medium text-white`,children:t(`setup.enableAuth`)})]}),a&&(0,G.jsxs)(`div`,{className:`space-y-4 mt-4`,children:[(0,G.jsx)(`div`,{className:`p-3 bg-bambu-dark-secondary/50 border border-bambu-dark-tertiary rounded-lg`,children:(0,G.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,G.jsx)(Bc,{className:`w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0`}),(0,G.jsxs)(`div`,{className:`text-sm text-bambu-gray`,children:[(0,G.jsx)(`p`,{className:`text-white font-medium mb-1`,children:t(`setup.adminAccount`)}),(0,G.jsx)(`p`,{children:t(`setup.adminAccountDesc`)})]})]})}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{htmlFor:`admin-username`,className:`block text-sm font-medium text-white mb-2`,children:[t(`setup.adminUsername`),` `,(0,G.jsx)(`span`,{className:`text-bambu-gray text-xs`,children:t(`setup.optionalIfAdminExists`)})]}),(0,G.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,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{htmlFor:`admin-password`,className:`block text-sm font-medium text-white mb-2`,children:[t(`setup.adminPassword`),` `,(0,G.jsx)(`span`,{className:`text-bambu-gray text-xs`,children:t(`setup.optionalIfAdminExists`)})]}),(0,G.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,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{htmlFor:`confirm-password`,className:`block text-sm font-medium text-white mb-2`,children:t(`setup.confirmPassword`)}),(0,G.jsx)(`input`,{id:`confirm-password`,type:`password`,value:d,onChange:e=>p(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,G.jsx)(`div`,{children:(0,G.jsx)(`button`,{type:`submit`,disabled:m.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:m.isPending?t(`setup.settingUp`):t(`setup.completeSetup`)})})]})]})})}function j4e(){let{t:e}=U(),{user:t}=Ld(),{showToast:n}=Zd(),r=no(),i=$n(),[a,o]=(0,f.useState)(!0),[s,c]=(0,f.useState)(!0),[l,u]=(0,f.useState)(!0),[d,p]=(0,f.useState)(!0),[m,h]=(0,f.useState)(!1),{data:g,isLoading:_}=K({queryKey:[`advancedAuthStatus`],queryFn:Z.getAdvancedAuthStatus,staleTime:300*1e3}),{data:v,isLoading:y}=K({queryKey:[`settings`],queryFn:Z.getSettings,staleTime:300*1e3}),{data:b,isLoading:x}=K({queryKey:[`user-email-preferences`],queryFn:()=>Z.getUserEmailPreferences()});(0,f.useEffect)(()=>{(g&&!g.advanced_auth_enabled||v&&!v.user_notifications_enabled)&&i(`/settings`,{replace:!0})},[g,v,i]),(0,f.useEffect)(()=>{b&&(o(b.notify_print_start),c(b.notify_print_complete),u(b.notify_print_failed),p(b.notify_print_stopped),h(!1))},[b]);let S=q({mutationFn:()=>Z.updateUserEmailPreferences({notify_print_start:a,notify_print_complete:s,notify_print_failed:l,notify_print_stopped:d}),onSuccess:()=>{r.invalidateQueries({queryKey:[`user-email-preferences`]}),h(!1),n(e(`notifications.userEmail.saveSuccess`),`success`)},onError:t=>{n(t.message||e(`notifications.userEmail.saveError`),`error`)}}),C=(e,t)=>{e(!t),h(!0)};return x||_||y?(0,G.jsx)(`div`,{className:`flex items-center justify-center h-64`,children:(0,G.jsx)(Y,{className:`w-8 h-8 animate-spin text-bambu-green`})}):(0,G.jsxs)(`div`,{className:`p-4 md:p-6 max-w-2xl mx-auto`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3 mb-6`,children:[(0,G.jsx)(Vo,{className:`w-7 h-7 text-bambu-green`}),(0,G.jsx)(`h1`,{className:`text-2xl font-bold text-white`,children:e(`notifications.userEmail.title`)})]}),(0,G.jsx)(Ud,{className:`mb-6 border-blue-300 bg-blue-50 dark:border-blue-500/30 dark:bg-blue-500/5`,children:(0,G.jsx)(Gd,{className:`py-4`,children:(0,G.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,G.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,G.jsx)(tl,{className:`w-5 h-5 text-blue-600 dark:text-blue-400`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`text-white font-medium`,children:e(`notifications.userEmail.emailNotifications`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:e(`notifications.userEmail.emailNotificationsDesc`)}),t?.email?(0,G.jsxs)(`p`,{className:`text-sm text-blue-700 dark:text-blue-400 mt-2`,children:[e(`notifications.userEmail.sendingTo`),`: `,(0,G.jsx)(`strong`,{children:t.email})]}):(0,G.jsx)(`p`,{className:`text-sm text-yellow-700 dark:text-yellow-400 mt-2`,children:e(`notifications.userEmail.noEmailWarning`)})]})]})})}),(0,G.jsxs)(Ud,{className:`mb-6`,children:[(0,G.jsxs)(Wd,{children:[(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`notifications.userEmail.printJobNotifications`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:e(`notifications.userEmail.printJobNotificationsDesc`)})]}),(0,G.jsxs)(Gd,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-4 bg-bambu-dark rounded-lg`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`w-10 h-10 rounded-full flex items-center justify-center ${a?`bg-bambu-green/20`:`bg-bambu-dark-tertiary`}`,children:(0,G.jsx)(gs,{className:`w-5 h-5 ${a?`text-bambu-green`:`text-bambu-gray`}`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white font-medium`,children:e(`notifications.userEmail.printJobStarts`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`notifications.userEmail.printJobStartsDesc`)})]})]}),(0,G.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,G.jsx)(`span`,{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${a?`translate-x-6`:`translate-x-1`}`})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-4 bg-bambu-dark rounded-lg`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`w-10 h-10 rounded-full flex items-center justify-center ${s?`bg-bambu-green/20`:`bg-bambu-dark-tertiary`}`,children:(0,G.jsx)(gs,{className:`w-5 h-5 ${s?`text-bambu-green`:`text-bambu-gray`}`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white font-medium`,children:e(`notifications.userEmail.printJobFinishes`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`notifications.userEmail.printJobFinishesDesc`)})]})]}),(0,G.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,G.jsx)(`span`,{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${s?`translate-x-6`:`translate-x-1`}`})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-4 bg-bambu-dark rounded-lg`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`w-10 h-10 rounded-full flex items-center justify-center ${l?`bg-bambu-green/20`:`bg-bambu-dark-tertiary`}`,children:(0,G.jsx)(gs,{className:`w-5 h-5 ${l?`text-bambu-green`:`text-bambu-gray`}`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white font-medium`,children:e(`notifications.userEmail.printErrors`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`notifications.userEmail.printErrorsDesc`)})]})]}),(0,G.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,G.jsx)(`span`,{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${l?`translate-x-6`:`translate-x-1`}`})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-4 bg-bambu-dark rounded-lg`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`w-10 h-10 rounded-full flex items-center justify-center ${d?`bg-bambu-green/20`:`bg-bambu-dark-tertiary`}`,children:(0,G.jsx)(gs,{className:`w-5 h-5 ${d?`text-bambu-green`:`text-bambu-gray`}`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white font-medium`,children:e(`notifications.userEmail.printJobStops`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`notifications.userEmail.printJobStopsDesc`)})]})]}),(0,G.jsx)(`button`,{onClick:()=>C(p,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,G.jsx)(`span`,{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${d?`translate-x-6`:`translate-x-1`}`})})]})]})]}),(0,G.jsx)(`div`,{className:`flex justify-end`,children:(0,G.jsx)(Q,{onClick:()=>S.mutate(),disabled:!m||S.isPending||!t?.email,children:S.isPending?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),e(`common.saving`)]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Wl,{className:`w-4 h-4`}),e(`common.save`)]})})})]})}function M4e(){let e=$n(),[t,n]=ji(),{t:r}=U(),i=t.get(`archive`),a=t.get(`library_file`),o=t.get(`plate`),s=K({queryKey:[`gcode-viewer-archive-colors`,i],queryFn:()=>Z.getArchiveCapabilities(Number(i)),enabled:!!i,staleTime:5*6e4,retry:!1}),c=K({queryKey:[`gcode-viewer-library-colors`,a],queryFn:()=>Z.getLibraryFilePlates(Number(a)),enabled:!!a,staleTime:5*6e4,retry:!1}),l=K({queryKey:[`gcode-viewer-archive-plates`,i],queryFn:()=>Z.getArchivePlates(Number(i)),enabled:!!i,staleTime:5*6e4,retry:!1}),u=(0,f.useMemo)(()=>(i?l.data?.plates:c.data?.plates)??[],[i,l.data,c.data]),d=(0,f.useMemo)(()=>o?Number(o):u.length===0?null:Math.min(...u.map(e=>e.index)),[o,u]),p=e=>{if(e===d)return;let r=new URLSearchParams(t);r.set(`plate`,String(e)),n(r,{replace:!0})},m=(0,f.useMemo)(()=>{if(i)return s.data?.filament_colors;let e=u.find(e=>e.index===d)||u[0];if(!e?.filaments?.length)return;let t=[];for(let n of e.filaments){let e=Math.max(0,(n.slot_id??1)-1);n.color&&(t[e]=n.color)}return t.length>0?t:void 0},[i,s.data,u,d]),h=(0,f.useMemo)(()=>{let e=e=>o?`${e}?plate=${encodeURIComponent(o)}`:e;return i?e(Z.getArchiveGcode(Number(i))):a?e(Z.getLibraryFileGcodeUrl(Number(a))):null},[i,a,o]),g=()=>{window.history.length>1?e(-1):e(i?`/archives`:`/files`)},_=i?r(`gcodeViewer.backToArchives`,`Back to Archives`):r(`gcodeViewer.backToFiles`,`Back to File Manager`);return(0,G.jsxs)(`div`,{className:`flex flex-col min-h-[calc(100vh-64px)] lg:h-screen`,children:[(0,G.jsxs)(`div`,{className:`flex-shrink-0 px-4 py-2 border-b border-bambu-dark-tertiary flex flex-wrap items-center gap-x-4 gap-y-2`,children:[(0,G.jsxs)(`button`,{type:`button`,onClick:g,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,G.jsx)(jo,{className:`w-4 h-4`}),_]}),u.length>1&&(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:r(`gcodeViewer.plates`,`Plates`)}),u.map(e=>(0,G.jsx)(`button`,{type:`button`,onClick:()=>p(e.index),"aria-pressed":e.index===d,title:e.name??void 0,className:`px-2 py-0.5 rounded text-xs transition-colors ${e.index===d?`bg-bambu-green text-white`:`bg-bambu-dark-tertiary text-gray-700 dark:text-gray-300 hover:text-gray-900 dark:hover:text-white`}`,children:r(`gcodeViewer.plateN`,`Plate {{n}}`,{n:e.index})},e.index))]})]}),h?(0,G.jsx)(FT,{gcodeUrl:h,filamentColors:m,className:`flex-1 min-h-0`}):(0,G.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-sm text-bambu-gray`,children:r(`gcodeViewer.noSource`,`No file was given to preview.`)})]})}var N4e=4401;function P4e(){let e=(0,f.useRef)(null),t=(0,f.useRef)(null),n=(0,f.useRef)(!1),r=no(),[i,a]=(0,f.useState)(!1),o=(0,f.useRef)(new Map),{showToast:s}=Zd(),{t:c}=U(),l=(0,f.useRef)(new Set),u=(0,f.useRef)(null),d=(0,f.useRef)(new Map),p=(0,f.useRef)(null),m=(0,f.useRef)([]),h=(0,f.useRef)(!1),g=(0,f.useRef)(()=>{}),_=(0,f.useCallback)(()=>{if(h.current||m.current.length===0)return;h.current=!0;let e=()=>{let t=m.current.shift();t?(g.current(t),m.current.length>0?setTimeout(e,16):h.current=!1):h.current=!1};e()},[]),v=(0,f.useCallback)(async()=>{if(n.current||e.current?.readyState===WebSocket.OPEN)return;let r;try{r=(await Z.getWebSocketToken()).token}catch(e){let t=e instanceof sd?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?g.current(t):(m.current.push(t),_())}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===N4e)&&(t.current=window.setTimeout(()=>{v()},3e3))},c.onerror=e=>{console.error(`[WebSocket] Error`,e),c.close()},e.current=c},[_]),y=(0,f.useCallback)(()=>{p.current&&=(clearTimeout(p.current),null);let e=new Map(d.current);d.current.clear(),e.forEach((e,t)=>{r.setQueryData([`printerStatus`,t],t=>{let n={...t,...e};return n.wifi_signal==null&&t?.wifi_signal!=null&&(n.wifi_signal=t.wifi_signal),n})})},[r]),b=(0,f.useCallback)((e,t)=>{let n=d.current.get(e)||{};if(d.current.set(e,{...n,...t}),document.hidden){y();return}p.current||=window.setTimeout(y,100)},[y]),x=(0,f.useCallback)(e=>{l.current.add(e),u.current&&clearTimeout(u.current),u.current=window.setTimeout(()=>{let e=Array.from(l.current);l.current.clear(),u.current=null;let t=0;e.forEach(e=>{setTimeout(()=>{r.invalidateQueries({queryKey:[e]})},t),t+=500})},3e3)},[r]),S=(0,f.useCallback)(()=>{r.invalidateQueries({queryKey:[`spool-assignments`]}),r.invalidateQueries({queryKey:[`spoolman-slot-assignments`]}),r.invalidateQueries({queryKey:[`slotPresets`]})},[r]),C=(0,f.useCallback)(e=>{switch(e.type){case`printer_status`:e.printer_id!==void 0&&e.data&&b(e.printer_id,e.data);break;case`print_start`:e.printer_id!==void 0&&r.invalidateQueries({queryKey:[`printerStatus`,e.printer_id]});break;case`missing_spool_assignment`:{if(e.printer_id===void 0||!Array.isArray(e.missing_slots))break;let t=e.missing_slots.map(e=>e&&typeof e.slot==`string`?e.slot:`Unknown`).filter(e=>e.length>0);if(t.length===0){o.current.delete(e.printer_id);break}let n=t.join(`|`);if(o.current.get(e.printer_id)===n)break;o.current.set(e.printer_id,n),s(c(`printers.toast.missingSpoolAssignment`,{printer:e.printer_name||`Printer ${e.printer_id}`,slots:t.join(`, `)}),`warning`);break}case`print_complete`:x(`archives`),x(`archiveStats`);break;case`print_confirm_request`:{let t=e.data;t?.archive_id!=null&&window.dispatchEvent(new CustomEvent(`print-confirm-request`,{detail:t}));break}case`kill_switch_triggered`:s(c(`printers.toast.killSwitchTriggered`,{printer:e.printer_name||`Printer ${e.printer_id??`?`}`,filename:e.filename||c(`common.unknown`)}),`error`);break;case`billing_charge_failed`:s(c(`printers.toast.billingChargeFailed`,{printer:e.printer_name||`Printer ${e.printer_id??`?`}`,filename:e.filename||c(`common.unknown`)}),`error`);break;case`archive_created`:x(`archives`),x(`archiveStats`);break;case`archive_updated`:x(`archives`);break;case`pong`:break;case`plate_not_empty`:window.dispatchEvent(new CustomEvent(`plate-not-empty`,{detail:{printer_id:e.printer_id,printer_name:e.printer_name,message:e.message}}));break;case`announcements_changed`:x(`announcements`);break;case`inventory_changed`:x(`inventory-spools`),x(`spoolman-inventory-spools`),x(f6[0]),x(m6[0]),x(`material-number-stats`);break;case`spool_assignment_changed`:S();break;case`spool_assignment_verified`:{let t=e.printer_name||`Printer`,n=e.slot||`?`;e.verified?e.kprofile_applied===!1?s(c(`printers.toast.assignmentVerifiedNoKprofile`,{slot:n,printer:t}),`warning`):s(c(`printers.toast.assignmentVerified`,{slot:n,printer:t}),`success`):s(c(`printers.toast.assignmentNotConfirmed`,{slot:n,printer:t}),`warning`);break}case`spool_auto_assigned`:x(`inventory-spools`),S();break;case`spool_usage_logged`:x(`inventory-spools`);break;case`unknown_tag`:{let t=e;window.dispatchEvent(new CustomEvent(`unknown-tag`,{detail:{printer_id:t.printer_id,ams_id:t.ams_id,tray_id:t.tray_id,tag_uid:t.tag_uid,tray_uuid:t.tray_uuid,tray_type:t.tray_type,tray_color:t.tray_color,tray_sub_brands:t.tray_sub_brands,tray_count:t.tray_count}}));break}case`spoolbuddy_weight`:window.dispatchEvent(new CustomEvent(`spoolbuddy-weight`,{detail:e}));break;case`spoolbuddy_tag_matched`:window.dispatchEvent(new CustomEvent(`spoolbuddy-tag-matched`,{detail:e})),x(`inventory-spools`);break;case`spoolbuddy_unknown_tag`:window.dispatchEvent(new CustomEvent(`spoolbuddy-unknown-tag`,{detail:e}));break;case`spoolbuddy_tag_removed`:window.dispatchEvent(new CustomEvent(`spoolbuddy-tag-removed`,{detail:e}));break;case`spoolbuddy_tag_written`:window.dispatchEvent(new CustomEvent(`spoolbuddy-tag-written`,{detail:e})),x(`inventory-spools`);break;case`spoolbuddy_tag_write_failed`:window.dispatchEvent(new CustomEvent(`spoolbuddy-tag-write-failed`,{detail:e}));break;case`spoolbuddy_online`:window.dispatchEvent(new CustomEvent(`spoolbuddy-online`,{detail:e})),x(`spoolbuddy-devices`),x(`spoolbuddy-update-check`);break;case`spoolbuddy_offline`:window.dispatchEvent(new CustomEvent(`spoolbuddy-offline`,{detail:e})),x(`spoolbuddy-devices`);break;case`spoolbuddy_update`:x(`spoolbuddy-devices`),x(`spoolbuddy-update-check`);break;case`queue_item_uploading`:case`queue_item_upload_progress`:case`queue_item_acked`:case`queue_item_failed`:window.dispatchEvent(new CustomEvent(`bambuddy:dispatch-toast`,{detail:e}));break;case`pipeline_run_updated`:r.invalidateQueries({queryKey:[`pipeline-runs-all`]}),e.run?.pipeline_id&&r.invalidateQueries({queryKey:[`pipeline-runs`,e.run.pipeline_id]});break}},[r,x,S,b,s,c]);return(0,f.useEffect)(()=>{g.current=C},[C]),(0,f.useEffect)(()=>(n.current=!1,v(),()=>{n.current=!0,t.current&&clearTimeout(t.current),u.current&&clearTimeout(u.current),p.current&&clearTimeout(p.current),e.current&&e.current.close()}),[v]),{isConnected:i,sendMessage:(0,f.useCallback)(t=>{e.current?.readyState===WebSocket.OPEN&&e.current.send(JSON.stringify(t))},[])}}var F4e=`#00ae42`,I4e=e=>e!=null&&e>0?e:1/0;function L4e(e){let t=null;for(let n of e){if(!n||n.state!==`RUNNING`||n.progress==null)continue;if(t===null){t=n;continue}let e=I4e(n.remaining_time),r=I4e(t.remaining_time);(e(t.progress??0))&&(t=n)}return t}function R4e(e){let t=document.createElement(`canvas`);t.width=32,t.height=32;let n=t.getContext(`2d`);if(!n)return null;let r=getComputedStyle(document.documentElement).getPropertyValue(`--accent`).trim()||F4e,i=Math.max(0,Math.min(100,e))/100,a=-Math.PI/2;return n.lineWidth=4,n.beginPath(),n.arc(16,16,13,0,Math.PI*2),n.strokeStyle=`rgba(128,128,128,0.3)`,n.stroke(),n.beginPath(),n.arc(16,16,13,a,a+i*Math.PI*2),n.strokeStyle=r,n.lineCap=`round`,n.stroke(),t.toDataURL(`image/png`)}function U9(e,t){document.querySelectorAll(`link[rel~="icon"]`).forEach(n=>{if(e)t.has(n)||t.set(n,n.href),n.href=e;else{let e=t.get(n);e!==void 0&&(n.href=e)}}),e||t.clear()}function z4e(){let{progressInTitle:e,resolvedMode:t,darkAccent:n,lightAccent:r}=Bd(),i=t===`dark`?n:r,{data:a}=K({queryKey:[`printers`],queryFn:Z.getPrinters,enabled:e}),o=_o({queries:(e?a??[]:[]).map(e=>({queryKey:[`printerStatus`,e.id],queryFn:()=>Z.getPrinterStatus(e.id)}))}),s=(0,f.useRef)(new Map),c=(0,f.useRef)(document.title),l=(0,f.useRef)(!1),u=e?L4e(o.map(e=>e.data)):null,d=u&&u.progress!=null?Math.round(u.progress):null;(0,f.useEffect)(()=>{e&&d!=null?(document.title=`${d}% · ${c.current}`,U9(R4e(d),s.current),l.current=!0):l.current&&=(document.title=c.current,U9(null,s.current),!1)},[e,d,i]),(0,f.useEffect)(()=>{let e=s.current,t=l,n=c.current;return()=>{t.current&&(document.title=n,U9(null,e))}},[])}function B4e({children:e}){let{authEnabled:t,user:n,loading:r}=Ld(),{data:i}=K({queryKey:[`color-catalog-map`],queryFn:async()=>{let e=await Z.getColorNameMap();return{colors:e.colors,byMaterial:e.by_material??{}}},staleTime:1/0,gcTime:1/0,retry:2,enabled:!r&&(!t||n!==null)});return(0,f.useEffect)(()=>{i&&Sf(i.colors,i.byMaterial)},[i]),(0,G.jsx)(G.Fragment,{children:e})}function V4e({selectedPrinterId:e,onPrinterChange:t,deviceOnline:n}){let{t:r}=U(),[i,a]=(0,f.useState)(new Date),{data:o=[]}=K({queryKey:[`printers`],queryFn:()=>Z.getPrinters()}),s=_o({queries:o.map(e=>({queryKey:[`printerStatus`,e.id],queryFn:()=>Z.getPrinterStatus(e.id),refetchInterval:1e4}))}),c=(0,f.useMemo)(()=>o.filter((e,t)=>s[t]?.data?.connected),[o,s]);(0,f.useEffect)(()=>{let n=c.some(t=>t.id===e);(!e||!n)&&c.length>0&&t(c[0].id)},[c,e,t]);let{data:l}=K({queryKey:[`settings`],queryFn:Z.getSettings});return(0,f.useEffect)(()=>{let e=setInterval(()=>a(new Date),1e3);return()=>clearInterval(e)},[]),(0,G.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,G.jsx)(`div`,{className:`flex items-center shrink-0`,children:(0,G.jsx)(`img`,{src:`/img/spoolbuddy_logo_dark_small.png`,alt:`SpoolBuddy`,width:113,height:28,className:`h-7 w-auto`})}),(0,G.jsx)(`div`,{className:`flex-1 flex justify-center`,children:(0,G.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,G.jsx)(`option`,{value:``,children:r(`spoolbuddy.status.noPrinters`,`No printers online`)}):c.map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.name},e.id))})}),(0,G.jsxs)(`div`,{className:`flex items-center gap-3 shrink-0`,children:[(0,G.jsx)(`div`,{className:`flex items-center`,title:n?r(`spoolbuddy.status.backend`,`Backend`):r(`spoolbuddy.status.offline`,`Offline`),children:n?(0,G.jsx)(`div`,{className:`flex items-end gap-0.5 h-4`,children:[1,2,3,4].map(e=>(0,G.jsx)(`div`,{className:`w-1 rounded-sm ${e<=4?`bg-white`:`bg-bambu-dark-tertiary`}`,style:{height:`${e*4}px`}},e))}):(0,G.jsx)(Zu,{className:`w-5 h-5 text-red-400`})}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,G.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,G.jsx)(`span`,{className:`text-sm text-white/50`,children:n?r(`spoolbuddy.status.backend`,`Backend`):r(`spoolbuddy.status.offline`,`Offline`)})]}),(0,G.jsx)(`span`,{className:`text-white/50 text-base font-mono min-w-[50px] text-right`,children:dp(i,l?.time_format||`system`)})]})]})}var H4e=[{to:`/spoolbuddy`,labelKey:`spoolbuddy.nav.dashboard`,fallback:`Dashboard`,icon:(0,G.jsx)(`svg`,{className:`w-6 h-6`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,G.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,G.jsx)(`svg`,{className:`w-6 h-6`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,G.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,G.jsxs)(`svg`,{className:`w-6 h-6`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:2,children:[(0,G.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,G.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,G.jsx)(`svg`,{className:`w-6 h-6`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,G.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,G.jsxs)(`svg`,{className:`w-6 h-6`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:[(0,G.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,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M15 12a3 3 0 11-6 0 3 3 0 016 0z`})]})}];function U4e(){let{t:e}=U();return(0,G.jsx)(`nav`,{className:`h-14 bg-bambu-dark-secondary border-t border-bambu-dark-tertiary flex items-stretch shrink-0`,children:H4e.map(t=>(0,G.jsxs)(wi,{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,G.jsx)(`span`,{className:`text-xs font-medium`,children:e(t.labelKey,t.fallback)})]},t.to))})}function W4e({alert:e}){let{t}=U(),n=e?e.type===`error`?`bg-red-500`:e.type===`warning`?`bg-amber-500`:`bg-bambu-green`:`bg-bambu-green`;return(0,G.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,G.jsx)(`div`,{className:`w-3.5 h-3.5 rounded-full ${n}`}),(0,G.jsx)(`div`,{className:`flex-1 text-sm text-white/50 truncate`,children:e?(0,G.jsx)(`span`,{children:e.message}):(0,G.jsx)(`span`,{className:`text-bambu-green`,children:t(`spoolbuddy.status.systemReady`,`System Ready`)})})]})}function G4e({isOpen:e,onClose:t,deviceId:n,deviceOnline:r}){let{t:i}=U(),[a,o]=(0,f.useState)(null),[s,c]=(0,f.useState)(!1),[l,u]=(0,f.useState)(new Map),{data:d=[]}=K({queryKey:[`printers`],queryFn:()=>Z.getPrinters(),enabled:e}),{data:p=[]}=K({queryKey:[`smart-plugs`],queryFn:()=>Z.getSmartPlugs(),enabled:e}),m=d.map(e=>{let t=p.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,f.useEffect)(()=>{!e||p.length===0||p.filter(e=>e.printer_id!==null&&e.plug_type!==`mqtt`&&e.enabled).forEach(async e=>{try{let t=await Z.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,p]),(0,f.useEffect)(()=>{e||(o(null),c(!1))},[e]);let h=(0,f.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 Z.controlSmartPlug(e.id,`toggle`);let t=await Z.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})}},[]),g=(0,f.useCallback)(async e=>{if(n){c(!0);try{await jd.systemCommand(n,e),setTimeout(()=>t(),500)}catch{c(!1)}}},[n,t]),_=(0,f.useCallback)(()=>{a&&(a.type===`system`?g(a.command):h(a.plug),o(null))},[a,g,h]);if(!e)return null;let v=e=>e===`ON`||e===`on`;return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`fixed inset-0 z-40 bg-black/50`,onPointerDown:t}),(0,G.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,G.jsx)(`div`,{className:`flex justify-center pt-2 pb-1`,children:(0,G.jsx)(`div`,{className:`w-10 h-1 rounded-full bg-zinc-600`})}),(0,G.jsxs)(`div`,{className:`px-4 pb-4 max-h-[80vh] overflow-y-auto`,children:[m.length>0&&(0,G.jsxs)(`div`,{className:`mb-4`,children:[(0,G.jsx)(`h3`,{className:`text-xs font-semibold text-zinc-500 uppercase tracking-wide mb-2`,children:i(`spoolbuddy.quickMenu.printerPower`,`Printer Power`)}),(0,G.jsx)(`div`,{className:`space-y-1`,children:m.map(({plug:e,printer:t,loading:n})=>{let r=l.get(e.id),i=v(r?.state??null);return(0,G.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,G.jsx)(`div`,{className:`w-2 h-2 rounded-full shrink-0 ${i?`bg-green-500`:`bg-zinc-600`}`}),n&&(0,G.jsx)(Y,{className:`w-3 h-3 animate-spin text-zinc-400 shrink-0`}),(0,G.jsx)(`span`,{className:`flex-1 text-sm text-zinc-200 text-left truncate`,children:t.name}),(0,G.jsx)(`span`,{className:`text-xs font-medium ${i?`text-green-400`:`text-zinc-500`}`,children:r?.state??`—`})]},e.id)})})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`text-xs font-semibold text-zinc-500 uppercase tracking-wide mb-2`,children:i(`spoolbuddy.quickMenu.systemControls`,`System`)}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,G.jsx)(W9,{icon:(0,G.jsx)(Hl,{className:`w-4 h-4`}),label:i(`spoolbuddy.quickMenu.restartDaemon`,`Restart Daemon`),onClick:()=>o({type:`system`,command:`restart_daemon`}),disabled:!n||!r||s}),(0,G.jsx)(W9,{icon:(0,G.jsx)(pl,{className:`w-4 h-4`}),label:i(`spoolbuddy.quickMenu.restartBrowser`,`Restart Browser`),onClick:()=>o({type:`system`,command:`restart_browser`}),disabled:!n||!r||s}),(0,G.jsx)(W9,{icon:(0,G.jsx)(Hl,{className:`w-4 h-4`}),label:i(`spoolbuddy.quickMenu.reboot`,`Reboot`),onClick:()=>o({type:`system`,command:`reboot`}),disabled:!n||!r||s,variant:`warning`}),(0,G.jsx)(W9,{icon:(0,G.jsx)(Nl,{className:`w-4 h-4`}),label:i(`spoolbuddy.quickMenu.shutdown`,`Shutdown`),onClick:()=>o({type:`system`,command:`shutdown`}),disabled:!n||!r||s,variant:`danger`})]})]}),(0,G.jsx)(`div`,{className:`flex justify-center mt-3`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-1 text-xs text-zinc-600`,children:[(0,G.jsx)(ss,{className:`w-3 h-3`}),(0,G.jsx)(`span`,{children:i(`spoolbuddy.quickMenu.swipeToClose`,`Swipe down to close`)})]})})]})]}),a&&(0,G.jsx)(`div`,{className:`fixed inset-0 z-[60] flex items-center justify-center bg-black/60`,children:(0,G.jsxs)(`div`,{className:`bg-zinc-800 rounded-2xl p-5 mx-4 max-w-sm w-full border border-zinc-700`,children:[(0,G.jsx)(`h3`,{className:`text-lg font-semibold text-zinc-100 mb-2`,children:i(`spoolbuddy.quickMenu.confirmTitle`,`Confirm`)}),(0,G.jsx)(`p`,{className:`text-sm text-zinc-400 mb-5`,children:a.type===`plug`?v(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,G.jsxs)(`div`,{className:`flex gap-3`,children:[(0,G.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,G.jsx)(`button`,{onClick:_,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`?v(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,G.jsx)(Y,{className:`w-4 h-4 animate-spin mx-auto`}):a.type===`plug`?v(a.currentState)?i(`spoolbuddy.quickMenu.turnOff`,`Turn Off`):i(`spoolbuddy.quickMenu.turnOn`,`Turn On`):i(`spoolbuddy.quickMenu.confirm`,`Confirm`)})]})]})})]})}function W9({icon:e,label:t,onClick:n,disabled:r,variant:i=`default`}){return(0,G.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,G.jsx)(`span`,{className:`text-sm font-medium`,children:t})]})}var K4e={weight:null,weightStable:!1,rawAdc:null,matchedSpool:null,unknownTagUid:null,unknownTrayUuid:null,deviceOnline:!1,deviceId:null};function q4e(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 J4e(){let[e,t]=(0,f.useReducer)(q4e,K4e),n=(0,f.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,f.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,color_name_is_synthesized:r.color_name_is_synthesized??!1,rgba:r.rgba??null,extra_colors:r.extra_colors??null,effect_type:r.effect_type??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,f.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,f.useCallback)(e=>{let n=e.detail;t({type:`TAG_REMOVED`,deviceId:n.device_id??n.data?.device_id??``})},[]),o=(0,f.useCallback)(e=>{let n=e.detail;t({type:`DEVICE_ONLINE`,deviceId:n.device_id??n.data?.device_id??``})},[]),s=(0,f.useCallback)(e=>{let n=e.detail;t({type:`DEVICE_OFFLINE`,deviceId:n.device_id??n.data?.device_id??``})},[]);(0,f.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 Y4e=e(r(((e,t)=>{(function(n,r){typeof e==`object`&&typeof t==`object`?t.exports=r(a()):typeof define==`function`&&define.amd?define([`react`],r):typeof e==`object`?e.ReactSimpleKeyboard=r(a()):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/assets/pdf-4oiL9bye.js b/static/assets/pdf-DG3KNKaP.js similarity index 99% rename from static/assets/pdf-4oiL9bye.js rename to static/assets/pdf-DG3KNKaP.js index ba8291e64..a85964405 100644 --- a/static/assets/pdf-4oiL9bye.js +++ b/static/assets/pdf-DG3KNKaP.js @@ -1,4 +1,4 @@ -import{_ as e}from"./index-Bc3Y2a4o.js";var t={9306(e,t,n){var r=n(4901),i=n(6823),a=TypeError;e.exports=function(e){if(r(e))return e;throw new a(i(e)+` is not a function`)}},3506(e,t,n){var r=n(3925),i=String,a=TypeError;e.exports=function(e){if(r(e))return e;throw new a(`Can't set `+i(e)+` as a prototype`)}},7080(e,t,n){var r=n(4402).has;e.exports=function(e){return r(e),e}},3463(e){var t=TypeError;e.exports=function(e){if(typeof e==`string`)return e;throw new t(`Argument is not a string`)}},4328(e,t,n){var r=n(4995),i=new r.WeakMap,a=r.set,o=r.remove;e.exports=function(e){return a(i,e,1),o(i,e),e}},6557(e,t,n){var r=n(4995).has;e.exports=function(e){return r(e),e}},6469(e,t,n){var r=n(8227),i=n(2360),a=n(4913).f,o=r(`unscopables`),s=Array.prototype;s[o]===void 0&&a(s,o,{configurable:!0,value:i(null)}),e.exports=function(e){s[o][e]=!0}},679(e,t,n){var r=n(1625),i=TypeError;e.exports=function(e,t){if(r(t,e))return e;throw new i(`Incorrect invocation`)}},3972(e,t,n){var r=n(34),i=String,a=TypeError;e.exports=function(e){if(e===void 0||r(e))return e;throw new a(i(e)+` is not an object or undefined`)}},8551(e,t,n){var r=n(34),i=String,a=TypeError;e.exports=function(e){if(r(e))return e;throw new a(i(e)+` is not an object`)}},4154(e,t,n){var r=n(6955),i=TypeError;e.exports=function(e){if(r(e)===`Uint8Array`)return e;throw new i(`Argument is not an Uint8Array`)}},7811(e){e.exports=typeof ArrayBuffer<`u`&&typeof DataView<`u`},7394(e,t,n){var r=n(4576),i=n(6706),a=n(2195),o=r.ArrayBuffer,s=r.TypeError;e.exports=o&&i(o.prototype,`byteLength`,`get`)||function(e){if(a(e)!==`ArrayBuffer`)throw new s(`ArrayBuffer expected`);return e.byteLength}},3238(e,t,n){var r=n(4576),i=n(7811),a=n(7394),o=r.DataView;e.exports=function(e){if(!i||a(e)!==0)return!1;try{return new o(e),!1}catch{return!0}}},5169(e,t,n){var r=n(3238),i=TypeError;e.exports=function(e){if(r(e))throw new i(`ArrayBuffer is detached`);return e}},4644(e,t,n){var r=n(7811),i=n(3724),a=n(4576),o=n(4901),s=n(34),c=n(9297),l=n(6955),u=n(6823),d=n(6699),f=n(6840),p=n(2106),m=n(1625),h=n(2787),g=n(2967),_=n(8227),v=n(3392),y=n(1181),b=y.enforce,x=y.get,S=a.Int8Array,C=S&&S.prototype,w=a.Uint8ClampedArray,T=w&&w.prototype,E=S&&h(S),D=C&&h(C),O=Object.prototype,k=a.TypeError,A=_(`toStringTag`),j=v(`TYPED_ARRAY_TAG`),M=`TypedArrayConstructor`,N=r&&!!g&&l(a.opera)!==`Opera`,P=!1,F,I,L,R={Int8Array:1,Uint8Array:1,Uint8ClampedArray:1,Int16Array:2,Uint16Array:2,Int32Array:4,Uint32Array:4,Float32Array:4,Float64Array:8},ee={BigInt64Array:8,BigUint64Array:8},te=function(e){if(!s(e))return!1;var t=l(e);return t===`DataView`||c(R,t)||c(ee,t)},ne=function(e){var t=h(e);if(s(t)){var n=x(t);return n&&c(n,M)?n[M]:ne(t)}},re=function(e){if(!s(e))return!1;var t=l(e);return c(R,t)||c(ee,t)},ie=function(e){if(re(e))return e;throw new k(`Target is not a typed array`)},ae=function(e){if(o(e)&&(!g||m(E,e)))return e;throw new k(u(e)+` is not a typed array constructor`)},z=function(e,t,n,r){if(i){if(n)for(var o in R){var s=a[o];if(s&&c(s.prototype,e))try{delete s.prototype[e]}catch{try{s.prototype[e]=t}catch{}}}(!D[e]||n)&&f(D,e,n?t:N&&C[e]||t,r)}},B=function(e,t,n){var r,o;if(i){if(g){if(n){for(r in R)if(o=a[r],o&&c(o,e))try{delete o[e]}catch{}}if(!E[e]||n)try{return f(E,e,n?t:N&&E[e]||t)}catch{}else return}for(r in R)o=a[r],o&&(!o[e]||n)&&f(o,e,t)}};for(F in R)I=a[F],L=I&&I.prototype,L?b(L)[M]=I:N=!1;for(F in ee)I=a[F],L=I&&I.prototype,L&&(b(L)[M]=I);if((!N||!o(E)||E===Function.prototype)&&(E=function(){throw new k(`Incorrect invocation`)},N))for(F in R)a[F]&&g(a[F],E);if((!N||!D||D===O)&&(D=E.prototype,N))for(F in R)a[F]&&g(a[F].prototype,D);if(N&&h(T)!==D&&g(T,D),i&&!c(D,A))for(F in P=!0,p(D,A,{configurable:!0,get:function(){return s(this)?this[j]:void 0}}),R)a[F]&&d(a[F].prototype,j,F);e.exports={NATIVE_ARRAY_BUFFER_VIEWS:N,TYPED_ARRAY_TAG:P&&j,aTypedArray:ie,aTypedArrayConstructor:ae,exportTypedArrayMethod:z,exportTypedArrayStaticMethod:B,getTypedArrayConstructor:ne,isView:te,isTypedArray:re,TypedArray:E,TypedArrayPrototype:D}},5370(e,t,n){var r=n(6198);e.exports=function(e,t,n){for(var i=0,a=arguments.length>2?n:r(t),o=new e(a);a>i;)o[i]=t[i++];return o}},9617(e,t,n){var r=n(5397),i=n(5610),a=n(6198),o=function(e){return function(t,n,o){var s=r(t),c=a(s);if(c===0)return!e&&-1;var l=i(o,c),u;if(e&&n!==n){for(;c>l;)if(u=s[l++],u!==u)return!0}else for(;c>l;l++)if((e||l in s)&&s[l]===n)return e||l||0;return!e&&-1}};e.exports={includes:o(!0),indexOf:o(!1)}},4527(e,t,n){var r=n(3724),i=n(4376),a=TypeError,o=Object.getOwnPropertyDescriptor;e.exports=r&&!function(){if(this!==void 0)return!0;try{Object.defineProperty([],"length",{writable:!1}).length=1}catch(e){return e instanceof TypeError}}()?function(e,t){if(i(e)&&!o(e,`length`).writable)throw new a(`Cannot set read only .length`);return e.length=t}:function(e,t){return e.length=t}},7680(e,t,n){e.exports=n(9504)([].slice)},2804(e){var t=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789`,n=t+`+/`,r=t+`-_`,i=function(e){for(var t={},n=0;n<64;n++)t[e.charAt(n)]=n;return t};e.exports={i2c:n,c2i:i(n),i2cUrl:r,c2iUrl:i(r)}},6319(e,t,n){var r=n(8551),i=n(9539);e.exports=function(e,t,n,a){try{return a?t(r(n)[0],n[1]):t(n)}catch(t){i(e,`throw`,t)}}},2195(e,t,n){var r=n(9504),i=r({}.toString),a=r(``.slice);e.exports=function(e){return a(i(e),8,-1)}},6955(e,t,n){var r=n(2140),i=n(4901),a=n(2195),o=n(8227)(`toStringTag`),s=Object,c=a(function(){return arguments}())===`Arguments`,l=function(e,t){try{return e[t]}catch{}};e.exports=r?a:function(e){var t,n,r;return e===void 0?`Undefined`:e===null?`Null`:typeof(n=l(t=s(e),o))==`string`?n:c?a(t):(r=a(t))===`Object`&&i(t.callee)?`Arguments`:r}},7740(e,t,n){var r=n(9297),i=n(5031),a=n(7347),o=n(4913);e.exports=function(e,t,n){for(var s=i(t),c=o.f,l=a.f,u=0;un)throw new t(`Maximum allowed index exceeded`);return e}},5002(e){e.exports={IndexSizeError:{s:`INDEX_SIZE_ERR`,c:1,m:1},DOMStringSizeError:{s:`DOMSTRING_SIZE_ERR`,c:2,m:0},HierarchyRequestError:{s:`HIERARCHY_REQUEST_ERR`,c:3,m:1},WrongDocumentError:{s:`WRONG_DOCUMENT_ERR`,c:4,m:1},InvalidCharacterError:{s:`INVALID_CHARACTER_ERR`,c:5,m:1},NoDataAllowedError:{s:`NO_DATA_ALLOWED_ERR`,c:6,m:0},NoModificationAllowedError:{s:`NO_MODIFICATION_ALLOWED_ERR`,c:7,m:1},NotFoundError:{s:`NOT_FOUND_ERR`,c:8,m:1},NotSupportedError:{s:`NOT_SUPPORTED_ERR`,c:9,m:1},InUseAttributeError:{s:`INUSE_ATTRIBUTE_ERR`,c:10,m:1},InvalidStateError:{s:`INVALID_STATE_ERR`,c:11,m:1},SyntaxError:{s:`SYNTAX_ERR`,c:12,m:1},InvalidModificationError:{s:`INVALID_MODIFICATION_ERR`,c:13,m:1},NamespaceError:{s:`NAMESPACE_ERR`,c:14,m:1},InvalidAccessError:{s:`INVALID_ACCESS_ERR`,c:15,m:1},ValidationError:{s:`VALIDATION_ERR`,c:16,m:0},TypeMismatchError:{s:`TYPE_MISMATCH_ERR`,c:17,m:1},SecurityError:{s:`SECURITY_ERR`,c:18,m:1},NetworkError:{s:`NETWORK_ERR`,c:19,m:1},AbortError:{s:`ABORT_ERR`,c:20,m:1},URLMismatchError:{s:`URL_MISMATCH_ERR`,c:21,m:1},QuotaExceededError:{s:`QUOTA_EXCEEDED_ERR`,c:22,m:1},TimeoutError:{s:`TIMEOUT_ERR`,c:23,m:1},InvalidNodeTypeError:{s:`INVALID_NODE_TYPE_ERR`,c:24,m:1},DataCloneError:{s:`DATA_CLONE_ERR`,c:25,m:1}}},8727(e){e.exports=[`constructor`,`hasOwnProperty`,`isPrototypeOf`,`propertyIsEnumerable`,`toLocaleString`,`toString`,`valueOf`]},2839(e,t,n){var r=n(4576).navigator,i=r&&r.userAgent;e.exports=i?String(i):``},9519(e,t,n){var r=n(4576),i=n(2839),a=r.process,o=r.Deno,s=a&&a.versions||o&&o.version,c=s&&s.v8,l,u;c&&(l=c.split(`.`),u=l[0]>0&&l[0]<4?1:+(l[0]+l[1])),!u&&i&&(l=i.match(/Edge\/(\d+)/),(!l||l[1]>=74)&&(l=i.match(/Chrome\/(\d+)/),l&&(u=+l[1]))),e.exports=u},6193(e,t,n){var r=n(9504),i=Error,a=r(``.replace),o=(function(e){return String(new i(e).stack)})(`zxcasd`),s=/\n\s*at [^:]*:[^\n]*/,c=s.test(o);e.exports=function(e,t){if(c&&typeof e==`string`&&!i.prepareStackTrace)for(;t--;)e=a(e,s,``);return e}},6518(e,t,n){var r=n(4576),i=n(7347).f,a=n(6699),o=n(6840),s=n(9433),c=n(7740),l=n(2796);e.exports=function(e,t){var n=e.target,u=e.global,d=e.stat,f,p=u?r:d?r[n]||s(n,{}):r[n]&&r[n].prototype,m,h,g,_;if(p)for(m in t){if(g=t[m],e.dontCallGetSet?(_=i(p,m),h=_&&_.value):h=p[m],f=l(u?m:n+(d?`.`:`#`)+m,e.forced),!f&&h!==void 0){if(typeof g==typeof h)continue;c(g,h)}(e.sham||h&&h.sham)&&a(g,`sham`,!0),o(p,m,g,e)}}},9039(e){e.exports=function(e){try{return!!e()}catch{return!0}}},8745(e,t,n){var r=n(616),i=Function.prototype,a=i.apply,o=i.call;e.exports=typeof Reflect==`object`&&Reflect.apply||(r?o.bind(a):function(){return o.apply(a,arguments)})},6080(e,t,n){var r=n(7476),i=n(9306),a=n(616),o=r(r.bind);e.exports=function(e,t){return i(e),t===void 0?e:a?o(e,t):function(){return e.apply(t,arguments)}}},616(e,t,n){e.exports=!n(9039)(function(){var e=function(){}.bind();return typeof e!=`function`||e.hasOwnProperty(`prototype`)})},9565(e,t,n){var r=n(616),i=Function.prototype.call;e.exports=r?i.bind(i):function(){return i.apply(i,arguments)}},350(e,t,n){var r=n(3724),i=n(9297),a=Function.prototype,o=r&&Object.getOwnPropertyDescriptor,s=i(a,`name`);e.exports={EXISTS:s,PROPER:s&&function(){}.name===`something`,CONFIGURABLE:s&&(!r||r&&o(a,`name`).configurable)}},6706(e,t,n){var r=n(9504),i=n(9306);e.exports=function(e,t,n){try{return r(i(Object.getOwnPropertyDescriptor(e,t)[n]))}catch{}}},7476(e,t,n){var r=n(2195),i=n(9504);e.exports=function(e){if(r(e)===`Function`)return i(e)}},9504(e,t,n){var r=n(616),i=Function.prototype,a=i.call,o=r&&i.bind.bind(a,a);e.exports=r?o:function(e){return function(){return a.apply(e,arguments)}}},944(e){var t=TypeError;e.exports=function(e){var n=e&&e.alphabet;if(n===void 0||n===`base64`||n===`base64url`)return n||`base64`;throw new t("Incorrect `alphabet` option")}},7751(e,t,n){var r=n(4576),i=n(4901),a=function(e){return i(e)?e:void 0};e.exports=function(e,t){return arguments.length<2?a(r[e]):r[e]&&r[e][t]}},1767(e){e.exports=function(e){return{iterator:e,next:e.next,done:!1}}},8646(e,t,n){var r=n(9565),i=n(8551),a=n(1767),o=n(851);e.exports=function(e,t){(!t||typeof e!=`string`)&&i(e);var n=o(e);return a(i(n===void 0?e:r(n,e)))}},851(e,t,n){var r=n(6955),i=n(5966),a=n(4117),o=n(6269),s=n(8227)(`iterator`);e.exports=function(e){if(!a(e))return i(e,s)||i(e,`@@iterator`)||o[r(e)]}},81(e,t,n){var r=n(9565),i=n(9306),a=n(8551),o=n(6823),s=n(851),c=TypeError;e.exports=function(e,t){var n=arguments.length<2?s(e):t;if(i(n))return a(r(n,e));throw new c(o(e)+` is not iterable`)}},5966(e,t,n){var r=n(9306),i=n(4117);e.exports=function(e,t){var n=e[t];return i(n)?void 0:r(n)}},3789(e,t,n){var r=n(9306),i=n(8551),a=n(9565),o=n(1291),s=n(1767),c=`Invalid size`,l=RangeError,u=TypeError,d=Math.max,f=function(e,t){this.set=e,this.size=d(t,0),this.has=r(e.has),this.keys=r(e.keys)};f.prototype={getIterator:function(){return s(i(a(this.keys,this.set)))},includes:function(e){return a(this.has,this.set,e)}},e.exports=function(e){i(e);var t=+e.size;if(t!==t)throw new u(c);var n=o(t);if(n<0)throw new l(c);return new f(e,n)}},4576(e){var t=function(e){return e&&e.Math===Math&&e};e.exports=t(typeof globalThis==`object`&&globalThis)||t(typeof window==`object`&&window)||t(typeof self==`object`&&self)||t(typeof global==`object`&&global)||t(typeof this==`object`&&this)||(function(){return this})()||Function(`return this`)()},9297(e,t,n){var r=n(9504),i=n(8981),a=r({}.hasOwnProperty);e.exports=Object.hasOwn||function(e,t){return a(i(e),t)}},421(e){e.exports={}},397(e,t,n){e.exports=n(7751)(`document`,`documentElement`)},5917(e,t,n){var r=n(3724),i=n(9039),a=n(4055);e.exports=!r&&!i(function(){return Object.defineProperty(a(`div`),"a",{get:function(){return 7}}).a!==7})},7055(e,t,n){var r=n(9504),i=n(9039),a=n(2195),o=Object,s=r(``.split);e.exports=i(function(){return!o(`z`).propertyIsEnumerable(0)})?function(e){return a(e)===`String`?s(e,``):o(e)}:o},3167(e,t,n){var r=n(4901),i=n(34),a=n(2967);e.exports=function(e,t,n){var o,s;return a&&r(o=t.constructor)&&o!==n&&i(s=o.prototype)&&s!==n.prototype&&a(e,s),e}},3706(e,t,n){var r=n(9504),i=n(4901),a=n(7629),o=r(Function.toString);i(a.inspectSource)||(a.inspectSource=function(e){return o(e)}),e.exports=a.inspectSource},1181(e,t,n){var r=n(8622),i=n(4576),a=n(34),o=n(6699),s=n(9297),c=n(7629),l=n(6119),u=n(421),d=`Object already initialized`,f=i.TypeError,p=i.WeakMap,m,h,g,_=function(e){return g(e)?h(e):m(e,{})},v=function(e){return function(t){var n;if(!a(t)||(n=h(t)).type!==e)throw new f(`Incompatible receiver, `+e+` required`);return n}};if(r||c.state){var y=c.state||=new p;y.get=y.get,y.has=y.has,y.set=y.set,m=function(e,t){if(y.has(e))throw new f(d);return t.facade=e,y.set(e,t),t},h=function(e){return y.get(e)||{}},g=function(e){return y.has(e)}}else{var b=l(`state`);u[b]=!0,m=function(e,t){if(s(e,b))throw new f(d);return t.facade=e,o(e,b,t),t},h=function(e){return s(e,b)?e[b]:{}},g=function(e){return s(e,b)}}e.exports={set:m,get:h,has:g,enforce:_,getterFor:v}},4209(e,t,n){var r=n(8227),i=n(6269),a=r(`iterator`),o=Array.prototype;e.exports=function(e){return e!==void 0&&(i.Array===e||o[a]===e)}},4376(e,t,n){var r=n(2195);e.exports=Array.isArray||function(e){return r(e)===`Array`}},1108(e,t,n){var r=n(6955);e.exports=function(e){var t=r(e);return t===`BigInt64Array`||t===`BigUint64Array`}},4901(e){var t=typeof document==`object`&&document.all;e.exports=t===void 0&&t!==void 0?function(e){return typeof e==`function`||e===t}:function(e){return typeof e==`function`}},2796(e,t,n){var r=n(9039),i=n(4901),a=/#|\.prototype\./,o=function(e,t){var n=c[s(e)];return n===u?!0:n===l?!1:i(t)?r(t):!!t},s=o.normalize=function(e){return String(e).replace(a,`.`).toLowerCase()},c=o.data={},l=o.NATIVE=`N`,u=o.POLYFILL=`P`;e.exports=o},4117(e){e.exports=function(e){return e==null}},34(e,t,n){var r=n(4901);e.exports=function(e){return typeof e==`object`?e!==null:r(e)}},3925(e,t,n){var r=n(34);e.exports=function(e){return r(e)||e===null}},6395(e){e.exports=!1},5810(e,t,n){var r=n(34),i=n(1181).get;e.exports=function(e){if(!r(e))return!1;var t=i(e);return!!t&&t.type===`RawJSON`}},757(e,t,n){var r=n(7751),i=n(4901),a=n(1625),o=n(7040),s=Object;e.exports=o?function(e){return typeof e==`symbol`}:function(e){var t=r(`Symbol`);return i(t)&&a(t.prototype,s(e))}},507(e,t,n){var r=n(9565);e.exports=function(e,t,n){for(var i=n?e:e.iterator,a=e.next,o,s;!(o=r(a,i)).done;)if(s=t(o.value),s!==void 0)return s}},2652(e,t,n){var r=n(6080),i=n(9565),a=n(8551),o=n(6823),s=n(4209),c=n(6198),l=n(1625),u=n(81),d=n(851),f=n(9539),p=TypeError,m=function(e,t){this.stopped=e,this.result=t},h=m.prototype;e.exports=function(e,t,n){var g=n&&n.that,_=!!(n&&n.AS_ENTRIES),v=!!(n&&n.IS_RECORD),y=!!(n&&n.IS_ITERATOR),b=!!(n&&n.INTERRUPTED),x=r(t,g),S,C,w,T,E,D,O,k=function(e){var t=S;return S=void 0,t&&f(t,`normal`),new m(!0,e)},A=function(e){return _?(a(e),b?x(e[0],e[1],k):x(e[0],e[1])):b?x(e,k):x(e)};if(v)S=e.iterator;else if(y)S=e;else{if(C=d(e),!C)throw new p(o(e)+` is not iterable`);if(s(C)){for(w=0,T=c(e);T>w;w++)if(E=A(e[w]),E&&l(h,E))return E;return new m(!1)}S=u(e,C)}for(D=v?e.next:S.next;!(O=i(D,S)).done;){var j=O.value;try{E=A(j)}catch(e){if(S)f(S,`throw`,e);else throw e}if(typeof E==`object`&&E&&l(h,E))return E}return new m(!1)}},1385(e,t,n){var r=n(9539);e.exports=function(e,t,n){for(var i=e.length-1;i>=0;i--)if(e[i]!==void 0)try{n=r(e[i].iterator,t,n)}catch(e){t=`throw`,n=e}if(t===`throw`)throw n;return n}},9539(e,t,n){var r=n(9565),i=n(8551),a=n(5966);e.exports=function(e,t,n){var o,s;i(e);try{if(o=a(e,`return`),!o){if(t===`throw`)throw n;return n}o=r(o,e)}catch(e){s=!0,o=e}if(t===`throw`)throw n;if(s)throw o;return i(o),n}},9462(e,t,n){var r=n(9565),i=n(2360),a=n(6699),o=n(6279),s=n(8227),c=n(1181),l=n(5966),u=n(7657).IteratorPrototype,d=n(2529),f=n(9539),p=n(1385),m=s(`toStringTag`),h=`IteratorHelper`,g=`WrapForValidIterator`,_=`normal`,v=`throw`,y=c.set,b=function(e){var t=c.getterFor(e?g:h);return o(i(u),{next:function(){var n=t(this);if(e)return n.nextHandler();if(n.done)return d(void 0,!0);try{var r=n.nextHandler();return n.returnHandlerResult?r:d(r,n.done)}catch(e){throw n.done=!0,e}},return:function(){var n=t(this),i=n.iterator,a=n.done;if(n.done=!0,e){var o=l(i,`return`);return o?r(o,i):d(void 0,!0)}if(a)return d(void 0,!0);if(n.inner)try{f(n.inner.iterator,_)}catch(e){return f(i,v,e)}if(n.openIters)try{p(n.openIters,_)}catch(e){if(i)return f(i,v,e);throw e}return i&&f(i,_),d(void 0,!0)}})},x=b(!0),S=b(!1);a(S,m,`Iterator Helper`),e.exports=function(e,t,n){var r=function(r,i){i?(i.iterator=r.iterator,i.next=r.next):i=r,i.type=t?g:h,i.returnHandlerResult=!!n,i.nextHandler=e,i.counter=0,i.done=!1,y(this,i)};return r.prototype=t?x:S,r}},684(e){e.exports=function(e,t){var n=typeof Iterator==`function`&&Iterator.prototype[e];if(n)try{n.call({next:null},t).next()}catch{return!0}}},4549(e,t,n){var r=n(4576);e.exports=function(e,t){var n=r.Iterator,i=n&&n.prototype,a=i&&i[e],o=!1;if(a)try{a.call({next:function(){return{done:!0}},return:function(){o=!0}},-1)}catch(e){e instanceof t||(o=!1)}if(!o)return a}},7657(e,t,n){var r=n(9039),i=n(4901),a=n(34),o=n(2360),s=n(2787),c=n(6840),l=n(8227),u=n(6395),d=l(`iterator`),f=!1,p,m,h;[].keys&&(h=[].keys(),`next`in h?(m=s(s(h)),m!==Object.prototype&&(p=m)):f=!0),!a(p)||r(function(){var e={};return p[d].call(e)!==e})?p={}:u&&(p=o(p)),i(p[d])||c(p,d,function(){return this}),e.exports={IteratorPrototype:p,BUGGY_SAFARI_ITERATORS:f}},6269(e){e.exports={}},6198(e,t,n){var r=n(8014);e.exports=function(e){return r(e.length)}},283(e,t,n){var r=n(9504),i=n(9039),a=n(4901),o=n(9297),s=n(3724),c=n(350).CONFIGURABLE,l=n(3706),u=n(1181),d=u.enforce,f=u.get,p=String,m=Object.defineProperty,h=r(``.slice),g=r(``.replace),_=r([].join),v=s&&!i(function(){return m(function(){},`length`,{value:8}).length!==8}),y=String(String).split(`String`),b=e.exports=function(e,t,n){h(p(t),0,7)===`Symbol(`&&(t=`[`+g(p(t),/^Symbol\(([^)]*)\).*$/,`$1`)+`]`),n&&n.getter&&(t=`get `+t),n&&n.setter&&(t=`set `+t),(!o(e,`name`)||c&&e.name!==t)&&(s?m(e,`name`,{value:t,configurable:!0}):e.name=t),v&&n&&o(n,`arity`)&&e.length!==n.arity&&m(e,`length`,{value:n.arity});try{n&&o(n,`constructor`)&&n.constructor?s&&m(e,`prototype`,{writable:!1}):e.prototype&&=void 0}catch{}var r=d(e);return o(r,`source`)||(r.source=_(y,typeof t==`string`?t:``)),e};Function.prototype.toString=b(function(){return a(this)&&f(this).source||l(this)},`toString`)},2248(e,t,n){var r=n(9504),i=Map.prototype;e.exports={Map,set:r(i.set),get:r(i.get),has:r(i.has),remove:r(i.delete),proto:i}},741(e){var t=Math.ceil,n=Math.floor;e.exports=Math.trunc||function(e){var r=+e;return(r>0?n:t)(r)}},7819(e,t,n){e.exports=!n(9039)(function(){var e=`9007199254740993`,t=JSON.rawJSON(e);return!JSON.isRawJSON(t)||JSON.stringify(t)!==e})},6043(e,t,n){var r=n(9306),i=TypeError,a=function(e){var t,n;this.promise=new e(function(e,r){if(t!==void 0||n!==void 0)throw new i(`Bad Promise constructor`);t=e,n=r}),this.resolve=r(t),this.reject=r(n)};e.exports.f=function(e){return new a(e)}},2603(e,t,n){var r=n(655);e.exports=function(e,t){return e===void 0?arguments.length<2?``:t:r(e)}},4149(e){var t=RangeError;e.exports=function(e){if(e===e)return e;throw new t(`NaN is not allowed`)}},2360(e,t,n){var r=n(8551),i=n(6801),a=n(8727),o=n(421),s=n(397),c=n(4055),l=n(6119),u=`>`,d=`<`,f=`prototype`,p=`script`,m=l(`IE_PROTO`),h=function(){},g=function(e){return d+p+u+e+d+`/`+p+u},_=function(e){e.write(g(``)),e.close();var t=e.parentWindow.Object;return e=null,t},v=function(){var e=c(`iframe`),t=`java`+p+`:`,n;return e.style.display=`none`,s.appendChild(e),e.src=String(t),n=e.contentWindow.document,n.open(),n.write(g(`document.F=Object`)),n.close(),n.F},y,b=function(){try{y=new ActiveXObject(`htmlfile`)}catch{}b=typeof document<`u`?document.domain&&y?_(y):v():_(y);for(var e=a.length;e--;)delete b[f][a[e]];return b()};o[m]=!0,e.exports=Object.create||function(e,t){var n;return e===null?n=b():(h[f]=r(e),n=new h,h[f]=null,n[m]=e),t===void 0?n:i.f(n,t)}},6801(e,t,n){var r=n(3724),i=n(8686),a=n(4913),o=n(8551),s=n(5397),c=n(1072);t.f=r&&!i?Object.defineProperties:function(e,t){o(e);for(var n=s(t),r=c(t),i=r.length,l=0,u;i>l;)a.f(e,u=r[l++],n[u]);return e}},4913(e,t,n){var r=n(3724),i=n(5917),a=n(8686),o=n(8551),s=n(6969),c=TypeError,l=Object.defineProperty,u=Object.getOwnPropertyDescriptor,d=`enumerable`,f=`configurable`,p=`writable`;t.f=r?a?function(e,t,n){if(o(e),t=s(t),o(n),typeof e==`function`&&t===`prototype`&&`value`in n&&p in n&&!n[p]){var r=u(e,t);r&&r[p]&&(e[t]=n.value,n={configurable:f in n?n[f]:r[f],enumerable:d in n?n[d]:r[d],writable:!1})}return l(e,t,n)}:l:function(e,t,n){if(o(e),t=s(t),o(n),i)try{return l(e,t,n)}catch{}if(`get`in n||`set`in n)throw new c(`Accessors not supported`);return`value`in n&&(e[t]=n.value),e}},7347(e,t,n){var r=n(3724),i=n(9565),a=n(8773),o=n(6980),s=n(5397),c=n(6969),l=n(9297),u=n(5917),d=Object.getOwnPropertyDescriptor;t.f=r?d:function(e,t){if(e=s(e),t=c(t),u)try{return d(e,t)}catch{}if(l(e,t))return o(!i(a.f,e,t),e[t])}},8480(e,t,n){var r=n(1828),i=n(8727).concat(`length`,`prototype`);t.f=Object.getOwnPropertyNames||function(e){return r(e,i)}},3717(e,t){t.f=Object.getOwnPropertySymbols},2787(e,t,n){var r=n(9297),i=n(4901),a=n(8981),o=n(6119),s=n(2211),c=o(`IE_PROTO`),l=Object,u=l.prototype;e.exports=s?l.getPrototypeOf:function(e){var t=a(e);if(r(t,c))return t[c];var n=t.constructor;return i(n)&&t instanceof n?n.prototype:t instanceof l?u:null}},1625(e,t,n){e.exports=n(9504)({}.isPrototypeOf)},1828(e,t,n){var r=n(9504),i=n(9297),a=n(5397),o=n(9617).indexOf,s=n(421),c=r([].push);e.exports=function(e,t){var n=a(e),r=0,l=[],u;for(u in n)!i(s,u)&&i(n,u)&&c(l,u);for(;t.length>r;)i(n,u=t[r++])&&(~o(l,u)||c(l,u));return l}},1072(e,t,n){var r=n(1828),i=n(8727);e.exports=Object.keys||function(e){return r(e,i)}},8773(e,t){var n={}.propertyIsEnumerable,r=Object.getOwnPropertyDescriptor;t.f=r&&!n.call({1:2},1)?function(e){var t=r(this,e);return!!t&&t.enumerable}:n},2967(e,t,n){var r=n(6706),i=n(34),a=n(7750),o=n(3506);e.exports=Object.setPrototypeOf||(`__proto__`in{}?function(){var e=!1,t={},n;try{n=r(Object.prototype,`__proto__`,`set`),n(t,[]),e=t instanceof Array}catch{}return function(t,r){return a(t),o(r),i(t)&&(e?n(t,r):t.__proto__=r),t}}():void 0)},4270(e,t,n){var r=n(9565),i=n(4901),a=n(34),o=TypeError;e.exports=function(e,t){var n,s;if(t===`string`&&i(n=e.toString)&&!a(s=r(n,e))||i(n=e.valueOf)&&!a(s=r(n,e))||t!==`string`&&i(n=e.toString)&&!a(s=r(n,e)))return s;throw new o(`Can't convert object to primitive value`)}},5031(e,t,n){var r=n(7751),i=n(9504),a=n(8480),o=n(3717),s=n(8551),c=i([].concat);e.exports=r(`Reflect`,`ownKeys`)||function(e){var t=a.f(s(e)),n=o.f;return n?c(t,n(e)):t}},8235(e,t,n){var r=n(9504),i=n(9297),a=SyntaxError,o=parseInt,s=String.fromCharCode,c=r(``.charAt),l=r(``.slice),u=r(/./.exec),d={'\\"':`"`,"\\\\":`\\`,"\\/":`/`,"\\b":`\b`,"\\f":`\f`,"\\n":` +import{_ as e}from"./index-7qfiHY5t.js";var t={9306(e,t,n){var r=n(4901),i=n(6823),a=TypeError;e.exports=function(e){if(r(e))return e;throw new a(i(e)+` is not a function`)}},3506(e,t,n){var r=n(3925),i=String,a=TypeError;e.exports=function(e){if(r(e))return e;throw new a(`Can't set `+i(e)+` as a prototype`)}},7080(e,t,n){var r=n(4402).has;e.exports=function(e){return r(e),e}},3463(e){var t=TypeError;e.exports=function(e){if(typeof e==`string`)return e;throw new t(`Argument is not a string`)}},4328(e,t,n){var r=n(4995),i=new r.WeakMap,a=r.set,o=r.remove;e.exports=function(e){return a(i,e,1),o(i,e),e}},6557(e,t,n){var r=n(4995).has;e.exports=function(e){return r(e),e}},6469(e,t,n){var r=n(8227),i=n(2360),a=n(4913).f,o=r(`unscopables`),s=Array.prototype;s[o]===void 0&&a(s,o,{configurable:!0,value:i(null)}),e.exports=function(e){s[o][e]=!0}},679(e,t,n){var r=n(1625),i=TypeError;e.exports=function(e,t){if(r(t,e))return e;throw new i(`Incorrect invocation`)}},3972(e,t,n){var r=n(34),i=String,a=TypeError;e.exports=function(e){if(e===void 0||r(e))return e;throw new a(i(e)+` is not an object or undefined`)}},8551(e,t,n){var r=n(34),i=String,a=TypeError;e.exports=function(e){if(r(e))return e;throw new a(i(e)+` is not an object`)}},4154(e,t,n){var r=n(6955),i=TypeError;e.exports=function(e){if(r(e)===`Uint8Array`)return e;throw new i(`Argument is not an Uint8Array`)}},7811(e){e.exports=typeof ArrayBuffer<`u`&&typeof DataView<`u`},7394(e,t,n){var r=n(4576),i=n(6706),a=n(2195),o=r.ArrayBuffer,s=r.TypeError;e.exports=o&&i(o.prototype,`byteLength`,`get`)||function(e){if(a(e)!==`ArrayBuffer`)throw new s(`ArrayBuffer expected`);return e.byteLength}},3238(e,t,n){var r=n(4576),i=n(7811),a=n(7394),o=r.DataView;e.exports=function(e){if(!i||a(e)!==0)return!1;try{return new o(e),!1}catch{return!0}}},5169(e,t,n){var r=n(3238),i=TypeError;e.exports=function(e){if(r(e))throw new i(`ArrayBuffer is detached`);return e}},4644(e,t,n){var r=n(7811),i=n(3724),a=n(4576),o=n(4901),s=n(34),c=n(9297),l=n(6955),u=n(6823),d=n(6699),f=n(6840),p=n(2106),m=n(1625),h=n(2787),g=n(2967),_=n(8227),v=n(3392),y=n(1181),b=y.enforce,x=y.get,S=a.Int8Array,C=S&&S.prototype,w=a.Uint8ClampedArray,T=w&&w.prototype,E=S&&h(S),D=C&&h(C),O=Object.prototype,k=a.TypeError,A=_(`toStringTag`),j=v(`TYPED_ARRAY_TAG`),M=`TypedArrayConstructor`,N=r&&!!g&&l(a.opera)!==`Opera`,P=!1,F,I,L,R={Int8Array:1,Uint8Array:1,Uint8ClampedArray:1,Int16Array:2,Uint16Array:2,Int32Array:4,Uint32Array:4,Float32Array:4,Float64Array:8},ee={BigInt64Array:8,BigUint64Array:8},te=function(e){if(!s(e))return!1;var t=l(e);return t===`DataView`||c(R,t)||c(ee,t)},ne=function(e){var t=h(e);if(s(t)){var n=x(t);return n&&c(n,M)?n[M]:ne(t)}},re=function(e){if(!s(e))return!1;var t=l(e);return c(R,t)||c(ee,t)},ie=function(e){if(re(e))return e;throw new k(`Target is not a typed array`)},ae=function(e){if(o(e)&&(!g||m(E,e)))return e;throw new k(u(e)+` is not a typed array constructor`)},z=function(e,t,n,r){if(i){if(n)for(var o in R){var s=a[o];if(s&&c(s.prototype,e))try{delete s.prototype[e]}catch{try{s.prototype[e]=t}catch{}}}(!D[e]||n)&&f(D,e,n?t:N&&C[e]||t,r)}},B=function(e,t,n){var r,o;if(i){if(g){if(n){for(r in R)if(o=a[r],o&&c(o,e))try{delete o[e]}catch{}}if(!E[e]||n)try{return f(E,e,n?t:N&&E[e]||t)}catch{}else return}for(r in R)o=a[r],o&&(!o[e]||n)&&f(o,e,t)}};for(F in R)I=a[F],L=I&&I.prototype,L?b(L)[M]=I:N=!1;for(F in ee)I=a[F],L=I&&I.prototype,L&&(b(L)[M]=I);if((!N||!o(E)||E===Function.prototype)&&(E=function(){throw new k(`Incorrect invocation`)},N))for(F in R)a[F]&&g(a[F],E);if((!N||!D||D===O)&&(D=E.prototype,N))for(F in R)a[F]&&g(a[F].prototype,D);if(N&&h(T)!==D&&g(T,D),i&&!c(D,A))for(F in P=!0,p(D,A,{configurable:!0,get:function(){return s(this)?this[j]:void 0}}),R)a[F]&&d(a[F].prototype,j,F);e.exports={NATIVE_ARRAY_BUFFER_VIEWS:N,TYPED_ARRAY_TAG:P&&j,aTypedArray:ie,aTypedArrayConstructor:ae,exportTypedArrayMethod:z,exportTypedArrayStaticMethod:B,getTypedArrayConstructor:ne,isView:te,isTypedArray:re,TypedArray:E,TypedArrayPrototype:D}},5370(e,t,n){var r=n(6198);e.exports=function(e,t,n){for(var i=0,a=arguments.length>2?n:r(t),o=new e(a);a>i;)o[i]=t[i++];return o}},9617(e,t,n){var r=n(5397),i=n(5610),a=n(6198),o=function(e){return function(t,n,o){var s=r(t),c=a(s);if(c===0)return!e&&-1;var l=i(o,c),u;if(e&&n!==n){for(;c>l;)if(u=s[l++],u!==u)return!0}else for(;c>l;l++)if((e||l in s)&&s[l]===n)return e||l||0;return!e&&-1}};e.exports={includes:o(!0),indexOf:o(!1)}},4527(e,t,n){var r=n(3724),i=n(4376),a=TypeError,o=Object.getOwnPropertyDescriptor;e.exports=r&&!function(){if(this!==void 0)return!0;try{Object.defineProperty([],"length",{writable:!1}).length=1}catch(e){return e instanceof TypeError}}()?function(e,t){if(i(e)&&!o(e,`length`).writable)throw new a(`Cannot set read only .length`);return e.length=t}:function(e,t){return e.length=t}},7680(e,t,n){e.exports=n(9504)([].slice)},2804(e){var t=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789`,n=t+`+/`,r=t+`-_`,i=function(e){for(var t={},n=0;n<64;n++)t[e.charAt(n)]=n;return t};e.exports={i2c:n,c2i:i(n),i2cUrl:r,c2iUrl:i(r)}},6319(e,t,n){var r=n(8551),i=n(9539);e.exports=function(e,t,n,a){try{return a?t(r(n)[0],n[1]):t(n)}catch(t){i(e,`throw`,t)}}},2195(e,t,n){var r=n(9504),i=r({}.toString),a=r(``.slice);e.exports=function(e){return a(i(e),8,-1)}},6955(e,t,n){var r=n(2140),i=n(4901),a=n(2195),o=n(8227)(`toStringTag`),s=Object,c=a(function(){return arguments}())===`Arguments`,l=function(e,t){try{return e[t]}catch{}};e.exports=r?a:function(e){var t,n,r;return e===void 0?`Undefined`:e===null?`Null`:typeof(n=l(t=s(e),o))==`string`?n:c?a(t):(r=a(t))===`Object`&&i(t.callee)?`Arguments`:r}},7740(e,t,n){var r=n(9297),i=n(5031),a=n(7347),o=n(4913);e.exports=function(e,t,n){for(var s=i(t),c=o.f,l=a.f,u=0;un)throw new t(`Maximum allowed index exceeded`);return e}},5002(e){e.exports={IndexSizeError:{s:`INDEX_SIZE_ERR`,c:1,m:1},DOMStringSizeError:{s:`DOMSTRING_SIZE_ERR`,c:2,m:0},HierarchyRequestError:{s:`HIERARCHY_REQUEST_ERR`,c:3,m:1},WrongDocumentError:{s:`WRONG_DOCUMENT_ERR`,c:4,m:1},InvalidCharacterError:{s:`INVALID_CHARACTER_ERR`,c:5,m:1},NoDataAllowedError:{s:`NO_DATA_ALLOWED_ERR`,c:6,m:0},NoModificationAllowedError:{s:`NO_MODIFICATION_ALLOWED_ERR`,c:7,m:1},NotFoundError:{s:`NOT_FOUND_ERR`,c:8,m:1},NotSupportedError:{s:`NOT_SUPPORTED_ERR`,c:9,m:1},InUseAttributeError:{s:`INUSE_ATTRIBUTE_ERR`,c:10,m:1},InvalidStateError:{s:`INVALID_STATE_ERR`,c:11,m:1},SyntaxError:{s:`SYNTAX_ERR`,c:12,m:1},InvalidModificationError:{s:`INVALID_MODIFICATION_ERR`,c:13,m:1},NamespaceError:{s:`NAMESPACE_ERR`,c:14,m:1},InvalidAccessError:{s:`INVALID_ACCESS_ERR`,c:15,m:1},ValidationError:{s:`VALIDATION_ERR`,c:16,m:0},TypeMismatchError:{s:`TYPE_MISMATCH_ERR`,c:17,m:1},SecurityError:{s:`SECURITY_ERR`,c:18,m:1},NetworkError:{s:`NETWORK_ERR`,c:19,m:1},AbortError:{s:`ABORT_ERR`,c:20,m:1},URLMismatchError:{s:`URL_MISMATCH_ERR`,c:21,m:1},QuotaExceededError:{s:`QUOTA_EXCEEDED_ERR`,c:22,m:1},TimeoutError:{s:`TIMEOUT_ERR`,c:23,m:1},InvalidNodeTypeError:{s:`INVALID_NODE_TYPE_ERR`,c:24,m:1},DataCloneError:{s:`DATA_CLONE_ERR`,c:25,m:1}}},8727(e){e.exports=[`constructor`,`hasOwnProperty`,`isPrototypeOf`,`propertyIsEnumerable`,`toLocaleString`,`toString`,`valueOf`]},2839(e,t,n){var r=n(4576).navigator,i=r&&r.userAgent;e.exports=i?String(i):``},9519(e,t,n){var r=n(4576),i=n(2839),a=r.process,o=r.Deno,s=a&&a.versions||o&&o.version,c=s&&s.v8,l,u;c&&(l=c.split(`.`),u=l[0]>0&&l[0]<4?1:+(l[0]+l[1])),!u&&i&&(l=i.match(/Edge\/(\d+)/),(!l||l[1]>=74)&&(l=i.match(/Chrome\/(\d+)/),l&&(u=+l[1]))),e.exports=u},6193(e,t,n){var r=n(9504),i=Error,a=r(``.replace),o=(function(e){return String(new i(e).stack)})(`zxcasd`),s=/\n\s*at [^:]*:[^\n]*/,c=s.test(o);e.exports=function(e,t){if(c&&typeof e==`string`&&!i.prepareStackTrace)for(;t--;)e=a(e,s,``);return e}},6518(e,t,n){var r=n(4576),i=n(7347).f,a=n(6699),o=n(6840),s=n(9433),c=n(7740),l=n(2796);e.exports=function(e,t){var n=e.target,u=e.global,d=e.stat,f,p=u?r:d?r[n]||s(n,{}):r[n]&&r[n].prototype,m,h,g,_;if(p)for(m in t){if(g=t[m],e.dontCallGetSet?(_=i(p,m),h=_&&_.value):h=p[m],f=l(u?m:n+(d?`.`:`#`)+m,e.forced),!f&&h!==void 0){if(typeof g==typeof h)continue;c(g,h)}(e.sham||h&&h.sham)&&a(g,`sham`,!0),o(p,m,g,e)}}},9039(e){e.exports=function(e){try{return!!e()}catch{return!0}}},8745(e,t,n){var r=n(616),i=Function.prototype,a=i.apply,o=i.call;e.exports=typeof Reflect==`object`&&Reflect.apply||(r?o.bind(a):function(){return o.apply(a,arguments)})},6080(e,t,n){var r=n(7476),i=n(9306),a=n(616),o=r(r.bind);e.exports=function(e,t){return i(e),t===void 0?e:a?o(e,t):function(){return e.apply(t,arguments)}}},616(e,t,n){e.exports=!n(9039)(function(){var e=function(){}.bind();return typeof e!=`function`||e.hasOwnProperty(`prototype`)})},9565(e,t,n){var r=n(616),i=Function.prototype.call;e.exports=r?i.bind(i):function(){return i.apply(i,arguments)}},350(e,t,n){var r=n(3724),i=n(9297),a=Function.prototype,o=r&&Object.getOwnPropertyDescriptor,s=i(a,`name`);e.exports={EXISTS:s,PROPER:s&&function(){}.name===`something`,CONFIGURABLE:s&&(!r||r&&o(a,`name`).configurable)}},6706(e,t,n){var r=n(9504),i=n(9306);e.exports=function(e,t,n){try{return r(i(Object.getOwnPropertyDescriptor(e,t)[n]))}catch{}}},7476(e,t,n){var r=n(2195),i=n(9504);e.exports=function(e){if(r(e)===`Function`)return i(e)}},9504(e,t,n){var r=n(616),i=Function.prototype,a=i.call,o=r&&i.bind.bind(a,a);e.exports=r?o:function(e){return function(){return a.apply(e,arguments)}}},944(e){var t=TypeError;e.exports=function(e){var n=e&&e.alphabet;if(n===void 0||n===`base64`||n===`base64url`)return n||`base64`;throw new t("Incorrect `alphabet` option")}},7751(e,t,n){var r=n(4576),i=n(4901),a=function(e){return i(e)?e:void 0};e.exports=function(e,t){return arguments.length<2?a(r[e]):r[e]&&r[e][t]}},1767(e){e.exports=function(e){return{iterator:e,next:e.next,done:!1}}},8646(e,t,n){var r=n(9565),i=n(8551),a=n(1767),o=n(851);e.exports=function(e,t){(!t||typeof e!=`string`)&&i(e);var n=o(e);return a(i(n===void 0?e:r(n,e)))}},851(e,t,n){var r=n(6955),i=n(5966),a=n(4117),o=n(6269),s=n(8227)(`iterator`);e.exports=function(e){if(!a(e))return i(e,s)||i(e,`@@iterator`)||o[r(e)]}},81(e,t,n){var r=n(9565),i=n(9306),a=n(8551),o=n(6823),s=n(851),c=TypeError;e.exports=function(e,t){var n=arguments.length<2?s(e):t;if(i(n))return a(r(n,e));throw new c(o(e)+` is not iterable`)}},5966(e,t,n){var r=n(9306),i=n(4117);e.exports=function(e,t){var n=e[t];return i(n)?void 0:r(n)}},3789(e,t,n){var r=n(9306),i=n(8551),a=n(9565),o=n(1291),s=n(1767),c=`Invalid size`,l=RangeError,u=TypeError,d=Math.max,f=function(e,t){this.set=e,this.size=d(t,0),this.has=r(e.has),this.keys=r(e.keys)};f.prototype={getIterator:function(){return s(i(a(this.keys,this.set)))},includes:function(e){return a(this.has,this.set,e)}},e.exports=function(e){i(e);var t=+e.size;if(t!==t)throw new u(c);var n=o(t);if(n<0)throw new l(c);return new f(e,n)}},4576(e){var t=function(e){return e&&e.Math===Math&&e};e.exports=t(typeof globalThis==`object`&&globalThis)||t(typeof window==`object`&&window)||t(typeof self==`object`&&self)||t(typeof global==`object`&&global)||t(typeof this==`object`&&this)||(function(){return this})()||Function(`return this`)()},9297(e,t,n){var r=n(9504),i=n(8981),a=r({}.hasOwnProperty);e.exports=Object.hasOwn||function(e,t){return a(i(e),t)}},421(e){e.exports={}},397(e,t,n){e.exports=n(7751)(`document`,`documentElement`)},5917(e,t,n){var r=n(3724),i=n(9039),a=n(4055);e.exports=!r&&!i(function(){return Object.defineProperty(a(`div`),"a",{get:function(){return 7}}).a!==7})},7055(e,t,n){var r=n(9504),i=n(9039),a=n(2195),o=Object,s=r(``.split);e.exports=i(function(){return!o(`z`).propertyIsEnumerable(0)})?function(e){return a(e)===`String`?s(e,``):o(e)}:o},3167(e,t,n){var r=n(4901),i=n(34),a=n(2967);e.exports=function(e,t,n){var o,s;return a&&r(o=t.constructor)&&o!==n&&i(s=o.prototype)&&s!==n.prototype&&a(e,s),e}},3706(e,t,n){var r=n(9504),i=n(4901),a=n(7629),o=r(Function.toString);i(a.inspectSource)||(a.inspectSource=function(e){return o(e)}),e.exports=a.inspectSource},1181(e,t,n){var r=n(8622),i=n(4576),a=n(34),o=n(6699),s=n(9297),c=n(7629),l=n(6119),u=n(421),d=`Object already initialized`,f=i.TypeError,p=i.WeakMap,m,h,g,_=function(e){return g(e)?h(e):m(e,{})},v=function(e){return function(t){var n;if(!a(t)||(n=h(t)).type!==e)throw new f(`Incompatible receiver, `+e+` required`);return n}};if(r||c.state){var y=c.state||=new p;y.get=y.get,y.has=y.has,y.set=y.set,m=function(e,t){if(y.has(e))throw new f(d);return t.facade=e,y.set(e,t),t},h=function(e){return y.get(e)||{}},g=function(e){return y.has(e)}}else{var b=l(`state`);u[b]=!0,m=function(e,t){if(s(e,b))throw new f(d);return t.facade=e,o(e,b,t),t},h=function(e){return s(e,b)?e[b]:{}},g=function(e){return s(e,b)}}e.exports={set:m,get:h,has:g,enforce:_,getterFor:v}},4209(e,t,n){var r=n(8227),i=n(6269),a=r(`iterator`),o=Array.prototype;e.exports=function(e){return e!==void 0&&(i.Array===e||o[a]===e)}},4376(e,t,n){var r=n(2195);e.exports=Array.isArray||function(e){return r(e)===`Array`}},1108(e,t,n){var r=n(6955);e.exports=function(e){var t=r(e);return t===`BigInt64Array`||t===`BigUint64Array`}},4901(e){var t=typeof document==`object`&&document.all;e.exports=t===void 0&&t!==void 0?function(e){return typeof e==`function`||e===t}:function(e){return typeof e==`function`}},2796(e,t,n){var r=n(9039),i=n(4901),a=/#|\.prototype\./,o=function(e,t){var n=c[s(e)];return n===u?!0:n===l?!1:i(t)?r(t):!!t},s=o.normalize=function(e){return String(e).replace(a,`.`).toLowerCase()},c=o.data={},l=o.NATIVE=`N`,u=o.POLYFILL=`P`;e.exports=o},4117(e){e.exports=function(e){return e==null}},34(e,t,n){var r=n(4901);e.exports=function(e){return typeof e==`object`?e!==null:r(e)}},3925(e,t,n){var r=n(34);e.exports=function(e){return r(e)||e===null}},6395(e){e.exports=!1},5810(e,t,n){var r=n(34),i=n(1181).get;e.exports=function(e){if(!r(e))return!1;var t=i(e);return!!t&&t.type===`RawJSON`}},757(e,t,n){var r=n(7751),i=n(4901),a=n(1625),o=n(7040),s=Object;e.exports=o?function(e){return typeof e==`symbol`}:function(e){var t=r(`Symbol`);return i(t)&&a(t.prototype,s(e))}},507(e,t,n){var r=n(9565);e.exports=function(e,t,n){for(var i=n?e:e.iterator,a=e.next,o,s;!(o=r(a,i)).done;)if(s=t(o.value),s!==void 0)return s}},2652(e,t,n){var r=n(6080),i=n(9565),a=n(8551),o=n(6823),s=n(4209),c=n(6198),l=n(1625),u=n(81),d=n(851),f=n(9539),p=TypeError,m=function(e,t){this.stopped=e,this.result=t},h=m.prototype;e.exports=function(e,t,n){var g=n&&n.that,_=!!(n&&n.AS_ENTRIES),v=!!(n&&n.IS_RECORD),y=!!(n&&n.IS_ITERATOR),b=!!(n&&n.INTERRUPTED),x=r(t,g),S,C,w,T,E,D,O,k=function(e){var t=S;return S=void 0,t&&f(t,`normal`),new m(!0,e)},A=function(e){return _?(a(e),b?x(e[0],e[1],k):x(e[0],e[1])):b?x(e,k):x(e)};if(v)S=e.iterator;else if(y)S=e;else{if(C=d(e),!C)throw new p(o(e)+` is not iterable`);if(s(C)){for(w=0,T=c(e);T>w;w++)if(E=A(e[w]),E&&l(h,E))return E;return new m(!1)}S=u(e,C)}for(D=v?e.next:S.next;!(O=i(D,S)).done;){var j=O.value;try{E=A(j)}catch(e){if(S)f(S,`throw`,e);else throw e}if(typeof E==`object`&&E&&l(h,E))return E}return new m(!1)}},1385(e,t,n){var r=n(9539);e.exports=function(e,t,n){for(var i=e.length-1;i>=0;i--)if(e[i]!==void 0)try{n=r(e[i].iterator,t,n)}catch(e){t=`throw`,n=e}if(t===`throw`)throw n;return n}},9539(e,t,n){var r=n(9565),i=n(8551),a=n(5966);e.exports=function(e,t,n){var o,s;i(e);try{if(o=a(e,`return`),!o){if(t===`throw`)throw n;return n}o=r(o,e)}catch(e){s=!0,o=e}if(t===`throw`)throw n;if(s)throw o;return i(o),n}},9462(e,t,n){var r=n(9565),i=n(2360),a=n(6699),o=n(6279),s=n(8227),c=n(1181),l=n(5966),u=n(7657).IteratorPrototype,d=n(2529),f=n(9539),p=n(1385),m=s(`toStringTag`),h=`IteratorHelper`,g=`WrapForValidIterator`,_=`normal`,v=`throw`,y=c.set,b=function(e){var t=c.getterFor(e?g:h);return o(i(u),{next:function(){var n=t(this);if(e)return n.nextHandler();if(n.done)return d(void 0,!0);try{var r=n.nextHandler();return n.returnHandlerResult?r:d(r,n.done)}catch(e){throw n.done=!0,e}},return:function(){var n=t(this),i=n.iterator,a=n.done;if(n.done=!0,e){var o=l(i,`return`);return o?r(o,i):d(void 0,!0)}if(a)return d(void 0,!0);if(n.inner)try{f(n.inner.iterator,_)}catch(e){return f(i,v,e)}if(n.openIters)try{p(n.openIters,_)}catch(e){if(i)return f(i,v,e);throw e}return i&&f(i,_),d(void 0,!0)}})},x=b(!0),S=b(!1);a(S,m,`Iterator Helper`),e.exports=function(e,t,n){var r=function(r,i){i?(i.iterator=r.iterator,i.next=r.next):i=r,i.type=t?g:h,i.returnHandlerResult=!!n,i.nextHandler=e,i.counter=0,i.done=!1,y(this,i)};return r.prototype=t?x:S,r}},684(e){e.exports=function(e,t){var n=typeof Iterator==`function`&&Iterator.prototype[e];if(n)try{n.call({next:null},t).next()}catch{return!0}}},4549(e,t,n){var r=n(4576);e.exports=function(e,t){var n=r.Iterator,i=n&&n.prototype,a=i&&i[e],o=!1;if(a)try{a.call({next:function(){return{done:!0}},return:function(){o=!0}},-1)}catch(e){e instanceof t||(o=!1)}if(!o)return a}},7657(e,t,n){var r=n(9039),i=n(4901),a=n(34),o=n(2360),s=n(2787),c=n(6840),l=n(8227),u=n(6395),d=l(`iterator`),f=!1,p,m,h;[].keys&&(h=[].keys(),`next`in h?(m=s(s(h)),m!==Object.prototype&&(p=m)):f=!0),!a(p)||r(function(){var e={};return p[d].call(e)!==e})?p={}:u&&(p=o(p)),i(p[d])||c(p,d,function(){return this}),e.exports={IteratorPrototype:p,BUGGY_SAFARI_ITERATORS:f}},6269(e){e.exports={}},6198(e,t,n){var r=n(8014);e.exports=function(e){return r(e.length)}},283(e,t,n){var r=n(9504),i=n(9039),a=n(4901),o=n(9297),s=n(3724),c=n(350).CONFIGURABLE,l=n(3706),u=n(1181),d=u.enforce,f=u.get,p=String,m=Object.defineProperty,h=r(``.slice),g=r(``.replace),_=r([].join),v=s&&!i(function(){return m(function(){},`length`,{value:8}).length!==8}),y=String(String).split(`String`),b=e.exports=function(e,t,n){h(p(t),0,7)===`Symbol(`&&(t=`[`+g(p(t),/^Symbol\(([^)]*)\).*$/,`$1`)+`]`),n&&n.getter&&(t=`get `+t),n&&n.setter&&(t=`set `+t),(!o(e,`name`)||c&&e.name!==t)&&(s?m(e,`name`,{value:t,configurable:!0}):e.name=t),v&&n&&o(n,`arity`)&&e.length!==n.arity&&m(e,`length`,{value:n.arity});try{n&&o(n,`constructor`)&&n.constructor?s&&m(e,`prototype`,{writable:!1}):e.prototype&&=void 0}catch{}var r=d(e);return o(r,`source`)||(r.source=_(y,typeof t==`string`?t:``)),e};Function.prototype.toString=b(function(){return a(this)&&f(this).source||l(this)},`toString`)},2248(e,t,n){var r=n(9504),i=Map.prototype;e.exports={Map,set:r(i.set),get:r(i.get),has:r(i.has),remove:r(i.delete),proto:i}},741(e){var t=Math.ceil,n=Math.floor;e.exports=Math.trunc||function(e){var r=+e;return(r>0?n:t)(r)}},7819(e,t,n){e.exports=!n(9039)(function(){var e=`9007199254740993`,t=JSON.rawJSON(e);return!JSON.isRawJSON(t)||JSON.stringify(t)!==e})},6043(e,t,n){var r=n(9306),i=TypeError,a=function(e){var t,n;this.promise=new e(function(e,r){if(t!==void 0||n!==void 0)throw new i(`Bad Promise constructor`);t=e,n=r}),this.resolve=r(t),this.reject=r(n)};e.exports.f=function(e){return new a(e)}},2603(e,t,n){var r=n(655);e.exports=function(e,t){return e===void 0?arguments.length<2?``:t:r(e)}},4149(e){var t=RangeError;e.exports=function(e){if(e===e)return e;throw new t(`NaN is not allowed`)}},2360(e,t,n){var r=n(8551),i=n(6801),a=n(8727),o=n(421),s=n(397),c=n(4055),l=n(6119),u=`>`,d=`<`,f=`prototype`,p=`script`,m=l(`IE_PROTO`),h=function(){},g=function(e){return d+p+u+e+d+`/`+p+u},_=function(e){e.write(g(``)),e.close();var t=e.parentWindow.Object;return e=null,t},v=function(){var e=c(`iframe`),t=`java`+p+`:`,n;return e.style.display=`none`,s.appendChild(e),e.src=String(t),n=e.contentWindow.document,n.open(),n.write(g(`document.F=Object`)),n.close(),n.F},y,b=function(){try{y=new ActiveXObject(`htmlfile`)}catch{}b=typeof document<`u`?document.domain&&y?_(y):v():_(y);for(var e=a.length;e--;)delete b[f][a[e]];return b()};o[m]=!0,e.exports=Object.create||function(e,t){var n;return e===null?n=b():(h[f]=r(e),n=new h,h[f]=null,n[m]=e),t===void 0?n:i.f(n,t)}},6801(e,t,n){var r=n(3724),i=n(8686),a=n(4913),o=n(8551),s=n(5397),c=n(1072);t.f=r&&!i?Object.defineProperties:function(e,t){o(e);for(var n=s(t),r=c(t),i=r.length,l=0,u;i>l;)a.f(e,u=r[l++],n[u]);return e}},4913(e,t,n){var r=n(3724),i=n(5917),a=n(8686),o=n(8551),s=n(6969),c=TypeError,l=Object.defineProperty,u=Object.getOwnPropertyDescriptor,d=`enumerable`,f=`configurable`,p=`writable`;t.f=r?a?function(e,t,n){if(o(e),t=s(t),o(n),typeof e==`function`&&t===`prototype`&&`value`in n&&p in n&&!n[p]){var r=u(e,t);r&&r[p]&&(e[t]=n.value,n={configurable:f in n?n[f]:r[f],enumerable:d in n?n[d]:r[d],writable:!1})}return l(e,t,n)}:l:function(e,t,n){if(o(e),t=s(t),o(n),i)try{return l(e,t,n)}catch{}if(`get`in n||`set`in n)throw new c(`Accessors not supported`);return`value`in n&&(e[t]=n.value),e}},7347(e,t,n){var r=n(3724),i=n(9565),a=n(8773),o=n(6980),s=n(5397),c=n(6969),l=n(9297),u=n(5917),d=Object.getOwnPropertyDescriptor;t.f=r?d:function(e,t){if(e=s(e),t=c(t),u)try{return d(e,t)}catch{}if(l(e,t))return o(!i(a.f,e,t),e[t])}},8480(e,t,n){var r=n(1828),i=n(8727).concat(`length`,`prototype`);t.f=Object.getOwnPropertyNames||function(e){return r(e,i)}},3717(e,t){t.f=Object.getOwnPropertySymbols},2787(e,t,n){var r=n(9297),i=n(4901),a=n(8981),o=n(6119),s=n(2211),c=o(`IE_PROTO`),l=Object,u=l.prototype;e.exports=s?l.getPrototypeOf:function(e){var t=a(e);if(r(t,c))return t[c];var n=t.constructor;return i(n)&&t instanceof n?n.prototype:t instanceof l?u:null}},1625(e,t,n){e.exports=n(9504)({}.isPrototypeOf)},1828(e,t,n){var r=n(9504),i=n(9297),a=n(5397),o=n(9617).indexOf,s=n(421),c=r([].push);e.exports=function(e,t){var n=a(e),r=0,l=[],u;for(u in n)!i(s,u)&&i(n,u)&&c(l,u);for(;t.length>r;)i(n,u=t[r++])&&(~o(l,u)||c(l,u));return l}},1072(e,t,n){var r=n(1828),i=n(8727);e.exports=Object.keys||function(e){return r(e,i)}},8773(e,t){var n={}.propertyIsEnumerable,r=Object.getOwnPropertyDescriptor;t.f=r&&!n.call({1:2},1)?function(e){var t=r(this,e);return!!t&&t.enumerable}:n},2967(e,t,n){var r=n(6706),i=n(34),a=n(7750),o=n(3506);e.exports=Object.setPrototypeOf||(`__proto__`in{}?function(){var e=!1,t={},n;try{n=r(Object.prototype,`__proto__`,`set`),n(t,[]),e=t instanceof Array}catch{}return function(t,r){return a(t),o(r),i(t)&&(e?n(t,r):t.__proto__=r),t}}():void 0)},4270(e,t,n){var r=n(9565),i=n(4901),a=n(34),o=TypeError;e.exports=function(e,t){var n,s;if(t===`string`&&i(n=e.toString)&&!a(s=r(n,e))||i(n=e.valueOf)&&!a(s=r(n,e))||t!==`string`&&i(n=e.toString)&&!a(s=r(n,e)))return s;throw new o(`Can't convert object to primitive value`)}},5031(e,t,n){var r=n(7751),i=n(9504),a=n(8480),o=n(3717),s=n(8551),c=i([].concat);e.exports=r(`Reflect`,`ownKeys`)||function(e){var t=a.f(s(e)),n=o.f;return n?c(t,n(e)):t}},8235(e,t,n){var r=n(9504),i=n(9297),a=SyntaxError,o=parseInt,s=String.fromCharCode,c=r(``.charAt),l=r(``.slice),u=r(/./.exec),d={'\\"':`"`,"\\\\":`\\`,"\\/":`/`,"\\b":`\b`,"\\f":`\f`,"\\n":` `,"\\r":`\r`,"\\t":` `},f=/^[\da-f]{4}$/i,p=/^[\u0000-\u001F]$/;e.exports=function(e,t){for(var n=!0,r=``;tn.size?c(n.getIterator(),function(e){d(t,e)&&u(i,e)}):s(t,function(e){n.includes(e)&&u(i,e)}),i}},4449(e,t,n){var r=n(7080),i=n(4402).has,a=n(5170),o=n(3789),s=n(8469),c=n(507),l=n(9539);e.exports=function(e){var t=r(this),n=o(e);if(a(t)<=n.size)return s(t,function(e){if(n.includes(e))return!1},!0)!==!1;var u=n.getIterator();return c(u,function(e){if(i(t,e))return l(u.iterator,`normal`,!1)})!==!1}},3838(e,t,n){var r=n(7080),i=n(5170),a=n(8469),o=n(3789);e.exports=function(e){var t=r(this),n=o(e);return i(t)>n.size?!1:a(t,function(e){if(!n.includes(e))return!1},!0)!==!1}},8527(e,t,n){var r=n(7080),i=n(4402).has,a=n(5170),o=n(3789),s=n(507),c=n(9539);e.exports=function(e){var t=r(this),n=o(e);if(a(t)0?i(t,9007199254740991):0}},8981(e,t,n){var r=n(7750),i=Object;e.exports=function(e){return i(r(e))}},9590(e,t,n){var r=n(1291),i=RangeError;e.exports=function(e){var t=r(e);if(t<0)throw new i(`The argument can't be less than 0`);return t}},2777(e,t,n){var r=n(9565),i=n(34),a=n(757),o=n(5966),s=n(4270),c=n(8227),l=TypeError,u=c(`toPrimitive`);e.exports=function(e,t){if(!i(e)||a(e))return e;var n=o(e,u),c;if(n){if(t===void 0&&(t=`default`),c=r(n,e,t),!i(c)||a(c))return c;throw new l(`Can't convert object to primitive value`)}return t===void 0&&(t=`number`),s(e,t)}},6969(e,t,n){var r=n(2777),i=n(757);e.exports=function(e){var t=r(e,`string`);return i(t)?t:t+``}},2140(e,t,n){var r=n(8227)(`toStringTag`),i={};i[r]=`z`,e.exports=String(i)===`[object z]`},655(e,t,n){var r=n(6955),i=String;e.exports=function(e){if(r(e)===`Symbol`)throw TypeError(`Cannot convert a Symbol value to a string`);return i(e)}},6823(e){var t=String;e.exports=function(e){try{return t(e)}catch{return`Object`}}},3392(e,t,n){var r=n(9504),i=0,a=Math.random(),o=r(1.1.toString);e.exports=function(e){return`Symbol(`+(e===void 0?``:e)+`)_`+o(++i+a,36)}},9143(e,t,n){var r=n(4576),i=n(9504),a=n(3972),o=n(3463),s=n(9297),c=n(2804),l=n(944),u=n(5169),d=c.c2i,f=c.c2iUrl,p=r.SyntaxError,m=r.TypeError,h=i(``.charAt),g=function(e,t){for(var n=e.length;t>16&255,i>>8&255,i&255];if(r===2){if(n&&a[1]!==0)throw new p(`Extra bits`);return[a[0]]}if(r===3){if(n&&a[2]!==0)throw new p(`Extra bits`);return[a[0],a[1]]}return a},v=function(e,t,n){for(var r=t.length,i=0;i0){if(c===`stop-before-partial`)break;if(c===`loose`){if(C.length===1)throw new p(`Malformed padding: exactly one additional character`);x=v(b,_(C,i,!1),x)}else throw new p(`Missing padding`)}S=y;break}var T=h(e,w);if(++w,T===`=`){if(C.length<2)throw new p(`Padding is too early`);if(w=g(e,w),C.length===2){if(w===y){if(c===`stop-before-partial`)break;throw new p(`Malformed padding: only one =`)}h(e,w)===`=`&&(++w,w=g(e,w))}if(w>4}return{bytes:i,read:u<<1}}},7416(e,t,n){var r=n(9039),i=n(8227),a=n(3724),o=n(6395),s=i(`iterator`);e.exports=!r(function(){var e=new URL(`b?a=1&b=2&c=3`,`https://a`),t=e.searchParams,n=new URLSearchParams(`a=1&a=2&b=3`),r=``;return e.pathname=`c%20d`,t.forEach(function(e,n){t.delete(`b`),r+=n+e}),n.delete(`a`,2),n.delete(`b`,void 0),o&&(!e.toJSON||!n.has(`a`,1)||n.has(`a`,2)||!n.has(`a`,void 0)||n.has(`b`))||!t.size&&(o||!a)||!t.sort||e.href!==`https://a/c%20d?a=1&c=3`||t.get(`c`)!==`3`||String(new URLSearchParams(`?a=1`))!==`a=1`||!t[s]||new URL(`https://a@b`).username!==`a`||new URLSearchParams(new URLSearchParams(`a=b`)).get(`a`)!==`b`||new URL(`https://тест`).host!==`xn--e1aybc`||new URL(`https://a#б`).hash!==`#%D0%B1`||r!==`a1c3`||new URL(`https://x`,void 0).host!==`x`})},7040(e,t,n){e.exports=n(4495)&&!Symbol.sham&&typeof Symbol.iterator==`symbol`},8686(e,t,n){var r=n(3724),i=n(9039);e.exports=r&&i(function(){return Object.defineProperty(function(){},"prototype",{value:42,writable:!1}).prototype!==42})},2812(e){var t=TypeError;e.exports=function(e,n){if(e1?arguments[1]:void 0)}}),o(`includes`)},4114(e,t,n){var r=n(6518),i=n(8981),a=n(6198),o=n(4527),s=n(6837);r({target:`Array`,proto:!0,arity:1,forced:n(9039)(function(){return[].push.call({length:4294967296},1)!==4294967297})||!function(){try{Object.defineProperty([],"length",{writable:!1}).push()}catch(e){return e instanceof TypeError}}()},{push:function(e){var t=i(this),n=a(t),r=arguments.length;s(n+r);for(var c=0;cm)throw new o(`Maximum allowed index exceeded`);if(typeof e!=`number`)throw new s(`Value is not a number`);r!==_&&(e===e?e===c?r=r===v?_:y:e===-c?r=r===y?_:v:(e!==0||1/e===c)&&(r===b||r===x)&&(r=x,f(t,e)):r=_)}),r){case _:return l;case v:return-c;case y:return c;case b:return-0}for(var i=[],d=0,C,w,T,E,D,O,k=0;k=0?i[N]:0;if(N--,u(d)>1||d>0&&P>0||d<0&&P<0)return d>0?c:-c;if(T=S(d*p,P/2),E=T.hi,D=T.lo,D*=2,u(2*E)===c)return E>0?E===p&&D===-(g/2)&&N>=0&&i[N]<0?h:c:E===-p&&D===g/2&&N>=0&&i[N]>0?-h:-c;D!==0&&(i[++N]=D,D=0),E*=2}for(;N>=0&&(T=S(E,i[N--]),E=T.hi,D=T.lo,D===0););return N>=0&&(D<0&&i[N]<0||D>0&&i[N]>0)&&(w=D*2,C=E+w,w===C-E&&(E=C)),E}})},1689(e,t,n){var r=n(6518),i=n(4576),a=n(8745),o=n(7680),s=n(6043),c=n(9306),l=n(1103),u=i.Promise,d=!1;r({target:`Promise`,stat:!0,forced:!u||!u.try||l(function(){u.try(function(e){d=e===8},8)}).error||!d},{try:function(e){var t=arguments.length>1?o(arguments,1):[],n=s.f(this),r=l(function(){return a(c(e),void 0,t)});return(r.error?n.reject:n.resolve)(r.value),n.promise}})},4628(e,t,n){var r=n(6518),i=n(6043);r({target:`Promise`,stat:!0},{withResolvers:function(){var e=i.f(this);return{promise:e.promise,resolve:e.resolve,reject:e.reject}}})},7642(e,t,n){var r=n(6518),i=n(3440),a=n(9039);r({target:`Set`,proto:!0,real:!0,forced:!n(4916)(`difference`,function(e){return e.size===0})||a(function(){var e={size:1,has:function(){return!0},keys:function(){var e=0;return{next:function(){var n=e++>1;return t.has(1)&&t.clear(),{done:n,value:2}}}}},t=new Set([1,2,3,4]);return t.difference(e).size!==3})},{difference:i})},8004(e,t,n){var r=n(6518),i=n(9039),a=n(8750);r({target:`Set`,proto:!0,real:!0,forced:!n(4916)(`intersection`,function(e){return e.size===2&&e.has(1)&&e.has(2)})||i(function(){return String(Array.from(new Set([1,2,3]).intersection(new Set([3,2]))))!==`3,2`})},{intersection:a})},3853(e,t,n){var r=n(6518),i=n(4449);r({target:`Set`,proto:!0,real:!0,forced:!n(4916)(`isDisjointFrom`,function(e){return!e})},{isDisjointFrom:i})},5876(e,t,n){var r=n(6518),i=n(3838);r({target:`Set`,proto:!0,real:!0,forced:!n(4916)(`isSubsetOf`,function(e){return e})},{isSubsetOf:i})},2475(e,t,n){var r=n(6518),i=n(8527);r({target:`Set`,proto:!0,real:!0,forced:!n(4916)(`isSupersetOf`,function(e){return!e})},{isSupersetOf:i})},5024(e,t,n){var r=n(6518),i=n(3650),a=n(9835);r({target:`Set`,proto:!0,real:!0,forced:!n(4916)(`symmetricDifference`)||!a(`symmetricDifference`)},{symmetricDifference:i})},1698(e,t,n){var r=n(6518),i=n(4204),a=n(9835);r({target:`Set`,proto:!0,real:!0,forced:!n(4916)(`union`)||!a(`union`)},{union:i})},9577(e,t,n){var r=n(4644),i=n(1108),a=n(6198),o=n(1291),s=n(5854),c=r.aTypedArray,l=r.getTypedArrayConstructor,u=r.exportTypedArrayMethod,d=RangeError,f=function(){try{new Int8Array(1).with(2,{valueOf:function(){throw 8}})}catch(e){return e===8}}(),p=f&&function(){try{new Int8Array(1).with(-.5,1)}catch{return!0}}();u(`with`,{with:function(e,t){var n=c(this),r=a(n),u=o(e),f=u<0?r+u:u,p=i(n)?s(t):+t;if(f>=r||f<0)throw new d(`Incorrect index`);for(var m=new(l(n))(r),h=0;h1?arguments[1]:void 0,null,9007199254740991).bytes)}})},6632(e,t,n){var r=n(6518),i=n(4576),a=n(9143),o=n(4154),s=i.Uint8Array,c=!s||!s.prototype.setFromBase64||!function(){var e=new s([255,255,255,255,255]);try{e.setFromBase64(``,null);return}catch{}try{e.setFromBase64(`a`);return}catch{}try{e.setFromBase64(`MjYyZg===`)}catch{return e[0]===50&&e[1]===54&&e[2]===50&&e[3]===255&&e[4]===255}}();s&&r({target:`Uint8Array`,proto:!0,forced:c},{setFromBase64:function(e){o(this);var t=a(e,arguments.length>1?arguments[1]:void 0,this,this.length);return{read:t.read,written:t.written}}})},4226(e,t,n){var r=n(6518),i=n(4576),a=n(3463),o=n(4154),s=n(5169),c=n(2303);function l(){try{new Uint8Array(new ArrayBuffer(16,{maxByteLength:1024})).setFromHex(`cafed00d`)}catch{return!0}}i.Uint8Array&&r({target:`Uint8Array`,proto:!0,forced:l()},{setFromHex:function(e){o(this),a(e),s(this.buffer);var t=c(e,this).read;return{read:t,written:t/2}}})},9486(e,t,n){var r=n(6518),i=n(4576),a=n(9504),o=n(3972),s=n(4154),c=n(5169),l=n(2804),u=n(944),d=l.i2c,f=l.i2cUrl,p=a(``.charAt),m=i.Uint8Array,h=!m||!m.prototype.toBase64||!function(){try{new m().toBase64(null)}catch{return!0}}();m&&r({target:`Uint8Array`,proto:!0,forced:h},{toBase64:function(){var e=s(this),t=arguments.length?o(arguments[0]):void 0,n=u(t)===`base64`?d:f,r=!!t&&!!t.omitPadding;c(this.buffer);for(var i=``,a=0,l=e.length,m,h=function(e){return p(n,m>>6*e&63)};a+2{if(Array.isArray(t))for(var n=0;nObject.prototype.hasOwnProperty.call(e,t),r(4423),r(4114),r(8111),r(2489),r(5367),r(2731),r(7642),r(8004),r(3853),r(5876),r(2475),r(5024),r(1698),r(9577),r(6632),r(4226),r(9486),r(456),r(5781);var i=typeof process==`object`&&process+``==`[object process]`&&!process.versions.nw&&!(process.versions.electron&&process.type&&process.type!==`browser`),a=[1/0,1/0,-1/0,-1/0],o=new Float32Array(a),s=[.001,0,0,.001,0,0],c=`http://www.w3.org/2000/svg`,l={ANY:1,DISPLAY:2,PRINT:4,SAVE:8,ANNOTATIONS_FORMS:16,ANNOTATIONS_STORAGE:32,ANNOTATIONS_DISABLE:64,IS_EDITING:128,OPLIST:256},u={DISABLE:0,ENABLE:1,ENABLE_FORMS:2,ENABLE_STORAGE:3},d=`pdfjs_internal_id_`,f=`pdfjs_internal_editor_`,p={DISABLE:-1,NONE:0,FREETEXT:3,HIGHLIGHT:9,STAMP:13,INK:15,POPUP:16,SIGNATURE:101,COMMENT:102},m={RESIZE:1,CREATE:2,FREETEXT_SIZE:11,FREETEXT_COLOR:12,FREETEXT_OPACITY:13,INK_COLOR:21,INK_THICKNESS:22,INK_OPACITY:23,INK_COLOR_AND_OPACITY:24,HIGHLIGHT_COLOR:31,HIGHLIGHT_THICKNESS:32,HIGHLIGHT_FREE:33,HIGHLIGHT_SHOW_ALL:34,DRAW_STEP:41},h={PRINT:4,MODIFY_CONTENTS:8,COPY:16,MODIFY_ANNOTATIONS:32,FILL_INTERACTIVE_FORMS:256,COPY_FOR_ACCESSIBILITY:512,ASSEMBLE:1024,PRINT_HIGH_QUALITY:2048},g={FILL:0,STROKE:1,FILL_STROKE:2,INVISIBLE:3,FILL_ADD_TO_PATH:4,STROKE_ADD_TO_PATH:5,FILL_STROKE_ADD_TO_PATH:6,ADD_TO_PATH:7,FILL_STROKE_MASK:3,ADD_TO_PATH_FLAG:4},_={GRAYSCALE_1BPP:1,RGB_24BPP:2,RGBA_32BPP:3},v={TEXT:1,LINK:2,FREETEXT:3,LINE:4,SQUARE:5,CIRCLE:6,POLYGON:7,POLYLINE:8,HIGHLIGHT:9,UNDERLINE:10,SQUIGGLY:11,STRIKEOUT:12,STAMP:13,CARET:14,INK:15,POPUP:16,FILEATTACHMENT:17,SOUND:18,MOVIE:19,WIDGET:20,SCREEN:21,PRINTERMARK:22,TRAPNET:23,WATERMARK:24,THREED:25,REDACT:26,RICHMEDIA:27},y={SOLID:1,DASHED:2,BEVELED:3,INSET:4,UNDERLINE:5},b={ERRORS:0,WARNINGS:1,INFOS:5},x={dependency:1,setLineWidth:2,setLineCap:3,setLineJoin:4,setMiterLimit:5,setDash:6,setRenderingIntent:7,setFlatness:8,setGState:9,save:10,restore:11,transform:12,moveTo:13,lineTo:14,curveTo:15,curveTo2:16,curveTo3:17,closePath:18,rectangle:19,stroke:20,closeStroke:21,fill:22,eoFill:23,fillStroke:24,eoFillStroke:25,closeFillStroke:26,closeEOFillStroke:27,endPath:28,clip:29,eoClip:30,beginText:31,endText:32,setCharSpacing:33,setWordSpacing:34,setHScale:35,setLeading:36,setFont:37,setTextRenderingMode:38,setTextRise:39,moveText:40,setLeadingMoveText:41,setTextMatrix:42,nextLine:43,showText:44,showSpacedText:45,nextLineShowText:46,nextLineSetSpacingShowText:47,setCharWidth:48,setCharWidthAndBounds:49,setStrokeColorSpace:50,setFillColorSpace:51,setStrokeColor:52,setStrokeColorN:53,setFillColor:54,setFillColorN:55,setStrokeGray:56,setFillGray:57,setStrokeRGBColor:58,setFillRGBColor:59,setStrokeCMYKColor:60,setFillCMYKColor:61,shadingFill:62,beginInlineImage:63,beginImageData:64,endInlineImage:65,paintXObject:66,markPoint:67,markPointProps:68,beginMarkedContent:69,beginMarkedContentProps:70,endMarkedContent:71,beginCompat:72,endCompat:73,paintFormXObjectBegin:74,paintFormXObjectEnd:75,beginGroup:76,endGroup:77,beginAnnotation:80,endAnnotation:81,paintImageMaskXObject:83,paintImageMaskXObjectGroup:84,paintImageXObject:85,paintInlineImageXObject:86,paintInlineImageXObjectGroup:87,paintImageXObjectRepeat:88,paintImageMaskXObjectRepeat:89,paintSolidColorImageMask:90,constructPath:91,setStrokeTransparent:92,setFillTransparent:93,rawFillPath:94},S={moveTo:0,lineTo:1,curveTo:2,quadraticCurveTo:3,closePath:4},C={NEED_PASSWORD:1,INCORRECT_PASSWORD:2},w=b.WARNINGS;function T(e){Number.isInteger(e)&&(w=e)}function E(){return w}function D(e){w>=b.INFOS&&console.info(`Info: ${e}`)}function O(e){w>=b.WARNINGS&&console.warn(`Warning: ${e}`)}function k(e){throw Error(e)}function A(e,t){e||k(t)}function j(e){switch(e?.protocol){case`http:`:case`https:`:case`ftp:`:case`mailto:`:case`tel:`:return!0;default:return!1}}function M(e,t=null,n=null){if(!e)return null;if(n&&typeof e==`string`&&(n.addDefaultProtocol&&e.startsWith(`www.`)&&e.match(/\./g)?.length>=2&&(e=`http://${e}`),n.tryConvertEncoding))try{e=oe(e)}catch{}let r=t?URL.parse(e,t):URL.parse(e);return j(r)?r:null}function N(e,t,n=!1){let r=URL.parse(e);return r?(r.hash=t,r.href):n&&M(e,`http://example.com`)?e.split(`#`,1)[0]+`${t?`#${t}`:``}`:``}function P(e){return e.substring(e.lastIndexOf(`/`)+1)}function F(e,t,n,r=!1){return Object.defineProperty(e,t,{value:n,enumerable:!r,configurable:!0,writable:!1}),n}var I=function(){function e(e,t){this.message=e,this.name=t}return e.prototype=Error(),e.constructor=e,e}(),L=class extends I{constructor(e,t){super(e,`PasswordException`),this.code=t}},R=class extends I{constructor(e,t){super(e,`UnknownErrorException`),this.details=t}},ee=class extends I{constructor(e){super(e,`InvalidPDFException`)}},te=class extends I{constructor(e,t,n){super(e,`ResponseException`),this.status=t,this.missing=n}},ne=class extends I{constructor(e){super(e,`FormatError`)}},re=class extends I{constructor(e){super(e,`AbortException`)}};function ie(e){(typeof e!=`object`||e?.length===void 0)&&k(`Invalid argument for bytesToString`);let t=e.length,n=8192;if(t`u`)return F(this,`isAlphaColorInputSupported`,!1);let e=document.createElement(`input`);return e.type=`color`,e.setAttribute(`alpha`,``),e.value=`#ff000080`,F(this,`isAlphaColorInputSupported`,e.value!==`#ff0000`)}static get isBackdropFilterSupported(){return F(this,`isBackdropFilterSupported`,typeof CSS<`u`&&CSS.supports(`backdrop-filter`,`blur(1px)`))}},B=class{static get hexNums(){return F(this,`hexNums`,Array.from(Array(256).keys(),e=>e.toString(16).padStart(2,`0`)))}static makeHexColor(e,t,n){return`#${this.hexNums[e]}${this.hexNums[t]}${this.hexNums[n]}`}static transform(e,t){return[e[0]*t[0]+e[2]*t[1],e[1]*t[0]+e[3]*t[1],e[0]*t[2]+e[2]*t[3],e[1]*t[2]+e[3]*t[3],e[0]*t[4]+e[2]*t[5]+e[4],e[1]*t[4]+e[3]*t[5]+e[5]]}static multiplyByDOMMatrix(e,t){return[e[0]*t.a+e[2]*t.b,e[1]*t.a+e[3]*t.b,e[0]*t.c+e[2]*t.d,e[1]*t.c+e[3]*t.d,e[0]*t.e+e[2]*t.f+e[4],e[1]*t.e+e[3]*t.f+e[5]]}static applyTransform(e,t,n=0){let r=e[n],i=e[n+1];e[n]=r*t[0]+i*t[2]+t[4],e[n+1]=r*t[1]+i*t[3]+t[5]}static applyTransformToBezier(e,t,n=0){let r=t[0],i=t[1],a=t[2],o=t[3],s=t[4],c=t[5];for(let t=0;t<6;t+=2){let l=e[n+t],u=e[n+t+1];e[n+t]=l*r+u*a+s,e[n+t+1]=l*i+u*o+c}}static applyInverseTransform(e,t){let n=e[0],r=e[1],i=t[0]*t[3]-t[1]*t[2];e[0]=(n*t[3]-r*t[2]+t[2]*t[5]-t[4]*t[3])/i,e[1]=(-n*t[1]+r*t[0]+t[4]*t[1]-t[5]*t[0])/i}static axialAlignedBoundingBox(e,t,n){let r=t[0],i=t[1],a=t[2],o=t[3],s=t[4],c=t[5],l=e[0],u=e[1],d=e[2],f=e[3],p=r*l+s,m=p,h=r*d+s,g=h,_=o*u+c,v=_,y=o*f+c,b=y;if(i!==0||a!==0){let e=i*l,t=i*d,n=a*u,r=a*f;p+=n,g+=n,h+=r,m+=r,_+=e,b+=e,y+=t,v+=t}n[0]=Math.min(n[0],p,h,m,g),n[1]=Math.min(n[1],_,y,v,b),n[2]=Math.max(n[2],p,h,m,g),n[3]=Math.max(n[3],_,y,v,b)}static inverseTransform(e){let t=e[0]*e[3]-e[1]*e[2];return[e[3]/t,-e[1]/t,-e[2]/t,e[0]/t,(e[2]*e[5]-e[4]*e[3])/t,(e[4]*e[1]-e[5]*e[0])/t]}static singularValueDecompose2dScale(e,t){let n=e[0],r=e[1],i=e[2],a=e[3],o=n**2+r**2,s=n*i+r*a,c=i**2+a**2,l=(o+c)/2,u=Math.sqrt(l**2-(o*c-s**2));t[0]=Math.sqrt(l+u||1),t[1]=Math.sqrt(l-u||1)}static normalizeRect(e){let t=e.slice(0);return e[0]>e[2]&&(t[0]=e[2],t[2]=e[0]),e[1]>e[3]&&(t[1]=e[3],t[3]=e[1]),t}static intersect(e,t){let n=Math.max(Math.min(e[0],e[2]),Math.min(t[0],t[2])),r=Math.min(Math.max(e[0],e[2]),Math.max(t[0],t[2]));if(n>r)return null;let i=Math.max(Math.min(e[1],e[3]),Math.min(t[1],t[3])),a=Math.min(Math.max(e[1],e[3]),Math.max(t[1],t[3]));return i>a?null:[n,i,r,a]}static pointBoundingBox(e,t,n){n[0]=Math.min(n[0],e),n[1]=Math.min(n[1],t),n[2]=Math.max(n[2],e),n[3]=Math.max(n[3],t)}static rectBoundingBox(e,t,n,r,i){i[0]=Math.min(i[0],e,n),i[1]=Math.min(i[1],t,r),i[2]=Math.max(i[2],e,n),i[3]=Math.max(i[3],t,r)}static#e(e,t,n,r,i,a,o,s,c,l){if(c<=0||c>=1)return;let u=1-c,d=c*c,f=d*c,p=u*(u*(u*e+3*c*t)+3*d*n)+f*r,m=u*(u*(u*i+3*c*a)+3*d*o)+f*s;l[0]=Math.min(l[0],p),l[1]=Math.min(l[1],m),l[2]=Math.max(l[2],p),l[3]=Math.max(l[3],m)}static#t(e,t,n,r,i,a,o,s,c,l,u,d){if(Math.abs(c)<1e-12){Math.abs(l)>=1e-12&&this.#e(e,t,n,r,i,a,o,s,-u/l,d);return}let f=l**2-4*u*c;if(f<0)return;let p=Math.sqrt(f),m=2*c;this.#e(e,t,n,r,i,a,o,s,(-l+p)/m,d),this.#e(e,t,n,r,i,a,o,s,(-l-p)/m,d)}static bezierBoundingBox(e,t,n,r,i,a,o,s,c){c[0]=Math.min(c[0],e,o),c[1]=Math.min(c[1],t,s),c[2]=Math.max(c[2],e,o),c[3]=Math.max(c[3],t,s),this.#t(e,n,i,o,t,r,a,s,3*(-e+3*(n-i)+o),6*(e-2*n+i),3*(n-e),c),this.#t(e,n,i,o,t,r,a,s,3*(-t+3*(r-a)+s),6*(t-2*r+a),3*(r-t),c)}};function oe(e){return decodeURIComponent(escape(e))}var se=null,ce=null;function le(e){return se||(se=/([\u00a0\u00b5\u037e\u0eb3\u2000-\u200a\u202f\u2126\ufb00-\ufb04\ufb06\ufb20-\ufb36\ufb38-\ufb3c\ufb3e\ufb40\ufb41\ufb43\ufb44\ufb46-\ufba1\ufba4-\ufba9\ufbae-\ufbb1\ufbd3-\ufbdc\ufbde-\ufbe7\ufbea-\ufbf8\ufbfc\ufbfd\ufc00-\ufc5d\ufc64-\ufcf1\ufcf5-\ufd3d\ufd88\ufdf4\ufdfa\ufdfb\ufe71\ufe77\ufe79\ufe7b\ufe7d]+)|(\ufb05+)/gu,ce=new Map([[`ſt`,`ſt`]])),e.replaceAll(se,(e,t,n)=>t?t.normalize(`NFKC`):ce.get(n))}function ue(){if(typeof crypto.randomUUID==`function`)return crypto.randomUUID();let e=new Uint8Array(32);return crypto.getRandomValues(e),ie(e)}function de(e,t,n){if(!Array.isArray(n)||n.length<2)return!1;let[r,i,...a]=n;if(!e(r)&&!Number.isInteger(r)||!t(i))return!1;let o=a.length,s=!0;switch(i.name){case`XYZ`:if(o<2||o>3)return!1;break;case`Fit`:case`FitB`:return o===0;case`FitH`:case`FitBH`:case`FitV`:case`FitBV`:if(o>1)return!1;break;case`FitR`:if(o!==4)return!1;s=!1;break;default:return!1}for(let e of a)if(!(typeof e==`number`||s&&e===null))return!1;return!0}var fe=()=>[],pe=()=>new Map,me=()=>Object.create(null),he=()=>new Set;typeof Blob.prototype.bytes!=`function`&&(Blob.prototype.bytes=async function(){return new Uint8Array(await this.arrayBuffer())}),typeof Response.prototype.bytes!=`function`&&(Response.prototype.bytes=async function(){return new Uint8Array(await this.arrayBuffer())}),typeof Iterator.prototype.join!=`function`&&(Iterator.prototype.join=function(e){return[...this].join(e)}),r(1701);function V(e,t,n){return Math.min(Math.max(e,t),n)}var ge=class e{constructor({viewBox:e,userUnit:t,scale:n,rotation:r,offsetX:i=0,offsetY:a=0,dontFlip:o=!1}){this.viewBox=e,this.userUnit=t,this.scale=n,this.rotation=r,this.offsetX=i,this.offsetY=a,n*=t;let s=(e[2]+e[0])/2,c=(e[3]+e[1])/2,l,u,d,f;switch(r%=360,r<0&&(r+=360),r){case 180:l=-1,u=0,d=0,f=1;break;case 90:l=0,u=1,d=1,f=0;break;case 270:l=0,u=-1,d=-1,f=0;break;case 0:l=1,u=0,d=0,f=-1;break;default:throw Error(`PageViewport: Invalid rotation, must be a multiple of 90 degrees.`)}o&&(d=-d,f=-f);let p,m,h,g;l===0?(p=Math.abs(c-e[1])*n+i,m=Math.abs(s-e[0])*n+a,h=(e[3]-e[1])*n,g=(e[2]-e[0])*n):(p=Math.abs(s-e[0])*n+i,m=Math.abs(c-e[1])*n+a,h=(e[2]-e[0])*n,g=(e[3]-e[1])*n),this.transform=[l*n,u*n,d*n,f*n,p-l*n*s-d*n*c,m-u*n*s-f*n*c],this.width=h,this.height=g}get rawDims(){let e=this.viewBox;return F(this,`rawDims`,{pageWidth:e[2]-e[0],pageHeight:e[3]-e[1],pageX:e[0],pageY:e[1]})}clone({scale:t=this.scale,rotation:n=this.rotation,offsetX:r=this.offsetX,offsetY:i=this.offsetY,dontFlip:a=!1}={}){return new e({viewBox:this.viewBox.slice(),userUnit:this.userUnit,scale:t,rotation:n,offsetX:r,offsetY:i,dontFlip:a})}convertToViewportPoint(e,t){let n=[e,t];return B.applyTransform(n,this.transform),n}convertToPdfPoint(e,t){let n=[e,t];return B.applyInverseTransform(n,this.transform),n}},_e=class e{static textContent(t){let n=[],r={items:n,styles:Object.create(null)};function i(t){if(!t)return;let r=null,a=t.name;if(a===`#text`)r=t.value;else if(e.shouldBuildText(a))t?.attributes?.textContent?r=t.attributes.textContent:t.value&&(r=t.value);else return;if(r!==null&&n.push({str:r}),t.children)for(let e of t.children)i(e)}return i(t),r}static shouldBuildText(e){return!(e===`textarea`||e===`input`||e===`option`||e===`select`)}},ve=/url\(|image-set\(/i,ye=/^on/i,be=class{static get _allowedHtmlElements(){return F(this,`_allowedHtmlElements`,new Set([`a`,`b`,`br`,`button`,`div`,`i`,`img`,`input`,`label`,`li`,`ol`,`option`,`p`,`select`,`span`,`sub`,`sup`,`textarea`,`ul`]))}static get _allowedSvgElements(){return F(this,`_allowedSvgElements`,new Set([`ellipse`,`line`,`path`,`rect`,`svg`]))}static get _allowedRichTextElements(){return F(this,`_allowedRichTextElements`,new Set([`a`,`b`,`br`,`div`,`i`,`li`,`ol`,`p`,`span`,`sub`,`sup`,`ul`]))}static get _allowedRichTextAttributes(){return F(this,`_allowedRichTextAttributes`,new Set([`class`,`dir`,`style`]))}static get _allowedRichTextStyles(){return F(this,`_allowedRichTextStyles`,new Set(`color.font.fontFamily.fontSize.fontStretch.fontStyle.fontWeight.kerningMode.letterSpacing.lineHeight.margin.marginBottom.marginLeft.marginRight.marginTop.orphans.paddingLeft.paddingRight.breakAfter.breakBefore.breakInside.tabInterval.tabStop.textAlign.textDecoration.textIndent.transform.verticalAlign.widows`.split(`.`)))}static setupStorage(e,t,n,r,i){let a=r.getValue(t,{value:null});switch(n.name){case`textarea`:if(a.value!==null&&(e.textContent=a.value),i===`print`)break;e.addEventListener(`input`,e=>{r.setValue(t,{value:e.target.value})});break;case`input`:if(n.attributes.type===`radio`||n.attributes.type===`checkbox`){if(a.value===n.attributes.xfaOn?e.setAttribute(`checked`,!0):a.value===n.attributes.xfaOff&&e.removeAttribute(`checked`),i===`print`)break;e.addEventListener(`change`,e=>{r.setValue(t,{value:e.target.checked?e.target.getAttribute(`xfaOn`):e.target.getAttribute(`xfaOff`)})})}else{if(a.value!==null&&e.setAttribute(`value`,a.value),i===`print`)break;e.addEventListener(`input`,e=>{r.setValue(t,{value:e.target.value})})}break;case`select`:if(a.value!==null){e.setAttribute(`value`,a.value);for(let e of n.children)e.attributes.value===a.value?e.attributes.selected=!0:Object.hasOwn(e.attributes,`selected`)&&delete e.attributes.selected}e.addEventListener(`input`,e=>{let n=e.target.options,i=n.selectedIndex===-1?``:n[n.selectedIndex].value;r.setValue(t,{value:i})});break}}static setAttributes({html:e,element:t,storage:n=null,intent:r,linkService:i}){let{attributes:a}=t,o=e instanceof HTMLAnchorElement;a.type===`radio`&&(a.name=`${a.name}-${r}`);for(let[t,n]of Object.entries(a))if(n!=null&&!ye.test(t)&&!(r===`richText`&&!this._allowedRichTextAttributes.has(t)))switch(t){case`class`:n.length&&e.setAttribute(t,n.join(` `));break;case`dataId`:break;case`id`:e.setAttribute(`data-element-id`,n);break;case`style`:if(r===`richText`){let t=this._allowedRichTextStyles;for(let[r,i]of Object.entries(n))t.has(r)&&!ve.test(i)&&(e.style[r]=i)}else Object.assign(e.style,n);break;case`textContent`:e.textContent=n;break;default:(!o||t!==`href`&&t!==`newWindow`)&&e.setAttribute(t,n)}o&&i?.addLinkAttributes(e,a.href,a.newWindow),n&&a.dataId&&this.setupStorage(e,a.dataId,t,n)}static#e(e,t,n){return n===`richText`?!t&&this._allowedRichTextElements.has(e)?document.createElement(e):null:t?t===c&&this._allowedSvgElements.has(e)?document.createElementNS(c,e):null:this._allowedHtmlElements.has(e)?document.createElement(e):null}static render(e){let t=e.annotationStorage,n=e.linkService,r=e.xfaHtml,i=e.intent||`display`,a=this.#e(r.name,r.attributes?.xmlns,i)??document.createElement(`div`);r.attributes&&this.setAttributes({html:a,element:r,intent:i,linkService:n});let o=i!==`richText`,s=e.div;if(s.append(a),e.viewport){let t=`matrix(${e.viewport.transform.join(`,`)})`;s.style.transform=t}o&&s.setAttribute(`class`,`xfaLayer xfaFont`);let c=[];if(r.children.length===0){if(r.value){let e=document.createTextNode(r.value);a.append(e),o&&_e.shouldBuildText(r.name)&&c.push(e)}return{textDivs:c}}let l=[[r,-1,a]];for(;l.length>0;){let[e,r,a]=l.at(-1);if(r+1===e.children.length){l.pop();continue}let s=e.children[++l.at(-1)[1]];if(s===null)continue;let{name:u}=s;if(u===`#text`){let e=document.createTextNode(s.value);c.push(e),a.append(e);continue}let d=this.#e(u,s.attributes?.xmlns,i);if(d){if(a.append(d),s.attributes&&this.setAttributes({html:d,element:s,storage:t,intent:i,linkService:n}),s.children?.length>0)l.push([s,-1,d]);else if(s.value){let e=document.createTextNode(s.value);o&&_e.shouldBuildText(u)&&c.push(e),d.append(e)}}}for(let e of s.querySelectorAll(`.xfaNonInteractive input, .xfaNonInteractive textarea`))e.setAttribute(`readOnly`,!0);return{textDivs:c}}static update(e){let t=`matrix(${e.viewport.transform.join(`,`)})`;e.div.style.transform=t,e.div.hidden=!1}static getPageViewport(e,{scale:t=1,rotation:n=0}){let{width:r,height:i}=e.attributes.style;return new ge({viewBox:[0,0,parseInt(r,10),parseInt(i,10)],userUnit:1,scale:t,rotation:n})}},xe=class{static CSS=96;static PDF=72;static PDF_TO_CSS_UNITS=this.CSS/this.PDF};async function Se(e,t=`text`){if(ke(e,document.baseURI)){let n=await fetch(e);if(!n.ok)throw Error(n.statusText);switch(t){case`blob`:return n.blob();case`bytes`:return n.bytes();case`json`:return n.json()}return n.text()}return new Promise((n,r)=>{let i=new XMLHttpRequest;i.open(`GET`,e,!0),i.responseType=t===`bytes`?`arraybuffer`:t,i.onreadystatechange=()=>{if(i.readyState===XMLHttpRequest.DONE){if(i.status===200||i.status===0){switch(t){case`bytes`:n(new Uint8Array(i.response));return;case`blob`:case`json`:n(i.response);return}n(i.responseText);return}r(Error(i.statusText))}},i.send(null)})}var Ce=class extends I{constructor(e,t=0){super(e,`RenderingCancelledException`),this.extraDelay=t}};function we(e){let t=e.length,n=0;for(;n{try{return new URL(e)}catch{}try{return new URL(decodeURIComponent(e))}catch{}try{return new URL(e,`https://foo.bar`)}catch{}try{return new URL(decodeURIComponent(e),`https://foo.bar`)}catch{}return null})(e);if(!n)return t;let r=e=>{try{let t=decodeURIComponent(e);return t.includes(`/`)&&(t=P(t),t.length===4&&i.test(t))?e:t}catch{return e}},i=/\.pdf$/i,a=P(n.pathname);if(i.test(a))return r(a);if(n.searchParams.size>0){let e=e=>[...e].findLast(e=>i.test(e)),t=e(n.searchParams.values())??e(n.searchParams.keys());if(t)return r(t)}if(n.hash){let e=/[^/?#=]+\.pdf\b(?!.*\.pdf\b)/i.exec(n.hash);if(e)return r(e[0])}return t}var Oe=class{#e=new Map;times=[];time(e){this.#e.has(e)&&O(`Timer is already running for ${e}`),this.#e.set(e,Date.now())}timeEnd(e){this.#e.has(e)||O(`Timer has not been started for ${e}`),this.times.push({name:e,start:this.#e.get(e),end:Date.now()}),this.#e.delete(e)}toString(){let e=Math.max(...this.times.map(e=>e.name.length));return this.times.map(t=>`${t.name.padEnd(e)} ${t.end-t.start}ms\n`).join(``)}};function ke(e,t){let n=t?URL.parse(e,t):URL.parse(e);return/https?:/.test(n?.protocol??``)}function H(e){e.preventDefault()}function U(e){e.preventDefault(),e.stopPropagation()}var Ae=class{static#e;static toDateObject(e){if(e instanceof Date)return e;if(!e||typeof e!=`string`)return null;this.#e||=RegExp(`^D:(\\d{4})(\\d{2})?(\\d{2})?(\\d{2})?(\\d{2})?(\\d{2})?([Z|+\\-])?(\\d{2})?'?(\\d{2})?'?`);let t=this.#e.exec(e);if(!t)return null;let n=parseInt(t[1],10),r=parseInt(t[2],10);r=r>=1&&r<=12?r-1:0;let i=parseInt(t[3],10);i=i>=1&&i<=31?i:1;let a=parseInt(t[4],10);a=a>=0&&a<=23?a:0;let o=parseInt(t[5],10);o=o>=0&&o<=59?o:0;let s=parseInt(t[6],10);s=s>=0&&s<=59?s:0;let c=t[7]||`Z`,l=parseInt(t[8],10);l=l>=0&&l<=23?l:0;let u=parseInt(t[9],10)||0;return u=u>=0&&u<=59?u:0,c===`-`?(a+=l,o+=u):c===`+`&&(a-=l,o-=u),new Date(Date.UTC(n,r,i,a,o,s))}};function je(e){if(e.startsWith(`#`)){let t=e.slice(1);return[parseInt(t.slice(0,2),16),parseInt(t.slice(2,4),16),parseInt(t.slice(4,6),16),t.length>=8?parseInt(t.slice(6,8),16)/255:1]}if(e.startsWith(`rgb(`)){let[t,n,r]=e.slice(4,-1).split(`,`).map(e=>parseInt(e,10));return[t,n,r,1]}if(e.startsWith(`rgba(`)){let t=e.slice(5,-1).split(`,`);return[parseInt(t[0],10),parseInt(t[1],10),parseInt(t[2],10),parseFloat(t[3])]}let t=e.match(/^color\(srgb\s+([\d.]+)\s+([\d.]+)\s+([\d.]+)(?:\s*\/\s*([\d.]+|none))?\)$/);return t?[Math.round(parseFloat(t[1])*255),Math.round(parseFloat(t[2])*255),Math.round(parseFloat(t[3])*255),t[4]!==void 0&&t[4]!==`none`?parseFloat(t[4]):1]:null}function Me(e){let t=je(e);return t?t.slice(0,3):(O(`Not a valid color format: "${e}"`),[0,0,0])}function Ne(e){let t=document.createElement(`span`);t.style.visibility=`hidden`,t.style.colorScheme=`only light`,document.body.append(t);for(let n of e.keys()){t.style.color=n;let r=window.getComputedStyle(t).color;e.set(n,Me(r))}t.remove()}function W(e){let{a:t,b:n,c:r,d:i,e:a,f:o}=e.getTransform();return[t,n,r,i,a,o]}function Pe(e){let{a:t,b:n,c:r,d:i,e:a,f:o}=e.getTransform().invertSelf();return[t,n,r,i,a,o]}function Fe(e,t,n=!1,r=!0){if(t instanceof ge){let{pageWidth:r,pageHeight:i}=t.rawDims,{style:a}=e,o=`round(down, var(--total-scale-factor) * ${r}px, var(--scale-round-x))`,s=`round(down, var(--total-scale-factor) * ${i}px, var(--scale-round-y))`;!n||t.rotation%180==0?(a.width=o,a.height=s):(a.width=s,a.height=o)}r&&e.setAttribute(`data-main-rotation`,t.rotation)}var Ie=class e{constructor(){let{pixelRatio:t}=e;this.sx=t,this.sy=t}get scaled(){return this.sx!==1||this.sy!==1}get symmetric(){return this.sx===this.sy}limitCanvas(t,n,r,i,a=-1){let o=1/0,s=1/0,c=1/0;r=e.capPixels(r,a),r>0&&(o=Math.sqrt(r/(t*n))),i!==-1&&(s=i/t,c=i/n);let l=Math.min(o,s,c);return this.sx>l||this.sy>l?(this.sx=l,this.sy=l,!0):!1}static get pixelRatio(){return globalThis.devicePixelRatio||1}static capPixels(e,t){if(t>=0){let n=Math.ceil(window.screen.availWidth*window.screen.availHeight*this.pixelRatio**2*(1+t/100));return e>0?Math.min(e,n):n}return e}},Le=[`image/apng`,`image/avif`,`image/bmp`,`image/gif`,`image/jpeg`,`image/png`,`image/svg+xml`,`image/webp`,`image/x-icon`],Re=class{static get isDarkMode(){return F(this,`isDarkMode`,!!window?.matchMedia?.(`(prefers-color-scheme: dark)`).matches)}},ze=class{static get commentForegroundColor(){let e=document.createElement(`span`);e.classList.add(`comment`,`sidebar`);let{style:t}=e;t.width=t.height=`0`,t.display=`none`,t.color=`var(--comment-fg-color)`,document.body.append(e);let{color:n}=window.getComputedStyle(e);return e.remove(),F(this,`commentForegroundColor`,Me(n))}};function Be(e,t){t=V(t??1,0,1);let n=255*(1-t);return e.map(e=>Math.round(e*t+n))}function Ve(e,t){let n=e[0]/255,r=e[1]/255,i=e[2]/255,a=Math.max(n,r,i),o=Math.min(n,r,i),s=(a+o)/2;if(a===o)t[0]=t[1]=0;else{let e=a-o;switch(t[1]=s<.5?e/(a+o):e/(2-a-o),a){case n:t[0]=((r-i)/e+(ri?(r+.05)/(i+.05):(i+.05)/(r+.05)}var Ge=new Map;function Ke(e,t){let n=e[0]+e[1]*256+e[2]*65536+t[0]*16777216+t[1]*4294967296+t[2]*1099511627776,r=Ge.get(n);if(r)return r;let i=new Float32Array(9),a=i.subarray(0,3),o=i.subarray(3,6);Ve(e,o);let s=i.subarray(6,9);Ve(t,s);let c=s[2]<.5,l=c?12:4.5;if(o[2]=c?Math.sqrt(o[2]):1-Math.sqrt(1-o[2]),We(o,s,a).005;){let n=o[2]=(e+t)/2;c===We(o,s,a){n.delete()},{signal:n._signal}),this.#r.append(r)}get#p(){let e=document.createElement(`div`);return e.className=`divider`,e}async addAltText(e){let t=await e.render();this.#f(t),this.#r.append(t,this.#p),this.#i=e}addComment(e,t=null){if(this.#a)return;let n=e.renderForToolbar();if(!n)return;this.#f(n);let r=this.#o=this.#p;t?(this.#r.insertBefore(n,t),this.#r.insertBefore(r,t)):this.#r.append(n,r),this.#a=e,e.toolbar=this}addColorPicker(e){if(this.#t)return;this.#t=e;let t=e.renderButton();this.#f(t),this.#r.append(t,this.#p)}async addEditSignatureButton(e){let t=this.#s=await e.renderEditButton(this.#n);this.#f(t),this.#r.append(t,this.#p)}removeButton(e){switch(e){case`comment`:this.#a?.removeToolbarCommentButton(),this.#a=null,this.#o?.remove(),this.#o=null;break}}async addButton(e,t){switch(e){case`colorPicker`:t&&this.addColorPicker(t);break;case`altText`:t&&await this.addAltText(t);break;case`editSignature`:t&&await this.addEditSignatureButton(t);break;case`delete`:this.addDeleteButton();break;case`comment`:t&&this.addComment(t);break}}async addButtonBefore(e,t,n){if(!t&&e===`comment`)return;let r=this.#r.querySelector(n);r&&e===`comment`&&this.addComment(t,r)}updateEditSignatureButton(e){this.#s&&(this.#s.title=e)}remove(){this.#e.remove(),this.#t?.destroy(),this.#t=null}},Xe=class{#e=null;#t=null;#n;constructor(e){this.#n=e}#r(){let e=this.#t=document.createElement(`div`);e.className=`editToolbar`,e.setAttribute(`role`,`toolbar`);let t=this.#n._signal;t instanceof AbortSignal&&!t.aborted&&e.addEventListener(`contextmenu`,H,{signal:t});let n=this.#e=document.createElement(`div`);return n.className=`buttons`,e.append(n),this.#n.hasCommentManager()&&this.#a(`commentButton`,`pdfjs-comment-floating-button`,`pdfjs-comment-floating-button-label`,()=>{this.#n.commentSelection(`floating_button`)}),this.#a(`highlightButton`,`pdfjs-highlight-floating-button1`,`pdfjs-highlight-floating-button-label`,()=>{this.#n.highlightSelection(`floating_button`)}),e}#i(e,t){let n=0,r=0;for(let i of e){let e=i.y+i.height;if(en){r=a,n=e;continue}t?a>r&&(r=a):a=1}static clearPointerType(){e.#r=null}static clearPointerIds(){e.#e=NaN,e.#t=null}static clearTimeStamp(){e.#n=NaN}},$e=class{#e=0;get id(){return`${f}${this.#e++}`}},et=class e{#e=ue();#t=0;#n=null;static get _isSVGFittingCanvas(){let e=`data:image/svg+xml;charset=UTF-8,`,t=new OffscreenCanvas(1,3).getContext(`2d`,{willReadFrequently:!0}),n=new Image;n.src=e;let r=n.decode().then(()=>(t.drawImage(n,0,0,1,1,0,0,1,3),new Uint32Array(t.getImageData(0,0,1,1).data.buffer)[0]===0));return F(this,`_isSVGFittingCanvas`,r)}async#r(t,n){this.#n||=new Map;let r=this.#n.get(t);if(r===null)return null;if(r?.bitmap)return r.refCounter+=1,r;try{r||={bitmap:null,id:`image_${this.#e}_${this.#t++}`,refCounter:0,isSvg:!1};let t;if(typeof n==`string`?(r.url=n,t=await Se(n,`blob`)):n instanceof File?t=r.file=n:n instanceof Blob&&(t=n),t.type===`image/svg+xml`){let n=e._isSVGFittingCanvas,i=new FileReader,a=new Image,o=new Promise((e,t)=>{a.onload=()=>{r.bitmap=a,r.isSvg=!0,e()},i.onload=async()=>{let e=r.svgUrl=i.result;a.src=await n?`${e}#svgView(preserveAspectRatio(none))`:e},a.onerror=i.onerror=t});i.readAsDataURL(t),await o}else r.bitmap=await createImageBitmap(t);r.refCounter=1}catch(e){O(e),r=null}return this.#n.set(t,r),r&&this.#n.set(r.id,r),r}async getFromFile(e){let{lastModified:t,name:n,size:r,type:i}=e;return this.#r(`${t}_${n}_${r}_${i}`,e)}async getFromUrl(e){return this.#r(e,e)}async getFromBlob(e,t){let n=await t;return this.#r(e,n)}async getFromId(e){this.#n||=new Map;let t=this.#n.get(e);if(!t)return null;if(t.bitmap)return t.refCounter+=1,t;if(t.file)return this.getFromFile(t.file);if(t.blobPromise){let{blobPromise:e}=t;return delete t.blobPromise,this.getFromBlob(t.id,e)}return this.getFromUrl(t.url)}getFromCanvas(e,t){this.#n||=new Map;let n=this.#n.get(e);if(n?.bitmap)return n.refCounter+=1,n;let r=new OffscreenCanvas(t.width,t.height);return r.getContext(`2d`).drawImage(t,0,0),n={bitmap:r.transferToImageBitmap(),id:`image_${this.#e}_${this.#t++}`,refCounter:1,isSvg:!1},this.#n.set(e,n),this.#n.set(n.id,n),n}getSvgUrl(e){let t=this.#n.get(e);return t?.isSvg?t.svgUrl:null}deleteId(e){this.#n||=new Map;let t=this.#n.get(e);if(!t||(--t.refCounter,t.refCounter!==0))return;let{bitmap:n}=t;if(!t.url&&!t.file){let e=new OffscreenCanvas(n.width,n.height);e.getContext(`bitmaprenderer`).transferFromImageBitmap(n),t.blobPromise=e.convertToBlob()}n.close?.(),t.bitmap=null}isValidId(e){return e.startsWith(`image_${this.#e}_`)}},tt=class{#e=[];#t=!1;#n;#r=-1;constructor(e=128){this.#n=e}add({cmd:e,undo:t,post:n,mustExec:r,type:i=NaN,overwriteIfSameType:a=!1,keepUndo:o=!1}){if(r&&e(),this.#t)return;let s={cmd:e,undo:t,post:n,type:i};if(this.#r===-1){this.#e.length>0&&(this.#e.length=0),this.#r=0,this.#e.push(s);return}if(a&&this.#e[this.#r].type===i){o&&(s.undo=this.#e[this.#r].undo),this.#e[this.#r]=s;return}let c=this.#r+1;c===this.#n?this.#e.splice(0,1):(this.#r=c,c=0;t--)if(this.#e[t].type!==e){this.#e.splice(t+1,this.#r-t),this.#r=t;return}this.#e.length=0,this.#r=-1}}destroy(){this.#e=null}},nt=class e{static ALT=1;static CTRL=2;static META=4;static SHIFT=8;constructor(t){this.callbacks=new Map;let{isMac:n}=z.platform;for(let[r,i,a={}]of t){let t=r.some(e=>e.startsWith(`mac+`));for(let o of r){let r=o;if(t){let e=o.startsWith(`mac+`);if(n!==e)continue;e&&(r=o.slice(4))}let[s,c]=e.#e(r);s!==null&&this.callbacks.getOrInsertComputed(s,fe).push({callback:i,options:a,modifiers:c})}}}static#e(t){let n=null,r=0;for(let i of t.split(`+`)){if(i=i.trim(),!i)continue;let a=i.toUpperCase(),o=e[a];if(o){r|=o;continue}if(n!==null){O(`KeyboardManager: multiple keys in shortcut "${t}"`);break}n=a===`SPACE`?` `:i}return n===null&&O(`KeyboardManager: no key found in shortcut "${t}"`),[n,r]}static#t(e){let t=/^(?:Key([A-Z])|(?:Digit|Numpad)(\d))$/.exec(e);return t?t[1]?.toLowerCase()??t[2]:null}exec(t,n){let r=this.callbacks.get(n.key);if(!r){if(/^[a-z]$/i.test(n.key))return;let t=e.#t(n.code);if(t===null||t===n.key||(r=this.callbacks.get(t),!r))return}let i=(n.altKey?e.ALT:0)|(n.ctrlKey?e.CTRL:0)|(n.metaKey?e.META:0)|(n.shiftKey?e.SHIFT:0),a=r.find(e=>e.modifiers===i);if(!a)return;let{callback:o,options:{bubbles:s=!1,args:c=[],checker:l=null}}=a;l&&!l(t,n)||(o.bind(t,...c,n)(),s||U(n))}},rt=class e{static _colorsMapping=new Map([[`CanvasText`,[0,0,0]],[`Canvas`,[255,255,255]]]);get _colors(){let e=new Map([[`CanvasText`,null],[`Canvas`,null]]);return Ne(e),F(this,`_colors`,e)}convert(t){let n=Me(t);if(!window.matchMedia(`(forced-colors: active)`).matches)return n;for(let[t,r]of this._colors)if(r.every((e,t)=>e===n[t]))return e._colorsMapping.get(t);return n}getHexCode(e){let t=this._colors.get(e);return t?B.makeHexColor(...t):e}},it=class e{#e=new AbortController;#t=null;#n=null;#r=new Map;#i=new Map;#a=null;#o=null;#s=null;#c=null;#l=new tt;#u=null;#d=null;#f=null;#p=0;#m=new Set;#h=null;#g=null;#_=new Set;_editorUndoBar=null;#v=!1;#y=!1;#b=!1;#x=null;#S=null;#C=null;#w=null;#T=!1;#E=null;#D=new $e;#O=!1;#k=!1;#A=!1;#j=null;#M=null;#N=null;#P=null;#F=null;#I=p.NONE;#L=new Set;#R=null;#z=null;#B=null;#V=null;#H=null;#U={isEditing:!1,isEmpty:!0,hasSomethingToUndo:!1,hasSomethingToRedo:!1,hasSelectedEditor:!1,hasSelectedText:!1};#W=[0,0];#G=null;#K=null;#q=null;#J=null;#Y=null;static TRANSLATE_SMALL=1;static TRANSLATE_BIG=10;static get _keyboardManager(){let t=e.prototype,n=e=>e.#K.contains(document.activeElement)&&document.activeElement.tagName!==`BUTTON`&&e.hasSomethingToControl(),r=(e,{target:t})=>{if(t instanceof HTMLInputElement){let{type:e}=t;return e!==`text`&&e!==`number`}return!0},i=this.TRANSLATE_SMALL,a=this.TRANSLATE_BIG;return F(this,`_keyboardManager`,new nt([[[`ctrl+a`,`mac+meta+a`],t.selectAll,{checker:r}],[[`ctrl+z`,`mac+meta+z`],t.undo,{checker:r}],[[`ctrl+y`,`ctrl+shift+z`,`mac+meta+shift+z`,`ctrl+shift+Z`,`mac+meta+shift+Z`],t.redo,{checker:r}],[[`Backspace`,`alt+Backspace`,`ctrl+Backspace`,`shift+Backspace`,`mac+Backspace`,`mac+alt+Backspace`,`mac+ctrl+Backspace`,`Delete`,`ctrl+Delete`,`shift+Delete`,`mac+Delete`],t.delete,{checker:r}],[[`Enter`],t.addNewEditorFromKeyboard,{checker:(e,{target:t})=>!(t instanceof HTMLButtonElement)&&e.#K.contains(t)&&!e.isEnterHandled}],[[`Space`],t.addNewEditorFromKeyboard,{checker:(e,{target:t})=>!(t instanceof HTMLButtonElement)&&e.#K.contains(document.activeElement)}],[[`Escape`],t.unselectAll],[[`ArrowLeft`],t.translateSelectedEditors,{args:[-i,0],checker:n}],[[`ctrl+ArrowLeft`,`mac+shift+ArrowLeft`],t.translateSelectedEditors,{args:[-a,0],checker:n}],[[`ArrowRight`],t.translateSelectedEditors,{args:[i,0],checker:n}],[[`ctrl+ArrowRight`,`mac+shift+ArrowRight`],t.translateSelectedEditors,{args:[a,0],checker:n}],[[`ArrowUp`],t.translateSelectedEditors,{args:[0,-i],checker:n}],[[`ctrl+ArrowUp`,`mac+shift+ArrowUp`],t.translateSelectedEditors,{args:[0,-a],checker:n}],[[`ArrowDown`],t.translateSelectedEditors,{args:[0,i],checker:n}],[[`ctrl+ArrowDown`,`mac+shift+ArrowDown`],t.translateSelectedEditors,{args:[0,a],checker:n}]]))}constructor(e,t,n,r,i,a,o,s,c,l,u,d,f,p,m,h){let g=this._signal=this.#e.signal;this.#K=e,this.#q=t,this.#J=n,this.#o=r,this.#u=i,this.#z=a,this.#H=s,this._eventBus=o;let _={signal:g,...Ze};o.on(`editingaction`,this.onEditingAction.bind(this),_),o.on(`pagechanging`,this.onPageChanging.bind(this),_),o.on(`scalechanging`,this.onScaleChanging.bind(this),_),o.on(`rotationchanging`,this.onRotationChanging.bind(this),_),o.on(`setpreference`,this.onSetPreference.bind(this),_),o.on(`switchannotationeditorparams`,e=>this.updateParams(e.type,e.value),_),window.addEventListener(`pointerdown`,()=>{this.#k=!0},{capture:!0,signal:g}),window.addEventListener(`pointerup`,()=>{this.#k=!1},{capture:!0,signal:g}),window.addEventListener(`beforeunload`,this.endCurrentEditing.bind(this),{capture:!0,signal:g}),this.#te(),this.#ce(),this.#ie(),this.#s=s.annotationStorage,this.#x=s.filterFactory,this.#B=c,this.#w=l||null,this.#v=u,this.#y=d,this.#b=f,this.#F=p||null,this.viewParameters={realScale:xe.PDF_TO_CSS_UNITS,rotation:0},this.isShiftKeyDown=!1,this._editorUndoBar=m||null,this._supportsPinchToZoom=h!==!1,i?.setSidebarUiManager(this)}destroy(){this.#Y?.resolve(),this.#Y=null,this.#e?.abort(),this.#e=null,this._signal=null;for(let e of this.#i.values())e.destroy();this.#i.clear(),this.#r.clear(),this.#_.clear(),this.#P?.clear(),this.#t=null,this.#L.clear(),this.#l.destroy(),this.#o?.destroy(),this.#u?.destroy(),this.#z?.destroy(),this.#E?.hide(),this.#E=null,this.#N?.destroy(),this.#N=null,this.#n=null,this.#S&&=(clearTimeout(this.#S),null),this.#G&&=(clearTimeout(this.#G),null),this._editorUndoBar?.destroy(),this.#H=null}combinedSignal(e){return AbortSignal.any([this._signal,e.signal])}get mlManager(){return this.#F}get useNewAltTextFlow(){return this.#y}get useNewAltTextWhenAddingImage(){return this.#b}get hcmFilter(){return F(this,`hcmFilter`,this.#B?this.#x.addHCMFilter(this.#B.foreground,this.#B.background):`none`)}get direction(){return F(this,`direction`,getComputedStyle(this.#K).direction)}get _highlightColors(){return F(this,`_highlightColors`,this.#w?new Map(this.#w.split(`,`).map(e=>(e=e.split(`=`).map(e=>e.trim()),e[1]=e[1].toUpperCase(),e))):null)}get highlightColors(){let{_highlightColors:e}=this;if(!e)return F(this,`highlightColors`,null);let t=new Map,n=!!this.#B;for(let[r,i]of e){let e=r.endsWith(`_HCM`);if(n&&e){t.set(r.replace(`_HCM`,``),i);continue}!n&&!e&&t.set(r,i)}return F(this,`highlightColors`,t)}get highlightColorNames(){return F(this,`highlightColorNames`,this.highlightColors?new Map(Array.from(this.highlightColors,e=>e.reverse())):null)}getNonHCMColor(e){if(!this._highlightColors)return e;let t=this.highlightColorNames.get(e);return this._highlightColors.get(t)||e}getNonHCMColorName(e){return this.highlightColorNames.get(e)||e}setCurrentDrawingSession(e){e?(this.unselectAll(),this.disableUserSelect(!0)):this.disableUserSelect(!1),this.#f=e}setMainHighlightColorPicker(e){this.#N=e}editAltText(e,t=!1){this.#o?.editAltText(this,e,t)}hasCommentManager(){return!!this.#u}editComment(e,t,n,r){this.#u?.showDialog(this,e,t,n,r)}selectComment(e,t){(this.#i.get(e)?.getEditorByUID(t))?.toggleComment(!0,!0)}updateComment(e){this.#u?.updateComment(e.getData())}updatePopupColor(e){this.#u?.updatePopupColor(e)}removeComment(e){this.#u?.removeComments([e.uid])}deleteComment(e,t){let n=()=>{e.comment=t};this.addCommands({cmd:()=>{this._editorUndoBar?.show(n,`comment`),this.toggleComment(null),e.comment=null},undo:n,mustExec:!0})}toggleComment(e,t,n=void 0){this.#u?.toggleCommentPopup(e,t,n)}makeCommentColor(e,t){return e&&this.#u?.makeCommentColor(e,t)||null}getCommentDialogElement(){return this.#u?.dialogElement||null}async waitForEditorsRendered(e){if(this.#i.has(e-1))return;let{resolve:t,promise:n}=Promise.withResolvers(),r=n=>{n.pageNumber===e&&(this._eventBus.off(`editorsrendered`,r),t())};this._eventBus.on(`editorsrendered`,r,Ze),await n}getSignature(e){this.#z?.getSignature({uiManager:this,editor:e})}get signatureManager(){return this.#z}switchToMode(e,t){this._eventBus.on(`annotationeditormodechanged`,t,{once:!0,signal:this._signal,...Ze}),this._eventBus.dispatch(`showannotationeditorui`,{source:this,mode:e})}setPreference(e,t){this._eventBus.dispatch(`setpreference`,{source:this,name:e,value:t})}onSetPreference({name:e,value:t}){switch(e){case`enableNewAltTextWhenAddingImage`:this.#b=t;break}}onPageChanging({pageNumber:e}){this.#p=e-1}deletePage(e){for(let t of this.getEditors(e))t.remove();this.#i.delete(e),this.#p===e&&(this.#p=0)}focusMainContainer(){this.#K.focus()}findParent(e,t){for(let n of this.#i.values()){let{x:r,y:i,width:a,height:o}=n.div.getBoundingClientRect();if(e>=r&&e<=r+a&&t>=i&&t<=i+o)return n}return null}disableUserSelect(e=!1){this.#q.classList.toggle(`noUserSelect`,e)}addShouldRescale(e){this.#_.add(e)}removeShouldRescale(e){this.#_.delete(e)}onScaleChanging({scale:e}){this.commitOrRemove(),this.viewParameters.realScale=e*xe.PDF_TO_CSS_UNITS;for(let e of this.#_)e.onScaleChanging();this.#f?.onScaleChanging()}onRotationChanging({pagesRotation:e}){this.commitOrRemove(),this.viewParameters.rotation=e}#X({anchorNode:e}){return e.nodeType===Node.TEXT_NODE?e.parentElement:e}#Z(e){let{currentLayer:t}=this;if(t.hasTextLayer(e))return t;for(let t of this.#i.values())if(t.hasTextLayer(e))return t;return null}highlightSelection(e=``,t=!1){let n=document.getSelection();if(!n||n.isCollapsed)return;let{anchorNode:r,anchorOffset:i,focusNode:a,focusOffset:o}=n,s=n.toString(),c=this.#X(n).closest(`.textLayer`),l=this.getSelectionBoxes(c);if(!l)return;n.empty();let u=this.#Z(c),d=this.#I===p.NONE,f=()=>{let n=u?.createAndAddNewEditor({x:0,y:0},!1,{methodOfCreation:e,boxes:l,anchorNode:r,anchorOffset:i,focusNode:a,focusOffset:o,text:s});d&&this.showAllEditors(`highlight`,!0,!0),t&&n?.editComment()};if(d){this.switchToMode(p.HIGHLIGHT,f);return}f()}commentSelection(e=``){this.highlightSelection(e,!0)}endCurrentEditing(){this.commitOrRemove(),this.currentLayer?.endDrawingSession(!1)}#Q(){let e=document.getSelection();if(!e||e.isCollapsed)return;let t=this.#X(e).closest(`.textLayer`),n=this.getSelectionBoxes(t);n&&(this.#E||=new Xe(this),this.#E.show(t,n,this.direction===`ltr`))}getAndRemoveDataFromAnnotationStorage(e){if(!this.#s)return null;let t=`${f}${e}`,n=this.#s.getRawValue(t);return n&&this.#s.remove(t),n}addToAnnotationStorage(e){!e.isEmpty()&&this.#s&&!this.#s.has(e.id)&&this.#s.setValue(e.id,e)}a11yAlert(e,t=null){let n=this.#J;n&&(n.setAttribute(`data-l10n-id`,e),t?n.setAttribute(`data-l10n-args`,JSON.stringify(t)):n.removeAttribute(`data-l10n-args`))}#$(){let e=document.getSelection();if(!e||e.isCollapsed){this.#R&&(this.#E?.hide(),this.#R=null,this.#le({hasSelectedText:!1}));return}let{anchorNode:t}=e;if(t===this.#R)return;let n=this.#X(e).closest(`.textLayer`);if(!n){this.#R&&(this.#E?.hide(),this.#R=null,this.#le({hasSelectedText:!1}));return}if(this.#E?.hide(),this.#R=t,this.#le({hasSelectedText:!0}),!(this.#I!==p.HIGHLIGHT&&this.#I!==p.NONE)&&(this.#I===p.HIGHLIGHT&&this.showAllEditors(`highlight`,!0,!0),this.#T=this.isShiftKeyDown,!this.isShiftKeyDown)){let e=this.#I===p.HIGHLIGHT?this.#Z(n):null;if(e?.toggleDrawing(),this.#k){let t=new AbortController,n=this.combinedSignal(t),r=n=>{n.type===`pointerup`&&n.button!==0||(t.abort(),e?.toggleDrawing(!0),n.type===`pointerup`&&this.#ee(`main_toolbar`))};window.addEventListener(`pointerup`,r,{signal:n}),window.addEventListener(`blur`,r,{signal:n})}else e?.toggleDrawing(!0),this.#ee(`main_toolbar`)}}#ee(e=``){this.#I===p.HIGHLIGHT?this.highlightSelection(e):this.#v&&this.#Q()}#te(){document.addEventListener(`selectionchange`,this.#$.bind(this),{signal:this._signal})}#ne(){if(this.#C)return;this.#C=new AbortController;let e=this.combinedSignal(this.#C);window.addEventListener(`focus`,this.focus.bind(this),{signal:e}),window.addEventListener(`blur`,this.blur.bind(this),{signal:e})}#re(){this.#C?.abort(),this.#C=null}blur(){if(this.isShiftKeyDown=!1,this.#T&&(this.#T=!1,this.#ee(`main_toolbar`)),!this.hasSelection)return;let{activeElement:e}=document;for(let t of this.#L)if(t.div.contains(e)){this.#M=[t,e],t._focusEventsAllowed=!1;break}}focus(){if(!this.#M)return;let[e,t]=this.#M;this.#M=null,t.addEventListener(`focusin`,()=>{e._focusEventsAllowed=!0},{once:!0,signal:this._signal}),t.focus()}#ie(){if(this.#j)return;this.#j=new AbortController;let e=this.combinedSignal(this.#j);window.addEventListener(`keydown`,this.keydown.bind(this),{signal:e}),window.addEventListener(`keyup`,this.keyup.bind(this),{signal:e})}#ae(){this.#j?.abort(),this.#j=null}#oe(){if(this.#d)return;this.#d=new AbortController;let e=this.combinedSignal(this.#d);document.addEventListener(`copy`,this.copy.bind(this),{signal:e}),document.addEventListener(`cut`,this.cut.bind(this),{signal:e}),document.addEventListener(`paste`,this.paste.bind(this),{signal:e})}#se(){this.#d?.abort(),this.#d=null}#ce(){let e=this._signal;document.addEventListener(`dragover`,this.dragOver.bind(this),{signal:e}),document.addEventListener(`drop`,this.drop.bind(this),{signal:e})}addEditListeners(){this.#ie(),this.setEditingState(!0)}removeEditListeners(){this.#ae(),this.setEditingState(!1)}dragOver(e){for(let{type:t}of e.dataTransfer.items)for(let n of this.#g)if(n.isHandlingMimeForPasting(t)){e.dataTransfer.dropEffect=`copy`,e.preventDefault();return}}drop(e){for(let t of e.dataTransfer.items)for(let n of this.#g)if(n.isHandlingMimeForPasting(t.type)){n.paste(t,this.currentLayer),e.preventDefault();return}}copy(e){if(e.preventDefault(),this.#t?.commitOrRemove(),!this.hasSelection)return;let t=[];for(let e of this.#L){let n=e.serialize(!0);n&&t.push(n)}t.length!==0&&e.clipboardData.setData(`application/pdfjs`,JSON.stringify(t))}cut(e){this.copy(e),this.delete()}async paste(e){e.preventDefault();let{clipboardData:t}=e;for(let e of t.items)for(let t of this.#g)if(t.isHandlingMimeForPasting(e.type)){t.paste(e,this.currentLayer);return}let n=t.getData(`application/pdfjs`);if(!n)return;try{n=JSON.parse(n)}catch(e){O(`paste: "${e.message}".`);return}if(!Array.isArray(n))return;this.unselectAll();let r=this.currentLayer;try{let e=[];for(let t of n){let n=await r.deserialize(t);if(!n)return;e.push(n)}this.addCommands({cmd:()=>{for(let t of e)this.#pe(t);this.#ge(e)},undo:()=>{for(let t of e)t.remove()},mustExec:!0})}catch(e){O(`paste: "${e.message}".`)}}keydown(t){!this.isShiftKeyDown&&t.key===`Shift`&&(this.isShiftKeyDown=!0),this.#I!==p.NONE&&!this.isEditorHandlingKeyboard&&e._keyboardManager.exec(this,t)}keyup(e){this.isShiftKeyDown&&e.key===`Shift`&&(this.isShiftKeyDown=!1,this.#T&&(this.#T=!1,this.#ee(`main_toolbar`)))}onEditingAction({name:e}){switch(e){case`undo`:case`redo`:case`delete`:case`selectAll`:this[e]();break;case`highlightSelection`:this.highlightSelection(`context_menu`);break;case`commentSelection`:this.commentSelection(`context_menu`);break}}updatePageIndex(e,t){for(let n of this.getEditors(e))n.pageIndex=t;let n=this.#a.get(e);n&&(n.pageIndex=t,this.#i.set(t,n),this.#O?n.enable():n.disable())}startUpdatePages(){this.#a=new Map(this.#i),this.#i.clear()}endUpdatePages(){this.#a=null}clonePage(e,t){for(let n of this.getEditors(e)){let e=n.serialize(n.mode!==p.HIGHLIGHT);e&&(e.pageIndex=t,e.id=this.getId(),e.isClone=!0,delete e.popupRef,this.#s.setValue(e.id,e))}}findClonesForPage(e){let t=[],{pageIndex:n}=e;for(let[r,i]of this.#s)i.pageIndex===n&&i.isClone&&(this.#s.remove(r),t.push(e.deserialize(i).then(t=>{t&&(t.isClone=!0,e.addOrRebuild(t))})));return Promise.all(t)}#le(e){Object.entries(e).some(([e,t])=>this.#U[e]!==t)&&(this._eventBus.dispatch(`editingstateschanged`,{source:this,details:Object.assign(this.#U,e)}),this.#I===p.HIGHLIGHT&&e.hasSelectedEditor===!1&&this.#ue([[m.HIGHLIGHT_FREE,!0]]))}#ue(e){this._eventBus.dispatch(`annotationeditorparamschanged`,{source:this,details:e})}setEditingState(e){e?(this.#ne(),this.#oe(),this.#le({isEditing:this.#I!==p.NONE,isEmpty:this.#he(),hasSomethingToUndo:this.#l.hasSomethingToUndo(),hasSomethingToRedo:this.#l.hasSomethingToRedo(),hasSelectedEditor:!1})):(this.#re(),this.#se(),this.#le({isEditing:!1}),this.disableUserSelect(!1))}registerEditorTypes(e){if(!this.#g){this.#g=e;for(let e of this.#g)this.#ue(e.defaultPropertiesToUpdate)}}getId(){return this.#D.id}get currentLayer(){return this.#i.get(this.#p)}getLayer(e){return this.#i.get(e)}get currentPageIndex(){return this.#p}addLayer(e){this.#i.set(e.pageIndex,e),this.#O?e.enable():e.disable()}removeLayer(e){this.#i.delete(e.pageIndex)}async updateMode(e,t=null,n=!1,r=!1,i=!1,a=!1){if(this.#I!==e&&!(this.#Y&&(await this.#Y.promise,!this.#Y))){if(this.#Y=Promise.withResolvers(),this.#f?.commitOrRemove(),this.#I===p.POPUP&&this.#u?.hideSidebar(),this.#u?.destroyPopup(),this.#I=e,e===p.NONE){this.setEditingState(!1),this.#fe();for(let e of this.#r.values())e.hideStandaloneCommentButton();this._editorUndoBar?.hide(),this.toggleComment(null),this.#Y.resolve();return}for(let e of this.#r.values())e.addStandaloneCommentButton();e===p.SIGNATURE&&await this.#z?.loadSignatures(),n&&G.clearPointerType(),this.setEditingState(!0),await this.#de(),this.unselectAll();for(let t of this.#i.values())t.updateMode(e);if(e===p.POPUP){this.#n||=await this.#H.getAnnotationsByType(new Set(this.#g.map(e=>e._editorType)));let e=new Set,t=[];for(let n of this.#r.values()){let{annotationElementId:r,hasComment:i,deleted:a}=n;r&&e.add(r),i&&!a&&t.push(n.getData())}for(let n of this.#n){let{id:r,popupRef:i,contentsObj:a}=n;i&&a?.str&&!e.has(r)&&!this.#m.has(r)&&t.push(n)}this.#u?.showSidebar(t)}if(!t){r&&this.addNewEditorFromKeyboard(),this.#Y.resolve();return}for(let e of this.#r.values())e.uid===t?(this.setSelected(e),a?e.editComment():i?e.enterInEditMode():e.focus()):e.unselect();this.#Y.resolve()}}addNewEditorFromKeyboard(){this.currentLayer.canCreateNewEmptyEditor()&&this.currentLayer.addNewEditor()}updateToolbar(e){e.mode!==this.#I&&this._eventBus.dispatch(`switchannotationeditormode`,{source:this,...e})}updateParams(e,t){if(this.#g){switch(e){case m.CREATE:this.currentLayer.addNewEditor(t);return;case m.HIGHLIGHT_SHOW_ALL:this._eventBus.dispatch(`reporttelemetry`,{source:this,details:{type:`editing`,data:{type:`highlight`,action:`toggle_visibility`}}}),(this.#V||=new Map).set(e,t),this.showAllEditors(`highlight`,t);break}if(this.hasSelection)for(let n of this.#L)n.updateParams(e,t);else for(let n of this.#g)n.updateDefaultParams(e,t)}}showAllEditors(e,t,n=!1){for(let n of this.#r.values())n.editorType===e&&n.show(t);(this.#V?.get(m.HIGHLIGHT_SHOW_ALL)??!0)!==t&&this.#ue([[m.HIGHLIGHT_SHOW_ALL,t]])}enableWaiting(e=!1){if(this.#A!==e){this.#A=e;for(let t of this.#i.values())e?t.disableClick():t.enableClick(),t.div.classList.toggle(`waiting`,e)}}async#de(){if(!this.#O){this.#O=!0;let e=[];for(let t of this.#i.values())e.push(t.enable());await Promise.all(e);for(let e of this.#r.values())e.enable()}}#fe(){if(this.unselectAll(),this.#O){this.#O=!1;for(let e of this.#i.values())e.disable();for(let e of this.#r.values())e.disable()}}*getEditors(e){for(let t of this.#r.values())t.pageIndex===e&&(yield t)}getEditor(e){return this.#r.get(e)}addEditor(e){this.#r.set(e.id,e)}removeEditor(e){e.div.contains(document.activeElement)&&(this.#S&&clearTimeout(this.#S),this.#S=setTimeout(()=>{this.focusMainContainer(),this.#S=null},0)),this.#r.delete(e.id),e.annotationElementId&&this.#P?.delete(e.annotationElementId),this.unselect(e),(!e.annotationElementId||!this.#m.has(e.annotationElementId))&&this.#s?.remove(e.id)}addDeletedAnnotationElement(e){this.#m.add(e.annotationElementId),this.addChangedExistingAnnotation(e),e.deleted=!0}isDeletedAnnotationElement(e){return this.#m.has(e)}removeDeletedAnnotationElement(e){this.#m.delete(e.annotationElementId),this.removeChangedExistingAnnotation(e),e.deleted=!1}#pe(e){let t=this.#i.get(e.pageIndex);t?t.addOrRebuild(e):(this.addEditor(e),this.addToAnnotationStorage(e))}setActiveEditor(e){this.#t!==e&&(this.#t=e,e&&this.#ue(e.propertiesToUpdate))}get#me(){let e=null;for(e of this.#L);return e}updateUI(e){this.#me===e&&this.#ue(e.propertiesToUpdate)}updateUIForDefaultProperties(e){this.#ue(e.defaultPropertiesToUpdate)}toggleSelected(e){if(this.#L.has(e)){this.#L.delete(e),e.unselect(),this.#le({hasSelectedEditor:this.hasSelection});return}this.#L.add(e),e.select(),this.#ue(e.propertiesToUpdate),this.#le({hasSelectedEditor:!0})}setSelected(e){this.updateToolbar({mode:e.mode,editId:e.uid}),this.#f?.commitOrRemove();for(let t of this.#L)t!==e&&t.unselect();this.#u?.destroyPopup(),this.#L.clear(),this.#L.add(e),e.select(),this.#ue(e.propertiesToUpdate),this.#le({hasSelectedEditor:!0})}get firstSelectedEditor(){return this.#L.values().next().value}unselect(e){e.unselect(),this.#L.delete(e),this.#le({hasSelectedEditor:this.hasSelection})}get hasSelection(){return this.#L.size!==0}get isEnterHandled(){return this.#L.size===1&&this.firstSelectedEditor.isEnterHandled}undo(){this.#l.undo(),this.#le({hasSomethingToUndo:this.#l.hasSomethingToUndo(),hasSomethingToRedo:!0,isEmpty:this.#he()}),this._editorUndoBar?.hide()}redo(){this.#l.redo(),this.#le({hasSomethingToUndo:!0,hasSomethingToRedo:this.#l.hasSomethingToRedo(),isEmpty:this.#he()})}addCommands(e){this.#l.add(e),this.#le({hasSomethingToUndo:!0,hasSomethingToRedo:!1,isEmpty:this.#he()})}cleanUndoStack(e){this.#l.cleanType(e)}#he(){if(this.#r.size===0)return!0;if(this.#r.size===1)for(let e of this.#r.values())return e.isEmpty();return!1}delete(){this.commitOrRemove();let e=this.currentLayer?.endDrawingSession(!0);if(!this.hasSelection&&!e)return;let t=e?[e]:[...this.#L],n=()=>{this._editorUndoBar?.show(r,t.length===1?t[0].editorType:t.length);for(let e of t)e.remove()},r=()=>{for(let e of t)this.#pe(e)};this.addCommands({cmd:n,undo:r,mustExec:!0})}commitOrRemove(){this.#t?.commitOrRemove()}hasSomethingToControl(){return this.#t||this.hasSelection}#ge(e){for(let e of this.#L)e.unselect();this.#L.clear();for(let t of e)t.isEmpty()||(this.#L.add(t),t.select());this.#le({hasSelectedEditor:this.hasSelection})}selectAll(){for(let e of this.#L)e.commit();this.#ge(this.#r.values())}unselectAll(){if(!(this.#t&&(this.#t.commitOrRemove(),this.#I!==p.NONE))&&!this.#f?.commitOrRemove()&&(this.#u?.destroyPopup(),this.hasSelection)){for(let e of this.#L)e.unselect();this.#L.clear(),this.#le({hasSelectedEditor:!1})}}translateSelectedEditors(e,t,n=!1){if(n||this.commitOrRemove(),!this.hasSelection)return;this.#W[0]+=e,this.#W[1]+=t;let[r,i]=this.#W,a=[...this.#L];this.#G&&clearTimeout(this.#G),this.#G=setTimeout(()=>{this.#G=null,this.#W[0]=this.#W[1]=0,this.addCommands({cmd:()=>{for(let e of a)this.#r.has(e.id)&&(e.translateInPage(r,i),e.translationDone())},undo:()=>{for(let e of a)this.#r.has(e.id)&&(e.translateInPage(-r,-i),e.translationDone())},mustExec:!1})},1e3);for(let n of a)n.translateInPage(e,t),n.translationDone()}setUpDragSession(){if(this.hasSelection){this.disableUserSelect(!0),this.#h=new Map;for(let e of this.#L)this.#h.set(e,{savedX:e.x,savedY:e.y,savedPageIndex:e.pageIndex,newX:0,newY:0,newPageIndex:-1})}}endDragSession(){if(!this.#h)return!1;this.disableUserSelect(!1);let e=this.#h;this.#h=null;let t=!1;for(let[{x:n,y:r,pageIndex:i},a]of e)a.newX=n,a.newY=r,a.newPageIndex=i,t||=n!==a.savedX||r!==a.savedY||i!==a.savedPageIndex;if(!t)return!1;let n=(e,t,n,r)=>{if(this.#r.has(e.id)){let i=this.#i.get(r);i?e._setParentAndPosition(i,t,n):(e.pageIndex=r,e.x=t,e.y=n)}};return this.addCommands({cmd:()=>{for(let[t,{newX:r,newY:i,newPageIndex:a}]of e)n(t,r,i,a)},undo:()=>{for(let[t,{savedX:r,savedY:i,savedPageIndex:a}]of e)n(t,r,i,a)},mustExec:!0}),!0}dragSelectedEditors(e,t){if(this.#h)for(let n of this.#h.keys())n.drag(e,t)}rebuild(e){if(e.parent===null){let t=this.getLayer(e.pageIndex);t?(t.changeParent(e),t.addOrRebuild(e)):(this.addEditor(e),this.addToAnnotationStorage(e),e.rebuild())}else e.parent.addOrRebuild(e)}get isEditorHandlingKeyboard(){return this.getActive()?.shouldGetKeyboardEvents()||this.#L.size===1&&this.firstSelectedEditor.shouldGetKeyboardEvents()}isActive(e){return this.#t===e}getActive(){return this.#t}getMode(){return this.#I}isEditingMode(){return this.#I!==p.NONE}get imageManager(){return F(this,`imageManager`,new et)}getSelectionBoxes(e){if(!e)return null;let t=document.getSelection();for(let n=0,r=t.rangeCount;n({x:(t-r)/a,y:1-(e+o-n)/i,width:s/a,height:o/i});break;case`180`:o=(e,t,o,s)=>({x:1-(e+o-n)/i,y:1-(t+s-r)/a,width:o/i,height:s/a});break;case`270`:o=(e,t,o,s)=>({x:1-(t+s-r)/a,y:(e-n)/i,width:s/a,height:o/i});break;default:o=(e,t,o,s)=>({x:(e-n)/i,y:(t-r)/a,width:o/i,height:s/a});break}let s=[];for(let e=0,n=t.rangeCount;ee.stopPropagation(),{signal:r});let i=e=>{e.preventDefault(),this.#c._uiManager.editAltText(this.#c),this.#d&&this.#c._reportTelemetry({action:`pdfjs.image.alt_text.image_status_label_clicked`,data:{label:this.#p}})};return t.addEventListener(`click`,i,{capture:!0,signal:r}),t.addEventListener(`keydown`,e=>{e.target===t&&e.key===`Enter`&&(this.#o=!0,i(e))},{signal:r}),await this.#m(),t}get#p(){return this.#e&&`added`||this.#e===null&&this.guessedText&&`review`||`missing`}finish(){this.#n&&(this.#n.focus({focusVisible:this.#o}),this.#o=!1)}isEmpty(){return this.#d?this.#e===null:!this.#e&&!this.#t}hasData(){return this.#d?this.#e!==null||!!this.#l:this.isEmpty()}get guessedText(){return this.#l}async setGuessedText(t){this.#e===null&&(this.#l=t,this.#u=await e._l10n.get(`pdfjs-editor-new-alt-text-generated-alt-text-with-disclaimer`,{generatedAltText:t}),this.#m())}toggleAltTextBadge(e=!1){if(!this.#d||this.#e){this.#s?.remove(),this.#s=null;return}if(!this.#s){let e=this.#s=document.createElement(`div`);e.className=`noAltTextBadge`,this.#c.div.append(e)}this.#s.classList.toggle(`hidden`,!e)}serialize(e){let t=this.#e;return!e&&this.#l===t&&(t=this.#u),{altText:t,decorative:this.#t,guessedText:this.#l,textWithDisclaimer:this.#u}}get data(){return{altText:this.#e,decorative:this.#t}}set data({altText:e,decorative:t,guessedText:n,textWithDisclaimer:r,cancel:i=!1}){n&&(this.#l=n,this.#u=r),!(this.#e===e&&this.#t===t)&&(i||(this.#e=e,this.#t=t),this.#m())}toggle(e=!1){this.#n&&(!e&&this.#a&&(clearTimeout(this.#a),this.#a=null),this.#n.disabled=!e)}shown(){this.#c._reportTelemetry({action:`pdfjs.image.alt_text.image_status_label_displayed`,data:{label:this.#p}})}destroy(){this.#n?.remove(),this.#n=null,this.#r=null,this.#i=null,this.#s?.remove(),this.#s=null}async#m(){let t=this.#n;if(!t)return;if(this.#d){if(t.classList.toggle(`done`,!!this.#e),t.setAttribute(`data-l10n-id`,e.#f[this.#p]),this.#r?.setAttribute(`data-l10n-id`,e.#f[`${this.#p}-label`]),!this.#e){this.#i?.remove();return}}else{if(!this.#e&&!this.#t){t.classList.remove(`done`),this.#i?.remove();return}t.classList.add(`done`),t.setAttribute(`data-l10n-id`,`pdfjs-editor-alt-text-edit-button`)}let n=this.#i;if(!n){this.#i=n=document.createElement(`span`),n.className=`tooltip`,n.setAttribute(`role`,`tooltip`),n.id=`alt-text-tooltip-${this.#c.id}`;let e=this.#c._uiManager._signal;e.addEventListener(`abort`,()=>{clearTimeout(this.#a),this.#a=null},{once:!0}),t.addEventListener(`mouseenter`,()=>{this.#a=setTimeout(()=>{this.#a=null,this.#i.classList.add(`show`),this.#c._reportTelemetry({action:`alt_text_tooltip`})},100)},{signal:e}),t.addEventListener(`mouseleave`,()=>{this.#a&&=(clearTimeout(this.#a),null),this.#i?.classList.remove(`show`)},{signal:e})}this.#t?n.setAttribute(`data-l10n-id`,`pdfjs-editor-alt-text-decorative-tooltip`):(n.removeAttribute(`data-l10n-id`),n.textContent=this.#e),n.parentNode||t.append(n),this.#c.getElementForAltText()?.setAttribute(`aria-describedby`,n.id)}},ot=class{#e=null;#t=null;#n=!1;#r=null;#i=null;#a=null;#o=null;#s=null;#c=!1;#l=null;constructor(e){this.#r=e}renderForToolbar(){let e=this.#t=document.createElement(`button`);return e.className=`comment`,this.#u(e,!1)}renderForStandalone(){let e=this.#e=document.createElement(`button`);e.className=`annotationCommentButton`;let t=this.#r.commentButtonPosition;if(t){let{style:n}=e;n.insetInlineEnd=`calc(${100*(this.#r._uiManager.direction===`ltr`?1-t[0]:t[0])}% - var(--comment-button-dim))`,n.top=`calc(${100*t[1]}% - var(--comment-button-dim))`;let r=this.#r.commentButtonColor;r&&(n.backgroundColor=r)}return this.#u(e,!0)}focusButton(){setTimeout(()=>{(this.#e??this.#t)?.focus()},0)}onUpdatedColor(){if(!this.#e)return;let e=this.#r.commentButtonColor;e&&(this.#e.style.backgroundColor=e),this.#r._uiManager.updatePopupColor(this.#r)}get commentButtonWidth(){return(this.#e?.getBoundingClientRect().width??0)/this.#r.parent.boundingClientRect.width}get commentPopupPositionInLayer(){if(this.#l)return this.#l;if(!this.#e)return null;let{x:e,y:t,height:n}=this.#e.getBoundingClientRect(),{x:r,y:i,width:a,height:o}=this.#r.parent.boundingClientRect;return[(e-r)/a,(t+n-i)/o]}set commentPopupPositionInLayer(e){this.#l=e}hasDefaultPopupPosition(){return this.#l===null}removeStandaloneCommentButton(){this.#e?.remove(),this.#e=null}removeToolbarCommentButton(){this.#t?.remove(),this.#t=null}setCommentButtonStates({selected:e,hasPopup:t}){this.#e&&(this.#e.classList.toggle(`selected`,e),this.#e.ariaExpanded=t)}#u(e,t){if(!this.#r._uiManager.hasCommentManager())return null;e.tabIndex=`0`,e.ariaHasPopup=`dialog`,t?(e.ariaControls=`commentPopup`,e.setAttribute(`data-l10n-id`,`pdfjs-show-comment-button`)):(e.ariaControlsElements=[this.#r._uiManager.getCommentDialogElement()],e.setAttribute(`data-l10n-id`,`pdfjs-editor-add-comment-button`));let n=this.#r._uiManager._signal;if(!(n instanceof AbortSignal)||n.aborted)return e;e.addEventListener(`contextmenu`,H,{signal:n}),t&&(e.addEventListener(`focusin`,e=>{this.#r._focusEventsAllowed=!1,U(e)},{capture:!0,signal:n}),e.addEventListener(`focusout`,e=>{this.#r._focusEventsAllowed=!0,U(e)},{capture:!0,signal:n})),e.addEventListener(`pointerdown`,e=>e.stopPropagation(),{signal:n});let r=t=>{t.preventDefault(),e===this.#t?this.edit():this.#r.toggleComment(!0)};return e.addEventListener(`click`,r,{capture:!0,signal:n}),e.addEventListener(`keydown`,t=>{t.target===e&&t.key===`Enter`&&(this.#n=!0,r(t))},{signal:n}),e.addEventListener(`pointerenter`,()=>{this.#r.toggleComment(!1,!0)},{signal:n}),e.addEventListener(`pointerleave`,()=>{this.#r.toggleComment(!1,!1)},{signal:n}),e}edit(e){let t=this.commentPopupPositionInLayer,n,r;if(t)[n,r]=t;else{[n,r]=this.#r.commentButtonPosition;let{width:e,height:t,x:i,y:a}=this.#r;n=i+n*e,r=a+r*t}let i=this.#r.parent.boundingClientRect,{x:a,y:o,width:s,height:c}=i;this.#r._uiManager.editComment(this.#r,a+n*s,o+r*c,{...e,parentDimensions:i})}finish(){this.#t&&(this.#t.focus({focusVisible:this.#n}),this.#n=!1)}isDeleted(){return this.#c||this.#o===``}isEmpty(){return this.#o===null}hasBeenEdited(){return this.isDeleted()||this.#o!==this.#i}serialize(){return this.data}get data(){return{text:this.#o,richText:this.#a,date:this.#s,deleted:this.isDeleted()}}set data(e){if(e!==this.#o&&(this.#a=null),e===null){this.#o=``,this.#c=!0;return}this.#o=e,this.#s=new Date,this.#c=!1}restoreData({text:e,richText:t,date:n}){this.#o=e,this.#a=t,this.#s=n,this.#c=!1}setInitialText(e,t=null){this.#i=e,this.data=e,this.#s=null,this.#a=t}shown(){}destroy(){this.#t?.remove(),this.#t=null,this.#e?.remove(),this.#e=null,this.#o=``,this.#a=null,this.#s=null,this.#r=null,this.#n=!1,this.#c=!1}},st=class e{#e;#t=!1;#n=null;#r;#i;#a;#o;#s=null;#c;#l=null;#u;#d=null;constructor({container:e,isPinchingDisabled:t=null,isPinchingStopped:n=null,onPinchStart:r=null,onPinching:i=null,onPinchEnd:a=null,signal:o}){this.#e=e,this.#n=n,this.#r=t,this.#i=r,this.#a=i,this.#o=a,this.#u=new AbortController,this.#c=AbortSignal.any([o,this.#u.signal]),e.addEventListener(`touchstart`,this.#f.bind(this),{passive:!1,signal:this.#c})}get MIN_TOUCH_DISTANCE_TO_PINCH(){return 35/Ie.pixelRatio}#f(e){if(this.#r?.())return;if(e.touches.length===1){if(this.#s)return;let e=this.#s=new AbortController,t=AbortSignal.any([this.#c,e.signal]),n=this.#e,r={capture:!0,signal:t,passive:!1},i=e=>{e.pointerType===`touch`&&(this.#s?.abort(),this.#s=null)};n.addEventListener(`pointerdown`,e=>{e.pointerType===`touch`&&(U(e),i(e))},r),n.addEventListener(`pointerup`,i,r),n.addEventListener(`pointercancel`,i,r);return}if(!this.#d){this.#d=new AbortController;let e=AbortSignal.any([this.#c,this.#d.signal]),t=this.#e,n={signal:e,capture:!1,passive:!1};t.addEventListener(`touchmove`,this.#p.bind(this),n);let r=this.#m.bind(this);t.addEventListener(`touchend`,r,n),t.addEventListener(`touchcancel`,r,n),n.capture=!0,t.addEventListener(`pointerdown`,U,n),t.addEventListener(`pointermove`,U,n),t.addEventListener(`pointercancel`,U,n),t.addEventListener(`pointerup`,U,n),this.#i?.()}if(U(e),e.touches.length!==2||this.#n?.()){this.#l=null;return}let[t,n]=e.touches;t.identifier>n.identifier&&([t,n]=[n,t]),this.#l={touch0X:t.screenX,touch0Y:t.screenY,touch1X:n.screenX,touch1Y:n.screenY}}#p(t){if(!this.#l||t.touches.length!==2)return;U(t);let[n,r]=t.touches;n.identifier>r.identifier&&([n,r]=[r,n]);let{screenX:i,screenY:a}=n,{screenX:o,screenY:s}=r,c=this.#l,{touch0X:l,touch0Y:u,touch1X:d,touch1Y:f}=c,p=d-l,m=f-u,h=o-i,g=s-a,_=Math.hypot(h,g)||1,v=Math.hypot(p,m)||1;if(!this.#t&&Math.abs(v-_)<=e.MIN_TOUCH_DISTANCE_TO_PINCH)return;if(c.touch0X=i,c.touch0Y=a,c.touch1X=o,c.touch1Y=s,!this.#t){this.#t=!0;return}let y=[(i+o)/2,(a+s)/2];this.#a?.(y,v,_)}#m(e){e.touches.length>=2||(this.#d&&(this.#d.abort(),this.#d=null,this.#o?.()),this.#l&&(U(e),this.#l=null,this.#t=!1))}destroy(){this.#u?.abort(),this.#u=null,this.#s?.abort(),this.#s=null}},K=class e{#e=null;#t=null;#n=null;#r=null;#i=null;#a=!1;#o=null;#s=``;#c=null;#l=null;#u=null;#d=null;#f=null;#p=``;#m=!1;#h=null;#g=!1;#_=!1;#v=!1;#y=null;#b=0;#x=0;#S=null;#C=null;isSelected=!1;_isCopy=!1;_editToolbar=null;_initialOptions=Object.create(null);_initialData=null;_isVisible=!0;_uiManager=null;_focusEventsAllowed=!0;static _l10n=null;static _l10nAlert=null;static _l10nResizer=null;#w=!1;#T=e._zIndex++;static _borderLineWidth=-1;static _colorManager=new rt;static _zIndex=1;static _telemetryTimeout=1e3;static get _resizerKeyboardManager(){let t=e.prototype._resizeWithKeyboard,n=it.TRANSLATE_SMALL,r=it.TRANSLATE_BIG;return F(this,`_resizerKeyboardManager`,new nt([[[`ArrowLeft`],t,{args:[-n,0]}],[[`ctrl+ArrowLeft`,`mac+shift+ArrowLeft`],t,{args:[-r,0]}],[[`ArrowRight`],t,{args:[n,0]}],[[`ctrl+ArrowRight`,`mac+shift+ArrowRight`],t,{args:[r,0]}],[[`ArrowUp`],t,{args:[0,-n]}],[[`ctrl+ArrowUp`,`mac+shift+ArrowUp`],t,{args:[0,-r]}],[[`ArrowDown`],t,{args:[0,n]}],[[`ctrl+ArrowDown`,`mac+shift+ArrowDown`],t,{args:[0,r]}],[[`Escape`],e.prototype._stopResizingWithKeyboard]]))}constructor(e){this.parent=e.parent,this.id=e.id,this.width=this.height=null,this.pageIndex=e.parent.pageIndex,this.name=e.name,this.div=null,this._uiManager=e.uiManager,this.annotationElementId=null,this._willKeepAspectRatio=!1,this._initialOptions.isCentered=e.isCentered,this._structTreeParentId=null,this.annotationElementId=e.annotationElementId||null,this.creationDate=e.creationDate||new Date,this.modificationDate=e.modificationDate||null,this.canAddComment=!0;let{rotation:t,rawDims:{pageWidth:n,pageHeight:r,pageX:i,pageY:a}}=this.parent.viewport;this.rotation=t,this.pageRotation=(360+t-this._uiManager.viewParameters.rotation)%360,this.pageDimensions=[n,r],this.pageTranslation=[i,a];let[o,s]=this.parentDimensions;this.x=e.x/o,this.y=e.y/s,this.isAttachedToDOM=!1,this.deleted=!1}updatePageIndex(e){this.pageIndex=e}get editorType(){return Object.getPrototypeOf(this).constructor._type}get mode(){return Object.getPrototypeOf(this).constructor._editorType}static get isDrawer(){return!1}static get _defaultLineColor(){return F(this,`_defaultLineColor`,this._colorManager.getHexCode(`CanvasText`))}static deleteAnnotationElement(e){let t=new ct({id:e._uiManager.getId(),parent:e.parent,uiManager:e._uiManager});t.annotationElementId=e.annotationElementId,t.deleted=!0,t._uiManager.addToAnnotationStorage(t)}static initialize(t,n){if(e._l10n??=t,e._l10nAlert??=Object.freeze({highlight:`pdfjs-editor-highlight-added-alert`,freetext:`pdfjs-editor-freetext-added-alert`,ink:`pdfjs-editor-ink-added-alert`,stamp:`pdfjs-editor-stamp-added-alert`,signature:`pdfjs-editor-signature-added-alert`}),e._l10nResizer??=Object.freeze({topLeft:`pdfjs-editor-resizer-top-left`,topMiddle:`pdfjs-editor-resizer-top-middle`,topRight:`pdfjs-editor-resizer-top-right`,middleRight:`pdfjs-editor-resizer-middle-right`,bottomRight:`pdfjs-editor-resizer-bottom-right`,bottomMiddle:`pdfjs-editor-resizer-bottom-middle`,bottomLeft:`pdfjs-editor-resizer-bottom-left`,middleLeft:`pdfjs-editor-resizer-middle-left`}),e._borderLineWidth!==-1)return;let r=getComputedStyle(document.documentElement);e._borderLineWidth=parseFloat(r.getPropertyValue(`--outline-width`))||0}static updateDefaultParams(e,t){}static get defaultPropertiesToUpdate(){return[]}static isHandlingMimeForPasting(e){return!1}static paste(e,t){k(`Not implemented`)}get propertiesToUpdate(){return[]}get _isDraggable(){return this.#w}set _isDraggable(e){this.#w=e,this.div?.classList.toggle(`draggable`,e)}get uid(){return this.annotationElementId||this.id}get isEnterHandled(){return!0}center(){let[e,t]=this.pageDimensions;switch(this.parentRotation){case 90:this.x-=this.height*t/(e*2),this.y+=this.width*e/(t*2);break;case 180:this.x+=this.width/2,this.y+=this.height/2;break;case 270:this.x+=this.height*t/(e*2),this.y-=this.width*e/(t*2);break;default:this.x-=this.width/2,this.y-=this.height/2;break}this.fixAndSetPosition()}addCommands(e){this._uiManager.addCommands(e)}get currentLayer(){return this._uiManager.currentLayer}setInBackground(){this.div.style.zIndex=0}setInForeground(){this.div.style.zIndex=this.#T}setParent(e){e===null?(this.#W(),this.#d?.remove(),this.#d=null):(this.pageIndex=e.pageIndex,this.pageDimensions=e.pageDimensions),this.parent=e}focusin(e){this._focusEventsAllowed&&(this.#m?this.#m=!1:this.parent.setSelected(this))}focusout(e){this._focusEventsAllowed&&this.isAttachedToDOM&&(e.relatedTarget?.closest(`#${this.id}`)||(e.preventDefault(),this.parent?.isMultipleSelection||this.commitOrRemove()))}commitOrRemove(){this.isEmpty()?this.remove():this.commit()}commit(){this.isInEditMode()&&this.addToAnnotationStorage()}addToAnnotationStorage(){this._uiManager.addToAnnotationStorage(this)}setAt(e,t,n,r){let[i,a]=this.parentDimensions;[n,r]=this.screenToPageTranslation(n,r),this.x=(e+n)/i,this.y=(t+r)/a,this.fixAndSetPosition()}_moveAfterPaste(e,t){if(this.isClone){delete this.isClone;return}let[n,r]=this.parentDimensions;this.setAt(e*n,t*r,this.width*n,this.height*r),this._onTranslated()}#E([e,t],n,r){[n,r]=this.screenToPageTranslation(n,r),this.x+=n/e,this.y+=r/t,this._onTranslating(this.x,this.y),this.fixAndSetPosition()}translate(e,t){this.#E(this.parentDimensions,e,t)}translateInPage(e,t){this.#h||=[this.x,this.y,this.width,this.height],this.#E(this.pageDimensions,e,t),this.div.scrollIntoView({block:`nearest`})}translationDone(){this._onTranslated(this.x,this.y)}drag(e,t){this.#h||=[this.x,this.y,this.width,this.height];let{div:n,parentDimensions:[r,i]}=this;if(this.x+=e/r,this.y+=t/i,this.parent&&(this.x<0||this.x>1||this.y<0||this.y>1)){let{x:e,y:t}=this.div.getBoundingClientRect();this.parent.findNewParent(this,e,t)&&(this.x-=Math.floor(this.x),this.y-=Math.floor(this.y))}let{x:a,y:o}=this,[s,c]=this.getBaseTranslation();a+=s,o+=c;let{style:l}=n;l.left=`${(100*a).toFixed(2)}%`,l.top=`${(100*o).toFixed(2)}%`,this._onTranslating(a,o),n.scrollIntoView({block:`nearest`})}_onTranslating(e,t){}_onTranslated(e,t){}get _hasBeenMoved(){return!!this.#h&&(this.#h[0]!==this.x||this.#h[1]!==this.y)}get _hasBeenResized(){return!!this.#h&&(this.#h[2]!==this.width||this.#h[3]!==this.height)}getBaseTranslation(){let[t,n]=this.parentDimensions,{_borderLineWidth:r}=e,i=r/t,a=r/n;switch(this.rotation){case 90:return[-i,a];case 180:return[i,a];case 270:return[i,-a];default:return[-i,-a]}}get _mustFixPosition(){return!0}fixAndSetPosition(e=this.rotation){let{div:{style:t},pageDimensions:[n,r]}=this,{x:i,y:a,width:o,height:s}=this;if(o*=n,s*=r,i*=n,a*=r,this._mustFixPosition)switch(e){case 0:i=V(i,0,n-o),a=V(a,0,r-s);break;case 90:i=V(i,0,n-s),a=V(a,o,r);break;case 180:i=V(i,o,n),a=V(a,s,r);break;case 270:i=V(i,s,n),a=V(a,0,r-o);break}this.x=i/=n,this.y=a/=r;let[c,l]=this.getBaseTranslation();i+=c,a+=l,t.left=`${(100*i).toFixed(2)}%`,t.top=`${(100*a).toFixed(2)}%`,this.moveInDOM()}static#D(e,t,n){switch(n){case 90:return[t,-e];case 180:return[-e,-t];case 270:return[-t,e];default:return[e,t]}}screenToPageTranslation(t,n){return e.#D(t,n,this.parentRotation)}pageTranslationToScreen(t,n){return e.#D(t,n,360-this.parentRotation)}#O(e){switch(e){case 90:{let[e,t]=this.pageDimensions;return[0,-e/t,t/e,0]}case 180:return[-1,0,0,-1];case 270:{let[e,t]=this.pageDimensions;return[0,e/t,-t/e,0]}default:return[1,0,0,1]}}get parentScale(){return this._uiManager.viewParameters.realScale}get parentRotation(){return(this._uiManager.viewParameters.rotation+this.pageRotation)%360}get parentDimensions(){let{parentScale:e,pageDimensions:[t,n]}=this;return[t*e,n*e]}setDims(){let{div:{style:e},width:t,height:n}=this;e.width=`${(100*t).toFixed(2)}%`,e.height=`${(100*n).toFixed(2)}%`}getInitialTranslation(){return[0,0]}#k(){if(this.#c)return;this.#c=document.createElement(`div`),this.#c.classList.add(`resizers`);let e=this._willKeepAspectRatio?[`topLeft`,`topRight`,`bottomRight`,`bottomLeft`]:[`topLeft`,`topMiddle`,`topRight`,`middleRight`,`bottomRight`,`bottomMiddle`,`bottomLeft`,`middleLeft`],t=this._uiManager._signal;for(let n of e){let e=document.createElement(`div`);this.#c.append(e),e.classList.add(`resizer`,n),e.setAttribute(`data-resizer-name`,n),e.addEventListener(`pointerdown`,this.#A.bind(this,n),{signal:t}),e.addEventListener(`contextmenu`,H,{signal:t}),e.tabIndex=-1}this.div.prepend(this.#c)}#A(e,t){t.preventDefault();let{isMac:n}=z.platform;if(t.button!==0||t.ctrlKey&&n)return;this.#n?.toggle(!1);let r=this._isDraggable;this._isDraggable=!1,this.#l=[t.screenX,t.screenY];let i=new AbortController,a=this._uiManager.combinedSignal(i);this.parent.togglePointerEvents(!1),window.addEventListener(`pointermove`,this.#N.bind(this,e),{passive:!0,capture:!0,signal:a}),window.addEventListener(`touchmove`,U,{passive:!1,signal:a}),window.addEventListener(`contextmenu`,H,{signal:a}),this.#u={savedX:this.x,savedY:this.y,savedWidth:this.width,savedHeight:this.height};let o=this.parent.div.style.cursor,s=this.div.style.cursor;this.div.style.cursor=this.parent.div.style.cursor=window.getComputedStyle(t.target).cursor;let c=()=>{i.abort(),this.parent.togglePointerEvents(!0),this.#n?.toggle(!0),this._isDraggable=r,this.parent.div.style.cursor=o,this.div.style.cursor=s,this.#M()};window.addEventListener(`pointerup`,c,{signal:a}),window.addEventListener(`blur`,c,{signal:a})}#j(e,t,n,r){this.width=n,this.height=r,this.x=e,this.y=t,this.setDims(),this.fixAndSetPosition(),this._onResized()}_onResized(){}#M(){if(!this.#u)return;let{savedX:e,savedY:t,savedWidth:n,savedHeight:r}=this.#u;this.#u=null;let i=this.x,a=this.y,o=this.width,s=this.height;i===e&&a===t&&o===n&&s===r||this.addCommands({cmd:this.#j.bind(this,i,a,o,s),undo:this.#j.bind(this,e,t,n,r),mustExec:!0})}static _round(e){return Math.round(e*1e4)/1e4}#N(t,n){let[r,i]=this.parentDimensions,a=this.x,o=this.y,s=this.width,c=this.height,l=e.MIN_SIZE/r,u=e.MIN_SIZE/i,d=this.#O(this.rotation),f=(e,t)=>[d[0]*e+d[2]*t,d[1]*e+d[3]*t],p=this.#O(360-this.rotation),m=(e,t)=>[p[0]*e+p[2]*t,p[1]*e+p[3]*t],h,g,_=!1,v=!1;switch(t){case`topLeft`:_=!0,h=(e,t)=>[0,0],g=(e,t)=>[e,t];break;case`topMiddle`:h=(e,t)=>[e/2,0],g=(e,t)=>[e/2,t];break;case`topRight`:_=!0,h=(e,t)=>[e,0],g=(e,t)=>[0,t];break;case`middleRight`:v=!0,h=(e,t)=>[e,t/2],g=(e,t)=>[0,t/2];break;case`bottomRight`:_=!0,h=(e,t)=>[e,t],g=(e,t)=>[0,0];break;case`bottomMiddle`:h=(e,t)=>[e/2,t],g=(e,t)=>[e/2,0];break;case`bottomLeft`:_=!0,h=(e,t)=>[0,t],g=(e,t)=>[e,0];break;case`middleLeft`:v=!0,h=(e,t)=>[0,t/2],g=(e,t)=>[e,t/2];break}let y=h(s,c),b=g(s,c),x=f(...b),S=e._round(a+x[0]),C=e._round(o+x[1]),w=1,T=1,E,D;if(n.fromKeyboard)({deltaX:E,deltaY:D}=n);else{let{screenX:e,screenY:t}=n,[r,i]=this.#l;[E,D]=this.screenToPageTranslation(e-r,t-i),this.#l[0]=e,this.#l[1]=t}if([E,D]=m(E/r,D/i),_){let e=Math.hypot(s,c);w=T=Math.max(Math.min(Math.hypot(b[0]-y[0]-E,b[1]-y[1]-D)/e,1/s,1/c),l/s,u/c)}else v?w=V(Math.abs(b[0]-y[0]-E),l,1)/s:T=V(Math.abs(b[1]-y[1]-D),u,1)/c;let O=e._round(s*w),k=e._round(c*T);x=f(...g(O,k));let A=S-x[0],j=C-x[1];this.#h||=[this.x,this.y,this.width,this.height],this.width=O,this.height=k,this.x=A,this.y=j,this.setDims(),this.fixAndSetPosition(),this._onResizing()}_onResizing(){}altTextFinish(){this.#n?.finish()}get toolbarButtons(){return null}async addEditToolbar(){if(this._editToolbar||this.#_)return this._editToolbar;this._editToolbar=new Ye(this),this.div.append(this._editToolbar.render());let{toolbarButtons:e}=this;if(e)for(let[t,n]of e)await this._editToolbar.addButton(t,n);return this.hasComment||this._editToolbar.addButton(`comment`,this.addCommentButton()),this._editToolbar.addButton(`delete`),this._editToolbar}addCommentButtonInToolbar(){this._editToolbar?.addButtonBefore(`comment`,this.addCommentButton(),`.deleteButton`)}removeCommentButtonFromToolbar(){this._editToolbar?.removeButton(`comment`)}removeEditToolbar(){this._editToolbar?.remove(),this._editToolbar=null,this.#n?.destroy()}addContainer(e){let t=this._editToolbar?.div;t?t.before(e):this.div.append(e)}getClientDimensions(){return this.div.getBoundingClientRect()}createAltText(){return this.#n||(at.initialize(e._l10n),this.#n=new at(this),this.#e&&=(this.#n.data=this.#e,null)),this.#n}get altTextData(){return this.#n?.data}set altTextData(e){this.#n&&(this.#n.data=e)}get guessedAltText(){return this.#n?.guessedText}async setGuessedAltText(e){await this.#n?.setGuessedText(e)}serializeAltText(e){return this.#n?.serialize(e)}hasAltText(){return!!this.#n&&!this.#n.isEmpty()}hasAltTextData(){return this.#n?.hasData()??!1}focusCommentButton(){this.#r?.focusButton()}addCommentButton(){return this.canAddComment?this.#r||=new ot(this):null}addStandaloneCommentButton(){if(this._uiManager.hasCommentManager()){if(this.#i){this._uiManager.isEditingMode()&&this.#i.classList.remove(`hidden`);return}this.hasComment&&(this.#i=this.#r.renderForStandalone(),this.div.append(this.#i))}}removeStandaloneCommentButton(){this.#r.removeStandaloneCommentButton(),this.#i=null}hideStandaloneCommentButton(){this.#i?.classList.add(`hidden`)}get comment(){if(!this.#r)return null;let{data:{richText:e,text:t,date:n,deleted:r}}=this.#r;return{text:t,richText:e,date:n,deleted:r,color:this.getNonHCMColor(),opacity:this.opacity??1}}set comment(e){this.#r||=new ot(this),typeof e==`object`&&e?this.#r.restoreData(e):this.#r.data=e,this.hasComment?(this.removeCommentButtonFromToolbar(),this.addStandaloneCommentButton(),this._uiManager.updateComment(this)):(this.addCommentButtonInToolbar(),this.removeStandaloneCommentButton(),this._uiManager.removeComment(this))}setCommentData({comment:e,popupRef:t,richText:n}){if(!t||(this.#r||=new ot(this),this.#r.setInitialText(e,n),!this.annotationElementId))return;let r=this._uiManager.getAndRemoveDataFromAnnotationStorage(this.annotationElementId);r&&this.updateFromAnnotationLayer(r)}get hasEditedComment(){return this.#r?.hasBeenEdited()}get hasDeletedComment(){return this.#r?.isDeleted()}get hasComment(){return!!this.#r&&!this.#r.isEmpty()&&!this.#r.isDeleted()}async editComment(e){this.#r||=new ot(this),this.#r.edit(e)}toggleComment(e,t=void 0){this.hasComment&&this._uiManager.toggleComment(this,e,t)}setSelectedCommentButton(e){this.#r.setSelectedButton(e)}addComment(e){if(this.hasEditedComment){let[,,,t]=e.rect,[n]=this.pageDimensions,[r]=this.pageTranslation,i=r+n+1,a=t-100,o=i+180;e.popup={contents:this.comment.text,deleted:this.comment.deleted,rect:[i,a,o,t]}}}updateFromAnnotationLayer({popup:{contents:e,deleted:t}}){this.#r.data=t?null:e}get parentBoundingClientRect(){return this.parent.boundingClientRect}render(){let e=this.div=document.createElement(`div`);e.setAttribute(`data-editor-rotation`,(360-this.rotation)%360),e.className=this.name,e.setAttribute(`id`,this.id),e.tabIndex=this.#a?-1:0,e.setAttribute(`role`,`application`),this.defaultL10nId&&e.setAttribute(`data-l10n-id`,this.defaultL10nId),this._isVisible||e.classList.add(`hidden`),this.setInForeground(),this.#z();let[t,n]=this.parentDimensions;this.parentRotation%180!=0&&(e.style.maxWidth=`${(100*n/t).toFixed(2)}%`,e.style.maxHeight=`${(100*t/n).toFixed(2)}%`);let[r,i]=this.getInitialTranslation();return this.translate(r,i),Qe(this,e,[`keydown`,`pointerdown`,`dblclick`]),this.isResizable&&this._uiManager._supportsPinchToZoom&&(this.#C||=new st({container:e,isPinchingDisabled:()=>!this.isSelected,onPinchStart:this.#P.bind(this),onPinching:this.#F.bind(this),onPinchEnd:this.#I.bind(this),signal:this._uiManager._signal})),this.addStandaloneCommentButton(),this._uiManager._editorUndoBar?.hide(),e}#P(){this.#u={savedX:this.x,savedY:this.y,savedWidth:this.width,savedHeight:this.height},this.#n?.toggle(!1),this.parent.togglePointerEvents(!1)}#F(t,n,r){let i=.7,a=r/n*i+1-i;if(a===1)return;let o=this.#O(this.rotation),s=(e,t)=>[o[0]*e+o[2]*t,o[1]*e+o[3]*t],[c,l]=this.parentDimensions,u=this.x,d=this.y,f=this.width,p=this.height,m=e.MIN_SIZE/c,h=e.MIN_SIZE/l;a=Math.max(Math.min(a,1/f,1/p),m/f,h/p);let g=e._round(f*a),_=e._round(p*a);if(g===f&&_===p)return;this.#h||=[u,d,f,p];let v=s(f/2,p/2),y=e._round(u+v[0]),b=e._round(d+v[1]),x=s(g/2,_/2);this.x=y-x[0],this.y=b-x[1],this.width=g,this.height=_,this.setDims(),this.fixAndSetPosition(),this._onResizing()}#I(){this.#n?.toggle(!0),this.parent.togglePointerEvents(!0),this.#M()}pointerdown(e){let{isMac:t}=z.platform;if(e.button!==0||e.ctrlKey&&t){e.preventDefault();return}if(this.#m=!0,this._isDraggable){this.#R(e);return}this.#L(e)}#L(e){let{isMac:t}=z.platform;e.ctrlKey&&!t||e.shiftKey||e.metaKey&&t?this.parent.toggleSelected(this):this.parent.setSelected(this)}#R(e){let{isSelected:t}=this;this._uiManager.setUpDragSession();let n=!1,r=new AbortController,i=this._uiManager.combinedSignal(r),a={capture:!0,passive:!1,signal:i},o=e=>{r.abort(),this.#o=null,this.#m=!1,this._uiManager.endDragSession()||this.#L(e),n&&this._onStopDragging()};t&&(this.#b=e.clientX,this.#x=e.clientY,this.#o=e.pointerId,this.#s=e.pointerType,window.addEventListener(`pointermove`,e=>{n||(n=!0,this._uiManager.toggleComment(this,!0,!1),this._onStartDragging());let{clientX:t,clientY:r,pointerId:i}=e;if(i!==this.#o){U(e);return}let[a,o]=this.screenToPageTranslation(t-this.#b,r-this.#x);this.#b=t,this.#x=r,this._uiManager.dragSelectedEditors(a,o)},a),window.addEventListener(`touchmove`,U,a),window.addEventListener(`pointerdown`,e=>{e.pointerType===this.#s&&(this.#C||e.isPrimary)&&o(e),U(e)},a));let s=e=>{if(!this.#o||this.#o===e.pointerId){o(e);return}U(e)};window.addEventListener(`pointerup`,s,{signal:i}),window.addEventListener(`blur`,s,{signal:i})}_onStartDragging(){}_onStopDragging(){}moveInDOM(){this.#y&&clearTimeout(this.#y),this.#y=setTimeout(()=>{this.#y=null,this.parent?.moveEditorInDOM(this)},0)}_setParentAndPosition(e,t,n){e.changeParent(this),this.x=t,this.y=n,this.fixAndSetPosition(),this._onTranslated()}getRect(e,t,n=this.rotation){let r=this.parentScale,[i,a]=this.pageDimensions,[o,s]=this.pageTranslation,c=e/r,l=t/r,u=this.x*i,d=this.y*a,f=this.width*i,p=this.height*a;switch(n){case 0:return[u+c+o,a-d-l-p+s,u+c+f+o,a-d-l+s];case 90:return[u+l+o,a-d+c+s,u+l+p+o,a-d+c+f+s];case 180:return[u-c-f+o,a-d+l+s,u-c+o,a-d+l+p+s];case 270:return[u-l-p+o,a-d-c-f+s,u-l+o,a-d-c+s];default:throw Error(`Invalid rotation`)}}getRectInCurrentCoords(e,t){let[n,r,i,a]=e,o=i-n,s=a-r;switch(this.rotation){case 0:return[n,t-a,o,s];case 90:return[n,t-r,s,o];case 180:return[i,t-r,o,s];case 270:return[i,t-a,s,o];default:throw Error(`Invalid rotation`)}}getPDFRect(){return this.getRect(0,0)}getNonHCMColor(){return this.color&&e._colorManager.convert(this._uiManager.getNonHCMColor(this.color))}onUpdatedColor(){this.#r?.onUpdatedColor()}getData(){let{comment:{text:e,color:t,date:n,opacity:r,deleted:i,richText:a},uid:o,pageIndex:s,creationDate:c,modificationDate:l}=this;return{id:o,pageIndex:s,rect:this.getPDFRect(),richText:a,contentsObj:{str:e},creationDate:c,modificationDate:n||l,popupRef:!i,color:t,opacity:r}}onceAdded(e){}isEmpty(){return!1}enableEditMode(){return this.isInEditMode()?!1:(this.parent.setEditingState(!1),this.#_=!0,!0)}disableEditMode(){return this.isInEditMode()?(this.parent.setEditingState(!0),this.#_=!1,!0):!1}isInEditMode(){return this.#_}shouldGetKeyboardEvents(){return this.#v}needsToBeRebuilt(){return this.div&&!this.isAttachedToDOM}get isOnScreen(){let{top:e,left:t,bottom:n,right:r}=this.getClientDimensions(),{innerHeight:i,innerWidth:a}=window;return t0&&e0}#z(){if(this.#f||!this.div)return;this.#f=new AbortController;let e=this._uiManager.combinedSignal(this.#f);this.div.addEventListener(`focusin`,this.focusin.bind(this),{signal:e}),this.div.addEventListener(`focusout`,this.focusout.bind(this),{signal:e})}rebuild(){this.#z()}rotate(e){}resize(){}serializeDeleted(){return{id:this.annotationElementId,deleted:!0,pageIndex:this.pageIndex,popupRef:this._initialData?.popupRef||``}}serialize(e=!1,t=null){return{annotationType:this.mode,pageIndex:this.pageIndex,rect:this.getPDFRect(),rotation:this.rotation,structTreeParentId:this._structTreeParentId,popupRef:this._initialData?.popupRef||``}}static async deserialize(e,t,n){let r=new this.prototype.constructor({parent:t,id:n.getId(),uiManager:n,annotationElementId:e.annotationElementId,creationDate:e.creationDate,modificationDate:e.modificationDate});r.rotation=e.rotation,r.#e=e.accessibilityData,r._isCopy=e.isCopy||!1;let[i,a]=r.pageDimensions,[o,s,c,l]=r.getRectInCurrentCoords(e.rect,a);return r.x=o/i,r.y=s/a,r.width=c/i,r.height=l/a,r}get hasBeenModified(){return!!this.annotationElementId&&(this.deleted||this.serialize()!==null)}remove(){if(this.#f?.abort(),this.#f=null,this.isEmpty()||this.commit(),this.parent?this.parent.remove(this):this._uiManager.removeEditor(this),this.hideCommentPopup(),this.#y&&=(clearTimeout(this.#y),null),this.#W(),this.removeEditToolbar(),this.#S){for(let e of this.#S.values())clearTimeout(e);this.#S=null}this.parent=null,this.#C?.destroy(),this.#C=null,this.#d?.remove(),this.#d=null}get isResizable(){return!1}makeResizable(){this.isResizable&&(this.#k(),this.#c.classList.remove(`hidden`))}get toolbarPosition(){return null}get commentButtonPosition(){return this._uiManager.direction===`ltr`?[1,0]:[0,0]}get commentButtonPositionInPage(){let{commentButtonPosition:[t,n]}=this,[r,i,a,o]=this.getPDFRect();return[e._round(r+(a-r)*t),e._round(i+(o-i)*(1-n))]}get commentButtonColor(){return this._uiManager.makeCommentColor(this.getNonHCMColor(),this.opacity)}get commentPopupPosition(){return this.#r.commentPopupPositionInLayer}set commentPopupPosition(e){this.#r.commentPopupPositionInLayer=e}hasDefaultPopupPosition(){return this.#r.hasDefaultPopupPosition()}get commentButtonWidth(){return this.#r.commentButtonWidth}get elementBeforePopup(){return this.div}setCommentButtonStates(e){this.#r?.setCommentButtonStates(e)}keydown(t){if(!this.isResizable||t.target!==this.div||t.key!==`Enter`)return;this._uiManager.setSelected(this),this.#u={savedX:this.x,savedY:this.y,savedWidth:this.width,savedHeight:this.height};let n=this.#c.children;if(!this.#t){this.#t=Array.from(n);let t=this.#B.bind(this),r=this.#V.bind(this),i=this._uiManager._signal;for(let n of this.#t){let a=n.getAttribute(`data-resizer-name`);n.setAttribute(`role`,`spinbutton`),n.addEventListener(`keydown`,t,{signal:i}),n.addEventListener(`blur`,r,{signal:i}),n.addEventListener(`focus`,this.#H.bind(this,a),{signal:i}),n.setAttribute(`data-l10n-id`,e._l10nResizer[a])}}let r=this.#t[0],i=0;for(let e of n){if(e===r)break;i++}let a=(360-this.rotation+this.parentRotation)%360/90*(this.#t.length/4);if(a!==i){if(ai)for(let e=0;e{this.div?.classList.contains(`selectedEditor`)&&this._editToolbar?.show()});return}this._editToolbar?.show(),this.#n?.toggleAltTextBadge(!1)}focus(){this.div&&!this.div.contains(document.activeElement)&&setTimeout(()=>this.div?.focus({preventScroll:!0}),0)}unselect(){this.isSelected&&(this.isSelected=!1,this.#c?.classList.add(`hidden`),this.div?.classList.remove(`selectedEditor`),this.div?.contains(document.activeElement)&&this._uiManager.currentLayer.div.focus({preventScroll:!0}),this._editToolbar?.hide(),this.#n?.toggleAltTextBadge(!0),this.hideCommentPopup())}hideCommentPopup(){this.hasComment&&this._uiManager.toggleComment(null)}updateParams(e,t){}disableEditing(){}enableEditing(){}get canChangeContent(){return!1}enterInEditMode(){this.canChangeContent&&(this.enableEditMode(),this.div.focus())}dblclick(e){e.target.nodeName!==`BUTTON`&&(this.enterInEditMode(),this.parent.updateToolbar({mode:this.constructor._editorType,editId:this.uid}))}getElementForAltText(){return this.div}get contentDiv(){return this.div}get isEditing(){return this.#g}set isEditing(e){this.#g=e,this.parent&&(e?(this.parent.setSelected(this),this.parent.setActiveEditor(this)):this.parent.setActiveEditor(null))}static get MIN_SIZE(){return 16}static canCreateNewEmptyEditor(){return!0}get telemetryInitialData(){return{action:`added`}}get telemetryFinalData(){return null}_reportTelemetry(t,n=!1){if(n){this.#S||=new Map;let{action:n}=t,r=this.#S.get(n);r&&clearTimeout(r),r=setTimeout(()=>{this._reportTelemetry(t),this.#S.delete(n),this.#S.size===0&&(this.#S=null)},e._telemetryTimeout),this.#S.set(n,r);return}t.type||=this.editorType,this._uiManager._eventBus.dispatch(`reporttelemetry`,{source:this,details:{type:`editing`,data:t}})}show(e=this._isVisible){this.div.classList.toggle(`hidden`,!e),this._isVisible=e}enable(){this.div&&(this.div.tabIndex=0),this.#a=!1}disable(){this.div&&(this.div.tabIndex=-1),this.#a=!0}updateFakeAnnotationElement(e){if(!this.#d&&!this.deleted){this.#d=e.addFakeAnnotation(this);return}if(this.deleted){this.#d.remove(),this.#d=null;return}(this.hasEditedComment||this._hasBeenMoved||this._hasBeenResized)&&this.#d.updateEdited({rect:this.getPDFRect(),popup:this.comment})}renderAnnotationElement(e){if(this.deleted)return e.hide(),null;let t=e.container.querySelector(`.annotationContent`);if(!t)t=document.createElement(`div`),t.classList.add(`annotationContent`,this.editorType),e.container.prepend(t);else if(t.nodeName===`CANVAS`){let e=t;t=document.createElement(`div`),t.classList.add(`annotationContent`,this.editorType),e.before(t)}return t}resetAnnotationElement(e){let{firstElementChild:t}=e.container;t?.nodeName===`DIV`&&t.classList.contains(`annotationContent`)&&t.remove()}},ct=class extends K{constructor(e){super(e),this.annotationElementId=e.annotationElementId,this.deleted=!0}serialize(){return this.serializeDeleted()}},lt=3285377520,ut=4294901760,dt=65535,ft=class{constructor(e){this.h1=e?e&4294967295:lt,this.h2=e?e&4294967295:lt}update(e){let t,n;if(typeof e==`string`){t=new Uint8Array(e.length*2),n=0;for(let r=0,i=e.length;r>>8,t[n++]=i&255)}}else if(ArrayBuffer.isView(e))t=e.slice(),n=t.byteLength;else throw Error(`Invalid data format, must be a string or TypedArray.`);let r=n>>2,i=n-r*4,a=new Uint32Array(t.buffer,0,r),o=0,s=0,c=this.h1,l=this.h2,u=3432918353,d=461845907,f=11601,p=13715;for(let e=0;e>>17,o=o*d&ut|o*p&dt,c^=o,c=c<<13|c>>>19,c=c*5+3864292196):(s=a[e],s=s*u&ut|s*f&dt,s=s<<15|s>>>17,s=s*d&ut|s*p&dt,l^=s,l=l<<13|l>>>19,l=l*5+3864292196);switch(o=0,i){case 3:o^=t[r*4+2]<<16;case 2:o^=t[r*4+1]<<8;case 1:o^=t[r*4],o=o*u&ut|o*f&dt,o=o<<15|o>>>17,o=o*d&ut|o*p&dt,r&1?c^=o:l^=o}this.h1=c,this.h2=l}hexdigest(){let e=this.h1,t=this.h2;return e^=t>>>1,e=e*3981806797&ut|e*36045&dt,t=t*4283543511&ut|((t<<16|e>>>16)*2950163797&ut)>>>16,e^=t>>>1,e=e*444984403&ut|e*60499&dt,t=t*3301882366&ut|((t<<16|e>>>16)*3120437893&ut)>>>16,e^=t>>>1,(e>>>0).toString(16).padStart(8,`0`)+(t>>>0).toString(16).padStart(8,`0`)}},pt=Object.freeze({map:null,hash:``,transfer:void 0}),mt=class{#e=!1;#t=null;#n=null;#r=new Map;onSetModified=null;onResetModified=null;onAnnotationEditor=null;getValue(e,t){let n=this.#r.get(e);return n===void 0?t:Object.assign(t,n)}getRawValue(e){return this.#r.get(e)}remove(e){let t=this.#r.get(e);t!==void 0&&(t instanceof K&&this.#n.delete(t.annotationElementId),this.#r.delete(e),this.#r.size===0&&this.resetModified(),!this.#r.values().some(e=>e instanceof K)&&this.onAnnotationEditor?.(null))}setValue(e,t){let n=this.#r.get(e),r=!1;if(n!==void 0)for(let[e,i]of Object.entries(t))n[e]!==i&&(r=!0,n[e]=i);else r=!0,this.#r.set(e,t);r&&this.#i(),t instanceof K&&((this.#n||=new Map).set(t.annotationElementId,t),this.onAnnotationEditor?.(t.constructor._type))}has(e){return this.#r.has(e)}get size(){return this.#r.size}#i(){this.#e||(this.#e=!0,this.onSetModified?.())}resetModified(){this.#e&&(this.#e=!1,this.onResetModified?.())}get print(){return new ht(this)}get serializable(){if(this.#r.size===0)return pt;let e=new Map,t=new ft,n=[],r=Object.create(null),i=!1;for(let[n,a]of this.#r){let o=a instanceof K?a.serialize(!1,r):a;a.page&&(a.pageIndex=a.page._pageIndex,delete a.page),o&&(e.set(n,o),t.update(`${n}:${JSON.stringify(o)}`),i||=!!o.bitmap)}if(i)for(let t of e.values())t.bitmap&&n.push(t.bitmap);return e.size>0?{map:e,hash:t.hexdigest(),transfer:n}:pt}get editorStats(){let e=null,t=new Map,n=0,r=0;for(let i of this.#r.values()){if(!(i instanceof K)){i.popup&&(i.popup.deleted?r+=1:n+=1);continue}i.isCommentDeleted?r+=1:i.hasEditedComment&&(n+=1);let a=i.telemetryFinalData;if(!a)continue;let{type:o}=a;t.getOrInsertComputed(o,()=>Object.getPrototypeOf(i).constructor),e||=Object.create(null);let s=e[o]||=new Map;for(let[e,t]of Object.entries(a)){if(e===`type`)continue;let n=s.getOrInsertComputed(e,pe);n.set(t,(n.get(t)??0)+1)}}if((r>0||n>0)&&(e||=Object.create(null),e.comments={deleted:r,edited:n}),!e)return null;for(let[n,r]of t)e[n]=r.computeTelemetryFinalData(e[n]);return e}resetModifiedIds(){this.#t=null}updateEditor(e,t){let n=this.#n?.get(e);return n?(n.updateFromAnnotationLayer(t),!0):!1}getEditor(e){return this.#n?.get(e)||null}get modifiedIds(){if(this.#t)return this.#t;let e=[];if(this.#n)for(let t of this.#n.values())t.serialize()&&e.push(t.annotationElementId);let t=``;if(e.length){let n=new ft;n.update(e.join(`,`)),t=n.hexdigest()}return this.#t={ids:new Set(e),hash:t}}[Symbol.iterator](){return this.#r.entries()}},ht=class extends mt{#e=pt;constructor(e){super();let{serializable:t}=e;if(t===pt)return;let{map:n,hash:r,transfer:i}=t,a=structuredClone(n,i?{transfer:i}:null);this.#e={map:a,hash:r,transfer:[]}}get print(){k(`Should not call PrintAnnotationStorage.print`)}get serializable(){return this.#e}get modifiedIds(){return F(this,`modifiedIds`,{ids:new Set,hash:``})}};r(7588);var gt=`__forcedDependency`,{floor:_t,ceil:vt}=Math;function yt(e,t,n,r,i,a){e[t*4+0]=Math.min(e[t*4+0],n),e[t*4+1]=Math.min(e[t*4+1],r),e[t*4+2]=Math.max(e[t*4+2],i),e[t*4+3]=Math.max(e[t*4+3],a)}function bt(e,t,n,r,i){let a;e?(e<0&&(a=i[0],i[0]=i[2],i[2]=a),i[0]*=e,i[2]*=e,t<0&&(a=i[1],i[1]=i[3],i[3]=a),i[1]*=t,i[3]*=t):i.fill(0),i[0]+=n,i[1]+=r,i[2]+=n,i[3]+=r}var xt=new Uint32Array(new Uint8Array([255,255,0,0]).buffer)[0],St=class{#e;#t;constructor(e,t){this.#e=e,this.#t=t}get length(){return this.#e.length}isEmpty(e){return this.#e[e]===xt}minX(e){return this.#t[e*4+0]/256}minY(e){return this.#t[e*4+1]/256}maxX(e){return(this.#t[e*4+2]+1)/256}maxY(e){return(this.#t[e*4+3]+1)/256}},Ct=(e,t)=>e?.getOrInsertComputed(t,()=>({dependencies:new Set,isRenderingOperation:!1})),wt=class{#e=[[1,0,0,1,0,0]];#t=[-1/0,-1/0,1/0,1/0];#n=new Float64Array(a);_pendingBBoxIdx=-1;#r;#i;#a;#o;_savesStack=[];_markedContentStack=[];constructor(e,t){this.#r=e.width,this.#i=e.height,this.#s(t)}growOperationsCount(e){e>=this.#o.length&&this.#s(e,this.#o)}#s(e,t){let n=new ArrayBuffer(e*4);this.#a=new Uint8ClampedArray(n),this.#o=new Uint32Array(n),t&&t.length>0?(this.#o.set(t),this.#o.fill(xt,t.length)):this.#o.fill(xt)}get clipBox(){return this.#t}save(e){return this.#t={__proto__:this.#t},this._savesStack.push(e),this}restore(e,t){let n=Object.getPrototypeOf(this.#t);if(n===null)return this;this.#t=n;let r=this._savesStack.pop();return r!==void 0&&(t?.(r,e),this.#o[e]=this.#o[r]),this}recordOpenMarker(e){return this._savesStack.push(e),this}getOpenMarker(){return this._savesStack.length===0?null:this._savesStack.at(-1)}recordCloseMarker(e,t){let n=this._savesStack.pop();return n!==void 0&&(t?.(n,e),this.#o[e]=this.#o[n]),this}beginMarkedContent(e){return this._markedContentStack.push(e),this}endMarkedContent(e,t){let n=this._markedContentStack.pop();return n!==void 0&&(t?.(n,e),this.#o[e]=this.#o[n]),this}pushBaseTransform(e){return this.#e.push(B.multiplyByDOMMatrix(this.#e.at(-1),e.getTransform())),this}popBaseTransform(){return this.#e.length>1&&this.#e.pop(),this}resetBBox(e){return this._pendingBBoxIdx!==e&&(this._pendingBBoxIdx=e,this.#n.set(a,0)),this}recordClipBox(e,t,n,r,i,o){let s=B.multiplyByDOMMatrix(this.#e.at(-1),t.getTransform()),c=a.slice();B.axialAlignedBoundingBox([n,i,r,o],s,c);let l=B.intersect(this.#t,c);return l?(this.#t[0]=l[0],this.#t[1]=l[1],this.#t[2]=l[2],this.#t[3]=l[3]):(this.#t[0]=this.#t[1]=1/0,this.#t[2]=this.#t[3]=-1/0),this}recordBBox(e,t,n,r,i,o){let s=this.#t;if(s[0]===1/0)return this;let c=B.multiplyByDOMMatrix(this.#e.at(-1),t.getTransform());if(s[0]===-1/0)return B.axialAlignedBoundingBox([n,i,r,o],c,this.#n),this;let l=a.slice();return B.axialAlignedBoundingBox([n,i,r,o],c,l),this.#n[0]=V(l[0],s[0],this.#n[0]),this.#n[1]=V(l[1],s[1],this.#n[1]),this.#n[2]=V(l[2],this.#n[2],s[2]),this.#n[3]=V(l[3],this.#n[3],s[3]),this}recordFullPageBBox(e){return this.#n[0]=Math.max(0,this.#t[0]),this.#n[1]=Math.max(0,this.#t[1]),this.#n[2]=Math.min(this.#r,this.#t[2]),this.#n[3]=Math.min(this.#i,this.#t[3]),this}recordOperation(e,t=!1,n){if(this._pendingBBoxIdx!==e)return this;let r=_t(this.#n[0]*256/this.#r),i=_t(this.#n[1]*256/this.#i),a=vt(this.#n[2]*256/this.#r),o=vt(this.#n[3]*256/this.#i);if(yt(this.#a,e,r,i,a,o),n)for(let t of n)for(let n of t)n!==e&&yt(this.#a,n,r,i,a,o);return t||(this._pendingBBoxIdx=-1),this}bboxToClipBoxDropOperation(e){return this._pendingBBoxIdx===e&&(this._pendingBBoxIdx=-1,this.#t[0]=Math.max(this.#t[0],this.#n[0]),this.#t[1]=Math.max(this.#t[1],this.#n[1]),this.#t[2]=Math.min(this.#t[2],this.#n[2]),this.#t[3]=Math.min(this.#t[3],this.#n[3])),this}take(){return new St(this.#o,this.#a)}takeDebugMetadata(){throw Error(`Unreachable`)}recordSimpleData(e,t){return this}recordIncrementalData(e,t){return this}resetIncrementalData(e,t){return this}recordNamedData(e,t){return this}recordSimpleDataFromNamed(e,t,n){return this}recordFutureForcedDependency(e,t){return this}inheritSimpleDataAsFutureForcedDependencies(e){return this}inheritPendingDependenciesAsFutureForcedDependencies(){return this}recordCharacterBBox(e,t,n,r=1,i=0,a=0,o){return this}getSimpleIndex(e){}recordDependencies(e,t){return this}recordNamedDependency(e,t){return this}recordShowTextOperation(e,t=!1){return this}},Tt=class{#e={__proto__:null};#t={__proto__:null,transform:[],moveText:[],sameLineText:[],[gt]:[]};#n=new Map;#r=new Set;#i=new Map;#a;#o;#s;constructor(e,t=!1){this.#s=e,t&&(this.#a=new Map,this.#o=(e,t)=>{Ct(this.#a,t).dependencies.add(e)})}get clipBox(){return this.#s.clipBox}growOperationsCount(e){this.#s.growOperationsCount(e)}save(e){return this.#e={__proto__:this.#e},this.#t={__proto__:this.#t,transform:{__proto__:this.#t.transform},moveText:{__proto__:this.#t.moveText},sameLineText:{__proto__:this.#t.sameLineText},[gt]:{__proto__:this.#t[gt]}},this.#s.save(e),this}restore(e){this.#s.restore(e,this.#o);let t=Object.getPrototypeOf(this.#e);return t===null?this:(this.#e=t,this.#t=Object.getPrototypeOf(this.#t),this)}recordOpenMarker(e){return this.#s.recordOpenMarker(e,this.#o),this}getOpenMarker(){return this.#s.getOpenMarker()}recordCloseMarker(e){return this.#s.recordCloseMarker(e,this.#o),this}beginMarkedContent(e){return this.#s.beginMarkedContent(e),this}endMarkedContent(e){return this.#s.endMarkedContent(e,this.#o),this}pushBaseTransform(e){return this.#s.pushBaseTransform(e),this}popBaseTransform(){return this.#s.popBaseTransform(),this}recordSimpleData(e,t){return this.#e[e]=t,this}recordIncrementalData(e,t){return this.#t[e].push(t),this}resetIncrementalData(e,t){return this.#t[e].length=0,this}recordNamedData(e,t){return this.#n.set(e,t),this}recordSimpleDataFromNamed(e,t,n){this.#e[e]=this.#n.get(t)??n}recordFutureForcedDependency(e,t){return this.recordIncrementalData(gt,t),this}inheritSimpleDataAsFutureForcedDependencies(e){for(let t of e)t in this.#e&&this.recordFutureForcedDependency(t,this.#e[t]);return this}inheritPendingDependenciesAsFutureForcedDependencies(){for(let e of this.#r)this.recordFutureForcedDependency(gt,e);return this}resetBBox(e){return this.#s.resetBBox(e),this}recordClipBox(e,t,n,r,i,a){return this.#s.recordClipBox(e,t,n,r,i,a),this}recordBBox(e,t,n,r,i,a){return this.#s.recordBBox(e,t,n,r,i,a),this}recordCharacterBBox(e,t,n,r=1,i=0,a=0,o){let s=n.bbox,c,l;if(s&&(c=s[2]!==s[0]&&s[3]!==s[1]&&this.#i.get(n),c!==!1&&(l=[0,0,0,0],B.axialAlignedBoundingBox(s,n.fontMatrix,l),(r!==1||i!==0||a!==0)&&bt(r,-r,i,a,l),c)))return this.recordBBox(e,t,l[0],l[2],l[1],l[3]);if(!o)return this.recordFullPageBBox(e);let u=o();return s&&l&&c===void 0&&(c=l[0]<=i-u.actualBoundingBoxLeft&&l[2]>=i+u.actualBoundingBoxRight&&l[1]<=a-u.actualBoundingBoxAscent&&l[3]>=a+u.actualBoundingBoxDescent,this.#i.set(n,c),c)?this.recordBBox(e,t,l[0],l[2],l[1],l[3]):this.recordBBox(e,t,i-u.actualBoundingBoxLeft,i+u.actualBoundingBoxRight,a-u.actualBoundingBoxAscent,a+u.actualBoundingBoxDescent)}recordFullPageBBox(e){return this.#s.recordFullPageBBox(e),this}getSimpleIndex(e){return this.#e[e]}recordDependencies(e,t){let n=this.#r,r=this.#e,i=this.#t;for(let e of t)e in this.#e?n.add(r[e]):e in i&&i[e].forEach(n.add,n);return this}recordNamedDependency(e,t){return this.#n.has(t)&&this.#r.add(this.#n.get(t)),this}recordOperation(e,t=!1){if(this.recordDependencies(e,[gt]),this.#a){let t=Ct(this.#a,e),{dependencies:n}=t;this.#r.forEach(n.add,n),this.#s._savesStack.forEach(n.add,n),this.#s._markedContentStack.forEach(n.add,n),n.delete(e),t.isRenderingOperation=!0}let n=!t&&e===this.#s._pendingBBoxIdx;return this.#s.recordOperation(e,t,[this.#r,this.#s._savesStack,this.#s._markedContentStack]),n&&this.#r.clear(),this}recordShowTextOperation(e,t=!1){let n=Array.from(this.#r);this.recordOperation(e,t),this.recordIncrementalData(`sameLineText`,e);for(let e of n)this.recordIncrementalData(`sameLineText`,e);return this}bboxToClipBoxDropOperation(e,t=!1){let n=!t&&e===this.#s._pendingBBoxIdx;return this.#s.bboxToClipBoxDropOperation(e),n&&this.#r.clear(),this}take(){return this.#i.clear(),this.#s.take()}takeDebugMetadata(){return this.#a}},Et=class e{#e;#t;#n;#r=0;#i=0;constructor(t,n,r){if(t instanceof e&&t.#n===!!r)return t;this.#e=t,this.#t=n,this.#n=!!r}get clipBox(){return this.#e.clipBox}growOperationsCount(){throw Error(`Unreachable`)}save(e){return this.#i++,this.#e.save(this.#t),this}restore(e){return this.#i>0&&(this.#e.restore(this.#t),this.#i--),this}recordOpenMarker(e){return this.#r++,this}getOpenMarker(){return this.#r>0?this.#t:this.#e.getOpenMarker()}recordCloseMarker(e){return this.#r--,this}beginMarkedContent(e){return this}endMarkedContent(e){return this}pushBaseTransform(e){return this.#e.pushBaseTransform(e),this}popBaseTransform(){return this.#e.popBaseTransform(),this}recordSimpleData(e,t){return this.#e.recordSimpleData(e,this.#t),this}recordIncrementalData(e,t){return this.#e.recordIncrementalData(e,this.#t),this}resetIncrementalData(e,t){return this.#e.resetIncrementalData(e,this.#t),this}recordNamedData(e,t){return this}recordSimpleDataFromNamed(e,t,n){return this.#e.recordSimpleDataFromNamed(e,t,this.#t),this}recordFutureForcedDependency(e,t){return this.#e.recordFutureForcedDependency(e,this.#t),this}inheritSimpleDataAsFutureForcedDependencies(e){return this.#e.inheritSimpleDataAsFutureForcedDependencies(e),this}inheritPendingDependenciesAsFutureForcedDependencies(){return this.#e.inheritPendingDependenciesAsFutureForcedDependencies(),this}resetBBox(e){return this.#n||this.#e.resetBBox(this.#t),this}recordClipBox(e,t,n,r,i,a){return this.#n||this.#e.recordClipBox(this.#t,t,n,r,i,a),this}recordBBox(e,t,n,r,i,a){return this.#n||this.#e.recordBBox(this.#t,t,n,r,i,a),this}recordCharacterBBox(e,t,n,r,i,a,o){return this.#n||this.#e.recordCharacterBBox(this.#t,t,n,r,i,a,o),this}recordFullPageBBox(e){return this.#n||this.#e.recordFullPageBBox(this.#t),this}getSimpleIndex(e){return this.#e.getSimpleIndex(e)}recordDependencies(e,t){return this.#e.recordDependencies(this.#t,t),this}recordNamedDependency(e,t){return this.#e.recordNamedDependency(this.#t,t),this}recordOperation(e){return this.#e.recordOperation(this.#t,!0),this}recordShowTextOperation(e){return this.#e.recordShowTextOperation(this.#t,!0),this}bboxToClipBoxDropOperation(e){return this.#n||this.#e.bboxToClipBoxDropOperation(this.#t,!0),this}take(){throw Error(`Unreachable`)}takeDebugMetadata(){throw Error(`Unreachable`)}},Dt={stroke:[`path`,`transform`,`filter`,`strokeColor`,`strokeAlpha`,`lineWidth`,`lineCap`,`lineJoin`,`miterLimit`,`dash`],fill:[`path`,`transform`,`filter`,`fillColor`,`fillAlpha`,`globalCompositeOperation`,`SMask`],imageXObject:[`transform`,`SMask`,`filter`,`fillAlpha`,`strokeAlpha`,`globalCompositeOperation`],rawFillPath:[`filter`,`fillColor`,`fillAlpha`],showText:[`transform`,`leading`,`charSpacing`,`wordSpacing`,`hScale`,`textRise`,`moveText`,`textMatrix`,`font`,`fontObj`,`filter`,`fillColor`,`textRenderingMode`,`SMask`,`fillAlpha`,`strokeAlpha`,`globalCompositeOperation`,`sameLineText`],transform:[`transform`],transformAndFill:[`transform`,`fillColor`]},Ot=class e{#e;#t;#n=4;#r=0;#i=new e.#a(this.#n*6);static#a=z.isFloat16ArraySupported?Float16Array:Float32Array;constructor(e){this.#e=e.width,this.#t=e.height}record(t,n,r,i){if(this.#r===this.#n){this.#n*=2;let t=new e.#a(this.#n*6);t.set(this.#i),this.#i=t}let o=W(t),s;if(i[0]!==1/0){let e=a.slice();B.axialAlignedBoundingBox([0,-r,n,0],o,e);let t=B.intersect(i,e);if(!t)return;let[c,l,u,d]=t;if(c!==e[0]||l!==e[1]||u!==e[2]||d!==e[3]){let e=Math.atan2(o[1],o[0]),t=Math.abs(Math.sin(e)),n=Math.abs(Math.cos(e));if(t<1e-6||n<1e-6||Math.abs(t-n)<1e-6)s=[c,l,c,d,u,l];else{let e=u-c,r=d-l,i=t*t,a=n*n,o=n*t,f=a-i,p=(r*a-e*o)/f;s=[c+(r*o-e*i)/f,l,c,l+p,u,d-p]}}}s||(s=[0,-r,0,0,n,-r],B.applyTransform(s,o,0),B.applyTransform(s,o,2),B.applyTransform(s,o,4)),s[0]/=this.#e,s[1]/=this.#t,s[2]/=this.#e,s[3]/=this.#t,s[4]/=this.#e,s[5]/=this.#t,this.#i.set(s,this.#r*6),this.#r++}take(){return this.#i.subarray(0,this.#r*6)}},kt=class{#e=new Set;#t=null;constructor({ownerDocument:e=globalThis.document,styleElement:t=null}){this._document=e,this.nativeFontFaces=new Set,this.styleElement=null,this.loadingRequests=[],this.loadTestFontId=0}addNativeFontFace(e){this.nativeFontFaces.add(e),this._document.fonts.add(e)}removeNativeFontFace(e){this.nativeFontFaces.delete(e),this._document.fonts.delete(e)}insertRule(e){let t=this.#n();t.insertRule(e,t.cssRules.length)}#n(){if(this.#t)return this.#t;let e=this._document.defaultView?.CSSStyleSheet||globalThis.CSSStyleSheet;if(!this.styleElement&&e){let{adoptedStyleSheets:t}=this._document;if(t){let n=new e;return t.push(n),this.#t=n}}return this.styleElement||(this.styleElement=this._document.createElement(`style`),this._document.documentElement.getElementsByTagName(`head`)[0].append(this.styleElement)),this.#t=this.styleElement.sheet}clear(){for(let e of this.nativeFontFaces)this._document.fonts.delete(e);if(this.nativeFontFaces.clear(),this.#e.clear(),this.#t){let{adoptedStyleSheets:e}=this._document;e?.includes(this.#t)&&(this._document.adoptedStyleSheets=e.filter(e=>e!==this.#t)),this.#t=null}this.styleElement&&=(this.styleElement.remove(),null)}async loadSystemFont({systemFontInfo:e,disableFontFace:t,_inspectFont:n}){if(!(!e||this.#e.has(e.loadedName))){if(A(!t,"loadSystemFont shouldn't be called when `disableFontFace` is set."),this.isFontLoadingAPISupported){let{loadedName:t,src:r,style:i}=e,a=new FontFace(t,r,i);this.addNativeFontFace(a);try{await a.load(),this.#e.add(t),n?.(e)}catch{O(`Cannot load system font: ${e.baseFontName}, installing it could help to improve PDF rendering.`),this.removeNativeFontFace(a)}return}k(`Not implemented: loadSystemFont without the Font Loading API.`)}}async bind(e){if(e.attached||e.missingFile&&!e.systemFontInfo)return;if(e.attached=!0,e.systemFontInfo){await this.loadSystemFont(e);return}if(this.isFontLoadingAPISupported){let t=e.createNativeFontFace();if(t){this.addNativeFontFace(t);try{await t.loaded}catch(n){throw O(`Failed to load font '${t.family}': '${n}'.`),e.disableFontFace=!0,n}}return}let t=e.createFontFaceRule();if(t){if(this.insertRule(t),this.isSyncFontLoadingSupported)return;await new Promise(t=>{let n=this._queueLoadingCallback(t);this._prepareFontLoadEvent(e,n)})}}get isFontLoadingAPISupported(){let e=!!this._document?.fonts;return F(this,`isFontLoadingAPISupported`,e)}get isSyncFontLoadingSupported(){return F(this,`isSyncFontLoadingSupported`,i||z.platform.isFirefox)}_queueLoadingCallback(e){function t(){for(A(!r.done,`completeRequest() cannot be called twice.`),r.done=!0;n.length>0&&n[0].done;){let e=n.shift();setTimeout(e.callback,0)}}let{loadingRequests:n}=this,r={done:!1,complete:t,callback:e};return n.push(r),r}get _loadTestFont(){let e=atob(`T1RUTwALAIAAAwAwQ0ZGIDHtZg4AAAOYAAAAgUZGVE1lkzZwAAAEHAAAABxHREVGABQAFQAABDgAAAAeT1MvMlYNYwkAAAEgAAAAYGNtYXABDQLUAAACNAAAAUJoZWFk/xVFDQAAALwAAAA2aGhlYQdkA+oAAAD0AAAAJGhtdHgD6AAAAAAEWAAAAAZtYXhwAAJQAAAAARgAAAAGbmFtZVjmdH4AAAGAAAAAsXBvc3T/hgAzAAADeAAAACAAAQAAAAEAALZRFsRfDzz1AAsD6AAAAADOBOTLAAAAAM4KHDwAAAAAA+gDIQAAAAgAAgAAAAAAAAABAAADIQAAAFoD6AAAAAAD6AABAAAAAAAAAAAAAAAAAAAAAQAAUAAAAgAAAAQD6AH0AAUAAAKKArwAAACMAooCvAAAAeAAMQECAAACAAYJAAAAAAAAAAAAAQAAAAAAAAAAAAAAAFBmRWQAwAAuAC4DIP84AFoDIQAAAAAAAQAAAAAAAAAAACAAIAABAAAADgCuAAEAAAAAAAAAAQAAAAEAAAAAAAEAAQAAAAEAAAAAAAIAAQAAAAEAAAAAAAMAAQAAAAEAAAAAAAQAAQAAAAEAAAAAAAUAAQAAAAEAAAAAAAYAAQAAAAMAAQQJAAAAAgABAAMAAQQJAAEAAgABAAMAAQQJAAIAAgABAAMAAQQJAAMAAgABAAMAAQQJAAQAAgABAAMAAQQJAAUAAgABAAMAAQQJAAYAAgABWABYAAAAAAAAAwAAAAMAAAAcAAEAAAAAADwAAwABAAAAHAAEACAAAAAEAAQAAQAAAC7//wAAAC7////TAAEAAAAAAAABBgAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAAAAAD/gwAyAAAAAQAAAAAAAAAAAAAAAAAAAAABAAQEAAEBAQJYAAEBASH4DwD4GwHEAvgcA/gXBIwMAYuL+nz5tQXkD5j3CBLnEQACAQEBIVhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYAAABAQAADwACAQEEE/t3Dov6fAH6fAT+fPp8+nwHDosMCvm1Cvm1DAz6fBQAAAAAAAABAAAAAMmJbzEAAAAAzgTjFQAAAADOBOQpAAEAAAAAAAAADAAUAAQAAAABAAAAAgABAAAAAAAAAAAD6AAAAAAAAA==`);return F(this,`_loadTestFont`,e)}_prepareFontLoadEvent(e,t){function n(e,t){return e.charCodeAt(t)<<24|e.charCodeAt(t+1)<<16|e.charCodeAt(t+2)<<8|e.charCodeAt(t+3)&255}function r(e){return String.fromCharCode(e>>24&255,e>>16&255,e>>8&255,e&255)}function i(e,t,n,r){let i=e.substring(0,t),a=e.substring(t+n);return i+r+a}let a,o,s=this._document.createElement(`canvas`);s.width=1,s.height=1;let c=s.getContext(`2d`),l=0;function u(e,t){if(++l>30){O(`Load test font never loaded.`),t();return}if(c.font=`30px `+e,c.fillText(`.`,0,20),c.getImageData(0,0,1,1).data[3]>0){t();return}setTimeout(u.bind(null,e,t))}let d=`lt${Date.now()}${this.loadTestFontId++}`,f=this._loadTestFont;f=i(f,976,d.length,d);let p=1482184792,m=n(f,16);for(a=0,o=d.length-3;a{g.remove(),t.complete()})}},At=class{compiledGlyphs=Object.create(null);#e;constructor(e,t=null,n,r){this.#e=e,this._inspectFont=t,n&&(this.charProcOperatorList=n),r&&Object.assign(this,r)}createNativeFontFace(){if(!this.data||this.disableFontFace)return null;let e;if(!this.cssFontInfo)e=new FontFace(this.loadedName,this.data,{});else{let t={weight:this.cssFontInfo.fontWeight};this.cssFontInfo.italicAngle&&(t.style=`oblique ${this.cssFontInfo.italicAngle}deg`),e=new FontFace(this.cssFontInfo.fontFamily,this.data,t)}return this._inspectFont?.(this),e}createFontFaceRule(){if(!this.data||this.disableFontFace)return null;let e=`url(data:${this.mimetype};base64,${this.data.toBase64()});`,t;if(!this.cssFontInfo)t=`@font-face {font-family:"${this.loadedName}";src:${e}}`;else{let n=`font-weight: ${this.cssFontInfo.fontWeight};`;this.cssFontInfo.italicAngle&&(n+=`font-style: oblique ${this.cssFontInfo.italicAngle}deg;`),t=`@font-face {font-family:"${this.cssFontInfo.fontFamily}";${n}src:${e}}`}return this._inspectFont?.(this,e),t}getPathGenerator(e,t){if(this.compiledGlyphs[t]!==void 0)return this.compiledGlyphs[t];let n=this.loadedName+`_path_`+t,r;try{r=e.get(n)}catch(e){O(`getPathGenerator - ignoring character: "${e}".`)}let i=Je(r?.path);return this.fontExtraProperties||e.delete(n),this.compiledGlyphs[t]=i}get black(){return this.#e.black}get bold(){return this.#e.bold}get disableFontFace(){return this.#e.disableFontFace}set disableFontFace(e){F(this,`disableFontFace`,!!e)}get fontExtraProperties(){return this.#e.fontExtraProperties}get isInvalidPDFjsFont(){return this.#e.isInvalidPDFjsFont}get isType3Font(){return this.#e.isType3Font}get italic(){return this.#e.italic}get missingFile(){return this.#e.missingFile}get remeasure(){return this.#e.remeasure}get vertical(){return this.#e.vertical}get ascent(){return this.#e.ascent}get defaultWidth(){return this.#e.defaultWidth}get descent(){return this.#e.descent}get bbox(){return this.#e.bbox}get fontMatrix(){return this.#e.fontMatrix}get fallbackName(){return this.#e.fallbackName}get loadedName(){return this.#e.loadedName}get mimetype(){return this.#e.mimetype}get name(){return this.#e.name}get data(){return this.#e.data}clearData(){this.#e.clearData()}get cssFontInfo(){return this.#e.cssFontInfo}get systemFontInfo(){return this.#e.systemFontInfo}get defaultVMetrics(){return this.#e.defaultVMetrics}},jt=class{static strings=[`fontFamily`,`fontWeight`,`italicAngle`]},Mt=class{static strings=[`css`,`loadedName`,`baseFontName`,`src`]},Nt=class{static bools=[`black`,`bold`,`disableFontFace`,`fontExtraProperties`,`isInvalidPDFjsFont`,`isType3Font`,`italic`,`missingFile`,`remeasure`,`vertical`];static numbers=[`ascent`,`defaultWidth`,`descent`];static strings=[`fallbackName`,`loadedName`,`mimetype`,`name`];static OFFSET_NUMBERS=Math.ceil(this.bools.length*2/8);static OFFSET_BBOX=this.OFFSET_NUMBERS+this.numbers.length*8;static OFFSET_FONT_MATRIX=this.OFFSET_BBOX+1+8;static OFFSET_DEFAULT_VMETRICS=this.OFFSET_FONT_MATRIX+1+48;static OFFSET_STRINGS=this.OFFSET_DEFAULT_VMETRICS+1+6},Pt=class{static KIND=0;static HAS_BBOX=1;static HAS_BACKGROUND=2;static SHADING_TYPE=3;static N_COORD=4;static N_COLOR=8;static N_STOP=12;static N_FIGURES=16},Ft=class{#e;#t=new TextDecoder;#n;constructor(e){this.#e=e,this.#n=new DataView(e)}#r(e){A(e>n&3;return r===0?void 0:r===2}get black(){return this.#r(0)}get bold(){return this.#r(1)}get disableFontFace(){return this.#r(2)}get fontExtraProperties(){return this.#r(3)}get isInvalidPDFjsFont(){return this.#r(4)}get isType3Font(){return this.#r(5)}get italic(){return this.#r(6)}get missingFile(){return this.#r(7)}get remeasure(){return this.#r(8)}get vertical(){return this.#r(9)}#i(e){return A(e0){t=a.slice();for(let e=0,n=l.length;etypeof e==`object`&&Number.isInteger(e?.num)&&e.num>=0&&Number.isInteger(e?.gen)&&e.gen>=0,Wt=de.bind(null,Ut,e=>typeof e==`object`&&typeof e?.name==`string`),Gt=class{#e=new Map;#t=Promise.resolve();postMessage(e,t){let n={data:structuredClone(e,t?{transfer:t}:null)};this.#t.then(()=>{for(let[e]of this.#e)e.call(this,n)})}addEventListener(e,t,n=null){let r=null;if(n?.signal instanceof AbortSignal){let{signal:i}=n;if(i.aborted){O("LoopbackPort - cannot use an `aborted` signal.");return}let a=()=>this.removeEventListener(e,t);r=()=>i.removeEventListener(`abort`,a),i.addEventListener(`abort`,a)}this.#e.set(t,r)}removeEventListener(e,t){this.#e.get(t)?.(),this.#e.delete(t)}terminate(){for(let[,e]of this.#e)e?.();this.#e.clear()}};r(1689);var Kt={DATA:1,ERROR:2},q={CANCEL:1,CANCEL_COMPLETE:2,CLOSE:3,ENQUEUE:4,ERROR:5,PULL:6,PULL_COMPLETE:7,START_COMPLETE:8};function qt(){}function J(e){if(e instanceof re||e instanceof ee||e instanceof L||e instanceof te||e instanceof R)return e;switch(e instanceof Error||typeof e==`object`&&e||k(`wrapReason: Expected "reason" to be a (possibly cloned) Error.`),e.name){case`AbortException`:return new re(e.message);case`InvalidPDFException`:return new ee(e.message);case`PasswordException`:return new L(e.message,e.code);case`ResponseException`:return new te(e.message,e.status,e.missing);case`UnknownErrorException`:return new R(e.message,e.details)}return new R(e.message,e.toString())}var Jt=class{#e=new AbortController;constructor(e,t,n){this.sourceName=e,this.targetName=t,this.comObj=n,this.callbackId=1,this.streamId=1,this.streamSinks=Object.create(null),this.streamControllers=Object.create(null),this.callbackCapabilities=Object.create(null),this.actionHandler=Object.create(null),n.addEventListener(`message`,this.#t.bind(this),{signal:this.#e.signal})}#t({data:e}){if(e.targetName!==this.sourceName)return;if(e.stream){this.#r(e);return}if(e.callback){let t=e.callbackId,n=this.callbackCapabilities[t];if(!n)throw Error(`Cannot resolve callback ${t}`);if(delete this.callbackCapabilities[t],e.callback===Kt.DATA)n.resolve(e.data);else if(e.callback===Kt.ERROR)n.reject(J(e.reason));else throw Error(`Unexpected callback case`);return}let t=this.actionHandler[e.action];if(!t)throw Error(`Unknown action from worker: ${e.action}`);if(e.callbackId){let n=this.sourceName,r=e.sourceName,i=this.comObj;Promise.try(t,e.data).then(function(t){i.postMessage({sourceName:n,targetName:r,callback:Kt.DATA,callbackId:e.callbackId,data:t})},function(t){i.postMessage({sourceName:n,targetName:r,callback:Kt.ERROR,callbackId:e.callbackId,reason:J(t)})});return}if(e.streamId){this.#n(e);return}t(e.data)}on(e,t){let n=this.actionHandler;if(n[e])throw Error(`There is already an actionName called "${e}"`);n[e]=t}send(e,t,n){this.comObj.postMessage({sourceName:this.sourceName,targetName:this.targetName,action:e,data:t},n)}sendWithPromise(e,t,n){let r=this.callbackId++,i=Promise.withResolvers();this.callbackCapabilities[r]=i;try{this.comObj.postMessage({sourceName:this.sourceName,targetName:this.targetName,action:e,callbackId:r,data:t},n)}catch(e){i.reject(e)}return i.promise}sendWithStream(e,t,n,r){let i=this.streamId++,a=this.sourceName,o=this.targetName,s=this.comObj;return new ReadableStream({start:n=>{let c=Promise.withResolvers();return this.streamControllers[i]={controller:n,startCall:c,pullCall:null,cancelCall:null,isClosed:!1},s.postMessage({sourceName:a,targetName:o,action:e,streamId:i,data:t,desiredSize:n.desiredSize},r),c.promise},pull:e=>{let t=Promise.withResolvers();return this.streamControllers[i].pullCall=t,s.postMessage({sourceName:a,targetName:o,stream:q.PULL,streamId:i,desiredSize:e.desiredSize}),t.promise},cancel:e=>{A(e instanceof Error,`cancel must have a valid reason`);let t=Promise.withResolvers();return this.streamControllers[i].cancelCall=t,this.streamControllers[i].isClosed=!0,s.postMessage({sourceName:a,targetName:o,stream:q.CANCEL,streamId:i,reason:J(e)}),t.promise}},n)}#n(e){let t=e.streamId,n=this.sourceName,r=e.sourceName,i=this.comObj,a=this,o=this.actionHandler[e.action],s={enqueue(e,a=1,o){if(this.isCancelled)return;let s=this.desiredSize;this.desiredSize-=a,s>0&&this.desiredSize<=0&&(this.sinkCapability=Promise.withResolvers(),this.ready=this.sinkCapability.promise),i.postMessage({sourceName:n,targetName:r,stream:q.ENQUEUE,streamId:t,chunk:e},o)},close(){this.isCancelled||(this.isCancelled=!0,i.postMessage({sourceName:n,targetName:r,stream:q.CLOSE,streamId:t}),delete a.streamSinks[t])},error(e){A(e instanceof Error,`error must have a valid reason`),!this.isCancelled&&(this.isCancelled=!0,i.postMessage({sourceName:n,targetName:r,stream:q.ERROR,streamId:t,reason:J(e)}))},sinkCapability:Promise.withResolvers(),onPull:null,onCancel:null,isCancelled:!1,desiredSize:e.desiredSize,ready:null};s.sinkCapability.resolve(),s.ready=s.sinkCapability.promise,this.streamSinks[t]=s,Promise.try(o,e.data,s).then(function(){i.postMessage({sourceName:n,targetName:r,stream:q.START_COMPLETE,streamId:t,success:!0})},function(e){i.postMessage({sourceName:n,targetName:r,stream:q.START_COMPLETE,streamId:t,reason:J(e)})})}#r(e){let t=e.streamId,n=this.sourceName,r=e.sourceName,i=this.comObj,a=this.streamControllers[t],o=this.streamSinks[t];switch(e.stream){case q.START_COMPLETE:e.success?a.startCall.resolve():a.startCall.reject(J(e.reason));break;case q.PULL_COMPLETE:e.success?a.pullCall.resolve():a.pullCall.reject(J(e.reason));break;case q.PULL:if(!o){i.postMessage({sourceName:n,targetName:r,stream:q.PULL_COMPLETE,streamId:t,success:!0});break}o.desiredSize<=0&&e.desiredSize>0&&o.sinkCapability.resolve(),o.desiredSize=e.desiredSize,Promise.try(o.onPull||qt).then(function(){i.postMessage({sourceName:n,targetName:r,stream:q.PULL_COMPLETE,streamId:t,success:!0})},function(e){i.postMessage({sourceName:n,targetName:r,stream:q.PULL_COMPLETE,streamId:t,reason:J(e)})});break;case q.ENQUEUE:if(A(a,`enqueue should have stream controller`),a.isClosed)break;a.controller.enqueue(e.chunk);break;case q.CLOSE:if(A(a,`close should have stream controller`),a.isClosed)break;a.isClosed=!0,a.controller.close(),this.#i(a,t);break;case q.ERROR:A(a,`error should have stream controller`),a.controller.error(J(e.reason)),this.#i(a,t);break;case q.CANCEL_COMPLETE:e.success?a.cancelCall.resolve():a.cancelCall.reject(J(e.reason)),this.#i(a,t);break;case q.CANCEL:if(!o)break;let s=J(e.reason);Promise.try(o.onCancel||qt,s).then(function(){i.postMessage({sourceName:n,targetName:r,stream:q.CANCEL_COMPLETE,streamId:t,success:!0})},function(e){i.postMessage({sourceName:n,targetName:r,stream:q.CANCEL_COMPLETE,streamId:t,reason:J(e)})}),o.sinkCapability.reject(s),o.isCancelled=!0,delete this.streamSinks[t];break;default:throw Error(`Unexpected stream case`)}}async#i(e,t){await Promise.allSettled([e.startCall?.promise,e.pullCall?.promise,e.cancelCall?.promise]),delete this.streamControllers[t]}destroy(){this.#e?.abort(),this.#e=null}},Yt=class{#e=Object.freeze({cMapUrl:`CMap`,standardFontDataUrl:`font`,wasmUrl:`wasm`});constructor({cMapUrl:e=null,standardFontDataUrl:t=null,wasmUrl:n=null}){this.cMapUrl=e,this.standardFontDataUrl=t,this.wasmUrl=n}async fetch({kind:e,filename:t}){switch(e){case`cMapUrl`:case`standardFontDataUrl`:case`wasmUrl`:break;default:k(`Not implemented: ${e}`)}let n=this[e];if(!n)throw Error(`Ensure that the \`${e}\` API parameter is provided.`);let r=`${n}${t}`;return this._fetch(r,e).catch(t=>{throw Error(`Unable to load ${this.#e[e]} data at: ${r}`)})}async _fetch(e,t){k("Abstract method `_fetch` called.")}},Xt=class extends Yt{async _fetch(e,t){let n=await Se(e,t===`cMapUrl`&&!e.endsWith(`.bcmap`)?`text`:`bytes`);return n instanceof Uint8Array?n:ae(n)}},Zt=class{#e=!1;constructor({enableHWA:e=!1}){this.#e=e}create(e,t){if(e<=0||t<=0)throw Error(`Invalid canvas size`);let n=this._createCanvas(e,t);return{canvas:n,context:n.getContext(`2d`,{willReadFrequently:!this.#e})}}reset({canvas:e},t,n){if(!e)throw Error(`Canvas is not specified`);if(t<=0||n<=0)throw Error(`Invalid canvas size`);e.width=t,e.height=n}destroy(e){let{canvas:t}=e;if(!t)throw Error(`Canvas is not specified`);t.width=t.height=0,e.canvas=null,e.context=null}_createCanvas(e,t){k("Abstract method `_createCanvas` called.")}},Qt=class extends Zt{constructor({ownerDocument:e=globalThis.document,enableHWA:t=!1}){super({enableHWA:t}),this._document=e}_createCanvas(e,t){let n=this._document.createElement(`canvas`);return n.width=e,n.height=t,n}},$t=class{addFilter(e){return`none`}addHCMFilter(e,t){return`none`}addAlphaFilter(e){return`none`}addLuminosityFilter(e){return`none`}addKnockoutFilter(e=0){return`none`}addHighlightHCMFilter(e,t,n,r,i){return`none`}addSelectionHCMFilter(e,t){return`none`}addSelectionFilter(){return`none`}createSelectionStyle(e=null){return null}destroy(e=!1){}},en=class extends $t{#e;#t;#n;#r;#i;#a;#o=0;constructor({docId:e,ownerDocument:t=globalThis.document}){super(),this.#r=e,this.#i=t}get#s(){return this.#t||=new Map}get#c(){return this.#a||=new Map}get#l(){if(!this.#n){let e=this.#i.createElement(`div`),{style:t}=e;t.colorScheme=`only light`,t.visibility=`hidden`,t.contain=`strict`,t.width=t.height=0,t.position=`absolute`,t.top=t.left=0,t.zIndex=-1;let n=this.#i.createElementNS(c,`svg`);n.setAttribute(`width`,0),n.setAttribute(`height`,0),this.#n=this.#i.createElementNS(c,`defs`),e.append(n),n.append(this.#n),this.#i.body.append(e)}return this.#n}#u(e){if(e.length===1){let t=e[0],n=Array(256);for(let e=0;e<256;e++)n[e]=t[e]/255;let r=n.join(`,`);return[r,r,r]}let[t,n,r]=e,i=Array(256),a=Array(256),o=Array(256);for(let e=0;e<256;e++)i[e]=t[e]/255,a[e]=n[e]/255,o[e]=r[e]/255;return[i.join(`,`),a.join(`,`),o.join(`,`)]}#d(e){if(this.#e===void 0){this.#e=``;let e=this.#i.URL;e!==this.#i.baseURI&&(we(e)?O(`#createUrl: ignore "data:"-URL for performance reasons.`):this.#e=N(e,``))}return`url(${this.#e}#${e})`}addFilter(e){if(!e)return`none`;let t=this.#s.get(e);if(t)return t;let[n,r,i]=this.#u(e),a=e.length===1?n:`${n}${r}${i}`;if(t=this.#s.get(a),t)return this.#s.set(e,t),t;let o=`g_${this.#r}_transfer_map_${this.#o++}`,s=this.#d(o);this.#s.set(e,s),this.#s.set(a,s);let c=this.#m(o);return this.#g(n,r,i,c),s}addHCMFilter(e,t){let n=`${e}-${t}`,r=`base`,i=this.#c.get(r);if(i?.key===n||(i?(i.filter?.remove(),i.key=n,i.url=`none`,i.filter=null):(i={key:n,url:`none`,filter:null},this.#c.set(r,i)),!e||!t))return i.url;let a=this.#v(e);e=B.makeHexColor(...a);let o=this.#v(t);if(t=B.makeHexColor(...o),this.#b(),e===`#000000`&&t===`#ffffff`||e===t)return i.url;let s=Array(256);for(let e=0;e<=255;e++){let t=e/255;s[e]=t<=.03928?t/12.92:((t+.055)/1.055)**2.4}let c=s.join(`,`),l=`g_${this.#r}_hcm_filter`,u=i.filter=this.#m(l);this.#g(c,c,c,u),this.#p(u);let d=(e,t)=>{let n=a[e]/255,r=o[e]/255,i=Array(t+1);for(let e=0;e<=t;e++)i[e]=n+e/t*(r-n);return i.join(`,`)};return this.#g(d(0,5),d(1,5),d(2,5),u),i.url=this.#d(l),i.url}addSelectionHCMFilter(e,t){return this.addHighlightHCMFilter(`selection`,e,t,`HighlightText`,`Highlight`)}addSelectionFilter(){return this.addHighlightHCMFilter(`selection_default`,`black`,`white`,`HighlightText`,`Highlight`)}createSelectionStyle(e=null){let t=e?this.addSelectionHCMFilter(e.foreground,e.background):this.addSelectionFilter();return t===`none`||!z.platform.isFirefox?null:{"backdrop-filter":t,"background-color":`transparent`}}addAlphaFilter(e){let t=this.#s.get(e);if(t)return t;let[n]=this.#u([e]),r=`alpha_${n}`;if(t=this.#s.get(r),t)return this.#s.set(e,t),t;let i=`g_${this.#r}_alpha_map_${this.#o++}`,a=this.#d(i);this.#s.set(e,a),this.#s.set(r,a);let o=this.#m(i);return this.#_(n,o),a}addLuminosityFilter(e){let t=this.#s.get(e||`luminosity`);if(t)return t;let n,r;if(e?([n]=this.#u([e]),r=`luminosity_${n}`):r=`luminosity`,t=this.#s.get(r),t)return this.#s.set(e,t),t;let i=`g_${this.#r}_luminosity_map_${this.#o++}`,a=this.#d(i);this.#s.set(e,a),this.#s.set(r,a);let o=this.#m(i);return this.#f(o),e&&this.#_(n,o),a}addKnockoutFilter(e=0){let t=e>0?Math.min(1/e,1e6):1e6,n=`knockout_${t}`,r=this.#s.get(n);if(r)return r;let i=`g_${this.#r}_knockout_filter_${this.#o++}`,a=this.#d(i);this.#s.set(n,a);let o=this.#m(i),s=this.#i.createElementNS(c,`feComponentTransfer`);o.append(s);let l=this.#i.createElementNS(c,`feFuncA`);return l.setAttribute(`type`,`linear`),l.setAttribute(`slope`,`${t}`),l.setAttribute(`intercept`,`0`),s.append(l),a}addHighlightHCMFilter(e,t,n,r,i){let a=`${t}-${n}-${r}-${i}`,o=this.#c.get(e);if(o?.key===a||(o?(o.filter?.remove(),o.key=a,o.url=`none`,o.filter=null):(o={key:a,url:`none`,filter:null},this.#c.set(e,o)),!t||!n))return o.url;let[s,c]=[t,n].map(this.#v.bind(this)),l=Math.round(.2126*s[0]+.7152*s[1]+.0722*s[2]),u=Math.round(.2126*c[0]+.7152*c[1]+.0722*c[2]),[d,f]=[r,i].map(this.#x.bind(this));u{let r=Array(256),i=(u-l)/n,a=e/255,o=(t-e)/(255*n),s=0;for(let e=0;e<=n;e++){let t=Math.round(l+e*i),n=a+e*o;for(let e=s;e<=t;e++)r[e]=n;s=t+1}for(let e=s;e<256;e++)r[e]=r[s-1];return r.join(`,`)},m=`g_${this.#r}_hcm_${e}_filter`,h=o.filter=this.#m(m);return this.#p(h),this.#g(p(d[0],f[0],5),p(d[1],f[1],5),p(d[2],f[2],5),h),o.url=this.#d(m),o.url}destroy(e=!1){e&&this.#a?.size||(this.#n?.parentNode.parentNode.remove(),this.#n=null,this.#t?.clear(),this.#t=null,this.#a?.clear(),this.#a=null,this.#o=0)}#f(e){let t=this.#i.createElementNS(c,`feColorMatrix`);t.setAttribute(`type`,`matrix`),t.setAttribute(`values`,`0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.3 0.59 0.11 0 0`),e.append(t)}#p(e){let t=this.#i.createElementNS(c,`feColorMatrix`);t.setAttribute(`type`,`matrix`),t.setAttribute(`values`,`0.2126 0.7152 0.0722 0 0 0.2126 0.7152 0.0722 0 0 0.2126 0.7152 0.0722 0 0 0 0 0 1 0`),e.append(t)}#m(e){let t=this.#i.createElementNS(c,`filter`);return t.setAttribute(`color-interpolation-filters`,`sRGB`),t.setAttribute(`id`,e),this.#l.append(t),t}#h(e,t,n){let r=this.#i.createElementNS(c,t);r.setAttribute(`type`,`discrete`),r.setAttribute(`tableValues`,n),e.append(r)}#g(e,t,n,r){let i=this.#i.createElementNS(c,`feComponentTransfer`);r.append(i),this.#h(i,`feFuncR`,e),this.#h(i,`feFuncG`,t),this.#h(i,`feFuncB`,n)}#_(e,t){let n=this.#i.createElementNS(c,`feComponentTransfer`);t.append(n),this.#h(n,`feFuncA`,e)}#v(e){return this.#l.style.color=`CanvasText`,this.#l.style.backgroundColor=e,Me(getComputedStyle(this.#l).getPropertyValue(`background-color`))}#y(e){return this.#l.style.color=`CanvasText`,this.#l.style.backgroundColor=e,je(getComputedStyle(this.#l).getPropertyValue(`background-color`))}#b(){this.#l.style.color=``,this.#l.style.backgroundColor=``}#x(e){let[t,n,r,i]=this.#y(e);if(i===1)return[t,n,r];let[a,o,s]=this.#v(`Canvas`);return[tn(t,a,i),tn(n,o,i),tn(r,s,i)]}};function tn(e,t,n){return Math.round(n*e+(1-n)*t)}if(i){let e;try{let t=process.getBuiltinModule(`module`).createRequire(import.meta.url);try{e=t("@napi-rs/canvas")}catch(e){O(`Cannot load "@napi-rs/canvas" package: "${e}".`)}}catch(e){O(`Cannot access the \`require\` function: "${e}".`)}globalThis.DOMMatrix||(e?.DOMMatrix?globalThis.DOMMatrix=e.DOMMatrix:O("Cannot polyfill `DOMMatrix`, rendering may be broken.")),globalThis.Path2D||(e?.Path2D?globalThis.Path2D=e.Path2D:O("Cannot polyfill `Path2D`, rendering may be broken.")),globalThis.navigator?.language||(globalThis.navigator={language:`en-US`,platform:``,userAgent:``})}async function nn(e){let t=await process.getBuiltinModule(`fs/promises`).readFile(e);return new Uint8Array(t)}var rn=class extends $t{},an=class extends Zt{_createCanvas(e,t){return process.getBuiltinModule(`module`).createRequire(import.meta.url)(`@napi-rs/canvas`).createCanvas(e,t)}},on=class extends Yt{async _fetch(e,t){return nn(e)}};function sn({src:e,srcPos:t=0,dest:n,width:r,height:i,nonBlackColor:a=4294967295,inverseDecode:o=!1}){let s=z.isLittleEndian?4278190080:255,[c,l]=o?[a,s]:[s,a],u=r>>3,d=r&7,f=c^l,p=e.length;n=new Uint32Array(n.buffer);let m=0;for(let r=0;r>7&1)&f,n[m+1]=c^-(r>>6&1)&f,n[m+2]=c^-(r>>5&1)&f,n[m+3]=c^-(r>>4&1)&f,n[m+4]=c^-(r>>3&1)&f,n[m+5]=c^-(r>>2&1)&f,n[m+6]=c^-(r>>1&1)&f,n[m+7]=c^-(r&1)&f}if(d===0)continue;let r=t>7-e&1)&f}return{srcPos:t,destPos:m}}function cn({src:e,srcPos:t=0,dest:n,destPos:r=0,width:i,height:a}){let o=0,s=i*a*3,c=s>>2,l=new Uint32Array(e.buffer,t,c),u=z.isLittleEndian?4278190080:255;if(z.isLittleEndian){for(;o>>24|t<<8|u,n[r+2]=t>>>16|i<<16|u,n[r+3]=i>>>8|u}for(let i=o*4,a=t+s;i>>8|u,n[r+2]=t<<16|i>>>16|u,n[r+3]=i<<8|u}for(let i=o*4,a=t+s;i - +