diff --git a/CHANGELOG.md b/CHANGELOG.md index a3b946d7f..ca1afae90 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ All notable changes to Bambuddy will be documented in this file. ## [1.2.6b1] - Unreleased ### Fixed +- **The build plate of a powered-down printer can be cleared again (#2864, reported by @bryanmahin)** — With Auto Power Off enabled this is the ordinary end of every print: the job finishes, Bambuddy switches the printer off at the plug, and the plate is left flagged dirty on a machine that is no longer reachable. The operator then walks over, clears the plate, and had no way to say so — `POST /printers/{id}/clear-plate` answered 400 "Printer not connected", and the button was hidden on the printer card, so the physical clear-plate buttons some farms drive over the API went dead too. Everything gated on the flag stayed stuck until each printer was powered back on by hand, cleared, and switched off again, which is the opposite of what Auto Power Off is for. Nothing in clearing a plate talks to the printer: the flag is Bambuddy's own state, persisted in its database precisely so it survives the power cycle, and the check that refused was inherited from the stop, pause and resume handlers next to it, where reaching the printer genuinely is required. It is gone, and the card offers the control whether the printer is online or not — in both card sizes, and for bulk selections, where powered-down printers were being filtered out of a Clear All. This does not dispatch work to an unreachable machine: the queue still requires a live connection before it sends anything, and releasing the gate is what lets it power the printer back on for the next job instead of skipping it. One related gap went with it — a printer with no live connection at all, disconnected by hand or not yet reconnected after a restart, reported its plate as clean over the API regardless of what the database said, which hid the control on exactly the printers that needed it. Wiki updated. Covered by backend and frontend tests. - **H2D archives lost their 3MF, thumbnail and filament data after the last update (#2856, reported by @aishlai)** — When a print starts, the printer says where it put the sliced file, and Bambuddy took `brtc://emmc/` — internal storage — as proof there was nothing to fetch, so it archived the print by name alone. On an H2D with a card in the slot that is not true: the same file sits under `/cache` and downloads without complaint, as it had for that reporter's every print until the change landed. Bambuddy now checks instead of assuming. The printer names the exact file, so confirming it takes one connection across five paths rather than the ~110-connection search that made skipping worth doing — and when the file really is out of reach, as it is on an H2C or P2S with no copy on the card, the archive falls back exactly as before and still says why. The connection diagnostic asks the same question before warning that a print is out of reach. Covered by backend tests. - **A printer with more than one smart plug never recorded energy or energy cost (#2859, reported by @sn8key)** — Linking a second plug to a printer — a dry box, a filter fan, a chamber light you want to switch from the printer card — stopped energy tracking on that printer completely, from the moment the second plug was linked. Per-print energy is the change in one plug's meter between the start and the end of a print, and both readings asked for "the plug on this printer" in a way that accepts one answer and fails on two. The failure was indistinguishable from having no plug at all: the print-end log said no starting reading had been taken, which is also what it says for a printer with nothing linked to it. Bambuddy now picks the printer's own plug — the one marked as supplying its power, and of those the one that actually reports a meter, so accessories drop out on their own — and names the plugs it tried when none of them measures anything. Linking several plugs to a printer is supported and always was; only energy assumed otherwise. Past prints cannot be recovered, since the starting reading was never taken. Covered by backend tests. - **The smart plug page counted an online plug as offline unless it reported energy (#2859)** — A plug with no power sensor is still online, but "N/M plugs online" only counted the ones sending energy figures, so a working switch showed as offline for as long as it stayed linked. The count now reflects whether the plug answers. diff --git a/backend/app/api/routes/printers.py b/backend/app/api/routes/printers.py index 3b740f71c..047301f2b 100644 --- a/backend/app/api/routes/printers.py +++ b/backend/app/api/routes/printers.py @@ -465,10 +465,16 @@ async def get_printer_status( state = printer_manager.get_status(printer_id) if not state: + # No MQTT client state — the printer was never connected this run, or it + # was disconnected manually. The plate-clear gate is Bambuddy-side and + # persisted, so it still has a truthful value here (#2864); reporting the + # schema default instead told clients the plate was clean and hid the + # only control that can release the gate. return PrinterStatus( id=printer_id, name=printer.name, connected=False, + awaiting_plate_clear=printer_manager.is_awaiting_plate_clear(printer_id), ) # Determine cover URL if there's an active print (including paused) @@ -3104,8 +3110,12 @@ async def clear_plate( if not printer: raise HTTPException(404, "Printer not found") - if not printer_manager.is_connected(printer_id): - raise HTTPException(400, "Printer not connected") + # Deliberately NOT gated on the printer being connected. Acknowledging the plate + # only mutates Bambuddy-side state — no MQTT command is sent — and with Auto Power + # Off the normal end-of-print state is exactly this: gate up, printer powered down. + # The guard this replaces was inherited from the sibling stop/pause/resume handlers, + # where reaching the printer IS required, and left farms with no way to release the + # gate short of powering each printer back on by hand (#2864). # Accept the acknowledgment whenever the printer is awaiting it — not only when the # reported state is FINISH/FAILED. After a power cycle the printer boots into IDLE diff --git a/backend/app/services/printer_manager.py b/backend/app/services/printer_manager.py index 0ce074c40..d164bc228 100644 --- a/backend/app/services/printer_manager.py +++ b/backend/app/services/printer_manager.py @@ -493,7 +493,14 @@ class PrinterManager: """ printer = self.get_printer(printer_id) if not printer: - return + # No cached info means no client is registered — the printer was + # disconnected outright rather than merely powered off. The gate is + # still releasable from the API in that state (#2864), and a retained + # MQTT topic left saying "awaiting" would outlive the truth, so fall + # back to the row rather than dropping the emission. + printer = await self._printer_info_from_db(printer_id) + if not printer: + return try: from backend.app.services.mqtt_relay import mqtt_relay @@ -516,6 +523,20 @@ class PrinterManager: except Exception as e: logger.warning("Failed to send plate-clear notification for printer %d: %s", printer_id, e) + async def _printer_info_from_db(self, printer_id: int) -> PrinterInfo | None: + """Name and serial for a printer with no registered client.""" + from backend.app.core.database import async_session + + try: + async with async_session() as db: + row = ( + await db.execute(select(Printer.name, Printer.serial_number).where(Printer.id == printer_id)) + ).first() + except Exception as e: + logger.warning("Failed to load printer %d info from DB: %s", printer_id, e) + return None + return PrinterInfo(row[0], row[1]) if row else None + async def _broadcast_status_change(self, printer_id: int) -> None: """Emit a ``printer_status`` WebSocket update for this printer (#1128). diff --git a/backend/tests/integration/test_printers_api.py b/backend/tests/integration/test_printers_api.py index b595badb9..81b1f616c 100644 --- a/backend/tests/integration/test_printers_api.py +++ b/backend/tests/integration/test_printers_api.py @@ -4370,3 +4370,127 @@ class TestCoverWhenThePrintIsOnInternalStorage: await async_client.get(f"/api/v1/printers/{printer.id}/cover") mock_download.assert_called() + + +class TestClearPlateOnAPoweredDownPrinter: + """Releasing the plate-clear gate must not require a reachable printer. + + #2864: with Auto Power Off the end-of-print state is a dirty plate on a + machine Bambuddy has just switched off. The endpoint answered 400 for + anything not connected, so the operator who physically cleared that plate + had no way to say so — not from the API, not from the UI — and everything + gated on the flag stayed stuck until the printer was powered back on by + hand. Nothing in the clear path talks to the printer: the flag is + Bambuddy-side and persisted. + """ + + @pytest.mark.asyncio + @pytest.mark.integration + async def test_clear_plate_succeeds_while_disconnected( + self, async_client: AsyncClient, printer_factory, db_session + ): + printer = await printer_factory(name="Powered-off X1C") + # What the smart-plug power-off leaves behind: the client is still + # registered, but its state is blanked to unknown/disconnected. + state = MagicMock(state="unknown", connected=False) + + with ( + patch("backend.app.api.routes.printers.printer_manager.is_connected", return_value=False), + patch("backend.app.api.routes.printers.printer_manager.get_status", return_value=state), + patch( + "backend.app.api.routes.printers.printer_manager.is_awaiting_plate_clear", + return_value=True, + ), + patch("backend.app.api.routes.printers.printer_manager.set_awaiting_plate_clear") as mock_set, + ): + response = await async_client.post(f"/api/v1/printers/{printer.id}/clear-plate") + + assert response.status_code == 200, response.text + mock_set.assert_called_once_with(printer.id, False) + + @pytest.mark.asyncio + @pytest.mark.integration + async def test_clear_plate_succeeds_with_no_client_state_at_all( + self, async_client: AsyncClient, printer_factory, db_session + ): + """A printer disconnected manually, or never connected since the last + restart, has no client state — the persisted gate is still releasable.""" + printer = await printer_factory(name="Never connected") + + with ( + patch("backend.app.api.routes.printers.printer_manager.is_connected", return_value=False), + patch("backend.app.api.routes.printers.printer_manager.get_status", return_value=None), + patch( + "backend.app.api.routes.printers.printer_manager.is_awaiting_plate_clear", + return_value=True, + ), + patch("backend.app.api.routes.printers.printer_manager.set_awaiting_plate_clear") as mock_set, + ): + response = await async_client.post(f"/api/v1/printers/{printer.id}/clear-plate") + + assert response.status_code == 200, response.text + mock_set.assert_called_once_with(printer.id, False) + + @pytest.mark.asyncio + @pytest.mark.integration + async def test_clear_plate_still_rejects_when_there_is_nothing_to_clear( + self, async_client: AsyncClient, printer_factory, db_session + ): + """Dropping the connection guard must not turn the endpoint into a + no-op accept: an offline printer with a clean plate is still a 400.""" + printer = await printer_factory(name="Powered-off, clean plate") + + with ( + patch("backend.app.api.routes.printers.printer_manager.is_connected", return_value=False), + patch("backend.app.api.routes.printers.printer_manager.get_status", return_value=None), + patch( + "backend.app.api.routes.printers.printer_manager.is_awaiting_plate_clear", + return_value=False, + ), + patch("backend.app.api.routes.printers.printer_manager.set_awaiting_plate_clear") as mock_set, + ): + response = await async_client.post(f"/api/v1/printers/{printer.id}/clear-plate") + + assert response.status_code == 400, response.text + mock_set.assert_not_called() + + @pytest.mark.asyncio + @pytest.mark.integration + async def test_plate_clear_state_still_reaches_mqtt_without_a_client( + self, async_client: AsyncClient, printer_factory, db_session + ): + """Clearing the gate on a printer with no registered client must still + update the retained MQTT topic (#2525) — otherwise it keeps telling Home + Assistant the plate is dirty after it was acknowledged.""" + from backend.app.services.printer_manager import printer_manager + + printer = await printer_factory(name="Disconnected P1S") + + info = await printer_manager._printer_info_from_db(printer.id) + + assert info is not None + assert info.name == "Disconnected P1S" + assert info.serial_number == printer.serial_number + + @pytest.mark.asyncio + @pytest.mark.integration + async def test_status_reports_the_gate_without_client_state( + self, async_client: AsyncClient, printer_factory, db_session + ): + """Without this the schema default reported a clean plate for a printer + the DB says is still gated, and the UI hid the control that releases it.""" + printer = await printer_factory(name="No client state") + + with ( + patch("backend.app.api.routes.printers.printer_manager.get_status", return_value=None), + patch( + "backend.app.api.routes.printers.printer_manager.is_awaiting_plate_clear", + return_value=True, + ), + ): + response = await async_client.get(f"/api/v1/printers/{printer.id}/status") + + assert response.status_code == 200, response.text + body = response.json() + assert body["connected"] is False + assert body["awaiting_plate_clear"] is True diff --git a/backend/tests/unit/test_plate_clear_mqtt_notification.py b/backend/tests/unit/test_plate_clear_mqtt_notification.py index 84a3613cd..dcb2b051e 100644 --- a/backend/tests/unit/test_plate_clear_mqtt_notification.py +++ b/backend/tests/unit/test_plate_clear_mqtt_notification.py @@ -234,6 +234,26 @@ class TestEmitFanOut: publish.assert_not_awaited() + @pytest.mark.asyncio + async def test_falls_back_to_the_db_when_no_client_is_registered(self): + """A printer disconnected outright has no cached info, but the gate can + still be released through the API (#2864) — the retained topic must not + be left asserting a state that is no longer true.""" + manager = PrinterManager() + + publish = AsyncMock() + with ( + patch("backend.app.services.mqtt_relay.mqtt_relay.on_plate_clear_state", publish), + patch.object( + PrinterManager, + "_printer_info_from_db", + AsyncMock(return_value=SimpleNamespace(name="Powered-off X1C", serial_number="01P00A000000009")), + ), + ): + await manager._emit_plate_clear_change(9, False) + + publish.assert_awaited_once_with(9, "Powered-off X1C", "01P00A000000009", False) + @pytest.mark.asyncio async def test_mqtt_failure_does_not_block_the_notification(self): manager = PrinterManager() diff --git a/frontend/src/__tests__/pages/PrintersPage.test.tsx b/frontend/src/__tests__/pages/PrintersPage.test.tsx index 219deddaf..af5ae0603 100644 --- a/frontend/src/__tests__/pages/PrintersPage.test.tsx +++ b/frontend/src/__tests__/pages/PrintersPage.test.tsx @@ -496,6 +496,47 @@ describe('PrintersPage', () => { expect(screen.getAllByRole('button', { name: 'Mark plate as cleared' }).length).toBeGreaterThan(0); }); + it('offers the clear action on a powered-down printer (#2864)', async () => { + // Auto Power Off leaves exactly this: gate up, printer unreachable. The + // control used to be hidden here, so a plate cleared by hand could not be + // acknowledged until the printer was powered back on. + let awaitingPlateClear = true; + let cleared = false; + + server.use( + http.get('/api/v1/printers/', () => { + return HttpResponse.json([mockPrinters[0]]); + }), + http.get('/api/v1/printers/:id/status', () => { + return HttpResponse.json({ + ...mockPrinterStatus, + connected: false, + state: 'unknown', + awaiting_plate_clear: awaitingPlateClear, + }); + }), + http.post('/api/v1/printers/:id/clear-plate', () => { + cleared = true; + awaitingPlateClear = false; + return HttpResponse.json({ success: true, message: 'Plate cleared' }); + }) + ); + + render(); + + const clearButton = await screen.findByRole('button', { name: 'Mark plate as cleared' }); + + fireEvent.click(clearButton); + + await waitFor(() => { + expect(cleared).toBe(true); + }); + + await waitFor(() => { + expect(screen.queryByRole('button', { name: 'Mark plate as cleared' })).not.toBeInTheDocument(); + }); + }); + it('updates the plate clear status after using the printer card action', async () => { let awaitingPlateClear = true; diff --git a/frontend/src/pages/PrintersPage.tsx b/frontend/src/pages/PrintersPage.tsx index 4a4f7456f..87b9853c1 100644 --- a/frontend/src/pages/PrintersPage.tsx +++ b/frontend/src/pages/PrintersPage.tsx @@ -2615,7 +2615,10 @@ function PrinterCard({ const lastPrint = lastPrints?.[0]; const isPrintingOrPaused = status?.state === 'RUNNING' || status?.state === 'PAUSE'; const needsPlateClear = requirePlateClear && status?.awaiting_plate_clear === true; - const showClearPlateButton = status?.connected && needsPlateClear && !isPrintingOrPaused; + // Not gated on `connected`: the plate-clear gate is Bambuddy-side state, and with + // Auto Power Off the printer is powered down exactly when the operator clears the + // plate. Hiding the control there left no way to release the gate (#2864). + const showClearPlateButton = needsPlateClear && !isPrintingOrPaused; const activePrintName = status?.current_print && isPrintingOrPaused ? formatPrintName(status.subtask_name || status.current_print || null, status.gcode_file, t, activePlateLabel) : null; @@ -2628,6 +2631,9 @@ function PrinterCard({ } }, [activePrintName, needsPlateClear, status?.cover_url]); const plateStatus = (() => { + // Connected-only because the pill's only render site sits inside the live-status + // panel. For a powered-down printer the plate-clear button itself carries the + // state — see the standalone slot below the status block (#2864). if (!requirePlateClear || !status?.connected) return null; if (isPrintingOrPaused) { return { @@ -2825,6 +2831,26 @@ function PrinterCard({ onError: (error: Error) => showToast(error.message || t('printers.toast.failedToSendCommand'), 'error'), }); + // Rendered from two places: inside the live-status block for a connected printer, + // and standalone below it for a powered-down one, whose status block isn't rendered + // at all (#2864). Shared so the two can't drift apart. + const expandedClearPlateButton = ( + + ); + const nozzleTemperatureMutation = useMutation({ mutationFn: ({ target, nozzle }: { target: number; nozzle: number }) => api.setNozzleTemperature(printer.id, target, nozzle), @@ -4692,22 +4718,7 @@ function PrinterCard({ ); })()} - {viewMode === 'expanded' && showClearPlateButton && ( - - )} + {viewMode === 'expanded' && showClearPlateButton && expandedClearPlateButton} {/* Controls */} {viewMode === 'expanded' && (() => { @@ -6285,6 +6296,14 @@ function PrinterCard({ )} + {/* Powered-down printer with a dirty plate: the status block above renders + nothing without a live connection, so the plate-clear control gets its own + slot here. Auto Power Off makes this the ordinary end-of-print state, and + the gate is Bambuddy-side — releasing it never touches the printer (#2864). */} + {printer.is_active !== false && !status?.connected && viewMode === 'expanded' && showClearPlateButton && ( + expandedClearPlateButton + )} + {/* Bottom block (power row + action bar). Wrapped together so the power row hugs the action bar at the card bottom instead of floating up when there's less filament content above. */} @@ -8895,12 +8914,15 @@ export function PrintersPage() { // Filter to only applicable printers based on cached state const applicableIds = ids.filter(id => { const status = queryClient.getQueryData<{ connected: boolean; state: string | null; hms_errors?: HMSError[] }>(['printerStatus', id]); + // clearPlate is checked before the connection filter: it only releases a + // Bambuddy-side gate, so it applies to a printer Auto Power Off has shut + // down — every other action here needs to reach the machine (#2864). + if (action === 'clearPlate') return !!(status as { awaiting_plate_clear?: boolean } | undefined)?.awaiting_plate_clear; if (!status?.connected) return false; switch (action) { case 'stop': return status.state === 'RUNNING' || status.state === 'PAUSE'; case 'pause': return status.state === 'RUNNING'; case 'resume': return status.state === 'PAUSE'; - case 'clearPlate': return !!(status as { awaiting_plate_clear?: boolean }).awaiting_plate_clear; case 'clearHMS': return status.hms_errors && filterKnownHMSErrors(status.hms_errors).length > 0; default: return false; } diff --git a/static/assets/index-CXdmGala.js b/static/assets/index-pHbVkL6v.js similarity index 98% rename from static/assets/index-CXdmGala.js rename to static/assets/index-pHbVkL6v.js index a8e6b88e4..d6ef081b5 100644 --- a/static/assets/index-CXdmGala.js +++ b/static/assets/index-pHbVkL6v.js @@ -4204,13 +4204,13 @@ void main() { absolute left-0 z-50 ${u===`top`?`bottom-full mb-2`:`top-full mt-2`} animate-in fade-in-0 zoom-in-95 duration-150 - `,style:{maxWidth:`calc(100vw - 24px)`},onMouseEnter:w,onMouseLeave:T,children:(0,G.jsxs)(`div`,{className:`w-52 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl overflow-hidden backdrop-blur-sm p-2.5 space-y-2`,children:[(0,G.jsx)(`div`,{className:`text-[length:var(--pc-t10,10px)] uppercase tracking-wider text-bambu-gray font-medium`,children:n}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,G.jsx)(`span`,{className:`text-[length:var(--pc-t10,10px)] tracking-wide text-bambu-gray font-medium shrink-0`,children:s(`printers.amsPopup.serialNumber`)}),(0,G.jsx)(`span`,{className:`text-[length:var(--pc-t10,10px)] text-white font-mono truncate`,children:e.serial_number||`—`})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,G.jsx)(`span`,{className:`text-[length:var(--pc-t10,10px)] tracking-wide text-bambu-gray font-medium shrink-0`,children:s(`printers.amsPopup.firmwareVersion`)}),(0,G.jsx)(`span`,{className:`text-[length:var(--pc-t10,10px)] text-white font-mono truncate`,children:e.sw_ver||`—`})]}),(0,G.jsxs)(`div`,{className:`space-y-1`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-[length:var(--pc-t10,10px)] text-bambu-gray font-medium shrink-0`,children:s(`printers.amsPopup.friendlyName`)}),(0,G.jsx)(`div`,{className:`flex-1 h-[2px] bg-bambu-dark-tertiary/50`})]}),(0,G.jsx)(`input`,{type:`text`,value:f,onChange:e=>i&&p(e.target.value),onKeyDown:e=>e.key===`Enter`&&E(),onFocus:()=>b(!0),onBlur:()=>{b(!1),C.current&&clearTimeout(C.current),C.current=setTimeout(()=>l(!1),200)},placeholder:i?s(`printers.amsPopup.friendlyNamePlaceholder`):r?.[e.id]||`—`,disabled:!i,title:i?void 0:s(`printers.amsPopup.noEditPermission`),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-2 py-1 text-xs text-white placeholder-bambu-gray/60 focus:outline-none focus:border-bambu-green disabled:opacity-50 disabled:cursor-not-allowed`,maxLength:100}),i&&(0,G.jsxs)(`div`,{className:`space-y-1`,children:[g&&(0,G.jsx)(`p`,{className:`text-[length:var(--pc-t10,10px)] text-red-700 dark:text-red-400 break-words`,children:g}),(0,G.jsxs)(`div`,{className:`flex gap-1 justify-end`,children:[(0,G.jsx)(`button`,{onClick:E,disabled:m,className:`px-2 py-0.5 text-[length:var(--pc-t10,10px)] bg-bambu-green text-white rounded hover:bg-bambu-green/80 disabled:opacity-50`,children:s(`printers.amsPopup.save`)}),r?.[e.id]&&(0,G.jsx)(`button`,{onClick:async()=>{if(i){h(!0),_(null);try{await Z.deleteAmsLabel(t,e.id,e.serial_number),a(),l(!1)}catch(e){_(e instanceof Error?e.message:String(e))}finally{h(!1)}}},disabled:m,className:`px-2 py-0.5 text-[length:var(--pc-t10,10px)] bg-bambu-dark-tertiary text-bambu-gray rounded hover:bg-bambu-dark-tertiary/70 disabled:opacity-50`,children:s(`printers.amsPopup.clear`)})]})]})]})]})})]})}var fG={PLA:{n3f:45,n3s:45,n3f_hours:12,n3s_hours:12},PETG:{n3f:65,n3s:65,n3f_hours:12,n3s_hours:12},TPU:{n3f:65,n3s:75,n3f_hours:12,n3s_hours:18},ABS:{n3f:65,n3s:80,n3f_hours:12,n3s_hours:8},ASA:{n3f:65,n3s:80,n3f_hours:12,n3s_hours:8},PA:{n3f:65,n3s:85,n3f_hours:12,n3s_hours:12},PC:{n3f:65,n3s:80,n3f_hours:12,n3s_hours:8},PVA:{n3f:65,n3s:85,n3f_hours:12,n3s_hours:18}},pG={1:1,2:1,3:1.2,4:1.4};function POe(e){let t=pG[e]??1,n=e=>`${Math.round(e*t*10)/10}px`;return{"--pc-t8":n(8),"--pc-t9":n(9),"--pc-t10":n(10),"--pc-t11":n(11),"--pc-i2":n(8),"--pc-i25":n(10),"--pc-i3":n(12),"--pc-i35":n(14),"--pc-i4":n(16),"--pc-i5":n(20),"--pc-i7":n(28)}}function FOe({printerId:e,dryingActive:t,timeFormat:n}){let{t:r}=U(),i=so(),{showToast:a}=zd(),{data:o=[]}=K({queryKey:GW,queryFn:()=>Z.listScheduledDryings(),refetchInterval:3e4});(0,y.useEffect)(()=>{t&&i.invalidateQueries({queryKey:GW})},[t,i]);let s=q({mutationFn:e=>Z.cancelScheduledDrying(e),onSuccess:()=>i.invalidateQueries({queryKey:GW}),onError:e=>a(e.message||r(`printers.drying.scheduleFailed`),`error`)}),c=o.filter(t=>t.printer_id===e&&(t.status===`pending`||t.status===`failed`));return c.length===0?null:(0,G.jsx)(`div`,{className:`mt-2 space-y-1`,children:c.map(e=>{let t=e.status===`failed`,i=fOe(e.waiting_reason);return(0,G.jsxs)(`div`,{"data-testid":t?`scheduled-drying-failed`:`scheduled-drying-pending`,className:`flex items-center justify-between px-2 py-1 rounded-lg text-[length:var(--pc-t11,11px)] ${t?`bg-red-500/10 border border-red-500/30`:`bg-amber-500/10 border border-amber-500/30`}`,children:[(0,G.jsx)(`span`,{className:t?`text-red-700 dark:text-red-400`:`text-amber-700 dark:text-amber-400`,children:t?r(`printers.drying.scheduleFailedReason`,{reason:e.error_message||r(`printers.drying.scheduleFailedUnknown`)}):(0,G.jsxs)(G.Fragment,{children:[e.start_after?r(`printers.drying.scheduledFor`,{time:Kf(e.start_after,n)}):r(`printers.drying.scheduledAsap`),i&&(0,G.jsx)(`span`,{className:`ml-1 opacity-80`,children:r(i)})]})}),(0,G.jsx)(`button`,{onClick:()=>s.mutate(e.id),disabled:s.isPending,title:r(t?`printers.drying.dismissFailed`:`printers.drying.cancelScheduled`),className:`text-bambu-gray hover:text-red-400 transition-colors disabled:opacity-50 disabled:cursor-not-allowed`,children:(0,G.jsx)(Qu,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)]`})})]},e.id)})})}function mG({printer:e,hideIfDisconnected:t,maintenanceInfo:n,viewMode:r=`expanded`,cardSize:i=2,amsThresholds:a,spoolmanEnabled:o=!1,linkedSpools:s,spoolmanUrl:c,spoolmanSyncMode:l,onGetAssignment:u,onUnassignSpool:d,spoolmanSpools:f,spoolmanSlotAssignments:p,spoolmanLoading:m=!1,onUnassignSpoolmanSpool:h,timeFormat:g=`system`,cameraViewMode:_=`window`,onOpenEmbeddedCamera:v,onSelectCameraViewMode:b,checkPrinterFirmware:x=!0,dryingPresets:S=fG,requirePlateClear:C=!1,selectionMode:w=!1,isSelected:T=!1,onToggleSelect:E,onOpenCompactCard:D,nozzleTempPresets:O=fm,bedTempPresets:k=pm,chamberTempPresets:A=mm,fanSpeedPresets:j=hm,aiDetectionEnabled:M=!1,aiDetection:N,aiLastError:P=null}){let{t:F}=U(),I=so(),L=or(),{showToast:R}=zd(),{hasPermission:z}=Td(),[B,V]=(0,y.useState)(!1),[ee,te]=(0,y.useState)(!1),[ne,re]=(0,y.useState)(!0),[ie,ae]=(0,y.useState)(!1),[oe,se]=(0,y.useState)(!1),[H,ce]=(0,y.useState)(!1),[le,ue]=(0,y.useState)(!1),[de,fe]=(0,y.useState)(!1),[pe,me]=(0,y.useState)(null),[he,ge]=(0,y.useState)(!1),[_e,ve]=(0,y.useState)(!1),[ye,be]=(0,y.useState)(!1),[xe,Se]=(0,y.useState)(()=>jee(e.id)),Ce=(0,y.useCallback)(()=>{Se(t=>{let n=!t;return Mee(e.id,n),n})},[e.id]),[we,Te]=(0,y.useState)(!1),[Ee,De]=(0,y.useState)(!1),[Oe,ke]=(0,y.useState)(null),[Ae,je]=(0,y.useState)(null),[Me,Ne]=(0,y.useState)(null),[Pe,Fe]=(0,y.useState)(null),[Ie,Le]=(0,y.useState)(10),[Re,ze]=(0,y.useState)(!1),[Be,Ve]=(0,y.useState)(!1),[He,Ue]=(0,y.useState)(!1),[We,Ge]=(0,y.useState)(!1),[Ke,qe]=(0,y.useState)(!1),Je=(0,y.useCallback)(()=>Ge(!1),[]),[Ye,Xe]=(0,y.useState)(null),[Ze,Qe]=(0,y.useState)(null),[$e,et]=(0,y.useState)(`n3f`),[tt,nt]=(0,y.useState)(`PLA`),[rt,it]=(0,y.useState)(50),[at,ot]=(0,y.useState)(4),[st,ct]=(0,y.useState)(!1),[lt,ut]=(0,y.useState)(`now`),[dt,ft]=(0,y.useState)(120),[pt,mt]=(0,y.useState)(``),[ht,gt]=(0,y.useState)(null),[_t,vt]=(0,y.useState)(null),yt=(0,y.useCallback)((e,t)=>{let n=kee(e.tray.find(e=>e.tray_type)?.tray_type,S),r=S[n]??fG.PLA,i=e.module_type;nt(n),it(r[i]||r.n3f),ot(i===`n3s`?r.n3s_hours:r.n3f_hours),ct(!1),ut(`now`),ft(120),mt(``),et(e.module_type),Qe(e.id),vt(t)},[S]);(0,y.useLayoutEffect)(()=>{if(Ze===null||!_t)return;let e=()=>{gt(nm({triggerRect:_t.getBoundingClientRect(),popoverWidth:cOe,estimatedHeight:lOe,horizontalAlign:`center`}))};return e(),window.addEventListener(`resize`,e),window.addEventListener(`scroll`,e,!0),()=>{window.removeEventListener(`resize`,e),window.removeEventListener(`scroll`,e,!0)}},[Ze,_t]);let bt=(0,y.useRef)(null),xt=(0,y.useRef)(!1),[St,Ct]=(0,y.useState)(null),[wt,Tt]=(0,y.useState)(!1),[Et,Dt]=(0,y.useState)(!1),Ot=(0,y.useRef)(null),[kt,At]=(0,y.useState)(null),jt=(0,y.useRef)(0),[Mt,Nt]=(0,y.useState)(null),[Pt,Ft]=(0,y.useState)(null),[It,Lt]=(0,y.useState)(null),[Rt,zt]=(0,y.useState)(null),[Bt,Vt]=(0,y.useState)(null),[Ht,Ut]=(0,y.useState)(!1),[Wt,Gt]=(0,y.useState)(null),[Kt,qt]=(0,y.useState)(!1),[Jt,Yt]=(0,y.useState)(!1),[Xt,Zt]=(0,y.useState)(null),[Qt,$t]=(0,y.useState)(!1),[en,tn]=(0,y.useState)(!1),{data:W}=K({queryKey:[`printerStatus`,e.id],queryFn:()=>Z.getPrinterStatus(e.id),refetchInterval:3e4}),{data:nn}=K({queryKey:[`firmwareUpdate`,e.id],queryFn:()=>vd.checkPrinterUpdate(e.id),staleTime:300*1e3,refetchInterval:300*1e3,enabled:x&&z(`firmware:read`)}),rn=(0,y.useMemo)(()=>{let e=new Set;if(W?.ams)for(let t of W.ams)for(let n of t.tray||[])n.tray_info_idx&&e.add(n.tray_info_idx);for(let t of W?.vt_tray??[])t.tray_info_idx&&e.add(t.tray_info_idx);if(W?.nozzle_rack)for(let t of W.nozzle_rack)t.filament_id&&e.add(t.filament_id);return Array.from(e)},[W?.ams,W?.vt_tray,W?.nozzle_rack]),an=(0,y.useMemo)(()=>{let e=new Set;if(W?.ams)for(let t of W.ams)for(let n of t.tray||[])n.tray_type&&e.add(n.tray_type.toUpperCase());for(let t of W?.vt_tray??[])t.tray_type&&e.add(t.tray_type.toUpperCase());return e},[W?.ams,W?.vt_tray]),on=(0,y.useMemo)(()=>{let e=new Set;if(W?.ams){for(let t of W.ams)for(let n of t.tray||[])if(n.tray_type&&n.tray_color){let t=n.tray_color.replace(`#`,``).toLowerCase().slice(0,6);e.add(`${n.tray_type.toUpperCase()}:${t}`)}}for(let t of W?.vt_tray??[])if(t.tray_type&&t.tray_color){let n=t.tray_color.replace(`#`,``).toLowerCase().slice(0,6);e.add(`${t.tray_type.toUpperCase()}:${n}`)}return e},[W?.ams,W?.vt_tray]),sn=(0,y.useMemo)(()=>{let e=new Set;if(W?.ams){for(let t of W.ams)for(let n of t.tray||[])if(n.tray_type&&n.tray_color){let t=n.tray_color.replace(`#`,``).toLowerCase().slice(0,6);e.add(`${n.tray_type.toUpperCase()}:${t}:${n.tray_info_idx||``}`)}}for(let t of W?.vt_tray??[])if(t.tray_type&&t.tray_color){let n=t.tray_color.replace(`#`,``).toLowerCase().slice(0,6);e.add(`${t.tray_type.toUpperCase()}:${n}:${t.tray_info_idx||``}`)}return e},[W?.ams,W?.vt_tray]),{data:cn}=K({queryKey:[`filamentInfo`,rn],queryFn:()=>Z.getFilamentInfo(rn),enabled:rn.length>0,staleTime:300*1e3}),{data:ln}=K({queryKey:[`slotPresets`,e.id],queryFn:()=>Z.getSlotPresets(e.id),staleTime:120*1e3}),un=W?.state===`RUNNING`||W?.state===`PAUSE`?W?.current_archive_id??null:null,{data:dn}=K({queryKey:[`archive-plates`,un],queryFn:()=>Z.getArchivePlates(un),enabled:un!=null,staleTime:300*1e3}),fn=!dn?.is_multi_plate||W?.current_plate_id==null?null:dn.plates.find(e=>e.index===W.current_plate_id)?.name||F(`printers.plateNumber`,`Plate {{number}}`,{number:W.current_plate_id}),{data:pn,refetch:mn}=K({queryKey:[`amsLabels`,e.id],queryFn:()=>Z.getAmsLabels(e.id),staleTime:300*1e3}),[hn,gn]=(0,y.useState)(null);(0,y.useEffect)(()=>{W?.wifi_signal!=null&&gn(W.wifi_signal)},[W?.wifi_signal]);let _n=W?.wifi_signal??hn,vn=(0,y.useRef)(void 0);(0,y.useEffect)(()=>{W?.connected!==void 0&&(vn.current=W.connected)},[W?.connected]);let yn=W?.connected??vn.current,bn=(0,y.useRef)({});(0,y.useEffect)(()=>{W?.ams_extruder_map&&Object.keys(W.ams_extruder_map).length>0&&(bn.current=W.ams_extruder_map)},[W?.ams_extruder_map]);let xn=W?.ams_extruder_map&&Object.keys(W.ams_extruder_map).length>0?W.ams_extruder_map:bn.current,Sn=(0,y.useRef)({});(0,y.useEffect)(()=>{W?.ams_switch_inlet&&Object.keys(W.ams_switch_inlet).length>0&&(Sn.current=W.ams_switch_inlet)},[W?.ams_switch_inlet]);let Cn=W?.fila_switch?.installed===!0,wn=W?.ams_switch_inlet&&Object.keys(W.ams_switch_inlet).length>0?W.ams_switch_inlet:Sn.current,Tn=(0,y.useRef)([]);(0,y.useEffect)(()=>{W?.ams&&W.ams.length>0&&(Tn.current=W.ams)},[W?.ams]);let En=W?.ams&&W.ams.length>0?W.ams:Tn.current;(0,y.useEffect)(()=>{if(!St)return;let e=En.find(e=>e.id===St.amsId);e&&(e.dry_time>0||e.dry_status>0)&&Ct(null)},[St,En]),(0,y.useEffect)(()=>{if(!St)return;let e=setTimeout(()=>{Ct(null),R(F(`printers.drying.toastNotStarted`),`error`)},EOe);return()=>clearTimeout(e)},[St,R,F]);let Dn=(0,y.useRef)(void 0),On=W?.tray_now;On!==void 0&&On!==255?Dn.current=On:On===255&&(Dn.current=void 0);let kn=On!==void 0&&On!==255?On:Dn.current,An=W?.expected_tray??null,jn=W?.previous_tray??null,Mn=e=>{if(e===null)return null;if(e===254)return F(`printers.expectedSlot.external`);if(e>=128&&e<=135)return pn?.[e]||ap(e,1);let t=Math.floor(e/4),n=e%4;return F(`printers.expectedSlot.label`,{ams:pn?.[t]||ap(t,4),slot:n+1})},Nn=W?.state===`PAUSE`?{expectedSlotLabel:Mn(An),ranOutSlotLabel:Mn(jn)}:null,{data:Pn}=K({queryKey:[`smartPlugByPrinter`,e.id],queryFn:()=>Z.getSmartPlugByPrinter(e.id)}),{data:Fn}=K({queryKey:[`scriptPlugsByPrinter`,e.id],queryFn:()=>Z.getScriptPlugsByPrinter(e.id)}),{data:In}=K({queryKey:[`smartPlugStatus`,Pn?.id],queryFn:()=>Pn?Z.getSmartPlugStatus(Pn.id):null,enabled:!!Pn,refetchInterval:1e4}),{data:Ln}=K({queryKey:[`queue`,e.id,`pending`],queryFn:()=>Z.getQueue(e.id,`pending`)}),Rn=(0,y.useMemo)(()=>Ln?.length?dm(Ln,an,on,sn).length:0,[Ln,an,on,sn]),{data:zn}=K({queryKey:[`queue`,e.id,`printing`],queryFn:()=>Z.getQueue(e.id,`printing`),enabled:W?.state===`RUNNING`}),{data:Bn}=K({queryKey:[`currentPrintUser`,e.id],queryFn:()=>Z.getCurrentPrintUser(e.id),enabled:W?.state===`RUNNING`}),Vn=zn?.[0]?.created_by_username||Bn?.username,{data:Hn}=K({queryKey:[`archives`,e.id,`last`],queryFn:()=>Z.getArchives(e.id,1,0),enabled:W?.connected&&W?.state!==`RUNNING`}),Un=Hn?.[0],Wn=W?.state===`RUNNING`||W?.state===`PAUSE`,Gn=C&&W?.awaiting_plate_clear===!0,Kn=W?.connected&&Gn&&!Wn,qn=W?.current_print&&Wn?Cee(W.subtask_name||W.current_print||null,W.gcode_file,F,fn):null,[Jn,Yn]=(0,y.useState)(null);(0,y.useEffect)(()=>{qn?Yn({name:qn,coverUrl:W?.cover_url??null}):Gn||Yn(null)},[qn,Gn,W?.cover_url]);let Xn=!C||!W?.connected?null:Wn?{label:F(`printers.plateStatus.inUse`),className:`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`}:W.awaiting_plate_clear?{label:F(`printers.plateStatus.notCleared`),className:`bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400`}:{label:F(`printers.plateStatus.cleared`),className:`bg-status-ok/20 text-status-ok`},Zn=Xn?(0,G.jsx)(`span`,{className:`inline-flex flex-shrink-0 items-center rounded-full px-2 py-0.5 text-[length:var(--pc-t10,10px)] font-medium ${Xn.className}`,children:Xn.label}):null,Qn=t&&yn===!1,$n=q({mutationFn:t=>Z.deletePrinter(e.id,t.deleteArchives),onSuccess:()=>{I.invalidateQueries({queryKey:[`printers`]}),I.invalidateQueries({queryKey:[`archives`]}),I.invalidateQueries({queryKey:[`maintenanceOverview`]})},onError:e=>R(e.message||F(`printers.toast.failedToDelete`),`error`)}),er=q({mutationFn:()=>Z.connectPrinter(e.id),onSuccess:()=>{I.invalidateQueries({queryKey:[`printerStatus`,e.id]})}}),tr=q({mutationFn:()=>Z.refreshPrinterStatus(e.id),onSuccess:()=>{I.invalidateQueries({queryKey:[`printerStatus`,e.id]}),R(F(`printers.forceRefreshSuccess`),`success`)},onError:e=>R(e.message||F(`printers.toast.failedToSendCommand`),`error`)}),nr=q({mutationFn:e=>Z.unlinkSpool(e),onSuccess:e=>{R(F(`spoolman.unlinkSuccess`)||e?.message,`success`),I.invalidateQueries({queryKey:[`linked-spools`]}),I.invalidateQueries({queryKey:[`unlinked-spools`]}),I.invalidateQueries({queryKey:[`spoolman-slot-assignments`]})},onError:e=>{R(e.message||F(`spoolman.unlinkFailed`),`error`)}}),rr=q({mutationFn:({amsId:t,temp:n,duration:r,filament:i,rotateTray:a})=>Z.startDrying(e.id,t,n,r,i,a),onSuccess:(t,{amsId:n})=>{Qe(null),Ct({amsId:n}),R(F(`printers.drying.toastCommandSent`),`success`),I.invalidateQueries({queryKey:[`printerStatus`,e.id]})},onError:e=>R(e.message||F(`printers.toast.failedToSendCommand`),`error`)}),ir=q({mutationFn:t=>Z.createScheduledDrying({printer_id:e.id,ams_id:t.amsId,temp:t.temp,duration_hours:t.duration,filament:t.filament,rotate_tray:t.rotateTray,start_after:t.startAfter}),onSuccess:()=>{I.invalidateQueries({queryKey:GW}),Qe(null)},onError:e=>R(e.message||F(`printers.drying.scheduleFailed`),`error`)}),ar=q({mutationFn:t=>Z.stopDrying(e.id,t),onSuccess:()=>{Ct(null),R(F(`printers.drying.toastStopped`),`success`),I.invalidateQueries({queryKey:[`printerStatus`,e.id]})},onError:e=>R(e.message||F(`printers.toast.failedToSendCommand`),`error`)}),sr=q({mutationFn:t=>Z.setAmsFilamentBackup(e.id,t),onSuccess:(t,n)=>{I.invalidateQueries({queryKey:[`printerStatus`,e.id]}),I.invalidateQueries({queryKey:[`printer-status`,e.id]}),R(F(n?`printers.amsBackup.toastEnabled`:`printers.amsBackup.toastDisabled`),`success`)},onError:e=>R(e.message||F(`printers.toast.failedToSendCommand`),`error`)}),cr=q({mutationFn:e=>Pn?Z.controlSmartPlug(Pn.id,e):Promise.reject(`No plug`),onSuccess:()=>{I.invalidateQueries({queryKey:[`smartPlugStatus`,Pn?.id]})}}),lr=q({mutationFn:e=>Pn?Z.updateSmartPlug(Pn.id,{auto_off:e}):Promise.reject(`No plug`),onSuccess:()=>{I.invalidateQueries({queryKey:[`smartPlugByPrinter`,e.id]}),I.invalidateQueries({queryKey:[`smart-plugs`]})}}),ur=q({mutationFn:({id:e,action:t})=>Z.controlSmartPlug(e,t),onSuccess:()=>{R(F(`printers.toast.scriptTriggered`))},onError:e=>R(e.message||F(`printers.toast.failedToRunScript`),`error`)}),dr=q({mutationFn:()=>Z.stopPrint(e.id),onSuccess:()=>{R(F(`printers.toast.printStopped`)),I.invalidateQueries({queryKey:[`printerStatus`,e.id]})},onError:e=>R(e.message||F(`printers.toast.failedToStopPrint`),`error`)}),fr=q({mutationFn:()=>Z.pausePrint(e.id),onSuccess:()=>{R(F(`printers.toast.printPaused`)),I.invalidateQueries({queryKey:[`printerStatus`,e.id]})},onError:e=>R(e.message||F(`printers.toast.failedToPausePrint`),`error`)}),pr=q({mutationFn:()=>Z.resumePrint(e.id),onSuccess:()=>{R(F(`printers.toast.printResumed`)),I.invalidateQueries({queryKey:[`printerStatus`,e.id]})},onError:e=>R(e.message||F(`printers.toast.failedToResumePrint`),`error`)}),mr=q({mutationFn:()=>Z.clearPlate(e.id),onSuccess:()=>{R(F(`queue.clearPlateSuccess`)),I.setQueryData([`printerStatus`,e.id],e=>e&&{...e,awaiting_plate_clear:!1}),I.invalidateQueries({queryKey:[`printerStatus`,e.id]}),I.invalidateQueries({queryKey:[`queue`,e.id]})},onError:e=>R(e.message||F(`printers.toast.failedToSendCommand`),`error`)}),hr=q({mutationFn:({target:t,nozzle:n})=>Z.setNozzleTemperature(e.id,t,n),onSuccess:t=>{Fe(null),R(t.message),I.invalidateQueries({queryKey:[`printerStatus`,e.id]})},onError:e=>R(e.message||F(`printers.toast.failedToSendCommand`),`error`)}),gr=q({mutationFn:t=>Z.setBedTemperature(e.id,t),onSuccess:t=>{Fe(null),R(t.message),I.invalidateQueries({queryKey:[`printerStatus`,e.id]})},onError:e=>R(e.message||F(`printers.toast.failedToSendCommand`),`error`)}),_r=q({mutationFn:t=>Z.setChamberTemperature(e.id,t),onSuccess:t=>{Fe(null),R(t.message),I.invalidateQueries({queryKey:[`printerStatus`,e.id]})},onError:e=>R(e.message||F(`printers.toast.failedToSendCommand`),`error`)}),vr=q({mutationFn:({fan:t,speed:n})=>Z.setFanSpeed(e.id,t,n),onMutate:async({fan:t,speed:n})=>{await I.cancelQueries({queryKey:[`printerStatus`,e.id]});let r=I.getQueryData([`printerStatus`,e.id]),i={part:`cooling_fan_speed`,aux:`big_fan1_speed`,aux2:`left_aux_fan_speed`,chamber:`big_fan2_speed`}[t];return I.setQueryData([`printerStatus`,e.id],e=>e&&{...e,[i]:n}),{previousStatus:r}},onSuccess:t=>{Fe(null),R(t.message),I.invalidateQueries({queryKey:[`printerStatus`,e.id]})},onError:(t,n,r)=>{r?.previousStatus&&I.setQueryData([`printerStatus`,e.id],r.previousStatus),R(t.message||F(`printers.toast.failedToSendCommand`),`error`)}}),yr=q({mutationFn:t=>Z.selectExtruder(e.id,t),onMutate:async t=>{await I.cancelQueries({queryKey:[`printerStatus`,e.id]});let n=I.getQueryData([`printerStatus`,e.id]);return I.setQueryData([`printerStatus`,e.id],e=>e&&{...e,active_extruder:t}),{previousStatus:n}},onSuccess:t=>{Fe(null),R(t.message),I.invalidateQueries({queryKey:[`printerStatus`,e.id]})},onError:(t,n,r)=>{r?.previousStatus&&I.setQueryData([`printerStatus`,e.id],r.previousStatus),R(t.message||F(`printers.toast.failedToSendCommand`),`error`)}}),br=q({mutationFn:t=>Z.setChamberLight(e.id,t),onMutate:async t=>{await I.cancelQueries({queryKey:[`printerStatus`,e.id]});let n=I.getQueryData([`printerStatus`,e.id]);return I.setQueryData([`printerStatus`,e.id],e=>({...e,chamber_light:t})),{previousStatus:n}},onSuccess:(e,t)=>{R(`Chamber light ${t?`on`:`off`}`)},onError:(t,n,r)=>{r?.previousStatus&&I.setQueryData([`printerStatus`,e.id],r.previousStatus),R(t.message||F(`printers.toast.failedToControlChamberLight`),`error`)}}),xr=q({mutationFn:t=>Z.setPrintSpeed(e.id,t),onMutate:async t=>{await I.cancelQueries({queryKey:[`printerStatus`,e.id]});let n=I.getQueryData([`printerStatus`,e.id]);return I.setQueryData([`printerStatus`,e.id],e=>({...e,speed_level:t})),{previousStatus:n}},onError:(t,n,r)=>{r?.previousStatus&&I.setQueryData([`printerStatus`,e.id],r.previousStatus),R(t.message||F(`printers.toast.failedToSetSpeed`),`error`)}}),Sr=q({mutationFn:t=>Z.setAirductMode(e.id,t),onMutate:async t=>{await I.cancelQueries({queryKey:[`printerStatus`,e.id]});let n=I.getQueryData([`printerStatus`,e.id]);return I.setQueryData([`printerStatus`,e.id],e=>({...e,airduct_mode:t===`cooling`?0:1})),{previousStatus:n}},onError:(t,n,r)=>{r?.previousStatus&&I.setQueryData([`printerStatus`,e.id],r.previousStatus),R(t.message||F(`printers.toast.failedToSendCommand`),`error`)}}),Cr=q({mutationFn:({distance:t})=>Z.bedJog(e.id,t),onError:e=>R(e.message||F(`printers.toast.failedToSendCommand`),`error`)}),wr=q({mutationFn:({x:t,y:n})=>Z.xyJog(e.id,t,n),onError:e=>R(e.message||F(`printers.toast.failedToSendCommand`),`error`)}),Tr=q({mutationFn:t=>Z.extruderJog(e.id,t),onError:e=>R(e.message||F(`printers.toast.failedToSendCommand`),`error`)}),Er=q({mutationFn:t=>Z.homeAxes(e.id,t),onSuccess:()=>{R(F(`printers.bedJog.homingStarted`))},onError:e=>R(e.message||F(`printers.toast.failedToSendCommand`),`error`)}),Dr=q({mutationFn:t=>Z.updatePrinter(e.id,{plate_detection_enabled:t}),onSuccess:()=>{I.invalidateQueries({queryKey:[`printers`]}),R(Dr.variables?F(`printers.toast.plateCheckEnabled`):F(`printers.toast.plateCheckDisabled`))},onError:e=>R(e.message||F(`printers.toast.failedToUpdateSetting`),`error`)}),Or=q({mutationFn:t=>Z.updatePrinter(e.id,{is_active:t}),onSuccess:(t,n)=>{I.invalidateQueries({queryKey:[`printers`]}),I.invalidateQueries({queryKey:[`printerStatus`,e.id]}),R(F(n?`printers.maintenance.toastExited`:`printers.maintenance.toastEntered`,{name:e.name}),`success`)},onError:e=>R(e.message||F(`printers.toast.failedToUpdateSetting`),`error`)}),[kr,Ar]=(0,y.useState)(!1),jr=()=>{W?.state===`RUNNING`||W?.state===`PAUSE`?Ar(!0):Or.mutate(!1)},Mr=(W?.state===`RUNNING`||W?.state===`PAUSE`)&&(W?.printable_objects_count??0)>=2,{data:Nr}=K({queryKey:[`printableObjects`,e.id],queryFn:()=>Z.getPrintableObjects(e.id),enabled:Be||Mr,refetchInterval:Be?5e3:Mr?3e4:!1}),[Pr,Fr]=(0,y.useState)(null),Ir=(0,y.useRef)(!1),Lr=(0,y.useRef)(null),Rr=(0,y.useRef)(!1),zr=q({mutationFn:({amsId:t,slotId:n})=>Z.refreshAmsSlot(e.id,t,n),onMutate:({amsId:e,slotId:t})=>{Lr.current&&clearTimeout(Lr.current),Ir.current=!1,Rr.current=!1,Fr({amsId:e,slotId:t}),setTimeout(()=>{Rr.current=!0},2e3),Lr.current=setTimeout(()=>{Fr(null)},3e4)},onSuccess:e=>{R(e.message||F(`printers.toast.rfidRereadInitiated`))},onError:e=>{R(e.message||F(`printers.toast.failedToRereadRfid`),`error`),Lr.current&&clearTimeout(Lr.current),Fr(null)}}),Br=q({mutationFn:({trayId:t})=>Z.loadAmsTray(e.id,t),onSuccess:e=>{R(e.message||F(`printers.toast.loadInitiated`))},onError:e=>{R(e.message||F(`printers.toast.failedToLoad`),`error`)}}),Vr=q({mutationFn:()=>Z.unloadAms(e.id),onSuccess:e=>{R(e.message||F(`printers.toast.unloadInitiated`))},onError:e=>{R(e.message||F(`printers.toast.failedToUnload`),`error`)}}),[Hr,Ur]=(0,y.useState)(null),[Wr,Gr]=(0,y.useState)(null),Kr=async()=>{try{Ur(await Z.getPlateReferences(e.id))}catch{}},qr=()=>{Dr.mutate(!e.plate_detection_enabled)},Jr=async()=>{qt(!0),Gt(null);let t=W?.chamber_light===!1;tn(t),t&&(await Z.setChamberLight(e.id,!0),await new Promise(e=>setTimeout(e,2500)));try{Gt(await Z.checkPlateEmpty(e.id,{includeDebugImage:!0})),Kr()}catch(n){R(n instanceof Error?n.message:F(`printers.toast.failedToCheckPlate`),`error`),t&&(await Z.setChamberLight(e.id,!1),tn(!1))}finally{qt(!1)}},Yr=(0,y.useCallback)(async()=>{Gt(null),en&&(await Z.setChamberLight(e.id,!1),tn(!1))},[en,e.id]),Xr=async t=>{Yt(!0);try{let n=await Z.calibratePlateDetection(e.id,{label:t});n.success?(R(n.message||F(`printers.toast.calibrationSaved`),`success`),Kr(),Gt(await Z.checkPlateEmpty(e.id,{includeDebugImage:!0}))):R(n.message||F(`printers.toast.calibrationFailed`),`error`)}catch(e){R(e instanceof Error?e.message:F(`printers.toast.calibrationFailed`),`error`)}finally{Yt(!1)}},Zr=async(t,n)=>{try{await Z.updatePlateReferenceLabel(e.id,t,n),Gr(null),Kr()}catch(e){R(e instanceof Error?e.message:F(`printers.toast.failedToUpdateLabel`),`error`)}},Qr=async t=>{try{await Z.deletePlateReference(e.id,t),R(F(`printers.toast.referenceDeleted`),`success`),Kr(),Gt(await Z.checkPlateEmpty(e.id,{includeDebugImage:!0}))}catch(e){R(e instanceof Error?e.message:F(`printers.toast.failedToDeleteReference`),`error`)}},$r=async()=>{if(Xt){$t(!0);try{await Z.updatePrinter(e.id,{plate_detection_roi:Xt}),R(F(`printers.toast.detectionAreaSaved`),`success`),Zt(null),Gt(await Z.checkPlateEmpty(e.id,{includeDebugImage:!0}))}catch(e){R(e instanceof Error?e.message:F(`printers.toast.failedToSaveDetectionArea`),`error`)}finally{$t(!1)}}};(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&Wt&&Yr()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[Wt,Yr]);let ei=(0,y.useRef)(null);if((0,y.useEffect)(()=>{if(!Pr)return;let e=W?.ams_status_main??0;return e!==0&&(Ir.current=!0,ei.current&&=(clearTimeout(ei.current),null)),Ir.current&&e===0&&(Rr.current?(Lr.current&&clearTimeout(Lr.current),Fr(null)):ei.current||=setTimeout(()=>{Lr.current&&clearTimeout(Lr.current),Fr(null)},2e3)),()=>{ei.current&&clearTimeout(ei.current)}},[W?.ams_status_main,Pr]),(0,y.useEffect)(()=>{if(!B)return;let e=e=>{let t=e.target;Ot.current?.contains(t)||V(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[B]),Qn)return null;let ti=POe(i),ni=()=>{switch(i){case 1:return`w-10 h-10`;case 2:return`w-14 h-14`;case 3:return`w-16 h-16`;case 4:return`w-20 h-20`;default:return`w-14 h-14`}},ri=()=>{switch(i){case 1:return`text-base truncate`;case 2:return`text-lg`;case 3:return`text-xl`;case 4:return`text-2xl`;default:return`text-lg`}},ii=()=>{switch(i){case 1:return`mb-2`;case 2:return`mb-4`;case 3:return`mb-5`;case 4:return`mb-6`;default:return`mb-4`}},ai=z(`library:upload`)&&z(`queue:create`),oi=!um(W),si=e=>{e.preventDefault(),jt.current++,jt.current===1&&Tt(!0)},ci=e=>{e.preventDefault(),e.dataTransfer.dropEffect=ai?`copy`:`none`},li=e=>{e.preventDefault(),jt.current--,jt.current===0&&Tt(!1)},ui=async t=>{if(t.preventDefault(),jt.current=0,Tt(!1),!ai)return;let n=Array.from(t.dataTransfer.files)[0];if(!n)return;let r=n.name.toLowerCase();if(!r.endsWith(`.gcode`)&&!r.includes(`.gcode.`)){R(F(`printers.dropNotPrintable`,`Only .gcode and .gcode.3mf files can be printed`),`error`);return}Dt(!0);try{let t=await Z.uploadLibraryFile(n,null),r=t.metadata?.sliced_for_model,i=uG(e.model);if(r&&i&&r.toLowerCase()!==i.toLowerCase()){await Z.deleteLibraryFile(t.id).catch(()=>{}),R(F(`printers.incompatibleFile`,`This file was sliced for {{slicedFor}}, but this printer is a {{printerModel}}`,{slicedFor:r,printerModel:i}),`error`);return}Xe({id:t.id,filename:t.filename})}catch{R(F(`common.uploadFailed`,`Upload failed`),`error`)}finally{Dt(!1)}},di=t=>{r!==`compact`||w||t.target.closest(`button, a, input, select, textarea, [role="button"]`)||D?.(e.id)},fi=`!h-8 !min-h-8 !w-8 !px-0 !py-0`,pi=t=>{t===`embedded`&&v?v(e.id,e.name):im(e.id)},mi=[{mode:`window`,icon:(0,G.jsx)(ec,{className:`w-4 h-4`}),label:F(`settings.newWindow`),title:F(`settings.cameraWindowDescription`)},{mode:`embedded`,icon:(0,G.jsx)(Ol,{className:`w-4 h-4`}),label:F(`settings.embeddedOverlay`),title:F(`settings.cameraOverlayDescription`)}].map(({mode:e,icon:t,label:n,title:r})=>({icon:t,label:e===_?`${n} ✓`:n,title:r,onClick:()=>{b?.(e),pi(e)}})),hi=({amsId:e,slotId:t,loadTrayId:n,isRefreshing:r,includeRfid:i=!0})=>{let a=W?.state===`RUNNING`;return(0,G.jsxs)(G.Fragment,{children:[i&&(0,G.jsxs)(`button`,{className:`w-full px-2 py-1.5 text-left text-xs flex items-center gap-2 rounded transition-colors ${z(`printers:ams_rfid`)?`text-white hover:bg-bambu-dark-tertiary`:`text-bambu-gray/50 cursor-not-allowed`}`,onClick:n=>{n.stopPropagation(),!(a||!z(`printers:ams_rfid`))&&zr.mutate({amsId:e,slotId:t})},disabled:a||r||!z(`printers:ams_rfid`),title:a?F(`printers.bedJog.disabledWhilePrinting`):z(`printers:ams_rfid`)?void 0:F(`printers.permission.noAmsRfid`),children:[(0,G.jsx)(Rl,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)] ${r?`animate-spin`:``}`}),F(`printers.rfid.reread`)]}),(0,G.jsxs)(`button`,{className:`w-full px-2 py-1.5 text-left text-xs flex items-center gap-2 rounded transition-colors ${z(`printers:control`)?`text-white hover:bg-bambu-dark-tertiary`:`text-bambu-gray/50 cursor-not-allowed`}`,onClick:e=>{e.stopPropagation(),!(a||!z(`printers:control`))&&Br.mutate({trayId:n})},disabled:a||!z(`printers:control`),title:a?F(`printers.bedJog.disabledWhilePrinting`):z(`printers:control`)?void 0:F(`printers.permission.noControl`),children:[(0,G.jsx)($c,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)]`}),F(`printers.ams.load`)]}),(0,G.jsxs)(`button`,{className:`w-full px-2 py-1.5 text-left text-xs flex items-center gap-2 rounded transition-colors ${z(`printers:control`)?`text-white hover:bg-bambu-dark-tertiary`:`text-bambu-gray/50 cursor-not-allowed`}`,onClick:e=>{e.stopPropagation(),!(a||!z(`printers:control`))&&Vr.mutate()},disabled:a||!z(`printers:control`),title:a?F(`printers.bedJog.disabledWhilePrinting`):z(`printers:control`)?void 0:F(`printers.permission.noControl`),children:[(0,G.jsx)(el,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)]`}),F(`printers.ams.unload`)]})]})},gi=(0,G.jsxs)(`div`,{ref:Ot,className:`relative flex-shrink-0`,children:[(0,G.jsx)(Q,{variant:`secondary`,size:`sm`,onClick:()=>V(!B),title:F(`common.more`,`More`),className:fi,children:(0,G.jsx)(Xs,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)]`})}),B&&(0,G.jsxs)(`div`,{className:`absolute left-0 bottom-full mb-2 w-48 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg z-20`,children:[(0,G.jsxs)(`button`,{className:`w-full px-4 py-2 text-left text-sm flex items-center gap-2 ${z(`printers:update`)?`hover:bg-bambu-dark-tertiary`:`opacity-50 cursor-not-allowed`}`,onClick:()=>{z(`printers:update`)&&(ae(!0),V(!1))},title:z(`printers:update`)?void 0:F(`printers.permission.noEdit`),children:[(0,G.jsx)(El,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)]`}),F(`common.edit`)]}),(0,G.jsxs)(`button`,{className:`w-full px-4 py-2 text-left text-sm hover:bg-bambu-dark-tertiary flex items-center gap-2`,onClick:()=>{Ge(!0),V(!1)},children:[(0,G.jsx)(zc,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)]`}),F(`printers.printerInformation`)]}),(0,G.jsxs)(`button`,{className:`w-full px-4 py-2 text-left text-sm flex items-center gap-2 ${z(`printers:update`)?`hover:bg-bambu-dark-tertiary`:`opacity-50 cursor-not-allowed`}`,disabled:Or.isPending||!z(`printers:update`),onClick:()=>{z(`printers:update`)&&(V(!1),e.is_active===!1?Or.mutate(!0):jr())},title:z(`printers:update`)?void 0:F(`printers.permission.noEdit`),children:[(0,G.jsx)(Zu,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)]`}),e.is_active===!1?F(`printers.maintenance.menuExit`):F(`printers.maintenance.menuEnter`)]}),(0,G.jsxs)(`button`,{className:`w-full px-4 py-2 text-left text-sm hover:bg-bambu-dark-tertiary flex items-center gap-2`,onClick:()=>{er.mutate(),V(!1)},children:[(0,G.jsx)(Rl,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)]`}),F(`printers.reconnect`)]}),(0,G.jsxs)(`button`,{className:`w-full px-4 py-2 text-left text-sm hover:bg-bambu-dark-tertiary flex items-center gap-2 disabled:opacity-50`,disabled:tr.isPending,onClick:()=>{tr.mutate(),V(!1)},children:[(0,G.jsx)(Vl,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)] ${tr.isPending?`animate-spin`:``}`}),F(`printers.forceRefresh`)]}),(0,G.jsxs)(`button`,{className:`w-full px-4 py-2 text-left text-sm hover:bg-bambu-dark-tertiary flex items-center gap-2`,onClick:()=>{ce(!0),V(!1)},children:[(0,G.jsx)(wu,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)]`}),F(`printers.mqttDebug`)]}),(0,G.jsxs)(`button`,{className:`w-full px-4 py-2 text-left text-sm hover:bg-bambu-dark-tertiary flex items-center gap-2`,onClick:()=>{qe(!0),V(!1)},children:[(0,G.jsx)(vu,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)]`}),F(`diagnostic.runButton`)]}),(0,G.jsxs)(`button`,{className:`w-full px-4 py-2 text-left text-sm flex items-center gap-2 ${z(`printers:delete`)?`text-red-700 dark:text-red-400 hover:bg-bambu-dark-tertiary`:`text-red-700/50 dark:text-red-400/50 cursor-not-allowed`}`,onClick:()=>{z(`printers:delete`)&&(te(!0),V(!1))},title:z(`printers:delete`)?void 0:F(`printers.permission.noDelete`),children:[(0,G.jsx)(Au,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)]`}),F(`common.delete`)]})]})]});return(0,G.jsxs)(jd,{id:`printer-card-${e.id}`,className:`relative flex h-full flex-col ${T?`ring-2 ring-bambu-green`:``} ${w||r===`compact`?`cursor-pointer`:``}`,style:ti,onClick:di,onDragEnter:si,onDragOver:ci,onDragLeave:li,onDrop:ui,children:[w&&(0,G.jsx)(`div`,{className:`absolute inset-0 z-20 flex items-start p-2`,onClick:t=>{t.stopPropagation(),E?.(e.id)},children:T?(0,G.jsx)(mu,{className:`w-[var(--pc-i5,1.25rem)] h-[var(--pc-i5,1.25rem)] text-bambu-green`}):(0,G.jsx)(gu,{className:`w-[var(--pc-i5,1.25rem)] h-[var(--pc-i5,1.25rem)] text-bambu-gray`})}),(wt||Et)&&(0,G.jsx)(`div`,{className:`absolute inset-0 z-10 rounded-xl border-2 border-dashed flex items-center justify-center transition-colors ${Et?`bg-bambu-green/10 border-bambu-green/50`:ai?`bg-bambu-green/10 border-bambu-green`:`bg-red-50 dark:bg-red-500/10 border-red-300 dark:border-red-500/50`}`,children:(0,G.jsx)(`div`,{className:`text-center`,children:Et?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-8 h-8 mx-auto mb-2 text-bambu-green animate-spin`}),(0,G.jsx)(`p`,{className:`text-sm font-medium text-bambu-green`,children:F(`common.uploading`,`Uploading...`)})]}):ai?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Pl,{className:`w-8 h-8 mx-auto mb-2 text-bambu-green`}),(0,G.jsx)(`p`,{className:`text-sm font-medium text-bambu-green`,children:F(oi?`printers.dropToQueue`:`printers.dropToPrint`)})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Qu,{className:`w-8 h-8 mx-auto mb-2 text-red-600 dark:text-red-400`}),(0,G.jsx)(`p`,{className:`text-sm font-medium text-red-700 dark:text-red-400`,children:z(`library:upload`)?F(`fileManager.noPermissionAddToQueue`):F(`fileManager.noPermissionUpload`)})]})})}),(0,G.jsxs)(Nd,{className:`${i>=3?`p-5`:``} flex flex-1 flex-col`,children:[(0,G.jsxs)(`div`,{className:ii(),children:[(0,G.jsx)(`div`,{className:`flex items-start justify-between gap-2`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 flex-1`,children:[(0,G.jsx)(`img`,{src:sm(e.model),alt:e.model||F(`common.printer`),className:`object-contain rounded-lg flex-shrink-0 ${ni()}`}),(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,G.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,G.jsx)(`h3`,{className:`font-semibold text-white ${ri()}`,children:e.name}),r===`compact`&&(()=>{let e=W?.connected&&W.hms_errors?xm(W.hms_errors):[],t=e.some(e=>e.severity<=2),n=e.length>0,r=W?.connected?t?`bg-status-error`:n?`bg-status-warning`:`bg-status-ok`:`bg-status-error`,i=W?.connected?n?`${e.length} HMS ${e.length===1?`error`:`errors`}`:F(`printers.connection.connected`):F(`printers.connection.offline`);return(0,G.jsx)(`div`,{className:`w-[var(--pc-i2,0.5rem)] h-[var(--pc-i2,0.5rem)] rounded-full flex-shrink-0 ${r}`,title:i})})()]}),r===`compact`&&Kn&&(0,G.jsx)(`button`,{type:`button`,onClick:()=>mr.mutate(),disabled:mr.isPending||!z(`printers:clear_plate`),"aria-label":F(`printers.plateStatus.markCleared`),className:`inline-flex h-5 w-5 flex-shrink-0 items-center justify-center rounded-md bg-yellow-100 dark:bg-yellow-500/20 border border-yellow-300 dark:border-yellow-400/40 text-yellow-700 dark:text-yellow-400 hover:bg-yellow-500/30 transition-colors disabled:opacity-50`,title:z(`printers:clear_plate`)?F(`printers.plateStatus.markCleared`):F(`printers.permission.noControl`),children:mr.isPending?(0,G.jsx)(Y,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)] animate-spin`}):(0,G.jsx)(yW,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)]`})})]}),(0,G.jsxs)(`p`,{className:`text-sm text-bambu-gray`,children:[e.model||`Unknown Model`,r===`expanded`&&W?.nozzles&&W.nozzles[0]?.nozzle_diameter&&(0,G.jsxs)(`span`,{className:`ml-1.5 text-bambu-gray`,title:W.nozzles[0].nozzle_type||`Nozzle`,children:[`• `,W.nozzles[0].nozzle_diameter,`mm`]}),r===`expanded`&&n&&n.total_print_hours>0&&(0,G.jsxs)(`span`,{className:`ml-2 text-bambu-gray`,children:[(0,G.jsx)(ks,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)] inline-block mr-1`}),Math.round(n.total_print_hours),`h`]})]})]})]})}),r===`expanded`&&(0,G.jsx)(`div`,{className:`mt-2`,children:(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[e.is_active===!1?(0,G.jsxs)(`span`,{className:`flex items-center gap-1.5 px-2 py-1 rounded-full text-xs bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-400`,title:F(`printers.maintenance.subtitle`),children:[(0,G.jsx)(Zu,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)]`}),F(`printers.maintenance.pillLabel`)]}):(0,G.jsxs)(`span`,{className:`flex items-center gap-1.5 px-2 py-1 rounded-full text-xs ${W?.connected?`bg-status-ok/20 text-status-ok`:`bg-status-error/20 text-status-error`}`,children:[W?.connected?(0,G.jsx)(qc,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)]`}):(0,G.jsx)(Iu,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)]`}),W?.connected?F(`printers.connection.connected`):F(`printers.connection.offline`)]}),e.is_active!==!1&&!W?.connected&&(0,G.jsxs)(`button`,{onClick:()=>qe(!0),className:`flex items-center gap-1 px-2 py-1 rounded-full text-xs cursor-pointer bg-bambu-dark-tertiary text-bambu-gray hover:text-white transition-colors`,title:F(`diagnostic.runButton`),children:[(0,G.jsx)(vu,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)]`}),F(`diagnostic.runButton`)]}),W?.connected&&W?.wired_network&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1 px-2 py-1 rounded-full text-xs bg-status-ok/20 text-status-ok`,title:F(`printers.connection.ethernet`,`Ethernet`),children:[(0,G.jsx)($o,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)]`}),F(`printers.connection.ethernet`,`Ethernet`)]}),W?.connected&&!W?.wired_network&&_n!=null&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1 px-2 py-1 rounded-full text-xs ${_n>=-50||_n>=-60?`bg-status-ok/20 text-status-ok`:_n>=-70?`bg-status-warning/20 text-status-warning`:_n>=-80?`bg-orange-500/20 text-orange-600`:`bg-status-error/20 text-status-error`}`,title:`WiFi: ${_n} dBm - ${F(lm(_n).labelKey)}`,children:[(0,G.jsx)(au,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)]`}),_n,`dBm`]}),W?.connected&&(()=>{let e=W.hms_errors?xm(W.hms_errors):[];return(0,G.jsxs)(`button`,{onClick:()=>ge(!0),className:`flex items-center gap-1 px-2 py-1 rounded-full text-xs cursor-pointer hover:opacity-80 transition-opacity ${e.length>0?e.some(e=>e.severity<=2)?`bg-status-error/20 text-status-error`:`bg-status-warning/20 text-status-warning`:`bg-status-ok/20 text-status-ok`}`,title:F(`printers.clickToViewHmsErrors`),children:[(0,G.jsx)(Nu,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)]`}),e.length>0?e.length:`OK`]})})(),M&&(()=>{let e=N?N.class===`failure`||N.class===`warning`?N.class:`safe`:`idle`;return(0,G.jsxs)(`button`,{onClick:()=>ve(!0),className:`flex items-center gap-1 px-2 py-1 rounded-full text-xs cursor-pointer hover:opacity-80 transition-opacity ${e===`failure`?`bg-status-error/20 text-status-error`:e===`warning`?`bg-status-warning/20 text-status-warning`:e===`safe`?`bg-status-ok/20 text-status-ok`:`bg-bambu-dark-tertiary text-bambu-gray`}`,title:N?F(`printers.aiDetection.tooltip`,{status:F(`printers.aiDetection.${e}`),score:N.score.toFixed(3)}):F(`printers.aiDetection.tooltipIdle`),children:[(0,G.jsx)(Gl,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)]`}),F(`printers.aiDetection.${e}`)]})})(),n&&(0,G.jsxs)(`button`,{onClick:()=>L(`/maintenance`),className:`flex items-center gap-1 px-2 py-1 rounded-full text-xs cursor-pointer hover:opacity-80 transition-opacity ${n.due_count>0?`bg-status-error/20 text-status-error`:n.warning_count>0?`bg-status-warning/20 text-status-warning`:`bg-status-ok/20 text-status-ok`}`,title:n.due_count>0||n.warning_count>0?`${n.due_count>0?`${n.due_count} maintenance due`:``}${n.due_count>0&&n.warning_count>0?`, `:``}${n.warning_count>0?`${n.warning_count} due soon`:``} - Click to view`:F(`printers.maintenanceUpToDate`),children:[(0,G.jsx)(Zu,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)]`}),n.due_count>0||n.warning_count>0?n.due_count+n.warning_count:`OK`]}),Rn>0&&(0,G.jsxs)(`button`,{onClick:()=>L(`/queue`),className:`flex items-center gap-1 px-2 py-1 rounded-full text-xs bg-indigo-100 dark:bg-indigo-500/20 text-indigo-700 dark:text-indigo-400 hover:opacity-80 transition-opacity`,title:F(`printers.queue.inQueue`,{count:Rn}),children:[(0,G.jsx)(Uc,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)]`}),Rn]}),x&&nn?.current_version&&nn?.latest_version?(0,G.jsxs)(`button`,{onClick:()=>Ut(!0),className:`flex items-center gap-1 px-2 py-1 rounded-full text-xs hover:opacity-80 transition-opacity ${nn.update_available?`bg-orange-100 dark:bg-orange-500/20 text-orange-700 dark:text-orange-400`:`bg-status-ok/20 text-status-ok`}`,title:nn.update_available?F(`printers.firmwareUpdateAvailable`,{current:nn.current_version,latest:nn.latest_version}):F(`printers.firmwareUpToDate`,{version:nn.current_version}),children:[nn.update_available?(0,G.jsx)(qs,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)]`}):(0,G.jsx)(ys,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)]`}),nn.current_version]}):W?.firmware_version?(0,G.jsx)(`span`,{className:`flex items-center gap-1 px-2 py-1 rounded-full text-xs bg-bambu-dark-tertiary/50 text-bambu-gray`,children:W.firmware_version}):null,W?.connected&&[`X1C`,`X1`,`X1E`,`X2D`,`P2S`,`H2D`,`H2D Pro`,`H2C`,`H2S`].includes(e.model??``)&&(0,G.jsx)(`span`,{className:`flex items-center px-2 py-1 rounded-full text-xs ${W.door_open?`bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400`:`bg-status-ok/20 text-status-ok`}`,title:W.door_open?F(`printers.door.open`):F(`printers.door.closed`),children:W.door_open?(0,G.jsx)(Ks,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)]`}):(0,G.jsx)(Gs,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)]`})})]})})]}),ee&&(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50`,children:(0,G.jsx)(jd,{className:`w-full max-w-md mx-4`,children:(0,G.jsxs)(Nd,{children:[(0,G.jsxs)(`div`,{className:`flex items-start gap-3 mb-4`,children:[(0,G.jsx)(`div`,{className:`p-2 rounded-full bg-red-100 dark:bg-red-500/20`,children:(0,G.jsx)(Nu,{className:`w-[var(--pc-i5,1.25rem)] h-[var(--pc-i5,1.25rem)] text-red-600 dark:text-red-400`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`text-lg font-semibold text-white`,children:F(`printers.confirm.deleteTitle`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:F(`printers.confirm.deleteMessage`,{name:e.name})})]})]}),(0,G.jsx)(`div`,{className:`bg-bambu-dark rounded-lg p-3 mb-4`,children:(0,G.jsxs)(`label`,{className:`flex items-start gap-3 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:ne,onChange:e=>re(e.target.checked),className:`mt-0.5 w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)] rounded border-bambu-gray bg-bambu-dark-secondary text-bambu-green focus:ring-bambu-green focus:ring-offset-0`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-sm text-white`,children:F(`printers.deleteArchives`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:F(ne?`printers.confirm.deleteArchivesNote`:`printers.confirm.keepArchivesNote`)})]})]})}),(0,G.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>{te(!1),re(!0)},children:F(`common.cancel`)}),(0,G.jsx)(Q,{variant:`danger`,onClick:()=>{$n.mutate({deleteArchives:ne}),te(!1),re(!0)},children:`Delete`})]})]})})}),e.is_active===!1?(0,G.jsx)(G.Fragment,{children:r===`compact`?(0,G.jsxs)(`div`,{className:`mt-2 flex items-center gap-2 px-2 py-1.5 rounded-full bg-amber-50 dark:bg-amber-500/15 border border-amber-300 dark:border-amber-500/30`,children:[(0,G.jsx)(Zu,{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-[length:var(--pc-t11,11px)] text-amber-700 dark:text-amber-400 font-medium truncate`,children:F(`printers.maintenance.pillLabel`)})]}):(0,G.jsxs)(G.Fragment,{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.status.title`,`Status`)}),(0,G.jsx)(`div`,{className:`flex-1 h-[2px] bg-bambu-dark-tertiary`})]}),(0,G.jsxs)(`div`,{className:`p-3 bg-amber-50 dark:bg-amber-500/10 border border-amber-300 dark:border-amber-500/30 rounded-[10px] flex items-center gap-3`,children:[(0,G.jsx)(Zu,{className:`w-6 h-6 text-amber-600 dark:text-amber-400 shrink-0`}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`p`,{className:`text-sm text-amber-700 dark:text-amber-400 font-medium`,children:F(`printers.maintenance.title`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:F(`printers.maintenance.subtitle`)})]}),(0,G.jsx)(Q,{variant:`secondary`,size:`sm`,disabled:Or.isPending||!z(`printers:update`),onClick:()=>Or.mutate(!0),title:z(`printers:update`)?void 0:F(`printers.permission.noEdit`),children:F(`printers.maintenance.exitButton`)})]})]})}):W?.connected&&(0,G.jsxs)(G.Fragment,{children:[r===`compact`?(()=>{let e=W.hms_errors?xm(W.hms_errors):[],t=W.state===`FAILED`||e.length>0,n=W.state===`RUNNING`||W.state===`PAUSE`?Math.max(0,Math.min(100,W.progress||0)):Kn||t?100:0,r=W.state===`RUNNING`||W.state===`PAUSE`,i=t?`bg-status-error`:W.state===`PAUSE`?`bg-status-warning`:`bg-bambu-green`,a=r&&W.remaining_time!=null&&W.remaining_time>0,o=r&&W.layer_num!=null&&W.total_layers!=null&&W.total_layers>0;return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`relative mt-2 flex items-center gap-2`,children:[(0,G.jsx)(`div`,{className:`h-1.5 min-w-0 flex-1 overflow-hidden rounded-full bg-bambu-dark-tertiary`,children:(0,G.jsx)(`div`,{className:`${i} h-1.5 rounded-full transition-all`,style:{width:`${n}%`}})}),(0,G.jsx)(`span`,{className:`w-9 shrink-0 text-right text-[length:var(--pc-t11,11px)] leading-none ${r?`text-white`:`text-bambu-gray`}`,children:r?`${Math.round(n)}%`:`---%`})]}),(0,G.jsxs)(`div`,{className:`mt-1 flex min-h-[14px] items-center gap-2 overflow-hidden text-[length:var(--pc-t11,11px)] leading-none text-bambu-gray`,children:[a&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`span`,{className:`flex shrink-0 items-center gap-1`,children:[(0,G.jsx)(ks,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)]`}),Yf(W.remaining_time*60)]}),(0,G.jsxs)(`span`,{className:`shrink-0 font-medium text-bambu-green`,title:F(`printers.estimatedCompletion`),children:[`ETA `,Jf(W.remaining_time,g,F)]})]}),o&&(0,G.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1 truncate`,children:[(0,G.jsx)(Uc,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)] shrink-0`}),W.layer_num,`/`,W.total_layers]})]})]})})():(0,G.jsxs)(G.Fragment,{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.status.title`,`Status`)}),(0,G.jsx)(`div`,{className:`flex-1 h-[2px] bg-bambu-dark-tertiary`})]}),(()=>{let t=!!(W.current_print&&(W.state===`RUNNING`||W.state===`PAUSE`)),n=!t&&Gn&&Jn,r=t?qn:n?Jn.name:null,i=t?W.cover_url:n?Jn.coverUrl:null,a=t?W.progress||0:n?100:0;return(0,G.jsxs)(`div`,{className:`p-2 bg-bambu-dark rounded-[10px] relative overflow-hidden`,children:[(0,G.jsxs)(`button`,{onClick:()=>Ve(!0),disabled:!t||(W.printable_objects_count??0)<2||!z(`printers:control`),className:`absolute top-2 right-2 p-1.5 rounded transition-colors z-10 ${t&&(W.printable_objects_count??0)>=2&&z(`printers:control`)?`text-bambu-gray hover:text-white hover:bg-white/10`:`text-bambu-gray/30 cursor-not-allowed`}`,title:z(`printers:control`)?t?(W.printable_objects_count??0)>=2?F(`printers.skipObjects.tooltip`):F(`printers.skipObjects.requiresMultiple`):F(`printers.skipObjects.onlyWhilePrinting`):F(`printers.permission.noControl`),children:[(0,G.jsx)(bT,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)]`}),Nr&&Nr.skipped_count>0&&(0,G.jsx)(`span`,{className:`absolute -top-1 -right-1 min-w-[16px] h-4 px-1 flex items-center justify-center text-[length:var(--pc-t10,10px)] font-bold bg-red-500 text-white rounded-full`,children:Nr.skipped_count})]}),(0,G.jsxs)(`div`,{className:`flex items-stretch gap-2`,children:[(0,G.jsx)(DOe,{url:i,printName:r||void 0,className:`w-24 h-24 max-[520px]:w-20 max-[520px]:h-20`}),(0,G.jsxs)(`div`,{className:`flex h-24 max-[520px]:h-20 min-w-0 flex-1 flex-col justify-between pt-1`,children:[(0,G.jsxs)(`div`,{className:`flex min-h-[18px] items-center gap-2 pr-8`,children:[(0,G.jsx)(`p`,{className:`min-w-0 truncate text-sm text-bambu-gray`,children:jOe(W.state,W.stg_cur_name)}),Zn]}),(0,G.jsx)(`p`,{className:`min-h-[18px] truncate pr-8 text-sm ${r?`text-white`:`text-bambu-gray/70`}`,children:r||F(`printers.noActiveJob`,`No active job`)}),(0,G.jsxs)(`div`,{className:`flex h-3 items-center gap-2 text-sm`,children:[(0,G.jsx)(`div`,{className:`h-1.5 min-w-0 flex-1 rounded-full bg-bambu-dark-tertiary`,children:(0,G.jsx)(`div`,{className:`${t?W.state===`PAUSE`?`bg-status-warning`:`bg-bambu-green`:n?`bg-bambu-green`:`bg-bambu-dark-tertiary`} h-1.5 rounded-full transition-all`,style:{width:`${a}%`}})}),(0,G.jsx)(`span`,{className:`w-9 shrink-0 pr-1 text-right text-[length:var(--pc-t11,11px)] leading-none ${t||n?`text-white`:`text-bambu-gray`}`,children:t||n?`${Math.round(a)}%`:`---%`})]}),(0,G.jsx)(`div`,{className:`flex min-h-[16px] items-center gap-2 text-xs text-bambu-gray`,children:t?(0,G.jsxs)(G.Fragment,{children:[W.remaining_time!=null&&W.remaining_time>0&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(ks,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)]`}),Yf(W.remaining_time*60)]}),(0,G.jsxs)(`span`,{className:`text-bambu-green font-medium`,title:F(`printers.estimatedCompletion`),children:[`ETA `,Jf(W.remaining_time,g,F)]})]}),W.layer_num!=null&&W.total_layers!=null&&W.total_layers>0&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(Uc,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)]`}),W.layer_num,`/`,W.total_layers]}),Vn&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1`,title:`Started by ${Vn}`,children:[(0,G.jsx)(Ru,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)]`}),Vn]})]}):Un?(0,G.jsxs)(`p`,{className:`truncate`,title:Un.print_name||Un.filename,children:[`Last: `,Un.print_name||Un.filename,Un.completed_at&&(0,G.jsxs)(`span`,{className:`ml-1 text-bambu-gray/60`,children:[`• `,Gf(Un.completed_at,{month:`short`,day:`numeric`})]})]}):(0,G.jsx)(`span`,{children:F(`printers.readyToPrint`)})})]})]}),(0,G.jsx)(Kse,{printerId:e.id,printerModel:e.model,loadedFilamentTypes:an,loadedFilaments:on,loadedVariants:sn,variant:`panelExtension`})]})})()]}),W.temperatures&&r===`expanded`&&(()=>{let t=W.temperatures.nozzle_heating||W.temperatures.nozzle_2_heating||!1,n=W.temperatures.bed_heating||!1,r=W.temperatures.chamber_heating||!1,i=e.nozzle_count===2||W.temperatures.nozzle_2!==void 0,a=(()=>{let e=[`nozzle`];return W.temperatures.nozzle_2!==void 0&&e.push(`nozzle_2`),e.push(`bed`),W.temperatures.chamber!==void 0&&e.push(`chamber`),e})(),o=W.active_extruder===1?`L`:`R`,s=W.nozzle_rack?.find(e=>e.id===1),c=W.nozzle_rack?.find(e=>e.id===0),l=c||s,u=W.connected&&z(`printers:control`),d=u?void 0:F(`printers.permission.noControl`),f=`relative text-center px-2 py-1.5 bg-bambu-dark rounded-lg flex-1 flex flex-col justify-center items-center transition-colors ${u?`cursor-pointer hover:bg-bambu-dark-tertiary`:`cursor-default opacity-80`}`,p=MOe.has(e.model??``),m=NOe.has(e.model??``),h=F(m?`printers.fans.exhaust`:`printers.fans.chamber`),g=p&&(!m||W.exhaust_fan_present),_=[{key:`part`,label:F(`printers.fans.partCooling`),value:W.cooling_fan_speed??0,Icon:rc,activeClass:`text-cyan-600 dark:text-cyan-400`},...W.left_aux_fan_speed==null?[]:[{key:`aux2`,label:F(`printers.fans.leftAuxiliary`),value:W.left_aux_fan_speed,Icon:Yu,activeClass:`text-indigo-600 dark:text-indigo-400`}],{key:`aux`,label:F(`printers.fans.auxiliary`),value:W.big_fan1_speed??0,Icon:Yu,activeClass:`text-blue-600 dark:text-blue-400`},...g?[{key:`chamber`,label:h,value:W.big_fan2_speed??0,Icon:Mo,activeClass:`text-green-600 dark:text-green-400`}]:[]];return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`mt-2 flex items-stretch gap-1.5 flex-wrap`,children:[(0,G.jsxs)(`div`,{className:f,title:d,onClick:()=>u&&Fe(Pe===`nozzle-temp`?null:`nozzle-temp`),children:[(0,G.jsx)(`button`,{type:`button`,className:`absolute top-0.5 right-0.5 p-0.5 rounded text-bambu-gray hover:text-white hover:bg-white/10 transition-colors`,title:F(`printers.heaterHistory.openLabel`,`View heater history`),onClick:e=>{e.stopPropagation(),Ft({initialKind:`nozzle`,availableKinds:a})},children:(0,G.jsx)(ss,{className:`w-[var(--pc-i25,0.625rem)] h-[var(--pc-i25,0.625rem)]`})}),(0,G.jsx)(eG,{className:`w-[var(--pc-i35,0.875rem)] h-[var(--pc-i35,0.875rem)] mb-0.5`,color:`text-orange-400`,isHeating:t}),W.temperatures.nozzle_2===void 0?l?(0,G.jsx)($W,{slot:l,index:0,activeStatus:!0,filamentName:l.filament_id?cn?.[l.filament_id]?.name:void 0,children:(0,G.jsxs)(`div`,{className:`cursor-default`,children:[(0,G.jsx)(`p`,{className:`text-[length:var(--pc-t9,9px)] text-bambu-gray`,children:F(`printers.temperatures.nozzle`)}),(0,G.jsxs)(`p`,{className:`text-[length:var(--pc-t11,11px)] text-white`,children:[Math.round(W.temperatures.nozzle||0),`°C`]})]})}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`p`,{className:`text-[length:var(--pc-t9,9px)] text-bambu-gray`,children:F(`printers.temperatures.nozzle`)}),(0,G.jsxs)(`p`,{className:`text-[length:var(--pc-t11,11px)] text-white`,children:[Math.round(W.temperatures.nozzle||0),`°C`]})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`p`,{className:`text-[length:var(--pc-t9,9px)] text-bambu-gray`,children:`L / R`}),(0,G.jsxs)(`p`,{className:`text-[length:var(--pc-t11,11px)] text-white`,children:[Math.round(W.temperatures.nozzle||0),`° / `,Math.round(W.temperatures.nozzle_2||0),`°`]})]}),Pe===`nozzle-temp`&&(i?(0,G.jsx)(oG,{title:`Set Nozzle Temperatures`,widthClass:`w-[300px]`,popoverWidth:300,popoverHeight:260,isPending:hr.isPending,onClose:()=>Fe(null),children:(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-2 px-3 py-2.5`,children:[(0,G.jsx)(sG,{label:`Left Temp`,current:W.temperatures.nozzle,target:W.temperatures.nozzle_target,isActive:o===`L`,isPending:hr.isPending,onSubmit:e=>hr.mutate({target:e,nozzle:1}),options:_m(O,`C`)}),(0,G.jsx)(sG,{label:`Right Temp`,current:W.temperatures.nozzle_2,target:W.temperatures.nozzle_2_target,isActive:o===`R`,isPending:hr.isPending,onSubmit:e=>hr.mutate({target:e,nozzle:0}),options:_m(O,`C`)})]})}):(0,G.jsx)(oG,{title:`Set Nozzle Temperature`,unit:`°C`,customMin:0,customMax:320,isPending:hr.isPending,options:_m(O,`C`),onClose:()=>Fe(null),onSubmit:e=>hr.mutate({target:e,nozzle:W.active_extruder??0})}))]}),(0,G.jsxs)(`div`,{className:f,title:d,onClick:()=>u&&Fe(Pe===`bed-temp`?null:`bed-temp`),children:[(0,G.jsx)(`button`,{type:`button`,className:`absolute top-0.5 right-0.5 p-0.5 rounded text-bambu-gray hover:text-white hover:bg-white/10 transition-colors`,title:F(`printers.heaterHistory.openLabel`,`View heater history`),onClick:e=>{e.stopPropagation(),Ft({initialKind:`bed`,availableKinds:a})},children:(0,G.jsx)(ss,{className:`w-[var(--pc-i25,0.625rem)] h-[var(--pc-i25,0.625rem)]`})}),(0,G.jsx)(eG,{className:`w-[var(--pc-i35,0.875rem)] h-[var(--pc-i35,0.875rem)] mb-0.5`,color:`text-blue-400`,isHeating:n}),(0,G.jsx)(`p`,{className:`text-[length:var(--pc-t9,9px)] text-bambu-gray`,children:F(`printers.temperatures.bed`)}),(0,G.jsxs)(`p`,{className:`text-[length:var(--pc-t11,11px)] text-white`,children:[Math.round(W.temperatures.bed||0),`°C`]}),Pe===`bed-temp`&&(0,G.jsx)(oG,{title:`Set Bed Temperature`,unit:`°C`,customMin:0,customMax:140,isPending:gr.isPending,options:_m(k,`C`),onClose:()=>Fe(null),onSubmit:e=>gr.mutate(e)})]}),W.temperatures.chamber!==void 0&&(()=>{let e=W.supports_chamber_heater===!0;return(0,G.jsxs)(`div`,{className:e?f:`relative text-center px-2 py-1.5 bg-bambu-dark rounded-lg flex-1 flex flex-col justify-center items-center`,title:e?d:void 0,onClick:e?()=>u&&Fe(Pe===`chamber-temp`?null:`chamber-temp`):void 0,children:[(0,G.jsx)(`button`,{type:`button`,className:`absolute top-0.5 right-0.5 p-0.5 rounded text-bambu-gray hover:text-white hover:bg-white/10 transition-colors`,title:F(`printers.heaterHistory.openLabel`,`View heater history`),onClick:e=>{e.stopPropagation(),Ft({initialKind:`chamber`,availableKinds:a})},children:(0,G.jsx)(ss,{className:`w-[var(--pc-i25,0.625rem)] h-[var(--pc-i25,0.625rem)]`})}),(0,G.jsx)(eG,{className:`w-[var(--pc-i35,0.875rem)] h-[var(--pc-i35,0.875rem)] mb-0.5`,color:`text-green-400`,isHeating:r}),(0,G.jsx)(`p`,{className:`text-[length:var(--pc-t9,9px)] text-bambu-gray`,children:F(`printers.temperatures.chamber`)}),(0,G.jsxs)(`p`,{className:`text-[length:var(--pc-t11,11px)] text-white`,children:[Math.round(W.temperatures.chamber||0),`°C`]}),e&&Pe===`chamber-temp`&&(0,G.jsx)(oG,{title:`Set Chamber Temperature`,unit:`°C`,customMin:0,customMax:65,isPending:_r.isPending,options:_m(A,`C`),onClose:()=>Fe(null),onSubmit:e=>_r.mutate(e)})]})})(),i&&(0,G.jsx)(hOe,{leftSlot:s,rightSlot:c,activeNozzle:o,filamentInfo:cn,children:(0,G.jsxs)(`div`,{className:`relative text-center px-3 py-1.5 bg-bambu-dark rounded-lg h-full flex flex-col justify-center items-center transition-colors ${u?`cursor-pointer hover:bg-bambu-dark-tertiary`:`cursor-default opacity-80`}`,title:u?F(`printers.activeNozzle`,{nozzle:F(o===`L`?`common.left`:`common.right`)}):d,onClick:()=>u&&Fe(Pe===`nozzle-select`?null:`nozzle-select`),children:[(0,G.jsx)(COe,{className:`w-[var(--pc-i35,0.875rem)] h-[var(--pc-i35,0.875rem)] mb-0.5 text-amber-600 dark:text-amber-400`}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`span`,{className:`text-[length:var(--pc-t11,11px)] font-bold ${o===`L`?`text-amber-700 dark:text-amber-400`:`text-gray-500`}`,children:[`L`,s?.nozzle_diameter?` ${s.nozzle_diameter}`:``]}),(0,G.jsx)(`span`,{className:`text-[length:var(--pc-t9,9px)] text-bambu-gray/40`,children:`·`}),(0,G.jsxs)(`span`,{className:`text-[length:var(--pc-t11,11px)] font-bold ${o===`R`?`text-amber-700 dark:text-amber-400`:`text-gray-500`}`,children:[`R`,c?.nozzle_diameter?` ${c.nozzle_diameter}`:``]})]}),(0,G.jsx)(`p`,{className:`text-[length:var(--pc-t9,9px)] text-bambu-gray`,children:F(`printers.temperatures.nozzle`)}),Pe===`nozzle-select`&&(0,G.jsx)(oG,{title:`Set Nozzle Selection`,widthClass:`w-[300px]`,popoverWidth:300,popoverHeight:140,isPending:yr.isPending,options:[{label:`Left`,value:1},{label:`Right`,value:0}],onClose:()=>Fe(null),onSubmit:e=>yr.mutate(e)})]})}),W.nozzle_rack&&W.nozzle_rack.some(e=>e.id>=2)&&(0,G.jsx)(gOe,{slots:W.nozzle_rack,filamentInfo:cn})]}),(0,G.jsx)(`div`,{className:`mt-2 flex items-center gap-1.5`,children:_.map(({key:e,label:t,value:n,Icon:r,activeClass:i})=>{let a=n>0;return(0,G.jsxs)(`div`,{className:`relative px-2 py-1.5 bg-bambu-dark rounded-lg flex-1 min-w-0 flex items-center justify-center gap-1 transition-colors ${u?`cursor-pointer hover:bg-bambu-dark-tertiary`:`cursor-default opacity-80`}`,title:u?t:d,onClick:()=>u&&Fe(Pe===`fan-${e}`?null:`fan-${e}`),children:[(0,G.jsx)(r,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)] shrink-0 ${a?i:`text-bambu-gray/50`}`}),(0,G.jsxs)(`span`,{className:`text-[length:var(--pc-t10,10px)] leading-none ${a?`text-white`:`text-bambu-gray/50`}`,children:[n,`%`]}),Pe===`fan-${e}`&&(0,G.jsx)(oG,{title:`Set ${t} Speed`,unit:`%`,customMin:0,customMax:100,isPending:vr.isPending,options:_m(j,`%`),onClose:()=>Fe(null),onSubmit:t=>vr.mutate({fan:e,speed:t})})]},e)})})]})})(),r===`expanded`&&Kn&&(0,G.jsxs)(`button`,{type:`button`,onClick:()=>mr.mutate(),disabled:mr.isPending||!z(`printers:clear_plate`),className:`mt-2 w-full inline-flex items-center justify-center gap-2 px-3 py-1.5 rounded-lg bg-yellow-100 dark:bg-yellow-500/20 border border-yellow-300 dark:border-yellow-400/40 text-yellow-700 dark:text-yellow-400 hover:bg-yellow-500/30 transition-colors text-xs font-medium disabled:opacity-50`,title:z(`printers:clear_plate`)?F(`printers.plateStatus.markCleared`):F(`printers.permission.noControl`),children:[mr.isPending?(0,G.jsx)(Y,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)] animate-spin`}):(0,G.jsx)(yW,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)]`}),F(`printers.plateStatus.markCleared`)]}),r===`expanded`&&(()=>{let t=W.state===`RUNNING`,n=W.state===`PAUSE`,r=t||n,i=dr.isPending||fr.isPending||pr.isPending,a=`bg-bambu-dark text-bambu-gray/50 cursor-not-allowed opacity-50`,o=`flex h-8 w-8 items-center justify-center rounded-lg text-xs font-medium transition-colors disabled:opacity-50 disabled:cursor-not-allowed`,s=`flex h-8 w-20 items-center justify-center gap-1 px-2 rounded-lg text-xs font-medium transition-colors`;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.controls`)}),(0,G.jsx)(`div`,{className:`flex-1 h-[2px] bg-bambu-dark-tertiary`})]}),(0,G.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-x-2 gap-y-2`,children:[(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 min-w-0`,children:[(0,G.jsx)(`button`,{onClick:()=>br.mutate(!W.chamber_light),disabled:!W.connected||br.isPending||!z(`printers:control`),className:`${o} ${W.chamber_light?`bg-yellow-50 dark:bg-yellow-500/10 text-yellow-700 dark:text-yellow-400 hover:bg-yellow-500/20`:`bg-bambu-dark text-bambu-gray/50 hover:bg-bambu-dark-tertiary hover:text-white`}`,title:z(`printers:control`)?W.chamber_light?F(`printers.chamberLightOff`):F(`printers.chamberLightOn`):F(`printers.permission.noControl`),children:(0,G.jsx)(yT,{on:W.chamber_light??!1,className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)]`})}),[`P2S`,`X2D`,`H2D`,`H2C`,`H2S`].includes(e.model??``)&&(()=>{let t=W.airduct_mode===1,n=t?dc:fu,r=t?`text-orange-600 dark:text-orange-400`:`text-sky-600 dark:text-sky-400`,i=t?`bg-orange-50 dark:bg-orange-500/10 text-orange-700 dark:text-orange-400 hover:bg-orange-500/20`:`bg-sky-50 dark:bg-sky-500/10 text-sky-700 dark:text-sky-400 hover:bg-sky-500/20`;return(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(`button`,{onClick:()=>je(Ae===e.id?null:e.id),disabled:!z(`printers:control`),className:`${o} ${i}`,title:`${F(`printers.airduct.title`)}: ${F(t?`printers.airduct.heating`:`printers.airduct.cooling`)}`,children:(0,G.jsx)(n,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)] ${r}`})}),Ae===e.id&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`fixed inset-0 z-40`,onClick:()=>je(null)}),(0,G.jsx)(`div`,{className:`absolute bottom-full left-0 mb-1 z-50 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg py-1 min-w-[130px]`,children:[{mode:`cooling`,label:F(`printers.airduct.cooling`),modeId:0},{mode:`heating`,label:F(`printers.airduct.heating`),modeId:1}].map(({mode:e,label:t,modeId:n})=>(0,G.jsxs)(`button`,{onClick:()=>{Sr.mutate(e),je(null)},className:`w-full text-left px-3 py-1.5 text-xs transition-colors flex items-center gap-2 ${W.airduct_mode===n?`text-bambu-green bg-bambu-green/10`:`text-white hover:bg-bambu-dark-tertiary`}`,children:[e===`heating`?(0,G.jsx)(dc,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)]`}):(0,G.jsx)(fu,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)]`}),t]},e))})]})]})})(),(()=>{let t=z(`printers:control`),n=r||!t,i=`flex h-8 w-8 items-center justify-center rounded bg-indigo-100 dark:bg-indigo-500/15 text-indigo-700 dark:text-indigo-300 transition-colors hover:bg-indigo-200 dark:hover:bg-indigo-500/30 disabled:cursor-not-allowed disabled:opacity-50`,a=e=>{let t=e*Ie*1;Cr.mutate({distance:t})},s=(e,t)=>{wr.mutate({x:e,y:t})},c=e=>{Tr.mutate(e)};return(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(`button`,{onClick:()=>Ne(Me===e.id?null:e.id),disabled:n,className:`${o} ${n?`bg-bambu-dark text-bambu-gray/50 cursor-not-allowed`:`bg-indigo-50 dark:bg-indigo-500/10 text-indigo-700 dark:text-indigo-400 hover:bg-indigo-500/20`}`,title:F(t?r?`printers.bedJog.disabledWhilePrinting`:`printers.bedJog.title`:`printers.permission.noControl`),children:(0,G.jsx)(hl,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)]`})}),Me===e.id&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`fixed inset-0 z-40`,onClick:()=>Ne(null)}),(0,G.jsxs)(`div`,{className:`absolute bottom-full left-0 mb-1 z-50 flex w-[216px] flex-col overflow-hidden rounded-xl border border-bambu-dark-tertiary bg-bambu-dark-secondary shadow-2xl`,children:[(0,G.jsx)(`div`,{className:`shrink-0 px-3 py-2.5 text-center text-sm font-medium text-white`,children:F(`printers.bedJog.title`)}),(0,G.jsx)(`div`,{className:`h-px bg-bambu-dark-tertiary`}),(0,G.jsxs)(`div`,{className:`flex items-start gap-1.5 bg-yellow-500/10 px-3 py-2 text-[length:var(--pc-t11,11px)] leading-snug text-yellow-700 dark:text-yellow-400`,children:[(0,G.jsx)(Nu,{className:`mt-0.5 h-3.5 w-3.5 shrink-0`}),(0,G.jsx)(`span`,{children:F(`printers.bedJog.limitWarning`)})]}),(0,G.jsx)(`div`,{className:`h-px bg-bambu-dark-tertiary`}),(0,G.jsx)(`div`,{className:`flex justify-center px-3 py-2.5`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-center gap-3`,children:[(0,G.jsxs)(`div`,{className:`grid grid-cols-3 gap-1`,children:[(0,G.jsx)(`div`,{}),(0,G.jsx)(`button`,{onClick:()=>s(0,Ie),disabled:wr.isPending,className:i,"aria-label":`Move Y forward`,children:(0,G.jsx)(Vo,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)]`})}),(0,G.jsx)(`div`,{}),(0,G.jsx)(`button`,{onClick:()=>s(-Ie,0),disabled:wr.isPending,className:i,"aria-label":`Move X left`,children:(0,G.jsx)(Io,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)]`})}),(0,G.jsx)(`button`,{onClick:()=>{Ne(null),Er.mutate(`all`)},disabled:Er.isPending,className:i,"aria-label":F(`printers.bedJog.homeZ`),children:(0,G.jsx)(Fc,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)]`})}),(0,G.jsx)(`button`,{onClick:()=>s(Ie,0),disabled:wr.isPending,className:i,"aria-label":`Move X right`,children:(0,G.jsx)(Ro,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)]`})}),(0,G.jsx)(`div`,{}),(0,G.jsx)(`button`,{onClick:()=>s(0,-Ie),disabled:wr.isPending,className:i,"aria-label":`Move Y back`,children:(0,G.jsx)(Fo,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)]`})}),(0,G.jsx)(`div`,{})]}),(0,G.jsxs)(`div`,{className:`flex flex-col items-center gap-1`,children:[(0,G.jsx)(`button`,{onClick:()=>a(-1),disabled:Cr.isPending,className:i,"aria-label":F(`printers.bedJog.up`),children:(0,G.jsx)(Vo,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)]`})}),(0,G.jsx)(`div`,{className:`flex h-8 w-8 items-center justify-center text-bambu-gray/80`,children:(0,G.jsx)(Uc,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)]`})}),(0,G.jsx)(`button`,{onClick:()=>a(1),disabled:Cr.isPending,className:i,"aria-label":F(`printers.bedJog.down`),children:(0,G.jsx)(Fo,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)]`})})]}),(0,G.jsxs)(`div`,{className:`flex flex-col items-center gap-1`,children:[(0,G.jsx)(`button`,{onClick:()=>c(-Ie),disabled:Tr.isPending,className:i,"aria-label":`Retract filament`,children:(0,G.jsx)(Vo,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)]`})}),(0,G.jsx)(`div`,{className:`flex h-8 w-8 items-center justify-center text-bambu-gray/80`,children:(0,G.jsx)(`span`,{className:`text-sm font-semibold leading-none`,children:`E`})}),(0,G.jsx)(`button`,{onClick:()=>c(Ie),disabled:Tr.isPending,className:i,"aria-label":`Extrude filament`,children:(0,G.jsx)(Fo,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)]`})})]})]})}),(0,G.jsx)(`div`,{className:`h-px bg-bambu-dark-tertiary`}),(0,G.jsxs)(`div`,{className:`px-3 pt-2.5 pb-3`,children:[(0,G.jsx)(`div`,{className:`mb-1 text-[length:var(--pc-t9,9px)] uppercase tracking-wider text-bambu-gray/70`,children:F(`printers.bedJog.step`)}),(0,G.jsx)(`div`,{className:`flex gap-1`,children:[1,10,50].map(e=>(0,G.jsx)(`button`,{onClick:()=>Le(e),className:`flex-1 px-1 py-1 rounded text-[length:var(--pc-t10,10px)] transition-colors ${Ie===e?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:e},e))})]})]})]})]})})(),(0,G.jsxs)(`div`,{className:`inline-flex rounded-lg ${e.plate_detection_enabled?`ring-1 ring-green-500`:``}`,children:[(0,G.jsx)(`button`,{onClick:qr,disabled:!W.connected||Dr.isPending||!z(`printers:update`),className:`${o} rounded-r-none ${e.plate_detection_enabled?`bg-green-50 dark:bg-green-500/10 text-green-700 dark:text-green-400 hover:bg-green-500/20`:`bg-bambu-dark text-bambu-gray/50 hover:bg-bambu-dark-tertiary hover:text-white`}`,title:z(`printers:update`)?e.plate_detection_enabled?F(`printers.plateDetection.enabledClick`):F(`printers.plateDetection.disabledClick`):F(`printers.plateDetection.noPermission`),children:Dr.isPending?(0,G.jsx)(Y,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)] animate-spin`}):(0,G.jsx)(Kl,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)]`})}),(0,G.jsx)(`button`,{onClick:Jr,disabled:!W.connected||Kt||!z(`printers:update`),className:`flex h-8 w-8 items-center justify-center rounded-r-lg border-l border-bambu-dark-tertiary transition-colors disabled:opacity-50 disabled:cursor-not-allowed ${e.plate_detection_enabled?`bg-green-50 dark:bg-green-500/10 text-green-700 dark:text-green-400 hover:bg-green-500/20`:`bg-bambu-dark text-bambu-gray/50 hover:bg-bambu-dark-tertiary hover:text-white`}`,title:z(`printers:update`)?F(`printers.plateDetection.manageCalibration`):F(`printers.plateDetection.noPermission`),children:Kt?(0,G.jsx)(Y,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)] animate-spin`}):(0,G.jsx)(ds,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)]`})})]}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(`button`,{"data-testid":`speed-control`,onClick:()=>ke(Oe===e.id?null:e.id),disabled:!r||!z(`printers:control`),className:`${o} ${r?`bg-amber-50 dark:bg-amber-500/10 text-amber-700 dark:text-amber-400 hover:bg-amber-500/20`:`bg-bambu-dark text-bambu-gray/50 cursor-not-allowed`}`,title:r?F(`printers.speed.title`):void 0,children:(0,G.jsx)(xc,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)]`})}),Oe===e.id&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`fixed inset-0 z-40`,onClick:()=>ke(null)}),(0,G.jsx)(`div`,{className:`absolute bottom-full left-0 mb-1 z-50 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg py-1 min-w-[130px]`,children:[{mode:1,label:F(`printers.speed.silent`)},{mode:2,label:F(`printers.speed.standard`)},{mode:3,label:F(`printers.speed.sport`)},{mode:4,label:F(`printers.speed.ludicrous`)}].map(({mode:e,label:t})=>(0,G.jsx)(`button`,{onClick:()=>{xr.mutate(e),ke(null)},className:`w-full text-left px-3 py-1.5 text-xs transition-colors ${W.speed_level===e?`text-bambu-green bg-bambu-green/10`:`text-white hover:bg-bambu-dark-tertiary`}`,children:t},e))})]})]})]}),(0,G.jsxs)(`div`,{className:`ml-auto flex items-center justify-end gap-2 flex-shrink-0`,children:[(()=>{let e=!r||i||!z(`printers:control`);return(0,G.jsxs)(`button`,{onClick:()=>n?ze(!0):De(!0),disabled:e,className:` + `,style:{maxWidth:`calc(100vw - 24px)`},onMouseEnter:w,onMouseLeave:T,children:(0,G.jsxs)(`div`,{className:`w-52 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl overflow-hidden backdrop-blur-sm p-2.5 space-y-2`,children:[(0,G.jsx)(`div`,{className:`text-[length:var(--pc-t10,10px)] uppercase tracking-wider text-bambu-gray font-medium`,children:n}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,G.jsx)(`span`,{className:`text-[length:var(--pc-t10,10px)] tracking-wide text-bambu-gray font-medium shrink-0`,children:s(`printers.amsPopup.serialNumber`)}),(0,G.jsx)(`span`,{className:`text-[length:var(--pc-t10,10px)] text-white font-mono truncate`,children:e.serial_number||`—`})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,G.jsx)(`span`,{className:`text-[length:var(--pc-t10,10px)] tracking-wide text-bambu-gray font-medium shrink-0`,children:s(`printers.amsPopup.firmwareVersion`)}),(0,G.jsx)(`span`,{className:`text-[length:var(--pc-t10,10px)] text-white font-mono truncate`,children:e.sw_ver||`—`})]}),(0,G.jsxs)(`div`,{className:`space-y-1`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-[length:var(--pc-t10,10px)] text-bambu-gray font-medium shrink-0`,children:s(`printers.amsPopup.friendlyName`)}),(0,G.jsx)(`div`,{className:`flex-1 h-[2px] bg-bambu-dark-tertiary/50`})]}),(0,G.jsx)(`input`,{type:`text`,value:f,onChange:e=>i&&p(e.target.value),onKeyDown:e=>e.key===`Enter`&&E(),onFocus:()=>b(!0),onBlur:()=>{b(!1),C.current&&clearTimeout(C.current),C.current=setTimeout(()=>l(!1),200)},placeholder:i?s(`printers.amsPopup.friendlyNamePlaceholder`):r?.[e.id]||`—`,disabled:!i,title:i?void 0:s(`printers.amsPopup.noEditPermission`),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-2 py-1 text-xs text-white placeholder-bambu-gray/60 focus:outline-none focus:border-bambu-green disabled:opacity-50 disabled:cursor-not-allowed`,maxLength:100}),i&&(0,G.jsxs)(`div`,{className:`space-y-1`,children:[g&&(0,G.jsx)(`p`,{className:`text-[length:var(--pc-t10,10px)] text-red-700 dark:text-red-400 break-words`,children:g}),(0,G.jsxs)(`div`,{className:`flex gap-1 justify-end`,children:[(0,G.jsx)(`button`,{onClick:E,disabled:m,className:`px-2 py-0.5 text-[length:var(--pc-t10,10px)] bg-bambu-green text-white rounded hover:bg-bambu-green/80 disabled:opacity-50`,children:s(`printers.amsPopup.save`)}),r?.[e.id]&&(0,G.jsx)(`button`,{onClick:async()=>{if(i){h(!0),_(null);try{await Z.deleteAmsLabel(t,e.id,e.serial_number),a(),l(!1)}catch(e){_(e instanceof Error?e.message:String(e))}finally{h(!1)}}},disabled:m,className:`px-2 py-0.5 text-[length:var(--pc-t10,10px)] bg-bambu-dark-tertiary text-bambu-gray rounded hover:bg-bambu-dark-tertiary/70 disabled:opacity-50`,children:s(`printers.amsPopup.clear`)})]})]})]})]})})]})}var fG={PLA:{n3f:45,n3s:45,n3f_hours:12,n3s_hours:12},PETG:{n3f:65,n3s:65,n3f_hours:12,n3s_hours:12},TPU:{n3f:65,n3s:75,n3f_hours:12,n3s_hours:18},ABS:{n3f:65,n3s:80,n3f_hours:12,n3s_hours:8},ASA:{n3f:65,n3s:80,n3f_hours:12,n3s_hours:8},PA:{n3f:65,n3s:85,n3f_hours:12,n3s_hours:12},PC:{n3f:65,n3s:80,n3f_hours:12,n3s_hours:8},PVA:{n3f:65,n3s:85,n3f_hours:12,n3s_hours:18}},pG={1:1,2:1,3:1.2,4:1.4};function POe(e){let t=pG[e]??1,n=e=>`${Math.round(e*t*10)/10}px`;return{"--pc-t8":n(8),"--pc-t9":n(9),"--pc-t10":n(10),"--pc-t11":n(11),"--pc-i2":n(8),"--pc-i25":n(10),"--pc-i3":n(12),"--pc-i35":n(14),"--pc-i4":n(16),"--pc-i5":n(20),"--pc-i7":n(28)}}function FOe({printerId:e,dryingActive:t,timeFormat:n}){let{t:r}=U(),i=so(),{showToast:a}=zd(),{data:o=[]}=K({queryKey:GW,queryFn:()=>Z.listScheduledDryings(),refetchInterval:3e4});(0,y.useEffect)(()=>{t&&i.invalidateQueries({queryKey:GW})},[t,i]);let s=q({mutationFn:e=>Z.cancelScheduledDrying(e),onSuccess:()=>i.invalidateQueries({queryKey:GW}),onError:e=>a(e.message||r(`printers.drying.scheduleFailed`),`error`)}),c=o.filter(t=>t.printer_id===e&&(t.status===`pending`||t.status===`failed`));return c.length===0?null:(0,G.jsx)(`div`,{className:`mt-2 space-y-1`,children:c.map(e=>{let t=e.status===`failed`,i=fOe(e.waiting_reason);return(0,G.jsxs)(`div`,{"data-testid":t?`scheduled-drying-failed`:`scheduled-drying-pending`,className:`flex items-center justify-between px-2 py-1 rounded-lg text-[length:var(--pc-t11,11px)] ${t?`bg-red-500/10 border border-red-500/30`:`bg-amber-500/10 border border-amber-500/30`}`,children:[(0,G.jsx)(`span`,{className:t?`text-red-700 dark:text-red-400`:`text-amber-700 dark:text-amber-400`,children:t?r(`printers.drying.scheduleFailedReason`,{reason:e.error_message||r(`printers.drying.scheduleFailedUnknown`)}):(0,G.jsxs)(G.Fragment,{children:[e.start_after?r(`printers.drying.scheduledFor`,{time:Kf(e.start_after,n)}):r(`printers.drying.scheduledAsap`),i&&(0,G.jsx)(`span`,{className:`ml-1 opacity-80`,children:r(i)})]})}),(0,G.jsx)(`button`,{onClick:()=>s.mutate(e.id),disabled:s.isPending,title:r(t?`printers.drying.dismissFailed`:`printers.drying.cancelScheduled`),className:`text-bambu-gray hover:text-red-400 transition-colors disabled:opacity-50 disabled:cursor-not-allowed`,children:(0,G.jsx)(Qu,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)]`})})]},e.id)})})}function mG({printer:e,hideIfDisconnected:t,maintenanceInfo:n,viewMode:r=`expanded`,cardSize:i=2,amsThresholds:a,spoolmanEnabled:o=!1,linkedSpools:s,spoolmanUrl:c,spoolmanSyncMode:l,onGetAssignment:u,onUnassignSpool:d,spoolmanSpools:f,spoolmanSlotAssignments:p,spoolmanLoading:m=!1,onUnassignSpoolmanSpool:h,timeFormat:g=`system`,cameraViewMode:_=`window`,onOpenEmbeddedCamera:v,onSelectCameraViewMode:b,checkPrinterFirmware:x=!0,dryingPresets:S=fG,requirePlateClear:C=!1,selectionMode:w=!1,isSelected:T=!1,onToggleSelect:E,onOpenCompactCard:D,nozzleTempPresets:O=fm,bedTempPresets:k=pm,chamberTempPresets:A=mm,fanSpeedPresets:j=hm,aiDetectionEnabled:M=!1,aiDetection:N,aiLastError:P=null}){let{t:F}=U(),I=so(),L=or(),{showToast:R}=zd(),{hasPermission:z}=Td(),[B,V]=(0,y.useState)(!1),[ee,te]=(0,y.useState)(!1),[ne,re]=(0,y.useState)(!0),[ie,ae]=(0,y.useState)(!1),[oe,se]=(0,y.useState)(!1),[H,ce]=(0,y.useState)(!1),[le,ue]=(0,y.useState)(!1),[de,fe]=(0,y.useState)(!1),[pe,me]=(0,y.useState)(null),[he,ge]=(0,y.useState)(!1),[_e,ve]=(0,y.useState)(!1),[ye,be]=(0,y.useState)(!1),[xe,Se]=(0,y.useState)(()=>jee(e.id)),Ce=(0,y.useCallback)(()=>{Se(t=>{let n=!t;return Mee(e.id,n),n})},[e.id]),[we,Te]=(0,y.useState)(!1),[Ee,De]=(0,y.useState)(!1),[Oe,ke]=(0,y.useState)(null),[Ae,je]=(0,y.useState)(null),[Me,Ne]=(0,y.useState)(null),[Pe,Fe]=(0,y.useState)(null),[Ie,Le]=(0,y.useState)(10),[Re,ze]=(0,y.useState)(!1),[Be,Ve]=(0,y.useState)(!1),[He,Ue]=(0,y.useState)(!1),[We,Ge]=(0,y.useState)(!1),[Ke,qe]=(0,y.useState)(!1),Je=(0,y.useCallback)(()=>Ge(!1),[]),[Ye,Xe]=(0,y.useState)(null),[Ze,Qe]=(0,y.useState)(null),[$e,et]=(0,y.useState)(`n3f`),[tt,nt]=(0,y.useState)(`PLA`),[rt,it]=(0,y.useState)(50),[at,ot]=(0,y.useState)(4),[st,ct]=(0,y.useState)(!1),[lt,ut]=(0,y.useState)(`now`),[dt,ft]=(0,y.useState)(120),[pt,mt]=(0,y.useState)(``),[ht,gt]=(0,y.useState)(null),[_t,vt]=(0,y.useState)(null),yt=(0,y.useCallback)((e,t)=>{let n=kee(e.tray.find(e=>e.tray_type)?.tray_type,S),r=S[n]??fG.PLA,i=e.module_type;nt(n),it(r[i]||r.n3f),ot(i===`n3s`?r.n3s_hours:r.n3f_hours),ct(!1),ut(`now`),ft(120),mt(``),et(e.module_type),Qe(e.id),vt(t)},[S]);(0,y.useLayoutEffect)(()=>{if(Ze===null||!_t)return;let e=()=>{gt(nm({triggerRect:_t.getBoundingClientRect(),popoverWidth:cOe,estimatedHeight:lOe,horizontalAlign:`center`}))};return e(),window.addEventListener(`resize`,e),window.addEventListener(`scroll`,e,!0),()=>{window.removeEventListener(`resize`,e),window.removeEventListener(`scroll`,e,!0)}},[Ze,_t]);let bt=(0,y.useRef)(null),xt=(0,y.useRef)(!1),[St,Ct]=(0,y.useState)(null),[wt,Tt]=(0,y.useState)(!1),[Et,Dt]=(0,y.useState)(!1),Ot=(0,y.useRef)(null),[kt,At]=(0,y.useState)(null),jt=(0,y.useRef)(0),[Mt,Nt]=(0,y.useState)(null),[Pt,Ft]=(0,y.useState)(null),[It,Lt]=(0,y.useState)(null),[Rt,zt]=(0,y.useState)(null),[Bt,Vt]=(0,y.useState)(null),[Ht,Ut]=(0,y.useState)(!1),[Wt,Gt]=(0,y.useState)(null),[Kt,qt]=(0,y.useState)(!1),[Jt,Yt]=(0,y.useState)(!1),[Xt,Zt]=(0,y.useState)(null),[Qt,$t]=(0,y.useState)(!1),[en,tn]=(0,y.useState)(!1),{data:W}=K({queryKey:[`printerStatus`,e.id],queryFn:()=>Z.getPrinterStatus(e.id),refetchInterval:3e4}),{data:nn}=K({queryKey:[`firmwareUpdate`,e.id],queryFn:()=>vd.checkPrinterUpdate(e.id),staleTime:300*1e3,refetchInterval:300*1e3,enabled:x&&z(`firmware:read`)}),rn=(0,y.useMemo)(()=>{let e=new Set;if(W?.ams)for(let t of W.ams)for(let n of t.tray||[])n.tray_info_idx&&e.add(n.tray_info_idx);for(let t of W?.vt_tray??[])t.tray_info_idx&&e.add(t.tray_info_idx);if(W?.nozzle_rack)for(let t of W.nozzle_rack)t.filament_id&&e.add(t.filament_id);return Array.from(e)},[W?.ams,W?.vt_tray,W?.nozzle_rack]),an=(0,y.useMemo)(()=>{let e=new Set;if(W?.ams)for(let t of W.ams)for(let n of t.tray||[])n.tray_type&&e.add(n.tray_type.toUpperCase());for(let t of W?.vt_tray??[])t.tray_type&&e.add(t.tray_type.toUpperCase());return e},[W?.ams,W?.vt_tray]),on=(0,y.useMemo)(()=>{let e=new Set;if(W?.ams){for(let t of W.ams)for(let n of t.tray||[])if(n.tray_type&&n.tray_color){let t=n.tray_color.replace(`#`,``).toLowerCase().slice(0,6);e.add(`${n.tray_type.toUpperCase()}:${t}`)}}for(let t of W?.vt_tray??[])if(t.tray_type&&t.tray_color){let n=t.tray_color.replace(`#`,``).toLowerCase().slice(0,6);e.add(`${t.tray_type.toUpperCase()}:${n}`)}return e},[W?.ams,W?.vt_tray]),sn=(0,y.useMemo)(()=>{let e=new Set;if(W?.ams){for(let t of W.ams)for(let n of t.tray||[])if(n.tray_type&&n.tray_color){let t=n.tray_color.replace(`#`,``).toLowerCase().slice(0,6);e.add(`${n.tray_type.toUpperCase()}:${t}:${n.tray_info_idx||``}`)}}for(let t of W?.vt_tray??[])if(t.tray_type&&t.tray_color){let n=t.tray_color.replace(`#`,``).toLowerCase().slice(0,6);e.add(`${t.tray_type.toUpperCase()}:${n}:${t.tray_info_idx||``}`)}return e},[W?.ams,W?.vt_tray]),{data:cn}=K({queryKey:[`filamentInfo`,rn],queryFn:()=>Z.getFilamentInfo(rn),enabled:rn.length>0,staleTime:300*1e3}),{data:ln}=K({queryKey:[`slotPresets`,e.id],queryFn:()=>Z.getSlotPresets(e.id),staleTime:120*1e3}),un=W?.state===`RUNNING`||W?.state===`PAUSE`?W?.current_archive_id??null:null,{data:dn}=K({queryKey:[`archive-plates`,un],queryFn:()=>Z.getArchivePlates(un),enabled:un!=null,staleTime:300*1e3}),fn=!dn?.is_multi_plate||W?.current_plate_id==null?null:dn.plates.find(e=>e.index===W.current_plate_id)?.name||F(`printers.plateNumber`,`Plate {{number}}`,{number:W.current_plate_id}),{data:pn,refetch:mn}=K({queryKey:[`amsLabels`,e.id],queryFn:()=>Z.getAmsLabels(e.id),staleTime:300*1e3}),[hn,gn]=(0,y.useState)(null);(0,y.useEffect)(()=>{W?.wifi_signal!=null&&gn(W.wifi_signal)},[W?.wifi_signal]);let _n=W?.wifi_signal??hn,vn=(0,y.useRef)(void 0);(0,y.useEffect)(()=>{W?.connected!==void 0&&(vn.current=W.connected)},[W?.connected]);let yn=W?.connected??vn.current,bn=(0,y.useRef)({});(0,y.useEffect)(()=>{W?.ams_extruder_map&&Object.keys(W.ams_extruder_map).length>0&&(bn.current=W.ams_extruder_map)},[W?.ams_extruder_map]);let xn=W?.ams_extruder_map&&Object.keys(W.ams_extruder_map).length>0?W.ams_extruder_map:bn.current,Sn=(0,y.useRef)({});(0,y.useEffect)(()=>{W?.ams_switch_inlet&&Object.keys(W.ams_switch_inlet).length>0&&(Sn.current=W.ams_switch_inlet)},[W?.ams_switch_inlet]);let Cn=W?.fila_switch?.installed===!0,wn=W?.ams_switch_inlet&&Object.keys(W.ams_switch_inlet).length>0?W.ams_switch_inlet:Sn.current,Tn=(0,y.useRef)([]);(0,y.useEffect)(()=>{W?.ams&&W.ams.length>0&&(Tn.current=W.ams)},[W?.ams]);let En=W?.ams&&W.ams.length>0?W.ams:Tn.current;(0,y.useEffect)(()=>{if(!St)return;let e=En.find(e=>e.id===St.amsId);e&&(e.dry_time>0||e.dry_status>0)&&Ct(null)},[St,En]),(0,y.useEffect)(()=>{if(!St)return;let e=setTimeout(()=>{Ct(null),R(F(`printers.drying.toastNotStarted`),`error`)},EOe);return()=>clearTimeout(e)},[St,R,F]);let Dn=(0,y.useRef)(void 0),On=W?.tray_now;On!==void 0&&On!==255?Dn.current=On:On===255&&(Dn.current=void 0);let kn=On!==void 0&&On!==255?On:Dn.current,An=W?.expected_tray??null,jn=W?.previous_tray??null,Mn=e=>{if(e===null)return null;if(e===254)return F(`printers.expectedSlot.external`);if(e>=128&&e<=135)return pn?.[e]||ap(e,1);let t=Math.floor(e/4),n=e%4;return F(`printers.expectedSlot.label`,{ams:pn?.[t]||ap(t,4),slot:n+1})},Nn=W?.state===`PAUSE`?{expectedSlotLabel:Mn(An),ranOutSlotLabel:Mn(jn)}:null,{data:Pn}=K({queryKey:[`smartPlugByPrinter`,e.id],queryFn:()=>Z.getSmartPlugByPrinter(e.id)}),{data:Fn}=K({queryKey:[`scriptPlugsByPrinter`,e.id],queryFn:()=>Z.getScriptPlugsByPrinter(e.id)}),{data:In}=K({queryKey:[`smartPlugStatus`,Pn?.id],queryFn:()=>Pn?Z.getSmartPlugStatus(Pn.id):null,enabled:!!Pn,refetchInterval:1e4}),{data:Ln}=K({queryKey:[`queue`,e.id,`pending`],queryFn:()=>Z.getQueue(e.id,`pending`)}),Rn=(0,y.useMemo)(()=>Ln?.length?dm(Ln,an,on,sn).length:0,[Ln,an,on,sn]),{data:zn}=K({queryKey:[`queue`,e.id,`printing`],queryFn:()=>Z.getQueue(e.id,`printing`),enabled:W?.state===`RUNNING`}),{data:Bn}=K({queryKey:[`currentPrintUser`,e.id],queryFn:()=>Z.getCurrentPrintUser(e.id),enabled:W?.state===`RUNNING`}),Vn=zn?.[0]?.created_by_username||Bn?.username,{data:Hn}=K({queryKey:[`archives`,e.id,`last`],queryFn:()=>Z.getArchives(e.id,1,0),enabled:W?.connected&&W?.state!==`RUNNING`}),Un=Hn?.[0],Wn=W?.state===`RUNNING`||W?.state===`PAUSE`,Gn=C&&W?.awaiting_plate_clear===!0,Kn=Gn&&!Wn,qn=W?.current_print&&Wn?Cee(W.subtask_name||W.current_print||null,W.gcode_file,F,fn):null,[Jn,Yn]=(0,y.useState)(null);(0,y.useEffect)(()=>{qn?Yn({name:qn,coverUrl:W?.cover_url??null}):Gn||Yn(null)},[qn,Gn,W?.cover_url]);let Xn=!C||!W?.connected?null:Wn?{label:F(`printers.plateStatus.inUse`),className:`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`}:W.awaiting_plate_clear?{label:F(`printers.plateStatus.notCleared`),className:`bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400`}:{label:F(`printers.plateStatus.cleared`),className:`bg-status-ok/20 text-status-ok`},Zn=Xn?(0,G.jsx)(`span`,{className:`inline-flex flex-shrink-0 items-center rounded-full px-2 py-0.5 text-[length:var(--pc-t10,10px)] font-medium ${Xn.className}`,children:Xn.label}):null,Qn=t&&yn===!1,$n=q({mutationFn:t=>Z.deletePrinter(e.id,t.deleteArchives),onSuccess:()=>{I.invalidateQueries({queryKey:[`printers`]}),I.invalidateQueries({queryKey:[`archives`]}),I.invalidateQueries({queryKey:[`maintenanceOverview`]})},onError:e=>R(e.message||F(`printers.toast.failedToDelete`),`error`)}),er=q({mutationFn:()=>Z.connectPrinter(e.id),onSuccess:()=>{I.invalidateQueries({queryKey:[`printerStatus`,e.id]})}}),tr=q({mutationFn:()=>Z.refreshPrinterStatus(e.id),onSuccess:()=>{I.invalidateQueries({queryKey:[`printerStatus`,e.id]}),R(F(`printers.forceRefreshSuccess`),`success`)},onError:e=>R(e.message||F(`printers.toast.failedToSendCommand`),`error`)}),nr=q({mutationFn:e=>Z.unlinkSpool(e),onSuccess:e=>{R(F(`spoolman.unlinkSuccess`)||e?.message,`success`),I.invalidateQueries({queryKey:[`linked-spools`]}),I.invalidateQueries({queryKey:[`unlinked-spools`]}),I.invalidateQueries({queryKey:[`spoolman-slot-assignments`]})},onError:e=>{R(e.message||F(`spoolman.unlinkFailed`),`error`)}}),rr=q({mutationFn:({amsId:t,temp:n,duration:r,filament:i,rotateTray:a})=>Z.startDrying(e.id,t,n,r,i,a),onSuccess:(t,{amsId:n})=>{Qe(null),Ct({amsId:n}),R(F(`printers.drying.toastCommandSent`),`success`),I.invalidateQueries({queryKey:[`printerStatus`,e.id]})},onError:e=>R(e.message||F(`printers.toast.failedToSendCommand`),`error`)}),ir=q({mutationFn:t=>Z.createScheduledDrying({printer_id:e.id,ams_id:t.amsId,temp:t.temp,duration_hours:t.duration,filament:t.filament,rotate_tray:t.rotateTray,start_after:t.startAfter}),onSuccess:()=>{I.invalidateQueries({queryKey:GW}),Qe(null)},onError:e=>R(e.message||F(`printers.drying.scheduleFailed`),`error`)}),ar=q({mutationFn:t=>Z.stopDrying(e.id,t),onSuccess:()=>{Ct(null),R(F(`printers.drying.toastStopped`),`success`),I.invalidateQueries({queryKey:[`printerStatus`,e.id]})},onError:e=>R(e.message||F(`printers.toast.failedToSendCommand`),`error`)}),sr=q({mutationFn:t=>Z.setAmsFilamentBackup(e.id,t),onSuccess:(t,n)=>{I.invalidateQueries({queryKey:[`printerStatus`,e.id]}),I.invalidateQueries({queryKey:[`printer-status`,e.id]}),R(F(n?`printers.amsBackup.toastEnabled`:`printers.amsBackup.toastDisabled`),`success`)},onError:e=>R(e.message||F(`printers.toast.failedToSendCommand`),`error`)}),cr=q({mutationFn:e=>Pn?Z.controlSmartPlug(Pn.id,e):Promise.reject(`No plug`),onSuccess:()=>{I.invalidateQueries({queryKey:[`smartPlugStatus`,Pn?.id]})}}),lr=q({mutationFn:e=>Pn?Z.updateSmartPlug(Pn.id,{auto_off:e}):Promise.reject(`No plug`),onSuccess:()=>{I.invalidateQueries({queryKey:[`smartPlugByPrinter`,e.id]}),I.invalidateQueries({queryKey:[`smart-plugs`]})}}),ur=q({mutationFn:({id:e,action:t})=>Z.controlSmartPlug(e,t),onSuccess:()=>{R(F(`printers.toast.scriptTriggered`))},onError:e=>R(e.message||F(`printers.toast.failedToRunScript`),`error`)}),dr=q({mutationFn:()=>Z.stopPrint(e.id),onSuccess:()=>{R(F(`printers.toast.printStopped`)),I.invalidateQueries({queryKey:[`printerStatus`,e.id]})},onError:e=>R(e.message||F(`printers.toast.failedToStopPrint`),`error`)}),fr=q({mutationFn:()=>Z.pausePrint(e.id),onSuccess:()=>{R(F(`printers.toast.printPaused`)),I.invalidateQueries({queryKey:[`printerStatus`,e.id]})},onError:e=>R(e.message||F(`printers.toast.failedToPausePrint`),`error`)}),pr=q({mutationFn:()=>Z.resumePrint(e.id),onSuccess:()=>{R(F(`printers.toast.printResumed`)),I.invalidateQueries({queryKey:[`printerStatus`,e.id]})},onError:e=>R(e.message||F(`printers.toast.failedToResumePrint`),`error`)}),mr=q({mutationFn:()=>Z.clearPlate(e.id),onSuccess:()=>{R(F(`queue.clearPlateSuccess`)),I.setQueryData([`printerStatus`,e.id],e=>e&&{...e,awaiting_plate_clear:!1}),I.invalidateQueries({queryKey:[`printerStatus`,e.id]}),I.invalidateQueries({queryKey:[`queue`,e.id]})},onError:e=>R(e.message||F(`printers.toast.failedToSendCommand`),`error`)}),hr=(0,G.jsxs)(`button`,{type:`button`,onClick:()=>mr.mutate(),disabled:mr.isPending||!z(`printers:clear_plate`),className:`mt-2 w-full inline-flex items-center justify-center gap-2 px-3 py-1.5 rounded-lg bg-yellow-100 dark:bg-yellow-500/20 border border-yellow-300 dark:border-yellow-400/40 text-yellow-700 dark:text-yellow-400 hover:bg-yellow-500/30 transition-colors text-xs font-medium disabled:opacity-50`,title:z(`printers:clear_plate`)?F(`printers.plateStatus.markCleared`):F(`printers.permission.noControl`),children:[mr.isPending?(0,G.jsx)(Y,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)] animate-spin`}):(0,G.jsx)(yW,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)]`}),F(`printers.plateStatus.markCleared`)]}),gr=q({mutationFn:({target:t,nozzle:n})=>Z.setNozzleTemperature(e.id,t,n),onSuccess:t=>{Fe(null),R(t.message),I.invalidateQueries({queryKey:[`printerStatus`,e.id]})},onError:e=>R(e.message||F(`printers.toast.failedToSendCommand`),`error`)}),_r=q({mutationFn:t=>Z.setBedTemperature(e.id,t),onSuccess:t=>{Fe(null),R(t.message),I.invalidateQueries({queryKey:[`printerStatus`,e.id]})},onError:e=>R(e.message||F(`printers.toast.failedToSendCommand`),`error`)}),vr=q({mutationFn:t=>Z.setChamberTemperature(e.id,t),onSuccess:t=>{Fe(null),R(t.message),I.invalidateQueries({queryKey:[`printerStatus`,e.id]})},onError:e=>R(e.message||F(`printers.toast.failedToSendCommand`),`error`)}),yr=q({mutationFn:({fan:t,speed:n})=>Z.setFanSpeed(e.id,t,n),onMutate:async({fan:t,speed:n})=>{await I.cancelQueries({queryKey:[`printerStatus`,e.id]});let r=I.getQueryData([`printerStatus`,e.id]),i={part:`cooling_fan_speed`,aux:`big_fan1_speed`,aux2:`left_aux_fan_speed`,chamber:`big_fan2_speed`}[t];return I.setQueryData([`printerStatus`,e.id],e=>e&&{...e,[i]:n}),{previousStatus:r}},onSuccess:t=>{Fe(null),R(t.message),I.invalidateQueries({queryKey:[`printerStatus`,e.id]})},onError:(t,n,r)=>{r?.previousStatus&&I.setQueryData([`printerStatus`,e.id],r.previousStatus),R(t.message||F(`printers.toast.failedToSendCommand`),`error`)}}),br=q({mutationFn:t=>Z.selectExtruder(e.id,t),onMutate:async t=>{await I.cancelQueries({queryKey:[`printerStatus`,e.id]});let n=I.getQueryData([`printerStatus`,e.id]);return I.setQueryData([`printerStatus`,e.id],e=>e&&{...e,active_extruder:t}),{previousStatus:n}},onSuccess:t=>{Fe(null),R(t.message),I.invalidateQueries({queryKey:[`printerStatus`,e.id]})},onError:(t,n,r)=>{r?.previousStatus&&I.setQueryData([`printerStatus`,e.id],r.previousStatus),R(t.message||F(`printers.toast.failedToSendCommand`),`error`)}}),xr=q({mutationFn:t=>Z.setChamberLight(e.id,t),onMutate:async t=>{await I.cancelQueries({queryKey:[`printerStatus`,e.id]});let n=I.getQueryData([`printerStatus`,e.id]);return I.setQueryData([`printerStatus`,e.id],e=>({...e,chamber_light:t})),{previousStatus:n}},onSuccess:(e,t)=>{R(`Chamber light ${t?`on`:`off`}`)},onError:(t,n,r)=>{r?.previousStatus&&I.setQueryData([`printerStatus`,e.id],r.previousStatus),R(t.message||F(`printers.toast.failedToControlChamberLight`),`error`)}}),Sr=q({mutationFn:t=>Z.setPrintSpeed(e.id,t),onMutate:async t=>{await I.cancelQueries({queryKey:[`printerStatus`,e.id]});let n=I.getQueryData([`printerStatus`,e.id]);return I.setQueryData([`printerStatus`,e.id],e=>({...e,speed_level:t})),{previousStatus:n}},onError:(t,n,r)=>{r?.previousStatus&&I.setQueryData([`printerStatus`,e.id],r.previousStatus),R(t.message||F(`printers.toast.failedToSetSpeed`),`error`)}}),Cr=q({mutationFn:t=>Z.setAirductMode(e.id,t),onMutate:async t=>{await I.cancelQueries({queryKey:[`printerStatus`,e.id]});let n=I.getQueryData([`printerStatus`,e.id]);return I.setQueryData([`printerStatus`,e.id],e=>({...e,airduct_mode:t===`cooling`?0:1})),{previousStatus:n}},onError:(t,n,r)=>{r?.previousStatus&&I.setQueryData([`printerStatus`,e.id],r.previousStatus),R(t.message||F(`printers.toast.failedToSendCommand`),`error`)}}),wr=q({mutationFn:({distance:t})=>Z.bedJog(e.id,t),onError:e=>R(e.message||F(`printers.toast.failedToSendCommand`),`error`)}),Tr=q({mutationFn:({x:t,y:n})=>Z.xyJog(e.id,t,n),onError:e=>R(e.message||F(`printers.toast.failedToSendCommand`),`error`)}),Er=q({mutationFn:t=>Z.extruderJog(e.id,t),onError:e=>R(e.message||F(`printers.toast.failedToSendCommand`),`error`)}),Dr=q({mutationFn:t=>Z.homeAxes(e.id,t),onSuccess:()=>{R(F(`printers.bedJog.homingStarted`))},onError:e=>R(e.message||F(`printers.toast.failedToSendCommand`),`error`)}),Or=q({mutationFn:t=>Z.updatePrinter(e.id,{plate_detection_enabled:t}),onSuccess:()=>{I.invalidateQueries({queryKey:[`printers`]}),R(Or.variables?F(`printers.toast.plateCheckEnabled`):F(`printers.toast.plateCheckDisabled`))},onError:e=>R(e.message||F(`printers.toast.failedToUpdateSetting`),`error`)}),kr=q({mutationFn:t=>Z.updatePrinter(e.id,{is_active:t}),onSuccess:(t,n)=>{I.invalidateQueries({queryKey:[`printers`]}),I.invalidateQueries({queryKey:[`printerStatus`,e.id]}),R(F(n?`printers.maintenance.toastExited`:`printers.maintenance.toastEntered`,{name:e.name}),`success`)},onError:e=>R(e.message||F(`printers.toast.failedToUpdateSetting`),`error`)}),[Ar,jr]=(0,y.useState)(!1),Mr=()=>{W?.state===`RUNNING`||W?.state===`PAUSE`?jr(!0):kr.mutate(!1)},Nr=(W?.state===`RUNNING`||W?.state===`PAUSE`)&&(W?.printable_objects_count??0)>=2,{data:Pr}=K({queryKey:[`printableObjects`,e.id],queryFn:()=>Z.getPrintableObjects(e.id),enabled:Be||Nr,refetchInterval:Be?5e3:Nr?3e4:!1}),[Fr,Ir]=(0,y.useState)(null),Lr=(0,y.useRef)(!1),Rr=(0,y.useRef)(null),zr=(0,y.useRef)(!1),Br=q({mutationFn:({amsId:t,slotId:n})=>Z.refreshAmsSlot(e.id,t,n),onMutate:({amsId:e,slotId:t})=>{Rr.current&&clearTimeout(Rr.current),Lr.current=!1,zr.current=!1,Ir({amsId:e,slotId:t}),setTimeout(()=>{zr.current=!0},2e3),Rr.current=setTimeout(()=>{Ir(null)},3e4)},onSuccess:e=>{R(e.message||F(`printers.toast.rfidRereadInitiated`))},onError:e=>{R(e.message||F(`printers.toast.failedToRereadRfid`),`error`),Rr.current&&clearTimeout(Rr.current),Ir(null)}}),Vr=q({mutationFn:({trayId:t})=>Z.loadAmsTray(e.id,t),onSuccess:e=>{R(e.message||F(`printers.toast.loadInitiated`))},onError:e=>{R(e.message||F(`printers.toast.failedToLoad`),`error`)}}),Hr=q({mutationFn:()=>Z.unloadAms(e.id),onSuccess:e=>{R(e.message||F(`printers.toast.unloadInitiated`))},onError:e=>{R(e.message||F(`printers.toast.failedToUnload`),`error`)}}),[Ur,Wr]=(0,y.useState)(null),[Gr,Kr]=(0,y.useState)(null),qr=async()=>{try{Wr(await Z.getPlateReferences(e.id))}catch{}},Jr=()=>{Or.mutate(!e.plate_detection_enabled)},Yr=async()=>{qt(!0),Gt(null);let t=W?.chamber_light===!1;tn(t),t&&(await Z.setChamberLight(e.id,!0),await new Promise(e=>setTimeout(e,2500)));try{Gt(await Z.checkPlateEmpty(e.id,{includeDebugImage:!0})),qr()}catch(n){R(n instanceof Error?n.message:F(`printers.toast.failedToCheckPlate`),`error`),t&&(await Z.setChamberLight(e.id,!1),tn(!1))}finally{qt(!1)}},Xr=(0,y.useCallback)(async()=>{Gt(null),en&&(await Z.setChamberLight(e.id,!1),tn(!1))},[en,e.id]),Zr=async t=>{Yt(!0);try{let n=await Z.calibratePlateDetection(e.id,{label:t});n.success?(R(n.message||F(`printers.toast.calibrationSaved`),`success`),qr(),Gt(await Z.checkPlateEmpty(e.id,{includeDebugImage:!0}))):R(n.message||F(`printers.toast.calibrationFailed`),`error`)}catch(e){R(e instanceof Error?e.message:F(`printers.toast.calibrationFailed`),`error`)}finally{Yt(!1)}},Qr=async(t,n)=>{try{await Z.updatePlateReferenceLabel(e.id,t,n),Kr(null),qr()}catch(e){R(e instanceof Error?e.message:F(`printers.toast.failedToUpdateLabel`),`error`)}},$r=async t=>{try{await Z.deletePlateReference(e.id,t),R(F(`printers.toast.referenceDeleted`),`success`),qr(),Gt(await Z.checkPlateEmpty(e.id,{includeDebugImage:!0}))}catch(e){R(e instanceof Error?e.message:F(`printers.toast.failedToDeleteReference`),`error`)}},ei=async()=>{if(Xt){$t(!0);try{await Z.updatePrinter(e.id,{plate_detection_roi:Xt}),R(F(`printers.toast.detectionAreaSaved`),`success`),Zt(null),Gt(await Z.checkPlateEmpty(e.id,{includeDebugImage:!0}))}catch(e){R(e instanceof Error?e.message:F(`printers.toast.failedToSaveDetectionArea`),`error`)}finally{$t(!1)}}};(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&Wt&&Xr()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[Wt,Xr]);let ti=(0,y.useRef)(null);if((0,y.useEffect)(()=>{if(!Fr)return;let e=W?.ams_status_main??0;return e!==0&&(Lr.current=!0,ti.current&&=(clearTimeout(ti.current),null)),Lr.current&&e===0&&(zr.current?(Rr.current&&clearTimeout(Rr.current),Ir(null)):ti.current||=setTimeout(()=>{Rr.current&&clearTimeout(Rr.current),Ir(null)},2e3)),()=>{ti.current&&clearTimeout(ti.current)}},[W?.ams_status_main,Fr]),(0,y.useEffect)(()=>{if(!B)return;let e=e=>{let t=e.target;Ot.current?.contains(t)||V(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[B]),Qn)return null;let ni=POe(i),ri=()=>{switch(i){case 1:return`w-10 h-10`;case 2:return`w-14 h-14`;case 3:return`w-16 h-16`;case 4:return`w-20 h-20`;default:return`w-14 h-14`}},ii=()=>{switch(i){case 1:return`text-base truncate`;case 2:return`text-lg`;case 3:return`text-xl`;case 4:return`text-2xl`;default:return`text-lg`}},ai=()=>{switch(i){case 1:return`mb-2`;case 2:return`mb-4`;case 3:return`mb-5`;case 4:return`mb-6`;default:return`mb-4`}},oi=z(`library:upload`)&&z(`queue:create`),si=!um(W),ci=e=>{e.preventDefault(),jt.current++,jt.current===1&&Tt(!0)},li=e=>{e.preventDefault(),e.dataTransfer.dropEffect=oi?`copy`:`none`},ui=e=>{e.preventDefault(),jt.current--,jt.current===0&&Tt(!1)},di=async t=>{if(t.preventDefault(),jt.current=0,Tt(!1),!oi)return;let n=Array.from(t.dataTransfer.files)[0];if(!n)return;let r=n.name.toLowerCase();if(!r.endsWith(`.gcode`)&&!r.includes(`.gcode.`)){R(F(`printers.dropNotPrintable`,`Only .gcode and .gcode.3mf files can be printed`),`error`);return}Dt(!0);try{let t=await Z.uploadLibraryFile(n,null),r=t.metadata?.sliced_for_model,i=uG(e.model);if(r&&i&&r.toLowerCase()!==i.toLowerCase()){await Z.deleteLibraryFile(t.id).catch(()=>{}),R(F(`printers.incompatibleFile`,`This file was sliced for {{slicedFor}}, but this printer is a {{printerModel}}`,{slicedFor:r,printerModel:i}),`error`);return}Xe({id:t.id,filename:t.filename})}catch{R(F(`common.uploadFailed`,`Upload failed`),`error`)}finally{Dt(!1)}},fi=t=>{r!==`compact`||w||t.target.closest(`button, a, input, select, textarea, [role="button"]`)||D?.(e.id)},pi=`!h-8 !min-h-8 !w-8 !px-0 !py-0`,mi=t=>{t===`embedded`&&v?v(e.id,e.name):im(e.id)},hi=[{mode:`window`,icon:(0,G.jsx)(ec,{className:`w-4 h-4`}),label:F(`settings.newWindow`),title:F(`settings.cameraWindowDescription`)},{mode:`embedded`,icon:(0,G.jsx)(Ol,{className:`w-4 h-4`}),label:F(`settings.embeddedOverlay`),title:F(`settings.cameraOverlayDescription`)}].map(({mode:e,icon:t,label:n,title:r})=>({icon:t,label:e===_?`${n} ✓`:n,title:r,onClick:()=>{b?.(e),mi(e)}})),gi=({amsId:e,slotId:t,loadTrayId:n,isRefreshing:r,includeRfid:i=!0})=>{let a=W?.state===`RUNNING`;return(0,G.jsxs)(G.Fragment,{children:[i&&(0,G.jsxs)(`button`,{className:`w-full px-2 py-1.5 text-left text-xs flex items-center gap-2 rounded transition-colors ${z(`printers:ams_rfid`)?`text-white hover:bg-bambu-dark-tertiary`:`text-bambu-gray/50 cursor-not-allowed`}`,onClick:n=>{n.stopPropagation(),!(a||!z(`printers:ams_rfid`))&&Br.mutate({amsId:e,slotId:t})},disabled:a||r||!z(`printers:ams_rfid`),title:a?F(`printers.bedJog.disabledWhilePrinting`):z(`printers:ams_rfid`)?void 0:F(`printers.permission.noAmsRfid`),children:[(0,G.jsx)(Rl,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)] ${r?`animate-spin`:``}`}),F(`printers.rfid.reread`)]}),(0,G.jsxs)(`button`,{className:`w-full px-2 py-1.5 text-left text-xs flex items-center gap-2 rounded transition-colors ${z(`printers:control`)?`text-white hover:bg-bambu-dark-tertiary`:`text-bambu-gray/50 cursor-not-allowed`}`,onClick:e=>{e.stopPropagation(),!(a||!z(`printers:control`))&&Vr.mutate({trayId:n})},disabled:a||!z(`printers:control`),title:a?F(`printers.bedJog.disabledWhilePrinting`):z(`printers:control`)?void 0:F(`printers.permission.noControl`),children:[(0,G.jsx)($c,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)]`}),F(`printers.ams.load`)]}),(0,G.jsxs)(`button`,{className:`w-full px-2 py-1.5 text-left text-xs flex items-center gap-2 rounded transition-colors ${z(`printers:control`)?`text-white hover:bg-bambu-dark-tertiary`:`text-bambu-gray/50 cursor-not-allowed`}`,onClick:e=>{e.stopPropagation(),!(a||!z(`printers:control`))&&Hr.mutate()},disabled:a||!z(`printers:control`),title:a?F(`printers.bedJog.disabledWhilePrinting`):z(`printers:control`)?void 0:F(`printers.permission.noControl`),children:[(0,G.jsx)(el,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)]`}),F(`printers.ams.unload`)]})]})},_i=(0,G.jsxs)(`div`,{ref:Ot,className:`relative flex-shrink-0`,children:[(0,G.jsx)(Q,{variant:`secondary`,size:`sm`,onClick:()=>V(!B),title:F(`common.more`,`More`),className:pi,children:(0,G.jsx)(Xs,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)]`})}),B&&(0,G.jsxs)(`div`,{className:`absolute left-0 bottom-full mb-2 w-48 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg z-20`,children:[(0,G.jsxs)(`button`,{className:`w-full px-4 py-2 text-left text-sm flex items-center gap-2 ${z(`printers:update`)?`hover:bg-bambu-dark-tertiary`:`opacity-50 cursor-not-allowed`}`,onClick:()=>{z(`printers:update`)&&(ae(!0),V(!1))},title:z(`printers:update`)?void 0:F(`printers.permission.noEdit`),children:[(0,G.jsx)(El,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)]`}),F(`common.edit`)]}),(0,G.jsxs)(`button`,{className:`w-full px-4 py-2 text-left text-sm hover:bg-bambu-dark-tertiary flex items-center gap-2`,onClick:()=>{Ge(!0),V(!1)},children:[(0,G.jsx)(zc,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)]`}),F(`printers.printerInformation`)]}),(0,G.jsxs)(`button`,{className:`w-full px-4 py-2 text-left text-sm flex items-center gap-2 ${z(`printers:update`)?`hover:bg-bambu-dark-tertiary`:`opacity-50 cursor-not-allowed`}`,disabled:kr.isPending||!z(`printers:update`),onClick:()=>{z(`printers:update`)&&(V(!1),e.is_active===!1?kr.mutate(!0):Mr())},title:z(`printers:update`)?void 0:F(`printers.permission.noEdit`),children:[(0,G.jsx)(Zu,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)]`}),e.is_active===!1?F(`printers.maintenance.menuExit`):F(`printers.maintenance.menuEnter`)]}),(0,G.jsxs)(`button`,{className:`w-full px-4 py-2 text-left text-sm hover:bg-bambu-dark-tertiary flex items-center gap-2`,onClick:()=>{er.mutate(),V(!1)},children:[(0,G.jsx)(Rl,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)]`}),F(`printers.reconnect`)]}),(0,G.jsxs)(`button`,{className:`w-full px-4 py-2 text-left text-sm hover:bg-bambu-dark-tertiary flex items-center gap-2 disabled:opacity-50`,disabled:tr.isPending,onClick:()=>{tr.mutate(),V(!1)},children:[(0,G.jsx)(Vl,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)] ${tr.isPending?`animate-spin`:``}`}),F(`printers.forceRefresh`)]}),(0,G.jsxs)(`button`,{className:`w-full px-4 py-2 text-left text-sm hover:bg-bambu-dark-tertiary flex items-center gap-2`,onClick:()=>{ce(!0),V(!1)},children:[(0,G.jsx)(wu,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)]`}),F(`printers.mqttDebug`)]}),(0,G.jsxs)(`button`,{className:`w-full px-4 py-2 text-left text-sm hover:bg-bambu-dark-tertiary flex items-center gap-2`,onClick:()=>{qe(!0),V(!1)},children:[(0,G.jsx)(vu,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)]`}),F(`diagnostic.runButton`)]}),(0,G.jsxs)(`button`,{className:`w-full px-4 py-2 text-left text-sm flex items-center gap-2 ${z(`printers:delete`)?`text-red-700 dark:text-red-400 hover:bg-bambu-dark-tertiary`:`text-red-700/50 dark:text-red-400/50 cursor-not-allowed`}`,onClick:()=>{z(`printers:delete`)&&(te(!0),V(!1))},title:z(`printers:delete`)?void 0:F(`printers.permission.noDelete`),children:[(0,G.jsx)(Au,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)]`}),F(`common.delete`)]})]})]});return(0,G.jsxs)(jd,{id:`printer-card-${e.id}`,className:`relative flex h-full flex-col ${T?`ring-2 ring-bambu-green`:``} ${w||r===`compact`?`cursor-pointer`:``}`,style:ni,onClick:fi,onDragEnter:ci,onDragOver:li,onDragLeave:ui,onDrop:di,children:[w&&(0,G.jsx)(`div`,{className:`absolute inset-0 z-20 flex items-start p-2`,onClick:t=>{t.stopPropagation(),E?.(e.id)},children:T?(0,G.jsx)(mu,{className:`w-[var(--pc-i5,1.25rem)] h-[var(--pc-i5,1.25rem)] text-bambu-green`}):(0,G.jsx)(gu,{className:`w-[var(--pc-i5,1.25rem)] h-[var(--pc-i5,1.25rem)] text-bambu-gray`})}),(wt||Et)&&(0,G.jsx)(`div`,{className:`absolute inset-0 z-10 rounded-xl border-2 border-dashed flex items-center justify-center transition-colors ${Et?`bg-bambu-green/10 border-bambu-green/50`:oi?`bg-bambu-green/10 border-bambu-green`:`bg-red-50 dark:bg-red-500/10 border-red-300 dark:border-red-500/50`}`,children:(0,G.jsx)(`div`,{className:`text-center`,children:Et?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-8 h-8 mx-auto mb-2 text-bambu-green animate-spin`}),(0,G.jsx)(`p`,{className:`text-sm font-medium text-bambu-green`,children:F(`common.uploading`,`Uploading...`)})]}):oi?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Pl,{className:`w-8 h-8 mx-auto mb-2 text-bambu-green`}),(0,G.jsx)(`p`,{className:`text-sm font-medium text-bambu-green`,children:F(si?`printers.dropToQueue`:`printers.dropToPrint`)})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Qu,{className:`w-8 h-8 mx-auto mb-2 text-red-600 dark:text-red-400`}),(0,G.jsx)(`p`,{className:`text-sm font-medium text-red-700 dark:text-red-400`,children:z(`library:upload`)?F(`fileManager.noPermissionAddToQueue`):F(`fileManager.noPermissionUpload`)})]})})}),(0,G.jsxs)(Nd,{className:`${i>=3?`p-5`:``} flex flex-1 flex-col`,children:[(0,G.jsxs)(`div`,{className:ai(),children:[(0,G.jsx)(`div`,{className:`flex items-start justify-between gap-2`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 flex-1`,children:[(0,G.jsx)(`img`,{src:sm(e.model),alt:e.model||F(`common.printer`),className:`object-contain rounded-lg flex-shrink-0 ${ri()}`}),(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,G.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,G.jsx)(`h3`,{className:`font-semibold text-white ${ii()}`,children:e.name}),r===`compact`&&(()=>{let e=W?.connected&&W.hms_errors?xm(W.hms_errors):[],t=e.some(e=>e.severity<=2),n=e.length>0,r=W?.connected?t?`bg-status-error`:n?`bg-status-warning`:`bg-status-ok`:`bg-status-error`,i=W?.connected?n?`${e.length} HMS ${e.length===1?`error`:`errors`}`:F(`printers.connection.connected`):F(`printers.connection.offline`);return(0,G.jsx)(`div`,{className:`w-[var(--pc-i2,0.5rem)] h-[var(--pc-i2,0.5rem)] rounded-full flex-shrink-0 ${r}`,title:i})})()]}),r===`compact`&&Kn&&(0,G.jsx)(`button`,{type:`button`,onClick:()=>mr.mutate(),disabled:mr.isPending||!z(`printers:clear_plate`),"aria-label":F(`printers.plateStatus.markCleared`),className:`inline-flex h-5 w-5 flex-shrink-0 items-center justify-center rounded-md bg-yellow-100 dark:bg-yellow-500/20 border border-yellow-300 dark:border-yellow-400/40 text-yellow-700 dark:text-yellow-400 hover:bg-yellow-500/30 transition-colors disabled:opacity-50`,title:z(`printers:clear_plate`)?F(`printers.plateStatus.markCleared`):F(`printers.permission.noControl`),children:mr.isPending?(0,G.jsx)(Y,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)] animate-spin`}):(0,G.jsx)(yW,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)]`})})]}),(0,G.jsxs)(`p`,{className:`text-sm text-bambu-gray`,children:[e.model||`Unknown Model`,r===`expanded`&&W?.nozzles&&W.nozzles[0]?.nozzle_diameter&&(0,G.jsxs)(`span`,{className:`ml-1.5 text-bambu-gray`,title:W.nozzles[0].nozzle_type||`Nozzle`,children:[`• `,W.nozzles[0].nozzle_diameter,`mm`]}),r===`expanded`&&n&&n.total_print_hours>0&&(0,G.jsxs)(`span`,{className:`ml-2 text-bambu-gray`,children:[(0,G.jsx)(ks,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)] inline-block mr-1`}),Math.round(n.total_print_hours),`h`]})]})]})]})}),r===`expanded`&&(0,G.jsx)(`div`,{className:`mt-2`,children:(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[e.is_active===!1?(0,G.jsxs)(`span`,{className:`flex items-center gap-1.5 px-2 py-1 rounded-full text-xs bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-400`,title:F(`printers.maintenance.subtitle`),children:[(0,G.jsx)(Zu,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)]`}),F(`printers.maintenance.pillLabel`)]}):(0,G.jsxs)(`span`,{className:`flex items-center gap-1.5 px-2 py-1 rounded-full text-xs ${W?.connected?`bg-status-ok/20 text-status-ok`:`bg-status-error/20 text-status-error`}`,children:[W?.connected?(0,G.jsx)(qc,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)]`}):(0,G.jsx)(Iu,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)]`}),W?.connected?F(`printers.connection.connected`):F(`printers.connection.offline`)]}),e.is_active!==!1&&!W?.connected&&(0,G.jsxs)(`button`,{onClick:()=>qe(!0),className:`flex items-center gap-1 px-2 py-1 rounded-full text-xs cursor-pointer bg-bambu-dark-tertiary text-bambu-gray hover:text-white transition-colors`,title:F(`diagnostic.runButton`),children:[(0,G.jsx)(vu,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)]`}),F(`diagnostic.runButton`)]}),W?.connected&&W?.wired_network&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1 px-2 py-1 rounded-full text-xs bg-status-ok/20 text-status-ok`,title:F(`printers.connection.ethernet`,`Ethernet`),children:[(0,G.jsx)($o,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)]`}),F(`printers.connection.ethernet`,`Ethernet`)]}),W?.connected&&!W?.wired_network&&_n!=null&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1 px-2 py-1 rounded-full text-xs ${_n>=-50||_n>=-60?`bg-status-ok/20 text-status-ok`:_n>=-70?`bg-status-warning/20 text-status-warning`:_n>=-80?`bg-orange-500/20 text-orange-600`:`bg-status-error/20 text-status-error`}`,title:`WiFi: ${_n} dBm - ${F(lm(_n).labelKey)}`,children:[(0,G.jsx)(au,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)]`}),_n,`dBm`]}),W?.connected&&(()=>{let e=W.hms_errors?xm(W.hms_errors):[];return(0,G.jsxs)(`button`,{onClick:()=>ge(!0),className:`flex items-center gap-1 px-2 py-1 rounded-full text-xs cursor-pointer hover:opacity-80 transition-opacity ${e.length>0?e.some(e=>e.severity<=2)?`bg-status-error/20 text-status-error`:`bg-status-warning/20 text-status-warning`:`bg-status-ok/20 text-status-ok`}`,title:F(`printers.clickToViewHmsErrors`),children:[(0,G.jsx)(Nu,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)]`}),e.length>0?e.length:`OK`]})})(),M&&(()=>{let e=N?N.class===`failure`||N.class===`warning`?N.class:`safe`:`idle`;return(0,G.jsxs)(`button`,{onClick:()=>ve(!0),className:`flex items-center gap-1 px-2 py-1 rounded-full text-xs cursor-pointer hover:opacity-80 transition-opacity ${e===`failure`?`bg-status-error/20 text-status-error`:e===`warning`?`bg-status-warning/20 text-status-warning`:e===`safe`?`bg-status-ok/20 text-status-ok`:`bg-bambu-dark-tertiary text-bambu-gray`}`,title:N?F(`printers.aiDetection.tooltip`,{status:F(`printers.aiDetection.${e}`),score:N.score.toFixed(3)}):F(`printers.aiDetection.tooltipIdle`),children:[(0,G.jsx)(Gl,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)]`}),F(`printers.aiDetection.${e}`)]})})(),n&&(0,G.jsxs)(`button`,{onClick:()=>L(`/maintenance`),className:`flex items-center gap-1 px-2 py-1 rounded-full text-xs cursor-pointer hover:opacity-80 transition-opacity ${n.due_count>0?`bg-status-error/20 text-status-error`:n.warning_count>0?`bg-status-warning/20 text-status-warning`:`bg-status-ok/20 text-status-ok`}`,title:n.due_count>0||n.warning_count>0?`${n.due_count>0?`${n.due_count} maintenance due`:``}${n.due_count>0&&n.warning_count>0?`, `:``}${n.warning_count>0?`${n.warning_count} due soon`:``} - Click to view`:F(`printers.maintenanceUpToDate`),children:[(0,G.jsx)(Zu,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)]`}),n.due_count>0||n.warning_count>0?n.due_count+n.warning_count:`OK`]}),Rn>0&&(0,G.jsxs)(`button`,{onClick:()=>L(`/queue`),className:`flex items-center gap-1 px-2 py-1 rounded-full text-xs bg-indigo-100 dark:bg-indigo-500/20 text-indigo-700 dark:text-indigo-400 hover:opacity-80 transition-opacity`,title:F(`printers.queue.inQueue`,{count:Rn}),children:[(0,G.jsx)(Uc,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)]`}),Rn]}),x&&nn?.current_version&&nn?.latest_version?(0,G.jsxs)(`button`,{onClick:()=>Ut(!0),className:`flex items-center gap-1 px-2 py-1 rounded-full text-xs hover:opacity-80 transition-opacity ${nn.update_available?`bg-orange-100 dark:bg-orange-500/20 text-orange-700 dark:text-orange-400`:`bg-status-ok/20 text-status-ok`}`,title:nn.update_available?F(`printers.firmwareUpdateAvailable`,{current:nn.current_version,latest:nn.latest_version}):F(`printers.firmwareUpToDate`,{version:nn.current_version}),children:[nn.update_available?(0,G.jsx)(qs,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)]`}):(0,G.jsx)(ys,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)]`}),nn.current_version]}):W?.firmware_version?(0,G.jsx)(`span`,{className:`flex items-center gap-1 px-2 py-1 rounded-full text-xs bg-bambu-dark-tertiary/50 text-bambu-gray`,children:W.firmware_version}):null,W?.connected&&[`X1C`,`X1`,`X1E`,`X2D`,`P2S`,`H2D`,`H2D Pro`,`H2C`,`H2S`].includes(e.model??``)&&(0,G.jsx)(`span`,{className:`flex items-center px-2 py-1 rounded-full text-xs ${W.door_open?`bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400`:`bg-status-ok/20 text-status-ok`}`,title:W.door_open?F(`printers.door.open`):F(`printers.door.closed`),children:W.door_open?(0,G.jsx)(Ks,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)]`}):(0,G.jsx)(Gs,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)]`})})]})})]}),ee&&(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50`,children:(0,G.jsx)(jd,{className:`w-full max-w-md mx-4`,children:(0,G.jsxs)(Nd,{children:[(0,G.jsxs)(`div`,{className:`flex items-start gap-3 mb-4`,children:[(0,G.jsx)(`div`,{className:`p-2 rounded-full bg-red-100 dark:bg-red-500/20`,children:(0,G.jsx)(Nu,{className:`w-[var(--pc-i5,1.25rem)] h-[var(--pc-i5,1.25rem)] text-red-600 dark:text-red-400`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`text-lg font-semibold text-white`,children:F(`printers.confirm.deleteTitle`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:F(`printers.confirm.deleteMessage`,{name:e.name})})]})]}),(0,G.jsx)(`div`,{className:`bg-bambu-dark rounded-lg p-3 mb-4`,children:(0,G.jsxs)(`label`,{className:`flex items-start gap-3 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:ne,onChange:e=>re(e.target.checked),className:`mt-0.5 w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)] rounded border-bambu-gray bg-bambu-dark-secondary text-bambu-green focus:ring-bambu-green focus:ring-offset-0`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-sm text-white`,children:F(`printers.deleteArchives`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:F(ne?`printers.confirm.deleteArchivesNote`:`printers.confirm.keepArchivesNote`)})]})]})}),(0,G.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>{te(!1),re(!0)},children:F(`common.cancel`)}),(0,G.jsx)(Q,{variant:`danger`,onClick:()=>{$n.mutate({deleteArchives:ne}),te(!1),re(!0)},children:`Delete`})]})]})})}),e.is_active===!1?(0,G.jsx)(G.Fragment,{children:r===`compact`?(0,G.jsxs)(`div`,{className:`mt-2 flex items-center gap-2 px-2 py-1.5 rounded-full bg-amber-50 dark:bg-amber-500/15 border border-amber-300 dark:border-amber-500/30`,children:[(0,G.jsx)(Zu,{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-[length:var(--pc-t11,11px)] text-amber-700 dark:text-amber-400 font-medium truncate`,children:F(`printers.maintenance.pillLabel`)})]}):(0,G.jsxs)(G.Fragment,{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.status.title`,`Status`)}),(0,G.jsx)(`div`,{className:`flex-1 h-[2px] bg-bambu-dark-tertiary`})]}),(0,G.jsxs)(`div`,{className:`p-3 bg-amber-50 dark:bg-amber-500/10 border border-amber-300 dark:border-amber-500/30 rounded-[10px] flex items-center gap-3`,children:[(0,G.jsx)(Zu,{className:`w-6 h-6 text-amber-600 dark:text-amber-400 shrink-0`}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`p`,{className:`text-sm text-amber-700 dark:text-amber-400 font-medium`,children:F(`printers.maintenance.title`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:F(`printers.maintenance.subtitle`)})]}),(0,G.jsx)(Q,{variant:`secondary`,size:`sm`,disabled:kr.isPending||!z(`printers:update`),onClick:()=>kr.mutate(!0),title:z(`printers:update`)?void 0:F(`printers.permission.noEdit`),children:F(`printers.maintenance.exitButton`)})]})]})}):W?.connected&&(0,G.jsxs)(G.Fragment,{children:[r===`compact`?(()=>{let e=W.hms_errors?xm(W.hms_errors):[],t=W.state===`FAILED`||e.length>0,n=W.state===`RUNNING`||W.state===`PAUSE`?Math.max(0,Math.min(100,W.progress||0)):Kn||t?100:0,r=W.state===`RUNNING`||W.state===`PAUSE`,i=t?`bg-status-error`:W.state===`PAUSE`?`bg-status-warning`:`bg-bambu-green`,a=r&&W.remaining_time!=null&&W.remaining_time>0,o=r&&W.layer_num!=null&&W.total_layers!=null&&W.total_layers>0;return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`relative mt-2 flex items-center gap-2`,children:[(0,G.jsx)(`div`,{className:`h-1.5 min-w-0 flex-1 overflow-hidden rounded-full bg-bambu-dark-tertiary`,children:(0,G.jsx)(`div`,{className:`${i} h-1.5 rounded-full transition-all`,style:{width:`${n}%`}})}),(0,G.jsx)(`span`,{className:`w-9 shrink-0 text-right text-[length:var(--pc-t11,11px)] leading-none ${r?`text-white`:`text-bambu-gray`}`,children:r?`${Math.round(n)}%`:`---%`})]}),(0,G.jsxs)(`div`,{className:`mt-1 flex min-h-[14px] items-center gap-2 overflow-hidden text-[length:var(--pc-t11,11px)] leading-none text-bambu-gray`,children:[a&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`span`,{className:`flex shrink-0 items-center gap-1`,children:[(0,G.jsx)(ks,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)]`}),Yf(W.remaining_time*60)]}),(0,G.jsxs)(`span`,{className:`shrink-0 font-medium text-bambu-green`,title:F(`printers.estimatedCompletion`),children:[`ETA `,Jf(W.remaining_time,g,F)]})]}),o&&(0,G.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1 truncate`,children:[(0,G.jsx)(Uc,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)] shrink-0`}),W.layer_num,`/`,W.total_layers]})]})]})})():(0,G.jsxs)(G.Fragment,{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.status.title`,`Status`)}),(0,G.jsx)(`div`,{className:`flex-1 h-[2px] bg-bambu-dark-tertiary`})]}),(()=>{let t=!!(W.current_print&&(W.state===`RUNNING`||W.state===`PAUSE`)),n=!t&&Gn&&Jn,r=t?qn:n?Jn.name:null,i=t?W.cover_url:n?Jn.coverUrl:null,a=t?W.progress||0:n?100:0;return(0,G.jsxs)(`div`,{className:`p-2 bg-bambu-dark rounded-[10px] relative overflow-hidden`,children:[(0,G.jsxs)(`button`,{onClick:()=>Ve(!0),disabled:!t||(W.printable_objects_count??0)<2||!z(`printers:control`),className:`absolute top-2 right-2 p-1.5 rounded transition-colors z-10 ${t&&(W.printable_objects_count??0)>=2&&z(`printers:control`)?`text-bambu-gray hover:text-white hover:bg-white/10`:`text-bambu-gray/30 cursor-not-allowed`}`,title:z(`printers:control`)?t?(W.printable_objects_count??0)>=2?F(`printers.skipObjects.tooltip`):F(`printers.skipObjects.requiresMultiple`):F(`printers.skipObjects.onlyWhilePrinting`):F(`printers.permission.noControl`),children:[(0,G.jsx)(bT,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)]`}),Pr&&Pr.skipped_count>0&&(0,G.jsx)(`span`,{className:`absolute -top-1 -right-1 min-w-[16px] h-4 px-1 flex items-center justify-center text-[length:var(--pc-t10,10px)] font-bold bg-red-500 text-white rounded-full`,children:Pr.skipped_count})]}),(0,G.jsxs)(`div`,{className:`flex items-stretch gap-2`,children:[(0,G.jsx)(DOe,{url:i,printName:r||void 0,className:`w-24 h-24 max-[520px]:w-20 max-[520px]:h-20`}),(0,G.jsxs)(`div`,{className:`flex h-24 max-[520px]:h-20 min-w-0 flex-1 flex-col justify-between pt-1`,children:[(0,G.jsxs)(`div`,{className:`flex min-h-[18px] items-center gap-2 pr-8`,children:[(0,G.jsx)(`p`,{className:`min-w-0 truncate text-sm text-bambu-gray`,children:jOe(W.state,W.stg_cur_name)}),Zn]}),(0,G.jsx)(`p`,{className:`min-h-[18px] truncate pr-8 text-sm ${r?`text-white`:`text-bambu-gray/70`}`,children:r||F(`printers.noActiveJob`,`No active job`)}),(0,G.jsxs)(`div`,{className:`flex h-3 items-center gap-2 text-sm`,children:[(0,G.jsx)(`div`,{className:`h-1.5 min-w-0 flex-1 rounded-full bg-bambu-dark-tertiary`,children:(0,G.jsx)(`div`,{className:`${t?W.state===`PAUSE`?`bg-status-warning`:`bg-bambu-green`:n?`bg-bambu-green`:`bg-bambu-dark-tertiary`} h-1.5 rounded-full transition-all`,style:{width:`${a}%`}})}),(0,G.jsx)(`span`,{className:`w-9 shrink-0 pr-1 text-right text-[length:var(--pc-t11,11px)] leading-none ${t||n?`text-white`:`text-bambu-gray`}`,children:t||n?`${Math.round(a)}%`:`---%`})]}),(0,G.jsx)(`div`,{className:`flex min-h-[16px] items-center gap-2 text-xs text-bambu-gray`,children:t?(0,G.jsxs)(G.Fragment,{children:[W.remaining_time!=null&&W.remaining_time>0&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(ks,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)]`}),Yf(W.remaining_time*60)]}),(0,G.jsxs)(`span`,{className:`text-bambu-green font-medium`,title:F(`printers.estimatedCompletion`),children:[`ETA `,Jf(W.remaining_time,g,F)]})]}),W.layer_num!=null&&W.total_layers!=null&&W.total_layers>0&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(Uc,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)]`}),W.layer_num,`/`,W.total_layers]}),Vn&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1`,title:`Started by ${Vn}`,children:[(0,G.jsx)(Ru,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)]`}),Vn]})]}):Un?(0,G.jsxs)(`p`,{className:`truncate`,title:Un.print_name||Un.filename,children:[`Last: `,Un.print_name||Un.filename,Un.completed_at&&(0,G.jsxs)(`span`,{className:`ml-1 text-bambu-gray/60`,children:[`• `,Gf(Un.completed_at,{month:`short`,day:`numeric`})]})]}):(0,G.jsx)(`span`,{children:F(`printers.readyToPrint`)})})]})]}),(0,G.jsx)(Kse,{printerId:e.id,printerModel:e.model,loadedFilamentTypes:an,loadedFilaments:on,loadedVariants:sn,variant:`panelExtension`})]})})()]}),W.temperatures&&r===`expanded`&&(()=>{let t=W.temperatures.nozzle_heating||W.temperatures.nozzle_2_heating||!1,n=W.temperatures.bed_heating||!1,r=W.temperatures.chamber_heating||!1,i=e.nozzle_count===2||W.temperatures.nozzle_2!==void 0,a=(()=>{let e=[`nozzle`];return W.temperatures.nozzle_2!==void 0&&e.push(`nozzle_2`),e.push(`bed`),W.temperatures.chamber!==void 0&&e.push(`chamber`),e})(),o=W.active_extruder===1?`L`:`R`,s=W.nozzle_rack?.find(e=>e.id===1),c=W.nozzle_rack?.find(e=>e.id===0),l=c||s,u=W.connected&&z(`printers:control`),d=u?void 0:F(`printers.permission.noControl`),f=`relative text-center px-2 py-1.5 bg-bambu-dark rounded-lg flex-1 flex flex-col justify-center items-center transition-colors ${u?`cursor-pointer hover:bg-bambu-dark-tertiary`:`cursor-default opacity-80`}`,p=MOe.has(e.model??``),m=NOe.has(e.model??``),h=F(m?`printers.fans.exhaust`:`printers.fans.chamber`),g=p&&(!m||W.exhaust_fan_present),_=[{key:`part`,label:F(`printers.fans.partCooling`),value:W.cooling_fan_speed??0,Icon:rc,activeClass:`text-cyan-600 dark:text-cyan-400`},...W.left_aux_fan_speed==null?[]:[{key:`aux2`,label:F(`printers.fans.leftAuxiliary`),value:W.left_aux_fan_speed,Icon:Yu,activeClass:`text-indigo-600 dark:text-indigo-400`}],{key:`aux`,label:F(`printers.fans.auxiliary`),value:W.big_fan1_speed??0,Icon:Yu,activeClass:`text-blue-600 dark:text-blue-400`},...g?[{key:`chamber`,label:h,value:W.big_fan2_speed??0,Icon:Mo,activeClass:`text-green-600 dark:text-green-400`}]:[]];return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`mt-2 flex items-stretch gap-1.5 flex-wrap`,children:[(0,G.jsxs)(`div`,{className:f,title:d,onClick:()=>u&&Fe(Pe===`nozzle-temp`?null:`nozzle-temp`),children:[(0,G.jsx)(`button`,{type:`button`,className:`absolute top-0.5 right-0.5 p-0.5 rounded text-bambu-gray hover:text-white hover:bg-white/10 transition-colors`,title:F(`printers.heaterHistory.openLabel`,`View heater history`),onClick:e=>{e.stopPropagation(),Ft({initialKind:`nozzle`,availableKinds:a})},children:(0,G.jsx)(ss,{className:`w-[var(--pc-i25,0.625rem)] h-[var(--pc-i25,0.625rem)]`})}),(0,G.jsx)(eG,{className:`w-[var(--pc-i35,0.875rem)] h-[var(--pc-i35,0.875rem)] mb-0.5`,color:`text-orange-400`,isHeating:t}),W.temperatures.nozzle_2===void 0?l?(0,G.jsx)($W,{slot:l,index:0,activeStatus:!0,filamentName:l.filament_id?cn?.[l.filament_id]?.name:void 0,children:(0,G.jsxs)(`div`,{className:`cursor-default`,children:[(0,G.jsx)(`p`,{className:`text-[length:var(--pc-t9,9px)] text-bambu-gray`,children:F(`printers.temperatures.nozzle`)}),(0,G.jsxs)(`p`,{className:`text-[length:var(--pc-t11,11px)] text-white`,children:[Math.round(W.temperatures.nozzle||0),`°C`]})]})}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`p`,{className:`text-[length:var(--pc-t9,9px)] text-bambu-gray`,children:F(`printers.temperatures.nozzle`)}),(0,G.jsxs)(`p`,{className:`text-[length:var(--pc-t11,11px)] text-white`,children:[Math.round(W.temperatures.nozzle||0),`°C`]})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`p`,{className:`text-[length:var(--pc-t9,9px)] text-bambu-gray`,children:`L / R`}),(0,G.jsxs)(`p`,{className:`text-[length:var(--pc-t11,11px)] text-white`,children:[Math.round(W.temperatures.nozzle||0),`° / `,Math.round(W.temperatures.nozzle_2||0),`°`]})]}),Pe===`nozzle-temp`&&(i?(0,G.jsx)(oG,{title:`Set Nozzle Temperatures`,widthClass:`w-[300px]`,popoverWidth:300,popoverHeight:260,isPending:gr.isPending,onClose:()=>Fe(null),children:(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-2 px-3 py-2.5`,children:[(0,G.jsx)(sG,{label:`Left Temp`,current:W.temperatures.nozzle,target:W.temperatures.nozzle_target,isActive:o===`L`,isPending:gr.isPending,onSubmit:e=>gr.mutate({target:e,nozzle:1}),options:_m(O,`C`)}),(0,G.jsx)(sG,{label:`Right Temp`,current:W.temperatures.nozzle_2,target:W.temperatures.nozzle_2_target,isActive:o===`R`,isPending:gr.isPending,onSubmit:e=>gr.mutate({target:e,nozzle:0}),options:_m(O,`C`)})]})}):(0,G.jsx)(oG,{title:`Set Nozzle Temperature`,unit:`°C`,customMin:0,customMax:320,isPending:gr.isPending,options:_m(O,`C`),onClose:()=>Fe(null),onSubmit:e=>gr.mutate({target:e,nozzle:W.active_extruder??0})}))]}),(0,G.jsxs)(`div`,{className:f,title:d,onClick:()=>u&&Fe(Pe===`bed-temp`?null:`bed-temp`),children:[(0,G.jsx)(`button`,{type:`button`,className:`absolute top-0.5 right-0.5 p-0.5 rounded text-bambu-gray hover:text-white hover:bg-white/10 transition-colors`,title:F(`printers.heaterHistory.openLabel`,`View heater history`),onClick:e=>{e.stopPropagation(),Ft({initialKind:`bed`,availableKinds:a})},children:(0,G.jsx)(ss,{className:`w-[var(--pc-i25,0.625rem)] h-[var(--pc-i25,0.625rem)]`})}),(0,G.jsx)(eG,{className:`w-[var(--pc-i35,0.875rem)] h-[var(--pc-i35,0.875rem)] mb-0.5`,color:`text-blue-400`,isHeating:n}),(0,G.jsx)(`p`,{className:`text-[length:var(--pc-t9,9px)] text-bambu-gray`,children:F(`printers.temperatures.bed`)}),(0,G.jsxs)(`p`,{className:`text-[length:var(--pc-t11,11px)] text-white`,children:[Math.round(W.temperatures.bed||0),`°C`]}),Pe===`bed-temp`&&(0,G.jsx)(oG,{title:`Set Bed Temperature`,unit:`°C`,customMin:0,customMax:140,isPending:_r.isPending,options:_m(k,`C`),onClose:()=>Fe(null),onSubmit:e=>_r.mutate(e)})]}),W.temperatures.chamber!==void 0&&(()=>{let e=W.supports_chamber_heater===!0;return(0,G.jsxs)(`div`,{className:e?f:`relative text-center px-2 py-1.5 bg-bambu-dark rounded-lg flex-1 flex flex-col justify-center items-center`,title:e?d:void 0,onClick:e?()=>u&&Fe(Pe===`chamber-temp`?null:`chamber-temp`):void 0,children:[(0,G.jsx)(`button`,{type:`button`,className:`absolute top-0.5 right-0.5 p-0.5 rounded text-bambu-gray hover:text-white hover:bg-white/10 transition-colors`,title:F(`printers.heaterHistory.openLabel`,`View heater history`),onClick:e=>{e.stopPropagation(),Ft({initialKind:`chamber`,availableKinds:a})},children:(0,G.jsx)(ss,{className:`w-[var(--pc-i25,0.625rem)] h-[var(--pc-i25,0.625rem)]`})}),(0,G.jsx)(eG,{className:`w-[var(--pc-i35,0.875rem)] h-[var(--pc-i35,0.875rem)] mb-0.5`,color:`text-green-400`,isHeating:r}),(0,G.jsx)(`p`,{className:`text-[length:var(--pc-t9,9px)] text-bambu-gray`,children:F(`printers.temperatures.chamber`)}),(0,G.jsxs)(`p`,{className:`text-[length:var(--pc-t11,11px)] text-white`,children:[Math.round(W.temperatures.chamber||0),`°C`]}),e&&Pe===`chamber-temp`&&(0,G.jsx)(oG,{title:`Set Chamber Temperature`,unit:`°C`,customMin:0,customMax:65,isPending:vr.isPending,options:_m(A,`C`),onClose:()=>Fe(null),onSubmit:e=>vr.mutate(e)})]})})(),i&&(0,G.jsx)(hOe,{leftSlot:s,rightSlot:c,activeNozzle:o,filamentInfo:cn,children:(0,G.jsxs)(`div`,{className:`relative text-center px-3 py-1.5 bg-bambu-dark rounded-lg h-full flex flex-col justify-center items-center transition-colors ${u?`cursor-pointer hover:bg-bambu-dark-tertiary`:`cursor-default opacity-80`}`,title:u?F(`printers.activeNozzle`,{nozzle:F(o===`L`?`common.left`:`common.right`)}):d,onClick:()=>u&&Fe(Pe===`nozzle-select`?null:`nozzle-select`),children:[(0,G.jsx)(COe,{className:`w-[var(--pc-i35,0.875rem)] h-[var(--pc-i35,0.875rem)] mb-0.5 text-amber-600 dark:text-amber-400`}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`span`,{className:`text-[length:var(--pc-t11,11px)] font-bold ${o===`L`?`text-amber-700 dark:text-amber-400`:`text-gray-500`}`,children:[`L`,s?.nozzle_diameter?` ${s.nozzle_diameter}`:``]}),(0,G.jsx)(`span`,{className:`text-[length:var(--pc-t9,9px)] text-bambu-gray/40`,children:`·`}),(0,G.jsxs)(`span`,{className:`text-[length:var(--pc-t11,11px)] font-bold ${o===`R`?`text-amber-700 dark:text-amber-400`:`text-gray-500`}`,children:[`R`,c?.nozzle_diameter?` ${c.nozzle_diameter}`:``]})]}),(0,G.jsx)(`p`,{className:`text-[length:var(--pc-t9,9px)] text-bambu-gray`,children:F(`printers.temperatures.nozzle`)}),Pe===`nozzle-select`&&(0,G.jsx)(oG,{title:`Set Nozzle Selection`,widthClass:`w-[300px]`,popoverWidth:300,popoverHeight:140,isPending:br.isPending,options:[{label:`Left`,value:1},{label:`Right`,value:0}],onClose:()=>Fe(null),onSubmit:e=>br.mutate(e)})]})}),W.nozzle_rack&&W.nozzle_rack.some(e=>e.id>=2)&&(0,G.jsx)(gOe,{slots:W.nozzle_rack,filamentInfo:cn})]}),(0,G.jsx)(`div`,{className:`mt-2 flex items-center gap-1.5`,children:_.map(({key:e,label:t,value:n,Icon:r,activeClass:i})=>{let a=n>0;return(0,G.jsxs)(`div`,{className:`relative px-2 py-1.5 bg-bambu-dark rounded-lg flex-1 min-w-0 flex items-center justify-center gap-1 transition-colors ${u?`cursor-pointer hover:bg-bambu-dark-tertiary`:`cursor-default opacity-80`}`,title:u?t:d,onClick:()=>u&&Fe(Pe===`fan-${e}`?null:`fan-${e}`),children:[(0,G.jsx)(r,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)] shrink-0 ${a?i:`text-bambu-gray/50`}`}),(0,G.jsxs)(`span`,{className:`text-[length:var(--pc-t10,10px)] leading-none ${a?`text-white`:`text-bambu-gray/50`}`,children:[n,`%`]}),Pe===`fan-${e}`&&(0,G.jsx)(oG,{title:`Set ${t} Speed`,unit:`%`,customMin:0,customMax:100,isPending:yr.isPending,options:_m(j,`%`),onClose:()=>Fe(null),onSubmit:t=>yr.mutate({fan:e,speed:t})})]},e)})})]})})(),r===`expanded`&&Kn&&hr,r===`expanded`&&(()=>{let t=W.state===`RUNNING`,n=W.state===`PAUSE`,r=t||n,i=dr.isPending||fr.isPending||pr.isPending,a=`bg-bambu-dark text-bambu-gray/50 cursor-not-allowed opacity-50`,o=`flex h-8 w-8 items-center justify-center rounded-lg text-xs font-medium transition-colors disabled:opacity-50 disabled:cursor-not-allowed`,s=`flex h-8 w-20 items-center justify-center gap-1 px-2 rounded-lg text-xs font-medium transition-colors`;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.controls`)}),(0,G.jsx)(`div`,{className:`flex-1 h-[2px] bg-bambu-dark-tertiary`})]}),(0,G.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-x-2 gap-y-2`,children:[(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 min-w-0`,children:[(0,G.jsx)(`button`,{onClick:()=>xr.mutate(!W.chamber_light),disabled:!W.connected||xr.isPending||!z(`printers:control`),className:`${o} ${W.chamber_light?`bg-yellow-50 dark:bg-yellow-500/10 text-yellow-700 dark:text-yellow-400 hover:bg-yellow-500/20`:`bg-bambu-dark text-bambu-gray/50 hover:bg-bambu-dark-tertiary hover:text-white`}`,title:z(`printers:control`)?W.chamber_light?F(`printers.chamberLightOff`):F(`printers.chamberLightOn`):F(`printers.permission.noControl`),children:(0,G.jsx)(yT,{on:W.chamber_light??!1,className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)]`})}),[`P2S`,`X2D`,`H2D`,`H2C`,`H2S`].includes(e.model??``)&&(()=>{let t=W.airduct_mode===1,n=t?dc:fu,r=t?`text-orange-600 dark:text-orange-400`:`text-sky-600 dark:text-sky-400`,i=t?`bg-orange-50 dark:bg-orange-500/10 text-orange-700 dark:text-orange-400 hover:bg-orange-500/20`:`bg-sky-50 dark:bg-sky-500/10 text-sky-700 dark:text-sky-400 hover:bg-sky-500/20`;return(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(`button`,{onClick:()=>je(Ae===e.id?null:e.id),disabled:!z(`printers:control`),className:`${o} ${i}`,title:`${F(`printers.airduct.title`)}: ${F(t?`printers.airduct.heating`:`printers.airduct.cooling`)}`,children:(0,G.jsx)(n,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)] ${r}`})}),Ae===e.id&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`fixed inset-0 z-40`,onClick:()=>je(null)}),(0,G.jsx)(`div`,{className:`absolute bottom-full left-0 mb-1 z-50 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg py-1 min-w-[130px]`,children:[{mode:`cooling`,label:F(`printers.airduct.cooling`),modeId:0},{mode:`heating`,label:F(`printers.airduct.heating`),modeId:1}].map(({mode:e,label:t,modeId:n})=>(0,G.jsxs)(`button`,{onClick:()=>{Cr.mutate(e),je(null)},className:`w-full text-left px-3 py-1.5 text-xs transition-colors flex items-center gap-2 ${W.airduct_mode===n?`text-bambu-green bg-bambu-green/10`:`text-white hover:bg-bambu-dark-tertiary`}`,children:[e===`heating`?(0,G.jsx)(dc,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)]`}):(0,G.jsx)(fu,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)]`}),t]},e))})]})]})})(),(()=>{let t=z(`printers:control`),n=r||!t,i=`flex h-8 w-8 items-center justify-center rounded bg-indigo-100 dark:bg-indigo-500/15 text-indigo-700 dark:text-indigo-300 transition-colors hover:bg-indigo-200 dark:hover:bg-indigo-500/30 disabled:cursor-not-allowed disabled:opacity-50`,a=e=>{let t=e*Ie*1;wr.mutate({distance:t})},s=(e,t)=>{Tr.mutate({x:e,y:t})},c=e=>{Er.mutate(e)};return(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(`button`,{onClick:()=>Ne(Me===e.id?null:e.id),disabled:n,className:`${o} ${n?`bg-bambu-dark text-bambu-gray/50 cursor-not-allowed`:`bg-indigo-50 dark:bg-indigo-500/10 text-indigo-700 dark:text-indigo-400 hover:bg-indigo-500/20`}`,title:F(t?r?`printers.bedJog.disabledWhilePrinting`:`printers.bedJog.title`:`printers.permission.noControl`),children:(0,G.jsx)(hl,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)]`})}),Me===e.id&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`fixed inset-0 z-40`,onClick:()=>Ne(null)}),(0,G.jsxs)(`div`,{className:`absolute bottom-full left-0 mb-1 z-50 flex w-[216px] flex-col overflow-hidden rounded-xl border border-bambu-dark-tertiary bg-bambu-dark-secondary shadow-2xl`,children:[(0,G.jsx)(`div`,{className:`shrink-0 px-3 py-2.5 text-center text-sm font-medium text-white`,children:F(`printers.bedJog.title`)}),(0,G.jsx)(`div`,{className:`h-px bg-bambu-dark-tertiary`}),(0,G.jsxs)(`div`,{className:`flex items-start gap-1.5 bg-yellow-500/10 px-3 py-2 text-[length:var(--pc-t11,11px)] leading-snug text-yellow-700 dark:text-yellow-400`,children:[(0,G.jsx)(Nu,{className:`mt-0.5 h-3.5 w-3.5 shrink-0`}),(0,G.jsx)(`span`,{children:F(`printers.bedJog.limitWarning`)})]}),(0,G.jsx)(`div`,{className:`h-px bg-bambu-dark-tertiary`}),(0,G.jsx)(`div`,{className:`flex justify-center px-3 py-2.5`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-center gap-3`,children:[(0,G.jsxs)(`div`,{className:`grid grid-cols-3 gap-1`,children:[(0,G.jsx)(`div`,{}),(0,G.jsx)(`button`,{onClick:()=>s(0,Ie),disabled:Tr.isPending,className:i,"aria-label":`Move Y forward`,children:(0,G.jsx)(Vo,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)]`})}),(0,G.jsx)(`div`,{}),(0,G.jsx)(`button`,{onClick:()=>s(-Ie,0),disabled:Tr.isPending,className:i,"aria-label":`Move X left`,children:(0,G.jsx)(Io,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)]`})}),(0,G.jsx)(`button`,{onClick:()=>{Ne(null),Dr.mutate(`all`)},disabled:Dr.isPending,className:i,"aria-label":F(`printers.bedJog.homeZ`),children:(0,G.jsx)(Fc,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)]`})}),(0,G.jsx)(`button`,{onClick:()=>s(Ie,0),disabled:Tr.isPending,className:i,"aria-label":`Move X right`,children:(0,G.jsx)(Ro,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)]`})}),(0,G.jsx)(`div`,{}),(0,G.jsx)(`button`,{onClick:()=>s(0,-Ie),disabled:Tr.isPending,className:i,"aria-label":`Move Y back`,children:(0,G.jsx)(Fo,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)]`})}),(0,G.jsx)(`div`,{})]}),(0,G.jsxs)(`div`,{className:`flex flex-col items-center gap-1`,children:[(0,G.jsx)(`button`,{onClick:()=>a(-1),disabled:wr.isPending,className:i,"aria-label":F(`printers.bedJog.up`),children:(0,G.jsx)(Vo,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)]`})}),(0,G.jsx)(`div`,{className:`flex h-8 w-8 items-center justify-center text-bambu-gray/80`,children:(0,G.jsx)(Uc,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)]`})}),(0,G.jsx)(`button`,{onClick:()=>a(1),disabled:wr.isPending,className:i,"aria-label":F(`printers.bedJog.down`),children:(0,G.jsx)(Fo,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)]`})})]}),(0,G.jsxs)(`div`,{className:`flex flex-col items-center gap-1`,children:[(0,G.jsx)(`button`,{onClick:()=>c(-Ie),disabled:Er.isPending,className:i,"aria-label":`Retract filament`,children:(0,G.jsx)(Vo,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)]`})}),(0,G.jsx)(`div`,{className:`flex h-8 w-8 items-center justify-center text-bambu-gray/80`,children:(0,G.jsx)(`span`,{className:`text-sm font-semibold leading-none`,children:`E`})}),(0,G.jsx)(`button`,{onClick:()=>c(Ie),disabled:Er.isPending,className:i,"aria-label":`Extrude filament`,children:(0,G.jsx)(Fo,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)]`})})]})]})}),(0,G.jsx)(`div`,{className:`h-px bg-bambu-dark-tertiary`}),(0,G.jsxs)(`div`,{className:`px-3 pt-2.5 pb-3`,children:[(0,G.jsx)(`div`,{className:`mb-1 text-[length:var(--pc-t9,9px)] uppercase tracking-wider text-bambu-gray/70`,children:F(`printers.bedJog.step`)}),(0,G.jsx)(`div`,{className:`flex gap-1`,children:[1,10,50].map(e=>(0,G.jsx)(`button`,{onClick:()=>Le(e),className:`flex-1 px-1 py-1 rounded text-[length:var(--pc-t10,10px)] transition-colors ${Ie===e?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:e},e))})]})]})]})]})})(),(0,G.jsxs)(`div`,{className:`inline-flex rounded-lg ${e.plate_detection_enabled?`ring-1 ring-green-500`:``}`,children:[(0,G.jsx)(`button`,{onClick:Jr,disabled:!W.connected||Or.isPending||!z(`printers:update`),className:`${o} rounded-r-none ${e.plate_detection_enabled?`bg-green-50 dark:bg-green-500/10 text-green-700 dark:text-green-400 hover:bg-green-500/20`:`bg-bambu-dark text-bambu-gray/50 hover:bg-bambu-dark-tertiary hover:text-white`}`,title:z(`printers:update`)?e.plate_detection_enabled?F(`printers.plateDetection.enabledClick`):F(`printers.plateDetection.disabledClick`):F(`printers.plateDetection.noPermission`),children:Or.isPending?(0,G.jsx)(Y,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)] animate-spin`}):(0,G.jsx)(Kl,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)]`})}),(0,G.jsx)(`button`,{onClick:Yr,disabled:!W.connected||Kt||!z(`printers:update`),className:`flex h-8 w-8 items-center justify-center rounded-r-lg border-l border-bambu-dark-tertiary transition-colors disabled:opacity-50 disabled:cursor-not-allowed ${e.plate_detection_enabled?`bg-green-50 dark:bg-green-500/10 text-green-700 dark:text-green-400 hover:bg-green-500/20`:`bg-bambu-dark text-bambu-gray/50 hover:bg-bambu-dark-tertiary hover:text-white`}`,title:z(`printers:update`)?F(`printers.plateDetection.manageCalibration`):F(`printers.plateDetection.noPermission`),children:Kt?(0,G.jsx)(Y,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)] animate-spin`}):(0,G.jsx)(ds,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)]`})})]}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(`button`,{"data-testid":`speed-control`,onClick:()=>ke(Oe===e.id?null:e.id),disabled:!r||!z(`printers:control`),className:`${o} ${r?`bg-amber-50 dark:bg-amber-500/10 text-amber-700 dark:text-amber-400 hover:bg-amber-500/20`:`bg-bambu-dark text-bambu-gray/50 cursor-not-allowed`}`,title:r?F(`printers.speed.title`):void 0,children:(0,G.jsx)(xc,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)]`})}),Oe===e.id&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`fixed inset-0 z-40`,onClick:()=>ke(null)}),(0,G.jsx)(`div`,{className:`absolute bottom-full left-0 mb-1 z-50 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg py-1 min-w-[130px]`,children:[{mode:1,label:F(`printers.speed.silent`)},{mode:2,label:F(`printers.speed.standard`)},{mode:3,label:F(`printers.speed.sport`)},{mode:4,label:F(`printers.speed.ludicrous`)}].map(({mode:e,label:t})=>(0,G.jsx)(`button`,{onClick:()=>{Sr.mutate(e),ke(null)},className:`w-full text-left px-3 py-1.5 text-xs transition-colors ${W.speed_level===e?`text-bambu-green bg-bambu-green/10`:`text-white hover:bg-bambu-dark-tertiary`}`,children:t},e))})]})]})]}),(0,G.jsxs)(`div`,{className:`ml-auto flex items-center justify-end gap-2 flex-shrink-0`,children:[(()=>{let e=!r||i||!z(`printers:control`);return(0,G.jsxs)(`button`,{onClick:()=>n?ze(!0):De(!0),disabled:e,className:` ${s} ${e?a:n?`bg-bambu-green/20 text-bambu-green hover:bg-bambu-green/30`:`bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400 hover:bg-yellow-500/30`} `,title:z(`printers:control`)?F(n?`printers.resume`:`printers.pause`):F(`printers.permission.noControl`),children:[n?(0,G.jsx)(kl,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)]`}):(0,G.jsx)(Cl,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)]`}),F(n?`printers.resume`:`printers.pause`)]})})(),(()=>{let e=!r||i||!z(`printers:control`);return(0,G.jsxs)(`button`,{onClick:()=>Te(!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)(gu,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)]`}),F(`printers.stop`)]})})()]})]})]})})(),(En?.length>0||W.vt_tray.length>0)&&r===`expanded`&&(()=>{let t=En.filter(e=>e.tray.length>1),n=En.filter(e=>e.tray.length===1),r=En.length>0&&W.vt_tray.length>0,g=!(r&&xe),_=e.nozzle_count===2||W?.temperatures?.nozzle_2!==void 0,v=pG[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)(wOe,{state:W.ams_filament_backup,onClick:()=>be(!0)}),(0,G.jsx)(`div`,{className:`flex-1 h-[2px] bg-bambu-dark-tertiary`}),r&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(TOe,{hidden:xe,onClick:Ce}),(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=XW(t.id,xn,wn,Cn);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)(dG,{ams:t,printerId:e.id,label:ap(t.id,t.tray.length),amsLabels:pn,canEdit:z(`printers:update`),onSaved:mn,children:(0,G.jsx)(`span`,{className:`block truncate text-[length:var(--pc-t10,10px)] text-white font-medium cursor-default select-none`,children:pn?.[t.id]||ap(t.id,t.tray.length)})}),n?.kind===`inlet`?(0,G.jsx)(YW,{inlet:n.inlet,title:F(`printers.amsSwitchInletTooltip`,{inlet:n.inlet,side:np[n.inlet]})}):_&&n?.kind===`nozzle`?(0,G.jsx)(JW,{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)(tG,{humidity:t.humidity,goodThreshold:a?.humidityGood,fairThreshold:a?.humidityFair,onClick:()=>Nt({amsId:t.id,amsLabel:ap(t.id,t.tray.length),mode:`humidity`}),compact:!0}),t.temp!=null&&(0,G.jsx)(`div`,{className:`mr-1`,children:(0,G.jsx)(nG,{temp:t.temp,goodThreshold:a?.tempGood,fairThreshold:a?.tempFair,onClick:()=>Nt({amsId:t.id,amsLabel:ap(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?ar.mutate(t.id):Ze===t.id?Qe(null):yt(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(pOe(t.dry_sf_reason)):F(`printers.drying.start`),children:(0,G.jsx)(dc,{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-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)(dc,{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:()=>ar.mutate(t.id),disabled:ar.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)(Qu,{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,g=rG(r),_=t.id*4+n,v=kn===_,y=An!==null&&An===_,b=jn!==null&&jn===_,S=r?.tray_info_idx?cn?.[r.tray_info_idx]:null,C=ln?.[_],T=(r?.tray_uuid||r?.tag_uid||Cp(e.serial_number,t.id,n))?.toUpperCase(),E=T?s?.[T]:void 0,D=bp(E),O=o&&!m?p?.find(r=>r.printer_id===e.id&&r.ams_id===t.id&&r.tray_id===n):void 0,k=O?f?.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=u?.(e.id,t.id,n),M=(()=>{let e=j?.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})(),N=M===0&&i&&r.remain>0?null:M,P=D??A??N??(i?r.remain:null),I=D!==null||A!==null?`spoolman`:N===null?i?`ams`:void 0:`inventory`,L=r?.tray_type?{vendor:Np(r)?`Bambu Lab`:`Generic`,profile:C?.preset_name||(k?[k.brand,k.slicer_filament_name?.split(`@`)[0].trim()||k.material].filter(Boolean).join(` `).trim():null)||j?.spool?.slicer_filament_name||S?.name||r.tray_sub_brands||r.tray_type,colorName:gf(r.tray_color||``),colorHex:r.tray_color||null,kFactor:qW(r.k),fillLevel:P,trayUuid:r.tray_uuid||null,tagUid:r.tag_uid||null,fillSource:I}:null,R=Pr?.amsId===t.id&&Pr?.slotId===n,B=w.indexOf(_),V=B>=0?`P${B+1}`:null,ee=(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:`↓`}),V&&(0,G.jsx)(`span`,{"aria-label":F(`printers.activeJobSlot.ariaLabel`,{n:B+1}),title:F(`printers.activeJobSlot.title`,{n:B+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:V}),(0,G.jsx)(WW,{trayColor:r?.tray_color,trayType:r?.tray_type,isEmpty:a,emptyKind:g,slotNumber:n+1}),(0,G.jsx)(`div`,{className:`text-[length:var(--pc-t9,9px)] text-white font-bold truncate`,children:r?.tray_type||F(g===`reset`?`ams.slotUnconfigured`:`ams.slotEmpty`)}),(0,G.jsx)(`div`,{className:`mt-1 h-1.5 bg-black/30 rounded-full overflow-hidden`,children:P!==null&&P>=0&&!a&&r&&(0,G.jsx)(`div`,{className:`h-full rounded-full transition-all`,style:{width:`${P}%`,backgroundColor:yp(P)}})})]});return(0,G.jsxs)(`div`,{className:`relative group w-full`,style:x,children:[R&&(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)(Rl,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)] text-bambu-green animate-spin`})}),L?(0,G.jsx)(kU,{data:L,actions:hi({amsId:t.id,slotId:n,loadTrayId:t.id*4+n,isRefreshing:R}),spoolman:{enabled:o,linkedSpoolId:O?.spoolman_spool_id??(T?s?.[T]?.id:void 0),spoolmanUrl:c,syncMode:l,onLinkSpool:o&&!O&&!j?()=>{let r=(L.trayUuid||L.tagUid||Cp(e.serial_number,t.id,n)).toUpperCase();Lt({tagUid:L.tagUid||r,trayUuid:L.trayUuid||``,printerId:e.id,amsId:t.id,trayId:n})}:void 0,onUnlinkSpool:E?.id?()=>nr.mutate(E.id):void 0},inventory:(()=>{if(o){if(m)return;let i=O,a=k;return{assignedSpool:a?{id:a.id,material:a.material,brand:a.brand??null,color_name:a.color_name??null,remainingWeightGrams:a.label_weight?Math.max(0,Math.round(a.label_weight-a.weight_used)):void 0}:null,onAssignSpool:()=>zt({printerId:e.id,amsId:t.id,trayId:n,trayInfo:{type:r?.tray_type||L.profile,material:r?.tray_type??void 0,profile:L.profile,color:L.colorHex||``,location:`${ap(t.id,t.tray.length)} Slot ${n+1}`}}),onUnassignSpool:a&&!Np(r)?()=>h?.(a.id):void 0,isAssigned:!!i||Np(r)}}let i=u?.(e.id,t.id,n);return{assignedSpool:i?.spool?{id:i.spool.id,material:i.spool.material,brand:i.spool.brand,color_name:i.spool.color_name,remainingWeightGrams:Math.max(0,Math.round(i.spool.label_weight-i.spool.weight_used))}:null,onAssignSpool:()=>zt({printerId:e.id,amsId:t.id,trayId:n,trayInfo:{type:r?.tray_type||L.profile,material:r?.tray_type??void 0,profile:L.profile,color:L.colorHex||``,location:`${ap(t.id,t.tray.length)} Slot ${n+1}`}}),onUnassignSpool:i&&!Np(r)?()=>d?.(e.id,t.id,n):void 0,isAssigned:!!i||Np(r)}})(),configureSlot:{enabled:z(`printers:control`),onConfigure:()=>Vt({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:ip(t.id,r?.id??0,xn,wn),caliIdx:r?.cali_idx,savedPresetId:C?.preset_id})},children:ee}):(0,G.jsx)(AU,{kind:g??void 0,actions:hi({amsId:t.id,slotId:n,loadTrayId:t.id*4+n,isRefreshing:R}),configureSlot:{enabled:z(`printers:control`),onConfigure:()=>Vt({amsId:t.id,trayId:n,trayCount:t.tray.length,extruderId:ip(t.id,r?.id??0,xn,wn)})},onAssignSpool:()=>zt({printerId:e.id,amsId:t.id,trayId:n,trayInfo:{type:``,material:void 0,profile:``,color:``,location:`${ap(t.id,t.tray.length)} Slot ${n+1}`}}),children:ee})]},n)})})]},t.id)}),n.map(t=>{let n=XW(t.id,xn,wn,Cn),r=t.tray[0],i=r?.tray_type&&r.remain>=0,g=!r?.tray_type,v=rG(r),x=vp(t.id,r?.id??0,!1),C=kn===x,T=An!==null&&An===x,E=jn!==null&&jn===x,D=r?.tray_info_idx?cn?.[r.tray_info_idx]:null,O=ln?.[x],k=r?.id??0,A=(r?.tray_uuid||r?.tag_uid||Cp(e.serial_number,t.id,k))?.toUpperCase(),j=A?s?.[A]:void 0,M=bp(j),N=u?.(e.id,t.id,k),P=(()=>{let e=N?.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})(),I=P===0&&i&&r.remain>0?null:P,L=o&&!m?p?.find(n=>n.printer_id===e.id&&n.ams_id===t.id&&n.tray_id===k):void 0,R=L?f?.find(e=>e.id===L.spoolman_spool_id):void 0,B=R&&(R.label_weight??0)>0?Math.round(Math.max(0,(R.label_weight??0)-R.weight_used)/(R.label_weight??1)*100):null,V=M??B??I??(i?r.remain:null),ee=M!==null||B!==null?`spoolman`:I===null?i?`ams`:void 0:`inventory`,te=r?.tray_type?{vendor:Np(r)?`Bambu Lab`:`Generic`,profile:O?.preset_name||(R?[R.brand,R.slicer_filament_name?.split(`@`)[0].trim()||R.material].filter(Boolean).join(` `).trim():null)||N?.spool?.slicer_filament_name||D?.name||r.tray_sub_brands||r.tray_type,colorName:gf(r.tray_color||``),colorHex:r.tray_color||null,kFactor:qW(r.k),fillLevel:V,trayUuid:r.tray_uuid||null,tagUid:r.tag_uid||null,fillSource:ee}:null,ne=Pr?.amsId===t.id&&Pr?.slotId===k,re=w.indexOf(x),ie=re>=0?`P${re+1}`:null,ae=(0,G.jsxs)(`div`,{className:`relative w-full bg-bambu-dark-secondary rounded-lg p-1 text-center ${g?`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:`↓`}),ie&&(0,G.jsx)(`span`,{"aria-label":F(`printers.activeJobSlot.ariaLabel`,{n:re+1}),title:F(`printers.activeJobSlot.title`,{n:re+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:ie}),(0,G.jsx)(WW,{trayColor:r?.tray_color,trayType:r?.tray_type,isEmpty:g,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)(`div`,{className:`mt-1 h-1.5 bg-black/30 rounded-full overflow-hidden`,children:V!==null&&V>=0&&!g&&(0,G.jsx)(`div`,{className:`h-full rounded-full transition-all`,style:{width:`${V}%`,backgroundColor:yp(V)}})})]}),oe=y(11);return(0,G.jsxs)(`div`,{style:{flex:`1 1 ${oe}`,minWidth:oe,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)(dG,{ams:t,printerId:e.id,label:ap(t.id,t.tray.length),amsLabels:pn,canEdit:z(`printers:update`),onSaved:mn,children:(0,G.jsx)(`span`,{className:`block truncate text-[length:var(--pc-t10,10px)] text-white font-medium cursor-default select-none`,children:pn?.[t.id]||ap(t.id,t.tray.length)})}),n?.kind===`inlet`?(0,G.jsx)(YW,{inlet:n.inlet,title:F(`printers.amsSwitchInletTooltip`,{inlet:n.inlet,side:np[n.inlet]})}):_&&n?.kind===`nozzle`?(0,G.jsx)(JW,{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?ar.mutate(t.id):Ze===t.id?Qe(null):yt(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)(dc,{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 bg-amber-50 dark:bg-amber-500/10 px-2 py-1 text-[length:var(--pc-t9,9px)]`,children:[(0,G.jsx)(dc,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)] text-amber-600 dark:text-amber-400 shrink-0`}),t.dry_filament&&(0,G.jsx)(`span`,{className:`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})}),(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:()=>ar.mutate(t.id),disabled:ar.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)(Qu,{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:[ne&&(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)(Rl,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)] text-bambu-green animate-spin`})}),te?(0,G.jsx)(kU,{data:te,actions:hi({amsId:t.id,slotId:k,loadTrayId:t.id*4+k,isRefreshing:ne}),spoolman:{enabled:o,linkedSpoolId:L?.spoolman_spool_id??(A?s?.[A]?.id:void 0),spoolmanUrl:c,syncMode:l,onLinkSpool:o&&!L&&!N?()=>{let n=(te.trayUuid||te.tagUid||Cp(e.serial_number,t.id,k)).toUpperCase();Lt({tagUid:te.tagUid||n,trayUuid:te.trayUuid||``,printerId:e.id,amsId:t.id,trayId:k})}:void 0,onUnlinkSpool:j?.id?()=>nr.mutate(j.id):void 0},inventory:(()=>{if(o){if(m)return;let n=L,i=R;return{assignedSpool:i?{id:i.id,material:i.material,brand:i.brand??null,color_name:i.color_name??null,remainingWeightGrams:i.label_weight?Math.max(0,Math.round(i.label_weight-i.weight_used)):void 0}:null,onAssignSpool:()=>zt({printerId:e.id,amsId:t.id,trayId:k,trayInfo:{type:r?.tray_type||te.profile,material:r?.tray_type??void 0,profile:te.profile,color:te.colorHex||``,location:ap(t.id,t.tray.length)}}),onUnassignSpool:i&&!Np(r)?()=>h?.(i.id):void 0,isAssigned:!!n||Np(r)}}let n=u?.(e.id,t.id,k);return{assignedSpool:n?.spool?{id:n.spool.id,material:n.spool.material,brand:n.spool.brand,color_name:n.spool.color_name,remainingWeightGrams:Math.max(0,Math.round(n.spool.label_weight-n.spool.weight_used))}:null,onAssignSpool:()=>zt({printerId:e.id,amsId:t.id,trayId:k,trayInfo:{type:r?.tray_type||te.profile,material:r?.tray_type??void 0,profile:te.profile,color:te.colorHex||``,location:ap(t.id,t.tray.length)}}),onUnassignSpool:n&&!Np(r)?()=>d?.(e.id,t.id,k):void 0,isAssigned:!!n||Np(r)}})(),configureSlot:{enabled:z(`printers:control`),onConfigure:()=>Vt({amsId:t.id,trayId:k,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:ip(t.id,r?.id??0,xn,wn),caliIdx:r?.cali_idx,savedPresetId:O?.preset_id})},children:ae}):(0,G.jsx)(AU,{kind:v??void 0,actions:hi({amsId:t.id,slotId:k,loadTrayId:t.id*4+k,isRefreshing:ne}),configureSlot:{enabled:z(`printers:control`),onConfigure:()=>Vt({amsId:t.id,trayId:k,trayCount:t.tray.length,extruderId:ip(t.id,r?.id??0,xn,wn)})},onAssignSpool:()=>zt({printerId:e.id,amsId:t.id,trayId:k,trayInfo:{type:``,material:void 0,profile:``,color:``,location:ap(t.id,t.tray.length)}}),children:ae})]}),(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)(nG,{temp:t.temp,goodThreshold:a?.tempGood,fairThreshold:a?.tempFair,onClick:()=>Nt({amsId:t.id,amsLabel:ap(t.id,t.tray.length),mode:`temperature`}),compact:!0}),t.humidity!=null&&(0,G.jsx)(tG,{humidity:t.humidity,goodThreshold:a?.humidityGood,fairThreshold:a?.humidityFair,onClick:()=>Nt({amsId:t.id,amsLabel:ap(t.id,t.tray.length),mode:`humidity`}),compact:!0})]})]})]},t.id)}),W.vt_tray.length>0&&g&&(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=_&&kn===254?n===254&&W.active_extruder===1||n===255&&W.active_extruder===0:kn===n,i=n-254,a=_?F(n===254?`printers.extL`:`printers.extR`):``,g=t.tray_info_idx?cn?.[t.tray_info_idx]:null,v=ln?.[1020+i],y=(t.tray_uuid||t.tag_uid||Cp(e.serial_number,255,i))?.toUpperCase(),b=y?s?.[y]:void 0,S=bp(b),C=u?.(e.id,255,i),w=(()=>{let e=C?.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})(),T=t.tray_type&&t.remain>=0,E=w===0&&T&&t.remain>0?null:w,D=o&&!m?p?.find(t=>t.printer_id===e.id&&t.ams_id===255&&t.tray_id===i):void 0,O=D?f?.find(e=>e.id===D.spoolman_spool_id):void 0,k=O&&(O.label_weight??0)>0?Math.round(Math.max(0,(O.label_weight??0)-O.weight_used)/(O.label_weight??1)*100):null,A=S??k??E??(T?t.remain:null),j=S!==null||k!==null?`spoolman`:E===null?T?`ams`:void 0:`inventory`,M={vendor:Np(t)?`Bambu Lab`:`Generic`,profile:v?.preset_name||(O?[O.brand,O.slicer_filament_name?.split(`@`)[0].trim()||O.material].filter(Boolean).join(` `).trim():null)||C?.spool?.slicer_filament_name||g?.name||t.tray_sub_brands||t.tray_type||`Unknown`,colorName:gf(t.tray_color||``),colorHex:t.tray_color||null,kFactor:qW(t.k),fillLevel:A,trayUuid:t.tray_uuid||null,tagUid:t.tag_uid||null,fillSource:j},N=!t.tray_type,P=rG(t),I=(0,G.jsxs)(`div`,{className:`w-full bg-bambu-dark-secondary rounded-lg p-1 text-center ${N?`opacity-50`:``} ${r?`ring-2 ring-bambu-green ring-offset-1 ring-offset-bambu-dark`:``}`,children:[(0,G.jsx)(WW,{trayColor:t.tray_color,trayType:t.tray_type,isEmpty:N,emptyKind:P,slotNumber:_?n===254?`L`:`R`:i+1}),(0,G.jsx)(`div`,{className:`text-[length:var(--pc-t9,9px)] font-bold truncate ${N?`text-white/40`:`text-white`}`,children:t.tray_type||F(`ams.slotEmpty`)}),(0,G.jsx)(`div`,{className:`mt-1 h-1.5 bg-black/30 rounded-full overflow-hidden`,children:A!==null&&A>=0&&!N&&(0,G.jsx)(`div`,{className:`h-full rounded-full transition-all`,style:{width:`${A}%`,backgroundColor:yp(A)}})})]});return(0,G.jsx)(`div`,{className:`relative group w-full`,style:x,children:N?(0,G.jsx)(AU,{kind:P??void 0,actions:hi({amsId:255,slotId:i,loadTrayId:n,includeRfid:!1}),configureSlot:{enabled:z(`printers:control`),onConfigure:()=>Vt({amsId:255,trayId:i,trayCount:1,extruderId:_?+(n===254):void 0})},onAssignSpool:()=>zt({printerId:e.id,amsId:255,trayId:i,trayInfo:{type:``,material:void 0,profile:``,color:``,location:`External Slot ${i+1}`}}),children:I}):(0,G.jsx)(kU,{data:M,actions:hi({amsId:255,slotId:i,loadTrayId:n,includeRfid:!1}),spoolman:{enabled:o,linkedSpoolId:D?.spoolman_spool_id??(y?s?.[y]?.id:void 0),spoolmanUrl:c,syncMode:l,onLinkSpool:o&&!D&&!C?()=>{let t=(M.trayUuid||M.tagUid||Cp(e.serial_number,255,i)).toUpperCase();Lt({tagUid:M.tagUid||t,trayUuid:M.trayUuid||``,printerId:e.id,amsId:255,trayId:i})}:void 0,onUnlinkSpool:b?.id?()=>nr.mutate(b.id):void 0},inventory:(()=>{if(o){if(m)return;let n=D,r=O;return{assignedSpool:r?{id:r.id,material:r.material,brand:r.brand??null,color_name:r.color_name??null,remainingWeightGrams:r.label_weight?Math.max(0,Math.round(r.label_weight-r.weight_used)):void 0}:null,onAssignSpool:()=>zt({printerId:e.id,amsId:255,trayId:i,trayInfo:{type:t.tray_type||M.profile,material:t.tray_type??void 0,profile:M.profile,color:M.colorHex||``,location:a||F(`printers.external`)}}),onUnassignSpool:r&&!Np(t)?()=>h?.(r.id):void 0,isAssigned:!!n||Np(t)}}let n=u?.(e.id,255,i);return{assignedSpool:n?.spool?{id:n.spool.id,material:n.spool.material,brand:n.spool.brand,color_name:n.spool.color_name,remainingWeightGrams:Math.max(0,Math.round(n.spool.label_weight-n.spool.weight_used))}:null,onAssignSpool:()=>zt({printerId:e.id,amsId:255,trayId:i,trayInfo:{type:t.tray_type||M.profile,material:t.tray_type??void 0,profile:M.profile,color:M.colorHex||``,location:a||F(`printers.external`)}}),onUnassignSpool:n&&!Np(t)?()=>d?.(e.id,255,i):void 0,isAssigned:!!n||Np(t)}})(),configureSlot:{enabled:z(`printers:control`),onConfigure:()=>Vt({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:I})},n)})})]})]})]})})()]}),r===`expanded`&&(0,G.jsxs)(`div`,{className:`mt-auto`,children:[Pn&&(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)(ed,{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:Pn.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:In?.energy?.power!==null&&In?.energy?.power!==void 0?`${Math.round(In.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:()=>lr.mutate(!Pn.auto_off),disabled:lr.isPending||Pn.auto_off_executed||!z(`smart_plugs:control`),title:z(`smart_plugs:control`)?Pn.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`)?Pn.auto_off||Pn.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)(ks,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)]`})}),(0,G.jsx)(`button`,{onClick:()=>{In?.state===`ON`?fe(!0):ue(!0)},disabled:cr.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`)?In?.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`)?In?.state===`ON`?`Turn off`:`Turn on`:F(`printers.permission.noSmartPlugControl`),children:(0,G.jsx)(ed,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)]`})})]})]}),Fn&&Fn.length>0&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mt-2`,children:[(0,G.jsx)(Fc,{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:Fn.map(e=>{let t=e.ha_entity_id?.startsWith(`script.`);return(0,G.jsxs)(`button`,{onClick:()=>{t?ur.mutate({id:e.id,action:`on`}):me(e)},disabled:ur.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)(kl,{className:`w-[var(--pc-i25,0.625rem)] h-[var(--pc-i25,0.625rem)]`}),e.name]},e.id)})})]})]}),(0,G.jsx)(Yse,{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:[gi,(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:()=>pi(_),disabled:!W?.connected||!z(`camera:view`),title:z(`camera:view`)?F(_===`embedded`?`printers.openCameraOverlay`:`printers.openCameraWindow`):F(`printers.permission.noCamera`),className:`${fi} !rounded-r-none`,children:(0,G.jsx)(Vu,{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();At({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)(ds,{className:`w-3 h-3`})})]}),kt&&(0,G.jsx)(AT,{x:kt.x,y:kt.y,items:mi,onClose:()=>At(null)}),(0,G.jsx)(Q,{variant:`secondary`,size:`sm`,onClick:()=>se(!0),disabled:!yn||!z(`printers:files`),title:z(`printers:files`)?F(`printers.browseFiles`):F(`printers.permission.noFiles`),className:fi,children:(0,G.jsx)(Ac,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)]`})}),(0,G.jsxs)(Q,{size:`sm`,onClick:()=>Ue(!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)(Pl,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)]`}),F(`common.print`)]})]})]})]})]}),(0,G.jsx)(FOe,{printerId:e.id,dryingActive:En.some(e=>(e.dry_time??0)>0),timeFormat:g})]}),oe&&(0,G.jsx)(kse,{printerId:e.id,printerName:e.name,onClose:()=>se(!1)}),He&&(0,G.jsx)(bW,{folderId:null,onClose:()=>Ue(!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=uG(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});Xe({id:t.id,filename:t.filename})}}),Ye&&(0,G.jsx)(HW,{mode:`create`,libraryFileId:Ye.id,archiveName:Ye.filename,initialSelectedPrinterIds:[e.id],onClose:()=>Xe(null),onSuccess:()=>Xe(null),cleanupLibraryAfterDispatch:!0}),H&&(0,G.jsx)(Wse,{printerId:e.id,printerName:e.name,onClose:()=>ce(!1)}),Ke&&(0,G.jsx)(Rp,{printerId:e.id,printerName:e.name,onClose:()=>qe(!1)}),We&&(0,G.jsx)(oOe,{printer:e,status:W,totalPrintHours:n?.total_print_hours,onClose:Je}),Wt&&(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,onClick:()=>Yr(),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:[Wt.needs_calibration?(0,G.jsx)(Kl,{className:`w-[var(--pc-i5,1.25rem)] h-[var(--pc-i5,1.25rem)] text-blue-500`}):Wt.is_empty?(0,G.jsx)(ys,{className:`w-[var(--pc-i5,1.25rem)] h-[var(--pc-i5,1.25rem)] text-green-500`}):(0,G.jsx)(Ts,{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`}),Wt.reference_count!==void 0&&Wt.max_references&&(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray bg-bambu-dark-tertiary px-2 py-1 rounded`,children:[Wt.reference_count,`/`,Wt.max_references,` refs`]})]}),(0,G.jsx)(`button`,{onClick:()=>Yr(),className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,G.jsx)(Qu,{className:`w-[var(--pc-i5,1.25rem)] h-[var(--pc-i5,1.25rem)]`})})]}),(0,G.jsxs)(`div`,{className:`p-4 space-y-4`,children:[Wt.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 ${Wt.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 ${Wt.is_empty?`text-green-700 dark:text-green-400`:`text-yellow-700 dark:text-yellow-400`}`,children:Wt.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(Wt.confidence*100),`% | `,F(`printers.plateDetection.difference`),`: `,Wt.difference_percent.toFixed(1),`%`]})]}),Wt.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:Wt.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:Wt.message})]}),Hr&&Hr.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:Hr.references.length,max:Hr.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:Hr.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:()=>Qr(t.index),className:`absolute top-1 right-1 p-0.5 bg-red-500/80 rounded opacity-0 group-hover:opacity-100 transition-opacity`,title:F(`printers.plateDetection.deleteReference`),children:(0,G.jsx)(Qu,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)] text-white`})}),Wr?.index===t.index?(0,G.jsx)(`input`,{type:`text`,value:Wr.label,onChange:e=>Gr({...Wr,label:e.target.value}),onBlur:()=>Zr(t.index,Wr.label),onKeyDown:e=>{e.key===`Enter`&&Zr(t.index,Wr.label),e.key===`Escape`&&Gr(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:()=>Gr({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?Uf(t.timestamp)?.toLocaleDateString()??``:``})]},t.index))})]}),!Wt.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`})]}),Xt?(0,G.jsxs)(`div`,{className:`flex gap-1`,children:[(0,G.jsx)(Q,{variant:`ghost`,size:`sm`,onClick:()=>Zt(null),disabled:Qt,children:F(`common.cancel`)}),(0,G.jsx)(Q,{size:`sm`,onClick:$r,disabled:Qt,children:Qt?(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:()=>Zt(Wt.roi||{x:.15,y:.35,w:.7,h:.55}),children:[(0,G.jsx)(El,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)] mr-1`}),F(`common.edit`)]})]}),Xt?(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:Xt.x,onChange:e=>Zt({...Xt,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(Xt.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:Xt.y,onChange:e=>Zt({...Xt,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(Xt.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:Xt.w,onChange:e=>Zt({...Xt,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(Xt.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:Xt.h,onChange:e=>Zt({...Xt,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(Xt.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((Wt.roi?.x||.15)*100),`%, Y=`,Math.round((Wt.roi?.y||.35)*100),`%, W=`,Math.round((Wt.roi?.w||.7)*100),`%, H=`,Math.round((Wt.roi?.h||.55)*100),`%`]})]})]}),(0,G.jsx)(`div`,{className:`flex justify-end gap-2 p-4`,children:Wt.needs_calibration?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Q,{variant:`ghost`,onClick:()=>Yr(),children:F(`common.cancel`)}),(0,G.jsx)(Q,{onClick:()=>Xr(),disabled:Jt,children:Jt?(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:()=>Xr(),disabled:Jt,children:Jt?`Adding...`:`Add Reference (${Hr?.references.length||0}/${Hr?.max_references||5})`}),(0,G.jsx)(Q,{onClick:()=>Yr(),children:`Close`})]})})]})}),le&&Pn&&(0,G.jsx)(Xd,{title:F(`printers.confirm.powerOnTitle`),message:F(`printers.confirm.powerOnMessage`,{name:e.name}),confirmText:F(`printers.confirm.powerOnButton`),variant:`default`,onConfirm:()=>{cr.mutate(`on`),ue(!1)},onCancel:()=>ue(!1)}),kr&&(0,G.jsx)(Xd,{title:F(`printers.maintenance.confirmMidPrintTitle`),message:F(`printers.maintenance.confirmMidPrintMessage`,{name:e.name}),confirmText:F(`printers.maintenance.menuEnter`),variant:`danger`,onConfirm:()=>{Or.mutate(!1),Ar(!1)},onCancel:()=>Ar(!1)}),de&&Pn&&(0,G.jsx)(Xd,{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:()=>{cr.mutate(`off`),fe(!1)},onCancel:()=>fe(!1)}),pe&&(0,G.jsx)(Xd,{title:F(`printers.confirm.haToggleTitle`,{name:pe.name}),message:W?.state===`RUNNING`?F(`printers.confirm.haToggleWarning`,{name:e.name,entity:pe.ha_entity_id||pe.name}):F(`printers.confirm.haToggleMessage`,{entity:pe.ha_entity_id||pe.name}),confirmText:F(`printers.confirm.haToggleButton`),variant:W?.state===`RUNNING`?`danger`:`default`,onConfirm:()=>{ur.mutate({id:pe.id,action:`toggle`}),me(null)},onCancel:()=>me(null)}),we&&(0,G.jsx)(Xd,{title:F(`printers.confirm.stopTitle`),message:F(`printers.confirm.stopMessage`,{name:e.name}),confirmText:F(`printers.confirm.stopButton`),variant:`danger`,onConfirm:()=>{dr.mutate(),Te(!1)},onCancel:()=>Te(!1)}),Ee&&(0,G.jsx)(Xd,{title:F(`printers.confirm.pauseTitle`),message:F(`printers.confirm.pauseMessage`,{name:e.name}),confirmText:F(`printers.confirm.pauseButton`),variant:`default`,onConfirm:()=>{fr.mutate(),De(!1)},onCancel:()=>De(!1)}),Re&&(0,G.jsx)(Xd,{title:F(`printers.confirm.resumeTitle`),message:F(`printers.confirm.resumeMessage`,{name:e.name}),confirmText:F(`printers.confirm.resumeButton`),variant:`default`,onConfirm:()=>{pr.mutate(),ze(!1)},onCancel:()=>ze(!1)}),(0,G.jsx)(xT,{printerId:e.id,isOpen:Be,onClose:()=>Ve(!1)}),he&&(0,G.jsx)(Ree,{printerName:e.name,errors:W?.hms_errors||[],onClose:()=>ge(!1),printerId:e.id,hasPermission:z,runoutGuidance:Nn}),_e&&(0,G.jsx)(Gse,{printerName:e.name,detection:N,lastError:P,onClose:()=>ve(!1)}),ye&&W&&(0,G.jsx)(yDe,{isOpen:ye,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:sr.isPending,onToggle:e=>sr.mutate(e),onClose:()=>be(!1)}),Mt&&(0,G.jsx)(hDe,{isOpen:!!Mt,onClose:()=>Nt(null),printerId:e.id,printerName:e.name,amsId:Mt.amsId,amsLabel:Mt.amsLabel,initialMode:Mt.mode,thresholds:a}),Pt&&(0,G.jsx)(xDe,{isOpen:!!Pt,onClose:()=>Ft(null),printerId:e.id,printerName:e.name,initialKind:Pt.initialKind,availableKinds:Pt.availableKinds}),It&&(0,G.jsx)(jU,{isOpen:!!It,onClose:()=>Lt(null),tagUid:It.tagUid,trayUuid:It.trayUuid,printerId:It.printerId,amsId:It.amsId,trayId:It.trayId}),Rt&&(0,G.jsx)(NU,{isOpen:!!Rt,onClose:()=>zt(null),printerId:Rt.printerId,amsId:Rt.amsId,trayId:Rt.trayId,trayInfo:Rt.trayInfo,spoolmanEnabled:!!o}),Bt&&(0,G.jsx)(vW,{isOpen:!!Bt,onClose:()=>Vt(null),printerId:e.id,slotInfo:Bt,printerModel:uG(e.model)||void 0,nozzleDiameter:Mp(W,Bt.amsId),onSuccess:()=>{I.invalidateQueries({queryKey:[`slotPresets`,e.id]}),I.invalidateQueries({queryKey:[`printerStatus`,e.id]})}}),ie&&(0,G.jsx)(ROe,{printer:e,onClose:()=>ae(!1)}),Ht&&nn&&(0,G.jsx)(LOe,{printer:e,firmwareInfo:nn,onClose:()=>Ut(!1)}),Ze!==null&&ht&&(()=>{let e=$e===`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:()=>{xt.current=bt.current!==null&&document.activeElement===bt.current},onClick:()=>{if(xt.current){xt.current=!1;return}Qe(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:ht.left,...ht.placement===`above`?{bottom:`calc(100dvh - ${ht.anchorY}px)`,maxHeight:`${ht.anchorY-8}px`}:{top:ht.top,maxHeight:`calc(100dvh - ${ht.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)(dc,{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)(iG,{value:tt,options:Object.keys(S).map(e=>({value:e,label:e})),onChange:e=>{nt(e);let t=S[e];t&&(it(t[$e===`n3s`?`n3s`:`n3f`]),ot($e===`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)(`input`,{type:`number`,min:45,max:e,value:rt,onChange:t=>it(Math.min(e,Math.max(45,Number(t.target.value)||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:rt,onChange:t=>it(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)(`input`,{type:`number`,min:1,max:24,value:at,onChange:e=>ot(Math.min(24,Math.max(1,Number(e.target.value)||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:at,onChange:e=>ot(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=((Ze===null?void 0:En.find(e=>e.id===Ze))?.tray??[]).some(e=>e.state===11),t=st&&!e;return(0,G.jsx)(`button`,{type:`button`,onClick:()=>ct(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:()=>ut(e),className:`py-1 rounded-lg border text-[10px] font-medium transition-colors ${lt===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))}),lt===`delay`&&(0,G.jsx)(`div`,{className:`mt-1.5 grid grid-cols-4 gap-1`,children:uOe.map(e=>(0,G.jsx)(`button`,{type:`button`,"aria-pressed":dt===e,onClick:()=>ft(e),className:`py-1 rounded-lg border text-[10px] font-medium transition-colors ${dt===e?`bg-bambu-green border-bambu-green text-white`:`bg-bambu-dark border-bambu-dark-tertiary text-white hover:bg-bambu-dark-tertiary`}`,children:Qf(e/60)},e))}),lt===`at_time`&&(0,G.jsx)(`input`,{ref:bt,type:`datetime-local`,"data-testid":`drying-start-at`,value:pt,onChange:e=>mt(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(Ze!==null){let e=(En.find(e=>e.id===Ze)?.tray??[]).some(e=>e.state===11),t=st&&!e;if(lt===`now`)rr.mutate({amsId:Ze,temp:rt,duration:at,filament:tt,rotateTray:t});else{let e=Aee(lt,dt,pt);e&&ir.mutate({amsId:Ze,temp:rt,duration:at,filament:tt,rotateTray:t,startAfter:e})}}},disabled:rr.isPending||ir.isPending||lt===`at_time`&&!pt,"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:lt===`now`?rr.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:ht.left+ht.arrowLeft-5,top:ht.anchorY-5,...ht.placement===`above`?{borderRightWidth:1,borderBottomWidth:1}:{borderLeftWidth:1,borderTopWidth:1}}})]})})()]})}function IOe({onClose:e,onAdd:t,existingSerials:n}){let{t:r}=U(),[i,a]=(0,y.useState)({name:``,serial_number:``,ip_address:``,access_code:``,model:``,location:``,auto_archive:!0}),[o,s]=(0,y.useState)(!1),[c,l]=(0,y.useState)([]),[u,d]=(0,y.useState)(``),[f,p]=(0,y.useState)(!1),[m,h]=(0,y.useState)(!1),[g,_]=(0,y.useState)([]),[v,b]=(0,y.useState)(``),[x,S]=(0,y.useState)(``),[C,w]=(0,y.useState)(!1),[T,E]=(0,y.useState)({scanned:0,total:0}),[D,O]=(0,y.useState)(!1),[k,A]=(0,y.useState)(!1),[j,M]=(0,y.useState)(null);(0,y.useEffect)(()=>{md.getInfo().then(e=>{h(e.is_docker),e.subnets.length>0&&(_(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),p(!1),E({scanned:0,total:0});let e=C?x.trim():v,t=m||C;if(t&&C)try{localStorage.setItem(`bambuddy.discovery.customSubnet`,e)}catch{}try{if(t){await md.startSubnetScan(e);let t=setInterval(async()=>{try{let e=await md.getScanStatus();E({scanned:e.scanned,total:e.total}),l(await md.getDiscoveredPrinters()),e.running||(clearInterval(t),s(!1),p(!0))}catch(e){console.error(`Failed to get scan status:`,e)}},500)}else{await md.startDiscovery(10);let e=setInterval(async()=>{try{l(await md.getDiscoveredPrinters())}catch(e){console.error(`Failed to get discovered printers:`,e)}},1e3);setTimeout(async()=>{clearInterval(e);try{await md.stopDiscovery()}catch{}s(!1),p(!0);try{l(await md.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),p(!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:uG(e.model)}),l([])};return(0,y.useEffect)(()=>()=>{md.stopDiscovery().catch(()=>{}),md.stopSubnetScan().catch(()=>{})},[]),(0,y.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)(jd,{className:`w-full max-w-md my-auto max-h-[calc(100vh-2rem)] overflow-y-auto`,onClick:e=>e.stopPropagation(),children:(0,G.jsxs)(Nd,{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`)}),g.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__`:v,onChange:e=>{e.target.value===`__custom__`?w(!0):(w(!1),b(e.target.value))},disabled:o,children:[g.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:v,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(m?`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`}),(m||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)(Jl,{className:`w-4 h-4`}),r(m||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:[uG(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)(ds,{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(m||C?`printers.discovery.scanningSubnet`:`printers.discovery.scanningNetwork`)}),f&&!o&&c.length===0&&(0,G.jsx)(`p`,{className:`mt-2 text-sm text-bambu-gray text-center`,children:r(m||C?`printers.discovery.noPrintersFoundSubnet`:`printers.discovery.noPrintersFoundNetwork`)}),f&&!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)(vu,{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)(Nu,{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)(Lp,{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)(Rp,{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 LOe({printer:e,firmwareInfo:t,onClose:n}){let{t:r}=U(),i=so(),{showToast:a}=zd(),{hasPermission:o}=Td(),s=o(`firmware:update`),[c,l]=(0,y.useState)(null),[u,d]=(0,y.useState)(!1),[f,p]=(0,y.useState)(null),[m,h]=(0,y.useState)(t.update_available?t.latest_version:null),{data:g,isLoading:_}=K({queryKey:[`firmwarePrepare`,e.id,m],queryFn:()=>vd.prepareUpload(e.id,m??void 0),staleTime:3e4,enabled:!!m&&s&&!u}),v=q({mutationFn:()=>vd.startUpload(e.id,m??void 0),onSuccess:()=>{d(!0);let t=setInterval(async()=>{try{let n=await vd.getUploadStatus(e.id);l(n),(n.status===`complete`||n.status===`error`)&&(clearInterval(t),p(null),d(!1),n.status===`complete`&&(a(r(`printers.firmwareModal.uploadedToast`),`success`),i.invalidateQueries({queryKey:[`firmwareUpdate`,e.id]})))}catch{}},2e3);p(t)},onError:e=>{a(r(`printers.firmwareModal.uploadFailed`,{error:e.message}),`error`),d(!1)}});return(0,y.useEffect)(()=>()=>{f&&clearInterval(f)},[f]),(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50`,children:(0,G.jsx)(jd,{className:`w-full max-w-md mx-4`,children:(0,G.jsxs)(Nd,{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)(qs,{className:`w-5 h-5 text-orange-600 dark:text-orange-400`}):(0,G.jsx)(ys,{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=m?t.available_versions?.find(e=>e.version===m):null,n=m??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=m===e.version,a=t.current_version?See(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:()=>h(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)})})]}),m?_?(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`)]}):g&&!u&&!c?(0,G.jsx)(`div`,{className:`mb-4`,children:g.can_proceed?(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-green text-sm`,children:[(0,G.jsx)(Yo,{className:`w-4 h-4`}),r(`printers.firmwareModal.sdCardReady`)]}):(0,G.jsx)(`div`,{className:`space-y-1`,children:g.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)(_s,{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`)}),g?.can_proceed&&!u&&c?.status!==`complete`&&s&&(0,G.jsx)(Q,{onClick:()=>{l(null),v.mutate()},disabled:v.isPending,children:v.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)(qs,{className:`w-4 h-4 mr-2`}),r(`printers.firmwareModal.uploadFirmware`)]})})]})]})})})}function ROe({printer:e,onClose:t}){let{t:n}=U(),r=so(),{showToast:i}=zd(),[a,o]=(0,y.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,y.useState)(!1),[l,u]=(0,y.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,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]);let f=()=>{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)(jd,{className:`w-full max-w-md my-auto max-h-[calc(100vh-2rem)] overflow-y-auto`,onClick:e=>e.stopPropagation(),children:(0,G.jsxs)(Nd,{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)}f()},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)(Zu,{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)(Nu,{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)(Lp,{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:f,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 zOe(e){let{data:t}=K({queryKey:[`printerStatus`,e],queryFn:()=>Z.getPrinterStatus(e),refetchInterval:3e4});return!t?.connected}function BOe({printer:e,plug:t,onPowerOn:n,isPowering:r}){let i=zOe(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)(Nl,{className:`w-3 h-3`}),r?`...`:`On`]})]}):null}function VOe(){let{t:e}=U(),{resolvedMode:t,darkAccent:n,lightAccent:r}=Od(),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,y.useState)(!1),[s,c]=(0,y.useState)(()=>localStorage.getItem(`hideDisconnectedPrinters`)===`true`),[l,u]=(0,y.useState)(!1),[d,f]=(0,y.useState)(null),[p,m]=(0,y.useState)(()=>localStorage.getItem(`printerSortBy`)||`name`),[h,g]=(0,y.useState)(()=>localStorage.getItem(`printerSortAsc`)!==`false`),[_,v]=(0,y.useState)(()=>{let e=localStorage.getItem(`printerCardSize`);return e?parseInt(e,10):2}),[b,x]=(0,y.useState)(()=>localStorage.getItem(`printerPageView`)===`camwall`?`camwall`:`cards`),[S,C]=(0,y.useState)(()=>{let e=parseInt(localStorage.getItem(`camWallMaxLive`)||``,10);return Number.isFinite(e)&&e>0?e:4}),[w,T]=(0,y.useState)(()=>{let e=parseInt(localStorage.getItem(`camWallSnapshotSec`)||``,10);return Number.isFinite(e)&&e>0?e:8}),[E,D]=(0,y.useState)(()=>{let e=localStorage.getItem(`camWallStatusMode`);return e===`off`||e===`compact`||e===`full`?e:`full`}),O=_===1?`compact`:`expanded`,[k,A]=(0,y.useState)(null),j=(0,y.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,y.useCallback)(e=>{A(e),v(2),localStorage.setItem(`printerCardSize`,`2`),j(e)},[j]),N=(0,y.useCallback)(()=>{let e=k;A(null),v(1),localStorage.setItem(`printerCardSize`,`1`),e!=null&&j(e)},[k,j]),[P,F]=(0,y.useState)(``),[I,L]=(0,y.useState)(()=>{let e=localStorage.getItem(`printerStatusFilter`);return mOe(e)?e:`all`}),[R,z]=(0,y.useState)(()=>localStorage.getItem(`printerLocationFilter`)||`all`),[B,V]=(0,y.useState)(0),[ee,te]=(0,y.useState)(()=>{try{let e=localStorage.getItem(`printerCollapsedSections`);return e?JSON.parse(e):{}}catch{return{}}}),ne=so(),{showToast:re}=zd(),{hasPermission:ie}=Td(),[ae,oe]=(0,y.useState)(()=>Eee()),[se,H]=(0,y.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,y.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,y.useMemo)(()=>gm(ue?.nozzle_temp_presets,fm,0,320),[ue?.nozzle_temp_presets]),fe=(0,y.useMemo)(()=>gm(ue?.bed_temp_presets,pm,0,140),[ue?.bed_temp_presets]),pe=(0,y.useMemo)(()=>gm(ue?.chamber_temp_presets,mm,0,65),[ue?.chamber_temp_presets]),me=(0,y.useMemo)(()=>gm(ue?.fan_speed_presets,hm,0,100),[ue?.fan_speed_presets]),he=(0,y.useMemo)(()=>{if(ue?.drying_presets)try{let e=JSON.parse(ue.drying_presets);if(typeof e==`object`&&e&&Object.keys(e).length>0)return{...fG,...e}}catch{}return fG},[ue?.drying_presets]),ge=ae??(ue?.camera_view_mode===`embedded`?`embedded`:`window`),_e=(0,y.useCallback)(e=>{Dee(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,y.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 rd&&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`]}),f(null)},onError:()=>{f(null)}}),[He,Ue]=(0,y.useState)(new Set),[We,Ge]=(0,y.useState)(!1),[Ke,qe]=(0,y.useState)(null),[Je,Ye]=(0,y.useState)(!1),Xe=We||He.size>0,Ze=(0,y.useCallback)(e=>{Ue(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),Qe=(0,y.useCallback)(()=>{Ue(new Set),Ge(!1)},[]);(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&Xe&&Qe()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[Xe,Qe]);let $e=(0,y.useCallback)(async t=>{Ye(!0);let n=Array.from(He).filter(e=>{let n=ne.getQueryData([`printerStatus`,e]);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`clearPlate`:return!!n.awaiting_plate_clear;case`clearHMS`:return n.hms_errors&&xm(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,y.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=>{m(e),localStorage.setItem(`printerSortBy`,e)},rt=e=>{L(e),localStorage.setItem(`printerStatusFilter`,e)},it=e=>{z(e),localStorage.setItem(`printerLocationFilter`,e)},at=()=>{let e=!h;g(e),localStorage.setItem(`printerSortAsc`,String(e))},ot=()=>{switch(_){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,y.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,y.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?xm(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,y.useMemo)(()=>ce?[...new Set(ce.map(e=>e.location||``).filter(Boolean))].sort():[],[ce]);(0,y.useEffect)(()=>{!ce||R===`all`||lt.includes(R)||(z(`all`),localStorage.setItem(`printerLocationFilter`,`all`))},[ce,lt,R]);let ut=(0,y.useMemo)(()=>{let e=[...ct];switch(p){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?xm(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 h||e.reverse(),e},[ct,p,h,ne]),dt=(0,y.useCallback)(()=>{Ue(new Set(ut.map(e=>e.id))),Ge(!0)},[ut]),ft=(0,y.useCallback)(e=>{Ue(t=>{let n=new Set(t);return ut.forEach(t=>{lG(ne.getQueryData([`printerStatus`,t.id]))===e&&n.add(t.id)}),n}),Ge(!0)},[ut,ne]),pt=(0,y.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,y.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,y.useCallback)(e=>{te(t=>{let n={...t,[e]:!t[e]};try{localStorage.setItem(`printerCollapsedSections`,JSON.stringify(n))}catch{}return n})},[]),gt=(0,y.useMemo)(()=>{if(p===`name`||p===`eta`)return null;let e={};return p===`location`?ut.forEach(t=>{let n=t.location||`Ungrouped`;e[n]||(e[n]=[]),e[n].push(t)}):p===`model`?ut.forEach(t=>{let n=t.model||`Unknown`;e[n]||(e[n]=[]),e[n].push(t)}):p===`status`&&ut.forEach(t=>{let n=lG(ne.getQueryData([`printerStatus`,t.id]));e[n]||(e[n]=[]),e[n].push(t)}),e},[p,ut,ne,B]),_t=(0,y.useRef)(null),vt=(0,y.useRef)(null),yt=(0,y.useRef)(0),[bt,xt]=(0,y.useState)(!1),St=(0,y.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,y.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)(iG,{value:I,onChange:rt,fullWidth:t,options:KW.map(t=>({value:t.value,label:e(t.labelKey)}))}),ce&&ce.length>0&<.length>0&&(0,G.jsx)(iG,{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)(iG,{value:p,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(h?`printers.sort.descending`:`printers.sort.ascending`),children:h?(0,G.jsx)(Vo,{className:`w-4 h-4 text-white`}):(0,G.jsx)(Fo,{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)(Wc,{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)(dl,{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)(Ai,{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)(ec,{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=_===i;return(0,G.jsx)(`button`,{onClick:()=>{A(null),v(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)(mu,{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)(Nl,{className:`w-4 h-4`}),e(`printers.powerOn`)]}),(0,G.jsx)(ds,{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)(BOe,{printer:e,plug:ze[e.id],onPowerOn:e=>{f(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)(jl,{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)(Pl,{className:`w-7 h-7 text-bambu-green`}),e(`printers.title`)]}),(0,G.jsx)(OOe,{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)(Jl,{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)(Qu,{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)(aG,{label:e(`printers.toolbar.filters`,`Filters`),icon:(0,G.jsx)(bc,{className:`w-4 h-4`}),children:(0,G.jsx)(`div`,{className:`flex w-48 flex-col gap-2`,children:wt(!0)})}),(0,G.jsx)(aG,{label:e(`printers.toolbar.view`,`View`),icon:(0,G.jsx)(cu,{className:`w-4 h-4`}),children:(0,G.jsx)(`div`,{className:`flex w-48 flex-col gap-2`,children:Tt(!0)})}),(0,G.jsx)(aG,{label:e(`printers.toolbar.actions`,`Actions`),icon:(0,G.jsx)(Zs,{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)(jd,{children:(0,G.jsxs)(Nd,{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)(jl,{className:`w-4 h-4`}),e(`printers.addPrinter`)]})]})}):ut.length===0&&(P.trim()||I!==`all`||R!==`all`)?(0,G.jsx)(jd,{children:(0,G.jsx)(Nd,{className:`text-center py-12`,children:(0,G.jsx)(`p`,{className:`text-bambu-gray`,children:e(`printers.noSearchResults`)})})}):b===`camwall`?(0,G.jsx)(kT,{printers:ut,maxLive:S,snapshotIntervalSec:w,onTileClick:(e,t)=>{ge===`embedded`?H(n=>new Map(n).set(e,{id:e,name:t})):im(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=p===`status`?AOe.filter(e=>gt[e]?.length>0):Object.keys(gt);return h?e:[...e].reverse()})().map(t=>{let n=gt[t],r=`${p}:${t}`,i=!ee[r],a=p===`status`&&cG[t]?.dot||`bg-bambu-green`,o=p===`status`?e(cG[t]?.labelKey||t):t;return(0,G.jsx)(Vp,{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(),p===`location`?pt(t===`Ungrouped`?``:t):p===`status`?ft(t):p===`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 ${_>=3?`gap-6`:``} ${ot()}`,children:n.map(e=>(0,G.jsx)(mG,{printer:e,hideIfDisconnected:s,maintenanceInfo:Re[e.id],viewMode:O,cardSize:_,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 ${_>=3?`gap-6`:``} ${ot()}`,children:ut.map(e=>(0,G.jsx)(mG,{printer:e,hideIfDisconnected:s,maintenanceInfo:Re[e.id],viewMode:O,cardSize:_,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))}),_===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)(Io,{className:`w-4 h-4`}),e(`common.back`,`Back`)]}),a&&(0,G.jsx)(IOe,{onClose:()=>o(!1),onAdd:e=>Be.mutate(e),existingSerials:ce?.map(e=>e.serial_number)||[]}),Xe&&ce&&(0,G.jsx)(Bee,{selectedIds:He,printers:ce,onClose:Qe,onSelectAll:dt,onSelectByLocation:pt,onSelectByState:ft,onAction:et,actionPending:Je}),Ke===`stop`&&(0,G.jsx)(Xd,{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)(Xd,{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)(Xd,{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)(Lse,{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 HOe({title:e,message:t,subtitle:n,closeText:r,variant:i=`error`,onClose:a}){let{t:o}=U(),s=r??o(`common.close`);return(0,y.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)(jd,{className:`w-full max-w-md`,onClick:e=>e.stopPropagation(),children:(0,G.jsxs)(Nd,{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)(Nu,{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 hG=(0,y.createContext)(null),UOe=1500,WOe=1e3,gG=e=>`slice-job-${e}`;function _G(e){try{return decodeURIComponent(e)}catch{return e}}function GOe(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 KOe({children:e}){let{t}=U(),{showToast:n,showPersistentToast:r,dismissToast:i}=zd(),a=so(),[o,s]=(0,y.useState)([]),[c,l]=(0,y.useState)(null),u=(0,y.useRef)([]);u.current=o;let d=(0,y.useRef)(new Map),f=(0,y.useRef)(new Map),p=(0,y.useRef)(new Map),m=(0,y.useRef)(new Set),h=(0,y.useCallback)(e=>{let n=d.current.get(e.id);if(n==null)return;let i=(Date.now()-n)/1e3,a=f.current.get(e.id)??`pending`,o=GOe(i),s=p.current.get(e.id)??null,c=s&&s.stage&&s.total_percent>0;if(a===`running`&&c){let n=_G(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(gG(e.id),c,`loading`);return}let l=a===`pending`?`slice.queuedToast`:`slice.runningToast`,u=a===`pending`?`Queued: {{name}} — {{elapsed}}`:`Slicing {{name}} — {{elapsed}}`;r(gG(e.id),t(l,u,{name:_G(e.sourceName),elapsed:o}),`loading`)},[r,t]),g=(0,y.useCallback)((e,t,n)=>{s(r=>r.some(t=>t.id===e)?r:[...r,{id:e,kind:t,sourceName:n}]),m.current.delete(e),d.current.set(e,Date.now()),f.current.set(e,`pending`),p.current.set(e,null),h({id:e,kind:t,sourceName:n})},[h]),_=(0,y.useCallback)((e,r)=>{m.current.has(e.id)||(m.current.add(e.id),s(t=>t.filter(t=>t.id!==e.id)),d.current.delete(e.id),f.current.delete(e.id),p.current.delete(e.id),i(gG(e.id)),r.status===`completed`?(n(t(`slice.completedToast`,`Sliced {{name}}`,{name:_G(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:_G(e.sourceName),detail:r.error_detail||t(`slice.failed`)}),a.invalidateQueries({queryKey:[`library-files`]}),a.invalidateQueries({queryKey:[`archives`]}))},[i,a,n,t]);return(0,y.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;f.current.set(n.id,t.status),t.progress&&p.current.set(n.id,t.progress),(t.status===`completed`||t.status===`failed`)&&_(n,t)}catch{}}finally{t=!1}}},UOe);return()=>{e=!0,clearInterval(n)}},[o.length,_]),(0,y.useEffect)(()=>{if(o.length===0)return;let e=setInterval(()=>{for(let e of u.current)h(e)},WOe);return()=>clearInterval(e)},[o.length,h]),(0,G.jsxs)(hG.Provider,{value:{trackJob:g,activeJobs:o},children:[e,c&&(0,G.jsx)(HOe,{title:t(`slice.failedTitle`),subtitle:c.name,message:c.detail,onClose:()=>l(null)})]})}function vG(){let e=(0,y.useContext)(hG);if(!e)throw Error(`useSliceJobTracker must be used inside SliceJobTrackerProvider`);return e}var yG=1024;function qOe(){let[e,t]=(0,y.useState)(()=>typeof window<`u`?window.innerWidth>=yG:!1);return(0,y.useEffect)(()=>{let e=window.matchMedia(`(min-width: ${yG}px)`),n=e=>{t(e.matches)};return t(e.matches),e.addEventListener(`change`,n),()=>e.removeEventListener(`change`,n)},[]),e}function bG({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)(Qu,{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:ud(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)(Uc,{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?``:` • ${Yf(e.print_time_seconds)}`]})]})]},e.index))})})]})})}var xG=e=>typeof e==`object`&&!!e&&`enumKey`in e,SG=`enum:`;function CG(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 wG(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 JOe(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 YOe=[`->`,`||`,`&&`,`==`,`!=`,`<=`,`>=`,`(`,`)`,`,`,`<`,`>`,`!`];function XOe(e){let t=[],n=0;for(;n0||W.vt_tray.length>0)&&r===`expanded`&&(()=>{let t=En.filter(e=>e.tray.length>1),n=En.filter(e=>e.tray.length===1),r=En.length>0&&W.vt_tray.length>0,g=!(r&&xe),_=e.nozzle_count===2||W?.temperatures?.nozzle_2!==void 0,v=pG[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)(wOe,{state:W.ams_filament_backup,onClick:()=>be(!0)}),(0,G.jsx)(`div`,{className:`flex-1 h-[2px] bg-bambu-dark-tertiary`}),r&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(TOe,{hidden:xe,onClick:Ce}),(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=XW(t.id,xn,wn,Cn);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)(dG,{ams:t,printerId:e.id,label:ap(t.id,t.tray.length),amsLabels:pn,canEdit:z(`printers:update`),onSaved:mn,children:(0,G.jsx)(`span`,{className:`block truncate text-[length:var(--pc-t10,10px)] text-white font-medium cursor-default select-none`,children:pn?.[t.id]||ap(t.id,t.tray.length)})}),n?.kind===`inlet`?(0,G.jsx)(YW,{inlet:n.inlet,title:F(`printers.amsSwitchInletTooltip`,{inlet:n.inlet,side:np[n.inlet]})}):_&&n?.kind===`nozzle`?(0,G.jsx)(JW,{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)(tG,{humidity:t.humidity,goodThreshold:a?.humidityGood,fairThreshold:a?.humidityFair,onClick:()=>Nt({amsId:t.id,amsLabel:ap(t.id,t.tray.length),mode:`humidity`}),compact:!0}),t.temp!=null&&(0,G.jsx)(`div`,{className:`mr-1`,children:(0,G.jsx)(nG,{temp:t.temp,goodThreshold:a?.tempGood,fairThreshold:a?.tempFair,onClick:()=>Nt({amsId:t.id,amsLabel:ap(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?ar.mutate(t.id):Ze===t.id?Qe(null):yt(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(pOe(t.dry_sf_reason)):F(`printers.drying.start`),children:(0,G.jsx)(dc,{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-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)(dc,{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:()=>ar.mutate(t.id),disabled:ar.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)(Qu,{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,g=rG(r),_=t.id*4+n,v=kn===_,y=An!==null&&An===_,b=jn!==null&&jn===_,S=r?.tray_info_idx?cn?.[r.tray_info_idx]:null,C=ln?.[_],T=(r?.tray_uuid||r?.tag_uid||Cp(e.serial_number,t.id,n))?.toUpperCase(),E=T?s?.[T]:void 0,D=bp(E),O=o&&!m?p?.find(r=>r.printer_id===e.id&&r.ams_id===t.id&&r.tray_id===n):void 0,k=O?f?.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=u?.(e.id,t.id,n),M=(()=>{let e=j?.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})(),N=M===0&&i&&r.remain>0?null:M,P=D??A??N??(i?r.remain:null),I=D!==null||A!==null?`spoolman`:N===null?i?`ams`:void 0:`inventory`,L=r?.tray_type?{vendor:Np(r)?`Bambu Lab`:`Generic`,profile:C?.preset_name||(k?[k.brand,k.slicer_filament_name?.split(`@`)[0].trim()||k.material].filter(Boolean).join(` `).trim():null)||j?.spool?.slicer_filament_name||S?.name||r.tray_sub_brands||r.tray_type,colorName:gf(r.tray_color||``),colorHex:r.tray_color||null,kFactor:qW(r.k),fillLevel:P,trayUuid:r.tray_uuid||null,tagUid:r.tag_uid||null,fillSource:I}:null,R=Fr?.amsId===t.id&&Fr?.slotId===n,B=w.indexOf(_),V=B>=0?`P${B+1}`:null,ee=(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:`↓`}),V&&(0,G.jsx)(`span`,{"aria-label":F(`printers.activeJobSlot.ariaLabel`,{n:B+1}),title:F(`printers.activeJobSlot.title`,{n:B+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:V}),(0,G.jsx)(WW,{trayColor:r?.tray_color,trayType:r?.tray_type,isEmpty:a,emptyKind:g,slotNumber:n+1}),(0,G.jsx)(`div`,{className:`text-[length:var(--pc-t9,9px)] text-white font-bold truncate`,children:r?.tray_type||F(g===`reset`?`ams.slotUnconfigured`:`ams.slotEmpty`)}),(0,G.jsx)(`div`,{className:`mt-1 h-1.5 bg-black/30 rounded-full overflow-hidden`,children:P!==null&&P>=0&&!a&&r&&(0,G.jsx)(`div`,{className:`h-full rounded-full transition-all`,style:{width:`${P}%`,backgroundColor:yp(P)}})})]});return(0,G.jsxs)(`div`,{className:`relative group w-full`,style:x,children:[R&&(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)(Rl,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)] text-bambu-green animate-spin`})}),L?(0,G.jsx)(kU,{data:L,actions:gi({amsId:t.id,slotId:n,loadTrayId:t.id*4+n,isRefreshing:R}),spoolman:{enabled:o,linkedSpoolId:O?.spoolman_spool_id??(T?s?.[T]?.id:void 0),spoolmanUrl:c,syncMode:l,onLinkSpool:o&&!O&&!j?()=>{let r=(L.trayUuid||L.tagUid||Cp(e.serial_number,t.id,n)).toUpperCase();Lt({tagUid:L.tagUid||r,trayUuid:L.trayUuid||``,printerId:e.id,amsId:t.id,trayId:n})}:void 0,onUnlinkSpool:E?.id?()=>nr.mutate(E.id):void 0},inventory:(()=>{if(o){if(m)return;let i=O,a=k;return{assignedSpool:a?{id:a.id,material:a.material,brand:a.brand??null,color_name:a.color_name??null,remainingWeightGrams:a.label_weight?Math.max(0,Math.round(a.label_weight-a.weight_used)):void 0}:null,onAssignSpool:()=>zt({printerId:e.id,amsId:t.id,trayId:n,trayInfo:{type:r?.tray_type||L.profile,material:r?.tray_type??void 0,profile:L.profile,color:L.colorHex||``,location:`${ap(t.id,t.tray.length)} Slot ${n+1}`}}),onUnassignSpool:a&&!Np(r)?()=>h?.(a.id):void 0,isAssigned:!!i||Np(r)}}let i=u?.(e.id,t.id,n);return{assignedSpool:i?.spool?{id:i.spool.id,material:i.spool.material,brand:i.spool.brand,color_name:i.spool.color_name,remainingWeightGrams:Math.max(0,Math.round(i.spool.label_weight-i.spool.weight_used))}:null,onAssignSpool:()=>zt({printerId:e.id,amsId:t.id,trayId:n,trayInfo:{type:r?.tray_type||L.profile,material:r?.tray_type??void 0,profile:L.profile,color:L.colorHex||``,location:`${ap(t.id,t.tray.length)} Slot ${n+1}`}}),onUnassignSpool:i&&!Np(r)?()=>d?.(e.id,t.id,n):void 0,isAssigned:!!i||Np(r)}})(),configureSlot:{enabled:z(`printers:control`),onConfigure:()=>Vt({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:ip(t.id,r?.id??0,xn,wn),caliIdx:r?.cali_idx,savedPresetId:C?.preset_id})},children:ee}):(0,G.jsx)(AU,{kind:g??void 0,actions:gi({amsId:t.id,slotId:n,loadTrayId:t.id*4+n,isRefreshing:R}),configureSlot:{enabled:z(`printers:control`),onConfigure:()=>Vt({amsId:t.id,trayId:n,trayCount:t.tray.length,extruderId:ip(t.id,r?.id??0,xn,wn)})},onAssignSpool:()=>zt({printerId:e.id,amsId:t.id,trayId:n,trayInfo:{type:``,material:void 0,profile:``,color:``,location:`${ap(t.id,t.tray.length)} Slot ${n+1}`}}),children:ee})]},n)})})]},t.id)}),n.map(t=>{let n=XW(t.id,xn,wn,Cn),r=t.tray[0],i=r?.tray_type&&r.remain>=0,g=!r?.tray_type,v=rG(r),x=vp(t.id,r?.id??0,!1),C=kn===x,T=An!==null&&An===x,E=jn!==null&&jn===x,D=r?.tray_info_idx?cn?.[r.tray_info_idx]:null,O=ln?.[x],k=r?.id??0,A=(r?.tray_uuid||r?.tag_uid||Cp(e.serial_number,t.id,k))?.toUpperCase(),j=A?s?.[A]:void 0,M=bp(j),N=u?.(e.id,t.id,k),P=(()=>{let e=N?.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})(),I=P===0&&i&&r.remain>0?null:P,L=o&&!m?p?.find(n=>n.printer_id===e.id&&n.ams_id===t.id&&n.tray_id===k):void 0,R=L?f?.find(e=>e.id===L.spoolman_spool_id):void 0,B=R&&(R.label_weight??0)>0?Math.round(Math.max(0,(R.label_weight??0)-R.weight_used)/(R.label_weight??1)*100):null,V=M??B??I??(i?r.remain:null),ee=M!==null||B!==null?`spoolman`:I===null?i?`ams`:void 0:`inventory`,te=r?.tray_type?{vendor:Np(r)?`Bambu Lab`:`Generic`,profile:O?.preset_name||(R?[R.brand,R.slicer_filament_name?.split(`@`)[0].trim()||R.material].filter(Boolean).join(` `).trim():null)||N?.spool?.slicer_filament_name||D?.name||r.tray_sub_brands||r.tray_type,colorName:gf(r.tray_color||``),colorHex:r.tray_color||null,kFactor:qW(r.k),fillLevel:V,trayUuid:r.tray_uuid||null,tagUid:r.tag_uid||null,fillSource:ee}:null,ne=Fr?.amsId===t.id&&Fr?.slotId===k,re=w.indexOf(x),ie=re>=0?`P${re+1}`:null,ae=(0,G.jsxs)(`div`,{className:`relative w-full bg-bambu-dark-secondary rounded-lg p-1 text-center ${g?`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:`↓`}),ie&&(0,G.jsx)(`span`,{"aria-label":F(`printers.activeJobSlot.ariaLabel`,{n:re+1}),title:F(`printers.activeJobSlot.title`,{n:re+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:ie}),(0,G.jsx)(WW,{trayColor:r?.tray_color,trayType:r?.tray_type,isEmpty:g,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)(`div`,{className:`mt-1 h-1.5 bg-black/30 rounded-full overflow-hidden`,children:V!==null&&V>=0&&!g&&(0,G.jsx)(`div`,{className:`h-full rounded-full transition-all`,style:{width:`${V}%`,backgroundColor:yp(V)}})})]}),oe=y(11);return(0,G.jsxs)(`div`,{style:{flex:`1 1 ${oe}`,minWidth:oe,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)(dG,{ams:t,printerId:e.id,label:ap(t.id,t.tray.length),amsLabels:pn,canEdit:z(`printers:update`),onSaved:mn,children:(0,G.jsx)(`span`,{className:`block truncate text-[length:var(--pc-t10,10px)] text-white font-medium cursor-default select-none`,children:pn?.[t.id]||ap(t.id,t.tray.length)})}),n?.kind===`inlet`?(0,G.jsx)(YW,{inlet:n.inlet,title:F(`printers.amsSwitchInletTooltip`,{inlet:n.inlet,side:np[n.inlet]})}):_&&n?.kind===`nozzle`?(0,G.jsx)(JW,{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?ar.mutate(t.id):Ze===t.id?Qe(null):yt(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)(dc,{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 bg-amber-50 dark:bg-amber-500/10 px-2 py-1 text-[length:var(--pc-t9,9px)]`,children:[(0,G.jsx)(dc,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)] text-amber-600 dark:text-amber-400 shrink-0`}),t.dry_filament&&(0,G.jsx)(`span`,{className:`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})}),(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:()=>ar.mutate(t.id),disabled:ar.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)(Qu,{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:[ne&&(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)(Rl,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)] text-bambu-green animate-spin`})}),te?(0,G.jsx)(kU,{data:te,actions:gi({amsId:t.id,slotId:k,loadTrayId:t.id*4+k,isRefreshing:ne}),spoolman:{enabled:o,linkedSpoolId:L?.spoolman_spool_id??(A?s?.[A]?.id:void 0),spoolmanUrl:c,syncMode:l,onLinkSpool:o&&!L&&!N?()=>{let n=(te.trayUuid||te.tagUid||Cp(e.serial_number,t.id,k)).toUpperCase();Lt({tagUid:te.tagUid||n,trayUuid:te.trayUuid||``,printerId:e.id,amsId:t.id,trayId:k})}:void 0,onUnlinkSpool:j?.id?()=>nr.mutate(j.id):void 0},inventory:(()=>{if(o){if(m)return;let n=L,i=R;return{assignedSpool:i?{id:i.id,material:i.material,brand:i.brand??null,color_name:i.color_name??null,remainingWeightGrams:i.label_weight?Math.max(0,Math.round(i.label_weight-i.weight_used)):void 0}:null,onAssignSpool:()=>zt({printerId:e.id,amsId:t.id,trayId:k,trayInfo:{type:r?.tray_type||te.profile,material:r?.tray_type??void 0,profile:te.profile,color:te.colorHex||``,location:ap(t.id,t.tray.length)}}),onUnassignSpool:i&&!Np(r)?()=>h?.(i.id):void 0,isAssigned:!!n||Np(r)}}let n=u?.(e.id,t.id,k);return{assignedSpool:n?.spool?{id:n.spool.id,material:n.spool.material,brand:n.spool.brand,color_name:n.spool.color_name,remainingWeightGrams:Math.max(0,Math.round(n.spool.label_weight-n.spool.weight_used))}:null,onAssignSpool:()=>zt({printerId:e.id,amsId:t.id,trayId:k,trayInfo:{type:r?.tray_type||te.profile,material:r?.tray_type??void 0,profile:te.profile,color:te.colorHex||``,location:ap(t.id,t.tray.length)}}),onUnassignSpool:n&&!Np(r)?()=>d?.(e.id,t.id,k):void 0,isAssigned:!!n||Np(r)}})(),configureSlot:{enabled:z(`printers:control`),onConfigure:()=>Vt({amsId:t.id,trayId:k,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:ip(t.id,r?.id??0,xn,wn),caliIdx:r?.cali_idx,savedPresetId:O?.preset_id})},children:ae}):(0,G.jsx)(AU,{kind:v??void 0,actions:gi({amsId:t.id,slotId:k,loadTrayId:t.id*4+k,isRefreshing:ne}),configureSlot:{enabled:z(`printers:control`),onConfigure:()=>Vt({amsId:t.id,trayId:k,trayCount:t.tray.length,extruderId:ip(t.id,r?.id??0,xn,wn)})},onAssignSpool:()=>zt({printerId:e.id,amsId:t.id,trayId:k,trayInfo:{type:``,material:void 0,profile:``,color:``,location:ap(t.id,t.tray.length)}}),children:ae})]}),(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)(nG,{temp:t.temp,goodThreshold:a?.tempGood,fairThreshold:a?.tempFair,onClick:()=>Nt({amsId:t.id,amsLabel:ap(t.id,t.tray.length),mode:`temperature`}),compact:!0}),t.humidity!=null&&(0,G.jsx)(tG,{humidity:t.humidity,goodThreshold:a?.humidityGood,fairThreshold:a?.humidityFair,onClick:()=>Nt({amsId:t.id,amsLabel:ap(t.id,t.tray.length),mode:`humidity`}),compact:!0})]})]})]},t.id)}),W.vt_tray.length>0&&g&&(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=_&&kn===254?n===254&&W.active_extruder===1||n===255&&W.active_extruder===0:kn===n,i=n-254,a=_?F(n===254?`printers.extL`:`printers.extR`):``,g=t.tray_info_idx?cn?.[t.tray_info_idx]:null,v=ln?.[1020+i],y=(t.tray_uuid||t.tag_uid||Cp(e.serial_number,255,i))?.toUpperCase(),b=y?s?.[y]:void 0,S=bp(b),C=u?.(e.id,255,i),w=(()=>{let e=C?.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})(),T=t.tray_type&&t.remain>=0,E=w===0&&T&&t.remain>0?null:w,D=o&&!m?p?.find(t=>t.printer_id===e.id&&t.ams_id===255&&t.tray_id===i):void 0,O=D?f?.find(e=>e.id===D.spoolman_spool_id):void 0,k=O&&(O.label_weight??0)>0?Math.round(Math.max(0,(O.label_weight??0)-O.weight_used)/(O.label_weight??1)*100):null,A=S??k??E??(T?t.remain:null),j=S!==null||k!==null?`spoolman`:E===null?T?`ams`:void 0:`inventory`,M={vendor:Np(t)?`Bambu Lab`:`Generic`,profile:v?.preset_name||(O?[O.brand,O.slicer_filament_name?.split(`@`)[0].trim()||O.material].filter(Boolean).join(` `).trim():null)||C?.spool?.slicer_filament_name||g?.name||t.tray_sub_brands||t.tray_type||`Unknown`,colorName:gf(t.tray_color||``),colorHex:t.tray_color||null,kFactor:qW(t.k),fillLevel:A,trayUuid:t.tray_uuid||null,tagUid:t.tag_uid||null,fillSource:j},N=!t.tray_type,P=rG(t),I=(0,G.jsxs)(`div`,{className:`w-full bg-bambu-dark-secondary rounded-lg p-1 text-center ${N?`opacity-50`:``} ${r?`ring-2 ring-bambu-green ring-offset-1 ring-offset-bambu-dark`:``}`,children:[(0,G.jsx)(WW,{trayColor:t.tray_color,trayType:t.tray_type,isEmpty:N,emptyKind:P,slotNumber:_?n===254?`L`:`R`:i+1}),(0,G.jsx)(`div`,{className:`text-[length:var(--pc-t9,9px)] font-bold truncate ${N?`text-white/40`:`text-white`}`,children:t.tray_type||F(`ams.slotEmpty`)}),(0,G.jsx)(`div`,{className:`mt-1 h-1.5 bg-black/30 rounded-full overflow-hidden`,children:A!==null&&A>=0&&!N&&(0,G.jsx)(`div`,{className:`h-full rounded-full transition-all`,style:{width:`${A}%`,backgroundColor:yp(A)}})})]});return(0,G.jsx)(`div`,{className:`relative group w-full`,style:x,children:N?(0,G.jsx)(AU,{kind:P??void 0,actions:gi({amsId:255,slotId:i,loadTrayId:n,includeRfid:!1}),configureSlot:{enabled:z(`printers:control`),onConfigure:()=>Vt({amsId:255,trayId:i,trayCount:1,extruderId:_?+(n===254):void 0})},onAssignSpool:()=>zt({printerId:e.id,amsId:255,trayId:i,trayInfo:{type:``,material:void 0,profile:``,color:``,location:`External Slot ${i+1}`}}),children:I}):(0,G.jsx)(kU,{data:M,actions:gi({amsId:255,slotId:i,loadTrayId:n,includeRfid:!1}),spoolman:{enabled:o,linkedSpoolId:D?.spoolman_spool_id??(y?s?.[y]?.id:void 0),spoolmanUrl:c,syncMode:l,onLinkSpool:o&&!D&&!C?()=>{let t=(M.trayUuid||M.tagUid||Cp(e.serial_number,255,i)).toUpperCase();Lt({tagUid:M.tagUid||t,trayUuid:M.trayUuid||``,printerId:e.id,amsId:255,trayId:i})}:void 0,onUnlinkSpool:b?.id?()=>nr.mutate(b.id):void 0},inventory:(()=>{if(o){if(m)return;let n=D,r=O;return{assignedSpool:r?{id:r.id,material:r.material,brand:r.brand??null,color_name:r.color_name??null,remainingWeightGrams:r.label_weight?Math.max(0,Math.round(r.label_weight-r.weight_used)):void 0}:null,onAssignSpool:()=>zt({printerId:e.id,amsId:255,trayId:i,trayInfo:{type:t.tray_type||M.profile,material:t.tray_type??void 0,profile:M.profile,color:M.colorHex||``,location:a||F(`printers.external`)}}),onUnassignSpool:r&&!Np(t)?()=>h?.(r.id):void 0,isAssigned:!!n||Np(t)}}let n=u?.(e.id,255,i);return{assignedSpool:n?.spool?{id:n.spool.id,material:n.spool.material,brand:n.spool.brand,color_name:n.spool.color_name,remainingWeightGrams:Math.max(0,Math.round(n.spool.label_weight-n.spool.weight_used))}:null,onAssignSpool:()=>zt({printerId:e.id,amsId:255,trayId:i,trayInfo:{type:t.tray_type||M.profile,material:t.tray_type??void 0,profile:M.profile,color:M.colorHex||``,location:a||F(`printers.external`)}}),onUnassignSpool:n&&!Np(t)?()=>d?.(e.id,255,i):void 0,isAssigned:!!n||Np(t)}})(),configureSlot:{enabled:z(`printers:control`),onConfigure:()=>Vt({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:I})},n)})})]})]})]})})()]}),e.is_active!==!1&&!W?.connected&&r===`expanded`&&Kn&&hr,r===`expanded`&&(0,G.jsxs)(`div`,{className:`mt-auto`,children:[Pn&&(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)(ed,{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:Pn.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:In?.energy?.power!==null&&In?.energy?.power!==void 0?`${Math.round(In.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:()=>lr.mutate(!Pn.auto_off),disabled:lr.isPending||Pn.auto_off_executed||!z(`smart_plugs:control`),title:z(`smart_plugs:control`)?Pn.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`)?Pn.auto_off||Pn.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)(ks,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)]`})}),(0,G.jsx)(`button`,{onClick:()=>{In?.state===`ON`?fe(!0):ue(!0)},disabled:cr.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`)?In?.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`)?In?.state===`ON`?`Turn off`:`Turn on`:F(`printers.permission.noSmartPlugControl`),children:(0,G.jsx)(ed,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)]`})})]})]}),Fn&&Fn.length>0&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mt-2`,children:[(0,G.jsx)(Fc,{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:Fn.map(e=>{let t=e.ha_entity_id?.startsWith(`script.`);return(0,G.jsxs)(`button`,{onClick:()=>{t?ur.mutate({id:e.id,action:`on`}):me(e)},disabled:ur.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)(kl,{className:`w-[var(--pc-i25,0.625rem)] h-[var(--pc-i25,0.625rem)]`}),e.name]},e.id)})})]})]}),(0,G.jsx)(Yse,{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:[_i,(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:()=>mi(_),disabled:!W?.connected||!z(`camera:view`),title:z(`camera:view`)?F(_===`embedded`?`printers.openCameraOverlay`:`printers.openCameraWindow`):F(`printers.permission.noCamera`),className:`${pi} !rounded-r-none`,children:(0,G.jsx)(Vu,{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();At({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)(ds,{className:`w-3 h-3`})})]}),kt&&(0,G.jsx)(AT,{x:kt.x,y:kt.y,items:hi,onClose:()=>At(null)}),(0,G.jsx)(Q,{variant:`secondary`,size:`sm`,onClick:()=>se(!0),disabled:!yn||!z(`printers:files`),title:z(`printers:files`)?F(`printers.browseFiles`):F(`printers.permission.noFiles`),className:pi,children:(0,G.jsx)(Ac,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)]`})}),(0,G.jsxs)(Q,{size:`sm`,onClick:()=>Ue(!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)(Pl,{className:`w-[var(--pc-i4,1rem)] h-[var(--pc-i4,1rem)]`}),F(`common.print`)]})]})]})]})]}),(0,G.jsx)(FOe,{printerId:e.id,dryingActive:En.some(e=>(e.dry_time??0)>0),timeFormat:g})]}),oe&&(0,G.jsx)(kse,{printerId:e.id,printerName:e.name,onClose:()=>se(!1)}),He&&(0,G.jsx)(bW,{folderId:null,onClose:()=>Ue(!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=uG(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});Xe({id:t.id,filename:t.filename})}}),Ye&&(0,G.jsx)(HW,{mode:`create`,libraryFileId:Ye.id,archiveName:Ye.filename,initialSelectedPrinterIds:[e.id],onClose:()=>Xe(null),onSuccess:()=>Xe(null),cleanupLibraryAfterDispatch:!0}),H&&(0,G.jsx)(Wse,{printerId:e.id,printerName:e.name,onClose:()=>ce(!1)}),Ke&&(0,G.jsx)(Rp,{printerId:e.id,printerName:e.name,onClose:()=>qe(!1)}),We&&(0,G.jsx)(oOe,{printer:e,status:W,totalPrintHours:n?.total_print_hours,onClose:Je}),Wt&&(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,onClick:()=>Xr(),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:[Wt.needs_calibration?(0,G.jsx)(Kl,{className:`w-[var(--pc-i5,1.25rem)] h-[var(--pc-i5,1.25rem)] text-blue-500`}):Wt.is_empty?(0,G.jsx)(ys,{className:`w-[var(--pc-i5,1.25rem)] h-[var(--pc-i5,1.25rem)] text-green-500`}):(0,G.jsx)(Ts,{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`}),Wt.reference_count!==void 0&&Wt.max_references&&(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray bg-bambu-dark-tertiary px-2 py-1 rounded`,children:[Wt.reference_count,`/`,Wt.max_references,` refs`]})]}),(0,G.jsx)(`button`,{onClick:()=>Xr(),className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,G.jsx)(Qu,{className:`w-[var(--pc-i5,1.25rem)] h-[var(--pc-i5,1.25rem)]`})})]}),(0,G.jsxs)(`div`,{className:`p-4 space-y-4`,children:[Wt.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 ${Wt.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 ${Wt.is_empty?`text-green-700 dark:text-green-400`:`text-yellow-700 dark:text-yellow-400`}`,children:Wt.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(Wt.confidence*100),`% | `,F(`printers.plateDetection.difference`),`: `,Wt.difference_percent.toFixed(1),`%`]})]}),Wt.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:Wt.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:Wt.message})]}),Ur&&Ur.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:Ur.references.length,max:Ur.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:Ur.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:()=>$r(t.index),className:`absolute top-1 right-1 p-0.5 bg-red-500/80 rounded opacity-0 group-hover:opacity-100 transition-opacity`,title:F(`printers.plateDetection.deleteReference`),children:(0,G.jsx)(Qu,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)] text-white`})}),Gr?.index===t.index?(0,G.jsx)(`input`,{type:`text`,value:Gr.label,onChange:e=>Kr({...Gr,label:e.target.value}),onBlur:()=>Qr(t.index,Gr.label),onKeyDown:e=>{e.key===`Enter`&&Qr(t.index,Gr.label),e.key===`Escape`&&Kr(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:()=>Kr({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?Uf(t.timestamp)?.toLocaleDateString()??``:``})]},t.index))})]}),!Wt.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`})]}),Xt?(0,G.jsxs)(`div`,{className:`flex gap-1`,children:[(0,G.jsx)(Q,{variant:`ghost`,size:`sm`,onClick:()=>Zt(null),disabled:Qt,children:F(`common.cancel`)}),(0,G.jsx)(Q,{size:`sm`,onClick:ei,disabled:Qt,children:Qt?(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:()=>Zt(Wt.roi||{x:.15,y:.35,w:.7,h:.55}),children:[(0,G.jsx)(El,{className:`w-[var(--pc-i3,0.75rem)] h-[var(--pc-i3,0.75rem)] mr-1`}),F(`common.edit`)]})]}),Xt?(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:Xt.x,onChange:e=>Zt({...Xt,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(Xt.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:Xt.y,onChange:e=>Zt({...Xt,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(Xt.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:Xt.w,onChange:e=>Zt({...Xt,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(Xt.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:Xt.h,onChange:e=>Zt({...Xt,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(Xt.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((Wt.roi?.x||.15)*100),`%, Y=`,Math.round((Wt.roi?.y||.35)*100),`%, W=`,Math.round((Wt.roi?.w||.7)*100),`%, H=`,Math.round((Wt.roi?.h||.55)*100),`%`]})]})]}),(0,G.jsx)(`div`,{className:`flex justify-end gap-2 p-4`,children:Wt.needs_calibration?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Q,{variant:`ghost`,onClick:()=>Xr(),children:F(`common.cancel`)}),(0,G.jsx)(Q,{onClick:()=>Zr(),disabled:Jt,children:Jt?(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:()=>Zr(),disabled:Jt,children:Jt?`Adding...`:`Add Reference (${Ur?.references.length||0}/${Ur?.max_references||5})`}),(0,G.jsx)(Q,{onClick:()=>Xr(),children:`Close`})]})})]})}),le&&Pn&&(0,G.jsx)(Xd,{title:F(`printers.confirm.powerOnTitle`),message:F(`printers.confirm.powerOnMessage`,{name:e.name}),confirmText:F(`printers.confirm.powerOnButton`),variant:`default`,onConfirm:()=>{cr.mutate(`on`),ue(!1)},onCancel:()=>ue(!1)}),Ar&&(0,G.jsx)(Xd,{title:F(`printers.maintenance.confirmMidPrintTitle`),message:F(`printers.maintenance.confirmMidPrintMessage`,{name:e.name}),confirmText:F(`printers.maintenance.menuEnter`),variant:`danger`,onConfirm:()=>{kr.mutate(!1),jr(!1)},onCancel:()=>jr(!1)}),de&&Pn&&(0,G.jsx)(Xd,{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:()=>{cr.mutate(`off`),fe(!1)},onCancel:()=>fe(!1)}),pe&&(0,G.jsx)(Xd,{title:F(`printers.confirm.haToggleTitle`,{name:pe.name}),message:W?.state===`RUNNING`?F(`printers.confirm.haToggleWarning`,{name:e.name,entity:pe.ha_entity_id||pe.name}):F(`printers.confirm.haToggleMessage`,{entity:pe.ha_entity_id||pe.name}),confirmText:F(`printers.confirm.haToggleButton`),variant:W?.state===`RUNNING`?`danger`:`default`,onConfirm:()=>{ur.mutate({id:pe.id,action:`toggle`}),me(null)},onCancel:()=>me(null)}),we&&(0,G.jsx)(Xd,{title:F(`printers.confirm.stopTitle`),message:F(`printers.confirm.stopMessage`,{name:e.name}),confirmText:F(`printers.confirm.stopButton`),variant:`danger`,onConfirm:()=>{dr.mutate(),Te(!1)},onCancel:()=>Te(!1)}),Ee&&(0,G.jsx)(Xd,{title:F(`printers.confirm.pauseTitle`),message:F(`printers.confirm.pauseMessage`,{name:e.name}),confirmText:F(`printers.confirm.pauseButton`),variant:`default`,onConfirm:()=>{fr.mutate(),De(!1)},onCancel:()=>De(!1)}),Re&&(0,G.jsx)(Xd,{title:F(`printers.confirm.resumeTitle`),message:F(`printers.confirm.resumeMessage`,{name:e.name}),confirmText:F(`printers.confirm.resumeButton`),variant:`default`,onConfirm:()=>{pr.mutate(),ze(!1)},onCancel:()=>ze(!1)}),(0,G.jsx)(xT,{printerId:e.id,isOpen:Be,onClose:()=>Ve(!1)}),he&&(0,G.jsx)(Ree,{printerName:e.name,errors:W?.hms_errors||[],onClose:()=>ge(!1),printerId:e.id,hasPermission:z,runoutGuidance:Nn}),_e&&(0,G.jsx)(Gse,{printerName:e.name,detection:N,lastError:P,onClose:()=>ve(!1)}),ye&&W&&(0,G.jsx)(yDe,{isOpen:ye,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:sr.isPending,onToggle:e=>sr.mutate(e),onClose:()=>be(!1)}),Mt&&(0,G.jsx)(hDe,{isOpen:!!Mt,onClose:()=>Nt(null),printerId:e.id,printerName:e.name,amsId:Mt.amsId,amsLabel:Mt.amsLabel,initialMode:Mt.mode,thresholds:a}),Pt&&(0,G.jsx)(xDe,{isOpen:!!Pt,onClose:()=>Ft(null),printerId:e.id,printerName:e.name,initialKind:Pt.initialKind,availableKinds:Pt.availableKinds}),It&&(0,G.jsx)(jU,{isOpen:!!It,onClose:()=>Lt(null),tagUid:It.tagUid,trayUuid:It.trayUuid,printerId:It.printerId,amsId:It.amsId,trayId:It.trayId}),Rt&&(0,G.jsx)(NU,{isOpen:!!Rt,onClose:()=>zt(null),printerId:Rt.printerId,amsId:Rt.amsId,trayId:Rt.trayId,trayInfo:Rt.trayInfo,spoolmanEnabled:!!o}),Bt&&(0,G.jsx)(vW,{isOpen:!!Bt,onClose:()=>Vt(null),printerId:e.id,slotInfo:Bt,printerModel:uG(e.model)||void 0,nozzleDiameter:Mp(W,Bt.amsId),onSuccess:()=>{I.invalidateQueries({queryKey:[`slotPresets`,e.id]}),I.invalidateQueries({queryKey:[`printerStatus`,e.id]})}}),ie&&(0,G.jsx)(ROe,{printer:e,onClose:()=>ae(!1)}),Ht&&nn&&(0,G.jsx)(LOe,{printer:e,firmwareInfo:nn,onClose:()=>Ut(!1)}),Ze!==null&&ht&&(()=>{let e=$e===`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:()=>{xt.current=bt.current!==null&&document.activeElement===bt.current},onClick:()=>{if(xt.current){xt.current=!1;return}Qe(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:ht.left,...ht.placement===`above`?{bottom:`calc(100dvh - ${ht.anchorY}px)`,maxHeight:`${ht.anchorY-8}px`}:{top:ht.top,maxHeight:`calc(100dvh - ${ht.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)(dc,{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)(iG,{value:tt,options:Object.keys(S).map(e=>({value:e,label:e})),onChange:e=>{nt(e);let t=S[e];t&&(it(t[$e===`n3s`?`n3s`:`n3f`]),ot($e===`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)(`input`,{type:`number`,min:45,max:e,value:rt,onChange:t=>it(Math.min(e,Math.max(45,Number(t.target.value)||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:rt,onChange:t=>it(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)(`input`,{type:`number`,min:1,max:24,value:at,onChange:e=>ot(Math.min(24,Math.max(1,Number(e.target.value)||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:at,onChange:e=>ot(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=((Ze===null?void 0:En.find(e=>e.id===Ze))?.tray??[]).some(e=>e.state===11),t=st&&!e;return(0,G.jsx)(`button`,{type:`button`,onClick:()=>ct(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:()=>ut(e),className:`py-1 rounded-lg border text-[10px] font-medium transition-colors ${lt===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))}),lt===`delay`&&(0,G.jsx)(`div`,{className:`mt-1.5 grid grid-cols-4 gap-1`,children:uOe.map(e=>(0,G.jsx)(`button`,{type:`button`,"aria-pressed":dt===e,onClick:()=>ft(e),className:`py-1 rounded-lg border text-[10px] font-medium transition-colors ${dt===e?`bg-bambu-green border-bambu-green text-white`:`bg-bambu-dark border-bambu-dark-tertiary text-white hover:bg-bambu-dark-tertiary`}`,children:Qf(e/60)},e))}),lt===`at_time`&&(0,G.jsx)(`input`,{ref:bt,type:`datetime-local`,"data-testid":`drying-start-at`,value:pt,onChange:e=>mt(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(Ze!==null){let e=(En.find(e=>e.id===Ze)?.tray??[]).some(e=>e.state===11),t=st&&!e;if(lt===`now`)rr.mutate({amsId:Ze,temp:rt,duration:at,filament:tt,rotateTray:t});else{let e=Aee(lt,dt,pt);e&&ir.mutate({amsId:Ze,temp:rt,duration:at,filament:tt,rotateTray:t,startAfter:e})}}},disabled:rr.isPending||ir.isPending||lt===`at_time`&&!pt,"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:lt===`now`?rr.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:ht.left+ht.arrowLeft-5,top:ht.anchorY-5,...ht.placement===`above`?{borderRightWidth:1,borderBottomWidth:1}:{borderLeftWidth:1,borderTopWidth:1}}})]})})()]})}function IOe({onClose:e,onAdd:t,existingSerials:n}){let{t:r}=U(),[i,a]=(0,y.useState)({name:``,serial_number:``,ip_address:``,access_code:``,model:``,location:``,auto_archive:!0}),[o,s]=(0,y.useState)(!1),[c,l]=(0,y.useState)([]),[u,d]=(0,y.useState)(``),[f,p]=(0,y.useState)(!1),[m,h]=(0,y.useState)(!1),[g,_]=(0,y.useState)([]),[v,b]=(0,y.useState)(``),[x,S]=(0,y.useState)(``),[C,w]=(0,y.useState)(!1),[T,E]=(0,y.useState)({scanned:0,total:0}),[D,O]=(0,y.useState)(!1),[k,A]=(0,y.useState)(!1),[j,M]=(0,y.useState)(null);(0,y.useEffect)(()=>{md.getInfo().then(e=>{h(e.is_docker),e.subnets.length>0&&(_(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),p(!1),E({scanned:0,total:0});let e=C?x.trim():v,t=m||C;if(t&&C)try{localStorage.setItem(`bambuddy.discovery.customSubnet`,e)}catch{}try{if(t){await md.startSubnetScan(e);let t=setInterval(async()=>{try{let e=await md.getScanStatus();E({scanned:e.scanned,total:e.total}),l(await md.getDiscoveredPrinters()),e.running||(clearInterval(t),s(!1),p(!0))}catch(e){console.error(`Failed to get scan status:`,e)}},500)}else{await md.startDiscovery(10);let e=setInterval(async()=>{try{l(await md.getDiscoveredPrinters())}catch(e){console.error(`Failed to get discovered printers:`,e)}},1e3);setTimeout(async()=>{clearInterval(e);try{await md.stopDiscovery()}catch{}s(!1),p(!0);try{l(await md.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),p(!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:uG(e.model)}),l([])};return(0,y.useEffect)(()=>()=>{md.stopDiscovery().catch(()=>{}),md.stopSubnetScan().catch(()=>{})},[]),(0,y.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)(jd,{className:`w-full max-w-md my-auto max-h-[calc(100vh-2rem)] overflow-y-auto`,onClick:e=>e.stopPropagation(),children:(0,G.jsxs)(Nd,{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`)}),g.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__`:v,onChange:e=>{e.target.value===`__custom__`?w(!0):(w(!1),b(e.target.value))},disabled:o,children:[g.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:v,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(m?`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`}),(m||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)(Jl,{className:`w-4 h-4`}),r(m||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:[uG(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)(ds,{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(m||C?`printers.discovery.scanningSubnet`:`printers.discovery.scanningNetwork`)}),f&&!o&&c.length===0&&(0,G.jsx)(`p`,{className:`mt-2 text-sm text-bambu-gray text-center`,children:r(m||C?`printers.discovery.noPrintersFoundSubnet`:`printers.discovery.noPrintersFoundNetwork`)}),f&&!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)(vu,{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)(Nu,{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)(Lp,{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)(Rp,{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 LOe({printer:e,firmwareInfo:t,onClose:n}){let{t:r}=U(),i=so(),{showToast:a}=zd(),{hasPermission:o}=Td(),s=o(`firmware:update`),[c,l]=(0,y.useState)(null),[u,d]=(0,y.useState)(!1),[f,p]=(0,y.useState)(null),[m,h]=(0,y.useState)(t.update_available?t.latest_version:null),{data:g,isLoading:_}=K({queryKey:[`firmwarePrepare`,e.id,m],queryFn:()=>vd.prepareUpload(e.id,m??void 0),staleTime:3e4,enabled:!!m&&s&&!u}),v=q({mutationFn:()=>vd.startUpload(e.id,m??void 0),onSuccess:()=>{d(!0);let t=setInterval(async()=>{try{let n=await vd.getUploadStatus(e.id);l(n),(n.status===`complete`||n.status===`error`)&&(clearInterval(t),p(null),d(!1),n.status===`complete`&&(a(r(`printers.firmwareModal.uploadedToast`),`success`),i.invalidateQueries({queryKey:[`firmwareUpdate`,e.id]})))}catch{}},2e3);p(t)},onError:e=>{a(r(`printers.firmwareModal.uploadFailed`,{error:e.message}),`error`),d(!1)}});return(0,y.useEffect)(()=>()=>{f&&clearInterval(f)},[f]),(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50`,children:(0,G.jsx)(jd,{className:`w-full max-w-md mx-4`,children:(0,G.jsxs)(Nd,{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)(qs,{className:`w-5 h-5 text-orange-600 dark:text-orange-400`}):(0,G.jsx)(ys,{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=m?t.available_versions?.find(e=>e.version===m):null,n=m??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=m===e.version,a=t.current_version?See(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:()=>h(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)})})]}),m?_?(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`)]}):g&&!u&&!c?(0,G.jsx)(`div`,{className:`mb-4`,children:g.can_proceed?(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-green text-sm`,children:[(0,G.jsx)(Yo,{className:`w-4 h-4`}),r(`printers.firmwareModal.sdCardReady`)]}):(0,G.jsx)(`div`,{className:`space-y-1`,children:g.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)(_s,{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`)}),g?.can_proceed&&!u&&c?.status!==`complete`&&s&&(0,G.jsx)(Q,{onClick:()=>{l(null),v.mutate()},disabled:v.isPending,children:v.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)(qs,{className:`w-4 h-4 mr-2`}),r(`printers.firmwareModal.uploadFirmware`)]})})]})]})})})}function ROe({printer:e,onClose:t}){let{t:n}=U(),r=so(),{showToast:i}=zd(),[a,o]=(0,y.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,y.useState)(!1),[l,u]=(0,y.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,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]);let f=()=>{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)(jd,{className:`w-full max-w-md my-auto max-h-[calc(100vh-2rem)] overflow-y-auto`,onClick:e=>e.stopPropagation(),children:(0,G.jsxs)(Nd,{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)}f()},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)(Zu,{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)(Nu,{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)(Lp,{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:f,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 zOe(e){let{data:t}=K({queryKey:[`printerStatus`,e],queryFn:()=>Z.getPrinterStatus(e),refetchInterval:3e4});return!t?.connected}function BOe({printer:e,plug:t,onPowerOn:n,isPowering:r}){let i=zOe(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)(Nl,{className:`w-3 h-3`}),r?`...`:`On`]})]}):null}function VOe(){let{t:e}=U(),{resolvedMode:t,darkAccent:n,lightAccent:r}=Od(),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,y.useState)(!1),[s,c]=(0,y.useState)(()=>localStorage.getItem(`hideDisconnectedPrinters`)===`true`),[l,u]=(0,y.useState)(!1),[d,f]=(0,y.useState)(null),[p,m]=(0,y.useState)(()=>localStorage.getItem(`printerSortBy`)||`name`),[h,g]=(0,y.useState)(()=>localStorage.getItem(`printerSortAsc`)!==`false`),[_,v]=(0,y.useState)(()=>{let e=localStorage.getItem(`printerCardSize`);return e?parseInt(e,10):2}),[b,x]=(0,y.useState)(()=>localStorage.getItem(`printerPageView`)===`camwall`?`camwall`:`cards`),[S,C]=(0,y.useState)(()=>{let e=parseInt(localStorage.getItem(`camWallMaxLive`)||``,10);return Number.isFinite(e)&&e>0?e:4}),[w,T]=(0,y.useState)(()=>{let e=parseInt(localStorage.getItem(`camWallSnapshotSec`)||``,10);return Number.isFinite(e)&&e>0?e:8}),[E,D]=(0,y.useState)(()=>{let e=localStorage.getItem(`camWallStatusMode`);return e===`off`||e===`compact`||e===`full`?e:`full`}),O=_===1?`compact`:`expanded`,[k,A]=(0,y.useState)(null),j=(0,y.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,y.useCallback)(e=>{A(e),v(2),localStorage.setItem(`printerCardSize`,`2`),j(e)},[j]),N=(0,y.useCallback)(()=>{let e=k;A(null),v(1),localStorage.setItem(`printerCardSize`,`1`),e!=null&&j(e)},[k,j]),[P,F]=(0,y.useState)(``),[I,L]=(0,y.useState)(()=>{let e=localStorage.getItem(`printerStatusFilter`);return mOe(e)?e:`all`}),[R,z]=(0,y.useState)(()=>localStorage.getItem(`printerLocationFilter`)||`all`),[B,V]=(0,y.useState)(0),[ee,te]=(0,y.useState)(()=>{try{let e=localStorage.getItem(`printerCollapsedSections`);return e?JSON.parse(e):{}}catch{return{}}}),ne=so(),{showToast:re}=zd(),{hasPermission:ie}=Td(),[ae,oe]=(0,y.useState)(()=>Eee()),[se,H]=(0,y.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,y.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,y.useMemo)(()=>gm(ue?.nozzle_temp_presets,fm,0,320),[ue?.nozzle_temp_presets]),fe=(0,y.useMemo)(()=>gm(ue?.bed_temp_presets,pm,0,140),[ue?.bed_temp_presets]),pe=(0,y.useMemo)(()=>gm(ue?.chamber_temp_presets,mm,0,65),[ue?.chamber_temp_presets]),me=(0,y.useMemo)(()=>gm(ue?.fan_speed_presets,hm,0,100),[ue?.fan_speed_presets]),he=(0,y.useMemo)(()=>{if(ue?.drying_presets)try{let e=JSON.parse(ue.drying_presets);if(typeof e==`object`&&e&&Object.keys(e).length>0)return{...fG,...e}}catch{}return fG},[ue?.drying_presets]),ge=ae??(ue?.camera_view_mode===`embedded`?`embedded`:`window`),_e=(0,y.useCallback)(e=>{Dee(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,y.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 rd&&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`]}),f(null)},onError:()=>{f(null)}}),[He,Ue]=(0,y.useState)(new Set),[We,Ge]=(0,y.useState)(!1),[Ke,qe]=(0,y.useState)(null),[Je,Ye]=(0,y.useState)(!1),Xe=We||He.size>0,Ze=(0,y.useCallback)(e=>{Ue(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),Qe=(0,y.useCallback)(()=>{Ue(new Set),Ge(!1)},[]);(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&Xe&&Qe()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[Xe,Qe]);let $e=(0,y.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&&xm(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,y.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=>{m(e),localStorage.setItem(`printerSortBy`,e)},rt=e=>{L(e),localStorage.setItem(`printerStatusFilter`,e)},it=e=>{z(e),localStorage.setItem(`printerLocationFilter`,e)},at=()=>{let e=!h;g(e),localStorage.setItem(`printerSortAsc`,String(e))},ot=()=>{switch(_){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,y.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,y.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?xm(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,y.useMemo)(()=>ce?[...new Set(ce.map(e=>e.location||``).filter(Boolean))].sort():[],[ce]);(0,y.useEffect)(()=>{!ce||R===`all`||lt.includes(R)||(z(`all`),localStorage.setItem(`printerLocationFilter`,`all`))},[ce,lt,R]);let ut=(0,y.useMemo)(()=>{let e=[...ct];switch(p){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?xm(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 h||e.reverse(),e},[ct,p,h,ne]),dt=(0,y.useCallback)(()=>{Ue(new Set(ut.map(e=>e.id))),Ge(!0)},[ut]),ft=(0,y.useCallback)(e=>{Ue(t=>{let n=new Set(t);return ut.forEach(t=>{lG(ne.getQueryData([`printerStatus`,t.id]))===e&&n.add(t.id)}),n}),Ge(!0)},[ut,ne]),pt=(0,y.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,y.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,y.useCallback)(e=>{te(t=>{let n={...t,[e]:!t[e]};try{localStorage.setItem(`printerCollapsedSections`,JSON.stringify(n))}catch{}return n})},[]),gt=(0,y.useMemo)(()=>{if(p===`name`||p===`eta`)return null;let e={};return p===`location`?ut.forEach(t=>{let n=t.location||`Ungrouped`;e[n]||(e[n]=[]),e[n].push(t)}):p===`model`?ut.forEach(t=>{let n=t.model||`Unknown`;e[n]||(e[n]=[]),e[n].push(t)}):p===`status`&&ut.forEach(t=>{let n=lG(ne.getQueryData([`printerStatus`,t.id]));e[n]||(e[n]=[]),e[n].push(t)}),e},[p,ut,ne,B]),_t=(0,y.useRef)(null),vt=(0,y.useRef)(null),yt=(0,y.useRef)(0),[bt,xt]=(0,y.useState)(!1),St=(0,y.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,y.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)(iG,{value:I,onChange:rt,fullWidth:t,options:KW.map(t=>({value:t.value,label:e(t.labelKey)}))}),ce&&ce.length>0&<.length>0&&(0,G.jsx)(iG,{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)(iG,{value:p,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(h?`printers.sort.descending`:`printers.sort.ascending`),children:h?(0,G.jsx)(Vo,{className:`w-4 h-4 text-white`}):(0,G.jsx)(Fo,{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)(Wc,{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)(dl,{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)(Ai,{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)(ec,{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=_===i;return(0,G.jsx)(`button`,{onClick:()=>{A(null),v(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)(mu,{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)(Nl,{className:`w-4 h-4`}),e(`printers.powerOn`)]}),(0,G.jsx)(ds,{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)(BOe,{printer:e,plug:ze[e.id],onPowerOn:e=>{f(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)(jl,{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)(Pl,{className:`w-7 h-7 text-bambu-green`}),e(`printers.title`)]}),(0,G.jsx)(OOe,{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)(Jl,{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)(Qu,{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)(aG,{label:e(`printers.toolbar.filters`,`Filters`),icon:(0,G.jsx)(bc,{className:`w-4 h-4`}),children:(0,G.jsx)(`div`,{className:`flex w-48 flex-col gap-2`,children:wt(!0)})}),(0,G.jsx)(aG,{label:e(`printers.toolbar.view`,`View`),icon:(0,G.jsx)(cu,{className:`w-4 h-4`}),children:(0,G.jsx)(`div`,{className:`flex w-48 flex-col gap-2`,children:Tt(!0)})}),(0,G.jsx)(aG,{label:e(`printers.toolbar.actions`,`Actions`),icon:(0,G.jsx)(Zs,{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)(jd,{children:(0,G.jsxs)(Nd,{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)(jl,{className:`w-4 h-4`}),e(`printers.addPrinter`)]})]})}):ut.length===0&&(P.trim()||I!==`all`||R!==`all`)?(0,G.jsx)(jd,{children:(0,G.jsx)(Nd,{className:`text-center py-12`,children:(0,G.jsx)(`p`,{className:`text-bambu-gray`,children:e(`printers.noSearchResults`)})})}):b===`camwall`?(0,G.jsx)(kT,{printers:ut,maxLive:S,snapshotIntervalSec:w,onTileClick:(e,t)=>{ge===`embedded`?H(n=>new Map(n).set(e,{id:e,name:t})):im(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=p===`status`?AOe.filter(e=>gt[e]?.length>0):Object.keys(gt);return h?e:[...e].reverse()})().map(t=>{let n=gt[t],r=`${p}:${t}`,i=!ee[r],a=p===`status`&&cG[t]?.dot||`bg-bambu-green`,o=p===`status`?e(cG[t]?.labelKey||t):t;return(0,G.jsx)(Vp,{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(),p===`location`?pt(t===`Ungrouped`?``:t):p===`status`?ft(t):p===`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 ${_>=3?`gap-6`:``} ${ot()}`,children:n.map(e=>(0,G.jsx)(mG,{printer:e,hideIfDisconnected:s,maintenanceInfo:Re[e.id],viewMode:O,cardSize:_,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 ${_>=3?`gap-6`:``} ${ot()}`,children:ut.map(e=>(0,G.jsx)(mG,{printer:e,hideIfDisconnected:s,maintenanceInfo:Re[e.id],viewMode:O,cardSize:_,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))}),_===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)(Io,{className:`w-4 h-4`}),e(`common.back`,`Back`)]}),a&&(0,G.jsx)(IOe,{onClose:()=>o(!1),onAdd:e=>Be.mutate(e),existingSerials:ce?.map(e=>e.serial_number)||[]}),Xe&&ce&&(0,G.jsx)(Bee,{selectedIds:He,printers:ce,onClose:Qe,onSelectAll:dt,onSelectByLocation:pt,onSelectByState:ft,onAction:et,actionPending:Je}),Ke===`stop`&&(0,G.jsx)(Xd,{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)(Xd,{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)(Xd,{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)(Lse,{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 HOe({title:e,message:t,subtitle:n,closeText:r,variant:i=`error`,onClose:a}){let{t:o}=U(),s=r??o(`common.close`);return(0,y.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)(jd,{className:`w-full max-w-md`,onClick:e=>e.stopPropagation(),children:(0,G.jsxs)(Nd,{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)(Nu,{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 hG=(0,y.createContext)(null),UOe=1500,WOe=1e3,gG=e=>`slice-job-${e}`;function _G(e){try{return decodeURIComponent(e)}catch{return e}}function GOe(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 KOe({children:e}){let{t}=U(),{showToast:n,showPersistentToast:r,dismissToast:i}=zd(),a=so(),[o,s]=(0,y.useState)([]),[c,l]=(0,y.useState)(null),u=(0,y.useRef)([]);u.current=o;let d=(0,y.useRef)(new Map),f=(0,y.useRef)(new Map),p=(0,y.useRef)(new Map),m=(0,y.useRef)(new Set),h=(0,y.useCallback)(e=>{let n=d.current.get(e.id);if(n==null)return;let i=(Date.now()-n)/1e3,a=f.current.get(e.id)??`pending`,o=GOe(i),s=p.current.get(e.id)??null,c=s&&s.stage&&s.total_percent>0;if(a===`running`&&c){let n=_G(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(gG(e.id),c,`loading`);return}let l=a===`pending`?`slice.queuedToast`:`slice.runningToast`,u=a===`pending`?`Queued: {{name}} — {{elapsed}}`:`Slicing {{name}} — {{elapsed}}`;r(gG(e.id),t(l,u,{name:_G(e.sourceName),elapsed:o}),`loading`)},[r,t]),g=(0,y.useCallback)((e,t,n)=>{s(r=>r.some(t=>t.id===e)?r:[...r,{id:e,kind:t,sourceName:n}]),m.current.delete(e),d.current.set(e,Date.now()),f.current.set(e,`pending`),p.current.set(e,null),h({id:e,kind:t,sourceName:n})},[h]),_=(0,y.useCallback)((e,r)=>{m.current.has(e.id)||(m.current.add(e.id),s(t=>t.filter(t=>t.id!==e.id)),d.current.delete(e.id),f.current.delete(e.id),p.current.delete(e.id),i(gG(e.id)),r.status===`completed`?(n(t(`slice.completedToast`,`Sliced {{name}}`,{name:_G(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:_G(e.sourceName),detail:r.error_detail||t(`slice.failed`)}),a.invalidateQueries({queryKey:[`library-files`]}),a.invalidateQueries({queryKey:[`archives`]}))},[i,a,n,t]);return(0,y.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;f.current.set(n.id,t.status),t.progress&&p.current.set(n.id,t.progress),(t.status===`completed`||t.status===`failed`)&&_(n,t)}catch{}}finally{t=!1}}},UOe);return()=>{e=!0,clearInterval(n)}},[o.length,_]),(0,y.useEffect)(()=>{if(o.length===0)return;let e=setInterval(()=>{for(let e of u.current)h(e)},WOe);return()=>clearInterval(e)},[o.length,h]),(0,G.jsxs)(hG.Provider,{value:{trackJob:g,activeJobs:o},children:[e,c&&(0,G.jsx)(HOe,{title:t(`slice.failedTitle`),subtitle:c.name,message:c.detail,onClose:()=>l(null)})]})}function vG(){let e=(0,y.useContext)(hG);if(!e)throw Error(`useSliceJobTracker must be used inside SliceJobTrackerProvider`);return e}var yG=1024;function qOe(){let[e,t]=(0,y.useState)(()=>typeof window<`u`?window.innerWidth>=yG:!1);return(0,y.useEffect)(()=>{let e=window.matchMedia(`(min-width: ${yG}px)`),n=e=>{t(e.matches)};return t(e.matches),e.addEventListener(`change`,n),()=>e.removeEventListener(`change`,n)},[]),e}function bG({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)(Qu,{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:ud(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)(Uc,{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?``:` • ${Yf(e.print_time_seconds)}`]})]})]},e.index))})})]})})}var xG=e=>typeof e==`object`&&!!e&&`enumKey`in e,SG=`enum:`;function CG(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 wG(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 JOe(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 YOe=[`->`,`||`,`&&`,`==`,`!=`,`<=`,`>=`,`(`,`)`,`,`,`<`,`>`,`!`];function XOe(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 ZOe=new Set([`opt_bool`,`opt_int`,`opt_float`,`opt_float_nullable`,`opt_int_nullable`,`opt_bool_nullable`,`opt_enum`,`opt_string`,`option`,`has`]),QOe=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=XOe(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=wG(e),r=wG(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=wG(e),r=wG(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 $Oe(e,this.parseUnary(),t,this.schema);return e}parseUnary(){if(this.eatOp(`!`)){let e=wG(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?`${SG}${e.value}`:this.resolveLocal(e.value,t)}parseConfigAccess(){if(!this.eatOp(`->`))return;let e=this.peek();if(!e||e.kind!==`id`||!ZOe.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 $Oe(e,t,n,r){let i=typeof e==`string`&&e.startsWith(SG)?e:typeof t==`string`&&t.startsWith(SG)?t:void 0;if(i!==void 0){if(n!==`==`&&n!==`!=`)return;let a=i===e?t:e;if(!xG(a))return;let o=r[a.enumKey]?.enum_values;if(!o||a.value===void 0)return;let s=eke(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=xG(e)?e.value:e,o=xG(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):CG(a)===CG(o);return n===`==`?e:!e}let s=CG(a),c=CG(o);if(!(s===void 0||c===void 0)){if(n===`<`)return s`)return s>c;if(n===`>=`)return s>=c}}function eke(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 tke(e,t,n){let r=JOe(e,t),i=new Map,a=new Set;for(let e of n.rules){let o=nke(e.enable_if);if(o&&wG(new QOe(r,n.locals,t,new Set,i).evaluate(o))===!1)for(let t of e.fields)a.add(t)}return a}function nke(e){let t=0;for(let n=0;nrke.has(e.type);function TG(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 ake(e){let t=e.sidetext;if(!(!t||t.includes(`->`)||t.includes(`::`)))return t}function oke(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 EG(e,t){if(ike(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 ske(e,t){let n={};for(let[r,i]of Object.entries(e)){let e=t[r];e&&(n[r]=EG(e,i))}return n}function DG(e,t,n){if(t===void 0||t===``)return!1;let r=t=>{let n=EG(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 cke=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`]),lke=[`simple`,`advanced`,`expert`],OG={simple:0,advanced:1,expert:2,develop:3};function uke({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,f]=(0,y.useState)(null),[p,m]=(0,y.useState)(`simple`),[h,g]=(0,y.useState)(null),[_,v]=(0,y.useState)(``);(0,y.useEffect)(()=>{let e=!1;return Promise.all([Pt(()=>import(`./process-schema-CzfeynAH.js`),[]),Pt(()=>import(`./process-ui-tree-BWrKRLV6.js`),[]),Pt(()=>import(`./process-toggle-rules-DDBax3G5.js`),[])]).then(([t,n,r])=>{e||f({schema:t.default??t,tree:n.default??n,toggles:r.default??r})}),()=>{e=!0}},[]);let b=(0,y.useMemo)(()=>d?tke(e,d.schema,d.toggles):new Set,[d,e]),x=(0,y.useMemo)(()=>new Map(r.map(e=>[e.key,e])),[r]),S=(0,y.useMemo)(()=>d?r.filter(e=>!d.schema[e.key]):[],[d,r]),C=e=>{if(!d)return;let n={};for(let[t,r]of Object.entries(e))d.schema[t]&&DG(d.schema[t],r,s?.[t])&&(n[t]=r);t(e,ske(n,d.schema))},w=(t,n)=>{let r={...e};n===void 0?delete r[t]:r[t]=n,C(r)},T=(0,y.useMemo)(()=>{if(!d)return[];let e=e=>e.toLowerCase().replace(/[_\s]+/g,` `).trim(),t=e(_),n=e=>OG[d.schema[e]?.mode??`expert`]<=OG[p],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,p,_]),E=(0,y.useMemo)(()=>T.length===0||_.trim()?null:T.find(e=>e.page===h)??T[0],[T,h,_]),D=(0,y.useMemo)(()=>d?Object.keys(e).filter(t=>d.schema[t]&&DG(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 O=E?[E]:T;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:lke.map(e=>(0,G.jsx)(`button`,{type:`button`,onClick:()=>m(e),disabled:n,className:`px-2.5 py-1 text-xs capitalize transition-colors ${p===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)(Jl,{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:_,onChange:e=>v(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`})]}),D>0&&(0,G.jsxs)(`button`,{type:`button`,onClick:()=>C({}),disabled:n,className:`flex items-center gap-1 text-xs text-bambu-gray hover:text-white`,children:[(0,G.jsx)(Bl,{className:`w-3 h-3`}),u(`slicerSettings.resetAll`,`Reset {{count}}`,{count:D})]})]}),!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.`)}),!_.trim()&&(0,G.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:T.map(e=>(0,G.jsx)(`button`,{type:`button`,onClick:()=>g(e.page),disabled:n,className:`px-2 py-1 text-xs rounded transition-colors ${E?.page===e.page?`bg-bambu-dark-tertiary text-white`:`text-bambu-gray hover:text-white`}`,children:e.page},e.page))}),O.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:[O.map(t=>(0,G.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[_.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)(dke,{optionKey:t,option:d.schema[t],value:e[t],onChange:e=>w(t,e),disabled:n||b.has(t),disabledBySlicer:b.has(t),source:x.get(t),sourceOn:i?.has(t)??!1,onToggleSource:a,filamentChoices:cke.has(t)?o:void 0,presetValue:s?.[t]},t))]},`${t.page}:${r.group}`))]},t.page)),S.length>0&&!_.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`)}),S.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:kG(e.value)})]}),e.printer_coupled&&(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:u(`slicerSettings.fromFilePrinterCoupled`,`designer's printer`)})]},e.key))]})]})]})}function dke({optionKey:e,option:t,value:n,onChange:r,disabled:i,disabledBySlicer:a,source:o,sourceOn:s=!1,onToggleSource:c,filamentChoices:l,presetValue:u}){let{t:d}=U(),f=DG(t,n,u),p=ake(t),m=n===void 0?s&&o?kG(o.value):oke(t,u):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}),f&&(0,G.jsx)(`span`,{className:`shrink-0 text-bambu-green`,"aria-hidden":`true`,children:`•`}),o&&(0,G.jsx)(`span`,{className:`shrink-0 rounded px-1 py-0.5 text-[10px] ${o.printer_coupled?`bg-amber-100 text-amber-700 dark:bg-amber-500/20 dark:text-amber-400`:`bg-bambu-green/15 text-bambu-green`}`,title:o.printer_coupled?d(`slicerSettings.fromFilePrinterCoupledHint`,`Tuned for the printer this file was designed for -- may be wrong or out of range on yours.`):d(`slicerSettings.fromFileHint`,`The designer changed this in the source file. Its value is {{value}}.`,{value:kG(o.value)}),children:o.printer_coupled?d(`slicerSettings.fromFilePrinterCoupled`,`designer's printer`):d(`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:o&&c&&(0,G.jsx)(`input`,{type:`checkbox`,checked:s,disabled:i,onChange:t=>c(e,t.target.checked),"aria-label":d(`slicerSettings.useFromFile`,`Use the source file's value for {{option}}`,{option:t.label||e}),title:d(`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)(fke,{id:`slicer-opt-${e}`,option:t,current:m,onChange:r,disabled:i,filamentChoices:l})}),(0,G.jsx)(`span`,{className:`w-16 shrink-0 whitespace-nowrap text-[0.65rem] text-bambu-gray/60`,children:p??``}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>r(void 0),disabled:i||!f,"aria-label":d(`slicerSettings.resetOption`,`Reset to default`),className:`p-0.5 transition-opacity ${f?`text-bambu-gray hover:text-white`:`opacity-0 pointer-events-none`}`,children:(0,G.jsx)(Bl,{className:`w-3 h-3`})})]})]})}function kG(e){return Array.isArray(e)?e.map(e=>String(e)).join(`, `):e==null?``:String(e)}function fke({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)(ds,{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)(ds,{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:TG(t.min),max:TG(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 AG=[`local`,`orca_cloud`,`cloud`,`standard`],pke={local:1.75,orca_cloud:1.5,cloud:1,standard:.5};function jG(e,t){for(let n of AG){let r=e[n][t];if(r.length>0)return{source:r[0].source,id:r[0].id}}return null}function MG(e,t,n){return t?e[t.source][n].find(e=>e.id===t.id)??null:null}function NG(e,t,n){if(!n)return null;for(let r of AG){let i=e[r][t].find(e=>e.name===n);if(i)return{source:i.source,id:i.id}}return null}function mke(e,t,n,r){let i=NG(e,`process`,r);if(i){let r=MG(e,i,`process`);if(r&&HU(r,`process`,t,n)!==`mismatch`)return i}for(let r of[`match`,`unknown`])for(let i of AG)for(let a of e[i].process)if(HU(a,`process`,t,n)===r)return{source:a.source,id:a.id};return jG(e,`process`)}function hke(e,t,n,r){let i=t.type.trim().toUpperCase(),a=tp(t.color),o=null,s=null;for(let c of AG)for(let l of e[c].filament){let e=0,u=(l.filament_type??``).trim().toUpperCase(),d=tp(l.filament_colour??``);i&&u&&i===u&&(e+=10),a&&d&&(d===a?e+=5:up(l.filament_colour??``,t.color)&&(e+=2)),e+=pke[c];let f={source:l.source,id:l.id};HU(l,`filament`,n,r)===`mismatch`?(s==null||e>s.score)&&(s={ref:f,score:e}):(o==null||e>o.score)&&(o={ref:f,score:e})}return o==null?s==null?jG(e,`filament`):s.ref:o.ref}function PG(e){return e?`${e.source}:${e.id}`:``}function gke(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 _ke({requestId:e,sourceName:t}){let{t:n}=U(),{showPersistentToast:r,dismissToast:i}=zd(),[a,o]=(0,y.useState)(0),[s,c]=(0,y.useState)(null),l=t;try{l=decodeURIComponent(t)}catch{}(0,y.useEffect)(()=>{let e=Date.now(),t=setInterval(()=>o(Math.floor((Date.now()-e)/1e3)),1e3);return()=>clearInterval(t)},[]),(0,y.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,y.useEffect)(()=>{let e=s&&s.stage&&s.total_percent>0,t=vke(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,f=s?.total_percent,p=d&&typeof f==`number`&&f>0?`${d} (${Math.min(100,Math.max(0,Math.round(f)))}%)`: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`}),p,(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 vke(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 FG({source:e,onClose:t}){let{t:n}=U(),{trackJob:r}=vG(),i=so(),[a,o]=(0,y.useState)(null),[s,c]=(0,y.useState)(null),[l,u]=(0,y.useState)([]),[d,f]=(0,y.useState)(null),[p,m]=(0,y.useState)(null),[h,g]=(0,y.useState)(!1),[_,v]=(0,y.useState)(null),[b,x]=(0,y.useState)(!1),[S,C]=(0,y.useState)(!1),[w,T]=(0,y.useState)(!1),[E,D]=(0,y.useState)(new Set),[O,k]=(0,y.useState)({}),[A,j]=(0,y.useState)({}),[M,N]=(0,y.useState)(!1),P=qOe(),F=P||M,I=K({queryKey:[`slicer-pipelines`],queryFn:()=>Z.listSlicerPipelines(),staleTime:6e4}),[L,R]=(0,y.useState)(!1),[z,B]=(0,y.useState)(``),{showToast:V}=zd(),ee=q({mutationFn:e=>Z.createSlicerPipeline(e),onSuccess:()=>{i.invalidateQueries({queryKey:[`slicer-pipelines`]}),V(n(`slice.pipelines.toast.saved`,`Pipeline saved`),`success`),R(!1),B(``)},onError:e=>{V(e.message||n(`slice.pipelines.toast.saveFailed`,`Save failed`),`error`)}}),te=K({queryKey:[`slicePlates`,e.kind,e.id],queryFn:async()=>e.kind===`libraryFile`?Z.getLibraryFilePlates(e.id):Z.getArchivePlates(e.id),staleTime:6e4}),ne=!!te.data?.is_multi_plate&&(te.data?.plates?.length??0)>1,re=ne&&p==null,ie=p??1,ae=(0,y.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${ie}-${t}`},[e.kind,e.id,ie]),oe=K({queryKey:[`sliceFilamentReqs`,e.kind,e.id,ie],queryFn:async()=>e.kind===`libraryFile`?Z.getLibraryFileFilamentRequirements(e.id,ie,ae,!0):Z.getArchiveFilamentRequirements(e.id,ie,ae,!0),enabled:!re,staleTime:6e4}),se=(0,y.useMemo)(()=>{let e=oe.data?.filaments??[],t=e.length>0?e:[{slot_id:1,type:``,color:``,used_grams:0,used_meters:0}];return h?t.map(e=>({...e,used_in_plate:!0})):t},[h,oe.data]),H=K({queryKey:[`slicerPresets`],queryFn:()=>Z.getSlicerPresets(),staleTime:6e4,enabled:!te.isLoading&&!re}),[ce,le]=(0,y.useState)(!1),ue=async()=>{if(!ce){le(!0);try{let e=await Z.getSlicerPresets({refresh:!0});i.setQueryData([`slicerPresets`],e)}catch{i.invalidateQueries({queryKey:[`slicerPresets`]})}finally{le(!1)}}},de=K({queryKey:[`slicerPrinterModels`],queryFn:Z.getSlicerPrinterModels,staleTime:1/0}),fe=(0,y.useMemo)(()=>!H.data||!a?null:MG(H.data,a,`printer`)?.name??null,[H.data,a]),pe=(0,y.useMemo)(()=>IU(de.data??{}),[de.data]),me=K({queryKey:[`slicer-preset-values`,s?.source,s?.id],queryFn:()=>Z.getSlicerPresetValues(s),enabled:s!=null,staleTime:5*6e4}),he=me.data?.values,ge=me.data?.resolved??me.isLoading,_e=me.data?.reason??(me.isError?`sidecar_unavailable`:void 0),ve=(0,y.useMemo)(()=>{let e=H.data;return se.map((t,r)=>{let i=l[r]??null,a=e&&i?MG(e,i,`filament`):null;return{index:r+1,label:a?.name||t.type||n(`slice.filamentSlotUnset`,`not set`),color:t.color||void 0}})},[se,l,H.data,n]),ye=te.data?.embedded_printer??null,be=(0,y.useMemo)(()=>te.data?.design_overrides??[],[te.data]),xe=te.data?.embedded_process??null,Se=(0,y.useMemo)(()=>{if(!ye||!xe||!fe)return!1;let e=e=>e.replace(/^#\s*/,``).trim().toLowerCase();return e(fe)===e(ye)},[ye,xe,fe]);(0,y.useEffect)(()=>{Se||x(!1)},[Se]),(0,y.useEffect)(()=>{D(new Set(be.filter(e=>!e.printer_coupled).map(e=>e.key)))},[be]),(0,y.useEffect)(()=>{let e=H.data;e&&(a??o(NG(e,`printer`,ye)??jG(e,`printer`)))},[H.data,ye]),(0,y.useEffect)(()=>{let e=H.data;e&&c(t=>{if(t){let n=MG(e,t,`process`);if(n&&HU(n,`process`,fe,pe)!==`mismatch`)return t}return mke(e,fe,pe,xe)})},[H.data,fe,pe,xe]),(0,y.useEffect)(()=>{let e=H.data;e&&u(t=>se.map((n,r)=>{let i=t[r]??null;if(i){let t=MG(e,i,`filament`);if(t&&HU(t,`filament`,fe,pe)!==`mismatch`)return i}return hke(e,{type:n.type,color:n.color},fe,pe)}))},[H.data,se,fe,pe]);let Ce=q({mutationFn:async t=>{let n=we(t);return e.kind===`libraryFile`?Z.sliceLibraryFile(e.id,n):Z.sliceArchive(e.id,n)},onSuccess:n=>{r(n.job_id,e.kind,e.filename),t()},onError:e=>{f(e instanceof Error?e.message:String(e))}});function we(e){if(!a||!s||l.length===0||l.some(e=>e==null))throw Error(n(`slice.allPresetsRequired`));return{printer_preset:a,process_preset:s,filament_preset:l[0],filament_presets:l,...e==null?{}:{plate:e},..._==null?{}:{bed_type:_},...b&&Se?{use_embedded_settings:!0}:{},...!b&&E.size>0?{design_overrides:[...E]}:{},...!b&&Object.keys(O).length>0?{process_overrides:A}:{},...S?{auto_orient:!0}:{},...w?{auto_arrange:!0}:{}}}let Te=a!=null&&s!=null&&oe.isSuccess&&l.length>0&&l.every(e=>e!=null),Ee=Ce.isPending,De=te.data?.plates?.length??0,Oe=ne&&De>1&&!re;return re&&te.data?(0,G.jsx)(bG,{plates:te.data.plates,onSelect:e=>m(e),onClose:t}):(0,G.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-4`,onClick:()=>{Ee||t()},children:(0,G.jsxs)(`div`,{className:`w-full max-w-xl lg:max-w-5xl 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)(Is,{className:`w-4 h-4`}),n(`slice.title`)]}),(0,G.jsxs)(`p`,{className:`text-xs text-bambu-gray mt-1 truncate`,title:e.filename,children:[e.filename,p==null?``:` • ${n(`archives.platePicker.plateLabel`,{index:p})}`]})]}),(0,G.jsx)(`button`,{onClick:t,disabled:Ee,className:`flex-shrink-0 text-bambu-gray hover:text-white transition-colors disabled:opacity-50`,"aria-label":n(`common.close`),children:(0,G.jsx)(Qu,{className:`w-5 h-5`})})]}),(0,G.jsxs)(`div`,{className:`flex-1 overflow-y-auto p-4 space-y-4`,children:[(te.isLoading||H.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`}),n(`slice.loadingPresets`)]}),H.isError&&(0,G.jsx)(`div`,{className:`text-sm text-red-700 dark:text-red-400`,role:`alert`,children:n(`slice.presetsLoadFailed`,`Failed to load presets. Open Settings → Profiles to import them, or sign in to Bambu Cloud.`)}),H.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)(IG,{status:H.data.cloud_status,cloudName:`bambu`}),(0,G.jsx)(IG,{status:H.data.orca_cloud_status,cloudName:`orca`})]}),(0,G.jsxs)(`button`,{type:`button`,onClick:ue,disabled:ce||Ee,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:n(`slice.refreshPresetsTitle`),"aria-label":n(`slice.refreshPresets`),children:[(0,G.jsx)(Rl,{className:`w-3.5 h-3.5 ${ce?`animate-spin`:``}`}),n(`slice.refreshPresets`)]})]}),(0,G.jsxs)(`div`,{className:`lg:grid lg:grid-cols-[minmax(0,20rem)_minmax(0,1fr)] 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)(Is,{className:`w-3.5 h-3.5`}),` `,n(`slice.pipelines.label`,`Pipeline`)]}),(0,G.jsxs)(`select`,{value:``,disabled:Ee||(I.data?.pipelines.length??0)===0,onChange:e=>{let t=parseInt(e.target.value,10);if(Number.isNaN(t))return;let r=I.data?.pipelines.find(e=>e.id===t);r&&(o(r.printer_preset),c(r.process_preset),v(r.bed_type),u(e=>{let t=e.length>0?[...e]:r.filament_presets.map(()=>null);for(let e=0;e(0,G.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),L?(0,G.jsxs)(`div`,{className:`flex items-center gap-1 flex-1 min-w-[16ch]`,children:[(0,G.jsx)(`input`,{autoFocus:!0,value:z,onChange:e=>B(e.target.value),placeholder:n(`slice.pipelines.namePlaceholder`,`Pipeline name`),"aria-label":n(`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=z.trim();if(!e||!a||!s)return;let t=l.filter(e=>e!==null);t.length!==0&&ee.mutate({name:e,printer_preset:a,process_preset:s,filament_presets:t,bed_type:_})},disabled:ee.isPending||!z.trim(),className:`text-xs px-2 py-1 bg-bambu-green hover:bg-bambu-green/80 text-white rounded disabled:opacity-50`,children:ee.isPending?(0,G.jsx)(Y,{className:`w-3 h-3 animate-spin`}):n(`common.save`,`Save`)}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>{R(!1),B(``)},className:`text-xs px-2 py-1 text-bambu-gray hover:text-white`,children:n(`common.cancel`,`Cancel`)})]}):(0,G.jsx)(`button`,{type:`button`,onClick:()=>{B(``),R(!0)},disabled:Ee||!a||!s||l.length===0||l.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:n(`slice.pipelines.saveTitle`,`Save the current four-slot selection as a reusable pipeline`),children:n(`slice.pipelines.saveButton`,`Save as pipeline`)})]}),(0,G.jsx)(LG,{label:n(`slice.printer`),slot:`printer`,data:H.data,value:a,onChange:o,disabled:Ee||b}),Se&&(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:b,onChange:e=>x(e.target.checked),disabled:Ee,className:`mt-0.5 cursor-pointer`}),(0,G.jsxs)(`span`,{children:[n(`slice.useEmbedded`),(0,G.jsx)(`span`,{className:`block text-xs text-bambu-gray/70`,children:n(`slice.useEmbeddedHint`)})]})]}),(0,G.jsx)(LG,{label:n(`slice.process`),slot:`process`,data:H.data,value:s,onChange:c,disabled:Ee||b,selectedPrinterName:fe,compatIndex:pe}),(0,G.jsx)(bke,{value:_,onChange:v,disabled:Ee||b}),(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:S,onChange:e=>C(e.target.checked),disabled:Ee,className:`mt-0.5 cursor-pointer`}),(0,G.jsxs)(`span`,{children:[n(`slice.autoOrient`),(0,G.jsx)(`span`,{className:`block text-xs text-bambu-gray/70`,children:n(`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:w,onChange:e=>T(e.target.checked),disabled:Ee,className:`mt-0.5 cursor-pointer`}),(0,G.jsxs)(`span`,{children:[n(`slice.autoArrange`),(0,G.jsx)(`span`,{className:`block text-xs text-bambu-gray/70`,children:n(`slice.autoArrangeHint`)})]})]})]}),oe.isLoading?(0,G.jsx)(_ke,{requestId:ae,sourceName:e.filename}):se.map((e,t)=>{let r=e.used_in_plate!==!1,i=se.length>1?n(`slice.filamentSlot`,{index:t+1,type:e.type}):n(`slice.filament`);return(0,G.jsx)(LG,{label:r?i:`${i} ${n(`slice.notUsedByPlate`)}`,slot:`filament`,data:H.data,value:l[t]??null,onChange:e=>u(n=>{let r=n.length===se.length?[...n]:se.map((e,t)=>n[t]??null);return r[t]=e,r}),disabled:Ee||!r||b,swatchColor:se.length>1?e.color:void 0,selectedPrinterName:fe,compatIndex:pe},`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 ${b?`opacity-60`:``}`,children:[(0,G.jsxs)(`button`,{type:`button`,onClick:()=>N(e=>!e),"aria-expanded":F,disabled:P,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:[n(`slice.processSettings`,`Process settings`),(0,G.jsx)(`span`,{className:`block text-xs text-bambu-gray/70`,children:b?n(`slice.processSettingsEmbedded`,`Not used while "Use the file's built-in settings" is on -- the file's own settings drive this slice.`):n(`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:b?n(`slice.processSettingsInactive`,`Inactive`):Object.keys(A).length>0?n(`slice.processSettingsChanged`,`{{count}} changed`,{count:Object.keys(A).length}):n(`slice.processSettingsUnchanged`,`Preset defaults`)})]}),F&&(0,G.jsx)(`div`,{className:`mt-3 border-t border-bambu-dark-tertiary pt-3`,children:(0,G.jsx)(uke,{values:O,onChange:(e,t)=>{k(e),j(t)},disabled:Ee||b,filamentChoices:ve,presetValues:he,presetValuesResolved:ge,presetValuesReason:_e,sourceOverrides:be,sourceSelected:E,onToggleSource:(e,t)=>D(n=>{let r=new Set(n);return t?r.add(e):r.delete(e),r})})})]})})]})]}),d&&(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:d})]}),(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:Ee,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:n(`common.cancel`)}),Oe&&(0,G.jsxs)(`label`,{className:`flex items-center gap-2 mr-auto text-sm text-bambu-gray cursor-pointer select-none`,title:n(`slice.actionAllTitle`,{count:De}),children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:h,onChange:e=>g(e.target.checked),disabled:Ee,className:`cursor-pointer`}),n(`slice.allPlatesToggle`,{count:De})]}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>{f(null);let e=h?0:p;Ce.mutate(e)},disabled:!Te||Ee,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:Ee?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),n(`slice.enqueuing`)]}):h?n(`slice.actionAll`,{count:De}):n(`slice.action`)})]})]})})}function IG({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:As},unreachable:{tone:`border-bambu-dark-tertiary/40 bg-bambu-dark text-bambu-gray`,icon:As}}[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 yke=[{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 bke({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:`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:r(`slice.bedType.auto`)}),yke.map(e=>(0,G.jsx)(`option`,{value:e.value,children:r(e.labelKey,e.fallback)},e.value))]})]})}function LG({label:e,slot:t,data:n,value:r,onChange:i,disabled:a,swatchColor:o,selectedPrinterName:s,compatIndex:c}){let{t:l}=U(),[u,d]=(0,y.useState)(!1),f=(0,y.useId)(),{sections:p,otherEntries:m}=(0,y.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=[];for(let{key:o,label:u,fallback:d}of e){let e=n[o][t];if(!r){e.length>0&&i.push({tierLabel:l(u,d),entries:e});continue}let f=[];for(let n of e)HU(n,t,s??null,c??CDe)===`mismatch`?a.push(n):f.push(n);f.length>0&&i.push({tierLabel:l(u,d),entries:f})}return{sections:i,otherEntries:a}},[n,t,l,s,c]),h=PG(r),g=(0,y.useMemo)(()=>u?m:m.filter(e=>`${e.source}:${e.id}`===h),[u,m,h]),_=m.length-g.length,v=p.reduce((e,t)=>e+t.entries.length,0)+g.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:[o&&(0,G.jsx)(`span`,{className:`inline-block w-3 h-3 rounded-full border border-bambu-dark-tertiary`,style:{backgroundColor:o||`transparent`},"aria-hidden":!0}),(0,G.jsx)(`label`,{htmlFor:f,children:e}),(_>0||u)&&(0,G.jsxs)(`span`,{className:`ml-auto flex items-center gap-1.5 font-normal`,children:[_>0&&(0,G.jsx)(`span`,{className:`text-bambu-gray/60`,children:l(`slice.presetsHidden`,`{{count}} hidden`,{count:_})}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>d(e=>!e),disabled:a,className:`text-bambu-green hover:underline disabled:opacity-50 disabled:no-underline`,children:u?l(`slice.showFewerPresets`,`Show fewer`):l(`slice.showAllPresets`,`Show all`)})]})]}),(0,G.jsxs)(`select`,{id:f,value:PG(r),onChange:e=>i(gke(e.target.value)),disabled:a||v===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:l(v===0?`slice.noPresetsForSlot`:`slice.selectPreset`)}),p.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)),g.length>0&&(0,G.jsx)(`optgroup`,{label:l(`slice.otherPrinters`),children:g.map(e=>(0,G.jsx)(`option`,{value:`${e.source}:${e.id}`,children:e.name},`${e.source}:${e.id}`))})]})]})}function RG({source:e,onClose:t}){let{t:n}=U(),r=so(),{showToast:i}=zd(),[a,o]=(0,y.useState)(null),[s,c]=(0,y.useState)(null),[l,u]=(0,y.useState)(1),{trackJob:d}=vG(),{data:f,isLoading:p}=K({queryKey:[`slicer-pipelines`],queryFn:()=>Z.listSlicerPipelines()}),{data:m}=K({queryKey:[`printers`],queryFn:()=>Z.getPrinters()}),{data:h}=K({queryKey:[`app-settings`],queryFn:()=>Z.getSettings()}),g=h?.pipeline_max_copies??50,_={kind:e.kind,id:e.id},v=q({mutationFn:e=>Z.checkPipelineEligibility(e,_)}),b=q({mutationFn:({pipelineId:e,force:t})=>Z.runPipeline(e,_,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=f?.pipelines??[],S=(m??[]).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)(kl,{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)(Qu,{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)(Ske,{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)(xke,{source:e,pipelines:x,printerById:S,loading:p||v.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 v.mutateAsync(e.id);c(t),t.ok&&b.mutate({pipelineId:e.id,force:!1})}catch{o(null)}},copies:l,maxCopies:g,onCopiesChange:u})})]})})}function xke({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)(Is,{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)(Pl,{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 Ske({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)(Nu,{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)(Cke,{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)(kl,{className:`w-3 h-3`}),o(`library.runWithPipeline.runAnyway`,`Run anyway`)]})]})]})}function Cke({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 zG(e,t){return e??t??`bambu_studio`}var BG=[`3mf`,`stl`,`step`,`stp`],VG=[`3mf`,`stl`];function wke(e){let t=(e||``).toLowerCase();return BG.includes(t)}function HG(e){let t=e.toLowerCase();return t.endsWith(`.gcode`)||t.endsWith(`.gcode.3mf`)?!1:BG.some(e=>t.endsWith(`.${e}`))}function UG(e){let t=e.toLowerCase();return t.endsWith(`.gcode`)||t.endsWith(`.gcode.3mf`)?!1:VG.some(e=>t.endsWith(`.${e}`))}function Tke(){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 WG(e,t=`bambu_studio`){let n,r=encodeURIComponent(e);n=t===`orcaslicer`?`orcaslicer://open?file=${r}`:Tke()===`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 Eke(e){let t=(e||``).toLowerCase();return VG.includes(t)}var Dke=[[`projects`],[`project`],[`project-archives`],[`project-timeline`],[`project-file-progress`]];function Oke(e){return Promise.all(Dke.map(t=>e.invalidateQueries({queryKey:[...t]})))}function GG(e){return Promise.all([e.invalidateQueries({queryKey:[`archives`]}),Oke(e)])}function KG({onFiles:e,onRejected:t,extensions:n,disabled:r=!1}){let[i,a]=(0,y.useState)(!1),o=(0,y.useRef)(e),s=(0,y.useRef)(t),c=(0,y.useRef)(n);(0,y.useEffect)(()=>{o.current=e},[e]),(0,y.useEffect)(()=>{s.current=t},[t]),(0,y.useEffect)(()=>{c.current=n},[n]);let l=(0,y.useCallback)(e=>{r||(e.preventDefault(),e.dataTransfer.types.includes(`Files`)&&a(!0))},[r]),u=(0,y.useCallback)(e=>{r||(e.preventDefault(),e.dataTransfer.types.includes(`Files`)&&a(!0))},[r]),d=(0,y.useCallback)(e=>{if(r)return;e.preventDefault();let t=e.currentTarget,n=e.relatedTarget;(!n||!t.contains(n))&&a(!1)},[r]),f=(0,y.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,y.useEffect)(()=>{if(!i)return;let e=()=>a(!1),t=t=>{t.key===`Escape`&&e()};return document.addEventListener(`drop`,e),document.addEventListener(`dragend`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`drop`,e),document.removeEventListener(`dragend`,e),document.removeEventListener(`keydown`,t)}},[i]),{isDraggingOver:i,dragHandlers:{onDragOver:l,onDragEnter:u,onDragLeave:d,onDrop:f}}}function kke({onClose:e,initialFiles:t}){let{t:n}=U(),r=so(),{showToast:i}=zd(),a=(0,y.useRef)(null),[o,s]=(0,y.useState)(()=>t?.filter(e=>e.name.endsWith(`.3mf`)).map(e=>({file:e,status:`pending`}))||[]),[c,l]=(0,y.useState)(!1),[u,d]=(0,y.useState)(null);(0,y.useEffect)(()=>{let t=t=>{t.key===`Escape`&&e()};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e]);let f=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`)}}),p=(0,y.useCallback)(e=>{e.preventDefault(),l(!0)},[]),m=(0,y.useCallback)(e=>{e.preventDefault(),l(!1)},[]),h=(0,y.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`}))])},[]),g=(0,y.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=``)},[]),_=(0,y.useCallback)(e=>{s(t=>t.filter((t,n)=>n!==e))},[]),v=()=>{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)),f.mutate(e.map(e=>e.file)))},b=o.filter(e=>e.status===`pending`).length,x=f.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)(jd,{className:`w-full max-w-2xl max-h-[90vh] flex flex-col`,children:(0,G.jsxs)(Nd,{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)(Qu,{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:p,onDragLeave:m,onDrop:h,children:[(0,G.jsx)(Lu,{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:g})]})}),(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)(lc,{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:()=>_(t),className:`text-bambu-gray hover:text-red-600 dark:hover:text-red-400 transition-colors`,disabled:x,children:(0,G.jsx)(Qu,{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)(ys,{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)(_s,{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:v,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)(Lu,{className:`w-4 h-4`}),n(`uploadModal.upload`),` `,b>0&&`(${b})`]})})]})]})})})}var Ake=365;function jke({onClose:e,initialDays:t}){let{t:n}=U(),r=so(),{showToast:i}=zd(),[a,o]=(0,y.useState)(t??Ake),[s,c]=(0,y.useState)(!1),[l,u]=(0,y.useState)(a);(0,y.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}),f=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,y.useEffect)(()=>{let t=t=>{t.key===`Escape`&&!f.isPending&&e()};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e,f.isPending]);let p=d.data,m=p?.count??0,h=p?.total_bytes??0,g=m>0&&!f.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)(Au,{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:f.isPending,children:(0,G.jsx)(Qu,{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:m,size:Ld(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:n(`archivePurge.andMore`,{count:m-p.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:f.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)(Nu,{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:f.isPending,children:n(`common.cancel`)}),(0,G.jsx)(Q,{variant:`danger`,disabled:!g,onClick:()=>f.mutate(),children:f.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:m})})]})]})})}function Mke(e){if(!e||e<=0)return`—`;let t=Math.floor(e/3600),n=Math.floor(e%3600/60);return t>0?`${t}h ${n}m`:`${n}m`}function Nke(e){if(!e)return`—`;let t=Uf(e);return t?t.toLocaleString():`—`}function qG({archiveId:e}){let{t}=U(),{data:n,isLoading:r}=K({queryKey:[`archive-runs`,e],queryFn:()=>Z.getArchiveRuns(e)});if(r)return(0,G.jsx)(`div`,{className:`flex justify-center py-4`,children:(0,G.jsx)(Y,{className:`w-5 h-5 text-bambu-gray animate-spin`})});let i=n?.items||[];return i.length===0?(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray italic py-2`,children:t(`archives.runLog.empty`)}):(0,G.jsx)(`div`,{className:`overflow-x-auto`,children:(0,G.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,G.jsx)(`thead`,{children:(0,G.jsxs)(`tr`,{className:`text-bambu-gray border-b border-bambu-dark-tertiary`,children:[(0,G.jsx)(`th`,{className:`text-left py-1.5 pr-2 font-medium`,children:t(`archives.runLog.col.date`)}),(0,G.jsx)(`th`,{className:`text-left py-1.5 pr-2 font-medium`,children:t(`archives.runLog.col.status`)}),(0,G.jsx)(`th`,{className:`text-right py-1.5 pr-2 font-medium`,children:t(`archives.runLog.col.duration`)}),(0,G.jsx)(`th`,{className:`text-right py-1.5 pr-2 font-medium`,children:t(`archives.runLog.col.filament`)}),(0,G.jsx)(`th`,{className:`text-right py-1.5 font-medium`,children:t(`archives.runLog.col.cost`)})]})}),(0,G.jsx)(`tbody`,{children:i.map(e=>{let n=e.status===`completed`?`text-bambu-green`:e.status===`failed`?`text-red-700 dark:text-red-400`:`text-bambu-gray`;return(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/40 last:border-0`,children:[(0,G.jsx)(`td`,{className:`py-1.5 pr-2 text-bambu-gray-light`,children:Nke(e.started_at||e.created_at)}),(0,G.jsxs)(`td`,{className:`py-1.5 pr-2 font-medium ${n}`,children:[t(`archives.runLog.status.${e.status}`,{defaultValue:e.status}),e.failure_reason&&(0,G.jsx)(`span`,{className:`block text-[10px] text-bambu-gray font-normal`,children:t(`editArchive.failureReasons.${e.failure_reason}`,{defaultValue:e.failure_reason})})]}),(0,G.jsx)(`td`,{className:`py-1.5 pr-2 text-right text-bambu-gray-light`,children:Mke(e.duration_seconds)}),(0,G.jsx)(`td`,{className:`py-1.5 pr-2 text-right text-bambu-gray-light`,children:e.filament_used_grams==null?`—`:`${e.filament_used_grams.toFixed(1)} g`}),(0,G.jsx)(`td`,{className:`py-1.5 text-right text-bambu-gray-light`,children:e.cost==null?`—`:e.cost.toFixed(2)})]},e.id)})})]})})}var JG=[`adhesionFailure`,`spaghettiDetached`,`layerShift`,`cloggedNozzle`,`filamentRunout`,`warping`,`stringing`,`underExtrusion`,`powerFailure`,`userCancelled`,`other`],Pke=[`completed`,`failed`,`aborted`,`printing`];function YG({archive:e,onClose:t,existingTags:n=[]}){let{t:r}=U();(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]);let i=so(),[a,o]=(0,y.useState)(e.print_name||``),[s,c]=(0,y.useState)(e.printer_id),[l,u]=(0,y.useState)(e.project_id??null),[d,f]=(0,y.useState)(e.notes||``),[p,m]=(0,y.useState)(e.tags||``),[h,g]=(0,y.useState)(()=>{let t=e.failure_reason||``;return t?JG.includes(t)?t:JG.find(e=>r(`editArchive.failureReasons.${e}`)===t)||``:``}),[_,v]=(0,y.useState)(e.status),[b,x]=(0,y.useState)(e.quantity??1),[S,C]=(0,y.useState)(e.photos||[]),[w,T]=(0,y.useState)(e.external_url||``),[E,D]=(0,y.useState)(!1),[O,k]=(0,y.useState)(!1),A=(0,y.useRef)(null),j=(0,y.useRef)(null),M=(0,y.useRef)(null),{data:N}=K({queryKey:[`printers`],queryFn:Z.getPrinters}),{data:P}=K({queryKey:[`projects`],queryFn:()=>Z.getProjects(),select:e=>[...e].sort((e,t)=>e.name.localeCompare(t.name))}),{data:F}=K({queryKey:[`tags`],queryFn:Z.getTags,enabled:n.length===0}),I=n.length>0?n:F?.map(e=>e.name)||[],L=p.split(`,`).map(e=>e.trim()).filter(Boolean),R=p.includes(`,`)?p.substring(p.lastIndexOf(`,`)+1).trim().toLowerCase():p.trim().toLowerCase(),z=I.filter(e=>!L.includes(e)&&(R===``||e.toLowerCase().includes(R))),B=e=>{let t;t=R&&!I.includes(R)?p.includes(`,`)?p.substring(0,p.lastIndexOf(`,`)).split(`,`).map(e=>e.trim()).filter(Boolean):[]:L,t.includes(e)||m([...t,e].join(`, `)),M.current!==null&&clearTimeout(M.current),A.current?.focus()},V=e=>{m(L.filter(t=>t!==e).join(`, `))},ee=q({mutationFn:t=>Z.updateArchive(e.id,t),onSuccess:()=>{GG(i),t()}}),te=async t=>{let n=t.target.files?.[0];if(n){D(!0);try{C((await Z.uploadArchivePhoto(e.id,n)).photos),i.invalidateQueries({queryKey:[`archives`]})}catch(e){console.error(`Failed to upload photo:`,e)}finally{D(!1),j.current&&(j.current.value=``)}}},ne=async t=>{try{C((await Z.deleteArchivePhoto(e.id,t)).photos||[]),i.invalidateQueries({queryKey:[`archives`]})}catch(e){console.error(`Failed to delete photo:`,e)}};return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:t,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-md max-h-[90vh] flex flex-col`,onClick:e=>e.stopPropagation(),children:[(0,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:r(`editArchive.title`)}),(0,G.jsx)(`button`,{onClick:t,className:`text-bambu-gray hover:text-white transition-colors`,children:(0,G.jsx)(Qu,{className:`w-5 h-5`})})]}),(0,G.jsxs)(`form`,{onSubmit:t=>{t.preventDefault();let n={print_name:a||void 0,printer_id:s,project_id:l,notes:d||void 0,tags:p||void 0,quantity:b,external_url:w||null};_!==e.status&&(n.status=_),_===`failed`||_===`aborted`?n.failure_reason=h||void 0:(e.status===`failed`||e.status===`aborted`)&&(n.failure_reason=null),ee.mutate(n)},className:`p-6 space-y-4 overflow-y-auto flex-1`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`archives.runLog.title`)}),(0,G.jsx)(qG,{archiveId:e.id})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`editArchive.name`)}),(0,G.jsx)(`input`,{type:`text`,value:a,onChange:e=>o(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,placeholder:r(`editArchive.namePlaceholder`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`editArchive.printer`)}),(0,G.jsxs)(`select`,{value:s??``,onChange:e=>c(e.target.value?Number(e.target.value):null),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,G.jsx)(`option`,{value:``,children:r(`editArchive.noPrinter`)}),N?.map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[(0,G.jsx)(pc,{className:`w-4 h-4 inline mr-1`}),r(`editArchive.project`)]}),(0,G.jsxs)(`select`,{value:l??``,onChange:e=>u(e.target.value?Number(e.target.value):null),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,G.jsx)(`option`,{value:``,children:r(`editArchive.noProject`)}),P?.map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[(0,G.jsx)(jc,{className:`w-4 h-4 inline mr-1`}),r(`editArchive.itemsPrinted`)]}),(0,G.jsx)(`input`,{type:`number`,min:1,value:b,onChange:e=>x(Math.max(1,parseInt(e.target.value)||1)),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,placeholder:`1`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:r(`editArchive.itemsPrintedHelp`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`editArchive.notes`)}),(0,G.jsx)(`textarea`,{value:d,onChange:e=>f(e.target.value),rows:3,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none resize-none`,placeholder:r(`editArchive.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(`editArchive.externalLink`)]}),(0,G.jsx)(`input`,{type:`url`,value:w,onChange:e=>T(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,placeholder:`https://printables.com/model/...`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:r(`editArchive.externalLinkHelp`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`editArchive.tags`)}),L.length>0&&(0,G.jsx)(`div`,{className:`flex flex-wrap gap-1.5 mb-2`,children:L.map(e=>(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-2 py-0.5 bg-bambu-dark-tertiary rounded text-sm text-white`,children:[(0,G.jsx)(Su,{className:`w-3 h-3`}),e,(0,G.jsx)(`button`,{type:`button`,onClick:()=>V(e),className:`ml-0.5 text-bambu-gray hover:text-white`,children:(0,G.jsx)(Qu,{className:`w-3 h-3`})})]},e))}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(`input`,{ref:A,type:`text`,value:p,onChange:e=>m(e.target.value),onFocus:()=>{M.current!==null&&clearTimeout(M.current),k(!0)},onBlur:()=>{M.current=window.setTimeout(()=>k(!1),200)},className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,placeholder:L.length>0?r(`editArchive.addMoreTags`):r(`editArchive.tagsPlaceholder`)}),O&&z.length>0&&(0,G.jsxs)(`div`,{className:`absolute top-full left-0 right-0 mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg z-10 max-h-40 overflow-y-auto`,children:[(0,G.jsxs)(`div`,{className:`p-2 text-xs text-bambu-gray border-b border-bambu-dark-tertiary`,children:[R?r(`editArchive.matchingTags`,{query:R}):r(`editArchive.existingTags`),` `,r(`editArchive.clickToAdd`)]}),(0,G.jsx)(`div`,{className:`p-2 flex flex-wrap gap-1.5`,children:z.map(e=>(0,G.jsx)(`button`,{type:`button`,onClick:()=>B(e),className:`px-2 py-0.5 bg-bambu-dark-tertiary hover:bg-bambu-green/20 rounded text-sm text-bambu-gray hover:text-white transition-colors`,children:e},e))})]})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`editArchive.status`)}),(0,G.jsx)(`select`,{value:_,onChange:e=>{v(e.target.value),e.target.value===`completed`&&g(``)},className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:Pke.map(e=>(0,G.jsx)(`option`,{value:e,children:r(`editArchive.statuses.${e}`)},e))})]}),(_===`failed`||_===`aborted`)&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{htmlFor:`failure-reason-select`,className:`block text-sm text-bambu-gray mb-1`,children:r(`editArchive.failureReason`)}),(0,G.jsxs)(`select`,{id:`failure-reason-select`,value:h,onChange:e=>g(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,G.jsx)(`option`,{value:``,children:r(`editArchive.selectReason`)}),JG.map(e=>(0,G.jsx)(`option`,{value:e,children:r(`editArchive.failureReasons.${e}`)},e))]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[(0,G.jsx)(is,{className:`w-4 h-4 inline mr-1`}),r(`editArchive.photos`)]}),(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-2 mb-2`,children:[S.map(t=>(0,G.jsxs)(`div`,{className:`relative group`,children:[(0,G.jsx)(`img`,{src:Z.getArchivePhotoUrl(e.id,t),alt:r(`editArchive.printResult`),className:`w-20 h-20 object-cover rounded-lg border border-bambu-dark-tertiary`}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>ne(t),className:`absolute -top-1 -right-1 p-1 bg-red-500 rounded-full opacity-0 group-hover:opacity-100 transition-opacity`,children:(0,G.jsx)(Au,{className:`w-3 h-3 text-white`})})]},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`,children:[(0,G.jsx)(`input`,{ref:j,type:`file`,accept:`image/jpeg,image/png,image/webp`,onChange:te,className:`hidden`,disabled:E}),E?(0,G.jsx)(Y,{className:`w-6 h-6 text-bambu-gray animate-spin`}):(0,G.jsx)(jl,{className:`w-6 h-6 text-bambu-gray`})]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:r(`editArchive.photosHelp`)})]}),(0,G.jsxs)(`div`,{className:`flex gap-3 pt-2`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:t,className:`flex-1`,children:r(`common.cancel`)}),(0,G.jsxs)(Q,{type:`submit`,disabled:ee.isPending,className:`flex-1`,children:[(0,G.jsx)(Ul,{className:`w-4 h-4`}),ee.isPending?r(`common.saving`):r(`common.save`)]})]})]})]})})}function XG({archiveId:e,archiveName:t,onClose:n}){let{t:r}=U();return(0,y.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)(Qu,{className:`w-5 h-5`})})]}),(0,G.jsx)(`div`,{className:`p-6 overflow-y-auto flex-1`,children:(0,G.jsx)(qG,{archiveId:e})})]})})}function ZG({isOpen:e,onClose:t,columns:n,defaultColumns:r,onSave:i}){let{t:a}=U(),[o,s]=(0,y.useState)(n),[c,l]=(0,y.useState)(null),u=(0,y.useRef)(null);if((0,y.useEffect)(()=>{e&&s(n.map(e=>({...e})))},[e,n]),(0,y.useEffect)(()=>{if(!e)return;let n=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,n),()=>window.removeEventListener(`keydown`,n)},[e,t]),!e)return null;let d=e=>{s(t=>t.map((t,n)=>n===e?{...t,visible:!t.visible}:t))},f=(e,t)=>{t<0||t>=o.length||s(n=>{let r=[...n],[i]=r.splice(e,1);return r.splice(t,0,i),r})},p=(e,t)=>{u.current=t,l(t),e.dataTransfer.effectAllowed=`move`},m=(e,t)=>{e.preventDefault(),e.dataTransfer.dropEffect=`move`;let n=u.current;n!==null&&n!==t&&(f(n,t),u.current=t,l(t))},h=e=>{e.preventDefault()},g=()=>{u.current=null,l(null)},_=()=>{s(r.map(e=>({...e})))},v=()=>{i(o),t()},b=o.filter(e=>e.visible).length;return(0,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)(jd,{className:`w-full max-w-md max-h-[80vh] flex flex-col`,onClick:e=>e.stopPropagation(),children:(0,G.jsxs)(Nd,{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=>p(e,t),onDragOver:e=>m(e,t),onDrop:h,onDragEnd:g,children:[(0,G.jsx)(`div`,{className:`cursor-grab text-bambu-gray/50 hover:text-bambu-gray`,children:(0,G.jsx)(Dc,{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:()=>f(t,t-1),disabled:t===0,className:`p-1 rounded text-bambu-gray hover:bg-bambu-dark-secondary disabled:opacity-30 disabled:cursor-not-allowed`,title:a(`inventory.moveUp`),children:(0,G.jsx)(ms,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:()=>f(t,t+1),disabled:t===o.length-1,className:`p-1 rounded text-bambu-gray hover:bg-bambu-dark-secondary disabled:opacity-30 disabled:cursor-not-allowed`,title:a(`inventory.moveDown`),children:(0,G.jsx)(ds,{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)(nc,{className:`w-4 h-4`}):(0,G.jsx)(tc,{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:_,className:`mr-auto`,children:[(0,G.jsx)(Bl,{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:v,children:a(`inventory.applyChanges`)})]})]})})})}function Fke({selectedIds:e,existingTags:t,onClose:n}){let r=so(),{showToast:i}=zd(),[a,o]=(0,y.useState)(``),[s,c]=(0,y.useState)(new Set),[l,u]=(0,y.useState)(`add`);(0,y.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`)}}),f=e=>{c(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},p=()=>{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)(jd,{className:`w-full max-w-md`,children:(0,G.jsxs)(Nd,{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)(Su,{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)(Qu,{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(),p())}}),(0,G.jsx)(Q,{size:`sm`,variant:`secondary`,onClick:p,disabled:!a.trim(),children:(0,G.jsx)(jl,{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:()=>f(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:()=>f(e),className:`hover:opacity-70`,children:(0,G.jsx)(Qu,{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)(Su,{className:`w-4 h-4`}),l===`add`?`Add Tags`:`Remove Tags`]})})]})]})})})}function Ike({selectedIds:e,onClose:t}){let{t:n}=U(),r=so(),{showToast:i}=zd(),[a,o]=(0,y.useState)(``),{data:s,isLoading:c}=K({queryKey:[`projects`],queryFn:()=>Z.getProjects()}),l=(0,y.useMemo)(()=>s?[...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,f=(l?.length??0)>5;(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]);let p=()=>GG(r),m=q({mutationFn:async t=>(await Z.addArchivesToProject(t,e),t),onSuccess:n=>{let r=s?.find(e=>e.id===n);p(),i(`Added ${e.length} archive${e.length===1?``:`s`} to "${r?.name}"`),t()},onError:()=>{i(`Failed to assign project`,`error`)}}),h=q({mutationFn:async()=>{for(let t of e)await Z.updateArchive(t,{project_id:null});return e.length},onSuccess:e=>{p(),i(`Removed ${e} archive${e===1?``:`s`} from project`),t()},onError:()=>{i(`Failed to remove from project`,`error`)}}),g=m.isPending||h.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)(jd,{className:`w-full max-w-md max-h-[80vh] flex flex-col`,children:(0,G.jsxs)(Nd,{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)(pc,{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:g,children:(0,G.jsx)(Qu,{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:()=>h.mutate(),disabled:g,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)(Ts,{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`})]}),h.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`})]}),f&&(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(Jl,{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:()=>m.mutate(e.id),disabled:g,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)(pc,{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}`]})]}),m.isPending&&m.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:g,children:`Cancel`})})]})})})}function Lke(e,t){return new Date(e,t+1,0).getDate()}function Rke(e,t){return new Date(e,t,1).getDay()}var zke=[`January`,`February`,`March`,`April`,`May`,`June`,`July`,`August`,`September`,`October`,`November`,`December`],Bke=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`];function Vke({archives:e,onArchiveClick:t,highlightedArchiveId:n}){let r=new Date,[i,a]=(0,y.useState)(r.getMonth()),[o,s]=(0,y.useState)(r.getFullYear()),[c,l]=(0,y.useState)(null),[u,d]=(0,y.useState)(null),f=(0,y.useMemo)(()=>{let t=new Map;return e.forEach(e=>{let n=Uf(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]),p=Lke(o,i),m=Rke(o,i),h=()=>{i===0?(a(11),s(o-1)):a(i-1)},g=()=>{i===11?(a(0),s(o+1)):a(i+1)},_=()=>{a(r.getMonth()),s(r.getFullYear())},v=[];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:h,className:`p-2 hover:bg-bambu-dark-tertiary rounded-lg transition-colors`,children:(0,G.jsx)(ps,{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:[zke[i],` `,o]}),(0,G.jsx)(`button`,{onClick:_,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:g,className:`p-2 hover:bg-bambu-dark-tertiary rounded-lg transition-colors`,children:(0,G.jsx)(fs,{className:`w-5 h-5 text-bambu-gray`})})]}),(0,G.jsx)(`div`,{className:`grid grid-cols-7 gap-1 mb-1`,children:Bke.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:v.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=f.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,p=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 ${p>0&&d===0?`bg-red-400`:p>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=Uf(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=Uf(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=Uf(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 QG({archiveId:e,archiveName:t,onClose:n}){let r=Z.getArchiveQRCodeUrl(e,300);return(0,y.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)(Qu,{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)(qs,{className:`w-4 h-4`}),`Download QR Code`]})]})]})})}function $G({archiveId:e,archiveName:t,photos:n,onClose:r,onDelete:i}){let[a,o]=(0,y.useState)(0),[s,c]=(0,y.useState)(!1);if((0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&r(),e.key===`ArrowLeft`&&o(e=>Math.max(0,e-1)),e.key===`ArrowRight`&&o(e=>Math.min(n.length-1,e+1))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[r,n.length]),(0,y.useEffect)(()=>{a>=n.length&&o(Math.max(0,n.length-1))},[n.length,a]),n.length===0)return r(),null;let l=n[a],u=Z.getArchivePhotoUrl(e,l);return(0,G.jsxs)(`div`,{className:`fixed inset-0 bg-black/90 flex items-center justify-center z-50`,onClick:r,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 `,a+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=u,e.download=`${t}_photo_${a+1}.jpg`,e.click()},children:[(0,G.jsx)(qs,{className:`w-4 h-4`}),`Download`]}),i&&(0,G.jsx)(Q,{variant:`secondary`,size:`sm`,onClick:()=>{i&&c(!0)},className:`text-red-400 hover:text-red-300`,children:(0,G.jsx)(Au,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:r,className:`p-2 text-bambu-gray hover:text-white transition-colors`,children:(0,G.jsx)(Qu,{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:[a>0&&(0,G.jsx)(`button`,{onClick:()=>o(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)(ps,{className:`w-8 h-8 text-white`})}),(0,G.jsx)(`img`,{src:u,alt:`Photo ${a+1}`,className:`max-w-full max-h-full object-contain rounded-lg`,style:{maxHeight:`calc(100vh - 200px)`}}),ao(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)(fs,{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((t,n)=>(0,G.jsx)(`button`,{onClick:()=>o(n),className:`w-16 h-16 rounded-lg overflow-hidden border-2 transition-colors ${n===a?`border-bambu-green`:`border-transparent hover:border-bambu-gray`}`,children:(0,G.jsx)(`img`,{src:Z.getArchivePhotoUrl(e,t),alt:`Thumbnail ${n+1}`,className:`w-full h-full object-cover`})},t))})]}),s&&(0,G.jsx)(Xd,{title:`Delete Photo`,message:`Delete this photo? This cannot be undone.`,confirmText:`Delete`,variant:`danger`,onConfirm:()=>{i?.(l),c(!1)},onCancel:()=>c(!1)})]})}function eK(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n`u`?null:wK(BigInt.prototype.toString),yK=typeof Symbol>`u`?null:wK(Symbol.prototype.toString),bK=wK(Object.prototype.hasOwnProperty),xK=wK(Object.prototype.toString),SK=wK(RegExp.prototype.test),CK=tAe(TypeError);function wK(e){return function(t){t instanceof RegExp&&(t.lastIndex=0);var n=[...arguments].slice(1);return sK(e,t,n)}}function tAe(e){return function(){return cK(e,[...arguments])}}function TK(e,t){let n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:pK;if(nK&&nK(e,null),!fK(t))return e;let r=t.length;for(;r--;){let i=t[r];if(typeof i==`string`){let e=n(i);e!==i&&(qke(t)||(t[r]=e),i=e)}e[i]=!0}return e}function nAe(e){for(let t=0;t/g),lAe=iK(/\${[\w\W]*/g),uAe=iK(/^data-[\-\w.\u00B7-\uFFFF]+$/),dAe=iK(/^aria-[\-\w]+$/),LK=iK(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i),fAe=iK(/^(?:\w+script|data):/i),pAe=iK(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g),mAe=iK(/^html$/i),hAe=iK(/^[a-z][.\w]*(-[.\w]+)+$/i),RK=iK(/<[/\w!]/g),zK=iK(/<[/\w]/g),gAe=iK(/<\/no(script|embed|frames)/i),_Ae=iK(/\/>/i),BK={element:1,attribute:2,text:3,cdataSection:4,entityReference:5,entityNode:6,processingInstruction:7,comment:8,document:9,documentType:10,documentFragment:11,notation:12},vAe=function(){return typeof window>`u`?null:window},yAe=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}},VK=function(){return{afterSanitizeAttributes:[],afterSanitizeElements:[],afterSanitizeShadowDOM:[],beforeSanitizeAttributes:[],beforeSanitizeElements:[],beforeSanitizeShadowDOM:[],uponSanitizeAttribute:[],uponSanitizeElement:[],uponSanitizeShadowNode:[]}},HK=function(e,t,n,r){return bK(e,t)&&fK(e[t])?TK(r.base?EK(r.base):{},e[t],r.transform):n};function UK(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:vAe(),t=e=>UK(e);if(t.version=`3.4.13`,t.removed=[],!e||!e.document||e.document.nodeType!==BK.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=DK(d,`cloneNode`),p=DK(d,`remove`),m=DK(d,`nextSibling`),h=DK(d,`childNodes`),g=DK(d,`parentNode`),_=DK(d,`shadowRoot`),v=DK(d,`attributes`),y=o&&o.prototype?DK(o.prototype,`nodeType`):null,b=o&&o.prototype?DK(o.prototype,`nodeName`):null,x=o&&o.prototype?DK(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 CK(`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=yAe(u,i),!0),w},j=n,M=j.implementation,N=j.createNodeIterator,P=j.createDocumentFragment,F=j.getElementsByTagName,I=r.importNode,L=VK();t.isSupported=typeof tK==`function`&&typeof g==`function`&&M&&M.createHTMLDocument!==void 0;let R=sAe,z=cAe,B=lAe,V=uAe,ee=dAe,te=fAe,ne=pAe,re=hAe,ie=LK,ae=null,oe=TK({},[...OK,...kK,...AK,...jK,...MK]),se=null,H=TK({},[...NK,...PK,...FK,...IK]),ce=Object.seal(aK(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(aK(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=TK({},`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=TK({},[`audio`,`video`,`img`,`source`,`image`,`track`]),Ie=null,Le=TK({},[`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=TK({},[Re,ze,Be],mK),Ge=rK([`mi`,`mo`,`mn`,`ms`,`mtext`]),Ke=TK({},Ge),qe=rK([`annotation-xml`]),Je=TK({},qe),Ye=TK({},[`title`,`style`,`font`,`a`,`script`]),Xe=null,Ze=[`application/xhtml+xml`,`text/html`],Qe=null,$e=null,et=n.createElement(`form`),U=function(e){return e instanceof RegExp||e instanceof Function},tt=function(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if($e&&$e===e)return;(!e||typeof e!=`object`)&&(e={}),e=EK(e),Xe=Ze.indexOf(e.PARSER_MEDIA_TYPE)===-1?`text/html`:e.PARSER_MEDIA_TYPE,Qe=Xe===`application/xhtml+xml`?mK:pK,ae=HK(e,`ALLOWED_TAGS`,oe,{transform:Qe}),se=HK(e,`ALLOWED_ATTR`,H,{transform:Qe}),Ue=HK(e,`ALLOWED_NAMESPACES`,We,{transform:mK}),Ie=HK(e,`ADD_URI_SAFE_ATTR`,Le,{transform:Qe,base:Le}),Pe=HK(e,`ADD_DATA_URI_TAGS`,Fe,{transform:Qe,base:Fe}),Me=HK(e,`FORBID_CONTENTS`,Ne,{transform:Qe}),le=HK(e,`FORBID_TAGS`,EK({}),{transform:Qe}),ue=HK(e,`FORBID_ATTR`,EK({}),{transform:Qe}),je=bK(e,`USE_PROFILES`)?e.USE_PROFILES&&typeof e.USE_PROFILES==`object`?EK(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=iAe(e.ALLOWED_URI_REGEXP)?e.ALLOWED_URI_REGEXP:LK,Ve=typeof e.NAMESPACE==`string`?e.NAMESPACE:Be,Ke=bK(e,`MATHML_TEXT_INTEGRATION_POINTS`)&&e.MATHML_TEXT_INTEGRATION_POINTS&&typeof e.MATHML_TEXT_INTEGRATION_POINTS==`object`?EK(e.MATHML_TEXT_INTEGRATION_POINTS):TK({},Ge),Je=bK(e,`HTML_INTEGRATION_POINTS`)&&e.HTML_INTEGRATION_POINTS&&typeof e.HTML_INTEGRATION_POINTS==`object`?EK(e.HTML_INTEGRATION_POINTS):TK({},qe);let t=bK(e,`CUSTOM_ELEMENT_HANDLING`)&&e.CUSTOM_ELEMENT_HANDLING&&typeof e.CUSTOM_ELEMENT_HANDLING==`object`?EK(e.CUSTOM_ELEMENT_HANDLING):aK(null);if(ce=aK(null),bK(t,`tagNameCheck`)&&U(t.tagNameCheck)&&(ce.tagNameCheck=t.tagNameCheck),bK(t,`attributeNameCheck`)&&U(t.attributeNameCheck)&&(ce.attributeNameCheck=t.attributeNameCheck),bK(t,`allowCustomizedBuiltInElements`)&&typeof t.allowCustomizedBuiltInElements==`boolean`&&(ce.allowCustomizedBuiltInElements=t.allowCustomizedBuiltInElements),iK(ce),ge&&(pe=!1),we&&(Ce=!0),je&&(ae=TK({},MK),se=aK(null),je.html===!0&&(TK(ae,OK),TK(se,NK)),je.svg===!0&&(TK(ae,kK),TK(se,PK),TK(se,IK)),je.svgFilters===!0&&(TK(ae,AK),TK(se,PK),TK(se,IK)),je.mathMl===!0&&(TK(ae,jK),TK(se,FK),TK(se,IK))),de.tagCheck=null,de.attributeCheck=null,bK(e,`ADD_TAGS`)&&(typeof e.ADD_TAGS==`function`?de.tagCheck=e.ADD_TAGS:fK(e.ADD_TAGS)&&(ae===oe&&(ae=EK(ae)),TK(ae,e.ADD_TAGS,Qe))),bK(e,`ADD_ATTR`)&&(typeof e.ADD_ATTR==`function`?de.attributeCheck=e.ADD_ATTR:fK(e.ADD_ATTR)&&(se===H&&(se=EK(se)),TK(se,e.ADD_ATTR,Qe))),bK(e,`ADD_URI_SAFE_ATTR`)&&fK(e.ADD_URI_SAFE_ATTR)&&TK(Ie,e.ADD_URI_SAFE_ATTR,Qe),bK(e,`FORBID_CONTENTS`)&&fK(e.FORBID_CONTENTS)&&(Me===Ne&&(Me=EK(Me)),TK(Me,e.FORBID_CONTENTS,Qe)),bK(e,`ADD_FORBID_CONTENTS`)&&fK(e.ADD_FORBID_CONTENTS)&&(Me===Ne&&(Me=EK(Me)),TK(Me,e.ADD_FORBID_CONTENTS,Qe)),ke&&(ae[`#text`]=!0),ve&&TK(ae,[`html`,`head`,`body`]),ae.table&&(TK(ae,[`tbody`]),delete le.tbody),e.TRUSTED_TYPES_POLICY){if(typeof e.TRUSTED_TYPES_POLICY.createHTML!=`function`)throw CK(`TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.`);if(typeof e.TRUSTED_TYPES_POLICY.createScriptURL!=`function`)throw CK(`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(``)));rK&&rK(e),$e=e},nt=TK({},[...kK,...AK,...aAe]),rt=TK({},[...jK,...oAe]),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`&&Je[n]:!!rt[e]},ot=function(e,t,n){return t.namespaceURI===ze&&!Je[n]||t.namespaceURI===Re&&!Ke[n]?!1:!rt[e]&&(Ye[e]||!nt[e])},st=function(e){let t=g(e);(!t||!t.tagName)&&(t={namespaceURI:Ve,tagName:`template`});let n=pK(e.tagName),r=pK(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):!!(Xe===`application/xhtml+xml`&&Ue[e.namespaceURI]):!1},ct=function(e){dK(t.removed,{element:e});try{g(e).removeChild(e)}catch{if(p(e),!g(e))throw CK(`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=[];lK(t,t=>{dK(e,t)}),lK(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{dK(t.removed,{attribute:n.getAttributeNode(e),from:n})}catch{dK(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[Qe(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)===BK.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===BK.processingInstruction||n===BK.comment&&SK(zK,e.data)){try{p(e)}catch{}continue}if(n===BK.element){let t=e,n=Qe(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=hK(e,/^[\r\n\t ]+/);r=t&&t[0]}Xe===`application/xhtml+xml`&&Ve===Be&&(e=``+e+``);let i=S?O(e):e;if(Ve===Be)try{t=new l().parseFromString(i,Xe)}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=gK(e,R,` `),e=gK(e,z,` `),e=gK(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&&lK(i,e=>{yt(e.content)&&_t(e.content)})},vt=function(e){let t=b?b(e):null;return typeof t!=`string`||Qe(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)===BK.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&&lK(e,e=>{e.call(t,n,r,$e)})}let St=function(e,t){return!!(_e&&e.hasChildNodes()&&!bt(e.firstElementChild)&&SK(RK,e.textContent)&&SK(RK,e.innerHTML)||_e&&e.namespaceURI===Be&&t===`style`&&bt(e.firstElementChild)||e.nodeType===BK.processingInstruction||_e&&e.nodeType===BK.comment&&SK(zK,e.data))},Ct=function(e,t,n){if(!le[t]&&Ot(t)&&(ce.tagNameCheck instanceof RegExp&&SK(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?EK(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=Qe(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)===BK.element&&!st(e)||(r===`noscript`||r===`noembed`||r===`noframes`)&&SK(gAe,e.innerHTML))return ct(e),!0;if(ge&&e.nodeType===BK.text){let n=gt(e.textContent);e.textContent!==n&&(dK(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 et))return!1;let i=se[t]||de.attributeCheck instanceof Function&&de.attributeCheck(t,e);if(!(pe&&SK(V,t))&&!(fe&&SK(ee,t))){if(!i){if(!(Ot(e)&&(ce.tagNameCheck instanceof RegExp&&SK(ce.tagNameCheck,e)||ce.tagNameCheck instanceof Function&&ce.tagNameCheck(e))&&(ce.attributeNameCheck instanceof RegExp&&SK(ce.attributeNameCheck,t)||ce.attributeNameCheck instanceof Function&&ce.attributeNameCheck(t,e))||t===`is`&&ce.allowCustomizedBuiltInElements&&(ce.tagNameCheck instanceof RegExp&&SK(ce.tagNameCheck,r)||ce.tagNameCheck instanceof Function&&ce.tagNameCheck(r))))return!1}else if(!Ie[t]&&!SK(ie,gK(r,ne,``))&&!((t===`src`||t===`xlink:href`||t===`href`)&&e!==`script`&&_K(r,`data:`)===0&&Pe[e])&&!(me&&!SK(te,gK(r,ne,``)))&&r)return!1}return!0},Dt=TK({},[`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[pK(e)]&&SK(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):uK(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=Qe(e.nodeName);for(;r--;){let a=t[r],o=a.name,s=a.namespaceURI,c=a.value,l=Qe(o),u=c,d=o===`value`?u:Qke(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`)&&_K(d,Oe)!==0&&(ut(o,e),d=Oe+d),_e&&SK(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i,d)){ut(o,e);continue}if(l===`attributename`&&hK(d,`href`)){ut(o,e);continue}if(!n.forceKeepAttr){if(!n.keepAttr){ut(o,e);continue}if(!he&&SK(_Ae,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)===BK.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)===BK.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`&&Qe(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=rAe(e),typeof e!=`string`))throw CK(`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=EK(ae)),L.uponSanitizeAttribute.length>0&&(se=EK(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=Qe(t);if(!ae[n]||le[n])throw lt(e),CK(`root node is forbidden and cannot be sanitized in-place`)}if(vt(e))throw lt(e),CK(`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===BK.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),lK(t.removed,e=>{e.element&&ft(e.element)})),n}if(c)return lK(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&&SK(mAe,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(){$e=null,ye=!1,be=null,xe=null,S=w,C=``},t.isValidAttribute=function(e,t,n){return $e||tt({}),Et(Qe(e),Qe(t),n)},t.addHook=function(e,t){typeof t==`function`&&bK(L,e)&&dK(L[e],t)},t.removeHook=function(e,t){if(bK(L,e)){if(t!==void 0){let n=Xke(L[e],t);return n===-1?void 0:Zke(L[e],n,1)[0]}return uK(L[e])}},t.removeHooks=function(e){bK(L,e)&&(L[e]=[])},t.removeAllHooks=function(){L=VK()},t}var WK=UK();function GK(e){this.content=e}GK.prototype={constructor:GK,find:function(e){for(var t=0;t>1}},GK.from=function(e){if(e instanceof GK)return e;var t=[];if(e)for(var n in e)t.push(n,e[n]);return new GK(t)};function KK(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){for(let e=0;i.text[e]==a.text[e];e++)n++;return n}if(i.content.size||a.content.size){let e=KK(i.content,a.content,n+1);if(e!=null)return e}n+=i.nodeSize}}function qK(e,t,n,r){for(let i=e.childCount,a=t.childCount;;){if(i==0||a==0)return i==a?null:{a:n,b:r};let o=e.child(--i),s=t.child(--a),c=o.nodeSize;if(o==s){n-=c,r-=c;continue}if(!o.sameMarkup(s))return{a:n,b:r};if(o.isText&&o.text!=s.text){let e=0,t=Math.min(o.text.length,s.text.length);for(;ee&&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?XK(t+1,i):XK(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 new e(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}};QK.none=[];var $K=class extends Error{},eq=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=nq(this.content,t+this.openStart,n);return r&&new e(r,this.openStart,this.openEnd)}removeBetween(t,n){return new e(tq(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(JK.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)}};eq.empty=new eq(JK.empty,0,0);function tq(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(tq(a.content,t-i-1,n-i-1)))}function nq(e,t,n,r){let{index:i,offset:a}=e.findIndex(t),o=e.maybeChild(i);if(a==t||o.isText)return r&&!r.canReplace(i,i,n)?null:e.cut(0,t).append(n).append(e.cut(t));let s=nq(o.content,t-a-1,n,o);return s&&e.replaceChild(i,o.copy(s))}function bAe(e,t,n){if(n.openStart>e.depth)throw new $K(`Inserted content deeper than insertion position`);if(e.depth-n.openStart!=t.depth-n.openEnd)throw new $K(`Inconsistent open depths`);return rq(e,t,n,0)}function rq(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 sq(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&&(oq(e.nodeAfter,r),a++));for(let e=a;ei&&aq(e,t,i+1),o=r.depth>i&&aq(n,r,i+1),s=[];return sq(null,e,i,s),a&&o&&t.index(i)==n.index(i)?(iq(a,o),oq(cq(a,lq(e,t,n,r,i+1)),s)):(a&&oq(cq(a,uq(e,t,i+1)),s),sq(t,n,i,s),o&&oq(cq(o,uq(n,r,i+1)),s)),sq(r,null,i,s),new JK(s)}function uq(e,t,n){let r=[];return sq(null,e,n,r),e.depth>n&&oq(cq(aq(e,t,n+1),uq(e,t,n+1)),r),sq(t,null,n,r),new JK(r)}function xAe(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(JK.from(r));return{start:r.resolveNoCache(e.openStart+n),end:r.resolveNoCache(r.content.size-e.openEnd-n)}}var dq=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 pq(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=fq.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()+`)`),hq(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=JK.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=JK.fromJSON(e,t.content),i=e.nodeType(t.type).create(t.attrs,r,n);return i.type.checkAttrs(i.attrs),i}};mq.prototype.text=void 0;var TAe=class e extends mq{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):hq(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 hq(e,t){for(let n=e.length-1;n>=0;n--)t=e[n].type.name+`(`+t+`)`;return t}var gq=class e{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(t,n){let r=new EAe(t,n);if(r.next==null)return e.empty;let i=_q(r);r.next&&r.err(`Unexpected trailing text`);let a=NAe(MAe(i));return PAe(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(` diff --git a/static/index.html b/static/index.html index 57e884b2f..1817ebebf 100644 --- a/static/index.html +++ b/static/index.html @@ -26,7 +26,7 @@ - +