From 48244bcfcf42154d52c65e8ff990addce7133bb8 Mon Sep 17 00:00:00 2001 From: maziggy Date: Fri, 18 Sep 2026 19:38:24 +0200 Subject: [PATCH] fix(queue): tell a pinned queue item why it is waiting (issue #3074) A job queued as "Any X1C" explains itself when it cannot start: the model-based branch builds a reason for every candidate printer and puts it on the row, so the queue shows "Busy: X1C-01" or "Waiting for filament: X1C-02 (needs PETG)". The same job pinned to one printer showed nothing. It sat at Pending with waiting_reason NULL for as long as that printer was busy, which from the outside is indistinguishable from a queue that has stopped working -- the reporter watched fourteen minutes of it while his X1C ran a print he had started from its own screen. The fixed-printer branch had six ways out and none of them wrote the field. The sensor interlock (#1148) was its only writer, and it cleared the field up front on every pass where no sensor was holding the printer, so NULL was not an oversight on those paths but a guarantee. Every exit now writes, through one helper. The reasons reuse the model-based branch's vocabulary so _is_busy_only() keeps deciding what is worth a notification: a printer that is printing, drying, or working through the item ahead of this one reads as "Busy: " and stays silent, because it resolves itself. A printer that is off with no Auto On plug, and one whose plug could not switch it on, are worth saying. A finished plate nobody has acknowledged is split out from plain busy and named as itself. _is_printer_idle() returns the same plain False for that and for a running print, but they are not the same thing to the person looking at the queue: one clears itself and the other needs somebody to walk over to the printer. That notification fires on the transition into asking, where a busy-only reason counts as not asking. Testing whether the item was waiting at all -- which is what the model-based branch does -- would never fire it here: nobody's queue goes straight from idle to an unconfirmed plate, it waits behind the print first. The cost is that a printer dropping offline, returning busy and dropping again asks twice rather than once. The interlock stays silent. It has never sent this notification, and a change about what the queue displays is not the place to start. Clearing the field up front is gone with it. It existed so a shut door could not leave "Waiting on Enclosure Door" standing while the printer stayed busy with something else, and the new rule carries that guarantee instead -- whichever exit runs next overwrites it, and the dispatch path clears it. Two paths clear it that the report did not mention. A staged item and a future-scheduled one skip before this branch and never reach it again, so anything written on an earlier pass would outlive its condition for the life of the row. That includes the filament-deficit check, which stages the item itself. The notification is wrapped: a queue that cannot say why it is waiting is the bug being fixed, and a queue that stops dispatching because a provider timed out would be a worse one. On the frontend, the queue timeline drops any pending item carrying a reason, on the grounds that such an item will not auto-dispatch. That held while only the model-based branch wrote the field; "Busy: " is now the commonest reason there is, and it describes the very chain the timeline forecasts, so the rule would have emptied the view for anyone whose queue is pinned. It now asks whether the reason needs the user, via a small shared reader of the same shape the scheduler encodes. Which job goes out, and when, is unchanged: running the previous scheduler and this one over the same 768 states dispatches the same items in the same order with the same statuses, across 1452 rows that now carry a reason. --- CHANGELOG.md | 1 + backend/app/schemas/print_queue.py | 2 +- backend/app/services/print_scheduler.py | 206 ++++++- .../unit/test_scheduler_ha_interlock_1148.py | 15 +- ...st_scheduler_pinned_waiting_reason_3074.py | 507 ++++++++++++++++++ .../components/QueueTimelineView.test.tsx | 57 ++ .../src/__tests__/utils/waitingReason.test.ts | 50 ++ frontend/src/api/client.ts | 2 +- frontend/src/components/QueueTimelineView.tsx | 16 +- frontend/src/pages/QueuePage.tsx | 10 +- frontend/src/utils/waitingReason.ts | 23 + .../{index-BMoCmvVS.js => index-DmKOXvHy.js} | 38 +- static/index.html | 2 +- 13 files changed, 877 insertions(+), 52 deletions(-) create mode 100644 backend/tests/unit/test_scheduler_pinned_waiting_reason_3074.py create mode 100644 frontend/src/__tests__/utils/waitingReason.test.ts create mode 100644 frontend/src/utils/waitingReason.ts rename static/assets/{index-BMoCmvVS.js => index-DmKOXvHy.js} (98%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 68b0b23de..800380cf2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ All notable changes to Bambuddy will be documented in this file. - **Every FTP session Bambuddy opens now records how it closed (#3009, reported by @grengojbo)** — the report traced a print completion that opened two FTP connections to the printer, deleted one file and then, as far as the log showed, did nothing else until the printer was powered off 21 minutes later, and concluded the connections were being left open. They were not: the post-print SD-card cleanup opens one connection per candidate filename and closes each in a `finally`, which a run against a real FTPS server confirms at the server end for both the delete and the 550 not-here case. The trouble is that nothing in the log could have said so. Neither the clean close nor the hard socket drop logged anything at any level, so a session closed properly and a socket genuinely abandoned produced the same output — none — and the only way to tell them apart was to read the source. Both now log one DEBUG line naming the printer, whether QUIT was acknowledged or the socket had to be dropped without it, why, and how long the session was held. Every connect in a debug log is now paired with a close, so the next person suspecting a leaked FTP connection can settle it from a support bundle rather than by inference. Nothing about the connection handling itself changed, and at default log level nothing new is printed. This does not explain the SD-card read/write error in that report or in #645; it only removes one theory from the list by making it checkable. ### Fixed +- **A queue item pinned to one printer never said why it was waiting (#3074, reported by @Sawtaytoes)** — the reporter watched a job pinned to a specific X1C sit at Pending for fourteen minutes, with nothing in the UI or the API to say why, while that printer ran a print he had started from its own screen. The same job queued as "Any X1C" explains itself, because the model-based half of the scheduler builds a sentence for every way a job could not start and puts it on the row. The pinned half never wrote that field at all: the Home Assistant sensor interlock was its only writer, and it actively cleared the field whenever no sensor was holding the printer. Pinned items now say what they are waiting on in the same words — **Busy: X1C-01** while it prints, while it dries, or while another job on that printer goes first; **Offline, no Auto On smart plug: X1C-01** when nothing can switch it back on — and the row shows the purple **Waiting** badge instead of a silent Pending. "Finished, waiting for you to confirm the plate is clear" is split out from plain busy and named as itself, because it is the one case on that list that does not resolve on its own. A printer that is simply printing still sends no notification, exactly as before, and neither does a sensor interlock; only the cases that need you to go and do something do. On the queue timeline, a job that is merely next in line still draws its forecast bar as before, while one that is waiting for you now drops off it rather than promising a start time nobody can keep. Nothing about which job goes out, or when, has changed. - **A plate printed entirely from the external spool stalled at preheat and failed (#3087, reported by @Notaseraf)** — the reporter's P1S heated up, sat there for ten minutes and then paused with HMS 07FF_8012, "Failed to get AMS mapping table". Resuming just reheated it; prints that used the AMS were fine. The plate was a single filament out of a seven-filament MakerWorld project, mapped by hand to the external spool. A project's filaments are numbered across the whole project, so a plate that prints only the seventh one carries six placeholder entries in front of it — the same shape BambuStudio sends. Bambuddy read that as "nothing here is on the spool holder" and told the printer to use the AMS anyway, with a mapping that pointed at no tray at all, which is precisely the mapping table the firmware then could not find. A plate whose every printed filament sits on the external spool now dispatches with the AMS switched off, so it prints. The decision is made against the plate's own filament list rather than guessed from the mapping alone, because a placeholder entry and a filament that could not be matched to any tray look identical in the mapping, and sending the second one to the spool holder would silently print it in the wrong material (#2589). A plate that mixes the spool holder with an AMS tray, or that has a filament which matched nothing, is untouched and still behaves exactly as before, as are dual-nozzle printers — on those the same switch selects which nozzle to feed rather than whether to use the AMS. - **A printer that had been offline for hours could stop the whole server (#3068, reported by @bazza2000)** — the reporter's A1 had been unreachable for 38 hours but still answered on its MQTT port, which is exactly the case the connection watchdog exists for: rebuild the session with a fresh client so nothing left over from the dead one can replay onto the new print. The rebuild ended in a call that waits for the old connection's network thread to finish, and that thread was stuck part-way through a TLS handshake the printer never completed, where nothing can interrupt it. The wait had no limit and it ran on the thread that serves every request, so Bambuddy stopped answering — the web UI, the API and the health check alike — while the process itself stayed up, which is why Docker's restart policy never kicked in. Retiring an old connection no longer waits for it: the replacement is built immediately and the old one is shut down in the background, cut off from the new session first so a printer that eventually answers cannot report itself connected again after being replaced. The same wait sat on three other printer paths — the queue's dispatch recovery, the staleness check behind an ordinary status poll, and editing, deleting or disconnecting a printer — and on the shutdown of the MQTT relay and smart-plug connections, where a wedged broker kept the process from exiting at all. All of them are fixed together. A connection that takes more than a few seconds to shut down now says so in the log instead of silently taking the server with it. - **Auto-drying skipped every composite spool (#3067, reported by @TheUltimateC0der)** — the reporter's AMS-HT would not dry PA6-CF, and drying the same spool by hand worked. The scheduler reduced a tray to a preset key by splitting on spaces only, so "PA6-CF" stayed "PA6-CF", matched none of the eight rows the preset table has, and the tray was read as holding nothing worth drying. It was never only nylon: of the 41 types a printer can report, 33 had no row under that rule, and 20 of those — every -CF, -GF and -AERO variant of PLA, PETG, ABS, ASA, PC and PA — have a base material sitting right there. The drying popover has resolved these correctly since 1.2.5, which is exactly why doing it by hand worked; the scheduler now shares that rule, including the alias map that reads PA6, PA11, PA12, PAHT, PPA and Nylon as PA. A row you have added for the exact type still wins over the base material's, and a material whose base is not in the table either is still left alone rather than dried at a temperature nobody chose. The same lookup decides per-filament humidity thresholds and the chamber preheat target, so a composite now gets the override and the preheat that were set for its material too. diff --git a/backend/app/schemas/print_queue.py b/backend/app/schemas/print_queue.py index 7846db595..0c337b5ca 100644 --- a/backend/app/schemas/print_queue.py +++ b/backend/app/schemas/print_queue.py @@ -187,7 +187,7 @@ class PrintQueueItemResponse(BaseModel): target_location: str | None = None # Target location filter for model-based assignment required_filament_types: list[str] | None = None # Required filament types for model-based assignment filament_overrides: list[dict] | None = None # Filament overrides for model-based assignment - waiting_reason: str | None = None # Why a model-based job hasn't started yet + waiting_reason: str | None = None # Why this job hasn't started yet (empty once it can) archive_id: int | None # None if library_file_id is set (archive created at print start) library_file_id: int | None # For queue items from library files cost_center_id: int | None = None diff --git a/backend/app/services/print_scheduler.py b/backend/app/services/print_scheduler.py index c356f75ba..50aae6396 100644 --- a/backend/app/services/print_scheduler.py +++ b/backend/app/services/print_scheduler.py @@ -1291,6 +1291,95 @@ class PrintScheduler: claimed_printers.add(printer_id) mark_busy(printer_id, "selected for dispatch in this pass") + # The user-facing half of `busy_reasons` (#3074). The same decisions + # worded for a different audience: the log wants "still inside its + # post-dispatch hold window", the queue row wants to know the printer + # is taken and nothing is broken. Only the cases that would read wrong + # as a plain "Busy" are recorded here; the rest fall back to it. + item_hold_reasons: dict[int, str] = {} + + # Names and models for the printers this pass may have to write a + # waiting reason about, read once rather than per skip per tick. The + # model-based branch already has its names from `_printers_for_model`. + pinned_printer_ids = {i.printer_id for i in items if i.printer_id} + pinned_printers: dict[int, tuple[str, str]] = {} + if pinned_printer_ids: + pinned_rows = await db.execute( + select(Printer.id, Printer.name, Printer.model).where(Printer.id.in_(pinned_printer_ids)) + ) + pinned_printers = {pid: (name or "", model or "") for pid, name, model in pinned_rows.all()} + + def printer_label(printer_id: int) -> str: + """What to call this printer in a queue row.""" + entry = pinned_printers.get(printer_id) + return (entry[0] if entry else "") or f"printer {printer_id}" + + async def hold_item(item: PrintQueueItem, reason: str | None, *, notify: bool = True) -> None: + """Record why *item* is not going out, in the words the queue row shows. + + The fixed-printer branch's single writer for ``waiting_reason`` + (#3074). Before this, the sensor interlock was the only thing that + wrote the field there, so an item pinned to a printer that was + merely printing sat at `pending` with nothing to show for it — + indistinguishable from a queue that had stopped working — while + the same job queued as "Any " explained itself. + + Every exit from that branch now calls this, which is also what + replaced the interlock's old habit of clearing the field up front: + a lifted hold cannot leave "Waiting on Enclosure Door" standing, + because whichever exit runs next overwrites it and the dispatch + path clears it. + + A notification goes out when this item starts asking for + something, and only then: the new reason needs the user, and what + it replaced did not. "What it replaced did not" has to include a + busy-only reason, not just an empty one. The sequence this branch + actually produces is a print running (``Busy: X1C-01``) and then + the plate it left behind (``Waiting for plate confirmation``), and + testing "was the field empty" would call that no transition at all + and stay quiet through the one case worth saying out loud. + + The cost is that a printer dropping offline, coming back busy and + dropping again asks twice rather than once. That is the honest + reading — it went wrong twice — and the alternative was a rule + that never fired for the case this was built for. + + *notify* is how a caller opts out. The sensor interlock does: it + has never sent this notification, and a change about what the + queue *displays* is not the place to start (#1148). + """ + if item.waiting_reason == reason: + return + # Busy-only and empty are the same thing here: neither is the + # queue asking the user for anything. + was_asking = bool(item.waiting_reason) and not self._is_busy_only(item.waiting_reason) + item.waiting_reason = reason + await db.commit() + if not notify or not reason or was_asking or self._is_busy_only(reason): + return + try: + job_name = await self._get_job_name(db, item) + entry = pinned_printers.get(item.printer_id) if item.printer_id else None + await notification_service.on_queue_job_waiting( + job_name=job_name, + target_model=(entry[1] if entry else "") or "", + waiting_reason=reason, + db=db, + ) + except Exception as e: + # A queue that cannot say why it is waiting is the bug being + # fixed here; a queue that stops dispatching because a + # notification provider is down would be a worse one. + logger.debug("Waiting notification failed for item %s: %s", item.id, e) + + async def hold_for_printer( + item: PrintQueueItem, printer_id: int, log_reason: str, item_reason: str + ) -> None: + """Take *printer_id* out of this pass and tell the item's owner why.""" + mark_busy(printer_id, log_reason) + item_hold_reasons.setdefault(printer_id, item_reason) + await hold_item(item, item_reason) + # Defense-in-depth (#1157): augment busy_printers with any printer # still in its post-dispatch hold window. Empirically, the DB seed # above can miss in-flight items in a multi-plate batch — same-file @@ -1415,11 +1504,18 @@ class PrintScheduler: if sched.tzinfo is None: sched = sched.replace(tzinfo=timezone.utc) if sched > datetime.now(timezone.utc): + # Waiting on the clock, not on a printer. + await hold_item(item, None) skip_reasons["scheduled_future"] = skip_reasons.get("scheduled_future", 0) + 1 continue # Skip items that require manual start if item.manual_start: + # Waiting on the user, not on a printer. Cleared here because + # this is the last pass that will look at the row: a staged + # item never reaches the branches below again, so a reason + # left from before it was staged would stand forever (#3074). + await hold_item(item, None) skip_reasons["manual_start"] = skip_reasons.get("manual_start", 0) + 1 continue @@ -1430,24 +1526,35 @@ class PrintScheduler: # to shut the enclosure" need to read differently, and only # one of them is something the user can fix. # - # The interlock is the only thing that writes a - # waiting_reason on this branch — the model-based branch - # nulls it at the moment it assigns a printer — so any - # reason still standing once the hold lifts is stale and is - # cleared here. Doing it at dispatch instead would leave a - # shut door reading "Waiting on Enclosure Door" for as long - # as the printer stayed busy with something else. + # It used to be the only thing that wrote a waiting_reason on + # this branch, and it cleared the field up front so a lifted + # hold could not leave a shut door reading "Waiting on + # Enclosure Door". `hold_item` carries that guarantee now — + # every exit below writes — so the clear is gone and the + # interlock is an ordinary hold like the rest (#3074). interlock_reason = interlocked.get(item.printer_id) - reason = f"Waiting on {interlock_reason}" if interlock_reason else None - if item.waiting_reason != reason: - item.waiting_reason = reason - await db.commit() if interlock_reason: + # Silent, exactly as it has always been. #1148 built this + # as a hold that shows on the row, never as an alert, and + # routing it through the shared writer must not quietly + # turn every open door into a notification. + await hold_item(item, f"Waiting on {interlock_reason}", notify=False) skip_reasons["sensor_interlock"] = skip_reasons.get("sensor_interlock", 0) + 1 continue # Specific printer assignment (existing behavior) if item.printer_id in busy_printers: + # Whatever took the printer out of this pass — a print + # already running on it, a post-dispatch hold, an upload + # still in flight, an item ahead of this one in the same + # pass — reads the same way from the queue: the printer is + # taken and this item is in line for it. The exceptions + # that do not (an offline printer, say) recorded their own + # wording in `item_hold_reasons` when they held it. + await hold_item( + item, + item_hold_reasons.get(item.printer_id) or f"Busy: {printer_label(item.printer_id)}", + ) continue # Check if printer is idle @@ -1479,16 +1586,36 @@ class PrintScheduler: printer_idle = self._is_printer_idle(item.printer_id, require_plate_clear) else: logger.warning("Could not power on printer %s via smart plug", item.printer_id) - mark_busy(item.printer_id, "smart-plug power-on failed") + await hold_for_printer( + item, + item.printer_id, + "smart-plug power-on failed", + f"Offline: {printer_label(item.printer_id)} — the smart plug could not power it on", + ) continue else: - # No plug or auto_on disabled - mark_busy(item.printer_id, "offline, with no smart plug to power it on") + # No plug or auto_on disabled. Worded exactly as the + # model-based branch words it (#2786): this is the one + # entry on that list the user has to act on, because + # Bambuddy will never switch this printer on itself. + await hold_for_printer( + item, + item.printer_id, + "offline, with no smart plug to power it on", + f"Offline, no Auto On smart plug: {printer_label(item.printer_id)}", + ) continue # Check if printer is idle (busy with another print) if not printer_idle: - mark_busy(item.printer_id, "not idle") + await hold_for_printer( + item, + item.printer_id, + "not idle", + self._pinned_hold_reason( + item.printer_id, printer_label(item.printer_id), require_plate_clear + ), + ) continue # Drying blocks the queue, if the user asked it to. A hold @@ -1497,7 +1624,14 @@ class PrintScheduler: if self._drying_in_progress.get(item.printer_id) and await self._get_bool_setting( db, "queue_drying_block" ): - mark_busy(item.printer_id, "drying, and drying is set to block the queue") + # Busy-shaped on purpose: the cycle ends on its own and + # the job goes out, so there is nothing to alert about. + await hold_for_printer( + item, + item.printer_id, + "drying, and drying is set to block the queue", + f"Busy: {printer_label(item.printer_id)} (drying)", + ) continue # Check condition (previous print success) @@ -1506,6 +1640,8 @@ class PrintScheduler: item.status = "skipped" item.error_message = "Previous print failed or was aborted" item.completed_at = datetime.now(timezone.utc) + # Not pending any more, so not waiting for anything. + item.waiting_reason = None await db.commit() logger.info("Skipped queue item %s - previous print failed", item.id) @@ -1535,6 +1671,10 @@ class PrintScheduler: # promote the item to manual_start so the user must # acknowledge via the ▶ button (which re-checks live). if await self._block_on_filament_deficit(db, item): + # Now staged for the user to start by hand, and the row + # shows the filament-short badge instead. Cleared because + # a staged item never reaches this branch again. + await hold_item(item, None) continue # Hold this item back for the next pass rather than racing @@ -1543,7 +1683,12 @@ class PrintScheduler: # its place in this printer's queue. if _library_row_conflict(item): skip_reasons["library_row_in_use"] = skip_reasons.get("library_row_in_use", 0) + 1 - mark_busy(item.printer_id, "holding its place while another item releases a library row") + await hold_for_printer( + item, + item.printer_id, + "holding its place while another item releases a library row", + f"Busy: {printer_label(item.printer_id)}", + ) continue # Print takes priority: stop a cycle Bambuddy armed, now @@ -1571,6 +1716,11 @@ class PrintScheduler: # Queue the dispatch instead of running it here — see # _dispatch_selected(). busy_printers still gets the printer # immediately, so nothing else in this pass can target it. + # + # The reason goes first: this item is not waiting for anything + # any more, and the model-based branch clears its own at the + # equivalent moment (#3074). + await hold_item(item, None) _claim_library_row(item) dispatch_ids.append(item.id) claim_printer(item.printer_id) @@ -3781,6 +3931,28 @@ class PrintScheduler: logger.debug("Printer %d: not idle — state=%s", printer_id, state.state) return idle + @staticmethod + def _pinned_hold_reason(printer_id: int, printer_name: str, require_plate_clear: bool) -> str: + """Why a connected, non-idle printer cannot take this job, for the queue row (#3074). + + Only ever asked about a printer :meth:`_is_printer_idle` has just refused + and that the fixed-printer branch has already found connected, so the two + offline cases answer at their own exits and never arrive here. + + The default is the model-based branch's ``Busy:`` wording, which + :meth:`_is_busy_only` reads as "resolves itself, stay quiet". That is also + the right answer for the connected-but-no-telemetry second or two after a + reconnect: the model-based branch has always reported it that way, and it + is not something to wake anybody up for. + + A plate nobody has confirmed is the one case here that does not resolve + itself — somebody has to walk over to the printer — so it is worded as + itself and allowed to notify. + """ + if require_plate_clear and printer_manager.is_awaiting_plate_clear(printer_id): + return f"Waiting for plate confirmation: {printer_name}" + return f"Busy: {printer_name}" + async def _get_setting(self, db: AsyncSession, key: str) -> str | None: """Read a setting value from the database.""" result = await db.execute(select(Settings).where(Settings.key == key)) diff --git a/backend/tests/unit/test_scheduler_ha_interlock_1148.py b/backend/tests/unit/test_scheduler_ha_interlock_1148.py index fa2cc4049..9843e1d42 100644 --- a/backend/tests/unit/test_scheduler_ha_interlock_1148.py +++ b/backend/tests/unit/test_scheduler_ha_interlock_1148.py @@ -179,9 +179,14 @@ class TestFixedPrinter: async def test_the_reason_clears_even_when_the_printer_is_still_busy(self, queue_db): """You shut the door, but the printer is midway through something else. - The hold has lifted and the queue must say so. Clearing the reason only - at dispatch would leave a shut door reading "Waiting on Enclosure Door" - for the rest of a ten-hour print. + The hold has lifted and the queue must say so. Leaving the old reason + standing would have a shut door reading "Waiting on Enclosure Door" for + the rest of a ten-hour print. + + The reason no longer goes to None here: since #3074 the branch always + says what it is waiting on, and what it is waiting on now is the print. + The invariant under test is the same one — the lifted hold does not + survive the pass that lifted it. """ item_id = await _add_item(queue_db, printer_id=1) scheduler = PrintScheduler() @@ -191,7 +196,9 @@ class TestFixedPrinter: await _run(queue_db, scheduler, {}, launched, idle=False) launched.assert_not_called() - assert (await _get_item(queue_db, item_id)).waiting_reason is None + reason = (await _get_item(queue_db, item_id)).waiting_reason + assert "Enclosure Door" not in (reason or "") + assert reason == "Busy: X1C-1" @pytest.mark.asyncio async def test_another_printers_sensor_does_not_hold_this_one(self, queue_db): diff --git a/backend/tests/unit/test_scheduler_pinned_waiting_reason_3074.py b/backend/tests/unit/test_scheduler_pinned_waiting_reason_3074.py new file mode 100644 index 000000000..444bb79bb --- /dev/null +++ b/backend/tests/unit/test_scheduler_pinned_waiting_reason_3074.py @@ -0,0 +1,507 @@ +"""A queue item pinned to one printer explains itself (#3074). + +Bambuddy has two ways to queue a job. "Any X1C" goes through the model-based +branch, which builds a sentence for every way the job could not start and puts +it on the row: `Busy: X1C-01`, `Waiting for filament: X1C-02 (needs PETG)`. The +same job pinned to a specific printer went through a branch that wrote nothing. + +The reporter watched a pinned item sit at `pending` with `waiting_reason: null` +for fourteen minutes while its printer ran a print started from the printer's +own screen. Nothing in the UI or the API said why, and a queue that will not say +why it is waiting is indistinguishable from a queue that has stopped working. + +Two rules hold everything here together: + +- **Every exit writes.** Not one path out of the fixed-printer branch may leave + the field as it found it, or a reason from an earlier pass outlives the + condition that produced it. +- **Only what the user must act on makes a noise.** A printer that is merely + printing resolves itself; the wording stays inside what `_is_busy_only` reads + as silent. A plate nobody has confirmed does not resolve itself, so it is + worded as itself and allowed through. +""" + +from contextlib import ExitStack +from types import SimpleNamespace +from unittest.mock import AsyncMock, MagicMock, patch + +import pytest +from sqlalchemy import select +from sqlalchemy.ext.asyncio import async_sessionmaker, create_async_engine + +import backend.app.models # noqa: F401 - populate Base.metadata +from backend.app.core.database import Base +from backend.app.models.library import LibraryFile +from backend.app.models.print_queue import PrintQueueItem +from backend.app.models.printer import Printer +from backend.app.models.settings import Settings +from backend.app.services.print_scheduler import PrintScheduler + + +@pytest.fixture +async def ctx(): + engine = create_async_engine("sqlite+aiosqlite:///:memory:", echo=False) + async with engine.begin() as conn: + await conn.run_sync(Base.metadata.create_all) + session_maker = async_sessionmaker(engine, expire_on_commit=False) + + async with session_maker() as db: + db.add( + Printer( + id=1, + name="X1C-01", + serial_number="X1C0001", + ip_address="10.0.0.1", + access_code="x", + model="X1C", + is_active=True, + ) + ) + await db.commit() + + try: + yield SimpleNamespace(session_maker=session_maker) + finally: + await engine.dispose() + + +async def _add_item(ctx, *, printer_id=1, target_model=None, position=1, manual_start=False): + async with ctx.session_maker() as db: + lib = LibraryFile( + filename="job.gcode.3mf", + file_path="/library/job.gcode.3mf", + file_size=10, + file_type="gcode.3mf", + file_metadata={"sliced_for_model": "X1C"}, + ) + db.add(lib) + await db.flush() + item = PrintQueueItem( + status="pending", + position=position, + printer_id=printer_id, + target_model=target_model, + library_file_id=lib.id, + manual_start=manual_start, + ) + db.add(item) + await db.commit() + return item.id + + +async def _set(ctx, key, value): + async with ctx.session_maker() as db: + db.add(Settings(key=key, value=value)) + await db.commit() + + +async def _item(ctx, item_id): + async with ctx.session_maker() as db: + return (await db.execute(select(PrintQueueItem).where(PrintQueueItem.id == item_id))).scalar_one() + + +async def _run( + ctx, + scheduler, + *, + idle=True, + connected=True, + awaiting_plate_clear=False, + blocked=None, + plugs=None, + launched=None, + waiting=None, +): + """One check_queue pass with the printer in the state the test cares about.""" + launched = launched or MagicMock() + patches = [ + patch("backend.app.services.print_scheduler.async_session", ctx.session_maker), + patch("backend.app.core.database.async_session", ctx.session_maker), + patch( + "backend.app.services.print_scheduler.printer_manager.is_connected", + MagicMock(return_value=connected), + ), + patch("backend.app.services.print_scheduler.printer_manager.get_status", MagicMock(return_value=None)), + patch( + "backend.app.services.print_scheduler.printer_manager.is_awaiting_plate_clear", + MagicMock(return_value=awaiting_plate_clear), + ), + patch( + "backend.app.services.print_scheduler.ha_sensor_manager.blocked_printers", + AsyncMock(return_value=blocked or {}), + ), + patch( + "backend.app.services.notification_service.notification_service.on_queue_job_waiting", + waiting or AsyncMock(), + ), + patch( + "backend.app.services.notification_service.notification_service.on_queue_job_assigned", + AsyncMock(), + ), + patch.object(scheduler, "_is_printer_idle", MagicMock(return_value=idle)), + patch.object(scheduler, "_check_auto_drying", AsyncMock()), + patch.object(scheduler, "_ensure_ams_mapping", AsyncMock(return_value=None)), + patch.object(scheduler, "_block_on_filament_deficit", AsyncMock(return_value=False)), + patch.object(scheduler, "_get_smart_plugs", AsyncMock(return_value=plugs or [])), + patch.object(scheduler, "_launch_uploads", launched), + ] + with ExitStack() as stack: + for p in patches: + stack.enter_context(p) + await scheduler.check_queue() + return launched + + +class TestThePinnedItemSaysWhyItIsWaiting: + """The reporter's four cases, each of which used to produce ``None``.""" + + @pytest.mark.asyncio + async def test_a_printer_midway_through_a_print(self, ctx): + """The exact fourteen minutes from the report: a print started at the + printer's own screen, and a pinned item with nothing to show for it.""" + item_id = await _add_item(ctx) + + launched = await _run(ctx, PrintScheduler(), idle=False) + + launched.assert_not_called() + assert (await _item(ctx, item_id)).waiting_reason == "Busy: X1C-01" + + @pytest.mark.asyncio + async def test_a_plate_nobody_has_confirmed(self, ctx): + """The other half of the report. `_is_printer_idle` returns a plain + False for both this and a running print, but they are not the same + thing to the person looking at the queue: this one waits on them.""" + await _set(ctx, "require_plate_clear", "true") + item_id = await _add_item(ctx) + + await _run(ctx, PrintScheduler(), idle=False, awaiting_plate_clear=True) + + assert (await _item(ctx, item_id)).waiting_reason == "Waiting for plate confirmation: X1C-01" + + @pytest.mark.asyncio + async def test_an_item_queued_behind_another_on_the_same_printer(self, ctx): + """The commonest case of all, and one the reporter never even reached: + two items pinned to one printer. The second leaves the pass at the + `busy_printers` test, several checks before anything that could have + described the printer.""" + first = await _add_item(ctx, position=1) + second = await _add_item(ctx, position=2) + + launched = await _run(ctx, PrintScheduler(), idle=True) + + assert launched.call_args[0][0] == [first] + assert (await _item(ctx, second)).waiting_reason == "Busy: X1C-01" + + @pytest.mark.asyncio + async def test_a_printer_that_is_off_with_nothing_to_switch_it_on(self, ctx): + """Worded exactly as the model-based branch words it (#2786). This is + the one entry here the user has to act on themselves: with no enabled + Auto On plug, Bambuddy will never power this printer up for the queue.""" + item_id = await _add_item(ctx) + + await _run(ctx, PrintScheduler(), connected=False) + + assert (await _item(ctx, item_id)).waiting_reason == "Offline, no Auto On smart plug: X1C-01" + + @pytest.mark.asyncio + async def test_a_drying_cycle_the_user_asked_to_block_the_queue(self, ctx): + await _set(ctx, "queue_drying_block", "true") + item_id = await _add_item(ctx) + scheduler = PrintScheduler() + scheduler._drying_in_progress[1] = True + + launched = await _run(ctx, scheduler, idle=True) + + launched.assert_not_called() + assert (await _item(ctx, item_id)).waiting_reason == "Busy: X1C-01 (drying)" + + +class TestTheReasonNeverOutlivesTheThingItDescribes: + """Every exit from the branch writes, so no pass can leave a stale reason.""" + + @pytest.mark.asyncio + async def test_it_clears_the_moment_the_item_goes_out(self, ctx): + item_id = await _add_item(ctx) + scheduler = PrintScheduler() + await _run(ctx, scheduler, idle=False) + assert (await _item(ctx, item_id)).waiting_reason == "Busy: X1C-01" + + launched = await _run(ctx, scheduler, idle=True) + + assert launched.call_args[0][0] == [item_id] + assert (await _item(ctx, item_id)).waiting_reason is None + + @pytest.mark.asyncio + async def test_a_busy_printer_replaces_a_lifted_interlock(self, ctx): + """The guarantee the interlock used to buy by clearing the field up + front, now bought by the exits all writing instead.""" + item_id = await _add_item(ctx) + scheduler = PrintScheduler() + await _run(ctx, scheduler, idle=False, blocked={1: "Enclosure Door"}) + assert (await _item(ctx, item_id)).waiting_reason == "Waiting on Enclosure Door" + + await _run(ctx, scheduler, idle=False) + + assert (await _item(ctx, item_id)).waiting_reason == "Busy: X1C-01" + + @pytest.mark.asyncio + async def test_staging_an_item_drops_the_reason_it_was_carrying(self, ctx): + """A staged item never reaches the fixed-printer branch again, so + whatever it was carrying when the user staged it would otherwise stand + for as long as the row lived.""" + item_id = await _add_item(ctx) + scheduler = PrintScheduler() + await _run(ctx, scheduler, idle=False) + assert (await _item(ctx, item_id)).waiting_reason == "Busy: X1C-01" + + async with ctx.session_maker() as db: + item = (await db.execute(select(PrintQueueItem).where(PrintQueueItem.id == item_id))).scalar_one() + item.manual_start = True + await db.commit() + + await _run(ctx, scheduler, idle=False) + + assert (await _item(ctx, item_id)).waiting_reason is None + + @pytest.mark.asyncio + async def test_the_reason_is_written_once_not_once_per_tick(self, ctx): + """Four passes over a printer that is printing throughout must not be + four writes — the scheduler runs on a timer and this row is read by the + UI on a poll.""" + item_id = await _add_item(ctx) + scheduler = PrintScheduler() + for _ in range(4): + await _run(ctx, scheduler, idle=False) + + item = await _item(ctx, item_id) + assert item.waiting_reason == "Busy: X1C-01" + assert item.status == "pending" + + +class TestOnlyWhatTheUserMustActOnMakesANoise: + """`_is_busy_only` decided this for the model-based branch; the reporter + asked for the same restraint here, and the wording is what enforces it.""" + + @pytest.mark.asyncio + async def test_a_printer_that_is_simply_printing_stays_silent(self, ctx): + await _add_item(ctx) + waiting = AsyncMock() + + await _run(ctx, PrintScheduler(), idle=False, waiting=waiting) + + waiting.assert_not_called() + + @pytest.mark.asyncio + async def test_a_drying_cycle_stays_silent(self, ctx): + await _set(ctx, "queue_drying_block", "true") + await _add_item(ctx) + scheduler = PrintScheduler() + scheduler._drying_in_progress[1] = True + waiting = AsyncMock() + + await _run(ctx, scheduler, idle=True, waiting=waiting) + + waiting.assert_not_called() + + @pytest.mark.asyncio + async def test_an_item_waiting_its_turn_stays_silent(self, ctx): + await _add_item(ctx, position=1) + await _add_item(ctx, position=2) + waiting = AsyncMock() + + await _run(ctx, PrintScheduler(), idle=True, waiting=waiting) + + waiting.assert_not_called() + + @pytest.mark.asyncio + async def test_an_unconfirmed_plate_is_worth_saying_once(self, ctx): + await _set(ctx, "require_plate_clear", "true") + await _add_item(ctx) + waiting = AsyncMock() + scheduler = PrintScheduler() + + for _ in range(3): + await _run(ctx, scheduler, idle=False, awaiting_plate_clear=True, waiting=waiting) + + waiting.assert_called_once() + assert waiting.call_args.kwargs["waiting_reason"] == "Waiting for plate confirmation: X1C-01" + assert waiting.call_args.kwargs["target_model"] == "X1C" + + @pytest.mark.asyncio + async def test_the_plate_notification_survives_the_print_that_came_before_it(self, ctx): + """The sequence this branch actually produces, and the one a naive + "was the field empty" transition test gets wrong. + + Nobody's queue goes straight from idle to an unconfirmed plate. It waits + behind the print first, carrying "Busy: X1C-01" for however long that + takes, and only then does the plate appear. Asking whether the item was + waiting at all would call that no transition and stay silent through the + single case on this list that needs a human. + """ + await _set(ctx, "require_plate_clear", "true") + item_id = await _add_item(ctx) + scheduler = PrintScheduler() + waiting = AsyncMock() + + await _run(ctx, scheduler, idle=False, waiting=waiting) + assert (await _item(ctx, item_id)).waiting_reason == "Busy: X1C-01" + waiting.assert_not_called() + + await _run(ctx, scheduler, idle=False, awaiting_plate_clear=True, waiting=waiting) + + assert (await _item(ctx, item_id)).waiting_reason == "Waiting for plate confirmation: X1C-01" + waiting.assert_called_once() + + @pytest.mark.asyncio + async def test_it_does_not_ask_twice_for_the_same_thing(self, ctx): + """Busy, plate, plate, plate — one notification, not three.""" + await _set(ctx, "require_plate_clear", "true") + await _add_item(ctx) + scheduler = PrintScheduler() + waiting = AsyncMock() + + await _run(ctx, scheduler, idle=False, waiting=waiting) + for _ in range(3): + await _run(ctx, scheduler, idle=False, awaiting_plate_clear=True, waiting=waiting) + + waiting.assert_called_once() + + @pytest.mark.asyncio + async def test_an_interlock_has_never_notified_and_still_does_not(self, ctx): + """#1148 built the sensor interlock as a hold that shows on the row, not + as an alert. Routing it through the shared writer must not quietly turn + every open enclosure door into a notification.""" + item_id = await _add_item(ctx) + waiting = AsyncMock() + + await _run(ctx, PrintScheduler(), blocked={1: "Enclosure Door"}, waiting=waiting) + + assert (await _item(ctx, item_id)).waiting_reason == "Waiting on Enclosure Door" + waiting.assert_not_called() + + @pytest.mark.asyncio + async def test_a_printer_nobody_can_switch_on_is_worth_saying(self, ctx): + await _add_item(ctx) + waiting = AsyncMock() + + await _run(ctx, PrintScheduler(), connected=False, waiting=waiting) + + waiting.assert_called_once() + + @pytest.mark.asyncio + async def test_a_provider_that_is_down_does_not_stop_the_queue(self, ctx): + """The bug being fixed is a queue that cannot say why it is waiting. A + queue that stops dispatching because a webhook timed out would be the + worse one.""" + await _set(ctx, "require_plate_clear", "true") + item_id = await _add_item(ctx) + scheduler = PrintScheduler() + + await _run( + ctx, + scheduler, + idle=False, + awaiting_plate_clear=True, + waiting=AsyncMock(side_effect=RuntimeError("provider down")), + ) + assert (await _item(ctx, item_id)).waiting_reason == "Waiting for plate confirmation: X1C-01" + + launched = await _run(ctx, scheduler, idle=True) + + assert launched.call_args[0][0] == [item_id] + + +class TestWhatMustNotChange: + @pytest.mark.asyncio + async def test_an_interlock_still_reads_as_itself(self, ctx): + """#1148's wording is what the user acts on — it names the sensor.""" + item_id = await _add_item(ctx) + + launched = await _run(ctx, PrintScheduler(), blocked={1: "Enclosure Door"}) + + launched.assert_not_called() + assert (await _item(ctx, item_id)).waiting_reason == "Waiting on Enclosure Door" + + @pytest.mark.asyncio + async def test_an_idle_printer_still_dispatches(self, ctx): + item_id = await _add_item(ctx) + + launched = await _run(ctx, PrintScheduler(), idle=True) + + assert launched.call_args[0][0] == [item_id] + assert (await _item(ctx, item_id)).waiting_reason is None + + @pytest.mark.asyncio + async def test_the_plate_gate_is_not_consulted_when_it_is_switched_off(self, ctx): + """`require_plate_clear` defaults to off. With the gate off, an + unconfirmed plate is not what is holding the queue, and saying so would + send the user to a prompt that is not there.""" + item_id = await _add_item(ctx) + + await _run(ctx, PrintScheduler(), idle=False, awaiting_plate_clear=True) + + assert (await _item(ctx, item_id)).waiting_reason == "Busy: X1C-01" + + +class TestTheWordingStaysInsideWhatIsBusyOnlyUnderstands: + """The silence is enforced by string prefixes, so pin them directly rather + than only through the scheduler. A future rewording that drops the ``Busy:`` + prefix would turn every printing fleet into a notification source.""" + + @pytest.mark.parametrize( + "reason", + [ + "Busy: X1C-01", + "Busy: X1C-01 (drying)", + ], + ) + def test_these_are_silent(self, reason): + assert PrintScheduler._is_busy_only(reason) is True + + @pytest.mark.parametrize( + "reason", + [ + "Waiting for plate confirmation: X1C-01", + "Offline, no Auto On smart plug: X1C-01", + "Offline: X1C-01 — the smart plug could not power it on", + "Waiting on Enclosure Door", + ], + ) + def test_these_are_not(self, reason): + assert PrintScheduler._is_busy_only(reason) is False + + +class TestPinnedHoldReason: + """The one new branch, exercised without a scheduler pass around it.""" + + def test_a_printing_printer_is_busy(self): + with patch( + "backend.app.services.print_scheduler.printer_manager.is_awaiting_plate_clear", + MagicMock(return_value=False), + ): + assert PrintScheduler._pinned_hold_reason(1, "X1C-01", True) == "Busy: X1C-01" + + def test_an_unconfirmed_plate_is_named(self): + with patch( + "backend.app.services.print_scheduler.printer_manager.is_awaiting_plate_clear", + MagicMock(return_value=True), + ): + assert PrintScheduler._pinned_hold_reason(1, "X1C-01", True) == "Waiting for plate confirmation: X1C-01" + + def test_the_gate_being_off_beats_the_flag(self): + """The flag is persisted, so it survives the setting being turned off.""" + with patch( + "backend.app.services.print_scheduler.printer_manager.is_awaiting_plate_clear", + MagicMock(return_value=True), + ): + assert PrintScheduler._pinned_hold_reason(1, "X1C-01", False) == "Busy: X1C-01" + + def test_no_telemetry_yet_reads_as_busy(self): + """A printer that reconnected a second ago has no status, which + `_is_printer_idle` refuses. It resolves itself within a tick or two, and + the model-based branch has always reported it as plain busy.""" + with patch( + "backend.app.services.print_scheduler.printer_manager.is_awaiting_plate_clear", + MagicMock(return_value=False), + ): + assert PrintScheduler._pinned_hold_reason(9, "X1C-01", True) == "Busy: X1C-01" diff --git a/frontend/src/__tests__/components/QueueTimelineView.test.tsx b/frontend/src/__tests__/components/QueueTimelineView.test.tsx index 36290f8d9..6bd9a8417 100644 --- a/frontend/src/__tests__/components/QueueTimelineView.test.tsx +++ b/frontend/src/__tests__/components/QueueTimelineView.test.tsx @@ -114,3 +114,60 @@ describe('QueueTimelineView job ordering', () => { expect(barsLeftToRight()).toEqual(['Running now', 'Long job', 'Short job']); }); }); + +describe('QueueTimelineView and the scheduler waiting reasons (#3074)', () => { + /** The scheduler now puts a reason on a pinned item too, and the commonest + * one by far -- "Busy: " -- describes the very chain this view + * forecasts. Dropping every item that has a reason would empty the timeline + * for anyone whose queue is pinned to specific printers. */ + function renderWith(items: PrintQueueItem[]) { + render( + {}} + t={(key: string) => key} + />, + ); + } + + it('still forecasts an item that is only waiting its turn', () => { + renderWith([ + running, + pending(1, 'Long job', 1, 2 * HOUR, { waiting_reason: 'Busy: X1C-01' }), + pending(2, 'Medium job', 2, HOUR, { waiting_reason: 'Busy: X1C-01' }), + ]); + expect(barsLeftToRight()).toEqual(['Running now', 'Long job', 'Medium job']); + }); + + it('still forecasts one held behind a drying cycle', () => { + renderWith([running, pending(1, 'Long job', 1, 2 * HOUR, { waiting_reason: 'Busy: X1C-01 (drying)' })]); + expect(barsLeftToRight()).toEqual(['Running now', 'Long job']); + }); + + it('drops one that is waiting for the user', () => { + // These do not start on their own, so a bar would be a promise the queue + // cannot keep. + for (const reason of [ + 'Waiting for plate confirmation: X1C-01', + 'Offline, no Auto On smart plug: X1C-01', + 'Waiting on Enclosure Door', + 'Waiting for filament: X1C-01 (needs PETG)', + ]) { + const { unmount } = render( + {}} + t={(key: string) => key} + />, + ); + expect(barsLeftToRight()).toEqual(['Running now']); + unmount(); + } + }); +}); diff --git a/frontend/src/__tests__/utils/waitingReason.test.ts b/frontend/src/__tests__/utils/waitingReason.test.ts new file mode 100644 index 000000000..ccc9adff6 --- /dev/null +++ b/frontend/src/__tests__/utils/waitingReason.test.ts @@ -0,0 +1,50 @@ +/** + * The frontend half of the `waiting_reason` shape contract (#3074). + * + * The scheduler encodes "starts by itself" as a reason made only of `Busy: ...` + * clauses, joined with ` | `, and decides notifications on that basis. The UI + * reads the same bit to decide what still belongs on a forecast. These cases + * are the exact strings both branches of the scheduler emit, so a reword on + * either side lands here first. + */ + +import { describe, it, expect } from 'vitest'; +import { isBusyOnlyWaitingReason } from '../../utils/waitingReason'; + +describe('isBusyOnlyWaitingReason', () => { + it('treats nothing as not-busy rather than busy', () => { + // An item with no reason is dispatchable, not "waiting its turn"; callers + // check the reason's presence separately. + expect(isBusyOnlyWaitingReason(null)).toBe(false); + expect(isBusyOnlyWaitingReason(undefined)).toBe(false); + expect(isBusyOnlyWaitingReason('')).toBe(false); + }); + + it.each([ + 'Busy: X1C-01', + 'Busy: X1C-01 (drying)', + 'Busy: X1C-01, X1C-02', + 'Busy: X1C-01 | Busy: X1C-02', + ])('reads %s as waiting its turn', reason => { + expect(isBusyOnlyWaitingReason(reason)).toBe(true); + }); + + it.each([ + 'Waiting for plate confirmation: X1C-01', + 'Offline, no Auto On smart plug: X1C-01', + 'Offline: X1C-01 — the smart plug could not power it on', + 'Waiting on Enclosure Door', + 'Waiting for filament: X1C-01 (needs PETG)', + 'No available X1C printers', + 'Every file for this job has been deleted — add a file back or remove the item', + ])('reads %s as waiting for the user', reason => { + expect(isBusyOnlyWaitingReason(reason)).toBe(false); + }); + + it('needs every clause to be busy, not just the first', () => { + // The scheduler only joins with " | " when every clause is busy, but the + // reader must not assume that -- one clause needing the user makes the + // whole reason need the user. + expect(isBusyOnlyWaitingReason('Busy: X1C-01 | Offline: X1C-02')).toBe(false); + }); +}); diff --git a/frontend/src/api/client.ts b/frontend/src/api/client.ts index 9edbfdfb8..ea5cd6aae 100644 --- a/frontend/src/api/client.ts +++ b/frontend/src/api/client.ts @@ -2533,7 +2533,7 @@ export interface PrintQueueItem { target_model: string | null; // Target printer model for model-based assignment target_location: string | null; // Target location filter for model-based assignment required_filament_types: string[] | null; // Required filament types for model-based assignment - waiting_reason: string | null; // Why a model-based job hasn't started yet + waiting_reason: string | null; // Why this job hasn't started yet (empty once it can) // Cross-model alternatives (#671), in priority order. Empty for ordinary // items. Present until dispatch resolves one, after which library_file_id and // target_model name the candidate that actually ran. diff --git a/frontend/src/components/QueueTimelineView.tsx b/frontend/src/components/QueueTimelineView.tsx index df70769f5..81e951745 100644 --- a/frontend/src/components/QueueTimelineView.tsx +++ b/frontend/src/components/QueueTimelineView.tsx @@ -2,6 +2,7 @@ import { useState, useMemo, useEffect, useRef } from 'react'; import { ChevronLeft, ChevronRight, Clock, Layers, Printer as PrinterIcon } from 'lucide-react'; import { formatDuration, parseUTCDate } from '../utils/date'; import { compareQueueOrder, queueLaneKey } from '../utils/queueOrder'; +import { isBusyOnlyWaitingReason } from '../utils/waitingReason'; import type { PrintQueueItem, Printer } from '../api/client'; import { api } from '../api/client'; import { Button } from './Button'; @@ -91,8 +92,11 @@ export function QueueTimelineView({ // • pending with explicit scheduled_time → at that time // • pending ASAP that chain behind a print actually running on the same // lane → forecast - // Staged (manual_start) and waiting (waiting_reason) items are not on the - // timeline because they won't auto-dispatch — they'd be misleading bars. + // Staged (manual_start) and blocked items are not on the timeline because + // they won't auto-dispatch — they'd be misleading bars. "Blocked" is not the + // same as "has a waiting_reason": since #3074 an item queued behind a running + // print carries one too ("Busy: X1C-01"), and that is the chain this view + // exists to forecast. Only a reason that needs the user takes an item off. // Idle-printer ASAP queues also stay off until something starts on them. const events = useMemo(() => { const result: ScheduleEvent[] = []; @@ -128,10 +132,12 @@ export function QueueTimelineView({ lanesWithActive.add(lk); chainEndByLane.set(lk, Math.max(chainEndByLane.get(lk) ?? nowMs, endTime.getTime())); } else if (item.status === 'pending') { - // Skip un-committed pending shapes — staged items and waiting items - // won't auto-dispatch, so a bar would lie. + // Skip un-committed pending shapes — staged items and blocked items + // won't auto-dispatch, so a bar would lie. An item merely waiting its + // turn behind a print does auto-dispatch, and is the whole point of the + // chain forecast below. if (item.manual_start) continue; - if (item.waiting_reason) continue; + if (item.waiting_reason && !isBusyOnlyWaitingReason(item.waiting_reason)) continue; const lk = queueLaneKey(item); if (!pendingByLaneKey.has(lk)) pendingByLaneKey.set(lk, []); pendingByLaneKey.get(lk)!.push(item); diff --git a/frontend/src/pages/QueuePage.tsx b/frontend/src/pages/QueuePage.tsx index 9a04f8724..6eea82bf0 100644 --- a/frontend/src/pages/QueuePage.tsx +++ b/frontend/src/pages/QueuePage.tsx @@ -1836,10 +1836,12 @@ export function QueuePage() { // Queue items eligible for an "if started now" ETA (#2740). // // The ETA answers "when would this finish if it began right now", so it may - // only appear on items that really could begin right now. Deriving that from - // waiting_reason alone is not enough: the scheduler only writes that field on - // the model-based assignment path (print_scheduler.py), so an item pinned to a - // specific printer sits behind a running job with waiting_reason still NULL. + // only appear on items that really could begin right now. waiting_reason now + // covers the pinned-printer case too (#3074), but it is still not enough on + // its own: it says whether the scheduler had a reason to hold the item on its + // last pass, not whether this item is the one that printer takes next. Two + // items pinned to the same free printer both come back with no reason, and + // only one of them can start now — which is what the ordering below works out. // // Computed from the unfiltered queue on purpose — hiding a printer behind the // location filter must not make its printer look free. diff --git a/frontend/src/utils/waitingReason.ts b/frontend/src/utils/waitingReason.ts new file mode 100644 index 000000000..8f3079b1c --- /dev/null +++ b/frontend/src/utils/waitingReason.ts @@ -0,0 +1,23 @@ +/** + * Reading the scheduler's `waiting_reason` (#3074). + * + * The backend writes one sentence per held queue item and encodes one bit in + * its shape: a reason made only of `Busy: ...` clauses means the job starts by + * itself once a printer frees up, and anything else means somebody has to do + * something — load filament, switch a printer on, confirm a plate. The + * scheduler uses that bit to decide whether a hold is worth a notification + * (`PrintScheduler._is_busy_only`), and the UI needs the same distinction to + * decide whether a held item still belongs on a forecast. + * + * Kept in one place on this side too, so the two halves of the contract are one + * grep apart. + */ + +/** Does this reason mean "waiting its turn", rather than "waiting for you"? */ +export function isBusyOnlyWaitingReason(reason: string | null | undefined): boolean { + if (!reason) return false; + return reason + .split(' | ') + .map(part => part.trim()) + .every(part => part.startsWith('Busy:')); +} diff --git a/static/assets/index-BMoCmvVS.js b/static/assets/index-DmKOXvHy.js similarity index 98% rename from static/assets/index-BMoCmvVS.js rename to static/assets/index-DmKOXvHy.js index c8b2e3809..194759cc9 100644 --- a/static/assets/index-BMoCmvVS.js +++ b/static/assets/index-DmKOXvHy.js @@ -4352,7 +4352,7 @@ img.ProseMirror-separator { To pick up a draggable item, press the space bar. While dragging, use the arrow keys to move the item. Press space again to drop the item in its new position, or press escape to cancel. - `},XVe={onDragStart(e){let{active:t}=e;return`Picked up draggable item `+t.id+`.`},onDragOver(e){let{active:t,over:n}=e;return n?`Draggable item `+t.id+` was moved over droppable area `+n.id+`.`:`Draggable item `+t.id+` is no longer over a droppable area.`},onDragEnd(e){let{active:t,over:n}=e;return n?`Draggable item `+t.id+` was dropped over droppable area `+n.id:`Draggable item `+t.id+` was dropped.`},onDragCancel(e){let{active:t}=e;return`Dragging was cancelled. Draggable item `+t.id+` was dropped.`}};function ZVe(e){let{announcements:t=XVe,container:n,hiddenTextDescribedById:r,screenReaderInstructions:i=YVe}=e,{announce:a,announcement:o}=KVe(),s=p4(`DndLiveRegion`),[c,l]=(0,y.useState)(!1);if((0,y.useEffect)(()=>{l(!0)},[]),qVe((0,y.useMemo)(()=>({onDragStart(e){let{active:n}=e;a(t.onDragStart({active:n}))},onDragMove(e){let{active:n,over:r}=e;t.onDragMove&&a(t.onDragMove({active:n,over:r}))},onDragOver(e){let{active:n,over:r}=e;a(t.onDragOver({active:n,over:r}))},onDragEnd(e){let{active:n,over:r}=e;a(t.onDragEnd({active:n,over:r}))},onDragCancel(e){let{active:n,over:r}=e;a(t.onDragCancel({active:n,over:r}))}}),[a,t])),!c)return null;let u=y.createElement(y.Fragment,null,y.createElement(WVe,{id:r,value:i.draggable}),y.createElement(GVe,{id:s,announcement:o}));return n?(0,At.createPortal)(u,n):u}var S4;(function(e){e.DragStart=`dragStart`,e.DragMove=`dragMove`,e.DragEnd=`dragEnd`,e.DragCancel=`dragCancel`,e.DragOver=`dragOver`,e.RegisterDroppable=`registerDroppable`,e.SetDroppableDisabled=`setDroppableDisabled`,e.UnregisterDroppable=`unregisterDroppable`})(S4||={});function C4(){}function w4(e,t){return(0,y.useMemo)(()=>({sensor:e,options:t??{}}),[e,t])}function T4(){var e=[...arguments];return(0,y.useMemo)(()=>[...e].filter(e=>e!=null),[...e])}var E4=Object.freeze({x:0,y:0});function D4(e,t){return Math.sqrt((e.x-t.x)**2+(e.y-t.y)**2)}function QVe(e,t){let n=v4(e);if(!n)return`0 0`;let r={x:(n.x-t.left)/t.width*100,y:(n.y-t.top)/t.height*100};return r.x+`% `+r.y+`%`}function O4(e,t){let{data:{value:n}}=e,{data:{value:r}}=t;return n-r}function $Ve(e,t){let{data:{value:n}}=e,{data:{value:r}}=t;return r-n}function k4(e){let{left:t,top:n,height:r,width:i}=e;return[{x:t,y:n},{x:t+i,y:n},{x:t,y:n+r},{x:t+i,y:n+r}]}function A4(e,t){if(!e||e.length===0)return null;let[n]=e;return t?n[t]:n}function j4(e,t,n){return t===void 0&&(t=e.left),n===void 0&&(n=e.top),{x:t+e.width*.5,y:n+e.height*.5}}var M4=e=>{let{collisionRect:t,droppableRects:n,droppableContainers:r}=e,i=j4(t,t.left,t.top),a=[];for(let e of r){let{id:t}=e,r=n.get(t);if(r){let n=D4(j4(r),i);a.push({id:t,data:{droppableContainer:e,value:n}})}}return a.sort(O4)},eHe=e=>{let{collisionRect:t,droppableRects:n,droppableContainers:r}=e,i=k4(t),a=[];for(let e of r){let{id:t}=e,r=n.get(t);if(r){let n=k4(r),o=i.reduce((e,t,r)=>e+D4(n[r],t),0),s=Number((o/4).toFixed(4));a.push({id:t,data:{droppableContainer:e,value:s}})}}return a.sort(O4)};function tHe(e,t){let n=Math.max(t.top,e.top),r=Math.max(t.left,e.left),i=Math.min(t.left+t.width,e.left+e.width),a=Math.min(t.top+t.height,e.top+e.height),o=i-r,s=a-n;if(r{let{collisionRect:t,droppableRects:n,droppableContainers:r}=e,i=[];for(let e of r){let{id:r}=e,a=n.get(r);if(a){let n=tHe(a,t);n>0&&i.push({id:r,data:{droppableContainer:e,value:n}})}}return i.sort($Ve)};function rHe(e,t,n){return{...e,scaleX:t&&n?t.width/n.width:1,scaleY:t&&n?t.height/n.height:1}}function N4(e,t){return e&&t?{x:e.left-t.left,y:e.top-t.top}:E4}function iHe(e){return function(t){return[...arguments].slice(1).reduce((t,n)=>({...t,top:t.top+e*n.y,bottom:t.bottom+e*n.y,left:t.left+e*n.x,right:t.right+e*n.x}),{...t})}}var aHe=iHe(1);function P4(e){if(e.startsWith(`matrix3d(`)){let t=e.slice(9,-1).split(/, /);return{x:+t[12],y:+t[13],scaleX:+t[0],scaleY:+t[5]}}else if(e.startsWith(`matrix(`)){let t=e.slice(7,-1).split(/, /);return{x:+t[4],y:+t[5],scaleX:+t[0],scaleY:+t[3]}}return null}function oHe(e,t,n){let r=P4(t);if(!r)return e;let{scaleX:i,scaleY:a,x:o,y:s}=r,c=e.left-o-(1-i)*parseFloat(n),l=e.top-s-(1-a)*parseFloat(n.slice(n.indexOf(` `)+1)),u=i?e.width/i:e.width,d=a?e.height/a:e.height;return{width:u,height:d,top:l,right:c+u,bottom:l+d,left:c}}var sHe={ignoreTransform:!1};function F4(e,t){t===void 0&&(t=sHe);let n=e.getBoundingClientRect();if(t.ignoreTransform){let{transform:t,transformOrigin:r}=t4(e).getComputedStyle(e);t&&(n=oHe(n,t,r))}let{top:r,left:i,width:a,height:o,bottom:s,right:c}=n;return{top:r,left:i,width:a,height:o,bottom:s,right:c}}function I4(e){return F4(e,{ignoreTransform:!0})}function cHe(e){let t=e.innerWidth,n=e.innerHeight;return{top:0,left:0,right:t,bottom:n,width:t,height:n}}function lHe(e,t){return t===void 0&&(t=t4(e).getComputedStyle(e)),t.position===`fixed`}function uHe(e,t){t===void 0&&(t=t4(e).getComputedStyle(e));let n=/(auto|scroll|overlay)/;return[`overflow`,`overflowX`,`overflowY`].some(e=>{let r=t[e];return typeof r==`string`?n.test(r):!1})}function L4(e,t){let n=[];function r(i){if(t!=null&&n.length>=t||!i)return n;if(n4(i)&&i.scrollingElement!=null&&!n.includes(i.scrollingElement))return n.push(i.scrollingElement),n;if(!r4(i)||i4(i)||n.includes(i))return n;let a=t4(e).getComputedStyle(i);return i!==e&&uHe(i,a)&&n.push(i),lHe(i,a)?n:r(i.parentNode)}return e?r(e):n}function R4(e){let[t]=L4(e,1);return t??null}function z4(e){return!Q2||!e?null:$2(e)?e:e4(e)?n4(e)||e===a4(e).scrollingElement?window:r4(e)?e:null:null}function B4(e){return $2(e)?e.scrollX:e.scrollLeft}function V4(e){return $2(e)?e.scrollY:e.scrollTop}function H4(e){return{x:B4(e),y:V4(e)}}var U4;(function(e){e[e.Forward=1]=`Forward`,e[e.Backward=-1]=`Backward`})(U4||={});function W4(e){return!Q2||!e?!1:e===document.scrollingElement}function G4(e){let t={x:0,y:0},n=W4(e)?{height:window.innerHeight,width:window.innerWidth}:{height:e.clientHeight,width:e.clientWidth},r={x:e.scrollWidth-n.width,y:e.scrollHeight-n.height};return{isTop:e.scrollTop<=t.y,isLeft:e.scrollLeft<=t.x,isBottom:e.scrollTop>=r.y,isRight:e.scrollLeft>=r.x,maxScroll:r,minScroll:t}}var dHe={x:.2,y:.2};function fHe(e,t,n,r,i){let{top:a,left:o,right:s,bottom:c}=n;r===void 0&&(r=10),i===void 0&&(i=dHe);let{isTop:l,isBottom:u,isLeft:d,isRight:f}=G4(e),p={x:0,y:0},m={x:0,y:0},h={height:t.height*i.y,width:t.width*i.x};return!l&&a<=t.top+h.height?(p.y=U4.Backward,m.y=r*Math.abs((t.top+h.height-a)/h.height)):!u&&c>=t.bottom-h.height&&(p.y=U4.Forward,m.y=r*Math.abs((t.bottom-h.height-c)/h.height)),!f&&s>=t.right-h.width?(p.x=U4.Forward,m.x=r*Math.abs((t.right-h.width-s)/h.width)):!d&&o<=t.left+h.width&&(p.x=U4.Backward,m.x=r*Math.abs((t.left+h.width-o)/h.width)),{direction:p,speed:m}}function pHe(e){if(e===document.scrollingElement){let{innerWidth:e,innerHeight:t}=window;return{top:0,left:0,right:e,bottom:t,width:e,height:t}}let{top:t,left:n,right:r,bottom:i}=e.getBoundingClientRect();return{top:t,left:n,right:r,bottom:i,width:e.clientWidth,height:e.clientHeight}}function K4(e){return e.reduce((e,t)=>h4(e,H4(t)),E4)}function mHe(e){return e.reduce((e,t)=>e+B4(t),0)}function hHe(e){return e.reduce((e,t)=>e+V4(t),0)}function q4(e,t){if(t===void 0&&(t=F4),!e)return;let{top:n,left:r,bottom:i,right:a}=t(e);R4(e)&&(i<=0||a<=0||n>=window.innerHeight||r>=window.innerWidth)&&e.scrollIntoView({block:`center`,inline:`center`})}var gHe=[[`x`,[`left`,`right`],mHe],[`y`,[`top`,`bottom`],hHe]],J4=class{constructor(e,t){this.rect=void 0,this.width=void 0,this.height=void 0,this.top=void 0,this.bottom=void 0,this.right=void 0,this.left=void 0;let n=L4(t),r=K4(n);this.rect={...e},this.width=e.width,this.height=e.height;for(let[e,t,i]of gHe)for(let a of t)Object.defineProperty(this,a,{get:()=>{let t=i(n),o=r[e]-t;return this.rect[a]+o},enumerable:!0});Object.defineProperty(this,"rect",{enumerable:!1})}},Y4=class{constructor(e){this.target=void 0,this.listeners=[],this.removeAll=()=>{this.listeners.forEach(e=>this.target?.removeEventListener(...e))},this.target=e}add(e,t,n){var r;(r=this.target)==null||r.addEventListener(e,t,n),this.listeners.push([e,t,n])}};function _He(e){let{EventTarget:t}=t4(e);return e instanceof t?e:a4(e)}function X4(e,t){let n=Math.abs(e.x),r=Math.abs(e.y);return typeof t==`number`?Math.sqrt(n**2+r**2)>t:`x`in t&&`y`in t?n>t.x&&r>t.y:`x`in t?n>t.x:`y`in t?r>t.y:!1}var Z4;(function(e){e.Click=`click`,e.DragStart=`dragstart`,e.Keydown=`keydown`,e.ContextMenu=`contextmenu`,e.Resize=`resize`,e.SelectionChange=`selectionchange`,e.VisibilityChange=`visibilitychange`})(Z4||={});function Q4(e){e.preventDefault()}function vHe(e){e.stopPropagation()}var $4;(function(e){e.Space=`Space`,e.Down=`ArrowDown`,e.Right=`ArrowRight`,e.Left=`ArrowLeft`,e.Up=`ArrowUp`,e.Esc=`Escape`,e.Enter=`Enter`,e.Tab=`Tab`})($4||={});var e3={start:[$4.Space,$4.Enter],cancel:[$4.Esc],end:[$4.Space,$4.Enter,$4.Tab]},yHe=(e,t)=>{let{currentCoordinates:n}=t;switch(e.code){case $4.Right:return{...n,x:n.x+25};case $4.Left:return{...n,x:n.x-25};case $4.Down:return{...n,y:n.y+25};case $4.Up:return{...n,y:n.y-25}}},t3=class{constructor(e){this.props=void 0,this.autoScrollEnabled=!1,this.referenceCoordinates=void 0,this.listeners=void 0,this.windowListeners=void 0,this.props=e;let{event:{target:t}}=e;this.props=e,this.listeners=new Y4(a4(t)),this.windowListeners=new Y4(t4(t)),this.handleKeyDown=this.handleKeyDown.bind(this),this.handleCancel=this.handleCancel.bind(this),this.attach()}attach(){this.handleStart(),this.windowListeners.add(Z4.Resize,this.handleCancel),this.windowListeners.add(Z4.VisibilityChange,this.handleCancel),setTimeout(()=>this.listeners.add(Z4.Keydown,this.handleKeyDown))}handleStart(){let{activeNode:e,onStart:t}=this.props,n=e.node.current;n&&q4(n),t(E4)}handleKeyDown(e){if(_4(e)){let{active:t,context:n,options:r}=this.props,{keyboardCodes:i=e3,coordinateGetter:a=yHe,scrollBehavior:o=`smooth`}=r,{code:s}=e;if(i.end.includes(s)){this.handleEnd(e);return}if(i.cancel.includes(s)){this.handleCancel(e);return}let{collisionRect:c}=n.current,l=c?{x:c.left,y:c.top}:E4;this.referenceCoordinates||=l;let u=a(e,{active:t,context:n.current,currentCoordinates:l});if(u){let t=g4(u,l),r={x:0,y:0},{scrollableAncestors:i}=n.current;for(let n of i){let i=e.code,{isTop:a,isRight:s,isLeft:c,isBottom:l,maxScroll:d,minScroll:f}=G4(n),p=pHe(n),m={x:Math.min(i===$4.Right?p.right-p.width/2:p.right,Math.max(i===$4.Right?p.left:p.left+p.width/2,u.x)),y:Math.min(i===$4.Down?p.bottom-p.height/2:p.bottom,Math.max(i===$4.Down?p.top:p.top+p.height/2,u.y))},h=i===$4.Right&&!s||i===$4.Left&&!c,g=i===$4.Down&&!l||i===$4.Up&&!a;if(h&&m.x!==u.x){let e=n.scrollLeft+t.x,a=i===$4.Right&&e<=d.x||i===$4.Left&&e>=f.x;if(a&&!t.y){n.scrollTo({left:e,behavior:o});return}a?r.x=n.scrollLeft-e:r.x=i===$4.Right?n.scrollLeft-d.x:n.scrollLeft-f.x,r.x&&n.scrollBy({left:-r.x,behavior:o});break}else if(g&&m.y!==u.y){let e=n.scrollTop+t.y,a=i===$4.Down&&e<=d.y||i===$4.Up&&e>=f.y;if(a&&!t.x){n.scrollTo({top:e,behavior:o});return}a?r.y=n.scrollTop-e:r.y=i===$4.Down?n.scrollTop-d.y:n.scrollTop-f.y,r.y&&n.scrollBy({top:-r.y,behavior:o});break}}this.handleMove(e,h4(g4(u,this.referenceCoordinates),r))}}}handleMove(e,t){let{onMove:n}=this.props;e.preventDefault(),n(t)}handleEnd(e){let{onEnd:t}=this.props;e.preventDefault(),this.detach(),t()}handleCancel(e){let{onCancel:t}=this.props;e.preventDefault(),this.detach(),t()}detach(){this.listeners.removeAll(),this.windowListeners.removeAll()}};t3.activators=[{eventName:`onKeyDown`,handler:(e,t,n)=>{let{keyboardCodes:r=e3,onActivation:i}=t,{active:a}=n,{code:o}=e.nativeEvent;if(r.start.includes(o)){let t=a.activatorNode.current;return t&&e.target!==t?!1:(e.preventDefault(),i?.({event:e.nativeEvent}),!0)}return!1}}];function n3(e){return!!(e&&`distance`in e)}function r3(e){return!!(e&&`delay`in e)}var i3=class{constructor(e,t,n){n===void 0&&(n=_He(e.event.target)),this.props=void 0,this.events=void 0,this.autoScrollEnabled=!0,this.document=void 0,this.activated=!1,this.initialCoordinates=void 0,this.timeoutId=null,this.listeners=void 0,this.documentListeners=void 0,this.windowListeners=void 0,this.props=e,this.events=t;let{event:r}=e,{target:i}=r;this.props=e,this.events=t,this.document=a4(i),this.documentListeners=new Y4(this.document),this.listeners=new Y4(n),this.windowListeners=new Y4(t4(i)),this.initialCoordinates=v4(r)??E4,this.handleStart=this.handleStart.bind(this),this.handleMove=this.handleMove.bind(this),this.handleEnd=this.handleEnd.bind(this),this.handleCancel=this.handleCancel.bind(this),this.handleKeydown=this.handleKeydown.bind(this),this.removeTextSelection=this.removeTextSelection.bind(this),this.attach()}attach(){let{events:e,props:{options:{activationConstraint:t,bypassActivationConstraint:n}}}=this;if(this.listeners.add(e.move.name,this.handleMove,{passive:!1}),this.listeners.add(e.end.name,this.handleEnd),e.cancel&&this.listeners.add(e.cancel.name,this.handleCancel),this.windowListeners.add(Z4.Resize,this.handleCancel),this.windowListeners.add(Z4.DragStart,Q4),this.windowListeners.add(Z4.VisibilityChange,this.handleCancel),this.windowListeners.add(Z4.ContextMenu,Q4),this.documentListeners.add(Z4.Keydown,this.handleKeydown),t){if(n!=null&&n({event:this.props.event,activeNode:this.props.activeNode,options:this.props.options}))return this.handleStart();if(r3(t)){this.timeoutId=setTimeout(this.handleStart,t.delay),this.handlePending(t);return}if(n3(t)){this.handlePending(t);return}}this.handleStart()}detach(){this.listeners.removeAll(),this.windowListeners.removeAll(),setTimeout(this.documentListeners.removeAll,50),this.timeoutId!==null&&(clearTimeout(this.timeoutId),this.timeoutId=null)}handlePending(e,t){let{active:n,onPending:r}=this.props;r(n,e,this.initialCoordinates,t)}handleStart(){let{initialCoordinates:e}=this,{onStart:t}=this.props;e&&(this.activated=!0,this.documentListeners.add(Z4.Click,vHe,{capture:!0}),this.removeTextSelection(),this.documentListeners.add(Z4.SelectionChange,this.removeTextSelection),t(e))}handleMove(e){let{activated:t,initialCoordinates:n,props:r}=this,{onMove:i,options:{activationConstraint:a}}=r;if(!n)return;let o=v4(e)??E4,s=g4(n,o);if(!t&&a){if(n3(a)){if(a.tolerance!=null&&X4(s,a.tolerance))return this.handleCancel();if(X4(s,a.distance))return this.handleStart()}if(r3(a)&&X4(s,a.tolerance))return this.handleCancel();this.handlePending(a,s);return}e.cancelable&&e.preventDefault(),i(o)}handleEnd(){let{onAbort:e,onEnd:t}=this.props;this.detach(),this.activated||e(this.props.active),t()}handleCancel(){let{onAbort:e,onCancel:t}=this.props;this.detach(),this.activated||e(this.props.active),t()}handleKeydown(e){e.code===$4.Esc&&this.handleCancel()}removeTextSelection(){var e;(e=this.document.getSelection())==null||e.removeAllRanges()}},bHe={cancel:{name:`pointercancel`},move:{name:`pointermove`},end:{name:`pointerup`}},a3=class extends i3{constructor(e){let{event:t}=e,n=a4(t.target);super(e,bHe,n)}};a3.activators=[{eventName:`onPointerDown`,handler:(e,t)=>{let{nativeEvent:n}=e,{onActivation:r}=t;return!n.isPrimary||n.button!==0?!1:(r?.({event:n}),!0)}}];var xHe={move:{name:`mousemove`},end:{name:`mouseup`}},o3;(function(e){e[e.RightClick=2]=`RightClick`})(o3||={});var SHe=class extends i3{constructor(e){super(e,xHe,a4(e.event.target))}};SHe.activators=[{eventName:`onMouseDown`,handler:(e,t)=>{let{nativeEvent:n}=e,{onActivation:r}=t;return n.button===o3.RightClick?!1:(r?.({event:n}),!0)}}];var s3={cancel:{name:`touchcancel`},move:{name:`touchmove`},end:{name:`touchend`}},CHe=class extends i3{constructor(e){super(e,s3)}static setup(){return window.addEventListener(s3.move.name,e,{capture:!1,passive:!1}),function(){window.removeEventListener(s3.move.name,e)};function e(){}}};CHe.activators=[{eventName:`onTouchStart`,handler:(e,t)=>{let{nativeEvent:n}=e,{onActivation:r}=t,{touches:i}=n;return i.length>1?!1:(r?.({event:n}),!0)}}];var c3;(function(e){e[e.Pointer=0]=`Pointer`,e[e.DraggableRect=1]=`DraggableRect`})(c3||={});var l3;(function(e){e[e.TreeOrder=0]=`TreeOrder`,e[e.ReversedTreeOrder=1]=`ReversedTreeOrder`})(l3||={});function wHe(e){let{acceleration:t,activator:n=c3.Pointer,canScroll:r,draggingRect:i,enabled:a,interval:o=5,order:s=l3.TreeOrder,pointerCoordinates:c,scrollableAncestors:l,scrollableAncestorRects:u,delta:d,threshold:f}=e,p=EHe({delta:d,disabled:!a}),[m,h]=zVe(),g=(0,y.useRef)({x:0,y:0}),_=(0,y.useRef)({x:0,y:0}),v=(0,y.useMemo)(()=>{switch(n){case c3.Pointer:return c?{top:c.y,bottom:c.y,left:c.x,right:c.x}:null;case c3.DraggableRect:return i}},[n,i,c]),b=(0,y.useRef)(null),x=(0,y.useCallback)(()=>{let e=b.current;if(!e)return;let t=g.current.x*_.current.x,n=g.current.y*_.current.y;e.scrollBy(t,n)},[]),S=(0,y.useMemo)(()=>s===l3.TreeOrder?[...l].reverse():l,[s,l]);(0,y.useEffect)(()=>{if(!a||!l.length||!v){h();return}for(let e of S){if(r?.(e)===!1)continue;let n=u[l.indexOf(e)];if(!n)continue;let{direction:i,speed:a}=fHe(e,n,v,t,f);for(let e of[`x`,`y`])p[e][i[e]]||(a[e]=0,i[e]=0);if(a.x>0||a.y>0){h(),b.current=e,m(x,o),g.current=a,_.current=i;return}}g.current={x:0,y:0},_.current={x:0,y:0},h()},[t,x,r,h,a,o,JSON.stringify(v),JSON.stringify(p),m,l,S,u,JSON.stringify(f)])}var THe={x:{[U4.Backward]:!1,[U4.Forward]:!1},y:{[U4.Backward]:!1,[U4.Forward]:!1}};function EHe(e){let{delta:t,disabled:n}=e,r=d4(t);return l4(e=>{if(n||!r||!e)return THe;let i={x:Math.sign(t.x-r.x),y:Math.sign(t.y-r.y)};return{x:{[U4.Backward]:e.x[U4.Backward]||i.x===-1,[U4.Forward]:e.x[U4.Forward]||i.x===1},y:{[U4.Backward]:e.y[U4.Backward]||i.y===-1,[U4.Forward]:e.y[U4.Forward]||i.y===1}}},[n,t,r])}function DHe(e,t){let n=t==null?void 0:e.get(t),r=n?n.node.current:null;return l4(e=>t==null?null:r??e??null,[r,t])}function OHe(e,t){return(0,y.useMemo)(()=>e.reduce((e,n)=>{let{sensor:r}=n,i=r.activators.map(e=>({eventName:e.eventName,handler:t(e.handler,n)}));return[...e,...i]},[]),[e,t])}var u3;(function(e){e[e.Always=0]=`Always`,e[e.BeforeDragging=1]=`BeforeDragging`,e[e.WhileDragging=2]=`WhileDragging`})(u3||={});var d3;(function(e){e.Optimized=`optimized`})(d3||={});var f3=new Map;function kHe(e,t){let{dragging:n,dependencies:r,config:i}=t,[a,o]=(0,y.useState)(null),{frequency:s,measure:c,strategy:l}=i,u=(0,y.useRef)(e),d=g(),f=c4(d),p=(0,y.useCallback)(function(e){e===void 0&&(e=[]),!f.current&&o(t=>t===null?e:t.concat(e.filter(e=>!t.includes(e))))},[f]),m=(0,y.useRef)(null),h=l4(t=>{if(d&&!n)return f3;if(!t||t===f3||u.current!==e||a!=null){let t=new Map;for(let n of e){if(!n)continue;if(a&&a.length>0&&!a.includes(n.id)&&n.rect.current){t.set(n.id,n.rect.current);continue}let e=n.node.current,r=e?new J4(c(e),e):null;n.rect.current=r,r&&t.set(n.id,r)}return t}return t},[e,a,n,d,c]);return(0,y.useEffect)(()=>{u.current=e},[e]),(0,y.useEffect)(()=>{d||p()},[n,d]),(0,y.useEffect)(()=>{a&&a.length>0&&o(null)},[JSON.stringify(a)]),(0,y.useEffect)(()=>{d||typeof s!=`number`||m.current!==null||(m.current=setTimeout(()=>{p(),m.current=null},s))},[s,d,p,...r]),{droppableRects:h,measureDroppableContainers:p,measuringScheduled:a!=null};function g(){switch(l){case u3.Always:return!1;case u3.BeforeDragging:return n;default:return!n}}}function p3(e,t){return l4(n=>e?n||(typeof t==`function`?t(e):e):null,[t,e])}function AHe(e,t){return p3(e,t)}function jHe(e){let{callback:t,disabled:n}=e,r=s4(t),i=(0,y.useMemo)(()=>{if(n||typeof window>`u`||window.MutationObserver===void 0)return;let{MutationObserver:e}=window;return new e(r)},[r,n]);return(0,y.useEffect)(()=>()=>i?.disconnect(),[i]),i}function m3(e){let{callback:t,disabled:n}=e,r=s4(t),i=(0,y.useMemo)(()=>{if(n||typeof window>`u`||window.ResizeObserver===void 0)return;let{ResizeObserver:e}=window;return new e(r)},[n]);return(0,y.useEffect)(()=>()=>i?.disconnect(),[i]),i}function MHe(e){return new J4(F4(e),e)}function h3(e,t,n){t===void 0&&(t=MHe);let[r,i]=(0,y.useState)(null);function a(){i(r=>{if(!e)return null;if(e.isConnected===!1)return r??n??null;let i=t(e);return JSON.stringify(r)===JSON.stringify(i)?r:i})}let o=jHe({callback(t){if(e)for(let n of t){let{type:t,target:r}=n;if(t===`childList`&&r instanceof HTMLElement&&r.contains(e)){a();break}}}}),s=m3({callback:a});return o4(()=>{a(),e?(s?.observe(e),o?.observe(document.body,{childList:!0,subtree:!0})):(s?.disconnect(),o?.disconnect())},[e]),r}function NHe(e){return N4(e,p3(e))}var g3=[];function PHe(e){let t=(0,y.useRef)(e),n=l4(n=>e?n&&n!==g3&&e&&t.current&&e.parentNode===t.current.parentNode?n:L4(e):g3,[e]);return(0,y.useEffect)(()=>{t.current=e},[e]),n}function FHe(e){let[t,n]=(0,y.useState)(null),r=(0,y.useRef)(e),i=(0,y.useCallback)(e=>{let t=z4(e.target);t&&n(e=>e?(e.set(t,H4(t)),new Map(e)):null)},[]);return(0,y.useEffect)(()=>{let t=r.current;if(e!==t){a(t);let o=e.map(e=>{let t=z4(e);return t?(t.addEventListener(`scroll`,i,{passive:!0}),[t,H4(t)]):null}).filter(e=>e!=null);n(o.length?new Map(o):null),r.current=e}return()=>{a(e),a(t)};function a(e){e.forEach(e=>{z4(e)?.removeEventListener(`scroll`,i)})}},[i,e]),(0,y.useMemo)(()=>e.length?t?Array.from(t.values()).reduce((e,t)=>h4(e,t),E4):K4(e):E4,[e,t])}function _3(e,t){t===void 0&&(t=[]);let n=(0,y.useRef)(null);return(0,y.useEffect)(()=>{n.current=null},t),(0,y.useEffect)(()=>{let t=e!==E4;t&&!n.current&&(n.current=e),!t&&n.current&&(n.current=null)},[e]),n.current?g4(e,n.current):E4}function IHe(e){(0,y.useEffect)(()=>{if(!Q2)return;let t=e.map(e=>{let{sensor:t}=e;return t.setup==null?void 0:t.setup()});return()=>{for(let e of t)e?.()}},e.map(e=>{let{sensor:t}=e;return t}))}function LHe(e,t){return(0,y.useMemo)(()=>e.reduce((e,n)=>{let{eventName:r,handler:i}=n;return e[r]=e=>{i(e,t)},e},{}),[e,t])}function v3(e){return(0,y.useMemo)(()=>e?cHe(e):null,[e])}var y3=[];function RHe(e,t){t===void 0&&(t=F4);let[n]=e,r=v3(n?t4(n):null),[i,a]=(0,y.useState)(y3);function o(){a(()=>e.length?e.map(e=>W4(e)?r:new J4(t(e),e)):y3)}let s=m3({callback:o});return o4(()=>{s?.disconnect(),o(),e.forEach(e=>s?.observe(e))},[e]),i}function b3(e){if(!e)return null;if(e.children.length>1)return e;let t=e.children[0];return r4(t)?t:e}function zHe(e){let{measure:t}=e,[n,r]=(0,y.useState)(null),i=m3({callback:(0,y.useCallback)(e=>{for(let{target:n}of e)if(r4(n)){r(e=>{let r=t(n);return e?{...e,width:r.width,height:r.height}:r});break}},[t])}),[a,o]=u4((0,y.useCallback)(e=>{let n=b3(e);i?.disconnect(),n&&i?.observe(n),r(n?t(n):null)},[t,i]));return(0,y.useMemo)(()=>({nodeRef:a,rect:n,setRef:o}),[n,a,o])}var BHe=[{sensor:a3,options:{}},{sensor:t3,options:{}}],VHe={current:{}},x3={draggable:{measure:I4},droppable:{measure:I4,strategy:u3.WhileDragging,frequency:d3.Optimized},dragOverlay:{measure:F4}},S3=class extends Map{get(e){return e==null?void 0:super.get(e)??void 0}toArray(){return Array.from(this.values())}getEnabled(){return this.toArray().filter(e=>{let{disabled:t}=e;return!t})}getNodeFor(e){return this.get(e)?.node.current??void 0}},HHe={activatorEvent:null,active:null,activeNode:null,activeNodeRect:null,collisions:null,containerNodeRect:null,draggableNodes:new Map,droppableRects:new Map,droppableContainers:new S3,over:null,dragOverlay:{nodeRef:{current:null},rect:null,setRef:C4},scrollableAncestors:[],scrollableAncestorRects:[],measuringConfiguration:x3,measureDroppableContainers:C4,windowRect:null,measuringScheduled:!1},C3={activatorEvent:null,activators:[],active:null,activeNodeRect:null,ariaDescribedById:{draggable:``},dispatch:C4,draggableNodes:new Map,over:null,measureDroppableContainers:C4},w3=(0,y.createContext)(C3),T3=(0,y.createContext)(HHe);function UHe(){return{draggable:{active:null,initialCoordinates:{x:0,y:0},nodes:new Map,translate:{x:0,y:0}},droppable:{containers:new S3}}}function WHe(e,t){switch(t.type){case S4.DragStart:return{...e,draggable:{...e.draggable,initialCoordinates:t.initialCoordinates,active:t.active}};case S4.DragMove:return e.draggable.active==null?e:{...e,draggable:{...e.draggable,translate:{x:t.coordinates.x-e.draggable.initialCoordinates.x,y:t.coordinates.y-e.draggable.initialCoordinates.y}}};case S4.DragEnd:case S4.DragCancel:return{...e,draggable:{...e.draggable,active:null,initialCoordinates:{x:0,y:0},translate:{x:0,y:0}}};case S4.RegisterDroppable:{let{element:n}=t,{id:r}=n,i=new S3(e.droppable.containers);return i.set(r,n),{...e,droppable:{...e.droppable,containers:i}}}case S4.SetDroppableDisabled:{let{id:n,key:r,disabled:i}=t,a=e.droppable.containers.get(n);if(!a||r!==a.key)return e;let o=new S3(e.droppable.containers);return o.set(n,{...a,disabled:i}),{...e,droppable:{...e.droppable,containers:o}}}case S4.UnregisterDroppable:{let{id:n,key:r}=t,i=e.droppable.containers.get(n);if(!i||r!==i.key)return e;let a=new S3(e.droppable.containers);return a.delete(n),{...e,droppable:{...e.droppable,containers:a}}}default:return e}}function GHe(e){let{disabled:t}=e,{active:n,activatorEvent:r,draggableNodes:i}=(0,y.useContext)(w3),a=d4(r),o=d4(n?.id);return(0,y.useEffect)(()=>{if(!t&&!r&&a&&o!=null){if(!_4(a)||document.activeElement===a.target)return;let e=i.get(o);if(!e)return;let{activatorNode:t,node:n}=e;if(!t.current&&!n.current)return;requestAnimationFrame(()=>{for(let e of[t.current,n.current]){if(!e)continue;let t=HVe(e);if(t){t.focus();break}}})}},[r,t,i,o,a]),null}function E3(e,t){let{transform:n,...r}=t;return e!=null&&e.length?e.reduce((e,t)=>t({transform:e,...r}),n):n}function KHe(e){return(0,y.useMemo)(()=>({draggable:{...x3.draggable,...e?.draggable},droppable:{...x3.droppable,...e?.droppable},dragOverlay:{...x3.dragOverlay,...e?.dragOverlay}}),[e?.draggable,e?.droppable,e?.dragOverlay])}function qHe(e){let{activeNode:t,measure:n,initialRect:r,config:i=!0}=e,a=(0,y.useRef)(!1),{x:o,y:s}=typeof i==`boolean`?{x:i,y:i}:i;o4(()=>{if(!o&&!s||!t){a.current=!1;return}if(a.current||!r)return;let e=t?.node.current;if(!e||e.isConnected===!1)return;let i=N4(n(e),r);if(o||(i.x=0),s||(i.y=0),a.current=!0,Math.abs(i.x)>0||Math.abs(i.y)>0){let t=R4(e);t&&t.scrollBy({top:i.y,left:i.x})}},[t,o,s,r,n])}var D3=(0,y.createContext)({...E4,scaleX:1,scaleY:1}),O3;(function(e){e[e.Uninitialized=0]=`Uninitialized`,e[e.Initializing=1]=`Initializing`,e[e.Initialized=2]=`Initialized`})(O3||={});var k3=(0,y.memo)(function(e){let{id:t,accessibility:n,autoScroll:r=!0,children:i,sensors:a=BHe,collisionDetection:o=nHe,measuring:s,modifiers:c,...l}=e,[u,d]=(0,y.useReducer)(WHe,void 0,UHe),[f,p]=JVe(),[m,h]=(0,y.useState)(O3.Uninitialized),g=m===O3.Initialized,{draggable:{active:_,nodes:v,translate:b},droppable:{containers:x}}=u,S=_==null?null:v.get(_),C=(0,y.useRef)({initial:null,translated:null}),w=(0,y.useMemo)(()=>_==null?null:{id:_,data:S?.data??VHe,rect:C},[_,S]),T=(0,y.useRef)(null),[E,D]=(0,y.useState)(null),[O,k]=(0,y.useState)(null),A=c4(l,Object.values(l)),j=p4(`DndDescribedBy`,t),M=(0,y.useMemo)(()=>x.getEnabled(),[x]),N=KHe(s),{droppableRects:P,measureDroppableContainers:F,measuringScheduled:I}=kHe(M,{dragging:g,dependencies:[b.x,b.y],config:N.droppable}),L=DHe(v,_),R=(0,y.useMemo)(()=>O?v4(O):null,[O]),z=De(),B=AHe(L,N.draggable.measure);qHe({activeNode:_==null?null:v.get(_),config:z.layoutShiftCompensation,initialRect:B,measure:N.draggable.measure});let V=h3(L,N.draggable.measure,B),ee=h3(L?L.parentElement:null),te=(0,y.useRef)({activatorEvent:null,active:null,activeNode:L,collisionRect:null,collisions:null,droppableRects:P,draggableNodes:v,draggingNode:null,draggingNodeRect:null,droppableContainers:x,over:null,scrollableAncestors:[],scrollAdjustedTranslate:null}),ne=x.getNodeFor(te.current.over?.id),re=zHe({measure:N.dragOverlay.measure}),ie=re.nodeRef.current??L,ae=g?re.rect??V:null,oe=!!(re.nodeRef.current&&re.rect),se=NHe(oe?null:V),H=v3(ie?t4(ie):null),ce=PHe(g?ne??L:null),le=RHe(ce),ue=E3(c,{transform:{x:b.x-se.x,y:b.y-se.y,scaleX:1,scaleY:1},activatorEvent:O,active:w,activeNodeRect:V,containerNodeRect:ee,draggingNodeRect:ae,over:te.current.over,overlayNodeRect:re.rect,scrollableAncestors:ce,scrollableAncestorRects:le,windowRect:H}),de=R?h4(R,b):null,fe=FHe(ce),pe=_3(fe),me=_3(fe,[V]),he=h4(ue,pe),ge=ae?aHe(ae,ue):null,_e=w&&ge?o({active:w,collisionRect:ge,droppableRects:P,droppableContainers:M,pointerCoordinates:de}):null,ve=A4(_e,`id`),[ye,be]=(0,y.useState)(null),xe=rHe(oe?ue:h4(ue,me),ye?.rect??null,V),Se=(0,y.useRef)(null),Ce=(0,y.useCallback)((e,t)=>{let{sensor:n,options:r}=t;if(T.current==null)return;let i=v.get(T.current);if(!i)return;let a=e.nativeEvent;Se.current=new n({active:T.current,activeNode:i,event:a,options:r,context:te,onAbort(e){if(!v.get(e))return;let{onDragAbort:t}=A.current,n={id:e};t?.(n),f({type:`onDragAbort`,event:n})},onPending(e,t,n,r){if(!v.get(e))return;let{onDragPending:i}=A.current,a={id:e,constraint:t,initialCoordinates:n,offset:r};i?.(a),f({type:`onDragPending`,event:a})},onStart(e){let t=T.current;if(t==null)return;let n=v.get(t);if(!n)return;let{onDragStart:r}=A.current,i={activatorEvent:a,active:{id:t,data:n.data,rect:C}};(0,At.unstable_batchedUpdates)(()=>{r?.(i),h(O3.Initializing),d({type:S4.DragStart,initialCoordinates:e,active:t}),f({type:`onDragStart`,event:i}),D(Se.current),k(a)})},onMove(e){d({type:S4.DragMove,coordinates:e})},onEnd:o(S4.DragEnd),onCancel:o(S4.DragCancel)});function o(e){return async function(){let{active:t,collisions:n,over:r,scrollAdjustedTranslate:i}=te.current,o=null;if(t&&i){let{cancelDrop:s}=A.current;o={activatorEvent:a,active:t,collisions:n,delta:i,over:r},e===S4.DragEnd&&typeof s==`function`&&await Promise.resolve(s(o))&&(e=S4.DragCancel)}T.current=null,(0,At.unstable_batchedUpdates)(()=>{d({type:e}),h(O3.Uninitialized),be(null),D(null),k(null),Se.current=null;let t=e===S4.DragEnd?`onDragEnd`:`onDragCancel`;if(o){let e=A.current[t];e?.(o),f({type:t,event:o})}})}}},[v]),we=OHe(a,(0,y.useCallback)((e,t)=>(n,r)=>{let i=n.nativeEvent,a=v.get(r);if(T.current!==null||!a||i.dndKit||i.defaultPrevented)return;let o={active:a};e(n,t.options,o)===!0&&(i.dndKit={capturedBy:t.sensor},T.current=r,Ce(n,t))},[v,Ce]));IHe(a),o4(()=>{V&&m===O3.Initializing&&h(O3.Initialized)},[V,m]),(0,y.useEffect)(()=>{let{onDragMove:e}=A.current,{active:t,activatorEvent:n,collisions:r,over:i}=te.current;if(!t||!n)return;let a={active:t,activatorEvent:n,collisions:r,delta:{x:he.x,y:he.y},over:i};(0,At.unstable_batchedUpdates)(()=>{e?.(a),f({type:`onDragMove`,event:a})})},[he.x,he.y]),(0,y.useEffect)(()=>{let{active:e,activatorEvent:t,collisions:n,droppableContainers:r,scrollAdjustedTranslate:i}=te.current;if(!e||T.current==null||!t||!i)return;let{onDragOver:a}=A.current,o=r.get(ve),s=o&&o.rect.current?{id:o.id,rect:o.rect.current,data:o.data,disabled:o.disabled}:null,c={active:e,activatorEvent:t,collisions:n,delta:{x:i.x,y:i.y},over:s};(0,At.unstable_batchedUpdates)(()=>{be(s),a?.(c),f({type:`onDragOver`,event:c})})},[ve]),o4(()=>{te.current={activatorEvent:O,active:w,activeNode:L,collisionRect:ge,collisions:_e,droppableRects:P,draggableNodes:v,draggingNode:ie,draggingNodeRect:ae,droppableContainers:x,over:ye,scrollableAncestors:ce,scrollAdjustedTranslate:he},C.current={initial:ae,translated:ge}},[w,L,_e,ge,v,ie,ae,P,x,ye,ce,he]),wHe({...z,delta:b,draggingRect:ge,pointerCoordinates:de,scrollableAncestors:ce,scrollableAncestorRects:le});let Te=(0,y.useMemo)(()=>({active:w,activeNode:L,activeNodeRect:V,activatorEvent:O,collisions:_e,containerNodeRect:ee,dragOverlay:re,draggableNodes:v,droppableContainers:x,droppableRects:P,over:ye,measureDroppableContainers:F,scrollableAncestors:ce,scrollableAncestorRects:le,measuringConfiguration:N,measuringScheduled:I,windowRect:H}),[w,L,V,O,_e,ee,re,v,x,P,ye,F,ce,le,N,I,H]),Ee=(0,y.useMemo)(()=>({activatorEvent:O,activators:we,active:w,activeNodeRect:V,ariaDescribedById:{draggable:j},dispatch:d,draggableNodes:v,over:ye,measureDroppableContainers:F}),[O,we,w,V,d,j,v,ye,F]);return y.createElement(x4.Provider,{value:p},y.createElement(w3.Provider,{value:Ee},y.createElement(T3.Provider,{value:Te},y.createElement(D3.Provider,{value:xe},i)),y.createElement(GHe,{disabled:n?.restoreFocus===!1})),y.createElement(ZVe,{...n,hiddenTextDescribedById:j}));function De(){let e=E?.autoScrollEnabled===!1,t=typeof r==`object`?r.enabled===!1:r===!1,n=g&&!e&&!t;return typeof r==`object`?{...r,enabled:n}:{enabled:n}}}),JHe=(0,y.createContext)(null),A3=`button`,YHe=`Draggable`;function XHe(e){let{id:t,data:n,disabled:r=!1,attributes:i}=e,a=p4(YHe),{activators:o,activatorEvent:s,active:c,activeNodeRect:l,ariaDescribedById:u,draggableNodes:d,over:f}=(0,y.useContext)(w3),{role:p=A3,roleDescription:m=`draggable`,tabIndex:h=0}=i??{},g=c?.id===t,_=(0,y.useContext)(g?D3:JHe),[v,b]=u4(),[x,S]=u4(),C=LHe(o,t),w=c4(n);return o4(()=>(d.set(t,{id:t,key:a,node:v,activatorNode:x,data:w}),()=>{let e=d.get(t);e&&e.key===a&&d.delete(t)}),[d,t]),{active:c,activatorEvent:s,activeNodeRect:l,attributes:(0,y.useMemo)(()=>({role:p,tabIndex:h,"aria-disabled":r,"aria-pressed":g&&p===A3?!0:void 0,"aria-roledescription":m,"aria-describedby":u.draggable}),[r,p,h,g,m,u.draggable]),isDragging:g,listeners:r?void 0:C,node:v,over:f,setNodeRef:b,setActivatorNodeRef:S,transform:_}}function j3(){return(0,y.useContext)(T3)}var ZHe=`Droppable`,QHe={timeout:25};function $He(e){let{data:t,disabled:n=!1,id:r,resizeObserverConfig:i}=e,a=p4(ZHe),{active:o,dispatch:s,over:c,measureDroppableContainers:l}=(0,y.useContext)(w3),u=(0,y.useRef)({disabled:n}),d=(0,y.useRef)(!1),f=(0,y.useRef)(null),p=(0,y.useRef)(null),{disabled:m,updateMeasurementsFor:h,timeout:g}={...QHe,...i},_=c4(h??r),v=m3({callback:(0,y.useCallback)(()=>{if(!d.current){d.current=!0;return}p.current!=null&&clearTimeout(p.current),p.current=setTimeout(()=>{l(Array.isArray(_.current)?_.current:[_.current]),p.current=null},g)},[g]),disabled:m||!o}),[b,x]=u4((0,y.useCallback)((e,t)=>{v&&(t&&(v.unobserve(t),d.current=!1),e&&v.observe(e))},[v])),S=c4(t);return(0,y.useEffect)(()=>{!v||!b.current||(v.disconnect(),d.current=!1,v.observe(b.current))},[b,v]),(0,y.useEffect)(()=>(s({type:S4.RegisterDroppable,element:{id:r,key:a,disabled:n,node:b,rect:f,data:S}}),()=>s({type:S4.UnregisterDroppable,key:a,id:r})),[r]),(0,y.useEffect)(()=>{n!==u.current.disabled&&(s({type:S4.SetDroppableDisabled,id:r,key:a,disabled:n}),u.current.disabled=n)},[r,a,n,s]),{active:o,rect:f,isOver:c?.id===r,node:b,over:c,setNodeRef:x}}function eUe(e){let{animation:t,children:n}=e,[r,i]=(0,y.useState)(null),[a,o]=(0,y.useState)(null),s=d4(n);return!n&&!r&&s&&i(s),o4(()=>{if(!a)return;let e=r?.key,n=r?.props.id;if(e==null||n==null){i(null);return}Promise.resolve(t(n,a)).then(()=>{i(null)})},[t,r,a]),y.createElement(y.Fragment,null,n,r?(0,y.cloneElement)(r,{ref:o}):null)}var tUe={x:0,y:0,scaleX:1,scaleY:1};function nUe(e){let{children:t}=e;return y.createElement(w3.Provider,{value:C3},y.createElement(D3.Provider,{value:tUe},t))}var rUe={position:`fixed`,touchAction:`none`},iUe=e=>_4(e)?`transform 250ms ease`:void 0,aUe=(0,y.forwardRef)((e,t)=>{let{as:n,activatorEvent:r,adjustScale:i,children:a,className:o,rect:s,style:c,transform:l,transition:u=iUe}=e;if(!s)return null;let d=i?l:{...l,scaleX:1,scaleY:1},f={...rUe,width:s.width,height:s.height,top:s.top,left:s.left,transform:y4.Transform.toString(d),transformOrigin:i&&r?QVe(r,s):void 0,transition:typeof u==`function`?u(r):u,...c};return y.createElement(n,{className:o,style:f,ref:t},a)}),oUe={duration:250,easing:`ease`,keyframes:e=>{let{transform:{initial:t,final:n}}=e;return[{transform:y4.Transform.toString(t)},{transform:y4.Transform.toString(n)}]},sideEffects:(e=>t=>{let{active:n,dragOverlay:r}=t,i={},{styles:a,className:o}=e;if(a!=null&&a.active)for(let[e,t]of Object.entries(a.active))t!==void 0&&(i[e]=n.node.style.getPropertyValue(e),n.node.style.setProperty(e,t));if(a!=null&&a.dragOverlay)for(let[e,t]of Object.entries(a.dragOverlay))t!==void 0&&r.node.style.setProperty(e,t);return o!=null&&o.active&&n.node.classList.add(o.active),o!=null&&o.dragOverlay&&r.node.classList.add(o.dragOverlay),function(){for(let[e,t]of Object.entries(i))n.node.style.setProperty(e,t);o!=null&&o.active&&n.node.classList.remove(o.active)}})({styles:{active:{opacity:`0`}}})};function sUe(e){let{config:t,draggableNodes:n,droppableContainers:r,measuringConfiguration:i}=e;return s4((e,a)=>{if(t===null)return;let o=n.get(e);if(!o)return;let s=o.node.current;if(!s)return;let c=b3(a);if(!c)return;let{transform:l}=t4(a).getComputedStyle(a),u=P4(l);if(!u)return;let d=typeof t==`function`?t:cUe(t);return q4(s,i.draggable.measure),d({active:{id:e,data:o.data,node:s,rect:i.draggable.measure(s)},draggableNodes:n,dragOverlay:{node:a,rect:i.dragOverlay.measure(c)},droppableContainers:r,measuringConfiguration:i,transform:u})})}function cUe(e){let{duration:t,easing:n,sideEffects:r,keyframes:i}={...oUe,...e};return e=>{let{active:a,dragOverlay:o,transform:s,...c}=e;if(!t)return;let l={x:o.rect.left-a.rect.left,y:o.rect.top-a.rect.top},u={scaleX:s.scaleX===1?1:a.rect.width*s.scaleX/o.rect.width,scaleY:s.scaleY===1?1:a.rect.height*s.scaleY/o.rect.height},d={x:s.x-l.x,y:s.y-l.y,...u},f=i({...c,active:a,dragOverlay:o,transform:{initial:s,final:d}}),[p]=f,m=f[f.length-1];if(JSON.stringify(p)===JSON.stringify(m))return;let h=r?.({active:a,dragOverlay:o,...c}),g=o.node.animate(f,{duration:t,easing:n,fill:`forwards`});return new Promise(e=>{g.onfinish=()=>{h?.(),e()}})}}var M3=0;function lUe(e){return(0,y.useMemo)(()=>{if(e!=null)return M3++,M3},[e])}var uUe=y.memo(e=>{let{adjustScale:t=!1,children:n,dropAnimation:r,style:i,transition:a,modifiers:o,wrapperElement:s=`div`,className:c,zIndex:l=999}=e,{activatorEvent:u,active:d,activeNodeRect:f,containerNodeRect:p,draggableNodes:m,droppableContainers:h,dragOverlay:g,over:_,measuringConfiguration:v,scrollableAncestors:b,scrollableAncestorRects:x,windowRect:S}=j3(),C=(0,y.useContext)(D3),w=lUe(d?.id),T=E3(o,{activatorEvent:u,active:d,activeNodeRect:f,containerNodeRect:p,draggingNodeRect:g.rect,over:_,overlayNodeRect:g.rect,scrollableAncestors:b,scrollableAncestorRects:x,transform:C,windowRect:S}),E=p3(f),D=sUe({config:r,draggableNodes:m,droppableContainers:h,measuringConfiguration:v}),O=E?g.setRef:void 0;return y.createElement(nUe,null,y.createElement(eUe,{animation:D},d&&w?y.createElement(aUe,{key:w,id:d.id,ref:O,as:s,activatorEvent:u,adjustScale:t,className:c,transition:a,rect:E,style:{zIndex:l,...i},transform:T},n):null))});function N3(e,t,n){let r=e.slice();return r.splice(n<0?r.length+n:n,0,r.splice(t,1)[0]),r}function dUe(e,t){return e.reduce((e,n,r)=>{let i=t.get(n);return i&&(e[r]=i),e},Array(e.length))}function P3(e){return e!==null&&e>=0}function fUe(e,t){if(e===t)return!0;if(e.length!==t.length)return!1;for(let n=0;n{let{rects:t,activeIndex:n,overIndex:r,index:i}=e,a=N3(t,r,n),o=t[i],s=a[i];return!s||!o?null:{x:s.left-o.left,y:s.top-o.top,scaleX:s.width/o.width,scaleY:s.height/o.height}},I3={scaleX:1,scaleY:1},mUe=e=>{let{activeIndex:t,activeNodeRect:n,index:r,rects:i,overIndex:a}=e,o=i[t]??n;if(!o)return null;if(r===t){let e=i[a];return e?{x:0,y:tt&&r<=a?{x:0,y:-o.height-s,...I3}:r=a?{x:0,y:o.height+s,...I3}:{x:0,y:0,...I3}};function hUe(e,t,n){let r=e[t],i=e[t-1],a=e[t+1];return r?nr.map(e=>typeof e==`object`&&`id`in e?e.id:e),[r]),m=o!=null,h=o?p.indexOf(o.id):-1,g=l?p.indexOf(l.id):-1,_=(0,y.useRef)(p),v=!fUe(p,_.current),b=g!==-1&&h===-1||v,x=pUe(a);o4(()=>{v&&m&&u(p)},[v,p,m,u]),(0,y.useEffect)(()=>{_.current=p},[p]);let S=(0,y.useMemo)(()=>({activeIndex:h,containerId:d,disabled:x,disableTransforms:b,items:p,overIndex:g,useDragOverlay:f,sortedRects:dUe(p,c),strategy:i}),[h,d,x.draggable,x.droppable,b,p,g,c,f,i]);return y.createElement(R3.Provider,{value:S},t)}var gUe=e=>{let{id:t,items:n,activeIndex:r,overIndex:i}=e;return N3(n,r,i).indexOf(t)},_Ue=e=>{let{containerId:t,isSorting:n,wasDragging:r,index:i,items:a,newIndex:o,previousItems:s,previousContainerId:c,transition:l}=e;return!l||!r||s!==a&&i===o?!1:n?!0:o!==i&&t===c},vUe={duration:200,easing:`ease`},B3=`transform`,yUe=y4.Transition.toString({property:B3,duration:0,easing:`linear`}),bUe={roleDescription:`sortable`};function xUe(e){let{disabled:t,index:n,node:r,rect:i}=e,[a,o]=(0,y.useState)(null),s=(0,y.useRef)(n);return o4(()=>{if(!t&&n!==s.current&&r.current){let e=i.current;if(e){let t=F4(r.current,{ignoreTransform:!0}),n={x:e.left-t.left,y:e.top-t.top,scaleX:e.width/t.width,scaleY:e.height/t.height};(n.x||n.y)&&o(n)}}n!==s.current&&(s.current=n)},[t,n,r,i]),(0,y.useEffect)(()=>{a&&o(null)},[a]),a}function V3(e){let{animateLayoutChanges:t=_Ue,attributes:n,disabled:r,data:i,getNewIndex:a=gUe,id:o,strategy:s,resizeObserverConfig:c,transition:l=vUe}=e,{items:u,containerId:d,activeIndex:f,disabled:p,disableTransforms:m,sortedRects:h,overIndex:g,useDragOverlay:_,strategy:v}=(0,y.useContext)(R3),b=SUe(r,p),x=u.indexOf(o),S=(0,y.useMemo)(()=>({sortable:{containerId:d,index:x,items:u},...i}),[d,i,x,u]),C=(0,y.useMemo)(()=>u.slice(u.indexOf(o)),[u,o]),{rect:w,node:T,isOver:E,setNodeRef:D}=$He({id:o,data:S,disabled:b.droppable,resizeObserverConfig:{updateMeasurementsFor:C,...c}}),{active:O,activatorEvent:k,activeNodeRect:A,attributes:j,setNodeRef:M,listeners:N,isDragging:P,over:F,setActivatorNodeRef:I,transform:L}=XHe({id:o,data:S,attributes:{...bUe,...n},disabled:b.draggable}),R=RVe(D,M),z=!!O,B=z&&!m&&P3(f)&&P3(g),V=!_&&P,ee=B?(V&&B?L:null)??(s??v)({rects:h,activeNodeRect:A,activeIndex:f,overIndex:g,index:x}):null,te=P3(f)&&P3(g)?a({id:o,items:u,activeIndex:f,overIndex:g}):x,ne=O?.id,re=(0,y.useRef)({activeId:ne,items:u,newIndex:te,containerId:d}),ie=u!==re.current.items,ae=t({active:O,containerId:d,isDragging:P,isSorting:z,id:o,index:x,items:u,newIndex:re.current.newIndex,previousItems:re.current.items,previousContainerId:re.current.containerId,transition:l,wasDragging:re.current.activeId!=null}),oe=xUe({disabled:!ae,index:x,node:T,rect:w});return(0,y.useEffect)(()=>{z&&re.current.newIndex!==te&&(re.current.newIndex=te),d!==re.current.containerId&&(re.current.containerId=d),u!==re.current.items&&(re.current.items=u)},[z,te,d,u]),(0,y.useEffect)(()=>{if(ne===re.current.activeId)return;if(ne!=null&&re.current.activeId==null){re.current.activeId=ne;return}let e=setTimeout(()=>{re.current.activeId=ne},50);return()=>clearTimeout(e)},[ne]),{active:O,activeIndex:f,attributes:j,data:S,rect:w,index:x,newIndex:te,items:u,isOver:E,isSorting:z,isDragging:P,listeners:N,node:T,overIndex:g,over:F,setNodeRef:R,setActivatorNodeRef:I,setDroppableNodeRef:D,setDraggableNodeRef:M,transform:oe??ee,transition:se()};function se(){if(oe||ie&&re.current.newIndex===x)return yUe;if(!(V&&!_4(k)||!l)&&(z||ae))return y4.Transition.toString({...l,property:B3})}}function SUe(e,t){return typeof e==`boolean`?{draggable:e,droppable:!1}:{draggable:e?.draggable??t.draggable,droppable:e?.droppable??t.droppable}}function H3(e){if(!e)return!1;let t=e.data.current;return!!(t&&`sortable`in t&&typeof t.sortable==`object`&&`containerId`in t.sortable&&`items`in t.sortable&&`index`in t.sortable)}var CUe=[$4.Down,$4.Right,$4.Up,$4.Left],U3=(e,t)=>{let{context:{active:n,collisionRect:r,droppableRects:i,droppableContainers:a,over:o,scrollableAncestors:s}}=t;if(CUe.includes(e.code)){if(e.preventDefault(),!n||!r)return;let t=[];a.getEnabled().forEach(n=>{if(!n||n!=null&&n.disabled)return;let a=i.get(n.id);if(a)switch(e.code){case $4.Down:r.topa.top&&t.push(n);break;case $4.Left:r.left>a.left&&t.push(n);break;case $4.Right:r.left1&&(l=c[1].id),l!=null){let e=a.get(n.id),t=a.get(l),o=t?i.get(t.id):null,c=t?.node.current;if(c&&o&&e&&t){let n=L4(c).some((e,t)=>s[t]!==e),i=W3(e,t),a=wUe(e,t),l=n||!i?{x:0,y:0}:{x:a?r.width-o.width:0,y:a?r.height-o.height:0},u={x:o.left,y:o.top};return l.x&&l.y?u:g4(u,l)}}}};function W3(e,t){return!H3(e)||!H3(t)?!1:e.data.current.sortable.containerId===t.data.current.sortable.containerId}function wUe(e,t){return!H3(e)||!H3(t)||!W3(e,t)?!1:e.data.current.sortable.indexZ.listSlicerPipelines()}),{data:g}=K({queryKey:[`printers`],queryFn:()=>Z.getPrinters()}),_=(g??[]).reduce((e,t)=>(e[t.id]=t,e),{}),v=s.startsWith(`p:`)?parseInt(s.slice(2),10):void 0,b=s.startsWith(`c:`)?s.slice(2):void 0,{data:x,isLoading:S}=K({queryKey:[`pipeline-runs-all`,r,a,l,s],queryFn:()=>Z.listAllPipelineRuns({limit:G3,offset:l,pipelineId:a??void 0,status:r||void 0,targetPrinterId:v,targetModelClass:b}),refetchInterval:15e3}),C=q({mutationFn:e=>Z.cancelPipelineRun(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`pipeline-runs-all`]}),n(e(`pipelineRuns.toast.cancelled`,`Run cancelled`),`success`)},onError:t=>n(t.message||e(`pipelineRuns.toast.cancelFailed`,`Cancel failed`),`error`)}),w=q({mutationFn:e=>Z.retryFailedPipelineRun(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`pipeline-runs-all`]}),n(e(`pipelineRuns.toast.retryStarted`,`Retry started`),`success`)},onError:t=>n(t.message||e(`pipelineRuns.toast.retryFailed`,`Retry failed`),`error`)}),T=q({mutationFn:()=>Z.clearTerminalPipelineRuns(),onSuccess:r=>{t.invalidateQueries({queryKey:[`pipeline-runs-all`]}),m(!1),u(0),n(e(`pipelineRuns.toast.cleared`,`{{n}} runs cleared`,{n:r.deleted}),`success`)},onError:t=>n(t.message||e(`pipelineRuns.toast.clearFailed`,`Clear failed`),`error`)}),E=x?.runs??[],D=x?.total??0,O=(h?.pipelines??[]).reduce((e,t)=>(e[t.id]=t,e),{}),k=e=>{f(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},A=!!(r||a!==null||s),j=(()=>{let e=new Set,t=new Set;for(let n of h?.pipelines??[])n.target_kind===`printer_class`&&n.target_model_class?t.add(n.target_model_class):n.target_printer_id&&e.add(n.target_printer_id);return{printers:(g??[]).filter(t=>e.has(t.id)),classes:Array.from(t).sort()}})();return(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 mb-4 text-sm`,children:[(0,G.jsx)(`button`,{type:`button`,onClick:()=>t.invalidateQueries({queryKey:[`pipeline-runs-all`]}),"aria-label":e(`common.refresh`,`Refresh`),title:e(`common.refresh`,`Refresh`),className:`p-1.5 text-bambu-gray hover:text-white border border-bambu-dark-tertiary rounded`,children:(0,G.jsx)(Hl,{className:`w-3.5 h-3.5`})}),(0,G.jsx)(K3,{icon:(0,G.jsx)(ed,{className:`w-3.5 h-3.5 text-bambu-gray`}),ariaLabel:e(`pipelineRuns.filter.pipeline`,`Pipeline`),value:a===null?``:String(a),onChange:e=>{u(0),o(e?parseInt(e,10):null)},options:[{value:``,label:e(`pipelineRuns.filter.allPipelines`,`All pipelines`)},...(h?.pipelines??[]).map(e=>({value:String(e.id),label:e.name}))]}),(0,G.jsx)(K3,{icon:(0,G.jsx)(wc,{className:`w-3.5 h-3.5 text-bambu-gray`}),ariaLabel:e(`pipelineRuns.filter.status`,`Status`),value:r,onChange:e=>{u(0),i(e)},options:TUe.map(t=>({value:t,label:t===``?e(`pipelineRuns.filter.allStatus`,`All statuses`):e(`settings.pipelines.runs.status.${t}`,t)}))}),(j.printers.length>0||j.classes.length>0)&&(0,G.jsx)(K3,{icon:(0,G.jsx)(Rl,{className:`w-3.5 h-3.5 text-bambu-gray`}),ariaLabel:e(`pipelineRuns.filter.target`,`Target`),value:s,onChange:e=>{u(0),c(e)},options:[{value:``,label:e(`pipelineRuns.filter.allTargets`,`All targets`)},...j.printers.map(t=>({value:`p:${t.id}`,label:t.name,group:e(`settings.pipelines.field.targetKindSpecific`,`Specific printer`)})),...j.classes.map(t=>({value:`c:${t}`,label:e(`library.runWithPipeline.classTarget`,`Any {{model}}`,{model:t}),group:e(`settings.pipelines.field.targetKindClass`,`Printer class`)}))]}),A&&(0,G.jsx)(`button`,{type:`button`,onClick:()=>{i(``),o(null),c(``),u(0)},className:`text-xs text-bambu-gray hover:text-white`,children:e(`pipelineRuns.filter.clear`,`Clear filters`)}),(0,G.jsxs)(`div`,{className:`ml-auto flex items-center gap-2 text-xs text-bambu-gray`,children:[!S&&D>0&&(0,G.jsx)(`span`,{children:e(`pipelineRuns.totalCount`,`{{n}} run`,{n:D,count:D})}),(0,G.jsxs)(`button`,{type:`button`,onClick:()=>m(!0),disabled:D===0,className:`flex items-center gap-1 px-2 py-1 text-red-700 dark:text-red-400 hover:bg-red-50 dark:hover:bg-red-500/10 rounded disabled:opacity-50 disabled:cursor-not-allowed`,children:[(0,G.jsx)(Pu,{className:`w-3 h-3`}),e(`pipelineRuns.clearLog`,`Clear log`)]})]})]}),p&&(0,G.jsx)(`div`,{className:`fixed inset-0 z-50 bg-black/60 flex items-center justify-center p-4`,onClick:()=>m(!1),role:`dialog`,"aria-modal":`true`,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-2xl w-full max-w-md p-4`,onClick:e=>e.stopPropagation(),children:[(0,G.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(Pu,{className:`w-4 h-4 text-red-600 dark:text-red-400`}),e(`pipelineRuns.clearConfirmTitle`,`Clear log?`)]}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-2`,children:e(`pipelineRuns.clearConfirmBody`,`Delete every completed, failed, cancelled, and partial-failure pipeline run? In-flight runs are kept. This cannot be undone.`)}),(0,G.jsxs)(`div`,{className:`flex items-center justify-end gap-2 mt-4`,children:[(0,G.jsx)(`button`,{type:`button`,onClick:()=>m(!1),disabled:T.isPending,className:`px-3 py-1.5 text-sm text-bambu-gray hover:text-white`,children:e(`common.cancel`,`Cancel`)}),(0,G.jsxs)(`button`,{type:`button`,onClick:()=>T.mutate(),disabled:T.isPending,className:`px-3 py-1.5 text-sm bg-red-500 hover:bg-red-600 text-white rounded disabled:opacity-50 flex items-center gap-1`,children:[T.isPending?(0,G.jsx)(Y,{className:`w-3.5 h-3.5 animate-spin`}):(0,G.jsx)(Pu,{className:`w-3.5 h-3.5`}),e(`pipelineRuns.clearConfirmAction`,`Clear`)]})]})]})}),S&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray`,children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),e(`pipelineRuns.loading`,`Loading…`)]}),!S&&E.length===0&&(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:A?e(`pipelineRuns.filter.noMatches`,`No runs match the current filters.`):e(`pipelineRuns.empty`,`No pipeline runs yet.`)}),!S&&E.length>0&&(0,G.jsx)(`div`,{className:`space-y-1.5`,children:E.map(e=>(0,G.jsx)(DUe,{run:e,pipeline:e.pipeline_id?O[e.pipeline_id]:void 0,printersById:_,expanded:d.has(e.id),onToggle:()=>k(e.id),onCancel:()=>C.mutate(e.id),onRetry:()=>w.mutate(e.id),cancelling:C.isPending,retrying:w.isPending},e.id))}),!S&&D>G3&&(0,G.jsxs)(`div`,{className:`flex items-center justify-between mt-4 text-sm`,children:[(0,G.jsx)(`button`,{type:`button`,onClick:()=>u(Math.max(0,l-G3)),disabled:l===0,className:`px-3 py-1.5 rounded border border-bambu-dark-tertiary disabled:opacity-50 text-bambu-gray hover:text-white`,children:e(`common.previous`,`Previous`)}),(0,G.jsx)(`span`,{className:`text-bambu-gray text-xs`,children:e(`pipelineRuns.pagination`,`{{start}}–{{end}} of {{total}}`,{start:l+1,end:Math.min(l+G3,D),total:D})}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>u(l+G3),disabled:l+G3>=D,className:`px-3 py-1.5 rounded border border-bambu-dark-tertiary disabled:opacity-50 text-bambu-gray hover:text-white`,children:e(`common.next`,`Next`)})]})]})}function DUe({run:e,pipeline:t,printersById:n,expanded:r,onToggle:i,onCancel:a,onRetry:o,cancelling:s,retrying:c}){let{t:l}=U(),u=[`queued`,`slicing`,`dispatching`,`in_progress`].includes(e.status),d=e.status===`partial_failure`||e.status===`failed`,f=e.status===`cancelled`&&e.error_message===`Cancelled by user`,p=e.target_kind===`printer_class`&&e.target_model_class?l(`library.runWithPipeline.classTarget`,`Any {{model}}`,{model:e.target_model_class}):e.target_printer_id&&n[e.target_printer_id]?n[e.target_printer_id].name:null;return(0,G.jsxs)(`div`,{className:`rounded-md border border-bambu-dark-tertiary bg-bambu-dark/40 overflow-hidden`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2`,children:[(0,G.jsx)(`button`,{type:`button`,onClick:i,"aria-label":r?l(`common.collapse`,`Collapse`):l(`common.expand`,`Expand`),"aria-expanded":r,className:`text-bambu-gray hover:text-white flex-shrink-0`,children:r?(0,G.jsx)(ps,{className:`w-4 h-4`}):(0,G.jsx)(ms,{className:`w-4 h-4`})}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-0.5 text-sm`,children:[(0,G.jsxs)(`span`,{className:`font-medium text-white`,children:[`#`,e.id]}),(0,G.jsx)(`span`,{className:`text-white truncate`,children:t?.name??e.pipeline_name??`—`}),(0,G.jsx)(OUe,{status:e.status}),p&&(0,G.jsxs)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-bambu-dark-tertiary text-bambu-gray flex items-center gap-1`,children:[(0,G.jsx)(Rl,{className:`w-3 h-3`}),p]}),e.parent_run_id&&(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray/70 italic`,children:l(`pipelineRuns.retryOf`,`retry of #{{n}}`,{n:e.parent_run_id})})]}),e.source_filename&&(0,G.jsxs)(`div`,{className:`mt-0.5 flex items-center gap-1.5 text-xs text-bambu-gray min-w-0`,children:[(0,G.jsx)(fc,{className:`w-3 h-3 flex-shrink-0`}),(0,G.jsx)(`span`,{className:`truncate`,title:e.source_filename,children:e.source_filename})]}),(0,G.jsxs)(`div`,{className:`mt-0.5 text-xs text-bambu-gray/70 flex flex-wrap items-center gap-x-2`,children:[(0,G.jsx)(`span`,{children:new Date(e.created_at).toLocaleString()}),e.copies>1&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`span`,{className:`text-bambu-gray/40`,children:`·`}),(0,G.jsx)(`span`,{children:l(`pipelineRuns.copies`,`{{n}} copies`,{n:e.copies})})]}),(e.copies_completed>0||e.copies_failed>0||e.copies_cancelled>0)&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`span`,{className:`text-bambu-gray/40`,children:`·`}),(0,G.jsxs)(`span`,{children:[(0,G.jsx)(`span`,{className:`text-bambu-green`,children:e.copies_completed}),`/`,e.copies]}),e.copies_failed>0&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`span`,{className:`text-bambu-gray/40`,children:`·`}),(0,G.jsx)(`span`,{className:`text-red-700 dark:text-red-400`,children:l(`pipelineRuns.failedCount`,`{{n}} failed`,{n:e.copies_failed})})]})]})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1 flex-shrink-0`,children:[u&&(0,G.jsxs)(`button`,{type:`button`,onClick:a,disabled:s,"aria-label":l(`common.cancel`,`Cancel`),className:`text-xs px-2 py-1 text-red-700 dark:text-red-400 hover:bg-red-50 dark:hover:bg-red-500/10 rounded disabled:opacity-50 flex items-center gap-1`,children:[(0,G.jsx)(nd,{className:`w-3 h-3`}),l(`common.cancel`,`Cancel`)]}),d&&(0,G.jsxs)(`button`,{type:`button`,onClick:o,disabled:c,"aria-label":l(`pipelineRuns.retryFailed`,`Retry failed`),className:`text-xs px-2 py-1 text-bambu-green hover:bg-bambu-green/10 rounded disabled:opacity-50 flex items-center gap-1`,children:[(0,G.jsx)(Wl,{className:`w-3 h-3`}),l(`pipelineRuns.retryFailed`,`Retry failed`)]})]})]}),r&&(0,G.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary px-3 py-2 bg-bambu-dark/30`,children:[(0,G.jsx)(`div`,{className:`space-y-1.5`,children:e.jobs.map(e=>(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-xs`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray/60 w-14 flex-shrink-0`,children:l(`pipelineRuns.copyN`,`Copy {{n}}`,{n:e.copy_index+1})}),(0,G.jsx)(kUe,{status:e.status}),e.assigned_printer_name&&(0,G.jsxs)(`span`,{className:`text-bambu-gray flex items-center gap-1 truncate`,children:[(0,G.jsx)(Rl,{className:`w-3 h-3 text-bambu-gray/60`}),(0,G.jsx)(`span`,{className:`text-white truncate`,children:e.assigned_printer_name})]}),e.error_message&&(0,G.jsx)(`span`,{className:`text-red-700 dark:text-red-400 truncate`,title:e.error_message,children:e.error_message})]},e.id))}),e.error_message&&!f&&(0,G.jsx)(`div`,{className:`text-xs text-red-700 dark:text-red-400 mt-2 pt-2 border-t border-bambu-dark-tertiary`,children:e.error_message}),f&&(0,G.jsx)(`div`,{className:`text-xs text-bambu-gray/70 mt-2 pt-2 border-t border-bambu-dark-tertiary italic`,children:l(`pipelineRuns.cancelledByUser`,`Cancelled by user`)})]})]})}function OUe({status:e}){let{t}=U();return(0,G.jsx)(`span`,{className:`px-1.5 py-0.5 rounded text-[10px] uppercase font-semibold tracking-wide whitespace-nowrap ${{queued:`bg-slate-700 text-slate-200`,slicing:`bg-sky-700 text-sky-100`,dispatching:`bg-sky-700 text-sky-100`,in_progress:`bg-emerald-700 text-emerald-100`,completed:`bg-emerald-700 text-emerald-100`,failed:`bg-red-700 text-red-100`,partial_failure:`bg-amber-700 text-amber-100`,cancelled:`bg-rose-900 text-rose-200`}[e]}`,children:t(`settings.pipelines.runs.status.${e}`,e)})}function K3({value:e,onChange:t,options:n,icon:r,ariaLabel:i}){let[a,o]=(0,y.useState)(!1),s=(0,y.useRef)(null);(0,y.useEffect)(()=>{if(!a)return;let e=e=>{s.current&&!s.current.contains(e.target)&&o(!1)},t=e=>{e.key===`Escape`&&o(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[a]);let c=n.find(t=>t.value===e),l=[];for(let e of n){let t=l[l.length-1];t&&t.group===e.group?t.options.push(e):l.push({group:e.group,options:[e]})}return(0,G.jsxs)(`div`,{ref:s,className:`relative`,children:[(0,G.jsxs)(`button`,{type:`button`,onClick:()=>o(e=>!e),"aria-label":i,"aria-haspopup":`listbox`,"aria-expanded":a,className:`flex items-center gap-1.5 px-2 py-1 border border-bambu-dark-tertiary rounded bg-bambu-dark/40 text-xs text-white hover:border-bambu-gray/60 focus:outline-none focus:ring-1 focus:ring-bambu-green/40`,children:[r,(0,G.jsx)(`span`,{className:`truncate max-w-[14rem]`,children:c?.label??``}),(0,G.jsx)(ps,{className:`w-3 h-3 text-bambu-gray transition-transform ${a?`rotate-180`:``}`})]}),a&&(0,G.jsx)(`div`,{role:`listbox`,className:`absolute left-0 top-full mt-1 z-30 min-w-full max-h-72 overflow-auto rounded border border-bambu-dark-tertiary bg-bambu-dark-secondary shadow-xl py-1`,children:l.map((n,r)=>(0,G.jsxs)(`div`,{children:[n.group&&(0,G.jsx)(`div`,{className:`px-2 pt-1.5 pb-0.5 text-[10px] uppercase tracking-wider text-bambu-gray/60`,children:n.group}),n.options.map(n=>{let r=n.value===e;return(0,G.jsxs)(`button`,{type:`button`,role:`option`,"aria-selected":r,onClick:()=>{t(n.value),o(!1)},className:`flex w-full items-center gap-1.5 text-left px-2 py-1 text-xs whitespace-nowrap ${r?`bg-bambu-dark-tertiary text-white`:`text-bambu-gray hover:bg-bambu-dark-tertiary/60 hover:text-white`}`,children:[(0,G.jsx)(fs,{className:`w-3 h-3 flex-shrink-0 ${r?`opacity-100`:`opacity-0`}`}),(0,G.jsx)(`span`,{className:`truncate`,children:n.label})]},n.value)})]},r))})]})}function kUe({status:e}){let{t}=U();return(0,G.jsx)(`span`,{className:`px-1.5 py-0.5 rounded text-[10px] uppercase font-semibold tracking-wide ${{pending:`bg-slate-700 text-slate-200`,awaiting_printer:`bg-sky-700 text-sky-100`,queued:`bg-sky-700 text-sky-100`,printing:`bg-emerald-700 text-emerald-100`,completed:`bg-emerald-700 text-emerald-100`,failed:`bg-red-700 text-red-100`,cancelled:`bg-rose-900 text-rose-200`}[e]}`,children:t(`pipelineRuns.jobStatus.${e}`,e)})}function AUe(e){return e>=1e3?`${(e/1e3).toFixed(1)}kg`:`${Math.round(e)}g`}function jUe({activeCount:e,pendingCount:t,totalTime:n,totalWeight:r,historyCount:i,t:a}){return(0,G.jsx)(`div`,{className:`flex items-center gap-3 sm:gap-5 flex-wrap px-4 py-3 bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary mb-6`,children:[{icon:Nl,value:e,label:a(`queue.summary.printing`),color:`text-blue-600 dark:text-blue-400`},{icon:js,value:t,label:a(`queue.summary.queued`),color:`text-yellow-600 dark:text-yellow-400`},{icon:Nu,value:lp(n),label:a(`queue.summary.totalTime`),color:`text-bambu-green`},{icon:Xu,value:AUe(r),label:a(`queue.summary.totalWeight`),color:`text-purple-600 dark:text-purple-400`},{icon:xs,value:i,label:a(`queue.summary.history`),color:`text-bambu-gray`}].map((e,t)=>(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[t>0&&(0,G.jsx)(`span`,{className:`hidden sm:block text-bambu-dark-tertiary`,children:`|`}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,G.jsx)(e.icon,{className:`w-4 h-4 ${e.color}`}),(0,G.jsx)(`span`,{className:`text-sm font-semibold text-white`,children:e.value}),(0,G.jsx)(`span`,{className:`text-xs sm:text-sm text-bambu-gray`,children:e.label})]})]},t))})}var q3={completed:{icon:xs,color:`text-emerald-600 dark:text-emerald-400`,border:`border-l-emerald-500`},failed:{icon:Ds,color:`text-red-600 dark:text-red-400`,border:`border-l-red-500`},skipped:{icon:du,color:`text-orange-600 dark:text-orange-400`,border:`border-l-gray-500`},cancelled:{icon:Uo,color:`text-gray-400`,border:`border-l-gray-500`}};function MUe(e){if(!e)return null;let t=e.startsWith(`#`)?e.slice(1):e;return/^0{6,8}$/.test(t)||!/^[0-9a-fA-F]{6,8}$/.test(t)?null:`#${t.slice(0,6)}`}function J3({item:e,onRequeue:t,onRemove:n,timeFormat:r=`system`,hasPermission:i,canModify:a,t:o}){let s=q3[e.status]||q3.cancelled,c=s.icon,l=jT(e),u=e.archive_thumbnail?Z.getArchiveThumbnail(e.archive_id):e.library_file_thumbnail?Z.getLibraryFileThumbnailUrl(e.library_file_id):null,d=e.completed_at||e.created_at,f=MUe(e.filament_color),p=e.filament_used_grams?Math.round(e.filament_used_grams):null,m=!!e.error_message&&(e.status===`failed`||e.status===`skipped`);return(0,G.jsxs)(`div`,{className:`px-3 py-2 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary border-l-[3px] ${s.border}`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 sm:gap-3`,children:[(0,G.jsx)(c,{className:`w-4 h-4 shrink-0 ${s.color}`}),(0,G.jsxs)(`div`,{className:`relative shrink-0 history-thumb-hover`,children:[(0,G.jsx)(`div`,{className:`w-8 h-8 bg-bambu-dark rounded overflow-hidden`,children:u?(0,G.jsx)(`img`,{src:u,alt:``,className:`w-full h-full object-cover`}):(0,G.jsx)(`div`,{className:`w-full h-full flex items-center justify-center text-bambu-gray`,children:(0,G.jsx)(Jc,{className:`w-4 h-4`})})}),u&&(0,G.jsx)(`div`,{className:`history-thumb-preview absolute z-[60] left-full top-0 ml-2 w-48 h-48 pointer-events-none opacity-0 transition-opacity`,children:(0,G.jsx)(`img`,{src:u,alt:``,className:`w-full h-full object-cover rounded-lg shadow-2xl border-2 border-bambu-dark-tertiary bg-bambu-dark`})})]}),(0,G.jsx)(`span`,{className:`text-sm text-white font-medium truncate min-w-0 flex-1`,children:l}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray shrink-0`,title:d??void 0,children:up(d,r,o)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-0.5 shrink-0`,children:[(0,G.jsx)(Q,{variant:`ghost`,size:`sm`,onClick:t,disabled:!i(`queue:create`),title:i(`queue:create`)?o(`queue.actions.requeue`):o(`queue.permissions.noRequeue`),className:`text-bambu-green hover:text-bambu-green/80 hover:bg-bambu-green/10 p-1.5`,children:(0,G.jsx)(Hl,{className:`w-3.5 h-3.5`})}),(0,G.jsx)(Q,{variant:`ghost`,size:`sm`,onClick:n,disabled:!a(`queue`,`delete`,e.created_by_id),title:a(`queue`,`delete`,e.created_by_id)?o(`common.remove`):o(`queue.permissions.noRemove`),className:`p-1.5`,children:(0,G.jsx)(Pu,{className:`w-3.5 h-3.5`})})]})]}),(0,G.jsxs)(`div`,{className:`mt-1 ml-[3.25rem] flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-bambu-gray`,children:[e.printer_name&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1 shrink-0`,children:[(0,G.jsx)(Rl,{className:`w-3 h-3`}),(0,G.jsx)(`span`,{className:`truncate max-w-[100px] sm:max-w-[140px]`,children:e.printer_name})]}),(f||p)&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1 shrink-0`,children:[f?(0,G.jsx)(`span`,{className:`inline-block w-2.5 h-2.5 rounded-full border border-white/15`,style:{backgroundColor:f},"aria-hidden":!0}):(0,G.jsx)(Xu,{className:`w-3 h-3`}),(0,G.jsxs)(`span`,{className:`truncate`,children:[p?`${p}g`:null,p&&e.filament_type?` ${e.filament_type}`:null,!p&&e.filament_type?e.filament_type:null]})]}),e.print_time_seconds&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1 shrink-0`,children:[(0,G.jsx)(Nu,{className:`w-3 h-3`}),lp(e.print_time_seconds)]}),e.created_by_username&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1 shrink-0`,title:o(`queue.addedBy`,{name:e.created_by_username}),children:[(0,G.jsx)(Hu,{className:`w-3 h-3`}),(0,G.jsx)(`span`,{className:`truncate max-w-[120px]`,children:e.created_by_username})]})]}),m&&(0,G.jsxs)(`div`,{className:`mt-1 ml-[3.25rem] flex items-start gap-1 text-xs text-red-700 dark:text-red-400`,children:[(0,G.jsx)(ys,{className:`w-3 h-3 mt-0.5 shrink-0`}),(0,G.jsx)(`span`,{className:`break-words`,children:e.error_message})]})]})}function Y3(e){return e.printer_id==null?e.target_model?`model:${e.target_model}`:`unassigned`:`printer:${e.printer_id}`}function X3(e,t,n){if(n){let n=+!!e.been_jumped,r=+!!t.been_jumped;if(n!==r)return r-n;let i=e.print_time_seconds??1/0,a=t.print_time_seconds??1/0;if(i!==a)return i-a}return e.position-t.position}function NUe(e,t,n){let r=Y3(e),i=Y3(t);if(r!==i){if(e.printer_id!=null&&t.printer_id!=null)return e.printer_id-t.printer_id;let n=Z3(e),a=Z3(t);return n===a?rnew Date);(0,y.useEffect)(()=>{let e=setInterval(()=>s(new Date),6e4);return()=>clearInterval(e)},[]);let[c,l]=(0,y.useState)(0),u=(0,y.useMemo)(()=>{let e=o.getTime()+c;return Math.floor(e/Q3)*Q3},[o,c]),d=u+e6,f=o.getTime(),p=(0,y.useMemo)(()=>{let t=[],i=new Map,a=new Set,o=new Map;for(let r of e)if(r.status===`printing`){let e=r.printer_id==null?void 0:n[r.printer_id],i=rp(r.started_at)||new Date,s;if(e?.remaining_time!=null&&e.remaining_time>0)s=new Date(f+e.remaining_time*60*1e3);else if(r.print_time_seconds){let t=e?.progress||0,n=Math.max(0,1-t/100);s=new Date(f+r.print_time_seconds*n*1e3)}else s=new Date(f+Q3);t.push({item:r,estimatedStart:i,estimatedEnd:s,progress:e?.progress??void 0,type:`printing`});let c=Y3(r);a.add(c),o.set(c,Math.max(o.get(c)??f,s.getTime()))}else if(r.status===`pending`){if(r.manual_start||r.waiting_reason)continue;let e=Y3(r);i.has(e)||i.set(e,[]),i.get(e).push(r)}let s=Date.now()+4320*Q3;for(let[e,n]of i){n.sort((e,t)=>X3(e,t,r));let i=a.has(e),c=n[0]?rp(n[0].scheduled_time):null,l=c&&c.getTime()<=s;if(!i&&!l)continue;let u=o.get(e)??f;for(let e of n){let n=rp(e.scheduled_time);n&&n.getTime()<=s&&(u=Math.max(u,n.getTime()));let r=(e.print_time_seconds||3600)*1e3;t.push({item:e,estimatedStart:new Date(u),estimatedEnd:new Date(u+r),type:`queued`}),u+=r}}return t},[e,n,f,r]),m=(0,y.useMemo)(()=>{let e=[];for(let n of t)e.push({key:`printer:${n.id}`,label:n.name,printerId:n.id,targetModel:null});let n=new Set,r=!1;for(let t of p)if(t.item.printer_id==null)if(t.item.target_model){let r=`model:${t.item.target_model}`;n.has(r)||(n.add(r),e.push({key:r,label:`${a(`queue.filter.any`)} ${t.item.target_model}`,printerId:null,targetModel:t.item.target_model}))}else r=!0;return r&&e.push({key:`unassigned`,label:a(`queue.filter.unassigned`),printerId:null,targetModel:null}),e},[t,p,a]),h=(0,y.useMemo)(()=>{let e=new Map;for(let t of p){let n;n=t.item.printer_id==null?t.item.target_model?`model:${t.item.target_model}`:`unassigned`:`printer:${t.item.printer_id}`,e.has(n)||e.set(n,[]),e.get(n).push(t)}return e},[p]),g=(0,y.useMemo)(()=>{let e=[];for(let t=0;t<=$3;t+=2){let n=u+t*Q3;e.push({ms:n,pct:t/$3*100,label:IUe(new Date(n))})}return e},[u]),_=(f-u)/e6*100,v=_>=0&&_<=100,b=(0,y.useMemo)(()=>{let e=0;for(let t of p)e=Math.max(e,t.estimatedEnd.getTime());return e>0?new Date(e):null},[p]),x=(0,y.useRef)(null);return(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between gap-3 mb-5`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Q,{variant:`ghost`,size:`sm`,onClick:()=>l(e=>e-12*Q3),className:`p-1.5`,title:a(`queue.timeline.window.back12h`),children:(0,G.jsx)(hs,{className:`w-4 h-4`})}),(0,G.jsxs)(`span`,{className:`text-sm font-medium text-white min-w-[180px] text-center`,children:[new Date(u).toLocaleString(void 0,{weekday:`short`,month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`}),` → `,new Date(d).toLocaleTimeString(void 0,{hour:`2-digit`,minute:`2-digit`})]}),(0,G.jsx)(Q,{variant:`ghost`,size:`sm`,onClick:()=>l(e=>e+12*Q3),className:`p-1.5`,title:a(`queue.timeline.window.forward12h`),children:(0,G.jsx)(ms,{className:`w-4 h-4`})}),c!==0&&(0,G.jsx)(Q,{variant:`ghost`,size:`sm`,onClick:()=>l(0),className:`text-xs text-bambu-green`,children:a(`queue.timeline.window.now`)})]}),b&&(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray flex items-center gap-1.5`,children:[(0,G.jsx)(js,{className:`w-3.5 h-3.5`}),a(`queue.timeline.allDoneBy`,{time:b.toLocaleString(void 0,{weekday:`short`,hour:`2-digit`,minute:`2-digit`})})]})]}),m.length>0&&p.length===0&&(0,G.jsx)(`div`,{className:`mb-4 p-3 rounded-lg border border-bambu-dark-tertiary bg-bambu-dark/40 text-xs text-bambu-gray`,children:a(`queue.timeline.nothingCommitted`)}),m.length===0?(0,G.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-16 text-bambu-gray`,children:[(0,G.jsx)(Jc,{className:`w-12 h-12 mb-3 opacity-30`}),(0,G.jsx)(`p`,{className:`text-sm`,children:a(`queue.timeline.noData`)})]}):(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary overflow-hidden`,children:[(0,G.jsxs)(`div`,{className:`flex border-b border-bambu-dark-tertiary`,children:[(0,G.jsx)(`div`,{className:`w-32 sm:w-40 shrink-0 px-3 py-2 text-xs font-medium text-bambu-gray border-r border-bambu-dark-tertiary`,children:a(`queue.timeline.printerColumnHeader`)}),(0,G.jsx)(`div`,{className:`relative flex-1 h-9`,children:g.map(e=>(0,G.jsx)(`div`,{className:`absolute top-0 bottom-0 border-l border-bambu-dark-tertiary/40 text-[10px] sm:text-xs text-bambu-gray pl-1 flex items-center`,style:{left:`${e.pct}%`},children:e.label},e.ms))})]}),(0,G.jsxs)(`div`,{ref:x,className:`relative`,children:[m.map(e=>{let t=h.get(e.key)??[];return(0,G.jsxs)(`div`,{className:`flex border-b border-bambu-dark-tertiary/40 last:border-b-0`,children:[(0,G.jsxs)(`div`,{className:`w-32 sm:w-40 shrink-0 px-3 py-3 border-r border-bambu-dark-tertiary flex items-center gap-2`,children:[(0,G.jsx)(Rl,{className:`w-3.5 h-3.5 shrink-0 ${e.printerId==null&&e.targetModel==null?`text-orange-600 dark:text-orange-400`:e.targetModel?`text-blue-600 dark:text-blue-400`:`text-bambu-green`}`}),(0,G.jsx)(`span`,{className:`text-sm text-white truncate`,children:e.label})]}),(0,G.jsxs)(`div`,{className:`relative flex-1`,style:{height:56},children:[g.map(e=>(0,G.jsx)(`div`,{className:`absolute top-0 bottom-0 border-l border-bambu-dark-tertiary/30`,style:{left:`${e.pct}%`}},e.ms)),(0,G.jsx)(`div`,{className:`absolute inset-0 opacity-30`,style:{backgroundImage:`repeating-linear-gradient(45deg, transparent, transparent 6px, rgba(255,255,255,0.04) 6px, rgba(255,255,255,0.04) 12px)`},"aria-hidden":!0}),t.map(e=>{let t=Math.max(u,e.estimatedStart.getTime()),n=Math.min(d,e.estimatedEnd.getTime());if(n<=u||t>=d)return null;let r=(t-u)/e6*100,a=(n-t)/e6*100,o=e.item.archive_name||e.item.library_file_name||`#${e.item.id}`,s=e.item.archive_thumbnail?Z.getArchiveThumbnail(e.item.archive_id):e.item.library_file_thumbnail?Z.getLibraryFileThumbnailUrl(e.item.library_file_id):null,c=e.type===`printing`,l=e.item.batch_id!=null;return(0,G.jsxs)(`button`,{onClick:()=>i(e.item),title:[o,`${t6(e.estimatedStart)} → ${t6(e.estimatedEnd)}`,e.item.print_time_seconds?lp(e.item.print_time_seconds):null,c&&e.progress!=null?`${Math.round(e.progress)}%`:null,e.item.batch_name?`batch: ${e.item.batch_name}`:null].filter(Boolean).join(` · `),className:`absolute rounded-md transition-all hover:brightness-110 hover:z-10 overflow-hidden flex items-center gap-1.5 px-1.5 text-left ${c?`bg-blue-500/30 border border-blue-400/60`:l?`bg-cyan-500/20 border border-cyan-400/50`:`bg-bambu-green/20 border border-bambu-green/40`}`,style:{left:`${r}%`,width:`max(${PUe}px, ${a}%)`,top:8,height:FUe},children:[s&&(0,G.jsx)(`img`,{src:s,alt:``,className:`w-7 h-7 rounded object-cover shrink-0 bg-bambu-dark`}),(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,G.jsx)(`div`,{className:`text-xs text-white font-medium truncate leading-tight`,children:o}),(0,G.jsxs)(`div`,{className:`text-[10px] text-bambu-gray truncate leading-tight`,children:[e.item.print_time_seconds?lp(e.item.print_time_seconds):``,c&&e.progress!=null?` · ${Math.round(e.progress)}%`:``]})]}),c&&e.progress!=null&&(0,G.jsx)(`div`,{className:`absolute bottom-0 left-0 h-0.5 bg-blue-300`,style:{width:`${e.progress}%`},"aria-hidden":!0})]},e.item.id)})]})]},e.key)}),v&&(0,G.jsxs)(`div`,{className:`absolute top-0 bottom-0 pointer-events-none z-20 flex inset-x-0`,children:[(0,G.jsx)(`div`,{className:`w-32 sm:w-40 shrink-0`}),(0,G.jsx)(`div`,{className:`relative flex-1`,children:(0,G.jsx)(`div`,{className:`absolute top-0 bottom-0 w-0.5 bg-red-400 shadow-[0_0_8px_rgba(248,113,113,0.6)]`,style:{left:`${_}%`},children:(0,G.jsx)(`div`,{className:`absolute -top-1 -left-1 w-2.5 h-2.5 bg-red-400 rounded-full`})})})]})]})]})]})}function RUe({hasPermission:e,t}){let n=co(),{showToast:r}=qd(),[i,a]=(0,y.useState)(`active`),[o,s]=(0,y.useState)(null),{data:c}=K({queryKey:[`settings`],queryFn:Z.getSettings}),l=Lf(c?.currency||`USD`),{data:u,isLoading:d}=K({queryKey:[`batches`,i],queryFn:()=>Z.getBatches(i===`all`?void 0:i)}),f=()=>{n.invalidateQueries({queryKey:[`batches`]}),n.invalidateQueries({queryKey:[`queue`]})},p=q({mutationFn:({id:e,plateId:t})=>Z.dispatchBatch(e,t===void 0?{}:{plate_id:t,only_plate:!0}),onSuccess:e=>{f(),r(t(`queue.batchOrders.dispatched`,{name:e.name}),`success`)},onError:e=>r(e.message,`error`)}),m=q({mutationFn:e=>Z.cancelBatch(e),onSuccess:()=>{f(),s(null),r(t(`queue.batchCancelled`),`success`)},onError:e=>r(e.message,`error`)}),h=e(`queue:create`),g=e(`queue:delete_all`);return(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 mb-4`,children:[(0,G.jsx)(Cl,{className:`w-5 h-5 text-cyan-700 dark:text-cyan-300`}),(0,G.jsx)(`h2`,{className:`text-base sm:text-lg font-semibold text-white`,children:t(`queue.batchOrders.title`)}),(0,G.jsx)(`div`,{className:`flex gap-1 ml-auto`,children:[`active`,`completed`,`cancelled`,`all`].map(e=>(0,G.jsx)(`button`,{type:`button`,onClick:()=>a(e),className:`text-xs px-2.5 py-1 rounded-full border transition-colors ${i===e?`border-bambu-green bg-bambu-green/10 text-bambu-green`:`border-bambu-dark-tertiary text-bambu-gray hover:border-bambu-gray`}`,children:t(`queue.batchOrders.filter.${e}`)},e))})]}),d?(0,G.jsx)(`div`,{className:`text-center py-12 text-bambu-gray`,children:t(`common.loading`)}):u?.length?(0,G.jsx)(`div`,{className:`space-y-4`,children:u.map(e=>(0,G.jsx)(zUe,{batch:e,currency:l,canDispatch:h,canCancel:g,isDispatching:p.isPending&&p.variables?.id===e.id,onDispatch:t=>p.mutate({id:e.id,plateId:t}),onCancel:()=>s(e),t},e.id))}):(0,G.jsxs)(zd,{className:`p-12 text-center border-dashed`,children:[(0,G.jsx)(Cl,{className:`w-16 h-16 text-bambu-gray mx-auto mb-4 opacity-50`}),(0,G.jsx)(`h3`,{className:`text-xl font-medium text-white mb-2`,children:t(`queue.batchOrders.emptyTitle`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray max-w-md mx-auto`,children:t(`queue.batchOrders.emptyDescription`)})]}),o&&(0,G.jsx)(of,{title:t(`queue.cancelBatchConfirmTitle`),message:t(`queue.cancelBatchConfirmMessage`),confirmText:t(`queue.cancelBatch`),variant:`warning`,onConfirm:()=>m.mutate(o.id),onCancel:()=>s(null)})]})}var n6={active:`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-300`,completed:`bg-green-100 dark:bg-green-500/20 text-green-700 dark:text-green-300`,cancelled:`bg-bambu-dark-tertiary text-bambu-gray`};function zUe({batch:e,currency:t,canDispatch:n,canCancel:r,isDispatching:i,onDispatch:a,onCancel:o,t:s}){let c=e.has_targets?e.target_count:e.completed_count+e.pending_count+e.printing_count+e.failed_count,l=c>0?Math.round(e.completed_count/c*100):0,u=e.has_targets?e.remaining_count-e.dispatchable_count:0,d=e.due_date?rp(e.due_date):null,f=d!=null&&e.status===`active`&&d.getTime()0&&e.status!==`cancelled`&&n&&(0,G.jsxs)(Q,{variant:`primary`,size:`sm`,onClick:()=>a(),disabled:i,children:[(0,G.jsx)(Ts,{className:`w-4 h-4 mr-1`}),s(`queue.batchOrders.dispatchRemaining`,{count:e.dispatchable_count})]}),e.status===`active`&&r&&(0,G.jsxs)(Q,{variant:`ghost`,size:`sm`,onClick:o,children:[(0,G.jsx)(Ds,{className:`w-4 h-4 mr-1`}),s(`queue.cancelBatch`)]})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-3 mb-2`,children:[(0,G.jsx)(`div`,{className:`flex-1 h-2 bg-bambu-dark-tertiary rounded-full overflow-hidden`,children:(0,G.jsx)(`div`,{className:`h-full rounded-full transition-all ${e.status===`completed`?`bg-bambu-green`:`bg-blue-500`}`,style:{width:`${Math.min(100,l)}%`}})}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap tabular-nums`,children:s(`queue.batchProgress`,{completed:e.completed_count,total:c})})]}),(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-x-4 gap-y-1 text-xs text-bambu-gray mb-1`,children:[e.printing_count>0&&(0,G.jsx)(`span`,{children:s(`queue.batchOrders.printing`,{count:e.printing_count})}),e.pending_count>0&&(0,G.jsx)(`span`,{children:s(`queue.batch.pendingCount`,{count:e.pending_count})}),e.failed_count>0&&(0,G.jsxs)(`span`,{className:`text-orange-600 dark:text-orange-400 flex items-center gap-1`,children:[(0,G.jsx)(Lu,{className:`w-3 h-3`}),s(`queue.batchOrders.failed`,{count:e.failed_count})]}),e.has_targets&&e.remaining_count>0&&(0,G.jsx)(`span`,{children:s(`queue.batchOrders.remaining`,{count:e.remaining_count})}),e.print_time_seconds>0&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(js,{className:`w-3 h-3`}),lp(e.print_time_seconds)]}),e.actual_cost!=null&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(Ls,{className:`w-3 h-3`}),(0,G.jsx)(`span`,{children:s(`queue.batchOrders.costSoFar`,{amount:`${t} ${e.actual_cost.toFixed(2)}`})}),e.estimated_remaining_cost!=null&&e.estimated_remaining_cost>0&&(0,G.jsx)(`span`,{children:s(`queue.batchOrders.costRemaining`,{amount:`${t} ${e.estimated_remaining_cost.toFixed(2)}`})})]})]}),u>0&&e.status!==`cancelled`&&(0,G.jsxs)(`p`,{className:`flex items-start gap-1.5 text-xs text-orange-600 dark:text-orange-400 mb-1`,children:[(0,G.jsx)(Lu,{className:`w-3 h-3 mt-0.5 flex-shrink-0`}),(0,G.jsx)(`span`,{children:s(`queue.batchOrders.strandedNotice`,{runs:u,owed:e.remaining_count})})]}),e.has_targets&&e.plates.length>0&&(0,G.jsx)(`div`,{className:`mt-3 border-t border-bambu-dark-tertiary pt-3 space-y-1.5`,children:e.plates.map(r=>(0,G.jsx)(BUe,{plate:r,batchStatus:e.status,currency:t,canDispatch:n,isDispatching:i,onDispatch:()=>a(r.plate_id),t:s},`${r.plate_id??`file`}`))})]})}function BUe({plate:e,batchStatus:t,currency:n,canDispatch:r,isDispatching:i,onDispatch:a,t:o}){let s=e.plate_name||(e.plate_id==null?o(`queue.batchOrders.wholeFile`):o(`queue.plateNumber`,{index:e.plate_id}));return(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-xs`,children:[(0,G.jsx)(Jc,{className:`w-3.5 h-3.5 text-bambu-gray flex-shrink-0`}),(0,G.jsx)(`span`,{className:`text-white min-w-0 truncate`,children:s}),(0,G.jsx)(`span`,{className:`text-bambu-gray tabular-nums`,children:o(`queue.batchOrders.plateProgress`,{completed:e.completed_count,target:e.quantity_target})}),e.failed_count>0&&(0,G.jsx)(`span`,{className:`text-orange-600 dark:text-orange-400`,children:o(`queue.batchOrders.failed`,{count:e.failed_count})}),e.actual_cost!=null&&(0,G.jsx)(`span`,{className:`text-bambu-gray tabular-nums`,children:`${n} ${e.actual_cost.toFixed(2)}`}),e.remaining>0&&t!==`cancelled`&&(0,G.jsxs)(`span`,{className:`ml-auto flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:o(`queue.batchOrders.remaining`,{count:e.remaining})}),e.can_dispatch?r&&(0,G.jsx)(`button`,{type:`button`,onClick:a,disabled:i,className:`text-bambu-green hover:underline disabled:opacity-50`,children:o(`queue.batchOrders.dispatchPlate`)}):(0,G.jsx)(`span`,{className:`text-orange-600 dark:text-orange-400`,children:o(`queue.batchOrders.strandedPlate`)})]})]})}function r6(e,t=!1){return t&&e>=1e3?`${(e/1e3).toFixed(1)}kg`:`${Math.round(e)}g`}function VUe({status:e,waitingReason:t,printerState:n,t:r}){if(e===`pending`&&t)return(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full text-xs font-medium border text-purple-700 dark:text-purple-400 bg-purple-50 dark:bg-purple-400/10 border-purple-200 dark:border-purple-400/20`,children:[(0,G.jsx)(js,{className:`w-3.5 h-3.5`}),r(`queue.status.waiting`)]});if(e===`printing`&&n===`PAUSE`)return(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full text-xs font-medium border text-yellow-700 dark:text-yellow-400 bg-yellow-50 dark:bg-yellow-400/10 border-yellow-200 dark:border-yellow-400/20`,children:[(0,G.jsx)(Dl,{className:`w-3.5 h-3.5`}),r(`queue.status.paused`)]});let{icon:i,color:a,label:o}={pending:{icon:js,color:`text-status-warning bg-status-warning/10 border-status-warning/20`,label:r(`queue.status.pending`)},printing:{icon:Nl,color:`text-blue-700 dark:text-blue-400 bg-blue-50 dark:bg-blue-400/10 border-blue-200 dark:border-blue-400/20`,label:r(`queue.status.printing`)},completed:{icon:xs,color:`text-status-ok bg-status-ok/10 border-status-ok/20`,label:r(`queue.status.completed`)},failed:{icon:Ds,color:`text-status-error bg-status-error/10 border-status-error/20`,label:r(`queue.status.failed`)},skipped:{icon:du,color:`text-orange-700 dark:text-orange-400 bg-orange-50 dark:bg-orange-400/10 border-orange-200 dark:border-orange-400/20`,label:r(`queue.status.skipped`)},cancelled:{icon:nd,color:`text-gray-400 bg-gray-400/10 border-gray-400/20`,label:r(`queue.status.cancelled`)}}[e];return(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full text-xs font-medium border ${a}`,children:[(0,G.jsx)(i,{className:`w-3.5 h-3.5`}),o]})}function HUe({selectedCount:e,printers:t,onSave:n,onClose:r,isSaving:i,canControlPrinter:a,hasGcodeSnippets:o,t:s}){let[c,l]=(0,y.useState)(`unchanged`),[u,d]=(0,y.useState)(`unchanged`),[f,p]=(0,y.useState)(`unchanged`),[m,h]=(0,y.useState)(`unchanged`),[g,_]=(0,y.useState)(`unchanged`),[v,b]=(0,y.useState)(`unchanged`),[x,S]=(0,y.useState)(`unchanged`),[C,w]=(0,y.useState)(`unchanged`),[T,E]=(0,y.useState)(`unchanged`),[D,O]=(0,y.useState)(`unchanged`),[k,A]=(0,y.useState)(`unchanged`),[j,M]=(0,y.useState)(`unchanged`),N=t.some(e=>e.nozzle_count===2),P=()=>{let e={};c!==`unchanged`&&(e.printer_id=c),u!==`unchanged`&&(e.manual_start=u),f!==`unchanged`&&(e.auto_off_after=f),m!==`unchanged`&&(e.require_previous_success=m),g!==`unchanged`&&(e.gcode_injection=g),v!==`unchanged`&&(e.bed_levelling=v),x!==`unchanged`&&(e.flow_cali=x),C!==`unchanged`&&(e.vibration_cali=C),T!==`unchanged`&&(e.layer_inspect=T),D!==`unchanged`&&(e.timelapse=D),k!==`unchanged`&&(e.use_ams=k),j!==`unchanged`&&(e.nozzle_offset_cali=j),n(e)},F=c!==`unchanged`||u!==`unchanged`||f!==`unchanged`||m!==`unchanged`||v!==`unchanged`||x!==`unchanged`||C!==`unchanged`||T!==`unchanged`||D!==`unchanged`||k!==`unchanged`||j!==`unchanged`||g!==`unchanged`;return(0,G.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center p-4 bg-black/50 backdrop-blur-sm`,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-lg max-h-[90vh] overflow-y-auto`,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-lg font-semibold text-white`,children:s(`queue.bulkEdit.title`,{count:e})}),(0,G.jsx)(`button`,{onClick:r,className:`p-1 hover:bg-bambu-dark rounded`,children:(0,G.jsx)(nd,{className:`w-5 h-5 text-bambu-gray`})})]}),(0,G.jsxs)(`div`,{className:`p-4 space-y-4`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:s(`queue.bulkEdit.description`)}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:s(`queue.bulkEdit.printer`)}),(0,G.jsxs)(`select`,{value:c===null?`null`:c===`unchanged`?`unchanged`:String(c),onChange:e=>{let t=e.target.value;l(t===`unchanged`?`unchanged`:t===`null`?null:Number(t))},className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,G.jsx)(`option`,{value:`unchanged`,children:s(`queue.bulkEdit.noChange`)}),(0,G.jsx)(`option`,{value:`null`,children:s(`queue.filter.unassigned`)}),t.map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:s(`queue.bulkEdit.queueOptions`)}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(i6,{label:s(`queue.bulkEdit.staged`),value:u,onChange:d,t:s}),(0,G.jsx)(i6,{label:s(`queue.bulkEdit.autoPowerOff`),value:f,onChange:p,disabled:!a,t:s}),(0,G.jsx)(i6,{label:s(`queue.bulkEdit.requirePrevious`),value:m,onChange:h,t:s}),o&&(0,G.jsx)(i6,{label:s(`queue.bulkEdit.gcodeInjection`),value:g,onChange:_,t:s})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:s(`queue.bulkEdit.printOptions`)}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(a6,{label:s(`queue.bulkEdit.bedLevelling`),value:v,onChange:b,t:s}),(0,G.jsx)(a6,{label:s(`queue.bulkEdit.flowCalibration`),value:x,onChange:S,t:s}),(0,G.jsx)(i6,{label:s(`queue.bulkEdit.vibrationCalibration`),value:C,onChange:w,t:s}),(0,G.jsx)(i6,{label:s(`queue.bulkEdit.layerInspection`),value:T,onChange:E,t:s}),(0,G.jsx)(i6,{label:s(`queue.bulkEdit.timelapse`),value:D,onChange:O,t:s}),(0,G.jsx)(i6,{label:s(`queue.bulkEdit.useAms`),value:k,onChange:A,t:s}),N&&(0,G.jsx)(a6,{label:s(`queue.bulkEdit.nozzleOffsetCali`),value:j,onChange:M,t:s})]})]})]}),(0,G.jsxs)(`div`,{className:`flex justify-end gap-3 p-4 border-t border-bambu-dark-tertiary`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:r,children:s(`common.cancel`)}),(0,G.jsx)(Q,{onClick:P,disabled:!F||i,children:s(i?`common.saving`:`queue.bulkEdit.applyChanges`)})]})]})})}function i6({label:e,value:t,onChange:n,disabled:r,t:i}){return(0,G.jsxs)(`div`,{className:`flex items-center justify-between py-1 ${r?`opacity-50`:``}`,children:[(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1 bg-bambu-dark rounded-lg p-0.5`,children:[(0,G.jsx)(`button`,{onClick:()=>n(`unchanged`),disabled:r,className:`px-2 py-1 text-xs rounded ${t===`unchanged`?`bg-bambu-dark-tertiary text-white`:`text-bambu-gray hover:text-white`} disabled:cursor-not-allowed`,children:`—`}),(0,G.jsx)(`button`,{onClick:()=>n(!1),disabled:r,className:`px-2 py-1 text-xs rounded ${t===!1?`bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400`:`text-bambu-gray hover:text-white`} disabled:cursor-not-allowed`,children:i(`common.off`)}),(0,G.jsx)(`button`,{onClick:()=>n(!0),disabled:r,className:`px-2 py-1 text-xs rounded ${t===!0?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:text-white`} disabled:cursor-not-allowed`,children:i(`common.on`)})]})]})}function a6({label:e,value:t,onChange:n,t:r}){let i=[{key:`unchanged`,label:`—`,active:`bg-bambu-dark-tertiary text-white`},{key:`off`,label:r(`settings.calibrationMode_off`),active:`bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400`},{key:`auto`,label:r(`settings.calibrationMode_auto`),active:`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`},{key:`on`,label:r(`settings.calibrationMode_on`),active:`bg-bambu-green/20 text-bambu-green`}];return(0,G.jsxs)(`div`,{className:`flex items-center justify-between py-1`,children:[(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e}),(0,G.jsx)(`div`,{className:`flex items-center gap-1 bg-bambu-dark rounded-lg p-0.5`,children:i.map(({key:e,label:r,active:i})=>(0,G.jsx)(`button`,{onClick:()=>n(e),className:`px-2 py-1 text-xs rounded ${t===e?i:`text-bambu-gray hover:text-white`}`,children:r},e))})]})}function o6({item:e,position:t,onEdit:n,onCancel:r,onRemove:i,onStop:a,onRequeue:o,onStart:s,onMoveUp:c,onMoveDown:l,timeFormat:u=`system`,isSelected:d=!1,onToggleSelect:f,hasPermission:p,canModify:m,printerState:h,showEta:g=!1,etaNow:_,t:v}){let{data:y}=K({queryKey:[`printerStatus`,e.printer_id],queryFn:()=>Z.getPrinterStatus(e.printer_id),refetchInterval:3e4,enabled:e.printer_id!=null&&h===`printing`}),b=!!e.library_file_id&&!e.archive_id,{data:x}=K({queryKey:[`archive-plates`,e.archive_id],queryFn:()=>Z.getArchivePlates(e.archive_id),enabled:!!e.archive_id&&!b&&!e.archive_deleted}),{data:S}=K({queryKey:[`library-file-plates`,e.library_file_id],queryFn:()=>Z.getLibraryFilePlates(e.library_file_id),enabled:b&&!!e.library_file_id}),C=b?S:x,w=C?.plates??[],T=p(`queue:reorder`),{attributes:E,listeners:D,setNodeRef:O,transform:k,transition:A,isDragging:j}=V3({id:e.id,disabled:e.status!==`pending`||!T}),M={transform:y4.Transform.toString(k),transition:A},N=e.status===`printing`,P=e.status===`pending`,F=[`completed`,`failed`,`skipped`,`cancelled`].includes(e.status),I=P&&g&&e.print_time_seconds!=null&&e.print_time_seconds>0?cp(e.print_time_seconds/60,u,v,_):null,L=P&&f;return(0,G.jsxs)(`div`,{ref:O,style:M,className:` + `},XVe={onDragStart(e){let{active:t}=e;return`Picked up draggable item `+t.id+`.`},onDragOver(e){let{active:t,over:n}=e;return n?`Draggable item `+t.id+` was moved over droppable area `+n.id+`.`:`Draggable item `+t.id+` is no longer over a droppable area.`},onDragEnd(e){let{active:t,over:n}=e;return n?`Draggable item `+t.id+` was dropped over droppable area `+n.id:`Draggable item `+t.id+` was dropped.`},onDragCancel(e){let{active:t}=e;return`Dragging was cancelled. Draggable item `+t.id+` was dropped.`}};function ZVe(e){let{announcements:t=XVe,container:n,hiddenTextDescribedById:r,screenReaderInstructions:i=YVe}=e,{announce:a,announcement:o}=KVe(),s=p4(`DndLiveRegion`),[c,l]=(0,y.useState)(!1);if((0,y.useEffect)(()=>{l(!0)},[]),qVe((0,y.useMemo)(()=>({onDragStart(e){let{active:n}=e;a(t.onDragStart({active:n}))},onDragMove(e){let{active:n,over:r}=e;t.onDragMove&&a(t.onDragMove({active:n,over:r}))},onDragOver(e){let{active:n,over:r}=e;a(t.onDragOver({active:n,over:r}))},onDragEnd(e){let{active:n,over:r}=e;a(t.onDragEnd({active:n,over:r}))},onDragCancel(e){let{active:n,over:r}=e;a(t.onDragCancel({active:n,over:r}))}}),[a,t])),!c)return null;let u=y.createElement(y.Fragment,null,y.createElement(WVe,{id:r,value:i.draggable}),y.createElement(GVe,{id:s,announcement:o}));return n?(0,At.createPortal)(u,n):u}var S4;(function(e){e.DragStart=`dragStart`,e.DragMove=`dragMove`,e.DragEnd=`dragEnd`,e.DragCancel=`dragCancel`,e.DragOver=`dragOver`,e.RegisterDroppable=`registerDroppable`,e.SetDroppableDisabled=`setDroppableDisabled`,e.UnregisterDroppable=`unregisterDroppable`})(S4||={});function C4(){}function w4(e,t){return(0,y.useMemo)(()=>({sensor:e,options:t??{}}),[e,t])}function T4(){var e=[...arguments];return(0,y.useMemo)(()=>[...e].filter(e=>e!=null),[...e])}var E4=Object.freeze({x:0,y:0});function D4(e,t){return Math.sqrt((e.x-t.x)**2+(e.y-t.y)**2)}function QVe(e,t){let n=v4(e);if(!n)return`0 0`;let r={x:(n.x-t.left)/t.width*100,y:(n.y-t.top)/t.height*100};return r.x+`% `+r.y+`%`}function O4(e,t){let{data:{value:n}}=e,{data:{value:r}}=t;return n-r}function $Ve(e,t){let{data:{value:n}}=e,{data:{value:r}}=t;return r-n}function k4(e){let{left:t,top:n,height:r,width:i}=e;return[{x:t,y:n},{x:t+i,y:n},{x:t,y:n+r},{x:t+i,y:n+r}]}function A4(e,t){if(!e||e.length===0)return null;let[n]=e;return t?n[t]:n}function j4(e,t,n){return t===void 0&&(t=e.left),n===void 0&&(n=e.top),{x:t+e.width*.5,y:n+e.height*.5}}var M4=e=>{let{collisionRect:t,droppableRects:n,droppableContainers:r}=e,i=j4(t,t.left,t.top),a=[];for(let e of r){let{id:t}=e,r=n.get(t);if(r){let n=D4(j4(r),i);a.push({id:t,data:{droppableContainer:e,value:n}})}}return a.sort(O4)},eHe=e=>{let{collisionRect:t,droppableRects:n,droppableContainers:r}=e,i=k4(t),a=[];for(let e of r){let{id:t}=e,r=n.get(t);if(r){let n=k4(r),o=i.reduce((e,t,r)=>e+D4(n[r],t),0),s=Number((o/4).toFixed(4));a.push({id:t,data:{droppableContainer:e,value:s}})}}return a.sort(O4)};function tHe(e,t){let n=Math.max(t.top,e.top),r=Math.max(t.left,e.left),i=Math.min(t.left+t.width,e.left+e.width),a=Math.min(t.top+t.height,e.top+e.height),o=i-r,s=a-n;if(r{let{collisionRect:t,droppableRects:n,droppableContainers:r}=e,i=[];for(let e of r){let{id:r}=e,a=n.get(r);if(a){let n=tHe(a,t);n>0&&i.push({id:r,data:{droppableContainer:e,value:n}})}}return i.sort($Ve)};function rHe(e,t,n){return{...e,scaleX:t&&n?t.width/n.width:1,scaleY:t&&n?t.height/n.height:1}}function N4(e,t){return e&&t?{x:e.left-t.left,y:e.top-t.top}:E4}function iHe(e){return function(t){return[...arguments].slice(1).reduce((t,n)=>({...t,top:t.top+e*n.y,bottom:t.bottom+e*n.y,left:t.left+e*n.x,right:t.right+e*n.x}),{...t})}}var aHe=iHe(1);function P4(e){if(e.startsWith(`matrix3d(`)){let t=e.slice(9,-1).split(/, /);return{x:+t[12],y:+t[13],scaleX:+t[0],scaleY:+t[5]}}else if(e.startsWith(`matrix(`)){let t=e.slice(7,-1).split(/, /);return{x:+t[4],y:+t[5],scaleX:+t[0],scaleY:+t[3]}}return null}function oHe(e,t,n){let r=P4(t);if(!r)return e;let{scaleX:i,scaleY:a,x:o,y:s}=r,c=e.left-o-(1-i)*parseFloat(n),l=e.top-s-(1-a)*parseFloat(n.slice(n.indexOf(` `)+1)),u=i?e.width/i:e.width,d=a?e.height/a:e.height;return{width:u,height:d,top:l,right:c+u,bottom:l+d,left:c}}var sHe={ignoreTransform:!1};function F4(e,t){t===void 0&&(t=sHe);let n=e.getBoundingClientRect();if(t.ignoreTransform){let{transform:t,transformOrigin:r}=t4(e).getComputedStyle(e);t&&(n=oHe(n,t,r))}let{top:r,left:i,width:a,height:o,bottom:s,right:c}=n;return{top:r,left:i,width:a,height:o,bottom:s,right:c}}function I4(e){return F4(e,{ignoreTransform:!0})}function cHe(e){let t=e.innerWidth,n=e.innerHeight;return{top:0,left:0,right:t,bottom:n,width:t,height:n}}function lHe(e,t){return t===void 0&&(t=t4(e).getComputedStyle(e)),t.position===`fixed`}function uHe(e,t){t===void 0&&(t=t4(e).getComputedStyle(e));let n=/(auto|scroll|overlay)/;return[`overflow`,`overflowX`,`overflowY`].some(e=>{let r=t[e];return typeof r==`string`?n.test(r):!1})}function L4(e,t){let n=[];function r(i){if(t!=null&&n.length>=t||!i)return n;if(n4(i)&&i.scrollingElement!=null&&!n.includes(i.scrollingElement))return n.push(i.scrollingElement),n;if(!r4(i)||i4(i)||n.includes(i))return n;let a=t4(e).getComputedStyle(i);return i!==e&&uHe(i,a)&&n.push(i),lHe(i,a)?n:r(i.parentNode)}return e?r(e):n}function R4(e){let[t]=L4(e,1);return t??null}function z4(e){return!Q2||!e?null:$2(e)?e:e4(e)?n4(e)||e===a4(e).scrollingElement?window:r4(e)?e:null:null}function B4(e){return $2(e)?e.scrollX:e.scrollLeft}function V4(e){return $2(e)?e.scrollY:e.scrollTop}function H4(e){return{x:B4(e),y:V4(e)}}var U4;(function(e){e[e.Forward=1]=`Forward`,e[e.Backward=-1]=`Backward`})(U4||={});function W4(e){return!Q2||!e?!1:e===document.scrollingElement}function G4(e){let t={x:0,y:0},n=W4(e)?{height:window.innerHeight,width:window.innerWidth}:{height:e.clientHeight,width:e.clientWidth},r={x:e.scrollWidth-n.width,y:e.scrollHeight-n.height};return{isTop:e.scrollTop<=t.y,isLeft:e.scrollLeft<=t.x,isBottom:e.scrollTop>=r.y,isRight:e.scrollLeft>=r.x,maxScroll:r,minScroll:t}}var dHe={x:.2,y:.2};function fHe(e,t,n,r,i){let{top:a,left:o,right:s,bottom:c}=n;r===void 0&&(r=10),i===void 0&&(i=dHe);let{isTop:l,isBottom:u,isLeft:d,isRight:f}=G4(e),p={x:0,y:0},m={x:0,y:0},h={height:t.height*i.y,width:t.width*i.x};return!l&&a<=t.top+h.height?(p.y=U4.Backward,m.y=r*Math.abs((t.top+h.height-a)/h.height)):!u&&c>=t.bottom-h.height&&(p.y=U4.Forward,m.y=r*Math.abs((t.bottom-h.height-c)/h.height)),!f&&s>=t.right-h.width?(p.x=U4.Forward,m.x=r*Math.abs((t.right-h.width-s)/h.width)):!d&&o<=t.left+h.width&&(p.x=U4.Backward,m.x=r*Math.abs((t.left+h.width-o)/h.width)),{direction:p,speed:m}}function pHe(e){if(e===document.scrollingElement){let{innerWidth:e,innerHeight:t}=window;return{top:0,left:0,right:e,bottom:t,width:e,height:t}}let{top:t,left:n,right:r,bottom:i}=e.getBoundingClientRect();return{top:t,left:n,right:r,bottom:i,width:e.clientWidth,height:e.clientHeight}}function K4(e){return e.reduce((e,t)=>h4(e,H4(t)),E4)}function mHe(e){return e.reduce((e,t)=>e+B4(t),0)}function hHe(e){return e.reduce((e,t)=>e+V4(t),0)}function q4(e,t){if(t===void 0&&(t=F4),!e)return;let{top:n,left:r,bottom:i,right:a}=t(e);R4(e)&&(i<=0||a<=0||n>=window.innerHeight||r>=window.innerWidth)&&e.scrollIntoView({block:`center`,inline:`center`})}var gHe=[[`x`,[`left`,`right`],mHe],[`y`,[`top`,`bottom`],hHe]],J4=class{constructor(e,t){this.rect=void 0,this.width=void 0,this.height=void 0,this.top=void 0,this.bottom=void 0,this.right=void 0,this.left=void 0;let n=L4(t),r=K4(n);this.rect={...e},this.width=e.width,this.height=e.height;for(let[e,t,i]of gHe)for(let a of t)Object.defineProperty(this,a,{get:()=>{let t=i(n),o=r[e]-t;return this.rect[a]+o},enumerable:!0});Object.defineProperty(this,"rect",{enumerable:!1})}},Y4=class{constructor(e){this.target=void 0,this.listeners=[],this.removeAll=()=>{this.listeners.forEach(e=>this.target?.removeEventListener(...e))},this.target=e}add(e,t,n){var r;(r=this.target)==null||r.addEventListener(e,t,n),this.listeners.push([e,t,n])}};function _He(e){let{EventTarget:t}=t4(e);return e instanceof t?e:a4(e)}function X4(e,t){let n=Math.abs(e.x),r=Math.abs(e.y);return typeof t==`number`?Math.sqrt(n**2+r**2)>t:`x`in t&&`y`in t?n>t.x&&r>t.y:`x`in t?n>t.x:`y`in t?r>t.y:!1}var Z4;(function(e){e.Click=`click`,e.DragStart=`dragstart`,e.Keydown=`keydown`,e.ContextMenu=`contextmenu`,e.Resize=`resize`,e.SelectionChange=`selectionchange`,e.VisibilityChange=`visibilitychange`})(Z4||={});function Q4(e){e.preventDefault()}function vHe(e){e.stopPropagation()}var $4;(function(e){e.Space=`Space`,e.Down=`ArrowDown`,e.Right=`ArrowRight`,e.Left=`ArrowLeft`,e.Up=`ArrowUp`,e.Esc=`Escape`,e.Enter=`Enter`,e.Tab=`Tab`})($4||={});var e3={start:[$4.Space,$4.Enter],cancel:[$4.Esc],end:[$4.Space,$4.Enter,$4.Tab]},yHe=(e,t)=>{let{currentCoordinates:n}=t;switch(e.code){case $4.Right:return{...n,x:n.x+25};case $4.Left:return{...n,x:n.x-25};case $4.Down:return{...n,y:n.y+25};case $4.Up:return{...n,y:n.y-25}}},t3=class{constructor(e){this.props=void 0,this.autoScrollEnabled=!1,this.referenceCoordinates=void 0,this.listeners=void 0,this.windowListeners=void 0,this.props=e;let{event:{target:t}}=e;this.props=e,this.listeners=new Y4(a4(t)),this.windowListeners=new Y4(t4(t)),this.handleKeyDown=this.handleKeyDown.bind(this),this.handleCancel=this.handleCancel.bind(this),this.attach()}attach(){this.handleStart(),this.windowListeners.add(Z4.Resize,this.handleCancel),this.windowListeners.add(Z4.VisibilityChange,this.handleCancel),setTimeout(()=>this.listeners.add(Z4.Keydown,this.handleKeyDown))}handleStart(){let{activeNode:e,onStart:t}=this.props,n=e.node.current;n&&q4(n),t(E4)}handleKeyDown(e){if(_4(e)){let{active:t,context:n,options:r}=this.props,{keyboardCodes:i=e3,coordinateGetter:a=yHe,scrollBehavior:o=`smooth`}=r,{code:s}=e;if(i.end.includes(s)){this.handleEnd(e);return}if(i.cancel.includes(s)){this.handleCancel(e);return}let{collisionRect:c}=n.current,l=c?{x:c.left,y:c.top}:E4;this.referenceCoordinates||=l;let u=a(e,{active:t,context:n.current,currentCoordinates:l});if(u){let t=g4(u,l),r={x:0,y:0},{scrollableAncestors:i}=n.current;for(let n of i){let i=e.code,{isTop:a,isRight:s,isLeft:c,isBottom:l,maxScroll:d,minScroll:f}=G4(n),p=pHe(n),m={x:Math.min(i===$4.Right?p.right-p.width/2:p.right,Math.max(i===$4.Right?p.left:p.left+p.width/2,u.x)),y:Math.min(i===$4.Down?p.bottom-p.height/2:p.bottom,Math.max(i===$4.Down?p.top:p.top+p.height/2,u.y))},h=i===$4.Right&&!s||i===$4.Left&&!c,g=i===$4.Down&&!l||i===$4.Up&&!a;if(h&&m.x!==u.x){let e=n.scrollLeft+t.x,a=i===$4.Right&&e<=d.x||i===$4.Left&&e>=f.x;if(a&&!t.y){n.scrollTo({left:e,behavior:o});return}a?r.x=n.scrollLeft-e:r.x=i===$4.Right?n.scrollLeft-d.x:n.scrollLeft-f.x,r.x&&n.scrollBy({left:-r.x,behavior:o});break}else if(g&&m.y!==u.y){let e=n.scrollTop+t.y,a=i===$4.Down&&e<=d.y||i===$4.Up&&e>=f.y;if(a&&!t.x){n.scrollTo({top:e,behavior:o});return}a?r.y=n.scrollTop-e:r.y=i===$4.Down?n.scrollTop-d.y:n.scrollTop-f.y,r.y&&n.scrollBy({top:-r.y,behavior:o});break}}this.handleMove(e,h4(g4(u,this.referenceCoordinates),r))}}}handleMove(e,t){let{onMove:n}=this.props;e.preventDefault(),n(t)}handleEnd(e){let{onEnd:t}=this.props;e.preventDefault(),this.detach(),t()}handleCancel(e){let{onCancel:t}=this.props;e.preventDefault(),this.detach(),t()}detach(){this.listeners.removeAll(),this.windowListeners.removeAll()}};t3.activators=[{eventName:`onKeyDown`,handler:(e,t,n)=>{let{keyboardCodes:r=e3,onActivation:i}=t,{active:a}=n,{code:o}=e.nativeEvent;if(r.start.includes(o)){let t=a.activatorNode.current;return t&&e.target!==t?!1:(e.preventDefault(),i?.({event:e.nativeEvent}),!0)}return!1}}];function n3(e){return!!(e&&`distance`in e)}function r3(e){return!!(e&&`delay`in e)}var i3=class{constructor(e,t,n){n===void 0&&(n=_He(e.event.target)),this.props=void 0,this.events=void 0,this.autoScrollEnabled=!0,this.document=void 0,this.activated=!1,this.initialCoordinates=void 0,this.timeoutId=null,this.listeners=void 0,this.documentListeners=void 0,this.windowListeners=void 0,this.props=e,this.events=t;let{event:r}=e,{target:i}=r;this.props=e,this.events=t,this.document=a4(i),this.documentListeners=new Y4(this.document),this.listeners=new Y4(n),this.windowListeners=new Y4(t4(i)),this.initialCoordinates=v4(r)??E4,this.handleStart=this.handleStart.bind(this),this.handleMove=this.handleMove.bind(this),this.handleEnd=this.handleEnd.bind(this),this.handleCancel=this.handleCancel.bind(this),this.handleKeydown=this.handleKeydown.bind(this),this.removeTextSelection=this.removeTextSelection.bind(this),this.attach()}attach(){let{events:e,props:{options:{activationConstraint:t,bypassActivationConstraint:n}}}=this;if(this.listeners.add(e.move.name,this.handleMove,{passive:!1}),this.listeners.add(e.end.name,this.handleEnd),e.cancel&&this.listeners.add(e.cancel.name,this.handleCancel),this.windowListeners.add(Z4.Resize,this.handleCancel),this.windowListeners.add(Z4.DragStart,Q4),this.windowListeners.add(Z4.VisibilityChange,this.handleCancel),this.windowListeners.add(Z4.ContextMenu,Q4),this.documentListeners.add(Z4.Keydown,this.handleKeydown),t){if(n!=null&&n({event:this.props.event,activeNode:this.props.activeNode,options:this.props.options}))return this.handleStart();if(r3(t)){this.timeoutId=setTimeout(this.handleStart,t.delay),this.handlePending(t);return}if(n3(t)){this.handlePending(t);return}}this.handleStart()}detach(){this.listeners.removeAll(),this.windowListeners.removeAll(),setTimeout(this.documentListeners.removeAll,50),this.timeoutId!==null&&(clearTimeout(this.timeoutId),this.timeoutId=null)}handlePending(e,t){let{active:n,onPending:r}=this.props;r(n,e,this.initialCoordinates,t)}handleStart(){let{initialCoordinates:e}=this,{onStart:t}=this.props;e&&(this.activated=!0,this.documentListeners.add(Z4.Click,vHe,{capture:!0}),this.removeTextSelection(),this.documentListeners.add(Z4.SelectionChange,this.removeTextSelection),t(e))}handleMove(e){let{activated:t,initialCoordinates:n,props:r}=this,{onMove:i,options:{activationConstraint:a}}=r;if(!n)return;let o=v4(e)??E4,s=g4(n,o);if(!t&&a){if(n3(a)){if(a.tolerance!=null&&X4(s,a.tolerance))return this.handleCancel();if(X4(s,a.distance))return this.handleStart()}if(r3(a)&&X4(s,a.tolerance))return this.handleCancel();this.handlePending(a,s);return}e.cancelable&&e.preventDefault(),i(o)}handleEnd(){let{onAbort:e,onEnd:t}=this.props;this.detach(),this.activated||e(this.props.active),t()}handleCancel(){let{onAbort:e,onCancel:t}=this.props;this.detach(),this.activated||e(this.props.active),t()}handleKeydown(e){e.code===$4.Esc&&this.handleCancel()}removeTextSelection(){var e;(e=this.document.getSelection())==null||e.removeAllRanges()}},bHe={cancel:{name:`pointercancel`},move:{name:`pointermove`},end:{name:`pointerup`}},a3=class extends i3{constructor(e){let{event:t}=e,n=a4(t.target);super(e,bHe,n)}};a3.activators=[{eventName:`onPointerDown`,handler:(e,t)=>{let{nativeEvent:n}=e,{onActivation:r}=t;return!n.isPrimary||n.button!==0?!1:(r?.({event:n}),!0)}}];var xHe={move:{name:`mousemove`},end:{name:`mouseup`}},o3;(function(e){e[e.RightClick=2]=`RightClick`})(o3||={});var SHe=class extends i3{constructor(e){super(e,xHe,a4(e.event.target))}};SHe.activators=[{eventName:`onMouseDown`,handler:(e,t)=>{let{nativeEvent:n}=e,{onActivation:r}=t;return n.button===o3.RightClick?!1:(r?.({event:n}),!0)}}];var s3={cancel:{name:`touchcancel`},move:{name:`touchmove`},end:{name:`touchend`}},CHe=class extends i3{constructor(e){super(e,s3)}static setup(){return window.addEventListener(s3.move.name,e,{capture:!1,passive:!1}),function(){window.removeEventListener(s3.move.name,e)};function e(){}}};CHe.activators=[{eventName:`onTouchStart`,handler:(e,t)=>{let{nativeEvent:n}=e,{onActivation:r}=t,{touches:i}=n;return i.length>1?!1:(r?.({event:n}),!0)}}];var c3;(function(e){e[e.Pointer=0]=`Pointer`,e[e.DraggableRect=1]=`DraggableRect`})(c3||={});var l3;(function(e){e[e.TreeOrder=0]=`TreeOrder`,e[e.ReversedTreeOrder=1]=`ReversedTreeOrder`})(l3||={});function wHe(e){let{acceleration:t,activator:n=c3.Pointer,canScroll:r,draggingRect:i,enabled:a,interval:o=5,order:s=l3.TreeOrder,pointerCoordinates:c,scrollableAncestors:l,scrollableAncestorRects:u,delta:d,threshold:f}=e,p=EHe({delta:d,disabled:!a}),[m,h]=zVe(),g=(0,y.useRef)({x:0,y:0}),_=(0,y.useRef)({x:0,y:0}),v=(0,y.useMemo)(()=>{switch(n){case c3.Pointer:return c?{top:c.y,bottom:c.y,left:c.x,right:c.x}:null;case c3.DraggableRect:return i}},[n,i,c]),b=(0,y.useRef)(null),x=(0,y.useCallback)(()=>{let e=b.current;if(!e)return;let t=g.current.x*_.current.x,n=g.current.y*_.current.y;e.scrollBy(t,n)},[]),S=(0,y.useMemo)(()=>s===l3.TreeOrder?[...l].reverse():l,[s,l]);(0,y.useEffect)(()=>{if(!a||!l.length||!v){h();return}for(let e of S){if(r?.(e)===!1)continue;let n=u[l.indexOf(e)];if(!n)continue;let{direction:i,speed:a}=fHe(e,n,v,t,f);for(let e of[`x`,`y`])p[e][i[e]]||(a[e]=0,i[e]=0);if(a.x>0||a.y>0){h(),b.current=e,m(x,o),g.current=a,_.current=i;return}}g.current={x:0,y:0},_.current={x:0,y:0},h()},[t,x,r,h,a,o,JSON.stringify(v),JSON.stringify(p),m,l,S,u,JSON.stringify(f)])}var THe={x:{[U4.Backward]:!1,[U4.Forward]:!1},y:{[U4.Backward]:!1,[U4.Forward]:!1}};function EHe(e){let{delta:t,disabled:n}=e,r=d4(t);return l4(e=>{if(n||!r||!e)return THe;let i={x:Math.sign(t.x-r.x),y:Math.sign(t.y-r.y)};return{x:{[U4.Backward]:e.x[U4.Backward]||i.x===-1,[U4.Forward]:e.x[U4.Forward]||i.x===1},y:{[U4.Backward]:e.y[U4.Backward]||i.y===-1,[U4.Forward]:e.y[U4.Forward]||i.y===1}}},[n,t,r])}function DHe(e,t){let n=t==null?void 0:e.get(t),r=n?n.node.current:null;return l4(e=>t==null?null:r??e??null,[r,t])}function OHe(e,t){return(0,y.useMemo)(()=>e.reduce((e,n)=>{let{sensor:r}=n,i=r.activators.map(e=>({eventName:e.eventName,handler:t(e.handler,n)}));return[...e,...i]},[]),[e,t])}var u3;(function(e){e[e.Always=0]=`Always`,e[e.BeforeDragging=1]=`BeforeDragging`,e[e.WhileDragging=2]=`WhileDragging`})(u3||={});var d3;(function(e){e.Optimized=`optimized`})(d3||={});var f3=new Map;function kHe(e,t){let{dragging:n,dependencies:r,config:i}=t,[a,o]=(0,y.useState)(null),{frequency:s,measure:c,strategy:l}=i,u=(0,y.useRef)(e),d=g(),f=c4(d),p=(0,y.useCallback)(function(e){e===void 0&&(e=[]),!f.current&&o(t=>t===null?e:t.concat(e.filter(e=>!t.includes(e))))},[f]),m=(0,y.useRef)(null),h=l4(t=>{if(d&&!n)return f3;if(!t||t===f3||u.current!==e||a!=null){let t=new Map;for(let n of e){if(!n)continue;if(a&&a.length>0&&!a.includes(n.id)&&n.rect.current){t.set(n.id,n.rect.current);continue}let e=n.node.current,r=e?new J4(c(e),e):null;n.rect.current=r,r&&t.set(n.id,r)}return t}return t},[e,a,n,d,c]);return(0,y.useEffect)(()=>{u.current=e},[e]),(0,y.useEffect)(()=>{d||p()},[n,d]),(0,y.useEffect)(()=>{a&&a.length>0&&o(null)},[JSON.stringify(a)]),(0,y.useEffect)(()=>{d||typeof s!=`number`||m.current!==null||(m.current=setTimeout(()=>{p(),m.current=null},s))},[s,d,p,...r]),{droppableRects:h,measureDroppableContainers:p,measuringScheduled:a!=null};function g(){switch(l){case u3.Always:return!1;case u3.BeforeDragging:return n;default:return!n}}}function p3(e,t){return l4(n=>e?n||(typeof t==`function`?t(e):e):null,[t,e])}function AHe(e,t){return p3(e,t)}function jHe(e){let{callback:t,disabled:n}=e,r=s4(t),i=(0,y.useMemo)(()=>{if(n||typeof window>`u`||window.MutationObserver===void 0)return;let{MutationObserver:e}=window;return new e(r)},[r,n]);return(0,y.useEffect)(()=>()=>i?.disconnect(),[i]),i}function m3(e){let{callback:t,disabled:n}=e,r=s4(t),i=(0,y.useMemo)(()=>{if(n||typeof window>`u`||window.ResizeObserver===void 0)return;let{ResizeObserver:e}=window;return new e(r)},[n]);return(0,y.useEffect)(()=>()=>i?.disconnect(),[i]),i}function MHe(e){return new J4(F4(e),e)}function h3(e,t,n){t===void 0&&(t=MHe);let[r,i]=(0,y.useState)(null);function a(){i(r=>{if(!e)return null;if(e.isConnected===!1)return r??n??null;let i=t(e);return JSON.stringify(r)===JSON.stringify(i)?r:i})}let o=jHe({callback(t){if(e)for(let n of t){let{type:t,target:r}=n;if(t===`childList`&&r instanceof HTMLElement&&r.contains(e)){a();break}}}}),s=m3({callback:a});return o4(()=>{a(),e?(s?.observe(e),o?.observe(document.body,{childList:!0,subtree:!0})):(s?.disconnect(),o?.disconnect())},[e]),r}function NHe(e){return N4(e,p3(e))}var g3=[];function PHe(e){let t=(0,y.useRef)(e),n=l4(n=>e?n&&n!==g3&&e&&t.current&&e.parentNode===t.current.parentNode?n:L4(e):g3,[e]);return(0,y.useEffect)(()=>{t.current=e},[e]),n}function FHe(e){let[t,n]=(0,y.useState)(null),r=(0,y.useRef)(e),i=(0,y.useCallback)(e=>{let t=z4(e.target);t&&n(e=>e?(e.set(t,H4(t)),new Map(e)):null)},[]);return(0,y.useEffect)(()=>{let t=r.current;if(e!==t){a(t);let o=e.map(e=>{let t=z4(e);return t?(t.addEventListener(`scroll`,i,{passive:!0}),[t,H4(t)]):null}).filter(e=>e!=null);n(o.length?new Map(o):null),r.current=e}return()=>{a(e),a(t)};function a(e){e.forEach(e=>{z4(e)?.removeEventListener(`scroll`,i)})}},[i,e]),(0,y.useMemo)(()=>e.length?t?Array.from(t.values()).reduce((e,t)=>h4(e,t),E4):K4(e):E4,[e,t])}function _3(e,t){t===void 0&&(t=[]);let n=(0,y.useRef)(null);return(0,y.useEffect)(()=>{n.current=null},t),(0,y.useEffect)(()=>{let t=e!==E4;t&&!n.current&&(n.current=e),!t&&n.current&&(n.current=null)},[e]),n.current?g4(e,n.current):E4}function IHe(e){(0,y.useEffect)(()=>{if(!Q2)return;let t=e.map(e=>{let{sensor:t}=e;return t.setup==null?void 0:t.setup()});return()=>{for(let e of t)e?.()}},e.map(e=>{let{sensor:t}=e;return t}))}function LHe(e,t){return(0,y.useMemo)(()=>e.reduce((e,n)=>{let{eventName:r,handler:i}=n;return e[r]=e=>{i(e,t)},e},{}),[e,t])}function v3(e){return(0,y.useMemo)(()=>e?cHe(e):null,[e])}var y3=[];function RHe(e,t){t===void 0&&(t=F4);let[n]=e,r=v3(n?t4(n):null),[i,a]=(0,y.useState)(y3);function o(){a(()=>e.length?e.map(e=>W4(e)?r:new J4(t(e),e)):y3)}let s=m3({callback:o});return o4(()=>{s?.disconnect(),o(),e.forEach(e=>s?.observe(e))},[e]),i}function b3(e){if(!e)return null;if(e.children.length>1)return e;let t=e.children[0];return r4(t)?t:e}function zHe(e){let{measure:t}=e,[n,r]=(0,y.useState)(null),i=m3({callback:(0,y.useCallback)(e=>{for(let{target:n}of e)if(r4(n)){r(e=>{let r=t(n);return e?{...e,width:r.width,height:r.height}:r});break}},[t])}),[a,o]=u4((0,y.useCallback)(e=>{let n=b3(e);i?.disconnect(),n&&i?.observe(n),r(n?t(n):null)},[t,i]));return(0,y.useMemo)(()=>({nodeRef:a,rect:n,setRef:o}),[n,a,o])}var BHe=[{sensor:a3,options:{}},{sensor:t3,options:{}}],VHe={current:{}},x3={draggable:{measure:I4},droppable:{measure:I4,strategy:u3.WhileDragging,frequency:d3.Optimized},dragOverlay:{measure:F4}},S3=class extends Map{get(e){return e==null?void 0:super.get(e)??void 0}toArray(){return Array.from(this.values())}getEnabled(){return this.toArray().filter(e=>{let{disabled:t}=e;return!t})}getNodeFor(e){return this.get(e)?.node.current??void 0}},HHe={activatorEvent:null,active:null,activeNode:null,activeNodeRect:null,collisions:null,containerNodeRect:null,draggableNodes:new Map,droppableRects:new Map,droppableContainers:new S3,over:null,dragOverlay:{nodeRef:{current:null},rect:null,setRef:C4},scrollableAncestors:[],scrollableAncestorRects:[],measuringConfiguration:x3,measureDroppableContainers:C4,windowRect:null,measuringScheduled:!1},C3={activatorEvent:null,activators:[],active:null,activeNodeRect:null,ariaDescribedById:{draggable:``},dispatch:C4,draggableNodes:new Map,over:null,measureDroppableContainers:C4},w3=(0,y.createContext)(C3),T3=(0,y.createContext)(HHe);function UHe(){return{draggable:{active:null,initialCoordinates:{x:0,y:0},nodes:new Map,translate:{x:0,y:0}},droppable:{containers:new S3}}}function WHe(e,t){switch(t.type){case S4.DragStart:return{...e,draggable:{...e.draggable,initialCoordinates:t.initialCoordinates,active:t.active}};case S4.DragMove:return e.draggable.active==null?e:{...e,draggable:{...e.draggable,translate:{x:t.coordinates.x-e.draggable.initialCoordinates.x,y:t.coordinates.y-e.draggable.initialCoordinates.y}}};case S4.DragEnd:case S4.DragCancel:return{...e,draggable:{...e.draggable,active:null,initialCoordinates:{x:0,y:0},translate:{x:0,y:0}}};case S4.RegisterDroppable:{let{element:n}=t,{id:r}=n,i=new S3(e.droppable.containers);return i.set(r,n),{...e,droppable:{...e.droppable,containers:i}}}case S4.SetDroppableDisabled:{let{id:n,key:r,disabled:i}=t,a=e.droppable.containers.get(n);if(!a||r!==a.key)return e;let o=new S3(e.droppable.containers);return o.set(n,{...a,disabled:i}),{...e,droppable:{...e.droppable,containers:o}}}case S4.UnregisterDroppable:{let{id:n,key:r}=t,i=e.droppable.containers.get(n);if(!i||r!==i.key)return e;let a=new S3(e.droppable.containers);return a.delete(n),{...e,droppable:{...e.droppable,containers:a}}}default:return e}}function GHe(e){let{disabled:t}=e,{active:n,activatorEvent:r,draggableNodes:i}=(0,y.useContext)(w3),a=d4(r),o=d4(n?.id);return(0,y.useEffect)(()=>{if(!t&&!r&&a&&o!=null){if(!_4(a)||document.activeElement===a.target)return;let e=i.get(o);if(!e)return;let{activatorNode:t,node:n}=e;if(!t.current&&!n.current)return;requestAnimationFrame(()=>{for(let e of[t.current,n.current]){if(!e)continue;let t=HVe(e);if(t){t.focus();break}}})}},[r,t,i,o,a]),null}function E3(e,t){let{transform:n,...r}=t;return e!=null&&e.length?e.reduce((e,t)=>t({transform:e,...r}),n):n}function KHe(e){return(0,y.useMemo)(()=>({draggable:{...x3.draggable,...e?.draggable},droppable:{...x3.droppable,...e?.droppable},dragOverlay:{...x3.dragOverlay,...e?.dragOverlay}}),[e?.draggable,e?.droppable,e?.dragOverlay])}function qHe(e){let{activeNode:t,measure:n,initialRect:r,config:i=!0}=e,a=(0,y.useRef)(!1),{x:o,y:s}=typeof i==`boolean`?{x:i,y:i}:i;o4(()=>{if(!o&&!s||!t){a.current=!1;return}if(a.current||!r)return;let e=t?.node.current;if(!e||e.isConnected===!1)return;let i=N4(n(e),r);if(o||(i.x=0),s||(i.y=0),a.current=!0,Math.abs(i.x)>0||Math.abs(i.y)>0){let t=R4(e);t&&t.scrollBy({top:i.y,left:i.x})}},[t,o,s,r,n])}var D3=(0,y.createContext)({...E4,scaleX:1,scaleY:1}),O3;(function(e){e[e.Uninitialized=0]=`Uninitialized`,e[e.Initializing=1]=`Initializing`,e[e.Initialized=2]=`Initialized`})(O3||={});var k3=(0,y.memo)(function(e){let{id:t,accessibility:n,autoScroll:r=!0,children:i,sensors:a=BHe,collisionDetection:o=nHe,measuring:s,modifiers:c,...l}=e,[u,d]=(0,y.useReducer)(WHe,void 0,UHe),[f,p]=JVe(),[m,h]=(0,y.useState)(O3.Uninitialized),g=m===O3.Initialized,{draggable:{active:_,nodes:v,translate:b},droppable:{containers:x}}=u,S=_==null?null:v.get(_),C=(0,y.useRef)({initial:null,translated:null}),w=(0,y.useMemo)(()=>_==null?null:{id:_,data:S?.data??VHe,rect:C},[_,S]),T=(0,y.useRef)(null),[E,D]=(0,y.useState)(null),[O,k]=(0,y.useState)(null),A=c4(l,Object.values(l)),j=p4(`DndDescribedBy`,t),M=(0,y.useMemo)(()=>x.getEnabled(),[x]),N=KHe(s),{droppableRects:P,measureDroppableContainers:F,measuringScheduled:I}=kHe(M,{dragging:g,dependencies:[b.x,b.y],config:N.droppable}),L=DHe(v,_),R=(0,y.useMemo)(()=>O?v4(O):null,[O]),z=De(),B=AHe(L,N.draggable.measure);qHe({activeNode:_==null?null:v.get(_),config:z.layoutShiftCompensation,initialRect:B,measure:N.draggable.measure});let V=h3(L,N.draggable.measure,B),ee=h3(L?L.parentElement:null),te=(0,y.useRef)({activatorEvent:null,active:null,activeNode:L,collisionRect:null,collisions:null,droppableRects:P,draggableNodes:v,draggingNode:null,draggingNodeRect:null,droppableContainers:x,over:null,scrollableAncestors:[],scrollAdjustedTranslate:null}),ne=x.getNodeFor(te.current.over?.id),re=zHe({measure:N.dragOverlay.measure}),ie=re.nodeRef.current??L,ae=g?re.rect??V:null,oe=!!(re.nodeRef.current&&re.rect),se=NHe(oe?null:V),H=v3(ie?t4(ie):null),ce=PHe(g?ne??L:null),le=RHe(ce),ue=E3(c,{transform:{x:b.x-se.x,y:b.y-se.y,scaleX:1,scaleY:1},activatorEvent:O,active:w,activeNodeRect:V,containerNodeRect:ee,draggingNodeRect:ae,over:te.current.over,overlayNodeRect:re.rect,scrollableAncestors:ce,scrollableAncestorRects:le,windowRect:H}),de=R?h4(R,b):null,fe=FHe(ce),pe=_3(fe),me=_3(fe,[V]),he=h4(ue,pe),ge=ae?aHe(ae,ue):null,_e=w&&ge?o({active:w,collisionRect:ge,droppableRects:P,droppableContainers:M,pointerCoordinates:de}):null,ve=A4(_e,`id`),[ye,be]=(0,y.useState)(null),xe=rHe(oe?ue:h4(ue,me),ye?.rect??null,V),Se=(0,y.useRef)(null),Ce=(0,y.useCallback)((e,t)=>{let{sensor:n,options:r}=t;if(T.current==null)return;let i=v.get(T.current);if(!i)return;let a=e.nativeEvent;Se.current=new n({active:T.current,activeNode:i,event:a,options:r,context:te,onAbort(e){if(!v.get(e))return;let{onDragAbort:t}=A.current,n={id:e};t?.(n),f({type:`onDragAbort`,event:n})},onPending(e,t,n,r){if(!v.get(e))return;let{onDragPending:i}=A.current,a={id:e,constraint:t,initialCoordinates:n,offset:r};i?.(a),f({type:`onDragPending`,event:a})},onStart(e){let t=T.current;if(t==null)return;let n=v.get(t);if(!n)return;let{onDragStart:r}=A.current,i={activatorEvent:a,active:{id:t,data:n.data,rect:C}};(0,At.unstable_batchedUpdates)(()=>{r?.(i),h(O3.Initializing),d({type:S4.DragStart,initialCoordinates:e,active:t}),f({type:`onDragStart`,event:i}),D(Se.current),k(a)})},onMove(e){d({type:S4.DragMove,coordinates:e})},onEnd:o(S4.DragEnd),onCancel:o(S4.DragCancel)});function o(e){return async function(){let{active:t,collisions:n,over:r,scrollAdjustedTranslate:i}=te.current,o=null;if(t&&i){let{cancelDrop:s}=A.current;o={activatorEvent:a,active:t,collisions:n,delta:i,over:r},e===S4.DragEnd&&typeof s==`function`&&await Promise.resolve(s(o))&&(e=S4.DragCancel)}T.current=null,(0,At.unstable_batchedUpdates)(()=>{d({type:e}),h(O3.Uninitialized),be(null),D(null),k(null),Se.current=null;let t=e===S4.DragEnd?`onDragEnd`:`onDragCancel`;if(o){let e=A.current[t];e?.(o),f({type:t,event:o})}})}}},[v]),we=OHe(a,(0,y.useCallback)((e,t)=>(n,r)=>{let i=n.nativeEvent,a=v.get(r);if(T.current!==null||!a||i.dndKit||i.defaultPrevented)return;let o={active:a};e(n,t.options,o)===!0&&(i.dndKit={capturedBy:t.sensor},T.current=r,Ce(n,t))},[v,Ce]));IHe(a),o4(()=>{V&&m===O3.Initializing&&h(O3.Initialized)},[V,m]),(0,y.useEffect)(()=>{let{onDragMove:e}=A.current,{active:t,activatorEvent:n,collisions:r,over:i}=te.current;if(!t||!n)return;let a={active:t,activatorEvent:n,collisions:r,delta:{x:he.x,y:he.y},over:i};(0,At.unstable_batchedUpdates)(()=>{e?.(a),f({type:`onDragMove`,event:a})})},[he.x,he.y]),(0,y.useEffect)(()=>{let{active:e,activatorEvent:t,collisions:n,droppableContainers:r,scrollAdjustedTranslate:i}=te.current;if(!e||T.current==null||!t||!i)return;let{onDragOver:a}=A.current,o=r.get(ve),s=o&&o.rect.current?{id:o.id,rect:o.rect.current,data:o.data,disabled:o.disabled}:null,c={active:e,activatorEvent:t,collisions:n,delta:{x:i.x,y:i.y},over:s};(0,At.unstable_batchedUpdates)(()=>{be(s),a?.(c),f({type:`onDragOver`,event:c})})},[ve]),o4(()=>{te.current={activatorEvent:O,active:w,activeNode:L,collisionRect:ge,collisions:_e,droppableRects:P,draggableNodes:v,draggingNode:ie,draggingNodeRect:ae,droppableContainers:x,over:ye,scrollableAncestors:ce,scrollAdjustedTranslate:he},C.current={initial:ae,translated:ge}},[w,L,_e,ge,v,ie,ae,P,x,ye,ce,he]),wHe({...z,delta:b,draggingRect:ge,pointerCoordinates:de,scrollableAncestors:ce,scrollableAncestorRects:le});let Te=(0,y.useMemo)(()=>({active:w,activeNode:L,activeNodeRect:V,activatorEvent:O,collisions:_e,containerNodeRect:ee,dragOverlay:re,draggableNodes:v,droppableContainers:x,droppableRects:P,over:ye,measureDroppableContainers:F,scrollableAncestors:ce,scrollableAncestorRects:le,measuringConfiguration:N,measuringScheduled:I,windowRect:H}),[w,L,V,O,_e,ee,re,v,x,P,ye,F,ce,le,N,I,H]),Ee=(0,y.useMemo)(()=>({activatorEvent:O,activators:we,active:w,activeNodeRect:V,ariaDescribedById:{draggable:j},dispatch:d,draggableNodes:v,over:ye,measureDroppableContainers:F}),[O,we,w,V,d,j,v,ye,F]);return y.createElement(x4.Provider,{value:p},y.createElement(w3.Provider,{value:Ee},y.createElement(T3.Provider,{value:Te},y.createElement(D3.Provider,{value:xe},i)),y.createElement(GHe,{disabled:n?.restoreFocus===!1})),y.createElement(ZVe,{...n,hiddenTextDescribedById:j}));function De(){let e=E?.autoScrollEnabled===!1,t=typeof r==`object`?r.enabled===!1:r===!1,n=g&&!e&&!t;return typeof r==`object`?{...r,enabled:n}:{enabled:n}}}),JHe=(0,y.createContext)(null),A3=`button`,YHe=`Draggable`;function XHe(e){let{id:t,data:n,disabled:r=!1,attributes:i}=e,a=p4(YHe),{activators:o,activatorEvent:s,active:c,activeNodeRect:l,ariaDescribedById:u,draggableNodes:d,over:f}=(0,y.useContext)(w3),{role:p=A3,roleDescription:m=`draggable`,tabIndex:h=0}=i??{},g=c?.id===t,_=(0,y.useContext)(g?D3:JHe),[v,b]=u4(),[x,S]=u4(),C=LHe(o,t),w=c4(n);return o4(()=>(d.set(t,{id:t,key:a,node:v,activatorNode:x,data:w}),()=>{let e=d.get(t);e&&e.key===a&&d.delete(t)}),[d,t]),{active:c,activatorEvent:s,activeNodeRect:l,attributes:(0,y.useMemo)(()=>({role:p,tabIndex:h,"aria-disabled":r,"aria-pressed":g&&p===A3?!0:void 0,"aria-roledescription":m,"aria-describedby":u.draggable}),[r,p,h,g,m,u.draggable]),isDragging:g,listeners:r?void 0:C,node:v,over:f,setNodeRef:b,setActivatorNodeRef:S,transform:_}}function j3(){return(0,y.useContext)(T3)}var ZHe=`Droppable`,QHe={timeout:25};function $He(e){let{data:t,disabled:n=!1,id:r,resizeObserverConfig:i}=e,a=p4(ZHe),{active:o,dispatch:s,over:c,measureDroppableContainers:l}=(0,y.useContext)(w3),u=(0,y.useRef)({disabled:n}),d=(0,y.useRef)(!1),f=(0,y.useRef)(null),p=(0,y.useRef)(null),{disabled:m,updateMeasurementsFor:h,timeout:g}={...QHe,...i},_=c4(h??r),v=m3({callback:(0,y.useCallback)(()=>{if(!d.current){d.current=!0;return}p.current!=null&&clearTimeout(p.current),p.current=setTimeout(()=>{l(Array.isArray(_.current)?_.current:[_.current]),p.current=null},g)},[g]),disabled:m||!o}),[b,x]=u4((0,y.useCallback)((e,t)=>{v&&(t&&(v.unobserve(t),d.current=!1),e&&v.observe(e))},[v])),S=c4(t);return(0,y.useEffect)(()=>{!v||!b.current||(v.disconnect(),d.current=!1,v.observe(b.current))},[b,v]),(0,y.useEffect)(()=>(s({type:S4.RegisterDroppable,element:{id:r,key:a,disabled:n,node:b,rect:f,data:S}}),()=>s({type:S4.UnregisterDroppable,key:a,id:r})),[r]),(0,y.useEffect)(()=>{n!==u.current.disabled&&(s({type:S4.SetDroppableDisabled,id:r,key:a,disabled:n}),u.current.disabled=n)},[r,a,n,s]),{active:o,rect:f,isOver:c?.id===r,node:b,over:c,setNodeRef:x}}function eUe(e){let{animation:t,children:n}=e,[r,i]=(0,y.useState)(null),[a,o]=(0,y.useState)(null),s=d4(n);return!n&&!r&&s&&i(s),o4(()=>{if(!a)return;let e=r?.key,n=r?.props.id;if(e==null||n==null){i(null);return}Promise.resolve(t(n,a)).then(()=>{i(null)})},[t,r,a]),y.createElement(y.Fragment,null,n,r?(0,y.cloneElement)(r,{ref:o}):null)}var tUe={x:0,y:0,scaleX:1,scaleY:1};function nUe(e){let{children:t}=e;return y.createElement(w3.Provider,{value:C3},y.createElement(D3.Provider,{value:tUe},t))}var rUe={position:`fixed`,touchAction:`none`},iUe=e=>_4(e)?`transform 250ms ease`:void 0,aUe=(0,y.forwardRef)((e,t)=>{let{as:n,activatorEvent:r,adjustScale:i,children:a,className:o,rect:s,style:c,transform:l,transition:u=iUe}=e;if(!s)return null;let d=i?l:{...l,scaleX:1,scaleY:1},f={...rUe,width:s.width,height:s.height,top:s.top,left:s.left,transform:y4.Transform.toString(d),transformOrigin:i&&r?QVe(r,s):void 0,transition:typeof u==`function`?u(r):u,...c};return y.createElement(n,{className:o,style:f,ref:t},a)}),oUe={duration:250,easing:`ease`,keyframes:e=>{let{transform:{initial:t,final:n}}=e;return[{transform:y4.Transform.toString(t)},{transform:y4.Transform.toString(n)}]},sideEffects:(e=>t=>{let{active:n,dragOverlay:r}=t,i={},{styles:a,className:o}=e;if(a!=null&&a.active)for(let[e,t]of Object.entries(a.active))t!==void 0&&(i[e]=n.node.style.getPropertyValue(e),n.node.style.setProperty(e,t));if(a!=null&&a.dragOverlay)for(let[e,t]of Object.entries(a.dragOverlay))t!==void 0&&r.node.style.setProperty(e,t);return o!=null&&o.active&&n.node.classList.add(o.active),o!=null&&o.dragOverlay&&r.node.classList.add(o.dragOverlay),function(){for(let[e,t]of Object.entries(i))n.node.style.setProperty(e,t);o!=null&&o.active&&n.node.classList.remove(o.active)}})({styles:{active:{opacity:`0`}}})};function sUe(e){let{config:t,draggableNodes:n,droppableContainers:r,measuringConfiguration:i}=e;return s4((e,a)=>{if(t===null)return;let o=n.get(e);if(!o)return;let s=o.node.current;if(!s)return;let c=b3(a);if(!c)return;let{transform:l}=t4(a).getComputedStyle(a),u=P4(l);if(!u)return;let d=typeof t==`function`?t:cUe(t);return q4(s,i.draggable.measure),d({active:{id:e,data:o.data,node:s,rect:i.draggable.measure(s)},draggableNodes:n,dragOverlay:{node:a,rect:i.dragOverlay.measure(c)},droppableContainers:r,measuringConfiguration:i,transform:u})})}function cUe(e){let{duration:t,easing:n,sideEffects:r,keyframes:i}={...oUe,...e};return e=>{let{active:a,dragOverlay:o,transform:s,...c}=e;if(!t)return;let l={x:o.rect.left-a.rect.left,y:o.rect.top-a.rect.top},u={scaleX:s.scaleX===1?1:a.rect.width*s.scaleX/o.rect.width,scaleY:s.scaleY===1?1:a.rect.height*s.scaleY/o.rect.height},d={x:s.x-l.x,y:s.y-l.y,...u},f=i({...c,active:a,dragOverlay:o,transform:{initial:s,final:d}}),[p]=f,m=f[f.length-1];if(JSON.stringify(p)===JSON.stringify(m))return;let h=r?.({active:a,dragOverlay:o,...c}),g=o.node.animate(f,{duration:t,easing:n,fill:`forwards`});return new Promise(e=>{g.onfinish=()=>{h?.(),e()}})}}var M3=0;function lUe(e){return(0,y.useMemo)(()=>{if(e!=null)return M3++,M3},[e])}var uUe=y.memo(e=>{let{adjustScale:t=!1,children:n,dropAnimation:r,style:i,transition:a,modifiers:o,wrapperElement:s=`div`,className:c,zIndex:l=999}=e,{activatorEvent:u,active:d,activeNodeRect:f,containerNodeRect:p,draggableNodes:m,droppableContainers:h,dragOverlay:g,over:_,measuringConfiguration:v,scrollableAncestors:b,scrollableAncestorRects:x,windowRect:S}=j3(),C=(0,y.useContext)(D3),w=lUe(d?.id),T=E3(o,{activatorEvent:u,active:d,activeNodeRect:f,containerNodeRect:p,draggingNodeRect:g.rect,over:_,overlayNodeRect:g.rect,scrollableAncestors:b,scrollableAncestorRects:x,transform:C,windowRect:S}),E=p3(f),D=sUe({config:r,draggableNodes:m,droppableContainers:h,measuringConfiguration:v}),O=E?g.setRef:void 0;return y.createElement(nUe,null,y.createElement(eUe,{animation:D},d&&w?y.createElement(aUe,{key:w,id:d.id,ref:O,as:s,activatorEvent:u,adjustScale:t,className:c,transition:a,rect:E,style:{zIndex:l,...i},transform:T},n):null))});function N3(e,t,n){let r=e.slice();return r.splice(n<0?r.length+n:n,0,r.splice(t,1)[0]),r}function dUe(e,t){return e.reduce((e,n,r)=>{let i=t.get(n);return i&&(e[r]=i),e},Array(e.length))}function P3(e){return e!==null&&e>=0}function fUe(e,t){if(e===t)return!0;if(e.length!==t.length)return!1;for(let n=0;n{let{rects:t,activeIndex:n,overIndex:r,index:i}=e,a=N3(t,r,n),o=t[i],s=a[i];return!s||!o?null:{x:s.left-o.left,y:s.top-o.top,scaleX:s.width/o.width,scaleY:s.height/o.height}},I3={scaleX:1,scaleY:1},mUe=e=>{let{activeIndex:t,activeNodeRect:n,index:r,rects:i,overIndex:a}=e,o=i[t]??n;if(!o)return null;if(r===t){let e=i[a];return e?{x:0,y:tt&&r<=a?{x:0,y:-o.height-s,...I3}:r=a?{x:0,y:o.height+s,...I3}:{x:0,y:0,...I3}};function hUe(e,t,n){let r=e[t],i=e[t-1],a=e[t+1];return r?nr.map(e=>typeof e==`object`&&`id`in e?e.id:e),[r]),m=o!=null,h=o?p.indexOf(o.id):-1,g=l?p.indexOf(l.id):-1,_=(0,y.useRef)(p),v=!fUe(p,_.current),b=g!==-1&&h===-1||v,x=pUe(a);o4(()=>{v&&m&&u(p)},[v,p,m,u]),(0,y.useEffect)(()=>{_.current=p},[p]);let S=(0,y.useMemo)(()=>({activeIndex:h,containerId:d,disabled:x,disableTransforms:b,items:p,overIndex:g,useDragOverlay:f,sortedRects:dUe(p,c),strategy:i}),[h,d,x.draggable,x.droppable,b,p,g,c,f,i]);return y.createElement(R3.Provider,{value:S},t)}var gUe=e=>{let{id:t,items:n,activeIndex:r,overIndex:i}=e;return N3(n,r,i).indexOf(t)},_Ue=e=>{let{containerId:t,isSorting:n,wasDragging:r,index:i,items:a,newIndex:o,previousItems:s,previousContainerId:c,transition:l}=e;return!l||!r||s!==a&&i===o?!1:n?!0:o!==i&&t===c},vUe={duration:200,easing:`ease`},B3=`transform`,yUe=y4.Transition.toString({property:B3,duration:0,easing:`linear`}),bUe={roleDescription:`sortable`};function xUe(e){let{disabled:t,index:n,node:r,rect:i}=e,[a,o]=(0,y.useState)(null),s=(0,y.useRef)(n);return o4(()=>{if(!t&&n!==s.current&&r.current){let e=i.current;if(e){let t=F4(r.current,{ignoreTransform:!0}),n={x:e.left-t.left,y:e.top-t.top,scaleX:e.width/t.width,scaleY:e.height/t.height};(n.x||n.y)&&o(n)}}n!==s.current&&(s.current=n)},[t,n,r,i]),(0,y.useEffect)(()=>{a&&o(null)},[a]),a}function V3(e){let{animateLayoutChanges:t=_Ue,attributes:n,disabled:r,data:i,getNewIndex:a=gUe,id:o,strategy:s,resizeObserverConfig:c,transition:l=vUe}=e,{items:u,containerId:d,activeIndex:f,disabled:p,disableTransforms:m,sortedRects:h,overIndex:g,useDragOverlay:_,strategy:v}=(0,y.useContext)(R3),b=SUe(r,p),x=u.indexOf(o),S=(0,y.useMemo)(()=>({sortable:{containerId:d,index:x,items:u},...i}),[d,i,x,u]),C=(0,y.useMemo)(()=>u.slice(u.indexOf(o)),[u,o]),{rect:w,node:T,isOver:E,setNodeRef:D}=$He({id:o,data:S,disabled:b.droppable,resizeObserverConfig:{updateMeasurementsFor:C,...c}}),{active:O,activatorEvent:k,activeNodeRect:A,attributes:j,setNodeRef:M,listeners:N,isDragging:P,over:F,setActivatorNodeRef:I,transform:L}=XHe({id:o,data:S,attributes:{...bUe,...n},disabled:b.draggable}),R=RVe(D,M),z=!!O,B=z&&!m&&P3(f)&&P3(g),V=!_&&P,ee=B?(V&&B?L:null)??(s??v)({rects:h,activeNodeRect:A,activeIndex:f,overIndex:g,index:x}):null,te=P3(f)&&P3(g)?a({id:o,items:u,activeIndex:f,overIndex:g}):x,ne=O?.id,re=(0,y.useRef)({activeId:ne,items:u,newIndex:te,containerId:d}),ie=u!==re.current.items,ae=t({active:O,containerId:d,isDragging:P,isSorting:z,id:o,index:x,items:u,newIndex:re.current.newIndex,previousItems:re.current.items,previousContainerId:re.current.containerId,transition:l,wasDragging:re.current.activeId!=null}),oe=xUe({disabled:!ae,index:x,node:T,rect:w});return(0,y.useEffect)(()=>{z&&re.current.newIndex!==te&&(re.current.newIndex=te),d!==re.current.containerId&&(re.current.containerId=d),u!==re.current.items&&(re.current.items=u)},[z,te,d,u]),(0,y.useEffect)(()=>{if(ne===re.current.activeId)return;if(ne!=null&&re.current.activeId==null){re.current.activeId=ne;return}let e=setTimeout(()=>{re.current.activeId=ne},50);return()=>clearTimeout(e)},[ne]),{active:O,activeIndex:f,attributes:j,data:S,rect:w,index:x,newIndex:te,items:u,isOver:E,isSorting:z,isDragging:P,listeners:N,node:T,overIndex:g,over:F,setNodeRef:R,setActivatorNodeRef:I,setDroppableNodeRef:D,setDraggableNodeRef:M,transform:oe??ee,transition:se()};function se(){if(oe||ie&&re.current.newIndex===x)return yUe;if(!(V&&!_4(k)||!l)&&(z||ae))return y4.Transition.toString({...l,property:B3})}}function SUe(e,t){return typeof e==`boolean`?{draggable:e,droppable:!1}:{draggable:e?.draggable??t.draggable,droppable:e?.droppable??t.droppable}}function H3(e){if(!e)return!1;let t=e.data.current;return!!(t&&`sortable`in t&&typeof t.sortable==`object`&&`containerId`in t.sortable&&`items`in t.sortable&&`index`in t.sortable)}var CUe=[$4.Down,$4.Right,$4.Up,$4.Left],U3=(e,t)=>{let{context:{active:n,collisionRect:r,droppableRects:i,droppableContainers:a,over:o,scrollableAncestors:s}}=t;if(CUe.includes(e.code)){if(e.preventDefault(),!n||!r)return;let t=[];a.getEnabled().forEach(n=>{if(!n||n!=null&&n.disabled)return;let a=i.get(n.id);if(a)switch(e.code){case $4.Down:r.topa.top&&t.push(n);break;case $4.Left:r.left>a.left&&t.push(n);break;case $4.Right:r.left1&&(l=c[1].id),l!=null){let e=a.get(n.id),t=a.get(l),o=t?i.get(t.id):null,c=t?.node.current;if(c&&o&&e&&t){let n=L4(c).some((e,t)=>s[t]!==e),i=W3(e,t),a=wUe(e,t),l=n||!i?{x:0,y:0}:{x:a?r.width-o.width:0,y:a?r.height-o.height:0},u={x:o.left,y:o.top};return l.x&&l.y?u:g4(u,l)}}}};function W3(e,t){return!H3(e)||!H3(t)?!1:e.data.current.sortable.containerId===t.data.current.sortable.containerId}function wUe(e,t){return!H3(e)||!H3(t)||!W3(e,t)?!1:e.data.current.sortable.indexZ.listSlicerPipelines()}),{data:g}=K({queryKey:[`printers`],queryFn:()=>Z.getPrinters()}),_=(g??[]).reduce((e,t)=>(e[t.id]=t,e),{}),v=s.startsWith(`p:`)?parseInt(s.slice(2),10):void 0,b=s.startsWith(`c:`)?s.slice(2):void 0,{data:x,isLoading:S}=K({queryKey:[`pipeline-runs-all`,r,a,l,s],queryFn:()=>Z.listAllPipelineRuns({limit:G3,offset:l,pipelineId:a??void 0,status:r||void 0,targetPrinterId:v,targetModelClass:b}),refetchInterval:15e3}),C=q({mutationFn:e=>Z.cancelPipelineRun(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`pipeline-runs-all`]}),n(e(`pipelineRuns.toast.cancelled`,`Run cancelled`),`success`)},onError:t=>n(t.message||e(`pipelineRuns.toast.cancelFailed`,`Cancel failed`),`error`)}),w=q({mutationFn:e=>Z.retryFailedPipelineRun(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`pipeline-runs-all`]}),n(e(`pipelineRuns.toast.retryStarted`,`Retry started`),`success`)},onError:t=>n(t.message||e(`pipelineRuns.toast.retryFailed`,`Retry failed`),`error`)}),T=q({mutationFn:()=>Z.clearTerminalPipelineRuns(),onSuccess:r=>{t.invalidateQueries({queryKey:[`pipeline-runs-all`]}),m(!1),u(0),n(e(`pipelineRuns.toast.cleared`,`{{n}} runs cleared`,{n:r.deleted}),`success`)},onError:t=>n(t.message||e(`pipelineRuns.toast.clearFailed`,`Clear failed`),`error`)}),E=x?.runs??[],D=x?.total??0,O=(h?.pipelines??[]).reduce((e,t)=>(e[t.id]=t,e),{}),k=e=>{f(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},A=!!(r||a!==null||s),j=(()=>{let e=new Set,t=new Set;for(let n of h?.pipelines??[])n.target_kind===`printer_class`&&n.target_model_class?t.add(n.target_model_class):n.target_printer_id&&e.add(n.target_printer_id);return{printers:(g??[]).filter(t=>e.has(t.id)),classes:Array.from(t).sort()}})();return(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 mb-4 text-sm`,children:[(0,G.jsx)(`button`,{type:`button`,onClick:()=>t.invalidateQueries({queryKey:[`pipeline-runs-all`]}),"aria-label":e(`common.refresh`,`Refresh`),title:e(`common.refresh`,`Refresh`),className:`p-1.5 text-bambu-gray hover:text-white border border-bambu-dark-tertiary rounded`,children:(0,G.jsx)(Hl,{className:`w-3.5 h-3.5`})}),(0,G.jsx)(K3,{icon:(0,G.jsx)(ed,{className:`w-3.5 h-3.5 text-bambu-gray`}),ariaLabel:e(`pipelineRuns.filter.pipeline`,`Pipeline`),value:a===null?``:String(a),onChange:e=>{u(0),o(e?parseInt(e,10):null)},options:[{value:``,label:e(`pipelineRuns.filter.allPipelines`,`All pipelines`)},...(h?.pipelines??[]).map(e=>({value:String(e.id),label:e.name}))]}),(0,G.jsx)(K3,{icon:(0,G.jsx)(wc,{className:`w-3.5 h-3.5 text-bambu-gray`}),ariaLabel:e(`pipelineRuns.filter.status`,`Status`),value:r,onChange:e=>{u(0),i(e)},options:TUe.map(t=>({value:t,label:t===``?e(`pipelineRuns.filter.allStatus`,`All statuses`):e(`settings.pipelines.runs.status.${t}`,t)}))}),(j.printers.length>0||j.classes.length>0)&&(0,G.jsx)(K3,{icon:(0,G.jsx)(Rl,{className:`w-3.5 h-3.5 text-bambu-gray`}),ariaLabel:e(`pipelineRuns.filter.target`,`Target`),value:s,onChange:e=>{u(0),c(e)},options:[{value:``,label:e(`pipelineRuns.filter.allTargets`,`All targets`)},...j.printers.map(t=>({value:`p:${t.id}`,label:t.name,group:e(`settings.pipelines.field.targetKindSpecific`,`Specific printer`)})),...j.classes.map(t=>({value:`c:${t}`,label:e(`library.runWithPipeline.classTarget`,`Any {{model}}`,{model:t}),group:e(`settings.pipelines.field.targetKindClass`,`Printer class`)}))]}),A&&(0,G.jsx)(`button`,{type:`button`,onClick:()=>{i(``),o(null),c(``),u(0)},className:`text-xs text-bambu-gray hover:text-white`,children:e(`pipelineRuns.filter.clear`,`Clear filters`)}),(0,G.jsxs)(`div`,{className:`ml-auto flex items-center gap-2 text-xs text-bambu-gray`,children:[!S&&D>0&&(0,G.jsx)(`span`,{children:e(`pipelineRuns.totalCount`,`{{n}} run`,{n:D,count:D})}),(0,G.jsxs)(`button`,{type:`button`,onClick:()=>m(!0),disabled:D===0,className:`flex items-center gap-1 px-2 py-1 text-red-700 dark:text-red-400 hover:bg-red-50 dark:hover:bg-red-500/10 rounded disabled:opacity-50 disabled:cursor-not-allowed`,children:[(0,G.jsx)(Pu,{className:`w-3 h-3`}),e(`pipelineRuns.clearLog`,`Clear log`)]})]})]}),p&&(0,G.jsx)(`div`,{className:`fixed inset-0 z-50 bg-black/60 flex items-center justify-center p-4`,onClick:()=>m(!1),role:`dialog`,"aria-modal":`true`,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-2xl w-full max-w-md p-4`,onClick:e=>e.stopPropagation(),children:[(0,G.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(Pu,{className:`w-4 h-4 text-red-600 dark:text-red-400`}),e(`pipelineRuns.clearConfirmTitle`,`Clear log?`)]}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-2`,children:e(`pipelineRuns.clearConfirmBody`,`Delete every completed, failed, cancelled, and partial-failure pipeline run? In-flight runs are kept. This cannot be undone.`)}),(0,G.jsxs)(`div`,{className:`flex items-center justify-end gap-2 mt-4`,children:[(0,G.jsx)(`button`,{type:`button`,onClick:()=>m(!1),disabled:T.isPending,className:`px-3 py-1.5 text-sm text-bambu-gray hover:text-white`,children:e(`common.cancel`,`Cancel`)}),(0,G.jsxs)(`button`,{type:`button`,onClick:()=>T.mutate(),disabled:T.isPending,className:`px-3 py-1.5 text-sm bg-red-500 hover:bg-red-600 text-white rounded disabled:opacity-50 flex items-center gap-1`,children:[T.isPending?(0,G.jsx)(Y,{className:`w-3.5 h-3.5 animate-spin`}):(0,G.jsx)(Pu,{className:`w-3.5 h-3.5`}),e(`pipelineRuns.clearConfirmAction`,`Clear`)]})]})]})}),S&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray`,children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),e(`pipelineRuns.loading`,`Loading…`)]}),!S&&E.length===0&&(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:A?e(`pipelineRuns.filter.noMatches`,`No runs match the current filters.`):e(`pipelineRuns.empty`,`No pipeline runs yet.`)}),!S&&E.length>0&&(0,G.jsx)(`div`,{className:`space-y-1.5`,children:E.map(e=>(0,G.jsx)(DUe,{run:e,pipeline:e.pipeline_id?O[e.pipeline_id]:void 0,printersById:_,expanded:d.has(e.id),onToggle:()=>k(e.id),onCancel:()=>C.mutate(e.id),onRetry:()=>w.mutate(e.id),cancelling:C.isPending,retrying:w.isPending},e.id))}),!S&&D>G3&&(0,G.jsxs)(`div`,{className:`flex items-center justify-between mt-4 text-sm`,children:[(0,G.jsx)(`button`,{type:`button`,onClick:()=>u(Math.max(0,l-G3)),disabled:l===0,className:`px-3 py-1.5 rounded border border-bambu-dark-tertiary disabled:opacity-50 text-bambu-gray hover:text-white`,children:e(`common.previous`,`Previous`)}),(0,G.jsx)(`span`,{className:`text-bambu-gray text-xs`,children:e(`pipelineRuns.pagination`,`{{start}}–{{end}} of {{total}}`,{start:l+1,end:Math.min(l+G3,D),total:D})}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>u(l+G3),disabled:l+G3>=D,className:`px-3 py-1.5 rounded border border-bambu-dark-tertiary disabled:opacity-50 text-bambu-gray hover:text-white`,children:e(`common.next`,`Next`)})]})]})}function DUe({run:e,pipeline:t,printersById:n,expanded:r,onToggle:i,onCancel:a,onRetry:o,cancelling:s,retrying:c}){let{t:l}=U(),u=[`queued`,`slicing`,`dispatching`,`in_progress`].includes(e.status),d=e.status===`partial_failure`||e.status===`failed`,f=e.status===`cancelled`&&e.error_message===`Cancelled by user`,p=e.target_kind===`printer_class`&&e.target_model_class?l(`library.runWithPipeline.classTarget`,`Any {{model}}`,{model:e.target_model_class}):e.target_printer_id&&n[e.target_printer_id]?n[e.target_printer_id].name:null;return(0,G.jsxs)(`div`,{className:`rounded-md border border-bambu-dark-tertiary bg-bambu-dark/40 overflow-hidden`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2`,children:[(0,G.jsx)(`button`,{type:`button`,onClick:i,"aria-label":r?l(`common.collapse`,`Collapse`):l(`common.expand`,`Expand`),"aria-expanded":r,className:`text-bambu-gray hover:text-white flex-shrink-0`,children:r?(0,G.jsx)(ps,{className:`w-4 h-4`}):(0,G.jsx)(ms,{className:`w-4 h-4`})}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-0.5 text-sm`,children:[(0,G.jsxs)(`span`,{className:`font-medium text-white`,children:[`#`,e.id]}),(0,G.jsx)(`span`,{className:`text-white truncate`,children:t?.name??e.pipeline_name??`—`}),(0,G.jsx)(OUe,{status:e.status}),p&&(0,G.jsxs)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-bambu-dark-tertiary text-bambu-gray flex items-center gap-1`,children:[(0,G.jsx)(Rl,{className:`w-3 h-3`}),p]}),e.parent_run_id&&(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray/70 italic`,children:l(`pipelineRuns.retryOf`,`retry of #{{n}}`,{n:e.parent_run_id})})]}),e.source_filename&&(0,G.jsxs)(`div`,{className:`mt-0.5 flex items-center gap-1.5 text-xs text-bambu-gray min-w-0`,children:[(0,G.jsx)(fc,{className:`w-3 h-3 flex-shrink-0`}),(0,G.jsx)(`span`,{className:`truncate`,title:e.source_filename,children:e.source_filename})]}),(0,G.jsxs)(`div`,{className:`mt-0.5 text-xs text-bambu-gray/70 flex flex-wrap items-center gap-x-2`,children:[(0,G.jsx)(`span`,{children:new Date(e.created_at).toLocaleString()}),e.copies>1&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`span`,{className:`text-bambu-gray/40`,children:`·`}),(0,G.jsx)(`span`,{children:l(`pipelineRuns.copies`,`{{n}} copies`,{n:e.copies})})]}),(e.copies_completed>0||e.copies_failed>0||e.copies_cancelled>0)&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`span`,{className:`text-bambu-gray/40`,children:`·`}),(0,G.jsxs)(`span`,{children:[(0,G.jsx)(`span`,{className:`text-bambu-green`,children:e.copies_completed}),`/`,e.copies]}),e.copies_failed>0&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`span`,{className:`text-bambu-gray/40`,children:`·`}),(0,G.jsx)(`span`,{className:`text-red-700 dark:text-red-400`,children:l(`pipelineRuns.failedCount`,`{{n}} failed`,{n:e.copies_failed})})]})]})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1 flex-shrink-0`,children:[u&&(0,G.jsxs)(`button`,{type:`button`,onClick:a,disabled:s,"aria-label":l(`common.cancel`,`Cancel`),className:`text-xs px-2 py-1 text-red-700 dark:text-red-400 hover:bg-red-50 dark:hover:bg-red-500/10 rounded disabled:opacity-50 flex items-center gap-1`,children:[(0,G.jsx)(nd,{className:`w-3 h-3`}),l(`common.cancel`,`Cancel`)]}),d&&(0,G.jsxs)(`button`,{type:`button`,onClick:o,disabled:c,"aria-label":l(`pipelineRuns.retryFailed`,`Retry failed`),className:`text-xs px-2 py-1 text-bambu-green hover:bg-bambu-green/10 rounded disabled:opacity-50 flex items-center gap-1`,children:[(0,G.jsx)(Wl,{className:`w-3 h-3`}),l(`pipelineRuns.retryFailed`,`Retry failed`)]})]})]}),r&&(0,G.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary px-3 py-2 bg-bambu-dark/30`,children:[(0,G.jsx)(`div`,{className:`space-y-1.5`,children:e.jobs.map(e=>(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-xs`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray/60 w-14 flex-shrink-0`,children:l(`pipelineRuns.copyN`,`Copy {{n}}`,{n:e.copy_index+1})}),(0,G.jsx)(kUe,{status:e.status}),e.assigned_printer_name&&(0,G.jsxs)(`span`,{className:`text-bambu-gray flex items-center gap-1 truncate`,children:[(0,G.jsx)(Rl,{className:`w-3 h-3 text-bambu-gray/60`}),(0,G.jsx)(`span`,{className:`text-white truncate`,children:e.assigned_printer_name})]}),e.error_message&&(0,G.jsx)(`span`,{className:`text-red-700 dark:text-red-400 truncate`,title:e.error_message,children:e.error_message})]},e.id))}),e.error_message&&!f&&(0,G.jsx)(`div`,{className:`text-xs text-red-700 dark:text-red-400 mt-2 pt-2 border-t border-bambu-dark-tertiary`,children:e.error_message}),f&&(0,G.jsx)(`div`,{className:`text-xs text-bambu-gray/70 mt-2 pt-2 border-t border-bambu-dark-tertiary italic`,children:l(`pipelineRuns.cancelledByUser`,`Cancelled by user`)})]})]})}function OUe({status:e}){let{t}=U();return(0,G.jsx)(`span`,{className:`px-1.5 py-0.5 rounded text-[10px] uppercase font-semibold tracking-wide whitespace-nowrap ${{queued:`bg-slate-700 text-slate-200`,slicing:`bg-sky-700 text-sky-100`,dispatching:`bg-sky-700 text-sky-100`,in_progress:`bg-emerald-700 text-emerald-100`,completed:`bg-emerald-700 text-emerald-100`,failed:`bg-red-700 text-red-100`,partial_failure:`bg-amber-700 text-amber-100`,cancelled:`bg-rose-900 text-rose-200`}[e]}`,children:t(`settings.pipelines.runs.status.${e}`,e)})}function K3({value:e,onChange:t,options:n,icon:r,ariaLabel:i}){let[a,o]=(0,y.useState)(!1),s=(0,y.useRef)(null);(0,y.useEffect)(()=>{if(!a)return;let e=e=>{s.current&&!s.current.contains(e.target)&&o(!1)},t=e=>{e.key===`Escape`&&o(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[a]);let c=n.find(t=>t.value===e),l=[];for(let e of n){let t=l[l.length-1];t&&t.group===e.group?t.options.push(e):l.push({group:e.group,options:[e]})}return(0,G.jsxs)(`div`,{ref:s,className:`relative`,children:[(0,G.jsxs)(`button`,{type:`button`,onClick:()=>o(e=>!e),"aria-label":i,"aria-haspopup":`listbox`,"aria-expanded":a,className:`flex items-center gap-1.5 px-2 py-1 border border-bambu-dark-tertiary rounded bg-bambu-dark/40 text-xs text-white hover:border-bambu-gray/60 focus:outline-none focus:ring-1 focus:ring-bambu-green/40`,children:[r,(0,G.jsx)(`span`,{className:`truncate max-w-[14rem]`,children:c?.label??``}),(0,G.jsx)(ps,{className:`w-3 h-3 text-bambu-gray transition-transform ${a?`rotate-180`:``}`})]}),a&&(0,G.jsx)(`div`,{role:`listbox`,className:`absolute left-0 top-full mt-1 z-30 min-w-full max-h-72 overflow-auto rounded border border-bambu-dark-tertiary bg-bambu-dark-secondary shadow-xl py-1`,children:l.map((n,r)=>(0,G.jsxs)(`div`,{children:[n.group&&(0,G.jsx)(`div`,{className:`px-2 pt-1.5 pb-0.5 text-[10px] uppercase tracking-wider text-bambu-gray/60`,children:n.group}),n.options.map(n=>{let r=n.value===e;return(0,G.jsxs)(`button`,{type:`button`,role:`option`,"aria-selected":r,onClick:()=>{t(n.value),o(!1)},className:`flex w-full items-center gap-1.5 text-left px-2 py-1 text-xs whitespace-nowrap ${r?`bg-bambu-dark-tertiary text-white`:`text-bambu-gray hover:bg-bambu-dark-tertiary/60 hover:text-white`}`,children:[(0,G.jsx)(fs,{className:`w-3 h-3 flex-shrink-0 ${r?`opacity-100`:`opacity-0`}`}),(0,G.jsx)(`span`,{className:`truncate`,children:n.label})]},n.value)})]},r))})]})}function kUe({status:e}){let{t}=U();return(0,G.jsx)(`span`,{className:`px-1.5 py-0.5 rounded text-[10px] uppercase font-semibold tracking-wide ${{pending:`bg-slate-700 text-slate-200`,awaiting_printer:`bg-sky-700 text-sky-100`,queued:`bg-sky-700 text-sky-100`,printing:`bg-emerald-700 text-emerald-100`,completed:`bg-emerald-700 text-emerald-100`,failed:`bg-red-700 text-red-100`,cancelled:`bg-rose-900 text-rose-200`}[e]}`,children:t(`pipelineRuns.jobStatus.${e}`,e)})}function AUe(e){return e>=1e3?`${(e/1e3).toFixed(1)}kg`:`${Math.round(e)}g`}function jUe({activeCount:e,pendingCount:t,totalTime:n,totalWeight:r,historyCount:i,t:a}){return(0,G.jsx)(`div`,{className:`flex items-center gap-3 sm:gap-5 flex-wrap px-4 py-3 bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary mb-6`,children:[{icon:Nl,value:e,label:a(`queue.summary.printing`),color:`text-blue-600 dark:text-blue-400`},{icon:js,value:t,label:a(`queue.summary.queued`),color:`text-yellow-600 dark:text-yellow-400`},{icon:Nu,value:lp(n),label:a(`queue.summary.totalTime`),color:`text-bambu-green`},{icon:Xu,value:AUe(r),label:a(`queue.summary.totalWeight`),color:`text-purple-600 dark:text-purple-400`},{icon:xs,value:i,label:a(`queue.summary.history`),color:`text-bambu-gray`}].map((e,t)=>(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[t>0&&(0,G.jsx)(`span`,{className:`hidden sm:block text-bambu-dark-tertiary`,children:`|`}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,G.jsx)(e.icon,{className:`w-4 h-4 ${e.color}`}),(0,G.jsx)(`span`,{className:`text-sm font-semibold text-white`,children:e.value}),(0,G.jsx)(`span`,{className:`text-xs sm:text-sm text-bambu-gray`,children:e.label})]})]},t))})}var q3={completed:{icon:xs,color:`text-emerald-600 dark:text-emerald-400`,border:`border-l-emerald-500`},failed:{icon:Ds,color:`text-red-600 dark:text-red-400`,border:`border-l-red-500`},skipped:{icon:du,color:`text-orange-600 dark:text-orange-400`,border:`border-l-gray-500`},cancelled:{icon:Uo,color:`text-gray-400`,border:`border-l-gray-500`}};function MUe(e){if(!e)return null;let t=e.startsWith(`#`)?e.slice(1):e;return/^0{6,8}$/.test(t)||!/^[0-9a-fA-F]{6,8}$/.test(t)?null:`#${t.slice(0,6)}`}function J3({item:e,onRequeue:t,onRemove:n,timeFormat:r=`system`,hasPermission:i,canModify:a,t:o}){let s=q3[e.status]||q3.cancelled,c=s.icon,l=jT(e),u=e.archive_thumbnail?Z.getArchiveThumbnail(e.archive_id):e.library_file_thumbnail?Z.getLibraryFileThumbnailUrl(e.library_file_id):null,d=e.completed_at||e.created_at,f=MUe(e.filament_color),p=e.filament_used_grams?Math.round(e.filament_used_grams):null,m=!!e.error_message&&(e.status===`failed`||e.status===`skipped`);return(0,G.jsxs)(`div`,{className:`px-3 py-2 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary border-l-[3px] ${s.border}`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 sm:gap-3`,children:[(0,G.jsx)(c,{className:`w-4 h-4 shrink-0 ${s.color}`}),(0,G.jsxs)(`div`,{className:`relative shrink-0 history-thumb-hover`,children:[(0,G.jsx)(`div`,{className:`w-8 h-8 bg-bambu-dark rounded overflow-hidden`,children:u?(0,G.jsx)(`img`,{src:u,alt:``,className:`w-full h-full object-cover`}):(0,G.jsx)(`div`,{className:`w-full h-full flex items-center justify-center text-bambu-gray`,children:(0,G.jsx)(Jc,{className:`w-4 h-4`})})}),u&&(0,G.jsx)(`div`,{className:`history-thumb-preview absolute z-[60] left-full top-0 ml-2 w-48 h-48 pointer-events-none opacity-0 transition-opacity`,children:(0,G.jsx)(`img`,{src:u,alt:``,className:`w-full h-full object-cover rounded-lg shadow-2xl border-2 border-bambu-dark-tertiary bg-bambu-dark`})})]}),(0,G.jsx)(`span`,{className:`text-sm text-white font-medium truncate min-w-0 flex-1`,children:l}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray shrink-0`,title:d??void 0,children:up(d,r,o)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-0.5 shrink-0`,children:[(0,G.jsx)(Q,{variant:`ghost`,size:`sm`,onClick:t,disabled:!i(`queue:create`),title:i(`queue:create`)?o(`queue.actions.requeue`):o(`queue.permissions.noRequeue`),className:`text-bambu-green hover:text-bambu-green/80 hover:bg-bambu-green/10 p-1.5`,children:(0,G.jsx)(Hl,{className:`w-3.5 h-3.5`})}),(0,G.jsx)(Q,{variant:`ghost`,size:`sm`,onClick:n,disabled:!a(`queue`,`delete`,e.created_by_id),title:a(`queue`,`delete`,e.created_by_id)?o(`common.remove`):o(`queue.permissions.noRemove`),className:`p-1.5`,children:(0,G.jsx)(Pu,{className:`w-3.5 h-3.5`})})]})]}),(0,G.jsxs)(`div`,{className:`mt-1 ml-[3.25rem] flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-bambu-gray`,children:[e.printer_name&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1 shrink-0`,children:[(0,G.jsx)(Rl,{className:`w-3 h-3`}),(0,G.jsx)(`span`,{className:`truncate max-w-[100px] sm:max-w-[140px]`,children:e.printer_name})]}),(f||p)&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1 shrink-0`,children:[f?(0,G.jsx)(`span`,{className:`inline-block w-2.5 h-2.5 rounded-full border border-white/15`,style:{backgroundColor:f},"aria-hidden":!0}):(0,G.jsx)(Xu,{className:`w-3 h-3`}),(0,G.jsxs)(`span`,{className:`truncate`,children:[p?`${p}g`:null,p&&e.filament_type?` ${e.filament_type}`:null,!p&&e.filament_type?e.filament_type:null]})]}),e.print_time_seconds&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1 shrink-0`,children:[(0,G.jsx)(Nu,{className:`w-3 h-3`}),lp(e.print_time_seconds)]}),e.created_by_username&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1 shrink-0`,title:o(`queue.addedBy`,{name:e.created_by_username}),children:[(0,G.jsx)(Hu,{className:`w-3 h-3`}),(0,G.jsx)(`span`,{className:`truncate max-w-[120px]`,children:e.created_by_username})]})]}),m&&(0,G.jsxs)(`div`,{className:`mt-1 ml-[3.25rem] flex items-start gap-1 text-xs text-red-700 dark:text-red-400`,children:[(0,G.jsx)(ys,{className:`w-3 h-3 mt-0.5 shrink-0`}),(0,G.jsx)(`span`,{className:`break-words`,children:e.error_message})]})]})}function Y3(e){return e.printer_id==null?e.target_model?`model:${e.target_model}`:`unassigned`:`printer:${e.printer_id}`}function X3(e,t,n){if(n){let n=+!!e.been_jumped,r=+!!t.been_jumped;if(n!==r)return r-n;let i=e.print_time_seconds??1/0,a=t.print_time_seconds??1/0;if(i!==a)return i-a}return e.position-t.position}function NUe(e,t,n){let r=Y3(e),i=Y3(t);if(r!==i){if(e.printer_id!=null&&t.printer_id!=null)return e.printer_id-t.printer_id;let n=Z3(e),a=Z3(t);return n===a?re.trim()).every(e=>e.startsWith(`Busy:`)):!1}var Q3=3600*1e3,$3=24,e6=$3*Q3,FUe=32,IUe=40;function LUe(e){return e.toLocaleTimeString(void 0,{hour:`numeric`})}function t6(e){return e.toLocaleTimeString(void 0,{hour:`2-digit`,minute:`2-digit`})}function RUe({queueItems:e,printers:t,printerStatuses:n,sjfEnabled:r,onItemClick:i,t:a}){let[o,s]=(0,y.useState)(()=>new Date);(0,y.useEffect)(()=>{let e=setInterval(()=>s(new Date),6e4);return()=>clearInterval(e)},[]);let[c,l]=(0,y.useState)(0),u=(0,y.useMemo)(()=>{let e=o.getTime()+c;return Math.floor(e/Q3)*Q3},[o,c]),d=u+e6,f=o.getTime(),p=(0,y.useMemo)(()=>{let t=[],i=new Map,a=new Set,o=new Map;for(let r of e)if(r.status===`printing`){let e=r.printer_id==null?void 0:n[r.printer_id],i=rp(r.started_at)||new Date,s;if(e?.remaining_time!=null&&e.remaining_time>0)s=new Date(f+e.remaining_time*60*1e3);else if(r.print_time_seconds){let t=e?.progress||0,n=Math.max(0,1-t/100);s=new Date(f+r.print_time_seconds*n*1e3)}else s=new Date(f+Q3);t.push({item:r,estimatedStart:i,estimatedEnd:s,progress:e?.progress??void 0,type:`printing`});let c=Y3(r);a.add(c),o.set(c,Math.max(o.get(c)??f,s.getTime()))}else if(r.status===`pending`){if(r.manual_start||r.waiting_reason&&!PUe(r.waiting_reason))continue;let e=Y3(r);i.has(e)||i.set(e,[]),i.get(e).push(r)}let s=Date.now()+4320*Q3;for(let[e,n]of i){n.sort((e,t)=>X3(e,t,r));let i=a.has(e),c=n[0]?rp(n[0].scheduled_time):null,l=c&&c.getTime()<=s;if(!i&&!l)continue;let u=o.get(e)??f;for(let e of n){let n=rp(e.scheduled_time);n&&n.getTime()<=s&&(u=Math.max(u,n.getTime()));let r=(e.print_time_seconds||3600)*1e3;t.push({item:e,estimatedStart:new Date(u),estimatedEnd:new Date(u+r),type:`queued`}),u+=r}}return t},[e,n,f,r]),m=(0,y.useMemo)(()=>{let e=[];for(let n of t)e.push({key:`printer:${n.id}`,label:n.name,printerId:n.id,targetModel:null});let n=new Set,r=!1;for(let t of p)if(t.item.printer_id==null)if(t.item.target_model){let r=`model:${t.item.target_model}`;n.has(r)||(n.add(r),e.push({key:r,label:`${a(`queue.filter.any`)} ${t.item.target_model}`,printerId:null,targetModel:t.item.target_model}))}else r=!0;return r&&e.push({key:`unassigned`,label:a(`queue.filter.unassigned`),printerId:null,targetModel:null}),e},[t,p,a]),h=(0,y.useMemo)(()=>{let e=new Map;for(let t of p){let n;n=t.item.printer_id==null?t.item.target_model?`model:${t.item.target_model}`:`unassigned`:`printer:${t.item.printer_id}`,e.has(n)||e.set(n,[]),e.get(n).push(t)}return e},[p]),g=(0,y.useMemo)(()=>{let e=[];for(let t=0;t<=$3;t+=2){let n=u+t*Q3;e.push({ms:n,pct:t/$3*100,label:LUe(new Date(n))})}return e},[u]),_=(f-u)/e6*100,v=_>=0&&_<=100,b=(0,y.useMemo)(()=>{let e=0;for(let t of p)e=Math.max(e,t.estimatedEnd.getTime());return e>0?new Date(e):null},[p]),x=(0,y.useRef)(null);return(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between gap-3 mb-5`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Q,{variant:`ghost`,size:`sm`,onClick:()=>l(e=>e-12*Q3),className:`p-1.5`,title:a(`queue.timeline.window.back12h`),children:(0,G.jsx)(hs,{className:`w-4 h-4`})}),(0,G.jsxs)(`span`,{className:`text-sm font-medium text-white min-w-[180px] text-center`,children:[new Date(u).toLocaleString(void 0,{weekday:`short`,month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`}),` → `,new Date(d).toLocaleTimeString(void 0,{hour:`2-digit`,minute:`2-digit`})]}),(0,G.jsx)(Q,{variant:`ghost`,size:`sm`,onClick:()=>l(e=>e+12*Q3),className:`p-1.5`,title:a(`queue.timeline.window.forward12h`),children:(0,G.jsx)(ms,{className:`w-4 h-4`})}),c!==0&&(0,G.jsx)(Q,{variant:`ghost`,size:`sm`,onClick:()=>l(0),className:`text-xs text-bambu-green`,children:a(`queue.timeline.window.now`)})]}),b&&(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray flex items-center gap-1.5`,children:[(0,G.jsx)(js,{className:`w-3.5 h-3.5`}),a(`queue.timeline.allDoneBy`,{time:b.toLocaleString(void 0,{weekday:`short`,hour:`2-digit`,minute:`2-digit`})})]})]}),m.length>0&&p.length===0&&(0,G.jsx)(`div`,{className:`mb-4 p-3 rounded-lg border border-bambu-dark-tertiary bg-bambu-dark/40 text-xs text-bambu-gray`,children:a(`queue.timeline.nothingCommitted`)}),m.length===0?(0,G.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-16 text-bambu-gray`,children:[(0,G.jsx)(Jc,{className:`w-12 h-12 mb-3 opacity-30`}),(0,G.jsx)(`p`,{className:`text-sm`,children:a(`queue.timeline.noData`)})]}):(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary overflow-hidden`,children:[(0,G.jsxs)(`div`,{className:`flex border-b border-bambu-dark-tertiary`,children:[(0,G.jsx)(`div`,{className:`w-32 sm:w-40 shrink-0 px-3 py-2 text-xs font-medium text-bambu-gray border-r border-bambu-dark-tertiary`,children:a(`queue.timeline.printerColumnHeader`)}),(0,G.jsx)(`div`,{className:`relative flex-1 h-9`,children:g.map(e=>(0,G.jsx)(`div`,{className:`absolute top-0 bottom-0 border-l border-bambu-dark-tertiary/40 text-[10px] sm:text-xs text-bambu-gray pl-1 flex items-center`,style:{left:`${e.pct}%`},children:e.label},e.ms))})]}),(0,G.jsxs)(`div`,{ref:x,className:`relative`,children:[m.map(e=>{let t=h.get(e.key)??[];return(0,G.jsxs)(`div`,{className:`flex border-b border-bambu-dark-tertiary/40 last:border-b-0`,children:[(0,G.jsxs)(`div`,{className:`w-32 sm:w-40 shrink-0 px-3 py-3 border-r border-bambu-dark-tertiary flex items-center gap-2`,children:[(0,G.jsx)(Rl,{className:`w-3.5 h-3.5 shrink-0 ${e.printerId==null&&e.targetModel==null?`text-orange-600 dark:text-orange-400`:e.targetModel?`text-blue-600 dark:text-blue-400`:`text-bambu-green`}`}),(0,G.jsx)(`span`,{className:`text-sm text-white truncate`,children:e.label})]}),(0,G.jsxs)(`div`,{className:`relative flex-1`,style:{height:56},children:[g.map(e=>(0,G.jsx)(`div`,{className:`absolute top-0 bottom-0 border-l border-bambu-dark-tertiary/30`,style:{left:`${e.pct}%`}},e.ms)),(0,G.jsx)(`div`,{className:`absolute inset-0 opacity-30`,style:{backgroundImage:`repeating-linear-gradient(45deg, transparent, transparent 6px, rgba(255,255,255,0.04) 6px, rgba(255,255,255,0.04) 12px)`},"aria-hidden":!0}),t.map(e=>{let t=Math.max(u,e.estimatedStart.getTime()),n=Math.min(d,e.estimatedEnd.getTime());if(n<=u||t>=d)return null;let r=(t-u)/e6*100,a=(n-t)/e6*100,o=e.item.archive_name||e.item.library_file_name||`#${e.item.id}`,s=e.item.archive_thumbnail?Z.getArchiveThumbnail(e.item.archive_id):e.item.library_file_thumbnail?Z.getLibraryFileThumbnailUrl(e.item.library_file_id):null,c=e.type===`printing`,l=e.item.batch_id!=null;return(0,G.jsxs)(`button`,{onClick:()=>i(e.item),title:[o,`${t6(e.estimatedStart)} → ${t6(e.estimatedEnd)}`,e.item.print_time_seconds?lp(e.item.print_time_seconds):null,c&&e.progress!=null?`${Math.round(e.progress)}%`:null,e.item.batch_name?`batch: ${e.item.batch_name}`:null].filter(Boolean).join(` · `),className:`absolute rounded-md transition-all hover:brightness-110 hover:z-10 overflow-hidden flex items-center gap-1.5 px-1.5 text-left ${c?`bg-blue-500/30 border border-blue-400/60`:l?`bg-cyan-500/20 border border-cyan-400/50`:`bg-bambu-green/20 border border-bambu-green/40`}`,style:{left:`${r}%`,width:`max(${FUe}px, ${a}%)`,top:8,height:IUe},children:[s&&(0,G.jsx)(`img`,{src:s,alt:``,className:`w-7 h-7 rounded object-cover shrink-0 bg-bambu-dark`}),(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,G.jsx)(`div`,{className:`text-xs text-white font-medium truncate leading-tight`,children:o}),(0,G.jsxs)(`div`,{className:`text-[10px] text-bambu-gray truncate leading-tight`,children:[e.item.print_time_seconds?lp(e.item.print_time_seconds):``,c&&e.progress!=null?` · ${Math.round(e.progress)}%`:``]})]}),c&&e.progress!=null&&(0,G.jsx)(`div`,{className:`absolute bottom-0 left-0 h-0.5 bg-blue-300`,style:{width:`${e.progress}%`},"aria-hidden":!0})]},e.item.id)})]})]},e.key)}),v&&(0,G.jsxs)(`div`,{className:`absolute top-0 bottom-0 pointer-events-none z-20 flex inset-x-0`,children:[(0,G.jsx)(`div`,{className:`w-32 sm:w-40 shrink-0`}),(0,G.jsx)(`div`,{className:`relative flex-1`,children:(0,G.jsx)(`div`,{className:`absolute top-0 bottom-0 w-0.5 bg-red-400 shadow-[0_0_8px_rgba(248,113,113,0.6)]`,style:{left:`${_}%`},children:(0,G.jsx)(`div`,{className:`absolute -top-1 -left-1 w-2.5 h-2.5 bg-red-400 rounded-full`})})})]})]})]})]})}function zUe({hasPermission:e,t}){let n=co(),{showToast:r}=qd(),[i,a]=(0,y.useState)(`active`),[o,s]=(0,y.useState)(null),{data:c}=K({queryKey:[`settings`],queryFn:Z.getSettings}),l=Lf(c?.currency||`USD`),{data:u,isLoading:d}=K({queryKey:[`batches`,i],queryFn:()=>Z.getBatches(i===`all`?void 0:i)}),f=()=>{n.invalidateQueries({queryKey:[`batches`]}),n.invalidateQueries({queryKey:[`queue`]})},p=q({mutationFn:({id:e,plateId:t})=>Z.dispatchBatch(e,t===void 0?{}:{plate_id:t,only_plate:!0}),onSuccess:e=>{f(),r(t(`queue.batchOrders.dispatched`,{name:e.name}),`success`)},onError:e=>r(e.message,`error`)}),m=q({mutationFn:e=>Z.cancelBatch(e),onSuccess:()=>{f(),s(null),r(t(`queue.batchCancelled`),`success`)},onError:e=>r(e.message,`error`)}),h=e(`queue:create`),g=e(`queue:delete_all`);return(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 mb-4`,children:[(0,G.jsx)(Cl,{className:`w-5 h-5 text-cyan-700 dark:text-cyan-300`}),(0,G.jsx)(`h2`,{className:`text-base sm:text-lg font-semibold text-white`,children:t(`queue.batchOrders.title`)}),(0,G.jsx)(`div`,{className:`flex gap-1 ml-auto`,children:[`active`,`completed`,`cancelled`,`all`].map(e=>(0,G.jsx)(`button`,{type:`button`,onClick:()=>a(e),className:`text-xs px-2.5 py-1 rounded-full border transition-colors ${i===e?`border-bambu-green bg-bambu-green/10 text-bambu-green`:`border-bambu-dark-tertiary text-bambu-gray hover:border-bambu-gray`}`,children:t(`queue.batchOrders.filter.${e}`)},e))})]}),d?(0,G.jsx)(`div`,{className:`text-center py-12 text-bambu-gray`,children:t(`common.loading`)}):u?.length?(0,G.jsx)(`div`,{className:`space-y-4`,children:u.map(e=>(0,G.jsx)(BUe,{batch:e,currency:l,canDispatch:h,canCancel:g,isDispatching:p.isPending&&p.variables?.id===e.id,onDispatch:t=>p.mutate({id:e.id,plateId:t}),onCancel:()=>s(e),t},e.id))}):(0,G.jsxs)(zd,{className:`p-12 text-center border-dashed`,children:[(0,G.jsx)(Cl,{className:`w-16 h-16 text-bambu-gray mx-auto mb-4 opacity-50`}),(0,G.jsx)(`h3`,{className:`text-xl font-medium text-white mb-2`,children:t(`queue.batchOrders.emptyTitle`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray max-w-md mx-auto`,children:t(`queue.batchOrders.emptyDescription`)})]}),o&&(0,G.jsx)(of,{title:t(`queue.cancelBatchConfirmTitle`),message:t(`queue.cancelBatchConfirmMessage`),confirmText:t(`queue.cancelBatch`),variant:`warning`,onConfirm:()=>m.mutate(o.id),onCancel:()=>s(null)})]})}var n6={active:`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-300`,completed:`bg-green-100 dark:bg-green-500/20 text-green-700 dark:text-green-300`,cancelled:`bg-bambu-dark-tertiary text-bambu-gray`};function BUe({batch:e,currency:t,canDispatch:n,canCancel:r,isDispatching:i,onDispatch:a,onCancel:o,t:s}){let c=e.has_targets?e.target_count:e.completed_count+e.pending_count+e.printing_count+e.failed_count,l=c>0?Math.round(e.completed_count/c*100):0,u=e.has_targets?e.remaining_count-e.dispatchable_count:0,d=e.due_date?rp(e.due_date):null,f=d!=null&&e.status===`active`&&d.getTime()0&&e.status!==`cancelled`&&n&&(0,G.jsxs)(Q,{variant:`primary`,size:`sm`,onClick:()=>a(),disabled:i,children:[(0,G.jsx)(Ts,{className:`w-4 h-4 mr-1`}),s(`queue.batchOrders.dispatchRemaining`,{count:e.dispatchable_count})]}),e.status===`active`&&r&&(0,G.jsxs)(Q,{variant:`ghost`,size:`sm`,onClick:o,children:[(0,G.jsx)(Ds,{className:`w-4 h-4 mr-1`}),s(`queue.cancelBatch`)]})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-3 mb-2`,children:[(0,G.jsx)(`div`,{className:`flex-1 h-2 bg-bambu-dark-tertiary rounded-full overflow-hidden`,children:(0,G.jsx)(`div`,{className:`h-full rounded-full transition-all ${e.status===`completed`?`bg-bambu-green`:`bg-blue-500`}`,style:{width:`${Math.min(100,l)}%`}})}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap tabular-nums`,children:s(`queue.batchProgress`,{completed:e.completed_count,total:c})})]}),(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-x-4 gap-y-1 text-xs text-bambu-gray mb-1`,children:[e.printing_count>0&&(0,G.jsx)(`span`,{children:s(`queue.batchOrders.printing`,{count:e.printing_count})}),e.pending_count>0&&(0,G.jsx)(`span`,{children:s(`queue.batch.pendingCount`,{count:e.pending_count})}),e.failed_count>0&&(0,G.jsxs)(`span`,{className:`text-orange-600 dark:text-orange-400 flex items-center gap-1`,children:[(0,G.jsx)(Lu,{className:`w-3 h-3`}),s(`queue.batchOrders.failed`,{count:e.failed_count})]}),e.has_targets&&e.remaining_count>0&&(0,G.jsx)(`span`,{children:s(`queue.batchOrders.remaining`,{count:e.remaining_count})}),e.print_time_seconds>0&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(js,{className:`w-3 h-3`}),lp(e.print_time_seconds)]}),e.actual_cost!=null&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(Ls,{className:`w-3 h-3`}),(0,G.jsx)(`span`,{children:s(`queue.batchOrders.costSoFar`,{amount:`${t} ${e.actual_cost.toFixed(2)}`})}),e.estimated_remaining_cost!=null&&e.estimated_remaining_cost>0&&(0,G.jsx)(`span`,{children:s(`queue.batchOrders.costRemaining`,{amount:`${t} ${e.estimated_remaining_cost.toFixed(2)}`})})]})]}),u>0&&e.status!==`cancelled`&&(0,G.jsxs)(`p`,{className:`flex items-start gap-1.5 text-xs text-orange-600 dark:text-orange-400 mb-1`,children:[(0,G.jsx)(Lu,{className:`w-3 h-3 mt-0.5 flex-shrink-0`}),(0,G.jsx)(`span`,{children:s(`queue.batchOrders.strandedNotice`,{runs:u,owed:e.remaining_count})})]}),e.has_targets&&e.plates.length>0&&(0,G.jsx)(`div`,{className:`mt-3 border-t border-bambu-dark-tertiary pt-3 space-y-1.5`,children:e.plates.map(r=>(0,G.jsx)(VUe,{plate:r,batchStatus:e.status,currency:t,canDispatch:n,isDispatching:i,onDispatch:()=>a(r.plate_id),t:s},`${r.plate_id??`file`}`))})]})}function VUe({plate:e,batchStatus:t,currency:n,canDispatch:r,isDispatching:i,onDispatch:a,t:o}){let s=e.plate_name||(e.plate_id==null?o(`queue.batchOrders.wholeFile`):o(`queue.plateNumber`,{index:e.plate_id}));return(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-xs`,children:[(0,G.jsx)(Jc,{className:`w-3.5 h-3.5 text-bambu-gray flex-shrink-0`}),(0,G.jsx)(`span`,{className:`text-white min-w-0 truncate`,children:s}),(0,G.jsx)(`span`,{className:`text-bambu-gray tabular-nums`,children:o(`queue.batchOrders.plateProgress`,{completed:e.completed_count,target:e.quantity_target})}),e.failed_count>0&&(0,G.jsx)(`span`,{className:`text-orange-600 dark:text-orange-400`,children:o(`queue.batchOrders.failed`,{count:e.failed_count})}),e.actual_cost!=null&&(0,G.jsx)(`span`,{className:`text-bambu-gray tabular-nums`,children:`${n} ${e.actual_cost.toFixed(2)}`}),e.remaining>0&&t!==`cancelled`&&(0,G.jsxs)(`span`,{className:`ml-auto flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:o(`queue.batchOrders.remaining`,{count:e.remaining})}),e.can_dispatch?r&&(0,G.jsx)(`button`,{type:`button`,onClick:a,disabled:i,className:`text-bambu-green hover:underline disabled:opacity-50`,children:o(`queue.batchOrders.dispatchPlate`)}):(0,G.jsx)(`span`,{className:`text-orange-600 dark:text-orange-400`,children:o(`queue.batchOrders.strandedPlate`)})]})]})}function r6(e,t=!1){return t&&e>=1e3?`${(e/1e3).toFixed(1)}kg`:`${Math.round(e)}g`}function HUe({status:e,waitingReason:t,printerState:n,t:r}){if(e===`pending`&&t)return(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full text-xs font-medium border text-purple-700 dark:text-purple-400 bg-purple-50 dark:bg-purple-400/10 border-purple-200 dark:border-purple-400/20`,children:[(0,G.jsx)(js,{className:`w-3.5 h-3.5`}),r(`queue.status.waiting`)]});if(e===`printing`&&n===`PAUSE`)return(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full text-xs font-medium border text-yellow-700 dark:text-yellow-400 bg-yellow-50 dark:bg-yellow-400/10 border-yellow-200 dark:border-yellow-400/20`,children:[(0,G.jsx)(Dl,{className:`w-3.5 h-3.5`}),r(`queue.status.paused`)]});let{icon:i,color:a,label:o}={pending:{icon:js,color:`text-status-warning bg-status-warning/10 border-status-warning/20`,label:r(`queue.status.pending`)},printing:{icon:Nl,color:`text-blue-700 dark:text-blue-400 bg-blue-50 dark:bg-blue-400/10 border-blue-200 dark:border-blue-400/20`,label:r(`queue.status.printing`)},completed:{icon:xs,color:`text-status-ok bg-status-ok/10 border-status-ok/20`,label:r(`queue.status.completed`)},failed:{icon:Ds,color:`text-status-error bg-status-error/10 border-status-error/20`,label:r(`queue.status.failed`)},skipped:{icon:du,color:`text-orange-700 dark:text-orange-400 bg-orange-50 dark:bg-orange-400/10 border-orange-200 dark:border-orange-400/20`,label:r(`queue.status.skipped`)},cancelled:{icon:nd,color:`text-gray-400 bg-gray-400/10 border-gray-400/20`,label:r(`queue.status.cancelled`)}}[e];return(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full text-xs font-medium border ${a}`,children:[(0,G.jsx)(i,{className:`w-3.5 h-3.5`}),o]})}function UUe({selectedCount:e,printers:t,onSave:n,onClose:r,isSaving:i,canControlPrinter:a,hasGcodeSnippets:o,t:s}){let[c,l]=(0,y.useState)(`unchanged`),[u,d]=(0,y.useState)(`unchanged`),[f,p]=(0,y.useState)(`unchanged`),[m,h]=(0,y.useState)(`unchanged`),[g,_]=(0,y.useState)(`unchanged`),[v,b]=(0,y.useState)(`unchanged`),[x,S]=(0,y.useState)(`unchanged`),[C,w]=(0,y.useState)(`unchanged`),[T,E]=(0,y.useState)(`unchanged`),[D,O]=(0,y.useState)(`unchanged`),[k,A]=(0,y.useState)(`unchanged`),[j,M]=(0,y.useState)(`unchanged`),N=t.some(e=>e.nozzle_count===2),P=()=>{let e={};c!==`unchanged`&&(e.printer_id=c),u!==`unchanged`&&(e.manual_start=u),f!==`unchanged`&&(e.auto_off_after=f),m!==`unchanged`&&(e.require_previous_success=m),g!==`unchanged`&&(e.gcode_injection=g),v!==`unchanged`&&(e.bed_levelling=v),x!==`unchanged`&&(e.flow_cali=x),C!==`unchanged`&&(e.vibration_cali=C),T!==`unchanged`&&(e.layer_inspect=T),D!==`unchanged`&&(e.timelapse=D),k!==`unchanged`&&(e.use_ams=k),j!==`unchanged`&&(e.nozzle_offset_cali=j),n(e)},F=c!==`unchanged`||u!==`unchanged`||f!==`unchanged`||m!==`unchanged`||v!==`unchanged`||x!==`unchanged`||C!==`unchanged`||T!==`unchanged`||D!==`unchanged`||k!==`unchanged`||j!==`unchanged`||g!==`unchanged`;return(0,G.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center p-4 bg-black/50 backdrop-blur-sm`,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-lg max-h-[90vh] overflow-y-auto`,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-lg font-semibold text-white`,children:s(`queue.bulkEdit.title`,{count:e})}),(0,G.jsx)(`button`,{onClick:r,className:`p-1 hover:bg-bambu-dark rounded`,children:(0,G.jsx)(nd,{className:`w-5 h-5 text-bambu-gray`})})]}),(0,G.jsxs)(`div`,{className:`p-4 space-y-4`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:s(`queue.bulkEdit.description`)}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:s(`queue.bulkEdit.printer`)}),(0,G.jsxs)(`select`,{value:c===null?`null`:c===`unchanged`?`unchanged`:String(c),onChange:e=>{let t=e.target.value;l(t===`unchanged`?`unchanged`:t===`null`?null:Number(t))},className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,G.jsx)(`option`,{value:`unchanged`,children:s(`queue.bulkEdit.noChange`)}),(0,G.jsx)(`option`,{value:`null`,children:s(`queue.filter.unassigned`)}),t.map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:s(`queue.bulkEdit.queueOptions`)}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(i6,{label:s(`queue.bulkEdit.staged`),value:u,onChange:d,t:s}),(0,G.jsx)(i6,{label:s(`queue.bulkEdit.autoPowerOff`),value:f,onChange:p,disabled:!a,t:s}),(0,G.jsx)(i6,{label:s(`queue.bulkEdit.requirePrevious`),value:m,onChange:h,t:s}),o&&(0,G.jsx)(i6,{label:s(`queue.bulkEdit.gcodeInjection`),value:g,onChange:_,t:s})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:s(`queue.bulkEdit.printOptions`)}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(a6,{label:s(`queue.bulkEdit.bedLevelling`),value:v,onChange:b,t:s}),(0,G.jsx)(a6,{label:s(`queue.bulkEdit.flowCalibration`),value:x,onChange:S,t:s}),(0,G.jsx)(i6,{label:s(`queue.bulkEdit.vibrationCalibration`),value:C,onChange:w,t:s}),(0,G.jsx)(i6,{label:s(`queue.bulkEdit.layerInspection`),value:T,onChange:E,t:s}),(0,G.jsx)(i6,{label:s(`queue.bulkEdit.timelapse`),value:D,onChange:O,t:s}),(0,G.jsx)(i6,{label:s(`queue.bulkEdit.useAms`),value:k,onChange:A,t:s}),N&&(0,G.jsx)(a6,{label:s(`queue.bulkEdit.nozzleOffsetCali`),value:j,onChange:M,t:s})]})]})]}),(0,G.jsxs)(`div`,{className:`flex justify-end gap-3 p-4 border-t border-bambu-dark-tertiary`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:r,children:s(`common.cancel`)}),(0,G.jsx)(Q,{onClick:P,disabled:!F||i,children:s(i?`common.saving`:`queue.bulkEdit.applyChanges`)})]})]})})}function i6({label:e,value:t,onChange:n,disabled:r,t:i}){return(0,G.jsxs)(`div`,{className:`flex items-center justify-between py-1 ${r?`opacity-50`:``}`,children:[(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1 bg-bambu-dark rounded-lg p-0.5`,children:[(0,G.jsx)(`button`,{onClick:()=>n(`unchanged`),disabled:r,className:`px-2 py-1 text-xs rounded ${t===`unchanged`?`bg-bambu-dark-tertiary text-white`:`text-bambu-gray hover:text-white`} disabled:cursor-not-allowed`,children:`—`}),(0,G.jsx)(`button`,{onClick:()=>n(!1),disabled:r,className:`px-2 py-1 text-xs rounded ${t===!1?`bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400`:`text-bambu-gray hover:text-white`} disabled:cursor-not-allowed`,children:i(`common.off`)}),(0,G.jsx)(`button`,{onClick:()=>n(!0),disabled:r,className:`px-2 py-1 text-xs rounded ${t===!0?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:text-white`} disabled:cursor-not-allowed`,children:i(`common.on`)})]})]})}function a6({label:e,value:t,onChange:n,t:r}){let i=[{key:`unchanged`,label:`—`,active:`bg-bambu-dark-tertiary text-white`},{key:`off`,label:r(`settings.calibrationMode_off`),active:`bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400`},{key:`auto`,label:r(`settings.calibrationMode_auto`),active:`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`},{key:`on`,label:r(`settings.calibrationMode_on`),active:`bg-bambu-green/20 text-bambu-green`}];return(0,G.jsxs)(`div`,{className:`flex items-center justify-between py-1`,children:[(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e}),(0,G.jsx)(`div`,{className:`flex items-center gap-1 bg-bambu-dark rounded-lg p-0.5`,children:i.map(({key:e,label:r,active:i})=>(0,G.jsx)(`button`,{onClick:()=>n(e),className:`px-2 py-1 text-xs rounded ${t===e?i:`text-bambu-gray hover:text-white`}`,children:r},e))})]})}function o6({item:e,position:t,onEdit:n,onCancel:r,onRemove:i,onStop:a,onRequeue:o,onStart:s,onMoveUp:c,onMoveDown:l,timeFormat:u=`system`,isSelected:d=!1,onToggleSelect:f,hasPermission:p,canModify:m,printerState:h,showEta:g=!1,etaNow:_,t:v}){let{data:y}=K({queryKey:[`printerStatus`,e.printer_id],queryFn:()=>Z.getPrinterStatus(e.printer_id),refetchInterval:3e4,enabled:e.printer_id!=null&&h===`printing`}),b=!!e.library_file_id&&!e.archive_id,{data:x}=K({queryKey:[`archive-plates`,e.archive_id],queryFn:()=>Z.getArchivePlates(e.archive_id),enabled:!!e.archive_id&&!b&&!e.archive_deleted}),{data:S}=K({queryKey:[`library-file-plates`,e.library_file_id],queryFn:()=>Z.getLibraryFilePlates(e.library_file_id),enabled:b&&!!e.library_file_id}),C=b?S:x,w=C?.plates??[],T=p(`queue:reorder`),{attributes:E,listeners:D,setNodeRef:O,transform:k,transition:A,isDragging:j}=V3({id:e.id,disabled:e.status!==`pending`||!T}),M={transform:y4.Transform.toString(k),transition:A},N=e.status===`printing`,P=e.status===`pending`,F=[`completed`,`failed`,`skipped`,`cancelled`].includes(e.status),I=P&&g&&e.print_time_seconds!=null&&e.print_time_seconds>0?cp(e.print_time_seconds/60,u,v,_):null,L=P&&f;return(0,G.jsxs)(`div`,{ref:O,style:M,className:` group relative bg-bambu-dark-secondary rounded-xl border transition-all duration-200 border-l-[3px] ${N?`border-l-blue-500`:P?`border-l-yellow-500`:e.status===`completed`?`border-l-emerald-500`:e.status===`failed`?`border-l-red-500`:`border-l-gray-500`} ${j?`opacity-50 scale-[1.02] shadow-xl z-50`:``} @@ -4360,16 +4360,16 @@ img.ProseMirror-separator { ${d&&L?`sm:border-bambu-dark-tertiary border-bambu-green/40`:``} ${!d&&!N?`border-bambu-dark-tertiary hover:border-bambu-dark-tertiary/80`:``} ${L?`cursor-pointer sm:cursor-default`:``} - `,onClick:L?()=>{window.innerWidth<640&&f()}:void 0,children:[L&&d&&(0,G.jsx)(`div`,{className:`sm:hidden absolute left-0 top-3 bottom-3 w-1 rounded-full bg-bambu-green`}),(0,G.jsxs)(`div`,{className:`flex items-start sm:items-center gap-2 sm:gap-4 p-3 sm:p-4`,children:[P&&(c||l)&&(0,G.jsxs)(`div`,{className:`flex sm:hidden flex-col shrink-0 -my-1`,onClick:e=>e.stopPropagation(),children:[(0,G.jsx)(`button`,{type:`button`,onClick:c,disabled:!c,title:v(`queue.moveUp`),"aria-label":v(`queue.moveUp`),className:`flex items-center justify-center w-8 h-7 rounded-lg text-bambu-gray hover:text-white hover:bg-bambu-dark disabled:opacity-25 disabled:hover:bg-transparent transition-colors`,children:(0,G.jsx)(gs,{className:`w-5 h-5`})}),(0,G.jsx)(`button`,{type:`button`,onClick:l,disabled:!l,title:v(`queue.moveDown`),"aria-label":v(`queue.moveDown`),className:`flex items-center justify-center w-8 h-7 rounded-lg text-bambu-gray hover:text-white hover:bg-bambu-dark disabled:opacity-25 disabled:hover:bg-transparent transition-colors`,children:(0,G.jsx)(ps,{className:`w-5 h-5`})})]}),P&&f&&(0,G.jsx)(`button`,{onClick:e=>{e.stopPropagation(),f()},className:`hidden sm:flex items-center justify-center w-6 h-6 rounded border transition-colors shrink-0 ${d?`bg-bambu-green border-bambu-green text-white`:`border-white/30 bg-black/30 hover:border-bambu-green/50`}`,children:d&&(0,G.jsx)(fs,{className:`w-4 h-4`})}),P?(0,G.jsx)(`div`,{...E,...D,className:`hidden sm:flex items-center justify-center w-8 h-8 rounded-lg bg-bambu-dark cursor-grab active:cursor-grabbing hover:bg-bambu-dark-tertiary transition-colors touch-none shrink-0`,children:(0,G.jsx)(jc,{className:`w-4 h-4 text-bambu-gray`})}):t===void 0?(0,G.jsx)(`div`,{className:`hidden sm:block w-8 shrink-0`}):(0,G.jsxs)(`div`,{className:`hidden sm:flex items-center justify-center w-8 h-8 rounded-lg bg-bambu-dark text-bambu-gray text-sm font-medium shrink-0`,children:[`#`,t]}),(0,G.jsx)(`div`,{className:`w-10 h-10 sm:w-14 sm:h-14 flex-shrink-0 bg-bambu-dark rounded-lg overflow-hidden`,children:e.archive_thumbnail?(0,G.jsx)(`img`,{src:e.plate_id==null?Z.getArchiveThumbnail(e.archive_id):Z.getArchivePlateThumbnail(e.archive_id,e.plate_id),alt:``,className:`w-full h-full object-cover`}):e.library_file_thumbnail?(0,G.jsx)(`img`,{src:e.plate_id==null?Z.getLibraryFileThumbnailUrl(e.library_file_id):Z.getLibraryFilePlateThumbnail(e.library_file_id,e.plate_id),alt:``,className:`w-full h-full object-cover`}):(0,G.jsx)(`div`,{className:`w-full h-full flex items-center justify-center text-bambu-gray`,children:(0,G.jsx)(Jc,{className:`w-5 h-5 sm:w-6 sm:h-6`})})}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,G.jsxs)(`p`,{className:`text-sm sm:text-base text-white font-medium truncate`,children:[jT(e,e=>v(`common.plusNMore`,{count:e})),(C?.is_multi_plate??!1)&&e.plate_id!==void 0&&e.plate_id!==null&&` • ${w.find(t=>t.index===e.plate_id)?.name||v(`queue.plateNumber`,{index:e.plate_id})}`]}),e.archive_id?(0,G.jsx)(Ai,{to:`/archives?highlight=${e.archive_id}`,className:`text-bambu-gray hover:text-bambu-green transition-colors flex-shrink-0`,title:v(`queue.viewArchive`),children:(0,G.jsx)(rc,{className:`w-3.5 h-3.5`})}):e.library_file_id?(0,G.jsx)(Ai,{to:`/library?highlight=${e.library_file_id}`,className:`text-bambu-gray hover:text-bambu-green transition-colors flex-shrink-0`,title:v(`queue.viewInFileManager`),children:(0,G.jsx)(rc,{className:`w-3.5 h-3.5`})}):null,e.batch_name&&(0,G.jsx)(`span`,{className:`flex-shrink-0 px-1.5 py-0.5 text-[10px] sm:text-xs bg-cyan-100 dark:bg-cyan-500/20 text-cyan-700 dark:text-cyan-300 rounded border border-cyan-300 dark:border-cyan-500/30`,children:e.batch_name})]}),(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-xs sm:text-sm text-bambu-gray`,children:[(0,G.jsxs)(`span`,{className:`flex items-center gap-1 sm:gap-1.5 ${e.printer_id===null&&!e.target_model?`text-orange-700 dark:text-orange-400`:``} ${e.target_model&&!e.printer_id?`text-blue-700 dark:text-blue-400`:``}`,children:[(0,G.jsx)(Rl,{className:`w-3 h-3 sm:w-3.5 sm:h-3.5`}),(0,G.jsx)(`span`,{className:`truncate max-w-[120px] sm:max-w-none`,children:(e.variants?.length??0)>1&&!e.printer_id?`${v(`queue.filter.any`)} ${e.variants.map(e=>e.target_model).join(` / `)}${e.target_location?` @ ${e.target_location}`:``}`:e.target_model&&!e.printer_id?`${v(`queue.filter.any`)} ${e.target_model}${e.target_location?` @ ${e.target_location}`:``}${e.required_filament_types?.length?` (${e.required_filament_types.join(`, `)})`:``}`:e.printer_id===null?v(`queue.filter.unassigned`):e.printer_name||`${v(`common.printer`)} #${e.printer_id}`})]}),e.print_time_seconds&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1 sm:gap-1.5`,children:[(0,G.jsx)(Nu,{className:`w-3 h-3 sm:w-3.5 sm:h-3.5`}),lp(e.print_time_seconds)]}),I&&(0,G.jsxs)(`span`,{"data-testid":`queue-item-eta`,className:`text-bambu-green font-medium`,title:v(`queue.time.etaIfStartedNow`),children:[`ETA `,I]}),e.filament_used_grams&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1 sm:gap-1.5`,children:[(0,G.jsx)(Xu,{className:`w-3 h-3 sm:w-3.5 sm:h-3.5`}),r6(e.filament_used_grams)]}),(()=>{let t=EU(e.bed_type);return t?(0,G.jsxs)(`span`,{className:`flex items-center gap-1 sm:gap-1.5`,title:t.label,children:[(0,G.jsx)(`img`,{src:t.icon,alt:``,className:`w-3.5 h-3.5 sm:w-4 sm:h-4 object-contain`}),(0,G.jsx)(`span`,{className:`truncate max-w-[120px]`,children:t.label})]}):null})(),e.created_by_username&&(0,G.jsxs)(`span`,{className:`hidden sm:flex items-center gap-1.5`,title:v(`queue.addedBy`,{name:e.created_by_username}),children:[(0,G.jsx)(Hu,{className:`w-3.5 h-3.5`}),e.created_by_username]}),P&&!e.manual_start&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,G.jsx)(js,{className:`w-3.5 h-3.5`}),e.scheduled_time?(rp(e.scheduled_time)?.getTime()??0)-Date.now()<-6e4?v?.(`queue.time.overdue`)??`Overdue`:up(e.scheduled_time,u,v):v?.(`queue.time.whenFree`)??`When a printer is free`]})]}),(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5 sm:gap-2 mt-1.5 sm:mt-2`,children:[e.manual_start&&(0,G.jsxs)(`span`,{className:`text-[10px] sm:text-xs px-1.5 sm:px-2 py-0.5 bg-purple-50 dark:bg-purple-500/10 text-purple-700 dark:text-purple-400 rounded-full border border-purple-200 dark:border-purple-500/20 flex items-center gap-1`,children:[(0,G.jsx)(Nc,{className:`w-2.5 h-2.5 sm:w-3 sm:h-3`}),v(`queue.badges.staged`)]}),e.require_previous_success&&(0,G.jsx)(`span`,{className:`text-[10px] sm:text-xs px-1.5 sm:px-2 py-0.5 bg-orange-50 dark:bg-orange-500/10 text-orange-700 dark:text-orange-400 rounded-full border border-orange-200 dark:border-orange-500/20`,children:v(`queue.badges.requiresPrevious`)}),e.auto_off_after&&(0,G.jsxs)(`span`,{className:`text-[10px] sm:text-xs px-1.5 sm:px-2 py-0.5 bg-blue-50 dark:bg-blue-500/10 text-blue-700 dark:text-blue-400 rounded-full border border-blue-200 dark:border-blue-500/20 flex items-center gap-1`,children:[(0,G.jsx)(Ll,{className:`w-2.5 h-2.5 sm:w-3 sm:h-3`}),v(`queue.badges.autoPowerOff`)]}),e.gcode_injection&&(0,G.jsxs)(`span`,{className:`text-[10px] sm:text-xs px-1.5 sm:px-2 py-0.5 bg-emerald-50 dark:bg-emerald-500/10 text-emerald-700 dark:text-emerald-400 rounded-full border border-emerald-200 dark:border-emerald-500/20 flex items-center gap-1`,children:[(0,G.jsx)(Fs,{className:`w-2.5 h-2.5 sm:w-3 sm:h-3`}),v(`queue.badges.gcodeInjection`)]})]}),N&&y&&(()=>{let e=y.state===`RUNNING`||y.state===`PAUSE`,t=e&&y.progress||0,n=e?y.remaining_time:null,r=e?y.layer_num:null,i=e?y.total_layers:null;return(0,G.jsxs)(`div`,{className:`mt-2 sm:mt-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between text-xs sm:text-sm`,children:[(0,G.jsx)(`div`,{className:`flex-1 bg-bambu-dark-tertiary rounded-full h-1.5 sm:h-2 mr-3`,children:(0,G.jsx)(`div`,{className:`bg-bambu-green h-1.5 sm:h-2 rounded-full transition-all`,style:{width:`${t}%`}})}),(0,G.jsxs)(`span`,{className:`text-white`,children:[Math.round(t),`%`]})]}),(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 sm:gap-3 mt-1.5 sm:mt-2 text-[10px] sm:text-xs text-bambu-gray`,children:[n!=null&&n>0&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(js,{className:`w-3 h-3`}),lp(n*60)]}),(0,G.jsxs)(`span`,{className:`text-bambu-green font-medium`,title:v(`printers.estimatedCompletion`),children:[`ETA `,cp(n,u,v)]})]}),r!=null&&i!=null&&i>0&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(Jc,{className:`w-3 h-3`}),r,`/`,i]})]})]})})(),e.waiting_reason&&e.status===`pending`&&(0,G.jsxs)(`p`,{className:`text-[10px] sm:text-xs text-purple-700 dark:text-purple-400 mt-1.5 sm:mt-2 flex items-start gap-1`,children:[(0,G.jsx)(ys,{className:`w-3 h-3 mt-0.5 flex-shrink-0`}),(0,G.jsx)(`span`,{children:e.waiting_reason})]}),e.filament_short&&e.status===`pending`&&(0,G.jsxs)(`p`,{className:`text-[10px] sm:text-xs text-yellow-700 dark:text-yellow-400 mt-1.5 sm:mt-2 flex items-start gap-1`,title:v(`queue.filamentShort.rowTooltip`),children:[(0,G.jsx)(ys,{className:`w-3 h-3 mt-0.5 flex-shrink-0`}),(0,G.jsx)(`span`,{children:v(`queue.filamentShort.rowBadge`)})]}),e.archive_has_slicer_ams_mapping&&(0,G.jsxs)(`p`,{className:`text-[10px] sm:text-xs text-green-700 dark:text-green-400 mt-1.5 sm:mt-2 flex items-start gap-1`,title:v(`queue.slicerAmsMapping.rowTooltip`),children:[(0,G.jsx)(fs,{className:`w-3 h-3 mt-0.5 flex-shrink-0`}),(0,G.jsx)(`span`,{children:v(`queue.slicerAmsMapping.rowBadge`)})]}),e.error_message&&(0,G.jsxs)(`p`,{className:`text-[10px] sm:text-xs text-red-700 dark:text-red-400 mt-1.5 sm:mt-2 flex items-center gap-1`,children:[(0,G.jsx)(ys,{className:`w-3 h-3`}),e.error_message]})]}),(0,G.jsxs)(`div`,{className:`flex flex-col sm:flex-row items-end sm:items-center gap-2 sm:gap-1 shrink-0`,onClick:e=>e.stopPropagation(),children:[(0,G.jsx)(VUe,{status:e.status,waitingReason:e.waiting_reason,printerState:h,t:v}),(0,G.jsxs)(`div`,{className:`flex items-center gap-0.5 sm:gap-1`,children:[N&&(0,G.jsx)(Q,{variant:`ghost`,size:`sm`,onClick:a,disabled:!m(`queue`,`update`,e.created_by_id),title:m(`queue`,`update`,e.created_by_id)?v(`queue.actions.stopPrint`):v(`queue.permissions.noStopPrint`),className:`text-red-600 dark:text-red-400 hover:text-red-700 dark:hover:text-red-300 hover:bg-red-50 dark:hover:bg-red-500/10 p-1.5 sm:p-2`,children:(0,G.jsx)(Es,{className:`w-4 h-4`})}),P&&(0,G.jsxs)(G.Fragment,{children:[e.manual_start&&(0,G.jsx)(Q,{variant:`ghost`,size:`sm`,onClick:s,disabled:!m(`queue`,`update`,e.created_by_id),title:m(`queue`,`update`,e.created_by_id)?v(`queue.actions.startPrint`):v(`queue.permissions.noStartPrint`),className:`text-bambu-green hover:text-bambu-green-light hover:bg-bambu-green/10 p-1.5 sm:p-2`,children:(0,G.jsx)(Nl,{className:`w-4 h-4`})}),(0,G.jsx)(Q,{variant:`ghost`,size:`sm`,onClick:n,disabled:!m(`queue`,`update`,e.created_by_id),title:m(`queue`,`update`,e.created_by_id)?v(`common.edit`):v(`queue.permissions.noEdit`),className:`p-1.5 sm:p-2`,children:(0,G.jsx)(Al,{className:`w-4 h-4`})}),(0,G.jsx)(Q,{variant:`ghost`,size:`sm`,onClick:r,disabled:!m(`queue`,`delete`,e.created_by_id),title:m(`queue`,`delete`,e.created_by_id)?v(`common.cancel`):v(`queue.permissions.noCancel`),className:`text-red-600 dark:text-red-400 hover:text-red-700 dark:hover:text-red-300 hover:bg-red-50 dark:hover:bg-red-500/10 p-1.5 sm:p-2`,children:(0,G.jsx)(nd,{className:`w-4 h-4`})})]}),F&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Q,{variant:`ghost`,size:`sm`,onClick:o,disabled:!p(`queue:create`),title:p(`queue:create`)?v(`queue.actions.requeue`):v(`queue.permissions.noRequeue`),className:`text-bambu-green hover:text-bambu-green/80 hover:bg-bambu-green/10 p-1.5 sm:p-2`,children:(0,G.jsx)(Hl,{className:`w-4 h-4`})}),(0,G.jsx)(Q,{variant:`ghost`,size:`sm`,onClick:i,disabled:!m(`queue`,`delete`,e.created_by_id),title:m(`queue`,`delete`,e.created_by_id)?v(`common.remove`):v(`queue.permissions.noRemove`),className:`p-1.5 sm:p-2`,children:(0,G.jsx)(Pu,{className:`w-4 h-4`})})]})]})]})]})]})}function s6(e){let{row:t,setEditItem:n,setConfirmAction:r,startMutation:i,selectedItems:a,handleToggleSelect:o,timeFormat:s,hasPermission:c,canModify:l,t:u,etaEligibleIds:d,etaNow:f,onMoveUp:p,onMoveDown:m}=e;return t.kind===`item`?(0,G.jsx)(o6,{item:t.item,onEdit:()=>n(t.item),onCancel:()=>r({type:`cancel`,item:t.item}),onRemove:()=>{},onStop:()=>{},onRequeue:()=>{},onStart:()=>i.mutate({id:t.item.id}),onMoveUp:p,onMoveDown:m,timeFormat:s,isSelected:a.includes(t.item.id),onToggleSelect:()=>o(t.item.id),hasPermission:c,canModify:l,showEta:d.has(t.item.id),etaNow:f,t:u}):(0,G.jsx)(UUe,{...e})}function UUe({row:e,collapsed:t,onToggleBatch:n,onUngroup:r,setEditItem:i,setConfirmAction:a,startMutation:o,selectedItems:s,handleToggleSelect:c,timeFormat:l,hasPermission:u,canModify:d,t:f,etaEligibleIds:p,etaNow:m,aggregateForRows:h,onMoveUp:g,onMoveDown:_,onMoveBlock:v}){let y=e,b=u(`queue:reorder`),{attributes:x,listeners:S,setNodeRef:C,transform:w,transition:T,isDragging:E}=V3({id:`batch-${y.batchId}`,disabled:!b}),D={transform:y4.Transform.toString(w),transition:T},O=h([y]),k=y.items.map(e=>e.id),A=k.length>0&&k.every(e=>s.includes(e)),j=new Set(y.items.map(e=>e.status)),M=j.has(`failed`)?`failed`:j.has(`printing`)?`printing`:`pending`,N=y.items.filter(e=>e.status===`pending`).length;return(0,G.jsxs)(`div`,{ref:C,style:D,className:`bg-bambu-dark-secondary rounded-xl border border-l-[3px] border-l-cyan-400 border-bambu-dark-tertiary overflow-hidden ${E?`opacity-50 scale-[1.01] shadow-xl z-50`:``}`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 sm:gap-3 p-3 sm:p-4`,children:[b&&(g||_)&&(0,G.jsxs)(`div`,{className:`flex sm:hidden flex-col shrink-0 -my-1`,children:[(0,G.jsx)(`button`,{type:`button`,onClick:g,disabled:!g,title:f(`queue.moveUp`),"aria-label":f(`queue.moveUp`),className:`flex items-center justify-center w-8 h-7 rounded-lg text-bambu-gray hover:text-white hover:bg-bambu-dark disabled:opacity-25 disabled:hover:bg-transparent transition-colors`,children:(0,G.jsx)(gs,{className:`w-5 h-5`})}),(0,G.jsx)(`button`,{type:`button`,onClick:_,disabled:!_,title:f(`queue.moveDown`),"aria-label":f(`queue.moveDown`),className:`flex items-center justify-center w-8 h-7 rounded-lg text-bambu-gray hover:text-white hover:bg-bambu-dark disabled:opacity-25 disabled:hover:bg-transparent transition-colors`,children:(0,G.jsx)(ps,{className:`w-5 h-5`})})]}),(0,G.jsx)(`button`,{onClick:e=>{e.stopPropagation(),k.forEach(e=>{(A&&s.includes(e)||!A&&!s.includes(e))&&c(e)})},className:`hidden sm:flex items-center justify-center w-6 h-6 rounded border transition-colors shrink-0 ${A?`bg-bambu-green border-bambu-green text-white`:`border-white/30 bg-black/30 hover:border-bambu-green/50`}`,title:f(A?`queue.bulkEdit.deselectAll`:`queue.bulkEdit.selectAll`),children:A&&(0,G.jsx)(fs,{className:`w-4 h-4`})}),b&&(0,G.jsx)(`div`,{...x,...S,className:`hidden sm:flex items-center justify-center w-8 h-8 rounded-lg bg-bambu-dark cursor-grab active:cursor-grabbing hover:bg-bambu-dark-tertiary transition-colors touch-none shrink-0`,title:f(`queue.batch.dragGroup`,{defaultValue:`Drag group`}),children:(0,G.jsx)(jc,{className:`w-4 h-4 text-bambu-gray`})}),(0,G.jsx)(`button`,{onClick:n,className:`flex items-center justify-center w-8 h-8 rounded-lg bg-bambu-dark hover:bg-bambu-dark-tertiary transition-colors shrink-0`,title:f(t?`queue.batch.expand`:`queue.batch.collapse`),children:t?(0,G.jsx)(ms,{className:`w-4 h-4 text-bambu-gray`}):(0,G.jsx)(ps,{className:`w-4 h-4 text-bambu-gray`})}),(0,G.jsx)(`div`,{className:`w-10 h-10 sm:w-12 sm:h-12 flex-shrink-0 bg-bambu-dark rounded-lg flex items-center justify-center`,children:t?(0,G.jsx)(Cl,{className:`w-5 h-5 text-cyan-700 dark:text-cyan-300`}):(0,G.jsx)(Sl,{className:`w-5 h-5 text-cyan-700 dark:text-cyan-300`})}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,G.jsx)(`p`,{className:`text-sm sm:text-base text-white font-medium truncate`,children:y.batchName}),(0,G.jsx)(`span`,{className:`flex-shrink-0 px-1.5 py-0.5 text-[10px] sm:text-xs bg-cyan-100 dark:bg-cyan-500/15 text-cyan-700 dark:text-cyan-300 rounded border border-cyan-300 dark:border-cyan-500/30`,children:f(`queue.batch.label`,{count:O.count})})]}),(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-xs sm:text-sm text-bambu-gray`,children:[O.time>0&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1 sm:gap-1.5`,children:[(0,G.jsx)(Nu,{className:`w-3 h-3 sm:w-3.5 sm:h-3.5`}),lp(O.time)]}),O.weight>0&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1 sm:gap-1.5`,children:[(0,G.jsx)(Xu,{className:`w-3 h-3 sm:w-3.5 sm:h-3.5`}),r6(O.weight)]}),N>0&&M===`pending`&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1 sm:gap-1.5 text-yellow-700 dark:text-yellow-400`,children:[(0,G.jsx)(js,{className:`w-3 h-3 sm:w-3.5 sm:h-3.5`}),f(`queue.batch.pendingCount`,{count:N})]})]})]}),(0,G.jsx)(`div`,{className:`flex items-center gap-1 shrink-0`,children:r&&(0,G.jsx)(Q,{variant:`ghost`,size:`sm`,onClick:r,title:f(`queue.batch.ungroup`),className:`text-cyan-700 dark:text-cyan-300 hover:text-cyan-900 dark:hover:text-cyan-200 hover:bg-cyan-50 dark:hover:bg-cyan-500/10 p-1.5 sm:p-2`,children:(0,G.jsx)(zu,{className:`w-4 h-4`})})})]}),!t&&(0,G.jsx)(`div`,{className:`border-t border-bambu-dark-tertiary bg-black/20 p-2 sm:p-3 space-y-2`,children:y.items.map((e,t)=>(0,G.jsx)(o6,{item:e,onEdit:()=>i(e),onCancel:()=>a({type:`cancel`,item:e}),onRemove:()=>{},onStop:()=>{},onRequeue:()=>{},onStart:()=>o.mutate({id:e.id}),onMoveUp:v&&t>0?()=>v([e.id],y.items[t-1].id,!1):void 0,onMoveDown:v&&tv([e.id],y.items[t+1].id,!0):void 0,timeFormat:l,isSelected:s.includes(e.id),onToggleSelect:()=>c(e.id),hasPermission:u,canModify:d,showEta:p.has(e.id),etaNow:m,t:f},e.id))})]})}function WUe({items:e,visibleCount:t,onShowMore:n,sortBy:r,sortAsc:i,onSortByChange:a,onSortAscToggle:o,onRemove:s,onRequeue:c,timeFormat:l,batchCollapsed:u,toggleBatchCollapsed:d,hasPermission:f,canModify:p,t:m}){if(e.length===0)return(0,G.jsxs)(zd,{className:`p-12 text-center border-dashed`,children:[(0,G.jsx)(Qc,{className:`w-16 h-16 text-bambu-gray mx-auto mb-4 opacity-50`}),(0,G.jsx)(`h3`,{className:`text-xl font-medium text-white mb-2`,children:m(`queue.history.emptyTitle`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray max-w-md mx-auto`,children:m(`queue.history.emptyDescription`)})]});let h=[],g=new Set;for(let n of e.slice(0,t))if(n.batch_id!=null){if(g.has(n.batch_id))continue;g.add(n.batch_id);let t=e.filter(e=>e.batch_id===n.batch_id);h.push({kind:`batch`,batchId:n.batch_id,batchName:n.batch_name||m(`queue.batch.defaultName`),items:t})}else h.push({kind:`item`,item:n});return(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2 mb-3 sm:mb-4`,children:[(0,G.jsxs)(`h2`,{className:`text-base sm:text-lg font-semibold text-white flex items-center gap-2`,children:[m(`queue.sections.history`),(0,G.jsxs)(`span`,{className:`text-xs sm:text-sm font-normal text-bambu-gray`,children:[`(`,m(`queue.itemCount`,{count:e.length}),`)`]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`select`,{className:`px-2 sm:px-3 py-1.5 text-xs sm:text-sm bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,value:r,onChange:e=>a(e.target.value),children:[(0,G.jsx)(`option`,{value:`date`,children:m(`queue.sort.byDate`)}),(0,G.jsx)(`option`,{value:`name`,children:m(`queue.sort.byName`)}),(0,G.jsx)(`option`,{value:`printer`,children:m(`queue.sort.byPrinter`)})]}),(0,G.jsx)(Q,{variant:`ghost`,size:`sm`,onClick:o,title:m(i?`queue.sort.ascendingOldest`:`queue.sort.descendingNewest`),className:`px-2`,children:i?(0,G.jsx)(Ho,{className:`w-4 h-4`}):(0,G.jsx)(Io,{className:`w-4 h-4`})})]})]}),(0,G.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-2`,children:h.map(e=>{if(e.kind===`item`)return(0,G.jsx)(J3,{item:e.item,onRemove:()=>s(e.item),onRequeue:()=>c(e.item),timeFormat:l,hasPermission:f,canModify:p,t:m},e.item.id);let t=u[e.batchId]??!0,n=e.items.filter(e=>e.status===`completed`).length,r=e.items.filter(e=>e.status===`failed`).length,i=e.items.filter(e=>e.status===`skipped`).length,a=e.items.filter(e=>e.status===`cancelled`).length,o=e.items.map(e=>e.completed_at||e.created_at).filter(e=>!!e).sort().at(-1);return(0,G.jsxs)(`div`,{className:`md:col-span-2 xl:col-span-3 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary border-l-[3px] border-l-cyan-400`,children:[(0,G.jsxs)(`button`,{onClick:()=>d(e.batchId),className:`w-full flex items-center gap-2 sm:gap-3 px-3 py-2 hover:bg-bambu-dark/30 transition-colors text-left`,title:m(t?`queue.batch.expand`:`queue.batch.collapse`),children:[t?(0,G.jsx)(ms,{className:`w-4 h-4 text-bambu-gray shrink-0`}):(0,G.jsx)(ps,{className:`w-4 h-4 text-bambu-gray shrink-0`}),t?(0,G.jsx)(Cl,{className:`w-5 h-5 text-cyan-700 dark:text-cyan-300 shrink-0`}):(0,G.jsx)(Sl,{className:`w-5 h-5 text-cyan-700 dark:text-cyan-300 shrink-0`}),(0,G.jsx)(`span`,{className:`text-sm text-white font-medium truncate min-w-0 flex-1`,children:e.batchName}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-bambu-gray shrink-0`,children:[n>0&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-emerald-700 dark:text-emerald-400`,children:[(0,G.jsx)(xs,{className:`w-3 h-3`}),n]}),r>0&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-red-700 dark:text-red-400`,children:[(0,G.jsx)(Ds,{className:`w-3 h-3`}),r]}),i>0&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-orange-700 dark:text-orange-400`,children:[(0,G.jsx)(du,{className:`w-3 h-3`}),i]}),a>0&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-gray-400`,children:[(0,G.jsx)(Uo,{className:`w-3 h-3`}),a]}),(0,G.jsx)(`span`,{title:o??void 0,children:o?up(o,l,m):null})]})]}),!t&&(0,G.jsx)(`div`,{className:`border-t border-bambu-dark-tertiary bg-black/20 p-2 grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-2`,children:e.items.map(e=>(0,G.jsx)(J3,{item:e,onRemove:()=>s(e),onRequeue:()=>c(e),timeFormat:l,hasPermission:f,canModify:p,t:m},e.id))})]},`batch-${e.batchId}`)})}),e.length>t&&(0,G.jsxs)(`div`,{className:`mt-4 flex flex-col items-center gap-2`,children:[(0,G.jsx)(Q,{variant:`secondary`,size:`sm`,onClick:n,children:m(`queue.history.showMore`)}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:m(`queue.history.showingCount`,{shown:Math.min(t,e.length),total:e.length})})]})]})}var c6=50;function GUe(){let{t:e}=U(),t=co(),{showToast:n}=qd(),{hasPermission:r,hasAnyPermission:i,canModify:a}=Nd(),[o,s]=(0,y.useState)(null),[c,l]=(0,y.useState)(``),[u,d]=(0,y.useState)(``),[f,p]=(0,y.useState)(!1),[m,h]=(0,y.useState)(null),[g,_]=(0,y.useState)(null),[v,b]=(0,y.useState)(null),[x,S]=(0,y.useState)([]),[C,w]=(0,y.useState)(!1),[T,E]=(0,y.useState)(null),[D,O]=(0,y.useState)(()=>localStorage.getItem(`queue.historySortBy`)||`date`),[k,A]=(0,y.useState)(()=>{let e=localStorage.getItem(`queue.historySortAsc`);return e===null?!1:e===`true`}),[j,M]=(0,y.useState)(c6),[N,P]=(0,y.useState)(()=>localStorage.getItem(`queue.pendingSortBy`)||`position`),[F,I]=(0,y.useState)(()=>{let e=localStorage.getItem(`queue.pendingSortAsc`);return e===null?!0:e===`true`}),[L,R]=(0,y.useState)(()=>{let e=new URLSearchParams(window.location.search).get(`tab`);if(e===`pipelines`||e===`history`||e===`timeline`||e===`queue`||e===`batches`)return e;let t=localStorage.getItem(`queue.activeTab`);return t===`history`||t===`timeline`||t===`pipelines`||t===`batches`?t:`queue`}),[z,B]=(0,y.useState)(()=>localStorage.getItem(`queue.activeLayout`)===`printer`?`printer`:`position`),[V,ee]=(0,y.useState)(()=>{try{let e=localStorage.getItem(`queue.batchCollapsed`);return e?JSON.parse(e):{}}catch{return{}}}),[te,ne]=(0,y.useState)(null),[re,ie]=(0,y.useState)(!1),[ae,oe]=(0,y.useState)(null);(0,y.useEffect)(()=>{localStorage.setItem(`queue.historySortBy`,D)},[D]),(0,y.useEffect)(()=>{localStorage.setItem(`queue.historySortAsc`,String(k))},[k]),(0,y.useEffect)(()=>{M(c6)},[D,k,u]),(0,y.useEffect)(()=>{localStorage.setItem(`queue.pendingSortBy`,N)},[N]),(0,y.useEffect)(()=>{localStorage.setItem(`queue.pendingSortAsc`,String(F))},[F]),(0,y.useEffect)(()=>{localStorage.setItem(`queue.activeTab`,L)},[L]),(0,y.useEffect)(()=>{localStorage.setItem(`queue.activeLayout`,z)},[z]),(0,y.useEffect)(()=>{localStorage.setItem(`queue.batchCollapsed`,JSON.stringify(V))},[V]);let se=T4(w4(a3,{activationConstraint:{distance:8}}),w4(t3,{coordinateGetter:U3})),{data:H}=K({queryKey:[`settings`],queryFn:Z.getSettings}),ce=H?.time_format||`system`,{data:le}=K({queryKey:[`batches`,`active`],queryFn:()=>Z.getBatches(`active`)}),ue=le?.length??0,{data:de,isLoading:fe}=K({queryKey:[`queue`,o,c],queryFn:()=>Z.getQueue(o||void 0,c||void 0),refetchInterval:5e3}),{data:pe}=K({queryKey:[`printers`],queryFn:()=>Z.getPrinters()}),me=q({mutationFn:e=>Z.updateSettings({queue_shortest_first:e}),onSuccess:()=>{t.invalidateQueries({queryKey:[`settings`]})}}),he=q({mutationFn:e=>Z.cancelQueueItem(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`queue`]}),n(e(`queue.toast.cancelled`))},onError:()=>n(e(`queue.toast.cancelFailed`),`error`)}),ge=q({mutationFn:e=>Z.removeFromQueue(e),onSuccess:r=>{t.invalidateQueries({queryKey:[`queue`]}),t.invalidateQueries({queryKey:[`batches`]}),n(r.deleted===!1?e(`queue.toast.keptForOrder`):e(`queue.toast.removed`))},onError:()=>n(e(`queue.toast.removeFailed`),`error`)}),_e=q({mutationFn:e=>Z.stopQueueItem(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`queue`]}),n(e(`queue.toast.stopped`))},onError:()=>n(e(`queue.toast.stopFailed`),`error`)}),[ve,ye]=(0,y.useState)(null),be=q({mutationFn:({id:e,skipFilamentCheck:t})=>Z.startQueueItem(e,{skipFilamentCheck:t}),onSuccess:()=>{t.invalidateQueries({queryKey:[`queue`]}),n(e(`queue.toast.released`)),ye(null)},onError:(t,r)=>{if(t instanceof sd&&t.status===409&&t.code===`insufficient_filament`){let e=t.detail?.deficit??[];ye({itemId:r.id,deficit:e});return}n(e(`queue.toast.startFailed`),`error`)}}),xe=q({mutationFn:e=>Z.reorderQueue(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`queue`]})},onError:()=>n(e(`queue.toast.reorderFailed`),`error`)}),Se=q({mutationFn:async()=>{let e=de?.filter(e=>[`completed`,`failed`,`skipped`,`cancelled`].includes(e.status))||[],t=0,n=0;for(let r of e)(await Z.removeFromQueue(r.id)).deleted===!1?n+=1:t+=1;return{cleared:t,kept:n}},onSuccess:({cleared:r,kept:i})=>{t.invalidateQueries({queryKey:[`queue`]}),t.invalidateQueries({queryKey:[`batches`]}),n(i>0?`${e(`queue.toast.historyCleared`,{count:r})} ${e(`queue.toast.historyKeptForOrders`,{kept:i})}`:e(`queue.toast.historyCleared`,{count:r}))},onError:()=>n(e(`queue.toast.clearHistoryFailed`),`error`)}),Ce=q({mutationFn:e=>Z.bulkUpdateQueue(e),onSuccess:e=>{t.invalidateQueries({queryKey:[`queue`]}),S([]),w(!1),n(e.message)},onError:()=>n(e(`queue.toast.updateFailed`),`error`)}),we=q({mutationFn:async e=>{for(let t of e)await Z.cancelQueueItem(t);return e.length},onSuccess:r=>{t.invalidateQueries({queryKey:[`queue`]}),S([]),n(e(`queue.toast.bulkCancelled`,{count:r}))},onError:()=>n(e(`queue.toast.bulkCancelFailed`),`error`)}),Te=q({mutationFn:e=>Z.resumeQueueAfterFailure(e),onSuccess:r=>{t.invalidateQueries({queryKey:[`queue`]}),E(null),n(e(`queue.toast.resumedAfterFailure`,{restored:r.restored,acknowledged:r.acknowledged}))},onError:()=>n(e(`queue.toast.resumeAfterFailureFailed`),`error`)}),Ee=q({mutationFn:e=>Z.createBatch(e),onSuccess:r=>{t.invalidateQueries({queryKey:[`queue`]}),S([]),ie(!1),ee(e=>({...e,[r.id]:!1})),n(e(`queue.toast.batchCreated`,{name:r.name}))},onError:()=>n(e(`queue.toast.batchCreateFailed`),`error`)}),De=q({mutationFn:e=>Z.ungroupBatch(e),onSuccess:r=>{t.invalidateQueries({queryKey:[`queue`]}),oe(null),n(e(`queue.toast.batchUngrouped`,{count:r.ungrouped_count}))},onError:()=>n(e(`queue.toast.batchUngroupFailed`),`error`)}),Oe=e=>{S(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},ke=(0,y.useMemo)(()=>{let e=new Set;return pe?.forEach(t=>{t.location&&e.add(t.location)}),de?.forEach(t=>{t.target_location&&e.add(t.target_location)}),Array.from(e).sort()},[pe,de]),Ae=(0,y.useCallback)(e=>u?e.target_location?e.target_location===u:e.printer_id?pe?.find(t=>t.id===e.printer_id)?.location===u:!1:!0,[u,pe]),je=(0,y.useMemo)(()=>{let e=de?.filter(e=>e.status===`pending`)||[];u&&(e=e.filter(Ae));let t=e=>{if(!e.scheduled_time)return 0;let t=rp(e.scheduled_time)?.getTime()??0;return t>Date.now()+4320*60*60*1e3?0:t};return H?.queue_shortest_first?[...e].sort((e,t)=>NUe(e,t,!0)):[...e].sort((e,n)=>{let r;if(N===`name`){let t=e.archive_name||e.library_file_name||``,i=n.archive_name||n.library_file_name||``;r=t.localeCompare(i)}else r=N===`printer`?(e.printer_name||``).localeCompare(n.printer_name||``):N===`time`?t(e)-t(n):e.position-n.position;return F?r:-r})},[de,N,F,Ae,u,H?.queue_shortest_first]),Me=()=>{let e=je.map(e=>e.id);x.length===e.length?S([]):S(e)},Ne=(0,y.useMemo)(()=>{let e=de?.filter(e=>e.status===`printing`)||[];return u&&(e=e.filter(Ae)),e},[de,u,Ae]),Pe=(0,y.useMemo)(()=>{let e=new Set;if(!de)return e;let t=new Set;de.forEach(e=>{e.status===`printing`&&e.printer_id&&t.add(e.printer_id)});let n=e=>e.scheduled_time?(rp(e.scheduled_time)?.getTime()??0)>Date.now():!1,r=(e,t)=>X3(e,t,H?.queue_shortest_first??!1),i=new Map;return de.filter(e=>e.status===`pending`&&e.printer_id!=null&&!e.manual_start&&!n(e)).sort(r).forEach(e=>{let t=i.get(e.printer_id)??[];t.push(e),i.set(e.printer_id,t)}),de.forEach(r=>{if(r.status===`pending`&&!r.waiting_reason&&!n(r)&&!(r.print_time_seconds==null||r.print_time_seconds<=0)&&!r.require_previous_success){if(r.printer_id==null){e.add(r.id);return}if(!t.has(r.printer_id)){if(r.manual_start){e.add(r.id);return}i.get(r.printer_id)?.[0]?.id===r.id&&e.add(r.id)}}}),e},[de,H?.queue_shortest_first]),[Fe,Ie]=(0,y.useState)(()=>Date.now()),Le=Pe.size>0;(0,y.useEffect)(()=>{if(!Le)return;Ie(Date.now());let e=setInterval(()=>Ie(Date.now()),3e4);return()=>clearInterval(e)},[Le]);let Re=(0,y.useMemo)(()=>{let e=new Set;return Ne.forEach(t=>{t.printer_id&&e.add(t.printer_id)}),Array.from(e)},[Ne]),ze=Co({queries:Re.map(e=>({queryKey:[`printerStatus`,e],queryFn:()=>Z.getPrinterStatus(e),refetchInterval:5e3}))}),Be=(0,y.useMemo)(()=>{let e={};return Re.forEach((t,n)=>{let r=ze[n];r?.data?.state&&(e[t]=r.data.state)}),e},[Re,ze]),Ve=(0,y.useMemo)(()=>{let e={};return Re.forEach((t,n)=>{let r=ze[n];r?.data&&(e[t]={progress:r.data.progress??void 0,remaining_time:r.data.remaining_time??void 0,state:r.data.state??void 0})}),e},[Re,ze]),He=(0,y.useMemo)(()=>{let e=de?.filter(e=>[`completed`,`failed`,`skipped`,`cancelled`].includes(e.status))||[];return u&&(e=e.filter(Ae)),[...e].sort((e,t)=>{let n;if(D===`name`){let r=e.archive_name||e.library_file_name||``,i=t.archive_name||t.library_file_name||``;n=r.localeCompare(i)}else n=D===`printer`?(e.printer_name||``).localeCompare(t.printer_name||``):(rp(t.completed_at||t.created_at)?.getTime()??0)-(rp(e.completed_at||e.created_at)?.getTime()??0);return k?-n:n})},[de,D,k,Ae,u]),Ue=(0,y.useMemo)(()=>je.reduce((e,t)=>e+(t.print_time_seconds||0),0),[je]),We=(0,y.useMemo)(()=>je.reduce((e,t)=>e+(t.filament_used_grams||0),0),[je]),Ge=e=>{let t=e.active.id;ne(typeof t==`number`||typeof t==`string`?t:null)},Ke=e=>{let{active:t,over:n}=e;if(ne(null),!n||t.id===n.id)return;let r,i=t.id;if(typeof i==`string`&&i.startsWith(`batch-`)){let e=Number(i.slice(6));r=je.filter(t=>t.batch_id===e).map(e=>e.id)}else{let e=i;r=x.includes(e)&&x.length>1?x.slice().sort((e,t)=>je.findIndex(t=>t.id===e)-je.findIndex(e=>e.id===t)):[e]}if(r.length===0)return;let a,o=n.id;if(typeof o==`string`&&o.startsWith(`batch-`)){let e=Number(o.slice(6));a=je.findIndex(t=>t.batch_id===e)}else a=je.findIndex(e=>e.id===o);if(a===-1)return;let s=je[a],c=je.filter(e=>!r.includes(e.id)),l=c.findIndex(e=>e.id===s.id);l===-1&&(l=a),je.findIndex(e=>e.id===r[0])je.find(t=>t.id===e)).filter(e=>!!e),...c.slice(l)].map((e,t)=>({id:e.id,position:t+1}));xe.mutate(u)},qe=(0,y.useMemo)(()=>{let t=[],n=new Set;for(let r of je)if(r.batch_id!=null){if(n.has(r.batch_id))continue;n.add(r.batch_id);let i=je.filter(e=>e.batch_id===r.batch_id);t.push({kind:`batch`,batchId:r.batch_id,batchName:r.batch_name||e(`queue.batch.defaultName`),items:i})}else t.push({kind:`item`,item:r});return t},[je,e]),Je=r(`queue:reorder`)&&N===`position`&&!H?.queue_shortest_first,Ye=e=>e.kind===`item`?[e.item.id]:e.items.map(e=>e.id),Xe=(e,t,n)=>{let r=je.filter(t=>!e.includes(t.id)),i=r.findIndex(e=>e.id===t);if(i===-1)return;n&&(i+=1);let a=e.map(e=>je.find(t=>t.id===e)).filter(e=>!!e),o=[...r.slice(0,i),...a,...r.slice(i)];xe.mutate(o.map((e,t)=>({id:e.id,position:t+1})))},Ze=(e,t)=>{if(!Je)return{};let n=Ye(e[t]);return{onMoveUp:t>0?()=>Xe(n,Ye(e[t-1])[0],!1):void 0,onMoveDown:t{let r=Ye(e[t+1]);Xe(n,r[r.length-1],!0)}:void 0}},Qe=(0,y.useMemo)(()=>{let e=[];for(let t of qe)if(t.kind===`item`)e.push(t.item.id);else if(e.push(`batch-${t.batchId}`),!(V[t.batchId]??!0))for(let n of t.items)e.push(n.id);return e},[qe,V]),$e=(0,y.useMemo)(()=>x.length<2?!1:x.every(e=>{let t=je.find(t=>t.id===e);return t&&t.batch_id==null}),[x,je]),et=e=>{ee(t=>({...t,[e]:!(t[e]??!0)}))},tt=(0,y.useMemo)(()=>{let t=new Map,n=t=>{if(t.printer_id)return{key:`printer:${t.printer_id}`,label:t.printer_name||`Printer #${t.printer_id}`,printerId:t.printer_id,targetModel:null,isUnassigned:!1};if((t.variants?.length??0)>1){let n=t.variants.map(e=>e.target_model).join(` / `);return{key:`models:${n}`,label:`${e(`queue.filter.any`)} ${n}`,printerId:null,targetModel:null,isUnassigned:!1}}return t.target_model?{key:`model:${t.target_model}`,label:`${e(`queue.filter.any`)} ${t.target_model}`,printerId:null,targetModel:t.target_model,isUnassigned:!1}:{key:`unassigned`,label:e(`queue.filter.unassigned`),printerId:null,targetModel:null,isUnassigned:!0}};for(let e of qe){let r=e.kind===`item`?e.item:e.items[0];if(!r)continue;let i=n(r);t.has(i.key)||t.set(i.key,{...i,rows:[]}),t.get(i.key).rows.push(e)}return Array.from(t.values()).sort((e,t)=>e.isUnassigned&&!t.isUnassigned?1:!e.isUnassigned&&t.isUnassigned?-1:e.label.localeCompare(t.label))},[qe,e]),nt=(0,y.useMemo)(()=>{let e=new Map;return de?.forEach(t=>{if(t.status===`skipped`&&t.error_message===`Previous print failed or was aborted`&&t.printer_id){let n=e.get(t.printer_id);n?n.count+=1:e.set(t.printer_id,{name:t.printer_name||`Printer #${t.printer_id}`,count:1})}}),Array.from(e.entries()).map(([e,{name:t,count:n}])=>({printerId:e,printerName:t,skippedCount:n})).sort((e,t)=>e.printerName.localeCompare(t.printerName))},[de]),rt=e=>{let t=0,n=0,r=0;for(let i of e){let e=i.kind===`item`?[i.item]:i.items;for(let i of e)t+=1,n+=i.print_time_seconds||0,r+=i.filament_used_grams||0}return{count:t,time:n,weight:r}};return(0,G.jsxs)(`div`,{className:`p-4 md:p-8`,children:[(0,G.jsx)(`div`,{className:`flex items-center justify-between 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)(Qc,{className:`w-7 h-7 text-bambu-green`}),e(`queue.title`)]}),(0,G.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:e(`queue.subtitle`)})]})}),(0,G.jsx)(`div`,{className:`flex gap-1 border-b border-bambu-dark-tertiary mb-6 overflow-x-auto`,children:[{id:`queue`,label:e(`queue.tabs.queue`),icon:js,count:je.length+Ne.length},{id:`batches`,label:e(`queue.tabs.batches`),icon:Cl,count:ue},{id:`history`,label:e(`queue.tabs.history`),icon:Qc,count:He.length},{id:`timeline`,label:e(`queue.tabs.timeline`),icon:ds,count:null},{id:`pipelines`,label:e(`queue.tabs.pipelines`),icon:ed,count:null}].map(({id:e,label:t,icon:n,count:r})=>(0,G.jsxs)(`button`,{onClick:()=>R(e),className:`px-4 py-2.5 text-sm flex items-center gap-2 border-b-2 -mb-px transition-colors whitespace-nowrap ${L===e?`text-white border-bambu-green font-medium`:`text-bambu-gray border-transparent hover:text-white`}`,children:[(0,G.jsx)(n,{className:`w-4 h-4`}),t,r!==null&&r>0&&(0,G.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded-full ${L===e?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark-tertiary text-bambu-gray`}`,children:r})]},e))}),L!==`pipelines`&&L!==`batches`&&(0,G.jsx)(jUe,{activeCount:Ne.length,pendingCount:je.length,totalTime:Ue,totalWeight:We,historyCount:He.length,t:e}),L===`queue`&&nt.length>0&&r(`queue:update_all`)&&(0,G.jsx)(`div`,{className:`mb-4 space-y-2`,children:nt.map(({printerId:t,printerName:n,skippedCount:r})=>(0,G.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-3 bg-orange-50 dark:bg-orange-500/10 border border-orange-300 dark:border-orange-500/30 rounded-lg`,children:[(0,G.jsx)(ys,{className:`w-5 h-5 text-orange-600 dark:text-orange-400 flex-shrink-0`}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`div`,{className:`text-sm text-orange-800 dark:text-orange-200`,children:e(`queue.resumeAfterFailure.banner`,{printer:n,count:r})}),(0,G.jsx)(`div`,{className:`text-xs text-orange-800/80 dark:text-orange-200/70 mt-0.5`,children:e(`queue.resumeAfterFailure.bannerHint`)})]}),(0,G.jsxs)(`button`,{onClick:()=>E({printerId:t,printerName:n,skippedCount:r}),className:`flex items-center gap-1.5 px-3 py-1.5 bg-orange-100 dark:bg-orange-500/20 hover:bg-orange-200 dark:hover:bg-orange-500/30 text-orange-900 dark:text-orange-100 text-sm rounded-md border border-orange-300 dark:border-orange-500/40 transition-colors flex-shrink-0`,children:[(0,G.jsx)(Ts,{className:`w-4 h-4`}),e(`queue.resumeAfterFailure.button`)]})]},t))}),L!==`pipelines`&&L!==`batches`&&(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 sm:gap-4 mb-6`,children:[(0,G.jsxs)(`select`,{className:`px-2 sm:px-3 py-2 text-sm sm:text-base bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none min-w-0 flex-1 sm:flex-none`,value:o===-1?`unassigned`:o||``,onChange:e=>{let t=e.target.value;s(t===`unassigned`?-1:t===``?null:Number(t))},children:[(0,G.jsx)(`option`,{value:``,children:e(`queue.filter.allPrinters`)}),(0,G.jsx)(`option`,{value:`unassigned`,children:e(`queue.filter.unassigned`)}),pe?.map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),(0,G.jsxs)(`select`,{className:`px-2 sm:px-3 py-2 text-sm sm:text-base bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none min-w-0 flex-1 sm:flex-none`,value:c,onChange:e=>l(e.target.value),children:[(0,G.jsx)(`option`,{value:``,children:e(`queue.filter.allStatus`)}),(0,G.jsx)(`option`,{value:`pending`,children:e(`queue.status.pending`)}),(0,G.jsx)(`option`,{value:`printing`,children:e(`queue.status.printing`)}),(0,G.jsx)(`option`,{value:`completed`,children:e(`queue.status.completed`)}),(0,G.jsx)(`option`,{value:`failed`,children:e(`queue.status.failed`)}),(0,G.jsx)(`option`,{value:`skipped`,children:e(`queue.status.skipped`)}),(0,G.jsx)(`option`,{value:`cancelled`,children:e(`queue.status.cancelled`)})]}),ke.length>0&&(0,G.jsxs)(`select`,{className:`px-2 sm:px-3 py-2 text-sm sm:text-base bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none min-w-0 flex-1 sm:flex-none`,value:u,onChange:e=>d(e.target.value),children:[(0,G.jsx)(`option`,{value:``,children:e(`queue.filter.allLocations`)}),ke.map(e=>(0,G.jsx)(`option`,{value:e,children:e},e))]}),(0,G.jsx)(`div`,{className:`hidden sm:block flex-1`}),L===`history`&&He.length>0&&(0,G.jsxs)(Q,{className:`w-full sm:w-auto`,variant:`secondary`,size:`sm`,onClick:()=>p(!0),disabled:!r(`queue:delete_all`),title:r(`queue:delete_all`)?void 0:e(`queue.permissions.noClearHistory`),children:[(0,G.jsx)(Pu,{className:`w-4 h-4`}),e(`queue.clearHistory`)]})]}),L===`queue`&&(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 mb-6`,children:[(0,G.jsxs)(`div`,{className:`inline-flex items-center bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg p-0.5`,children:[(0,G.jsxs)(`button`,{className:`px-3 py-1.5 text-xs sm:text-sm rounded-md transition-colors flex items-center gap-1.5 ${z===`position`?`bg-bambu-dark-tertiary text-white`:`text-bambu-gray hover:text-white`}`,onClick:()=>B(`position`),title:e(`queue.layout.flatList`),children:[(0,G.jsx)(el,{className:`w-3.5 h-3.5`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`queue.layout.flatList`)})]}),(0,G.jsxs)(`button`,{className:`px-3 py-1.5 text-xs sm:text-sm rounded-md transition-colors flex items-center gap-1.5 ${z===`printer`?`bg-bambu-dark-tertiary text-white`:`text-bambu-gray hover:text-white`}`,onClick:()=>B(`printer`),title:e(`queue.layout.groupByPrinter`),children:[(0,G.jsx)(Rl,{className:`w-3.5 h-3.5`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`queue.layout.byPrinter`)})]})]}),(0,G.jsxs)(`button`,{onClick:()=>{let e=!(H?.queue_shortest_first??!1);me.mutate(e)},className:`flex items-center gap-1 px-2 py-1.5 text-xs rounded-lg border transition-colors ${H?.queue_shortest_first?`bg-bambu-green/20 border-bambu-green text-bambu-green`:`bg-bambu-dark-secondary border-bambu-dark-tertiary text-bambu-gray hover:text-white hover:border-bambu-gray`}`,title:e(`queue.sjf.tooltip`,`Shortest Job First — scheduler prioritizes shorter prints`),children:[(0,G.jsx)(hu,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`queue.sjf.label`,`SJF`)}),(0,G.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full ${H?.queue_shortest_first?`bg-bambu-green`:`bg-bambu-gray`}`})]})]}),L===`pipelines`?(0,G.jsx)(EUe,{}):L===`batches`?(0,G.jsx)(RUe,{hasPermission:r,t:e}):fe?(0,G.jsx)(`div`,{className:`text-center py-12 text-bambu-gray`,children:e(`common.loading`)}):de?.length===0?(0,G.jsxs)(zd,{className:`p-12 text-center border-dashed`,children:[(0,G.jsx)(as,{className:`w-16 h-16 text-bambu-gray mx-auto mb-4 opacity-50`}),(0,G.jsx)(`h3`,{className:`text-xl font-medium text-white mb-2`,children:e(`queue.empty.title`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray max-w-md mx-auto`,children:e(`queue.empty.description`)})]}):L===`timeline`?(0,G.jsx)(LUe,{queueItems:de||[],printers:pe||[],printerStatuses:Ve,sjfEnabled:H?.queue_shortest_first??!1,onItemClick:e=>{[`completed`,`failed`,`skipped`,`cancelled`].includes(e.status)?_(e):e.status===`pending`?h(e):e.status===`printing`&&b({type:`stop`,item:e})},t:e}):L===`history`?(0,G.jsx)(WUe,{items:He,collapsed:!1,visibleCount:j,onShowMore:()=>M(e=>e+c6),sortBy:D,sortAsc:k,onSortByChange:O,onSortAscToggle:()=>A(!k),onRemove:e=>b({type:`remove`,item:e}),onRequeue:_,timeFormat:ce,batchCollapsed:V,toggleBatchCollapsed:et,hasPermission:r,canModify:a,t:e}):(0,G.jsxs)(`div`,{className:`space-y-6 sm:space-y-8`,children:[Ne.length>0&&(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`h2`,{className:`text-base sm:text-lg font-semibold text-white mb-3 sm:mb-4 flex items-center gap-2`,children:[(0,G.jsx)(`div`,{className:`w-2 h-2 rounded-full bg-blue-400 animate-pulse`}),e(`queue.sections.currentlyPrinting`)]}),(0,G.jsx)(`div`,{className:`space-y-2 sm:space-y-3`,children:Ne.map(t=>(0,G.jsx)(o6,{item:t,onEdit:()=>{},onCancel:()=>{},onRemove:()=>{},onStop:()=>b({type:`stop`,item:t}),onRequeue:()=>{},onStart:()=>{},timeFormat:ce,hasPermission:r,canModify:a,printerState:t.printer_id?Be[t.printer_id]:null,t:e},t.id))})]}),je.length>0&&(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2 mb-3 sm:mb-4`,children:[(0,G.jsxs)(`h2`,{className:`text-base sm:text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(js,{className:`w-4 h-4 sm:w-5 sm:h-5 text-yellow-600 dark:text-yellow-400`}),e(`queue.sections.queued`),(0,G.jsxs)(`span`,{className:`text-xs sm:text-sm font-normal text-bambu-gray`,children:[`(`,e(`queue.itemCount`,{count:je.length}),`)`]}),(0,G.jsx)(`span`,{className:`hidden sm:inline text-xs text-bambu-gray ml-2`,title:e(`queue.reorderHint`),children:e(`queue.dragToReorder`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`select`,{className:`px-2 sm:px-3 py-1.5 text-xs sm:text-sm bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,value:N,onChange:e=>P(e.target.value),children:[(0,G.jsx)(`option`,{value:`position`,children:e(`queue.sort.byPosition`)}),(0,G.jsx)(`option`,{value:`name`,children:e(`queue.sort.byName`)}),(0,G.jsx)(`option`,{value:`printer`,children:e(`queue.sort.byPrinter`)}),(0,G.jsx)(`option`,{value:`time`,children:e(`queue.sort.bySchedule`)})]}),(0,G.jsx)(Q,{variant:`ghost`,size:`sm`,onClick:()=>I(!F),title:e(F?`common.ascending`:`common.descending`),className:`px-2`,children:F?(0,G.jsx)(Ho,{className:`w-4 h-4`}):(0,G.jsx)(Io,{className:`w-4 h-4`})})]})]}),(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 sm:gap-3 mb-3 sm:mb-4 p-2 sm:p-3 bg-bambu-dark rounded-lg`,children:[(0,G.jsxs)(Q,{variant:`ghost`,size:`sm`,onClick:Me,className:`flex items-center gap-1.5 sm:gap-2 text-xs sm:text-sm`,children:[x.length===je.length&&je.length>0?(0,G.jsx)(vu,{className:`w-4 h-4 text-bambu-green`}):(0,G.jsx)(bu,{className:`w-4 h-4`}),x.length===je.length&&je.length>0?e(`queue.bulkEdit.deselectAll`):e(`queue.bulkEdit.selectAll`)]}),x.length>0&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`span`,{className:`text-xs sm:text-sm text-bambu-gray`,children:e(`queue.bulkEdit.selected`,{count:x.length})}),(0,G.jsx)(`div`,{className:`hidden sm:block h-4 w-px bg-bambu-dark-tertiary`}),$e&&(0,G.jsxs)(Q,{variant:`ghost`,size:`sm`,onClick:()=>ie(!0),className:`flex items-center gap-1.5 sm:gap-2 text-xs sm:text-sm text-cyan-700 dark:text-cyan-300 hover:text-cyan-900 dark:hover:text-cyan-200`,title:e(`queue.batch.groupAsBatch`),children:[(0,G.jsx)(Cl,{className:`w-3.5 h-3.5 sm:w-4 sm:h-4`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`queue.batch.groupAsBatch`)})]}),(0,G.jsxs)(Q,{variant:`ghost`,size:`sm`,onClick:()=>w(!0),className:`flex items-center gap-1.5 sm:gap-2 text-xs sm:text-sm text-bambu-green hover:text-bambu-green-light`,disabled:!i(`queue:update_own`,`queue:update_all`),title:i(`queue:update_own`,`queue:update_all`)?e(`queue.bulkEdit.editSelected`):e(`queue.permissions.noEditItems`),children:[(0,G.jsx)(Al,{className:`w-3.5 h-3.5 sm:w-4 sm:h-4`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`queue.bulkEdit.editSelected`)})]}),(0,G.jsxs)(Q,{variant:`ghost`,size:`sm`,onClick:()=>we.mutate(x),className:`flex items-center gap-1.5 sm:gap-2 text-xs sm:text-sm text-red-600 dark:text-red-400 hover:text-red-700 dark:hover:text-red-300`,disabled:we.isPending||!i(`queue:delete_own`,`queue:delete_all`),title:i(`queue:delete_own`,`queue:delete_all`)?e(`queue.bulkEdit.cancelSelected`):e(`queue.permissions.noCancelItems`),children:[(0,G.jsx)(nd,{className:`w-3.5 h-3.5 sm:w-4 sm:h-4`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`queue.bulkEdit.cancelSelected`)})]})]})]}),(0,G.jsxs)(k3,{sensors:se,collisionDetection:M4,onDragStart:Ge,onDragEnd:Ke,children:[(0,G.jsx)(z3,{items:Qe,strategy:mUe,children:z===`position`?(0,G.jsx)(`div`,{className:`space-y-2 sm:space-y-3`,children:qe.map((t,n)=>(0,G.jsx)(s6,{row:t,collapsed:t.kind===`batch`?V[t.batchId]??!0:!1,onToggleBatch:t.kind===`batch`?()=>et(t.batchId):void 0,onUngroup:t.kind===`batch`?()=>oe(t.batchId):void 0,setEditItem:h,setConfirmAction:b,startMutation:be,selectedItems:x,handleToggleSelect:Oe,timeFormat:ce,hasPermission:r,canModify:a,t:e,etaEligibleIds:Pe,etaNow:Fe,aggregateForRows:rt,...Ze(qe,n),onMoveBlock:Je?Xe:void 0},t.kind===`item`?`item-${t.item.id}`:`batch-${t.batchId}`))}):(0,G.jsx)(`div`,{className:`space-y-4`,children:tt.map(t=>{let n=rt(t.rows);return(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3 px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-t-lg`,children:[(0,G.jsx)(Rl,{className:`w-4 h-4 ${t.isUnassigned?`text-orange-600 dark:text-orange-400`:t.targetModel?`text-blue-600 dark:text-blue-400`:`text-bambu-green`}`}),(0,G.jsx)(`span`,{className:`font-semibold text-white text-sm`,children:t.label}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray flex flex-wrap gap-x-3`,children:[(0,G.jsx)(`span`,{children:e(`queue.itemCount`,{count:n.count})}),n.time>0&&(0,G.jsx)(`span`,{children:lp(n.time)}),n.weight>0&&(0,G.jsx)(`span`,{children:r6(n.weight)})]})]}),(0,G.jsx)(`div`,{className:`bg-bambu-dark/40 border border-t-0 border-bambu-dark-tertiary rounded-b-lg p-2 space-y-2`,children:t.rows.map((n,i)=>(0,G.jsx)(s6,{row:n,collapsed:n.kind===`batch`?V[n.batchId]??!0:!1,onToggleBatch:n.kind===`batch`?()=>et(n.batchId):void 0,onUngroup:n.kind===`batch`?()=>oe(n.batchId):void 0,setEditItem:h,setConfirmAction:b,startMutation:be,selectedItems:x,handleToggleSelect:Oe,timeFormat:ce,hasPermission:r,canModify:a,t:e,etaEligibleIds:Pe,etaNow:Fe,aggregateForRows:rt,...Ze(t.rows,i),onMoveBlock:Je?Xe:void 0},n.kind===`item`?`item-${n.item.id}`:`batch-${n.batchId}`))})]},t.key)})})}),(0,G.jsx)(uUe,{children:(()=>{if(te===null)return null;if(typeof te==`string`&&te.startsWith(`batch-`)){let t=Number(te.slice(6)),n=je.filter(e=>e.batch_id===t);if(n.length===0)return null;let r=n[0].batch_name||e(`queue.batch.defaultName`);return(0,G.jsxs)(`div`,{className:`flex items-center gap-3 px-3 py-2 bg-bambu-dark-secondary border-2 border-cyan-400 rounded-lg shadow-2xl`,children:[(0,G.jsx)(Cl,{className:`w-4 h-4 text-cyan-700 dark:text-cyan-300`}),(0,G.jsx)(`span`,{className:`text-sm text-white font-medium`,children:e(`queue.dragGhost.batch`,{defaultValue:`{{name}} ({{count}} copies)`,name:r,count:n.length})})]})}return typeof te==`number`&&x.includes(te)&&x.length>1?(0,G.jsxs)(`div`,{className:`flex items-center gap-3 px-3 py-2 bg-bambu-dark-secondary border-2 border-cyan-400 rounded-lg shadow-2xl`,children:[(0,G.jsx)(Cl,{className:`w-4 h-4 text-cyan-700 dark:text-cyan-300`}),(0,G.jsx)(`span`,{className:`text-sm text-white font-medium`,children:e(`queue.dragGhost.multiCount`,{count:x.length})})]}):null})()})]})]})]}),m&&(0,G.jsx)(zU,{mode:`edit-queue-item`,archiveId:m.archive_id??void 0,libraryFileId:m.library_file_id??void 0,archiveName:jT(m,t=>e(`common.plusNMore`,{count:t})),queueItem:m,onClose:()=>h(null)}),g&&(0,G.jsx)(zU,{mode:`create`,archiveId:g.archive_id??void 0,libraryFileId:g.library_file_id??void 0,archiveName:jT(g,t=>e(`common.plusNMore`,{count:t})),onClose:()=>_(null)}),ve&&(0,G.jsx)(of,{title:e(`queue.filamentShort.confirmTitle`),message:e(`queue.filamentShort.confirmIntro`)+` + `,onClick:L?()=>{window.innerWidth<640&&f()}:void 0,children:[L&&d&&(0,G.jsx)(`div`,{className:`sm:hidden absolute left-0 top-3 bottom-3 w-1 rounded-full bg-bambu-green`}),(0,G.jsxs)(`div`,{className:`flex items-start sm:items-center gap-2 sm:gap-4 p-3 sm:p-4`,children:[P&&(c||l)&&(0,G.jsxs)(`div`,{className:`flex sm:hidden flex-col shrink-0 -my-1`,onClick:e=>e.stopPropagation(),children:[(0,G.jsx)(`button`,{type:`button`,onClick:c,disabled:!c,title:v(`queue.moveUp`),"aria-label":v(`queue.moveUp`),className:`flex items-center justify-center w-8 h-7 rounded-lg text-bambu-gray hover:text-white hover:bg-bambu-dark disabled:opacity-25 disabled:hover:bg-transparent transition-colors`,children:(0,G.jsx)(gs,{className:`w-5 h-5`})}),(0,G.jsx)(`button`,{type:`button`,onClick:l,disabled:!l,title:v(`queue.moveDown`),"aria-label":v(`queue.moveDown`),className:`flex items-center justify-center w-8 h-7 rounded-lg text-bambu-gray hover:text-white hover:bg-bambu-dark disabled:opacity-25 disabled:hover:bg-transparent transition-colors`,children:(0,G.jsx)(ps,{className:`w-5 h-5`})})]}),P&&f&&(0,G.jsx)(`button`,{onClick:e=>{e.stopPropagation(),f()},className:`hidden sm:flex items-center justify-center w-6 h-6 rounded border transition-colors shrink-0 ${d?`bg-bambu-green border-bambu-green text-white`:`border-white/30 bg-black/30 hover:border-bambu-green/50`}`,children:d&&(0,G.jsx)(fs,{className:`w-4 h-4`})}),P?(0,G.jsx)(`div`,{...E,...D,className:`hidden sm:flex items-center justify-center w-8 h-8 rounded-lg bg-bambu-dark cursor-grab active:cursor-grabbing hover:bg-bambu-dark-tertiary transition-colors touch-none shrink-0`,children:(0,G.jsx)(jc,{className:`w-4 h-4 text-bambu-gray`})}):t===void 0?(0,G.jsx)(`div`,{className:`hidden sm:block w-8 shrink-0`}):(0,G.jsxs)(`div`,{className:`hidden sm:flex items-center justify-center w-8 h-8 rounded-lg bg-bambu-dark text-bambu-gray text-sm font-medium shrink-0`,children:[`#`,t]}),(0,G.jsx)(`div`,{className:`w-10 h-10 sm:w-14 sm:h-14 flex-shrink-0 bg-bambu-dark rounded-lg overflow-hidden`,children:e.archive_thumbnail?(0,G.jsx)(`img`,{src:e.plate_id==null?Z.getArchiveThumbnail(e.archive_id):Z.getArchivePlateThumbnail(e.archive_id,e.plate_id),alt:``,className:`w-full h-full object-cover`}):e.library_file_thumbnail?(0,G.jsx)(`img`,{src:e.plate_id==null?Z.getLibraryFileThumbnailUrl(e.library_file_id):Z.getLibraryFilePlateThumbnail(e.library_file_id,e.plate_id),alt:``,className:`w-full h-full object-cover`}):(0,G.jsx)(`div`,{className:`w-full h-full flex items-center justify-center text-bambu-gray`,children:(0,G.jsx)(Jc,{className:`w-5 h-5 sm:w-6 sm:h-6`})})}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,G.jsxs)(`p`,{className:`text-sm sm:text-base text-white font-medium truncate`,children:[jT(e,e=>v(`common.plusNMore`,{count:e})),(C?.is_multi_plate??!1)&&e.plate_id!==void 0&&e.plate_id!==null&&` • ${w.find(t=>t.index===e.plate_id)?.name||v(`queue.plateNumber`,{index:e.plate_id})}`]}),e.archive_id?(0,G.jsx)(Ai,{to:`/archives?highlight=${e.archive_id}`,className:`text-bambu-gray hover:text-bambu-green transition-colors flex-shrink-0`,title:v(`queue.viewArchive`),children:(0,G.jsx)(rc,{className:`w-3.5 h-3.5`})}):e.library_file_id?(0,G.jsx)(Ai,{to:`/library?highlight=${e.library_file_id}`,className:`text-bambu-gray hover:text-bambu-green transition-colors flex-shrink-0`,title:v(`queue.viewInFileManager`),children:(0,G.jsx)(rc,{className:`w-3.5 h-3.5`})}):null,e.batch_name&&(0,G.jsx)(`span`,{className:`flex-shrink-0 px-1.5 py-0.5 text-[10px] sm:text-xs bg-cyan-100 dark:bg-cyan-500/20 text-cyan-700 dark:text-cyan-300 rounded border border-cyan-300 dark:border-cyan-500/30`,children:e.batch_name})]}),(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-xs sm:text-sm text-bambu-gray`,children:[(0,G.jsxs)(`span`,{className:`flex items-center gap-1 sm:gap-1.5 ${e.printer_id===null&&!e.target_model?`text-orange-700 dark:text-orange-400`:``} ${e.target_model&&!e.printer_id?`text-blue-700 dark:text-blue-400`:``}`,children:[(0,G.jsx)(Rl,{className:`w-3 h-3 sm:w-3.5 sm:h-3.5`}),(0,G.jsx)(`span`,{className:`truncate max-w-[120px] sm:max-w-none`,children:(e.variants?.length??0)>1&&!e.printer_id?`${v(`queue.filter.any`)} ${e.variants.map(e=>e.target_model).join(` / `)}${e.target_location?` @ ${e.target_location}`:``}`:e.target_model&&!e.printer_id?`${v(`queue.filter.any`)} ${e.target_model}${e.target_location?` @ ${e.target_location}`:``}${e.required_filament_types?.length?` (${e.required_filament_types.join(`, `)})`:``}`:e.printer_id===null?v(`queue.filter.unassigned`):e.printer_name||`${v(`common.printer`)} #${e.printer_id}`})]}),e.print_time_seconds&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1 sm:gap-1.5`,children:[(0,G.jsx)(Nu,{className:`w-3 h-3 sm:w-3.5 sm:h-3.5`}),lp(e.print_time_seconds)]}),I&&(0,G.jsxs)(`span`,{"data-testid":`queue-item-eta`,className:`text-bambu-green font-medium`,title:v(`queue.time.etaIfStartedNow`),children:[`ETA `,I]}),e.filament_used_grams&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1 sm:gap-1.5`,children:[(0,G.jsx)(Xu,{className:`w-3 h-3 sm:w-3.5 sm:h-3.5`}),r6(e.filament_used_grams)]}),(()=>{let t=EU(e.bed_type);return t?(0,G.jsxs)(`span`,{className:`flex items-center gap-1 sm:gap-1.5`,title:t.label,children:[(0,G.jsx)(`img`,{src:t.icon,alt:``,className:`w-3.5 h-3.5 sm:w-4 sm:h-4 object-contain`}),(0,G.jsx)(`span`,{className:`truncate max-w-[120px]`,children:t.label})]}):null})(),e.created_by_username&&(0,G.jsxs)(`span`,{className:`hidden sm:flex items-center gap-1.5`,title:v(`queue.addedBy`,{name:e.created_by_username}),children:[(0,G.jsx)(Hu,{className:`w-3.5 h-3.5`}),e.created_by_username]}),P&&!e.manual_start&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,G.jsx)(js,{className:`w-3.5 h-3.5`}),e.scheduled_time?(rp(e.scheduled_time)?.getTime()??0)-Date.now()<-6e4?v?.(`queue.time.overdue`)??`Overdue`:up(e.scheduled_time,u,v):v?.(`queue.time.whenFree`)??`When a printer is free`]})]}),(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5 sm:gap-2 mt-1.5 sm:mt-2`,children:[e.manual_start&&(0,G.jsxs)(`span`,{className:`text-[10px] sm:text-xs px-1.5 sm:px-2 py-0.5 bg-purple-50 dark:bg-purple-500/10 text-purple-700 dark:text-purple-400 rounded-full border border-purple-200 dark:border-purple-500/20 flex items-center gap-1`,children:[(0,G.jsx)(Nc,{className:`w-2.5 h-2.5 sm:w-3 sm:h-3`}),v(`queue.badges.staged`)]}),e.require_previous_success&&(0,G.jsx)(`span`,{className:`text-[10px] sm:text-xs px-1.5 sm:px-2 py-0.5 bg-orange-50 dark:bg-orange-500/10 text-orange-700 dark:text-orange-400 rounded-full border border-orange-200 dark:border-orange-500/20`,children:v(`queue.badges.requiresPrevious`)}),e.auto_off_after&&(0,G.jsxs)(`span`,{className:`text-[10px] sm:text-xs px-1.5 sm:px-2 py-0.5 bg-blue-50 dark:bg-blue-500/10 text-blue-700 dark:text-blue-400 rounded-full border border-blue-200 dark:border-blue-500/20 flex items-center gap-1`,children:[(0,G.jsx)(Ll,{className:`w-2.5 h-2.5 sm:w-3 sm:h-3`}),v(`queue.badges.autoPowerOff`)]}),e.gcode_injection&&(0,G.jsxs)(`span`,{className:`text-[10px] sm:text-xs px-1.5 sm:px-2 py-0.5 bg-emerald-50 dark:bg-emerald-500/10 text-emerald-700 dark:text-emerald-400 rounded-full border border-emerald-200 dark:border-emerald-500/20 flex items-center gap-1`,children:[(0,G.jsx)(Fs,{className:`w-2.5 h-2.5 sm:w-3 sm:h-3`}),v(`queue.badges.gcodeInjection`)]})]}),N&&y&&(()=>{let e=y.state===`RUNNING`||y.state===`PAUSE`,t=e&&y.progress||0,n=e?y.remaining_time:null,r=e?y.layer_num:null,i=e?y.total_layers:null;return(0,G.jsxs)(`div`,{className:`mt-2 sm:mt-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between text-xs sm:text-sm`,children:[(0,G.jsx)(`div`,{className:`flex-1 bg-bambu-dark-tertiary rounded-full h-1.5 sm:h-2 mr-3`,children:(0,G.jsx)(`div`,{className:`bg-bambu-green h-1.5 sm:h-2 rounded-full transition-all`,style:{width:`${t}%`}})}),(0,G.jsxs)(`span`,{className:`text-white`,children:[Math.round(t),`%`]})]}),(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 sm:gap-3 mt-1.5 sm:mt-2 text-[10px] sm:text-xs text-bambu-gray`,children:[n!=null&&n>0&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(js,{className:`w-3 h-3`}),lp(n*60)]}),(0,G.jsxs)(`span`,{className:`text-bambu-green font-medium`,title:v(`printers.estimatedCompletion`),children:[`ETA `,cp(n,u,v)]})]}),r!=null&&i!=null&&i>0&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(Jc,{className:`w-3 h-3`}),r,`/`,i]})]})]})})(),e.waiting_reason&&e.status===`pending`&&(0,G.jsxs)(`p`,{className:`text-[10px] sm:text-xs text-purple-700 dark:text-purple-400 mt-1.5 sm:mt-2 flex items-start gap-1`,children:[(0,G.jsx)(ys,{className:`w-3 h-3 mt-0.5 flex-shrink-0`}),(0,G.jsx)(`span`,{children:e.waiting_reason})]}),e.filament_short&&e.status===`pending`&&(0,G.jsxs)(`p`,{className:`text-[10px] sm:text-xs text-yellow-700 dark:text-yellow-400 mt-1.5 sm:mt-2 flex items-start gap-1`,title:v(`queue.filamentShort.rowTooltip`),children:[(0,G.jsx)(ys,{className:`w-3 h-3 mt-0.5 flex-shrink-0`}),(0,G.jsx)(`span`,{children:v(`queue.filamentShort.rowBadge`)})]}),e.archive_has_slicer_ams_mapping&&(0,G.jsxs)(`p`,{className:`text-[10px] sm:text-xs text-green-700 dark:text-green-400 mt-1.5 sm:mt-2 flex items-start gap-1`,title:v(`queue.slicerAmsMapping.rowTooltip`),children:[(0,G.jsx)(fs,{className:`w-3 h-3 mt-0.5 flex-shrink-0`}),(0,G.jsx)(`span`,{children:v(`queue.slicerAmsMapping.rowBadge`)})]}),e.error_message&&(0,G.jsxs)(`p`,{className:`text-[10px] sm:text-xs text-red-700 dark:text-red-400 mt-1.5 sm:mt-2 flex items-center gap-1`,children:[(0,G.jsx)(ys,{className:`w-3 h-3`}),e.error_message]})]}),(0,G.jsxs)(`div`,{className:`flex flex-col sm:flex-row items-end sm:items-center gap-2 sm:gap-1 shrink-0`,onClick:e=>e.stopPropagation(),children:[(0,G.jsx)(HUe,{status:e.status,waitingReason:e.waiting_reason,printerState:h,t:v}),(0,G.jsxs)(`div`,{className:`flex items-center gap-0.5 sm:gap-1`,children:[N&&(0,G.jsx)(Q,{variant:`ghost`,size:`sm`,onClick:a,disabled:!m(`queue`,`update`,e.created_by_id),title:m(`queue`,`update`,e.created_by_id)?v(`queue.actions.stopPrint`):v(`queue.permissions.noStopPrint`),className:`text-red-600 dark:text-red-400 hover:text-red-700 dark:hover:text-red-300 hover:bg-red-50 dark:hover:bg-red-500/10 p-1.5 sm:p-2`,children:(0,G.jsx)(Es,{className:`w-4 h-4`})}),P&&(0,G.jsxs)(G.Fragment,{children:[e.manual_start&&(0,G.jsx)(Q,{variant:`ghost`,size:`sm`,onClick:s,disabled:!m(`queue`,`update`,e.created_by_id),title:m(`queue`,`update`,e.created_by_id)?v(`queue.actions.startPrint`):v(`queue.permissions.noStartPrint`),className:`text-bambu-green hover:text-bambu-green-light hover:bg-bambu-green/10 p-1.5 sm:p-2`,children:(0,G.jsx)(Nl,{className:`w-4 h-4`})}),(0,G.jsx)(Q,{variant:`ghost`,size:`sm`,onClick:n,disabled:!m(`queue`,`update`,e.created_by_id),title:m(`queue`,`update`,e.created_by_id)?v(`common.edit`):v(`queue.permissions.noEdit`),className:`p-1.5 sm:p-2`,children:(0,G.jsx)(Al,{className:`w-4 h-4`})}),(0,G.jsx)(Q,{variant:`ghost`,size:`sm`,onClick:r,disabled:!m(`queue`,`delete`,e.created_by_id),title:m(`queue`,`delete`,e.created_by_id)?v(`common.cancel`):v(`queue.permissions.noCancel`),className:`text-red-600 dark:text-red-400 hover:text-red-700 dark:hover:text-red-300 hover:bg-red-50 dark:hover:bg-red-500/10 p-1.5 sm:p-2`,children:(0,G.jsx)(nd,{className:`w-4 h-4`})})]}),F&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Q,{variant:`ghost`,size:`sm`,onClick:o,disabled:!p(`queue:create`),title:p(`queue:create`)?v(`queue.actions.requeue`):v(`queue.permissions.noRequeue`),className:`text-bambu-green hover:text-bambu-green/80 hover:bg-bambu-green/10 p-1.5 sm:p-2`,children:(0,G.jsx)(Hl,{className:`w-4 h-4`})}),(0,G.jsx)(Q,{variant:`ghost`,size:`sm`,onClick:i,disabled:!m(`queue`,`delete`,e.created_by_id),title:m(`queue`,`delete`,e.created_by_id)?v(`common.remove`):v(`queue.permissions.noRemove`),className:`p-1.5 sm:p-2`,children:(0,G.jsx)(Pu,{className:`w-4 h-4`})})]})]})]})]})]})}function s6(e){let{row:t,setEditItem:n,setConfirmAction:r,startMutation:i,selectedItems:a,handleToggleSelect:o,timeFormat:s,hasPermission:c,canModify:l,t:u,etaEligibleIds:d,etaNow:f,onMoveUp:p,onMoveDown:m}=e;return t.kind===`item`?(0,G.jsx)(o6,{item:t.item,onEdit:()=>n(t.item),onCancel:()=>r({type:`cancel`,item:t.item}),onRemove:()=>{},onStop:()=>{},onRequeue:()=>{},onStart:()=>i.mutate({id:t.item.id}),onMoveUp:p,onMoveDown:m,timeFormat:s,isSelected:a.includes(t.item.id),onToggleSelect:()=>o(t.item.id),hasPermission:c,canModify:l,showEta:d.has(t.item.id),etaNow:f,t:u}):(0,G.jsx)(WUe,{...e})}function WUe({row:e,collapsed:t,onToggleBatch:n,onUngroup:r,setEditItem:i,setConfirmAction:a,startMutation:o,selectedItems:s,handleToggleSelect:c,timeFormat:l,hasPermission:u,canModify:d,t:f,etaEligibleIds:p,etaNow:m,aggregateForRows:h,onMoveUp:g,onMoveDown:_,onMoveBlock:v}){let y=e,b=u(`queue:reorder`),{attributes:x,listeners:S,setNodeRef:C,transform:w,transition:T,isDragging:E}=V3({id:`batch-${y.batchId}`,disabled:!b}),D={transform:y4.Transform.toString(w),transition:T},O=h([y]),k=y.items.map(e=>e.id),A=k.length>0&&k.every(e=>s.includes(e)),j=new Set(y.items.map(e=>e.status)),M=j.has(`failed`)?`failed`:j.has(`printing`)?`printing`:`pending`,N=y.items.filter(e=>e.status===`pending`).length;return(0,G.jsxs)(`div`,{ref:C,style:D,className:`bg-bambu-dark-secondary rounded-xl border border-l-[3px] border-l-cyan-400 border-bambu-dark-tertiary overflow-hidden ${E?`opacity-50 scale-[1.01] shadow-xl z-50`:``}`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 sm:gap-3 p-3 sm:p-4`,children:[b&&(g||_)&&(0,G.jsxs)(`div`,{className:`flex sm:hidden flex-col shrink-0 -my-1`,children:[(0,G.jsx)(`button`,{type:`button`,onClick:g,disabled:!g,title:f(`queue.moveUp`),"aria-label":f(`queue.moveUp`),className:`flex items-center justify-center w-8 h-7 rounded-lg text-bambu-gray hover:text-white hover:bg-bambu-dark disabled:opacity-25 disabled:hover:bg-transparent transition-colors`,children:(0,G.jsx)(gs,{className:`w-5 h-5`})}),(0,G.jsx)(`button`,{type:`button`,onClick:_,disabled:!_,title:f(`queue.moveDown`),"aria-label":f(`queue.moveDown`),className:`flex items-center justify-center w-8 h-7 rounded-lg text-bambu-gray hover:text-white hover:bg-bambu-dark disabled:opacity-25 disabled:hover:bg-transparent transition-colors`,children:(0,G.jsx)(ps,{className:`w-5 h-5`})})]}),(0,G.jsx)(`button`,{onClick:e=>{e.stopPropagation(),k.forEach(e=>{(A&&s.includes(e)||!A&&!s.includes(e))&&c(e)})},className:`hidden sm:flex items-center justify-center w-6 h-6 rounded border transition-colors shrink-0 ${A?`bg-bambu-green border-bambu-green text-white`:`border-white/30 bg-black/30 hover:border-bambu-green/50`}`,title:f(A?`queue.bulkEdit.deselectAll`:`queue.bulkEdit.selectAll`),children:A&&(0,G.jsx)(fs,{className:`w-4 h-4`})}),b&&(0,G.jsx)(`div`,{...x,...S,className:`hidden sm:flex items-center justify-center w-8 h-8 rounded-lg bg-bambu-dark cursor-grab active:cursor-grabbing hover:bg-bambu-dark-tertiary transition-colors touch-none shrink-0`,title:f(`queue.batch.dragGroup`,{defaultValue:`Drag group`}),children:(0,G.jsx)(jc,{className:`w-4 h-4 text-bambu-gray`})}),(0,G.jsx)(`button`,{onClick:n,className:`flex items-center justify-center w-8 h-8 rounded-lg bg-bambu-dark hover:bg-bambu-dark-tertiary transition-colors shrink-0`,title:f(t?`queue.batch.expand`:`queue.batch.collapse`),children:t?(0,G.jsx)(ms,{className:`w-4 h-4 text-bambu-gray`}):(0,G.jsx)(ps,{className:`w-4 h-4 text-bambu-gray`})}),(0,G.jsx)(`div`,{className:`w-10 h-10 sm:w-12 sm:h-12 flex-shrink-0 bg-bambu-dark rounded-lg flex items-center justify-center`,children:t?(0,G.jsx)(Cl,{className:`w-5 h-5 text-cyan-700 dark:text-cyan-300`}):(0,G.jsx)(Sl,{className:`w-5 h-5 text-cyan-700 dark:text-cyan-300`})}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,G.jsx)(`p`,{className:`text-sm sm:text-base text-white font-medium truncate`,children:y.batchName}),(0,G.jsx)(`span`,{className:`flex-shrink-0 px-1.5 py-0.5 text-[10px] sm:text-xs bg-cyan-100 dark:bg-cyan-500/15 text-cyan-700 dark:text-cyan-300 rounded border border-cyan-300 dark:border-cyan-500/30`,children:f(`queue.batch.label`,{count:O.count})})]}),(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-xs sm:text-sm text-bambu-gray`,children:[O.time>0&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1 sm:gap-1.5`,children:[(0,G.jsx)(Nu,{className:`w-3 h-3 sm:w-3.5 sm:h-3.5`}),lp(O.time)]}),O.weight>0&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1 sm:gap-1.5`,children:[(0,G.jsx)(Xu,{className:`w-3 h-3 sm:w-3.5 sm:h-3.5`}),r6(O.weight)]}),N>0&&M===`pending`&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1 sm:gap-1.5 text-yellow-700 dark:text-yellow-400`,children:[(0,G.jsx)(js,{className:`w-3 h-3 sm:w-3.5 sm:h-3.5`}),f(`queue.batch.pendingCount`,{count:N})]})]})]}),(0,G.jsx)(`div`,{className:`flex items-center gap-1 shrink-0`,children:r&&(0,G.jsx)(Q,{variant:`ghost`,size:`sm`,onClick:r,title:f(`queue.batch.ungroup`),className:`text-cyan-700 dark:text-cyan-300 hover:text-cyan-900 dark:hover:text-cyan-200 hover:bg-cyan-50 dark:hover:bg-cyan-500/10 p-1.5 sm:p-2`,children:(0,G.jsx)(zu,{className:`w-4 h-4`})})})]}),!t&&(0,G.jsx)(`div`,{className:`border-t border-bambu-dark-tertiary bg-black/20 p-2 sm:p-3 space-y-2`,children:y.items.map((e,t)=>(0,G.jsx)(o6,{item:e,onEdit:()=>i(e),onCancel:()=>a({type:`cancel`,item:e}),onRemove:()=>{},onStop:()=>{},onRequeue:()=>{},onStart:()=>o.mutate({id:e.id}),onMoveUp:v&&t>0?()=>v([e.id],y.items[t-1].id,!1):void 0,onMoveDown:v&&tv([e.id],y.items[t+1].id,!0):void 0,timeFormat:l,isSelected:s.includes(e.id),onToggleSelect:()=>c(e.id),hasPermission:u,canModify:d,showEta:p.has(e.id),etaNow:m,t:f},e.id))})]})}function GUe({items:e,visibleCount:t,onShowMore:n,sortBy:r,sortAsc:i,onSortByChange:a,onSortAscToggle:o,onRemove:s,onRequeue:c,timeFormat:l,batchCollapsed:u,toggleBatchCollapsed:d,hasPermission:f,canModify:p,t:m}){if(e.length===0)return(0,G.jsxs)(zd,{className:`p-12 text-center border-dashed`,children:[(0,G.jsx)(Qc,{className:`w-16 h-16 text-bambu-gray mx-auto mb-4 opacity-50`}),(0,G.jsx)(`h3`,{className:`text-xl font-medium text-white mb-2`,children:m(`queue.history.emptyTitle`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray max-w-md mx-auto`,children:m(`queue.history.emptyDescription`)})]});let h=[],g=new Set;for(let n of e.slice(0,t))if(n.batch_id!=null){if(g.has(n.batch_id))continue;g.add(n.batch_id);let t=e.filter(e=>e.batch_id===n.batch_id);h.push({kind:`batch`,batchId:n.batch_id,batchName:n.batch_name||m(`queue.batch.defaultName`),items:t})}else h.push({kind:`item`,item:n});return(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2 mb-3 sm:mb-4`,children:[(0,G.jsxs)(`h2`,{className:`text-base sm:text-lg font-semibold text-white flex items-center gap-2`,children:[m(`queue.sections.history`),(0,G.jsxs)(`span`,{className:`text-xs sm:text-sm font-normal text-bambu-gray`,children:[`(`,m(`queue.itemCount`,{count:e.length}),`)`]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`select`,{className:`px-2 sm:px-3 py-1.5 text-xs sm:text-sm bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,value:r,onChange:e=>a(e.target.value),children:[(0,G.jsx)(`option`,{value:`date`,children:m(`queue.sort.byDate`)}),(0,G.jsx)(`option`,{value:`name`,children:m(`queue.sort.byName`)}),(0,G.jsx)(`option`,{value:`printer`,children:m(`queue.sort.byPrinter`)})]}),(0,G.jsx)(Q,{variant:`ghost`,size:`sm`,onClick:o,title:m(i?`queue.sort.ascendingOldest`:`queue.sort.descendingNewest`),className:`px-2`,children:i?(0,G.jsx)(Ho,{className:`w-4 h-4`}):(0,G.jsx)(Io,{className:`w-4 h-4`})})]})]}),(0,G.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-2`,children:h.map(e=>{if(e.kind===`item`)return(0,G.jsx)(J3,{item:e.item,onRemove:()=>s(e.item),onRequeue:()=>c(e.item),timeFormat:l,hasPermission:f,canModify:p,t:m},e.item.id);let t=u[e.batchId]??!0,n=e.items.filter(e=>e.status===`completed`).length,r=e.items.filter(e=>e.status===`failed`).length,i=e.items.filter(e=>e.status===`skipped`).length,a=e.items.filter(e=>e.status===`cancelled`).length,o=e.items.map(e=>e.completed_at||e.created_at).filter(e=>!!e).sort().at(-1);return(0,G.jsxs)(`div`,{className:`md:col-span-2 xl:col-span-3 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary border-l-[3px] border-l-cyan-400`,children:[(0,G.jsxs)(`button`,{onClick:()=>d(e.batchId),className:`w-full flex items-center gap-2 sm:gap-3 px-3 py-2 hover:bg-bambu-dark/30 transition-colors text-left`,title:m(t?`queue.batch.expand`:`queue.batch.collapse`),children:[t?(0,G.jsx)(ms,{className:`w-4 h-4 text-bambu-gray shrink-0`}):(0,G.jsx)(ps,{className:`w-4 h-4 text-bambu-gray shrink-0`}),t?(0,G.jsx)(Cl,{className:`w-5 h-5 text-cyan-700 dark:text-cyan-300 shrink-0`}):(0,G.jsx)(Sl,{className:`w-5 h-5 text-cyan-700 dark:text-cyan-300 shrink-0`}),(0,G.jsx)(`span`,{className:`text-sm text-white font-medium truncate min-w-0 flex-1`,children:e.batchName}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-bambu-gray shrink-0`,children:[n>0&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-emerald-700 dark:text-emerald-400`,children:[(0,G.jsx)(xs,{className:`w-3 h-3`}),n]}),r>0&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-red-700 dark:text-red-400`,children:[(0,G.jsx)(Ds,{className:`w-3 h-3`}),r]}),i>0&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-orange-700 dark:text-orange-400`,children:[(0,G.jsx)(du,{className:`w-3 h-3`}),i]}),a>0&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-gray-400`,children:[(0,G.jsx)(Uo,{className:`w-3 h-3`}),a]}),(0,G.jsx)(`span`,{title:o??void 0,children:o?up(o,l,m):null})]})]}),!t&&(0,G.jsx)(`div`,{className:`border-t border-bambu-dark-tertiary bg-black/20 p-2 grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-2`,children:e.items.map(e=>(0,G.jsx)(J3,{item:e,onRemove:()=>s(e),onRequeue:()=>c(e),timeFormat:l,hasPermission:f,canModify:p,t:m},e.id))})]},`batch-${e.batchId}`)})}),e.length>t&&(0,G.jsxs)(`div`,{className:`mt-4 flex flex-col items-center gap-2`,children:[(0,G.jsx)(Q,{variant:`secondary`,size:`sm`,onClick:n,children:m(`queue.history.showMore`)}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:m(`queue.history.showingCount`,{shown:Math.min(t,e.length),total:e.length})})]})]})}var c6=50;function KUe(){let{t:e}=U(),t=co(),{showToast:n}=qd(),{hasPermission:r,hasAnyPermission:i,canModify:a}=Nd(),[o,s]=(0,y.useState)(null),[c,l]=(0,y.useState)(``),[u,d]=(0,y.useState)(``),[f,p]=(0,y.useState)(!1),[m,h]=(0,y.useState)(null),[g,_]=(0,y.useState)(null),[v,b]=(0,y.useState)(null),[x,S]=(0,y.useState)([]),[C,w]=(0,y.useState)(!1),[T,E]=(0,y.useState)(null),[D,O]=(0,y.useState)(()=>localStorage.getItem(`queue.historySortBy`)||`date`),[k,A]=(0,y.useState)(()=>{let e=localStorage.getItem(`queue.historySortAsc`);return e===null?!1:e===`true`}),[j,M]=(0,y.useState)(c6),[N,P]=(0,y.useState)(()=>localStorage.getItem(`queue.pendingSortBy`)||`position`),[F,I]=(0,y.useState)(()=>{let e=localStorage.getItem(`queue.pendingSortAsc`);return e===null?!0:e===`true`}),[L,R]=(0,y.useState)(()=>{let e=new URLSearchParams(window.location.search).get(`tab`);if(e===`pipelines`||e===`history`||e===`timeline`||e===`queue`||e===`batches`)return e;let t=localStorage.getItem(`queue.activeTab`);return t===`history`||t===`timeline`||t===`pipelines`||t===`batches`?t:`queue`}),[z,B]=(0,y.useState)(()=>localStorage.getItem(`queue.activeLayout`)===`printer`?`printer`:`position`),[V,ee]=(0,y.useState)(()=>{try{let e=localStorage.getItem(`queue.batchCollapsed`);return e?JSON.parse(e):{}}catch{return{}}}),[te,ne]=(0,y.useState)(null),[re,ie]=(0,y.useState)(!1),[ae,oe]=(0,y.useState)(null);(0,y.useEffect)(()=>{localStorage.setItem(`queue.historySortBy`,D)},[D]),(0,y.useEffect)(()=>{localStorage.setItem(`queue.historySortAsc`,String(k))},[k]),(0,y.useEffect)(()=>{M(c6)},[D,k,u]),(0,y.useEffect)(()=>{localStorage.setItem(`queue.pendingSortBy`,N)},[N]),(0,y.useEffect)(()=>{localStorage.setItem(`queue.pendingSortAsc`,String(F))},[F]),(0,y.useEffect)(()=>{localStorage.setItem(`queue.activeTab`,L)},[L]),(0,y.useEffect)(()=>{localStorage.setItem(`queue.activeLayout`,z)},[z]),(0,y.useEffect)(()=>{localStorage.setItem(`queue.batchCollapsed`,JSON.stringify(V))},[V]);let se=T4(w4(a3,{activationConstraint:{distance:8}}),w4(t3,{coordinateGetter:U3})),{data:H}=K({queryKey:[`settings`],queryFn:Z.getSettings}),ce=H?.time_format||`system`,{data:le}=K({queryKey:[`batches`,`active`],queryFn:()=>Z.getBatches(`active`)}),ue=le?.length??0,{data:de,isLoading:fe}=K({queryKey:[`queue`,o,c],queryFn:()=>Z.getQueue(o||void 0,c||void 0),refetchInterval:5e3}),{data:pe}=K({queryKey:[`printers`],queryFn:()=>Z.getPrinters()}),me=q({mutationFn:e=>Z.updateSettings({queue_shortest_first:e}),onSuccess:()=>{t.invalidateQueries({queryKey:[`settings`]})}}),he=q({mutationFn:e=>Z.cancelQueueItem(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`queue`]}),n(e(`queue.toast.cancelled`))},onError:()=>n(e(`queue.toast.cancelFailed`),`error`)}),ge=q({mutationFn:e=>Z.removeFromQueue(e),onSuccess:r=>{t.invalidateQueries({queryKey:[`queue`]}),t.invalidateQueries({queryKey:[`batches`]}),n(r.deleted===!1?e(`queue.toast.keptForOrder`):e(`queue.toast.removed`))},onError:()=>n(e(`queue.toast.removeFailed`),`error`)}),_e=q({mutationFn:e=>Z.stopQueueItem(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`queue`]}),n(e(`queue.toast.stopped`))},onError:()=>n(e(`queue.toast.stopFailed`),`error`)}),[ve,ye]=(0,y.useState)(null),be=q({mutationFn:({id:e,skipFilamentCheck:t})=>Z.startQueueItem(e,{skipFilamentCheck:t}),onSuccess:()=>{t.invalidateQueries({queryKey:[`queue`]}),n(e(`queue.toast.released`)),ye(null)},onError:(t,r)=>{if(t instanceof sd&&t.status===409&&t.code===`insufficient_filament`){let e=t.detail?.deficit??[];ye({itemId:r.id,deficit:e});return}n(e(`queue.toast.startFailed`),`error`)}}),xe=q({mutationFn:e=>Z.reorderQueue(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`queue`]})},onError:()=>n(e(`queue.toast.reorderFailed`),`error`)}),Se=q({mutationFn:async()=>{let e=de?.filter(e=>[`completed`,`failed`,`skipped`,`cancelled`].includes(e.status))||[],t=0,n=0;for(let r of e)(await Z.removeFromQueue(r.id)).deleted===!1?n+=1:t+=1;return{cleared:t,kept:n}},onSuccess:({cleared:r,kept:i})=>{t.invalidateQueries({queryKey:[`queue`]}),t.invalidateQueries({queryKey:[`batches`]}),n(i>0?`${e(`queue.toast.historyCleared`,{count:r})} ${e(`queue.toast.historyKeptForOrders`,{kept:i})}`:e(`queue.toast.historyCleared`,{count:r}))},onError:()=>n(e(`queue.toast.clearHistoryFailed`),`error`)}),Ce=q({mutationFn:e=>Z.bulkUpdateQueue(e),onSuccess:e=>{t.invalidateQueries({queryKey:[`queue`]}),S([]),w(!1),n(e.message)},onError:()=>n(e(`queue.toast.updateFailed`),`error`)}),we=q({mutationFn:async e=>{for(let t of e)await Z.cancelQueueItem(t);return e.length},onSuccess:r=>{t.invalidateQueries({queryKey:[`queue`]}),S([]),n(e(`queue.toast.bulkCancelled`,{count:r}))},onError:()=>n(e(`queue.toast.bulkCancelFailed`),`error`)}),Te=q({mutationFn:e=>Z.resumeQueueAfterFailure(e),onSuccess:r=>{t.invalidateQueries({queryKey:[`queue`]}),E(null),n(e(`queue.toast.resumedAfterFailure`,{restored:r.restored,acknowledged:r.acknowledged}))},onError:()=>n(e(`queue.toast.resumeAfterFailureFailed`),`error`)}),Ee=q({mutationFn:e=>Z.createBatch(e),onSuccess:r=>{t.invalidateQueries({queryKey:[`queue`]}),S([]),ie(!1),ee(e=>({...e,[r.id]:!1})),n(e(`queue.toast.batchCreated`,{name:r.name}))},onError:()=>n(e(`queue.toast.batchCreateFailed`),`error`)}),De=q({mutationFn:e=>Z.ungroupBatch(e),onSuccess:r=>{t.invalidateQueries({queryKey:[`queue`]}),oe(null),n(e(`queue.toast.batchUngrouped`,{count:r.ungrouped_count}))},onError:()=>n(e(`queue.toast.batchUngroupFailed`),`error`)}),Oe=e=>{S(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},ke=(0,y.useMemo)(()=>{let e=new Set;return pe?.forEach(t=>{t.location&&e.add(t.location)}),de?.forEach(t=>{t.target_location&&e.add(t.target_location)}),Array.from(e).sort()},[pe,de]),Ae=(0,y.useCallback)(e=>u?e.target_location?e.target_location===u:e.printer_id?pe?.find(t=>t.id===e.printer_id)?.location===u:!1:!0,[u,pe]),je=(0,y.useMemo)(()=>{let e=de?.filter(e=>e.status===`pending`)||[];u&&(e=e.filter(Ae));let t=e=>{if(!e.scheduled_time)return 0;let t=rp(e.scheduled_time)?.getTime()??0;return t>Date.now()+4320*60*60*1e3?0:t};return H?.queue_shortest_first?[...e].sort((e,t)=>NUe(e,t,!0)):[...e].sort((e,n)=>{let r;if(N===`name`){let t=e.archive_name||e.library_file_name||``,i=n.archive_name||n.library_file_name||``;r=t.localeCompare(i)}else r=N===`printer`?(e.printer_name||``).localeCompare(n.printer_name||``):N===`time`?t(e)-t(n):e.position-n.position;return F?r:-r})},[de,N,F,Ae,u,H?.queue_shortest_first]),Me=()=>{let e=je.map(e=>e.id);x.length===e.length?S([]):S(e)},Ne=(0,y.useMemo)(()=>{let e=de?.filter(e=>e.status===`printing`)||[];return u&&(e=e.filter(Ae)),e},[de,u,Ae]),Pe=(0,y.useMemo)(()=>{let e=new Set;if(!de)return e;let t=new Set;de.forEach(e=>{e.status===`printing`&&e.printer_id&&t.add(e.printer_id)});let n=e=>e.scheduled_time?(rp(e.scheduled_time)?.getTime()??0)>Date.now():!1,r=(e,t)=>X3(e,t,H?.queue_shortest_first??!1),i=new Map;return de.filter(e=>e.status===`pending`&&e.printer_id!=null&&!e.manual_start&&!n(e)).sort(r).forEach(e=>{let t=i.get(e.printer_id)??[];t.push(e),i.set(e.printer_id,t)}),de.forEach(r=>{if(r.status===`pending`&&!r.waiting_reason&&!n(r)&&!(r.print_time_seconds==null||r.print_time_seconds<=0)&&!r.require_previous_success){if(r.printer_id==null){e.add(r.id);return}if(!t.has(r.printer_id)){if(r.manual_start){e.add(r.id);return}i.get(r.printer_id)?.[0]?.id===r.id&&e.add(r.id)}}}),e},[de,H?.queue_shortest_first]),[Fe,Ie]=(0,y.useState)(()=>Date.now()),Le=Pe.size>0;(0,y.useEffect)(()=>{if(!Le)return;Ie(Date.now());let e=setInterval(()=>Ie(Date.now()),3e4);return()=>clearInterval(e)},[Le]);let Re=(0,y.useMemo)(()=>{let e=new Set;return Ne.forEach(t=>{t.printer_id&&e.add(t.printer_id)}),Array.from(e)},[Ne]),ze=Co({queries:Re.map(e=>({queryKey:[`printerStatus`,e],queryFn:()=>Z.getPrinterStatus(e),refetchInterval:5e3}))}),Be=(0,y.useMemo)(()=>{let e={};return Re.forEach((t,n)=>{let r=ze[n];r?.data?.state&&(e[t]=r.data.state)}),e},[Re,ze]),Ve=(0,y.useMemo)(()=>{let e={};return Re.forEach((t,n)=>{let r=ze[n];r?.data&&(e[t]={progress:r.data.progress??void 0,remaining_time:r.data.remaining_time??void 0,state:r.data.state??void 0})}),e},[Re,ze]),He=(0,y.useMemo)(()=>{let e=de?.filter(e=>[`completed`,`failed`,`skipped`,`cancelled`].includes(e.status))||[];return u&&(e=e.filter(Ae)),[...e].sort((e,t)=>{let n;if(D===`name`){let r=e.archive_name||e.library_file_name||``,i=t.archive_name||t.library_file_name||``;n=r.localeCompare(i)}else n=D===`printer`?(e.printer_name||``).localeCompare(t.printer_name||``):(rp(t.completed_at||t.created_at)?.getTime()??0)-(rp(e.completed_at||e.created_at)?.getTime()??0);return k?-n:n})},[de,D,k,Ae,u]),Ue=(0,y.useMemo)(()=>je.reduce((e,t)=>e+(t.print_time_seconds||0),0),[je]),We=(0,y.useMemo)(()=>je.reduce((e,t)=>e+(t.filament_used_grams||0),0),[je]),Ge=e=>{let t=e.active.id;ne(typeof t==`number`||typeof t==`string`?t:null)},Ke=e=>{let{active:t,over:n}=e;if(ne(null),!n||t.id===n.id)return;let r,i=t.id;if(typeof i==`string`&&i.startsWith(`batch-`)){let e=Number(i.slice(6));r=je.filter(t=>t.batch_id===e).map(e=>e.id)}else{let e=i;r=x.includes(e)&&x.length>1?x.slice().sort((e,t)=>je.findIndex(t=>t.id===e)-je.findIndex(e=>e.id===t)):[e]}if(r.length===0)return;let a,o=n.id;if(typeof o==`string`&&o.startsWith(`batch-`)){let e=Number(o.slice(6));a=je.findIndex(t=>t.batch_id===e)}else a=je.findIndex(e=>e.id===o);if(a===-1)return;let s=je[a],c=je.filter(e=>!r.includes(e.id)),l=c.findIndex(e=>e.id===s.id);l===-1&&(l=a),je.findIndex(e=>e.id===r[0])je.find(t=>t.id===e)).filter(e=>!!e),...c.slice(l)].map((e,t)=>({id:e.id,position:t+1}));xe.mutate(u)},qe=(0,y.useMemo)(()=>{let t=[],n=new Set;for(let r of je)if(r.batch_id!=null){if(n.has(r.batch_id))continue;n.add(r.batch_id);let i=je.filter(e=>e.batch_id===r.batch_id);t.push({kind:`batch`,batchId:r.batch_id,batchName:r.batch_name||e(`queue.batch.defaultName`),items:i})}else t.push({kind:`item`,item:r});return t},[je,e]),Je=r(`queue:reorder`)&&N===`position`&&!H?.queue_shortest_first,Ye=e=>e.kind===`item`?[e.item.id]:e.items.map(e=>e.id),Xe=(e,t,n)=>{let r=je.filter(t=>!e.includes(t.id)),i=r.findIndex(e=>e.id===t);if(i===-1)return;n&&(i+=1);let a=e.map(e=>je.find(t=>t.id===e)).filter(e=>!!e),o=[...r.slice(0,i),...a,...r.slice(i)];xe.mutate(o.map((e,t)=>({id:e.id,position:t+1})))},Ze=(e,t)=>{if(!Je)return{};let n=Ye(e[t]);return{onMoveUp:t>0?()=>Xe(n,Ye(e[t-1])[0],!1):void 0,onMoveDown:t{let r=Ye(e[t+1]);Xe(n,r[r.length-1],!0)}:void 0}},Qe=(0,y.useMemo)(()=>{let e=[];for(let t of qe)if(t.kind===`item`)e.push(t.item.id);else if(e.push(`batch-${t.batchId}`),!(V[t.batchId]??!0))for(let n of t.items)e.push(n.id);return e},[qe,V]),$e=(0,y.useMemo)(()=>x.length<2?!1:x.every(e=>{let t=je.find(t=>t.id===e);return t&&t.batch_id==null}),[x,je]),et=e=>{ee(t=>({...t,[e]:!(t[e]??!0)}))},tt=(0,y.useMemo)(()=>{let t=new Map,n=t=>{if(t.printer_id)return{key:`printer:${t.printer_id}`,label:t.printer_name||`Printer #${t.printer_id}`,printerId:t.printer_id,targetModel:null,isUnassigned:!1};if((t.variants?.length??0)>1){let n=t.variants.map(e=>e.target_model).join(` / `);return{key:`models:${n}`,label:`${e(`queue.filter.any`)} ${n}`,printerId:null,targetModel:null,isUnassigned:!1}}return t.target_model?{key:`model:${t.target_model}`,label:`${e(`queue.filter.any`)} ${t.target_model}`,printerId:null,targetModel:t.target_model,isUnassigned:!1}:{key:`unassigned`,label:e(`queue.filter.unassigned`),printerId:null,targetModel:null,isUnassigned:!0}};for(let e of qe){let r=e.kind===`item`?e.item:e.items[0];if(!r)continue;let i=n(r);t.has(i.key)||t.set(i.key,{...i,rows:[]}),t.get(i.key).rows.push(e)}return Array.from(t.values()).sort((e,t)=>e.isUnassigned&&!t.isUnassigned?1:!e.isUnassigned&&t.isUnassigned?-1:e.label.localeCompare(t.label))},[qe,e]),nt=(0,y.useMemo)(()=>{let e=new Map;return de?.forEach(t=>{if(t.status===`skipped`&&t.error_message===`Previous print failed or was aborted`&&t.printer_id){let n=e.get(t.printer_id);n?n.count+=1:e.set(t.printer_id,{name:t.printer_name||`Printer #${t.printer_id}`,count:1})}}),Array.from(e.entries()).map(([e,{name:t,count:n}])=>({printerId:e,printerName:t,skippedCount:n})).sort((e,t)=>e.printerName.localeCompare(t.printerName))},[de]),rt=e=>{let t=0,n=0,r=0;for(let i of e){let e=i.kind===`item`?[i.item]:i.items;for(let i of e)t+=1,n+=i.print_time_seconds||0,r+=i.filament_used_grams||0}return{count:t,time:n,weight:r}};return(0,G.jsxs)(`div`,{className:`p-4 md:p-8`,children:[(0,G.jsx)(`div`,{className:`flex items-center justify-between 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)(Qc,{className:`w-7 h-7 text-bambu-green`}),e(`queue.title`)]}),(0,G.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:e(`queue.subtitle`)})]})}),(0,G.jsx)(`div`,{className:`flex gap-1 border-b border-bambu-dark-tertiary mb-6 overflow-x-auto`,children:[{id:`queue`,label:e(`queue.tabs.queue`),icon:js,count:je.length+Ne.length},{id:`batches`,label:e(`queue.tabs.batches`),icon:Cl,count:ue},{id:`history`,label:e(`queue.tabs.history`),icon:Qc,count:He.length},{id:`timeline`,label:e(`queue.tabs.timeline`),icon:ds,count:null},{id:`pipelines`,label:e(`queue.tabs.pipelines`),icon:ed,count:null}].map(({id:e,label:t,icon:n,count:r})=>(0,G.jsxs)(`button`,{onClick:()=>R(e),className:`px-4 py-2.5 text-sm flex items-center gap-2 border-b-2 -mb-px transition-colors whitespace-nowrap ${L===e?`text-white border-bambu-green font-medium`:`text-bambu-gray border-transparent hover:text-white`}`,children:[(0,G.jsx)(n,{className:`w-4 h-4`}),t,r!==null&&r>0&&(0,G.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded-full ${L===e?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark-tertiary text-bambu-gray`}`,children:r})]},e))}),L!==`pipelines`&&L!==`batches`&&(0,G.jsx)(jUe,{activeCount:Ne.length,pendingCount:je.length,totalTime:Ue,totalWeight:We,historyCount:He.length,t:e}),L===`queue`&&nt.length>0&&r(`queue:update_all`)&&(0,G.jsx)(`div`,{className:`mb-4 space-y-2`,children:nt.map(({printerId:t,printerName:n,skippedCount:r})=>(0,G.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-3 bg-orange-50 dark:bg-orange-500/10 border border-orange-300 dark:border-orange-500/30 rounded-lg`,children:[(0,G.jsx)(ys,{className:`w-5 h-5 text-orange-600 dark:text-orange-400 flex-shrink-0`}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`div`,{className:`text-sm text-orange-800 dark:text-orange-200`,children:e(`queue.resumeAfterFailure.banner`,{printer:n,count:r})}),(0,G.jsx)(`div`,{className:`text-xs text-orange-800/80 dark:text-orange-200/70 mt-0.5`,children:e(`queue.resumeAfterFailure.bannerHint`)})]}),(0,G.jsxs)(`button`,{onClick:()=>E({printerId:t,printerName:n,skippedCount:r}),className:`flex items-center gap-1.5 px-3 py-1.5 bg-orange-100 dark:bg-orange-500/20 hover:bg-orange-200 dark:hover:bg-orange-500/30 text-orange-900 dark:text-orange-100 text-sm rounded-md border border-orange-300 dark:border-orange-500/40 transition-colors flex-shrink-0`,children:[(0,G.jsx)(Ts,{className:`w-4 h-4`}),e(`queue.resumeAfterFailure.button`)]})]},t))}),L!==`pipelines`&&L!==`batches`&&(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 sm:gap-4 mb-6`,children:[(0,G.jsxs)(`select`,{className:`px-2 sm:px-3 py-2 text-sm sm:text-base bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none min-w-0 flex-1 sm:flex-none`,value:o===-1?`unassigned`:o||``,onChange:e=>{let t=e.target.value;s(t===`unassigned`?-1:t===``?null:Number(t))},children:[(0,G.jsx)(`option`,{value:``,children:e(`queue.filter.allPrinters`)}),(0,G.jsx)(`option`,{value:`unassigned`,children:e(`queue.filter.unassigned`)}),pe?.map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),(0,G.jsxs)(`select`,{className:`px-2 sm:px-3 py-2 text-sm sm:text-base bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none min-w-0 flex-1 sm:flex-none`,value:c,onChange:e=>l(e.target.value),children:[(0,G.jsx)(`option`,{value:``,children:e(`queue.filter.allStatus`)}),(0,G.jsx)(`option`,{value:`pending`,children:e(`queue.status.pending`)}),(0,G.jsx)(`option`,{value:`printing`,children:e(`queue.status.printing`)}),(0,G.jsx)(`option`,{value:`completed`,children:e(`queue.status.completed`)}),(0,G.jsx)(`option`,{value:`failed`,children:e(`queue.status.failed`)}),(0,G.jsx)(`option`,{value:`skipped`,children:e(`queue.status.skipped`)}),(0,G.jsx)(`option`,{value:`cancelled`,children:e(`queue.status.cancelled`)})]}),ke.length>0&&(0,G.jsxs)(`select`,{className:`px-2 sm:px-3 py-2 text-sm sm:text-base bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none min-w-0 flex-1 sm:flex-none`,value:u,onChange:e=>d(e.target.value),children:[(0,G.jsx)(`option`,{value:``,children:e(`queue.filter.allLocations`)}),ke.map(e=>(0,G.jsx)(`option`,{value:e,children:e},e))]}),(0,G.jsx)(`div`,{className:`hidden sm:block flex-1`}),L===`history`&&He.length>0&&(0,G.jsxs)(Q,{className:`w-full sm:w-auto`,variant:`secondary`,size:`sm`,onClick:()=>p(!0),disabled:!r(`queue:delete_all`),title:r(`queue:delete_all`)?void 0:e(`queue.permissions.noClearHistory`),children:[(0,G.jsx)(Pu,{className:`w-4 h-4`}),e(`queue.clearHistory`)]})]}),L===`queue`&&(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 mb-6`,children:[(0,G.jsxs)(`div`,{className:`inline-flex items-center bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg p-0.5`,children:[(0,G.jsxs)(`button`,{className:`px-3 py-1.5 text-xs sm:text-sm rounded-md transition-colors flex items-center gap-1.5 ${z===`position`?`bg-bambu-dark-tertiary text-white`:`text-bambu-gray hover:text-white`}`,onClick:()=>B(`position`),title:e(`queue.layout.flatList`),children:[(0,G.jsx)(el,{className:`w-3.5 h-3.5`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`queue.layout.flatList`)})]}),(0,G.jsxs)(`button`,{className:`px-3 py-1.5 text-xs sm:text-sm rounded-md transition-colors flex items-center gap-1.5 ${z===`printer`?`bg-bambu-dark-tertiary text-white`:`text-bambu-gray hover:text-white`}`,onClick:()=>B(`printer`),title:e(`queue.layout.groupByPrinter`),children:[(0,G.jsx)(Rl,{className:`w-3.5 h-3.5`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`queue.layout.byPrinter`)})]})]}),(0,G.jsxs)(`button`,{onClick:()=>{let e=!(H?.queue_shortest_first??!1);me.mutate(e)},className:`flex items-center gap-1 px-2 py-1.5 text-xs rounded-lg border transition-colors ${H?.queue_shortest_first?`bg-bambu-green/20 border-bambu-green text-bambu-green`:`bg-bambu-dark-secondary border-bambu-dark-tertiary text-bambu-gray hover:text-white hover:border-bambu-gray`}`,title:e(`queue.sjf.tooltip`,`Shortest Job First — scheduler prioritizes shorter prints`),children:[(0,G.jsx)(hu,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`queue.sjf.label`,`SJF`)}),(0,G.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full ${H?.queue_shortest_first?`bg-bambu-green`:`bg-bambu-gray`}`})]})]}),L===`pipelines`?(0,G.jsx)(EUe,{}):L===`batches`?(0,G.jsx)(zUe,{hasPermission:r,t:e}):fe?(0,G.jsx)(`div`,{className:`text-center py-12 text-bambu-gray`,children:e(`common.loading`)}):de?.length===0?(0,G.jsxs)(zd,{className:`p-12 text-center border-dashed`,children:[(0,G.jsx)(as,{className:`w-16 h-16 text-bambu-gray mx-auto mb-4 opacity-50`}),(0,G.jsx)(`h3`,{className:`text-xl font-medium text-white mb-2`,children:e(`queue.empty.title`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray max-w-md mx-auto`,children:e(`queue.empty.description`)})]}):L===`timeline`?(0,G.jsx)(RUe,{queueItems:de||[],printers:pe||[],printerStatuses:Ve,sjfEnabled:H?.queue_shortest_first??!1,onItemClick:e=>{[`completed`,`failed`,`skipped`,`cancelled`].includes(e.status)?_(e):e.status===`pending`?h(e):e.status===`printing`&&b({type:`stop`,item:e})},t:e}):L===`history`?(0,G.jsx)(GUe,{items:He,collapsed:!1,visibleCount:j,onShowMore:()=>M(e=>e+c6),sortBy:D,sortAsc:k,onSortByChange:O,onSortAscToggle:()=>A(!k),onRemove:e=>b({type:`remove`,item:e}),onRequeue:_,timeFormat:ce,batchCollapsed:V,toggleBatchCollapsed:et,hasPermission:r,canModify:a,t:e}):(0,G.jsxs)(`div`,{className:`space-y-6 sm:space-y-8`,children:[Ne.length>0&&(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`h2`,{className:`text-base sm:text-lg font-semibold text-white mb-3 sm:mb-4 flex items-center gap-2`,children:[(0,G.jsx)(`div`,{className:`w-2 h-2 rounded-full bg-blue-400 animate-pulse`}),e(`queue.sections.currentlyPrinting`)]}),(0,G.jsx)(`div`,{className:`space-y-2 sm:space-y-3`,children:Ne.map(t=>(0,G.jsx)(o6,{item:t,onEdit:()=>{},onCancel:()=>{},onRemove:()=>{},onStop:()=>b({type:`stop`,item:t}),onRequeue:()=>{},onStart:()=>{},timeFormat:ce,hasPermission:r,canModify:a,printerState:t.printer_id?Be[t.printer_id]:null,t:e},t.id))})]}),je.length>0&&(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2 mb-3 sm:mb-4`,children:[(0,G.jsxs)(`h2`,{className:`text-base sm:text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(js,{className:`w-4 h-4 sm:w-5 sm:h-5 text-yellow-600 dark:text-yellow-400`}),e(`queue.sections.queued`),(0,G.jsxs)(`span`,{className:`text-xs sm:text-sm font-normal text-bambu-gray`,children:[`(`,e(`queue.itemCount`,{count:je.length}),`)`]}),(0,G.jsx)(`span`,{className:`hidden sm:inline text-xs text-bambu-gray ml-2`,title:e(`queue.reorderHint`),children:e(`queue.dragToReorder`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`select`,{className:`px-2 sm:px-3 py-1.5 text-xs sm:text-sm bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,value:N,onChange:e=>P(e.target.value),children:[(0,G.jsx)(`option`,{value:`position`,children:e(`queue.sort.byPosition`)}),(0,G.jsx)(`option`,{value:`name`,children:e(`queue.sort.byName`)}),(0,G.jsx)(`option`,{value:`printer`,children:e(`queue.sort.byPrinter`)}),(0,G.jsx)(`option`,{value:`time`,children:e(`queue.sort.bySchedule`)})]}),(0,G.jsx)(Q,{variant:`ghost`,size:`sm`,onClick:()=>I(!F),title:e(F?`common.ascending`:`common.descending`),className:`px-2`,children:F?(0,G.jsx)(Ho,{className:`w-4 h-4`}):(0,G.jsx)(Io,{className:`w-4 h-4`})})]})]}),(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 sm:gap-3 mb-3 sm:mb-4 p-2 sm:p-3 bg-bambu-dark rounded-lg`,children:[(0,G.jsxs)(Q,{variant:`ghost`,size:`sm`,onClick:Me,className:`flex items-center gap-1.5 sm:gap-2 text-xs sm:text-sm`,children:[x.length===je.length&&je.length>0?(0,G.jsx)(vu,{className:`w-4 h-4 text-bambu-green`}):(0,G.jsx)(bu,{className:`w-4 h-4`}),x.length===je.length&&je.length>0?e(`queue.bulkEdit.deselectAll`):e(`queue.bulkEdit.selectAll`)]}),x.length>0&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`span`,{className:`text-xs sm:text-sm text-bambu-gray`,children:e(`queue.bulkEdit.selected`,{count:x.length})}),(0,G.jsx)(`div`,{className:`hidden sm:block h-4 w-px bg-bambu-dark-tertiary`}),$e&&(0,G.jsxs)(Q,{variant:`ghost`,size:`sm`,onClick:()=>ie(!0),className:`flex items-center gap-1.5 sm:gap-2 text-xs sm:text-sm text-cyan-700 dark:text-cyan-300 hover:text-cyan-900 dark:hover:text-cyan-200`,title:e(`queue.batch.groupAsBatch`),children:[(0,G.jsx)(Cl,{className:`w-3.5 h-3.5 sm:w-4 sm:h-4`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`queue.batch.groupAsBatch`)})]}),(0,G.jsxs)(Q,{variant:`ghost`,size:`sm`,onClick:()=>w(!0),className:`flex items-center gap-1.5 sm:gap-2 text-xs sm:text-sm text-bambu-green hover:text-bambu-green-light`,disabled:!i(`queue:update_own`,`queue:update_all`),title:i(`queue:update_own`,`queue:update_all`)?e(`queue.bulkEdit.editSelected`):e(`queue.permissions.noEditItems`),children:[(0,G.jsx)(Al,{className:`w-3.5 h-3.5 sm:w-4 sm:h-4`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`queue.bulkEdit.editSelected`)})]}),(0,G.jsxs)(Q,{variant:`ghost`,size:`sm`,onClick:()=>we.mutate(x),className:`flex items-center gap-1.5 sm:gap-2 text-xs sm:text-sm text-red-600 dark:text-red-400 hover:text-red-700 dark:hover:text-red-300`,disabled:we.isPending||!i(`queue:delete_own`,`queue:delete_all`),title:i(`queue:delete_own`,`queue:delete_all`)?e(`queue.bulkEdit.cancelSelected`):e(`queue.permissions.noCancelItems`),children:[(0,G.jsx)(nd,{className:`w-3.5 h-3.5 sm:w-4 sm:h-4`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`queue.bulkEdit.cancelSelected`)})]})]})]}),(0,G.jsxs)(k3,{sensors:se,collisionDetection:M4,onDragStart:Ge,onDragEnd:Ke,children:[(0,G.jsx)(z3,{items:Qe,strategy:mUe,children:z===`position`?(0,G.jsx)(`div`,{className:`space-y-2 sm:space-y-3`,children:qe.map((t,n)=>(0,G.jsx)(s6,{row:t,collapsed:t.kind===`batch`?V[t.batchId]??!0:!1,onToggleBatch:t.kind===`batch`?()=>et(t.batchId):void 0,onUngroup:t.kind===`batch`?()=>oe(t.batchId):void 0,setEditItem:h,setConfirmAction:b,startMutation:be,selectedItems:x,handleToggleSelect:Oe,timeFormat:ce,hasPermission:r,canModify:a,t:e,etaEligibleIds:Pe,etaNow:Fe,aggregateForRows:rt,...Ze(qe,n),onMoveBlock:Je?Xe:void 0},t.kind===`item`?`item-${t.item.id}`:`batch-${t.batchId}`))}):(0,G.jsx)(`div`,{className:`space-y-4`,children:tt.map(t=>{let n=rt(t.rows);return(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3 px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-t-lg`,children:[(0,G.jsx)(Rl,{className:`w-4 h-4 ${t.isUnassigned?`text-orange-600 dark:text-orange-400`:t.targetModel?`text-blue-600 dark:text-blue-400`:`text-bambu-green`}`}),(0,G.jsx)(`span`,{className:`font-semibold text-white text-sm`,children:t.label}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray flex flex-wrap gap-x-3`,children:[(0,G.jsx)(`span`,{children:e(`queue.itemCount`,{count:n.count})}),n.time>0&&(0,G.jsx)(`span`,{children:lp(n.time)}),n.weight>0&&(0,G.jsx)(`span`,{children:r6(n.weight)})]})]}),(0,G.jsx)(`div`,{className:`bg-bambu-dark/40 border border-t-0 border-bambu-dark-tertiary rounded-b-lg p-2 space-y-2`,children:t.rows.map((n,i)=>(0,G.jsx)(s6,{row:n,collapsed:n.kind===`batch`?V[n.batchId]??!0:!1,onToggleBatch:n.kind===`batch`?()=>et(n.batchId):void 0,onUngroup:n.kind===`batch`?()=>oe(n.batchId):void 0,setEditItem:h,setConfirmAction:b,startMutation:be,selectedItems:x,handleToggleSelect:Oe,timeFormat:ce,hasPermission:r,canModify:a,t:e,etaEligibleIds:Pe,etaNow:Fe,aggregateForRows:rt,...Ze(t.rows,i),onMoveBlock:Je?Xe:void 0},n.kind===`item`?`item-${n.item.id}`:`batch-${n.batchId}`))})]},t.key)})})}),(0,G.jsx)(uUe,{children:(()=>{if(te===null)return null;if(typeof te==`string`&&te.startsWith(`batch-`)){let t=Number(te.slice(6)),n=je.filter(e=>e.batch_id===t);if(n.length===0)return null;let r=n[0].batch_name||e(`queue.batch.defaultName`);return(0,G.jsxs)(`div`,{className:`flex items-center gap-3 px-3 py-2 bg-bambu-dark-secondary border-2 border-cyan-400 rounded-lg shadow-2xl`,children:[(0,G.jsx)(Cl,{className:`w-4 h-4 text-cyan-700 dark:text-cyan-300`}),(0,G.jsx)(`span`,{className:`text-sm text-white font-medium`,children:e(`queue.dragGhost.batch`,{defaultValue:`{{name}} ({{count}} copies)`,name:r,count:n.length})})]})}return typeof te==`number`&&x.includes(te)&&x.length>1?(0,G.jsxs)(`div`,{className:`flex items-center gap-3 px-3 py-2 bg-bambu-dark-secondary border-2 border-cyan-400 rounded-lg shadow-2xl`,children:[(0,G.jsx)(Cl,{className:`w-4 h-4 text-cyan-700 dark:text-cyan-300`}),(0,G.jsx)(`span`,{className:`text-sm text-white font-medium`,children:e(`queue.dragGhost.multiCount`,{count:x.length})})]}):null})()})]})]})]}),m&&(0,G.jsx)(zU,{mode:`edit-queue-item`,archiveId:m.archive_id??void 0,libraryFileId:m.library_file_id??void 0,archiveName:jT(m,t=>e(`common.plusNMore`,{count:t})),queueItem:m,onClose:()=>h(null)}),g&&(0,G.jsx)(zU,{mode:`create`,archiveId:g.archive_id??void 0,libraryFileId:g.library_file_id??void 0,archiveName:jT(g,t=>e(`common.plusNMore`,{count:t})),onClose:()=>_(null)}),ve&&(0,G.jsx)(of,{title:e(`queue.filamentShort.confirmTitle`),message:e(`queue.filamentShort.confirmIntro`)+` `+ve.deficit.map(t=>e(`queue.filamentShort.lineItem`,{slot:t.slot_id,required:Math.round(t.required_grams),remaining:t.remaining_grams==null?e(`queue.filamentShort.unknown`):Math.round(t.remaining_grams)})).join(` -`),confirmText:e(`queue.filamentShort.printAnyway`),variant:`warning`,onConfirm:()=>{be.mutate({id:ve.itemId,skipFilamentCheck:!0})},onCancel:()=>ye(null)}),v&&(0,G.jsx)(of,{title:v.type===`cancel`?e(`queue.confirm.cancelTitle`):v.type===`stop`?e(`queue.confirm.stopTitle`):e(`queue.confirm.removeTitle`),message:v.type===`cancel`?e(`queue.confirm.cancelMessage`,{name:v.item.archive_name||v.item.library_file_name||e(`queue.confirm.thisPrint`)}):v.type===`stop`?e(`queue.confirm.stopMessage`,{name:v.item.archive_name||v.item.library_file_name||e(`queue.confirm.thisPrint`)}):e(`queue.confirm.removeMessage`,{name:v.item.archive_name||v.item.library_file_name||e(`queue.confirm.thisItem`)}),confirmText:v.type===`cancel`?e(`queue.confirm.cancelButton`):v.type===`stop`?e(`queue.confirm.stopButton`):e(`common.remove`),variant:`danger`,onConfirm:()=>{v.type===`cancel`?he.mutate(v.item.id):v.type===`stop`?_e.mutate(v.item.id):ge.mutate(v.item.id),b(null)},onCancel:()=>b(null)}),T&&(0,G.jsx)(of,{title:e(`queue.resumeAfterFailure.confirmTitle`),message:e(`queue.resumeAfterFailure.confirmMessage`,{printer:T.printerName,count:T.skippedCount}),confirmText:e(`queue.resumeAfterFailure.button`),variant:`warning`,onConfirm:()=>Te.mutate(T.printerId),onCancel:()=>E(null)}),f&&(0,G.jsx)(of,{title:e(`queue.confirm.clearHistoryTitle`),message:e(`queue.confirm.clearHistoryMessage`,{count:He.length}),confirmText:e(`queue.clearHistory`),variant:`danger`,onConfirm:()=>{Se.mutate(),p(!1)},onCancel:()=>p(!1)}),C&&(0,G.jsx)(HUe,{selectedCount:x.length,printers:pe?.map(e=>({id:e.id,name:e.name,nozzle_count:e.nozzle_count}))||[],onSave:e=>{Object.keys(e).length>0&&Ce.mutate({item_ids:x,...e})},onClose:()=>w(!1),isSaving:Ce.isPending,canControlPrinter:r(`printers:control`),hasGcodeSnippets:!!H?.gcode_snippets,t:e}),re&&(0,G.jsx)(KUe,{itemCount:x.length,isSaving:Ee.isPending,defaultName:(()=>{let t=je.find(e=>x.includes(e.id)),n=(t?.archive_name||t?.library_file_name||``).replace(/\.gcode\.3mf$/i,``).replace(/\.3mf$/i,``);return n?`${n}`:e(`queue.batch.defaultName`)})(),onSave:e=>Ee.mutate({name:e,item_ids:x}),onClose:()=>ie(!1),t:e}),ae!==null&&(0,G.jsx)(of,{title:e(`queue.batch.ungroupConfirmTitle`),message:e(`queue.batch.ungroupConfirmMessage`),confirmText:e(`queue.batch.ungroup`),variant:`warning`,onConfirm:()=>De.mutate(ae),onCancel:()=>oe(null)})]})}function KUe({itemCount:e,defaultName:t,isSaving:n,onSave:r,onClose:i,t:a}){let[o,s]=(0,y.useState)(t);return(0,G.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-4`,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl p-6 w-full max-w-md`,children:[(0,G.jsxs)(`h3`,{className:`text-lg font-semibold text-white mb-2 flex items-center gap-2`,children:[(0,G.jsx)(Cl,{className:`w-5 h-5 text-cyan-700 dark:text-cyan-300`}),a(`queue.batch.groupAsBatch`)]}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4`,children:a(`queue.batch.groupAsBatchDescription`,{count:e})}),(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:a(`queue.batch.nameLabel`)}),(0,G.jsx)(`input`,{type:`text`,autoFocus:!0,value:o,onChange:e=>s(e.target.value),placeholder:a(`queue.batch.namePlaceholder`),maxLength:120,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none mb-5`}),(0,G.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,G.jsx)(Q,{variant:`ghost`,size:`sm`,onClick:i,disabled:n,children:a(`common.cancel`)}),(0,G.jsx)(Q,{variant:`primary`,size:`sm`,onClick:()=>{let e=o.trim();e&&r(e)},disabled:n||!o.trim(),children:a(n?`common.saving`:`queue.batch.create`)})]})]})})}function qUe({printDates:e,months:t=3}){let n=(0,y.useRef)(null),[r,i]=(0,y.useState)(0);(0,y.useEffect)(()=>{let e=n.current;if(!e)return;let t=new ResizeObserver(e=>{i(e[0]?.contentRect.width||0)});return t.observe(e),()=>t.disconnect()},[]);let{weeks:a,monthLabels:o,printCounts:s}=(0,y.useMemo)(()=>{let n={};e.forEach(e=>{let t=pp(e);t&&(n[t]=(n[t]||0)+1)});let r=new Date,i=new Date(r);i.setMonth(i.getMonth()-t),i.setDate(i.getDate()-i.getDay());let a=[],o=[],s=[],c=-1,l=new Date(i),u=0;for(;l<=r;)l.getDay()===0&&s.length>0&&(a.push(s),s=[],u++),l.getMonth()!==c&&(o.push({month:l.toLocaleDateString(`en-US`,{month:`short`}),weekIndex:u}),c=l.getMonth()),s.push(new Date(l)),l.setDate(l.getDate()+1);return s.length>0&&a.push(s),{weeks:a,monthLabels:o,printCounts:n}},[e,t]),c=Math.max(1,...Object.values(s)),l=e=>{if(e===0)return`bg-bambu-dark`;let t=e/c;return t<=.25?`bg-bambu-green/30`:t<=.5?`bg-bambu-green/50`:t<=.75?`bg-bambu-green/75`:`bg-bambu-green`},u=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`],d=a.length,f=r-32-16,p=d>0?Math.floor((f-(d-1)*2)/d):12,m=Math.max(8,Math.min(20,p)),h=m<=10?10:12;return(0,G.jsx)(`div`,{ref:n,className:`w-full flex justify-center`,children:r>0&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`div`,{className:`flex mb-1`,style:{marginLeft:36},children:o.map(({month:e,weekIndex:t},n)=>(0,G.jsx)(`div`,{className:`text-bambu-gray`,style:{fontSize:h,marginLeft:n===0?0:`${(t-(o[n-1]?.weekIndex||0))*(m+2)-24}px`},children:e},n))}),(0,G.jsxs)(`div`,{className:`flex`,style:{gap:2},children:[(0,G.jsx)(`div`,{className:`flex flex-col`,style:{gap:2,marginRight:4,width:32},children:u.map((e,t)=>(0,G.jsx)(`div`,{className:`text-bambu-gray flex items-center`,style:{width:32,height:m,fontSize:h,visibility:t%2==1?`visible`:`hidden`},children:e},e))}),a.map((e,t)=>(0,G.jsx)(`div`,{className:`flex flex-col`,style:{gap:2},children:[0,1,2,3,4,5,6].map(t=>{let n=e.find(e=>e.getDay()===t);if(!n)return(0,G.jsx)(`div`,{style:{width:m,height:m}},t);let r=pp(n),i=s[r]||0,a=r===pp(new Date);return(0,G.jsx)(`div`,{className:`rounded-sm ${l(i)} ${a?`ring-1 ring-white`:``}`,style:{width:m,height:m},title:`${n.toLocaleDateString()}: ${i} print${i===1?``:`s`}`},t)})},t))]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mt-3 text-bambu-gray`,style:{fontSize:h},children:[(0,G.jsx)(`span`,{children:`Less`}),(0,G.jsxs)(`div`,{className:`flex`,style:{gap:2},children:[(0,G.jsx)(`div`,{className:`rounded-sm bg-bambu-dark`,style:{width:m,height:m}}),(0,G.jsx)(`div`,{className:`rounded-sm bg-bambu-green/30`,style:{width:m,height:m}}),(0,G.jsx)(`div`,{className:`rounded-sm bg-bambu-green/50`,style:{width:m,height:m}}),(0,G.jsx)(`div`,{className:`rounded-sm bg-bambu-green/75`,style:{width:m,height:m}}),(0,G.jsx)(`div`,{className:`rounded-sm bg-bambu-green`,style:{width:m,height:m}})]}),(0,G.jsx)(`span`,{children:`More`})]})]})})}var l6=[`weight`,`prints`,`time`];function u6({value:e,onChange:t,exclude:n}){let{t:r}=U(),i={weight:r(`stats.filamentByWeight`),prints:r(`stats.filamentByPrints`),time:r(`stats.filamentByTime`)};return(0,G.jsx)(`div`,{className:`flex gap-0.5 bg-bambu-dark rounded-lg p-0.5`,children:(n?l6.filter(e=>!n.includes(e)):l6).map(n=>(0,G.jsx)(`button`,{onClick:()=>t(n),className:`px-2 py-0.5 text-xs rounded-md transition-colors ${e===n?`bg-bambu-green text-white`:`text-bambu-gray hover:text-white`}`,children:i[n]},n))})}function d6(e){if(e>=1e6){let t=e/1e6;return`${t%1==0?t.toFixed(0):t.toFixed(1)}t`}if(e>=1e3){let t=e/1e3;return`${t%1==0?t.toFixed(0):t.toFixed(1)}kg`}return`${Math.round(e)}g`}var f6=[`#00ae42`,`#3b82f6`,`#f59e0b`,`#ef4444`,`#8b5cf6`,`#ec4899`,`#14b8a6`,`#f97316`],JUe=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`],p6=[`12am`,`1am`,`2am`,`3am`,`4am`,`5am`,`6am`,`7am`,`8am`,`9am`,`10am`,`11am`,`12pm`,`1pm`,`2pm`,`3pm`,`4pm`,`5pm`,`6pm`,`7pm`,`8pm`,`9pm`,`10pm`,`11pm`];function YUe({archives:e,currency:t=`$`,dateFrom:n,dateTo:r}){let{t:i}=U(),[a,o]=(0,y.useState)(`weight`),[s,c]=(0,y.useState)(`weight`),l=(0,y.useMemo)(()=>{let t=new Map;return e.forEach(e=>{let n=rp(e.completed_at||e.created_at)||new Date,r=`${n.getFullYear()}-${String(n.getMonth()+1).padStart(2,`0`)}-${String(n.getDate()).padStart(2,`0`)}`,i=t.get(r)||{date:r,filament:0,cost:0,energy:0,prints:0};i.filament+=e.filament_used_grams||0,i.cost+=e.cost||0,i.energy+=e.energy_kwh||0,i.prints+=e.quantity??1,t.set(r,i)}),Array.from(t.values()).sort((e,t)=>e.date.localeCompare(t.date)).map(e=>({...e,dateLabel:new Date(e.date).toLocaleDateString(`en-US`,{month:`short`,day:`numeric`})}))},[e]),u=(0,y.useMemo)(()=>{if(n&&r)return Math.max((new Date(r).getTime()-new Date(n).getTime())/864e5,0)+1;if(n)return Math.max((Date.now()-new Date(n).getTime())/864e5,0)+1;if(e.length<2)return 0;let t=e.map(e=>new Date(e.completed_at||e.created_at).getTime());return(Math.max(...t)-Math.min(...t))/864e5},[e,n,r]),d=(0,y.useMemo)(()=>{if(u>7)return[];let t=new Map,n=u>1;return e.forEach(e=>{let n=rp(e.completed_at||e.created_at)||new Date,r=n.getHours(),i=`${n.getFullYear()}-${String(n.getMonth()+1).padStart(2,`0`)}-${String(n.getDate()).padStart(2,`0`)}T${String(r).padStart(2,`0`)}`,a=t.get(i)||{date:i,filament:0,cost:0,energy:0,prints:0};a.filament+=e.filament_used_grams||0,a.cost+=e.cost||0,a.energy+=e.energy_kwh||0,a.prints+=e.quantity??1,t.set(i,a)}),Array.from(t.values()).sort((e,t)=>e.date.localeCompare(t.date)).map(e=>{let[t,r]=e.date.split(`T`),i=new Date(t),a=parseInt(r,10),o=n?`${JUe[i.getDay()]} ${p6[a]}`:p6[a];return{...e,dateLabel:o}})},[e,u]),f=(0,y.useMemo)(()=>{if(l.length<=60)return l;let e=new Map;return l.forEach(t=>{let n=new Date(t.date),r=new Date(n);r.setDate(n.getDate()-n.getDay());let i=`${r.getFullYear()}-${String(r.getMonth()+1).padStart(2,`0`)}-${String(r.getDate()).padStart(2,`0`)}`,a=e.get(i)||{week:i,filament:0,cost:0,energy:0,prints:0};a.filament+=t.filament,a.cost+=t.cost,a.energy+=t.energy,a.prints+=t.prints,e.set(i,a)}),Array.from(e.values()).sort((e,t)=>e.week.localeCompare(t.week)).map(e=>({date:e.week,dateLabel:`Week of ${new Date(e.week).toLocaleDateString(`en-US`,{month:`short`,day:`numeric`})}`,...e}))},[l]),p=(0,y.useMemo)(()=>{let t=new Map;return e.forEach(e=>{let n=(e.filament_type||`Unknown`).split(`, `);n.forEach(r=>{let i=(e.filament_used_grams||0)/n.length;t.set(r,(t.get(r)||0)+i)})}),Array.from(t.entries()).map(([e,t])=>({name:e,value:Math.round(t)})).sort((e,t)=>t.value-e.value)},[e]),m=(0,y.useMemo)(()=>{let t=new Map;return e.forEach(e=>{(e.filament_type||`Unknown`).split(`, `).forEach(e=>{t.set(e,(t.get(e)||0)+1)})}),Array.from(t.entries()).map(([e,t])=>({name:e,value:t})).sort((e,t)=>t.value-e.value)},[e]),h=(0,y.useMemo)(()=>{let t=new Map;return e.forEach(e=>{let n=(e.filament_type||`Unknown`).split(`, `),r=(e.actual_time_seconds||e.print_time_seconds||0)/n.length;n.forEach(e=>{t.set(e,(t.get(e)||0)+r)})}),Array.from(t.entries()).map(([e,t])=>({name:e,value:Math.round(t/3600*10)/10})).sort((e,t)=>t.value-e.value)},[e]),g=(0,y.useMemo)(()=>{let t=new Map;return e.forEach(e=>{e.status!==`completed`&&e.status!==`failed`||(e.filament_type||`Unknown`).split(`, `).forEach(n=>{let r=t.get(n)||{completed:0,failed:0};e.status===`completed`?r.completed++:r.failed++,t.set(n,r)})}),Array.from(t.entries()).filter(([,e])=>e.completed+e.failed>=2).map(([e,t])=>{let n=t.completed+t.failed;return{name:e,rate:Math.round(t.completed/n*100),total:n}}).sort((e,t)=>t.rate-e.rate)},[e]),_=(0,y.useMemo)(()=>{let t=new Map;return e.forEach(e=>{if(!e.filament_color)return;let n=e.filament_color.split(`,`).map(e=>e.trim()),r=(e.filament_used_grams||0)/n.length;n.forEach(e=>{let n=t.get(e)||{count:0,weight:0};n.count++,n.weight+=r,t.set(e,n)})}),Array.from(t.entries()).map(([e,t])=>({hex:e,value:s===`prints`?t.count:Math.round(t.weight)})).sort((e,t)=>t.value-e.value)},[e,s]),v=a===`weight`?p:a===`prints`?m:h,b=u<=7&&d.length>0?d:f,x=e.reduce((e,t)=>e+(t.filament_used_grams||0),0),S=e.reduce((e,t)=>e+(t.cost||0),0),C=e.reduce((e,t)=>e+(t.energy_kwh||0),0),w=e.reduce((e,t)=>e+(t.energy_cost||0),0),T=e.reduce((e,t)=>e+(t.quantity??1),0),E=new Set(e.map(e=>e.printer_id).filter(Boolean)).size;return(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{className:`grid grid-cols-3 gap-2 max-[640px]:grid-cols-1`,children:[(0,G.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray leading-none`,children:i(`stats.periodFilament`)}),(0,G.jsx)(`p`,{className:`text-2xl font-bold text-white leading-none`,children:d6(x)})]}),(0,G.jsxs)(`p`,{className:`text-xs text-bambu-gray`,children:[E,` `,i(`nav.printers`).toLowerCase()]})]}),(0,G.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray leading-none`,children:i(`stats.periodCost`)}),(0,G.jsxs)(`p`,{className:`text-2xl font-bold text-white leading-none`,children:[t,S.toFixed(2)]})]}),(0,G.jsxs)(`p`,{className:`text-xs text-bambu-gray`,children:[T,` `,i(`common.prints`)]})]}),(0,G.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray leading-none`,children:i(`stats.avgPerPrint`)}),(0,G.jsxs)(`p`,{className:`text-2xl font-bold text-white leading-none`,children:[T>0?(x/T).toFixed(0):0,`g`]})]}),(0,G.jsxs)(`p`,{className:`text-xs text-bambu-gray`,children:[t,T>0?(S/T).toFixed(2):`0.00`,` avg`]})]})]}),b.length>0?(0,G.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4`,children:[(0,G.jsx)(`h4`,{className:`text-sm font-medium text-bambu-gray mb-4`,children:i(`stats.usageOverTime`)}),(0,G.jsx)(rA,{width:`100%`,height:250,children:(0,G.jsxs)(uH,{data:b,children:[(0,G.jsx)(`defs`,{children:(0,G.jsxs)(`linearGradient`,{id:`colorFilament`,x1:`0`,y1:`0`,x2:`0`,y2:`1`,children:[(0,G.jsx)(`stop`,{offset:`5%`,stopColor:`#00ae42`,stopOpacity:.3}),(0,G.jsx)(`stop`,{offset:`95%`,stopColor:`#00ae42`,stopOpacity:0})]})}),(0,G.jsx)(WB,{strokeDasharray:`3 3`,stroke:`#3d3d3d`}),(0,G.jsx)(bV,{dataKey:`dateLabel`,stroke:`#9ca3af`,tick:{fontSize:12},interval:`preserveStartEnd`}),(0,G.jsx)(TV,{stroke:`#9ca3af`,tick:{fontSize:12},tickFormatter:e=>`${e}g`}),(0,G.jsx)(sz,{contentStyle:{backgroundColor:`#2d2d2d`,border:`1px solid #3d3d3d`,borderRadius:`8px`},labelStyle:{color:`#fff`},formatter:e=>[`${Number(e??0).toFixed(0)}g`,`Filament`]}),(0,G.jsx)(rV,{type:`monotone`,dataKey:`filament`,stroke:`#00ae42`,strokeWidth:2,fillOpacity:1,fill:`url(#colorFilament)`})]})})]}):(0,G.jsx)(`div`,{className:`bg-bambu-dark rounded-lg p-8 text-center text-bambu-gray`,children:i(`stats.noPrintDataInRange`)}),C>0&&b.length>0&&(0,G.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-4`,children:[(0,G.jsx)(`h4`,{className:`text-sm font-medium text-bambu-gray`,children:i(`stats.energyOverTime`)}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[C.toFixed(3),` kWh · `,t,w.toFixed(2)]})]}),(0,G.jsx)(rA,{width:`100%`,height:250,children:(0,G.jsxs)(uH,{data:b,children:[(0,G.jsx)(`defs`,{children:(0,G.jsxs)(`linearGradient`,{id:`colorEnergy`,x1:`0`,y1:`0`,x2:`0`,y2:`1`,children:[(0,G.jsx)(`stop`,{offset:`5%`,stopColor:`#f59e0b`,stopOpacity:.3}),(0,G.jsx)(`stop`,{offset:`95%`,stopColor:`#f59e0b`,stopOpacity:0})]})}),(0,G.jsx)(WB,{strokeDasharray:`3 3`,stroke:`#3d3d3d`}),(0,G.jsx)(bV,{dataKey:`dateLabel`,stroke:`#9ca3af`,tick:{fontSize:12},interval:`preserveStartEnd`}),(0,G.jsx)(TV,{stroke:`#9ca3af`,tick:{fontSize:12},tickFormatter:e=>`${e}kWh`}),(0,G.jsx)(sz,{contentStyle:{backgroundColor:`#2d2d2d`,border:`1px solid #3d3d3d`,borderRadius:`8px`},labelStyle:{color:`#fff`},formatter:e=>[`${Number(e??0).toFixed(3)} kWh`,i(`stats.energyUsed`)]}),(0,G.jsx)(rV,{type:`monotone`,dataKey:`energy`,stroke:`#f59e0b`,strokeWidth:2,fillOpacity:1,fill:`url(#colorEnergy)`})]})})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-3 gap-4`,children:[(0,G.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-4`,children:[(0,G.jsx)(`h4`,{className:`text-sm font-medium text-bambu-gray`,children:i(`stats.byMaterial`)}),(0,G.jsx)(u6,{value:a,onChange:o})]}),v.length>0?(0,G.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,G.jsx)(rA,{width:160,height:160,children:(0,G.jsxs)(lH,{children:[(0,G.jsx)(TB,{data:v,cx:`50%`,cy:`50%`,innerRadius:40,outerRadius:70,paddingAngle:2,dataKey:`value`,children:v.map((e,t)=>(0,G.jsx)(cz,{fill:f6[t%f6.length]},`cell-${t}`))}),(0,G.jsx)(sz,{contentStyle:{backgroundColor:`#2d2d2d`,border:`1px solid #3d3d3d`,borderRadius:`8px`},formatter:e=>[a===`weight`?d6(Number(e??0)):a===`time`?`${Number(e??0)}h`:`${e??0}`,a===`weight`?`Usage`:a===`time`?`Time`:`Prints`]})]})}),(0,G.jsx)(`div`,{className:`flex-1 space-y-2 overflow-hidden`,children:v.map((e,t)=>{let n=v.reduce((e,t)=>e+t.value,0),r=n>0?(e.value/n*100).toFixed(0):0;return(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,G.jsx)(`div`,{className:`w-3 h-3 rounded-sm flex-shrink-0`,style:{backgroundColor:f6[t%f6.length]}}),(0,G.jsx)(`span`,{className:`text-white truncate flex-1`,children:e.name}),(0,G.jsxs)(`span`,{className:`text-bambu-gray flex-shrink-0`,children:[a===`weight`?d6(e.value):a===`time`?`${e.value}h`:e.value,` · `,r,`%`]})]},e.name)})})]}):(0,G.jsx)(`div`,{className:`h-[160px] flex items-center justify-center text-bambu-gray`,children:i(`stats.noFilamentData`)})]}),(0,G.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4`,children:[(0,G.jsx)(`h4`,{className:`text-sm font-medium text-bambu-gray mb-4`,children:i(`stats.filamentSuccess`)}),g.length>0?(0,G.jsx)(`div`,{className:`space-y-1.5`,children:g.map(e=>(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,G.jsx)(`span`,{className:`text-white truncate w-20 flex-shrink-0`,children:e.name}),(0,G.jsx)(`div`,{className:`flex-1 h-1.5 bg-bambu-dark-secondary rounded-full`,children:(0,G.jsx)(`div`,{className:`h-full rounded-full transition-all ${e.rate>=90?`bg-status-ok`:e.rate>=70?`bg-status-warning`:`bg-status-error`}`,style:{width:`${e.rate}%`}})}),(0,G.jsxs)(`span`,{className:`font-medium flex-shrink-0 tabular-nums ${e.rate>=90?`text-status-ok`:e.rate>=70?`text-status-warning`:`text-status-error`}`,children:[e.rate,`%`]}),(0,G.jsxs)(`span`,{className:`text-bambu-gray flex-shrink-0 text-xs`,children:[`(`,e.total,`)`]})]},e.name))}):(0,G.jsx)(`div`,{className:`h-[160px] flex items-center justify-center text-bambu-gray`,children:i(`stats.noArchiveData`)})]}),(0,G.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-4`,children:[(0,G.jsx)(`h4`,{className:`text-sm font-medium text-bambu-gray`,children:i(`stats.colorDistribution`)}),(0,G.jsx)(u6,{value:s,onChange:c,exclude:[`time`]})]}),_.length>0?(()=>{let e=_.reduce((e,t)=>e+t.value,0);return(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`relative mx-auto`,style:{width:160,height:160},children:[(0,G.jsx)(rA,{width:`100%`,height:`100%`,children:(0,G.jsxs)(lH,{children:[(0,G.jsx)(TB,{data:_,cx:`50%`,cy:`50%`,innerRadius:45,outerRadius:70,paddingAngle:2,dataKey:`value`,children:_.map((e,t)=>(0,G.jsx)(cz,{fill:e.hex,stroke:`#1a1a1a`,strokeWidth:1},`color-${t}`))}),(0,G.jsx)(sz,{contentStyle:{backgroundColor:`#2d2d2d`,border:`1px solid #3d3d3d`,borderRadius:`8px`},formatter:e=>[s===`weight`?d6(Number(e??0)):`${e??0}`,i(s===`weight`?`stats.filamentByWeight`:`stats.filamentByPrints`)]})]})}),(0,G.jsxs)(`div`,{className:`absolute inset-0 flex flex-col items-center justify-center`,children:[(0,G.jsx)(`span`,{className:`text-lg font-bold text-white`,children:s===`weight`?d6(e):e}),(0,G.jsxs)(`span`,{className:`text-[10px] text-bambu-gray`,children:[_.length,` `,_.length===1?`color`:`colors`]})]})]}),(0,G.jsx)(`div`,{className:`grid grid-cols-2 gap-x-3 gap-y-1 mt-2`,children:_.slice(0,8).map(t=>{let n=e>0?(t.value/e*100).toFixed(0):0;return(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 text-xs min-w-0`,children:[(0,G.jsx)(`div`,{className:`w-2.5 h-2.5 rounded-full flex-shrink-0 border border-black/20`,style:{backgroundColor:t.hex}}),(0,G.jsxs)(`span`,{className:`text-bambu-gray truncate`,children:[n,`%`]})]},t.hex)})}),_.length>8&&(0,G.jsxs)(`p`,{className:`text-[10px] text-bambu-gray mt-1 text-center`,children:[`+`,_.length-8,` more`]})]})})():(0,G.jsx)(`div`,{className:`h-[160px] flex items-center justify-center text-bambu-gray`,children:i(`stats.noColorData`)})]})]})]})}function XUe({id:e,title:t,component:n,isHidden:r,size:i,columnSpan:a,onToggleVisibility:o,onToggleSize:s}){let{attributes:c,listeners:l,setNodeRef:u,transform:d,transition:f,isDragging:p}=V3({id:e}),m={transform:y4.Transform.toString(d),transition:f,opacity:p?.5:1};return r?null:(0,G.jsxs)(`div`,{ref:u,style:{...m,gridColumn:`span ${a}`},className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary overflow-hidden ${p?`ring-2 ring-bambu-green shadow-lg`:``}`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 border-b border-bambu-dark-tertiary bg-bambu-dark/30`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`button`,{...c,...l,className:`cursor-grab active:cursor-grabbing p-1 hover:bg-bambu-dark-tertiary rounded transition-colors`,title:`Drag to reorder`,children:(0,G.jsx)(jc,{className:`w-6 h-6 md:w-4 md:h-4 text-bambu-gray`})}),(0,G.jsx)(`h3`,{className:`text-sm font-medium text-white`,children:t})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(`button`,{onClick:s,className:`p-1 hover:bg-bambu-dark-tertiary rounded transition-colors`,title:`Size: ${i===1?`1/4`:i===2?`1/2`:`Full`} - Click to cycle`,children:i===4?(0,G.jsx)(fl,{className:`w-4 h-4 text-bambu-gray hover:text-white`}):(0,G.jsx)(cl,{className:`w-4 h-4 text-bambu-gray hover:text-white`})}),(0,G.jsx)(`button`,{onClick:o,className:`p-1 hover:bg-bambu-dark-tertiary rounded transition-colors`,title:`Hide widget`,children:(0,G.jsx)(ic,{className:`w-4 h-4 text-bambu-gray hover:text-white`})})]})]}),(0,G.jsx)(`div`,{className:`p-4`,children:typeof n==`function`?n(i):n})]})}function ZUe({widgets:e,storageKey:t,columns:n=4,stackBelow:r,hideControls:i=!1,onResetLayout:a,renderControls:o}){let s=()=>{let t={};return e.forEach(e=>{t[e.id]=e.defaultSize||4}),t},[c,l]=(0,y.useState)(()=>{let n=localStorage.getItem(t);if(n)try{let e=JSON.parse(n);if(!e.sizes)e.sizes=s();else{let t=s();for(let n in t)n in e.sizes||(e.sizes[n]=t[n])}return e}catch{}return{order:e.map(e=>e.id),hidden:e.filter(e=>e.defaultVisible===!1).map(e=>e.id),sizes:s()}}),[u,d]=(0,y.useState)(!1),[f,p]=(0,y.useState)(!1);(0,y.useEffect)(()=>{if(!r)return;let e=window.matchMedia(`(max-width: ${r}px)`),t=e=>{p(e.matches)};t(e);let n=e=>t(e);return e.addEventListener?e.addEventListener(`change`,n):e.addListener(n),()=>{e.removeEventListener?e.removeEventListener(`change`,n):e.removeListener(n)}},[r]);let m=r&&f?1:n;(0,y.useEffect)(()=>{let e=()=>d(e=>!e);return window.addEventListener(`toggle-hidden-panel`,e),()=>window.removeEventListener(`toggle-hidden-panel`,e)},[]),(0,y.useEffect)(()=>{localStorage.setItem(t,JSON.stringify(c))},[c,t]),(0,y.useEffect)(()=>{let t=e.map(e=>e.id).filter(e=>!c.order.includes(e));t.length>0&&l(e=>({...e,order:[...e.order,...t]}))},[e,c.order]);let h=T4(w4(a3,{activationConstraint:{distance:8}}),w4(t3,{coordinateGetter:U3})),g=e=>{let{active:t,over:n}=e;n&&t.id!==n.id&&l(e=>{let r=e.order.indexOf(t.id),i=e.order.indexOf(n.id);return{...e,order:N3(e.order,r,i)}})},_=e=>{l(t=>({...t,hidden:t.hidden.includes(e)?t.hidden.filter(t=>t!==e):[...t.hidden,e]}))},v=e=>{l(t=>{let n=t.sizes[e]||4,r=n===1?2:n===2?4:1;return{...t,sizes:{...t.sizes,[e]:r}}})},b=()=>{l({order:e.map(e=>e.id),hidden:e.filter(e=>e.defaultVisible===!1).map(e=>e.id),sizes:s()}),a?.()},x=c.order.map(t=>e.find(e=>e.id===t)).filter(Boolean),S=x.filter(e=>!c.hidden.includes(e.id)),C=x.filter(e=>c.hidden.includes(e.id)),w=o?.({hiddenCount:C.length,showHiddenPanel:u,setShowHiddenPanel:d,resetLayout:b});return(0,G.jsxs)(`div`,{className:`space-y-4`,children:[w,!i&&!o&&(0,G.jsxs)(`div`,{className:`flex items-center justify-end gap-2`,children:[(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:b,children:[(0,G.jsx)(Wl,{className:`w-4 h-4`}),`Reset Layout`]}),C.length>0&&(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:()=>d(!u),children:[(0,G.jsx)(ac,{className:`w-4 h-4`}),C.length,` Hidden`]})]}),u&&C.length>0&&(0,G.jsxs)(`div`,{className:`p-4 bg-bambu-dark rounded-xl border border-bambu-dark-tertiary`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mb-3`,children:`Hidden widgets (click to show):`}),(0,G.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:C.map(e=>(0,G.jsxs)(`button`,{onClick:()=>_(e.id),className:`px-3 py-1.5 bg-bambu-dark-tertiary hover:bg-bambu-green/20 rounded-lg text-sm text-white transition-colors flex items-center gap-2`,children:[(0,G.jsx)(ac,{className:`w-3 h-3`}),e.title]},e.id))})]}),(0,G.jsx)(k3,{sensors:h,collisionDetection:M4,onDragEnd:g,children:(0,G.jsx)(z3,{items:S.map(e=>e.id),strategy:F3,children:(0,G.jsx)(`div`,{className:`grid gap-6`,style:{gridTemplateColumns:`repeat(${m}, minmax(0, 1fr))`},children:S.map(e=>{let t=c.sizes[e.id]||2,n=Math.min(t,m);return(0,G.jsx)(XUe,{id:e.id,title:e.title,component:e.component,isHidden:c.hidden.includes(e.id),size:t,columnSpan:n,onToggleVisibility:()=>_(e.id),onToggleSize:()=>v(e.id)},e.id)})})})}),S.length===0&&(0,G.jsxs)(`div`,{className:`text-center py-12 text-bambu-gray`,children:[(0,G.jsx)(`p`,{children:`All widgets are hidden.`}),(0,G.jsx)(Q,{className:`mt-4`,onClick:b,children:`Reset Layout`})]})]})}function QUe(e){let t=new Date,n=t.getUTCFullYear(),r=t.getUTCMonth(),i=t.getUTCDate(),a=e=>e.toISOString().split(`T`)[0],o=a(t);switch(e){case`today`:return{dateFrom:o,dateTo:o};case`this-week`:{let e=t.getUTCDay();return{dateFrom:a(new Date(Date.UTC(n,r,i-(e===0?6:e-1)))),dateTo:o}}case`this-month`:return{dateFrom:a(new Date(Date.UTC(n,r,1))),dateTo:o};case`last-7`:return{dateFrom:a(new Date(Date.UTC(n,r,i-6))),dateTo:o};case`last-30`:return{dateFrom:a(new Date(Date.UTC(n,r,i-29))),dateTo:o};case`last-90`:return{dateFrom:a(new Date(Date.UTC(n,r,i-89))),dateTo:o};case`this-year`:return{dateFrom:a(new Date(Date.UTC(n,0,1))),dateTo:o};case`all-time`:return{dateFrom:void 0,dateTo:void 0};case`custom`:return{}}}var $Ue=[`today`,`this-week`,`this-month`,`last-7`,`last-30`,`last-90`,`this-year`,`all-time`],eWe=[`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`,`Sun`],m6=[`12am`,`1am`,`2am`,`3am`,`4am`,`5am`,`6am`,`7am`,`8am`,`9am`,`10am`,`11am`,`12pm`,`1pm`,`2pm`,`3pm`,`4pm`,`5pm`,`6pm`,`7pm`,`8pm`,`9pm`,`10pm`,`11pm`],h6=[{key:`<30m`,max:1800},{key:`30m-1h`,max:3600},{key:`1-2h`,max:7200},{key:`2-4h`,max:14400},{key:`4-8h`,max:28800},{key:`8-12h`,max:43200},{key:`12-24h`,max:86400},{key:`24h+`,max:1/0}],g6={backgroundColor:`#2d2d2d`,border:`1px solid #3d3d3d`,borderRadius:`8px`};function tWe({stats:e,currency:t}){let{t:n}=U(),r=e?.energy_data_warming_up===!0,i=r?n(`stats.energyWarmingUpTooltip`):void 0;return(0,G.jsx)(`div`,{className:`grid grid-cols-2 sm:grid-cols-3 gap-4`,children:[{icon:Cl,color:`text-bambu-green`,label:n(`stats.totalPrints`),value:`${e?.total_prints||0}`},{icon:js,color:`text-blue-600 dark:text-blue-400`,label:n(`stats.printTime`),value:`${e?.total_print_time_hours?.toFixed(1)??`0`}h`},{icon:Cl,color:`text-orange-600 dark:text-orange-400`,label:n(`stats.filamentUsed`),value:d6(e?.total_filament_grams||0)},{icon:qs,color:`text-green-600 dark:text-green-400`,label:n(`stats.filamentCost`),value:`${t} ${e?.total_cost?.toFixed(2)??`0.00`}`},{icon:id,color:`text-yellow-600 dark:text-yellow-400`,label:n(`stats.energyUsed`),value:`${e?.total_energy_kwh?.toFixed(3)??`0.000`} kWh`,warning:r,tooltip:i},{icon:qs,color:`text-yellow-500`,label:n(`stats.energyCost`),value:`${t} ${e?.total_energy_cost?.toFixed(2)??`0.00`}`,warning:r,tooltip:i}].map(e=>(0,G.jsxs)(`div`,{className:`flex items-start gap-3`,title:e.tooltip,children:[(0,G.jsx)(`div`,{className:`p-2 rounded-lg bg-bambu-dark ${e.color}`,children:(0,G.jsx)(e.icon,{className:`w-5 h-5`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`p`,{className:`text-xs text-bambu-gray flex items-center gap-1`,children:[e.label,e.warning&&(0,G.jsx)(Lu,{className:`w-3 h-3 text-yellow-600 dark:text-yellow-400`,"aria-label":e.tooltip})]}),(0,G.jsx)(`p`,{className:`text-xl font-bold text-white`,children:e.value})]})]},e.label))})}function nWe({stats:e,printerMap:t,size:n=1}){let{t:r}=U(),i=(e?.successful_prints||0)+(e?.failed_prints||0),a=i?Math.round((e?.successful_prints||0)/i*100):0,o=n===1?112:n===2?128:144,s=o/2-8,c=s*2*Math.PI;return(0,G.jsxs)(`div`,{className:`flex items-center gap-6`,children:[(0,G.jsxs)(`div`,{className:`relative flex-shrink-0`,style:{width:o,height:o},children:[(0,G.jsxs)(`svg`,{className:`w-full h-full -rotate-90`,children:[(0,G.jsx)(`circle`,{cx:o/2,cy:o/2,r:s,fill:`none`,stroke:`#3d3d3d`,strokeWidth:`10`}),(0,G.jsx)(`circle`,{cx:o/2,cy:o/2,r:s,fill:`none`,stroke:`#00ae42`,strokeWidth:`10`,strokeLinecap:`round`,strokeDasharray:`${a/100*c} ${c}`})]}),(0,G.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center`,children:(0,G.jsxs)(`span`,{className:`font-bold text-white ${n>=2?`text-2xl`:`text-xl`}`,children:[a,`%`]})})]}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(xs,{className:`w-4 h-4 text-status-ok flex-shrink-0`}),(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:r(`stats.successful`)}),(0,G.jsx)(`span`,{className:`text-sm text-white font-medium`,children:e?.successful_prints||0})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Ds,{className:`w-4 h-4 text-status-error flex-shrink-0`}),(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:r(`stats.failed`)}),(0,G.jsx)(`span`,{className:`text-sm text-white font-medium`,children:e?.failed_prints||0})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Uo,{className:`w-4 h-4 text-status-warning flex-shrink-0`}),(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:r(`stats.cancelled`)}),(0,G.jsx)(`span`,{className:`text-sm text-white font-medium`,children:e?.cancelled_prints||0})]})]}),n>=2&&e?.prints_by_printer&&Object.keys(e.prints_by_printer).length>0&&(0,G.jsxs)(`div`,{className:`mt-4 pt-4 border-t border-bambu-dark-tertiary`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray font-medium mb-2`,children:r(`stats.printsByPrinter`)}),(0,G.jsx)(`div`,{className:`grid gap-x-6 gap-y-1 ${n===4?`grid-cols-3`:`grid-cols-2`}`,style:{width:`fit-content`},children:Object.entries(e.prints_by_printer).map(([e,n])=>(0,G.jsxs)(`div`,{className:`flex items-center gap-3 text-sm`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray truncate max-w-[120px]`,children:t.get(e)||`${r(`common.printer`)} ${e}`}),(0,G.jsx)(`span`,{className:`text-white font-medium`,children:n})]},e))})]})]})]})}function rWe({stats:e,printerMap:t,size:n=1}){let{t:r}=U(),i=e?.average_time_accuracy;if(i==null)return(0,G.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,G.jsx)(`p`,{className:`text-bambu-gray text-center py-4`,children:r(`stats.noTimeAccuracyData`)})});let a=(Math.min(150,Math.max(50,i))-50)/100*100,o=(e=>e>=95&&e<=105?`#00ae42`:e>105?`#3b82f6`:`#f97316`)(i),s=i-100,c=n===1?112:n===2?128:144,l=c/2-8,u=l*2*Math.PI,d=n===1?3:n===2?6:999,f=e?.time_accuracy_by_printer?Object.entries(e.time_accuracy_by_printer).slice(0,d):[];return(0,G.jsxs)(`div`,{className:`flex items-center gap-6`,children:[(0,G.jsxs)(`div`,{className:`relative flex-shrink-0`,style:{width:c,height:c},children:[(0,G.jsxs)(`svg`,{className:`w-full h-full -rotate-90`,children:[(0,G.jsx)(`circle`,{cx:c/2,cy:c/2,r:l,fill:`none`,stroke:`#3d3d3d`,strokeWidth:`10`}),(0,G.jsx)(`circle`,{cx:c/2,cy:c/2,r:l,fill:`none`,stroke:o,strokeWidth:`10`,strokeLinecap:`round`,strokeDasharray:`${a/100*u} ${u}`})]}),(0,G.jsxs)(`div`,{className:`absolute inset-0 flex flex-col items-center justify-center`,children:[(0,G.jsxs)(`span`,{className:`font-bold text-white ${n>=2?`text-2xl`:`text-xl`}`,children:[i.toFixed(0),`%`]}),(0,G.jsxs)(`span`,{className:`text-xs ${s>=0?`text-blue-700 dark:text-blue-400`:`text-orange-700 dark:text-orange-400`}`,children:[s>=0?`+`:``,s.toFixed(0),`%`]})]})]}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-bambu-gray`,children:[(0,G.jsx)(Du,{className:`w-3 h-3 flex-shrink-0`}),(0,G.jsx)(`span`,{children:r(`stats.perfectEstimate`)})]}),f.length>0&&(0,G.jsx)(`div`,{className:`mt-2 ${n===4?`grid grid-cols-3 gap-x-6 gap-y-1`:n===2?`grid grid-cols-2 gap-x-6 gap-y-1`:`space-y-1`}`,style:{width:`fit-content`},children:f.map(([e,n])=>(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-xs`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray truncate max-w-[100px]`,children:t.get(e)||`${r(`common.printer`)} ${e}`}),(0,G.jsxs)(`span`,{className:`font-medium ${n>=95&&n<=105?`text-status-ok`:n>105?`text-blue-700 dark:text-blue-400`:`text-status-warning`}`,children:[n.toFixed(0),`%`]})]},e))})]})]})}function iWe({printDates:e,dateFrom:t,dateTo:n}){let{days:r,hourlyCounts:i,maxCount:a}=(0,y.useMemo)(()=>{let r=new Date(t+`T00:00:00`),i=new Date(n+`T00:00:00`),a=[],o=e=>`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,`0`)}-${String(e.getDate()).padStart(2,`0`)}`,s=new Date(r);for(;s<=i;)a.push({key:o(s),label:s.toLocaleDateString(void 0,{weekday:`short`,month:`short`,day:`numeric`})}),s.setDate(s.getDate()+1);let c={},l=0;return e.forEach(e=>{let t=rp(e);if(!t)return;let n=`${`${t.getFullYear()}-${String(t.getMonth()+1).padStart(2,`0`)}-${String(t.getDate()).padStart(2,`0`)}`}-${t.getHours()}`;c[n]=(c[n]||0)+1,c[n]>l&&(l=c[n])}),{days:a,hourlyCounts:c,maxCount:Math.max(1,l)}},[e,t,n]),o=e=>{if(e===0)return`bg-bambu-dark`;let t=e/a;return t<=.25?`bg-bambu-green/30`:t<=.5?`bg-bambu-green/50`:t<=.75?`bg-bambu-green/75`:`bg-bambu-green`};return(0,G.jsxs)(`div`,{className:`w-full overflow-x-auto`,children:[(0,G.jsxs)(`div`,{className:`inline-flex flex-col`,style:{gap:2},children:[(0,G.jsx)(`div`,{className:`flex`,style:{gap:2,marginLeft:84},children:m6.map((e,t)=>(0,G.jsx)(`div`,{className:`text-bambu-gray text-[10px] text-center`,style:{width:20,visibility:t%2==0?`visible`:`hidden`},children:e},t))}),r.map(e=>(0,G.jsxs)(`div`,{className:`flex items-center`,style:{gap:2},children:[(0,G.jsx)(`div`,{className:`text-bambu-gray text-[10px] flex-shrink-0 truncate`,style:{width:80},children:e.label}),Array.from({length:24},(t,n)=>{let r=i[`${e.key}-${n}`]||0;return(0,G.jsx)(`div`,{className:`rounded-sm ${o(r)}`,style:{width:20,height:20},title:`${e.label} ${m6[n]}: ${r} print${r===1?``:`s`}`},n)})]},e.key))]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mt-3 text-bambu-gray text-xs`,children:[(0,G.jsx)(`span`,{children:`Less`}),(0,G.jsxs)(`div`,{className:`flex`,style:{gap:2},children:[(0,G.jsx)(`div`,{className:`rounded-sm bg-bambu-dark`,style:{width:20,height:20}}),(0,G.jsx)(`div`,{className:`rounded-sm bg-bambu-green/30`,style:{width:20,height:20}}),(0,G.jsx)(`div`,{className:`rounded-sm bg-bambu-green/50`,style:{width:20,height:20}}),(0,G.jsx)(`div`,{className:`rounded-sm bg-bambu-green/75`,style:{width:20,height:20}}),(0,G.jsx)(`div`,{className:`rounded-sm bg-bambu-green`,style:{width:20,height:20}})]}),(0,G.jsx)(`span`,{children:`More`})]})]})}function aWe({printDates:e,size:t=2,dateFrom:n,dateTo:r}){let i=(0,y.useMemo)(()=>n&&r?Math.max((new Date(r).getTime()-new Date(n).getTime())/864e5,0)+1:n?Math.max((Date.now()-new Date(n).getTime())/864e5,0)+1:1/0,[n,r]);return i<=7&&n&&r?(0,G.jsx)(iWe,{printDates:e,dateFrom:n,dateTo:r}):(0,G.jsx)(qUe,{printDates:e,months:i===1/0?t===1?3:t===2?6:12:Math.max(1,Math.ceil(i/30))})}function oWe({stats:e,archives:t,printerMap:n}){let{t:r}=U(),[i,a]=(0,y.useState)(`weight`),[o,s]=(0,y.useState)(`weight`),c=(0,y.useMemo)(()=>{let a=new Map;return e?.prints_by_printer&&Object.entries(e.prints_by_printer).forEach(([e,t])=>{let n=a.get(e)||{prints:0,weight:0,time:0};n.prints=t,a.set(e,n)}),t.forEach(t=>{if(!t.printer_id)return;let n=String(t.printer_id),r=a.get(n)||{prints:0,weight:0,time:0};r.weight+=t.filament_used_grams||0,r.time+=t.actual_time_seconds||t.print_time_seconds||0,e?.prints_by_printer||r.prints++,a.set(n,r)}),Array.from(a.entries()).map(([e,t])=>({name:n.get(e)||`${r(`common.printer`)} ${e}`,value:i===`prints`?t.prints:i===`weight`?Math.round(t.weight):Math.round(t.time/3600*10)/10})).sort((e,t)=>t.value-e.value)},[e,t,n,i,r]),l=(0,y.useMemo)(()=>{let e=Array.from({length:24},(e,t)=>({hour:t,label:m6[t],total:0,failures:0}));return t.forEach(t=>{if(!t.started_at)return;let n=rp(t.started_at);if(!n)return;let r=n.getHours();e[r].total++,t.status===`failed`&&e[r].failures++}),e},[t]),u=(0,y.useMemo)(()=>{let e=h6.map(e=>({name:e.key,count:0}));return t.forEach(t=>{let n=t.actual_time_seconds||t.print_time_seconds;if(!(!n||n<=0)){for(let t=0;t{let e=[0,0,0,0,0,0,0],n=new Set;t.forEach(t=>{let r=rp(t.created_at)||new Date(t.created_at),i=r.getDay()-1;i<0&&(i=6),o===`prints`?e[i]++:o===`weight`?e[i]+=t.filament_used_grams||0:e[i]+=(t.actual_time_seconds||t.print_time_seconds||0)/3600;let a=new Date(r);a.setDate(r.getDate()-(r.getDay()+6)%7),n.add(`${a.getFullYear()}-${String(a.getMonth()+1).padStart(2,`0`)}-${String(a.getDate()).padStart(2,`0`)}`)});let r=Math.max(n.size,1);return eWe.map((t,n)=>({name:t,avg:Math.round(e[n]/r*10)/10}))},[t,o]),f=e=>({unit:e===`weight`?`g`:e===`time`?`h`:``,color:e===`weight`?`#00ae42`:e===`time`?`#3b82f6`:`#f59e0b`}),p=f(i),m=r(i===`weight`?`stats.filamentByWeight`:i===`time`?`stats.hours`:`common.prints`),h=f(o),g=r(o===`weight`?`stats.avgWeight`:o===`time`?`stats.avgTime`:`stats.avgPrints`);return(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,G.jsx)(`h4`,{className:`text-sm font-medium text-bambu-gray`,children:r(`stats.printsByPrinter`)}),(0,G.jsx)(u6,{value:i,onChange:a})]}),c.length>0?(0,G.jsx)(rA,{width:`100%`,height:Math.max(140,c.length*40),children:(0,G.jsxs)(iH,{data:c,layout:`vertical`,margin:{left:10},children:[(0,G.jsx)(WB,{strokeDasharray:`3 3`,stroke:`#3d3d3d`}),(0,G.jsx)(bV,{type:`number`,stroke:`#9ca3af`,tick:{fontSize:11},unit:p.unit}),(0,G.jsx)(TV,{type:`category`,dataKey:`name`,stroke:`#9ca3af`,tick:{fontSize:11},width:100}),(0,G.jsx)(sz,{contentStyle:g6,formatter:e=>[i===`weight`?d6(Number(e??0)):`${e??0}${p.unit}`,m]}),(0,G.jsx)(fV,{dataKey:`value`,fill:p.color,radius:[0,4,4,0]})]})}):(0,G.jsx)(`p`,{className:`text-bambu-gray text-center py-4`,children:r(`stats.noPrinterData`)})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-3 gap-4`,children:[(0,G.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4`,children:[(0,G.jsx)(`h4`,{className:`text-sm font-medium text-bambu-gray mb-3`,children:r(`stats.printDuration`)}),t.length>0?(0,G.jsx)(rA,{width:`100%`,height:160,children:(0,G.jsxs)(iH,{data:u,children:[(0,G.jsx)(WB,{strokeDasharray:`3 3`,stroke:`#3d3d3d`}),(0,G.jsx)(bV,{dataKey:`name`,stroke:`#9ca3af`,tick:{fontSize:11}}),(0,G.jsx)(TV,{stroke:`#9ca3af`,tick:{fontSize:11},allowDecimals:!1}),(0,G.jsx)(sz,{contentStyle:g6}),(0,G.jsx)(fV,{dataKey:`count`,name:r(`common.prints`),fill:`#00ae42`,radius:[4,4,0,0]})]})}):(0,G.jsx)(`p`,{className:`text-bambu-gray text-center py-4`,children:r(`stats.noArchiveData`)})]}),(0,G.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,G.jsx)(`h4`,{className:`text-sm font-medium text-bambu-gray`,children:r(`stats.printHabits`)}),(0,G.jsx)(u6,{value:o,onChange:s})]}),t.length>0?(0,G.jsx)(rA,{width:`100%`,height:160,children:(0,G.jsxs)(iH,{data:d,children:[(0,G.jsx)(WB,{strokeDasharray:`3 3`,stroke:`#3d3d3d`}),(0,G.jsx)(bV,{dataKey:`name`,stroke:`#9ca3af`,tick:{fontSize:11}}),(0,G.jsx)(TV,{stroke:`#9ca3af`,tick:{fontSize:11},unit:h.unit}),(0,G.jsx)(sz,{contentStyle:g6,formatter:e=>[`${e??0}${h.unit}`,g]}),(0,G.jsx)(fV,{dataKey:`avg`,fill:h.color,radius:[4,4,0,0]})]})}):(0,G.jsx)(`p`,{className:`text-bambu-gray text-center py-4`,children:r(`stats.noArchiveData`)})]}),(0,G.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4`,children:[(0,G.jsx)(`h4`,{className:`text-sm font-medium text-bambu-gray mb-3`,children:r(`stats.printTimeOfDay`)}),t.length>0?(0,G.jsx)(rA,{width:`100%`,height:160,children:(0,G.jsxs)(iH,{data:l,children:[(0,G.jsx)(WB,{strokeDasharray:`3 3`,stroke:`#3d3d3d`}),(0,G.jsx)(bV,{dataKey:`label`,stroke:`#9ca3af`,tick:{fontSize:10},interval:5}),(0,G.jsx)(TV,{stroke:`#9ca3af`,tick:{fontSize:11},allowDecimals:!1}),(0,G.jsx)(sz,{contentStyle:g6}),(0,G.jsx)(fV,{dataKey:`total`,name:r(`stats.totalPrints`),fill:`#00ae42`,radius:[2,2,0,0]}),(0,G.jsx)(fV,{dataKey:`failures`,name:r(`stats.failed`),fill:`#ef4444`,radius:[2,2,0,0]})]})}):(0,G.jsx)(`p`,{className:`text-bambu-gray text-center py-4`,children:r(`stats.noArchiveData`)})]})]})]})}function sWe({archives:e,currency:t,dateFrom:n,dateTo:r}){let{t:i}=U();return!e||e.length===0?(0,G.jsx)(`p`,{className:`text-bambu-gray text-center py-4`,children:i(`stats.noPrintData`)}):(0,G.jsx)(YUe,{archives:e,currency:t,dateFrom:n,dateTo:r})}function cWe({size:e=1,dateFrom:t,dateTo:n,createdById:r}){let{t:i}=U(),a=!!(t||n),{data:o,isLoading:s}=K({queryKey:[`failureAnalysis`,t,n,r??`all`],queryFn:()=>Z.getFailureAnalysis({...a?{dateFrom:t,dateTo:n}:{days:30},createdById:r})});if(s)return(0,G.jsx)(`div`,{className:`flex justify-center py-4`,children:(0,G.jsx)(Y,{className:`w-6 h-6 text-bambu-green animate-spin`})});if(!o||o.total_prints===0)return(0,G.jsx)(`p`,{className:`text-bambu-gray text-center py-4`,children:i(a?`stats.noPrintDataInRange`:`stats.noPrintDataLast30Days`)});let c=e===1?5:e===2?8:999,l=Object.entries(o.failures_by_reason).sort(([,e],[,t])=>t-e),u=l.slice(0,c),d=l.length>c;return(0,G.jsxs)(`div`,{className:`${e>=2?`flex gap-8`:`space-y-4`}`,children:[(0,G.jsxs)(`div`,{className:e>=2?`flex-shrink-0`:``,children:[(0,G.jsx)(`div`,{className:`flex items-center gap-4`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Lu,{className:`w-5 h-5 ${o.failure_rate>20?`text-status-error`:o.failure_rate>10?`text-status-warning`:`text-status-ok`}`}),(0,G.jsxs)(`span`,{className:`font-bold text-white ${e>=2?`text-3xl`:`text-2xl`}`,children:[o.failure_rate.toFixed(1),`%`]})]})}),(0,G.jsx)(`div`,{className:`text-sm text-bambu-gray mt-1`,children:i(`stats.failedPrintsCount`,{failed:o.failed_prints,total:o.total_prints})}),o.trend&&o.trend.length>=2&&(0,G.jsx)(`div`,{className:`${e>=2?`mt-4`:`mt-2 pt-2 border-t border-bambu-dark-tertiary`}`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,G.jsx)(Fu,{className:`w-4 h-4 ${o.trend[o.trend.length-1].failure_rate0&&(0,G.jsxs)(`div`,{className:`flex-1 ${e>=2?`border-l border-bambu-dark-tertiary pl-8`:`pt-2`}`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray font-medium mb-2`,children:i(e>=2?`stats.failureReasons`:`stats.topFailureReasons`)}),(0,G.jsx)(`div`,{className:`${e===4?`grid grid-cols-2 gap-x-6 gap-y-1`:`space-y-1`}`,children:u.map(([t,n])=>(0,G.jsxs)(`div`,{className:`flex items-center justify-between text-sm`,children:[(0,G.jsx)(`span`,{className:`text-white truncate ${e===4?`max-w-[200px]`:`max-w-[160px]`}`,children:t?i(`editArchive.failureReasons.${t}`,{defaultValue:t}):i(`common.unknown`)}),(0,G.jsx)(`span`,{className:`text-bambu-gray ml-2`,children:n})]},t))}),d&&(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-2`,children:i(`common.more`,{count:l.length-c})})]})]})}function lWe({archives:e,currency:t}){let{t:n}=U(),r=(0,y.useMemo)(()=>{let r=[];if(e.length===0)return r;let i=t=>{let n=null,r=0;return e.forEach(e=>{let i=t(e);i&&i>r&&(r=i,n=e)}),{archive:n,value:r}},a=i(e=>e.status===`completed`?e.actual_time_seconds:null);a.archive&&r.push({icon:js,iconColor:`text-blue-600 dark:text-blue-400`,label:n(`stats.longestPrint`),value:lp(a.value),detail:a.archive.print_name||null});let o=i(e=>e.filament_used_grams);o.archive&&r.push({icon:Cl,iconColor:`text-orange-600 dark:text-orange-400`,label:n(`stats.heaviestPrint`),value:d6(o.value),detail:o.archive.print_name||null});let s=i(e=>(e.cost??0)+(e.energy_cost??0));s.archive&&r.push({icon:qs,iconColor:`text-green-600 dark:text-green-400`,label:n(`stats.mostExpensivePrint`),value:`${t}${s.value.toFixed(2)}`,detail:s.archive.print_name||null});let c=new Map;e.forEach(e=>{let t=rp(e.created_at)||new Date(e.created_at),n=`${t.getFullYear()}-${String(t.getMonth()+1).padStart(2,`0`)}-${String(t.getDate()).padStart(2,`0`)}`;c.set(n,(c.get(n)||0)+1)});let l=``,u=0;c.forEach((e,t)=>{e>u&&(u=e,l=t)}),u>1&&r.push({icon:as,iconColor:`text-purple-600 dark:text-purple-400`,label:n(`stats.busiestDay`),value:`${u} ${n(`common.prints`)}`,detail:(()=>{let[e,t,n]=l.split(`-`).map(Number);return new Date(e,t-1,n).toLocaleDateString(void 0,{month:`short`,day:`numeric`,year:`numeric`})})()});let d=[...e].filter(e=>e.status===`completed`||e.status===`failed`).sort((e,t)=>new Date(t.completed_at||t.created_at).getTime()-new Date(e.completed_at||e.created_at).getTime()),f=0;for(let e of d)if(e.status===`completed`)f++;else break;return f>0&&r.push({icon:id,iconColor:`text-yellow-600 dark:text-yellow-400`,label:n(`stats.successStreak`),value:`${f}`,detail:f===1?n(`stats.streakPrint`):n(`stats.streakPrints`,{count:f})}),r},[e,t,n]);return r.length===0?(0,G.jsx)(`p`,{className:`text-bambu-gray text-center py-4`,children:n(`stats.noArchiveData`)}):(0,G.jsx)(`div`,{className:`space-y-3`,children:r.map((e,t)=>(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`p-1.5 rounded-lg bg-bambu-dark ${e.iconColor}`,children:(0,G.jsx)(e.icon,{className:`w-4 h-4`})}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:e.label}),(0,G.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,G.jsx)(`span`,{className:`text-sm font-bold text-white`,children:e.value}),e.detail&&(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray truncate`,children:e.detail})]})]})]},t))})}function uWe(){let{t:e}=U(),{showToast:t}=qd(),{hasPermission:n,authEnabled:r}=Nd(),[i,a]=(0,y.useState)(!1),[o,s]=(0,y.useState)(!1),[c,l]=(0,y.useState)(0),[u,d]=(0,y.useState)(0),[f,p]=(0,y.useState)(!1),[m,h]=(0,y.useState)(null),[g,_]=(0,y.useState)(!1),v=r&&n(`stats:filter_by_user`),[b,x]=(0,y.useState)(()=>{try{let e=localStorage.getItem(`bambusy-stats-timeframe`);if(e){let t=JSON.parse(e);if(t.preset)return t}}catch{}return{preset:`all-time`,dateFrom:void 0,dateTo:void 0}}),[S,C]=(0,y.useState)(!1);(0,y.useEffect)(()=>{localStorage.setItem(`bambusy-stats-timeframe`,JSON.stringify(b))},[b]);let w=(0,y.useMemo)(()=>b.preset===`custom`?{dateFrom:b.dateFrom,dateTo:b.dateTo}:QUe(b.preset),[b]);(0,y.useEffect)(()=>{let e=()=>{try{let e=localStorage.getItem(`bambusy-dashboard-layout-v2`);e&&d(JSON.parse(e).hidden?.length||0)}catch{d(0)}};e(),window.addEventListener(`storage`,e);let t=setInterval(e,2e3);return()=>{window.removeEventListener(`storage`,e),clearInterval(t)}},[c]);let T=m===null?void 0:m,{data:E,isLoading:D,isFetching:O,refetch:k}=K({queryKey:[`archiveStats`,w.dateFrom,w.dateTo,T??`all`],queryFn:()=>Z.getArchiveStats({dateFrom:w.dateFrom,dateTo:w.dateTo,createdById:T})}),{data:A}=K({queryKey:[`printers`],queryFn:Z.getPrinters}),{data:j,isFetching:M,refetch:N}=K({queryKey:[`archivesSlim`,w.dateFrom,w.dateTo,T??`all`],queryFn:()=>Z.getArchivesSlim(w.dateFrom,w.dateTo,T)}),{data:P}=K({queryKey:[`settings`],queryFn:Z.getSettings}),{data:F}=K({queryKey:[`users`,`slim`],queryFn:Z.getUsersSlim,enabled:v}),I=(0,y.useMemo)(()=>m===null?e(`stats.allUsers`,`All Users`):m===-1?e(`stats.noUser`,`No User (System)`):F?.find(e=>e.id===m)?.username??`?`,[m,F,e]),L=async n=>{s(!1),a(!0);try{let{blob:r,filename:i}=await Z.exportStats({format:n,days:90,createdById:T}),a=URL.createObjectURL(r),o=document.createElement(`a`);o.href=a,o.download=i,o.click(),URL.revokeObjectURL(a),t(e(`stats.exportDownloaded`))}catch{t(e(`stats.exportFailed`),`error`)}finally{a(!1)}},R=async()=>{p(!0);try{let n=await Z.recalculateCosts();await Promise.all([k(),N()]),t(e(`stats.recalculatedCosts`,{count:n.updated}))}catch{t(e(`stats.recalculateFailed`),`error`)}finally{p(!1)}},z=(O||M)&&!D,B=Lf(P?.currency||`USD`),V=(0,y.useMemo)(()=>new Map([...Object.entries(E?.printer_names||{}),...A?.map(e=>[String(e.id),e.name])||[]]),[E?.printer_names,A]),ee=(0,y.useMemo)(()=>j?.map(e=>e.created_at)||[],[j]);if(D)return(0,G.jsx)(`div`,{className:`p-4 md:p-8`,children:(0,G.jsx)(`div`,{className:`text-center py-12 text-bambu-gray`,children:e(`stats.loadingStats`)})});let te=[{id:`quick-stats`,title:e(`stats.quickStats`),component:(0,G.jsx)(tWe,{stats:E,currency:B}),defaultSize:2},{id:`success-rate`,title:e(`stats.successRate`),component:e=>(0,G.jsx)(nWe,{stats:E,printerMap:V,size:e}),defaultSize:1},{id:`time-accuracy`,title:e(`stats.timeAccuracy`),component:e=>(0,G.jsx)(rWe,{stats:E,printerMap:V,size:e}),defaultSize:1},{id:`failure-analysis`,title:e(`stats.failureAnalysis`),component:e=>(0,G.jsx)(cWe,{size:e,dateFrom:w.dateFrom,dateTo:w.dateTo,createdById:T}),defaultSize:1},{id:`print-activity`,title:e(`stats.printActivity`),component:e=>(0,G.jsx)(aWe,{printDates:ee,size:e,dateFrom:w.dateFrom,dateTo:w.dateTo}),defaultSize:2},{id:`records`,title:e(`stats.records`),component:(0,G.jsx)(lWe,{archives:j||[],currency:B}),defaultSize:1},{id:`printer-stats`,title:e(`stats.printerStats`),component:(0,G.jsx)(oWe,{stats:E,archives:j||[],printerMap:V}),defaultSize:4},{id:`filament-trends`,title:e(`stats.filamentTrends`),component:(0,G.jsx)(sWe,{archives:j||[],currency:B,dateFrom:w.dateFrom,dateTo:w.dateTo}),defaultSize:4}];return(0,G.jsxs)(`div`,{className:`p-4 md:p-8`,children:[(0,G.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4 mb-6`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,G.jsx)(cs,{className:`w-7 h-7 text-bambu-green`}),e(`stats.title`)]}),z&&(0,G.jsx)(Y,{className:`w-5 h-5 text-bambu-green animate-spin`})]}),(0,G.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:e(`stats.subtitle`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[u>0&&(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>{window.dispatchEvent(new CustomEvent(`toggle-hidden-panel`))},children:[(0,G.jsx)(ac,{className:`w-4 h-4`}),e(`stats.hiddenCount`,{count:u})]}),(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>{localStorage.removeItem(`bambusy-dashboard-layout-v2`),l(e=>e+1),t(e(`stats.layoutReset`))},disabled:!n(`settings:update`),title:n(`settings:update`)?void 0:e(`stats.noPermissionResetLayout`),children:[(0,G.jsx)(Wl,{className:`w-4 h-4`}),e(`stats.resetLayout`)]}),(0,G.jsxs)(Q,{variant:`secondary`,onClick:R,disabled:f||!n(`archives:update_all`),title:n(`archives:update_all`)?e(`stats.recalculateCostsHint`):e(`stats.noPermissionRecalculate`),children:[f?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(ns,{className:`w-4 h-4`}),e(`stats.recalculateCosts`)]}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>s(!o),disabled:i,children:[i?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(dc,{className:`w-4 h-4`}),e(`stats.exportStats`)]}),o&&(0,G.jsxs)(`div`,{className:`absolute right-0 top-full mt-1 w-48 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl z-20`,children:[(0,G.jsxs)(`button`,{className:`w-full px-4 py-2 text-left text-white hover:bg-bambu-dark-tertiary transition-colors flex items-center gap-2 rounded-t-lg`,onClick:()=>L(`csv`),children:[(0,G.jsx)(fc,{className:`w-4 h-4`}),e(`stats.exportAsCsv`)]}),(0,G.jsxs)(`button`,{className:`w-full px-4 py-2 text-left text-white hover:bg-bambu-dark-tertiary transition-colors flex items-center gap-2 rounded-b-lg`,onClick:()=>L(`xlsx`),children:[(0,G.jsx)(dc,{className:`w-4 h-4`}),e(`stats.exportAsExcel`)]})]})]}),v&&F&&F.length>0&&(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>_(!g),children:[(0,G.jsx)(Uu,{className:`w-4 h-4`}),I,(0,G.jsx)(ps,{className:`w-3 h-3`})]}),g&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`fixed inset-0 z-10`,onClick:()=>_(!1)}),(0,G.jsxs)(`div`,{className:`absolute right-0 top-full mt-1 w-48 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl z-20 p-2 max-h-64 overflow-y-auto`,children:[(0,G.jsx)(`button`,{className:`w-full px-3 py-2 text-left text-sm rounded-md transition-colors ${m===null?`bg-bambu-green text-white`:`text-white hover:bg-bambu-dark-tertiary`}`,onClick:()=>{h(null),_(!1)},children:e(`stats.allUsers`,`All Users`)}),(0,G.jsx)(`button`,{className:`w-full px-3 py-2 text-left text-sm rounded-md transition-colors ${m===-1?`bg-bambu-green text-white`:`text-white hover:bg-bambu-dark-tertiary`}`,onClick:()=>{h(-1),_(!1)},children:e(`stats.noUser`,`No User (System)`)}),(0,G.jsx)(`div`,{className:`border-t border-bambu-dark-tertiary my-1`}),F.map(e=>(0,G.jsx)(`button`,{className:`w-full px-3 py-2 text-left text-sm rounded-md transition-colors ${m===e.id?`bg-bambu-green text-white`:`text-white hover:bg-bambu-dark-tertiary`}`,onClick:()=>{h(e.id),_(!1)},children:e.username},e.id))]})]})]}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>C(!S),children:[(0,G.jsx)(as,{className:`w-4 h-4`}),e(`stats.timeframe.${b.preset}`),(0,G.jsx)(ps,{className:`w-3 h-3`})]}),S&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`fixed inset-0 z-10`,onClick:()=>C(!1)}),(0,G.jsxs)(`div`,{className:`absolute right-0 top-full mt-1 w-64 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl z-20 p-2`,children:[$Ue.map(t=>(0,G.jsx)(`button`,{className:`w-full px-3 py-2 text-left text-sm rounded-md transition-colors ${b.preset===t?`bg-bambu-green text-white`:`text-white hover:bg-bambu-dark-tertiary`}`,onClick:()=>{x({preset:t,dateFrom:void 0,dateTo:void 0}),C(!1)},children:e(`stats.timeframe.${t}`)},t)),(0,G.jsx)(`div`,{className:`border-t border-bambu-dark-tertiary my-2`}),(0,G.jsx)(`button`,{className:`w-full px-3 py-2 text-left text-sm rounded-md transition-colors ${b.preset===`custom`?`bg-bambu-green text-white`:`text-white hover:bg-bambu-dark-tertiary`}`,onClick:()=>x(e=>({...e,preset:`custom`})),children:e(`stats.timeframe.custom`)}),b.preset===`custom`&&(0,G.jsxs)(`div`,{className:`mt-2 px-1 pb-1 space-y-2`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`text-xs text-bambu-gray block mb-1`,children:e(`stats.timeframe.from`)}),(0,G.jsx)(`input`,{type:`date`,value:b.dateFrom||``,max:b.dateTo||new Date().toISOString().split(`T`)[0],onChange:e=>x(t=>({...t,dateFrom:e.target.value||void 0})),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded-md px-3 py-1.5 text-sm text-white`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`text-xs text-bambu-gray block mb-1`,children:e(`stats.timeframe.to`)}),(0,G.jsx)(`input`,{type:`date`,value:b.dateTo||``,min:b.dateFrom,max:new Date().toISOString().split(`T`)[0],onChange:e=>x(t=>({...t,dateTo:e.target.value||void 0})),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded-md px-3 py-1.5 text-sm text-white`})]}),(0,G.jsx)(Q,{variant:`primary`,onClick:()=>C(!1),className:`w-full`,children:e(`common.apply`)})]})]})]})]})]})]}),(0,G.jsx)(ZUe,{widgets:te,storageKey:`bambusy-dashboard-layout-v2`,stackBelow:640,hideControls:!0},c)]})}function _6(e){return e.length<8?`tooShort`:/[A-Z]/.test(e)?/[a-z]/.test(e)?/\d/.test(e)?/[^A-Za-z0-9]/.test(e)?null:`needsSpecial`:`needsDigit`:`needsLowercase`:`needsUppercase`}var v6=[`inventory-locations`];function y6(e){return e.invalidateQueries({queryKey:v6})}function b6(e,t){return Promise.all([e.invalidateQueries({queryKey:[...t]}),y6(e)])}var x6=`bambuddy-location-sensor-show-on-card-defaults`,S6={alertAbove:``,alertBelow:``,notifyOnAlert:!1,showOnCard:!0};function dWe(){return{temperature:{...S6,alertAbove:`30`,alertBelow:`20`},humidity:{...S6,alertAbove:`30`,alertBelow:`10`},battery:{...S6,alertBelow:`10`}}}function fWe(){try{let e=localStorage.getItem(x6);return e?JSON.parse(e):{}}catch{return{}}}function C6(e){let t=dWe();if(e)try{let n=JSON.parse(e);Object.keys(t).forEach(e=>{let r=n[e];r&&(typeof r.alertAbove==`string`&&(t[e].alertAbove=r.alertAbove),typeof r.alertBelow==`string`&&(t[e].alertBelow=r.alertBelow),typeof r.notifyOnAlert==`boolean`&&(t[e].notifyOnAlert=r.notifyOnAlert))})}catch{}let n=fWe();return Object.keys(t).forEach(e=>{typeof n[e]==`boolean`&&(t[e].showOnCard=n[e])}),t}function pWe(e){let t={};return Object.keys(e).forEach(n=>{t[n]={alertAbove:e[n].alertAbove,alertBelow:e[n].alertBelow,notifyOnAlert:e[n].notifyOnAlert}}),JSON.stringify(t)}function mWe(e){try{let t={};Object.keys(e).forEach(n=>{t[n]=e[n].showOnCard}),localStorage.setItem(x6,JSON.stringify(t))}catch{return}}var w6=`bambuddy-location-sensor-colorize-values`;function T6(){try{let e=localStorage.getItem(w6);return e?e===`true`:!0}catch{return!0}}var E6=`bambuddy:location-sensor-color-prefs-changed`;function D6(){window.dispatchEvent(new Event(E6))}function hWe(e){try{localStorage.setItem(w6,String(e))}catch{return}D6()}var O6=[`red`,`orange`,`yellow`,`green`,`blue`,`purple`,`pink`],k6={red:`text-red-400`,orange:`text-orange-400`,yellow:`text-yellow-400`,green:`text-green-400`,blue:`text-blue-400`,purple:`text-purple-400`,pink:`text-pink-400`},A6=`bambuddy-location-sensor-alert-above-color`,j6=`bambuddy-location-sensor-alert-below-color`,M6=`bambuddy-location-sensor-alert-optimal-color`;function N6(e){return!!e&&O6.includes(e)}function P6(){try{let e=localStorage.getItem(A6);return N6(e)?e:`purple`}catch{return`purple`}}function gWe(e){try{localStorage.setItem(A6,e)}catch{return}D6()}function F6(){try{let e=localStorage.getItem(j6);return N6(e)?e:`red`}catch{return`red`}}function _We(e){try{localStorage.setItem(j6,e)}catch{return}D6()}function I6(){try{let e=localStorage.getItem(M6);return N6(e)?e:`green`}catch{return`green`}}function vWe(e){try{localStorage.setItem(M6,e)}catch{return}D6()}function L6(){return{colorize:T6(),aboveColor:P6(),belowColor:F6(),optimalColor:I6()}}function R6(){let[e,t]=(0,y.useState)(L6);return(0,y.useEffect)(()=>{let e=()=>t(L6());return window.addEventListener(E6,e),()=>window.removeEventListener(E6,e)},[]),e}function z6(e){return!e.reachable||e.state===null?null:e.kind===`numeric`?e.alert_above===null&&e.alert_below===null||e.value===null?null:e.alert_above!==null&&e.value>e.alert_above?`above`:e.alert_below!==null&&e.value{let r=Math.max(0,Math.min(65,Math.round(n)));t(bWe({...i,[e]:r}))};return(0,G.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-x-3 gap-y-1.5`,children:H6.map(e=>{let t=i[e]??V6[e]??0,o=e==="default"?r(`settings.preheatFilamentTargetsDefaultRow`,`Other / unmapped`):e;return(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,G.jsx)(`span`,{className:`text-xs ${e==="default"?`text-bambu-gray italic`:`text-bambu-gray`}`,children:o}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(`input`,{type:`number`,min:0,max:65,step:1,value:t,onChange:t=>a(e,parseInt(t.target.value,10)||0),disabled:n,className:`w-16 px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-xs text-right focus:outline-none focus:border-bambu-green disabled:opacity-50`}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:`°C`})]})]},e)})})}function U6(e,t,n){if(!e)return null;let r=(e[n.source]?.[t]??[]).find(e=>e.id===n.id);return r?r.name:null}var SWe={orca_cloud:`Orca Cloud`,cloud:`Bambu Cloud`,local:`Imported`,standard:`Standard`};function CWe(){let{t:e}=U(),t=co(),{showToast:n}=qd(),{data:r,isLoading:i,error:a}=K({queryKey:[`slicer-pipelines`],queryFn:()=>Z.listSlicerPipelines()}),{data:o}=K({queryKey:[`slicer-presets`],queryFn:()=>Z.getSlicerPresets()}),{data:s}=K({queryKey:[`printers`],queryFn:()=>Z.getPrinters()}),c=q({mutationFn:({id:e,name:t,description:n,target_printer_id:r,target_kind:i,target_model_class:a,fanout_strategy:o})=>Z.updateSlicerPipeline(e,{name:t,description:n,target_printer_id:r,target_kind:i,target_model_class:a,fanout_strategy:o}),onSuccess:()=>{t.invalidateQueries({queryKey:[`slicer-pipelines`]}),n(e(`settings.pipelines.toast.saved`,`Pipeline saved`),`success`)},onError:t=>{n(t.message||e(`settings.pipelines.toast.saveFailed`,`Save failed`),`error`)}}),l=q({mutationFn:e=>Z.deleteSlicerPipeline(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`slicer-pipelines`]}),n(e(`settings.pipelines.toast.deleted`,`Pipeline deleted`),`success`)},onError:t=>{n(t.message||e(`settings.pipelines.toast.deleteFailed`,`Delete failed`),`error`)}}),[u,d]=(0,y.useState)(``),[f,p]=(0,y.useState)(``),m=(0,y.useMemo)(()=>r?.pipelines??[],[r?.pipelines]),h=(0,y.useMemo)(()=>{let e=new Set,t=new Set,n=!1;for(let r of m)r.target_kind===`printer_class`&&r.target_model_class?t.add(r.target_model_class):r.target_printer_id?e.add(r.target_printer_id):n=!0;return{printers:(s??[]).filter(t=>e.has(t.id)),classes:Array.from(t).sort(),anyWithoutTarget:n}},[m,s]),g=(0,y.useMemo)(()=>{let e=u.trim().toLowerCase();return m.filter(t=>{if(e&&!t.name.toLowerCase().includes(e))return!1;if(f===`none`){if(t.target_kind===`printer_class`?t.target_model_class:t.target_printer_id!==null)return!1}else if(f.startsWith(`p:`)){let e=parseInt(f.slice(2),10);if(t.target_kind===`printer_class`||t.target_printer_id!==e)return!1}else if(f.startsWith(`c:`)){let e=f.slice(2);if(t.target_kind!==`printer_class`||t.target_model_class!==e)return!1}return!0})},[m,u,f]);return(0,G.jsxs)(zd,{children:[(0,G.jsxs)(Bd,{children:[(0,G.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(ed,{className:`w-4 h-4 text-bambu-green`}),e(`settings.pipelines.title`,`Slicer Pipelines`)]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`settings.pipelines.subtitle`,`Reusable preset bundles (printer + process + filaments + bed type). Save one from the Slice dialog and apply it with a single click on the next file.`)})]}),(0,G.jsxs)(Vd,{children:[i&&(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`}),e(`settings.pipelines.loading`,`Loading pipelines…`)]}),a&&(0,G.jsx)(`div`,{className:`text-sm text-red-700 dark:text-red-400`,children:e(`settings.pipelines.loadError`,`Could not load pipelines.`)}),!i&&!a&&m.length>0&&(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 mb-3`,children:[(0,G.jsxs)(`div`,{className:`relative flex-1 min-w-[12rem]`,children:[(0,G.jsx)(Ql,{className:`absolute left-2 top-1/2 -translate-y-1/2 w-3.5 h-3.5 text-bambu-gray pointer-events-none`}),(0,G.jsx)(`input`,{type:`search`,value:u,onChange:e=>d(e.target.value),placeholder:e(`settings.pipelines.searchPlaceholder`,`Search pipelines…`),"aria-label":e(`settings.pipelines.searchPlaceholder`,`Search pipelines…`),className:`w-full pl-7 pr-2 py-1 text-xs bg-bambu-dark border border-bambu-dark-tertiary rounded text-white`})]}),(0,G.jsxs)(`select`,{value:f,onChange:e=>p(e.target.value),"aria-label":e(`settings.pipelines.filterTarget`,`Filter by target`),className:`text-xs px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white`,children:[(0,G.jsx)(`option`,{value:``,children:e(`settings.pipelines.filter.all`,`All targets`)}),h.printers.length>0&&(0,G.jsx)(`optgroup`,{label:e(`settings.pipelines.field.targetKindSpecific`,`Specific printer`),children:h.printers.map(e=>(0,G.jsx)(`option`,{value:`p:${e.id}`,children:e.name},`p-${e.id}`))}),h.classes.length>0&&(0,G.jsx)(`optgroup`,{label:e(`settings.pipelines.field.targetKindClass`,`Printer class`),children:h.classes.map(t=>(0,G.jsx)(`option`,{value:`c:${t}`,children:e(`library.runWithPipeline.classTarget`,`Any {{model}}`,{model:t})},`c-${t}`))}),h.anyWithoutTarget&&(0,G.jsx)(`option`,{value:`none`,children:e(`settings.pipelines.filter.noTarget`,`No target set`)})]}),(u||f)&&(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:e(`settings.pipelines.filter.count`,`{{shown}} / {{total}}`,{shown:g.length,total:m.length})})]}),!i&&!a&&m.length===0&&(0,G.jsxs)(`div`,{className:`text-sm text-bambu-gray space-y-2`,children:[(0,G.jsx)(`p`,{children:e(`settings.pipelines.empty.title`,`No pipelines yet.`)}),(0,G.jsx)(`p`,{children:e(`settings.pipelines.empty.howto`,`Open the Slice dialog for any file, pick your printer / process / filaments / bed type, then click "Save as pipeline". Your saved pipelines will appear here.`)})]}),!i&&!a&&m.length>0&&g.length===0&&(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`settings.pipelines.filter.noMatches`,`No pipelines match the current filters.`)}),!i&&!a&&g.length>0&&(0,G.jsx)(`div`,{className:`space-y-2`,children:g.map(t=>(0,G.jsx)(wWe,{pipeline:t,presets:o,printers:s??[],onSave:e=>c.mutate({id:t.id,...e}),onDelete:()=>{confirm(e(`settings.pipelines.confirmDelete`,`Delete this pipeline? This cannot be undone.`))&&l.mutate(t.id)},saving:c.isPending,deleting:l.isPending},t.id))})]})]})}function wWe({pipeline:e,presets:t,printers:n,onSave:r,onDelete:i,saving:a,deleting:o}){let{t:s}=U(),[c,l]=(0,y.useState)(!1),[u,d]=(0,y.useState)(e.name),[f,p]=(0,y.useState)(e.description??``),[m,h]=(0,y.useState)(e.target_printer_id),[g,_]=(0,y.useState)(e.target_kind===`printer_class`?`printer_class`:`specific_printer`),[v,b]=(0,y.useState)(e.target_model_class??``),[x,S]=(0,y.useState)(e.fanout_strategy??`max_parallel`),C=Array.from(new Set(n.map(e=>e.model).filter(e=>!!e))).sort(),{data:w}=K({queryKey:[`pipeline-runs`,e.id],queryFn:()=>Z.listPipelineRuns(e.id,1),enabled:!c,refetchInterval:15e3}),T=w?.runs?.[0],E=U6(t,`printer`,e.printer_preset),D=U6(t,`process`,e.process_preset),O=e.filament_presets.map(e=>U6(t,`filament`,e)),k=e.filament_presets.length>1&&e.filament_presets.every(t=>t.source===e.filament_presets[0].source&&t.id===e.filament_presets[0].id),A=t!==void 0&&(E===null||D===null||O.some(e=>e===null)),j=e.target_printer_id?n.find(t=>t.id===e.target_printer_id):void 0,M=e.target_kind===`printer_class`,N=M?!e.target_model_class:e.target_printer_id===null;return(0,G.jsxs)(`div`,{className:`rounded-md border border-bambu-dark-tertiary bg-bambu-dark/40 px-3 py-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,G.jsx)(`div`,{className:`min-w-0 flex-1`,children:c?(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`input`,{value:u,onChange:e=>d(e.target.value),"aria-label":s(`settings.pipelines.field.name`,`Pipeline name`),placeholder:s(`settings.pipelines.field.name`,`Pipeline name`),className:`w-full px-2 py-1 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded text-white`}),(0,G.jsx)(`textarea`,{value:f,onChange:e=>p(e.target.value),"aria-label":s(`settings.pipelines.field.description`,`Description`),placeholder:s(`settings.pipelines.field.description`,`Description`),rows:2,className:`w-full px-2 py-1 text-xs bg-bambu-dark border border-bambu-dark-tertiary rounded text-white`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`text-xs text-bambu-gray block mb-1`,children:s(`settings.pipelines.field.targetKind`,`Target type`)}),(0,G.jsxs)(`div`,{className:`flex gap-3 text-xs`,children:[(0,G.jsxs)(`label`,{className:`flex items-center gap-1 text-white`,children:[(0,G.jsx)(`input`,{type:`radio`,name:`target-kind-${e.id}`,value:`specific_printer`,checked:g===`specific_printer`,onChange:()=>_(`specific_printer`),"aria-label":s(`settings.pipelines.field.targetKindSpecific`,`Specific printer`)}),s(`settings.pipelines.field.targetKindSpecific`,`Specific printer`)]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-1 text-white`,children:[(0,G.jsx)(`input`,{type:`radio`,name:`target-kind-${e.id}`,value:`printer_class`,checked:g===`printer_class`,onChange:()=>_(`printer_class`),"aria-label":s(`settings.pipelines.field.targetKindClass`,`Printer class`)}),s(`settings.pipelines.field.targetKindClass`,`Printer class`)]})]})]}),g===`specific_printer`?(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`text-xs text-bambu-gray block mb-1`,children:s(`settings.pipelines.field.targetPrinter`,`Target printer`)}),(0,G.jsxs)(`select`,{value:m??``,onChange:e=>h(e.target.value?parseInt(e.target.value,10):null),"aria-label":s(`settings.pipelines.field.targetPrinter`,`Target printer`),className:`w-full px-2 py-1 text-xs bg-bambu-dark border border-bambu-dark-tertiary rounded text-white`,children:[(0,G.jsx)(`option`,{value:``,children:s(`settings.pipelines.field.noTarget`,`— No target —`)}),n.map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}):(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`text-xs text-bambu-gray block mb-1`,children:s(`settings.pipelines.field.targetModelClass`,`Printer model`)}),(0,G.jsxs)(`select`,{value:v,onChange:e=>b(e.target.value),"aria-label":s(`settings.pipelines.field.targetModelClass`,`Printer model`),className:`w-full px-2 py-1 text-xs bg-bambu-dark border border-bambu-dark-tertiary rounded text-white`,children:[(0,G.jsx)(`option`,{value:``,children:s(`settings.pipelines.field.noTarget`,`— No target —`)}),C.map(e=>(0,G.jsx)(`option`,{value:e,children:e},e))]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`text-xs text-bambu-gray block mb-1`,children:s(`settings.pipelines.field.fanoutStrategy`,`Fanout strategy`)}),(0,G.jsxs)(`select`,{value:x,onChange:e=>S(e.target.value),"aria-label":s(`settings.pipelines.field.fanoutStrategy`,`Fanout strategy`),className:`w-full px-2 py-1 text-xs bg-bambu-dark border border-bambu-dark-tertiary rounded text-white`,children:[(0,G.jsx)(`option`,{value:`max_parallel`,children:s(`settings.pipelines.field.fanout.max_parallel`,`Max parallel — distribute across any idle matching printer`)}),(0,G.jsx)(`option`,{value:`round_robin`,children:s(`settings.pipelines.field.fanout.round_robin`,`Round robin — cycle through eligible printers`)}),(0,G.jsx)(`option`,{value:`fill_one_first`,children:s(`settings.pipelines.field.fanout.fill_one_first`,`Fill one first — pin all copies to one printer`)})]})]})]})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2 gap-y-1`,children:[(0,G.jsx)(`h4`,{className:`text-sm font-medium text-white truncate`,children:e.name}),(0,G.jsxs)(`span`,{className:`text-xs px-1.5 py-0.5 rounded inline-flex items-center gap-1 ${N?`bg-amber-100 dark:bg-amber-500/15 text-amber-700 dark:text-amber-400`:`bg-bambu-dark-tertiary text-bambu-gray`}`,children:[(0,G.jsx)(Rl,{className:`w-3 h-3`}),N?s(`settings.pipelines.noTargetHint`,`Set a target printer to run this`):M?(0,G.jsxs)(G.Fragment,{children:[s(`library.runWithPipeline.classTarget`,`Any {{model}}`,{model:e.target_model_class}),e.fanout_strategy&&(0,G.jsxs)(`span`,{className:`text-bambu-gray/60`,children:[` · `,s(`settings.pipelines.field.fanoutShort.${e.fanout_strategy}`,e.fanout_strategy)]})]}):j?.name??``]})]}),e.description&&(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:e.description})]})}),(0,G.jsx)(`div`,{className:`flex items-center gap-1 flex-shrink-0`,children:c?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`button`,{onClick:()=>{let e=u.trim();e&&(r({name:e,description:f.trim()||null,target_kind:g,target_printer_id:g===`specific_printer`?m??0:0,target_model_class:g===`printer_class`&&v||null,fanout_strategy:x}),l(!1))},disabled:a||!u.trim(),"aria-label":s(`settings.pipelines.action.save`,`Save`),className:`p-1.5 text-bambu-green hover:bg-bambu-dark-tertiary rounded disabled:opacity-50`,children:(0,G.jsx)(fs,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:()=>{d(e.name),p(e.description??``),h(e.target_printer_id),_(e.target_kind===`printer_class`?`printer_class`:`specific_printer`),b(e.target_model_class??``),S(e.fanout_strategy??`max_parallel`),l(!1)},"aria-label":s(`settings.pipelines.action.cancel`,`Cancel`),className:`p-1.5 text-bambu-gray hover:bg-bambu-dark-tertiary rounded`,children:(0,G.jsx)(nd,{className:`w-4 h-4`})})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`button`,{onClick:()=>l(!0),"aria-label":s(`settings.pipelines.action.rename`,`Rename`),className:`p-1.5 text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary rounded`,children:(0,G.jsx)(kl,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:i,disabled:o,"aria-label":s(`settings.pipelines.action.delete`,`Delete`),className:`p-1.5 text-bambu-gray hover:text-red-600 dark:hover:text-red-400 hover:bg-bambu-dark-tertiary rounded disabled:opacity-50`,children:(0,G.jsx)(Pu,{className:`w-4 h-4`})})]})})]}),!c&&(0,G.jsxs)(`div`,{className:`mt-2 grid grid-cols-1 md:grid-cols-2 gap-x-4 gap-y-2 text-xs`,children:[(0,G.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,G.jsx)(`div`,{className:`text-[10px] uppercase tracking-wide text-bambu-gray/60`,children:s(`settings.pipelines.group.profiles`,`Profiles`)}),(0,G.jsx)(W6,{label:s(`settings.pipelines.slot.printer`,`Printer`),ref:e.printer_preset,name:E}),(0,G.jsx)(W6,{label:s(`settings.pipelines.slot.process`,`Process`),ref:e.process_preset,name:D}),e.bed_type&&(0,G.jsxs)(`div`,{className:`text-bambu-gray`,children:[(0,G.jsxs)(`span`,{className:`font-medium text-bambu-gray/80`,children:[s(`settings.pipelines.slot.bed`,`Bed`),`:`]}),` `,(0,G.jsx)(`span`,{className:`text-white`,children:e.bed_type})]})]}),(0,G.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,G.jsxs)(`div`,{className:`text-[10px] uppercase tracking-wide text-bambu-gray/60`,children:[s(`settings.pipelines.group.filaments`,`Filaments`),e.filament_presets.length>1&&(0,G.jsxs)(`span`,{className:`text-bambu-gray/60 normal-case ml-1`,children:[`(`,e.filament_presets.length,`)`]})]}),k?(0,G.jsx)(W6,{label:s(`settings.pipelines.slot.filamentAll`,`All {{n}} slots`,{n:e.filament_presets.length}),ref:e.filament_presets[0],name:O[0]}):e.filament_presets.map((t,n)=>(0,G.jsx)(W6,{label:e.filament_presets.length>1?s(`settings.pipelines.slot.filamentN`,`Filament {{n}}`,{n:n+1}):s(`settings.pipelines.slot.filament`,`Filament`),ref:t,name:O[n]},n))]})]}),!c&&T&&(0,G.jsxs)(`div`,{className:`mt-1.5 text-xs text-bambu-gray flex items-center gap-1`,children:[(0,G.jsxs)(`span`,{className:`font-medium text-bambu-gray/80`,children:[s(`settings.pipelines.runs.lastRun`,`Last run`),`:`]}),` `,(0,G.jsx)(TWe,{status:T.status}),T.created_at&&(0,G.jsxs)(`span`,{className:`text-bambu-gray/60`,children:[`· `,new Date(T.created_at).toLocaleString()]})]}),N&&!c&&(0,G.jsxs)(`div`,{className:`mt-2 flex items-center gap-1.5 text-xs text-amber-700 dark:text-amber-400`,children:[(0,G.jsx)(Lu,{className:`w-3.5 h-3.5`}),s(`settings.pipelines.noTargetWarning`,`Set a target printer before running this pipeline.`)]}),A&&!c&&(0,G.jsxs)(`div`,{className:`mt-2 flex items-center gap-1.5 text-xs text-amber-700 dark:text-amber-400`,children:[(0,G.jsx)(Lu,{className:`w-3.5 h-3.5`}),s(`settings.pipelines.staleWarning`,`One or more referenced presets no longer exist. Re-save this pipeline from the Slice dialog to fix.`)]})]})}function TWe({status:e}){let{t}=U();return(0,G.jsx)(`span`,{className:{queued:`text-bambu-gray`,slicing:`text-blue-700 dark:text-blue-400`,dispatching:`text-blue-700 dark:text-blue-400`,in_progress:`text-bambu-green`,completed:`text-bambu-green`,failed:`text-red-700 dark:text-red-400`,partial_failure:`text-amber-700 dark:text-amber-400`,cancelled:`text-bambu-gray`}[e],children:t(`settings.pipelines.runs.status.${e}`,e)})}function W6({label:e,ref:t,name:n}){return(0,G.jsxs)(`div`,{className:`text-bambu-gray truncate`,children:[(0,G.jsxs)(`span`,{className:`font-medium text-bambu-gray/80`,children:[e,`:`]}),` `,n?(0,G.jsx)(`span`,{className:`text-white`,children:n}):(0,G.jsxs)(`span`,{className:`text-amber-700 dark:text-amber-400`,children:[`[`,SWe[t.source],` #`,t.id,`]`]})]})}var G6=90,K6=365;function q6(e){if(!e)return`—`;let t=rp(e);return t?t.toLocaleString():`—`}function EWe(e){let t=rp(e);return t?t.getTime(){if(l.preventDefault(),r.trim()){u(!0);try{e(await Z.createLongLivedCameraToken({name:r.trim(),expires_in_days:a,scope:s})),i(``),o(G6),c(`camera_stream`),n(t(`cameraTokens.toast.created`,`Token created`))}catch(e){n(e instanceof Error?e.message:t(`cameraTokens.toast.createFailed`,`Failed to create token`),`error`)}finally{u(!1)}}},className:`bg-bambu-dark-secondary rounded-lg p-4 mb-6 border border-bambu-dark-tertiary`,children:[(0,G.jsx)(`h3`,{className:`text-base font-semibold text-white mb-3`,children:t(`cameraTokens.create.title`,`Create new token`)}),(0,G.jsxs)(`div`,{className:`grid gap-3 md:grid-cols-[1fr_180px_140px_auto]`,children:[(0,G.jsx)(`input`,{type:`text`,maxLength:100,required:!0,value:r,onChange:e=>i(e.target.value),placeholder:t(`cameraTokens.create.namePlaceholder`,`e.g. Home Assistant`),className:`px-3 py-2 bg-bambu-dark rounded-md text-white border border-bambu-dark-tertiary focus:border-bambu-green focus:outline-none`,"aria-label":t(`cameraTokens.create.nameLabel`,`Token name`)}),(0,G.jsxs)(`select`,{value:s,onChange:e=>c(e.target.value),className:`px-3 py-2 bg-bambu-dark rounded-md text-white border border-bambu-dark-tertiary focus:border-bambu-green focus:outline-none`,"aria-label":t(`cameraTokens.create.scopeLabel`,`Scope`),children:[(0,G.jsx)(`option`,{value:`camera_stream`,children:t(`cameraTokens.scope.camera_stream`,`Camera stream`)}),(0,G.jsx)(`option`,{value:`camwall`,children:t(`cameraTokens.scope.camwall`,`Cam Wall`)}),(0,G.jsx)(`option`,{value:`overlay`,children:t(`cameraTokens.scope.overlay`,`Streaming Overlay`)})]}),(0,G.jsx)(`input`,{type:`number`,min:1,max:K6,required:!0,value:a,onChange:e=>{let t=Number(e.target.value);o(Math.min(Math.max(t,1),K6))},className:`px-3 py-2 bg-bambu-dark rounded-md text-white border border-bambu-dark-tertiary focus:border-bambu-green focus:outline-none`,"aria-label":t(`cameraTokens.create.daysLabel`,`Days until expiry`)}),(0,G.jsxs)(`button`,{type:`submit`,disabled:l||!r.trim(),className:`flex items-center gap-2 px-4 py-2 bg-bambu-green text-white rounded-md hover:bg-bambu-green/90 disabled:opacity-50 disabled:cursor-not-allowed`,children:[(0,G.jsx)(Fl,{className:`w-4 h-4`}),t(`cameraTokens.create.submit`,`Create`)]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-2`,children:s===`camwall`?t(`cameraTokens.create.hintCamWall`,`A Cam Wall token opens /camwall on a screen with no login — it can see every printer's name and state, and their camera streams. It cannot see filenames, addresses or access codes.`):s===`overlay`?t(`cameraTokens.create.hintOverlay`,`A Streaming Overlay token opens /overlay/{printerId} on a screen with no login — for OBS or any live stream. It can see one printer's camera stream plus its live print status, including the filename shown on screen. It cannot see addresses or access codes.`):t(`cameraTokens.create.hintCameraStream`,`A camera-stream token can only fetch camera streams and snapshots. Use it for Home Assistant, Frigate, or anything embedding a single camera.`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:t(`cameraTokens.create.hint`,`Maximum lifetime is 365 days. The token value is shown only once on creation — copy it now.`)})]})}function OWe({token:e,onConfirm:t,onCancel:n}){let{t:r}=U();return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/60 flex items-center justify-center z-50 p-4`,role:`dialog`,"aria-modal":`true`,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg p-6 max-w-md w-full border border-red-500/40`,children:[(0,G.jsxs)(`div`,{className:`flex items-start gap-3 mb-4`,children:[(0,G.jsx)(Lu,{className:`w-6 h-6 text-red-600 dark:text-red-400 flex-shrink-0 mt-0.5`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:r(`cameraTokens.confirmRevoke.title`,`Revoke this token?`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:r(`cameraTokens.confirmRevoke.body`,`Any device using "{{name}}" will lose access immediately. This cannot be undone.`,{name:e.name})})]})]}),(0,G.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,G.jsx)(`button`,{type:`button`,onClick:n,className:`px-4 py-2 bg-bambu-dark-tertiary text-white rounded-md hover:bg-bambu-dark-tertiary/80`,children:r(`cameraTokens.confirmRevoke.cancel`,`Cancel`)}),(0,G.jsx)(`button`,{type:`button`,onClick:t,className:`px-4 py-2 bg-red-500 text-white rounded-md hover:bg-red-600`,children:r(`cameraTokens.confirmRevoke.confirm`,`Revoke`)})]})]})})}function kWe({token:e,onClose:t}){let{t:n}=U(),{showToast:r}=qd(),i=e.token??``,a=e.scope===`camwall`&&i?`${window.location.origin}/camwall?token=${encodeURIComponent(i)}`:null,o=e.scope===`overlay`&&i?`${window.location.origin}/overlay/1?token=${encodeURIComponent(i)}`:null,s=async e=>{if(e)try{if(navigator.clipboard&&window.isSecureContext)await navigator.clipboard.writeText(e);else{let t=document.createElement(`textarea`);t.value=e,t.style.position=`fixed`,t.style.opacity=`0`,document.body.appendChild(t);try{t.select(),document.execCommand(`copy`)}finally{document.body.removeChild(t)}}r(n(`cameraTokens.toast.copied`,`Copied to clipboard`))}catch{r(n(`cameraTokens.toast.copyFailed`,`Copy failed — select and copy manually`),`error`)}};return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/60 flex items-center justify-center z-50 p-4`,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg p-6 max-w-2xl w-full border border-bambu-green/40`,children:[(0,G.jsxs)(`div`,{className:`flex items-start gap-3 mb-4`,children:[(0,G.jsx)(Lu,{className:`w-6 h-6 text-yellow-600 dark:text-yellow-400 flex-shrink-0 mt-0.5`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:n(`cameraTokens.created.title`,`Token created — copy it now`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:n(`cameraTokens.created.warning`,`This is the only time this token will be visible. After you close this dialog you can never view it again.`)})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-4`,children:[(0,G.jsx)(`code`,{className:`flex-1 px-3 py-2 bg-bambu-dark rounded-md text-bambu-green text-xs break-all font-mono select-all`,children:i}),(0,G.jsxs)(`button`,{type:`button`,onClick:()=>s(i),className:`flex items-center gap-2 px-3 py-2 bg-bambu-green text-white rounded-md hover:bg-bambu-green/90`,children:[(0,G.jsx)(Vs,{className:`w-4 h-4`}),n(`cameraTokens.created.copy`,`Copy`)]})]}),a&&(0,G.jsxs)(`div`,{className:`mb-4`,children:[(0,G.jsx)(`p`,{className:`text-sm font-medium text-white mb-1`,children:n(`cameraTokens.created.camWallUrlTitle`,`Cam Wall URL for this display`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:n(`cameraTokens.created.camWallUrlHint`,`Open this on the screen. Anyone who can read the URL can watch the wall, so treat it like a key — revoke the token to cut the display off.`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`code`,{className:`flex-1 px-3 py-2 bg-bambu-dark rounded-md text-bambu-green text-xs break-all font-mono select-all`,children:a}),(0,G.jsxs)(`button`,{type:`button`,onClick:()=>s(a),className:`flex items-center gap-2 px-3 py-2 bg-bambu-green text-white rounded-md hover:bg-bambu-green/90`,children:[(0,G.jsx)(Vs,{className:`w-4 h-4`}),n(`cameraTokens.created.copy`,`Copy`)]})]})]}),o&&(0,G.jsxs)(`div`,{className:`mb-4`,children:[(0,G.jsx)(`p`,{className:`text-sm font-medium text-white mb-1`,children:n(`cameraTokens.created.overlayUrlTitle`,`Overlay URL for OBS`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:n(`cameraTokens.created.overlayUrlHint`,`Add this as a Browser Source in OBS. Change the /overlay/1 number to your printer's number (from its URL on the Printers page). Anyone who can read the URL can watch the stream, so treat it like a key — revoke the token to cut it off.`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`code`,{className:`flex-1 px-3 py-2 bg-bambu-dark rounded-md text-bambu-green text-xs break-all font-mono select-all`,children:o}),(0,G.jsxs)(`button`,{type:`button`,onClick:()=>s(o),className:`flex items-center gap-2 px-3 py-2 bg-bambu-green text-white rounded-md hover:bg-bambu-green/90`,children:[(0,G.jsx)(Vs,{className:`w-4 h-4`}),n(`cameraTokens.created.copy`,`Copy`)]})]})]}),(0,G.jsx)(`div`,{className:`flex justify-end`,children:(0,G.jsx)(`button`,{type:`button`,onClick:t,className:`px-4 py-2 bg-bambu-dark-tertiary text-white rounded-md hover:bg-bambu-dark-tertiary/80`,children:n(`cameraTokens.created.dismiss`,`I've saved it`)})})]})})}function AWe({token:e,showOwner:t,ownerLabel:n,onRevoke:r}){let{t:i}=U(),a=EWe(e.expires_at);return(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary last:border-b-0`,children:[(0,G.jsx)(`td`,{className:`py-3 px-3 text-white`,children:e.name}),t&&(0,G.jsx)(`td`,{className:`py-3 px-3 text-bambu-gray`,children:n}),(0,G.jsx)(`td`,{className:`py-3 px-3`,children:(0,G.jsx)(`span`,{className:`rounded bg-bambu-dark-tertiary px-2 py-0.5 text-xs text-bambu-gray`,children:i(`cameraTokens.scope.${e.scope}`,e.scope)})}),(0,G.jsxs)(`td`,{className:`py-3 px-3 text-bambu-gray font-mono text-xs`,children:[e.lookup_prefix,`…`]}),(0,G.jsx)(`td`,{className:`py-3 px-3 text-bambu-gray`,children:q6(e.created_at)}),(0,G.jsxs)(`td`,{className:`py-3 px-3 ${a?`text-red-700 dark:text-red-400`:`text-bambu-gray`}`,children:[q6(e.expires_at),a&&(0,G.jsx)(`span`,{className:`ml-2 px-2 py-0.5 text-xs bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-300 rounded`,children:i(`cameraTokens.list.expired`,`Expired`)})]}),(0,G.jsx)(`td`,{className:`py-3 px-3 text-bambu-gray`,children:q6(e.last_used_at)}),(0,G.jsx)(`td`,{className:`py-3 px-3 text-right`,children:(0,G.jsxs)(`button`,{type:`button`,onClick:()=>r(e.id),className:`inline-flex items-center gap-1 px-2 py-1 text-sm text-red-700 dark:text-red-400 hover:text-red-900 dark:hover:text-red-300`,title:i(`cameraTokens.list.revoke`,`Revoke`),children:[(0,G.jsx)(Pu,{className:`w-4 h-4`}),i(`cameraTokens.list.revoke`,`Revoke`)]})})]})}function J6({tokens:e,showOwner:t,userIdToName:n,onRevoke:r,emptyMessage:i}){let{t:a}=U();return e.length===0?(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray italic`,children:i}):(0,G.jsx)(`div`,{className:`overflow-x-auto`,children:(0,G.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,G.jsx)(`thead`,{className:`text-bambu-gray text-left border-b border-bambu-dark-tertiary`,children:(0,G.jsxs)(`tr`,{children:[(0,G.jsx)(`th`,{className:`py-2 px-3 font-medium`,children:a(`cameraTokens.list.name`,`Name`)}),t&&(0,G.jsx)(`th`,{className:`py-2 px-3 font-medium`,children:a(`cameraTokens.list.owner`,`Owner`)}),(0,G.jsx)(`th`,{className:`py-2 px-3 font-medium`,children:a(`cameraTokens.list.scope`,`Scope`)}),(0,G.jsx)(`th`,{className:`py-2 px-3 font-medium`,children:a(`cameraTokens.list.prefix`,`Prefix`)}),(0,G.jsx)(`th`,{className:`py-2 px-3 font-medium`,children:a(`cameraTokens.list.created`,`Created`)}),(0,G.jsx)(`th`,{className:`py-2 px-3 font-medium`,children:a(`cameraTokens.list.expires`,`Expires`)}),(0,G.jsx)(`th`,{className:`py-2 px-3 font-medium`,children:a(`cameraTokens.list.lastUsed`,`Last used`)}),(0,G.jsx)(`th`,{className:`py-2 px-3`})]})}),(0,G.jsx)(`tbody`,{children:e.map(e=>(0,G.jsx)(AWe,{token:e,showOwner:t,ownerLabel:n?.get(e.user_id)??`#${e.user_id}`,onRevoke:r},e.id))})]})})}function jWe(){let{t:e}=U(),{user:t,isAdmin:n}=Nd(),{showToast:r}=qd(),[i,a]=(0,y.useState)([]),[o,s]=(0,y.useState)([]),[c,l]=(0,y.useState)(new Map),[u,d]=(0,y.useState)(!0),[f,p]=(0,y.useState)(null),[m,h]=(0,y.useState)(null),g=async()=>{d(!0);try{if(a(await Z.listMyLongLivedCameraTokens()),n){s(await Z.listAllLongLivedCameraTokens());try{let e=await Z.getUsersSlim();l(new Map(e.map(e=>[e.id,e.username])))}catch{l(new Map)}}}catch(t){r(t instanceof Error?t.message:e(`cameraTokens.toast.loadFailed`,`Failed to load tokens`),`error`)}finally{d(!1)}};(0,y.useEffect)(()=>{g()},[n]);let _=async e=>{let t=[...i,...o].find(t=>t.id===e);t&&h(t)},v=async()=>{if(!m)return;let t=m.id;h(null);try{await Z.revokeLongLivedCameraToken(t),r(e(`cameraTokens.toast.revoked`,`Token revoked`)),await g()}catch(t){r(t instanceof Error?t.message:e(`cameraTokens.toast.revokeFailed`,`Failed to revoke token`),`error`)}},b=(0,y.useMemo)(()=>o.filter(e=>e.user_id!==t?.id),[o,t?.id]);return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4`,children:e(`cameraTokens.description`,`Long-lived tokens for embedding the camera stream into Home Assistant, Frigate, kiosks, or any other tool that needs a stable URL. Each token is camera-stream-only and can be revoked at any time.`)}),(0,G.jsx)(DWe,{onCreated:e=>{p(e),g()}}),(0,G.jsxs)(`div`,{className:`mb-6`,children:[(0,G.jsx)(`h3`,{className:`text-base font-semibold text-white mb-3`,children:e(`cameraTokens.list.myTitle`,`My tokens`)}),u?(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`cameraTokens.loading`,`Loading…`)}):(0,G.jsx)(J6,{tokens:i,onRevoke:_,emptyMessage:e(`cameraTokens.list.empty`,`No tokens yet.`)})]}),n&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`text-base font-semibold text-white mb-3`,children:e(`cameraTokens.list.allTitle`,`All users (admin view)`)}),(0,G.jsx)(J6,{tokens:b,showOwner:!0,userIdToName:c,onRevoke:_,emptyMessage:e(`cameraTokens.list.empty`,`No tokens yet.`)})]}),f&&(0,G.jsx)(kWe,{token:f,onClose:()=>p(null)}),m&&(0,G.jsx)(OWe,{token:m,onConfirm:()=>void v(),onCancel:()=>h(null)})]})}var Y6=[{key:`printer`,labelKey:`streamOverlay.builder.fieldPrinter`,fallback:`Printer name`},{key:`filename`,labelKey:`streamOverlay.builder.fieldFilename`,fallback:`File name`},{key:`status`,labelKey:`streamOverlay.builder.fieldStatus`,fallback:`Status`},{key:`progress`,labelKey:`streamOverlay.builder.fieldProgress`,fallback:`Progress bar`},{key:`layers`,labelKey:`streamOverlay.builder.fieldLayers`,fallback:`Layer count`},{key:`eta`,labelKey:`streamOverlay.builder.fieldEta`,fallback:`Time remaining and ETA`},{key:`nozzle`,labelKey:`printers.heaterHistory.nozzle`,fallback:`Nozzle`},{key:`bed`,labelKey:`printers.heaterHistory.bed`,fallback:`Bed`},{key:`chamber`,labelKey:`printers.heaterHistory.chamber`,fallback:`Chamber`}],MWe=[`progress`,`layers`,`eta`,`filename`,`status`],X6=15;function NWe(){let{t:e}=U(),{showToast:t}=qd(),[n,r]=(0,y.useState)([]),[i,a]=(0,y.useState)(null),[o,s]=(0,y.useState)(MWe),[c,l]=(0,y.useState)(`medium`),[u,d]=(0,y.useState)(X6),[f,p]=(0,y.useState)(!0),[m,h]=(0,y.useState)(``),[g,_]=(0,y.useState)(!1);(0,y.useEffect)(()=>{let e=!1;return(async()=>{try{let t=await Z.getPrinters();if(e)return;r(t),t.length>0&&a(t[0].id)}catch{}})(),()=>{e=!0}},[]);let v=(0,y.useMemo)(()=>{let e=i??1,t=new URLSearchParams,n=Y6.filter(e=>o.includes(e.key)).map(e=>e.key);return t.set(`show`,n.join(`,`)),c!==`medium`&&t.set(`size`,c),u!==X6&&t.set(`fps`,String(u)),f||t.set(`camera`,`false`),m.trim()&&t.set(`token`,m.trim()),`${window.location.origin}/overlay/${e}?${t.toString()}`},[i,o,c,u,f,m]),b=e=>{s(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},x=async()=>{try{if(navigator.clipboard&&window.isSecureContext)await navigator.clipboard.writeText(v);else{let e=document.createElement(`textarea`);e.value=v,e.style.position=`fixed`,e.style.opacity=`0`,document.body.appendChild(e);try{e.select(),document.execCommand(`copy`)}finally{document.body.removeChild(e)}}t(e(`cameraTokens.toast.copied`,`Copied to clipboard`))}catch{t(e(`cameraTokens.toast.copyFailed`,`Copy failed — select and copy manually`),`error`)}};return(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4`,children:e(`streamOverlay.builder.description`,`Build the URL for a streaming overlay — a full-screen camera view with live print data drawn over it, for OBS, a wall display, or any browser source. Pick the fields you want and copy the URL.`)}),(0,G.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{htmlFor:`overlay-builder-printer`,className:`block text-sm font-medium text-white mb-1`,children:e(`streamOverlay.builder.printer`,`Printer`)}),(0,G.jsxs)(`select`,{id:`overlay-builder-printer`,value:i??``,onChange:e=>a(Number(e.target.value)),className:`w-full px-3 py-2 bg-bambu-dark rounded-md text-white border border-bambu-dark-tertiary focus:border-bambu-green focus:outline-none`,children:[n.length===0&&(0,G.jsx)(`option`,{value:``,children:e(`common.loading`,`Loading…`)}),n.map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{htmlFor:`overlay-builder-size`,className:`block text-sm font-medium text-white mb-1`,children:e(`streamOverlay.builder.size`,`Text size`)}),(0,G.jsxs)(`select`,{id:`overlay-builder-size`,value:c,onChange:e=>l(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark rounded-md text-white border border-bambu-dark-tertiary focus:border-bambu-green focus:outline-none`,children:[(0,G.jsx)(`option`,{value:`small`,children:e(`streamOverlay.builder.sizeSmall`,`Small`)}),(0,G.jsx)(`option`,{value:`medium`,children:e(`streamOverlay.builder.sizeMedium`,`Medium`)}),(0,G.jsx)(`option`,{value:`large`,children:e(`streamOverlay.builder.sizeLarge`,`Large`)})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{htmlFor:`overlay-builder-fps`,className:`block text-sm font-medium text-white mb-1`,children:e(`streamOverlay.builder.fps`,`Frame rate`)}),(0,G.jsx)(`input`,{id:`overlay-builder-fps`,type:`number`,min:1,max:30,value:u,onChange:e=>d(Math.min(Math.max(Number(e.target.value)||1,1),30)),className:`w-full px-3 py-2 bg-bambu-dark rounded-md text-white border border-bambu-dark-tertiary focus:border-bambu-green focus:outline-none`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`streamOverlay.builder.fpsHint`,`A1 and P1 cameras top out around 5 fps whatever you ask for.`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{htmlFor:`overlay-builder-token`,className:`block text-sm font-medium text-white mb-1`,children:e(`streamOverlay.builder.token`,`Streaming Overlay token (optional)`)}),(0,G.jsx)(`input`,{id:`overlay-builder-token`,type:`text`,value:m,onChange:e=>h(e.target.value),placeholder:`bblt_…`,className:`w-full px-3 py-2 bg-bambu-dark rounded-md text-white border border-bambu-dark-tertiary focus:border-bambu-green focus:outline-none font-mono text-xs`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`streamOverlay.builder.tokenHint`,`Only needed when login is enabled: OBS has no session of its own. Create one above with the Streaming Overlay scope.`)})]})]}),(0,G.jsxs)(`fieldset`,{className:`mt-4`,children:[(0,G.jsx)(`legend`,{className:`text-sm font-medium text-white mb-2`,children:e(`streamOverlay.builder.fields`,`Fields to show`)}),(0,G.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-2 md:grid-cols-3`,children:[Y6.map(t=>(0,G.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-bambu-gray`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:o.includes(t.key),onChange:()=>b(t.key),className:`accent-bambu-green`}),e(t.labelKey,t.fallback)]},t.key)),(0,G.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-bambu-gray`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:f,onChange:e=>p(e.target.checked),className:`accent-bambu-green`}),e(`streamOverlay.builder.fieldCamera`,`Camera feed`)]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-2`,children:e(`streamOverlay.builder.chamberHint`,`Chamber temperature only appears on models with a real chamber sensor — P1 and A1 printers report a meaningless value, so it is left out there.`)})]}),(0,G.jsxs)(`div`,{className:`mt-4`,children:[(0,G.jsx)(`p`,{className:`text-sm font-medium text-white mb-1`,children:e(`streamOverlay.builder.urlTitle`,`Overlay URL`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`code`,{className:`flex-1 px-3 py-2 bg-bambu-dark rounded-md text-bambu-green text-xs break-all font-mono select-all`,children:v}),(0,G.jsxs)(`button`,{type:`button`,onClick:()=>void x(),className:`flex items-center gap-2 px-3 py-2 bg-bambu-green text-white rounded-md hover:bg-bambu-green/90`,children:[(0,G.jsx)(Vs,{className:`w-4 h-4`}),e(`cameraTokens.created.copy`,`Copy`)]}),(0,G.jsxs)(`a`,{href:v,target:`_blank`,rel:`noopener noreferrer`,className:`flex items-center gap-2 px-3 py-2 bg-bambu-dark-tertiary text-white rounded-md hover:bg-bambu-dark-tertiary/80`,children:[(0,G.jsx)(rc,{className:`w-4 h-4`}),e(`streamOverlay.builder.open`,`Open`)]})]}),m.trim()&&(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-2`,children:e(`streamOverlay.builder.tokenWarning`,`This URL contains a token — anyone who can read it can watch the stream and see the file name. Revoke the token to cut it off.`)})]}),(0,G.jsxs)(`div`,{className:`mt-4`,children:[(0,G.jsxs)(`button`,{type:`button`,onClick:()=>_(e=>!e),className:`flex items-center gap-2 px-3 py-2 bg-bambu-dark-tertiary text-white rounded-md hover:bg-bambu-dark-tertiary/80 text-sm`,children:[g?(0,G.jsx)(ic,{className:`w-4 h-4`}):(0,G.jsx)(ac,{className:`w-4 h-4`}),g?e(`streamOverlay.builder.hidePreview`,`Hide preview`):e(`streamOverlay.builder.showPreview`,`Show preview`)]}),g&&(0,G.jsx)(`iframe`,{src:v,title:e(`streamOverlay.builder.previewTitle`,`Overlay preview`),className:`mt-3 w-full aspect-video rounded-md border border-bambu-dark-tertiary bg-black`},v)]})]})}function PWe({plug:e,onEdit:t}){let{t:n}=U(),r=co(),{showToast:i}=qd(),[a,o]=(0,y.useState)(!1),[s,c]=(0,y.useState)(!1),[l,u]=(0,y.useState)(!1),[d,f]=(0,y.useState)(!1),{data:p,isLoading:m}=K({queryKey:[`smart-plug-status`,e.id],queryFn:()=>Z.getSmartPlugStatus(e.id),refetchInterval:3e4}),{data:h}=K({queryKey:[`printers`],queryFn:Z.getPrinters}),g=h?.find(t=>t.id===e.printer_id),_=q({mutationFn:t=>Z.controlSmartPlug(e.id,t),onMutate:async t=>{await r.cancelQueries({queryKey:[`smart-plug-status`,e.id]});let n=r.getQueryData([`smart-plug-status`,e.id]),i=t===`on`?`ON`:t===`off`||p?.state===`ON`?`OFF`:`ON`;return r.setQueryData([`smart-plug-status`,e.id],e=>({...e,state:i})),{previousStatus:n}},onError:(t,a,o)=>{o?.previousStatus&&r.setQueryData([`smart-plug-status`,e.id],o.previousStatus),i(n(`smartPlugs.failedToTurn`,{action:a,name:e.name}),`error`)},onSettled:()=>{setTimeout(()=>{r.invalidateQueries({queryKey:[`smart-plug-status`,e.id]}),r.invalidateQueries({queryKey:[`smart-plugs`]})},1e3)}}),v=q({mutationFn:t=>Z.updateSmartPlug(e.id,t),onSuccess:()=>{r.invalidateQueries({queryKey:[`smart-plugs`]}),e.printer_id&&(r.invalidateQueries({queryKey:[`smartPlugByPrinter`,e.printer_id]}),r.invalidateQueries({queryKey:[`scriptPlugsByPrinter`,e.printer_id]}))}}),b=q({mutationFn:()=>Z.deleteSmartPlug(e.id),onSuccess:()=>{r.invalidateQueries({queryKey:[`smart-plugs`]}),e.printer_id&&r.invalidateQueries({queryKey:[`scriptPlugsByPrinter`,e.printer_id]})}}),x=p?.state===`ON`,S=e.plug_type===`mqtt`&&p?.energy?.power!==null&&p?.energy?.power!==void 0,C=(p?.reachable??!1)||S,w=_.isPending,T=(()=>{if(e.plug_type!==`tasmota`||!e.ip_address)return null;let t=e.ip_address;return e.username&&e.password?`http://${encodeURIComponent(e.username)}:${encodeURIComponent(e.password)}@${t}/`:`http://${t}/`})();return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(zd,{className:`relative`,children:(0,G.jsxs)(Vd,{className:`p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-start justify-between gap-2 mb-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 flex-1`,children:[(0,G.jsx)(`div`,{className:`p-2 rounded-lg flex-shrink-0 ${e.plug_type===`mqtt`?C?`bg-teal-100 dark:bg-teal-500/20`:`bg-red-100 dark:bg-red-500/20`:C?x?`bg-bambu-green/20`:`bg-bambu-dark`:`bg-red-100 dark:bg-red-500/20`}`,children:e.plug_type===`mqtt`?(0,G.jsx)(Bl,{className:`w-5 h-5 ${C?`text-teal-600 dark:text-teal-400`:`text-red-600 dark:text-red-400`}`}):e.plug_type===`homeassistant`?(0,G.jsx)(Bc,{className:`w-5 h-5 ${C?x?`text-bambu-green`:`text-bambu-gray`:`text-red-600 dark:text-red-400`}`}):e.plug_type===`rest`?(0,G.jsx)(Ac,{className:`w-5 h-5 ${C?x?`text-bambu-green`:`text-bambu-gray`:`text-red-600 dark:text-red-400`}`}):(0,G.jsx)(Pl,{className:`w-5 h-5 ${C?x?`text-bambu-green`:`text-bambu-gray`:`text-red-600 dark:text-red-400`}`})}),(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsx)(`h3`,{className:`font-medium text-white truncate`,children:e.name}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray truncate`,title:e.plug_type===`mqtt`?e.mqtt_topic??void 0:e.plug_type===`homeassistant`?e.ha_entity_id??void 0:e.plug_type===`rest`?e.rest_on_url??e.rest_off_url??void 0:e.ip_address??void 0,children:e.plug_type===`mqtt`?e.mqtt_topic:e.plug_type===`homeassistant`?e.ha_entity_id:e.plug_type===`rest`?e.rest_on_url||e.rest_off_url:e.ip_address})]})]}),(0,G.jsxs)(`div`,{className:`flex flex-col items-end gap-1 flex-shrink-0`,children:[m?(0,G.jsx)(Y,{className:`w-4 h-4 text-bambu-gray animate-spin`}):e.plug_type===`mqtt`?(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 text-sm whitespace-nowrap`,children:[(0,G.jsx)(`span`,{className:`px-1.5 py-0.5 bg-teal-100 dark:bg-teal-500/20 text-teal-700 dark:text-teal-400 text-[10px] font-medium rounded flex-shrink-0`,children:`MQTT`}),C&&(0,G.jsx)(`span`,{className:`text-status-ok`,children:`✓`})]}):e.plug_type===`homeassistant`?(0,G.jsxs)(`div`,{className:`flex items-center gap-1 text-sm`,children:[(0,G.jsx)(`span`,{className:`px-1 py-0.5 bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400 text-[10px] font-medium rounded`,children:`HA`}),(0,G.jsx)(`span`,{className:C?x?`text-status-ok`:`text-bambu-gray`:`text-status-error`,children:C?p?.state||`?`:n(`smartPlugs.offline`)})]}):e.plug_type===`rest`?(0,G.jsxs)(`div`,{className:`flex items-center gap-1 text-sm`,children:[(0,G.jsx)(`span`,{className:`px-1 py-0.5 bg-purple-100 dark:bg-purple-500/20 text-purple-700 dark:text-purple-400 text-[10px] font-medium rounded`,children:`REST`}),(0,G.jsx)(`span`,{className:C?x?`text-status-ok`:`text-bambu-gray`:`text-status-error`,children:C?p?.state||`?`:n(`smartPlugs.offline`)})]}):C?(0,G.jsxs)(`div`,{className:`flex items-center gap-1 text-sm`,children:[(0,G.jsx)(Qu,{className:`w-4 h-4 text-status-ok`}),(0,G.jsx)(`span`,{className:x?`text-status-ok`:`text-bambu-gray`,children:p?.state||n(`smartPlugs.unknown`)})]}):(0,G.jsxs)(`div`,{className:`flex items-center gap-1 text-sm text-status-error`,children:[(0,G.jsx)(Zu,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{children:n(`smartPlugs.offline`)})]}),T&&(0,G.jsxs)(`a`,{href:T,target:`_blank`,rel:`noopener noreferrer`,className:`flex items-center gap-1 px-2 py-0.5 bg-bambu-dark hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white text-xs rounded-full transition-colors`,title:n(`smartPlugs.openPlugAdminPage`),children:[(0,G.jsx)(rc,{className:`w-3 h-3`}),n(`smartPlugs.admin`)]})]})]}),g&&(0,G.jsxs)(`div`,{className:`mb-3 px-2 py-1.5 bg-bambu-dark rounded-lg`,children:[(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[n(`smartPlugs.linkedTo`),` `]}),(0,G.jsx)(`span`,{className:`text-sm text-white`,children:g.name})]}),(e.power_alert_enabled||e.schedule_enabled||e.plug_type===`mqtt`)&&(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-1.5 mb-3`,children:[e.plug_type===`mqtt`&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1 px-2 py-0.5 bg-teal-100 dark:bg-teal-500/20 text-teal-700 dark:text-teal-400 text-xs rounded-full`,children:[(0,G.jsx)(ac,{className:`w-3 h-3`}),n(`smartPlugs.monitorOnly`)]}),e.power_alert_enabled&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1 px-2 py-0.5 bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400 text-xs rounded-full`,children:[(0,G.jsx)(qo,{className:`w-3 h-3`}),n(`smartPlugs.alerts`)]}),e.schedule_enabled&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1 px-2 py-0.5 bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400 text-xs rounded-full`,children:[(0,G.jsx)(as,{className:`w-3 h-3`}),e.schedule_on_time&&e.schedule_off_time?`${e.schedule_on_time} - ${e.schedule_off_time}`:e.schedule_on_time?n(`smartPlugs.scheduleOn`,{time:e.schedule_on_time}):n(`smartPlugs.scheduleOff`,{time:e.schedule_off_time})]})]}),e.plug_type!==`mqtt`&&(0,G.jsxs)(`div`,{className:`flex gap-2 mb-3`,children:[(0,G.jsxs)(Q,{size:`sm`,variant:x?`primary`:`secondary`,disabled:!C||w,onClick:()=>c(!0),className:`flex-1`,children:[w?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Ll,{className:`w-4 h-4`}),n(`smartPlugs.on`)]}),(0,G.jsxs)(Q,{size:`sm`,variant:x?`secondary`:`primary`,disabled:!C||w,onClick:()=>u(!0),className:`flex-1`,children:[w?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Il,{className:`w-4 h-4`}),n(`smartPlugs.off`)]})]}),e.plug_type===`mqtt`&&p?.energy&&(0,G.jsxs)(`div`,{className:`flex gap-2 mb-3 px-3 py-2 bg-bambu-dark rounded-lg`,children:[p.energy.power!==null&&p.energy.power!==void 0&&(0,G.jsxs)(`div`,{className:`flex-1 text-center`,children:[(0,G.jsxs)(`p`,{className:`text-lg font-semibold text-white`,children:[Math.round(p.energy.power),`W`]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.power`)})]}),p.energy.today!==null&&p.energy.today!==void 0&&(0,G.jsxs)(`div`,{className:`flex-1 text-center border-l border-bambu-dark-tertiary`,children:[(0,G.jsx)(`p`,{className:`text-lg font-semibold text-white`,children:p.energy.today.toFixed(3)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.kwhToday`)})]})]}),(0,G.jsxs)(`button`,{onClick:()=>f(!d),className:`w-full flex items-center justify-between py-2 text-sm text-bambu-gray hover:text-white transition-colors`,children:[(0,G.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(nu,{className:`w-4 h-4`}),e.plug_type===`mqtt`?n(`smartPlugs.settings`):n(`smartPlugs.automationSettings`)]}),(0,G.jsx)(`span`,{children:d?`-`:`+`})]}),d&&(0,G.jsxs)(`div`,{className:`pt-3 border-t border-bambu-dark-tertiary space-y-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Yc,{className:`w-4 h-4 text-bambu-green`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`smartPlugs.showInSwitchbar`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.quickAccessSidebar`)})]})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:e.show_in_switchbar,onChange:e=>v.mutate({show_in_switchbar:e.target.checked}),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green`})]})]}),e.printer_id!=null&&(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Ll,{className:`w-4 h-4 text-bambu-green`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`smartPlugs.controlsPrinterPower`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.controlsPrinterPowerDescription`)})]})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:e.controls_printer_power,onChange:e=>v.mutate({controls_printer_power:e.target.checked}),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green`})]})]}),e.plug_type!==`mqtt`&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`smartPlugs.enabled`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.enableAutomation`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:e.enabled,onChange:e=>v.mutate({enabled:e.target.checked}),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`smartPlugs.autoOn`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.autoOnDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:e.auto_on,onChange:e=>v.mutate({auto_on:e.target.checked}),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`smartPlugs.autoOff`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.autoOffDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:e.auto_off,onChange:e=>v.mutate({auto_off:e.target.checked}),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green`})]})]}),e.auto_off&&(0,G.jsxs)(`div`,{className:`flex items-center justify-between pl-4 border-l-2 border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`smartPlugs.autoOffPersistent`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.autoOffPersistentDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:e.auto_off_persistent,onChange:e=>v.mutate({auto_off_persistent:e.target.checked}),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green`})]})]}),e.auto_off&&(0,G.jsxs)(`div`,{className:`space-y-3 pl-4 border-l-2 border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white mb-2`,children:n(`smartPlugs.turnOffDelayMode`)}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsxs)(`button`,{onClick:()=>v.mutate({off_delay_mode:`time`}),className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg text-sm transition-colors ${e.off_delay_mode===`time`?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white`}`,children:[(0,G.jsx)(js,{className:`w-4 h-4`}),n(`smartPlugs.time`)]}),(0,G.jsxs)(`button`,{onClick:()=>v.mutate({off_delay_mode:`temperature`}),className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg text-sm transition-colors ${e.off_delay_mode===`temperature`?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white`}`,children:[(0,G.jsx)(Mu,{className:`w-4 h-4`}),n(`smartPlugs.temp`)]})]})]}),e.off_delay_mode===`time`?(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:n(`smartPlugs.delayMinutes`)}),(0,G.jsx)(`input`,{type:`number`,min:`1`,max:`60`,value:e.off_delay_minutes,onChange:e=>v.mutate({off_delay_minutes:parseInt(e.target.value)||5}),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`})]}):(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:n(`smartPlugs.tempThreshold`)}),(0,G.jsx)(`input`,{type:`number`,min:`30`,max:`100`,value:e.off_temp_threshold,onChange:e=>v.mutate({off_temp_threshold:parseInt(e.target.value)||70}),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(`smartPlugs.tempThresholdDescription`)})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`smartPlugs.autoOffAfterDrying`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.autoOffAfterDryingDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:e.auto_off_after_drying,onChange:e=>v.mutate({auto_off_after_drying:e.target.checked}),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green`})]})]}),e.auto_off_after_drying&&(0,G.jsxs)(`div`,{className:`pl-4 border-l-2 border-bambu-dark-tertiary`,children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:n(`smartPlugs.delayAfterDryingMinutes`)}),(0,G.jsx)(`input`,{type:`number`,min:`0`,max:`120`,value:e.off_delay_after_drying_minutes,onChange:e=>v.mutate({off_delay_after_drying_minutes:parseInt(e.target.value)||10}),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`})]})]}),(0,G.jsxs)(`div`,{className:`flex gap-2 pt-2`,children:[(0,G.jsxs)(Q,{size:`sm`,variant:`secondary`,onClick:()=>t(e),className:`flex-1`,children:[(0,G.jsx)(kl,{className:`w-4 h-4`}),n(`smartPlugs.edit`)]}),(0,G.jsx)(Q,{size:`sm`,variant:`secondary`,onClick:()=>o(!0),className:`text-red-600 dark:text-red-400 hover:text-red-700 dark:hover:text-red-300`,children:(0,G.jsx)(Pu,{className:`w-4 h-4`})})]})]})]})}),a&&(0,G.jsx)(of,{title:n(`smartPlugs.deleteSmartPlug`),message:n(`smartPlugs.deleteConfirm`,{name:e.name}),confirmText:n(`smartPlugs.delete`),variant:`danger`,onConfirm:()=>{b.mutate(),o(!1)},onCancel:()=>o(!1)}),s&&(0,G.jsx)(of,{title:n(`smartPlugs.turnOnSmartPlug`),message:n(`smartPlugs.turnOnConfirm`,{name:e.name}),confirmText:n(`smartPlugs.turnOn`),variant:`default`,onConfirm:()=>{_.mutate(`on`),c(!1)},onCancel:()=>c(!1)}),l&&(0,G.jsx)(of,{title:n(`smartPlugs.turnOffSmartPlug`),message:n(`smartPlugs.turnOffConfirm`,{name:e.name}),confirmText:n(`smartPlugs.turnOff`),variant:`danger`,onConfirm:()=>{_.mutate(`off`),u(!1)},onCancel:()=>u(!1)})]})}function FWe({plug:e,onClose:t}){let{t:n}=U(),r=co(),i=!!e,[a,o]=(0,y.useState)(e?.plug_type||`tasmota`),[s,c]=(0,y.useState)(e?.name||``),[l,u]=(0,y.useState)(e?.ip_address||``),[d,f]=(0,y.useState)(e?.username||``),[p,m]=(0,y.useState)(e?.password||``),[h,g]=(0,y.useState)(e?.ha_entity_id||``),[_,v]=(0,y.useState)(e?.mqtt_power_topic||e?.mqtt_topic||``),[b,x]=(0,y.useState)(e?.mqtt_power_path||``),[S,C]=(0,y.useState)((e?.mqtt_power_multiplier??e?.mqtt_multiplier??1).toString()),[w,T]=(0,y.useState)(e?.mqtt_energy_topic||``),[E,D]=(0,y.useState)(e?.mqtt_energy_path||``),[O,k]=(0,y.useState)((e?.mqtt_energy_multiplier??1).toString()),[A,j]=(0,y.useState)(e?.mqtt_state_topic||``),[M,N]=(0,y.useState)(e?.mqtt_state_path||``),[P,F]=(0,y.useState)(e?.mqtt_state_on_value||``),[I,L]=(0,y.useState)(e?.rest_on_url||``),[R,z]=(0,y.useState)(e?.rest_on_body||``),[B,V]=(0,y.useState)(e?.rest_off_url||``),[ee,te]=(0,y.useState)(e?.rest_off_body||``),[ne,re]=(0,y.useState)(e?.rest_method||`POST`),[ie,ae]=(0,y.useState)(e?.rest_headers||``),[oe,se]=(0,y.useState)(e?.rest_status_url||``),[H,ce]=(0,y.useState)(e?.rest_status_path||``),[le,ue]=(0,y.useState)(e?.rest_status_on_value||``),[de,fe]=(0,y.useState)(e?.rest_power_url||``),[pe,me]=(0,y.useState)(e?.rest_power_path||``),[he,ge]=(0,y.useState)((e?.rest_power_multiplier??1).toString()),[_e,ve]=(0,y.useState)(e?.rest_energy_url||``),[ye,be]=(0,y.useState)(e?.rest_energy_path||``),[xe,Se]=(0,y.useState)((e?.rest_energy_multiplier??1).toString()),[Ce,we]=(0,y.useState)(e?.rest_energy_total_path||``),[Te,Ee]=(0,y.useState)((e?.rest_energy_total_multiplier??1).toString()),[De,Oe]=(0,y.useState)(e?.ha_power_entity||``),[ke,Ae]=(0,y.useState)(e?.ha_energy_today_entity||``),[je,Me]=(0,y.useState)(e?.ha_energy_total_entity||``),[Ne,Pe]=(0,y.useState)(``),[Fe,Ie]=(0,y.useState)(``),[Le,Re]=(0,y.useState)(!1),ze=(0,y.useRef)(null),[Be,Ve]=(0,y.useState)(``),[He,Ue]=(0,y.useState)(!1),We=(0,y.useRef)(null),[Ge,Ke]=(0,y.useState)(``),[qe,Je]=(0,y.useState)(!1),Ye=(0,y.useRef)(null),[Xe,Ze]=(0,y.useState)(``),[Qe,$e]=(0,y.useState)(!1),et=(0,y.useRef)(null),[tt,nt]=(0,y.useState)(e?.printer_id||null),[rt,it]=(0,y.useState)(e?.controls_printer_power??!0),[at,ot]=(0,y.useState)(null),[st,ct]=(0,y.useState)(null),[lt,ut]=(0,y.useState)(e?.power_alert_enabled||!1),[dt,ft]=(0,y.useState)(e?.power_alert_high?.toString()||``),[pt,mt]=(0,y.useState)(e?.power_alert_low?.toString()||``),[ht,gt]=(0,y.useState)(e?.schedule_enabled||!1),[_t,vt]=(0,y.useState)(e?.schedule_on_time||``),[yt,bt]=(0,y.useState)(e?.schedule_off_time||``),[xt,St]=(0,y.useState)(e?.show_in_switchbar||!1),[Ct,wt]=(0,y.useState)(e?.show_on_printer_card??!0),[Tt,Et]=(0,y.useState)(!1),[Dt,Ot]=(0,y.useState)({scanned:0,total:0}),[kt,At]=(0,y.useState)([]),jt=(0,y.useRef)(null),{data:Mt}=K({queryKey:[`printers`],queryFn:Z.getPrinters}),{data:Nt}=K({queryKey:[`smart-plugs`],queryFn:Z.getSmartPlugs}),{data:Pt}=K({queryKey:[`settings`],queryFn:Z.getSettings}),Ft=!!(Pt?.ha_enabled&&Pt?.ha_url&&Pt?.ha_token);(0,y.useEffect)(()=>{let e=setTimeout(()=>{Ie(Ne)},300);return()=>clearTimeout(e)},[Ne]),(0,y.useEffect)(()=>{let e=e=>{ze.current&&!ze.current.contains(e.target)&&Re(!1),We.current&&!We.current.contains(e.target)&&Ue(!1),Ye.current&&!Ye.current.contains(e.target)&&Je(!1),et.current&&!et.current.contains(e.target)&&$e(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[]);let{data:It,isLoading:Lt,error:Rt}=K({queryKey:[`ha-entities`,Fe],queryFn:()=>Z.getHAEntities(Fe||void 0),enabled:a===`homeassistant`&&Ft,retry:!1,staleTime:0}),{data:zt}=K({queryKey:[`ha-sensor-entities`],queryFn:Z.getHASensorEntities,enabled:a===`homeassistant`&&Ft,retry:!1,staleTime:0});(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,e),()=>{window.removeEventListener(`keydown`,e),jt.current&&clearInterval(jt.current)}},[t]);let Bt=async()=>{Et(!0),At([]),Ot({scanned:0,total:0}),ct(null);try{await Z.startTasmotaScan();let e=async()=>{try{let e=await Z.getTasmotaScanStatus();Ot({scanned:e.scanned,total:e.total}),At(await Z.getDiscoveredTasmotaDevices()),e.running||(Et(!1),jt.current&&=(clearInterval(jt.current),null))}catch(e){console.error(`Polling error:`,e)}};await e(),jt.current=setInterval(e,500)}catch(e){Et(!1),ct((e instanceof Error?e.message:typeof e==`string`?e:JSON.stringify(e))||n(`smartPlugs.failedToStartScan`))}},Vt=async()=>{try{await Z.stopTasmotaScan()}catch{}Et(!1),jt.current&&=(clearInterval(jt.current),null)},Ht=e=>{u(e.ip_address),c(e.name),ot(null)},Ut=q({mutationFn:()=>Z.testSmartPlugConnection(l,d||null,p||null),onSuccess:e=>{ot(e),ct(null),!s&&e.device_name&&c(e.device_name)},onError:e=>{ot(null),ct(e.message)}}),Wt=q({mutationFn:e=>Z.createSmartPlug(e),onSuccess:()=>{r.invalidateQueries({queryKey:[`smart-plugs`]}),r.invalidateQueries({queryKey:[`scriptPlugsByPrinter`]}),t()},onError:e=>{ct(e.message)}}),Gt=q({mutationFn:t=>Z.updateSmartPlug(e.id,t),onSuccess:()=>{r.invalidateQueries({queryKey:[`smart-plugs`]}),r.invalidateQueries({queryKey:[`scriptPlugsByPrinter`]}),t()},onError:e=>{ct(e.message)}}),Kt=Mt?.filter(t=>a===`tasmota`?!Nt?.some(n=>n.printer_id===t.id&&n.id!==e?.id&&n.plug_type===`tasmota`):!0),qt=e=>{if(e.preventDefault(),ct(null),!s.trim()){ct(n(`smartPlugs.nameRequired`));return}if(a===`tasmota`&&!l.trim()){ct(`IP address is required for Tasmota plugs`);return}if(a===`homeassistant`&&!h){ct(n(`smartPlugs.entityRequired`));return}if(a===`mqtt`){let e=_.trim(),t=w.trim(),r=A.trim();if(!e&&!t&&!r){ct(n(`smartPlugs.mqttTopicRequired`));return}}if(a===`rest`&&!I.trim()&&!B.trim()){ct(n(`smartPlugs.restUrlRequired`));return}let t={name:s.trim(),plug_type:a,ip_address:a===`tasmota`?l.trim():null,ha_entity_id:a===`homeassistant`?h:null,ha_power_entity:a===`homeassistant`&&De||null,ha_energy_today_entity:a===`homeassistant`&&ke||null,ha_energy_total_entity:a===`homeassistant`&&je||null,mqtt_power_topic:a===`mqtt`&&_.trim()||null,mqtt_power_path:a===`mqtt`&&b.trim()||null,mqtt_power_multiplier:a===`mqtt`&&parseFloat(S)||1,mqtt_energy_topic:a===`mqtt`&&w.trim()||null,mqtt_energy_path:a===`mqtt`&&E.trim()||null,mqtt_energy_multiplier:a===`mqtt`&&parseFloat(O)||1,mqtt_state_topic:a===`mqtt`&&A.trim()||null,mqtt_state_path:a===`mqtt`&&M.trim()||null,mqtt_state_on_value:a===`mqtt`&&P.trim()||null,rest_on_url:a===`rest`&&I.trim()||null,rest_on_body:a===`rest`&&R.trim()||null,rest_off_url:a===`rest`&&B.trim()||null,rest_off_body:a===`rest`&&ee.trim()||null,rest_method:a===`rest`?ne:null,rest_headers:a===`rest`&&ie.trim()||null,rest_status_url:a===`rest`&&oe.trim()||null,rest_status_path:a===`rest`&&H.trim()||null,rest_status_on_value:a===`rest`&&le.trim()||null,rest_power_url:a===`rest`&&de.trim()||null,rest_power_path:a===`rest`&&pe.trim()||null,rest_power_multiplier:a===`rest`&&parseFloat(he)||1,rest_energy_url:a===`rest`&&_e.trim()||null,rest_energy_path:a===`rest`&&ye.trim()||null,rest_energy_multiplier:a===`rest`&&parseFloat(xe)||1,rest_energy_total_path:a===`rest`&&Ce.trim()||null,rest_energy_total_multiplier:a===`rest`&&parseFloat(Te)||1,username:a===`tasmota`&&d.trim()||null,password:a===`tasmota`&&p.trim()||null,printer_id:tt,controls_printer_power:rt,power_alert_enabled:lt,power_alert_high:dt?parseFloat(dt):null,power_alert_low:pt?parseFloat(pt):null,schedule_enabled:ht,schedule_on_time:_t||null,schedule_off_time:yt||null,show_in_switchbar:xt,show_on_printer_card:Ct};i?Gt.mutate(t):Wt.mutate(t)},Jt=Wt.isPending||Gt.isPending;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 flex-shrink-0`,children:[(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:n(i?`smartPlugs.editTitle`:`smartPlugs.addTitle`)}),(0,G.jsx)(`button`,{onClick:t,className:`text-bambu-gray hover:text-white transition-colors`,children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]}),(0,G.jsxs)(`form`,{onSubmit:qt,className:`p-6 space-y-4 overflow-y-auto`,children:[st&&(0,G.jsx)(`div`,{className:`p-3 bg-red-100 dark:bg-red-500/20 border border-red-400 dark:border-red-500/50 rounded-lg text-sm text-red-700 dark:text-red-400`,children:st}),!i&&(0,G.jsxs)(`div`,{className:`flex gap-2 mb-2`,children:[(0,G.jsxs)(`button`,{type:`button`,onClick:()=>{o(`tasmota`),ot(null),ct(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2.5 rounded-lg font-medium transition-colors ${a===`tasmota`?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white border border-bambu-dark-tertiary`}`,children:[(0,G.jsx)(Pl,{className:`w-4 h-4`}),`Tasmota`]}),(0,G.jsxs)(`button`,{type:`button`,onClick:()=>{o(`homeassistant`),ot(null),ct(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2.5 rounded-lg font-medium transition-colors ${a===`homeassistant`?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white border border-bambu-dark-tertiary`}`,children:[(0,G.jsx)(Bc,{className:`w-4 h-4`}),`HA`]}),(0,G.jsxs)(`button`,{type:`button`,onClick:()=>{o(`mqtt`),ot(null),ct(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2.5 rounded-lg font-medium transition-colors ${a===`mqtt`?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white border border-bambu-dark-tertiary`}`,children:[(0,G.jsx)(Bl,{className:`w-4 h-4`}),`MQTT`]}),(0,G.jsxs)(`button`,{type:`button`,onClick:()=>{o(`rest`),ot(null),ct(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2.5 rounded-lg font-medium transition-colors ${a===`rest`?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white border border-bambu-dark-tertiary`}`,children:[(0,G.jsx)(Ac,{className:`w-4 h-4`}),`REST`]})]}),!i&&a===`tasmota`&&(0,G.jsxs)(`div`,{className:`space-y-3`,children:[Tt?(0,G.jsxs)(Q,{type:`button`,variant:`secondary`,onClick:Vt,className:`w-full`,children:[(0,G.jsx)(nd,{className:`w-4 h-4`}),n(`smartPlugs.stopScanning`)]}):(0,G.jsxs)(Q,{type:`button`,variant:`primary`,onClick:Bt,className:`w-full`,children:[(0,G.jsx)(Ql,{className:`w-4 h-4`}),n(`smartPlugs.discoverTasmota`)]}),Tt&&Dt.total>0&&(0,G.jsxs)(`div`,{className:`space-y-1`,children:[(0,G.jsxs)(`div`,{className:`flex justify-between text-xs text-bambu-gray`,children:[(0,G.jsx)(`span`,{children:n(`smartPlugs.addSmartPlug.scanningNetwork`)}),(0,G.jsxs)(`span`,{children:[Dt.scanned,` / `,Dt.total]})]}),(0,G.jsx)(`div`,{className:`w-full bg-bambu-dark-tertiary rounded-full h-2`,children:(0,G.jsx)(`div`,{className:`bg-bambu-green h-2 rounded-full transition-all duration-300`,style:{width:`${Dt.scanned/Dt.total*100}%`}})})]}),kt.length>0&&(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.foundDevices`,{count:kt.length})}),(0,G.jsx)(`div`,{className:`max-h-40 overflow-y-auto space-y-1`,children:kt.map(e=>(0,G.jsxs)(`button`,{type:`button`,onClick:()=>Ht(e),className:`w-full flex items-center justify-between p-2 bg-bambu-dark hover:bg-bambu-dark-tertiary rounded-lg transition-colors text-left border border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Pl,{className:`w-4 h-4 text-bambu-green`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:e.name}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:e.ip_address})]})]}),e.state&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-xs ${e.state===`ON`?`text-bambu-green`:`text-bambu-gray`}`,children:[(0,G.jsx)(Ll,{className:`w-3 h-3`}),e.state]})]},e.ip_address))})]}),!Tt&&kt.length===0&&Dt.total>0&&(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray text-center py-2`,children:n(`smartPlugs.noDevicesFound`)})]}),a===`homeassistant`&&(0,G.jsxs)(`div`,{className:`space-y-3`,children:[!Ft&&(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{className:`p-3 bg-yellow-100 dark:bg-yellow-500/20 border border-yellow-400 dark:border-yellow-500/50 rounded-lg text-sm text-yellow-700 dark:text-yellow-400`,children:[n(`smartPlugs.haNotConfigured`),` `,(0,G.jsx)(`span`,{className:`font-medium`,children:n(`smartPlugs.haSettingsPath`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1 opacity-50`,children:n(`smartPlugs.selectEntity`)}),(0,G.jsx)(`select`,{disabled:!0,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray cursor-not-allowed opacity-50`,children:(0,G.jsx)(`option`,{children:n(`smartPlugs.addSmartPlug.chooseEntity`)})})]})]}),Ft&&(0,G.jsxs)(G.Fragment,{children:[Lt&&(0,G.jsxs)(`div`,{className:`flex items-center justify-center py-4 text-bambu-gray`,children:[(0,G.jsx)(Y,{className:`w-5 h-5 animate-spin mr-2`}),n(`smartPlugs.loadingEntities`)]}),Rt&&(0,G.jsx)(`div`,{className:`p-3 bg-red-100 dark:bg-red-500/20 border border-red-400 dark:border-red-500/50 rounded-lg text-sm text-red-700 dark:text-red-400`,children:n(`smartPlugs.failedToLoadEntities`,{error:Rt.message})}),(()=>{let t=Nt?.filter(t=>t.ha_entity_id&&t.id!==e?.id).map(e=>e.ha_entity_id)||[],r=(It||[]).filter(e=>!t.includes(e.entity_id)),i=It?.find(e=>e.entity_id===h);return(0,G.jsxs)(`div`,{ref:ze,className:`relative`,children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.selectEntity`)}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(Ql,{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:Le?Ne:i?`${i.friendly_name} (${i.entity_id})`:``,onChange:e=>{Pe(e.target.value),Le||Re(!0)},onFocus:()=>{Re(!0),Pe(``)},placeholder:n(`smartPlugs.addSmartPlug.placeholders.searchEntities`),className:`w-full pl-9 pr-8 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`}),h&&!Le&&(0,G.jsx)(`button`,{type:`button`,onClick:()=>{g(``),Pe(``)},className:`absolute right-2 top-1/2 -translate-y-1/2 p-1 hover:bg-bambu-dark-tertiary rounded`,children:(0,G.jsx)(nd,{className:`w-4 h-4 text-bambu-gray hover:text-white`})}),Lt&&(0,G.jsx)(Y,{className:`absolute right-2 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray animate-spin`})]}),Le&&(0,G.jsxs)(`div`,{className:`absolute z-50 w-full mt-1 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-60 overflow-y-auto`,children:[Lt&&(0,G.jsxs)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray flex items-center gap-2`,children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),n(`smartPlugs.loading`)]}),!Lt&&r.length===0&&(0,G.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:Fe?n(`smartPlugs.noEntitiesMatching`,{search:Fe}):n(`smartPlugs.noEntitiesAvailable`)}),!Lt&&r.map(e=>(0,G.jsxs)(`button`,{type:`button`,onClick:()=>{g(e.entity_id),Re(!1),Pe(``),s||c(e.friendly_name)},className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary transition-colors ${e.entity_id===h?`bg-bambu-green/20 text-bambu-green`:`text-white`}`,children:[(0,G.jsx)(`div`,{className:`font-medium`,children:e.friendly_name}),(0,G.jsxs)(`div`,{className:`text-xs text-bambu-gray flex items-center justify-between`,children:[(0,G.jsx)(`span`,{children:e.entity_id}),(0,G.jsx)(`span`,{className:e.state===`on`?`text-bambu-green`:``,children:e.state})]})]},e.entity_id))]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(Fe?`smartPlugs.searchingEntities`:`smartPlugs.showingEntities`,{count:r.length})})]})})(),h&&zt&&zt.length>0&&(0,G.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary pt-4 mt-4 space-y-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white font-medium mb-1`,children:n(`smartPlugs.energyMonitoringOptional`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mb-3`,children:n(`smartPlugs.energyMonitoringHint`)})]}),(()=>{let e=zt.filter(e=>e.unit_of_measurement===`W`||e.unit_of_measurement===`kW`||e.unit_of_measurement===`mW`),t=Be?e.filter(e=>e.entity_id.toLowerCase().includes(Be.toLowerCase())||e.friendly_name.toLowerCase().includes(Be.toLowerCase())):e,r=zt.find(e=>e.entity_id===De);return(0,G.jsxs)(`div`,{ref:We,className:`relative`,children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.powerSensorW`)}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(Ql,{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:He?Be:r?`${r.friendly_name} (${r.state} ${r.unit_of_measurement})`:``,onChange:e=>{Ve(e.target.value),He||Ue(!0)},onFocus:()=>{Ue(!0),Ve(``)},placeholder:n(`smartPlugs.addSmartPlug.placeholders.searchPowerSensors`),className:`w-full pl-9 pr-8 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`}),De&&!He&&(0,G.jsx)(`button`,{type:`button`,onClick:()=>{Oe(``),Ve(``)},className:`absolute right-2 top-1/2 -translate-y-1/2 p-1 hover:bg-bambu-dark-tertiary rounded`,children:(0,G.jsx)(nd,{className:`w-4 h-4 text-bambu-gray hover:text-white`})})]}),He&&(0,G.jsxs)(`div`,{className:`absolute z-50 w-full mt-1 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-48 overflow-y-auto`,children:[(0,G.jsx)(`button`,{type:`button`,onClick:()=>{Oe(``),Ue(!1),Ve(``)},className:`w-full px-3 py-2 text-left text-sm text-bambu-gray hover:bg-bambu-dark-tertiary`,children:n(`smartPlugs.none`)}),t.map(e=>(0,G.jsxs)(`button`,{type:`button`,onClick:()=>{Oe(e.entity_id),Ue(!1),Ve(``)},className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${e.entity_id===De?`bg-bambu-green/20 text-bambu-green`:`text-white`}`,children:[(0,G.jsx)(`div`,{className:`font-medium`,children:e.friendly_name}),(0,G.jsxs)(`div`,{className:`text-xs text-bambu-gray`,children:[e.entity_id,` • `,e.state,` `,e.unit_of_measurement]})]},e.entity_id)),t.length===0&&(0,G.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:n(`smartPlugs.noMatchingSensors`)})]})]})})(),(()=>{let e=zt.filter(e=>e.unit_of_measurement===`kWh`||e.unit_of_measurement===`Wh`||e.unit_of_measurement===`MWh`),t=Ge?e.filter(e=>e.entity_id.toLowerCase().includes(Ge.toLowerCase())||e.friendly_name.toLowerCase().includes(Ge.toLowerCase())):e,r=zt.find(e=>e.entity_id===ke);return(0,G.jsxs)(`div`,{ref:Ye,className:`relative`,children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.energyTodayKwh`)}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(Ql,{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:qe?Ge:r?`${r.friendly_name} (${r.state} ${r.unit_of_measurement})`:``,onChange:e=>{Ke(e.target.value),qe||Je(!0)},onFocus:()=>{Je(!0),Ke(``)},placeholder:n(`smartPlugs.addSmartPlug.placeholders.searchEnergySensors`),className:`w-full pl-9 pr-8 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`}),ke&&!qe&&(0,G.jsx)(`button`,{type:`button`,onClick:()=>{Ae(``),Ke(``)},className:`absolute right-2 top-1/2 -translate-y-1/2 p-1 hover:bg-bambu-dark-tertiary rounded`,children:(0,G.jsx)(nd,{className:`w-4 h-4 text-bambu-gray hover:text-white`})})]}),qe&&(0,G.jsxs)(`div`,{className:`absolute z-50 w-full mt-1 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-48 overflow-y-auto`,children:[(0,G.jsx)(`button`,{type:`button`,onClick:()=>{Ae(``),Je(!1),Ke(``)},className:`w-full px-3 py-2 text-left text-sm text-bambu-gray hover:bg-bambu-dark-tertiary`,children:n(`smartPlugs.none`)}),t.map(e=>(0,G.jsxs)(`button`,{type:`button`,onClick:()=>{Ae(e.entity_id),Je(!1),Ke(``)},className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${e.entity_id===ke?`bg-bambu-green/20 text-bambu-green`:`text-white`}`,children:[(0,G.jsx)(`div`,{className:`font-medium`,children:e.friendly_name}),(0,G.jsxs)(`div`,{className:`text-xs text-bambu-gray`,children:[e.entity_id,` • `,e.state,` `,e.unit_of_measurement]})]},e.entity_id)),t.length===0&&(0,G.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:n(`smartPlugs.noMatchingSensors`)})]})]})})(),(()=>{let e=zt.filter(e=>e.unit_of_measurement===`kWh`||e.unit_of_measurement===`Wh`||e.unit_of_measurement===`MWh`),t=Xe?e.filter(e=>e.entity_id.toLowerCase().includes(Xe.toLowerCase())||e.friendly_name.toLowerCase().includes(Xe.toLowerCase())):e,r=zt.find(e=>e.entity_id===je);return(0,G.jsxs)(`div`,{ref:et,className:`relative`,children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.totalEnergyKwh`)}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(Ql,{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:Qe?Xe:r?`${r.friendly_name} (${r.state} ${r.unit_of_measurement})`:``,onChange:e=>{Ze(e.target.value),Qe||$e(!0)},onFocus:()=>{$e(!0),Ze(``)},placeholder:n(`smartPlugs.addSmartPlug.placeholders.searchEnergySensors`),className:`w-full pl-9 pr-8 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`}),je&&!Qe&&(0,G.jsx)(`button`,{type:`button`,onClick:()=>{Me(``),Ze(``)},className:`absolute right-2 top-1/2 -translate-y-1/2 p-1 hover:bg-bambu-dark-tertiary rounded`,children:(0,G.jsx)(nd,{className:`w-4 h-4 text-bambu-gray hover:text-white`})})]}),Qe&&(0,G.jsxs)(`div`,{className:`absolute z-50 w-full mt-1 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-48 overflow-y-auto`,children:[(0,G.jsx)(`button`,{type:`button`,onClick:()=>{Me(``),$e(!1),Ze(``)},className:`w-full px-3 py-2 text-left text-sm text-bambu-gray hover:bg-bambu-dark-tertiary`,children:n(`smartPlugs.none`)}),t.map(e=>(0,G.jsxs)(`button`,{type:`button`,onClick:()=>{Me(e.entity_id),$e(!1),Ze(``)},className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${e.entity_id===je?`bg-bambu-green/20 text-bambu-green`:`text-white`}`,children:[(0,G.jsx)(`div`,{className:`font-medium`,children:e.friendly_name}),(0,G.jsxs)(`div`,{className:`text-xs text-bambu-gray`,children:[e.entity_id,` • `,e.state,` `,e.unit_of_measurement]})]},e.entity_id)),t.length===0&&(0,G.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:n(`smartPlugs.noMatchingSensors`)})]})]})})()]})]})]}),a===`mqtt`&&(0,G.jsxs)(`div`,{className:`space-y-3`,children:[!Pt?.mqtt_broker&&(0,G.jsxs)(`div`,{className:`p-3 bg-yellow-100 dark:bg-yellow-500/20 border border-yellow-400 dark:border-yellow-500/50 rounded-lg text-sm text-yellow-700 dark:text-yellow-400`,children:[n(`smartPlugs.mqttNotConfigured`),` `,(0,G.jsx)(`span`,{className:`font-medium`,children:n(`smartPlugs.mqttSettingsPath`)}),` `,n(`smartPlugs.mqttNotConfiguredSuffix`)]}),Pt?.mqtt_broker&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`p-3 bg-blue-50 dark:bg-blue-500/10 border border-blue-300 dark:border-blue-500/30 rounded-lg text-sm text-blue-700 dark:text-blue-300`,children:[(0,G.jsx)(`p`,{className:`font-medium mb-1`,children:n(`smartPlugs.monitorOnly`)}),(0,G.jsx)(`p`,{className:`text-xs opacity-80`,children:n(`smartPlugs.mqttMonitorOnlyDescription`)})]}),(0,G.jsxs)(`div`,{className:`space-y-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,G.jsx)(`p`,{className:`text-white font-medium text-sm`,children:n(`smartPlugs.powerMonitoring`)}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.topic`)}),(0,G.jsx)(`input`,{type:`text`,value:_,onChange:e=>v(e.target.value),placeholder:`zigbee2mqtt/shelly-working-room`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.jsonPath`)}),(0,G.jsx)(`input`,{type:`text`,value:b,onChange:e=>x(e.target.value),placeholder:`power_l1`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.multiplier`)}),(0,G.jsx)(`input`,{type:`text`,value:S,onChange:e=>C(e.target.value),placeholder:`1`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,style:{whiteSpace:`pre-line`},children:n(`smartPlugs.mqttPowerHint`)})]}),(0,G.jsxs)(`div`,{className:`space-y-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`p`,{className:`text-white font-medium text-sm`,children:[n(`smartPlugs.energyMonitoring`),` `,(0,G.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,n(`smartPlugs.optional`),`)`]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.topic`)}),(0,G.jsx)(`input`,{type:`text`,value:w,onChange:e=>T(e.target.value),placeholder:`Same as power topic, or different`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.jsonPath`)}),(0,G.jsx)(`input`,{type:`text`,value:E,onChange:e=>D(e.target.value),placeholder:`energy_l1`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.multiplier`)}),(0,G.jsx)(`input`,{type:`text`,value:O,onChange:e=>k(e.target.value),placeholder:`1`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,style:{whiteSpace:`pre-line`},children:n(`smartPlugs.mqttEnergyHint`)})]}),(0,G.jsxs)(`div`,{className:`space-y-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`p`,{className:`text-white font-medium text-sm`,children:[n(`smartPlugs.stateMonitoring`),` `,(0,G.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,n(`smartPlugs.optional`),`)`]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.topic`)}),(0,G.jsx)(`input`,{type:`text`,value:A,onChange:e=>j(e.target.value),placeholder:`Same as power topic, or different`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.jsonPath`)}),(0,G.jsx)(`input`,{type:`text`,value:M,onChange:e=>N(e.target.value),placeholder:`state_l1`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.onValue`)}),(0,G.jsx)(`input`,{type:`text`,value:P,onChange:e=>F(e.target.value),placeholder:n(`smartPlugs.addSmartPlug.placeholders.mqttStateOnValue`),className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,style:{whiteSpace:`pre-line`},children:n(`smartPlugs.mqttStateHint`)})]})]})]}),a===`rest`&&(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{className:`space-y-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,G.jsx)(`p`,{className:`text-white font-medium text-sm`,children:n(`smartPlugs.restControl`)}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restMethod`)}),(0,G.jsxs)(`select`,{value:ne,onChange:e=>re(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,G.jsx)(`option`,{value:`GET`,children:`GET`}),(0,G.jsx)(`option`,{value:`POST`,children:`POST`}),(0,G.jsx)(`option`,{value:`PUT`,children:`PUT`}),(0,G.jsx)(`option`,{value:`PATCH`,children:`PATCH`})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restOnUrl`)}),(0,G.jsx)(`input`,{type:`text`,value:I,onChange:e=>{L(e.target.value),ot(null)},placeholder:`http://openhab:8080/rest/items/MyPlug`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[n(`smartPlugs.restOnBody`),` `,(0,G.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,n(`smartPlugs.optional`),`)`]})]}),(0,G.jsx)(`input`,{type:`text`,value:R,onChange:e=>z(e.target.value),placeholder:n(`smartPlugs.restBodyHint`),className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restOffUrl`)}),(0,G.jsx)(`input`,{type:`text`,value:B,onChange:e=>{V(e.target.value),ot(null)},placeholder:`http://openhab:8080/rest/items/MyPlug`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[n(`smartPlugs.restOffBody`),` `,(0,G.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,n(`smartPlugs.optional`),`)`]})]}),(0,G.jsx)(`input`,{type:`text`,value:ee,onChange:e=>te(e.target.value),placeholder:n(`smartPlugs.restBodyHint`),className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]})]}),(0,G.jsxs)(`div`,{className:`space-y-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`p`,{className:`text-white font-medium text-sm`,children:[n(`smartPlugs.restHeaders`),` `,(0,G.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,n(`smartPlugs.optional`),`)`]})]}),(0,G.jsx)(`div`,{children:(0,G.jsx)(`textarea`,{value:ie,onChange:e=>ae(e.target.value),placeholder:n(`smartPlugs.restHeadersHint`),rows:2,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none font-mono text-sm`})})]}),(0,G.jsxs)(`div`,{className:`space-y-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`p`,{className:`text-white font-medium text-sm`,children:[n(`smartPlugs.stateMonitoring`),` `,(0,G.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,n(`smartPlugs.optional`),`)`]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restStatusUrl`)}),(0,G.jsx)(`input`,{type:`text`,value:oe,onChange:e=>se(e.target.value),placeholder:n(`smartPlugs.restStatusHint`),className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restStatusPath`)}),(0,G.jsx)(`input`,{type:`text`,value:H,onChange:e=>ce(e.target.value),placeholder:n(`smartPlugs.restPathHint`),className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restStatusOnValue`)}),(0,G.jsx)(`input`,{type:`text`,value:le,onChange:e=>ue(e.target.value),placeholder:`ON`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]})]})]}),(0,G.jsxs)(`div`,{className:`space-y-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`p`,{className:`text-white font-medium text-sm`,children:[n(`smartPlugs.energyMonitoring`),` `,(0,G.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,n(`smartPlugs.optional`),`)`]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[n(`smartPlugs.restPowerUrl`),` `,(0,G.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,n(`smartPlugs.optional`),`)`]})]}),(0,G.jsx)(`input`,{type:`text`,value:de,onChange:e=>fe(e.target.value),placeholder:n(`smartPlugs.restPowerUrlHint`),className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restPowerPath`)}),(0,G.jsx)(`input`,{type:`text`,value:pe,onChange:e=>me(e.target.value),placeholder:n(`smartPlugs.restPathHint`),className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restPowerMultiplier`)}),(0,G.jsx)(`input`,{type:`text`,value:he,onChange:e=>ge(e.target.value),placeholder:`1`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[n(`smartPlugs.restEnergyUrl`),` `,(0,G.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,n(`smartPlugs.optional`),`)`]})]}),(0,G.jsx)(`input`,{type:`text`,value:_e,onChange:e=>ve(e.target.value),placeholder:n(`smartPlugs.restEnergyUrlHint`),className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restEnergyPath`)}),(0,G.jsx)(`input`,{type:`text`,value:ye,onChange:e=>be(e.target.value),placeholder:n(`smartPlugs.restPathHint`),className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restEnergyMultiplier`)}),(0,G.jsx)(`input`,{type:`text`,value:xe,onChange:e=>Se(e.target.value),placeholder:`1`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.restEnergyHint`)}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restEnergyTotalPath`)}),(0,G.jsx)(`input`,{type:`text`,value:Ce,onChange:e=>we(e.target.value),placeholder:n(`smartPlugs.restEnergyTotalPathHint`),className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restEnergyTotalMultiplier`)}),(0,G.jsx)(`input`,{type:`text`,value:Te,onChange:e=>Ee(e.target.value),placeholder:`1`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.restEnergyTotalHint`)})]}),(I.trim()||B.trim())&&(0,G.jsx)(`div`,{className:`flex gap-2`,children:(0,G.jsxs)(Q,{type:`button`,variant:`secondary`,onClick:async()=>{ot(null);try{let e=I.trim()||B.trim(),t=await Z.testRESTConnection(e,ne,ie.trim()||null);ot({success:t.success}),t.success||ct(t.error||n(`smartPlugs.addSmartPlug.connectionFailed`))}catch{ot({success:!1}),ct(n(`smartPlugs.addSmartPlug.connectionFailed`))}},className:`w-full`,children:[(0,G.jsx)(Qu,{className:`w-4 h-4`}),n(`smartPlugs.testConnection`)]})}),at&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm ${at.success?`text-green-700 dark:text-green-400`:`text-red-700 dark:text-red-400`}`,children:[at.success?(0,G.jsx)(xs,{className:`w-4 h-4`}):(0,G.jsx)(Zu,{className:`w-4 h-4`}),at.success?n(`smartPlugs.connectionSuccess`):n(`smartPlugs.addSmartPlug.connectionFailed`)]})]}),a===`tasmota`&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.ipAddress`)}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsx)(`input`,{type:`text`,value:l,onChange:e=>{u(e.target.value),ot(null)},placeholder:`192.168.1.100`,className:`flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,G.jsxs)(Q,{type:`button`,variant:`secondary`,onClick:()=>Ut.mutate(),disabled:!l.trim()||Ut.isPending,children:[Ut.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Qu,{className:`w-4 h-4`}),n(`smartPlugs.test`)]})]})]}),a===`tasmota`&&at&&(0,G.jsx)(`div`,{className:`p-3 rounded-lg flex items-center gap-2 ${at.success?`bg-bambu-green/20 border border-bambu-green/50 text-bambu-green`:`bg-red-100 dark:bg-red-500/20 border border-red-400 dark:border-red-500/50 text-red-700 dark:text-red-400`}`,children:at.success?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(xs,{className:`w-5 h-5`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`font-medium`,children:n(`smartPlugs.connectedResult`)}),(0,G.jsxs)(`p`,{className:`text-sm opacity-80`,children:[at.device_name&&n(`smartPlugs.deviceLabel`,{name:at.device_name}),n(`smartPlugs.stateLabel`,{state:at.state})]})]})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Zu,{className:`w-5 h-5`}),(0,G.jsx)(`span`,{children:n(`smartPlugs.addSmartPlug.connectionFailed`)})]})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.nameLabel`)}),(0,G.jsx)(`input`,{type:`text`,value:s,onChange:e=>c(e.target.value),placeholder:n(`smartPlugs.addSmartPlug.placeholders.plugName`),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),a===`tasmota`&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.username`)}),(0,G.jsx)(`input`,{type:`text`,value:d,onChange:e=>f(e.target.value),placeholder:`admin`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.password`)}),(0,G.jsx)(`input`,{type:`password`,value:p,onChange:e=>m(e.target.value),placeholder:`********`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray -mt-2`,children:n(`smartPlugs.authHint`)})]}),a!==`mqtt`&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.linkToPrinter`)}),(0,G.jsxs)(`select`,{value:tt??``,onChange:e=>nt(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:n(`smartPlugs.noPrinter`)}),Kt?.map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(`smartPlugs.linkingDescription`)}),tt!==null&&(0,G.jsxs)(`div`,{className:`flex items-center justify-between mt-3`,children:[(0,G.jsxs)(`div`,{className:`pr-3`,children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`smartPlugs.controlsPrinterPower`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.controlsPrinterPowerDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer shrink-0`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:rt,onChange:e=>it(e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]})]}),(0,G.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary pt-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(qo,{className:`w-4 h-4 text-bambu-green`}),(0,G.jsx)(`span`,{className:`text-white font-medium`,children:n(`smartPlugs.powerAlerts`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:lt,onChange:e=>ut(e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),lt&&(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.alertAbove`)}),(0,G.jsx)(`input`,{type:`number`,value:dt,onChange:e=>ft(e.target.value),placeholder:`e.g. 200`,min:`0`,max:`5000`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.alertBelow`)}),(0,G.jsx)(`input`,{type:`number`,value:pt,onChange:e=>mt(e.target.value),placeholder:`e.g. 10`,min:`0`,max:`5000`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.alertDescription`)})]})]}),a!==`mqtt`&&(0,G.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary pt-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(js,{className:`w-4 h-4 text-bambu-green`}),(0,G.jsx)(`span`,{className:`text-white font-medium`,children:n(`smartPlugs.dailySchedule`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:ht,onChange:e=>gt(e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),ht&&(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.turnOnAt`)}),(0,G.jsx)(`input`,{type:`time`,value:_t,onChange:e=>vt(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.turnOffAt`)}),(0,G.jsx)(`input`,{type:`time`,value:yt,onChange:e=>bt(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.scheduleDescription`)})]})]}),(0,G.jsx)(`div`,{className:`border-t border-bambu-dark-tertiary pt-4`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Yc,{className:`w-4 h-4 text-bambu-green`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-white font-medium`,children:n(`smartPlugs.showInSwitchbar`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.quickAccessSidebar`)})]})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:xt,onChange:e=>St(e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]})}),a===`homeassistant`&&(0,G.jsx)(`div`,{className:`border-t border-bambu-dark-tertiary pt-4`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(ac,{className:`w-4 h-4 text-bambu-green`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-white font-medium`,children:n(`smartPlugs.showOnPrinterCard`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.displayOnPrinterCard`)})]})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:Ct,onChange:e=>wt(e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]})}),(0,G.jsxs)(`div`,{className:`flex gap-3 pt-2`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:t,className:`flex-1`,children:n(`smartPlugs.cancel`)}),(0,G.jsxs)(Q,{type:`submit`,disabled:Jt,className:`flex-1`,children:[Jt?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(ql,{className:`w-4 h-4`}),n(i?`smartPlugs.save`:`smartPlugs.add`)]})]})]})]})})}function IWe({sensor:e,printers:t,onClose:n}){let{t:r}=U(),i=co(),{showToast:a}=qd(),o=!!e,[s,c]=(0,y.useState)(e?.printer_id??t[0]?.id??``),[l,u]=(0,y.useState)(e?.entity_id??``),[d,f]=(0,y.useState)(e?.kind??`binary`),[p,m]=(0,y.useState)(e?.device_class??null),[h,g]=(0,y.useState)(e?.unit??null),[_,v]=(0,y.useState)(e?.name??``),[b,x]=(0,y.useState)(e?.alert_state??``),[S,C]=(0,y.useState)(e?.alert_above?.toString()??``),[w,T]=(0,y.useState)(e?.alert_below?.toString()??``),[E,D]=(0,y.useState)(e?.show_on_printer_card??!0),[O,k]=(0,y.useState)(e?.notify_on_alert??!1),[A,j]=(0,y.useState)(e?.block_print??!1),[M,N]=(0,y.useState)(``),[P,F]=(0,y.useState)(null);(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[n]);let{data:I}=K({queryKey:[`settings`],queryFn:Z.getSettings}),L=!!(I?.ha_enabled&&I?.ha_url&&I?.ha_token),{data:R,isLoading:z,error:B}=K({queryKey:[`bindableHAEntities`],queryFn:()=>Z.getBindableHAEntities(),enabled:L}),V=(0,y.useMemo)(()=>{let e=M.trim().toLowerCase(),t=R??[];return e?t.filter(t=>t.entity_id.toLowerCase().includes(e)||t.friendly_name.toLowerCase().includes(e)):t},[R,M]),ee=e=>{u(e.entity_id),m(e.device_class),g(e.unit_of_measurement);let t=e.domain===`binary_sensor`?`binary`:`numeric`;f(t),t===`numeric`?x(``):(C(``),T(``)),_.trim()||v(e.friendly_name.slice(0,100))},te=()=>{i.invalidateQueries({queryKey:[`haSensors`]}),i.invalidateQueries({queryKey:[`haSensorReadings`]})},ne=q({mutationFn:()=>{let t={name:_.trim(),entity_id:l,kind:d,device_class:p,unit:h,alert_state:d===`binary`&&b?b:null,alert_above:d===`numeric`&&S!==``?Number(S):null,alert_below:d===`numeric`&&w!==``?Number(w):null,block_print:A,notify_on_alert:O,show_on_printer_card:E};return o?Z.updateHASensor(e.id,t):Z.createHASensor({...t,printer_id:Number(s)})},onSuccess:()=>{te(),a(r(o?`haSensors.toast.updated`:`haSensors.toast.created`),`success`),n()},onError:e=>F(e.message)}),re=q({mutationFn:()=>Z.deleteHASensor(e.id),onSuccess:()=>{te(),a(r(`haSensors.toast.deleted`),`success`),n()},onError:e=>F(e.message)}),ie=d===`binary`?b!==``:S!==``||w!==``,ae=e=>{if(e.preventDefault(),F(null),!l)return F(r(`haSensors.error.pickEntity`));if(!_.trim())return F(r(`haSensors.error.nameRequired`));if(s===``)return F(r(`haSensors.error.printerRequired`));if((A||O)&&!ie)return F(r(`haSensors.error.alertRequired`));ne.mutate()},oe=MT[p??``],se=e=>{let t=oe?.[e]??e;return r(`haSensors.states.${t}`,{defaultValue:t})},H=ne.isPending||re.isPending;return(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-lg max-h-[90vh] overflow-y-auto`,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-3`,children:[(0,G.jsx)(`div`,{className:`p-2 rounded-full bg-bambu-green/20 text-bambu-green`,children:(0,G.jsx)(Tc,{className:`w-5 h-5`})}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:r(o?`haSensors.editTitle`:`haSensors.addTitle`)})]}),(0,G.jsx)(`button`,{onClick:n,className:`text-bambu-gray hover:text-white transition-colors`,children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]}),(0,G.jsxs)(`form`,{onSubmit:ae,className:`p-6 space-y-4`,children:[P&&(0,G.jsx)(`div`,{className:`p-3 bg-red-100 dark:bg-red-500/20 border border-red-300 dark:border-red-500/50 rounded-lg text-sm text-red-700 dark:text-red-400`,children:P}),!o&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`haSensors.printer`)}),(0,G.jsx)(`select`,{value:s,onChange:e=>c(e.target.value===``?``:Number(e.target.value)),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white`,children:t.map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.name},e.id))})]}),!L&&(0,G.jsxs)(`div`,{className:`p-3 bg-yellow-100 dark:bg-yellow-500/20 border border-yellow-400 dark:border-yellow-500/50 rounded-lg text-sm text-yellow-700 dark:text-yellow-400`,children:[r(`smartPlugs.haNotConfigured`),` `,(0,G.jsx)(`span`,{className:`font-medium`,children:r(`smartPlugs.haSettingsPath`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1 ${L?``:`opacity-50`}`,children:r(`haSensors.entity`)}),B&&(0,G.jsx)(`div`,{className:`p-3 mb-2 bg-red-100 dark:bg-red-500/20 rounded-lg text-sm text-red-700 dark:text-red-400`,children:B.message}),(0,G.jsxs)(`div`,{className:`relative mb-2`,children:[(0,G.jsx)(Ql,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,G.jsx)(`input`,{type:`text`,value:M,onChange:e=>N(e.target.value),placeholder:r(`haSensors.searchPlaceholder`),disabled:!L,className:`w-full pl-9 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white disabled:opacity-50 disabled:cursor-not-allowed`})]}),(0,G.jsxs)(`div`,{className:`max-h-44 overflow-y-auto rounded-lg border border-bambu-dark-tertiary ${L?``:`opacity-50`}`,children:[!L&&(0,G.jsx)(`div`,{className:`p-3 text-sm text-bambu-gray`,children:r(`haSensors.noEntities`)}),L&&z&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2 p-3 text-sm text-bambu-gray`,children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),r(`common.loading`)]}),L&&!z&&V.length===0&&(0,G.jsx)(`div`,{className:`p-3 text-sm text-bambu-gray`,children:r(`haSensors.noEntities`)}),L&&!z&&V.map(e=>(0,G.jsxs)(`button`,{type:`button`,onClick:()=>ee(e),className:`w-full text-left px-3 py-2 text-sm transition-colors ${e.entity_id===l?`bg-bambu-green/20 text-bambu-green`:`text-white hover:bg-bambu-dark`}`,children:[(0,G.jsx)(`div`,{className:`font-medium`,children:e.friendly_name}),(0,G.jsxs)(`div`,{className:`text-xs text-bambu-gray`,children:[e.entity_id,e.state!==null&&` — ${e.state}`,e.unit_of_measurement?` ${e.unit_of_measurement}`:``]})]},e.entity_id))]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`haSensors.name`)}),(0,G.jsx)(`input`,{type:`text`,value:_,onChange:e=>v(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`haSensors.alertWhen`)}),d===`binary`?(0,G.jsxs)(`select`,{value:b,onChange:e=>x(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white`,children:[(0,G.jsx)(`option`,{value:``,children:r(`haSensors.alertNever`)}),(0,G.jsx)(`option`,{value:`on`,children:se(`on`)}),(0,G.jsx)(`option`,{value:`off`,children:se(`off`)})]}):(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`span`,{className:`block text-xs text-bambu-gray mb-1`,children:[r(`haSensors.alertAbove`),` `,h??``]}),(0,G.jsx)(`input`,{type:`number`,step:`any`,value:S,onChange:e=>C(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`span`,{className:`block text-xs text-bambu-gray mb-1`,children:[r(`haSensors.alertBelow`),` `,h??``]}),(0,G.jsx)(`input`,{type:`number`,step:`any`,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`})]})]}),(0,G.jsx)(`p`,{className:`mt-1 text-xs text-bambu-gray`,children:r(`haSensors.alertHint`)})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:E,onChange:e=>D(e.target.checked),className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`text-sm text-white`,children:r(`haSensors.showOnCard`)})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:O,onChange:e=>k(e.target.checked),disabled:!ie,className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`text-sm ${ie?`text-white`:`text-bambu-gray`}`,children:r(`haSensors.notifyOnAlert`)})]}),(0,G.jsxs)(`label`,{className:`flex items-start gap-3 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A,onChange:e=>j(e.target.checked),disabled:!ie,className:`w-4 h-4 mt-0.5`}),(0,G.jsxs)(`span`,{children:[(0,G.jsx)(`span`,{className:`block text-sm ${ie?`text-white`:`text-bambu-gray`}`,children:r(`haSensors.blockPrint`)}),(0,G.jsx)(`span`,{className:`block text-xs text-bambu-gray`,children:r(`haSensors.blockPrintHint`)})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between pt-2`,children:[o?(0,G.jsx)(Q,{type:`button`,variant:`danger`,onClick:()=>re.mutate(),disabled:H,children:r(`common.delete`)}):(0,G.jsx)(`span`,{}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:n,disabled:H,children:r(`common.cancel`)}),(0,G.jsxs)(Q,{type:`submit`,disabled:H||!L&&!o,children:[H?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(ql,{className:`w-4 h-4`}),r(`common.save`)]})]})]})]})]})})}function Z6({open:e,onClose:t,onPickLocation:n,startCreating:r}){let{t:i}=U(),a=co(),{showToast:o}=qd(),[s,c]=(0,y.useState)(!1),[l,u]=(0,y.useState)(null),[d,f]=(0,y.useState)(``),[p,m]=(0,y.useState)(null),{data:h=[],isLoading:g}=K({queryKey:v6,queryFn:Z.getLocations,enabled:e}),{data:_=[]}=K({queryKey:[`locationHaSensors`],queryFn:()=>Z.getLocationHASensors(),enabled:e}),v=_.reduce((e,t)=>(e[t.location_id]=(e[t.location_id]??0)+1,e),{}),b=()=>{y6(a),a.invalidateQueries({queryKey:[`inventory-spools`]}),a.invalidateQueries({queryKey:[`spoolman-inventory-spools`]}),a.invalidateQueries({queryKey:[`locationHaSensors`]}),a.invalidateQueries({queryKey:[`locationHaSensorReadings`]})},x=q({mutationFn:async()=>{let e=d.trim();if(!e)throw Error(i(`locations.nameRequired`));return l?Z.updateLocation(l.id,{name:e}):Z.createLocation({name:e})},onSuccess:e=>{if(o(i(l?`locations.updated`:`locations.created`),`success`),b(),!l&&r){n?.(e.id),t();return}c(!1),u(null),f(``)},onError:e=>{o(e.message||i(`locations.saveFailed`),`error`)}}),S=q({mutationFn:e=>Z.deleteLocation(e),onSuccess:()=>{o(i(`locations.deleted`),`success`),m(null),b()},onError:e=>{o(e.message||i(`locations.deleteFailed`),`error`)}}),C=()=>{u(null),f(``),c(!0)};(0,y.useEffect)(()=>{e&&r&&(u(null),f(``),c(!0))},[e,r]);let w=e=>{u(e),f(e.name),c(!0)},T=(0,y.useCallback)(()=>{if(!x.isPending){if(r){t();return}c(!1),u(null),f(``)}},[x.isPending,r,t]);(0,y.useEffect)(()=>{if(!e)return;let n=e=>{e.key===`Escape`&&(x.isPending||S.isPending||(s?T():p||t()))};return document.addEventListener(`keydown`,n),()=>document.removeEventListener(`keydown`,n)},[e,s,p,x.isPending,S.isPending,T,t]);let E=e=>{e.preventDefault(),x.mutate()};if(!e)return null;let D=`locations-modal-title`,O=`location-editor-title`,k=(0,G.jsxs)(`form`,{onSubmit:E,children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,htmlFor:`location-name`,children:i(`locations.name`)}),(0,G.jsx)(`input`,{id:`location-name`,type:`text`,maxLength:255,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green mb-4`,placeholder:i(`locations.createPlaceholder`),value:d,onChange:e=>f(e.target.value),autoFocus:!0}),(0,G.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:T,children:i(`common.cancel`)}),(0,G.jsxs)(Q,{type:`submit`,disabled:x.isPending||!d.trim(),children:[x.isPending&&(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),i(`common.save`)]})]})]});return r?s?(0,G.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[(0,G.jsx)(`div`,{className:`absolute inset-0 bg-black/60`,onClick:T}),(0,G.jsxs)(`div`,{className:`relative w-full max-w-md mx-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl p-6 shadow-2xl`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":O,children:[(0,G.jsx)(`h3`,{id:O,className:`text-lg font-semibold text-white mb-4`,children:i(`locations.add`)}),k]})]}):null:(0,G.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[(0,G.jsx)(`div`,{className:`absolute inset-0 bg-black/60`,onClick:()=>{x.isPending||S.isPending||t()}}),(0,G.jsxs)(`div`,{className:`relative w-full max-w-2xl mx-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl shadow-2xl max-h-[90vh] flex flex-col`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":D,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-4 px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`h2`,{id:D,className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(ol,{className:`w-5 h-5 text-bambu-green`}),i(`locations.title`)]}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-sm mt-0.5`,children:i(`locations.subtitle`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(Q,{onClick:C,children:[(0,G.jsx)(Fl,{className:`w-4 h-4`}),i(`locations.add`)]}),(0,G.jsx)(`button`,{type:`button`,className:`p-1.5 text-bambu-gray hover:text-white rounded`,onClick:t,"aria-label":i(`common.close`),children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]})]}),(0,G.jsx)(`div`,{className:`overflow-y-auto`,children:g?(0,G.jsxs)(`div`,{className:`flex items-center justify-center py-16 text-bambu-gray`,children:[(0,G.jsx)(Y,{className:`w-6 h-6 animate-spin mr-2`}),i(`common.loading`)]}):h.length===0?(0,G.jsx)(`div`,{className:`py-16 text-center text-bambu-gray`,children:i(`locations.empty`)}):(0,G.jsxs)(`table`,{className:`w-full text-sm table-fixed`,children:[(0,G.jsx)(`thead`,{children:(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary text-left text-bambu-gray`,children:[(0,G.jsx)(`th`,{className:`px-4 py-3 font-medium`,children:i(`locations.name`)}),(0,G.jsx)(`th`,{className:`px-2 py-3 font-medium text-right w-24`,children:i(`locations.sensors`)}),(0,G.jsx)(`th`,{className:`pl-[28px] pr-4 py-3 font-medium text-right w-28`,children:i(`locations.spools`)}),(0,G.jsx)(`th`,{className:`px-4 py-3 font-medium text-right w-32`,children:i(`common.actions`)})]})}),(0,G.jsx)(`tbody`,{children:h.map(e=>(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/60 hover:bg-bambu-dark-tertiary/30 cursor-pointer`,onClick:()=>{n&&(n(e.id),t())},children:[(0,G.jsx)(`td`,{className:`px-4 py-3 text-white font-medium truncate`,children:e.name}),(0,G.jsx)(`td`,{className:`px-2 py-3 text-right text-bambu-gray`,children:v[e.id]??0}),(0,G.jsx)(`td`,{className:`pl-[28px] pr-4 py-3 text-right text-bambu-gray`,children:e.spool_count}),(0,G.jsx)(`td`,{className:`px-4 py-3 text-right`,onClick:e=>e.stopPropagation(),children:(0,G.jsxs)(`div`,{className:`flex items-center justify-end gap-1`,children:[(0,G.jsx)(`button`,{type:`button`,className:`p-1.5 text-bambu-gray hover:text-bambu-green rounded`,onClick:()=>w(e),title:i(`common.edit`),"aria-label":i(`locations.editAria`,{name:e.name,defaultValue:`Edit ${e.name}`}),children:(0,G.jsx)(Al,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{type:`button`,className:`p-1.5 text-bambu-gray hover:text-red-600 dark:hover:text-red-400 rounded disabled:opacity-40`,disabled:e.spool_count>0,onClick:()=>m(e),title:e.spool_count>0?i(`locations.deleteBlocked`):i(`common.delete`),"aria-label":i(`locations.deleteAria`,{name:e.name,defaultValue:`Delete ${e.name}`}),children:(0,G.jsx)(Pu,{className:`w-4 h-4`})})]})})]},e.id))})]})})]}),s&&(0,G.jsxs)(`div`,{className:`fixed inset-0 z-[60] flex items-center justify-center`,children:[(0,G.jsx)(`div`,{className:`absolute inset-0 bg-black/60`,onClick:T}),(0,G.jsxs)(`div`,{className:`relative w-full max-w-md mx-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl p-6 shadow-2xl`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":O,children:[(0,G.jsx)(`h3`,{id:O,className:`text-lg font-semibold text-white mb-4`,children:i(l?`locations.edit`:`locations.add`)}),k]})]}),p&&(0,G.jsx)(of,{title:i(`locations.confirmDelete`,{name:p.name}),message:v[p.id]?i(`locations.confirmDeleteMessageWithSensors`):i(`locations.confirmDeleteMessage`),confirmText:i(`common.delete`),variant:`danger`,isLoading:S.isPending,onConfirm:()=>S.mutate(p.id),onCancel:()=>m(null)})]})}function Q6(e){return e===`temperature`?`temperature`:e===`humidity`?`humidity`:e===`battery`?`battery`:null}var $6={temperature:`temperature`,humidity:`humidity`,battery:`battery`};function LWe(e,t,n){let r=$6[t];if(!e.toLowerCase().endsWith(r))return[];let i=e.slice(0,e.length-r.length),a=[];return Object.keys($6).forEach(e=>{if(e===t)return;let r=`${i}${$6[e]}`.toLowerCase(),o=n.find(e=>e.entity_id.toLowerCase()===r);o&&a.push(o)}),a}function RWe({sensor:e,locations:t,onClose:n}){let{t:r}=U(),i=co(),{showToast:a}=qd(),o=!!e,[s,c]=(0,y.useState)(e?.location_id??t[0]?.id??``),[l,u]=(0,y.useState)(e?.entity_id??``),[d,f]=(0,y.useState)(e?.kind??`numeric`),[p,m]=(0,y.useState)(e?.device_class??null),[h,g]=(0,y.useState)(e?.unit??null),[_,v]=(0,y.useState)(e?.name??``),b=(0,y.useRef)(e?.name??``),[x,S]=(0,y.useState)(e?.alert_state??``),[C,w]=(0,y.useState)(e?.alert_above?.toString()??``),[T,E]=(0,y.useState)(e?.alert_below?.toString()??``),[D,O]=(0,y.useState)(e?.notify_on_alert??!1),[k,A]=(0,y.useState)(e?.show_on_card??!0),[j,M]=(0,y.useState)(``),[N,P]=(0,y.useState)(null),[F,I]=(0,y.useState)(!1),[L,R]=(0,y.useState)(!1),[z,B]=(0,y.useState)(null),[V,ee]=(0,y.useState)(!1),[te,ne]=(0,y.useState)([]),[re,ie]=(0,y.useState)({}),{data:ae}=K({queryKey:[`settings`],queryFn:Z.getSettings}),oe=!!(ae?.ha_enabled&&ae?.ha_url&&ae?.ha_token),{data:se,isLoading:H,error:ce}=K({queryKey:[`bindableLocationHAEntities`],queryFn:()=>Z.getBindableLocationHAEntities(),enabled:oe}),le=(0,y.useMemo)(()=>(se??[]).filter(e=>Q6(e.device_class)!==null),[se]),{data:ue}=K({queryKey:[`locationHaSensors`],queryFn:()=>Z.getLocationHASensors()}),de=le.find(e=>e.entity_id===l),fe=(0,y.useMemo)(()=>{let e=j.trim().toLowerCase(),t=le??[],n=e?t.filter(t=>t.entity_id.toLowerCase().includes(e)||t.friendly_name.toLowerCase().includes(e)):t;return!de||n[0]?.entity_id===de.entity_id?n:[de,...n.filter(e=>e.entity_id!==de.entity_id)]},[le,j,de]),pe=e=>{u(e.entity_id),m(e.device_class),g(e.unit_of_measurement?.slice(0,16)??null);let t=e.domain===`binary_sensor`?`binary`:`numeric`;if(f(t),t===`numeric`?S(``):(w(``),E(``)),_===b.current){let t=e.friendly_name.slice(0,100);v(t),b.current=t}if(!o){let n=Q6(e.device_class);if(n){let e=C6(ae?.location_sensor_alert_defaults)[n];t===`numeric`&&(w(n===`battery`?``:e.alertAbove),E(e.alertBelow)),O(e.notifyOnAlert),A(e.showOnCard)}}},me=()=>{i.invalidateQueries({queryKey:[`locationHaSensors`]}),i.invalidateQueries({queryKey:[`locationHaSensorReadings`]})},he=()=>({name:_.trim(),entity_id:l,kind:d,device_class:p,unit:h,alert_state:d===`binary`&&x?x:null,alert_above:d===`numeric`&&Q6(p)!==`battery`&&C!==``?Number(C):null,alert_below:d===`numeric`&&T!==``?Number(T):null,notify_on_alert:D,show_on_card:k}),ge=q({mutationFn:()=>{let t=he();return o?Z.updateLocationHASensor(e.id,t):Z.createLocationHASensor({...t,location_id:Number(s)})},onSuccess:()=>{me(),a(r(o?`locationHaSensors.toast.updated`:`locationHaSensors.toast.created`),`success`),n()},onError:e=>P(e.message)}),_e=q({mutationFn:async()=>{let e=Number(s);await Z.createLocationHASensor({...he(),location_id:e});let t=C6(ae?.location_sensor_alert_defaults),n=te.filter(e=>re[e.entity_id]);for(let r of n){let n=Q6(r.device_class),i=n?t[n]:null;await Z.createLocationHASensor({name:r.friendly_name.slice(0,100),entity_id:r.entity_id,kind:r.domain===`binary_sensor`?`binary`:`numeric`,device_class:r.device_class,unit:r.unit_of_measurement?.slice(0,16)??null,alert_state:null,alert_above:n!==`battery`&&i&&i.alertAbove!==``?Number(i.alertAbove):null,alert_below:i&&i.alertBelow!==``?Number(i.alertBelow):null,notify_on_alert:i?.notifyOnAlert??!1,show_on_card:i?.showOnCard??k,location_id:e})}return n},onSuccess:e=>{me(),ee(!1),e.length>0?a(r(`locationHaSensors.autoAdd.added`,{names:e.map(e=>e.entity_id).join(`, `)}),`success`):a(r(`locationHaSensors.toast.created`),`success`),n()},onError:e=>{me(),ee(!1),P(e.message)}}),ve=q({mutationFn:()=>Z.deleteLocationHASensor(e.id),onSuccess:()=>{me(),a(r(`locationHaSensors.toast.deleted`),`success`),n()},onError:e=>P(e.message)}),ye=q({mutationFn:()=>Z.updateLocationHASensor(z.id,he()),onSuccess:()=>{me(),R(!1),B(null),a(r(`locationHaSensors.toast.updated`),`success`),n()},onError:e=>{R(!1),B(null),P(e.message)}}),be=d===`binary`?x!==``:C!==``||T!==``,xe=e=>{if(e.preventDefault(),P(null),!l)return P(r(`haSensors.error.pickEntity`));if(!_.trim())return P(r(`haSensors.error.nameRequired`));if(s===``)return P(r(`locationHaSensors.error.locationRequired`));if(D&&!be)return P(r(`haSensors.error.alertRequired`));if(!o){let e=(ue??[]).filter(e=>e.location_id===Number(s)),t=Q6(p);if(t){let n=e.find(e=>Q6(e.device_class)===t);if(n){B(n),R(!0);return}}if(e.length===0&&t){let e=LWe(l,t,le);if(e.length>0){ne(e),ie(Object.fromEntries(e.map(e=>[e.entity_id,!0]))),ee(!0);return}a(r(`locationHaSensors.autoAdd.noneFound`),`info`)}}ge.mutate()},Se=MT[p??``],Ce=e=>{let t=Se?.[e]??e;return r(`haSensors.states.${t}`,{defaultValue:t})},we=ge.isPending||ve.isPending||ye.isPending||_e.isPending,Te=t.find(e=>e.id===Number(s));return(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&!we&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[n,we]),(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:()=>{we||n()},children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-lg max-h-[90vh] overflow-y-auto`,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-3`,children:[(0,G.jsx)(`div`,{className:`p-2 rounded-full bg-bambu-green/20 text-bambu-green`,children:(0,G.jsx)(Tc,{className:`w-5 h-5`})}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:r(o?`locationHaSensors.editTitle`:`locationHaSensors.addTitle`)})]}),(0,G.jsx)(`button`,{onClick:n,disabled:we,className:`text-bambu-gray hover:text-white transition-colors disabled:opacity-50 disabled:cursor-not-allowed`,children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]}),(0,G.jsxs)(`form`,{onSubmit:xe,className:`p-6 space-y-4`,children:[N&&(0,G.jsx)(`div`,{className:`p-3 bg-red-100 dark:bg-red-500/20 border border-red-300 dark:border-red-500/50 rounded-lg text-sm text-red-700 dark:text-red-400`,children:N}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`locationHaSensors.location`)}),o?(0,G.jsx)(`div`,{className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white`,children:t.find(t=>t.id===e.location_id)?.name??r(`locationHaSensors.unknownLocation`)}):(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`select`,{value:s,onChange:e=>c(e.target.value===``?``:Number(e.target.value)),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white`,children:t.map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.name},e.id))}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>I(!0),className:`p-2 rounded-lg bg-bambu-dark-tertiary hover:bg-bambu-gray-dark text-white transition-colors shrink-0`,title:r(`locations.add`),"aria-label":r(`locations.add`),children:(0,G.jsx)(Fl,{className:`w-4 h-4`})})]})]}),!oe&&(0,G.jsxs)(`div`,{className:`p-3 bg-yellow-100 dark:bg-yellow-500/20 border border-yellow-400 dark:border-yellow-500/50 rounded-lg text-sm text-yellow-700 dark:text-yellow-400`,children:[r(`smartPlugs.haNotConfigured`),` `,(0,G.jsx)(`span`,{className:`font-medium`,children:r(`smartPlugs.haSettingsPath`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1 ${oe?``:`opacity-50`}`,children:r(`haSensors.entity`)}),ce&&(0,G.jsx)(`div`,{className:`p-3 mb-2 bg-red-100 dark:bg-red-500/20 rounded-lg text-sm text-red-700 dark:text-red-400`,children:ce.message}),(0,G.jsxs)(`div`,{className:`relative mb-2`,children:[(0,G.jsx)(Ql,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,G.jsx)(`input`,{type:`text`,value:j,onChange:e=>M(e.target.value),placeholder:r(`haSensors.searchPlaceholder`),disabled:!oe,className:`w-full pl-9 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white disabled:opacity-50 disabled:cursor-not-allowed`})]}),(0,G.jsxs)(`div`,{className:`max-h-44 overflow-y-auto rounded-lg border border-bambu-dark-tertiary ${oe?``:`opacity-50`}`,children:[l&&!de&&(0,G.jsx)(`div`,{className:`px-3 py-2 text-sm bg-bambu-green/10 text-bambu-green border-b border-bambu-dark-tertiary`,children:r(`locationHaSensors.currentlyBound`,{entity:l})}),!oe&&(0,G.jsx)(`div`,{className:`p-3 text-sm text-bambu-gray`,children:r(`haSensors.noEntities`)}),oe&&H&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2 p-3 text-sm text-bambu-gray`,children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),r(`common.loading`)]}),oe&&!H&&fe.length===0&&(0,G.jsx)(`div`,{className:`p-3 text-sm text-bambu-gray`,children:r(`haSensors.noEntities`)}),oe&&!H&&fe.map(e=>(0,G.jsxs)(`button`,{type:`button`,onClick:()=>pe(e),className:`w-full text-left px-3 py-2 text-sm transition-colors ${e.entity_id===l?`bg-bambu-green/20 text-bambu-green`:`text-white hover:bg-bambu-dark`}`,children:[(0,G.jsx)(`div`,{className:`font-medium`,children:e.friendly_name}),(0,G.jsxs)(`div`,{className:`text-xs text-bambu-gray`,children:[e.entity_id,e.state!==null&&` — ${e.state}`,e.unit_of_measurement?` ${e.unit_of_measurement}`:``]})]},e.entity_id))]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,htmlFor:`location-ha-sensor-name`,children:r(`haSensors.name`)}),(0,G.jsx)(`input`,{id:`location-ha-sensor-name`,type:`text`,value:_,onChange:e=>v(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white`})]}),l&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`haSensors.alertWhen`)}),d===`binary`?(0,G.jsxs)(`select`,{value:x,onChange:e=>S(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white`,children:[(0,G.jsx)(`option`,{value:``,children:r(`haSensors.alertNever`)}),(0,G.jsx)(`option`,{value:`on`,children:Ce(`on`)}),(0,G.jsx)(`option`,{value:`off`,children:Ce(`off`)})]}):Q6(p)===`battery`?(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`span`,{className:`block text-xs text-bambu-gray mb-1`,children:[r(`haSensors.alertBelow`),` `,h??``]}),(0,G.jsx)(`input`,{type:`number`,step:`any`,value:T,onChange:e=>E(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white`})]}):(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`span`,{className:`block text-xs text-bambu-gray mb-1`,children:[r(`haSensors.alertAbove`),` `,h??``]}),(0,G.jsx)(`input`,{type:`number`,step:`any`,value:C,onChange:e=>w(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`span`,{className:`block text-xs text-bambu-gray mb-1`,children:[r(`haSensors.alertBelow`),` `,h??``]}),(0,G.jsx)(`input`,{type:`number`,step:`any`,value:T,onChange:e=>E(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white`})]})]}),(0,G.jsx)(`p`,{className:`mt-1 text-xs text-bambu-gray`,children:r(`haSensors.alertHint`)})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:k,onChange:e=>A(e.target.checked),className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`text-sm text-white`,children:r(`locationHaSensors.showOnCard`)})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:D,onChange:e=>O(e.target.checked),disabled:!be,className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`text-sm ${be?`text-white`:`text-bambu-gray`}`,children:r(`haSensors.notifyOnAlert`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between pt-2`,children:[o?(0,G.jsx)(Q,{type:`button`,variant:`danger`,onClick:()=>ve.mutate(),disabled:we,children:r(`common.delete`)}):(0,G.jsx)(`span`,{}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:n,disabled:we,children:r(`common.cancel`)}),(0,G.jsxs)(Q,{type:`submit`,disabled:we||!oe&&!o,children:[we?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(ql,{className:`w-4 h-4`}),r(`common.save`)]})]})]})]})]})}),L&&z&&(0,G.jsx)(of,{title:r(`locationHaSensors.overwriteConfirm.title`),message:r(`locationHaSensors.overwriteConfirm.message${Q6(z.device_class)===`humidity`?`Humidity`:Q6(z.device_class)===`battery`?`Battery`:`Temperature`}`,{location:Te?.name??``,name:z.name}),variant:`warning`,overlayZIndex:`z-[110]`,isLoading:ye.isPending,onConfirm:()=>ye.mutate(),onCancel:()=>{R(!1),B(null)}}),V&&te.length>0&&(0,G.jsx)(of,{title:r(`locationHaSensors.autoAdd.confirmTitle`),message:r(`locationHaSensors.autoAdd.confirmMessage`),overlayZIndex:`z-[110]`,isLoading:_e.isPending,confirmDisabled:!te.some(e=>re[e.entity_id]),onConfirm:()=>_e.mutate(),cancelText:r(`locationHaSensors.autoAdd.onlyThisOne`),onCancel:()=>{ee(!1),ne([]),ie({}),ge.mutate()},children:(0,G.jsx)(`div`,{className:`space-y-2`,children:te.map(e=>(0,G.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:re[e.entity_id]??!0,onChange:t=>ie(n=>({...n,[e.entity_id]:t.target.checked})),className:`w-4 h-4`}),(0,G.jsxs)(`span`,{className:`text-sm text-white`,children:[e.friendly_name,(0,G.jsxs)(`span`,{className:`text-bambu-gray`,children:[` — `,e.entity_id]})]})]},e.entity_id))})}),F&&(0,G.jsx)(Z6,{open:F,onClose:()=>I(!1),onPickLocation:e=>{c(e),I(!1)},startCreating:!0})]})}var e8=60,t8=120,zWe={temperature:Mu,humidity:Qs,battery:Wo},BWe={temperature:`°C`,humidity:`%`,battery:`%`};function n8(e){return e===`temperature`?`temperature`:e===`humidity`?`humidity`:e===`battery`?`battery`:null}function r8({category:e,state:t,onChange:n}){let{t:r}=U(),i=zWe[e],a=BWe[e],o=t.alertAbove!==``||t.alertBelow!==``;return(0,G.jsxs)(`div`,{className:`p-3 border border-bambu-dark-tertiary rounded-lg space-y-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 text-sm text-white font-medium`,children:[(0,G.jsx)(i,{className:`w-4 h-4`}),r(`inventory.${e}`)]}),e===`battery`?(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`span`,{className:`block text-xs text-bambu-gray mb-1`,children:[r(`haSensors.alertBelow`),` `,a]}),(0,G.jsx)(`input`,{type:`number`,step:`any`,value:t.alertBelow,onChange:e=>n({alertBelow:e.target.value}),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white`})]}):(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`span`,{className:`block text-xs text-bambu-gray mb-1`,children:[r(`haSensors.alertAbove`),` `,a]}),(0,G.jsx)(`input`,{type:`number`,step:`any`,value:t.alertAbove,onChange:e=>n({alertAbove:e.target.value}),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`span`,{className:`block text-xs text-bambu-gray mb-1`,children:[r(`haSensors.alertBelow`),` `,a]}),(0,G.jsx)(`input`,{type:`number`,step:`any`,value:t.alertBelow,onChange:e=>n({alertBelow:e.target.value}),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white`})]})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:t.showOnCard,onChange:e=>n({showOnCard:e.target.checked}),className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`text-sm text-white`,children:r(`locationHaSensors.showOnCard`)})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:t.notifyOnAlert,onChange:e=>n({notifyOnAlert:e.target.checked}),disabled:!o,className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`text-sm ${o?`text-white`:`text-bambu-gray`}`,children:r(`haSensors.notifyOnAlert`)})]})]})}function VWe({onClose:e}){let{t}=U(),{showToast:n}=qd(),r=co(),[i,a]=(0,y.useState)(()=>C6()),[o,s]=(0,y.useState)(()=>T6()),[c,l]=(0,y.useState)(()=>P6()),[u,d]=(0,y.useState)(()=>F6()),[f,p]=(0,y.useState)(()=>I6()),[m,h]=(0,y.useState)(!1),{data:g}=K({queryKey:[`settings`],queryFn:Z.getSettings}),[_,v]=(0,y.useState)(t8),b=(0,y.useRef)(!1),x=(0,y.useRef)(new Set);(0,y.useEffect)(()=>{if(!g||b.current)return;b.current=!0,x.current.has(`pollInterval`)||v(g.location_sensor_poll_interval);let e=C6(g.location_sensor_alert_defaults);a(t=>{let n={...e};return Object.keys(n).forEach(e=>{x.current.has(e)&&(n[e]=t[e])}),n})},[g]);let S=(e,t)=>{x.current.add(e),a(n=>({...n,[e]:{...n[e],...t}}))},C=e=>{x.current.add(`pollInterval`),v(e)},w=async()=>{let e=Math.max(e8,_),t=pWe({...i,battery:{...i.battery,alertAbove:``}}),n={};g&&e!==g.location_sensor_poll_interval&&(n.location_sensor_poll_interval=e),g&&t!==g.location_sensor_alert_defaults&&(n.location_sensor_alert_defaults=t),Object.keys(n).length>0&&(await Z.updateSettings(n),r.invalidateQueries({queryKey:[`settings`]})),mWe(i),hWe(o),gWe(c),_We(u),vWe(f)},T=q({mutationFn:w,onSuccess:()=>{n(t(`locationHaSensors.options.saved`),`success`),e()},onError:e=>{n(e.message||t(`locationHaSensors.options.saveFailed`),`error`)}}),E=e=>{e.preventDefault(),T.mutate()},D=q({mutationFn:async()=>{let[e,t]=await Promise.all([Z.getLocationHASensors(),Z.getBindableLocationHAEntities()]),n=new Map(t.map(e=>[e.entity_id,e.friendly_name])),r=e.filter(e=>n8(e.device_class)!==null);return await Promise.all(r.map(e=>{let t=n8(e.device_class),r=i[t],a=n.get(e.entity_id);return Z.updateLocationHASensor(e.id,{...a?{name:a.slice(0,100)}:{},alert_above:t!==`battery`&&r.alertAbove!==``?Number(r.alertAbove):null,alert_below:r.alertBelow===``?null:Number(r.alertBelow),notify_on_alert:r.notifyOnAlert,show_on_card:r.showOnCard})})),await w(),r.length},onSuccess:i=>{r.invalidateQueries({queryKey:[`locationHaSensors`]}),r.invalidateQueries({queryKey:[`locationHaSensorReadings`]}),n(t(`locationHaSensors.options.resetDone`,{count:i}),`success`),h(!1),e()},onError:e=>{n(e.message||t(`locationHaSensors.options.resetFailed`),`error`),h(!1)}});return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:e,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-lg max-h-[90vh] overflow-y-auto`,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-3`,children:[(0,G.jsx)(`div`,{className:`p-2 rounded-full bg-bambu-green/20 text-bambu-green`,children:(0,G.jsx)(nu,{className:`w-5 h-5`})}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:t(`locationHaSensors.options.title`)})]}),(0,G.jsx)(`button`,{onClick:e,className:`text-bambu-gray hover:text-white transition-colors`,children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]}),(0,G.jsxs)(`form`,{onSubmit:E,className:`px-6 pb-6 pt-3 space-y-4`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:t(`locationHaSensors.options.description`)}),(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsx)(r8,{category:`temperature`,state:i.temperature,onChange:e=>S(`temperature`,e)}),(0,G.jsx)(r8,{category:`humidity`,state:i.humidity,onChange:e=>S(`humidity`,e)}),(0,G.jsx)(r8,{category:`battery`,state:i.battery,onChange:e=>S(`battery`,e)})]}),(0,G.jsxs)(`div`,{className:`p-3 border border-bambu-dark-tertiary rounded-lg space-y-3`,children:[(0,G.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:o,onChange:e=>s(e.target.checked),className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`text-sm text-white`,children:t(`locationHaSensors.options.colorizeValues`)})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-3 gap-x-3 gap-y-1 items-end ${o?``:`opacity-50`}`,children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray`,htmlFor:`location-sensor-below-color`,children:t(`locationHaSensors.options.belowColor`)}),(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray`,htmlFor:`location-sensor-optimal-color`,children:t(`locationHaSensors.options.optimalColor`)}),(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray`,htmlFor:`location-sensor-above-color`,children:t(`locationHaSensors.options.aboveColor`)}),(0,G.jsx)(`select`,{id:`location-sensor-below-color`,value:u,onChange:e=>d(e.target.value),disabled:!o,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white disabled:cursor-not-allowed`,children:O6.map(e=>(0,G.jsx)(`option`,{value:e,children:t(`locationHaSensors.options.colors.${e}`)},e))}),(0,G.jsx)(`select`,{id:`location-sensor-optimal-color`,value:f,onChange:e=>p(e.target.value),disabled:!o,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white disabled:cursor-not-allowed`,children:O6.map(e=>(0,G.jsx)(`option`,{value:e,children:t(`locationHaSensors.options.colors.${e}`)},e))}),(0,G.jsx)(`select`,{id:`location-sensor-above-color`,value:c,onChange:e=>l(e.target.value),disabled:!o,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white disabled:cursor-not-allowed`,children:O6.map(e=>(0,G.jsx)(`option`,{value:e,children:t(`locationHaSensors.options.colors.${e}`)},e))})]})]}),(0,G.jsx)(`div`,{className:`pt-4 mt-4 border-t border-bambu-dark-tertiary`,children:(0,G.jsx)(`p`,{className:`text-xs font-medium text-bambu-gray uppercase tracking-wider mb-3`,children:t(`locationHaSensors.options.generalSettings`)})}),(0,G.jsxs)(`div`,{className:`p-3 border border-bambu-dark-tertiary rounded-lg space-y-2`,children:[(0,G.jsx)(`label`,{className:`block text-sm text-white`,htmlFor:`location-sensor-poll-interval`,children:t(`locationHaSensors.options.pollInterval`)}),(0,G.jsx)(`input`,{id:`location-sensor-poll-interval`,type:`number`,min:e8,step:`1`,value:_,onChange:e=>C(Number(e.target.value)),onBlur:()=>C(Math.max(e8,_||t8)),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:t(`locationHaSensors.options.pollIntervalHint`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-2 pt-2`,children:[(0,G.jsxs)(Q,{type:`button`,variant:`secondary`,onClick:()=>h(!0),children:[(0,G.jsx)(Wl,{className:`w-4 h-4`}),t(`locationHaSensors.options.reset`)]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:e,children:t(`common.cancel`)}),(0,G.jsxs)(Q,{type:`submit`,disabled:T.isPending,children:[(0,G.jsx)(ql,{className:`w-4 h-4`}),t(`common.save`)]})]})]})]})]})}),m&&(0,G.jsx)(of,{title:t(`locationHaSensors.options.resetConfirm.title`),message:t(`locationHaSensors.options.resetConfirm.message`),confirmText:t(`locationHaSensors.options.reset`),variant:`danger`,overlayZIndex:`z-[60]`,isLoading:D.isPending,onConfirm:()=>D.mutate(),onCancel:()=>h(!1)})]})}function HWe({provider:e,onEdit:t}){let{t:n}=U(),r=co(),[i,a]=(0,y.useState)(!1),[o,s]=(0,y.useState)(!1),[c,l]=(0,y.useState)(null),{data:u}=K({queryKey:[`printers`],queryFn:Z.getPrinters}),d=u?.find(t=>t.id===e.printer_id),f=q({mutationFn:t=>Z.updateNotificationProvider(e.id,t),onSuccess:()=>{r.invalidateQueries({queryKey:[`notification-providers`]})}}),p=q({mutationFn:()=>Z.deleteNotificationProvider(e.id),onSuccess:()=>{r.invalidateQueries({queryKey:[`notification-providers`]})}}),m=q({mutationFn:()=>Z.testNotificationProvider(e.id),onSuccess:e=>{l(e),r.invalidateQueries({queryKey:[`notification-providers`]})},onError:e=>{l({success:!1,message:e.message})}}),h=e=>e||``;return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(zd,{className:`relative`,children:(0,G.jsxs)(Vd,{className:`p-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-start justify-between ${e.enabled?`mb-3`:`mb-0`}`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`p-2 rounded-lg ${e.enabled?`bg-bambu-green/20`:`bg-bambu-dark`}`,children:(0,G.jsx)(qo,{className:`w-5 h-5 ${e.enabled?`text-bambu-green`:`text-bambu-gray`}`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`font-medium text-white`,children:e.name}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`notifications.providerTypes.${e.provider_type}`,e.provider_type)})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[e.last_success&&(0,G.jsx)(`span`,{className:`text-xs text-status-ok hidden sm:inline`,children:n(`notifications.lastSuccess`,{date:ap(e.last_success)})}),e.last_error&&e.last_error_at&&(!e.last_success||(rp(e.last_error_at)?.getTime()||0)>(rp(e.last_success)?.getTime()||0))&&(0,G.jsx)(`span`,{className:`text-xs text-status-error`,title:e.last_error,children:n(`notifications.error`)}),(0,G.jsx)(fH,{checked:e.enabled,onChange:e=>f.mutate({enabled:e})})]})]}),e.enabled&&(0,G.jsxs)(G.Fragment,{children:[d&&(0,G.jsxs)(`div`,{className:`mb-3 px-2 py-1.5 bg-bambu-dark rounded-lg`,children:[(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[n(`notifications.printer`),` `]}),(0,G.jsx)(`span`,{className:`text-sm text-white`,children:d.name})]}),!d&&!e.printer_id&&(0,G.jsx)(`div`,{className:`mb-3 px-2 py-1.5 bg-bambu-dark rounded-lg`,children:(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:n(`notifications.allPrinters`)})}),(0,G.jsxs)(`div`,{className:`mb-3 flex flex-wrap gap-1`,children:[e.on_print_start&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400 text-xs rounded`,children:n(`notifications.start`)}),e.on_plate_not_empty&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 bg-rose-100 dark:bg-rose-600/20 text-rose-700 dark:text-rose-300 text-xs rounded`,children:n(`notifications.plateCheck`)}),e.on_print_complete&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 bg-bambu-green/20 text-bambu-green text-xs rounded`,children:n(`notifications.complete`)}),e.on_plate_clear_required&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-400 text-xs rounded`,children:n(`notifications.plateClear`)}),e.on_print_failed&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400 text-xs rounded`,children:n(`notifications.failed`)}),e.on_print_stopped&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 bg-orange-100 dark:bg-orange-500/20 text-orange-700 dark:text-orange-400 text-xs rounded`,children:n(`notifications.stopped`)}),e.on_billing_charge_failed&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 bg-red-100 dark:bg-red-600/20 text-red-700 dark:text-red-300 text-xs rounded`,children:n(`notifications.billingChargeFailedLabel`)}),e.on_print_progress&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400 text-xs rounded`,children:n(`notifications.progress`)}),e.on_printer_offline&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 bg-gray-500/20 text-gray-400 text-xs rounded`,children:n(`notifications.offline`)}),e.on_printer_error&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 bg-rose-100 dark:bg-rose-500/20 text-rose-700 dark:text-rose-400 text-xs rounded`,children:n(`notifications.error`)}),e.on_ai_failure_detection&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 bg-fuchsia-100 dark:bg-fuchsia-500/20 text-fuchsia-700 dark:text-fuchsia-300 text-xs rounded`,children:n(`notifications.aiFailureDetection`)}),e.on_ha_sensor_alert&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 bg-indigo-100 dark:bg-indigo-500/20 text-indigo-700 dark:text-indigo-300 text-xs rounded`,children:n(`notifications.haSensorAlert`)}),e.on_location_ha_sensor_alert&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 bg-indigo-100 dark:bg-indigo-500/20 text-indigo-700 dark:text-indigo-300 text-xs rounded`,children:n(`notifications.locationHaSensorAlert`)}),e.on_filament_low&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 bg-cyan-100 dark:bg-cyan-500/20 text-cyan-700 dark:text-cyan-400 text-xs rounded`,children:n(`notifications.lowFilament`)}),e.on_maintenance_due&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 bg-purple-100 dark:bg-purple-500/20 text-purple-700 dark:text-purple-400 text-xs rounded`,children:n(`notifications.maintenance`)}),e.on_ams_humidity_high&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 bg-blue-100 dark:bg-blue-600/20 text-blue-700 dark:text-blue-300 text-xs rounded`,children:n(`notifications.amsHumidity`)}),e.on_ams_temperature_high&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 bg-orange-100 dark:bg-orange-600/20 text-orange-700 dark:text-orange-300 text-xs rounded`,children:n(`notifications.amsTemp`)}),e.on_ams_drying_suspended&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 bg-rose-100 dark:bg-rose-600/20 text-rose-700 dark:text-rose-300 text-xs rounded`,children:n(`notifications.amsDryingSuspended`)}),e.on_ams_ht_humidity_high&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 bg-cyan-100 dark:bg-cyan-600/20 text-cyan-700 dark:text-cyan-300 text-xs rounded`,children:n(`notifications.amsHtHumidity`)}),e.on_ams_ht_temperature_high&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 bg-amber-100 dark:bg-amber-600/20 text-amber-700 dark:text-amber-300 text-xs rounded`,children:n(`notifications.amsHtTemp`)}),e.on_bed_cooled&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 bg-teal-100 dark:bg-teal-500/20 text-teal-700 dark:text-teal-400 text-xs rounded`,children:n(`notifications.bedCooled`)}),e.on_first_layer_complete&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 bg-emerald-100 dark:bg-emerald-600/20 text-emerald-700 dark:text-emerald-300 text-xs rounded`,children:n(`notifications.firstLayer`)}),e.on_print_missing_spool_assignment&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-300 text-xs rounded`,children:n(`notifications.missingSpoolAssignmentLabel`)}),e.on_stock_reorder_alert&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 bg-lime-100 dark:bg-lime-500/20 text-lime-700 dark:text-lime-400 text-xs rounded`,children:n(`notifications.stockReorderAlert`)}),e.on_stock_break_alert&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 bg-red-100 dark:bg-red-600/20 text-red-700 dark:text-red-300 text-xs rounded`,children:n(`notifications.stockBreakAlert`)}),e.quiet_hours_enabled&&(0,G.jsxs)(`span`,{className:`px-2 py-0.5 bg-indigo-100 dark:bg-indigo-500/20 text-indigo-700 dark:text-indigo-400 text-xs rounded flex items-center gap-1`,children:[(0,G.jsx)(_l,{className:`w-3 h-3`}),n(`notifications.quiet`)]}),e.daily_digest_enabled&&(0,G.jsxs)(`span`,{className:`px-2 py-0.5 bg-emerald-100 dark:bg-emerald-500/20 text-emerald-700 dark:text-emerald-400 text-xs rounded flex items-center gap-1`,children:[(0,G.jsx)(as,{className:`w-3 h-3`}),n(`notifications.digest`,{time:e.daily_digest_time})]})]}),(0,G.jsx)(`div`,{className:`mb-3`,children:(0,G.jsxs)(Q,{size:`sm`,variant:`secondary`,disabled:m.isPending,onClick:()=>{l(null),m.mutate()},className:`w-full`,children:[m.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)($l,{className:`w-4 h-4`}),n(`notifications.sendTestNotification`)]})}),c&&(0,G.jsxs)(`div`,{className:`mb-3 p-2 rounded-lg flex items-center gap-2 text-sm ${c.success?`bg-bambu-green/20 text-bambu-green`:`bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400`}`,children:[c.success?(0,G.jsx)(xs,{className:`w-4 h-4`}):(0,G.jsx)(Ds,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{children:c.message})]})]}),(0,G.jsxs)(`button`,{onClick:()=>s(!o),className:`w-full flex items-center justify-between py-2 text-sm text-bambu-gray hover:text-white transition-colors ${e.enabled?`border-t border-bambu-dark-tertiary`:`mt-2 border-t border-bambu-dark-tertiary`}`,children:[(0,G.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(nu,{className:`w-4 h-4`}),n(`notifications.eventSettings`)]}),o?(0,G.jsx)(gs,{className:`w-4 h-4`}):(0,G.jsx)(ps,{className:`w-4 h-4`})]}),o&&(0,G.jsxs)(`div`,{className:`pt-3 border-t border-bambu-dark-tertiary space-y-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.enabled`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.sendFromProvider`)})]}),(0,G.jsx)(fH,{checked:e.enabled,onChange:e=>f.mutate({enabled:e})})]}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase tracking-wide`,children:n(`notifications.printEvents`)}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.printStarted`)}),(0,G.jsx)(fH,{checked:e.on_print_start,onChange:e=>f.mutate({on_print_start:e})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.plateNotEmpty`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.plateNotEmptyDescription`)})]}),(0,G.jsx)(fH,{checked:e.on_plate_not_empty??!0,onChange:e=>f.mutate({on_plate_not_empty:e})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.printCompleted`)}),(0,G.jsx)(fH,{checked:e.on_print_complete,onChange:e=>f.mutate({on_print_complete:e})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.plateClearRequired`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.plateClearRequiredDescription`)})]}),(0,G.jsx)(fH,{checked:e.on_plate_clear_required??!1,onChange:e=>f.mutate({on_plate_clear_required:e})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.bedCooledLabel`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.bedCooledDescription`)})]}),(0,G.jsx)(fH,{checked:e.on_bed_cooled??!1,onChange:e=>f.mutate({on_bed_cooled:e})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.firstLayerCompleteLabel`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.firstLayerCompleteDescription`)})]}),(0,G.jsx)(fH,{checked:e.on_first_layer_complete??!1,onChange:e=>f.mutate({on_first_layer_complete:e})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.missingSpoolAssignmentLabel`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.missingSpoolAssignmentDescription`)})]}),(0,G.jsx)(fH,{checked:e.on_print_missing_spool_assignment??!1,onChange:e=>f.mutate({on_print_missing_spool_assignment:e})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.printFailed`)}),(0,G.jsx)(fH,{checked:e.on_print_failed,onChange:e=>f.mutate({on_print_failed:e})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.printStopped`)}),(0,G.jsx)(fH,{checked:e.on_print_stopped,onChange:e=>f.mutate({on_print_stopped:e})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.billingChargeFailedLabel`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.billingChargeFailedDescription`)})]}),(0,G.jsx)(fH,{checked:e.on_billing_charge_failed??!0,onChange:e=>f.mutate({on_billing_charge_failed:e})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.progressMilestones`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.progressMilestonesDescription`)})]}),(0,G.jsx)(fH,{checked:e.on_print_progress,onChange:e=>f.mutate({on_print_progress:e})})]})]}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase tracking-wide`,children:n(`notifications.printerStatus`)}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.printerOffline`)}),(0,G.jsx)(fH,{checked:e.on_printer_offline,onChange:e=>f.mutate({on_printer_offline:e})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.printerError`)}),(0,G.jsx)(fH,{checked:e.on_printer_error,onChange:e=>f.mutate({on_printer_error:e})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.aiFailureDetection`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.aiFailureDetectionDescription`)})]}),(0,G.jsx)(fH,{checked:e.on_ai_failure_detection??!1,onChange:e=>f.mutate({on_ai_failure_detection:e})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.haSensorAlert`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.haSensorAlertDescription`)})]}),(0,G.jsx)(fH,{checked:e.on_ha_sensor_alert??!1,onChange:e=>f.mutate({on_ha_sensor_alert:e})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.locationHaSensorAlert`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.locationHaSensorAlertDescription`)})]}),(0,G.jsx)(fH,{checked:e.on_location_ha_sensor_alert??!1,onChange:e=>f.mutate({on_location_ha_sensor_alert:e})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.lowFilamentLabel`)}),(0,G.jsx)(fH,{checked:e.on_filament_low,onChange:e=>f.mutate({on_filament_low:e})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.maintenanceDue`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.maintenanceDueDescription`)})]}),(0,G.jsx)(fH,{checked:e.on_maintenance_due??!1,onChange:e=>f.mutate({on_maintenance_due:e})})]})]}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase tracking-wide`,children:n(`notifications.amsAlarms`)}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.amsHumidityHigh`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.amsHumidityHighDescription`)})]}),(0,G.jsx)(fH,{checked:e.on_ams_humidity_high??!1,onChange:e=>f.mutate({on_ams_humidity_high:e})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.amsTemperatureHigh`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.amsTemperatureHighDescription`)})]}),(0,G.jsx)(fH,{checked:e.on_ams_temperature_high??!1,onChange:e=>f.mutate({on_ams_temperature_high:e})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.amsDryingSuspendedTitle`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.amsDryingSuspendedDescription`)})]}),(0,G.jsx)(fH,{checked:e.on_ams_drying_suspended??!1,onChange:e=>f.mutate({on_ams_drying_suspended:e})})]})]}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase tracking-wide`,children:n(`notifications.amsHtAlarms`)}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.amsHtHumidityHigh`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.amsHtHumidityHighDescription`)})]}),(0,G.jsx)(fH,{checked:e.on_ams_ht_humidity_high??!1,onChange:e=>f.mutate({on_ams_ht_humidity_high:e})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.amsHtTemperatureHigh`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.amsHtTemperatureHighDescription`)})]}),(0,G.jsx)(fH,{checked:e.on_ams_ht_temperature_high??!1,onChange:e=>f.mutate({on_ams_ht_temperature_high:e})})]})]}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase tracking-wide`,children:n(`notifications.inventoryAlerts`)}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.stockReorderAlert`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.stockReorderAlertDescription`)})]}),(0,G.jsx)(fH,{checked:e.on_stock_reorder_alert??!1,onChange:e=>f.mutate({on_stock_reorder_alert:e})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.stockBreakAlert`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.stockBreakAlertDescription`)})]}),(0,G.jsx)(fH,{checked:e.on_stock_break_alert??!1,onChange:e=>f.mutate({on_stock_break_alert:e})})]})]}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase tracking-wide`,children:n(`notifications.printQueue`)}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.jobAdded`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.jobAddedDescription`)})]}),(0,G.jsx)(fH,{checked:e.on_queue_job_added??!1,onChange:e=>f.mutate({on_queue_job_added:e})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.jobAssigned`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.jobAssignedDescription`)})]}),(0,G.jsx)(fH,{checked:e.on_queue_job_assigned??!1,onChange:e=>f.mutate({on_queue_job_assigned:e})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.jobStarted`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.jobStartedDescription`)})]}),(0,G.jsx)(fH,{checked:e.on_queue_job_started??!1,onChange:e=>f.mutate({on_queue_job_started:e})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.jobWaiting`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.jobWaitingDescription`)})]}),(0,G.jsx)(fH,{checked:e.on_queue_job_waiting??!0,onChange:e=>f.mutate({on_queue_job_waiting:e})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.jobSkipped`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.jobSkippedDescription`)})]}),(0,G.jsx)(fH,{checked:e.on_queue_job_skipped??!0,onChange:e=>f.mutate({on_queue_job_skipped:e})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.jobFailed`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.jobFailedDescription`)})]}),(0,G.jsx)(fH,{checked:e.on_queue_job_failed??!0,onChange:e=>f.mutate({on_queue_job_failed:e})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.queueComplete`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.queueCompleteDescription`)})]}),(0,G.jsx)(fH,{checked:e.on_queue_completed??!1,onChange:e=>f.mutate({on_queue_completed:e})})]})]}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(_l,{className:`w-4 h-4 text-purple-600 dark:text-purple-400`}),(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.quietHours`)})]}),(0,G.jsx)(fH,{checked:e.quiet_hours_enabled,onChange:e=>f.mutate({quiet_hours_enabled:e})})]}),e.quiet_hours_enabled&&(0,G.jsxs)(`div`,{className:`pl-4 border-l-2 border-bambu-dark-tertiary space-y-2`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.noNotificationsDuring`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(js,{className:`w-4 h-4 text-bambu-gray`}),(0,G.jsxs)(`span`,{className:`text-sm text-white`,children:[h(e.quiet_hours_start)||`22:00`,` - `,h(e.quiet_hours_end)||`07:00`]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.editProviderToChangeQuietHours`)})]})]}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(as,{className:`w-4 h-4 text-emerald-600 dark:text-emerald-400`}),(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.dailyDigest`)})]}),(0,G.jsx)(fH,{checked:e.daily_digest_enabled,onChange:e=>f.mutate({daily_digest_enabled:e})})]}),e.daily_digest_enabled&&(0,G.jsxs)(`div`,{className:`pl-4 border-l-2 border-bambu-dark-tertiary space-y-2`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.batchNotifications`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(js,{className:`w-4 h-4 text-bambu-gray`}),(0,G.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.sendAt`,{time:h(e.daily_digest_time)||`08:00`})})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.editProviderToChangeDigestTime`)})]})]}),(0,G.jsxs)(`div`,{className:`flex gap-2 pt-2`,children:[(0,G.jsxs)(Q,{size:`sm`,variant:`secondary`,onClick:()=>t(e),className:`flex-1`,children:[(0,G.jsx)(kl,{className:`w-4 h-4`}),n(`notifications.edit`)]}),(0,G.jsx)(Q,{size:`sm`,variant:`secondary`,onClick:()=>a(!0),className:`text-red-700 dark:text-red-400 hover:text-red-800 dark:hover:text-red-300`,children:(0,G.jsx)(Pu,{className:`w-4 h-4`})})]})]})]})}),i&&(0,G.jsx)(of,{title:n(`notifications.deleteProvider`),message:n(`notifications.deleteConfirm`,{name:e.name}),confirmText:n(`notifications.delete`),variant:`danger`,onConfirm:()=>{p.mutate(),a(!1)},onCancel:()=>a(!1)})]})}var UWe=[`email`,`telegram`,`discord`,`ntfy`,`pushover`,`bark`,`callmebot`,`webhook`,`homeassistant`];function WWe({provider:e,onClose:t}){let{t:n}=U(),r=co(),i=!!e,[a,o]=(0,y.useState)(e?.name||``),[s,c]=(0,y.useState)(e?.provider_type||`email`),[l,u]=(0,y.useState)(e?.printer_id||null),[d,f]=(0,y.useState)(e?.quiet_hours_enabled||!1),[p,m]=(0,y.useState)(e?.quiet_hours_start||`22:00`),[h,g]=(0,y.useState)(e?.quiet_hours_end||`07:00`),[_,v]=(0,y.useState)(e?.daily_digest_enabled||!1),[b,x]=(0,y.useState)(e?.daily_digest_time||`08:00`),[S,C]=(0,y.useState)(e?.on_print_start??!1),[w,T]=(0,y.useState)(e?.on_print_complete??!0),[E,D]=(0,y.useState)(e?.on_print_failed??!0),[O,k]=(0,y.useState)(e?.on_print_stopped??!0),[A,j]=(0,y.useState)(e?.on_print_progress??!1),[M,N]=(0,y.useState)(e?.on_billing_charge_failed??!0),[P,F]=(0,y.useState)(e?.on_printer_offline??!1),[I,L]=(0,y.useState)(e?.on_printer_error??!1),[R,z]=(0,y.useState)(e?.on_ai_failure_detection??!1),[B,V]=(0,y.useState)(e?.on_filament_low??!1),[ee,te]=(0,y.useState)(e?.on_maintenance_due??!1),[ne,re]=(0,y.useState)(e?.on_stock_reorder_alert??!1),[ie,ae]=(0,y.useState)(e?.on_stock_break_alert??!1),[oe,se]=(0,y.useState)(e?.on_plate_clear_required??!1),[H,ce]=(0,y.useState)(e?.on_bed_cooled??!1),[le,ue]=(0,y.useState)(e?.on_ha_sensor_alert??!1),[de,fe]=(0,y.useState)(e?.on_location_ha_sensor_alert??!1),[pe,me]=(0,y.useState)(e?.on_first_layer_complete??!1),[he,ge]=(0,y.useState)(e?.config?Object.fromEntries(Object.entries(e.config).filter(([e])=>e!==`event_priorities`).map(([e,t])=>[e,String(t)])):{}),[_e,ve]=(0,y.useState)((()=>{let t=e?.config?.event_priorities;if(!t||typeof t!=`object`)return{};let n={};for(let[e,r]of Object.entries(t)){let t=Number(r);Number.isInteger(t)&&t>=1&&t<=5&&(n[e]=t)}return n})()),[ye,be]=(0,y.useState)(null),[xe,Se]=(0,y.useState)(null),{data:Ce}=K({queryKey:[`printers`],queryFn:Z.getPrinters});(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]);let we=q({mutationFn:()=>Z.testNotificationConfig({provider_type:s,config:he}),onSuccess:e=>{be(e),Se(null)},onError:e=>{be({success:!1,message:e.message})}}),Te=q({mutationFn:e=>Z.createNotificationProvider(e),onSuccess:()=>{r.invalidateQueries({queryKey:[`notification-providers`]}),t()},onError:e=>{Se(e.message)}}),Ee=q({mutationFn:t=>Z.updateNotificationProvider(e.id,t),onSuccess:()=>{r.invalidateQueries({queryKey:[`notification-providers`]}),t()},onError:e=>{Se(e.message)}}),De=e=>{if(e.preventDefault(),Se(null),!a.trim()){Se(n(`notifications.nameRequired`));return}let t=Ae(s);for(let e of t)if(!he[e.key]?.trim()){Se(n(`notifications.fieldRequired`,{field:e.label}));return}if(s===`homeassistant`&&he.data?.trim()){let e;try{e=JSON.parse(he.data)}catch{Se(n(`notifications.haDataInvalid`));return}if(typeof e!=`object`||!e||Array.isArray(e)){Se(n(`notifications.haDataInvalid`));return}}if(s===`telegram`&&he.message_thread_id?.trim()&&!/^\d+$/.test(he.message_thread_id.trim())){Se(n(`notifications.telegramThreadIdInvalid`));return}let r=s===`ntfy`&&Object.keys(_e).length>0?{...he,event_priorities:_e}:he,o={name:a.trim(),provider_type:s,config:r,printer_id:l,quiet_hours_enabled:d,quiet_hours_start:d?p:null,quiet_hours_end:d?h:null,daily_digest_enabled:_,daily_digest_time:_?b:null,on_print_start:S,on_print_complete:w,on_print_failed:E,on_print_stopped:O,on_print_progress:A,on_billing_charge_failed:M,on_printer_offline:P,on_printer_error:I,on_ai_failure_detection:R,on_filament_low:B,on_maintenance_due:ee,on_stock_reorder_alert:ne,on_stock_break_alert:ie,on_plate_clear_required:oe,on_bed_cooled:H,on_ha_sensor_alert:le,on_location_ha_sensor_alert:de,on_first_layer_complete:pe};i?Ee.mutate(o):Te.mutate(o)},Oe=Te.isPending||Ee.isPending,ke=e=>{switch(e){case`callmebot`:return[{key:`phone`,label:`Phone Number`,placeholder:`+1234567890`,type:`text`,required:!0},{key:`apikey`,label:`API Key`,placeholder:`Your CallMeBot API key`,type:`text`,required:!0}];case`ntfy`:return[{key:`server`,label:`Server URL`,placeholder:`https://ntfy.sh`,type:`text`,required:!1},{key:`topic`,label:`Topic`,placeholder:`my-bambuddy`,type:`text`,required:!0},{key:`auth_token`,label:`Auth Token`,placeholder:`Optional authentication`,type:`password`,required:!1}];case`pushover`:return[{key:`user_key`,label:`User Key`,placeholder:`Your Pushover user key`,type:`text`,required:!0},{key:`app_token`,label:`App Token`,placeholder:`Your Pushover app token`,type:`text`,required:!0},{key:`priority`,label:`Priority`,placeholder:`0 (normal)`,type:`number`,required:!1},{key:`retry`,label:n(`notifications.pushoverRetry`),placeholder:`60`,type:`number`,required:!1,showIf:e=>e.priority===`2`},{key:`expire`,label:n(`notifications.pushoverExpire`),placeholder:`3600`,type:`number`,required:!1,showIf:e=>e.priority===`2`}];case`telegram`:return[{key:`bot_token`,label:`Bot Token`,placeholder:`Bot token from @BotFather`,type:`password`,required:!0},{key:`chat_id`,label:`Chat ID`,placeholder:`Your chat or group ID`,type:`text`,required:!0},{key:`message_thread_id`,label:n(`notifications.telegramThreadId`),placeholder:`123`,type:`number`,required:!1,help:n(`notifications.telegramThreadIdHelp`)}];case`email`:return[{key:`smtp_server`,label:`SMTP Server`,placeholder:`smtp.gmail.com`,type:`text`,required:!0},{key:`smtp_port`,label:`SMTP Port`,placeholder:`587`,type:`number`,required:!1},{key:`security`,label:`Security`,type:`select`,required:!1,options:[{value:`starttls`,label:`STARTTLS (Port 587)`},{value:`ssl`,label:`SSL/TLS (Port 465)`},{value:`none`,label:`None (Port 25)`}]},{key:`auth_enabled`,label:`Authentication`,type:`select`,required:!1,options:[{value:`true`,label:`Enabled`},{value:`false`,label:`Disabled`}]},{key:`username`,label:`Username`,placeholder:`your@email.com`,type:`text`,required:!1},{key:`password`,label:`Password`,placeholder:`App password`,type:`password`,required:!1},{key:`from_email`,label:`From Email`,placeholder:`your@email.com`,type:`text`,required:!0},{key:`to_email`,label:`To Email`,placeholder:`recipient@email.com`,type:`text`,required:!0}];case`discord`:return[{key:`webhook_url`,label:`Webhook URL`,placeholder:`https://discord.com/api/webhooks/...`,type:`text`,required:!0}];case`webhook`:return[{key:`webhook_url`,label:`Webhook URL`,placeholder:`https://example.com/webhook`,type:`text`,required:!0},{key:`payload_format`,label:`Payload Format`,type:`select`,required:!1,options:[{value:`generic`,label:`Generic JSON`},{value:`slack`,label:`Slack / Mattermost`}]},{key:`auth_header`,label:`Authorization`,placeholder:`Bearer token (optional)`,type:`password`,required:!1},{key:`field_title`,label:`Title Field Name`,placeholder:`title`,type:`text`,required:!1,showIf:e=>e.payload_format!==`slack`},{key:`field_message`,label:`Message Field Name`,placeholder:`message`,type:`text`,required:!1,showIf:e=>e.payload_format!==`slack`}];case`homeassistant`:return[{key:`service`,label:`Home Assistant Service`,placeholder:`notify.mobile_app_myphone`,type:`text`,required:!1},{key:`data`,label:`Data (JSON, optional)`,placeholder:`{"priority": "high", "ttl": 0, "channel": "3D Printing"}`,type:`textarea`,required:!1}];case`bark`:return[{key:`device_key`,label:`Device Key`,placeholder:`Your Bark device key`,type:`text`,required:!0},{key:`server`,label:`Server URL`,placeholder:`https://api.day.app`,type:`text`,required:!1},{key:`group`,label:`Group`,placeholder:`Bambuddy`,type:`text`,required:!1},{key:`sound`,label:`Sound`,placeholder:`minuet`,type:`text`,required:!1},{key:`level`,label:`Interruption Level`,type:`select`,required:!1,options:[{value:``,label:`Default`},{value:`active`,label:`Active`},{value:`timeSensitive`,label:`Time Sensitive`},{value:`critical`,label:`Critical (bypasses Silent/Focus)`},{value:`passive`,label:`Passive (no sound)`}]}];default:return[]}},Ae=e=>ke(e).filter(e=>e.required),je=ke(s);return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4 overflow-y-auto`,onClick:t,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-lg my-8 max-h-[90vh] overflow-y-auto`,onClick:e=>e.stopPropagation(),children:[(0,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:n(i?`notifications.editTitle`:`notifications.addTitle`)}),(0,G.jsx)(`button`,{onClick:t,className:`text-bambu-gray hover:text-white transition-colors`,children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]}),(0,G.jsxs)(`form`,{onSubmit:De,className:`p-6 space-y-4`,children:[xe&&(0,G.jsx)(`div`,{className:`p-3 bg-red-100 dark:bg-red-500/20 border border-red-300 dark:border-red-500/50 rounded-lg text-sm text-red-700 dark:text-red-400`,children:xe}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`notifications.nameLabel`)}),(0,G.jsx)(`input`,{type:`text`,value:a,onChange:e=>o(e.target.value),placeholder:n(`notifications.namePlaceholder`),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`notifications.providerTypeLabel`)}),(0,G.jsx)(`select`,{value:s,onChange:e=>{c(e.target.value),ge({}),be(null)},disabled:i,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none disabled:opacity-50`,children:UWe.map(e=>(0,G.jsx)(`option`,{value:e,children:n(`notifications.providerTypes.${e}`,e)},e))}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(`notifications.providerDescriptions.${s}`,``)})]}),(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`notifications.configuration`)}),je.filter(e=>!(`showIf`in e)||e.showIf?.(he)!==!1).map(e=>(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[e.label,` `,e.required&&`*`]}),e.type===`select`&&`options`in e&&e.options?(0,G.jsx)(`select`,{value:he[e.key]||e.options[0]?.value||``,onChange:t=>{ge({...he,[e.key]:t.target.value}),be(null)},className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:e.options.map(e=>(0,G.jsx)(`option`,{value:e.value,children:e.label},e.value))}):e.type===`textarea`?(0,G.jsx)(`textarea`,{value:he[e.key]||``,onChange:t=>{ge({...he,[e.key]:t.target.value}),be(null)},placeholder:e.placeholder,rows:3,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none font-mono text-sm`}):(0,G.jsx)(`input`,{type:e.type,value:he[e.key]||``,onChange:t=>{ge({...he,[e.key]:t.target.value}),be(null)},placeholder:e.placeholder,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),`help`in e&&e.help&&(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e.help})]},e.key))]}),(0,G.jsx)(`div`,{className:`flex gap-2`,children:(0,G.jsxs)(Q,{type:`button`,variant:`secondary`,onClick:()=>{be(null),we.mutate()},disabled:we.isPending||Ae(s).length>0&&!he[Ae(s)[0]?.key],className:`flex-1`,children:[we.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)($l,{className:`w-4 h-4`}),n(`notifications.testConfiguration`)]})}),ye&&(0,G.jsx)(`div`,{className:`p-3 rounded-lg flex items-center gap-2 ${ye.success?`bg-bambu-green/20 border border-bambu-green/50 text-bambu-green`:`bg-red-100 dark:bg-red-500/20 border border-red-300 dark:border-red-500/50 text-red-700 dark:text-red-400`}`,children:ye.success?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(xs,{className:`w-5 h-5`}),(0,G.jsx)(`span`,{children:ye.message})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Ds,{className:`w-5 h-5`}),(0,G.jsx)(`span`,{children:ye.message})]})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`notifications.printerFilter`)}),(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:n(`notifications.allPrinters`)}),Ce?.map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(`notifications.onlyFromPrinter`)})]}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`label`,{className:`text-sm text-white`,children:n(`notifications.quietHoursDnd`)}),(0,G.jsx)(fH,{checked:d,onChange:f})]}),d&&(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:n(`notifications.quietStart`)}),(0,G.jsx)(`input`,{type:`time`,value:p,onChange:e=>m(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:n(`notifications.quietEnd`)}),(0,G.jsx)(`input`,{type:`time`,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`})]})]})]}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`text-sm text-white`,children:n(`notifications.dailyDigestLabel`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.batchNotifications`)})]}),(0,G.jsx)(fH,{checked:_,onChange:v})]}),_&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:n(`notifications.sendDigestAt`)}),(0,G.jsx)(`input`,{type:`time`,value:b,onChange:e=>x(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(`notifications.digestCollected`)})]})]}),(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`notifications.notificationEvents`)}),(0,G.jsxs)(`div`,{className:`space-y-2 p-3 bg-bambu-dark rounded-lg`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase tracking-wide mb-2`,children:n(`notifications.printEvents`)}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.start`)}),(0,G.jsx)(fH,{checked:S,onChange:C})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.complete`)}),(0,G.jsx)(fH,{checked:w,onChange:T})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.failed`)}),(0,G.jsx)(fH,{checked:E,onChange:D})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.stopped`)}),(0,G.jsx)(fH,{checked:O,onChange:k})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between col-span-2`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.progress`)}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray ml-1`,children:n(`notifications.progressPercent`)})]}),(0,G.jsx)(fH,{checked:A,onChange:j})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between col-span-2`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.billingChargeFailedLabel`)}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray ml-1`,children:n(`notifications.billingChargeFailedDescription`)})]}),(0,G.jsx)(fH,{checked:M,onChange:N})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between col-span-2`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.plateClearRequired`)}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray ml-1`,children:n(`notifications.plateClearRequiredDescription`)})]}),(0,G.jsx)(fH,{checked:oe,onChange:se})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between col-span-2`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.bedCooled`)}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray ml-1`,children:n(`notifications.bedCooledAfterPrint`)})]}),(0,G.jsx)(fH,{checked:H,onChange:ce})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between col-span-2`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.firstLayerCompleteLabel`)}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray ml-1`,children:n(`notifications.firstLayerCompleteDescription`)})]}),(0,G.jsx)(fH,{checked:pe,onChange:me})]})]})]}),(0,G.jsxs)(`div`,{className:`space-y-2 p-3 bg-bambu-dark rounded-lg`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase tracking-wide mb-2`,children:n(`notifications.printerStatus`)}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.offline`)}),(0,G.jsx)(fH,{checked:P,onChange:F})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between col-span-2`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.haSensorAlert`)}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray ml-1`,children:n(`notifications.haSensorAlertDescription`)})]}),(0,G.jsx)(fH,{checked:le,onChange:ue})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between col-span-2`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.locationHaSensorAlert`)}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray ml-1`,children:n(`notifications.locationHaSensorAlertDescription`)})]}),(0,G.jsx)(fH,{checked:de,onChange:fe})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.error`)}),(0,G.jsx)(fH,{checked:I,onChange:L})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.aiFailureDetection`)}),(0,G.jsx)(fH,{checked:R,onChange:z})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.lowFilament`)}),(0,G.jsx)(fH,{checked:B,onChange:V})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.maintenance`)}),(0,G.jsx)(fH,{checked:ee,onChange:te})]})]})]}),(0,G.jsxs)(`div`,{className:`space-y-2 p-3 bg-bambu-dark rounded-lg`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase tracking-wide mb-2`,children:n(`notifications.inventoryAlerts`)}),(0,G.jsxs)(`div`,{className:`grid grid-cols-1 gap-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.stockReorderAlert`)}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray ml-1`,children:n(`notifications.stockReorderAlertDescription`)})]}),(0,G.jsx)(fH,{checked:ne,onChange:re})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.stockBreakAlert`)}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray ml-1`,children:n(`notifications.stockBreakAlertDescription`)})]}),(0,G.jsx)(fH,{checked:ie,onChange:ae})]})]})]}),s===`ntfy`&&(()=>{let e=[];return S&&e.push({key:`on_print_start`,label:n(`notifications.start`)}),w&&e.push({key:`on_print_complete`,label:n(`notifications.complete`)}),E&&e.push({key:`on_print_failed`,label:n(`notifications.failed`)}),O&&e.push({key:`on_print_stopped`,label:n(`notifications.stopped`)}),A&&e.push({key:`on_print_progress`,label:n(`notifications.progress`)}),M&&e.push({key:`on_billing_charge_failed`,label:n(`notifications.billingChargeFailedLabel`)}),oe&&e.push({key:`on_plate_clear_required`,label:n(`notifications.plateClearRequired`)}),H&&e.push({key:`on_bed_cooled`,label:n(`notifications.bedCooled`)}),pe&&e.push({key:`on_first_layer_complete`,label:n(`notifications.firstLayerCompleteLabel`)}),P&&e.push({key:`on_printer_offline`,label:n(`notifications.offline`)}),I&&e.push({key:`on_printer_error`,label:n(`notifications.error`)}),le&&e.push({key:`on_ha_sensor_alert`,label:n(`notifications.haSensorAlert`)}),de&&e.push({key:`on_location_ha_sensor_alert`,label:n(`notifications.locationHaSensorAlert`)}),R&&e.push({key:`on_ai_failure_detection`,label:n(`notifications.aiFailureDetection`)}),B&&e.push({key:`on_filament_low`,label:n(`notifications.lowFilament`)}),ee&&e.push({key:`on_maintenance_due`,label:n(`notifications.maintenance`)}),ne&&e.push({key:`on_stock_reorder_alert`,label:n(`notifications.stockReorderAlert`)}),ie&&e.push({key:`on_stock_break_alert`,label:n(`notifications.stockBreakAlert`)}),e.length===0?null:(0,G.jsxs)(`div`,{className:`space-y-2 p-3 bg-bambu-dark rounded-lg`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase tracking-wide mb-1`,children:n(`notifications.eventPriority.sectionTitle`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:n(`notifications.eventPriority.helpNtfy`)}),(0,G.jsx)(`div`,{className:`space-y-2`,children:e.map(e=>(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,G.jsx)(`span`,{className:`text-sm text-white`,children:e.label}),(0,G.jsxs)(`select`,{value:_e[e.key]??3,onChange:t=>{let n=Number(t.target.value);ve(t=>({...t,[e.key]:n}))},className:`px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-sm text-white focus:border-bambu-green focus:outline-none`,children:[(0,G.jsx)(`option`,{value:1,children:n(`notifications.eventPriority.min`)}),(0,G.jsx)(`option`,{value:2,children:n(`notifications.eventPriority.low`)}),(0,G.jsx)(`option`,{value:3,children:n(`notifications.eventPriority.default`)}),(0,G.jsx)(`option`,{value:4,children:n(`notifications.eventPriority.high`)}),(0,G.jsx)(`option`,{value:5,children:n(`notifications.eventPriority.urgent`)})]})]},e.key))})]})})()]}),(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:n(`notifications.cancel`)}),(0,G.jsxs)(Q,{type:`submit`,disabled:Oe,className:`flex-1`,children:[Oe?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(ql,{className:`w-4 h-4`}),n(i?`notifications.save`:`notifications.add`)]})]})]})]})})}function GWe({template:e,onClose:t}){let{t:n}=U(),r=co(),i=(0,y.useRef)(null),[a,o]=(0,y.useState)(e.title_template),[s,c]=(0,y.useState)(e.body_template),[l,u]=(0,y.useState)(null),[d,f]=(0,y.useState)(!0),{data:p}=K({queryKey:[`template-variables`],queryFn:Z.getTemplateVariables}),m=p?.find(t=>t.event_type===e.event_type),{data:h,isLoading:g}=K({queryKey:[`template-preview`,e.event_type,a,s],queryFn:()=>Z.previewTemplate({event_type:e.event_type,title_template:a,body_template:s}),enabled:d&&a.length>0&&s.length>0});(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]);let _=q({mutationFn:t=>Z.updateNotificationTemplate(e.id,t),onSuccess:()=>{r.invalidateQueries({queryKey:[`notification-templates`]}),t()},onError:e=>{u(e.message)}}),v=q({mutationFn:()=>Z.resetNotificationTemplate(e.id),onSuccess:e=>{o(e.title_template),c(e.body_template),r.invalidateQueries({queryKey:[`notification-templates`]})},onError:e=>{u(e.message)}}),b=e=>{if(e.preventDefault(),u(null),!a.trim()){u(n(`notifications.titleRequired`));return}if(!s.trim()){u(n(`notifications.bodyRequired`));return}_.mutate({title_template:a,body_template:s})},x=e=>{let t=i.current;if(!t)return;let n=t.selectionStart,r=t.selectionEnd,a=s,o=a.substring(0,n),l=a.substring(r);c(o+`{${e}}`+l),setTimeout(()=>{t.focus();let r=n+e.length+2;t.setSelectionRange(r,r)},0)},S=a!==e.title_template||s!==e.body_template;return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/80 flex items-center justify-center z-50 p-4`,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg w-full max-w-2xl max-h-[90vh] flex flex-col`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary shrink-0`,children:[(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:n(`notifications.editTemplate`,{name:e.name})}),(0,G.jsx)(`button`,{onClick:t,className:`p-1 hover:bg-bambu-dark-tertiary rounded transition-colors`,children:(0,G.jsx)(nd,{className:`w-5 h-5 text-bambu-gray`})})]}),(0,G.jsxs)(`form`,{onSubmit:b,className:`flex-1 overflow-y-auto p-4 space-y-4`,children:[l&&(0,G.jsx)(`div`,{className:`p-3 bg-red-100 dark:bg-red-500/20 border border-red-300 dark:border-red-500/50 rounded text-red-700 dark:text-red-400 text-sm`,children:l}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:n(`notifications.titleLabel`)}),(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 text-white focus:outline-none focus:ring-1 focus:ring-bambu-green`,placeholder:n(`notifications.titlePlaceholder`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:n(`notifications.bodyLabel`)}),(0,G.jsx)(`textarea`,{ref:i,value:s,onChange:e=>c(e.target.value),rows:4,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white focus:outline-none focus:ring-1 focus:ring-bambu-green font-mono text-sm resize-none`,placeholder:n(`notifications.bodyPlaceholder`)})]}),m&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-2`,children:n(`notifications.availableVariables`)}),(0,G.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:m.variables.map(e=>(0,G.jsxs)(`button`,{type:`button`,onClick:()=>x(e),className:`inline-flex items-center gap-1 px-2 py-1 bg-bambu-dark hover:bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-xs text-bambu-gray hover:text-white transition-colors`,children:[(0,G.jsx)(Fl,{className:`w-3 h-3`}),e]},e))}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray/60 mt-1`,children:n(`notifications.clickToInsert`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,G.jsxs)(`label`,{className:`text-sm font-medium text-bambu-gray flex items-center gap-2`,children:[(0,G.jsx)(ac,{className:`w-4 h-4`}),n(`notifications.livePreview`)]}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>f(!d),className:`text-xs text-bambu-green hover:text-bambu-green-light`,children:n(d?`notifications.hide`:`notifications.show`)})]}),d&&(0,G.jsx)(`div`,{className:`bg-bambu-dark border border-bambu-dark-tertiary rounded p-3 space-y-2`,children:g?(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(`notifications.loadingPreview`)]}):h?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:n(`notifications.titlePreview`)}),(0,G.jsx)(`div`,{className:`text-white font-medium`,children:h.title})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:n(`notifications.bodyPreview`)}),(0,G.jsx)(`div`,{className:`text-white whitespace-pre-wrap text-sm`,children:h.body})]})]}):(0,G.jsx)(`div`,{className:`text-bambu-gray text-sm`,children:n(`notifications.enterTemplateContent`)})})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-t border-bambu-dark-tertiary shrink-0`,children:[(0,G.jsxs)(Q,{type:`button`,variant:`ghost`,onClick:()=>v.mutate(),disabled:v.isPending,className:`text-orange-600 dark:text-orange-400 hover:text-orange-700 dark:hover:text-orange-300`,children:[v.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin mr-2`}):(0,G.jsx)(Wl,{className:`w-4 h-4 mr-2`}),n(`notifications.resetToDefault`)]}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:t,children:n(`notifications.cancel`)}),(0,G.jsxs)(Q,{onClick:b,disabled:_.isPending||!S,children:[_.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin mr-2`}):(0,G.jsx)(ql,{className:`w-4 h-4 mr-2`}),n(`notifications.save`)]})]})]})]})})}var KWe={print_start:`text-blue-700 dark:text-blue-400`,print_complete:`text-bambu-green`,print_failed:`text-red-700 dark:text-red-400`,print_stopped:`text-orange-700 dark:text-orange-400`,print_progress:`text-yellow-700 dark:text-yellow-400`,printer_offline:`text-gray-400`,printer_error:`text-rose-700 dark:text-rose-400`,filament_low:`text-cyan-700 dark:text-cyan-400`,maintenance_due:`text-purple-700 dark:text-purple-400`,test:`text-bambu-gray`};function qWe({onClose:e}){let{t}=U(),n=co(),{showToast:r}=qd(),[i,a]=(0,y.useState)(7),[o,s]=(0,y.useState)(null),[c,l]=(0,y.useState)(!1),{data:u}=K({queryKey:[`settings`],queryFn:Z.getSettings}),d=u?.time_format||`system`,{data:f,isLoading:p,refetch:m,isRefetching:h}=K({queryKey:[`notification-logs`,i,c],queryFn:()=>Z.getNotificationLogs({days:i,limit:100,success:c?!1:void 0})}),{data:g}=K({queryKey:[`notification-log-stats`,i],queryFn:()=>Z.getNotificationLogStats(i)}),_=q({mutationFn:()=>Z.clearNotificationLogs(30),onSuccess:e=>{r(e.message,`success`),n.invalidateQueries({queryKey:[`notification-logs`]}),n.invalidateQueries({queryKey:[`notification-log-stats`]})},onError:e=>{r(`Failed to clear logs: ${e.message}`,`error`)}}),v=e=>{let n=rp(e);if(!n)return``;let r=new Date().getTime()-n.getTime();return r<6e4?t(`notifications.justNow`):r<36e5?`${Math.floor(r/6e4)}m ago`:r<864e5?`${Math.floor(r/36e5)}h ago`:n.toLocaleDateString()+` `+sp(n,d)};return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg w-full max-w-3xl max-h-[85vh] flex flex-col`,children:[(0,G.jsxs)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(zc,{className:`w-5 h-5 text-bambu-green`}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:t(`notifications.notificationLog`)})]}),(0,G.jsx)(`button`,{onClick:e,className:`text-bambu-gray hover:text-white transition-colors`,children:`×`})]}),g&&(0,G.jsx)(`div`,{className:`px-4 py-3 border-b border-bambu-dark-tertiary bg-bambu-dark/50`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-6 text-sm`,children:[(0,G.jsxs)(`span`,{className:`text-bambu-gray`,children:[t(`notifications.statsSummary`,{days:i}),` `,(0,G.jsx)(`span`,{className:`text-white font-medium`,children:g.total}),` `,t(`notifications.statsNotifications`)]}),(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-bambu-green`,children:[(0,G.jsx)(xs,{className:`w-4 h-4`}),t(`notifications.statsSent`,{count:g.success_count})]}),g.failure_count>0&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-red-700 dark:text-red-400`,children:[(0,G.jsx)(Ds,{className:`w-4 h-4`}),t(`notifications.statsFailed`,{count:g.failure_count})]})]})}),(0,G.jsxs)(`div`,{className:`px-4 py-3 border-b border-bambu-dark-tertiary flex items-center gap-4`,children:[(0,G.jsxs)(`select`,{value:i,onChange:e=>a(Number(e.target.value)),className:`px-3 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:outline-none focus:ring-1 focus:ring-bambu-green`,children:[(0,G.jsx)(`option`,{value:1,children:t(`notifications.last24Hours`)}),(0,G.jsx)(`option`,{value:7,children:t(`notifications.last7Days`)}),(0,G.jsx)(`option`,{value:30,children:t(`notifications.last30Days`)}),(0,G.jsx)(`option`,{value:90,children:t(`notifications.last90Days`)})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-bambu-gray cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:c,onChange:e=>l(e.target.checked),className:`rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),t(`notifications.showFailedOnly`)]}),(0,G.jsx)(`div`,{className:`flex-1`}),(0,G.jsxs)(Q,{size:`sm`,variant:`secondary`,onClick:()=>m(),disabled:h,children:[h?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Hl,{className:`w-4 h-4`}),t(`notifications.refresh`)]}),(0,G.jsxs)(Q,{size:`sm`,variant:`secondary`,onClick:()=>_.mutate(),disabled:_.isPending,className:`text-red-700 dark:text-red-400 hover:text-red-800 dark:hover:text-red-300`,children:[_.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Pu,{className:`w-4 h-4`}),t(`notifications.clearOld`)]})]}),(0,G.jsx)(`div`,{className:`flex-1 overflow-y-auto p-4`,children:p?(0,G.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,G.jsx)(Y,{className:`w-6 h-6 text-bambu-green animate-spin`})}):f&&f.length>0?(0,G.jsx)(`div`,{className:`space-y-2`,children:f.map(e=>(0,G.jsx)(JWe,{log:e,isExpanded:o===e.id,onToggle:()=>s(o===e.id?null:e.id),formatDate:v,formatFullDate:e=>op(e,d)},e.id))}):(0,G.jsxs)(`div`,{className:`text-center py-12 text-bambu-gray`,children:[(0,G.jsx)(zc,{className:`w-12 h-12 mx-auto mb-3 opacity-30`}),(0,G.jsx)(`p`,{className:`text-sm`,children:t(c?`notifications.noFailedNotifications`:`notifications.noNotificationsLogged`)})]})})]})})}function JWe({log:e,isExpanded:t,onToggle:n,formatDate:r,formatFullDate:i}){let{t:a}=U();return(0,G.jsxs)(`div`,{className:`border rounded-lg overflow-hidden transition-colors ${e.success?`border-bambu-dark-tertiary bg-bambu-dark/30`:`border-red-500/30 bg-red-500/5`}`,children:[(0,G.jsxs)(`button`,{className:`w-full px-3 py-2 flex items-center gap-3 text-left hover:bg-bambu-dark/50 transition-colors`,onClick:n,children:[e.success?(0,G.jsx)(xs,{className:`w-4 h-4 text-bambu-green shrink-0`}):(0,G.jsx)(Ds,{className:`w-4 h-4 text-red-600 dark:text-red-400 shrink-0`}),(0,G.jsx)(`span`,{className:`text-xs font-medium ${KWe[e.event_type]||`text-bambu-gray`}`,children:a(`notifications.eventTypes.${e.event_type}`,e.event_type)}),(0,G.jsx)(`span`,{className:`text-sm text-white truncate flex-1`,children:e.provider_name||a(`notifications.unknownProvider`)}),e.printer_name&&(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:e.printer_name}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray shrink-0`,children:r(e.created_at)}),t?(0,G.jsx)(gs,{className:`w-4 h-4 text-bambu-gray shrink-0`}):(0,G.jsx)(ps,{className:`w-4 h-4 text-bambu-gray shrink-0`})]}),t&&(0,G.jsxs)(`div`,{className:`px-3 py-2 border-t border-bambu-dark-tertiary bg-bambu-dark/20 space-y-2`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mb-1`,children:a(`notifications.logTitle`)}),(0,G.jsx)(`p`,{className:`text-sm text-white`,children:e.title})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mb-1`,children:a(`notifications.logMessage`)}),(0,G.jsx)(`p`,{className:`text-sm text-white whitespace-pre-wrap`,children:e.message})]}),!e.success&&e.error_message&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-xs text-red-700 dark:text-red-400 mb-1`,children:a(`notifications.logError`)}),(0,G.jsx)(`p`,{className:`text-sm text-red-700 dark:text-red-300`,children:e.error_message})]}),(0,G.jsxs)(`div`,{className:`flex gap-4 text-xs text-bambu-gray pt-1`,children:[(0,G.jsx)(`span`,{children:a(`notifications.logProvider`,{type:e.provider_type})}),(0,G.jsx)(`span`,{children:a(`notifications.logTime`,{time:i(e.created_at)})})]})]})]})}var YWe=Object.defineProperty,i8=Object.getOwnPropertySymbols,a8=Object.prototype.hasOwnProperty,o8=Object.prototype.propertyIsEnumerable,s8=(e,t,n)=>t in e?YWe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,c8=(e,t)=>{for(var n in t||={})a8.call(t,n)&&s8(e,n,t[n]);if(i8)for(var n of i8(t))o8.call(t,n)&&s8(e,n,t[n]);return e},l8=(e,t)=>{var n={};for(var r in e)a8.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&i8)for(var r of i8(e))t.indexOf(r)<0&&o8.call(e,r)&&(n[r]=e[r]);return n},u8;(e=>{let t=class t{constructor(e,n,r,a){if(this.version=e,this.errorCorrectionLevel=n,this.modules=[],this.isFunction=[],et.MAX_VERSION)throw RangeError(`Version value out of range`);if(a<-1||a>7)throw RangeError(`Mask value out of range`);this.size=e*4+17;let o=[];for(let e=0;e7)throw RangeError(`Invalid value`);let u,d;for(u=a;;u++){let n=t.getNumDataCodewords(u,r)*8,i=o.getTotalBits(e,u);if(i<=n){d=i;break}if(u>=s)throw RangeError(`Data too long`)}for(let e of[t.Ecc.MEDIUM,t.Ecc.QUARTILE,t.Ecc.HIGH])l&&d<=t.getNumDataCodewords(u,e)*8&&(r=e);let f=[];for(let t of e){n(t.mode.modeBits,4,f),n(t.numChars,t.mode.numCharCountBits(u),f);for(let e of t.getData())f.push(e)}i(f.length==d);let p=t.getNumDataCodewords(u,r)*8;i(f.length<=p),n(0,Math.min(4,p-f.length),f),n(0,(8-f.length%8)%8,f),i(f.length%8==0);for(let e=236;f.lengthm[t>>>3]|=e<<7-(t&7)),new t(u,r,m,c)}getModule(e,t){return 0<=e&&e>>9)*1335;let a=(t<<10|n)^21522;i(a>>>15==0);for(let e=0;e<=5;e++)this.setFunctionModule(8,e,r(a,e));this.setFunctionModule(8,7,r(a,6)),this.setFunctionModule(8,8,r(a,7)),this.setFunctionModule(7,8,r(a,8));for(let e=9;e<15;e++)this.setFunctionModule(14-e,8,r(a,e));for(let e=0;e<8;e++)this.setFunctionModule(this.size-1-e,8,r(a,e));for(let e=8;e<15;e++)this.setFunctionModule(8,this.size-15+e,r(a,e));this.setFunctionModule(8,this.size-8,!0)}drawVersion(){if(this.version<7)return;let e=this.version;for(let t=0;t<12;t++)e=e<<1^(e>>>11)*7973;let t=this.version<<12|e;i(t>>>18==0);for(let e=0;e<18;e++){let n=r(t,e),i=this.size-11+e%3,a=Math.floor(e/3);this.setFunctionModule(i,a,n),this.setFunctionModule(a,i,n)}}drawFinderPattern(e,t){for(let n=-4;n<=4;n++)for(let r=-4;r<=4;r++){let i=Math.max(Math.abs(r),Math.abs(n)),a=e+r,o=t+n;0<=a&&a{(e!=l-o||n>=c)&&f.push(t[e])});return i(f.length==s),f}drawCodewords(e){if(e.length!=Math.floor(t.getNumRawDataModules(this.version)/8))throw RangeError(`Invalid argument`);let n=0;for(let t=this.size-1;t>=1;t-=2){t==6&&(t=5);for(let i=0;i>>3],7-(n&7)),n++)}}i(n==e.length*8)}applyMask(e){if(e<0||e>7)throw RangeError(`Mask value out of range`);for(let t=0;t5&&e++):(this.finderPenaltyAddHistory(i,a),r||(e+=this.finderPenaltyCountPatterns(a)*t.PENALTY_N3),r=this.modules[n][o],i=1);e+=this.finderPenaltyTerminateAndCount(r,i,a)*t.PENALTY_N3}for(let n=0;n5&&e++):(this.finderPenaltyAddHistory(i,a),r||(e+=this.finderPenaltyCountPatterns(a)*t.PENALTY_N3),r=this.modules[o][n],i=1);e+=this.finderPenaltyTerminateAndCount(r,i,a)*t.PENALTY_N3}for(let n=0;ne+ +!!t,n);let r=this.size*this.size,a=Math.ceil(Math.abs(n*20-r*10)/r)-1;return i(0<=a&&a<=9),e+=a*t.PENALTY_N4,i(0<=e&&e<=2568888),e}getAlignmentPatternPositions(){if(this.version==1)return[];{let e=Math.floor(this.version/7)+2,t=this.version==32?26:Math.ceil((this.version*4+4)/(e*2-2))*2,n=[6];for(let r=this.size-7;n.lengtht.MAX_VERSION)throw RangeError(`Version number out of range`);let n=(16*e+128)*e+64;if(e>=2){let t=Math.floor(e/7)+2;n-=(25*t-10)*t-55,e>=7&&(n-=36)}return i(208<=n&&n<=29648),n}static getNumDataCodewords(e,n){return Math.floor(t.getNumRawDataModules(e)/8)-t.ECC_CODEWORDS_PER_BLOCK[n.ordinal][e]*t.NUM_ERROR_CORRECTION_BLOCKS[n.ordinal][e]}static reedSolomonComputeDivisor(e){if(e<1||e>255)throw RangeError(`Degree out of range`);let n=[];for(let t=0;t0);for(let i of e){let e=i^r.shift();r.push(0),n.forEach((n,i)=>r[i]^=t.reedSolomonMultiply(n,e))}return r}static reedSolomonMultiply(e,t){if(e>>>8||t>>>8)throw RangeError(`Byte out of range`);let n=0;for(let r=7;r>=0;r--)n=n<<1^(n>>>7)*285,n^=(t>>>r&1)*e;return i(n>>>8==0),n}finderPenaltyCountPatterns(e){let t=e[1];i(t<=this.size*3);let n=t>0&&e[2]==t&&e[3]==t*3&&e[4]==t&&e[5]==t;return(n&&e[0]>=t*4&&e[6]>=t?1:0)+(n&&e[6]>=t*4&&e[0]>=t?1:0)}finderPenaltyTerminateAndCount(e,t,n){return e&&(this.finderPenaltyAddHistory(t,n),t=0),t+=this.size,this.finderPenaltyAddHistory(t,n),this.finderPenaltyCountPatterns(n)}finderPenaltyAddHistory(e,t){t[0]==0&&(e+=this.size),t.pop(),t.unshift(e)}};t.MIN_VERSION=1,t.MAX_VERSION=40,t.PENALTY_N1=3,t.PENALTY_N2=3,t.PENALTY_N3=40,t.PENALTY_N4=10,t.ECC_CODEWORDS_PER_BLOCK=[[-1,7,10,15,20,26,18,20,24,30,18,20,24,26,30,22,24,28,30,28,28,28,28,30,30,26,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,10,16,26,18,24,16,18,22,22,26,30,22,22,24,24,28,28,26,26,26,26,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28],[-1,13,22,18,26,18,24,18,22,20,24,28,26,24,20,30,24,28,28,26,30,28,30,30,30,30,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,17,28,22,16,22,28,26,26,24,28,24,28,22,24,24,30,28,28,26,28,30,24,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30]],t.NUM_ERROR_CORRECTION_BLOCKS=[[-1,1,1,1,1,1,2,2,2,2,4,4,4,4,4,6,6,6,6,7,8,8,9,9,10,12,12,12,13,14,15,16,17,18,19,19,20,21,22,24,25],[-1,1,1,1,2,2,4,4,4,5,5,5,8,9,9,10,10,11,13,14,16,17,17,18,20,21,23,25,26,28,29,31,33,35,37,38,40,43,45,47,49],[-1,1,1,2,2,4,4,6,6,8,8,8,10,12,16,12,17,16,18,21,20,23,23,25,27,29,34,34,35,38,40,43,45,48,51,53,56,59,62,65,68],[-1,1,1,2,4,4,4,5,6,8,8,11,11,16,16,18,16,19,21,25,25,25,34,30,32,35,37,40,42,45,48,51,54,57,60,63,66,70,74,77,81]],e.QrCode=t;function n(e,t,n){if(t<0||t>31||e>>>t)throw RangeError(`Value out of range`);for(let r=t-1;r>=0;r--)n.push(e>>>r&1)}function r(e,t){return(e>>>t&1)!=0}function i(e){if(!e)throw Error(`Assertion error`)}let a=class e{constructor(e,t,n){if(this.mode=e,this.numChars=t,this.bitData=n,t<0)throw RangeError(`Invalid argument`);this.bitData=n.slice()}static makeBytes(t){let r=[];for(let e of t)n(e,8,r);return new e(e.Mode.BYTE,t.length,r)}static makeNumeric(t){if(!e.isNumeric(t))throw RangeError(`String contains non-numeric characters`);let r=[];for(let e=0;e=1<{(e=>{let t=class{constructor(e,t){this.ordinal=e,this.formatBits=t}};t.LOW=new t(0,1),t.MEDIUM=new t(1,0),t.QUARTILE=new t(2,3),t.HIGH=new t(3,2),e.Ecc=t})(e.QrCode||={})})(u8||={}),(e=>{(e=>{let t=class{constructor(e,t){this.modeBits=e,this.numBitsCharCount=t}numCharCountBits(e){return this.numBitsCharCount[Math.floor((e+7)/17)]}};t.NUMERIC=new t(1,[10,12,14]),t.ALPHANUMERIC=new t(2,[9,11,13]),t.BYTE=new t(4,[8,16,16]),t.KANJI=new t(8,[8,10,12]),t.ECI=new t(7,[0,0,0]),e.Mode=t})(e.QrSegment||={})})(u8||={});var d8=u8,XWe={L:d8.QrCode.Ecc.LOW,M:d8.QrCode.Ecc.MEDIUM,Q:d8.QrCode.Ecc.QUARTILE,H:d8.QrCode.Ecc.HIGH},f8=128,p8=`L`,m8=`#FFFFFF`,h8=`#000000`,g8=!1,_8=1,ZWe=4,QWe=0,$We=.1;function v8(e,t=0){let n=[];return e.forEach(function(e,r){let i=null;e.forEach(function(a,o){if(!a&&i!==null){n.push(`M${i+t} ${r+t}h${o-i}v1H${i+t}z`),i=null;return}if(o===e.length-1){if(!a)return;i===null?n.push(`M${o+t},${r+t} h1v1H${o+t}z`):n.push(`M${i+t},${r+t} h${o+1-i}v1H${i+t}z`);return}a&&i===null&&(i=o)})}),n.join(``)}function y8(e,t){return e.slice().map((e,n)=>n=t.y+t.h?e:e.map((e,n)=>n=t.x+t.w?e:!1))}function eGe(e,t,n,r){if(r==null)return null;let i=e.length+n*2,a=Math.floor(t*$We),o=i/t,s=(r.width||a)*o,c=(r.height||a)*o,l=r.x==null?e.length/2-s/2:r.x*o,u=r.y==null?e.length/2-c/2:r.y*o,d=r.opacity==null?1:r.opacity,f=null;if(r.excavate){let e=Math.floor(l),t=Math.floor(u);f={x:e,y:t,w:Math.ceil(s+l-e),h:Math.ceil(c+u-t)}}let p=r.crossOrigin;return{x:l,y:u,h:c,w:s,excavation:f,opacity:d,crossOrigin:p}}function tGe(e,t){return t==null?e?ZWe:QWe:Math.max(Math.floor(t),0)}function b8({value:e,level:t,minVersion:n,includeMargin:r,marginSize:i,imageSettings:a,size:o,boostLevel:s}){let c=y.useMemo(()=>{let r=(Array.isArray(e)?e:[e]).reduce((e,t)=>(e.push(...d8.QrSegment.makeSegments(t)),e),[]);return d8.QrCode.encodeSegments(r,XWe[t],n,void 0,void 0,s)},[e,t,n,s]),{cells:l,margin:u,numCells:d,calculatedImageSettings:f}=y.useMemo(()=>{let e=c.getModules(),t=tGe(r,i);return{cells:e,margin:t,numCells:e.length+t*2,calculatedImageSettings:eGe(e,o,t,a)}},[c,o,a,r,i]);return{qrcode:c,margin:u,cells:l,numCells:d,calculatedImageSettings:f}}var nGe=function(){try{new Path2D().addPath(new Path2D)}catch{return!1}return!0}(),rGe=y.forwardRef(function(e,t){let n=e,{value:r,size:i=f8,level:a=p8,bgColor:o=m8,fgColor:s=h8,includeMargin:c=g8,minVersion:l=_8,boostLevel:u,marginSize:d,imageSettings:f}=n,p=l8(n,[`value`,`size`,`level`,`bgColor`,`fgColor`,`includeMargin`,`minVersion`,`boostLevel`,`marginSize`,`imageSettings`]),{style:m}=p,h=l8(p,[`style`]),g=f?.src,_=y.useRef(null),v=y.useRef(null),b=y.useCallback(e=>{_.current=e,typeof t==`function`?t(e):t&&(t.current=e)},[t]),[x,S]=y.useState(!1),{margin:C,cells:w,numCells:T,calculatedImageSettings:E}=b8({value:r,level:a,minVersion:l,boostLevel:u,includeMargin:c,marginSize:d,imageSettings:f,size:i});y.useEffect(()=>{if(_.current!=null){let e=_.current,t=e.getContext(`2d`);if(!t)return;let n=w,r=v.current,a=E!=null&&r!==null&&r.complete&&r.naturalHeight!==0&&r.naturalWidth!==0;a&&E.excavation!=null&&(n=y8(w,E.excavation));let c=window.devicePixelRatio||1;e.height=e.width=i*c;let l=i/T*c;t.scale(l,l),t.fillStyle=o,t.fillRect(0,0,T,T),t.fillStyle=s,nGe?t.fill(new Path2D(v8(n,C))):w.forEach(function(e,n){e.forEach(function(e,r){e&&t.fillRect(r+C,n+C,1,1)})}),E&&(t.globalAlpha=E.opacity),a&&t.drawImage(r,E.x+C,E.y+C,E.w,E.h)}}),y.useEffect(()=>{S(!1)},[g]);let D=c8({height:i,width:i},m),O=null;return g!=null&&(O=y.createElement(`img`,{src:g,key:g,style:{display:`none`},onLoad:()=>{S(!0)},ref:v,crossOrigin:E?.crossOrigin})),y.createElement(y.Fragment,null,y.createElement(`canvas`,c8({style:D,height:i,width:i,ref:b,role:`img`},h)),O)});rGe.displayName=`QRCodeCanvas`;var x8=y.forwardRef(function(e,t){let n=e,{value:r,size:i=f8,level:a=p8,bgColor:o=m8,fgColor:s=h8,includeMargin:c=g8,minVersion:l=_8,boostLevel:u,title:d,marginSize:f,imageSettings:p}=n,m=l8(n,[`value`,`size`,`level`,`bgColor`,`fgColor`,`includeMargin`,`minVersion`,`boostLevel`,`title`,`marginSize`,`imageSettings`]),{margin:h,cells:g,numCells:_,calculatedImageSettings:v}=b8({value:r,level:a,minVersion:l,boostLevel:u,includeMargin:c,marginSize:f,imageSettings:p,size:i}),b=g,x=null;p!=null&&v!=null&&(v.excavation!=null&&(b=y8(g,v.excavation)),x=y.createElement(`image`,{href:p.src,height:v.h,width:v.w,x:v.x+h,y:v.y+h,preserveAspectRatio:`none`,opacity:v.opacity,crossOrigin:v.crossOrigin}));let S=v8(b,h);return y.createElement(`svg`,c8({height:i,width:i,viewBox:`0 0 ${_} ${_}`,ref:t,role:`img`},m),!!d&&y.createElement(`title`,null,d),y.createElement(`path`,{fill:o,d:`M0,0 h${_}v${_}H0z`,shapeRendering:`crispEdges`}),y.createElement(`path`,{fill:s,d:S,shapeRendering:`crispEdges`}),x)});x8.displayName=`QRCodeSVG`;function iGe(e,t){return`bambuddy://config?v=1&url=${encodeURIComponent(e)}&key=${encodeURIComponent(t)}`}function aGe({apiKey:e,baseUrl:t,onClose:n}){let{t:r}=U(),i=iGe(t??window.location.origin,e);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:r(`settings.apiKeyQrTitle`)}),(0,G.jsx)(`button`,{onClick:n,className:`text-bambu-gray hover:text-white transition-colors`,"aria-label":r(`common.close`),children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]}),(0,G.jsxs)(`div`,{className:`p-6 flex flex-col items-center`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4 text-center`,children:r(`settings.apiKeyQrCaption`)}),(0,G.jsx)(`div`,{className:`bg-white p-4 rounded-lg mb-4`,children:(0,G.jsx)(x8,{value:i,size:256})}),(0,G.jsxs)(`div`,{className:`flex items-start gap-2 text-xs text-amber-700 dark:text-amber-400 mb-4`,children:[(0,G.jsx)(Lu,{className:`w-4 h-4 flex-shrink-0 mt-0.5`}),(0,G.jsx)(`span`,{children:r(`settings.apiKeyQrWarning`)})]}),(0,G.jsx)(Q,{onClick:n,className:`w-full`,children:r(`common.close`)})]})]})})}var oGe=300,S8=2;function C8({onSuccess:e}){let{t}=U(),n=co(),[r,i]=(0,y.useState)(``),[a,o]=(0,y.useState)(``),[s,c]=(0,y.useState)(null),[l,u]=(0,y.useState)(null);(0,y.useEffect)(()=>{let e=r.trim();if(e.lengtho(e),oGe);return()=>clearTimeout(t)},[r]),(0,y.useEffect)(()=>{c(null),u(null)},[a]);let d=K({queryKey:[`ldap-search`,a],queryFn:()=>Z.searchLDAPDirectory(a),enabled:a.length>=S8,staleTime:3e4}),f=q({mutationFn:e=>Z.provisionLDAPUser(e),onSuccess:t=>{n.invalidateQueries({queryKey:[`users`]}),e(t)},onError:e=>{u(e.message||t(`users.modal.ldapErrorProvision`))}}),p=(0,y.useMemo)(()=>d.data?.find(e=>e.dn===s)??null,[d.data,s]),m=r.trim().length>0&&r.trim().length=S8,g=!!d.data&&d.data.length>0,_=!h&&!!d.data&&d.data.length===0&&a.length>=S8;return(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:t(`users.modal.ldapSearchLabel`)}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(Ql,{className:`w-4 h-4 text-bambu-gray absolute left-3 top-1/2 -translate-y-1/2`}),(0,G.jsx)(`input`,{type:`text`,value:r,onChange:e=>i(e.target.value),className:`w-full pl-9 pr-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:t(`users.modal.ldapSearchPlaceholder`),autoComplete:`off`})]}),m&&(0,G.jsx)(`p`,{className:`mt-1 text-xs text-bambu-gray`,children:t(`users.modal.ldapMinChars`)})]}),(0,G.jsxs)(`div`,{className:`min-h-[8rem] max-h-64 overflow-y-auto bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg`,children:[h&&(0,G.jsxs)(`div`,{className:`flex items-center justify-center py-8 text-bambu-gray`,children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin mr-2`}),(0,G.jsx)(`span`,{children:t(`users.modal.ldapSearching`)})]}),_&&(0,G.jsx)(`div`,{className:`flex items-center justify-center py-8 text-bambu-gray text-sm`,children:t(`users.modal.ldapNoResults`)}),d.isError&&(0,G.jsx)(`div`,{className:`px-3 py-4 text-sm text-red-700 dark:text-red-400`,children:d.error instanceof Error?d.error.message:t(`users.modal.ldapSearchError`)}),!h&&g&&(0,G.jsx)(`ul`,{className:`divide-y divide-bambu-dark-tertiary`,children:d.data.map(e=>(0,G.jsx)(sGe,{result:e,selected:s===e.dn,onSelect:()=>c(e.dn)},e.dn))}),!h&&!d.data&&!d.isError&&(0,G.jsx)(`div`,{className:`flex items-center justify-center py-8 text-bambu-gray text-sm`,children:t(`users.modal.ldapTypeToSearch`)})]}),p&&(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary/50 border border-bambu-green/20 rounded-lg p-3 space-y-1`,children:[(0,G.jsxs)(`p`,{className:`text-sm text-white`,children:[(0,G.jsxs)(`span`,{className:`text-bambu-gray`,children:[t(`users.modal.ldapSelectedLabel`),`: `]}),(0,G.jsx)(`span`,{className:`font-medium`,children:p.username}),p.display_name&&(0,G.jsxs)(`span`,{className:`text-bambu-gray`,children:[` — `,p.display_name]})]}),p.email&&(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:p.email}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray break-all`,children:p.dn})]}),l&&(0,G.jsx)(`div`,{className:`bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30 rounded-lg p-3`,children:(0,G.jsx)(`p`,{className:`text-sm text-red-700 dark:text-red-400`,children:l})}),(0,G.jsx)(`div`,{className:`flex justify-end`,children:(0,G.jsx)(Q,{onClick:()=>{!p||p.already_provisioned||(u(null),f.mutate(p.username))},disabled:!p||p.already_provisioned||f.isPending,children:f.isPending?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),t(`users.modal.ldapProvisioning`)]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Fl,{className:`w-4 h-4`}),t(`users.modal.ldapProvision`)]})})})]})}function sGe({result:e,selected:t,onSelect:n}){let{t:r}=U(),i=e.already_provisioned;return(0,G.jsx)(`li`,{children:(0,G.jsxs)(`button`,{type:`button`,onClick:n,disabled:i,className:`w-full text-left px-3 py-2 flex items-center gap-3 transition-colors ${i?`opacity-50 cursor-not-allowed`:t?`bg-bambu-green/10`:`hover:bg-bambu-dark-tertiary`}`,children:[(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsxs)(`p`,{className:`text-sm text-white truncate`,children:[(0,G.jsx)(`span`,{className:`font-medium`,children:e.username}),e.display_name&&(0,G.jsxs)(`span`,{className:`text-bambu-gray`,children:[` — `,e.display_name]})]}),e.email&&(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray truncate`,children:e.email})]}),i&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-xs text-bambu-gray whitespace-nowrap`,children:[(0,G.jsx)(Ss,{className:`w-3.5 h-3.5`}),r(`users.modal.ldapAlreadyProvisioned`)]})]})})}function cGe({formData:e,setFormData:t,groups:n,onClose:r,onCreate:i,isCreating:a,isCreateButtonDisabled:o,ldapEnabled:s=!1,onLdapProvisioned:c}){let{t:l}=U(),[u,d]=(0,y.useState)(`local`);(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&r()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[r]);let f=n=>{t({...e,group_ids:e.group_ids.includes(n)?e.group_ids.filter(e=>e!==n):[...e.group_ids,n]})};return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:r,children:(0,G.jsxs)(zd,{className:`w-full max-w-md`,onClick:e=>e.stopPropagation(),children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Uu,{className:`w-5 h-5 text-bambu-green`}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:l(`users.modal.createUser`)})]}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray ml-7`,children:l(`users.modal.advancedAuthSubtitle`)||`with Advanced Authentication`})]}),(0,G.jsx)(Q,{variant:`ghost`,size:`sm`,onClick:r,children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]})}),(0,G.jsxs)(Vd,{children:[s&&(0,G.jsxs)(`div`,{className:`mb-4 flex items-center gap-1 p-1 bg-bambu-dark-secondary rounded-lg`,role:`tablist`,"aria-label":l(`users.modal.tabsAriaLabel`),children:[(0,G.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":u===`local`,onClick:()=>d(`local`),className:`flex-1 px-3 py-2 text-sm rounded-md transition-colors ${u===`local`?`bg-bambu-green/15 text-bambu-green`:`text-bambu-gray hover:text-white`}`,children:l(`users.modal.localTab`)}),(0,G.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":u===`ldap`,onClick:()=>d(`ldap`),className:`flex-1 px-3 py-2 text-sm rounded-md transition-colors ${u===`ldap`?`bg-bambu-green/15 text-bambu-green`:`text-bambu-gray hover:text-white`}`,children:l(`users.modal.ldapTab`)})]}),u===`ldap`&&s?(0,G.jsx)(C8,{onSuccess:e=>{c?.(e)}}):(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:[l(`users.form.username`),` `,(0,G.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:`*`})]}),(0,G.jsx)(`input`,{type:`text`,value:e.username,onChange:n=>t({...e,username:n.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:l(`users.form.usernamePlaceholder`),autoComplete:`username`,required:!0})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:[l(`users.form.email`)||`Email`,` `,(0,G.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:`*`})]}),(0,G.jsx)(`input`,{type:`email`,value:e.email,onChange:n=>t({...e,email:n.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:l(`users.form.emailPlaceholder`)||`user@example.com`,required:!0})]}),(0,G.jsx)(`div`,{className:`bg-bambu-dark-secondary/50 border border-bambu-green/20 rounded-lg p-3`,children:(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:l(`users.form.autoGeneratedPassword`)||`A secure password will be automatically generated and emailed to the user.`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:l(`users.form.groups`)}),(0,G.jsxs)(`div`,{className:`space-y-2 max-h-40 overflow-y-auto p-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg`,children:[n.map(t=>(0,G.jsxs)(`label`,{className:`flex items-center gap-3 px-2 py-1.5 rounded hover:bg-bambu-dark-tertiary cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:e.group_ids.includes(t.id),onChange:()=>f(t.id),className:`w-4 h-4 rounded border-bambu-gray text-bambu-green focus:ring-bambu-green focus:ring-offset-0 bg-bambu-dark`}),(0,G.jsx)(`span`,{className:`text-sm text-white`,children:t.name}),t.is_system&&(0,G.jsxs)(`span`,{className:`text-xs text-yellow-700 dark:text-yellow-400`,children:[`(`,l(`users.system`),`)`]})]},t.id)),n.length===0&&(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:l(`users.noGroupsAvailable`)})]})]})]}),(0,G.jsxs)(`div`,{className:`mt-6 flex justify-end gap-3`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:r,children:l(`users.modal.cancel`)}),u===`local`&&(0,G.jsx)(Q,{onClick:i,disabled:o,children:a?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),l(`users.modal.creating`)]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Fl,{className:`w-4 h-4`}),l(`users.modal.createUser`)]})})]})]})]})})}function lGe(){let{t:e}=U(),t=co(),{showToast:n}=qd(),[r,i]=(0,y.useState)(!1),[a,o]=(0,y.useState)(``),[s,c]=(0,y.useState)(`auto`),[l,u]=(0,y.useState)(!1),[d,f]=(0,y.useState)(!0),[p,m]=(0,y.useState)(!0),[h,g]=(0,y.useState)(`all`),[_,v]=(0,y.useState)(!1),[b,x]=(0,y.useState)(!1),[S,C]=(0,y.useState)(!1),[w,T]=(0,y.useState)(!1),{data:E,isLoading:D}=K({queryKey:[`spoolman-settings`],queryFn:Z.getSpoolmanSettings}),{data:O,isLoading:k,refetch:A}=K({queryKey:[`spoolman-status`],queryFn:Z.getSpoolmanStatus,refetchInterval:3e4}),{data:j}=K({queryKey:[`printers`],queryFn:Z.getPrinters});(0,y.useEffect)(()=>{E&&(i(E.spoolman_enabled===`true`),o(E.spoolman_url||``),c(E.spoolman_sync_mode||`auto`),u(E.spoolman_disable_weight_sync===`true`),f(E.spoolman_report_partial_usage!==`false`),m(E.auto_add_unknown_rfid!==`false`),v(!0))},[E]),(0,y.useEffect)(()=>{if(!(!_||!E)&&(E.spoolman_enabled===`true`!==r||(E.spoolman_url||``)!==a||(E.spoolman_sync_mode||`auto`)!==s||E.spoolman_disable_weight_sync===`true`!==l||E.spoolman_report_partial_usage!==`false`!==d||E.auto_add_unknown_rfid!==`false`!==p)){let e=setTimeout(()=>{M.mutate()},500);return()=>clearTimeout(e)}},[r,a,s,l,d,p,_]);let M=q({mutationFn:()=>Z.updateSpoolmanSettings({spoolman_enabled:r?`true`:`false`,spoolman_url:a,spoolman_sync_mode:s,spoolman_disable_weight_sync:l?`true`:`false`,spoolman_report_partial_usage:d?`true`:`false`,auto_add_unknown_rfid:p?`true`:`false`}),onSuccess:()=>{t.invalidateQueries({queryKey:[`spoolman-settings`]}),t.invalidateQueries({queryKey:[`spoolman-status`]}),t.invalidateQueries({queryKey:[`spool-assignments`]}),t.invalidateQueries({queryKey:[`settings`]}),t.invalidateQueries({queryKey:[`spoolman-inventory-filaments`]}),n(e(`settings.toast.settingsSaved`))},onError:()=>{n(e(`settings.toast.saveFailed`),`error`)}}),N=q({mutationFn:Z.connectSpoolman,onSuccess:()=>{A()},onError:()=>{n(e(`settings.toast.saveFailed`),`error`)}}),P=q({mutationFn:Z.syncAllPrintersAms,onSuccess:t=>{n(e(`settings.spoolmanAmsSyncSuccess`,{synced:t.synced_count,skipped:0}),`success`)},onError:()=>{n(e(`settings.toast.saveFailed`),`error`)}}),F=q({mutationFn:e=>Z.syncPrinterAms(e),onSuccess:t=>{n(e(`settings.spoolmanAmsSyncSuccess`,{synced:t.synced_count,skipped:0}),`success`)},onError:()=>{n(e(`settings.toast.saveFailed`),`error`)}}),I=()=>{h===`all`?P.mutate():F.mutate(h)},L=q({mutationFn:Z.syncWeightsFromAms,onSuccess:r=>{t.invalidateQueries({queryKey:[`spools`]}),t.invalidateQueries({queryKey:[`inventory-spools`]}),n(e(`settings.amsSyncSuccess`,{synced:r.synced,skipped:r.skipped}),`success`),C(!1)},onError:()=>{n(e(`settings.amsSyncError`),`error`),C(!1)}}),R=q({mutationFn:Z.syncSpoolmanAmsWeights,onSuccess:r=>{t.invalidateQueries({queryKey:[`spoolman-inventory-spools`]}),n(e(`settings.spoolmanAmsSyncSuccess`,{synced:r.synced,skipped:r.skipped}),`success`),T(!1)},onError:t=>{t instanceof sd&&t.status===503?n(e(`settings.spoolmanAmsSyncErrorUnreachable`),`error`):t instanceof sd&&t.status===400?n(e(`settings.spoolmanAmsSyncErrorNotConfigured`),`error`):n(e(`settings.spoolmanAmsSyncError`),`error`),T(!1)}}),z=P.isPending||F.isPending,B=h===`all`?P.data:F.data,V=h===`all`?P.isSuccess:F.isSuccess;return D?(0,G.jsxs)(zd,{id:`card-spoolman`,children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Gs,{className:`w-5 h-5 text-bambu-green`}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`settings.filamentTracking`)})]})}),(0,G.jsx)(Vd,{children:(0,G.jsx)(`div`,{className:`flex justify-center py-8`,children:(0,G.jsx)(Y,{className:`w-6 h-6 text-bambu-green animate-spin`})})})]}):(0,G.jsxs)(zd,{id:`card-spoolman`,children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Gs,{className:`w-5 h-5 text-bambu-green`}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`settings.filamentTracking`)})]}),M.isPending&&(0,G.jsx)(Y,{className:`w-4 h-4 text-bambu-green animate-spin`})]})}),(0,G.jsxs)(Vd,{className:`space-y-4`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`settings.filamentTrackingDesc`)}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,G.jsxs)(`button`,{type:`button`,onClick:()=>i(!1),className:`p-3 rounded-lg border-2 text-left transition-colors ${r?`border-bambu-dark-tertiary bg-bambu-dark hover:border-bambu-gray/50`:`border-bambu-green bg-bambu-green/10`}`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-1.5`,children:[(0,G.jsx)(Cl,{className:`w-4 h-4 ${r?`text-bambu-gray`:`text-bambu-green`}`}),(0,G.jsx)(`span`,{className:`text-sm font-medium ${r?`text-bambu-gray`:`text-white`}`,children:e(`settings.trackingModeBuiltIn`)})]}),(0,G.jsx)(`p`,{className:`text-xs ${r?`text-bambu-gray/60`:`text-bambu-gray`}`,children:e(`settings.trackingModeBuiltInDesc`)}),!r&&(0,G.jsxs)(`div`,{className:`flex items-center gap-1 mt-2`,children:[(0,G.jsx)(fs,{className:`w-3 h-3 text-bambu-green`}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-green`,children:e(`common.enabled`)})]})]}),(0,G.jsxs)(`button`,{type:`button`,onClick:()=>i(!0),className:`p-3 rounded-lg border-2 text-left transition-colors ${r?`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary bg-bambu-dark hover:border-bambu-gray/50`}`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-1.5`,children:[(0,G.jsx)(rc,{className:`w-4 h-4 ${r?`text-bambu-green`:`text-bambu-gray`}`}),(0,G.jsx)(`span`,{className:`text-sm font-medium ${r?`text-white`:`text-bambu-gray`}`,children:`Spoolman`})]}),(0,G.jsx)(`p`,{className:`text-xs ${r?`text-bambu-gray`:`text-bambu-gray/60`}`,children:e(`settings.trackingModeSpoolmanDesc`)}),r&&(0,G.jsxs)(`div`,{className:`flex items-center gap-1 mt-2`,children:[(0,G.jsx)(fs,{className:`w-3 h-3 text-bambu-green`}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-green`,children:e(`common.enabled`)})]})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between pt-2 border-t border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`pr-4`,children:[(0,G.jsx)(`p`,{className:`text-white`,children:e(`settings.autoAddUnknownRfid`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`settings.autoAddUnknownRfidDesc`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:p,onChange:e=>m(e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),!r&&(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsx)(`div`,{className:`p-3 bg-bambu-green/5 border border-bambu-green/20 rounded-lg`,children:(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsx)(Wc,{className:`w-4 h-4 text-bambu-green flex-shrink-0 mt-0.5`}),(0,G.jsx)(`div`,{className:`text-xs text-bambu-gray`,children:(0,G.jsxs)(`ul`,{className:`list-disc list-inside space-y-0.5`,children:[(0,G.jsx)(`li`,{children:e(`settings.builtInFeatureRfid`)}),(0,G.jsx)(`li`,{children:e(`settings.builtInFeatureUsage`)}),(0,G.jsx)(`li`,{children:e(`settings.builtInFeatureCatalog`)}),(0,G.jsx)(`li`,{children:e(`settings.builtInFeatureThirdParty`)})]})})]})}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:()=>C(!0),disabled:L.isPending,children:[L.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 mr-2 animate-spin`}):(0,G.jsx)(Hl,{className:`w-4 h-4 mr-2`}),e(`settings.amsSyncButton`)]})]}),r&&(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsx)(`div`,{className:`p-3 bg-blue-50 dark:bg-blue-500/10 border border-blue-300 dark:border-blue-500/30 rounded-lg`,children:(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsx)(Wc,{className:`w-4 h-4 text-blue-600 dark:text-blue-400 flex-shrink-0 mt-0.5`}),(0,G.jsxs)(`div`,{className:`text-xs text-blue-700 dark:text-blue-300`,children:[(0,G.jsx)(`p`,{className:`font-medium mb-1`,children:e(`settings.howSyncWorks`)}),(0,G.jsxs)(`ul`,{className:`list-disc list-inside space-y-0.5 text-blue-700/90 dark:text-blue-300/80`,children:[(0,G.jsx)(`li`,{children:e(`settings.syncInfoRfidOnly`)}),(0,G.jsx)(`li`,{children:e(`settings.syncInfoAutoCreate`)}),(0,G.jsx)(`li`,{children:e(`settings.syncInfoThirdPartySkipped`)})]}),(0,G.jsx)(`p`,{className:`font-medium mt-2 mb-1`,children:e(`settings.linkingExistingSpools`)}),(0,G.jsx)(`p`,{className:`text-blue-700/90 dark:text-blue-300/80`,children:e(`settings.linkingExistingSpoolsDesc`)})]})]})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:e(`settings.spoolmanUrl`)}),(0,G.jsx)(`input`,{type:`text`,placeholder:`http://192.168.1.100:7912`,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 placeholder-bambu-gray/50 focus:border-bambu-green focus:outline-none`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`settings.spoolmanUrlHint`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:e(`settings.syncMode`)}),(0,G.jsxs)(`select`,{value:s,onChange:e=>c(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,G.jsx)(`option`,{value:`auto`,children:e(`settings.syncModeAuto`)}),(0,G.jsx)(`option`,{value:`manual`,children:e(`settings.syncModeManual`)})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(s===`auto`?`settings.syncModeAutoDesc`:`settings.syncModeManualDesc`)})]}),s===`auto`&&(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:e(`spoolman.disableWeightSync`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`spoolman.disableWeightSyncDesc`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:l,onChange:e=>u(e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),l&&(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:e(`spoolman.reportPartialUsage`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`spoolman.reportPartialUsageDesc`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:d,onChange:e=>f(e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,G.jsxs)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[e(`settings.status`),`:`]}),k?(0,G.jsx)(Y,{className:`w-4 h-4 text-bambu-gray animate-spin`}):O?.connected?(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-sm text-green-500`,children:[(0,G.jsx)(fs,{className:`w-4 h-4`}),e(`settings.spoolmanConnected`)]}):(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-sm text-red-500`,children:[(0,G.jsx)(nd,{className:`w-4 h-4`}),e(`settings.spoolmanDisconnected`)]})]}),(0,G.jsx)(`div`,{className:`flex gap-2`,children:!O?.connected&&(0,G.jsxs)(Q,{size:`sm`,onClick:()=>N.mutate(),disabled:N.isPending||!a,children:[N.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Xc,{className:`w-4 h-4`}),e(`settings.connect`)]})})]}),N.isError&&(0,G.jsx)(`div`,{className:`mb-3 p-2 bg-red-100 dark:bg-red-500/20 border border-red-300 dark:border-red-500/50 rounded text-sm text-red-700 dark:text-red-400`,children:N.error.message}),O?.connected&&(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:e(`settings.syncAmsData`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:e(`settings.syncAmsDataDesc`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`div`,{className:`relative flex-1`,children:[(0,G.jsxs)(`select`,{value:h,onChange:e=>g(e.target.value===`all`?`all`:Number(e.target.value)),className:`w-full px-3 py-2 pr-8 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none appearance-none cursor-pointer`,children:[(0,G.jsx)(`option`,{value:`all`,children:e(`settings.allPrinters`)}),j?.map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),(0,G.jsx)(ps,{className:`absolute right-2 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:I,disabled:z,children:[z?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Hl,{className:`w-4 h-4`}),e(`spoolman.sync`)]})]})]}),O?.connected&&(0,G.jsx)(`div`,{className:`mt-4 pt-4 border-t border-bambu-dark-tertiary`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:e(`settings.spoolmanAmsSyncButton`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:e(`settings.spoolmanAmsSyncMessage`)})]}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:()=>T(!0),disabled:R.isPending,children:[R.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Hl,{className:`w-4 h-4`}),R.isPending?e(`settings.spoolmanAmsSyncing`):e(`settings.spoolmanAmsSyncButton`)]})]})}),V&&B&&(0,G.jsxs)(`div`,{className:`mt-3 space-y-2`,children:[(0,G.jsx)(`div`,{className:`p-2 rounded text-sm ${B.success?`bg-green-100 dark:bg-green-500/20 border border-green-300 dark:border-green-500/50 text-green-700 dark:text-green-400`:`bg-yellow-100 dark:bg-yellow-500/20 border border-yellow-300 dark:border-yellow-500/50 text-yellow-700 dark:text-yellow-400`}`,children:B.success?`Synced ${B.synced_count} spool${B.synced_count===1?``:`s`} successfully`:`Synced ${B.synced_count} spool${B.synced_count===1?``:`s`} with ${B.errors.length} error${B.errors.length===1?``:`s`}`}),B.skipped_count>0&&(0,G.jsxs)(`div`,{className:`p-2 bg-amber-50 dark:bg-amber-500/10 border border-amber-300 dark:border-amber-500/30 rounded text-sm`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between text-amber-700 dark:text-amber-400 mb-1`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,G.jsx)(Lu,{className:`w-3.5 h-3.5`}),(0,G.jsxs)(`span`,{className:`font-medium`,children:[B.skipped_count,` spool`,B.skipped_count===1?``:`s`,` skipped`]})]}),B.skipped_count>5&&(0,G.jsx)(`button`,{onClick:()=>x(!b),className:`text-xs text-amber-700 dark:text-amber-400 hover:text-amber-800 dark:hover:text-amber-300 underline`,children:b?`Show less`:`Show all`})]}),(0,G.jsxs)(`ul`,{className:`text-xs text-amber-700/90 dark:text-amber-300/80 space-y-0.5`,children:[(b?B.skipped:B.skipped.slice(0,5)).map((e,t)=>(0,G.jsxs)(`li`,{className:`flex items-center gap-2`,children:[e.color&&(0,G.jsx)(`span`,{className:`w-3 h-3 rounded-full border border-black/20`,style:{backgroundColor:`#${e.color}`}}),(0,G.jsx)(`span`,{children:e.location}),(0,G.jsxs)(`span`,{className:`text-amber-700/70 dark:text-amber-300/60`,children:[`- `,e.reason]})]},t)),!b&&B.skipped_count>5&&(0,G.jsxs)(`li`,{className:`text-amber-700/70 dark:text-amber-300/60 italic`,children:[`...and `,B.skipped_count-5,` more`]})]})]}),B.errors.length>0&&(0,G.jsxs)(`div`,{className:`p-2 bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30 rounded text-sm`,children:[(0,G.jsx)(`div`,{className:`text-red-700 dark:text-red-400 font-medium mb-1`,children:`Errors:`}),(0,G.jsx)(`ul`,{className:`text-xs text-red-700/90 dark:text-red-300/80 space-y-0.5`,children:B.errors.map((e,t)=>(0,G.jsx)(`li`,{children:e},t))})]})]})]})]})]}),S&&(0,G.jsx)(of,{title:e(`settings.amsSyncTitle`),message:e(`settings.amsSyncMessage`),confirmText:e(`settings.amsSyncButton`),variant:`warning`,isLoading:L.isPending,loadingText:e(`settings.amsSyncing`),onConfirm:()=>L.mutate(),onCancel:()=>C(!1)}),w&&(0,G.jsx)(of,{title:e(`settings.spoolmanAmsSyncTitle`),message:e(`settings.spoolmanAmsSyncMessage`),confirmText:e(`settings.spoolmanAmsSyncButton`),variant:`warning`,isLoading:R.isPending,loadingText:e(`settings.spoolmanAmsSyncing`),onConfirm:()=>R.mutate(),onCancel:()=>T(!1)})]})}function uGe(){let{t:e}=U(),{showToast:t}=qd(),[n,r]=(0,y.useState)([]),[i,a]=(0,y.useState)(!0),[o,s]=(0,y.useState)(``),c=(0,y.useRef)(null),[l,u]=(0,y.useState)(!1),[d,f]=(0,y.useState)(null),[p,m]=(0,y.useState)(``),[h,g]=(0,y.useState)(``),[_,v]=(0,y.useState)(!1),[b,x]=(0,y.useState)(new Set),[S,C]=(0,y.useState)(!1),[w,T]=(0,y.useState)(null),[E,D]=(0,y.useState)(!1),O=(0,y.useCallback)(async()=>{try{r(await Z.getSpoolCatalog())}catch(n){console.error(`SpoolCatalogSettings.loadCatalog failed:`,n),t(e(`settings.catalog.loadFailed`),`error`)}finally{a(!1)}},[t,e]);(0,y.useEffect)(()=>{O()},[O]);let k=n.filter(e=>e.name.toLowerCase().includes(o.toLowerCase())),A=async()=>{if(!p.trim()||!h){t(e(`settings.catalog.nameWeightRequired`),`error`);return}v(!0);try{let n=await Z.addCatalogEntry({name:p.trim(),weight:parseInt(h)});r(e=>[...e,n].sort((e,t)=>e.name.localeCompare(t.name))),u(!1),m(``),g(``),t(e(`settings.catalog.entryAdded`),`success`)}catch(n){console.error(`SpoolCatalogSettings.handleAdd failed:`,n),t(e(`settings.catalog.addFailed`),`error`)}finally{v(!1)}},j=e=>{f(e.id),m(e.name),g(e.weight.toString())},M=()=>{f(null),m(``),g(``)},N=async n=>{if(!p.trim()||!h){t(e(`settings.catalog.nameWeightRequired`),`error`);return}v(!0);try{let i=await Z.updateCatalogEntry(n,{name:p.trim(),weight:parseInt(h)});r(e=>e.map(e=>e.id===n?i:e).sort((e,t)=>e.name.localeCompare(t.name))),f(null),m(``),g(``),t(e(`settings.catalog.entryUpdated`),`success`)}catch(n){console.error(`SpoolCatalogSettings.handleUpdate failed:`,n),t(e(`settings.catalog.updateFailed`),`error`)}finally{v(!1)}},P=async()=>{if(w)try{await Z.deleteCatalogEntry(w.id),r(e=>e.filter(e=>e.id!==w.id)),t(e(`settings.catalog.entryDeleted`),`success`)}catch(n){console.error(`SpoolCatalogSettings.handleDelete failed:`,n),t(e(`settings.catalog.deleteFailed`),`error`)}finally{T(null)}},F=async()=>{D(!1),a(!0);try{await Z.resetSpoolCatalog(),await O(),t(e(`settings.catalog.resetSuccess`),`success`)}catch(n){console.error(`SpoolCatalogSettings.handleReset failed:`,n),t(e(`settings.catalog.resetFailed`),`error`),a(!1)}},I=e=>{x(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})};return(0,G.jsxs)(zd,{id:`card-spool-catalog`,children:[(0,G.jsxs)(Bd,{children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,G.jsx)(Gs,{className:`w-5 h-5 text-bambu-gray`}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`settings.catalog.spoolCatalog`)}),(0,G.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[`(`,n.length,`)`]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,G.jsxs)(`button`,{onClick:()=>{let r=n.map(({name:e,weight:t})=>({name:e,weight:t})),i=new Blob([JSON.stringify(r,null,2)],{type:`application/json`}),a=URL.createObjectURL(i),o=document.createElement(`a`);o.href=a,o.download=`spool-catalog.json`,document.body.appendChild(o),o.click(),document.body.removeChild(o),URL.revokeObjectURL(a),t(e(`settings.catalog.exported`,{count:n.length}),`success`)},className:`px-3 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray hover:text-white transition-colors flex items-center gap-1.5`,title:e(`settings.catalog.exportTooltip`),children:[(0,G.jsx)(Xs,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.export`)})]}),(0,G.jsxs)(`button`,{onClick:()=>c.current?.click(),className:`px-3 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray hover:text-white transition-colors flex items-center gap-1.5`,title:e(`settings.catalog.importTooltip`),children:[(0,G.jsx)(Vu,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.import`)})]}),(0,G.jsx)(`input`,{ref:c,type:`file`,accept:`.json`,className:`hidden`,onChange:async i=>{let a=i.target.files?.[0];if(a){try{let i=await a.text(),o=JSON.parse(i);if(!Array.isArray(o))throw Error(`Invalid format`);let s=0,c=0;for(let e of o){if(!e.name||typeof e.weight!=`number`){c++;continue}if(n.some(t=>t.name.toLowerCase()===e.name.toLowerCase())){c++;continue}try{let t=await Z.addCatalogEntry({name:e.name,weight:e.weight});r(e=>[...e,t].sort((e,t)=>e.name.localeCompare(t.name))),s++}catch(e){console.error(`SpoolCatalogSettings import item failed:`,e),c++}}t(e(`settings.catalog.imported`,{added:s,skipped:c}),`success`)}catch(n){console.error(`SpoolCatalogSettings.handleImport failed:`,n),t(e(`settings.catalog.importFailed`),`error`)}c.current&&(c.current.value=``)}}}),(0,G.jsxs)(`button`,{onClick:()=>D(!0),className:`px-3 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray hover:text-white transition-colors flex items-center gap-1.5`,title:e(`settings.catalog.resetTooltip`),children:[(0,G.jsx)(Wl,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.reset`)})]}),(0,G.jsxs)(`button`,{onClick:()=>u(!0),className:`px-3 py-1.5 text-sm bg-bambu-green text-white rounded-lg hover:bg-bambu-green/80 transition-colors flex items-center gap-1.5`,children:[(0,G.jsx)(Fl,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.add`)})]})]}),b.size>0&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mt-2 px-3 py-2 bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30 rounded-lg`,children:[(0,G.jsx)(`span`,{className:`text-sm text-red-700 dark:text-red-400`,children:e(`settings.catalog.selectedCount`,{count:b.size})}),(0,G.jsxs)(`button`,{onClick:()=>C(!0),className:`ml-auto px-3 py-1.5 text-sm bg-red-500 text-white rounded-lg hover:bg-red-600 transition-colors flex items-center gap-1.5`,children:[(0,G.jsx)(Pu,{className:`w-4 h-4`}),e(`settings.catalog.deleteSelected`)]}),(0,G.jsx)(`button`,{onClick:()=>x(new Set),className:`px-3 py-1.5 text-sm text-bambu-gray hover:text-white transition-colors`,children:e(`common.cancel`)})]})]}),(0,G.jsxs)(Vd,{className:`space-y-4`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`settings.catalog.spoolCatalogDescription`)}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(Ql,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,G.jsx)(`input`,{type:`text`,className:`w-full pl-10 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`,placeholder:e(`settings.catalog.searchCatalog`),value:o,onChange:e=>s(e.target.value)})]}),l&&(0,G.jsxs)(`div`,{className:`p-4 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,G.jsx)(`h3`,{className:`text-sm font-medium text-white mb-3`,children:e(`settings.catalog.addNewEntry`)}),(0,G.jsxs)(`div`,{className:`flex gap-2 items-center`,children:[(0,G.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,G.jsx)(`input`,{type:`text`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`,placeholder:e(`settings.catalog.namePlaceholder`),value:p,onChange:e=>m(e.target.value)})}),(0,G.jsx)(`input`,{type:`number`,className:`w-20 px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white text-center focus:border-bambu-green focus:outline-none`,placeholder:`g`,value:h,onChange:e=>g(e.target.value)}),(0,G.jsx)(`span`,{className:`text-bambu-gray shrink-0`,children:`g`}),(0,G.jsxs)(`button`,{onClick:A,disabled:_,className:`px-3 py-2 bg-bambu-green text-white rounded-lg hover:bg-bambu-green/80 flex items-center gap-1 shrink-0`,children:[_?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(fs,{className:`w-4 h-4`}),e(`common.add`)]}),(0,G.jsx)(`button`,{onClick:()=>{u(!1),m(``),g(``)},className:`p-2 rounded-lg text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary`,children:(0,G.jsx)(nd,{className:`w-4 h-4`})})]})]}),i?(0,G.jsxs)(`div`,{className:`flex items-center justify-center py-8 text-bambu-gray`,children:[(0,G.jsx)(Y,{className:`w-5 h-5 animate-spin mr-2`}),e(`common.loading`)]}):(0,G.jsx)(`div`,{className:`max-h-[600px] overflow-y-auto border border-bambu-dark-tertiary rounded-lg`,children:(0,G.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,G.jsx)(`thead`,{className:`bg-bambu-dark sticky top-0`,children:(0,G.jsxs)(`tr`,{children:[(0,G.jsx)(`th`,{className:`px-2 py-2 w-10`,children:(0,G.jsx)(`input`,{type:`checkbox`,checked:k.length>0&&b.size===k.length,onChange:()=>{b.size===k.length?x(new Set):x(new Set(k.map(e=>e.id)))},className:`w-4 h-4 accent-bambu-green cursor-pointer`})}),(0,G.jsx)(`th`,{className:`px-4 py-2 text-left text-bambu-gray font-medium`,children:e(`common.name`)}),(0,G.jsx)(`th`,{className:`px-4 py-2 text-right text-bambu-gray font-medium w-24`,children:e(`settings.catalog.weight`)}),(0,G.jsx)(`th`,{className:`px-4 py-2 text-center text-bambu-gray font-medium w-20`,children:e(`settings.catalog.type`)}),(0,G.jsx)(`th`,{className:`px-4 py-2 w-24`})]})}),(0,G.jsx)(`tbody`,{children:k.length===0?(0,G.jsx)(`tr`,{children:(0,G.jsx)(`td`,{colSpan:5,className:`px-4 py-8 text-center text-bambu-gray`,children:e(o?`settings.catalog.noMatch`:`settings.catalog.empty`)})}):k.map(t=>(0,G.jsx)(`tr`,{className:`border-t border-bambu-dark-tertiary hover:bg-bambu-dark ${b.has(t.id)?`bg-bambu-dark`:``}`,children:d===t.id?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`td`,{className:`px-2 py-2`,children:(0,G.jsx)(`input`,{type:`checkbox`,checked:b.has(t.id),onChange:()=>I(t.id),className:`w-4 h-4 accent-bambu-green cursor-pointer`})}),(0,G.jsx)(`td`,{className:`px-4 py-2`,children:(0,G.jsx)(`input`,{type:`text`,className:`w-full px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white focus:border-bambu-green focus:outline-none`,value:p,onChange:e=>m(e.target.value)})}),(0,G.jsx)(`td`,{className:`px-4 py-2`,children:(0,G.jsx)(`input`,{type:`number`,className:`w-full px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-right focus:border-bambu-green focus:outline-none`,value:h,onChange:e=>g(e.target.value)})}),(0,G.jsx)(`td`,{className:`px-4 py-2 text-center`,children:(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:`-`})}),(0,G.jsx)(`td`,{className:`px-4 py-2`,children:(0,G.jsxs)(`div`,{className:`flex justify-end gap-1`,children:[(0,G.jsx)(`button`,{onClick:()=>N(t.id),disabled:_,className:`p-1.5 rounded hover:bg-green-500/20 text-green-500`,children:_?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(fs,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:M,className:`p-1.5 rounded hover:bg-bambu-dark-tertiary text-bambu-gray`,children:(0,G.jsx)(nd,{className:`w-4 h-4`})})]})})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`td`,{className:`px-2 py-2`,children:(0,G.jsx)(`input`,{type:`checkbox`,checked:b.has(t.id),onChange:()=>I(t.id),className:`w-4 h-4 accent-bambu-green cursor-pointer`})}),(0,G.jsx)(`td`,{className:`px-4 py-2 text-white`,children:t.name}),(0,G.jsxs)(`td`,{className:`px-4 py-2 text-right font-mono text-white`,children:[t.weight,`g`]}),(0,G.jsx)(`td`,{className:`px-4 py-2 text-center`,children:t.is_default?(0,G.jsx)(`span`,{className:`text-xs px-2 py-0.5 rounded bg-bambu-dark-tertiary text-bambu-gray`,children:e(`settings.catalog.default`)}):(0,G.jsx)(`span`,{className:`text-xs px-2 py-0.5 rounded bg-bambu-green/20 text-bambu-green`,children:e(`settings.catalog.custom`)})}),(0,G.jsx)(`td`,{className:`px-4 py-2`,children:(0,G.jsxs)(`div`,{className:`flex justify-end gap-1`,children:[(0,G.jsx)(`button`,{onClick:()=>j(t),className:`p-1.5 rounded hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white`,children:(0,G.jsx)(Al,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:()=>T(t),className:`p-1.5 rounded bg-red-500/10 hover:bg-red-500/20 text-red-500`,children:(0,G.jsx)(Pu,{className:`w-4 h-4`})})]})})]})},t.id))})]})})]}),w&&(0,G.jsx)(of,{title:e(`settings.catalog.deleteEntry`),message:e(`settings.catalog.deleteConfirm`,{name:w.name}),confirmText:e(`common.delete`),variant:`danger`,onConfirm:P,onCancel:()=>T(null)}),S&&(0,G.jsx)(of,{title:e(`settings.catalog.deleteSelected`),message:e(`settings.catalog.bulkDeleteConfirm`,{count:b.size}),confirmText:e(`common.delete`),variant:`danger`,onConfirm:async()=>{if(C(!1),b.size!==0)try{let n=await Z.bulkDeleteCatalogEntries([...b]);r(e=>e.filter(e=>!b.has(e.id))),x(new Set),t(e(`settings.catalog.bulkDeleted`,{count:n.deleted}),`success`)}catch(n){console.error(`SpoolCatalogSettings.handleBulkDelete failed:`,n),t(e(`settings.catalog.bulkDeleteFailed`),`error`)}},onCancel:()=>C(!1)}),E&&(0,G.jsx)(of,{title:e(`settings.catalog.resetCatalog`),message:e(`settings.catalog.resetConfirm`),confirmText:e(`common.reset`),variant:`danger`,onConfirm:F,onCancel:()=>D(!1)})]})}function w8({rgba:e,extraColors:t,effectType:n,subtype:r,className:i=`w-5 h-5`,shape:a=`circle`,style:o,title:s,effectSize:c}){let l=(0,y.useMemo)(()=>yH(t),[t]),u=(0,y.useMemo)(()=>bH({effectSize:c,rgba:e,extraColors:t,effectType:n,subtype:r}),[c,e,t,n,r]),d=u.backgroundImage,f=u.backgroundSize,p=a===`circle`||a===`pill`?`rounded-full`:`rounded`,m=(()=>{if(!e)return;let t=e.replace(/^#/,``);return t.length>=8&&t.substring(6,8).toLowerCase()!==`ff`?`#${t.substring(0,8)}`:`#${t.substring(0,6)}`})(),h=s??(l.length>0?l.join(`, `):m);return(0,G.jsx)(`span`,{"data-testid":`filament-swatch`,className:`${i} ${p} border border-black/20 inline-block flex-shrink-0`,style:{backgroundImage:d,backgroundSize:f,...o},title:h})}function dGe(){let{t:e}=U(),{showToast:t}=qd(),[n,r]=(0,y.useState)([]),[i,a]=(0,y.useState)(!0),[o,s]=(0,y.useState)(``),[c,l]=(0,y.useState)(``),u=(0,y.useRef)(null),[d,f]=(0,y.useState)(!1),[p,m]=(0,y.useState)(null),[h,g]=(0,y.useState)(``),[_,v]=(0,y.useState)(``),[b,x]=(0,y.useState)(`#FFFFFF`),[S,C]=(0,y.useState)(``),[w,T]=(0,y.useState)(``),[E,D]=(0,y.useState)(``),[O,k]=(0,y.useState)(!1),[A,j]=(0,y.useState)(new Set),[M,N]=(0,y.useState)(!1),[P,F]=(0,y.useState)(!1),[I,L]=(0,y.useState)(null),[R,z]=(0,y.useState)(null),[B,V]=(0,y.useState)(!1),ee=(0,y.useCallback)(async()=>{try{r(await Z.getColorCatalog())}catch{t(e(`settings.colorCatalog.loadFailed`),`error`)}finally{a(!1)}},[t,e]);(0,y.useEffect)(()=>{ee()},[ee]);let te=[...new Set(n.map(e=>e.manufacturer))].sort(),ne=n.filter(e=>{let t=o===``||e.manufacturer.toLowerCase().includes(o.toLowerCase())||e.color_name.toLowerCase().includes(o.toLowerCase())||(e.material?.toLowerCase().includes(o.toLowerCase())??!1),n=c===``||e.manufacturer===c;return t&&n}),re=()=>{g(``),v(``),x(`#FFFFFF`),C(``),T(``),D(``)},ie=async()=>{if(!h.trim()||!_.trim()||!b){t(e(`settings.colorCatalog.fieldsRequired`),`error`);return}k(!0);try{let n=await Z.addColorEntry({manufacturer:h.trim(),color_name:_.trim(),hex_color:b,material:S.trim()||null,extra_colors:w.trim()||null,effect_type:E.trim()||null});r(e=>[...e,n].sort((e,t)=>e.manufacturer.localeCompare(t.manufacturer)||(e.material||``).localeCompare(t.material||``)||e.color_name.localeCompare(t.color_name))),f(!1),re(),t(e(`settings.colorCatalog.colorAdded`),`success`)}catch{t(e(`settings.colorCatalog.addFailed`),`error`)}finally{k(!1)}},ae=e=>{m(e.id),g(e.manufacturer),v(e.color_name),x(e.hex_color),C(e.material||``),T(e.extra_colors||``),D(e.effect_type||``)},oe=()=>{m(null),re()},se=async n=>{if(!h.trim()||!_.trim()||!b){t(e(`settings.colorCatalog.fieldsRequired`),`error`);return}k(!0);try{let i=await Z.updateColorEntry(n,{manufacturer:h.trim(),color_name:_.trim(),hex_color:b,material:S.trim()||null,extra_colors:w.trim()||null,effect_type:E.trim()||null});r(e=>e.map(e=>e.id===n?i:e).sort((e,t)=>e.manufacturer.localeCompare(t.manufacturer)||(e.material||``).localeCompare(t.material||``)||e.color_name.localeCompare(t.color_name))),m(null),re(),t(e(`settings.colorCatalog.colorUpdated`),`success`)}catch{t(e(`settings.colorCatalog.updateFailed`),`error`)}finally{k(!1)}},H=async()=>{if(R)try{await Z.deleteColorEntry(R.id),r(e=>e.filter(e=>e.id!==R.id)),t(e(`settings.colorCatalog.colorDeleted`),`success`)}catch{t(e(`settings.colorCatalog.deleteFailed`),`error`)}finally{z(null)}},ce=async()=>{V(!1),a(!0);try{await Z.resetColorCatalog(),await ee(),t(e(`settings.colorCatalog.resetSuccess`),`success`)}catch{t(e(`settings.colorCatalog.resetFailed`),`error`),a(!1)}},le=async()=>{F(!0),L(null);try{let n={},r=ud();r&&(n.Authorization=`Bearer ${r}`);let i=await fetch(`/api/v1/inventory/colors/sync`,{method:`POST`,headers:n});if(!i.ok)throw Error(`Failed to start sync`);let a=i.body?.getReader();if(!a)throw Error(`No response body`);let o=new TextDecoder,s=``;for(;;){let{done:n,value:r}=await a.read();if(n)break;s+=o.decode(r,{stream:!0});let i=s.split(` -`);s=i.pop()||``;for(let n of i)if(n.startsWith(`data: `))try{let r=JSON.parse(n.slice(6));r.type===`progress`?L({fetched:r.total_fetched,total:r.total_available}):r.type===`complete`?r.added===0?t(e(`settings.colorCatalog.syncUpToDate`,{count:r.total_fetched}),`success`):t(e(`settings.colorCatalog.syncComplete`,{added:r.added,skipped:r.skipped}),`success`):r.type===`error`&&t(`${e(`settings.colorCatalog.syncError`)}: ${r.error}`,`error`)}catch{}}await ee()}catch{t(e(`settings.colorCatalog.syncFailed`),`error`)}finally{F(!1),L(null)}},ue=e=>{j(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})};return(0,G.jsxs)(zd,{id:`card-color-catalog`,children:[(0,G.jsxs)(Bd,{children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,G.jsx)(wl,{className:`w-5 h-5 text-bambu-gray`}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`settings.colorCatalog.title`)}),(0,G.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[`(`,n.length,`)`]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,G.jsxs)(`button`,{onClick:()=>{let r=n.map(({manufacturer:e,color_name:t,hex_color:n,material:r,extra_colors:i,effect_type:a})=>({manufacturer:e,color_name:t,hex_color:n,material:r,extra_colors:i,effect_type:a})),i=new Blob([JSON.stringify(r,null,2)],{type:`application/json`}),a=URL.createObjectURL(i),o=document.createElement(`a`);o.href=a,o.download=`color-catalog.json`,document.body.appendChild(o),o.click(),document.body.removeChild(o),URL.revokeObjectURL(a),t(e(`settings.colorCatalog.exported`,{count:n.length}),`success`)},className:`px-3 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray hover:text-white transition-colors flex items-center gap-1.5`,children:[(0,G.jsx)(Xs,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.export`)})]}),(0,G.jsxs)(`button`,{onClick:()=>u.current?.click(),className:`px-3 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray hover:text-white transition-colors flex items-center gap-1.5`,children:[(0,G.jsx)(Vu,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.import`)})]}),(0,G.jsx)(`input`,{ref:u,type:`file`,accept:`.json`,className:`hidden`,onChange:async i=>{let a=i.target.files?.[0];if(a){try{let i=await a.text(),o=JSON.parse(i);if(!Array.isArray(o))throw Error(`Invalid format`);let s=0,c=0;for(let e of o){if(!e.manufacturer||!e.color_name||!e.hex_color){c++;continue}if(n.some(t=>t.manufacturer.toLowerCase()===e.manufacturer.toLowerCase()&&t.color_name.toLowerCase()===e.color_name.toLowerCase()&&(t.material||``).toLowerCase()===(e.material||``).toLowerCase())){c++;continue}try{let t=await Z.addColorEntry({manufacturer:e.manufacturer,color_name:e.color_name,hex_color:e.hex_color,material:e.material||null,extra_colors:e.extra_colors||null,effect_type:e.effect_type||null});r(e=>[...e,t].sort((e,t)=>e.manufacturer.localeCompare(t.manufacturer)||(e.material||``).localeCompare(t.material||``)||e.color_name.localeCompare(t.color_name))),s++}catch{c++}}t(e(`settings.colorCatalog.imported`,{added:s,skipped:c}),`success`)}catch{t(e(`settings.colorCatalog.importFailed`),`error`)}u.current&&(u.current.value=``)}}}),(0,G.jsxs)(`button`,{onClick:le,disabled:P,className:`px-3 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray hover:text-white transition-colors flex items-center gap-1.5`,title:e(`settings.colorCatalog.syncTooltip`),children:[P?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Ps,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:P?I?`${Math.min(I.fetched,I.total)} / ${I.total}`:e(`settings.colorCatalog.starting`):e(`settings.colorCatalog.sync`)})]}),(0,G.jsxs)(`button`,{onClick:()=>V(!0),className:`px-3 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray hover:text-white transition-colors flex items-center gap-1.5`,children:[(0,G.jsx)(Wl,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.reset`)})]}),(0,G.jsxs)(`button`,{onClick:()=>f(!0),className:`px-3 py-1.5 text-sm bg-bambu-green text-white rounded-lg hover:bg-bambu-green/80 transition-colors flex items-center gap-1.5`,children:[(0,G.jsx)(Fl,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.add`)})]})]}),A.size>0&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mt-2 px-3 py-2 bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30 rounded-lg`,children:[(0,G.jsx)(`span`,{className:`text-sm text-red-700 dark:text-red-400`,children:e(`settings.colorCatalog.selectedCount`,{count:A.size})}),(0,G.jsxs)(`button`,{onClick:()=>N(!0),className:`ml-auto px-3 py-1.5 text-sm bg-red-500 text-white rounded-lg hover:bg-red-600 transition-colors flex items-center gap-1.5`,children:[(0,G.jsx)(Pu,{className:`w-4 h-4`}),e(`settings.colorCatalog.deleteSelected`)]}),(0,G.jsx)(`button`,{onClick:()=>j(new Set),className:`px-3 py-1.5 text-sm text-bambu-gray hover:text-white transition-colors`,children:e(`common.cancel`)})]})]}),(0,G.jsxs)(Vd,{className:`space-y-4`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`settings.colorCatalog.description`)}),(0,G.jsxs)(`div`,{className:`flex gap-2 flex-wrap`,children:[(0,G.jsxs)(`div`,{className:`relative flex-1 min-w-[200px]`,children:[(0,G.jsx)(Ql,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,G.jsx)(`input`,{type:`text`,className:`w-full pl-10 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`,placeholder:e(`settings.colorCatalog.searchColors`),value:o,onChange:e=>s(e.target.value)})]}),(0,G.jsxs)(`select`,{className:`px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,value:c,onChange:e=>l(e.target.value),children:[(0,G.jsx)(`option`,{value:``,children:e(`settings.colorCatalog.allManufacturers`)}),te.map(e=>(0,G.jsx)(`option`,{value:e,children:e},e))]})]}),d&&(0,G.jsxs)(`div`,{className:`p-4 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,G.jsx)(`h3`,{className:`text-sm font-medium text-white mb-3`,children:e(`settings.colorCatalog.addNewColor`)}),(0,G.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-5 gap-2 items-end`,children:[(0,G.jsx)(`input`,{type:`text`,className:`px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`,placeholder:e(`settings.colorCatalog.manufacturer`),value:h,onChange:e=>g(e.target.value)}),(0,G.jsx)(`input`,{type:`text`,className:`px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`,placeholder:e(`settings.colorCatalog.colorName`),value:_,onChange:e=>v(e.target.value)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`input`,{type:`color`,className:`w-20 h-10 rounded cursor-pointer border border-bambu-dark-tertiary`,value:b,onChange:e=>x(e.target.value)}),(0,G.jsx)(`input`,{type:`text`,className:`w-32 px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`,placeholder:`#FFFFFF`,value:b,onChange:e=>x(e.target.value)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(`input`,{type:`text`,className:`flex-1 max-w-lg min-w-[200px] px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`,placeholder:e(`settings.colorCatalog.materialOptional`),value:S,onChange:e=>C(e.target.value)}),(0,G.jsxs)(`button`,{onClick:ie,disabled:O,className:`w-24 px-3 py-2 bg-bambu-green text-white rounded-lg hover:bg-bambu-green/80 flex items-center justify-center gap-3`,children:[O?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(fs,{className:`w-4 h-4`}),e(`common.add`)]}),(0,G.jsx)(`button`,{onClick:()=>{f(!1),re()},className:`p-2 ml-2 rounded-lg text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary`,children:(0,G.jsx)(nd,{className:`w-4 h-4`})})]})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-2 mt-2`,children:[(0,G.jsx)(`input`,{type:`text`,className:`px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white text-sm font-mono placeholder-bambu-gray focus:border-bambu-green focus:outline-none`,placeholder:e(`inventory.extraColorsPlaceholder`),value:w,onChange:e=>T(e.target.value)}),(0,G.jsx)(`select`,{className:`px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,value:E,onChange:e=>D(e.target.value),children:_H.map(t=>(0,G.jsx)(`option`,{value:t.value,children:e(t.labelKey)},t.value||`none`))})]})]}),(o||c)&&(0,G.jsx)(`div`,{className:`text-xs text-bambu-gray`,children:e(`settings.colorCatalog.showing`,{filtered:ne.length,total:n.length})}),i?(0,G.jsxs)(`div`,{className:`flex items-center justify-center py-8 text-bambu-gray`,children:[(0,G.jsx)(Y,{className:`w-5 h-5 animate-spin mr-2`}),e(`common.loading`)]}):(0,G.jsx)(`div`,{className:`max-h-[600px] overflow-auto border border-bambu-dark-tertiary rounded-lg`,children:(0,G.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,G.jsx)(`thead`,{className:`bg-bambu-dark sticky top-0`,children:(0,G.jsxs)(`tr`,{children:[(0,G.jsx)(`th`,{className:`px-2 py-2 w-10`,children:(0,G.jsx)(`input`,{type:`checkbox`,checked:ne.length>0&&A.size===ne.length,onChange:()=>{A.size===ne.length?j(new Set):j(new Set(ne.map(e=>e.id)))},className:`w-4 h-4 accent-bambu-green cursor-pointer`})}),(0,G.jsx)(`th`,{className:`px-3 py-2 text-left text-bambu-gray font-medium w-12`}),(0,G.jsx)(`th`,{className:`px-3 py-2 text-left text-bambu-gray font-medium`,children:e(`settings.colorCatalog.manufacturer`)}),(0,G.jsx)(`th`,{className:`px-3 py-2 text-left text-bambu-gray font-medium`,children:e(`inventory.material`)}),(0,G.jsx)(`th`,{className:`px-3 py-2 text-left text-bambu-gray font-medium`,children:e(`settings.colorCatalog.colorName`)}),(0,G.jsx)(`th`,{className:`px-3 py-2 text-left text-bambu-gray font-medium w-24`,children:e(`settings.colorCatalog.hex`)}),(0,G.jsx)(`th`,{className:`px-3 py-2 w-16`})]})}),(0,G.jsx)(`tbody`,{children:ne.length===0?(0,G.jsx)(`tr`,{children:(0,G.jsx)(`td`,{colSpan:7,className:`px-3 py-8 text-center text-bambu-gray`,children:e(o||c?`settings.colorCatalog.noMatch`:`settings.colorCatalog.empty`)})}):ne.map(t=>(0,G.jsxs)(y.Fragment,{children:[(0,G.jsx)(`tr`,{className:`border-t border-bambu-dark-tertiary hover:bg-bambu-dark ${A.has(t.id)?`bg-bambu-dark`:``}`,children:p===t.id?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`td`,{className:`px-2 py-2`,children:(0,G.jsx)(`input`,{type:`checkbox`,checked:A.has(t.id),onChange:()=>ue(t.id),className:`w-4 h-4 accent-bambu-green cursor-pointer`})}),(0,G.jsx)(`td`,{className:`px-3 py-2`,children:(0,G.jsx)(`input`,{type:`color`,className:`w-8 h-8 rounded cursor-pointer border border-bambu-dark-tertiary`,value:b,onChange:e=>x(e.target.value)})}),(0,G.jsx)(`td`,{className:`px-3 py-2`,children:(0,G.jsx)(`input`,{type:`text`,className:`w-full px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`,value:h,onChange:e=>g(e.target.value)})}),(0,G.jsx)(`td`,{className:`px-3 py-2`,children:(0,G.jsx)(`input`,{type:`text`,className:`w-full px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`,value:S,onChange:e=>C(e.target.value)})}),(0,G.jsx)(`td`,{className:`px-3 py-2`,children:(0,G.jsx)(`input`,{type:`text`,className:`w-full px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`,value:_,onChange:e=>v(e.target.value)})}),(0,G.jsx)(`td`,{className:`px-3 py-2`,children:(0,G.jsx)(`input`,{type:`text`,className:`w-full px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`,value:b,onChange:e=>x(e.target.value)})}),(0,G.jsx)(`td`,{className:`px-3 py-2`,children:(0,G.jsxs)(`div`,{className:`flex justify-end gap-1`,children:[(0,G.jsx)(`button`,{onClick:()=>se(t.id),disabled:O,className:`p-1.5 rounded hover:bg-green-500/20 text-green-500`,children:O?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(fs,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:oe,className:`p-1.5 rounded hover:bg-bambu-dark-tertiary text-bambu-gray`,children:(0,G.jsx)(nd,{className:`w-4 h-4`})})]})})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`td`,{className:`px-2 py-2`,children:(0,G.jsx)(`input`,{type:`checkbox`,checked:A.has(t.id),onChange:()=>ue(t.id),className:`w-4 h-4 accent-bambu-green cursor-pointer`})}),(0,G.jsx)(`td`,{className:`px-3 py-2`,children:(0,G.jsx)(w8,{rgba:t.hex_color.replace(/^#/,``)+(t.hex_color.length===7?`FF`:``),extraColors:t.extra_colors,effectType:t.effect_type,className:`w-8 h-8`,shape:`square`,title:t.hex_color,effectSize:`table`})}),(0,G.jsx)(`td`,{className:`px-3 py-2 text-white`,children:t.manufacturer}),(0,G.jsx)(`td`,{className:`px-3 py-2 text-bambu-gray`,children:t.material||`-`}),(0,G.jsx)(`td`,{className:`px-3 py-2 text-white`,children:t.color_name}),(0,G.jsx)(`td`,{className:`px-3 py-2 font-mono text-xs text-bambu-gray`,children:t.hex_color}),(0,G.jsx)(`td`,{className:`px-3 py-2`,children:(0,G.jsxs)(`div`,{className:`flex justify-end gap-1`,children:[(0,G.jsx)(`button`,{onClick:()=>ae(t),className:`p-1.5 rounded hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white`,children:(0,G.jsx)(Al,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:()=>z(t),className:`p-1.5 rounded bg-red-500/10 hover:bg-red-500/20 text-red-500`,children:(0,G.jsx)(Pu,{className:`w-4 h-4`})})]})})]})}),p===t.id&&(0,G.jsxs)(`tr`,{className:`border-t border-bambu-dark-tertiary/50 bg-bambu-dark`,children:[(0,G.jsx)(`td`,{colSpan:2}),(0,G.jsx)(`td`,{className:`px-3 py-2`,colSpan:2,children:(0,G.jsx)(`input`,{type:`text`,className:`w-full px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm font-mono focus:border-bambu-green focus:outline-none`,placeholder:e(`inventory.extraColorsPlaceholder`),value:w,onChange:e=>T(e.target.value)})}),(0,G.jsx)(`td`,{className:`px-3 py-2`,colSpan:2,children:(0,G.jsx)(`select`,{className:`w-full px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`,value:E,onChange:e=>D(e.target.value),children:_H.map(t=>(0,G.jsx)(`option`,{value:t.value,children:e(t.labelKey)},t.value||`none`))})}),(0,G.jsx)(`td`,{})]})]},t.id))})]})})]}),R&&(0,G.jsx)(of,{title:e(`settings.colorCatalog.deleteColor`),message:e(`settings.colorCatalog.deleteConfirm`,{name:`${R.manufacturer} - ${R.color_name}`}),confirmText:e(`common.delete`),variant:`danger`,onConfirm:H,onCancel:()=>z(null)}),M&&(0,G.jsx)(of,{title:e(`settings.colorCatalog.deleteSelected`),message:e(`settings.colorCatalog.bulkDeleteConfirm`,{count:A.size}),confirmText:e(`common.delete`),variant:`danger`,onConfirm:async()=>{if(N(!1),A.size!==0)try{let n=await Z.bulkDeleteColorEntries([...A]);r(e=>e.filter(e=>!A.has(e.id))),j(new Set),t(e(`settings.colorCatalog.bulkDeleted`,{count:n.deleted}),`success`)}catch{t(e(`settings.colorCatalog.bulkDeleteFailed`),`error`)}},onCancel:()=>N(!1)}),B&&(0,G.jsx)(of,{title:e(`settings.colorCatalog.resetCatalog`),message:e(`settings.colorCatalog.resetConfirm`),confirmText:e(`common.reset`),variant:`danger`,onConfirm:ce,onCancel:()=>V(!1)})]})}function fGe({link:e,onClose:t}){let{t:n}=U(),r=co(),i=!!e,a=(0,y.useRef)(null),[o,s]=(0,y.useState)(e?.name||``),[c,l]=(0,y.useState)(e?.url||``),[u,d]=(0,y.useState)(e?.icon||`link`),[f,p]=(0,y.useState)(e?.open_in_new_tab||!1),[m,h]=(0,y.useState)(!!e?.custom_icon),[g,_]=(0,y.useState)(e?.custom_icon?Z.getExternalLinkIconUrl(e.id):null),[v,b]=(0,y.useState)(null),[x,S]=(0,y.useState)(null);(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]);let C=q({mutationFn:async e=>{let t=await Z.createExternalLink(e);return v?await Z.uploadExternalLinkIcon(t.id,v):t},onSuccess:()=>{r.invalidateQueries({queryKey:[`external-links`]}),t()},onError:e=>{S(e.message)}}),w=q({mutationFn:async t=>{let n=await Z.updateExternalLink(e.id,t);return v?n=await Z.uploadExternalLinkIcon(e.id,v):!m&&e?.custom_icon&&(n=await Z.deleteExternalLinkIcon(e.id)),n},onSuccess:()=>{r.invalidateQueries({queryKey:[`external-links`]}),t()},onError:e=>{S(e.message)}}),T=e=>{let t=e.target.files?.[0];if(t){if(![`image/png`,`image/jpeg`,`image/gif`,`image/svg+xml`,`image/webp`,`image/x-icon`].includes(t.type)){S(`Please select a valid image file (PNG, JPG, GIF, SVG, WebP, or ICO)`);return}if(t.size>1024*1024){S(`Image file must be less than 1MB`);return}b(t),h(!0);let e=new FileReader;e.onload=e=>{_(e.target?.result)},e.readAsDataURL(t)}},E=()=>{b(null),_(null),h(!1),a.current&&(a.current.value=``)},D=e=>{if(e.preventDefault(),S(null),!o.trim()){S(`Name is required`);return}if(!c.trim()){S(`URL is required`);return}if(!c.startsWith(`http://`)&&!c.startsWith(`https://`)){S(`URL must start with http:// or https://`);return}let t={name:o.trim(),url:c.trim(),icon:u,open_in_new_tab:f};i?w.mutate(t):C.mutate(t)},O=C.isPending||w.isPending,k=uf(u);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`,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-3`,children:[(0,G.jsx)(`div`,{className:`p-2 rounded-full bg-bambu-green/20 text-bambu-green`,children:m&&g?(0,G.jsx)(`img`,{src:g,alt:``,className:`w-5 h-5 rounded`}):(0,G.jsx)(k,{className:`w-5 h-5`})}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i?`Edit Link`:`Add External Link`})]}),(0,G.jsx)(`button`,{onClick:t,className:`text-bambu-gray hover:text-white transition-colors`,children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]}),(0,G.jsxs)(`form`,{onSubmit:D,className:`p-6 space-y-4`,children:[x&&(0,G.jsx)(`div`,{className:`p-3 bg-red-100 dark:bg-red-500/20 border border-red-300 dark:border-red-500/50 rounded-lg text-sm text-red-700 dark:text-red-400`,children:x}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:`Name *`}),(0,G.jsx)(`input`,{type:`text`,value:o,onChange:e=>s(e.target.value),placeholder:`My Link`,maxLength:50,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:`URL *`}),(0,G.jsx)(`input`,{type:`text`,value:c,onChange:e=>l(e.target.value),placeholder:`https://example.com`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`label`,{className:`text-sm text-bambu-gray`,children:n(`externalLinks.openInNewTab`)}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>p(!f),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors ${f?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,children:(0,G.jsx)(`span`,{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${f?`translate-x-6`:`translate-x-1`}`})})]}),(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray`,children:`Icon`}),(0,G.jsxs)(`div`,{className:`p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,G.jsx)(`span`,{className:`text-sm text-white`,children:`Custom Icon`}),(0,G.jsx)(`input`,{ref:a,type:`file`,accept:`image/png,image/jpeg,image/gif,image/svg+xml,image/webp,image/x-icon`,className:`hidden`,onChange:T}),m&&g?(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`img`,{src:g,alt:`Custom icon`,className:`w-8 h-8 rounded border border-bambu-dark-tertiary`}),(0,G.jsx)(`button`,{type:`button`,onClick:E,className:`p-1 text-red-700 dark:text-red-400 hover:text-red-800 dark:hover:text-red-300 transition-colors`,title:`Remove custom icon`,children:(0,G.jsx)(Pu,{className:`w-4 h-4`})})]}):(0,G.jsxs)(Q,{type:`button`,variant:`secondary`,size:`sm`,onClick:()=>a.current?.click(),children:[(0,G.jsx)(Vu,{className:`w-4 h-4`}),`Upload`]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:`PNG, JPG, GIF, SVG, WebP, or ICO. Max 1MB.`})]}),!m&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray block mb-2`,children:`Or choose a preset icon`}),(0,G.jsx)(df,{value:u,onChange:d})]})]}),(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:`Cancel`}),(0,G.jsxs)(Q,{type:`submit`,disabled:O,className:`flex-1`,children:[O?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(ql,{className:`w-4 h-4`}),i?`Save`:`Add`]})]})]})]})})}function pGe(){let{t:e}=U(),t=co(),{authEnabled:n,hasPermission:r}=Nd(),{showToast:i}=qd(),[a,o]=(0,y.useState)(!1),[s,c]=(0,y.useState)(null),[l,u]=(0,y.useState)(null),[d,f]=(0,y.useState)(null),[p,m]=(0,y.useState)(null),[h,g]=(0,y.useState)(fm),[_,v]=(0,y.useState)(()=>um(mm.map(e=>e.id))),{data:b,isLoading:x}=K({queryKey:[`external-links`],queryFn:Z.getExternalLinks}),S=q({mutationFn:e=>Z.deleteExternalLink(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`external-links`]})}}),{data:C}=K({queryKey:[`settings`],queryFn:Z.getSettings,enabled:n&&r(`settings:update`)}),w=q({mutationFn:e=>Z.updateSettings({default_sidebar_order:e}),onSuccess:(n,r)=>{t.invalidateQueries({queryKey:[`settings`]}),t.invalidateQueries({queryKey:[`default-sidebar-order`]}),i(e(r?`settings.sidebarDefaultSet`:`settings.sidebarDefaultCleared`),`success`)},onError:()=>{i(e(`settings.sidebarDefaultFailed`),`error`)}}),T=(0,y.useMemo)(()=>{let e=new Map(mm.map(e=>[e.id,e])),t=new Map((b||[]).map(e=>[`ext-${e.id}`,e])),n=[],r=new Set,i=i=>{if(r.has(i))return;let a=e.get(i);if(a){n.push({type:`system`,id:i,navItem:a}),r.add(i);return}let o=t.get(i);o&&(n.push({type:`external`,id:i,link:o}),r.add(i))};return _.forEach(i),mm.forEach(e=>i(e.id)),(b||[]).forEach(e=>i(`ext-${e.id}`)),n},[b,_]),E=e=>{v(e),dm(e)},D=(e,t)=>{f(t),e.dataTransfer.effectAllowed=`move`,e.dataTransfer.setData(`text/plain`,t)},O=(e,t)=>{e.preventDefault(),e.dataTransfer.dropEffect=`move`,m(t)},k=(e,t)=>{if(e.preventDefault(),d===null||d===t){f(null),m(null);return}let n=T.map(e=>e.id),r=n.indexOf(d),i=n.indexOf(t);if(r===-1||i===-1){f(null),m(null);return}n.splice(r,1),n.splice(i,0,d),E(n),f(null),m(null)},A=()=>{f(null),m(null)},j=e=>{u(e)},M=()=>{l&&(S.mutate(l.id),u(null))},N=()=>{let e=[...mm.map(e=>e.id),...(b||[]).map(e=>`ext-${e.id}`)];g([]),v(e),pm([]),dm(e)},P=e=>{let t=T.map(e=>e.id);w.mutate(e?JSON.stringify({order:t,hiddenSystemItemIds:h}):``)},F=e=>{if(e===`settings`)return;let t=h.includes(e)?h.filter(t=>t!==e):[...h,e];g(t),pm(t)},I=n&&r(`settings:update`),L=!!C?.default_sidebar_order;return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(zd,{id:`card-sidebar-links`,children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-y-2 gap-x-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Xc,{className:`w-5 h-5 text-bambu-green`}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`externalLinks.sidebarLayout`)})]}),(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[I&&(0,G.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-bambu-gray`,children:[(0,G.jsx)(`span`,{children:e(`settings.setDefault`)}),(0,G.jsx)(fH,{checked:L,onChange:P,disabled:w.isPending})]}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:N,className:`whitespace-nowrap`,children:[(0,G.jsx)(Wl,{className:`w-4 h-4`}),e(`settings.reset`)]}),(0,G.jsxs)(Q,{size:`sm`,onClick:()=>o(!0),className:`whitespace-nowrap`,children:[(0,G.jsx)(Fl,{className:`w-4 h-4`}),`Add Link`]})]})]})}),(0,G.jsxs)(Vd,{children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4`,children:e(`externalLinks.sidebarLayoutDescription`)}),x?(0,G.jsx)(`div`,{className:`flex justify-center py-8`,children:(0,G.jsx)(Y,{className:`w-6 h-6 text-bambu-green animate-spin`})}):(0,G.jsx)(`div`,{className:`space-y-2`,children:T.map(t=>{let n=t.type===`system`&&h.includes(t.id),r=t.id===`settings`;if(t.type===`system`){let i=t.navItem.icon;return(0,G.jsxs)(`div`,{draggable:!0,onDragStart:e=>D(e,t.id),onDragOver:e=>O(e,t.id),onDragLeave:()=>m(null),onDrop:e=>k(e,t.id),onDragEnd:A,className:`relative flex items-center gap-3 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary transition-colors ${d===t.id?`opacity-50`:n?`opacity-60`:``} ${p===t.id&&d!==t.id?`before:absolute before:left-3 before:right-3 before:top-0 before:h-0.5 before:bg-bambu-green`:``}`,children:[(0,G.jsx)(jc,{className:`w-6 h-6 md:w-4 md:h-4 text-bambu-gray cursor-grab flex-shrink-0`}),(0,G.jsx)(`div`,{className:`p-2 rounded-lg bg-bambu-dark-tertiary text-bambu-gray`,children:(0,G.jsx)(i,{className:`w-4 h-4`})}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`span`,{className:`text-white font-medium truncate block`,children:e(t.navItem.labelKey)}),(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray truncate block`,children:e(r?`externalLinks.requiredInSidebar`:n?`externalLinks.hiddenFromSidebar`:`externalLinks.visibleInSidebar`)})]}),(0,G.jsx)(`button`,{onClick:()=>F(t.id),disabled:r,className:`p-2 rounded-lg hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white transition-colors flex-shrink-0 disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:bg-transparent disabled:hover:text-bambu-gray`,title:e(r?`externalLinks.settingsCannotBeHidden`:n?`externalLinks.showPage`:`externalLinks.hidePage`),"aria-label":e(r?`externalLinks.settingsCannotBeHidden`:n?`externalLinks.showPage`:`externalLinks.hidePage`),children:n?(0,G.jsx)(ic,{className:`w-4 h-4`}):(0,G.jsx)(ac,{className:`w-4 h-4`})})]},t.id)}let i=t.link,a=uf(i.icon);return(0,G.jsxs)(`div`,{draggable:!0,onDragStart:e=>D(e,t.id),onDragOver:e=>O(e,t.id),onDragLeave:()=>m(null),onDrop:e=>k(e,t.id),onDragEnd:A,className:`relative flex items-center gap-3 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary transition-colors ${d===t.id?`opacity-50`:``} ${p===t.id&&d!==t.id?`before:absolute before:left-3 before:right-3 before:top-0 before:h-0.5 before:bg-bambu-green`:``}`,children:[(0,G.jsx)(jc,{className:`w-6 h-6 md:w-4 md:h-4 text-bambu-gray cursor-grab flex-shrink-0`}),(0,G.jsx)(`div`,{className:`p-2 rounded-lg bg-bambu-dark-tertiary text-bambu-gray`,children:i.custom_icon?(0,G.jsx)(`img`,{src:Z.getExternalLinkIconUrl(i.id),alt:``,className:`w-4 h-4`}):(0,G.jsx)(a,{className:`w-4 h-4`})}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-white font-medium truncate`,children:i.name}),(0,G.jsx)(rc,{className:`w-3 h-3 text-bambu-gray flex-shrink-0`})]}),(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray truncate block`,children:i.url})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1 flex-shrink-0`,children:[(0,G.jsx)(`button`,{onClick:()=>c(i),className:`p-2 rounded-lg hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white transition-colors`,title:e(`common.edit`),children:(0,G.jsx)(Al,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:()=>j(i),disabled:S.isPending,className:`p-2 rounded-lg hover:bg-red-100 dark:hover:bg-red-500/20 text-bambu-gray hover:text-red-900 dark:hover:text-red-400 transition-colors disabled:opacity-50`,title:e(`externalLinks.deleteLink`),children:(0,G.jsx)(Pu,{className:`w-4 h-4`})})]})]},t.id)})})]})]}),(a||s)&&(0,G.jsx)(fGe,{link:s,onClose:()=>{o(!1),c(null)}}),l&&(0,G.jsx)(of,{title:`Delete Link`,message:`Are you sure you want to delete "${l.name}"? This action cannot be undone.`,confirmText:`Delete`,cancelText:`Cancel`,variant:`danger`,onConfirm:M,onCancel:()=>u(null)})]})}async function T8(e){if(navigator.clipboard&&window.isSecureContext)try{return await navigator.clipboard.writeText(e),!0}catch{}let t=document.createElement(`textarea`);t.value=e,t.style.position=`fixed`,t.style.opacity=`0`,document.body.appendChild(t);try{return t.select(),document.execCommand(`copy`)}catch{return!1}finally{t.parentNode&&t.parentNode.removeChild(t)}}function mGe(e,t,n=`text/plain`){let r=new Blob([e],{type:n}),i=URL.createObjectURL(r),a=document.createElement(`a`);a.href=i,a.download=t,document.body.appendChild(a),a.click(),a.remove(),URL.revokeObjectURL(i)}function hGe({status:e}){return e===`pass`?(0,G.jsx)(Ss,{className:`w-5 h-5 text-bambu-green flex-shrink-0`}):e===`fail`?(0,G.jsx)(Ds,{className:`w-5 h-5 text-red-600 dark:text-red-400 flex-shrink-0`}):e===`warn`?(0,G.jsx)(Lu,{className:`w-5 h-5 text-amber-600 dark:text-amber-400 flex-shrink-0`}):(0,G.jsx)(ws,{className:`w-5 h-5 text-bambu-gray flex-shrink-0`})}function gGe({vpId:e,vpName:t,onClose:n}){let{t:r}=U(),i=q({mutationFn:()=>wd.diagnose(e)});(0,y.useEffect)(()=>{i.mutate()},[]),(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[n]);let a=i.data,o=a?.overall===`ok`?`bg-bambu-green/10 border-bambu-green/30 text-bambu-green`:a?.overall===`warnings`?`bg-amber-50 dark:bg-amber-500/10 border-amber-300 dark:border-amber-500/30 text-amber-700 dark:text-amber-300`:`bg-red-50 dark:bg-red-500/10 border-red-300 dark:border-red-500/30 text-red-700 dark:text-red-300`;return(0,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-lg flex flex-col max-h-[85vh]`,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)(Su,{className:`w-5 h-5 text-bambu-green flex-shrink-0`}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white truncate`,children:r(`vpDiagnostic.title`,{name:t})})]}),(0,G.jsx)(`button`,{onClick:n,className:`text-bambu-gray hover:text-white transition-colors`,title:r(`common.close`),children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]}),(0,G.jsxs)(`div`,{className:`p-6 space-y-4 overflow-y-auto`,children:[i.isPending&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray`,children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),(0,G.jsx)(`span`,{children:r(`vpDiagnostic.running`)})]}),i.isError&&(0,G.jsx)(`div`,{className:`rounded-lg bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30 px-4 py-3 text-sm text-red-700 dark:text-red-300`,children:r(`vpDiagnostic.runFailed`,{error:i.error.message})}),a&&(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsx)(`ol`,{className:`space-y-2`,children:a.checks.map(e=>{let t=r(`vpDiagnostic.check.${e.id}.${e.status}`,{...e.params,defaultValue:``});return(0,G.jsxs)(`li`,{className:`flex items-start gap-3 bg-bambu-dark rounded-lg px-4 py-2.5 ${e.status===`skip`?`opacity-60`:``}`,children:[(0,G.jsx)(`div`,{className:`mt-0.5`,children:(0,G.jsx)(hGe,{status:e.status})}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`div`,{className:`text-sm text-white`,children:r(`vpDiagnostic.check.${e.id}.title`,e.params)}),t&&(0,G.jsx)(`div`,{className:`text-xs text-bambu-gray mt-0.5`,children:t})]})]},e.id)})}),(0,G.jsx)(`div`,{className:`rounded-lg border px-4 py-3 text-sm ${o}`,children:r(`vpDiagnostic.overall.${a.overall}`)})]})]}),(0,G.jsxs)(`div`,{className:`px-6 py-4 border-t border-bambu-dark-tertiary flex justify-end gap-2`,children:[(0,G.jsx)(`button`,{onClick:()=>i.mutate(),disabled:i.isPending,className:`px-4 py-2 bg-bambu-dark hover:bg-bambu-dark-tertiary disabled:opacity-50 text-white text-sm rounded-lg transition-colors`,children:r(`vpDiagnostic.retry`)}),(0,G.jsx)(`button`,{onClick:n,className:`px-4 py-2 bg-bambu-green hover:bg-bambu-green/90 text-white text-sm rounded-lg transition-colors`,children:r(`common.close`)})]})]})})}var E8={archive:`archive`,review:`review`,queue:`queue`,proxy:`proxy`};function D8(e){return e===`immediate`?`archive`:e===`print_queue`||e===`queue`?`queue`:e===`archive`||e===`review`||e===`proxy`?e:`archive`}function _Ge({printer:e,models:t}){let{t:n}=U(),r=co(),{showToast:i}=qd(),[a,o]=(0,y.useState)(!0),[s,c]=(0,y.useState)(e.enabled),[l,u]=(0,y.useState)(e.name),[d,f]=(0,y.useState)(``),[p,m]=(0,y.useState)(D8(e.mode)),[h,g]=(0,y.useState)(e.target_printer_id),[_,v]=(0,y.useState)(e.bind_ip||``),[b,x]=(0,y.useState)(e.remote_interface_ip||``),[S,C]=(0,y.useState)(e.model||``),[w,T]=(0,y.useState)(e.auto_dispatch??!0),[E,D]=(0,y.useState)(e.queue_force_color_match??!1),[O,k]=(0,y.useState)(e.save_ams_mapping??!1),[A,j]=(0,y.useState)(e.gcode_injection??!1),[M,N]=(0,y.useState)(e.tailscale_disabled??!0),[P,F]=(0,y.useState)(!1),[I,L]=(0,y.useState)(null),[R,z]=(0,y.useState)(!1),[B,V]=(0,y.useState)(!1),[ee,te]=(0,y.useState)(!1),{data:ne}=K({queryKey:[`tailscale-status`],queryFn:wd.getTailscaleStatus,enabled:!M,staleTime:6e4}),re=ne?.available?ne.fqdn:``,ie=ne?.available?ne.tailscale_ips?.[0]??``:``,ae=async e=>{e.stopPropagation();let t=re;t&&(await T8(t)?(te(!0),i(n(`printers.copied`)),setTimeout(()=>te(!1),2e3)):i(n(`virtualPrinter.toast.copyFailed`),`error`))};(0,y.useEffect)(()=>{I||(c(e.enabled),m(D8(e.mode)),u(e.name),g(e.target_printer_id),v(e.bind_ip||``),x(e.remote_interface_ip||``),C(e.model||``),T(e.auto_dispatch??!0),D(e.queue_force_color_match??!1),k(e.save_ams_mapping??!1),j(e.gcode_injection??!1),N(e.tailscale_disabled??!0))},[e,I]);let{data:oe}=K({queryKey:[`printers`],queryFn:Z.getPrinters}),{data:se}=K({queryKey:[`network-interfaces`],queryFn:()=>Z.getNetworkInterfaces().then(e=>e.interfaces)}),H=q({mutationFn:t=>wd.update(e.id,t),onSuccess:()=>{r.invalidateQueries({queryKey:[`virtual-printers`]}),i(n(`virtualPrinter.toast.updated`)),L(null)},onError:t=>{i(t.message||n(`virtualPrinter.toast.failedToUpdate`),`error`),c(e.enabled),m(D8(e.mode)),g(e.target_printer_id),v(e.bind_ip||``),N(e.tailscale_disabled??!0),D(e.queue_force_color_match??!1),k(e.save_ams_mapping??!1),j(e.gcode_injection??!1),L(null)}}),ce=q({mutationFn:()=>wd.remove(e.id),onSuccess:()=>{r.invalidateQueries({queryKey:[`virtual-printers`]}),i(n(`virtualPrinter.toast.deleted`)),z(!1)},onError:e=>{i(e.message||n(`virtualPrinter.toast.failedToDelete`),`error`),z(!1)}}),le=t=>{t.stopPropagation();let r=!s;if(r){if(!_){i(n(`virtualPrinter.toast.bindIpRequired`),`error`);return}if(p===`proxy`){if(!h){i(n(`virtualPrinter.toast.targetPrinterRequired`),`error`);return}}else if(!d&&!e.access_code_set){i(n(`virtualPrinter.toast.accessCodeRequired`),`error`);return}}c(r),L(`toggle`),H.mutate({enabled:r})},ue=()=>{l.trim()&&(L(`name`),H.mutate({name:l.trim()}))},de=()=>{if(!d){i(n(`virtualPrinter.toast.accessCodeEmpty`),`error`);return}if(d.length!==8){i(n(`virtualPrinter.toast.accessCodeLength`),`error`);return}L(`accessCode`),H.mutate({access_code:d}),f(``)},fe=e=>{m(e),L(`mode`),H.mutate({mode:e})},pe=e=>{C(e),L(`model`),H.mutate({model:e})},me=e=>{let t=ve?.access_code,r=oe?.find(t=>t.id===e)?.access_code;g(e),L(`targetPrinter`),H.mutate({target_printer_id:e},{onSuccess:()=>{t&&r&&t!==r&&i(n(`virtualPrinter.toast.targetCodeChangedRebind`),`info`)}})},he=e=>{x(e),L(`remoteInterface`),H.mutate({remote_interface_ip:e})},ge=e.status?.running||!1,_e=n(`virtualPrinter.mode.${E8[p]||`archive`}`),ve=oe?.find(e=>e.id===h),ye=ve?.name,be=!!h,xe=be?ve?.access_code??``:``;return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(zd,{className:`overflow-hidden`,children:[(0,G.jsxs)(`div`,{className:`px-4 py-3 flex items-center gap-3 cursor-pointer select-none`,onClick:()=>o(!a),children:[(0,G.jsx)(`button`,{className:`text-bambu-gray flex-shrink-0`,children:a?(0,G.jsx)(ps,{className:`w-4 h-4`}):(0,G.jsx)(ms,{className:`w-4 h-4`})}),(0,G.jsx)(`span`,{className:`w-2 h-2 rounded-full flex-shrink-0 ${ge?`bg-green-400 animate-pulse`:`bg-gray-500`}`}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0 flex flex-wrap items-center gap-x-3 gap-y-1`,children:[(0,G.jsx)(`span`,{className:`text-white font-medium truncate max-w-full`,children:e.name}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray flex-shrink-0`,children:_e}),e.model_name&&(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray flex-shrink-0`,children:e.model_name}),ye&&(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray truncate max-w-full`,children:[p===`proxy`&&(0,G.jsx)(Ro,{className:`w-3 h-3 inline mr-1`}),ye]}),_&&(0,G.jsx)(`span`,{className:`text-[10px] text-bambu-gray flex-shrink-0 font-mono`,children:_}),b&&(0,G.jsx)(`span`,{className:`text-[10px] text-bambu-gray flex-shrink-0 font-mono`,children:b})]}),(0,G.jsx)(`div`,{className:`ml-auto flex items-center gap-2 flex-shrink-0`,onClick:e=>e.stopPropagation(),children:(0,G.jsx)(`button`,{onClick:le,disabled:I===`toggle`,className:`relative w-10 h-5 rounded-full transition-colors ${s?`bg-bambu-green`:`bg-bambu-dark-tertiary`} ${I===`toggle`?`opacity-50`:``}`,children:(0,G.jsx)(`span`,{className:`absolute top-0.5 left-0.5 w-4 h-4 bg-white rounded-full transition-transform ${s?`translate-x-5`:``}`})})})]}),a&&(0,G.jsxs)(Vd,{className:`pt-0 space-y-4`,children:[(0,G.jsx)(`div`,{className:`border-t border-bambu-dark-tertiary`}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`input`,{type:`text`,value:l,onChange:e=>u(e.target.value),onBlur:ue,onKeyDown:e=>e.key===`Enter`&&ue(),className:`flex-1 text-sm text-white bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-1.5 focus:border-bambu-green focus:outline-none`}),(0,G.jsx)(`button`,{onClick:()=>V(!0),className:`p-1.5 text-bambu-gray hover:text-bambu-green transition-colors flex-shrink-0`,title:n(`vpDiagnostic.runButton`),children:(0,G.jsx)(Su,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:()=>z(!0),className:`p-1.5 text-bambu-gray hover:text-red-600 dark:hover:text-red-400 transition-colors flex-shrink-0`,title:n(`common.delete`),children:(0,G.jsx)(Pu,{className:`w-4 h-4`})})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 -mt-2`,children:[re&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-green-700/80 dark:text-green-400/70 min-w-0`,children:[(0,G.jsx)(au,{className:`w-3.5 h-3.5 flex-shrink-0`}),(0,G.jsx)(`span`,{className:`font-mono text-xs truncate`,children:ie?`${ie} (${re})`:re}),(0,G.jsx)(`button`,{onClick:ae,className:`p-0.5 rounded hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white transition-colors flex-shrink-0`,title:n(ee?`printers.copied`:`printers.copyToClipboard`),children:ee?(0,G.jsx)(fs,{className:`w-3.5 h-3.5 text-bambu-green`}):(0,G.jsx)(Vs,{className:`w-3.5 h-3.5`})})]}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray font-mono ml-auto flex-shrink-0`,children:e.serial})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`div`,{className:`text-white text-sm font-medium mb-2`,children:n(`virtualPrinter.mode.title`)}),(0,G.jsx)(`div`,{className:`grid grid-cols-2 gap-2`,children:[`archive`,`review`,`queue`,`proxy`].map(e=>(0,G.jsxs)(`button`,{onClick:()=>fe(e),disabled:I===`mode`,className:`p-2 rounded-lg border text-left transition-colors ${p===e?e===`proxy`?`border-blue-500 bg-blue-500/10`:`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary hover:border-bambu-gray`}`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 text-white text-xs font-medium`,children:[e===`proxy`&&(0,G.jsx)(Ro,{className:`w-3 h-3`}),n(`virtualPrinter.mode.${E8[e]}`)]}),(0,G.jsx)(`div`,{className:`text-[10px] text-bambu-gray`,children:n(`virtualPrinter.mode.${E8[e]}Desc`)})]},e))})]}),p===`queue`&&(0,G.jsx)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsx)(`div`,{className:`text-white text-sm font-medium`,children:n(`virtualPrinter.autoDispatch.title`)}),(0,G.jsx)(`div`,{className:`text-[10px] text-bambu-gray`,children:n(`virtualPrinter.autoDispatch.description`)})]}),(0,G.jsx)(`button`,{onClick:()=>{let e=!w;T(e),L(`autoDispatch`),H.mutate({auto_dispatch:e})},disabled:I===`autoDispatch`,className:`relative w-10 h-5 rounded-full transition-colors flex-shrink-0 ${w?`bg-bambu-green`:`bg-bambu-dark-tertiary`} ${I===`autoDispatch`?`opacity-50`:``}`,children:(0,G.jsx)(`span`,{className:`absolute top-0.5 left-0.5 w-4 h-4 bg-white rounded-full transition-transform ${w?`translate-x-5`:``}`})})]})}),p===`queue`&&(0,G.jsx)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsx)(`div`,{className:`text-white text-sm font-medium`,children:n(`virtualPrinter.queueForceColorMatch.title`)}),(0,G.jsx)(`div`,{className:`text-[10px] text-bambu-gray`,children:n(`virtualPrinter.queueForceColorMatch.description`)})]}),(0,G.jsx)(`button`,{onClick:()=>{let e=!E;D(e),L(`queueForceColorMatch`),H.mutate({queue_force_color_match:e})},disabled:I===`queueForceColorMatch`,className:`relative w-10 h-5 rounded-full transition-colors flex-shrink-0 ${E?`bg-bambu-green`:`bg-bambu-dark-tertiary`} ${I===`queueForceColorMatch`?`opacity-50`:``}`,children:(0,G.jsx)(`span`,{className:`absolute top-0.5 left-0.5 w-4 h-4 bg-white rounded-full transition-transform ${E?`translate-x-5`:``}`})})]})}),p===`queue`&&(0,G.jsx)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsx)(`div`,{className:`text-white text-sm font-medium`,children:n(`virtualPrinter.saveAmsMapping.title`)}),(0,G.jsx)(`div`,{className:`text-[10px] text-bambu-gray`,children:n(`virtualPrinter.saveAmsMapping.description`)})]}),(0,G.jsx)(`button`,{onClick:()=>{let e=!O;k(e),L(`saveAmsMapping`),H.mutate({save_ams_mapping:e})},disabled:I===`saveAmsMapping`,className:`relative w-10 h-5 rounded-full transition-colors flex-shrink-0 ${O?`bg-bambu-green`:`bg-bambu-dark-tertiary`} ${I===`saveAmsMapping`?`opacity-50`:``}`,children:(0,G.jsx)(`span`,{className:`absolute top-0.5 left-0.5 w-4 h-4 bg-white rounded-full transition-transform ${O?`translate-x-5`:``}`})})]})}),p===`queue`&&(0,G.jsx)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsx)(`div`,{className:`text-white text-sm font-medium`,children:n(`virtualPrinter.gcodeInjection.title`)}),(0,G.jsx)(`div`,{className:`text-[10px] text-bambu-gray`,children:n(`virtualPrinter.gcodeInjection.description`)})]}),(0,G.jsx)(`button`,{onClick:()=>{let e=!A;j(e),L(`gcodeInjection`),H.mutate({gcode_injection:e})},disabled:I===`gcodeInjection`,className:`relative w-10 h-5 rounded-full transition-colors flex-shrink-0 ${A?`bg-bambu-green`:`bg-bambu-dark-tertiary`} ${I===`gcodeInjection`?`opacity-50`:``}`,children:(0,G.jsx)(`span`,{className:`absolute top-0.5 left-0.5 w-4 h-4 bg-white rounded-full transition-transform ${A?`translate-x-5`:``}`})})]})}),(0,G.jsx)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsx)(`div`,{className:`text-white text-sm font-medium`,children:n(`virtualPrinter.tailscaleDisabled.title`)}),(0,G.jsx)(`div`,{className:`text-[10px] text-bambu-gray`,children:n(`virtualPrinter.tailscaleDisabled.description`)})]}),(0,G.jsx)(`button`,{onClick:()=>{let e=!M;N(e),L(`tailscaleDisabled`),H.mutate({tailscale_disabled:e})},disabled:I===`tailscaleDisabled`,className:`relative w-10 h-5 rounded-full transition-colors shrink-0 ${M?`bg-bambu-dark-tertiary`:`bg-bambu-green`} ${I===`tailscaleDisabled`?`opacity-50`:``}`,children:(0,G.jsx)(`span`,{className:`absolute top-0.5 left-0.5 w-4 h-4 bg-white rounded-full transition-transform ${M?``:`translate-x-5`}`})})]})}),p!==`proxy`&&(0,G.jsxs)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:[(0,G.jsx)(`div`,{className:`text-white text-sm font-medium mb-1`,children:n(`virtualPrinter.model.title`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:n(`virtualPrinter.model.description`)}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(`select`,{value:S,onChange:e=>pe(e.target.value),disabled:I===`model`,className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-1.5 text-white text-sm appearance-none cursor-pointer disabled:opacity-50 pr-10`,children:Object.entries(t).map(([e,t])=>(0,G.jsxs)(`option`,{value:e,children:[t,` (`,e,`)`]},e))}),(0,G.jsx)(ps,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]})]}),p===`proxy`&&(0,G.jsx)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:(0,G.jsxs)(`div`,{className:`flex items-start gap-2 p-2 rounded bg-blue-50 border border-blue-300 dark:bg-blue-500/10 dark:border-blue-500/30`,children:[(0,G.jsx)(Wc,{className:`w-4 h-4 text-blue-600 dark:text-blue-400 flex-shrink-0 mt-0.5`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`virtualPrinter.proxy.accessCodeHint`)})]})}),p!==`proxy`&&(0,G.jsxs)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,G.jsx)(`div`,{className:`text-white text-sm font-medium`,children:n(`virtualPrinter.accessCode.title`)}),be?(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-xs text-blue-700 dark:text-blue-400`,children:[(0,G.jsx)(Wc,{className:`w-3 h-3`}),n(`virtualPrinter.accessCode.inheritedFromTarget`)]}):e.access_code_set?(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-xs text-green-700 dark:text-green-400`,children:[(0,G.jsx)(fs,{className:`w-3 h-3`}),n(`virtualPrinter.accessCode.isSet`)]}):(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-xs text-yellow-700 dark:text-yellow-400`,children:[(0,G.jsx)(Lu,{className:`w-3 h-3`}),n(`virtualPrinter.accessCode.notSet`)]})]}),be?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(`input`,{type:P?`text`:`password`,value:xe,readOnly:!0,"aria-label":n(`virtualPrinter.accessCode.title`),className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-1.5 text-white text-sm pr-10 font-mono opacity-90 cursor-default`}),(0,G.jsx)(`button`,{onClick:()=>F(!P),className:`absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white`,"aria-label":n(P?`virtualPrinter.accessCode.hide`:`virtualPrinter.accessCode.reveal`),children:P?(0,G.jsx)(ic,{className:`w-4 h-4`}):(0,G.jsx)(ac,{className:`w-4 h-4`})})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(`virtualPrinter.accessCode.derivedFromTargetHint`)})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsxs)(`div`,{className:`relative flex-1`,children:[(0,G.jsx)(`input`,{type:P?`text`:`password`,value:d,onChange:e=>f(e.target.value),placeholder:e.access_code_set?n(`virtualPrinter.accessCode.placeholderChange`):n(`virtualPrinter.accessCode.placeholder`),maxLength:8,className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-1.5 text-white text-sm placeholder-bambu-gray pr-10 font-mono`}),(0,G.jsx)(`button`,{onClick:()=>F(!P),className:`absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white`,children:P?(0,G.jsx)(ic,{className:`w-4 h-4`}):(0,G.jsx)(ac,{className:`w-4 h-4`})})]}),(0,G.jsx)(Q,{onClick:de,disabled:!d||I===`accessCode`,variant:`primary`,children:I===`accessCode`?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):n(`common.save`)})]}),d&&(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:(0,G.jsx)(`span`,{className:d.length===8?`text-green-700 dark:text-green-400`:`text-yellow-700 dark:text-yellow-400`,children:n(`virtualPrinter.accessCode.charCount`,{count:d.length})})})]})]}),(0,G.jsxs)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:[(0,G.jsx)(`div`,{className:`text-white text-sm font-medium mb-2`,children:n(`virtualPrinter.targetPrinter.title`)}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsxs)(`select`,{value:h??``,onChange:e=>{let t=parseInt(e.target.value,10);isNaN(t)||me(t)},disabled:I===`targetPrinter`,className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-1.5 text-white text-sm appearance-none cursor-pointer disabled:opacity-50 pr-10`,children:[(0,G.jsx)(`option`,{value:``,children:n(`virtualPrinter.targetPrinter.placeholder`)}),oe?.map(e=>(0,G.jsxs)(`option`,{value:e.id,children:[e.name,` (`,e.ip_address,`)`]},e.id))]}),(0,G.jsx)(ps,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]})]}),(0,G.jsxs)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:[(0,G.jsx)(`div`,{className:`text-white text-sm font-medium mb-1`,children:n(`virtualPrinter.bindIp.title`)}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsxs)(`select`,{value:_,onChange:e=>{v(e.target.value),L(`bindIp`),H.mutate({bind_ip:e.target.value})},disabled:I===`bindIp`,className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-1.5 text-white text-sm appearance-none cursor-pointer disabled:opacity-50 pr-10`,children:[(0,G.jsx)(`option`,{value:``,children:n(`virtualPrinter.bindIp.placeholder`)}),se?.map(e=>(0,G.jsxs)(`option`,{value:e.ip,children:[e.name,` (`,e.ip,`)`,e.is_alias?` [alias]`:``,` - `,e.subnet]},e.ip))]}),(0,G.jsx)(ps,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(`virtualPrinter.bindIp.hint`)})]}),(0,G.jsxs)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,G.jsx)(`div`,{className:`text-white text-sm font-medium`,children:n(`virtualPrinter.remoteInterface.title`)}),b?(0,G.jsx)(`span`,{className:`flex items-center gap-1 text-xs text-green-700 dark:text-green-400`,children:(0,G.jsx)(fs,{className:`w-3 h-3`})}):(0,G.jsx)(`span`,{className:`flex items-center gap-1 text-xs text-bambu-gray`,title:n(`virtualPrinter.remoteInterface.optional`),children:(0,G.jsx)(Wc,{className:`w-3 h-3`})})]}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsxs)(`select`,{value:b,onChange:e=>he(e.target.value),disabled:I===`remoteInterface`,className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-1.5 text-white text-sm appearance-none cursor-pointer disabled:opacity-50 pr-10`,children:[(0,G.jsx)(`option`,{value:``,children:n(`virtualPrinter.remoteInterface.placeholder`)}),se?.map(e=>(0,G.jsxs)(`option`,{value:e.ip,children:[e.name,` (`,e.ip,`) - `,e.subnet]},e.ip))]}),(0,G.jsx)(ps,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]})]})]})]}),R&&(0,G.jsx)(of,{title:n(`virtualPrinter.deleteConfirm.title`),message:n(`virtualPrinter.deleteConfirm.message`,{name:e.name}),variant:`danger`,confirmText:n(`common.delete`),isLoading:ce.isPending,onConfirm:()=>ce.mutate(),onCancel:()=>z(!1)}),B&&(0,G.jsx)(gGe,{vpId:e.id,vpName:e.name,onClose:()=>V(!1)})]})}var O8={archive:`archive`,review:`review`,queue:`queue`,proxy:`proxy`};function vGe({onClose:e}){let{t}=U(),n=co(),{showToast:r}=qd(),[i,a]=(0,y.useState)(``),[o,s]=(0,y.useState)(`archive`),[c,l]=(0,y.useState)(null),{data:u}=K({queryKey:[`printers`],queryFn:Z.getPrinters}),d=q({mutationFn:()=>wd.create({name:i.trim()||`Bambuddy`,mode:o,target_printer_id:o===`proxy`?c??void 0:void 0}),onSuccess:()=>{n.invalidateQueries({queryKey:[`virtual-printers`]}),r(t(`virtualPrinter.toast.created`)),e()},onError:e=>{r(e.message||t(`virtualPrinter.toast.failedToCreate`),`error`)}});return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,onClick:e,children:(0,G.jsx)(zd,{className:`w-full max-w-md`,onClick:e=>e.stopPropagation(),children:(0,G.jsxs)(Vd,{className:`p-6 space-y-4`,children:[(0,G.jsx)(`h3`,{className:`text-lg font-semibold text-white`,children:t(`virtualPrinter.addDialog.title`)}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`text-sm text-white font-medium block mb-1`,children:t(`virtualPrinter.addDialog.name`)}),(0,G.jsx)(`input`,{type:`text`,value:i,onChange:e=>a(e.target.value),placeholder:`Bambuddy`,className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-2 text-white text-sm placeholder-bambu-gray`,autoFocus:!0})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`text-sm text-white font-medium block mb-1`,children:t(`virtualPrinter.mode.title`)}),(0,G.jsx)(`div`,{className:`grid grid-cols-2 gap-2`,children:[`archive`,`review`,`queue`,`proxy`].map(e=>(0,G.jsxs)(`button`,{onClick:()=>s(e),className:`p-2 rounded-lg border text-left transition-colors ${o===e?e===`proxy`?`border-blue-500 bg-blue-500/10`:`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary hover:border-bambu-gray`}`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 text-white text-xs font-medium`,children:[e===`proxy`&&(0,G.jsx)(Ro,{className:`w-3 h-3`}),t(`virtualPrinter.mode.${O8[e]}`)]}),(0,G.jsx)(`div`,{className:`text-[10px] text-bambu-gray`,children:t(`virtualPrinter.mode.${O8[e]}Desc`)})]},e))})]}),o===`proxy`&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`text-sm text-white font-medium block mb-1`,children:t(`virtualPrinter.targetPrinter.title`)}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsxs)(`select`,{value:c??``,onChange:e=>{let t=parseInt(e.target.value,10);l(isNaN(t)?null:t)},className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-2 text-white text-sm appearance-none cursor-pointer pr-10`,children:[(0,G.jsx)(`option`,{value:``,children:t(`virtualPrinter.targetPrinter.placeholder`)}),u?.map(e=>(0,G.jsxs)(`option`,{value:e.id,children:[e.name,` (`,e.ip_address,`)`]},e.id))]}),(0,G.jsx)(ps,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:t(`virtualPrinter.addDialog.hint`)}),(0,G.jsxs)(`div`,{className:`flex gap-3 pt-2`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:e,className:`flex-1`,disabled:d.isPending,children:t(`common.cancel`)}),(0,G.jsx)(Q,{variant:`primary`,onClick:()=>d.mutate(),className:`flex-1`,disabled:d.isPending,children:d.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):t(`virtualPrinter.addDialog.create`)})]})]})})})}function yGe(){let{t:e}=U(),t=co(),{showToast:n}=qd(),[r,i]=(0,y.useState)(!1),{data:a,isLoading:o}=K({queryKey:[`virtual-printers`],queryFn:wd.list,refetchInterval:1e4}),{data:s}=K({queryKey:[`virtual-printer-settings`],queryFn:Cd.getSettings}),c=q({mutationFn:e=>Cd.updateSettings({archive_name_source:e}),onSuccess:()=>{t.invalidateQueries({queryKey:[`virtual-printer-settings`]}),n(e(`virtualPrinter.toast.updated`))},onError:t=>{n(t.message||e(`virtualPrinter.toast.failedToUpdate`),`error`)}}),l=s?.archive_name_source===`filename`,{data:u}=K({queryKey:[`vp-ca-certificate`],queryFn:wd.getCaCertificate,staleTime:1/0}),[d,f]=(0,y.useState)(!1),p=async()=>{u&&(await T8(u.pem)?(f(!0),n(e(`virtualPrinter.caCert.copied`)),setTimeout(()=>f(!1),2e3)):n(e(`virtualPrinter.toast.copyFailed`),`error`))},m=()=>{u&&mGe(u.pem,`bambuddy-virtual-printer-ca.crt`,`application/x-pem-file`)};if(o)return(0,G.jsx)(zd,{children:(0,G.jsx)(Vd,{className:`py-8 flex justify-center`,children:(0,G.jsx)(Y,{className:`w-6 h-6 animate-spin text-bambu-green`})})});let h=a?.printers||[],g=a?.models||{};return(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-3 gap-4 items-stretch`,children:[(0,G.jsx)(zd,{className:`border-l-4 border-l-yellow-500`,children:(0,G.jsx)(Vd,{className:`py-3 px-4`,children:(0,G.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,G.jsx)(Lu,{className:`w-4 h-4 text-yellow-500 flex-shrink-0 mt-0.5`}),(0,G.jsxs)(`div`,{className:`text-xs`,children:[(0,G.jsx)(`p`,{className:`text-white font-medium`,children:e(`virtualPrinter.setupRequired.title`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:e(`virtualPrinter.setupRequired.description`)}),(0,G.jsxs)(`a`,{href:`https://wiki.bambuddy.cool/features/virtual-printer/`,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center gap-1.5 mt-2 px-3 py-1.5 bg-yellow-100 dark:bg-yellow-500/20 border border-yellow-500/50 rounded text-yellow-700 dark:text-yellow-400 hover:bg-yellow-500/30 transition-colors text-xs`,children:[(0,G.jsx)(rc,{className:`w-3 h-3`}),e(`virtualPrinter.setupRequired.readGuide`)]})]})]})})}),(0,G.jsx)(zd,{className:`lg:col-span-2`,children:(0,G.jsx)(Vd,{className:`py-3 px-4`,children:(0,G.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,G.jsx)(Wc,{className:`w-4 h-4 text-blue-600 dark:text-blue-400 flex-shrink-0 mt-0.5`}),(0,G.jsxs)(`div`,{className:`text-xs text-bambu-gray`,children:[(0,G.jsx)(`p`,{className:`text-white font-medium mb-1`,children:e(`virtualPrinter.howItWorks.title`)}),(0,G.jsxs)(`ul`,{className:`space-y-1 list-disc list-inside`,children:[(0,G.jsx)(`li`,{children:e(`virtualPrinter.howItWorks.step1`)}),(0,G.jsx)(`li`,{children:e(`virtualPrinter.howItWorks.step2`)}),(0,G.jsx)(`li`,{children:e(`virtualPrinter.howItWorks.step3`)})]})]})]})})})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-4 items-stretch`,children:[(0,G.jsx)(zd,{children:(0,G.jsx)(Vd,{className:`py-3 px-4`,children:(0,G.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,G.jsx)(au,{className:`w-4 h-4 text-bambu-green flex-shrink-0 mt-1`}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,G.jsx)(`p`,{className:`text-sm text-white font-medium`,children:e(`virtualPrinter.caCert.title`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[(0,G.jsxs)(`button`,{onClick:p,disabled:!u,className:`inline-flex items-center gap-1.5 px-2.5 py-1 text-xs rounded bg-bambu-dark-secondary border border-bambu-dark-tertiary text-white hover:border-bambu-gray disabled:opacity-50 transition-colors`,children:[d?(0,G.jsx)(fs,{className:`w-3.5 h-3.5 text-bambu-green`}):(0,G.jsx)(Vs,{className:`w-3.5 h-3.5`}),e(d?`virtualPrinter.caCert.copied`:`virtualPrinter.caCert.copy`)]}),(0,G.jsxs)(`button`,{onClick:m,disabled:!u,className:`inline-flex items-center gap-1.5 px-2.5 py-1 text-xs rounded bg-bambu-dark-secondary border border-bambu-dark-tertiary text-white hover:border-bambu-gray disabled:opacity-50 transition-colors`,children:[(0,G.jsx)(Xs,{className:`w-3.5 h-3.5`}),e(`virtualPrinter.caCert.download`)]})]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`virtualPrinter.caCert.description`)}),u&&(0,G.jsxs)(`p`,{className:`text-[10px] text-bambu-gray font-mono mt-1 truncate`,title:u.fingerprint_sha256,children:[e(`virtualPrinter.caCert.fingerprint`),`: `,u.fingerprint_sha256]})]})]})})}),(0,G.jsx)(zd,{children:(0,G.jsx)(Vd,{className:`py-3 px-4`,children:(0,G.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,G.jsx)(fc,{className:`w-4 h-4 text-bambu-green flex-shrink-0 mt-1`}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,G.jsx)(`p`,{className:`text-sm text-white font-medium`,children:e(`virtualPrinter.archiveNameSource.title`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[(0,G.jsx)(`span`,{className:`text-xs ${l?`text-bambu-gray`:`text-white`}`,children:e(`virtualPrinter.archiveNameSource.metadata`)}),(0,G.jsx)(fH,{checked:l,onChange:e=>c.mutate(e?`filename`:`metadata`),disabled:c.isPending}),(0,G.jsx)(`span`,{className:`text-xs ${l?`text-white`:`text-bambu-gray`}`,children:e(`virtualPrinter.archiveNameSource.filename`)})]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`virtualPrinter.archiveNameSource.description`)})]})]})})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Rl,{className:`w-5 h-5 text-bambu-green`}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`virtualPrinter.list.title`)}),(0,G.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[`(`,h.length,`)`]})]}),(0,G.jsxs)(Q,{variant:`primary`,onClick:()=>i(!0),children:[(0,G.jsx)(Fl,{className:`w-4 h-4 mr-1`}),e(`virtualPrinter.list.add`)]})]}),h.length===0?(0,G.jsx)(zd,{children:(0,G.jsxs)(Vd,{className:`py-8 text-center`,children:[(0,G.jsx)(Rl,{className:`w-12 h-12 text-bambu-gray mx-auto mb-3`}),(0,G.jsx)(`p`,{className:`text-bambu-gray mb-4`,children:e(`virtualPrinter.list.empty`)}),(0,G.jsxs)(Q,{variant:`primary`,onClick:()=>i(!0),children:[(0,G.jsx)(Fl,{className:`w-4 h-4 mr-1`}),e(`virtualPrinter.list.addFirst`)]})]})}):(0,G.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-4 items-start`,children:h.map(e=>(0,G.jsx)(_Ge,{printer:e,models:g},e.id))}),r&&(0,G.jsx)(vGe,{onClose:()=>i(!1)})]})}function k8(e){if(e<60)return`${e}s`;let t=Math.floor(e/60);if(t<60)return`${t}m`;let n=Math.floor(t/60),r=t%60;if(n<24)return r?`${n}h ${r}m`:`${n}h`;let i=Math.floor(n/24),a=n%24;return a?`${i}d ${a}h`:`${i}d`}function A8(e){return e==null?`—`:e>=1024?`${(e/1024).toFixed(1)} GB`:`${Math.round(e)} MB`}function bGe({device:e,onUnregister:t,isDeleting:n}){let{t:r}=U(),{showToast:i}=qd(),a=e.system_stats,o=a?.memory,s=a?.disk,c=e.online,[l,u]=(0,y.useState)(null),[d,f]=(0,y.useState)(null),p=async t=>{f(t);try{t===`update`?await Od.triggerUpdate(e.device_id):await Od.systemCommand(e.device_id,t),i(r(`settings.spoolbuddy.commandQueued`),`success`)}catch(e){i(e instanceof Error?e.message:r(`settings.spoolbuddy.commandError`),`error`)}finally{f(null),u(null)}},m=[{key:`update`,label:r(`settings.spoolbuddy.update`),icon:Xs},{key:`restart_browser`,label:r(`settings.spoolbuddy.restartBrowser`),icon:gl},{key:`restart_daemon`,label:r(`settings.spoolbuddy.restartDaemon`),icon:Hl},{key:`reboot`,label:r(`settings.spoolbuddy.reboot`),icon:Gl},{key:`shutdown`,label:r(`settings.spoolbuddy.shutdown`),icon:Ll,variant:`danger`}],h={update:r(`settings.spoolbuddy.updateConfirmTitle`),restart_browser:r(`settings.spoolbuddy.restartBrowserConfirmTitle`),restart_daemon:r(`settings.spoolbuddy.restartDaemonConfirmTitle`),reboot:r(`settings.spoolbuddy.rebootConfirmTitle`),shutdown:r(`settings.spoolbuddy.shutdownConfirmTitle`)},g={update:r(`settings.spoolbuddy.updateConfirmBody`,{hostname:e.hostname}),restart_browser:r(`settings.spoolbuddy.restartBrowserConfirmBody`,{hostname:e.hostname}),restart_daemon:r(`settings.spoolbuddy.restartDaemonConfirmBody`,{hostname:e.hostname}),reboot:r(`settings.spoolbuddy.rebootConfirmBody`,{hostname:e.hostname}),shutdown:r(`settings.spoolbuddy.shutdownConfirmBody`,{hostname:e.hostname})};return(0,G.jsxs)(zd,{children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`div`,{className:`flex items-start justify-between gap-3 flex-wrap`,children:[(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`h3`,{className:`text-base font-semibold text-white truncate`,children:e.hostname}),(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-medium ${c?`bg-green-500/15 text-green-400 border border-green-500/40`:`bg-gray-500/15 text-gray-400 border border-gray-500/40`}`,children:[c?(0,G.jsx)(Qu,{className:`w-3 h-3`}):(0,G.jsx)(Zu,{className:`w-3 h-3`}),r(c?`settings.spoolbuddy.online`:`settings.spoolbuddy.offline`)]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray font-mono mt-1 truncate`,children:e.device_id})]}),(0,G.jsxs)(Q,{variant:`danger`,size:`sm`,onClick:()=>t(e),disabled:n,"aria-label":r(`settings.spoolbuddy.unregister`),children:[(0,G.jsx)(Pu,{className:`w-3.5 h-3.5`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:r(`settings.spoolbuddy.unregister`)})]})]})}),(0,G.jsxs)(Vd,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{className:`grid grid-cols-2 sm:grid-cols-4 gap-3 text-xs`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`div`,{className:`text-bambu-gray`,children:r(`settings.spoolbuddy.ipAddress`)}),(0,G.jsx)(`div`,{className:`text-white font-mono`,children:e.ip_address})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`div`,{className:`text-bambu-gray`,children:r(`settings.spoolbuddy.firmware`)}),(0,G.jsx)(`div`,{className:`text-white`,children:e.firmware_version??`—`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`text-bambu-gray flex items-center gap-1`,children:[(0,G.jsx)(js,{className:`w-3 h-3`}),r(`settings.spoolbuddy.lastSeen`)]}),(0,G.jsx)(`div`,{className:`text-white`,children:e.last_seen?up(e.last_seen):r(`settings.spoolbuddy.never`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`div`,{className:`text-bambu-gray`,children:r(`settings.spoolbuddy.daemonUptime`)}),(0,G.jsx)(`div`,{className:`text-white`,children:k8(e.uptime_s)})]})]}),(0,G.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:m.map(({key:e,label:t,icon:n,variant:r})=>(0,G.jsxs)(Q,{variant:r??`secondary`,size:`sm`,onClick:()=>u(e),disabled:!c||d!==null,"aria-label":t,children:[d===e?(0,G.jsx)(Y,{className:`w-3.5 h-3.5 animate-spin`}):(0,G.jsx)(n,{className:`w-3.5 h-3.5`}),(0,G.jsx)(`span`,{children:t})]},e))}),(0,G.jsxs)(`div`,{className:`flex items-center gap-3 text-xs flex-wrap`,children:[(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-bambu-gray`,children:[e.nfc_ok?(0,G.jsx)(Ss,{className:`w-3.5 h-3.5 text-green-400`}):(0,G.jsx)(Ds,{className:`w-3.5 h-3.5 text-red-400`}),r(`settings.spoolbuddy.nfc`),e.nfc_reader_type&&(0,G.jsxs)(`span`,{className:`text-bambu-gray/70`,children:[`(`,e.nfc_reader_type,`)`]})]}),(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-bambu-gray`,children:[e.scale_ok?(0,G.jsx)(Ss,{className:`w-3.5 h-3.5 text-green-400`}):(0,G.jsx)(Ds,{className:`w-3.5 h-3.5 text-red-400`}),r(`settings.spoolbuddy.scale`)]})]}),a&&(0,G.jsxs)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-3 text-xs`,children:[a.cpu_temp_c!==void 0&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Mu,{className:`w-3.5 h-3.5 text-bambu-gray`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`div`,{className:`text-bambu-gray`,children:r(`settings.spoolbuddy.cpuTemp`)}),(0,G.jsxs)(`div`,{className:`text-white`,children:[a.cpu_temp_c.toFixed(1),`°C`]})]})]}),a.load_avg&&a.load_avg.length>0&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Mo,{className:`w-3.5 h-3.5 text-bambu-gray`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`div`,{className:`text-bambu-gray`,children:r(`settings.spoolbuddy.cpuLoad`)}),(0,G.jsxs)(`div`,{className:`text-white`,children:[a.load_avg[0].toFixed(2),a.cpu_count?` / ${a.cpu_count} (${Math.round(a.load_avg[0]/a.cpu_count*100)}%)`:``]})]})]}),o&&o.percent!==void 0&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Hs,{className:`w-3.5 h-3.5 text-bambu-gray`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`div`,{className:`text-bambu-gray`,children:r(`settings.spoolbuddy.memory`)}),(0,G.jsxs)(`div`,{className:`text-white`,children:[o.percent.toFixed(0),`% (`,A8(o.used_mb),` / `,A8(o.total_mb),`)`]})]})]}),s&&s.percent!==void 0&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Pc,{className:`w-3.5 h-3.5 text-bambu-gray`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`div`,{className:`text-bambu-gray`,children:r(`settings.spoolbuddy.disk`)}),(0,G.jsxs)(`div`,{className:`text-white`,children:[s.percent.toFixed(0),`% (`,s.used_gb?.toFixed(1),` / `,s.total_gb?.toFixed(1),` GB)`]})]})]}),a.system_uptime_s!==void 0&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(js,{className:`w-3.5 h-3.5 text-bambu-gray`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`div`,{className:`text-bambu-gray`,children:r(`settings.spoolbuddy.systemUptime`)}),(0,G.jsx)(`div`,{className:`text-white`,children:k8(a.system_uptime_s)})]})]})]}),a.os&&(0,G.jsx)(`div`,{className:`mt-3 text-xs text-bambu-gray font-mono truncate`,children:[a.os.os,a.os.kernel,a.os.arch,a.os.python&&`Python ${a.os.python}`].filter(Boolean).join(` · `)})]})]}),l&&(0,G.jsx)(of,{variant:l===`shutdown`||l===`reboot`?`danger`:`default`,title:h[l],message:g[l],confirmText:r(`settings.spoolbuddy.commandConfirm`),isLoading:d!==null,onConfirm:()=>p(l),onCancel:()=>u(null)})]})}function xGe(){let{t:e}=U(),t=co(),{showToast:n}=qd(),[r,i]=(0,y.useState)(null),{data:a=[],isLoading:o}=K({queryKey:[`spoolbuddy-devices`],queryFn:()=>Od.getDevices(),refetchInterval:15e3}),s=q({mutationFn:e=>Od.deleteDevice(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`spoolbuddy-devices`]}),n(e(`settings.spoolbuddy.unregisterSuccess`),`success`),i(null)},onError:t=>{n(t.message||e(`settings.spoolbuddy.unregisterError`),`error`)}});if(o)return(0,G.jsx)(zd,{children:(0,G.jsx)(Vd,{className:`py-8 flex justify-center`,children:(0,G.jsx)(Y,{className:`w-6 h-6 animate-spin text-bambu-green`})})});let c=a.length>1;return(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsx)(zd,{children:(0,G.jsx)(Vd,{className:`py-3 px-4`,children:(0,G.jsxs)(`div`,{className:`flex items-start gap-2 text-xs`,children:[(0,G.jsx)(Wc,{className:`w-4 h-4 text-blue-400 flex-shrink-0 mt-0.5`}),(0,G.jsxs)(`div`,{className:`text-bambu-gray`,children:[(0,G.jsx)(`p`,{className:`text-white font-medium mb-1`,children:e(`settings.spoolbuddy.infoTitle`)}),(0,G.jsx)(`p`,{children:e(`settings.spoolbuddy.infoBody`)})]})]})})}),c&&(0,G.jsx)(zd,{className:`border-l-4 border-l-yellow-500`,children:(0,G.jsx)(Vd,{className:`py-3 px-4`,children:(0,G.jsxs)(`div`,{className:`flex items-start gap-2 text-xs`,children:[(0,G.jsx)(Lu,{className:`w-4 h-4 text-yellow-500 flex-shrink-0 mt-0.5`}),(0,G.jsxs)(`div`,{className:`text-bambu-gray`,children:[(0,G.jsx)(`p`,{className:`text-white font-medium mb-1`,children:e(`settings.spoolbuddy.duplicatesTitle`,{count:a.length})}),(0,G.jsx)(`p`,{children:e(`settings.spoolbuddy.duplicatesBody`)})]})]})})}),a.length===0?(0,G.jsx)(zd,{children:(0,G.jsx)(Vd,{className:`py-8 text-center text-bambu-gray text-sm`,children:e(`settings.spoolbuddy.empty`)})}):(0,G.jsx)(`div`,{className:`space-y-3`,children:a.map(e=>(0,G.jsx)(bGe,{device:e,onUnregister:i,isDeleting:s.isPending&&s.variables===e.device_id},e.id))}),r&&(0,G.jsx)(of,{variant:`danger`,title:e(`settings.spoolbuddy.confirmTitle`),message:e(`settings.spoolbuddy.confirmBody`,{hostname:r.hostname,deviceId:r.device_id}),confirmText:e(`settings.spoolbuddy.unregister`),isLoading:s.isPending,onConfirm:()=>s.mutate(r.device_id),onCancel:()=>i(null)})]})}function j8(e,t,n,r,i){return n?e(`backup.restoreFromGit.${t}.${n}`,{...r??{},defaultValue:i??n}):i}var M8=[{id:`archives`,labelKey:`backup.printArchives`,icon:(0,G.jsx)(Po,{className:`w-4 h-4`})},{id:`spools`,labelKey:`backup.spoolInventory`,icon:(0,G.jsx)(wl,{className:`w-4 h-4`})},{id:`settings`,labelKey:`backup.appSettings`,icon:(0,G.jsx)(ru,{className:`w-4 h-4`})},{id:`kprofiles`,labelKey:`backup.kProfiles`,icon:(0,G.jsx)(Mu,{className:`w-4 h-4`})}],N8=Object.fromEntries(M8.map(e=>[e.id,e.labelKey])),P8=`HEAD`;function SGe({onClose:e}){let{t}=U(),n=co(),[r,i]=(0,y.useState)(P8),[a,o]=(0,y.useState)({}),[s,c]=(0,y.useState)(!1),[l,u]=(0,y.useState)(!1),[d,f]=(0,y.useState)(null),p=K({queryKey:[`github-backup-commits`],queryFn:()=>Z.getGitHubBackupCommits(20)}),m=K({queryKey:[`github-restore-preview`,r],queryFn:()=>Z.getGitHubRestorePreview(r)}),h=m.data?.success?m.data.ref:r,g=(0,y.useMemo)(()=>{let e={};return m.data?.categories?.forEach(n=>{e[n.category]={available:n.available,itemCount:n.item_count,detail:j8(t,`details`,n.detail_code,n.detail_params,n.detail)}}),e},[m.data,t]),_=(0,y.useMemo)(()=>M8.filter(e=>a[e.id]&&g[e.id]?.available).map(e=>e.id),[a,g]),v=_.length,b=!s&&_.includes(`kprofiles`),x=q({mutationFn:()=>Z.restoreFromGitHub({ref:h,categories:_,overwrite_existing:s}),onSuccess:e=>{u(!1);let t=Object.keys(e.results??{}).length>0;(e.success||t)&&(f(e),n.invalidateQueries({queryKey:[`spools`]}),n.invalidateQueries({queryKey:[`archives`]}),n.invalidateQueries({queryKey:[`settings`]})),n.invalidateQueries({queryKey:[`github-backup-logs`]}),n.invalidateQueries({queryKey:[`github-backup-status`]})},onError:()=>u(!1)}),S=x.isPending,C=!!(d&&`settings`in d.results),w=(0,y.useCallback)(()=>{if(C){window.location.reload();return}e()},[C,e]);(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&!S&&!l&&w()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[w,S,l]),(0,y.useEffect)(()=>{if(!S)return;let e=e=>{e.preventDefault(),e.returnValue=``};return window.addEventListener(`beforeunload`,e),()=>window.removeEventListener(`beforeunload`,e)},[S]),(0,y.useEffect)(()=>{m.data&&o(e=>{let t={};return M8.forEach(n=>{t[n.id]=!!e[n.id]&&!!g[n.id]?.available}),t})},[m.data,g]);let T=p.data?.commits??[],E=(e,t,n)=>{let r=(t||``).split(` -`)[0],i=n?new Date(n).toLocaleString():``;return`${e.slice(0,7)} — ${i}${r?` — ${r}`:``}`},D=e=>e.isError?e.error?.message||t(`backup.restoreFromGit.loadFailed`):null,O=D(m)??(m.data&&!m.data.success?m.data.message:null),k=D(p)??(p.data&&!p.data.success?p.data.message:null);return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,onClick:S?void 0:w,children:(0,G.jsx)(zd,{className:`w-full max-w-lg`,onClick:e=>e.stopPropagation(),children:(0,G.jsxs)(Vd,{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-3`,children:[(0,G.jsx)(`div`,{className:`p-2 rounded-full bg-bambu-green/20 text-bambu-green`,children:(0,G.jsx)(Wl,{className:`w-5 h-5`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`text-lg font-semibold text-white`,children:t(`backup.restoreFromGit.title`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:t(`backup.restoreFromGit.subtitle`)})]})]}),(0,G.jsx)(`button`,{onClick:w,disabled:S,"aria-label":t(`common.close`),className:`p-2 hover:bg-bambu-dark-tertiary rounded-lg transition-colors disabled:opacity-50`,children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]}),d?(0,G.jsxs)(`div`,{className:`p-4 space-y-3 max-h-[400px] overflow-y-auto`,children:[(0,G.jsxs)(`div`,{className:`flex items-start gap-2 text-sm`,children:[d.success?(0,G.jsx)(Ss,{className:`w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0`}):(0,G.jsx)(Lu,{className:`w-4 h-4 text-yellow-500 mt-0.5 flex-shrink-0`}),(0,G.jsx)(`span`,{className:`text-white`,children:d.message})]}),!d.success&&(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:t(`backup.restoreFromGit.partialHint`)}),Object.entries(d.results).map(([e,n])=>(0,G.jsxs)(`div`,{className:`p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`span`,{className:`text-sm font-medium text-white`,children:N8[e]?t(N8[e]):e}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:t(`backup.restoreFromGit.tally`,{restored:n.restored,skipped:n.skipped,failed:n.failed})})]}),n.notes.length>0&&(0,G.jsx)(`ul`,{className:`mt-2 space-y-1`,children:n.notes.map(e=>(0,G.jsxs)(`li`,{className:`text-xs text-bambu-gray flex items-start gap-1.5`,children:[(0,G.jsx)(Wc,{className:`w-3 h-3 mt-0.5 flex-shrink-0`}),(0,G.jsx)(`span`,{children:j8(t,`notes`,e.code,e.params,e.message)})]},`${e.code}:${JSON.stringify(e.params)}`))})]},e)),(0,G.jsx)(`div`,{className:`p-3 rounded-lg bg-yellow-50 dark:bg-yellow-500/10 border border-yellow-300 dark:border-yellow-500/30`,children:(0,G.jsx)(`p`,{className:`text-xs text-yellow-700 dark:text-yellow-200`,children:t(`backup.restoreFromGit.reloadHint`)})})]}):(0,G.jsxs)(`div`,{className:`p-4 space-y-4 max-h-[400px] overflow-y-auto ${S?`opacity-50 pointer-events-none`:``}`,children:[x.isError&&(0,G.jsx)(`div`,{className:`p-3 rounded-lg bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30`,children:(0,G.jsx)(`p`,{className:`text-sm text-red-700 dark:text-red-400`,children:x.error?.message||t(`backup.restoreFromGit.failed`)})}),x.data&&!x.data.success&&(0,G.jsx)(`div`,{className:`p-3 rounded-lg bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30`,children:(0,G.jsx)(`p`,{className:`text-sm text-red-700 dark:text-red-400`,children:x.data.message})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{htmlFor:`restore-commit`,className:`block text-sm font-medium text-white mb-1`,children:t(`backup.restoreFromGit.commitLabel`)}),(0,G.jsxs)(`select`,{id:`restore-commit`,value:r,onChange:e=>{i(e.target.value),x.reset()},disabled:S||p.isLoading,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`,children:[(0,G.jsx)(`option`,{value:P8,children:t(`backup.restoreFromGit.latestCommit`)}),T.map(e=>(0,G.jsx)(`option`,{value:e.sha,children:E(e.sha,e.message,e.date)},e.sha))]}),k&&(0,G.jsx)(`p`,{className:`mt-1 text-xs text-red-500 dark:text-red-400`,children:k})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm font-medium text-white mb-2`,children:t(`backup.restoreFromGit.categoriesLabel`)}),m.isLoading?(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-bambu-gray p-3`,children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),t(`backup.restoreFromGit.inspecting`)]}):O?(0,G.jsx)(`div`,{className:`p-3 rounded-lg bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30`,children:(0,G.jsx)(`p`,{className:`text-sm text-red-700 dark:text-red-400`,children:O})}):(0,G.jsx)(`div`,{className:`space-y-2`,children:M8.map(e=>{let n=g[e.id],r=!!n?.available,i=!!a[e.id]&&r;return(0,G.jsxs)(`label`,{className:`flex items-center gap-3 p-3 rounded-lg transition-colors ${r?`cursor-pointer`:`cursor-not-allowed opacity-50`} ${i?`bg-bambu-green/10 border border-bambu-green/30`:`bg-bambu-dark hover:bg-bambu-dark-tertiary border border-transparent`}`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:i,disabled:!r||S,onChange:()=>o(t=>({...t,[e.id]:!t[e.id]})),className:`w-4 h-4 rounded border-bambu-gray bg-bambu-dark text-bambu-green focus:ring-bambu-green focus:ring-offset-0`}),(0,G.jsx)(`div`,{className:i?`text-bambu-green`:`text-bambu-gray`,children:e.icon}),(0,G.jsxs)(`div`,{className:`flex-1`,children:[(0,G.jsxs)(`div`,{className:`text-white text-sm font-medium`,children:[t(e.labelKey),r&&n?.itemCount?(0,G.jsx)(`span`,{className:`ml-2 text-xs text-bambu-gray`,children:t(`backup.restoreFromGit.itemCount`,{count:n.itemCount})}):null]}),n?.detail&&(0,G.jsx)(`div`,{className:`text-xs text-bambu-gray`,children:n.detail}),e.id===`kprofiles`&&i&&b&&(0,G.jsx)(`div`,{className:`text-xs text-yellow-700 dark:text-yellow-200`,children:t(`backup.restoreFromGit.kprofilesOverwriteCaveat`)})]})]},e.id)})})]}),(0,G.jsx)(`div`,{className:`p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm font-medium text-white`,children:t(`backup.restoreFromGit.overwriteLabel`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:t(s?`backup.restoreFromGit.overwriteOn`:`backup.restoreFromGit.overwriteOff`)})]}),(0,G.jsx)(fH,{checked:s,onChange:c,disabled:S})]})})]}),(0,G.jsx)(`div`,{className:`flex items-center justify-between p-4 border-t border-bambu-dark-tertiary`,children:d?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`span`,{}),(0,G.jsxs)(`div`,{className:`flex gap-3`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:w,children:t(`common.close`)}),(0,G.jsx)(Q,{onClick:()=>window.location.reload(),className:`bg-bambu-green hover:bg-bambu-green-dark`,children:t(`backup.reloadNow`)})]})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:t(`backup.restoreFromGit.selectedCount`,{count:v})}),(0,G.jsxs)(`div`,{className:`flex gap-3`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:w,disabled:S,children:t(`common.cancel`)}),(0,G.jsx)(Q,{onClick:()=>u(!0),disabled:v===0||S,className:`bg-bambu-green hover:bg-bambu-green-dark disabled:opacity-50 disabled:cursor-not-allowed min-w-[100px]`,children:S?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 mr-2 animate-spin`}),t(`backup.restoreFromGit.restoring`)]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Wl,{className:`w-4 h-4 mr-2`}),t(`backup.restore`)]})})]})]})})]})})}),l&&(0,G.jsx)(of,{variant:`danger`,overlayZIndex:`z-[110]`,title:t(`backup.restoreFromGit.confirmTitle`),message:s?t(`backup.restoreFromGit.confirmMessageOverwrite`):b?`${t(`backup.restoreFromGit.confirmMessage`)} ${t(`backup.restoreFromGit.kprofilesOverwriteCaveat`)}`:t(`backup.restoreFromGit.confirmMessage`),confirmText:t(`backup.restore`),isLoading:S,loadingText:t(`backup.restoreFromGit.restoring`),onConfirm:()=>x.mutate(),onCancel:()=>u(!1)})]})}function F8(e){if(!e)return`-`;let t=rp(e);return t?t.toLocaleString():`-`}function I8({status:e}){if(!e)return null;let t={success:`bg-green-100 dark:bg-green-500/20 text-green-700 dark:text-green-400`,failed:`bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400`,skipped:`bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400`,running:`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`},n={success:(0,G.jsx)(xs,{className:`w-3 h-3`}),failed:(0,G.jsx)(Ds,{className:`w-3 h-3`}),skipped:(0,G.jsx)(du,{className:`w-3 h-3`}),running:(0,G.jsx)(Y,{className:`w-3 h-3 animate-spin`})};return(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded text-xs font-medium ${t[e]||`bg-gray-500/20 text-gray-400`}`,children:[n[e],e.charAt(0).toUpperCase()+e.slice(1)]})}var CGe={github:`backup.repoUrlPlaceholderGitHub`,gitea:`backup.repoUrlPlaceholderGitea`,forgejo:`backup.repoUrlPlaceholderForgejo`,gitlab:`backup.repoUrlPlaceholderGitLab`},wGe={github:`ghp_xxxxxxxxxxxx`,gitea:`your_access_token`,forgejo:`your_access_token`,gitlab:`glpat-xxxxxxxxxxxx`},TGe={github:`backup.tokenHintGitHub`,gitea:`backup.tokenHintGitea`,forgejo:`backup.tokenHintForgejo`,gitlab:`backup.tokenHintGitLab`};function L8(e){return JSON.stringify(e)}function EGe(e,t){if(!t)return e;let n={};for(let r of Object.keys(e))e[r]!==t[r]&&(n[r]=e[r]);return n}function DGe(){let e=co(),{showToast:t}=qd(),{t:n}=U(),{hasPermission:r}=Nd(),i=r(`github:restore`),[a,o]=(0,y.useState)(``),[s,c]=(0,y.useState)(``),[l,u]=(0,y.useState)(`main`),[d,f]=(0,y.useState)(`github`),[p,m]=(0,y.useState)(!1),[h,g]=(0,y.useState)(`daily`),[_,v]=(0,y.useState)(!0),[b,x]=(0,y.useState)(!0),[S,C]=(0,y.useState)(!1),[w,T]=(0,y.useState)(!1),[E,D]=(0,y.useState)(!1),[O,k]=(0,y.useState)(!1),[A,j]=(0,y.useState)(!0),[M,N]=(0,y.useState)(!1),[P,F]=(0,y.useState)(!1),[I,L]=(0,y.useState)(``),[R,z]=(0,y.useState)(!1),[B,V]=(0,y.useState)(null),[ee,te]=(0,y.useState)(null),ne=(0,y.useRef)(null),[re,ie]=(0,y.useState)(!1),[ae,oe]=(0,y.useState)(null),[se,H]=(0,y.useState)(null),[ce,le]=(0,y.useState)(``),{data:ue,refetch:de}=K({queryKey:[`local-backup-status`],queryFn:Z.getLocalBackupStatus,refetchInterval:e=>e.state.data?.is_running?1e3:1e4}),{data:fe,refetch:pe}=K({queryKey:[`local-backup-files`],queryFn:Z.getLocalBackups,refetchInterval:3e4}),{data:me,refetch:he}=K({queryKey:[`local-backup-path-check`],queryFn:Z.checkLocalBackupPath,enabled:ue?.enabled===!0,refetchOnWindowFocus:!1});(0,y.useEffect)(()=>{ue?.path!==void 0&&le(ue.path)},[ue?.path]);let ge=q({mutationFn:Z.triggerLocalBackup,onSuccess:e=>{e.success?t(n(`backup.scheduledBackupComplete`)):t(e.message,`error`),de(),pe(),he()},onError:()=>t(n(`backup.scheduledBackupFailed`),`error`)}),_e=q({mutationFn:e=>Z.deleteLocalBackup(e),onSuccess:()=>{pe(),oe(null)}}),ve=q({mutationFn:async e=>(H(null),F(!0),te(null),L(n(`backup.restoring`)),Z.restoreLocalBackup(e)),onSuccess:e=>{F(!1),L(``),e.success?(te({success:!0,message:e.message}),t(n(`backup.backupRestoredRestart`),`success`)):(te({success:!1,message:e.message}),t(e.message,`error`))},onError:e=>{F(!1),L(``);let r=e instanceof Error?e.message:n(`backup.failedToRestore`);te({success:!1,message:r}),t(r,`error`)}});(0,y.useEffect)(()=>{if(M||P){let e=e=>(e.preventDefault(),e.returnValue=`A backup operation is in progress. Are you sure you want to leave?`,e.returnValue);return window.addEventListener(`beforeunload`,e),()=>window.removeEventListener(`beforeunload`,e)}},[M,P]);let[ye,be]=(0,y.useState)(!1),[xe,Se]=(0,y.useState)(null),[Ce,we]=(0,y.useState)(null),Te=(0,y.useRef)(null),Ee=(0,y.useRef)(null),De=(0,y.useRef)(null),Oe=(0,y.useRef)(null),ke=(0,y.useRef)(``),[Ae,je]=(0,y.useState)(!1),Me=(0,y.useMemo)(()=>({repository_url:a,branch:l,provider:d,allow_insecure_http:O,schedule_enabled:p,schedule_type:h,backup_kprofiles:_,backup_cloud_profiles:b,backup_settings:S,backup_spools:w,backup_archives:E,enabled:A}),[a,l,d,O,p,h,_,b,S,w,E,A]),Ne=(0,y.useMemo)(()=>L8(Me),[Me]),{data:Pe,isLoading:Fe}=K({queryKey:[`github-backup-config`],queryFn:Z.getGitHubBackupConfig}),{data:Ie}=K({queryKey:[`github-backup-status`],queryFn:Z.getGitHubBackupStatus,refetchInterval:e=>e.state.data?.is_running?500:1e4}),{data:Le}=K({queryKey:[`github-backup-logs`],queryFn:()=>Z.getGitHubBackupLogs(20)}),{data:Re}=K({queryKey:[`cloud-status`],queryFn:Z.getCloudStatus}),{data:ze}=K({queryKey:[`github-backup-cloud-accounts`],queryFn:Z.getGitHubBackupCloudAccounts,staleTime:6e4}),Be=(ze?.bambu??0)+(ze?.orca??0),Ve=ze?Be>0:!!Re?.is_authenticated,{data:He}=K({queryKey:[`printers`],queryFn:Z.getPrinters}),Ue=Co({queries:(He??[]).map(e=>({queryKey:[`printerStatus`,e.id],queryFn:()=>Z.getPrinterStatus(e.id),staleTime:1e4,refetchInterval:3e4}))}),We=(He??[]).map((e,t)=>({printer:e,connected:Ue[t]?.data?.connected??!1})),Ge=We.length,Ke=We.filter(e=>e.connected).length,qe=Ge>0&&Ke===0,Je=Ke>0&&Ke(De.current&&clearTimeout(De.current),Pe?(je(!1),Oe.current={repository_url:Pe.repository_url,branch:Pe.branch,provider:Pe.provider??`github`,allow_insecure_http:Pe.allow_insecure_http??!1,schedule_enabled:Pe.schedule_enabled,schedule_type:Pe.schedule_type,backup_kprofiles:Pe.backup_kprofiles,backup_cloud_profiles:Pe.backup_cloud_profiles,backup_settings:Pe.backup_settings,backup_spools:Pe.backup_spools,backup_archives:Pe.backup_archives,enabled:Pe.enabled},o(Pe.repository_url),u(Pe.branch),f(Pe.provider??`github`),m(Pe.schedule_enabled),g(Pe.schedule_type),v(Pe.backup_kprofiles),x(Pe.backup_cloud_profiles),C(Pe.backup_settings),T(Pe.backup_spools),D(Pe.backup_archives),k(Pe.allow_insecure_http??!1),j(Pe.enabled),c(``),De.current=setTimeout(()=>{je(!0)},100)):(je(!1),Oe.current=null,c(``)),()=>{De.current&&clearTimeout(De.current)}),[Pe]);let Ye=(0,y.useCallback)(async(r=!1)=>{if(Pe)try{r&&s?(await Z.saveGitHubBackupConfig({...Me,access_token:s}),c(``),we(null),t(n(`backup.tokenUpdated`)),ke.current=``):(await Z.updateGitHubBackupConfig(EGe(Me,Oe.current)),we(null),t(n(`backup.settingsSaved`))),Oe.current=Me,e.invalidateQueries({queryKey:[`github-backup-config`]}),e.invalidateQueries({queryKey:[`github-backup-status`]})}catch(e){we(e.message)}},[Pe,s,Me,e,t,n]),Xe=(0,y.useRef)(Ye);(0,y.useEffect)(()=>{Xe.current=Ye},[Ye]),(0,y.useEffect)(()=>{if(!(!Ae||!Pe)&&!(Oe.current&&Ne===L8(Oe.current)))return Te.current&&clearTimeout(Te.current),Te.current=setTimeout(()=>{Ye(!1)},500),()=>{Te.current&&clearTimeout(Te.current)}},[Ae,Pe,Ne,Ye]),(0,y.useEffect)(()=>{if(!(!Ae||!Pe||!s)&&s!==ke.current)return ke.current=s,Ee.current&&clearTimeout(Ee.current),Ee.current=setTimeout(()=>{Xe.current(!0)},1e3),()=>{Ee.current&&clearTimeout(Ee.current)}},[Ae,s,Pe]);let Ze=q({mutationFn:e=>Z.saveGitHubBackupConfig(e),onMutate:()=>{we(null)},onSuccess:()=>{e.invalidateQueries({queryKey:[`github-backup-config`]}),e.invalidateQueries({queryKey:[`github-backup-status`]}),t(n(`backup.githubBackupEnabled`)),c(``),je(!0)},onError:e=>{we(e.message)}}),Qe=q({mutationFn:Z.triggerGitHubBackup,onSuccess:r=>{e.invalidateQueries({queryKey:[`github-backup-status`]}),e.invalidateQueries({queryKey:[`github-backup-logs`]}),r.success?r.files_changed>0?t(n(`backup.backupCompleteFiles`,{count:r.files_changed})):t(n(`backup.backupSkippedNoChanges`)):t(n(`backup.backupFailed2`,{message:r.message}),`error`)},onError:e=>{t(n(`backup.backupFailed2`,{message:e.message}),`error`)}}),$e=q({mutationFn:()=>Z.clearGitHubBackupLogs(0),onSuccess:r=>{e.invalidateQueries({queryKey:[`github-backup-logs`]}),t(n(`backup.clearedLogs`,{count:r.deleted}))},onError:e=>{t(n(`backup.failedToClearLogs`,{message:e.message}),`error`)}}),et=async()=>{be(!0),Se(null);try{let e;if(s){if(!a){t(n(`backup.enterRepoUrl`),`error`),be(!1);return}e=await Z.testGitHubConnection(a,s,d)}else if(Pe?.has_token)e=await Z.testGitHubStoredConnection();else{t(n(`backup.enterRepoAndToken`),`error`),be(!1);return}Se({success:e.success,message:e.message,isPrivate:e.is_private})}catch(e){Se({success:!1,message:e.message,isPrivate:null})}finally{be(!1)}};return Fe?(0,G.jsx)(`div`,{className:`flex items-center justify-center py-12`,children:(0,G.jsx)(Y,{className:`w-8 h-8 animate-spin text-bambu-green`})}):(0,G.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-6`,children:[(0,G.jsxs)(`div`,{className:`space-y-6`,children:[(0,G.jsxs)(zd,{id:`card-backup-github`,children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(kc,{className:`w-5 h-5 text-gray-400`}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:n(`backup.githubBackup`)})]}),Pe&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:n(`backup.enabled`)}),(0,G.jsx)(fH,{checked:A,onChange:j})]})]})}),(0,G.jsxs)(Vd,{className:`space-y-4`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`backup.githubDescription`)}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{htmlFor:`git-provider-select`,className:`block text-sm text-bambu-gray mb-1`,children:n(`backup.provider`)}),(0,G.jsxs)(`select`,{id:`git-provider-select`,value:d,onChange:e=>{f(e.target.value),Se(null),we(null)},className:`w-full h-10 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,G.jsx)(`option`,{value:`github`,children:n(`backup.providerGitHub`)}),(0,G.jsx)(`option`,{value:`gitlab`,children:n(`backup.providerGitLab`)}),(0,G.jsx)(`option`,{value:`gitea`,children:n(`backup.providerGitea`)}),(0,G.jsx)(`option`,{value:`forgejo`,children:n(`backup.providerForgejo`)})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`backup.repositoryUrl`)}),(0,G.jsx)(`input`,{type:`text`,value:a,onChange:e=>{o(e.target.value),Se(null),we(null)},placeholder:n(CGe[d]),className:`w-full h-10 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,G.jsxs)(`label`,{className:`flex items-start gap-2 mt-2 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:O,onChange:e=>{k(e.target.checked),Se(null)},className:`w-4 h-4 mt-0.5 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-sm text-white`,children:n(`backup.allowInsecureHttp`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`backup.allowInsecureHttpHint`)})]})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[n(`backup.personalAccessToken`),` `,Pe?.has_token&&(0,G.jsx)(`span`,{className:`text-green-700 dark:text-green-400`,children:n(`backup.tokenSaved`)})]}),(0,G.jsx)(`input`,{type:`password`,value:s,onChange:e=>{c(e.target.value),Se(null),we(null)},placeholder:Pe?.has_token?n(`backup.enterNewToken`):wGe[d],className:`w-full h-10 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(TGe[d])})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`backup.branch`)}),(0,G.jsx)(`input`,{type:`text`,value:l,onChange:e=>u(e.target.value),placeholder:`main`,className:`w-full h-10 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`backup.autoBackup`)}),(0,G.jsxs)(`select`,{value:p?h:`disabled`,onChange:e=>{e.target.value===`disabled`?m(!1):(m(!0),g(e.target.value))},className:`w-full h-10 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,G.jsx)(`option`,{value:`disabled`,children:n(`backup.manualOnly`)}),(0,G.jsx)(`option`,{value:`hourly`,children:n(`backup.hourly`)}),(0,G.jsx)(`option`,{value:`daily`,children:n(`backup.daily`)}),(0,G.jsx)(`option`,{value:`weekly`,children:n(`backup.weekly`)})]})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-2`,children:n(`backup.includeInBackup`)}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsxs)(`label`,{className:`flex items-start gap-2 ${qe?`cursor-not-allowed opacity-60`:`cursor-pointer`}`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:_,onChange:e=>v(e.target.checked),className:`w-4 h-4 mt-0.5 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`,disabled:qe}),(0,G.jsxs)(`div`,{className:`flex-1`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-sm ${qe?`text-bambu-gray`:`text-white`}`,children:n(`backup.kProfiles`)}),qe&&(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-xs bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400`,children:[(0,G.jsx)(Lu,{className:`w-3 h-3`}),n(`backup.noPrintersConnected`)]}),Je&&(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-xs bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400`,children:[(0,G.jsx)(Lu,{className:`w-3 h-3`}),n(`backup.printersConnected`,{connected:Ke,total:Ge})]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`backup.kProfilesDescription`)})]})]}),(0,G.jsxs)(`label`,{className:`flex items-start gap-2 ${Ve?`cursor-pointer`:`cursor-not-allowed opacity-60`}`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:b,onChange:e=>x(e.target.checked),className:`w-4 h-4 mt-0.5 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`,disabled:!Ve}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-sm ${Ve?`text-white`:`text-bambu-gray`}`,children:n(`backup.cloudProfiles`)}),!Ve&&(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-xs bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400`,children:[(0,G.jsx)(Lu,{className:`w-3 h-3`}),n(`backup.cloudLoginRequiredShort`)]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`backup.cloudProfilesDescription`)}),Be>0&&(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:n(`backup.cloudProfilesAccounts`,{bambu:ze?.bambu??0,orca:ze?.orca??0})})]})]}),(0,G.jsxs)(`label`,{className:`flex items-start gap-2 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:S,onChange:e=>C(e.target.checked),className:`w-4 h-4 mt-0.5 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-white text-sm`,children:n(`backup.appSettings`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`backup.appSettingsDescription`)})]})]}),(0,G.jsxs)(`label`,{className:`flex items-start gap-2 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:w,onChange:e=>T(e.target.checked),className:`w-4 h-4 mt-0.5 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-white text-sm`,children:n(`backup.spoolInventory`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`backup.spoolInventoryDescription`)})]})]}),(0,G.jsxs)(`label`,{className:`flex items-start gap-2 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:E,onChange:e=>D(e.target.checked),className:`w-4 h-4 mt-0.5 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-white text-sm`,children:n(`backup.printArchives`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`backup.printArchivesDescription`)})]})]})]})]}),(0,G.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary pt-4 space-y-3`,children:[Ie?.configured&&(0,G.jsxs)(`div`,{className:`flex items-center justify-between text-sm`,children:[(0,G.jsx)(`div`,{className:`flex items-center gap-2 text-bambu-gray`,children:Ie.last_backup_at?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`span`,{children:[n(`backup.lastBackupAt`),` `,up(Ie.last_backup_at,`system`,n)]}),(0,G.jsx)(I8,{status:Ie.last_backup_status})]}):(0,G.jsx)(`span`,{children:n(`backup.noBackupsYet`)})}),Ie.next_scheduled_run&&(0,G.jsxs)(`span`,{className:`text-bambu-gray`,children:[(0,G.jsx)(js,{className:`w-3 h-3 inline mr-1`}),n(`backup.next`),` `,up(Ie.next_scheduled_run,`system`,n)]})]}),Ce&&(0,G.jsxs)(`div`,{className:`text-sm text-red-700 dark:text-red-400 bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30 rounded p-3 flex items-start gap-2`,children:[(0,G.jsx)(Ds,{className:`w-4 h-4 mt-0.5 shrink-0`}),(0,G.jsx)(`div`,{className:`flex-1 leading-relaxed whitespace-pre-wrap break-words`,children:Ce}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>we(null),className:`text-bambu-gray hover:text-white shrink-0`,"aria-label":n(`common.dismiss`,`Dismiss`),children:(0,G.jsx)(Ds,{className:`w-4 h-4`})})]}),xe&&(0,G.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,G.jsxs)(`div`,{className:`text-sm flex items-center gap-1 ${xe.success?`text-green-700 dark:text-green-400`:`text-red-700 dark:text-red-400`}`,children:[xe.success?(0,G.jsx)(xs,{className:`w-4 h-4`}):(0,G.jsx)(Ds,{className:`w-4 h-4`}),xe.message]}),xe.success&&xe.isPrivate===!0&&(0,G.jsxs)(`div`,{className:`text-xs flex items-center gap-1 text-green-700 dark:text-green-400`,children:[(0,G.jsx)(xs,{className:`w-3.5 h-3.5`}),n(`backup.repoIsPrivate`,`Repository is private — safe to back up to.`)]}),xe.success&&xe.isPrivate===!1&&(0,G.jsxs)(`div`,{className:`text-xs text-red-700 dark:text-red-400 bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30 rounded p-2 flex items-start gap-1.5`,children:[(0,G.jsx)(Ds,{className:`w-4 h-4 mt-0.5 shrink-0`}),(0,G.jsx)(`span`,{children:n(`backup.repoIsPublicWarning`,`Repository is PUBLIC. Bambuddy backups include MQTT credentials, Home Assistant tokens, Prometheus tokens, your Bambu Cloud email, and printer access codes via K-profiles. Saving is blocked until you make the repository private in your provider's settings.`)})]}),xe.success&&xe.isPrivate===null&&(0,G.jsxs)(`div`,{className:`text-xs text-yellow-700 dark:text-yellow-400 bg-yellow-50 dark:bg-yellow-500/10 border border-yellow-300 dark:border-yellow-500/30 rounded p-2 flex items-start gap-1.5`,children:[(0,G.jsx)(Ds,{className:`w-4 h-4 mt-0.5 shrink-0`}),(0,G.jsx)(`span`,{children:n(`backup.repoVisibilityUnknown`,`Could not determine repository visibility. Bambuddy refuses to back up to anything not confirmed private; saving will be blocked.`)})]})]}),(0,G.jsx)(`div`,{className:`flex flex-wrap items-center gap-2`,children:Ie?.configured?(0,G.jsx)(G.Fragment,{children:Qe.isPending||Ie.is_running?(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-green`,children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),(0,G.jsx)(`span`,{className:`text-sm`,children:Ie.progress||n(`backup.startingBackup`)})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(Q,{variant:`primary`,size:`sm`,onClick:()=>Qe.mutate(),disabled:!Pe?.enabled,children:[(0,G.jsx)(Nl,{className:`w-4 h-4`}),n(`backup.backupNow`)]}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:et,disabled:ye,children:[ye?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Hl,{className:`w-4 h-4`}),n(`backup.test`)]}),i&&(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:()=>ie(!0),disabled:Ie.restore_running,children:[(0,G.jsx)(Wl,{className:`w-4 h-4`}),n(`backup.restoreFromGit.button`)]})]})}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(Q,{variant:`primary`,size:`sm`,onClick:()=>{if(!a){t(n(`backup.repoRequired`),`error`);return}if(!s){t(n(`backup.tokenRequired`),`error`);return}Ze.mutate({repository_url:a,access_token:s,branch:l,provider:d,allow_insecure_http:O,schedule_enabled:p,schedule_type:h,backup_kprofiles:_,backup_cloud_profiles:b,backup_settings:S,backup_spools:w,backup_archives:E,enabled:A})},disabled:Ze.isPending||!a||!s,children:[Ze.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(xs,{className:`w-4 h-4`}),n(`backup.enableBackup`)]}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:et,disabled:ye||!a||!s,children:[ye?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Hl,{className:`w-4 h-4`}),n(`backup.testConnection`)]})]})})]})]})]}),Le&&Le.length>0&&(0,G.jsxs)(zd,{id:`card-backup-history`,children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(zc,{className:`w-5 h-5 text-gray-400`}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:n(`backup.history`)})]}),(0,G.jsxs)(Q,{variant:`ghost`,size:`sm`,onClick:()=>$e.mutate(),disabled:$e.isPending,children:[(0,G.jsx)(Pu,{className:`w-4 h-4`}),n(`backup.clear`)]})]})}),(0,G.jsx)(Vd,{children:(0,G.jsx)(`div`,{className:`overflow-x-auto`,children:(0,G.jsxs)(`table`,{className:`w-full text-sm`,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-2 px-2`,children:n(`backup.date`)}),(0,G.jsx)(`th`,{className:`text-left py-2 px-2`,children:n(`backup.trigger`)}),(0,G.jsx)(`th`,{className:`text-left py-2 px-2`,children:n(`backup.status`)}),(0,G.jsx)(`th`,{className:`text-left py-2 px-2`,children:n(`backup.commit`)})]})}),(0,G.jsx)(`tbody`,{children:Le.slice(0,10).map(e=>(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/50 hover:bg-bambu-dark-secondary`,children:[(0,G.jsx)(`td`,{className:`py-2 px-2 text-white`,children:F8(e.started_at)}),(0,G.jsx)(`td`,{className:`py-2 px-2 text-bambu-gray`,children:n(`backup.triggers.${e.trigger}`,{defaultValue:e.trigger})}),(0,G.jsx)(`td`,{className:`py-2 px-2`,children:(0,G.jsx)(I8,{status:e.status})}),(0,G.jsx)(`td`,{className:`py-2 px-2`,children:e.commit_sha?(0,G.jsxs)(`a`,{href:`${Pe?.repository_url}/commit/${e.commit_sha}`,target:`_blank`,rel:`noopener noreferrer`,className:`text-bambu-green hover:underline inline-flex items-center gap-1`,children:[e.commit_sha.substring(0,7),(0,G.jsx)(rc,{className:`w-3 h-3`})]}):(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:`-`})})]},e.id))})]})})})]})]}),(0,G.jsxs)(`div`,{className:`space-y-6`,children:[(0,G.jsxs)(zd,{id:`card-backup-local`,children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Gs,{className:`w-5 h-5 text-gray-400`}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:n(`backup.localBackup`)})]})}),(0,G.jsxs)(Vd,{className:`space-y-4`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`backup.localBackupDescription`)}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between py-3 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:n(`backup.downloadBackupLabel`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`backup.completeBackupZip`)})]}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,disabled:M||P,onClick:async()=>{N(!0),L(n(`backup.preparingBackup`));try{L(n(`backup.creatingArchive`));let{blob:e,filename:r}=await Z.exportBackup();L(n(`backup.downloadingFile`));let i=URL.createObjectURL(e),a=document.createElement(`a`);a.href=i,a.download=r,a.click(),URL.revokeObjectURL(i),t(n(`backup.backupDownloaded`))}catch(e){t(n(`backup.failedToCreateBackup`,{message:e instanceof Error?e.message:`Unknown error`}),`error`)}finally{N(!1),L(``)}},children:[(0,G.jsx)(Xs,{className:`w-4 h-4`}),n(`backup.download`)]})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between py-3 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:n(`backup.restoreBackup`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`backup.restoreDescription`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray-light mt-1`,children:n(`backup.restoreNote`)})]}),(0,G.jsx)(`input`,{ref:ne,type:`file`,accept:`.zip`,className:`hidden`,onChange:e=>{let t=e.target.files?.[0];t&&(V(t),z(!0)),e.target.value=``}}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,disabled:P||M,onClick:()=>ne.current?.click(),children:[(0,G.jsx)(Vu,{className:`w-4 h-4`}),n(`backup.restore`)]})]}),ee&&(0,G.jsx)(`div`,{className:`p-3 rounded-lg ${ee.success?`bg-green-50 dark:bg-green-500/10 border border-green-300 dark:border-green-500/30`:`bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30`}`,children:(0,G.jsxs)(`div`,{className:`flex items-start gap-2 text-sm`,children:[ee.success?(0,G.jsx)(xs,{className:`w-4 h-4 text-green-600 dark:text-green-400 mt-0.5 flex-shrink-0`}):(0,G.jsx)(Ds,{className:`w-4 h-4 text-red-600 dark:text-red-400 mt-0.5 flex-shrink-0`}),(0,G.jsxs)(`div`,{className:ee.success?`text-green-800 dark:text-green-200`:`text-red-800 dark:text-red-200`,children:[ee.message,ee.success&&(0,G.jsx)(`div`,{className:`mt-2`,children:(0,G.jsxs)(Q,{size:`sm`,onClick:()=>window.location.reload(),children:[(0,G.jsx)(Wl,{className:`w-3 h-3`}),n(`backup.reloadNow`)]})})]})]})}),(0,G.jsx)(`div`,{className:`p-3 rounded-lg bg-yellow-50 dark:bg-yellow-500/10 border border-yellow-300 dark:border-yellow-500/30`,children:(0,G.jsxs)(`div`,{className:`flex items-start gap-2 text-sm`,children:[(0,G.jsx)(Lu,{className:`w-4 h-4 text-yellow-600 dark:text-yellow-400 mt-0.5 flex-shrink-0`}),(0,G.jsxs)(`div`,{className:`text-yellow-800 dark:text-yellow-200`,children:[(0,G.jsx)(`span`,{className:`font-medium`,children:n(`backup.restoreReplacesAll`)}),` `,(0,G.jsx)(`span`,{className:`text-yellow-800/80 dark:text-yellow-200/70`,children:n(`backup.restoreReplacesAllDetail`)})]})]})})]})]}),(0,G.jsxs)(zd,{id:`card-backup-scheduled`,children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(gc,{className:`w-5 h-5 text-gray-400`}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:n(`backup.scheduledBackup`)})]}),(0,G.jsx)(fH,{checked:ue?.enabled??!1,onChange:async r=>{try{await Z.updateSettings({local_backup_enabled:r}),e.invalidateQueries({queryKey:[`settings`]}),t(n(`backup.settingsSaved`))}catch(e){t(n(`backup.failedToSave`,{message:e instanceof Error?e.message:`Unknown error`}),`error`)}de()}})]})}),(0,G.jsxs)(Vd,{className:`space-y-4`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`backup.scheduledBackupDescription`)}),ue?.enabled&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`grid grid-cols-3 gap-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`backup.frequency`)}),(0,G.jsxs)(`select`,{value:ue?.schedule??`daily`,className:`w-full h-10 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,onChange:async e=>{try{await Z.updateSettings({local_backup_schedule:e.target.value}),t(n(`backup.settingsSaved`))}catch(e){t(n(`backup.failedToSave`,{message:e instanceof Error?e.message:`Unknown error`}),`error`)}de()},children:[(0,G.jsx)(`option`,{value:`hourly`,children:n(`backup.hourly`)}),(0,G.jsx)(`option`,{value:`daily`,children:n(`backup.daily`)}),(0,G.jsx)(`option`,{value:`weekly`,children:n(`backup.weekly`)})]})]}),(ue?.schedule??`daily`)!==`hourly`&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`backup.backupTime`)}),(0,G.jsx)(`input`,{type:`time`,value:ue?.time??`03:00`,className:`w-full h-10 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,onChange:async e=>{try{await Z.updateSettings({local_backup_time:e.target.value}),t(n(`backup.settingsSaved`))}catch(e){t(n(`backup.failedToSave`,{message:e instanceof Error?e.message:`Unknown error`}),`error`)}de()}}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray-light mt-1`,children:n(`backup.localTimeHint`,{tz:ue?.timezone||`UTC`})})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`backup.retention`)}),(0,G.jsx)(`input`,{type:`number`,min:1,max:100,value:ue?.retention??5,className:`w-full h-10 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,onChange:async e=>{let r=Math.max(1,Math.min(100,parseInt(e.target.value)||5));try{await Z.updateSettings({local_backup_retention:r}),t(n(`backup.settingsSaved`))}catch(e){t(n(`backup.failedToSave`,{message:e instanceof Error?e.message:`Unknown error`}),`error`)}de()}}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray-light mt-1`,children:n(`backup.retentionDescription`)})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`backup.outputPath`)}),(0,G.jsx)(`input`,{type:`text`,value:ce,onChange:e=>le(e.target.value),className:`w-full h-10 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,onBlur:async()=>{try{await Z.updateSettings({local_backup_path:ce}),t(n(`backup.settingsSaved`))}catch(e){t(n(`backup.failedToSave`,{message:e instanceof Error?e.message:`Unknown error`}),`error`)}de(),pe(),he()},onKeyDown:e=>{e.key===`Enter`&&e.target.blur()}}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray-light mt-1`,children:ce?n(`backup.outputPathDescription`):(0,G.jsxs)(G.Fragment,{children:[n(`backup.defaultPathLabel`),` `,(0,G.jsx)(`code`,{className:`text-bambu-gray`,children:ue?.default_path||`...`})]})}),me&&!me.writable&&(0,G.jsx)(`div`,{className:`mt-2 p-3 rounded-lg bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30`,children:(0,G.jsxs)(`div`,{className:`flex items-start gap-2 text-sm`,children:[(0,G.jsx)(Lu,{className:`w-4 h-4 text-red-600 dark:text-red-400 mt-0.5 flex-shrink-0`}),(0,G.jsxs)(`div`,{className:`min-w-0 text-red-800 dark:text-red-200`,children:[(0,G.jsx)(`p`,{className:`font-medium`,children:n(`backup.pathCheck.title`)}),(0,G.jsx)(`p`,{className:`mt-1 text-red-800/80 dark:text-red-200/80`,children:n(`backup.pathCheck.${me.code}`,{path:me.path,defaultValue:me.message})}),me.remedy&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`p`,{className:`mt-2 font-medium`,children:n(`backup.pathCheck.howToFix`)}),(0,G.jsx)(`pre`,{className:`mt-1 p-2 rounded bg-black/10 dark:bg-black/40 text-xs whitespace-pre-wrap break-words`,children:me.remedy})]}),me.detail&&(0,G.jsx)(`p`,{className:`mt-2 text-xs text-red-800/60 dark:text-red-200/60 break-words`,children:me.detail})]})]})}),me?.writable&&me.warning===`container_ephemeral`&&(0,G.jsx)(`div`,{className:`mt-2 p-3 rounded-lg bg-yellow-50 dark:bg-yellow-500/10 border border-yellow-300 dark:border-yellow-500/30`,children:(0,G.jsxs)(`div`,{className:`flex items-start gap-2 text-sm`,children:[(0,G.jsx)(Lu,{className:`w-4 h-4 text-yellow-600 dark:text-yellow-400 mt-0.5 flex-shrink-0`}),(0,G.jsxs)(`div`,{className:`min-w-0 text-yellow-800 dark:text-yellow-200`,children:[(0,G.jsx)(`p`,{className:`font-medium`,children:n(`backup.pathCheck.ephemeralTitle`)}),(0,G.jsx)(`p`,{className:`mt-1 text-yellow-800/80 dark:text-yellow-200/80`,children:n(`backup.pathCheck.container_ephemeral`,{path:me.path})}),me.remedy&&(0,G.jsx)(`pre`,{className:`mt-1 p-2 rounded bg-black/10 dark:bg-black/40 text-xs whitespace-pre-wrap break-words`,children:me.remedy})]})]})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between py-3 border-t border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`text-sm`,children:[ue?.last_backup_at&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray`,children:[(0,G.jsxs)(`span`,{children:[n(`backup.lastBackup`),`:`]}),(0,G.jsx)(I8,{status:ue.last_status}),(0,G.jsx)(`span`,{children:up(ue.last_backup_at)})]}),ue?.next_run&&(0,G.jsxs)(`div`,{className:`text-bambu-gray mt-1`,children:[(0,G.jsxs)(`span`,{children:[n(`backup.nextBackup`),`: `]}),(0,G.jsx)(`span`,{children:F8(ue.next_run)})]})]}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,disabled:ue?.is_running||ge.isPending,onClick:()=>ge.mutate(),children:[ue?.is_running||ge.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Nl,{className:`w-4 h-4`}),ue?.is_running?n(`backup.backupRunning`):n(`backup.runNow`)]})]}),fe&&fe.length>0&&(0,G.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary pt-3`,children:[(0,G.jsx)(`h3`,{className:`text-sm font-medium text-white mb-2`,children:n(`backup.backupFiles`)}),(0,G.jsx)(`div`,{className:`space-y-1`,children:fe.map(e=>(0,G.jsxs)(`div`,{className:`flex items-center justify-between py-1.5 px-2 rounded hover:bg-bambu-dark-tertiary/50 text-sm`,children:[(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`span`,{className:`text-white truncate block`,children:e.filename}),(0,G.jsxs)(`span`,{className:`text-bambu-gray text-xs`,children:[(e.size/1024/1024).toFixed(1),` MB · `,F8(e.created_at)]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1 flex-shrink-0`,children:[(0,G.jsx)(`button`,{className:`text-bambu-gray hover:text-bambu-green p-1`,title:n(`backup.download`),onClick:async()=>{try{let{blob:t,filename:n}=await Z.downloadLocalBackup(e.filename),r=URL.createObjectURL(t),i=document.createElement(`a`);i.href=r,i.download=n,i.click(),URL.revokeObjectURL(r)}catch{t(n(`backup.scheduledBackupFailed`),`error`)}},children:(0,G.jsx)(Xs,{className:`w-3.5 h-3.5`})}),(0,G.jsx)(`button`,{className:`text-bambu-gray hover:text-yellow-600 dark:hover:text-yellow-400 p-1`,title:n(`backup.restore`),onClick:()=>H(e.filename),children:(0,G.jsx)(Wl,{className:`w-3.5 h-3.5`})}),(0,G.jsx)(`button`,{className:`text-bambu-gray hover:text-red-600 dark:hover:text-red-400 p-1`,onClick:()=>oe(e.filename),title:n(`backup.deleteBackup`),children:(0,G.jsx)(Pu,{className:`w-3.5 h-3.5`})})]})]},e.filename))})]}),fe&&fe.length===0&&(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray text-center py-3 border-t border-bambu-dark-tertiary`,children:n(`backup.noScheduledBackups`)})]})]})]})]}),re&&(0,G.jsx)(SGe,{onClose:()=>ie(!1)}),ae&&(0,G.jsx)(of,{title:n(`backup.deleteBackup`),message:n(`backup.deleteBackupConfirm`),confirmText:n(`backup.deleteBackup`),variant:`danger`,onConfirm:()=>_e.mutate(ae),onCancel:()=>oe(null)}),se&&(0,G.jsx)(of,{title:n(`backup.restoreConfirmTitle`),message:n(`backup.restoreConfirmMessage`,{filename:se}),confirmText:n(`backup.restoreConfirmButton`),variant:`danger`,onConfirm:()=>ve.mutate(se),onCancel:()=>H(null)}),R&&B&&(0,G.jsx)(of,{title:n(`backup.restoreConfirmTitle`),message:n(`backup.restoreConfirmMessage`,{filename:B.name}),confirmText:n(`backup.restoreConfirmButton`),variant:`danger`,onConfirm:async()=>{z(!1),F(!0),te(null);try{L(n(`backup.uploadingFile`));let e=await Z.importBackup(B);te(e),e.success?t(n(`backup.backupRestoredRestart`),`success`):t(e.message,`error`)}catch(e){let r=e instanceof Error?e.message:n(`backup.failedToRestore`);te({success:!1,message:r}),t(r,`error`)}finally{F(!1),L(``),V(null)}},onCancel:()=>{z(!1),V(null)}}),(M||P)&&(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/80 flex items-center justify-center z-[100]`,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl p-8 max-w-md w-full mx-4 text-center`,children:[(0,G.jsx)(`div`,{className:`flex justify-center mb-4`,children:(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(`div`,{className:`w-16 h-16 border-4 border-bambu-dark-tertiary rounded-full`}),(0,G.jsx)(`div`,{className:`w-16 h-16 border-4 border-bambu-green border-t-transparent rounded-full absolute inset-0 animate-spin`})]})}),(0,G.jsx)(`h3`,{className:`text-xl font-semibold text-white mb-2`,children:n(M?`backup.creatingBackup`:`backup.restoringBackup`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray mb-4`,children:I||n(M?`backup.preparing`:`backup.processing`)}),(0,G.jsx)(`div`,{className:`p-3 rounded-lg bg-yellow-50 dark:bg-yellow-500/10 border border-yellow-300 dark:border-yellow-500/30`,children:(0,G.jsxs)(`div`,{className:`flex items-start gap-2 text-sm`,children:[(0,G.jsx)(Lu,{className:`w-4 h-4 text-yellow-600 dark:text-yellow-400 mt-0.5 flex-shrink-0`}),(0,G.jsx)(`p`,{className:`text-yellow-800 dark:text-yellow-200 text-left`,children:n(`backup.doNotClosePage`)})]})})]})})]})}function OGe(){let{t:e}=U(),t=co(),{showToast:n}=qd(),[r,i]=(0,y.useState)(!1),[a,o]=(0,y.useState)(``),[s,c]=(0,y.useState)(``),[l,u]=(0,y.useState)(`medium`),[d,f]=(0,y.useState)(`notify`),[p,m]=(0,y.useState)(10),[h,g]=(0,y.useState)(null),[_,v]=(0,y.useState)(null),[b,x]=(0,y.useState)(!1),{data:S}=K({queryKey:[`settings`],queryFn:Z.getSettings}),{data:C,refetch:w}=K({queryKey:[`obico-status`],queryFn:Z.getObicoStatus,refetchInterval:1e4}),{data:T}=K({queryKey:[`printers`],queryFn:Z.getPrinters});(0,y.useEffect)(()=>{if(S){i(S.obico_enabled??!1),o(S.obico_ml_url??``),c(S.obico_ml_token??``),u(S.obico_sensitivity??`medium`),f(S.obico_action??`notify`),m(S.obico_poll_interval??10);try{let e=S.obico_enabled_printers?JSON.parse(S.obico_enabled_printers):null;g(Array.isArray(e)?e:null)}catch{g(null)}x(!0)}},[S]);let E=q({mutationFn:()=>Z.updateSettings({obico_enabled:r,obico_ml_url:a,obico_ml_token:s,obico_sensitivity:l,obico_action:d,obico_poll_interval:p,obico_enabled_printers:h===null?``:JSON.stringify(h)}),onSuccess:()=>{t.invalidateQueries({queryKey:[`settings`]}),t.invalidateQueries({queryKey:[`obico-status`]}),t.invalidateQueries({queryKey:[`obico-printer-status`]}),n(e(`settings.toast.settingsSaved`))}}),D=(0,y.useMemo)(()=>!b||!S?!1:S.obico_enabled!==r||S.obico_ml_url!==a||(S.obico_ml_token??``)!==s||S.obico_sensitivity!==l||S.obico_action!==d||S.obico_poll_interval!==p||S.obico_enabled_printers!==(h===null?``:JSON.stringify(h)),[S,b,r,a,s,l,d,p,h]);(0,y.useEffect)(()=>{if(!D)return;let e=setTimeout(()=>E.mutate(),500);return()=>clearTimeout(e)},[D,r,a,s,l,d,p,h]);let O=async()=>{v(null);try{D&&await E.mutateAsync();let t=await Z.testObicoConnection(a,s);t.ok?v({ok:!0,message:t.auth_ok===null?e(`failureDetection.testSuccessTokenUnknown`):e(`failureDetection.testSuccess`)}):v({ok:!1,message:t.error||`HTTP ${t.status_code??`?`} — ${t.body??e(`failureDetection.testFailed`)}`})}catch(e){v({ok:!1,message:e instanceof Error?e.message:String(e)})}},k=(e,t)=>{if(h===null){let n=T?.map(e=>e.id)??[];g(t?n:n.filter(t=>t!==e));return}g(t?[...h,e]:h.filter(t=>t!==e))};return(0,G.jsxs)(`div`,{className:`flex flex-col lg:flex-row gap-4 lg:gap-6`,children:[(0,G.jsxs)(`div`,{className:`space-y-3 flex-1 lg:max-w-xl`,children:[(0,G.jsxs)(zd,{id:`card-fd-ml`,children:[(0,G.jsxs)(Bd,{children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Yl,{className:`w-5 h-5 text-bambu-green`}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`failureDetection.title`)})]}),(0,G.jsx)(fH,{checked:r,onChange:i})]}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-2`,children:e(`failureDetection.description`)})]}),(0,G.jsxs)(Vd,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:e(`failureDetection.mlUrl`)}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsx)(`input`,{type:`text`,value:a,onChange:e=>o(e.target.value),placeholder:`http://192.168.1.10:3333`,className:`flex-1 bg-gray-800 border border-gray-700 rounded px-3 py-2 text-white text-sm`,disabled:!r}),(0,G.jsx)(Q,{onClick:O,disabled:!a||E.isPending,variant:`secondary`,children:e(`failureDetection.test`)})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`failureDetection.mlUrlHint`)}),(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1 mt-3`,children:e(`failureDetection.mlToken`)}),(0,G.jsx)(`input`,{type:`password`,value:s,onChange:e=>c(e.target.value),autoComplete:`off`,placeholder:e(`failureDetection.mlTokenPlaceholder`),className:`w-full bg-gray-800 border border-gray-700 rounded px-3 py-2 text-white text-sm`,disabled:!r}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`failureDetection.mlTokenHint`)}),_&&(0,G.jsxs)(`div`,{className:`flex items-start gap-2 mt-2 text-sm ${_.ok?`text-green-700 dark:text-green-400`:`text-red-700 dark:text-red-400`}`,children:[_.ok?(0,G.jsx)(fs,{className:`w-4 h-4 mt-0.5`}):(0,G.jsx)(nd,{className:`w-4 h-4 mt-0.5`}),(0,G.jsx)(`span`,{children:_.message})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:e(`failureDetection.sensitivity`)}),(0,G.jsxs)(`select`,{value:l,onChange:e=>u(e.target.value),disabled:!r,className:`w-full bg-gray-800 border border-gray-700 rounded px-3 py-2 text-white text-sm`,children:[(0,G.jsx)(`option`,{value:`low`,children:e(`failureDetection.sensitivityLow`)}),(0,G.jsx)(`option`,{value:`medium`,children:e(`failureDetection.sensitivityMedium`)}),(0,G.jsx)(`option`,{value:`high`,children:e(`failureDetection.sensitivityHigh`)})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`failureDetection.sensitivityHint`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:e(`failureDetection.action`)}),(0,G.jsxs)(`select`,{value:d,onChange:e=>f(e.target.value),disabled:!r,className:`w-full bg-gray-800 border border-gray-700 rounded px-3 py-2 text-white text-sm`,children:[(0,G.jsx)(`option`,{value:`notify`,children:e(`failureDetection.actionNotify`)}),(0,G.jsx)(`option`,{value:`pause`,children:e(`failureDetection.actionPause`)}),(0,G.jsx)(`option`,{value:`pause_and_off`,children:e(`failureDetection.actionPauseOff`)})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:e(`failureDetection.pollInterval`)}),(0,G.jsx)(`input`,{type:`number`,value:p,onChange:e=>m(Math.max(5,Math.min(120,Number(e.target.value)||10))),min:5,max:120,disabled:!r,className:`w-full bg-gray-800 border border-gray-700 rounded px-3 py-2 text-white text-sm`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`failureDetection.pollIntervalHint`)})]}),C&&!C.external_url_configured&&r&&(0,G.jsxs)(`div`,{className:`flex items-start gap-2 p-3 bg-amber-50 dark:bg-amber-900/30 border border-amber-300 dark:border-amber-700 rounded text-sm text-amber-800 dark:text-amber-200`,children:[(0,G.jsx)(Lu,{className:`w-4 h-4 mt-0.5 flex-shrink-0`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`div`,{className:`font-medium`,children:e(`failureDetection.externalUrlMissing`)}),(0,G.jsx)(`div`,{className:`text-xs mt-1`,children:e(`failureDetection.externalUrlHint`)})]})]})]})]}),(0,G.jsxs)(zd,{id:`card-fd-perprinter`,children:[(0,G.jsxs)(Bd,{children:[(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`failureDetection.perPrinterTitle`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:e(`failureDetection.perPrinterHint`)})]}),(0,G.jsxs)(Vd,{className:`space-y-2`,children:[(0,G.jsxs)(`label`,{className:`flex items-center gap-2 text-sm`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:h===null,onChange:e=>g(e.target.checked?null:T?.map(e=>e.id)??[]),disabled:!r}),(0,G.jsx)(`span`,{className:`text-white`,children:e(`failureDetection.monitorAll`)})]}),h!==null&&T&&(0,G.jsx)(`div`,{className:`pl-5 space-y-1 border-l border-gray-700`,children:T.map(e=>(0,G.jsxs)(`label`,{className:`flex items-center gap-2 text-sm`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:h.includes(e.id),onChange:t=>k(e.id,t.target.checked),disabled:!r}),(0,G.jsx)(`span`,{className:`text-white`,children:e.name})]},e.id))})]})]})]}),(0,G.jsxs)(`div`,{className:`space-y-3 flex-1 lg:max-w-xl`,children:[(0,G.jsxs)(zd,{id:`card-fd-status`,children:[(0,G.jsx)(Bd,{children:(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`failureDetection.statusTitle`)})}),(0,G.jsx)(Vd,{children:C?(0,G.jsxs)(`div`,{className:`space-y-3 text-sm`,children:[(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:e(`failureDetection.serviceRunning`)}),(0,G.jsx)(`span`,{className:C.is_running?`text-green-700 dark:text-green-400`:`text-red-700 dark:text-red-400`,children:C.is_running?e(`common.yes`):e(`common.no`)})]}),(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:e(`failureDetection.thresholds`)}),(0,G.jsxs)(`span`,{className:`text-white font-mono`,children:[C.thresholds.low.toFixed(2),` / `,C.thresholds.high.toFixed(2)]})]}),C.last_error&&(0,G.jsxs)(`div`,{className:`flex items-start gap-2 text-red-700 dark:text-red-400`,children:[(0,G.jsx)(nd,{className:`w-4 h-4 mt-0.5 flex-shrink-0`}),(0,G.jsx)(`span`,{className:`break-words`,children:C.last_error})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`div`,{className:`text-bambu-gray mb-1`,children:e(`failureDetection.activePrinters`)}),Object.keys(C.per_printer).length===0?(0,G.jsx)(`div`,{className:`text-bambu-gray italic text-xs`,children:e(`failureDetection.noActivePrints`)}):(0,G.jsx)(`div`,{className:`space-y-1`,children:Object.entries(C.per_printer).map(([e,t])=>{let n=T?.find(t=>String(t.id)===e),r=t.class===`failure`?`text-red-700 dark:text-red-400`:t.class===`warning`?`text-amber-700 dark:text-amber-400`:`text-green-700 dark:text-green-400`;return(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-white`,children:n?.name??`Printer ${e}`}),(0,G.jsxs)(`span`,{className:`font-mono ${r}`,children:[t.class,` (`,t.score.toFixed(3),`, `,t.frame_count,`f)`]})]},e)})})]})]}):(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray`,children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),(0,G.jsx)(`span`,{children:e(`common.loading`)})]})})]}),(0,G.jsxs)(zd,{id:`card-fd-history`,children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`failureDetection.historyTitle`)}),(0,G.jsx)(`button`,{onClick:()=>w(),className:`text-xs text-bambu-gray hover:text-white`,children:e(`common.refresh`)})]})}),(0,G.jsx)(Vd,{children:!C||C.history.length===0?(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray text-sm`,children:[(0,G.jsx)(Wc,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{children:e(`failureDetection.noHistory`)})]}):(0,G.jsx)(`div`,{className:`space-y-1 max-h-96 overflow-y-auto text-xs font-mono`,children:C.history.map((e,t)=>{let n=T?.find(t=>t.id===e.printer_id),r=e.class===`failure`?`text-red-700 dark:text-red-400`:e.class===`warning`?`text-amber-700 dark:text-amber-400`:`text-bambu-gray`;return(0,G.jsxs)(`div`,{className:`flex justify-between gap-2 py-1 border-b border-gray-800`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:new Date(e.timestamp).toLocaleTimeString()}),(0,G.jsx)(`span`,{className:`text-white truncate`,children:n?.name??`#${e.printer_id}`}),(0,G.jsxs)(`span`,{className:r,children:[e.class,` `,e.score.toFixed(3)]})]},t)})})})]})]})]})}var kGe={starttls:587,ssl:465,none:25},AGe={587:`starttls`,465:`ssl`,25:`none`};function jGe(){let{t:e}=U(),{showToast:t}=qd(),n=co(),[r,i]=(0,y.useState)({smtp_host:``,smtp_port:587,smtp_username:``,smtp_password:``,smtp_security:`starttls`,smtp_auth_enabled:!0,smtp_from_email:``,smtp_from_name:`BamBuddy`}),[a,o]=(0,y.useState)(``),{data:s,isLoading:c}=K({queryKey:[`smtpSettings`],queryFn:()=>Z.getSMTPSettings()}),{authEnabled:l}=Nd(),{data:u}=K({queryKey:[`advancedAuthStatus`],queryFn:()=>Z.getAdvancedAuthStatus()});(0,y.useEffect)(()=>{s&&i({...s,smtp_password:``})},[s]);let d=e=>{i({...r,smtp_security:e,smtp_port:kGe[e]})},f=e=>{let t=AGe[e];i({...r,smtp_port:e,...t?{smtp_security:t}:{}})},p=e=>{i({...r,smtp_auth_enabled:e,...e?{}:{smtp_username:``,smtp_password:``}})},m=q({mutationFn:e=>Z.saveSMTPSettings(e),onSuccess:()=>{n.invalidateQueries({queryKey:[`smtpSettings`]}),n.invalidateQueries({queryKey:[`advancedAuthStatus`]}),t(e(`settings.email.success.settingsSaved`),`success`)},onError:e=>{t(e.message,`error`)}}),h=q({mutationFn:e=>Z.testSMTP(e),onSuccess:e=>{t(e.message,e.success?`success`:`error`)},onError:e=>{t(e.message,`error`)}}),g=q({mutationFn:e=>e?Z.enableAdvancedAuth():Z.disableAdvancedAuth(),onSuccess:e=>{n.invalidateQueries({queryKey:[`advancedAuthStatus`]}),t(e.message,`success`)},onError:e=>{t(e.message,`error`)}}),_=()=>{if(!r.smtp_host||!r.smtp_from_email){t(e(`settings.email.errors.requiredFields`),`error`);return}if(r.smtp_auth_enabled&&!r.smtp_username){t(e(`settings.email.errors.usernameRequired`),`error`);return}m.mutate(r)},v=()=>{if(!a){t(e(`settings.email.errors.enterTestEmail`),`error`);return}h.mutate({test_recipient:a})},b=()=>{if(!l){t(e(`settings.email.errors.enableAuthFirst`),`error`);return}if(!u?.advanced_auth_enabled&&!u?.smtp_configured){t(e(`settings.email.errors.configureSmtpFirst`),`error`);return}g.mutate(!u?.advanced_auth_enabled)};if(c)return(0,G.jsx)(`div`,{className:`flex items-center justify-center p-12`,children:(0,G.jsx)(Y,{className:`w-8 h-8 animate-spin text-bambu-green`})});let x=u?.advanced_auth_enabled??!1,S=`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,C=`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white/40 placeholder-bambu-gray/40 cursor-not-allowed`;return(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(zd,{id:`card-email-advanced-auth`,children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(al,{className:`w-5 h-5 text-bambu-green`}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`settings.email.advancedAuth`)||`Advanced Authentication`})]}),(0,G.jsx)(Q,{onClick:b,disabled:g.isPending,variant:x?`danger`:`primary`,children:x?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(tl,{className:`w-4 h-4`}),e(`settings.email.disable`)||`Disable`]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(nl,{className:`w-4 h-4`}),e(`settings.email.enable`)||`Enable`]})})]})}),(0,G.jsx)(Vd,{children:(0,G.jsx)(`div`,{className:`space-y-3`,children:x?(0,G.jsx)(`div`,{className:`bg-green-50 dark:bg-green-500/10 border border-green-300 dark:border-green-500/30 rounded-lg p-4`,children:(0,G.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,G.jsx)(xs,{className:`w-5 h-5 text-green-600 dark:text-green-400 mt-0.5 flex-shrink-0`}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`p`,{className:`text-white font-medium`,children:e(`settings.email.advancedAuthEnabled`)||`Advanced Authentication is enabled`}),(0,G.jsxs)(`ul`,{className:`text-sm text-green-700 dark:text-green-300 space-y-1 list-disc list-inside`,children:[(0,G.jsx)(`li`,{children:e(`settings.email.feature1`)||`Passwords are auto-generated and emailed to new users`}),(0,G.jsx)(`li`,{children:e(`settings.email.feature2`)||`Users can login with username or email`}),(0,G.jsx)(`li`,{children:e(`settings.email.feature3`)||`Forgot password feature is available`}),(0,G.jsx)(`li`,{children:e(`settings.email.feature4`)||`Admins can reset user passwords via email`})]})]})]})}):(0,G.jsx)(`div`,{className:`bg-yellow-50 dark:bg-yellow-500/10 border border-yellow-300 dark:border-yellow-500/30 rounded-lg p-4`,children:(0,G.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,G.jsx)(Lu,{className:`w-5 h-5 text-yellow-600 dark:text-yellow-400 mt-0.5 flex-shrink-0`}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`p`,{className:`text-white font-medium`,children:e(`settings.email.advancedAuthDisabled`)||`Advanced Authentication is disabled`}),(0,G.jsx)(`p`,{className:`text-sm text-yellow-700 dark:text-yellow-300`,children:e(`settings.email.advancedAuthDisabledDesc`)||`Enable advanced authentication to activate email-based features for user management.`})]})]})})})})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-3 gap-4`,children:[(0,G.jsx)(`div`,{className:`lg:col-span-2`,children:(0,G.jsxs)(zd,{id:`card-smtp-config`,children:[(0,G.jsx)(Bd,{children:(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`settings.email.smtpSettings`)||`SMTP Configuration`})}),(0,G.jsx)(Vd,{children:(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:e(`settings.email.authentication`)||`Authentication`}),(0,G.jsxs)(`select`,{value:r.smtp_auth_enabled?`true`:`false`,onChange:e=>p(e.target.value===`true`),className:S,children:[(0,G.jsx)(`option`,{value:`true`,children:e(`settings.email.authOptions.enabled`)}),(0,G.jsx)(`option`,{value:`false`,children:e(`settings.email.authOptions.disabled`)})]})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4 transition-opacity ${r.smtp_auth_enabled?``:`opacity-40 pointer-events-none`}`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:e(`settings.email.username`)||`Username`}),(0,G.jsx)(`input`,{type:`text`,value:r.smtp_username||``,onChange:e=>i({...r,smtp_username:e.target.value}),placeholder:`your.email@gmail.com`,disabled:!r.smtp_auth_enabled,className:r.smtp_auth_enabled?S:C})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:e(`settings.email.password`)||`Password`}),(0,G.jsx)(`input`,{type:`password`,value:r.smtp_password||``,onChange:e=>i({...r,smtp_password:e.target.value}),placeholder:s?`••••••••`:`App password`,disabled:!r.smtp_auth_enabled,className:r.smtp_auth_enabled?S:C})]})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:[e(`settings.email.smtpHost`)||`SMTP Server`,` *`]}),(0,G.jsx)(`input`,{type:`text`,value:r.smtp_host,onChange:e=>i({...r,smtp_host:e.target.value}),placeholder:`smtp.gmail.com`,className:S})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:e(`settings.email.smtpPort`)||`SMTP Port`}),(0,G.jsx)(`input`,{type:`number`,value:r.smtp_port,onChange:e=>f(parseInt(e.target.value)||587),placeholder:`587`,className:S})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:e(`settings.email.security`)||`Security`}),(0,G.jsxs)(`select`,{value:r.smtp_security,onChange:e=>d(e.target.value),className:S,children:[(0,G.jsx)(`option`,{value:`starttls`,children:e(`settings.email.securityOptions.starttls`)}),(0,G.jsx)(`option`,{value:`ssl`,children:e(`settings.email.securityOptions.ssl`)}),(0,G.jsx)(`option`,{value:`none`,children:e(`settings.email.securityOptions.none`)})]})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:[e(`settings.email.fromEmail`)||`From Email`,` *`]}),(0,G.jsx)(`input`,{type:`email`,value:r.smtp_from_email,onChange:e=>i({...r,smtp_from_email:e.target.value}),placeholder:`your@email.com`,className:S})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:e(`settings.email.fromName`)||`From Name`}),(0,G.jsx)(`input`,{type:`text`,value:r.smtp_from_name,onChange:e=>i({...r,smtp_from_name:e.target.value}),placeholder:`BamBuddy`,className:S})]})]}),(0,G.jsx)(`div`,{className:`flex gap-2`,children:(0,G.jsx)(Q,{onClick:_,disabled:m.isPending,className:`flex-1`,children:m.isPending?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),e(`settings.email.saving`)||`Saving...`]}):e(`settings.email.save`)||`Save Settings`})})]})})]})}),(0,G.jsx)(`div`,{children:(0,G.jsxs)(zd,{id:`card-email-test`,children:[(0,G.jsx)(Bd,{children:(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`settings.email.testConnection`)||`Test SMTP Connection`})}),(0,G.jsx)(Vd,{children:(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:e(`settings.email.testRecipient`)||`Test Recipient Email`}),(0,G.jsx)(`input`,{type:`email`,value:a,onChange:e=>o(e.target.value),placeholder:`test@example.com`,className:S})]}),(0,G.jsx)(Q,{onClick:v,disabled:h.isPending,variant:`secondary`,children:h.isPending?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),e(`settings.email.sending`)||`Sending...`]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)($l,{className:`w-4 h-4`}),e(`settings.email.sendTest`)||`Send Test Email`]})})]})})]})})]})]})}var MGe={starttls:`389`,ldaps:`636`};function NGe(){let{t:e}=U(),{showToast:t}=qd(),n=co(),{authEnabled:r}=Nd(),[i,a]=(0,y.useState)({ldap_server_url:``,ldap_bind_dn:``,ldap_bind_password:``,ldap_search_base:``,ldap_user_filter:`(sAMAccountName={username})`,ldap_security:`starttls`,ldap_group_mapping:``,ldap_auto_provision:!1,ldap_default_group:``}),{data:o,isLoading:s}=K({queryKey:[`settings`],queryFn:()=>Z.getSettings()}),{data:c}=K({queryKey:[`ldapStatus`],queryFn:()=>Z.getLDAPStatus()}),{data:l=[]}=K({queryKey:[`groups`],queryFn:()=>Z.getGroups()});(0,y.useEffect)(()=>{o&&a({ldap_server_url:o.ldap_server_url||``,ldap_bind_dn:o.ldap_bind_dn||``,ldap_bind_password:``,ldap_search_base:o.ldap_search_base||``,ldap_user_filter:o.ldap_user_filter||`(sAMAccountName={username})`,ldap_security:o.ldap_security||`starttls`,ldap_group_mapping:o.ldap_group_mapping||``,ldap_auto_provision:o.ldap_auto_provision??!1,ldap_default_group:o.ldap_default_group||``})},[o]);let u=q({mutationFn:e=>Z.updateSettings(e),onSuccess:()=>{n.invalidateQueries({queryKey:[`settings`]}),n.invalidateQueries({queryKey:[`ldapStatus`]}),t(e(`settings.ldap.settingsSaved`)||`LDAP settings saved`,`success`)},onError:e=>{t(e.message,`error`)}}),d=q({mutationFn:e=>Z.updateSettings({ldap_enabled:e}),onSuccess:()=>{n.invalidateQueries({queryKey:[`settings`]}),n.invalidateQueries({queryKey:[`ldapStatus`]}),t(c?.ldap_enabled?e(`settings.ldap.disabled`)||`LDAP authentication disabled`:e(`settings.ldap.enabled`)||`LDAP authentication enabled`,`success`)},onError:e=>{t(e.message,`error`)}}),f=q({mutationFn:()=>Z.testLDAP(),onSuccess:e=>{t(e.message,e.success?`success`:`error`)},onError:e=>{t(e.message,`error`)}}),p=()=>{if(!i.ldap_server_url){t(e(`settings.ldap.errors.serverRequired`)||`LDAP server URL is required`,`error`);return}if(!i.ldap_search_base){t(e(`settings.ldap.errors.searchBaseRequired`)||`Search base DN is required`,`error`);return}let n={ldap_server_url:i.ldap_server_url,ldap_bind_dn:i.ldap_bind_dn,ldap_search_base:i.ldap_search_base,ldap_user_filter:i.ldap_user_filter,ldap_security:i.ldap_security,ldap_group_mapping:i.ldap_group_mapping,ldap_auto_provision:i.ldap_auto_provision,ldap_default_group:i.ldap_default_group};i.ldap_bind_password&&(n.ldap_bind_password=i.ldap_bind_password),u.mutate(n)},m=()=>{if(!r){t(e(`settings.ldap.errors.enableAuthFirst`)||`Enable authentication first`,`error`);return}if(!c?.ldap_enabled&&!c?.ldap_configured){t(e(`settings.ldap.errors.configureLdapFirst`)||`Save LDAP settings first`,`error`);return}d.mutate(!c?.ldap_enabled)};if(s)return(0,G.jsx)(`div`,{className:`flex items-center justify-center p-12`,children:(0,G.jsx)(Y,{className:`w-8 h-8 animate-spin text-bambu-green`})});let h=c?.ldap_enabled??!1,g=`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`;return(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(zd,{id:`card-ldap-toggle`,children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(su,{className:`w-5 h-5 text-bambu-green`}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`settings.ldap.title`)||`LDAP Authentication`})]}),(0,G.jsx)(Q,{onClick:m,disabled:d.isPending,variant:h?`danger`:`primary`,children:h?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(tl,{className:`w-4 h-4`}),e(`common.disable`)||`Disable`]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(nl,{className:`w-4 h-4`}),e(`common.enable`)||`Enable`]})})]})}),(0,G.jsx)(Vd,{children:h?(0,G.jsx)(`div`,{className:`bg-green-50 dark:bg-green-500/10 border border-green-300 dark:border-green-500/30 rounded-lg p-4`,children:(0,G.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,G.jsx)(xs,{className:`w-5 h-5 text-green-600 dark:text-green-400 mt-0.5 flex-shrink-0`}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`p`,{className:`text-white font-medium`,children:e(`settings.ldap.enabledDesc`)||`LDAP authentication is enabled`}),(0,G.jsxs)(`ul`,{className:`text-sm text-green-700 dark:text-green-300 space-y-1 list-disc list-inside`,children:[(0,G.jsx)(`li`,{children:e(`settings.ldap.feature1`)||`Users can login with LDAP credentials`}),(0,G.jsx)(`li`,{children:e(`settings.ldap.feature2`)||`Local admin account remains as fallback`}),(0,G.jsx)(`li`,{children:e(`settings.ldap.feature3`)||`LDAP groups are mapped to BamBuddy groups on login`})]})]})]})}):(0,G.jsx)(`div`,{className:`bg-yellow-50 dark:bg-yellow-500/10 border border-yellow-300 dark:border-yellow-500/30 rounded-lg p-4`,children:(0,G.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,G.jsx)(Lu,{className:`w-5 h-5 text-yellow-600 dark:text-yellow-400 mt-0.5 flex-shrink-0`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white font-medium`,children:e(`settings.ldap.disabledDesc`)||`LDAP authentication is disabled`}),(0,G.jsx)(`p`,{className:`text-sm text-yellow-700 dark:text-yellow-300 mt-1`,children:e(`settings.ldap.disabledHint`)||`Configure and save LDAP settings below, then enable.`})]})]})})})]}),(0,G.jsxs)(zd,{id:`card-ldap-server`,children:[(0,G.jsx)(Bd,{children:(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`settings.ldap.serverConfig`)||`LDAP Server Configuration`})}),(0,G.jsx)(Vd,{children:(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-3`,children:[(0,G.jsxs)(`div`,{className:`md:col-span-2`,children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:e(`settings.ldap.serverUrl`)||`Server URL`}),(0,G.jsx)(`input`,{type:`text`,className:g,placeholder:`ldaps://ldap.example.com:636`,value:i.ldap_server_url,onChange:e=>a({...i,ldap_server_url:e.target.value})}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`settings.ldap.serverUrlHint`)||`Use ldaps:// for SSL or ldap:// with StartTLS`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:e(`settings.ldap.security`)||`Security`}),(0,G.jsx)(`div`,{className:`flex gap-2`,children:[`starttls`,`ldaps`].map(e=>(0,G.jsx)(`button`,{onClick:()=>a({...i,ldap_security:e}),className:`flex-1 px-2 py-2 rounded-lg text-sm font-medium transition-colors ${i.ldap_security===e?`bg-bambu-green text-black`:`bg-bambu-dark-secondary text-bambu-gray hover:text-white border border-bambu-dark-tertiary`}`,children:e===`starttls`?`StartTLS`:`LDAPS`},e))}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`settings.ldap.securityHint`)||`Default port: ${MGe[i.ldap_security]}`})]})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:e(`settings.ldap.bindDn`)||`Bind DN (Service Account)`}),(0,G.jsx)(`input`,{type:`text`,className:g,placeholder:`cn=service-account,ou=service,dc=example,dc=com`,value:i.ldap_bind_dn,onChange:e=>a({...i,ldap_bind_dn:e.target.value})})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:e(`settings.ldap.bindPassword`)||`Bind Password`}),(0,G.jsx)(`input`,{type:`password`,className:g,placeholder:o?.ldap_bind_dn?`••••••••`:``,value:i.ldap_bind_password,onChange:e=>a({...i,ldap_bind_password:e.target.value})})]})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:e(`settings.ldap.searchBase`)||`Search Base DN`}),(0,G.jsx)(`input`,{type:`text`,className:g,placeholder:`ou=users,dc=example,dc=com`,value:i.ldap_search_base,onChange:e=>a({...i,ldap_search_base:e.target.value})})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:e(`settings.ldap.userFilter`)||`User Search Filter`}),(0,G.jsx)(`input`,{type:`text`,className:g,placeholder:`(sAMAccountName={username})`,value:i.ldap_user_filter,onChange:e=>a({...i,ldap_user_filter:e.target.value})})]})]}),(0,G.jsx)($p,{summary:(0,G.jsx)(`span`,{className:`text-sm font-medium text-bambu-gray`,children:e(`settings.ldap.advanced`)||`Advanced`}),className:`border-t border-bambu-dark-tertiary pt-3`,summaryClassName:`py-1`,children:(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white`,children:e(`settings.ldap.autoProvision`)||`Auto-provision users`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:e(`settings.ldap.autoProvisionHint`)||`Automatically create a BamBuddy account on first LDAP login`})]}),(0,G.jsx)(`button`,{onClick:()=>a({...i,ldap_auto_provision:!i.ldap_auto_provision}),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors flex-shrink-0 ${i.ldap_auto_provision?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,children:(0,G.jsx)(`span`,{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${i.ldap_auto_provision?`translate-x-6`:`translate-x-1`}`})})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:e(`settings.ldap.defaultGroup`)||`Default group`}),(0,G.jsxs)(`select`,{className:g,value:i.ldap_default_group,onChange:e=>a({...i,ldap_default_group:e.target.value}),children:[(0,G.jsx)(`option`,{value:``,children:e(`settings.ldap.defaultGroupNone`)||`— None (reject login) —`}),l.map(e=>(0,G.jsx)(`option`,{value:e.name,children:e.name},e.id))]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`settings.ldap.defaultGroupHint`)||`Fallback group assigned when an LDAP user authenticates but is not listed in any mapped group. Leave empty to leave unmapped users without permissions.`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:e(`settings.ldap.groupMapping`)||`Group Mapping (JSON)`}),(0,G.jsx)(`textarea`,{className:`${g} font-mono text-sm`,rows:4,placeholder:`{ +`),confirmText:e(`queue.filamentShort.printAnyway`),variant:`warning`,onConfirm:()=>{be.mutate({id:ve.itemId,skipFilamentCheck:!0})},onCancel:()=>ye(null)}),v&&(0,G.jsx)(of,{title:v.type===`cancel`?e(`queue.confirm.cancelTitle`):v.type===`stop`?e(`queue.confirm.stopTitle`):e(`queue.confirm.removeTitle`),message:v.type===`cancel`?e(`queue.confirm.cancelMessage`,{name:v.item.archive_name||v.item.library_file_name||e(`queue.confirm.thisPrint`)}):v.type===`stop`?e(`queue.confirm.stopMessage`,{name:v.item.archive_name||v.item.library_file_name||e(`queue.confirm.thisPrint`)}):e(`queue.confirm.removeMessage`,{name:v.item.archive_name||v.item.library_file_name||e(`queue.confirm.thisItem`)}),confirmText:v.type===`cancel`?e(`queue.confirm.cancelButton`):v.type===`stop`?e(`queue.confirm.stopButton`):e(`common.remove`),variant:`danger`,onConfirm:()=>{v.type===`cancel`?he.mutate(v.item.id):v.type===`stop`?_e.mutate(v.item.id):ge.mutate(v.item.id),b(null)},onCancel:()=>b(null)}),T&&(0,G.jsx)(of,{title:e(`queue.resumeAfterFailure.confirmTitle`),message:e(`queue.resumeAfterFailure.confirmMessage`,{printer:T.printerName,count:T.skippedCount}),confirmText:e(`queue.resumeAfterFailure.button`),variant:`warning`,onConfirm:()=>Te.mutate(T.printerId),onCancel:()=>E(null)}),f&&(0,G.jsx)(of,{title:e(`queue.confirm.clearHistoryTitle`),message:e(`queue.confirm.clearHistoryMessage`,{count:He.length}),confirmText:e(`queue.clearHistory`),variant:`danger`,onConfirm:()=>{Se.mutate(),p(!1)},onCancel:()=>p(!1)}),C&&(0,G.jsx)(UUe,{selectedCount:x.length,printers:pe?.map(e=>({id:e.id,name:e.name,nozzle_count:e.nozzle_count}))||[],onSave:e=>{Object.keys(e).length>0&&Ce.mutate({item_ids:x,...e})},onClose:()=>w(!1),isSaving:Ce.isPending,canControlPrinter:r(`printers:control`),hasGcodeSnippets:!!H?.gcode_snippets,t:e}),re&&(0,G.jsx)(qUe,{itemCount:x.length,isSaving:Ee.isPending,defaultName:(()=>{let t=je.find(e=>x.includes(e.id)),n=(t?.archive_name||t?.library_file_name||``).replace(/\.gcode\.3mf$/i,``).replace(/\.3mf$/i,``);return n?`${n}`:e(`queue.batch.defaultName`)})(),onSave:e=>Ee.mutate({name:e,item_ids:x}),onClose:()=>ie(!1),t:e}),ae!==null&&(0,G.jsx)(of,{title:e(`queue.batch.ungroupConfirmTitle`),message:e(`queue.batch.ungroupConfirmMessage`),confirmText:e(`queue.batch.ungroup`),variant:`warning`,onConfirm:()=>De.mutate(ae),onCancel:()=>oe(null)})]})}function qUe({itemCount:e,defaultName:t,isSaving:n,onSave:r,onClose:i,t:a}){let[o,s]=(0,y.useState)(t);return(0,G.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-4`,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl p-6 w-full max-w-md`,children:[(0,G.jsxs)(`h3`,{className:`text-lg font-semibold text-white mb-2 flex items-center gap-2`,children:[(0,G.jsx)(Cl,{className:`w-5 h-5 text-cyan-700 dark:text-cyan-300`}),a(`queue.batch.groupAsBatch`)]}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4`,children:a(`queue.batch.groupAsBatchDescription`,{count:e})}),(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:a(`queue.batch.nameLabel`)}),(0,G.jsx)(`input`,{type:`text`,autoFocus:!0,value:o,onChange:e=>s(e.target.value),placeholder:a(`queue.batch.namePlaceholder`),maxLength:120,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none mb-5`}),(0,G.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,G.jsx)(Q,{variant:`ghost`,size:`sm`,onClick:i,disabled:n,children:a(`common.cancel`)}),(0,G.jsx)(Q,{variant:`primary`,size:`sm`,onClick:()=>{let e=o.trim();e&&r(e)},disabled:n||!o.trim(),children:a(n?`common.saving`:`queue.batch.create`)})]})]})})}function JUe({printDates:e,months:t=3}){let n=(0,y.useRef)(null),[r,i]=(0,y.useState)(0);(0,y.useEffect)(()=>{let e=n.current;if(!e)return;let t=new ResizeObserver(e=>{i(e[0]?.contentRect.width||0)});return t.observe(e),()=>t.disconnect()},[]);let{weeks:a,monthLabels:o,printCounts:s}=(0,y.useMemo)(()=>{let n={};e.forEach(e=>{let t=pp(e);t&&(n[t]=(n[t]||0)+1)});let r=new Date,i=new Date(r);i.setMonth(i.getMonth()-t),i.setDate(i.getDate()-i.getDay());let a=[],o=[],s=[],c=-1,l=new Date(i),u=0;for(;l<=r;)l.getDay()===0&&s.length>0&&(a.push(s),s=[],u++),l.getMonth()!==c&&(o.push({month:l.toLocaleDateString(`en-US`,{month:`short`}),weekIndex:u}),c=l.getMonth()),s.push(new Date(l)),l.setDate(l.getDate()+1);return s.length>0&&a.push(s),{weeks:a,monthLabels:o,printCounts:n}},[e,t]),c=Math.max(1,...Object.values(s)),l=e=>{if(e===0)return`bg-bambu-dark`;let t=e/c;return t<=.25?`bg-bambu-green/30`:t<=.5?`bg-bambu-green/50`:t<=.75?`bg-bambu-green/75`:`bg-bambu-green`},u=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`],d=a.length,f=r-32-16,p=d>0?Math.floor((f-(d-1)*2)/d):12,m=Math.max(8,Math.min(20,p)),h=m<=10?10:12;return(0,G.jsx)(`div`,{ref:n,className:`w-full flex justify-center`,children:r>0&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`div`,{className:`flex mb-1`,style:{marginLeft:36},children:o.map(({month:e,weekIndex:t},n)=>(0,G.jsx)(`div`,{className:`text-bambu-gray`,style:{fontSize:h,marginLeft:n===0?0:`${(t-(o[n-1]?.weekIndex||0))*(m+2)-24}px`},children:e},n))}),(0,G.jsxs)(`div`,{className:`flex`,style:{gap:2},children:[(0,G.jsx)(`div`,{className:`flex flex-col`,style:{gap:2,marginRight:4,width:32},children:u.map((e,t)=>(0,G.jsx)(`div`,{className:`text-bambu-gray flex items-center`,style:{width:32,height:m,fontSize:h,visibility:t%2==1?`visible`:`hidden`},children:e},e))}),a.map((e,t)=>(0,G.jsx)(`div`,{className:`flex flex-col`,style:{gap:2},children:[0,1,2,3,4,5,6].map(t=>{let n=e.find(e=>e.getDay()===t);if(!n)return(0,G.jsx)(`div`,{style:{width:m,height:m}},t);let r=pp(n),i=s[r]||0,a=r===pp(new Date);return(0,G.jsx)(`div`,{className:`rounded-sm ${l(i)} ${a?`ring-1 ring-white`:``}`,style:{width:m,height:m},title:`${n.toLocaleDateString()}: ${i} print${i===1?``:`s`}`},t)})},t))]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mt-3 text-bambu-gray`,style:{fontSize:h},children:[(0,G.jsx)(`span`,{children:`Less`}),(0,G.jsxs)(`div`,{className:`flex`,style:{gap:2},children:[(0,G.jsx)(`div`,{className:`rounded-sm bg-bambu-dark`,style:{width:m,height:m}}),(0,G.jsx)(`div`,{className:`rounded-sm bg-bambu-green/30`,style:{width:m,height:m}}),(0,G.jsx)(`div`,{className:`rounded-sm bg-bambu-green/50`,style:{width:m,height:m}}),(0,G.jsx)(`div`,{className:`rounded-sm bg-bambu-green/75`,style:{width:m,height:m}}),(0,G.jsx)(`div`,{className:`rounded-sm bg-bambu-green`,style:{width:m,height:m}})]}),(0,G.jsx)(`span`,{children:`More`})]})]})})}var l6=[`weight`,`prints`,`time`];function u6({value:e,onChange:t,exclude:n}){let{t:r}=U(),i={weight:r(`stats.filamentByWeight`),prints:r(`stats.filamentByPrints`),time:r(`stats.filamentByTime`)};return(0,G.jsx)(`div`,{className:`flex gap-0.5 bg-bambu-dark rounded-lg p-0.5`,children:(n?l6.filter(e=>!n.includes(e)):l6).map(n=>(0,G.jsx)(`button`,{onClick:()=>t(n),className:`px-2 py-0.5 text-xs rounded-md transition-colors ${e===n?`bg-bambu-green text-white`:`text-bambu-gray hover:text-white`}`,children:i[n]},n))})}function d6(e){if(e>=1e6){let t=e/1e6;return`${t%1==0?t.toFixed(0):t.toFixed(1)}t`}if(e>=1e3){let t=e/1e3;return`${t%1==0?t.toFixed(0):t.toFixed(1)}kg`}return`${Math.round(e)}g`}var f6=[`#00ae42`,`#3b82f6`,`#f59e0b`,`#ef4444`,`#8b5cf6`,`#ec4899`,`#14b8a6`,`#f97316`],YUe=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`],p6=[`12am`,`1am`,`2am`,`3am`,`4am`,`5am`,`6am`,`7am`,`8am`,`9am`,`10am`,`11am`,`12pm`,`1pm`,`2pm`,`3pm`,`4pm`,`5pm`,`6pm`,`7pm`,`8pm`,`9pm`,`10pm`,`11pm`];function XUe({archives:e,currency:t=`$`,dateFrom:n,dateTo:r}){let{t:i}=U(),[a,o]=(0,y.useState)(`weight`),[s,c]=(0,y.useState)(`weight`),l=(0,y.useMemo)(()=>{let t=new Map;return e.forEach(e=>{let n=rp(e.completed_at||e.created_at)||new Date,r=`${n.getFullYear()}-${String(n.getMonth()+1).padStart(2,`0`)}-${String(n.getDate()).padStart(2,`0`)}`,i=t.get(r)||{date:r,filament:0,cost:0,energy:0,prints:0};i.filament+=e.filament_used_grams||0,i.cost+=e.cost||0,i.energy+=e.energy_kwh||0,i.prints+=e.quantity??1,t.set(r,i)}),Array.from(t.values()).sort((e,t)=>e.date.localeCompare(t.date)).map(e=>({...e,dateLabel:new Date(e.date).toLocaleDateString(`en-US`,{month:`short`,day:`numeric`})}))},[e]),u=(0,y.useMemo)(()=>{if(n&&r)return Math.max((new Date(r).getTime()-new Date(n).getTime())/864e5,0)+1;if(n)return Math.max((Date.now()-new Date(n).getTime())/864e5,0)+1;if(e.length<2)return 0;let t=e.map(e=>new Date(e.completed_at||e.created_at).getTime());return(Math.max(...t)-Math.min(...t))/864e5},[e,n,r]),d=(0,y.useMemo)(()=>{if(u>7)return[];let t=new Map,n=u>1;return e.forEach(e=>{let n=rp(e.completed_at||e.created_at)||new Date,r=n.getHours(),i=`${n.getFullYear()}-${String(n.getMonth()+1).padStart(2,`0`)}-${String(n.getDate()).padStart(2,`0`)}T${String(r).padStart(2,`0`)}`,a=t.get(i)||{date:i,filament:0,cost:0,energy:0,prints:0};a.filament+=e.filament_used_grams||0,a.cost+=e.cost||0,a.energy+=e.energy_kwh||0,a.prints+=e.quantity??1,t.set(i,a)}),Array.from(t.values()).sort((e,t)=>e.date.localeCompare(t.date)).map(e=>{let[t,r]=e.date.split(`T`),i=new Date(t),a=parseInt(r,10),o=n?`${YUe[i.getDay()]} ${p6[a]}`:p6[a];return{...e,dateLabel:o}})},[e,u]),f=(0,y.useMemo)(()=>{if(l.length<=60)return l;let e=new Map;return l.forEach(t=>{let n=new Date(t.date),r=new Date(n);r.setDate(n.getDate()-n.getDay());let i=`${r.getFullYear()}-${String(r.getMonth()+1).padStart(2,`0`)}-${String(r.getDate()).padStart(2,`0`)}`,a=e.get(i)||{week:i,filament:0,cost:0,energy:0,prints:0};a.filament+=t.filament,a.cost+=t.cost,a.energy+=t.energy,a.prints+=t.prints,e.set(i,a)}),Array.from(e.values()).sort((e,t)=>e.week.localeCompare(t.week)).map(e=>({date:e.week,dateLabel:`Week of ${new Date(e.week).toLocaleDateString(`en-US`,{month:`short`,day:`numeric`})}`,...e}))},[l]),p=(0,y.useMemo)(()=>{let t=new Map;return e.forEach(e=>{let n=(e.filament_type||`Unknown`).split(`, `);n.forEach(r=>{let i=(e.filament_used_grams||0)/n.length;t.set(r,(t.get(r)||0)+i)})}),Array.from(t.entries()).map(([e,t])=>({name:e,value:Math.round(t)})).sort((e,t)=>t.value-e.value)},[e]),m=(0,y.useMemo)(()=>{let t=new Map;return e.forEach(e=>{(e.filament_type||`Unknown`).split(`, `).forEach(e=>{t.set(e,(t.get(e)||0)+1)})}),Array.from(t.entries()).map(([e,t])=>({name:e,value:t})).sort((e,t)=>t.value-e.value)},[e]),h=(0,y.useMemo)(()=>{let t=new Map;return e.forEach(e=>{let n=(e.filament_type||`Unknown`).split(`, `),r=(e.actual_time_seconds||e.print_time_seconds||0)/n.length;n.forEach(e=>{t.set(e,(t.get(e)||0)+r)})}),Array.from(t.entries()).map(([e,t])=>({name:e,value:Math.round(t/3600*10)/10})).sort((e,t)=>t.value-e.value)},[e]),g=(0,y.useMemo)(()=>{let t=new Map;return e.forEach(e=>{e.status!==`completed`&&e.status!==`failed`||(e.filament_type||`Unknown`).split(`, `).forEach(n=>{let r=t.get(n)||{completed:0,failed:0};e.status===`completed`?r.completed++:r.failed++,t.set(n,r)})}),Array.from(t.entries()).filter(([,e])=>e.completed+e.failed>=2).map(([e,t])=>{let n=t.completed+t.failed;return{name:e,rate:Math.round(t.completed/n*100),total:n}}).sort((e,t)=>t.rate-e.rate)},[e]),_=(0,y.useMemo)(()=>{let t=new Map;return e.forEach(e=>{if(!e.filament_color)return;let n=e.filament_color.split(`,`).map(e=>e.trim()),r=(e.filament_used_grams||0)/n.length;n.forEach(e=>{let n=t.get(e)||{count:0,weight:0};n.count++,n.weight+=r,t.set(e,n)})}),Array.from(t.entries()).map(([e,t])=>({hex:e,value:s===`prints`?t.count:Math.round(t.weight)})).sort((e,t)=>t.value-e.value)},[e,s]),v=a===`weight`?p:a===`prints`?m:h,b=u<=7&&d.length>0?d:f,x=e.reduce((e,t)=>e+(t.filament_used_grams||0),0),S=e.reduce((e,t)=>e+(t.cost||0),0),C=e.reduce((e,t)=>e+(t.energy_kwh||0),0),w=e.reduce((e,t)=>e+(t.energy_cost||0),0),T=e.reduce((e,t)=>e+(t.quantity??1),0),E=new Set(e.map(e=>e.printer_id).filter(Boolean)).size;return(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{className:`grid grid-cols-3 gap-2 max-[640px]:grid-cols-1`,children:[(0,G.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray leading-none`,children:i(`stats.periodFilament`)}),(0,G.jsx)(`p`,{className:`text-2xl font-bold text-white leading-none`,children:d6(x)})]}),(0,G.jsxs)(`p`,{className:`text-xs text-bambu-gray`,children:[E,` `,i(`nav.printers`).toLowerCase()]})]}),(0,G.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray leading-none`,children:i(`stats.periodCost`)}),(0,G.jsxs)(`p`,{className:`text-2xl font-bold text-white leading-none`,children:[t,S.toFixed(2)]})]}),(0,G.jsxs)(`p`,{className:`text-xs text-bambu-gray`,children:[T,` `,i(`common.prints`)]})]}),(0,G.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray leading-none`,children:i(`stats.avgPerPrint`)}),(0,G.jsxs)(`p`,{className:`text-2xl font-bold text-white leading-none`,children:[T>0?(x/T).toFixed(0):0,`g`]})]}),(0,G.jsxs)(`p`,{className:`text-xs text-bambu-gray`,children:[t,T>0?(S/T).toFixed(2):`0.00`,` avg`]})]})]}),b.length>0?(0,G.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4`,children:[(0,G.jsx)(`h4`,{className:`text-sm font-medium text-bambu-gray mb-4`,children:i(`stats.usageOverTime`)}),(0,G.jsx)(rA,{width:`100%`,height:250,children:(0,G.jsxs)(uH,{data:b,children:[(0,G.jsx)(`defs`,{children:(0,G.jsxs)(`linearGradient`,{id:`colorFilament`,x1:`0`,y1:`0`,x2:`0`,y2:`1`,children:[(0,G.jsx)(`stop`,{offset:`5%`,stopColor:`#00ae42`,stopOpacity:.3}),(0,G.jsx)(`stop`,{offset:`95%`,stopColor:`#00ae42`,stopOpacity:0})]})}),(0,G.jsx)(WB,{strokeDasharray:`3 3`,stroke:`#3d3d3d`}),(0,G.jsx)(bV,{dataKey:`dateLabel`,stroke:`#9ca3af`,tick:{fontSize:12},interval:`preserveStartEnd`}),(0,G.jsx)(TV,{stroke:`#9ca3af`,tick:{fontSize:12},tickFormatter:e=>`${e}g`}),(0,G.jsx)(sz,{contentStyle:{backgroundColor:`#2d2d2d`,border:`1px solid #3d3d3d`,borderRadius:`8px`},labelStyle:{color:`#fff`},formatter:e=>[`${Number(e??0).toFixed(0)}g`,`Filament`]}),(0,G.jsx)(rV,{type:`monotone`,dataKey:`filament`,stroke:`#00ae42`,strokeWidth:2,fillOpacity:1,fill:`url(#colorFilament)`})]})})]}):(0,G.jsx)(`div`,{className:`bg-bambu-dark rounded-lg p-8 text-center text-bambu-gray`,children:i(`stats.noPrintDataInRange`)}),C>0&&b.length>0&&(0,G.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-4`,children:[(0,G.jsx)(`h4`,{className:`text-sm font-medium text-bambu-gray`,children:i(`stats.energyOverTime`)}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[C.toFixed(3),` kWh · `,t,w.toFixed(2)]})]}),(0,G.jsx)(rA,{width:`100%`,height:250,children:(0,G.jsxs)(uH,{data:b,children:[(0,G.jsx)(`defs`,{children:(0,G.jsxs)(`linearGradient`,{id:`colorEnergy`,x1:`0`,y1:`0`,x2:`0`,y2:`1`,children:[(0,G.jsx)(`stop`,{offset:`5%`,stopColor:`#f59e0b`,stopOpacity:.3}),(0,G.jsx)(`stop`,{offset:`95%`,stopColor:`#f59e0b`,stopOpacity:0})]})}),(0,G.jsx)(WB,{strokeDasharray:`3 3`,stroke:`#3d3d3d`}),(0,G.jsx)(bV,{dataKey:`dateLabel`,stroke:`#9ca3af`,tick:{fontSize:12},interval:`preserveStartEnd`}),(0,G.jsx)(TV,{stroke:`#9ca3af`,tick:{fontSize:12},tickFormatter:e=>`${e}kWh`}),(0,G.jsx)(sz,{contentStyle:{backgroundColor:`#2d2d2d`,border:`1px solid #3d3d3d`,borderRadius:`8px`},labelStyle:{color:`#fff`},formatter:e=>[`${Number(e??0).toFixed(3)} kWh`,i(`stats.energyUsed`)]}),(0,G.jsx)(rV,{type:`monotone`,dataKey:`energy`,stroke:`#f59e0b`,strokeWidth:2,fillOpacity:1,fill:`url(#colorEnergy)`})]})})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-3 gap-4`,children:[(0,G.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-4`,children:[(0,G.jsx)(`h4`,{className:`text-sm font-medium text-bambu-gray`,children:i(`stats.byMaterial`)}),(0,G.jsx)(u6,{value:a,onChange:o})]}),v.length>0?(0,G.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,G.jsx)(rA,{width:160,height:160,children:(0,G.jsxs)(lH,{children:[(0,G.jsx)(TB,{data:v,cx:`50%`,cy:`50%`,innerRadius:40,outerRadius:70,paddingAngle:2,dataKey:`value`,children:v.map((e,t)=>(0,G.jsx)(cz,{fill:f6[t%f6.length]},`cell-${t}`))}),(0,G.jsx)(sz,{contentStyle:{backgroundColor:`#2d2d2d`,border:`1px solid #3d3d3d`,borderRadius:`8px`},formatter:e=>[a===`weight`?d6(Number(e??0)):a===`time`?`${Number(e??0)}h`:`${e??0}`,a===`weight`?`Usage`:a===`time`?`Time`:`Prints`]})]})}),(0,G.jsx)(`div`,{className:`flex-1 space-y-2 overflow-hidden`,children:v.map((e,t)=>{let n=v.reduce((e,t)=>e+t.value,0),r=n>0?(e.value/n*100).toFixed(0):0;return(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,G.jsx)(`div`,{className:`w-3 h-3 rounded-sm flex-shrink-0`,style:{backgroundColor:f6[t%f6.length]}}),(0,G.jsx)(`span`,{className:`text-white truncate flex-1`,children:e.name}),(0,G.jsxs)(`span`,{className:`text-bambu-gray flex-shrink-0`,children:[a===`weight`?d6(e.value):a===`time`?`${e.value}h`:e.value,` · `,r,`%`]})]},e.name)})})]}):(0,G.jsx)(`div`,{className:`h-[160px] flex items-center justify-center text-bambu-gray`,children:i(`stats.noFilamentData`)})]}),(0,G.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4`,children:[(0,G.jsx)(`h4`,{className:`text-sm font-medium text-bambu-gray mb-4`,children:i(`stats.filamentSuccess`)}),g.length>0?(0,G.jsx)(`div`,{className:`space-y-1.5`,children:g.map(e=>(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,G.jsx)(`span`,{className:`text-white truncate w-20 flex-shrink-0`,children:e.name}),(0,G.jsx)(`div`,{className:`flex-1 h-1.5 bg-bambu-dark-secondary rounded-full`,children:(0,G.jsx)(`div`,{className:`h-full rounded-full transition-all ${e.rate>=90?`bg-status-ok`:e.rate>=70?`bg-status-warning`:`bg-status-error`}`,style:{width:`${e.rate}%`}})}),(0,G.jsxs)(`span`,{className:`font-medium flex-shrink-0 tabular-nums ${e.rate>=90?`text-status-ok`:e.rate>=70?`text-status-warning`:`text-status-error`}`,children:[e.rate,`%`]}),(0,G.jsxs)(`span`,{className:`text-bambu-gray flex-shrink-0 text-xs`,children:[`(`,e.total,`)`]})]},e.name))}):(0,G.jsx)(`div`,{className:`h-[160px] flex items-center justify-center text-bambu-gray`,children:i(`stats.noArchiveData`)})]}),(0,G.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-4`,children:[(0,G.jsx)(`h4`,{className:`text-sm font-medium text-bambu-gray`,children:i(`stats.colorDistribution`)}),(0,G.jsx)(u6,{value:s,onChange:c,exclude:[`time`]})]}),_.length>0?(()=>{let e=_.reduce((e,t)=>e+t.value,0);return(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`relative mx-auto`,style:{width:160,height:160},children:[(0,G.jsx)(rA,{width:`100%`,height:`100%`,children:(0,G.jsxs)(lH,{children:[(0,G.jsx)(TB,{data:_,cx:`50%`,cy:`50%`,innerRadius:45,outerRadius:70,paddingAngle:2,dataKey:`value`,children:_.map((e,t)=>(0,G.jsx)(cz,{fill:e.hex,stroke:`#1a1a1a`,strokeWidth:1},`color-${t}`))}),(0,G.jsx)(sz,{contentStyle:{backgroundColor:`#2d2d2d`,border:`1px solid #3d3d3d`,borderRadius:`8px`},formatter:e=>[s===`weight`?d6(Number(e??0)):`${e??0}`,i(s===`weight`?`stats.filamentByWeight`:`stats.filamentByPrints`)]})]})}),(0,G.jsxs)(`div`,{className:`absolute inset-0 flex flex-col items-center justify-center`,children:[(0,G.jsx)(`span`,{className:`text-lg font-bold text-white`,children:s===`weight`?d6(e):e}),(0,G.jsxs)(`span`,{className:`text-[10px] text-bambu-gray`,children:[_.length,` `,_.length===1?`color`:`colors`]})]})]}),(0,G.jsx)(`div`,{className:`grid grid-cols-2 gap-x-3 gap-y-1 mt-2`,children:_.slice(0,8).map(t=>{let n=e>0?(t.value/e*100).toFixed(0):0;return(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 text-xs min-w-0`,children:[(0,G.jsx)(`div`,{className:`w-2.5 h-2.5 rounded-full flex-shrink-0 border border-black/20`,style:{backgroundColor:t.hex}}),(0,G.jsxs)(`span`,{className:`text-bambu-gray truncate`,children:[n,`%`]})]},t.hex)})}),_.length>8&&(0,G.jsxs)(`p`,{className:`text-[10px] text-bambu-gray mt-1 text-center`,children:[`+`,_.length-8,` more`]})]})})():(0,G.jsx)(`div`,{className:`h-[160px] flex items-center justify-center text-bambu-gray`,children:i(`stats.noColorData`)})]})]})]})}function ZUe({id:e,title:t,component:n,isHidden:r,size:i,columnSpan:a,onToggleVisibility:o,onToggleSize:s}){let{attributes:c,listeners:l,setNodeRef:u,transform:d,transition:f,isDragging:p}=V3({id:e}),m={transform:y4.Transform.toString(d),transition:f,opacity:p?.5:1};return r?null:(0,G.jsxs)(`div`,{ref:u,style:{...m,gridColumn:`span ${a}`},className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary overflow-hidden ${p?`ring-2 ring-bambu-green shadow-lg`:``}`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 border-b border-bambu-dark-tertiary bg-bambu-dark/30`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`button`,{...c,...l,className:`cursor-grab active:cursor-grabbing p-1 hover:bg-bambu-dark-tertiary rounded transition-colors`,title:`Drag to reorder`,children:(0,G.jsx)(jc,{className:`w-6 h-6 md:w-4 md:h-4 text-bambu-gray`})}),(0,G.jsx)(`h3`,{className:`text-sm font-medium text-white`,children:t})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(`button`,{onClick:s,className:`p-1 hover:bg-bambu-dark-tertiary rounded transition-colors`,title:`Size: ${i===1?`1/4`:i===2?`1/2`:`Full`} - Click to cycle`,children:i===4?(0,G.jsx)(fl,{className:`w-4 h-4 text-bambu-gray hover:text-white`}):(0,G.jsx)(cl,{className:`w-4 h-4 text-bambu-gray hover:text-white`})}),(0,G.jsx)(`button`,{onClick:o,className:`p-1 hover:bg-bambu-dark-tertiary rounded transition-colors`,title:`Hide widget`,children:(0,G.jsx)(ic,{className:`w-4 h-4 text-bambu-gray hover:text-white`})})]})]}),(0,G.jsx)(`div`,{className:`p-4`,children:typeof n==`function`?n(i):n})]})}function QUe({widgets:e,storageKey:t,columns:n=4,stackBelow:r,hideControls:i=!1,onResetLayout:a,renderControls:o}){let s=()=>{let t={};return e.forEach(e=>{t[e.id]=e.defaultSize||4}),t},[c,l]=(0,y.useState)(()=>{let n=localStorage.getItem(t);if(n)try{let e=JSON.parse(n);if(!e.sizes)e.sizes=s();else{let t=s();for(let n in t)n in e.sizes||(e.sizes[n]=t[n])}return e}catch{}return{order:e.map(e=>e.id),hidden:e.filter(e=>e.defaultVisible===!1).map(e=>e.id),sizes:s()}}),[u,d]=(0,y.useState)(!1),[f,p]=(0,y.useState)(!1);(0,y.useEffect)(()=>{if(!r)return;let e=window.matchMedia(`(max-width: ${r}px)`),t=e=>{p(e.matches)};t(e);let n=e=>t(e);return e.addEventListener?e.addEventListener(`change`,n):e.addListener(n),()=>{e.removeEventListener?e.removeEventListener(`change`,n):e.removeListener(n)}},[r]);let m=r&&f?1:n;(0,y.useEffect)(()=>{let e=()=>d(e=>!e);return window.addEventListener(`toggle-hidden-panel`,e),()=>window.removeEventListener(`toggle-hidden-panel`,e)},[]),(0,y.useEffect)(()=>{localStorage.setItem(t,JSON.stringify(c))},[c,t]),(0,y.useEffect)(()=>{let t=e.map(e=>e.id).filter(e=>!c.order.includes(e));t.length>0&&l(e=>({...e,order:[...e.order,...t]}))},[e,c.order]);let h=T4(w4(a3,{activationConstraint:{distance:8}}),w4(t3,{coordinateGetter:U3})),g=e=>{let{active:t,over:n}=e;n&&t.id!==n.id&&l(e=>{let r=e.order.indexOf(t.id),i=e.order.indexOf(n.id);return{...e,order:N3(e.order,r,i)}})},_=e=>{l(t=>({...t,hidden:t.hidden.includes(e)?t.hidden.filter(t=>t!==e):[...t.hidden,e]}))},v=e=>{l(t=>{let n=t.sizes[e]||4,r=n===1?2:n===2?4:1;return{...t,sizes:{...t.sizes,[e]:r}}})},b=()=>{l({order:e.map(e=>e.id),hidden:e.filter(e=>e.defaultVisible===!1).map(e=>e.id),sizes:s()}),a?.()},x=c.order.map(t=>e.find(e=>e.id===t)).filter(Boolean),S=x.filter(e=>!c.hidden.includes(e.id)),C=x.filter(e=>c.hidden.includes(e.id)),w=o?.({hiddenCount:C.length,showHiddenPanel:u,setShowHiddenPanel:d,resetLayout:b});return(0,G.jsxs)(`div`,{className:`space-y-4`,children:[w,!i&&!o&&(0,G.jsxs)(`div`,{className:`flex items-center justify-end gap-2`,children:[(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:b,children:[(0,G.jsx)(Wl,{className:`w-4 h-4`}),`Reset Layout`]}),C.length>0&&(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:()=>d(!u),children:[(0,G.jsx)(ac,{className:`w-4 h-4`}),C.length,` Hidden`]})]}),u&&C.length>0&&(0,G.jsxs)(`div`,{className:`p-4 bg-bambu-dark rounded-xl border border-bambu-dark-tertiary`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mb-3`,children:`Hidden widgets (click to show):`}),(0,G.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:C.map(e=>(0,G.jsxs)(`button`,{onClick:()=>_(e.id),className:`px-3 py-1.5 bg-bambu-dark-tertiary hover:bg-bambu-green/20 rounded-lg text-sm text-white transition-colors flex items-center gap-2`,children:[(0,G.jsx)(ac,{className:`w-3 h-3`}),e.title]},e.id))})]}),(0,G.jsx)(k3,{sensors:h,collisionDetection:M4,onDragEnd:g,children:(0,G.jsx)(z3,{items:S.map(e=>e.id),strategy:F3,children:(0,G.jsx)(`div`,{className:`grid gap-6`,style:{gridTemplateColumns:`repeat(${m}, minmax(0, 1fr))`},children:S.map(e=>{let t=c.sizes[e.id]||2,n=Math.min(t,m);return(0,G.jsx)(ZUe,{id:e.id,title:e.title,component:e.component,isHidden:c.hidden.includes(e.id),size:t,columnSpan:n,onToggleVisibility:()=>_(e.id),onToggleSize:()=>v(e.id)},e.id)})})})}),S.length===0&&(0,G.jsxs)(`div`,{className:`text-center py-12 text-bambu-gray`,children:[(0,G.jsx)(`p`,{children:`All widgets are hidden.`}),(0,G.jsx)(Q,{className:`mt-4`,onClick:b,children:`Reset Layout`})]})]})}function $Ue(e){let t=new Date,n=t.getUTCFullYear(),r=t.getUTCMonth(),i=t.getUTCDate(),a=e=>e.toISOString().split(`T`)[0],o=a(t);switch(e){case`today`:return{dateFrom:o,dateTo:o};case`this-week`:{let e=t.getUTCDay();return{dateFrom:a(new Date(Date.UTC(n,r,i-(e===0?6:e-1)))),dateTo:o}}case`this-month`:return{dateFrom:a(new Date(Date.UTC(n,r,1))),dateTo:o};case`last-7`:return{dateFrom:a(new Date(Date.UTC(n,r,i-6))),dateTo:o};case`last-30`:return{dateFrom:a(new Date(Date.UTC(n,r,i-29))),dateTo:o};case`last-90`:return{dateFrom:a(new Date(Date.UTC(n,r,i-89))),dateTo:o};case`this-year`:return{dateFrom:a(new Date(Date.UTC(n,0,1))),dateTo:o};case`all-time`:return{dateFrom:void 0,dateTo:void 0};case`custom`:return{}}}var eWe=[`today`,`this-week`,`this-month`,`last-7`,`last-30`,`last-90`,`this-year`,`all-time`],tWe=[`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`,`Sun`],m6=[`12am`,`1am`,`2am`,`3am`,`4am`,`5am`,`6am`,`7am`,`8am`,`9am`,`10am`,`11am`,`12pm`,`1pm`,`2pm`,`3pm`,`4pm`,`5pm`,`6pm`,`7pm`,`8pm`,`9pm`,`10pm`,`11pm`],h6=[{key:`<30m`,max:1800},{key:`30m-1h`,max:3600},{key:`1-2h`,max:7200},{key:`2-4h`,max:14400},{key:`4-8h`,max:28800},{key:`8-12h`,max:43200},{key:`12-24h`,max:86400},{key:`24h+`,max:1/0}],g6={backgroundColor:`#2d2d2d`,border:`1px solid #3d3d3d`,borderRadius:`8px`};function nWe({stats:e,currency:t}){let{t:n}=U(),r=e?.energy_data_warming_up===!0,i=r?n(`stats.energyWarmingUpTooltip`):void 0;return(0,G.jsx)(`div`,{className:`grid grid-cols-2 sm:grid-cols-3 gap-4`,children:[{icon:Cl,color:`text-bambu-green`,label:n(`stats.totalPrints`),value:`${e?.total_prints||0}`},{icon:js,color:`text-blue-600 dark:text-blue-400`,label:n(`stats.printTime`),value:`${e?.total_print_time_hours?.toFixed(1)??`0`}h`},{icon:Cl,color:`text-orange-600 dark:text-orange-400`,label:n(`stats.filamentUsed`),value:d6(e?.total_filament_grams||0)},{icon:qs,color:`text-green-600 dark:text-green-400`,label:n(`stats.filamentCost`),value:`${t} ${e?.total_cost?.toFixed(2)??`0.00`}`},{icon:id,color:`text-yellow-600 dark:text-yellow-400`,label:n(`stats.energyUsed`),value:`${e?.total_energy_kwh?.toFixed(3)??`0.000`} kWh`,warning:r,tooltip:i},{icon:qs,color:`text-yellow-500`,label:n(`stats.energyCost`),value:`${t} ${e?.total_energy_cost?.toFixed(2)??`0.00`}`,warning:r,tooltip:i}].map(e=>(0,G.jsxs)(`div`,{className:`flex items-start gap-3`,title:e.tooltip,children:[(0,G.jsx)(`div`,{className:`p-2 rounded-lg bg-bambu-dark ${e.color}`,children:(0,G.jsx)(e.icon,{className:`w-5 h-5`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`p`,{className:`text-xs text-bambu-gray flex items-center gap-1`,children:[e.label,e.warning&&(0,G.jsx)(Lu,{className:`w-3 h-3 text-yellow-600 dark:text-yellow-400`,"aria-label":e.tooltip})]}),(0,G.jsx)(`p`,{className:`text-xl font-bold text-white`,children:e.value})]})]},e.label))})}function rWe({stats:e,printerMap:t,size:n=1}){let{t:r}=U(),i=(e?.successful_prints||0)+(e?.failed_prints||0),a=i?Math.round((e?.successful_prints||0)/i*100):0,o=n===1?112:n===2?128:144,s=o/2-8,c=s*2*Math.PI;return(0,G.jsxs)(`div`,{className:`flex items-center gap-6`,children:[(0,G.jsxs)(`div`,{className:`relative flex-shrink-0`,style:{width:o,height:o},children:[(0,G.jsxs)(`svg`,{className:`w-full h-full -rotate-90`,children:[(0,G.jsx)(`circle`,{cx:o/2,cy:o/2,r:s,fill:`none`,stroke:`#3d3d3d`,strokeWidth:`10`}),(0,G.jsx)(`circle`,{cx:o/2,cy:o/2,r:s,fill:`none`,stroke:`#00ae42`,strokeWidth:`10`,strokeLinecap:`round`,strokeDasharray:`${a/100*c} ${c}`})]}),(0,G.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center`,children:(0,G.jsxs)(`span`,{className:`font-bold text-white ${n>=2?`text-2xl`:`text-xl`}`,children:[a,`%`]})})]}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(xs,{className:`w-4 h-4 text-status-ok flex-shrink-0`}),(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:r(`stats.successful`)}),(0,G.jsx)(`span`,{className:`text-sm text-white font-medium`,children:e?.successful_prints||0})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Ds,{className:`w-4 h-4 text-status-error flex-shrink-0`}),(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:r(`stats.failed`)}),(0,G.jsx)(`span`,{className:`text-sm text-white font-medium`,children:e?.failed_prints||0})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Uo,{className:`w-4 h-4 text-status-warning flex-shrink-0`}),(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:r(`stats.cancelled`)}),(0,G.jsx)(`span`,{className:`text-sm text-white font-medium`,children:e?.cancelled_prints||0})]})]}),n>=2&&e?.prints_by_printer&&Object.keys(e.prints_by_printer).length>0&&(0,G.jsxs)(`div`,{className:`mt-4 pt-4 border-t border-bambu-dark-tertiary`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray font-medium mb-2`,children:r(`stats.printsByPrinter`)}),(0,G.jsx)(`div`,{className:`grid gap-x-6 gap-y-1 ${n===4?`grid-cols-3`:`grid-cols-2`}`,style:{width:`fit-content`},children:Object.entries(e.prints_by_printer).map(([e,n])=>(0,G.jsxs)(`div`,{className:`flex items-center gap-3 text-sm`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray truncate max-w-[120px]`,children:t.get(e)||`${r(`common.printer`)} ${e}`}),(0,G.jsx)(`span`,{className:`text-white font-medium`,children:n})]},e))})]})]})]})}function iWe({stats:e,printerMap:t,size:n=1}){let{t:r}=U(),i=e?.average_time_accuracy;if(i==null)return(0,G.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,G.jsx)(`p`,{className:`text-bambu-gray text-center py-4`,children:r(`stats.noTimeAccuracyData`)})});let a=(Math.min(150,Math.max(50,i))-50)/100*100,o=(e=>e>=95&&e<=105?`#00ae42`:e>105?`#3b82f6`:`#f97316`)(i),s=i-100,c=n===1?112:n===2?128:144,l=c/2-8,u=l*2*Math.PI,d=n===1?3:n===2?6:999,f=e?.time_accuracy_by_printer?Object.entries(e.time_accuracy_by_printer).slice(0,d):[];return(0,G.jsxs)(`div`,{className:`flex items-center gap-6`,children:[(0,G.jsxs)(`div`,{className:`relative flex-shrink-0`,style:{width:c,height:c},children:[(0,G.jsxs)(`svg`,{className:`w-full h-full -rotate-90`,children:[(0,G.jsx)(`circle`,{cx:c/2,cy:c/2,r:l,fill:`none`,stroke:`#3d3d3d`,strokeWidth:`10`}),(0,G.jsx)(`circle`,{cx:c/2,cy:c/2,r:l,fill:`none`,stroke:o,strokeWidth:`10`,strokeLinecap:`round`,strokeDasharray:`${a/100*u} ${u}`})]}),(0,G.jsxs)(`div`,{className:`absolute inset-0 flex flex-col items-center justify-center`,children:[(0,G.jsxs)(`span`,{className:`font-bold text-white ${n>=2?`text-2xl`:`text-xl`}`,children:[i.toFixed(0),`%`]}),(0,G.jsxs)(`span`,{className:`text-xs ${s>=0?`text-blue-700 dark:text-blue-400`:`text-orange-700 dark:text-orange-400`}`,children:[s>=0?`+`:``,s.toFixed(0),`%`]})]})]}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-bambu-gray`,children:[(0,G.jsx)(Du,{className:`w-3 h-3 flex-shrink-0`}),(0,G.jsx)(`span`,{children:r(`stats.perfectEstimate`)})]}),f.length>0&&(0,G.jsx)(`div`,{className:`mt-2 ${n===4?`grid grid-cols-3 gap-x-6 gap-y-1`:n===2?`grid grid-cols-2 gap-x-6 gap-y-1`:`space-y-1`}`,style:{width:`fit-content`},children:f.map(([e,n])=>(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-xs`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray truncate max-w-[100px]`,children:t.get(e)||`${r(`common.printer`)} ${e}`}),(0,G.jsxs)(`span`,{className:`font-medium ${n>=95&&n<=105?`text-status-ok`:n>105?`text-blue-700 dark:text-blue-400`:`text-status-warning`}`,children:[n.toFixed(0),`%`]})]},e))})]})]})}function aWe({printDates:e,dateFrom:t,dateTo:n}){let{days:r,hourlyCounts:i,maxCount:a}=(0,y.useMemo)(()=>{let r=new Date(t+`T00:00:00`),i=new Date(n+`T00:00:00`),a=[],o=e=>`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,`0`)}-${String(e.getDate()).padStart(2,`0`)}`,s=new Date(r);for(;s<=i;)a.push({key:o(s),label:s.toLocaleDateString(void 0,{weekday:`short`,month:`short`,day:`numeric`})}),s.setDate(s.getDate()+1);let c={},l=0;return e.forEach(e=>{let t=rp(e);if(!t)return;let n=`${`${t.getFullYear()}-${String(t.getMonth()+1).padStart(2,`0`)}-${String(t.getDate()).padStart(2,`0`)}`}-${t.getHours()}`;c[n]=(c[n]||0)+1,c[n]>l&&(l=c[n])}),{days:a,hourlyCounts:c,maxCount:Math.max(1,l)}},[e,t,n]),o=e=>{if(e===0)return`bg-bambu-dark`;let t=e/a;return t<=.25?`bg-bambu-green/30`:t<=.5?`bg-bambu-green/50`:t<=.75?`bg-bambu-green/75`:`bg-bambu-green`};return(0,G.jsxs)(`div`,{className:`w-full overflow-x-auto`,children:[(0,G.jsxs)(`div`,{className:`inline-flex flex-col`,style:{gap:2},children:[(0,G.jsx)(`div`,{className:`flex`,style:{gap:2,marginLeft:84},children:m6.map((e,t)=>(0,G.jsx)(`div`,{className:`text-bambu-gray text-[10px] text-center`,style:{width:20,visibility:t%2==0?`visible`:`hidden`},children:e},t))}),r.map(e=>(0,G.jsxs)(`div`,{className:`flex items-center`,style:{gap:2},children:[(0,G.jsx)(`div`,{className:`text-bambu-gray text-[10px] flex-shrink-0 truncate`,style:{width:80},children:e.label}),Array.from({length:24},(t,n)=>{let r=i[`${e.key}-${n}`]||0;return(0,G.jsx)(`div`,{className:`rounded-sm ${o(r)}`,style:{width:20,height:20},title:`${e.label} ${m6[n]}: ${r} print${r===1?``:`s`}`},n)})]},e.key))]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mt-3 text-bambu-gray text-xs`,children:[(0,G.jsx)(`span`,{children:`Less`}),(0,G.jsxs)(`div`,{className:`flex`,style:{gap:2},children:[(0,G.jsx)(`div`,{className:`rounded-sm bg-bambu-dark`,style:{width:20,height:20}}),(0,G.jsx)(`div`,{className:`rounded-sm bg-bambu-green/30`,style:{width:20,height:20}}),(0,G.jsx)(`div`,{className:`rounded-sm bg-bambu-green/50`,style:{width:20,height:20}}),(0,G.jsx)(`div`,{className:`rounded-sm bg-bambu-green/75`,style:{width:20,height:20}}),(0,G.jsx)(`div`,{className:`rounded-sm bg-bambu-green`,style:{width:20,height:20}})]}),(0,G.jsx)(`span`,{children:`More`})]})]})}function oWe({printDates:e,size:t=2,dateFrom:n,dateTo:r}){let i=(0,y.useMemo)(()=>n&&r?Math.max((new Date(r).getTime()-new Date(n).getTime())/864e5,0)+1:n?Math.max((Date.now()-new Date(n).getTime())/864e5,0)+1:1/0,[n,r]);return i<=7&&n&&r?(0,G.jsx)(aWe,{printDates:e,dateFrom:n,dateTo:r}):(0,G.jsx)(JUe,{printDates:e,months:i===1/0?t===1?3:t===2?6:12:Math.max(1,Math.ceil(i/30))})}function sWe({stats:e,archives:t,printerMap:n}){let{t:r}=U(),[i,a]=(0,y.useState)(`weight`),[o,s]=(0,y.useState)(`weight`),c=(0,y.useMemo)(()=>{let a=new Map;return e?.prints_by_printer&&Object.entries(e.prints_by_printer).forEach(([e,t])=>{let n=a.get(e)||{prints:0,weight:0,time:0};n.prints=t,a.set(e,n)}),t.forEach(t=>{if(!t.printer_id)return;let n=String(t.printer_id),r=a.get(n)||{prints:0,weight:0,time:0};r.weight+=t.filament_used_grams||0,r.time+=t.actual_time_seconds||t.print_time_seconds||0,e?.prints_by_printer||r.prints++,a.set(n,r)}),Array.from(a.entries()).map(([e,t])=>({name:n.get(e)||`${r(`common.printer`)} ${e}`,value:i===`prints`?t.prints:i===`weight`?Math.round(t.weight):Math.round(t.time/3600*10)/10})).sort((e,t)=>t.value-e.value)},[e,t,n,i,r]),l=(0,y.useMemo)(()=>{let e=Array.from({length:24},(e,t)=>({hour:t,label:m6[t],total:0,failures:0}));return t.forEach(t=>{if(!t.started_at)return;let n=rp(t.started_at);if(!n)return;let r=n.getHours();e[r].total++,t.status===`failed`&&e[r].failures++}),e},[t]),u=(0,y.useMemo)(()=>{let e=h6.map(e=>({name:e.key,count:0}));return t.forEach(t=>{let n=t.actual_time_seconds||t.print_time_seconds;if(!(!n||n<=0)){for(let t=0;t{let e=[0,0,0,0,0,0,0],n=new Set;t.forEach(t=>{let r=rp(t.created_at)||new Date(t.created_at),i=r.getDay()-1;i<0&&(i=6),o===`prints`?e[i]++:o===`weight`?e[i]+=t.filament_used_grams||0:e[i]+=(t.actual_time_seconds||t.print_time_seconds||0)/3600;let a=new Date(r);a.setDate(r.getDate()-(r.getDay()+6)%7),n.add(`${a.getFullYear()}-${String(a.getMonth()+1).padStart(2,`0`)}-${String(a.getDate()).padStart(2,`0`)}`)});let r=Math.max(n.size,1);return tWe.map((t,n)=>({name:t,avg:Math.round(e[n]/r*10)/10}))},[t,o]),f=e=>({unit:e===`weight`?`g`:e===`time`?`h`:``,color:e===`weight`?`#00ae42`:e===`time`?`#3b82f6`:`#f59e0b`}),p=f(i),m=r(i===`weight`?`stats.filamentByWeight`:i===`time`?`stats.hours`:`common.prints`),h=f(o),g=r(o===`weight`?`stats.avgWeight`:o===`time`?`stats.avgTime`:`stats.avgPrints`);return(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,G.jsx)(`h4`,{className:`text-sm font-medium text-bambu-gray`,children:r(`stats.printsByPrinter`)}),(0,G.jsx)(u6,{value:i,onChange:a})]}),c.length>0?(0,G.jsx)(rA,{width:`100%`,height:Math.max(140,c.length*40),children:(0,G.jsxs)(iH,{data:c,layout:`vertical`,margin:{left:10},children:[(0,G.jsx)(WB,{strokeDasharray:`3 3`,stroke:`#3d3d3d`}),(0,G.jsx)(bV,{type:`number`,stroke:`#9ca3af`,tick:{fontSize:11},unit:p.unit}),(0,G.jsx)(TV,{type:`category`,dataKey:`name`,stroke:`#9ca3af`,tick:{fontSize:11},width:100}),(0,G.jsx)(sz,{contentStyle:g6,formatter:e=>[i===`weight`?d6(Number(e??0)):`${e??0}${p.unit}`,m]}),(0,G.jsx)(fV,{dataKey:`value`,fill:p.color,radius:[0,4,4,0]})]})}):(0,G.jsx)(`p`,{className:`text-bambu-gray text-center py-4`,children:r(`stats.noPrinterData`)})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-3 gap-4`,children:[(0,G.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4`,children:[(0,G.jsx)(`h4`,{className:`text-sm font-medium text-bambu-gray mb-3`,children:r(`stats.printDuration`)}),t.length>0?(0,G.jsx)(rA,{width:`100%`,height:160,children:(0,G.jsxs)(iH,{data:u,children:[(0,G.jsx)(WB,{strokeDasharray:`3 3`,stroke:`#3d3d3d`}),(0,G.jsx)(bV,{dataKey:`name`,stroke:`#9ca3af`,tick:{fontSize:11}}),(0,G.jsx)(TV,{stroke:`#9ca3af`,tick:{fontSize:11},allowDecimals:!1}),(0,G.jsx)(sz,{contentStyle:g6}),(0,G.jsx)(fV,{dataKey:`count`,name:r(`common.prints`),fill:`#00ae42`,radius:[4,4,0,0]})]})}):(0,G.jsx)(`p`,{className:`text-bambu-gray text-center py-4`,children:r(`stats.noArchiveData`)})]}),(0,G.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,G.jsx)(`h4`,{className:`text-sm font-medium text-bambu-gray`,children:r(`stats.printHabits`)}),(0,G.jsx)(u6,{value:o,onChange:s})]}),t.length>0?(0,G.jsx)(rA,{width:`100%`,height:160,children:(0,G.jsxs)(iH,{data:d,children:[(0,G.jsx)(WB,{strokeDasharray:`3 3`,stroke:`#3d3d3d`}),(0,G.jsx)(bV,{dataKey:`name`,stroke:`#9ca3af`,tick:{fontSize:11}}),(0,G.jsx)(TV,{stroke:`#9ca3af`,tick:{fontSize:11},unit:h.unit}),(0,G.jsx)(sz,{contentStyle:g6,formatter:e=>[`${e??0}${h.unit}`,g]}),(0,G.jsx)(fV,{dataKey:`avg`,fill:h.color,radius:[4,4,0,0]})]})}):(0,G.jsx)(`p`,{className:`text-bambu-gray text-center py-4`,children:r(`stats.noArchiveData`)})]}),(0,G.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4`,children:[(0,G.jsx)(`h4`,{className:`text-sm font-medium text-bambu-gray mb-3`,children:r(`stats.printTimeOfDay`)}),t.length>0?(0,G.jsx)(rA,{width:`100%`,height:160,children:(0,G.jsxs)(iH,{data:l,children:[(0,G.jsx)(WB,{strokeDasharray:`3 3`,stroke:`#3d3d3d`}),(0,G.jsx)(bV,{dataKey:`label`,stroke:`#9ca3af`,tick:{fontSize:10},interval:5}),(0,G.jsx)(TV,{stroke:`#9ca3af`,tick:{fontSize:11},allowDecimals:!1}),(0,G.jsx)(sz,{contentStyle:g6}),(0,G.jsx)(fV,{dataKey:`total`,name:r(`stats.totalPrints`),fill:`#00ae42`,radius:[2,2,0,0]}),(0,G.jsx)(fV,{dataKey:`failures`,name:r(`stats.failed`),fill:`#ef4444`,radius:[2,2,0,0]})]})}):(0,G.jsx)(`p`,{className:`text-bambu-gray text-center py-4`,children:r(`stats.noArchiveData`)})]})]})]})}function cWe({archives:e,currency:t,dateFrom:n,dateTo:r}){let{t:i}=U();return!e||e.length===0?(0,G.jsx)(`p`,{className:`text-bambu-gray text-center py-4`,children:i(`stats.noPrintData`)}):(0,G.jsx)(XUe,{archives:e,currency:t,dateFrom:n,dateTo:r})}function lWe({size:e=1,dateFrom:t,dateTo:n,createdById:r}){let{t:i}=U(),a=!!(t||n),{data:o,isLoading:s}=K({queryKey:[`failureAnalysis`,t,n,r??`all`],queryFn:()=>Z.getFailureAnalysis({...a?{dateFrom:t,dateTo:n}:{days:30},createdById:r})});if(s)return(0,G.jsx)(`div`,{className:`flex justify-center py-4`,children:(0,G.jsx)(Y,{className:`w-6 h-6 text-bambu-green animate-spin`})});if(!o||o.total_prints===0)return(0,G.jsx)(`p`,{className:`text-bambu-gray text-center py-4`,children:i(a?`stats.noPrintDataInRange`:`stats.noPrintDataLast30Days`)});let c=e===1?5:e===2?8:999,l=Object.entries(o.failures_by_reason).sort(([,e],[,t])=>t-e),u=l.slice(0,c),d=l.length>c;return(0,G.jsxs)(`div`,{className:`${e>=2?`flex gap-8`:`space-y-4`}`,children:[(0,G.jsxs)(`div`,{className:e>=2?`flex-shrink-0`:``,children:[(0,G.jsx)(`div`,{className:`flex items-center gap-4`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Lu,{className:`w-5 h-5 ${o.failure_rate>20?`text-status-error`:o.failure_rate>10?`text-status-warning`:`text-status-ok`}`}),(0,G.jsxs)(`span`,{className:`font-bold text-white ${e>=2?`text-3xl`:`text-2xl`}`,children:[o.failure_rate.toFixed(1),`%`]})]})}),(0,G.jsx)(`div`,{className:`text-sm text-bambu-gray mt-1`,children:i(`stats.failedPrintsCount`,{failed:o.failed_prints,total:o.total_prints})}),o.trend&&o.trend.length>=2&&(0,G.jsx)(`div`,{className:`${e>=2?`mt-4`:`mt-2 pt-2 border-t border-bambu-dark-tertiary`}`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,G.jsx)(Fu,{className:`w-4 h-4 ${o.trend[o.trend.length-1].failure_rate0&&(0,G.jsxs)(`div`,{className:`flex-1 ${e>=2?`border-l border-bambu-dark-tertiary pl-8`:`pt-2`}`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray font-medium mb-2`,children:i(e>=2?`stats.failureReasons`:`stats.topFailureReasons`)}),(0,G.jsx)(`div`,{className:`${e===4?`grid grid-cols-2 gap-x-6 gap-y-1`:`space-y-1`}`,children:u.map(([t,n])=>(0,G.jsxs)(`div`,{className:`flex items-center justify-between text-sm`,children:[(0,G.jsx)(`span`,{className:`text-white truncate ${e===4?`max-w-[200px]`:`max-w-[160px]`}`,children:t?i(`editArchive.failureReasons.${t}`,{defaultValue:t}):i(`common.unknown`)}),(0,G.jsx)(`span`,{className:`text-bambu-gray ml-2`,children:n})]},t))}),d&&(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-2`,children:i(`common.more`,{count:l.length-c})})]})]})}function uWe({archives:e,currency:t}){let{t:n}=U(),r=(0,y.useMemo)(()=>{let r=[];if(e.length===0)return r;let i=t=>{let n=null,r=0;return e.forEach(e=>{let i=t(e);i&&i>r&&(r=i,n=e)}),{archive:n,value:r}},a=i(e=>e.status===`completed`?e.actual_time_seconds:null);a.archive&&r.push({icon:js,iconColor:`text-blue-600 dark:text-blue-400`,label:n(`stats.longestPrint`),value:lp(a.value),detail:a.archive.print_name||null});let o=i(e=>e.filament_used_grams);o.archive&&r.push({icon:Cl,iconColor:`text-orange-600 dark:text-orange-400`,label:n(`stats.heaviestPrint`),value:d6(o.value),detail:o.archive.print_name||null});let s=i(e=>(e.cost??0)+(e.energy_cost??0));s.archive&&r.push({icon:qs,iconColor:`text-green-600 dark:text-green-400`,label:n(`stats.mostExpensivePrint`),value:`${t}${s.value.toFixed(2)}`,detail:s.archive.print_name||null});let c=new Map;e.forEach(e=>{let t=rp(e.created_at)||new Date(e.created_at),n=`${t.getFullYear()}-${String(t.getMonth()+1).padStart(2,`0`)}-${String(t.getDate()).padStart(2,`0`)}`;c.set(n,(c.get(n)||0)+1)});let l=``,u=0;c.forEach((e,t)=>{e>u&&(u=e,l=t)}),u>1&&r.push({icon:as,iconColor:`text-purple-600 dark:text-purple-400`,label:n(`stats.busiestDay`),value:`${u} ${n(`common.prints`)}`,detail:(()=>{let[e,t,n]=l.split(`-`).map(Number);return new Date(e,t-1,n).toLocaleDateString(void 0,{month:`short`,day:`numeric`,year:`numeric`})})()});let d=[...e].filter(e=>e.status===`completed`||e.status===`failed`).sort((e,t)=>new Date(t.completed_at||t.created_at).getTime()-new Date(e.completed_at||e.created_at).getTime()),f=0;for(let e of d)if(e.status===`completed`)f++;else break;return f>0&&r.push({icon:id,iconColor:`text-yellow-600 dark:text-yellow-400`,label:n(`stats.successStreak`),value:`${f}`,detail:f===1?n(`stats.streakPrint`):n(`stats.streakPrints`,{count:f})}),r},[e,t,n]);return r.length===0?(0,G.jsx)(`p`,{className:`text-bambu-gray text-center py-4`,children:n(`stats.noArchiveData`)}):(0,G.jsx)(`div`,{className:`space-y-3`,children:r.map((e,t)=>(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`p-1.5 rounded-lg bg-bambu-dark ${e.iconColor}`,children:(0,G.jsx)(e.icon,{className:`w-4 h-4`})}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:e.label}),(0,G.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,G.jsx)(`span`,{className:`text-sm font-bold text-white`,children:e.value}),e.detail&&(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray truncate`,children:e.detail})]})]})]},t))})}function dWe(){let{t:e}=U(),{showToast:t}=qd(),{hasPermission:n,authEnabled:r}=Nd(),[i,a]=(0,y.useState)(!1),[o,s]=(0,y.useState)(!1),[c,l]=(0,y.useState)(0),[u,d]=(0,y.useState)(0),[f,p]=(0,y.useState)(!1),[m,h]=(0,y.useState)(null),[g,_]=(0,y.useState)(!1),v=r&&n(`stats:filter_by_user`),[b,x]=(0,y.useState)(()=>{try{let e=localStorage.getItem(`bambusy-stats-timeframe`);if(e){let t=JSON.parse(e);if(t.preset)return t}}catch{}return{preset:`all-time`,dateFrom:void 0,dateTo:void 0}}),[S,C]=(0,y.useState)(!1);(0,y.useEffect)(()=>{localStorage.setItem(`bambusy-stats-timeframe`,JSON.stringify(b))},[b]);let w=(0,y.useMemo)(()=>b.preset===`custom`?{dateFrom:b.dateFrom,dateTo:b.dateTo}:$Ue(b.preset),[b]);(0,y.useEffect)(()=>{let e=()=>{try{let e=localStorage.getItem(`bambusy-dashboard-layout-v2`);e&&d(JSON.parse(e).hidden?.length||0)}catch{d(0)}};e(),window.addEventListener(`storage`,e);let t=setInterval(e,2e3);return()=>{window.removeEventListener(`storage`,e),clearInterval(t)}},[c]);let T=m===null?void 0:m,{data:E,isLoading:D,isFetching:O,refetch:k}=K({queryKey:[`archiveStats`,w.dateFrom,w.dateTo,T??`all`],queryFn:()=>Z.getArchiveStats({dateFrom:w.dateFrom,dateTo:w.dateTo,createdById:T})}),{data:A}=K({queryKey:[`printers`],queryFn:Z.getPrinters}),{data:j,isFetching:M,refetch:N}=K({queryKey:[`archivesSlim`,w.dateFrom,w.dateTo,T??`all`],queryFn:()=>Z.getArchivesSlim(w.dateFrom,w.dateTo,T)}),{data:P}=K({queryKey:[`settings`],queryFn:Z.getSettings}),{data:F}=K({queryKey:[`users`,`slim`],queryFn:Z.getUsersSlim,enabled:v}),I=(0,y.useMemo)(()=>m===null?e(`stats.allUsers`,`All Users`):m===-1?e(`stats.noUser`,`No User (System)`):F?.find(e=>e.id===m)?.username??`?`,[m,F,e]),L=async n=>{s(!1),a(!0);try{let{blob:r,filename:i}=await Z.exportStats({format:n,days:90,createdById:T}),a=URL.createObjectURL(r),o=document.createElement(`a`);o.href=a,o.download=i,o.click(),URL.revokeObjectURL(a),t(e(`stats.exportDownloaded`))}catch{t(e(`stats.exportFailed`),`error`)}finally{a(!1)}},R=async()=>{p(!0);try{let n=await Z.recalculateCosts();await Promise.all([k(),N()]),t(e(`stats.recalculatedCosts`,{count:n.updated}))}catch{t(e(`stats.recalculateFailed`),`error`)}finally{p(!1)}},z=(O||M)&&!D,B=Lf(P?.currency||`USD`),V=(0,y.useMemo)(()=>new Map([...Object.entries(E?.printer_names||{}),...A?.map(e=>[String(e.id),e.name])||[]]),[E?.printer_names,A]),ee=(0,y.useMemo)(()=>j?.map(e=>e.created_at)||[],[j]);if(D)return(0,G.jsx)(`div`,{className:`p-4 md:p-8`,children:(0,G.jsx)(`div`,{className:`text-center py-12 text-bambu-gray`,children:e(`stats.loadingStats`)})});let te=[{id:`quick-stats`,title:e(`stats.quickStats`),component:(0,G.jsx)(nWe,{stats:E,currency:B}),defaultSize:2},{id:`success-rate`,title:e(`stats.successRate`),component:e=>(0,G.jsx)(rWe,{stats:E,printerMap:V,size:e}),defaultSize:1},{id:`time-accuracy`,title:e(`stats.timeAccuracy`),component:e=>(0,G.jsx)(iWe,{stats:E,printerMap:V,size:e}),defaultSize:1},{id:`failure-analysis`,title:e(`stats.failureAnalysis`),component:e=>(0,G.jsx)(lWe,{size:e,dateFrom:w.dateFrom,dateTo:w.dateTo,createdById:T}),defaultSize:1},{id:`print-activity`,title:e(`stats.printActivity`),component:e=>(0,G.jsx)(oWe,{printDates:ee,size:e,dateFrom:w.dateFrom,dateTo:w.dateTo}),defaultSize:2},{id:`records`,title:e(`stats.records`),component:(0,G.jsx)(uWe,{archives:j||[],currency:B}),defaultSize:1},{id:`printer-stats`,title:e(`stats.printerStats`),component:(0,G.jsx)(sWe,{stats:E,archives:j||[],printerMap:V}),defaultSize:4},{id:`filament-trends`,title:e(`stats.filamentTrends`),component:(0,G.jsx)(cWe,{archives:j||[],currency:B,dateFrom:w.dateFrom,dateTo:w.dateTo}),defaultSize:4}];return(0,G.jsxs)(`div`,{className:`p-4 md:p-8`,children:[(0,G.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4 mb-6`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,G.jsx)(cs,{className:`w-7 h-7 text-bambu-green`}),e(`stats.title`)]}),z&&(0,G.jsx)(Y,{className:`w-5 h-5 text-bambu-green animate-spin`})]}),(0,G.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:e(`stats.subtitle`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[u>0&&(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>{window.dispatchEvent(new CustomEvent(`toggle-hidden-panel`))},children:[(0,G.jsx)(ac,{className:`w-4 h-4`}),e(`stats.hiddenCount`,{count:u})]}),(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>{localStorage.removeItem(`bambusy-dashboard-layout-v2`),l(e=>e+1),t(e(`stats.layoutReset`))},disabled:!n(`settings:update`),title:n(`settings:update`)?void 0:e(`stats.noPermissionResetLayout`),children:[(0,G.jsx)(Wl,{className:`w-4 h-4`}),e(`stats.resetLayout`)]}),(0,G.jsxs)(Q,{variant:`secondary`,onClick:R,disabled:f||!n(`archives:update_all`),title:n(`archives:update_all`)?e(`stats.recalculateCostsHint`):e(`stats.noPermissionRecalculate`),children:[f?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(ns,{className:`w-4 h-4`}),e(`stats.recalculateCosts`)]}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>s(!o),disabled:i,children:[i?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(dc,{className:`w-4 h-4`}),e(`stats.exportStats`)]}),o&&(0,G.jsxs)(`div`,{className:`absolute right-0 top-full mt-1 w-48 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl z-20`,children:[(0,G.jsxs)(`button`,{className:`w-full px-4 py-2 text-left text-white hover:bg-bambu-dark-tertiary transition-colors flex items-center gap-2 rounded-t-lg`,onClick:()=>L(`csv`),children:[(0,G.jsx)(fc,{className:`w-4 h-4`}),e(`stats.exportAsCsv`)]}),(0,G.jsxs)(`button`,{className:`w-full px-4 py-2 text-left text-white hover:bg-bambu-dark-tertiary transition-colors flex items-center gap-2 rounded-b-lg`,onClick:()=>L(`xlsx`),children:[(0,G.jsx)(dc,{className:`w-4 h-4`}),e(`stats.exportAsExcel`)]})]})]}),v&&F&&F.length>0&&(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>_(!g),children:[(0,G.jsx)(Uu,{className:`w-4 h-4`}),I,(0,G.jsx)(ps,{className:`w-3 h-3`})]}),g&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`fixed inset-0 z-10`,onClick:()=>_(!1)}),(0,G.jsxs)(`div`,{className:`absolute right-0 top-full mt-1 w-48 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl z-20 p-2 max-h-64 overflow-y-auto`,children:[(0,G.jsx)(`button`,{className:`w-full px-3 py-2 text-left text-sm rounded-md transition-colors ${m===null?`bg-bambu-green text-white`:`text-white hover:bg-bambu-dark-tertiary`}`,onClick:()=>{h(null),_(!1)},children:e(`stats.allUsers`,`All Users`)}),(0,G.jsx)(`button`,{className:`w-full px-3 py-2 text-left text-sm rounded-md transition-colors ${m===-1?`bg-bambu-green text-white`:`text-white hover:bg-bambu-dark-tertiary`}`,onClick:()=>{h(-1),_(!1)},children:e(`stats.noUser`,`No User (System)`)}),(0,G.jsx)(`div`,{className:`border-t border-bambu-dark-tertiary my-1`}),F.map(e=>(0,G.jsx)(`button`,{className:`w-full px-3 py-2 text-left text-sm rounded-md transition-colors ${m===e.id?`bg-bambu-green text-white`:`text-white hover:bg-bambu-dark-tertiary`}`,onClick:()=>{h(e.id),_(!1)},children:e.username},e.id))]})]})]}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>C(!S),children:[(0,G.jsx)(as,{className:`w-4 h-4`}),e(`stats.timeframe.${b.preset}`),(0,G.jsx)(ps,{className:`w-3 h-3`})]}),S&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`fixed inset-0 z-10`,onClick:()=>C(!1)}),(0,G.jsxs)(`div`,{className:`absolute right-0 top-full mt-1 w-64 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl z-20 p-2`,children:[eWe.map(t=>(0,G.jsx)(`button`,{className:`w-full px-3 py-2 text-left text-sm rounded-md transition-colors ${b.preset===t?`bg-bambu-green text-white`:`text-white hover:bg-bambu-dark-tertiary`}`,onClick:()=>{x({preset:t,dateFrom:void 0,dateTo:void 0}),C(!1)},children:e(`stats.timeframe.${t}`)},t)),(0,G.jsx)(`div`,{className:`border-t border-bambu-dark-tertiary my-2`}),(0,G.jsx)(`button`,{className:`w-full px-3 py-2 text-left text-sm rounded-md transition-colors ${b.preset===`custom`?`bg-bambu-green text-white`:`text-white hover:bg-bambu-dark-tertiary`}`,onClick:()=>x(e=>({...e,preset:`custom`})),children:e(`stats.timeframe.custom`)}),b.preset===`custom`&&(0,G.jsxs)(`div`,{className:`mt-2 px-1 pb-1 space-y-2`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`text-xs text-bambu-gray block mb-1`,children:e(`stats.timeframe.from`)}),(0,G.jsx)(`input`,{type:`date`,value:b.dateFrom||``,max:b.dateTo||new Date().toISOString().split(`T`)[0],onChange:e=>x(t=>({...t,dateFrom:e.target.value||void 0})),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded-md px-3 py-1.5 text-sm text-white`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`text-xs text-bambu-gray block mb-1`,children:e(`stats.timeframe.to`)}),(0,G.jsx)(`input`,{type:`date`,value:b.dateTo||``,min:b.dateFrom,max:new Date().toISOString().split(`T`)[0],onChange:e=>x(t=>({...t,dateTo:e.target.value||void 0})),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded-md px-3 py-1.5 text-sm text-white`})]}),(0,G.jsx)(Q,{variant:`primary`,onClick:()=>C(!1),className:`w-full`,children:e(`common.apply`)})]})]})]})]})]})]}),(0,G.jsx)(QUe,{widgets:te,storageKey:`bambusy-dashboard-layout-v2`,stackBelow:640,hideControls:!0},c)]})}function _6(e){return e.length<8?`tooShort`:/[A-Z]/.test(e)?/[a-z]/.test(e)?/\d/.test(e)?/[^A-Za-z0-9]/.test(e)?null:`needsSpecial`:`needsDigit`:`needsLowercase`:`needsUppercase`}var v6=[`inventory-locations`];function y6(e){return e.invalidateQueries({queryKey:v6})}function b6(e,t){return Promise.all([e.invalidateQueries({queryKey:[...t]}),y6(e)])}var x6=`bambuddy-location-sensor-show-on-card-defaults`,S6={alertAbove:``,alertBelow:``,notifyOnAlert:!1,showOnCard:!0};function fWe(){return{temperature:{...S6,alertAbove:`30`,alertBelow:`20`},humidity:{...S6,alertAbove:`30`,alertBelow:`10`},battery:{...S6,alertBelow:`10`}}}function pWe(){try{let e=localStorage.getItem(x6);return e?JSON.parse(e):{}}catch{return{}}}function C6(e){let t=fWe();if(e)try{let n=JSON.parse(e);Object.keys(t).forEach(e=>{let r=n[e];r&&(typeof r.alertAbove==`string`&&(t[e].alertAbove=r.alertAbove),typeof r.alertBelow==`string`&&(t[e].alertBelow=r.alertBelow),typeof r.notifyOnAlert==`boolean`&&(t[e].notifyOnAlert=r.notifyOnAlert))})}catch{}let n=pWe();return Object.keys(t).forEach(e=>{typeof n[e]==`boolean`&&(t[e].showOnCard=n[e])}),t}function mWe(e){let t={};return Object.keys(e).forEach(n=>{t[n]={alertAbove:e[n].alertAbove,alertBelow:e[n].alertBelow,notifyOnAlert:e[n].notifyOnAlert}}),JSON.stringify(t)}function hWe(e){try{let t={};Object.keys(e).forEach(n=>{t[n]=e[n].showOnCard}),localStorage.setItem(x6,JSON.stringify(t))}catch{return}}var w6=`bambuddy-location-sensor-colorize-values`;function T6(){try{let e=localStorage.getItem(w6);return e?e===`true`:!0}catch{return!0}}var E6=`bambuddy:location-sensor-color-prefs-changed`;function D6(){window.dispatchEvent(new Event(E6))}function gWe(e){try{localStorage.setItem(w6,String(e))}catch{return}D6()}var O6=[`red`,`orange`,`yellow`,`green`,`blue`,`purple`,`pink`],k6={red:`text-red-400`,orange:`text-orange-400`,yellow:`text-yellow-400`,green:`text-green-400`,blue:`text-blue-400`,purple:`text-purple-400`,pink:`text-pink-400`},A6=`bambuddy-location-sensor-alert-above-color`,j6=`bambuddy-location-sensor-alert-below-color`,M6=`bambuddy-location-sensor-alert-optimal-color`;function N6(e){return!!e&&O6.includes(e)}function P6(){try{let e=localStorage.getItem(A6);return N6(e)?e:`purple`}catch{return`purple`}}function _We(e){try{localStorage.setItem(A6,e)}catch{return}D6()}function F6(){try{let e=localStorage.getItem(j6);return N6(e)?e:`red`}catch{return`red`}}function vWe(e){try{localStorage.setItem(j6,e)}catch{return}D6()}function I6(){try{let e=localStorage.getItem(M6);return N6(e)?e:`green`}catch{return`green`}}function yWe(e){try{localStorage.setItem(M6,e)}catch{return}D6()}function L6(){return{colorize:T6(),aboveColor:P6(),belowColor:F6(),optimalColor:I6()}}function R6(){let[e,t]=(0,y.useState)(L6);return(0,y.useEffect)(()=>{let e=()=>t(L6());return window.addEventListener(E6,e),()=>window.removeEventListener(E6,e)},[]),e}function z6(e){return!e.reachable||e.state===null?null:e.kind===`numeric`?e.alert_above===null&&e.alert_below===null||e.value===null?null:e.alert_above!==null&&e.value>e.alert_above?`above`:e.alert_below!==null&&e.value{let r=Math.max(0,Math.min(65,Math.round(n)));t(xWe({...i,[e]:r}))};return(0,G.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-x-3 gap-y-1.5`,children:H6.map(e=>{let t=i[e]??V6[e]??0,o=e==="default"?r(`settings.preheatFilamentTargetsDefaultRow`,`Other / unmapped`):e;return(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,G.jsx)(`span`,{className:`text-xs ${e==="default"?`text-bambu-gray italic`:`text-bambu-gray`}`,children:o}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(`input`,{type:`number`,min:0,max:65,step:1,value:t,onChange:t=>a(e,parseInt(t.target.value,10)||0),disabled:n,className:`w-16 px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-xs text-right focus:outline-none focus:border-bambu-green disabled:opacity-50`}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:`°C`})]})]},e)})})}function U6(e,t,n){if(!e)return null;let r=(e[n.source]?.[t]??[]).find(e=>e.id===n.id);return r?r.name:null}var CWe={orca_cloud:`Orca Cloud`,cloud:`Bambu Cloud`,local:`Imported`,standard:`Standard`};function wWe(){let{t:e}=U(),t=co(),{showToast:n}=qd(),{data:r,isLoading:i,error:a}=K({queryKey:[`slicer-pipelines`],queryFn:()=>Z.listSlicerPipelines()}),{data:o}=K({queryKey:[`slicer-presets`],queryFn:()=>Z.getSlicerPresets()}),{data:s}=K({queryKey:[`printers`],queryFn:()=>Z.getPrinters()}),c=q({mutationFn:({id:e,name:t,description:n,target_printer_id:r,target_kind:i,target_model_class:a,fanout_strategy:o})=>Z.updateSlicerPipeline(e,{name:t,description:n,target_printer_id:r,target_kind:i,target_model_class:a,fanout_strategy:o}),onSuccess:()=>{t.invalidateQueries({queryKey:[`slicer-pipelines`]}),n(e(`settings.pipelines.toast.saved`,`Pipeline saved`),`success`)},onError:t=>{n(t.message||e(`settings.pipelines.toast.saveFailed`,`Save failed`),`error`)}}),l=q({mutationFn:e=>Z.deleteSlicerPipeline(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`slicer-pipelines`]}),n(e(`settings.pipelines.toast.deleted`,`Pipeline deleted`),`success`)},onError:t=>{n(t.message||e(`settings.pipelines.toast.deleteFailed`,`Delete failed`),`error`)}}),[u,d]=(0,y.useState)(``),[f,p]=(0,y.useState)(``),m=(0,y.useMemo)(()=>r?.pipelines??[],[r?.pipelines]),h=(0,y.useMemo)(()=>{let e=new Set,t=new Set,n=!1;for(let r of m)r.target_kind===`printer_class`&&r.target_model_class?t.add(r.target_model_class):r.target_printer_id?e.add(r.target_printer_id):n=!0;return{printers:(s??[]).filter(t=>e.has(t.id)),classes:Array.from(t).sort(),anyWithoutTarget:n}},[m,s]),g=(0,y.useMemo)(()=>{let e=u.trim().toLowerCase();return m.filter(t=>{if(e&&!t.name.toLowerCase().includes(e))return!1;if(f===`none`){if(t.target_kind===`printer_class`?t.target_model_class:t.target_printer_id!==null)return!1}else if(f.startsWith(`p:`)){let e=parseInt(f.slice(2),10);if(t.target_kind===`printer_class`||t.target_printer_id!==e)return!1}else if(f.startsWith(`c:`)){let e=f.slice(2);if(t.target_kind!==`printer_class`||t.target_model_class!==e)return!1}return!0})},[m,u,f]);return(0,G.jsxs)(zd,{children:[(0,G.jsxs)(Bd,{children:[(0,G.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(ed,{className:`w-4 h-4 text-bambu-green`}),e(`settings.pipelines.title`,`Slicer Pipelines`)]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`settings.pipelines.subtitle`,`Reusable preset bundles (printer + process + filaments + bed type). Save one from the Slice dialog and apply it with a single click on the next file.`)})]}),(0,G.jsxs)(Vd,{children:[i&&(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`}),e(`settings.pipelines.loading`,`Loading pipelines…`)]}),a&&(0,G.jsx)(`div`,{className:`text-sm text-red-700 dark:text-red-400`,children:e(`settings.pipelines.loadError`,`Could not load pipelines.`)}),!i&&!a&&m.length>0&&(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 mb-3`,children:[(0,G.jsxs)(`div`,{className:`relative flex-1 min-w-[12rem]`,children:[(0,G.jsx)(Ql,{className:`absolute left-2 top-1/2 -translate-y-1/2 w-3.5 h-3.5 text-bambu-gray pointer-events-none`}),(0,G.jsx)(`input`,{type:`search`,value:u,onChange:e=>d(e.target.value),placeholder:e(`settings.pipelines.searchPlaceholder`,`Search pipelines…`),"aria-label":e(`settings.pipelines.searchPlaceholder`,`Search pipelines…`),className:`w-full pl-7 pr-2 py-1 text-xs bg-bambu-dark border border-bambu-dark-tertiary rounded text-white`})]}),(0,G.jsxs)(`select`,{value:f,onChange:e=>p(e.target.value),"aria-label":e(`settings.pipelines.filterTarget`,`Filter by target`),className:`text-xs px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white`,children:[(0,G.jsx)(`option`,{value:``,children:e(`settings.pipelines.filter.all`,`All targets`)}),h.printers.length>0&&(0,G.jsx)(`optgroup`,{label:e(`settings.pipelines.field.targetKindSpecific`,`Specific printer`),children:h.printers.map(e=>(0,G.jsx)(`option`,{value:`p:${e.id}`,children:e.name},`p-${e.id}`))}),h.classes.length>0&&(0,G.jsx)(`optgroup`,{label:e(`settings.pipelines.field.targetKindClass`,`Printer class`),children:h.classes.map(t=>(0,G.jsx)(`option`,{value:`c:${t}`,children:e(`library.runWithPipeline.classTarget`,`Any {{model}}`,{model:t})},`c-${t}`))}),h.anyWithoutTarget&&(0,G.jsx)(`option`,{value:`none`,children:e(`settings.pipelines.filter.noTarget`,`No target set`)})]}),(u||f)&&(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:e(`settings.pipelines.filter.count`,`{{shown}} / {{total}}`,{shown:g.length,total:m.length})})]}),!i&&!a&&m.length===0&&(0,G.jsxs)(`div`,{className:`text-sm text-bambu-gray space-y-2`,children:[(0,G.jsx)(`p`,{children:e(`settings.pipelines.empty.title`,`No pipelines yet.`)}),(0,G.jsx)(`p`,{children:e(`settings.pipelines.empty.howto`,`Open the Slice dialog for any file, pick your printer / process / filaments / bed type, then click "Save as pipeline". Your saved pipelines will appear here.`)})]}),!i&&!a&&m.length>0&&g.length===0&&(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`settings.pipelines.filter.noMatches`,`No pipelines match the current filters.`)}),!i&&!a&&g.length>0&&(0,G.jsx)(`div`,{className:`space-y-2`,children:g.map(t=>(0,G.jsx)(TWe,{pipeline:t,presets:o,printers:s??[],onSave:e=>c.mutate({id:t.id,...e}),onDelete:()=>{confirm(e(`settings.pipelines.confirmDelete`,`Delete this pipeline? This cannot be undone.`))&&l.mutate(t.id)},saving:c.isPending,deleting:l.isPending},t.id))})]})]})}function TWe({pipeline:e,presets:t,printers:n,onSave:r,onDelete:i,saving:a,deleting:o}){let{t:s}=U(),[c,l]=(0,y.useState)(!1),[u,d]=(0,y.useState)(e.name),[f,p]=(0,y.useState)(e.description??``),[m,h]=(0,y.useState)(e.target_printer_id),[g,_]=(0,y.useState)(e.target_kind===`printer_class`?`printer_class`:`specific_printer`),[v,b]=(0,y.useState)(e.target_model_class??``),[x,S]=(0,y.useState)(e.fanout_strategy??`max_parallel`),C=Array.from(new Set(n.map(e=>e.model).filter(e=>!!e))).sort(),{data:w}=K({queryKey:[`pipeline-runs`,e.id],queryFn:()=>Z.listPipelineRuns(e.id,1),enabled:!c,refetchInterval:15e3}),T=w?.runs?.[0],E=U6(t,`printer`,e.printer_preset),D=U6(t,`process`,e.process_preset),O=e.filament_presets.map(e=>U6(t,`filament`,e)),k=e.filament_presets.length>1&&e.filament_presets.every(t=>t.source===e.filament_presets[0].source&&t.id===e.filament_presets[0].id),A=t!==void 0&&(E===null||D===null||O.some(e=>e===null)),j=e.target_printer_id?n.find(t=>t.id===e.target_printer_id):void 0,M=e.target_kind===`printer_class`,N=M?!e.target_model_class:e.target_printer_id===null;return(0,G.jsxs)(`div`,{className:`rounded-md border border-bambu-dark-tertiary bg-bambu-dark/40 px-3 py-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,G.jsx)(`div`,{className:`min-w-0 flex-1`,children:c?(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`input`,{value:u,onChange:e=>d(e.target.value),"aria-label":s(`settings.pipelines.field.name`,`Pipeline name`),placeholder:s(`settings.pipelines.field.name`,`Pipeline name`),className:`w-full px-2 py-1 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded text-white`}),(0,G.jsx)(`textarea`,{value:f,onChange:e=>p(e.target.value),"aria-label":s(`settings.pipelines.field.description`,`Description`),placeholder:s(`settings.pipelines.field.description`,`Description`),rows:2,className:`w-full px-2 py-1 text-xs bg-bambu-dark border border-bambu-dark-tertiary rounded text-white`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`text-xs text-bambu-gray block mb-1`,children:s(`settings.pipelines.field.targetKind`,`Target type`)}),(0,G.jsxs)(`div`,{className:`flex gap-3 text-xs`,children:[(0,G.jsxs)(`label`,{className:`flex items-center gap-1 text-white`,children:[(0,G.jsx)(`input`,{type:`radio`,name:`target-kind-${e.id}`,value:`specific_printer`,checked:g===`specific_printer`,onChange:()=>_(`specific_printer`),"aria-label":s(`settings.pipelines.field.targetKindSpecific`,`Specific printer`)}),s(`settings.pipelines.field.targetKindSpecific`,`Specific printer`)]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-1 text-white`,children:[(0,G.jsx)(`input`,{type:`radio`,name:`target-kind-${e.id}`,value:`printer_class`,checked:g===`printer_class`,onChange:()=>_(`printer_class`),"aria-label":s(`settings.pipelines.field.targetKindClass`,`Printer class`)}),s(`settings.pipelines.field.targetKindClass`,`Printer class`)]})]})]}),g===`specific_printer`?(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`text-xs text-bambu-gray block mb-1`,children:s(`settings.pipelines.field.targetPrinter`,`Target printer`)}),(0,G.jsxs)(`select`,{value:m??``,onChange:e=>h(e.target.value?parseInt(e.target.value,10):null),"aria-label":s(`settings.pipelines.field.targetPrinter`,`Target printer`),className:`w-full px-2 py-1 text-xs bg-bambu-dark border border-bambu-dark-tertiary rounded text-white`,children:[(0,G.jsx)(`option`,{value:``,children:s(`settings.pipelines.field.noTarget`,`— No target —`)}),n.map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}):(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`text-xs text-bambu-gray block mb-1`,children:s(`settings.pipelines.field.targetModelClass`,`Printer model`)}),(0,G.jsxs)(`select`,{value:v,onChange:e=>b(e.target.value),"aria-label":s(`settings.pipelines.field.targetModelClass`,`Printer model`),className:`w-full px-2 py-1 text-xs bg-bambu-dark border border-bambu-dark-tertiary rounded text-white`,children:[(0,G.jsx)(`option`,{value:``,children:s(`settings.pipelines.field.noTarget`,`— No target —`)}),C.map(e=>(0,G.jsx)(`option`,{value:e,children:e},e))]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`text-xs text-bambu-gray block mb-1`,children:s(`settings.pipelines.field.fanoutStrategy`,`Fanout strategy`)}),(0,G.jsxs)(`select`,{value:x,onChange:e=>S(e.target.value),"aria-label":s(`settings.pipelines.field.fanoutStrategy`,`Fanout strategy`),className:`w-full px-2 py-1 text-xs bg-bambu-dark border border-bambu-dark-tertiary rounded text-white`,children:[(0,G.jsx)(`option`,{value:`max_parallel`,children:s(`settings.pipelines.field.fanout.max_parallel`,`Max parallel — distribute across any idle matching printer`)}),(0,G.jsx)(`option`,{value:`round_robin`,children:s(`settings.pipelines.field.fanout.round_robin`,`Round robin — cycle through eligible printers`)}),(0,G.jsx)(`option`,{value:`fill_one_first`,children:s(`settings.pipelines.field.fanout.fill_one_first`,`Fill one first — pin all copies to one printer`)})]})]})]})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2 gap-y-1`,children:[(0,G.jsx)(`h4`,{className:`text-sm font-medium text-white truncate`,children:e.name}),(0,G.jsxs)(`span`,{className:`text-xs px-1.5 py-0.5 rounded inline-flex items-center gap-1 ${N?`bg-amber-100 dark:bg-amber-500/15 text-amber-700 dark:text-amber-400`:`bg-bambu-dark-tertiary text-bambu-gray`}`,children:[(0,G.jsx)(Rl,{className:`w-3 h-3`}),N?s(`settings.pipelines.noTargetHint`,`Set a target printer to run this`):M?(0,G.jsxs)(G.Fragment,{children:[s(`library.runWithPipeline.classTarget`,`Any {{model}}`,{model:e.target_model_class}),e.fanout_strategy&&(0,G.jsxs)(`span`,{className:`text-bambu-gray/60`,children:[` · `,s(`settings.pipelines.field.fanoutShort.${e.fanout_strategy}`,e.fanout_strategy)]})]}):j?.name??``]})]}),e.description&&(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:e.description})]})}),(0,G.jsx)(`div`,{className:`flex items-center gap-1 flex-shrink-0`,children:c?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`button`,{onClick:()=>{let e=u.trim();e&&(r({name:e,description:f.trim()||null,target_kind:g,target_printer_id:g===`specific_printer`?m??0:0,target_model_class:g===`printer_class`&&v||null,fanout_strategy:x}),l(!1))},disabled:a||!u.trim(),"aria-label":s(`settings.pipelines.action.save`,`Save`),className:`p-1.5 text-bambu-green hover:bg-bambu-dark-tertiary rounded disabled:opacity-50`,children:(0,G.jsx)(fs,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:()=>{d(e.name),p(e.description??``),h(e.target_printer_id),_(e.target_kind===`printer_class`?`printer_class`:`specific_printer`),b(e.target_model_class??``),S(e.fanout_strategy??`max_parallel`),l(!1)},"aria-label":s(`settings.pipelines.action.cancel`,`Cancel`),className:`p-1.5 text-bambu-gray hover:bg-bambu-dark-tertiary rounded`,children:(0,G.jsx)(nd,{className:`w-4 h-4`})})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`button`,{onClick:()=>l(!0),"aria-label":s(`settings.pipelines.action.rename`,`Rename`),className:`p-1.5 text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary rounded`,children:(0,G.jsx)(kl,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:i,disabled:o,"aria-label":s(`settings.pipelines.action.delete`,`Delete`),className:`p-1.5 text-bambu-gray hover:text-red-600 dark:hover:text-red-400 hover:bg-bambu-dark-tertiary rounded disabled:opacity-50`,children:(0,G.jsx)(Pu,{className:`w-4 h-4`})})]})})]}),!c&&(0,G.jsxs)(`div`,{className:`mt-2 grid grid-cols-1 md:grid-cols-2 gap-x-4 gap-y-2 text-xs`,children:[(0,G.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,G.jsx)(`div`,{className:`text-[10px] uppercase tracking-wide text-bambu-gray/60`,children:s(`settings.pipelines.group.profiles`,`Profiles`)}),(0,G.jsx)(W6,{label:s(`settings.pipelines.slot.printer`,`Printer`),ref:e.printer_preset,name:E}),(0,G.jsx)(W6,{label:s(`settings.pipelines.slot.process`,`Process`),ref:e.process_preset,name:D}),e.bed_type&&(0,G.jsxs)(`div`,{className:`text-bambu-gray`,children:[(0,G.jsxs)(`span`,{className:`font-medium text-bambu-gray/80`,children:[s(`settings.pipelines.slot.bed`,`Bed`),`:`]}),` `,(0,G.jsx)(`span`,{className:`text-white`,children:e.bed_type})]})]}),(0,G.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,G.jsxs)(`div`,{className:`text-[10px] uppercase tracking-wide text-bambu-gray/60`,children:[s(`settings.pipelines.group.filaments`,`Filaments`),e.filament_presets.length>1&&(0,G.jsxs)(`span`,{className:`text-bambu-gray/60 normal-case ml-1`,children:[`(`,e.filament_presets.length,`)`]})]}),k?(0,G.jsx)(W6,{label:s(`settings.pipelines.slot.filamentAll`,`All {{n}} slots`,{n:e.filament_presets.length}),ref:e.filament_presets[0],name:O[0]}):e.filament_presets.map((t,n)=>(0,G.jsx)(W6,{label:e.filament_presets.length>1?s(`settings.pipelines.slot.filamentN`,`Filament {{n}}`,{n:n+1}):s(`settings.pipelines.slot.filament`,`Filament`),ref:t,name:O[n]},n))]})]}),!c&&T&&(0,G.jsxs)(`div`,{className:`mt-1.5 text-xs text-bambu-gray flex items-center gap-1`,children:[(0,G.jsxs)(`span`,{className:`font-medium text-bambu-gray/80`,children:[s(`settings.pipelines.runs.lastRun`,`Last run`),`:`]}),` `,(0,G.jsx)(EWe,{status:T.status}),T.created_at&&(0,G.jsxs)(`span`,{className:`text-bambu-gray/60`,children:[`· `,new Date(T.created_at).toLocaleString()]})]}),N&&!c&&(0,G.jsxs)(`div`,{className:`mt-2 flex items-center gap-1.5 text-xs text-amber-700 dark:text-amber-400`,children:[(0,G.jsx)(Lu,{className:`w-3.5 h-3.5`}),s(`settings.pipelines.noTargetWarning`,`Set a target printer before running this pipeline.`)]}),A&&!c&&(0,G.jsxs)(`div`,{className:`mt-2 flex items-center gap-1.5 text-xs text-amber-700 dark:text-amber-400`,children:[(0,G.jsx)(Lu,{className:`w-3.5 h-3.5`}),s(`settings.pipelines.staleWarning`,`One or more referenced presets no longer exist. Re-save this pipeline from the Slice dialog to fix.`)]})]})}function EWe({status:e}){let{t}=U();return(0,G.jsx)(`span`,{className:{queued:`text-bambu-gray`,slicing:`text-blue-700 dark:text-blue-400`,dispatching:`text-blue-700 dark:text-blue-400`,in_progress:`text-bambu-green`,completed:`text-bambu-green`,failed:`text-red-700 dark:text-red-400`,partial_failure:`text-amber-700 dark:text-amber-400`,cancelled:`text-bambu-gray`}[e],children:t(`settings.pipelines.runs.status.${e}`,e)})}function W6({label:e,ref:t,name:n}){return(0,G.jsxs)(`div`,{className:`text-bambu-gray truncate`,children:[(0,G.jsxs)(`span`,{className:`font-medium text-bambu-gray/80`,children:[e,`:`]}),` `,n?(0,G.jsx)(`span`,{className:`text-white`,children:n}):(0,G.jsxs)(`span`,{className:`text-amber-700 dark:text-amber-400`,children:[`[`,CWe[t.source],` #`,t.id,`]`]})]})}var G6=90,K6=365;function q6(e){if(!e)return`—`;let t=rp(e);return t?t.toLocaleString():`—`}function DWe(e){let t=rp(e);return t?t.getTime(){if(l.preventDefault(),r.trim()){u(!0);try{e(await Z.createLongLivedCameraToken({name:r.trim(),expires_in_days:a,scope:s})),i(``),o(G6),c(`camera_stream`),n(t(`cameraTokens.toast.created`,`Token created`))}catch(e){n(e instanceof Error?e.message:t(`cameraTokens.toast.createFailed`,`Failed to create token`),`error`)}finally{u(!1)}}},className:`bg-bambu-dark-secondary rounded-lg p-4 mb-6 border border-bambu-dark-tertiary`,children:[(0,G.jsx)(`h3`,{className:`text-base font-semibold text-white mb-3`,children:t(`cameraTokens.create.title`,`Create new token`)}),(0,G.jsxs)(`div`,{className:`grid gap-3 md:grid-cols-[1fr_180px_140px_auto]`,children:[(0,G.jsx)(`input`,{type:`text`,maxLength:100,required:!0,value:r,onChange:e=>i(e.target.value),placeholder:t(`cameraTokens.create.namePlaceholder`,`e.g. Home Assistant`),className:`px-3 py-2 bg-bambu-dark rounded-md text-white border border-bambu-dark-tertiary focus:border-bambu-green focus:outline-none`,"aria-label":t(`cameraTokens.create.nameLabel`,`Token name`)}),(0,G.jsxs)(`select`,{value:s,onChange:e=>c(e.target.value),className:`px-3 py-2 bg-bambu-dark rounded-md text-white border border-bambu-dark-tertiary focus:border-bambu-green focus:outline-none`,"aria-label":t(`cameraTokens.create.scopeLabel`,`Scope`),children:[(0,G.jsx)(`option`,{value:`camera_stream`,children:t(`cameraTokens.scope.camera_stream`,`Camera stream`)}),(0,G.jsx)(`option`,{value:`camwall`,children:t(`cameraTokens.scope.camwall`,`Cam Wall`)}),(0,G.jsx)(`option`,{value:`overlay`,children:t(`cameraTokens.scope.overlay`,`Streaming Overlay`)})]}),(0,G.jsx)(`input`,{type:`number`,min:1,max:K6,required:!0,value:a,onChange:e=>{let t=Number(e.target.value);o(Math.min(Math.max(t,1),K6))},className:`px-3 py-2 bg-bambu-dark rounded-md text-white border border-bambu-dark-tertiary focus:border-bambu-green focus:outline-none`,"aria-label":t(`cameraTokens.create.daysLabel`,`Days until expiry`)}),(0,G.jsxs)(`button`,{type:`submit`,disabled:l||!r.trim(),className:`flex items-center gap-2 px-4 py-2 bg-bambu-green text-white rounded-md hover:bg-bambu-green/90 disabled:opacity-50 disabled:cursor-not-allowed`,children:[(0,G.jsx)(Fl,{className:`w-4 h-4`}),t(`cameraTokens.create.submit`,`Create`)]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-2`,children:s===`camwall`?t(`cameraTokens.create.hintCamWall`,`A Cam Wall token opens /camwall on a screen with no login — it can see every printer's name and state, and their camera streams. It cannot see filenames, addresses or access codes.`):s===`overlay`?t(`cameraTokens.create.hintOverlay`,`A Streaming Overlay token opens /overlay/{printerId} on a screen with no login — for OBS or any live stream. It can see one printer's camera stream plus its live print status, including the filename shown on screen. It cannot see addresses or access codes.`):t(`cameraTokens.create.hintCameraStream`,`A camera-stream token can only fetch camera streams and snapshots. Use it for Home Assistant, Frigate, or anything embedding a single camera.`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:t(`cameraTokens.create.hint`,`Maximum lifetime is 365 days. The token value is shown only once on creation — copy it now.`)})]})}function kWe({token:e,onConfirm:t,onCancel:n}){let{t:r}=U();return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/60 flex items-center justify-center z-50 p-4`,role:`dialog`,"aria-modal":`true`,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg p-6 max-w-md w-full border border-red-500/40`,children:[(0,G.jsxs)(`div`,{className:`flex items-start gap-3 mb-4`,children:[(0,G.jsx)(Lu,{className:`w-6 h-6 text-red-600 dark:text-red-400 flex-shrink-0 mt-0.5`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:r(`cameraTokens.confirmRevoke.title`,`Revoke this token?`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:r(`cameraTokens.confirmRevoke.body`,`Any device using "{{name}}" will lose access immediately. This cannot be undone.`,{name:e.name})})]})]}),(0,G.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,G.jsx)(`button`,{type:`button`,onClick:n,className:`px-4 py-2 bg-bambu-dark-tertiary text-white rounded-md hover:bg-bambu-dark-tertiary/80`,children:r(`cameraTokens.confirmRevoke.cancel`,`Cancel`)}),(0,G.jsx)(`button`,{type:`button`,onClick:t,className:`px-4 py-2 bg-red-500 text-white rounded-md hover:bg-red-600`,children:r(`cameraTokens.confirmRevoke.confirm`,`Revoke`)})]})]})})}function AWe({token:e,onClose:t}){let{t:n}=U(),{showToast:r}=qd(),i=e.token??``,a=e.scope===`camwall`&&i?`${window.location.origin}/camwall?token=${encodeURIComponent(i)}`:null,o=e.scope===`overlay`&&i?`${window.location.origin}/overlay/1?token=${encodeURIComponent(i)}`:null,s=async e=>{if(e)try{if(navigator.clipboard&&window.isSecureContext)await navigator.clipboard.writeText(e);else{let t=document.createElement(`textarea`);t.value=e,t.style.position=`fixed`,t.style.opacity=`0`,document.body.appendChild(t);try{t.select(),document.execCommand(`copy`)}finally{document.body.removeChild(t)}}r(n(`cameraTokens.toast.copied`,`Copied to clipboard`))}catch{r(n(`cameraTokens.toast.copyFailed`,`Copy failed — select and copy manually`),`error`)}};return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/60 flex items-center justify-center z-50 p-4`,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg p-6 max-w-2xl w-full border border-bambu-green/40`,children:[(0,G.jsxs)(`div`,{className:`flex items-start gap-3 mb-4`,children:[(0,G.jsx)(Lu,{className:`w-6 h-6 text-yellow-600 dark:text-yellow-400 flex-shrink-0 mt-0.5`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:n(`cameraTokens.created.title`,`Token created — copy it now`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:n(`cameraTokens.created.warning`,`This is the only time this token will be visible. After you close this dialog you can never view it again.`)})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-4`,children:[(0,G.jsx)(`code`,{className:`flex-1 px-3 py-2 bg-bambu-dark rounded-md text-bambu-green text-xs break-all font-mono select-all`,children:i}),(0,G.jsxs)(`button`,{type:`button`,onClick:()=>s(i),className:`flex items-center gap-2 px-3 py-2 bg-bambu-green text-white rounded-md hover:bg-bambu-green/90`,children:[(0,G.jsx)(Vs,{className:`w-4 h-4`}),n(`cameraTokens.created.copy`,`Copy`)]})]}),a&&(0,G.jsxs)(`div`,{className:`mb-4`,children:[(0,G.jsx)(`p`,{className:`text-sm font-medium text-white mb-1`,children:n(`cameraTokens.created.camWallUrlTitle`,`Cam Wall URL for this display`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:n(`cameraTokens.created.camWallUrlHint`,`Open this on the screen. Anyone who can read the URL can watch the wall, so treat it like a key — revoke the token to cut the display off.`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`code`,{className:`flex-1 px-3 py-2 bg-bambu-dark rounded-md text-bambu-green text-xs break-all font-mono select-all`,children:a}),(0,G.jsxs)(`button`,{type:`button`,onClick:()=>s(a),className:`flex items-center gap-2 px-3 py-2 bg-bambu-green text-white rounded-md hover:bg-bambu-green/90`,children:[(0,G.jsx)(Vs,{className:`w-4 h-4`}),n(`cameraTokens.created.copy`,`Copy`)]})]})]}),o&&(0,G.jsxs)(`div`,{className:`mb-4`,children:[(0,G.jsx)(`p`,{className:`text-sm font-medium text-white mb-1`,children:n(`cameraTokens.created.overlayUrlTitle`,`Overlay URL for OBS`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:n(`cameraTokens.created.overlayUrlHint`,`Add this as a Browser Source in OBS. Change the /overlay/1 number to your printer's number (from its URL on the Printers page). Anyone who can read the URL can watch the stream, so treat it like a key — revoke the token to cut it off.`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`code`,{className:`flex-1 px-3 py-2 bg-bambu-dark rounded-md text-bambu-green text-xs break-all font-mono select-all`,children:o}),(0,G.jsxs)(`button`,{type:`button`,onClick:()=>s(o),className:`flex items-center gap-2 px-3 py-2 bg-bambu-green text-white rounded-md hover:bg-bambu-green/90`,children:[(0,G.jsx)(Vs,{className:`w-4 h-4`}),n(`cameraTokens.created.copy`,`Copy`)]})]})]}),(0,G.jsx)(`div`,{className:`flex justify-end`,children:(0,G.jsx)(`button`,{type:`button`,onClick:t,className:`px-4 py-2 bg-bambu-dark-tertiary text-white rounded-md hover:bg-bambu-dark-tertiary/80`,children:n(`cameraTokens.created.dismiss`,`I've saved it`)})})]})})}function jWe({token:e,showOwner:t,ownerLabel:n,onRevoke:r}){let{t:i}=U(),a=DWe(e.expires_at);return(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary last:border-b-0`,children:[(0,G.jsx)(`td`,{className:`py-3 px-3 text-white`,children:e.name}),t&&(0,G.jsx)(`td`,{className:`py-3 px-3 text-bambu-gray`,children:n}),(0,G.jsx)(`td`,{className:`py-3 px-3`,children:(0,G.jsx)(`span`,{className:`rounded bg-bambu-dark-tertiary px-2 py-0.5 text-xs text-bambu-gray`,children:i(`cameraTokens.scope.${e.scope}`,e.scope)})}),(0,G.jsxs)(`td`,{className:`py-3 px-3 text-bambu-gray font-mono text-xs`,children:[e.lookup_prefix,`…`]}),(0,G.jsx)(`td`,{className:`py-3 px-3 text-bambu-gray`,children:q6(e.created_at)}),(0,G.jsxs)(`td`,{className:`py-3 px-3 ${a?`text-red-700 dark:text-red-400`:`text-bambu-gray`}`,children:[q6(e.expires_at),a&&(0,G.jsx)(`span`,{className:`ml-2 px-2 py-0.5 text-xs bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-300 rounded`,children:i(`cameraTokens.list.expired`,`Expired`)})]}),(0,G.jsx)(`td`,{className:`py-3 px-3 text-bambu-gray`,children:q6(e.last_used_at)}),(0,G.jsx)(`td`,{className:`py-3 px-3 text-right`,children:(0,G.jsxs)(`button`,{type:`button`,onClick:()=>r(e.id),className:`inline-flex items-center gap-1 px-2 py-1 text-sm text-red-700 dark:text-red-400 hover:text-red-900 dark:hover:text-red-300`,title:i(`cameraTokens.list.revoke`,`Revoke`),children:[(0,G.jsx)(Pu,{className:`w-4 h-4`}),i(`cameraTokens.list.revoke`,`Revoke`)]})})]})}function J6({tokens:e,showOwner:t,userIdToName:n,onRevoke:r,emptyMessage:i}){let{t:a}=U();return e.length===0?(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray italic`,children:i}):(0,G.jsx)(`div`,{className:`overflow-x-auto`,children:(0,G.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,G.jsx)(`thead`,{className:`text-bambu-gray text-left border-b border-bambu-dark-tertiary`,children:(0,G.jsxs)(`tr`,{children:[(0,G.jsx)(`th`,{className:`py-2 px-3 font-medium`,children:a(`cameraTokens.list.name`,`Name`)}),t&&(0,G.jsx)(`th`,{className:`py-2 px-3 font-medium`,children:a(`cameraTokens.list.owner`,`Owner`)}),(0,G.jsx)(`th`,{className:`py-2 px-3 font-medium`,children:a(`cameraTokens.list.scope`,`Scope`)}),(0,G.jsx)(`th`,{className:`py-2 px-3 font-medium`,children:a(`cameraTokens.list.prefix`,`Prefix`)}),(0,G.jsx)(`th`,{className:`py-2 px-3 font-medium`,children:a(`cameraTokens.list.created`,`Created`)}),(0,G.jsx)(`th`,{className:`py-2 px-3 font-medium`,children:a(`cameraTokens.list.expires`,`Expires`)}),(0,G.jsx)(`th`,{className:`py-2 px-3 font-medium`,children:a(`cameraTokens.list.lastUsed`,`Last used`)}),(0,G.jsx)(`th`,{className:`py-2 px-3`})]})}),(0,G.jsx)(`tbody`,{children:e.map(e=>(0,G.jsx)(jWe,{token:e,showOwner:t,ownerLabel:n?.get(e.user_id)??`#${e.user_id}`,onRevoke:r},e.id))})]})})}function MWe(){let{t:e}=U(),{user:t,isAdmin:n}=Nd(),{showToast:r}=qd(),[i,a]=(0,y.useState)([]),[o,s]=(0,y.useState)([]),[c,l]=(0,y.useState)(new Map),[u,d]=(0,y.useState)(!0),[f,p]=(0,y.useState)(null),[m,h]=(0,y.useState)(null),g=async()=>{d(!0);try{if(a(await Z.listMyLongLivedCameraTokens()),n){s(await Z.listAllLongLivedCameraTokens());try{let e=await Z.getUsersSlim();l(new Map(e.map(e=>[e.id,e.username])))}catch{l(new Map)}}}catch(t){r(t instanceof Error?t.message:e(`cameraTokens.toast.loadFailed`,`Failed to load tokens`),`error`)}finally{d(!1)}};(0,y.useEffect)(()=>{g()},[n]);let _=async e=>{let t=[...i,...o].find(t=>t.id===e);t&&h(t)},v=async()=>{if(!m)return;let t=m.id;h(null);try{await Z.revokeLongLivedCameraToken(t),r(e(`cameraTokens.toast.revoked`,`Token revoked`)),await g()}catch(t){r(t instanceof Error?t.message:e(`cameraTokens.toast.revokeFailed`,`Failed to revoke token`),`error`)}},b=(0,y.useMemo)(()=>o.filter(e=>e.user_id!==t?.id),[o,t?.id]);return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4`,children:e(`cameraTokens.description`,`Long-lived tokens for embedding the camera stream into Home Assistant, Frigate, kiosks, or any other tool that needs a stable URL. Each token is camera-stream-only and can be revoked at any time.`)}),(0,G.jsx)(OWe,{onCreated:e=>{p(e),g()}}),(0,G.jsxs)(`div`,{className:`mb-6`,children:[(0,G.jsx)(`h3`,{className:`text-base font-semibold text-white mb-3`,children:e(`cameraTokens.list.myTitle`,`My tokens`)}),u?(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`cameraTokens.loading`,`Loading…`)}):(0,G.jsx)(J6,{tokens:i,onRevoke:_,emptyMessage:e(`cameraTokens.list.empty`,`No tokens yet.`)})]}),n&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`text-base font-semibold text-white mb-3`,children:e(`cameraTokens.list.allTitle`,`All users (admin view)`)}),(0,G.jsx)(J6,{tokens:b,showOwner:!0,userIdToName:c,onRevoke:_,emptyMessage:e(`cameraTokens.list.empty`,`No tokens yet.`)})]}),f&&(0,G.jsx)(AWe,{token:f,onClose:()=>p(null)}),m&&(0,G.jsx)(kWe,{token:m,onConfirm:()=>void v(),onCancel:()=>h(null)})]})}var Y6=[{key:`printer`,labelKey:`streamOverlay.builder.fieldPrinter`,fallback:`Printer name`},{key:`filename`,labelKey:`streamOverlay.builder.fieldFilename`,fallback:`File name`},{key:`status`,labelKey:`streamOverlay.builder.fieldStatus`,fallback:`Status`},{key:`progress`,labelKey:`streamOverlay.builder.fieldProgress`,fallback:`Progress bar`},{key:`layers`,labelKey:`streamOverlay.builder.fieldLayers`,fallback:`Layer count`},{key:`eta`,labelKey:`streamOverlay.builder.fieldEta`,fallback:`Time remaining and ETA`},{key:`nozzle`,labelKey:`printers.heaterHistory.nozzle`,fallback:`Nozzle`},{key:`bed`,labelKey:`printers.heaterHistory.bed`,fallback:`Bed`},{key:`chamber`,labelKey:`printers.heaterHistory.chamber`,fallback:`Chamber`}],NWe=[`progress`,`layers`,`eta`,`filename`,`status`],X6=15;function PWe(){let{t:e}=U(),{showToast:t}=qd(),[n,r]=(0,y.useState)([]),[i,a]=(0,y.useState)(null),[o,s]=(0,y.useState)(NWe),[c,l]=(0,y.useState)(`medium`),[u,d]=(0,y.useState)(X6),[f,p]=(0,y.useState)(!0),[m,h]=(0,y.useState)(``),[g,_]=(0,y.useState)(!1);(0,y.useEffect)(()=>{let e=!1;return(async()=>{try{let t=await Z.getPrinters();if(e)return;r(t),t.length>0&&a(t[0].id)}catch{}})(),()=>{e=!0}},[]);let v=(0,y.useMemo)(()=>{let e=i??1,t=new URLSearchParams,n=Y6.filter(e=>o.includes(e.key)).map(e=>e.key);return t.set(`show`,n.join(`,`)),c!==`medium`&&t.set(`size`,c),u!==X6&&t.set(`fps`,String(u)),f||t.set(`camera`,`false`),m.trim()&&t.set(`token`,m.trim()),`${window.location.origin}/overlay/${e}?${t.toString()}`},[i,o,c,u,f,m]),b=e=>{s(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},x=async()=>{try{if(navigator.clipboard&&window.isSecureContext)await navigator.clipboard.writeText(v);else{let e=document.createElement(`textarea`);e.value=v,e.style.position=`fixed`,e.style.opacity=`0`,document.body.appendChild(e);try{e.select(),document.execCommand(`copy`)}finally{document.body.removeChild(e)}}t(e(`cameraTokens.toast.copied`,`Copied to clipboard`))}catch{t(e(`cameraTokens.toast.copyFailed`,`Copy failed — select and copy manually`),`error`)}};return(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4`,children:e(`streamOverlay.builder.description`,`Build the URL for a streaming overlay — a full-screen camera view with live print data drawn over it, for OBS, a wall display, or any browser source. Pick the fields you want and copy the URL.`)}),(0,G.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{htmlFor:`overlay-builder-printer`,className:`block text-sm font-medium text-white mb-1`,children:e(`streamOverlay.builder.printer`,`Printer`)}),(0,G.jsxs)(`select`,{id:`overlay-builder-printer`,value:i??``,onChange:e=>a(Number(e.target.value)),className:`w-full px-3 py-2 bg-bambu-dark rounded-md text-white border border-bambu-dark-tertiary focus:border-bambu-green focus:outline-none`,children:[n.length===0&&(0,G.jsx)(`option`,{value:``,children:e(`common.loading`,`Loading…`)}),n.map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{htmlFor:`overlay-builder-size`,className:`block text-sm font-medium text-white mb-1`,children:e(`streamOverlay.builder.size`,`Text size`)}),(0,G.jsxs)(`select`,{id:`overlay-builder-size`,value:c,onChange:e=>l(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark rounded-md text-white border border-bambu-dark-tertiary focus:border-bambu-green focus:outline-none`,children:[(0,G.jsx)(`option`,{value:`small`,children:e(`streamOverlay.builder.sizeSmall`,`Small`)}),(0,G.jsx)(`option`,{value:`medium`,children:e(`streamOverlay.builder.sizeMedium`,`Medium`)}),(0,G.jsx)(`option`,{value:`large`,children:e(`streamOverlay.builder.sizeLarge`,`Large`)})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{htmlFor:`overlay-builder-fps`,className:`block text-sm font-medium text-white mb-1`,children:e(`streamOverlay.builder.fps`,`Frame rate`)}),(0,G.jsx)(`input`,{id:`overlay-builder-fps`,type:`number`,min:1,max:30,value:u,onChange:e=>d(Math.min(Math.max(Number(e.target.value)||1,1),30)),className:`w-full px-3 py-2 bg-bambu-dark rounded-md text-white border border-bambu-dark-tertiary focus:border-bambu-green focus:outline-none`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`streamOverlay.builder.fpsHint`,`A1 and P1 cameras top out around 5 fps whatever you ask for.`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{htmlFor:`overlay-builder-token`,className:`block text-sm font-medium text-white mb-1`,children:e(`streamOverlay.builder.token`,`Streaming Overlay token (optional)`)}),(0,G.jsx)(`input`,{id:`overlay-builder-token`,type:`text`,value:m,onChange:e=>h(e.target.value),placeholder:`bblt_…`,className:`w-full px-3 py-2 bg-bambu-dark rounded-md text-white border border-bambu-dark-tertiary focus:border-bambu-green focus:outline-none font-mono text-xs`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`streamOverlay.builder.tokenHint`,`Only needed when login is enabled: OBS has no session of its own. Create one above with the Streaming Overlay scope.`)})]})]}),(0,G.jsxs)(`fieldset`,{className:`mt-4`,children:[(0,G.jsx)(`legend`,{className:`text-sm font-medium text-white mb-2`,children:e(`streamOverlay.builder.fields`,`Fields to show`)}),(0,G.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-2 md:grid-cols-3`,children:[Y6.map(t=>(0,G.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-bambu-gray`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:o.includes(t.key),onChange:()=>b(t.key),className:`accent-bambu-green`}),e(t.labelKey,t.fallback)]},t.key)),(0,G.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-bambu-gray`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:f,onChange:e=>p(e.target.checked),className:`accent-bambu-green`}),e(`streamOverlay.builder.fieldCamera`,`Camera feed`)]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-2`,children:e(`streamOverlay.builder.chamberHint`,`Chamber temperature only appears on models with a real chamber sensor — P1 and A1 printers report a meaningless value, so it is left out there.`)})]}),(0,G.jsxs)(`div`,{className:`mt-4`,children:[(0,G.jsx)(`p`,{className:`text-sm font-medium text-white mb-1`,children:e(`streamOverlay.builder.urlTitle`,`Overlay URL`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`code`,{className:`flex-1 px-3 py-2 bg-bambu-dark rounded-md text-bambu-green text-xs break-all font-mono select-all`,children:v}),(0,G.jsxs)(`button`,{type:`button`,onClick:()=>void x(),className:`flex items-center gap-2 px-3 py-2 bg-bambu-green text-white rounded-md hover:bg-bambu-green/90`,children:[(0,G.jsx)(Vs,{className:`w-4 h-4`}),e(`cameraTokens.created.copy`,`Copy`)]}),(0,G.jsxs)(`a`,{href:v,target:`_blank`,rel:`noopener noreferrer`,className:`flex items-center gap-2 px-3 py-2 bg-bambu-dark-tertiary text-white rounded-md hover:bg-bambu-dark-tertiary/80`,children:[(0,G.jsx)(rc,{className:`w-4 h-4`}),e(`streamOverlay.builder.open`,`Open`)]})]}),m.trim()&&(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-2`,children:e(`streamOverlay.builder.tokenWarning`,`This URL contains a token — anyone who can read it can watch the stream and see the file name. Revoke the token to cut it off.`)})]}),(0,G.jsxs)(`div`,{className:`mt-4`,children:[(0,G.jsxs)(`button`,{type:`button`,onClick:()=>_(e=>!e),className:`flex items-center gap-2 px-3 py-2 bg-bambu-dark-tertiary text-white rounded-md hover:bg-bambu-dark-tertiary/80 text-sm`,children:[g?(0,G.jsx)(ic,{className:`w-4 h-4`}):(0,G.jsx)(ac,{className:`w-4 h-4`}),g?e(`streamOverlay.builder.hidePreview`,`Hide preview`):e(`streamOverlay.builder.showPreview`,`Show preview`)]}),g&&(0,G.jsx)(`iframe`,{src:v,title:e(`streamOverlay.builder.previewTitle`,`Overlay preview`),className:`mt-3 w-full aspect-video rounded-md border border-bambu-dark-tertiary bg-black`},v)]})]})}function FWe({plug:e,onEdit:t}){let{t:n}=U(),r=co(),{showToast:i}=qd(),[a,o]=(0,y.useState)(!1),[s,c]=(0,y.useState)(!1),[l,u]=(0,y.useState)(!1),[d,f]=(0,y.useState)(!1),{data:p,isLoading:m}=K({queryKey:[`smart-plug-status`,e.id],queryFn:()=>Z.getSmartPlugStatus(e.id),refetchInterval:3e4}),{data:h}=K({queryKey:[`printers`],queryFn:Z.getPrinters}),g=h?.find(t=>t.id===e.printer_id),_=q({mutationFn:t=>Z.controlSmartPlug(e.id,t),onMutate:async t=>{await r.cancelQueries({queryKey:[`smart-plug-status`,e.id]});let n=r.getQueryData([`smart-plug-status`,e.id]),i=t===`on`?`ON`:t===`off`||p?.state===`ON`?`OFF`:`ON`;return r.setQueryData([`smart-plug-status`,e.id],e=>({...e,state:i})),{previousStatus:n}},onError:(t,a,o)=>{o?.previousStatus&&r.setQueryData([`smart-plug-status`,e.id],o.previousStatus),i(n(`smartPlugs.failedToTurn`,{action:a,name:e.name}),`error`)},onSettled:()=>{setTimeout(()=>{r.invalidateQueries({queryKey:[`smart-plug-status`,e.id]}),r.invalidateQueries({queryKey:[`smart-plugs`]})},1e3)}}),v=q({mutationFn:t=>Z.updateSmartPlug(e.id,t),onSuccess:()=>{r.invalidateQueries({queryKey:[`smart-plugs`]}),e.printer_id&&(r.invalidateQueries({queryKey:[`smartPlugByPrinter`,e.printer_id]}),r.invalidateQueries({queryKey:[`scriptPlugsByPrinter`,e.printer_id]}))}}),b=q({mutationFn:()=>Z.deleteSmartPlug(e.id),onSuccess:()=>{r.invalidateQueries({queryKey:[`smart-plugs`]}),e.printer_id&&r.invalidateQueries({queryKey:[`scriptPlugsByPrinter`,e.printer_id]})}}),x=p?.state===`ON`,S=e.plug_type===`mqtt`&&p?.energy?.power!==null&&p?.energy?.power!==void 0,C=(p?.reachable??!1)||S,w=_.isPending,T=(()=>{if(e.plug_type!==`tasmota`||!e.ip_address)return null;let t=e.ip_address;return e.username&&e.password?`http://${encodeURIComponent(e.username)}:${encodeURIComponent(e.password)}@${t}/`:`http://${t}/`})();return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(zd,{className:`relative`,children:(0,G.jsxs)(Vd,{className:`p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-start justify-between gap-2 mb-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 flex-1`,children:[(0,G.jsx)(`div`,{className:`p-2 rounded-lg flex-shrink-0 ${e.plug_type===`mqtt`?C?`bg-teal-100 dark:bg-teal-500/20`:`bg-red-100 dark:bg-red-500/20`:C?x?`bg-bambu-green/20`:`bg-bambu-dark`:`bg-red-100 dark:bg-red-500/20`}`,children:e.plug_type===`mqtt`?(0,G.jsx)(Bl,{className:`w-5 h-5 ${C?`text-teal-600 dark:text-teal-400`:`text-red-600 dark:text-red-400`}`}):e.plug_type===`homeassistant`?(0,G.jsx)(Bc,{className:`w-5 h-5 ${C?x?`text-bambu-green`:`text-bambu-gray`:`text-red-600 dark:text-red-400`}`}):e.plug_type===`rest`?(0,G.jsx)(Ac,{className:`w-5 h-5 ${C?x?`text-bambu-green`:`text-bambu-gray`:`text-red-600 dark:text-red-400`}`}):(0,G.jsx)(Pl,{className:`w-5 h-5 ${C?x?`text-bambu-green`:`text-bambu-gray`:`text-red-600 dark:text-red-400`}`})}),(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsx)(`h3`,{className:`font-medium text-white truncate`,children:e.name}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray truncate`,title:e.plug_type===`mqtt`?e.mqtt_topic??void 0:e.plug_type===`homeassistant`?e.ha_entity_id??void 0:e.plug_type===`rest`?e.rest_on_url??e.rest_off_url??void 0:e.ip_address??void 0,children:e.plug_type===`mqtt`?e.mqtt_topic:e.plug_type===`homeassistant`?e.ha_entity_id:e.plug_type===`rest`?e.rest_on_url||e.rest_off_url:e.ip_address})]})]}),(0,G.jsxs)(`div`,{className:`flex flex-col items-end gap-1 flex-shrink-0`,children:[m?(0,G.jsx)(Y,{className:`w-4 h-4 text-bambu-gray animate-spin`}):e.plug_type===`mqtt`?(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 text-sm whitespace-nowrap`,children:[(0,G.jsx)(`span`,{className:`px-1.5 py-0.5 bg-teal-100 dark:bg-teal-500/20 text-teal-700 dark:text-teal-400 text-[10px] font-medium rounded flex-shrink-0`,children:`MQTT`}),C&&(0,G.jsx)(`span`,{className:`text-status-ok`,children:`✓`})]}):e.plug_type===`homeassistant`?(0,G.jsxs)(`div`,{className:`flex items-center gap-1 text-sm`,children:[(0,G.jsx)(`span`,{className:`px-1 py-0.5 bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400 text-[10px] font-medium rounded`,children:`HA`}),(0,G.jsx)(`span`,{className:C?x?`text-status-ok`:`text-bambu-gray`:`text-status-error`,children:C?p?.state||`?`:n(`smartPlugs.offline`)})]}):e.plug_type===`rest`?(0,G.jsxs)(`div`,{className:`flex items-center gap-1 text-sm`,children:[(0,G.jsx)(`span`,{className:`px-1 py-0.5 bg-purple-100 dark:bg-purple-500/20 text-purple-700 dark:text-purple-400 text-[10px] font-medium rounded`,children:`REST`}),(0,G.jsx)(`span`,{className:C?x?`text-status-ok`:`text-bambu-gray`:`text-status-error`,children:C?p?.state||`?`:n(`smartPlugs.offline`)})]}):C?(0,G.jsxs)(`div`,{className:`flex items-center gap-1 text-sm`,children:[(0,G.jsx)(Qu,{className:`w-4 h-4 text-status-ok`}),(0,G.jsx)(`span`,{className:x?`text-status-ok`:`text-bambu-gray`,children:p?.state||n(`smartPlugs.unknown`)})]}):(0,G.jsxs)(`div`,{className:`flex items-center gap-1 text-sm text-status-error`,children:[(0,G.jsx)(Zu,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{children:n(`smartPlugs.offline`)})]}),T&&(0,G.jsxs)(`a`,{href:T,target:`_blank`,rel:`noopener noreferrer`,className:`flex items-center gap-1 px-2 py-0.5 bg-bambu-dark hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white text-xs rounded-full transition-colors`,title:n(`smartPlugs.openPlugAdminPage`),children:[(0,G.jsx)(rc,{className:`w-3 h-3`}),n(`smartPlugs.admin`)]})]})]}),g&&(0,G.jsxs)(`div`,{className:`mb-3 px-2 py-1.5 bg-bambu-dark rounded-lg`,children:[(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[n(`smartPlugs.linkedTo`),` `]}),(0,G.jsx)(`span`,{className:`text-sm text-white`,children:g.name})]}),(e.power_alert_enabled||e.schedule_enabled||e.plug_type===`mqtt`)&&(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-1.5 mb-3`,children:[e.plug_type===`mqtt`&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1 px-2 py-0.5 bg-teal-100 dark:bg-teal-500/20 text-teal-700 dark:text-teal-400 text-xs rounded-full`,children:[(0,G.jsx)(ac,{className:`w-3 h-3`}),n(`smartPlugs.monitorOnly`)]}),e.power_alert_enabled&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1 px-2 py-0.5 bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400 text-xs rounded-full`,children:[(0,G.jsx)(qo,{className:`w-3 h-3`}),n(`smartPlugs.alerts`)]}),e.schedule_enabled&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1 px-2 py-0.5 bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400 text-xs rounded-full`,children:[(0,G.jsx)(as,{className:`w-3 h-3`}),e.schedule_on_time&&e.schedule_off_time?`${e.schedule_on_time} - ${e.schedule_off_time}`:e.schedule_on_time?n(`smartPlugs.scheduleOn`,{time:e.schedule_on_time}):n(`smartPlugs.scheduleOff`,{time:e.schedule_off_time})]})]}),e.plug_type!==`mqtt`&&(0,G.jsxs)(`div`,{className:`flex gap-2 mb-3`,children:[(0,G.jsxs)(Q,{size:`sm`,variant:x?`primary`:`secondary`,disabled:!C||w,onClick:()=>c(!0),className:`flex-1`,children:[w?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Ll,{className:`w-4 h-4`}),n(`smartPlugs.on`)]}),(0,G.jsxs)(Q,{size:`sm`,variant:x?`secondary`:`primary`,disabled:!C||w,onClick:()=>u(!0),className:`flex-1`,children:[w?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Il,{className:`w-4 h-4`}),n(`smartPlugs.off`)]})]}),e.plug_type===`mqtt`&&p?.energy&&(0,G.jsxs)(`div`,{className:`flex gap-2 mb-3 px-3 py-2 bg-bambu-dark rounded-lg`,children:[p.energy.power!==null&&p.energy.power!==void 0&&(0,G.jsxs)(`div`,{className:`flex-1 text-center`,children:[(0,G.jsxs)(`p`,{className:`text-lg font-semibold text-white`,children:[Math.round(p.energy.power),`W`]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.power`)})]}),p.energy.today!==null&&p.energy.today!==void 0&&(0,G.jsxs)(`div`,{className:`flex-1 text-center border-l border-bambu-dark-tertiary`,children:[(0,G.jsx)(`p`,{className:`text-lg font-semibold text-white`,children:p.energy.today.toFixed(3)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.kwhToday`)})]})]}),(0,G.jsxs)(`button`,{onClick:()=>f(!d),className:`w-full flex items-center justify-between py-2 text-sm text-bambu-gray hover:text-white transition-colors`,children:[(0,G.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(nu,{className:`w-4 h-4`}),e.plug_type===`mqtt`?n(`smartPlugs.settings`):n(`smartPlugs.automationSettings`)]}),(0,G.jsx)(`span`,{children:d?`-`:`+`})]}),d&&(0,G.jsxs)(`div`,{className:`pt-3 border-t border-bambu-dark-tertiary space-y-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Yc,{className:`w-4 h-4 text-bambu-green`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`smartPlugs.showInSwitchbar`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.quickAccessSidebar`)})]})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:e.show_in_switchbar,onChange:e=>v.mutate({show_in_switchbar:e.target.checked}),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green`})]})]}),e.printer_id!=null&&(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Ll,{className:`w-4 h-4 text-bambu-green`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`smartPlugs.controlsPrinterPower`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.controlsPrinterPowerDescription`)})]})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:e.controls_printer_power,onChange:e=>v.mutate({controls_printer_power:e.target.checked}),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green`})]})]}),e.plug_type!==`mqtt`&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`smartPlugs.enabled`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.enableAutomation`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:e.enabled,onChange:e=>v.mutate({enabled:e.target.checked}),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`smartPlugs.autoOn`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.autoOnDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:e.auto_on,onChange:e=>v.mutate({auto_on:e.target.checked}),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`smartPlugs.autoOff`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.autoOffDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:e.auto_off,onChange:e=>v.mutate({auto_off:e.target.checked}),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green`})]})]}),e.auto_off&&(0,G.jsxs)(`div`,{className:`flex items-center justify-between pl-4 border-l-2 border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`smartPlugs.autoOffPersistent`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.autoOffPersistentDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:e.auto_off_persistent,onChange:e=>v.mutate({auto_off_persistent:e.target.checked}),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green`})]})]}),e.auto_off&&(0,G.jsxs)(`div`,{className:`space-y-3 pl-4 border-l-2 border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white mb-2`,children:n(`smartPlugs.turnOffDelayMode`)}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsxs)(`button`,{onClick:()=>v.mutate({off_delay_mode:`time`}),className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg text-sm transition-colors ${e.off_delay_mode===`time`?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white`}`,children:[(0,G.jsx)(js,{className:`w-4 h-4`}),n(`smartPlugs.time`)]}),(0,G.jsxs)(`button`,{onClick:()=>v.mutate({off_delay_mode:`temperature`}),className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg text-sm transition-colors ${e.off_delay_mode===`temperature`?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white`}`,children:[(0,G.jsx)(Mu,{className:`w-4 h-4`}),n(`smartPlugs.temp`)]})]})]}),e.off_delay_mode===`time`?(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:n(`smartPlugs.delayMinutes`)}),(0,G.jsx)(`input`,{type:`number`,min:`1`,max:`60`,value:e.off_delay_minutes,onChange:e=>v.mutate({off_delay_minutes:parseInt(e.target.value)||5}),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`})]}):(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:n(`smartPlugs.tempThreshold`)}),(0,G.jsx)(`input`,{type:`number`,min:`30`,max:`100`,value:e.off_temp_threshold,onChange:e=>v.mutate({off_temp_threshold:parseInt(e.target.value)||70}),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(`smartPlugs.tempThresholdDescription`)})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`smartPlugs.autoOffAfterDrying`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.autoOffAfterDryingDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:e.auto_off_after_drying,onChange:e=>v.mutate({auto_off_after_drying:e.target.checked}),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green`})]})]}),e.auto_off_after_drying&&(0,G.jsxs)(`div`,{className:`pl-4 border-l-2 border-bambu-dark-tertiary`,children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:n(`smartPlugs.delayAfterDryingMinutes`)}),(0,G.jsx)(`input`,{type:`number`,min:`0`,max:`120`,value:e.off_delay_after_drying_minutes,onChange:e=>v.mutate({off_delay_after_drying_minutes:parseInt(e.target.value)||10}),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`})]})]}),(0,G.jsxs)(`div`,{className:`flex gap-2 pt-2`,children:[(0,G.jsxs)(Q,{size:`sm`,variant:`secondary`,onClick:()=>t(e),className:`flex-1`,children:[(0,G.jsx)(kl,{className:`w-4 h-4`}),n(`smartPlugs.edit`)]}),(0,G.jsx)(Q,{size:`sm`,variant:`secondary`,onClick:()=>o(!0),className:`text-red-600 dark:text-red-400 hover:text-red-700 dark:hover:text-red-300`,children:(0,G.jsx)(Pu,{className:`w-4 h-4`})})]})]})]})}),a&&(0,G.jsx)(of,{title:n(`smartPlugs.deleteSmartPlug`),message:n(`smartPlugs.deleteConfirm`,{name:e.name}),confirmText:n(`smartPlugs.delete`),variant:`danger`,onConfirm:()=>{b.mutate(),o(!1)},onCancel:()=>o(!1)}),s&&(0,G.jsx)(of,{title:n(`smartPlugs.turnOnSmartPlug`),message:n(`smartPlugs.turnOnConfirm`,{name:e.name}),confirmText:n(`smartPlugs.turnOn`),variant:`default`,onConfirm:()=>{_.mutate(`on`),c(!1)},onCancel:()=>c(!1)}),l&&(0,G.jsx)(of,{title:n(`smartPlugs.turnOffSmartPlug`),message:n(`smartPlugs.turnOffConfirm`,{name:e.name}),confirmText:n(`smartPlugs.turnOff`),variant:`danger`,onConfirm:()=>{_.mutate(`off`),u(!1)},onCancel:()=>u(!1)})]})}function IWe({plug:e,onClose:t}){let{t:n}=U(),r=co(),i=!!e,[a,o]=(0,y.useState)(e?.plug_type||`tasmota`),[s,c]=(0,y.useState)(e?.name||``),[l,u]=(0,y.useState)(e?.ip_address||``),[d,f]=(0,y.useState)(e?.username||``),[p,m]=(0,y.useState)(e?.password||``),[h,g]=(0,y.useState)(e?.ha_entity_id||``),[_,v]=(0,y.useState)(e?.mqtt_power_topic||e?.mqtt_topic||``),[b,x]=(0,y.useState)(e?.mqtt_power_path||``),[S,C]=(0,y.useState)((e?.mqtt_power_multiplier??e?.mqtt_multiplier??1).toString()),[w,T]=(0,y.useState)(e?.mqtt_energy_topic||``),[E,D]=(0,y.useState)(e?.mqtt_energy_path||``),[O,k]=(0,y.useState)((e?.mqtt_energy_multiplier??1).toString()),[A,j]=(0,y.useState)(e?.mqtt_state_topic||``),[M,N]=(0,y.useState)(e?.mqtt_state_path||``),[P,F]=(0,y.useState)(e?.mqtt_state_on_value||``),[I,L]=(0,y.useState)(e?.rest_on_url||``),[R,z]=(0,y.useState)(e?.rest_on_body||``),[B,V]=(0,y.useState)(e?.rest_off_url||``),[ee,te]=(0,y.useState)(e?.rest_off_body||``),[ne,re]=(0,y.useState)(e?.rest_method||`POST`),[ie,ae]=(0,y.useState)(e?.rest_headers||``),[oe,se]=(0,y.useState)(e?.rest_status_url||``),[H,ce]=(0,y.useState)(e?.rest_status_path||``),[le,ue]=(0,y.useState)(e?.rest_status_on_value||``),[de,fe]=(0,y.useState)(e?.rest_power_url||``),[pe,me]=(0,y.useState)(e?.rest_power_path||``),[he,ge]=(0,y.useState)((e?.rest_power_multiplier??1).toString()),[_e,ve]=(0,y.useState)(e?.rest_energy_url||``),[ye,be]=(0,y.useState)(e?.rest_energy_path||``),[xe,Se]=(0,y.useState)((e?.rest_energy_multiplier??1).toString()),[Ce,we]=(0,y.useState)(e?.rest_energy_total_path||``),[Te,Ee]=(0,y.useState)((e?.rest_energy_total_multiplier??1).toString()),[De,Oe]=(0,y.useState)(e?.ha_power_entity||``),[ke,Ae]=(0,y.useState)(e?.ha_energy_today_entity||``),[je,Me]=(0,y.useState)(e?.ha_energy_total_entity||``),[Ne,Pe]=(0,y.useState)(``),[Fe,Ie]=(0,y.useState)(``),[Le,Re]=(0,y.useState)(!1),ze=(0,y.useRef)(null),[Be,Ve]=(0,y.useState)(``),[He,Ue]=(0,y.useState)(!1),We=(0,y.useRef)(null),[Ge,Ke]=(0,y.useState)(``),[qe,Je]=(0,y.useState)(!1),Ye=(0,y.useRef)(null),[Xe,Ze]=(0,y.useState)(``),[Qe,$e]=(0,y.useState)(!1),et=(0,y.useRef)(null),[tt,nt]=(0,y.useState)(e?.printer_id||null),[rt,it]=(0,y.useState)(e?.controls_printer_power??!0),[at,ot]=(0,y.useState)(null),[st,ct]=(0,y.useState)(null),[lt,ut]=(0,y.useState)(e?.power_alert_enabled||!1),[dt,ft]=(0,y.useState)(e?.power_alert_high?.toString()||``),[pt,mt]=(0,y.useState)(e?.power_alert_low?.toString()||``),[ht,gt]=(0,y.useState)(e?.schedule_enabled||!1),[_t,vt]=(0,y.useState)(e?.schedule_on_time||``),[yt,bt]=(0,y.useState)(e?.schedule_off_time||``),[xt,St]=(0,y.useState)(e?.show_in_switchbar||!1),[Ct,wt]=(0,y.useState)(e?.show_on_printer_card??!0),[Tt,Et]=(0,y.useState)(!1),[Dt,Ot]=(0,y.useState)({scanned:0,total:0}),[kt,At]=(0,y.useState)([]),jt=(0,y.useRef)(null),{data:Mt}=K({queryKey:[`printers`],queryFn:Z.getPrinters}),{data:Nt}=K({queryKey:[`smart-plugs`],queryFn:Z.getSmartPlugs}),{data:Pt}=K({queryKey:[`settings`],queryFn:Z.getSettings}),Ft=!!(Pt?.ha_enabled&&Pt?.ha_url&&Pt?.ha_token);(0,y.useEffect)(()=>{let e=setTimeout(()=>{Ie(Ne)},300);return()=>clearTimeout(e)},[Ne]),(0,y.useEffect)(()=>{let e=e=>{ze.current&&!ze.current.contains(e.target)&&Re(!1),We.current&&!We.current.contains(e.target)&&Ue(!1),Ye.current&&!Ye.current.contains(e.target)&&Je(!1),et.current&&!et.current.contains(e.target)&&$e(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[]);let{data:It,isLoading:Lt,error:Rt}=K({queryKey:[`ha-entities`,Fe],queryFn:()=>Z.getHAEntities(Fe||void 0),enabled:a===`homeassistant`&&Ft,retry:!1,staleTime:0}),{data:zt}=K({queryKey:[`ha-sensor-entities`],queryFn:Z.getHASensorEntities,enabled:a===`homeassistant`&&Ft,retry:!1,staleTime:0});(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,e),()=>{window.removeEventListener(`keydown`,e),jt.current&&clearInterval(jt.current)}},[t]);let Bt=async()=>{Et(!0),At([]),Ot({scanned:0,total:0}),ct(null);try{await Z.startTasmotaScan();let e=async()=>{try{let e=await Z.getTasmotaScanStatus();Ot({scanned:e.scanned,total:e.total}),At(await Z.getDiscoveredTasmotaDevices()),e.running||(Et(!1),jt.current&&=(clearInterval(jt.current),null))}catch(e){console.error(`Polling error:`,e)}};await e(),jt.current=setInterval(e,500)}catch(e){Et(!1),ct((e instanceof Error?e.message:typeof e==`string`?e:JSON.stringify(e))||n(`smartPlugs.failedToStartScan`))}},Vt=async()=>{try{await Z.stopTasmotaScan()}catch{}Et(!1),jt.current&&=(clearInterval(jt.current),null)},Ht=e=>{u(e.ip_address),c(e.name),ot(null)},Ut=q({mutationFn:()=>Z.testSmartPlugConnection(l,d||null,p||null),onSuccess:e=>{ot(e),ct(null),!s&&e.device_name&&c(e.device_name)},onError:e=>{ot(null),ct(e.message)}}),Wt=q({mutationFn:e=>Z.createSmartPlug(e),onSuccess:()=>{r.invalidateQueries({queryKey:[`smart-plugs`]}),r.invalidateQueries({queryKey:[`scriptPlugsByPrinter`]}),t()},onError:e=>{ct(e.message)}}),Gt=q({mutationFn:t=>Z.updateSmartPlug(e.id,t),onSuccess:()=>{r.invalidateQueries({queryKey:[`smart-plugs`]}),r.invalidateQueries({queryKey:[`scriptPlugsByPrinter`]}),t()},onError:e=>{ct(e.message)}}),Kt=Mt?.filter(t=>a===`tasmota`?!Nt?.some(n=>n.printer_id===t.id&&n.id!==e?.id&&n.plug_type===`tasmota`):!0),qt=e=>{if(e.preventDefault(),ct(null),!s.trim()){ct(n(`smartPlugs.nameRequired`));return}if(a===`tasmota`&&!l.trim()){ct(`IP address is required for Tasmota plugs`);return}if(a===`homeassistant`&&!h){ct(n(`smartPlugs.entityRequired`));return}if(a===`mqtt`){let e=_.trim(),t=w.trim(),r=A.trim();if(!e&&!t&&!r){ct(n(`smartPlugs.mqttTopicRequired`));return}}if(a===`rest`&&!I.trim()&&!B.trim()){ct(n(`smartPlugs.restUrlRequired`));return}let t={name:s.trim(),plug_type:a,ip_address:a===`tasmota`?l.trim():null,ha_entity_id:a===`homeassistant`?h:null,ha_power_entity:a===`homeassistant`&&De||null,ha_energy_today_entity:a===`homeassistant`&&ke||null,ha_energy_total_entity:a===`homeassistant`&&je||null,mqtt_power_topic:a===`mqtt`&&_.trim()||null,mqtt_power_path:a===`mqtt`&&b.trim()||null,mqtt_power_multiplier:a===`mqtt`&&parseFloat(S)||1,mqtt_energy_topic:a===`mqtt`&&w.trim()||null,mqtt_energy_path:a===`mqtt`&&E.trim()||null,mqtt_energy_multiplier:a===`mqtt`&&parseFloat(O)||1,mqtt_state_topic:a===`mqtt`&&A.trim()||null,mqtt_state_path:a===`mqtt`&&M.trim()||null,mqtt_state_on_value:a===`mqtt`&&P.trim()||null,rest_on_url:a===`rest`&&I.trim()||null,rest_on_body:a===`rest`&&R.trim()||null,rest_off_url:a===`rest`&&B.trim()||null,rest_off_body:a===`rest`&&ee.trim()||null,rest_method:a===`rest`?ne:null,rest_headers:a===`rest`&&ie.trim()||null,rest_status_url:a===`rest`&&oe.trim()||null,rest_status_path:a===`rest`&&H.trim()||null,rest_status_on_value:a===`rest`&&le.trim()||null,rest_power_url:a===`rest`&&de.trim()||null,rest_power_path:a===`rest`&&pe.trim()||null,rest_power_multiplier:a===`rest`&&parseFloat(he)||1,rest_energy_url:a===`rest`&&_e.trim()||null,rest_energy_path:a===`rest`&&ye.trim()||null,rest_energy_multiplier:a===`rest`&&parseFloat(xe)||1,rest_energy_total_path:a===`rest`&&Ce.trim()||null,rest_energy_total_multiplier:a===`rest`&&parseFloat(Te)||1,username:a===`tasmota`&&d.trim()||null,password:a===`tasmota`&&p.trim()||null,printer_id:tt,controls_printer_power:rt,power_alert_enabled:lt,power_alert_high:dt?parseFloat(dt):null,power_alert_low:pt?parseFloat(pt):null,schedule_enabled:ht,schedule_on_time:_t||null,schedule_off_time:yt||null,show_in_switchbar:xt,show_on_printer_card:Ct};i?Gt.mutate(t):Wt.mutate(t)},Jt=Wt.isPending||Gt.isPending;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 flex-shrink-0`,children:[(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:n(i?`smartPlugs.editTitle`:`smartPlugs.addTitle`)}),(0,G.jsx)(`button`,{onClick:t,className:`text-bambu-gray hover:text-white transition-colors`,children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]}),(0,G.jsxs)(`form`,{onSubmit:qt,className:`p-6 space-y-4 overflow-y-auto`,children:[st&&(0,G.jsx)(`div`,{className:`p-3 bg-red-100 dark:bg-red-500/20 border border-red-400 dark:border-red-500/50 rounded-lg text-sm text-red-700 dark:text-red-400`,children:st}),!i&&(0,G.jsxs)(`div`,{className:`flex gap-2 mb-2`,children:[(0,G.jsxs)(`button`,{type:`button`,onClick:()=>{o(`tasmota`),ot(null),ct(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2.5 rounded-lg font-medium transition-colors ${a===`tasmota`?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white border border-bambu-dark-tertiary`}`,children:[(0,G.jsx)(Pl,{className:`w-4 h-4`}),`Tasmota`]}),(0,G.jsxs)(`button`,{type:`button`,onClick:()=>{o(`homeassistant`),ot(null),ct(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2.5 rounded-lg font-medium transition-colors ${a===`homeassistant`?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white border border-bambu-dark-tertiary`}`,children:[(0,G.jsx)(Bc,{className:`w-4 h-4`}),`HA`]}),(0,G.jsxs)(`button`,{type:`button`,onClick:()=>{o(`mqtt`),ot(null),ct(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2.5 rounded-lg font-medium transition-colors ${a===`mqtt`?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white border border-bambu-dark-tertiary`}`,children:[(0,G.jsx)(Bl,{className:`w-4 h-4`}),`MQTT`]}),(0,G.jsxs)(`button`,{type:`button`,onClick:()=>{o(`rest`),ot(null),ct(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2.5 rounded-lg font-medium transition-colors ${a===`rest`?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white border border-bambu-dark-tertiary`}`,children:[(0,G.jsx)(Ac,{className:`w-4 h-4`}),`REST`]})]}),!i&&a===`tasmota`&&(0,G.jsxs)(`div`,{className:`space-y-3`,children:[Tt?(0,G.jsxs)(Q,{type:`button`,variant:`secondary`,onClick:Vt,className:`w-full`,children:[(0,G.jsx)(nd,{className:`w-4 h-4`}),n(`smartPlugs.stopScanning`)]}):(0,G.jsxs)(Q,{type:`button`,variant:`primary`,onClick:Bt,className:`w-full`,children:[(0,G.jsx)(Ql,{className:`w-4 h-4`}),n(`smartPlugs.discoverTasmota`)]}),Tt&&Dt.total>0&&(0,G.jsxs)(`div`,{className:`space-y-1`,children:[(0,G.jsxs)(`div`,{className:`flex justify-between text-xs text-bambu-gray`,children:[(0,G.jsx)(`span`,{children:n(`smartPlugs.addSmartPlug.scanningNetwork`)}),(0,G.jsxs)(`span`,{children:[Dt.scanned,` / `,Dt.total]})]}),(0,G.jsx)(`div`,{className:`w-full bg-bambu-dark-tertiary rounded-full h-2`,children:(0,G.jsx)(`div`,{className:`bg-bambu-green h-2 rounded-full transition-all duration-300`,style:{width:`${Dt.scanned/Dt.total*100}%`}})})]}),kt.length>0&&(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.foundDevices`,{count:kt.length})}),(0,G.jsx)(`div`,{className:`max-h-40 overflow-y-auto space-y-1`,children:kt.map(e=>(0,G.jsxs)(`button`,{type:`button`,onClick:()=>Ht(e),className:`w-full flex items-center justify-between p-2 bg-bambu-dark hover:bg-bambu-dark-tertiary rounded-lg transition-colors text-left border border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Pl,{className:`w-4 h-4 text-bambu-green`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:e.name}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:e.ip_address})]})]}),e.state&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-xs ${e.state===`ON`?`text-bambu-green`:`text-bambu-gray`}`,children:[(0,G.jsx)(Ll,{className:`w-3 h-3`}),e.state]})]},e.ip_address))})]}),!Tt&&kt.length===0&&Dt.total>0&&(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray text-center py-2`,children:n(`smartPlugs.noDevicesFound`)})]}),a===`homeassistant`&&(0,G.jsxs)(`div`,{className:`space-y-3`,children:[!Ft&&(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{className:`p-3 bg-yellow-100 dark:bg-yellow-500/20 border border-yellow-400 dark:border-yellow-500/50 rounded-lg text-sm text-yellow-700 dark:text-yellow-400`,children:[n(`smartPlugs.haNotConfigured`),` `,(0,G.jsx)(`span`,{className:`font-medium`,children:n(`smartPlugs.haSettingsPath`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1 opacity-50`,children:n(`smartPlugs.selectEntity`)}),(0,G.jsx)(`select`,{disabled:!0,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray cursor-not-allowed opacity-50`,children:(0,G.jsx)(`option`,{children:n(`smartPlugs.addSmartPlug.chooseEntity`)})})]})]}),Ft&&(0,G.jsxs)(G.Fragment,{children:[Lt&&(0,G.jsxs)(`div`,{className:`flex items-center justify-center py-4 text-bambu-gray`,children:[(0,G.jsx)(Y,{className:`w-5 h-5 animate-spin mr-2`}),n(`smartPlugs.loadingEntities`)]}),Rt&&(0,G.jsx)(`div`,{className:`p-3 bg-red-100 dark:bg-red-500/20 border border-red-400 dark:border-red-500/50 rounded-lg text-sm text-red-700 dark:text-red-400`,children:n(`smartPlugs.failedToLoadEntities`,{error:Rt.message})}),(()=>{let t=Nt?.filter(t=>t.ha_entity_id&&t.id!==e?.id).map(e=>e.ha_entity_id)||[],r=(It||[]).filter(e=>!t.includes(e.entity_id)),i=It?.find(e=>e.entity_id===h);return(0,G.jsxs)(`div`,{ref:ze,className:`relative`,children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.selectEntity`)}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(Ql,{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:Le?Ne:i?`${i.friendly_name} (${i.entity_id})`:``,onChange:e=>{Pe(e.target.value),Le||Re(!0)},onFocus:()=>{Re(!0),Pe(``)},placeholder:n(`smartPlugs.addSmartPlug.placeholders.searchEntities`),className:`w-full pl-9 pr-8 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`}),h&&!Le&&(0,G.jsx)(`button`,{type:`button`,onClick:()=>{g(``),Pe(``)},className:`absolute right-2 top-1/2 -translate-y-1/2 p-1 hover:bg-bambu-dark-tertiary rounded`,children:(0,G.jsx)(nd,{className:`w-4 h-4 text-bambu-gray hover:text-white`})}),Lt&&(0,G.jsx)(Y,{className:`absolute right-2 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray animate-spin`})]}),Le&&(0,G.jsxs)(`div`,{className:`absolute z-50 w-full mt-1 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-60 overflow-y-auto`,children:[Lt&&(0,G.jsxs)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray flex items-center gap-2`,children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),n(`smartPlugs.loading`)]}),!Lt&&r.length===0&&(0,G.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:Fe?n(`smartPlugs.noEntitiesMatching`,{search:Fe}):n(`smartPlugs.noEntitiesAvailable`)}),!Lt&&r.map(e=>(0,G.jsxs)(`button`,{type:`button`,onClick:()=>{g(e.entity_id),Re(!1),Pe(``),s||c(e.friendly_name)},className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary transition-colors ${e.entity_id===h?`bg-bambu-green/20 text-bambu-green`:`text-white`}`,children:[(0,G.jsx)(`div`,{className:`font-medium`,children:e.friendly_name}),(0,G.jsxs)(`div`,{className:`text-xs text-bambu-gray flex items-center justify-between`,children:[(0,G.jsx)(`span`,{children:e.entity_id}),(0,G.jsx)(`span`,{className:e.state===`on`?`text-bambu-green`:``,children:e.state})]})]},e.entity_id))]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(Fe?`smartPlugs.searchingEntities`:`smartPlugs.showingEntities`,{count:r.length})})]})})(),h&&zt&&zt.length>0&&(0,G.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary pt-4 mt-4 space-y-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white font-medium mb-1`,children:n(`smartPlugs.energyMonitoringOptional`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mb-3`,children:n(`smartPlugs.energyMonitoringHint`)})]}),(()=>{let e=zt.filter(e=>e.unit_of_measurement===`W`||e.unit_of_measurement===`kW`||e.unit_of_measurement===`mW`),t=Be?e.filter(e=>e.entity_id.toLowerCase().includes(Be.toLowerCase())||e.friendly_name.toLowerCase().includes(Be.toLowerCase())):e,r=zt.find(e=>e.entity_id===De);return(0,G.jsxs)(`div`,{ref:We,className:`relative`,children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.powerSensorW`)}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(Ql,{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:He?Be:r?`${r.friendly_name} (${r.state} ${r.unit_of_measurement})`:``,onChange:e=>{Ve(e.target.value),He||Ue(!0)},onFocus:()=>{Ue(!0),Ve(``)},placeholder:n(`smartPlugs.addSmartPlug.placeholders.searchPowerSensors`),className:`w-full pl-9 pr-8 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`}),De&&!He&&(0,G.jsx)(`button`,{type:`button`,onClick:()=>{Oe(``),Ve(``)},className:`absolute right-2 top-1/2 -translate-y-1/2 p-1 hover:bg-bambu-dark-tertiary rounded`,children:(0,G.jsx)(nd,{className:`w-4 h-4 text-bambu-gray hover:text-white`})})]}),He&&(0,G.jsxs)(`div`,{className:`absolute z-50 w-full mt-1 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-48 overflow-y-auto`,children:[(0,G.jsx)(`button`,{type:`button`,onClick:()=>{Oe(``),Ue(!1),Ve(``)},className:`w-full px-3 py-2 text-left text-sm text-bambu-gray hover:bg-bambu-dark-tertiary`,children:n(`smartPlugs.none`)}),t.map(e=>(0,G.jsxs)(`button`,{type:`button`,onClick:()=>{Oe(e.entity_id),Ue(!1),Ve(``)},className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${e.entity_id===De?`bg-bambu-green/20 text-bambu-green`:`text-white`}`,children:[(0,G.jsx)(`div`,{className:`font-medium`,children:e.friendly_name}),(0,G.jsxs)(`div`,{className:`text-xs text-bambu-gray`,children:[e.entity_id,` • `,e.state,` `,e.unit_of_measurement]})]},e.entity_id)),t.length===0&&(0,G.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:n(`smartPlugs.noMatchingSensors`)})]})]})})(),(()=>{let e=zt.filter(e=>e.unit_of_measurement===`kWh`||e.unit_of_measurement===`Wh`||e.unit_of_measurement===`MWh`),t=Ge?e.filter(e=>e.entity_id.toLowerCase().includes(Ge.toLowerCase())||e.friendly_name.toLowerCase().includes(Ge.toLowerCase())):e,r=zt.find(e=>e.entity_id===ke);return(0,G.jsxs)(`div`,{ref:Ye,className:`relative`,children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.energyTodayKwh`)}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(Ql,{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:qe?Ge:r?`${r.friendly_name} (${r.state} ${r.unit_of_measurement})`:``,onChange:e=>{Ke(e.target.value),qe||Je(!0)},onFocus:()=>{Je(!0),Ke(``)},placeholder:n(`smartPlugs.addSmartPlug.placeholders.searchEnergySensors`),className:`w-full pl-9 pr-8 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`}),ke&&!qe&&(0,G.jsx)(`button`,{type:`button`,onClick:()=>{Ae(``),Ke(``)},className:`absolute right-2 top-1/2 -translate-y-1/2 p-1 hover:bg-bambu-dark-tertiary rounded`,children:(0,G.jsx)(nd,{className:`w-4 h-4 text-bambu-gray hover:text-white`})})]}),qe&&(0,G.jsxs)(`div`,{className:`absolute z-50 w-full mt-1 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-48 overflow-y-auto`,children:[(0,G.jsx)(`button`,{type:`button`,onClick:()=>{Ae(``),Je(!1),Ke(``)},className:`w-full px-3 py-2 text-left text-sm text-bambu-gray hover:bg-bambu-dark-tertiary`,children:n(`smartPlugs.none`)}),t.map(e=>(0,G.jsxs)(`button`,{type:`button`,onClick:()=>{Ae(e.entity_id),Je(!1),Ke(``)},className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${e.entity_id===ke?`bg-bambu-green/20 text-bambu-green`:`text-white`}`,children:[(0,G.jsx)(`div`,{className:`font-medium`,children:e.friendly_name}),(0,G.jsxs)(`div`,{className:`text-xs text-bambu-gray`,children:[e.entity_id,` • `,e.state,` `,e.unit_of_measurement]})]},e.entity_id)),t.length===0&&(0,G.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:n(`smartPlugs.noMatchingSensors`)})]})]})})(),(()=>{let e=zt.filter(e=>e.unit_of_measurement===`kWh`||e.unit_of_measurement===`Wh`||e.unit_of_measurement===`MWh`),t=Xe?e.filter(e=>e.entity_id.toLowerCase().includes(Xe.toLowerCase())||e.friendly_name.toLowerCase().includes(Xe.toLowerCase())):e,r=zt.find(e=>e.entity_id===je);return(0,G.jsxs)(`div`,{ref:et,className:`relative`,children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.totalEnergyKwh`)}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(Ql,{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:Qe?Xe:r?`${r.friendly_name} (${r.state} ${r.unit_of_measurement})`:``,onChange:e=>{Ze(e.target.value),Qe||$e(!0)},onFocus:()=>{$e(!0),Ze(``)},placeholder:n(`smartPlugs.addSmartPlug.placeholders.searchEnergySensors`),className:`w-full pl-9 pr-8 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`}),je&&!Qe&&(0,G.jsx)(`button`,{type:`button`,onClick:()=>{Me(``),Ze(``)},className:`absolute right-2 top-1/2 -translate-y-1/2 p-1 hover:bg-bambu-dark-tertiary rounded`,children:(0,G.jsx)(nd,{className:`w-4 h-4 text-bambu-gray hover:text-white`})})]}),Qe&&(0,G.jsxs)(`div`,{className:`absolute z-50 w-full mt-1 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-48 overflow-y-auto`,children:[(0,G.jsx)(`button`,{type:`button`,onClick:()=>{Me(``),$e(!1),Ze(``)},className:`w-full px-3 py-2 text-left text-sm text-bambu-gray hover:bg-bambu-dark-tertiary`,children:n(`smartPlugs.none`)}),t.map(e=>(0,G.jsxs)(`button`,{type:`button`,onClick:()=>{Me(e.entity_id),$e(!1),Ze(``)},className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${e.entity_id===je?`bg-bambu-green/20 text-bambu-green`:`text-white`}`,children:[(0,G.jsx)(`div`,{className:`font-medium`,children:e.friendly_name}),(0,G.jsxs)(`div`,{className:`text-xs text-bambu-gray`,children:[e.entity_id,` • `,e.state,` `,e.unit_of_measurement]})]},e.entity_id)),t.length===0&&(0,G.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:n(`smartPlugs.noMatchingSensors`)})]})]})})()]})]})]}),a===`mqtt`&&(0,G.jsxs)(`div`,{className:`space-y-3`,children:[!Pt?.mqtt_broker&&(0,G.jsxs)(`div`,{className:`p-3 bg-yellow-100 dark:bg-yellow-500/20 border border-yellow-400 dark:border-yellow-500/50 rounded-lg text-sm text-yellow-700 dark:text-yellow-400`,children:[n(`smartPlugs.mqttNotConfigured`),` `,(0,G.jsx)(`span`,{className:`font-medium`,children:n(`smartPlugs.mqttSettingsPath`)}),` `,n(`smartPlugs.mqttNotConfiguredSuffix`)]}),Pt?.mqtt_broker&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`p-3 bg-blue-50 dark:bg-blue-500/10 border border-blue-300 dark:border-blue-500/30 rounded-lg text-sm text-blue-700 dark:text-blue-300`,children:[(0,G.jsx)(`p`,{className:`font-medium mb-1`,children:n(`smartPlugs.monitorOnly`)}),(0,G.jsx)(`p`,{className:`text-xs opacity-80`,children:n(`smartPlugs.mqttMonitorOnlyDescription`)})]}),(0,G.jsxs)(`div`,{className:`space-y-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,G.jsx)(`p`,{className:`text-white font-medium text-sm`,children:n(`smartPlugs.powerMonitoring`)}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.topic`)}),(0,G.jsx)(`input`,{type:`text`,value:_,onChange:e=>v(e.target.value),placeholder:`zigbee2mqtt/shelly-working-room`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.jsonPath`)}),(0,G.jsx)(`input`,{type:`text`,value:b,onChange:e=>x(e.target.value),placeholder:`power_l1`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.multiplier`)}),(0,G.jsx)(`input`,{type:`text`,value:S,onChange:e=>C(e.target.value),placeholder:`1`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,style:{whiteSpace:`pre-line`},children:n(`smartPlugs.mqttPowerHint`)})]}),(0,G.jsxs)(`div`,{className:`space-y-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`p`,{className:`text-white font-medium text-sm`,children:[n(`smartPlugs.energyMonitoring`),` `,(0,G.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,n(`smartPlugs.optional`),`)`]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.topic`)}),(0,G.jsx)(`input`,{type:`text`,value:w,onChange:e=>T(e.target.value),placeholder:`Same as power topic, or different`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.jsonPath`)}),(0,G.jsx)(`input`,{type:`text`,value:E,onChange:e=>D(e.target.value),placeholder:`energy_l1`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.multiplier`)}),(0,G.jsx)(`input`,{type:`text`,value:O,onChange:e=>k(e.target.value),placeholder:`1`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,style:{whiteSpace:`pre-line`},children:n(`smartPlugs.mqttEnergyHint`)})]}),(0,G.jsxs)(`div`,{className:`space-y-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`p`,{className:`text-white font-medium text-sm`,children:[n(`smartPlugs.stateMonitoring`),` `,(0,G.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,n(`smartPlugs.optional`),`)`]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.topic`)}),(0,G.jsx)(`input`,{type:`text`,value:A,onChange:e=>j(e.target.value),placeholder:`Same as power topic, or different`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.jsonPath`)}),(0,G.jsx)(`input`,{type:`text`,value:M,onChange:e=>N(e.target.value),placeholder:`state_l1`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.onValue`)}),(0,G.jsx)(`input`,{type:`text`,value:P,onChange:e=>F(e.target.value),placeholder:n(`smartPlugs.addSmartPlug.placeholders.mqttStateOnValue`),className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,style:{whiteSpace:`pre-line`},children:n(`smartPlugs.mqttStateHint`)})]})]})]}),a===`rest`&&(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{className:`space-y-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,G.jsx)(`p`,{className:`text-white font-medium text-sm`,children:n(`smartPlugs.restControl`)}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restMethod`)}),(0,G.jsxs)(`select`,{value:ne,onChange:e=>re(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,G.jsx)(`option`,{value:`GET`,children:`GET`}),(0,G.jsx)(`option`,{value:`POST`,children:`POST`}),(0,G.jsx)(`option`,{value:`PUT`,children:`PUT`}),(0,G.jsx)(`option`,{value:`PATCH`,children:`PATCH`})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restOnUrl`)}),(0,G.jsx)(`input`,{type:`text`,value:I,onChange:e=>{L(e.target.value),ot(null)},placeholder:`http://openhab:8080/rest/items/MyPlug`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[n(`smartPlugs.restOnBody`),` `,(0,G.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,n(`smartPlugs.optional`),`)`]})]}),(0,G.jsx)(`input`,{type:`text`,value:R,onChange:e=>z(e.target.value),placeholder:n(`smartPlugs.restBodyHint`),className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restOffUrl`)}),(0,G.jsx)(`input`,{type:`text`,value:B,onChange:e=>{V(e.target.value),ot(null)},placeholder:`http://openhab:8080/rest/items/MyPlug`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[n(`smartPlugs.restOffBody`),` `,(0,G.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,n(`smartPlugs.optional`),`)`]})]}),(0,G.jsx)(`input`,{type:`text`,value:ee,onChange:e=>te(e.target.value),placeholder:n(`smartPlugs.restBodyHint`),className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]})]}),(0,G.jsxs)(`div`,{className:`space-y-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`p`,{className:`text-white font-medium text-sm`,children:[n(`smartPlugs.restHeaders`),` `,(0,G.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,n(`smartPlugs.optional`),`)`]})]}),(0,G.jsx)(`div`,{children:(0,G.jsx)(`textarea`,{value:ie,onChange:e=>ae(e.target.value),placeholder:n(`smartPlugs.restHeadersHint`),rows:2,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none font-mono text-sm`})})]}),(0,G.jsxs)(`div`,{className:`space-y-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`p`,{className:`text-white font-medium text-sm`,children:[n(`smartPlugs.stateMonitoring`),` `,(0,G.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,n(`smartPlugs.optional`),`)`]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restStatusUrl`)}),(0,G.jsx)(`input`,{type:`text`,value:oe,onChange:e=>se(e.target.value),placeholder:n(`smartPlugs.restStatusHint`),className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restStatusPath`)}),(0,G.jsx)(`input`,{type:`text`,value:H,onChange:e=>ce(e.target.value),placeholder:n(`smartPlugs.restPathHint`),className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restStatusOnValue`)}),(0,G.jsx)(`input`,{type:`text`,value:le,onChange:e=>ue(e.target.value),placeholder:`ON`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]})]})]}),(0,G.jsxs)(`div`,{className:`space-y-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`p`,{className:`text-white font-medium text-sm`,children:[n(`smartPlugs.energyMonitoring`),` `,(0,G.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,n(`smartPlugs.optional`),`)`]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[n(`smartPlugs.restPowerUrl`),` `,(0,G.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,n(`smartPlugs.optional`),`)`]})]}),(0,G.jsx)(`input`,{type:`text`,value:de,onChange:e=>fe(e.target.value),placeholder:n(`smartPlugs.restPowerUrlHint`),className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restPowerPath`)}),(0,G.jsx)(`input`,{type:`text`,value:pe,onChange:e=>me(e.target.value),placeholder:n(`smartPlugs.restPathHint`),className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restPowerMultiplier`)}),(0,G.jsx)(`input`,{type:`text`,value:he,onChange:e=>ge(e.target.value),placeholder:`1`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[n(`smartPlugs.restEnergyUrl`),` `,(0,G.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,n(`smartPlugs.optional`),`)`]})]}),(0,G.jsx)(`input`,{type:`text`,value:_e,onChange:e=>ve(e.target.value),placeholder:n(`smartPlugs.restEnergyUrlHint`),className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restEnergyPath`)}),(0,G.jsx)(`input`,{type:`text`,value:ye,onChange:e=>be(e.target.value),placeholder:n(`smartPlugs.restPathHint`),className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restEnergyMultiplier`)}),(0,G.jsx)(`input`,{type:`text`,value:xe,onChange:e=>Se(e.target.value),placeholder:`1`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.restEnergyHint`)}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restEnergyTotalPath`)}),(0,G.jsx)(`input`,{type:`text`,value:Ce,onChange:e=>we(e.target.value),placeholder:n(`smartPlugs.restEnergyTotalPathHint`),className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restEnergyTotalMultiplier`)}),(0,G.jsx)(`input`,{type:`text`,value:Te,onChange:e=>Ee(e.target.value),placeholder:`1`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.restEnergyTotalHint`)})]}),(I.trim()||B.trim())&&(0,G.jsx)(`div`,{className:`flex gap-2`,children:(0,G.jsxs)(Q,{type:`button`,variant:`secondary`,onClick:async()=>{ot(null);try{let e=I.trim()||B.trim(),t=await Z.testRESTConnection(e,ne,ie.trim()||null);ot({success:t.success}),t.success||ct(t.error||n(`smartPlugs.addSmartPlug.connectionFailed`))}catch{ot({success:!1}),ct(n(`smartPlugs.addSmartPlug.connectionFailed`))}},className:`w-full`,children:[(0,G.jsx)(Qu,{className:`w-4 h-4`}),n(`smartPlugs.testConnection`)]})}),at&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm ${at.success?`text-green-700 dark:text-green-400`:`text-red-700 dark:text-red-400`}`,children:[at.success?(0,G.jsx)(xs,{className:`w-4 h-4`}):(0,G.jsx)(Zu,{className:`w-4 h-4`}),at.success?n(`smartPlugs.connectionSuccess`):n(`smartPlugs.addSmartPlug.connectionFailed`)]})]}),a===`tasmota`&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.ipAddress`)}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsx)(`input`,{type:`text`,value:l,onChange:e=>{u(e.target.value),ot(null)},placeholder:`192.168.1.100`,className:`flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,G.jsxs)(Q,{type:`button`,variant:`secondary`,onClick:()=>Ut.mutate(),disabled:!l.trim()||Ut.isPending,children:[Ut.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Qu,{className:`w-4 h-4`}),n(`smartPlugs.test`)]})]})]}),a===`tasmota`&&at&&(0,G.jsx)(`div`,{className:`p-3 rounded-lg flex items-center gap-2 ${at.success?`bg-bambu-green/20 border border-bambu-green/50 text-bambu-green`:`bg-red-100 dark:bg-red-500/20 border border-red-400 dark:border-red-500/50 text-red-700 dark:text-red-400`}`,children:at.success?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(xs,{className:`w-5 h-5`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`font-medium`,children:n(`smartPlugs.connectedResult`)}),(0,G.jsxs)(`p`,{className:`text-sm opacity-80`,children:[at.device_name&&n(`smartPlugs.deviceLabel`,{name:at.device_name}),n(`smartPlugs.stateLabel`,{state:at.state})]})]})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Zu,{className:`w-5 h-5`}),(0,G.jsx)(`span`,{children:n(`smartPlugs.addSmartPlug.connectionFailed`)})]})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.nameLabel`)}),(0,G.jsx)(`input`,{type:`text`,value:s,onChange:e=>c(e.target.value),placeholder:n(`smartPlugs.addSmartPlug.placeholders.plugName`),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),a===`tasmota`&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.username`)}),(0,G.jsx)(`input`,{type:`text`,value:d,onChange:e=>f(e.target.value),placeholder:`admin`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.password`)}),(0,G.jsx)(`input`,{type:`password`,value:p,onChange:e=>m(e.target.value),placeholder:`********`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray -mt-2`,children:n(`smartPlugs.authHint`)})]}),a!==`mqtt`&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.linkToPrinter`)}),(0,G.jsxs)(`select`,{value:tt??``,onChange:e=>nt(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:n(`smartPlugs.noPrinter`)}),Kt?.map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(`smartPlugs.linkingDescription`)}),tt!==null&&(0,G.jsxs)(`div`,{className:`flex items-center justify-between mt-3`,children:[(0,G.jsxs)(`div`,{className:`pr-3`,children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`smartPlugs.controlsPrinterPower`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.controlsPrinterPowerDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer shrink-0`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:rt,onChange:e=>it(e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]})]}),(0,G.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary pt-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(qo,{className:`w-4 h-4 text-bambu-green`}),(0,G.jsx)(`span`,{className:`text-white font-medium`,children:n(`smartPlugs.powerAlerts`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:lt,onChange:e=>ut(e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),lt&&(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.alertAbove`)}),(0,G.jsx)(`input`,{type:`number`,value:dt,onChange:e=>ft(e.target.value),placeholder:`e.g. 200`,min:`0`,max:`5000`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.alertBelow`)}),(0,G.jsx)(`input`,{type:`number`,value:pt,onChange:e=>mt(e.target.value),placeholder:`e.g. 10`,min:`0`,max:`5000`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.alertDescription`)})]})]}),a!==`mqtt`&&(0,G.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary pt-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(js,{className:`w-4 h-4 text-bambu-green`}),(0,G.jsx)(`span`,{className:`text-white font-medium`,children:n(`smartPlugs.dailySchedule`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:ht,onChange:e=>gt(e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),ht&&(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.turnOnAt`)}),(0,G.jsx)(`input`,{type:`time`,value:_t,onChange:e=>vt(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.turnOffAt`)}),(0,G.jsx)(`input`,{type:`time`,value:yt,onChange:e=>bt(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.scheduleDescription`)})]})]}),(0,G.jsx)(`div`,{className:`border-t border-bambu-dark-tertiary pt-4`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Yc,{className:`w-4 h-4 text-bambu-green`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-white font-medium`,children:n(`smartPlugs.showInSwitchbar`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.quickAccessSidebar`)})]})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:xt,onChange:e=>St(e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]})}),a===`homeassistant`&&(0,G.jsx)(`div`,{className:`border-t border-bambu-dark-tertiary pt-4`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(ac,{className:`w-4 h-4 text-bambu-green`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-white font-medium`,children:n(`smartPlugs.showOnPrinterCard`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.displayOnPrinterCard`)})]})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:Ct,onChange:e=>wt(e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]})}),(0,G.jsxs)(`div`,{className:`flex gap-3 pt-2`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:t,className:`flex-1`,children:n(`smartPlugs.cancel`)}),(0,G.jsxs)(Q,{type:`submit`,disabled:Jt,className:`flex-1`,children:[Jt?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(ql,{className:`w-4 h-4`}),n(i?`smartPlugs.save`:`smartPlugs.add`)]})]})]})]})})}function LWe({sensor:e,printers:t,onClose:n}){let{t:r}=U(),i=co(),{showToast:a}=qd(),o=!!e,[s,c]=(0,y.useState)(e?.printer_id??t[0]?.id??``),[l,u]=(0,y.useState)(e?.entity_id??``),[d,f]=(0,y.useState)(e?.kind??`binary`),[p,m]=(0,y.useState)(e?.device_class??null),[h,g]=(0,y.useState)(e?.unit??null),[_,v]=(0,y.useState)(e?.name??``),[b,x]=(0,y.useState)(e?.alert_state??``),[S,C]=(0,y.useState)(e?.alert_above?.toString()??``),[w,T]=(0,y.useState)(e?.alert_below?.toString()??``),[E,D]=(0,y.useState)(e?.show_on_printer_card??!0),[O,k]=(0,y.useState)(e?.notify_on_alert??!1),[A,j]=(0,y.useState)(e?.block_print??!1),[M,N]=(0,y.useState)(``),[P,F]=(0,y.useState)(null);(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[n]);let{data:I}=K({queryKey:[`settings`],queryFn:Z.getSettings}),L=!!(I?.ha_enabled&&I?.ha_url&&I?.ha_token),{data:R,isLoading:z,error:B}=K({queryKey:[`bindableHAEntities`],queryFn:()=>Z.getBindableHAEntities(),enabled:L}),V=(0,y.useMemo)(()=>{let e=M.trim().toLowerCase(),t=R??[];return e?t.filter(t=>t.entity_id.toLowerCase().includes(e)||t.friendly_name.toLowerCase().includes(e)):t},[R,M]),ee=e=>{u(e.entity_id),m(e.device_class),g(e.unit_of_measurement);let t=e.domain===`binary_sensor`?`binary`:`numeric`;f(t),t===`numeric`?x(``):(C(``),T(``)),_.trim()||v(e.friendly_name.slice(0,100))},te=()=>{i.invalidateQueries({queryKey:[`haSensors`]}),i.invalidateQueries({queryKey:[`haSensorReadings`]})},ne=q({mutationFn:()=>{let t={name:_.trim(),entity_id:l,kind:d,device_class:p,unit:h,alert_state:d===`binary`&&b?b:null,alert_above:d===`numeric`&&S!==``?Number(S):null,alert_below:d===`numeric`&&w!==``?Number(w):null,block_print:A,notify_on_alert:O,show_on_printer_card:E};return o?Z.updateHASensor(e.id,t):Z.createHASensor({...t,printer_id:Number(s)})},onSuccess:()=>{te(),a(r(o?`haSensors.toast.updated`:`haSensors.toast.created`),`success`),n()},onError:e=>F(e.message)}),re=q({mutationFn:()=>Z.deleteHASensor(e.id),onSuccess:()=>{te(),a(r(`haSensors.toast.deleted`),`success`),n()},onError:e=>F(e.message)}),ie=d===`binary`?b!==``:S!==``||w!==``,ae=e=>{if(e.preventDefault(),F(null),!l)return F(r(`haSensors.error.pickEntity`));if(!_.trim())return F(r(`haSensors.error.nameRequired`));if(s===``)return F(r(`haSensors.error.printerRequired`));if((A||O)&&!ie)return F(r(`haSensors.error.alertRequired`));ne.mutate()},oe=MT[p??``],se=e=>{let t=oe?.[e]??e;return r(`haSensors.states.${t}`,{defaultValue:t})},H=ne.isPending||re.isPending;return(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-lg max-h-[90vh] overflow-y-auto`,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-3`,children:[(0,G.jsx)(`div`,{className:`p-2 rounded-full bg-bambu-green/20 text-bambu-green`,children:(0,G.jsx)(Tc,{className:`w-5 h-5`})}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:r(o?`haSensors.editTitle`:`haSensors.addTitle`)})]}),(0,G.jsx)(`button`,{onClick:n,className:`text-bambu-gray hover:text-white transition-colors`,children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]}),(0,G.jsxs)(`form`,{onSubmit:ae,className:`p-6 space-y-4`,children:[P&&(0,G.jsx)(`div`,{className:`p-3 bg-red-100 dark:bg-red-500/20 border border-red-300 dark:border-red-500/50 rounded-lg text-sm text-red-700 dark:text-red-400`,children:P}),!o&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`haSensors.printer`)}),(0,G.jsx)(`select`,{value:s,onChange:e=>c(e.target.value===``?``:Number(e.target.value)),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white`,children:t.map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.name},e.id))})]}),!L&&(0,G.jsxs)(`div`,{className:`p-3 bg-yellow-100 dark:bg-yellow-500/20 border border-yellow-400 dark:border-yellow-500/50 rounded-lg text-sm text-yellow-700 dark:text-yellow-400`,children:[r(`smartPlugs.haNotConfigured`),` `,(0,G.jsx)(`span`,{className:`font-medium`,children:r(`smartPlugs.haSettingsPath`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1 ${L?``:`opacity-50`}`,children:r(`haSensors.entity`)}),B&&(0,G.jsx)(`div`,{className:`p-3 mb-2 bg-red-100 dark:bg-red-500/20 rounded-lg text-sm text-red-700 dark:text-red-400`,children:B.message}),(0,G.jsxs)(`div`,{className:`relative mb-2`,children:[(0,G.jsx)(Ql,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,G.jsx)(`input`,{type:`text`,value:M,onChange:e=>N(e.target.value),placeholder:r(`haSensors.searchPlaceholder`),disabled:!L,className:`w-full pl-9 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white disabled:opacity-50 disabled:cursor-not-allowed`})]}),(0,G.jsxs)(`div`,{className:`max-h-44 overflow-y-auto rounded-lg border border-bambu-dark-tertiary ${L?``:`opacity-50`}`,children:[!L&&(0,G.jsx)(`div`,{className:`p-3 text-sm text-bambu-gray`,children:r(`haSensors.noEntities`)}),L&&z&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2 p-3 text-sm text-bambu-gray`,children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),r(`common.loading`)]}),L&&!z&&V.length===0&&(0,G.jsx)(`div`,{className:`p-3 text-sm text-bambu-gray`,children:r(`haSensors.noEntities`)}),L&&!z&&V.map(e=>(0,G.jsxs)(`button`,{type:`button`,onClick:()=>ee(e),className:`w-full text-left px-3 py-2 text-sm transition-colors ${e.entity_id===l?`bg-bambu-green/20 text-bambu-green`:`text-white hover:bg-bambu-dark`}`,children:[(0,G.jsx)(`div`,{className:`font-medium`,children:e.friendly_name}),(0,G.jsxs)(`div`,{className:`text-xs text-bambu-gray`,children:[e.entity_id,e.state!==null&&` — ${e.state}`,e.unit_of_measurement?` ${e.unit_of_measurement}`:``]})]},e.entity_id))]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`haSensors.name`)}),(0,G.jsx)(`input`,{type:`text`,value:_,onChange:e=>v(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`haSensors.alertWhen`)}),d===`binary`?(0,G.jsxs)(`select`,{value:b,onChange:e=>x(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white`,children:[(0,G.jsx)(`option`,{value:``,children:r(`haSensors.alertNever`)}),(0,G.jsx)(`option`,{value:`on`,children:se(`on`)}),(0,G.jsx)(`option`,{value:`off`,children:se(`off`)})]}):(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`span`,{className:`block text-xs text-bambu-gray mb-1`,children:[r(`haSensors.alertAbove`),` `,h??``]}),(0,G.jsx)(`input`,{type:`number`,step:`any`,value:S,onChange:e=>C(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`span`,{className:`block text-xs text-bambu-gray mb-1`,children:[r(`haSensors.alertBelow`),` `,h??``]}),(0,G.jsx)(`input`,{type:`number`,step:`any`,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`})]})]}),(0,G.jsx)(`p`,{className:`mt-1 text-xs text-bambu-gray`,children:r(`haSensors.alertHint`)})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:E,onChange:e=>D(e.target.checked),className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`text-sm text-white`,children:r(`haSensors.showOnCard`)})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:O,onChange:e=>k(e.target.checked),disabled:!ie,className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`text-sm ${ie?`text-white`:`text-bambu-gray`}`,children:r(`haSensors.notifyOnAlert`)})]}),(0,G.jsxs)(`label`,{className:`flex items-start gap-3 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A,onChange:e=>j(e.target.checked),disabled:!ie,className:`w-4 h-4 mt-0.5`}),(0,G.jsxs)(`span`,{children:[(0,G.jsx)(`span`,{className:`block text-sm ${ie?`text-white`:`text-bambu-gray`}`,children:r(`haSensors.blockPrint`)}),(0,G.jsx)(`span`,{className:`block text-xs text-bambu-gray`,children:r(`haSensors.blockPrintHint`)})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between pt-2`,children:[o?(0,G.jsx)(Q,{type:`button`,variant:`danger`,onClick:()=>re.mutate(),disabled:H,children:r(`common.delete`)}):(0,G.jsx)(`span`,{}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:n,disabled:H,children:r(`common.cancel`)}),(0,G.jsxs)(Q,{type:`submit`,disabled:H||!L&&!o,children:[H?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(ql,{className:`w-4 h-4`}),r(`common.save`)]})]})]})]})]})})}function Z6({open:e,onClose:t,onPickLocation:n,startCreating:r}){let{t:i}=U(),a=co(),{showToast:o}=qd(),[s,c]=(0,y.useState)(!1),[l,u]=(0,y.useState)(null),[d,f]=(0,y.useState)(``),[p,m]=(0,y.useState)(null),{data:h=[],isLoading:g}=K({queryKey:v6,queryFn:Z.getLocations,enabled:e}),{data:_=[]}=K({queryKey:[`locationHaSensors`],queryFn:()=>Z.getLocationHASensors(),enabled:e}),v=_.reduce((e,t)=>(e[t.location_id]=(e[t.location_id]??0)+1,e),{}),b=()=>{y6(a),a.invalidateQueries({queryKey:[`inventory-spools`]}),a.invalidateQueries({queryKey:[`spoolman-inventory-spools`]}),a.invalidateQueries({queryKey:[`locationHaSensors`]}),a.invalidateQueries({queryKey:[`locationHaSensorReadings`]})},x=q({mutationFn:async()=>{let e=d.trim();if(!e)throw Error(i(`locations.nameRequired`));return l?Z.updateLocation(l.id,{name:e}):Z.createLocation({name:e})},onSuccess:e=>{if(o(i(l?`locations.updated`:`locations.created`),`success`),b(),!l&&r){n?.(e.id),t();return}c(!1),u(null),f(``)},onError:e=>{o(e.message||i(`locations.saveFailed`),`error`)}}),S=q({mutationFn:e=>Z.deleteLocation(e),onSuccess:()=>{o(i(`locations.deleted`),`success`),m(null),b()},onError:e=>{o(e.message||i(`locations.deleteFailed`),`error`)}}),C=()=>{u(null),f(``),c(!0)};(0,y.useEffect)(()=>{e&&r&&(u(null),f(``),c(!0))},[e,r]);let w=e=>{u(e),f(e.name),c(!0)},T=(0,y.useCallback)(()=>{if(!x.isPending){if(r){t();return}c(!1),u(null),f(``)}},[x.isPending,r,t]);(0,y.useEffect)(()=>{if(!e)return;let n=e=>{e.key===`Escape`&&(x.isPending||S.isPending||(s?T():p||t()))};return document.addEventListener(`keydown`,n),()=>document.removeEventListener(`keydown`,n)},[e,s,p,x.isPending,S.isPending,T,t]);let E=e=>{e.preventDefault(),x.mutate()};if(!e)return null;let D=`locations-modal-title`,O=`location-editor-title`,k=(0,G.jsxs)(`form`,{onSubmit:E,children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,htmlFor:`location-name`,children:i(`locations.name`)}),(0,G.jsx)(`input`,{id:`location-name`,type:`text`,maxLength:255,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green mb-4`,placeholder:i(`locations.createPlaceholder`),value:d,onChange:e=>f(e.target.value),autoFocus:!0}),(0,G.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:T,children:i(`common.cancel`)}),(0,G.jsxs)(Q,{type:`submit`,disabled:x.isPending||!d.trim(),children:[x.isPending&&(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),i(`common.save`)]})]})]});return r?s?(0,G.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[(0,G.jsx)(`div`,{className:`absolute inset-0 bg-black/60`,onClick:T}),(0,G.jsxs)(`div`,{className:`relative w-full max-w-md mx-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl p-6 shadow-2xl`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":O,children:[(0,G.jsx)(`h3`,{id:O,className:`text-lg font-semibold text-white mb-4`,children:i(`locations.add`)}),k]})]}):null:(0,G.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[(0,G.jsx)(`div`,{className:`absolute inset-0 bg-black/60`,onClick:()=>{x.isPending||S.isPending||t()}}),(0,G.jsxs)(`div`,{className:`relative w-full max-w-2xl mx-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl shadow-2xl max-h-[90vh] flex flex-col`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":D,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-4 px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`h2`,{id:D,className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(ol,{className:`w-5 h-5 text-bambu-green`}),i(`locations.title`)]}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-sm mt-0.5`,children:i(`locations.subtitle`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(Q,{onClick:C,children:[(0,G.jsx)(Fl,{className:`w-4 h-4`}),i(`locations.add`)]}),(0,G.jsx)(`button`,{type:`button`,className:`p-1.5 text-bambu-gray hover:text-white rounded`,onClick:t,"aria-label":i(`common.close`),children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]})]}),(0,G.jsx)(`div`,{className:`overflow-y-auto`,children:g?(0,G.jsxs)(`div`,{className:`flex items-center justify-center py-16 text-bambu-gray`,children:[(0,G.jsx)(Y,{className:`w-6 h-6 animate-spin mr-2`}),i(`common.loading`)]}):h.length===0?(0,G.jsx)(`div`,{className:`py-16 text-center text-bambu-gray`,children:i(`locations.empty`)}):(0,G.jsxs)(`table`,{className:`w-full text-sm table-fixed`,children:[(0,G.jsx)(`thead`,{children:(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary text-left text-bambu-gray`,children:[(0,G.jsx)(`th`,{className:`px-4 py-3 font-medium`,children:i(`locations.name`)}),(0,G.jsx)(`th`,{className:`px-2 py-3 font-medium text-right w-24`,children:i(`locations.sensors`)}),(0,G.jsx)(`th`,{className:`pl-[28px] pr-4 py-3 font-medium text-right w-28`,children:i(`locations.spools`)}),(0,G.jsx)(`th`,{className:`px-4 py-3 font-medium text-right w-32`,children:i(`common.actions`)})]})}),(0,G.jsx)(`tbody`,{children:h.map(e=>(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/60 hover:bg-bambu-dark-tertiary/30 cursor-pointer`,onClick:()=>{n&&(n(e.id),t())},children:[(0,G.jsx)(`td`,{className:`px-4 py-3 text-white font-medium truncate`,children:e.name}),(0,G.jsx)(`td`,{className:`px-2 py-3 text-right text-bambu-gray`,children:v[e.id]??0}),(0,G.jsx)(`td`,{className:`pl-[28px] pr-4 py-3 text-right text-bambu-gray`,children:e.spool_count}),(0,G.jsx)(`td`,{className:`px-4 py-3 text-right`,onClick:e=>e.stopPropagation(),children:(0,G.jsxs)(`div`,{className:`flex items-center justify-end gap-1`,children:[(0,G.jsx)(`button`,{type:`button`,className:`p-1.5 text-bambu-gray hover:text-bambu-green rounded`,onClick:()=>w(e),title:i(`common.edit`),"aria-label":i(`locations.editAria`,{name:e.name,defaultValue:`Edit ${e.name}`}),children:(0,G.jsx)(Al,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{type:`button`,className:`p-1.5 text-bambu-gray hover:text-red-600 dark:hover:text-red-400 rounded disabled:opacity-40`,disabled:e.spool_count>0,onClick:()=>m(e),title:e.spool_count>0?i(`locations.deleteBlocked`):i(`common.delete`),"aria-label":i(`locations.deleteAria`,{name:e.name,defaultValue:`Delete ${e.name}`}),children:(0,G.jsx)(Pu,{className:`w-4 h-4`})})]})})]},e.id))})]})})]}),s&&(0,G.jsxs)(`div`,{className:`fixed inset-0 z-[60] flex items-center justify-center`,children:[(0,G.jsx)(`div`,{className:`absolute inset-0 bg-black/60`,onClick:T}),(0,G.jsxs)(`div`,{className:`relative w-full max-w-md mx-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl p-6 shadow-2xl`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":O,children:[(0,G.jsx)(`h3`,{id:O,className:`text-lg font-semibold text-white mb-4`,children:i(l?`locations.edit`:`locations.add`)}),k]})]}),p&&(0,G.jsx)(of,{title:i(`locations.confirmDelete`,{name:p.name}),message:v[p.id]?i(`locations.confirmDeleteMessageWithSensors`):i(`locations.confirmDeleteMessage`),confirmText:i(`common.delete`),variant:`danger`,isLoading:S.isPending,onConfirm:()=>S.mutate(p.id),onCancel:()=>m(null)})]})}function Q6(e){return e===`temperature`?`temperature`:e===`humidity`?`humidity`:e===`battery`?`battery`:null}var $6={temperature:`temperature`,humidity:`humidity`,battery:`battery`};function RWe(e,t,n){let r=$6[t];if(!e.toLowerCase().endsWith(r))return[];let i=e.slice(0,e.length-r.length),a=[];return Object.keys($6).forEach(e=>{if(e===t)return;let r=`${i}${$6[e]}`.toLowerCase(),o=n.find(e=>e.entity_id.toLowerCase()===r);o&&a.push(o)}),a}function zWe({sensor:e,locations:t,onClose:n}){let{t:r}=U(),i=co(),{showToast:a}=qd(),o=!!e,[s,c]=(0,y.useState)(e?.location_id??t[0]?.id??``),[l,u]=(0,y.useState)(e?.entity_id??``),[d,f]=(0,y.useState)(e?.kind??`numeric`),[p,m]=(0,y.useState)(e?.device_class??null),[h,g]=(0,y.useState)(e?.unit??null),[_,v]=(0,y.useState)(e?.name??``),b=(0,y.useRef)(e?.name??``),[x,S]=(0,y.useState)(e?.alert_state??``),[C,w]=(0,y.useState)(e?.alert_above?.toString()??``),[T,E]=(0,y.useState)(e?.alert_below?.toString()??``),[D,O]=(0,y.useState)(e?.notify_on_alert??!1),[k,A]=(0,y.useState)(e?.show_on_card??!0),[j,M]=(0,y.useState)(``),[N,P]=(0,y.useState)(null),[F,I]=(0,y.useState)(!1),[L,R]=(0,y.useState)(!1),[z,B]=(0,y.useState)(null),[V,ee]=(0,y.useState)(!1),[te,ne]=(0,y.useState)([]),[re,ie]=(0,y.useState)({}),{data:ae}=K({queryKey:[`settings`],queryFn:Z.getSettings}),oe=!!(ae?.ha_enabled&&ae?.ha_url&&ae?.ha_token),{data:se,isLoading:H,error:ce}=K({queryKey:[`bindableLocationHAEntities`],queryFn:()=>Z.getBindableLocationHAEntities(),enabled:oe}),le=(0,y.useMemo)(()=>(se??[]).filter(e=>Q6(e.device_class)!==null),[se]),{data:ue}=K({queryKey:[`locationHaSensors`],queryFn:()=>Z.getLocationHASensors()}),de=le.find(e=>e.entity_id===l),fe=(0,y.useMemo)(()=>{let e=j.trim().toLowerCase(),t=le??[],n=e?t.filter(t=>t.entity_id.toLowerCase().includes(e)||t.friendly_name.toLowerCase().includes(e)):t;return!de||n[0]?.entity_id===de.entity_id?n:[de,...n.filter(e=>e.entity_id!==de.entity_id)]},[le,j,de]),pe=e=>{u(e.entity_id),m(e.device_class),g(e.unit_of_measurement?.slice(0,16)??null);let t=e.domain===`binary_sensor`?`binary`:`numeric`;if(f(t),t===`numeric`?S(``):(w(``),E(``)),_===b.current){let t=e.friendly_name.slice(0,100);v(t),b.current=t}if(!o){let n=Q6(e.device_class);if(n){let e=C6(ae?.location_sensor_alert_defaults)[n];t===`numeric`&&(w(n===`battery`?``:e.alertAbove),E(e.alertBelow)),O(e.notifyOnAlert),A(e.showOnCard)}}},me=()=>{i.invalidateQueries({queryKey:[`locationHaSensors`]}),i.invalidateQueries({queryKey:[`locationHaSensorReadings`]})},he=()=>({name:_.trim(),entity_id:l,kind:d,device_class:p,unit:h,alert_state:d===`binary`&&x?x:null,alert_above:d===`numeric`&&Q6(p)!==`battery`&&C!==``?Number(C):null,alert_below:d===`numeric`&&T!==``?Number(T):null,notify_on_alert:D,show_on_card:k}),ge=q({mutationFn:()=>{let t=he();return o?Z.updateLocationHASensor(e.id,t):Z.createLocationHASensor({...t,location_id:Number(s)})},onSuccess:()=>{me(),a(r(o?`locationHaSensors.toast.updated`:`locationHaSensors.toast.created`),`success`),n()},onError:e=>P(e.message)}),_e=q({mutationFn:async()=>{let e=Number(s);await Z.createLocationHASensor({...he(),location_id:e});let t=C6(ae?.location_sensor_alert_defaults),n=te.filter(e=>re[e.entity_id]);for(let r of n){let n=Q6(r.device_class),i=n?t[n]:null;await Z.createLocationHASensor({name:r.friendly_name.slice(0,100),entity_id:r.entity_id,kind:r.domain===`binary_sensor`?`binary`:`numeric`,device_class:r.device_class,unit:r.unit_of_measurement?.slice(0,16)??null,alert_state:null,alert_above:n!==`battery`&&i&&i.alertAbove!==``?Number(i.alertAbove):null,alert_below:i&&i.alertBelow!==``?Number(i.alertBelow):null,notify_on_alert:i?.notifyOnAlert??!1,show_on_card:i?.showOnCard??k,location_id:e})}return n},onSuccess:e=>{me(),ee(!1),e.length>0?a(r(`locationHaSensors.autoAdd.added`,{names:e.map(e=>e.entity_id).join(`, `)}),`success`):a(r(`locationHaSensors.toast.created`),`success`),n()},onError:e=>{me(),ee(!1),P(e.message)}}),ve=q({mutationFn:()=>Z.deleteLocationHASensor(e.id),onSuccess:()=>{me(),a(r(`locationHaSensors.toast.deleted`),`success`),n()},onError:e=>P(e.message)}),ye=q({mutationFn:()=>Z.updateLocationHASensor(z.id,he()),onSuccess:()=>{me(),R(!1),B(null),a(r(`locationHaSensors.toast.updated`),`success`),n()},onError:e=>{R(!1),B(null),P(e.message)}}),be=d===`binary`?x!==``:C!==``||T!==``,xe=e=>{if(e.preventDefault(),P(null),!l)return P(r(`haSensors.error.pickEntity`));if(!_.trim())return P(r(`haSensors.error.nameRequired`));if(s===``)return P(r(`locationHaSensors.error.locationRequired`));if(D&&!be)return P(r(`haSensors.error.alertRequired`));if(!o){let e=(ue??[]).filter(e=>e.location_id===Number(s)),t=Q6(p);if(t){let n=e.find(e=>Q6(e.device_class)===t);if(n){B(n),R(!0);return}}if(e.length===0&&t){let e=RWe(l,t,le);if(e.length>0){ne(e),ie(Object.fromEntries(e.map(e=>[e.entity_id,!0]))),ee(!0);return}a(r(`locationHaSensors.autoAdd.noneFound`),`info`)}}ge.mutate()},Se=MT[p??``],Ce=e=>{let t=Se?.[e]??e;return r(`haSensors.states.${t}`,{defaultValue:t})},we=ge.isPending||ve.isPending||ye.isPending||_e.isPending,Te=t.find(e=>e.id===Number(s));return(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&!we&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[n,we]),(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:()=>{we||n()},children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-lg max-h-[90vh] overflow-y-auto`,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-3`,children:[(0,G.jsx)(`div`,{className:`p-2 rounded-full bg-bambu-green/20 text-bambu-green`,children:(0,G.jsx)(Tc,{className:`w-5 h-5`})}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:r(o?`locationHaSensors.editTitle`:`locationHaSensors.addTitle`)})]}),(0,G.jsx)(`button`,{onClick:n,disabled:we,className:`text-bambu-gray hover:text-white transition-colors disabled:opacity-50 disabled:cursor-not-allowed`,children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]}),(0,G.jsxs)(`form`,{onSubmit:xe,className:`p-6 space-y-4`,children:[N&&(0,G.jsx)(`div`,{className:`p-3 bg-red-100 dark:bg-red-500/20 border border-red-300 dark:border-red-500/50 rounded-lg text-sm text-red-700 dark:text-red-400`,children:N}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`locationHaSensors.location`)}),o?(0,G.jsx)(`div`,{className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white`,children:t.find(t=>t.id===e.location_id)?.name??r(`locationHaSensors.unknownLocation`)}):(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`select`,{value:s,onChange:e=>c(e.target.value===``?``:Number(e.target.value)),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white`,children:t.map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.name},e.id))}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>I(!0),className:`p-2 rounded-lg bg-bambu-dark-tertiary hover:bg-bambu-gray-dark text-white transition-colors shrink-0`,title:r(`locations.add`),"aria-label":r(`locations.add`),children:(0,G.jsx)(Fl,{className:`w-4 h-4`})})]})]}),!oe&&(0,G.jsxs)(`div`,{className:`p-3 bg-yellow-100 dark:bg-yellow-500/20 border border-yellow-400 dark:border-yellow-500/50 rounded-lg text-sm text-yellow-700 dark:text-yellow-400`,children:[r(`smartPlugs.haNotConfigured`),` `,(0,G.jsx)(`span`,{className:`font-medium`,children:r(`smartPlugs.haSettingsPath`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1 ${oe?``:`opacity-50`}`,children:r(`haSensors.entity`)}),ce&&(0,G.jsx)(`div`,{className:`p-3 mb-2 bg-red-100 dark:bg-red-500/20 rounded-lg text-sm text-red-700 dark:text-red-400`,children:ce.message}),(0,G.jsxs)(`div`,{className:`relative mb-2`,children:[(0,G.jsx)(Ql,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,G.jsx)(`input`,{type:`text`,value:j,onChange:e=>M(e.target.value),placeholder:r(`haSensors.searchPlaceholder`),disabled:!oe,className:`w-full pl-9 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white disabled:opacity-50 disabled:cursor-not-allowed`})]}),(0,G.jsxs)(`div`,{className:`max-h-44 overflow-y-auto rounded-lg border border-bambu-dark-tertiary ${oe?``:`opacity-50`}`,children:[l&&!de&&(0,G.jsx)(`div`,{className:`px-3 py-2 text-sm bg-bambu-green/10 text-bambu-green border-b border-bambu-dark-tertiary`,children:r(`locationHaSensors.currentlyBound`,{entity:l})}),!oe&&(0,G.jsx)(`div`,{className:`p-3 text-sm text-bambu-gray`,children:r(`haSensors.noEntities`)}),oe&&H&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2 p-3 text-sm text-bambu-gray`,children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),r(`common.loading`)]}),oe&&!H&&fe.length===0&&(0,G.jsx)(`div`,{className:`p-3 text-sm text-bambu-gray`,children:r(`haSensors.noEntities`)}),oe&&!H&&fe.map(e=>(0,G.jsxs)(`button`,{type:`button`,onClick:()=>pe(e),className:`w-full text-left px-3 py-2 text-sm transition-colors ${e.entity_id===l?`bg-bambu-green/20 text-bambu-green`:`text-white hover:bg-bambu-dark`}`,children:[(0,G.jsx)(`div`,{className:`font-medium`,children:e.friendly_name}),(0,G.jsxs)(`div`,{className:`text-xs text-bambu-gray`,children:[e.entity_id,e.state!==null&&` — ${e.state}`,e.unit_of_measurement?` ${e.unit_of_measurement}`:``]})]},e.entity_id))]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,htmlFor:`location-ha-sensor-name`,children:r(`haSensors.name`)}),(0,G.jsx)(`input`,{id:`location-ha-sensor-name`,type:`text`,value:_,onChange:e=>v(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white`})]}),l&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`haSensors.alertWhen`)}),d===`binary`?(0,G.jsxs)(`select`,{value:x,onChange:e=>S(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white`,children:[(0,G.jsx)(`option`,{value:``,children:r(`haSensors.alertNever`)}),(0,G.jsx)(`option`,{value:`on`,children:Ce(`on`)}),(0,G.jsx)(`option`,{value:`off`,children:Ce(`off`)})]}):Q6(p)===`battery`?(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`span`,{className:`block text-xs text-bambu-gray mb-1`,children:[r(`haSensors.alertBelow`),` `,h??``]}),(0,G.jsx)(`input`,{type:`number`,step:`any`,value:T,onChange:e=>E(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white`})]}):(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`span`,{className:`block text-xs text-bambu-gray mb-1`,children:[r(`haSensors.alertAbove`),` `,h??``]}),(0,G.jsx)(`input`,{type:`number`,step:`any`,value:C,onChange:e=>w(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`span`,{className:`block text-xs text-bambu-gray mb-1`,children:[r(`haSensors.alertBelow`),` `,h??``]}),(0,G.jsx)(`input`,{type:`number`,step:`any`,value:T,onChange:e=>E(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white`})]})]}),(0,G.jsx)(`p`,{className:`mt-1 text-xs text-bambu-gray`,children:r(`haSensors.alertHint`)})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:k,onChange:e=>A(e.target.checked),className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`text-sm text-white`,children:r(`locationHaSensors.showOnCard`)})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:D,onChange:e=>O(e.target.checked),disabled:!be,className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`text-sm ${be?`text-white`:`text-bambu-gray`}`,children:r(`haSensors.notifyOnAlert`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between pt-2`,children:[o?(0,G.jsx)(Q,{type:`button`,variant:`danger`,onClick:()=>ve.mutate(),disabled:we,children:r(`common.delete`)}):(0,G.jsx)(`span`,{}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:n,disabled:we,children:r(`common.cancel`)}),(0,G.jsxs)(Q,{type:`submit`,disabled:we||!oe&&!o,children:[we?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(ql,{className:`w-4 h-4`}),r(`common.save`)]})]})]})]})]})}),L&&z&&(0,G.jsx)(of,{title:r(`locationHaSensors.overwriteConfirm.title`),message:r(`locationHaSensors.overwriteConfirm.message${Q6(z.device_class)===`humidity`?`Humidity`:Q6(z.device_class)===`battery`?`Battery`:`Temperature`}`,{location:Te?.name??``,name:z.name}),variant:`warning`,overlayZIndex:`z-[110]`,isLoading:ye.isPending,onConfirm:()=>ye.mutate(),onCancel:()=>{R(!1),B(null)}}),V&&te.length>0&&(0,G.jsx)(of,{title:r(`locationHaSensors.autoAdd.confirmTitle`),message:r(`locationHaSensors.autoAdd.confirmMessage`),overlayZIndex:`z-[110]`,isLoading:_e.isPending,confirmDisabled:!te.some(e=>re[e.entity_id]),onConfirm:()=>_e.mutate(),cancelText:r(`locationHaSensors.autoAdd.onlyThisOne`),onCancel:()=>{ee(!1),ne([]),ie({}),ge.mutate()},children:(0,G.jsx)(`div`,{className:`space-y-2`,children:te.map(e=>(0,G.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:re[e.entity_id]??!0,onChange:t=>ie(n=>({...n,[e.entity_id]:t.target.checked})),className:`w-4 h-4`}),(0,G.jsxs)(`span`,{className:`text-sm text-white`,children:[e.friendly_name,(0,G.jsxs)(`span`,{className:`text-bambu-gray`,children:[` — `,e.entity_id]})]})]},e.entity_id))})}),F&&(0,G.jsx)(Z6,{open:F,onClose:()=>I(!1),onPickLocation:e=>{c(e),I(!1)},startCreating:!0})]})}var e8=60,t8=120,BWe={temperature:Mu,humidity:Qs,battery:Wo},VWe={temperature:`°C`,humidity:`%`,battery:`%`};function n8(e){return e===`temperature`?`temperature`:e===`humidity`?`humidity`:e===`battery`?`battery`:null}function r8({category:e,state:t,onChange:n}){let{t:r}=U(),i=BWe[e],a=VWe[e],o=t.alertAbove!==``||t.alertBelow!==``;return(0,G.jsxs)(`div`,{className:`p-3 border border-bambu-dark-tertiary rounded-lg space-y-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 text-sm text-white font-medium`,children:[(0,G.jsx)(i,{className:`w-4 h-4`}),r(`inventory.${e}`)]}),e===`battery`?(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`span`,{className:`block text-xs text-bambu-gray mb-1`,children:[r(`haSensors.alertBelow`),` `,a]}),(0,G.jsx)(`input`,{type:`number`,step:`any`,value:t.alertBelow,onChange:e=>n({alertBelow:e.target.value}),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white`})]}):(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`span`,{className:`block text-xs text-bambu-gray mb-1`,children:[r(`haSensors.alertAbove`),` `,a]}),(0,G.jsx)(`input`,{type:`number`,step:`any`,value:t.alertAbove,onChange:e=>n({alertAbove:e.target.value}),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`span`,{className:`block text-xs text-bambu-gray mb-1`,children:[r(`haSensors.alertBelow`),` `,a]}),(0,G.jsx)(`input`,{type:`number`,step:`any`,value:t.alertBelow,onChange:e=>n({alertBelow:e.target.value}),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white`})]})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:t.showOnCard,onChange:e=>n({showOnCard:e.target.checked}),className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`text-sm text-white`,children:r(`locationHaSensors.showOnCard`)})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:t.notifyOnAlert,onChange:e=>n({notifyOnAlert:e.target.checked}),disabled:!o,className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`text-sm ${o?`text-white`:`text-bambu-gray`}`,children:r(`haSensors.notifyOnAlert`)})]})]})}function HWe({onClose:e}){let{t}=U(),{showToast:n}=qd(),r=co(),[i,a]=(0,y.useState)(()=>C6()),[o,s]=(0,y.useState)(()=>T6()),[c,l]=(0,y.useState)(()=>P6()),[u,d]=(0,y.useState)(()=>F6()),[f,p]=(0,y.useState)(()=>I6()),[m,h]=(0,y.useState)(!1),{data:g}=K({queryKey:[`settings`],queryFn:Z.getSettings}),[_,v]=(0,y.useState)(t8),b=(0,y.useRef)(!1),x=(0,y.useRef)(new Set);(0,y.useEffect)(()=>{if(!g||b.current)return;b.current=!0,x.current.has(`pollInterval`)||v(g.location_sensor_poll_interval);let e=C6(g.location_sensor_alert_defaults);a(t=>{let n={...e};return Object.keys(n).forEach(e=>{x.current.has(e)&&(n[e]=t[e])}),n})},[g]);let S=(e,t)=>{x.current.add(e),a(n=>({...n,[e]:{...n[e],...t}}))},C=e=>{x.current.add(`pollInterval`),v(e)},w=async()=>{let e=Math.max(e8,_),t=mWe({...i,battery:{...i.battery,alertAbove:``}}),n={};g&&e!==g.location_sensor_poll_interval&&(n.location_sensor_poll_interval=e),g&&t!==g.location_sensor_alert_defaults&&(n.location_sensor_alert_defaults=t),Object.keys(n).length>0&&(await Z.updateSettings(n),r.invalidateQueries({queryKey:[`settings`]})),hWe(i),gWe(o),_We(c),vWe(u),yWe(f)},T=q({mutationFn:w,onSuccess:()=>{n(t(`locationHaSensors.options.saved`),`success`),e()},onError:e=>{n(e.message||t(`locationHaSensors.options.saveFailed`),`error`)}}),E=e=>{e.preventDefault(),T.mutate()},D=q({mutationFn:async()=>{let[e,t]=await Promise.all([Z.getLocationHASensors(),Z.getBindableLocationHAEntities()]),n=new Map(t.map(e=>[e.entity_id,e.friendly_name])),r=e.filter(e=>n8(e.device_class)!==null);return await Promise.all(r.map(e=>{let t=n8(e.device_class),r=i[t],a=n.get(e.entity_id);return Z.updateLocationHASensor(e.id,{...a?{name:a.slice(0,100)}:{},alert_above:t!==`battery`&&r.alertAbove!==``?Number(r.alertAbove):null,alert_below:r.alertBelow===``?null:Number(r.alertBelow),notify_on_alert:r.notifyOnAlert,show_on_card:r.showOnCard})})),await w(),r.length},onSuccess:i=>{r.invalidateQueries({queryKey:[`locationHaSensors`]}),r.invalidateQueries({queryKey:[`locationHaSensorReadings`]}),n(t(`locationHaSensors.options.resetDone`,{count:i}),`success`),h(!1),e()},onError:e=>{n(e.message||t(`locationHaSensors.options.resetFailed`),`error`),h(!1)}});return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:e,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-lg max-h-[90vh] overflow-y-auto`,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-3`,children:[(0,G.jsx)(`div`,{className:`p-2 rounded-full bg-bambu-green/20 text-bambu-green`,children:(0,G.jsx)(nu,{className:`w-5 h-5`})}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:t(`locationHaSensors.options.title`)})]}),(0,G.jsx)(`button`,{onClick:e,className:`text-bambu-gray hover:text-white transition-colors`,children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]}),(0,G.jsxs)(`form`,{onSubmit:E,className:`px-6 pb-6 pt-3 space-y-4`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:t(`locationHaSensors.options.description`)}),(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsx)(r8,{category:`temperature`,state:i.temperature,onChange:e=>S(`temperature`,e)}),(0,G.jsx)(r8,{category:`humidity`,state:i.humidity,onChange:e=>S(`humidity`,e)}),(0,G.jsx)(r8,{category:`battery`,state:i.battery,onChange:e=>S(`battery`,e)})]}),(0,G.jsxs)(`div`,{className:`p-3 border border-bambu-dark-tertiary rounded-lg space-y-3`,children:[(0,G.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:o,onChange:e=>s(e.target.checked),className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`text-sm text-white`,children:t(`locationHaSensors.options.colorizeValues`)})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-3 gap-x-3 gap-y-1 items-end ${o?``:`opacity-50`}`,children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray`,htmlFor:`location-sensor-below-color`,children:t(`locationHaSensors.options.belowColor`)}),(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray`,htmlFor:`location-sensor-optimal-color`,children:t(`locationHaSensors.options.optimalColor`)}),(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray`,htmlFor:`location-sensor-above-color`,children:t(`locationHaSensors.options.aboveColor`)}),(0,G.jsx)(`select`,{id:`location-sensor-below-color`,value:u,onChange:e=>d(e.target.value),disabled:!o,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white disabled:cursor-not-allowed`,children:O6.map(e=>(0,G.jsx)(`option`,{value:e,children:t(`locationHaSensors.options.colors.${e}`)},e))}),(0,G.jsx)(`select`,{id:`location-sensor-optimal-color`,value:f,onChange:e=>p(e.target.value),disabled:!o,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white disabled:cursor-not-allowed`,children:O6.map(e=>(0,G.jsx)(`option`,{value:e,children:t(`locationHaSensors.options.colors.${e}`)},e))}),(0,G.jsx)(`select`,{id:`location-sensor-above-color`,value:c,onChange:e=>l(e.target.value),disabled:!o,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white disabled:cursor-not-allowed`,children:O6.map(e=>(0,G.jsx)(`option`,{value:e,children:t(`locationHaSensors.options.colors.${e}`)},e))})]})]}),(0,G.jsx)(`div`,{className:`pt-4 mt-4 border-t border-bambu-dark-tertiary`,children:(0,G.jsx)(`p`,{className:`text-xs font-medium text-bambu-gray uppercase tracking-wider mb-3`,children:t(`locationHaSensors.options.generalSettings`)})}),(0,G.jsxs)(`div`,{className:`p-3 border border-bambu-dark-tertiary rounded-lg space-y-2`,children:[(0,G.jsx)(`label`,{className:`block text-sm text-white`,htmlFor:`location-sensor-poll-interval`,children:t(`locationHaSensors.options.pollInterval`)}),(0,G.jsx)(`input`,{id:`location-sensor-poll-interval`,type:`number`,min:e8,step:`1`,value:_,onChange:e=>C(Number(e.target.value)),onBlur:()=>C(Math.max(e8,_||t8)),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:t(`locationHaSensors.options.pollIntervalHint`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-2 pt-2`,children:[(0,G.jsxs)(Q,{type:`button`,variant:`secondary`,onClick:()=>h(!0),children:[(0,G.jsx)(Wl,{className:`w-4 h-4`}),t(`locationHaSensors.options.reset`)]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:e,children:t(`common.cancel`)}),(0,G.jsxs)(Q,{type:`submit`,disabled:T.isPending,children:[(0,G.jsx)(ql,{className:`w-4 h-4`}),t(`common.save`)]})]})]})]})]})}),m&&(0,G.jsx)(of,{title:t(`locationHaSensors.options.resetConfirm.title`),message:t(`locationHaSensors.options.resetConfirm.message`),confirmText:t(`locationHaSensors.options.reset`),variant:`danger`,overlayZIndex:`z-[60]`,isLoading:D.isPending,onConfirm:()=>D.mutate(),onCancel:()=>h(!1)})]})}function UWe({provider:e,onEdit:t}){let{t:n}=U(),r=co(),[i,a]=(0,y.useState)(!1),[o,s]=(0,y.useState)(!1),[c,l]=(0,y.useState)(null),{data:u}=K({queryKey:[`printers`],queryFn:Z.getPrinters}),d=u?.find(t=>t.id===e.printer_id),f=q({mutationFn:t=>Z.updateNotificationProvider(e.id,t),onSuccess:()=>{r.invalidateQueries({queryKey:[`notification-providers`]})}}),p=q({mutationFn:()=>Z.deleteNotificationProvider(e.id),onSuccess:()=>{r.invalidateQueries({queryKey:[`notification-providers`]})}}),m=q({mutationFn:()=>Z.testNotificationProvider(e.id),onSuccess:e=>{l(e),r.invalidateQueries({queryKey:[`notification-providers`]})},onError:e=>{l({success:!1,message:e.message})}}),h=e=>e||``;return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(zd,{className:`relative`,children:(0,G.jsxs)(Vd,{className:`p-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-start justify-between ${e.enabled?`mb-3`:`mb-0`}`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`p-2 rounded-lg ${e.enabled?`bg-bambu-green/20`:`bg-bambu-dark`}`,children:(0,G.jsx)(qo,{className:`w-5 h-5 ${e.enabled?`text-bambu-green`:`text-bambu-gray`}`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`font-medium text-white`,children:e.name}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`notifications.providerTypes.${e.provider_type}`,e.provider_type)})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[e.last_success&&(0,G.jsx)(`span`,{className:`text-xs text-status-ok hidden sm:inline`,children:n(`notifications.lastSuccess`,{date:ap(e.last_success)})}),e.last_error&&e.last_error_at&&(!e.last_success||(rp(e.last_error_at)?.getTime()||0)>(rp(e.last_success)?.getTime()||0))&&(0,G.jsx)(`span`,{className:`text-xs text-status-error`,title:e.last_error,children:n(`notifications.error`)}),(0,G.jsx)(fH,{checked:e.enabled,onChange:e=>f.mutate({enabled:e})})]})]}),e.enabled&&(0,G.jsxs)(G.Fragment,{children:[d&&(0,G.jsxs)(`div`,{className:`mb-3 px-2 py-1.5 bg-bambu-dark rounded-lg`,children:[(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[n(`notifications.printer`),` `]}),(0,G.jsx)(`span`,{className:`text-sm text-white`,children:d.name})]}),!d&&!e.printer_id&&(0,G.jsx)(`div`,{className:`mb-3 px-2 py-1.5 bg-bambu-dark rounded-lg`,children:(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:n(`notifications.allPrinters`)})}),(0,G.jsxs)(`div`,{className:`mb-3 flex flex-wrap gap-1`,children:[e.on_print_start&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400 text-xs rounded`,children:n(`notifications.start`)}),e.on_plate_not_empty&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 bg-rose-100 dark:bg-rose-600/20 text-rose-700 dark:text-rose-300 text-xs rounded`,children:n(`notifications.plateCheck`)}),e.on_print_complete&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 bg-bambu-green/20 text-bambu-green text-xs rounded`,children:n(`notifications.complete`)}),e.on_plate_clear_required&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-400 text-xs rounded`,children:n(`notifications.plateClear`)}),e.on_print_failed&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400 text-xs rounded`,children:n(`notifications.failed`)}),e.on_print_stopped&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 bg-orange-100 dark:bg-orange-500/20 text-orange-700 dark:text-orange-400 text-xs rounded`,children:n(`notifications.stopped`)}),e.on_billing_charge_failed&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 bg-red-100 dark:bg-red-600/20 text-red-700 dark:text-red-300 text-xs rounded`,children:n(`notifications.billingChargeFailedLabel`)}),e.on_print_progress&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400 text-xs rounded`,children:n(`notifications.progress`)}),e.on_printer_offline&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 bg-gray-500/20 text-gray-400 text-xs rounded`,children:n(`notifications.offline`)}),e.on_printer_error&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 bg-rose-100 dark:bg-rose-500/20 text-rose-700 dark:text-rose-400 text-xs rounded`,children:n(`notifications.error`)}),e.on_ai_failure_detection&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 bg-fuchsia-100 dark:bg-fuchsia-500/20 text-fuchsia-700 dark:text-fuchsia-300 text-xs rounded`,children:n(`notifications.aiFailureDetection`)}),e.on_ha_sensor_alert&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 bg-indigo-100 dark:bg-indigo-500/20 text-indigo-700 dark:text-indigo-300 text-xs rounded`,children:n(`notifications.haSensorAlert`)}),e.on_location_ha_sensor_alert&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 bg-indigo-100 dark:bg-indigo-500/20 text-indigo-700 dark:text-indigo-300 text-xs rounded`,children:n(`notifications.locationHaSensorAlert`)}),e.on_filament_low&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 bg-cyan-100 dark:bg-cyan-500/20 text-cyan-700 dark:text-cyan-400 text-xs rounded`,children:n(`notifications.lowFilament`)}),e.on_maintenance_due&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 bg-purple-100 dark:bg-purple-500/20 text-purple-700 dark:text-purple-400 text-xs rounded`,children:n(`notifications.maintenance`)}),e.on_ams_humidity_high&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 bg-blue-100 dark:bg-blue-600/20 text-blue-700 dark:text-blue-300 text-xs rounded`,children:n(`notifications.amsHumidity`)}),e.on_ams_temperature_high&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 bg-orange-100 dark:bg-orange-600/20 text-orange-700 dark:text-orange-300 text-xs rounded`,children:n(`notifications.amsTemp`)}),e.on_ams_drying_suspended&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 bg-rose-100 dark:bg-rose-600/20 text-rose-700 dark:text-rose-300 text-xs rounded`,children:n(`notifications.amsDryingSuspended`)}),e.on_ams_ht_humidity_high&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 bg-cyan-100 dark:bg-cyan-600/20 text-cyan-700 dark:text-cyan-300 text-xs rounded`,children:n(`notifications.amsHtHumidity`)}),e.on_ams_ht_temperature_high&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 bg-amber-100 dark:bg-amber-600/20 text-amber-700 dark:text-amber-300 text-xs rounded`,children:n(`notifications.amsHtTemp`)}),e.on_bed_cooled&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 bg-teal-100 dark:bg-teal-500/20 text-teal-700 dark:text-teal-400 text-xs rounded`,children:n(`notifications.bedCooled`)}),e.on_first_layer_complete&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 bg-emerald-100 dark:bg-emerald-600/20 text-emerald-700 dark:text-emerald-300 text-xs rounded`,children:n(`notifications.firstLayer`)}),e.on_print_missing_spool_assignment&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-300 text-xs rounded`,children:n(`notifications.missingSpoolAssignmentLabel`)}),e.on_stock_reorder_alert&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 bg-lime-100 dark:bg-lime-500/20 text-lime-700 dark:text-lime-400 text-xs rounded`,children:n(`notifications.stockReorderAlert`)}),e.on_stock_break_alert&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 bg-red-100 dark:bg-red-600/20 text-red-700 dark:text-red-300 text-xs rounded`,children:n(`notifications.stockBreakAlert`)}),e.quiet_hours_enabled&&(0,G.jsxs)(`span`,{className:`px-2 py-0.5 bg-indigo-100 dark:bg-indigo-500/20 text-indigo-700 dark:text-indigo-400 text-xs rounded flex items-center gap-1`,children:[(0,G.jsx)(_l,{className:`w-3 h-3`}),n(`notifications.quiet`)]}),e.daily_digest_enabled&&(0,G.jsxs)(`span`,{className:`px-2 py-0.5 bg-emerald-100 dark:bg-emerald-500/20 text-emerald-700 dark:text-emerald-400 text-xs rounded flex items-center gap-1`,children:[(0,G.jsx)(as,{className:`w-3 h-3`}),n(`notifications.digest`,{time:e.daily_digest_time})]})]}),(0,G.jsx)(`div`,{className:`mb-3`,children:(0,G.jsxs)(Q,{size:`sm`,variant:`secondary`,disabled:m.isPending,onClick:()=>{l(null),m.mutate()},className:`w-full`,children:[m.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)($l,{className:`w-4 h-4`}),n(`notifications.sendTestNotification`)]})}),c&&(0,G.jsxs)(`div`,{className:`mb-3 p-2 rounded-lg flex items-center gap-2 text-sm ${c.success?`bg-bambu-green/20 text-bambu-green`:`bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400`}`,children:[c.success?(0,G.jsx)(xs,{className:`w-4 h-4`}):(0,G.jsx)(Ds,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{children:c.message})]})]}),(0,G.jsxs)(`button`,{onClick:()=>s(!o),className:`w-full flex items-center justify-between py-2 text-sm text-bambu-gray hover:text-white transition-colors ${e.enabled?`border-t border-bambu-dark-tertiary`:`mt-2 border-t border-bambu-dark-tertiary`}`,children:[(0,G.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(nu,{className:`w-4 h-4`}),n(`notifications.eventSettings`)]}),o?(0,G.jsx)(gs,{className:`w-4 h-4`}):(0,G.jsx)(ps,{className:`w-4 h-4`})]}),o&&(0,G.jsxs)(`div`,{className:`pt-3 border-t border-bambu-dark-tertiary space-y-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.enabled`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.sendFromProvider`)})]}),(0,G.jsx)(fH,{checked:e.enabled,onChange:e=>f.mutate({enabled:e})})]}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase tracking-wide`,children:n(`notifications.printEvents`)}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.printStarted`)}),(0,G.jsx)(fH,{checked:e.on_print_start,onChange:e=>f.mutate({on_print_start:e})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.plateNotEmpty`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.plateNotEmptyDescription`)})]}),(0,G.jsx)(fH,{checked:e.on_plate_not_empty??!0,onChange:e=>f.mutate({on_plate_not_empty:e})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.printCompleted`)}),(0,G.jsx)(fH,{checked:e.on_print_complete,onChange:e=>f.mutate({on_print_complete:e})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.plateClearRequired`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.plateClearRequiredDescription`)})]}),(0,G.jsx)(fH,{checked:e.on_plate_clear_required??!1,onChange:e=>f.mutate({on_plate_clear_required:e})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.bedCooledLabel`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.bedCooledDescription`)})]}),(0,G.jsx)(fH,{checked:e.on_bed_cooled??!1,onChange:e=>f.mutate({on_bed_cooled:e})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.firstLayerCompleteLabel`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.firstLayerCompleteDescription`)})]}),(0,G.jsx)(fH,{checked:e.on_first_layer_complete??!1,onChange:e=>f.mutate({on_first_layer_complete:e})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.missingSpoolAssignmentLabel`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.missingSpoolAssignmentDescription`)})]}),(0,G.jsx)(fH,{checked:e.on_print_missing_spool_assignment??!1,onChange:e=>f.mutate({on_print_missing_spool_assignment:e})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.printFailed`)}),(0,G.jsx)(fH,{checked:e.on_print_failed,onChange:e=>f.mutate({on_print_failed:e})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.printStopped`)}),(0,G.jsx)(fH,{checked:e.on_print_stopped,onChange:e=>f.mutate({on_print_stopped:e})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.billingChargeFailedLabel`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.billingChargeFailedDescription`)})]}),(0,G.jsx)(fH,{checked:e.on_billing_charge_failed??!0,onChange:e=>f.mutate({on_billing_charge_failed:e})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.progressMilestones`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.progressMilestonesDescription`)})]}),(0,G.jsx)(fH,{checked:e.on_print_progress,onChange:e=>f.mutate({on_print_progress:e})})]})]}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase tracking-wide`,children:n(`notifications.printerStatus`)}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.printerOffline`)}),(0,G.jsx)(fH,{checked:e.on_printer_offline,onChange:e=>f.mutate({on_printer_offline:e})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.printerError`)}),(0,G.jsx)(fH,{checked:e.on_printer_error,onChange:e=>f.mutate({on_printer_error:e})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.aiFailureDetection`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.aiFailureDetectionDescription`)})]}),(0,G.jsx)(fH,{checked:e.on_ai_failure_detection??!1,onChange:e=>f.mutate({on_ai_failure_detection:e})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.haSensorAlert`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.haSensorAlertDescription`)})]}),(0,G.jsx)(fH,{checked:e.on_ha_sensor_alert??!1,onChange:e=>f.mutate({on_ha_sensor_alert:e})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.locationHaSensorAlert`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.locationHaSensorAlertDescription`)})]}),(0,G.jsx)(fH,{checked:e.on_location_ha_sensor_alert??!1,onChange:e=>f.mutate({on_location_ha_sensor_alert:e})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.lowFilamentLabel`)}),(0,G.jsx)(fH,{checked:e.on_filament_low,onChange:e=>f.mutate({on_filament_low:e})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.maintenanceDue`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.maintenanceDueDescription`)})]}),(0,G.jsx)(fH,{checked:e.on_maintenance_due??!1,onChange:e=>f.mutate({on_maintenance_due:e})})]})]}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase tracking-wide`,children:n(`notifications.amsAlarms`)}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.amsHumidityHigh`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.amsHumidityHighDescription`)})]}),(0,G.jsx)(fH,{checked:e.on_ams_humidity_high??!1,onChange:e=>f.mutate({on_ams_humidity_high:e})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.amsTemperatureHigh`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.amsTemperatureHighDescription`)})]}),(0,G.jsx)(fH,{checked:e.on_ams_temperature_high??!1,onChange:e=>f.mutate({on_ams_temperature_high:e})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.amsDryingSuspendedTitle`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.amsDryingSuspendedDescription`)})]}),(0,G.jsx)(fH,{checked:e.on_ams_drying_suspended??!1,onChange:e=>f.mutate({on_ams_drying_suspended:e})})]})]}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase tracking-wide`,children:n(`notifications.amsHtAlarms`)}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.amsHtHumidityHigh`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.amsHtHumidityHighDescription`)})]}),(0,G.jsx)(fH,{checked:e.on_ams_ht_humidity_high??!1,onChange:e=>f.mutate({on_ams_ht_humidity_high:e})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.amsHtTemperatureHigh`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.amsHtTemperatureHighDescription`)})]}),(0,G.jsx)(fH,{checked:e.on_ams_ht_temperature_high??!1,onChange:e=>f.mutate({on_ams_ht_temperature_high:e})})]})]}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase tracking-wide`,children:n(`notifications.inventoryAlerts`)}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.stockReorderAlert`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.stockReorderAlertDescription`)})]}),(0,G.jsx)(fH,{checked:e.on_stock_reorder_alert??!1,onChange:e=>f.mutate({on_stock_reorder_alert:e})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.stockBreakAlert`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.stockBreakAlertDescription`)})]}),(0,G.jsx)(fH,{checked:e.on_stock_break_alert??!1,onChange:e=>f.mutate({on_stock_break_alert:e})})]})]}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase tracking-wide`,children:n(`notifications.printQueue`)}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.jobAdded`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.jobAddedDescription`)})]}),(0,G.jsx)(fH,{checked:e.on_queue_job_added??!1,onChange:e=>f.mutate({on_queue_job_added:e})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.jobAssigned`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.jobAssignedDescription`)})]}),(0,G.jsx)(fH,{checked:e.on_queue_job_assigned??!1,onChange:e=>f.mutate({on_queue_job_assigned:e})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.jobStarted`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.jobStartedDescription`)})]}),(0,G.jsx)(fH,{checked:e.on_queue_job_started??!1,onChange:e=>f.mutate({on_queue_job_started:e})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.jobWaiting`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.jobWaitingDescription`)})]}),(0,G.jsx)(fH,{checked:e.on_queue_job_waiting??!0,onChange:e=>f.mutate({on_queue_job_waiting:e})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.jobSkipped`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.jobSkippedDescription`)})]}),(0,G.jsx)(fH,{checked:e.on_queue_job_skipped??!0,onChange:e=>f.mutate({on_queue_job_skipped:e})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.jobFailed`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.jobFailedDescription`)})]}),(0,G.jsx)(fH,{checked:e.on_queue_job_failed??!0,onChange:e=>f.mutate({on_queue_job_failed:e})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.queueComplete`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.queueCompleteDescription`)})]}),(0,G.jsx)(fH,{checked:e.on_queue_completed??!1,onChange:e=>f.mutate({on_queue_completed:e})})]})]}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(_l,{className:`w-4 h-4 text-purple-600 dark:text-purple-400`}),(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.quietHours`)})]}),(0,G.jsx)(fH,{checked:e.quiet_hours_enabled,onChange:e=>f.mutate({quiet_hours_enabled:e})})]}),e.quiet_hours_enabled&&(0,G.jsxs)(`div`,{className:`pl-4 border-l-2 border-bambu-dark-tertiary space-y-2`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.noNotificationsDuring`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(js,{className:`w-4 h-4 text-bambu-gray`}),(0,G.jsxs)(`span`,{className:`text-sm text-white`,children:[h(e.quiet_hours_start)||`22:00`,` - `,h(e.quiet_hours_end)||`07:00`]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.editProviderToChangeQuietHours`)})]})]}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(as,{className:`w-4 h-4 text-emerald-600 dark:text-emerald-400`}),(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.dailyDigest`)})]}),(0,G.jsx)(fH,{checked:e.daily_digest_enabled,onChange:e=>f.mutate({daily_digest_enabled:e})})]}),e.daily_digest_enabled&&(0,G.jsxs)(`div`,{className:`pl-4 border-l-2 border-bambu-dark-tertiary space-y-2`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.batchNotifications`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(js,{className:`w-4 h-4 text-bambu-gray`}),(0,G.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.sendAt`,{time:h(e.daily_digest_time)||`08:00`})})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.editProviderToChangeDigestTime`)})]})]}),(0,G.jsxs)(`div`,{className:`flex gap-2 pt-2`,children:[(0,G.jsxs)(Q,{size:`sm`,variant:`secondary`,onClick:()=>t(e),className:`flex-1`,children:[(0,G.jsx)(kl,{className:`w-4 h-4`}),n(`notifications.edit`)]}),(0,G.jsx)(Q,{size:`sm`,variant:`secondary`,onClick:()=>a(!0),className:`text-red-700 dark:text-red-400 hover:text-red-800 dark:hover:text-red-300`,children:(0,G.jsx)(Pu,{className:`w-4 h-4`})})]})]})]})}),i&&(0,G.jsx)(of,{title:n(`notifications.deleteProvider`),message:n(`notifications.deleteConfirm`,{name:e.name}),confirmText:n(`notifications.delete`),variant:`danger`,onConfirm:()=>{p.mutate(),a(!1)},onCancel:()=>a(!1)})]})}var WWe=[`email`,`telegram`,`discord`,`ntfy`,`pushover`,`bark`,`callmebot`,`webhook`,`homeassistant`];function GWe({provider:e,onClose:t}){let{t:n}=U(),r=co(),i=!!e,[a,o]=(0,y.useState)(e?.name||``),[s,c]=(0,y.useState)(e?.provider_type||`email`),[l,u]=(0,y.useState)(e?.printer_id||null),[d,f]=(0,y.useState)(e?.quiet_hours_enabled||!1),[p,m]=(0,y.useState)(e?.quiet_hours_start||`22:00`),[h,g]=(0,y.useState)(e?.quiet_hours_end||`07:00`),[_,v]=(0,y.useState)(e?.daily_digest_enabled||!1),[b,x]=(0,y.useState)(e?.daily_digest_time||`08:00`),[S,C]=(0,y.useState)(e?.on_print_start??!1),[w,T]=(0,y.useState)(e?.on_print_complete??!0),[E,D]=(0,y.useState)(e?.on_print_failed??!0),[O,k]=(0,y.useState)(e?.on_print_stopped??!0),[A,j]=(0,y.useState)(e?.on_print_progress??!1),[M,N]=(0,y.useState)(e?.on_billing_charge_failed??!0),[P,F]=(0,y.useState)(e?.on_printer_offline??!1),[I,L]=(0,y.useState)(e?.on_printer_error??!1),[R,z]=(0,y.useState)(e?.on_ai_failure_detection??!1),[B,V]=(0,y.useState)(e?.on_filament_low??!1),[ee,te]=(0,y.useState)(e?.on_maintenance_due??!1),[ne,re]=(0,y.useState)(e?.on_stock_reorder_alert??!1),[ie,ae]=(0,y.useState)(e?.on_stock_break_alert??!1),[oe,se]=(0,y.useState)(e?.on_plate_clear_required??!1),[H,ce]=(0,y.useState)(e?.on_bed_cooled??!1),[le,ue]=(0,y.useState)(e?.on_ha_sensor_alert??!1),[de,fe]=(0,y.useState)(e?.on_location_ha_sensor_alert??!1),[pe,me]=(0,y.useState)(e?.on_first_layer_complete??!1),[he,ge]=(0,y.useState)(e?.config?Object.fromEntries(Object.entries(e.config).filter(([e])=>e!==`event_priorities`).map(([e,t])=>[e,String(t)])):{}),[_e,ve]=(0,y.useState)((()=>{let t=e?.config?.event_priorities;if(!t||typeof t!=`object`)return{};let n={};for(let[e,r]of Object.entries(t)){let t=Number(r);Number.isInteger(t)&&t>=1&&t<=5&&(n[e]=t)}return n})()),[ye,be]=(0,y.useState)(null),[xe,Se]=(0,y.useState)(null),{data:Ce}=K({queryKey:[`printers`],queryFn:Z.getPrinters});(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]);let we=q({mutationFn:()=>Z.testNotificationConfig({provider_type:s,config:he}),onSuccess:e=>{be(e),Se(null)},onError:e=>{be({success:!1,message:e.message})}}),Te=q({mutationFn:e=>Z.createNotificationProvider(e),onSuccess:()=>{r.invalidateQueries({queryKey:[`notification-providers`]}),t()},onError:e=>{Se(e.message)}}),Ee=q({mutationFn:t=>Z.updateNotificationProvider(e.id,t),onSuccess:()=>{r.invalidateQueries({queryKey:[`notification-providers`]}),t()},onError:e=>{Se(e.message)}}),De=e=>{if(e.preventDefault(),Se(null),!a.trim()){Se(n(`notifications.nameRequired`));return}let t=Ae(s);for(let e of t)if(!he[e.key]?.trim()){Se(n(`notifications.fieldRequired`,{field:e.label}));return}if(s===`homeassistant`&&he.data?.trim()){let e;try{e=JSON.parse(he.data)}catch{Se(n(`notifications.haDataInvalid`));return}if(typeof e!=`object`||!e||Array.isArray(e)){Se(n(`notifications.haDataInvalid`));return}}if(s===`telegram`&&he.message_thread_id?.trim()&&!/^\d+$/.test(he.message_thread_id.trim())){Se(n(`notifications.telegramThreadIdInvalid`));return}let r=s===`ntfy`&&Object.keys(_e).length>0?{...he,event_priorities:_e}:he,o={name:a.trim(),provider_type:s,config:r,printer_id:l,quiet_hours_enabled:d,quiet_hours_start:d?p:null,quiet_hours_end:d?h:null,daily_digest_enabled:_,daily_digest_time:_?b:null,on_print_start:S,on_print_complete:w,on_print_failed:E,on_print_stopped:O,on_print_progress:A,on_billing_charge_failed:M,on_printer_offline:P,on_printer_error:I,on_ai_failure_detection:R,on_filament_low:B,on_maintenance_due:ee,on_stock_reorder_alert:ne,on_stock_break_alert:ie,on_plate_clear_required:oe,on_bed_cooled:H,on_ha_sensor_alert:le,on_location_ha_sensor_alert:de,on_first_layer_complete:pe};i?Ee.mutate(o):Te.mutate(o)},Oe=Te.isPending||Ee.isPending,ke=e=>{switch(e){case`callmebot`:return[{key:`phone`,label:`Phone Number`,placeholder:`+1234567890`,type:`text`,required:!0},{key:`apikey`,label:`API Key`,placeholder:`Your CallMeBot API key`,type:`text`,required:!0}];case`ntfy`:return[{key:`server`,label:`Server URL`,placeholder:`https://ntfy.sh`,type:`text`,required:!1},{key:`topic`,label:`Topic`,placeholder:`my-bambuddy`,type:`text`,required:!0},{key:`auth_token`,label:`Auth Token`,placeholder:`Optional authentication`,type:`password`,required:!1}];case`pushover`:return[{key:`user_key`,label:`User Key`,placeholder:`Your Pushover user key`,type:`text`,required:!0},{key:`app_token`,label:`App Token`,placeholder:`Your Pushover app token`,type:`text`,required:!0},{key:`priority`,label:`Priority`,placeholder:`0 (normal)`,type:`number`,required:!1},{key:`retry`,label:n(`notifications.pushoverRetry`),placeholder:`60`,type:`number`,required:!1,showIf:e=>e.priority===`2`},{key:`expire`,label:n(`notifications.pushoverExpire`),placeholder:`3600`,type:`number`,required:!1,showIf:e=>e.priority===`2`}];case`telegram`:return[{key:`bot_token`,label:`Bot Token`,placeholder:`Bot token from @BotFather`,type:`password`,required:!0},{key:`chat_id`,label:`Chat ID`,placeholder:`Your chat or group ID`,type:`text`,required:!0},{key:`message_thread_id`,label:n(`notifications.telegramThreadId`),placeholder:`123`,type:`number`,required:!1,help:n(`notifications.telegramThreadIdHelp`)}];case`email`:return[{key:`smtp_server`,label:`SMTP Server`,placeholder:`smtp.gmail.com`,type:`text`,required:!0},{key:`smtp_port`,label:`SMTP Port`,placeholder:`587`,type:`number`,required:!1},{key:`security`,label:`Security`,type:`select`,required:!1,options:[{value:`starttls`,label:`STARTTLS (Port 587)`},{value:`ssl`,label:`SSL/TLS (Port 465)`},{value:`none`,label:`None (Port 25)`}]},{key:`auth_enabled`,label:`Authentication`,type:`select`,required:!1,options:[{value:`true`,label:`Enabled`},{value:`false`,label:`Disabled`}]},{key:`username`,label:`Username`,placeholder:`your@email.com`,type:`text`,required:!1},{key:`password`,label:`Password`,placeholder:`App password`,type:`password`,required:!1},{key:`from_email`,label:`From Email`,placeholder:`your@email.com`,type:`text`,required:!0},{key:`to_email`,label:`To Email`,placeholder:`recipient@email.com`,type:`text`,required:!0}];case`discord`:return[{key:`webhook_url`,label:`Webhook URL`,placeholder:`https://discord.com/api/webhooks/...`,type:`text`,required:!0}];case`webhook`:return[{key:`webhook_url`,label:`Webhook URL`,placeholder:`https://example.com/webhook`,type:`text`,required:!0},{key:`payload_format`,label:`Payload Format`,type:`select`,required:!1,options:[{value:`generic`,label:`Generic JSON`},{value:`slack`,label:`Slack / Mattermost`}]},{key:`auth_header`,label:`Authorization`,placeholder:`Bearer token (optional)`,type:`password`,required:!1},{key:`field_title`,label:`Title Field Name`,placeholder:`title`,type:`text`,required:!1,showIf:e=>e.payload_format!==`slack`},{key:`field_message`,label:`Message Field Name`,placeholder:`message`,type:`text`,required:!1,showIf:e=>e.payload_format!==`slack`}];case`homeassistant`:return[{key:`service`,label:`Home Assistant Service`,placeholder:`notify.mobile_app_myphone`,type:`text`,required:!1},{key:`data`,label:`Data (JSON, optional)`,placeholder:`{"priority": "high", "ttl": 0, "channel": "3D Printing"}`,type:`textarea`,required:!1}];case`bark`:return[{key:`device_key`,label:`Device Key`,placeholder:`Your Bark device key`,type:`text`,required:!0},{key:`server`,label:`Server URL`,placeholder:`https://api.day.app`,type:`text`,required:!1},{key:`group`,label:`Group`,placeholder:`Bambuddy`,type:`text`,required:!1},{key:`sound`,label:`Sound`,placeholder:`minuet`,type:`text`,required:!1},{key:`level`,label:`Interruption Level`,type:`select`,required:!1,options:[{value:``,label:`Default`},{value:`active`,label:`Active`},{value:`timeSensitive`,label:`Time Sensitive`},{value:`critical`,label:`Critical (bypasses Silent/Focus)`},{value:`passive`,label:`Passive (no sound)`}]}];default:return[]}},Ae=e=>ke(e).filter(e=>e.required),je=ke(s);return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4 overflow-y-auto`,onClick:t,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-lg my-8 max-h-[90vh] overflow-y-auto`,onClick:e=>e.stopPropagation(),children:[(0,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:n(i?`notifications.editTitle`:`notifications.addTitle`)}),(0,G.jsx)(`button`,{onClick:t,className:`text-bambu-gray hover:text-white transition-colors`,children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]}),(0,G.jsxs)(`form`,{onSubmit:De,className:`p-6 space-y-4`,children:[xe&&(0,G.jsx)(`div`,{className:`p-3 bg-red-100 dark:bg-red-500/20 border border-red-300 dark:border-red-500/50 rounded-lg text-sm text-red-700 dark:text-red-400`,children:xe}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`notifications.nameLabel`)}),(0,G.jsx)(`input`,{type:`text`,value:a,onChange:e=>o(e.target.value),placeholder:n(`notifications.namePlaceholder`),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`notifications.providerTypeLabel`)}),(0,G.jsx)(`select`,{value:s,onChange:e=>{c(e.target.value),ge({}),be(null)},disabled:i,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none disabled:opacity-50`,children:WWe.map(e=>(0,G.jsx)(`option`,{value:e,children:n(`notifications.providerTypes.${e}`,e)},e))}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(`notifications.providerDescriptions.${s}`,``)})]}),(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`notifications.configuration`)}),je.filter(e=>!(`showIf`in e)||e.showIf?.(he)!==!1).map(e=>(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[e.label,` `,e.required&&`*`]}),e.type===`select`&&`options`in e&&e.options?(0,G.jsx)(`select`,{value:he[e.key]||e.options[0]?.value||``,onChange:t=>{ge({...he,[e.key]:t.target.value}),be(null)},className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:e.options.map(e=>(0,G.jsx)(`option`,{value:e.value,children:e.label},e.value))}):e.type===`textarea`?(0,G.jsx)(`textarea`,{value:he[e.key]||``,onChange:t=>{ge({...he,[e.key]:t.target.value}),be(null)},placeholder:e.placeholder,rows:3,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none font-mono text-sm`}):(0,G.jsx)(`input`,{type:e.type,value:he[e.key]||``,onChange:t=>{ge({...he,[e.key]:t.target.value}),be(null)},placeholder:e.placeholder,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),`help`in e&&e.help&&(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e.help})]},e.key))]}),(0,G.jsx)(`div`,{className:`flex gap-2`,children:(0,G.jsxs)(Q,{type:`button`,variant:`secondary`,onClick:()=>{be(null),we.mutate()},disabled:we.isPending||Ae(s).length>0&&!he[Ae(s)[0]?.key],className:`flex-1`,children:[we.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)($l,{className:`w-4 h-4`}),n(`notifications.testConfiguration`)]})}),ye&&(0,G.jsx)(`div`,{className:`p-3 rounded-lg flex items-center gap-2 ${ye.success?`bg-bambu-green/20 border border-bambu-green/50 text-bambu-green`:`bg-red-100 dark:bg-red-500/20 border border-red-300 dark:border-red-500/50 text-red-700 dark:text-red-400`}`,children:ye.success?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(xs,{className:`w-5 h-5`}),(0,G.jsx)(`span`,{children:ye.message})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Ds,{className:`w-5 h-5`}),(0,G.jsx)(`span`,{children:ye.message})]})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`notifications.printerFilter`)}),(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:n(`notifications.allPrinters`)}),Ce?.map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(`notifications.onlyFromPrinter`)})]}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`label`,{className:`text-sm text-white`,children:n(`notifications.quietHoursDnd`)}),(0,G.jsx)(fH,{checked:d,onChange:f})]}),d&&(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:n(`notifications.quietStart`)}),(0,G.jsx)(`input`,{type:`time`,value:p,onChange:e=>m(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:n(`notifications.quietEnd`)}),(0,G.jsx)(`input`,{type:`time`,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`})]})]})]}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`text-sm text-white`,children:n(`notifications.dailyDigestLabel`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.batchNotifications`)})]}),(0,G.jsx)(fH,{checked:_,onChange:v})]}),_&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:n(`notifications.sendDigestAt`)}),(0,G.jsx)(`input`,{type:`time`,value:b,onChange:e=>x(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(`notifications.digestCollected`)})]})]}),(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`notifications.notificationEvents`)}),(0,G.jsxs)(`div`,{className:`space-y-2 p-3 bg-bambu-dark rounded-lg`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase tracking-wide mb-2`,children:n(`notifications.printEvents`)}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.start`)}),(0,G.jsx)(fH,{checked:S,onChange:C})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.complete`)}),(0,G.jsx)(fH,{checked:w,onChange:T})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.failed`)}),(0,G.jsx)(fH,{checked:E,onChange:D})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.stopped`)}),(0,G.jsx)(fH,{checked:O,onChange:k})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between col-span-2`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.progress`)}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray ml-1`,children:n(`notifications.progressPercent`)})]}),(0,G.jsx)(fH,{checked:A,onChange:j})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between col-span-2`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.billingChargeFailedLabel`)}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray ml-1`,children:n(`notifications.billingChargeFailedDescription`)})]}),(0,G.jsx)(fH,{checked:M,onChange:N})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between col-span-2`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.plateClearRequired`)}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray ml-1`,children:n(`notifications.plateClearRequiredDescription`)})]}),(0,G.jsx)(fH,{checked:oe,onChange:se})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between col-span-2`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.bedCooled`)}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray ml-1`,children:n(`notifications.bedCooledAfterPrint`)})]}),(0,G.jsx)(fH,{checked:H,onChange:ce})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between col-span-2`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.firstLayerCompleteLabel`)}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray ml-1`,children:n(`notifications.firstLayerCompleteDescription`)})]}),(0,G.jsx)(fH,{checked:pe,onChange:me})]})]})]}),(0,G.jsxs)(`div`,{className:`space-y-2 p-3 bg-bambu-dark rounded-lg`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase tracking-wide mb-2`,children:n(`notifications.printerStatus`)}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.offline`)}),(0,G.jsx)(fH,{checked:P,onChange:F})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between col-span-2`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.haSensorAlert`)}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray ml-1`,children:n(`notifications.haSensorAlertDescription`)})]}),(0,G.jsx)(fH,{checked:le,onChange:ue})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between col-span-2`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.locationHaSensorAlert`)}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray ml-1`,children:n(`notifications.locationHaSensorAlertDescription`)})]}),(0,G.jsx)(fH,{checked:de,onChange:fe})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.error`)}),(0,G.jsx)(fH,{checked:I,onChange:L})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.aiFailureDetection`)}),(0,G.jsx)(fH,{checked:R,onChange:z})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.lowFilament`)}),(0,G.jsx)(fH,{checked:B,onChange:V})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.maintenance`)}),(0,G.jsx)(fH,{checked:ee,onChange:te})]})]})]}),(0,G.jsxs)(`div`,{className:`space-y-2 p-3 bg-bambu-dark rounded-lg`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase tracking-wide mb-2`,children:n(`notifications.inventoryAlerts`)}),(0,G.jsxs)(`div`,{className:`grid grid-cols-1 gap-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.stockReorderAlert`)}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray ml-1`,children:n(`notifications.stockReorderAlertDescription`)})]}),(0,G.jsx)(fH,{checked:ne,onChange:re})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.stockBreakAlert`)}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray ml-1`,children:n(`notifications.stockBreakAlertDescription`)})]}),(0,G.jsx)(fH,{checked:ie,onChange:ae})]})]})]}),s===`ntfy`&&(()=>{let e=[];return S&&e.push({key:`on_print_start`,label:n(`notifications.start`)}),w&&e.push({key:`on_print_complete`,label:n(`notifications.complete`)}),E&&e.push({key:`on_print_failed`,label:n(`notifications.failed`)}),O&&e.push({key:`on_print_stopped`,label:n(`notifications.stopped`)}),A&&e.push({key:`on_print_progress`,label:n(`notifications.progress`)}),M&&e.push({key:`on_billing_charge_failed`,label:n(`notifications.billingChargeFailedLabel`)}),oe&&e.push({key:`on_plate_clear_required`,label:n(`notifications.plateClearRequired`)}),H&&e.push({key:`on_bed_cooled`,label:n(`notifications.bedCooled`)}),pe&&e.push({key:`on_first_layer_complete`,label:n(`notifications.firstLayerCompleteLabel`)}),P&&e.push({key:`on_printer_offline`,label:n(`notifications.offline`)}),I&&e.push({key:`on_printer_error`,label:n(`notifications.error`)}),le&&e.push({key:`on_ha_sensor_alert`,label:n(`notifications.haSensorAlert`)}),de&&e.push({key:`on_location_ha_sensor_alert`,label:n(`notifications.locationHaSensorAlert`)}),R&&e.push({key:`on_ai_failure_detection`,label:n(`notifications.aiFailureDetection`)}),B&&e.push({key:`on_filament_low`,label:n(`notifications.lowFilament`)}),ee&&e.push({key:`on_maintenance_due`,label:n(`notifications.maintenance`)}),ne&&e.push({key:`on_stock_reorder_alert`,label:n(`notifications.stockReorderAlert`)}),ie&&e.push({key:`on_stock_break_alert`,label:n(`notifications.stockBreakAlert`)}),e.length===0?null:(0,G.jsxs)(`div`,{className:`space-y-2 p-3 bg-bambu-dark rounded-lg`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase tracking-wide mb-1`,children:n(`notifications.eventPriority.sectionTitle`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:n(`notifications.eventPriority.helpNtfy`)}),(0,G.jsx)(`div`,{className:`space-y-2`,children:e.map(e=>(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,G.jsx)(`span`,{className:`text-sm text-white`,children:e.label}),(0,G.jsxs)(`select`,{value:_e[e.key]??3,onChange:t=>{let n=Number(t.target.value);ve(t=>({...t,[e.key]:n}))},className:`px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-sm text-white focus:border-bambu-green focus:outline-none`,children:[(0,G.jsx)(`option`,{value:1,children:n(`notifications.eventPriority.min`)}),(0,G.jsx)(`option`,{value:2,children:n(`notifications.eventPriority.low`)}),(0,G.jsx)(`option`,{value:3,children:n(`notifications.eventPriority.default`)}),(0,G.jsx)(`option`,{value:4,children:n(`notifications.eventPriority.high`)}),(0,G.jsx)(`option`,{value:5,children:n(`notifications.eventPriority.urgent`)})]})]},e.key))})]})})()]}),(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:n(`notifications.cancel`)}),(0,G.jsxs)(Q,{type:`submit`,disabled:Oe,className:`flex-1`,children:[Oe?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(ql,{className:`w-4 h-4`}),n(i?`notifications.save`:`notifications.add`)]})]})]})]})})}function KWe({template:e,onClose:t}){let{t:n}=U(),r=co(),i=(0,y.useRef)(null),[a,o]=(0,y.useState)(e.title_template),[s,c]=(0,y.useState)(e.body_template),[l,u]=(0,y.useState)(null),[d,f]=(0,y.useState)(!0),{data:p}=K({queryKey:[`template-variables`],queryFn:Z.getTemplateVariables}),m=p?.find(t=>t.event_type===e.event_type),{data:h,isLoading:g}=K({queryKey:[`template-preview`,e.event_type,a,s],queryFn:()=>Z.previewTemplate({event_type:e.event_type,title_template:a,body_template:s}),enabled:d&&a.length>0&&s.length>0});(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]);let _=q({mutationFn:t=>Z.updateNotificationTemplate(e.id,t),onSuccess:()=>{r.invalidateQueries({queryKey:[`notification-templates`]}),t()},onError:e=>{u(e.message)}}),v=q({mutationFn:()=>Z.resetNotificationTemplate(e.id),onSuccess:e=>{o(e.title_template),c(e.body_template),r.invalidateQueries({queryKey:[`notification-templates`]})},onError:e=>{u(e.message)}}),b=e=>{if(e.preventDefault(),u(null),!a.trim()){u(n(`notifications.titleRequired`));return}if(!s.trim()){u(n(`notifications.bodyRequired`));return}_.mutate({title_template:a,body_template:s})},x=e=>{let t=i.current;if(!t)return;let n=t.selectionStart,r=t.selectionEnd,a=s,o=a.substring(0,n),l=a.substring(r);c(o+`{${e}}`+l),setTimeout(()=>{t.focus();let r=n+e.length+2;t.setSelectionRange(r,r)},0)},S=a!==e.title_template||s!==e.body_template;return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/80 flex items-center justify-center z-50 p-4`,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg w-full max-w-2xl max-h-[90vh] flex flex-col`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary shrink-0`,children:[(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:n(`notifications.editTemplate`,{name:e.name})}),(0,G.jsx)(`button`,{onClick:t,className:`p-1 hover:bg-bambu-dark-tertiary rounded transition-colors`,children:(0,G.jsx)(nd,{className:`w-5 h-5 text-bambu-gray`})})]}),(0,G.jsxs)(`form`,{onSubmit:b,className:`flex-1 overflow-y-auto p-4 space-y-4`,children:[l&&(0,G.jsx)(`div`,{className:`p-3 bg-red-100 dark:bg-red-500/20 border border-red-300 dark:border-red-500/50 rounded text-red-700 dark:text-red-400 text-sm`,children:l}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:n(`notifications.titleLabel`)}),(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 text-white focus:outline-none focus:ring-1 focus:ring-bambu-green`,placeholder:n(`notifications.titlePlaceholder`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:n(`notifications.bodyLabel`)}),(0,G.jsx)(`textarea`,{ref:i,value:s,onChange:e=>c(e.target.value),rows:4,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white focus:outline-none focus:ring-1 focus:ring-bambu-green font-mono text-sm resize-none`,placeholder:n(`notifications.bodyPlaceholder`)})]}),m&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-2`,children:n(`notifications.availableVariables`)}),(0,G.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:m.variables.map(e=>(0,G.jsxs)(`button`,{type:`button`,onClick:()=>x(e),className:`inline-flex items-center gap-1 px-2 py-1 bg-bambu-dark hover:bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-xs text-bambu-gray hover:text-white transition-colors`,children:[(0,G.jsx)(Fl,{className:`w-3 h-3`}),e]},e))}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray/60 mt-1`,children:n(`notifications.clickToInsert`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,G.jsxs)(`label`,{className:`text-sm font-medium text-bambu-gray flex items-center gap-2`,children:[(0,G.jsx)(ac,{className:`w-4 h-4`}),n(`notifications.livePreview`)]}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>f(!d),className:`text-xs text-bambu-green hover:text-bambu-green-light`,children:n(d?`notifications.hide`:`notifications.show`)})]}),d&&(0,G.jsx)(`div`,{className:`bg-bambu-dark border border-bambu-dark-tertiary rounded p-3 space-y-2`,children:g?(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(`notifications.loadingPreview`)]}):h?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:n(`notifications.titlePreview`)}),(0,G.jsx)(`div`,{className:`text-white font-medium`,children:h.title})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:n(`notifications.bodyPreview`)}),(0,G.jsx)(`div`,{className:`text-white whitespace-pre-wrap text-sm`,children:h.body})]})]}):(0,G.jsx)(`div`,{className:`text-bambu-gray text-sm`,children:n(`notifications.enterTemplateContent`)})})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-t border-bambu-dark-tertiary shrink-0`,children:[(0,G.jsxs)(Q,{type:`button`,variant:`ghost`,onClick:()=>v.mutate(),disabled:v.isPending,className:`text-orange-600 dark:text-orange-400 hover:text-orange-700 dark:hover:text-orange-300`,children:[v.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin mr-2`}):(0,G.jsx)(Wl,{className:`w-4 h-4 mr-2`}),n(`notifications.resetToDefault`)]}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:t,children:n(`notifications.cancel`)}),(0,G.jsxs)(Q,{onClick:b,disabled:_.isPending||!S,children:[_.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin mr-2`}):(0,G.jsx)(ql,{className:`w-4 h-4 mr-2`}),n(`notifications.save`)]})]})]})]})})}var qWe={print_start:`text-blue-700 dark:text-blue-400`,print_complete:`text-bambu-green`,print_failed:`text-red-700 dark:text-red-400`,print_stopped:`text-orange-700 dark:text-orange-400`,print_progress:`text-yellow-700 dark:text-yellow-400`,printer_offline:`text-gray-400`,printer_error:`text-rose-700 dark:text-rose-400`,filament_low:`text-cyan-700 dark:text-cyan-400`,maintenance_due:`text-purple-700 dark:text-purple-400`,test:`text-bambu-gray`};function JWe({onClose:e}){let{t}=U(),n=co(),{showToast:r}=qd(),[i,a]=(0,y.useState)(7),[o,s]=(0,y.useState)(null),[c,l]=(0,y.useState)(!1),{data:u}=K({queryKey:[`settings`],queryFn:Z.getSettings}),d=u?.time_format||`system`,{data:f,isLoading:p,refetch:m,isRefetching:h}=K({queryKey:[`notification-logs`,i,c],queryFn:()=>Z.getNotificationLogs({days:i,limit:100,success:c?!1:void 0})}),{data:g}=K({queryKey:[`notification-log-stats`,i],queryFn:()=>Z.getNotificationLogStats(i)}),_=q({mutationFn:()=>Z.clearNotificationLogs(30),onSuccess:e=>{r(e.message,`success`),n.invalidateQueries({queryKey:[`notification-logs`]}),n.invalidateQueries({queryKey:[`notification-log-stats`]})},onError:e=>{r(`Failed to clear logs: ${e.message}`,`error`)}}),v=e=>{let n=rp(e);if(!n)return``;let r=new Date().getTime()-n.getTime();return r<6e4?t(`notifications.justNow`):r<36e5?`${Math.floor(r/6e4)}m ago`:r<864e5?`${Math.floor(r/36e5)}h ago`:n.toLocaleDateString()+` `+sp(n,d)};return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg w-full max-w-3xl max-h-[85vh] flex flex-col`,children:[(0,G.jsxs)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(zc,{className:`w-5 h-5 text-bambu-green`}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:t(`notifications.notificationLog`)})]}),(0,G.jsx)(`button`,{onClick:e,className:`text-bambu-gray hover:text-white transition-colors`,children:`×`})]}),g&&(0,G.jsx)(`div`,{className:`px-4 py-3 border-b border-bambu-dark-tertiary bg-bambu-dark/50`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-6 text-sm`,children:[(0,G.jsxs)(`span`,{className:`text-bambu-gray`,children:[t(`notifications.statsSummary`,{days:i}),` `,(0,G.jsx)(`span`,{className:`text-white font-medium`,children:g.total}),` `,t(`notifications.statsNotifications`)]}),(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-bambu-green`,children:[(0,G.jsx)(xs,{className:`w-4 h-4`}),t(`notifications.statsSent`,{count:g.success_count})]}),g.failure_count>0&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-red-700 dark:text-red-400`,children:[(0,G.jsx)(Ds,{className:`w-4 h-4`}),t(`notifications.statsFailed`,{count:g.failure_count})]})]})}),(0,G.jsxs)(`div`,{className:`px-4 py-3 border-b border-bambu-dark-tertiary flex items-center gap-4`,children:[(0,G.jsxs)(`select`,{value:i,onChange:e=>a(Number(e.target.value)),className:`px-3 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:outline-none focus:ring-1 focus:ring-bambu-green`,children:[(0,G.jsx)(`option`,{value:1,children:t(`notifications.last24Hours`)}),(0,G.jsx)(`option`,{value:7,children:t(`notifications.last7Days`)}),(0,G.jsx)(`option`,{value:30,children:t(`notifications.last30Days`)}),(0,G.jsx)(`option`,{value:90,children:t(`notifications.last90Days`)})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-bambu-gray cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:c,onChange:e=>l(e.target.checked),className:`rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),t(`notifications.showFailedOnly`)]}),(0,G.jsx)(`div`,{className:`flex-1`}),(0,G.jsxs)(Q,{size:`sm`,variant:`secondary`,onClick:()=>m(),disabled:h,children:[h?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Hl,{className:`w-4 h-4`}),t(`notifications.refresh`)]}),(0,G.jsxs)(Q,{size:`sm`,variant:`secondary`,onClick:()=>_.mutate(),disabled:_.isPending,className:`text-red-700 dark:text-red-400 hover:text-red-800 dark:hover:text-red-300`,children:[_.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Pu,{className:`w-4 h-4`}),t(`notifications.clearOld`)]})]}),(0,G.jsx)(`div`,{className:`flex-1 overflow-y-auto p-4`,children:p?(0,G.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,G.jsx)(Y,{className:`w-6 h-6 text-bambu-green animate-spin`})}):f&&f.length>0?(0,G.jsx)(`div`,{className:`space-y-2`,children:f.map(e=>(0,G.jsx)(YWe,{log:e,isExpanded:o===e.id,onToggle:()=>s(o===e.id?null:e.id),formatDate:v,formatFullDate:e=>op(e,d)},e.id))}):(0,G.jsxs)(`div`,{className:`text-center py-12 text-bambu-gray`,children:[(0,G.jsx)(zc,{className:`w-12 h-12 mx-auto mb-3 opacity-30`}),(0,G.jsx)(`p`,{className:`text-sm`,children:t(c?`notifications.noFailedNotifications`:`notifications.noNotificationsLogged`)})]})})]})})}function YWe({log:e,isExpanded:t,onToggle:n,formatDate:r,formatFullDate:i}){let{t:a}=U();return(0,G.jsxs)(`div`,{className:`border rounded-lg overflow-hidden transition-colors ${e.success?`border-bambu-dark-tertiary bg-bambu-dark/30`:`border-red-500/30 bg-red-500/5`}`,children:[(0,G.jsxs)(`button`,{className:`w-full px-3 py-2 flex items-center gap-3 text-left hover:bg-bambu-dark/50 transition-colors`,onClick:n,children:[e.success?(0,G.jsx)(xs,{className:`w-4 h-4 text-bambu-green shrink-0`}):(0,G.jsx)(Ds,{className:`w-4 h-4 text-red-600 dark:text-red-400 shrink-0`}),(0,G.jsx)(`span`,{className:`text-xs font-medium ${qWe[e.event_type]||`text-bambu-gray`}`,children:a(`notifications.eventTypes.${e.event_type}`,e.event_type)}),(0,G.jsx)(`span`,{className:`text-sm text-white truncate flex-1`,children:e.provider_name||a(`notifications.unknownProvider`)}),e.printer_name&&(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:e.printer_name}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray shrink-0`,children:r(e.created_at)}),t?(0,G.jsx)(gs,{className:`w-4 h-4 text-bambu-gray shrink-0`}):(0,G.jsx)(ps,{className:`w-4 h-4 text-bambu-gray shrink-0`})]}),t&&(0,G.jsxs)(`div`,{className:`px-3 py-2 border-t border-bambu-dark-tertiary bg-bambu-dark/20 space-y-2`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mb-1`,children:a(`notifications.logTitle`)}),(0,G.jsx)(`p`,{className:`text-sm text-white`,children:e.title})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mb-1`,children:a(`notifications.logMessage`)}),(0,G.jsx)(`p`,{className:`text-sm text-white whitespace-pre-wrap`,children:e.message})]}),!e.success&&e.error_message&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-xs text-red-700 dark:text-red-400 mb-1`,children:a(`notifications.logError`)}),(0,G.jsx)(`p`,{className:`text-sm text-red-700 dark:text-red-300`,children:e.error_message})]}),(0,G.jsxs)(`div`,{className:`flex gap-4 text-xs text-bambu-gray pt-1`,children:[(0,G.jsx)(`span`,{children:a(`notifications.logProvider`,{type:e.provider_type})}),(0,G.jsx)(`span`,{children:a(`notifications.logTime`,{time:i(e.created_at)})})]})]})]})}var XWe=Object.defineProperty,i8=Object.getOwnPropertySymbols,a8=Object.prototype.hasOwnProperty,o8=Object.prototype.propertyIsEnumerable,s8=(e,t,n)=>t in e?XWe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,c8=(e,t)=>{for(var n in t||={})a8.call(t,n)&&s8(e,n,t[n]);if(i8)for(var n of i8(t))o8.call(t,n)&&s8(e,n,t[n]);return e},l8=(e,t)=>{var n={};for(var r in e)a8.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&i8)for(var r of i8(e))t.indexOf(r)<0&&o8.call(e,r)&&(n[r]=e[r]);return n},u8;(e=>{let t=class t{constructor(e,n,r,a){if(this.version=e,this.errorCorrectionLevel=n,this.modules=[],this.isFunction=[],et.MAX_VERSION)throw RangeError(`Version value out of range`);if(a<-1||a>7)throw RangeError(`Mask value out of range`);this.size=e*4+17;let o=[];for(let e=0;e7)throw RangeError(`Invalid value`);let u,d;for(u=a;;u++){let n=t.getNumDataCodewords(u,r)*8,i=o.getTotalBits(e,u);if(i<=n){d=i;break}if(u>=s)throw RangeError(`Data too long`)}for(let e of[t.Ecc.MEDIUM,t.Ecc.QUARTILE,t.Ecc.HIGH])l&&d<=t.getNumDataCodewords(u,e)*8&&(r=e);let f=[];for(let t of e){n(t.mode.modeBits,4,f),n(t.numChars,t.mode.numCharCountBits(u),f);for(let e of t.getData())f.push(e)}i(f.length==d);let p=t.getNumDataCodewords(u,r)*8;i(f.length<=p),n(0,Math.min(4,p-f.length),f),n(0,(8-f.length%8)%8,f),i(f.length%8==0);for(let e=236;f.lengthm[t>>>3]|=e<<7-(t&7)),new t(u,r,m,c)}getModule(e,t){return 0<=e&&e>>9)*1335;let a=(t<<10|n)^21522;i(a>>>15==0);for(let e=0;e<=5;e++)this.setFunctionModule(8,e,r(a,e));this.setFunctionModule(8,7,r(a,6)),this.setFunctionModule(8,8,r(a,7)),this.setFunctionModule(7,8,r(a,8));for(let e=9;e<15;e++)this.setFunctionModule(14-e,8,r(a,e));for(let e=0;e<8;e++)this.setFunctionModule(this.size-1-e,8,r(a,e));for(let e=8;e<15;e++)this.setFunctionModule(8,this.size-15+e,r(a,e));this.setFunctionModule(8,this.size-8,!0)}drawVersion(){if(this.version<7)return;let e=this.version;for(let t=0;t<12;t++)e=e<<1^(e>>>11)*7973;let t=this.version<<12|e;i(t>>>18==0);for(let e=0;e<18;e++){let n=r(t,e),i=this.size-11+e%3,a=Math.floor(e/3);this.setFunctionModule(i,a,n),this.setFunctionModule(a,i,n)}}drawFinderPattern(e,t){for(let n=-4;n<=4;n++)for(let r=-4;r<=4;r++){let i=Math.max(Math.abs(r),Math.abs(n)),a=e+r,o=t+n;0<=a&&a{(e!=l-o||n>=c)&&f.push(t[e])});return i(f.length==s),f}drawCodewords(e){if(e.length!=Math.floor(t.getNumRawDataModules(this.version)/8))throw RangeError(`Invalid argument`);let n=0;for(let t=this.size-1;t>=1;t-=2){t==6&&(t=5);for(let i=0;i>>3],7-(n&7)),n++)}}i(n==e.length*8)}applyMask(e){if(e<0||e>7)throw RangeError(`Mask value out of range`);for(let t=0;t5&&e++):(this.finderPenaltyAddHistory(i,a),r||(e+=this.finderPenaltyCountPatterns(a)*t.PENALTY_N3),r=this.modules[n][o],i=1);e+=this.finderPenaltyTerminateAndCount(r,i,a)*t.PENALTY_N3}for(let n=0;n5&&e++):(this.finderPenaltyAddHistory(i,a),r||(e+=this.finderPenaltyCountPatterns(a)*t.PENALTY_N3),r=this.modules[o][n],i=1);e+=this.finderPenaltyTerminateAndCount(r,i,a)*t.PENALTY_N3}for(let n=0;ne+ +!!t,n);let r=this.size*this.size,a=Math.ceil(Math.abs(n*20-r*10)/r)-1;return i(0<=a&&a<=9),e+=a*t.PENALTY_N4,i(0<=e&&e<=2568888),e}getAlignmentPatternPositions(){if(this.version==1)return[];{let e=Math.floor(this.version/7)+2,t=this.version==32?26:Math.ceil((this.version*4+4)/(e*2-2))*2,n=[6];for(let r=this.size-7;n.lengtht.MAX_VERSION)throw RangeError(`Version number out of range`);let n=(16*e+128)*e+64;if(e>=2){let t=Math.floor(e/7)+2;n-=(25*t-10)*t-55,e>=7&&(n-=36)}return i(208<=n&&n<=29648),n}static getNumDataCodewords(e,n){return Math.floor(t.getNumRawDataModules(e)/8)-t.ECC_CODEWORDS_PER_BLOCK[n.ordinal][e]*t.NUM_ERROR_CORRECTION_BLOCKS[n.ordinal][e]}static reedSolomonComputeDivisor(e){if(e<1||e>255)throw RangeError(`Degree out of range`);let n=[];for(let t=0;t0);for(let i of e){let e=i^r.shift();r.push(0),n.forEach((n,i)=>r[i]^=t.reedSolomonMultiply(n,e))}return r}static reedSolomonMultiply(e,t){if(e>>>8||t>>>8)throw RangeError(`Byte out of range`);let n=0;for(let r=7;r>=0;r--)n=n<<1^(n>>>7)*285,n^=(t>>>r&1)*e;return i(n>>>8==0),n}finderPenaltyCountPatterns(e){let t=e[1];i(t<=this.size*3);let n=t>0&&e[2]==t&&e[3]==t*3&&e[4]==t&&e[5]==t;return(n&&e[0]>=t*4&&e[6]>=t?1:0)+(n&&e[6]>=t*4&&e[0]>=t?1:0)}finderPenaltyTerminateAndCount(e,t,n){return e&&(this.finderPenaltyAddHistory(t,n),t=0),t+=this.size,this.finderPenaltyAddHistory(t,n),this.finderPenaltyCountPatterns(n)}finderPenaltyAddHistory(e,t){t[0]==0&&(e+=this.size),t.pop(),t.unshift(e)}};t.MIN_VERSION=1,t.MAX_VERSION=40,t.PENALTY_N1=3,t.PENALTY_N2=3,t.PENALTY_N3=40,t.PENALTY_N4=10,t.ECC_CODEWORDS_PER_BLOCK=[[-1,7,10,15,20,26,18,20,24,30,18,20,24,26,30,22,24,28,30,28,28,28,28,30,30,26,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,10,16,26,18,24,16,18,22,22,26,30,22,22,24,24,28,28,26,26,26,26,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28],[-1,13,22,18,26,18,24,18,22,20,24,28,26,24,20,30,24,28,28,26,30,28,30,30,30,30,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,17,28,22,16,22,28,26,26,24,28,24,28,22,24,24,30,28,28,26,28,30,24,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30]],t.NUM_ERROR_CORRECTION_BLOCKS=[[-1,1,1,1,1,1,2,2,2,2,4,4,4,4,4,6,6,6,6,7,8,8,9,9,10,12,12,12,13,14,15,16,17,18,19,19,20,21,22,24,25],[-1,1,1,1,2,2,4,4,4,5,5,5,8,9,9,10,10,11,13,14,16,17,17,18,20,21,23,25,26,28,29,31,33,35,37,38,40,43,45,47,49],[-1,1,1,2,2,4,4,6,6,8,8,8,10,12,16,12,17,16,18,21,20,23,23,25,27,29,34,34,35,38,40,43,45,48,51,53,56,59,62,65,68],[-1,1,1,2,4,4,4,5,6,8,8,11,11,16,16,18,16,19,21,25,25,25,34,30,32,35,37,40,42,45,48,51,54,57,60,63,66,70,74,77,81]],e.QrCode=t;function n(e,t,n){if(t<0||t>31||e>>>t)throw RangeError(`Value out of range`);for(let r=t-1;r>=0;r--)n.push(e>>>r&1)}function r(e,t){return(e>>>t&1)!=0}function i(e){if(!e)throw Error(`Assertion error`)}let a=class e{constructor(e,t,n){if(this.mode=e,this.numChars=t,this.bitData=n,t<0)throw RangeError(`Invalid argument`);this.bitData=n.slice()}static makeBytes(t){let r=[];for(let e of t)n(e,8,r);return new e(e.Mode.BYTE,t.length,r)}static makeNumeric(t){if(!e.isNumeric(t))throw RangeError(`String contains non-numeric characters`);let r=[];for(let e=0;e=1<{(e=>{let t=class{constructor(e,t){this.ordinal=e,this.formatBits=t}};t.LOW=new t(0,1),t.MEDIUM=new t(1,0),t.QUARTILE=new t(2,3),t.HIGH=new t(3,2),e.Ecc=t})(e.QrCode||={})})(u8||={}),(e=>{(e=>{let t=class{constructor(e,t){this.modeBits=e,this.numBitsCharCount=t}numCharCountBits(e){return this.numBitsCharCount[Math.floor((e+7)/17)]}};t.NUMERIC=new t(1,[10,12,14]),t.ALPHANUMERIC=new t(2,[9,11,13]),t.BYTE=new t(4,[8,16,16]),t.KANJI=new t(8,[8,10,12]),t.ECI=new t(7,[0,0,0]),e.Mode=t})(e.QrSegment||={})})(u8||={});var d8=u8,ZWe={L:d8.QrCode.Ecc.LOW,M:d8.QrCode.Ecc.MEDIUM,Q:d8.QrCode.Ecc.QUARTILE,H:d8.QrCode.Ecc.HIGH},f8=128,p8=`L`,m8=`#FFFFFF`,h8=`#000000`,g8=!1,_8=1,QWe=4,$We=0,eGe=.1;function v8(e,t=0){let n=[];return e.forEach(function(e,r){let i=null;e.forEach(function(a,o){if(!a&&i!==null){n.push(`M${i+t} ${r+t}h${o-i}v1H${i+t}z`),i=null;return}if(o===e.length-1){if(!a)return;i===null?n.push(`M${o+t},${r+t} h1v1H${o+t}z`):n.push(`M${i+t},${r+t} h${o+1-i}v1H${i+t}z`);return}a&&i===null&&(i=o)})}),n.join(``)}function y8(e,t){return e.slice().map((e,n)=>n=t.y+t.h?e:e.map((e,n)=>n=t.x+t.w?e:!1))}function tGe(e,t,n,r){if(r==null)return null;let i=e.length+n*2,a=Math.floor(t*eGe),o=i/t,s=(r.width||a)*o,c=(r.height||a)*o,l=r.x==null?e.length/2-s/2:r.x*o,u=r.y==null?e.length/2-c/2:r.y*o,d=r.opacity==null?1:r.opacity,f=null;if(r.excavate){let e=Math.floor(l),t=Math.floor(u);f={x:e,y:t,w:Math.ceil(s+l-e),h:Math.ceil(c+u-t)}}let p=r.crossOrigin;return{x:l,y:u,h:c,w:s,excavation:f,opacity:d,crossOrigin:p}}function nGe(e,t){return t==null?e?QWe:$We:Math.max(Math.floor(t),0)}function b8({value:e,level:t,minVersion:n,includeMargin:r,marginSize:i,imageSettings:a,size:o,boostLevel:s}){let c=y.useMemo(()=>{let r=(Array.isArray(e)?e:[e]).reduce((e,t)=>(e.push(...d8.QrSegment.makeSegments(t)),e),[]);return d8.QrCode.encodeSegments(r,ZWe[t],n,void 0,void 0,s)},[e,t,n,s]),{cells:l,margin:u,numCells:d,calculatedImageSettings:f}=y.useMemo(()=>{let e=c.getModules(),t=nGe(r,i);return{cells:e,margin:t,numCells:e.length+t*2,calculatedImageSettings:tGe(e,o,t,a)}},[c,o,a,r,i]);return{qrcode:c,margin:u,cells:l,numCells:d,calculatedImageSettings:f}}var rGe=function(){try{new Path2D().addPath(new Path2D)}catch{return!1}return!0}(),iGe=y.forwardRef(function(e,t){let n=e,{value:r,size:i=f8,level:a=p8,bgColor:o=m8,fgColor:s=h8,includeMargin:c=g8,minVersion:l=_8,boostLevel:u,marginSize:d,imageSettings:f}=n,p=l8(n,[`value`,`size`,`level`,`bgColor`,`fgColor`,`includeMargin`,`minVersion`,`boostLevel`,`marginSize`,`imageSettings`]),{style:m}=p,h=l8(p,[`style`]),g=f?.src,_=y.useRef(null),v=y.useRef(null),b=y.useCallback(e=>{_.current=e,typeof t==`function`?t(e):t&&(t.current=e)},[t]),[x,S]=y.useState(!1),{margin:C,cells:w,numCells:T,calculatedImageSettings:E}=b8({value:r,level:a,minVersion:l,boostLevel:u,includeMargin:c,marginSize:d,imageSettings:f,size:i});y.useEffect(()=>{if(_.current!=null){let e=_.current,t=e.getContext(`2d`);if(!t)return;let n=w,r=v.current,a=E!=null&&r!==null&&r.complete&&r.naturalHeight!==0&&r.naturalWidth!==0;a&&E.excavation!=null&&(n=y8(w,E.excavation));let c=window.devicePixelRatio||1;e.height=e.width=i*c;let l=i/T*c;t.scale(l,l),t.fillStyle=o,t.fillRect(0,0,T,T),t.fillStyle=s,rGe?t.fill(new Path2D(v8(n,C))):w.forEach(function(e,n){e.forEach(function(e,r){e&&t.fillRect(r+C,n+C,1,1)})}),E&&(t.globalAlpha=E.opacity),a&&t.drawImage(r,E.x+C,E.y+C,E.w,E.h)}}),y.useEffect(()=>{S(!1)},[g]);let D=c8({height:i,width:i},m),O=null;return g!=null&&(O=y.createElement(`img`,{src:g,key:g,style:{display:`none`},onLoad:()=>{S(!0)},ref:v,crossOrigin:E?.crossOrigin})),y.createElement(y.Fragment,null,y.createElement(`canvas`,c8({style:D,height:i,width:i,ref:b,role:`img`},h)),O)});iGe.displayName=`QRCodeCanvas`;var x8=y.forwardRef(function(e,t){let n=e,{value:r,size:i=f8,level:a=p8,bgColor:o=m8,fgColor:s=h8,includeMargin:c=g8,minVersion:l=_8,boostLevel:u,title:d,marginSize:f,imageSettings:p}=n,m=l8(n,[`value`,`size`,`level`,`bgColor`,`fgColor`,`includeMargin`,`minVersion`,`boostLevel`,`title`,`marginSize`,`imageSettings`]),{margin:h,cells:g,numCells:_,calculatedImageSettings:v}=b8({value:r,level:a,minVersion:l,boostLevel:u,includeMargin:c,marginSize:f,imageSettings:p,size:i}),b=g,x=null;p!=null&&v!=null&&(v.excavation!=null&&(b=y8(g,v.excavation)),x=y.createElement(`image`,{href:p.src,height:v.h,width:v.w,x:v.x+h,y:v.y+h,preserveAspectRatio:`none`,opacity:v.opacity,crossOrigin:v.crossOrigin}));let S=v8(b,h);return y.createElement(`svg`,c8({height:i,width:i,viewBox:`0 0 ${_} ${_}`,ref:t,role:`img`},m),!!d&&y.createElement(`title`,null,d),y.createElement(`path`,{fill:o,d:`M0,0 h${_}v${_}H0z`,shapeRendering:`crispEdges`}),y.createElement(`path`,{fill:s,d:S,shapeRendering:`crispEdges`}),x)});x8.displayName=`QRCodeSVG`;function aGe(e,t){return`bambuddy://config?v=1&url=${encodeURIComponent(e)}&key=${encodeURIComponent(t)}`}function oGe({apiKey:e,baseUrl:t,onClose:n}){let{t:r}=U(),i=aGe(t??window.location.origin,e);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:r(`settings.apiKeyQrTitle`)}),(0,G.jsx)(`button`,{onClick:n,className:`text-bambu-gray hover:text-white transition-colors`,"aria-label":r(`common.close`),children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]}),(0,G.jsxs)(`div`,{className:`p-6 flex flex-col items-center`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4 text-center`,children:r(`settings.apiKeyQrCaption`)}),(0,G.jsx)(`div`,{className:`bg-white p-4 rounded-lg mb-4`,children:(0,G.jsx)(x8,{value:i,size:256})}),(0,G.jsxs)(`div`,{className:`flex items-start gap-2 text-xs text-amber-700 dark:text-amber-400 mb-4`,children:[(0,G.jsx)(Lu,{className:`w-4 h-4 flex-shrink-0 mt-0.5`}),(0,G.jsx)(`span`,{children:r(`settings.apiKeyQrWarning`)})]}),(0,G.jsx)(Q,{onClick:n,className:`w-full`,children:r(`common.close`)})]})]})})}var sGe=300,S8=2;function C8({onSuccess:e}){let{t}=U(),n=co(),[r,i]=(0,y.useState)(``),[a,o]=(0,y.useState)(``),[s,c]=(0,y.useState)(null),[l,u]=(0,y.useState)(null);(0,y.useEffect)(()=>{let e=r.trim();if(e.lengtho(e),sGe);return()=>clearTimeout(t)},[r]),(0,y.useEffect)(()=>{c(null),u(null)},[a]);let d=K({queryKey:[`ldap-search`,a],queryFn:()=>Z.searchLDAPDirectory(a),enabled:a.length>=S8,staleTime:3e4}),f=q({mutationFn:e=>Z.provisionLDAPUser(e),onSuccess:t=>{n.invalidateQueries({queryKey:[`users`]}),e(t)},onError:e=>{u(e.message||t(`users.modal.ldapErrorProvision`))}}),p=(0,y.useMemo)(()=>d.data?.find(e=>e.dn===s)??null,[d.data,s]),m=r.trim().length>0&&r.trim().length=S8,g=!!d.data&&d.data.length>0,_=!h&&!!d.data&&d.data.length===0&&a.length>=S8;return(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:t(`users.modal.ldapSearchLabel`)}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(Ql,{className:`w-4 h-4 text-bambu-gray absolute left-3 top-1/2 -translate-y-1/2`}),(0,G.jsx)(`input`,{type:`text`,value:r,onChange:e=>i(e.target.value),className:`w-full pl-9 pr-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:t(`users.modal.ldapSearchPlaceholder`),autoComplete:`off`})]}),m&&(0,G.jsx)(`p`,{className:`mt-1 text-xs text-bambu-gray`,children:t(`users.modal.ldapMinChars`)})]}),(0,G.jsxs)(`div`,{className:`min-h-[8rem] max-h-64 overflow-y-auto bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg`,children:[h&&(0,G.jsxs)(`div`,{className:`flex items-center justify-center py-8 text-bambu-gray`,children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin mr-2`}),(0,G.jsx)(`span`,{children:t(`users.modal.ldapSearching`)})]}),_&&(0,G.jsx)(`div`,{className:`flex items-center justify-center py-8 text-bambu-gray text-sm`,children:t(`users.modal.ldapNoResults`)}),d.isError&&(0,G.jsx)(`div`,{className:`px-3 py-4 text-sm text-red-700 dark:text-red-400`,children:d.error instanceof Error?d.error.message:t(`users.modal.ldapSearchError`)}),!h&&g&&(0,G.jsx)(`ul`,{className:`divide-y divide-bambu-dark-tertiary`,children:d.data.map(e=>(0,G.jsx)(cGe,{result:e,selected:s===e.dn,onSelect:()=>c(e.dn)},e.dn))}),!h&&!d.data&&!d.isError&&(0,G.jsx)(`div`,{className:`flex items-center justify-center py-8 text-bambu-gray text-sm`,children:t(`users.modal.ldapTypeToSearch`)})]}),p&&(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary/50 border border-bambu-green/20 rounded-lg p-3 space-y-1`,children:[(0,G.jsxs)(`p`,{className:`text-sm text-white`,children:[(0,G.jsxs)(`span`,{className:`text-bambu-gray`,children:[t(`users.modal.ldapSelectedLabel`),`: `]}),(0,G.jsx)(`span`,{className:`font-medium`,children:p.username}),p.display_name&&(0,G.jsxs)(`span`,{className:`text-bambu-gray`,children:[` — `,p.display_name]})]}),p.email&&(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:p.email}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray break-all`,children:p.dn})]}),l&&(0,G.jsx)(`div`,{className:`bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30 rounded-lg p-3`,children:(0,G.jsx)(`p`,{className:`text-sm text-red-700 dark:text-red-400`,children:l})}),(0,G.jsx)(`div`,{className:`flex justify-end`,children:(0,G.jsx)(Q,{onClick:()=>{!p||p.already_provisioned||(u(null),f.mutate(p.username))},disabled:!p||p.already_provisioned||f.isPending,children:f.isPending?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),t(`users.modal.ldapProvisioning`)]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Fl,{className:`w-4 h-4`}),t(`users.modal.ldapProvision`)]})})})]})}function cGe({result:e,selected:t,onSelect:n}){let{t:r}=U(),i=e.already_provisioned;return(0,G.jsx)(`li`,{children:(0,G.jsxs)(`button`,{type:`button`,onClick:n,disabled:i,className:`w-full text-left px-3 py-2 flex items-center gap-3 transition-colors ${i?`opacity-50 cursor-not-allowed`:t?`bg-bambu-green/10`:`hover:bg-bambu-dark-tertiary`}`,children:[(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsxs)(`p`,{className:`text-sm text-white truncate`,children:[(0,G.jsx)(`span`,{className:`font-medium`,children:e.username}),e.display_name&&(0,G.jsxs)(`span`,{className:`text-bambu-gray`,children:[` — `,e.display_name]})]}),e.email&&(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray truncate`,children:e.email})]}),i&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-xs text-bambu-gray whitespace-nowrap`,children:[(0,G.jsx)(Ss,{className:`w-3.5 h-3.5`}),r(`users.modal.ldapAlreadyProvisioned`)]})]})})}function lGe({formData:e,setFormData:t,groups:n,onClose:r,onCreate:i,isCreating:a,isCreateButtonDisabled:o,ldapEnabled:s=!1,onLdapProvisioned:c}){let{t:l}=U(),[u,d]=(0,y.useState)(`local`);(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&r()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[r]);let f=n=>{t({...e,group_ids:e.group_ids.includes(n)?e.group_ids.filter(e=>e!==n):[...e.group_ids,n]})};return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:r,children:(0,G.jsxs)(zd,{className:`w-full max-w-md`,onClick:e=>e.stopPropagation(),children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Uu,{className:`w-5 h-5 text-bambu-green`}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:l(`users.modal.createUser`)})]}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray ml-7`,children:l(`users.modal.advancedAuthSubtitle`)||`with Advanced Authentication`})]}),(0,G.jsx)(Q,{variant:`ghost`,size:`sm`,onClick:r,children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]})}),(0,G.jsxs)(Vd,{children:[s&&(0,G.jsxs)(`div`,{className:`mb-4 flex items-center gap-1 p-1 bg-bambu-dark-secondary rounded-lg`,role:`tablist`,"aria-label":l(`users.modal.tabsAriaLabel`),children:[(0,G.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":u===`local`,onClick:()=>d(`local`),className:`flex-1 px-3 py-2 text-sm rounded-md transition-colors ${u===`local`?`bg-bambu-green/15 text-bambu-green`:`text-bambu-gray hover:text-white`}`,children:l(`users.modal.localTab`)}),(0,G.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":u===`ldap`,onClick:()=>d(`ldap`),className:`flex-1 px-3 py-2 text-sm rounded-md transition-colors ${u===`ldap`?`bg-bambu-green/15 text-bambu-green`:`text-bambu-gray hover:text-white`}`,children:l(`users.modal.ldapTab`)})]}),u===`ldap`&&s?(0,G.jsx)(C8,{onSuccess:e=>{c?.(e)}}):(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:[l(`users.form.username`),` `,(0,G.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:`*`})]}),(0,G.jsx)(`input`,{type:`text`,value:e.username,onChange:n=>t({...e,username:n.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:l(`users.form.usernamePlaceholder`),autoComplete:`username`,required:!0})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:[l(`users.form.email`)||`Email`,` `,(0,G.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:`*`})]}),(0,G.jsx)(`input`,{type:`email`,value:e.email,onChange:n=>t({...e,email:n.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:l(`users.form.emailPlaceholder`)||`user@example.com`,required:!0})]}),(0,G.jsx)(`div`,{className:`bg-bambu-dark-secondary/50 border border-bambu-green/20 rounded-lg p-3`,children:(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:l(`users.form.autoGeneratedPassword`)||`A secure password will be automatically generated and emailed to the user.`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:l(`users.form.groups`)}),(0,G.jsxs)(`div`,{className:`space-y-2 max-h-40 overflow-y-auto p-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg`,children:[n.map(t=>(0,G.jsxs)(`label`,{className:`flex items-center gap-3 px-2 py-1.5 rounded hover:bg-bambu-dark-tertiary cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:e.group_ids.includes(t.id),onChange:()=>f(t.id),className:`w-4 h-4 rounded border-bambu-gray text-bambu-green focus:ring-bambu-green focus:ring-offset-0 bg-bambu-dark`}),(0,G.jsx)(`span`,{className:`text-sm text-white`,children:t.name}),t.is_system&&(0,G.jsxs)(`span`,{className:`text-xs text-yellow-700 dark:text-yellow-400`,children:[`(`,l(`users.system`),`)`]})]},t.id)),n.length===0&&(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:l(`users.noGroupsAvailable`)})]})]})]}),(0,G.jsxs)(`div`,{className:`mt-6 flex justify-end gap-3`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:r,children:l(`users.modal.cancel`)}),u===`local`&&(0,G.jsx)(Q,{onClick:i,disabled:o,children:a?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),l(`users.modal.creating`)]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Fl,{className:`w-4 h-4`}),l(`users.modal.createUser`)]})})]})]})]})})}function uGe(){let{t:e}=U(),t=co(),{showToast:n}=qd(),[r,i]=(0,y.useState)(!1),[a,o]=(0,y.useState)(``),[s,c]=(0,y.useState)(`auto`),[l,u]=(0,y.useState)(!1),[d,f]=(0,y.useState)(!0),[p,m]=(0,y.useState)(!0),[h,g]=(0,y.useState)(`all`),[_,v]=(0,y.useState)(!1),[b,x]=(0,y.useState)(!1),[S,C]=(0,y.useState)(!1),[w,T]=(0,y.useState)(!1),{data:E,isLoading:D}=K({queryKey:[`spoolman-settings`],queryFn:Z.getSpoolmanSettings}),{data:O,isLoading:k,refetch:A}=K({queryKey:[`spoolman-status`],queryFn:Z.getSpoolmanStatus,refetchInterval:3e4}),{data:j}=K({queryKey:[`printers`],queryFn:Z.getPrinters});(0,y.useEffect)(()=>{E&&(i(E.spoolman_enabled===`true`),o(E.spoolman_url||``),c(E.spoolman_sync_mode||`auto`),u(E.spoolman_disable_weight_sync===`true`),f(E.spoolman_report_partial_usage!==`false`),m(E.auto_add_unknown_rfid!==`false`),v(!0))},[E]),(0,y.useEffect)(()=>{if(!(!_||!E)&&(E.spoolman_enabled===`true`!==r||(E.spoolman_url||``)!==a||(E.spoolman_sync_mode||`auto`)!==s||E.spoolman_disable_weight_sync===`true`!==l||E.spoolman_report_partial_usage!==`false`!==d||E.auto_add_unknown_rfid!==`false`!==p)){let e=setTimeout(()=>{M.mutate()},500);return()=>clearTimeout(e)}},[r,a,s,l,d,p,_]);let M=q({mutationFn:()=>Z.updateSpoolmanSettings({spoolman_enabled:r?`true`:`false`,spoolman_url:a,spoolman_sync_mode:s,spoolman_disable_weight_sync:l?`true`:`false`,spoolman_report_partial_usage:d?`true`:`false`,auto_add_unknown_rfid:p?`true`:`false`}),onSuccess:()=>{t.invalidateQueries({queryKey:[`spoolman-settings`]}),t.invalidateQueries({queryKey:[`spoolman-status`]}),t.invalidateQueries({queryKey:[`spool-assignments`]}),t.invalidateQueries({queryKey:[`settings`]}),t.invalidateQueries({queryKey:[`spoolman-inventory-filaments`]}),n(e(`settings.toast.settingsSaved`))},onError:()=>{n(e(`settings.toast.saveFailed`),`error`)}}),N=q({mutationFn:Z.connectSpoolman,onSuccess:()=>{A()},onError:()=>{n(e(`settings.toast.saveFailed`),`error`)}}),P=q({mutationFn:Z.syncAllPrintersAms,onSuccess:t=>{n(e(`settings.spoolmanAmsSyncSuccess`,{synced:t.synced_count,skipped:0}),`success`)},onError:()=>{n(e(`settings.toast.saveFailed`),`error`)}}),F=q({mutationFn:e=>Z.syncPrinterAms(e),onSuccess:t=>{n(e(`settings.spoolmanAmsSyncSuccess`,{synced:t.synced_count,skipped:0}),`success`)},onError:()=>{n(e(`settings.toast.saveFailed`),`error`)}}),I=()=>{h===`all`?P.mutate():F.mutate(h)},L=q({mutationFn:Z.syncWeightsFromAms,onSuccess:r=>{t.invalidateQueries({queryKey:[`spools`]}),t.invalidateQueries({queryKey:[`inventory-spools`]}),n(e(`settings.amsSyncSuccess`,{synced:r.synced,skipped:r.skipped}),`success`),C(!1)},onError:()=>{n(e(`settings.amsSyncError`),`error`),C(!1)}}),R=q({mutationFn:Z.syncSpoolmanAmsWeights,onSuccess:r=>{t.invalidateQueries({queryKey:[`spoolman-inventory-spools`]}),n(e(`settings.spoolmanAmsSyncSuccess`,{synced:r.synced,skipped:r.skipped}),`success`),T(!1)},onError:t=>{t instanceof sd&&t.status===503?n(e(`settings.spoolmanAmsSyncErrorUnreachable`),`error`):t instanceof sd&&t.status===400?n(e(`settings.spoolmanAmsSyncErrorNotConfigured`),`error`):n(e(`settings.spoolmanAmsSyncError`),`error`),T(!1)}}),z=P.isPending||F.isPending,B=h===`all`?P.data:F.data,V=h===`all`?P.isSuccess:F.isSuccess;return D?(0,G.jsxs)(zd,{id:`card-spoolman`,children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Gs,{className:`w-5 h-5 text-bambu-green`}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`settings.filamentTracking`)})]})}),(0,G.jsx)(Vd,{children:(0,G.jsx)(`div`,{className:`flex justify-center py-8`,children:(0,G.jsx)(Y,{className:`w-6 h-6 text-bambu-green animate-spin`})})})]}):(0,G.jsxs)(zd,{id:`card-spoolman`,children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Gs,{className:`w-5 h-5 text-bambu-green`}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`settings.filamentTracking`)})]}),M.isPending&&(0,G.jsx)(Y,{className:`w-4 h-4 text-bambu-green animate-spin`})]})}),(0,G.jsxs)(Vd,{className:`space-y-4`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`settings.filamentTrackingDesc`)}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,G.jsxs)(`button`,{type:`button`,onClick:()=>i(!1),className:`p-3 rounded-lg border-2 text-left transition-colors ${r?`border-bambu-dark-tertiary bg-bambu-dark hover:border-bambu-gray/50`:`border-bambu-green bg-bambu-green/10`}`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-1.5`,children:[(0,G.jsx)(Cl,{className:`w-4 h-4 ${r?`text-bambu-gray`:`text-bambu-green`}`}),(0,G.jsx)(`span`,{className:`text-sm font-medium ${r?`text-bambu-gray`:`text-white`}`,children:e(`settings.trackingModeBuiltIn`)})]}),(0,G.jsx)(`p`,{className:`text-xs ${r?`text-bambu-gray/60`:`text-bambu-gray`}`,children:e(`settings.trackingModeBuiltInDesc`)}),!r&&(0,G.jsxs)(`div`,{className:`flex items-center gap-1 mt-2`,children:[(0,G.jsx)(fs,{className:`w-3 h-3 text-bambu-green`}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-green`,children:e(`common.enabled`)})]})]}),(0,G.jsxs)(`button`,{type:`button`,onClick:()=>i(!0),className:`p-3 rounded-lg border-2 text-left transition-colors ${r?`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary bg-bambu-dark hover:border-bambu-gray/50`}`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-1.5`,children:[(0,G.jsx)(rc,{className:`w-4 h-4 ${r?`text-bambu-green`:`text-bambu-gray`}`}),(0,G.jsx)(`span`,{className:`text-sm font-medium ${r?`text-white`:`text-bambu-gray`}`,children:`Spoolman`})]}),(0,G.jsx)(`p`,{className:`text-xs ${r?`text-bambu-gray`:`text-bambu-gray/60`}`,children:e(`settings.trackingModeSpoolmanDesc`)}),r&&(0,G.jsxs)(`div`,{className:`flex items-center gap-1 mt-2`,children:[(0,G.jsx)(fs,{className:`w-3 h-3 text-bambu-green`}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-green`,children:e(`common.enabled`)})]})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between pt-2 border-t border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`pr-4`,children:[(0,G.jsx)(`p`,{className:`text-white`,children:e(`settings.autoAddUnknownRfid`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`settings.autoAddUnknownRfidDesc`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:p,onChange:e=>m(e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),!r&&(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsx)(`div`,{className:`p-3 bg-bambu-green/5 border border-bambu-green/20 rounded-lg`,children:(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsx)(Wc,{className:`w-4 h-4 text-bambu-green flex-shrink-0 mt-0.5`}),(0,G.jsx)(`div`,{className:`text-xs text-bambu-gray`,children:(0,G.jsxs)(`ul`,{className:`list-disc list-inside space-y-0.5`,children:[(0,G.jsx)(`li`,{children:e(`settings.builtInFeatureRfid`)}),(0,G.jsx)(`li`,{children:e(`settings.builtInFeatureUsage`)}),(0,G.jsx)(`li`,{children:e(`settings.builtInFeatureCatalog`)}),(0,G.jsx)(`li`,{children:e(`settings.builtInFeatureThirdParty`)})]})})]})}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:()=>C(!0),disabled:L.isPending,children:[L.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 mr-2 animate-spin`}):(0,G.jsx)(Hl,{className:`w-4 h-4 mr-2`}),e(`settings.amsSyncButton`)]})]}),r&&(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsx)(`div`,{className:`p-3 bg-blue-50 dark:bg-blue-500/10 border border-blue-300 dark:border-blue-500/30 rounded-lg`,children:(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsx)(Wc,{className:`w-4 h-4 text-blue-600 dark:text-blue-400 flex-shrink-0 mt-0.5`}),(0,G.jsxs)(`div`,{className:`text-xs text-blue-700 dark:text-blue-300`,children:[(0,G.jsx)(`p`,{className:`font-medium mb-1`,children:e(`settings.howSyncWorks`)}),(0,G.jsxs)(`ul`,{className:`list-disc list-inside space-y-0.5 text-blue-700/90 dark:text-blue-300/80`,children:[(0,G.jsx)(`li`,{children:e(`settings.syncInfoRfidOnly`)}),(0,G.jsx)(`li`,{children:e(`settings.syncInfoAutoCreate`)}),(0,G.jsx)(`li`,{children:e(`settings.syncInfoThirdPartySkipped`)})]}),(0,G.jsx)(`p`,{className:`font-medium mt-2 mb-1`,children:e(`settings.linkingExistingSpools`)}),(0,G.jsx)(`p`,{className:`text-blue-700/90 dark:text-blue-300/80`,children:e(`settings.linkingExistingSpoolsDesc`)})]})]})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:e(`settings.spoolmanUrl`)}),(0,G.jsx)(`input`,{type:`text`,placeholder:`http://192.168.1.100:7912`,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 placeholder-bambu-gray/50 focus:border-bambu-green focus:outline-none`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`settings.spoolmanUrlHint`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:e(`settings.syncMode`)}),(0,G.jsxs)(`select`,{value:s,onChange:e=>c(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,G.jsx)(`option`,{value:`auto`,children:e(`settings.syncModeAuto`)}),(0,G.jsx)(`option`,{value:`manual`,children:e(`settings.syncModeManual`)})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(s===`auto`?`settings.syncModeAutoDesc`:`settings.syncModeManualDesc`)})]}),s===`auto`&&(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:e(`spoolman.disableWeightSync`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`spoolman.disableWeightSyncDesc`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:l,onChange:e=>u(e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),l&&(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:e(`spoolman.reportPartialUsage`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`spoolman.reportPartialUsageDesc`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:d,onChange:e=>f(e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,G.jsxs)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[e(`settings.status`),`:`]}),k?(0,G.jsx)(Y,{className:`w-4 h-4 text-bambu-gray animate-spin`}):O?.connected?(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-sm text-green-500`,children:[(0,G.jsx)(fs,{className:`w-4 h-4`}),e(`settings.spoolmanConnected`)]}):(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-sm text-red-500`,children:[(0,G.jsx)(nd,{className:`w-4 h-4`}),e(`settings.spoolmanDisconnected`)]})]}),(0,G.jsx)(`div`,{className:`flex gap-2`,children:!O?.connected&&(0,G.jsxs)(Q,{size:`sm`,onClick:()=>N.mutate(),disabled:N.isPending||!a,children:[N.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Xc,{className:`w-4 h-4`}),e(`settings.connect`)]})})]}),N.isError&&(0,G.jsx)(`div`,{className:`mb-3 p-2 bg-red-100 dark:bg-red-500/20 border border-red-300 dark:border-red-500/50 rounded text-sm text-red-700 dark:text-red-400`,children:N.error.message}),O?.connected&&(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:e(`settings.syncAmsData`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:e(`settings.syncAmsDataDesc`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`div`,{className:`relative flex-1`,children:[(0,G.jsxs)(`select`,{value:h,onChange:e=>g(e.target.value===`all`?`all`:Number(e.target.value)),className:`w-full px-3 py-2 pr-8 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none appearance-none cursor-pointer`,children:[(0,G.jsx)(`option`,{value:`all`,children:e(`settings.allPrinters`)}),j?.map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),(0,G.jsx)(ps,{className:`absolute right-2 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:I,disabled:z,children:[z?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Hl,{className:`w-4 h-4`}),e(`spoolman.sync`)]})]})]}),O?.connected&&(0,G.jsx)(`div`,{className:`mt-4 pt-4 border-t border-bambu-dark-tertiary`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:e(`settings.spoolmanAmsSyncButton`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:e(`settings.spoolmanAmsSyncMessage`)})]}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:()=>T(!0),disabled:R.isPending,children:[R.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Hl,{className:`w-4 h-4`}),R.isPending?e(`settings.spoolmanAmsSyncing`):e(`settings.spoolmanAmsSyncButton`)]})]})}),V&&B&&(0,G.jsxs)(`div`,{className:`mt-3 space-y-2`,children:[(0,G.jsx)(`div`,{className:`p-2 rounded text-sm ${B.success?`bg-green-100 dark:bg-green-500/20 border border-green-300 dark:border-green-500/50 text-green-700 dark:text-green-400`:`bg-yellow-100 dark:bg-yellow-500/20 border border-yellow-300 dark:border-yellow-500/50 text-yellow-700 dark:text-yellow-400`}`,children:B.success?`Synced ${B.synced_count} spool${B.synced_count===1?``:`s`} successfully`:`Synced ${B.synced_count} spool${B.synced_count===1?``:`s`} with ${B.errors.length} error${B.errors.length===1?``:`s`}`}),B.skipped_count>0&&(0,G.jsxs)(`div`,{className:`p-2 bg-amber-50 dark:bg-amber-500/10 border border-amber-300 dark:border-amber-500/30 rounded text-sm`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between text-amber-700 dark:text-amber-400 mb-1`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,G.jsx)(Lu,{className:`w-3.5 h-3.5`}),(0,G.jsxs)(`span`,{className:`font-medium`,children:[B.skipped_count,` spool`,B.skipped_count===1?``:`s`,` skipped`]})]}),B.skipped_count>5&&(0,G.jsx)(`button`,{onClick:()=>x(!b),className:`text-xs text-amber-700 dark:text-amber-400 hover:text-amber-800 dark:hover:text-amber-300 underline`,children:b?`Show less`:`Show all`})]}),(0,G.jsxs)(`ul`,{className:`text-xs text-amber-700/90 dark:text-amber-300/80 space-y-0.5`,children:[(b?B.skipped:B.skipped.slice(0,5)).map((e,t)=>(0,G.jsxs)(`li`,{className:`flex items-center gap-2`,children:[e.color&&(0,G.jsx)(`span`,{className:`w-3 h-3 rounded-full border border-black/20`,style:{backgroundColor:`#${e.color}`}}),(0,G.jsx)(`span`,{children:e.location}),(0,G.jsxs)(`span`,{className:`text-amber-700/70 dark:text-amber-300/60`,children:[`- `,e.reason]})]},t)),!b&&B.skipped_count>5&&(0,G.jsxs)(`li`,{className:`text-amber-700/70 dark:text-amber-300/60 italic`,children:[`...and `,B.skipped_count-5,` more`]})]})]}),B.errors.length>0&&(0,G.jsxs)(`div`,{className:`p-2 bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30 rounded text-sm`,children:[(0,G.jsx)(`div`,{className:`text-red-700 dark:text-red-400 font-medium mb-1`,children:`Errors:`}),(0,G.jsx)(`ul`,{className:`text-xs text-red-700/90 dark:text-red-300/80 space-y-0.5`,children:B.errors.map((e,t)=>(0,G.jsx)(`li`,{children:e},t))})]})]})]})]})]}),S&&(0,G.jsx)(of,{title:e(`settings.amsSyncTitle`),message:e(`settings.amsSyncMessage`),confirmText:e(`settings.amsSyncButton`),variant:`warning`,isLoading:L.isPending,loadingText:e(`settings.amsSyncing`),onConfirm:()=>L.mutate(),onCancel:()=>C(!1)}),w&&(0,G.jsx)(of,{title:e(`settings.spoolmanAmsSyncTitle`),message:e(`settings.spoolmanAmsSyncMessage`),confirmText:e(`settings.spoolmanAmsSyncButton`),variant:`warning`,isLoading:R.isPending,loadingText:e(`settings.spoolmanAmsSyncing`),onConfirm:()=>R.mutate(),onCancel:()=>T(!1)})]})}function dGe(){let{t:e}=U(),{showToast:t}=qd(),[n,r]=(0,y.useState)([]),[i,a]=(0,y.useState)(!0),[o,s]=(0,y.useState)(``),c=(0,y.useRef)(null),[l,u]=(0,y.useState)(!1),[d,f]=(0,y.useState)(null),[p,m]=(0,y.useState)(``),[h,g]=(0,y.useState)(``),[_,v]=(0,y.useState)(!1),[b,x]=(0,y.useState)(new Set),[S,C]=(0,y.useState)(!1),[w,T]=(0,y.useState)(null),[E,D]=(0,y.useState)(!1),O=(0,y.useCallback)(async()=>{try{r(await Z.getSpoolCatalog())}catch(n){console.error(`SpoolCatalogSettings.loadCatalog failed:`,n),t(e(`settings.catalog.loadFailed`),`error`)}finally{a(!1)}},[t,e]);(0,y.useEffect)(()=>{O()},[O]);let k=n.filter(e=>e.name.toLowerCase().includes(o.toLowerCase())),A=async()=>{if(!p.trim()||!h){t(e(`settings.catalog.nameWeightRequired`),`error`);return}v(!0);try{let n=await Z.addCatalogEntry({name:p.trim(),weight:parseInt(h)});r(e=>[...e,n].sort((e,t)=>e.name.localeCompare(t.name))),u(!1),m(``),g(``),t(e(`settings.catalog.entryAdded`),`success`)}catch(n){console.error(`SpoolCatalogSettings.handleAdd failed:`,n),t(e(`settings.catalog.addFailed`),`error`)}finally{v(!1)}},j=e=>{f(e.id),m(e.name),g(e.weight.toString())},M=()=>{f(null),m(``),g(``)},N=async n=>{if(!p.trim()||!h){t(e(`settings.catalog.nameWeightRequired`),`error`);return}v(!0);try{let i=await Z.updateCatalogEntry(n,{name:p.trim(),weight:parseInt(h)});r(e=>e.map(e=>e.id===n?i:e).sort((e,t)=>e.name.localeCompare(t.name))),f(null),m(``),g(``),t(e(`settings.catalog.entryUpdated`),`success`)}catch(n){console.error(`SpoolCatalogSettings.handleUpdate failed:`,n),t(e(`settings.catalog.updateFailed`),`error`)}finally{v(!1)}},P=async()=>{if(w)try{await Z.deleteCatalogEntry(w.id),r(e=>e.filter(e=>e.id!==w.id)),t(e(`settings.catalog.entryDeleted`),`success`)}catch(n){console.error(`SpoolCatalogSettings.handleDelete failed:`,n),t(e(`settings.catalog.deleteFailed`),`error`)}finally{T(null)}},F=async()=>{D(!1),a(!0);try{await Z.resetSpoolCatalog(),await O(),t(e(`settings.catalog.resetSuccess`),`success`)}catch(n){console.error(`SpoolCatalogSettings.handleReset failed:`,n),t(e(`settings.catalog.resetFailed`),`error`),a(!1)}},I=e=>{x(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})};return(0,G.jsxs)(zd,{id:`card-spool-catalog`,children:[(0,G.jsxs)(Bd,{children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,G.jsx)(Gs,{className:`w-5 h-5 text-bambu-gray`}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`settings.catalog.spoolCatalog`)}),(0,G.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[`(`,n.length,`)`]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,G.jsxs)(`button`,{onClick:()=>{let r=n.map(({name:e,weight:t})=>({name:e,weight:t})),i=new Blob([JSON.stringify(r,null,2)],{type:`application/json`}),a=URL.createObjectURL(i),o=document.createElement(`a`);o.href=a,o.download=`spool-catalog.json`,document.body.appendChild(o),o.click(),document.body.removeChild(o),URL.revokeObjectURL(a),t(e(`settings.catalog.exported`,{count:n.length}),`success`)},className:`px-3 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray hover:text-white transition-colors flex items-center gap-1.5`,title:e(`settings.catalog.exportTooltip`),children:[(0,G.jsx)(Xs,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.export`)})]}),(0,G.jsxs)(`button`,{onClick:()=>c.current?.click(),className:`px-3 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray hover:text-white transition-colors flex items-center gap-1.5`,title:e(`settings.catalog.importTooltip`),children:[(0,G.jsx)(Vu,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.import`)})]}),(0,G.jsx)(`input`,{ref:c,type:`file`,accept:`.json`,className:`hidden`,onChange:async i=>{let a=i.target.files?.[0];if(a){try{let i=await a.text(),o=JSON.parse(i);if(!Array.isArray(o))throw Error(`Invalid format`);let s=0,c=0;for(let e of o){if(!e.name||typeof e.weight!=`number`){c++;continue}if(n.some(t=>t.name.toLowerCase()===e.name.toLowerCase())){c++;continue}try{let t=await Z.addCatalogEntry({name:e.name,weight:e.weight});r(e=>[...e,t].sort((e,t)=>e.name.localeCompare(t.name))),s++}catch(e){console.error(`SpoolCatalogSettings import item failed:`,e),c++}}t(e(`settings.catalog.imported`,{added:s,skipped:c}),`success`)}catch(n){console.error(`SpoolCatalogSettings.handleImport failed:`,n),t(e(`settings.catalog.importFailed`),`error`)}c.current&&(c.current.value=``)}}}),(0,G.jsxs)(`button`,{onClick:()=>D(!0),className:`px-3 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray hover:text-white transition-colors flex items-center gap-1.5`,title:e(`settings.catalog.resetTooltip`),children:[(0,G.jsx)(Wl,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.reset`)})]}),(0,G.jsxs)(`button`,{onClick:()=>u(!0),className:`px-3 py-1.5 text-sm bg-bambu-green text-white rounded-lg hover:bg-bambu-green/80 transition-colors flex items-center gap-1.5`,children:[(0,G.jsx)(Fl,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.add`)})]})]}),b.size>0&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mt-2 px-3 py-2 bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30 rounded-lg`,children:[(0,G.jsx)(`span`,{className:`text-sm text-red-700 dark:text-red-400`,children:e(`settings.catalog.selectedCount`,{count:b.size})}),(0,G.jsxs)(`button`,{onClick:()=>C(!0),className:`ml-auto px-3 py-1.5 text-sm bg-red-500 text-white rounded-lg hover:bg-red-600 transition-colors flex items-center gap-1.5`,children:[(0,G.jsx)(Pu,{className:`w-4 h-4`}),e(`settings.catalog.deleteSelected`)]}),(0,G.jsx)(`button`,{onClick:()=>x(new Set),className:`px-3 py-1.5 text-sm text-bambu-gray hover:text-white transition-colors`,children:e(`common.cancel`)})]})]}),(0,G.jsxs)(Vd,{className:`space-y-4`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`settings.catalog.spoolCatalogDescription`)}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(Ql,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,G.jsx)(`input`,{type:`text`,className:`w-full pl-10 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`,placeholder:e(`settings.catalog.searchCatalog`),value:o,onChange:e=>s(e.target.value)})]}),l&&(0,G.jsxs)(`div`,{className:`p-4 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,G.jsx)(`h3`,{className:`text-sm font-medium text-white mb-3`,children:e(`settings.catalog.addNewEntry`)}),(0,G.jsxs)(`div`,{className:`flex gap-2 items-center`,children:[(0,G.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,G.jsx)(`input`,{type:`text`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`,placeholder:e(`settings.catalog.namePlaceholder`),value:p,onChange:e=>m(e.target.value)})}),(0,G.jsx)(`input`,{type:`number`,className:`w-20 px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white text-center focus:border-bambu-green focus:outline-none`,placeholder:`g`,value:h,onChange:e=>g(e.target.value)}),(0,G.jsx)(`span`,{className:`text-bambu-gray shrink-0`,children:`g`}),(0,G.jsxs)(`button`,{onClick:A,disabled:_,className:`px-3 py-2 bg-bambu-green text-white rounded-lg hover:bg-bambu-green/80 flex items-center gap-1 shrink-0`,children:[_?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(fs,{className:`w-4 h-4`}),e(`common.add`)]}),(0,G.jsx)(`button`,{onClick:()=>{u(!1),m(``),g(``)},className:`p-2 rounded-lg text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary`,children:(0,G.jsx)(nd,{className:`w-4 h-4`})})]})]}),i?(0,G.jsxs)(`div`,{className:`flex items-center justify-center py-8 text-bambu-gray`,children:[(0,G.jsx)(Y,{className:`w-5 h-5 animate-spin mr-2`}),e(`common.loading`)]}):(0,G.jsx)(`div`,{className:`max-h-[600px] overflow-y-auto border border-bambu-dark-tertiary rounded-lg`,children:(0,G.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,G.jsx)(`thead`,{className:`bg-bambu-dark sticky top-0`,children:(0,G.jsxs)(`tr`,{children:[(0,G.jsx)(`th`,{className:`px-2 py-2 w-10`,children:(0,G.jsx)(`input`,{type:`checkbox`,checked:k.length>0&&b.size===k.length,onChange:()=>{b.size===k.length?x(new Set):x(new Set(k.map(e=>e.id)))},className:`w-4 h-4 accent-bambu-green cursor-pointer`})}),(0,G.jsx)(`th`,{className:`px-4 py-2 text-left text-bambu-gray font-medium`,children:e(`common.name`)}),(0,G.jsx)(`th`,{className:`px-4 py-2 text-right text-bambu-gray font-medium w-24`,children:e(`settings.catalog.weight`)}),(0,G.jsx)(`th`,{className:`px-4 py-2 text-center text-bambu-gray font-medium w-20`,children:e(`settings.catalog.type`)}),(0,G.jsx)(`th`,{className:`px-4 py-2 w-24`})]})}),(0,G.jsx)(`tbody`,{children:k.length===0?(0,G.jsx)(`tr`,{children:(0,G.jsx)(`td`,{colSpan:5,className:`px-4 py-8 text-center text-bambu-gray`,children:e(o?`settings.catalog.noMatch`:`settings.catalog.empty`)})}):k.map(t=>(0,G.jsx)(`tr`,{className:`border-t border-bambu-dark-tertiary hover:bg-bambu-dark ${b.has(t.id)?`bg-bambu-dark`:``}`,children:d===t.id?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`td`,{className:`px-2 py-2`,children:(0,G.jsx)(`input`,{type:`checkbox`,checked:b.has(t.id),onChange:()=>I(t.id),className:`w-4 h-4 accent-bambu-green cursor-pointer`})}),(0,G.jsx)(`td`,{className:`px-4 py-2`,children:(0,G.jsx)(`input`,{type:`text`,className:`w-full px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white focus:border-bambu-green focus:outline-none`,value:p,onChange:e=>m(e.target.value)})}),(0,G.jsx)(`td`,{className:`px-4 py-2`,children:(0,G.jsx)(`input`,{type:`number`,className:`w-full px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-right focus:border-bambu-green focus:outline-none`,value:h,onChange:e=>g(e.target.value)})}),(0,G.jsx)(`td`,{className:`px-4 py-2 text-center`,children:(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:`-`})}),(0,G.jsx)(`td`,{className:`px-4 py-2`,children:(0,G.jsxs)(`div`,{className:`flex justify-end gap-1`,children:[(0,G.jsx)(`button`,{onClick:()=>N(t.id),disabled:_,className:`p-1.5 rounded hover:bg-green-500/20 text-green-500`,children:_?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(fs,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:M,className:`p-1.5 rounded hover:bg-bambu-dark-tertiary text-bambu-gray`,children:(0,G.jsx)(nd,{className:`w-4 h-4`})})]})})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`td`,{className:`px-2 py-2`,children:(0,G.jsx)(`input`,{type:`checkbox`,checked:b.has(t.id),onChange:()=>I(t.id),className:`w-4 h-4 accent-bambu-green cursor-pointer`})}),(0,G.jsx)(`td`,{className:`px-4 py-2 text-white`,children:t.name}),(0,G.jsxs)(`td`,{className:`px-4 py-2 text-right font-mono text-white`,children:[t.weight,`g`]}),(0,G.jsx)(`td`,{className:`px-4 py-2 text-center`,children:t.is_default?(0,G.jsx)(`span`,{className:`text-xs px-2 py-0.5 rounded bg-bambu-dark-tertiary text-bambu-gray`,children:e(`settings.catalog.default`)}):(0,G.jsx)(`span`,{className:`text-xs px-2 py-0.5 rounded bg-bambu-green/20 text-bambu-green`,children:e(`settings.catalog.custom`)})}),(0,G.jsx)(`td`,{className:`px-4 py-2`,children:(0,G.jsxs)(`div`,{className:`flex justify-end gap-1`,children:[(0,G.jsx)(`button`,{onClick:()=>j(t),className:`p-1.5 rounded hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white`,children:(0,G.jsx)(Al,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:()=>T(t),className:`p-1.5 rounded bg-red-500/10 hover:bg-red-500/20 text-red-500`,children:(0,G.jsx)(Pu,{className:`w-4 h-4`})})]})})]})},t.id))})]})})]}),w&&(0,G.jsx)(of,{title:e(`settings.catalog.deleteEntry`),message:e(`settings.catalog.deleteConfirm`,{name:w.name}),confirmText:e(`common.delete`),variant:`danger`,onConfirm:P,onCancel:()=>T(null)}),S&&(0,G.jsx)(of,{title:e(`settings.catalog.deleteSelected`),message:e(`settings.catalog.bulkDeleteConfirm`,{count:b.size}),confirmText:e(`common.delete`),variant:`danger`,onConfirm:async()=>{if(C(!1),b.size!==0)try{let n=await Z.bulkDeleteCatalogEntries([...b]);r(e=>e.filter(e=>!b.has(e.id))),x(new Set),t(e(`settings.catalog.bulkDeleted`,{count:n.deleted}),`success`)}catch(n){console.error(`SpoolCatalogSettings.handleBulkDelete failed:`,n),t(e(`settings.catalog.bulkDeleteFailed`),`error`)}},onCancel:()=>C(!1)}),E&&(0,G.jsx)(of,{title:e(`settings.catalog.resetCatalog`),message:e(`settings.catalog.resetConfirm`),confirmText:e(`common.reset`),variant:`danger`,onConfirm:F,onCancel:()=>D(!1)})]})}function w8({rgba:e,extraColors:t,effectType:n,subtype:r,className:i=`w-5 h-5`,shape:a=`circle`,style:o,title:s,effectSize:c}){let l=(0,y.useMemo)(()=>yH(t),[t]),u=(0,y.useMemo)(()=>bH({effectSize:c,rgba:e,extraColors:t,effectType:n,subtype:r}),[c,e,t,n,r]),d=u.backgroundImage,f=u.backgroundSize,p=a===`circle`||a===`pill`?`rounded-full`:`rounded`,m=(()=>{if(!e)return;let t=e.replace(/^#/,``);return t.length>=8&&t.substring(6,8).toLowerCase()!==`ff`?`#${t.substring(0,8)}`:`#${t.substring(0,6)}`})(),h=s??(l.length>0?l.join(`, `):m);return(0,G.jsx)(`span`,{"data-testid":`filament-swatch`,className:`${i} ${p} border border-black/20 inline-block flex-shrink-0`,style:{backgroundImage:d,backgroundSize:f,...o},title:h})}function fGe(){let{t:e}=U(),{showToast:t}=qd(),[n,r]=(0,y.useState)([]),[i,a]=(0,y.useState)(!0),[o,s]=(0,y.useState)(``),[c,l]=(0,y.useState)(``),u=(0,y.useRef)(null),[d,f]=(0,y.useState)(!1),[p,m]=(0,y.useState)(null),[h,g]=(0,y.useState)(``),[_,v]=(0,y.useState)(``),[b,x]=(0,y.useState)(`#FFFFFF`),[S,C]=(0,y.useState)(``),[w,T]=(0,y.useState)(``),[E,D]=(0,y.useState)(``),[O,k]=(0,y.useState)(!1),[A,j]=(0,y.useState)(new Set),[M,N]=(0,y.useState)(!1),[P,F]=(0,y.useState)(!1),[I,L]=(0,y.useState)(null),[R,z]=(0,y.useState)(null),[B,V]=(0,y.useState)(!1),ee=(0,y.useCallback)(async()=>{try{r(await Z.getColorCatalog())}catch{t(e(`settings.colorCatalog.loadFailed`),`error`)}finally{a(!1)}},[t,e]);(0,y.useEffect)(()=>{ee()},[ee]);let te=[...new Set(n.map(e=>e.manufacturer))].sort(),ne=n.filter(e=>{let t=o===``||e.manufacturer.toLowerCase().includes(o.toLowerCase())||e.color_name.toLowerCase().includes(o.toLowerCase())||(e.material?.toLowerCase().includes(o.toLowerCase())??!1),n=c===``||e.manufacturer===c;return t&&n}),re=()=>{g(``),v(``),x(`#FFFFFF`),C(``),T(``),D(``)},ie=async()=>{if(!h.trim()||!_.trim()||!b){t(e(`settings.colorCatalog.fieldsRequired`),`error`);return}k(!0);try{let n=await Z.addColorEntry({manufacturer:h.trim(),color_name:_.trim(),hex_color:b,material:S.trim()||null,extra_colors:w.trim()||null,effect_type:E.trim()||null});r(e=>[...e,n].sort((e,t)=>e.manufacturer.localeCompare(t.manufacturer)||(e.material||``).localeCompare(t.material||``)||e.color_name.localeCompare(t.color_name))),f(!1),re(),t(e(`settings.colorCatalog.colorAdded`),`success`)}catch{t(e(`settings.colorCatalog.addFailed`),`error`)}finally{k(!1)}},ae=e=>{m(e.id),g(e.manufacturer),v(e.color_name),x(e.hex_color),C(e.material||``),T(e.extra_colors||``),D(e.effect_type||``)},oe=()=>{m(null),re()},se=async n=>{if(!h.trim()||!_.trim()||!b){t(e(`settings.colorCatalog.fieldsRequired`),`error`);return}k(!0);try{let i=await Z.updateColorEntry(n,{manufacturer:h.trim(),color_name:_.trim(),hex_color:b,material:S.trim()||null,extra_colors:w.trim()||null,effect_type:E.trim()||null});r(e=>e.map(e=>e.id===n?i:e).sort((e,t)=>e.manufacturer.localeCompare(t.manufacturer)||(e.material||``).localeCompare(t.material||``)||e.color_name.localeCompare(t.color_name))),m(null),re(),t(e(`settings.colorCatalog.colorUpdated`),`success`)}catch{t(e(`settings.colorCatalog.updateFailed`),`error`)}finally{k(!1)}},H=async()=>{if(R)try{await Z.deleteColorEntry(R.id),r(e=>e.filter(e=>e.id!==R.id)),t(e(`settings.colorCatalog.colorDeleted`),`success`)}catch{t(e(`settings.colorCatalog.deleteFailed`),`error`)}finally{z(null)}},ce=async()=>{V(!1),a(!0);try{await Z.resetColorCatalog(),await ee(),t(e(`settings.colorCatalog.resetSuccess`),`success`)}catch{t(e(`settings.colorCatalog.resetFailed`),`error`),a(!1)}},le=async()=>{F(!0),L(null);try{let n={},r=ud();r&&(n.Authorization=`Bearer ${r}`);let i=await fetch(`/api/v1/inventory/colors/sync`,{method:`POST`,headers:n});if(!i.ok)throw Error(`Failed to start sync`);let a=i.body?.getReader();if(!a)throw Error(`No response body`);let o=new TextDecoder,s=``;for(;;){let{done:n,value:r}=await a.read();if(n)break;s+=o.decode(r,{stream:!0});let i=s.split(` +`);s=i.pop()||``;for(let n of i)if(n.startsWith(`data: `))try{let r=JSON.parse(n.slice(6));r.type===`progress`?L({fetched:r.total_fetched,total:r.total_available}):r.type===`complete`?r.added===0?t(e(`settings.colorCatalog.syncUpToDate`,{count:r.total_fetched}),`success`):t(e(`settings.colorCatalog.syncComplete`,{added:r.added,skipped:r.skipped}),`success`):r.type===`error`&&t(`${e(`settings.colorCatalog.syncError`)}: ${r.error}`,`error`)}catch{}}await ee()}catch{t(e(`settings.colorCatalog.syncFailed`),`error`)}finally{F(!1),L(null)}},ue=e=>{j(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})};return(0,G.jsxs)(zd,{id:`card-color-catalog`,children:[(0,G.jsxs)(Bd,{children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,G.jsx)(wl,{className:`w-5 h-5 text-bambu-gray`}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`settings.colorCatalog.title`)}),(0,G.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[`(`,n.length,`)`]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,G.jsxs)(`button`,{onClick:()=>{let r=n.map(({manufacturer:e,color_name:t,hex_color:n,material:r,extra_colors:i,effect_type:a})=>({manufacturer:e,color_name:t,hex_color:n,material:r,extra_colors:i,effect_type:a})),i=new Blob([JSON.stringify(r,null,2)],{type:`application/json`}),a=URL.createObjectURL(i),o=document.createElement(`a`);o.href=a,o.download=`color-catalog.json`,document.body.appendChild(o),o.click(),document.body.removeChild(o),URL.revokeObjectURL(a),t(e(`settings.colorCatalog.exported`,{count:n.length}),`success`)},className:`px-3 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray hover:text-white transition-colors flex items-center gap-1.5`,children:[(0,G.jsx)(Xs,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.export`)})]}),(0,G.jsxs)(`button`,{onClick:()=>u.current?.click(),className:`px-3 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray hover:text-white transition-colors flex items-center gap-1.5`,children:[(0,G.jsx)(Vu,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.import`)})]}),(0,G.jsx)(`input`,{ref:u,type:`file`,accept:`.json`,className:`hidden`,onChange:async i=>{let a=i.target.files?.[0];if(a){try{let i=await a.text(),o=JSON.parse(i);if(!Array.isArray(o))throw Error(`Invalid format`);let s=0,c=0;for(let e of o){if(!e.manufacturer||!e.color_name||!e.hex_color){c++;continue}if(n.some(t=>t.manufacturer.toLowerCase()===e.manufacturer.toLowerCase()&&t.color_name.toLowerCase()===e.color_name.toLowerCase()&&(t.material||``).toLowerCase()===(e.material||``).toLowerCase())){c++;continue}try{let t=await Z.addColorEntry({manufacturer:e.manufacturer,color_name:e.color_name,hex_color:e.hex_color,material:e.material||null,extra_colors:e.extra_colors||null,effect_type:e.effect_type||null});r(e=>[...e,t].sort((e,t)=>e.manufacturer.localeCompare(t.manufacturer)||(e.material||``).localeCompare(t.material||``)||e.color_name.localeCompare(t.color_name))),s++}catch{c++}}t(e(`settings.colorCatalog.imported`,{added:s,skipped:c}),`success`)}catch{t(e(`settings.colorCatalog.importFailed`),`error`)}u.current&&(u.current.value=``)}}}),(0,G.jsxs)(`button`,{onClick:le,disabled:P,className:`px-3 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray hover:text-white transition-colors flex items-center gap-1.5`,title:e(`settings.colorCatalog.syncTooltip`),children:[P?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Ps,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:P?I?`${Math.min(I.fetched,I.total)} / ${I.total}`:e(`settings.colorCatalog.starting`):e(`settings.colorCatalog.sync`)})]}),(0,G.jsxs)(`button`,{onClick:()=>V(!0),className:`px-3 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray hover:text-white transition-colors flex items-center gap-1.5`,children:[(0,G.jsx)(Wl,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.reset`)})]}),(0,G.jsxs)(`button`,{onClick:()=>f(!0),className:`px-3 py-1.5 text-sm bg-bambu-green text-white rounded-lg hover:bg-bambu-green/80 transition-colors flex items-center gap-1.5`,children:[(0,G.jsx)(Fl,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.add`)})]})]}),A.size>0&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mt-2 px-3 py-2 bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30 rounded-lg`,children:[(0,G.jsx)(`span`,{className:`text-sm text-red-700 dark:text-red-400`,children:e(`settings.colorCatalog.selectedCount`,{count:A.size})}),(0,G.jsxs)(`button`,{onClick:()=>N(!0),className:`ml-auto px-3 py-1.5 text-sm bg-red-500 text-white rounded-lg hover:bg-red-600 transition-colors flex items-center gap-1.5`,children:[(0,G.jsx)(Pu,{className:`w-4 h-4`}),e(`settings.colorCatalog.deleteSelected`)]}),(0,G.jsx)(`button`,{onClick:()=>j(new Set),className:`px-3 py-1.5 text-sm text-bambu-gray hover:text-white transition-colors`,children:e(`common.cancel`)})]})]}),(0,G.jsxs)(Vd,{className:`space-y-4`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`settings.colorCatalog.description`)}),(0,G.jsxs)(`div`,{className:`flex gap-2 flex-wrap`,children:[(0,G.jsxs)(`div`,{className:`relative flex-1 min-w-[200px]`,children:[(0,G.jsx)(Ql,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,G.jsx)(`input`,{type:`text`,className:`w-full pl-10 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`,placeholder:e(`settings.colorCatalog.searchColors`),value:o,onChange:e=>s(e.target.value)})]}),(0,G.jsxs)(`select`,{className:`px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,value:c,onChange:e=>l(e.target.value),children:[(0,G.jsx)(`option`,{value:``,children:e(`settings.colorCatalog.allManufacturers`)}),te.map(e=>(0,G.jsx)(`option`,{value:e,children:e},e))]})]}),d&&(0,G.jsxs)(`div`,{className:`p-4 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,G.jsx)(`h3`,{className:`text-sm font-medium text-white mb-3`,children:e(`settings.colorCatalog.addNewColor`)}),(0,G.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-5 gap-2 items-end`,children:[(0,G.jsx)(`input`,{type:`text`,className:`px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`,placeholder:e(`settings.colorCatalog.manufacturer`),value:h,onChange:e=>g(e.target.value)}),(0,G.jsx)(`input`,{type:`text`,className:`px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`,placeholder:e(`settings.colorCatalog.colorName`),value:_,onChange:e=>v(e.target.value)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`input`,{type:`color`,className:`w-20 h-10 rounded cursor-pointer border border-bambu-dark-tertiary`,value:b,onChange:e=>x(e.target.value)}),(0,G.jsx)(`input`,{type:`text`,className:`w-32 px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`,placeholder:`#FFFFFF`,value:b,onChange:e=>x(e.target.value)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(`input`,{type:`text`,className:`flex-1 max-w-lg min-w-[200px] px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`,placeholder:e(`settings.colorCatalog.materialOptional`),value:S,onChange:e=>C(e.target.value)}),(0,G.jsxs)(`button`,{onClick:ie,disabled:O,className:`w-24 px-3 py-2 bg-bambu-green text-white rounded-lg hover:bg-bambu-green/80 flex items-center justify-center gap-3`,children:[O?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(fs,{className:`w-4 h-4`}),e(`common.add`)]}),(0,G.jsx)(`button`,{onClick:()=>{f(!1),re()},className:`p-2 ml-2 rounded-lg text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary`,children:(0,G.jsx)(nd,{className:`w-4 h-4`})})]})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-2 mt-2`,children:[(0,G.jsx)(`input`,{type:`text`,className:`px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white text-sm font-mono placeholder-bambu-gray focus:border-bambu-green focus:outline-none`,placeholder:e(`inventory.extraColorsPlaceholder`),value:w,onChange:e=>T(e.target.value)}),(0,G.jsx)(`select`,{className:`px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,value:E,onChange:e=>D(e.target.value),children:_H.map(t=>(0,G.jsx)(`option`,{value:t.value,children:e(t.labelKey)},t.value||`none`))})]})]}),(o||c)&&(0,G.jsx)(`div`,{className:`text-xs text-bambu-gray`,children:e(`settings.colorCatalog.showing`,{filtered:ne.length,total:n.length})}),i?(0,G.jsxs)(`div`,{className:`flex items-center justify-center py-8 text-bambu-gray`,children:[(0,G.jsx)(Y,{className:`w-5 h-5 animate-spin mr-2`}),e(`common.loading`)]}):(0,G.jsx)(`div`,{className:`max-h-[600px] overflow-auto border border-bambu-dark-tertiary rounded-lg`,children:(0,G.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,G.jsx)(`thead`,{className:`bg-bambu-dark sticky top-0`,children:(0,G.jsxs)(`tr`,{children:[(0,G.jsx)(`th`,{className:`px-2 py-2 w-10`,children:(0,G.jsx)(`input`,{type:`checkbox`,checked:ne.length>0&&A.size===ne.length,onChange:()=>{A.size===ne.length?j(new Set):j(new Set(ne.map(e=>e.id)))},className:`w-4 h-4 accent-bambu-green cursor-pointer`})}),(0,G.jsx)(`th`,{className:`px-3 py-2 text-left text-bambu-gray font-medium w-12`}),(0,G.jsx)(`th`,{className:`px-3 py-2 text-left text-bambu-gray font-medium`,children:e(`settings.colorCatalog.manufacturer`)}),(0,G.jsx)(`th`,{className:`px-3 py-2 text-left text-bambu-gray font-medium`,children:e(`inventory.material`)}),(0,G.jsx)(`th`,{className:`px-3 py-2 text-left text-bambu-gray font-medium`,children:e(`settings.colorCatalog.colorName`)}),(0,G.jsx)(`th`,{className:`px-3 py-2 text-left text-bambu-gray font-medium w-24`,children:e(`settings.colorCatalog.hex`)}),(0,G.jsx)(`th`,{className:`px-3 py-2 w-16`})]})}),(0,G.jsx)(`tbody`,{children:ne.length===0?(0,G.jsx)(`tr`,{children:(0,G.jsx)(`td`,{colSpan:7,className:`px-3 py-8 text-center text-bambu-gray`,children:e(o||c?`settings.colorCatalog.noMatch`:`settings.colorCatalog.empty`)})}):ne.map(t=>(0,G.jsxs)(y.Fragment,{children:[(0,G.jsx)(`tr`,{className:`border-t border-bambu-dark-tertiary hover:bg-bambu-dark ${A.has(t.id)?`bg-bambu-dark`:``}`,children:p===t.id?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`td`,{className:`px-2 py-2`,children:(0,G.jsx)(`input`,{type:`checkbox`,checked:A.has(t.id),onChange:()=>ue(t.id),className:`w-4 h-4 accent-bambu-green cursor-pointer`})}),(0,G.jsx)(`td`,{className:`px-3 py-2`,children:(0,G.jsx)(`input`,{type:`color`,className:`w-8 h-8 rounded cursor-pointer border border-bambu-dark-tertiary`,value:b,onChange:e=>x(e.target.value)})}),(0,G.jsx)(`td`,{className:`px-3 py-2`,children:(0,G.jsx)(`input`,{type:`text`,className:`w-full px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`,value:h,onChange:e=>g(e.target.value)})}),(0,G.jsx)(`td`,{className:`px-3 py-2`,children:(0,G.jsx)(`input`,{type:`text`,className:`w-full px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`,value:S,onChange:e=>C(e.target.value)})}),(0,G.jsx)(`td`,{className:`px-3 py-2`,children:(0,G.jsx)(`input`,{type:`text`,className:`w-full px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`,value:_,onChange:e=>v(e.target.value)})}),(0,G.jsx)(`td`,{className:`px-3 py-2`,children:(0,G.jsx)(`input`,{type:`text`,className:`w-full px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`,value:b,onChange:e=>x(e.target.value)})}),(0,G.jsx)(`td`,{className:`px-3 py-2`,children:(0,G.jsxs)(`div`,{className:`flex justify-end gap-1`,children:[(0,G.jsx)(`button`,{onClick:()=>se(t.id),disabled:O,className:`p-1.5 rounded hover:bg-green-500/20 text-green-500`,children:O?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(fs,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:oe,className:`p-1.5 rounded hover:bg-bambu-dark-tertiary text-bambu-gray`,children:(0,G.jsx)(nd,{className:`w-4 h-4`})})]})})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`td`,{className:`px-2 py-2`,children:(0,G.jsx)(`input`,{type:`checkbox`,checked:A.has(t.id),onChange:()=>ue(t.id),className:`w-4 h-4 accent-bambu-green cursor-pointer`})}),(0,G.jsx)(`td`,{className:`px-3 py-2`,children:(0,G.jsx)(w8,{rgba:t.hex_color.replace(/^#/,``)+(t.hex_color.length===7?`FF`:``),extraColors:t.extra_colors,effectType:t.effect_type,className:`w-8 h-8`,shape:`square`,title:t.hex_color,effectSize:`table`})}),(0,G.jsx)(`td`,{className:`px-3 py-2 text-white`,children:t.manufacturer}),(0,G.jsx)(`td`,{className:`px-3 py-2 text-bambu-gray`,children:t.material||`-`}),(0,G.jsx)(`td`,{className:`px-3 py-2 text-white`,children:t.color_name}),(0,G.jsx)(`td`,{className:`px-3 py-2 font-mono text-xs text-bambu-gray`,children:t.hex_color}),(0,G.jsx)(`td`,{className:`px-3 py-2`,children:(0,G.jsxs)(`div`,{className:`flex justify-end gap-1`,children:[(0,G.jsx)(`button`,{onClick:()=>ae(t),className:`p-1.5 rounded hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white`,children:(0,G.jsx)(Al,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:()=>z(t),className:`p-1.5 rounded bg-red-500/10 hover:bg-red-500/20 text-red-500`,children:(0,G.jsx)(Pu,{className:`w-4 h-4`})})]})})]})}),p===t.id&&(0,G.jsxs)(`tr`,{className:`border-t border-bambu-dark-tertiary/50 bg-bambu-dark`,children:[(0,G.jsx)(`td`,{colSpan:2}),(0,G.jsx)(`td`,{className:`px-3 py-2`,colSpan:2,children:(0,G.jsx)(`input`,{type:`text`,className:`w-full px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm font-mono focus:border-bambu-green focus:outline-none`,placeholder:e(`inventory.extraColorsPlaceholder`),value:w,onChange:e=>T(e.target.value)})}),(0,G.jsx)(`td`,{className:`px-3 py-2`,colSpan:2,children:(0,G.jsx)(`select`,{className:`w-full px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`,value:E,onChange:e=>D(e.target.value),children:_H.map(t=>(0,G.jsx)(`option`,{value:t.value,children:e(t.labelKey)},t.value||`none`))})}),(0,G.jsx)(`td`,{})]})]},t.id))})]})})]}),R&&(0,G.jsx)(of,{title:e(`settings.colorCatalog.deleteColor`),message:e(`settings.colorCatalog.deleteConfirm`,{name:`${R.manufacturer} - ${R.color_name}`}),confirmText:e(`common.delete`),variant:`danger`,onConfirm:H,onCancel:()=>z(null)}),M&&(0,G.jsx)(of,{title:e(`settings.colorCatalog.deleteSelected`),message:e(`settings.colorCatalog.bulkDeleteConfirm`,{count:A.size}),confirmText:e(`common.delete`),variant:`danger`,onConfirm:async()=>{if(N(!1),A.size!==0)try{let n=await Z.bulkDeleteColorEntries([...A]);r(e=>e.filter(e=>!A.has(e.id))),j(new Set),t(e(`settings.colorCatalog.bulkDeleted`,{count:n.deleted}),`success`)}catch{t(e(`settings.colorCatalog.bulkDeleteFailed`),`error`)}},onCancel:()=>N(!1)}),B&&(0,G.jsx)(of,{title:e(`settings.colorCatalog.resetCatalog`),message:e(`settings.colorCatalog.resetConfirm`),confirmText:e(`common.reset`),variant:`danger`,onConfirm:ce,onCancel:()=>V(!1)})]})}function pGe({link:e,onClose:t}){let{t:n}=U(),r=co(),i=!!e,a=(0,y.useRef)(null),[o,s]=(0,y.useState)(e?.name||``),[c,l]=(0,y.useState)(e?.url||``),[u,d]=(0,y.useState)(e?.icon||`link`),[f,p]=(0,y.useState)(e?.open_in_new_tab||!1),[m,h]=(0,y.useState)(!!e?.custom_icon),[g,_]=(0,y.useState)(e?.custom_icon?Z.getExternalLinkIconUrl(e.id):null),[v,b]=(0,y.useState)(null),[x,S]=(0,y.useState)(null);(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]);let C=q({mutationFn:async e=>{let t=await Z.createExternalLink(e);return v?await Z.uploadExternalLinkIcon(t.id,v):t},onSuccess:()=>{r.invalidateQueries({queryKey:[`external-links`]}),t()},onError:e=>{S(e.message)}}),w=q({mutationFn:async t=>{let n=await Z.updateExternalLink(e.id,t);return v?n=await Z.uploadExternalLinkIcon(e.id,v):!m&&e?.custom_icon&&(n=await Z.deleteExternalLinkIcon(e.id)),n},onSuccess:()=>{r.invalidateQueries({queryKey:[`external-links`]}),t()},onError:e=>{S(e.message)}}),T=e=>{let t=e.target.files?.[0];if(t){if(![`image/png`,`image/jpeg`,`image/gif`,`image/svg+xml`,`image/webp`,`image/x-icon`].includes(t.type)){S(`Please select a valid image file (PNG, JPG, GIF, SVG, WebP, or ICO)`);return}if(t.size>1024*1024){S(`Image file must be less than 1MB`);return}b(t),h(!0);let e=new FileReader;e.onload=e=>{_(e.target?.result)},e.readAsDataURL(t)}},E=()=>{b(null),_(null),h(!1),a.current&&(a.current.value=``)},D=e=>{if(e.preventDefault(),S(null),!o.trim()){S(`Name is required`);return}if(!c.trim()){S(`URL is required`);return}if(!c.startsWith(`http://`)&&!c.startsWith(`https://`)){S(`URL must start with http:// or https://`);return}let t={name:o.trim(),url:c.trim(),icon:u,open_in_new_tab:f};i?w.mutate(t):C.mutate(t)},O=C.isPending||w.isPending,k=uf(u);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`,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-3`,children:[(0,G.jsx)(`div`,{className:`p-2 rounded-full bg-bambu-green/20 text-bambu-green`,children:m&&g?(0,G.jsx)(`img`,{src:g,alt:``,className:`w-5 h-5 rounded`}):(0,G.jsx)(k,{className:`w-5 h-5`})}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i?`Edit Link`:`Add External Link`})]}),(0,G.jsx)(`button`,{onClick:t,className:`text-bambu-gray hover:text-white transition-colors`,children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]}),(0,G.jsxs)(`form`,{onSubmit:D,className:`p-6 space-y-4`,children:[x&&(0,G.jsx)(`div`,{className:`p-3 bg-red-100 dark:bg-red-500/20 border border-red-300 dark:border-red-500/50 rounded-lg text-sm text-red-700 dark:text-red-400`,children:x}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:`Name *`}),(0,G.jsx)(`input`,{type:`text`,value:o,onChange:e=>s(e.target.value),placeholder:`My Link`,maxLength:50,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:`URL *`}),(0,G.jsx)(`input`,{type:`text`,value:c,onChange:e=>l(e.target.value),placeholder:`https://example.com`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`label`,{className:`text-sm text-bambu-gray`,children:n(`externalLinks.openInNewTab`)}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>p(!f),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors ${f?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,children:(0,G.jsx)(`span`,{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${f?`translate-x-6`:`translate-x-1`}`})})]}),(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray`,children:`Icon`}),(0,G.jsxs)(`div`,{className:`p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,G.jsx)(`span`,{className:`text-sm text-white`,children:`Custom Icon`}),(0,G.jsx)(`input`,{ref:a,type:`file`,accept:`image/png,image/jpeg,image/gif,image/svg+xml,image/webp,image/x-icon`,className:`hidden`,onChange:T}),m&&g?(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`img`,{src:g,alt:`Custom icon`,className:`w-8 h-8 rounded border border-bambu-dark-tertiary`}),(0,G.jsx)(`button`,{type:`button`,onClick:E,className:`p-1 text-red-700 dark:text-red-400 hover:text-red-800 dark:hover:text-red-300 transition-colors`,title:`Remove custom icon`,children:(0,G.jsx)(Pu,{className:`w-4 h-4`})})]}):(0,G.jsxs)(Q,{type:`button`,variant:`secondary`,size:`sm`,onClick:()=>a.current?.click(),children:[(0,G.jsx)(Vu,{className:`w-4 h-4`}),`Upload`]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:`PNG, JPG, GIF, SVG, WebP, or ICO. Max 1MB.`})]}),!m&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray block mb-2`,children:`Or choose a preset icon`}),(0,G.jsx)(df,{value:u,onChange:d})]})]}),(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:`Cancel`}),(0,G.jsxs)(Q,{type:`submit`,disabled:O,className:`flex-1`,children:[O?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(ql,{className:`w-4 h-4`}),i?`Save`:`Add`]})]})]})]})})}function mGe(){let{t:e}=U(),t=co(),{authEnabled:n,hasPermission:r}=Nd(),{showToast:i}=qd(),[a,o]=(0,y.useState)(!1),[s,c]=(0,y.useState)(null),[l,u]=(0,y.useState)(null),[d,f]=(0,y.useState)(null),[p,m]=(0,y.useState)(null),[h,g]=(0,y.useState)(fm),[_,v]=(0,y.useState)(()=>um(mm.map(e=>e.id))),{data:b,isLoading:x}=K({queryKey:[`external-links`],queryFn:Z.getExternalLinks}),S=q({mutationFn:e=>Z.deleteExternalLink(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`external-links`]})}}),{data:C}=K({queryKey:[`settings`],queryFn:Z.getSettings,enabled:n&&r(`settings:update`)}),w=q({mutationFn:e=>Z.updateSettings({default_sidebar_order:e}),onSuccess:(n,r)=>{t.invalidateQueries({queryKey:[`settings`]}),t.invalidateQueries({queryKey:[`default-sidebar-order`]}),i(e(r?`settings.sidebarDefaultSet`:`settings.sidebarDefaultCleared`),`success`)},onError:()=>{i(e(`settings.sidebarDefaultFailed`),`error`)}}),T=(0,y.useMemo)(()=>{let e=new Map(mm.map(e=>[e.id,e])),t=new Map((b||[]).map(e=>[`ext-${e.id}`,e])),n=[],r=new Set,i=i=>{if(r.has(i))return;let a=e.get(i);if(a){n.push({type:`system`,id:i,navItem:a}),r.add(i);return}let o=t.get(i);o&&(n.push({type:`external`,id:i,link:o}),r.add(i))};return _.forEach(i),mm.forEach(e=>i(e.id)),(b||[]).forEach(e=>i(`ext-${e.id}`)),n},[b,_]),E=e=>{v(e),dm(e)},D=(e,t)=>{f(t),e.dataTransfer.effectAllowed=`move`,e.dataTransfer.setData(`text/plain`,t)},O=(e,t)=>{e.preventDefault(),e.dataTransfer.dropEffect=`move`,m(t)},k=(e,t)=>{if(e.preventDefault(),d===null||d===t){f(null),m(null);return}let n=T.map(e=>e.id),r=n.indexOf(d),i=n.indexOf(t);if(r===-1||i===-1){f(null),m(null);return}n.splice(r,1),n.splice(i,0,d),E(n),f(null),m(null)},A=()=>{f(null),m(null)},j=e=>{u(e)},M=()=>{l&&(S.mutate(l.id),u(null))},N=()=>{let e=[...mm.map(e=>e.id),...(b||[]).map(e=>`ext-${e.id}`)];g([]),v(e),pm([]),dm(e)},P=e=>{let t=T.map(e=>e.id);w.mutate(e?JSON.stringify({order:t,hiddenSystemItemIds:h}):``)},F=e=>{if(e===`settings`)return;let t=h.includes(e)?h.filter(t=>t!==e):[...h,e];g(t),pm(t)},I=n&&r(`settings:update`),L=!!C?.default_sidebar_order;return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(zd,{id:`card-sidebar-links`,children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-y-2 gap-x-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Xc,{className:`w-5 h-5 text-bambu-green`}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`externalLinks.sidebarLayout`)})]}),(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[I&&(0,G.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-bambu-gray`,children:[(0,G.jsx)(`span`,{children:e(`settings.setDefault`)}),(0,G.jsx)(fH,{checked:L,onChange:P,disabled:w.isPending})]}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:N,className:`whitespace-nowrap`,children:[(0,G.jsx)(Wl,{className:`w-4 h-4`}),e(`settings.reset`)]}),(0,G.jsxs)(Q,{size:`sm`,onClick:()=>o(!0),className:`whitespace-nowrap`,children:[(0,G.jsx)(Fl,{className:`w-4 h-4`}),`Add Link`]})]})]})}),(0,G.jsxs)(Vd,{children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4`,children:e(`externalLinks.sidebarLayoutDescription`)}),x?(0,G.jsx)(`div`,{className:`flex justify-center py-8`,children:(0,G.jsx)(Y,{className:`w-6 h-6 text-bambu-green animate-spin`})}):(0,G.jsx)(`div`,{className:`space-y-2`,children:T.map(t=>{let n=t.type===`system`&&h.includes(t.id),r=t.id===`settings`;if(t.type===`system`){let i=t.navItem.icon;return(0,G.jsxs)(`div`,{draggable:!0,onDragStart:e=>D(e,t.id),onDragOver:e=>O(e,t.id),onDragLeave:()=>m(null),onDrop:e=>k(e,t.id),onDragEnd:A,className:`relative flex items-center gap-3 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary transition-colors ${d===t.id?`opacity-50`:n?`opacity-60`:``} ${p===t.id&&d!==t.id?`before:absolute before:left-3 before:right-3 before:top-0 before:h-0.5 before:bg-bambu-green`:``}`,children:[(0,G.jsx)(jc,{className:`w-6 h-6 md:w-4 md:h-4 text-bambu-gray cursor-grab flex-shrink-0`}),(0,G.jsx)(`div`,{className:`p-2 rounded-lg bg-bambu-dark-tertiary text-bambu-gray`,children:(0,G.jsx)(i,{className:`w-4 h-4`})}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`span`,{className:`text-white font-medium truncate block`,children:e(t.navItem.labelKey)}),(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray truncate block`,children:e(r?`externalLinks.requiredInSidebar`:n?`externalLinks.hiddenFromSidebar`:`externalLinks.visibleInSidebar`)})]}),(0,G.jsx)(`button`,{onClick:()=>F(t.id),disabled:r,className:`p-2 rounded-lg hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white transition-colors flex-shrink-0 disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:bg-transparent disabled:hover:text-bambu-gray`,title:e(r?`externalLinks.settingsCannotBeHidden`:n?`externalLinks.showPage`:`externalLinks.hidePage`),"aria-label":e(r?`externalLinks.settingsCannotBeHidden`:n?`externalLinks.showPage`:`externalLinks.hidePage`),children:n?(0,G.jsx)(ic,{className:`w-4 h-4`}):(0,G.jsx)(ac,{className:`w-4 h-4`})})]},t.id)}let i=t.link,a=uf(i.icon);return(0,G.jsxs)(`div`,{draggable:!0,onDragStart:e=>D(e,t.id),onDragOver:e=>O(e,t.id),onDragLeave:()=>m(null),onDrop:e=>k(e,t.id),onDragEnd:A,className:`relative flex items-center gap-3 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary transition-colors ${d===t.id?`opacity-50`:``} ${p===t.id&&d!==t.id?`before:absolute before:left-3 before:right-3 before:top-0 before:h-0.5 before:bg-bambu-green`:``}`,children:[(0,G.jsx)(jc,{className:`w-6 h-6 md:w-4 md:h-4 text-bambu-gray cursor-grab flex-shrink-0`}),(0,G.jsx)(`div`,{className:`p-2 rounded-lg bg-bambu-dark-tertiary text-bambu-gray`,children:i.custom_icon?(0,G.jsx)(`img`,{src:Z.getExternalLinkIconUrl(i.id),alt:``,className:`w-4 h-4`}):(0,G.jsx)(a,{className:`w-4 h-4`})}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-white font-medium truncate`,children:i.name}),(0,G.jsx)(rc,{className:`w-3 h-3 text-bambu-gray flex-shrink-0`})]}),(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray truncate block`,children:i.url})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1 flex-shrink-0`,children:[(0,G.jsx)(`button`,{onClick:()=>c(i),className:`p-2 rounded-lg hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white transition-colors`,title:e(`common.edit`),children:(0,G.jsx)(Al,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:()=>j(i),disabled:S.isPending,className:`p-2 rounded-lg hover:bg-red-100 dark:hover:bg-red-500/20 text-bambu-gray hover:text-red-900 dark:hover:text-red-400 transition-colors disabled:opacity-50`,title:e(`externalLinks.deleteLink`),children:(0,G.jsx)(Pu,{className:`w-4 h-4`})})]})]},t.id)})})]})]}),(a||s)&&(0,G.jsx)(pGe,{link:s,onClose:()=>{o(!1),c(null)}}),l&&(0,G.jsx)(of,{title:`Delete Link`,message:`Are you sure you want to delete "${l.name}"? This action cannot be undone.`,confirmText:`Delete`,cancelText:`Cancel`,variant:`danger`,onConfirm:M,onCancel:()=>u(null)})]})}async function T8(e){if(navigator.clipboard&&window.isSecureContext)try{return await navigator.clipboard.writeText(e),!0}catch{}let t=document.createElement(`textarea`);t.value=e,t.style.position=`fixed`,t.style.opacity=`0`,document.body.appendChild(t);try{return t.select(),document.execCommand(`copy`)}catch{return!1}finally{t.parentNode&&t.parentNode.removeChild(t)}}function hGe(e,t,n=`text/plain`){let r=new Blob([e],{type:n}),i=URL.createObjectURL(r),a=document.createElement(`a`);a.href=i,a.download=t,document.body.appendChild(a),a.click(),a.remove(),URL.revokeObjectURL(i)}function gGe({status:e}){return e===`pass`?(0,G.jsx)(Ss,{className:`w-5 h-5 text-bambu-green flex-shrink-0`}):e===`fail`?(0,G.jsx)(Ds,{className:`w-5 h-5 text-red-600 dark:text-red-400 flex-shrink-0`}):e===`warn`?(0,G.jsx)(Lu,{className:`w-5 h-5 text-amber-600 dark:text-amber-400 flex-shrink-0`}):(0,G.jsx)(ws,{className:`w-5 h-5 text-bambu-gray flex-shrink-0`})}function _Ge({vpId:e,vpName:t,onClose:n}){let{t:r}=U(),i=q({mutationFn:()=>wd.diagnose(e)});(0,y.useEffect)(()=>{i.mutate()},[]),(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[n]);let a=i.data,o=a?.overall===`ok`?`bg-bambu-green/10 border-bambu-green/30 text-bambu-green`:a?.overall===`warnings`?`bg-amber-50 dark:bg-amber-500/10 border-amber-300 dark:border-amber-500/30 text-amber-700 dark:text-amber-300`:`bg-red-50 dark:bg-red-500/10 border-red-300 dark:border-red-500/30 text-red-700 dark:text-red-300`;return(0,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-lg flex flex-col max-h-[85vh]`,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)(Su,{className:`w-5 h-5 text-bambu-green flex-shrink-0`}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white truncate`,children:r(`vpDiagnostic.title`,{name:t})})]}),(0,G.jsx)(`button`,{onClick:n,className:`text-bambu-gray hover:text-white transition-colors`,title:r(`common.close`),children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]}),(0,G.jsxs)(`div`,{className:`p-6 space-y-4 overflow-y-auto`,children:[i.isPending&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray`,children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),(0,G.jsx)(`span`,{children:r(`vpDiagnostic.running`)})]}),i.isError&&(0,G.jsx)(`div`,{className:`rounded-lg bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30 px-4 py-3 text-sm text-red-700 dark:text-red-300`,children:r(`vpDiagnostic.runFailed`,{error:i.error.message})}),a&&(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsx)(`ol`,{className:`space-y-2`,children:a.checks.map(e=>{let t=r(`vpDiagnostic.check.${e.id}.${e.status}`,{...e.params,defaultValue:``});return(0,G.jsxs)(`li`,{className:`flex items-start gap-3 bg-bambu-dark rounded-lg px-4 py-2.5 ${e.status===`skip`?`opacity-60`:``}`,children:[(0,G.jsx)(`div`,{className:`mt-0.5`,children:(0,G.jsx)(gGe,{status:e.status})}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`div`,{className:`text-sm text-white`,children:r(`vpDiagnostic.check.${e.id}.title`,e.params)}),t&&(0,G.jsx)(`div`,{className:`text-xs text-bambu-gray mt-0.5`,children:t})]})]},e.id)})}),(0,G.jsx)(`div`,{className:`rounded-lg border px-4 py-3 text-sm ${o}`,children:r(`vpDiagnostic.overall.${a.overall}`)})]})]}),(0,G.jsxs)(`div`,{className:`px-6 py-4 border-t border-bambu-dark-tertiary flex justify-end gap-2`,children:[(0,G.jsx)(`button`,{onClick:()=>i.mutate(),disabled:i.isPending,className:`px-4 py-2 bg-bambu-dark hover:bg-bambu-dark-tertiary disabled:opacity-50 text-white text-sm rounded-lg transition-colors`,children:r(`vpDiagnostic.retry`)}),(0,G.jsx)(`button`,{onClick:n,className:`px-4 py-2 bg-bambu-green hover:bg-bambu-green/90 text-white text-sm rounded-lg transition-colors`,children:r(`common.close`)})]})]})})}var E8={archive:`archive`,review:`review`,queue:`queue`,proxy:`proxy`};function D8(e){return e===`immediate`?`archive`:e===`print_queue`||e===`queue`?`queue`:e===`archive`||e===`review`||e===`proxy`?e:`archive`}function vGe({printer:e,models:t}){let{t:n}=U(),r=co(),{showToast:i}=qd(),[a,o]=(0,y.useState)(!0),[s,c]=(0,y.useState)(e.enabled),[l,u]=(0,y.useState)(e.name),[d,f]=(0,y.useState)(``),[p,m]=(0,y.useState)(D8(e.mode)),[h,g]=(0,y.useState)(e.target_printer_id),[_,v]=(0,y.useState)(e.bind_ip||``),[b,x]=(0,y.useState)(e.remote_interface_ip||``),[S,C]=(0,y.useState)(e.model||``),[w,T]=(0,y.useState)(e.auto_dispatch??!0),[E,D]=(0,y.useState)(e.queue_force_color_match??!1),[O,k]=(0,y.useState)(e.save_ams_mapping??!1),[A,j]=(0,y.useState)(e.gcode_injection??!1),[M,N]=(0,y.useState)(e.tailscale_disabled??!0),[P,F]=(0,y.useState)(!1),[I,L]=(0,y.useState)(null),[R,z]=(0,y.useState)(!1),[B,V]=(0,y.useState)(!1),[ee,te]=(0,y.useState)(!1),{data:ne}=K({queryKey:[`tailscale-status`],queryFn:wd.getTailscaleStatus,enabled:!M,staleTime:6e4}),re=ne?.available?ne.fqdn:``,ie=ne?.available?ne.tailscale_ips?.[0]??``:``,ae=async e=>{e.stopPropagation();let t=re;t&&(await T8(t)?(te(!0),i(n(`printers.copied`)),setTimeout(()=>te(!1),2e3)):i(n(`virtualPrinter.toast.copyFailed`),`error`))};(0,y.useEffect)(()=>{I||(c(e.enabled),m(D8(e.mode)),u(e.name),g(e.target_printer_id),v(e.bind_ip||``),x(e.remote_interface_ip||``),C(e.model||``),T(e.auto_dispatch??!0),D(e.queue_force_color_match??!1),k(e.save_ams_mapping??!1),j(e.gcode_injection??!1),N(e.tailscale_disabled??!0))},[e,I]);let{data:oe}=K({queryKey:[`printers`],queryFn:Z.getPrinters}),{data:se}=K({queryKey:[`network-interfaces`],queryFn:()=>Z.getNetworkInterfaces().then(e=>e.interfaces)}),H=q({mutationFn:t=>wd.update(e.id,t),onSuccess:()=>{r.invalidateQueries({queryKey:[`virtual-printers`]}),i(n(`virtualPrinter.toast.updated`)),L(null)},onError:t=>{i(t.message||n(`virtualPrinter.toast.failedToUpdate`),`error`),c(e.enabled),m(D8(e.mode)),g(e.target_printer_id),v(e.bind_ip||``),N(e.tailscale_disabled??!0),D(e.queue_force_color_match??!1),k(e.save_ams_mapping??!1),j(e.gcode_injection??!1),L(null)}}),ce=q({mutationFn:()=>wd.remove(e.id),onSuccess:()=>{r.invalidateQueries({queryKey:[`virtual-printers`]}),i(n(`virtualPrinter.toast.deleted`)),z(!1)},onError:e=>{i(e.message||n(`virtualPrinter.toast.failedToDelete`),`error`),z(!1)}}),le=t=>{t.stopPropagation();let r=!s;if(r){if(!_){i(n(`virtualPrinter.toast.bindIpRequired`),`error`);return}if(p===`proxy`){if(!h){i(n(`virtualPrinter.toast.targetPrinterRequired`),`error`);return}}else if(!d&&!e.access_code_set){i(n(`virtualPrinter.toast.accessCodeRequired`),`error`);return}}c(r),L(`toggle`),H.mutate({enabled:r})},ue=()=>{l.trim()&&(L(`name`),H.mutate({name:l.trim()}))},de=()=>{if(!d){i(n(`virtualPrinter.toast.accessCodeEmpty`),`error`);return}if(d.length!==8){i(n(`virtualPrinter.toast.accessCodeLength`),`error`);return}L(`accessCode`),H.mutate({access_code:d}),f(``)},fe=e=>{m(e),L(`mode`),H.mutate({mode:e})},pe=e=>{C(e),L(`model`),H.mutate({model:e})},me=e=>{let t=ve?.access_code,r=oe?.find(t=>t.id===e)?.access_code;g(e),L(`targetPrinter`),H.mutate({target_printer_id:e},{onSuccess:()=>{t&&r&&t!==r&&i(n(`virtualPrinter.toast.targetCodeChangedRebind`),`info`)}})},he=e=>{x(e),L(`remoteInterface`),H.mutate({remote_interface_ip:e})},ge=e.status?.running||!1,_e=n(`virtualPrinter.mode.${E8[p]||`archive`}`),ve=oe?.find(e=>e.id===h),ye=ve?.name,be=!!h,xe=be?ve?.access_code??``:``;return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(zd,{className:`overflow-hidden`,children:[(0,G.jsxs)(`div`,{className:`px-4 py-3 flex items-center gap-3 cursor-pointer select-none`,onClick:()=>o(!a),children:[(0,G.jsx)(`button`,{className:`text-bambu-gray flex-shrink-0`,children:a?(0,G.jsx)(ps,{className:`w-4 h-4`}):(0,G.jsx)(ms,{className:`w-4 h-4`})}),(0,G.jsx)(`span`,{className:`w-2 h-2 rounded-full flex-shrink-0 ${ge?`bg-green-400 animate-pulse`:`bg-gray-500`}`}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0 flex flex-wrap items-center gap-x-3 gap-y-1`,children:[(0,G.jsx)(`span`,{className:`text-white font-medium truncate max-w-full`,children:e.name}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray flex-shrink-0`,children:_e}),e.model_name&&(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray flex-shrink-0`,children:e.model_name}),ye&&(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray truncate max-w-full`,children:[p===`proxy`&&(0,G.jsx)(Ro,{className:`w-3 h-3 inline mr-1`}),ye]}),_&&(0,G.jsx)(`span`,{className:`text-[10px] text-bambu-gray flex-shrink-0 font-mono`,children:_}),b&&(0,G.jsx)(`span`,{className:`text-[10px] text-bambu-gray flex-shrink-0 font-mono`,children:b})]}),(0,G.jsx)(`div`,{className:`ml-auto flex items-center gap-2 flex-shrink-0`,onClick:e=>e.stopPropagation(),children:(0,G.jsx)(`button`,{onClick:le,disabled:I===`toggle`,className:`relative w-10 h-5 rounded-full transition-colors ${s?`bg-bambu-green`:`bg-bambu-dark-tertiary`} ${I===`toggle`?`opacity-50`:``}`,children:(0,G.jsx)(`span`,{className:`absolute top-0.5 left-0.5 w-4 h-4 bg-white rounded-full transition-transform ${s?`translate-x-5`:``}`})})})]}),a&&(0,G.jsxs)(Vd,{className:`pt-0 space-y-4`,children:[(0,G.jsx)(`div`,{className:`border-t border-bambu-dark-tertiary`}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`input`,{type:`text`,value:l,onChange:e=>u(e.target.value),onBlur:ue,onKeyDown:e=>e.key===`Enter`&&ue(),className:`flex-1 text-sm text-white bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-1.5 focus:border-bambu-green focus:outline-none`}),(0,G.jsx)(`button`,{onClick:()=>V(!0),className:`p-1.5 text-bambu-gray hover:text-bambu-green transition-colors flex-shrink-0`,title:n(`vpDiagnostic.runButton`),children:(0,G.jsx)(Su,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:()=>z(!0),className:`p-1.5 text-bambu-gray hover:text-red-600 dark:hover:text-red-400 transition-colors flex-shrink-0`,title:n(`common.delete`),children:(0,G.jsx)(Pu,{className:`w-4 h-4`})})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 -mt-2`,children:[re&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-green-700/80 dark:text-green-400/70 min-w-0`,children:[(0,G.jsx)(au,{className:`w-3.5 h-3.5 flex-shrink-0`}),(0,G.jsx)(`span`,{className:`font-mono text-xs truncate`,children:ie?`${ie} (${re})`:re}),(0,G.jsx)(`button`,{onClick:ae,className:`p-0.5 rounded hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white transition-colors flex-shrink-0`,title:n(ee?`printers.copied`:`printers.copyToClipboard`),children:ee?(0,G.jsx)(fs,{className:`w-3.5 h-3.5 text-bambu-green`}):(0,G.jsx)(Vs,{className:`w-3.5 h-3.5`})})]}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray font-mono ml-auto flex-shrink-0`,children:e.serial})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`div`,{className:`text-white text-sm font-medium mb-2`,children:n(`virtualPrinter.mode.title`)}),(0,G.jsx)(`div`,{className:`grid grid-cols-2 gap-2`,children:[`archive`,`review`,`queue`,`proxy`].map(e=>(0,G.jsxs)(`button`,{onClick:()=>fe(e),disabled:I===`mode`,className:`p-2 rounded-lg border text-left transition-colors ${p===e?e===`proxy`?`border-blue-500 bg-blue-500/10`:`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary hover:border-bambu-gray`}`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 text-white text-xs font-medium`,children:[e===`proxy`&&(0,G.jsx)(Ro,{className:`w-3 h-3`}),n(`virtualPrinter.mode.${E8[e]}`)]}),(0,G.jsx)(`div`,{className:`text-[10px] text-bambu-gray`,children:n(`virtualPrinter.mode.${E8[e]}Desc`)})]},e))})]}),p===`queue`&&(0,G.jsx)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsx)(`div`,{className:`text-white text-sm font-medium`,children:n(`virtualPrinter.autoDispatch.title`)}),(0,G.jsx)(`div`,{className:`text-[10px] text-bambu-gray`,children:n(`virtualPrinter.autoDispatch.description`)})]}),(0,G.jsx)(`button`,{onClick:()=>{let e=!w;T(e),L(`autoDispatch`),H.mutate({auto_dispatch:e})},disabled:I===`autoDispatch`,className:`relative w-10 h-5 rounded-full transition-colors flex-shrink-0 ${w?`bg-bambu-green`:`bg-bambu-dark-tertiary`} ${I===`autoDispatch`?`opacity-50`:``}`,children:(0,G.jsx)(`span`,{className:`absolute top-0.5 left-0.5 w-4 h-4 bg-white rounded-full transition-transform ${w?`translate-x-5`:``}`})})]})}),p===`queue`&&(0,G.jsx)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsx)(`div`,{className:`text-white text-sm font-medium`,children:n(`virtualPrinter.queueForceColorMatch.title`)}),(0,G.jsx)(`div`,{className:`text-[10px] text-bambu-gray`,children:n(`virtualPrinter.queueForceColorMatch.description`)})]}),(0,G.jsx)(`button`,{onClick:()=>{let e=!E;D(e),L(`queueForceColorMatch`),H.mutate({queue_force_color_match:e})},disabled:I===`queueForceColorMatch`,className:`relative w-10 h-5 rounded-full transition-colors flex-shrink-0 ${E?`bg-bambu-green`:`bg-bambu-dark-tertiary`} ${I===`queueForceColorMatch`?`opacity-50`:``}`,children:(0,G.jsx)(`span`,{className:`absolute top-0.5 left-0.5 w-4 h-4 bg-white rounded-full transition-transform ${E?`translate-x-5`:``}`})})]})}),p===`queue`&&(0,G.jsx)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsx)(`div`,{className:`text-white text-sm font-medium`,children:n(`virtualPrinter.saveAmsMapping.title`)}),(0,G.jsx)(`div`,{className:`text-[10px] text-bambu-gray`,children:n(`virtualPrinter.saveAmsMapping.description`)})]}),(0,G.jsx)(`button`,{onClick:()=>{let e=!O;k(e),L(`saveAmsMapping`),H.mutate({save_ams_mapping:e})},disabled:I===`saveAmsMapping`,className:`relative w-10 h-5 rounded-full transition-colors flex-shrink-0 ${O?`bg-bambu-green`:`bg-bambu-dark-tertiary`} ${I===`saveAmsMapping`?`opacity-50`:``}`,children:(0,G.jsx)(`span`,{className:`absolute top-0.5 left-0.5 w-4 h-4 bg-white rounded-full transition-transform ${O?`translate-x-5`:``}`})})]})}),p===`queue`&&(0,G.jsx)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsx)(`div`,{className:`text-white text-sm font-medium`,children:n(`virtualPrinter.gcodeInjection.title`)}),(0,G.jsx)(`div`,{className:`text-[10px] text-bambu-gray`,children:n(`virtualPrinter.gcodeInjection.description`)})]}),(0,G.jsx)(`button`,{onClick:()=>{let e=!A;j(e),L(`gcodeInjection`),H.mutate({gcode_injection:e})},disabled:I===`gcodeInjection`,className:`relative w-10 h-5 rounded-full transition-colors flex-shrink-0 ${A?`bg-bambu-green`:`bg-bambu-dark-tertiary`} ${I===`gcodeInjection`?`opacity-50`:``}`,children:(0,G.jsx)(`span`,{className:`absolute top-0.5 left-0.5 w-4 h-4 bg-white rounded-full transition-transform ${A?`translate-x-5`:``}`})})]})}),(0,G.jsx)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsx)(`div`,{className:`text-white text-sm font-medium`,children:n(`virtualPrinter.tailscaleDisabled.title`)}),(0,G.jsx)(`div`,{className:`text-[10px] text-bambu-gray`,children:n(`virtualPrinter.tailscaleDisabled.description`)})]}),(0,G.jsx)(`button`,{onClick:()=>{let e=!M;N(e),L(`tailscaleDisabled`),H.mutate({tailscale_disabled:e})},disabled:I===`tailscaleDisabled`,className:`relative w-10 h-5 rounded-full transition-colors shrink-0 ${M?`bg-bambu-dark-tertiary`:`bg-bambu-green`} ${I===`tailscaleDisabled`?`opacity-50`:``}`,children:(0,G.jsx)(`span`,{className:`absolute top-0.5 left-0.5 w-4 h-4 bg-white rounded-full transition-transform ${M?``:`translate-x-5`}`})})]})}),p!==`proxy`&&(0,G.jsxs)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:[(0,G.jsx)(`div`,{className:`text-white text-sm font-medium mb-1`,children:n(`virtualPrinter.model.title`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:n(`virtualPrinter.model.description`)}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(`select`,{value:S,onChange:e=>pe(e.target.value),disabled:I===`model`,className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-1.5 text-white text-sm appearance-none cursor-pointer disabled:opacity-50 pr-10`,children:Object.entries(t).map(([e,t])=>(0,G.jsxs)(`option`,{value:e,children:[t,` (`,e,`)`]},e))}),(0,G.jsx)(ps,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]})]}),p===`proxy`&&(0,G.jsx)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:(0,G.jsxs)(`div`,{className:`flex items-start gap-2 p-2 rounded bg-blue-50 border border-blue-300 dark:bg-blue-500/10 dark:border-blue-500/30`,children:[(0,G.jsx)(Wc,{className:`w-4 h-4 text-blue-600 dark:text-blue-400 flex-shrink-0 mt-0.5`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`virtualPrinter.proxy.accessCodeHint`)})]})}),p!==`proxy`&&(0,G.jsxs)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,G.jsx)(`div`,{className:`text-white text-sm font-medium`,children:n(`virtualPrinter.accessCode.title`)}),be?(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-xs text-blue-700 dark:text-blue-400`,children:[(0,G.jsx)(Wc,{className:`w-3 h-3`}),n(`virtualPrinter.accessCode.inheritedFromTarget`)]}):e.access_code_set?(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-xs text-green-700 dark:text-green-400`,children:[(0,G.jsx)(fs,{className:`w-3 h-3`}),n(`virtualPrinter.accessCode.isSet`)]}):(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-xs text-yellow-700 dark:text-yellow-400`,children:[(0,G.jsx)(Lu,{className:`w-3 h-3`}),n(`virtualPrinter.accessCode.notSet`)]})]}),be?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(`input`,{type:P?`text`:`password`,value:xe,readOnly:!0,"aria-label":n(`virtualPrinter.accessCode.title`),className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-1.5 text-white text-sm pr-10 font-mono opacity-90 cursor-default`}),(0,G.jsx)(`button`,{onClick:()=>F(!P),className:`absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white`,"aria-label":n(P?`virtualPrinter.accessCode.hide`:`virtualPrinter.accessCode.reveal`),children:P?(0,G.jsx)(ic,{className:`w-4 h-4`}):(0,G.jsx)(ac,{className:`w-4 h-4`})})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(`virtualPrinter.accessCode.derivedFromTargetHint`)})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsxs)(`div`,{className:`relative flex-1`,children:[(0,G.jsx)(`input`,{type:P?`text`:`password`,value:d,onChange:e=>f(e.target.value),placeholder:e.access_code_set?n(`virtualPrinter.accessCode.placeholderChange`):n(`virtualPrinter.accessCode.placeholder`),maxLength:8,className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-1.5 text-white text-sm placeholder-bambu-gray pr-10 font-mono`}),(0,G.jsx)(`button`,{onClick:()=>F(!P),className:`absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white`,children:P?(0,G.jsx)(ic,{className:`w-4 h-4`}):(0,G.jsx)(ac,{className:`w-4 h-4`})})]}),(0,G.jsx)(Q,{onClick:de,disabled:!d||I===`accessCode`,variant:`primary`,children:I===`accessCode`?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):n(`common.save`)})]}),d&&(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:(0,G.jsx)(`span`,{className:d.length===8?`text-green-700 dark:text-green-400`:`text-yellow-700 dark:text-yellow-400`,children:n(`virtualPrinter.accessCode.charCount`,{count:d.length})})})]})]}),(0,G.jsxs)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:[(0,G.jsx)(`div`,{className:`text-white text-sm font-medium mb-2`,children:n(`virtualPrinter.targetPrinter.title`)}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsxs)(`select`,{value:h??``,onChange:e=>{let t=parseInt(e.target.value,10);isNaN(t)||me(t)},disabled:I===`targetPrinter`,className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-1.5 text-white text-sm appearance-none cursor-pointer disabled:opacity-50 pr-10`,children:[(0,G.jsx)(`option`,{value:``,children:n(`virtualPrinter.targetPrinter.placeholder`)}),oe?.map(e=>(0,G.jsxs)(`option`,{value:e.id,children:[e.name,` (`,e.ip_address,`)`]},e.id))]}),(0,G.jsx)(ps,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]})]}),(0,G.jsxs)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:[(0,G.jsx)(`div`,{className:`text-white text-sm font-medium mb-1`,children:n(`virtualPrinter.bindIp.title`)}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsxs)(`select`,{value:_,onChange:e=>{v(e.target.value),L(`bindIp`),H.mutate({bind_ip:e.target.value})},disabled:I===`bindIp`,className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-1.5 text-white text-sm appearance-none cursor-pointer disabled:opacity-50 pr-10`,children:[(0,G.jsx)(`option`,{value:``,children:n(`virtualPrinter.bindIp.placeholder`)}),se?.map(e=>(0,G.jsxs)(`option`,{value:e.ip,children:[e.name,` (`,e.ip,`)`,e.is_alias?` [alias]`:``,` - `,e.subnet]},e.ip))]}),(0,G.jsx)(ps,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(`virtualPrinter.bindIp.hint`)})]}),(0,G.jsxs)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,G.jsx)(`div`,{className:`text-white text-sm font-medium`,children:n(`virtualPrinter.remoteInterface.title`)}),b?(0,G.jsx)(`span`,{className:`flex items-center gap-1 text-xs text-green-700 dark:text-green-400`,children:(0,G.jsx)(fs,{className:`w-3 h-3`})}):(0,G.jsx)(`span`,{className:`flex items-center gap-1 text-xs text-bambu-gray`,title:n(`virtualPrinter.remoteInterface.optional`),children:(0,G.jsx)(Wc,{className:`w-3 h-3`})})]}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsxs)(`select`,{value:b,onChange:e=>he(e.target.value),disabled:I===`remoteInterface`,className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-1.5 text-white text-sm appearance-none cursor-pointer disabled:opacity-50 pr-10`,children:[(0,G.jsx)(`option`,{value:``,children:n(`virtualPrinter.remoteInterface.placeholder`)}),se?.map(e=>(0,G.jsxs)(`option`,{value:e.ip,children:[e.name,` (`,e.ip,`) - `,e.subnet]},e.ip))]}),(0,G.jsx)(ps,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]})]})]})]}),R&&(0,G.jsx)(of,{title:n(`virtualPrinter.deleteConfirm.title`),message:n(`virtualPrinter.deleteConfirm.message`,{name:e.name}),variant:`danger`,confirmText:n(`common.delete`),isLoading:ce.isPending,onConfirm:()=>ce.mutate(),onCancel:()=>z(!1)}),B&&(0,G.jsx)(_Ge,{vpId:e.id,vpName:e.name,onClose:()=>V(!1)})]})}var O8={archive:`archive`,review:`review`,queue:`queue`,proxy:`proxy`};function yGe({onClose:e}){let{t}=U(),n=co(),{showToast:r}=qd(),[i,a]=(0,y.useState)(``),[o,s]=(0,y.useState)(`archive`),[c,l]=(0,y.useState)(null),{data:u}=K({queryKey:[`printers`],queryFn:Z.getPrinters}),d=q({mutationFn:()=>wd.create({name:i.trim()||`Bambuddy`,mode:o,target_printer_id:o===`proxy`?c??void 0:void 0}),onSuccess:()=>{n.invalidateQueries({queryKey:[`virtual-printers`]}),r(t(`virtualPrinter.toast.created`)),e()},onError:e=>{r(e.message||t(`virtualPrinter.toast.failedToCreate`),`error`)}});return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,onClick:e,children:(0,G.jsx)(zd,{className:`w-full max-w-md`,onClick:e=>e.stopPropagation(),children:(0,G.jsxs)(Vd,{className:`p-6 space-y-4`,children:[(0,G.jsx)(`h3`,{className:`text-lg font-semibold text-white`,children:t(`virtualPrinter.addDialog.title`)}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`text-sm text-white font-medium block mb-1`,children:t(`virtualPrinter.addDialog.name`)}),(0,G.jsx)(`input`,{type:`text`,value:i,onChange:e=>a(e.target.value),placeholder:`Bambuddy`,className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-2 text-white text-sm placeholder-bambu-gray`,autoFocus:!0})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`text-sm text-white font-medium block mb-1`,children:t(`virtualPrinter.mode.title`)}),(0,G.jsx)(`div`,{className:`grid grid-cols-2 gap-2`,children:[`archive`,`review`,`queue`,`proxy`].map(e=>(0,G.jsxs)(`button`,{onClick:()=>s(e),className:`p-2 rounded-lg border text-left transition-colors ${o===e?e===`proxy`?`border-blue-500 bg-blue-500/10`:`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary hover:border-bambu-gray`}`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 text-white text-xs font-medium`,children:[e===`proxy`&&(0,G.jsx)(Ro,{className:`w-3 h-3`}),t(`virtualPrinter.mode.${O8[e]}`)]}),(0,G.jsx)(`div`,{className:`text-[10px] text-bambu-gray`,children:t(`virtualPrinter.mode.${O8[e]}Desc`)})]},e))})]}),o===`proxy`&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`text-sm text-white font-medium block mb-1`,children:t(`virtualPrinter.targetPrinter.title`)}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsxs)(`select`,{value:c??``,onChange:e=>{let t=parseInt(e.target.value,10);l(isNaN(t)?null:t)},className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-2 text-white text-sm appearance-none cursor-pointer pr-10`,children:[(0,G.jsx)(`option`,{value:``,children:t(`virtualPrinter.targetPrinter.placeholder`)}),u?.map(e=>(0,G.jsxs)(`option`,{value:e.id,children:[e.name,` (`,e.ip_address,`)`]},e.id))]}),(0,G.jsx)(ps,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:t(`virtualPrinter.addDialog.hint`)}),(0,G.jsxs)(`div`,{className:`flex gap-3 pt-2`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:e,className:`flex-1`,disabled:d.isPending,children:t(`common.cancel`)}),(0,G.jsx)(Q,{variant:`primary`,onClick:()=>d.mutate(),className:`flex-1`,disabled:d.isPending,children:d.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):t(`virtualPrinter.addDialog.create`)})]})]})})})}function bGe(){let{t:e}=U(),t=co(),{showToast:n}=qd(),[r,i]=(0,y.useState)(!1),{data:a,isLoading:o}=K({queryKey:[`virtual-printers`],queryFn:wd.list,refetchInterval:1e4}),{data:s}=K({queryKey:[`virtual-printer-settings`],queryFn:Cd.getSettings}),c=q({mutationFn:e=>Cd.updateSettings({archive_name_source:e}),onSuccess:()=>{t.invalidateQueries({queryKey:[`virtual-printer-settings`]}),n(e(`virtualPrinter.toast.updated`))},onError:t=>{n(t.message||e(`virtualPrinter.toast.failedToUpdate`),`error`)}}),l=s?.archive_name_source===`filename`,{data:u}=K({queryKey:[`vp-ca-certificate`],queryFn:wd.getCaCertificate,staleTime:1/0}),[d,f]=(0,y.useState)(!1),p=async()=>{u&&(await T8(u.pem)?(f(!0),n(e(`virtualPrinter.caCert.copied`)),setTimeout(()=>f(!1),2e3)):n(e(`virtualPrinter.toast.copyFailed`),`error`))},m=()=>{u&&hGe(u.pem,`bambuddy-virtual-printer-ca.crt`,`application/x-pem-file`)};if(o)return(0,G.jsx)(zd,{children:(0,G.jsx)(Vd,{className:`py-8 flex justify-center`,children:(0,G.jsx)(Y,{className:`w-6 h-6 animate-spin text-bambu-green`})})});let h=a?.printers||[],g=a?.models||{};return(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-3 gap-4 items-stretch`,children:[(0,G.jsx)(zd,{className:`border-l-4 border-l-yellow-500`,children:(0,G.jsx)(Vd,{className:`py-3 px-4`,children:(0,G.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,G.jsx)(Lu,{className:`w-4 h-4 text-yellow-500 flex-shrink-0 mt-0.5`}),(0,G.jsxs)(`div`,{className:`text-xs`,children:[(0,G.jsx)(`p`,{className:`text-white font-medium`,children:e(`virtualPrinter.setupRequired.title`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:e(`virtualPrinter.setupRequired.description`)}),(0,G.jsxs)(`a`,{href:`https://wiki.bambuddy.cool/features/virtual-printer/`,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center gap-1.5 mt-2 px-3 py-1.5 bg-yellow-100 dark:bg-yellow-500/20 border border-yellow-500/50 rounded text-yellow-700 dark:text-yellow-400 hover:bg-yellow-500/30 transition-colors text-xs`,children:[(0,G.jsx)(rc,{className:`w-3 h-3`}),e(`virtualPrinter.setupRequired.readGuide`)]})]})]})})}),(0,G.jsx)(zd,{className:`lg:col-span-2`,children:(0,G.jsx)(Vd,{className:`py-3 px-4`,children:(0,G.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,G.jsx)(Wc,{className:`w-4 h-4 text-blue-600 dark:text-blue-400 flex-shrink-0 mt-0.5`}),(0,G.jsxs)(`div`,{className:`text-xs text-bambu-gray`,children:[(0,G.jsx)(`p`,{className:`text-white font-medium mb-1`,children:e(`virtualPrinter.howItWorks.title`)}),(0,G.jsxs)(`ul`,{className:`space-y-1 list-disc list-inside`,children:[(0,G.jsx)(`li`,{children:e(`virtualPrinter.howItWorks.step1`)}),(0,G.jsx)(`li`,{children:e(`virtualPrinter.howItWorks.step2`)}),(0,G.jsx)(`li`,{children:e(`virtualPrinter.howItWorks.step3`)})]})]})]})})})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-4 items-stretch`,children:[(0,G.jsx)(zd,{children:(0,G.jsx)(Vd,{className:`py-3 px-4`,children:(0,G.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,G.jsx)(au,{className:`w-4 h-4 text-bambu-green flex-shrink-0 mt-1`}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,G.jsx)(`p`,{className:`text-sm text-white font-medium`,children:e(`virtualPrinter.caCert.title`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[(0,G.jsxs)(`button`,{onClick:p,disabled:!u,className:`inline-flex items-center gap-1.5 px-2.5 py-1 text-xs rounded bg-bambu-dark-secondary border border-bambu-dark-tertiary text-white hover:border-bambu-gray disabled:opacity-50 transition-colors`,children:[d?(0,G.jsx)(fs,{className:`w-3.5 h-3.5 text-bambu-green`}):(0,G.jsx)(Vs,{className:`w-3.5 h-3.5`}),e(d?`virtualPrinter.caCert.copied`:`virtualPrinter.caCert.copy`)]}),(0,G.jsxs)(`button`,{onClick:m,disabled:!u,className:`inline-flex items-center gap-1.5 px-2.5 py-1 text-xs rounded bg-bambu-dark-secondary border border-bambu-dark-tertiary text-white hover:border-bambu-gray disabled:opacity-50 transition-colors`,children:[(0,G.jsx)(Xs,{className:`w-3.5 h-3.5`}),e(`virtualPrinter.caCert.download`)]})]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`virtualPrinter.caCert.description`)}),u&&(0,G.jsxs)(`p`,{className:`text-[10px] text-bambu-gray font-mono mt-1 truncate`,title:u.fingerprint_sha256,children:[e(`virtualPrinter.caCert.fingerprint`),`: `,u.fingerprint_sha256]})]})]})})}),(0,G.jsx)(zd,{children:(0,G.jsx)(Vd,{className:`py-3 px-4`,children:(0,G.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,G.jsx)(fc,{className:`w-4 h-4 text-bambu-green flex-shrink-0 mt-1`}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,G.jsx)(`p`,{className:`text-sm text-white font-medium`,children:e(`virtualPrinter.archiveNameSource.title`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[(0,G.jsx)(`span`,{className:`text-xs ${l?`text-bambu-gray`:`text-white`}`,children:e(`virtualPrinter.archiveNameSource.metadata`)}),(0,G.jsx)(fH,{checked:l,onChange:e=>c.mutate(e?`filename`:`metadata`),disabled:c.isPending}),(0,G.jsx)(`span`,{className:`text-xs ${l?`text-white`:`text-bambu-gray`}`,children:e(`virtualPrinter.archiveNameSource.filename`)})]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`virtualPrinter.archiveNameSource.description`)})]})]})})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Rl,{className:`w-5 h-5 text-bambu-green`}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`virtualPrinter.list.title`)}),(0,G.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[`(`,h.length,`)`]})]}),(0,G.jsxs)(Q,{variant:`primary`,onClick:()=>i(!0),children:[(0,G.jsx)(Fl,{className:`w-4 h-4 mr-1`}),e(`virtualPrinter.list.add`)]})]}),h.length===0?(0,G.jsx)(zd,{children:(0,G.jsxs)(Vd,{className:`py-8 text-center`,children:[(0,G.jsx)(Rl,{className:`w-12 h-12 text-bambu-gray mx-auto mb-3`}),(0,G.jsx)(`p`,{className:`text-bambu-gray mb-4`,children:e(`virtualPrinter.list.empty`)}),(0,G.jsxs)(Q,{variant:`primary`,onClick:()=>i(!0),children:[(0,G.jsx)(Fl,{className:`w-4 h-4 mr-1`}),e(`virtualPrinter.list.addFirst`)]})]})}):(0,G.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-4 items-start`,children:h.map(e=>(0,G.jsx)(vGe,{printer:e,models:g},e.id))}),r&&(0,G.jsx)(yGe,{onClose:()=>i(!1)})]})}function k8(e){if(e<60)return`${e}s`;let t=Math.floor(e/60);if(t<60)return`${t}m`;let n=Math.floor(t/60),r=t%60;if(n<24)return r?`${n}h ${r}m`:`${n}h`;let i=Math.floor(n/24),a=n%24;return a?`${i}d ${a}h`:`${i}d`}function A8(e){return e==null?`—`:e>=1024?`${(e/1024).toFixed(1)} GB`:`${Math.round(e)} MB`}function xGe({device:e,onUnregister:t,isDeleting:n}){let{t:r}=U(),{showToast:i}=qd(),a=e.system_stats,o=a?.memory,s=a?.disk,c=e.online,[l,u]=(0,y.useState)(null),[d,f]=(0,y.useState)(null),p=async t=>{f(t);try{t===`update`?await Od.triggerUpdate(e.device_id):await Od.systemCommand(e.device_id,t),i(r(`settings.spoolbuddy.commandQueued`),`success`)}catch(e){i(e instanceof Error?e.message:r(`settings.spoolbuddy.commandError`),`error`)}finally{f(null),u(null)}},m=[{key:`update`,label:r(`settings.spoolbuddy.update`),icon:Xs},{key:`restart_browser`,label:r(`settings.spoolbuddy.restartBrowser`),icon:gl},{key:`restart_daemon`,label:r(`settings.spoolbuddy.restartDaemon`),icon:Hl},{key:`reboot`,label:r(`settings.spoolbuddy.reboot`),icon:Gl},{key:`shutdown`,label:r(`settings.spoolbuddy.shutdown`),icon:Ll,variant:`danger`}],h={update:r(`settings.spoolbuddy.updateConfirmTitle`),restart_browser:r(`settings.spoolbuddy.restartBrowserConfirmTitle`),restart_daemon:r(`settings.spoolbuddy.restartDaemonConfirmTitle`),reboot:r(`settings.spoolbuddy.rebootConfirmTitle`),shutdown:r(`settings.spoolbuddy.shutdownConfirmTitle`)},g={update:r(`settings.spoolbuddy.updateConfirmBody`,{hostname:e.hostname}),restart_browser:r(`settings.spoolbuddy.restartBrowserConfirmBody`,{hostname:e.hostname}),restart_daemon:r(`settings.spoolbuddy.restartDaemonConfirmBody`,{hostname:e.hostname}),reboot:r(`settings.spoolbuddy.rebootConfirmBody`,{hostname:e.hostname}),shutdown:r(`settings.spoolbuddy.shutdownConfirmBody`,{hostname:e.hostname})};return(0,G.jsxs)(zd,{children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`div`,{className:`flex items-start justify-between gap-3 flex-wrap`,children:[(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`h3`,{className:`text-base font-semibold text-white truncate`,children:e.hostname}),(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-medium ${c?`bg-green-500/15 text-green-400 border border-green-500/40`:`bg-gray-500/15 text-gray-400 border border-gray-500/40`}`,children:[c?(0,G.jsx)(Qu,{className:`w-3 h-3`}):(0,G.jsx)(Zu,{className:`w-3 h-3`}),r(c?`settings.spoolbuddy.online`:`settings.spoolbuddy.offline`)]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray font-mono mt-1 truncate`,children:e.device_id})]}),(0,G.jsxs)(Q,{variant:`danger`,size:`sm`,onClick:()=>t(e),disabled:n,"aria-label":r(`settings.spoolbuddy.unregister`),children:[(0,G.jsx)(Pu,{className:`w-3.5 h-3.5`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:r(`settings.spoolbuddy.unregister`)})]})]})}),(0,G.jsxs)(Vd,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{className:`grid grid-cols-2 sm:grid-cols-4 gap-3 text-xs`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`div`,{className:`text-bambu-gray`,children:r(`settings.spoolbuddy.ipAddress`)}),(0,G.jsx)(`div`,{className:`text-white font-mono`,children:e.ip_address})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`div`,{className:`text-bambu-gray`,children:r(`settings.spoolbuddy.firmware`)}),(0,G.jsx)(`div`,{className:`text-white`,children:e.firmware_version??`—`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`text-bambu-gray flex items-center gap-1`,children:[(0,G.jsx)(js,{className:`w-3 h-3`}),r(`settings.spoolbuddy.lastSeen`)]}),(0,G.jsx)(`div`,{className:`text-white`,children:e.last_seen?up(e.last_seen):r(`settings.spoolbuddy.never`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`div`,{className:`text-bambu-gray`,children:r(`settings.spoolbuddy.daemonUptime`)}),(0,G.jsx)(`div`,{className:`text-white`,children:k8(e.uptime_s)})]})]}),(0,G.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:m.map(({key:e,label:t,icon:n,variant:r})=>(0,G.jsxs)(Q,{variant:r??`secondary`,size:`sm`,onClick:()=>u(e),disabled:!c||d!==null,"aria-label":t,children:[d===e?(0,G.jsx)(Y,{className:`w-3.5 h-3.5 animate-spin`}):(0,G.jsx)(n,{className:`w-3.5 h-3.5`}),(0,G.jsx)(`span`,{children:t})]},e))}),(0,G.jsxs)(`div`,{className:`flex items-center gap-3 text-xs flex-wrap`,children:[(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-bambu-gray`,children:[e.nfc_ok?(0,G.jsx)(Ss,{className:`w-3.5 h-3.5 text-green-400`}):(0,G.jsx)(Ds,{className:`w-3.5 h-3.5 text-red-400`}),r(`settings.spoolbuddy.nfc`),e.nfc_reader_type&&(0,G.jsxs)(`span`,{className:`text-bambu-gray/70`,children:[`(`,e.nfc_reader_type,`)`]})]}),(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-bambu-gray`,children:[e.scale_ok?(0,G.jsx)(Ss,{className:`w-3.5 h-3.5 text-green-400`}):(0,G.jsx)(Ds,{className:`w-3.5 h-3.5 text-red-400`}),r(`settings.spoolbuddy.scale`)]})]}),a&&(0,G.jsxs)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-3 text-xs`,children:[a.cpu_temp_c!==void 0&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Mu,{className:`w-3.5 h-3.5 text-bambu-gray`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`div`,{className:`text-bambu-gray`,children:r(`settings.spoolbuddy.cpuTemp`)}),(0,G.jsxs)(`div`,{className:`text-white`,children:[a.cpu_temp_c.toFixed(1),`°C`]})]})]}),a.load_avg&&a.load_avg.length>0&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Mo,{className:`w-3.5 h-3.5 text-bambu-gray`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`div`,{className:`text-bambu-gray`,children:r(`settings.spoolbuddy.cpuLoad`)}),(0,G.jsxs)(`div`,{className:`text-white`,children:[a.load_avg[0].toFixed(2),a.cpu_count?` / ${a.cpu_count} (${Math.round(a.load_avg[0]/a.cpu_count*100)}%)`:``]})]})]}),o&&o.percent!==void 0&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Hs,{className:`w-3.5 h-3.5 text-bambu-gray`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`div`,{className:`text-bambu-gray`,children:r(`settings.spoolbuddy.memory`)}),(0,G.jsxs)(`div`,{className:`text-white`,children:[o.percent.toFixed(0),`% (`,A8(o.used_mb),` / `,A8(o.total_mb),`)`]})]})]}),s&&s.percent!==void 0&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Pc,{className:`w-3.5 h-3.5 text-bambu-gray`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`div`,{className:`text-bambu-gray`,children:r(`settings.spoolbuddy.disk`)}),(0,G.jsxs)(`div`,{className:`text-white`,children:[s.percent.toFixed(0),`% (`,s.used_gb?.toFixed(1),` / `,s.total_gb?.toFixed(1),` GB)`]})]})]}),a.system_uptime_s!==void 0&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(js,{className:`w-3.5 h-3.5 text-bambu-gray`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`div`,{className:`text-bambu-gray`,children:r(`settings.spoolbuddy.systemUptime`)}),(0,G.jsx)(`div`,{className:`text-white`,children:k8(a.system_uptime_s)})]})]})]}),a.os&&(0,G.jsx)(`div`,{className:`mt-3 text-xs text-bambu-gray font-mono truncate`,children:[a.os.os,a.os.kernel,a.os.arch,a.os.python&&`Python ${a.os.python}`].filter(Boolean).join(` · `)})]})]}),l&&(0,G.jsx)(of,{variant:l===`shutdown`||l===`reboot`?`danger`:`default`,title:h[l],message:g[l],confirmText:r(`settings.spoolbuddy.commandConfirm`),isLoading:d!==null,onConfirm:()=>p(l),onCancel:()=>u(null)})]})}function SGe(){let{t:e}=U(),t=co(),{showToast:n}=qd(),[r,i]=(0,y.useState)(null),{data:a=[],isLoading:o}=K({queryKey:[`spoolbuddy-devices`],queryFn:()=>Od.getDevices(),refetchInterval:15e3}),s=q({mutationFn:e=>Od.deleteDevice(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`spoolbuddy-devices`]}),n(e(`settings.spoolbuddy.unregisterSuccess`),`success`),i(null)},onError:t=>{n(t.message||e(`settings.spoolbuddy.unregisterError`),`error`)}});if(o)return(0,G.jsx)(zd,{children:(0,G.jsx)(Vd,{className:`py-8 flex justify-center`,children:(0,G.jsx)(Y,{className:`w-6 h-6 animate-spin text-bambu-green`})})});let c=a.length>1;return(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsx)(zd,{children:(0,G.jsx)(Vd,{className:`py-3 px-4`,children:(0,G.jsxs)(`div`,{className:`flex items-start gap-2 text-xs`,children:[(0,G.jsx)(Wc,{className:`w-4 h-4 text-blue-400 flex-shrink-0 mt-0.5`}),(0,G.jsxs)(`div`,{className:`text-bambu-gray`,children:[(0,G.jsx)(`p`,{className:`text-white font-medium mb-1`,children:e(`settings.spoolbuddy.infoTitle`)}),(0,G.jsx)(`p`,{children:e(`settings.spoolbuddy.infoBody`)})]})]})})}),c&&(0,G.jsx)(zd,{className:`border-l-4 border-l-yellow-500`,children:(0,G.jsx)(Vd,{className:`py-3 px-4`,children:(0,G.jsxs)(`div`,{className:`flex items-start gap-2 text-xs`,children:[(0,G.jsx)(Lu,{className:`w-4 h-4 text-yellow-500 flex-shrink-0 mt-0.5`}),(0,G.jsxs)(`div`,{className:`text-bambu-gray`,children:[(0,G.jsx)(`p`,{className:`text-white font-medium mb-1`,children:e(`settings.spoolbuddy.duplicatesTitle`,{count:a.length})}),(0,G.jsx)(`p`,{children:e(`settings.spoolbuddy.duplicatesBody`)})]})]})})}),a.length===0?(0,G.jsx)(zd,{children:(0,G.jsx)(Vd,{className:`py-8 text-center text-bambu-gray text-sm`,children:e(`settings.spoolbuddy.empty`)})}):(0,G.jsx)(`div`,{className:`space-y-3`,children:a.map(e=>(0,G.jsx)(xGe,{device:e,onUnregister:i,isDeleting:s.isPending&&s.variables===e.device_id},e.id))}),r&&(0,G.jsx)(of,{variant:`danger`,title:e(`settings.spoolbuddy.confirmTitle`),message:e(`settings.spoolbuddy.confirmBody`,{hostname:r.hostname,deviceId:r.device_id}),confirmText:e(`settings.spoolbuddy.unregister`),isLoading:s.isPending,onConfirm:()=>s.mutate(r.device_id),onCancel:()=>i(null)})]})}function j8(e,t,n,r,i){return n?e(`backup.restoreFromGit.${t}.${n}`,{...r??{},defaultValue:i??n}):i}var M8=[{id:`archives`,labelKey:`backup.printArchives`,icon:(0,G.jsx)(Po,{className:`w-4 h-4`})},{id:`spools`,labelKey:`backup.spoolInventory`,icon:(0,G.jsx)(wl,{className:`w-4 h-4`})},{id:`settings`,labelKey:`backup.appSettings`,icon:(0,G.jsx)(ru,{className:`w-4 h-4`})},{id:`kprofiles`,labelKey:`backup.kProfiles`,icon:(0,G.jsx)(Mu,{className:`w-4 h-4`})}],N8=Object.fromEntries(M8.map(e=>[e.id,e.labelKey])),P8=`HEAD`;function CGe({onClose:e}){let{t}=U(),n=co(),[r,i]=(0,y.useState)(P8),[a,o]=(0,y.useState)({}),[s,c]=(0,y.useState)(!1),[l,u]=(0,y.useState)(!1),[d,f]=(0,y.useState)(null),p=K({queryKey:[`github-backup-commits`],queryFn:()=>Z.getGitHubBackupCommits(20)}),m=K({queryKey:[`github-restore-preview`,r],queryFn:()=>Z.getGitHubRestorePreview(r)}),h=m.data?.success?m.data.ref:r,g=(0,y.useMemo)(()=>{let e={};return m.data?.categories?.forEach(n=>{e[n.category]={available:n.available,itemCount:n.item_count,detail:j8(t,`details`,n.detail_code,n.detail_params,n.detail)}}),e},[m.data,t]),_=(0,y.useMemo)(()=>M8.filter(e=>a[e.id]&&g[e.id]?.available).map(e=>e.id),[a,g]),v=_.length,b=!s&&_.includes(`kprofiles`),x=q({mutationFn:()=>Z.restoreFromGitHub({ref:h,categories:_,overwrite_existing:s}),onSuccess:e=>{u(!1);let t=Object.keys(e.results??{}).length>0;(e.success||t)&&(f(e),n.invalidateQueries({queryKey:[`spools`]}),n.invalidateQueries({queryKey:[`archives`]}),n.invalidateQueries({queryKey:[`settings`]})),n.invalidateQueries({queryKey:[`github-backup-logs`]}),n.invalidateQueries({queryKey:[`github-backup-status`]})},onError:()=>u(!1)}),S=x.isPending,C=!!(d&&`settings`in d.results),w=(0,y.useCallback)(()=>{if(C){window.location.reload();return}e()},[C,e]);(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&!S&&!l&&w()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[w,S,l]),(0,y.useEffect)(()=>{if(!S)return;let e=e=>{e.preventDefault(),e.returnValue=``};return window.addEventListener(`beforeunload`,e),()=>window.removeEventListener(`beforeunload`,e)},[S]),(0,y.useEffect)(()=>{m.data&&o(e=>{let t={};return M8.forEach(n=>{t[n.id]=!!e[n.id]&&!!g[n.id]?.available}),t})},[m.data,g]);let T=p.data?.commits??[],E=(e,t,n)=>{let r=(t||``).split(` +`)[0],i=n?new Date(n).toLocaleString():``;return`${e.slice(0,7)} — ${i}${r?` — ${r}`:``}`},D=e=>e.isError?e.error?.message||t(`backup.restoreFromGit.loadFailed`):null,O=D(m)??(m.data&&!m.data.success?m.data.message:null),k=D(p)??(p.data&&!p.data.success?p.data.message:null);return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,onClick:S?void 0:w,children:(0,G.jsx)(zd,{className:`w-full max-w-lg`,onClick:e=>e.stopPropagation(),children:(0,G.jsxs)(Vd,{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-3`,children:[(0,G.jsx)(`div`,{className:`p-2 rounded-full bg-bambu-green/20 text-bambu-green`,children:(0,G.jsx)(Wl,{className:`w-5 h-5`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`text-lg font-semibold text-white`,children:t(`backup.restoreFromGit.title`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:t(`backup.restoreFromGit.subtitle`)})]})]}),(0,G.jsx)(`button`,{onClick:w,disabled:S,"aria-label":t(`common.close`),className:`p-2 hover:bg-bambu-dark-tertiary rounded-lg transition-colors disabled:opacity-50`,children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]}),d?(0,G.jsxs)(`div`,{className:`p-4 space-y-3 max-h-[400px] overflow-y-auto`,children:[(0,G.jsxs)(`div`,{className:`flex items-start gap-2 text-sm`,children:[d.success?(0,G.jsx)(Ss,{className:`w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0`}):(0,G.jsx)(Lu,{className:`w-4 h-4 text-yellow-500 mt-0.5 flex-shrink-0`}),(0,G.jsx)(`span`,{className:`text-white`,children:d.message})]}),!d.success&&(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:t(`backup.restoreFromGit.partialHint`)}),Object.entries(d.results).map(([e,n])=>(0,G.jsxs)(`div`,{className:`p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`span`,{className:`text-sm font-medium text-white`,children:N8[e]?t(N8[e]):e}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:t(`backup.restoreFromGit.tally`,{restored:n.restored,skipped:n.skipped,failed:n.failed})})]}),n.notes.length>0&&(0,G.jsx)(`ul`,{className:`mt-2 space-y-1`,children:n.notes.map(e=>(0,G.jsxs)(`li`,{className:`text-xs text-bambu-gray flex items-start gap-1.5`,children:[(0,G.jsx)(Wc,{className:`w-3 h-3 mt-0.5 flex-shrink-0`}),(0,G.jsx)(`span`,{children:j8(t,`notes`,e.code,e.params,e.message)})]},`${e.code}:${JSON.stringify(e.params)}`))})]},e)),(0,G.jsx)(`div`,{className:`p-3 rounded-lg bg-yellow-50 dark:bg-yellow-500/10 border border-yellow-300 dark:border-yellow-500/30`,children:(0,G.jsx)(`p`,{className:`text-xs text-yellow-700 dark:text-yellow-200`,children:t(`backup.restoreFromGit.reloadHint`)})})]}):(0,G.jsxs)(`div`,{className:`p-4 space-y-4 max-h-[400px] overflow-y-auto ${S?`opacity-50 pointer-events-none`:``}`,children:[x.isError&&(0,G.jsx)(`div`,{className:`p-3 rounded-lg bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30`,children:(0,G.jsx)(`p`,{className:`text-sm text-red-700 dark:text-red-400`,children:x.error?.message||t(`backup.restoreFromGit.failed`)})}),x.data&&!x.data.success&&(0,G.jsx)(`div`,{className:`p-3 rounded-lg bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30`,children:(0,G.jsx)(`p`,{className:`text-sm text-red-700 dark:text-red-400`,children:x.data.message})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{htmlFor:`restore-commit`,className:`block text-sm font-medium text-white mb-1`,children:t(`backup.restoreFromGit.commitLabel`)}),(0,G.jsxs)(`select`,{id:`restore-commit`,value:r,onChange:e=>{i(e.target.value),x.reset()},disabled:S||p.isLoading,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`,children:[(0,G.jsx)(`option`,{value:P8,children:t(`backup.restoreFromGit.latestCommit`)}),T.map(e=>(0,G.jsx)(`option`,{value:e.sha,children:E(e.sha,e.message,e.date)},e.sha))]}),k&&(0,G.jsx)(`p`,{className:`mt-1 text-xs text-red-500 dark:text-red-400`,children:k})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm font-medium text-white mb-2`,children:t(`backup.restoreFromGit.categoriesLabel`)}),m.isLoading?(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-bambu-gray p-3`,children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),t(`backup.restoreFromGit.inspecting`)]}):O?(0,G.jsx)(`div`,{className:`p-3 rounded-lg bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30`,children:(0,G.jsx)(`p`,{className:`text-sm text-red-700 dark:text-red-400`,children:O})}):(0,G.jsx)(`div`,{className:`space-y-2`,children:M8.map(e=>{let n=g[e.id],r=!!n?.available,i=!!a[e.id]&&r;return(0,G.jsxs)(`label`,{className:`flex items-center gap-3 p-3 rounded-lg transition-colors ${r?`cursor-pointer`:`cursor-not-allowed opacity-50`} ${i?`bg-bambu-green/10 border border-bambu-green/30`:`bg-bambu-dark hover:bg-bambu-dark-tertiary border border-transparent`}`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:i,disabled:!r||S,onChange:()=>o(t=>({...t,[e.id]:!t[e.id]})),className:`w-4 h-4 rounded border-bambu-gray bg-bambu-dark text-bambu-green focus:ring-bambu-green focus:ring-offset-0`}),(0,G.jsx)(`div`,{className:i?`text-bambu-green`:`text-bambu-gray`,children:e.icon}),(0,G.jsxs)(`div`,{className:`flex-1`,children:[(0,G.jsxs)(`div`,{className:`text-white text-sm font-medium`,children:[t(e.labelKey),r&&n?.itemCount?(0,G.jsx)(`span`,{className:`ml-2 text-xs text-bambu-gray`,children:t(`backup.restoreFromGit.itemCount`,{count:n.itemCount})}):null]}),n?.detail&&(0,G.jsx)(`div`,{className:`text-xs text-bambu-gray`,children:n.detail}),e.id===`kprofiles`&&i&&b&&(0,G.jsx)(`div`,{className:`text-xs text-yellow-700 dark:text-yellow-200`,children:t(`backup.restoreFromGit.kprofilesOverwriteCaveat`)})]})]},e.id)})})]}),(0,G.jsx)(`div`,{className:`p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm font-medium text-white`,children:t(`backup.restoreFromGit.overwriteLabel`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:t(s?`backup.restoreFromGit.overwriteOn`:`backup.restoreFromGit.overwriteOff`)})]}),(0,G.jsx)(fH,{checked:s,onChange:c,disabled:S})]})})]}),(0,G.jsx)(`div`,{className:`flex items-center justify-between p-4 border-t border-bambu-dark-tertiary`,children:d?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`span`,{}),(0,G.jsxs)(`div`,{className:`flex gap-3`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:w,children:t(`common.close`)}),(0,G.jsx)(Q,{onClick:()=>window.location.reload(),className:`bg-bambu-green hover:bg-bambu-green-dark`,children:t(`backup.reloadNow`)})]})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:t(`backup.restoreFromGit.selectedCount`,{count:v})}),(0,G.jsxs)(`div`,{className:`flex gap-3`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:w,disabled:S,children:t(`common.cancel`)}),(0,G.jsx)(Q,{onClick:()=>u(!0),disabled:v===0||S,className:`bg-bambu-green hover:bg-bambu-green-dark disabled:opacity-50 disabled:cursor-not-allowed min-w-[100px]`,children:S?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 mr-2 animate-spin`}),t(`backup.restoreFromGit.restoring`)]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Wl,{className:`w-4 h-4 mr-2`}),t(`backup.restore`)]})})]})]})})]})})}),l&&(0,G.jsx)(of,{variant:`danger`,overlayZIndex:`z-[110]`,title:t(`backup.restoreFromGit.confirmTitle`),message:s?t(`backup.restoreFromGit.confirmMessageOverwrite`):b?`${t(`backup.restoreFromGit.confirmMessage`)} ${t(`backup.restoreFromGit.kprofilesOverwriteCaveat`)}`:t(`backup.restoreFromGit.confirmMessage`),confirmText:t(`backup.restore`),isLoading:S,loadingText:t(`backup.restoreFromGit.restoring`),onConfirm:()=>x.mutate(),onCancel:()=>u(!1)})]})}function F8(e){if(!e)return`-`;let t=rp(e);return t?t.toLocaleString():`-`}function I8({status:e}){if(!e)return null;let t={success:`bg-green-100 dark:bg-green-500/20 text-green-700 dark:text-green-400`,failed:`bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400`,skipped:`bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400`,running:`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`},n={success:(0,G.jsx)(xs,{className:`w-3 h-3`}),failed:(0,G.jsx)(Ds,{className:`w-3 h-3`}),skipped:(0,G.jsx)(du,{className:`w-3 h-3`}),running:(0,G.jsx)(Y,{className:`w-3 h-3 animate-spin`})};return(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded text-xs font-medium ${t[e]||`bg-gray-500/20 text-gray-400`}`,children:[n[e],e.charAt(0).toUpperCase()+e.slice(1)]})}var wGe={github:`backup.repoUrlPlaceholderGitHub`,gitea:`backup.repoUrlPlaceholderGitea`,forgejo:`backup.repoUrlPlaceholderForgejo`,gitlab:`backup.repoUrlPlaceholderGitLab`},TGe={github:`ghp_xxxxxxxxxxxx`,gitea:`your_access_token`,forgejo:`your_access_token`,gitlab:`glpat-xxxxxxxxxxxx`},EGe={github:`backup.tokenHintGitHub`,gitea:`backup.tokenHintGitea`,forgejo:`backup.tokenHintForgejo`,gitlab:`backup.tokenHintGitLab`};function L8(e){return JSON.stringify(e)}function DGe(e,t){if(!t)return e;let n={};for(let r of Object.keys(e))e[r]!==t[r]&&(n[r]=e[r]);return n}function OGe(){let e=co(),{showToast:t}=qd(),{t:n}=U(),{hasPermission:r}=Nd(),i=r(`github:restore`),[a,o]=(0,y.useState)(``),[s,c]=(0,y.useState)(``),[l,u]=(0,y.useState)(`main`),[d,f]=(0,y.useState)(`github`),[p,m]=(0,y.useState)(!1),[h,g]=(0,y.useState)(`daily`),[_,v]=(0,y.useState)(!0),[b,x]=(0,y.useState)(!0),[S,C]=(0,y.useState)(!1),[w,T]=(0,y.useState)(!1),[E,D]=(0,y.useState)(!1),[O,k]=(0,y.useState)(!1),[A,j]=(0,y.useState)(!0),[M,N]=(0,y.useState)(!1),[P,F]=(0,y.useState)(!1),[I,L]=(0,y.useState)(``),[R,z]=(0,y.useState)(!1),[B,V]=(0,y.useState)(null),[ee,te]=(0,y.useState)(null),ne=(0,y.useRef)(null),[re,ie]=(0,y.useState)(!1),[ae,oe]=(0,y.useState)(null),[se,H]=(0,y.useState)(null),[ce,le]=(0,y.useState)(``),{data:ue,refetch:de}=K({queryKey:[`local-backup-status`],queryFn:Z.getLocalBackupStatus,refetchInterval:e=>e.state.data?.is_running?1e3:1e4}),{data:fe,refetch:pe}=K({queryKey:[`local-backup-files`],queryFn:Z.getLocalBackups,refetchInterval:3e4}),{data:me,refetch:he}=K({queryKey:[`local-backup-path-check`],queryFn:Z.checkLocalBackupPath,enabled:ue?.enabled===!0,refetchOnWindowFocus:!1});(0,y.useEffect)(()=>{ue?.path!==void 0&&le(ue.path)},[ue?.path]);let ge=q({mutationFn:Z.triggerLocalBackup,onSuccess:e=>{e.success?t(n(`backup.scheduledBackupComplete`)):t(e.message,`error`),de(),pe(),he()},onError:()=>t(n(`backup.scheduledBackupFailed`),`error`)}),_e=q({mutationFn:e=>Z.deleteLocalBackup(e),onSuccess:()=>{pe(),oe(null)}}),ve=q({mutationFn:async e=>(H(null),F(!0),te(null),L(n(`backup.restoring`)),Z.restoreLocalBackup(e)),onSuccess:e=>{F(!1),L(``),e.success?(te({success:!0,message:e.message}),t(n(`backup.backupRestoredRestart`),`success`)):(te({success:!1,message:e.message}),t(e.message,`error`))},onError:e=>{F(!1),L(``);let r=e instanceof Error?e.message:n(`backup.failedToRestore`);te({success:!1,message:r}),t(r,`error`)}});(0,y.useEffect)(()=>{if(M||P){let e=e=>(e.preventDefault(),e.returnValue=`A backup operation is in progress. Are you sure you want to leave?`,e.returnValue);return window.addEventListener(`beforeunload`,e),()=>window.removeEventListener(`beforeunload`,e)}},[M,P]);let[ye,be]=(0,y.useState)(!1),[xe,Se]=(0,y.useState)(null),[Ce,we]=(0,y.useState)(null),Te=(0,y.useRef)(null),Ee=(0,y.useRef)(null),De=(0,y.useRef)(null),Oe=(0,y.useRef)(null),ke=(0,y.useRef)(``),[Ae,je]=(0,y.useState)(!1),Me=(0,y.useMemo)(()=>({repository_url:a,branch:l,provider:d,allow_insecure_http:O,schedule_enabled:p,schedule_type:h,backup_kprofiles:_,backup_cloud_profiles:b,backup_settings:S,backup_spools:w,backup_archives:E,enabled:A}),[a,l,d,O,p,h,_,b,S,w,E,A]),Ne=(0,y.useMemo)(()=>L8(Me),[Me]),{data:Pe,isLoading:Fe}=K({queryKey:[`github-backup-config`],queryFn:Z.getGitHubBackupConfig}),{data:Ie}=K({queryKey:[`github-backup-status`],queryFn:Z.getGitHubBackupStatus,refetchInterval:e=>e.state.data?.is_running?500:1e4}),{data:Le}=K({queryKey:[`github-backup-logs`],queryFn:()=>Z.getGitHubBackupLogs(20)}),{data:Re}=K({queryKey:[`cloud-status`],queryFn:Z.getCloudStatus}),{data:ze}=K({queryKey:[`github-backup-cloud-accounts`],queryFn:Z.getGitHubBackupCloudAccounts,staleTime:6e4}),Be=(ze?.bambu??0)+(ze?.orca??0),Ve=ze?Be>0:!!Re?.is_authenticated,{data:He}=K({queryKey:[`printers`],queryFn:Z.getPrinters}),Ue=Co({queries:(He??[]).map(e=>({queryKey:[`printerStatus`,e.id],queryFn:()=>Z.getPrinterStatus(e.id),staleTime:1e4,refetchInterval:3e4}))}),We=(He??[]).map((e,t)=>({printer:e,connected:Ue[t]?.data?.connected??!1})),Ge=We.length,Ke=We.filter(e=>e.connected).length,qe=Ge>0&&Ke===0,Je=Ke>0&&Ke(De.current&&clearTimeout(De.current),Pe?(je(!1),Oe.current={repository_url:Pe.repository_url,branch:Pe.branch,provider:Pe.provider??`github`,allow_insecure_http:Pe.allow_insecure_http??!1,schedule_enabled:Pe.schedule_enabled,schedule_type:Pe.schedule_type,backup_kprofiles:Pe.backup_kprofiles,backup_cloud_profiles:Pe.backup_cloud_profiles,backup_settings:Pe.backup_settings,backup_spools:Pe.backup_spools,backup_archives:Pe.backup_archives,enabled:Pe.enabled},o(Pe.repository_url),u(Pe.branch),f(Pe.provider??`github`),m(Pe.schedule_enabled),g(Pe.schedule_type),v(Pe.backup_kprofiles),x(Pe.backup_cloud_profiles),C(Pe.backup_settings),T(Pe.backup_spools),D(Pe.backup_archives),k(Pe.allow_insecure_http??!1),j(Pe.enabled),c(``),De.current=setTimeout(()=>{je(!0)},100)):(je(!1),Oe.current=null,c(``)),()=>{De.current&&clearTimeout(De.current)}),[Pe]);let Ye=(0,y.useCallback)(async(r=!1)=>{if(Pe)try{r&&s?(await Z.saveGitHubBackupConfig({...Me,access_token:s}),c(``),we(null),t(n(`backup.tokenUpdated`)),ke.current=``):(await Z.updateGitHubBackupConfig(DGe(Me,Oe.current)),we(null),t(n(`backup.settingsSaved`))),Oe.current=Me,e.invalidateQueries({queryKey:[`github-backup-config`]}),e.invalidateQueries({queryKey:[`github-backup-status`]})}catch(e){we(e.message)}},[Pe,s,Me,e,t,n]),Xe=(0,y.useRef)(Ye);(0,y.useEffect)(()=>{Xe.current=Ye},[Ye]),(0,y.useEffect)(()=>{if(!(!Ae||!Pe)&&!(Oe.current&&Ne===L8(Oe.current)))return Te.current&&clearTimeout(Te.current),Te.current=setTimeout(()=>{Ye(!1)},500),()=>{Te.current&&clearTimeout(Te.current)}},[Ae,Pe,Ne,Ye]),(0,y.useEffect)(()=>{if(!(!Ae||!Pe||!s)&&s!==ke.current)return ke.current=s,Ee.current&&clearTimeout(Ee.current),Ee.current=setTimeout(()=>{Xe.current(!0)},1e3),()=>{Ee.current&&clearTimeout(Ee.current)}},[Ae,s,Pe]);let Ze=q({mutationFn:e=>Z.saveGitHubBackupConfig(e),onMutate:()=>{we(null)},onSuccess:()=>{e.invalidateQueries({queryKey:[`github-backup-config`]}),e.invalidateQueries({queryKey:[`github-backup-status`]}),t(n(`backup.githubBackupEnabled`)),c(``),je(!0)},onError:e=>{we(e.message)}}),Qe=q({mutationFn:Z.triggerGitHubBackup,onSuccess:r=>{e.invalidateQueries({queryKey:[`github-backup-status`]}),e.invalidateQueries({queryKey:[`github-backup-logs`]}),r.success?r.files_changed>0?t(n(`backup.backupCompleteFiles`,{count:r.files_changed})):t(n(`backup.backupSkippedNoChanges`)):t(n(`backup.backupFailed2`,{message:r.message}),`error`)},onError:e=>{t(n(`backup.backupFailed2`,{message:e.message}),`error`)}}),$e=q({mutationFn:()=>Z.clearGitHubBackupLogs(0),onSuccess:r=>{e.invalidateQueries({queryKey:[`github-backup-logs`]}),t(n(`backup.clearedLogs`,{count:r.deleted}))},onError:e=>{t(n(`backup.failedToClearLogs`,{message:e.message}),`error`)}}),et=async()=>{be(!0),Se(null);try{let e;if(s){if(!a){t(n(`backup.enterRepoUrl`),`error`),be(!1);return}e=await Z.testGitHubConnection(a,s,d)}else if(Pe?.has_token)e=await Z.testGitHubStoredConnection();else{t(n(`backup.enterRepoAndToken`),`error`),be(!1);return}Se({success:e.success,message:e.message,isPrivate:e.is_private})}catch(e){Se({success:!1,message:e.message,isPrivate:null})}finally{be(!1)}};return Fe?(0,G.jsx)(`div`,{className:`flex items-center justify-center py-12`,children:(0,G.jsx)(Y,{className:`w-8 h-8 animate-spin text-bambu-green`})}):(0,G.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-6`,children:[(0,G.jsxs)(`div`,{className:`space-y-6`,children:[(0,G.jsxs)(zd,{id:`card-backup-github`,children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(kc,{className:`w-5 h-5 text-gray-400`}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:n(`backup.githubBackup`)})]}),Pe&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:n(`backup.enabled`)}),(0,G.jsx)(fH,{checked:A,onChange:j})]})]})}),(0,G.jsxs)(Vd,{className:`space-y-4`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`backup.githubDescription`)}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{htmlFor:`git-provider-select`,className:`block text-sm text-bambu-gray mb-1`,children:n(`backup.provider`)}),(0,G.jsxs)(`select`,{id:`git-provider-select`,value:d,onChange:e=>{f(e.target.value),Se(null),we(null)},className:`w-full h-10 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,G.jsx)(`option`,{value:`github`,children:n(`backup.providerGitHub`)}),(0,G.jsx)(`option`,{value:`gitlab`,children:n(`backup.providerGitLab`)}),(0,G.jsx)(`option`,{value:`gitea`,children:n(`backup.providerGitea`)}),(0,G.jsx)(`option`,{value:`forgejo`,children:n(`backup.providerForgejo`)})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`backup.repositoryUrl`)}),(0,G.jsx)(`input`,{type:`text`,value:a,onChange:e=>{o(e.target.value),Se(null),we(null)},placeholder:n(wGe[d]),className:`w-full h-10 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,G.jsxs)(`label`,{className:`flex items-start gap-2 mt-2 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:O,onChange:e=>{k(e.target.checked),Se(null)},className:`w-4 h-4 mt-0.5 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-sm text-white`,children:n(`backup.allowInsecureHttp`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`backup.allowInsecureHttpHint`)})]})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[n(`backup.personalAccessToken`),` `,Pe?.has_token&&(0,G.jsx)(`span`,{className:`text-green-700 dark:text-green-400`,children:n(`backup.tokenSaved`)})]}),(0,G.jsx)(`input`,{type:`password`,value:s,onChange:e=>{c(e.target.value),Se(null),we(null)},placeholder:Pe?.has_token?n(`backup.enterNewToken`):TGe[d],className:`w-full h-10 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(EGe[d])})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`backup.branch`)}),(0,G.jsx)(`input`,{type:`text`,value:l,onChange:e=>u(e.target.value),placeholder:`main`,className:`w-full h-10 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`backup.autoBackup`)}),(0,G.jsxs)(`select`,{value:p?h:`disabled`,onChange:e=>{e.target.value===`disabled`?m(!1):(m(!0),g(e.target.value))},className:`w-full h-10 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,G.jsx)(`option`,{value:`disabled`,children:n(`backup.manualOnly`)}),(0,G.jsx)(`option`,{value:`hourly`,children:n(`backup.hourly`)}),(0,G.jsx)(`option`,{value:`daily`,children:n(`backup.daily`)}),(0,G.jsx)(`option`,{value:`weekly`,children:n(`backup.weekly`)})]})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-2`,children:n(`backup.includeInBackup`)}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsxs)(`label`,{className:`flex items-start gap-2 ${qe?`cursor-not-allowed opacity-60`:`cursor-pointer`}`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:_,onChange:e=>v(e.target.checked),className:`w-4 h-4 mt-0.5 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`,disabled:qe}),(0,G.jsxs)(`div`,{className:`flex-1`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-sm ${qe?`text-bambu-gray`:`text-white`}`,children:n(`backup.kProfiles`)}),qe&&(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-xs bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400`,children:[(0,G.jsx)(Lu,{className:`w-3 h-3`}),n(`backup.noPrintersConnected`)]}),Je&&(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-xs bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400`,children:[(0,G.jsx)(Lu,{className:`w-3 h-3`}),n(`backup.printersConnected`,{connected:Ke,total:Ge})]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`backup.kProfilesDescription`)})]})]}),(0,G.jsxs)(`label`,{className:`flex items-start gap-2 ${Ve?`cursor-pointer`:`cursor-not-allowed opacity-60`}`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:b,onChange:e=>x(e.target.checked),className:`w-4 h-4 mt-0.5 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`,disabled:!Ve}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-sm ${Ve?`text-white`:`text-bambu-gray`}`,children:n(`backup.cloudProfiles`)}),!Ve&&(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-xs bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400`,children:[(0,G.jsx)(Lu,{className:`w-3 h-3`}),n(`backup.cloudLoginRequiredShort`)]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`backup.cloudProfilesDescription`)}),Be>0&&(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:n(`backup.cloudProfilesAccounts`,{bambu:ze?.bambu??0,orca:ze?.orca??0})})]})]}),(0,G.jsxs)(`label`,{className:`flex items-start gap-2 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:S,onChange:e=>C(e.target.checked),className:`w-4 h-4 mt-0.5 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-white text-sm`,children:n(`backup.appSettings`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`backup.appSettingsDescription`)})]})]}),(0,G.jsxs)(`label`,{className:`flex items-start gap-2 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:w,onChange:e=>T(e.target.checked),className:`w-4 h-4 mt-0.5 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-white text-sm`,children:n(`backup.spoolInventory`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`backup.spoolInventoryDescription`)})]})]}),(0,G.jsxs)(`label`,{className:`flex items-start gap-2 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:E,onChange:e=>D(e.target.checked),className:`w-4 h-4 mt-0.5 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-white text-sm`,children:n(`backup.printArchives`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`backup.printArchivesDescription`)})]})]})]})]}),(0,G.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary pt-4 space-y-3`,children:[Ie?.configured&&(0,G.jsxs)(`div`,{className:`flex items-center justify-between text-sm`,children:[(0,G.jsx)(`div`,{className:`flex items-center gap-2 text-bambu-gray`,children:Ie.last_backup_at?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`span`,{children:[n(`backup.lastBackupAt`),` `,up(Ie.last_backup_at,`system`,n)]}),(0,G.jsx)(I8,{status:Ie.last_backup_status})]}):(0,G.jsx)(`span`,{children:n(`backup.noBackupsYet`)})}),Ie.next_scheduled_run&&(0,G.jsxs)(`span`,{className:`text-bambu-gray`,children:[(0,G.jsx)(js,{className:`w-3 h-3 inline mr-1`}),n(`backup.next`),` `,up(Ie.next_scheduled_run,`system`,n)]})]}),Ce&&(0,G.jsxs)(`div`,{className:`text-sm text-red-700 dark:text-red-400 bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30 rounded p-3 flex items-start gap-2`,children:[(0,G.jsx)(Ds,{className:`w-4 h-4 mt-0.5 shrink-0`}),(0,G.jsx)(`div`,{className:`flex-1 leading-relaxed whitespace-pre-wrap break-words`,children:Ce}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>we(null),className:`text-bambu-gray hover:text-white shrink-0`,"aria-label":n(`common.dismiss`,`Dismiss`),children:(0,G.jsx)(Ds,{className:`w-4 h-4`})})]}),xe&&(0,G.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,G.jsxs)(`div`,{className:`text-sm flex items-center gap-1 ${xe.success?`text-green-700 dark:text-green-400`:`text-red-700 dark:text-red-400`}`,children:[xe.success?(0,G.jsx)(xs,{className:`w-4 h-4`}):(0,G.jsx)(Ds,{className:`w-4 h-4`}),xe.message]}),xe.success&&xe.isPrivate===!0&&(0,G.jsxs)(`div`,{className:`text-xs flex items-center gap-1 text-green-700 dark:text-green-400`,children:[(0,G.jsx)(xs,{className:`w-3.5 h-3.5`}),n(`backup.repoIsPrivate`,`Repository is private — safe to back up to.`)]}),xe.success&&xe.isPrivate===!1&&(0,G.jsxs)(`div`,{className:`text-xs text-red-700 dark:text-red-400 bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30 rounded p-2 flex items-start gap-1.5`,children:[(0,G.jsx)(Ds,{className:`w-4 h-4 mt-0.5 shrink-0`}),(0,G.jsx)(`span`,{children:n(`backup.repoIsPublicWarning`,`Repository is PUBLIC. Bambuddy backups include MQTT credentials, Home Assistant tokens, Prometheus tokens, your Bambu Cloud email, and printer access codes via K-profiles. Saving is blocked until you make the repository private in your provider's settings.`)})]}),xe.success&&xe.isPrivate===null&&(0,G.jsxs)(`div`,{className:`text-xs text-yellow-700 dark:text-yellow-400 bg-yellow-50 dark:bg-yellow-500/10 border border-yellow-300 dark:border-yellow-500/30 rounded p-2 flex items-start gap-1.5`,children:[(0,G.jsx)(Ds,{className:`w-4 h-4 mt-0.5 shrink-0`}),(0,G.jsx)(`span`,{children:n(`backup.repoVisibilityUnknown`,`Could not determine repository visibility. Bambuddy refuses to back up to anything not confirmed private; saving will be blocked.`)})]})]}),(0,G.jsx)(`div`,{className:`flex flex-wrap items-center gap-2`,children:Ie?.configured?(0,G.jsx)(G.Fragment,{children:Qe.isPending||Ie.is_running?(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-green`,children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),(0,G.jsx)(`span`,{className:`text-sm`,children:Ie.progress||n(`backup.startingBackup`)})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(Q,{variant:`primary`,size:`sm`,onClick:()=>Qe.mutate(),disabled:!Pe?.enabled,children:[(0,G.jsx)(Nl,{className:`w-4 h-4`}),n(`backup.backupNow`)]}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:et,disabled:ye,children:[ye?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Hl,{className:`w-4 h-4`}),n(`backup.test`)]}),i&&(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:()=>ie(!0),disabled:Ie.restore_running,children:[(0,G.jsx)(Wl,{className:`w-4 h-4`}),n(`backup.restoreFromGit.button`)]})]})}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(Q,{variant:`primary`,size:`sm`,onClick:()=>{if(!a){t(n(`backup.repoRequired`),`error`);return}if(!s){t(n(`backup.tokenRequired`),`error`);return}Ze.mutate({repository_url:a,access_token:s,branch:l,provider:d,allow_insecure_http:O,schedule_enabled:p,schedule_type:h,backup_kprofiles:_,backup_cloud_profiles:b,backup_settings:S,backup_spools:w,backup_archives:E,enabled:A})},disabled:Ze.isPending||!a||!s,children:[Ze.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(xs,{className:`w-4 h-4`}),n(`backup.enableBackup`)]}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:et,disabled:ye||!a||!s,children:[ye?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Hl,{className:`w-4 h-4`}),n(`backup.testConnection`)]})]})})]})]})]}),Le&&Le.length>0&&(0,G.jsxs)(zd,{id:`card-backup-history`,children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(zc,{className:`w-5 h-5 text-gray-400`}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:n(`backup.history`)})]}),(0,G.jsxs)(Q,{variant:`ghost`,size:`sm`,onClick:()=>$e.mutate(),disabled:$e.isPending,children:[(0,G.jsx)(Pu,{className:`w-4 h-4`}),n(`backup.clear`)]})]})}),(0,G.jsx)(Vd,{children:(0,G.jsx)(`div`,{className:`overflow-x-auto`,children:(0,G.jsxs)(`table`,{className:`w-full text-sm`,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-2 px-2`,children:n(`backup.date`)}),(0,G.jsx)(`th`,{className:`text-left py-2 px-2`,children:n(`backup.trigger`)}),(0,G.jsx)(`th`,{className:`text-left py-2 px-2`,children:n(`backup.status`)}),(0,G.jsx)(`th`,{className:`text-left py-2 px-2`,children:n(`backup.commit`)})]})}),(0,G.jsx)(`tbody`,{children:Le.slice(0,10).map(e=>(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/50 hover:bg-bambu-dark-secondary`,children:[(0,G.jsx)(`td`,{className:`py-2 px-2 text-white`,children:F8(e.started_at)}),(0,G.jsx)(`td`,{className:`py-2 px-2 text-bambu-gray`,children:n(`backup.triggers.${e.trigger}`,{defaultValue:e.trigger})}),(0,G.jsx)(`td`,{className:`py-2 px-2`,children:(0,G.jsx)(I8,{status:e.status})}),(0,G.jsx)(`td`,{className:`py-2 px-2`,children:e.commit_sha?(0,G.jsxs)(`a`,{href:`${Pe?.repository_url}/commit/${e.commit_sha}`,target:`_blank`,rel:`noopener noreferrer`,className:`text-bambu-green hover:underline inline-flex items-center gap-1`,children:[e.commit_sha.substring(0,7),(0,G.jsx)(rc,{className:`w-3 h-3`})]}):(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:`-`})})]},e.id))})]})})})]})]}),(0,G.jsxs)(`div`,{className:`space-y-6`,children:[(0,G.jsxs)(zd,{id:`card-backup-local`,children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Gs,{className:`w-5 h-5 text-gray-400`}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:n(`backup.localBackup`)})]})}),(0,G.jsxs)(Vd,{className:`space-y-4`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`backup.localBackupDescription`)}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between py-3 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:n(`backup.downloadBackupLabel`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`backup.completeBackupZip`)})]}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,disabled:M||P,onClick:async()=>{N(!0),L(n(`backup.preparingBackup`));try{L(n(`backup.creatingArchive`));let{blob:e,filename:r}=await Z.exportBackup();L(n(`backup.downloadingFile`));let i=URL.createObjectURL(e),a=document.createElement(`a`);a.href=i,a.download=r,a.click(),URL.revokeObjectURL(i),t(n(`backup.backupDownloaded`))}catch(e){t(n(`backup.failedToCreateBackup`,{message:e instanceof Error?e.message:`Unknown error`}),`error`)}finally{N(!1),L(``)}},children:[(0,G.jsx)(Xs,{className:`w-4 h-4`}),n(`backup.download`)]})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between py-3 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:n(`backup.restoreBackup`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`backup.restoreDescription`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray-light mt-1`,children:n(`backup.restoreNote`)})]}),(0,G.jsx)(`input`,{ref:ne,type:`file`,accept:`.zip`,className:`hidden`,onChange:e=>{let t=e.target.files?.[0];t&&(V(t),z(!0)),e.target.value=``}}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,disabled:P||M,onClick:()=>ne.current?.click(),children:[(0,G.jsx)(Vu,{className:`w-4 h-4`}),n(`backup.restore`)]})]}),ee&&(0,G.jsx)(`div`,{className:`p-3 rounded-lg ${ee.success?`bg-green-50 dark:bg-green-500/10 border border-green-300 dark:border-green-500/30`:`bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30`}`,children:(0,G.jsxs)(`div`,{className:`flex items-start gap-2 text-sm`,children:[ee.success?(0,G.jsx)(xs,{className:`w-4 h-4 text-green-600 dark:text-green-400 mt-0.5 flex-shrink-0`}):(0,G.jsx)(Ds,{className:`w-4 h-4 text-red-600 dark:text-red-400 mt-0.5 flex-shrink-0`}),(0,G.jsxs)(`div`,{className:ee.success?`text-green-800 dark:text-green-200`:`text-red-800 dark:text-red-200`,children:[ee.message,ee.success&&(0,G.jsx)(`div`,{className:`mt-2`,children:(0,G.jsxs)(Q,{size:`sm`,onClick:()=>window.location.reload(),children:[(0,G.jsx)(Wl,{className:`w-3 h-3`}),n(`backup.reloadNow`)]})})]})]})}),(0,G.jsx)(`div`,{className:`p-3 rounded-lg bg-yellow-50 dark:bg-yellow-500/10 border border-yellow-300 dark:border-yellow-500/30`,children:(0,G.jsxs)(`div`,{className:`flex items-start gap-2 text-sm`,children:[(0,G.jsx)(Lu,{className:`w-4 h-4 text-yellow-600 dark:text-yellow-400 mt-0.5 flex-shrink-0`}),(0,G.jsxs)(`div`,{className:`text-yellow-800 dark:text-yellow-200`,children:[(0,G.jsx)(`span`,{className:`font-medium`,children:n(`backup.restoreReplacesAll`)}),` `,(0,G.jsx)(`span`,{className:`text-yellow-800/80 dark:text-yellow-200/70`,children:n(`backup.restoreReplacesAllDetail`)})]})]})})]})]}),(0,G.jsxs)(zd,{id:`card-backup-scheduled`,children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(gc,{className:`w-5 h-5 text-gray-400`}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:n(`backup.scheduledBackup`)})]}),(0,G.jsx)(fH,{checked:ue?.enabled??!1,onChange:async r=>{try{await Z.updateSettings({local_backup_enabled:r}),e.invalidateQueries({queryKey:[`settings`]}),t(n(`backup.settingsSaved`))}catch(e){t(n(`backup.failedToSave`,{message:e instanceof Error?e.message:`Unknown error`}),`error`)}de()}})]})}),(0,G.jsxs)(Vd,{className:`space-y-4`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`backup.scheduledBackupDescription`)}),ue?.enabled&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`grid grid-cols-3 gap-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`backup.frequency`)}),(0,G.jsxs)(`select`,{value:ue?.schedule??`daily`,className:`w-full h-10 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,onChange:async e=>{try{await Z.updateSettings({local_backup_schedule:e.target.value}),t(n(`backup.settingsSaved`))}catch(e){t(n(`backup.failedToSave`,{message:e instanceof Error?e.message:`Unknown error`}),`error`)}de()},children:[(0,G.jsx)(`option`,{value:`hourly`,children:n(`backup.hourly`)}),(0,G.jsx)(`option`,{value:`daily`,children:n(`backup.daily`)}),(0,G.jsx)(`option`,{value:`weekly`,children:n(`backup.weekly`)})]})]}),(ue?.schedule??`daily`)!==`hourly`&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`backup.backupTime`)}),(0,G.jsx)(`input`,{type:`time`,value:ue?.time??`03:00`,className:`w-full h-10 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,onChange:async e=>{try{await Z.updateSettings({local_backup_time:e.target.value}),t(n(`backup.settingsSaved`))}catch(e){t(n(`backup.failedToSave`,{message:e instanceof Error?e.message:`Unknown error`}),`error`)}de()}}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray-light mt-1`,children:n(`backup.localTimeHint`,{tz:ue?.timezone||`UTC`})})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`backup.retention`)}),(0,G.jsx)(`input`,{type:`number`,min:1,max:100,value:ue?.retention??5,className:`w-full h-10 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,onChange:async e=>{let r=Math.max(1,Math.min(100,parseInt(e.target.value)||5));try{await Z.updateSettings({local_backup_retention:r}),t(n(`backup.settingsSaved`))}catch(e){t(n(`backup.failedToSave`,{message:e instanceof Error?e.message:`Unknown error`}),`error`)}de()}}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray-light mt-1`,children:n(`backup.retentionDescription`)})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`backup.outputPath`)}),(0,G.jsx)(`input`,{type:`text`,value:ce,onChange:e=>le(e.target.value),className:`w-full h-10 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,onBlur:async()=>{try{await Z.updateSettings({local_backup_path:ce}),t(n(`backup.settingsSaved`))}catch(e){t(n(`backup.failedToSave`,{message:e instanceof Error?e.message:`Unknown error`}),`error`)}de(),pe(),he()},onKeyDown:e=>{e.key===`Enter`&&e.target.blur()}}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray-light mt-1`,children:ce?n(`backup.outputPathDescription`):(0,G.jsxs)(G.Fragment,{children:[n(`backup.defaultPathLabel`),` `,(0,G.jsx)(`code`,{className:`text-bambu-gray`,children:ue?.default_path||`...`})]})}),me&&!me.writable&&(0,G.jsx)(`div`,{className:`mt-2 p-3 rounded-lg bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30`,children:(0,G.jsxs)(`div`,{className:`flex items-start gap-2 text-sm`,children:[(0,G.jsx)(Lu,{className:`w-4 h-4 text-red-600 dark:text-red-400 mt-0.5 flex-shrink-0`}),(0,G.jsxs)(`div`,{className:`min-w-0 text-red-800 dark:text-red-200`,children:[(0,G.jsx)(`p`,{className:`font-medium`,children:n(`backup.pathCheck.title`)}),(0,G.jsx)(`p`,{className:`mt-1 text-red-800/80 dark:text-red-200/80`,children:n(`backup.pathCheck.${me.code}`,{path:me.path,defaultValue:me.message})}),me.remedy&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`p`,{className:`mt-2 font-medium`,children:n(`backup.pathCheck.howToFix`)}),(0,G.jsx)(`pre`,{className:`mt-1 p-2 rounded bg-black/10 dark:bg-black/40 text-xs whitespace-pre-wrap break-words`,children:me.remedy})]}),me.detail&&(0,G.jsx)(`p`,{className:`mt-2 text-xs text-red-800/60 dark:text-red-200/60 break-words`,children:me.detail})]})]})}),me?.writable&&me.warning===`container_ephemeral`&&(0,G.jsx)(`div`,{className:`mt-2 p-3 rounded-lg bg-yellow-50 dark:bg-yellow-500/10 border border-yellow-300 dark:border-yellow-500/30`,children:(0,G.jsxs)(`div`,{className:`flex items-start gap-2 text-sm`,children:[(0,G.jsx)(Lu,{className:`w-4 h-4 text-yellow-600 dark:text-yellow-400 mt-0.5 flex-shrink-0`}),(0,G.jsxs)(`div`,{className:`min-w-0 text-yellow-800 dark:text-yellow-200`,children:[(0,G.jsx)(`p`,{className:`font-medium`,children:n(`backup.pathCheck.ephemeralTitle`)}),(0,G.jsx)(`p`,{className:`mt-1 text-yellow-800/80 dark:text-yellow-200/80`,children:n(`backup.pathCheck.container_ephemeral`,{path:me.path})}),me.remedy&&(0,G.jsx)(`pre`,{className:`mt-1 p-2 rounded bg-black/10 dark:bg-black/40 text-xs whitespace-pre-wrap break-words`,children:me.remedy})]})]})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between py-3 border-t border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`text-sm`,children:[ue?.last_backup_at&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray`,children:[(0,G.jsxs)(`span`,{children:[n(`backup.lastBackup`),`:`]}),(0,G.jsx)(I8,{status:ue.last_status}),(0,G.jsx)(`span`,{children:up(ue.last_backup_at)})]}),ue?.next_run&&(0,G.jsxs)(`div`,{className:`text-bambu-gray mt-1`,children:[(0,G.jsxs)(`span`,{children:[n(`backup.nextBackup`),`: `]}),(0,G.jsx)(`span`,{children:F8(ue.next_run)})]})]}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,disabled:ue?.is_running||ge.isPending,onClick:()=>ge.mutate(),children:[ue?.is_running||ge.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Nl,{className:`w-4 h-4`}),ue?.is_running?n(`backup.backupRunning`):n(`backup.runNow`)]})]}),fe&&fe.length>0&&(0,G.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary pt-3`,children:[(0,G.jsx)(`h3`,{className:`text-sm font-medium text-white mb-2`,children:n(`backup.backupFiles`)}),(0,G.jsx)(`div`,{className:`space-y-1`,children:fe.map(e=>(0,G.jsxs)(`div`,{className:`flex items-center justify-between py-1.5 px-2 rounded hover:bg-bambu-dark-tertiary/50 text-sm`,children:[(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`span`,{className:`text-white truncate block`,children:e.filename}),(0,G.jsxs)(`span`,{className:`text-bambu-gray text-xs`,children:[(e.size/1024/1024).toFixed(1),` MB · `,F8(e.created_at)]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1 flex-shrink-0`,children:[(0,G.jsx)(`button`,{className:`text-bambu-gray hover:text-bambu-green p-1`,title:n(`backup.download`),onClick:async()=>{try{let{blob:t,filename:n}=await Z.downloadLocalBackup(e.filename),r=URL.createObjectURL(t),i=document.createElement(`a`);i.href=r,i.download=n,i.click(),URL.revokeObjectURL(r)}catch{t(n(`backup.scheduledBackupFailed`),`error`)}},children:(0,G.jsx)(Xs,{className:`w-3.5 h-3.5`})}),(0,G.jsx)(`button`,{className:`text-bambu-gray hover:text-yellow-600 dark:hover:text-yellow-400 p-1`,title:n(`backup.restore`),onClick:()=>H(e.filename),children:(0,G.jsx)(Wl,{className:`w-3.5 h-3.5`})}),(0,G.jsx)(`button`,{className:`text-bambu-gray hover:text-red-600 dark:hover:text-red-400 p-1`,onClick:()=>oe(e.filename),title:n(`backup.deleteBackup`),children:(0,G.jsx)(Pu,{className:`w-3.5 h-3.5`})})]})]},e.filename))})]}),fe&&fe.length===0&&(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray text-center py-3 border-t border-bambu-dark-tertiary`,children:n(`backup.noScheduledBackups`)})]})]})]})]}),re&&(0,G.jsx)(CGe,{onClose:()=>ie(!1)}),ae&&(0,G.jsx)(of,{title:n(`backup.deleteBackup`),message:n(`backup.deleteBackupConfirm`),confirmText:n(`backup.deleteBackup`),variant:`danger`,onConfirm:()=>_e.mutate(ae),onCancel:()=>oe(null)}),se&&(0,G.jsx)(of,{title:n(`backup.restoreConfirmTitle`),message:n(`backup.restoreConfirmMessage`,{filename:se}),confirmText:n(`backup.restoreConfirmButton`),variant:`danger`,onConfirm:()=>ve.mutate(se),onCancel:()=>H(null)}),R&&B&&(0,G.jsx)(of,{title:n(`backup.restoreConfirmTitle`),message:n(`backup.restoreConfirmMessage`,{filename:B.name}),confirmText:n(`backup.restoreConfirmButton`),variant:`danger`,onConfirm:async()=>{z(!1),F(!0),te(null);try{L(n(`backup.uploadingFile`));let e=await Z.importBackup(B);te(e),e.success?t(n(`backup.backupRestoredRestart`),`success`):t(e.message,`error`)}catch(e){let r=e instanceof Error?e.message:n(`backup.failedToRestore`);te({success:!1,message:r}),t(r,`error`)}finally{F(!1),L(``),V(null)}},onCancel:()=>{z(!1),V(null)}}),(M||P)&&(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/80 flex items-center justify-center z-[100]`,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl p-8 max-w-md w-full mx-4 text-center`,children:[(0,G.jsx)(`div`,{className:`flex justify-center mb-4`,children:(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(`div`,{className:`w-16 h-16 border-4 border-bambu-dark-tertiary rounded-full`}),(0,G.jsx)(`div`,{className:`w-16 h-16 border-4 border-bambu-green border-t-transparent rounded-full absolute inset-0 animate-spin`})]})}),(0,G.jsx)(`h3`,{className:`text-xl font-semibold text-white mb-2`,children:n(M?`backup.creatingBackup`:`backup.restoringBackup`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray mb-4`,children:I||n(M?`backup.preparing`:`backup.processing`)}),(0,G.jsx)(`div`,{className:`p-3 rounded-lg bg-yellow-50 dark:bg-yellow-500/10 border border-yellow-300 dark:border-yellow-500/30`,children:(0,G.jsxs)(`div`,{className:`flex items-start gap-2 text-sm`,children:[(0,G.jsx)(Lu,{className:`w-4 h-4 text-yellow-600 dark:text-yellow-400 mt-0.5 flex-shrink-0`}),(0,G.jsx)(`p`,{className:`text-yellow-800 dark:text-yellow-200 text-left`,children:n(`backup.doNotClosePage`)})]})})]})})]})}function kGe(){let{t:e}=U(),t=co(),{showToast:n}=qd(),[r,i]=(0,y.useState)(!1),[a,o]=(0,y.useState)(``),[s,c]=(0,y.useState)(``),[l,u]=(0,y.useState)(`medium`),[d,f]=(0,y.useState)(`notify`),[p,m]=(0,y.useState)(10),[h,g]=(0,y.useState)(null),[_,v]=(0,y.useState)(null),[b,x]=(0,y.useState)(!1),{data:S}=K({queryKey:[`settings`],queryFn:Z.getSettings}),{data:C,refetch:w}=K({queryKey:[`obico-status`],queryFn:Z.getObicoStatus,refetchInterval:1e4}),{data:T}=K({queryKey:[`printers`],queryFn:Z.getPrinters});(0,y.useEffect)(()=>{if(S){i(S.obico_enabled??!1),o(S.obico_ml_url??``),c(S.obico_ml_token??``),u(S.obico_sensitivity??`medium`),f(S.obico_action??`notify`),m(S.obico_poll_interval??10);try{let e=S.obico_enabled_printers?JSON.parse(S.obico_enabled_printers):null;g(Array.isArray(e)?e:null)}catch{g(null)}x(!0)}},[S]);let E=q({mutationFn:()=>Z.updateSettings({obico_enabled:r,obico_ml_url:a,obico_ml_token:s,obico_sensitivity:l,obico_action:d,obico_poll_interval:p,obico_enabled_printers:h===null?``:JSON.stringify(h)}),onSuccess:()=>{t.invalidateQueries({queryKey:[`settings`]}),t.invalidateQueries({queryKey:[`obico-status`]}),t.invalidateQueries({queryKey:[`obico-printer-status`]}),n(e(`settings.toast.settingsSaved`))}}),D=(0,y.useMemo)(()=>!b||!S?!1:S.obico_enabled!==r||S.obico_ml_url!==a||(S.obico_ml_token??``)!==s||S.obico_sensitivity!==l||S.obico_action!==d||S.obico_poll_interval!==p||S.obico_enabled_printers!==(h===null?``:JSON.stringify(h)),[S,b,r,a,s,l,d,p,h]);(0,y.useEffect)(()=>{if(!D)return;let e=setTimeout(()=>E.mutate(),500);return()=>clearTimeout(e)},[D,r,a,s,l,d,p,h]);let O=async()=>{v(null);try{D&&await E.mutateAsync();let t=await Z.testObicoConnection(a,s);t.ok?v({ok:!0,message:t.auth_ok===null?e(`failureDetection.testSuccessTokenUnknown`):e(`failureDetection.testSuccess`)}):v({ok:!1,message:t.error||`HTTP ${t.status_code??`?`} — ${t.body??e(`failureDetection.testFailed`)}`})}catch(e){v({ok:!1,message:e instanceof Error?e.message:String(e)})}},k=(e,t)=>{if(h===null){let n=T?.map(e=>e.id)??[];g(t?n:n.filter(t=>t!==e));return}g(t?[...h,e]:h.filter(t=>t!==e))};return(0,G.jsxs)(`div`,{className:`flex flex-col lg:flex-row gap-4 lg:gap-6`,children:[(0,G.jsxs)(`div`,{className:`space-y-3 flex-1 lg:max-w-xl`,children:[(0,G.jsxs)(zd,{id:`card-fd-ml`,children:[(0,G.jsxs)(Bd,{children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Yl,{className:`w-5 h-5 text-bambu-green`}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`failureDetection.title`)})]}),(0,G.jsx)(fH,{checked:r,onChange:i})]}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-2`,children:e(`failureDetection.description`)})]}),(0,G.jsxs)(Vd,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:e(`failureDetection.mlUrl`)}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsx)(`input`,{type:`text`,value:a,onChange:e=>o(e.target.value),placeholder:`http://192.168.1.10:3333`,className:`flex-1 bg-gray-800 border border-gray-700 rounded px-3 py-2 text-white text-sm`,disabled:!r}),(0,G.jsx)(Q,{onClick:O,disabled:!a||E.isPending,variant:`secondary`,children:e(`failureDetection.test`)})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`failureDetection.mlUrlHint`)}),(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1 mt-3`,children:e(`failureDetection.mlToken`)}),(0,G.jsx)(`input`,{type:`password`,value:s,onChange:e=>c(e.target.value),autoComplete:`off`,placeholder:e(`failureDetection.mlTokenPlaceholder`),className:`w-full bg-gray-800 border border-gray-700 rounded px-3 py-2 text-white text-sm`,disabled:!r}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`failureDetection.mlTokenHint`)}),_&&(0,G.jsxs)(`div`,{className:`flex items-start gap-2 mt-2 text-sm ${_.ok?`text-green-700 dark:text-green-400`:`text-red-700 dark:text-red-400`}`,children:[_.ok?(0,G.jsx)(fs,{className:`w-4 h-4 mt-0.5`}):(0,G.jsx)(nd,{className:`w-4 h-4 mt-0.5`}),(0,G.jsx)(`span`,{children:_.message})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:e(`failureDetection.sensitivity`)}),(0,G.jsxs)(`select`,{value:l,onChange:e=>u(e.target.value),disabled:!r,className:`w-full bg-gray-800 border border-gray-700 rounded px-3 py-2 text-white text-sm`,children:[(0,G.jsx)(`option`,{value:`low`,children:e(`failureDetection.sensitivityLow`)}),(0,G.jsx)(`option`,{value:`medium`,children:e(`failureDetection.sensitivityMedium`)}),(0,G.jsx)(`option`,{value:`high`,children:e(`failureDetection.sensitivityHigh`)})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`failureDetection.sensitivityHint`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:e(`failureDetection.action`)}),(0,G.jsxs)(`select`,{value:d,onChange:e=>f(e.target.value),disabled:!r,className:`w-full bg-gray-800 border border-gray-700 rounded px-3 py-2 text-white text-sm`,children:[(0,G.jsx)(`option`,{value:`notify`,children:e(`failureDetection.actionNotify`)}),(0,G.jsx)(`option`,{value:`pause`,children:e(`failureDetection.actionPause`)}),(0,G.jsx)(`option`,{value:`pause_and_off`,children:e(`failureDetection.actionPauseOff`)})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:e(`failureDetection.pollInterval`)}),(0,G.jsx)(`input`,{type:`number`,value:p,onChange:e=>m(Math.max(5,Math.min(120,Number(e.target.value)||10))),min:5,max:120,disabled:!r,className:`w-full bg-gray-800 border border-gray-700 rounded px-3 py-2 text-white text-sm`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`failureDetection.pollIntervalHint`)})]}),C&&!C.external_url_configured&&r&&(0,G.jsxs)(`div`,{className:`flex items-start gap-2 p-3 bg-amber-50 dark:bg-amber-900/30 border border-amber-300 dark:border-amber-700 rounded text-sm text-amber-800 dark:text-amber-200`,children:[(0,G.jsx)(Lu,{className:`w-4 h-4 mt-0.5 flex-shrink-0`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`div`,{className:`font-medium`,children:e(`failureDetection.externalUrlMissing`)}),(0,G.jsx)(`div`,{className:`text-xs mt-1`,children:e(`failureDetection.externalUrlHint`)})]})]})]})]}),(0,G.jsxs)(zd,{id:`card-fd-perprinter`,children:[(0,G.jsxs)(Bd,{children:[(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`failureDetection.perPrinterTitle`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:e(`failureDetection.perPrinterHint`)})]}),(0,G.jsxs)(Vd,{className:`space-y-2`,children:[(0,G.jsxs)(`label`,{className:`flex items-center gap-2 text-sm`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:h===null,onChange:e=>g(e.target.checked?null:T?.map(e=>e.id)??[]),disabled:!r}),(0,G.jsx)(`span`,{className:`text-white`,children:e(`failureDetection.monitorAll`)})]}),h!==null&&T&&(0,G.jsx)(`div`,{className:`pl-5 space-y-1 border-l border-gray-700`,children:T.map(e=>(0,G.jsxs)(`label`,{className:`flex items-center gap-2 text-sm`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:h.includes(e.id),onChange:t=>k(e.id,t.target.checked),disabled:!r}),(0,G.jsx)(`span`,{className:`text-white`,children:e.name})]},e.id))})]})]})]}),(0,G.jsxs)(`div`,{className:`space-y-3 flex-1 lg:max-w-xl`,children:[(0,G.jsxs)(zd,{id:`card-fd-status`,children:[(0,G.jsx)(Bd,{children:(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`failureDetection.statusTitle`)})}),(0,G.jsx)(Vd,{children:C?(0,G.jsxs)(`div`,{className:`space-y-3 text-sm`,children:[(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:e(`failureDetection.serviceRunning`)}),(0,G.jsx)(`span`,{className:C.is_running?`text-green-700 dark:text-green-400`:`text-red-700 dark:text-red-400`,children:C.is_running?e(`common.yes`):e(`common.no`)})]}),(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:e(`failureDetection.thresholds`)}),(0,G.jsxs)(`span`,{className:`text-white font-mono`,children:[C.thresholds.low.toFixed(2),` / `,C.thresholds.high.toFixed(2)]})]}),C.last_error&&(0,G.jsxs)(`div`,{className:`flex items-start gap-2 text-red-700 dark:text-red-400`,children:[(0,G.jsx)(nd,{className:`w-4 h-4 mt-0.5 flex-shrink-0`}),(0,G.jsx)(`span`,{className:`break-words`,children:C.last_error})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`div`,{className:`text-bambu-gray mb-1`,children:e(`failureDetection.activePrinters`)}),Object.keys(C.per_printer).length===0?(0,G.jsx)(`div`,{className:`text-bambu-gray italic text-xs`,children:e(`failureDetection.noActivePrints`)}):(0,G.jsx)(`div`,{className:`space-y-1`,children:Object.entries(C.per_printer).map(([e,t])=>{let n=T?.find(t=>String(t.id)===e),r=t.class===`failure`?`text-red-700 dark:text-red-400`:t.class===`warning`?`text-amber-700 dark:text-amber-400`:`text-green-700 dark:text-green-400`;return(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-white`,children:n?.name??`Printer ${e}`}),(0,G.jsxs)(`span`,{className:`font-mono ${r}`,children:[t.class,` (`,t.score.toFixed(3),`, `,t.frame_count,`f)`]})]},e)})})]})]}):(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray`,children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),(0,G.jsx)(`span`,{children:e(`common.loading`)})]})})]}),(0,G.jsxs)(zd,{id:`card-fd-history`,children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`failureDetection.historyTitle`)}),(0,G.jsx)(`button`,{onClick:()=>w(),className:`text-xs text-bambu-gray hover:text-white`,children:e(`common.refresh`)})]})}),(0,G.jsx)(Vd,{children:!C||C.history.length===0?(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray text-sm`,children:[(0,G.jsx)(Wc,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{children:e(`failureDetection.noHistory`)})]}):(0,G.jsx)(`div`,{className:`space-y-1 max-h-96 overflow-y-auto text-xs font-mono`,children:C.history.map((e,t)=>{let n=T?.find(t=>t.id===e.printer_id),r=e.class===`failure`?`text-red-700 dark:text-red-400`:e.class===`warning`?`text-amber-700 dark:text-amber-400`:`text-bambu-gray`;return(0,G.jsxs)(`div`,{className:`flex justify-between gap-2 py-1 border-b border-gray-800`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:new Date(e.timestamp).toLocaleTimeString()}),(0,G.jsx)(`span`,{className:`text-white truncate`,children:n?.name??`#${e.printer_id}`}),(0,G.jsxs)(`span`,{className:r,children:[e.class,` `,e.score.toFixed(3)]})]},t)})})})]})]})]})}var AGe={starttls:587,ssl:465,none:25},jGe={587:`starttls`,465:`ssl`,25:`none`};function MGe(){let{t:e}=U(),{showToast:t}=qd(),n=co(),[r,i]=(0,y.useState)({smtp_host:``,smtp_port:587,smtp_username:``,smtp_password:``,smtp_security:`starttls`,smtp_auth_enabled:!0,smtp_from_email:``,smtp_from_name:`BamBuddy`}),[a,o]=(0,y.useState)(``),{data:s,isLoading:c}=K({queryKey:[`smtpSettings`],queryFn:()=>Z.getSMTPSettings()}),{authEnabled:l}=Nd(),{data:u}=K({queryKey:[`advancedAuthStatus`],queryFn:()=>Z.getAdvancedAuthStatus()});(0,y.useEffect)(()=>{s&&i({...s,smtp_password:``})},[s]);let d=e=>{i({...r,smtp_security:e,smtp_port:AGe[e]})},f=e=>{let t=jGe[e];i({...r,smtp_port:e,...t?{smtp_security:t}:{}})},p=e=>{i({...r,smtp_auth_enabled:e,...e?{}:{smtp_username:``,smtp_password:``}})},m=q({mutationFn:e=>Z.saveSMTPSettings(e),onSuccess:()=>{n.invalidateQueries({queryKey:[`smtpSettings`]}),n.invalidateQueries({queryKey:[`advancedAuthStatus`]}),t(e(`settings.email.success.settingsSaved`),`success`)},onError:e=>{t(e.message,`error`)}}),h=q({mutationFn:e=>Z.testSMTP(e),onSuccess:e=>{t(e.message,e.success?`success`:`error`)},onError:e=>{t(e.message,`error`)}}),g=q({mutationFn:e=>e?Z.enableAdvancedAuth():Z.disableAdvancedAuth(),onSuccess:e=>{n.invalidateQueries({queryKey:[`advancedAuthStatus`]}),t(e.message,`success`)},onError:e=>{t(e.message,`error`)}}),_=()=>{if(!r.smtp_host||!r.smtp_from_email){t(e(`settings.email.errors.requiredFields`),`error`);return}if(r.smtp_auth_enabled&&!r.smtp_username){t(e(`settings.email.errors.usernameRequired`),`error`);return}m.mutate(r)},v=()=>{if(!a){t(e(`settings.email.errors.enterTestEmail`),`error`);return}h.mutate({test_recipient:a})},b=()=>{if(!l){t(e(`settings.email.errors.enableAuthFirst`),`error`);return}if(!u?.advanced_auth_enabled&&!u?.smtp_configured){t(e(`settings.email.errors.configureSmtpFirst`),`error`);return}g.mutate(!u?.advanced_auth_enabled)};if(c)return(0,G.jsx)(`div`,{className:`flex items-center justify-center p-12`,children:(0,G.jsx)(Y,{className:`w-8 h-8 animate-spin text-bambu-green`})});let x=u?.advanced_auth_enabled??!1,S=`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,C=`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white/40 placeholder-bambu-gray/40 cursor-not-allowed`;return(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(zd,{id:`card-email-advanced-auth`,children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(al,{className:`w-5 h-5 text-bambu-green`}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`settings.email.advancedAuth`)||`Advanced Authentication`})]}),(0,G.jsx)(Q,{onClick:b,disabled:g.isPending,variant:x?`danger`:`primary`,children:x?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(tl,{className:`w-4 h-4`}),e(`settings.email.disable`)||`Disable`]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(nl,{className:`w-4 h-4`}),e(`settings.email.enable`)||`Enable`]})})]})}),(0,G.jsx)(Vd,{children:(0,G.jsx)(`div`,{className:`space-y-3`,children:x?(0,G.jsx)(`div`,{className:`bg-green-50 dark:bg-green-500/10 border border-green-300 dark:border-green-500/30 rounded-lg p-4`,children:(0,G.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,G.jsx)(xs,{className:`w-5 h-5 text-green-600 dark:text-green-400 mt-0.5 flex-shrink-0`}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`p`,{className:`text-white font-medium`,children:e(`settings.email.advancedAuthEnabled`)||`Advanced Authentication is enabled`}),(0,G.jsxs)(`ul`,{className:`text-sm text-green-700 dark:text-green-300 space-y-1 list-disc list-inside`,children:[(0,G.jsx)(`li`,{children:e(`settings.email.feature1`)||`Passwords are auto-generated and emailed to new users`}),(0,G.jsx)(`li`,{children:e(`settings.email.feature2`)||`Users can login with username or email`}),(0,G.jsx)(`li`,{children:e(`settings.email.feature3`)||`Forgot password feature is available`}),(0,G.jsx)(`li`,{children:e(`settings.email.feature4`)||`Admins can reset user passwords via email`})]})]})]})}):(0,G.jsx)(`div`,{className:`bg-yellow-50 dark:bg-yellow-500/10 border border-yellow-300 dark:border-yellow-500/30 rounded-lg p-4`,children:(0,G.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,G.jsx)(Lu,{className:`w-5 h-5 text-yellow-600 dark:text-yellow-400 mt-0.5 flex-shrink-0`}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`p`,{className:`text-white font-medium`,children:e(`settings.email.advancedAuthDisabled`)||`Advanced Authentication is disabled`}),(0,G.jsx)(`p`,{className:`text-sm text-yellow-700 dark:text-yellow-300`,children:e(`settings.email.advancedAuthDisabledDesc`)||`Enable advanced authentication to activate email-based features for user management.`})]})]})})})})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-3 gap-4`,children:[(0,G.jsx)(`div`,{className:`lg:col-span-2`,children:(0,G.jsxs)(zd,{id:`card-smtp-config`,children:[(0,G.jsx)(Bd,{children:(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`settings.email.smtpSettings`)||`SMTP Configuration`})}),(0,G.jsx)(Vd,{children:(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:e(`settings.email.authentication`)||`Authentication`}),(0,G.jsxs)(`select`,{value:r.smtp_auth_enabled?`true`:`false`,onChange:e=>p(e.target.value===`true`),className:S,children:[(0,G.jsx)(`option`,{value:`true`,children:e(`settings.email.authOptions.enabled`)}),(0,G.jsx)(`option`,{value:`false`,children:e(`settings.email.authOptions.disabled`)})]})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4 transition-opacity ${r.smtp_auth_enabled?``:`opacity-40 pointer-events-none`}`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:e(`settings.email.username`)||`Username`}),(0,G.jsx)(`input`,{type:`text`,value:r.smtp_username||``,onChange:e=>i({...r,smtp_username:e.target.value}),placeholder:`your.email@gmail.com`,disabled:!r.smtp_auth_enabled,className:r.smtp_auth_enabled?S:C})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:e(`settings.email.password`)||`Password`}),(0,G.jsx)(`input`,{type:`password`,value:r.smtp_password||``,onChange:e=>i({...r,smtp_password:e.target.value}),placeholder:s?`••••••••`:`App password`,disabled:!r.smtp_auth_enabled,className:r.smtp_auth_enabled?S:C})]})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:[e(`settings.email.smtpHost`)||`SMTP Server`,` *`]}),(0,G.jsx)(`input`,{type:`text`,value:r.smtp_host,onChange:e=>i({...r,smtp_host:e.target.value}),placeholder:`smtp.gmail.com`,className:S})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:e(`settings.email.smtpPort`)||`SMTP Port`}),(0,G.jsx)(`input`,{type:`number`,value:r.smtp_port,onChange:e=>f(parseInt(e.target.value)||587),placeholder:`587`,className:S})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:e(`settings.email.security`)||`Security`}),(0,G.jsxs)(`select`,{value:r.smtp_security,onChange:e=>d(e.target.value),className:S,children:[(0,G.jsx)(`option`,{value:`starttls`,children:e(`settings.email.securityOptions.starttls`)}),(0,G.jsx)(`option`,{value:`ssl`,children:e(`settings.email.securityOptions.ssl`)}),(0,G.jsx)(`option`,{value:`none`,children:e(`settings.email.securityOptions.none`)})]})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:[e(`settings.email.fromEmail`)||`From Email`,` *`]}),(0,G.jsx)(`input`,{type:`email`,value:r.smtp_from_email,onChange:e=>i({...r,smtp_from_email:e.target.value}),placeholder:`your@email.com`,className:S})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:e(`settings.email.fromName`)||`From Name`}),(0,G.jsx)(`input`,{type:`text`,value:r.smtp_from_name,onChange:e=>i({...r,smtp_from_name:e.target.value}),placeholder:`BamBuddy`,className:S})]})]}),(0,G.jsx)(`div`,{className:`flex gap-2`,children:(0,G.jsx)(Q,{onClick:_,disabled:m.isPending,className:`flex-1`,children:m.isPending?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),e(`settings.email.saving`)||`Saving...`]}):e(`settings.email.save`)||`Save Settings`})})]})})]})}),(0,G.jsx)(`div`,{children:(0,G.jsxs)(zd,{id:`card-email-test`,children:[(0,G.jsx)(Bd,{children:(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`settings.email.testConnection`)||`Test SMTP Connection`})}),(0,G.jsx)(Vd,{children:(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:e(`settings.email.testRecipient`)||`Test Recipient Email`}),(0,G.jsx)(`input`,{type:`email`,value:a,onChange:e=>o(e.target.value),placeholder:`test@example.com`,className:S})]}),(0,G.jsx)(Q,{onClick:v,disabled:h.isPending,variant:`secondary`,children:h.isPending?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),e(`settings.email.sending`)||`Sending...`]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)($l,{className:`w-4 h-4`}),e(`settings.email.sendTest`)||`Send Test Email`]})})]})})]})})]})]})}var NGe={starttls:`389`,ldaps:`636`};function PGe(){let{t:e}=U(),{showToast:t}=qd(),n=co(),{authEnabled:r}=Nd(),[i,a]=(0,y.useState)({ldap_server_url:``,ldap_bind_dn:``,ldap_bind_password:``,ldap_search_base:``,ldap_user_filter:`(sAMAccountName={username})`,ldap_security:`starttls`,ldap_group_mapping:``,ldap_auto_provision:!1,ldap_default_group:``}),{data:o,isLoading:s}=K({queryKey:[`settings`],queryFn:()=>Z.getSettings()}),{data:c}=K({queryKey:[`ldapStatus`],queryFn:()=>Z.getLDAPStatus()}),{data:l=[]}=K({queryKey:[`groups`],queryFn:()=>Z.getGroups()});(0,y.useEffect)(()=>{o&&a({ldap_server_url:o.ldap_server_url||``,ldap_bind_dn:o.ldap_bind_dn||``,ldap_bind_password:``,ldap_search_base:o.ldap_search_base||``,ldap_user_filter:o.ldap_user_filter||`(sAMAccountName={username})`,ldap_security:o.ldap_security||`starttls`,ldap_group_mapping:o.ldap_group_mapping||``,ldap_auto_provision:o.ldap_auto_provision??!1,ldap_default_group:o.ldap_default_group||``})},[o]);let u=q({mutationFn:e=>Z.updateSettings(e),onSuccess:()=>{n.invalidateQueries({queryKey:[`settings`]}),n.invalidateQueries({queryKey:[`ldapStatus`]}),t(e(`settings.ldap.settingsSaved`)||`LDAP settings saved`,`success`)},onError:e=>{t(e.message,`error`)}}),d=q({mutationFn:e=>Z.updateSettings({ldap_enabled:e}),onSuccess:()=>{n.invalidateQueries({queryKey:[`settings`]}),n.invalidateQueries({queryKey:[`ldapStatus`]}),t(c?.ldap_enabled?e(`settings.ldap.disabled`)||`LDAP authentication disabled`:e(`settings.ldap.enabled`)||`LDAP authentication enabled`,`success`)},onError:e=>{t(e.message,`error`)}}),f=q({mutationFn:()=>Z.testLDAP(),onSuccess:e=>{t(e.message,e.success?`success`:`error`)},onError:e=>{t(e.message,`error`)}}),p=()=>{if(!i.ldap_server_url){t(e(`settings.ldap.errors.serverRequired`)||`LDAP server URL is required`,`error`);return}if(!i.ldap_search_base){t(e(`settings.ldap.errors.searchBaseRequired`)||`Search base DN is required`,`error`);return}let n={ldap_server_url:i.ldap_server_url,ldap_bind_dn:i.ldap_bind_dn,ldap_search_base:i.ldap_search_base,ldap_user_filter:i.ldap_user_filter,ldap_security:i.ldap_security,ldap_group_mapping:i.ldap_group_mapping,ldap_auto_provision:i.ldap_auto_provision,ldap_default_group:i.ldap_default_group};i.ldap_bind_password&&(n.ldap_bind_password=i.ldap_bind_password),u.mutate(n)},m=()=>{if(!r){t(e(`settings.ldap.errors.enableAuthFirst`)||`Enable authentication first`,`error`);return}if(!c?.ldap_enabled&&!c?.ldap_configured){t(e(`settings.ldap.errors.configureLdapFirst`)||`Save LDAP settings first`,`error`);return}d.mutate(!c?.ldap_enabled)};if(s)return(0,G.jsx)(`div`,{className:`flex items-center justify-center p-12`,children:(0,G.jsx)(Y,{className:`w-8 h-8 animate-spin text-bambu-green`})});let h=c?.ldap_enabled??!1,g=`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`;return(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(zd,{id:`card-ldap-toggle`,children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(su,{className:`w-5 h-5 text-bambu-green`}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`settings.ldap.title`)||`LDAP Authentication`})]}),(0,G.jsx)(Q,{onClick:m,disabled:d.isPending,variant:h?`danger`:`primary`,children:h?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(tl,{className:`w-4 h-4`}),e(`common.disable`)||`Disable`]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(nl,{className:`w-4 h-4`}),e(`common.enable`)||`Enable`]})})]})}),(0,G.jsx)(Vd,{children:h?(0,G.jsx)(`div`,{className:`bg-green-50 dark:bg-green-500/10 border border-green-300 dark:border-green-500/30 rounded-lg p-4`,children:(0,G.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,G.jsx)(xs,{className:`w-5 h-5 text-green-600 dark:text-green-400 mt-0.5 flex-shrink-0`}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`p`,{className:`text-white font-medium`,children:e(`settings.ldap.enabledDesc`)||`LDAP authentication is enabled`}),(0,G.jsxs)(`ul`,{className:`text-sm text-green-700 dark:text-green-300 space-y-1 list-disc list-inside`,children:[(0,G.jsx)(`li`,{children:e(`settings.ldap.feature1`)||`Users can login with LDAP credentials`}),(0,G.jsx)(`li`,{children:e(`settings.ldap.feature2`)||`Local admin account remains as fallback`}),(0,G.jsx)(`li`,{children:e(`settings.ldap.feature3`)||`LDAP groups are mapped to BamBuddy groups on login`})]})]})]})}):(0,G.jsx)(`div`,{className:`bg-yellow-50 dark:bg-yellow-500/10 border border-yellow-300 dark:border-yellow-500/30 rounded-lg p-4`,children:(0,G.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,G.jsx)(Lu,{className:`w-5 h-5 text-yellow-600 dark:text-yellow-400 mt-0.5 flex-shrink-0`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white font-medium`,children:e(`settings.ldap.disabledDesc`)||`LDAP authentication is disabled`}),(0,G.jsx)(`p`,{className:`text-sm text-yellow-700 dark:text-yellow-300 mt-1`,children:e(`settings.ldap.disabledHint`)||`Configure and save LDAP settings below, then enable.`})]})]})})})]}),(0,G.jsxs)(zd,{id:`card-ldap-server`,children:[(0,G.jsx)(Bd,{children:(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`settings.ldap.serverConfig`)||`LDAP Server Configuration`})}),(0,G.jsx)(Vd,{children:(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-3`,children:[(0,G.jsxs)(`div`,{className:`md:col-span-2`,children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:e(`settings.ldap.serverUrl`)||`Server URL`}),(0,G.jsx)(`input`,{type:`text`,className:g,placeholder:`ldaps://ldap.example.com:636`,value:i.ldap_server_url,onChange:e=>a({...i,ldap_server_url:e.target.value})}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`settings.ldap.serverUrlHint`)||`Use ldaps:// for SSL or ldap:// with StartTLS`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:e(`settings.ldap.security`)||`Security`}),(0,G.jsx)(`div`,{className:`flex gap-2`,children:[`starttls`,`ldaps`].map(e=>(0,G.jsx)(`button`,{onClick:()=>a({...i,ldap_security:e}),className:`flex-1 px-2 py-2 rounded-lg text-sm font-medium transition-colors ${i.ldap_security===e?`bg-bambu-green text-black`:`bg-bambu-dark-secondary text-bambu-gray hover:text-white border border-bambu-dark-tertiary`}`,children:e===`starttls`?`StartTLS`:`LDAPS`},e))}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`settings.ldap.securityHint`)||`Default port: ${NGe[i.ldap_security]}`})]})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:e(`settings.ldap.bindDn`)||`Bind DN (Service Account)`}),(0,G.jsx)(`input`,{type:`text`,className:g,placeholder:`cn=service-account,ou=service,dc=example,dc=com`,value:i.ldap_bind_dn,onChange:e=>a({...i,ldap_bind_dn:e.target.value})})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:e(`settings.ldap.bindPassword`)||`Bind Password`}),(0,G.jsx)(`input`,{type:`password`,className:g,placeholder:o?.ldap_bind_dn?`••••••••`:``,value:i.ldap_bind_password,onChange:e=>a({...i,ldap_bind_password:e.target.value})})]})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:e(`settings.ldap.searchBase`)||`Search Base DN`}),(0,G.jsx)(`input`,{type:`text`,className:g,placeholder:`ou=users,dc=example,dc=com`,value:i.ldap_search_base,onChange:e=>a({...i,ldap_search_base:e.target.value})})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:e(`settings.ldap.userFilter`)||`User Search Filter`}),(0,G.jsx)(`input`,{type:`text`,className:g,placeholder:`(sAMAccountName={username})`,value:i.ldap_user_filter,onChange:e=>a({...i,ldap_user_filter:e.target.value})})]})]}),(0,G.jsx)($p,{summary:(0,G.jsx)(`span`,{className:`text-sm font-medium text-bambu-gray`,children:e(`settings.ldap.advanced`)||`Advanced`}),className:`border-t border-bambu-dark-tertiary pt-3`,summaryClassName:`py-1`,children:(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white`,children:e(`settings.ldap.autoProvision`)||`Auto-provision users`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:e(`settings.ldap.autoProvisionHint`)||`Automatically create a BamBuddy account on first LDAP login`})]}),(0,G.jsx)(`button`,{onClick:()=>a({...i,ldap_auto_provision:!i.ldap_auto_provision}),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors flex-shrink-0 ${i.ldap_auto_provision?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,children:(0,G.jsx)(`span`,{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${i.ldap_auto_provision?`translate-x-6`:`translate-x-1`}`})})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:e(`settings.ldap.defaultGroup`)||`Default group`}),(0,G.jsxs)(`select`,{className:g,value:i.ldap_default_group,onChange:e=>a({...i,ldap_default_group:e.target.value}),children:[(0,G.jsx)(`option`,{value:``,children:e(`settings.ldap.defaultGroupNone`)||`— None (reject login) —`}),l.map(e=>(0,G.jsx)(`option`,{value:e.name,children:e.name},e.id))]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`settings.ldap.defaultGroupHint`)||`Fallback group assigned when an LDAP user authenticates but is not listed in any mapped group. Leave empty to leave unmapped users without permissions.`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:e(`settings.ldap.groupMapping`)||`Group Mapping (JSON)`}),(0,G.jsx)(`textarea`,{className:`${g} font-mono text-sm`,rows:4,placeholder:`{ "CN=PrintFarm_Admins,OU=Groups,DC=example,DC=com": "Administrators", "CN=PrintFarm_Users,OU=Groups,DC=example,DC=com": "Operators" }`,value:i.ldap_group_mapping,onChange:e=>a({...i,ldap_group_mapping:e.target.value})}),(0,G.jsxs)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:[e(`settings.ldap.groupMappingHint`)||`Map LDAP group DNs to BamBuddy groups. Available groups: `,l.map(e=>e.name).join(`, `)]})]})]})}),(0,G.jsxs)(`div`,{className:`flex gap-3 pt-2`,children:[(0,G.jsxs)(Q,{onClick:p,disabled:u.isPending,children:[u.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(xs,{className:`w-4 h-4`}),e(`common.save`)||`Save`]}),(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>f.mutate(),disabled:f.isPending,children:[f.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)($l,{className:`w-4 h-4`}),e(`settings.ldap.testConnection`)||`Test Connection`]})]})]})})]})]})}function R8({value:e,onChange:t,placeholder:n,maxLength:r=6}){return(0,G.jsx)(`input`,{type:`text`,value:e,onChange:e=>t(e.target.value.toUpperCase().replace(/\s/g,``)),maxLength:r,className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors font-mono tracking-widest text-center`,placeholder:n,autoComplete:`one-time-code`})}function z8({codes:e,onDone:t}){let{t:n}=U(),[r,i]=(0,y.useState)(!1);return(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsx)(`div`,{className:`bg-amber-50 dark:bg-amber-500/10 border border-amber-300 dark:border-amber-500/30 rounded-lg p-4`,children:(0,G.jsx)(`p`,{className:`text-amber-700 dark:text-amber-400 text-sm font-medium`,children:n(`settings.twoFa.backupCodesWarning`)})}),(0,G.jsx)(`div`,{className:`grid grid-cols-2 gap-2`,children:e.map((e,t)=>(0,G.jsx)(`code`,{className:`bg-bambu-dark-secondary rounded px-3 py-2 text-center font-mono text-sm text-white tracking-widest`,children:e},t))}),(0,G.jsxs)(`div`,{className:`flex gap-3`,children:[(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:()=>{navigator.clipboard.writeText(e.join(` -`)),i(!0),setTimeout(()=>i(!1),2e3)},className:`flex items-center gap-2`,children:[(0,G.jsx)(Vs,{className:`w-4 h-4`}),n(r?`common.copied`:`common.copy`)]}),(0,G.jsx)(Q,{variant:`primary`,size:`sm`,onClick:t,className:`flex-1`,children:n(`settings.twoFa.savedCodes`)})]})]})}function PGe({onDone:e}){let{t}=U(),n=co(),{showToast:r}=qd(),[i,a]=(0,y.useState)(`qr`),[o,s]=(0,y.useState)(``),[c,l]=(0,y.useState)([]),[u,d]=(0,y.useState)(!1),{data:f,isLoading:p}=K({queryKey:[`totp-setup`],queryFn:()=>Z.setupTOTP(),staleTime:1/0}),m=q({mutationFn:e=>Z.enableTOTP(e),onSuccess:e=>{l(e.backup_codes),a(`backup`),n.invalidateQueries({queryKey:[`2fa-status`]})},onError:()=>r(t(`settings.twoFa.invalidCode`),`error`)});return p||!f?(0,G.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,G.jsx)(Hl,{className:`w-6 h-6 animate-spin text-bambu-green`})}):i===`qr`?(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsx)(`p`,{className:`text-bambu-gray-light text-sm`,children:t(`settings.twoFa.setupInstructions`)}),(0,G.jsx)(`div`,{className:`flex justify-center`,children:(0,G.jsx)(`img`,{src:`data:image/png;base64,${f.qr_code_b64}`,alt:`TOTP QR Code`,className:`w-48 h-48 rounded-lg`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mb-1`,children:t(`settings.twoFa.manualEntry`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 bg-bambu-dark-secondary rounded-lg px-3 py-2`,children:[(0,G.jsx)(`code`,{className:`text-white text-xs font-mono flex-1 break-all`,children:u?f.secret:`••••••••••••••••`}),(0,G.jsx)(`button`,{onClick:()=>d(!u),className:`text-bambu-gray hover:text-white`,children:u?(0,G.jsx)(ic,{className:`w-4 h-4`}):(0,G.jsx)(ac,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:()=>{navigator.clipboard.writeText(f.secret)},className:`text-bambu-gray hover:text-white`,children:(0,G.jsx)(Vs,{className:`w-4 h-4`})})]})]}),(0,G.jsx)(Q,{variant:`primary`,className:`w-full`,onClick:()=>a(`confirm`),children:t(`settings.twoFa.scannedContinue`)})]}):i===`confirm`?(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsx)(`p`,{className:`text-bambu-gray-light text-sm`,children:t(`settings.twoFa.enterCodeToConfirm`)}),(0,G.jsx)(R8,{value:o,onChange:s,placeholder:`000000`}),(0,G.jsxs)(`div`,{className:`flex gap-3`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>a(`qr`),className:`flex-1`,children:t(`common.back`)}),(0,G.jsx)(Q,{variant:`primary`,className:`flex-1`,disabled:o.length!==6||m.isPending,onClick:()=>m.mutate(o),children:m.isPending?t(`common.saving`):t(`settings.twoFa.activate`)})]})]}):(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsx)(`h3`,{className:`text-white font-medium`,children:t(`settings.twoFa.backupCodesTitle`)}),(0,G.jsx)(z8,{codes:c,onDone:e})]})}function FGe(){let{t:e}=U(),t=co(),{showToast:n}=qd(),{user:r}=Nd(),[i,a]=(0,y.useState)(!1),[o,s]=(0,y.useState)(!1),[c,l]=(0,y.useState)(!1),[u,d]=(0,y.useState)(``),[f,p]=(0,y.useState)(``),[m,h]=(0,y.useState)(null),[g,_]=(0,y.useState)(null),[v,b]=(0,y.useState)(``),[x,S]=(0,y.useState)(!1),[C,w]=(0,y.useState)(``),[T,E]=(0,y.useState)(!1),{data:D,isLoading:O}=K({queryKey:[`2fa-status`],queryFn:()=>Z.get2FAStatus()}),{data:k}=K({queryKey:[`oidc-links`],queryFn:()=>Z.getOIDCLinks()}),A=q({mutationFn:()=>Z.enableEmailOTP(),onSuccess:e=>{_(e.setup_token),n(e.message,`success`)},onError:t=>{let r=t.message??``;r.toLowerCase().includes(`smtp`)?n(e(`settings.twoFa.smtpRequired`),`error`):n(r,`error`)}}),j=q({mutationFn:()=>Z.confirmEnableEmailOTP(g,v),onSuccess:()=>{t.invalidateQueries({queryKey:[`2fa-status`]}),_(null),b(``),n(e(`settings.twoFa.emailOtpEnabled`),`success`)},onError:e=>n(e.message,`error`)}),M=q({mutationFn:e=>Z.disableEmailOTP(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`2fa-status`]}),S(!1),w(``),n(e(`settings.twoFa.emailOtpDisabled`),`success`)},onError:e=>n(e.message,`error`)}),N=q({mutationFn:e=>Z.disableTOTP(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`2fa-status`]}),s(!1),d(``),n(e(`settings.twoFa.totpDisabled`),`success`)},onError:()=>n(e(`settings.twoFa.invalidCode`),`error`)}),P=q({mutationFn:e=>Z.regenerateBackupCodes(e),onSuccess:e=>{t.invalidateQueries({queryKey:[`2fa-status`]}),l(!1),p(``),h(e.backup_codes)},onError:()=>n(e(`settings.twoFa.invalidCode`),`error`)}),F=q({mutationFn:e=>Z.deleteOIDCLink(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`oidc-links`]}),n(e(`settings.twoFa.oidcUnlinked`),`success`)},onError:e=>n(e.message,`error`)});if(O)return(0,G.jsx)(`div`,{className:`flex items-center justify-center py-12`,children:(0,G.jsx)(Hl,{className:`w-6 h-6 animate-spin text-bambu-green`})});let I=!!r?.email;return(0,G.jsxs)(`div`,{className:`space-y-6`,children:[(0,G.jsxs)(zd,{id:`card-2fa-totp`,children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`w-10 h-10 rounded-full flex items-center justify-center ${D?.totp_enabled?`bg-green-100 dark:bg-green-500/20`:`bg-gray-500/20`}`,children:(0,G.jsx)(mu,{className:`w-5 h-5 ${D?.totp_enabled?`text-green-600 dark:text-green-400`:`text-gray-400`}`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`text-white font-semibold`,children:e(`settings.twoFa.totpTitle`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-sm`,children:e(`settings.twoFa.totpDesc`)})]}),(0,G.jsx)(`div`,{className:`ml-auto`,children:D?.totp_enabled?(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-green-700 dark:text-green-400 text-sm font-medium`,children:[(0,G.jsx)(au,{className:`w-4 h-4`}),` `,e(`common.enabled`)]}):(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-bambu-gray text-sm`,children:[(0,G.jsx)(ou,{className:`w-4 h-4`}),` `,e(`common.disabled`)]})})]})}),(0,G.jsx)(Vd,{children:i?(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,G.jsx)(`h4`,{className:`text-white font-medium`,children:e(`settings.twoFa.setupAuthApp`)}),(0,G.jsx)(`button`,{onClick:()=>{a(!1),t.removeQueries({queryKey:[`totp-setup`]})},className:`text-bambu-gray hover:text-white`,children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]}),(0,G.jsx)(PGe,{onDone:()=>{a(!1),t.removeQueries({queryKey:[`totp-setup`]})}})]}):o?(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsx)(`p`,{className:`text-bambu-gray-light text-sm`,children:e(`settings.twoFa.disableConfirmHint`)}),(0,G.jsx)(R8,{value:u,onChange:d,placeholder:`000000 or XXXXXXXX`,maxLength:8}),(0,G.jsxs)(`div`,{className:`flex gap-3`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>{s(!1),d(``)},className:`flex-1`,children:e(`common.cancel`)}),(0,G.jsx)(Q,{variant:`danger`,className:`flex-1`,disabled:u.length<6||N.isPending,onClick:()=>N.mutate(u),children:N.isPending?e(`common.saving`):e(`settings.twoFa.disableTotp`)})]})]}):c?(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsx)(`p`,{className:`text-bambu-gray-light text-sm`,children:e(`settings.twoFa.regenBackupHint`)}),(0,G.jsx)(R8,{value:f,onChange:p,placeholder:`000000 or XXXXXXXX`,maxLength:8}),(0,G.jsxs)(`div`,{className:`flex gap-3`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>{l(!1),p(``)},className:`flex-1`,children:e(`common.cancel`)}),(0,G.jsx)(Q,{variant:`primary`,className:`flex-1`,disabled:f.length<6||P.isPending,onClick:()=>P.mutate(f),children:P.isPending?e(`common.saving`):e(`settings.twoFa.regenBackup`)})]})]}):m?(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsx)(`h4`,{className:`text-white font-medium`,children:e(`settings.twoFa.newBackupCodes`)}),(0,G.jsx)(z8,{codes:m,onDone:()=>h(null)})]}):(0,G.jsx)(`div`,{className:`space-y-3`,children:D?.totp_enabled?(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-bambu-gray-light`,children:[(0,G.jsx)(Kc,{className:`w-4 h-4`}),e(`settings.twoFa.backupCodesRemaining`,{count:D.backup_codes_remaining})]}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:()=>l(!0),className:`flex items-center gap-2`,children:[(0,G.jsx)(Hl,{className:`w-4 h-4`}),e(`settings.twoFa.regenBackup`)]}),(0,G.jsxs)(Q,{variant:`danger`,size:`sm`,onClick:()=>s(!0),className:`flex items-center gap-2`,children:[(0,G.jsx)(Pu,{className:`w-4 h-4`}),e(`settings.twoFa.disableTotp`)]})]}):(0,G.jsxs)(Q,{variant:`primary`,onClick:()=>a(!0),className:`flex items-center gap-2`,children:[(0,G.jsx)(mu,{className:`w-4 h-4`}),e(`settings.twoFa.setupTotp`)]})})})]}),(0,G.jsxs)(zd,{id:`card-2fa-emailotp`,children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`w-10 h-10 rounded-full flex items-center justify-center ${D?.email_otp_enabled?`bg-green-100 dark:bg-green-500/20`:`bg-gray-500/20`}`,children:(0,G.jsx)(al,{className:`w-5 h-5 ${D?.email_otp_enabled?`text-green-600 dark:text-green-400`:`text-gray-400`}`})}),(0,G.jsxs)(`div`,{className:`flex-1`,children:[(0,G.jsx)(`h3`,{className:`text-white font-semibold`,children:e(`settings.twoFa.emailOtpTitle`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-sm`,children:I?e(`settings.twoFa.emailOtpDesc`,{email:r?.email}):e(`settings.twoFa.emailOtpNoEmail`)})]}),(0,G.jsx)(`div`,{className:`ml-auto`,children:D?.email_otp_enabled?(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-green-700 dark:text-green-400 text-sm font-medium`,children:[(0,G.jsx)(au,{className:`w-4 h-4`}),` `,e(`common.enabled`)]}):(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-bambu-gray text-sm`,children:[(0,G.jsx)(ou,{className:`w-4 h-4`}),` `,e(`common.disabled`)]})})]})}),(0,G.jsx)(Vd,{children:I?g?(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsx)(`p`,{className:`text-bambu-gray-light text-sm`,children:e(`settings.twoFa.emailSetupEnterCode`)}),(0,G.jsx)(R8,{value:v,onChange:b,placeholder:`000000`}),(0,G.jsxs)(`div`,{className:`flex gap-3`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>{_(null),b(``)},className:`flex-1`,children:e(`common.cancel`)}),(0,G.jsx)(Q,{variant:`primary`,className:`flex-1`,disabled:v.length!==6||j.isPending,onClick:()=>j.mutate(),children:j.isPending?e(`common.saving`):e(`settings.twoFa.verifyAndEnable`)})]})]}):x?(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsx)(`p`,{className:`text-bambu-gray-light text-sm`,children:e(`settings.twoFa.emailDisablePasswordHint`)}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(`input`,{type:T?`text`:`password`,value:C,onChange:e=>w(e.target.value),placeholder:e(`settings.twoFa.passwordPlaceholder`),className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>E(!T),className:`absolute right-3 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white`,children:T?(0,G.jsx)(ic,{className:`w-5 h-5`}):(0,G.jsx)(ac,{className:`w-5 h-5`})})]}),(0,G.jsxs)(`div`,{className:`flex gap-3`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>{S(!1),w(``)},className:`flex-1`,children:e(`common.cancel`)}),(0,G.jsx)(Q,{variant:`danger`,className:`flex-1`,disabled:!C||M.isPending,onClick:()=>M.mutate(C),children:M.isPending?e(`common.saving`):e(`settings.twoFa.disableEmailOtp`)})]})]}):(0,G.jsx)(`div`,{className:`flex gap-3`,children:D?.email_otp_enabled?(0,G.jsxs)(Q,{variant:`danger`,size:`sm`,onClick:()=>S(!0),className:`flex items-center gap-2`,children:[(0,G.jsx)(Pu,{className:`w-4 h-4`}),e(`settings.twoFa.disableEmailOtp`)]}):(0,G.jsxs)(Q,{variant:`primary`,disabled:!I||A.isPending,onClick:()=>A.mutate(),className:`flex items-center gap-2`,children:[(0,G.jsx)(al,{className:`w-4 h-4`}),A.isPending?e(`common.saving`):e(`settings.twoFa.enableEmailOtp`)]})}):(0,G.jsx)(`p`,{className:`text-amber-700 dark:text-amber-400 text-sm`,children:e(`settings.twoFa.addEmailFirst`)})})]}),k&&k.length>0&&(0,G.jsxs)(zd,{id:`card-2fa-linked`,children:[(0,G.jsxs)(Bd,{children:[(0,G.jsx)(`h3`,{className:`text-white font-semibold`,children:e(`settings.twoFa.linkedAccounts`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-sm`,children:e(`settings.twoFa.linkedAccountsDesc`)})]}),(0,G.jsx)(Vd,{children:(0,G.jsx)(`div`,{className:`space-y-3`,children:k.map(e=>(0,G.jsxs)(`div`,{className:`flex items-center justify-between py-2 border-b border-bambu-dark-tertiary last:border-0`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white text-sm font-medium`,children:e.provider_name}),e.provider_email&&(0,G.jsx)(`p`,{className:`text-bambu-gray text-xs`,children:e.provider_email})]}),(0,G.jsx)(Q,{variant:`danger`,size:`sm`,onClick:()=>F.mutate(e.provider_id),disabled:F.isPending,children:(0,G.jsx)(Pu,{className:`w-4 h-4`})})]},e.id))})})]})]})}var IGe={name:``,issuer_url:``,client_id:``,client_secret:``,scopes:`openid email profile`,is_enabled:!0,auto_create_users:!1,auto_link_existing_accounts:!1,email_claim:`email`,require_email_verified:!0,icon_url:void 0,default_group_id:null,is_autologin:!1};function B8({initial:e,isEdit:t=!1,groups:n=[],onSave:r,onCancel:i,isPending:a}){let{t:o}=U(),[s,c]=(0,y.useState)(e),[l,u]=(0,y.useState)(!1),d=(e,t)=>c(n=>({...n,[e]:t})),f=`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors text-sm`,p=`block text-sm font-medium text-white mb-1`,m=()=>{let e={...s};t&&!l&&delete e.client_secret,r(e)},h=s.auto_link_existing_accounts===!0,g=s.require_email_verified??!0,_;return _=h?o(`settings.oidc.form.requireEmailVerifiedAutoLink`):g?o(`settings.oidc.form.requireEmailVerifiedDesc`):(0,G.jsx)(`span`,{className:`text-red-700 dark:text-red-400`,children:o(`settings.oidc.form.requireEmailVerifiedWarning`)}),(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:p,children:[o(`settings.oidc.form.name`),` `,(0,G.jsx)(`span`,{className:`text-red-700 dark:text-red-400`,children:`*`})]}),(0,G.jsx)(`input`,{className:f,value:s.name,onChange:e=>d(`name`,e.target.value),placeholder:`Google`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:p,children:[o(`settings.oidc.form.issuerUrl`),` `,(0,G.jsx)(`span`,{className:`text-red-700 dark:text-red-400`,children:`*`})]}),(0,G.jsx)(`input`,{className:f,value:s.issuer_url,onChange:e=>d(`issuer_url`,e.target.value),placeholder:`https://accounts.google.com`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:p,children:[o(`settings.oidc.form.clientId`),` `,(0,G.jsx)(`span`,{className:`text-red-700 dark:text-red-400`,children:`*`})]}),(0,G.jsx)(`input`,{className:f,value:s.client_id,onChange:e=>d(`client_id`,e.target.value),placeholder:`your-client-id`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:p,children:[o(`settings.oidc.form.clientSecret`),!t&&(0,G.jsx)(`span`,{className:`text-red-700 dark:text-red-400`,children:` *`}),t&&(0,G.jsxs)(`span`,{className:`text-bambu-gray text-xs ml-1`,children:[`(`,o(`settings.oidc.form.secretHint`),`)`]})]}),(0,G.jsx)(`input`,{className:f,type:`password`,value:l?s.client_secret:``,placeholder:t&&!l?`••••••••`:o(`settings.oidc.form.secretPlaceholder`),onChange:e=>{u(!0),d(`client_secret`,e.target.value)}})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:p,children:o(`settings.oidc.form.scopes`)}),(0,G.jsx)(`input`,{className:f,value:s.scopes,onChange:e=>d(`scopes`,e.target.value),placeholder:`openid email profile`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:p,children:o(`settings.oidc.form.iconUrl`)}),(0,G.jsx)(`input`,{className:f,value:s.icon_url??``,onChange:e=>d(`icon_url`,e.target.value===``?null:e.target.value),placeholder:`https://...`})]})]}),(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-6 pt-2`,children:[(0,G.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,G.jsx)(fH,{checked:s.is_enabled??!0,onChange:e=>d(`is_enabled`,e)}),(0,G.jsx)(`span`,{className:`text-white text-sm`,children:o(`settings.oidc.form.enabled`)})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,G.jsx)(fH,{checked:s.auto_create_users??!1,onChange:e=>d(`auto_create_users`,e)}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white text-sm`,children:o(`settings.oidc.form.autoCreate`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-xs`,children:o(`settings.oidc.form.autoCreateDesc`)})]})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer w-full`,children:[(0,G.jsx)(fH,{checked:s.auto_link_existing_accounts??!1,onChange:e=>d(`auto_link_existing_accounts`,e)}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white text-sm`,children:o(`settings.oidc.form.autoLink`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-xs`,children:o(`settings.oidc.form.autoLinkDesc`)})]})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer w-full`,children:[(0,G.jsx)(fH,{checked:g,onChange:e=>d(`require_email_verified`,e),disabled:h}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white text-sm`,children:o(`settings.oidc.form.requireEmailVerified`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-xs`,children:_})]})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer w-full`,children:[(0,G.jsx)(fH,{checked:s.is_autologin??!1,onChange:e=>d(`is_autologin`,e)}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white text-sm`,children:o(`settings.oidc.form.autologin`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-xs`,children:o(`settings.oidc.form.autologinDesc`)})]})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:p,children:o(`settings.oidc.form.emailClaim`)}),(0,G.jsx)(`input`,{className:f,value:s.email_claim,onChange:e=>d(`email_claim`,e.target.value||`email`),placeholder:o(`settings.oidc.form.emailClaimPlaceholder`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-xs mt-1`,children:o(`settings.oidc.form.emailClaimDesc`)}),h&&s.email_claim!==`email`&&(0,G.jsx)(`p`,{className:`text-yellow-700 dark:text-yellow-400 text-xs mt-1`,children:o(`settings.oidc.form.emailClaimCustomClaimAutoLinkWarning`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:p,children:o(`settings.oidc.form.defaultGroup`)}),(0,G.jsxs)(`select`,{className:f,value:s.default_group_id??``,onChange:e=>d(`default_group_id`,e.target.value?Number(e.target.value):null),children:[(0,G.jsx)(`option`,{value:``,children:o(`settings.oidc.form.defaultGroupViewersFallback`)}),n.map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-xs mt-1`,children:o(`settings.oidc.form.defaultGroupDesc`)})]}),(0,G.jsxs)(`div`,{className:`flex gap-3 pt-2`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:i,className:`flex-1`,children:o(`common.cancel`)}),(0,G.jsx)(Q,{variant:`primary`,className:`flex-1`,disabled:!s.name||!s.issuer_url||!s.client_id||!t&&!s.client_secret||t&&l&&!s.client_secret||a,onClick:m,children:o(a?`common.saving`:`common.save`)})]})]})}function LGe({provider:e}){let[t,n]=(0,y.useState)(!1);return e.has_icon&&!t?(0,G.jsx)(`img`,{src:Z.oidcProviderIconUrl(e.id),alt:e.name,className:`w-8 h-8 rounded object-contain`,onError:()=>n(!0)}):(0,G.jsx)(`div`,{className:`w-8 h-8 rounded-full bg-bambu-dark-tertiary flex items-center justify-center`,children:(0,G.jsx)(Ac,{className:`w-4 h-4 text-bambu-gray`})})}function RGe(){let{t:e}=U(),t=co(),{showToast:n}=qd(),[r,i]=(0,y.useState)(!1),[a,o]=(0,y.useState)(null),[s,c]=(0,y.useState)(null),{data:l,isLoading:u}=K({queryKey:[`oidc-providers-all`],queryFn:()=>Z.getOIDCProvidersAll()}),{data:d=[]}=K({queryKey:[`groups`],queryFn:()=>Z.getGroups()}),f=q({mutationFn:e=>Z.createOIDCProvider(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`oidc-providers-all`]}),i(!1),n(e(`settings.oidc.created`),`success`)},onError:e=>n(e.message,`error`)}),p=q({mutationFn:({id:e,data:t})=>Z.updateOIDCProvider(e,t),onSuccess:()=>{t.invalidateQueries({queryKey:[`oidc-providers-all`]}),o(null),n(e(`settings.oidc.updated`),`success`)},onError:e=>n(e.message,`error`)}),m=q({mutationFn:e=>Z.deleteOIDCProvider(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`oidc-providers-all`]}),c(null),n(e(`settings.oidc.deleted`),`success`)},onError:e=>n(e.message,`error`)}),h=q({mutationFn:e=>Z.refreshOIDCProviderIcon(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`oidc-providers-all`]}),t.invalidateQueries({queryKey:[`oidc-providers`]}),n(e(`settings.oidc.iconRefreshed`),`success`)},onError:t=>n(t.message||e(`settings.oidc.iconFetchFailed`),`error`)}),g=q({mutationFn:e=>Z.deleteOIDCProviderIcon(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`oidc-providers-all`]}),t.invalidateQueries({queryKey:[`oidc-providers`]}),n(e(`settings.oidc.iconRemoved`),`success`)},onError:e=>n(e.message,`error`)}),_=e=>p.mutate({id:e.id,data:{is_enabled:!e.is_enabled}});return u?(0,G.jsx)(`div`,{className:`flex items-center justify-center py-12`,children:(0,G.jsx)(Hl,{className:`w-6 h-6 animate-spin text-bambu-green`})}):(0,G.jsxs)(`div`,{className:`space-y-6`,children:[(0,G.jsxs)(zd,{id:`card-oidc`,children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`text-white font-semibold`,children:e(`settings.oidc.title`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-sm`,children:e(`settings.oidc.desc`)})]}),!r&&(0,G.jsxs)(Q,{variant:`primary`,size:`sm`,onClick:()=>i(!0),className:`flex items-center gap-2`,children:[(0,G.jsx)(Fl,{className:`w-4 h-4`}),e(`settings.oidc.addProvider`)]})]})}),r&&(0,G.jsx)(Vd,{children:(0,G.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary pt-4`,children:[(0,G.jsx)(`h4`,{className:`text-white font-medium mb-4`,children:e(`settings.oidc.newProvider`)}),(0,G.jsx)(B8,{initial:IGe,groups:d,onSave:e=>f.mutate(e),onCancel:()=>i(!1),isPending:f.isPending})]})})]}),l&&l.length===0&&!r&&(0,G.jsx)(zd,{id:`card-oidc-empty`,children:(0,G.jsx)(Vd,{children:(0,G.jsxs)(`div`,{className:`text-center py-8 space-y-3`,children:[(0,G.jsx)(Ac,{className:`w-12 h-12 text-bambu-gray mx-auto`}),(0,G.jsx)(`p`,{className:`text-bambu-gray`,children:e(`settings.oidc.empty`)}),(0,G.jsxs)(Q,{variant:`primary`,size:`sm`,onClick:()=>i(!0),className:`inline-flex items-center gap-2`,children:[(0,G.jsx)(Fl,{className:`w-4 h-4`}),e(`settings.oidc.addProvider`)]})]})})}),l?.map(t=>(0,G.jsxs)(zd,{children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(LGe,{provider:t}),(0,G.jsxs)(`div`,{className:`flex-1`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`h4`,{className:`text-white font-medium`,children:t.name}),t.is_enabled?(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-xs text-green-700 dark:text-green-400 bg-green-50 dark:bg-green-400/10 px-2 py-0.5 rounded-full`,children:[(0,G.jsx)(fs,{className:`w-3 h-3`}),` `,e(`common.enabled`)]}):(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-xs text-bambu-gray bg-bambu-dark-tertiary px-2 py-0.5 rounded-full`,children:[(0,G.jsx)(nd,{className:`w-3 h-3`}),` `,e(`common.disabled`)]}),t.is_env_managed&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-xs text-bambu-green`,children:[(0,G.jsx)(nl,{className:`w-3 h-3`}),` `,e(`settings.environmentManagedLabel`)]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1 text-bambu-gray text-xs mt-0.5`,children:[(0,G.jsx)(rc,{className:`w-3 h-3`}),(0,G.jsx)(`span`,{children:t.issuer_url})]})]}),(0,G.jsx)(`div`,{className:`flex items-center gap-2`,children:!t.is_env_managed&&(0,G.jsxs)(G.Fragment,{children:[t.icon_url&&(0,G.jsx)(Q,{variant:`secondary`,size:`sm`,onClick:()=>h.mutate(t.id),disabled:h.isPending,title:e(`settings.oidc.refreshIcon`),"data-testid":`refresh-icon-${t.id}`,children:(0,G.jsx)(Hl,{className:`w-4 h-4 ${h.isPending?`animate-spin`:``}`})}),t.has_icon&&(0,G.jsx)(Q,{variant:`secondary`,size:`sm`,onClick:()=>g.mutate(t.id),disabled:g.isPending,title:e(`settings.oidc.removeIcon`),"data-testid":`remove-icon-${t.id}`,children:(0,G.jsx)(Vc,{className:`w-4 h-4`})}),(0,G.jsx)(fH,{checked:t.is_enabled,onChange:()=>_(t),disabled:p.isPending}),(0,G.jsx)(Q,{variant:`secondary`,size:`sm`,onClick:()=>o(a===t.id?null:t.id),"data-testid":`edit-provider-${t.id}`,children:(0,G.jsx)(kl,{className:`w-4 h-4`})}),(0,G.jsx)(Q,{variant:`danger`,size:`sm`,onClick:()=>c(t),"data-testid":`delete-provider-${t.id}`,children:(0,G.jsx)(Pu,{className:`w-4 h-4`})})]})})]})}),a===t.id&&(0,G.jsx)(Vd,{children:(0,G.jsx)(`div`,{className:`border-t border-bambu-dark-tertiary pt-4`,children:(0,G.jsx)(B8,{isEdit:!0,groups:d,initial:{name:t.name,issuer_url:t.issuer_url,client_id:t.client_id,client_secret:``,scopes:t.scopes,is_enabled:t.is_enabled,auto_create_users:t.auto_create_users,auto_link_existing_accounts:t.auto_link_existing_accounts,email_claim:t.email_claim,require_email_verified:t.require_email_verified,icon_url:t.icon_url??void 0,default_group_id:t.default_group_id??null,is_autologin:t.is_autologin},onSave:e=>p.mutate({id:t.id,data:e}),onCancel:()=>o(null),isPending:p.isPending})})}),a!==t.id&&(0,G.jsx)(Vd,{children:(0,G.jsxs)(`dl`,{className:`grid grid-cols-2 sm:grid-cols-3 gap-x-6 gap-y-2 text-sm`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`dt`,{className:`text-bambu-gray`,children:e(`settings.oidc.form.clientId`)}),(0,G.jsx)(`dd`,{className:`text-white font-mono truncate`,children:t.client_id})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`dt`,{className:`text-bambu-gray`,children:e(`settings.oidc.form.scopes`)}),(0,G.jsx)(`dd`,{className:`text-white`,children:t.scopes})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`dt`,{className:`text-bambu-gray`,children:e(`settings.oidc.form.autoCreate`)}),(0,G.jsx)(`dd`,{className:t.auto_create_users?`text-green-700 dark:text-green-400`:`text-bambu-gray`,children:t.auto_create_users?e(`common.yes`):e(`common.no`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`dt`,{className:`text-bambu-gray`,children:e(`settings.oidc.form.autoLink`)}),(0,G.jsx)(`dd`,{className:t.auto_link_existing_accounts?`text-green-700 dark:text-green-400`:`text-bambu-gray`,children:t.auto_link_existing_accounts?e(`common.yes`):e(`common.no`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`dt`,{className:`text-bambu-gray`,children:e(`settings.oidc.form.emailClaim`)}),(0,G.jsx)(`dd`,{className:`text-white font-mono`,children:t.email_claim})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`dt`,{className:`text-bambu-gray`,children:e(`settings.oidc.form.requireEmailVerified`)}),(0,G.jsx)(`dd`,{className:t.require_email_verified?`text-green-700 dark:text-green-400`:`text-red-700 dark:text-red-400`,children:t.require_email_verified?e(`common.yes`):e(`common.no`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`dt`,{className:`text-bambu-gray`,children:e(`settings.oidc.form.defaultGroup`)}),(0,G.jsx)(`dd`,{className:`text-white`,children:t.default_group_id?d.find(e=>e.id===t.default_group_id)?.name??e(`settings.oidc.form.defaultGroupViewersFallback`):e(`settings.oidc.form.defaultGroupViewersFallback`)})]})]})})]},t.id)),s&&(0,G.jsx)(of,{title:e(`settings.oidc.deleteTitle`),message:e(`settings.oidc.deleteMessage`,{name:s.name}),confirmText:e(`common.delete`),variant:`danger`,onConfirm:()=>m.mutate(s.id),onCancel:()=>c(null)})]})}var V8=new Map;function H8(e){V8.set(e.anchor,e)}function zGe(){return Array.from(V8.values())}H8({labelKey:`settings.encryption.title`,labelFallback:`MFA Encryption Status`,tab:`users`,subTab:`security`,keywords:`mfa encryption status security backup totp oidc fernet`,anchor:`card-mfa-encryption`});function BGe(){let{t:e}=U(),{data:t,isLoading:n,isError:r,refetch:i}=K({queryKey:[`encryptionStatus`],queryFn:()=>Z.getEncryptionStatus(),refetchInterval:e=>{if(!e.state.error)return 3e4;let t=e.state.fetchFailureCount??0;return t<=3?Math.min(5e3*Math.max(1,t),3e4):!1}});if(n)return(0,G.jsxs)(zd,{id:`card-mfa-encryption`,"data-testid":`encryption-status-card`,children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(su,{className:`text-bambu-gray`,size:20}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold`,children:e(`settings.encryption.title`)})]})}),(0,G.jsx)(Vd,{children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray`,"data-testid":`encryption-loading`,children:[(0,G.jsx)(Y,{className:`animate-spin`,size:16}),(0,G.jsx)(`span`,{children:e(`common.loading`)})]})})]});if(r||!t)return(0,G.jsxs)(zd,{id:`card-mfa-encryption`,"data-testid":`encryption-status-card`,children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(su,{className:`text-bambu-gray`,size:20}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold`,children:e(`settings.encryption.title`)})]})}),(0,G.jsxs)(Vd,{children:[(0,G.jsx)(`div`,{className:`text-red-700 dark:text-red-400`,"data-testid":`encryption-error`,children:e(`common.errorLoading`)}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>i(),className:`mt-2 text-sm text-blue-700 dark:text-blue-400 underline hover:text-blue-800 dark:hover:text-blue-300`,"data-testid":`encryption-retry-button`,children:e(`common.retry`)})]})]});let a=t.legacy_plaintext_rows.oidc_providers+t.legacy_plaintext_rows.user_totp,o=t.encrypted_rows.oidc_providers+t.encrypted_rows.user_totp,s,c,l,u;t.decryption_broken?(s=`bg-red-100 dark:bg-red-500/20 border-red-400 dark:border-red-500/50 text-red-700 dark:text-red-400`,c=(0,G.jsx)(Ds,{className:`text-red-600 dark:text-red-400`,size:20}),l=e(`settings.encryption.decryptionBrokenTitle`),u=e(`settings.encryption.decryptionBrokenError`,{count:o})):t.key_source===`generated`?(s=`bg-amber-50 dark:bg-amber-500/10 border-amber-300 dark:border-amber-500/30 text-amber-700 dark:text-amber-400`,c=(0,G.jsx)(au,{className:`text-amber-600 dark:text-amber-400`,size:20}),l=e(`settings.encryption.enabledGenerated`),u=e(`settings.encryption.backupHint`)):a>0?(s=`bg-amber-50 dark:bg-amber-500/10 border-amber-300 dark:border-amber-500/30 text-amber-700 dark:text-amber-400`,c=(0,G.jsx)(Lu,{className:`text-amber-600 dark:text-amber-400`,size:20}),l=t.key_source===`env`?e(`settings.encryption.enabledFromEnv`):e(`settings.encryption.enabledFromFile`),u=e(`settings.encryption.legacyRowsWarning`,{count:a})):t.key_configured?(s=`bg-green-100 dark:bg-green-500/20 border-green-300 dark:border-green-500/30 text-green-700 dark:text-green-400`,c=(0,G.jsx)(au,{className:`text-green-600 dark:text-green-400`,size:20}),l=t.key_source===`env`?e(`settings.encryption.enabledFromEnv`):e(`settings.encryption.enabledFromFile`),u=e(`settings.encryption.allEncrypted`)):(s=`bg-gray-500/20 border-gray-500/30 text-gray-400`,c=(0,G.jsx)(ou,{className:`text-gray-400`,size:20}),l=e(`settings.encryption.notConfigured`),u=e(`settings.encryption.notConfiguredDesc`));let d=t.key_source===`generated`&&a>0;return(0,G.jsxs)(zd,{id:`card-mfa-encryption`,"data-testid":`encryption-status-card`,children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[c,(0,G.jsx)(`h2`,{className:`text-lg font-semibold`,children:e(`settings.encryption.title`)})]})}),(0,G.jsxs)(Vd,{children:[(0,G.jsxs)(`div`,{className:`p-3 border rounded-lg ${s}`,"data-testid":`encryption-status`,children:[(0,G.jsx)(`p`,{className:`font-medium mb-1`,children:l}),(0,G.jsx)(`p`,{className:`text-sm`,children:u})]}),d&&(0,G.jsx)(`div`,{className:`mt-2 p-3 border rounded-lg bg-amber-50 dark:bg-amber-500/10 border-amber-300 dark:border-amber-500/30 text-amber-700 dark:text-amber-400`,"data-testid":`encryption-legacy-warning`,children:(0,G.jsx)(`p`,{className:`text-sm`,children:e(`settings.encryption.legacyRowsWarning`,{count:a})})}),t.migration_error_count>0&&(0,G.jsx)(`div`,{className:`mt-2 p-3 border rounded-lg bg-amber-50 dark:bg-amber-500/10 border-amber-300 dark:border-amber-500/30 text-amber-700 dark:text-amber-400`,"data-testid":`encryption-migration-warning`,children:(0,G.jsx)(`p`,{className:`text-sm`,children:e(`settings.encryption.migrationErrorWarning`,{count:t.migration_error_count})})}),(0,G.jsxs)(`div`,{className:`mt-4 grid grid-cols-2 gap-4 text-sm`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-bambu-gray`,children:e(`settings.encryption.encryptedRowsLabel`)}),(0,G.jsxs)(`p`,{className:`font-medium`,children:[`OIDC: `,t.encrypted_rows.oidc_providers,` · TOTP: `,t.encrypted_rows.user_totp]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-bambu-gray`,children:e(`settings.encryption.legacyRowsLabel`)}),(0,G.jsxs)(`p`,{className:`font-medium`,children:[`OIDC: `,t.legacy_plaintext_rows.oidc_providers,` · TOTP: `,t.legacy_plaintext_rows.user_totp]})]})]})]})]})}var VGe={get:`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400 border-blue-300 dark:border-blue-500/30`,post:`bg-green-100 dark:bg-green-500/20 text-green-700 dark:text-green-400 border-green-300 dark:border-green-500/30`,put:`bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400 border-yellow-300 dark:border-yellow-500/30`,patch:`bg-orange-100 dark:bg-orange-500/20 text-orange-700 dark:text-orange-400 border-orange-300 dark:border-orange-500/30`,delete:`bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400 border-red-300 dark:border-red-500/30`};function HGe(e,t){let n=t.replace(`#/`,``).split(`/`),r=e;for(let e of n)r=r[e];return r}function U8(e,t,n=0){if(n>5)return`...`;if(t.$ref)return U8(e,HGe(e,t.$ref),n+1);if(t.allOf){let r={};for(let i of t.allOf){let t=U8(e,i,n+1);typeof t==`object`&&t&&Object.assign(r,t)}return r}if(t.example!==void 0)return t.example;if(t.default!==void 0)return t.default;switch(t.type){case`string`:return t.enum?t.enum[0]:`string`;case`integer`:case`number`:return 0;case`boolean`:return!1;case`array`:return t.items?[U8(e,t.items,n+1)]:[];case`object`:if(t.properties){let r={};for(let[i,a]of Object.entries(t.properties))r[i]=U8(e,a,n+1);return r}return{};default:return null}}function UGe({path:e,method:t,spec:n,schema:r,apiKey:i}){let[a,o]=(0,y.useState)(!1),[s,c]=(0,y.useState)({}),[l,u]=(0,y.useState)(``),[d,f]=(0,y.useState)(null),[p,m]=(0,y.useState)(!1),[h,g]=(0,y.useState)(!1);(0,y.useEffect)(()=>{if(a&&n.parameters){let e={};for(let t of n.parameters)t.schema?.default!==void 0&&(e[t.name]=String(t.schema.default));c(t=>({...e,...t}))}},[a,n.parameters]),(0,y.useEffect)(()=>{if(a&&n.requestBody?.content?.[`application/json`]?.schema&&!l){let e=n.requestBody.content[`application/json`].schema,t=U8(r,e);u(JSON.stringify(t,null,2))}},[a,n.requestBody,r,l]);let _=(()=>{let e=[];for(let t of n.parameters||[])if(t.in===`path`||t.required){let n=s[t.name];(n===void 0||n===``)&&e.push(t.name)}return e})(),v=async()=>{if(_.length>0){f({status:0,statusText:`Validation Error`,headers:{},body:`Missing required parameters: ${_.join(`, `)}`,duration:0});return}m(!0),f(null);try{let r=e,a=new URLSearchParams;for(let e of n.parameters||[]){let t=s[e.name];t!==void 0&&t!==``&&(e.in===`path`?r=r.replace(`{${e.name}}`,encodeURIComponent(t)):e.in===`query`&&a.append(e.name,t))}let o=a.toString(),c=`${r}${o?`?${o}`:``}`,u={"Content-Type":`application/json`};i&&(u[`X-API-Key`]=i);let d={method:t.toUpperCase(),headers:u};[`post`,`put`,`patch`].includes(t)&&l&&(d.body=l);let p=performance.now(),m=await fetch(c,d),h=Math.round(performance.now()-p),g={};m.headers.forEach((e,t)=>{g[t]=e});let _;_=m.headers.get(`content-type`)?.includes(`application/json`)?await m.json():await m.text(),f({status:m.status,statusText:m.statusText,headers:g,body:_,duration:h})}catch(e){f({status:0,statusText:`Network Error`,headers:{},body:e instanceof Error?e.message:`Unknown error`,duration:0})}finally{m(!1)}},b=async()=>{if(d){let e=typeof d.body==`string`?d.body:JSON.stringify(d.body,null,2);try{await navigator.clipboard.writeText(e),g(!0),setTimeout(()=>g(!1),2e3)}catch{let t=document.createElement(`textarea`);t.value=e,t.style.position=`fixed`,t.style.left=`-999999px`,document.body.appendChild(t),t.select(),document.execCommand(`copy`),document.body.removeChild(t),g(!0),setTimeout(()=>g(!1),2e3)}}},x=(n.parameters||[]).filter(e=>e.in===`path`),S=(n.parameters||[]).filter(e=>e.in===`query`),C=[`post`,`put`,`patch`].includes(t)&&n.requestBody;return(0,G.jsxs)(`div`,{className:`border border-bambu-dark-tertiary rounded-lg overflow-hidden`,children:[(0,G.jsxs)(`button`,{onClick:()=>o(!a),className:`w-full flex items-center gap-3 p-3 hover:bg-bambu-dark-tertiary/50 transition-colors text-left`,children:[a?(0,G.jsx)(ps,{className:`w-4 h-4 text-bambu-gray flex-shrink-0`}):(0,G.jsx)(ms,{className:`w-4 h-4 text-bambu-gray flex-shrink-0`}),(0,G.jsx)(`span`,{className:`px-2 py-0.5 text-xs font-mono font-semibold uppercase rounded border ${VGe[t]||`bg-gray-500/20 text-gray-400`}`,children:t}),(0,G.jsx)(`code`,{className:`text-sm text-white font-mono flex-1 truncate`,children:e}),n.summary&&(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray truncate max-w-[40%]`,children:n.summary})]}),a&&(0,G.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary p-4 space-y-4 bg-bambu-dark/50`,children:[n.description&&(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n.description}),x.length>0&&(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`h4`,{className:`text-sm font-medium text-white`,children:`Path Parameters`}),(0,G.jsx)(`div`,{className:`space-y-2`,children:x.map(e=>(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`label`,{className:`text-sm text-bambu-gray w-32 flex-shrink-0`,children:[e.name,e.required&&(0,G.jsx)(`span`,{className:`text-red-700 dark:text-red-400 ml-1`,children:`*`})]}),(0,G.jsx)(`input`,{type:`text`,value:s[e.name]||``,onChange:t=>c(n=>({...n,[e.name]:t.target.value})),placeholder:e.description||e.schema?.type||`value`,className:`flex-1 px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm font-mono focus:border-bambu-green focus:outline-none`})]},e.name))})]}),S.length>0&&(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`h4`,{className:`text-sm font-medium text-white`,children:`Query Parameters`}),(0,G.jsx)(`div`,{className:`space-y-2`,children:S.map(e=>(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`label`,{className:`text-sm text-bambu-gray w-32 flex-shrink-0`,children:[e.name,e.required&&(0,G.jsx)(`span`,{className:`text-red-700 dark:text-red-400 ml-1`,children:`*`})]}),e.schema?.enum?(0,G.jsxs)(`select`,{value:s[e.name]||``,onChange:t=>c(n=>({...n,[e.name]:t.target.value})),className:`flex-1 px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`,children:[(0,G.jsx)(`option`,{value:``,children:`-- Select --`}),e.schema.enum.map(e=>(0,G.jsx)(`option`,{value:e,children:e},e))]}):(0,G.jsx)(`input`,{type:`text`,value:s[e.name]||``,onChange:t=>c(n=>({...n,[e.name]:t.target.value})),placeholder:e.description||e.schema?.type||`value`,className:`flex-1 px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm font-mono focus:border-bambu-green focus:outline-none`})]},e.name))})]}),C&&(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`h4`,{className:`text-sm font-medium text-white`,children:`Request Body`}),(0,G.jsx)(`textarea`,{value:l,onChange:e=>u(e.target.value),rows:8,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm font-mono focus:border-bambu-green focus:outline-none resize-y`,placeholder:`JSON request body...`})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(Q,{onClick:v,disabled:p,children:[p?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Nl,{className:`w-4 h-4`}),`Execute`]}),_.length>0&&(0,G.jsxs)(`span`,{className:`text-xs text-yellow-700 dark:text-yellow-400 flex items-center gap-1`,children:[(0,G.jsx)(ys,{className:`w-3 h-3`}),`Fill in: `,_.join(`, `)]})]}),d&&(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`h4`,{className:`text-sm font-medium text-white flex items-center gap-2`,children:[`Response`,(0,G.jsxs)(`span`,{className:`px-2 py-0.5 text-xs rounded ${d.status>=200&&d.status<300?`bg-green-100 dark:bg-green-500/20 text-green-700 dark:text-green-400`:d.status>=400?`bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400`:`bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400`}`,children:[d.status,` `,d.statusText]}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[d.duration,`ms`]})]}),(0,G.jsx)(Q,{variant:`secondary`,size:`sm`,onClick:b,children:h?(0,G.jsx)(xs,{className:`w-3 h-3 text-green-600 dark:text-green-400`}):(0,G.jsx)(Vs,{className:`w-3 h-3`})})]}),(0,G.jsx)(`pre`,{className:`p-3 bg-bambu-dark rounded-lg text-sm font-mono text-white overflow-auto max-h-96 border border-bambu-dark-tertiary`,children:typeof d.body==`string`?d.body:JSON.stringify(d.body,null,2)})]})]})]})}function WGe({apiKey:e=``}){let[t,n]=(0,y.useState)(null),[r,i]=(0,y.useState)(!0),[a,o]=(0,y.useState)(null),[s,c]=(0,y.useState)(new Set),[l,u]=(0,y.useState)(``);if((0,y.useEffect)(()=>{async function e(){try{let e=await fetch(`/openapi.json`);if(!e.ok)throw Error(`Failed to fetch OpenAPI schema`);n(await e.json())}catch(e){o(e instanceof Error?e.message:`Unknown error`)}finally{i(!1)}}e()},[]),r)return(0,G.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,G.jsx)(Y,{className:`w-8 h-8 text-bambu-green animate-spin`})});if(a||!t)return(0,G.jsx)(zd,{children:(0,G.jsx)(Vd,{className:`py-8`,children:(0,G.jsxs)(`div`,{className:`text-center text-red-700 dark:text-red-400`,children:[(0,G.jsx)(ys,{className:`w-12 h-12 mx-auto mb-3 opacity-50`}),(0,G.jsx)(`p`,{children:`Failed to load API schema`}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:a})]})})});let d={};for(let[e,n]of Object.entries(t.paths))for(let[t,r]of Object.entries(n)){if(t===`parameters`)continue;let n=r.tags||[`Other`];for(let i of n)d[i]||(d[i]=[]),d[i].push({path:e,method:t,spec:r})}let f=Object.entries(d).map(([e,t])=>l?{tag:e,endpoints:t.filter(({path:e,method:t,spec:n})=>{let r=l.toLowerCase();return e.toLowerCase().includes(r)||t.toLowerCase().includes(r)||(n.summary?.toLowerCase()||``).includes(r)||(n.description?.toLowerCase()||``).includes(r)})}:{tag:e,endpoints:t}).filter(({endpoints:e})=>e.length>0).sort((e,t)=>e.tag.localeCompare(t.tag)),p=e=>{c(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})};return(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,G.jsx)(`div`,{className:`flex-1`,children:(0,G.jsx)(`input`,{type:`text`,value:l,onChange:e=>u(e.target.value),placeholder:`Search endpoints...`,className:`w-full max-w-md px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Q,{variant:`secondary`,size:`sm`,onClick:()=>{c(new Set(f.map(e=>e.tag)))},children:`Expand All`}),(0,G.jsx)(Q,{variant:`secondary`,size:`sm`,onClick:()=>{c(new Set)},children:`Collapse All`}),(0,G.jsxs)(`a`,{href:`/docs`,target:`_blank`,rel:`noopener noreferrer`,className:`flex items-center gap-1 text-sm text-bambu-green hover:underline`,children:[(0,G.jsx)(rc,{className:`w-4 h-4`}),`Swagger UI`]})]})]}),(0,G.jsxs)(`p`,{className:`text-sm text-bambu-gray`,children:[f.reduce((e,t)=>e+t.endpoints.length,0),` endpoints in `,f.length,` categories`]}),(0,G.jsx)(`div`,{className:`space-y-3`,children:f.map(({tag:n,endpoints:r})=>(0,G.jsxs)(zd,{children:[(0,G.jsx)(`button`,{onClick:()=>p(n),className:`w-full flex items-center justify-between p-4 hover:bg-bambu-dark-tertiary/30 transition-colors text-left`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[s.has(n)?(0,G.jsx)(ps,{className:`w-5 h-5 text-bambu-gray`}):(0,G.jsx)(ms,{className:`w-5 h-5 text-bambu-gray`}),(0,G.jsx)(`h3`,{className:`text-base font-semibold text-white capitalize`,children:n.replace(/-/g,` `)}),(0,G.jsx)(`span`,{className:`text-xs bg-bambu-dark-tertiary px-2 py-0.5 rounded-full text-bambu-gray`,children:r.length})]})}),s.has(n)&&(0,G.jsx)(Vd,{className:`pt-0 space-y-2`,children:r.map(({path:n,method:r,spec:i})=>(0,G.jsx)(UGe,{path:n,method:r,spec:i,schema:t,apiKey:e},`${r}-${n}`))})]},n))})]})}var GGe=[{id:`sidecar`,labelKey:`settings.sliceEngineSidecar`,descriptionKey:`settings.sliceEngineSidecarHint`,available:!0},{id:`browser`,labelKey:`settings.sliceEngineBrowser`,descriptionKey:`settings.sliceEngineBrowserHint`,available:!1}];function W8(){return GGe.filter(e=>e.available)}function KGe(){return W8().length>1}function G8(e){return W8().find(t=>t.id===e)?.id??`sidecar`}var qGe=[`general`,`plugs`,`sensors`,`notifications`,`queue`,`filament`,`network`,`apikeys`,`virtual-printer`,`spoolbuddy`,`failure-detection`,`users`,`backup`];H8({labelKey:`settings.general`,tab:`general`,keywords:`language date time format printer model printers cards`,anchor:`card-general`}),H8({labelKey:`settings.appearance`,tab:`general`,keywords:`theme dark light mode colors`,anchor:`card-appearance`}),H8({labelKey:`settings.archiveSettings`,tab:`general`,keywords:`archive auto save thumbnails captures`,anchor:`card-archive`}),H8({labelKey:`settings.camera`,tab:`general`,keywords:`camera external video stream`,anchor:`card-camera`}),H8({labelKey:`settings.costTracking`,tab:`general`,keywords:`currency filament cost energy kwh price`,anchor:`card-cost`}),H8({labelKey:`settings.fileManager`,tab:`general`,keywords:`file manager archive mode disk warning storage`,anchor:`card-filemanager`}),H8({labelKey:`settings.updates`,tab:`general`,keywords:`updates version firmware beta check`,anchor:`card-updates`}),H8({labelKey:`settings.dataManagement`,tab:`general`,keywords:`data reset clear logs notifications preferences`,anchor:`card-data`}),H8({labelKey:`settings.smartPlugs`,tab:`plugs`,keywords:`smart plug energy power automation tapo kasa tplink shelly`,anchor:`card-plugs`}),H8({labelKey:`haSensors.sectionTitle`,tab:`sensors`,keywords:`home assistant sensor printer temperature humidity alert notify block print`,anchor:`card-ha-sensors`}),H8({labelKey:`locationHaSensors.sectionTitle`,tab:`sensors`,keywords:`home assistant sensor location storage box temperature humidity battery alert notify`,anchor:`card-location-sensors`}),H8({labelKey:`settings.providers`,tab:`notifications`,keywords:`telegram discord email notification providers webhook`,anchor:`card-providers`}),H8({labelKey:`settings.messageTemplates`,tab:`notifications`,keywords:`message templates notification text edit`,anchor:`card-templates`}),H8({labelKey:`settings.defaultPrintOptions`,labelFallback:`Default Print Options`,tab:`queue`,keywords:`print bed leveling flow calibration vibration first layer timelapse`,anchor:`card-print-options`}),H8({labelKey:`settings.tempFanPresetsTitle`,labelFallback:`Temperature & Fan Presets`,tab:`queue`,keywords:`temperature fan presets nozzle bed chamber quick buttons popover`,anchor:`card-temp-fan-presets`}),H8({labelKey:`settings.staggeredStart`,labelFallback:`Staggered Start`,tab:`queue`,keywords:`staggered batch delay start queue group`,anchor:`card-staggered`}),H8({labelKey:`settings.plateClear`,labelFallback:`Plate-Clear Confirmation`,tab:`queue`,keywords:`plate clear confirm auto queue`,anchor:`card-plate`}),H8({labelKey:`settings.concurrentUploadsTitle`,labelFallback:`Concurrent Uploads`,tab:`queue`,keywords:`concurrent parallel upload transfer ftp queue slow farm simultaneous`,anchor:`card-concurrent-uploads`}),H8({labelKey:`settings.gcodeInjection`,labelFallback:`G-code Injection`,tab:`queue`,keywords:`gcode injection start end autoprint farmloop swapmod autoclear printflow`,anchor:`card-gcode`}),H8({labelKey:`settings.slicerCard`,labelFallback:`Slicer`,tab:`queue`,keywords:`slicer orcaslicer bambustudio orca bambu api sidecar url docker preferred`,anchor:`card-slicer`}),H8({labelKey:`settings.queueDrying`,tab:`queue`,keywords:`drying presets temperature time humidity ams`,anchor:`card-drying`}),H8({labelKey:`settings.filamentChecks`,tab:`filament`,keywords:`filament check warning runout remaining`,anchor:`card-filamentchecks`}),H8({labelKey:`settings.printModal`,tab:`filament`,keywords:`print modal custom mapping`,anchor:`card-printmodal`}),H8({labelKey:`settings.amsDisplayThresholds`,tab:`filament`,keywords:`ams humidity temperature threshold history retention`,anchor:`card-amsthresholds`}),H8({labelKey:`settings.externalUrl`,tab:`network`,keywords:`external url reverse proxy public notification link`,anchor:`card-externalurl`}),H8({labelKey:`settings.ftpRetry`,tab:`network`,keywords:`ftp retry upload retries backoff`,anchor:`card-ftpretry`}),H8({labelKey:`settings.homeAssistant`,tab:`network`,keywords:`home assistant ha hass mqtt integration`,anchor:`card-ha`}),H8({labelKey:`settings.mqttPublishing`,tab:`network`,keywords:`mqtt publish broker topic`,anchor:`card-mqtt`}),H8({labelKey:`settings.prometheusMetrics`,tab:`network`,keywords:`prometheus metrics grafana monitoring bearer token`,anchor:`card-prometheus`}),H8({labelKey:`settings.createNewApiKey`,tab:`apikeys`,keywords:`api key create permission scope`,anchor:`card-createapi`}),H8({labelKey:`settings.webhookEndpoints`,tab:`apikeys`,keywords:`webhook endpoint post http`,anchor:`card-webhooks`}),H8({labelKey:`settings.apiBrowser`,tab:`apikeys`,keywords:`api browser endpoint documentation test`,anchor:`card-apibrowser`}),H8({labelKey:`cameraTokens.title`,tab:`apikeys`,keywords:`camera token long-lived home assistant frigate kiosk stream`,anchor:`card-camera-tokens`}),H8({labelKey:`settings.tabs.virtualPrinter`,tab:`virtual-printer`,keywords:`virtual printer proxy archive slicer bambustudio orcaslicer ip bind`,anchor:`card-vp`}),H8({labelKey:`settings.tabs.spoolbuddy`,tab:`spoolbuddy`,keywords:`spoolbuddy device scale nfc rfid kiosk unregister`,anchor:`card-spoolbuddy`}),H8({labelKey:`settings.currentUser`,tab:`users`,subTab:`users`,keywords:`current user profile password change`,anchor:`card-currentuser`}),H8({labelKey:`settings.users`,tab:`users`,subTab:`users`,keywords:`users accounts list`,anchor:`card-users`}),H8({labelKey:`settings.groups`,tab:`users`,subTab:`users`,keywords:`groups roles permissions administrators operators viewers`,anchor:`card-groups`}),H8({labelKey:`settings.sessionPolicy.title`,labelFallback:`Session Policy`,tab:`users`,subTab:`users`,keywords:`session timeout expiry logout remember me jwt token lifetime`,anchor:`card-session-policy`}),H8({labelKey:`settings.email.smtpSettings`,labelFallback:`SMTP Configuration`,tab:`users`,subTab:`email`,keywords:`smtp email send server port password auth starttls ssl`,anchor:`card-smtp`}),H8({labelKey:`settings.ldap.title`,labelFallback:`LDAP Authentication`,tab:`users`,subTab:`ldap`,keywords:`ldap active directory ad authentication bind dn search base group mapping`,anchor:`card-ldap`}),H8({labelKey:`settings.tabs.backup`,tab:`backup`,keywords:`backup github restore download cloud sync profiles archives`,anchor:`card-backup`}),H8({labelKey:`externalLinks.sidebarLayout`,labelFallback:`Sidebar`,tab:`general`,keywords:`sidebar layout links pages hide show external custom navigation url add`,anchor:`card-sidebar-links`}),H8({labelKey:`settings.filamentTracking`,tab:`filament`,keywords:`spoolman filament tracking inventory sync remote integration`,anchor:`card-spoolman`}),H8({labelKey:`settings.catalog.spoolCatalog`,labelFallback:`Spool Catalog`,tab:`filament`,keywords:`spool catalog entries brand material reset import export`,anchor:`card-spool-catalog`}),H8({labelKey:`settings.colorCatalog.title`,labelFallback:`Color Catalog`,tab:`filament`,keywords:`color catalog hex swatch palette sync reset`,anchor:`card-color-catalog`}),H8({labelKey:`settings.tabs.failureDetection`,labelFallback:`Failure Detection`,tab:`failure-detection`,keywords:`failure detection ai ml obico spaghetti detect monitoring`,anchor:`card-fd-ml`}),H8({labelKey:`failureDetection.perPrinterTitle`,labelFallback:`Per-Printer Settings`,tab:`failure-detection`,keywords:`failure detection per printer enable per-printer sensitivity`,anchor:`card-fd-perprinter`}),H8({labelKey:`failureDetection.statusTitle`,labelFallback:`Detection Status`,tab:`failure-detection`,keywords:`failure detection status running connection`,anchor:`card-fd-status`}),H8({labelKey:`failureDetection.historyTitle`,labelFallback:`Detection History`,tab:`failure-detection`,keywords:`failure detection history log events`,anchor:`card-fd-history`}),H8({labelKey:`settings.email.advancedAuth`,labelFallback:`Advanced Email Authentication`,tab:`users`,subTab:`email`,keywords:`email authentication advanced password reset self-service forgot`,anchor:`card-email-advanced-auth`}),H8({labelKey:`settings.email.testConnection`,labelFallback:`Test SMTP Connection`,tab:`users`,subTab:`email`,keywords:`email smtp test connection send check`,anchor:`card-email-test`}),H8({labelKey:`settings.twoFa.totpTitle`,labelFallback:`Authenticator App (TOTP)`,tab:`users`,subTab:`twofa`,keywords:`two factor 2fa totp authenticator app google authy otp`,anchor:`card-2fa-totp`}),H8({labelKey:`settings.twoFa.emailOtpTitle`,labelFallback:`Email One-Time Codes`,tab:`users`,subTab:`twofa`,keywords:`two factor 2fa email otp one time code`,anchor:`card-2fa-emailotp`}),H8({labelKey:`settings.twoFa.linkedAccounts`,labelFallback:`Linked Accounts`,tab:`users`,subTab:`twofa`,keywords:`two factor 2fa linked accounts sso oidc provider google github`,anchor:`card-2fa-linked`}),H8({labelKey:`settings.oidc.title`,labelFallback:`Single Sign-On (OIDC)`,tab:`users`,subTab:`oidc`,keywords:`sso oidc openid single sign-on pocketid authentik keycloak google okta azure provider`,anchor:`card-oidc`}),H8({labelKey:`settings.ldap.serverConfig`,labelFallback:`LDAP Server Configuration`,tab:`users`,subTab:`ldap`,keywords:`ldap server url bind dn user search base group filter tls`,anchor:`card-ldap-server`}),H8({labelKey:`backup.githubBackup`,labelFallback:`GitHub Backup`,tab:`backup`,keywords:`github backup cloud remote sync profiles token`,anchor:`card-backup-github`}),H8({labelKey:`backup.history`,labelFallback:`Backup History`,tab:`backup`,keywords:`backup history log runs github commits`,anchor:`card-backup-history`}),H8({labelKey:`backup.localBackup`,labelFallback:`Local Backup`,tab:`backup`,keywords:`local backup download zip manual export`,anchor:`card-backup-local`}),H8({labelKey:`backup.scheduledBackup`,labelFallback:`Scheduled Backups`,tab:`backup`,keywords:`scheduled backup automatic hourly daily weekly retention local path`,anchor:`card-backup-scheduled`});var K8=20,JGe={database:`bg-blue-600`,library_files:`bg-green-500`,library_thumbnails:`bg-teal-500`,library_other:`bg-emerald-700`,archive_timelapses:`bg-red-500`,archive_thumbnails:`bg-amber-500`,archive_files:`bg-sky-500`,virtual_printer_uploads:`bg-purple-500`,virtual_printer_upload_cache:`bg-fuchsia-500`,virtual_printer_certs:`bg-violet-500`,virtual_printer_other:`bg-purple-700`,downloads:`bg-cyan-500`,plate_calibration:`bg-lime-500`,logs:`bg-orange-500`,other_data:`bg-yellow-500`},q8=[`bg-blue-500`,`bg-green-500`,`bg-yellow-500`,`bg-red-500`,`bg-orange-500`,`bg-teal-500`,`bg-cyan-500`,`bg-purple-500`],J8=(e,t)=>JGe[e]||q8[t%q8.length],Y8={temperature:0,humidity:1,battery:2};function YGe(e,t){return e?PT(e,t,{decimals:2}):null}function XGe(){let e=co(),t=or(),[n,r]=Ri(),{t:i,i18n:a}=U(),{showToast:o}=qd(),{authEnabled:s,user:c,isAdmin:l,refreshAuth:u,hasPermission:d}=Nd(),{mode:f,resolvedMode:p,darkStyle:m,darkBackground:h,darkAccent:g,lightStyle:_,lightBackground:v,lightAccent:b,setMode:x,setDarkStyle:S,setDarkBackground:C,setDarkAccent:w,setLightStyle:T,setLightBackground:E,setLightAccent:D,progressInTitle:O,setProgressInTitle:k}=Id(),[A,j]=(0,y.useState)(null),[M,N]=(0,y.useState)({}),[P,F]=(0,y.useState)(!1),[I,L]=(0,y.useState)(null),[R,z]=(0,y.useState)(!1),[B,V]=(0,y.useState)(null),[ee,te]=(0,y.useState)(!1),[ne,re]=(0,y.useState)(null),[ie,ae]=(0,y.useState)(!1),{colorize:oe,aboveColor:se,belowColor:H,optimalColor:ce}=R6(),[le,ue]=(0,y.useState)(null),[de,fe]=(0,y.useState)(!1),[pe,me]=(0,y.useState)(null),[he,ge]=(0,y.useState)(null),[_e,ve]=(0,y.useState)(``),[ye,be]=(0,y.useState)(``),[xe,Se]=(0,y.useState)(!1),[Ce,we]=(0,y.useState)(!1),[Te,Ee]=(0,y.useState)(!1),[De,Oe]=(0,y.useState)(hm()),ke=n.get(`tab`),Ae=ke===`email`,[je,Me]=(0,y.useState)(Ae?`users`:ke&&qGe.includes(ke)?ke:`general`),[Ne,Pe]=(0,y.useState)(Ae?`email`:`users`),[Fe,Ie]=(0,y.useState)(ke===`queue`&&n.get(`sub`)===`pipelines`?`pipelines`:`dispatch`),Le=e=>{Me(e),e===`users`&&Pe(`users`),e===`queue`&&(Ie(`dispatch`),n.delete(`sub`)),e===`general`?n.delete(`tab`):n.set(`tab`,e),r(n,{replace:!0})},Re=e=>{Ie(e),e===`pipelines`?n.set(`sub`,`pipelines`):n.delete(`sub`),r(n,{replace:!0})},[ze,Be]=(0,y.useState)(!1),[Ve,He]=(0,y.useState)(``),[Ue,We]=(0,y.useState)({can_queue:!0,can_control_printer:!1,can_read_status:!0,can_manage_library:!0,can_manage_inventory:!0,can_manage_maintenance:!0,can_manage_archives:!0,can_manage_projects:!0,can_access_cloud:!1,can_update_energy_cost:!1}),[Ge,Ke]=(0,y.useState)(null),[qe,Je]=(0,y.useState)(!1),[Ye,Xe]=(0,y.useState)(null),[Ze,Qe]=(0,y.useState)(``),[$e,et]=(0,y.useState)(!1),[tt,nt]=(0,y.useState)(!1),[rt,it]=(0,y.useState)(null),[at,ot]=(0,y.useState)(!1),[st,ct]=(0,y.useState)(!1),[lt,ut]=(0,y.useState)(!1),[dt,ft]=(0,y.useState)({currentPassword:``,newPassword:``,confirmPassword:``}),[pt,mt]=(0,y.useState)(!1),[ht,gt]=(0,y.useState)(!1),[_t,vt]=(0,y.useState)(!1),[yt,bt]=(0,y.useState)(`local`),[xt,St]=(0,y.useState)(!1),[Ct,wt]=(0,y.useState)(null),[Tt,Et]=(0,y.useState)(null),[Dt,Ot]=(0,y.useState)(null),[At,jt]=(0,y.useState)(!1),[Mt,Nt]=(0,y.useState)({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]}),[Pt,Ft]=(0,y.useState)(null),[It,Lt]=(0,y.useState)(null),[Rt,zt]=(0,y.useState)(!1),[Bt,Vt]=(0,y.useState)({}),[Ht,Ut]=(0,y.useState)({}),Wt=e=>{Oe(e),hee(e),o(i(`settings.toast.settingsSaved`),`success`)},{data:Gt,isLoading:Kt}=K({queryKey:[`settings`],queryFn:Z.getSettings}),{data:qt,isLoading:Jt,isFetching:Yt}=K({queryKey:[`storage-usage`],queryFn:()=>Z.getStorageUsage(),enabled:je===`general`,staleTime:1/0,refetchInterval:!1,refetchOnWindowFocus:!1,refetchOnReconnect:!1}),Xt=async()=>{gt(!0);try{let t=await Z.getStorageUsage({refresh:!0});e.setQueryData([`storage-usage`],t)}catch(e){o(e instanceof Error?e.message:`Failed to refresh storage usage`,`error`)}finally{gt(!1)}},{data:Zt,isLoading:Qt}=K({queryKey:[`smart-plugs`],queryFn:Z.getSmartPlugs}),{data:$t,isLoading:en}=K({queryKey:[`smart-plugs-energy`,Zt?.map(e=>e.id)],queryFn:async()=>{if(!Zt||Zt.length===0)return null;let e=await Promise.all(Zt.filter(e=>e.enabled).map(async e=>{try{return{plug:e,status:await Z.getSmartPlugStatus(e.id)}}catch{return{plug:e,status:null}}})),t=0,n=0,r=0,i=0,a=0;for(let{plug:o,status:s}of e){let e=o.plug_type===`mqtt`&&s?.energy?.power!=null;(s?.reachable||e)&&(a++,s?.energy?.power!=null&&(t+=s.energy.power),s?.energy?.today!=null&&(n+=s.energy.today),s?.energy?.yesterday!=null&&(r+=s.energy.yesterday),s?.energy?.total!=null&&(i+=s.energy.total))}return{totalPower:t,totalToday:n,totalYesterday:r,totalLifetime:i,reachableCount:a,totalPlugs:Zt.filter(e=>e.enabled).length}},enabled:je===`plugs`&&!!Zt&&Zt.length>0,refetchInterval:je===`plugs`?1e4:!1}),{data:tn,isLoading:W}=K({queryKey:[`notification-providers`],queryFn:Z.getNotificationProviders}),{data:nn,isLoading:rn}=K({queryKey:[`api-keys`],queryFn:Z.getAPIKeys}),an=q({mutationFn:e=>Z.createAPIKey(e),onSuccess:t=>{Ke(t.key||null),Be(!1),He(``),e.invalidateQueries({queryKey:[`api-keys`]}),o(i(`settings.toast.apiKeyCreated`))},onError:e=>{o(`Failed to create API key: ${e.message}`,`error`)}}),on=q({mutationFn:e=>Z.deleteAPIKey(e),onSuccess:(t,n)=>{e.setQueryData([`api-keys`],e=>(e??[]).filter(e=>e.id!==n)),o(i(`settings.toast.apiKeyDeleted`))},onError:e=>{o(`Failed to delete API key: ${e.message}`,`error`)}}),{data:sn}=K({queryKey:[`printers`],queryFn:Z.getPrinters}),{data:cn}=K({queryKey:[`haSensors`],queryFn:()=>Z.getHASensors()}),{data:ln}=K({queryKey:[`locationHaSensors`],queryFn:()=>Z.getLocationHASensors()}),{data:un}=K({queryKey:v6,queryFn:Z.getLocations,enabled:je===`sensors`}),dn=Co({queries:(0,y.useMemo)(()=>Array.from(new Set((ln??[]).map(e=>e.location_id))),[ln]).map(e=>({queryKey:[`locationHaSensorReadings`,e],queryFn:()=>Z.getLocationHASensorReadings(e,!1),enabled:je===`sensors`,refetchInterval:je===`sensors`?(Gt?.location_sensor_poll_interval||120)*1e3:!1}))}),fn=(0,y.useMemo)(()=>{let e=new Map;for(let t of dn)for(let n of t.data??[])e.set(n.id,n);return e},[dn]),pn=q({mutationFn:async e=>{for(let t of e)await Z.deleteLocationHASensor(t)},onSuccess:()=>{o(i(`locationHaSensors.toast.deleted`),`success`)},onError:e=>{o(e.message,`error`)},onSettled:()=>{e.invalidateQueries({queryKey:[`locationHaSensors`]}),e.invalidateQueries({queryKey:[`locationHaSensorReadings`]}),ue(null)}}),mn=zf(sn?.length??0),{data:hn,isLoading:gn}=K({queryKey:[`notification-templates`],queryFn:Z.getNotificationTemplates}),{data:_n}=K({queryKey:[`virtual-printer-settings`],queryFn:Cd.getSettings,refetchInterval:1e4}),vn=_n?.status?.running??!1,{data:yn}=K({queryKey:[`spoolbuddy-devices`],queryFn:()=>Od.getDevices(),refetchInterval:15e3}),bn=yn?.length??0,xn=yn?.some(e=>e.online)??!1,{data:Sn}=K({queryKey:[`obico-status`],queryFn:Z.getObicoStatus,refetchInterval:15e3}),Cn=!!(Sn?.is_running&&Sn?.enabled),{data:wn}=K({queryKey:[`ffmpeg-status`],queryFn:Z.checkFfmpeg}),{data:Tn}=K({queryKey:[`version`],queryFn:Z.getVersion}),En=!s||d(`library:purge`),{data:Dn}=K({queryKey:[`library-trash-settings`],queryFn:()=>Z.getLibraryTrashSettings(),enabled:En}),On=q({mutationFn:e=>Z.updateLibraryTrashSettings(e),onSuccess:()=>{e.invalidateQueries({queryKey:[`library-trash-settings`]}),o(i(`settings.toast.settingsSaved`),`success`)},onError:e=>o(e.message||i(`libraryAutoPurge.saveFailed`),`error`)}),kn=e=>{Dn&&On.mutate({retention_days:Dn.retention_days,auto_purge_enabled:Dn.auto_purge_enabled,auto_purge_days:Dn.auto_purge_days,auto_purge_include_never_printed:Dn.auto_purge_include_never_printed,...e})},An=!s||d(`archives:purge`),{data:jn}=K({queryKey:[`archive-purge-settings`],queryFn:()=>Z.getArchivePurgeSettings(),enabled:An}),Mn=q({mutationFn:e=>Z.updateArchivePurgeSettings(e),onSuccess:()=>{e.invalidateQueries({queryKey:[`archive-purge-settings`]}),o(i(`settings.toast.settingsSaved`),`success`)},onError:e=>o(e.message||i(`archiveAutoPurge.saveFailed`),`error`)}),Nn=e=>{jn&&Mn.mutate({enabled:jn.enabled,days:jn.days,purge_stats:jn.purge_stats,...e})},{data:Pn,refetch:Fn,isRefetching:In}=K({queryKey:[`updateCheck`],queryFn:Z.checkForUpdates,enabled:Gt?.check_updates!==!1,staleTime:300*1e3}),{data:Ln,refetch:Rn}=K({queryKey:[`updateStatus`],queryFn:Z.getUpdateStatus,refetchInterval:e=>{let t=e.state.data;return t?.status===`downloading`||t?.status===`installing`?1e3:!1}}),{data:zn}=K({queryKey:[`mqtt-status`],queryFn:Z.getMQTTStatus,refetchInterval:je===`network`?5e3:!1}),{data:Bn}=K({queryKey:[`github-backup-status`],queryFn:Z.getGitHubBackupStatus}),{data:Vn}=K({queryKey:[`cloud-status`],queryFn:Z.getCloudStatus}),{data:Hn={advanced_auth_enabled:!1,smtp_configured:!1,local_login_enabled:!0,autologin_provider_id:null}}=K({queryKey:[`advancedAuthStatus`],queryFn:()=>Z.getAdvancedAuthStatus()}),{data:Un}=K({queryKey:[`ldapStatus`],queryFn:()=>Z.getLDAPStatus()}),{data:Wn}=K({queryKey:[`twoFAStatus`],queryFn:()=>Z.get2FAStatus()}),{data:Gn=[]}=K({queryKey:[`oidcProvidersAll`],queryFn:()=>Z.getOIDCProvidersAll(),enabled:l}),{data:Kn=[],isLoading:qn}=K({queryKey:[`users`],queryFn:()=>Z.getUsers(),enabled:s&&d(`users:read`)}),{data:Jn=[],isLoading:Yn}=K({queryKey:[`groups`],queryFn:()=>Z.getGroups(),enabled:s&&d(`groups:read`)}),Xn=q({mutationFn:e=>Z.createUser(e),onSuccess:()=>{e.invalidateQueries({queryKey:[`users`]}),e.invalidateQueries({queryKey:[`groups`]}),vt(!1),Nt({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]}),o(i(`settings.toast.userCreated`))},onError:e=>{o(e.message,`error`)}}),Zn=q({mutationFn:({id:e,data:t})=>Z.updateUser(e,t),onSuccess:()=>{e.invalidateQueries({queryKey:[`users`]}),e.invalidateQueries({queryKey:[`groups`]}),St(!1),wt(null),Nt({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]}),o(i(`settings.toast.userUpdated`))},onError:e=>{o(e.message,`error`)}}),Qn=q({mutationFn:({id:e,deleteItems:t})=>Z.deleteUser(e,t),onSuccess:()=>{e.invalidateQueries({queryKey:[`users`]}),o(i(`settings.toast.userDeleted`)),Et(null),Ot(null)},onError:e=>{o(e.message,`error`)}}),$n=q({mutationFn:e=>Z.resetUserPassword({user_id:e}),onSuccess:e=>{o(e.message,`success`)},onError:e=>{o(e.message,`error`)}}),er=async e=>{Et(e),jt(!0);try{Ot(await Z.getUserItemsCount(e))}catch{Ot({archives:0,queue_items:0,library_files:0})}finally{jt(!1)}},tr=q({mutationFn:e=>Z.deleteGroup(e),onSuccess:()=>{e.invalidateQueries({queryKey:[`groups`]}),o(i(`settings.toast.groupDeleted`))},onError:e=>{o(e.message,`error`)}}),nr=()=>{let e=Hn?.advanced_auth_enabled||!1;if(!Mt.username){o(i(`settings.toast.fillRequiredFields`),`error`);return}if(e&&!Mt.email){o(`Email is required when advanced authentication is enabled`,`error`);return}if(!e){if(!Mt.password){o(i(`settings.toast.fillRequiredFields`),`error`);return}if(Mt.password!==Mt.confirmPassword){o(i(`settings.toast.passwordsDoNotMatch`),`error`);return}let e=_6(Mt.password);if(e){o(i({tooShort:`settings.toast.passwordTooShort`,needsUppercase:`settings.toast.passwordNeedsUppercase`,needsLowercase:`settings.toast.passwordNeedsLowercase`,needsDigit:`settings.toast.passwordNeedsDigit`,needsSpecial:`settings.toast.passwordNeedsSpecial`}[e]),`error`);return}}Xn.mutate({username:Mt.username,password:e?void 0:Mt.password,email:Mt.email||void 0,role:Mt.role,group_ids:Mt.group_ids.length>0?Mt.group_ids:void 0})},rr=e=>{if(Mt.password){if(Mt.password!==Mt.confirmPassword){o(i(`settings.toast.passwordsDoNotMatch`),`error`);return}let e=_6(Mt.password);if(e){o(i({tooShort:`settings.toast.passwordTooShort`,needsUppercase:`settings.toast.passwordNeedsUppercase`,needsLowercase:`settings.toast.passwordNeedsLowercase`,needsDigit:`settings.toast.passwordNeedsDigit`,needsSpecial:`settings.toast.passwordNeedsSpecial`}[e]),`error`);return}}let t={username:Mt.username||void 0,password:Mt.password||void 0,email:Mt.email||void 0,role:Mt.role,group_ids:Mt.group_ids};t.password||delete t.password,Zn.mutate({id:e,data:t})},ir=e=>{wt(e.id),Nt({username:e.username,password:``,email:e.email||``,confirmPassword:``,role:e.role,group_ids:e.groups?.map(e=>e.id)||[]}),St(!0)},ar=e=>{Nt(t=>({...t,group_ids:t.group_ids.includes(e)?t.group_ids.filter(t=>t!==e):[...t.group_ids,e]}))},sr=q({mutationFn:Z.applyUpdate,onSuccess:e=>{e.is_ha_addon||e.is_docker||e.is_windows_installer?o(e.message,`error`):Rn()}}),[cr,lr]=(0,y.useState)(null),ur=q({mutationFn:Z.testAllNotificationProviders,onSuccess:t=>{lr(t),e.invalidateQueries({queryKey:[`notification-providers`]}),t.failed===0?o(`All ${t.tested} providers tested successfully!`,`success`):o(`${t.success}/${t.tested} providers succeeded`,t.failed>0?`error`:`success`)},onError:e=>{o(`Failed to test providers: ${e.message}`,`error`)}}),dr=q({mutationFn:async e=>{if(!Zt)return{success:0,failed:0};let t=Zt.filter(e=>e.enabled),n=await Promise.all(t.map(async t=>{try{return await Z.controlSmartPlug(t.id,e),{success:!0}}catch{return{success:!1}}}));return{success:n.filter(e=>e.success).length,failed:n.filter(e=>!e.success).length}},onSuccess:(t,n)=>{e.invalidateQueries({queryKey:[`smart-plugs`]}),e.invalidateQueries({queryKey:[`smart-plugs-energy`]}),t.failed===0?o(`All ${t.success} plugs turned ${n}`,`success`):o(`${t.success} plugs turned ${n}, ${t.failed} failed`,`error`)},onError:e=>{o(`Failed: ${e.message}`,`error`)}}),fr=(0,y.useRef)(null),pr=(0,y.useRef)(null),mr=(0,y.useRef)(!1),hr=(0,y.useRef)(!0),gr=(0,y.useRef)(null);(0,y.useEffect)(()=>{if(Gt&&!A){let e={...Gt,external_url:Gt.external_url||window.location.origin};gr.current=Gt,j(e),setTimeout(()=>{hr.current=!1},100)}},[Gt,A]),(0,y.useEffect)(()=>{let e=gr.current;if(!Gt||!A||!e||Gt===e)return;let t={};for(let n of Object.keys(Gt))Gt[n]!==e[n]&&A[n]===e[n]&&(t[n]=Gt[n]);gr.current=Gt,Object.keys(t).length>0&&j(e=>e&&{...e,...t})},[Gt,A]);let _r=q({mutationFn:Z.updateSettings,onSuccess:t=>{gr.current=t,e.setQueryData([`settings`],t),e.invalidateQueries({queryKey:[`archiveStats`]}),o(i(`settings.toast.settingsSaved`),`success`)},onError:e=>{o(`Failed to save: ${e.message}`,`error`)},onSettled:()=>{mr.current=!1}}),vr=q({mutationFn:({id:e,data:t})=>Z.updatePrinter(e,t),onSuccess:()=>{e.invalidateQueries({queryKey:[`printers`]}),o(i(`settings.toast.cameraSettingsSaved`),`success`)},onError:e=>{o(`Failed to update printer: ${e.message}`,`error`)}});(0,y.useEffect)(()=>{let e=gr.current;if(!(hr.current||!A||!Gt||!e)&&!(s&&!d(`settings:update`))&&(e.auto_archive!==A.auto_archive||e.save_thumbnails!==A.save_thumbnails||e.capture_finish_photo!==A.capture_finish_photo||(e.finish_photo_restore_plate??!0)!==(A.finish_photo_restore_plate??!0)||e.default_filament_cost!==A.default_filament_cost||e.currency!==A.currency||e.energy_cost_per_kwh!==A.energy_cost_per_kwh||e.energy_tracking_mode!==A.energy_tracking_mode||e.check_updates!==A.check_updates||(e.check_printer_firmware??!0)!==(A.check_printer_firmware??!0)||(e.include_beta_updates??!1)!==(A.include_beta_updates??!1)||(e.local_login_enabled??!0)!==(A.local_login_enabled??!0)||e.notification_language!==A.notification_language||(e.bed_cooled_threshold??35)!==(A.bed_cooled_threshold??35)||e.ams_humidity_good!==A.ams_humidity_good||e.ams_humidity_fair!==A.ams_humidity_fair||e.ams_temp_good!==A.ams_temp_good||e.ams_temp_fair!==A.ams_temp_fair||(e.ams_temp_alarm??null)!==(A.ams_temp_alarm??null)||e.ams_history_retention_days!==A.ams_history_retention_days||e.disable_filament_warnings!==A.disable_filament_warnings||e.prefer_lowest_filament!==A.prefer_lowest_filament||(e.queue_drying_enabled??!1)!==(A.queue_drying_enabled??!1)||(e.queue_drying_block??!1)!==(A.queue_drying_block??!1)||(e.ambient_drying_enabled??!1)!==(A.ambient_drying_enabled??!1)||(e.print_drying_enabled??!1)!==(A.print_drying_enabled??!1)||(e.drying_presets??``)!==(A.drying_presets??``)||(e.ams_humidity_thresholds??``)!==(A.ams_humidity_thresholds??``)||e.per_printer_mapping_expanded!==A.per_printer_mapping_expanded||e.date_format!==A.date_format||e.time_format!==A.time_format||e.default_printer_id!==A.default_printer_id||e.ftp_retry_enabled!==A.ftp_retry_enabled||e.ftp_retry_count!==A.ftp_retry_count||e.ftp_retry_delay!==A.ftp_retry_delay||e.ftp_timeout!==A.ftp_timeout||e.mqtt_enabled!==A.mqtt_enabled||e.mqtt_broker!==A.mqtt_broker||e.mqtt_port!==A.mqtt_port||e.mqtt_username!==A.mqtt_username||e.mqtt_password!==A.mqtt_password||e.mqtt_topic_prefix!==A.mqtt_topic_prefix||e.mqtt_use_tls!==A.mqtt_use_tls||e.external_url!==A.external_url||e.ha_enabled!==A.ha_enabled||e.ha_url!==A.ha_url||e.ha_token!==A.ha_token||(e.library_archive_mode??`ask`)!==(A.library_archive_mode??`ask`)||Number(e.library_disk_warning_gb??5)!==Number(A.library_disk_warning_gb??5)||(e.preferred_slicer??`bambu_studio`)!==(A.preferred_slicer??`bambu_studio`)||G8(e.slice_engine)!==G8(A.slice_engine)||(e.open_in_slicer??null)!==(A.open_in_slicer??null)||(e.use_slicer_api??!1)!==(A.use_slicer_api??!1)||(e.orcaslicer_api_url??``)!==(A.orcaslicer_api_url??``)||(e.slicer_stall_timeout_minutes??15)!==(A.slicer_stall_timeout_minutes??15)||(e.bambu_studio_api_url??``)!==(A.bambu_studio_api_url??``)||e.prometheus_enabled!==A.prometheus_enabled||e.prometheus_token!==A.prometheus_token||(e.user_notifications_enabled??!0)!==(A.user_notifications_enabled??!0)||(e.default_bed_levelling??`auto`)!==(A.default_bed_levelling??`auto`)||(e.default_flow_cali??`auto`)!==(A.default_flow_cali??`auto`)||(e.default_vibration_cali??!0)!==(A.default_vibration_cali??!0)||(e.default_layer_inspect??!1)!==(A.default_layer_inspect??!1)||(e.default_timelapse??!1)!==(A.default_timelapse??!1)||(e.default_nozzle_offset_cali??`auto`)!==(A.default_nozzle_offset_cali??`auto`)||(e.stagger_group_size??2)!==(A.stagger_group_size??2)||(e.stagger_interval_minutes??5)!==(A.stagger_interval_minutes??5)||(e.require_plate_clear??!1)!==(A.require_plate_clear??!1)||(e.queue_max_concurrent_uploads??4)!==(A.queue_max_concurrent_uploads??4)||(e.preheat_enabled??!1)!==(A.preheat_enabled??!1)||(e.preheat_filament_targets??``)!==(A.preheat_filament_targets??``)||(e.preheat_max_wait_seconds??900)!==(A.preheat_max_wait_seconds??900)||(e.preheat_soak_seconds??300)!==(A.preheat_soak_seconds??300)||(e.queue_keep_bed_warm??!1)!==(A.queue_keep_bed_warm??!1)||(e.queue_keep_warm_bed_temp??90)!==(A.queue_keep_warm_bed_temp??90)||(e.queue_keep_warm_max_minutes??120)!==(A.queue_keep_warm_max_minutes??120)||(e.nozzle_temp_presets??``)!==(A.nozzle_temp_presets??``)||(e.bed_temp_presets??``)!==(A.bed_temp_presets??``)||(e.chamber_temp_presets??``)!==(A.chamber_temp_presets??``)||(e.fan_speed_presets??``)!==(A.fan_speed_presets??``)||(e.session_max_hours??24)!==(A.session_max_hours??24)||(e.billing_enabled??!1)!==(A.billing_enabled??!1)||(e.printer_kill_switch_enabled??!1)!==(A.printer_kill_switch_enabled??!1)||(e.finance_budget_reset_day??1)!==(A.finance_budget_reset_day??1)||(e.finance_budget_reset_timezone??`UTC`)!==(A.finance_budget_reset_timezone??`UTC`))&&!mr.current)return fr.current&&clearTimeout(fr.current),fr.current=setTimeout(()=>{if(mr.current)return;mr.current=!0;let e={auto_archive:A.auto_archive,save_thumbnails:A.save_thumbnails,capture_finish_photo:A.capture_finish_photo,finish_photo_restore_plate:A.finish_photo_restore_plate??!0,default_filament_cost:A.default_filament_cost,currency:A.currency,energy_cost_per_kwh:A.energy_cost_per_kwh,energy_tracking_mode:A.energy_tracking_mode,check_updates:A.check_updates,check_printer_firmware:A.check_printer_firmware,include_beta_updates:A.include_beta_updates,local_login_enabled:A.local_login_enabled,notification_language:A.notification_language,bed_cooled_threshold:A.bed_cooled_threshold,ams_humidity_good:A.ams_humidity_good,ams_humidity_fair:A.ams_humidity_fair,ams_temp_good:A.ams_temp_good,ams_temp_fair:A.ams_temp_fair,ams_temp_alarm:A.ams_temp_alarm??null,ams_history_retention_days:A.ams_history_retention_days,disable_filament_warnings:A.disable_filament_warnings,prefer_lowest_filament:A.prefer_lowest_filament,queue_drying_enabled:A.queue_drying_enabled,queue_drying_block:A.queue_drying_block,ambient_drying_enabled:A.ambient_drying_enabled,print_drying_enabled:A.print_drying_enabled,drying_presets:A.drying_presets,ams_humidity_thresholds:A.ams_humidity_thresholds,per_printer_mapping_expanded:A.per_printer_mapping_expanded,date_format:A.date_format,time_format:A.time_format,default_printer_id:A.default_printer_id,ftp_retry_enabled:A.ftp_retry_enabled,ftp_retry_count:A.ftp_retry_count,ftp_retry_delay:A.ftp_retry_delay,ftp_timeout:A.ftp_timeout,mqtt_enabled:A.mqtt_enabled,mqtt_broker:A.mqtt_broker,mqtt_port:A.mqtt_port,mqtt_username:A.mqtt_username,mqtt_password:A.mqtt_password,mqtt_topic_prefix:A.mqtt_topic_prefix,mqtt_use_tls:A.mqtt_use_tls,external_url:A.external_url,ha_enabled:A.ha_enabled,ha_url:A.ha_url,ha_token:A.ha_token,library_archive_mode:A.library_archive_mode,library_disk_warning_gb:A.library_disk_warning_gb,preferred_slicer:A.preferred_slicer,slice_engine:A.slice_engine,open_in_slicer:A.open_in_slicer,use_slicer_api:A.use_slicer_api,orcaslicer_api_url:A.orcaslicer_api_url,slicer_stall_timeout_minutes:A.slicer_stall_timeout_minutes,bambu_studio_api_url:A.bambu_studio_api_url,prometheus_enabled:A.prometheus_enabled,prometheus_token:A.prometheus_token,user_notifications_enabled:A.user_notifications_enabled,default_bed_levelling:A.default_bed_levelling,default_flow_cali:A.default_flow_cali,default_vibration_cali:A.default_vibration_cali,default_layer_inspect:A.default_layer_inspect,default_timelapse:A.default_timelapse,default_nozzle_offset_cali:A.default_nozzle_offset_cali,stagger_group_size:A.stagger_group_size,stagger_interval_minutes:A.stagger_interval_minutes,require_plate_clear:A.require_plate_clear,queue_max_concurrent_uploads:A.queue_max_concurrent_uploads,preheat_enabled:A.preheat_enabled,preheat_filament_targets:A.preheat_filament_targets,preheat_max_wait_seconds:A.preheat_max_wait_seconds,preheat_soak_seconds:A.preheat_soak_seconds,queue_keep_bed_warm:A.queue_keep_bed_warm,queue_keep_warm_bed_temp:A.queue_keep_warm_bed_temp,queue_keep_warm_max_minutes:A.queue_keep_warm_max_minutes,nozzle_temp_presets:A.nozzle_temp_presets,bed_temp_presets:A.bed_temp_presets,chamber_temp_presets:A.chamber_temp_presets,fan_speed_presets:A.fan_speed_presets,session_max_hours:A.session_max_hours,billing_enabled:A.billing_enabled,printer_kill_switch_enabled:A.printer_kill_switch_enabled,finance_budget_reset_day:A.finance_budget_reset_day,finance_budget_reset_timezone:A.finance_budget_reset_timezone};_r.mutate(e)},500),()=>{fr.current&&clearTimeout(fr.current)}},[A,Gt,_r,s,d,o,i]);let yr=(0,y.useCallback)((e,t)=>{if(s&&!d(`settings:update`)){o(i(`settings.toast.noPermissionUpdate`),`error`);return}j(n=>n?{...n,[e]:t}:null)},[s,d,o,i]),br=async(e,t,n)=>{if(!t){o(i(`settings.toast.enterCameraUrl`),`error`);return}Ut(t=>({...t,[e]:!0})),Vt(t=>({...t,[e]:null}));try{let r=await Z.testExternalCamera(e,t,n);Vt(t=>({...t,[e]:r})),r.success?o(r.coalesced?i(`settings.toast.cameraConnectedCoalesced`,{resolution:r.resolution||``}):i(`settings.toast.cameraConnected`,{resolution:r.resolution||``}),`success`):o(r.error||i(`settings.toast.connectionFailed`),`error`)}catch(t){let n=t instanceof Error?t.message:i(`settings.toast.testFailed`);Vt(t=>({...t,[e]:{success:!1,error:n}})),o(n,`error`)}finally{Ut(t=>({...t,[e]:!1}))}},[xr,Sr]=(0,y.useState)({}),Cr=(0,y.useRef)({}),wr=(0,y.useRef)(new Set),[Tr,Er]=(0,y.useState)({}),Dr=(0,y.useRef)({}),Or=(0,y.useRef)(new Set);(0,y.useEffect)(()=>{if(sn){let e={},t={};sn.forEach(n=>{n.external_camera_url&&!wr.current.has(n.id)&&(e[n.id]=n.external_camera_url,wr.current.add(n.id)),n.external_camera_snapshot_url&&!Or.current.has(n.id)&&(t[n.id]=n.external_camera_snapshot_url,Or.current.add(n.id))}),Object.keys(e).length>0&&Sr(t=>({...t,...e})),Object.keys(t).length>0&&Er(e=>({...e,...t}))}},[sn]);let kr=(e,t)=>{Sr(n=>({...n,[e]:t})),Cr.current[e]&&clearTimeout(Cr.current[e]),Cr.current[e]=setTimeout(()=>{vr.mutate({id:e,data:{external_camera_url:t||null}})},800)},Ar=(e,t)=>{Er(n=>({...n,[e]:t})),Dr.current[e]&&clearTimeout(Dr.current[e]),Dr.current[e]=setTimeout(()=>{vr.mutate({id:e,data:{external_camera_snapshot_url:t||null}})},800)},jr=(e,t)=>{let n={};t.type!==void 0&&(n.external_camera_type=t.type||null),t.enabled!==void 0&&(n.external_camera_enabled=t.enabled),t.rotation!==void 0&&(n.camera_rotation=t.rotation),vr.mutate({id:e,data:n})};if(Kt||!A)return(0,G.jsx)(`div`,{className:`p-4 md:p-8 flex justify-center`,children:(0,G.jsx)(Y,{className:`w-8 h-8 text-bambu-green animate-spin`})});let Mr=zGe().map(e=>({...e,label:i(e.labelKey,e.labelFallback??e.labelKey)})),Nr=ye.trim().toLowerCase(),Pr=Nr?Mr.filter(e=>e.label.toLowerCase().includes(Nr)||e.keywords.toLowerCase().includes(Nr)).slice(0,8):[],Fr=e=>{Le(e.tab),e.subTab&&Pe(e.subTab),be(``),setTimeout(()=>{let t=document.getElementById(e.anchor);t&&(t.scrollIntoView({behavior:`smooth`,block:`start`}),t.classList.add(`ring-2`,`ring-bambu-green`),setTimeout(()=>t.classList.remove(`ring-2`,`ring-bambu-green`),1500))},50)},Ir=(A?.docker_compose_dir??``).trim()||(Pn?.compose_dir_detected??``),Lr=Ir?`cd ${/\s/.test(Ir)?`"${Ir}"`:Ir} && docker compose pull && docker compose up -d`:`docker compose pull && docker compose up -d`;return(0,G.jsx)(Rd,{density:`dense`,children:(0,G.jsxs)(`div`,{className:`p-4 md:p-8`,children:[(0,G.jsxs)(`div`,{className:`mb-4 flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3`,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)(ru,{className:`w-7 h-7 text-bambu-green`}),i(`settings.title`)]}),(0,G.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:i(`settings.configureBambuddy`)})]}),(0,G.jsxs)(`div`,{className:`relative sm:w-72`,children:[(0,G.jsx)(Ql,{className:`w-4 h-4 text-bambu-gray absolute left-3 top-1/2 -translate-y-1/2 pointer-events-none`}),(0,G.jsx)(`input`,{type:`text`,value:ye,onChange:e=>be(e.target.value),placeholder:i(`settings.searchPlaceholder`,`Search settings…`),className:`w-full pl-9 pr-8 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`}),ye&&(0,G.jsx)(`button`,{onClick:()=>be(``),className:`absolute right-2 top-1/2 -translate-y-1/2 p-1 text-bambu-gray hover:text-white`,"aria-label":`Clear`,children:(0,G.jsx)(nd,{className:`w-3.5 h-3.5`})}),Pr.length>0&&(0,G.jsx)(`div`,{className:`absolute top-full left-0 right-0 mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl z-30 overflow-hidden`,children:Pr.map(e=>(0,G.jsxs)(`button`,{onClick:()=>Fr(e),className:`w-full px-3 py-2 text-left hover:bg-bambu-dark-tertiary transition-colors border-b border-bambu-dark-tertiary last:border-b-0`,children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:e.label}),(0,G.jsxs)(`p`,{className:`text-xs text-bambu-gray`,children:[i(`settings.tabs.${e.tab===`virtual-printer`?`virtualPrinter`:e.tab===`failure-detection`?`failureDetection`:e.tab}`),e.subTab?` › ${i(`settings.tabs.${e.subTab}`,e.subTab)}`:``]})]},e.anchor))}),Nr&&Pr.length===0&&(0,G.jsx)(`div`,{className:`absolute top-full left-0 right-0 mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl z-30 p-3`,children:(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray italic`,children:i(`settings.noSearchResults`,`No matching settings.`)})})]})]}),(0,G.jsxs)(`div`,{className:`flex flex-col lg:flex-row gap-4 lg:gap-6`,children:[(0,G.jsxs)(`nav`,{className:`flex flex-wrap gap-1 border-b border-bambu-dark-tertiary lg:flex-col lg:flex-nowrap lg:gap-0 lg:border-b-0 lg:border-r lg:w-48 lg:flex-shrink-0 lg:self-start lg:sticky lg:top-4`,children:[(0,G.jsxs)(`button`,{onClick:()=>Le(`general`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${je===`general`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,G.jsx)(ru,{className:`w-4 h-4`}),i(`settings.tabs.general`)]}),(0,G.jsxs)(`button`,{onClick:()=>Le(`plugs`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${je===`plugs`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,G.jsx)(Pl,{className:`w-4 h-4`}),i(`settings.tabs.smartPlugs`),Zt&&Zt.length>0&&(0,G.jsx)(`span`,{className:`text-xs bg-bambu-dark-tertiary px-1.5 py-0.5 rounded-full`,children:Zt.length})]}),(0,G.jsxs)(`button`,{onClick:()=>Le(`sensors`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${je===`sensors`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,G.jsx)(Tc,{className:`w-4 h-4`}),i(`settings.tabs.sensors`),(cn?.length??0)+(ln?.length??0)>0&&(0,G.jsx)(`span`,{className:`text-xs bg-bambu-dark-tertiary px-1.5 py-0.5 rounded-full`,children:(cn?.length??0)+(ln?.length??0)})]}),(0,G.jsxs)(`button`,{onClick:()=>Le(`notifications`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${je===`notifications`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,G.jsx)(qo,{className:`w-4 h-4`}),i(`settings.tabs.notifications`),tn&&tn.length>0&&(0,G.jsx)(`span`,{className:`text-xs bg-bambu-dark-tertiary px-1.5 py-0.5 rounded-full`,children:tn.length})]}),(0,G.jsxs)(`button`,{onClick:()=>Le(`queue`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${je===`queue`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,G.jsx)(Qc,{className:`w-4 h-4`}),i(`settings.tabs.queue`,`Workflow`)]}),(0,G.jsxs)(`button`,{onClick:()=>Le(`filament`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${je===`filament`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,G.jsx)(Ws,{className:`w-4 h-4`}),i(`settings.tabs.filament`)]}),(0,G.jsxs)(`button`,{onClick:()=>Le(`network`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${je===`network`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,G.jsx)(Qu,{className:`w-4 h-4`}),i(`settings.tabs.network`),(0,G.jsx)(`span`,{className:`w-2 h-2 rounded-full ${zn?.enabled?`bg-green-400`:`bg-gray-500`}`})]}),(0,G.jsxs)(`button`,{onClick:()=>Le(`apikeys`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${je===`apikeys`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,G.jsx)(Kc,{className:`w-4 h-4`}),i(`settings.tabs.apiKeys`),nn&&nn.length>0&&(0,G.jsx)(`span`,{className:`text-xs bg-bambu-dark-tertiary px-1.5 py-0.5 rounded-full`,children:nn.length})]}),(0,G.jsxs)(`button`,{onClick:()=>Le(`virtual-printer`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${je===`virtual-printer`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,G.jsx)(Rl,{className:`w-4 h-4`}),i(`settings.tabs.virtualPrinter`),(0,G.jsx)(`span`,{className:`w-2 h-2 rounded-full ${vn?`bg-green-400`:`bg-gray-500`}`})]}),(0,G.jsxs)(`button`,{onClick:()=>Le(`spoolbuddy`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${je===`spoolbuddy`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,G.jsx)(Jl,{className:`w-4 h-4`}),i(`settings.tabs.spoolbuddy`),bn>0&&(0,G.jsx)(`span`,{className:`text-xs bg-bambu-dark-tertiary px-1.5 py-0.5 rounded-full`,children:bn}),(0,G.jsx)(`span`,{className:`w-2 h-2 rounded-full ${xn?`bg-green-400`:`bg-gray-500`}`})]}),(0,G.jsxs)(`button`,{onClick:()=>Le(`failure-detection`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${je===`failure-detection`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,G.jsx)(Yl,{className:`w-4 h-4`}),i(`settings.tabs.failureDetection`),(0,G.jsx)(`span`,{className:`w-2 h-2 rounded-full ${Cn?`bg-green-400`:`bg-gray-500`}`})]}),(0,G.jsxs)(`button`,{onClick:()=>Le(`users`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${je===`users`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,G.jsx)(Uu,{className:`w-4 h-4`}),i(`settings.tabs.users`),s&&(0,G.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-green-400`})]}),(0,G.jsxs)(`button`,{onClick:()=>Le(`backup`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${je===`backup`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,G.jsx)(Gs,{className:`w-4 h-4`}),i(`settings.tabs.backup`),(0,G.jsx)(`span`,{className:`w-2 h-2 rounded-full ${Vn?.is_authenticated&&Bn?.configured&&Bn?.enabled||Gt?.local_backup_enabled?`bg-green-400`:`bg-gray-500`}`})]})]}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[je===`general`&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`a`,{href:Bf(mn,`app-settings`),target:`_blank`,rel:`noopener noreferrer`,className:`group block mb-4 lg:mb-6 rounded-xl border border-bambu-green/30 bg-gradient-to-br from-bambu-green/15 via-bambu-green/5 to-transparent hover:border-bambu-green/50 hover:from-bambu-green/20 transition-colors`,children:(0,G.jsxs)(`div`,{className:`flex flex-col md:flex-row items-start md:items-center gap-4 p-4 md:p-5`,children:[(0,G.jsx)(`div`,{className:`p-3 rounded-lg bg-bambu-green/20 text-bambu-green flex-shrink-0`,children:mn===`business`?(0,G.jsx)(Qo,{className:`w-6 h-6`}):(0,G.jsx)(Rc,{className:`w-6 h-6`})}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`p`,{className:`text-base font-semibold text-white`,children:mn===`business`?i(`sponsors.businessTitle`,`Bambuddy for business`):i(`sponsors.sectionTitle`,`Independent & community-funded`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-0.5`,children:mn===`business`?i(`sponsors.businessTagline`,`You're running {{count}} printers. Priority support, commercial licensing and invoicing are available for teams and print farms.`,{count:sn?.length??0}):i(`sponsors.tagline`,`Bambuddy is free and stays that way because people choose to support it. No VC, no cloud lock-in.`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 px-4 py-2 rounded-lg bg-bambu-green/20 text-bambu-green group-hover:bg-bambu-green/30 text-sm font-medium whitespace-nowrap self-start md:self-auto`,children:[mn===`business`?i(`sponsors.businessCta`,`Bambuddy for business`):i(`sponsors.viewSupporters`,`View supporters`),(0,G.jsx)(rc,{className:`w-4 h-4`})]})]})}),(0,G.jsxs)(`div`,{className:`flex flex-col lg:flex-row gap-4 lg:gap-6`,children:[(0,G.jsxs)(`div`,{className:`space-y-3 flex-1 lg:max-w-xl`,children:[(0,G.jsxs)(zd,{id:`card-general`,children:[(0,G.jsx)(Bd,{children:(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(`settings.general`)})}),(0,G.jsxs)(Vd,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[(0,G.jsx)(Ac,{className:`w-4 h-4 inline mr-1`}),i(`settings.language`)]}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(`select`,{value:a.language,onChange:e=>{let t=e.target.value;if(s&&!d(`settings:update`)){o(i(`settings.toast.noPermissionUpdate`),`error`);return}a.changeLanguage(t),_r.mutate({language:t})},className:`w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer`,children:kt.map(e=>(0,G.jsxs)(`option`,{value:e.code,children:[e.nativeName,` (`,e.name,`)`]},e.code))}),(0,G.jsx)(ps,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.languageDescription`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.defaultView`)}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(`select`,{value:De,onChange:e=>Wt(e.target.value),className:`w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer`,children:mm.map(e=>(0,G.jsx)(`option`,{value:e.to,children:i(e.labelKey)},e.id))}),(0,G.jsx)(ps,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.defaultViewDescription`)})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.dateFormat`)}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsxs)(`select`,{value:A.date_format||`system`,onChange:e=>yr(`date_format`,e.target.value),className:`w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer`,children:[(0,G.jsx)(`option`,{value:`system`,children:i(`settings.systemDefault`)}),(0,G.jsx)(`option`,{value:`us`,children:i(`settings.dateFormatUs`)}),(0,G.jsx)(`option`,{value:`eu`,children:i(`settings.dateFormatEu`)}),(0,G.jsx)(`option`,{value:`iso`,children:i(`settings.dateFormatIso`)})]}),(0,G.jsx)(ps,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.timeFormat`)}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsxs)(`select`,{value:A.time_format||`system`,onChange:e=>yr(`time_format`,e.target.value),className:`w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer`,children:[(0,G.jsx)(`option`,{value:`system`,children:i(`settings.systemDefault`)}),(0,G.jsx)(`option`,{value:`12h`,children:i(`settings.timeFormat12`)}),(0,G.jsx)(`option`,{value:`24h`,children:i(`settings.timeFormat24`)})]}),(0,G.jsx)(ps,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.defaultPrinter`)}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsxs)(`select`,{value:A.default_printer_id??``,onChange:e=>yr(`default_printer_id`,e.target.value?Number(e.target.value):null),className:`w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer`,children:[(0,G.jsx)(`option`,{value:``,children:i(`settings.noDefaultPrinter`)}),sn?.map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),(0,G.jsx)(ps,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.defaultPrinterDescription`)})]})]})]}),(0,G.jsxs)(zd,{id:`card-appearance`,children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(wl,{className:`w-5 h-5`}),i(`settings.appearance`)]})}),(0,G.jsxs)(Vd,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,G.jsxs)(`label`,{className:`text-sm text-bambu-gray`,children:[i(`settings.theme`),`:`]}),(0,G.jsx)(`div`,{className:`flex gap-1`,children:[{id:`dark`,label:i(`settings.themeDark`)},{id:`light`,label:i(`settings.themeLight`)},{id:`system`,label:i(`settings.themeSystem`)}].map(({id:e,label:t})=>(0,G.jsx)(`button`,{onClick:()=>{x(e),o(i(`settings.toast.settingsSaved`),`success`)},className:`px-3 py-1 text-xs rounded-lg border transition-colors ${f===e?`border-bambu-green bg-bambu-green/10 text-bambu-green`:`border-gray-300 dark:border-bambu-dark-tertiary text-gray-500 dark:text-bambu-gray hover:text-gray-900 dark:hover:text-white cursor-pointer`}`,children:t},e))})]}),(0,G.jsxs)(`div`,{className:`space-y-3 p-4 rounded-lg border ${p===`dark`?`border-bambu-green bg-bambu-green/5`:`border-bambu-dark-tertiary`}`,children:[(0,G.jsxs)(`h3`,{className:`text-sm font-medium text-white flex items-center gap-2`,children:[i(`settings.darkMode`),p===`dark`&&(0,G.jsx)(`span`,{className:`text-xs text-bambu-green`,children:i(`settings.active`)})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-3 gap-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.background`)}),(0,G.jsxs)(`select`,{value:h,onChange:e=>{C(e.target.value),o(i(`settings.toast.settingsSaved`),`success`)},className:`w-full px-2 py-1.5 text-sm 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:`neutral`,children:i(`settings.bgNeutral`)}),(0,G.jsx)(`option`,{value:`warm`,children:i(`settings.bgWarm`)}),(0,G.jsx)(`option`,{value:`cool`,children:i(`settings.bgCool`)}),(0,G.jsx)(`option`,{value:`oled`,children:i(`settings.bgOled`)}),(0,G.jsx)(`option`,{value:`slate`,children:i(`settings.bgSlate`)}),(0,G.jsx)(`option`,{value:`forest`,children:i(`settings.bgForest`)})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.accent`)}),(0,G.jsxs)(`select`,{value:g,onChange:e=>{w(e.target.value),o(i(`settings.toast.settingsSaved`),`success`)},className:`w-full px-2 py-1.5 text-sm 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:`green`,children:i(`settings.accentGreen`)}),(0,G.jsx)(`option`,{value:`teal`,children:i(`settings.accentTeal`)}),(0,G.jsx)(`option`,{value:`blue`,children:i(`settings.accentBlue`)}),(0,G.jsx)(`option`,{value:`orange`,children:i(`settings.accentOrange`)}),(0,G.jsx)(`option`,{value:`purple`,children:i(`settings.accentPurple`)}),(0,G.jsx)(`option`,{value:`red`,children:i(`settings.accentRed`)})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.style`)}),(0,G.jsxs)(`select`,{value:m,onChange:e=>{S(e.target.value),o(i(`settings.toast.settingsSaved`),`success`)},className:`w-full px-2 py-1.5 text-sm 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:`classic`,children:i(`settings.styleClassic`)}),(0,G.jsx)(`option`,{value:`glow`,children:i(`settings.styleGlow`)}),(0,G.jsx)(`option`,{value:`vibrant`,children:i(`settings.styleVibrant`)})]})]})]})]}),(0,G.jsxs)(`div`,{className:`space-y-3 p-4 rounded-lg border ${p===`light`?`border-bambu-green bg-bambu-green/5`:`border-bambu-dark-tertiary`}`,children:[(0,G.jsxs)(`h3`,{className:`text-sm font-medium text-white flex items-center gap-2`,children:[i(`settings.lightMode`),p===`light`&&(0,G.jsx)(`span`,{className:`text-xs text-bambu-green`,children:i(`settings.active`)})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-3 gap-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.background`)}),(0,G.jsxs)(`select`,{value:v,onChange:e=>{E(e.target.value),o(i(`settings.toast.settingsSaved`),`success`)},className:`w-full px-2 py-1.5 text-sm 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:`neutral`,children:i(`settings.bgNeutral`)}),(0,G.jsx)(`option`,{value:`warm`,children:i(`settings.bgWarm`)}),(0,G.jsx)(`option`,{value:`cool`,children:i(`settings.bgCool`)})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.accent`)}),(0,G.jsxs)(`select`,{value:b,onChange:e=>{D(e.target.value),o(i(`settings.toast.settingsSaved`),`success`)},className:`w-full px-2 py-1.5 text-sm 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:`green`,children:i(`settings.accentGreen`)}),(0,G.jsx)(`option`,{value:`teal`,children:i(`settings.accentTeal`)}),(0,G.jsx)(`option`,{value:`blue`,children:i(`settings.accentBlue`)}),(0,G.jsx)(`option`,{value:`orange`,children:i(`settings.accentOrange`)}),(0,G.jsx)(`option`,{value:`purple`,children:i(`settings.accentPurple`)}),(0,G.jsx)(`option`,{value:`red`,children:i(`settings.accentRed`)})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.style`)}),(0,G.jsxs)(`select`,{value:_,onChange:e=>{T(e.target.value),o(i(`settings.toast.settingsSaved`),`success`)},className:`w-full px-2 py-1.5 text-sm 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:`classic`,children:i(`settings.styleClassic`)}),(0,G.jsx)(`option`,{value:`glow`,children:i(`settings.styleGlow`)}),(0,G.jsx)(`option`,{value:`vibrant`,children:i(`settings.styleVibrant`)})]})]})]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.themeToggleHint`)}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between pt-2 border-t border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.progressInTitle`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.progressInTitleDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:O,onChange:e=>{k(e.target.checked),o(i(`settings.toast.settingsSaved`),`success`)},className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]})]})]}),(0,G.jsxs)(zd,{id:`card-archive`,children:[(0,G.jsx)(Bd,{children:(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(`settings.archiveSettings`)})}),(0,G.jsxs)(Vd,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.autoArchivePrints`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.autoArchiveDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.auto_archive,onChange:e=>yr(`auto_archive`,e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.saveThumbnails`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.saveThumbnailsDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.save_thumbnails,onChange:e=>yr(`save_thumbnails`,e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.captureFinishPhoto`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.captureFinishPhotoDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.capture_finish_photo,onChange:e=>yr(`capture_finish_photo`,e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),A.capture_finish_photo&&(0,G.jsxs)(`div`,{className:`flex items-center justify-between pl-4 border-l-2 border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.finishPhotoRestorePlate`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.finishPhotoRestorePlateDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.finish_photo_restore_plate??!0,onChange:e=>yr(`finish_photo_restore_plate`,e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),A.capture_finish_photo&&wn&&!wn.installed&&(0,G.jsxs)(`div`,{className:`flex items-start gap-2 p-3 bg-yellow-500/10 border border-yellow-500/30 rounded-lg`,children:[(0,G.jsx)(Lu,{className:`w-5 h-5 text-yellow-500 flex-shrink-0 mt-0.5`}),(0,G.jsxs)(`div`,{className:`text-sm`,children:[(0,G.jsx)(`p`,{className:`text-yellow-500 font-medium`,children:i(`settings.ffmpegNotInstalled`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:i(`settings.ffmpegRequired`)})]})]}),An&&jn&&(0,G.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary pt-3 mt-3 space-y-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`archiveAutoPurge.enableLabel`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`archiveAutoPurge.enableDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:jn.enabled,onChange:e=>Nn({enabled:e.target.checked}),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`archiveAutoPurge.ageLabel`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`input`,{type:`number`,min:7,max:3650,disabled:!jn.enabled,value:jn.days,onChange:e=>Nn({days:Math.max(7,Math.min(3650,parseInt(e.target.value||`0`,10)||0))}),className:`w-24 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none disabled:opacity-50`}),(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:i(`archiveAutoPurge.days`)})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`archiveAutoPurge.ageDescription`)})]}),(0,G.jsxs)(`label`,{className:`flex items-start gap-2 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,disabled:!jn.enabled,checked:jn.purge_stats,onChange:e=>Nn({purge_stats:e.target.checked}),className:`mt-0.5 shrink-0 disabled:opacity-50`}),(0,G.jsxs)(`span`,{className:`text-sm`,children:[(0,G.jsx)(`span`,{className:`text-white block`,children:i(`archiveAutoPurge.purgeStatsLabel`)}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray block mt-0.5`,children:i(`archiveAutoPurge.purgeStatsDescription`)})]})]})]})]})]})]}),(0,G.jsxs)(`div`,{className:`space-y-3 flex-1 lg:max-w-md`,children:[(0,G.jsxs)(zd,{id:`card-camera`,children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(Gu,{className:`w-5 h-5 text-bambu-green`}),i(`settings.camera`)]})}),(0,G.jsx)(Vd,{className:`space-y-3`,children:(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`text-sm font-medium text-white mb-2`,children:i(`settings.externalCameras`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mb-3`,children:i(`settings.externalCamerasDescription`)}),sn&&sn.length>0?(0,G.jsx)(`div`,{className:`space-y-3`,children:sn.map(e=>(0,G.jsxs)(`div`,{className:`p-3 bg-bambu-dark rounded-lg`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,G.jsx)(`span`,{className:`text-white font-medium text-sm`,children:e.name}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:e.external_camera_enabled,onChange:t=>jr(e.id,{enabled:t.target.checked}),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green`})]})]}),e.external_camera_enabled&&(0,G.jsxs)(`div`,{className:`space-y-2 mt-2`,children:[(0,G.jsx)(`input`,{type:`text`,placeholder:e.external_camera_type===`usb`?i(`settings.cameraPlaceholderUsb`):i(`settings.cameraPlaceholderUrl`),value:xr[e.id]??e.external_camera_url??``,onChange:t=>kr(e.id,t.target.value),className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsxs)(`select`,{value:e.external_camera_type||`mjpeg`,onChange:t=>jr(e.id,{type:t.target.value}),className:`flex-1 px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`,children:[(0,G.jsx)(`option`,{value:`mjpeg`,children:i(`settings.cameraTypeMjpeg`)}),(0,G.jsx)(`option`,{value:`rtsp`,children:i(`settings.cameraTypeRtsp`)}),(0,G.jsx)(`option`,{value:`snapshot`,children:i(`settings.cameraTypeSnapshot`)}),(0,G.jsx)(`option`,{value:`usb`,children:i(`settings.cameraTypeUsb`)})]}),(0,G.jsx)(Q,{size:`sm`,variant:`secondary`,onClick:()=>br(e.id,xr[e.id]??e.external_camera_url??``,e.external_camera_type||`mjpeg`),disabled:Ht[e.id]||!(xr[e.id]??e.external_camera_url),children:Ht[e.id]?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):i(`settings.test`)})]}),Bt[e.id]&&(0,G.jsx)(`div`,{className:`text-xs flex items-center gap-1 ${Bt[e.id]?.success?`text-green-500`:`text-red-500`}`,children:Bt[e.id]?.success?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(xs,{className:`w-3 h-3`}),i(`settings.connected`),Bt[e.id]?.resolution&&` (${Bt[e.id]?.resolution})`]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Ds,{className:`w-3 h-3`}),Bt[e.id]?.error||i(`settings.toast.connectionFailed`)]})}),(e.external_camera_type===`mjpeg`||e.external_camera_type===`rtsp`||e.external_camera_type===`usb`)&&(0,G.jsxs)(`div`,{className:`space-y-1`,children:[(0,G.jsx)(`label`,{className:`text-xs text-bambu-gray`,children:i(`settings.cameraSnapshotUrl`,`Snapshot URL (optional)`)}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsx)(`input`,{type:`text`,placeholder:i(`settings.cameraSnapshotUrlPlaceholder`,`http://192.168.1.61:1984/api/frame.jpeg?src=printer`),value:Tr[e.id]??e.external_camera_snapshot_url??``,onChange:t=>Ar(e.id,t.target.value),className:`flex-1 px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`}),(0,G.jsx)(Q,{size:`sm`,variant:`secondary`,onClick:()=>br(e.id,Tr[e.id]??e.external_camera_snapshot_url??``,`snapshot`),disabled:Ht[e.id]||!(Tr[e.id]??e.external_camera_snapshot_url),children:Ht[e.id]?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):i(`settings.test`)})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray opacity-75`,children:i(`settings.cameraSnapshotUrlHelp`,`Single-frame URL used for notification thumbnails, finish photos, timelapse and plate detection. Leave blank to capture from the live stream above. Useful for go2rtc (/api/frame.jpeg) and IP cameras with a dedicated snapshot endpoint.`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`label`,{className:`text-xs text-bambu-gray`,children:i(`settings.cameraRotation`)}),(0,G.jsxs)(`select`,{value:e.camera_rotation||0,onChange:t=>jr(e.id,{rotation:parseInt(t.target.value)}),className:`px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-xs focus:border-bambu-green focus:outline-none`,children:[(0,G.jsx)(`option`,{value:0,children:`0°`}),(0,G.jsx)(`option`,{value:90,children:`90°`}),(0,G.jsx)(`option`,{value:180,children:`180°`}),(0,G.jsx)(`option`,{value:270,children:`270°`})]})]})]})]},e.id))}):(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray italic`,children:i(`settings.noPrintersConfigured`)})]})})]}),(0,G.jsxs)(zd,{id:`card-cost`,children:[(0,G.jsx)(Bd,{children:(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(`settings.costTracking`)})}),(0,G.jsxs)(Vd,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.currency`)}),(0,G.jsx)(`select`,{value:A.currency,onChange:e=>yr(`currency`,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:Rf.map(e=>(0,G.jsx)(`option`,{value:e.code,children:e.label},e.code))})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.defaultFilamentCost`)}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(`span`,{className:`absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray text-sm pointer-events-none`,children:Lf(A.currency)}),(0,G.jsx)(`input`,{type:`number`,step:`0.01`,min:`0`,value:A.default_filament_cost,onChange:e=>yr(`default_filament_cost`,parseFloat(e.target.value)||0),style:{paddingLeft:`${Math.max(2,Lf(A.currency).length*.6+1)}rem`},className:`w-full pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.electricityCost`)}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(`span`,{className:`absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray text-sm pointer-events-none`,children:Lf(A.currency)}),(0,G.jsx)(`input`,{type:`number`,step:`0.001`,min:`0`,value:A.energy_cost_per_kwh,onChange:e=>yr(`energy_cost_per_kwh`,parseFloat(e.target.value)||0),style:{paddingLeft:`${Math.max(2,Lf(A.currency).length*.6+1)}rem`},className:`w-full pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.energyDisplayMode`)}),(0,G.jsxs)(`select`,{value:A.energy_tracking_mode||`total`,onChange:e=>yr(`energy_tracking_mode`,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:`print`,children:i(`settings.printsOnly`)}),(0,G.jsx)(`option`,{value:`total`,children:i(`settings.totalConsumption`)})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:A.energy_tracking_mode===`print`?i(`settings.energyModePrintDescription`):i(`settings.energyModeTotalDescription`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.billingEnabled`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.billingEnabledDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.billing_enabled??!1,onChange:e=>yr(`billing_enabled`,e.target.checked),className:`peer sr-only`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary rounded-full peer-checked:bg-bambu-green peer-checked:after:translate-x-5 after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border after:rounded-full after:h-5 after:w-5 after:transition-all`})]})]}),A.billing_enabled&&(0,G.jsxs)(`div`,{className:`mt-4 flex items-center justify-between gap-4 rounded-lg border border-bambu-dark-tertiary bg-bambu-dark px-4 py-3`,children:[(0,G.jsxs)(`div`,{className:`flex-1`,children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.printerKillSwitch`,`Unauthorized print kill switch`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.printerKillSwitchDescription`,`Immediately stop prints that start without authorization.`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.printer_kill_switch_enabled??!1,onChange:e=>yr(`printer_kill_switch_enabled`,e.target.checked),className:`peer sr-only`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary rounded-full peer-checked:bg-bambu-green peer-checked:after:translate-x-5 after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border after:rounded-full after:h-5 after:w-5 after:transition-all`})]})]}),A.billing_enabled&&(0,G.jsxs)(`div`,{className:`mt-4 rounded-lg border border-bambu-dark-tertiary bg-bambu-dark p-4`,children:[(0,G.jsx)(`div`,{className:`mb-3`,children:(0,G.jsxs)(`h4`,{className:`text-base font-medium text-white flex items-center gap-2`,children:[(0,G.jsx)(as,{className:`w-4 h-4 text-bambu-green`}),i(`settings.financeBudgetReset`,`Finance Monthly Budget Reset`)]})}),(0,G.jsxs)(`div`,{className:`flex gap-4`,children:[(0,G.jsxs)(`div`,{className:`flex-1`,children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.financeBudgetResetDay`,`Reset Day`)}),(0,G.jsx)(`input`,{type:`number`,min:1,max:31,value:A.finance_budget_reset_day??1,onChange:e=>yr(`finance_budget_reset_day`,Math.max(1,Math.min(31,parseInt(e.target.value,10)||1))),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.financeBudgetResetDayHelp`,`For short months, reset uses the last day of the month.`)})]}),(0,G.jsxs)(`div`,{className:`flex-1`,children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.financeBudgetResetTimezone`,`Reset timezone`)}),(0,G.jsxs)(`select`,{value:A.finance_budget_reset_timezone??`UTC`,onChange:e=>yr(`finance_budget_reset_timezone`,e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`,children:[(0,G.jsx)(`option`,{value:`UTC`,children:`UTC`}),(0,G.jsx)(`option`,{value:`Europe/Berlin`,children:`Europe/Berlin`}),(0,G.jsx)(`option`,{value:`Europe/Vienna`,children:`Europe/Vienna`}),(0,G.jsx)(`option`,{value:`Europe/Zurich`,children:`Europe/Zurich`}),(0,G.jsx)(`option`,{value:`America/New_York`,children:`America/New_York`}),(0,G.jsx)(`option`,{value:`America/Chicago`,children:`America/Chicago`}),(0,G.jsx)(`option`,{value:`America/Denver`,children:`America/Denver`}),(0,G.jsx)(`option`,{value:`America/Los_Angeles`,children:`America/Los_Angeles`}),(0,G.jsx)(`option`,{value:`Asia/Tokyo`,children:`Asia/Tokyo`}),(0,G.jsx)(`option`,{value:`Asia/Singapore`,children:`Asia/Singapore`}),(0,G.jsx)(`option`,{value:`Australia/Sydney`,children:`Australia/Sydney`})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.financeBudgetResetTimezoneHelp`,`Budget window start is calculated in this timezone.`)})]})]})]}),A.billing_enabled&&l&&(0,G.jsxs)(`div`,{className:`mt-3`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>we(!0),disabled:Te,children:Te?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 mr-2 animate-spin`}),i(`settings.rebuildLedgerInProgress`,`Starting...`)]}):i(`settings.rebuildLedger`,`Rebuild wallet ledger`)}),Ce&&(0,G.jsx)(of,{title:i(`settings.rebuildLedgerConfirmTitle`,`Rebuild wallet ledger?`),message:i(`settings.rebuildLedgerConfirmMessage`,`This will rebuild the wallet ledger to repair historical balance values. Run this only if you know what you are doing.`),confirmText:i(`common.run`,`Run`),cancelText:i(`common.cancel`,`Cancel`),isLoading:Te,loadingText:i(`common.running`,`Running`),variant:`warning`,onCancel:()=>we(!1),onConfirm:async()=>{Ee(!0);try{await Z.rebuildBalanceLedger(),o(i(`settings.rebuildLedgerStarted`,`Ledger rebuild started`),`success`),we(!1)}catch(e){o(e.message||`Failed to start ledger rebuild`,`error`)}finally{Ee(!1)}}})]})]})]})]}),(0,G.jsxs)(zd,{id:`card-filemanager`,children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(fc,{className:`w-5 h-5 text-bambu-green`}),i(`settings.fileManager`)]})}),(0,G.jsxs)(Vd,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.createArchiveEntry`)}),(0,G.jsxs)(`select`,{value:A.library_archive_mode??`ask`,onChange:e=>yr(`library_archive_mode`,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:`always`,children:i(`settings.archiveMode.always`)}),(0,G.jsx)(`option`,{value:`never`,children:i(`settings.archiveMode.never`)}),(0,G.jsx)(`option`,{value:`ask`,children:i(`settings.archiveMode.ask`)})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.createArchiveEntryDescription`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.lowDiskSpaceWarning`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`input`,{type:`number`,min:`0.5`,max:`100`,step:`0.5`,value:A.library_disk_warning_gb??5,onChange:e=>yr(`library_disk_warning_gb`,parseFloat(e.target.value)||5),className:`w-24 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:`GB`})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.lowDiskSpaceDescription`)})]}),En&&Dn&&(0,G.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary pt-3 mt-3 space-y-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`libraryAutoPurge.enableLabel`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`libraryAutoPurge.enableDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:Dn.auto_purge_enabled,onChange:e=>kn({auto_purge_enabled:e.target.checked}),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`libraryAutoPurge.ageLabel`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`input`,{type:`number`,min:7,max:3650,disabled:!Dn.auto_purge_enabled,value:Dn.auto_purge_days,onChange:e=>kn({auto_purge_days:Math.max(7,Math.min(3650,parseInt(e.target.value||`0`,10)||0))}),className:`w-24 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none disabled:opacity-50`}),(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:i(`libraryAutoPurge.days`)})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`libraryAutoPurge.ageDescription`)})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-white cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,disabled:!Dn.auto_purge_enabled,checked:Dn.auto_purge_include_never_printed,onChange:e=>kn({auto_purge_include_never_printed:e.target.checked}),className:`rounded border-gray-300 disabled:opacity-50`}),i(`libraryAutoPurge.includeNeverPrinted`)]})]})]})]}),(0,G.jsxs)(zd,{id:`card-data`,children:[(0,G.jsx)(Bd,{children:(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(`settings.dataManagement`)})}),(0,G.jsxs)(Vd,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.clearNotificationLogs`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.clearNotificationLogsDescription`)})]}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:()=>et(!0),children:[(0,G.jsx)(Pu,{className:`w-4 h-4`}),i(`common.clear`)]})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.resetUiPreferences`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.resetUiPreferencesDescription`)})]}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:()=>nt(!0),children:[(0,G.jsx)(Pu,{className:`w-4 h-4`}),i(`settings.reset`)]})]}),(0,G.jsxs)(`div`,{className:`pt-4 border-t border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.storageUsage`,`Storage Usage`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.storageUsageDescription`,`Breakdown of data usage by category`)})]}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:Xt,disabled:Yt||ht,children:[(0,G.jsx)(Hl,{className:`w-4 h-4 ${Yt||ht?`animate-spin`:``}`}),i(`common.refresh`,`Refresh`)]})]}),(0,G.jsx)(`div`,{className:`mt-3`,children:Jt?(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`}),i(`common.loading`,`Loading`)]}):qt?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`w-full h-3 bg-bambu-dark rounded-full overflow-hidden flex`,children:qt.categories.filter(e=>e.bytes>0).map((e,t)=>(0,G.jsx)(`div`,{className:`${J8(e.key,t)} h-full`,style:{width:`${e.percent_of_total}%`},title:`${e.label}: ${e.formatted}`},e.key))}),(0,G.jsx)(`div`,{className:`mt-3 flex flex-wrap gap-3`,children:qt.categories.filter(e=>e.bytes>0).map((e,t)=>(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-xs`,children:[(0,G.jsx)(`span`,{className:`w-3 h-3 rounded-full ${J8(e.key,t)}`}),(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:e.label}),(0,G.jsx)(`span`,{className:`text-white`,children:e.formatted}),(0,G.jsxs)(`span`,{className:`text-bambu-gray`,children:[`(`,e.percent_of_total.toFixed(1),`%)`]})]},e.key))}),(0,G.jsxs)(`div`,{className:`mt-2 text-xs text-bambu-gray`,children:[i(`settings.storageUsageTotal`,`Total`),`: `,(0,G.jsx)(`span`,{className:`text-white`,children:qt.total_formatted}),qt.scan_errors>0&&(0,G.jsxs)(`span`,{className:`ml-2 text-amber-700 dark:text-amber-400`,children:[i(`settings.storageUsageErrors`,`Scan errors`),`: `,qt.scan_errors]})]}),qt.other_breakdown?.length>0&&(0,G.jsxs)(`div`,{className:`mt-4`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:i(`settings.storageUsageOtherBreakdown`,`Other breakdown`)}),(0,G.jsx)(`div`,{className:`space-y-2`,children:qt.other_breakdown.map(e=>(0,G.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-white`,children:e.label}),(0,G.jsx)(`span`,{className:`px-2 py-0.5 rounded-full border ${e.kind===`system`?`border-slate-500 text-slate-300`:`border-bambu-green text-bambu-green`}`,children:e.kind===`system`?i(`settings.storageUsageSystem`,`System`):i(`settings.storageUsageData`,`Data`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray`,children:[(0,G.jsx)(`span`,{className:`text-white`,children:e.formatted}),(0,G.jsxs)(`span`,{children:[`(`,e.percent_of_total.toFixed(1),`%)`]})]})]},`${e.bucket}-${e.kind}`))})]})]}):(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.storageUsageUnavailable`,`Storage usage data is unavailable`)})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between pt-4 border-t border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.backupRestore`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.backupRestoreDescription`)})]}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:()=>Le(`backup`),children:[(0,G.jsx)(Gs,{className:`w-4 h-4`}),i(`settings.goToBackup`)]})]})]})]})]}),(0,G.jsxs)(`div`,{className:`space-y-3 flex-1 lg:max-w-sm`,children:[(0,G.jsxs)(zd,{id:`card-updates`,children:[(0,G.jsx)(Bd,{children:(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(`settings.updates`)})}),(0,G.jsxs)(Vd,{className:`space-y-3`,children:[(0,G.jsx)(`p`,{className:`text-xs font-medium text-bambu-gray uppercase tracking-wider`,children:i(`settings.printerFirmware`)}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.checkPrinterFirmware`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.checkFirmwareDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.check_printer_firmware??!0,onChange:e=>yr(`check_printer_firmware`,e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,G.jsx)(`div`,{className:`border-t border-bambu-dark-tertiary pt-4`,children:(0,G.jsx)(`p`,{className:`text-xs font-medium text-bambu-gray uppercase tracking-wider mb-4`,children:i(`settings.bambuddySoftware`)})}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.checkForUpdatesLabel`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.autoCheckDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.check_updates,onChange:e=>yr(`check_updates`,e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between ${A.check_updates?``:`opacity-50`}`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.includeBetaUpdates`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.includeBetaUpdatesDesc`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.include_beta_updates??!1,onChange:e=>yr(`include_beta_updates`,e.target.checked),disabled:!A.check_updates,className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.currentVersion`)}),(0,G.jsxs)(`p`,{className:`text-sm text-bambu-gray`,children:[`v`,Tn?.version||`...`]})]}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:()=>Fn(),disabled:In,children:[In?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Hl,{className:`w-4 h-4`}),i(`settings.checkNow`)]})]}),Pn?.update_available?(0,G.jsxs)(`div`,{className:`mt-4 p-3 bg-bambu-green/10 border border-bambu-green/30 rounded-lg`,children:[(0,G.jsxs)(`div`,{className:`flex items-start justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`p`,{className:`text-bambu-green font-medium`,children:[`Update available: v`,Pn.latest_version]}),Pn.release_name&&Pn.release_name!==Pn.latest_version&&(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:Pn.release_name})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[Pn.release_notes&&(0,G.jsx)(`button`,{onClick:()=>ot(!0),className:`text-bambu-gray hover:text-white transition-colors text-sm underline`,children:i(`settings.releaseNotes`)}),Pn.release_url&&(0,G.jsx)(`a`,{href:Pn.release_url,target:`_blank`,rel:`noopener noreferrer`,className:`text-bambu-gray hover:text-white transition-colors`,title:i(`settings.viewReleaseOnGitHub`),children:(0,G.jsx)(rc,{className:`w-4 h-4`})})]})]}),Ln?.status===`downloading`||Ln?.status===`installing`?(0,G.jsxs)(`div`,{className:`mt-3`,children:[(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`}),(0,G.jsx)(`span`,{children:Ln.message})]}),(0,G.jsx)(`div`,{className:`mt-2 w-full bg-bambu-dark-tertiary rounded-full h-2`,children:(0,G.jsx)(`div`,{className:`bg-bambu-green h-2 rounded-full transition-all duration-300`,style:{width:`${Ln.progress}%`}})})]}):Ln?.status===`complete`?(0,G.jsx)(`div`,{className:`mt-3 p-2 bg-bambu-green/20 rounded text-sm text-bambu-green`,children:Ln.message}):Ln?.status===`error`?(0,G.jsx)(`div`,{className:`mt-3 p-2 bg-red-100 dark:bg-red-500/20 rounded text-sm text-red-700 dark:text-red-400`,children:Ln.error||Ln.message}):Pn?.is_ha_addon?(0,G.jsx)(`div`,{className:`mt-3 p-3 bg-bambu-dark-tertiary rounded-lg`,children:(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.updateViaHomeAssistant`)})}):Pn?.is_docker?(0,G.jsxs)(`div`,{className:`mt-3 p-3 bg-bambu-dark-tertiary rounded-lg`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mb-2`,children:i(`settings.updateViaDocker`)}),(0,G.jsxs)(`div`,{className:`flex items-start gap-1`,children:[(0,G.jsx)(`code`,{className:`flex-1 block text-xs bg-bambu-dark p-2 rounded text-bambu-green font-mono break-all select-all`,children:Lr}),(0,G.jsx)(BU,{value:Lr,titleKey:`settings.copyUpdateCommand`,copiedTitleKey:`printers.copied`,className:`ml-0 p-2 rounded hover:bg-bambu-dark text-bambu-gray hover:text-white transition-colors flex-shrink-0`,iconClassName:`w-4 h-4`})]}),(0,G.jsxs)(`label`,{className:`block mt-3`,children:[(0,G.jsx)(`span`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.composeDirectory`)}),(0,G.jsx)(`input`,{type:`text`,value:A?.docker_compose_dir??``,onChange:e=>yr(`docker_compose_dir`,e.target.value),placeholder:Pn?.compose_dir_detected||`/opt/bambuddy`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded text-sm text-white font-mono placeholder:text-bambu-gray/60 focus:outline-none focus:border-bambu-green`}),(0,G.jsx)(`span`,{className:`block text-xs text-bambu-gray mt-1`,children:i(`settings.composeDirectoryHint`)})]})]}):Pn?.update_method===`windows_installer`?(0,G.jsxs)(`div`,{className:`mt-3 p-3 bg-bambu-dark-tertiary rounded-lg`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mb-3`,children:i(`settings.updateViaWindowsInstaller`)}),(0,G.jsxs)(`a`,{href:Pn.installer_download_url||Pn.release_url||`https://github.com/maziggy/bambuddy/releases/tag/v${Pn.latest_version}`,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center justify-center font-medium rounded-lg transition-colors focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-offset-bambu-dark disabled:opacity-50 bg-bambu-green hover:bg-bambu-green-light text-white focus:ring-bambu-green px-4 py-2 text-sm gap-2 min-h-[44px] md:min-h-0`,children:[(0,G.jsx)(Xs,{className:`w-4 h-4`}),i(`settings.downloadWindowsInstaller`,{version:Pn.latest_version})]})]}):(0,G.jsxs)(Q,{className:`mt-3`,onClick:()=>sr.mutate(),disabled:sr.isPending,children:[sr.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Xs,{className:`w-4 h-4`}),i(`settings.installUpdate`)]})]}):Pn?.error?(0,G.jsx)(`div`,{className:`mt-2 p-2 bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30 rounded text-sm text-red-700 dark:text-red-400`,children:i(`settings.failedToCheckUpdates`,{error:Pn.error})}):Pn&&!Pn.update_available?(0,G.jsx)(`p`,{className:`mt-2 text-sm text-bambu-gray`,children:i(`settings.latestVersionRunning`)}):null]})]})]}),(0,G.jsx)(pGe,{})]})]})]}),je===`network`&&A&&(0,G.jsxs)(`div`,{className:`flex flex-col lg:flex-row gap-6`,children:[(0,G.jsxs)(`div`,{className:`flex-1 lg:max-w-xl space-y-3`,children:[(0,G.jsxs)(zd,{id:`card-externalurl`,children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(Ac,{className:`w-5 h-5 text-blue-600 dark:text-blue-400`}),i(`settings.externalUrl`)]})}),(0,G.jsxs)(Vd,{className:`space-y-3`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.externalUrlDescription`)}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.bambuddyUrl`)}),(0,G.jsx)(`input`,{type:`text`,value:A.external_url??``,onChange:e=>yr(`external_url`,e.target.value),placeholder:`http://192.168.1.100:8000`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.externalUrlHint`)})]})]})]}),(0,G.jsxs)(zd,{id:`card-ftpretry`,children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(Hl,{className:`w-5 h-5 text-blue-600 dark:text-blue-400`}),i(`settings.ftpRetry`)]})}),(0,G.jsxs)(Vd,{className:`space-y-3`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.ftpRetryDescription`)}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.enableRetry`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.autoRetryDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.ftp_retry_enabled??!0,onChange:e=>yr(`ftp_retry_enabled`,e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),A.ftp_retry_enabled&&(0,G.jsxs)(`div`,{className:`space-y-3 pt-2 border-t border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.retryAttempts`)}),(0,G.jsxs)(`div`,{className:`relative w-44`,children:[(0,G.jsx)(`select`,{value:A.ftp_retry_count??3,onChange:e=>yr(`ftp_retry_count`,parseInt(e.target.value)),className:`w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer`,children:[1,2,3,4,5,6,7,8,9,10].map(e=>(0,G.jsx)(`option`,{value:e,children:i(`settings.time`,{count:e})},e))}),(0,G.jsx)(ps,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.retryDelay`)}),(0,G.jsxs)(`div`,{className:`relative w-44`,children:[(0,G.jsx)(`select`,{value:A.ftp_retry_delay??2,onChange:e=>yr(`ftp_retry_delay`,parseInt(e.target.value)),className:`w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer`,children:[1,2,3,5,10,15,20,30].map(e=>(0,G.jsx)(`option`,{value:e,children:i(`settings.second`,{count:e})},e))}),(0,G.jsx)(ps,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.connectionTimeout`)}),(0,G.jsxs)(`div`,{className:`relative w-44`,children:[(0,G.jsx)(`select`,{value:A.ftp_timeout??30,onChange:e=>yr(`ftp_timeout`,parseInt(e.target.value)),className:`w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer`,children:[10,15,20,30,45,60,90,120,180,300].map(e=>(0,G.jsx)(`option`,{value:e,children:i(`settings.nSeconds`,{count:e})},e))}),(0,G.jsx)(ps,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.increaseForWeakWifi`)})]})]})]})]})]}),(0,G.jsxs)(`div`,{className:`flex-1 lg:max-w-xl space-y-3`,children:[(0,G.jsxs)(zd,{id:`card-ha`,children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(Bc,{className:`w-5 h-5 text-bambu-green`}),i(`settings.homeAssistant`)]}),A.ha_enabled&&It&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`w-2.5 h-2.5 rounded-full ${It.success?`bg-green-400`:`bg-red-400`}`}),(0,G.jsx)(`span`,{className:`text-sm ${It.success?`text-green-700 dark:text-green-400`:`text-red-700 dark:text-red-400`}`,children:It.success?i(`settings.connected`):i(`settings.disconnected`)})]})]})}),(0,G.jsxs)(Vd,{className:`space-y-3`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.homeAssistantFullDescription`)}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex-1`,children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.enableHomeAssistant`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.homeAssistantDescription`)}),A.ha_env_managed&&(0,G.jsxs)(`div`,{className:`flex items-center gap-1 mt-1`,children:[(0,G.jsx)(nl,{className:`w-3 h-3 text-bambu-green`}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-green`,children:i(`settings.autoEnabledViaEnv`)})]})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.ha_enabled??!1,onChange:e=>yr(`ha_enabled`,e.target.checked),disabled:A.ha_env_managed,className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green ${A.ha_env_managed?`opacity-60 cursor-not-allowed`:``}`})]})]}),A.ha_enabled&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[i(`settings.homeAssistantUrl`),A.ha_url_from_env&&(0,G.jsx)(`span`,{className:`ml-2 text-xs text-bambu-green`,children:i(`settings.environmentManagedLabel`)})]}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(`input`,{type:`text`,value:A.ha_url??``,onChange:e=>yr(`ha_url`,e.target.value),placeholder:`http://192.168.1.100:8123`,disabled:A.ha_url_from_env,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 ${A.ha_url_from_env?`opacity-60 cursor-not-allowed`:``}`}),A.ha_url_from_env&&(0,G.jsx)(nl,{className:`absolute right-3 top-2.5 w-4 h-4 text-bambu-gray`})]}),A.ha_url_from_env&&(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.urlFromEnvReadOnly`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[i(`settings.longLivedAccessToken`),A.ha_token_from_env&&(0,G.jsx)(`span`,{className:`ml-2 text-xs text-bambu-green`,children:i(`settings.environmentManagedLabel`)})]}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(`input`,{type:`password`,value:A.ha_token??``,onChange:e=>yr(`ha_token`,e.target.value),placeholder:`eyJ0eXAiOiJKV1QiLC...`,disabled:A.ha_token_from_env,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 ${A.ha_token_from_env?`opacity-60 cursor-not-allowed`:``}`}),A.ha_token_from_env&&(0,G.jsx)(nl,{className:`absolute right-3 top-2.5 w-4 h-4 text-bambu-gray`})]}),A.ha_token_from_env?(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.tokenFromEnvReadOnly`)}):(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.haTokenHint`)})]}),A.ha_url&&A.ha_token&&(0,G.jsx)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,disabled:Rt,onClick:async()=>{zt(!0),Lt(null);try{Lt(await Z.testHAConnection(A.ha_url,A.ha_token))}catch(e){Lt({success:!1,message:null,error:e instanceof Error?e.message:i(`common.unknownError`)})}finally{zt(!1)}},children:[Rt?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Qu,{className:`w-4 h-4`}),i(`settings.testConnection`)]})})]})]})]}),(0,G.jsxs)(zd,{id:`card-mqtt`,children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(Qu,{className:`w-5 h-5 text-blue-600 dark:text-blue-400`}),i(`settings.mqttPublishing`)]}),zn?.enabled&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`w-2.5 h-2.5 rounded-full ${zn.connected?`bg-green-400`:`bg-red-400`}`}),(0,G.jsx)(`span`,{className:`text-sm ${zn.connected?`text-green-700 dark:text-green-400`:`text-red-700 dark:text-red-400`}`,children:zn.connected?i(`settings.connected`):i(`settings.disconnected`)})]})]})}),(0,G.jsxs)(Vd,{className:`space-y-3`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.mqttDescription`)}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.enableMqtt`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.mqttEnableDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.mqtt_enabled??!1,onChange:e=>yr(`mqtt_enabled`,e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),A.mqtt_enabled&&(0,G.jsxs)(`div`,{className:`space-y-3 pt-2 border-t border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.brokerHostname`)}),(0,G.jsx)(`input`,{type:`text`,value:A.mqtt_broker??``,onChange:e=>yr(`mqtt_broker`,e.target.value),placeholder:`mqtt.example.com or 192.168.1.100`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,G.jsxs)(`div`,{className:`flex items-end gap-4`,children:[(0,G.jsxs)(`div`,{className:`flex-1`,children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.port`)}),(0,G.jsx)(`input`,{type:`number`,min:`1`,max:`65535`,value:A.mqtt_port??1883,onChange:e=>yr(`mqtt_port`,Math.min(65535,Math.max(1,parseInt(e.target.value)||1883))),className:`w-24 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-3 pb-2`,children:[(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.mqtt_use_tls??!1,onChange:e=>{let t=e.target.checked;yr(`mqtt_use_tls`,t);let n=A.mqtt_port??1883;t&&n===1883?yr(`mqtt_port`,8883):!t&&n===8883&&yr(`mqtt_port`,1883)},className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]}),(0,G.jsx)(`span`,{className:`text-white text-sm`,children:i(`settings.useTls`)})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.usernameOptional`)}),(0,G.jsx)(`input`,{type:`text`,value:A.mqtt_username??``,onChange:e=>yr(`mqtt_username`,e.target.value),placeholder:i(`settings.leaveEmptyForAnonymous`),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.passwordOptional`)}),(0,G.jsx)(`input`,{type:`password`,value:A.mqtt_password??``,onChange:e=>yr(`mqtt_password`,e.target.value),placeholder:i(`settings.leaveEmptyForAnonymous`),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.topicPrefix`)}),(0,G.jsx)(`input`,{type:`text`,value:A.mqtt_topic_prefix??`bambuddy`,onChange:e=>yr(`mqtt_topic_prefix`,e.target.value),placeholder:`bambuddy`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.topicPrefixHint`,{prefix:A.mqtt_topic_prefix||`bambuddy`})})]}),zn&&(0,G.jsx)(`div`,{className:`pt-3 mt-3 border-t border-bambu-dark-tertiary`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,G.jsx)(`span`,{className:`w-2 h-2 rounded-full ${zn.connected?`bg-green-400`:`bg-red-400`}`}),(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:zn.connected?(0,G.jsxs)(G.Fragment,{children:[i(`settings.mqttConnectedTo`),` `,(0,G.jsxs)(`span`,{className:`text-white`,children:[zn.broker,`:`,zn.port]})]}):i(`settings.spoolmanDisconnected`)})]})})]})]})]})]}),(0,G.jsx)(`div`,{className:`flex-1 lg:max-w-md space-y-3`,children:(0,G.jsxs)(zd,{id:`card-prometheus`,children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(Iu,{className:`w-5 h-5 text-orange-600 dark:text-orange-400`}),i(`settings.prometheusMetrics`)]})}),(0,G.jsxs)(Vd,{className:`space-y-3`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.prometheusEndpointDescription`)}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.enableMetricsEndpoint`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.prometheusDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.prometheus_enabled??!1,onChange:e=>yr(`prometheus_enabled`,e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),A.prometheus_enabled&&(0,G.jsxs)(`div`,{className:`space-y-3 pt-2 border-t border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.bearerTokenOptional`)}),(0,G.jsx)(`input`,{type:`password`,value:A.prometheus_token??``,onChange:e=>yr(`prometheus_token`,e.target.value),placeholder:i(`settings.leaveEmptyForNoAuth`),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.bearerTokenHint`)})]}),(0,G.jsxs)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:[(0,G.jsx)(`p`,{className:`text-sm text-white mb-2`,children:i(`settings.availableMetrics`)}),(0,G.jsxs)(`div`,{className:`text-xs text-bambu-gray space-y-1`,children:[(0,G.jsxs)(`p`,{children:[(0,G.jsx)(`code`,{className:`text-orange-700 dark:text-orange-400`,children:`bambuddy_printer_connected`}),` - `,i(`settings.metricsConnectionStatus`)]}),(0,G.jsxs)(`p`,{children:[(0,G.jsx)(`code`,{className:`text-orange-700 dark:text-orange-400`,children:`bambuddy_printer_state`}),` - `,i(`settings.metricsPrinterState`)]}),(0,G.jsxs)(`p`,{children:[(0,G.jsx)(`code`,{className:`text-orange-700 dark:text-orange-400`,children:`bambuddy_print_progress`}),` - `,i(`settings.metricsPrintProgress`)]}),(0,G.jsxs)(`p`,{children:[(0,G.jsx)(`code`,{className:`text-orange-700 dark:text-orange-400`,children:`bambuddy_bed_temp_celsius`}),` - `,i(`settings.metricsBedTemp`)]}),(0,G.jsxs)(`p`,{children:[(0,G.jsx)(`code`,{className:`text-orange-700 dark:text-orange-400`,children:`bambuddy_nozzle_temp_celsius`}),` - `,i(`settings.metricsNozzleTemp`)]}),(0,G.jsxs)(`p`,{children:[(0,G.jsx)(`code`,{className:`text-orange-700 dark:text-orange-400`,children:`bambuddy_prints_total`}),` - `,i(`settings.metricsPrintsTotal`)]}),(0,G.jsx)(`p`,{className:`text-bambu-gray/70 italic`,children:i(`settings.metricsMore`)})]})]})]})]})]})})]}),It&&(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50`,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg p-6 max-w-md w-full mx-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3 mb-4`,children:[It.success?(0,G.jsx)(xs,{className:`w-8 h-8 text-green-600 dark:text-green-400`}):(0,G.jsx)(Ds,{className:`w-8 h-8 text-red-600 dark:text-red-400`}),(0,G.jsx)(`h3`,{className:`text-lg font-medium text-white`,children:It.success?i(`settings.connectionSuccessful`):i(`settings.connectionFailed`)})]}),(0,G.jsx)(`p`,{className:`text-bambu-gray mb-6`,children:It.success?It.message||i(`settings.haConnectionSuccess`):It.error||i(`settings.haConnectionFailed`)}),(0,G.jsx)(`div`,{className:`flex justify-end`,children:(0,G.jsx)(Q,{variant:`primary`,onClick:()=>Lt(null),children:i(`settings.ok`)})})]})}),je===`plugs`&&(0,G.jsxs)(`div`,{id:`card-plugs`,children:[(0,G.jsxs)(`div`,{className:`flex items-start justify-between mb-6`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(Pl,{className:`w-5 h-5 text-bambu-green`}),i(`settings.smartPlugs`)]}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:i(`settings.smartPlugsDescription`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 pt-1 shrink-0`,children:[Zt&&Zt.filter(e=>e.enabled).length>1&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,className:`whitespace-nowrap`,onClick:()=>it(`on`),disabled:dr.isPending,title:i(`settings.turnAllPlugsOn`),children:[dr.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Ll,{className:`w-4 h-4 text-bambu-green`}),i(`settings.allOn`)]}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,className:`whitespace-nowrap`,onClick:()=>it(`off`),disabled:dr.isPending,title:i(`settings.turnAllPlugsOff`),children:[dr.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Il,{className:`w-4 h-4 text-red-600 dark:text-red-400`}),i(`settings.allOff`)]})]}),(0,G.jsxs)(Q,{className:`whitespace-nowrap`,onClick:()=>{L(null),F(!0)},children:[(0,G.jsx)(Fl,{className:`w-4 h-4`}),i(`settings.addSmartPlug`)]})]})]}),Zt&&Zt.length>0&&(0,G.jsxs)(zd,{className:`mb-6`,children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(id,{className:`w-4 h-4 text-yellow-600 dark:text-yellow-400`}),i(`settings.energySummary`),en&&(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin text-bambu-gray ml-2`})]})}),(0,G.jsx)(Vd,{children:$t?(0,G.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-4`,children:[(0,G.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray text-xs mb-1`,children:[(0,G.jsx)(id,{className:`w-3 h-3`}),i(`settings.currentPower`)]}),(0,G.jsxs)(`div`,{className:`text-xl font-bold text-white`,children:[$t.totalPower.toFixed(1),(0,G.jsx)(`span`,{className:`text-sm font-normal text-bambu-gray ml-1`,children:`W`})]}),(0,G.jsx)(`div`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.plugsOnline`,{reachable:$t.reachableCount,total:$t.totalPlugs})})]}),(0,G.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray text-xs mb-1`,children:[(0,G.jsx)(as,{className:`w-3 h-3`}),i(`settings.today`)]}),(0,G.jsxs)(`div`,{className:`text-xl font-bold text-white`,children:[$t.totalToday.toFixed(3),(0,G.jsx)(`span`,{className:`text-sm font-normal text-bambu-gray ml-1`,children:`kWh`})]}),(A?.energy_cost_per_kwh??0)>0&&(0,G.jsxs)(`div`,{className:`text-xs text-bambu-gray mt-1`,children:[`~`,($t.totalToday*(A?.energy_cost_per_kwh??0)).toFixed(2),` `,Lf(A?.currency||`USD`)]})]}),(0,G.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray text-xs mb-1`,children:[(0,G.jsx)(Iu,{className:`w-3 h-3`}),i(`settings.yesterday`)]}),(0,G.jsxs)(`div`,{className:`text-xl font-bold text-white`,children:[$t.totalYesterday.toFixed(3),(0,G.jsx)(`span`,{className:`text-sm font-normal text-bambu-gray ml-1`,children:`kWh`})]}),(A?.energy_cost_per_kwh??0)>0&&(0,G.jsxs)(`div`,{className:`text-xs text-bambu-gray mt-1`,children:[`~`,($t.totalYesterday*(A?.energy_cost_per_kwh??0)).toFixed(2),` `,Lf(A?.currency||`USD`)]})]}),(0,G.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray text-xs mb-1`,children:[(0,G.jsx)(qs,{className:`w-3 h-3`}),i(`settings.total`)]}),(0,G.jsxs)(`div`,{className:`text-xl font-bold text-white`,children:[$t.totalLifetime.toFixed(1),(0,G.jsx)(`span`,{className:`text-sm font-normal text-bambu-gray ml-1`,children:`kWh`})]}),(A?.energy_cost_per_kwh??0)>0&&(0,G.jsxs)(`div`,{className:`text-xs text-bambu-gray mt-1`,children:[`~`,($t.totalLifetime*(A?.energy_cost_per_kwh??0)).toFixed(2),` `,Lf(A?.currency||`USD`)]})]})]}):en?null:(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.enablePlugsForSummary`)})})]}),Qt?(0,G.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,G.jsx)(Y,{className:`w-8 h-8 text-bambu-green animate-spin`})}):Zt&&Zt.length>0?(0,G.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4`,children:Zt.map(e=>(0,G.jsx)(PWe,{plug:e,onEdit:e=>{L(e),F(!0)}},e.id))}):(0,G.jsx)(zd,{children:(0,G.jsx)(Vd,{className:`py-12`,children:(0,G.jsxs)(`div`,{className:`text-center text-bambu-gray`,children:[(0,G.jsx)(Pl,{className:`w-16 h-16 mx-auto mb-4 opacity-30`}),(0,G.jsx)(`p`,{className:`text-lg font-medium text-white mb-2`,children:i(`settings.noSmartPlugsTitle`)}),(0,G.jsx)(`p`,{className:`text-sm mb-4`,children:i(`settings.noSmartPlugsDescription`)}),(0,G.jsxs)(Q,{onClick:()=>{L(null),F(!0)},children:[(0,G.jsx)(Fl,{className:`w-4 h-4`}),i(`settings.addFirstSmartPlug`)]})]})})})]}),je===`sensors`&&(0,G.jsxs)(`div`,{id:`card-sensors`,children:[(0,G.jsxs)(`div`,{id:`card-ha-sensors`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-4`,children:[(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(Tc,{className:`w-5 h-5 text-bambu-green`}),i(`haSensors.sectionTitle`)]}),(0,G.jsxs)(Q,{className:`whitespace-nowrap`,disabled:!sn?.length,onClick:()=>{V(null),z(!0)},children:[(0,G.jsx)(Fl,{className:`w-4 h-4`}),i(`haSensors.add`)]})]}),cn&&cn.length>0?(0,G.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4`,children:cn.map(e=>{let t=sn?.find(t=>t.id===e.printer_id);return(0,G.jsx)(zd,{children:(0,G.jsxs)(Vd,{className:`py-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsx)(`div`,{className:`text-white font-medium truncate`,children:e.name}),(0,G.jsx)(`div`,{className:`text-xs text-bambu-gray truncate`,children:e.entity_id}),(0,G.jsx)(`div`,{className:`text-xs text-bambu-gray mt-1`,children:t?.name??i(`haSensors.unknownPrinter`)})]}),(0,G.jsx)(Q,{size:`sm`,variant:`secondary`,onClick:()=>{V(e),z(!0)},children:i(`common.edit`)})]}),(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-1 mt-3`,children:[e.block_print&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 text-xs rounded bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-400`,children:i(`haSensors.badgeBlocks`)}),e.notify_on_alert&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 text-xs rounded bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`,children:i(`haSensors.badgeNotifies`)}),!e.show_on_printer_card&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 text-xs rounded bg-bambu-dark-tertiary text-bambu-gray`,children:i(`haSensors.badgeHidden`)})]})]})},e.id)})}):(0,G.jsx)(zd,{children:(0,G.jsx)(Vd,{className:`py-8`,children:(0,G.jsxs)(`div`,{className:`text-center text-bambu-gray`,children:[(0,G.jsx)(Tc,{className:`w-12 h-12 mx-auto mb-3 opacity-30`}),(0,G.jsx)(`p`,{className:`text-sm`,children:i(`haSensors.empty`)})]})})})]}),(0,G.jsxs)(`div`,{id:`card-location-sensors`,className:`mt-8`,children:[(0,G.jsxs)(`div`,{className:`flex items-start justify-between gap-[20px] mb-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(Tc,{className:`w-5 h-5 text-bambu-green`}),i(`locationHaSensors.sectionTitle`)]}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:i(`locationHaSensors.sectionDescription`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 pt-1 shrink-0`,children:[(0,G.jsx)(`button`,{type:`button`,onClick:()=>ae(!0),className:`p-2 rounded-lg bg-bambu-dark-tertiary hover:bg-bambu-gray-dark text-white transition-colors`,title:i(`locationHaSensors.options.buttonLabel`),"aria-label":i(`locationHaSensors.options.buttonLabel`),children:(0,G.jsx)(Rs,{className:`w-4 h-4`})}),(0,G.jsxs)(Q,{className:`whitespace-nowrap`,disabled:!un?.length,onClick:()=>{re(null),te(!0)},children:[(0,G.jsx)(Fl,{className:`w-4 h-4`}),i(`locationHaSensors.add`)]})]})]}),ln&&ln.length>0?(0,G.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4`,children:(()=>{let e=new Map((un??[]).map((e,t)=>[e.id,t])),t=ln.reduce((e,t)=>{let n=e.get(t.location_id)??[];return n.push(t),e.set(t.location_id,n),e},new Map);return Array.from(t.entries()).sort(([t],[n])=>(e.get(t)??2**53-1)-(e.get(n)??2**53-1))})().map(([e,t])=>{let n=un?.find(t=>t.id===e),r=e=>FT({device_class:e.device_class,state:e.last_state,kind:e.kind}),a=[...t].sort((e,t)=>(Y8[e.device_class??``]??99)-(Y8[t.device_class??``]??99));return(0,G.jsx)(zd,{children:(0,G.jsxs)(Vd,{className:`py-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,G.jsx)(`div`,{className:`text-white font-medium truncate`,children:n?.name??i(`locationHaSensors.unknownLocation`)}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>ue({locationName:n?.name??i(`locationHaSensors.unknownLocation`),sensorIds:a.map(e=>e.id)}),className:`p-1 text-bambu-gray hover:text-red-500 rounded transition-colors shrink-0`,title:i(`common.delete`),"aria-label":i(`common.delete`),children:(0,G.jsx)(Pu,{className:`w-3.5 h-3.5`})})]}),(0,G.jsx)(`div`,{className:`mt-2 space-y-1.5`,children:a.map(e=>{let t=r(e),n=fn.get(e.id),a=YGe(n,i),o=B6(oe&&n?z6(n):null,se,H,ce)||`text-white`;return(0,G.jsxs)(`div`,{className:`flex items-center min-w-0 text-xs text-bambu-gray`,children:[(0,G.jsx)(t,{className:`w-3.5 h-3.5 shrink-0 mr-1.5`}),a&&(0,G.jsx)(`span`,{className:`${o} shrink-0 w-[52px] text-center`,children:a}),a&&(0,G.jsx)(`span`,{className:`shrink-0 mr-1.5`,children:`-`}),(0,G.jsx)(`span`,{className:`truncate mr-1.5`,title:e.name,children:e.entity_id}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>{re(e),te(!0)},className:`p-1 text-bambu-gray hover:text-white rounded transition-colors shrink-0`,title:i(`common.edit`),"aria-label":i(`common.edit`),children:(0,G.jsx)(Al,{className:`w-3.5 h-3.5`})})]},e.id)})}),(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-1 mt-3`,children:[(()=>{let e=a.filter(e=>e.notify_on_alert);return e.length?(0,G.jsxs)(`span`,{className:`flex items-center gap-1 px-2 py-0.5 text-xs rounded bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`,children:[i(`haSensors.badgeNotifies`),e.map(e=>(0,G.jsx)(r(e),{className:`w-3 h-3`},e.id))]}):null})(),(()=>{let e=a.filter(e=>!e.show_on_card);return e.length?(0,G.jsxs)(`span`,{className:`flex items-center gap-1 px-2 py-0.5 text-xs rounded bg-bambu-dark-tertiary text-bambu-gray`,children:[i(`haSensors.badgeHidden`),e.map(e=>(0,G.jsx)(r(e),{className:`w-3 h-3`},e.id))]}):null})()]})]})},e)})}):(0,G.jsx)(zd,{children:(0,G.jsx)(Vd,{className:`py-8`,children:(0,G.jsxs)(`div`,{className:`text-center text-bambu-gray`,children:[(0,G.jsx)(Tc,{className:`w-12 h-12 mx-auto mb-3 opacity-30`}),(0,G.jsx)(`p`,{className:`text-sm`,children:i(`locationHaSensors.empty`)})]})})})]})]}),je===`notifications`&&(0,G.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-4`,children:[(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,id:`card-providers`,children:[(0,G.jsx)(qo,{className:`w-5 h-5 text-bambu-green`}),i(`settings.providers`)]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(Q,{size:`sm`,variant:`secondary`,onClick:()=>Se(!0),children:[(0,G.jsx)(zc,{className:`w-4 h-4`}),i(`settings.log`)]}),tn&&tn.length>0&&(0,G.jsxs)(Q,{size:`sm`,variant:`secondary`,onClick:()=>{lr(null),ur.mutate()},disabled:ur.isPending,children:[ur.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)($l,{className:`w-4 h-4`}),i(`settings.testAll`)]}),(0,G.jsxs)(Q,{size:`sm`,onClick:()=>{me(null),fe(!0)},children:[(0,G.jsx)(Fl,{className:`w-4 h-4`}),i(`settings.addNotificationProvider`)]})]})]}),(0,G.jsx)(zd,{className:`mb-4`,children:(0,G.jsx)(Vd,{className:`py-3`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white text-sm font-medium`,children:i(`settings.notificationLanguage`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.notificationLanguageDescription`)})]}),(0,G.jsx)(`select`,{value:A.notification_language||`en`,onChange:e=>yr(`notification_language`,e.target.value),className:`px-2 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:outline-none focus:ring-1 focus:ring-bambu-green`,children:kt.map(e=>(0,G.jsx)(`option`,{value:e.code,children:e.nativeName},e.code))})]})})}),(0,G.jsx)(zd,{className:`mb-4`,children:(0,G.jsx)(Vd,{className:`py-3`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white text-sm font-medium`,children:i(`settings.bedCooledThreshold`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.bedCooledThresholdDescription`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(`input`,{type:`number`,min:20,max:80,step:1,value:A.bed_cooled_threshold??35,onChange:e=>yr(`bed_cooled_threshold`,Number(e.target.value)),className:`w-16 px-2 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm text-center focus:outline-none focus:ring-1 focus:ring-bambu-green`}),(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:`°C`})]})]})})}),(0,G.jsx)(zd,{className:`mb-4`,children:(0,G.jsx)(Vd,{className:`py-3`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between ${Hn?.advanced_auth_enabled?``:`opacity-50`}`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white text-sm font-medium`,children:i(`settings.userNotificationsEnabled`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:Hn?.advanced_auth_enabled?i(`settings.userNotificationsEnabledDescription`):i(`settings.userNotificationsDisabledHint`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,className:`sr-only peer`,checked:A.user_notifications_enabled??!0,disabled:!Hn?.advanced_auth_enabled,onChange:e=>yr(`user_notifications_enabled`,e.target.checked)}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green peer-disabled:cursor-not-allowed`})]})]})})}),cr&&(0,G.jsx)(zd,{className:`mb-4`,children:(0,G.jsxs)(Vd,{className:`py-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,G.jsx)(`span`,{className:`text-sm font-medium text-white`,children:i(`settings.testResults`)}),(0,G.jsx)(`button`,{onClick:()=>lr(null),className:`text-bambu-gray hover:text-white text-xs`,children:i(`common.dismiss`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-4 text-sm mb-2`,children:[(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-bambu-green`,children:[(0,G.jsx)(xs,{className:`w-4 h-4`}),i(`settings.testPassedCount`,{count:cr.success})]}),cr.failed>0&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-red-700 dark:text-red-400`,children:[(0,G.jsx)(Ds,{className:`w-4 h-4`}),i(`settings.testFailedCount`,{count:cr.failed})]})]}),cr.results.filter(e=>!e.success).length>0&&(0,G.jsx)(`div`,{className:`space-y-1 mt-2 pt-2 border-t border-bambu-dark-tertiary`,children:cr.results.filter(e=>!e.success).map(e=>(0,G.jsxs)(`div`,{className:`text-xs text-red-700 dark:text-red-400`,children:[(0,G.jsxs)(`span`,{className:`font-medium`,children:[e.provider_name,`:`]}),` `,e.message]},e.provider_id))})]})}),W?(0,G.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,G.jsx)(Y,{className:`w-6 h-6 text-bambu-green animate-spin`})}):tn&&tn.length>0?(0,G.jsx)(`div`,{className:`space-y-3`,children:tn.map(e=>(0,G.jsx)(HWe,{provider:e,onEdit:e=>{me(e),fe(!0)}},e.id))}):(0,G.jsx)(zd,{children:(0,G.jsx)(Vd,{className:`py-8`,children:(0,G.jsxs)(`div`,{className:`text-center text-bambu-gray`,children:[(0,G.jsx)(qo,{className:`w-12 h-12 mx-auto mb-3 opacity-30`}),(0,G.jsx)(`p`,{className:`text-sm font-medium text-white mb-2`,children:i(`settings.noProvidersTitle`)}),(0,G.jsx)(`p`,{className:`text-xs mb-3`,children:i(`settings.noProvidersDescription`)}),(0,G.jsxs)(Q,{size:`sm`,onClick:()=>{me(null),fe(!0)},children:[(0,G.jsx)(Fl,{className:`w-4 h-4`}),i(`settings.addProvider`)]})]})})})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2 mb-2`,id:`card-templates`,children:[(0,G.jsx)(fc,{className:`w-5 h-5 text-bambu-green`}),i(`settings.messageTemplates`)]}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mb-3`,children:i(`settings.messageTemplatesDescription`)}),(0,G.jsxs)(`div`,{className:`relative mb-3`,children:[(0,G.jsx)(Ql,{className:`w-4 h-4 text-bambu-gray absolute left-3 top-1/2 -translate-y-1/2 pointer-events-none`}),(0,G.jsx)(`input`,{type:`text`,value:_e,onChange:e=>ve(e.target.value),placeholder:i(`settings.filterTemplates`,`Filter templates…`),className:`w-full pl-9 pr-8 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`}),_e&&(0,G.jsx)(`button`,{onClick:()=>ve(``),className:`absolute right-2 top-1/2 -translate-y-1/2 p-1 text-bambu-gray hover:text-white`,"aria-label":`Clear filter`,children:(0,G.jsx)(nd,{className:`w-3.5 h-3.5`})})]}),gn?(0,G.jsx)(`div`,{className:`flex justify-center py-8`,children:(0,G.jsx)(Y,{className:`w-6 h-6 text-bambu-green animate-spin`})}):hn&&hn.length>0?(()=>{let e=_e.trim().toLowerCase(),t=[...hn].sort((e,t)=>e.name.localeCompare(t.name)).filter(t=>!e||t.name.toLowerCase().includes(e)||(t.title_template||``).toLowerCase().includes(e));return t.length===0?(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray italic text-center py-6`,children:i(`settings.noTemplatesMatch`,`No templates match your filter.`)}):(0,G.jsx)(`div`,{className:`space-y-2`,children:t.map(e=>(0,G.jsx)(zd,{className:`cursor-pointer hover:border-bambu-green/50 transition-colors`,onClick:()=>ge(e),children:(0,G.jsx)(Vd,{className:`py-2.5 px-3`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,G.jsx)(`p`,{className:`text-white font-medium text-sm truncate`,children:e.name}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-xs truncate mt-0.5`,children:e.title_template})]}),(0,G.jsx)(`button`,{className:`p-1.5 hover:bg-bambu-dark-tertiary rounded transition-colors shrink-0 ml-2`,onClick:t=>{t.stopPropagation(),ge(e)},children:(0,G.jsx)(kl,{className:`w-4 h-4 text-bambu-gray`})})]})})},e.id))})})():(0,G.jsx)(zd,{children:(0,G.jsx)(Vd,{className:`py-8`,children:(0,G.jsxs)(`div`,{className:`text-center text-bambu-gray`,children:[(0,G.jsx)(fc,{className:`w-12 h-12 mx-auto mb-3 opacity-30`}),(0,G.jsx)(`p`,{className:`text-sm`,children:i(`settings.noTemplatesAvailable`)})]})})})]})]}),je===`apikeys`&&(0,G.jsxs)(`div`,{className:d(`api_keys:read`)?`grid grid-cols-1 xl:grid-cols-2 gap-4`:`grid grid-cols-1 gap-4`,children:[(0,G.jsxs)(`div`,{children:[d(`api_keys:read`)&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`flex items-start justify-between gap-4 mb-6`,children:[(0,G.jsxs)(`div`,{className:`flex-1`,children:[(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,id:`card-createapi`,children:[(0,G.jsx)(Kc,{className:`w-5 h-5 text-bambu-green`}),i(`settings.apiKeys`)]}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:i(`settings.apiKeysDescription`)})]}),(0,G.jsxs)(Q,{size:`sm`,onClick:()=>Be(!0),className:`flex-shrink-0`,children:[(0,G.jsx)(Fl,{className:`w-4 h-4`}),i(`settings.createKey`)]})]}),Ge&&(0,G.jsx)(zd,{className:`mb-6 border-bambu-green`,children:(0,G.jsx)(Vd,{className:`py-4`,children:(0,G.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,G.jsx)(xs,{className:`w-5 h-5 text-bambu-green flex-shrink-0 mt-0.5`}),(0,G.jsxs)(`div`,{className:`flex-1`,children:[(0,G.jsx)(`p`,{className:`text-white font-medium mb-1`,children:i(`settings.apiKeyCreated`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mb-2`,children:i(`settings.apiKeyCopyWarning`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 bg-bambu-dark rounded-lg p-2`,children:[(0,G.jsx)(`code`,{className:`flex-1 text-sm text-bambu-green font-mono break-all`,children:Ge}),(0,G.jsx)(Q,{variant:`secondary`,size:`sm`,onClick:async()=>{try{if(navigator.clipboard&&navigator.clipboard.writeText)await navigator.clipboard.writeText(Ge);else{let e=document.createElement(`textarea`);e.value=Ge,e.style.position=`fixed`,e.style.left=`-999999px`,document.body.appendChild(e),e.select(),document.execCommand(`copy`),document.body.removeChild(e)}o(i(`settings.toast.keyCopied`))}catch{o(i(`settings.toast.copyFailed`),`error`)}},children:(0,G.jsx)(Vs,{className:`w-4 h-4`})})]}),(0,G.jsxs)(`div`,{className:`flex gap-2 mt-3`,children:[(0,G.jsx)(Q,{variant:`secondary`,size:`sm`,onClick:()=>{Qe(Ge),o(i(`settings.toast.keyAddedToBrowser`))},children:i(`settings.useInApiBrowser`)}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:()=>Je(!0),children:[(0,G.jsx)(zl,{className:`w-4 h-4`}),i(`settings.apiKeyQrButton`)]}),(0,G.jsx)(Q,{variant:`secondary`,size:`sm`,onClick:()=>{Je(!1),Ke(null)},children:i(`common.dismiss`)})]})]})]})})}),qe&&Ge&&(0,G.jsx)(aGe,{apiKey:Ge,baseUrl:A?.external_url||void 0,onClose:()=>Je(!1)}),ze&&(0,G.jsxs)(zd,{className:`mb-6`,children:[(0,G.jsx)(Bd,{children:(0,G.jsx)(`h3`,{className:`text-base font-semibold text-white`,children:i(`settings.createNewApiKey`)})}),(0,G.jsxs)(Vd,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.keyName`)}),(0,G.jsx)(`input`,{type:`text`,value:Ve,onChange:e=>He(e.target.value),placeholder:i(`settings.keyNamePlaceholder`),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-2`,children:i(`common.permissions`)}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:Ue.can_read_status,onChange:e=>We(t=>({...t,can_read_status:e.target.checked})),className:`w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-white`,children:i(`settings.readStatus`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.readStatusDescription`)})]})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:Ue.can_queue,onChange:e=>We(t=>({...t,can_queue:e.target.checked})),className:`w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-white`,children:i(`settings.manageQueue`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.manageQueueDescription`)})]})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:Ue.can_control_printer,onChange:e=>We(t=>({...t,can_control_printer:e.target.checked})),className:`w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-white`,children:i(`settings.controlPrinter`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.controlPrinterDescription`)})]})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:Ue.can_manage_library,onChange:e=>We(t=>({...t,can_manage_library:e.target.checked})),className:`w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-white`,children:i(`settings.manageLibrary`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.manageLibraryDescription`)})]})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:Ue.can_manage_inventory,onChange:e=>We(t=>({...t,can_manage_inventory:e.target.checked})),className:`w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-white`,children:i(`settings.manageInventory`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.manageInventoryDescription`)})]})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:Ue.can_manage_maintenance,onChange:e=>We(t=>({...t,can_manage_maintenance:e.target.checked})),className:`w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-white`,children:i(`settings.manageMaintenance`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.manageMaintenanceDescription`)})]})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:Ue.can_manage_archives,onChange:e=>We(t=>({...t,can_manage_archives:e.target.checked})),className:`w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-white`,children:i(`settings.manageArchives`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.manageArchivesDescription`)})]})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:Ue.can_manage_projects,onChange:e=>We(t=>({...t,can_manage_projects:e.target.checked})),className:`w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-white`,children:i(`settings.manageProjects`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.manageProjectsDescription`)})]})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:Ue.can_access_cloud,onChange:e=>We(t=>({...t,can_access_cloud:e.target.checked})),className:`w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-white`,children:i(`settings.cloudAccess`,`Allow cloud access`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.cloudAccessDescription`,`Read Bambu Cloud presets and filaments on your behalf. Requires you to be signed into Bambu Cloud.`)})]})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:Ue.can_update_energy_cost,onChange:e=>We(t=>({...t,can_update_energy_cost:e.target.checked})),className:`w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-white`,children:i(`settings.updateEnergyCost`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.updateEnergyCostDescription`)})]})]})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 pt-2`,children:[(0,G.jsxs)(Q,{onClick:()=>an.mutate({name:Ve||i(`settings.unnamedKey`),...Ue}),disabled:an.isPending,children:[an.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Fl,{className:`w-4 h-4`}),i(`settings.createKey`)]}),(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>Be(!1),children:i(`common.cancel`)})]})]})]}),rn?(0,G.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,G.jsx)(Y,{className:`w-8 h-8 text-bambu-green animate-spin`})}):nn&&nn.length>0?(0,G.jsx)(`div`,{className:`space-y-3`,children:nn.map(e=>(0,G.jsx)(zd,{children:(0,G.jsx)(Vd,{className:`py-3`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(Kc,{className:`w-5 h-5 ${e.enabled?`text-bambu-green`:`text-bambu-gray`}`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white font-medium`,children:e.name}),(0,G.jsxs)(`p`,{className:`text-xs text-bambu-gray`,children:[e.key_prefix,`••••••••`,e.last_used&&` · ${i(`settings.lastUsed`)}: ${ap(e.last_used)}`]})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`div`,{className:`flex gap-1 text-xs flex-wrap justify-end`,children:[e.can_read_status&&(0,G.jsx)(`span`,{className:`px-1.5 py-0.5 bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400 rounded`,children:i(`settings.read`)}),e.can_queue&&(0,G.jsx)(`span`,{className:`px-1.5 py-0.5 bg-green-100 dark:bg-green-500/20 text-green-700 dark:text-green-400 rounded`,children:i(`queue.title`)}),e.can_control_printer&&(0,G.jsx)(`span`,{className:`px-1.5 py-0.5 bg-orange-100 dark:bg-orange-500/20 text-orange-700 dark:text-orange-400 rounded`,children:i(`settings.control`)}),e.can_manage_library&&(0,G.jsx)(`span`,{className:`px-1.5 py-0.5 bg-cyan-100 dark:bg-cyan-500/20 text-cyan-700 dark:text-cyan-400 rounded`,children:i(`settings.libraryBadge`)}),e.can_manage_inventory&&(0,G.jsx)(`span`,{className:`px-1.5 py-0.5 bg-pink-100 dark:bg-pink-500/20 text-pink-700 dark:text-pink-400 rounded`,children:i(`settings.inventoryBadge`)}),e.can_manage_maintenance&&(0,G.jsx)(`span`,{className:`px-1.5 py-0.5 bg-teal-100 dark:bg-teal-500/20 text-teal-700 dark:text-teal-400 rounded`,children:i(`settings.maintenanceBadge`)}),e.can_manage_archives&&(0,G.jsx)(`span`,{className:`px-1.5 py-0.5 bg-indigo-100 dark:bg-indigo-500/20 text-indigo-700 dark:text-indigo-400 rounded`,children:i(`settings.archivesBadge`)}),e.can_manage_projects&&(0,G.jsx)(`span`,{className:`px-1.5 py-0.5 bg-lime-100 dark:bg-lime-500/20 text-lime-700 dark:text-lime-400 rounded`,children:i(`settings.projectsBadge`)}),e.can_access_cloud&&(0,G.jsx)(`span`,{className:`px-1.5 py-0.5 bg-purple-100 dark:bg-purple-500/20 text-purple-700 dark:text-purple-400 rounded`,children:i(`settings.cloudBadge`,`Cloud`)}),e.can_update_energy_cost&&(0,G.jsx)(`span`,{className:`px-1.5 py-0.5 bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-400 rounded`,children:i(`settings.energyCostBadge`)}),e.user_id===null&&(0,G.jsx)(`span`,{className:`px-1.5 py-0.5 bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400 rounded`,title:i(`settings.legacyKeyTooltip`,`Created before per-user ownership; recreate to use cloud access`),children:i(`settings.legacyKey`,`Legacy`)})]}),(0,G.jsx)(Q,{variant:`secondary`,size:`sm`,onClick:()=>Xe(e.id),children:(0,G.jsx)(Pu,{className:`w-4 h-4 text-red-600 dark:text-red-400`})})]})]})})},e.id))}):(0,G.jsx)(zd,{children:(0,G.jsx)(Vd,{className:`py-12`,children:(0,G.jsxs)(`div`,{className:`text-center text-bambu-gray`,children:[(0,G.jsx)(Kc,{className:`w-16 h-16 mx-auto mb-4 opacity-30`}),(0,G.jsx)(`p`,{className:`text-lg font-medium text-white mb-2`,children:i(`settings.apiKeysEmptyTitle`)}),(0,G.jsx)(`p`,{className:`text-sm mb-4`,children:i(`settings.apiKeysEmptyDescription`)}),(0,G.jsxs)(Q,{onClick:()=>Be(!0),children:[(0,G.jsx)(Fl,{className:`w-4 h-4`}),i(`settings.createFirstKey`)]})]})})}),(0,G.jsxs)(zd,{className:`mt-6`,children:[(0,G.jsx)(Bd,{children:(0,G.jsx)(`h3`,{className:`text-base font-semibold text-white`,id:`card-webhooks`,children:i(`settings.webhookEndpoints`)})}),(0,G.jsxs)(Vd,{className:`space-y-3 text-sm`,children:[(0,G.jsx)(`p`,{className:`text-bambu-gray`,children:i(`settings.webhookApiKeyHint`)}),(0,G.jsxs)(`div`,{className:`space-y-2 font-mono text-xs`,children:[(0,G.jsxs)(`div`,{className:`p-2 bg-bambu-dark rounded`,children:[(0,G.jsx)(`span`,{className:`text-blue-700 dark:text-blue-400`,children:`GET`}),` `,(0,G.jsx)(`span`,{className:`text-white`,children:`/api/v1/webhook/status`}),(0,G.jsxs)(`span`,{className:`text-bambu-gray`,children:[` - `,i(`settings.webhook.getAllStatus`)]})]}),(0,G.jsxs)(`div`,{className:`p-2 bg-bambu-dark rounded`,children:[(0,G.jsx)(`span`,{className:`text-blue-700 dark:text-blue-400`,children:`GET`}),` `,(0,G.jsx)(`span`,{className:`text-white`,children:`/api/v1/webhook/status/:id`}),(0,G.jsxs)(`span`,{className:`text-bambu-gray`,children:[` - `,i(`settings.webhook.getSpecificStatus`)]})]}),(0,G.jsxs)(`div`,{className:`p-2 bg-bambu-dark rounded`,children:[(0,G.jsx)(`span`,{className:`text-green-700 dark:text-green-400`,children:`POST`}),` `,(0,G.jsx)(`span`,{className:`text-white`,children:`/api/v1/webhook/queue`}),(0,G.jsxs)(`span`,{className:`text-bambu-gray`,children:[` - `,i(`settings.webhook.addToQueue`)]})]}),(0,G.jsxs)(`div`,{className:`p-2 bg-bambu-dark rounded`,children:[(0,G.jsx)(`span`,{className:`text-orange-700 dark:text-orange-400`,children:`POST`}),` `,(0,G.jsx)(`span`,{className:`text-white`,children:`/api/v1/webhook/printer/:id/pause`}),(0,G.jsxs)(`span`,{className:`text-bambu-gray`,children:[` - `,i(`settings.webhook.pausePrint`)]})]}),(0,G.jsxs)(`div`,{className:`p-2 bg-bambu-dark rounded`,children:[(0,G.jsx)(`span`,{className:`text-orange-700 dark:text-orange-400`,children:`POST`}),` `,(0,G.jsx)(`span`,{className:`text-white`,children:`/api/v1/webhook/printer/:id/resume`}),(0,G.jsxs)(`span`,{className:`text-bambu-gray`,children:[` - `,i(`settings.webhook.resumePrint`)]})]}),(0,G.jsxs)(`div`,{className:`p-2 bg-bambu-dark rounded`,children:[(0,G.jsx)(`span`,{className:`text-red-700 dark:text-red-400`,children:`POST`}),` `,(0,G.jsx)(`span`,{className:`text-white`,children:`/api/v1/webhook/printer/:id/stop`}),(0,G.jsxs)(`span`,{className:`text-bambu-gray`,children:[` - `,i(`settings.webhook.stopPrint`)]})]})]})]})]})]}),(0,G.jsxs)(zd,{className:`mt-6`,children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,id:`card-camera-tokens`,children:[(0,G.jsx)(Gu,{className:`w-4 h-4 text-bambu-green`}),i(`cameraTokens.title`,`Camera API Tokens`)]})}),(0,G.jsx)(Vd,{children:(0,G.jsx)(jWe,{})})]}),(0,G.jsxs)(zd,{className:`mt-6`,children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,id:`card-stream-overlay`,children:[(0,G.jsx)(hl,{className:`w-4 h-4 text-bambu-green`}),i(`streamOverlay.builder.title`,`Streaming Overlay`)]})}),(0,G.jsx)(Vd,{children:(0,G.jsx)(NWe,{})})]})]}),d(`api_keys:read`)&&(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`mb-6`,children:[(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,id:`card-apibrowser`,children:[(0,G.jsx)(Ac,{className:`w-5 h-5 text-bambu-green`}),i(`settings.apiBrowser`)]}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:i(`settings.apiBrowserDescription`)})]}),(0,G.jsx)(zd,{className:`mb-4`,children:(0,G.jsxs)(Vd,{className:`py-3`,children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-2`,children:i(`settings.apiKeyForTesting`)}),(0,G.jsx)(`input`,{type:`text`,value:Ze,onChange:e=>Qe(e.target.value),placeholder:i(`settings.apiKeyPlaceholder`),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white font-mono text-sm focus:border-bambu-green focus:outline-none`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-2`,children:i(`settings.apiKeyHint`)})]})}),(0,G.jsx)(WGe,{apiKey:Ze})]})]}),je===`virtual-printer`&&(0,G.jsx)(`div`,{id:`card-vp`,children:(0,G.jsx)(yGe,{})}),je===`spoolbuddy`&&(0,G.jsx)(`div`,{id:`card-spoolbuddy`,children:(0,G.jsx)(xGe,{})}),je===`queue`&&(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{className:`flex gap-1 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`button`,{onClick:()=>Re(`dispatch`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${Fe===`dispatch`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,G.jsx)(Qc,{className:`w-4 h-4`}),i(`settings.tabs.queueDispatch`,`Queue & Dispatch`)]}),(0,G.jsxs)(`button`,{onClick:()=>Re(`pipelines`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${Fe===`pipelines`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,G.jsx)(ed,{className:`w-4 h-4`}),i(`settings.tabs.queuePipelines`,`Pipelines`)]})]}),Fe===`pipelines`&&(0,G.jsx)(CWe,{}),Fe===`dispatch`&&A&&(0,G.jsxs)(`div`,{className:`flex flex-col lg:flex-row gap-4 lg:gap-6`,children:[(0,G.jsxs)(`div`,{className:`lg:w-1/2 space-y-3`,children:[(0,G.jsxs)(zd,{id:`card-print-options`,children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(Qc,{className:`w-4 h-4 text-bambu-green`}),i(`settings.defaultPrintOptions`,`Default Print Options`)]})}),(0,G.jsxs)(Vd,{className:`space-y-3`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.defaultPrintOptionsDescription`,`Set default values for print options when starting new prints. These can be overridden per print in the print dialog.`)}),[{key:`default_bed_levelling`,label:i(`settings.defaultBedLevelling`,`Bed Levelling`),desc:i(`settings.defaultBedLevellingDesc`,`Auto-level bed before print`),fallback:!0,dualNozzleOnly:!1,tristate:!0},{key:`default_flow_cali`,label:i(`settings.defaultFlowCali`,`Flow Calibration`),desc:i(`settings.defaultFlowCaliDesc`,`Calibrate extrusion flow`),fallback:!1,dualNozzleOnly:!1,tristate:!0},{key:`default_vibration_cali`,label:i(`settings.defaultVibrationCali`,`Vibration Calibration`),desc:i(`settings.defaultVibrationCaliDesc`,`Reduce ringing artifacts`),fallback:!0,dualNozzleOnly:!1,tristate:!1},{key:`default_layer_inspect`,label:i(`settings.defaultLayerInspect`,`First Layer Inspection`),desc:i(`settings.defaultLayerInspectDesc`,`AI inspection of first layer`),fallback:!1,dualNozzleOnly:!1,tristate:!1},{key:`default_timelapse`,label:i(`settings.defaultTimelapse`,`Timelapse`),desc:i(`settings.defaultTimelapseDesc`,`Record timelapse video`),fallback:!1,dualNozzleOnly:!1,tristate:!1},{key:`default_nozzle_offset_cali`,label:i(`settings.defaultNozzleOffsetCali`,`Nozzle Offset Calibration`),desc:i(`settings.defaultNozzleOffsetCaliDesc`,`Calibrate nozzle offsets between extruders`),fallback:!0,dualNozzleOnly:!0,tristate:!0}].filter(({dualNozzleOnly:e})=>!e||(sn||[]).some(e=>e.nozzle_count===2)).map(({key:e,label:t,desc:n,fallback:r,tristate:a})=>(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex-1 mr-4`,children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:t}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:n})]}),a?(0,G.jsx)(`div`,{className:`flex gap-1 shrink-0`,children:PU.map(t=>(0,G.jsx)(`button`,{type:`button`,onClick:()=>yr(e,t),className:`px-2.5 py-1 text-xs rounded transition-colors ${(A[e]??`auto`)===t?FU[t]:`bg-bambu-dark-tertiary text-bambu-gray hover:text-white`}`,children:i(`settings.calibrationMode_${t}`)},t))}):(0,G.jsx)(`div`,{className:`flex gap-1 shrink-0`,children:[`off`,`on`].map(t=>(0,G.jsx)(`button`,{type:`button`,onClick:()=>yr(e,t===`on`),className:`px-2.5 py-1 text-xs rounded transition-colors ${(A[e]??r?`on`:`off`)===t?FU[t]:`bg-bambu-dark-tertiary text-bambu-gray hover:text-white`}`,children:i(`settings.calibrationMode_${t}`)},t))})]},e))]})]}),(0,G.jsxs)(zd,{id:`card-plate`,children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(su,{className:`w-4 h-4 text-bambu-green`}),i(`settings.plateClear`,`Plate-Clear Confirmation`)]})}),(0,G.jsx)(Vd,{className:`space-y-3`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex-1 mr-4`,children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:i(`settings.requirePlateClear`,`Require plate-clear confirmation`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.requirePlateClearDescription`,`When enabled, the scheduler waits for per-printer plate-clear confirmation before starting queued prints on printers with finished jobs. Disabling this also hides the plate status badge and the "Mark plate as cleared" button on printer cards.`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.require_plate_clear??!1,onChange:e=>yr(`require_plate_clear`,e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]})})]}),(0,G.jsxs)(zd,{id:`card-temp-fan-presets`,children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(Mu,{className:`w-4 h-4 text-bambu-green`}),i(`settings.tempFanPresetsTitle`,`Temperature & Fan Presets`)]})}),(0,G.jsxs)(Vd,{className:`space-y-4`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.tempFanPresetsDescription`,`Customize the quick-select values shown in printer-card temperature and fan-speed popovers. The Off button is always shown.`)}),kee.map(e=>{let t=Am(A?.[e.key]??``,e.defaults,e.lo,e.hi),n=e.unit===`C`?`°C`:`%`;return(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-1`,children:[(0,G.jsxs)(`label`,{className:`text-sm text-white`,children:[i(`settings.${{nozzle_temp_presets:`tempFanPresetsNozzle`,bed_temp_presets:`tempFanPresetsBed`,chamber_temp_presets:`tempFanPresetsChamber`,fan_speed_presets:`tempFanPresetsFan`}[e.key]}`,{nozzle_temp_presets:`Nozzle temperature`,bed_temp_presets:`Bed temperature`,chamber_temp_presets:`Chamber temperature`,fan_speed_presets:`Fan speed`}[e.key]),` `,(0,G.jsxs)(`span`,{className:`text-bambu-gray text-xs`,children:[`(`,n,` · `,e.lo,`–`,e.hi,`)`]})]}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>yr(e.key,``),title:i(`settings.tempFanPresetsReset`,`Reset to defaults`),className:`text-bambu-gray hover:text-white transition-colors p-1 rounded hover:bg-bambu-dark-tertiary`,children:(0,G.jsx)(Wl,{className:`w-3.5 h-3.5`})})]}),(0,G.jsx)(`div`,{className:`flex gap-2`,children:[0,1,2].map(n=>(0,G.jsx)(`input`,{type:`number`,min:e.lo,max:e.hi,value:t[n],onChange:r=>{let i=[t[0],t[1],t[2]],a=parseInt(r.target.value,10);i[n]=Math.max(e.lo,Math.min(e.hi,Number.isFinite(a)?a:e.lo)),yr(e.key,JSON.stringify(i))},className:`flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`},n))})]},e.key)})]})]}),(0,G.jsxs)(zd,{id:`card-staggered`,children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(Jc,{className:`w-4 h-4 text-bambu-green`}),i(`settings.staggeredStart`,`Staggered Start`)]})}),(0,G.jsxs)(Vd,{className:`space-y-3`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.staggeredStartDescription`,`Default group size and interval when staggering multi-printer batch starts. Can be overridden per batch in the print modal.`)}),(0,G.jsxs)(`div`,{className:`flex gap-4`,children:[(0,G.jsxs)(`div`,{className:`flex-1`,children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.staggerGroupSize`,`Group size`)}),(0,G.jsx)(`input`,{type:`number`,min:1,max:50,value:A.stagger_group_size??2,onChange:e=>yr(`stagger_group_size`,Math.max(1,Math.min(50,parseInt(e.target.value)||1))),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.staggerGroupSizeHelp`,`Printers to start simultaneously per group`)})]}),(0,G.jsxs)(`div`,{className:`flex-1`,children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.staggerInterval`,`Interval (minutes)`)}),(0,G.jsx)(`input`,{type:`number`,min:1,max:60,value:A.stagger_interval_minutes??5,onChange:e=>yr(`stagger_interval_minutes`,Math.max(1,Math.min(60,parseInt(e.target.value)||1))),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.staggerIntervalHelp`,`Delay between each group starting`)})]})]})]})]}),(0,G.jsxs)(zd,{id:`card-concurrent-uploads`,children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(Ns,{className:`w-4 h-4 text-bambu-green`}),i(`settings.concurrentUploadsTitle`,`Concurrent Uploads`)]})}),(0,G.jsxs)(Vd,{className:`space-y-3`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.concurrentUploadsDescription`,`How many printers the queue may send files to at the same time. Printers receive files slowly (a large print can take several minutes), and each one waits its turn — so on a bigger fleet, raising this is what stops the last printer in a batch from waiting out every transfer before it. Lower it if your network or Bambuddy host struggles with parallel transfers.`)}),(0,G.jsxs)(`div`,{className:`w-full sm:w-1/2`,children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.concurrentUploadsLabel`,`Printers uploaded to at once`)}),(0,G.jsx)(`input`,{type:`number`,min:1,max:16,value:A.queue_max_concurrent_uploads??4,onChange:e=>yr(`queue_max_concurrent_uploads`,Math.max(1,Math.min(16,parseInt(e.target.value)||1))),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.concurrentUploadsHelp`,`1 sends to one printer at a time (the old behaviour). Default is 4.`)})]})]})]}),(0,G.jsxs)(zd,{id:`card-preheat`,children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(hc,{className:`w-4 h-4 text-amber-600 dark:text-amber-400`}),i(`settings.preheatTitle`,`Preheat & Heat Soak`)]})}),(0,G.jsxs)(Vd,{className:`space-y-3`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.preheatDescription`,`Heat the bed (and chamber, if supported) and hold at temperature before each queued print starts. Helpful for engineering filaments (PA, ABS) on printers without an active chamber heater — the bed warms the chamber by radiation while the soak timer runs. The bed target is read from the print file; chamber behaviour depends on printer model.`)}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex-1 mr-4`,children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:i(`settings.preheatEnabled`,`Enable preheat & soak`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:i(`settings.preheatEnabledDesc`,`When off, queued prints dispatch immediately.`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.preheat_enabled??!1,onChange:e=>yr(`preheat_enabled`,e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3 pt-1`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.preheatMaxWait`,`Max wait (seconds)`)}),(0,G.jsx)(`input`,{type:`number`,min:60,max:3600,value:A.preheat_max_wait_seconds??900,onChange:e=>yr(`preheat_max_wait_seconds`,Math.max(60,Math.min(3600,parseInt(e.target.value)||900))),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green disabled:opacity-50`,disabled:!(A.preheat_enabled??!1)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.preheatMaxWaitHelp`,`Cap on the chamber warm-up phase before falling through.`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.preheatSoak`,`Soak (seconds)`)}),(0,G.jsx)(`input`,{type:`number`,min:0,max:1800,value:A.preheat_soak_seconds??300,onChange:e=>yr(`preheat_soak_seconds`,Math.max(0,Math.min(1800,parseInt(e.target.value)||0))),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green disabled:opacity-50`,disabled:!(A.preheat_enabled??!1)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.preheatSoakHelp`,`Hold time after target reached or max-wait elapsed.`)})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between pt-2 border-t border-bambu-dark-tertiary/50`,children:[(0,G.jsxs)(`div`,{className:`flex-1 mr-4`,children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:i(`settings.keepBedWarm`,`Keep bed warm between prints`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:i(`settings.keepBedWarmDesc`,`While awaiting plate-clear, hold the bed at the keep-warm temperature below so the chamber stays hot — or at the next print's own bed temperature when that is higher. Only applies when the next print needs chamber heating (ASA, ABS, PA, PC etc.). Requires plate-clear confirmation to be enabled.`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.queue_keep_bed_warm??!1,onChange:e=>yr(`queue_keep_bed_warm`,e.target.checked),className:`sr-only peer`,disabled:!(A.preheat_enabled??!1)||!(A.require_plate_clear??!1)}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green peer-disabled:opacity-50 peer-disabled:cursor-not-allowed`})]})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-3 mt-2`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.keepWarmBedTemp`,`Keep-warm bed temperature (°C)`)}),(0,G.jsx)(`input`,{type:`number`,min:40,max:110,value:A.queue_keep_warm_bed_temp??90,onChange:e=>yr(`queue_keep_warm_bed_temp`,Math.max(40,Math.min(110,parseInt(e.target.value)||90))),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green disabled:opacity-50`,disabled:!(A.preheat_enabled??!1)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.keepWarmBedTempHelp`,`Used whenever the bed's job is to heat the chamber — the keep-warm hold, and preheat when the print file carries no bed temperature. A higher bed temperature from the print file always wins.`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.keepWarmMaxMinutes`,`Stop keeping warm after (minutes)`)}),(0,G.jsx)(`input`,{type:`number`,min:5,max:480,value:A.queue_keep_warm_max_minutes??120,onChange:e=>yr(`queue_keep_warm_max_minutes`,Math.max(5,Math.min(480,parseInt(e.target.value)||120))),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green disabled:opacity-50`,disabled:!(A.queue_keep_bed_warm??!1)||!(A.preheat_enabled??!1)||!(A.require_plate_clear??!1)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.keepWarmMaxMinutesHelp`,`If the plate is not cleared within this time, the heaters are switched off rather than held indefinitely.`)})]})]}),(0,G.jsxs)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary/50`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-1`,children:[(0,G.jsx)(`label`,{className:`text-sm text-white`,children:i(`settings.preheatFilamentTargetsLabel`,`Per-filament chamber target (°C)`)}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>yr(`preheat_filament_targets`,``),title:i(`settings.preheatFilamentTargetsReset`,`Reset to defaults`),className:`text-bambu-gray hover:text-white transition-colors p-1 rounded hover:bg-bambu-dark-tertiary`,children:(0,G.jsx)(Wl,{className:`w-3.5 h-3.5`})})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:i(`settings.preheatFilamentTargetsHint`,`Bambuddy picks the highest target across the loaded AMS slots; PLA-only prints derive 0 and skip the chamber phase automatically.`)}),(0,G.jsx)(xWe,{value:A.preheat_filament_targets??``,onChange:e=>yr(`preheat_filament_targets`,e),disabled:!(A.preheat_enabled??!1)})]}),(0,G.jsxs)(`p`,{className:`text-xs text-bambu-gray pt-1 border-t border-bambu-dark-tertiary/50`,children:[(0,G.jsx)(`span`,{className:`font-medium text-bambu-gray/90`,children:i(`settings.preheatHardwareTitle`,`Per-printer behaviour:`)}),` `,i(`settings.preheatHardwareDetail`,`H2C/H2D/H2D Pro/H2S/X2D/X1E actively heat the chamber via M141. X1C/P2S read chamber temp but rely on bed-radiation heating. P1S/P1P/A1/A1 Mini have no chamber sensor — only the soak timer applies.`)]})]})]})]}),(0,G.jsxs)(`div`,{className:`lg:w-1/2 space-y-3`,children:[(0,G.jsxs)(zd,{id:`card-pipelines`,children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(ed,{className:`w-4 h-4 text-bambu-green`}),i(`settings.pipelineLimits.title`,`Slicer Pipeline limits`)]})}),(0,G.jsx)(Vd,{className:`space-y-2`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,G.jsxs)(`div`,{className:`flex-1`,children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:i(`settings.pipelineLimits.maxCopiesLabel`,`Max copies per run`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:i(`settings.pipelineLimits.maxCopiesDesc`,`Upper bound on the copies operators can request when running a pipeline. Server-side hard cap is 1000.`)})]}),(0,G.jsx)(`input`,{type:`number`,min:1,max:1e3,value:A.pipeline_max_copies??50,onChange:e=>{let t=parseInt(e.target.value,10);Number.isNaN(t)||yr(`pipeline_max_copies`,Math.max(1,Math.min(1e3,t)))},"aria-label":i(`settings.pipelineLimits.maxCopiesLabel`,`Max copies per run`),className:`w-24 px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm`})]})})]}),(0,G.jsxs)(zd,{id:`card-slicer`,children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(Rs,{className:`w-4 h-4 text-bambu-green`}),i(`settings.slicerCard`,`Slicer`)]})}),(0,G.jsxs)(Vd,{className:`space-y-3`,children:[KGe()&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.sliceEngine`)}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(`select`,{value:G8(A.slice_engine),onChange:e=>yr(`slice_engine`,e.target.value),className:`w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer`,children:W8().map(e=>(0,G.jsx)(`option`,{value:e.id,children:i(e.labelKey)},e.id))}),(0,G.jsx)(ps,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(W8().find(e=>e.id===G8(A.slice_engine))?.descriptionKey??`settings.sliceEngineSidecarHint`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.preferredSlicer`)}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsxs)(`select`,{value:A.preferred_slicer??`bambu_studio`,onChange:e=>yr(`preferred_slicer`,e.target.value),className:`w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer`,children:[(0,G.jsx)(`option`,{value:`bambu_studio`,children:i(`settings.slicerBambuStudio`)}),(0,G.jsx)(`option`,{value:`orcaslicer`,children:i(`settings.slicerOrcaSlicer`)})]}),(0,G.jsx)(ps,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.preferredSlicerDescription`)}),(A.preferred_slicer??`bambu_studio`)===`orcaslicer`&&(0,G.jsx)(`div`,{role:`alert`,className:`text-xs text-amber-800 dark:text-amber-200 bg-amber-50 dark:bg-amber-900/20 border border-amber-300 dark:border-amber-700/40 rounded p-2 mt-2`,children:i(`settings.orcaslicerKnownIssuesWarning`,`OrcaSlicer 2.3.2 / 2.4.0-dev have known CLI bugs that block slicing many Bambu-authored 3MFs — see upstream issues #12426 (segfault on painted multi-extruder files) and #13386 (parameter-range strict-validation reject). Bambu Studio is recommended until the upstream fixes land.`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.openInSlicerLabel`,`Open in Slicer`)}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsxs)(`select`,{value:A.open_in_slicer??``,onChange:e=>yr(`open_in_slicer`,e.target.value===``?null:e.target.value),className:`w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer`,children:[(0,G.jsx)(`option`,{value:``,children:i(`settings.openInSlicerInherit`,`Same as API slicer`)}),(0,G.jsx)(`option`,{value:`bambu_studio`,children:i(`settings.slicerBambuStudio`)}),(0,G.jsx)(`option`,{value:`orcaslicer`,children:i(`settings.slicerOrcaSlicer`)})]}),(0,G.jsx)(ps,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.openInSlicerDescription`,`Desktop slicer used by the 'Open in Slicer' button. Leave on 'Same as API slicer' to inherit, or pick a different slicer to use locally.`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.useSlicerApi`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.useSlicerApiDescription`)})]}),(0,G.jsxs)(`label`,{className:`flex items-center cursor-pointer shrink-0`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.use_slicer_api??!1,onChange:e=>yr(`use_slicer_api`,e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`relative w-11 h-6 bg-bambu-dark-tertiary rounded-full peer peer-checked:bg-bambu-green peer-focus:outline-none peer-focus:ring-2 peer-focus:ring-bambu-green/50 transition-colors after:content-[''] after:absolute after:top-0.5 after:left-0.5 after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-transform peer-checked:after:translate-x-5`})]})]}),(A.use_slicer_api??!1)&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:(A.preferred_slicer??`bambu_studio`)===`orcaslicer`?i(`settings.orcaslicerApiUrl`,`OrcaSlicer sidecar URL`):i(`settings.bambuStudioApiUrl`,`Bambu Studio sidecar URL`)}),(0,G.jsx)(`input`,{type:`text`,value:((A.preferred_slicer??`bambu_studio`)===`orcaslicer`?A.orcaslicer_api_url:A.bambu_studio_api_url)??``,onChange:e=>yr((A.preferred_slicer??`bambu_studio`)===`orcaslicer`?`orcaslicer_api_url`:`bambu_studio_api_url`,e.target.value),placeholder:(A.preferred_slicer??`bambu_studio`)===`orcaslicer`?`http://localhost:3003`:`http://localhost:3001`,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:text-bambu-gray/40`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.slicerApiUrlDescription`,`URL of the slicer-API sidecar container. Leave blank to use the SLICER_API_URL / BAMBU_STUDIO_API_URL env var defaults.`)})]}),(A.use_slicer_api??!1)&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.slicerStallTimeout`)}),(0,G.jsx)(`input`,{type:`number`,min:1,max:240,value:A.slicer_stall_timeout_minutes??15,onChange:e=>yr(`slicer_stall_timeout_minutes`,Number(e.target.value)),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.slicerStallTimeoutDescription`)})]})]})]}),(0,G.jsxs)(zd,{children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,id:`card-drying`,children:[(0,G.jsx)(hc,{className:`w-4 h-4 text-amber-600 dark:text-amber-400`}),i(`settings.queueDrying`)]})}),(0,G.jsxs)(Vd,{className:`space-y-3`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.queueDryingDescription`)}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-white`,children:i(`settings.queueDryingEnabled`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:i(`settings.queueDryingEnabledDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.queue_drying_enabled??!1,onChange:e=>yr(`queue_drying_enabled`,e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),A.queue_drying_enabled&&(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-white`,children:i(`settings.queueDryingBlock`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:i(`settings.queueDryingBlockDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.queue_drying_block??!1,onChange:e=>yr(`queue_drying_block`,e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-amber-500`})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-white`,children:i(`settings.ambientDryingEnabled`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:i(`settings.ambientDryingEnabledDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.ambient_drying_enabled??!1,onChange:e=>yr(`ambient_drying_enabled`,e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-white`,children:i(`settings.printDryingEnabled`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:i(`settings.printDryingEnabledDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.print_drying_enabled??!1,onChange:e=>yr(`print_drying_enabled`,e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`p`,{className:`text-sm text-white font-medium`,children:i(`settings.dryingPresets`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.dryingPresetsDescription`)}),(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`,children:i(`settings.dryingFilament`)}),(0,G.jsx)(`th`,{className:`text-center py-1.5`,colSpan:2,children:`AMS 2 Pro`}),(0,G.jsx)(`th`,{className:`text-center py-1.5`,colSpan:2,children:`AMS-HT`})]})}),(0,G.jsx)(`tbody`,{children:(()=>{let e={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}},t={...e};try{if(A.drying_presets){let n=JSON.parse(A.drying_presets);typeof n==`object`&&n&&(t={...e,...n})}}catch{}let n=(e,n,r)=>{let i={...t,[e]:{...t[e],[n]:r}};yr(`drying_presets`,JSON.stringify(i))};return Object.entries(t).map(([e,t])=>(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/50`,children:[(0,G.jsx)(`td`,{className:`py-1.5 pr-2 text-white font-medium`,children:e}),(0,G.jsx)(`td`,{className:`py-1 px-1`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-end gap-1`,children:[(0,G.jsx)(`input`,{type:`number`,min:30,max:65,value:t.n3f,onChange:t=>n(e,`n3f`,Math.max(1,parseInt(t.target.value)||0)),className:`w-14 px-1.5 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-center text-xs focus:border-amber-500/50 focus:outline-none [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none`}),(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:`°C`})]})}),(0,G.jsx)(`td`,{className:`py-1 px-1`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(`input`,{type:`number`,min:1,max:24,value:t.n3f_hours,onChange:t=>n(e,`n3f_hours`,Math.max(1,parseInt(t.target.value)||0)),className:`w-14 px-1.5 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-center text-xs focus:border-amber-500/50 focus:outline-none [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none`}),(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:`h`})]})}),(0,G.jsx)(`td`,{className:`py-1 px-1`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-end gap-1`,children:[(0,G.jsx)(`input`,{type:`number`,min:30,max:85,value:t.n3s,onChange:t=>n(e,`n3s`,Math.max(1,parseInt(t.target.value)||0)),className:`w-14 px-1.5 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-center text-xs focus:border-amber-500/50 focus:outline-none [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none`}),(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:`°C`})]})}),(0,G.jsx)(`td`,{className:`py-1 px-1`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(`input`,{type:`number`,min:1,max:24,value:t.n3s_hours,onChange:t=>n(e,`n3s_hours`,Math.max(1,parseInt(t.target.value)||0)),className:`w-14 px-1.5 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-center text-xs focus:border-amber-500/50 focus:outline-none [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none`}),(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:`h`})]})})]},e))})()})]})})]}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`p`,{className:`text-sm text-white font-medium`,children:i(`settings.humidityThresholds`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.humidityThresholdsDescription`)}),(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`,children:i(`settings.dryingFilament`)}),(0,G.jsx)(`th`,{className:`text-right py-1.5 pr-2`,children:i(`settings.humidityThresholdCol`)})]})}),(0,G.jsx)(`tbody`,{children:(()=>{let e=A.ams_humidity_fair??60,t=[`PLA`,`PETG`,`TPU`,`ABS`,`ASA`,`PA`,`PC`,`PVA`],n={};try{if(A.ams_humidity_thresholds){let e=JSON.parse(A.ams_humidity_thresholds);typeof e==`object`&&e&&(n=e)}}catch{}let r=[{key:`default`,label:i(`settings.humidityThresholdDefault`),value:Number(n.default??e),isDefault:!0},...t.map(t=>({key:t,label:t,value:Number(n[t]??n.default??e),isDefault:!1}))],a=(e,t)=>{if(t.trim()===``){let t={...n};delete t[e],yr(`ams_humidity_thresholds`,JSON.stringify(t));return}let r=parseInt(t,10);if(Number.isNaN(r))return;let i=Math.max(5,Math.min(95,r)),a={...n,[e]:i};yr(`ams_humidity_thresholds`,JSON.stringify(a))};return r.map(e=>{let t=M[e.key],n=t===void 0?String(e.value):t;return(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/50`,children:[(0,G.jsx)(`td`,{className:`py-1.5 pr-2 font-medium ${e.isDefault?`text-bambu-gray italic`:`text-white`}`,children:e.label}),(0,G.jsx)(`td`,{className:`py-1 pr-2`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-end gap-1`,children:[(0,G.jsx)(`input`,{type:`number`,min:5,max:95,value:n,onChange:t=>N(n=>({...n,[e.key]:t.target.value})),onBlur:t=>{a(e.key,t.target.value),N(t=>{let n={...t};return delete n[e.key],n})},onKeyDown:e=>{e.key===`Enter`&&e.currentTarget.blur()},className:`w-14 px-1.5 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-center text-xs focus:border-amber-500/50 focus:outline-none [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none`}),(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:`%`})]})})]},e.key)})})()})]})})]})]})]}),(0,G.jsxs)(zd,{id:`card-gcode`,children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(Fs,{className:`w-4 h-4 text-bambu-green`}),i(`settings.gcodeInjection`,`G-code Injection`)]})}),(0,G.jsxs)(Vd,{className:`space-y-3`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.gcodeInjectionDescription`,`Configure custom G-code to inject at the start and/or end of prints for auto-print systems like Farmloop, SwapMod, AutoClear, and Printflow 3D. Snippets are configured per printer model and applied when "Inject G-code" is enabled on a queue item.`)}),(()=>{let e=(()=>{try{return A.gcode_snippets?JSON.parse(A.gcode_snippets):{}}catch{return{}}})(),t=[...new Set((sn||[]).filter(e=>e.model).map(e=>e.model))].sort(),n=(t,n,r)=>{let i={...e};i[t]||(i[t]={start_gcode:``,end_gcode:``}),i[t][n]=r,!i[t].start_gcode&&!i[t].end_gcode&&delete i[t];let a=Object.keys(i).length>0?JSON.stringify(i):``;j(e=>e?{...e,gcode_snippets:a}:null),pr.current=a},r=()=>{pr.current!==null&&(_r.mutate({gcode_snippets:pr.current}),pr.current=null)};return t.length===0?(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray italic`,children:i(`settings.gcodeInjectionNoPrinters`,`No printers found. Add printers to configure G-code snippets.`)}):t.map(t=>{let a=e[t]||{start_gcode:``,end_gcode:``},o=!!(a.start_gcode||a.end_gcode);return(0,G.jsx)($p,{defaultOpen:o,className:`border border-bambu-dark-tertiary rounded-lg px-3 py-2`,summary:(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`h4`,{className:`text-sm font-medium text-white`,children:t}),o&&(0,G.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-bambu-green/20 text-bambu-green`,children:i(`settings.gcodeConfigured`,`Configured`)})]}),children:(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.gcodeStartLabel`,`Start G-code`)}),(0,G.jsx)(`textarea`,{value:a.start_gcode,onChange:e=>n(t,`start_gcode`,e.target.value),onBlur:r,placeholder:i(`settings.gcodeStartPlaceholder`,`G-code prepended before the print starts...`),rows:3,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-xs font-mono focus:outline-none focus:border-bambu-green resize-y`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.gcodeEndLabel`,`End G-code`)}),(0,G.jsx)(`textarea`,{value:a.end_gcode,onChange:e=>n(t,`end_gcode`,e.target.value),onBlur:r,placeholder:i(`settings.gcodeEndPlaceholder`,`G-code appended after the print ends...`),rows:3,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-xs font-mono focus:outline-none focus:border-bambu-green resize-y`})]})]})},t)})})()]})]})]})]})]}),je===`filament`&&A&&(0,G.jsx)(G.Fragment,{children:(0,G.jsxs)(`div`,{className:`flex flex-col lg:flex-row gap-4 lg:gap-6`,children:[(0,G.jsxs)(`div`,{className:`lg:w-1/3 space-y-3`,children:[(0,G.jsx)(lGe,{}),(0,G.jsxs)(zd,{id:`card-filamentchecks`,children:[(0,G.jsx)(Bd,{children:(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(`settings.filamentChecks`)})}),(0,G.jsxs)(Vd,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.disableFilamentWarnings`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.disableFilamentWarningsDesc`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.disable_filament_warnings,onChange:e=>yr(`disable_filament_warnings`,e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.preferLowestFilament`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.preferLowestFilamentDesc`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray/70 mt-1`,children:i(`settings.preferLowestFilamentBackupNote`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.prefer_lowest_filament,onChange:e=>yr(`prefer_lowest_filament`,e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]})]})]}),(0,G.jsxs)(zd,{id:`card-printmodal`,children:[(0,G.jsx)(Bd,{children:(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(`settings.printModal`)})}),(0,G.jsx)(Vd,{className:`space-y-3`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.expandCustomMapping`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.expandCustomMappingDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.per_printer_mapping_expanded??!1,onChange:e=>yr(`per_printer_mapping_expanded`,e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]})})]}),(0,G.jsxs)(zd,{id:`card-amsthresholds`,children:[(0,G.jsx)(Bd,{children:(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(`settings.amsDisplayThresholds`)})}),(0,G.jsxs)(Vd,{className:`space-y-3`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.amsThresholdsDescription`)}),(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-white`,children:[(0,G.jsx)(Qs,{className:`w-4 h-4 text-blue-600 dark:text-blue-400`}),(0,G.jsx)(`span`,{className:`font-medium`,children:i(`settings.humidity`)})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[i(`settings.goodGreen`),` ≤`]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`input`,{type:`number`,min:`0`,max:`100`,value:A.ams_humidity_good??40,onChange:e=>yr(`ams_humidity_good`,parseInt(e.target.value)||40),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:`%`})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[i(`settings.fairOrange`),` ≤`]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`input`,{type:`number`,min:`0`,max:`100`,value:A.ams_humidity_fair??60,onChange:e=>yr(`ams_humidity_fair`,parseInt(e.target.value)||60),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:`%`})]})]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.aboveFairBad`)}),(0,G.jsx)(`p`,{className:`text-xs text-amber-700/80 dark:text-amber-400/70`,children:i(`settings.fairAlsoDryingThreshold`)}),(A.ams_humidity_fair??60)yr(`ams_temp_good`,parseFloat(e.target.value)||28),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:`°C`})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[i(`settings.fairOrange`),` ≤`]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`input`,{type:`number`,step:`0.5`,min:`0`,max:`60`,value:A.ams_temp_fair??35,onChange:e=>yr(`ams_temp_fair`,parseFloat(e.target.value)||35),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:`°C`})]})]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.aboveFairHot`)}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.tempAlarmThreshold`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`input`,{type:`number`,step:`0.5`,min:`0.5`,max:`120`,value:A.ams_temp_alarm??``,placeholder:String(A.ams_temp_fair??35),onChange:e=>{let t=e.target.value.trim(),n=parseFloat(t);yr(`ams_temp_alarm`,t===``||Number.isNaN(n)?null:n)},className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:`°C`})]})]}),(A.ams_temp_alarm??1)<=0&&(0,G.jsx)(`p`,{className:`text-xs text-red-600 dark:text-red-400`,children:i(`settings.tempAlarmMustBePositive`)}),(0,G.jsx)(`p`,{className:`text-xs text-amber-700/80 dark:text-amber-400/70`,children:i(`settings.tempAlarmSeparateFromBand`)})]}),(0,G.jsxs)(`div`,{className:`space-y-3 pt-4 border-t border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-white`,children:[(0,G.jsx)(Gs,{className:`w-4 h-4 text-purple-600 dark:text-purple-400`}),(0,G.jsx)(`span`,{className:`font-medium`,children:i(`settings.historyRetention`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.keepSensorHistory`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`input`,{type:`number`,min:`1`,max:`365`,value:A.ams_history_retention_days??30,onChange:e=>yr(`ams_history_retention_days`,parseInt(e.target.value)||30),className:`w-24 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:i(`common.days`)})]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.historyRetentionDescription`)})]})]})]})]}),(0,G.jsxs)(`div`,{className:`lg:w-2/3 space-y-3`,children:[(0,G.jsx)(uGe,{}),(0,G.jsx)(dGe,{})]})]})}),Ye!==null&&(0,G.jsx)(of,{title:i(`settings.deleteApiKeyTitle`),message:i(`settings.deleteApiKeyMessage`),confirmText:i(`settings.deleteKey`),variant:`danger`,onConfirm:()=>{on.mutate(Ye),Xe(null)},onCancel:()=>Xe(null)}),P&&(0,G.jsx)(FWe,{plug:I,onClose:()=>{F(!1),L(null)}}),R&&(0,G.jsx)(IWe,{sensor:B,printers:sn??[],onClose:()=>{z(!1),V(null)}}),ee&&(0,G.jsx)(RWe,{sensor:ne,locations:un??[],onClose:()=>{te(!1),re(null)}}),ie&&(0,G.jsx)(VWe,{onClose:()=>ae(!1)}),le&&(0,G.jsx)(of,{title:i(`locationHaSensors.deleteAllConfirm.title`),message:i(`locationHaSensors.deleteAllConfirm.message`,{location:le.locationName,count:le.sensorIds.length}),variant:`danger`,isLoading:pn.isPending,onConfirm:()=>pn.mutate(le.sensorIds),onCancel:()=>ue(null)}),de&&(0,G.jsx)(WWe,{provider:pe,onClose:()=>{fe(!1),me(null)}}),he&&(0,G.jsx)(GWe,{template:he,onClose:()=>ge(null)}),xe&&(0,G.jsx)(qWe,{onClose:()=>Se(!1)}),$e&&(0,G.jsx)(of,{title:i(`settings.clearNotificationLogs`),message:i(`settings.clearLogsMessage`),confirmText:i(`settings.clearLogs`),variant:`warning`,onConfirm:async()=>{et(!1);try{o((await Z.clearNotificationLogs(30)).message,`success`)}catch{o(i(`settings.toast.clearLogsFailed`),`error`)}},onCancel:()=>et(!1)}),tt&&(0,G.jsx)(of,{title:i(`settings.resetUiPreferences`),message:i(`settings.resetUiPreferencesMessage`),confirmText:i(`settings.resetPreferences`),variant:`default`,onConfirm:()=>{nt(!1),localStorage.clear(),o(i(`settings.toast.uiPreferencesReset`),`success`),setTimeout(()=>window.location.reload(),1e3)},onCancel:()=>nt(!1)}),rt&&(0,G.jsx)(of,{title:`Turn All Plugs ${rt===`on`?`On`:`Off`}`,message:`This will turn ${rt===`on`?`ON`:`OFF`} all ${Zt?.filter(e=>e.enabled).length||0} enabled smart plugs. ${rt===`off`?`Any running printers may be affected!`:``}`,confirmText:`Turn All ${rt===`on`?`On`:`Off`}`,variant:rt===`off`?`danger`:`warning`,onConfirm:()=>{let e=rt;it(null),dr.mutate(e)},onCancel:()=>it(null)}),at&&Pn?.release_notes&&(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,onClick:()=>ot(!1),children:(0,G.jsxs)(zd,{className:`w-full max-w-2xl max-h-[80vh] flex flex-col`,onClick:e=>e.stopPropagation(),children:[(0,G.jsxs)(Bd,{className:`flex flex-row items-center justify-between shrink-0`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white`,children:[`Release Notes - v`,Pn.latest_version]}),Pn.release_name&&Pn.release_name!==Pn.latest_version&&(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:Pn.release_name})]}),(0,G.jsx)(`button`,{onClick:()=>ot(!1),className:`p-1 rounded hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white`,children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]}),(0,G.jsx)(Vd,{className:`overflow-y-auto flex-1`,children:(0,G.jsx)(`pre`,{className:`text-sm text-bambu-gray whitespace-pre-wrap font-sans`,children:Pn.release_notes})}),(0,G.jsxs)(`div`,{className:`p-4 border-t border-bambu-dark-tertiary shrink-0 flex gap-2`,children:[Pn.release_url&&(0,G.jsx)(`a`,{href:Pn.release_url,target:`_blank`,rel:`noopener noreferrer`,className:`flex-1`,children:(0,G.jsxs)(Q,{variant:`secondary`,className:`w-full`,children:[(0,G.jsx)(rc,{className:`w-4 h-4`}),`View on GitHub`]})}),(0,G.jsx)(Q,{onClick:()=>ot(!1),className:`flex-1`,children:`Close`})]})]})}),je===`users`&&(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{className:`flex gap-1 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`button`,{onClick:()=>Pe(`users`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${Ne===`users`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,G.jsx)(Uu,{className:`w-4 h-4`}),i(`settings.tabs.users`)]}),(0,G.jsxs)(`button`,{onClick:()=>Pe(`email`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${Ne===`email`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,G.jsx)(al,{className:`w-4 h-4`}),i(`settings.tabs.emailAuth`)||`Email Authentication`,Hn?.advanced_auth_enabled&&(0,G.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-green-400`})]}),(0,G.jsxs)(`button`,{onClick:()=>Pe(`ldap`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${Ne===`ldap`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,G.jsx)(su,{className:`w-4 h-4`}),i(`settings.tabs.ldap`)||`LDAP`,Un?.ldap_enabled&&(0,G.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-green-400`})]}),(0,G.jsxs)(`button`,{onClick:()=>Pe(`twofa`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${Ne===`twofa`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,G.jsx)(su,{className:`w-4 h-4`}),i(`settings.tabs.twoFa`),(0,G.jsx)(`span`,{className:`w-2 h-2 rounded-full ${Wn?.totp_enabled||Wn?.email_otp_enabled?`bg-green-400`:`bg-bambu-gray/40`}`})]}),l&&(0,G.jsxs)(`button`,{onClick:()=>Pe(`oidc`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${Ne===`oidc`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,G.jsx)(Ac,{className:`w-4 h-4`}),i(`settings.tabs.oidc`),(0,G.jsx)(`span`,{className:`w-2 h-2 rounded-full ${Gn.some(e=>e.is_enabled)?`bg-green-400`:`bg-bambu-gray/40`}`})]}),l&&(0,G.jsxs)(`button`,{onClick:()=>Pe(`security`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${Ne===`security`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,G.jsx)(su,{className:`w-4 h-4`}),i(`settings.tabs.security`)]})]}),Ne===`users`&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(zd,{children:(0,G.jsx)(Vd,{className:`py-4`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`w-10 h-10 rounded-full flex items-center justify-center ${s?`bg-green-500/20`:`bg-gray-500/20`}`,children:s?(0,G.jsx)(nl,{className:`w-5 h-5 text-green-600 dark:text-green-400`}):(0,G.jsx)(tl,{className:`w-5 h-5 text-gray-400`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`text-white font-medium`,children:i(`settings.authentication`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(s?`settings.authEnabledDescription`:`settings.authDisabledDescription`)})]})]}),s?c?.is_admin&&(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>ct(!0),children:[(0,G.jsx)(tl,{className:`w-4 h-4`}),i(`common.disable`)]}):(0,G.jsxs)(Q,{onClick:()=>t(`/setup`),children:[(0,G.jsx)(nl,{className:`w-4 h-4`}),i(`common.enable`)]})]})})}),Hn?.advanced_auth_enabled&&(0,G.jsx)(zd,{className:`border-blue-500/30 bg-blue-500/5`,children:(0,G.jsx)(Vd,{className:`py-4`,children:(0,G.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,G.jsx)(`div`,{className:`w-10 h-10 rounded-full flex items-center justify-center bg-blue-500/20 flex-shrink-0`,children:(0,G.jsx)(al,{className:`w-5 h-5 text-blue-600 dark:text-blue-400`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`text-white font-medium`,children:i(`settings.email.advancedAuthEnabled`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:i(`settings.email.advancedAuthEnabledDesc`)})]})]})})}),s&&(0,G.jsxs)(`div`,{className:`grid grid-cols-1 xl:grid-cols-2 gap-6`,children:[(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(zd,{id:`card-session-policy`,children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`h3`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(nl,{className:`w-5 h-5 text-bambu-green`}),i(`settings.sessionPolicy.title`)]})}),(0,G.jsxs)(Vd,{children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4`,children:i(`settings.sessionPolicy.description`)}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 sm:grid-cols-4 gap-2 mb-4`,children:[[{hours:24,labelKey:`settings.sessionPolicy.preset24h`},{hours:168,labelKey:`settings.sessionPolicy.preset7d`},{hours:720,labelKey:`settings.sessionPolicy.preset30d`}].map(e=>{let t=(A?.session_max_hours??24)===e.hours;return(0,G.jsx)(`button`,{type:`button`,onClick:()=>yr(`session_max_hours`,e.hours),disabled:s&&!d(`settings:update`),className:`px-3 py-2 rounded-lg text-sm font-medium transition-colors ${t?`bg-bambu-green text-white`:`bg-bambu-dark-tertiary text-bambu-gray hover:text-white hover:bg-bambu-dark`} disabled:opacity-50 disabled:cursor-not-allowed`,children:i(e.labelKey)},e.hours)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(`input`,{type:`number`,min:1,max:720,value:A?.session_max_hours??24,onChange:e=>{let t=parseInt(e.target.value,10);Number.isNaN(t)||yr(`session_max_hours`,Math.max(1,Math.min(720,t)))},disabled:s&&!d(`settings:update`),"aria-label":i(`settings.sessionPolicy.customHoursLabel`),className:`w-20 px-2 py-2 bg-bambu-dark-tertiary text-white text-sm rounded-lg border border-bambu-dark-tertiary focus:border-bambu-green focus:outline-none disabled:opacity-50`}),(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:i(`settings.sessionPolicy.hoursSuffix`)})]})]}),(A?.session_max_hours??24)>24&&(0,G.jsxs)(`div`,{className:`flex items-start gap-2 p-3 rounded-lg bg-yellow-50 dark:bg-yellow-500/10 border border-yellow-300 dark:border-yellow-500/30`,children:[(0,G.jsx)(Lu,{className:`w-4 h-4 text-yellow-600 dark:text-yellow-400 flex-shrink-0 mt-0.5`}),(0,G.jsx)(`p`,{className:`text-xs text-yellow-800 dark:text-yellow-200`,children:i(`settings.sessionPolicy.warning`)})]})]})]}),c&&(0,G.jsxs)(zd,{children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`h3`,{className:`text-lg font-semibold text-white flex items-center gap-2`,id:`card-currentuser`,children:[(0,G.jsx)(Uu,{className:`w-5 h-5 text-bambu-green`}),i(`settings.currentUser`)]}),c.auth_source!==`ldap`&&(0,G.jsxs)(Q,{size:`sm`,variant:`ghost`,onClick:()=>ut(!0),children:[(0,G.jsx)(Kc,{className:`w-4 h-4`}),i(`settings.changePassword`)]})]})}),(0,G.jsx)(Vd,{children:(0,G.jsx)(`div`,{className:`flex items-center justify-between`,children:(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white font-medium text-lg`,children:c.username}),(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-1 mt-2`,children:[c.is_admin&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 rounded-full text-xs font-medium bg-purple-100 dark:bg-purple-500/20 text-purple-700 dark:text-purple-300`,children:i(`settings.admin`)}),c.groups?.map(e=>(0,G.jsx)(`span`,{className:`px-2 py-0.5 rounded-full text-xs font-medium ${e.name===`Administrators`?`bg-purple-100 dark:bg-purple-500/20 text-purple-700 dark:text-purple-300`:e.name===`Operators`?`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-300`:e.name===`Viewers`?`bg-green-100 dark:bg-green-500/20 text-green-700 dark:text-green-300`:`bg-gray-500/20 text-gray-300`}`,children:e.name},e.id))]})]})})})]}),(0,G.jsxs)(zd,{children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`h3`,{className:`text-lg font-semibold text-white flex items-center gap-2`,id:`card-users`,children:[(0,G.jsx)(Uu,{className:`w-5 h-5 text-bambu-green`}),i(`settings.users`)]}),d(`users:create`)&&(0,G.jsxs)(Q,{size:`sm`,onClick:()=>{vt(!0),Nt({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]})},children:[(0,G.jsx)(Fl,{className:`w-4 h-4`}),i(`settings.addUser`)]})]})}),(0,G.jsx)(Vd,{children:qn?(0,G.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,G.jsx)(Y,{className:`w-6 h-6 text-bambu-green animate-spin`})}):Kn.length===0?(0,G.jsx)(`p`,{className:`text-center text-bambu-gray py-8`,children:i(`settings.noUsersFound`)}):(0,G.jsx)(`div`,{className:`divide-y divide-bambu-dark-tertiary`,children:Kn.map(e=>(0,G.jsxs)(`div`,{className:`py-3 flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`p`,{className:`text-white font-medium truncate`,children:e.username}),(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-1 mt-1`,children:[e.auth_source===`ldap`&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 rounded-full text-xs font-medium bg-cyan-100 dark:bg-cyan-500/20 text-cyan-700 dark:text-cyan-300`,children:`LDAP`}),e.is_admin&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 rounded-full text-xs font-medium bg-purple-100 dark:bg-purple-500/20 text-purple-700 dark:text-purple-300`,children:i(`settings.admin`)}),e.groups?.map(e=>(0,G.jsx)(`span`,{className:`px-2 py-0.5 rounded-full text-xs font-medium ${e.name===`Administrators`?`bg-purple-100 dark:bg-purple-500/20 text-purple-700 dark:text-purple-300`:e.name===`Operators`?`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-300`:e.name===`Viewers`?`bg-green-100 dark:bg-green-500/20 text-green-700 dark:text-green-300`:`bg-gray-500/20 text-gray-300`}`,children:e.name},e.id))]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1 ml-4`,children:[d(`users:update`)&&(0,G.jsx)(Q,{size:`sm`,variant:`ghost`,onClick:()=>ir(e),children:(0,G.jsx)(kl,{className:`w-4 h-4`})}),d(`users:delete`)&&e.id!==c?.id&&(0,G.jsx)(Q,{size:`sm`,variant:`ghost`,onClick:()=>er(e.id),children:(0,G.jsx)(Pu,{className:`w-4 h-4`})})]})]},e.id))})})]})]}),(0,G.jsx)(`div`,{children:(0,G.jsxs)(zd,{children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`h3`,{className:`text-lg font-semibold text-white flex items-center gap-2`,id:`card-groups`,children:[(0,G.jsx)(su,{className:`w-5 h-5 text-bambu-green`}),i(`settings.groups`)]}),d(`groups:create`)&&(0,G.jsxs)(Q,{size:`sm`,onClick:()=>t(`/groups/new`),children:[(0,G.jsx)(Fl,{className:`w-4 h-4`}),i(`settings.addGroup`)]})]})}),(0,G.jsx)(Vd,{children:Yn?(0,G.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,G.jsx)(Y,{className:`w-6 h-6 text-bambu-green animate-spin`})}):Jn.length===0?(0,G.jsx)(`p`,{className:`text-center text-bambu-gray py-8`,children:i(`settings.noGroupsFound`)}):(0,G.jsx)(`div`,{className:`divide-y divide-bambu-dark-tertiary`,children:Jn.map(e=>(0,G.jsxs)(`div`,{className:`py-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(su,{className:`w-4 h-4 ${e.name===`Administrators`?`text-purple-600 dark:text-purple-400`:e.name===`Operators`?`text-blue-600 dark:text-blue-400`:e.name===`Viewers`?`text-green-600 dark:text-green-400`:`text-bambu-gray`}`}),(0,G.jsx)(`span`,{className:`text-white font-medium`,children:e.name}),e.is_system&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 rounded text-xs bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400`,children:i(`settings.system`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[d(`groups:update`)&&(0,G.jsx)(Q,{size:`sm`,variant:`ghost`,onClick:()=>t(`/groups/${e.id}/edit`),children:(0,G.jsx)(kl,{className:`w-4 h-4`})}),d(`groups:delete`)&&!e.is_system&&(0,G.jsx)(Q,{size:`sm`,variant:`ghost`,onClick:()=>Ft(e.id),children:(0,G.jsx)(Pu,{className:`w-4 h-4`})})]})]}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1 ml-6`,children:e.description||i(`settings.noDescription`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-4 mt-2 ml-6 text-xs text-bambu-gray`,children:[(0,G.jsx)(`span`,{children:i(`settings.userCount`,{count:e.user_count})}),(0,G.jsx)(`span`,{children:i(`settings.permissionCount`,{count:e.permissions.length})})]})]},e.id))})})]})})]}),!s&&(0,G.jsx)(zd,{children:(0,G.jsx)(Vd,{className:`py-6`,children:(0,G.jsxs)(`div`,{className:`text-center`,children:[(0,G.jsx)(tl,{className:`w-12 h-12 text-bambu-gray mx-auto mb-4`}),(0,G.jsx)(`h3`,{className:`text-lg font-medium text-white mb-2`,children:i(`settings.authDisabledTitle`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4 max-w-md mx-auto`,children:i(`settings.authDisabledMessage`)}),(0,G.jsxs)(`ul`,{className:`space-y-2 text-sm text-bambu-gray mb-6 text-left max-w-xs mx-auto`,children:[(0,G.jsxs)(`li`,{className:`flex items-start gap-2`,children:[(0,G.jsx)(xs,{className:`w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0`}),(0,G.jsx)(`span`,{children:i(`settings.authDisabledFeature1`)})]}),(0,G.jsxs)(`li`,{className:`flex items-start gap-2`,children:[(0,G.jsx)(xs,{className:`w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0`}),(0,G.jsx)(`span`,{children:i(`settings.authDisabledFeature2`)})]}),(0,G.jsxs)(`li`,{className:`flex items-start gap-2`,children:[(0,G.jsx)(xs,{className:`w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0`}),(0,G.jsx)(`span`,{children:i(`settings.authDisabledFeature3`)})]})]}),(0,G.jsxs)(Q,{onClick:()=>t(`/setup`),children:[(0,G.jsx)(nl,{className:`w-4 h-4`}),i(`settings.enableAuthentication`)]})]})})})]}),Ne===`email`&&(0,G.jsx)(`div`,{className:`max-w-5xl`,id:`card-smtp`,children:(0,G.jsx)(jGe,{})}),Ne===`ldap`&&(0,G.jsx)(`div`,{className:`max-w-5xl`,id:`card-ldap`,children:(0,G.jsx)(NGe,{})}),Ne===`twofa`&&(0,G.jsx)(`div`,{className:`max-w-2xl`,children:(0,G.jsx)(FGe,{})}),Ne===`oidc`&&l&&(0,G.jsxs)(`div`,{className:`max-w-3xl space-y-4`,children:[(0,G.jsx)(zd,{children:(0,G.jsx)(Vd,{className:`space-y-3 p-4`,children:(0,G.jsxs)(`label`,{className:`flex items-start gap-3 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.local_login_enabled===!1,onChange:e=>yr(`local_login_enabled`,!e.target.checked),className:`mt-1 h-4 w-4 rounded border-bambu-dark-tertiary bg-bambu-dark-secondary text-bambu-green focus:ring-bambu-green/50 cursor-pointer`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm font-medium text-white`,children:i(`settings.localLogin.disable`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:i(`settings.localLogin.disableHint`)})]})]})})}),(0,G.jsx)(RGe,{})]}),Ne===`security`&&l&&(0,G.jsx)(`div`,{className:`max-w-3xl`,children:(0,G.jsx)(BGe,{})})]}),_t&&!Hn?.advanced_auth_enabled&&(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black flex items-center justify-center z-50 p-4`,onClick:()=>{vt(!1),Nt({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]})},children:(0,G.jsxs)(zd,{className:`w-full max-w-md`,onClick:e=>e.stopPropagation(),children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Uu,{className:`w-5 h-5 text-bambu-green`}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(`settings.createUser`)})]}),(0,G.jsx)(Q,{variant:`ghost`,size:`sm`,onClick:()=>{vt(!1),Nt({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]})},children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]})}),(0,G.jsxs)(Vd,{children:[Un?.ldap_enabled&&(0,G.jsxs)(`div`,{className:`mb-4 flex items-center gap-1 p-1 bg-bambu-dark-secondary rounded-lg`,role:`tablist`,"aria-label":i(`users.modal.tabsAriaLabel`),children:[(0,G.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":yt===`local`,onClick:()=>bt(`local`),className:`flex-1 px-3 py-2 text-sm rounded-md transition-colors ${yt===`local`?`bg-bambu-green/15 text-bambu-green`:`text-bambu-gray hover:text-white`}`,children:i(`users.modal.localTab`)}),(0,G.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":yt===`ldap`,onClick:()=>bt(`ldap`),className:`flex-1 px-3 py-2 text-sm rounded-md transition-colors ${yt===`ldap`?`bg-bambu-green/15 text-bambu-green`:`text-bambu-gray hover:text-white`}`,children:i(`users.modal.ldapTab`)})]}),yt===`ldap`&&Un?.ldap_enabled?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(C8,{onSuccess:e=>{vt(!1),bt(`local`),Nt({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]}),o(i(`users.toast.ldapProvisioned`,{username:e.username}))}}),(0,G.jsx)(`div`,{className:`mt-6 flex justify-end`,children:(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>{vt(!1),bt(`local`),Nt({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]})},children:i(`common.cancel`)})})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:i(`settings.username`)}),(0,G.jsx)(`input`,{type:`text`,value:Mt.username,onChange:e=>Nt({...Mt,username:e.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:i(`settings.enterUsername`),autoComplete:`username`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:i(`settings.password`)}),(0,G.jsx)(`input`,{type:`password`,value:Mt.password,onChange:e=>Nt({...Mt,password:e.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:i(`settings.enterPassword`),autoComplete:`new-password`,minLength:8}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-xs mt-1`,children:i(`settings.passwordRequirements`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:i(`settings.confirmPassword`)}),(0,G.jsx)(`input`,{type:`password`,value:Mt.confirmPassword,onChange:e=>Nt({...Mt,confirmPassword:e.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors ${Mt.confirmPassword&&Mt.password!==Mt.confirmPassword?`border-red-500`:`border-bambu-dark-tertiary`}`,placeholder:i(`settings.confirmPasswordPlaceholder`),autoComplete:`new-password`,minLength:6}),Mt.confirmPassword&&Mt.password!==Mt.confirmPassword&&(0,G.jsx)(`p`,{className:`text-red-700 dark:text-red-400 text-xs mt-1`,children:i(`settings.passwordsDoNotMatch`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:i(`settings.groups`)}),(0,G.jsxs)(`div`,{className:`space-y-2 max-h-40 overflow-y-auto p-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg`,children:[Jn.map(e=>(0,G.jsxs)(`label`,{className:`flex items-center gap-3 px-2 py-1.5 rounded hover:bg-bambu-dark-tertiary cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:Mt.group_ids.includes(e.id),onChange:()=>ar(e.id),className:`w-4 h-4 rounded border-bambu-gray text-bambu-green focus:ring-bambu-green focus:ring-offset-0 bg-bambu-dark`}),(0,G.jsx)(`span`,{className:`text-sm text-white`,children:e.name}),e.is_system&&(0,G.jsx)(`span`,{className:`text-xs text-yellow-700 dark:text-yellow-400`,children:i(`settings.systemBadge`)})]},e.id)),Jn.length===0&&(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.noGroupsAvailable`)})]})]})]}),(0,G.jsxs)(`div`,{className:`mt-6 flex justify-end gap-3`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>{vt(!1),Nt({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]})},children:i(`common.cancel`)}),(0,G.jsx)(Q,{onClick:nr,disabled:Xn.isPending||!Mt.username||!Mt.password||Mt.password!==Mt.confirmPassword||_6(Mt.password)!==null,children:Xn.isPending?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),i(`settings.creating`)]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Fl,{className:`w-4 h-4`}),i(`settings.createUser`)]})})]})]})]})]})}),_t&&Hn?.advanced_auth_enabled&&(0,G.jsx)(cGe,{formData:Mt,setFormData:Nt,groups:Jn,onClose:()=>{vt(!1),Nt({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]})},onCreate:nr,isCreating:Xn.isPending,isCreateButtonDisabled:Xn.isPending||!Mt.username||!Mt.email,ldapEnabled:Un?.ldap_enabled,onLdapProvisioned:e=>{vt(!1),Nt({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]}),o(i(`users.toast.ldapProvisioned`,{username:e.username}))}}),xt&&Ct!==null&&(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black flex items-center justify-center z-50 p-4`,onClick:()=>{St(!1),wt(null),Nt({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]})},children:(0,G.jsxs)(zd,{className:`w-full max-w-md`,onClick:e=>e.stopPropagation(),children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(kl,{className:`w-5 h-5 text-bambu-green`}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(`settings.editUser`)})]}),(0,G.jsx)(Q,{variant:`ghost`,size:`sm`,onClick:()=>{St(!1),wt(null),Nt({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]})},children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]})}),(0,G.jsxs)(Vd,{children:[(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:[i(`settings.username`),` `,Hn?.advanced_auth_enabled&&(0,G.jsx)(`span`,{className:`text-red-700 dark:text-red-400`,children:`*`})]}),(0,G.jsx)(`input`,{type:`text`,value:Mt.username,onChange:e=>Nt({...Mt,username:e.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:i(`settings.enterUsername`),autoComplete:`username`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:[i(`users.form.email`)||`Email`,` `,Hn?.advanced_auth_enabled?(0,G.jsx)(`span`,{className:`text-red-700 dark:text-red-400`,children:`*`}):(0,G.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,i(`users.form.optional`)||`optional`,`)`]})]}),(0,G.jsx)(`input`,{type:`email`,value:Mt.email,onChange:e=>Nt({...Mt,email:e.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:i(`users.form.emailPlaceholder`)||`user@example.com`,required:Hn?.advanced_auth_enabled})]}),!Hn?.advanced_auth_enabled&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:[i(`users.form.password`)||`Password`,` `,(0,G.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,i(`users.form.leaveBlankToKeep`)||`leave blank to keep current`,`)`]})]}),(0,G.jsx)(`input`,{type:`password`,value:Mt.password,onChange:e=>Nt({...Mt,password:e.target.value,confirmPassword:``}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:i(`settings.enterNewPassword`),autoComplete:`new-password`,minLength:8}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-xs mt-1`,children:i(`settings.passwordRequirements`)})]}),Mt.password&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:i(`settings.confirmPassword`)}),(0,G.jsx)(`input`,{type:`password`,value:Mt.confirmPassword,onChange:e=>Nt({...Mt,confirmPassword:e.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors ${Mt.confirmPassword&&Mt.password!==Mt.confirmPassword?`border-red-500`:`border-bambu-dark-tertiary`}`,placeholder:i(`settings.confirmNewPassword`),autoComplete:`new-password`,minLength:6}),Mt.confirmPassword&&Mt.password!==Mt.confirmPassword&&(0,G.jsx)(`p`,{className:`text-red-700 dark:text-red-400 text-xs mt-1`,children:i(`settings.passwordsDoNotMatch`)})]})]}),Hn?.advanced_auth_enabled&&(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary/50 border border-bambu-green/20 rounded-lg p-3 space-y-3`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`users.form.passwordManagedByAdvancedAuth`)||`Password is managed by Advanced Authentication. Use "Reset Password" to send a new password to the user via email.`}),(0,G.jsx)(Q,{variant:`secondary`,size:`sm`,onClick:()=>Ct&&$n.mutate(Ct),disabled:$n.isPending||!Mt.email,className:`w-full`,children:$n.isPending?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),i(`users.form.resettingPassword`)||`Resetting Password...`]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Wl,{className:`w-4 h-4`}),i(`users.form.resetPassword`)||`Reset Password`]})})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:i(`users.form.groups`)||`Groups`}),(0,G.jsx)(`div`,{className:`space-y-2 max-h-40 overflow-y-auto p-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg`,children:Jn.map(e=>(0,G.jsxs)(`label`,{className:`flex items-center gap-3 px-2 py-1.5 rounded hover:bg-bambu-dark-tertiary cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:Mt.group_ids.includes(e.id),onChange:()=>ar(e.id),className:`w-4 h-4 rounded border-bambu-gray text-bambu-green focus:ring-bambu-green focus:ring-offset-0 bg-bambu-dark`}),(0,G.jsx)(`span`,{className:`text-sm text-white`,children:e.name}),e.is_system&&(0,G.jsxs)(`span`,{className:`text-xs text-yellow-700 dark:text-yellow-400`,children:[`(`,i(`users.system`)||`System`,`)`]})]},e.id))})]})]}),(0,G.jsxs)(`div`,{className:`mt-6 flex justify-end gap-3`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>{St(!1),wt(null),Nt({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]})},children:i(`users.modal.cancel`)||`Cancel`}),(0,G.jsx)(Q,{onClick:()=>rr(Ct),disabled:Zn.isPending||!Mt.username||Hn?.advanced_auth_enabled&&!Mt.email||!!(!Hn?.advanced_auth_enabled&&Mt.password&&(Mt.password!==Mt.confirmPassword||_6(Mt.password)!==null)),children:Zn.isPending?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),i(`users.modal.saving`)||`Saving...`]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(ql,{className:`w-4 h-4`}),i(`users.modal.saveChanges`)||`Save Changes`]})})]})]})]})}),Tt!==null&&(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/80 flex items-center justify-center z-50 p-4`,onClick:()=>{Et(null),Ot(null)},children:(0,G.jsxs)(zd,{className:`w-full max-w-md`,onClick:e=>e.stopPropagation(),children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-red-700 dark:text-red-400`,children:[(0,G.jsx)(Pu,{className:`w-5 h-5`}),(0,G.jsx)(`h3`,{className:`text-lg font-semibold`,children:i(`settings.deleteUserTitle`)})]})}),(0,G.jsx)(Vd,{className:`space-y-3`,children:At?(0,G.jsx)(`div`,{className:`flex items-center justify-center py-4`,children:(0,G.jsx)(`div`,{className:`animate-spin rounded-full h-6 w-6 border-2 border-bambu-green border-t-transparent`})}):Dt&&Dt.archives+Dt.queue_items+Dt.library_files>0?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.userHasCreated`)}),(0,G.jsxs)(`ul`,{className:`list-disc list-inside text-bambu-gray space-y-1`,children:[Dt.archives>0&&(0,G.jsxs)(`li`,{children:[Dt.archives,` archive`,Dt.archives===1?``:`s`]}),Dt.queue_items>0&&(0,G.jsxs)(`li`,{children:[Dt.queue_items,` queue item`,Dt.queue_items===1?``:`s`]}),Dt.library_files>0&&(0,G.jsxs)(`li`,{children:[Dt.library_files,` library file`,Dt.library_files===1?``:`s`]})]}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-sm`,children:i(`settings.userItemsQuestion`)}),(0,G.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,G.jsx)(Q,{variant:`danger`,onClick:()=>Qn.mutate({id:Tt,deleteItems:!0}),disabled:Qn.isPending,className:`justify-center`,children:i(`settings.deleteUserAndItems`)}),(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>Qn.mutate({id:Tt,deleteItems:!1}),disabled:Qn.isPending,className:`justify-center`,children:i(`settings.deleteUserKeepItems`)}),(0,G.jsx)(Q,{variant:`ghost`,onClick:()=>{Et(null),Ot(null)},disabled:Qn.isPending,className:`justify-center`,children:i(`common.cancel`)})]})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.deleteUserConfirm`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-sm`,children:i(`settings.actionCannotBeUndone`)}),(0,G.jsxs)(`div`,{className:`flex gap-2 justify-end`,children:[(0,G.jsx)(Q,{variant:`ghost`,onClick:()=>{Et(null),Ot(null)},disabled:Qn.isPending,children:i(`common.cancel`)}),(0,G.jsx)(Q,{variant:`danger`,onClick:()=>Qn.mutate({id:Tt,deleteItems:!1}),disabled:Qn.isPending,children:i(`settings.deleteUserTitle`)})]})]})})]})}),Pt!==null&&(0,G.jsx)(of,{title:i(`settings.deleteGroupTitle`),message:i(`settings.deleteGroupMessage`),confirmText:i(`settings.deleteGroup`),variant:`danger`,onConfirm:()=>{tr.mutate(Pt),Ft(null)},onCancel:()=>Ft(null)}),je===`failure-detection`&&(0,G.jsx)(`div`,{id:`card-failure-detection`,children:(0,G.jsx)(OGe,{})}),je===`backup`&&(0,G.jsxs)(`div`,{id:`card-backup`,children:[(0,G.jsxs)(`div`,{className:`mb-4 p-3 bg-amber-50 dark:bg-amber-500/10 border border-amber-300 dark:border-amber-500/30 rounded-lg flex items-start gap-2`,children:[(0,G.jsx)(su,{className:`text-amber-600 dark:text-amber-400 flex-shrink-0 mt-0.5`,size:16}),(0,G.jsx)(`p`,{className:`text-sm text-amber-700 dark:text-amber-400`,children:i(`backup.includesEncryptionKey`)})]}),(0,G.jsx)(DGe,{})]}),st&&(0,G.jsx)(of,{title:i(`settings.disableAuthenticationTitle`),message:i(`settings.disableAuthenticationMessage`),confirmText:i(`settings.disableAuthentication`),variant:`danger`,onConfirm:async()=>{try{await Z.disableAuth(),o(i(`settings.toast.authDisabled`),`success`),await u(),ct(!1),window.location.href=`/`}catch(e){o(e instanceof Error?e.message:i(`settings.toast.authDisableFailed`),`error`)}},onCancel:()=>ct(!1)}),lt&&(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:()=>{ut(!1),ft({currentPassword:``,newPassword:``,confirmPassword:``})},children:(0,G.jsxs)(zd,{className:`w-full max-w-md`,onClick:e=>e.stopPropagation(),children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Kc,{className:`w-5 h-5 text-bambu-green`}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(`settings.changePassword`)})]}),(0,G.jsx)(Q,{variant:`ghost`,size:`sm`,onClick:()=>{ut(!1),ft({currentPassword:``,newPassword:``,confirmPassword:``})},children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]})}),(0,G.jsxs)(Vd,{children:[(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:`Current Password`}),(0,G.jsx)(`input`,{type:`password`,value:dt.currentPassword,onChange:e=>ft({...dt,currentPassword:e.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:i(`settings.enterCurrentPassword`),autoComplete:`current-password`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:`New Password`}),(0,G.jsx)(`input`,{type:`password`,value:dt.newPassword,onChange:e=>ft({...dt,newPassword:e.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:i(`settings.enterNewPasswordMin6`),autoComplete:`new-password`,minLength:6})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:`Confirm New Password`}),(0,G.jsx)(`input`,{type:`password`,value:dt.confirmPassword,onChange:e=>ft({...dt,confirmPassword:e.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors ${dt.confirmPassword&&dt.newPassword!==dt.confirmPassword?`border-red-500`:`border-bambu-dark-tertiary`}`,placeholder:i(`settings.confirmNewPassword`),autoComplete:`new-password`,minLength:6}),dt.confirmPassword&&dt.newPassword!==dt.confirmPassword&&(0,G.jsx)(`p`,{className:`text-red-700 dark:text-red-400 text-xs mt-1`,children:i(`settings.passwordsDoNotMatch`)})]})]}),(0,G.jsxs)(`div`,{className:`mt-6 flex justify-end gap-3`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>{ut(!1),ft({currentPassword:``,newPassword:``,confirmPassword:``})},children:i(`common.cancel`)}),(0,G.jsx)(Q,{onClick:async()=>{if(dt.newPassword!==dt.confirmPassword){o(i(`settings.toast.passwordsDoNotMatch`),`error`);return}if(dt.newPassword.length<6){o(i(`settings.toast.passwordTooShort`),`error`);return}mt(!0);try{await Z.changePassword(dt.currentPassword,dt.newPassword),o(i(`settings.toast.passwordChanged`),`success`),ut(!1),ft({currentPassword:``,newPassword:``,confirmPassword:``})}catch(e){o(e instanceof Error?e.message:`Failed to change password`,`error`)}finally{mt(!1)}},disabled:pt||!dt.currentPassword||!dt.newPassword||dt.newPassword!==dt.confirmPassword||dt.newPassword.length<6,children:pt?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),i(`settings.changing`)]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Kc,{className:`w-4 h-4`}),i(`settings.changePassword`)]})})]})]})]})})]})]})]})})}var ZGe=/\[(aborted|failed|cancelled):\s*([^\]]*)\]/i;function QGe(e){if(!e)return{isPartial:!1,partialType:null,cleanedDescription:null};let t=e.match(ZGe);if(!t)return{isPartial:!1,partialType:null,cleanedDescription:e};let n=e.replace(t[0],``).trim();return{isPartial:!0,partialType:t[1].toLowerCase(),cleanedDescription:n||null}}function $Ge(e,t){if(!e)return`-`;let n=rp(e);return n?n.toLocaleString(t):e}function X8(e){let t=e.trim();if(!t)return null;let n=Number.parseFloat(t);return Number.isFinite(n)?n:null}function Z8(e){return`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,`0`)}-${String(e.getDate()).padStart(2,`0`)}T${String(e.getHours()).padStart(2,`0`)}:${String(e.getMinutes()).padStart(2,`0`)}`}var Q8=`w-full px-3 py-2 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded text-white placeholder-bambu-gray focus:outline-none focus:ring-1 focus:ring-bambu-green`,$8=`block text-sm font-medium text-white mb-1`,e5=`px-4 py-3 text-left text-bambu-gray font-medium`,t5=`px-4 py-3 align-top text-white`;function n5({title:e,onClose:t,children:n,size:r=`md`}){let{t:i}=U();return(0,G.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/70 p-4`,children:(0,G.jsxs)(`div`,{className:`w-full ${r===`sm`?`max-w-xl`:r===`lg`?`max-w-6xl`:`max-w-4xl`} overflow-hidden rounded-lg border border-bambu-dark-tertiary bg-bambu-dark-secondary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between border-b border-bambu-dark-tertiary px-4 py-3`,children:[(0,G.jsx)(`h3`,{className:`text-lg font-semibold text-white`,children:e}),(0,G.jsx)(Q,{size:`sm`,variant:`secondary`,onClick:t,children:i(`common.close`,`Close`)})]}),(0,G.jsx)(`div`,{className:`max-h-[75vh] overflow-auto p-4`,children:n})]})})}function eKe(){let{t:e,i18n:t}=U(),{hasPermission:n,user:r}=Nd(),{showToast:i}=qd(),a=co(),o=n(`cost_centers:read_own`),s=n(`cost_centers:read_all`),c=n(`cost_centers:create`),l=n(`cost_centers:modify`),u=n(`cost_centers:modify`),d=n(`cost_centers:modify`),f=n(`cost_centers:modify`),p=n(`users:read_slim`)||n(`users:read`),m=s||c||l||u||d||f,h=o||m,g=h,[_,v]=(0,y.useState)(``),[b,x]=(0,y.useState)(`monthly`),[S,C]=(0,y.useState)(``),[w,T]=(0,y.useState)(null),[E,D]=(0,y.useState)(`deposit`),[O,k]=(0,y.useState)(``),[A,j]=(0,y.useState)(``),[M,N]=(0,y.useState)(null),[P,F]=(0,y.useState)(null),[I,L]=(0,y.useState)(null),[R,z]=(0,y.useState)(!0),[B,V]=(0,y.useState)(0),[ee,te]=(0,y.useState)(`all`),[ne,re]=(0,y.useState)(`all`),[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)(`personal`),[pe,me]=(0,y.useState)(null),[he,ge]=(0,y.useState)(``),[_e,ve]=(0,y.useState)(`monthly`),[ye,be]=(0,y.useState)(``),[xe,Se]=(0,y.useState)(!1),[Ce,we]=(0,y.useState)(null),[Te,Ee]=(0,y.useState)(null),[De,Oe]=(0,y.useState)(null),[ke,Ae]=(0,y.useState)(``),[je,Me]=(0,y.useState)(``),[Ne,Pe]=(0,y.useState)(!1),[Fe,Ie]=(0,y.useState)(null),[Le,Re]=(0,y.useState)(null),[ze,Be]=(0,y.useState)(``),[Ve,He]=(0,y.useState)(``),[Ue,We]=(0,y.useState)(Z8(new Date)),[Ge,Ke]=(0,y.useState)(null),[qe,Je]=(0,y.useState)(null),Ye=s||c||l||u||f&&p||d&&p;(0,y.useEffect)(()=>{Ye||fe(`personal`)},[Ye]);let{data:Xe,isLoading:Ze}=K({queryKey:[`finance`,`me`,`balance`],queryFn:Z.getMyBalance,enabled:o}),{data:Qe,isLoading:$e}=K({queryKey:[`finance`,`me`,`transactions`,50,B],queryFn:()=>Z.getMyTransactions(50,B),enabled:o}),{data:et,isLoading:tt}=K({queryKey:[`finance`,`transactions`,50,B],queryFn:()=>Z.getAllTransactions(50,B),enabled:de===`admin`&&s}),{data:nt,isLoading:rt}=K({queryKey:[`finance`,`cost-centers`,de],queryFn:()=>de===`admin`&&m?Z.listCostCenters(!0):Z.getMyCostCenters(),enabled:g}),{data:it}=K({queryKey:[`users`,`slim`],queryFn:Z.getUsersSlim,enabled:p&&(g||f||d)}),{data:at}=K({queryKey:[`finance`,`cost-center`,P],queryFn:()=>Z.getCostCenter(P),enabled:d&&P!=null});(0,y.useEffect)(()=>{!it||it.length===0||w!=null&&it.some(e=>e.id===w)||T(it[0].id)},[it,w]),(0,y.useEffect)(()=>{if(!d)return;let e=(nt||[]).filter(e=>!e.is_private);if(e.length===0){F(null);return}P!=null&&e.some(e=>e.id===P)||F(e[0].id)},[d,nt,P]),(0,y.useEffect)(()=>{if(!d||!it||it.length===0)return;let e=new Set((at?.members||[]).map(e=>e.user_id)),t=it.find(t=>!e.has(t.id));L(t?t.id:null)},[d,it,at]),(0,y.useEffect)(()=>{if(!le)return;let e=nt||[];if(e.length===0){me(null);return}pe!=null&&e.some(e=>e.id===pe)||me(e[0].id)},[le,pe,nt]),(0,y.useEffect)(()=>{if(!le||pe==null)return;let e=(nt||[]).find(e=>e.id===pe);if(e){if(ge(e.name),e.budget_mode===`total`){ve(`total`),be(e.total_budget==null?``:String(e.total_budget));return}ve(`monthly`),be(e.monthly_budget==null?``:String(e.monthly_budget))}},[le,pe,nt]);let ot=q({mutationFn:()=>Z.createCostCenter({name:_.trim(),total_budget:b===`total`?X8(S):null,monthly_budget:b===`monthly`?X8(S):null,is_active:!0}),onSuccess:()=>{a.invalidateQueries({queryKey:[`finance`]}),v(``),C(``),i(e(`finance.createdCostCenter`,`Cost center created`))},onError:t=>{i(t.message||e(`finance.createCostCenterFailed`,`Failed to create cost center`),`error`)}}),st=q({mutationFn:({costCenterId:e,value:t,mode:n})=>Z.updateCostCenterBudgets(e,{total_budget:n===`total`?X8(t):null,monthly_budget:n===`monthly`?X8(t):null})}),ct=q({mutationFn:({costCenterId:e,name:t})=>Z.updateCostCenter(e,{name:t})}),lt=q({mutationFn:e=>Z.deleteCostCenter(e)}),ut=q({mutationFn:e=>Z.deleteTransaction(e),onSuccess:()=>{a.invalidateQueries({queryKey:[`finance`]}),i(e(`finance.transactionDeleted`,`Transaction deleted`))},onError:t=>{i(t.message||e(`finance.deleteTransactionFailed`,`Failed to delete transaction`),`error`)}}),dt=q({mutationFn:e=>Z.editTransaction(e.transactionId,e.data),onSuccess:()=>{a.invalidateQueries({queryKey:[`finance`]}),i(e(`finance.transactionEdited`,`Transaction updated and ledger recalculated`)),Se(!1)},onError:t=>{i(t.message||e(`finance.editTransactionFailed`,`Failed to edit transaction`),`error`)}}),ft=q({mutationFn:e=>Z.createManualPrint(e),onSuccess:()=>{a.invalidateQueries({queryKey:[`finance`]}),i(e(`finance.manualPrintCreated`,`Manual print charge added and ledger recalculated`)),Pe(!1),Ie(null),Re(null),Be(``),He(``),We(Z8(new Date))},onError:t=>{i(t.message||e(`finance.manualPrintFailed`,`Failed to create manual print`),`error`)}}),pt=q({mutationFn:e=>Z.depositUserBalance(e.userId,{amount:e.amount,description:e.description,cost_center_id:e.costCenterId??null})}),mt=q({mutationFn:e=>Z.withdrawUserBalance(e.userId,{amount:e.amount,description:e.description,cost_center_id:e.costCenterId??null})}),ht=q({mutationFn:e=>Z.upsertCostCenterMember(e.costCenterId,{user_id:e.userId,can_print:e.canPrint}),onSuccess:()=>{a.invalidateQueries({queryKey:[`finance`]}),i(e(`finance.memberSaved`,`Member saved`))},onError:t=>{i(t.message||e(`finance.memberSaveFailed`,`Failed to save member`),`error`)}}),gt=q({mutationFn:e=>Z.removeCostCenterMember(e.costCenterId,e.userId),onSuccess:()=>{a.invalidateQueries({queryKey:[`finance`]}),i(e(`finance.memberRemoved`,`Member removed`))},onError:t=>{i(t.message||e(`finance.memberRemoveFailed`,`Failed to remove member`),`error`)}}),_t=pt.isPending||mt.isPending,vt=()=>{if(!_.trim()){i(e(`finance.costCenterNameRequired`,`Cost center name is required`),`error`);return}ot.mutate()},yt=async()=>{if(pe==null){i(e(`finance.selectCostCenter`,`Please select a cost center`),`error`);return}let t=he.trim();if(!t){i(e(`finance.costCenterNameRequired`,`Cost center name is required`),`error`);return}try{l&&await ct.mutateAsync({costCenterId:pe,name:t}),u&&await st.mutateAsync({costCenterId:pe,mode:_e,value:ye}),a.invalidateQueries({queryKey:[`finance`]}),i(e(`finance.costCenterUpdated`,`Cost center updated`)),ue(!1)}catch(t){i(t.message||e(`finance.costCenterUpdateFailed`,`Failed to update cost center`),`error`)}},bt=e=>{let t=(nt||[]).find(t=>t.id===e);t&&(me(t.id),ge(t.name),t.budget_mode===`total`?(ve(`total`),be(t.total_budget==null?``:String(t.total_budget))):(ve(`monthly`),be(t.monthly_budget==null?``:String(t.monthly_budget))),ue(!0))},xt=async()=>{if(Ge)try{await lt.mutateAsync(Ge.id),a.invalidateQueries({queryKey:[`finance`]}),P===Ge.id&&F(null),i(e(`finance.costCenterDeleted`,`Cost center deleted`))}catch(t){i(t.message||e(`finance.costCenterDeleteFailed`,`Failed to delete cost center`),`error`)}finally{Ke(null)}},St=()=>{qe!=null&&ut.mutate(qe,{onSettled:()=>Je(null)})},Ct=e=>{we(e.id),Ee(e.user_id),Oe(e.cost_center_id),Ae(String(e.amount)),Me(e.description||``),Se(!0)},wt=async()=>{if(Ce==null)return;let t=ke?Number.parseFloat(ke):null;if(t!==null&&!Number.isFinite(t)){i(e(`finance.amountInvalid`,`Amount must be a valid number`),`error`);return}dt.mutate({transactionId:Ce,data:{user_id:Te||void 0,cost_center_id:De||void 0,amount:t??void 0,description:je||void 0}})},Tt=async()=>{if(Fe==null){i(e(`finance.userRequired`,`Please select a user`),`error`);return}if(Le==null){i(e(`finance.costCenterRequired`,`Please select a cost center`),`error`);return}let t=ze?Number.parseFloat(ze):null;if(t===null||!Number.isFinite(t)){i(e(`finance.amountInvalid`,`Amount must be a valid number`),`error`);return}t=Math.abs(t),ft.mutate({user_id:Fe,cost_center_id:Le,amount:t,description:Ve||void 0,created_at:Ue?new Date(Ue).toISOString():void 0})},Et=async()=>{if(w==null){i(e(`finance.userRequired`,`Please select a user`),`error`);return}let t=Number.parseFloat(O);if(!Number.isFinite(t)||t<=0){i(e(`finance.amountMustBePositive`,`Amount must be greater than zero`),`error`);return}let n={userId:w,amount:t,description:A.trim()||void 0,costCenterId:M};try{E===`deposit`?await pt.mutateAsync(n):await mt.mutateAsync(n),a.invalidateQueries({queryKey:[`finance`]}),k(``),j(``),i(E===`deposit`?e(`finance.depositSuccess`,`Deposit successful`):e(`finance.withdrawSuccess`,`Withdrawal successful`))}catch(t){i(t.message||e(`finance.adjustmentFailed`,`Wallet adjustment failed`),`error`)}},Dt=()=>{if(P==null){i(e(`finance.selectCostCenter`,`Please select a cost center`),`error`);return}if(I==null){i(e(`finance.noEligibleUsers`,`No eligible users available`),`error`);return}ht.mutate({costCenterId:P,userId:I,canPrint:R})},Ot=e=>{P!=null&>.mutate({costCenterId:P,userId:e})},kt=Lf(Xe?.currency||`EUR`),At=(0,y.useMemo)(()=>[...it||[]].sort((e,t)=>e.username.localeCompare(t.username)),[it]),jt=(0,y.useMemo)(()=>{let e=new Map;for(let t of At)e.set(t.id,t.username);return e},[At]),Mt=(0,y.useMemo)(()=>{let e=new Set((at?.members||[]).map(e=>e.user_id));return At.filter(t=>!e.has(t.id))},[At,at]),Nt=de===`admin`&&s?et:Qe,Pt=de===`admin`&&s?tt:$e,Ft=(0,y.useMemo)(()=>Nt?.items??[],[Nt?.items]),It=Nt?.total??0,Lt=Math.max(1,Math.ceil(It/50)),Rt=(0,y.useMemo)(()=>Ft.filter(e=>!(ee!==`all`&&e.transaction_type!==ee||ne!==`all`&&e.cost_center_id!==ne)),[Ft,ee,ne]),zt=Math.floor(B/50)+1,Bt=de===`admin`,Vt=t=>t===`deposit`?e(`finance.deposit`):t===`withdraw`?e(`finance.withdraw`):t===`print_charge`?e(`finance.printCharge`):t,Ht=t=>t==null?e(`finance.personal`,`Personal`):jt.get(t)||(r?.id===t&&r.username?r.username:e(`finance.userWithId`,`User #{{id}}`,{id:t})),Ut=t=>t.budget_limit==null||t.budget_available==null?e(`finance.unlimited`,`Unlimited`):`${kt}${t.budget_available.toFixed(2)}/${kt}${t.budget_limit.toFixed(2)}`;return h?(0,G.jsxs)(`div`,{className:`p-4 md:p-8 space-y-8`,children:[(0,G.jsxs)(`div`,{className:`flex flex-col gap-4 lg:flex-row lg:items-start lg:justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Ju,{className:`h-6 w-6 text-bambu-green`}),(0,G.jsx)(`h1`,{className:`text-2xl font-bold text-white`,children:e(`finance.title`,`Finance`)})]}),(0,G.jsx)(`p`,{className:`text-bambu-gray mt-2 max-w-2xl`,children:e(`finance.subtitle`,`Wallet, personal transactions, and cost centers`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1 max-w-2xl`,children:e(`finance.budgetPolicyHint`,`Account balances track costs. Printing is limited only by the selected cost center budget; without a budget, printing is unlimited.`)})]}),(0,G.jsxs)(`div`,{className:`flex flex-col gap-2 lg:items-end`,children:[Ye&&(0,G.jsxs)(`div`,{className:`inline-flex overflow-hidden rounded border border-bambu-dark-tertiary`,children:[(0,G.jsx)(`button`,{type:`button`,onClick:()=>fe(`personal`),className:`px-3 py-1.5 text-sm ${de===`personal`?`bg-bambu-green text-black font-medium`:`bg-bambu-dark text-bambu-gray`}`,children:e(`finance.personalView`,`Personal view`)}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>fe(`admin`),className:`px-3 py-1.5 text-sm ${de===`admin`?`bg-bambu-green text-black font-medium`:`bg-bambu-dark text-bambu-gray`}`,children:e(`finance.adminView`,`Admin view`)})]}),de===`admin`&&Ye&&(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-2 lg:justify-end`,children:[c&&(0,G.jsx)(Q,{size:`sm`,variant:`secondary`,onClick:()=>ae(!0),children:e(`finance.createCostCenter`,`Create cost center`)}),f&&p&&(0,G.jsx)(Q,{size:`sm`,variant:`secondary`,onClick:()=>se(!0),children:e(`finance.adjustWallet`,`Adjust wallet`)}),f&&p&&(0,G.jsx)(Q,{size:`sm`,variant:`secondary`,onClick:()=>Pe(!0),children:e(`finance.addManualPrint`,`Add manual print`)}),d&&p&&(0,G.jsx)(Q,{size:`sm`,variant:`secondary`,onClick:()=>ce(!0),children:e(`finance.manageMembers`,`Manage cost center members`)})]})]})]}),(0,G.jsxs)(`div`,{className:`grid gap-5 md:grid-cols-2 xl:grid-cols-3`,children:[(0,G.jsxs)(zd,{children:[(0,G.jsxs)(Bd,{className:`flex flex-row items-center justify-between pb-2`,children:[(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e(`finance.currentBalance`,`Personal account balance`)}),(0,G.jsx)(Ju,{className:`w-4 h-4 text-bambu-green/90`})]}),(0,G.jsx)(Vd,{className:`pt-1`,children:(0,G.jsx)(`p`,{className:`text-3xl font-semibold text-white leading-tight`,children:Ze?e(`common.loading`,`Loading...`):`${kt}${(Xe?.balance??0).toFixed(2)}`})})]}),(0,G.jsxs)(zd,{children:[(0,G.jsxs)(Bd,{className:`flex flex-row items-center justify-between pb-2`,children:[(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:de===`admin`?e(`finance.transactions`,`Transactions`):e(`finance.personalTransactions`,`Personal transactions`)}),(0,G.jsx)(As,{className:`w-4 h-4 text-blue-400`})]}),(0,G.jsx)(Vd,{className:`pt-1`,children:(0,G.jsx)(`p`,{className:`text-3xl font-semibold text-white leading-tight`,children:Pt?`-`:It})})]}),(0,G.jsxs)(zd,{children:[(0,G.jsxs)(Bd,{className:`flex flex-row items-center justify-between pb-2`,children:[(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e(`finance.costCenters`,`Cost centers`)}),(0,G.jsx)(es,{className:`w-4 h-4 text-orange-400`})]}),(0,G.jsx)(Vd,{className:`pt-1`,children:(0,G.jsx)(`p`,{className:`text-3xl font-semibold text-white leading-tight`,children:rt?`-`:nt?.length??0})})]})]}),ie&&c&&(0,G.jsx)(n5,{title:e(`finance.createCostCenter`,`Create cost center`),size:`md`,onClose:()=>ae(!1),children:(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:$8,children:e(`finance.costCenterName`,`Name`)}),(0,G.jsx)(`input`,{type:`text`,value:_,onChange:e=>v(e.target.value),placeholder:e(`finance.costCenterName`,`Name`),className:Q8})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:$8,children:e(`finance.budgetType`,`Budget type`)}),(0,G.jsxs)(`select`,{value:b,onChange:e=>x(e.target.value),className:Q8,children:[(0,G.jsx)(`option`,{value:`monthly`,children:e(`finance.monthlyBudget`,`Monthly budget`)}),(0,G.jsx)(`option`,{value:`total`,children:e(`finance.totalBudget`,`Total budget`)})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:$8,children:b===`monthly`?e(`finance.monthlyBudget`,`Monthly budget`):e(`finance.totalBudget`,`Total budget`)}),(0,G.jsx)(`input`,{type:`number`,step:`0.01`,value:S,onChange:e=>C(e.target.value),placeholder:`0.00`,className:Q8})]})]}),(0,G.jsx)(Q,{className:`min-w-[180px]`,onClick:vt,disabled:ot.isPending,children:ot.isPending?e(`common.saving`,`Saving...`):e(`finance.create`,`Create`)})]})}),oe&&f&&p&&(0,G.jsx)(n5,{title:e(`finance.adjustWallet`,`Adjust wallet`),size:`md`,onClose:()=>se(!1),children:(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:$8,children:e(`finance.selectUser`,`Select user`)}),(0,G.jsx)(`select`,{value:w??``,onChange:e=>T(e.target.value?Number(e.target.value):null),className:Q8,children:(At||[]).map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.username},e.id))})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:$8,children:e(`finance.transactionType`,`Type`)}),(0,G.jsxs)(`select`,{value:E,onChange:e=>D(e.target.value),className:Q8,children:[(0,G.jsx)(`option`,{value:`deposit`,children:e(`finance.deposit`,`Deposit`)}),(0,G.jsx)(`option`,{value:`withdraw`,children:e(`finance.withdraw`,`Withdraw`)})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:$8,children:e(`finance.amount`,`Amount`)}),(0,G.jsx)(`input`,{type:`number`,step:`0.01`,min:`0`,value:O,onChange:e=>k(e.target.value),placeholder:`0.00`,className:Q8})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:$8,children:e(`finance.costCenters`,`Cost centers`)}),(0,G.jsxs)(`select`,{value:M??``,onChange:e=>N(e.target.value?Number(e.target.value):null),className:Q8,children:[(0,G.jsx)(`option`,{value:``,children:e(`finance.noCostCenter`,`No cost center`)}),(nt||[]).map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:$8,children:e(`common.description`,`Description`)}),(0,G.jsx)(`input`,{type:`text`,value:A,onChange:e=>j(e.target.value),placeholder:e(`finance.descriptionOptional`,`Description (optional)`),className:Q8})]}),(0,G.jsx)(Q,{className:`min-w-[180px]`,onClick:Et,disabled:_t,children:_t?e(`common.saving`,`Saving...`):e(`finance.applyAdjustment`,`Apply adjustment`)})]})}),H&&d&&p&&(0,G.jsx)(n5,{title:e(`finance.manageMembers`,`Manage cost center members`),size:`lg`,onClose:()=>ce(!1),children:(0,G.jsxs)(`div`,{className:`space-y-5`,children:[(0,G.jsxs)(`div`,{className:`grid gap-5 md:grid-cols-2`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:$8,children:e(`finance.costCenters`,`Cost centers`)}),(0,G.jsx)(`select`,{value:P??``,onChange:e=>F(e.target.value?Number(e.target.value):null),className:Q8,children:(nt||[]).filter(e=>!e.is_private).map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.name},e.id))})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:$8,children:e(`finance.selectUser`,`Select user`)}),(0,G.jsxs)(`select`,{value:I??``,onChange:e=>L(e.target.value?Number(e.target.value):null),className:Q8,children:[(0,G.jsx)(`option`,{value:``,children:e(`finance.selectUser`,`Select user`)}),Mt.map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.username},e.id))]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 rounded border border-bambu-dark-tertiary bg-bambu-dark-secondary px-3 py-2`,children:[(0,G.jsx)(`input`,{id:`memberCanPrint`,type:`checkbox`,checked:R,onChange:e=>z(e.target.checked),className:`rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,G.jsx)(`label`,{htmlFor:`memberCanPrint`,className:`text-sm text-bambu-gray`,children:e(`finance.memberCanPrint`,`Member can print`)})]}),(0,G.jsx)(`div`,{className:`flex items-end`,children:(0,G.jsx)(Q,{className:`min-w-[180px]`,onClick:Dt,disabled:ht.isPending||I==null,children:ht.isPending?e(`common.saving`,`Saving...`):e(`finance.addMember`,`Add member`)})})]}),(0,G.jsx)(`div`,{className:`overflow-auto rounded-lg border border-bambu-dark-tertiary`,children:(0,G.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,G.jsx)(`thead`,{children:(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary bg-bambu-dark text-bambu-gray`,children:[(0,G.jsx)(`th`,{className:e5,children:e(`common.name`,`Name`)}),(0,G.jsx)(`th`,{className:e5,children:e(`finance.canPrint`,`Can print`)}),(0,G.jsx)(`th`,{className:e5,children:e(`common.actions`,`Actions`)})]})}),(0,G.jsxs)(`tbody`,{children:[(at?.members||[]).map(t=>(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/60 text-white`,children:[(0,G.jsx)(`td`,{className:t5,children:At.find(e=>e.id===t.user_id)?.username||`User ${t.user_id}`}),(0,G.jsx)(`td`,{className:t5,children:t.can_print?e(`common.yes`,`Yes`):e(`common.no`,`No`)}),(0,G.jsx)(`td`,{className:t5,children:(0,G.jsx)(Q,{size:`sm`,variant:`danger`,onClick:()=>Ot(t.user_id),disabled:gt.isPending,children:e(`common.remove`,`Remove`)})})]},t.id)),(at?.members||[]).length===0&&(0,G.jsx)(`tr`,{children:(0,G.jsx)(`td`,{colSpan:3,className:`py-3 text-bambu-gray`,children:e(`finance.noMembers`,`No members assigned.`)})})]})]})})]})}),le&&(l||u)&&(0,G.jsx)(n5,{title:e(`finance.editCostCenter`,`Edit cost center`),size:`md`,onClose:()=>ue(!1),children:(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:$8,children:e(`finance.costCenterName`,`Name`)}),(0,G.jsx)(`input`,{type:`text`,value:he,onChange:e=>ge(e.target.value),placeholder:e(`finance.costCenterName`,`Name`),className:Q8,disabled:!l})]}),(0,G.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:$8,children:e(`finance.budgetType`,`Budget type`)}),(0,G.jsxs)(`select`,{value:_e,onChange:e=>ve(e.target.value),className:Q8,disabled:!u,children:[(0,G.jsx)(`option`,{value:`monthly`,children:e(`finance.monthlyBudget`,`Monthly budget`)}),(0,G.jsx)(`option`,{value:`total`,children:e(`finance.totalBudget`,`Total budget`)})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:$8,children:_e===`monthly`?e(`finance.monthlyBudget`,`Monthly budget`):e(`finance.totalBudget`,`Total budget`)}),(0,G.jsx)(`input`,{type:`number`,step:`0.01`,value:ye,onChange:e=>be(e.target.value),placeholder:`0.00`,className:Q8,disabled:!u})]})]}),(0,G.jsx)(Q,{className:`min-w-[180px]`,onClick:yt,disabled:ct.isPending||st.isPending||pe==null,children:ct.isPending||st.isPending?e(`common.saving`,`Saving...`):e(`common.save`,`Save`)})]})}),(0,G.jsxs)(`div`,{className:`grid gap-6 ${g&&o?`xl:grid-cols-2`:``}`,children:[g&&(0,G.jsxs)(zd,{children:[(0,G.jsxs)(Bd,{children:[(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`finance.myCostCenters`,`My cost centers`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:e(`finance.costCentersHint`,`Review budget limits and keep costs under control`)})]}),(0,G.jsxs)(Vd,{className:`space-y-3`,children:[rt&&(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`common.loading`,`Loading...`)}),!rt&&(!nt||nt.length===0)&&(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`finance.noCostCenters`,`No cost centers found.`)}),!rt&&nt&&nt.length>0&&(0,G.jsx)(`div`,{className:`overflow-auto rounded-lg border border-bambu-dark-tertiary`,children:(0,G.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,G.jsx)(`thead`,{children:(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary bg-bambu-dark text-bambu-gray`,children:[(0,G.jsx)(`th`,{className:e5,children:e(`common.name`,`Name`)}),Bt&&(0,G.jsx)(`th`,{className:e5,children:e(`finance.owner`,`Owner`)}),(0,G.jsx)(`th`,{className:e5,children:e(`finance.balance`,`Account balance`)}),(0,G.jsx)(`th`,{className:e5,children:e(`finance.budget`,`Budget`)}),Bt&&(0,G.jsx)(`th`,{className:e5,children:e(`common.actions`,`Actions`)})]})}),(0,G.jsx)(`tbody`,{children:nt.map(t=>{let n=l||u,r=!t.is_private&&l;return(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/60 text-white`,children:[(0,G.jsx)(`td`,{className:t5,children:t.name}),Bt&&(0,G.jsx)(`td`,{className:t5,children:t.is_private?Ht(t.owner_user_id):e(`finance.shared`,`Shared`)}),(0,G.jsxs)(`td`,{className:t5,children:[kt,t.total_balance.toFixed(2)]}),(0,G.jsx)(`td`,{className:t5,children:(0,G.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[(0,G.jsx)(`span`,{children:Ut(t)}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:t.budget_mode===`monthly`?e(`finance.monthlyBudget`,`Monthly budget`):t.budget_mode===`total`?e(`finance.totalBudget`,`Total budget`):e(`finance.noBudget`,`No budget`)})]})}),Bt&&(0,G.jsx)(`td`,{className:t5,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Q,{size:`sm`,variant:`ghost`,onClick:()=>bt(t.id),disabled:!n,title:n?e(`common.edit`,`Edit`):e(`finance.cannotEditPrivateCostCenter`,`Private cost centers cannot be edited here`),className:`p-1.5 sm:p-2`,children:(0,G.jsx)(Al,{className:`w-4 h-4`})}),r&&(0,G.jsx)(Q,{size:`sm`,variant:`ghost`,onClick:()=>Ke({id:t.id,name:t.name}),disabled:lt.isPending,title:e(`common.delete`,`Delete`),className:`text-red-400 hover:text-red-300 hover:bg-red-500/10 p-1.5 sm:p-2`,children:(0,G.jsx)(Pu,{className:`w-4 h-4`})})]})})]},t.id)})})]})})]})]}),o&&(0,G.jsxs)(zd,{children:[(0,G.jsxs)(Bd,{children:[(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`finance.recentTransactions`,`Recent transactions`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:e(`finance.transactionsHint`,`Filter by type and cost center, then navigate pages`)})]}),(0,G.jsxs)(Vd,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{className:`grid gap-4 lg:grid-cols-[minmax(0,1fr)_minmax(0,1fr)_auto] xl:grid-cols-[minmax(0,1fr)_minmax(0,1fr)_minmax(0,1fr)_auto] items-end`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:$8,children:e(`finance.transactionType`,`Type`)}),(0,G.jsxs)(`select`,{value:ee,onChange:e=>te(e.target.value),className:Q8,children:[(0,G.jsx)(`option`,{value:`all`,children:e(`finance.allTypes`)}),(0,G.jsx)(`option`,{value:`deposit`,children:e(`finance.deposit`)}),(0,G.jsx)(`option`,{value:`withdraw`,children:e(`finance.withdraw`)}),(0,G.jsx)(`option`,{value:`print_charge`,children:e(`finance.printCharge`)})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:$8,children:e(`finance.costCenters`,`Cost centers`)}),(0,G.jsxs)(`select`,{value:ne,onChange:e=>re(e.target.value===`all`?`all`:Number(e.target.value)),className:Q8,children:[(0,G.jsx)(`option`,{value:`all`,children:e(`finance.allCostCenters`)}),(nt||[]).map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]})]}),Pt&&(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`common.loading`,`Loading...`)}),!Pt&&(!Ft||Ft.length===0)&&(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`finance.noTransactions`,`No transactions available.`)}),!Pt&&Ft.length>0&&Rt.length===0&&(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`finance.noTransactionsForFilter`,`No transactions match the selected filters.`)}),!Pt&&Rt.length>0&&(0,G.jsx)(`div`,{className:`overflow-auto rounded-lg border border-bambu-dark-tertiary`,children:(0,G.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,G.jsx)(`thead`,{children:(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary bg-bambu-dark text-bambu-gray`,children:[(0,G.jsx)(`th`,{className:e5,children:e(`common.date`,`Date`)}),Bt&&(0,G.jsx)(`th`,{className:e5,children:e(`common.user`,`User`)}),(0,G.jsx)(`th`,{className:e5,children:e(`finance.costCenter`,`Cost center`)}),(0,G.jsx)(`th`,{className:e5,children:e(`finance.transactionType`,`Type`)}),(0,G.jsx)(`th`,{className:e5,children:e(`common.description`,`Description`)}),(0,G.jsx)(`th`,{className:e5,children:e(`finance.amount`,`Amount`)}),(0,G.jsx)(`th`,{className:e5,children:e(`finance.balanceAfter`,`Balance after`)}),Bt&&(0,G.jsx)(`th`,{className:e5,children:e(`common.actions`,`Actions`)})]})}),(0,G.jsx)(`tbody`,{children:Rt.map(n=>{let r=n.amount>=0,i=n.cost_center_id==null?null:(nt||[]).find(e=>e.id===n.cost_center_id),a=jt.get(n.user_id),o=n.transaction_type===`print_charge`?QGe(n.description??null):null,s=o?.isPartial??!1;return(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/60 text-white`,children:[(0,G.jsx)(`td`,{className:t5,children:$Ge(n.created_at,t.language)}),Bt&&(0,G.jsx)(`td`,{className:t5,children:a||e(`finance.userWithId`,`User #{{id}}`,{id:n.user_id})}),(0,G.jsx)(`td`,{className:t5,children:i?.name||`-`}),(0,G.jsx)(`td`,{className:t5,children:(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,G.jsx)(`span`,{children:Vt(n.transaction_type)}),s&&(0,G.jsx)(`span`,{className:`rounded border border-yellow-500/40 bg-yellow-500/10 px-2 py-0.5 text-[11px] text-yellow-300`,children:o&&o.partialType?e(`finance.partialStatus.${o.partialType}`,o.partialType):e(`finance.partial`,`Partial`)})]})}),(0,G.jsx)(`td`,{className:t5,children:(o?.cleanedDescription??n.description)||`-`}),(0,G.jsxs)(`td`,{className:`${t5} ${r?`text-green-400`:`text-red-400`}`,children:[r?`+`:`-`,kt,Math.abs(n.amount).toFixed(2)]}),(0,G.jsx)(`td`,{className:t5,children:n.balance_after==null?`-`:`${n.balance_after<0?`-`:``}${kt}${Math.abs(n.balance_after).toFixed(2)}`}),Bt&&(0,G.jsx)(`td`,{className:t5,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Q,{size:`sm`,variant:`secondary`,onClick:()=>Ct(n),disabled:dt.isPending,children:(0,G.jsx)(Al,{className:`w-4 h-4`})}),(0,G.jsx)(Q,{size:`sm`,variant:`danger`,onClick:()=>Je(n.id),disabled:ut.isPending,children:(0,G.jsx)(Pu,{className:`w-4 h-4`})})]})})]},n.id)})})]})}),!Pt&&Rt.length>0&&(0,G.jsx)(`div`,{className:`flex justify-end pt-2 lg:pt-0`,children:(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[(0,G.jsx)(`button`,{type:`button`,onClick:()=>V(0),disabled:B===0||Pt,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,"aria-label":e(`finance.first`,`First`),children:(0,G.jsx)(_s,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>V(e=>Math.max(0,e-50)),disabled:B===0||Pt,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,"aria-label":e(`finance.prev`,`Previous`),children:(0,G.jsx)(hs,{className:`w-4 h-4`})}),(0,G.jsx)(`span`,{className:`text-bambu-gray px-1 whitespace-nowrap`,children:e(`finance.pageNumberOf`,`Page {{page}} of {{total}}`,{page:zt,total:Lt})}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>V(e=>e+50),disabled:Pt||zt>=Lt,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,"aria-label":e(`finance.next`,`Next`),children:(0,G.jsx)(ms,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>V(Math.max(0,(Lt-1)*50)),disabled:Pt||zt>=Lt,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,"aria-label":e(`finance.last`,`Last`),children:(0,G.jsx)(vs,{className:`w-4 h-4`})})]})})]})]}),xe&&Ce!==null&&(0,G.jsx)(n5,{title:e(`finance.editTransaction`,`Edit Transaction`),onClose:()=>Se(!1),size:`md`,children:(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:$8,children:e(`common.user`,`User`)}),(0,G.jsxs)(`select`,{className:Q8,value:Te||``,onChange:e=>Ee(e.target.value?Number(e.target.value):null),children:[(0,G.jsx)(`option`,{value:``,children:e(`finance.selectUser`,`Select user...`)}),At.map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.username},e.id))]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:$8,children:e(`finance.costCenter`,`Cost center (optional)`)}),(0,G.jsxs)(`select`,{className:Q8,value:De||``,onChange:e=>Oe(e.target.value?Number(e.target.value):null),children:[(0,G.jsx)(`option`,{value:``,children:e(`finance.noCostCenter`,`Personal (no cost center)`)}),(nt||[]).map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:$8,children:e(`finance.amount`,`Amount`)}),(0,G.jsx)(`input`,{type:`number`,step:`0.01`,className:Q8,value:ke,onChange:e=>Ae(e.target.value),placeholder:e(`finance.amountExample`,`e.g., 10.50`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:$8,children:e(`common.description`,`Description`)}),(0,G.jsx)(`textarea`,{className:`${Q8} resize-none`,rows:3,value:je,onChange:e=>Me(e.target.value),placeholder:e(`finance.manualAdjustmentExample`,`e.g., Manual adjustment`)})]}),(0,G.jsxs)(`div`,{className:`flex justify-end gap-2 pt-4`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>Se(!1),children:e(`common.cancel`,`Cancel`)}),(0,G.jsx)(Q,{onClick:wt,disabled:dt.isPending,children:e(`common.save`,`Save`)})]})]})}),Ne&&(0,G.jsx)(n5,{title:e(`finance.addManualPrint`,`Add manual print`),onClose:()=>Pe(!1),size:`md`,children:(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:$8,children:e(`common.user`,`User`)}),(0,G.jsxs)(`select`,{className:Q8,value:Fe||``,onChange:e=>Ie(e.target.value?Number(e.target.value):null),children:[(0,G.jsx)(`option`,{value:``,children:e(`finance.selectUser`,`Select user...`)}),At.map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.username},e.id))]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:$8,children:e(`finance.costCenter`,`Cost center`)}),(0,G.jsxs)(`select`,{className:Q8,value:Le||``,onChange:e=>Re(e.target.value?Number(e.target.value):null),children:[(0,G.jsx)(`option`,{value:``,children:e(`finance.selectCostCenter`,`Select cost center...`)}),(nt||[]).map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:$8,children:e(`finance.amount`,`Amount`)}),(0,G.jsx)(`input`,{type:`number`,step:`0.01`,className:Q8,value:ze,onChange:e=>Be(e.target.value),placeholder:e(`finance.amountExample`,`e.g., 4.00`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:$8,children:e(`common.description`,`Description`)}),(0,G.jsx)(`input`,{type:`text`,value:Ve,onChange:e=>He(e.target.value),placeholder:e(`finance.descriptionOptional`,`Description (optional)`),className:Q8})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:$8,children:e(`common.date`,`Date`)}),(0,G.jsx)(`input`,{type:`datetime-local`,value:Ue,onChange:e=>We(e.target.value),className:Q8})]}),(0,G.jsxs)(`div`,{className:`flex justify-end gap-2 pt-4`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>Pe(!1),children:e(`common.cancel`,`Cancel`)}),(0,G.jsx)(Q,{onClick:Tt,disabled:ft.isPending,children:ft.isPending?e(`common.saving`,`Saving...`):e(`finance.addManualPrint`,`Add manual print`)})]})]})}),Ge&&(0,G.jsx)(of,{title:e(`common.delete`,`Delete`),message:e(`finance.confirmDeleteCostCenter`,`Delete cost center "{{name}}"?`,{name:Ge.name}),confirmText:e(`common.delete`,`Delete`),variant:`danger`,isLoading:lt.isPending,onConfirm:xt,onCancel:()=>Ke(null)}),qe!=null&&(0,G.jsx)(of,{title:e(`finance.deleteTransaction`,`Delete transaction`),message:e(`finance.deleteTransactionConfirm`,`Delete this transaction? Balances will be recalculated automatically.`),confirmText:e(`common.delete`,`Delete`),variant:`danger`,isLoading:ut.isPending,onConfirm:St,onCancel:()=>Je(null)})]})]}):(0,G.jsxs)(`div`,{className:`p-4 md:p-8 space-y-6`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Ju,{className:`h-6 w-6 text-bambu-green`}),(0,G.jsx)(`h1`,{className:`text-2xl font-bold text-white`,children:e(`finance.title`,`Finance`)})]}),(0,G.jsx)(`div`,{children:(0,G.jsx)(`p`,{className:`text-bambu-gray mt-2 max-w-2xl`,children:e(`finance.subtitle`,`Wallet, personal transactions, and cost centers`)})}),(0,G.jsx)(zd,{children:(0,G.jsx)(Vd,{className:`py-8 text-center text-bambu-gray`,children:e(`finance.noAccess`,`You do not have permission to view finance data.`)})})]})}var r5={PLA:`GFL99`,"PLA-CF":`GFL98`,"PLA SILK":`GFL96`,"PLA HIGH SPEED":`GFL95`,PETG:`GFG99`,"PETG HF":`GFG96`,"PETG-CF":`GFG98`,PCTG:`GFG97`,ABS:`GFB99`,ASA:`GFB98`,PC:`GFC99`,PA:`GFN99`,"PA-CF":`GFN98`,NYLON:`GFN99`,TPU:`GFU99`,PVA:`GFS99`,HIPS:`GFS98`,PE:`GFP99`,PP:`GFP97`};function i5(e){let t=(e||``).toUpperCase().trim();return t&&(r5[t]||r5[t.replace(/[-\s]?CF$/,``)]||r5[t.replace(/\+$/,``)]||r5[t.split(/[-\s]/)[0]])||``}function a5(e){let t=e.replace(/@.+$/,``).trim();return t.startsWith(`# `)?t.slice(2).trim():t}var o5={local:0,orca_cloud:1,cloud:2,builtin:3};function tKe(e){let{localPresets:t,orcaProfiles:n,cloudSettings:r,builtinFilaments:i}=e,a=[],o=e=>e.trim().toLowerCase(),s=new Set,c=new Set,l=new Set,u=(e,t,...n)=>{let r=n.filter(e=>!!e);if(r.some(e=>s.has(e)))return!1;let i=`${e}|${o(t)}`;return c.has(i)?!1:(r.forEach(e=>s.add(e)),c.add(i),l.add(o(t)),!0)};for(let e of t??[]){let t=a5(e.name),n=e.filament_type||WH(t).material;u(`local`,t)&&a.push({id:`local_${e.id}`,name:t,source:`local`,filamentId:i5(n),filamentType:n||``})}for(let e of n??[]){let t=a5(e.name),n=WH(t).material;u(`orca_cloud`,t,e.setting_id)&&a.push({id:`orca_${e.setting_id}`,name:t,source:`orca_cloud`,filamentId:i5(n),filamentType:n})}for(let e of r??[]){let t=a5(e.name),n=e.setting_id.startsWith(`GFS`)?QH(e.setting_id):``;u(`cloud`,t,e.setting_id,n||void 0)&&a.push({id:e.setting_id,name:t,source:`cloud`,filamentId:n,filamentType:WH(t).material})}for(let e of i??[]){let t=e.filament_id.startsWith(`GF`)?`GFS${e.filament_id.slice(2)}`:e.filament_id;l.has(o(e.name))||u(`builtin`,e.name,e.filament_id,t)&&a.push({id:`builtin_${e.filament_id}`,name:e.name,source:`builtin`,filamentId:e.filament_id,filamentType:WH(e.name).material})}return a.sort((e,t)=>e.source===t.source?e.name.localeCompare(t.name):o5[e.source]-o5[t.source])}async function nKe(e,t){if(e.filamentId)return e.filamentId;if(e.source!==`cloud`||!t)return``;try{return(await t(e.id)).filament_id||``}catch{return``}}var s5=e=>(Math.trunc(parseFloat(e)*1e3)/1e3).toFixed(3),c5=`HS00`,l5=`HH00`,u5=e=>{let t=e.match(/^([A-Z]{2}\d{2})/);return t?t[1]:c5},rKe=e=>u5(e)===l5?`HF`:`S`,d5=e=>{for(let t of[`High Flow_`,`High Flow `,`Standard_`,`Standard `,`HF_`,`HF `,`S_`,`S `])if(e.startsWith(t))return e.slice(t.length);let t=e.indexOf(`_`);return t>0?e.slice(t+1):e};function f5({profile:e,onEdit:t,onCopy:n,selectionMode:r,isSelected:i,onToggleSelect:a,note:o}){let s=rKe(e.nozzle_id),c=e.nozzle_diameter;return(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[r&&(0,G.jsx)(`button`,{onClick:a,className:`text-bambu-gray hover:text-white transition-colors p-1`,children:i?(0,G.jsx)(vu,{className:`w-4 h-4 text-bambu-green`}):(0,G.jsx)(bu,{className:`w-4 h-4`})}),(0,G.jsxs)(`button`,{onClick:()=>{r&&a?a():t()},className:`flex-1 text-left px-3 py-2 bg-bambu-dark rounded hover:bg-bambu-dark-tertiary transition-colors ${i?`ring-1 ring-bambu-green`:``}`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-bambu-green font-mono text-sm font-bold whitespace-nowrap`,children:s5(e.k_value)}),(0,G.jsx)(`span`,{className:`text-white text-sm truncate flex-1`,title:e.name,children:e.name||`Unnamed`}),o&&(0,G.jsx)(`span`,{title:`Has note`,children:(0,G.jsx)(Cu,{className:`w-3 h-3 text-yellow-500`})}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:[s,` `,c]})]}),o&&(0,G.jsxs)(`div`,{className:`text-xs mt-0.5 truncate text-yellow-500/70`,title:o,children:[`Note: `,o.length>50?o.substring(0,50)+`...`:o]})]}),!r&&n&&(0,G.jsx)(`button`,{onClick:e=>{e.stopPropagation(),n()},className:`text-bambu-gray hover:text-white transition-colors p-1`,title:`Copy profile`,children:(0,G.jsx)(Vs,{className:`w-4 h-4`})})]})}function p5({profile:e,printerId:t,nozzleDiameter:n,existingProfiles:r=[],builtinFilaments:i=[],filamentPresets:a=[],isDualNozzle:o=!1,supportsFlowType:s=!0,initialNote:c=``,initialNoteKey:l=null,onClose:u,onSave:d,onSaveNote:f,hasPermission:p}){let{t:m}=U(),{showToast:h}=qd(),[g,_]=(0,y.useState)(e?.name||``),[v,b]=(0,y.useState)(e?.k_value?s5(e.k_value):`0.020`),[x,S]=(0,y.useState)(e?.filament_id||``),[C,w]=(0,y.useState)(e?u5(e.nozzle_id):c5),[T,E]=(0,y.useState)(e?.nozzle_diameter||n),[D,O]=(0,y.useState)(e?[e.extruder_id]:o?[0,1]:[0]),[k,A]=(0,y.useState)(!1),[j,M]=(0,y.useState)({current:0,total:0}),[N,P]=(0,y.useState)(c),[F,I]=(0,y.useState)(``),{schedule:L}=rU(),R=y.useMemo(()=>e?.filament_id?i.find(t=>t.filament_id===e.filament_id)?.name||d5(r.find(t=>t.filament_id===e.filament_id)?.name||e.name||``)||e.filament_id:``,[e,r,i]),z=y.useMemo(()=>{let e=[[`local`,m(`kProfiles.modal.source.local`)],[`orca_cloud`,m(`kProfiles.modal.source.orcaCloud`)],[`cloud`,m(`kProfiles.modal.source.bambuCloud`)],[`builtin`,m(`kProfiles.modal.source.builtin`)]],t=F.trim().toLowerCase(),n=t?a.filter(e=>e.name.toLowerCase().includes(t)):a;return e.map(([e,t])=>({source:e,label:t,items:n.filter(t=>t.source===e)})).filter(e=>e.items.length>0)},[a,F,m]),B=q({mutationFn:e=>(console.log(`[KProfile] Calling API...`),Z.setKProfile(t,e)),onSuccess:(t,n)=>{if(console.log(`[KProfile] Save success:`,t),h(m(`kProfiles.toast.profileSaved`)),f&&N!==c){let t;t=N===``&&l?l:e&&e.slot_id>0?e.setting_id||`slot_${e.slot_id}_${e.filament_id}_${e.extruder_id}`:`name_${g}_${n.filament_id}`,f(t,N)}A(!0),L(()=>{A(!1),d()},2500)},onError:e=>{console.error(`[KProfile] Save error:`,e),h(e.message,`error`),A(!1)}}),V=q({mutationFn:e=>(console.log(`[KProfile] Deleting profile...`),Z.deleteKProfile(t,e)),onSuccess:e=>{console.log(`[KProfile] Delete success:`,e),h(m(`kProfiles.toast.profileDeleted`)),A(!0),L(()=>{A(!1),u()},4e3)},onError:e=>{console.error(`[KProfile] Delete error:`,e),h(e.message,`error`),A(!1)}}),[ee,te]=(0,y.useState)(!1),ne=()=>{e&&V.mutate({slot_id:e.slot_id,extruder_id:e.extruder_id,nozzle_id:e.nozzle_id,nozzle_diameter:e.nozzle_diameter,filament_id:e.filament_id,setting_id:e.setting_id})};return(0,G.jsxs)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,children:[(0,G.jsxs)(zd,{className:`w-full max-w-md relative`,children:[k&&(0,G.jsxs)(`div`,{className:`absolute inset-0 bg-bambu-dark-secondary/90 flex flex-col items-center justify-center z-10 rounded-lg`,children:[(0,G.jsx)(Y,{className:`w-8 h-8 text-bambu-green animate-spin mb-3`}),(0,G.jsx)(`p`,{className:`text-white font-medium`,children:j.total>1?m(`kProfiles.modal.savingExtruder`,{current:j.current,total:j.total}):m(`kProfiles.modal.syncing`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-sm mt-1`,children:m(`kProfiles.modal.pleaseWait`)})]}),(0,G.jsxs)(Vd,{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.jsx)(`h2`,{className:`text-xl font-semibold text-white`,children:m(e?`kProfiles.modal.editTitle`:`kProfiles.modal.addTitle`)}),(0,G.jsx)(`button`,{onClick:u,className:`text-bambu-gray hover:text-white transition-colors`,disabled:k,children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]}),(0,G.jsxs)(`form`,{onSubmit:async n=>{if(n.preventDefault(),o&&!e&&D.length===0){h(m(`kProfiles.toast.selectAtLeastOneExtruder`),`error`);return}let r=parseFloat(v).toFixed(6),i=`${C}-${T}`,s=e&&e.nozzle_id||i,c=e?e.nozzle_diameter:T,l=e?.filament_id||``;if(!e){let e=a.find(e=>e.id===x);if(!e){h(m(`kProfiles.toast.selectFilament`),`error`);return}if(l=await nKe(e,Z.getCloudSettingDetail),!l){h(m(`kProfiles.toast.filamentNotResolvable`,{name:e.name}),`error`);return}}if(e||D.length===1){let t={name:g,k_value:r,filament_id:l,nozzle_id:s,nozzle_diameter:c,extruder_id:e?e.extruder_id:D[0],setting_id:e?.setting_id,slot_id:e?.slot_id??0};console.log(`[KProfile] Saving profile:`,t),B.mutate(t);return}A(!0),M({current:1,total:D.length});let u=D.map(e=>({name:g,k_value:r,filament_id:l,nozzle_id:i,nozzle_diameter:T,extruder_id:e,setting_id:void 0,slot_id:0}));console.log(`[KProfile] Saving ${u.length} profiles in batch:`,u);try{await Z.setKProfilesBatch(t,u),h(m(`kProfiles.toast.profilesSaved`,{count:D.length})),f&&N&&f(`name_${g}_${l}`,N)}catch(e){console.error(`[KProfile] Failed to save batch:`,e),h(m(`kProfiles.toast.failedToSaveBatch`),`error`),A(!1),M({current:0,total:0});return}M({current:D.length,total:D.length}),L(()=>{A(!1),M({current:0,total:0}),d()},3e3)},className:`p-4 space-y-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:m(`kProfiles.modal.profileName`)}),(0,G.jsx)(`input`,{type:`text`,value:g,onChange:e=>_(e.target.value),disabled:!!e,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none ${e?`opacity-60 cursor-not-allowed`:``}`,placeholder:m(`kProfiles.modal.profileNamePlaceholder`),required:!e})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:m(`kProfiles.modal.kValue`)}),(0,G.jsx)(`input`,{type:`text`,inputMode:`decimal`,value:v,onChange:e=>{let t=e.target.value;(t===``||/^\d*\.?\d*$/.test(t))&&b(t)},onBlur:e=>{let t=parseFloat(e.target.value);isNaN(t)||b((Math.trunc(t*1e3)/1e3).toFixed(3))},className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none font-mono`,placeholder:m(`kProfiles.modal.kValuePlaceholder`),required:!0}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:m(`kProfiles.modal.kValueHelp`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:m(`kProfiles.modal.filament`)}),e?(0,G.jsx)(`div`,{className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white opacity-60`,children:R||e.filament_id}):(0,G.jsxs)(`div`,{className:`border border-bambu-dark-tertiary rounded-lg overflow-hidden`,children:[(0,G.jsxs)(`div`,{className:`relative border-b border-bambu-dark-tertiary`,children:[(0,G.jsx)(Ql,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,G.jsx)(`input`,{type:`text`,value:F,onChange:e=>I(e.target.value),placeholder:m(`kProfiles.modal.searchFilaments`),className:`w-full pl-10 pr-3 py-2 bg-bambu-dark text-white placeholder-bambu-gray focus:outline-none`})]}),(0,G.jsx)(`div`,{className:`max-h-56 overflow-y-auto bg-bambu-dark`,children:z.length===0?(0,G.jsx)(`p`,{className:`px-3 py-3 text-xs text-bambu-gray`,children:a.length===0?m(`kProfiles.modal.noFilamentsHelp`):m(`kProfiles.modal.noFilamentMatches`)}):z.map(e=>(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`sticky top-0 z-10 flex items-center gap-2 px-3 py-1.5 bg-bambu-dark-secondary border-y border-bambu-dark-tertiary`,children:[(0,G.jsx)(`span`,{className:`text-xs font-bold uppercase tracking-wider text-bambu-green`,children:e.label}),(0,G.jsx)(`span`,{className:`text-[10px] text-bambu-gray`,children:e.items.length})]}),e.items.map(e=>(0,G.jsx)(`button`,{type:`button`,onClick:()=>{S(e.id),g||_(`${C===l5?`HF`:`S`} ${e.name}`)},className:`w-full text-left px-3 py-1.5 text-sm transition-colors ${x===e.id?`bg-bambu-green/20 text-white`:`text-white hover:bg-bambu-dark-tertiary`}`,children:e.name},e.id))]},e.source))})]})]}),(0,G.jsxs)(`div`,{className:s?`grid grid-cols-2 gap-4`:``,children:[(0,G.jsxs)(`div`,{className:s?``:`hidden`,children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:m(`kProfiles.modal.flowType`)}),(0,G.jsxs)(`select`,{value:C,onChange:t=>{let n=t.target.value;if(w(n),!e&&x&&!g){let e=a.find(e=>e.id===x);e&&_(`${n===l5?`HF`:`S`} ${e.name}`)}},disabled:!!e,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none ${e?`opacity-60 cursor-not-allowed`:``}`,children:[(0,G.jsx)(`option`,{value:l5,children:m(`kProfiles.modal.highFlow`)}),(0,G.jsx)(`option`,{value:c5,children:m(`kProfiles.modal.standard`)})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:m(`kProfiles.modal.nozzleSize`)}),(0,G.jsxs)(`select`,{value:T,onChange:e=>E(e.target.value),disabled:!!e,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none ${e?`opacity-60 cursor-not-allowed`:``}`,children:[(0,G.jsx)(`option`,{value:`0.2`,children:`0.2mm`}),(0,G.jsx)(`option`,{value:`0.4`,children:`0.4mm`}),(0,G.jsx)(`option`,{value:`0.6`,children:`0.6mm`}),(0,G.jsx)(`option`,{value:`0.8`,children:`0.8mm`})]})]})]}),o&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:m(e?`kProfiles.modal.extruder`:`kProfiles.modal.extruders`)}),e?(0,G.jsx)(`div`,{className:`px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white opacity-60`,children:e.extruder_id===1?m(`kProfiles.modal.left`):m(`kProfiles.modal.right`)}):(0,G.jsxs)(`div`,{className:`flex gap-4`,children:[(0,G.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:D.includes(1),onChange:e=>{e.target.checked?O([...D,1]):O(D.filter(e=>e!==1))},className:`w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green focus:ring-offset-0 accent-bambu-green`}),(0,G.jsx)(`span`,{className:`text-white`,children:m(`kProfiles.modal.left`)})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:D.includes(0),onChange:e=>{e.target.checked?O([...D,0]):O(D.filter(e=>e!==0))},className:`w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green focus:ring-offset-0 accent-bambu-green`}),(0,G.jsx)(`span`,{className:`text-white`,children:m(`kProfiles.modal.right`)})]})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:m(`kProfiles.modal.notes`)}),(0,G.jsx)(`textarea`,{value:N,onChange:e=>P(e.target.value),placeholder:m(`kProfiles.modal.notesPlaceholder`),rows:2,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none resize-none`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:m(`kProfiles.modal.notesHelp`)})]}),(0,G.jsxs)(`div`,{className:`flex gap-2 pt-4`,children:[e&&(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:()=>te(!0),disabled:V.isPending||k||!p(`kprofiles:delete`),title:p(`kprofiles:delete`)?void 0:m(`kProfiles.permission.noDelete`),className:`text-red-500 hover:bg-red-500/10`,children:V.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Pu,{className:`w-4 h-4`})}),(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:u,disabled:k,className:`flex-1`,children:m(`common.cancel`)}),(0,G.jsxs)(Q,{type:`submit`,disabled:B.isPending||k||!p(e?`kprofiles:update`:`kprofiles:create`),title:p(e?`kprofiles:update`:`kprofiles:create`)?void 0:m(e?`kProfiles.permission.noUpdate`:`kProfiles.permission.noCreate`),className:`flex-1`,children:[B.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Tc,{className:`w-4 h-4`}),m(`common.save`)]})]})]})]})]}),ee&&(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-[60]`,children:(0,G.jsx)(zd,{className:`w-full max-w-sm`,children:(0,G.jsxs)(Vd,{className:`p-6`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3 mb-4`,children:[(0,G.jsx)(`div`,{className:`w-10 h-10 rounded-full bg-red-500/20 flex items-center justify-center`,children:(0,G.jsx)(Pu,{className:`w-5 h-5 text-red-500`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`text-lg font-semibold text-white`,children:m(`kProfiles.deleteConfirm.title`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:m(`kProfiles.deleteConfirm.cannotUndo`)})]})]}),(0,G.jsx)(`p`,{className:`text-bambu-gray mb-6`,children:m(`kProfiles.deleteConfirm.message`,{name:e?.name})}),(0,G.jsxs)(`div`,{className:`flex gap-3`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>te(!1),className:`flex-1`,children:m(`common.cancel`)}),(0,G.jsxs)(Q,{onClick:()=>{te(!1),ne()},disabled:V.isPending,className:`flex-1 bg-red-500 hover:bg-red-600 text-white`,children:[V.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Pu,{className:`w-4 h-4`}),m(`common.delete`)]})]})]})})})]})}var m5={NOZZLE_DIAMETER:`bambusy_kprofiles_nozzle`,SORT_OPTION:`bambusy_kprofiles_sort`};function iKe(){let{t:e}=U(),{showToast:t}=qd(),{hasPermission:n}=Nd(),[r,i]=(0,y.useState)(null),[a,o]=(0,y.useState)(()=>localStorage.getItem(m5.NOZZLE_DIAMETER)||`0.4`),[s,c]=(0,y.useState)(null),[l,u]=(0,y.useState)(!1),[d,f]=(0,y.useState)(null),[p,m]=(0,y.useState)(``),[h,g]=(0,y.useState)(`all`),[_,v]=(0,y.useState)(`all`),[b,x]=(0,y.useState)(()=>localStorage.getItem(m5.SORT_OPTION)||`name`),[S,C]=(0,y.useState)(!1),[w,T]=(0,y.useState)(new Set),[E,D]=(0,y.useState)(!1),[O,k]=(0,y.useState)(!1),A=(0,y.useCallback)(e=>`${e.slot_id}_${e.extruder_id}`,[]);(0,y.useEffect)(()=>{localStorage.setItem(m5.NOZZLE_DIAMETER,a)},[a]),(0,y.useEffect)(()=>{localStorage.setItem(m5.SORT_OPTION,b)},[b]);let{data:j,isLoading:M}=K({queryKey:[`printers`],queryFn:Z.getPrinters}),{data:N,isLoading:P,isFetching:F,error:I,refetch:L}=K({queryKey:[`kprofiles`,r,a],queryFn:async()=>{console.log(`[KProfiles] Fetching profiles for printer`,r,`nozzle`,a);let e=await Z.getKProfiles(r,a);return console.log(`[KProfiles] Received profiles:`,e?.profiles?.length||0,`profiles`),e},enabled:!!r,retry:!1,staleTime:0,gcTime:0,refetchOnMount:`always`}),{data:R}=K({queryKey:[`builtinFilaments`],queryFn:()=>Z.getBuiltinFilaments(),staleTime:3e5}),{data:z}=K({queryKey:[`filamentIdMap`],queryFn:()=>Z.getFilamentIdMap(),staleTime:3e5}),{data:B}=K({queryKey:[`localPresets`],queryFn:()=>Z.getLocalPresets(),retry:!1}),{data:V}=K({queryKey:[`orcaCloudProfilesForKProfiles`],queryFn:()=>Z.orcaCloudListProfiles(),retry:!1}),{data:ee}=K({queryKey:[`cloudSettings`],queryFn:()=>Z.getCloudSettings(),retry:!1}),{data:te,refetch:ne}=K({queryKey:[`kprofile-notes`,r],queryFn:()=>Z.getKProfileNotes(r),enabled:!!r,staleTime:3e4}),re=I?.message?.includes(`not connected`);(0,y.useEffect)(()=>{if(!r&&j&&j.length>0){let e=j.find(e=>e.is_active);e&&i(e.id)}},[r,j]),(0,y.useEffect)(()=>{if(r){let e=setTimeout(()=>{L()},150);return()=>clearTimeout(e)}},[r,a]);let ie=j?.filter(e=>e.is_active)||[],ae=y.useMemo(()=>{let e=new Map;if(R)for(let t of R)e.set(t.filament_id,t.name);if(z)for(let[t,n]of Object.entries(z))e.has(t)||e.set(t,n);return e},[R,z]),oe=y.useMemo(()=>Array.from(ae.entries()).map(([e,t])=>({filament_id:e,name:t})),[ae]),se=y.useMemo(()=>tKe({localPresets:B?.filament,orcaProfiles:V?.filament,cloudSettings:ee?.filament,builtinFilaments:R}),[B?.filament,V?.filament,ee?.filament,R]),H=y.useCallback(e=>ae.get(e.filament_id)||d5(e.name),[ae]),ce=y.useMemo(()=>N?.profiles?N.profiles.filter(e=>{let t=p.toLowerCase(),n=!t||e.name.toLowerCase().includes(t)||e.filament_id.toLowerCase().includes(t),r=h===`all`||h===`left`&&e.extruder_id===1||h===`right`&&e.extruder_id===0,i=_===`all`||_===`hf`&&e.nozzle_id.startsWith(`HH`)||_===`s`&&e.nozzle_id.startsWith(`HS`);return n&&r&&i}).sort((e,t)=>{switch(b){case`k_value`:return parseFloat(e.k_value)-parseFloat(t.k_value);case`filament`:return H(e).localeCompare(H(t));default:return e.name.localeCompare(t.name)}}):[],[N?.profiles,p,h,_,b,H]),le=j?.find(e=>e.id===r),ue=le?.nozzle_count===2,de=le?.supports_nozzle_flow_type??!0;(0,y.useEffect)(()=>{de||v(`all`)},[de]),(0,y.useEffect)(()=>{let e=e=>{e.target instanceof HTMLInputElement||e.target instanceof HTMLTextAreaElement||e.target instanceof HTMLSelectElement||s||l||d||(e.key===`r`||e.key===`R`?(e.preventDefault(),L()):e.key===`n`||e.key===`N`?(e.preventDefault(),u(!0)):e.key===`Escape`&&S&&(e.preventDefault(),C(!1),T(new Set)))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[s,l,d,S,L]);let fe=(0,y.useCallback)(()=>{if(!N?.profiles||N.profiles.length===0){t(e(`kProfiles.toast.noProfilesToExport`),`error`);return}let n={version:1,exported_at:new Date().toISOString(),printer:le?.name||`Unknown`,nozzle_diameter:a,profiles:N.profiles.map(e=>({name:e.name,k_value:e.k_value,filament_id:e.filament_id,nozzle_id:e.nozzle_id,nozzle_diameter:e.nozzle_diameter,extruder_id:e.extruder_id}))},r=new Blob([JSON.stringify(n,null,2)],{type:`application/json`}),i=URL.createObjectURL(r),o=document.createElement(`a`);o.href=i,o.download=`kprofiles_${le?.name||`printer`}_${a}mm_${new Date().toISOString().split(`T`)[0]}.json`,document.body.appendChild(o),o.click(),document.body.removeChild(o),URL.revokeObjectURL(i),t(e(`kProfiles.toast.exportedProfiles`,{count:N.profiles.length}))},[N?.profiles,le,a,t,e]),pe=(0,y.useCallback)(()=>{let n=document.createElement(`input`);n.type=`file`,n.accept=`.json`,n.onchange=async n=>{let i=n.target.files?.[0];if(i)try{let n=await i.text(),o=JSON.parse(n);if(!o.profiles||!Array.isArray(o.profiles)){t(e(`kProfiles.toast.invalidFileFormat`),`error`);return}let s=0;for(let e of o.profiles)if(!(!e.name||!e.k_value||!e.filament_id))try{await Z.setKProfile(r,{name:e.name,k_value:parseFloat(e.k_value).toFixed(6),filament_id:e.filament_id,nozzle_id:e.nozzle_id||`${c5}-${a}`,nozzle_diameter:e.nozzle_diameter||a,extruder_id:e.extruder_id??0,slot_id:0}),s++,await new Promise(e=>setTimeout(e,500))}catch(t){console.error(`Failed to import profile:`,e.name,t)}t(e(`kProfiles.toast.importedProfiles`,{count:s,total:o.profiles.length})),L()}catch(n){console.error(`Import error:`,n),t(e(`kProfiles.toast.failedToParseImport`),`error`)}},n.click()},[r,a,t,L,e]),me=(0,y.useCallback)(e=>{T(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),he=(0,y.useCallback)(()=>{T(new Set(ce.map(e=>A(e))))},[ce,A]),ge=(0,y.useCallback)(()=>{w.size!==0&&D(!0)},[w.size]),_e=(0,y.useCallback)(async()=>{let n=ce.filter(e=>w.has(A(e)));k(!0);let i=0;for(let e of n)try{await Z.deleteKProfile(r,{slot_id:e.slot_id,extruder_id:e.extruder_id,nozzle_id:e.nozzle_id,nozzle_diameter:e.nozzle_diameter,filament_id:e.filament_id,setting_id:e.setting_id}),i++,await new Promise(e=>setTimeout(e,300))}catch(t){console.error(`Failed to delete profile:`,e.name,t)}t(e(`kProfiles.toast.profilesDeleted`,{count:i})),k(!1),D(!1),C(!1),T(new Set),L()},[r,w,ce,t,L,A,e]),ve=(0,y.useCallback)(e=>{let t=[];return e.setting_id&&t.push(e.setting_id),t.push(`slot_${e.slot_id}_${e.filament_id}_${e.extruder_id}`),t.push(`name_${e.name}_${e.filament_id}`),t},[]),ye=(0,y.useCallback)(async(n,i)=>{if(r)try{await Z.setKProfileNote(r,n,i),ne()}catch(n){console.error(`Failed to save note:`,n),t(e(`kProfiles.toast.failedToSaveNote`),`error`)}},[r,ne,t,e]),be=(0,y.useCallback)(e=>{if(!te?.notes)return{note:``,key:null};let t=ve(e);for(let e of t)if(te.notes[e])return{note:te.notes[e],key:e};return{note:``,key:null}},[te,ve]),xe=(0,y.useCallback)(e=>be(e).note,[be]);return M?(0,G.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,G.jsx)(Y,{className:`w-8 h-8 text-bambu-green animate-spin`})}):!j||j.length===0?(0,G.jsx)(zd,{children:(0,G.jsxs)(Vd,{className:`py-12 text-center`,children:[(0,G.jsx)(ys,{className:`w-12 h-12 text-bambu-gray mx-auto mb-4`}),(0,G.jsx)(`h3`,{className:`text-lg font-semibold text-white mb-2`,children:e(`kProfiles.noPrintersConfigured`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray`,children:e(`kProfiles.addPrinterInSettings`)})]})}):ie.length===0?(0,G.jsx)(zd,{children:(0,G.jsxs)(Vd,{className:`py-12 text-center`,children:[(0,G.jsx)(Rl,{className:`w-12 h-12 text-bambu-gray mx-auto mb-4`}),(0,G.jsx)(`h3`,{className:`text-lg font-semibold text-white mb-2`,children:e(`kProfiles.noActivePrinters`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray`,children:e(`kProfiles.enablePrinterConnection`)})]})}):(0,G.jsxs)(G.Fragment,{children:[F&&!P&&(0,G.jsxs)(`div`,{className:`fixed inset-0 bg-black/50 flex flex-col items-center justify-center z-40`,children:[(0,G.jsx)(Y,{className:`w-10 h-10 text-bambu-green animate-spin mb-3`}),(0,G.jsx)(`p`,{className:`text-white font-medium`,children:e(`kProfiles.loadingProfiles`)})]}),(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-4 mb-6`,children:[(0,G.jsxs)(`div`,{className:`flex-1 min-w-48`,children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:e(`kProfiles.printer`)}),(0,G.jsx)(`select`,{value:r||``,onChange:e=>i(parseInt(e.target.value)),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:ie.map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.name},e.id))})]}),(0,G.jsxs)(`div`,{className:`w-32`,children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:e(`kProfiles.nozzle`)}),(0,G.jsxs)(`select`,{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`,children:[(0,G.jsx)(`option`,{value:`0.2`,children:`0.2mm`}),(0,G.jsx)(`option`,{value:`0.4`,children:`0.4mm`}),(0,G.jsx)(`option`,{value:`0.6`,children:`0.6mm`}),(0,G.jsx)(`option`,{value:`0.8`,children:`0.8mm`})]})]}),(0,G.jsxs)(`div`,{className:`flex items-end gap-2`,children:[(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>L(),disabled:F||!n(`kprofiles:read`),title:n(`kprofiles:read`)?void 0:e(`kProfiles.permission.noRead`),children:[(0,G.jsx)(Hl,{className:`w-4 h-4 ${F?`animate-spin`:``}`}),e(`kProfiles.refresh`)]}),(0,G.jsxs)(Q,{onClick:()=>u(!0),disabled:!n(`kprofiles:create`),title:n(`kprofiles:create`)?void 0:e(`kProfiles.permission.noCreate`),children:[(0,G.jsx)(Fl,{className:`w-4 h-4`}),e(`kProfiles.addProfile`)]})]})]}),(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-4 mb-4`,children:[(0,G.jsxs)(`div`,{className:`flex-1 min-w-48 relative`,children:[(0,G.jsx)(Ql,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,G.jsx)(`input`,{type:`text`,value:p,onChange:e=>m(e.target.value),placeholder:e(`kProfiles.searchPlaceholder`),className:`w-full pl-10 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),ue&&(0,G.jsx)(`div`,{className:`w-36`,children:(0,G.jsxs)(`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:`all`,children:e(`kProfiles.allExtruders`)}),(0,G.jsx)(`option`,{value:`left`,children:e(`kProfiles.leftOnly`)}),(0,G.jsx)(`option`,{value:`right`,children:e(`kProfiles.rightOnly`)})]})}),de&&(0,G.jsx)(`div`,{className:`w-32`,children:(0,G.jsxs)(`select`,{value:_,onChange:e=>v(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:`all`,children:e(`kProfiles.allFlow`)}),(0,G.jsx)(`option`,{value:`hf`,children:e(`kProfiles.hfOnly`)}),(0,G.jsx)(`option`,{value:`s`,children:e(`kProfiles.sOnly`)})]})}),(0,G.jsx)(`div`,{className:`w-32`,children:(0,G.jsxs)(`select`,{value:b,onChange:e=>x(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:`name`,children:e(`kProfiles.sortName`)}),(0,G.jsx)(`option`,{value:`k_value`,children:e(`kProfiles.sortKValue`)}),(0,G.jsx)(`option`,{value:`filament`,children:e(`kProfiles.sortFilament`)})]})})]}),(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-2 mb-6`,children:[(0,G.jsxs)(Q,{variant:`secondary`,onClick:fe,disabled:!N?.profiles?.length||!n(`kprofiles:read`),title:n(`kprofiles:read`)?void 0:e(`kProfiles.permission.noExport`),children:[(0,G.jsx)(Xs,{className:`w-4 h-4`}),e(`kProfiles.export`)]}),(0,G.jsxs)(Q,{variant:`secondary`,onClick:pe,disabled:!n(`kprofiles:create`),title:n(`kprofiles:create`)?void 0:e(`kProfiles.permission.noImport`),children:[(0,G.jsx)(Vu,{className:`w-4 h-4`}),e(`kProfiles.import`)]}),(0,G.jsx)(`div`,{className:`flex-1`}),S?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(Q,{variant:`secondary`,onClick:he,children:[(0,G.jsx)(vu,{className:`w-4 h-4`}),e(`kProfiles.selectAll`)]}),(0,G.jsxs)(Q,{variant:`secondary`,onClick:ge,disabled:w.size===0||!n(`kprofiles:delete`),className:`text-red-500 hover:bg-red-500/10`,title:n(`kprofiles:delete`)?void 0:e(`kProfiles.permission.noDelete`),children:[(0,G.jsx)(Pu,{className:`w-4 h-4`}),e(`kProfiles.delete`),` (`,w.size,`)`]}),(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>{C(!1),T(new Set)},children:[(0,G.jsx)(nd,{className:`w-4 h-4`}),e(`common.cancel`)]})]}):(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>C(!0),disabled:!ce.length||!n(`kprofiles:delete`),title:n(`kprofiles:delete`)?void 0:e(`kProfiles.permission.noDelete`),children:[(0,G.jsx)(vu,{className:`w-4 h-4`}),e(`kProfiles.select`)]})]}),P?(0,G.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,G.jsx)(Y,{className:`w-8 h-8 text-bambu-green animate-spin`})}):re?(0,G.jsx)(zd,{children:(0,G.jsxs)(Vd,{className:`py-12 text-center`,children:[(0,G.jsx)(Zu,{className:`w-12 h-12 text-bambu-gray mx-auto mb-4`}),(0,G.jsx)(`h3`,{className:`text-lg font-semibold text-white mb-2`,children:e(`kProfiles.printerOffline`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray mb-4`,children:e(`kProfiles.printerOfflineDesc`)}),(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>L(),children:[(0,G.jsx)(Hl,{className:`w-4 h-4`}),e(`common.refresh`)]})]})}):ce.length>0?ue?(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`text-sm font-medium text-bambu-gray mb-2 px-1`,children:e(`kProfiles.leftExtruder`)}),(0,G.jsx)(`div`,{className:`space-y-1`,children:ce.filter(e=>e.extruder_id===1).map(e=>(0,G.jsx)(f5,{profile:e,onEdit:()=>c(e),onCopy:()=>f(e),selectionMode:S,isSelected:w.has(A(e)),onToggleSelect:()=>me(A(e)),note:xe(e)},A(e)))})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`text-sm font-medium text-bambu-gray mb-2 px-1`,children:e(`kProfiles.rightExtruder`)}),(0,G.jsx)(`div`,{className:`space-y-1`,children:ce.filter(e=>e.extruder_id===0).map(e=>(0,G.jsx)(f5,{profile:e,onEdit:()=>c(e),onCopy:()=>f(e),selectionMode:S,isSelected:w.has(A(e)),onToggleSelect:()=>me(A(e)),note:xe(e)},A(e)))})]})]}):(0,G.jsx)(`div`,{className:`space-y-1`,children:ce.map(e=>(0,G.jsx)(f5,{profile:e,onEdit:()=>c(e),onCopy:()=>f(e),selectionMode:S,isSelected:w.has(A(e)),onToggleSelect:()=>me(A(e)),note:xe(e)},A(e)))}):p||h!==`all`||_!==`all`?(0,G.jsx)(zd,{children:(0,G.jsxs)(Vd,{className:`py-12 text-center`,children:[(0,G.jsx)(Ql,{className:`w-12 h-12 text-bambu-gray mx-auto mb-4`}),(0,G.jsx)(`h3`,{className:`text-lg font-semibold text-white mb-2`,children:e(`kProfiles.noMatchingProfiles`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray`,children:e(`kProfiles.noMatchingProfilesDesc`)})]})}):(0,G.jsx)(zd,{children:(0,G.jsxs)(Vd,{className:`py-12 text-center`,children:[(0,G.jsx)(Tc,{className:`w-12 h-12 text-bambu-gray mx-auto mb-4`}),(0,G.jsx)(`h3`,{className:`text-lg font-semibold text-white mb-2`,children:e(`kProfiles.noKProfiles`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray mb-4`,children:e(`kProfiles.noKProfilesDesc`,{diameter:a})}),(0,G.jsxs)(Q,{onClick:()=>u(!0),children:[(0,G.jsx)(Fl,{className:`w-4 h-4`}),e(`kProfiles.createFirstProfile`)]})]})}),s&&r&&(()=>{let{note:e,key:t}=be(s);return(0,G.jsx)(p5,{profile:s,printerId:r,nozzleDiameter:a,existingProfiles:N?.profiles,builtinFilaments:oe,filamentPresets:se,isDualNozzle:ue,supportsFlowType:de,initialNote:e,initialNoteKey:t,onSaveNote:ye,hasPermission:n,onClose:()=>{console.log(`[KProfiles] Edit modal onClose - refetching profiles...`),c(null),L()},onSave:()=>{c(null),L()}})})(),l&&r&&(0,G.jsx)(p5,{printerId:r,nozzleDiameter:a,existingProfiles:N?.profiles,builtinFilaments:oe,filamentPresets:se,isDualNozzle:ue,supportsFlowType:de,onSaveNote:ye,hasPermission:n,onClose:()=>{u(!1),L()},onSave:()=>{u(!1),L()}}),d&&r&&(0,G.jsx)(p5,{printerId:r,nozzleDiameter:a,existingProfiles:N?.profiles,builtinFilaments:oe,filamentPresets:se,isDualNozzle:ue,supportsFlowType:de,onSaveNote:ye,hasPermission:n,profile:{...d,slot_id:0,name:`${d.name} (Copy)`},onClose:()=>{f(null),L()},onSave:()=>{f(null),L()}}),E&&(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,children:(0,G.jsx)(zd,{className:`w-full max-w-sm`,children:(0,G.jsxs)(Vd,{className:`p-6`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3 mb-4`,children:[(0,G.jsx)(`div`,{className:`w-10 h-10 rounded-full bg-red-500/20 flex items-center justify-center`,children:(0,G.jsx)(Pu,{className:`w-5 h-5 text-red-500`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`text-lg font-semibold text-white`,children:e(`kProfiles.bulkDelete.title`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`kProfiles.bulkDelete.cannotUndo`)})]})]}),(0,G.jsx)(`p`,{className:`text-bambu-gray mb-6`,children:e(`kProfiles.bulkDelete.message`,{count:w.size})}),(0,G.jsxs)(`div`,{className:`flex gap-3`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>D(!1),disabled:O,className:`flex-1`,children:e(`common.cancel`)}),(0,G.jsxs)(Q,{onClick:_e,disabled:O,className:`flex-1 bg-red-500 hover:bg-red-600 text-white`,children:[O?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Pu,{className:`w-4 h-4`}),e(`common.delete`)]})]})]})})})]})}var h5=[`PLA`,`PETG`,`PCTG`,`ABS`,`ASA`,`TPU`,`PC`,`PA`,`PVA`,`HIPS`,`PP`,`PET`,`NYLON`],aKe={PLA:`E8E8E8`,PETG:`4A90D9`,ABS:`E67E22`,ASA:`D35400`,TPU:`9B59B6`,PC:`BDC3C7`,PA:`2ECC71`,NYLON:`2ECC71`,PVA:`F1C40F`,HIPS:`95A5A6`,PP:`ECF0F1`,PET:`3498DB`};function oKe(e){let t=e.toUpperCase();for(let e of h5)if(RegExp(`\\b${e}\\b`).test(t))return e;return null}function sKe(e){let t=e.replace(/@.+$/,``).trim(),n=t.toUpperCase();for(let e of h5){let r=n.indexOf(e);if(r>0){let e=t.slice(0,r).trim();if(e&&e.length>1)return e}}return null}function g5({preset:e,onDelete:t,onExpand:n,isExpanded:r}){let{t:i}=U(),{hasPermission:a}=Nd(),o=e.filament_type||oKe(e.name),s=e.filament_vendor||sKe(e.name),c=null,l=!1;if(e.default_filament_colour)try{let t=JSON.parse(e.default_filament_colour),n=Array.isArray(t)?t[0]:t;typeof n==`string`&&/^#?[0-9a-fA-F]{6,8}$/.test(n.replace(`#`,``))&&(c=n.replace(`#`,``).slice(0,6),l=!0)}catch{let t=e.default_filament_colour;/^#?[0-9a-fA-F]{6,8}$/.test(t.replace(`#`,``))&&(c=t.replace(`#`,``).slice(0,6),l=!0)}return!c&&o&&(c=aKe[o.toUpperCase()]||null),(0,G.jsx)(zd,{className:`bg-bambu-dark border-bambu-dark-tertiary hover:border-bambu-dark-tertiary/80 transition-colors`,children:(0,G.jsxs)(Vd,{className:`p-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[e.preset_type===`filament`&&(0,G.jsx)(`div`,{className:`w-4 h-4 rounded-full border border-black/20 flex-shrink-0 ${!l&&!c?`opacity-25`:l?``:`opacity-50`}`,style:{backgroundColor:c?`#${c}`:`#666`}}),(0,G.jsx)(`span`,{className:`text-sm font-medium text-white truncate`,children:e.name})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[o&&(0,G.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-bambu-green/20 text-bambu-green`,children:o}),s&&(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:s}),(0,G.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`,children:i(`profiles.localProfiles.badge`)})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1 flex-shrink-0`,children:[a(`settings:update`)&&(0,G.jsx)(`button`,{onClick:()=>t(e.id),className:`p-1 text-bambu-gray hover:text-red-600 dark:hover:text-red-400 transition-colors`,title:i(`profiles.localProfiles.delete`),children:(0,G.jsx)(Pu,{className:`w-3.5 h-3.5`})}),(0,G.jsx)(`button`,{onClick:()=>n(r?null:e.id),className:`p-1 text-bambu-gray hover:text-white transition-colors`,children:r?(0,G.jsx)(gs,{className:`w-3.5 h-3.5`}):(0,G.jsx)(ps,{className:`w-3.5 h-3.5`})})]})]}),r&&(0,G.jsxs)(`div`,{className:`mt-3 pt-3 border-t border-bambu-dark-tertiary text-xs space-y-1.5`,children:[o&&(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:i(`profiles.localProfiles.filamentType`)}),(0,G.jsx)(`span`,{className:`text-white`,children:o})]}),s&&(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:i(`profiles.localProfiles.vendor`)}),(0,G.jsx)(`span`,{className:`text-white`,children:s})]}),e.nozzle_temp_min!=null&&e.nozzle_temp_max!=null&&(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:i(`profiles.localProfiles.nozzleTemp`)}),(0,G.jsxs)(`span`,{className:`text-white`,children:[e.nozzle_temp_min,`–`,e.nozzle_temp_max,`°C`]})]}),e.filament_cost&&(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:i(`profiles.localProfiles.cost`)}),(0,G.jsx)(`span`,{className:`text-white`,children:e.filament_cost})]}),e.filament_density&&(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:i(`profiles.localProfiles.density`)}),(0,G.jsxs)(`span`,{className:`text-white`,children:[e.filament_density,` g/cm³`]})]}),e.pressure_advance&&(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:i(`profiles.localProfiles.pressureAdvance`)}),(0,G.jsx)(`span`,{className:`text-white`,children:e.pressure_advance})]}),e.compatible_printers&&(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:i(`profiles.localProfiles.compatiblePrinters`)}),(0,G.jsx)(`span`,{className:`text-white truncate ml-2`,children:(()=>{try{return JSON.parse(e.compatible_printers).join(`, `)}catch{return e.compatible_printers}})()})]}),e.inherits&&e.inherits!==e.name&&(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:i(`profiles.localProfiles.inheritsFrom`)}),(0,G.jsx)(`span`,{className:`text-white truncate ml-2`,children:e.inherits})]}),(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:i(`profiles.localProfiles.source`)}),(0,G.jsx)(`span`,{className:`text-white capitalize`,children:e.source})]})]})]})})}function cKe(){let{t:e}=U(),{hasPermission:t}=Nd(),n=co(),{showToast:r}=qd(),[i,a]=(0,y.useState)(``),[o,s]=(0,y.useState)(null),[c,l]=(0,y.useState)(!1),[u,d]=(0,y.useState)(null),{data:f,isLoading:p}=K({queryKey:[`localPresets`],queryFn:()=>Z.getLocalPresets()}),m=q({mutationFn:async e=>{let t=[];for(let n of Array.from(e)){let e=new FormData;e.append(`file`,n),t.push(await Z.importLocalPresets(e))}return t},onSuccess:t=>{n.invalidateQueries({queryKey:[`localPresets`]}),n.invalidateQueries({queryKey:[`slicerPresets`]});let i=0,a=0,o=0;for(let e of t)i+=e.imported,a+=e.skipped,o+=e.errors.length;i>0&&r(e(`profiles.localProfiles.toast.importSuccess`,{count:i})),a>0&&r(e(`profiles.localProfiles.toast.importSkipped`,{count:a}),`warning`),o>0&&r(e(`profiles.localProfiles.toast.importError`,{count:o}),`error`)},onError:e=>{r(e.message,`error`)}}),h=q({mutationFn:e=>Z.deleteLocalPreset(e),onSuccess:(t,i)=>{n.setQueryData([`localPresets`],e=>e&&{filament:e.filament.filter(e=>e.id!==i),printer:e.printer.filter(e=>e.id!==i),process:e.process.filter(e=>e.id!==i)}),n.invalidateQueries({queryKey:[`localPresets`]}),n.invalidateQueries({queryKey:[`slicerPresets`]}),d(null),r(e(`profiles.localProfiles.toast.deleted`))}}),g=(0,y.useCallback)(e=>{!e||e.length===0||m.mutate(e)},[m]),_=(0,y.useCallback)(e=>{e.preventDefault(),l(!1),g(e.dataTransfer.files)},[g]),v=(0,y.useCallback)(e=>{if(!i)return e;let t=i.toLowerCase();return e.filter(e=>e.name.toLowerCase().includes(t)||e.filament_type?.toLowerCase().includes(t)||e.filament_vendor?.toLowerCase().includes(t))},[i]),b=(0,y.useMemo)(()=>v(f?.filament||[]),[f?.filament,v]),x=(0,y.useMemo)(()=>v(f?.printer||[]),[f?.printer,v]),S=(0,y.useMemo)(()=>v(f?.process||[]),[f?.process,v]),C=b.length+x.length+S.length,w=(f?.filament?.length??0)+(f?.printer?.length??0)+(f?.process?.length??0)>0;return p?(0,G.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,G.jsx)(Y,{className:`w-8 h-8 text-bambu-green animate-spin`})}):(0,G.jsxs)(`div`,{className:`space-y-6`,children:[t(`settings:update`)&&(0,G.jsxs)(`div`,{onDragOver:e=>{e.preventDefault(),l(!0)},onDragLeave:()=>l(!1),onDrop:_,className:`relative border-2 border-dashed rounded-lg p-6 text-center transition-colors ${c?`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary hover:border-bambu-gray`}`,children:[(0,G.jsx)(`input`,{type:`file`,accept:`.json,.zip,.orca_filament,.bbscfg,.bbsflmt`,multiple:!0,className:`absolute inset-0 w-full h-full opacity-0 cursor-pointer`,onChange:e=>g(e.target.files)}),m.isPending?(0,G.jsxs)(`div`,{className:`flex items-center justify-center gap-2`,children:[(0,G.jsx)(Y,{className:`w-5 h-5 text-bambu-green animate-spin`}),(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:e(`profiles.localProfiles.importing`)})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Vu,{className:`w-8 h-8 text-bambu-gray mx-auto mb-2`}),(0,G.jsx)(`p`,{className:`text-sm text-white font-medium`,children:e(`profiles.localProfiles.import`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`profiles.localProfiles.importDesc`)})]})]}),w&&(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(Ql,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,G.jsx)(`input`,{type:`text`,value:i,onChange:e=>a(e.target.value),placeholder:e(`profiles.localProfiles.search`),className:`w-full pl-9 pr-4 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`})]}),!w&&!p&&(0,G.jsxs)(`div`,{className:`text-center py-12`,children:[(0,G.jsx)(Pc,{className:`w-12 h-12 text-bambu-gray mx-auto mb-3 opacity-50`}),(0,G.jsx)(`p`,{className:`text-bambu-gray`,children:e(`profiles.localProfiles.noPresets`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray/60 mt-1`,children:e(`profiles.localProfiles.importDesc`)})]}),w&&C===0&&!p&&(0,G.jsxs)(`div`,{className:`text-center py-12`,children:[(0,G.jsx)(Ql,{className:`w-12 h-12 text-bambu-gray mx-auto mb-3 opacity-50`}),(0,G.jsx)(`p`,{className:`text-bambu-gray`,children:e(`profiles.localProfiles.noSearchResults`)})]}),C>0&&(0,G.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6`,children:[b.length>0&&(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,G.jsx)(Zs,{className:`w-4 h-4 text-bambu-green`}),(0,G.jsx)(`h3`,{className:`text-sm font-medium text-white`,children:e(`profiles.localProfiles.filament`)}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[`(`,b.length,`)`]})]}),(0,G.jsx)(`div`,{className:`space-y-2`,children:b.map(e=>(0,G.jsx)(g5,{preset:e,onDelete:e=>d(e),onExpand:s,isExpanded:o===e.id},e.id))})]}),S.length>0&&(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,G.jsx)(Jc,{className:`w-4 h-4 text-blue-600 dark:text-blue-400`}),(0,G.jsx)(`h3`,{className:`text-sm font-medium text-white`,children:e(`profiles.localProfiles.process`)}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[`(`,S.length,`)`]})]}),(0,G.jsx)(`div`,{className:`space-y-2`,children:S.map(e=>(0,G.jsx)(g5,{preset:e,onDelete:e=>d(e),onExpand:s,isExpanded:o===e.id},e.id))})]}),x.length>0&&(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,G.jsx)(nu,{className:`w-4 h-4 text-orange-600 dark:text-orange-400`}),(0,G.jsx)(`h3`,{className:`text-sm font-medium text-white`,children:e(`profiles.localProfiles.printer`)}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[`(`,x.length,`)`]})]}),(0,G.jsx)(`div`,{className:`space-y-2`,children:x.map(e=>(0,G.jsx)(g5,{preset:e,onDelete:e=>d(e),onExpand:s,isExpanded:o===e.id},e.id))})]})]}),u!==null&&(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50`,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg p-6 max-w-sm mx-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,G.jsx)(ys,{className:`w-5 h-5 text-red-600 dark:text-red-400`}),(0,G.jsx)(`h3`,{className:`text-white font-medium`,children:e(`profiles.localProfiles.deleteConfirmTitle`)})]}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4`,children:e(`profiles.localProfiles.deleteConfirm`)}),(0,G.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,G.jsx)(Q,{variant:`secondary`,size:`sm`,onClick:()=>d(null),children:e(`profiles.localProfiles.cancel`)}),(0,G.jsxs)(Q,{variant:`danger`,size:`sm`,onClick:()=>h.mutate(u),disabled:h.isPending,children:[h.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Pu,{className:`w-4 h-4`}),e(`profiles.localProfiles.delete`)]})]})]})})]})}function lKe(e){let t=e.match(/@?\s*(?:BBL\s+)?(?:Bambu\s+Lab\s+)?([XPAH][1-9][A-Z]?(?:\s*(?:Carbon|mini))?|H2D)/i),n=e.match(/(\d+\.?\d*)\s*(?:mm\s*)?nozzle|nozzle\s*(\d+\.?\d*)/i),r=e.match(/(\d+\.?\d*)mm\s*(?:Standard|Fine|Extra Fine|Draft|Quality)?/i),i=e.match(/\b(PLA|PETG|ABS|ASA|TPU|PC|PA|PVA|HIPS|PP|PET(?:-?CF)?|PA(?:-?CF)?|PLA(?:-?CF)?)\b/i);return{printer:t?t[1].trim():null,nozzle:n?(n[1]||n[2])+`mm`:null,layerHeight:r?r[1]+`mm`:null,filamentType:i?i[1].toUpperCase():null}}function uKe({settings:e,lastSyncTime:t,onRefresh:n,isRefreshing:r,printers:i,t:a}){let[o,s]=(0,y.useState)(``),[c,l]=(0,y.useState)(`all`),[u,d]=(0,y.useState)(`all`),[f,p]=(0,y.useState)(`all`),[m,h]=(0,y.useState)(`all`),[g,_]=(0,y.useState)(`all`),[v,b]=(0,y.useState)(null),x=(0,y.useMemo)(()=>[...e.filament.map(e=>({...e,type:`filament`})),...e.printer.map(e=>({...e,type:`printer`})),...e.process.map(e=>({...e,type:`process`}))].map(e=>({...e,meta:lKe(e.name)})),[e]),S=(0,y.useMemo)(()=>{let e=new Set,t=new Set,n=new Set;return x.forEach(r=>{r.meta.nozzle&&e.add(r.meta.nozzle),r.meta.filamentType&&t.add(r.meta.filamentType),r.meta.layerHeight&&n.add(r.meta.layerHeight)}),{printers:i.map(e=>({id:e.id.toString(),name:e.name})),nozzles:Array.from(e).sort((e,t)=>parseFloat(e)-parseFloat(t)),filaments:Array.from(t).sort(),layerHeights:Array.from(n).sort((e,t)=>parseFloat(e)-parseFloat(t))}},[x,i]),C=(0,y.useMemo)(()=>u===`all`?null:i.find(e=>e.id.toString()===u)?.model||null,[u,i]),w=(0,y.useMemo)(()=>x.filter(e=>c===`all`||e.type===c).filter(e=>{if(u===`all`||!C)return!0;let t=e.meta.printer?.toLowerCase()||``,n=C.toLowerCase();return t.includes(n)||n.includes(t)}).filter(e=>f===`all`||e.meta.nozzle===f).filter(e=>m===`all`||e.meta.filamentType===m).filter(e=>g===`all`||e.meta.layerHeight===g).filter(e=>o===``||e.name.toLowerCase().includes(o.toLowerCase())).sort((e,t)=>e.name.localeCompare(t.name)),[x,c,u,C,f,m,g,o]),T=()=>{l(`all`),d(`all`),p(`all`),h(`all`),_(`all`),s(``)},E=c!==`all`||u!==`all`||f!==`all`||m!==`all`||g!==`all`||o!==``,D=e.filament.length+e.printer.length+e.process.length,O=e=>w.filter(t=>t.type===e);return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`space-y-4 mb-6`,children:[(0,G.jsxs)(`div`,{className:`flex flex-col sm:flex-row gap-3`,children:[(0,G.jsxs)(`div`,{className:`relative flex-1`,children:[(0,G.jsx)(Ql,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,G.jsx)(`input`,{type:`text`,value:o,onChange:e=>s(e.target.value),placeholder:a(`profiles.cloudView.searchPlaceholder`),className:`w-full pl-10 pr-4 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none`})]}),(0,G.jsx)(`div`,{className:`flex gap-2`,children:(0,G.jsxs)(Q,{variant:`secondary`,onClick:n,disabled:r,children:[(0,G.jsx)(Hl,{className:`w-4 h-4 ${r?`animate-spin`:``}`}),a(`profiles.cloudView.refresh`)]})})]}),(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,G.jsx)(wc,{className:`w-4 h-4 text-bambu-gray`}),(0,G.jsx)(b5,{label:a(`profiles.cloudView.filters.type`),value:c,options:[{value:`all`,label:a(`profiles.cloudView.filters.all`),count:D},{value:`filament`,label:a(`profiles.cloudView.filters.filament`),count:e.filament.length},{value:`printer`,label:a(`profiles.cloudView.filters.printer`),count:e.printer.length},{value:`process`,label:a(`profiles.cloudView.filters.process`),count:e.process.length}],onChange:e=>l(e)}),S.printers.length>0&&(0,G.jsx)(b5,{label:a(`profiles.cloudView.filters.printer`),value:u,options:[{value:`all`,label:a(`profiles.cloudView.filters.all`)},...S.printers.map(e=>({value:e.id,label:e.name}))],onChange:d}),S.nozzles.length>0&&(0,G.jsx)(b5,{label:a(`profiles.cloudView.filters.nozzle`),value:f,options:[{value:`all`,label:a(`profiles.cloudView.filters.all`)},...S.nozzles.map(e=>({value:e,label:e}))],onChange:p}),S.filaments.length>0&&(c===`all`||c===`filament`)&&(0,G.jsx)(b5,{label:a(`profiles.cloudView.filters.filament`),value:m,options:[{value:`all`,label:a(`profiles.cloudView.filters.all`)},...S.filaments.map(e=>({value:e,label:e}))],onChange:h}),S.layerHeights.length>0&&(c===`all`||c===`process`)&&(0,G.jsx)(b5,{label:a(`profiles.cloudView.filters.layer`),value:g,options:[{value:`all`,label:a(`profiles.cloudView.filters.all`)},...S.layerHeights.map(e=>({value:e,label:e}))],onChange:_}),E&&(0,G.jsx)(`button`,{onClick:T,className:`px-3 py-2 text-sm text-bambu-gray hover:text-white transition-colors`,children:a(`profiles.cloudView.clearFilters`)})]})]}),(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4 mb-4 text-sm text-bambu-gray`,children:[t&&(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(js,{className:`w-3 h-3`}),a(`profiles.cloudView.lastSynced`),` `,up(t.toISOString(),`system`,a)]}),(0,G.jsx)(`span`,{children:a(`profiles.cloudView.showingCount`,{showing:w.length,total:D})})]}),w.length===0?(0,G.jsxs)(`div`,{className:`text-center py-16`,children:[(0,G.jsx)(Jc,{className:`w-12 h-12 text-bambu-gray-dark mx-auto mb-4`}),(0,G.jsx)(`p`,{className:`text-bambu-gray`,children:a(`profiles.cloudView.noPresetsFound`)}),E&&(0,G.jsx)(`button`,{onClick:T,className:`mt-2 text-sm text-bambu-green hover:text-bambu-green-light`,children:a(`profiles.cloudView.clearFilters`)})]}):(0,G.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-6`,children:[(0,G.jsx)(_5,{icon:(0,G.jsx)(Zs,{className:`w-4 h-4 text-amber-600 dark:text-amber-400`}),title:a(`profiles.cloudView.columns.filament`),presets:O(`filament`),emptyText:a(`profiles.cloudView.noFilamentPresets`),onSelect:b}),(0,G.jsx)(_5,{icon:(0,G.jsx)(nu,{className:`w-4 h-4 text-blue-600 dark:text-blue-400`}),title:a(`profiles.cloudView.columns.process`),presets:O(`process`),emptyText:a(`profiles.cloudView.noProcessPresets`),onSelect:b}),(0,G.jsx)(_5,{icon:(0,G.jsx)(Rl,{className:`w-4 h-4 text-purple-600 dark:text-purple-400`}),title:a(`profiles.cloudView.columns.printer`),presets:O(`printer`),emptyText:a(`profiles.cloudView.noPrinterPresets`),onSelect:b})]}),v&&(0,G.jsx)(fKe,{setting:v,onClose:()=>b(null),t:a})]})}function _5({icon:e,title:t,presets:n,emptyText:r,onSelect:i}){return(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-3 px-1`,children:[e,(0,G.jsx)(`h3`,{className:`text-sm font-medium text-bambu-gray`,children:t}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray-dark`,children:[`(`,n.length,`)`]})]}),(0,G.jsx)(`div`,{className:`space-y-1 max-h-[calc(100vh-320px)] overflow-y-auto pr-1`,children:n.length===0?(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray-dark px-3 py-2`,children:r}):n.map(e=>(0,G.jsx)(dKe,{preset:e,onClick:()=>i(e)},e.setting_id))})]})}function dKe({preset:e,onClick:t}){return(0,G.jsx)(`button`,{onClick:t,className:`w-full text-left px-3 py-2 rounded bg-bambu-dark hover:bg-bambu-dark-tertiary transition-colors`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-white text-sm truncate flex-1`,title:e.name,children:e.name}),e.meta.filamentType&&e.type===`filament`&&(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:e.meta.filamentType}),e.meta.layerHeight&&e.type===`process`&&(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:e.meta.layerHeight}),e.meta.printer&&(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:e.meta.printer})]})})}function fKe({setting:e,onClose:t,t:n}){let{data:r,isLoading:i,error:a}=K({queryKey:[`orcaCloudProfileDetail`,e.setting_id],queryFn:()=>Z.orcaCloudGetProfile(e.setting_id),retry:!1});return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/60 z-50 flex items-center justify-center p-4`,onClick:t,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-2xl max-w-4xl w-full max-h-[90vh] flex flex-col`,onClick:e=>e.stopPropagation(),children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h2`,{className:`text-lg font-bold text-white`,children:e.name}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:e.type})]}),(0,G.jsx)(`button`,{onClick:t,className:`text-bambu-gray hover:text-white p-1`,children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]}),(0,G.jsx)(`div`,{className:`flex-1 overflow-y-auto p-4`,children:i?(0,G.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,G.jsx)(Y,{className:`w-8 h-8 text-bambu-green animate-spin`})}):a?(0,G.jsx)(`p`,{className:`text-center text-bambu-gray py-16`,children:a.message}):r?(0,G.jsx)(`pre`,{className:`text-xs font-mono text-bambu-gray bg-bambu-dark p-3 rounded overflow-x-auto whitespace-pre`,children:JSON.stringify(r.setting,null,2)}):(0,G.jsx)(`p`,{className:`text-center text-bambu-gray py-16`,children:n(`profiles.cloudView.noPresetsFound`)})})]})})}function pKe(){let{t:e}=U(),t=co(),{showToast:n}=qd(),{hasPermission:r}=Nd(),i=r(`orca_cloud:auth`),[a,o]=(0,y.useState)(null),[s,c]=(0,y.useState)(5e3),[l,u]=(0,y.useState)(null),{data:d,isLoading:f}=K({queryKey:[`orcaCloudStatus`],queryFn:Z.orcaCloudStatus}),p=!!d?.connected,{data:m,isLoading:h,refetch:g,isRefetching:_,error:v,dataUpdatedAt:b}=K({queryKey:[`orcaCloudProfiles`],queryFn:Z.orcaCloudListProfiles,enabled:p,retry:!1,staleTime:1e3*60*5}),{data:x=[]}=K({queryKey:[`printers`],queryFn:Z.getPrinters,enabled:p}),[S,C]=(0,y.useState)();(0,y.useEffect)(()=>{b&&C(new Date(b))},[b]);let w=()=>{o(null),c(5e3)},T=t=>{t===`access_denied`?u(e(`profiles.orcaCloud.errors.denied`)):t===`expired_token`&&u(e(`profiles.orcaCloud.errors.expired`)),w()},E=q({mutationFn:Z.orcaCloudDeviceStart,onSuccess:e=>{u(null),c(Math.max(1,e.interval)*1e3),o(e)},onError:t=>{u(t.message||e(`profiles.orcaCloud.errors.startFailed`))}}),D=q({mutationFn:Z.orcaCloudLogout,onSuccess:()=>{t.invalidateQueries({queryKey:[`orcaCloudStatus`]}),t.removeQueries({queryKey:[`orcaCloudProfiles`]}),n(e(`profiles.orcaCloud.toast.disconnected`))}}),{data:O,error:k}=K({queryKey:[`orcaCloudDevicePoll`,a?.user_code??`none`],queryFn:Z.orcaCloudDevicePoll,enabled:a!==null,gcTime:0,retry:!1,refetchOnWindowFocus:!1,refetchInterval:a===null?!1:s}),A=(0,y.useRef)(null);return(0,y.useEffect)(()=>{if(!a||!O)return;let r=O.status;if(r===`slow_down`){c(e=>e+5e3);return}r!==`authorization_pending`&&A.current!==r&&(A.current=r,r===`complete`?(w(),t.invalidateQueries({queryKey:[`orcaCloudStatus`]}),t.invalidateQueries({queryKey:[`orcaCloudProfiles`]}),n(e(`profiles.orcaCloud.connectedShort`))):T(r))},[O,a]),(0,y.useEffect)(()=>{a&&k&&(u(e(`profiles.orcaCloud.errors.pollFailed`)),w())},[k,a]),(0,y.useEffect)(()=>{a&&(A.current=null)},[a]),f?(0,G.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,G.jsx)(Y,{className:`w-8 h-8 text-bambu-green animate-spin`})}):(0,G.jsxs)(`div`,{children:[p&&(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-3 mb-6 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`w-2 h-2 rounded-full bg-bambu-green animate-pulse`}),(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:d?.email?(0,G.jsxs)(G.Fragment,{children:[e(`profiles.orcaCloud.connectedAs`),` `,(0,G.jsx)(`span`,{className:`text-white`,children:d.email})]}):(0,G.jsx)(`span`,{className:`text-white`,children:e(`profiles.orcaCloud.connectedShort`)})})]}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:()=>D.mutate(),disabled:D.isPending||!i,title:i?void 0:e(`profiles.orcaCloud.noLogoutPermission`),children:[(0,G.jsx)(il,{className:`w-4 h-4`}),e(`profiles.orcaCloud.logout`)]})]}),p?h?(0,G.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,G.jsx)(Y,{className:`w-8 h-8 text-bambu-green animate-spin`})}):v?(0,G.jsxs)(`div`,{className:`text-center py-16`,children:[(0,G.jsx)(`p`,{className:`text-bambu-gray mb-4`,children:v.message}),(0,G.jsx)(Q,{onClick:()=>g(),children:e(`profiles.orcaCloud.retry`)})]}):m?(0,G.jsx)(uKe,{settings:m,lastSyncTime:S,onRefresh:()=>g(),isRefreshing:_,printers:x,t:e}):null:(0,G.jsx)(mKe,{pairing:a,connectError:l,onConnect:()=>E.mutate(),onCancel:w,isStarting:E.isPending,canManage:i,t:e})]})}function mKe({pairing:e,connectError:t,onConnect:n,onCancel:r,isStarting:i,canManage:a,t:o}){return e?(0,G.jsx)(zd,{children:(0,G.jsxs)(Vd,{className:`p-8 text-center max-w-md mx-auto`,children:[(0,G.jsx)(Ps,{className:`w-12 h-12 text-bambu-green mx-auto mb-4`}),(0,G.jsx)(`h2`,{className:`text-xl font-bold text-white mb-2`,children:o(`profiles.orcaCloud.device.title`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray mb-6`,children:o(`profiles.orcaCloud.device.instruction`)}),(0,G.jsx)(`p`,{className:`text-xs uppercase tracking-wide text-bambu-gray mb-2`,children:o(`profiles.orcaCloud.device.codeLabel`)}),(0,G.jsx)(`div`,{className:`mb-6 py-3 px-4 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg`,children:(0,G.jsx)(`span`,{className:`text-2xl font-mono font-bold tracking-[0.3em] text-white select-all`,children:e.user_code})}),(0,G.jsx)(`a`,{href:e.verification_uri_complete,target:`_blank`,rel:`noopener noreferrer`,children:(0,G.jsxs)(Q,{className:`w-full mb-3`,children:[(0,G.jsx)(rc,{className:`w-4 h-4`}),o(`profiles.orcaCloud.device.openButton`)]})}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray break-all mb-6`,children:o(`profiles.orcaCloud.device.manualHint`,{url:e.verification_uri})}),(0,G.jsxs)(`div`,{className:`flex items-center justify-center gap-2 text-sm text-bambu-gray mb-4`,children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin text-bambu-green`}),o(`profiles.orcaCloud.device.waiting`)]}),(0,G.jsx)(`button`,{type:`button`,onClick:r,className:`text-bambu-gray hover:text-white text-sm`,children:o(`profiles.orcaCloud.device.cancel`)})]})}):(0,G.jsx)(zd,{children:(0,G.jsxs)(Vd,{className:`p-8 text-center`,children:[(0,G.jsx)(Ps,{className:`w-12 h-12 text-bambu-green mx-auto mb-4`}),(0,G.jsx)(`h2`,{className:`text-xl font-bold text-white mb-2`,children:o(`profiles.orcaCloud.connect.title`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray mb-6 max-w-xl mx-auto`,children:o(`profiles.orcaCloud.connect.description`)}),(0,G.jsxs)(`div`,{className:`max-w-sm mx-auto`,children:[(0,G.jsxs)(Q,{onClick:n,disabled:i||!a,title:a?void 0:o(`profiles.orcaCloud.noConnectPermission`),className:`w-full`,children:[i?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(fs,{className:`w-4 h-4`}),o(`profiles.orcaCloud.connectButton`)]}),t&&(0,G.jsxs)(`p`,{className:`mt-3 text-sm text-red-700 dark:text-red-400 flex items-center justify-center gap-2`,children:[(0,G.jsx)(ys,{className:`w-4 h-4 flex-shrink-0`}),t]})]})]})})}function v5(e,t){let n=`${e} ${t||``}`,r=n.match(/@?\s*(?:BBL\s+)?(?:Bambu\s+Lab\s+)?([XPAH][1-9][A-Z]?(?:\s*(?:Carbon|mini))?|H2D)/i),i=r?r[1].trim():null,a=n.match(/(\d+\.?\d*)\s*(?:mm\s*)?nozzle|nozzle\s*(\d+\.?\d*)/i),o=a?(a[1]||a[2])+`mm`:null,s=n.match(/(\d+\.?\d*)mm\s*(?:Standard|Fine|Extra Fine|Draft|Quality)?/i),c=s?s[1]+`mm`:null,l=n.match(/\b(PLA|PETG|ABS|ASA|TPU|PC|PA|PVA|HIPS|PP|PET(?:-?CF)?|PA(?:-?CF)?|PLA(?:-?CF)?)\b/i);return{printer:i,nozzle:o,layerHeight:c,filamentType:l?l[1].toUpperCase():null}}function y5(e){return/^(P[FPM]US|PF\d|PP\d)/.test(e)}function hKe({onSuccess:e,t}){let{showToast:n}=qd(),[r,i]=(0,y.useState)(`email`),[a,o]=(0,y.useState)(``),[s,c]=(0,y.useState)(``),[l,u]=(0,y.useState)(``),[d,f]=(0,y.useState)(``),[p,m]=(0,y.useState)(`global`),[h,g]=(0,y.useState)(null),[_,v]=(0,y.useState)(null),[b,x]=(0,y.useState)(!1),S=q({mutationFn:()=>Z.cloudLogin(a,s,p),onSuccess:r=>{if(x(r.reason===`captcha`),r.success)n(t(`profiles.login.toast.loggedIn`)),e();else if(r.reason===`captcha`)return;else r.needs_verification?(g(r.verification_type||`email`),v(r.tfa_key||null),r.verification_type===`totp`?n(t(`profiles.login.toast.enterTotp`)):n(t(`profiles.login.toast.codeSent`)),i(`code`)):n(r.message,`error`)},onError:e=>{x(!1),n(e.message,`error`)}}),C=q({mutationFn:()=>Z.cloudVerify(a,l,_||void 0,p),onSuccess:r=>{x(r.reason===`captcha`),r.success?(n(t(`profiles.login.toast.loggedIn`)),e()):r.reason!==`captcha`&&n(r.message,`error`)},onError:e=>{x(!1),n(e.message,`error`)}}),w=q({mutationFn:()=>Z.cloudSetToken(d,p),onSuccess:()=>{n(t(`profiles.login.toast.tokenSet`)),e()},onError:e=>n(e.message,`error`)}),T=e=>{e.preventDefault(),r===`email`?S.mutate():r===`code`?C.mutate():r===`token`&&w.mutate()},E=S.isPending||C.isPending||w.isPending;return(0,G.jsx)(zd,{className:`max-w-md mx-auto`,children:(0,G.jsxs)(Vd,{children:[(0,G.jsxs)(`div`,{className:`text-center mb-6`,children:[(0,G.jsx)(`div`,{className:`inline-flex items-center justify-center w-12 h-12 rounded-xl bg-bambu-green/20 mb-3`,children:(0,G.jsx)(Ps,{className:`w-6 h-6 text-bambu-green`})}),(0,G.jsx)(`h2`,{className:`text-xl font-semibold text-white`,children:t(`profiles.login.title`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:t(`profiles.login.subtitle`)})]}),b&&r!==`token`&&(0,G.jsx)(`div`,{role:`alert`,className:`mb-4 p-3 rounded-lg border border-amber-500/40 bg-amber-500/10`,children:(0,G.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,G.jsx)(iu,{className:`w-4 h-4 text-amber-400 shrink-0 mt-0.5`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm font-medium text-amber-300`,children:t(`profiles.login.captchaTitle`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:t(`profiles.login.captchaBody`)}),(0,G.jsxs)(`button`,{type:`button`,onClick:()=>{x(!1),i(`token`)},className:`mt-2 text-xs text-bambu-green hover:underline flex items-center gap-1`,children:[(0,G.jsx)(Kc,{className:`w-3 h-3`}),t(`profiles.login.useToken`)]})]})]})}),(0,G.jsxs)(`form`,{onSubmit:T,className:`space-y-4`,children:[r===`email`&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:t(`profiles.login.email`)}),(0,G.jsx)(`input`,{type:`email`,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 placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none`,placeholder:`your@email.com`,required:!0})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:t(`profiles.login.password`)}),(0,G.jsx)(`input`,{type:`password`,value:s,onChange:e=>c(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none`,placeholder:`••••••••`,required:!0})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:t(`profiles.login.region`)}),(0,G.jsxs)(`select`,{value:p,onChange:e=>m(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,G.jsx)(`option`,{value:`global`,children:t(`profiles.login.regionGlobal`)}),(0,G.jsx)(`option`,{value:`china`,children:t(`profiles.login.regionChina`)})]})]})]}),r===`code`&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:t(h===`totp`?`profiles.login.totpCode`:`profiles.login.verificationCode`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:h===`totp`?t(`profiles.login.enterTotpHint`):t(`profiles.login.checkEmail`,{email:a})}),(0,G.jsx)(`input`,{type:`text`,value:l,onChange:e=>u(e.target.value.replace(/\D/g,``).slice(0,6)),className:`w-full px-3 py-3 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-center text-2xl tracking-widest font-mono focus:border-bambu-green focus:outline-none`,placeholder:`000000`,maxLength:6,required:!0})]}),r===`token`&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:t(`profiles.login.accessToken`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:t(`profiles.login.accessTokenHint`)}),(0,G.jsx)(`textarea`,{value:d,onChange:e=>f(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-xs font-mono placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none resize-none`,placeholder:`eyJ...`,rows:4,required:!0})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:t(`profiles.login.region`)}),(0,G.jsxs)(`select`,{value:p,onChange:e=>m(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,G.jsx)(`option`,{value:`global`,children:t(`profiles.login.regionGlobal`)}),(0,G.jsx)(`option`,{value:`china`,children:t(`profiles.login.regionChina`)})]})]})]}),(0,G.jsxs)(`div`,{className:`flex gap-2 max-[550px]:flex-wrap max-[550px]:items-center`,children:[r===`code`&&(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:()=>i(`email`),className:`flex-1`,children:t(`profiles.login.back`)}),(0,G.jsxs)(Q,{type:`submit`,disabled:E,className:`flex-1`,children:[E?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(rl,{className:`w-4 h-4`}),t(r===`email`?`profiles.login.loginButton`:r===`code`?`profiles.login.verifyButton`:`profiles.login.setTokenButton`)]})]}),r===`email`&&(0,G.jsx)(`div`,{className:`pt-4 border-t border-bambu-dark-tertiary`,children:(0,G.jsxs)(`button`,{type:`button`,onClick:()=>i(`token`),className:`text-sm text-bambu-gray hover:text-white flex items-center gap-2 transition-colors`,children:[(0,G.jsx)(Kc,{className:`w-4 h-4`}),t(`profiles.login.useToken`)]})}),r===`token`&&(0,G.jsx)(`div`,{className:`pt-4 border-t border-bambu-dark-tertiary`,children:(0,G.jsxs)(`button`,{type:`button`,onClick:()=>i(`email`),className:`text-sm text-bambu-gray hover:text-white flex items-center gap-2 transition-colors`,children:[(0,G.jsx)(rl,{className:`w-4 h-4`}),t(`profiles.login.useEmail`)]})})]})]})})}function b5({label:e,value:t,options:n,onChange:r}){let[i,a]=(0,y.useState)(!1),o=n.find(e=>e.value===t);return(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsxs)(`button`,{onClick:()=>a(!i),className:`flex items-center gap-2 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-sm text-white hover:border-bambu-gray-dark transition-colors`,children:[(0,G.jsxs)(`span`,{className:`text-bambu-gray`,children:[e,`:`]}),(0,G.jsx)(`span`,{children:o?.label||`All`}),(0,G.jsx)(ps,{className:`w-4 h-4 text-bambu-gray transition-transform ${i?`rotate-180`:``}`})]}),i&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`fixed inset-0 z-10`,onClick:()=>a(!1)}),(0,G.jsx)(`div`,{className:`absolute top-full left-0 mt-1 min-w-[160px] bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl z-20 py-1 max-h-60 overflow-y-auto`,children:n.map(e=>(0,G.jsxs)(`button`,{onClick:()=>{r(e.value),a(!1)},className:`w-full px-3 py-2 text-left text-sm flex items-center justify-between hover:bg-bambu-dark-tertiary transition-colors ${t===e.value?`text-bambu-green`:`text-white`}`,children:[(0,G.jsx)(`span`,{children:e.label}),e.count!==void 0&&(0,G.jsx)(`span`,{className:`text-bambu-gray text-xs`,children:e.count})]},e.value))})]})]})}function gKe(){let[e,t]=(0,y.useState)(!1);return(0,y.useEffect)(()=>{let e=()=>{t(window.scrollY>300)};return window.addEventListener(`scroll`,e),()=>window.removeEventListener(`scroll`,e)},[]),e?(0,G.jsx)(`button`,{onClick:()=>{window.scrollTo({top:0,behavior:`smooth`})},className:`fixed bottom-24 right-6 p-3 bg-bambu-green hover:bg-bambu-green-light text-white rounded-full shadow-lg shadow-bambu-green/25 transition-all z-40`,"aria-label":`Scroll to top`,children:(0,G.jsx)(Ho,{className:`w-5 h-5`})}):null}function x5({setting:e,onClick:t,onDuplicate:n,compareMode:r,isCompareSelected:i,compareIndex:a,compareDisabled:o,t:s}){let c=v5(e.name),l=y5(e.setting_id);return(0,G.jsxs)(`div`,{className:`flex items-center gap-2 group`,children:[(0,G.jsx)(`button`,{onClick:t,disabled:o,className:`flex-1 text-left px-3 py-2 rounded transition-colors ${i?`bg-blue-500/20 border border-blue-500/50`:o?`bg-bambu-dark/50 opacity-40 cursor-not-allowed`:`bg-bambu-dark hover:bg-bambu-dark-tertiary`} ${r&&!o?`cursor-pointer`:``}`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[i&&a!==void 0&&(0,G.jsx)(`span`,{className:`flex-shrink-0 w-5 h-5 rounded-full bg-blue-500 text-white text-xs flex items-center justify-center font-medium`,children:a+1}),!i&&l&&(0,G.jsx)(`span`,{className:`flex-shrink-0 w-1.5 h-1.5 rounded-full bg-bambu-green`,title:s(`profiles.presets.myPreset`)}),(0,G.jsx)(`span`,{className:`text-white text-sm truncate flex-1`,title:e.name,children:e.name}),c.filamentType&&e.type===`filament`&&(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:c.filamentType}),c.layerHeight&&e.type===`process`&&(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:c.layerHeight}),c.printer&&(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:c.printer})]})}),(0,G.jsx)(`button`,{onClick:e=>{e.stopPropagation(),n()},className:`can-hover:opacity-0 group-hover:opacity-100 focus-visible:opacity-100 text-bambu-gray hover:text-white transition-all p-1`,title:s(`profiles.presets.duplicate`),children:(0,G.jsx)(Vs,{className:`w-4 h-4`})})]})}function S5(e,t=0){let n=` `.repeat(t);if(e===null)return`null`;if(e===void 0)return`undefined`;if(typeof e==`string`){if(e.includes(`\\n`)||e.includes(` +`)),i(!0),setTimeout(()=>i(!1),2e3)},className:`flex items-center gap-2`,children:[(0,G.jsx)(Vs,{className:`w-4 h-4`}),n(r?`common.copied`:`common.copy`)]}),(0,G.jsx)(Q,{variant:`primary`,size:`sm`,onClick:t,className:`flex-1`,children:n(`settings.twoFa.savedCodes`)})]})]})}function FGe({onDone:e}){let{t}=U(),n=co(),{showToast:r}=qd(),[i,a]=(0,y.useState)(`qr`),[o,s]=(0,y.useState)(``),[c,l]=(0,y.useState)([]),[u,d]=(0,y.useState)(!1),{data:f,isLoading:p}=K({queryKey:[`totp-setup`],queryFn:()=>Z.setupTOTP(),staleTime:1/0}),m=q({mutationFn:e=>Z.enableTOTP(e),onSuccess:e=>{l(e.backup_codes),a(`backup`),n.invalidateQueries({queryKey:[`2fa-status`]})},onError:()=>r(t(`settings.twoFa.invalidCode`),`error`)});return p||!f?(0,G.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,G.jsx)(Hl,{className:`w-6 h-6 animate-spin text-bambu-green`})}):i===`qr`?(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsx)(`p`,{className:`text-bambu-gray-light text-sm`,children:t(`settings.twoFa.setupInstructions`)}),(0,G.jsx)(`div`,{className:`flex justify-center`,children:(0,G.jsx)(`img`,{src:`data:image/png;base64,${f.qr_code_b64}`,alt:`TOTP QR Code`,className:`w-48 h-48 rounded-lg`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mb-1`,children:t(`settings.twoFa.manualEntry`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 bg-bambu-dark-secondary rounded-lg px-3 py-2`,children:[(0,G.jsx)(`code`,{className:`text-white text-xs font-mono flex-1 break-all`,children:u?f.secret:`••••••••••••••••`}),(0,G.jsx)(`button`,{onClick:()=>d(!u),className:`text-bambu-gray hover:text-white`,children:u?(0,G.jsx)(ic,{className:`w-4 h-4`}):(0,G.jsx)(ac,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:()=>{navigator.clipboard.writeText(f.secret)},className:`text-bambu-gray hover:text-white`,children:(0,G.jsx)(Vs,{className:`w-4 h-4`})})]})]}),(0,G.jsx)(Q,{variant:`primary`,className:`w-full`,onClick:()=>a(`confirm`),children:t(`settings.twoFa.scannedContinue`)})]}):i===`confirm`?(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsx)(`p`,{className:`text-bambu-gray-light text-sm`,children:t(`settings.twoFa.enterCodeToConfirm`)}),(0,G.jsx)(R8,{value:o,onChange:s,placeholder:`000000`}),(0,G.jsxs)(`div`,{className:`flex gap-3`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>a(`qr`),className:`flex-1`,children:t(`common.back`)}),(0,G.jsx)(Q,{variant:`primary`,className:`flex-1`,disabled:o.length!==6||m.isPending,onClick:()=>m.mutate(o),children:m.isPending?t(`common.saving`):t(`settings.twoFa.activate`)})]})]}):(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsx)(`h3`,{className:`text-white font-medium`,children:t(`settings.twoFa.backupCodesTitle`)}),(0,G.jsx)(z8,{codes:c,onDone:e})]})}function IGe(){let{t:e}=U(),t=co(),{showToast:n}=qd(),{user:r}=Nd(),[i,a]=(0,y.useState)(!1),[o,s]=(0,y.useState)(!1),[c,l]=(0,y.useState)(!1),[u,d]=(0,y.useState)(``),[f,p]=(0,y.useState)(``),[m,h]=(0,y.useState)(null),[g,_]=(0,y.useState)(null),[v,b]=(0,y.useState)(``),[x,S]=(0,y.useState)(!1),[C,w]=(0,y.useState)(``),[T,E]=(0,y.useState)(!1),{data:D,isLoading:O}=K({queryKey:[`2fa-status`],queryFn:()=>Z.get2FAStatus()}),{data:k}=K({queryKey:[`oidc-links`],queryFn:()=>Z.getOIDCLinks()}),A=q({mutationFn:()=>Z.enableEmailOTP(),onSuccess:e=>{_(e.setup_token),n(e.message,`success`)},onError:t=>{let r=t.message??``;r.toLowerCase().includes(`smtp`)?n(e(`settings.twoFa.smtpRequired`),`error`):n(r,`error`)}}),j=q({mutationFn:()=>Z.confirmEnableEmailOTP(g,v),onSuccess:()=>{t.invalidateQueries({queryKey:[`2fa-status`]}),_(null),b(``),n(e(`settings.twoFa.emailOtpEnabled`),`success`)},onError:e=>n(e.message,`error`)}),M=q({mutationFn:e=>Z.disableEmailOTP(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`2fa-status`]}),S(!1),w(``),n(e(`settings.twoFa.emailOtpDisabled`),`success`)},onError:e=>n(e.message,`error`)}),N=q({mutationFn:e=>Z.disableTOTP(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`2fa-status`]}),s(!1),d(``),n(e(`settings.twoFa.totpDisabled`),`success`)},onError:()=>n(e(`settings.twoFa.invalidCode`),`error`)}),P=q({mutationFn:e=>Z.regenerateBackupCodes(e),onSuccess:e=>{t.invalidateQueries({queryKey:[`2fa-status`]}),l(!1),p(``),h(e.backup_codes)},onError:()=>n(e(`settings.twoFa.invalidCode`),`error`)}),F=q({mutationFn:e=>Z.deleteOIDCLink(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`oidc-links`]}),n(e(`settings.twoFa.oidcUnlinked`),`success`)},onError:e=>n(e.message,`error`)});if(O)return(0,G.jsx)(`div`,{className:`flex items-center justify-center py-12`,children:(0,G.jsx)(Hl,{className:`w-6 h-6 animate-spin text-bambu-green`})});let I=!!r?.email;return(0,G.jsxs)(`div`,{className:`space-y-6`,children:[(0,G.jsxs)(zd,{id:`card-2fa-totp`,children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`w-10 h-10 rounded-full flex items-center justify-center ${D?.totp_enabled?`bg-green-100 dark:bg-green-500/20`:`bg-gray-500/20`}`,children:(0,G.jsx)(mu,{className:`w-5 h-5 ${D?.totp_enabled?`text-green-600 dark:text-green-400`:`text-gray-400`}`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`text-white font-semibold`,children:e(`settings.twoFa.totpTitle`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-sm`,children:e(`settings.twoFa.totpDesc`)})]}),(0,G.jsx)(`div`,{className:`ml-auto`,children:D?.totp_enabled?(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-green-700 dark:text-green-400 text-sm font-medium`,children:[(0,G.jsx)(au,{className:`w-4 h-4`}),` `,e(`common.enabled`)]}):(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-bambu-gray text-sm`,children:[(0,G.jsx)(ou,{className:`w-4 h-4`}),` `,e(`common.disabled`)]})})]})}),(0,G.jsx)(Vd,{children:i?(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,G.jsx)(`h4`,{className:`text-white font-medium`,children:e(`settings.twoFa.setupAuthApp`)}),(0,G.jsx)(`button`,{onClick:()=>{a(!1),t.removeQueries({queryKey:[`totp-setup`]})},className:`text-bambu-gray hover:text-white`,children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]}),(0,G.jsx)(FGe,{onDone:()=>{a(!1),t.removeQueries({queryKey:[`totp-setup`]})}})]}):o?(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsx)(`p`,{className:`text-bambu-gray-light text-sm`,children:e(`settings.twoFa.disableConfirmHint`)}),(0,G.jsx)(R8,{value:u,onChange:d,placeholder:`000000 or XXXXXXXX`,maxLength:8}),(0,G.jsxs)(`div`,{className:`flex gap-3`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>{s(!1),d(``)},className:`flex-1`,children:e(`common.cancel`)}),(0,G.jsx)(Q,{variant:`danger`,className:`flex-1`,disabled:u.length<6||N.isPending,onClick:()=>N.mutate(u),children:N.isPending?e(`common.saving`):e(`settings.twoFa.disableTotp`)})]})]}):c?(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsx)(`p`,{className:`text-bambu-gray-light text-sm`,children:e(`settings.twoFa.regenBackupHint`)}),(0,G.jsx)(R8,{value:f,onChange:p,placeholder:`000000 or XXXXXXXX`,maxLength:8}),(0,G.jsxs)(`div`,{className:`flex gap-3`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>{l(!1),p(``)},className:`flex-1`,children:e(`common.cancel`)}),(0,G.jsx)(Q,{variant:`primary`,className:`flex-1`,disabled:f.length<6||P.isPending,onClick:()=>P.mutate(f),children:P.isPending?e(`common.saving`):e(`settings.twoFa.regenBackup`)})]})]}):m?(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsx)(`h4`,{className:`text-white font-medium`,children:e(`settings.twoFa.newBackupCodes`)}),(0,G.jsx)(z8,{codes:m,onDone:()=>h(null)})]}):(0,G.jsx)(`div`,{className:`space-y-3`,children:D?.totp_enabled?(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-bambu-gray-light`,children:[(0,G.jsx)(Kc,{className:`w-4 h-4`}),e(`settings.twoFa.backupCodesRemaining`,{count:D.backup_codes_remaining})]}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:()=>l(!0),className:`flex items-center gap-2`,children:[(0,G.jsx)(Hl,{className:`w-4 h-4`}),e(`settings.twoFa.regenBackup`)]}),(0,G.jsxs)(Q,{variant:`danger`,size:`sm`,onClick:()=>s(!0),className:`flex items-center gap-2`,children:[(0,G.jsx)(Pu,{className:`w-4 h-4`}),e(`settings.twoFa.disableTotp`)]})]}):(0,G.jsxs)(Q,{variant:`primary`,onClick:()=>a(!0),className:`flex items-center gap-2`,children:[(0,G.jsx)(mu,{className:`w-4 h-4`}),e(`settings.twoFa.setupTotp`)]})})})]}),(0,G.jsxs)(zd,{id:`card-2fa-emailotp`,children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`w-10 h-10 rounded-full flex items-center justify-center ${D?.email_otp_enabled?`bg-green-100 dark:bg-green-500/20`:`bg-gray-500/20`}`,children:(0,G.jsx)(al,{className:`w-5 h-5 ${D?.email_otp_enabled?`text-green-600 dark:text-green-400`:`text-gray-400`}`})}),(0,G.jsxs)(`div`,{className:`flex-1`,children:[(0,G.jsx)(`h3`,{className:`text-white font-semibold`,children:e(`settings.twoFa.emailOtpTitle`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-sm`,children:I?e(`settings.twoFa.emailOtpDesc`,{email:r?.email}):e(`settings.twoFa.emailOtpNoEmail`)})]}),(0,G.jsx)(`div`,{className:`ml-auto`,children:D?.email_otp_enabled?(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-green-700 dark:text-green-400 text-sm font-medium`,children:[(0,G.jsx)(au,{className:`w-4 h-4`}),` `,e(`common.enabled`)]}):(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-bambu-gray text-sm`,children:[(0,G.jsx)(ou,{className:`w-4 h-4`}),` `,e(`common.disabled`)]})})]})}),(0,G.jsx)(Vd,{children:I?g?(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsx)(`p`,{className:`text-bambu-gray-light text-sm`,children:e(`settings.twoFa.emailSetupEnterCode`)}),(0,G.jsx)(R8,{value:v,onChange:b,placeholder:`000000`}),(0,G.jsxs)(`div`,{className:`flex gap-3`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>{_(null),b(``)},className:`flex-1`,children:e(`common.cancel`)}),(0,G.jsx)(Q,{variant:`primary`,className:`flex-1`,disabled:v.length!==6||j.isPending,onClick:()=>j.mutate(),children:j.isPending?e(`common.saving`):e(`settings.twoFa.verifyAndEnable`)})]})]}):x?(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsx)(`p`,{className:`text-bambu-gray-light text-sm`,children:e(`settings.twoFa.emailDisablePasswordHint`)}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(`input`,{type:T?`text`:`password`,value:C,onChange:e=>w(e.target.value),placeholder:e(`settings.twoFa.passwordPlaceholder`),className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>E(!T),className:`absolute right-3 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white`,children:T?(0,G.jsx)(ic,{className:`w-5 h-5`}):(0,G.jsx)(ac,{className:`w-5 h-5`})})]}),(0,G.jsxs)(`div`,{className:`flex gap-3`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>{S(!1),w(``)},className:`flex-1`,children:e(`common.cancel`)}),(0,G.jsx)(Q,{variant:`danger`,className:`flex-1`,disabled:!C||M.isPending,onClick:()=>M.mutate(C),children:M.isPending?e(`common.saving`):e(`settings.twoFa.disableEmailOtp`)})]})]}):(0,G.jsx)(`div`,{className:`flex gap-3`,children:D?.email_otp_enabled?(0,G.jsxs)(Q,{variant:`danger`,size:`sm`,onClick:()=>S(!0),className:`flex items-center gap-2`,children:[(0,G.jsx)(Pu,{className:`w-4 h-4`}),e(`settings.twoFa.disableEmailOtp`)]}):(0,G.jsxs)(Q,{variant:`primary`,disabled:!I||A.isPending,onClick:()=>A.mutate(),className:`flex items-center gap-2`,children:[(0,G.jsx)(al,{className:`w-4 h-4`}),A.isPending?e(`common.saving`):e(`settings.twoFa.enableEmailOtp`)]})}):(0,G.jsx)(`p`,{className:`text-amber-700 dark:text-amber-400 text-sm`,children:e(`settings.twoFa.addEmailFirst`)})})]}),k&&k.length>0&&(0,G.jsxs)(zd,{id:`card-2fa-linked`,children:[(0,G.jsxs)(Bd,{children:[(0,G.jsx)(`h3`,{className:`text-white font-semibold`,children:e(`settings.twoFa.linkedAccounts`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-sm`,children:e(`settings.twoFa.linkedAccountsDesc`)})]}),(0,G.jsx)(Vd,{children:(0,G.jsx)(`div`,{className:`space-y-3`,children:k.map(e=>(0,G.jsxs)(`div`,{className:`flex items-center justify-between py-2 border-b border-bambu-dark-tertiary last:border-0`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white text-sm font-medium`,children:e.provider_name}),e.provider_email&&(0,G.jsx)(`p`,{className:`text-bambu-gray text-xs`,children:e.provider_email})]}),(0,G.jsx)(Q,{variant:`danger`,size:`sm`,onClick:()=>F.mutate(e.provider_id),disabled:F.isPending,children:(0,G.jsx)(Pu,{className:`w-4 h-4`})})]},e.id))})})]})]})}var LGe={name:``,issuer_url:``,client_id:``,client_secret:``,scopes:`openid email profile`,is_enabled:!0,auto_create_users:!1,auto_link_existing_accounts:!1,email_claim:`email`,require_email_verified:!0,icon_url:void 0,default_group_id:null,is_autologin:!1};function B8({initial:e,isEdit:t=!1,groups:n=[],onSave:r,onCancel:i,isPending:a}){let{t:o}=U(),[s,c]=(0,y.useState)(e),[l,u]=(0,y.useState)(!1),d=(e,t)=>c(n=>({...n,[e]:t})),f=`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors text-sm`,p=`block text-sm font-medium text-white mb-1`,m=()=>{let e={...s};t&&!l&&delete e.client_secret,r(e)},h=s.auto_link_existing_accounts===!0,g=s.require_email_verified??!0,_;return _=h?o(`settings.oidc.form.requireEmailVerifiedAutoLink`):g?o(`settings.oidc.form.requireEmailVerifiedDesc`):(0,G.jsx)(`span`,{className:`text-red-700 dark:text-red-400`,children:o(`settings.oidc.form.requireEmailVerifiedWarning`)}),(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:p,children:[o(`settings.oidc.form.name`),` `,(0,G.jsx)(`span`,{className:`text-red-700 dark:text-red-400`,children:`*`})]}),(0,G.jsx)(`input`,{className:f,value:s.name,onChange:e=>d(`name`,e.target.value),placeholder:`Google`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:p,children:[o(`settings.oidc.form.issuerUrl`),` `,(0,G.jsx)(`span`,{className:`text-red-700 dark:text-red-400`,children:`*`})]}),(0,G.jsx)(`input`,{className:f,value:s.issuer_url,onChange:e=>d(`issuer_url`,e.target.value),placeholder:`https://accounts.google.com`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:p,children:[o(`settings.oidc.form.clientId`),` `,(0,G.jsx)(`span`,{className:`text-red-700 dark:text-red-400`,children:`*`})]}),(0,G.jsx)(`input`,{className:f,value:s.client_id,onChange:e=>d(`client_id`,e.target.value),placeholder:`your-client-id`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:p,children:[o(`settings.oidc.form.clientSecret`),!t&&(0,G.jsx)(`span`,{className:`text-red-700 dark:text-red-400`,children:` *`}),t&&(0,G.jsxs)(`span`,{className:`text-bambu-gray text-xs ml-1`,children:[`(`,o(`settings.oidc.form.secretHint`),`)`]})]}),(0,G.jsx)(`input`,{className:f,type:`password`,value:l?s.client_secret:``,placeholder:t&&!l?`••••••••`:o(`settings.oidc.form.secretPlaceholder`),onChange:e=>{u(!0),d(`client_secret`,e.target.value)}})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:p,children:o(`settings.oidc.form.scopes`)}),(0,G.jsx)(`input`,{className:f,value:s.scopes,onChange:e=>d(`scopes`,e.target.value),placeholder:`openid email profile`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:p,children:o(`settings.oidc.form.iconUrl`)}),(0,G.jsx)(`input`,{className:f,value:s.icon_url??``,onChange:e=>d(`icon_url`,e.target.value===``?null:e.target.value),placeholder:`https://...`})]})]}),(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-6 pt-2`,children:[(0,G.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,G.jsx)(fH,{checked:s.is_enabled??!0,onChange:e=>d(`is_enabled`,e)}),(0,G.jsx)(`span`,{className:`text-white text-sm`,children:o(`settings.oidc.form.enabled`)})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,G.jsx)(fH,{checked:s.auto_create_users??!1,onChange:e=>d(`auto_create_users`,e)}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white text-sm`,children:o(`settings.oidc.form.autoCreate`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-xs`,children:o(`settings.oidc.form.autoCreateDesc`)})]})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer w-full`,children:[(0,G.jsx)(fH,{checked:s.auto_link_existing_accounts??!1,onChange:e=>d(`auto_link_existing_accounts`,e)}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white text-sm`,children:o(`settings.oidc.form.autoLink`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-xs`,children:o(`settings.oidc.form.autoLinkDesc`)})]})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer w-full`,children:[(0,G.jsx)(fH,{checked:g,onChange:e=>d(`require_email_verified`,e),disabled:h}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white text-sm`,children:o(`settings.oidc.form.requireEmailVerified`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-xs`,children:_})]})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer w-full`,children:[(0,G.jsx)(fH,{checked:s.is_autologin??!1,onChange:e=>d(`is_autologin`,e)}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white text-sm`,children:o(`settings.oidc.form.autologin`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-xs`,children:o(`settings.oidc.form.autologinDesc`)})]})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:p,children:o(`settings.oidc.form.emailClaim`)}),(0,G.jsx)(`input`,{className:f,value:s.email_claim,onChange:e=>d(`email_claim`,e.target.value||`email`),placeholder:o(`settings.oidc.form.emailClaimPlaceholder`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-xs mt-1`,children:o(`settings.oidc.form.emailClaimDesc`)}),h&&s.email_claim!==`email`&&(0,G.jsx)(`p`,{className:`text-yellow-700 dark:text-yellow-400 text-xs mt-1`,children:o(`settings.oidc.form.emailClaimCustomClaimAutoLinkWarning`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:p,children:o(`settings.oidc.form.defaultGroup`)}),(0,G.jsxs)(`select`,{className:f,value:s.default_group_id??``,onChange:e=>d(`default_group_id`,e.target.value?Number(e.target.value):null),children:[(0,G.jsx)(`option`,{value:``,children:o(`settings.oidc.form.defaultGroupViewersFallback`)}),n.map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-xs mt-1`,children:o(`settings.oidc.form.defaultGroupDesc`)})]}),(0,G.jsxs)(`div`,{className:`flex gap-3 pt-2`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:i,className:`flex-1`,children:o(`common.cancel`)}),(0,G.jsx)(Q,{variant:`primary`,className:`flex-1`,disabled:!s.name||!s.issuer_url||!s.client_id||!t&&!s.client_secret||t&&l&&!s.client_secret||a,onClick:m,children:o(a?`common.saving`:`common.save`)})]})]})}function RGe({provider:e}){let[t,n]=(0,y.useState)(!1);return e.has_icon&&!t?(0,G.jsx)(`img`,{src:Z.oidcProviderIconUrl(e.id),alt:e.name,className:`w-8 h-8 rounded object-contain`,onError:()=>n(!0)}):(0,G.jsx)(`div`,{className:`w-8 h-8 rounded-full bg-bambu-dark-tertiary flex items-center justify-center`,children:(0,G.jsx)(Ac,{className:`w-4 h-4 text-bambu-gray`})})}function zGe(){let{t:e}=U(),t=co(),{showToast:n}=qd(),[r,i]=(0,y.useState)(!1),[a,o]=(0,y.useState)(null),[s,c]=(0,y.useState)(null),{data:l,isLoading:u}=K({queryKey:[`oidc-providers-all`],queryFn:()=>Z.getOIDCProvidersAll()}),{data:d=[]}=K({queryKey:[`groups`],queryFn:()=>Z.getGroups()}),f=q({mutationFn:e=>Z.createOIDCProvider(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`oidc-providers-all`]}),i(!1),n(e(`settings.oidc.created`),`success`)},onError:e=>n(e.message,`error`)}),p=q({mutationFn:({id:e,data:t})=>Z.updateOIDCProvider(e,t),onSuccess:()=>{t.invalidateQueries({queryKey:[`oidc-providers-all`]}),o(null),n(e(`settings.oidc.updated`),`success`)},onError:e=>n(e.message,`error`)}),m=q({mutationFn:e=>Z.deleteOIDCProvider(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`oidc-providers-all`]}),c(null),n(e(`settings.oidc.deleted`),`success`)},onError:e=>n(e.message,`error`)}),h=q({mutationFn:e=>Z.refreshOIDCProviderIcon(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`oidc-providers-all`]}),t.invalidateQueries({queryKey:[`oidc-providers`]}),n(e(`settings.oidc.iconRefreshed`),`success`)},onError:t=>n(t.message||e(`settings.oidc.iconFetchFailed`),`error`)}),g=q({mutationFn:e=>Z.deleteOIDCProviderIcon(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`oidc-providers-all`]}),t.invalidateQueries({queryKey:[`oidc-providers`]}),n(e(`settings.oidc.iconRemoved`),`success`)},onError:e=>n(e.message,`error`)}),_=e=>p.mutate({id:e.id,data:{is_enabled:!e.is_enabled}});return u?(0,G.jsx)(`div`,{className:`flex items-center justify-center py-12`,children:(0,G.jsx)(Hl,{className:`w-6 h-6 animate-spin text-bambu-green`})}):(0,G.jsxs)(`div`,{className:`space-y-6`,children:[(0,G.jsxs)(zd,{id:`card-oidc`,children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`text-white font-semibold`,children:e(`settings.oidc.title`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-sm`,children:e(`settings.oidc.desc`)})]}),!r&&(0,G.jsxs)(Q,{variant:`primary`,size:`sm`,onClick:()=>i(!0),className:`flex items-center gap-2`,children:[(0,G.jsx)(Fl,{className:`w-4 h-4`}),e(`settings.oidc.addProvider`)]})]})}),r&&(0,G.jsx)(Vd,{children:(0,G.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary pt-4`,children:[(0,G.jsx)(`h4`,{className:`text-white font-medium mb-4`,children:e(`settings.oidc.newProvider`)}),(0,G.jsx)(B8,{initial:LGe,groups:d,onSave:e=>f.mutate(e),onCancel:()=>i(!1),isPending:f.isPending})]})})]}),l&&l.length===0&&!r&&(0,G.jsx)(zd,{id:`card-oidc-empty`,children:(0,G.jsx)(Vd,{children:(0,G.jsxs)(`div`,{className:`text-center py-8 space-y-3`,children:[(0,G.jsx)(Ac,{className:`w-12 h-12 text-bambu-gray mx-auto`}),(0,G.jsx)(`p`,{className:`text-bambu-gray`,children:e(`settings.oidc.empty`)}),(0,G.jsxs)(Q,{variant:`primary`,size:`sm`,onClick:()=>i(!0),className:`inline-flex items-center gap-2`,children:[(0,G.jsx)(Fl,{className:`w-4 h-4`}),e(`settings.oidc.addProvider`)]})]})})}),l?.map(t=>(0,G.jsxs)(zd,{children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(RGe,{provider:t}),(0,G.jsxs)(`div`,{className:`flex-1`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`h4`,{className:`text-white font-medium`,children:t.name}),t.is_enabled?(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-xs text-green-700 dark:text-green-400 bg-green-50 dark:bg-green-400/10 px-2 py-0.5 rounded-full`,children:[(0,G.jsx)(fs,{className:`w-3 h-3`}),` `,e(`common.enabled`)]}):(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-xs text-bambu-gray bg-bambu-dark-tertiary px-2 py-0.5 rounded-full`,children:[(0,G.jsx)(nd,{className:`w-3 h-3`}),` `,e(`common.disabled`)]}),t.is_env_managed&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-xs text-bambu-green`,children:[(0,G.jsx)(nl,{className:`w-3 h-3`}),` `,e(`settings.environmentManagedLabel`)]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1 text-bambu-gray text-xs mt-0.5`,children:[(0,G.jsx)(rc,{className:`w-3 h-3`}),(0,G.jsx)(`span`,{children:t.issuer_url})]})]}),(0,G.jsx)(`div`,{className:`flex items-center gap-2`,children:!t.is_env_managed&&(0,G.jsxs)(G.Fragment,{children:[t.icon_url&&(0,G.jsx)(Q,{variant:`secondary`,size:`sm`,onClick:()=>h.mutate(t.id),disabled:h.isPending,title:e(`settings.oidc.refreshIcon`),"data-testid":`refresh-icon-${t.id}`,children:(0,G.jsx)(Hl,{className:`w-4 h-4 ${h.isPending?`animate-spin`:``}`})}),t.has_icon&&(0,G.jsx)(Q,{variant:`secondary`,size:`sm`,onClick:()=>g.mutate(t.id),disabled:g.isPending,title:e(`settings.oidc.removeIcon`),"data-testid":`remove-icon-${t.id}`,children:(0,G.jsx)(Vc,{className:`w-4 h-4`})}),(0,G.jsx)(fH,{checked:t.is_enabled,onChange:()=>_(t),disabled:p.isPending}),(0,G.jsx)(Q,{variant:`secondary`,size:`sm`,onClick:()=>o(a===t.id?null:t.id),"data-testid":`edit-provider-${t.id}`,children:(0,G.jsx)(kl,{className:`w-4 h-4`})}),(0,G.jsx)(Q,{variant:`danger`,size:`sm`,onClick:()=>c(t),"data-testid":`delete-provider-${t.id}`,children:(0,G.jsx)(Pu,{className:`w-4 h-4`})})]})})]})}),a===t.id&&(0,G.jsx)(Vd,{children:(0,G.jsx)(`div`,{className:`border-t border-bambu-dark-tertiary pt-4`,children:(0,G.jsx)(B8,{isEdit:!0,groups:d,initial:{name:t.name,issuer_url:t.issuer_url,client_id:t.client_id,client_secret:``,scopes:t.scopes,is_enabled:t.is_enabled,auto_create_users:t.auto_create_users,auto_link_existing_accounts:t.auto_link_existing_accounts,email_claim:t.email_claim,require_email_verified:t.require_email_verified,icon_url:t.icon_url??void 0,default_group_id:t.default_group_id??null,is_autologin:t.is_autologin},onSave:e=>p.mutate({id:t.id,data:e}),onCancel:()=>o(null),isPending:p.isPending})})}),a!==t.id&&(0,G.jsx)(Vd,{children:(0,G.jsxs)(`dl`,{className:`grid grid-cols-2 sm:grid-cols-3 gap-x-6 gap-y-2 text-sm`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`dt`,{className:`text-bambu-gray`,children:e(`settings.oidc.form.clientId`)}),(0,G.jsx)(`dd`,{className:`text-white font-mono truncate`,children:t.client_id})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`dt`,{className:`text-bambu-gray`,children:e(`settings.oidc.form.scopes`)}),(0,G.jsx)(`dd`,{className:`text-white`,children:t.scopes})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`dt`,{className:`text-bambu-gray`,children:e(`settings.oidc.form.autoCreate`)}),(0,G.jsx)(`dd`,{className:t.auto_create_users?`text-green-700 dark:text-green-400`:`text-bambu-gray`,children:t.auto_create_users?e(`common.yes`):e(`common.no`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`dt`,{className:`text-bambu-gray`,children:e(`settings.oidc.form.autoLink`)}),(0,G.jsx)(`dd`,{className:t.auto_link_existing_accounts?`text-green-700 dark:text-green-400`:`text-bambu-gray`,children:t.auto_link_existing_accounts?e(`common.yes`):e(`common.no`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`dt`,{className:`text-bambu-gray`,children:e(`settings.oidc.form.emailClaim`)}),(0,G.jsx)(`dd`,{className:`text-white font-mono`,children:t.email_claim})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`dt`,{className:`text-bambu-gray`,children:e(`settings.oidc.form.requireEmailVerified`)}),(0,G.jsx)(`dd`,{className:t.require_email_verified?`text-green-700 dark:text-green-400`:`text-red-700 dark:text-red-400`,children:t.require_email_verified?e(`common.yes`):e(`common.no`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`dt`,{className:`text-bambu-gray`,children:e(`settings.oidc.form.defaultGroup`)}),(0,G.jsx)(`dd`,{className:`text-white`,children:t.default_group_id?d.find(e=>e.id===t.default_group_id)?.name??e(`settings.oidc.form.defaultGroupViewersFallback`):e(`settings.oidc.form.defaultGroupViewersFallback`)})]})]})})]},t.id)),s&&(0,G.jsx)(of,{title:e(`settings.oidc.deleteTitle`),message:e(`settings.oidc.deleteMessage`,{name:s.name}),confirmText:e(`common.delete`),variant:`danger`,onConfirm:()=>m.mutate(s.id),onCancel:()=>c(null)})]})}var V8=new Map;function H8(e){V8.set(e.anchor,e)}function BGe(){return Array.from(V8.values())}H8({labelKey:`settings.encryption.title`,labelFallback:`MFA Encryption Status`,tab:`users`,subTab:`security`,keywords:`mfa encryption status security backup totp oidc fernet`,anchor:`card-mfa-encryption`});function VGe(){let{t:e}=U(),{data:t,isLoading:n,isError:r,refetch:i}=K({queryKey:[`encryptionStatus`],queryFn:()=>Z.getEncryptionStatus(),refetchInterval:e=>{if(!e.state.error)return 3e4;let t=e.state.fetchFailureCount??0;return t<=3?Math.min(5e3*Math.max(1,t),3e4):!1}});if(n)return(0,G.jsxs)(zd,{id:`card-mfa-encryption`,"data-testid":`encryption-status-card`,children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(su,{className:`text-bambu-gray`,size:20}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold`,children:e(`settings.encryption.title`)})]})}),(0,G.jsx)(Vd,{children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray`,"data-testid":`encryption-loading`,children:[(0,G.jsx)(Y,{className:`animate-spin`,size:16}),(0,G.jsx)(`span`,{children:e(`common.loading`)})]})})]});if(r||!t)return(0,G.jsxs)(zd,{id:`card-mfa-encryption`,"data-testid":`encryption-status-card`,children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(su,{className:`text-bambu-gray`,size:20}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold`,children:e(`settings.encryption.title`)})]})}),(0,G.jsxs)(Vd,{children:[(0,G.jsx)(`div`,{className:`text-red-700 dark:text-red-400`,"data-testid":`encryption-error`,children:e(`common.errorLoading`)}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>i(),className:`mt-2 text-sm text-blue-700 dark:text-blue-400 underline hover:text-blue-800 dark:hover:text-blue-300`,"data-testid":`encryption-retry-button`,children:e(`common.retry`)})]})]});let a=t.legacy_plaintext_rows.oidc_providers+t.legacy_plaintext_rows.user_totp,o=t.encrypted_rows.oidc_providers+t.encrypted_rows.user_totp,s,c,l,u;t.decryption_broken?(s=`bg-red-100 dark:bg-red-500/20 border-red-400 dark:border-red-500/50 text-red-700 dark:text-red-400`,c=(0,G.jsx)(Ds,{className:`text-red-600 dark:text-red-400`,size:20}),l=e(`settings.encryption.decryptionBrokenTitle`),u=e(`settings.encryption.decryptionBrokenError`,{count:o})):t.key_source===`generated`?(s=`bg-amber-50 dark:bg-amber-500/10 border-amber-300 dark:border-amber-500/30 text-amber-700 dark:text-amber-400`,c=(0,G.jsx)(au,{className:`text-amber-600 dark:text-amber-400`,size:20}),l=e(`settings.encryption.enabledGenerated`),u=e(`settings.encryption.backupHint`)):a>0?(s=`bg-amber-50 dark:bg-amber-500/10 border-amber-300 dark:border-amber-500/30 text-amber-700 dark:text-amber-400`,c=(0,G.jsx)(Lu,{className:`text-amber-600 dark:text-amber-400`,size:20}),l=t.key_source===`env`?e(`settings.encryption.enabledFromEnv`):e(`settings.encryption.enabledFromFile`),u=e(`settings.encryption.legacyRowsWarning`,{count:a})):t.key_configured?(s=`bg-green-100 dark:bg-green-500/20 border-green-300 dark:border-green-500/30 text-green-700 dark:text-green-400`,c=(0,G.jsx)(au,{className:`text-green-600 dark:text-green-400`,size:20}),l=t.key_source===`env`?e(`settings.encryption.enabledFromEnv`):e(`settings.encryption.enabledFromFile`),u=e(`settings.encryption.allEncrypted`)):(s=`bg-gray-500/20 border-gray-500/30 text-gray-400`,c=(0,G.jsx)(ou,{className:`text-gray-400`,size:20}),l=e(`settings.encryption.notConfigured`),u=e(`settings.encryption.notConfiguredDesc`));let d=t.key_source===`generated`&&a>0;return(0,G.jsxs)(zd,{id:`card-mfa-encryption`,"data-testid":`encryption-status-card`,children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[c,(0,G.jsx)(`h2`,{className:`text-lg font-semibold`,children:e(`settings.encryption.title`)})]})}),(0,G.jsxs)(Vd,{children:[(0,G.jsxs)(`div`,{className:`p-3 border rounded-lg ${s}`,"data-testid":`encryption-status`,children:[(0,G.jsx)(`p`,{className:`font-medium mb-1`,children:l}),(0,G.jsx)(`p`,{className:`text-sm`,children:u})]}),d&&(0,G.jsx)(`div`,{className:`mt-2 p-3 border rounded-lg bg-amber-50 dark:bg-amber-500/10 border-amber-300 dark:border-amber-500/30 text-amber-700 dark:text-amber-400`,"data-testid":`encryption-legacy-warning`,children:(0,G.jsx)(`p`,{className:`text-sm`,children:e(`settings.encryption.legacyRowsWarning`,{count:a})})}),t.migration_error_count>0&&(0,G.jsx)(`div`,{className:`mt-2 p-3 border rounded-lg bg-amber-50 dark:bg-amber-500/10 border-amber-300 dark:border-amber-500/30 text-amber-700 dark:text-amber-400`,"data-testid":`encryption-migration-warning`,children:(0,G.jsx)(`p`,{className:`text-sm`,children:e(`settings.encryption.migrationErrorWarning`,{count:t.migration_error_count})})}),(0,G.jsxs)(`div`,{className:`mt-4 grid grid-cols-2 gap-4 text-sm`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-bambu-gray`,children:e(`settings.encryption.encryptedRowsLabel`)}),(0,G.jsxs)(`p`,{className:`font-medium`,children:[`OIDC: `,t.encrypted_rows.oidc_providers,` · TOTP: `,t.encrypted_rows.user_totp]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-bambu-gray`,children:e(`settings.encryption.legacyRowsLabel`)}),(0,G.jsxs)(`p`,{className:`font-medium`,children:[`OIDC: `,t.legacy_plaintext_rows.oidc_providers,` · TOTP: `,t.legacy_plaintext_rows.user_totp]})]})]})]})]})}var HGe={get:`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400 border-blue-300 dark:border-blue-500/30`,post:`bg-green-100 dark:bg-green-500/20 text-green-700 dark:text-green-400 border-green-300 dark:border-green-500/30`,put:`bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400 border-yellow-300 dark:border-yellow-500/30`,patch:`bg-orange-100 dark:bg-orange-500/20 text-orange-700 dark:text-orange-400 border-orange-300 dark:border-orange-500/30`,delete:`bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400 border-red-300 dark:border-red-500/30`};function UGe(e,t){let n=t.replace(`#/`,``).split(`/`),r=e;for(let e of n)r=r[e];return r}function U8(e,t,n=0){if(n>5)return`...`;if(t.$ref)return U8(e,UGe(e,t.$ref),n+1);if(t.allOf){let r={};for(let i of t.allOf){let t=U8(e,i,n+1);typeof t==`object`&&t&&Object.assign(r,t)}return r}if(t.example!==void 0)return t.example;if(t.default!==void 0)return t.default;switch(t.type){case`string`:return t.enum?t.enum[0]:`string`;case`integer`:case`number`:return 0;case`boolean`:return!1;case`array`:return t.items?[U8(e,t.items,n+1)]:[];case`object`:if(t.properties){let r={};for(let[i,a]of Object.entries(t.properties))r[i]=U8(e,a,n+1);return r}return{};default:return null}}function WGe({path:e,method:t,spec:n,schema:r,apiKey:i}){let[a,o]=(0,y.useState)(!1),[s,c]=(0,y.useState)({}),[l,u]=(0,y.useState)(``),[d,f]=(0,y.useState)(null),[p,m]=(0,y.useState)(!1),[h,g]=(0,y.useState)(!1);(0,y.useEffect)(()=>{if(a&&n.parameters){let e={};for(let t of n.parameters)t.schema?.default!==void 0&&(e[t.name]=String(t.schema.default));c(t=>({...e,...t}))}},[a,n.parameters]),(0,y.useEffect)(()=>{if(a&&n.requestBody?.content?.[`application/json`]?.schema&&!l){let e=n.requestBody.content[`application/json`].schema,t=U8(r,e);u(JSON.stringify(t,null,2))}},[a,n.requestBody,r,l]);let _=(()=>{let e=[];for(let t of n.parameters||[])if(t.in===`path`||t.required){let n=s[t.name];(n===void 0||n===``)&&e.push(t.name)}return e})(),v=async()=>{if(_.length>0){f({status:0,statusText:`Validation Error`,headers:{},body:`Missing required parameters: ${_.join(`, `)}`,duration:0});return}m(!0),f(null);try{let r=e,a=new URLSearchParams;for(let e of n.parameters||[]){let t=s[e.name];t!==void 0&&t!==``&&(e.in===`path`?r=r.replace(`{${e.name}}`,encodeURIComponent(t)):e.in===`query`&&a.append(e.name,t))}let o=a.toString(),c=`${r}${o?`?${o}`:``}`,u={"Content-Type":`application/json`};i&&(u[`X-API-Key`]=i);let d={method:t.toUpperCase(),headers:u};[`post`,`put`,`patch`].includes(t)&&l&&(d.body=l);let p=performance.now(),m=await fetch(c,d),h=Math.round(performance.now()-p),g={};m.headers.forEach((e,t)=>{g[t]=e});let _;_=m.headers.get(`content-type`)?.includes(`application/json`)?await m.json():await m.text(),f({status:m.status,statusText:m.statusText,headers:g,body:_,duration:h})}catch(e){f({status:0,statusText:`Network Error`,headers:{},body:e instanceof Error?e.message:`Unknown error`,duration:0})}finally{m(!1)}},b=async()=>{if(d){let e=typeof d.body==`string`?d.body:JSON.stringify(d.body,null,2);try{await navigator.clipboard.writeText(e),g(!0),setTimeout(()=>g(!1),2e3)}catch{let t=document.createElement(`textarea`);t.value=e,t.style.position=`fixed`,t.style.left=`-999999px`,document.body.appendChild(t),t.select(),document.execCommand(`copy`),document.body.removeChild(t),g(!0),setTimeout(()=>g(!1),2e3)}}},x=(n.parameters||[]).filter(e=>e.in===`path`),S=(n.parameters||[]).filter(e=>e.in===`query`),C=[`post`,`put`,`patch`].includes(t)&&n.requestBody;return(0,G.jsxs)(`div`,{className:`border border-bambu-dark-tertiary rounded-lg overflow-hidden`,children:[(0,G.jsxs)(`button`,{onClick:()=>o(!a),className:`w-full flex items-center gap-3 p-3 hover:bg-bambu-dark-tertiary/50 transition-colors text-left`,children:[a?(0,G.jsx)(ps,{className:`w-4 h-4 text-bambu-gray flex-shrink-0`}):(0,G.jsx)(ms,{className:`w-4 h-4 text-bambu-gray flex-shrink-0`}),(0,G.jsx)(`span`,{className:`px-2 py-0.5 text-xs font-mono font-semibold uppercase rounded border ${HGe[t]||`bg-gray-500/20 text-gray-400`}`,children:t}),(0,G.jsx)(`code`,{className:`text-sm text-white font-mono flex-1 truncate`,children:e}),n.summary&&(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray truncate max-w-[40%]`,children:n.summary})]}),a&&(0,G.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary p-4 space-y-4 bg-bambu-dark/50`,children:[n.description&&(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n.description}),x.length>0&&(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`h4`,{className:`text-sm font-medium text-white`,children:`Path Parameters`}),(0,G.jsx)(`div`,{className:`space-y-2`,children:x.map(e=>(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`label`,{className:`text-sm text-bambu-gray w-32 flex-shrink-0`,children:[e.name,e.required&&(0,G.jsx)(`span`,{className:`text-red-700 dark:text-red-400 ml-1`,children:`*`})]}),(0,G.jsx)(`input`,{type:`text`,value:s[e.name]||``,onChange:t=>c(n=>({...n,[e.name]:t.target.value})),placeholder:e.description||e.schema?.type||`value`,className:`flex-1 px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm font-mono focus:border-bambu-green focus:outline-none`})]},e.name))})]}),S.length>0&&(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`h4`,{className:`text-sm font-medium text-white`,children:`Query Parameters`}),(0,G.jsx)(`div`,{className:`space-y-2`,children:S.map(e=>(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`label`,{className:`text-sm text-bambu-gray w-32 flex-shrink-0`,children:[e.name,e.required&&(0,G.jsx)(`span`,{className:`text-red-700 dark:text-red-400 ml-1`,children:`*`})]}),e.schema?.enum?(0,G.jsxs)(`select`,{value:s[e.name]||``,onChange:t=>c(n=>({...n,[e.name]:t.target.value})),className:`flex-1 px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`,children:[(0,G.jsx)(`option`,{value:``,children:`-- Select --`}),e.schema.enum.map(e=>(0,G.jsx)(`option`,{value:e,children:e},e))]}):(0,G.jsx)(`input`,{type:`text`,value:s[e.name]||``,onChange:t=>c(n=>({...n,[e.name]:t.target.value})),placeholder:e.description||e.schema?.type||`value`,className:`flex-1 px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm font-mono focus:border-bambu-green focus:outline-none`})]},e.name))})]}),C&&(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`h4`,{className:`text-sm font-medium text-white`,children:`Request Body`}),(0,G.jsx)(`textarea`,{value:l,onChange:e=>u(e.target.value),rows:8,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm font-mono focus:border-bambu-green focus:outline-none resize-y`,placeholder:`JSON request body...`})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(Q,{onClick:v,disabled:p,children:[p?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Nl,{className:`w-4 h-4`}),`Execute`]}),_.length>0&&(0,G.jsxs)(`span`,{className:`text-xs text-yellow-700 dark:text-yellow-400 flex items-center gap-1`,children:[(0,G.jsx)(ys,{className:`w-3 h-3`}),`Fill in: `,_.join(`, `)]})]}),d&&(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`h4`,{className:`text-sm font-medium text-white flex items-center gap-2`,children:[`Response`,(0,G.jsxs)(`span`,{className:`px-2 py-0.5 text-xs rounded ${d.status>=200&&d.status<300?`bg-green-100 dark:bg-green-500/20 text-green-700 dark:text-green-400`:d.status>=400?`bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400`:`bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400`}`,children:[d.status,` `,d.statusText]}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[d.duration,`ms`]})]}),(0,G.jsx)(Q,{variant:`secondary`,size:`sm`,onClick:b,children:h?(0,G.jsx)(xs,{className:`w-3 h-3 text-green-600 dark:text-green-400`}):(0,G.jsx)(Vs,{className:`w-3 h-3`})})]}),(0,G.jsx)(`pre`,{className:`p-3 bg-bambu-dark rounded-lg text-sm font-mono text-white overflow-auto max-h-96 border border-bambu-dark-tertiary`,children:typeof d.body==`string`?d.body:JSON.stringify(d.body,null,2)})]})]})]})}function GGe({apiKey:e=``}){let[t,n]=(0,y.useState)(null),[r,i]=(0,y.useState)(!0),[a,o]=(0,y.useState)(null),[s,c]=(0,y.useState)(new Set),[l,u]=(0,y.useState)(``);if((0,y.useEffect)(()=>{async function e(){try{let e=await fetch(`/openapi.json`);if(!e.ok)throw Error(`Failed to fetch OpenAPI schema`);n(await e.json())}catch(e){o(e instanceof Error?e.message:`Unknown error`)}finally{i(!1)}}e()},[]),r)return(0,G.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,G.jsx)(Y,{className:`w-8 h-8 text-bambu-green animate-spin`})});if(a||!t)return(0,G.jsx)(zd,{children:(0,G.jsx)(Vd,{className:`py-8`,children:(0,G.jsxs)(`div`,{className:`text-center text-red-700 dark:text-red-400`,children:[(0,G.jsx)(ys,{className:`w-12 h-12 mx-auto mb-3 opacity-50`}),(0,G.jsx)(`p`,{children:`Failed to load API schema`}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:a})]})})});let d={};for(let[e,n]of Object.entries(t.paths))for(let[t,r]of Object.entries(n)){if(t===`parameters`)continue;let n=r.tags||[`Other`];for(let i of n)d[i]||(d[i]=[]),d[i].push({path:e,method:t,spec:r})}let f=Object.entries(d).map(([e,t])=>l?{tag:e,endpoints:t.filter(({path:e,method:t,spec:n})=>{let r=l.toLowerCase();return e.toLowerCase().includes(r)||t.toLowerCase().includes(r)||(n.summary?.toLowerCase()||``).includes(r)||(n.description?.toLowerCase()||``).includes(r)})}:{tag:e,endpoints:t}).filter(({endpoints:e})=>e.length>0).sort((e,t)=>e.tag.localeCompare(t.tag)),p=e=>{c(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})};return(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,G.jsx)(`div`,{className:`flex-1`,children:(0,G.jsx)(`input`,{type:`text`,value:l,onChange:e=>u(e.target.value),placeholder:`Search endpoints...`,className:`w-full max-w-md px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Q,{variant:`secondary`,size:`sm`,onClick:()=>{c(new Set(f.map(e=>e.tag)))},children:`Expand All`}),(0,G.jsx)(Q,{variant:`secondary`,size:`sm`,onClick:()=>{c(new Set)},children:`Collapse All`}),(0,G.jsxs)(`a`,{href:`/docs`,target:`_blank`,rel:`noopener noreferrer`,className:`flex items-center gap-1 text-sm text-bambu-green hover:underline`,children:[(0,G.jsx)(rc,{className:`w-4 h-4`}),`Swagger UI`]})]})]}),(0,G.jsxs)(`p`,{className:`text-sm text-bambu-gray`,children:[f.reduce((e,t)=>e+t.endpoints.length,0),` endpoints in `,f.length,` categories`]}),(0,G.jsx)(`div`,{className:`space-y-3`,children:f.map(({tag:n,endpoints:r})=>(0,G.jsxs)(zd,{children:[(0,G.jsx)(`button`,{onClick:()=>p(n),className:`w-full flex items-center justify-between p-4 hover:bg-bambu-dark-tertiary/30 transition-colors text-left`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[s.has(n)?(0,G.jsx)(ps,{className:`w-5 h-5 text-bambu-gray`}):(0,G.jsx)(ms,{className:`w-5 h-5 text-bambu-gray`}),(0,G.jsx)(`h3`,{className:`text-base font-semibold text-white capitalize`,children:n.replace(/-/g,` `)}),(0,G.jsx)(`span`,{className:`text-xs bg-bambu-dark-tertiary px-2 py-0.5 rounded-full text-bambu-gray`,children:r.length})]})}),s.has(n)&&(0,G.jsx)(Vd,{className:`pt-0 space-y-2`,children:r.map(({path:n,method:r,spec:i})=>(0,G.jsx)(WGe,{path:n,method:r,spec:i,schema:t,apiKey:e},`${r}-${n}`))})]},n))})]})}var KGe=[{id:`sidecar`,labelKey:`settings.sliceEngineSidecar`,descriptionKey:`settings.sliceEngineSidecarHint`,available:!0},{id:`browser`,labelKey:`settings.sliceEngineBrowser`,descriptionKey:`settings.sliceEngineBrowserHint`,available:!1}];function W8(){return KGe.filter(e=>e.available)}function qGe(){return W8().length>1}function G8(e){return W8().find(t=>t.id===e)?.id??`sidecar`}var JGe=[`general`,`plugs`,`sensors`,`notifications`,`queue`,`filament`,`network`,`apikeys`,`virtual-printer`,`spoolbuddy`,`failure-detection`,`users`,`backup`];H8({labelKey:`settings.general`,tab:`general`,keywords:`language date time format printer model printers cards`,anchor:`card-general`}),H8({labelKey:`settings.appearance`,tab:`general`,keywords:`theme dark light mode colors`,anchor:`card-appearance`}),H8({labelKey:`settings.archiveSettings`,tab:`general`,keywords:`archive auto save thumbnails captures`,anchor:`card-archive`}),H8({labelKey:`settings.camera`,tab:`general`,keywords:`camera external video stream`,anchor:`card-camera`}),H8({labelKey:`settings.costTracking`,tab:`general`,keywords:`currency filament cost energy kwh price`,anchor:`card-cost`}),H8({labelKey:`settings.fileManager`,tab:`general`,keywords:`file manager archive mode disk warning storage`,anchor:`card-filemanager`}),H8({labelKey:`settings.updates`,tab:`general`,keywords:`updates version firmware beta check`,anchor:`card-updates`}),H8({labelKey:`settings.dataManagement`,tab:`general`,keywords:`data reset clear logs notifications preferences`,anchor:`card-data`}),H8({labelKey:`settings.smartPlugs`,tab:`plugs`,keywords:`smart plug energy power automation tapo kasa tplink shelly`,anchor:`card-plugs`}),H8({labelKey:`haSensors.sectionTitle`,tab:`sensors`,keywords:`home assistant sensor printer temperature humidity alert notify block print`,anchor:`card-ha-sensors`}),H8({labelKey:`locationHaSensors.sectionTitle`,tab:`sensors`,keywords:`home assistant sensor location storage box temperature humidity battery alert notify`,anchor:`card-location-sensors`}),H8({labelKey:`settings.providers`,tab:`notifications`,keywords:`telegram discord email notification providers webhook`,anchor:`card-providers`}),H8({labelKey:`settings.messageTemplates`,tab:`notifications`,keywords:`message templates notification text edit`,anchor:`card-templates`}),H8({labelKey:`settings.defaultPrintOptions`,labelFallback:`Default Print Options`,tab:`queue`,keywords:`print bed leveling flow calibration vibration first layer timelapse`,anchor:`card-print-options`}),H8({labelKey:`settings.tempFanPresetsTitle`,labelFallback:`Temperature & Fan Presets`,tab:`queue`,keywords:`temperature fan presets nozzle bed chamber quick buttons popover`,anchor:`card-temp-fan-presets`}),H8({labelKey:`settings.staggeredStart`,labelFallback:`Staggered Start`,tab:`queue`,keywords:`staggered batch delay start queue group`,anchor:`card-staggered`}),H8({labelKey:`settings.plateClear`,labelFallback:`Plate-Clear Confirmation`,tab:`queue`,keywords:`plate clear confirm auto queue`,anchor:`card-plate`}),H8({labelKey:`settings.concurrentUploadsTitle`,labelFallback:`Concurrent Uploads`,tab:`queue`,keywords:`concurrent parallel upload transfer ftp queue slow farm simultaneous`,anchor:`card-concurrent-uploads`}),H8({labelKey:`settings.gcodeInjection`,labelFallback:`G-code Injection`,tab:`queue`,keywords:`gcode injection start end autoprint farmloop swapmod autoclear printflow`,anchor:`card-gcode`}),H8({labelKey:`settings.slicerCard`,labelFallback:`Slicer`,tab:`queue`,keywords:`slicer orcaslicer bambustudio orca bambu api sidecar url docker preferred`,anchor:`card-slicer`}),H8({labelKey:`settings.queueDrying`,tab:`queue`,keywords:`drying presets temperature time humidity ams`,anchor:`card-drying`}),H8({labelKey:`settings.filamentChecks`,tab:`filament`,keywords:`filament check warning runout remaining`,anchor:`card-filamentchecks`}),H8({labelKey:`settings.printModal`,tab:`filament`,keywords:`print modal custom mapping`,anchor:`card-printmodal`}),H8({labelKey:`settings.amsDisplayThresholds`,tab:`filament`,keywords:`ams humidity temperature threshold history retention`,anchor:`card-amsthresholds`}),H8({labelKey:`settings.externalUrl`,tab:`network`,keywords:`external url reverse proxy public notification link`,anchor:`card-externalurl`}),H8({labelKey:`settings.ftpRetry`,tab:`network`,keywords:`ftp retry upload retries backoff`,anchor:`card-ftpretry`}),H8({labelKey:`settings.homeAssistant`,tab:`network`,keywords:`home assistant ha hass mqtt integration`,anchor:`card-ha`}),H8({labelKey:`settings.mqttPublishing`,tab:`network`,keywords:`mqtt publish broker topic`,anchor:`card-mqtt`}),H8({labelKey:`settings.prometheusMetrics`,tab:`network`,keywords:`prometheus metrics grafana monitoring bearer token`,anchor:`card-prometheus`}),H8({labelKey:`settings.createNewApiKey`,tab:`apikeys`,keywords:`api key create permission scope`,anchor:`card-createapi`}),H8({labelKey:`settings.webhookEndpoints`,tab:`apikeys`,keywords:`webhook endpoint post http`,anchor:`card-webhooks`}),H8({labelKey:`settings.apiBrowser`,tab:`apikeys`,keywords:`api browser endpoint documentation test`,anchor:`card-apibrowser`}),H8({labelKey:`cameraTokens.title`,tab:`apikeys`,keywords:`camera token long-lived home assistant frigate kiosk stream`,anchor:`card-camera-tokens`}),H8({labelKey:`settings.tabs.virtualPrinter`,tab:`virtual-printer`,keywords:`virtual printer proxy archive slicer bambustudio orcaslicer ip bind`,anchor:`card-vp`}),H8({labelKey:`settings.tabs.spoolbuddy`,tab:`spoolbuddy`,keywords:`spoolbuddy device scale nfc rfid kiosk unregister`,anchor:`card-spoolbuddy`}),H8({labelKey:`settings.currentUser`,tab:`users`,subTab:`users`,keywords:`current user profile password change`,anchor:`card-currentuser`}),H8({labelKey:`settings.users`,tab:`users`,subTab:`users`,keywords:`users accounts list`,anchor:`card-users`}),H8({labelKey:`settings.groups`,tab:`users`,subTab:`users`,keywords:`groups roles permissions administrators operators viewers`,anchor:`card-groups`}),H8({labelKey:`settings.sessionPolicy.title`,labelFallback:`Session Policy`,tab:`users`,subTab:`users`,keywords:`session timeout expiry logout remember me jwt token lifetime`,anchor:`card-session-policy`}),H8({labelKey:`settings.email.smtpSettings`,labelFallback:`SMTP Configuration`,tab:`users`,subTab:`email`,keywords:`smtp email send server port password auth starttls ssl`,anchor:`card-smtp`}),H8({labelKey:`settings.ldap.title`,labelFallback:`LDAP Authentication`,tab:`users`,subTab:`ldap`,keywords:`ldap active directory ad authentication bind dn search base group mapping`,anchor:`card-ldap`}),H8({labelKey:`settings.tabs.backup`,tab:`backup`,keywords:`backup github restore download cloud sync profiles archives`,anchor:`card-backup`}),H8({labelKey:`externalLinks.sidebarLayout`,labelFallback:`Sidebar`,tab:`general`,keywords:`sidebar layout links pages hide show external custom navigation url add`,anchor:`card-sidebar-links`}),H8({labelKey:`settings.filamentTracking`,tab:`filament`,keywords:`spoolman filament tracking inventory sync remote integration`,anchor:`card-spoolman`}),H8({labelKey:`settings.catalog.spoolCatalog`,labelFallback:`Spool Catalog`,tab:`filament`,keywords:`spool catalog entries brand material reset import export`,anchor:`card-spool-catalog`}),H8({labelKey:`settings.colorCatalog.title`,labelFallback:`Color Catalog`,tab:`filament`,keywords:`color catalog hex swatch palette sync reset`,anchor:`card-color-catalog`}),H8({labelKey:`settings.tabs.failureDetection`,labelFallback:`Failure Detection`,tab:`failure-detection`,keywords:`failure detection ai ml obico spaghetti detect monitoring`,anchor:`card-fd-ml`}),H8({labelKey:`failureDetection.perPrinterTitle`,labelFallback:`Per-Printer Settings`,tab:`failure-detection`,keywords:`failure detection per printer enable per-printer sensitivity`,anchor:`card-fd-perprinter`}),H8({labelKey:`failureDetection.statusTitle`,labelFallback:`Detection Status`,tab:`failure-detection`,keywords:`failure detection status running connection`,anchor:`card-fd-status`}),H8({labelKey:`failureDetection.historyTitle`,labelFallback:`Detection History`,tab:`failure-detection`,keywords:`failure detection history log events`,anchor:`card-fd-history`}),H8({labelKey:`settings.email.advancedAuth`,labelFallback:`Advanced Email Authentication`,tab:`users`,subTab:`email`,keywords:`email authentication advanced password reset self-service forgot`,anchor:`card-email-advanced-auth`}),H8({labelKey:`settings.email.testConnection`,labelFallback:`Test SMTP Connection`,tab:`users`,subTab:`email`,keywords:`email smtp test connection send check`,anchor:`card-email-test`}),H8({labelKey:`settings.twoFa.totpTitle`,labelFallback:`Authenticator App (TOTP)`,tab:`users`,subTab:`twofa`,keywords:`two factor 2fa totp authenticator app google authy otp`,anchor:`card-2fa-totp`}),H8({labelKey:`settings.twoFa.emailOtpTitle`,labelFallback:`Email One-Time Codes`,tab:`users`,subTab:`twofa`,keywords:`two factor 2fa email otp one time code`,anchor:`card-2fa-emailotp`}),H8({labelKey:`settings.twoFa.linkedAccounts`,labelFallback:`Linked Accounts`,tab:`users`,subTab:`twofa`,keywords:`two factor 2fa linked accounts sso oidc provider google github`,anchor:`card-2fa-linked`}),H8({labelKey:`settings.oidc.title`,labelFallback:`Single Sign-On (OIDC)`,tab:`users`,subTab:`oidc`,keywords:`sso oidc openid single sign-on pocketid authentik keycloak google okta azure provider`,anchor:`card-oidc`}),H8({labelKey:`settings.ldap.serverConfig`,labelFallback:`LDAP Server Configuration`,tab:`users`,subTab:`ldap`,keywords:`ldap server url bind dn user search base group filter tls`,anchor:`card-ldap-server`}),H8({labelKey:`backup.githubBackup`,labelFallback:`GitHub Backup`,tab:`backup`,keywords:`github backup cloud remote sync profiles token`,anchor:`card-backup-github`}),H8({labelKey:`backup.history`,labelFallback:`Backup History`,tab:`backup`,keywords:`backup history log runs github commits`,anchor:`card-backup-history`}),H8({labelKey:`backup.localBackup`,labelFallback:`Local Backup`,tab:`backup`,keywords:`local backup download zip manual export`,anchor:`card-backup-local`}),H8({labelKey:`backup.scheduledBackup`,labelFallback:`Scheduled Backups`,tab:`backup`,keywords:`scheduled backup automatic hourly daily weekly retention local path`,anchor:`card-backup-scheduled`});var K8=20,YGe={database:`bg-blue-600`,library_files:`bg-green-500`,library_thumbnails:`bg-teal-500`,library_other:`bg-emerald-700`,archive_timelapses:`bg-red-500`,archive_thumbnails:`bg-amber-500`,archive_files:`bg-sky-500`,virtual_printer_uploads:`bg-purple-500`,virtual_printer_upload_cache:`bg-fuchsia-500`,virtual_printer_certs:`bg-violet-500`,virtual_printer_other:`bg-purple-700`,downloads:`bg-cyan-500`,plate_calibration:`bg-lime-500`,logs:`bg-orange-500`,other_data:`bg-yellow-500`},q8=[`bg-blue-500`,`bg-green-500`,`bg-yellow-500`,`bg-red-500`,`bg-orange-500`,`bg-teal-500`,`bg-cyan-500`,`bg-purple-500`],J8=(e,t)=>YGe[e]||q8[t%q8.length],Y8={temperature:0,humidity:1,battery:2};function XGe(e,t){return e?PT(e,t,{decimals:2}):null}function ZGe(){let e=co(),t=or(),[n,r]=Ri(),{t:i,i18n:a}=U(),{showToast:o}=qd(),{authEnabled:s,user:c,isAdmin:l,refreshAuth:u,hasPermission:d}=Nd(),{mode:f,resolvedMode:p,darkStyle:m,darkBackground:h,darkAccent:g,lightStyle:_,lightBackground:v,lightAccent:b,setMode:x,setDarkStyle:S,setDarkBackground:C,setDarkAccent:w,setLightStyle:T,setLightBackground:E,setLightAccent:D,progressInTitle:O,setProgressInTitle:k}=Id(),[A,j]=(0,y.useState)(null),[M,N]=(0,y.useState)({}),[P,F]=(0,y.useState)(!1),[I,L]=(0,y.useState)(null),[R,z]=(0,y.useState)(!1),[B,V]=(0,y.useState)(null),[ee,te]=(0,y.useState)(!1),[ne,re]=(0,y.useState)(null),[ie,ae]=(0,y.useState)(!1),{colorize:oe,aboveColor:se,belowColor:H,optimalColor:ce}=R6(),[le,ue]=(0,y.useState)(null),[de,fe]=(0,y.useState)(!1),[pe,me]=(0,y.useState)(null),[he,ge]=(0,y.useState)(null),[_e,ve]=(0,y.useState)(``),[ye,be]=(0,y.useState)(``),[xe,Se]=(0,y.useState)(!1),[Ce,we]=(0,y.useState)(!1),[Te,Ee]=(0,y.useState)(!1),[De,Oe]=(0,y.useState)(hm()),ke=n.get(`tab`),Ae=ke===`email`,[je,Me]=(0,y.useState)(Ae?`users`:ke&&JGe.includes(ke)?ke:`general`),[Ne,Pe]=(0,y.useState)(Ae?`email`:`users`),[Fe,Ie]=(0,y.useState)(ke===`queue`&&n.get(`sub`)===`pipelines`?`pipelines`:`dispatch`),Le=e=>{Me(e),e===`users`&&Pe(`users`),e===`queue`&&(Ie(`dispatch`),n.delete(`sub`)),e===`general`?n.delete(`tab`):n.set(`tab`,e),r(n,{replace:!0})},Re=e=>{Ie(e),e===`pipelines`?n.set(`sub`,`pipelines`):n.delete(`sub`),r(n,{replace:!0})},[ze,Be]=(0,y.useState)(!1),[Ve,He]=(0,y.useState)(``),[Ue,We]=(0,y.useState)({can_queue:!0,can_control_printer:!1,can_read_status:!0,can_manage_library:!0,can_manage_inventory:!0,can_manage_maintenance:!0,can_manage_archives:!0,can_manage_projects:!0,can_access_cloud:!1,can_update_energy_cost:!1}),[Ge,Ke]=(0,y.useState)(null),[qe,Je]=(0,y.useState)(!1),[Ye,Xe]=(0,y.useState)(null),[Ze,Qe]=(0,y.useState)(``),[$e,et]=(0,y.useState)(!1),[tt,nt]=(0,y.useState)(!1),[rt,it]=(0,y.useState)(null),[at,ot]=(0,y.useState)(!1),[st,ct]=(0,y.useState)(!1),[lt,ut]=(0,y.useState)(!1),[dt,ft]=(0,y.useState)({currentPassword:``,newPassword:``,confirmPassword:``}),[pt,mt]=(0,y.useState)(!1),[ht,gt]=(0,y.useState)(!1),[_t,vt]=(0,y.useState)(!1),[yt,bt]=(0,y.useState)(`local`),[xt,St]=(0,y.useState)(!1),[Ct,wt]=(0,y.useState)(null),[Tt,Et]=(0,y.useState)(null),[Dt,Ot]=(0,y.useState)(null),[At,jt]=(0,y.useState)(!1),[Mt,Nt]=(0,y.useState)({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]}),[Pt,Ft]=(0,y.useState)(null),[It,Lt]=(0,y.useState)(null),[Rt,zt]=(0,y.useState)(!1),[Bt,Vt]=(0,y.useState)({}),[Ht,Ut]=(0,y.useState)({}),Wt=e=>{Oe(e),hee(e),o(i(`settings.toast.settingsSaved`),`success`)},{data:Gt,isLoading:Kt}=K({queryKey:[`settings`],queryFn:Z.getSettings}),{data:qt,isLoading:Jt,isFetching:Yt}=K({queryKey:[`storage-usage`],queryFn:()=>Z.getStorageUsage(),enabled:je===`general`,staleTime:1/0,refetchInterval:!1,refetchOnWindowFocus:!1,refetchOnReconnect:!1}),Xt=async()=>{gt(!0);try{let t=await Z.getStorageUsage({refresh:!0});e.setQueryData([`storage-usage`],t)}catch(e){o(e instanceof Error?e.message:`Failed to refresh storage usage`,`error`)}finally{gt(!1)}},{data:Zt,isLoading:Qt}=K({queryKey:[`smart-plugs`],queryFn:Z.getSmartPlugs}),{data:$t,isLoading:en}=K({queryKey:[`smart-plugs-energy`,Zt?.map(e=>e.id)],queryFn:async()=>{if(!Zt||Zt.length===0)return null;let e=await Promise.all(Zt.filter(e=>e.enabled).map(async e=>{try{return{plug:e,status:await Z.getSmartPlugStatus(e.id)}}catch{return{plug:e,status:null}}})),t=0,n=0,r=0,i=0,a=0;for(let{plug:o,status:s}of e){let e=o.plug_type===`mqtt`&&s?.energy?.power!=null;(s?.reachable||e)&&(a++,s?.energy?.power!=null&&(t+=s.energy.power),s?.energy?.today!=null&&(n+=s.energy.today),s?.energy?.yesterday!=null&&(r+=s.energy.yesterday),s?.energy?.total!=null&&(i+=s.energy.total))}return{totalPower:t,totalToday:n,totalYesterday:r,totalLifetime:i,reachableCount:a,totalPlugs:Zt.filter(e=>e.enabled).length}},enabled:je===`plugs`&&!!Zt&&Zt.length>0,refetchInterval:je===`plugs`?1e4:!1}),{data:tn,isLoading:W}=K({queryKey:[`notification-providers`],queryFn:Z.getNotificationProviders}),{data:nn,isLoading:rn}=K({queryKey:[`api-keys`],queryFn:Z.getAPIKeys}),an=q({mutationFn:e=>Z.createAPIKey(e),onSuccess:t=>{Ke(t.key||null),Be(!1),He(``),e.invalidateQueries({queryKey:[`api-keys`]}),o(i(`settings.toast.apiKeyCreated`))},onError:e=>{o(`Failed to create API key: ${e.message}`,`error`)}}),on=q({mutationFn:e=>Z.deleteAPIKey(e),onSuccess:(t,n)=>{e.setQueryData([`api-keys`],e=>(e??[]).filter(e=>e.id!==n)),o(i(`settings.toast.apiKeyDeleted`))},onError:e=>{o(`Failed to delete API key: ${e.message}`,`error`)}}),{data:sn}=K({queryKey:[`printers`],queryFn:Z.getPrinters}),{data:cn}=K({queryKey:[`haSensors`],queryFn:()=>Z.getHASensors()}),{data:ln}=K({queryKey:[`locationHaSensors`],queryFn:()=>Z.getLocationHASensors()}),{data:un}=K({queryKey:v6,queryFn:Z.getLocations,enabled:je===`sensors`}),dn=Co({queries:(0,y.useMemo)(()=>Array.from(new Set((ln??[]).map(e=>e.location_id))),[ln]).map(e=>({queryKey:[`locationHaSensorReadings`,e],queryFn:()=>Z.getLocationHASensorReadings(e,!1),enabled:je===`sensors`,refetchInterval:je===`sensors`?(Gt?.location_sensor_poll_interval||120)*1e3:!1}))}),fn=(0,y.useMemo)(()=>{let e=new Map;for(let t of dn)for(let n of t.data??[])e.set(n.id,n);return e},[dn]),pn=q({mutationFn:async e=>{for(let t of e)await Z.deleteLocationHASensor(t)},onSuccess:()=>{o(i(`locationHaSensors.toast.deleted`),`success`)},onError:e=>{o(e.message,`error`)},onSettled:()=>{e.invalidateQueries({queryKey:[`locationHaSensors`]}),e.invalidateQueries({queryKey:[`locationHaSensorReadings`]}),ue(null)}}),mn=zf(sn?.length??0),{data:hn,isLoading:gn}=K({queryKey:[`notification-templates`],queryFn:Z.getNotificationTemplates}),{data:_n}=K({queryKey:[`virtual-printer-settings`],queryFn:Cd.getSettings,refetchInterval:1e4}),vn=_n?.status?.running??!1,{data:yn}=K({queryKey:[`spoolbuddy-devices`],queryFn:()=>Od.getDevices(),refetchInterval:15e3}),bn=yn?.length??0,xn=yn?.some(e=>e.online)??!1,{data:Sn}=K({queryKey:[`obico-status`],queryFn:Z.getObicoStatus,refetchInterval:15e3}),Cn=!!(Sn?.is_running&&Sn?.enabled),{data:wn}=K({queryKey:[`ffmpeg-status`],queryFn:Z.checkFfmpeg}),{data:Tn}=K({queryKey:[`version`],queryFn:Z.getVersion}),En=!s||d(`library:purge`),{data:Dn}=K({queryKey:[`library-trash-settings`],queryFn:()=>Z.getLibraryTrashSettings(),enabled:En}),On=q({mutationFn:e=>Z.updateLibraryTrashSettings(e),onSuccess:()=>{e.invalidateQueries({queryKey:[`library-trash-settings`]}),o(i(`settings.toast.settingsSaved`),`success`)},onError:e=>o(e.message||i(`libraryAutoPurge.saveFailed`),`error`)}),kn=e=>{Dn&&On.mutate({retention_days:Dn.retention_days,auto_purge_enabled:Dn.auto_purge_enabled,auto_purge_days:Dn.auto_purge_days,auto_purge_include_never_printed:Dn.auto_purge_include_never_printed,...e})},An=!s||d(`archives:purge`),{data:jn}=K({queryKey:[`archive-purge-settings`],queryFn:()=>Z.getArchivePurgeSettings(),enabled:An}),Mn=q({mutationFn:e=>Z.updateArchivePurgeSettings(e),onSuccess:()=>{e.invalidateQueries({queryKey:[`archive-purge-settings`]}),o(i(`settings.toast.settingsSaved`),`success`)},onError:e=>o(e.message||i(`archiveAutoPurge.saveFailed`),`error`)}),Nn=e=>{jn&&Mn.mutate({enabled:jn.enabled,days:jn.days,purge_stats:jn.purge_stats,...e})},{data:Pn,refetch:Fn,isRefetching:In}=K({queryKey:[`updateCheck`],queryFn:Z.checkForUpdates,enabled:Gt?.check_updates!==!1,staleTime:300*1e3}),{data:Ln,refetch:Rn}=K({queryKey:[`updateStatus`],queryFn:Z.getUpdateStatus,refetchInterval:e=>{let t=e.state.data;return t?.status===`downloading`||t?.status===`installing`?1e3:!1}}),{data:zn}=K({queryKey:[`mqtt-status`],queryFn:Z.getMQTTStatus,refetchInterval:je===`network`?5e3:!1}),{data:Bn}=K({queryKey:[`github-backup-status`],queryFn:Z.getGitHubBackupStatus}),{data:Vn}=K({queryKey:[`cloud-status`],queryFn:Z.getCloudStatus}),{data:Hn={advanced_auth_enabled:!1,smtp_configured:!1,local_login_enabled:!0,autologin_provider_id:null}}=K({queryKey:[`advancedAuthStatus`],queryFn:()=>Z.getAdvancedAuthStatus()}),{data:Un}=K({queryKey:[`ldapStatus`],queryFn:()=>Z.getLDAPStatus()}),{data:Wn}=K({queryKey:[`twoFAStatus`],queryFn:()=>Z.get2FAStatus()}),{data:Gn=[]}=K({queryKey:[`oidcProvidersAll`],queryFn:()=>Z.getOIDCProvidersAll(),enabled:l}),{data:Kn=[],isLoading:qn}=K({queryKey:[`users`],queryFn:()=>Z.getUsers(),enabled:s&&d(`users:read`)}),{data:Jn=[],isLoading:Yn}=K({queryKey:[`groups`],queryFn:()=>Z.getGroups(),enabled:s&&d(`groups:read`)}),Xn=q({mutationFn:e=>Z.createUser(e),onSuccess:()=>{e.invalidateQueries({queryKey:[`users`]}),e.invalidateQueries({queryKey:[`groups`]}),vt(!1),Nt({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]}),o(i(`settings.toast.userCreated`))},onError:e=>{o(e.message,`error`)}}),Zn=q({mutationFn:({id:e,data:t})=>Z.updateUser(e,t),onSuccess:()=>{e.invalidateQueries({queryKey:[`users`]}),e.invalidateQueries({queryKey:[`groups`]}),St(!1),wt(null),Nt({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]}),o(i(`settings.toast.userUpdated`))},onError:e=>{o(e.message,`error`)}}),Qn=q({mutationFn:({id:e,deleteItems:t})=>Z.deleteUser(e,t),onSuccess:()=>{e.invalidateQueries({queryKey:[`users`]}),o(i(`settings.toast.userDeleted`)),Et(null),Ot(null)},onError:e=>{o(e.message,`error`)}}),$n=q({mutationFn:e=>Z.resetUserPassword({user_id:e}),onSuccess:e=>{o(e.message,`success`)},onError:e=>{o(e.message,`error`)}}),er=async e=>{Et(e),jt(!0);try{Ot(await Z.getUserItemsCount(e))}catch{Ot({archives:0,queue_items:0,library_files:0})}finally{jt(!1)}},tr=q({mutationFn:e=>Z.deleteGroup(e),onSuccess:()=>{e.invalidateQueries({queryKey:[`groups`]}),o(i(`settings.toast.groupDeleted`))},onError:e=>{o(e.message,`error`)}}),nr=()=>{let e=Hn?.advanced_auth_enabled||!1;if(!Mt.username){o(i(`settings.toast.fillRequiredFields`),`error`);return}if(e&&!Mt.email){o(`Email is required when advanced authentication is enabled`,`error`);return}if(!e){if(!Mt.password){o(i(`settings.toast.fillRequiredFields`),`error`);return}if(Mt.password!==Mt.confirmPassword){o(i(`settings.toast.passwordsDoNotMatch`),`error`);return}let e=_6(Mt.password);if(e){o(i({tooShort:`settings.toast.passwordTooShort`,needsUppercase:`settings.toast.passwordNeedsUppercase`,needsLowercase:`settings.toast.passwordNeedsLowercase`,needsDigit:`settings.toast.passwordNeedsDigit`,needsSpecial:`settings.toast.passwordNeedsSpecial`}[e]),`error`);return}}Xn.mutate({username:Mt.username,password:e?void 0:Mt.password,email:Mt.email||void 0,role:Mt.role,group_ids:Mt.group_ids.length>0?Mt.group_ids:void 0})},rr=e=>{if(Mt.password){if(Mt.password!==Mt.confirmPassword){o(i(`settings.toast.passwordsDoNotMatch`),`error`);return}let e=_6(Mt.password);if(e){o(i({tooShort:`settings.toast.passwordTooShort`,needsUppercase:`settings.toast.passwordNeedsUppercase`,needsLowercase:`settings.toast.passwordNeedsLowercase`,needsDigit:`settings.toast.passwordNeedsDigit`,needsSpecial:`settings.toast.passwordNeedsSpecial`}[e]),`error`);return}}let t={username:Mt.username||void 0,password:Mt.password||void 0,email:Mt.email||void 0,role:Mt.role,group_ids:Mt.group_ids};t.password||delete t.password,Zn.mutate({id:e,data:t})},ir=e=>{wt(e.id),Nt({username:e.username,password:``,email:e.email||``,confirmPassword:``,role:e.role,group_ids:e.groups?.map(e=>e.id)||[]}),St(!0)},ar=e=>{Nt(t=>({...t,group_ids:t.group_ids.includes(e)?t.group_ids.filter(t=>t!==e):[...t.group_ids,e]}))},sr=q({mutationFn:Z.applyUpdate,onSuccess:e=>{e.is_ha_addon||e.is_docker||e.is_windows_installer?o(e.message,`error`):Rn()}}),[cr,lr]=(0,y.useState)(null),ur=q({mutationFn:Z.testAllNotificationProviders,onSuccess:t=>{lr(t),e.invalidateQueries({queryKey:[`notification-providers`]}),t.failed===0?o(`All ${t.tested} providers tested successfully!`,`success`):o(`${t.success}/${t.tested} providers succeeded`,t.failed>0?`error`:`success`)},onError:e=>{o(`Failed to test providers: ${e.message}`,`error`)}}),dr=q({mutationFn:async e=>{if(!Zt)return{success:0,failed:0};let t=Zt.filter(e=>e.enabled),n=await Promise.all(t.map(async t=>{try{return await Z.controlSmartPlug(t.id,e),{success:!0}}catch{return{success:!1}}}));return{success:n.filter(e=>e.success).length,failed:n.filter(e=>!e.success).length}},onSuccess:(t,n)=>{e.invalidateQueries({queryKey:[`smart-plugs`]}),e.invalidateQueries({queryKey:[`smart-plugs-energy`]}),t.failed===0?o(`All ${t.success} plugs turned ${n}`,`success`):o(`${t.success} plugs turned ${n}, ${t.failed} failed`,`error`)},onError:e=>{o(`Failed: ${e.message}`,`error`)}}),fr=(0,y.useRef)(null),pr=(0,y.useRef)(null),mr=(0,y.useRef)(!1),hr=(0,y.useRef)(!0),gr=(0,y.useRef)(null);(0,y.useEffect)(()=>{if(Gt&&!A){let e={...Gt,external_url:Gt.external_url||window.location.origin};gr.current=Gt,j(e),setTimeout(()=>{hr.current=!1},100)}},[Gt,A]),(0,y.useEffect)(()=>{let e=gr.current;if(!Gt||!A||!e||Gt===e)return;let t={};for(let n of Object.keys(Gt))Gt[n]!==e[n]&&A[n]===e[n]&&(t[n]=Gt[n]);gr.current=Gt,Object.keys(t).length>0&&j(e=>e&&{...e,...t})},[Gt,A]);let _r=q({mutationFn:Z.updateSettings,onSuccess:t=>{gr.current=t,e.setQueryData([`settings`],t),e.invalidateQueries({queryKey:[`archiveStats`]}),o(i(`settings.toast.settingsSaved`),`success`)},onError:e=>{o(`Failed to save: ${e.message}`,`error`)},onSettled:()=>{mr.current=!1}}),vr=q({mutationFn:({id:e,data:t})=>Z.updatePrinter(e,t),onSuccess:()=>{e.invalidateQueries({queryKey:[`printers`]}),o(i(`settings.toast.cameraSettingsSaved`),`success`)},onError:e=>{o(`Failed to update printer: ${e.message}`,`error`)}});(0,y.useEffect)(()=>{let e=gr.current;if(!(hr.current||!A||!Gt||!e)&&!(s&&!d(`settings:update`))&&(e.auto_archive!==A.auto_archive||e.save_thumbnails!==A.save_thumbnails||e.capture_finish_photo!==A.capture_finish_photo||(e.finish_photo_restore_plate??!0)!==(A.finish_photo_restore_plate??!0)||e.default_filament_cost!==A.default_filament_cost||e.currency!==A.currency||e.energy_cost_per_kwh!==A.energy_cost_per_kwh||e.energy_tracking_mode!==A.energy_tracking_mode||e.check_updates!==A.check_updates||(e.check_printer_firmware??!0)!==(A.check_printer_firmware??!0)||(e.include_beta_updates??!1)!==(A.include_beta_updates??!1)||(e.local_login_enabled??!0)!==(A.local_login_enabled??!0)||e.notification_language!==A.notification_language||(e.bed_cooled_threshold??35)!==(A.bed_cooled_threshold??35)||e.ams_humidity_good!==A.ams_humidity_good||e.ams_humidity_fair!==A.ams_humidity_fair||e.ams_temp_good!==A.ams_temp_good||e.ams_temp_fair!==A.ams_temp_fair||(e.ams_temp_alarm??null)!==(A.ams_temp_alarm??null)||e.ams_history_retention_days!==A.ams_history_retention_days||e.disable_filament_warnings!==A.disable_filament_warnings||e.prefer_lowest_filament!==A.prefer_lowest_filament||(e.queue_drying_enabled??!1)!==(A.queue_drying_enabled??!1)||(e.queue_drying_block??!1)!==(A.queue_drying_block??!1)||(e.ambient_drying_enabled??!1)!==(A.ambient_drying_enabled??!1)||(e.print_drying_enabled??!1)!==(A.print_drying_enabled??!1)||(e.drying_presets??``)!==(A.drying_presets??``)||(e.ams_humidity_thresholds??``)!==(A.ams_humidity_thresholds??``)||e.per_printer_mapping_expanded!==A.per_printer_mapping_expanded||e.date_format!==A.date_format||e.time_format!==A.time_format||e.default_printer_id!==A.default_printer_id||e.ftp_retry_enabled!==A.ftp_retry_enabled||e.ftp_retry_count!==A.ftp_retry_count||e.ftp_retry_delay!==A.ftp_retry_delay||e.ftp_timeout!==A.ftp_timeout||e.mqtt_enabled!==A.mqtt_enabled||e.mqtt_broker!==A.mqtt_broker||e.mqtt_port!==A.mqtt_port||e.mqtt_username!==A.mqtt_username||e.mqtt_password!==A.mqtt_password||e.mqtt_topic_prefix!==A.mqtt_topic_prefix||e.mqtt_use_tls!==A.mqtt_use_tls||e.external_url!==A.external_url||e.ha_enabled!==A.ha_enabled||e.ha_url!==A.ha_url||e.ha_token!==A.ha_token||(e.library_archive_mode??`ask`)!==(A.library_archive_mode??`ask`)||Number(e.library_disk_warning_gb??5)!==Number(A.library_disk_warning_gb??5)||(e.preferred_slicer??`bambu_studio`)!==(A.preferred_slicer??`bambu_studio`)||G8(e.slice_engine)!==G8(A.slice_engine)||(e.open_in_slicer??null)!==(A.open_in_slicer??null)||(e.use_slicer_api??!1)!==(A.use_slicer_api??!1)||(e.orcaslicer_api_url??``)!==(A.orcaslicer_api_url??``)||(e.slicer_stall_timeout_minutes??15)!==(A.slicer_stall_timeout_minutes??15)||(e.bambu_studio_api_url??``)!==(A.bambu_studio_api_url??``)||e.prometheus_enabled!==A.prometheus_enabled||e.prometheus_token!==A.prometheus_token||(e.user_notifications_enabled??!0)!==(A.user_notifications_enabled??!0)||(e.default_bed_levelling??`auto`)!==(A.default_bed_levelling??`auto`)||(e.default_flow_cali??`auto`)!==(A.default_flow_cali??`auto`)||(e.default_vibration_cali??!0)!==(A.default_vibration_cali??!0)||(e.default_layer_inspect??!1)!==(A.default_layer_inspect??!1)||(e.default_timelapse??!1)!==(A.default_timelapse??!1)||(e.default_nozzle_offset_cali??`auto`)!==(A.default_nozzle_offset_cali??`auto`)||(e.stagger_group_size??2)!==(A.stagger_group_size??2)||(e.stagger_interval_minutes??5)!==(A.stagger_interval_minutes??5)||(e.require_plate_clear??!1)!==(A.require_plate_clear??!1)||(e.queue_max_concurrent_uploads??4)!==(A.queue_max_concurrent_uploads??4)||(e.preheat_enabled??!1)!==(A.preheat_enabled??!1)||(e.preheat_filament_targets??``)!==(A.preheat_filament_targets??``)||(e.preheat_max_wait_seconds??900)!==(A.preheat_max_wait_seconds??900)||(e.preheat_soak_seconds??300)!==(A.preheat_soak_seconds??300)||(e.queue_keep_bed_warm??!1)!==(A.queue_keep_bed_warm??!1)||(e.queue_keep_warm_bed_temp??90)!==(A.queue_keep_warm_bed_temp??90)||(e.queue_keep_warm_max_minutes??120)!==(A.queue_keep_warm_max_minutes??120)||(e.nozzle_temp_presets??``)!==(A.nozzle_temp_presets??``)||(e.bed_temp_presets??``)!==(A.bed_temp_presets??``)||(e.chamber_temp_presets??``)!==(A.chamber_temp_presets??``)||(e.fan_speed_presets??``)!==(A.fan_speed_presets??``)||(e.session_max_hours??24)!==(A.session_max_hours??24)||(e.billing_enabled??!1)!==(A.billing_enabled??!1)||(e.printer_kill_switch_enabled??!1)!==(A.printer_kill_switch_enabled??!1)||(e.finance_budget_reset_day??1)!==(A.finance_budget_reset_day??1)||(e.finance_budget_reset_timezone??`UTC`)!==(A.finance_budget_reset_timezone??`UTC`))&&!mr.current)return fr.current&&clearTimeout(fr.current),fr.current=setTimeout(()=>{if(mr.current)return;mr.current=!0;let e={auto_archive:A.auto_archive,save_thumbnails:A.save_thumbnails,capture_finish_photo:A.capture_finish_photo,finish_photo_restore_plate:A.finish_photo_restore_plate??!0,default_filament_cost:A.default_filament_cost,currency:A.currency,energy_cost_per_kwh:A.energy_cost_per_kwh,energy_tracking_mode:A.energy_tracking_mode,check_updates:A.check_updates,check_printer_firmware:A.check_printer_firmware,include_beta_updates:A.include_beta_updates,local_login_enabled:A.local_login_enabled,notification_language:A.notification_language,bed_cooled_threshold:A.bed_cooled_threshold,ams_humidity_good:A.ams_humidity_good,ams_humidity_fair:A.ams_humidity_fair,ams_temp_good:A.ams_temp_good,ams_temp_fair:A.ams_temp_fair,ams_temp_alarm:A.ams_temp_alarm??null,ams_history_retention_days:A.ams_history_retention_days,disable_filament_warnings:A.disable_filament_warnings,prefer_lowest_filament:A.prefer_lowest_filament,queue_drying_enabled:A.queue_drying_enabled,queue_drying_block:A.queue_drying_block,ambient_drying_enabled:A.ambient_drying_enabled,print_drying_enabled:A.print_drying_enabled,drying_presets:A.drying_presets,ams_humidity_thresholds:A.ams_humidity_thresholds,per_printer_mapping_expanded:A.per_printer_mapping_expanded,date_format:A.date_format,time_format:A.time_format,default_printer_id:A.default_printer_id,ftp_retry_enabled:A.ftp_retry_enabled,ftp_retry_count:A.ftp_retry_count,ftp_retry_delay:A.ftp_retry_delay,ftp_timeout:A.ftp_timeout,mqtt_enabled:A.mqtt_enabled,mqtt_broker:A.mqtt_broker,mqtt_port:A.mqtt_port,mqtt_username:A.mqtt_username,mqtt_password:A.mqtt_password,mqtt_topic_prefix:A.mqtt_topic_prefix,mqtt_use_tls:A.mqtt_use_tls,external_url:A.external_url,ha_enabled:A.ha_enabled,ha_url:A.ha_url,ha_token:A.ha_token,library_archive_mode:A.library_archive_mode,library_disk_warning_gb:A.library_disk_warning_gb,preferred_slicer:A.preferred_slicer,slice_engine:A.slice_engine,open_in_slicer:A.open_in_slicer,use_slicer_api:A.use_slicer_api,orcaslicer_api_url:A.orcaslicer_api_url,slicer_stall_timeout_minutes:A.slicer_stall_timeout_minutes,bambu_studio_api_url:A.bambu_studio_api_url,prometheus_enabled:A.prometheus_enabled,prometheus_token:A.prometheus_token,user_notifications_enabled:A.user_notifications_enabled,default_bed_levelling:A.default_bed_levelling,default_flow_cali:A.default_flow_cali,default_vibration_cali:A.default_vibration_cali,default_layer_inspect:A.default_layer_inspect,default_timelapse:A.default_timelapse,default_nozzle_offset_cali:A.default_nozzle_offset_cali,stagger_group_size:A.stagger_group_size,stagger_interval_minutes:A.stagger_interval_minutes,require_plate_clear:A.require_plate_clear,queue_max_concurrent_uploads:A.queue_max_concurrent_uploads,preheat_enabled:A.preheat_enabled,preheat_filament_targets:A.preheat_filament_targets,preheat_max_wait_seconds:A.preheat_max_wait_seconds,preheat_soak_seconds:A.preheat_soak_seconds,queue_keep_bed_warm:A.queue_keep_bed_warm,queue_keep_warm_bed_temp:A.queue_keep_warm_bed_temp,queue_keep_warm_max_minutes:A.queue_keep_warm_max_minutes,nozzle_temp_presets:A.nozzle_temp_presets,bed_temp_presets:A.bed_temp_presets,chamber_temp_presets:A.chamber_temp_presets,fan_speed_presets:A.fan_speed_presets,session_max_hours:A.session_max_hours,billing_enabled:A.billing_enabled,printer_kill_switch_enabled:A.printer_kill_switch_enabled,finance_budget_reset_day:A.finance_budget_reset_day,finance_budget_reset_timezone:A.finance_budget_reset_timezone};_r.mutate(e)},500),()=>{fr.current&&clearTimeout(fr.current)}},[A,Gt,_r,s,d,o,i]);let yr=(0,y.useCallback)((e,t)=>{if(s&&!d(`settings:update`)){o(i(`settings.toast.noPermissionUpdate`),`error`);return}j(n=>n?{...n,[e]:t}:null)},[s,d,o,i]),br=async(e,t,n)=>{if(!t){o(i(`settings.toast.enterCameraUrl`),`error`);return}Ut(t=>({...t,[e]:!0})),Vt(t=>({...t,[e]:null}));try{let r=await Z.testExternalCamera(e,t,n);Vt(t=>({...t,[e]:r})),r.success?o(r.coalesced?i(`settings.toast.cameraConnectedCoalesced`,{resolution:r.resolution||``}):i(`settings.toast.cameraConnected`,{resolution:r.resolution||``}),`success`):o(r.error||i(`settings.toast.connectionFailed`),`error`)}catch(t){let n=t instanceof Error?t.message:i(`settings.toast.testFailed`);Vt(t=>({...t,[e]:{success:!1,error:n}})),o(n,`error`)}finally{Ut(t=>({...t,[e]:!1}))}},[xr,Sr]=(0,y.useState)({}),Cr=(0,y.useRef)({}),wr=(0,y.useRef)(new Set),[Tr,Er]=(0,y.useState)({}),Dr=(0,y.useRef)({}),Or=(0,y.useRef)(new Set);(0,y.useEffect)(()=>{if(sn){let e={},t={};sn.forEach(n=>{n.external_camera_url&&!wr.current.has(n.id)&&(e[n.id]=n.external_camera_url,wr.current.add(n.id)),n.external_camera_snapshot_url&&!Or.current.has(n.id)&&(t[n.id]=n.external_camera_snapshot_url,Or.current.add(n.id))}),Object.keys(e).length>0&&Sr(t=>({...t,...e})),Object.keys(t).length>0&&Er(e=>({...e,...t}))}},[sn]);let kr=(e,t)=>{Sr(n=>({...n,[e]:t})),Cr.current[e]&&clearTimeout(Cr.current[e]),Cr.current[e]=setTimeout(()=>{vr.mutate({id:e,data:{external_camera_url:t||null}})},800)},Ar=(e,t)=>{Er(n=>({...n,[e]:t})),Dr.current[e]&&clearTimeout(Dr.current[e]),Dr.current[e]=setTimeout(()=>{vr.mutate({id:e,data:{external_camera_snapshot_url:t||null}})},800)},jr=(e,t)=>{let n={};t.type!==void 0&&(n.external_camera_type=t.type||null),t.enabled!==void 0&&(n.external_camera_enabled=t.enabled),t.rotation!==void 0&&(n.camera_rotation=t.rotation),vr.mutate({id:e,data:n})};if(Kt||!A)return(0,G.jsx)(`div`,{className:`p-4 md:p-8 flex justify-center`,children:(0,G.jsx)(Y,{className:`w-8 h-8 text-bambu-green animate-spin`})});let Mr=BGe().map(e=>({...e,label:i(e.labelKey,e.labelFallback??e.labelKey)})),Nr=ye.trim().toLowerCase(),Pr=Nr?Mr.filter(e=>e.label.toLowerCase().includes(Nr)||e.keywords.toLowerCase().includes(Nr)).slice(0,8):[],Fr=e=>{Le(e.tab),e.subTab&&Pe(e.subTab),be(``),setTimeout(()=>{let t=document.getElementById(e.anchor);t&&(t.scrollIntoView({behavior:`smooth`,block:`start`}),t.classList.add(`ring-2`,`ring-bambu-green`),setTimeout(()=>t.classList.remove(`ring-2`,`ring-bambu-green`),1500))},50)},Ir=(A?.docker_compose_dir??``).trim()||(Pn?.compose_dir_detected??``),Lr=Ir?`cd ${/\s/.test(Ir)?`"${Ir}"`:Ir} && docker compose pull && docker compose up -d`:`docker compose pull && docker compose up -d`;return(0,G.jsx)(Rd,{density:`dense`,children:(0,G.jsxs)(`div`,{className:`p-4 md:p-8`,children:[(0,G.jsxs)(`div`,{className:`mb-4 flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3`,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)(ru,{className:`w-7 h-7 text-bambu-green`}),i(`settings.title`)]}),(0,G.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:i(`settings.configureBambuddy`)})]}),(0,G.jsxs)(`div`,{className:`relative sm:w-72`,children:[(0,G.jsx)(Ql,{className:`w-4 h-4 text-bambu-gray absolute left-3 top-1/2 -translate-y-1/2 pointer-events-none`}),(0,G.jsx)(`input`,{type:`text`,value:ye,onChange:e=>be(e.target.value),placeholder:i(`settings.searchPlaceholder`,`Search settings…`),className:`w-full pl-9 pr-8 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`}),ye&&(0,G.jsx)(`button`,{onClick:()=>be(``),className:`absolute right-2 top-1/2 -translate-y-1/2 p-1 text-bambu-gray hover:text-white`,"aria-label":`Clear`,children:(0,G.jsx)(nd,{className:`w-3.5 h-3.5`})}),Pr.length>0&&(0,G.jsx)(`div`,{className:`absolute top-full left-0 right-0 mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl z-30 overflow-hidden`,children:Pr.map(e=>(0,G.jsxs)(`button`,{onClick:()=>Fr(e),className:`w-full px-3 py-2 text-left hover:bg-bambu-dark-tertiary transition-colors border-b border-bambu-dark-tertiary last:border-b-0`,children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:e.label}),(0,G.jsxs)(`p`,{className:`text-xs text-bambu-gray`,children:[i(`settings.tabs.${e.tab===`virtual-printer`?`virtualPrinter`:e.tab===`failure-detection`?`failureDetection`:e.tab}`),e.subTab?` › ${i(`settings.tabs.${e.subTab}`,e.subTab)}`:``]})]},e.anchor))}),Nr&&Pr.length===0&&(0,G.jsx)(`div`,{className:`absolute top-full left-0 right-0 mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl z-30 p-3`,children:(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray italic`,children:i(`settings.noSearchResults`,`No matching settings.`)})})]})]}),(0,G.jsxs)(`div`,{className:`flex flex-col lg:flex-row gap-4 lg:gap-6`,children:[(0,G.jsxs)(`nav`,{className:`flex flex-wrap gap-1 border-b border-bambu-dark-tertiary lg:flex-col lg:flex-nowrap lg:gap-0 lg:border-b-0 lg:border-r lg:w-48 lg:flex-shrink-0 lg:self-start lg:sticky lg:top-4`,children:[(0,G.jsxs)(`button`,{onClick:()=>Le(`general`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${je===`general`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,G.jsx)(ru,{className:`w-4 h-4`}),i(`settings.tabs.general`)]}),(0,G.jsxs)(`button`,{onClick:()=>Le(`plugs`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${je===`plugs`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,G.jsx)(Pl,{className:`w-4 h-4`}),i(`settings.tabs.smartPlugs`),Zt&&Zt.length>0&&(0,G.jsx)(`span`,{className:`text-xs bg-bambu-dark-tertiary px-1.5 py-0.5 rounded-full`,children:Zt.length})]}),(0,G.jsxs)(`button`,{onClick:()=>Le(`sensors`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${je===`sensors`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,G.jsx)(Tc,{className:`w-4 h-4`}),i(`settings.tabs.sensors`),(cn?.length??0)+(ln?.length??0)>0&&(0,G.jsx)(`span`,{className:`text-xs bg-bambu-dark-tertiary px-1.5 py-0.5 rounded-full`,children:(cn?.length??0)+(ln?.length??0)})]}),(0,G.jsxs)(`button`,{onClick:()=>Le(`notifications`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${je===`notifications`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,G.jsx)(qo,{className:`w-4 h-4`}),i(`settings.tabs.notifications`),tn&&tn.length>0&&(0,G.jsx)(`span`,{className:`text-xs bg-bambu-dark-tertiary px-1.5 py-0.5 rounded-full`,children:tn.length})]}),(0,G.jsxs)(`button`,{onClick:()=>Le(`queue`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${je===`queue`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,G.jsx)(Qc,{className:`w-4 h-4`}),i(`settings.tabs.queue`,`Workflow`)]}),(0,G.jsxs)(`button`,{onClick:()=>Le(`filament`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${je===`filament`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,G.jsx)(Ws,{className:`w-4 h-4`}),i(`settings.tabs.filament`)]}),(0,G.jsxs)(`button`,{onClick:()=>Le(`network`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${je===`network`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,G.jsx)(Qu,{className:`w-4 h-4`}),i(`settings.tabs.network`),(0,G.jsx)(`span`,{className:`w-2 h-2 rounded-full ${zn?.enabled?`bg-green-400`:`bg-gray-500`}`})]}),(0,G.jsxs)(`button`,{onClick:()=>Le(`apikeys`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${je===`apikeys`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,G.jsx)(Kc,{className:`w-4 h-4`}),i(`settings.tabs.apiKeys`),nn&&nn.length>0&&(0,G.jsx)(`span`,{className:`text-xs bg-bambu-dark-tertiary px-1.5 py-0.5 rounded-full`,children:nn.length})]}),(0,G.jsxs)(`button`,{onClick:()=>Le(`virtual-printer`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${je===`virtual-printer`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,G.jsx)(Rl,{className:`w-4 h-4`}),i(`settings.tabs.virtualPrinter`),(0,G.jsx)(`span`,{className:`w-2 h-2 rounded-full ${vn?`bg-green-400`:`bg-gray-500`}`})]}),(0,G.jsxs)(`button`,{onClick:()=>Le(`spoolbuddy`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${je===`spoolbuddy`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,G.jsx)(Jl,{className:`w-4 h-4`}),i(`settings.tabs.spoolbuddy`),bn>0&&(0,G.jsx)(`span`,{className:`text-xs bg-bambu-dark-tertiary px-1.5 py-0.5 rounded-full`,children:bn}),(0,G.jsx)(`span`,{className:`w-2 h-2 rounded-full ${xn?`bg-green-400`:`bg-gray-500`}`})]}),(0,G.jsxs)(`button`,{onClick:()=>Le(`failure-detection`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${je===`failure-detection`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,G.jsx)(Yl,{className:`w-4 h-4`}),i(`settings.tabs.failureDetection`),(0,G.jsx)(`span`,{className:`w-2 h-2 rounded-full ${Cn?`bg-green-400`:`bg-gray-500`}`})]}),(0,G.jsxs)(`button`,{onClick:()=>Le(`users`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${je===`users`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,G.jsx)(Uu,{className:`w-4 h-4`}),i(`settings.tabs.users`),s&&(0,G.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-green-400`})]}),(0,G.jsxs)(`button`,{onClick:()=>Le(`backup`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${je===`backup`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,G.jsx)(Gs,{className:`w-4 h-4`}),i(`settings.tabs.backup`),(0,G.jsx)(`span`,{className:`w-2 h-2 rounded-full ${Vn?.is_authenticated&&Bn?.configured&&Bn?.enabled||Gt?.local_backup_enabled?`bg-green-400`:`bg-gray-500`}`})]})]}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[je===`general`&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`a`,{href:Bf(mn,`app-settings`),target:`_blank`,rel:`noopener noreferrer`,className:`group block mb-4 lg:mb-6 rounded-xl border border-bambu-green/30 bg-gradient-to-br from-bambu-green/15 via-bambu-green/5 to-transparent hover:border-bambu-green/50 hover:from-bambu-green/20 transition-colors`,children:(0,G.jsxs)(`div`,{className:`flex flex-col md:flex-row items-start md:items-center gap-4 p-4 md:p-5`,children:[(0,G.jsx)(`div`,{className:`p-3 rounded-lg bg-bambu-green/20 text-bambu-green flex-shrink-0`,children:mn===`business`?(0,G.jsx)(Qo,{className:`w-6 h-6`}):(0,G.jsx)(Rc,{className:`w-6 h-6`})}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`p`,{className:`text-base font-semibold text-white`,children:mn===`business`?i(`sponsors.businessTitle`,`Bambuddy for business`):i(`sponsors.sectionTitle`,`Independent & community-funded`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-0.5`,children:mn===`business`?i(`sponsors.businessTagline`,`You're running {{count}} printers. Priority support, commercial licensing and invoicing are available for teams and print farms.`,{count:sn?.length??0}):i(`sponsors.tagline`,`Bambuddy is free and stays that way because people choose to support it. No VC, no cloud lock-in.`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 px-4 py-2 rounded-lg bg-bambu-green/20 text-bambu-green group-hover:bg-bambu-green/30 text-sm font-medium whitespace-nowrap self-start md:self-auto`,children:[mn===`business`?i(`sponsors.businessCta`,`Bambuddy for business`):i(`sponsors.viewSupporters`,`View supporters`),(0,G.jsx)(rc,{className:`w-4 h-4`})]})]})}),(0,G.jsxs)(`div`,{className:`flex flex-col lg:flex-row gap-4 lg:gap-6`,children:[(0,G.jsxs)(`div`,{className:`space-y-3 flex-1 lg:max-w-xl`,children:[(0,G.jsxs)(zd,{id:`card-general`,children:[(0,G.jsx)(Bd,{children:(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(`settings.general`)})}),(0,G.jsxs)(Vd,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[(0,G.jsx)(Ac,{className:`w-4 h-4 inline mr-1`}),i(`settings.language`)]}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(`select`,{value:a.language,onChange:e=>{let t=e.target.value;if(s&&!d(`settings:update`)){o(i(`settings.toast.noPermissionUpdate`),`error`);return}a.changeLanguage(t),_r.mutate({language:t})},className:`w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer`,children:kt.map(e=>(0,G.jsxs)(`option`,{value:e.code,children:[e.nativeName,` (`,e.name,`)`]},e.code))}),(0,G.jsx)(ps,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.languageDescription`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.defaultView`)}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(`select`,{value:De,onChange:e=>Wt(e.target.value),className:`w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer`,children:mm.map(e=>(0,G.jsx)(`option`,{value:e.to,children:i(e.labelKey)},e.id))}),(0,G.jsx)(ps,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.defaultViewDescription`)})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.dateFormat`)}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsxs)(`select`,{value:A.date_format||`system`,onChange:e=>yr(`date_format`,e.target.value),className:`w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer`,children:[(0,G.jsx)(`option`,{value:`system`,children:i(`settings.systemDefault`)}),(0,G.jsx)(`option`,{value:`us`,children:i(`settings.dateFormatUs`)}),(0,G.jsx)(`option`,{value:`eu`,children:i(`settings.dateFormatEu`)}),(0,G.jsx)(`option`,{value:`iso`,children:i(`settings.dateFormatIso`)})]}),(0,G.jsx)(ps,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.timeFormat`)}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsxs)(`select`,{value:A.time_format||`system`,onChange:e=>yr(`time_format`,e.target.value),className:`w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer`,children:[(0,G.jsx)(`option`,{value:`system`,children:i(`settings.systemDefault`)}),(0,G.jsx)(`option`,{value:`12h`,children:i(`settings.timeFormat12`)}),(0,G.jsx)(`option`,{value:`24h`,children:i(`settings.timeFormat24`)})]}),(0,G.jsx)(ps,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.defaultPrinter`)}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsxs)(`select`,{value:A.default_printer_id??``,onChange:e=>yr(`default_printer_id`,e.target.value?Number(e.target.value):null),className:`w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer`,children:[(0,G.jsx)(`option`,{value:``,children:i(`settings.noDefaultPrinter`)}),sn?.map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),(0,G.jsx)(ps,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.defaultPrinterDescription`)})]})]})]}),(0,G.jsxs)(zd,{id:`card-appearance`,children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(wl,{className:`w-5 h-5`}),i(`settings.appearance`)]})}),(0,G.jsxs)(Vd,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,G.jsxs)(`label`,{className:`text-sm text-bambu-gray`,children:[i(`settings.theme`),`:`]}),(0,G.jsx)(`div`,{className:`flex gap-1`,children:[{id:`dark`,label:i(`settings.themeDark`)},{id:`light`,label:i(`settings.themeLight`)},{id:`system`,label:i(`settings.themeSystem`)}].map(({id:e,label:t})=>(0,G.jsx)(`button`,{onClick:()=>{x(e),o(i(`settings.toast.settingsSaved`),`success`)},className:`px-3 py-1 text-xs rounded-lg border transition-colors ${f===e?`border-bambu-green bg-bambu-green/10 text-bambu-green`:`border-gray-300 dark:border-bambu-dark-tertiary text-gray-500 dark:text-bambu-gray hover:text-gray-900 dark:hover:text-white cursor-pointer`}`,children:t},e))})]}),(0,G.jsxs)(`div`,{className:`space-y-3 p-4 rounded-lg border ${p===`dark`?`border-bambu-green bg-bambu-green/5`:`border-bambu-dark-tertiary`}`,children:[(0,G.jsxs)(`h3`,{className:`text-sm font-medium text-white flex items-center gap-2`,children:[i(`settings.darkMode`),p===`dark`&&(0,G.jsx)(`span`,{className:`text-xs text-bambu-green`,children:i(`settings.active`)})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-3 gap-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.background`)}),(0,G.jsxs)(`select`,{value:h,onChange:e=>{C(e.target.value),o(i(`settings.toast.settingsSaved`),`success`)},className:`w-full px-2 py-1.5 text-sm 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:`neutral`,children:i(`settings.bgNeutral`)}),(0,G.jsx)(`option`,{value:`warm`,children:i(`settings.bgWarm`)}),(0,G.jsx)(`option`,{value:`cool`,children:i(`settings.bgCool`)}),(0,G.jsx)(`option`,{value:`oled`,children:i(`settings.bgOled`)}),(0,G.jsx)(`option`,{value:`slate`,children:i(`settings.bgSlate`)}),(0,G.jsx)(`option`,{value:`forest`,children:i(`settings.bgForest`)})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.accent`)}),(0,G.jsxs)(`select`,{value:g,onChange:e=>{w(e.target.value),o(i(`settings.toast.settingsSaved`),`success`)},className:`w-full px-2 py-1.5 text-sm 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:`green`,children:i(`settings.accentGreen`)}),(0,G.jsx)(`option`,{value:`teal`,children:i(`settings.accentTeal`)}),(0,G.jsx)(`option`,{value:`blue`,children:i(`settings.accentBlue`)}),(0,G.jsx)(`option`,{value:`orange`,children:i(`settings.accentOrange`)}),(0,G.jsx)(`option`,{value:`purple`,children:i(`settings.accentPurple`)}),(0,G.jsx)(`option`,{value:`red`,children:i(`settings.accentRed`)})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.style`)}),(0,G.jsxs)(`select`,{value:m,onChange:e=>{S(e.target.value),o(i(`settings.toast.settingsSaved`),`success`)},className:`w-full px-2 py-1.5 text-sm 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:`classic`,children:i(`settings.styleClassic`)}),(0,G.jsx)(`option`,{value:`glow`,children:i(`settings.styleGlow`)}),(0,G.jsx)(`option`,{value:`vibrant`,children:i(`settings.styleVibrant`)})]})]})]})]}),(0,G.jsxs)(`div`,{className:`space-y-3 p-4 rounded-lg border ${p===`light`?`border-bambu-green bg-bambu-green/5`:`border-bambu-dark-tertiary`}`,children:[(0,G.jsxs)(`h3`,{className:`text-sm font-medium text-white flex items-center gap-2`,children:[i(`settings.lightMode`),p===`light`&&(0,G.jsx)(`span`,{className:`text-xs text-bambu-green`,children:i(`settings.active`)})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-3 gap-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.background`)}),(0,G.jsxs)(`select`,{value:v,onChange:e=>{E(e.target.value),o(i(`settings.toast.settingsSaved`),`success`)},className:`w-full px-2 py-1.5 text-sm 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:`neutral`,children:i(`settings.bgNeutral`)}),(0,G.jsx)(`option`,{value:`warm`,children:i(`settings.bgWarm`)}),(0,G.jsx)(`option`,{value:`cool`,children:i(`settings.bgCool`)})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.accent`)}),(0,G.jsxs)(`select`,{value:b,onChange:e=>{D(e.target.value),o(i(`settings.toast.settingsSaved`),`success`)},className:`w-full px-2 py-1.5 text-sm 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:`green`,children:i(`settings.accentGreen`)}),(0,G.jsx)(`option`,{value:`teal`,children:i(`settings.accentTeal`)}),(0,G.jsx)(`option`,{value:`blue`,children:i(`settings.accentBlue`)}),(0,G.jsx)(`option`,{value:`orange`,children:i(`settings.accentOrange`)}),(0,G.jsx)(`option`,{value:`purple`,children:i(`settings.accentPurple`)}),(0,G.jsx)(`option`,{value:`red`,children:i(`settings.accentRed`)})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.style`)}),(0,G.jsxs)(`select`,{value:_,onChange:e=>{T(e.target.value),o(i(`settings.toast.settingsSaved`),`success`)},className:`w-full px-2 py-1.5 text-sm 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:`classic`,children:i(`settings.styleClassic`)}),(0,G.jsx)(`option`,{value:`glow`,children:i(`settings.styleGlow`)}),(0,G.jsx)(`option`,{value:`vibrant`,children:i(`settings.styleVibrant`)})]})]})]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.themeToggleHint`)}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between pt-2 border-t border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.progressInTitle`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.progressInTitleDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:O,onChange:e=>{k(e.target.checked),o(i(`settings.toast.settingsSaved`),`success`)},className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]})]})]}),(0,G.jsxs)(zd,{id:`card-archive`,children:[(0,G.jsx)(Bd,{children:(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(`settings.archiveSettings`)})}),(0,G.jsxs)(Vd,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.autoArchivePrints`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.autoArchiveDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.auto_archive,onChange:e=>yr(`auto_archive`,e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.saveThumbnails`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.saveThumbnailsDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.save_thumbnails,onChange:e=>yr(`save_thumbnails`,e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.captureFinishPhoto`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.captureFinishPhotoDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.capture_finish_photo,onChange:e=>yr(`capture_finish_photo`,e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),A.capture_finish_photo&&(0,G.jsxs)(`div`,{className:`flex items-center justify-between pl-4 border-l-2 border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.finishPhotoRestorePlate`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.finishPhotoRestorePlateDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.finish_photo_restore_plate??!0,onChange:e=>yr(`finish_photo_restore_plate`,e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),A.capture_finish_photo&&wn&&!wn.installed&&(0,G.jsxs)(`div`,{className:`flex items-start gap-2 p-3 bg-yellow-500/10 border border-yellow-500/30 rounded-lg`,children:[(0,G.jsx)(Lu,{className:`w-5 h-5 text-yellow-500 flex-shrink-0 mt-0.5`}),(0,G.jsxs)(`div`,{className:`text-sm`,children:[(0,G.jsx)(`p`,{className:`text-yellow-500 font-medium`,children:i(`settings.ffmpegNotInstalled`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:i(`settings.ffmpegRequired`)})]})]}),An&&jn&&(0,G.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary pt-3 mt-3 space-y-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`archiveAutoPurge.enableLabel`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`archiveAutoPurge.enableDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:jn.enabled,onChange:e=>Nn({enabled:e.target.checked}),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`archiveAutoPurge.ageLabel`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`input`,{type:`number`,min:7,max:3650,disabled:!jn.enabled,value:jn.days,onChange:e=>Nn({days:Math.max(7,Math.min(3650,parseInt(e.target.value||`0`,10)||0))}),className:`w-24 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none disabled:opacity-50`}),(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:i(`archiveAutoPurge.days`)})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`archiveAutoPurge.ageDescription`)})]}),(0,G.jsxs)(`label`,{className:`flex items-start gap-2 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,disabled:!jn.enabled,checked:jn.purge_stats,onChange:e=>Nn({purge_stats:e.target.checked}),className:`mt-0.5 shrink-0 disabled:opacity-50`}),(0,G.jsxs)(`span`,{className:`text-sm`,children:[(0,G.jsx)(`span`,{className:`text-white block`,children:i(`archiveAutoPurge.purgeStatsLabel`)}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray block mt-0.5`,children:i(`archiveAutoPurge.purgeStatsDescription`)})]})]})]})]})]})]}),(0,G.jsxs)(`div`,{className:`space-y-3 flex-1 lg:max-w-md`,children:[(0,G.jsxs)(zd,{id:`card-camera`,children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(Gu,{className:`w-5 h-5 text-bambu-green`}),i(`settings.camera`)]})}),(0,G.jsx)(Vd,{className:`space-y-3`,children:(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`text-sm font-medium text-white mb-2`,children:i(`settings.externalCameras`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mb-3`,children:i(`settings.externalCamerasDescription`)}),sn&&sn.length>0?(0,G.jsx)(`div`,{className:`space-y-3`,children:sn.map(e=>(0,G.jsxs)(`div`,{className:`p-3 bg-bambu-dark rounded-lg`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,G.jsx)(`span`,{className:`text-white font-medium text-sm`,children:e.name}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:e.external_camera_enabled,onChange:t=>jr(e.id,{enabled:t.target.checked}),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green`})]})]}),e.external_camera_enabled&&(0,G.jsxs)(`div`,{className:`space-y-2 mt-2`,children:[(0,G.jsx)(`input`,{type:`text`,placeholder:e.external_camera_type===`usb`?i(`settings.cameraPlaceholderUsb`):i(`settings.cameraPlaceholderUrl`),value:xr[e.id]??e.external_camera_url??``,onChange:t=>kr(e.id,t.target.value),className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsxs)(`select`,{value:e.external_camera_type||`mjpeg`,onChange:t=>jr(e.id,{type:t.target.value}),className:`flex-1 px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`,children:[(0,G.jsx)(`option`,{value:`mjpeg`,children:i(`settings.cameraTypeMjpeg`)}),(0,G.jsx)(`option`,{value:`rtsp`,children:i(`settings.cameraTypeRtsp`)}),(0,G.jsx)(`option`,{value:`snapshot`,children:i(`settings.cameraTypeSnapshot`)}),(0,G.jsx)(`option`,{value:`usb`,children:i(`settings.cameraTypeUsb`)})]}),(0,G.jsx)(Q,{size:`sm`,variant:`secondary`,onClick:()=>br(e.id,xr[e.id]??e.external_camera_url??``,e.external_camera_type||`mjpeg`),disabled:Ht[e.id]||!(xr[e.id]??e.external_camera_url),children:Ht[e.id]?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):i(`settings.test`)})]}),Bt[e.id]&&(0,G.jsx)(`div`,{className:`text-xs flex items-center gap-1 ${Bt[e.id]?.success?`text-green-500`:`text-red-500`}`,children:Bt[e.id]?.success?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(xs,{className:`w-3 h-3`}),i(`settings.connected`),Bt[e.id]?.resolution&&` (${Bt[e.id]?.resolution})`]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Ds,{className:`w-3 h-3`}),Bt[e.id]?.error||i(`settings.toast.connectionFailed`)]})}),(e.external_camera_type===`mjpeg`||e.external_camera_type===`rtsp`||e.external_camera_type===`usb`)&&(0,G.jsxs)(`div`,{className:`space-y-1`,children:[(0,G.jsx)(`label`,{className:`text-xs text-bambu-gray`,children:i(`settings.cameraSnapshotUrl`,`Snapshot URL (optional)`)}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsx)(`input`,{type:`text`,placeholder:i(`settings.cameraSnapshotUrlPlaceholder`,`http://192.168.1.61:1984/api/frame.jpeg?src=printer`),value:Tr[e.id]??e.external_camera_snapshot_url??``,onChange:t=>Ar(e.id,t.target.value),className:`flex-1 px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`}),(0,G.jsx)(Q,{size:`sm`,variant:`secondary`,onClick:()=>br(e.id,Tr[e.id]??e.external_camera_snapshot_url??``,`snapshot`),disabled:Ht[e.id]||!(Tr[e.id]??e.external_camera_snapshot_url),children:Ht[e.id]?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):i(`settings.test`)})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray opacity-75`,children:i(`settings.cameraSnapshotUrlHelp`,`Single-frame URL used for notification thumbnails, finish photos, timelapse and plate detection. Leave blank to capture from the live stream above. Useful for go2rtc (/api/frame.jpeg) and IP cameras with a dedicated snapshot endpoint.`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`label`,{className:`text-xs text-bambu-gray`,children:i(`settings.cameraRotation`)}),(0,G.jsxs)(`select`,{value:e.camera_rotation||0,onChange:t=>jr(e.id,{rotation:parseInt(t.target.value)}),className:`px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-xs focus:border-bambu-green focus:outline-none`,children:[(0,G.jsx)(`option`,{value:0,children:`0°`}),(0,G.jsx)(`option`,{value:90,children:`90°`}),(0,G.jsx)(`option`,{value:180,children:`180°`}),(0,G.jsx)(`option`,{value:270,children:`270°`})]})]})]})]},e.id))}):(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray italic`,children:i(`settings.noPrintersConfigured`)})]})})]}),(0,G.jsxs)(zd,{id:`card-cost`,children:[(0,G.jsx)(Bd,{children:(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(`settings.costTracking`)})}),(0,G.jsxs)(Vd,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.currency`)}),(0,G.jsx)(`select`,{value:A.currency,onChange:e=>yr(`currency`,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:Rf.map(e=>(0,G.jsx)(`option`,{value:e.code,children:e.label},e.code))})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.defaultFilamentCost`)}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(`span`,{className:`absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray text-sm pointer-events-none`,children:Lf(A.currency)}),(0,G.jsx)(`input`,{type:`number`,step:`0.01`,min:`0`,value:A.default_filament_cost,onChange:e=>yr(`default_filament_cost`,parseFloat(e.target.value)||0),style:{paddingLeft:`${Math.max(2,Lf(A.currency).length*.6+1)}rem`},className:`w-full pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.electricityCost`)}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(`span`,{className:`absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray text-sm pointer-events-none`,children:Lf(A.currency)}),(0,G.jsx)(`input`,{type:`number`,step:`0.001`,min:`0`,value:A.energy_cost_per_kwh,onChange:e=>yr(`energy_cost_per_kwh`,parseFloat(e.target.value)||0),style:{paddingLeft:`${Math.max(2,Lf(A.currency).length*.6+1)}rem`},className:`w-full pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.energyDisplayMode`)}),(0,G.jsxs)(`select`,{value:A.energy_tracking_mode||`total`,onChange:e=>yr(`energy_tracking_mode`,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:`print`,children:i(`settings.printsOnly`)}),(0,G.jsx)(`option`,{value:`total`,children:i(`settings.totalConsumption`)})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:A.energy_tracking_mode===`print`?i(`settings.energyModePrintDescription`):i(`settings.energyModeTotalDescription`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.billingEnabled`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.billingEnabledDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.billing_enabled??!1,onChange:e=>yr(`billing_enabled`,e.target.checked),className:`peer sr-only`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary rounded-full peer-checked:bg-bambu-green peer-checked:after:translate-x-5 after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border after:rounded-full after:h-5 after:w-5 after:transition-all`})]})]}),A.billing_enabled&&(0,G.jsxs)(`div`,{className:`mt-4 flex items-center justify-between gap-4 rounded-lg border border-bambu-dark-tertiary bg-bambu-dark px-4 py-3`,children:[(0,G.jsxs)(`div`,{className:`flex-1`,children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.printerKillSwitch`,`Unauthorized print kill switch`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.printerKillSwitchDescription`,`Immediately stop prints that start without authorization.`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.printer_kill_switch_enabled??!1,onChange:e=>yr(`printer_kill_switch_enabled`,e.target.checked),className:`peer sr-only`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary rounded-full peer-checked:bg-bambu-green peer-checked:after:translate-x-5 after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border after:rounded-full after:h-5 after:w-5 after:transition-all`})]})]}),A.billing_enabled&&(0,G.jsxs)(`div`,{className:`mt-4 rounded-lg border border-bambu-dark-tertiary bg-bambu-dark p-4`,children:[(0,G.jsx)(`div`,{className:`mb-3`,children:(0,G.jsxs)(`h4`,{className:`text-base font-medium text-white flex items-center gap-2`,children:[(0,G.jsx)(as,{className:`w-4 h-4 text-bambu-green`}),i(`settings.financeBudgetReset`,`Finance Monthly Budget Reset`)]})}),(0,G.jsxs)(`div`,{className:`flex gap-4`,children:[(0,G.jsxs)(`div`,{className:`flex-1`,children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.financeBudgetResetDay`,`Reset Day`)}),(0,G.jsx)(`input`,{type:`number`,min:1,max:31,value:A.finance_budget_reset_day??1,onChange:e=>yr(`finance_budget_reset_day`,Math.max(1,Math.min(31,parseInt(e.target.value,10)||1))),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.financeBudgetResetDayHelp`,`For short months, reset uses the last day of the month.`)})]}),(0,G.jsxs)(`div`,{className:`flex-1`,children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.financeBudgetResetTimezone`,`Reset timezone`)}),(0,G.jsxs)(`select`,{value:A.finance_budget_reset_timezone??`UTC`,onChange:e=>yr(`finance_budget_reset_timezone`,e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`,children:[(0,G.jsx)(`option`,{value:`UTC`,children:`UTC`}),(0,G.jsx)(`option`,{value:`Europe/Berlin`,children:`Europe/Berlin`}),(0,G.jsx)(`option`,{value:`Europe/Vienna`,children:`Europe/Vienna`}),(0,G.jsx)(`option`,{value:`Europe/Zurich`,children:`Europe/Zurich`}),(0,G.jsx)(`option`,{value:`America/New_York`,children:`America/New_York`}),(0,G.jsx)(`option`,{value:`America/Chicago`,children:`America/Chicago`}),(0,G.jsx)(`option`,{value:`America/Denver`,children:`America/Denver`}),(0,G.jsx)(`option`,{value:`America/Los_Angeles`,children:`America/Los_Angeles`}),(0,G.jsx)(`option`,{value:`Asia/Tokyo`,children:`Asia/Tokyo`}),(0,G.jsx)(`option`,{value:`Asia/Singapore`,children:`Asia/Singapore`}),(0,G.jsx)(`option`,{value:`Australia/Sydney`,children:`Australia/Sydney`})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.financeBudgetResetTimezoneHelp`,`Budget window start is calculated in this timezone.`)})]})]})]}),A.billing_enabled&&l&&(0,G.jsxs)(`div`,{className:`mt-3`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>we(!0),disabled:Te,children:Te?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 mr-2 animate-spin`}),i(`settings.rebuildLedgerInProgress`,`Starting...`)]}):i(`settings.rebuildLedger`,`Rebuild wallet ledger`)}),Ce&&(0,G.jsx)(of,{title:i(`settings.rebuildLedgerConfirmTitle`,`Rebuild wallet ledger?`),message:i(`settings.rebuildLedgerConfirmMessage`,`This will rebuild the wallet ledger to repair historical balance values. Run this only if you know what you are doing.`),confirmText:i(`common.run`,`Run`),cancelText:i(`common.cancel`,`Cancel`),isLoading:Te,loadingText:i(`common.running`,`Running`),variant:`warning`,onCancel:()=>we(!1),onConfirm:async()=>{Ee(!0);try{await Z.rebuildBalanceLedger(),o(i(`settings.rebuildLedgerStarted`,`Ledger rebuild started`),`success`),we(!1)}catch(e){o(e.message||`Failed to start ledger rebuild`,`error`)}finally{Ee(!1)}}})]})]})]})]}),(0,G.jsxs)(zd,{id:`card-filemanager`,children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(fc,{className:`w-5 h-5 text-bambu-green`}),i(`settings.fileManager`)]})}),(0,G.jsxs)(Vd,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.createArchiveEntry`)}),(0,G.jsxs)(`select`,{value:A.library_archive_mode??`ask`,onChange:e=>yr(`library_archive_mode`,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:`always`,children:i(`settings.archiveMode.always`)}),(0,G.jsx)(`option`,{value:`never`,children:i(`settings.archiveMode.never`)}),(0,G.jsx)(`option`,{value:`ask`,children:i(`settings.archiveMode.ask`)})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.createArchiveEntryDescription`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.lowDiskSpaceWarning`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`input`,{type:`number`,min:`0.5`,max:`100`,step:`0.5`,value:A.library_disk_warning_gb??5,onChange:e=>yr(`library_disk_warning_gb`,parseFloat(e.target.value)||5),className:`w-24 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:`GB`})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.lowDiskSpaceDescription`)})]}),En&&Dn&&(0,G.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary pt-3 mt-3 space-y-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`libraryAutoPurge.enableLabel`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`libraryAutoPurge.enableDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:Dn.auto_purge_enabled,onChange:e=>kn({auto_purge_enabled:e.target.checked}),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`libraryAutoPurge.ageLabel`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`input`,{type:`number`,min:7,max:3650,disabled:!Dn.auto_purge_enabled,value:Dn.auto_purge_days,onChange:e=>kn({auto_purge_days:Math.max(7,Math.min(3650,parseInt(e.target.value||`0`,10)||0))}),className:`w-24 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none disabled:opacity-50`}),(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:i(`libraryAutoPurge.days`)})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`libraryAutoPurge.ageDescription`)})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-white cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,disabled:!Dn.auto_purge_enabled,checked:Dn.auto_purge_include_never_printed,onChange:e=>kn({auto_purge_include_never_printed:e.target.checked}),className:`rounded border-gray-300 disabled:opacity-50`}),i(`libraryAutoPurge.includeNeverPrinted`)]})]})]})]}),(0,G.jsxs)(zd,{id:`card-data`,children:[(0,G.jsx)(Bd,{children:(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(`settings.dataManagement`)})}),(0,G.jsxs)(Vd,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.clearNotificationLogs`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.clearNotificationLogsDescription`)})]}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:()=>et(!0),children:[(0,G.jsx)(Pu,{className:`w-4 h-4`}),i(`common.clear`)]})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.resetUiPreferences`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.resetUiPreferencesDescription`)})]}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:()=>nt(!0),children:[(0,G.jsx)(Pu,{className:`w-4 h-4`}),i(`settings.reset`)]})]}),(0,G.jsxs)(`div`,{className:`pt-4 border-t border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.storageUsage`,`Storage Usage`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.storageUsageDescription`,`Breakdown of data usage by category`)})]}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:Xt,disabled:Yt||ht,children:[(0,G.jsx)(Hl,{className:`w-4 h-4 ${Yt||ht?`animate-spin`:``}`}),i(`common.refresh`,`Refresh`)]})]}),(0,G.jsx)(`div`,{className:`mt-3`,children:Jt?(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`}),i(`common.loading`,`Loading`)]}):qt?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`w-full h-3 bg-bambu-dark rounded-full overflow-hidden flex`,children:qt.categories.filter(e=>e.bytes>0).map((e,t)=>(0,G.jsx)(`div`,{className:`${J8(e.key,t)} h-full`,style:{width:`${e.percent_of_total}%`},title:`${e.label}: ${e.formatted}`},e.key))}),(0,G.jsx)(`div`,{className:`mt-3 flex flex-wrap gap-3`,children:qt.categories.filter(e=>e.bytes>0).map((e,t)=>(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-xs`,children:[(0,G.jsx)(`span`,{className:`w-3 h-3 rounded-full ${J8(e.key,t)}`}),(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:e.label}),(0,G.jsx)(`span`,{className:`text-white`,children:e.formatted}),(0,G.jsxs)(`span`,{className:`text-bambu-gray`,children:[`(`,e.percent_of_total.toFixed(1),`%)`]})]},e.key))}),(0,G.jsxs)(`div`,{className:`mt-2 text-xs text-bambu-gray`,children:[i(`settings.storageUsageTotal`,`Total`),`: `,(0,G.jsx)(`span`,{className:`text-white`,children:qt.total_formatted}),qt.scan_errors>0&&(0,G.jsxs)(`span`,{className:`ml-2 text-amber-700 dark:text-amber-400`,children:[i(`settings.storageUsageErrors`,`Scan errors`),`: `,qt.scan_errors]})]}),qt.other_breakdown?.length>0&&(0,G.jsxs)(`div`,{className:`mt-4`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:i(`settings.storageUsageOtherBreakdown`,`Other breakdown`)}),(0,G.jsx)(`div`,{className:`space-y-2`,children:qt.other_breakdown.map(e=>(0,G.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-white`,children:e.label}),(0,G.jsx)(`span`,{className:`px-2 py-0.5 rounded-full border ${e.kind===`system`?`border-slate-500 text-slate-300`:`border-bambu-green text-bambu-green`}`,children:e.kind===`system`?i(`settings.storageUsageSystem`,`System`):i(`settings.storageUsageData`,`Data`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray`,children:[(0,G.jsx)(`span`,{className:`text-white`,children:e.formatted}),(0,G.jsxs)(`span`,{children:[`(`,e.percent_of_total.toFixed(1),`%)`]})]})]},`${e.bucket}-${e.kind}`))})]})]}):(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.storageUsageUnavailable`,`Storage usage data is unavailable`)})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between pt-4 border-t border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.backupRestore`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.backupRestoreDescription`)})]}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:()=>Le(`backup`),children:[(0,G.jsx)(Gs,{className:`w-4 h-4`}),i(`settings.goToBackup`)]})]})]})]})]}),(0,G.jsxs)(`div`,{className:`space-y-3 flex-1 lg:max-w-sm`,children:[(0,G.jsxs)(zd,{id:`card-updates`,children:[(0,G.jsx)(Bd,{children:(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(`settings.updates`)})}),(0,G.jsxs)(Vd,{className:`space-y-3`,children:[(0,G.jsx)(`p`,{className:`text-xs font-medium text-bambu-gray uppercase tracking-wider`,children:i(`settings.printerFirmware`)}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.checkPrinterFirmware`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.checkFirmwareDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.check_printer_firmware??!0,onChange:e=>yr(`check_printer_firmware`,e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,G.jsx)(`div`,{className:`border-t border-bambu-dark-tertiary pt-4`,children:(0,G.jsx)(`p`,{className:`text-xs font-medium text-bambu-gray uppercase tracking-wider mb-4`,children:i(`settings.bambuddySoftware`)})}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.checkForUpdatesLabel`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.autoCheckDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.check_updates,onChange:e=>yr(`check_updates`,e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between ${A.check_updates?``:`opacity-50`}`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.includeBetaUpdates`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.includeBetaUpdatesDesc`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.include_beta_updates??!1,onChange:e=>yr(`include_beta_updates`,e.target.checked),disabled:!A.check_updates,className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.currentVersion`)}),(0,G.jsxs)(`p`,{className:`text-sm text-bambu-gray`,children:[`v`,Tn?.version||`...`]})]}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:()=>Fn(),disabled:In,children:[In?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Hl,{className:`w-4 h-4`}),i(`settings.checkNow`)]})]}),Pn?.update_available?(0,G.jsxs)(`div`,{className:`mt-4 p-3 bg-bambu-green/10 border border-bambu-green/30 rounded-lg`,children:[(0,G.jsxs)(`div`,{className:`flex items-start justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`p`,{className:`text-bambu-green font-medium`,children:[`Update available: v`,Pn.latest_version]}),Pn.release_name&&Pn.release_name!==Pn.latest_version&&(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:Pn.release_name})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[Pn.release_notes&&(0,G.jsx)(`button`,{onClick:()=>ot(!0),className:`text-bambu-gray hover:text-white transition-colors text-sm underline`,children:i(`settings.releaseNotes`)}),Pn.release_url&&(0,G.jsx)(`a`,{href:Pn.release_url,target:`_blank`,rel:`noopener noreferrer`,className:`text-bambu-gray hover:text-white transition-colors`,title:i(`settings.viewReleaseOnGitHub`),children:(0,G.jsx)(rc,{className:`w-4 h-4`})})]})]}),Ln?.status===`downloading`||Ln?.status===`installing`?(0,G.jsxs)(`div`,{className:`mt-3`,children:[(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`}),(0,G.jsx)(`span`,{children:Ln.message})]}),(0,G.jsx)(`div`,{className:`mt-2 w-full bg-bambu-dark-tertiary rounded-full h-2`,children:(0,G.jsx)(`div`,{className:`bg-bambu-green h-2 rounded-full transition-all duration-300`,style:{width:`${Ln.progress}%`}})})]}):Ln?.status===`complete`?(0,G.jsx)(`div`,{className:`mt-3 p-2 bg-bambu-green/20 rounded text-sm text-bambu-green`,children:Ln.message}):Ln?.status===`error`?(0,G.jsx)(`div`,{className:`mt-3 p-2 bg-red-100 dark:bg-red-500/20 rounded text-sm text-red-700 dark:text-red-400`,children:Ln.error||Ln.message}):Pn?.is_ha_addon?(0,G.jsx)(`div`,{className:`mt-3 p-3 bg-bambu-dark-tertiary rounded-lg`,children:(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.updateViaHomeAssistant`)})}):Pn?.is_docker?(0,G.jsxs)(`div`,{className:`mt-3 p-3 bg-bambu-dark-tertiary rounded-lg`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mb-2`,children:i(`settings.updateViaDocker`)}),(0,G.jsxs)(`div`,{className:`flex items-start gap-1`,children:[(0,G.jsx)(`code`,{className:`flex-1 block text-xs bg-bambu-dark p-2 rounded text-bambu-green font-mono break-all select-all`,children:Lr}),(0,G.jsx)(BU,{value:Lr,titleKey:`settings.copyUpdateCommand`,copiedTitleKey:`printers.copied`,className:`ml-0 p-2 rounded hover:bg-bambu-dark text-bambu-gray hover:text-white transition-colors flex-shrink-0`,iconClassName:`w-4 h-4`})]}),(0,G.jsxs)(`label`,{className:`block mt-3`,children:[(0,G.jsx)(`span`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.composeDirectory`)}),(0,G.jsx)(`input`,{type:`text`,value:A?.docker_compose_dir??``,onChange:e=>yr(`docker_compose_dir`,e.target.value),placeholder:Pn?.compose_dir_detected||`/opt/bambuddy`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded text-sm text-white font-mono placeholder:text-bambu-gray/60 focus:outline-none focus:border-bambu-green`}),(0,G.jsx)(`span`,{className:`block text-xs text-bambu-gray mt-1`,children:i(`settings.composeDirectoryHint`)})]})]}):Pn?.update_method===`windows_installer`?(0,G.jsxs)(`div`,{className:`mt-3 p-3 bg-bambu-dark-tertiary rounded-lg`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mb-3`,children:i(`settings.updateViaWindowsInstaller`)}),(0,G.jsxs)(`a`,{href:Pn.installer_download_url||Pn.release_url||`https://github.com/maziggy/bambuddy/releases/tag/v${Pn.latest_version}`,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center justify-center font-medium rounded-lg transition-colors focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-offset-bambu-dark disabled:opacity-50 bg-bambu-green hover:bg-bambu-green-light text-white focus:ring-bambu-green px-4 py-2 text-sm gap-2 min-h-[44px] md:min-h-0`,children:[(0,G.jsx)(Xs,{className:`w-4 h-4`}),i(`settings.downloadWindowsInstaller`,{version:Pn.latest_version})]})]}):(0,G.jsxs)(Q,{className:`mt-3`,onClick:()=>sr.mutate(),disabled:sr.isPending,children:[sr.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Xs,{className:`w-4 h-4`}),i(`settings.installUpdate`)]})]}):Pn?.error?(0,G.jsx)(`div`,{className:`mt-2 p-2 bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30 rounded text-sm text-red-700 dark:text-red-400`,children:i(`settings.failedToCheckUpdates`,{error:Pn.error})}):Pn&&!Pn.update_available?(0,G.jsx)(`p`,{className:`mt-2 text-sm text-bambu-gray`,children:i(`settings.latestVersionRunning`)}):null]})]})]}),(0,G.jsx)(mGe,{})]})]})]}),je===`network`&&A&&(0,G.jsxs)(`div`,{className:`flex flex-col lg:flex-row gap-6`,children:[(0,G.jsxs)(`div`,{className:`flex-1 lg:max-w-xl space-y-3`,children:[(0,G.jsxs)(zd,{id:`card-externalurl`,children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(Ac,{className:`w-5 h-5 text-blue-600 dark:text-blue-400`}),i(`settings.externalUrl`)]})}),(0,G.jsxs)(Vd,{className:`space-y-3`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.externalUrlDescription`)}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.bambuddyUrl`)}),(0,G.jsx)(`input`,{type:`text`,value:A.external_url??``,onChange:e=>yr(`external_url`,e.target.value),placeholder:`http://192.168.1.100:8000`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.externalUrlHint`)})]})]})]}),(0,G.jsxs)(zd,{id:`card-ftpretry`,children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(Hl,{className:`w-5 h-5 text-blue-600 dark:text-blue-400`}),i(`settings.ftpRetry`)]})}),(0,G.jsxs)(Vd,{className:`space-y-3`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.ftpRetryDescription`)}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.enableRetry`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.autoRetryDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.ftp_retry_enabled??!0,onChange:e=>yr(`ftp_retry_enabled`,e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),A.ftp_retry_enabled&&(0,G.jsxs)(`div`,{className:`space-y-3 pt-2 border-t border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.retryAttempts`)}),(0,G.jsxs)(`div`,{className:`relative w-44`,children:[(0,G.jsx)(`select`,{value:A.ftp_retry_count??3,onChange:e=>yr(`ftp_retry_count`,parseInt(e.target.value)),className:`w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer`,children:[1,2,3,4,5,6,7,8,9,10].map(e=>(0,G.jsx)(`option`,{value:e,children:i(`settings.time`,{count:e})},e))}),(0,G.jsx)(ps,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.retryDelay`)}),(0,G.jsxs)(`div`,{className:`relative w-44`,children:[(0,G.jsx)(`select`,{value:A.ftp_retry_delay??2,onChange:e=>yr(`ftp_retry_delay`,parseInt(e.target.value)),className:`w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer`,children:[1,2,3,5,10,15,20,30].map(e=>(0,G.jsx)(`option`,{value:e,children:i(`settings.second`,{count:e})},e))}),(0,G.jsx)(ps,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.connectionTimeout`)}),(0,G.jsxs)(`div`,{className:`relative w-44`,children:[(0,G.jsx)(`select`,{value:A.ftp_timeout??30,onChange:e=>yr(`ftp_timeout`,parseInt(e.target.value)),className:`w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer`,children:[10,15,20,30,45,60,90,120,180,300].map(e=>(0,G.jsx)(`option`,{value:e,children:i(`settings.nSeconds`,{count:e})},e))}),(0,G.jsx)(ps,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.increaseForWeakWifi`)})]})]})]})]})]}),(0,G.jsxs)(`div`,{className:`flex-1 lg:max-w-xl space-y-3`,children:[(0,G.jsxs)(zd,{id:`card-ha`,children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(Bc,{className:`w-5 h-5 text-bambu-green`}),i(`settings.homeAssistant`)]}),A.ha_enabled&&It&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`w-2.5 h-2.5 rounded-full ${It.success?`bg-green-400`:`bg-red-400`}`}),(0,G.jsx)(`span`,{className:`text-sm ${It.success?`text-green-700 dark:text-green-400`:`text-red-700 dark:text-red-400`}`,children:It.success?i(`settings.connected`):i(`settings.disconnected`)})]})]})}),(0,G.jsxs)(Vd,{className:`space-y-3`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.homeAssistantFullDescription`)}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex-1`,children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.enableHomeAssistant`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.homeAssistantDescription`)}),A.ha_env_managed&&(0,G.jsxs)(`div`,{className:`flex items-center gap-1 mt-1`,children:[(0,G.jsx)(nl,{className:`w-3 h-3 text-bambu-green`}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-green`,children:i(`settings.autoEnabledViaEnv`)})]})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.ha_enabled??!1,onChange:e=>yr(`ha_enabled`,e.target.checked),disabled:A.ha_env_managed,className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green ${A.ha_env_managed?`opacity-60 cursor-not-allowed`:``}`})]})]}),A.ha_enabled&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[i(`settings.homeAssistantUrl`),A.ha_url_from_env&&(0,G.jsx)(`span`,{className:`ml-2 text-xs text-bambu-green`,children:i(`settings.environmentManagedLabel`)})]}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(`input`,{type:`text`,value:A.ha_url??``,onChange:e=>yr(`ha_url`,e.target.value),placeholder:`http://192.168.1.100:8123`,disabled:A.ha_url_from_env,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 ${A.ha_url_from_env?`opacity-60 cursor-not-allowed`:``}`}),A.ha_url_from_env&&(0,G.jsx)(nl,{className:`absolute right-3 top-2.5 w-4 h-4 text-bambu-gray`})]}),A.ha_url_from_env&&(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.urlFromEnvReadOnly`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[i(`settings.longLivedAccessToken`),A.ha_token_from_env&&(0,G.jsx)(`span`,{className:`ml-2 text-xs text-bambu-green`,children:i(`settings.environmentManagedLabel`)})]}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(`input`,{type:`password`,value:A.ha_token??``,onChange:e=>yr(`ha_token`,e.target.value),placeholder:`eyJ0eXAiOiJKV1QiLC...`,disabled:A.ha_token_from_env,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 ${A.ha_token_from_env?`opacity-60 cursor-not-allowed`:``}`}),A.ha_token_from_env&&(0,G.jsx)(nl,{className:`absolute right-3 top-2.5 w-4 h-4 text-bambu-gray`})]}),A.ha_token_from_env?(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.tokenFromEnvReadOnly`)}):(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.haTokenHint`)})]}),A.ha_url&&A.ha_token&&(0,G.jsx)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,disabled:Rt,onClick:async()=>{zt(!0),Lt(null);try{Lt(await Z.testHAConnection(A.ha_url,A.ha_token))}catch(e){Lt({success:!1,message:null,error:e instanceof Error?e.message:i(`common.unknownError`)})}finally{zt(!1)}},children:[Rt?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Qu,{className:`w-4 h-4`}),i(`settings.testConnection`)]})})]})]})]}),(0,G.jsxs)(zd,{id:`card-mqtt`,children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(Qu,{className:`w-5 h-5 text-blue-600 dark:text-blue-400`}),i(`settings.mqttPublishing`)]}),zn?.enabled&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`w-2.5 h-2.5 rounded-full ${zn.connected?`bg-green-400`:`bg-red-400`}`}),(0,G.jsx)(`span`,{className:`text-sm ${zn.connected?`text-green-700 dark:text-green-400`:`text-red-700 dark:text-red-400`}`,children:zn.connected?i(`settings.connected`):i(`settings.disconnected`)})]})]})}),(0,G.jsxs)(Vd,{className:`space-y-3`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.mqttDescription`)}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.enableMqtt`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.mqttEnableDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.mqtt_enabled??!1,onChange:e=>yr(`mqtt_enabled`,e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),A.mqtt_enabled&&(0,G.jsxs)(`div`,{className:`space-y-3 pt-2 border-t border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.brokerHostname`)}),(0,G.jsx)(`input`,{type:`text`,value:A.mqtt_broker??``,onChange:e=>yr(`mqtt_broker`,e.target.value),placeholder:`mqtt.example.com or 192.168.1.100`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,G.jsxs)(`div`,{className:`flex items-end gap-4`,children:[(0,G.jsxs)(`div`,{className:`flex-1`,children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.port`)}),(0,G.jsx)(`input`,{type:`number`,min:`1`,max:`65535`,value:A.mqtt_port??1883,onChange:e=>yr(`mqtt_port`,Math.min(65535,Math.max(1,parseInt(e.target.value)||1883))),className:`w-24 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-3 pb-2`,children:[(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.mqtt_use_tls??!1,onChange:e=>{let t=e.target.checked;yr(`mqtt_use_tls`,t);let n=A.mqtt_port??1883;t&&n===1883?yr(`mqtt_port`,8883):!t&&n===8883&&yr(`mqtt_port`,1883)},className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]}),(0,G.jsx)(`span`,{className:`text-white text-sm`,children:i(`settings.useTls`)})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.usernameOptional`)}),(0,G.jsx)(`input`,{type:`text`,value:A.mqtt_username??``,onChange:e=>yr(`mqtt_username`,e.target.value),placeholder:i(`settings.leaveEmptyForAnonymous`),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.passwordOptional`)}),(0,G.jsx)(`input`,{type:`password`,value:A.mqtt_password??``,onChange:e=>yr(`mqtt_password`,e.target.value),placeholder:i(`settings.leaveEmptyForAnonymous`),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.topicPrefix`)}),(0,G.jsx)(`input`,{type:`text`,value:A.mqtt_topic_prefix??`bambuddy`,onChange:e=>yr(`mqtt_topic_prefix`,e.target.value),placeholder:`bambuddy`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.topicPrefixHint`,{prefix:A.mqtt_topic_prefix||`bambuddy`})})]}),zn&&(0,G.jsx)(`div`,{className:`pt-3 mt-3 border-t border-bambu-dark-tertiary`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,G.jsx)(`span`,{className:`w-2 h-2 rounded-full ${zn.connected?`bg-green-400`:`bg-red-400`}`}),(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:zn.connected?(0,G.jsxs)(G.Fragment,{children:[i(`settings.mqttConnectedTo`),` `,(0,G.jsxs)(`span`,{className:`text-white`,children:[zn.broker,`:`,zn.port]})]}):i(`settings.spoolmanDisconnected`)})]})})]})]})]})]}),(0,G.jsx)(`div`,{className:`flex-1 lg:max-w-md space-y-3`,children:(0,G.jsxs)(zd,{id:`card-prometheus`,children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(Iu,{className:`w-5 h-5 text-orange-600 dark:text-orange-400`}),i(`settings.prometheusMetrics`)]})}),(0,G.jsxs)(Vd,{className:`space-y-3`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.prometheusEndpointDescription`)}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.enableMetricsEndpoint`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.prometheusDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.prometheus_enabled??!1,onChange:e=>yr(`prometheus_enabled`,e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),A.prometheus_enabled&&(0,G.jsxs)(`div`,{className:`space-y-3 pt-2 border-t border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.bearerTokenOptional`)}),(0,G.jsx)(`input`,{type:`password`,value:A.prometheus_token??``,onChange:e=>yr(`prometheus_token`,e.target.value),placeholder:i(`settings.leaveEmptyForNoAuth`),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.bearerTokenHint`)})]}),(0,G.jsxs)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:[(0,G.jsx)(`p`,{className:`text-sm text-white mb-2`,children:i(`settings.availableMetrics`)}),(0,G.jsxs)(`div`,{className:`text-xs text-bambu-gray space-y-1`,children:[(0,G.jsxs)(`p`,{children:[(0,G.jsx)(`code`,{className:`text-orange-700 dark:text-orange-400`,children:`bambuddy_printer_connected`}),` - `,i(`settings.metricsConnectionStatus`)]}),(0,G.jsxs)(`p`,{children:[(0,G.jsx)(`code`,{className:`text-orange-700 dark:text-orange-400`,children:`bambuddy_printer_state`}),` - `,i(`settings.metricsPrinterState`)]}),(0,G.jsxs)(`p`,{children:[(0,G.jsx)(`code`,{className:`text-orange-700 dark:text-orange-400`,children:`bambuddy_print_progress`}),` - `,i(`settings.metricsPrintProgress`)]}),(0,G.jsxs)(`p`,{children:[(0,G.jsx)(`code`,{className:`text-orange-700 dark:text-orange-400`,children:`bambuddy_bed_temp_celsius`}),` - `,i(`settings.metricsBedTemp`)]}),(0,G.jsxs)(`p`,{children:[(0,G.jsx)(`code`,{className:`text-orange-700 dark:text-orange-400`,children:`bambuddy_nozzle_temp_celsius`}),` - `,i(`settings.metricsNozzleTemp`)]}),(0,G.jsxs)(`p`,{children:[(0,G.jsx)(`code`,{className:`text-orange-700 dark:text-orange-400`,children:`bambuddy_prints_total`}),` - `,i(`settings.metricsPrintsTotal`)]}),(0,G.jsx)(`p`,{className:`text-bambu-gray/70 italic`,children:i(`settings.metricsMore`)})]})]})]})]})]})})]}),It&&(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50`,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg p-6 max-w-md w-full mx-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3 mb-4`,children:[It.success?(0,G.jsx)(xs,{className:`w-8 h-8 text-green-600 dark:text-green-400`}):(0,G.jsx)(Ds,{className:`w-8 h-8 text-red-600 dark:text-red-400`}),(0,G.jsx)(`h3`,{className:`text-lg font-medium text-white`,children:It.success?i(`settings.connectionSuccessful`):i(`settings.connectionFailed`)})]}),(0,G.jsx)(`p`,{className:`text-bambu-gray mb-6`,children:It.success?It.message||i(`settings.haConnectionSuccess`):It.error||i(`settings.haConnectionFailed`)}),(0,G.jsx)(`div`,{className:`flex justify-end`,children:(0,G.jsx)(Q,{variant:`primary`,onClick:()=>Lt(null),children:i(`settings.ok`)})})]})}),je===`plugs`&&(0,G.jsxs)(`div`,{id:`card-plugs`,children:[(0,G.jsxs)(`div`,{className:`flex items-start justify-between mb-6`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(Pl,{className:`w-5 h-5 text-bambu-green`}),i(`settings.smartPlugs`)]}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:i(`settings.smartPlugsDescription`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 pt-1 shrink-0`,children:[Zt&&Zt.filter(e=>e.enabled).length>1&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,className:`whitespace-nowrap`,onClick:()=>it(`on`),disabled:dr.isPending,title:i(`settings.turnAllPlugsOn`),children:[dr.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Ll,{className:`w-4 h-4 text-bambu-green`}),i(`settings.allOn`)]}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,className:`whitespace-nowrap`,onClick:()=>it(`off`),disabled:dr.isPending,title:i(`settings.turnAllPlugsOff`),children:[dr.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Il,{className:`w-4 h-4 text-red-600 dark:text-red-400`}),i(`settings.allOff`)]})]}),(0,G.jsxs)(Q,{className:`whitespace-nowrap`,onClick:()=>{L(null),F(!0)},children:[(0,G.jsx)(Fl,{className:`w-4 h-4`}),i(`settings.addSmartPlug`)]})]})]}),Zt&&Zt.length>0&&(0,G.jsxs)(zd,{className:`mb-6`,children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(id,{className:`w-4 h-4 text-yellow-600 dark:text-yellow-400`}),i(`settings.energySummary`),en&&(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin text-bambu-gray ml-2`})]})}),(0,G.jsx)(Vd,{children:$t?(0,G.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-4`,children:[(0,G.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray text-xs mb-1`,children:[(0,G.jsx)(id,{className:`w-3 h-3`}),i(`settings.currentPower`)]}),(0,G.jsxs)(`div`,{className:`text-xl font-bold text-white`,children:[$t.totalPower.toFixed(1),(0,G.jsx)(`span`,{className:`text-sm font-normal text-bambu-gray ml-1`,children:`W`})]}),(0,G.jsx)(`div`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.plugsOnline`,{reachable:$t.reachableCount,total:$t.totalPlugs})})]}),(0,G.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray text-xs mb-1`,children:[(0,G.jsx)(as,{className:`w-3 h-3`}),i(`settings.today`)]}),(0,G.jsxs)(`div`,{className:`text-xl font-bold text-white`,children:[$t.totalToday.toFixed(3),(0,G.jsx)(`span`,{className:`text-sm font-normal text-bambu-gray ml-1`,children:`kWh`})]}),(A?.energy_cost_per_kwh??0)>0&&(0,G.jsxs)(`div`,{className:`text-xs text-bambu-gray mt-1`,children:[`~`,($t.totalToday*(A?.energy_cost_per_kwh??0)).toFixed(2),` `,Lf(A?.currency||`USD`)]})]}),(0,G.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray text-xs mb-1`,children:[(0,G.jsx)(Iu,{className:`w-3 h-3`}),i(`settings.yesterday`)]}),(0,G.jsxs)(`div`,{className:`text-xl font-bold text-white`,children:[$t.totalYesterday.toFixed(3),(0,G.jsx)(`span`,{className:`text-sm font-normal text-bambu-gray ml-1`,children:`kWh`})]}),(A?.energy_cost_per_kwh??0)>0&&(0,G.jsxs)(`div`,{className:`text-xs text-bambu-gray mt-1`,children:[`~`,($t.totalYesterday*(A?.energy_cost_per_kwh??0)).toFixed(2),` `,Lf(A?.currency||`USD`)]})]}),(0,G.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray text-xs mb-1`,children:[(0,G.jsx)(qs,{className:`w-3 h-3`}),i(`settings.total`)]}),(0,G.jsxs)(`div`,{className:`text-xl font-bold text-white`,children:[$t.totalLifetime.toFixed(1),(0,G.jsx)(`span`,{className:`text-sm font-normal text-bambu-gray ml-1`,children:`kWh`})]}),(A?.energy_cost_per_kwh??0)>0&&(0,G.jsxs)(`div`,{className:`text-xs text-bambu-gray mt-1`,children:[`~`,($t.totalLifetime*(A?.energy_cost_per_kwh??0)).toFixed(2),` `,Lf(A?.currency||`USD`)]})]})]}):en?null:(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.enablePlugsForSummary`)})})]}),Qt?(0,G.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,G.jsx)(Y,{className:`w-8 h-8 text-bambu-green animate-spin`})}):Zt&&Zt.length>0?(0,G.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4`,children:Zt.map(e=>(0,G.jsx)(FWe,{plug:e,onEdit:e=>{L(e),F(!0)}},e.id))}):(0,G.jsx)(zd,{children:(0,G.jsx)(Vd,{className:`py-12`,children:(0,G.jsxs)(`div`,{className:`text-center text-bambu-gray`,children:[(0,G.jsx)(Pl,{className:`w-16 h-16 mx-auto mb-4 opacity-30`}),(0,G.jsx)(`p`,{className:`text-lg font-medium text-white mb-2`,children:i(`settings.noSmartPlugsTitle`)}),(0,G.jsx)(`p`,{className:`text-sm mb-4`,children:i(`settings.noSmartPlugsDescription`)}),(0,G.jsxs)(Q,{onClick:()=>{L(null),F(!0)},children:[(0,G.jsx)(Fl,{className:`w-4 h-4`}),i(`settings.addFirstSmartPlug`)]})]})})})]}),je===`sensors`&&(0,G.jsxs)(`div`,{id:`card-sensors`,children:[(0,G.jsxs)(`div`,{id:`card-ha-sensors`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-4`,children:[(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(Tc,{className:`w-5 h-5 text-bambu-green`}),i(`haSensors.sectionTitle`)]}),(0,G.jsxs)(Q,{className:`whitespace-nowrap`,disabled:!sn?.length,onClick:()=>{V(null),z(!0)},children:[(0,G.jsx)(Fl,{className:`w-4 h-4`}),i(`haSensors.add`)]})]}),cn&&cn.length>0?(0,G.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4`,children:cn.map(e=>{let t=sn?.find(t=>t.id===e.printer_id);return(0,G.jsx)(zd,{children:(0,G.jsxs)(Vd,{className:`py-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsx)(`div`,{className:`text-white font-medium truncate`,children:e.name}),(0,G.jsx)(`div`,{className:`text-xs text-bambu-gray truncate`,children:e.entity_id}),(0,G.jsx)(`div`,{className:`text-xs text-bambu-gray mt-1`,children:t?.name??i(`haSensors.unknownPrinter`)})]}),(0,G.jsx)(Q,{size:`sm`,variant:`secondary`,onClick:()=>{V(e),z(!0)},children:i(`common.edit`)})]}),(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-1 mt-3`,children:[e.block_print&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 text-xs rounded bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-400`,children:i(`haSensors.badgeBlocks`)}),e.notify_on_alert&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 text-xs rounded bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`,children:i(`haSensors.badgeNotifies`)}),!e.show_on_printer_card&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 text-xs rounded bg-bambu-dark-tertiary text-bambu-gray`,children:i(`haSensors.badgeHidden`)})]})]})},e.id)})}):(0,G.jsx)(zd,{children:(0,G.jsx)(Vd,{className:`py-8`,children:(0,G.jsxs)(`div`,{className:`text-center text-bambu-gray`,children:[(0,G.jsx)(Tc,{className:`w-12 h-12 mx-auto mb-3 opacity-30`}),(0,G.jsx)(`p`,{className:`text-sm`,children:i(`haSensors.empty`)})]})})})]}),(0,G.jsxs)(`div`,{id:`card-location-sensors`,className:`mt-8`,children:[(0,G.jsxs)(`div`,{className:`flex items-start justify-between gap-[20px] mb-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(Tc,{className:`w-5 h-5 text-bambu-green`}),i(`locationHaSensors.sectionTitle`)]}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:i(`locationHaSensors.sectionDescription`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 pt-1 shrink-0`,children:[(0,G.jsx)(`button`,{type:`button`,onClick:()=>ae(!0),className:`p-2 rounded-lg bg-bambu-dark-tertiary hover:bg-bambu-gray-dark text-white transition-colors`,title:i(`locationHaSensors.options.buttonLabel`),"aria-label":i(`locationHaSensors.options.buttonLabel`),children:(0,G.jsx)(Rs,{className:`w-4 h-4`})}),(0,G.jsxs)(Q,{className:`whitespace-nowrap`,disabled:!un?.length,onClick:()=>{re(null),te(!0)},children:[(0,G.jsx)(Fl,{className:`w-4 h-4`}),i(`locationHaSensors.add`)]})]})]}),ln&&ln.length>0?(0,G.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4`,children:(()=>{let e=new Map((un??[]).map((e,t)=>[e.id,t])),t=ln.reduce((e,t)=>{let n=e.get(t.location_id)??[];return n.push(t),e.set(t.location_id,n),e},new Map);return Array.from(t.entries()).sort(([t],[n])=>(e.get(t)??2**53-1)-(e.get(n)??2**53-1))})().map(([e,t])=>{let n=un?.find(t=>t.id===e),r=e=>FT({device_class:e.device_class,state:e.last_state,kind:e.kind}),a=[...t].sort((e,t)=>(Y8[e.device_class??``]??99)-(Y8[t.device_class??``]??99));return(0,G.jsx)(zd,{children:(0,G.jsxs)(Vd,{className:`py-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,G.jsx)(`div`,{className:`text-white font-medium truncate`,children:n?.name??i(`locationHaSensors.unknownLocation`)}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>ue({locationName:n?.name??i(`locationHaSensors.unknownLocation`),sensorIds:a.map(e=>e.id)}),className:`p-1 text-bambu-gray hover:text-red-500 rounded transition-colors shrink-0`,title:i(`common.delete`),"aria-label":i(`common.delete`),children:(0,G.jsx)(Pu,{className:`w-3.5 h-3.5`})})]}),(0,G.jsx)(`div`,{className:`mt-2 space-y-1.5`,children:a.map(e=>{let t=r(e),n=fn.get(e.id),a=XGe(n,i),o=B6(oe&&n?z6(n):null,se,H,ce)||`text-white`;return(0,G.jsxs)(`div`,{className:`flex items-center min-w-0 text-xs text-bambu-gray`,children:[(0,G.jsx)(t,{className:`w-3.5 h-3.5 shrink-0 mr-1.5`}),a&&(0,G.jsx)(`span`,{className:`${o} shrink-0 w-[52px] text-center`,children:a}),a&&(0,G.jsx)(`span`,{className:`shrink-0 mr-1.5`,children:`-`}),(0,G.jsx)(`span`,{className:`truncate mr-1.5`,title:e.name,children:e.entity_id}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>{re(e),te(!0)},className:`p-1 text-bambu-gray hover:text-white rounded transition-colors shrink-0`,title:i(`common.edit`),"aria-label":i(`common.edit`),children:(0,G.jsx)(Al,{className:`w-3.5 h-3.5`})})]},e.id)})}),(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-1 mt-3`,children:[(()=>{let e=a.filter(e=>e.notify_on_alert);return e.length?(0,G.jsxs)(`span`,{className:`flex items-center gap-1 px-2 py-0.5 text-xs rounded bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`,children:[i(`haSensors.badgeNotifies`),e.map(e=>(0,G.jsx)(r(e),{className:`w-3 h-3`},e.id))]}):null})(),(()=>{let e=a.filter(e=>!e.show_on_card);return e.length?(0,G.jsxs)(`span`,{className:`flex items-center gap-1 px-2 py-0.5 text-xs rounded bg-bambu-dark-tertiary text-bambu-gray`,children:[i(`haSensors.badgeHidden`),e.map(e=>(0,G.jsx)(r(e),{className:`w-3 h-3`},e.id))]}):null})()]})]})},e)})}):(0,G.jsx)(zd,{children:(0,G.jsx)(Vd,{className:`py-8`,children:(0,G.jsxs)(`div`,{className:`text-center text-bambu-gray`,children:[(0,G.jsx)(Tc,{className:`w-12 h-12 mx-auto mb-3 opacity-30`}),(0,G.jsx)(`p`,{className:`text-sm`,children:i(`locationHaSensors.empty`)})]})})})]})]}),je===`notifications`&&(0,G.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-4`,children:[(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,id:`card-providers`,children:[(0,G.jsx)(qo,{className:`w-5 h-5 text-bambu-green`}),i(`settings.providers`)]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(Q,{size:`sm`,variant:`secondary`,onClick:()=>Se(!0),children:[(0,G.jsx)(zc,{className:`w-4 h-4`}),i(`settings.log`)]}),tn&&tn.length>0&&(0,G.jsxs)(Q,{size:`sm`,variant:`secondary`,onClick:()=>{lr(null),ur.mutate()},disabled:ur.isPending,children:[ur.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)($l,{className:`w-4 h-4`}),i(`settings.testAll`)]}),(0,G.jsxs)(Q,{size:`sm`,onClick:()=>{me(null),fe(!0)},children:[(0,G.jsx)(Fl,{className:`w-4 h-4`}),i(`settings.addNotificationProvider`)]})]})]}),(0,G.jsx)(zd,{className:`mb-4`,children:(0,G.jsx)(Vd,{className:`py-3`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white text-sm font-medium`,children:i(`settings.notificationLanguage`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.notificationLanguageDescription`)})]}),(0,G.jsx)(`select`,{value:A.notification_language||`en`,onChange:e=>yr(`notification_language`,e.target.value),className:`px-2 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:outline-none focus:ring-1 focus:ring-bambu-green`,children:kt.map(e=>(0,G.jsx)(`option`,{value:e.code,children:e.nativeName},e.code))})]})})}),(0,G.jsx)(zd,{className:`mb-4`,children:(0,G.jsx)(Vd,{className:`py-3`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white text-sm font-medium`,children:i(`settings.bedCooledThreshold`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.bedCooledThresholdDescription`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(`input`,{type:`number`,min:20,max:80,step:1,value:A.bed_cooled_threshold??35,onChange:e=>yr(`bed_cooled_threshold`,Number(e.target.value)),className:`w-16 px-2 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm text-center focus:outline-none focus:ring-1 focus:ring-bambu-green`}),(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:`°C`})]})]})})}),(0,G.jsx)(zd,{className:`mb-4`,children:(0,G.jsx)(Vd,{className:`py-3`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between ${Hn?.advanced_auth_enabled?``:`opacity-50`}`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white text-sm font-medium`,children:i(`settings.userNotificationsEnabled`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:Hn?.advanced_auth_enabled?i(`settings.userNotificationsEnabledDescription`):i(`settings.userNotificationsDisabledHint`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,className:`sr-only peer`,checked:A.user_notifications_enabled??!0,disabled:!Hn?.advanced_auth_enabled,onChange:e=>yr(`user_notifications_enabled`,e.target.checked)}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green peer-disabled:cursor-not-allowed`})]})]})})}),cr&&(0,G.jsx)(zd,{className:`mb-4`,children:(0,G.jsxs)(Vd,{className:`py-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,G.jsx)(`span`,{className:`text-sm font-medium text-white`,children:i(`settings.testResults`)}),(0,G.jsx)(`button`,{onClick:()=>lr(null),className:`text-bambu-gray hover:text-white text-xs`,children:i(`common.dismiss`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-4 text-sm mb-2`,children:[(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-bambu-green`,children:[(0,G.jsx)(xs,{className:`w-4 h-4`}),i(`settings.testPassedCount`,{count:cr.success})]}),cr.failed>0&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-red-700 dark:text-red-400`,children:[(0,G.jsx)(Ds,{className:`w-4 h-4`}),i(`settings.testFailedCount`,{count:cr.failed})]})]}),cr.results.filter(e=>!e.success).length>0&&(0,G.jsx)(`div`,{className:`space-y-1 mt-2 pt-2 border-t border-bambu-dark-tertiary`,children:cr.results.filter(e=>!e.success).map(e=>(0,G.jsxs)(`div`,{className:`text-xs text-red-700 dark:text-red-400`,children:[(0,G.jsxs)(`span`,{className:`font-medium`,children:[e.provider_name,`:`]}),` `,e.message]},e.provider_id))})]})}),W?(0,G.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,G.jsx)(Y,{className:`w-6 h-6 text-bambu-green animate-spin`})}):tn&&tn.length>0?(0,G.jsx)(`div`,{className:`space-y-3`,children:tn.map(e=>(0,G.jsx)(UWe,{provider:e,onEdit:e=>{me(e),fe(!0)}},e.id))}):(0,G.jsx)(zd,{children:(0,G.jsx)(Vd,{className:`py-8`,children:(0,G.jsxs)(`div`,{className:`text-center text-bambu-gray`,children:[(0,G.jsx)(qo,{className:`w-12 h-12 mx-auto mb-3 opacity-30`}),(0,G.jsx)(`p`,{className:`text-sm font-medium text-white mb-2`,children:i(`settings.noProvidersTitle`)}),(0,G.jsx)(`p`,{className:`text-xs mb-3`,children:i(`settings.noProvidersDescription`)}),(0,G.jsxs)(Q,{size:`sm`,onClick:()=>{me(null),fe(!0)},children:[(0,G.jsx)(Fl,{className:`w-4 h-4`}),i(`settings.addProvider`)]})]})})})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2 mb-2`,id:`card-templates`,children:[(0,G.jsx)(fc,{className:`w-5 h-5 text-bambu-green`}),i(`settings.messageTemplates`)]}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mb-3`,children:i(`settings.messageTemplatesDescription`)}),(0,G.jsxs)(`div`,{className:`relative mb-3`,children:[(0,G.jsx)(Ql,{className:`w-4 h-4 text-bambu-gray absolute left-3 top-1/2 -translate-y-1/2 pointer-events-none`}),(0,G.jsx)(`input`,{type:`text`,value:_e,onChange:e=>ve(e.target.value),placeholder:i(`settings.filterTemplates`,`Filter templates…`),className:`w-full pl-9 pr-8 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`}),_e&&(0,G.jsx)(`button`,{onClick:()=>ve(``),className:`absolute right-2 top-1/2 -translate-y-1/2 p-1 text-bambu-gray hover:text-white`,"aria-label":`Clear filter`,children:(0,G.jsx)(nd,{className:`w-3.5 h-3.5`})})]}),gn?(0,G.jsx)(`div`,{className:`flex justify-center py-8`,children:(0,G.jsx)(Y,{className:`w-6 h-6 text-bambu-green animate-spin`})}):hn&&hn.length>0?(()=>{let e=_e.trim().toLowerCase(),t=[...hn].sort((e,t)=>e.name.localeCompare(t.name)).filter(t=>!e||t.name.toLowerCase().includes(e)||(t.title_template||``).toLowerCase().includes(e));return t.length===0?(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray italic text-center py-6`,children:i(`settings.noTemplatesMatch`,`No templates match your filter.`)}):(0,G.jsx)(`div`,{className:`space-y-2`,children:t.map(e=>(0,G.jsx)(zd,{className:`cursor-pointer hover:border-bambu-green/50 transition-colors`,onClick:()=>ge(e),children:(0,G.jsx)(Vd,{className:`py-2.5 px-3`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,G.jsx)(`p`,{className:`text-white font-medium text-sm truncate`,children:e.name}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-xs truncate mt-0.5`,children:e.title_template})]}),(0,G.jsx)(`button`,{className:`p-1.5 hover:bg-bambu-dark-tertiary rounded transition-colors shrink-0 ml-2`,onClick:t=>{t.stopPropagation(),ge(e)},children:(0,G.jsx)(kl,{className:`w-4 h-4 text-bambu-gray`})})]})})},e.id))})})():(0,G.jsx)(zd,{children:(0,G.jsx)(Vd,{className:`py-8`,children:(0,G.jsxs)(`div`,{className:`text-center text-bambu-gray`,children:[(0,G.jsx)(fc,{className:`w-12 h-12 mx-auto mb-3 opacity-30`}),(0,G.jsx)(`p`,{className:`text-sm`,children:i(`settings.noTemplatesAvailable`)})]})})})]})]}),je===`apikeys`&&(0,G.jsxs)(`div`,{className:d(`api_keys:read`)?`grid grid-cols-1 xl:grid-cols-2 gap-4`:`grid grid-cols-1 gap-4`,children:[(0,G.jsxs)(`div`,{children:[d(`api_keys:read`)&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`flex items-start justify-between gap-4 mb-6`,children:[(0,G.jsxs)(`div`,{className:`flex-1`,children:[(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,id:`card-createapi`,children:[(0,G.jsx)(Kc,{className:`w-5 h-5 text-bambu-green`}),i(`settings.apiKeys`)]}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:i(`settings.apiKeysDescription`)})]}),(0,G.jsxs)(Q,{size:`sm`,onClick:()=>Be(!0),className:`flex-shrink-0`,children:[(0,G.jsx)(Fl,{className:`w-4 h-4`}),i(`settings.createKey`)]})]}),Ge&&(0,G.jsx)(zd,{className:`mb-6 border-bambu-green`,children:(0,G.jsx)(Vd,{className:`py-4`,children:(0,G.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,G.jsx)(xs,{className:`w-5 h-5 text-bambu-green flex-shrink-0 mt-0.5`}),(0,G.jsxs)(`div`,{className:`flex-1`,children:[(0,G.jsx)(`p`,{className:`text-white font-medium mb-1`,children:i(`settings.apiKeyCreated`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mb-2`,children:i(`settings.apiKeyCopyWarning`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 bg-bambu-dark rounded-lg p-2`,children:[(0,G.jsx)(`code`,{className:`flex-1 text-sm text-bambu-green font-mono break-all`,children:Ge}),(0,G.jsx)(Q,{variant:`secondary`,size:`sm`,onClick:async()=>{try{if(navigator.clipboard&&navigator.clipboard.writeText)await navigator.clipboard.writeText(Ge);else{let e=document.createElement(`textarea`);e.value=Ge,e.style.position=`fixed`,e.style.left=`-999999px`,document.body.appendChild(e),e.select(),document.execCommand(`copy`),document.body.removeChild(e)}o(i(`settings.toast.keyCopied`))}catch{o(i(`settings.toast.copyFailed`),`error`)}},children:(0,G.jsx)(Vs,{className:`w-4 h-4`})})]}),(0,G.jsxs)(`div`,{className:`flex gap-2 mt-3`,children:[(0,G.jsx)(Q,{variant:`secondary`,size:`sm`,onClick:()=>{Qe(Ge),o(i(`settings.toast.keyAddedToBrowser`))},children:i(`settings.useInApiBrowser`)}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:()=>Je(!0),children:[(0,G.jsx)(zl,{className:`w-4 h-4`}),i(`settings.apiKeyQrButton`)]}),(0,G.jsx)(Q,{variant:`secondary`,size:`sm`,onClick:()=>{Je(!1),Ke(null)},children:i(`common.dismiss`)})]})]})]})})}),qe&&Ge&&(0,G.jsx)(oGe,{apiKey:Ge,baseUrl:A?.external_url||void 0,onClose:()=>Je(!1)}),ze&&(0,G.jsxs)(zd,{className:`mb-6`,children:[(0,G.jsx)(Bd,{children:(0,G.jsx)(`h3`,{className:`text-base font-semibold text-white`,children:i(`settings.createNewApiKey`)})}),(0,G.jsxs)(Vd,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.keyName`)}),(0,G.jsx)(`input`,{type:`text`,value:Ve,onChange:e=>He(e.target.value),placeholder:i(`settings.keyNamePlaceholder`),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-2`,children:i(`common.permissions`)}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:Ue.can_read_status,onChange:e=>We(t=>({...t,can_read_status:e.target.checked})),className:`w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-white`,children:i(`settings.readStatus`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.readStatusDescription`)})]})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:Ue.can_queue,onChange:e=>We(t=>({...t,can_queue:e.target.checked})),className:`w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-white`,children:i(`settings.manageQueue`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.manageQueueDescription`)})]})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:Ue.can_control_printer,onChange:e=>We(t=>({...t,can_control_printer:e.target.checked})),className:`w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-white`,children:i(`settings.controlPrinter`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.controlPrinterDescription`)})]})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:Ue.can_manage_library,onChange:e=>We(t=>({...t,can_manage_library:e.target.checked})),className:`w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-white`,children:i(`settings.manageLibrary`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.manageLibraryDescription`)})]})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:Ue.can_manage_inventory,onChange:e=>We(t=>({...t,can_manage_inventory:e.target.checked})),className:`w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-white`,children:i(`settings.manageInventory`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.manageInventoryDescription`)})]})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:Ue.can_manage_maintenance,onChange:e=>We(t=>({...t,can_manage_maintenance:e.target.checked})),className:`w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-white`,children:i(`settings.manageMaintenance`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.manageMaintenanceDescription`)})]})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:Ue.can_manage_archives,onChange:e=>We(t=>({...t,can_manage_archives:e.target.checked})),className:`w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-white`,children:i(`settings.manageArchives`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.manageArchivesDescription`)})]})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:Ue.can_manage_projects,onChange:e=>We(t=>({...t,can_manage_projects:e.target.checked})),className:`w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-white`,children:i(`settings.manageProjects`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.manageProjectsDescription`)})]})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:Ue.can_access_cloud,onChange:e=>We(t=>({...t,can_access_cloud:e.target.checked})),className:`w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-white`,children:i(`settings.cloudAccess`,`Allow cloud access`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.cloudAccessDescription`,`Read Bambu Cloud presets and filaments on your behalf. Requires you to be signed into Bambu Cloud.`)})]})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:Ue.can_update_energy_cost,onChange:e=>We(t=>({...t,can_update_energy_cost:e.target.checked})),className:`w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-white`,children:i(`settings.updateEnergyCost`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.updateEnergyCostDescription`)})]})]})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 pt-2`,children:[(0,G.jsxs)(Q,{onClick:()=>an.mutate({name:Ve||i(`settings.unnamedKey`),...Ue}),disabled:an.isPending,children:[an.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Fl,{className:`w-4 h-4`}),i(`settings.createKey`)]}),(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>Be(!1),children:i(`common.cancel`)})]})]})]}),rn?(0,G.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,G.jsx)(Y,{className:`w-8 h-8 text-bambu-green animate-spin`})}):nn&&nn.length>0?(0,G.jsx)(`div`,{className:`space-y-3`,children:nn.map(e=>(0,G.jsx)(zd,{children:(0,G.jsx)(Vd,{className:`py-3`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(Kc,{className:`w-5 h-5 ${e.enabled?`text-bambu-green`:`text-bambu-gray`}`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white font-medium`,children:e.name}),(0,G.jsxs)(`p`,{className:`text-xs text-bambu-gray`,children:[e.key_prefix,`••••••••`,e.last_used&&` · ${i(`settings.lastUsed`)}: ${ap(e.last_used)}`]})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`div`,{className:`flex gap-1 text-xs flex-wrap justify-end`,children:[e.can_read_status&&(0,G.jsx)(`span`,{className:`px-1.5 py-0.5 bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400 rounded`,children:i(`settings.read`)}),e.can_queue&&(0,G.jsx)(`span`,{className:`px-1.5 py-0.5 bg-green-100 dark:bg-green-500/20 text-green-700 dark:text-green-400 rounded`,children:i(`queue.title`)}),e.can_control_printer&&(0,G.jsx)(`span`,{className:`px-1.5 py-0.5 bg-orange-100 dark:bg-orange-500/20 text-orange-700 dark:text-orange-400 rounded`,children:i(`settings.control`)}),e.can_manage_library&&(0,G.jsx)(`span`,{className:`px-1.5 py-0.5 bg-cyan-100 dark:bg-cyan-500/20 text-cyan-700 dark:text-cyan-400 rounded`,children:i(`settings.libraryBadge`)}),e.can_manage_inventory&&(0,G.jsx)(`span`,{className:`px-1.5 py-0.5 bg-pink-100 dark:bg-pink-500/20 text-pink-700 dark:text-pink-400 rounded`,children:i(`settings.inventoryBadge`)}),e.can_manage_maintenance&&(0,G.jsx)(`span`,{className:`px-1.5 py-0.5 bg-teal-100 dark:bg-teal-500/20 text-teal-700 dark:text-teal-400 rounded`,children:i(`settings.maintenanceBadge`)}),e.can_manage_archives&&(0,G.jsx)(`span`,{className:`px-1.5 py-0.5 bg-indigo-100 dark:bg-indigo-500/20 text-indigo-700 dark:text-indigo-400 rounded`,children:i(`settings.archivesBadge`)}),e.can_manage_projects&&(0,G.jsx)(`span`,{className:`px-1.5 py-0.5 bg-lime-100 dark:bg-lime-500/20 text-lime-700 dark:text-lime-400 rounded`,children:i(`settings.projectsBadge`)}),e.can_access_cloud&&(0,G.jsx)(`span`,{className:`px-1.5 py-0.5 bg-purple-100 dark:bg-purple-500/20 text-purple-700 dark:text-purple-400 rounded`,children:i(`settings.cloudBadge`,`Cloud`)}),e.can_update_energy_cost&&(0,G.jsx)(`span`,{className:`px-1.5 py-0.5 bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-400 rounded`,children:i(`settings.energyCostBadge`)}),e.user_id===null&&(0,G.jsx)(`span`,{className:`px-1.5 py-0.5 bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400 rounded`,title:i(`settings.legacyKeyTooltip`,`Created before per-user ownership; recreate to use cloud access`),children:i(`settings.legacyKey`,`Legacy`)})]}),(0,G.jsx)(Q,{variant:`secondary`,size:`sm`,onClick:()=>Xe(e.id),children:(0,G.jsx)(Pu,{className:`w-4 h-4 text-red-600 dark:text-red-400`})})]})]})})},e.id))}):(0,G.jsx)(zd,{children:(0,G.jsx)(Vd,{className:`py-12`,children:(0,G.jsxs)(`div`,{className:`text-center text-bambu-gray`,children:[(0,G.jsx)(Kc,{className:`w-16 h-16 mx-auto mb-4 opacity-30`}),(0,G.jsx)(`p`,{className:`text-lg font-medium text-white mb-2`,children:i(`settings.apiKeysEmptyTitle`)}),(0,G.jsx)(`p`,{className:`text-sm mb-4`,children:i(`settings.apiKeysEmptyDescription`)}),(0,G.jsxs)(Q,{onClick:()=>Be(!0),children:[(0,G.jsx)(Fl,{className:`w-4 h-4`}),i(`settings.createFirstKey`)]})]})})}),(0,G.jsxs)(zd,{className:`mt-6`,children:[(0,G.jsx)(Bd,{children:(0,G.jsx)(`h3`,{className:`text-base font-semibold text-white`,id:`card-webhooks`,children:i(`settings.webhookEndpoints`)})}),(0,G.jsxs)(Vd,{className:`space-y-3 text-sm`,children:[(0,G.jsx)(`p`,{className:`text-bambu-gray`,children:i(`settings.webhookApiKeyHint`)}),(0,G.jsxs)(`div`,{className:`space-y-2 font-mono text-xs`,children:[(0,G.jsxs)(`div`,{className:`p-2 bg-bambu-dark rounded`,children:[(0,G.jsx)(`span`,{className:`text-blue-700 dark:text-blue-400`,children:`GET`}),` `,(0,G.jsx)(`span`,{className:`text-white`,children:`/api/v1/webhook/status`}),(0,G.jsxs)(`span`,{className:`text-bambu-gray`,children:[` - `,i(`settings.webhook.getAllStatus`)]})]}),(0,G.jsxs)(`div`,{className:`p-2 bg-bambu-dark rounded`,children:[(0,G.jsx)(`span`,{className:`text-blue-700 dark:text-blue-400`,children:`GET`}),` `,(0,G.jsx)(`span`,{className:`text-white`,children:`/api/v1/webhook/status/:id`}),(0,G.jsxs)(`span`,{className:`text-bambu-gray`,children:[` - `,i(`settings.webhook.getSpecificStatus`)]})]}),(0,G.jsxs)(`div`,{className:`p-2 bg-bambu-dark rounded`,children:[(0,G.jsx)(`span`,{className:`text-green-700 dark:text-green-400`,children:`POST`}),` `,(0,G.jsx)(`span`,{className:`text-white`,children:`/api/v1/webhook/queue`}),(0,G.jsxs)(`span`,{className:`text-bambu-gray`,children:[` - `,i(`settings.webhook.addToQueue`)]})]}),(0,G.jsxs)(`div`,{className:`p-2 bg-bambu-dark rounded`,children:[(0,G.jsx)(`span`,{className:`text-orange-700 dark:text-orange-400`,children:`POST`}),` `,(0,G.jsx)(`span`,{className:`text-white`,children:`/api/v1/webhook/printer/:id/pause`}),(0,G.jsxs)(`span`,{className:`text-bambu-gray`,children:[` - `,i(`settings.webhook.pausePrint`)]})]}),(0,G.jsxs)(`div`,{className:`p-2 bg-bambu-dark rounded`,children:[(0,G.jsx)(`span`,{className:`text-orange-700 dark:text-orange-400`,children:`POST`}),` `,(0,G.jsx)(`span`,{className:`text-white`,children:`/api/v1/webhook/printer/:id/resume`}),(0,G.jsxs)(`span`,{className:`text-bambu-gray`,children:[` - `,i(`settings.webhook.resumePrint`)]})]}),(0,G.jsxs)(`div`,{className:`p-2 bg-bambu-dark rounded`,children:[(0,G.jsx)(`span`,{className:`text-red-700 dark:text-red-400`,children:`POST`}),` `,(0,G.jsx)(`span`,{className:`text-white`,children:`/api/v1/webhook/printer/:id/stop`}),(0,G.jsxs)(`span`,{className:`text-bambu-gray`,children:[` - `,i(`settings.webhook.stopPrint`)]})]})]})]})]})]}),(0,G.jsxs)(zd,{className:`mt-6`,children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,id:`card-camera-tokens`,children:[(0,G.jsx)(Gu,{className:`w-4 h-4 text-bambu-green`}),i(`cameraTokens.title`,`Camera API Tokens`)]})}),(0,G.jsx)(Vd,{children:(0,G.jsx)(MWe,{})})]}),(0,G.jsxs)(zd,{className:`mt-6`,children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,id:`card-stream-overlay`,children:[(0,G.jsx)(hl,{className:`w-4 h-4 text-bambu-green`}),i(`streamOverlay.builder.title`,`Streaming Overlay`)]})}),(0,G.jsx)(Vd,{children:(0,G.jsx)(PWe,{})})]})]}),d(`api_keys:read`)&&(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`mb-6`,children:[(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,id:`card-apibrowser`,children:[(0,G.jsx)(Ac,{className:`w-5 h-5 text-bambu-green`}),i(`settings.apiBrowser`)]}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:i(`settings.apiBrowserDescription`)})]}),(0,G.jsx)(zd,{className:`mb-4`,children:(0,G.jsxs)(Vd,{className:`py-3`,children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-2`,children:i(`settings.apiKeyForTesting`)}),(0,G.jsx)(`input`,{type:`text`,value:Ze,onChange:e=>Qe(e.target.value),placeholder:i(`settings.apiKeyPlaceholder`),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white font-mono text-sm focus:border-bambu-green focus:outline-none`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-2`,children:i(`settings.apiKeyHint`)})]})}),(0,G.jsx)(GGe,{apiKey:Ze})]})]}),je===`virtual-printer`&&(0,G.jsx)(`div`,{id:`card-vp`,children:(0,G.jsx)(bGe,{})}),je===`spoolbuddy`&&(0,G.jsx)(`div`,{id:`card-spoolbuddy`,children:(0,G.jsx)(SGe,{})}),je===`queue`&&(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{className:`flex gap-1 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`button`,{onClick:()=>Re(`dispatch`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${Fe===`dispatch`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,G.jsx)(Qc,{className:`w-4 h-4`}),i(`settings.tabs.queueDispatch`,`Queue & Dispatch`)]}),(0,G.jsxs)(`button`,{onClick:()=>Re(`pipelines`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${Fe===`pipelines`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,G.jsx)(ed,{className:`w-4 h-4`}),i(`settings.tabs.queuePipelines`,`Pipelines`)]})]}),Fe===`pipelines`&&(0,G.jsx)(wWe,{}),Fe===`dispatch`&&A&&(0,G.jsxs)(`div`,{className:`flex flex-col lg:flex-row gap-4 lg:gap-6`,children:[(0,G.jsxs)(`div`,{className:`lg:w-1/2 space-y-3`,children:[(0,G.jsxs)(zd,{id:`card-print-options`,children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(Qc,{className:`w-4 h-4 text-bambu-green`}),i(`settings.defaultPrintOptions`,`Default Print Options`)]})}),(0,G.jsxs)(Vd,{className:`space-y-3`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.defaultPrintOptionsDescription`,`Set default values for print options when starting new prints. These can be overridden per print in the print dialog.`)}),[{key:`default_bed_levelling`,label:i(`settings.defaultBedLevelling`,`Bed Levelling`),desc:i(`settings.defaultBedLevellingDesc`,`Auto-level bed before print`),fallback:!0,dualNozzleOnly:!1,tristate:!0},{key:`default_flow_cali`,label:i(`settings.defaultFlowCali`,`Flow Calibration`),desc:i(`settings.defaultFlowCaliDesc`,`Calibrate extrusion flow`),fallback:!1,dualNozzleOnly:!1,tristate:!0},{key:`default_vibration_cali`,label:i(`settings.defaultVibrationCali`,`Vibration Calibration`),desc:i(`settings.defaultVibrationCaliDesc`,`Reduce ringing artifacts`),fallback:!0,dualNozzleOnly:!1,tristate:!1},{key:`default_layer_inspect`,label:i(`settings.defaultLayerInspect`,`First Layer Inspection`),desc:i(`settings.defaultLayerInspectDesc`,`AI inspection of first layer`),fallback:!1,dualNozzleOnly:!1,tristate:!1},{key:`default_timelapse`,label:i(`settings.defaultTimelapse`,`Timelapse`),desc:i(`settings.defaultTimelapseDesc`,`Record timelapse video`),fallback:!1,dualNozzleOnly:!1,tristate:!1},{key:`default_nozzle_offset_cali`,label:i(`settings.defaultNozzleOffsetCali`,`Nozzle Offset Calibration`),desc:i(`settings.defaultNozzleOffsetCaliDesc`,`Calibrate nozzle offsets between extruders`),fallback:!0,dualNozzleOnly:!0,tristate:!0}].filter(({dualNozzleOnly:e})=>!e||(sn||[]).some(e=>e.nozzle_count===2)).map(({key:e,label:t,desc:n,fallback:r,tristate:a})=>(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex-1 mr-4`,children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:t}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:n})]}),a?(0,G.jsx)(`div`,{className:`flex gap-1 shrink-0`,children:PU.map(t=>(0,G.jsx)(`button`,{type:`button`,onClick:()=>yr(e,t),className:`px-2.5 py-1 text-xs rounded transition-colors ${(A[e]??`auto`)===t?FU[t]:`bg-bambu-dark-tertiary text-bambu-gray hover:text-white`}`,children:i(`settings.calibrationMode_${t}`)},t))}):(0,G.jsx)(`div`,{className:`flex gap-1 shrink-0`,children:[`off`,`on`].map(t=>(0,G.jsx)(`button`,{type:`button`,onClick:()=>yr(e,t===`on`),className:`px-2.5 py-1 text-xs rounded transition-colors ${(A[e]??r?`on`:`off`)===t?FU[t]:`bg-bambu-dark-tertiary text-bambu-gray hover:text-white`}`,children:i(`settings.calibrationMode_${t}`)},t))})]},e))]})]}),(0,G.jsxs)(zd,{id:`card-plate`,children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(su,{className:`w-4 h-4 text-bambu-green`}),i(`settings.plateClear`,`Plate-Clear Confirmation`)]})}),(0,G.jsx)(Vd,{className:`space-y-3`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex-1 mr-4`,children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:i(`settings.requirePlateClear`,`Require plate-clear confirmation`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.requirePlateClearDescription`,`When enabled, the scheduler waits for per-printer plate-clear confirmation before starting queued prints on printers with finished jobs. Disabling this also hides the plate status badge and the "Mark plate as cleared" button on printer cards.`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.require_plate_clear??!1,onChange:e=>yr(`require_plate_clear`,e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]})})]}),(0,G.jsxs)(zd,{id:`card-temp-fan-presets`,children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(Mu,{className:`w-4 h-4 text-bambu-green`}),i(`settings.tempFanPresetsTitle`,`Temperature & Fan Presets`)]})}),(0,G.jsxs)(Vd,{className:`space-y-4`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.tempFanPresetsDescription`,`Customize the quick-select values shown in printer-card temperature and fan-speed popovers. The Off button is always shown.`)}),kee.map(e=>{let t=Am(A?.[e.key]??``,e.defaults,e.lo,e.hi),n=e.unit===`C`?`°C`:`%`;return(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-1`,children:[(0,G.jsxs)(`label`,{className:`text-sm text-white`,children:[i(`settings.${{nozzle_temp_presets:`tempFanPresetsNozzle`,bed_temp_presets:`tempFanPresetsBed`,chamber_temp_presets:`tempFanPresetsChamber`,fan_speed_presets:`tempFanPresetsFan`}[e.key]}`,{nozzle_temp_presets:`Nozzle temperature`,bed_temp_presets:`Bed temperature`,chamber_temp_presets:`Chamber temperature`,fan_speed_presets:`Fan speed`}[e.key]),` `,(0,G.jsxs)(`span`,{className:`text-bambu-gray text-xs`,children:[`(`,n,` · `,e.lo,`–`,e.hi,`)`]})]}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>yr(e.key,``),title:i(`settings.tempFanPresetsReset`,`Reset to defaults`),className:`text-bambu-gray hover:text-white transition-colors p-1 rounded hover:bg-bambu-dark-tertiary`,children:(0,G.jsx)(Wl,{className:`w-3.5 h-3.5`})})]}),(0,G.jsx)(`div`,{className:`flex gap-2`,children:[0,1,2].map(n=>(0,G.jsx)(`input`,{type:`number`,min:e.lo,max:e.hi,value:t[n],onChange:r=>{let i=[t[0],t[1],t[2]],a=parseInt(r.target.value,10);i[n]=Math.max(e.lo,Math.min(e.hi,Number.isFinite(a)?a:e.lo)),yr(e.key,JSON.stringify(i))},className:`flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`},n))})]},e.key)})]})]}),(0,G.jsxs)(zd,{id:`card-staggered`,children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(Jc,{className:`w-4 h-4 text-bambu-green`}),i(`settings.staggeredStart`,`Staggered Start`)]})}),(0,G.jsxs)(Vd,{className:`space-y-3`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.staggeredStartDescription`,`Default group size and interval when staggering multi-printer batch starts. Can be overridden per batch in the print modal.`)}),(0,G.jsxs)(`div`,{className:`flex gap-4`,children:[(0,G.jsxs)(`div`,{className:`flex-1`,children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.staggerGroupSize`,`Group size`)}),(0,G.jsx)(`input`,{type:`number`,min:1,max:50,value:A.stagger_group_size??2,onChange:e=>yr(`stagger_group_size`,Math.max(1,Math.min(50,parseInt(e.target.value)||1))),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.staggerGroupSizeHelp`,`Printers to start simultaneously per group`)})]}),(0,G.jsxs)(`div`,{className:`flex-1`,children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.staggerInterval`,`Interval (minutes)`)}),(0,G.jsx)(`input`,{type:`number`,min:1,max:60,value:A.stagger_interval_minutes??5,onChange:e=>yr(`stagger_interval_minutes`,Math.max(1,Math.min(60,parseInt(e.target.value)||1))),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.staggerIntervalHelp`,`Delay between each group starting`)})]})]})]})]}),(0,G.jsxs)(zd,{id:`card-concurrent-uploads`,children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(Ns,{className:`w-4 h-4 text-bambu-green`}),i(`settings.concurrentUploadsTitle`,`Concurrent Uploads`)]})}),(0,G.jsxs)(Vd,{className:`space-y-3`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.concurrentUploadsDescription`,`How many printers the queue may send files to at the same time. Printers receive files slowly (a large print can take several minutes), and each one waits its turn — so on a bigger fleet, raising this is what stops the last printer in a batch from waiting out every transfer before it. Lower it if your network or Bambuddy host struggles with parallel transfers.`)}),(0,G.jsxs)(`div`,{className:`w-full sm:w-1/2`,children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.concurrentUploadsLabel`,`Printers uploaded to at once`)}),(0,G.jsx)(`input`,{type:`number`,min:1,max:16,value:A.queue_max_concurrent_uploads??4,onChange:e=>yr(`queue_max_concurrent_uploads`,Math.max(1,Math.min(16,parseInt(e.target.value)||1))),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.concurrentUploadsHelp`,`1 sends to one printer at a time (the old behaviour). Default is 4.`)})]})]})]}),(0,G.jsxs)(zd,{id:`card-preheat`,children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(hc,{className:`w-4 h-4 text-amber-600 dark:text-amber-400`}),i(`settings.preheatTitle`,`Preheat & Heat Soak`)]})}),(0,G.jsxs)(Vd,{className:`space-y-3`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.preheatDescription`,`Heat the bed (and chamber, if supported) and hold at temperature before each queued print starts. Helpful for engineering filaments (PA, ABS) on printers without an active chamber heater — the bed warms the chamber by radiation while the soak timer runs. The bed target is read from the print file; chamber behaviour depends on printer model.`)}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex-1 mr-4`,children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:i(`settings.preheatEnabled`,`Enable preheat & soak`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:i(`settings.preheatEnabledDesc`,`When off, queued prints dispatch immediately.`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.preheat_enabled??!1,onChange:e=>yr(`preheat_enabled`,e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3 pt-1`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.preheatMaxWait`,`Max wait (seconds)`)}),(0,G.jsx)(`input`,{type:`number`,min:60,max:3600,value:A.preheat_max_wait_seconds??900,onChange:e=>yr(`preheat_max_wait_seconds`,Math.max(60,Math.min(3600,parseInt(e.target.value)||900))),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green disabled:opacity-50`,disabled:!(A.preheat_enabled??!1)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.preheatMaxWaitHelp`,`Cap on the chamber warm-up phase before falling through.`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.preheatSoak`,`Soak (seconds)`)}),(0,G.jsx)(`input`,{type:`number`,min:0,max:1800,value:A.preheat_soak_seconds??300,onChange:e=>yr(`preheat_soak_seconds`,Math.max(0,Math.min(1800,parseInt(e.target.value)||0))),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green disabled:opacity-50`,disabled:!(A.preheat_enabled??!1)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.preheatSoakHelp`,`Hold time after target reached or max-wait elapsed.`)})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between pt-2 border-t border-bambu-dark-tertiary/50`,children:[(0,G.jsxs)(`div`,{className:`flex-1 mr-4`,children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:i(`settings.keepBedWarm`,`Keep bed warm between prints`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:i(`settings.keepBedWarmDesc`,`While awaiting plate-clear, hold the bed at the keep-warm temperature below so the chamber stays hot — or at the next print's own bed temperature when that is higher. Only applies when the next print needs chamber heating (ASA, ABS, PA, PC etc.). Requires plate-clear confirmation to be enabled.`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.queue_keep_bed_warm??!1,onChange:e=>yr(`queue_keep_bed_warm`,e.target.checked),className:`sr-only peer`,disabled:!(A.preheat_enabled??!1)||!(A.require_plate_clear??!1)}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green peer-disabled:opacity-50 peer-disabled:cursor-not-allowed`})]})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-3 mt-2`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.keepWarmBedTemp`,`Keep-warm bed temperature (°C)`)}),(0,G.jsx)(`input`,{type:`number`,min:40,max:110,value:A.queue_keep_warm_bed_temp??90,onChange:e=>yr(`queue_keep_warm_bed_temp`,Math.max(40,Math.min(110,parseInt(e.target.value)||90))),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green disabled:opacity-50`,disabled:!(A.preheat_enabled??!1)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.keepWarmBedTempHelp`,`Used whenever the bed's job is to heat the chamber — the keep-warm hold, and preheat when the print file carries no bed temperature. A higher bed temperature from the print file always wins.`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.keepWarmMaxMinutes`,`Stop keeping warm after (minutes)`)}),(0,G.jsx)(`input`,{type:`number`,min:5,max:480,value:A.queue_keep_warm_max_minutes??120,onChange:e=>yr(`queue_keep_warm_max_minutes`,Math.max(5,Math.min(480,parseInt(e.target.value)||120))),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green disabled:opacity-50`,disabled:!(A.queue_keep_bed_warm??!1)||!(A.preheat_enabled??!1)||!(A.require_plate_clear??!1)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.keepWarmMaxMinutesHelp`,`If the plate is not cleared within this time, the heaters are switched off rather than held indefinitely.`)})]})]}),(0,G.jsxs)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary/50`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-1`,children:[(0,G.jsx)(`label`,{className:`text-sm text-white`,children:i(`settings.preheatFilamentTargetsLabel`,`Per-filament chamber target (°C)`)}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>yr(`preheat_filament_targets`,``),title:i(`settings.preheatFilamentTargetsReset`,`Reset to defaults`),className:`text-bambu-gray hover:text-white transition-colors p-1 rounded hover:bg-bambu-dark-tertiary`,children:(0,G.jsx)(Wl,{className:`w-3.5 h-3.5`})})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:i(`settings.preheatFilamentTargetsHint`,`Bambuddy picks the highest target across the loaded AMS slots; PLA-only prints derive 0 and skip the chamber phase automatically.`)}),(0,G.jsx)(SWe,{value:A.preheat_filament_targets??``,onChange:e=>yr(`preheat_filament_targets`,e),disabled:!(A.preheat_enabled??!1)})]}),(0,G.jsxs)(`p`,{className:`text-xs text-bambu-gray pt-1 border-t border-bambu-dark-tertiary/50`,children:[(0,G.jsx)(`span`,{className:`font-medium text-bambu-gray/90`,children:i(`settings.preheatHardwareTitle`,`Per-printer behaviour:`)}),` `,i(`settings.preheatHardwareDetail`,`H2C/H2D/H2D Pro/H2S/X2D/X1E actively heat the chamber via M141. X1C/P2S read chamber temp but rely on bed-radiation heating. P1S/P1P/A1/A1 Mini have no chamber sensor — only the soak timer applies.`)]})]})]})]}),(0,G.jsxs)(`div`,{className:`lg:w-1/2 space-y-3`,children:[(0,G.jsxs)(zd,{id:`card-pipelines`,children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(ed,{className:`w-4 h-4 text-bambu-green`}),i(`settings.pipelineLimits.title`,`Slicer Pipeline limits`)]})}),(0,G.jsx)(Vd,{className:`space-y-2`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,G.jsxs)(`div`,{className:`flex-1`,children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:i(`settings.pipelineLimits.maxCopiesLabel`,`Max copies per run`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:i(`settings.pipelineLimits.maxCopiesDesc`,`Upper bound on the copies operators can request when running a pipeline. Server-side hard cap is 1000.`)})]}),(0,G.jsx)(`input`,{type:`number`,min:1,max:1e3,value:A.pipeline_max_copies??50,onChange:e=>{let t=parseInt(e.target.value,10);Number.isNaN(t)||yr(`pipeline_max_copies`,Math.max(1,Math.min(1e3,t)))},"aria-label":i(`settings.pipelineLimits.maxCopiesLabel`,`Max copies per run`),className:`w-24 px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm`})]})})]}),(0,G.jsxs)(zd,{id:`card-slicer`,children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(Rs,{className:`w-4 h-4 text-bambu-green`}),i(`settings.slicerCard`,`Slicer`)]})}),(0,G.jsxs)(Vd,{className:`space-y-3`,children:[qGe()&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.sliceEngine`)}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(`select`,{value:G8(A.slice_engine),onChange:e=>yr(`slice_engine`,e.target.value),className:`w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer`,children:W8().map(e=>(0,G.jsx)(`option`,{value:e.id,children:i(e.labelKey)},e.id))}),(0,G.jsx)(ps,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(W8().find(e=>e.id===G8(A.slice_engine))?.descriptionKey??`settings.sliceEngineSidecarHint`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.preferredSlicer`)}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsxs)(`select`,{value:A.preferred_slicer??`bambu_studio`,onChange:e=>yr(`preferred_slicer`,e.target.value),className:`w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer`,children:[(0,G.jsx)(`option`,{value:`bambu_studio`,children:i(`settings.slicerBambuStudio`)}),(0,G.jsx)(`option`,{value:`orcaslicer`,children:i(`settings.slicerOrcaSlicer`)})]}),(0,G.jsx)(ps,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.preferredSlicerDescription`)}),(A.preferred_slicer??`bambu_studio`)===`orcaslicer`&&(0,G.jsx)(`div`,{role:`alert`,className:`text-xs text-amber-800 dark:text-amber-200 bg-amber-50 dark:bg-amber-900/20 border border-amber-300 dark:border-amber-700/40 rounded p-2 mt-2`,children:i(`settings.orcaslicerKnownIssuesWarning`,`OrcaSlicer 2.3.2 / 2.4.0-dev have known CLI bugs that block slicing many Bambu-authored 3MFs — see upstream issues #12426 (segfault on painted multi-extruder files) and #13386 (parameter-range strict-validation reject). Bambu Studio is recommended until the upstream fixes land.`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.openInSlicerLabel`,`Open in Slicer`)}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsxs)(`select`,{value:A.open_in_slicer??``,onChange:e=>yr(`open_in_slicer`,e.target.value===``?null:e.target.value),className:`w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer`,children:[(0,G.jsx)(`option`,{value:``,children:i(`settings.openInSlicerInherit`,`Same as API slicer`)}),(0,G.jsx)(`option`,{value:`bambu_studio`,children:i(`settings.slicerBambuStudio`)}),(0,G.jsx)(`option`,{value:`orcaslicer`,children:i(`settings.slicerOrcaSlicer`)})]}),(0,G.jsx)(ps,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.openInSlicerDescription`,`Desktop slicer used by the 'Open in Slicer' button. Leave on 'Same as API slicer' to inherit, or pick a different slicer to use locally.`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.useSlicerApi`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.useSlicerApiDescription`)})]}),(0,G.jsxs)(`label`,{className:`flex items-center cursor-pointer shrink-0`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.use_slicer_api??!1,onChange:e=>yr(`use_slicer_api`,e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`relative w-11 h-6 bg-bambu-dark-tertiary rounded-full peer peer-checked:bg-bambu-green peer-focus:outline-none peer-focus:ring-2 peer-focus:ring-bambu-green/50 transition-colors after:content-[''] after:absolute after:top-0.5 after:left-0.5 after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-transform peer-checked:after:translate-x-5`})]})]}),(A.use_slicer_api??!1)&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:(A.preferred_slicer??`bambu_studio`)===`orcaslicer`?i(`settings.orcaslicerApiUrl`,`OrcaSlicer sidecar URL`):i(`settings.bambuStudioApiUrl`,`Bambu Studio sidecar URL`)}),(0,G.jsx)(`input`,{type:`text`,value:((A.preferred_slicer??`bambu_studio`)===`orcaslicer`?A.orcaslicer_api_url:A.bambu_studio_api_url)??``,onChange:e=>yr((A.preferred_slicer??`bambu_studio`)===`orcaslicer`?`orcaslicer_api_url`:`bambu_studio_api_url`,e.target.value),placeholder:(A.preferred_slicer??`bambu_studio`)===`orcaslicer`?`http://localhost:3003`:`http://localhost:3001`,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:text-bambu-gray/40`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.slicerApiUrlDescription`,`URL of the slicer-API sidecar container. Leave blank to use the SLICER_API_URL / BAMBU_STUDIO_API_URL env var defaults.`)})]}),(A.use_slicer_api??!1)&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.slicerStallTimeout`)}),(0,G.jsx)(`input`,{type:`number`,min:1,max:240,value:A.slicer_stall_timeout_minutes??15,onChange:e=>yr(`slicer_stall_timeout_minutes`,Number(e.target.value)),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.slicerStallTimeoutDescription`)})]})]})]}),(0,G.jsxs)(zd,{children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,id:`card-drying`,children:[(0,G.jsx)(hc,{className:`w-4 h-4 text-amber-600 dark:text-amber-400`}),i(`settings.queueDrying`)]})}),(0,G.jsxs)(Vd,{className:`space-y-3`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.queueDryingDescription`)}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-white`,children:i(`settings.queueDryingEnabled`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:i(`settings.queueDryingEnabledDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.queue_drying_enabled??!1,onChange:e=>yr(`queue_drying_enabled`,e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),A.queue_drying_enabled&&(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-white`,children:i(`settings.queueDryingBlock`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:i(`settings.queueDryingBlockDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.queue_drying_block??!1,onChange:e=>yr(`queue_drying_block`,e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-amber-500`})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-white`,children:i(`settings.ambientDryingEnabled`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:i(`settings.ambientDryingEnabledDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.ambient_drying_enabled??!1,onChange:e=>yr(`ambient_drying_enabled`,e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-white`,children:i(`settings.printDryingEnabled`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:i(`settings.printDryingEnabledDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.print_drying_enabled??!1,onChange:e=>yr(`print_drying_enabled`,e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`p`,{className:`text-sm text-white font-medium`,children:i(`settings.dryingPresets`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.dryingPresetsDescription`)}),(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`,children:i(`settings.dryingFilament`)}),(0,G.jsx)(`th`,{className:`text-center py-1.5`,colSpan:2,children:`AMS 2 Pro`}),(0,G.jsx)(`th`,{className:`text-center py-1.5`,colSpan:2,children:`AMS-HT`})]})}),(0,G.jsx)(`tbody`,{children:(()=>{let e={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}},t={...e};try{if(A.drying_presets){let n=JSON.parse(A.drying_presets);typeof n==`object`&&n&&(t={...e,...n})}}catch{}let n=(e,n,r)=>{let i={...t,[e]:{...t[e],[n]:r}};yr(`drying_presets`,JSON.stringify(i))};return Object.entries(t).map(([e,t])=>(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/50`,children:[(0,G.jsx)(`td`,{className:`py-1.5 pr-2 text-white font-medium`,children:e}),(0,G.jsx)(`td`,{className:`py-1 px-1`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-end gap-1`,children:[(0,G.jsx)(`input`,{type:`number`,min:30,max:65,value:t.n3f,onChange:t=>n(e,`n3f`,Math.max(1,parseInt(t.target.value)||0)),className:`w-14 px-1.5 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-center text-xs focus:border-amber-500/50 focus:outline-none [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none`}),(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:`°C`})]})}),(0,G.jsx)(`td`,{className:`py-1 px-1`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(`input`,{type:`number`,min:1,max:24,value:t.n3f_hours,onChange:t=>n(e,`n3f_hours`,Math.max(1,parseInt(t.target.value)||0)),className:`w-14 px-1.5 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-center text-xs focus:border-amber-500/50 focus:outline-none [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none`}),(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:`h`})]})}),(0,G.jsx)(`td`,{className:`py-1 px-1`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-end gap-1`,children:[(0,G.jsx)(`input`,{type:`number`,min:30,max:85,value:t.n3s,onChange:t=>n(e,`n3s`,Math.max(1,parseInt(t.target.value)||0)),className:`w-14 px-1.5 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-center text-xs focus:border-amber-500/50 focus:outline-none [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none`}),(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:`°C`})]})}),(0,G.jsx)(`td`,{className:`py-1 px-1`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(`input`,{type:`number`,min:1,max:24,value:t.n3s_hours,onChange:t=>n(e,`n3s_hours`,Math.max(1,parseInt(t.target.value)||0)),className:`w-14 px-1.5 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-center text-xs focus:border-amber-500/50 focus:outline-none [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none`}),(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:`h`})]})})]},e))})()})]})})]}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`p`,{className:`text-sm text-white font-medium`,children:i(`settings.humidityThresholds`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.humidityThresholdsDescription`)}),(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`,children:i(`settings.dryingFilament`)}),(0,G.jsx)(`th`,{className:`text-right py-1.5 pr-2`,children:i(`settings.humidityThresholdCol`)})]})}),(0,G.jsx)(`tbody`,{children:(()=>{let e=A.ams_humidity_fair??60,t=[`PLA`,`PETG`,`TPU`,`ABS`,`ASA`,`PA`,`PC`,`PVA`],n={};try{if(A.ams_humidity_thresholds){let e=JSON.parse(A.ams_humidity_thresholds);typeof e==`object`&&e&&(n=e)}}catch{}let r=[{key:`default`,label:i(`settings.humidityThresholdDefault`),value:Number(n.default??e),isDefault:!0},...t.map(t=>({key:t,label:t,value:Number(n[t]??n.default??e),isDefault:!1}))],a=(e,t)=>{if(t.trim()===``){let t={...n};delete t[e],yr(`ams_humidity_thresholds`,JSON.stringify(t));return}let r=parseInt(t,10);if(Number.isNaN(r))return;let i=Math.max(5,Math.min(95,r)),a={...n,[e]:i};yr(`ams_humidity_thresholds`,JSON.stringify(a))};return r.map(e=>{let t=M[e.key],n=t===void 0?String(e.value):t;return(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/50`,children:[(0,G.jsx)(`td`,{className:`py-1.5 pr-2 font-medium ${e.isDefault?`text-bambu-gray italic`:`text-white`}`,children:e.label}),(0,G.jsx)(`td`,{className:`py-1 pr-2`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-end gap-1`,children:[(0,G.jsx)(`input`,{type:`number`,min:5,max:95,value:n,onChange:t=>N(n=>({...n,[e.key]:t.target.value})),onBlur:t=>{a(e.key,t.target.value),N(t=>{let n={...t};return delete n[e.key],n})},onKeyDown:e=>{e.key===`Enter`&&e.currentTarget.blur()},className:`w-14 px-1.5 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-center text-xs focus:border-amber-500/50 focus:outline-none [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none`}),(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:`%`})]})})]},e.key)})})()})]})})]})]})]}),(0,G.jsxs)(zd,{id:`card-gcode`,children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(Fs,{className:`w-4 h-4 text-bambu-green`}),i(`settings.gcodeInjection`,`G-code Injection`)]})}),(0,G.jsxs)(Vd,{className:`space-y-3`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.gcodeInjectionDescription`,`Configure custom G-code to inject at the start and/or end of prints for auto-print systems like Farmloop, SwapMod, AutoClear, and Printflow 3D. Snippets are configured per printer model and applied when "Inject G-code" is enabled on a queue item.`)}),(()=>{let e=(()=>{try{return A.gcode_snippets?JSON.parse(A.gcode_snippets):{}}catch{return{}}})(),t=[...new Set((sn||[]).filter(e=>e.model).map(e=>e.model))].sort(),n=(t,n,r)=>{let i={...e};i[t]||(i[t]={start_gcode:``,end_gcode:``}),i[t][n]=r,!i[t].start_gcode&&!i[t].end_gcode&&delete i[t];let a=Object.keys(i).length>0?JSON.stringify(i):``;j(e=>e?{...e,gcode_snippets:a}:null),pr.current=a},r=()=>{pr.current!==null&&(_r.mutate({gcode_snippets:pr.current}),pr.current=null)};return t.length===0?(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray italic`,children:i(`settings.gcodeInjectionNoPrinters`,`No printers found. Add printers to configure G-code snippets.`)}):t.map(t=>{let a=e[t]||{start_gcode:``,end_gcode:``},o=!!(a.start_gcode||a.end_gcode);return(0,G.jsx)($p,{defaultOpen:o,className:`border border-bambu-dark-tertiary rounded-lg px-3 py-2`,summary:(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`h4`,{className:`text-sm font-medium text-white`,children:t}),o&&(0,G.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-bambu-green/20 text-bambu-green`,children:i(`settings.gcodeConfigured`,`Configured`)})]}),children:(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.gcodeStartLabel`,`Start G-code`)}),(0,G.jsx)(`textarea`,{value:a.start_gcode,onChange:e=>n(t,`start_gcode`,e.target.value),onBlur:r,placeholder:i(`settings.gcodeStartPlaceholder`,`G-code prepended before the print starts...`),rows:3,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-xs font-mono focus:outline-none focus:border-bambu-green resize-y`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.gcodeEndLabel`,`End G-code`)}),(0,G.jsx)(`textarea`,{value:a.end_gcode,onChange:e=>n(t,`end_gcode`,e.target.value),onBlur:r,placeholder:i(`settings.gcodeEndPlaceholder`,`G-code appended after the print ends...`),rows:3,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-xs font-mono focus:outline-none focus:border-bambu-green resize-y`})]})]})},t)})})()]})]})]})]})]}),je===`filament`&&A&&(0,G.jsx)(G.Fragment,{children:(0,G.jsxs)(`div`,{className:`flex flex-col lg:flex-row gap-4 lg:gap-6`,children:[(0,G.jsxs)(`div`,{className:`lg:w-1/3 space-y-3`,children:[(0,G.jsx)(uGe,{}),(0,G.jsxs)(zd,{id:`card-filamentchecks`,children:[(0,G.jsx)(Bd,{children:(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(`settings.filamentChecks`)})}),(0,G.jsxs)(Vd,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.disableFilamentWarnings`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.disableFilamentWarningsDesc`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.disable_filament_warnings,onChange:e=>yr(`disable_filament_warnings`,e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.preferLowestFilament`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.preferLowestFilamentDesc`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray/70 mt-1`,children:i(`settings.preferLowestFilamentBackupNote`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.prefer_lowest_filament,onChange:e=>yr(`prefer_lowest_filament`,e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]})]})]}),(0,G.jsxs)(zd,{id:`card-printmodal`,children:[(0,G.jsx)(Bd,{children:(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(`settings.printModal`)})}),(0,G.jsx)(Vd,{className:`space-y-3`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.expandCustomMapping`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.expandCustomMappingDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.per_printer_mapping_expanded??!1,onChange:e=>yr(`per_printer_mapping_expanded`,e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]})})]}),(0,G.jsxs)(zd,{id:`card-amsthresholds`,children:[(0,G.jsx)(Bd,{children:(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(`settings.amsDisplayThresholds`)})}),(0,G.jsxs)(Vd,{className:`space-y-3`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.amsThresholdsDescription`)}),(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-white`,children:[(0,G.jsx)(Qs,{className:`w-4 h-4 text-blue-600 dark:text-blue-400`}),(0,G.jsx)(`span`,{className:`font-medium`,children:i(`settings.humidity`)})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[i(`settings.goodGreen`),` ≤`]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`input`,{type:`number`,min:`0`,max:`100`,value:A.ams_humidity_good??40,onChange:e=>yr(`ams_humidity_good`,parseInt(e.target.value)||40),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:`%`})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[i(`settings.fairOrange`),` ≤`]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`input`,{type:`number`,min:`0`,max:`100`,value:A.ams_humidity_fair??60,onChange:e=>yr(`ams_humidity_fair`,parseInt(e.target.value)||60),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:`%`})]})]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.aboveFairBad`)}),(0,G.jsx)(`p`,{className:`text-xs text-amber-700/80 dark:text-amber-400/70`,children:i(`settings.fairAlsoDryingThreshold`)}),(A.ams_humidity_fair??60)yr(`ams_temp_good`,parseFloat(e.target.value)||28),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:`°C`})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[i(`settings.fairOrange`),` ≤`]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`input`,{type:`number`,step:`0.5`,min:`0`,max:`60`,value:A.ams_temp_fair??35,onChange:e=>yr(`ams_temp_fair`,parseFloat(e.target.value)||35),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:`°C`})]})]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.aboveFairHot`)}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.tempAlarmThreshold`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`input`,{type:`number`,step:`0.5`,min:`0.5`,max:`120`,value:A.ams_temp_alarm??``,placeholder:String(A.ams_temp_fair??35),onChange:e=>{let t=e.target.value.trim(),n=parseFloat(t);yr(`ams_temp_alarm`,t===``||Number.isNaN(n)?null:n)},className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:`°C`})]})]}),(A.ams_temp_alarm??1)<=0&&(0,G.jsx)(`p`,{className:`text-xs text-red-600 dark:text-red-400`,children:i(`settings.tempAlarmMustBePositive`)}),(0,G.jsx)(`p`,{className:`text-xs text-amber-700/80 dark:text-amber-400/70`,children:i(`settings.tempAlarmSeparateFromBand`)})]}),(0,G.jsxs)(`div`,{className:`space-y-3 pt-4 border-t border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-white`,children:[(0,G.jsx)(Gs,{className:`w-4 h-4 text-purple-600 dark:text-purple-400`}),(0,G.jsx)(`span`,{className:`font-medium`,children:i(`settings.historyRetention`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.keepSensorHistory`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`input`,{type:`number`,min:`1`,max:`365`,value:A.ams_history_retention_days??30,onChange:e=>yr(`ams_history_retention_days`,parseInt(e.target.value)||30),className:`w-24 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:i(`common.days`)})]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.historyRetentionDescription`)})]})]})]})]}),(0,G.jsxs)(`div`,{className:`lg:w-2/3 space-y-3`,children:[(0,G.jsx)(dGe,{}),(0,G.jsx)(fGe,{})]})]})}),Ye!==null&&(0,G.jsx)(of,{title:i(`settings.deleteApiKeyTitle`),message:i(`settings.deleteApiKeyMessage`),confirmText:i(`settings.deleteKey`),variant:`danger`,onConfirm:()=>{on.mutate(Ye),Xe(null)},onCancel:()=>Xe(null)}),P&&(0,G.jsx)(IWe,{plug:I,onClose:()=>{F(!1),L(null)}}),R&&(0,G.jsx)(LWe,{sensor:B,printers:sn??[],onClose:()=>{z(!1),V(null)}}),ee&&(0,G.jsx)(zWe,{sensor:ne,locations:un??[],onClose:()=>{te(!1),re(null)}}),ie&&(0,G.jsx)(HWe,{onClose:()=>ae(!1)}),le&&(0,G.jsx)(of,{title:i(`locationHaSensors.deleteAllConfirm.title`),message:i(`locationHaSensors.deleteAllConfirm.message`,{location:le.locationName,count:le.sensorIds.length}),variant:`danger`,isLoading:pn.isPending,onConfirm:()=>pn.mutate(le.sensorIds),onCancel:()=>ue(null)}),de&&(0,G.jsx)(GWe,{provider:pe,onClose:()=>{fe(!1),me(null)}}),he&&(0,G.jsx)(KWe,{template:he,onClose:()=>ge(null)}),xe&&(0,G.jsx)(JWe,{onClose:()=>Se(!1)}),$e&&(0,G.jsx)(of,{title:i(`settings.clearNotificationLogs`),message:i(`settings.clearLogsMessage`),confirmText:i(`settings.clearLogs`),variant:`warning`,onConfirm:async()=>{et(!1);try{o((await Z.clearNotificationLogs(30)).message,`success`)}catch{o(i(`settings.toast.clearLogsFailed`),`error`)}},onCancel:()=>et(!1)}),tt&&(0,G.jsx)(of,{title:i(`settings.resetUiPreferences`),message:i(`settings.resetUiPreferencesMessage`),confirmText:i(`settings.resetPreferences`),variant:`default`,onConfirm:()=>{nt(!1),localStorage.clear(),o(i(`settings.toast.uiPreferencesReset`),`success`),setTimeout(()=>window.location.reload(),1e3)},onCancel:()=>nt(!1)}),rt&&(0,G.jsx)(of,{title:`Turn All Plugs ${rt===`on`?`On`:`Off`}`,message:`This will turn ${rt===`on`?`ON`:`OFF`} all ${Zt?.filter(e=>e.enabled).length||0} enabled smart plugs. ${rt===`off`?`Any running printers may be affected!`:``}`,confirmText:`Turn All ${rt===`on`?`On`:`Off`}`,variant:rt===`off`?`danger`:`warning`,onConfirm:()=>{let e=rt;it(null),dr.mutate(e)},onCancel:()=>it(null)}),at&&Pn?.release_notes&&(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,onClick:()=>ot(!1),children:(0,G.jsxs)(zd,{className:`w-full max-w-2xl max-h-[80vh] flex flex-col`,onClick:e=>e.stopPropagation(),children:[(0,G.jsxs)(Bd,{className:`flex flex-row items-center justify-between shrink-0`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white`,children:[`Release Notes - v`,Pn.latest_version]}),Pn.release_name&&Pn.release_name!==Pn.latest_version&&(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:Pn.release_name})]}),(0,G.jsx)(`button`,{onClick:()=>ot(!1),className:`p-1 rounded hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white`,children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]}),(0,G.jsx)(Vd,{className:`overflow-y-auto flex-1`,children:(0,G.jsx)(`pre`,{className:`text-sm text-bambu-gray whitespace-pre-wrap font-sans`,children:Pn.release_notes})}),(0,G.jsxs)(`div`,{className:`p-4 border-t border-bambu-dark-tertiary shrink-0 flex gap-2`,children:[Pn.release_url&&(0,G.jsx)(`a`,{href:Pn.release_url,target:`_blank`,rel:`noopener noreferrer`,className:`flex-1`,children:(0,G.jsxs)(Q,{variant:`secondary`,className:`w-full`,children:[(0,G.jsx)(rc,{className:`w-4 h-4`}),`View on GitHub`]})}),(0,G.jsx)(Q,{onClick:()=>ot(!1),className:`flex-1`,children:`Close`})]})]})}),je===`users`&&(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{className:`flex gap-1 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`button`,{onClick:()=>Pe(`users`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${Ne===`users`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,G.jsx)(Uu,{className:`w-4 h-4`}),i(`settings.tabs.users`)]}),(0,G.jsxs)(`button`,{onClick:()=>Pe(`email`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${Ne===`email`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,G.jsx)(al,{className:`w-4 h-4`}),i(`settings.tabs.emailAuth`)||`Email Authentication`,Hn?.advanced_auth_enabled&&(0,G.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-green-400`})]}),(0,G.jsxs)(`button`,{onClick:()=>Pe(`ldap`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${Ne===`ldap`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,G.jsx)(su,{className:`w-4 h-4`}),i(`settings.tabs.ldap`)||`LDAP`,Un?.ldap_enabled&&(0,G.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-green-400`})]}),(0,G.jsxs)(`button`,{onClick:()=>Pe(`twofa`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${Ne===`twofa`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,G.jsx)(su,{className:`w-4 h-4`}),i(`settings.tabs.twoFa`),(0,G.jsx)(`span`,{className:`w-2 h-2 rounded-full ${Wn?.totp_enabled||Wn?.email_otp_enabled?`bg-green-400`:`bg-bambu-gray/40`}`})]}),l&&(0,G.jsxs)(`button`,{onClick:()=>Pe(`oidc`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${Ne===`oidc`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,G.jsx)(Ac,{className:`w-4 h-4`}),i(`settings.tabs.oidc`),(0,G.jsx)(`span`,{className:`w-2 h-2 rounded-full ${Gn.some(e=>e.is_enabled)?`bg-green-400`:`bg-bambu-gray/40`}`})]}),l&&(0,G.jsxs)(`button`,{onClick:()=>Pe(`security`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${Ne===`security`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,G.jsx)(su,{className:`w-4 h-4`}),i(`settings.tabs.security`)]})]}),Ne===`users`&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(zd,{children:(0,G.jsx)(Vd,{className:`py-4`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`w-10 h-10 rounded-full flex items-center justify-center ${s?`bg-green-500/20`:`bg-gray-500/20`}`,children:s?(0,G.jsx)(nl,{className:`w-5 h-5 text-green-600 dark:text-green-400`}):(0,G.jsx)(tl,{className:`w-5 h-5 text-gray-400`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`text-white font-medium`,children:i(`settings.authentication`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(s?`settings.authEnabledDescription`:`settings.authDisabledDescription`)})]})]}),s?c?.is_admin&&(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>ct(!0),children:[(0,G.jsx)(tl,{className:`w-4 h-4`}),i(`common.disable`)]}):(0,G.jsxs)(Q,{onClick:()=>t(`/setup`),children:[(0,G.jsx)(nl,{className:`w-4 h-4`}),i(`common.enable`)]})]})})}),Hn?.advanced_auth_enabled&&(0,G.jsx)(zd,{className:`border-blue-500/30 bg-blue-500/5`,children:(0,G.jsx)(Vd,{className:`py-4`,children:(0,G.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,G.jsx)(`div`,{className:`w-10 h-10 rounded-full flex items-center justify-center bg-blue-500/20 flex-shrink-0`,children:(0,G.jsx)(al,{className:`w-5 h-5 text-blue-600 dark:text-blue-400`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`text-white font-medium`,children:i(`settings.email.advancedAuthEnabled`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:i(`settings.email.advancedAuthEnabledDesc`)})]})]})})}),s&&(0,G.jsxs)(`div`,{className:`grid grid-cols-1 xl:grid-cols-2 gap-6`,children:[(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(zd,{id:`card-session-policy`,children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`h3`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(nl,{className:`w-5 h-5 text-bambu-green`}),i(`settings.sessionPolicy.title`)]})}),(0,G.jsxs)(Vd,{children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4`,children:i(`settings.sessionPolicy.description`)}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 sm:grid-cols-4 gap-2 mb-4`,children:[[{hours:24,labelKey:`settings.sessionPolicy.preset24h`},{hours:168,labelKey:`settings.sessionPolicy.preset7d`},{hours:720,labelKey:`settings.sessionPolicy.preset30d`}].map(e=>{let t=(A?.session_max_hours??24)===e.hours;return(0,G.jsx)(`button`,{type:`button`,onClick:()=>yr(`session_max_hours`,e.hours),disabled:s&&!d(`settings:update`),className:`px-3 py-2 rounded-lg text-sm font-medium transition-colors ${t?`bg-bambu-green text-white`:`bg-bambu-dark-tertiary text-bambu-gray hover:text-white hover:bg-bambu-dark`} disabled:opacity-50 disabled:cursor-not-allowed`,children:i(e.labelKey)},e.hours)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(`input`,{type:`number`,min:1,max:720,value:A?.session_max_hours??24,onChange:e=>{let t=parseInt(e.target.value,10);Number.isNaN(t)||yr(`session_max_hours`,Math.max(1,Math.min(720,t)))},disabled:s&&!d(`settings:update`),"aria-label":i(`settings.sessionPolicy.customHoursLabel`),className:`w-20 px-2 py-2 bg-bambu-dark-tertiary text-white text-sm rounded-lg border border-bambu-dark-tertiary focus:border-bambu-green focus:outline-none disabled:opacity-50`}),(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:i(`settings.sessionPolicy.hoursSuffix`)})]})]}),(A?.session_max_hours??24)>24&&(0,G.jsxs)(`div`,{className:`flex items-start gap-2 p-3 rounded-lg bg-yellow-50 dark:bg-yellow-500/10 border border-yellow-300 dark:border-yellow-500/30`,children:[(0,G.jsx)(Lu,{className:`w-4 h-4 text-yellow-600 dark:text-yellow-400 flex-shrink-0 mt-0.5`}),(0,G.jsx)(`p`,{className:`text-xs text-yellow-800 dark:text-yellow-200`,children:i(`settings.sessionPolicy.warning`)})]})]})]}),c&&(0,G.jsxs)(zd,{children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`h3`,{className:`text-lg font-semibold text-white flex items-center gap-2`,id:`card-currentuser`,children:[(0,G.jsx)(Uu,{className:`w-5 h-5 text-bambu-green`}),i(`settings.currentUser`)]}),c.auth_source!==`ldap`&&(0,G.jsxs)(Q,{size:`sm`,variant:`ghost`,onClick:()=>ut(!0),children:[(0,G.jsx)(Kc,{className:`w-4 h-4`}),i(`settings.changePassword`)]})]})}),(0,G.jsx)(Vd,{children:(0,G.jsx)(`div`,{className:`flex items-center justify-between`,children:(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white font-medium text-lg`,children:c.username}),(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-1 mt-2`,children:[c.is_admin&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 rounded-full text-xs font-medium bg-purple-100 dark:bg-purple-500/20 text-purple-700 dark:text-purple-300`,children:i(`settings.admin`)}),c.groups?.map(e=>(0,G.jsx)(`span`,{className:`px-2 py-0.5 rounded-full text-xs font-medium ${e.name===`Administrators`?`bg-purple-100 dark:bg-purple-500/20 text-purple-700 dark:text-purple-300`:e.name===`Operators`?`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-300`:e.name===`Viewers`?`bg-green-100 dark:bg-green-500/20 text-green-700 dark:text-green-300`:`bg-gray-500/20 text-gray-300`}`,children:e.name},e.id))]})]})})})]}),(0,G.jsxs)(zd,{children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`h3`,{className:`text-lg font-semibold text-white flex items-center gap-2`,id:`card-users`,children:[(0,G.jsx)(Uu,{className:`w-5 h-5 text-bambu-green`}),i(`settings.users`)]}),d(`users:create`)&&(0,G.jsxs)(Q,{size:`sm`,onClick:()=>{vt(!0),Nt({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]})},children:[(0,G.jsx)(Fl,{className:`w-4 h-4`}),i(`settings.addUser`)]})]})}),(0,G.jsx)(Vd,{children:qn?(0,G.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,G.jsx)(Y,{className:`w-6 h-6 text-bambu-green animate-spin`})}):Kn.length===0?(0,G.jsx)(`p`,{className:`text-center text-bambu-gray py-8`,children:i(`settings.noUsersFound`)}):(0,G.jsx)(`div`,{className:`divide-y divide-bambu-dark-tertiary`,children:Kn.map(e=>(0,G.jsxs)(`div`,{className:`py-3 flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`p`,{className:`text-white font-medium truncate`,children:e.username}),(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-1 mt-1`,children:[e.auth_source===`ldap`&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 rounded-full text-xs font-medium bg-cyan-100 dark:bg-cyan-500/20 text-cyan-700 dark:text-cyan-300`,children:`LDAP`}),e.is_admin&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 rounded-full text-xs font-medium bg-purple-100 dark:bg-purple-500/20 text-purple-700 dark:text-purple-300`,children:i(`settings.admin`)}),e.groups?.map(e=>(0,G.jsx)(`span`,{className:`px-2 py-0.5 rounded-full text-xs font-medium ${e.name===`Administrators`?`bg-purple-100 dark:bg-purple-500/20 text-purple-700 dark:text-purple-300`:e.name===`Operators`?`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-300`:e.name===`Viewers`?`bg-green-100 dark:bg-green-500/20 text-green-700 dark:text-green-300`:`bg-gray-500/20 text-gray-300`}`,children:e.name},e.id))]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1 ml-4`,children:[d(`users:update`)&&(0,G.jsx)(Q,{size:`sm`,variant:`ghost`,onClick:()=>ir(e),children:(0,G.jsx)(kl,{className:`w-4 h-4`})}),d(`users:delete`)&&e.id!==c?.id&&(0,G.jsx)(Q,{size:`sm`,variant:`ghost`,onClick:()=>er(e.id),children:(0,G.jsx)(Pu,{className:`w-4 h-4`})})]})]},e.id))})})]})]}),(0,G.jsx)(`div`,{children:(0,G.jsxs)(zd,{children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`h3`,{className:`text-lg font-semibold text-white flex items-center gap-2`,id:`card-groups`,children:[(0,G.jsx)(su,{className:`w-5 h-5 text-bambu-green`}),i(`settings.groups`)]}),d(`groups:create`)&&(0,G.jsxs)(Q,{size:`sm`,onClick:()=>t(`/groups/new`),children:[(0,G.jsx)(Fl,{className:`w-4 h-4`}),i(`settings.addGroup`)]})]})}),(0,G.jsx)(Vd,{children:Yn?(0,G.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,G.jsx)(Y,{className:`w-6 h-6 text-bambu-green animate-spin`})}):Jn.length===0?(0,G.jsx)(`p`,{className:`text-center text-bambu-gray py-8`,children:i(`settings.noGroupsFound`)}):(0,G.jsx)(`div`,{className:`divide-y divide-bambu-dark-tertiary`,children:Jn.map(e=>(0,G.jsxs)(`div`,{className:`py-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(su,{className:`w-4 h-4 ${e.name===`Administrators`?`text-purple-600 dark:text-purple-400`:e.name===`Operators`?`text-blue-600 dark:text-blue-400`:e.name===`Viewers`?`text-green-600 dark:text-green-400`:`text-bambu-gray`}`}),(0,G.jsx)(`span`,{className:`text-white font-medium`,children:e.name}),e.is_system&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 rounded text-xs bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400`,children:i(`settings.system`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[d(`groups:update`)&&(0,G.jsx)(Q,{size:`sm`,variant:`ghost`,onClick:()=>t(`/groups/${e.id}/edit`),children:(0,G.jsx)(kl,{className:`w-4 h-4`})}),d(`groups:delete`)&&!e.is_system&&(0,G.jsx)(Q,{size:`sm`,variant:`ghost`,onClick:()=>Ft(e.id),children:(0,G.jsx)(Pu,{className:`w-4 h-4`})})]})]}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1 ml-6`,children:e.description||i(`settings.noDescription`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-4 mt-2 ml-6 text-xs text-bambu-gray`,children:[(0,G.jsx)(`span`,{children:i(`settings.userCount`,{count:e.user_count})}),(0,G.jsx)(`span`,{children:i(`settings.permissionCount`,{count:e.permissions.length})})]})]},e.id))})})]})})]}),!s&&(0,G.jsx)(zd,{children:(0,G.jsx)(Vd,{className:`py-6`,children:(0,G.jsxs)(`div`,{className:`text-center`,children:[(0,G.jsx)(tl,{className:`w-12 h-12 text-bambu-gray mx-auto mb-4`}),(0,G.jsx)(`h3`,{className:`text-lg font-medium text-white mb-2`,children:i(`settings.authDisabledTitle`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4 max-w-md mx-auto`,children:i(`settings.authDisabledMessage`)}),(0,G.jsxs)(`ul`,{className:`space-y-2 text-sm text-bambu-gray mb-6 text-left max-w-xs mx-auto`,children:[(0,G.jsxs)(`li`,{className:`flex items-start gap-2`,children:[(0,G.jsx)(xs,{className:`w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0`}),(0,G.jsx)(`span`,{children:i(`settings.authDisabledFeature1`)})]}),(0,G.jsxs)(`li`,{className:`flex items-start gap-2`,children:[(0,G.jsx)(xs,{className:`w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0`}),(0,G.jsx)(`span`,{children:i(`settings.authDisabledFeature2`)})]}),(0,G.jsxs)(`li`,{className:`flex items-start gap-2`,children:[(0,G.jsx)(xs,{className:`w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0`}),(0,G.jsx)(`span`,{children:i(`settings.authDisabledFeature3`)})]})]}),(0,G.jsxs)(Q,{onClick:()=>t(`/setup`),children:[(0,G.jsx)(nl,{className:`w-4 h-4`}),i(`settings.enableAuthentication`)]})]})})})]}),Ne===`email`&&(0,G.jsx)(`div`,{className:`max-w-5xl`,id:`card-smtp`,children:(0,G.jsx)(MGe,{})}),Ne===`ldap`&&(0,G.jsx)(`div`,{className:`max-w-5xl`,id:`card-ldap`,children:(0,G.jsx)(PGe,{})}),Ne===`twofa`&&(0,G.jsx)(`div`,{className:`max-w-2xl`,children:(0,G.jsx)(IGe,{})}),Ne===`oidc`&&l&&(0,G.jsxs)(`div`,{className:`max-w-3xl space-y-4`,children:[(0,G.jsx)(zd,{children:(0,G.jsx)(Vd,{className:`space-y-3 p-4`,children:(0,G.jsxs)(`label`,{className:`flex items-start gap-3 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.local_login_enabled===!1,onChange:e=>yr(`local_login_enabled`,!e.target.checked),className:`mt-1 h-4 w-4 rounded border-bambu-dark-tertiary bg-bambu-dark-secondary text-bambu-green focus:ring-bambu-green/50 cursor-pointer`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm font-medium text-white`,children:i(`settings.localLogin.disable`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:i(`settings.localLogin.disableHint`)})]})]})})}),(0,G.jsx)(zGe,{})]}),Ne===`security`&&l&&(0,G.jsx)(`div`,{className:`max-w-3xl`,children:(0,G.jsx)(VGe,{})})]}),_t&&!Hn?.advanced_auth_enabled&&(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black flex items-center justify-center z-50 p-4`,onClick:()=>{vt(!1),Nt({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]})},children:(0,G.jsxs)(zd,{className:`w-full max-w-md`,onClick:e=>e.stopPropagation(),children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Uu,{className:`w-5 h-5 text-bambu-green`}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(`settings.createUser`)})]}),(0,G.jsx)(Q,{variant:`ghost`,size:`sm`,onClick:()=>{vt(!1),Nt({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]})},children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]})}),(0,G.jsxs)(Vd,{children:[Un?.ldap_enabled&&(0,G.jsxs)(`div`,{className:`mb-4 flex items-center gap-1 p-1 bg-bambu-dark-secondary rounded-lg`,role:`tablist`,"aria-label":i(`users.modal.tabsAriaLabel`),children:[(0,G.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":yt===`local`,onClick:()=>bt(`local`),className:`flex-1 px-3 py-2 text-sm rounded-md transition-colors ${yt===`local`?`bg-bambu-green/15 text-bambu-green`:`text-bambu-gray hover:text-white`}`,children:i(`users.modal.localTab`)}),(0,G.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":yt===`ldap`,onClick:()=>bt(`ldap`),className:`flex-1 px-3 py-2 text-sm rounded-md transition-colors ${yt===`ldap`?`bg-bambu-green/15 text-bambu-green`:`text-bambu-gray hover:text-white`}`,children:i(`users.modal.ldapTab`)})]}),yt===`ldap`&&Un?.ldap_enabled?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(C8,{onSuccess:e=>{vt(!1),bt(`local`),Nt({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]}),o(i(`users.toast.ldapProvisioned`,{username:e.username}))}}),(0,G.jsx)(`div`,{className:`mt-6 flex justify-end`,children:(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>{vt(!1),bt(`local`),Nt({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]})},children:i(`common.cancel`)})})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:i(`settings.username`)}),(0,G.jsx)(`input`,{type:`text`,value:Mt.username,onChange:e=>Nt({...Mt,username:e.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:i(`settings.enterUsername`),autoComplete:`username`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:i(`settings.password`)}),(0,G.jsx)(`input`,{type:`password`,value:Mt.password,onChange:e=>Nt({...Mt,password:e.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:i(`settings.enterPassword`),autoComplete:`new-password`,minLength:8}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-xs mt-1`,children:i(`settings.passwordRequirements`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:i(`settings.confirmPassword`)}),(0,G.jsx)(`input`,{type:`password`,value:Mt.confirmPassword,onChange:e=>Nt({...Mt,confirmPassword:e.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors ${Mt.confirmPassword&&Mt.password!==Mt.confirmPassword?`border-red-500`:`border-bambu-dark-tertiary`}`,placeholder:i(`settings.confirmPasswordPlaceholder`),autoComplete:`new-password`,minLength:6}),Mt.confirmPassword&&Mt.password!==Mt.confirmPassword&&(0,G.jsx)(`p`,{className:`text-red-700 dark:text-red-400 text-xs mt-1`,children:i(`settings.passwordsDoNotMatch`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:i(`settings.groups`)}),(0,G.jsxs)(`div`,{className:`space-y-2 max-h-40 overflow-y-auto p-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg`,children:[Jn.map(e=>(0,G.jsxs)(`label`,{className:`flex items-center gap-3 px-2 py-1.5 rounded hover:bg-bambu-dark-tertiary cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:Mt.group_ids.includes(e.id),onChange:()=>ar(e.id),className:`w-4 h-4 rounded border-bambu-gray text-bambu-green focus:ring-bambu-green focus:ring-offset-0 bg-bambu-dark`}),(0,G.jsx)(`span`,{className:`text-sm text-white`,children:e.name}),e.is_system&&(0,G.jsx)(`span`,{className:`text-xs text-yellow-700 dark:text-yellow-400`,children:i(`settings.systemBadge`)})]},e.id)),Jn.length===0&&(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.noGroupsAvailable`)})]})]})]}),(0,G.jsxs)(`div`,{className:`mt-6 flex justify-end gap-3`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>{vt(!1),Nt({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]})},children:i(`common.cancel`)}),(0,G.jsx)(Q,{onClick:nr,disabled:Xn.isPending||!Mt.username||!Mt.password||Mt.password!==Mt.confirmPassword||_6(Mt.password)!==null,children:Xn.isPending?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),i(`settings.creating`)]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Fl,{className:`w-4 h-4`}),i(`settings.createUser`)]})})]})]})]})]})}),_t&&Hn?.advanced_auth_enabled&&(0,G.jsx)(lGe,{formData:Mt,setFormData:Nt,groups:Jn,onClose:()=>{vt(!1),Nt({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]})},onCreate:nr,isCreating:Xn.isPending,isCreateButtonDisabled:Xn.isPending||!Mt.username||!Mt.email,ldapEnabled:Un?.ldap_enabled,onLdapProvisioned:e=>{vt(!1),Nt({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]}),o(i(`users.toast.ldapProvisioned`,{username:e.username}))}}),xt&&Ct!==null&&(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black flex items-center justify-center z-50 p-4`,onClick:()=>{St(!1),wt(null),Nt({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]})},children:(0,G.jsxs)(zd,{className:`w-full max-w-md`,onClick:e=>e.stopPropagation(),children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(kl,{className:`w-5 h-5 text-bambu-green`}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(`settings.editUser`)})]}),(0,G.jsx)(Q,{variant:`ghost`,size:`sm`,onClick:()=>{St(!1),wt(null),Nt({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]})},children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]})}),(0,G.jsxs)(Vd,{children:[(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:[i(`settings.username`),` `,Hn?.advanced_auth_enabled&&(0,G.jsx)(`span`,{className:`text-red-700 dark:text-red-400`,children:`*`})]}),(0,G.jsx)(`input`,{type:`text`,value:Mt.username,onChange:e=>Nt({...Mt,username:e.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:i(`settings.enterUsername`),autoComplete:`username`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:[i(`users.form.email`)||`Email`,` `,Hn?.advanced_auth_enabled?(0,G.jsx)(`span`,{className:`text-red-700 dark:text-red-400`,children:`*`}):(0,G.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,i(`users.form.optional`)||`optional`,`)`]})]}),(0,G.jsx)(`input`,{type:`email`,value:Mt.email,onChange:e=>Nt({...Mt,email:e.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:i(`users.form.emailPlaceholder`)||`user@example.com`,required:Hn?.advanced_auth_enabled})]}),!Hn?.advanced_auth_enabled&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:[i(`users.form.password`)||`Password`,` `,(0,G.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,i(`users.form.leaveBlankToKeep`)||`leave blank to keep current`,`)`]})]}),(0,G.jsx)(`input`,{type:`password`,value:Mt.password,onChange:e=>Nt({...Mt,password:e.target.value,confirmPassword:``}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:i(`settings.enterNewPassword`),autoComplete:`new-password`,minLength:8}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-xs mt-1`,children:i(`settings.passwordRequirements`)})]}),Mt.password&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:i(`settings.confirmPassword`)}),(0,G.jsx)(`input`,{type:`password`,value:Mt.confirmPassword,onChange:e=>Nt({...Mt,confirmPassword:e.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors ${Mt.confirmPassword&&Mt.password!==Mt.confirmPassword?`border-red-500`:`border-bambu-dark-tertiary`}`,placeholder:i(`settings.confirmNewPassword`),autoComplete:`new-password`,minLength:6}),Mt.confirmPassword&&Mt.password!==Mt.confirmPassword&&(0,G.jsx)(`p`,{className:`text-red-700 dark:text-red-400 text-xs mt-1`,children:i(`settings.passwordsDoNotMatch`)})]})]}),Hn?.advanced_auth_enabled&&(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary/50 border border-bambu-green/20 rounded-lg p-3 space-y-3`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`users.form.passwordManagedByAdvancedAuth`)||`Password is managed by Advanced Authentication. Use "Reset Password" to send a new password to the user via email.`}),(0,G.jsx)(Q,{variant:`secondary`,size:`sm`,onClick:()=>Ct&&$n.mutate(Ct),disabled:$n.isPending||!Mt.email,className:`w-full`,children:$n.isPending?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),i(`users.form.resettingPassword`)||`Resetting Password...`]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Wl,{className:`w-4 h-4`}),i(`users.form.resetPassword`)||`Reset Password`]})})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:i(`users.form.groups`)||`Groups`}),(0,G.jsx)(`div`,{className:`space-y-2 max-h-40 overflow-y-auto p-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg`,children:Jn.map(e=>(0,G.jsxs)(`label`,{className:`flex items-center gap-3 px-2 py-1.5 rounded hover:bg-bambu-dark-tertiary cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:Mt.group_ids.includes(e.id),onChange:()=>ar(e.id),className:`w-4 h-4 rounded border-bambu-gray text-bambu-green focus:ring-bambu-green focus:ring-offset-0 bg-bambu-dark`}),(0,G.jsx)(`span`,{className:`text-sm text-white`,children:e.name}),e.is_system&&(0,G.jsxs)(`span`,{className:`text-xs text-yellow-700 dark:text-yellow-400`,children:[`(`,i(`users.system`)||`System`,`)`]})]},e.id))})]})]}),(0,G.jsxs)(`div`,{className:`mt-6 flex justify-end gap-3`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>{St(!1),wt(null),Nt({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]})},children:i(`users.modal.cancel`)||`Cancel`}),(0,G.jsx)(Q,{onClick:()=>rr(Ct),disabled:Zn.isPending||!Mt.username||Hn?.advanced_auth_enabled&&!Mt.email||!!(!Hn?.advanced_auth_enabled&&Mt.password&&(Mt.password!==Mt.confirmPassword||_6(Mt.password)!==null)),children:Zn.isPending?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),i(`users.modal.saving`)||`Saving...`]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(ql,{className:`w-4 h-4`}),i(`users.modal.saveChanges`)||`Save Changes`]})})]})]})]})}),Tt!==null&&(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/80 flex items-center justify-center z-50 p-4`,onClick:()=>{Et(null),Ot(null)},children:(0,G.jsxs)(zd,{className:`w-full max-w-md`,onClick:e=>e.stopPropagation(),children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-red-700 dark:text-red-400`,children:[(0,G.jsx)(Pu,{className:`w-5 h-5`}),(0,G.jsx)(`h3`,{className:`text-lg font-semibold`,children:i(`settings.deleteUserTitle`)})]})}),(0,G.jsx)(Vd,{className:`space-y-3`,children:At?(0,G.jsx)(`div`,{className:`flex items-center justify-center py-4`,children:(0,G.jsx)(`div`,{className:`animate-spin rounded-full h-6 w-6 border-2 border-bambu-green border-t-transparent`})}):Dt&&Dt.archives+Dt.queue_items+Dt.library_files>0?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.userHasCreated`)}),(0,G.jsxs)(`ul`,{className:`list-disc list-inside text-bambu-gray space-y-1`,children:[Dt.archives>0&&(0,G.jsxs)(`li`,{children:[Dt.archives,` archive`,Dt.archives===1?``:`s`]}),Dt.queue_items>0&&(0,G.jsxs)(`li`,{children:[Dt.queue_items,` queue item`,Dt.queue_items===1?``:`s`]}),Dt.library_files>0&&(0,G.jsxs)(`li`,{children:[Dt.library_files,` library file`,Dt.library_files===1?``:`s`]})]}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-sm`,children:i(`settings.userItemsQuestion`)}),(0,G.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,G.jsx)(Q,{variant:`danger`,onClick:()=>Qn.mutate({id:Tt,deleteItems:!0}),disabled:Qn.isPending,className:`justify-center`,children:i(`settings.deleteUserAndItems`)}),(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>Qn.mutate({id:Tt,deleteItems:!1}),disabled:Qn.isPending,className:`justify-center`,children:i(`settings.deleteUserKeepItems`)}),(0,G.jsx)(Q,{variant:`ghost`,onClick:()=>{Et(null),Ot(null)},disabled:Qn.isPending,className:`justify-center`,children:i(`common.cancel`)})]})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.deleteUserConfirm`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-sm`,children:i(`settings.actionCannotBeUndone`)}),(0,G.jsxs)(`div`,{className:`flex gap-2 justify-end`,children:[(0,G.jsx)(Q,{variant:`ghost`,onClick:()=>{Et(null),Ot(null)},disabled:Qn.isPending,children:i(`common.cancel`)}),(0,G.jsx)(Q,{variant:`danger`,onClick:()=>Qn.mutate({id:Tt,deleteItems:!1}),disabled:Qn.isPending,children:i(`settings.deleteUserTitle`)})]})]})})]})}),Pt!==null&&(0,G.jsx)(of,{title:i(`settings.deleteGroupTitle`),message:i(`settings.deleteGroupMessage`),confirmText:i(`settings.deleteGroup`),variant:`danger`,onConfirm:()=>{tr.mutate(Pt),Ft(null)},onCancel:()=>Ft(null)}),je===`failure-detection`&&(0,G.jsx)(`div`,{id:`card-failure-detection`,children:(0,G.jsx)(kGe,{})}),je===`backup`&&(0,G.jsxs)(`div`,{id:`card-backup`,children:[(0,G.jsxs)(`div`,{className:`mb-4 p-3 bg-amber-50 dark:bg-amber-500/10 border border-amber-300 dark:border-amber-500/30 rounded-lg flex items-start gap-2`,children:[(0,G.jsx)(su,{className:`text-amber-600 dark:text-amber-400 flex-shrink-0 mt-0.5`,size:16}),(0,G.jsx)(`p`,{className:`text-sm text-amber-700 dark:text-amber-400`,children:i(`backup.includesEncryptionKey`)})]}),(0,G.jsx)(OGe,{})]}),st&&(0,G.jsx)(of,{title:i(`settings.disableAuthenticationTitle`),message:i(`settings.disableAuthenticationMessage`),confirmText:i(`settings.disableAuthentication`),variant:`danger`,onConfirm:async()=>{try{await Z.disableAuth(),o(i(`settings.toast.authDisabled`),`success`),await u(),ct(!1),window.location.href=`/`}catch(e){o(e instanceof Error?e.message:i(`settings.toast.authDisableFailed`),`error`)}},onCancel:()=>ct(!1)}),lt&&(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:()=>{ut(!1),ft({currentPassword:``,newPassword:``,confirmPassword:``})},children:(0,G.jsxs)(zd,{className:`w-full max-w-md`,onClick:e=>e.stopPropagation(),children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Kc,{className:`w-5 h-5 text-bambu-green`}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(`settings.changePassword`)})]}),(0,G.jsx)(Q,{variant:`ghost`,size:`sm`,onClick:()=>{ut(!1),ft({currentPassword:``,newPassword:``,confirmPassword:``})},children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]})}),(0,G.jsxs)(Vd,{children:[(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:`Current Password`}),(0,G.jsx)(`input`,{type:`password`,value:dt.currentPassword,onChange:e=>ft({...dt,currentPassword:e.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:i(`settings.enterCurrentPassword`),autoComplete:`current-password`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:`New Password`}),(0,G.jsx)(`input`,{type:`password`,value:dt.newPassword,onChange:e=>ft({...dt,newPassword:e.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:i(`settings.enterNewPasswordMin6`),autoComplete:`new-password`,minLength:6})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:`Confirm New Password`}),(0,G.jsx)(`input`,{type:`password`,value:dt.confirmPassword,onChange:e=>ft({...dt,confirmPassword:e.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors ${dt.confirmPassword&&dt.newPassword!==dt.confirmPassword?`border-red-500`:`border-bambu-dark-tertiary`}`,placeholder:i(`settings.confirmNewPassword`),autoComplete:`new-password`,minLength:6}),dt.confirmPassword&&dt.newPassword!==dt.confirmPassword&&(0,G.jsx)(`p`,{className:`text-red-700 dark:text-red-400 text-xs mt-1`,children:i(`settings.passwordsDoNotMatch`)})]})]}),(0,G.jsxs)(`div`,{className:`mt-6 flex justify-end gap-3`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>{ut(!1),ft({currentPassword:``,newPassword:``,confirmPassword:``})},children:i(`common.cancel`)}),(0,G.jsx)(Q,{onClick:async()=>{if(dt.newPassword!==dt.confirmPassword){o(i(`settings.toast.passwordsDoNotMatch`),`error`);return}if(dt.newPassword.length<6){o(i(`settings.toast.passwordTooShort`),`error`);return}mt(!0);try{await Z.changePassword(dt.currentPassword,dt.newPassword),o(i(`settings.toast.passwordChanged`),`success`),ut(!1),ft({currentPassword:``,newPassword:``,confirmPassword:``})}catch(e){o(e instanceof Error?e.message:`Failed to change password`,`error`)}finally{mt(!1)}},disabled:pt||!dt.currentPassword||!dt.newPassword||dt.newPassword!==dt.confirmPassword||dt.newPassword.length<6,children:pt?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),i(`settings.changing`)]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Kc,{className:`w-4 h-4`}),i(`settings.changePassword`)]})})]})]})]})})]})]})]})})}var QGe=/\[(aborted|failed|cancelled):\s*([^\]]*)\]/i;function $Ge(e){if(!e)return{isPartial:!1,partialType:null,cleanedDescription:null};let t=e.match(QGe);if(!t)return{isPartial:!1,partialType:null,cleanedDescription:e};let n=e.replace(t[0],``).trim();return{isPartial:!0,partialType:t[1].toLowerCase(),cleanedDescription:n||null}}function eKe(e,t){if(!e)return`-`;let n=rp(e);return n?n.toLocaleString(t):e}function X8(e){let t=e.trim();if(!t)return null;let n=Number.parseFloat(t);return Number.isFinite(n)?n:null}function Z8(e){return`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,`0`)}-${String(e.getDate()).padStart(2,`0`)}T${String(e.getHours()).padStart(2,`0`)}:${String(e.getMinutes()).padStart(2,`0`)}`}var Q8=`w-full px-3 py-2 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded text-white placeholder-bambu-gray focus:outline-none focus:ring-1 focus:ring-bambu-green`,$8=`block text-sm font-medium text-white mb-1`,e5=`px-4 py-3 text-left text-bambu-gray font-medium`,t5=`px-4 py-3 align-top text-white`;function n5({title:e,onClose:t,children:n,size:r=`md`}){let{t:i}=U();return(0,G.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/70 p-4`,children:(0,G.jsxs)(`div`,{className:`w-full ${r===`sm`?`max-w-xl`:r===`lg`?`max-w-6xl`:`max-w-4xl`} overflow-hidden rounded-lg border border-bambu-dark-tertiary bg-bambu-dark-secondary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between border-b border-bambu-dark-tertiary px-4 py-3`,children:[(0,G.jsx)(`h3`,{className:`text-lg font-semibold text-white`,children:e}),(0,G.jsx)(Q,{size:`sm`,variant:`secondary`,onClick:t,children:i(`common.close`,`Close`)})]}),(0,G.jsx)(`div`,{className:`max-h-[75vh] overflow-auto p-4`,children:n})]})})}function tKe(){let{t:e,i18n:t}=U(),{hasPermission:n,user:r}=Nd(),{showToast:i}=qd(),a=co(),o=n(`cost_centers:read_own`),s=n(`cost_centers:read_all`),c=n(`cost_centers:create`),l=n(`cost_centers:modify`),u=n(`cost_centers:modify`),d=n(`cost_centers:modify`),f=n(`cost_centers:modify`),p=n(`users:read_slim`)||n(`users:read`),m=s||c||l||u||d||f,h=o||m,g=h,[_,v]=(0,y.useState)(``),[b,x]=(0,y.useState)(`monthly`),[S,C]=(0,y.useState)(``),[w,T]=(0,y.useState)(null),[E,D]=(0,y.useState)(`deposit`),[O,k]=(0,y.useState)(``),[A,j]=(0,y.useState)(``),[M,N]=(0,y.useState)(null),[P,F]=(0,y.useState)(null),[I,L]=(0,y.useState)(null),[R,z]=(0,y.useState)(!0),[B,V]=(0,y.useState)(0),[ee,te]=(0,y.useState)(`all`),[ne,re]=(0,y.useState)(`all`),[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)(`personal`),[pe,me]=(0,y.useState)(null),[he,ge]=(0,y.useState)(``),[_e,ve]=(0,y.useState)(`monthly`),[ye,be]=(0,y.useState)(``),[xe,Se]=(0,y.useState)(!1),[Ce,we]=(0,y.useState)(null),[Te,Ee]=(0,y.useState)(null),[De,Oe]=(0,y.useState)(null),[ke,Ae]=(0,y.useState)(``),[je,Me]=(0,y.useState)(``),[Ne,Pe]=(0,y.useState)(!1),[Fe,Ie]=(0,y.useState)(null),[Le,Re]=(0,y.useState)(null),[ze,Be]=(0,y.useState)(``),[Ve,He]=(0,y.useState)(``),[Ue,We]=(0,y.useState)(Z8(new Date)),[Ge,Ke]=(0,y.useState)(null),[qe,Je]=(0,y.useState)(null),Ye=s||c||l||u||f&&p||d&&p;(0,y.useEffect)(()=>{Ye||fe(`personal`)},[Ye]);let{data:Xe,isLoading:Ze}=K({queryKey:[`finance`,`me`,`balance`],queryFn:Z.getMyBalance,enabled:o}),{data:Qe,isLoading:$e}=K({queryKey:[`finance`,`me`,`transactions`,50,B],queryFn:()=>Z.getMyTransactions(50,B),enabled:o}),{data:et,isLoading:tt}=K({queryKey:[`finance`,`transactions`,50,B],queryFn:()=>Z.getAllTransactions(50,B),enabled:de===`admin`&&s}),{data:nt,isLoading:rt}=K({queryKey:[`finance`,`cost-centers`,de],queryFn:()=>de===`admin`&&m?Z.listCostCenters(!0):Z.getMyCostCenters(),enabled:g}),{data:it}=K({queryKey:[`users`,`slim`],queryFn:Z.getUsersSlim,enabled:p&&(g||f||d)}),{data:at}=K({queryKey:[`finance`,`cost-center`,P],queryFn:()=>Z.getCostCenter(P),enabled:d&&P!=null});(0,y.useEffect)(()=>{!it||it.length===0||w!=null&&it.some(e=>e.id===w)||T(it[0].id)},[it,w]),(0,y.useEffect)(()=>{if(!d)return;let e=(nt||[]).filter(e=>!e.is_private);if(e.length===0){F(null);return}P!=null&&e.some(e=>e.id===P)||F(e[0].id)},[d,nt,P]),(0,y.useEffect)(()=>{if(!d||!it||it.length===0)return;let e=new Set((at?.members||[]).map(e=>e.user_id)),t=it.find(t=>!e.has(t.id));L(t?t.id:null)},[d,it,at]),(0,y.useEffect)(()=>{if(!le)return;let e=nt||[];if(e.length===0){me(null);return}pe!=null&&e.some(e=>e.id===pe)||me(e[0].id)},[le,pe,nt]),(0,y.useEffect)(()=>{if(!le||pe==null)return;let e=(nt||[]).find(e=>e.id===pe);if(e){if(ge(e.name),e.budget_mode===`total`){ve(`total`),be(e.total_budget==null?``:String(e.total_budget));return}ve(`monthly`),be(e.monthly_budget==null?``:String(e.monthly_budget))}},[le,pe,nt]);let ot=q({mutationFn:()=>Z.createCostCenter({name:_.trim(),total_budget:b===`total`?X8(S):null,monthly_budget:b===`monthly`?X8(S):null,is_active:!0}),onSuccess:()=>{a.invalidateQueries({queryKey:[`finance`]}),v(``),C(``),i(e(`finance.createdCostCenter`,`Cost center created`))},onError:t=>{i(t.message||e(`finance.createCostCenterFailed`,`Failed to create cost center`),`error`)}}),st=q({mutationFn:({costCenterId:e,value:t,mode:n})=>Z.updateCostCenterBudgets(e,{total_budget:n===`total`?X8(t):null,monthly_budget:n===`monthly`?X8(t):null})}),ct=q({mutationFn:({costCenterId:e,name:t})=>Z.updateCostCenter(e,{name:t})}),lt=q({mutationFn:e=>Z.deleteCostCenter(e)}),ut=q({mutationFn:e=>Z.deleteTransaction(e),onSuccess:()=>{a.invalidateQueries({queryKey:[`finance`]}),i(e(`finance.transactionDeleted`,`Transaction deleted`))},onError:t=>{i(t.message||e(`finance.deleteTransactionFailed`,`Failed to delete transaction`),`error`)}}),dt=q({mutationFn:e=>Z.editTransaction(e.transactionId,e.data),onSuccess:()=>{a.invalidateQueries({queryKey:[`finance`]}),i(e(`finance.transactionEdited`,`Transaction updated and ledger recalculated`)),Se(!1)},onError:t=>{i(t.message||e(`finance.editTransactionFailed`,`Failed to edit transaction`),`error`)}}),ft=q({mutationFn:e=>Z.createManualPrint(e),onSuccess:()=>{a.invalidateQueries({queryKey:[`finance`]}),i(e(`finance.manualPrintCreated`,`Manual print charge added and ledger recalculated`)),Pe(!1),Ie(null),Re(null),Be(``),He(``),We(Z8(new Date))},onError:t=>{i(t.message||e(`finance.manualPrintFailed`,`Failed to create manual print`),`error`)}}),pt=q({mutationFn:e=>Z.depositUserBalance(e.userId,{amount:e.amount,description:e.description,cost_center_id:e.costCenterId??null})}),mt=q({mutationFn:e=>Z.withdrawUserBalance(e.userId,{amount:e.amount,description:e.description,cost_center_id:e.costCenterId??null})}),ht=q({mutationFn:e=>Z.upsertCostCenterMember(e.costCenterId,{user_id:e.userId,can_print:e.canPrint}),onSuccess:()=>{a.invalidateQueries({queryKey:[`finance`]}),i(e(`finance.memberSaved`,`Member saved`))},onError:t=>{i(t.message||e(`finance.memberSaveFailed`,`Failed to save member`),`error`)}}),gt=q({mutationFn:e=>Z.removeCostCenterMember(e.costCenterId,e.userId),onSuccess:()=>{a.invalidateQueries({queryKey:[`finance`]}),i(e(`finance.memberRemoved`,`Member removed`))},onError:t=>{i(t.message||e(`finance.memberRemoveFailed`,`Failed to remove member`),`error`)}}),_t=pt.isPending||mt.isPending,vt=()=>{if(!_.trim()){i(e(`finance.costCenterNameRequired`,`Cost center name is required`),`error`);return}ot.mutate()},yt=async()=>{if(pe==null){i(e(`finance.selectCostCenter`,`Please select a cost center`),`error`);return}let t=he.trim();if(!t){i(e(`finance.costCenterNameRequired`,`Cost center name is required`),`error`);return}try{l&&await ct.mutateAsync({costCenterId:pe,name:t}),u&&await st.mutateAsync({costCenterId:pe,mode:_e,value:ye}),a.invalidateQueries({queryKey:[`finance`]}),i(e(`finance.costCenterUpdated`,`Cost center updated`)),ue(!1)}catch(t){i(t.message||e(`finance.costCenterUpdateFailed`,`Failed to update cost center`),`error`)}},bt=e=>{let t=(nt||[]).find(t=>t.id===e);t&&(me(t.id),ge(t.name),t.budget_mode===`total`?(ve(`total`),be(t.total_budget==null?``:String(t.total_budget))):(ve(`monthly`),be(t.monthly_budget==null?``:String(t.monthly_budget))),ue(!0))},xt=async()=>{if(Ge)try{await lt.mutateAsync(Ge.id),a.invalidateQueries({queryKey:[`finance`]}),P===Ge.id&&F(null),i(e(`finance.costCenterDeleted`,`Cost center deleted`))}catch(t){i(t.message||e(`finance.costCenterDeleteFailed`,`Failed to delete cost center`),`error`)}finally{Ke(null)}},St=()=>{qe!=null&&ut.mutate(qe,{onSettled:()=>Je(null)})},Ct=e=>{we(e.id),Ee(e.user_id),Oe(e.cost_center_id),Ae(String(e.amount)),Me(e.description||``),Se(!0)},wt=async()=>{if(Ce==null)return;let t=ke?Number.parseFloat(ke):null;if(t!==null&&!Number.isFinite(t)){i(e(`finance.amountInvalid`,`Amount must be a valid number`),`error`);return}dt.mutate({transactionId:Ce,data:{user_id:Te||void 0,cost_center_id:De||void 0,amount:t??void 0,description:je||void 0}})},Tt=async()=>{if(Fe==null){i(e(`finance.userRequired`,`Please select a user`),`error`);return}if(Le==null){i(e(`finance.costCenterRequired`,`Please select a cost center`),`error`);return}let t=ze?Number.parseFloat(ze):null;if(t===null||!Number.isFinite(t)){i(e(`finance.amountInvalid`,`Amount must be a valid number`),`error`);return}t=Math.abs(t),ft.mutate({user_id:Fe,cost_center_id:Le,amount:t,description:Ve||void 0,created_at:Ue?new Date(Ue).toISOString():void 0})},Et=async()=>{if(w==null){i(e(`finance.userRequired`,`Please select a user`),`error`);return}let t=Number.parseFloat(O);if(!Number.isFinite(t)||t<=0){i(e(`finance.amountMustBePositive`,`Amount must be greater than zero`),`error`);return}let n={userId:w,amount:t,description:A.trim()||void 0,costCenterId:M};try{E===`deposit`?await pt.mutateAsync(n):await mt.mutateAsync(n),a.invalidateQueries({queryKey:[`finance`]}),k(``),j(``),i(E===`deposit`?e(`finance.depositSuccess`,`Deposit successful`):e(`finance.withdrawSuccess`,`Withdrawal successful`))}catch(t){i(t.message||e(`finance.adjustmentFailed`,`Wallet adjustment failed`),`error`)}},Dt=()=>{if(P==null){i(e(`finance.selectCostCenter`,`Please select a cost center`),`error`);return}if(I==null){i(e(`finance.noEligibleUsers`,`No eligible users available`),`error`);return}ht.mutate({costCenterId:P,userId:I,canPrint:R})},Ot=e=>{P!=null&>.mutate({costCenterId:P,userId:e})},kt=Lf(Xe?.currency||`EUR`),At=(0,y.useMemo)(()=>[...it||[]].sort((e,t)=>e.username.localeCompare(t.username)),[it]),jt=(0,y.useMemo)(()=>{let e=new Map;for(let t of At)e.set(t.id,t.username);return e},[At]),Mt=(0,y.useMemo)(()=>{let e=new Set((at?.members||[]).map(e=>e.user_id));return At.filter(t=>!e.has(t.id))},[At,at]),Nt=de===`admin`&&s?et:Qe,Pt=de===`admin`&&s?tt:$e,Ft=(0,y.useMemo)(()=>Nt?.items??[],[Nt?.items]),It=Nt?.total??0,Lt=Math.max(1,Math.ceil(It/50)),Rt=(0,y.useMemo)(()=>Ft.filter(e=>!(ee!==`all`&&e.transaction_type!==ee||ne!==`all`&&e.cost_center_id!==ne)),[Ft,ee,ne]),zt=Math.floor(B/50)+1,Bt=de===`admin`,Vt=t=>t===`deposit`?e(`finance.deposit`):t===`withdraw`?e(`finance.withdraw`):t===`print_charge`?e(`finance.printCharge`):t,Ht=t=>t==null?e(`finance.personal`,`Personal`):jt.get(t)||(r?.id===t&&r.username?r.username:e(`finance.userWithId`,`User #{{id}}`,{id:t})),Ut=t=>t.budget_limit==null||t.budget_available==null?e(`finance.unlimited`,`Unlimited`):`${kt}${t.budget_available.toFixed(2)}/${kt}${t.budget_limit.toFixed(2)}`;return h?(0,G.jsxs)(`div`,{className:`p-4 md:p-8 space-y-8`,children:[(0,G.jsxs)(`div`,{className:`flex flex-col gap-4 lg:flex-row lg:items-start lg:justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Ju,{className:`h-6 w-6 text-bambu-green`}),(0,G.jsx)(`h1`,{className:`text-2xl font-bold text-white`,children:e(`finance.title`,`Finance`)})]}),(0,G.jsx)(`p`,{className:`text-bambu-gray mt-2 max-w-2xl`,children:e(`finance.subtitle`,`Wallet, personal transactions, and cost centers`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1 max-w-2xl`,children:e(`finance.budgetPolicyHint`,`Account balances track costs. Printing is limited only by the selected cost center budget; without a budget, printing is unlimited.`)})]}),(0,G.jsxs)(`div`,{className:`flex flex-col gap-2 lg:items-end`,children:[Ye&&(0,G.jsxs)(`div`,{className:`inline-flex overflow-hidden rounded border border-bambu-dark-tertiary`,children:[(0,G.jsx)(`button`,{type:`button`,onClick:()=>fe(`personal`),className:`px-3 py-1.5 text-sm ${de===`personal`?`bg-bambu-green text-black font-medium`:`bg-bambu-dark text-bambu-gray`}`,children:e(`finance.personalView`,`Personal view`)}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>fe(`admin`),className:`px-3 py-1.5 text-sm ${de===`admin`?`bg-bambu-green text-black font-medium`:`bg-bambu-dark text-bambu-gray`}`,children:e(`finance.adminView`,`Admin view`)})]}),de===`admin`&&Ye&&(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-2 lg:justify-end`,children:[c&&(0,G.jsx)(Q,{size:`sm`,variant:`secondary`,onClick:()=>ae(!0),children:e(`finance.createCostCenter`,`Create cost center`)}),f&&p&&(0,G.jsx)(Q,{size:`sm`,variant:`secondary`,onClick:()=>se(!0),children:e(`finance.adjustWallet`,`Adjust wallet`)}),f&&p&&(0,G.jsx)(Q,{size:`sm`,variant:`secondary`,onClick:()=>Pe(!0),children:e(`finance.addManualPrint`,`Add manual print`)}),d&&p&&(0,G.jsx)(Q,{size:`sm`,variant:`secondary`,onClick:()=>ce(!0),children:e(`finance.manageMembers`,`Manage cost center members`)})]})]})]}),(0,G.jsxs)(`div`,{className:`grid gap-5 md:grid-cols-2 xl:grid-cols-3`,children:[(0,G.jsxs)(zd,{children:[(0,G.jsxs)(Bd,{className:`flex flex-row items-center justify-between pb-2`,children:[(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e(`finance.currentBalance`,`Personal account balance`)}),(0,G.jsx)(Ju,{className:`w-4 h-4 text-bambu-green/90`})]}),(0,G.jsx)(Vd,{className:`pt-1`,children:(0,G.jsx)(`p`,{className:`text-3xl font-semibold text-white leading-tight`,children:Ze?e(`common.loading`,`Loading...`):`${kt}${(Xe?.balance??0).toFixed(2)}`})})]}),(0,G.jsxs)(zd,{children:[(0,G.jsxs)(Bd,{className:`flex flex-row items-center justify-between pb-2`,children:[(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:de===`admin`?e(`finance.transactions`,`Transactions`):e(`finance.personalTransactions`,`Personal transactions`)}),(0,G.jsx)(As,{className:`w-4 h-4 text-blue-400`})]}),(0,G.jsx)(Vd,{className:`pt-1`,children:(0,G.jsx)(`p`,{className:`text-3xl font-semibold text-white leading-tight`,children:Pt?`-`:It})})]}),(0,G.jsxs)(zd,{children:[(0,G.jsxs)(Bd,{className:`flex flex-row items-center justify-between pb-2`,children:[(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e(`finance.costCenters`,`Cost centers`)}),(0,G.jsx)(es,{className:`w-4 h-4 text-orange-400`})]}),(0,G.jsx)(Vd,{className:`pt-1`,children:(0,G.jsx)(`p`,{className:`text-3xl font-semibold text-white leading-tight`,children:rt?`-`:nt?.length??0})})]})]}),ie&&c&&(0,G.jsx)(n5,{title:e(`finance.createCostCenter`,`Create cost center`),size:`md`,onClose:()=>ae(!1),children:(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:$8,children:e(`finance.costCenterName`,`Name`)}),(0,G.jsx)(`input`,{type:`text`,value:_,onChange:e=>v(e.target.value),placeholder:e(`finance.costCenterName`,`Name`),className:Q8})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:$8,children:e(`finance.budgetType`,`Budget type`)}),(0,G.jsxs)(`select`,{value:b,onChange:e=>x(e.target.value),className:Q8,children:[(0,G.jsx)(`option`,{value:`monthly`,children:e(`finance.monthlyBudget`,`Monthly budget`)}),(0,G.jsx)(`option`,{value:`total`,children:e(`finance.totalBudget`,`Total budget`)})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:$8,children:b===`monthly`?e(`finance.monthlyBudget`,`Monthly budget`):e(`finance.totalBudget`,`Total budget`)}),(0,G.jsx)(`input`,{type:`number`,step:`0.01`,value:S,onChange:e=>C(e.target.value),placeholder:`0.00`,className:Q8})]})]}),(0,G.jsx)(Q,{className:`min-w-[180px]`,onClick:vt,disabled:ot.isPending,children:ot.isPending?e(`common.saving`,`Saving...`):e(`finance.create`,`Create`)})]})}),oe&&f&&p&&(0,G.jsx)(n5,{title:e(`finance.adjustWallet`,`Adjust wallet`),size:`md`,onClose:()=>se(!1),children:(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:$8,children:e(`finance.selectUser`,`Select user`)}),(0,G.jsx)(`select`,{value:w??``,onChange:e=>T(e.target.value?Number(e.target.value):null),className:Q8,children:(At||[]).map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.username},e.id))})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:$8,children:e(`finance.transactionType`,`Type`)}),(0,G.jsxs)(`select`,{value:E,onChange:e=>D(e.target.value),className:Q8,children:[(0,G.jsx)(`option`,{value:`deposit`,children:e(`finance.deposit`,`Deposit`)}),(0,G.jsx)(`option`,{value:`withdraw`,children:e(`finance.withdraw`,`Withdraw`)})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:$8,children:e(`finance.amount`,`Amount`)}),(0,G.jsx)(`input`,{type:`number`,step:`0.01`,min:`0`,value:O,onChange:e=>k(e.target.value),placeholder:`0.00`,className:Q8})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:$8,children:e(`finance.costCenters`,`Cost centers`)}),(0,G.jsxs)(`select`,{value:M??``,onChange:e=>N(e.target.value?Number(e.target.value):null),className:Q8,children:[(0,G.jsx)(`option`,{value:``,children:e(`finance.noCostCenter`,`No cost center`)}),(nt||[]).map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:$8,children:e(`common.description`,`Description`)}),(0,G.jsx)(`input`,{type:`text`,value:A,onChange:e=>j(e.target.value),placeholder:e(`finance.descriptionOptional`,`Description (optional)`),className:Q8})]}),(0,G.jsx)(Q,{className:`min-w-[180px]`,onClick:Et,disabled:_t,children:_t?e(`common.saving`,`Saving...`):e(`finance.applyAdjustment`,`Apply adjustment`)})]})}),H&&d&&p&&(0,G.jsx)(n5,{title:e(`finance.manageMembers`,`Manage cost center members`),size:`lg`,onClose:()=>ce(!1),children:(0,G.jsxs)(`div`,{className:`space-y-5`,children:[(0,G.jsxs)(`div`,{className:`grid gap-5 md:grid-cols-2`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:$8,children:e(`finance.costCenters`,`Cost centers`)}),(0,G.jsx)(`select`,{value:P??``,onChange:e=>F(e.target.value?Number(e.target.value):null),className:Q8,children:(nt||[]).filter(e=>!e.is_private).map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.name},e.id))})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:$8,children:e(`finance.selectUser`,`Select user`)}),(0,G.jsxs)(`select`,{value:I??``,onChange:e=>L(e.target.value?Number(e.target.value):null),className:Q8,children:[(0,G.jsx)(`option`,{value:``,children:e(`finance.selectUser`,`Select user`)}),Mt.map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.username},e.id))]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 rounded border border-bambu-dark-tertiary bg-bambu-dark-secondary px-3 py-2`,children:[(0,G.jsx)(`input`,{id:`memberCanPrint`,type:`checkbox`,checked:R,onChange:e=>z(e.target.checked),className:`rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,G.jsx)(`label`,{htmlFor:`memberCanPrint`,className:`text-sm text-bambu-gray`,children:e(`finance.memberCanPrint`,`Member can print`)})]}),(0,G.jsx)(`div`,{className:`flex items-end`,children:(0,G.jsx)(Q,{className:`min-w-[180px]`,onClick:Dt,disabled:ht.isPending||I==null,children:ht.isPending?e(`common.saving`,`Saving...`):e(`finance.addMember`,`Add member`)})})]}),(0,G.jsx)(`div`,{className:`overflow-auto rounded-lg border border-bambu-dark-tertiary`,children:(0,G.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,G.jsx)(`thead`,{children:(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary bg-bambu-dark text-bambu-gray`,children:[(0,G.jsx)(`th`,{className:e5,children:e(`common.name`,`Name`)}),(0,G.jsx)(`th`,{className:e5,children:e(`finance.canPrint`,`Can print`)}),(0,G.jsx)(`th`,{className:e5,children:e(`common.actions`,`Actions`)})]})}),(0,G.jsxs)(`tbody`,{children:[(at?.members||[]).map(t=>(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/60 text-white`,children:[(0,G.jsx)(`td`,{className:t5,children:At.find(e=>e.id===t.user_id)?.username||`User ${t.user_id}`}),(0,G.jsx)(`td`,{className:t5,children:t.can_print?e(`common.yes`,`Yes`):e(`common.no`,`No`)}),(0,G.jsx)(`td`,{className:t5,children:(0,G.jsx)(Q,{size:`sm`,variant:`danger`,onClick:()=>Ot(t.user_id),disabled:gt.isPending,children:e(`common.remove`,`Remove`)})})]},t.id)),(at?.members||[]).length===0&&(0,G.jsx)(`tr`,{children:(0,G.jsx)(`td`,{colSpan:3,className:`py-3 text-bambu-gray`,children:e(`finance.noMembers`,`No members assigned.`)})})]})]})})]})}),le&&(l||u)&&(0,G.jsx)(n5,{title:e(`finance.editCostCenter`,`Edit cost center`),size:`md`,onClose:()=>ue(!1),children:(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:$8,children:e(`finance.costCenterName`,`Name`)}),(0,G.jsx)(`input`,{type:`text`,value:he,onChange:e=>ge(e.target.value),placeholder:e(`finance.costCenterName`,`Name`),className:Q8,disabled:!l})]}),(0,G.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:$8,children:e(`finance.budgetType`,`Budget type`)}),(0,G.jsxs)(`select`,{value:_e,onChange:e=>ve(e.target.value),className:Q8,disabled:!u,children:[(0,G.jsx)(`option`,{value:`monthly`,children:e(`finance.monthlyBudget`,`Monthly budget`)}),(0,G.jsx)(`option`,{value:`total`,children:e(`finance.totalBudget`,`Total budget`)})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:$8,children:_e===`monthly`?e(`finance.monthlyBudget`,`Monthly budget`):e(`finance.totalBudget`,`Total budget`)}),(0,G.jsx)(`input`,{type:`number`,step:`0.01`,value:ye,onChange:e=>be(e.target.value),placeholder:`0.00`,className:Q8,disabled:!u})]})]}),(0,G.jsx)(Q,{className:`min-w-[180px]`,onClick:yt,disabled:ct.isPending||st.isPending||pe==null,children:ct.isPending||st.isPending?e(`common.saving`,`Saving...`):e(`common.save`,`Save`)})]})}),(0,G.jsxs)(`div`,{className:`grid gap-6 ${g&&o?`xl:grid-cols-2`:``}`,children:[g&&(0,G.jsxs)(zd,{children:[(0,G.jsxs)(Bd,{children:[(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`finance.myCostCenters`,`My cost centers`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:e(`finance.costCentersHint`,`Review budget limits and keep costs under control`)})]}),(0,G.jsxs)(Vd,{className:`space-y-3`,children:[rt&&(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`common.loading`,`Loading...`)}),!rt&&(!nt||nt.length===0)&&(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`finance.noCostCenters`,`No cost centers found.`)}),!rt&&nt&&nt.length>0&&(0,G.jsx)(`div`,{className:`overflow-auto rounded-lg border border-bambu-dark-tertiary`,children:(0,G.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,G.jsx)(`thead`,{children:(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary bg-bambu-dark text-bambu-gray`,children:[(0,G.jsx)(`th`,{className:e5,children:e(`common.name`,`Name`)}),Bt&&(0,G.jsx)(`th`,{className:e5,children:e(`finance.owner`,`Owner`)}),(0,G.jsx)(`th`,{className:e5,children:e(`finance.balance`,`Account balance`)}),(0,G.jsx)(`th`,{className:e5,children:e(`finance.budget`,`Budget`)}),Bt&&(0,G.jsx)(`th`,{className:e5,children:e(`common.actions`,`Actions`)})]})}),(0,G.jsx)(`tbody`,{children:nt.map(t=>{let n=l||u,r=!t.is_private&&l;return(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/60 text-white`,children:[(0,G.jsx)(`td`,{className:t5,children:t.name}),Bt&&(0,G.jsx)(`td`,{className:t5,children:t.is_private?Ht(t.owner_user_id):e(`finance.shared`,`Shared`)}),(0,G.jsxs)(`td`,{className:t5,children:[kt,t.total_balance.toFixed(2)]}),(0,G.jsx)(`td`,{className:t5,children:(0,G.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[(0,G.jsx)(`span`,{children:Ut(t)}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:t.budget_mode===`monthly`?e(`finance.monthlyBudget`,`Monthly budget`):t.budget_mode===`total`?e(`finance.totalBudget`,`Total budget`):e(`finance.noBudget`,`No budget`)})]})}),Bt&&(0,G.jsx)(`td`,{className:t5,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Q,{size:`sm`,variant:`ghost`,onClick:()=>bt(t.id),disabled:!n,title:n?e(`common.edit`,`Edit`):e(`finance.cannotEditPrivateCostCenter`,`Private cost centers cannot be edited here`),className:`p-1.5 sm:p-2`,children:(0,G.jsx)(Al,{className:`w-4 h-4`})}),r&&(0,G.jsx)(Q,{size:`sm`,variant:`ghost`,onClick:()=>Ke({id:t.id,name:t.name}),disabled:lt.isPending,title:e(`common.delete`,`Delete`),className:`text-red-400 hover:text-red-300 hover:bg-red-500/10 p-1.5 sm:p-2`,children:(0,G.jsx)(Pu,{className:`w-4 h-4`})})]})})]},t.id)})})]})})]})]}),o&&(0,G.jsxs)(zd,{children:[(0,G.jsxs)(Bd,{children:[(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`finance.recentTransactions`,`Recent transactions`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:e(`finance.transactionsHint`,`Filter by type and cost center, then navigate pages`)})]}),(0,G.jsxs)(Vd,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{className:`grid gap-4 lg:grid-cols-[minmax(0,1fr)_minmax(0,1fr)_auto] xl:grid-cols-[minmax(0,1fr)_minmax(0,1fr)_minmax(0,1fr)_auto] items-end`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:$8,children:e(`finance.transactionType`,`Type`)}),(0,G.jsxs)(`select`,{value:ee,onChange:e=>te(e.target.value),className:Q8,children:[(0,G.jsx)(`option`,{value:`all`,children:e(`finance.allTypes`)}),(0,G.jsx)(`option`,{value:`deposit`,children:e(`finance.deposit`)}),(0,G.jsx)(`option`,{value:`withdraw`,children:e(`finance.withdraw`)}),(0,G.jsx)(`option`,{value:`print_charge`,children:e(`finance.printCharge`)})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:$8,children:e(`finance.costCenters`,`Cost centers`)}),(0,G.jsxs)(`select`,{value:ne,onChange:e=>re(e.target.value===`all`?`all`:Number(e.target.value)),className:Q8,children:[(0,G.jsx)(`option`,{value:`all`,children:e(`finance.allCostCenters`)}),(nt||[]).map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]})]}),Pt&&(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`common.loading`,`Loading...`)}),!Pt&&(!Ft||Ft.length===0)&&(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`finance.noTransactions`,`No transactions available.`)}),!Pt&&Ft.length>0&&Rt.length===0&&(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`finance.noTransactionsForFilter`,`No transactions match the selected filters.`)}),!Pt&&Rt.length>0&&(0,G.jsx)(`div`,{className:`overflow-auto rounded-lg border border-bambu-dark-tertiary`,children:(0,G.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,G.jsx)(`thead`,{children:(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary bg-bambu-dark text-bambu-gray`,children:[(0,G.jsx)(`th`,{className:e5,children:e(`common.date`,`Date`)}),Bt&&(0,G.jsx)(`th`,{className:e5,children:e(`common.user`,`User`)}),(0,G.jsx)(`th`,{className:e5,children:e(`finance.costCenter`,`Cost center`)}),(0,G.jsx)(`th`,{className:e5,children:e(`finance.transactionType`,`Type`)}),(0,G.jsx)(`th`,{className:e5,children:e(`common.description`,`Description`)}),(0,G.jsx)(`th`,{className:e5,children:e(`finance.amount`,`Amount`)}),(0,G.jsx)(`th`,{className:e5,children:e(`finance.balanceAfter`,`Balance after`)}),Bt&&(0,G.jsx)(`th`,{className:e5,children:e(`common.actions`,`Actions`)})]})}),(0,G.jsx)(`tbody`,{children:Rt.map(n=>{let r=n.amount>=0,i=n.cost_center_id==null?null:(nt||[]).find(e=>e.id===n.cost_center_id),a=jt.get(n.user_id),o=n.transaction_type===`print_charge`?$Ge(n.description??null):null,s=o?.isPartial??!1;return(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/60 text-white`,children:[(0,G.jsx)(`td`,{className:t5,children:eKe(n.created_at,t.language)}),Bt&&(0,G.jsx)(`td`,{className:t5,children:a||e(`finance.userWithId`,`User #{{id}}`,{id:n.user_id})}),(0,G.jsx)(`td`,{className:t5,children:i?.name||`-`}),(0,G.jsx)(`td`,{className:t5,children:(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,G.jsx)(`span`,{children:Vt(n.transaction_type)}),s&&(0,G.jsx)(`span`,{className:`rounded border border-yellow-500/40 bg-yellow-500/10 px-2 py-0.5 text-[11px] text-yellow-300`,children:o&&o.partialType?e(`finance.partialStatus.${o.partialType}`,o.partialType):e(`finance.partial`,`Partial`)})]})}),(0,G.jsx)(`td`,{className:t5,children:(o?.cleanedDescription??n.description)||`-`}),(0,G.jsxs)(`td`,{className:`${t5} ${r?`text-green-400`:`text-red-400`}`,children:[r?`+`:`-`,kt,Math.abs(n.amount).toFixed(2)]}),(0,G.jsx)(`td`,{className:t5,children:n.balance_after==null?`-`:`${n.balance_after<0?`-`:``}${kt}${Math.abs(n.balance_after).toFixed(2)}`}),Bt&&(0,G.jsx)(`td`,{className:t5,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Q,{size:`sm`,variant:`secondary`,onClick:()=>Ct(n),disabled:dt.isPending,children:(0,G.jsx)(Al,{className:`w-4 h-4`})}),(0,G.jsx)(Q,{size:`sm`,variant:`danger`,onClick:()=>Je(n.id),disabled:ut.isPending,children:(0,G.jsx)(Pu,{className:`w-4 h-4`})})]})})]},n.id)})})]})}),!Pt&&Rt.length>0&&(0,G.jsx)(`div`,{className:`flex justify-end pt-2 lg:pt-0`,children:(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[(0,G.jsx)(`button`,{type:`button`,onClick:()=>V(0),disabled:B===0||Pt,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,"aria-label":e(`finance.first`,`First`),children:(0,G.jsx)(_s,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>V(e=>Math.max(0,e-50)),disabled:B===0||Pt,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,"aria-label":e(`finance.prev`,`Previous`),children:(0,G.jsx)(hs,{className:`w-4 h-4`})}),(0,G.jsx)(`span`,{className:`text-bambu-gray px-1 whitespace-nowrap`,children:e(`finance.pageNumberOf`,`Page {{page}} of {{total}}`,{page:zt,total:Lt})}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>V(e=>e+50),disabled:Pt||zt>=Lt,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,"aria-label":e(`finance.next`,`Next`),children:(0,G.jsx)(ms,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>V(Math.max(0,(Lt-1)*50)),disabled:Pt||zt>=Lt,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,"aria-label":e(`finance.last`,`Last`),children:(0,G.jsx)(vs,{className:`w-4 h-4`})})]})})]})]}),xe&&Ce!==null&&(0,G.jsx)(n5,{title:e(`finance.editTransaction`,`Edit Transaction`),onClose:()=>Se(!1),size:`md`,children:(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:$8,children:e(`common.user`,`User`)}),(0,G.jsxs)(`select`,{className:Q8,value:Te||``,onChange:e=>Ee(e.target.value?Number(e.target.value):null),children:[(0,G.jsx)(`option`,{value:``,children:e(`finance.selectUser`,`Select user...`)}),At.map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.username},e.id))]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:$8,children:e(`finance.costCenter`,`Cost center (optional)`)}),(0,G.jsxs)(`select`,{className:Q8,value:De||``,onChange:e=>Oe(e.target.value?Number(e.target.value):null),children:[(0,G.jsx)(`option`,{value:``,children:e(`finance.noCostCenter`,`Personal (no cost center)`)}),(nt||[]).map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:$8,children:e(`finance.amount`,`Amount`)}),(0,G.jsx)(`input`,{type:`number`,step:`0.01`,className:Q8,value:ke,onChange:e=>Ae(e.target.value),placeholder:e(`finance.amountExample`,`e.g., 10.50`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:$8,children:e(`common.description`,`Description`)}),(0,G.jsx)(`textarea`,{className:`${Q8} resize-none`,rows:3,value:je,onChange:e=>Me(e.target.value),placeholder:e(`finance.manualAdjustmentExample`,`e.g., Manual adjustment`)})]}),(0,G.jsxs)(`div`,{className:`flex justify-end gap-2 pt-4`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>Se(!1),children:e(`common.cancel`,`Cancel`)}),(0,G.jsx)(Q,{onClick:wt,disabled:dt.isPending,children:e(`common.save`,`Save`)})]})]})}),Ne&&(0,G.jsx)(n5,{title:e(`finance.addManualPrint`,`Add manual print`),onClose:()=>Pe(!1),size:`md`,children:(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:$8,children:e(`common.user`,`User`)}),(0,G.jsxs)(`select`,{className:Q8,value:Fe||``,onChange:e=>Ie(e.target.value?Number(e.target.value):null),children:[(0,G.jsx)(`option`,{value:``,children:e(`finance.selectUser`,`Select user...`)}),At.map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.username},e.id))]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:$8,children:e(`finance.costCenter`,`Cost center`)}),(0,G.jsxs)(`select`,{className:Q8,value:Le||``,onChange:e=>Re(e.target.value?Number(e.target.value):null),children:[(0,G.jsx)(`option`,{value:``,children:e(`finance.selectCostCenter`,`Select cost center...`)}),(nt||[]).map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:$8,children:e(`finance.amount`,`Amount`)}),(0,G.jsx)(`input`,{type:`number`,step:`0.01`,className:Q8,value:ze,onChange:e=>Be(e.target.value),placeholder:e(`finance.amountExample`,`e.g., 4.00`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:$8,children:e(`common.description`,`Description`)}),(0,G.jsx)(`input`,{type:`text`,value:Ve,onChange:e=>He(e.target.value),placeholder:e(`finance.descriptionOptional`,`Description (optional)`),className:Q8})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:$8,children:e(`common.date`,`Date`)}),(0,G.jsx)(`input`,{type:`datetime-local`,value:Ue,onChange:e=>We(e.target.value),className:Q8})]}),(0,G.jsxs)(`div`,{className:`flex justify-end gap-2 pt-4`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>Pe(!1),children:e(`common.cancel`,`Cancel`)}),(0,G.jsx)(Q,{onClick:Tt,disabled:ft.isPending,children:ft.isPending?e(`common.saving`,`Saving...`):e(`finance.addManualPrint`,`Add manual print`)})]})]})}),Ge&&(0,G.jsx)(of,{title:e(`common.delete`,`Delete`),message:e(`finance.confirmDeleteCostCenter`,`Delete cost center "{{name}}"?`,{name:Ge.name}),confirmText:e(`common.delete`,`Delete`),variant:`danger`,isLoading:lt.isPending,onConfirm:xt,onCancel:()=>Ke(null)}),qe!=null&&(0,G.jsx)(of,{title:e(`finance.deleteTransaction`,`Delete transaction`),message:e(`finance.deleteTransactionConfirm`,`Delete this transaction? Balances will be recalculated automatically.`),confirmText:e(`common.delete`,`Delete`),variant:`danger`,isLoading:ut.isPending,onConfirm:St,onCancel:()=>Je(null)})]})]}):(0,G.jsxs)(`div`,{className:`p-4 md:p-8 space-y-6`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Ju,{className:`h-6 w-6 text-bambu-green`}),(0,G.jsx)(`h1`,{className:`text-2xl font-bold text-white`,children:e(`finance.title`,`Finance`)})]}),(0,G.jsx)(`div`,{children:(0,G.jsx)(`p`,{className:`text-bambu-gray mt-2 max-w-2xl`,children:e(`finance.subtitle`,`Wallet, personal transactions, and cost centers`)})}),(0,G.jsx)(zd,{children:(0,G.jsx)(Vd,{className:`py-8 text-center text-bambu-gray`,children:e(`finance.noAccess`,`You do not have permission to view finance data.`)})})]})}var r5={PLA:`GFL99`,"PLA-CF":`GFL98`,"PLA SILK":`GFL96`,"PLA HIGH SPEED":`GFL95`,PETG:`GFG99`,"PETG HF":`GFG96`,"PETG-CF":`GFG98`,PCTG:`GFG97`,ABS:`GFB99`,ASA:`GFB98`,PC:`GFC99`,PA:`GFN99`,"PA-CF":`GFN98`,NYLON:`GFN99`,TPU:`GFU99`,PVA:`GFS99`,HIPS:`GFS98`,PE:`GFP99`,PP:`GFP97`};function i5(e){let t=(e||``).toUpperCase().trim();return t&&(r5[t]||r5[t.replace(/[-\s]?CF$/,``)]||r5[t.replace(/\+$/,``)]||r5[t.split(/[-\s]/)[0]])||``}function a5(e){let t=e.replace(/@.+$/,``).trim();return t.startsWith(`# `)?t.slice(2).trim():t}var o5={local:0,orca_cloud:1,cloud:2,builtin:3};function nKe(e){let{localPresets:t,orcaProfiles:n,cloudSettings:r,builtinFilaments:i}=e,a=[],o=e=>e.trim().toLowerCase(),s=new Set,c=new Set,l=new Set,u=(e,t,...n)=>{let r=n.filter(e=>!!e);if(r.some(e=>s.has(e)))return!1;let i=`${e}|${o(t)}`;return c.has(i)?!1:(r.forEach(e=>s.add(e)),c.add(i),l.add(o(t)),!0)};for(let e of t??[]){let t=a5(e.name),n=e.filament_type||WH(t).material;u(`local`,t)&&a.push({id:`local_${e.id}`,name:t,source:`local`,filamentId:i5(n),filamentType:n||``})}for(let e of n??[]){let t=a5(e.name),n=WH(t).material;u(`orca_cloud`,t,e.setting_id)&&a.push({id:`orca_${e.setting_id}`,name:t,source:`orca_cloud`,filamentId:i5(n),filamentType:n})}for(let e of r??[]){let t=a5(e.name),n=e.setting_id.startsWith(`GFS`)?QH(e.setting_id):``;u(`cloud`,t,e.setting_id,n||void 0)&&a.push({id:e.setting_id,name:t,source:`cloud`,filamentId:n,filamentType:WH(t).material})}for(let e of i??[]){let t=e.filament_id.startsWith(`GF`)?`GFS${e.filament_id.slice(2)}`:e.filament_id;l.has(o(e.name))||u(`builtin`,e.name,e.filament_id,t)&&a.push({id:`builtin_${e.filament_id}`,name:e.name,source:`builtin`,filamentId:e.filament_id,filamentType:WH(e.name).material})}return a.sort((e,t)=>e.source===t.source?e.name.localeCompare(t.name):o5[e.source]-o5[t.source])}async function rKe(e,t){if(e.filamentId)return e.filamentId;if(e.source!==`cloud`||!t)return``;try{return(await t(e.id)).filament_id||``}catch{return``}}var s5=e=>(Math.trunc(parseFloat(e)*1e3)/1e3).toFixed(3),c5=`HS00`,l5=`HH00`,u5=e=>{let t=e.match(/^([A-Z]{2}\d{2})/);return t?t[1]:c5},iKe=e=>u5(e)===l5?`HF`:`S`,d5=e=>{for(let t of[`High Flow_`,`High Flow `,`Standard_`,`Standard `,`HF_`,`HF `,`S_`,`S `])if(e.startsWith(t))return e.slice(t.length);let t=e.indexOf(`_`);return t>0?e.slice(t+1):e};function f5({profile:e,onEdit:t,onCopy:n,selectionMode:r,isSelected:i,onToggleSelect:a,note:o}){let s=iKe(e.nozzle_id),c=e.nozzle_diameter;return(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[r&&(0,G.jsx)(`button`,{onClick:a,className:`text-bambu-gray hover:text-white transition-colors p-1`,children:i?(0,G.jsx)(vu,{className:`w-4 h-4 text-bambu-green`}):(0,G.jsx)(bu,{className:`w-4 h-4`})}),(0,G.jsxs)(`button`,{onClick:()=>{r&&a?a():t()},className:`flex-1 text-left px-3 py-2 bg-bambu-dark rounded hover:bg-bambu-dark-tertiary transition-colors ${i?`ring-1 ring-bambu-green`:``}`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-bambu-green font-mono text-sm font-bold whitespace-nowrap`,children:s5(e.k_value)}),(0,G.jsx)(`span`,{className:`text-white text-sm truncate flex-1`,title:e.name,children:e.name||`Unnamed`}),o&&(0,G.jsx)(`span`,{title:`Has note`,children:(0,G.jsx)(Cu,{className:`w-3 h-3 text-yellow-500`})}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:[s,` `,c]})]}),o&&(0,G.jsxs)(`div`,{className:`text-xs mt-0.5 truncate text-yellow-500/70`,title:o,children:[`Note: `,o.length>50?o.substring(0,50)+`...`:o]})]}),!r&&n&&(0,G.jsx)(`button`,{onClick:e=>{e.stopPropagation(),n()},className:`text-bambu-gray hover:text-white transition-colors p-1`,title:`Copy profile`,children:(0,G.jsx)(Vs,{className:`w-4 h-4`})})]})}function p5({profile:e,printerId:t,nozzleDiameter:n,existingProfiles:r=[],builtinFilaments:i=[],filamentPresets:a=[],isDualNozzle:o=!1,supportsFlowType:s=!0,initialNote:c=``,initialNoteKey:l=null,onClose:u,onSave:d,onSaveNote:f,hasPermission:p}){let{t:m}=U(),{showToast:h}=qd(),[g,_]=(0,y.useState)(e?.name||``),[v,b]=(0,y.useState)(e?.k_value?s5(e.k_value):`0.020`),[x,S]=(0,y.useState)(e?.filament_id||``),[C,w]=(0,y.useState)(e?u5(e.nozzle_id):c5),[T,E]=(0,y.useState)(e?.nozzle_diameter||n),[D,O]=(0,y.useState)(e?[e.extruder_id]:o?[0,1]:[0]),[k,A]=(0,y.useState)(!1),[j,M]=(0,y.useState)({current:0,total:0}),[N,P]=(0,y.useState)(c),[F,I]=(0,y.useState)(``),{schedule:L}=rU(),R=y.useMemo(()=>e?.filament_id?i.find(t=>t.filament_id===e.filament_id)?.name||d5(r.find(t=>t.filament_id===e.filament_id)?.name||e.name||``)||e.filament_id:``,[e,r,i]),z=y.useMemo(()=>{let e=[[`local`,m(`kProfiles.modal.source.local`)],[`orca_cloud`,m(`kProfiles.modal.source.orcaCloud`)],[`cloud`,m(`kProfiles.modal.source.bambuCloud`)],[`builtin`,m(`kProfiles.modal.source.builtin`)]],t=F.trim().toLowerCase(),n=t?a.filter(e=>e.name.toLowerCase().includes(t)):a;return e.map(([e,t])=>({source:e,label:t,items:n.filter(t=>t.source===e)})).filter(e=>e.items.length>0)},[a,F,m]),B=q({mutationFn:e=>(console.log(`[KProfile] Calling API...`),Z.setKProfile(t,e)),onSuccess:(t,n)=>{if(console.log(`[KProfile] Save success:`,t),h(m(`kProfiles.toast.profileSaved`)),f&&N!==c){let t;t=N===``&&l?l:e&&e.slot_id>0?e.setting_id||`slot_${e.slot_id}_${e.filament_id}_${e.extruder_id}`:`name_${g}_${n.filament_id}`,f(t,N)}A(!0),L(()=>{A(!1),d()},2500)},onError:e=>{console.error(`[KProfile] Save error:`,e),h(e.message,`error`),A(!1)}}),V=q({mutationFn:e=>(console.log(`[KProfile] Deleting profile...`),Z.deleteKProfile(t,e)),onSuccess:e=>{console.log(`[KProfile] Delete success:`,e),h(m(`kProfiles.toast.profileDeleted`)),A(!0),L(()=>{A(!1),u()},4e3)},onError:e=>{console.error(`[KProfile] Delete error:`,e),h(e.message,`error`),A(!1)}}),[ee,te]=(0,y.useState)(!1),ne=()=>{e&&V.mutate({slot_id:e.slot_id,extruder_id:e.extruder_id,nozzle_id:e.nozzle_id,nozzle_diameter:e.nozzle_diameter,filament_id:e.filament_id,setting_id:e.setting_id})};return(0,G.jsxs)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,children:[(0,G.jsxs)(zd,{className:`w-full max-w-md relative`,children:[k&&(0,G.jsxs)(`div`,{className:`absolute inset-0 bg-bambu-dark-secondary/90 flex flex-col items-center justify-center z-10 rounded-lg`,children:[(0,G.jsx)(Y,{className:`w-8 h-8 text-bambu-green animate-spin mb-3`}),(0,G.jsx)(`p`,{className:`text-white font-medium`,children:j.total>1?m(`kProfiles.modal.savingExtruder`,{current:j.current,total:j.total}):m(`kProfiles.modal.syncing`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-sm mt-1`,children:m(`kProfiles.modal.pleaseWait`)})]}),(0,G.jsxs)(Vd,{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.jsx)(`h2`,{className:`text-xl font-semibold text-white`,children:m(e?`kProfiles.modal.editTitle`:`kProfiles.modal.addTitle`)}),(0,G.jsx)(`button`,{onClick:u,className:`text-bambu-gray hover:text-white transition-colors`,disabled:k,children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]}),(0,G.jsxs)(`form`,{onSubmit:async n=>{if(n.preventDefault(),o&&!e&&D.length===0){h(m(`kProfiles.toast.selectAtLeastOneExtruder`),`error`);return}let r=parseFloat(v).toFixed(6),i=`${C}-${T}`,s=e&&e.nozzle_id||i,c=e?e.nozzle_diameter:T,l=e?.filament_id||``;if(!e){let e=a.find(e=>e.id===x);if(!e){h(m(`kProfiles.toast.selectFilament`),`error`);return}if(l=await rKe(e,Z.getCloudSettingDetail),!l){h(m(`kProfiles.toast.filamentNotResolvable`,{name:e.name}),`error`);return}}if(e||D.length===1){let t={name:g,k_value:r,filament_id:l,nozzle_id:s,nozzle_diameter:c,extruder_id:e?e.extruder_id:D[0],setting_id:e?.setting_id,slot_id:e?.slot_id??0};console.log(`[KProfile] Saving profile:`,t),B.mutate(t);return}A(!0),M({current:1,total:D.length});let u=D.map(e=>({name:g,k_value:r,filament_id:l,nozzle_id:i,nozzle_diameter:T,extruder_id:e,setting_id:void 0,slot_id:0}));console.log(`[KProfile] Saving ${u.length} profiles in batch:`,u);try{await Z.setKProfilesBatch(t,u),h(m(`kProfiles.toast.profilesSaved`,{count:D.length})),f&&N&&f(`name_${g}_${l}`,N)}catch(e){console.error(`[KProfile] Failed to save batch:`,e),h(m(`kProfiles.toast.failedToSaveBatch`),`error`),A(!1),M({current:0,total:0});return}M({current:D.length,total:D.length}),L(()=>{A(!1),M({current:0,total:0}),d()},3e3)},className:`p-4 space-y-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:m(`kProfiles.modal.profileName`)}),(0,G.jsx)(`input`,{type:`text`,value:g,onChange:e=>_(e.target.value),disabled:!!e,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none ${e?`opacity-60 cursor-not-allowed`:``}`,placeholder:m(`kProfiles.modal.profileNamePlaceholder`),required:!e})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:m(`kProfiles.modal.kValue`)}),(0,G.jsx)(`input`,{type:`text`,inputMode:`decimal`,value:v,onChange:e=>{let t=e.target.value;(t===``||/^\d*\.?\d*$/.test(t))&&b(t)},onBlur:e=>{let t=parseFloat(e.target.value);isNaN(t)||b((Math.trunc(t*1e3)/1e3).toFixed(3))},className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none font-mono`,placeholder:m(`kProfiles.modal.kValuePlaceholder`),required:!0}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:m(`kProfiles.modal.kValueHelp`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:m(`kProfiles.modal.filament`)}),e?(0,G.jsx)(`div`,{className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white opacity-60`,children:R||e.filament_id}):(0,G.jsxs)(`div`,{className:`border border-bambu-dark-tertiary rounded-lg overflow-hidden`,children:[(0,G.jsxs)(`div`,{className:`relative border-b border-bambu-dark-tertiary`,children:[(0,G.jsx)(Ql,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,G.jsx)(`input`,{type:`text`,value:F,onChange:e=>I(e.target.value),placeholder:m(`kProfiles.modal.searchFilaments`),className:`w-full pl-10 pr-3 py-2 bg-bambu-dark text-white placeholder-bambu-gray focus:outline-none`})]}),(0,G.jsx)(`div`,{className:`max-h-56 overflow-y-auto bg-bambu-dark`,children:z.length===0?(0,G.jsx)(`p`,{className:`px-3 py-3 text-xs text-bambu-gray`,children:a.length===0?m(`kProfiles.modal.noFilamentsHelp`):m(`kProfiles.modal.noFilamentMatches`)}):z.map(e=>(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`sticky top-0 z-10 flex items-center gap-2 px-3 py-1.5 bg-bambu-dark-secondary border-y border-bambu-dark-tertiary`,children:[(0,G.jsx)(`span`,{className:`text-xs font-bold uppercase tracking-wider text-bambu-green`,children:e.label}),(0,G.jsx)(`span`,{className:`text-[10px] text-bambu-gray`,children:e.items.length})]}),e.items.map(e=>(0,G.jsx)(`button`,{type:`button`,onClick:()=>{S(e.id),g||_(`${C===l5?`HF`:`S`} ${e.name}`)},className:`w-full text-left px-3 py-1.5 text-sm transition-colors ${x===e.id?`bg-bambu-green/20 text-white`:`text-white hover:bg-bambu-dark-tertiary`}`,children:e.name},e.id))]},e.source))})]})]}),(0,G.jsxs)(`div`,{className:s?`grid grid-cols-2 gap-4`:``,children:[(0,G.jsxs)(`div`,{className:s?``:`hidden`,children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:m(`kProfiles.modal.flowType`)}),(0,G.jsxs)(`select`,{value:C,onChange:t=>{let n=t.target.value;if(w(n),!e&&x&&!g){let e=a.find(e=>e.id===x);e&&_(`${n===l5?`HF`:`S`} ${e.name}`)}},disabled:!!e,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none ${e?`opacity-60 cursor-not-allowed`:``}`,children:[(0,G.jsx)(`option`,{value:l5,children:m(`kProfiles.modal.highFlow`)}),(0,G.jsx)(`option`,{value:c5,children:m(`kProfiles.modal.standard`)})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:m(`kProfiles.modal.nozzleSize`)}),(0,G.jsxs)(`select`,{value:T,onChange:e=>E(e.target.value),disabled:!!e,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none ${e?`opacity-60 cursor-not-allowed`:``}`,children:[(0,G.jsx)(`option`,{value:`0.2`,children:`0.2mm`}),(0,G.jsx)(`option`,{value:`0.4`,children:`0.4mm`}),(0,G.jsx)(`option`,{value:`0.6`,children:`0.6mm`}),(0,G.jsx)(`option`,{value:`0.8`,children:`0.8mm`})]})]})]}),o&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:m(e?`kProfiles.modal.extruder`:`kProfiles.modal.extruders`)}),e?(0,G.jsx)(`div`,{className:`px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white opacity-60`,children:e.extruder_id===1?m(`kProfiles.modal.left`):m(`kProfiles.modal.right`)}):(0,G.jsxs)(`div`,{className:`flex gap-4`,children:[(0,G.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:D.includes(1),onChange:e=>{e.target.checked?O([...D,1]):O(D.filter(e=>e!==1))},className:`w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green focus:ring-offset-0 accent-bambu-green`}),(0,G.jsx)(`span`,{className:`text-white`,children:m(`kProfiles.modal.left`)})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:D.includes(0),onChange:e=>{e.target.checked?O([...D,0]):O(D.filter(e=>e!==0))},className:`w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green focus:ring-offset-0 accent-bambu-green`}),(0,G.jsx)(`span`,{className:`text-white`,children:m(`kProfiles.modal.right`)})]})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:m(`kProfiles.modal.notes`)}),(0,G.jsx)(`textarea`,{value:N,onChange:e=>P(e.target.value),placeholder:m(`kProfiles.modal.notesPlaceholder`),rows:2,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none resize-none`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:m(`kProfiles.modal.notesHelp`)})]}),(0,G.jsxs)(`div`,{className:`flex gap-2 pt-4`,children:[e&&(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:()=>te(!0),disabled:V.isPending||k||!p(`kprofiles:delete`),title:p(`kprofiles:delete`)?void 0:m(`kProfiles.permission.noDelete`),className:`text-red-500 hover:bg-red-500/10`,children:V.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Pu,{className:`w-4 h-4`})}),(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:u,disabled:k,className:`flex-1`,children:m(`common.cancel`)}),(0,G.jsxs)(Q,{type:`submit`,disabled:B.isPending||k||!p(e?`kprofiles:update`:`kprofiles:create`),title:p(e?`kprofiles:update`:`kprofiles:create`)?void 0:m(e?`kProfiles.permission.noUpdate`:`kProfiles.permission.noCreate`),className:`flex-1`,children:[B.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Tc,{className:`w-4 h-4`}),m(`common.save`)]})]})]})]})]}),ee&&(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-[60]`,children:(0,G.jsx)(zd,{className:`w-full max-w-sm`,children:(0,G.jsxs)(Vd,{className:`p-6`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3 mb-4`,children:[(0,G.jsx)(`div`,{className:`w-10 h-10 rounded-full bg-red-500/20 flex items-center justify-center`,children:(0,G.jsx)(Pu,{className:`w-5 h-5 text-red-500`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`text-lg font-semibold text-white`,children:m(`kProfiles.deleteConfirm.title`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:m(`kProfiles.deleteConfirm.cannotUndo`)})]})]}),(0,G.jsx)(`p`,{className:`text-bambu-gray mb-6`,children:m(`kProfiles.deleteConfirm.message`,{name:e?.name})}),(0,G.jsxs)(`div`,{className:`flex gap-3`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>te(!1),className:`flex-1`,children:m(`common.cancel`)}),(0,G.jsxs)(Q,{onClick:()=>{te(!1),ne()},disabled:V.isPending,className:`flex-1 bg-red-500 hover:bg-red-600 text-white`,children:[V.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Pu,{className:`w-4 h-4`}),m(`common.delete`)]})]})]})})})]})}var m5={NOZZLE_DIAMETER:`bambusy_kprofiles_nozzle`,SORT_OPTION:`bambusy_kprofiles_sort`};function aKe(){let{t:e}=U(),{showToast:t}=qd(),{hasPermission:n}=Nd(),[r,i]=(0,y.useState)(null),[a,o]=(0,y.useState)(()=>localStorage.getItem(m5.NOZZLE_DIAMETER)||`0.4`),[s,c]=(0,y.useState)(null),[l,u]=(0,y.useState)(!1),[d,f]=(0,y.useState)(null),[p,m]=(0,y.useState)(``),[h,g]=(0,y.useState)(`all`),[_,v]=(0,y.useState)(`all`),[b,x]=(0,y.useState)(()=>localStorage.getItem(m5.SORT_OPTION)||`name`),[S,C]=(0,y.useState)(!1),[w,T]=(0,y.useState)(new Set),[E,D]=(0,y.useState)(!1),[O,k]=(0,y.useState)(!1),A=(0,y.useCallback)(e=>`${e.slot_id}_${e.extruder_id}`,[]);(0,y.useEffect)(()=>{localStorage.setItem(m5.NOZZLE_DIAMETER,a)},[a]),(0,y.useEffect)(()=>{localStorage.setItem(m5.SORT_OPTION,b)},[b]);let{data:j,isLoading:M}=K({queryKey:[`printers`],queryFn:Z.getPrinters}),{data:N,isLoading:P,isFetching:F,error:I,refetch:L}=K({queryKey:[`kprofiles`,r,a],queryFn:async()=>{console.log(`[KProfiles] Fetching profiles for printer`,r,`nozzle`,a);let e=await Z.getKProfiles(r,a);return console.log(`[KProfiles] Received profiles:`,e?.profiles?.length||0,`profiles`),e},enabled:!!r,retry:!1,staleTime:0,gcTime:0,refetchOnMount:`always`}),{data:R}=K({queryKey:[`builtinFilaments`],queryFn:()=>Z.getBuiltinFilaments(),staleTime:3e5}),{data:z}=K({queryKey:[`filamentIdMap`],queryFn:()=>Z.getFilamentIdMap(),staleTime:3e5}),{data:B}=K({queryKey:[`localPresets`],queryFn:()=>Z.getLocalPresets(),retry:!1}),{data:V}=K({queryKey:[`orcaCloudProfilesForKProfiles`],queryFn:()=>Z.orcaCloudListProfiles(),retry:!1}),{data:ee}=K({queryKey:[`cloudSettings`],queryFn:()=>Z.getCloudSettings(),retry:!1}),{data:te,refetch:ne}=K({queryKey:[`kprofile-notes`,r],queryFn:()=>Z.getKProfileNotes(r),enabled:!!r,staleTime:3e4}),re=I?.message?.includes(`not connected`);(0,y.useEffect)(()=>{if(!r&&j&&j.length>0){let e=j.find(e=>e.is_active);e&&i(e.id)}},[r,j]),(0,y.useEffect)(()=>{if(r){let e=setTimeout(()=>{L()},150);return()=>clearTimeout(e)}},[r,a]);let ie=j?.filter(e=>e.is_active)||[],ae=y.useMemo(()=>{let e=new Map;if(R)for(let t of R)e.set(t.filament_id,t.name);if(z)for(let[t,n]of Object.entries(z))e.has(t)||e.set(t,n);return e},[R,z]),oe=y.useMemo(()=>Array.from(ae.entries()).map(([e,t])=>({filament_id:e,name:t})),[ae]),se=y.useMemo(()=>nKe({localPresets:B?.filament,orcaProfiles:V?.filament,cloudSettings:ee?.filament,builtinFilaments:R}),[B?.filament,V?.filament,ee?.filament,R]),H=y.useCallback(e=>ae.get(e.filament_id)||d5(e.name),[ae]),ce=y.useMemo(()=>N?.profiles?N.profiles.filter(e=>{let t=p.toLowerCase(),n=!t||e.name.toLowerCase().includes(t)||e.filament_id.toLowerCase().includes(t),r=h===`all`||h===`left`&&e.extruder_id===1||h===`right`&&e.extruder_id===0,i=_===`all`||_===`hf`&&e.nozzle_id.startsWith(`HH`)||_===`s`&&e.nozzle_id.startsWith(`HS`);return n&&r&&i}).sort((e,t)=>{switch(b){case`k_value`:return parseFloat(e.k_value)-parseFloat(t.k_value);case`filament`:return H(e).localeCompare(H(t));default:return e.name.localeCompare(t.name)}}):[],[N?.profiles,p,h,_,b,H]),le=j?.find(e=>e.id===r),ue=le?.nozzle_count===2,de=le?.supports_nozzle_flow_type??!0;(0,y.useEffect)(()=>{de||v(`all`)},[de]),(0,y.useEffect)(()=>{let e=e=>{e.target instanceof HTMLInputElement||e.target instanceof HTMLTextAreaElement||e.target instanceof HTMLSelectElement||s||l||d||(e.key===`r`||e.key===`R`?(e.preventDefault(),L()):e.key===`n`||e.key===`N`?(e.preventDefault(),u(!0)):e.key===`Escape`&&S&&(e.preventDefault(),C(!1),T(new Set)))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[s,l,d,S,L]);let fe=(0,y.useCallback)(()=>{if(!N?.profiles||N.profiles.length===0){t(e(`kProfiles.toast.noProfilesToExport`),`error`);return}let n={version:1,exported_at:new Date().toISOString(),printer:le?.name||`Unknown`,nozzle_diameter:a,profiles:N.profiles.map(e=>({name:e.name,k_value:e.k_value,filament_id:e.filament_id,nozzle_id:e.nozzle_id,nozzle_diameter:e.nozzle_diameter,extruder_id:e.extruder_id}))},r=new Blob([JSON.stringify(n,null,2)],{type:`application/json`}),i=URL.createObjectURL(r),o=document.createElement(`a`);o.href=i,o.download=`kprofiles_${le?.name||`printer`}_${a}mm_${new Date().toISOString().split(`T`)[0]}.json`,document.body.appendChild(o),o.click(),document.body.removeChild(o),URL.revokeObjectURL(i),t(e(`kProfiles.toast.exportedProfiles`,{count:N.profiles.length}))},[N?.profiles,le,a,t,e]),pe=(0,y.useCallback)(()=>{let n=document.createElement(`input`);n.type=`file`,n.accept=`.json`,n.onchange=async n=>{let i=n.target.files?.[0];if(i)try{let n=await i.text(),o=JSON.parse(n);if(!o.profiles||!Array.isArray(o.profiles)){t(e(`kProfiles.toast.invalidFileFormat`),`error`);return}let s=0;for(let e of o.profiles)if(!(!e.name||!e.k_value||!e.filament_id))try{await Z.setKProfile(r,{name:e.name,k_value:parseFloat(e.k_value).toFixed(6),filament_id:e.filament_id,nozzle_id:e.nozzle_id||`${c5}-${a}`,nozzle_diameter:e.nozzle_diameter||a,extruder_id:e.extruder_id??0,slot_id:0}),s++,await new Promise(e=>setTimeout(e,500))}catch(t){console.error(`Failed to import profile:`,e.name,t)}t(e(`kProfiles.toast.importedProfiles`,{count:s,total:o.profiles.length})),L()}catch(n){console.error(`Import error:`,n),t(e(`kProfiles.toast.failedToParseImport`),`error`)}},n.click()},[r,a,t,L,e]),me=(0,y.useCallback)(e=>{T(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),he=(0,y.useCallback)(()=>{T(new Set(ce.map(e=>A(e))))},[ce,A]),ge=(0,y.useCallback)(()=>{w.size!==0&&D(!0)},[w.size]),_e=(0,y.useCallback)(async()=>{let n=ce.filter(e=>w.has(A(e)));k(!0);let i=0;for(let e of n)try{await Z.deleteKProfile(r,{slot_id:e.slot_id,extruder_id:e.extruder_id,nozzle_id:e.nozzle_id,nozzle_diameter:e.nozzle_diameter,filament_id:e.filament_id,setting_id:e.setting_id}),i++,await new Promise(e=>setTimeout(e,300))}catch(t){console.error(`Failed to delete profile:`,e.name,t)}t(e(`kProfiles.toast.profilesDeleted`,{count:i})),k(!1),D(!1),C(!1),T(new Set),L()},[r,w,ce,t,L,A,e]),ve=(0,y.useCallback)(e=>{let t=[];return e.setting_id&&t.push(e.setting_id),t.push(`slot_${e.slot_id}_${e.filament_id}_${e.extruder_id}`),t.push(`name_${e.name}_${e.filament_id}`),t},[]),ye=(0,y.useCallback)(async(n,i)=>{if(r)try{await Z.setKProfileNote(r,n,i),ne()}catch(n){console.error(`Failed to save note:`,n),t(e(`kProfiles.toast.failedToSaveNote`),`error`)}},[r,ne,t,e]),be=(0,y.useCallback)(e=>{if(!te?.notes)return{note:``,key:null};let t=ve(e);for(let e of t)if(te.notes[e])return{note:te.notes[e],key:e};return{note:``,key:null}},[te,ve]),xe=(0,y.useCallback)(e=>be(e).note,[be]);return M?(0,G.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,G.jsx)(Y,{className:`w-8 h-8 text-bambu-green animate-spin`})}):!j||j.length===0?(0,G.jsx)(zd,{children:(0,G.jsxs)(Vd,{className:`py-12 text-center`,children:[(0,G.jsx)(ys,{className:`w-12 h-12 text-bambu-gray mx-auto mb-4`}),(0,G.jsx)(`h3`,{className:`text-lg font-semibold text-white mb-2`,children:e(`kProfiles.noPrintersConfigured`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray`,children:e(`kProfiles.addPrinterInSettings`)})]})}):ie.length===0?(0,G.jsx)(zd,{children:(0,G.jsxs)(Vd,{className:`py-12 text-center`,children:[(0,G.jsx)(Rl,{className:`w-12 h-12 text-bambu-gray mx-auto mb-4`}),(0,G.jsx)(`h3`,{className:`text-lg font-semibold text-white mb-2`,children:e(`kProfiles.noActivePrinters`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray`,children:e(`kProfiles.enablePrinterConnection`)})]})}):(0,G.jsxs)(G.Fragment,{children:[F&&!P&&(0,G.jsxs)(`div`,{className:`fixed inset-0 bg-black/50 flex flex-col items-center justify-center z-40`,children:[(0,G.jsx)(Y,{className:`w-10 h-10 text-bambu-green animate-spin mb-3`}),(0,G.jsx)(`p`,{className:`text-white font-medium`,children:e(`kProfiles.loadingProfiles`)})]}),(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-4 mb-6`,children:[(0,G.jsxs)(`div`,{className:`flex-1 min-w-48`,children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:e(`kProfiles.printer`)}),(0,G.jsx)(`select`,{value:r||``,onChange:e=>i(parseInt(e.target.value)),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:ie.map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.name},e.id))})]}),(0,G.jsxs)(`div`,{className:`w-32`,children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:e(`kProfiles.nozzle`)}),(0,G.jsxs)(`select`,{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`,children:[(0,G.jsx)(`option`,{value:`0.2`,children:`0.2mm`}),(0,G.jsx)(`option`,{value:`0.4`,children:`0.4mm`}),(0,G.jsx)(`option`,{value:`0.6`,children:`0.6mm`}),(0,G.jsx)(`option`,{value:`0.8`,children:`0.8mm`})]})]}),(0,G.jsxs)(`div`,{className:`flex items-end gap-2`,children:[(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>L(),disabled:F||!n(`kprofiles:read`),title:n(`kprofiles:read`)?void 0:e(`kProfiles.permission.noRead`),children:[(0,G.jsx)(Hl,{className:`w-4 h-4 ${F?`animate-spin`:``}`}),e(`kProfiles.refresh`)]}),(0,G.jsxs)(Q,{onClick:()=>u(!0),disabled:!n(`kprofiles:create`),title:n(`kprofiles:create`)?void 0:e(`kProfiles.permission.noCreate`),children:[(0,G.jsx)(Fl,{className:`w-4 h-4`}),e(`kProfiles.addProfile`)]})]})]}),(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-4 mb-4`,children:[(0,G.jsxs)(`div`,{className:`flex-1 min-w-48 relative`,children:[(0,G.jsx)(Ql,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,G.jsx)(`input`,{type:`text`,value:p,onChange:e=>m(e.target.value),placeholder:e(`kProfiles.searchPlaceholder`),className:`w-full pl-10 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]}),ue&&(0,G.jsx)(`div`,{className:`w-36`,children:(0,G.jsxs)(`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:`all`,children:e(`kProfiles.allExtruders`)}),(0,G.jsx)(`option`,{value:`left`,children:e(`kProfiles.leftOnly`)}),(0,G.jsx)(`option`,{value:`right`,children:e(`kProfiles.rightOnly`)})]})}),de&&(0,G.jsx)(`div`,{className:`w-32`,children:(0,G.jsxs)(`select`,{value:_,onChange:e=>v(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:`all`,children:e(`kProfiles.allFlow`)}),(0,G.jsx)(`option`,{value:`hf`,children:e(`kProfiles.hfOnly`)}),(0,G.jsx)(`option`,{value:`s`,children:e(`kProfiles.sOnly`)})]})}),(0,G.jsx)(`div`,{className:`w-32`,children:(0,G.jsxs)(`select`,{value:b,onChange:e=>x(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:`name`,children:e(`kProfiles.sortName`)}),(0,G.jsx)(`option`,{value:`k_value`,children:e(`kProfiles.sortKValue`)}),(0,G.jsx)(`option`,{value:`filament`,children:e(`kProfiles.sortFilament`)})]})})]}),(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-2 mb-6`,children:[(0,G.jsxs)(Q,{variant:`secondary`,onClick:fe,disabled:!N?.profiles?.length||!n(`kprofiles:read`),title:n(`kprofiles:read`)?void 0:e(`kProfiles.permission.noExport`),children:[(0,G.jsx)(Xs,{className:`w-4 h-4`}),e(`kProfiles.export`)]}),(0,G.jsxs)(Q,{variant:`secondary`,onClick:pe,disabled:!n(`kprofiles:create`),title:n(`kprofiles:create`)?void 0:e(`kProfiles.permission.noImport`),children:[(0,G.jsx)(Vu,{className:`w-4 h-4`}),e(`kProfiles.import`)]}),(0,G.jsx)(`div`,{className:`flex-1`}),S?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(Q,{variant:`secondary`,onClick:he,children:[(0,G.jsx)(vu,{className:`w-4 h-4`}),e(`kProfiles.selectAll`)]}),(0,G.jsxs)(Q,{variant:`secondary`,onClick:ge,disabled:w.size===0||!n(`kprofiles:delete`),className:`text-red-500 hover:bg-red-500/10`,title:n(`kprofiles:delete`)?void 0:e(`kProfiles.permission.noDelete`),children:[(0,G.jsx)(Pu,{className:`w-4 h-4`}),e(`kProfiles.delete`),` (`,w.size,`)`]}),(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>{C(!1),T(new Set)},children:[(0,G.jsx)(nd,{className:`w-4 h-4`}),e(`common.cancel`)]})]}):(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>C(!0),disabled:!ce.length||!n(`kprofiles:delete`),title:n(`kprofiles:delete`)?void 0:e(`kProfiles.permission.noDelete`),children:[(0,G.jsx)(vu,{className:`w-4 h-4`}),e(`kProfiles.select`)]})]}),P?(0,G.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,G.jsx)(Y,{className:`w-8 h-8 text-bambu-green animate-spin`})}):re?(0,G.jsx)(zd,{children:(0,G.jsxs)(Vd,{className:`py-12 text-center`,children:[(0,G.jsx)(Zu,{className:`w-12 h-12 text-bambu-gray mx-auto mb-4`}),(0,G.jsx)(`h3`,{className:`text-lg font-semibold text-white mb-2`,children:e(`kProfiles.printerOffline`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray mb-4`,children:e(`kProfiles.printerOfflineDesc`)}),(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>L(),children:[(0,G.jsx)(Hl,{className:`w-4 h-4`}),e(`common.refresh`)]})]})}):ce.length>0?ue?(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`text-sm font-medium text-bambu-gray mb-2 px-1`,children:e(`kProfiles.leftExtruder`)}),(0,G.jsx)(`div`,{className:`space-y-1`,children:ce.filter(e=>e.extruder_id===1).map(e=>(0,G.jsx)(f5,{profile:e,onEdit:()=>c(e),onCopy:()=>f(e),selectionMode:S,isSelected:w.has(A(e)),onToggleSelect:()=>me(A(e)),note:xe(e)},A(e)))})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`text-sm font-medium text-bambu-gray mb-2 px-1`,children:e(`kProfiles.rightExtruder`)}),(0,G.jsx)(`div`,{className:`space-y-1`,children:ce.filter(e=>e.extruder_id===0).map(e=>(0,G.jsx)(f5,{profile:e,onEdit:()=>c(e),onCopy:()=>f(e),selectionMode:S,isSelected:w.has(A(e)),onToggleSelect:()=>me(A(e)),note:xe(e)},A(e)))})]})]}):(0,G.jsx)(`div`,{className:`space-y-1`,children:ce.map(e=>(0,G.jsx)(f5,{profile:e,onEdit:()=>c(e),onCopy:()=>f(e),selectionMode:S,isSelected:w.has(A(e)),onToggleSelect:()=>me(A(e)),note:xe(e)},A(e)))}):p||h!==`all`||_!==`all`?(0,G.jsx)(zd,{children:(0,G.jsxs)(Vd,{className:`py-12 text-center`,children:[(0,G.jsx)(Ql,{className:`w-12 h-12 text-bambu-gray mx-auto mb-4`}),(0,G.jsx)(`h3`,{className:`text-lg font-semibold text-white mb-2`,children:e(`kProfiles.noMatchingProfiles`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray`,children:e(`kProfiles.noMatchingProfilesDesc`)})]})}):(0,G.jsx)(zd,{children:(0,G.jsxs)(Vd,{className:`py-12 text-center`,children:[(0,G.jsx)(Tc,{className:`w-12 h-12 text-bambu-gray mx-auto mb-4`}),(0,G.jsx)(`h3`,{className:`text-lg font-semibold text-white mb-2`,children:e(`kProfiles.noKProfiles`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray mb-4`,children:e(`kProfiles.noKProfilesDesc`,{diameter:a})}),(0,G.jsxs)(Q,{onClick:()=>u(!0),children:[(0,G.jsx)(Fl,{className:`w-4 h-4`}),e(`kProfiles.createFirstProfile`)]})]})}),s&&r&&(()=>{let{note:e,key:t}=be(s);return(0,G.jsx)(p5,{profile:s,printerId:r,nozzleDiameter:a,existingProfiles:N?.profiles,builtinFilaments:oe,filamentPresets:se,isDualNozzle:ue,supportsFlowType:de,initialNote:e,initialNoteKey:t,onSaveNote:ye,hasPermission:n,onClose:()=>{console.log(`[KProfiles] Edit modal onClose - refetching profiles...`),c(null),L()},onSave:()=>{c(null),L()}})})(),l&&r&&(0,G.jsx)(p5,{printerId:r,nozzleDiameter:a,existingProfiles:N?.profiles,builtinFilaments:oe,filamentPresets:se,isDualNozzle:ue,supportsFlowType:de,onSaveNote:ye,hasPermission:n,onClose:()=>{u(!1),L()},onSave:()=>{u(!1),L()}}),d&&r&&(0,G.jsx)(p5,{printerId:r,nozzleDiameter:a,existingProfiles:N?.profiles,builtinFilaments:oe,filamentPresets:se,isDualNozzle:ue,supportsFlowType:de,onSaveNote:ye,hasPermission:n,profile:{...d,slot_id:0,name:`${d.name} (Copy)`},onClose:()=>{f(null),L()},onSave:()=>{f(null),L()}}),E&&(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,children:(0,G.jsx)(zd,{className:`w-full max-w-sm`,children:(0,G.jsxs)(Vd,{className:`p-6`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3 mb-4`,children:[(0,G.jsx)(`div`,{className:`w-10 h-10 rounded-full bg-red-500/20 flex items-center justify-center`,children:(0,G.jsx)(Pu,{className:`w-5 h-5 text-red-500`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`text-lg font-semibold text-white`,children:e(`kProfiles.bulkDelete.title`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`kProfiles.bulkDelete.cannotUndo`)})]})]}),(0,G.jsx)(`p`,{className:`text-bambu-gray mb-6`,children:e(`kProfiles.bulkDelete.message`,{count:w.size})}),(0,G.jsxs)(`div`,{className:`flex gap-3`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>D(!1),disabled:O,className:`flex-1`,children:e(`common.cancel`)}),(0,G.jsxs)(Q,{onClick:_e,disabled:O,className:`flex-1 bg-red-500 hover:bg-red-600 text-white`,children:[O?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Pu,{className:`w-4 h-4`}),e(`common.delete`)]})]})]})})})]})}var h5=[`PLA`,`PETG`,`PCTG`,`ABS`,`ASA`,`TPU`,`PC`,`PA`,`PVA`,`HIPS`,`PP`,`PET`,`NYLON`],oKe={PLA:`E8E8E8`,PETG:`4A90D9`,ABS:`E67E22`,ASA:`D35400`,TPU:`9B59B6`,PC:`BDC3C7`,PA:`2ECC71`,NYLON:`2ECC71`,PVA:`F1C40F`,HIPS:`95A5A6`,PP:`ECF0F1`,PET:`3498DB`};function sKe(e){let t=e.toUpperCase();for(let e of h5)if(RegExp(`\\b${e}\\b`).test(t))return e;return null}function cKe(e){let t=e.replace(/@.+$/,``).trim(),n=t.toUpperCase();for(let e of h5){let r=n.indexOf(e);if(r>0){let e=t.slice(0,r).trim();if(e&&e.length>1)return e}}return null}function g5({preset:e,onDelete:t,onExpand:n,isExpanded:r}){let{t:i}=U(),{hasPermission:a}=Nd(),o=e.filament_type||sKe(e.name),s=e.filament_vendor||cKe(e.name),c=null,l=!1;if(e.default_filament_colour)try{let t=JSON.parse(e.default_filament_colour),n=Array.isArray(t)?t[0]:t;typeof n==`string`&&/^#?[0-9a-fA-F]{6,8}$/.test(n.replace(`#`,``))&&(c=n.replace(`#`,``).slice(0,6),l=!0)}catch{let t=e.default_filament_colour;/^#?[0-9a-fA-F]{6,8}$/.test(t.replace(`#`,``))&&(c=t.replace(`#`,``).slice(0,6),l=!0)}return!c&&o&&(c=oKe[o.toUpperCase()]||null),(0,G.jsx)(zd,{className:`bg-bambu-dark border-bambu-dark-tertiary hover:border-bambu-dark-tertiary/80 transition-colors`,children:(0,G.jsxs)(Vd,{className:`p-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[e.preset_type===`filament`&&(0,G.jsx)(`div`,{className:`w-4 h-4 rounded-full border border-black/20 flex-shrink-0 ${!l&&!c?`opacity-25`:l?``:`opacity-50`}`,style:{backgroundColor:c?`#${c}`:`#666`}}),(0,G.jsx)(`span`,{className:`text-sm font-medium text-white truncate`,children:e.name})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[o&&(0,G.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-bambu-green/20 text-bambu-green`,children:o}),s&&(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:s}),(0,G.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`,children:i(`profiles.localProfiles.badge`)})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1 flex-shrink-0`,children:[a(`settings:update`)&&(0,G.jsx)(`button`,{onClick:()=>t(e.id),className:`p-1 text-bambu-gray hover:text-red-600 dark:hover:text-red-400 transition-colors`,title:i(`profiles.localProfiles.delete`),children:(0,G.jsx)(Pu,{className:`w-3.5 h-3.5`})}),(0,G.jsx)(`button`,{onClick:()=>n(r?null:e.id),className:`p-1 text-bambu-gray hover:text-white transition-colors`,children:r?(0,G.jsx)(gs,{className:`w-3.5 h-3.5`}):(0,G.jsx)(ps,{className:`w-3.5 h-3.5`})})]})]}),r&&(0,G.jsxs)(`div`,{className:`mt-3 pt-3 border-t border-bambu-dark-tertiary text-xs space-y-1.5`,children:[o&&(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:i(`profiles.localProfiles.filamentType`)}),(0,G.jsx)(`span`,{className:`text-white`,children:o})]}),s&&(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:i(`profiles.localProfiles.vendor`)}),(0,G.jsx)(`span`,{className:`text-white`,children:s})]}),e.nozzle_temp_min!=null&&e.nozzle_temp_max!=null&&(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:i(`profiles.localProfiles.nozzleTemp`)}),(0,G.jsxs)(`span`,{className:`text-white`,children:[e.nozzle_temp_min,`–`,e.nozzle_temp_max,`°C`]})]}),e.filament_cost&&(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:i(`profiles.localProfiles.cost`)}),(0,G.jsx)(`span`,{className:`text-white`,children:e.filament_cost})]}),e.filament_density&&(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:i(`profiles.localProfiles.density`)}),(0,G.jsxs)(`span`,{className:`text-white`,children:[e.filament_density,` g/cm³`]})]}),e.pressure_advance&&(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:i(`profiles.localProfiles.pressureAdvance`)}),(0,G.jsx)(`span`,{className:`text-white`,children:e.pressure_advance})]}),e.compatible_printers&&(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:i(`profiles.localProfiles.compatiblePrinters`)}),(0,G.jsx)(`span`,{className:`text-white truncate ml-2`,children:(()=>{try{return JSON.parse(e.compatible_printers).join(`, `)}catch{return e.compatible_printers}})()})]}),e.inherits&&e.inherits!==e.name&&(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:i(`profiles.localProfiles.inheritsFrom`)}),(0,G.jsx)(`span`,{className:`text-white truncate ml-2`,children:e.inherits})]}),(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:i(`profiles.localProfiles.source`)}),(0,G.jsx)(`span`,{className:`text-white capitalize`,children:e.source})]})]})]})})}function lKe(){let{t:e}=U(),{hasPermission:t}=Nd(),n=co(),{showToast:r}=qd(),[i,a]=(0,y.useState)(``),[o,s]=(0,y.useState)(null),[c,l]=(0,y.useState)(!1),[u,d]=(0,y.useState)(null),{data:f,isLoading:p}=K({queryKey:[`localPresets`],queryFn:()=>Z.getLocalPresets()}),m=q({mutationFn:async e=>{let t=[];for(let n of Array.from(e)){let e=new FormData;e.append(`file`,n),t.push(await Z.importLocalPresets(e))}return t},onSuccess:t=>{n.invalidateQueries({queryKey:[`localPresets`]}),n.invalidateQueries({queryKey:[`slicerPresets`]});let i=0,a=0,o=0;for(let e of t)i+=e.imported,a+=e.skipped,o+=e.errors.length;i>0&&r(e(`profiles.localProfiles.toast.importSuccess`,{count:i})),a>0&&r(e(`profiles.localProfiles.toast.importSkipped`,{count:a}),`warning`),o>0&&r(e(`profiles.localProfiles.toast.importError`,{count:o}),`error`)},onError:e=>{r(e.message,`error`)}}),h=q({mutationFn:e=>Z.deleteLocalPreset(e),onSuccess:(t,i)=>{n.setQueryData([`localPresets`],e=>e&&{filament:e.filament.filter(e=>e.id!==i),printer:e.printer.filter(e=>e.id!==i),process:e.process.filter(e=>e.id!==i)}),n.invalidateQueries({queryKey:[`localPresets`]}),n.invalidateQueries({queryKey:[`slicerPresets`]}),d(null),r(e(`profiles.localProfiles.toast.deleted`))}}),g=(0,y.useCallback)(e=>{!e||e.length===0||m.mutate(e)},[m]),_=(0,y.useCallback)(e=>{e.preventDefault(),l(!1),g(e.dataTransfer.files)},[g]),v=(0,y.useCallback)(e=>{if(!i)return e;let t=i.toLowerCase();return e.filter(e=>e.name.toLowerCase().includes(t)||e.filament_type?.toLowerCase().includes(t)||e.filament_vendor?.toLowerCase().includes(t))},[i]),b=(0,y.useMemo)(()=>v(f?.filament||[]),[f?.filament,v]),x=(0,y.useMemo)(()=>v(f?.printer||[]),[f?.printer,v]),S=(0,y.useMemo)(()=>v(f?.process||[]),[f?.process,v]),C=b.length+x.length+S.length,w=(f?.filament?.length??0)+(f?.printer?.length??0)+(f?.process?.length??0)>0;return p?(0,G.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,G.jsx)(Y,{className:`w-8 h-8 text-bambu-green animate-spin`})}):(0,G.jsxs)(`div`,{className:`space-y-6`,children:[t(`settings:update`)&&(0,G.jsxs)(`div`,{onDragOver:e=>{e.preventDefault(),l(!0)},onDragLeave:()=>l(!1),onDrop:_,className:`relative border-2 border-dashed rounded-lg p-6 text-center transition-colors ${c?`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary hover:border-bambu-gray`}`,children:[(0,G.jsx)(`input`,{type:`file`,accept:`.json,.zip,.orca_filament,.bbscfg,.bbsflmt`,multiple:!0,className:`absolute inset-0 w-full h-full opacity-0 cursor-pointer`,onChange:e=>g(e.target.files)}),m.isPending?(0,G.jsxs)(`div`,{className:`flex items-center justify-center gap-2`,children:[(0,G.jsx)(Y,{className:`w-5 h-5 text-bambu-green animate-spin`}),(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:e(`profiles.localProfiles.importing`)})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Vu,{className:`w-8 h-8 text-bambu-gray mx-auto mb-2`}),(0,G.jsx)(`p`,{className:`text-sm text-white font-medium`,children:e(`profiles.localProfiles.import`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`profiles.localProfiles.importDesc`)})]})]}),w&&(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(Ql,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,G.jsx)(`input`,{type:`text`,value:i,onChange:e=>a(e.target.value),placeholder:e(`profiles.localProfiles.search`),className:`w-full pl-9 pr-4 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`})]}),!w&&!p&&(0,G.jsxs)(`div`,{className:`text-center py-12`,children:[(0,G.jsx)(Pc,{className:`w-12 h-12 text-bambu-gray mx-auto mb-3 opacity-50`}),(0,G.jsx)(`p`,{className:`text-bambu-gray`,children:e(`profiles.localProfiles.noPresets`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray/60 mt-1`,children:e(`profiles.localProfiles.importDesc`)})]}),w&&C===0&&!p&&(0,G.jsxs)(`div`,{className:`text-center py-12`,children:[(0,G.jsx)(Ql,{className:`w-12 h-12 text-bambu-gray mx-auto mb-3 opacity-50`}),(0,G.jsx)(`p`,{className:`text-bambu-gray`,children:e(`profiles.localProfiles.noSearchResults`)})]}),C>0&&(0,G.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6`,children:[b.length>0&&(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,G.jsx)(Zs,{className:`w-4 h-4 text-bambu-green`}),(0,G.jsx)(`h3`,{className:`text-sm font-medium text-white`,children:e(`profiles.localProfiles.filament`)}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[`(`,b.length,`)`]})]}),(0,G.jsx)(`div`,{className:`space-y-2`,children:b.map(e=>(0,G.jsx)(g5,{preset:e,onDelete:e=>d(e),onExpand:s,isExpanded:o===e.id},e.id))})]}),S.length>0&&(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,G.jsx)(Jc,{className:`w-4 h-4 text-blue-600 dark:text-blue-400`}),(0,G.jsx)(`h3`,{className:`text-sm font-medium text-white`,children:e(`profiles.localProfiles.process`)}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[`(`,S.length,`)`]})]}),(0,G.jsx)(`div`,{className:`space-y-2`,children:S.map(e=>(0,G.jsx)(g5,{preset:e,onDelete:e=>d(e),onExpand:s,isExpanded:o===e.id},e.id))})]}),x.length>0&&(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,G.jsx)(nu,{className:`w-4 h-4 text-orange-600 dark:text-orange-400`}),(0,G.jsx)(`h3`,{className:`text-sm font-medium text-white`,children:e(`profiles.localProfiles.printer`)}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[`(`,x.length,`)`]})]}),(0,G.jsx)(`div`,{className:`space-y-2`,children:x.map(e=>(0,G.jsx)(g5,{preset:e,onDelete:e=>d(e),onExpand:s,isExpanded:o===e.id},e.id))})]})]}),u!==null&&(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50`,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg p-6 max-w-sm mx-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,G.jsx)(ys,{className:`w-5 h-5 text-red-600 dark:text-red-400`}),(0,G.jsx)(`h3`,{className:`text-white font-medium`,children:e(`profiles.localProfiles.deleteConfirmTitle`)})]}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4`,children:e(`profiles.localProfiles.deleteConfirm`)}),(0,G.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,G.jsx)(Q,{variant:`secondary`,size:`sm`,onClick:()=>d(null),children:e(`profiles.localProfiles.cancel`)}),(0,G.jsxs)(Q,{variant:`danger`,size:`sm`,onClick:()=>h.mutate(u),disabled:h.isPending,children:[h.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Pu,{className:`w-4 h-4`}),e(`profiles.localProfiles.delete`)]})]})]})})]})}function uKe(e){let t=e.match(/@?\s*(?:BBL\s+)?(?:Bambu\s+Lab\s+)?([XPAH][1-9][A-Z]?(?:\s*(?:Carbon|mini))?|H2D)/i),n=e.match(/(\d+\.?\d*)\s*(?:mm\s*)?nozzle|nozzle\s*(\d+\.?\d*)/i),r=e.match(/(\d+\.?\d*)mm\s*(?:Standard|Fine|Extra Fine|Draft|Quality)?/i),i=e.match(/\b(PLA|PETG|ABS|ASA|TPU|PC|PA|PVA|HIPS|PP|PET(?:-?CF)?|PA(?:-?CF)?|PLA(?:-?CF)?)\b/i);return{printer:t?t[1].trim():null,nozzle:n?(n[1]||n[2])+`mm`:null,layerHeight:r?r[1]+`mm`:null,filamentType:i?i[1].toUpperCase():null}}function dKe({settings:e,lastSyncTime:t,onRefresh:n,isRefreshing:r,printers:i,t:a}){let[o,s]=(0,y.useState)(``),[c,l]=(0,y.useState)(`all`),[u,d]=(0,y.useState)(`all`),[f,p]=(0,y.useState)(`all`),[m,h]=(0,y.useState)(`all`),[g,_]=(0,y.useState)(`all`),[v,b]=(0,y.useState)(null),x=(0,y.useMemo)(()=>[...e.filament.map(e=>({...e,type:`filament`})),...e.printer.map(e=>({...e,type:`printer`})),...e.process.map(e=>({...e,type:`process`}))].map(e=>({...e,meta:uKe(e.name)})),[e]),S=(0,y.useMemo)(()=>{let e=new Set,t=new Set,n=new Set;return x.forEach(r=>{r.meta.nozzle&&e.add(r.meta.nozzle),r.meta.filamentType&&t.add(r.meta.filamentType),r.meta.layerHeight&&n.add(r.meta.layerHeight)}),{printers:i.map(e=>({id:e.id.toString(),name:e.name})),nozzles:Array.from(e).sort((e,t)=>parseFloat(e)-parseFloat(t)),filaments:Array.from(t).sort(),layerHeights:Array.from(n).sort((e,t)=>parseFloat(e)-parseFloat(t))}},[x,i]),C=(0,y.useMemo)(()=>u===`all`?null:i.find(e=>e.id.toString()===u)?.model||null,[u,i]),w=(0,y.useMemo)(()=>x.filter(e=>c===`all`||e.type===c).filter(e=>{if(u===`all`||!C)return!0;let t=e.meta.printer?.toLowerCase()||``,n=C.toLowerCase();return t.includes(n)||n.includes(t)}).filter(e=>f===`all`||e.meta.nozzle===f).filter(e=>m===`all`||e.meta.filamentType===m).filter(e=>g===`all`||e.meta.layerHeight===g).filter(e=>o===``||e.name.toLowerCase().includes(o.toLowerCase())).sort((e,t)=>e.name.localeCompare(t.name)),[x,c,u,C,f,m,g,o]),T=()=>{l(`all`),d(`all`),p(`all`),h(`all`),_(`all`),s(``)},E=c!==`all`||u!==`all`||f!==`all`||m!==`all`||g!==`all`||o!==``,D=e.filament.length+e.printer.length+e.process.length,O=e=>w.filter(t=>t.type===e);return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`space-y-4 mb-6`,children:[(0,G.jsxs)(`div`,{className:`flex flex-col sm:flex-row gap-3`,children:[(0,G.jsxs)(`div`,{className:`relative flex-1`,children:[(0,G.jsx)(Ql,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,G.jsx)(`input`,{type:`text`,value:o,onChange:e=>s(e.target.value),placeholder:a(`profiles.cloudView.searchPlaceholder`),className:`w-full pl-10 pr-4 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none`})]}),(0,G.jsx)(`div`,{className:`flex gap-2`,children:(0,G.jsxs)(Q,{variant:`secondary`,onClick:n,disabled:r,children:[(0,G.jsx)(Hl,{className:`w-4 h-4 ${r?`animate-spin`:``}`}),a(`profiles.cloudView.refresh`)]})})]}),(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,G.jsx)(wc,{className:`w-4 h-4 text-bambu-gray`}),(0,G.jsx)(b5,{label:a(`profiles.cloudView.filters.type`),value:c,options:[{value:`all`,label:a(`profiles.cloudView.filters.all`),count:D},{value:`filament`,label:a(`profiles.cloudView.filters.filament`),count:e.filament.length},{value:`printer`,label:a(`profiles.cloudView.filters.printer`),count:e.printer.length},{value:`process`,label:a(`profiles.cloudView.filters.process`),count:e.process.length}],onChange:e=>l(e)}),S.printers.length>0&&(0,G.jsx)(b5,{label:a(`profiles.cloudView.filters.printer`),value:u,options:[{value:`all`,label:a(`profiles.cloudView.filters.all`)},...S.printers.map(e=>({value:e.id,label:e.name}))],onChange:d}),S.nozzles.length>0&&(0,G.jsx)(b5,{label:a(`profiles.cloudView.filters.nozzle`),value:f,options:[{value:`all`,label:a(`profiles.cloudView.filters.all`)},...S.nozzles.map(e=>({value:e,label:e}))],onChange:p}),S.filaments.length>0&&(c===`all`||c===`filament`)&&(0,G.jsx)(b5,{label:a(`profiles.cloudView.filters.filament`),value:m,options:[{value:`all`,label:a(`profiles.cloudView.filters.all`)},...S.filaments.map(e=>({value:e,label:e}))],onChange:h}),S.layerHeights.length>0&&(c===`all`||c===`process`)&&(0,G.jsx)(b5,{label:a(`profiles.cloudView.filters.layer`),value:g,options:[{value:`all`,label:a(`profiles.cloudView.filters.all`)},...S.layerHeights.map(e=>({value:e,label:e}))],onChange:_}),E&&(0,G.jsx)(`button`,{onClick:T,className:`px-3 py-2 text-sm text-bambu-gray hover:text-white transition-colors`,children:a(`profiles.cloudView.clearFilters`)})]})]}),(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4 mb-4 text-sm text-bambu-gray`,children:[t&&(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(js,{className:`w-3 h-3`}),a(`profiles.cloudView.lastSynced`),` `,up(t.toISOString(),`system`,a)]}),(0,G.jsx)(`span`,{children:a(`profiles.cloudView.showingCount`,{showing:w.length,total:D})})]}),w.length===0?(0,G.jsxs)(`div`,{className:`text-center py-16`,children:[(0,G.jsx)(Jc,{className:`w-12 h-12 text-bambu-gray-dark mx-auto mb-4`}),(0,G.jsx)(`p`,{className:`text-bambu-gray`,children:a(`profiles.cloudView.noPresetsFound`)}),E&&(0,G.jsx)(`button`,{onClick:T,className:`mt-2 text-sm text-bambu-green hover:text-bambu-green-light`,children:a(`profiles.cloudView.clearFilters`)})]}):(0,G.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-6`,children:[(0,G.jsx)(_5,{icon:(0,G.jsx)(Zs,{className:`w-4 h-4 text-amber-600 dark:text-amber-400`}),title:a(`profiles.cloudView.columns.filament`),presets:O(`filament`),emptyText:a(`profiles.cloudView.noFilamentPresets`),onSelect:b}),(0,G.jsx)(_5,{icon:(0,G.jsx)(nu,{className:`w-4 h-4 text-blue-600 dark:text-blue-400`}),title:a(`profiles.cloudView.columns.process`),presets:O(`process`),emptyText:a(`profiles.cloudView.noProcessPresets`),onSelect:b}),(0,G.jsx)(_5,{icon:(0,G.jsx)(Rl,{className:`w-4 h-4 text-purple-600 dark:text-purple-400`}),title:a(`profiles.cloudView.columns.printer`),presets:O(`printer`),emptyText:a(`profiles.cloudView.noPrinterPresets`),onSelect:b})]}),v&&(0,G.jsx)(pKe,{setting:v,onClose:()=>b(null),t:a})]})}function _5({icon:e,title:t,presets:n,emptyText:r,onSelect:i}){return(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-3 px-1`,children:[e,(0,G.jsx)(`h3`,{className:`text-sm font-medium text-bambu-gray`,children:t}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray-dark`,children:[`(`,n.length,`)`]})]}),(0,G.jsx)(`div`,{className:`space-y-1 max-h-[calc(100vh-320px)] overflow-y-auto pr-1`,children:n.length===0?(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray-dark px-3 py-2`,children:r}):n.map(e=>(0,G.jsx)(fKe,{preset:e,onClick:()=>i(e)},e.setting_id))})]})}function fKe({preset:e,onClick:t}){return(0,G.jsx)(`button`,{onClick:t,className:`w-full text-left px-3 py-2 rounded bg-bambu-dark hover:bg-bambu-dark-tertiary transition-colors`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-white text-sm truncate flex-1`,title:e.name,children:e.name}),e.meta.filamentType&&e.type===`filament`&&(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:e.meta.filamentType}),e.meta.layerHeight&&e.type===`process`&&(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:e.meta.layerHeight}),e.meta.printer&&(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:e.meta.printer})]})})}function pKe({setting:e,onClose:t,t:n}){let{data:r,isLoading:i,error:a}=K({queryKey:[`orcaCloudProfileDetail`,e.setting_id],queryFn:()=>Z.orcaCloudGetProfile(e.setting_id),retry:!1});return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/60 z-50 flex items-center justify-center p-4`,onClick:t,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-2xl max-w-4xl w-full max-h-[90vh] flex flex-col`,onClick:e=>e.stopPropagation(),children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h2`,{className:`text-lg font-bold text-white`,children:e.name}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:e.type})]}),(0,G.jsx)(`button`,{onClick:t,className:`text-bambu-gray hover:text-white p-1`,children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]}),(0,G.jsx)(`div`,{className:`flex-1 overflow-y-auto p-4`,children:i?(0,G.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,G.jsx)(Y,{className:`w-8 h-8 text-bambu-green animate-spin`})}):a?(0,G.jsx)(`p`,{className:`text-center text-bambu-gray py-16`,children:a.message}):r?(0,G.jsx)(`pre`,{className:`text-xs font-mono text-bambu-gray bg-bambu-dark p-3 rounded overflow-x-auto whitespace-pre`,children:JSON.stringify(r.setting,null,2)}):(0,G.jsx)(`p`,{className:`text-center text-bambu-gray py-16`,children:n(`profiles.cloudView.noPresetsFound`)})})]})})}function mKe(){let{t:e}=U(),t=co(),{showToast:n}=qd(),{hasPermission:r}=Nd(),i=r(`orca_cloud:auth`),[a,o]=(0,y.useState)(null),[s,c]=(0,y.useState)(5e3),[l,u]=(0,y.useState)(null),{data:d,isLoading:f}=K({queryKey:[`orcaCloudStatus`],queryFn:Z.orcaCloudStatus}),p=!!d?.connected,{data:m,isLoading:h,refetch:g,isRefetching:_,error:v,dataUpdatedAt:b}=K({queryKey:[`orcaCloudProfiles`],queryFn:Z.orcaCloudListProfiles,enabled:p,retry:!1,staleTime:1e3*60*5}),{data:x=[]}=K({queryKey:[`printers`],queryFn:Z.getPrinters,enabled:p}),[S,C]=(0,y.useState)();(0,y.useEffect)(()=>{b&&C(new Date(b))},[b]);let w=()=>{o(null),c(5e3)},T=t=>{t===`access_denied`?u(e(`profiles.orcaCloud.errors.denied`)):t===`expired_token`&&u(e(`profiles.orcaCloud.errors.expired`)),w()},E=q({mutationFn:Z.orcaCloudDeviceStart,onSuccess:e=>{u(null),c(Math.max(1,e.interval)*1e3),o(e)},onError:t=>{u(t.message||e(`profiles.orcaCloud.errors.startFailed`))}}),D=q({mutationFn:Z.orcaCloudLogout,onSuccess:()=>{t.invalidateQueries({queryKey:[`orcaCloudStatus`]}),t.removeQueries({queryKey:[`orcaCloudProfiles`]}),n(e(`profiles.orcaCloud.toast.disconnected`))}}),{data:O,error:k}=K({queryKey:[`orcaCloudDevicePoll`,a?.user_code??`none`],queryFn:Z.orcaCloudDevicePoll,enabled:a!==null,gcTime:0,retry:!1,refetchOnWindowFocus:!1,refetchInterval:a===null?!1:s}),A=(0,y.useRef)(null);return(0,y.useEffect)(()=>{if(!a||!O)return;let r=O.status;if(r===`slow_down`){c(e=>e+5e3);return}r!==`authorization_pending`&&A.current!==r&&(A.current=r,r===`complete`?(w(),t.invalidateQueries({queryKey:[`orcaCloudStatus`]}),t.invalidateQueries({queryKey:[`orcaCloudProfiles`]}),n(e(`profiles.orcaCloud.connectedShort`))):T(r))},[O,a]),(0,y.useEffect)(()=>{a&&k&&(u(e(`profiles.orcaCloud.errors.pollFailed`)),w())},[k,a]),(0,y.useEffect)(()=>{a&&(A.current=null)},[a]),f?(0,G.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,G.jsx)(Y,{className:`w-8 h-8 text-bambu-green animate-spin`})}):(0,G.jsxs)(`div`,{children:[p&&(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-3 mb-6 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`w-2 h-2 rounded-full bg-bambu-green animate-pulse`}),(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:d?.email?(0,G.jsxs)(G.Fragment,{children:[e(`profiles.orcaCloud.connectedAs`),` `,(0,G.jsx)(`span`,{className:`text-white`,children:d.email})]}):(0,G.jsx)(`span`,{className:`text-white`,children:e(`profiles.orcaCloud.connectedShort`)})})]}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:()=>D.mutate(),disabled:D.isPending||!i,title:i?void 0:e(`profiles.orcaCloud.noLogoutPermission`),children:[(0,G.jsx)(il,{className:`w-4 h-4`}),e(`profiles.orcaCloud.logout`)]})]}),p?h?(0,G.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,G.jsx)(Y,{className:`w-8 h-8 text-bambu-green animate-spin`})}):v?(0,G.jsxs)(`div`,{className:`text-center py-16`,children:[(0,G.jsx)(`p`,{className:`text-bambu-gray mb-4`,children:v.message}),(0,G.jsx)(Q,{onClick:()=>g(),children:e(`profiles.orcaCloud.retry`)})]}):m?(0,G.jsx)(dKe,{settings:m,lastSyncTime:S,onRefresh:()=>g(),isRefreshing:_,printers:x,t:e}):null:(0,G.jsx)(hKe,{pairing:a,connectError:l,onConnect:()=>E.mutate(),onCancel:w,isStarting:E.isPending,canManage:i,t:e})]})}function hKe({pairing:e,connectError:t,onConnect:n,onCancel:r,isStarting:i,canManage:a,t:o}){return e?(0,G.jsx)(zd,{children:(0,G.jsxs)(Vd,{className:`p-8 text-center max-w-md mx-auto`,children:[(0,G.jsx)(Ps,{className:`w-12 h-12 text-bambu-green mx-auto mb-4`}),(0,G.jsx)(`h2`,{className:`text-xl font-bold text-white mb-2`,children:o(`profiles.orcaCloud.device.title`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray mb-6`,children:o(`profiles.orcaCloud.device.instruction`)}),(0,G.jsx)(`p`,{className:`text-xs uppercase tracking-wide text-bambu-gray mb-2`,children:o(`profiles.orcaCloud.device.codeLabel`)}),(0,G.jsx)(`div`,{className:`mb-6 py-3 px-4 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg`,children:(0,G.jsx)(`span`,{className:`text-2xl font-mono font-bold tracking-[0.3em] text-white select-all`,children:e.user_code})}),(0,G.jsx)(`a`,{href:e.verification_uri_complete,target:`_blank`,rel:`noopener noreferrer`,children:(0,G.jsxs)(Q,{className:`w-full mb-3`,children:[(0,G.jsx)(rc,{className:`w-4 h-4`}),o(`profiles.orcaCloud.device.openButton`)]})}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray break-all mb-6`,children:o(`profiles.orcaCloud.device.manualHint`,{url:e.verification_uri})}),(0,G.jsxs)(`div`,{className:`flex items-center justify-center gap-2 text-sm text-bambu-gray mb-4`,children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin text-bambu-green`}),o(`profiles.orcaCloud.device.waiting`)]}),(0,G.jsx)(`button`,{type:`button`,onClick:r,className:`text-bambu-gray hover:text-white text-sm`,children:o(`profiles.orcaCloud.device.cancel`)})]})}):(0,G.jsx)(zd,{children:(0,G.jsxs)(Vd,{className:`p-8 text-center`,children:[(0,G.jsx)(Ps,{className:`w-12 h-12 text-bambu-green mx-auto mb-4`}),(0,G.jsx)(`h2`,{className:`text-xl font-bold text-white mb-2`,children:o(`profiles.orcaCloud.connect.title`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray mb-6 max-w-xl mx-auto`,children:o(`profiles.orcaCloud.connect.description`)}),(0,G.jsxs)(`div`,{className:`max-w-sm mx-auto`,children:[(0,G.jsxs)(Q,{onClick:n,disabled:i||!a,title:a?void 0:o(`profiles.orcaCloud.noConnectPermission`),className:`w-full`,children:[i?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(fs,{className:`w-4 h-4`}),o(`profiles.orcaCloud.connectButton`)]}),t&&(0,G.jsxs)(`p`,{className:`mt-3 text-sm text-red-700 dark:text-red-400 flex items-center justify-center gap-2`,children:[(0,G.jsx)(ys,{className:`w-4 h-4 flex-shrink-0`}),t]})]})]})})}function v5(e,t){let n=`${e} ${t||``}`,r=n.match(/@?\s*(?:BBL\s+)?(?:Bambu\s+Lab\s+)?([XPAH][1-9][A-Z]?(?:\s*(?:Carbon|mini))?|H2D)/i),i=r?r[1].trim():null,a=n.match(/(\d+\.?\d*)\s*(?:mm\s*)?nozzle|nozzle\s*(\d+\.?\d*)/i),o=a?(a[1]||a[2])+`mm`:null,s=n.match(/(\d+\.?\d*)mm\s*(?:Standard|Fine|Extra Fine|Draft|Quality)?/i),c=s?s[1]+`mm`:null,l=n.match(/\b(PLA|PETG|ABS|ASA|TPU|PC|PA|PVA|HIPS|PP|PET(?:-?CF)?|PA(?:-?CF)?|PLA(?:-?CF)?)\b/i);return{printer:i,nozzle:o,layerHeight:c,filamentType:l?l[1].toUpperCase():null}}function y5(e){return/^(P[FPM]US|PF\d|PP\d)/.test(e)}function gKe({onSuccess:e,t}){let{showToast:n}=qd(),[r,i]=(0,y.useState)(`email`),[a,o]=(0,y.useState)(``),[s,c]=(0,y.useState)(``),[l,u]=(0,y.useState)(``),[d,f]=(0,y.useState)(``),[p,m]=(0,y.useState)(`global`),[h,g]=(0,y.useState)(null),[_,v]=(0,y.useState)(null),[b,x]=(0,y.useState)(!1),S=q({mutationFn:()=>Z.cloudLogin(a,s,p),onSuccess:r=>{if(x(r.reason===`captcha`),r.success)n(t(`profiles.login.toast.loggedIn`)),e();else if(r.reason===`captcha`)return;else r.needs_verification?(g(r.verification_type||`email`),v(r.tfa_key||null),r.verification_type===`totp`?n(t(`profiles.login.toast.enterTotp`)):n(t(`profiles.login.toast.codeSent`)),i(`code`)):n(r.message,`error`)},onError:e=>{x(!1),n(e.message,`error`)}}),C=q({mutationFn:()=>Z.cloudVerify(a,l,_||void 0,p),onSuccess:r=>{x(r.reason===`captcha`),r.success?(n(t(`profiles.login.toast.loggedIn`)),e()):r.reason!==`captcha`&&n(r.message,`error`)},onError:e=>{x(!1),n(e.message,`error`)}}),w=q({mutationFn:()=>Z.cloudSetToken(d,p),onSuccess:()=>{n(t(`profiles.login.toast.tokenSet`)),e()},onError:e=>n(e.message,`error`)}),T=e=>{e.preventDefault(),r===`email`?S.mutate():r===`code`?C.mutate():r===`token`&&w.mutate()},E=S.isPending||C.isPending||w.isPending;return(0,G.jsx)(zd,{className:`max-w-md mx-auto`,children:(0,G.jsxs)(Vd,{children:[(0,G.jsxs)(`div`,{className:`text-center mb-6`,children:[(0,G.jsx)(`div`,{className:`inline-flex items-center justify-center w-12 h-12 rounded-xl bg-bambu-green/20 mb-3`,children:(0,G.jsx)(Ps,{className:`w-6 h-6 text-bambu-green`})}),(0,G.jsx)(`h2`,{className:`text-xl font-semibold text-white`,children:t(`profiles.login.title`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:t(`profiles.login.subtitle`)})]}),b&&r!==`token`&&(0,G.jsx)(`div`,{role:`alert`,className:`mb-4 p-3 rounded-lg border border-amber-500/40 bg-amber-500/10`,children:(0,G.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,G.jsx)(iu,{className:`w-4 h-4 text-amber-400 shrink-0 mt-0.5`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm font-medium text-amber-300`,children:t(`profiles.login.captchaTitle`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:t(`profiles.login.captchaBody`)}),(0,G.jsxs)(`button`,{type:`button`,onClick:()=>{x(!1),i(`token`)},className:`mt-2 text-xs text-bambu-green hover:underline flex items-center gap-1`,children:[(0,G.jsx)(Kc,{className:`w-3 h-3`}),t(`profiles.login.useToken`)]})]})]})}),(0,G.jsxs)(`form`,{onSubmit:T,className:`space-y-4`,children:[r===`email`&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:t(`profiles.login.email`)}),(0,G.jsx)(`input`,{type:`email`,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 placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none`,placeholder:`your@email.com`,required:!0})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:t(`profiles.login.password`)}),(0,G.jsx)(`input`,{type:`password`,value:s,onChange:e=>c(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none`,placeholder:`••••••••`,required:!0})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:t(`profiles.login.region`)}),(0,G.jsxs)(`select`,{value:p,onChange:e=>m(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,G.jsx)(`option`,{value:`global`,children:t(`profiles.login.regionGlobal`)}),(0,G.jsx)(`option`,{value:`china`,children:t(`profiles.login.regionChina`)})]})]})]}),r===`code`&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:t(h===`totp`?`profiles.login.totpCode`:`profiles.login.verificationCode`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:h===`totp`?t(`profiles.login.enterTotpHint`):t(`profiles.login.checkEmail`,{email:a})}),(0,G.jsx)(`input`,{type:`text`,value:l,onChange:e=>u(e.target.value.replace(/\D/g,``).slice(0,6)),className:`w-full px-3 py-3 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-center text-2xl tracking-widest font-mono focus:border-bambu-green focus:outline-none`,placeholder:`000000`,maxLength:6,required:!0})]}),r===`token`&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:t(`profiles.login.accessToken`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:t(`profiles.login.accessTokenHint`)}),(0,G.jsx)(`textarea`,{value:d,onChange:e=>f(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-xs font-mono placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none resize-none`,placeholder:`eyJ...`,rows:4,required:!0})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:t(`profiles.login.region`)}),(0,G.jsxs)(`select`,{value:p,onChange:e=>m(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,G.jsx)(`option`,{value:`global`,children:t(`profiles.login.regionGlobal`)}),(0,G.jsx)(`option`,{value:`china`,children:t(`profiles.login.regionChina`)})]})]})]}),(0,G.jsxs)(`div`,{className:`flex gap-2 max-[550px]:flex-wrap max-[550px]:items-center`,children:[r===`code`&&(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:()=>i(`email`),className:`flex-1`,children:t(`profiles.login.back`)}),(0,G.jsxs)(Q,{type:`submit`,disabled:E,className:`flex-1`,children:[E?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(rl,{className:`w-4 h-4`}),t(r===`email`?`profiles.login.loginButton`:r===`code`?`profiles.login.verifyButton`:`profiles.login.setTokenButton`)]})]}),r===`email`&&(0,G.jsx)(`div`,{className:`pt-4 border-t border-bambu-dark-tertiary`,children:(0,G.jsxs)(`button`,{type:`button`,onClick:()=>i(`token`),className:`text-sm text-bambu-gray hover:text-white flex items-center gap-2 transition-colors`,children:[(0,G.jsx)(Kc,{className:`w-4 h-4`}),t(`profiles.login.useToken`)]})}),r===`token`&&(0,G.jsx)(`div`,{className:`pt-4 border-t border-bambu-dark-tertiary`,children:(0,G.jsxs)(`button`,{type:`button`,onClick:()=>i(`email`),className:`text-sm text-bambu-gray hover:text-white flex items-center gap-2 transition-colors`,children:[(0,G.jsx)(rl,{className:`w-4 h-4`}),t(`profiles.login.useEmail`)]})})]})]})})}function b5({label:e,value:t,options:n,onChange:r}){let[i,a]=(0,y.useState)(!1),o=n.find(e=>e.value===t);return(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsxs)(`button`,{onClick:()=>a(!i),className:`flex items-center gap-2 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-sm text-white hover:border-bambu-gray-dark transition-colors`,children:[(0,G.jsxs)(`span`,{className:`text-bambu-gray`,children:[e,`:`]}),(0,G.jsx)(`span`,{children:o?.label||`All`}),(0,G.jsx)(ps,{className:`w-4 h-4 text-bambu-gray transition-transform ${i?`rotate-180`:``}`})]}),i&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`fixed inset-0 z-10`,onClick:()=>a(!1)}),(0,G.jsx)(`div`,{className:`absolute top-full left-0 mt-1 min-w-[160px] bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl z-20 py-1 max-h-60 overflow-y-auto`,children:n.map(e=>(0,G.jsxs)(`button`,{onClick:()=>{r(e.value),a(!1)},className:`w-full px-3 py-2 text-left text-sm flex items-center justify-between hover:bg-bambu-dark-tertiary transition-colors ${t===e.value?`text-bambu-green`:`text-white`}`,children:[(0,G.jsx)(`span`,{children:e.label}),e.count!==void 0&&(0,G.jsx)(`span`,{className:`text-bambu-gray text-xs`,children:e.count})]},e.value))})]})]})}function _Ke(){let[e,t]=(0,y.useState)(!1);return(0,y.useEffect)(()=>{let e=()=>{t(window.scrollY>300)};return window.addEventListener(`scroll`,e),()=>window.removeEventListener(`scroll`,e)},[]),e?(0,G.jsx)(`button`,{onClick:()=>{window.scrollTo({top:0,behavior:`smooth`})},className:`fixed bottom-24 right-6 p-3 bg-bambu-green hover:bg-bambu-green-light text-white rounded-full shadow-lg shadow-bambu-green/25 transition-all z-40`,"aria-label":`Scroll to top`,children:(0,G.jsx)(Ho,{className:`w-5 h-5`})}):null}function x5({setting:e,onClick:t,onDuplicate:n,compareMode:r,isCompareSelected:i,compareIndex:a,compareDisabled:o,t:s}){let c=v5(e.name),l=y5(e.setting_id);return(0,G.jsxs)(`div`,{className:`flex items-center gap-2 group`,children:[(0,G.jsx)(`button`,{onClick:t,disabled:o,className:`flex-1 text-left px-3 py-2 rounded transition-colors ${i?`bg-blue-500/20 border border-blue-500/50`:o?`bg-bambu-dark/50 opacity-40 cursor-not-allowed`:`bg-bambu-dark hover:bg-bambu-dark-tertiary`} ${r&&!o?`cursor-pointer`:``}`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[i&&a!==void 0&&(0,G.jsx)(`span`,{className:`flex-shrink-0 w-5 h-5 rounded-full bg-blue-500 text-white text-xs flex items-center justify-center font-medium`,children:a+1}),!i&&l&&(0,G.jsx)(`span`,{className:`flex-shrink-0 w-1.5 h-1.5 rounded-full bg-bambu-green`,title:s(`profiles.presets.myPreset`)}),(0,G.jsx)(`span`,{className:`text-white text-sm truncate flex-1`,title:e.name,children:e.name}),c.filamentType&&e.type===`filament`&&(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:c.filamentType}),c.layerHeight&&e.type===`process`&&(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:c.layerHeight}),c.printer&&(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:c.printer})]})}),(0,G.jsx)(`button`,{onClick:e=>{e.stopPropagation(),n()},className:`can-hover:opacity-0 group-hover:opacity-100 focus-visible:opacity-100 text-bambu-gray hover:text-white transition-all p-1`,title:s(`profiles.presets.duplicate`),children:(0,G.jsx)(Vs,{className:`w-4 h-4`})})]})}function S5(e,t=0){let n=` `.repeat(t);if(e===null)return`null`;if(e===void 0)return`undefined`;if(typeof e==`string`){if(e.includes(`\\n`)||e.includes(` `)){let t=e.replace(/\\n/g,` `).replace(/\\"/g,`"`).replace(/\\t/g,` `).split(` `);if(t.length>1)return`""" @@ -4381,23 +4381,23 @@ img.ProseMirror-separator { `+n+`]`;if(typeof e==`object`){let r=Object.entries(e);return r.length===0?`{}`:`{ `+r.map(([e,r])=>n+` `+JSON.stringify(e)+`: `+S5(r,t+1)).join(`, `)+` -`+n+`}`}return String(e)}function _Ke({setting:e,onClose:t,onDeleted:n,onDuplicate:r,onEdit:i,hasPermission:a,t:o}){let{showToast:s}=qd(),c=co(),[l,u]=(0,y.useState)(!1),{data:d,isLoading:f}=K({queryKey:[`cloudSettingDetail`,e.setting_id],queryFn:()=>Z.getCloudSettingDetail(e.setting_id)}),p=q({mutationFn:()=>Z.deleteCloudSetting(e.setting_id),onSuccess:()=>{s(o(`profiles.presets.toast.deleted`)),c.invalidateQueries({queryKey:[`cloudSettings`]}),n()},onError:e=>s(e.message,`error`)}),m=y5(e.setting_id),h=v5(e.name,d?.setting?.inherits);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)(zd,{className:`w-full max-w-3xl max-h-[90vh] flex flex-col overflow-hidden`,children:(0,G.jsxs)(Vd,{className:`p-0 flex flex-col min-h-0 flex-1`,children:[(0,G.jsxs)(`div`,{className:`flex-shrink-0 flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`h2`,{className:`text-xl font-semibold text-white truncate`,children:e.name}),m&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 text-xs font-medium bg-bambu-green/20 text-bambu-green rounded-full`,children:o(`profiles.presets.editable`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mt-1 text-sm text-bambu-gray`,children:[(0,G.jsx)(`span`,{className:`capitalize`,children:o(`profiles.presets.types.${e.type}`)}),h.printer&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`span`,{children:`•`}),(0,G.jsx)(`span`,{children:h.printer})]})]})]}),(0,G.jsx)(`button`,{onClick:t,className:`p-2 text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary rounded-lg transition-colors`,children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]}),(0,G.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-4`,children:f?(0,G.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,G.jsx)(Y,{className:`w-8 h-8 text-bambu-green animate-spin`})}):d?(0,G.jsx)(`pre`,{className:`text-xs text-bambu-gray font-mono whitespace-pre-wrap break-all bg-bambu-dark p-4 rounded-lg border border-bambu-dark-tertiary overflow-x-auto max-w-full`,children:S5(d)}):(0,G.jsx)(`div`,{className:`text-center py-16 text-bambu-gray`,children:o(`profiles.presets.failedToLoadDetails`)})}),l?(0,G.jsxs)(`div`,{className:`flex-shrink-0 p-4 border-t border-bambu-dark-tertiary bg-red-500/5`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-3 text-red-700 dark:text-red-400`,children:[(0,G.jsx)(Lu,{className:`w-5 h-5`}),(0,G.jsx)(`span`,{className:`font-medium`,children:o(`profiles.presets.deleteConfirm`)})]}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4`,children:o(`profiles.presets.deleteWarning`,{name:e.name})}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>u(!1),disabled:p.isPending,className:`flex-1`,children:o(`common.cancel`)}),(0,G.jsxs)(Q,{variant:`danger`,onClick:()=>p.mutate(),disabled:p.isPending,className:`flex-1`,children:[p.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Pu,{className:`w-4 h-4`}),o(`common.delete`)]})]})]}):(0,G.jsx)(`div`,{className:`flex-shrink-0 p-4 border-t border-bambu-dark-tertiary`,children:(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:t,className:`flex-1`,children:o(`common.close`)}),(0,G.jsxs)(Q,{variant:`secondary`,onClick:r,disabled:!a(`cloud:auth`),title:a(`cloud:auth`)?void 0:o(`profiles.presets.noDuplicatePermission`),children:[(0,G.jsx)(Vs,{className:`w-4 h-4`}),o(`profiles.presets.duplicate`)]}),m&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(Q,{variant:`secondary`,onClick:i,disabled:f||!d||!a(`cloud:auth`),title:a(`cloud:auth`)?void 0:o(`profiles.presets.noEditPermission`),children:[(0,G.jsx)(Al,{className:`w-4 h-4`}),o(`common.edit`)]}),(0,G.jsx)(Q,{variant:`danger`,onClick:()=>u(!0),disabled:!a(`cloud:auth`),title:a(`cloud:auth`)?void 0:o(`profiles.presets.noDeletePermission`),children:(0,G.jsx)(Pu,{className:`w-4 h-4`})})]})]})})]})})})}function C5(){try{let e=localStorage.getItem(`bambusy_preset_templates`);return e?JSON.parse(e):[]}catch{return[]}}function w5(e){localStorage.setItem(`bambusy_preset_templates`,JSON.stringify(e))}function vKe({onClose:e,onApply:t,t:n}){let{showToast:r}=qd(),[i,a]=(0,y.useState)(C5),[o,s]=(0,y.useState)(`all`),[c,l]=(0,y.useState)(null),[u,d]=(0,y.useState)(``),[f,p]=(0,y.useState)(``),[m,h]=(0,y.useState)(`{}`),[g,_]=(0,y.useState)(null),[v,b]=(0,y.useState)(null),x=o===`all`?i:i.filter(e=>e.type===o),S=e=>{a(e),w5(e)},C=e=>{S(i.filter(t=>t.id!==e)),b(null),r(n(`profiles.templates.toast.deleted`))},w=e=>{l(e.id),d(e.name),p(e.description),h(JSON.stringify(e.settings,null,2)),_(null)},T=()=>{if(!(!c||!u.trim()))try{let e=JSON.parse(m);S(i.map(t=>t.id===c?{...t,name:u.trim(),description:f.trim(),settings:e}:t)),l(null),r(n(`profiles.templates.toast.updated`))}catch(e){_(e.message)}},E=()=>{l(null),d(``),p(``),h(`{}`),_(null)},D=e=>{S(i.map(t=>t.id===e?{...t,showInModal:!t.showInModal}:t))},O={filament:{label:n(`profiles.presets.types.filament`),icon:Zs,color:`text-amber-600 dark:text-amber-400`},print:{label:n(`profiles.presets.types.process`),icon:nu,color:`text-blue-600 dark:text-blue-400`},printer:{label:n(`profiles.presets.types.printer`),icon:Rl,color:`text-purple-600 dark:text-purple-400`}},k=v?i.find(e=>e.id===v):null;return(0,y.useEffect)(()=>{let t=t=>{t.key===`Escape`&&(v?b(null):c?E():e())};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[v,c,e]),(0,G.jsxs)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:[k&&(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-60`,children:(0,G.jsx)(zd,{className:`w-full max-w-md`,children:(0,G.jsxs)(Vd,{className:`p-6`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3 mb-4`,children:[(0,G.jsx)(`div`,{className:`p-2 bg-red-500/20 rounded-lg`,children:(0,G.jsx)(Lu,{className:`w-6 h-6 text-red-600 dark:text-red-400`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`text-lg font-semibold text-white`,children:n(`profiles.templates.deleteTitle`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`profiles.templates.deleteWarning`)})]})]}),(0,G.jsx)(`p`,{className:`text-white mb-6`,children:n(`profiles.templates.deleteConfirm`,{name:k.name})}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>b(null),className:`flex-1`,children:n(`common.cancel`)}),(0,G.jsxs)(Q,{onClick:()=>C(v),className:`flex-1 bg-red-500 hover:bg-red-600`,children:[(0,G.jsx)(Pu,{className:`w-4 h-4`}),n(`common.delete`)]})]})]})})}),(0,G.jsx)(zd,{className:`w-full max-w-2xl max-h-[80vh] flex flex-col`,children:(0,G.jsxs)(Vd,{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.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(_u,{className:`w-5 h-5 text-amber-600 dark:text-amber-400`}),n(`profiles.templates.title`)]}),(0,G.jsx)(`button`,{onClick:e,className:`text-bambu-gray hover:text-white`,children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 p-4 border-b border-bambu-dark-tertiary`,children:[(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:n(`profiles.templates.typeFilter`)}),[`all`,`filament`,`print`,`printer`].map(e=>(0,G.jsx)(`button`,{onClick:()=>s(e),className:`px-3 py-1 text-sm rounded-lg transition-colors ${o===e?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white`}`,children:e===`all`?n(`common.all`):O[e].label},e))]}),(0,G.jsx)(`div`,{className:`flex-1 overflow-y-auto p-4`,children:x.length===0?(0,G.jsxs)(`div`,{className:`text-center py-12 text-bambu-gray`,children:[(0,G.jsx)(_u,{className:`w-12 h-12 mx-auto mb-4 opacity-30`}),(0,G.jsx)(`p`,{children:n(`profiles.templates.noTemplates`)}),(0,G.jsx)(`p`,{className:`text-sm mt-1`,children:n(`profiles.templates.createFirst`)})]}):(0,G.jsx)(`div`,{className:`space-y-2`,children:x.map(e=>{let r=O[e.type],i=r.icon;return c===e.id?(0,G.jsxs)(`div`,{className:`p-4 bg-bambu-dark rounded-lg border border-bambu-green`,children:[(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-3 mb-3`,children:[(0,G.jsx)(`input`,{type:`text`,value:u,onChange:e=>d(e.target.value),placeholder:n(`profiles.templates.namePlaceholder`),className:`px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`,autoFocus:!0}),(0,G.jsx)(`input`,{type:`text`,value:f,onChange:e=>p(e.target.value),placeholder:n(`profiles.templates.descriptionPlaceholder`),className:`px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`})]}),(0,G.jsxs)(`div`,{className:`mb-3`,children:[(0,G.jsx)(`label`,{className:`text-xs text-bambu-gray mb-1 block`,children:n(`profiles.templates.settingsJson`)}),(0,G.jsx)(`textarea`,{value:m,onChange:e=>{h(e.target.value),_(null)},rows:6,className:`w-full px-3 py-2 bg-bambu-dark-secondary border rounded text-white text-sm font-mono focus:outline-none ${g?`border-red-500`:`border-bambu-dark-tertiary focus:border-bambu-green`}`}),g&&(0,G.jsx)(`p`,{className:`text-xs text-red-700 dark:text-red-400 mt-1`,children:g})]}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsxs)(Q,{size:`sm`,onClick:T,disabled:!u.trim(),children:[(0,G.jsx)(ql,{className:`w-4 h-4`}),`Save`]}),(0,G.jsx)(Q,{size:`sm`,variant:`secondary`,onClick:E,children:`Cancel`})]})]},e.id):(0,G.jsxs)(`div`,{className:`flex items-center gap-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary hover:border-bambu-gray-dark transition-colors`,children:[(0,G.jsx)(i,{className:`w-5 h-5 ${r.color} flex-shrink-0`}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`p`,{className:`text-sm font-medium text-white`,children:e.name}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray truncate`,children:e.description})]}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray-dark px-2 py-1 bg-bambu-dark-secondary rounded`,children:n(`profiles.templates.fieldsCount`,{count:Object.keys(e.settings).length})}),(0,G.jsx)(`button`,{onClick:()=>D(e.id),className:`p-1 transition-colors ${e.showInModal?`text-bambu-green hover:text-bambu-green/70`:`text-bambu-gray hover:text-white`}`,title:e.showInModal?n(`profiles.templates.shownInModals`):n(`profiles.templates.hiddenInModals`),children:e.showInModal?(0,G.jsx)(ac,{className:`w-4 h-4`}):(0,G.jsx)(ic,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:()=>t(e),className:`px-3 py-1 text-xs bg-bambu-green/20 text-bambu-green rounded hover:bg-bambu-green/30 transition-colors`,children:n(`profiles.templates.apply`)}),(0,G.jsx)(`button`,{onClick:()=>w(e),className:`p-1 text-bambu-gray hover:text-white`,title:n(`common.edit`),children:(0,G.jsx)(Al,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:()=>b(e.id),className:`p-1 text-bambu-gray hover:text-red-600 dark:hover:text-red-400`,title:n(`common.delete`),children:(0,G.jsx)(Pu,{className:`w-4 h-4`})})]},e.id)})})})]})})]})}function T5({onClose:e,leftPreset:t,rightPreset:n,leftLabel:r,rightLabel:i,t:a}){let[o,s]=(0,y.useState)(`changes`),[c,l]=(0,y.useState)(``),u=(0,y.useMemo)(()=>{let e=new Set([...Object.keys(t),...Object.keys(n)]),r=[];for(let i of e){if(i===`inherits`||i===`version`)continue;let e=t[i],a=n[i],o=i in t,s=i in n,c;c=!o&&s?`added`:o&&!s?`removed`:JSON.stringify(e)===JSON.stringify(a)?`same`:`changed`,r.push({key:i,left:e,right:a,status:c})}return r.sort((e,t)=>{let n={changed:0,added:1,removed:2,same:3};return n[e.status]===n[t.status]?e.key.localeCompare(t.key):n[e.status]-n[t.status]})},[t,n]),d=(0,y.useMemo)(()=>{let e=[...u];if(o===`changes`&&(e=e.filter(e=>e.status!==`same`)),c){let t=c.toLowerCase();e=e.filter(e=>e.key.toLowerCase().includes(t)||String(e.left).toLowerCase().includes(t)||String(e.right).toLowerCase().includes(t))}return e},[u,o,c]),f=(0,y.useMemo)(()=>({added:u.filter(e=>e.status===`added`).length,removed:u.filter(e=>e.status===`removed`).length,changed:u.filter(e=>e.status===`changed`).length,same:u.filter(e=>e.status===`same`).length}),[u]),p=e=>{if(e===void 0)return`—`;if(e===null)return`null`;if(Array.isArray(e))return e.length===0?`[]`:e.length===1?String(e[0]):e.join(`, `);if(typeof e==`object`)return JSON.stringify(e);let t=String(e);if(t.includes(`\\n`)||t.length>100){let e=t.split(`\\n`).length;if(e>1)return`[${e} lines of G-code/script]`;if(t.length>100)return t.substring(0,100)+`…`}return t};return(0,y.useEffect)(()=>{let t=t=>{t.key===`Escape`&&e()};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e]),(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,G.jsx)(zd,{className:`w-full max-w-4xl max-h-[85vh] flex flex-col overflow-hidden`,children:(0,G.jsxs)(Vd,{className:`p-0 flex flex-col min-h-0 flex-1`,children:[(0,G.jsxs)(`div`,{className:`flex-shrink-0 flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(Oc,{className:`w-5 h-5 text-blue-600 dark:text-blue-400`}),a(`profiles.diff.title`)]}),(0,G.jsx)(`button`,{onClick:e,className:`text-bambu-gray hover:text-white`,children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]}),(0,G.jsxs)(`div`,{className:`flex-shrink-0 grid grid-cols-2 gap-4 p-4 border-b border-bambu-dark-tertiary bg-bambu-dark`,children:[(0,G.jsxs)(`div`,{className:`text-center`,children:[(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:a(`profiles.diff.left`)}),(0,G.jsx)(`p`,{className:`text-white font-medium truncate`,children:r})]}),(0,G.jsxs)(`div`,{className:`text-center`,children:[(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:a(`profiles.diff.right`)}),(0,G.jsx)(`p`,{className:`text-white font-medium truncate`,children:i})]})]}),(0,G.jsxs)(`div`,{className:`flex-shrink-0 flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-4 text-sm`,children:[(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-green-700 dark:text-green-400`,children:[(0,G.jsx)(Fl,{className:`w-3.5 h-3.5`}),f.added,` `,a(`profiles.diff.added`)]}),(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-red-700 dark:text-red-400`,children:[(0,G.jsx)(ml,{className:`w-3.5 h-3.5`}),f.removed,` `,a(`profiles.diff.removed`)]}),(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-amber-700 dark:text-amber-400`,children:[(0,G.jsx)(zo,{className:`w-3.5 h-3.5`}),f.changed,` `,a(`profiles.diff.changed`)]}),(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-bambu-gray`,children:[(0,G.jsx)(tc,{className:`w-3.5 h-3.5`}),f.same,` `,a(`profiles.diff.same`)]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(Ql,{className:`absolute left-2 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,G.jsx)(`input`,{type:`text`,value:c,onChange:e=>l(e.target.value),placeholder:a(`profiles.diff.searchFields`),className:`pl-8 pr-3 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none w-48`})]}),f.same>0&&(0,G.jsxs)(`div`,{className:`flex rounded overflow-hidden border border-bambu-dark-tertiary`,children:[(0,G.jsx)(`button`,{onClick:()=>s(`changes`),className:`px-3 py-1.5 text-sm transition-colors ${o===`changes`?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white`}`,children:a(`profiles.diff.changes`)}),(0,G.jsx)(`button`,{onClick:()=>s(`all`),className:`px-3 py-1.5 text-sm transition-colors ${o===`all`?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white`}`,children:a(`common.all`)})]})]})]}),(0,G.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto`,children:d.length===0?(0,G.jsxs)(`div`,{className:`text-center py-12 text-bambu-gray`,children:[(0,G.jsx)(tc,{className:`w-12 h-12 mx-auto mb-4 opacity-30`}),(0,G.jsx)(`p`,{children:a(o===`changes`?`profiles.diff.noDifferences`:`profiles.diff.noFieldsMatch`)})]}):(0,G.jsxs)(`table`,{className:`w-full`,children:[(0,G.jsx)(`thead`,{className:`sticky top-0 bg-bambu-dark-secondary`,children:(0,G.jsxs)(`tr`,{className:`text-sm text-bambu-gray border-b border-bambu-dark-tertiary`,children:[(0,G.jsx)(`th`,{className:`text-left p-3 w-1/3`,children:a(`profiles.diff.field`)}),(0,G.jsx)(`th`,{className:`text-left p-3 w-1/3`,children:r}),(0,G.jsx)(`th`,{className:`text-left p-3 w-1/3`,children:i})]})}),(0,G.jsx)(`tbody`,{children:d.map(e=>{let t={added:`bg-green-500/10`,removed:`bg-red-500/10`,changed:`bg-amber-500/10`,same:``}[e.status],n={added:(0,G.jsx)(Fl,{className:`w-3.5 h-3.5 text-green-600 dark:text-green-400`}),removed:(0,G.jsx)(ml,{className:`w-3.5 h-3.5 text-red-600 dark:text-red-400`}),changed:(0,G.jsx)(zo,{className:`w-3.5 h-3.5 text-amber-600 dark:text-amber-400`}),same:(0,G.jsx)(tc,{className:`w-3.5 h-3.5 text-bambu-gray-dark`})}[e.status];return(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary ${t}`,children:[(0,G.jsx)(`td`,{className:`p-3`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[n,(0,G.jsx)(`span`,{className:`text-sm text-white font-mono`,children:e.key})]})}),(0,G.jsx)(`td`,{className:`p-3`,children:(0,G.jsx)(`span`,{className:`text-sm font-mono break-all ${e.status===`removed`?`text-red-700 dark:text-red-300`:e.status===`changed`?`text-white`:`text-bambu-gray`}`,children:p(e.left)})}),(0,G.jsx)(`td`,{className:`p-3`,children:(0,G.jsx)(`span`,{className:`text-sm font-mono break-all ${e.status===`added`?`text-green-700 dark:text-green-300`:e.status===`changed`?`text-white`:`text-bambu-gray`}`,children:p(e.right)})})]},e.key)})})]})})]})})})}function yKe({onClose:e,initialData:t,allPresets:n,t:r}){let{showToast:i}=qd(),a=co(),o=!!t?.setting_id,[s,c]=(0,y.useState)(`common`),[l,u]=(0,y.useState)(t?.type||`filament`),[d,f]=(0,y.useState)(t?.name?o?t.name:`${t.name} (Copy)`:``),[p,m]=(0,y.useState)(t?.base_id||``),[h,g]=(0,y.useState)(``),[_,v]=(0,y.useState)(t?.setting||{inherits:``}),[b,x]=(0,y.useState)(JSON.stringify(t?.setting||{inherits:``},null,2)),[S,C]=(0,y.useState)(null),[w,T]=(0,y.useState)(``),[E,D]=(0,y.useState)(!1),[O,k]=(0,y.useState)(``),[A,j]=(0,y.useState)(!1),[M,N]=(0,y.useState)(C5),[P,F]=(0,y.useState)(!1),[I,L]=(0,y.useState)(``),[R,z]=(0,y.useState)(``),[B,V]=(0,y.useState)(!0),[ee,te]=(0,y.useState)(null),[ne,re]=(0,y.useState)(!1),ie=(0,y.useMemo)(()=>({filament:n.filament,print:n.process,printer:n.printer})[l]||[],[n,l]),ae=(0,y.useMemo)(()=>ie.filter(e=>y5(e.setting_id)),[ie]),{data:oe}=K({queryKey:[`cloudFields`,l],queryFn:()=>Z.getCloudFields(l===`print`?`process`:l),staleTime:1e3*60*60}),{data:se}=K({queryKey:[`allPresetDetails`,l,ae.map(e=>e.setting_id).join(`,`)],queryFn:async()=>{let e={};for(let t=0;t{try{let t=await Z.getCloudSettingDetail(e.setting_id);return{id:e.setting_id,detail:t}}catch{return null}}))).forEach(t=>{t&&(e[t.id]=t.detail)})}return e},enabled:ae.length>0,staleTime:1e3*60*10}),{data:H,isLoading:ce}=K({queryKey:[`cloudSettingDetail`,p],queryFn:()=>Z.getCloudSettingDetail(p),enabled:!!p});(0,y.useEffect)(()=>{s!==`json`&&x(JSON.stringify(_,null,2))},[_,s]);let le=(0,y.useMemo)(()=>({filament:n.filament,print:n.process,printer:n.printer}[l]||[]).filter(e=>!y5(e.setting_id)).sort((e,t)=>e.name.localeCompare(t.name)),[n,l]);(0,y.useEffect)(()=>{if(!p)return;let e=le.find(e=>e.setting_id===p);e&&(g(e.name),o||(v({inherits:e.name}),x(JSON.stringify({inherits:e.name},null,2))))},[p,le,o]);let ue=(0,y.useMemo)(()=>{let e=oe?.fields||[],t=new Set(e.map(e=>e.key)),n=new Set,i=new Set([`inherits`,`updated_time`,`compatible_printers`,`compatible_prints`]);se&&Object.values(se).forEach(e=>{e?.setting&&Object.keys(e.setting).forEach(e=>{!t.has(e)&&!i.has(e)&&n.add(e)})}),Object.keys(_).forEach(e=>{!t.has(e)&&!i.has(e)&&n.add(e)});let a=Array.from(n).sort().map(e=>({key:e,label:e.replace(/_/g,` `).replace(/\b\w/g,e=>e.toUpperCase()),type:`text`,category:`discovered`,description:r(`profiles.presets.discoveredFromPresets`)}));return[...e,...a]},[oe,se,_,r]),de=ue.filter(e=>e.label.toLowerCase().includes(w.toLowerCase())||e.key.toLowerCase().includes(w.toLowerCase())),fe=()=>{if(O.trim()){let e=O.trim().toLowerCase().replace(/\s+/g,`_`);pe(e,``),k(``),j(!1),i(r(`profiles.presets.toast.fieldAdded`,{key:e}))}},pe=(e,t)=>{v(n=>{let r={...n};return t===``||t===void 0?delete r[e]:r[e]=t,r})},me=e=>{v(t=>({...t,...e.settings})),te(e.name),i(r(`profiles.templates.toast.applied`))},he=()=>{if(!I.trim())return;let e={..._};if(delete e.inherits,Object.keys(e).length===0){i(r(`profiles.presets.noOverridesToSave`),`error`);return}let t={id:Date.now().toString(),name:I.trim(),description:R.trim()||r(`profiles.presets.customTemplate`),type:l,settings:e,showInModal:B},n=[...M,t];N(n),w5(n),F(!1),L(``),z(``),V(!0),i(r(`profiles.templates.toast.created`))},ge=(0,y.useMemo)(()=>M.filter(e=>e.type===l&&e.showInModal),[l,M]),_e=e=>{x(e);try{v(JSON.parse(e)),C(null)}catch(e){C(e.message)}},ve=e=>{e.preventDefault(),D(!1);let t=e.dataTransfer.files[0];if(t&&t.name.endsWith(`.json`)){let e=new FileReader;e.onload=e=>{try{let t=e.target?.result,n=JSON.parse(t),a=n.setting||n;v(e=>({...e,...a})),x(JSON.stringify({..._,...a},null,2)),i(r(`profiles.presets.fileImported`))}catch{i(r(`profiles.presets.invalidJsonFile`),`error`)}},e.readAsText(t)}},ye=q({mutationFn:()=>{let e={..._},t=l===`filament`?`filament_settings_id`:l===`print`?`print_settings_id`:`printer_settings_id`;e[t]=`"${d}"`;let n={type:l,name:d,base_id:p,setting:e};return Z.createCloudSetting(n)},onSuccess:async()=>{i(r(`profiles.presets.toast.created`)),await a.refetchQueries({queryKey:[`cloudSettings`]}),e()},onError:e=>i(e.message,`error`)}),be=q({mutationFn:()=>{if(!t?.setting_id)throw Error(r(`profiles.presets.noSettingId`));return Z.updateCloudSetting(t.setting_id,{name:d,setting:_})},onSuccess:async()=>{i(r(`profiles.presets.toast.updated`)),a.removeQueries({queryKey:[`cloudSettingDetail`]}),await a.refetchQueries({queryKey:[`cloudSettings`]}),e()},onError:e=>i(e.message,`error`)}),xe=o?be:ye,Se=H?.setting?.inherits,Ce=Se?le.find(e=>e.name===Se):void 0,{data:we}=K({queryKey:[`cloudSettingDetail`,Ce?.setting_id],queryFn:()=>Z.getCloudSettingDetail(Ce.setting_id),enabled:!!Ce?.setting_id}),Te=(0,y.useMemo)(()=>{let e=we?.setting||{},t=H?.setting||{},n=p&&se?.[p]?.setting?se[p].setting:{};return{...e,...t,...n}},[p,H,we,se]),Ee=e=>{if(e==null)return``;if(Array.isArray(e)){let t=[...new Set(e.map(e=>String(e)))];return t.length===1?t[0]:e.join(`, `)}return String(e)},De=e=>{let t=_[e.key],n=Te[e.key],i=Ee(n),a=ce?r(`common.loading`):i||``,o=`w-full px-3 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`;if(e.type===`boolean`){let r=t===`1`||t===void 0&&n===`1`;return(0,G.jsx)(`button`,{type:`button`,onClick:()=>pe(e.key,t===`1`?`0`:`1`),className:`w-8 h-5 rounded-full transition-colors ${r?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,children:(0,G.jsx)(`div`,{className:`w-4 h-4 rounded-full bg-white shadow transition-transform ${r?`translate-x-3.5`:`translate-x-0.5`}`})})}return e.type===`select`?(0,G.jsxs)(`select`,{value:t||``,onChange:t=>pe(e.key,t.target.value),className:o,children:[(0,G.jsx)(`option`,{value:``,children:a}),e.options?.map(e=>(0,G.jsx)(`option`,{value:e.value,children:e.label},e.value))]}):(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`input`,{type:e.type===`number`?`number`:`text`,value:t===void 0?``:String(t),onChange:t=>pe(e.key,t.target.value),step:e.step,min:e.min,max:e.max,placeholder:a,className:o}),e.unit&&(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:e.unit})]})},Oe=(0,y.useMemo)(()=>H?.setting?H.setting:{},[H]);return(0,G.jsxs)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,onDragOver:e=>{e.preventDefault(),D(!0)},onDragLeave:()=>D(!1),onDrop:ve,children:[ne&&p&&(0,G.jsx)(T5,{onClose:()=>re(!1),leftPreset:Oe,rightPreset:_,leftLabel:r(`profiles.presets.baseLabel`,{name:h||p}),rightLabel:r(`profiles.presets.currentLabel`,{name:d||r(`profiles.presets.newPreset`)}),t:r}),(0,G.jsx)(zd,{className:`w-full max-w-6xl max-h-[90vh] flex flex-col overflow-y-auto`,children:(0,G.jsxs)(Vd,{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.jsxs)(`div`,{children:[(0,G.jsx)(`h2`,{className:`text-xl font-semibold text-white`,children:r(o?`profiles.presets.editPreset`:t?`profiles.presets.duplicatePreset`:`profiles.presets.createNewPreset`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:r(`profiles.presets.customizeSettings`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[p&&(0,G.jsxs)(`button`,{onClick:()=>re(!0),className:`flex items-center gap-2 px-3 py-2 text-sm text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary rounded-lg transition-colors`,title:r(`profiles.presets.compareWithBase`),children:[(0,G.jsx)(Oc,{className:`w-4 h-4`}),r(`profiles.presets.compare`)]}),(0,G.jsx)(`button`,{onClick:e,className:`p-2 text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary rounded-lg transition-colors`,children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]})]}),E&&(0,G.jsx)(`div`,{className:`absolute inset-0 bg-bambu-green/10 border-2 border-dashed border-bambu-green rounded-lg flex items-center justify-center z-10`,children:(0,G.jsxs)(`div`,{className:`text-center`,children:[(0,G.jsx)(Vu,{className:`w-12 h-12 text-bambu-green mx-auto mb-2`}),(0,G.jsx)(`p`,{className:`text-bambu-green font-medium`,children:r(`profiles.presets.dropJsonToImport`)})]})}),(0,G.jsxs)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary space-y-3`,children:[(0,G.jsxs)(`div`,{className:`grid grid-cols-3 gap-4 max-[640px]:grid-cols-1`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`common.type`)}),(0,G.jsxs)(`select`,{value:l,onChange:e=>{u(e.target.value),m(``)},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:`filament`,children:r(`profiles.presets.types.filament`)}),(0,G.jsx)(`option`,{value:`print`,children:r(`profiles.presets.types.process`)}),(0,G.jsx)(`option`,{value:`printer`,children:r(`profiles.presets.types.printer`)})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`profiles.presets.basePreset`)}),(0,G.jsxs)(`select`,{value:p,onChange:e=>m(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,children:[(0,G.jsx)(`option`,{value:``,children:r(`profiles.presets.selectBasePreset`)}),le.map(e=>(0,G.jsx)(`option`,{value:e.setting_id,children:e.name},e.setting_id))]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`profiles.presets.presetName`)}),(0,G.jsx)(`input`,{type:`text`,value:d,onChange:e=>f(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,placeholder:r(`profiles.presets.myCustomPreset`)})]})]}),h&&(0,G.jsx)(`div`,{className:`text-xs text-bambu-gray`,children:(0,G.jsxs)(`p`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(fs,{className:`w-3 h-3 text-bambu-green`}),r(`profiles.presets.inheritsFrom`),` `,(0,G.jsx)(`span`,{className:`text-white`,children:h}),ce&&(0,G.jsx)(Y,{className:`w-3 h-3 animate-spin ml-1`})]})})]}),(0,G.jsxs)(`div`,{className:`flex border-b border-bambu-dark-tertiary max-[640px]:flex-wrap max-[640px]:items-center`,children:[(0,G.jsxs)(`button`,{onClick:()=>c(`common`),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${s===`common`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-white border-transparent`}`,children:[(0,G.jsx)(pu,{className:`w-4 h-4`}),r(`profiles.presets.tabs.common`)]}),(0,G.jsxs)(`button`,{onClick:()=>c(`fields`),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${s===`fields`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-white border-transparent`}`,children:[(0,G.jsx)(el,{className:`w-4 h-4`}),r(`profiles.presets.tabs.allFields`)]}),(0,G.jsxs)(`button`,{onClick:()=>c(`json`),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${s===`json`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-white border-transparent`}`,children:[(0,G.jsx)(Fs,{className:`w-4 h-4`}),`JSON`,S&&(0,G.jsx)(ys,{className:`w-3 h-3 text-red-600 dark:text-red-400`})]}),(0,G.jsx)(`div`,{className:`flex-1 max-[640px]:hidden`}),(0,G.jsxs)(`button`,{onClick:()=>{let e=new Blob([JSON.stringify({name:d,type:l,base_id:p,setting:_},null,2)],{type:`application/json`}),t=URL.createObjectURL(e),n=document.createElement(`a`);n.href=t,n.download=`${d||`preset`}.json`,document.body.appendChild(n),n.click(),document.body.removeChild(n),URL.revokeObjectURL(t),i(r(`profiles.presets.toast.exported`))},className:`flex items-center gap-2 px-4 py-3 text-sm text-bambu-gray hover:text-white transition-colors`,title:r(`profiles.presets.exportToJson`),children:[(0,G.jsx)(Xs,{className:`w-4 h-4`}),r(`common.download`)]}),(0,G.jsxs)(`button`,{onClick:()=>document.getElementById(`file-import`)?.click(),className:`flex items-center gap-2 px-4 py-3 text-sm text-bambu-gray hover:text-white transition-colors`,title:r(`profiles.presets.importFromJson`),children:[(0,G.jsx)(Vu,{className:`w-4 h-4`}),r(`common.upload`)]}),(0,G.jsx)(`input`,{id:`file-import`,type:`file`,accept:`.json`,className:`hidden`,onChange:e=>{let t=e.target.files?.[0];if(t){let e=new FileReader;e.onload=e=>{try{let t=JSON.parse(e.target?.result),n=t.setting||t;v(e=>({...e,...n})),i(r(`profiles.presets.fileImported`))}catch{i(r(`profiles.presets.invalidJson`),`error`)}},e.readAsText(t)}}})]}),(0,G.jsxs)(`div`,{className:`flex-1 p-4`,children:[s===`common`&&(0,G.jsxs)(`div`,{className:`space-y-6`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,G.jsxs)(`h3`,{className:`text-sm font-medium text-white flex items-center gap-2`,children:[(0,G.jsx)(_u,{className:`w-4 h-4 text-amber-600 dark:text-amber-400`}),r(`profiles.templates.title`)]}),Object.keys(_).filter(e=>e!==`inherits`).length>0&&(0,G.jsxs)(`button`,{onClick:()=>F(!P),className:`text-xs text-bambu-gray hover:text-white flex items-center gap-1 transition-colors`,children:[(0,G.jsx)(ql,{className:`w-3 h-3`}),r(`profiles.presets.saveAsTemplate`)]})]}),P&&(0,G.jsxs)(`div`,{className:`mb-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-2 mb-2`,children:[(0,G.jsx)(`input`,{type:`text`,value:I,onChange:e=>L(e.target.value),placeholder:r(`profiles.templates.namePlaceholder`),className:`px-3 py-1.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`,autoFocus:!0}),(0,G.jsx)(`input`,{type:`text`,value:R,onChange:e=>z(e.target.value),placeholder:r(`profiles.templates.descriptionPlaceholder`),className:`px-3 py-1.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsxs)(Q,{size:`sm`,onClick:he,disabled:!I.trim(),children:[(0,G.jsx)(ql,{className:`w-3 h-3`}),r(`common.save`)]}),(0,G.jsx)(Q,{size:`sm`,variant:`secondary`,onClick:()=>F(!1),children:r(`common.cancel`)})]}),(0,G.jsxs)(`button`,{onClick:()=>V(!B),className:`flex items-center gap-1.5 text-xs transition-colors ${B?`text-bambu-green`:`text-bambu-gray hover:text-white`}`,children:[B?(0,G.jsx)(ac,{className:`w-3.5 h-3.5`}):(0,G.jsx)(ic,{className:`w-3.5 h-3.5`}),r(B?`profiles.templates.shownInModals`:`profiles.templates.hiddenInModals`)]})]})]}),ee&&(0,G.jsxs)(`div`,{className:`mb-3 px-3 py-2 bg-bambu-green/10 border border-bambu-green/30 rounded-lg flex items-center gap-2`,children:[(0,G.jsx)(fs,{className:`w-4 h-4 text-bambu-green`}),(0,G.jsxs)(`span`,{className:`text-sm text-bambu-green`,children:[r(`profiles.presets.templateApplied`),` `,(0,G.jsx)(`span`,{className:`font-medium`,children:ee})]}),(0,G.jsx)(`button`,{onClick:()=>te(null),className:`ml-auto text-bambu-green/70 hover:text-bambu-green`,children:(0,G.jsx)(nd,{className:`w-4 h-4`})})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-3 gap-2`,children:[ge.map(e=>(0,G.jsxs)(`button`,{onClick:()=>me(e),className:`p-3 text-left bg-bambu-dark border border-bambu-dark-tertiary rounded-lg hover:border-bambu-gray-dark transition-colors`,children:[(0,G.jsx)(`p`,{className:`text-sm font-medium text-white`,children:e.name}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e.description})]},e.id)),ge.length===0&&(0,G.jsx)(`p`,{className:`col-span-3 text-center text-bambu-gray text-sm py-4`,children:r(`profiles.presets.noTemplatesSelected`)})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray-dark mt-2 text-center`,children:r(`profiles.presets.manageTemplatesHint`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`text-sm font-medium text-white mb-3`,children:r(`profiles.presets.commonSettings`)}),(0,G.jsx)(`div`,{className:`grid grid-cols-2 gap-x-6 gap-y-3`,children:ue.slice(0,10).map(e=>(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-4 max-[640px]:flex-col max-[640px]:items-start`,children:[(0,G.jsx)(`label`,{className:`text-sm text-bambu-gray flex-shrink-0`,children:e.label}),(0,G.jsx)(`div`,{className:`w-48 max-[640px]:w-full`,children:De(e)})]},e.key))})]}),Object.keys(_).length>1&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`text-sm font-medium text-white mb-3`,children:r(`profiles.presets.currentOverrides`)}),(0,G.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:Object.entries(_).filter(([e])=>e!==`inherits`).map(([e,t])=>(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-2 py-1 bg-bambu-green/10 text-bambu-green text-xs rounded`,children:[e,`: `,String(t).slice(0,20),(0,G.jsx)(`button`,{onClick:()=>pe(e,void 0),className:`hover:text-white`,children:(0,G.jsx)(nd,{className:`w-3 h-3`})})]},e))})]})]}),s===`fields`&&(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-6`,style:{height:`400px`},children:[(0,G.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-3 flex-shrink-0`,children:[(0,G.jsx)(`h3`,{className:`text-sm font-medium text-white`,children:r(`profiles.presets.availableFields`)}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:se?r(`profiles.templates.fieldsCount`,{count:ue.length}):r(`common.loading`)})]}),(0,G.jsxs)(`div`,{className:`relative mb-3 flex-shrink-0`,children:[(0,G.jsx)(Ql,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,G.jsx)(`input`,{type:`text`,value:w,onChange:e=>T(e.target.value),placeholder:r(`profiles.presets.searchFieldsPlaceholder`),className:`w-full pl-10 pr-4 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none`})]}),(0,G.jsxs)(`div`,{className:`flex-1 overflow-y-auto space-y-1 pr-2 min-h-0`,children:[de.filter(e=>!(e.key in _)).map(e=>{let t=Te[e.key],n=Ee(t);return(0,G.jsxs)(`div`,{onClick:()=>{v(t=>({...t,[e.key]:n||``}))},className:`flex items-center justify-between gap-2 p-2 rounded-lg hover:bg-bambu-dark-tertiary transition-colors cursor-pointer group`,children:[(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,G.jsx)(`p`,{className:`text-sm text-white truncate`,children:e.label}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray-dark truncate`,children:e.key})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[n&&(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray bg-bambu-dark px-2 py-0.5 rounded max-w-32 truncate`,title:n,children:[n.slice(0,20),n.length>20?`...`:``]}),(0,G.jsx)(`div`,{className:`w-6 h-6 flex items-center justify-center rounded bg-bambu-dark-tertiary group-hover:bg-bambu-green/20 transition-colors`,children:(0,G.jsx)(Fl,{className:`w-4 h-4 text-bambu-gray group-hover:text-bambu-green transition-colors`})})]})]},e.key)}),de.filter(e=>!(e.key in _)).length===0&&(0,G.jsx)(`p`,{className:`text-center text-bambu-gray py-4 text-sm`,children:r(w?`profiles.presets.noMatchingFields`:`profiles.presets.allFieldsAdded`)})]}),(0,G.jsx)(`div`,{className:`pt-3 mt-3 border-t border-bambu-dark-tertiary flex-shrink-0`,children:A?(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsx)(`input`,{type:`text`,value:O,onChange:e=>k(e.target.value),onKeyDown:e=>e.key===`Enter`&&fe(),placeholder:`custom_field_name`,className:`flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white font-mono text-sm placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none`,autoFocus:!0}),(0,G.jsx)(Q,{size:`sm`,onClick:fe,disabled:!O.trim(),children:(0,G.jsx)(Fl,{className:`w-4 h-4`})}),(0,G.jsx)(Q,{size:`sm`,variant:`secondary`,onClick:()=>{j(!1),k(``)},children:(0,G.jsx)(nd,{className:`w-4 h-4`})})]}):(0,G.jsxs)(`button`,{onClick:()=>j(!0),className:`w-full flex items-center justify-center gap-2 p-2 text-sm text-bambu-gray hover:text-white border border-dashed border-bambu-dark-tertiary hover:border-bambu-gray-dark rounded-lg transition-colors`,children:[(0,G.jsx)(Fl,{className:`w-4 h-4`}),r(`profiles.presets.addCustomField`)]})})]}),(0,G.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-3 flex-shrink-0`,children:[(0,G.jsx)(`h3`,{className:`text-sm font-medium text-white`,children:r(`profiles.presets.yourOverrides`)}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:r(`profiles.templates.fieldsCount`,{count:Object.keys(_).filter(e=>e!==`inherits`).length})})]}),(0,G.jsxs)(`div`,{className:`flex-1 overflow-y-auto space-y-2 pr-2 min-h-0`,children:[Object.entries(_).filter(([e])=>e!==`inherits`).map(([e,t])=>{let n=ue.find(t=>t.key===e);return(0,G.jsxs)(`div`,{className:`p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm font-medium text-white`,children:n?.label||e}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray-dark`,children:e})]}),(0,G.jsx)(`button`,{onClick:()=>pe(e,void 0),className:`p-1 text-bambu-gray hover:text-red-600 dark:hover:text-red-400 transition-colors`,children:(0,G.jsx)(nd,{className:`w-4 h-4`})})]}),n?De(n):(0,G.jsx)(`input`,{type:`text`,value:String(t),onChange:t=>pe(e,t.target.value),className:`w-full px-3 py-1.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`})]},e)}),Object.keys(_).filter(e=>e!==`inherits`).length===0&&(0,G.jsxs)(`div`,{className:`text-center py-8 text-bambu-gray`,children:[(0,G.jsx)(pu,{className:`w-8 h-8 mx-auto mb-2 opacity-50`}),(0,G.jsx)(`p`,{className:`text-sm`,children:r(`profiles.presets.noOverridesYet`)}),(0,G.jsx)(`p`,{className:`text-xs mt-1`,children:r(`profiles.presets.clickFieldsToAdd`)})]})]}),Object.keys(_).filter(e=>e!==`inherits`).length>0&&(0,G.jsx)(`div`,{className:`pt-3 mt-3 border-t border-bambu-dark-tertiary flex-shrink-0`,children:(0,G.jsxs)(`button`,{onClick:()=>{F(!0),c(`common`)},className:`w-full flex items-center justify-center gap-2 p-2 text-sm text-bambu-gray hover:text-white border border-dashed border-bambu-dark-tertiary hover:border-bambu-gray-dark rounded-lg transition-colors`,children:[(0,G.jsx)(ql,{className:`w-4 h-4`}),r(`profiles.presets.saveAsTemplate`)]})})]})]}),s===`json`&&(0,G.jsxs)(`div`,{className:`space-y-2`,children:[S&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-red-700 dark:text-red-400 text-sm`,children:[(0,G.jsx)(ys,{className:`w-4 h-4`}),S]}),(0,G.jsx)(`textarea`,{value:b,onChange:e=>_e(e.target.value),className:`w-full h-80 px-3 py-2 bg-bambu-dark border rounded-lg text-white text-xs font-mono focus:outline-none resize-none ${S?`border-red-500 focus:border-red-500`:`border-bambu-dark-tertiary focus:border-bambu-green`}`,spellCheck:!1}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:r(`profiles.presets.jsonTip`)})]})]}),(0,G.jsxs)(`div`,{className:`p-4 border-t border-bambu-dark-tertiary flex gap-2`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:e,className:`flex-1`,children:r(`common.cancel`)}),(0,G.jsxs)(Q,{onClick:()=>xe.mutate(),disabled:xe.isPending||!d.trim()||!o&&!p||!!S,className:`flex-1`,children:[xe.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):o?(0,G.jsx)(ql,{className:`w-4 h-4`}):(0,G.jsx)(Fl,{className:`w-4 h-4`}),r(o?`common.save`:t?`common.duplicate`:`common.create`)]})]})]})})]})}function bKe({settings:e,lastSyncTime:t,onRefresh:n,isRefreshing:r,printers:i,hasPermission:a,t:o}){let[s,c]=(0,y.useState)(``),[l,u]=(0,y.useState)(`all`),[d,f]=(0,y.useState)(`all`),[p,m]=(0,y.useState)(`all`),[h,g]=(0,y.useState)(`all`),[_,v]=(0,y.useState)(`all`),[b,x]=(0,y.useState)(`all`),[S,C]=(0,y.useState)(null),[w,T]=(0,y.useState)(!1),[E,D]=(0,y.useState)(!1),[O,k]=(0,y.useState)(null),[A,j]=(0,y.useState)(null),[M,N]=(0,y.useState)(null),[P,F]=(0,y.useState)(!1),[I,L]=(0,y.useState)([null,null]),[R,z]=(0,y.useState)(!1),[B,V]=(0,y.useState)(null),ee=co(),te=(0,y.useMemo)(()=>[...e.filament.map(e=>({...e,type:`filament`})),...e.printer.map(e=>({...e,type:`printer`})),...e.process.map(e=>({...e,type:`process`}))].map(e=>({...e,meta:v5(e.name)})),[e]),ne=(0,y.useMemo)(()=>{let e=new Set,t=new Set,n=new Set;return te.forEach(r=>{r.meta.nozzle&&e.add(r.meta.nozzle),r.meta.filamentType&&t.add(r.meta.filamentType),r.meta.layerHeight&&n.add(r.meta.layerHeight)}),{printers:i.map(e=>({id:e.id.toString(),name:e.name})),nozzles:Array.from(e).sort((e,t)=>parseFloat(e)-parseFloat(t)),filaments:Array.from(t).sort(),layerHeights:Array.from(n).sort((e,t)=>parseFloat(e)-parseFloat(t))}},[te,i]),re=(0,y.useMemo)(()=>p===`all`?null:i.find(e=>e.id.toString()===p)?.model||null,[p,i]),ie=(0,y.useMemo)(()=>te.filter(e=>l===`all`||e.type===l).filter(e=>{if(d===`all`)return!0;let t=y5(e.setting_id);return d===`custom`?t:!t}).filter(e=>{if(p===`all`||!re)return!0;let t=e.meta.printer?.toLowerCase()||``,n=re.toLowerCase();return t.includes(n)||n.includes(t)}).filter(e=>h===`all`||e.meta.nozzle===h).filter(e=>_===`all`||e.meta.filamentType===_).filter(e=>b===`all`||e.meta.layerHeight===b).filter(e=>s===``||e.name.toLowerCase().includes(s.toLowerCase())).sort((e,t)=>e.name.localeCompare(t.name)),[te,l,d,p,re,h,_,b,s]),ae=e=>{if(P){let t=I[0]?.setting_id===e.setting_id,n=I[1]?.setting_id===e.setting_id;if(t)L([I[1],null]);else if(n)L([I[0],null]);else if(!I[0])L([e,null]);else if(I[1]){if(I[0].type!==e.type)return;L([I[0],e])}else{if(I[0].type!==e.type)return;L([I[0],e])}}else C(e)},oe=e=>{if(I[0]?.setting_id===e.setting_id)return 0;if(I[1]?.setting_id===e.setting_id)return 1},se=async e=>{try{let t=await Z.getCloudSettingDetail(e.setting_id);k({type:e.type===`process`?`print`:e.type,name:e.name,base_id:t.base_id||`GFSA00`,setting:t.setting||{}}),C(null)}catch(e){console.error(`Failed to fetch preset details for duplication:`,e)}},H=async e=>{try{ee.removeQueries({queryKey:[`cloudSettingDetail`,e.setting_id]});let t=await Z.getCloudSettingDetail(e.setting_id);j({type:e.type===`process`?`print`:e.type,name:e.name,base_id:t.base_id||`GFSA00`,setting:t.setting||{},setting_id:e.setting_id}),C(null)}catch(e){console.error(`Failed to fetch preset details for editing:`,e)}},ce=()=>{u(`all`),f(`all`),m(`all`),g(`all`),v(`all`),x(`all`),c(``)},le=l!==`all`||d!==`all`||p!==`all`||h!==`all`||_!==`all`||b!==`all`||s!==``,ue=e.filament.length+e.printer.length+e.process.length;return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`space-y-4 mb-6`,children:[(0,G.jsxs)(`div`,{className:`flex flex-col sm:flex-row gap-3`,children:[(0,G.jsxs)(`div`,{className:`relative flex-1`,children:[(0,G.jsx)(Ql,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,G.jsx)(`input`,{type:`text`,value:s,onChange:e=>c(e.target.value),placeholder:o(`profiles.cloudView.searchPlaceholder`),className:`w-full pl-10 pr-4 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none`})]}),(0,G.jsxs)(`div`,{className:`flex gap-2 max-[550px]:flex-wrap max-[550px]:items-center`,children:[(0,G.jsxs)(Q,{variant:P?`primary`:`secondary`,onClick:()=>{P?(F(!1),L([null,null])):F(!0)},children:[(0,G.jsx)(Oc,{className:`w-4 h-4`}),o(P?`common.cancel`:`profiles.presets.compare`)]}),(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>D(!0),disabled:!a(`cloud:auth`),title:a(`cloud:auth`)?void 0:o(`profiles.cloudView.noTemplatesPermission`),children:[(0,G.jsx)(_u,{className:`w-4 h-4`}),o(`profiles.cloudView.templates`)]}),(0,G.jsxs)(Q,{variant:`secondary`,onClick:n,disabled:r||!a(`cloud:auth`),title:a(`cloud:auth`)?void 0:o(`profiles.cloudView.noRefreshPermission`),children:[(0,G.jsx)(Hl,{className:`w-4 h-4 ${r?`animate-spin`:``}`}),o(`profiles.cloudView.refresh`)]}),(0,G.jsxs)(Q,{onClick:()=>T(!0),disabled:!a(`cloud:auth`),title:a(`cloud:auth`)?void 0:o(`profiles.cloudView.noCreatePermission`),children:[(0,G.jsx)(Fl,{className:`w-4 h-4`}),o(`profiles.cloudView.newPreset`)]})]})]}),(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,G.jsx)(wc,{className:`w-4 h-4 text-bambu-gray`}),(0,G.jsx)(b5,{label:o(`profiles.cloudView.filters.type`),value:l,options:[{value:`all`,label:o(`profiles.cloudView.filters.all`),count:ue},{value:`filament`,label:o(`profiles.cloudView.filters.filament`),count:e.filament.length},{value:`printer`,label:o(`profiles.cloudView.filters.printer`),count:e.printer.length},{value:`process`,label:o(`profiles.cloudView.filters.process`),count:e.process.length}],onChange:e=>u(e)}),(0,G.jsx)(b5,{label:o(`profiles.cloudView.filters.owner`),value:d,options:[{value:`all`,label:o(`profiles.cloudView.filters.all`)},{value:`custom`,label:o(`profiles.cloudView.filters.myPresets`)},{value:`builtin`,label:o(`profiles.cloudView.filters.builtIn`)}],onChange:e=>f(e)}),ne.printers.length>0&&(0,G.jsx)(b5,{label:o(`profiles.cloudView.filters.printer`),value:p,options:[{value:`all`,label:o(`profiles.cloudView.filters.all`)},...ne.printers.map(e=>({value:e.id,label:e.name}))],onChange:m}),ne.nozzles.length>0&&(0,G.jsx)(b5,{label:o(`profiles.cloudView.filters.nozzle`),value:h,options:[{value:`all`,label:o(`profiles.cloudView.filters.all`)},...ne.nozzles.map(e=>({value:e,label:e}))],onChange:g}),ne.filaments.length>0&&(l===`all`||l===`filament`)&&(0,G.jsx)(b5,{label:o(`profiles.cloudView.filters.filament`),value:_,options:[{value:`all`,label:o(`profiles.cloudView.filters.all`)},...ne.filaments.map(e=>({value:e,label:e}))],onChange:v}),ne.layerHeights.length>0&&(l===`all`||l===`process`)&&(0,G.jsx)(b5,{label:o(`profiles.cloudView.filters.layer`),value:b,options:[{value:`all`,label:o(`profiles.cloudView.filters.all`)},...ne.layerHeights.map(e=>({value:e,label:e}))],onChange:x}),le&&(0,G.jsx)(`button`,{onClick:ce,className:`px-3 py-2 text-sm text-bambu-gray hover:text-white transition-colors`,children:o(`profiles.cloudView.clearFilters`)})]})]}),P&&(0,G.jsx)(`div`,{className:`mb-4 p-3 bg-blue-500/10 border border-blue-500/30 rounded-lg`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,G.jsx)(Oc,{className:`w-5 h-5 text-blue-600 dark:text-blue-400`}),(0,G.jsx)(`span`,{className:`text-white font-medium`,children:o(`profiles.cloudView.compareMode`)}),(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:I[0]?o(`profiles.cloudView.selectAnotherPreset`,{type:I[0].type}):o(`profiles.cloudView.clickTwoPresets`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`px-2 py-1 text-sm rounded truncate max-w-[200px] ${I[0]?`bg-blue-500/30 text-blue-700 dark:text-blue-300`:`bg-bambu-dark text-bambu-gray`}`,children:I[0]?I[0].name:o(`profiles.cloudView.selectFirst`)}),(0,G.jsx)(zo,{className:`w-4 h-4 text-bambu-gray`}),(0,G.jsx)(`span`,{className:`px-2 py-1 text-sm rounded truncate max-w-[200px] ${I[1]?`bg-blue-500/30 text-blue-700 dark:text-blue-300`:`bg-bambu-dark text-bambu-gray`}`,children:I[1]?I[1].name:o(`profiles.cloudView.selectSecond`)})]}),I[0]&&I[1]&&(0,G.jsxs)(Q,{size:`sm`,onClick:async()=>{try{let[e,t]=await Promise.all([Z.getCloudSettingDetail(I[0].setting_id),Z.getCloudSettingDetail(I[1].setting_id)]);V([e.setting||{},t.setting||{}]),z(!0)}catch{}},children:[(0,G.jsx)(Oc,{className:`w-4 h-4`}),o(`profiles.cloudView.compareNow`)]})]})]})}),(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4 mb-4 text-sm text-bambu-gray`,children:[t&&(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(js,{className:`w-3 h-3`}),o(`profiles.cloudView.lastSynced`),` `,up(t.toISOString(),`system`,o)]}),(0,G.jsx)(`span`,{children:o(`profiles.cloudView.showingCount`,{showing:ie.length,total:ue})}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-bambu-green`}),(0,G.jsxs)(`span`,{children:[`= `,o(`profiles.presets.myPreset`)]})]})]}),ie.length===0?(0,G.jsxs)(`div`,{className:`text-center py-16`,children:[(0,G.jsx)(Jc,{className:`w-12 h-12 text-bambu-gray-dark mx-auto mb-4`}),(0,G.jsx)(`p`,{className:`text-bambu-gray`,children:o(`profiles.cloudView.noPresetsFound`)}),le&&(0,G.jsx)(`button`,{onClick:ce,className:`mt-2 text-sm text-bambu-green hover:text-bambu-green-light`,children:o(`profiles.cloudView.clearFilters`)})]}):(0,G.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-6`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-3 px-1`,children:[(0,G.jsx)(Zs,{className:`w-4 h-4 text-amber-600 dark:text-amber-400`}),(0,G.jsx)(`h3`,{className:`text-sm font-medium text-bambu-gray`,children:o(`profiles.cloudView.columns.filament`)}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray-dark`,children:[`(`,ie.filter(e=>e.type===`filament`).length,`)`]})]}),(0,G.jsxs)(`div`,{className:`space-y-1 max-h-[calc(100vh-320px)] overflow-y-auto pr-1`,children:[ie.filter(e=>e.type===`filament`).map(e=>(0,G.jsx)(x5,{setting:e,onClick:()=>ae(e),onDuplicate:()=>se(e),compareMode:P,isCompareSelected:oe(e)!==void 0,compareIndex:oe(e),compareDisabled:P&&!!I[0]&&I[0].type!==e.type,t:o},e.setting_id)),ie.filter(e=>e.type===`filament`).length===0&&(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray-dark px-3 py-2`,children:o(`profiles.cloudView.noFilamentPresets`)})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-3 px-1`,children:[(0,G.jsx)(nu,{className:`w-4 h-4 text-blue-600 dark:text-blue-400`}),(0,G.jsx)(`h3`,{className:`text-sm font-medium text-bambu-gray`,children:o(`profiles.cloudView.columns.process`)}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray-dark`,children:[`(`,ie.filter(e=>e.type===`process`).length,`)`]})]}),(0,G.jsxs)(`div`,{className:`space-y-1 max-h-[calc(100vh-320px)] overflow-y-auto pr-1`,children:[ie.filter(e=>e.type===`process`).map(e=>(0,G.jsx)(x5,{setting:e,onClick:()=>ae(e),onDuplicate:()=>se(e),compareMode:P,isCompareSelected:oe(e)!==void 0,compareIndex:oe(e),compareDisabled:P&&!!I[0]&&I[0].type!==e.type,t:o},e.setting_id)),ie.filter(e=>e.type===`process`).length===0&&(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray-dark px-3 py-2`,children:o(`profiles.cloudView.noProcessPresets`)})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-3 px-1`,children:[(0,G.jsx)(Rl,{className:`w-4 h-4 text-purple-600 dark:text-purple-400`}),(0,G.jsx)(`h3`,{className:`text-sm font-medium text-bambu-gray`,children:o(`profiles.cloudView.columns.printer`)}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray-dark`,children:[`(`,ie.filter(e=>e.type===`printer`).length,`)`]})]}),(0,G.jsxs)(`div`,{className:`space-y-1 max-h-[calc(100vh-320px)] overflow-y-auto pr-1`,children:[ie.filter(e=>e.type===`printer`).map(e=>(0,G.jsx)(x5,{setting:e,onClick:()=>ae(e),onDuplicate:()=>se(e),compareMode:P,isCompareSelected:oe(e)!==void 0,compareIndex:oe(e),compareDisabled:P&&!!I[0]&&I[0].type!==e.type,t:o},e.setting_id)),ie.filter(e=>e.type===`printer`).length===0&&(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray-dark px-3 py-2`,children:o(`profiles.cloudView.noPrinterPresets`)})]})]})]}),S&&(0,G.jsx)(_Ke,{setting:S,onClose:()=>C(null),onDeleted:()=>C(null),onDuplicate:()=>se(S),onEdit:()=>H(S),hasPermission:a,t:o}),(w||O||A||M)&&(0,G.jsx)(yKe,{onClose:()=>{T(!1),k(null),j(null),N(null)},initialData:A||O||(M?{type:M.type,name:``,base_id:``,setting:M.setting}:void 0),allPresets:e,t:o}),E&&(0,G.jsx)(vKe,{onClose:()=>D(!1),onApply:e=>{N({type:e.type,setting:e.settings}),D(!1)},t:o}),R&&B&&I[0]&&I[1]&&(0,G.jsx)(T5,{onClose:()=>{z(!1),V(null)},leftPreset:B[0],rightPreset:B[1],leftLabel:I[0].name,rightLabel:I[1].name,t:o})]})}function xKe(){let{t:e}=U(),t=co(),{showToast:n}=qd(),{hasPermission:r}=Nd(),[i,a]=(0,y.useState)(`cloud`),[o,s]=(0,y.useState)(),{data:c,isLoading:l}=K({queryKey:[`cloudStatus`],queryFn:Z.getCloudStatus}),{data:u=[]}=K({queryKey:[`printers`],queryFn:Z.getPrinters}),{data:d,isLoading:f,refetch:p,dataUpdatedAt:m}=K({queryKey:[`cloudSettings`],queryFn:()=>Z.getCloudSettings(),enabled:!!c?.is_authenticated,retry:!1,staleTime:1e3*60*5});(0,y.useEffect)(()=>{m&&s(new Date(m))},[m]);let h=q({mutationFn:Z.cloudLogout,onSuccess:()=>{t.invalidateQueries({queryKey:[`cloudStatus`]}),t.removeQueries({queryKey:[`cloudSettings`]}),n(e(`profiles.toast.loggedOut`))}});return l?(0,G.jsx)(`div`,{className:`p-4 md:p-8 flex items-center justify-center min-h-[400px]`,children:(0,G.jsx)(Y,{className:`w-8 h-8 text-bambu-green animate-spin`})}):(0,G.jsxs)(`div`,{className:`p-4 md:p-8`,children:[(0,G.jsxs)(`div`,{className:`mb-6`,children:[(0,G.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,G.jsx)(Ps,{className:`w-7 h-7 text-bambu-green`}),e(`profiles.title`)]}),(0,G.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:e(`profiles.subtitle`)})]}),(0,G.jsxs)(`div`,{className:`flex border-b border-bambu-dark-tertiary mb-6`,children:[(0,G.jsxs)(`button`,{onClick:()=>a(`cloud`),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${i===`cloud`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-white border-transparent`}`,children:[(0,G.jsx)(Ps,{className:`w-4 h-4`}),e(`profiles.tabs.bambuCloud`)]}),(0,G.jsxs)(`button`,{onClick:()=>a(`orca_cloud`),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${i===`orca_cloud`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-white border-transparent`}`,children:[(0,G.jsx)(Ps,{className:`w-4 h-4`}),e(`profiles.tabs.orcaCloud`)]}),(0,G.jsxs)(`button`,{onClick:()=>a(`local`),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${i===`local`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-white border-transparent`}`,children:[(0,G.jsx)(Pc,{className:`w-4 h-4`}),e(`profiles.tabs.local`)]}),(0,G.jsxs)(`button`,{onClick:()=>a(`kprofiles`),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${i===`kprofiles`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-white border-transparent`}`,children:[(0,G.jsx)(Tc,{className:`w-4 h-4`}),e(`profiles.tabs.kprofiles`)]})]}),i===`cloud`&&(0,G.jsxs)(G.Fragment,{children:[c?.is_authenticated&&(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-3 mb-6 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`w-2 h-2 rounded-full bg-bambu-green animate-pulse`}),(0,G.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[e(`profiles.connectedAs`),` `,(0,G.jsx)(`span`,{className:`text-white`,children:c.email}),c.region&&(0,G.jsx)(`span`,{className:`ml-2 px-2 py-0.5 text-xs rounded bg-bambu-dark-tertiary text-bambu-gray`,children:c.region===`china`?e(`profiles.login.regionChina`):e(`profiles.login.regionGlobal`)})]})]}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:()=>h.mutate(),disabled:h.isPending||!r(`cloud:auth`),title:r(`cloud:auth`)?void 0:e(`profiles.noLogoutPermission`),children:[(0,G.jsx)(il,{className:`w-4 h-4`}),e(`profiles.logout`)]})]}),c?.sign_in_expired&&(0,G.jsxs)(`div`,{className:`flex items-start gap-3 p-3 mb-6 rounded-lg border border-yellow-500/40 bg-yellow-500/10`,children:[(0,G.jsx)(Lu,{className:`w-5 h-5 shrink-0 text-yellow-400 mt-0.5`}),(0,G.jsxs)(`div`,{className:`text-sm`,children:[(0,G.jsx)(`p`,{className:`text-white font-medium`,children:e(`profiles.signInExpiredTitle`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray`,children:e(`profiles.signInExpiredBody`)})]})]}),c?.is_authenticated?f?(0,G.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,G.jsx)(Y,{className:`w-8 h-8 text-bambu-green animate-spin`})}):d?(0,G.jsx)(bKe,{settings:d,lastSyncTime:o,onRefresh:()=>p(),isRefreshing:f,printers:u,hasPermission:r,t:e}):(0,G.jsxs)(`div`,{className:`text-center py-16`,children:[(0,G.jsx)(`p`,{className:`text-bambu-gray mb-4`,children:e(`profiles.failedToLoad`)}),(0,G.jsx)(Q,{onClick:()=>p(),children:e(`profiles.retry`)})]}):(0,G.jsx)(hKe,{onSuccess:()=>{t.invalidateQueries({queryKey:[`cloudStatus`]})},t:e})]}),i===`orca_cloud`&&(0,G.jsx)(pKe,{}),i===`local`&&(0,G.jsx)(cKe,{}),i===`kprofiles`&&(0,G.jsx)(iKe,{}),(0,G.jsx)(gKe,{})]})}function SKe(e,t){let n=(t||``).toUpperCase().replace(/[- ]/g,``),r=n.includes(`X1`),i=n.includes(`P1`),a=n.includes(`A1MINI`),o=n.includes(`A1`)&&!a,s=n.includes(`H2D`),c=n.includes(`H2C`),l=n.includes(`H2S`),u=s||c||l,d=n.includes(`P2S`),f=n.includes(`X2D`),p=d||f;switch(e){case`Lubricate Steel Rods`:return p?`https://wiki.bambulab.com/en/p2s/maintenance/lubricate-x-y-z-axis`:null;case`Clean Steel Rods`:return p?`https://wiki.bambulab.com/en/p2s/maintenance/lubricate-x-y-z-axis`:null;case`Lubricate Linear Rails`:return a?`https://wiki.bambulab.com/en/a1-mini/maintenance/lubricate-y-axis`:o?`https://wiki.bambulab.com/en/a1/maintenance/lubricate-y-axis`:u?`https://wiki.bambulab.com/en/h2/maintenance/x-axis-lubrication`:null;case`Clean Nozzle/Hotend`:return r||i?`https://wiki.bambulab.com/en/x1/troubleshooting/nozzle-clog`:a||o?`https://wiki.bambulab.com/en/a1-mini/troubleshooting/nozzle-clog`:u?`https://wiki.bambulab.com/en/h2/maintenance/nozzl-cold-pull-maintenance-and-cleaning`:p?`https://wiki.bambulab.com/en/p2s/maintenance/cold-pull-maintenance-hotend`:`https://wiki.bambulab.com/en/x1/troubleshooting/nozzle-clog`;case`Check Belt Tension`:return r?`https://wiki.bambulab.com/en/x1/maintenance/belt-tension`:i?`https://wiki.bambulab.com/en/p1/maintenance/p1p-maintenance`:a?`https://wiki.bambulab.com/en/a1-mini/maintenance/belt_tension`:o?`https://wiki.bambulab.com/en/a1/maintenance/belt_tension`:s?`https://wiki.bambulab.com/en/h2/maintenance/belt-tension`:c?`https://wiki.bambulab.com/en/h2c/maintenance/belt-tension`:l?`https://wiki.bambulab.com/en/h2s/maintenance/belt-tension`:p?`https://wiki.bambulab.com/en/p2s/maintenance/belt-tension`:`https://wiki.bambulab.com/en/x1/maintenance/belt-tension`;case`Clean Carbon Rods`:return r||i?`https://wiki.bambulab.com/en/general/carbon-rods-clearance`:null;case`Clean Linear Rails`:return a?`https://wiki.bambulab.com/en/a1-mini/maintenance/lubricate-y-axis`:o?`https://wiki.bambulab.com/en/a1/maintenance/lubricate-y-axis`:u?`https://wiki.bambulab.com/en/h2/maintenance/x-axis-lubrication`:null;case`Clean Build Plate`:return`https://wiki.bambulab.com/en/filament-acc/acc/pei-plate-clean-guide`;case`Check PTFE Tube`:return r||i?`https://wiki.bambulab.com/en/x1/maintenance/replace-ptfe-tube`:a||o?`https://wiki.bambulab.com/en/a1-mini/maintenance/ptfe-tube`:s?`https://wiki.bambulab.com/en/h2/maintenance/replace-ptfe-tube-on-h2d-printer`:l?`https://wiki.bambulab.com/en/h2s/maintenance/replace-ptfe-tube-on-h2s-printer`:c?`https://wiki.bambulab.com/en/h2/maintenance/replace-ptfe-tube-on-h2d-printer`:`https://wiki.bambulab.com/en/x1/maintenance/replace-ptfe-tube`;case`Replace HEPA Filter`:case`HEPA Filter`:case`Replace Carbon Filter`:case`Carbon Filter`:return u?`https://wiki.bambulab.com/en/h2/maintenance/replace-smoke-purifier-air-filte`:`https://wiki.bambulab.com/en/x1/maintenance/replace-carbon-filter`;case`Lubricate Left Nozzle Rail`:case`Left Nozzle Rail`:return u?`https://wiki.bambulab.com/en/h2/maintenance/x-axis-lubrication`:null;default:return null}}var E5={Droplet:Zs,Flame:hc,Ruler:Kl,Sparkles:_u,Square:bu,Cable:ts,Wrench:td,Calendar:as,Timer:Nu,Cog:Rs,Fan:oc,Zap:id,Wind:$u,Thermometer:Mu,Layers:Jc,Box:Zo,Target:Du,RefreshCw:Hl,Settings:ru,Filter:wc,CircleDot:Cs};function D5(e){return e&&E5[e]||td}function O5(e,t,n){if(t===`days`){if(e<1)return n?n(`common.today`):`Today`;if(e===1)return n?n(`maintenance.day`):`1 day`;if(e<7){let t=Math.round(e);return n?n(`maintenance.days`,{count:t}):`${t} days`}if(e<180){let t=Math.round(e/7);return t===1?n?n(`maintenance.week`):`1 week`:n?n(`maintenance.weeks`,{count:t}):`${t} weeks`}let t=Math.round(e/30);return t===1?n?n(`maintenance.month`):`1 month`:n?n(`maintenance.months`,{count:t}):`${t} months`}else{if(e<1)return`${Math.round(e*60)}m`;if(e<24)return`${e<10?e.toFixed(1):Math.round(e)}h`;let t=e/24;if(t<7)return`${t<2?t.toFixed(1):Math.round(t)}d`;let n=t/7;return n<12?`${n<2?n.toFixed(1):Math.round(n)}w`:`${Math.round(n/4)}mo`}}function k5(e,t,n){return t===`days`?e===1?n?n(`maintenance.day`):`1 day`:e===7?n?n(`maintenance.week`):`1 week`:e===14?n?n(`maintenance.weeks`,{count:2}):`2 weeks`:e===30?n?n(`maintenance.month`):`1 month`:e===60?n?n(`maintenance.months`,{count:2}):`2 months`:e===90?n?n(`maintenance.months`,{count:3}):`3 months`:e===180?n?n(`maintenance.months`,{count:6}):`6 months`:e===365?n?n(`maintenance.year`):`1 year`:n?n(`maintenance.days`,{count:e}):`${e} days`:`${e}h`}function CKe({item:e,onPerform:t,onToggle:n,hasPermission:r,t:i}){let a=D5(e.maintenance_type_icon),o=e.interval_type||`hours`,s=(()=>{if(o===`days`){let t=e.days_since_maintenance??0;return Math.max(0,Math.min(100,t/e.interval_hours*100))}return Math.max(0,Math.min(100,(e.interval_hours-e.hours_until_due)/e.interval_hours*100))})(),c=()=>e.enabled?e.is_due?`text-red-700 dark:text-red-400`:e.is_warning?`text-amber-700 dark:text-amber-400`:`text-bambu-green`:`text-bambu-gray`;return(0,G.jsx)(`div`,{className:`rounded-xl border p-4 transition-all ${e.enabled?e.is_due?`bg-red-500/5 border-red-500/20`:e.is_warning?`bg-amber-500/5 border-amber-500/20`:`bg-bambu-dark-secondary border-bambu-dark-tertiary`:`bg-bambu-dark-secondary/50`}`,children:(0,G.jsxs)(`div`,{className:`flex items-start gap-3 max-[550px]:flex-wrap`,children:[(0,G.jsxs)(`div`,{className:`relative p-2.5 rounded-lg shrink-0 ${e.is_due?`bg-red-500/20`:e.is_warning?`bg-amber-500/20`:e.enabled?`bg-bambu-dark`:`bg-bambu-dark/50`}`,children:[(0,G.jsx)(a,{className:`w-5 h-5 ${c()}`}),e.enabled&&(e.is_due||e.is_warning)&&(0,G.jsx)(`span`,{className:`absolute -top-1 -right-1 w-2.5 h-2.5 rounded-full ${e.is_due?`bg-red-500`:`bg-amber-500`} animate-pulse`})]}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`h3`,{className:`font-medium truncate ${e.enabled?`text-white`:`text-bambu-gray`}`,children:e.maintenance_type_name}),o===`days`&&(0,G.jsx)(`span`,{title:i(`maintenance.timeBasedInterval`),children:(0,G.jsx)(as,{className:`w-3.5 h-3.5 text-bambu-gray shrink-0`})}),(()=>{let t=e.maintenance_type_wiki_url||SKe(e.maintenance_type_name,e.printer_model);return t?(0,G.jsx)(`a`,{href:t,target:`_blank`,rel:`noopener noreferrer`,className:`text-bambu-gray hover:text-bambu-green transition-colors shrink-0`,title:i(`maintenance.viewDocumentation`),onClick:e=>e.stopPropagation(),children:(0,G.jsx)(rc,{className:`w-3.5 h-3.5`})}):null})()]}),(0,G.jsx)(`div`,{className:`mt-2 mb-1.5`,children:(0,G.jsx)(`div`,{className:`w-full h-1.5 bg-bambu-dark rounded-full overflow-hidden`,children:(0,G.jsx)(`div`,{className:`h-full rounded-full transition-all duration-500 ${e.enabled?e.is_due?`bg-red-500`:e.is_warning?`bg-amber-500`:`bg-bambu-green`:`bg-bambu-gray/30`}`,style:{width:`${s}%`}})})}),(0,G.jsxs)(`div`,{className:`text-xs flex items-center gap-1 ${c()}`,children:[e.is_due&&(0,G.jsx)(Lu,{className:`w-3 h-3`}),e.is_warning&&!e.is_due&&(0,G.jsx)(js,{className:`w-3 h-3`}),!e.is_due&&!e.is_warning&&e.enabled&&(0,G.jsx)(fs,{className:`w-3 h-3`}),(()=>{if(!e.enabled)return i(`common.disabled`);if(o===`days`){let t=e.days_until_due??0;return e.is_due?i(`maintenance.overdueBy`,{duration:O5(Math.abs(t),`days`,i)}):e.is_warning?i(`maintenance.dueIn`,{duration:O5(t,`days`,i)}):i(`maintenance.timeLeft`,{duration:O5(t,`days`,i)})}else return e.is_due?i(`maintenance.overdueBy`,{duration:O5(Math.abs(e.hours_until_due),`hours`,i)}):e.is_warning?i(`maintenance.dueIn`,{duration:O5(e.hours_until_due,`hours`,i)}):i(`maintenance.timeLeft`,{duration:O5(e.hours_until_due,`hours`,i)})})()]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0 max-[550px]:w-full max-[550px]:justify-end max-[550px]:mt-1`,children:[(0,G.jsx)(`span`,{title:r(`maintenance:update`)?void 0:i(`maintenance.noPermissionUpdate`),children:(0,G.jsx)(fH,{checked:e.enabled,onChange:t=>n(e.id,t),disabled:!r(`maintenance:update`)})}),(0,G.jsxs)(Q,{size:`sm`,variant:e.is_due?`primary`:`secondary`,onClick:()=>t(e.id),disabled:!e.enabled||!r(`maintenance:update`),title:r(`maintenance:update`)?void 0:i(`maintenance.noPermissionPerform`),className:`!px-3`,children:[(0,G.jsx)(Wl,{className:`w-3.5 h-3.5`}),i(`common.reset`)]})]})]})})}function wKe({overview:e,onPerform:t,onToggle:n,onSetHours:r,hasPermission:i,t:a}){let[o,s]=(0,y.useState)(!1),[c,l]=(0,y.useState)(!1),[u,d]=(0,y.useState)(e.total_print_hours.toFixed(1)),f=[...e.maintenance_items].sort((e,t)=>e.is_due&&!t.is_due?-1:!e.is_due&&t.is_due?1:e.is_warning&&!t.is_warning?-1:!e.is_warning&&t.is_warning?1:e.maintenance_type_id-t.maintenance_type_id),p=f.find(e=>e.enabled&&(e.is_due||e.is_warning)),m=()=>{let t=parseFloat(u);!isNaN(t)&&t>=0&&(r(e.printer_id,t),l(!1))};return(0,G.jsxs)(zd,{className:`overflow-hidden`,children:[(0,G.jsxs)(`div`,{className:`p-5`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,G.jsx)(`h2`,{className:`text-xl font-semibold text-white`,children:e.printer_name}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.due_count>0&&(0,G.jsxs)(`span`,{className:`px-2.5 py-1 bg-red-100 text-red-700 dark:bg-red-500/20 dark:text-red-400 text-xs font-medium rounded-full flex items-center gap-1.5`,children:[(0,G.jsx)(Lu,{className:`w-3 h-3`}),a(`maintenance.overdueCount`,{count:e.due_count})]}),e.warning_count>0&&(0,G.jsxs)(`span`,{className:`px-2.5 py-1 bg-amber-100 text-amber-700 dark:bg-amber-500/20 dark:text-amber-400 text-xs font-medium rounded-full flex items-center gap-1.5`,children:[(0,G.jsx)(js,{className:`w-3 h-3`}),a(`maintenance.dueSoonCount`,{count:e.warning_count})]}),e.due_count===0&&e.warning_count===0&&(0,G.jsxs)(`span`,{className:`px-2.5 py-1 bg-bambu-green/20 text-bambu-green text-xs font-medium rounded-full flex items-center gap-1.5`,children:[(0,G.jsx)(fs,{className:`w-3 h-3`}),a(`maintenance.allGood`)]})]})]}),(0,G.jsxs)(`button`,{onClick:()=>s(!o),className:`flex items-center gap-1.5 px-3 py-1.5 text-sm text-bambu-gray hover:text-white hover:bg-bambu-dark rounded-lg transition-colors`,children:[o?(0,G.jsx)(gs,{className:`w-4 h-4`}):(0,G.jsx)(ps,{className:`w-4 h-4`}),a(o?`common.collapse`:`common.expand`)]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-6 mt-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`p-2 bg-bambu-dark/50 rounded-lg`,children:(0,G.jsx)(Nu,{className:`w-4 h-4 text-bambu-gray`})}),c?(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`input`,{type:`number`,value:u,onChange:e=>d(e.target.value),onKeyDown:e=>{e.key===`Enter`&&m(),e.key===`Escape`&&l(!1)},className:`w-24 px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm`,min:`0`,step:`1`,autoFocus:!0}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:a(`common.hours`)}),(0,G.jsx)(Q,{size:`sm`,onClick:m,children:a(`common.save`)}),(0,G.jsx)(Q,{size:`sm`,variant:`secondary`,onClick:()=>l(!1),children:a(`common.cancel`)})]}):(0,G.jsxs)(`button`,{onClick:()=>{i(`maintenance:update`)&&(d(Math.round(e.total_print_hours).toString()),l(!0))},className:`group ${i(`maintenance:update`)?``:`cursor-not-allowed opacity-60`}`,title:i(`maintenance:update`)?void 0:a(`maintenance.noPermissionEditHours`),children:[(0,G.jsxs)(`div`,{className:`text-sm font-medium text-white ${i(`maintenance:update`)?`group-hover:text-bambu-green`:``} transition-colors flex items-center gap-1`,children:[Math.round(e.total_print_hours),` `,a(`common.hours`),(0,G.jsx)(Ol,{className:`w-3 h-3 text-bambu-gray ${i(`maintenance:update`)?`group-hover:text-bambu-green`:``}`})]}),(0,G.jsx)(`div`,{className:`text-xs text-bambu-gray`,children:a(`maintenance.totalPrintTime`)})]})]}),(0,G.jsx)(`div`,{className:`w-px h-10 bg-bambu-dark-tertiary`}),p&&(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`p-2 rounded-lg ${p.is_due?`bg-red-500/20`:`bg-amber-500/20`}`,children:(0,G.jsx)(D5(p.maintenance_type_icon),{className:`w-4 h-4 ${p.is_due?`text-red-600 dark:text-red-400`:`text-amber-600 dark:text-amber-400`}`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`div`,{className:`text-sm font-medium ${p.is_due?`text-red-700 dark:text-red-400`:`text-amber-700 dark:text-amber-400`}`,children:p.maintenance_type_name}),(0,G.jsx)(`div`,{className:`text-xs ${p.is_due?`text-red-700/80 dark:text-red-400/70`:`text-amber-700/80 dark:text-amber-400/70`}`,children:p.is_due?a(`common.overdue`):a(`maintenance.dueSoon`)})]})]})]})]}),o&&(0,G.jsx)(Vd,{className:`pt-0 border-t border-bambu-dark-tertiary`,children:(0,G.jsx)(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-3 pt-4`,children:f.map(e=>(0,G.jsx)(CKe,{item:e,onPerform:t,onToggle:n,hasPermission:i,t:a},e.id))})})]})}function TKe({overview:e,types:t,onUpdateInterval:n,onAddType:r,onUpdateType:i,onDeleteType:a,onRestoreDefaults:o,isRestoringDefaults:s,onAssignType:c,onRemoveItem:l,hasPermission:u,t:d}){let[f,p]=(0,y.useState)(null),[m,h]=(0,y.useState)(``),[g,_]=(0,y.useState)(`hours`),[v,b]=(0,y.useState)(!1),[x,S]=(0,y.useState)(``),[C,w]=(0,y.useState)(`100`),[T,E]=(0,y.useState)(`hours`),[D,O]=(0,y.useState)(`Wrench`),[k,A]=(0,y.useState)(``),[j,M]=(0,y.useState)(new Set),[N,P]=(0,y.useState)(null),[F,I]=(0,y.useState)(null),L=(0,y.useMemo)(()=>e?e.map(e=>({id:e.printer_id,name:e.printer_name})):[],[e]),R=t=>e?e.filter(e=>e.maintenance_items.some(e=>e.maintenance_type_id===t)).map(e=>({printerId:e.printer_id,printerName:e.printer_name,itemId:e.maintenance_items.find(e=>e.maintenance_type_id===t)?.id})):[],z=t=>{if(!e)return[];let n=new Set(R(t).map(e=>e.printerId));return L.filter(e=>!n.has(e.id))},[B,V]=(0,y.useState)(null),[ee,te]=(0,y.useState)(``),[ne,re]=(0,y.useState)(``),[ie,ae]=(0,y.useState)(`hours`),[oe,se]=(0,y.useState)(`Wrench`),[H,ce]=(0,y.useState)(``),le=e=>{V(e),te(e.name),re(e.default_interval_hours.toString()),ae(e.interval_type||`hours`),se(e.icon||`Wrench`),ce(e.wiki_url||``)},ue=()=>{B&&ee.trim()&&parseFloat(ne)>0&&(i(B.id,{name:ee.trim(),default_interval_hours:parseFloat(ne),interval_type:ie,icon:oe,wiki_url:H.trim()||null}),V(null))},de=(e,t,r)=>{let i=parseFloat(m);!isNaN(i)&&i>0&&n(e,{custom_interval_hours:Math.abs(i-t)<.01?null:i,custom_interval_type:g===r?null:g}),p(null)},fe=e=>{e.preventDefault(),x.trim()&&parseFloat(C)>0&&j.size>0&&(r({name:x.trim(),default_interval_hours:parseFloat(C),interval_type:T,icon:D,wiki_url:k.trim()||null},Array.from(j)),S(``),w(`100`),E(`hours`),A(``),M(new Set),b(!1))},pe=e=>{M(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},me=e?.map(e=>({printerId:e.printer_id,printerName:e.printer_name,items:e.maintenance_items.sort((e,t)=>e.maintenance_type_id-t.maintenance_type_id)})).sort((e,t)=>e.printerName.localeCompare(t.printerName))||[],he=t.filter(e=>e.is_system),ge=t.filter(e=>!e.is_system);return(0,G.jsxs)(`div`,{className:`space-y-8`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:d(`maintenance.maintenanceTypes`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:d(`maintenance.maintenanceTypesDescription`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:o,disabled:!u(`maintenance:delete`)||s,title:u(`maintenance:delete`)?void 0:d(`maintenance.noPermissionDeleteTypes`),children:d(`maintenance.restoreDefaults`)}),(0,G.jsxs)(Q,{onClick:()=>b(!v),disabled:!u(`maintenance:create`),title:u(`maintenance:create`)?void 0:d(`maintenance.noPermissionEditTypes`),children:[(0,G.jsx)(Fl,{className:`w-4 h-4`}),d(`maintenance.addCustomType`)]})]})]}),v&&(0,G.jsx)(zd,{className:`mb-6`,children:(0,G.jsx)(Vd,{className:`py-4`,children:(0,G.jsxs)(`form`,{onSubmit:fe,children:[(0,G.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4`,children:[(0,G.jsxs)(`div`,{className:`lg:col-span-2`,children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1.5`,children:d(`common.name`)}),(0,G.jsx)(`input`,{type:`text`,value:x,onChange:e=>S(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,placeholder:d(`maintenance.exampleName`),autoFocus:!0})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1.5`,children:d(`maintenance.intervalType`)}),(0,G.jsxs)(`select`,{value:T,onChange:e=>{E(e.target.value),e.target.value===`days`?w(`30`):w(`100`)},className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,children:[(0,G.jsx)(`option`,{value:`hours`,children:d(`maintenance.printHours`)}),(0,G.jsx)(`option`,{value:`days`,children:d(`maintenance.calendarDays`)})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1.5`,children:d(`maintenance.intervalValue`,{type:T===`days`?d(`maintenance.calendarDays`).toLowerCase():d(`common.hours`)})}),(0,G.jsx)(`input`,{type:`number`,value:C,onChange:e=>w(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,min:`1`})]})]}),(0,G.jsx)(`div`,{className:`mt-4 flex items-end justify-between`,children:(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1.5`,children:d(`maintenance.icon`)}),(0,G.jsx)(`div`,{className:`flex gap-1`,children:Object.keys(E5).map(e=>{let t=E5[e];return(0,G.jsx)(`button`,{type:`button`,onClick:()=>O(e),className:`p-2 rounded-lg transition-colors ${D===e?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary`}`,children:(0,G.jsx)(t,{className:`w-4 h-4`})},e)})})]})}),(0,G.jsxs)(`div`,{className:`mt-4`,children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1.5`,children:d(`maintenance.documentationLink`)}),(0,G.jsx)(`input`,{type:`url`,value:k,onChange:e=>A(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,placeholder:`https://wiki.bambulab.com/...`})]}),(0,G.jsxs)(`div`,{className:`mt-4`,children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1.5`,children:d(`maintenance.assignToPrinters`)}),(0,G.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:L.map(e=>(0,G.jsx)(`button`,{type:`button`,onClick:()=>pe(e.id),className:`px-3 py-1.5 rounded-lg text-sm transition-colors ${j.has(e.id)?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary`}`,children:e.name},e.id))}),j.size===0&&(0,G.jsx)(`p`,{className:`text-xs text-orange-700 dark:text-orange-400 mt-1`,children:d(`maintenance.selectAtLeastOnePrinter`)})]}),(0,G.jsxs)(`div`,{className:`mt-4 flex justify-end gap-2`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:()=>{b(!1),M(new Set)},children:d(`common.cancel`)}),(0,G.jsx)(Q,{type:`submit`,disabled:!x.trim()||j.size===0,children:d(`maintenance.addType`)})]})]})})}),(0,G.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3`,children:[he.map(e=>{let t=D5(e.icon),n=e.interval_type||`hours`;return(0,G.jsx)(`div`,{className:`bg-bambu-dark-secondary rounded-xl p-4 border border-bambu-dark-tertiary`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`p-2.5 bg-bambu-dark rounded-lg`,children:(0,G.jsx)(t,{className:`w-5 h-5 text-bambu-gray`})}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`div`,{className:`text-sm font-medium text-white truncate`,children:e.name}),(0,G.jsxs)(`div`,{className:`text-xs text-bambu-gray mt-0.5 flex items-center gap-1`,children:[n===`days`?(0,G.jsx)(as,{className:`w-3 h-3`}):(0,G.jsx)(Nu,{className:`w-3 h-3`}),k5(e.default_interval_hours,n,d)]})]}),(0,G.jsx)(`button`,{onClick:()=>{u(`maintenance:delete`)&&I(e)},disabled:!u(`maintenance:delete`),title:u(`maintenance:delete`)?void 0:d(`maintenance.noPermissionDeleteTypes`),className:`p-2 rounded-lg hover:bg-bambu-dark text-bambu-gray hover:text-red-600 dark:hover:text-red-400 transition-colors ${u(`maintenance:delete`)?``:`opacity-50 cursor-not-allowed`}`,children:(0,G.jsx)(Pu,{className:`w-4 h-4`})})]})},e.id)}),ge.map(e=>{let t=D5(e.icon),n=e.interval_type||`hours`;if(B?.id===e.id)return(0,G.jsx)(`div`,{className:`bg-bambu-dark-secondary rounded-xl p-4 border border-bambu-green`,children:(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsx)(`input`,{type:`text`,value:ee,onChange:e=>te(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,placeholder:d(`common.name`),autoFocus:!0}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsxs)(`select`,{value:ie,onChange:e=>ae(e.target.value),className:`flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,children:[(0,G.jsx)(`option`,{value:`hours`,children:d(`maintenance.printHours`)}),(0,G.jsx)(`option`,{value:`days`,children:d(`maintenance.calendarDays`)})]}),(0,G.jsx)(`input`,{type:`number`,value:ne,onChange:e=>re(e.target.value),className:`w-24 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,min:`1`})]}),(0,G.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:Object.keys(E5).map(e=>{let t=E5[e];return(0,G.jsx)(`button`,{type:`button`,onClick:()=>se(e),className:`p-1.5 rounded transition-colors ${oe===e?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white`}`,children:(0,G.jsx)(t,{className:`w-3.5 h-3.5`})},e)})}),(0,G.jsx)(`input`,{type:`url`,value:H,onChange:e=>ce(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,placeholder:d(`maintenance.documentationLink`)}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsx)(Q,{size:`sm`,onClick:ue,disabled:!ee.trim(),children:d(`common.save`)}),(0,G.jsx)(Q,{size:`sm`,variant:`secondary`,onClick:()=>V(null),children:d(`common.cancel`)})]})]})},e.id);let r=R(e.id),i=z(e.id),o=N===e.id;return(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl p-4 border border-bambu-green/30`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`p-2.5 bg-bambu-green/20 rounded-lg`,children:(0,G.jsx)(t,{className:`w-5 h-5 text-bambu-green`})}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-sm font-medium text-white truncate`,children:e.name}),(0,G.jsx)(`span`,{className:`px-1.5 py-0.5 bg-bambu-green/20 text-bambu-green text-[10px] font-medium rounded`,children:d(`maintenance.custom`)})]}),(0,G.jsxs)(`div`,{className:`text-xs text-bambu-gray mt-0.5 flex items-center gap-1`,children:[n===`days`?(0,G.jsx)(as,{className:`w-3 h-3`}):(0,G.jsx)(Nu,{className:`w-3 h-3`}),k5(e.default_interval_hours,n,d)]})]}),(0,G.jsxs)(`button`,{onClick:()=>P(o?null:e.id),className:`px-2 py-1 rounded-lg border transition-colors flex items-center gap-1 ${r.length>0?`border-bambu-green/50 bg-bambu-green/10 text-bambu-green hover:bg-bambu-green/20`:`border-orange-300 bg-orange-50 text-orange-700 hover:bg-orange-100 dark:border-orange-400/50 dark:bg-orange-400/10 dark:text-orange-400 dark:hover:bg-orange-400/20`}`,title:d(`maintenance.printersAssignedClick`,{count:r.length}),children:[(0,G.jsx)(Rl,{className:`w-3 h-3`}),(0,G.jsx)(`span`,{className:`text-xs font-medium`,children:r.length}),(0,G.jsx)(ps,{className:`w-3 h-3 transition-transform ${o?`rotate-180`:``}`})]}),(0,G.jsx)(`button`,{onClick:()=>le(e),disabled:!u(`maintenance:update`),title:u(`maintenance:update`)?void 0:d(`maintenance.noPermissionEditTypes`),className:`p-2 rounded-lg hover:bg-bambu-dark text-bambu-gray hover:text-white transition-colors ${u(`maintenance:update`)?``:`opacity-50 cursor-not-allowed`}`,children:(0,G.jsx)(Ol,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:()=>{confirm(d(`maintenance.deleteTypeConfirm`,{name:e.name}))&&a(e.id)},disabled:!u(`maintenance:delete`),title:u(`maintenance:delete`)?void 0:d(`maintenance.noPermissionDeleteTypes`),className:`p-2 rounded-lg hover:bg-bambu-dark text-bambu-gray hover:text-red-600 dark:hover:text-red-400 transition-colors ${u(`maintenance:delete`)?``:`opacity-50 cursor-not-allowed`}`,children:(0,G.jsx)(Pu,{className:`w-4 h-4`})})]}),o&&(0,G.jsxs)(`div`,{className:`mt-3 pt-3 border-t border-bambu-dark-tertiary`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:d(`maintenance.assignedToPrinters`)}),r.length===0?(0,G.jsx)(`p`,{className:`text-xs text-orange-700 dark:text-orange-400`,children:d(`maintenance.noPrintersAssigned`)}):(0,G.jsx)(`div`,{className:`flex flex-wrap gap-1 mb-2`,children:r.map(e=>(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-2 py-1 bg-bambu-dark rounded text-xs text-white`,children:[e.printerName,(0,G.jsx)(`button`,{onClick:()=>e.itemId&&l(e.itemId),disabled:!u(`maintenance:delete`),title:u(`maintenance:delete`)?d(`maintenance.removeFromPrinter`):d(`maintenance.noPermissionRemovePrinter`),className:`ml-1 ${u(`maintenance:delete`)?`hover:text-red-600 dark:hover:text-red-400`:`opacity-50 cursor-not-allowed`}`,children:`×`})]},e.printerId))}),i.length>0&&(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-1`,children:[(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray mr-1`,children:d(`maintenance.addPrinterShort`)}),i.map(t=>(0,G.jsxs)(`button`,{onClick:()=>c(t.id,e.id),disabled:!u(`maintenance:create`),title:u(`maintenance:create`)?void 0:d(`maintenance.noPermissionAssignPrinter`),className:`px-2 py-1 bg-bambu-dark rounded text-xs transition-colors ${u(`maintenance:create`)?`hover:bg-bambu-green/20 text-bambu-gray hover:text-bambu-green`:`opacity-50 cursor-not-allowed text-bambu-gray`}`,children:[`+ `,t.name]},t.id))]})]})]},e.id)})]})]}),me.length>0&&(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`mb-4`,children:[(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:d(`maintenance.intervalOverrides`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:d(`maintenance.intervalOverridesDescription`)})]}),(0,G.jsx)(`div`,{className:`space-y-4`,children:me.map(e=>(0,G.jsx)(zd,{children:(0,G.jsxs)(Vd,{className:`py-4`,children:[(0,G.jsx)(`h3`,{className:`text-sm font-medium text-white mb-3`,children:e.printerName}),(0,G.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-2`,children:e.items.map(e=>{let n=D5(e.maintenance_type_icon),r=t.find(t=>t.id===e.maintenance_type_id),i=r?.default_interval_hours||e.interval_hours,a=r?.interval_type||`hours`,o=e.interval_type||`hours`,s=f===e.id;return(0,G.jsxs)(`div`,{className:`flex items-center gap-2 p-2.5 bg-bambu-dark rounded-lg`,children:[(0,G.jsx)(n,{className:`w-4 h-4 text-bambu-gray shrink-0`}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray flex-1 truncate`,children:e.maintenance_type_name}),s?(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[g===`days`?(0,G.jsx)(as,{className:`w-3.5 h-3.5 text-bambu-gray shrink-0`}):(0,G.jsx)(Nu,{className:`w-3.5 h-3.5 text-bambu-gray shrink-0`}),(0,G.jsxs)(`select`,{value:g,onChange:e=>_(e.target.value),className:`px-1.5 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-xs`,children:[(0,G.jsx)(`option`,{value:`hours`,children:d(`maintenance.printHours`)}),(0,G.jsx)(`option`,{value:`days`,children:d(`maintenance.calendarDays`)})]}),(0,G.jsx)(`input`,{type:`number`,value:m,onChange:e=>h(e.target.value),onKeyDown:t=>{t.key===`Enter`&&de(e.id,i,a),t.key===`Escape`&&p(null)},className:`w-16 px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-xs`,min:`1`}),(0,G.jsx)(Q,{size:`sm`,onClick:()=>de(e.id,i,a),children:`OK`})]}):(0,G.jsxs)(`button`,{onClick:()=>{u(`maintenance:update`)&&(p(e.id),h(e.interval_hours.toString()),_(o))},disabled:!u(`maintenance:update`),title:u(`maintenance:update`)?void 0:d(`maintenance.noPermissionEditIntervals`),className:`px-2 py-1 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-xs font-medium text-white transition-colors flex items-center gap-1 ${u(`maintenance:update`)?`hover:bg-bambu-dark-secondary hover:border-bambu-green`:`opacity-50 cursor-not-allowed`}`,children:[o===`days`?(0,G.jsx)(as,{className:`w-3 h-3`}):(0,G.jsx)(Nu,{className:`w-3 h-3`}),k5(e.interval_hours,o,d),(0,G.jsx)(Ol,{className:`w-3 h-3 text-bambu-gray`})]})]},e.id)})})]})},e.printerId))})]}),me.length===0&&(0,G.jsx)(zd,{children:(0,G.jsxs)(Vd,{className:`text-center py-12`,children:[(0,G.jsx)(js,{className:`w-12 h-12 mx-auto mb-4 text-bambu-gray/30`}),(0,G.jsx)(`p`,{className:`text-bambu-gray`,children:d(`common.noPrinters`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray/70 mt-1`,children:d(`maintenance.intervalOverridesDescription`)})]})}),F&&(0,G.jsx)(of,{title:d(`maintenance.deleteSystemTypeTitle`),message:d(`maintenance.deleteSystemTypeMessage`,{name:F.name}),confirmText:d(`common.delete`),cancelText:d(`common.cancel`),variant:`danger`,cancelVariant:`primary`,cardClassName:`bg-red-950/70 border border-red-800/70`,onConfirm:()=>{a(F.id),I(null)},onCancel:()=>I(null)})]})}function EKe(){let{t:e}=U(),t=co(),{showToast:n}=qd(),{hasPermission:r}=Nd(),[i,a]=(0,y.useState)(`status`),{data:o,isLoading:s}=K({queryKey:[`maintenanceOverview`],queryFn:Z.getMaintenanceOverview}),{data:c}=K({queryKey:[`maintenanceTypes`],queryFn:Z.getMaintenanceTypes}),l=q({mutationFn:({id:e,notes:t})=>Z.performMaintenance(e,t),onSuccess:()=>{t.invalidateQueries({queryKey:[`maintenanceOverview`]}),t.invalidateQueries({queryKey:[`maintenanceSummary`]}),n(e(`maintenance.maintenanceComplete`))},onError:e=>{n(e.message,`error`)}}),u=q({mutationFn:({id:e,data:t})=>Z.updateMaintenanceItem(e,t),onSuccess:()=>{t.invalidateQueries({queryKey:[`maintenanceOverview`]})},onError:e=>{n(e.message,`error`)}}),d=q({mutationFn:({id:e,data:t})=>Z.updateMaintenanceType(e,t),onSuccess:()=>{t.invalidateQueries({queryKey:[`maintenanceTypes`]}),t.invalidateQueries({queryKey:[`maintenanceOverview`]}),n(e(`maintenance.typeUpdated`))},onError:e=>{n(e.message,`error`)}}),f=q({mutationFn:Z.deleteMaintenanceType,onSuccess:()=>{t.invalidateQueries({queryKey:[`maintenanceTypes`]}),t.invalidateQueries({queryKey:[`maintenanceOverview`]}),n(e(`maintenance.typeDeleted`))},onError:e=>{n(e.message,`error`)}}),p=q({mutationFn:Z.restoreDefaultMaintenanceTypes,onSuccess:r=>{t.invalidateQueries({queryKey:[`maintenanceTypes`]}),t.invalidateQueries({queryKey:[`maintenanceOverview`]}),n(e(`maintenance.defaultsRestored`,{count:r.restored}))},onError:e=>{n(e.message,`error`)}}),m=q({mutationFn:({printerId:e,hours:t})=>Z.setPrinterHours(e,t),onSuccess:()=>{t.invalidateQueries({queryKey:[`maintenanceOverview`]}),t.invalidateQueries({queryKey:[`maintenanceSummary`]}),n(e(`maintenance.printHoursUpdated`))},onError:e=>{n(e.message,`error`)}}),h=q({mutationFn:({printerId:e,typeId:t})=>Z.assignMaintenanceType(e,t),onSuccess:()=>{t.invalidateQueries({queryKey:[`maintenanceOverview`]}),n(e(`maintenance.printerAssigned`))},onError:e=>{n(e.message,`error`)}}),g=q({mutationFn:Z.removeMaintenanceItem,onSuccess:()=>{t.invalidateQueries({queryKey:[`maintenanceOverview`]}),n(e(`maintenance.printerRemoved`))},onError:e=>{n(e.message,`error`)}}),_=e=>{l.mutate({id:e})},v=(e,t)=>{u.mutate({id:e,data:{enabled:t}})},b=(e,t)=>{m.mutate({printerId:e,hours:t})};if(s)return(0,G.jsx)(`div`,{className:`p-4 md:p-8 flex justify-center`,children:(0,G.jsx)(Y,{className:`w-8 h-8 text-bambu-green animate-spin`})});let x=o?.reduce((e,t)=>e+t.due_count,0)||0,S=o?.reduce((e,t)=>e+t.warning_count,0)||0;return(0,G.jsxs)(`div`,{className:`p-4 md:p-8`,children:[(0,G.jsxs)(`div`,{className:`mb-6`,children:[(0,G.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,G.jsx)(td,{className:`w-7 h-7 text-bambu-green`}),e(`maintenance.title`)]}),(0,G.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:i===`status`?(0,G.jsxs)(G.Fragment,{children:[x>0&&(0,G.jsx)(`span`,{className:`text-red-700 dark:text-red-400`,children:e(`maintenance.dueCount`,{count:x})}),x>0&&S>0&&` · `,S>0&&(0,G.jsx)(`span`,{className:`text-amber-700 dark:text-amber-400`,children:e(`maintenance.warningCount`,{count:S})}),x===0&&S===0&&(0,G.jsx)(`span`,{className:`text-bambu-green`,children:e(`maintenance.allOk`)})]}):e(`maintenance.configureSettings`)})]}),(0,G.jsxs)(`div`,{className:`flex gap-1 mb-6 border-b border-bambu-dark-tertiary`,children:[(0,G.jsx)(`button`,{onClick:()=>a(`status`),className:`px-4 py-2 text-sm font-medium border-b-2 -mb-px transition-colors ${i===`status`?`text-bambu-green border-bambu-green`:`text-bambu-gray border-transparent hover:text-white`}`,children:e(`maintenance.statusTab`)}),(0,G.jsx)(`button`,{onClick:()=>a(`settings`),className:`px-4 py-2 text-sm font-medium border-b-2 -mb-px transition-colors ${i===`settings`?`text-bambu-green border-bambu-green`:`text-bambu-gray border-transparent hover:text-white`}`,children:e(`maintenance.settingsTab`)})]}),i===`status`?(0,G.jsx)(`div`,{className:`space-y-6`,children:o&&o.length>0?[...o].sort((e,t)=>{let n=e.due_count*10+e.warning_count,r=t.due_count*10+t.warning_count;return n===r?e.printer_name.localeCompare(t.printer_name):r-n}).map(t=>(0,G.jsx)(wKe,{overview:t,onPerform:_,onToggle:v,onSetHours:b,hasPermission:r,t:e},t.printer_id)):(0,G.jsx)(zd,{children:(0,G.jsxs)(Vd,{className:`text-center py-16`,children:[(0,G.jsx)(td,{className:`w-16 h-16 mx-auto mb-4 text-bambu-gray/30`}),(0,G.jsx)(`p`,{className:`text-lg font-medium text-white mb-2`,children:e(`common.noPrinters`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray`,children:e(`maintenance.configureSettings`)})]})})}):(0,G.jsx)(TKe,{overview:o,types:c||[],onUpdateInterval:(e,t)=>u.mutate({id:e,data:t}),onAddType:async(r,i)=>{let a=await Z.createMaintenanceType(r);for(let e of i)await Z.assignMaintenanceType(e,a.id);t.invalidateQueries({queryKey:[`maintenanceTypes`]}),t.invalidateQueries({queryKey:[`maintenanceOverview`]}),n(e(`maintenance.typeUpdated`))},onUpdateType:(e,t)=>d.mutate({id:e,data:t}),onDeleteType:e=>f.mutate(e),onRestoreDefaults:()=>p.mutate(),isRestoringDefaults:p.isPending,onAssignType:(e,t)=>h.mutate({printerId:e,typeId:t}),onRemoveItem:e=>g.mutate(e),hasPermission:r,t:e})]})}var A5=[`#ef4444`,`#f97316`,`#eab308`,`#22c55e`,`#06b6d4`,`#3b82f6`,`#8b5cf6`,`#ec4899`,`#6b7280`];function j5({project:e,onClose:t,onSave:n,isLoading:r,currencySymbol:i,t:a}){let[o,s]=(0,y.useState)(e?.name||``),[c,l]=(0,y.useState)(e?.description||``),[u,d]=(0,y.useState)(e?.color||A5[0]),[f,p]=(0,y.useState)(e?.target_count?.toString()||``),[m,h]=(0,y.useState)(e?.target_parts_count?.toString()||``),[g,_]=(0,y.useState)(e?.target_sets?.toString()||``),[v,b]=(0,y.useState)(e?.status||`active`),[x,S]=(0,y.useState)(e?.tags||``),[C,w]=(0,y.useState)(e?.due_date?.split(`T`)[0]||``),[T,E]=(0,y.useState)(e?.priority||`normal`),[D,O]=(0,y.useState)(e?.budget?.toString()||``),[k,A]=(0,y.useState)(e?.url||``),[j,M]=(0,y.useState)(null),[N,P]=(0,y.useState)(e?.parent_id??null),F=co(),{data:I}=K({queryKey:[`projects`,void 0],queryFn:()=>Z.getProjects()}),L=_je(I||[],e?.id),[R,z]=(0,y.useState)(e?.cover_image_filename||null),B=(0,y.useRef)(null),[V,ee]=(0,y.useState)(!1),[te,ne]=(0,y.useState)(0);return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg w-full max-w-md border border-bambu-dark-tertiary flex flex-col max-h-[calc(100vh-2rem)]`,children:[(0,G.jsx)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary flex-shrink-0`,children:(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:a(e?`projects.editProject`:`projects.newProject`)})}),(0,G.jsxs)(`form`,{onSubmit:t=>{t.preventDefault();let r=k.trim();if(r&&!/^https?:\/\//i.test(r)){M(a(`projects.urlInvalid`));return}M(null),n({name:o.trim(),description:c.trim()||void 0,color:u,target_count:f?parseInt(f,10):void 0,target_parts_count:m?parseInt(m,10):void 0,target_sets:e?g?parseInt(g,10):null:g?parseInt(g,10):void 0,tags:e?x.trim()||null:x.trim()||void 0,due_date:e?C||null:C||void 0,priority:T,budget:D.trim()?parseFloat(D):null,url:e?r||null:r||void 0,parent_id:e?N??0:N??void 0,...e&&{status:v}})},className:`flex flex-col flex-1 min-h-0`,children:[(0,G.jsxs)(`div`,{className:`p-4 space-y-4 overflow-y-auto flex-1`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`common.name`)}),(0,G.jsx)(`input`,{type:`text`,value:o,onChange:e=>s(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:a(`projects.namePlaceholder`),required:!0})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`common.description`)}),(0,G.jsx)(`textarea`,{value:c,onChange:e=>l(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green resize-none`,placeholder:a(`projects.descriptionPlaceholder`),rows:2})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`projects.urlLabel`)}),(0,G.jsx)(`input`,{type:`url`,value:k,onChange:e=>{A(e.target.value),j&&M(null)},className:`w-full bg-bambu-dark border rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none ${j?`border-red-500 focus:border-red-500`:`border-bambu-dark-tertiary focus:border-bambu-green`}`,placeholder:a(`projects.urlPlaceholder`),maxLength:2048}),j&&(0,G.jsx)(`p`,{className:`text-xs text-red-600 dark:text-red-400 mt-1`,children:j})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`projects.parentLabel`)}),(0,G.jsxs)(`select`,{value:N??``,onChange:e=>P(e.target.value?parseInt(e.target.value,10):null),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white focus:outline-none focus:border-bambu-green`,children:[(0,G.jsx)(`option`,{value:``,children:a(`projects.parentNone`)}),L.map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:a(`projects.parentHint`)})]}),e&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`projects.coverImageLabel`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`w-20 h-20 rounded bg-bambu-dark border border-bambu-dark-tertiary overflow-hidden flex items-center justify-center flex-shrink-0`,children:R?(0,G.jsx)(`img`,{src:Z.getProjectCoverImageUrl(e.id,te),alt:a(`projects.coverImageAlt`),className:`w-full h-full object-cover`}):(0,G.jsx)(Hc,{className:`w-6 h-6 text-bambu-gray`})}),(0,G.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,G.jsx)(`input`,{ref:B,type:`file`,accept:`image/jpeg,image/png,image/gif,image/webp`,onChange:async t=>{let n=t.target.files?.[0];if(!(!n||!e)){ee(!0);try{z((await Z.uploadProjectCoverImage(e.id,n)).filename),ne(e=>e+1),F.invalidateQueries({queryKey:[`projects`]})}catch{}finally{ee(!1),B.current&&(B.current.value=``)}}},className:`hidden`}),(0,G.jsxs)(Q,{type:`button`,variant:`secondary`,onClick:()=>B.current?.click(),disabled:V,children:[V?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Vu,{className:`w-4 h-4 mr-1`}),a(R?`projects.coverImageReplace`:`projects.coverImageUpload`)]}),R&&(0,G.jsxs)(Q,{type:`button`,variant:`secondary`,onClick:async()=>{if(e){ee(!0);try{await Z.deleteProjectCoverImage(e.id),z(null),ne(e=>e+1),F.invalidateQueries({queryKey:[`projects`]})}finally{ee(!1)}}},disabled:V,children:[(0,G.jsx)(nd,{className:`w-4 h-4 mr-1`}),a(`projects.coverImageRemove`)]})]})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`projects.color`)}),(0,G.jsx)(`div`,{className:`flex gap-2 flex-wrap`,children:A5.map(e=>(0,G.jsx)(`button`,{type:`button`,onClick:()=>d(e),className:`w-8 h-8 rounded-full transition-transform ${u===e?`ring-2 ring-white ring-offset-2 ring-offset-bambu-dark-secondary scale-110`:``}`,style:{backgroundColor:e}},e))})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`projects.targetPlates`)}),(0,G.jsx)(`input`,{type:`number`,value:f,onChange:e=>p(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:a(`projects.targetPlatesPlaceholder`),min:`1`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:a(`projects.targetPlatesHelp`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`projects.targetParts`)}),(0,G.jsx)(`input`,{type:`number`,value:m,onChange:e=>h(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:a(`projects.targetPartsPlaceholder`),min:`1`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:a(`projects.targetPartsHelp`)})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`projects.targetSets`)}),(0,G.jsx)(`input`,{type:`number`,value:g,onChange:e=>_(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:a(`projects.targetSetsPlaceholder`),min:`1`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:a(`projects.targetSetsHelp`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`projects.tagsLabel`)}),(0,G.jsx)(`input`,{type:`text`,value:x,onChange:e=>S(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:a(`projects.tagsPlaceholder`)})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`projects.dueDate`)}),(0,G.jsx)(`input`,{type:`date`,value:C,onChange:e=>w(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white focus:outline-none focus:border-bambu-green`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`projects.priority`)}),(0,G.jsxs)(`select`,{value:T,onChange:e=>E(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white focus:outline-none focus:border-bambu-green`,children:[(0,G.jsx)(`option`,{value:`low`,children:a(`projects.priorityLow`)}),(0,G.jsx)(`option`,{value:`normal`,children:a(`projects.priorityNormal`)}),(0,G.jsx)(`option`,{value:`high`,children:a(`projects.priorityHigh`)}),(0,G.jsx)(`option`,{value:`urgent`,children:a(`projects.priorityUrgent`)})]})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`projectDetail.cost.budget`)}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(`span`,{className:`absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray pointer-events-none`,children:i}),(0,G.jsx)(`input`,{type:`number`,step:`0.01`,min:`0`,value:D,onChange:e=>O(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded pl-8 pr-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:`0.00`})]})]}),e&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`common.status`)}),(0,G.jsxs)(`select`,{value:v,onChange:e=>b(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white focus:outline-none focus:border-bambu-green`,children:[(0,G.jsx)(`option`,{value:`active`,children:a(`projects.statusActive`)}),(0,G.jsx)(`option`,{value:`completed`,children:a(`projects.statusCompleted`)}),(0,G.jsx)(`option`,{value:`archived`,children:a(`projects.statusArchived`)})]})]})]}),(0,G.jsxs)(`div`,{className:`flex justify-end gap-2 p-4 border-t border-bambu-dark-tertiary flex-shrink-0`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:t,children:a(`common.cancel`)}),(0,G.jsx)(Q,{type:`submit`,disabled:!o.trim()||r,children:r?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):a(e?`common.save`:`projects.create`)})]})]})]})})}function DKe({projectId:e,altText:t}){let n=(0,y.useRef)(null),[r,i]=(0,y.useState)(!1),[a,o]=(0,y.useState)(null);return(0,G.jsxs)(`div`,{ref:n,className:`relative flex-shrink-0`,onMouseEnter:()=>{if(!n.current)return;let e=n.current.getBoundingClientRect(),t=window.innerWidth,r=window.innerHeight,a=e.right+8;a+384>t-8&&(a=e.left-384-8);let s=e.top;s+384>r-8&&(s=r-384-8),s<8&&(s=8),o({left:a,top:s}),i(!0)},onMouseLeave:()=>i(!1),onClick:e=>e.stopPropagation(),children:[(0,G.jsx)(`div`,{className:`w-10 h-10 rounded-lg overflow-hidden bg-bambu-dark border border-bambu-dark-tertiary`,children:(0,G.jsx)(`img`,{src:Z.getProjectCoverImageUrl(e),alt:t,className:`w-full h-full object-cover`,loading:`lazy`})}),r&&a&&(0,At.createPortal)((0,G.jsx)(`div`,{className:`fixed z-[100] w-96 h-96 rounded-lg overflow-hidden border border-bambu-dark-tertiary shadow-2xl bg-bambu-dark pointer-events-none`,style:{left:a.left,top:a.top},"aria-hidden":`true`,children:(0,G.jsx)(`img`,{src:Z.getProjectCoverImageUrl(e),alt:``,className:`w-full h-full object-contain`,loading:`lazy`})}),document.body)]})}function OKe({project:e,parentName:t,onClick:n,onEdit:r,onDelete:i,hasPermission:a,t:o}){let s=e.target_count?Math.round(e.archive_count/e.target_count*100):0,c=e.target_parts_count?Math.round(e.completed_count/e.target_parts_count*100):0,l=e.status===`completed`,u=e.status===`archived`,[d,f]=(0,y.useState)(!1),p=l?{icon:Ss,color:`text-bambu-green`,bg:`bg-bambu-green/10`}:u?{icon:Po,color:`text-bambu-gray`,bg:`bg-bambu-gray/10`}:e.queue_count>0?{icon:js,color:`text-blue-600 dark:text-blue-400`,bg:`bg-blue-50 dark:bg-blue-400/10`}:{icon:_c,color:`text-bambu-gray`,bg:`bg-bambu-gray/10`};return(0,G.jsxs)(`div`,{className:`group relative bg-gradient-to-br from-bambu-card to-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary hover:border-bambu-green/50 hover:shadow-lg hover:shadow-bambu-green/5 transition-all duration-300 cursor-pointer overflow-hidden`,onClick:n,children:[(0,G.jsx)(`div`,{className:`absolute top-0 left-0 w-1.5 h-full`,style:{backgroundColor:e.color||`#6b7280`,boxShadow:`0 0 12px ${e.color||`#6b7280`}40`}}),(0,G.jsxs)(`div`,{className:`p-5 pl-6`,children:[(0,G.jsxs)(`div`,{className:`flex items-start justify-between mb-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 flex-1`,children:[e.cover_image_filename?(0,G.jsx)(DKe,{projectId:e.id,altText:o(`projects.coverImageAlt`)}):(0,G.jsx)(`div`,{className:`p-2 rounded-lg ${p.bg} flex-shrink-0`,children:(0,G.jsx)(p.icon,{className:`w-5 h-5 ${p.color}`})}),(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,G.jsx)(`h3`,{className:`font-semibold text-white truncate`,children:e.name}),e.url&&(0,G.jsx)(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,onClick:e=>e.stopPropagation(),title:e.url,"aria-label":o(`projects.openExternalUrl`),className:`inline-flex items-center justify-center w-6 h-6 rounded bg-bambu-dark border border-bambu-dark-tertiary text-bambu-green hover:bg-bambu-green/10 hover:border-bambu-green transition-colors flex-shrink-0`,children:(0,G.jsx)(rc,{className:`w-3.5 h-3.5`})}),e.target_parts_count?(0,G.jsxs)(`span`,{className:`text-xs px-2 py-0.5 rounded-full whitespace-nowrap font-medium ${c>=100?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark text-bambu-gray`}`,children:[e.completed_count,`/`,e.target_parts_count,` `,o(`projects.parts`)]}):e.target_count?(0,G.jsxs)(`span`,{className:`text-xs px-2 py-0.5 rounded-full whitespace-nowrap font-medium ${s>=100?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark text-bambu-gray`}`,children:[e.archive_count,`/`,e.target_count,` `,o(`projects.plates`)]}):e.completed_count>0?(0,G.jsxs)(`span`,{className:`text-xs px-2 py-0.5 rounded-full whitespace-nowrap font-medium bg-bambu-dark text-bambu-gray`,children:[e.completed_count,` `,o(`projects.parts`)]}):null,l&&(0,G.jsx)(`span`,{className:`text-xs bg-bambu-green/20 text-bambu-green px-2 py-0.5 rounded-full whitespace-nowrap`,children:o(`projects.done`)}),u&&(0,G.jsx)(`span`,{className:`text-xs bg-bambu-gray/20 text-bambu-gray px-2 py-0.5 rounded-full whitespace-nowrap`,children:o(`projects.statusArchived`)}),e.child_count>0&&(0,G.jsxs)(`span`,{className:`text-xs bg-bambu-dark text-bambu-gray px-2 py-0.5 rounded-full whitespace-nowrap inline-flex items-center gap-1`,title:o(`projects.subProjectCount`,{count:e.child_count}),children:[(0,G.jsx)(xc,{className:`w-3 h-3`}),e.child_count]})]}),t&&(0,G.jsxs)(`p`,{className:`text-xs text-bambu-gray mt-1 flex items-center gap-1`,children:[(0,G.jsx)(Jc,{className:`w-3 h-3 flex-shrink-0`}),(0,G.jsx)(`span`,{className:`truncate`,children:o(`projects.partOf`,{name:t})})]}),e.description&&(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray/70 mt-1 line-clamp-1`,children:e.description}),e.archives&&e.archives.length>0&&(()=>{let t=e.archives.map(e=>e.filament_type).filter(Boolean).flatMap(e=>e.split(`,`).map(e=>e.trim())).filter(Boolean),n=[...new Set(t)],r=e.archives.map(e=>e.filament_color).filter(Boolean).flatMap(e=>e.split(`,`).map(e=>e.trim())).filter(e=>e.startsWith(`#`)||/^[0-9A-Fa-f]{6}$/.test(e)),i=[...new Set(r)];return n.length===0&&i.length===0?null:(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mt-1.5`,children:[n.slice(0,3).map(e=>(0,G.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 bg-bambu-dark text-bambu-gray rounded`,children:e},e)),i.length>0&&(0,G.jsxs)(`div`,{className:`flex items-center gap-0.5`,children:[i.slice(0,5).map(e=>(0,G.jsx)(`div`,{className:`w-3 h-3 rounded-full border border-black/20`,style:{backgroundColor:e.startsWith(`#`)?e:`#${e}`},title:e},e)),i.length>5&&(0,G.jsxs)(`span`,{className:`text-[10px] text-bambu-gray ml-0.5`,children:[`+`,i.length-5]})]})]})})()]})]}),(0,G.jsxs)(`div`,{className:`relative`,onClick:e=>e.stopPropagation(),children:[(0,G.jsx)(`button`,{className:`p-1.5 rounded-lg hover:bg-bambu-dark text-bambu-gray hover:text-white transition-colors can-hover:opacity-0 group-hover:opacity-100 focus-visible:opacity-100`,onClick:()=>f(!d),children:(0,G.jsx)($s,{className:`w-4 h-4`})}),d&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`fixed inset-0 z-10`,onClick:()=>f(!1)}),(0,G.jsxs)(`div`,{className:`absolute right-0 top-8 z-20 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl py-1 min-w-[120px]`,children:[(0,G.jsxs)(`button`,{className:`w-full px-3 py-2 text-left text-sm flex items-center gap-2 ${a(`projects:update`)?`text-white hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{a(`projects:update`)&&(r(),f(!1))},disabled:!a(`projects:update`),title:a(`projects:update`)?void 0:o(`projects.noEditPermission`),children:[(0,G.jsx)(Ol,{className:`w-4 h-4`}),o(`common.edit`)]}),(0,G.jsxs)(`button`,{className:`w-full px-3 py-2 text-left text-sm flex items-center gap-2 ${a(`projects:delete`)?`text-red-600 dark:text-red-400 hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{a(`projects:delete`)&&(i(),f(!1))},disabled:!a(`projects:delete`),title:a(`projects:delete`)?void 0:o(`projects.noDeletePermission`),children:[(0,G.jsx)(Pu,{className:`w-4 h-4`}),o(`common.delete`)]})]})]})]})]}),(0,G.jsx)(`div`,{className:`mb-4`,children:e.target_count||e.target_parts_count?(0,G.jsxs)(`div`,{className:`space-y-3`,children:[e.target_count&&(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between text-xs mb-1`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:o(`projects.plates`)}),(0,G.jsxs)(`span`,{className:s>=100?`text-bambu-green font-medium`:`text-white`,children:[e.archive_count,` / `,e.target_count]})]}),(0,G.jsx)(`div`,{className:`h-2 bg-bambu-dark/80 rounded-full overflow-hidden backdrop-blur-sm`,children:(0,G.jsx)(`div`,{className:`h-full transition-all duration-500 ease-out rounded-full relative`,style:{width:`${Math.min(s,100)}%`,background:s>=100?`linear-gradient(90deg, #22c55e, #4ade80)`:`linear-gradient(90deg, ${e.color||`#6b7280`}, ${e.color||`#6b7280`}cc)`,boxShadow:`0 0 8px ${s>=100?`#22c55e`:e.color||`#6b7280`}60`}})})]}),e.target_parts_count&&(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between text-xs mb-1`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:o(`projects.parts`)}),(0,G.jsxs)(`span`,{className:c>=100?`text-bambu-green font-medium`:`text-white`,children:[e.completed_count,` / `,e.target_parts_count]})]}),(0,G.jsx)(`div`,{className:`h-2 bg-bambu-dark/80 rounded-full overflow-hidden backdrop-blur-sm`,children:(0,G.jsx)(`div`,{className:`h-full transition-all duration-500 ease-out rounded-full relative`,style:{width:`${Math.min(c,100)}%`,background:c>=100?`linear-gradient(90deg, #22c55e, #4ade80)`:`linear-gradient(90deg, ${e.color||`#6b7280`}, ${e.color||`#6b7280`}cc)`,boxShadow:`0 0 8px ${c>=100?`#22c55e`:e.color||`#6b7280`}60`}})})]}),e.failed_count>0&&(0,G.jsxs)(`div`,{className:`text-xs text-red-600 dark:text-red-400`,children:[e.failed_count,` `,o(`projects.failed`)]})]}):e.completed_count>0||e.failed_count>0?(0,G.jsxs)(`div`,{className:`flex items-center gap-4 text-xs`,children:[e.completed_count>0&&(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 text-bambu-gray`,children:[(0,G.jsx)(Po,{className:`w-3.5 h-3.5`}),(0,G.jsxs)(`span`,{children:[e.completed_count,` `,o(`projects.completed`)]})]}),e.failed_count>0&&(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 text-red-600 dark:text-red-400`,children:[(0,G.jsx)(Lu,{className:`w-3.5 h-3.5`}),(0,G.jsxs)(`span`,{children:[e.failed_count,` `,o(`projects.failed`)]})]}),e.queue_count>0&&(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 text-blue-600 dark:text-blue-400`,children:[(0,G.jsx)(js,{className:`w-3.5 h-3.5`}),(0,G.jsxs)(`span`,{children:[e.queue_count,` `,o(`projects.inQueue`)]})]})]}):(0,G.jsx)(`div`,{className:`text-xs text-bambu-gray/60 italic`,children:o(`projects.noPrintsYet`)})}),e.archives&&e.archives.length>0&&(0,G.jsxs)(`div`,{className:`mb-4`,children:[(0,G.jsx)(`div`,{className:`grid grid-cols-4 gap-1.5`,children:e.archives.slice(0,4).map(e=>(0,G.jsxs)(`div`,{className:`relative aspect-square rounded-lg bg-bambu-dark overflow-hidden border border-bambu-dark-tertiary`,title:e.print_name||`Unknown`,children:[e.thumbnail_path?(0,G.jsx)(`img`,{src:Z.getArchiveThumbnail(e.id),alt:e.print_name||``,className:`w-full h-full object-cover`}):(0,G.jsx)(`div`,{className:`w-full h-full flex items-center justify-center text-bambu-gray/50`,children:(0,G.jsx)(Cl,{className:`w-6 h-6`})}),e.status===`failed`&&(0,G.jsx)(`div`,{className:`absolute inset-0 bg-red-500/40 flex items-center justify-center`,children:(0,G.jsx)(Lu,{className:`w-4 h-4 text-white`})})]},e.id))}),e.archive_count>4&&(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1.5 text-center`,children:o(`common.more`,{count:e.archive_count-4})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between pt-3 border-t border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-4 text-xs text-bambu-gray`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5`,title:o(`projects.printJobs`),children:[(0,G.jsx)(Jc,{className:`w-3.5 h-3.5 text-blue-600 dark:text-blue-400`}),(0,G.jsxs)(`span`,{children:[e.archive_count,` `,o(`projects.plates`)]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5`,title:o(`projects.partsPrinted`),children:[(0,G.jsx)(Cl,{className:`w-3.5 h-3.5 text-bambu-green`}),(0,G.jsxs)(`span`,{children:[e.completed_count,` `,o(`projects.parts`)]})]}),e.failed_count>0&&(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 text-red-600 dark:text-red-400`,title:o(`projects.failedParts`),children:[(0,G.jsx)(Lu,{className:`w-3.5 h-3.5`}),(0,G.jsx)(`span`,{children:e.failed_count})]}),e.queue_count>0&&(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 text-yellow-600 dark:text-yellow-400`,title:o(`projects.inQueue`),children:[(0,G.jsx)($c,{className:`w-3.5 h-3.5`}),(0,G.jsx)(`span`,{children:e.queue_count})]})]}),(0,G.jsx)(ms,{className:`w-4 h-4 text-bambu-gray/50 group-hover:text-bambu-gray transition-colors`})]})]})]})}function kKe(){let{t:e}=U(),t=or(),n=co(),{showToast:r}=qd(),{hasPermission:i}=Nd(),[a,o]=(0,y.useState)(!1),[s,c]=(0,y.useState)(),[l,u]=(0,y.useState)(`active`),[d,f]=(0,y.useState)(null),[p,m]=(0,y.useState)(()=>localStorage.getItem(`projects-collapse-subprojects`)===`true`),[h,g]=(0,y.useState)({}),_=()=>{let e=!p;m(e),g({}),localStorage.setItem(`projects-collapse-subprojects`,String(e))},{data:v}=K({queryKey:[`settings`],queryFn:Z.getSettings}),b=Lf(v?.currency||`USD`),{data:x,isLoading:S}=K({queryKey:[`projects`,l===`all`?void 0:l],queryFn:()=>Z.getProjects(l===`all`?void 0:l)}),{data:C}=K({queryKey:[`projects`,void 0],queryFn:()=>Z.getProjects()}),w=new Map((C||[]).map(e=>[e.id,e.name])),T=x||[],E=new Set(T.map(e=>e.id)),D=new Map;for(let e of T)if(e.parent_id!==null&&E.has(e.parent_id)){let t=D.get(e.parent_id)||[];t.push(e),D.set(e.parent_id,t)}let O=new Set,k=e=>{if(!O.has(e)){O.add(e);for(let t of D.get(e)||[])k(t.id)}},A=[];for(let e of T)e.parent_id!==null&&E.has(e.parent_id)||(A.push(e),k(e.id));for(let e of T)O.has(e.id)||(A.push(e),k(e.id));let j=(t,n,r)=>{let a=(0,G.jsx)(OKe,{project:t,parentName:n===0&&t.parent_id!==null?w.get(t.parent_id):void 0,onClick:()=>ee(t),onEdit:()=>V(t),onDelete:()=>te(t.id),hasPermission:i,t:e}),o=new Set(r).add(t.id),s=(D.get(t.id)||[]).filter(e=>!o.has(e.id));if(s.length===0)return(0,G.jsx)(`div`,{children:a},t.id);let c=h[t.id]??!p;return(0,G.jsxs)(`div`,{className:c?`col-span-full space-y-4`:`space-y-4`,children:[a,(0,G.jsxs)(`div`,{className:`ml-4 md:ml-8 pl-4 md:pl-6 border-l-2 rounded-l space-y-4`,style:{borderColor:t.color||`#6b7280`},children:[(0,G.jsxs)(`button`,{type:`button`,onClick:()=>g(e=>({...e,[t.id]:!c})),"aria-expanded":c,title:e(c?`projects.collapseSubProjects`:`projects.expandSubProjects`),className:`text-xs uppercase tracking-wide text-bambu-gray hover:text-white transition-colors flex items-center gap-1.5 max-w-full min-w-0`,children:[c?(0,G.jsx)(ps,{className:`w-3.5 h-3.5 flex-shrink-0`}):(0,G.jsx)(ms,{className:`w-3.5 h-3.5 flex-shrink-0`}),(0,G.jsx)(xc,{className:`w-3.5 h-3.5 flex-shrink-0`}),(0,G.jsx)(`span`,{className:`truncate`,children:e(`projects.subProjectsOf`,{name:t.name})}),(0,G.jsx)(`span`,{className:`px-1.5 py-0.5 rounded-full bg-bambu-dark normal-case tracking-normal flex-shrink-0`,children:s.length})]}),c&&(0,G.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-8`,children:s.map(e=>j(e,n+1,o))})]})]},t.id)},M=q({mutationFn:e=>Z.createProject(e),onSuccess:()=>{n.invalidateQueries({queryKey:[`projects`]}),o(!1),r(e(`projects.toast.created`),`success`)},onError:e=>{r(e.message,`error`)}}),N=q({mutationFn:({id:e,data:t})=>Z.updateProject(e,t),onSuccess:()=>{n.invalidateQueries({queryKey:[`projects`]}),o(!1),c(void 0),r(e(`projects.toast.updated`),`success`)},onError:e=>{r(e.message,`error`)}}),P=q({mutationFn:e=>Z.deleteProject(e),onSuccess:()=>{f(null),r(e(`projects.toast.deleted`),`success`),setTimeout(()=>window.location.reload(),100)},onError:e=>{f(null),r(e.message,`error`)}}),F=q({mutationFn:e=>Z.importProject(e),onSuccess:()=>{n.invalidateQueries({queryKey:[`projects`]}),r(e(`projects.toast.imported`),`success`)},onError:e=>{r(e.message,`error`)}}),I=(0,y.useRef)(null),L=async()=>{try{let t=await Z.getProjects(),n=await Promise.all(t.map(async e=>await Z.exportProjectJson(e.id))),i=new Blob([JSON.stringify(n,null,2)],{type:`application/json`}),a=URL.createObjectURL(i),o=document.createElement(`a`);o.href=a,o.download=`bambuddy_projects_${new Date().toISOString().split(`T`)[0]}.json`,o.click(),URL.revokeObjectURL(a),r(e(`projects.toast.exported`),`success`)}catch(e){r(e.message,`error`)}},R=()=>{I.current?.click()},z=async t=>{let i=t.target.files?.[0];if(i){try{if(i.name.toLowerCase().endsWith(`.zip`))await Z.importProjectFile(i),n.invalidateQueries({queryKey:[`projects`]}),r(e(`projects.toast.imported`),`success`);else{let t=await i.text(),n=JSON.parse(t),a=Array.isArray(n)?n:[n];for(let e of a)await F.mutateAsync(e);a.length>1&&r(e(`projects.toast.multipleImported`,{count:a.length}),`success`)}}catch(t){r(`${e(`projects.toast.importFailed`)}: ${t.message}`,`error`)}t.target.value=``}},B=e=>{s?N.mutate({id:s.id,data:e}):M.mutate(e)},V=e=>{c(e),o(!0)},ee=e=>{t(`/projects/${e.id}`)},te=e=>{f(e)},ne=()=>{d!==null&&P.mutate(d)},re=C?.reduce((e,t)=>(e[t.status]=(e[t.status]||0)+1,e.all=(e.all||0)+1,e),{})||{};return(0,G.jsxs)(`div`,{className:`p-4 md:p-8 space-y-8`,children:[(0,G.jsx)(`input`,{ref:I,type:`file`,accept:`.json,.zip`,onChange:z,className:`hidden`}),(0,G.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between gap-4`,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)(_c,{className:`w-7 h-7 text-bambu-green`}),e(`projects.title`)]}),(0,G.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:e(`projects.subtitle`)})]}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsxs)(Q,{variant:`secondary`,onClick:R,disabled:!i(`projects:create`),title:i(`projects:create`)?e(`projects.importProject`):e(`projects.noImportPermission`),children:[(0,G.jsx)(Vu,{className:`w-4 h-4 mr-2`}),e(`projects.import`)]}),(0,G.jsxs)(Q,{variant:`secondary`,onClick:L,disabled:!i(`projects:read`),title:i(`projects:read`)?e(`projects.exportAll`):e(`projects.noExportPermission`),children:[(0,G.jsx)(Xs,{className:`w-4 h-4 mr-2`}),e(`projects.export`)]}),(0,G.jsxs)(Q,{onClick:()=>o(!0),className:`sm:w-auto w-full`,disabled:!i(`projects:create`),title:i(`projects:create`)?void 0:e(`projects.noCreatePermission`),children:[(0,G.jsx)(Fl,{className:`w-4 h-4 mr-2`}),e(`projects.newProject`)]})]})]}),(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`flex gap-1 p-1 bg-bambu-dark rounded-xl w-fit`,children:[{key:`active`,label:e(`projects.statusActive`),icon:js},{key:`completed`,label:e(`projects.statusCompleted`),icon:Ss},{key:`archived`,label:e(`projects.statusArchived`),icon:Po},{key:`all`,label:e(`common.all`),icon:_c}].map(({key:e,label:t,icon:n})=>(0,G.jsxs)(`button`,{onClick:()=>u(e),className:`flex items-center gap-2 px-4 py-2 text-sm rounded-lg transition-all ${l===e?`bg-bambu-card text-white shadow-sm`:`text-bambu-gray hover:text-white`}`,children:[(0,G.jsx)(n,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{children:t}),re[e]>0&&(0,G.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded-full ${l===e?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark-tertiary`}`,children:re[e]})]},e))}),D.size>0&&(0,G.jsxs)(`button`,{type:`button`,onClick:_,"aria-pressed":p,title:e(p?`projects.expandSubProjects`:`projects.collapseSubProjects`),className:`flex items-center gap-2 px-3 py-1.5 text-sm rounded-lg transition-colors ${p?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:text-white hover:bg-bambu-dark`}`,children:[(0,G.jsx)(xc,{className:`w-4 h-4`}),e(`common.collapse`)]})]}),S?(0,G.jsx)(`div`,{className:`flex items-center justify-center py-20`,children:(0,G.jsxs)(`div`,{className:`flex flex-col items-center gap-3`,children:[(0,G.jsx)(Y,{className:`w-8 h-8 animate-spin text-bambu-green`}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`projects.loading`)})]})}):x?.length===0?(0,G.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-20 px-4`,children:[(0,G.jsx)(`div`,{className:`p-4 bg-bambu-dark rounded-2xl mb-4`,children:(0,G.jsx)(_c,{className:`w-12 h-12 text-bambu-gray/50`})}),(0,G.jsx)(`h3`,{className:`text-lg font-medium text-white mb-2`,children:l===`all`?e(`projects.noProjects`):e(`projects.noProjectsFiltered`,{status:l})}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-center max-w-md mb-6`,children:l===`all`?e(`projects.createFirst`):e(`projects.noProjectsFilteredHelp`,{status:l})}),l===`all`&&(0,G.jsxs)(Q,{onClick:()=>o(!0),disabled:!i(`projects:create`),title:i(`projects:create`)?void 0:e(`projects.noCreatePermission`),children:[(0,G.jsx)(Fl,{className:`w-4 h-4 mr-2`}),e(`projects.createFirstButton`)]})]}):(0,G.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-8`,children:A.map(e=>j(e,0,new Set))}),d!==null&&(0,G.jsx)(of,{title:e(`projects.deleteProject`),message:e(`projects.deleteConfirm`),confirmText:e(`projects.deleteProject`),variant:`danger`,onConfirm:ne,onCancel:()=>f(null)}),a&&(0,G.jsx)(j5,{project:s,onClose:()=>{o(!1),c(void 0)},onSave:B,isLoading:M.isPending||N.isPending,currencySymbol:b,t:e})]})}function M5(e){let t=(e.file_type||``).toLowerCase();if(t===`gcode`||t===`gcode.3mf`)return!0;let n=(e.filename||``).toLowerCase();return n.endsWith(`.gcode`)||n.endsWith(`.gcode.3mf`)}function N5(e,t,n){return M5(e)?!1:t?fje(e.filename):dje(e.filename,n)}function P5(e){return e>=1e3?`${(e/1e3).toFixed(2)}kg`:`${Math.round(e)}g`}function AKe({status:e,t}){let n={active:`bg-bambu-green/20 text-bambu-green`,completed:`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`,archived:`bg-bambu-gray/20 text-bambu-gray`},r=n[e]||n.active,i={active:t(`projectDetail.status.active`),completed:t(`projectDetail.status.completed`),archived:t(`projectDetail.status.archived`)};return(0,G.jsx)(`span`,{className:`px-2 py-1 rounded text-sm font-medium ${r}`,children:i[e]||e.charAt(0).toUpperCase()+e.slice(1)})}function F5({icon:e,label:t,value:n,subValue:r,hint:i,color:a=`text-bambu-gray`}){return(0,G.jsx)(zd,{children:(0,G.jsx)(Vd,{className:`p-4`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,title:i,children:[(0,G.jsx)(`div`,{className:`p-2 rounded-lg bg-bambu-dark ${a}`,children:(0,G.jsx)(e,{className:`w-5 h-5`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:t}),(0,G.jsx)(`p`,{className:`text-xl font-semibold text-white`,children:n}),r&&(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray/70`,children:r})]})]})})})}function jKe({archives:e,t}){return e.length===0?(0,G.jsxs)(`div`,{className:`text-center py-8 text-bambu-gray`,children:[(0,G.jsx)(Cl,{className:`w-12 h-12 mx-auto mb-2 opacity-50`}),(0,G.jsx)(`p`,{children:t(`projectDetail.noPrints`)})]}):(0,G.jsx)(`div`,{className:`grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 xl:grid-cols-6 gap-3`,children:e.map(e=>(0,G.jsxs)(Ai,{to:`/archives?search=${encodeURIComponent(e.print_name||``)}`,className:`group relative aspect-square rounded-lg bg-bambu-dark border border-bambu-dark-tertiary overflow-hidden hover:border-bambu-green transition-colors`,children:[e.thumbnail_path?(0,G.jsx)(`img`,{src:Z.getArchiveThumbnail(e.id),alt:e.print_name||`Print`,className:`w-full h-full object-cover`}):(0,G.jsx)(`div`,{className:`w-full h-full flex items-center justify-center text-bambu-gray`,children:(0,G.jsx)(Cl,{className:`w-8 h-8`})}),e.status===`failed`&&(0,G.jsx)(`div`,{className:`absolute inset-0 bg-red-500/30 flex items-center justify-center`,children:(0,G.jsx)(Ds,{className:`w-8 h-8 text-white`})}),e.status===`completed`&&(0,G.jsx)(`div`,{className:`absolute top-1 right-1`,children:(0,G.jsx)(xs,{className:`w-4 h-4 text-bambu-green`})}),(0,G.jsx)(`div`,{className:`absolute inset-x-0 bottom-0 bg-gradient-to-t from-black/80 to-transparent p-2 opacity-0 group-hover:opacity-100 transition-opacity`,children:(0,G.jsx)(`p`,{className:`text-xs text-white truncate`,children:e.print_name||`Unknown`})})]},e.id))})}function MKe({priority:e,t}){let n={low:{color:`bg-gray-500/20 text-gray-400`,label:t(`projectDetail.priority.low`)},normal:{color:`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`,label:t(`projectDetail.priority.normal`)},high:{color:`bg-orange-100 dark:bg-orange-500/20 text-orange-700 dark:text-orange-400`,label:t(`projectDetail.priority.high`)},urgent:{color:`bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400`,label:t(`projectDetail.priority.urgent`)}},{color:r,label:i}=n[e]||n.normal;return(0,G.jsxs)(`span`,{className:`px-2 py-1 rounded text-xs font-medium flex items-center gap-1 ${r}`,children:[e===`urgent`&&(0,G.jsx)(Lu,{className:`w-3 h-3`}),i]})}function I5(e,t){if(!e)return null;let n=rp(e);if(!n)return null;let r=new Date,i=Math.ceil((n.getTime()-r.getTime())/(1e3*60*60*24));return i<0?{color:`text-red-700 dark:text-red-400`,label:t(`projectDetail.dueDate.overdue`)}:i===0?{color:`text-orange-700 dark:text-orange-400`,label:t(`projectDetail.dueDate.today`)}:i<=3?{color:`text-yellow-700 dark:text-yellow-400`,label:t(`projectDetail.dueDate.daysLeft`,{count:i})}:{color:`text-bambu-gray`,label:t(`projectDetail.dueDate.daysLeft`,{count:i})}}function NKe(){let{id:e}=dr(),t=or(),{t:n}=U(),r=co(),{showToast:i}=qd(),{hasPermission:a}=Nd(),[o,s]=(0,y.useState)(!1),[c,l]=(0,y.useState)(!1),[u,d]=(0,y.useState)(``),[f,p]=(0,y.useState)(null),m=parseInt(e||`0`,10),{data:h,isLoading:g,error:_}=K({queryKey:[`project`,m],queryFn:()=>Z.getProject(m),enabled:m>0}),{data:v,isLoading:b}=K({queryKey:[`project-archives`,m],queryFn:()=>Z.getProjectArchives(m),enabled:m>0}),{data:x,isLoading:S}=K({queryKey:[`project-bom`,m],queryFn:()=>Z.getProjectBOM(m),enabled:m>0}),{data:C,isLoading:w}=K({queryKey:[`project-timeline`,m],queryFn:()=>Z.getProjectTimeline(m,20),enabled:m>0}),{data:T}=K({queryKey:[`settings`],queryFn:Z.getSettings}),{data:E}=K({queryKey:[`project-folders`,m],queryFn:()=>Z.getLibraryFoldersByProject(m),enabled:m>0}),{data:D,isLoading:O}=K({queryKey:[`project-files`,m],queryFn:()=>Z.getLibraryFiles(null,!1,m),enabled:m>0}),k=(0,y.useMemo)(()=>{let e=new Map;for(let t of D??[])if(t.folder_id!=null){let n=e.get(t.folder_id)??[];n.push(t),e.set(t.folder_id,n)}return e},[D]),{data:A}=K({queryKey:[`project-file-progress`,m],queryFn:()=>Z.getProjectFileProgress(m),enabled:m>0}),j=(0,y.useMemo)(()=>{let e=new Map;for(let t of A??[])e.set(t.file_id,t.completed_count);return e},[A]),M=(0,y.useMemo)(()=>{let e=h?.target_sets;if(!e||!D)return null;let t=D.filter(e=>M5(e));return t.length===0?null:Math.min(...t.map(t=>Math.min(j.get(t.id)??0,e)))},[h?.target_sets,D,j]),N=Lf(T?.currency||`USD`),P=T?.time_format||`system`,F=q({mutationFn:e=>Z.updateProject(m,e),onSuccess:()=>{r.invalidateQueries({queryKey:[`project`,m]}),r.invalidateQueries({queryKey:[`projects`]}),s(!1),l(!1),i(n(`projectDetail.toast.projectUpdated`),`success`)},onError:e=>{i(e.message,`error`)}}),I=()=>{d(h?.notes||``),l(!0)},L=()=>{F.mutate({notes:u})},R=()=>{l(!1),d(``)},[z,B]=(0,y.useState)(``),[V,ee]=(0,y.useState)(1),[te,ne]=(0,y.useState)(``),[re,ie]=(0,y.useState)(``),[ae,oe]=(0,y.useState)(``),[se,H]=(0,y.useState)(!1),[ce,le]=(0,y.useState)(!1),[ue,de]=(0,y.useState)(null),[fe,pe]=(0,y.useState)(``),[me,he]=(0,y.useState)(1),[ge,_e]=(0,y.useState)(``),[ve,ye]=(0,y.useState)(``),[be,xe]=(0,y.useState)(``),[Se,Ce]=(0,y.useState)({isOpen:!1,title:``,message:``,onConfirm:()=>{}}),we=q({mutationFn:e=>Z.createBOMItem(m,e),onSuccess:()=>{r.invalidateQueries({queryKey:[`project-bom`,m]}),r.invalidateQueries({queryKey:[`project`,m]}),B(``),ee(1),ne(``),ie(``),oe(``),H(!1),i(n(`projectDetail.toast.partAdded`),`success`)},onError:e=>i(e.message,`error`)}),Te=q({mutationFn:({itemId:e,data:t})=>Z.updateBOMItem(m,e,t),onSuccess:()=>{r.invalidateQueries({queryKey:[`project-bom`,m]}),r.invalidateQueries({queryKey:[`project`,m]}),de(null)},onError:e=>i(e.message,`error`)}),Ee=q({mutationFn:e=>Z.deleteBOMItem(m,e),onSuccess:()=>{r.invalidateQueries({queryKey:[`project-bom`,m]}),r.invalidateQueries({queryKey:[`project`,m]}),i(n(`projectDetail.toast.partRemoved`),`success`)},onError:e=>i(e.message,`error`)}),De=e=>{e.preventDefault(),z.trim()&&we.mutate({name:z.trim(),quantity_needed:V,unit_price:te?parseFloat(te):void 0,sourcing_url:re.trim()||void 0,remarks:ae.trim()||void 0})},Oe=e=>{let t=e.is_complete?0:e.quantity_needed;Te.mutate({itemId:e.id,data:{quantity_acquired:t}})},ke=(e,t)=>{Ce({isOpen:!0,title:n(`projectDetail.bom.deletePart`),message:n(`projectDetail.bom.deleteConfirm`,{name:t}),onConfirm:()=>{Ce(e=>({...e,isOpen:!1})),Ee.mutate(e)}})},Ae=e=>{de(e),pe(e.name),he(e.quantity_needed),_e(e.unit_price?.toString()||``),ye(e.sourcing_url||``),xe(e.remarks||``)},je=e=>{e.preventDefault(),!(!ue||!fe.trim())&&Te.mutate({itemId:ue.id,data:{name:fe.trim(),quantity_needed:me,unit_price:ge?parseFloat(ge):void 0,sourcing_url:ve.trim()||void 0,remarks:be.trim()||void 0}})},Me=()=>{de(null)},Ne=async()=>{try{let{blob:e,filename:t}=await Z.exportProjectZip(Number(m)),r=URL.createObjectURL(e),a=document.createElement(`a`);a.href=r,a.download=t||`${h?.name||`project`}_${new Date().toISOString().split(`T`)[0]}.zip`,a.click(),URL.revokeObjectURL(r),i(n(`projectDetail.toast.projectExported`),`success`)}catch(e){i(e.message,`error`)}},Pe=q({mutationFn:()=>Z.createTemplateFromProject(m),onSuccess:()=>{r.invalidateQueries({queryKey:[`projects`]}),i(n(`projectDetail.toast.templateCreated`),`success`)},onError:e=>i(e.message,`error`)}),Fe=e=>op(e,P,{month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`});if(g)return(0,G.jsx)(`div`,{className:`flex items-center justify-center py-24`,children:(0,G.jsx)(Y,{className:`w-8 h-8 animate-spin text-bambu-green`})});if(_||!h)return(0,G.jsxs)(`div`,{className:`text-center py-24`,children:[(0,G.jsx)(`p`,{className:`text-bambu-gray`,children:_?`${n(`common.error`)}: ${_.message}`:n(`projectDetail.notFound`)}),(0,G.jsx)(Q,{variant:`secondary`,className:`mt-4`,onClick:()=>t(`/projects`),children:n(`projectDetail.backToProjects`)})]});let Ie=h.stats,Le=Ie?.progress_percent??0,Re=Ie?.parts_progress_percent??0;return(0,G.jsxs)(`div`,{className:`p-4 md:p-8 space-y-8`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-bambu-gray`,children:[(0,G.jsx)(Ai,{to:`/projects`,className:`hover:text-white transition-colors`,children:n(`nav.projects`)}),(0,G.jsx)(ms,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`text-white`,children:h.name})]}),(0,G.jsxs)(`div`,{className:`flex items-start justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,G.jsx)(`button`,{onClick:()=>t(`/projects`),className:`p-2 rounded-lg bg-bambu-card hover:bg-bambu-dark-tertiary transition-colors`,children:(0,G.jsx)(Lo,{className:`w-5 h-5 text-bambu-gray`})}),(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`w-4 h-4 rounded-full shrink-0`,style:{backgroundColor:h.color||`#6b7280`}}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h1`,{className:`text-2xl font-bold text-white`,children:h.name}),h.description&&(0,G.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:h.description})]})]}),(0,G.jsx)(AKe,{status:h.status,t:n})]}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsxs)(Q,{variant:`secondary`,onClick:Ne,disabled:!a(`projects:read`),title:a(`projects:read`)?n(`projectDetail.exportProject`):n(`projectDetail.noExportPermission`),children:[(0,G.jsx)(Xs,{className:`w-4 h-4 mr-2`}),n(`projectDetail.export`)]}),(0,G.jsxs)(Q,{onClick:()=>s(!0),disabled:!a(`projects:update`),title:a(`projects:update`)?void 0:n(`projectDetail.noEditPermission`),children:[(0,G.jsx)(Ol,{className:`w-4 h-4 mr-2`}),n(`common.edit`)]})]})]}),(h.target_count||h.target_parts_count||h.target_sets)&&(0,G.jsx)(zd,{children:(0,G.jsxs)(Vd,{className:`p-4 space-y-4`,children:[h.target_count&&(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:n(`projectDetail.progress.platesProgress`)}),(0,G.jsxs)(`span`,{className:`text-sm font-medium text-white`,children:[Ie?.total_archives||0,` / `,h.target_count,` `,n(`projectDetail.progress.printJobs`)]})]}),(0,G.jsx)(`div`,{className:`h-3 bg-bambu-dark rounded-full overflow-hidden`,children:(0,G.jsx)(`div`,{className:`h-full transition-all duration-500`,style:{width:`${Math.min(Le,100)}%`,backgroundColor:Le>=100?`#22c55e`:h.color||`#6b7280`}})}),(0,G.jsxs)(`div`,{className:`flex justify-between mt-1`,children:[(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray/70`,children:n(`projectDetail.progress.percentComplete`,{percent:Le.toFixed(0)})}),Ie?.remaining_prints!=null&&Ie.remaining_prints>0&&(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray/70`,children:n(`projectDetail.progress.remaining`,{count:Ie.remaining_prints})})]})]}),h.target_parts_count&&(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:n(`projectDetail.progress.partsProgress`)}),(0,G.jsxs)(`span`,{className:`text-sm font-medium text-white`,children:[Ie?.completed_prints||0,` / `,h.target_parts_count,` `,n(`projectDetail.progress.parts`)]})]}),(0,G.jsx)(`div`,{className:`h-3 bg-bambu-dark rounded-full overflow-hidden`,children:(0,G.jsx)(`div`,{className:`h-full transition-all duration-500`,style:{width:`${Math.min(Re,100)}%`,backgroundColor:Re>=100?`#22c55e`:h.color||`#6b7280`}})}),(0,G.jsxs)(`div`,{className:`flex justify-between mt-1`,children:[(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray/70`,children:n(`projectDetail.progress.percentComplete`,{percent:Re.toFixed(0)})}),Ie?.remaining_parts!=null&&Ie.remaining_parts>0&&(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray/70`,children:n(`projectDetail.progress.remaining`,{count:Ie.remaining_parts})})]})]}),h.target_sets?(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:n(`projectDetail.progress.setsProgress`)}),(0,G.jsxs)(`span`,{className:`text-sm font-medium text-white`,children:[M??0,` / `,h.target_sets,` `,n(`projectDetail.progress.sets`)]})]}),(0,G.jsx)(`div`,{className:`h-3 bg-bambu-dark rounded-full overflow-hidden`,children:(0,G.jsx)(`div`,{className:`h-full transition-all duration-500`,style:{width:`${Math.min((M??0)/h.target_sets*100,100)}%`,backgroundColor:(M??0)>=h.target_sets?`#22c55e`:h.color||`#6b7280`}})}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray/70 mt-1`,children:n(`projectDetail.progress.setsHint`)})]}):null]})}),Ie&&(0,G.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-4`,children:[(0,G.jsx)(zd,{children:(0,G.jsx)(Vd,{className:`p-4`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`p-2 rounded-lg bg-bambu-dark text-bambu-green`,children:(0,G.jsx)(Cl,{className:`w-5 h-5`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`projectDetail.stats.printJobs`)}),(0,G.jsxs)(`p`,{className:`text-xl font-semibold text-white`,children:[Ie.total_archives,` `,(0,G.jsx)(`span`,{className:`text-sm font-normal text-bambu-gray`,children:n(`projectDetail.stats.total`)})]}),Ie.failed_prints>0&&(0,G.jsx)(`p`,{className:`text-sm text-status-error`,children:n(`projectDetail.stats.failed`,{count:Ie.failed_prints})}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`projectDetail.stats.partsPrinted`,{count:Ie.completed_prints})})]})]})})}),(0,G.jsx)(F5,{icon:js,label:n(`projectDetail.stats.printTime`),value:fp(Ie.total_print_time_hours),color:`text-yellow-600 dark:text-yellow-400`}),(0,G.jsx)(F5,{icon:Rl,label:n(`projectDetail.stats.filamentUsed`),value:P5(Ie.total_filament_grams),color:`text-purple-600 dark:text-purple-400`})]}),h.rollup_stats&&(0,G.jsx)(zd,{children:(0,G.jsxs)(Vd,{className:`p-4`,children:[(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2 mb-3`,children:[(0,G.jsx)(xc,{className:`w-5 h-5`}),n(`projectDetail.rollup.title`,{count:h.descendant_count})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.stats.printJobs`)}),(0,G.jsx)(`p`,{className:`text-lg font-semibold text-white`,children:h.rollup_stats.total_archives}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`projectDetail.stats.partsPrinted`,{count:h.rollup_stats.completed_prints})})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.stats.printTime`)}),(0,G.jsx)(`p`,{className:`text-lg font-semibold text-white`,children:fp(h.rollup_stats.total_print_time_hours)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.stats.filamentUsed`)}),(0,G.jsx)(`p`,{className:`text-lg font-semibold text-white`,children:P5(h.rollup_stats.total_filament_grams)})]}),(()=>{let e=h.rollup_stats.estimated_cost+h.rollup_stats.total_energy_cost+h.rollup_stats.bom_cost;return e<=0?null:(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.cost.totalCost`)}),(0,G.jsxs)(`p`,{className:`text-lg font-semibold text-bambu-green`,children:[N,e.toFixed(2)]})]})})()]}),h.rollup_stats.progress_percent!==null&&(0,G.jsxs)(`div`,{className:`mt-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:n(`projectDetail.rollup.progress`)}),(0,G.jsx)(`span`,{className:`text-sm font-medium text-white`,children:n(`projectDetail.rollup.percentComplete`,{percent:h.rollup_stats.progress_percent.toFixed(0)})})]}),(0,G.jsx)(`div`,{className:`h-3 bg-bambu-dark rounded-full overflow-hidden`,children:(0,G.jsx)(`div`,{className:`h-full transition-all duration-500`,style:{width:`${Math.min(h.rollup_stats.progress_percent,100)}%`,backgroundColor:h.rollup_stats.progress_percent>=100?`#22c55e`:h.color||`#6b7280`}})})]})]})}),Ie&&(()=>{let e=Ie.estimated_cost+Ie.total_energy_cost+Ie.bom_cost;return Ie.estimated_cost>0||e>0||h.budget!==null})()&&(0,G.jsx)(zd,{children:(0,G.jsxs)(Vd,{className:`p-4`,children:[(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white mb-3`,children:n(`projectDetail.cost.title`)}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.cost.filamentCost`)}),(0,G.jsxs)(`p`,{className:`text-lg font-semibold text-white`,children:[N,Ie.estimated_cost.toFixed(2)]})]}),Ie.total_energy_kwh>0&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.cost.energy`)}),(0,G.jsxs)(`p`,{className:`text-lg font-semibold text-white`,children:[Ie.total_energy_kwh.toFixed(3),` kWh`,Ie.total_energy_cost>0&&(0,G.jsxs)(`span`,{className:`text-sm text-bambu-gray ml-1`,children:[`(`,N,Ie.total_energy_cost.toFixed(2),`)`]})]})]}),(()=>{let e=Ie.estimated_cost+Ie.total_energy_cost+Ie.bom_cost;return e<=0?null:(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.cost.totalCost`)}),(0,G.jsxs)(`p`,{className:`text-lg font-semibold text-bambu-green`,children:[N,e.toFixed(2)]}),Ie.bom_cost>0&&(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray/70`,children:n(`projectDetail.cost.includesBom`)})]})})(),h.budget!==null&&(()=>{let e=Ie.estimated_cost+Ie.total_energy_cost+Ie.bom_cost,t=h.budget-e;return(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.cost.budget`)}),(0,G.jsxs)(`p`,{className:`text-sm text-bambu-gray`,children:[n(`projectDetail.cost.total`),`: `,(0,G.jsxs)(`span`,{className:`text-white font-semibold`,children:[N,h.budget.toFixed(2)]})]}),(0,G.jsxs)(`p`,{className:`text-sm ${t>=0?`text-bambu-green`:`text-red-700 dark:text-red-400`}`,children:[n(`projectDetail.cost.remaining`),`: `,(0,G.jsxs)(`span`,{className:`font-semibold`,children:[N,t.toFixed(2)]})]})]})})()]})]})}),h.children&&h.children.length>0&&(0,G.jsx)(zd,{children:(0,G.jsxs)(Vd,{className:`p-4`,children:[(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2 mb-3`,children:[(0,G.jsx)(xc,{className:`w-5 h-5`}),n(`projectDetail.subProjects.title`,{count:h.children.length})]}),(0,G.jsx)(`div`,{className:`space-y-2`,children:h.children.map(e=>(0,G.jsxs)(Ai,{to:`/projects/${e.id}`,className:`flex items-center justify-between gap-4 p-3 bg-bambu-dark rounded-lg hover:bg-bambu-dark-tertiary transition-colors`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0`,children:[(0,G.jsx)(`div`,{className:`w-3 h-3 rounded-full flex-shrink-0`,style:{backgroundColor:e.color||`#6b7280`}}),(0,G.jsx)(`span`,{className:`text-white truncate`,children:e.name}),(0,G.jsx)(`span`,{className:`text-xs px-2 py-0.5 rounded flex-shrink-0 ${e.status===`completed`?`bg-status-ok/20 text-status-ok`:e.status===`archived`?`bg-bambu-gray/20 text-bambu-gray`:`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`}`,children:e.status}),e.descendant_count>0&&(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray flex-shrink-0 inline-flex items-center gap-1`,children:[(0,G.jsx)(xc,{className:`w-3 h-3`}),e.descendant_count]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-4 text-sm text-bambu-gray flex-shrink-0`,children:[e.total_archives>0&&(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:n(`projectDetail.subProjects.jobs`,{count:e.total_archives})}),e.total_filament_grams>0&&(0,G.jsx)(`span`,{className:`hidden md:inline`,children:P5(e.total_filament_grams)}),e.total_cost>0&&(0,G.jsxs)(`span`,{className:`hidden md:inline`,children:[N,e.total_cost.toFixed(2)]}),e.progress_percent!==null&&(0,G.jsxs)(`span`,{children:[e.progress_percent.toFixed(0),`%`]})]})]},e.id))})]})}),h.parent_id&&h.parent_name&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,G.jsx)(Jc,{className:`w-4 h-4 text-bambu-gray`}),(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:n(`projectDetail.partOf`)}),(0,G.jsx)(Ai,{to:`/projects/${h.parent_id}`,className:`text-bambu-green hover:underline`,children:h.parent_name})]}),(h.tags||h.due_date||h.priority!==`normal`)&&(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4`,children:[h.priority&&h.priority!==`normal`&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.priorityLabel`)}),(0,G.jsx)(MKe,{priority:h.priority,t:n})]}),h.due_date&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(as,{className:`w-4 h-4 text-bambu-gray`}),(0,G.jsx)(`span`,{className:`text-sm text-white`,children:ap(h.due_date,{year:`numeric`,month:`short`,day:`numeric`})}),I5(h.due_date,n)&&(0,G.jsxs)(`span`,{className:`text-xs ${I5(h.due_date,n).color}`,children:[`(`,I5(h.due_date,n).label,`)`]})]}),h.tags&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Eu,{className:`w-4 h-4 text-bambu-gray`}),(0,G.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:h.tags.split(`,`).map((e,t)=>(0,G.jsx)(`span`,{className:`px-2 py-0.5 bg-bambu-dark-tertiary text-bambu-gray text-xs rounded`,children:e.trim()},t))})]})]}),(0,G.jsx)(zd,{children:(0,G.jsxs)(Vd,{className:`p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(fc,{className:`w-5 h-5`}),n(`projectDetail.notes.title`)]}),c?(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:R,disabled:F.isPending,children:[(0,G.jsx)(nd,{className:`w-4 h-4 mr-1`}),n(`common.cancel`)]}),(0,G.jsxs)(Q,{size:`sm`,onClick:L,disabled:F.isPending,children:[F.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin mr-1`}):(0,G.jsx)(ql,{className:`w-4 h-4 mr-1`}),n(`common.save`)]})]}):(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:I,disabled:!a(`projects:update`),title:a(`projects:update`)?void 0:n(`projectDetail.notes.noEditPermission`),children:[(0,G.jsx)(Ol,{className:`w-4 h-4 mr-1`}),n(`common.edit`)]})]}),c?(0,G.jsx)(B2,{content:u,onChange:d,placeholder:n(`projectDetail.notes.placeholder`)}):h.notes?(0,G.jsx)(`div`,{className:`prose prose-invert prose-sm max-w-none`,dangerouslySetInnerHTML:{__html:JG.sanitize(h.notes)}}):(0,G.jsx)(`p`,{className:`text-bambu-gray/70 text-sm italic`,children:n(`projectDetail.notes.empty`)})]})}),(0,G.jsx)(zd,{children:(0,G.jsxs)(Vd,{className:`p-4`,children:[(0,G.jsx)(`div`,{className:`flex items-center justify-between mb-3`,children:(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(vc,{className:`w-5 h-5`}),n(`projectDetail.files.title`)]})}),(0,G.jsxs)(`p`,{className:`text-xs text-bambu-gray mb-3`,children:[(0,G.jsx)(Ai,{to:`/files`,className:`text-bambu-green hover:underline`,children:n(`projectDetail.files.linkFolders`)}),` `,n(`projectDetail.files.forQuickAccess`)]}),E&&E.length>0?(0,G.jsx)(`div`,{className:`space-y-4`,children:E.map(e=>{let t=k.get(e.id)??[],r=O;return(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(Ai,{to:`/files?folder=${e.id}`,className:`flex items-center justify-between p-3 bg-bambu-dark rounded-lg hover:bg-bambu-dark-tertiary transition-colors mb-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0`,children:[(0,G.jsx)(vc,{className:`w-5 h-5 text-bambu-green shrink-0`}),(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsx)(`p`,{className:`text-sm text-white truncate`,children:e.name}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`projectDetail.files.fileCount`,{count:e.file_count})})]})]}),(0,G.jsx)(ms,{className:`w-4 h-4 text-bambu-gray shrink-0`})]}),r?(0,G.jsx)(`div`,{className:`flex items-center gap-2 px-3 py-2 text-bambu-gray text-sm`,children:(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`})}):t.length===0?(0,G.jsx)(`p`,{className:`text-bambu-gray/60 text-xs italic px-3`,children:n(`projectDetail.files.noFiles`)}):(0,G.jsx)(`div`,{className:`space-y-1 pl-3`,children:t.map(e=>{let t=M5(e);return(0,G.jsxs)(`div`,{className:`flex items-center gap-3 p-2 rounded-lg hover:bg-bambu-dark-tertiary transition-colors`,children:[(0,G.jsx)(`div`,{className:`w-10 h-10 shrink-0 rounded bg-bambu-dark overflow-hidden flex items-center justify-center`,children:e.thumbnail_path?(0,G.jsx)(`img`,{src:Z.getLibraryFileThumbnailUrl(e.id),alt:e.print_name||e.filename,className:`w-full h-full object-cover`}):(0,G.jsx)(sc,{className:`w-5 h-5 text-bambu-gray/40`})}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`p`,{className:`text-sm text-white truncate`,title:e.print_name||e.filename,children:e.print_name||e.filename}),(0,G.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded font-medium ${e.file_type===`3mf`?`bg-bambu-green/20 text-bambu-green`:e.file_type===`gcode`||e.file_type===`gcode.3mf`?`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`:`bg-bambu-gray/20 text-bambu-gray`}`,children:e.file_type.toUpperCase()})]}),t&&(()=>{let t=j.get(e.id)??0,r=h.target_sets;if(!r)return t>0?(0,G.jsxs)(`span`,{className:`shrink-0 text-xs px-1.5 py-0.5 rounded-full bg-bambu-dark text-bambu-gray`,title:n(`projectDetail.files.printedCount`,{count:t}),children:[t,`×`]}):null;let i=Math.min(t/r*100,100),a=t>=r?`text-status-ok`:t>0?`text-status-warning`:`text-bambu-gray`,o=t>=r?`bg-status-ok`:t>0?`bg-status-warning`:`bg-bambu-gray`;return(0,G.jsxs)(`div`,{className:`shrink-0 w-20`,title:n(`projectDetail.files.progressTooltip`,{done:t,target:r}),children:[(0,G.jsxs)(`p`,{className:`text-xs font-medium text-right ${a}`,children:[t,` / `,r]}),(0,G.jsx)(`div`,{className:`h-1 bg-bambu-dark rounded-full overflow-hidden mt-1`,children:(0,G.jsx)(`div`,{className:`h-full ${o}`,style:{width:`${i}%`}})})]})})(),t&&(0,G.jsx)(`div`,{className:`flex items-center gap-1 shrink-0`,children:(0,G.jsx)(`button`,{onClick:()=>p(e),title:n(`common.print`),className:`p-1.5 rounded hover:bg-bambu-green/20 text-bambu-green transition-colors`,children:(0,G.jsx)(Rl,{className:`w-4 h-4`})})})]},e.id)})})]},e.id)})}):(0,G.jsx)(`p`,{className:`text-bambu-gray/70 text-sm italic`,children:n(`projectDetail.files.empty`)})]})}),(0,G.jsx)(zd,{children:(0,G.jsxs)(Vd,{className:`p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-4`,children:[(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(cu,{className:`w-5 h-5`}),n(`projectDetail.bom.title`),Ie&&Ie.bom_total_items>0&&(0,G.jsxs)(`span`,{className:`text-sm font-normal text-bambu-gray`,children:[`(`,n(`projectDetail.bom.acquired`,{completed:Ie.bom_completed_items,total:Ie.bom_total_items}),`)`]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[x&&x.some(e=>e.is_complete)&&(0,G.jsx)(`button`,{onClick:()=>le(!ce),className:`text-xs px-2 py-1 rounded transition-colors ${ce?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark text-bambu-gray hover:text-white`}`,children:n(ce?`projectDetail.bom.showAll`:`projectDetail.bom.hideDone`)}),!se&&(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:()=>H(!0),disabled:!a(`projects:update`),title:a(`projects:update`)?void 0:n(`projectDetail.bom.noAddPermission`),children:[(0,G.jsx)(Fl,{className:`w-4 h-4 mr-1`}),n(`projectDetail.bom.addPart`)]})]})]}),se&&(0,G.jsxs)(`form`,{onSubmit:De,className:`bg-bambu-dark rounded-lg p-4 mb-4 space-y-3`,children:[(0,G.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-3`,children:[(0,G.jsx)(`input`,{type:`text`,value:z,onChange:e=>B(e.target.value),className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:n(`projectDetail.bom.partNamePlaceholder`),autoFocus:!0}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsx)(`input`,{type:`number`,value:V,onChange:e=>ee(parseInt(e.target.value)||1),className:`w-20 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white focus:outline-none focus:border-bambu-green`,min:`1`,placeholder:n(`projectDetail.bom.qty`)}),(0,G.jsx)(`input`,{type:`number`,step:`0.01`,value:te,onChange:e=>ne(e.target.value),className:`flex-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:n(`projectDetail.bom.price`,{currency:N})})]})]}),(0,G.jsx)(`input`,{type:`url`,value:re,onChange:e=>ie(e.target.value),className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:n(`projectDetail.bom.sourcingUrlPlaceholder`)}),(0,G.jsx)(`input`,{type:`text`,value:ae,onChange:e=>oe(e.target.value),className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:n(`projectDetail.bom.remarksPlaceholder`)}),(0,G.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,size:`sm`,onClick:()=>H(!1),children:n(`common.cancel`)}),(0,G.jsx)(Q,{type:`submit`,size:`sm`,disabled:!z.trim()||we.isPending,children:we.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):n(`projectDetail.bom.addPart`)})]})]}),S?(0,G.jsx)(`div`,{className:`flex items-center justify-center py-4`,children:(0,G.jsx)(Y,{className:`w-6 h-6 animate-spin text-bambu-green`})}):x&&x.length>0?(0,G.jsxs)(`div`,{className:`space-y-2`,children:[x.filter(e=>!ce||!e.is_complete).map(e=>(0,G.jsx)(`div`,{className:`p-3 rounded-lg transition-colors ${e.is_complete?`bg-status-ok/10`:`bg-bambu-dark`}`,children:ue?.id===e.id?(0,G.jsxs)(`form`,{onSubmit:je,className:`space-y-3`,children:[(0,G.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-3`,children:[(0,G.jsx)(`input`,{type:`text`,value:fe,onChange:e=>pe(e.target.value),className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:n(`projectDetail.bom.partName`),autoFocus:!0}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsx)(`input`,{type:`number`,value:me,onChange:e=>he(parseInt(e.target.value)||1),className:`w-20 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white focus:outline-none focus:border-bambu-green`,min:`1`,placeholder:n(`projectDetail.bom.qty`)}),(0,G.jsx)(`input`,{type:`number`,step:`0.01`,value:ge,onChange:e=>_e(e.target.value),className:`flex-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:n(`projectDetail.bom.price`,{currency:N})})]})]}),(0,G.jsx)(`input`,{type:`url`,value:ve,onChange:e=>ye(e.target.value),className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:n(`projectDetail.bom.sourcingUrlPlaceholder`)}),(0,G.jsx)(`input`,{type:`text`,value:be,onChange:e=>xe(e.target.value),className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:n(`projectDetail.bom.remarksPlaceholder`)}),(0,G.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,size:`sm`,onClick:Me,children:n(`common.cancel`)}),(0,G.jsx)(Q,{type:`submit`,size:`sm`,disabled:!fe.trim()||Te.isPending,children:Te.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):n(`common.save`)})]})]}):(0,G.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,G.jsx)(`button`,{onClick:()=>a(`projects:update`)&&Oe(e),disabled:Te.isPending||!a(`projects:update`),title:a(`projects:update`)?void 0:n(`projectDetail.bom.noUpdatePermission`),className:`w-5 h-5 mt-0.5 rounded border-2 flex items-center justify-center transition-colors shrink-0 ${e.is_complete?`bg-status-ok border-status-ok text-white`:a(`projects:update`)?`border-bambu-gray hover:border-bambu-green`:`border-bambu-gray/50 cursor-not-allowed`}`,children:e.is_complete&&(0,G.jsx)(xs,{className:`w-3 h-3`})}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,G.jsxs)(`p`,{className:`text-sm font-medium ${e.is_complete?`text-bambu-gray line-through`:`text-white`}`,children:[e.name,(0,G.jsxs)(`span`,{className:`text-bambu-gray font-normal ml-2`,children:[`x`,e.quantity_needed]})]}),e.unit_price!==null&&(0,G.jsxs)(`span`,{className:`text-xs text-bambu-green whitespace-nowrap`,children:[N,(e.unit_price*e.quantity_needed).toFixed(2)]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(`button`,{onClick:()=>a(`projects:update`)&&Ae(e),disabled:!a(`projects:update`),className:`p-1 rounded transition-colors shrink-0 ${a(`projects:update`)?`hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white`:`text-bambu-gray/50 cursor-not-allowed`}`,title:a(`projects:update`)?n(`common.edit`):n(`projectDetail.bom.noEditPermission`),children:(0,G.jsx)(Al,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:()=>a(`projects:update`)&&ke(e.id,e.name),disabled:!a(`projects:update`),className:`p-1 rounded transition-colors shrink-0 ${a(`projects:update`)?`hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-red-400`:`text-bambu-gray/50 cursor-not-allowed`}`,title:a(`projects:update`)?n(`common.delete`):n(`projectDetail.bom.noDeletePermission`),children:(0,G.jsx)(Pu,{className:`w-4 h-4`})})]})]}),e.sourcing_url&&(0,G.jsxs)(`a`,{href:e.sourcing_url,target:`_blank`,rel:`noopener noreferrer`,className:`flex items-center gap-1 mt-1 text-xs text-blue-700 dark:text-blue-400 hover:text-blue-900 dark:hover:text-blue-300 transition-colors`,onClick:e=>e.stopPropagation(),children:[(0,G.jsx)(rc,{className:`w-3 h-3 shrink-0`}),(0,G.jsx)(`span`,{className:`truncate`,children:(()=>{try{return new URL(e.sourcing_url).hostname.replace(`www.`,``)}catch{return e.sourcing_url}})()})]}),e.remarks&&(0,G.jsx)(`p`,{className:`mt-1 text-xs text-bambu-gray/80 italic`,children:e.remarks})]})]})},e.id)),Ie&&Ie.bom_cost>0&&(0,G.jsxs)(`div`,{className:`pt-2 mt-2 border-t border-bambu-dark-tertiary flex justify-between text-sm`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:n(`projectDetail.bom.totalCost`)}),(0,G.jsxs)(`span`,{className:`text-white font-medium`,children:[N,Ie.bom_cost.toFixed(2)]})]})]}):(0,G.jsx)(`p`,{className:`text-bambu-gray/70 text-sm italic`,children:n(`projectDetail.bom.empty`)})]})}),(0,G.jsx)(zd,{children:(0,G.jsxs)(Vd,{className:`p-4`,children:[(0,G.jsx)(`div`,{className:`flex items-center justify-between mb-3`,children:(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(zc,{className:`w-5 h-5`}),n(`projectDetail.timeline.title`)]})}),w?(0,G.jsx)(`div`,{className:`flex items-center justify-center py-4`,children:(0,G.jsx)(Y,{className:`w-6 h-6 animate-spin text-bambu-green`})}):C&&C.length>0?(0,G.jsx)(`div`,{className:`space-y-3`,children:C.slice(0,10).map((e,t)=>(0,G.jsxs)(`div`,{className:`flex gap-3`,children:[(0,G.jsxs)(`div`,{className:`w-8 h-8 rounded-full flex items-center justify-center shrink-0 ${e.event_type===`print_completed`?`bg-status-ok/20 text-status-ok`:e.event_type===`print_failed`?`bg-status-error/20 text-status-error`:e.event_type===`print_started`?`bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400`:`bg-bambu-dark-tertiary text-bambu-gray`}`,children:[e.event_type===`print_completed`&&(0,G.jsx)(xs,{className:`w-4 h-4`}),e.event_type===`print_failed`&&(0,G.jsx)(Ds,{className:`w-4 h-4`}),e.event_type===`print_started`&&(0,G.jsx)(Rl,{className:`w-4 h-4`}),e.event_type===`queued`&&(0,G.jsx)($c,{className:`w-4 h-4`}),e.event_type===`project_created`&&(0,G.jsx)(Fl,{className:`w-4 h-4`})]}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:e.title}),e.description&&(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray truncate`,children:e.description}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray/70`,children:Fe(e.timestamp)})]})]},t))}):(0,G.jsx)(`p`,{className:`text-bambu-gray/70 text-sm italic`,children:n(`projectDetail.timeline.empty`)})]})}),!h.is_template&&(0,G.jsx)(`div`,{className:`flex justify-end`,children:(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:()=>Pe.mutate(),disabled:Pe.isPending||!a(`projects:create`),title:a(`projects:create`)?void 0:n(`projectDetail.template.noCreatePermission`),children:[Pe.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin mr-2`}):(0,G.jsx)(Vs,{className:`w-4 h-4 mr-2`}),n(`projectDetail.template.saveAsTemplate`)]})}),Ie&&(Ie.queued_prints>0||Ie.in_progress_prints>0)&&(0,G.jsx)(zd,{children:(0,G.jsxs)(Vd,{className:`p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)($c,{className:`w-5 h-5`}),n(`projectDetail.queue.title`)]}),(0,G.jsx)(Ai,{to:`/queue?project=${m}`,className:`text-sm text-bambu-green hover:underline`,children:n(`projectDetail.queue.viewAll`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-4 text-sm`,children:[Ie.in_progress_prints>0&&(0,G.jsx)(`span`,{className:`text-yellow-700 dark:text-yellow-400`,children:n(`projectDetail.queue.printing`,{count:Ie.in_progress_prints})}),Ie.queued_prints>0&&(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:n(`projectDetail.queue.queued`,{count:Ie.queued_prints})})]})]})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`div`,{className:`flex items-center justify-between mb-4`,children:(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(Cl,{className:`w-5 h-5`}),n(`projectDetail.prints.title`,{count:v?.length||0})]})}),b?(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-green`})}):(0,G.jsx)(jKe,{archives:v||[],t:n})]}),o&&(0,G.jsx)(j5,{t:n,currencySymbol:N,project:{...h,archive_count:Ie?.total_archives||0,total_items:Ie?.total_items||0,completed_count:Ie?.completed_prints||0,failed_count:Ie?.failed_prints||0,queue_count:Ie?.queued_prints||0,progress_percent:Ie?.progress_percent||null,child_count:h.children?.length??0,archives:[]},onClose:()=>s(!1),onSave:e=>F.mutate(e),isLoading:F.isPending}),Se.isOpen&&(0,G.jsx)(of,{title:Se.title,message:Se.message,confirmText:n(`common.delete`),variant:`danger`,onConfirm:Se.onConfirm,onCancel:()=>Ce(e=>({...e,isOpen:!1}))}),f&&(0,G.jsx)(zU,{mode:`create`,libraryFileId:f.id,archiveName:f.print_name||f.filename,projectId:m,onClose:()=>p(null),onSuccess:()=>{p(null),r.invalidateQueries({queryKey:[`archives`]}),r.invalidateQueries({queryKey:[`queue`]})}})]})}function L5({icon:e,label:t,dropdownLabel:n,onPrimary:r,items:i}){let[a,o]=(0,y.useState)(!1),s=(0,y.useRef)(null);return(0,y.useEffect)(()=>{if(!a)return;let e=e=>{s.current&&!s.current.contains(e.target)&&o(!1)},t=e=>{e.key===`Escape`&&(e.stopPropagation(),o(!1))};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[a]),i.length===0?(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:r,children:[e,t]}):(0,G.jsxs)(`div`,{className:`relative inline-flex`,ref:s,children:[(0,G.jsxs)(`div`,{className:`flex relative z-50`,children:[(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:()=>{o(!1),r()},className:`rounded-r-none`,children:[e,t]}),(0,G.jsx)(Q,{variant:`secondary`,size:`sm`,onClick:()=>o(e=>!e),"aria-label":n,"aria-haspopup":`menu`,"aria-expanded":a,className:`rounded-l-none border-l border-bambu-dark px-2`,children:(0,G.jsx)(ps,{className:`w-4 h-4 transition-transform ${a?`rotate-180`:``}`})})]}),a&&(0,G.jsx)(`div`,{role:`menu`,className:`absolute right-0 top-full mt-1 w-56 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg z-50 py-1`,children:i.map(e=>(0,G.jsxs)(`button`,{type:`button`,role:`menuitem`,onClick:()=>{o(!1),e.onClick()},className:`w-full text-left px-3 py-2 text-sm text-bambu-gray-light hover:bg-bambu-dark-tertiary hover:text-white transition-colors flex items-center gap-2`,children:[(0,G.jsx)(rc,{className:`w-4 h-4 flex-shrink-0`}),e.label]},e.key))})]})}function PKe({archiveId:e,libraryFileId:t,title:n,fileType:r,onClose:i,onSliceWithBambuddy:a}){let{t:o}=U(),{showToast:s}=qd(),{data:c}=K({queryKey:[`settings`],queryFn:Z.getSettings}),l=HW(c?.open_in_slicer,c?.preferred_slicer),u=t!=null,[d,f]=(0,y.useState)(null),[p,m]=(0,y.useState)(null),[h,g]=(0,y.useState)(!0),[_,v]=(0,y.useState)(null),[b,x]=(0,y.useState)(!1),[S,C]=(0,y.useState)(null),[w,T]=(0,y.useState)(0),[E,D]=(0,y.useState)(!1),[O,k]=(0,y.useState)(null),[A,j]=(0,y.useState)(!1),[M,N]=(0,y.useState)(!1),P=(0,y.useRef)(null),F=(0,y.useRef)(null),I=.35;(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&i()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[i]),(0,y.useEffect)(()=>{if(g(!0),u){let e=(r||``).toLowerCase(),t=e===`3mf`||e===`gcode.3mf`||e===`stl`;m({has_model:t,has_source:!1,build_volume:{x:256,y:256,z:256},filament_colors:[]}),f(t?`3d`:null),g(!1);return}if(!e){m(null),f(null),g(!1);return}Z.getArchiveCapabilities(e).then(e=>{m(e),e.has_model&&f(`3d`),g(!1)}).catch(()=>{m({has_model:!0,has_source:!1,build_volume:{x:256,y:256,z:256},filament_colors:[]}),f(`3d`),g(!1)})},[e,r,u]),(0,y.useEffect)(()=>{if(x(!0),C(null),T(0),u){let e=(r||``).toLowerCase();if(!t||!(e===`3mf`||e===`gcode.3mf`)){v(null),x(!1);return}Z.getLibraryFilePlates(t).then(e=>v(e)).catch(()=>v(null)).finally(()=>x(!1));return}if(!e){v(null),x(!1);return}Z.getArchivePlates(e).then(e=>v(e)).catch(()=>v(null)).finally(()=>x(!1))},[e,r,u,t]);let L=(0,y.useMemo)(()=>_?.plates??[],[_]),R=(_?.is_multi_plate??!1)&&L.length>1,z=E&&R,B=S==null?null:L.find(e=>e.index===S)??null,V=e=>e.object_count??e.objects?.length??0,ee=L.reduce((e,t)=>e+V(t),0),te=B?V(B):ee,ne=B?o(`modelViewer.plateNumber`,{number:B.index}):o(`modelViewer.allPlates`),re=L.length>0,ie=(0,y.useRef)(null),ae=(0,y.useRef)(null),[oe,se]=(0,y.useState)(10),[H,ce]=(0,y.useState)(3),le=L.length>oe,ue=Math.max(1,Math.ceil(L.length/oe)),de=le?L.slice(w*oe,(w+1)*oe):L;(0,y.useEffect)(()=>{if(!z){se(10),ce(3);return}let e=ie.current,t=ae.current;if(!e||!t)return;let n=0,r=()=>{let n=t.clientWidth,r=Math.floor(n/210),i=Math.max(3,Math.min(5,r||3));ce(e=>e===i?e:i);let a=window.getComputedStyle(e),o=Number.parseFloat(a.rowGap||`0`),s=e.querySelector(`button`)?.getBoundingClientRect().height??44,c=t.clientHeight,l=Math.max(1,Math.floor((c+o)/(s+o)))*i,u=Math.max(1,l-1);se(e=>e===u?e:u)},i=()=>{n&&cancelAnimationFrame(n),n=requestAnimationFrame(r)};i();let a=new ResizeObserver(i);return a.observe(t),a.observe(e),()=>{n&&cancelAnimationFrame(n),a.disconnect()}},[z,L.length]),(0,y.useEffect)(()=>{if(!le){T(0);return}T(e=>Math.min(e,ue-1))},[L.length,le,ue]),(0,y.useEffect)(()=>{if(!le||S==null)return;let e=L.findIndex(e=>e.index===S);if(e<0)return;let t=Math.floor(e/oe);T(e=>e===t?e:t)},[L,oe,S,le]),(0,y.useEffect)(()=>{if(!z){k(null),N(!1);return}if(M)return;let e=P.current,t=F.current;if(!e||!t)return;let n=e.clientHeight;if(!n)return;let r=Math.max(240,n*I),i=Math.max(160,n-10-r),a=Math.min(t.scrollHeight,i);k(Math.max(160,a))},[z,M,L.length,w,10,160,240,I]),(0,y.useEffect)(()=>{if(!A)return;let e=e=>{let t=P.current;if(!t)return;let n=t.getBoundingClientRect(),r=n.height;if(!r)return;let i=Math.max(240,r*I),a=Math.max(160,r-10-i);k(Math.min(a,Math.max(160,e.clientY-n.top)))},t=()=>{j(!1),N(!0)};return document.addEventListener(`mousemove`,e),document.addEventListener(`mouseup`,t),document.body.style.cursor=`row-resize`,document.body.style.userSelect=`none`,()=>{document.removeEventListener(`mousemove`,e),document.removeEventListener(`mouseup`,t),document.body.style.cursor=``,document.body.style.userSelect=``}},[A,10,160,240,I]);let fe=l===`orcaslicer`?[`orcaslicer`,`bambu_studio`]:[`bambu_studio`,`orcaslicer`],pe=u?fe.filter(e=>uje(r,e)):fe,me=pe.length>0,he=mje(r),ge=!!(u&&c?.use_slicer_api&&a&&he),_e=async r=>{if(!me)return;let i=n||`model`;try{if(u){let{token:e}=await Z.createLibrarySlicerToken(t),n=Z.getLibrarySlicerDownloadUrl(t,e,i);KW(`${window.location.origin}${n}`,r)}else{let{token:t}=await Z.createArchiveSlicerToken(e),n=Z.getArchiveSlicerDownloadUrl(e,t,i);KW(`${window.location.origin}${n}`,r)}}catch{s(o(`modelViewer.openInSlicerFailed`),`error`),KW(u?`${window.location.origin}${Z.getLibraryFileDownloadUrl(t)}`:`${window.location.origin}${Z.getArchiveForSlicer(e,i)}`,r)}},ve=ge?pe:pe.slice(1),ye=e=>o(e===`orcaslicer`?`settings.slicerOrcaSlicer`:`settings.slicerBambuStudio`),be=ve.map(e=>({key:e,label:o(`modelViewer.openInSlicerWith`,{slicer:ye(e)}),onClick:()=>_e(e)}));return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 ${E?`p-0`:`p-8`}`,onClick:i,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary w-full flex flex-col ${E?`h-full max-w-none rounded-none`:`h-[80vh] max-w-4xl rounded-xl`}`,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-3 min-w-0 flex-1 mr-4`,children:[(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white truncate`,children:n}),re&&(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray bg-bambu-dark-tertiary/70 px-2 py-1 rounded whitespace-nowrap`,children:[ne,`: `,o(`modelViewer.objectCount`,{count:te})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[ge?(0,G.jsx)(L5,{icon:(0,G.jsx)(Rs,{className:`w-4 h-4`}),label:o(`slice.action`),dropdownLabel:o(`modelViewer.moreSlicerOptions`),onPrimary:()=>a?.(),items:be}):me?(0,G.jsx)(L5,{icon:(0,G.jsx)(rc,{className:`w-4 h-4`}),label:pe[0]===l?o(`modelViewer.openInSlicer`):o(`modelViewer.openInSlicerWith`,{slicer:ye(pe[0])}),dropdownLabel:o(`modelViewer.moreSlicerOptions`),onPrimary:()=>_e(pe[0]),items:be}):(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,disabled:!0,children:[(0,G.jsx)(rc,{className:`w-4 h-4`}),o(`modelViewer.openInSlicer`)]}),(0,G.jsx)(Q,{variant:`secondary`,size:`sm`,onClick:()=>D(e=>!e),title:E?`Exit fullscreen`:`Enter fullscreen`,children:E?(0,G.jsx)(fl,{className:`w-4 h-4`}):(0,G.jsx)(cl,{className:`w-4 h-4`})}),(0,G.jsx)(Q,{variant:`ghost`,size:`sm`,onClick:i,children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]})]}),p&&(0,G.jsx)(`div`,{className:`flex border-b border-bambu-dark-tertiary`,children:(0,G.jsxs)(`button`,{onClick:()=>p.has_model&&f(`3d`),disabled:!p.has_model,className:`flex items-center gap-2 px-6 py-3 text-sm font-medium transition-colors ${d===`3d`?`text-bambu-green border-b-2 border-bambu-green`:p.has_model?`text-bambu-gray hover:text-white`:`text-bambu-gray/30 cursor-not-allowed`}`,children:[(0,G.jsx)(Zo,{className:`w-4 h-4`}),o(`modelViewer.tabs.model`),!p.has_model&&(0,G.jsxs)(`span`,{className:`text-xs`,children:[`(`,o(`modelViewer.notAvailable`),`)`]})]})}),(0,G.jsx)(`div`,{className:`flex-1 overflow-hidden p-4`,children:h?(0,G.jsx)(`div`,{className:`w-full h-full flex items-center justify-center`,children:(0,G.jsx)(Y,{className:`w-8 h-8 animate-spin text-bambu-green`})}):d===`3d`&&p?(0,G.jsxs)(`div`,{ref:P,className:`w-full h-full flex flex-col ${z?`gap-0 min-h-0`:`gap-3`}`,children:[R&&(0,G.jsxs)(`div`,{ref:F,style:z&&O!=null?{height:O}:void 0,className:`rounded-lg border border-bambu-dark-tertiary bg-bambu-dark p-3 ${z?`flex flex-col shrink-0`:``}`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-bambu-gray mb-2`,children:[(0,G.jsx)(Jc,{className:`w-4 h-4`}),o(`modelViewer.plates`),b&&(0,G.jsx)(Y,{className:`w-3 h-3 animate-spin`})]}),(0,G.jsxs)(`div`,{className:z?`flex flex-col min-h-0 flex-1`:void 0,children:[(0,G.jsx)(`div`,{ref:ae,className:z?`min-h-0 overflow-hidden pr-1 flex-1`:void 0,children:(0,G.jsxs)(`div`,{ref:ie,className:z?`grid gap-2`:`grid grid-cols-2 md:grid-cols-3 gap-2`,style:z?{gridTemplateColumns:`repeat(${H}, minmax(0, 1fr))`}:void 0,children:[(0,G.jsxs)(`button`,{type:`button`,onClick:()=>C(null),className:`flex items-center rounded-lg border text-left transition-colors ${z?`gap-1.5 p-1.5 w-full`:`gap-2 p-2`} ${S==null?`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary bg-bambu-dark-secondary hover:border-bambu-gray`}`,children:[(0,G.jsx)(`div`,{className:`rounded bg-bambu-dark-tertiary flex items-center justify-center ${z?`w-8 h-8`:`w-10 h-10`}`,children:(0,G.jsx)(Jc,{className:`${z?`w-4 h-4`:`w-5 h-5`} text-bambu-gray`})}),(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,G.jsx)(`p`,{className:`${z?`text-xs`:`text-sm`} text-white font-medium truncate`,children:o(`modelViewer.allPlates`)}),(0,G.jsx)(`p`,{className:`${z?`text-[10px]`:`text-xs`} text-bambu-gray truncate`,children:o(`modelViewer.plateCount`,{count:L.length})})]}),S==null&&(0,G.jsx)(fs,{className:`${z?`w-3.5 h-3.5`:`w-4 h-4`} text-bambu-green flex-shrink-0`})]}),de.map(e=>(0,G.jsxs)(`button`,{type:`button`,onClick:()=>C(e.index),className:`flex items-center rounded-lg border text-left transition-colors ${z?`gap-1.5 p-1.5 w-full`:`gap-2 p-2`} ${S===e.index?`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary bg-bambu-dark-secondary hover:border-bambu-gray`}`,children:[e.has_thumbnail&&e.thumbnail_url?(0,G.jsx)(`img`,{src:vd(e.thumbnail_url),alt:`Plate ${e.index}`,className:`${z?`w-8 h-8`:`w-10 h-10`} rounded object-cover bg-bambu-dark-tertiary`}):(0,G.jsx)(`div`,{className:`rounded bg-bambu-dark-tertiary flex items-center justify-center ${z?`w-8 h-8`:`w-10 h-10`}`,children:(0,G.jsx)(Jc,{className:`${z?`w-4 h-4`:`w-5 h-5`} text-bambu-gray`})}),(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,G.jsx)(`p`,{className:`${z?`text-xs`:`text-sm`} text-white font-medium truncate`,children:e.name||o(`modelViewer.plateNumber`,{number:e.index})}),(0,G.jsx)(`p`,{className:`${z?`text-[10px]`:`text-xs`} text-bambu-gray truncate`,children:o(`modelViewer.objectCount`,{count:e.object_count??e.objects?.length??0})})]}),S===e.index&&(0,G.jsx)(fs,{className:`${z?`w-3.5 h-3.5`:`w-4 h-4`} text-bambu-green flex-shrink-0`})]},e.index))]})}),(B||le)&&(0,G.jsxs)(`div`,{className:`mt-auto pt-3 flex items-center gap-4 text-xs text-bambu-gray overflow-x-auto`,children:[B&&(0,G.jsxs)(`div`,{className:`flex items-center gap-3 whitespace-nowrap`,children:[(0,G.jsx)(`span`,{children:o(`modelViewer.plateNumber`,{number:B.index})}),B.print_time_seconds!=null&&(0,G.jsx)(`span`,{children:o(`modelViewer.eta`,{minutes:Math.round(B.print_time_seconds/60)})}),B.filament_used_grams!=null&&(0,G.jsxs)(`span`,{children:[B.filament_used_grams.toFixed(1),` g`]}),B.filaments.length>0&&(0,G.jsx)(`span`,{children:o(`modelViewer.filamentCount`,{count:B.filaments.length})})]}),le&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2 whitespace-nowrap ${B?`ml-auto`:``}`,children:[(0,G.jsx)(`span`,{children:o(`modelViewer.pagination.pageOf`,{current:w+1,total:ue})}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(`button`,{type:`button`,onClick:()=>T(e=>Math.max(e-1,0)),disabled:w===0,className:`px-2 py-1 rounded border text-xs ${w===0?`border-bambu-dark-tertiary text-bambu-gray/40 cursor-not-allowed`:`border-bambu-dark-tertiary text-bambu-gray hover:text-white hover:border-bambu-gray`}`,children:o(`modelViewer.pagination.prev`)}),(()=>{let e=Math.max(0,w-2),t=Math.min(ue,e+5);t-e<5&&(e=Math.max(0,t-5));let n=Array.from({length:t-e},(t,n)=>e+n);return(0,G.jsxs)(G.Fragment,{children:[e>0&&(0,G.jsx)(`button`,{type:`button`,onClick:()=>T(0),className:`px-2 py-1 rounded border text-xs ${w===0?`border-bambu-green text-bambu-green`:`border-bambu-dark-tertiary text-bambu-gray hover:text-white hover:border-bambu-gray`}`,children:`1`}),e>1&&(0,G.jsx)(`span`,{className:`px-1`,children:`…`}),n.map(e=>(0,G.jsx)(`button`,{type:`button`,onClick:()=>T(e),className:`px-2 py-1 rounded border text-xs ${w===e?`border-bambu-green text-bambu-green`:`border-bambu-dark-tertiary text-bambu-gray hover:text-white hover:border-bambu-gray`}`,children:e+1},e)),tT(ue-1),className:`px-2 py-1 rounded border text-xs ${w===ue-1?`border-bambu-green text-bambu-green`:`border-bambu-dark-tertiary text-bambu-gray hover:text-white hover:border-bambu-gray`}`,children:ue})]})})(),(0,G.jsx)(`button`,{type:`button`,onClick:()=>T(e=>Math.min(e+1,ue-1)),disabled:w>=ue-1,className:`px-2 py-1 rounded border text-xs ${w>=ue-1?`border-bambu-dark-tertiary text-bambu-gray/40 cursor-not-allowed`:`border-bambu-dark-tertiary text-bambu-gray hover:text-white hover:border-bambu-gray`}`,children:o(`modelViewer.pagination.next`)})]})]})]})]})]}),z&&(0,G.jsx)(`div`,{role:`separator`,"aria-orientation":`horizontal`,onMouseDown:e=>{e.preventDefault(),j(!0),N(!0)},className:`h-2 cursor-row-resize flex items-center justify-center ${A?`bg-bambu-dark-tertiary`:`bg-bambu-dark-secondary/60 hover:bg-bambu-dark-tertiary`}`,children:(0,G.jsx)(`div`,{className:`w-12 h-1 rounded-full bg-bambu-gray/50`})}),(0,G.jsx)(`div`,{className:`flex-1 ${z?`min-h-0`:``}`,children:(0,G.jsx)(rT,{url:u?Z.getLibraryFileDownloadUrl(t):p.has_source?Z.getSource3mfDownloadUrl(e):Z.getArchiveDownload(e),fileType:r,buildVolume:p.build_volume,filamentColors:p.filament_colors,selectedPlateId:S,className:`w-full h-full`})})]}):(0,G.jsx)(`div`,{className:`w-full h-full flex items-center justify-center text-bambu-gray`,children:o(`modelViewer.noPreview`)})})]})})}var R5=[`library-tags`];function FKe({open:e,fileIds:t,onClose:n}){let{t:r}=U(),i=co(),{showToast:a}=qd(),[o,s]=(0,y.useState)(`add`),[c,l]=(0,y.useState)(new Set),[u,d]=(0,y.useState)(``),[f,p]=(0,y.useState)(``);(0,y.useEffect)(()=>{e||(s(`add`),l(new Set),d(``),p(``))},[e]);let{data:m=[],isLoading:h}=K({queryKey:R5,queryFn:Z.getLibraryTags,enabled:e}),g=(0,y.useMemo)(()=>{let e=u.trim().toLowerCase();return e?m.filter(t=>t.name.toLowerCase().includes(e)):m},[m,u]),_=e=>{l(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},v=q({mutationFn:e=>Z.createLibraryTag(e),onSuccess:e=>{l(t=>new Set(t).add(e.id)),p(``),i.invalidateQueries({queryKey:R5})},onError:e=>{a(e.message||r(`fileManager.tags.saveFailed`),`error`)}}),b=q({mutationFn:()=>Z.bulkAssignLibraryTags(t,Array.from(c),o),onSuccess:e=>{a(o===`add`?r(`fileManager.tags.applyAddSuccess`,{count:e.associations_added,files:e.files_updated}):r(`fileManager.tags.applyRemoveSuccess`,{count:e.associations_removed,files:e.files_updated}),`success`),i.invalidateQueries({queryKey:[`library-files`]}),i.invalidateQueries({queryKey:R5}),n()},onError:e=>{a(e.message||r(`fileManager.tags.applyFailed`),`error`)}});if((0,y.useEffect)(()=>{if(!e)return;let t=e=>{e.key===`Escape`&&!b.isPending&&!v.isPending&&n()};return document.addEventListener(`keydown`,t),()=>document.removeEventListener(`keydown`,t)},[e,n,b.isPending,v.isPending]),!e)return null;let x=!f.trim()||v.isPending||m.some(e=>e.name.toLowerCase()===f.trim().toLowerCase()),S=`bulk-tags-picker-title`;return(0,G.jsxs)(`div`,{className:`fixed inset-0 z-[60] flex items-center justify-center`,children:[(0,G.jsx)(`div`,{className:`absolute inset-0 bg-black/60`,onClick:()=>!b.isPending&&n()}),(0,G.jsxs)(`div`,{className:`relative w-full max-w-md mx-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl shadow-2xl max-h-[90vh] flex flex-col`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":S,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-4 px-5 py-4 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`h3`,{id:S,className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(Eu,{className:`w-4 h-4 text-bambu-green`}),r(`fileManager.tags.bulkTitle`,{count:t.length})]}),(0,G.jsx)(`button`,{type:`button`,className:`p-1.5 text-bambu-gray hover:text-white rounded`,onClick:n,"aria-label":r(`common.close`),children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]}),(0,G.jsxs)(`div`,{className:`px-5 py-3 border-b border-bambu-dark-tertiary flex gap-4 text-sm`,children:[(0,G.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`radio`,name:`bulk-action`,checked:o===`add`,onChange:()=>s(`add`),className:`accent-bambu-green`}),(0,G.jsx)(`span`,{className:`text-white`,children:r(`fileManager.tags.actionAdd`)})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`radio`,name:`bulk-action`,checked:o===`remove`,onChange:()=>s(`remove`),className:`accent-bambu-green`}),(0,G.jsx)(`span`,{className:`text-white`,children:r(`fileManager.tags.actionRemove`)})]})]}),(0,G.jsx)(`div`,{className:`px-5 py-3 border-b border-bambu-dark-tertiary`,children:(0,G.jsx)(`input`,{type:`text`,value:u,onChange:e=>d(e.target.value),placeholder:r(`fileManager.tags.searchPlaceholder`),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`})}),(0,G.jsx)(`div`,{className:`overflow-y-auto flex-1 min-h-[8rem] max-h-[24rem]`,children:h?(0,G.jsxs)(`div`,{className:`flex items-center justify-center py-12 text-bambu-gray`,children:[(0,G.jsx)(Y,{className:`w-5 h-5 animate-spin mr-2`}),r(`common.loading`)]}):g.length===0?(0,G.jsx)(`div`,{className:`py-12 text-center text-bambu-gray text-sm`,children:m.length===0?r(`fileManager.tags.empty`):r(`fileManager.tags.noMatches`)}):(0,G.jsx)(`ul`,{className:`divide-y divide-bambu-dark-tertiary/40`,children:g.map(e=>(0,G.jsx)(`li`,{children:(0,G.jsxs)(`label`,{className:`flex items-center gap-3 px-5 py-2 hover:bg-bambu-dark-tertiary/30 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:c.has(e.id),onChange:()=>_(e.id),className:`accent-bambu-green`}),(0,G.jsx)(`span`,{className:`text-sm text-white truncate flex-1`,children:e.name}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:e.file_count})]})},e.id))})}),o===`add`&&(0,G.jsxs)(`div`,{className:`px-5 py-3 border-t border-bambu-dark-tertiary flex gap-2`,children:[(0,G.jsx)(`input`,{type:`text`,value:f,onChange:e=>p(e.target.value),placeholder:r(`fileManager.tags.createPlaceholder`),maxLength:64,className:`flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,onKeyDown:e=>{e.key===`Enter`&&!x&&(e.preventDefault(),v.mutate(f.trim()))}}),(0,G.jsxs)(Q,{type:`button`,variant:`secondary`,onClick:()=>v.mutate(f.trim()),disabled:x,children:[v.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Fl,{className:`w-4 h-4`}),r(`fileManager.tags.createButton`)]})]}),(0,G.jsxs)(`div`,{className:`px-5 py-4 border-t border-bambu-dark-tertiary flex justify-end gap-2`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:n,disabled:b.isPending,children:r(`common.cancel`)}),(0,G.jsxs)(Q,{type:`button`,onClick:()=>b.mutate(),disabled:c.size===0||b.isPending||t.length===0,children:[b.isPending&&(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),r(o===`add`?`fileManager.tags.applyAdd`:`fileManager.tags.applyRemove`)]})]})]})]})}function IKe(e,t){let n=t||{};return(e[e.length-1]===``?[...e,``]:e).join((n.padRight?` `:``)+`,`+(n.padLeft===!1?``:` `)).trim()}var LKe=/^[$_\p{ID_Start}][$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,RKe=/^[$_\p{ID_Start}][-$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,zKe={};function z5(e,t){return((t||zKe).jsx?RKe:LKe).test(e)}var BKe=/[ \t\n\f\r]/g;function VKe(e){return typeof e==`object`?e.type===`text`?HKe(e.value):!1:HKe(e)}function HKe(e){return e.replace(BKe,``)===``}var B5=class{constructor(e,t,n){this.normal=t,this.property=e,n&&(this.space=n)}};B5.prototype.normal={},B5.prototype.property={},B5.prototype.space=void 0;function UKe(e,t){let n={},r={};for(let t of e)Object.assign(n,t.property),Object.assign(r,t.normal);return new B5(n,r,t)}function V5(e){return e.toLowerCase()}var H5=class{constructor(e,t){this.attribute=t,this.property=e}};H5.prototype.attribute=``,H5.prototype.booleanish=!1,H5.prototype.boolean=!1,H5.prototype.commaOrSpaceSeparated=!1,H5.prototype.commaSeparated=!1,H5.prototype.defined=!1,H5.prototype.mustUseProperty=!1,H5.prototype.number=!1,H5.prototype.overloadedBoolean=!1,H5.prototype.property=``,H5.prototype.spaceSeparated=!1,H5.prototype.space=void 0;var U5=s({boolean:()=>W5,booleanish:()=>G5,commaOrSpaceSeparated:()=>X5,commaSeparated:()=>Y5,number:()=>q5,overloadedBoolean:()=>K5,spaceSeparated:()=>J5}),WKe=0,W5=Z5(),G5=Z5(),K5=Z5(),q5=Z5(),J5=Z5(),Y5=Z5(),X5=Z5();function Z5(){return 2**++WKe}var Q5=Object.keys(U5),$5=class extends H5{constructor(e,t,n,r){let i=-1;if(super(e,t),GKe(this,`space`,r),typeof n==`number`)for(;++i4&&n.slice(0,4)===`data`&&rqe.test(t)){if(t.charAt(4)===`-`){let e=t.slice(5).replace(nqe,oqe);r=`data`+e.charAt(0).toUpperCase()+e.slice(1)}else{let e=t.slice(4);if(!nqe.test(e)){let n=e.replace(tqe,aqe);n.charAt(0)!==`-`&&(n=`-`+n),t=`data`+n}}i=$5}return new i(r,t)}function aqe(e){return`-`+e.toLowerCase()}function oqe(e){return e.charAt(1).toUpperCase()}var sqe=UKe([KKe,YKe,ZKe,QKe,$Ke],`html`),t7=UKe([KKe,XKe,ZKe,QKe,$Ke],`svg`);function cqe(e){return e.join(` `).trim()}var lqe=o(((e,t)=>{var n=/\/\*[^*]*\*+([^/*][^*]*\*+)*\//g,r=/\n/g,i=/^\s*/,a=/^(\*?[-#/*\\\w]+(\[[0-9a-z_-]+\])?)\s*/,o=/^:\s*/,s=/^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^)]*?\)|[^};])+)/,c=/^[;\s]*/,l=/^\s+|\s+$/g,u=` -`,d=`/`,f=`*`,p=``,m=`comment`,h=`declaration`;function g(e,t){if(typeof e!=`string`)throw TypeError(`First argument must be a string`);if(!e)return[];t||={};var l=1,g=1;function v(e){var t=e.match(r);t&&(l+=t.length);var n=e.lastIndexOf(u);g=~n?e.length-n:g+e.length}function y(){var e={line:l,column:g};return function(t){return t.position=new b(e),C(),t}}function b(e){this.start=e,this.end={line:l,column:g},this.source=t.source}b.prototype.content=e;function x(n){var r=Error(t.source+`:`+l+`:`+g+`: `+n);if(r.reason=n,r.filename=t.source,r.line=l,r.column=g,r.source=e,!t.silent)throw r}function S(t){var n=t.exec(e);if(n){var r=n[0];return v(r),e=e.slice(r.length),n}}function C(){S(i)}function w(e){var t;for(e||=[];t=T();)t!==!1&&e.push(t);return e}function T(){var t=y();if(!(d!=e.charAt(0)||f!=e.charAt(1))){for(var n=2;p!=e.charAt(n)&&(f!=e.charAt(n)||d!=e.charAt(n+1));)++n;if(n+=2,p===e.charAt(n-1))return x(`End of comment missing`);var r=e.slice(2,n-2);return g+=2,v(r),e=e.slice(n),g+=2,t({type:m,comment:r})}}function E(){var e=y(),t=S(a);if(t){if(T(),!S(o))return x(`property missing ':'`);var r=S(s),i=e({type:h,property:_(t[0].replace(n,p)),value:r?_(r[0].replace(n,p)):p});return S(c),i}}function D(){var e=[];w(e);for(var t;t=E();)t!==!1&&(e.push(t),w(e));return e}return C(),D()}function _(e){return e?e.replace(l,p):p}t.exports=g})),uqe=o((e=>{var t=e&&e.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(e,"__esModule",{value:!0}),e.default=r;var n=t(lqe());function r(e,t){let r=null;if(!e||typeof e!=`string`)return r;let i=(0,n.default)(e),a=typeof t==`function`;return i.forEach(e=>{if(e.type!==`declaration`)return;let{property:n,value:i}=e;a?t(n,i,e):i&&(r||={},r[n]=i)}),r}})),dqe=o((e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.camelCase=void 0;var t=/^--[a-zA-Z0-9_-]+$/,n=/-([a-z])/g,r=/^[^-]+$/,i=/^-(webkit|moz|ms|o|khtml)-/,a=/^-(ms)-/,o=function(e){return!e||r.test(e)||t.test(e)},s=function(e,t){return t.toUpperCase()},c=function(e,t){return`${t}-`};e.camelCase=function(e,t){return t===void 0&&(t={}),o(e)?e:(e=e.toLowerCase(),e=t.reactCompat?e.replace(a,c):e.replace(i,c),e.replace(n,s))}})),fqe=o(((e,t)=>{var n=(e&&e.__importDefault||function(e){return e&&e.__esModule?e:{default:e}})(uqe()),r=dqe();function i(e,t){var i={};return!e||typeof e!=`string`||(0,n.default)(e,function(e,n){e&&n&&(i[(0,r.camelCase)(e,t)]=n)}),i}i.default=i,t.exports=i})),pqe=mqe(`end`),n7=mqe(`start`);function mqe(e){return t;function t(t){let n=t&&t.position&&t.position[e]||{};if(typeof n.line==`number`&&n.line>0&&typeof n.column==`number`&&n.column>0)return{line:n.line,column:n.column,offset:typeof n.offset==`number`&&n.offset>-1?n.offset:void 0}}}function hqe(e){let t=n7(e),n=pqe(e);if(t&&n)return{start:t,end:n}}function r7(e){return!e||typeof e!=`object`?``:`position`in e||`type`in e?gqe(e.position):`start`in e||`end`in e?gqe(e):`line`in e||`column`in e?i7(e):``}function i7(e){return _qe(e&&e.line)+`:`+_qe(e&&e.column)}function gqe(e){return i7(e&&e.start)+`-`+i7(e&&e.end)}function _qe(e){return e&&typeof e==`number`?e:1}var a7=class extends Error{constructor(e,t,n){super(),typeof t==`string`&&(n=t,t=void 0);let r=``,i={},a=!1;if(t&&(i=`line`in t&&`column`in t||`start`in t&&`end`in t?{place:t}:`type`in t?{ancestors:[t],place:t.position}:{...t}),typeof e==`string`?r=e:!i.cause&&e&&(a=!0,r=e.message,i.cause=e),!i.ruleId&&!i.source&&typeof n==`string`){let e=n.indexOf(`:`);e===-1?i.ruleId=n:(i.source=n.slice(0,e),i.ruleId=n.slice(e+1))}if(!i.place&&i.ancestors&&i.ancestors){let e=i.ancestors[i.ancestors.length-1];e&&(i.place=e.position)}let o=i.place&&`start`in i.place?i.place.start:i.place;this.ancestors=i.ancestors||void 0,this.cause=i.cause||void 0,this.column=o?o.column:void 0,this.fatal=void 0,this.file=``,this.message=r,this.line=o?o.line:void 0,this.name=r7(i.place)||`1:1`,this.place=i.place||void 0,this.reason=this.message,this.ruleId=i.ruleId||void 0,this.source=i.source||void 0,this.stack=a&&i.cause&&typeof i.cause.stack==`string`?i.cause.stack:``,this.actual=void 0,this.expected=void 0,this.note=void 0,this.url=void 0}};a7.prototype.file=``,a7.prototype.name=``,a7.prototype.reason=``,a7.prototype.message=``,a7.prototype.stack=``,a7.prototype.column=void 0,a7.prototype.line=void 0,a7.prototype.ancestors=void 0,a7.prototype.cause=void 0,a7.prototype.fatal=void 0,a7.prototype.place=void 0,a7.prototype.ruleId=void 0,a7.prototype.source=void 0;var vqe=l(fqe(),1),o7={}.hasOwnProperty,yqe=new Map,bqe=/[A-Z]/g,xqe=new Set([`table`,`tbody`,`thead`,`tfoot`,`tr`]),Sqe=new Set([`td`,`th`]);function Cqe(e,t){if(!t||t.Fragment===void 0)throw TypeError("Expected `Fragment` in options");let n=t.filePath||void 0,r;if(t.development){if(typeof t.jsxDEV!=`function`)throw TypeError("Expected `jsxDEV` in options when `development: true`");r=Nqe(n,t.jsxDEV)}else{if(typeof t.jsx!=`function`)throw TypeError("Expected `jsx` in production options");if(typeof t.jsxs!=`function`)throw TypeError("Expected `jsxs` in production options");r=Mqe(n,t.jsx,t.jsxs)}let i={Fragment:t.Fragment,ancestors:[],components:t.components||{},create:r,elementAttributeNameCase:t.elementAttributeNameCase||`react`,evaluater:t.createEvaluater?t.createEvaluater():void 0,filePath:n,ignoreInvalidStyle:t.ignoreInvalidStyle||!1,passKeys:t.passKeys!==!1,passNode:t.passNode||!1,schema:t.space===`svg`?t7:sqe,stylePropertyNameCase:t.stylePropertyNameCase||`dom`,tableCellAlignToStyle:t.tableCellAlignToStyle!==!1},a=wqe(i,e,void 0);return a&&typeof a!=`string`?a:i.create(e,i.Fragment,{children:a||void 0},void 0)}function wqe(e,t,n){if(t.type===`element`)return Tqe(e,t,n);if(t.type===`mdxFlowExpression`||t.type===`mdxTextExpression`)return Eqe(e,t);if(t.type===`mdxJsxFlowElement`||t.type===`mdxJsxTextElement`)return Oqe(e,t,n);if(t.type===`mdxjsEsm`)return Dqe(e,t);if(t.type===`root`)return kqe(e,t,n);if(t.type===`text`)return Aqe(e,t)}function Tqe(e,t,n){let r=e.schema,i=r;t.tagName.toLowerCase()===`svg`&&r.space===`html`&&(i=t7,e.schema=i),e.ancestors.push(t);let a=Rqe(e,t.tagName,!1),o=Pqe(e,t),s=c7(e,t);return xqe.has(t.tagName)&&(s=s.filter(function(e){return typeof e==`string`?!VKe(e):!0})),jqe(e,o,a,t),s7(o,s),e.ancestors.pop(),e.schema=r,e.create(t,a,o,n)}function Eqe(e,t){if(t.data&&t.data.estree&&e.evaluater){let n=t.data.estree.body[0];return n.type,e.evaluater.evaluateExpression(n.expression)}l7(e,t.position)}function Dqe(e,t){if(t.data&&t.data.estree&&e.evaluater)return e.evaluater.evaluateProgram(t.data.estree);l7(e,t.position)}function Oqe(e,t,n){let r=e.schema,i=r;t.name===`svg`&&r.space===`html`&&(i=t7,e.schema=i),e.ancestors.push(t);let a=t.name===null?e.Fragment:Rqe(e,t.name,!0),o=Fqe(e,t),s=c7(e,t);return jqe(e,o,a,t),s7(o,s),e.ancestors.pop(),e.schema=r,e.create(t,a,o,n)}function kqe(e,t,n){let r={};return s7(r,c7(e,t)),e.create(t,e.Fragment,r,n)}function Aqe(e,t){return t.value}function jqe(e,t,n,r){typeof n!=`string`&&n!==e.Fragment&&e.passNode&&(t.node=r)}function s7(e,t){if(t.length>0){let n=t.length>1?t:t[0];n&&(e.children=n)}}function Mqe(e,t,n){return r;function r(e,r,i,a){let o=Array.isArray(i.children)?n:t;return a?o(r,i,a):o(r,i)}}function Nqe(e,t){return n;function n(n,r,i,a){let o=Array.isArray(i.children),s=n7(n);return t(r,i,a,o,{columnNumber:s?s.column-1:void 0,fileName:e,lineNumber:s?s.line:void 0},void 0)}}function Pqe(e,t){let n={},r,i;for(i in t.properties)if(i!==`children`&&o7.call(t.properties,i)){let a=Iqe(e,i,t.properties[i]);if(a){let[i,o]=a;e.tableCellAlignToStyle&&i===`align`&&typeof o==`string`&&Sqe.has(t.tagName)?r=o:n[i]=o}}if(r){let t=n.style||={};t[e.stylePropertyNameCase===`css`?`text-align`:`textAlign`]=r}return n}function Fqe(e,t){let n={};for(let r of t.attributes)if(r.type===`mdxJsxExpressionAttribute`)if(r.data&&r.data.estree&&e.evaluater){let t=r.data.estree.body[0];t.type;let i=t.expression;i.type;let a=i.properties[0];a.type,Object.assign(n,e.evaluater.evaluateExpression(a.argument))}else l7(e,t.position);else{let i=r.name,a;if(r.value&&typeof r.value==`object`)if(r.value.data&&r.value.data.estree&&e.evaluater){let t=r.value.data.estree.body[0];t.type,a=e.evaluater.evaluateExpression(t.expression)}else l7(e,t.position);else a=r.value===null?!0:r.value;n[i]=a}return n}function c7(e,t){let n=[],r=-1,i=e.passKeys?new Map:yqe;for(;++ri?0:i+t:t>i?i:t,n=n>0?n:0,r.length<1e4)o=Array.from(r),o.unshift(t,n),e.splice(...o);else for(n&&e.splice(t,n);a0?(f7(e,e.length,0,t),e):t}var Jqe={}.hasOwnProperty;function Yqe(e){let t={},n=-1;for(;++n13&&n<32||n>126&&n<160||n>55295&&n<57344||n>64975&&n<65008||(n&65535)==65535||(n&65535)==65534||n>1114111?`�`:String.fromCodePoint(n)}function m7(e){return e.replace(/[\t\n\r ]+/g,` `).replace(/^ | $/g,``).toLowerCase().toUpperCase()}var h7=S7(/[A-Za-z]/),g7=S7(/[\dA-Za-z]/),$qe=S7(/[#-'*+\--9=?A-Z^-~]/);function _7(e){return e!==null&&(e<32||e===127)}var v7=S7(/\d/),eJe=S7(/[\dA-Fa-f]/),tJe=S7(/[!-/:-@[-`{-~]/);function y7(e){return e!==null&&e<-2}function b7(e){return e!==null&&(e<0||e===32)}function x7(e){return e===-2||e===-1||e===32}var nJe=S7(/\p{P}|\p{S}/u),rJe=S7(/\s/);function S7(e){return t;function t(t){return t!==null&&t>-1&&e.test(String.fromCharCode(t))}}function C7(e){let t=[],n=-1,r=0,i=0;for(;++n55295&&a<57344){let t=e.charCodeAt(n+1);a<56320&&t>56319&&t<57344?(o=String.fromCharCode(a,t),i=1):o=`�`}else o=String.fromCharCode(a);o&&=(t.push(e.slice(r,n),encodeURIComponent(o)),r=n+i+1,``),i&&=(n+=i,0)}return t.join(``)+e.slice(r)}function w7(e,t,n,r){let i=r?r-1:1/0,a=0;return o;function o(r){return x7(r)?(e.enter(n),s(r)):t(r)}function s(r){return x7(r)&&a++o))return;let n=t.events.length,a=n,s,c;for(;a--;)if(t.events[a][0]===`exit`&&t.events[a][1].type===`chunkFlow`){if(s){c=t.events[a][1].end;break}s=!0}for(_(r),e=n;er;){let r=n[i];t.containerState=r[1],r[0].exit.call(t,e)}n.length=r}function v(){i.write([null]),a=void 0,i=void 0,t.containerState._closeFlow=void 0}}function lJe(e,t,n){return w7(e,e.attempt(this.parser.constructs.document,t,n),`linePrefix`,this.parser.constructs.disable.null.includes(`codeIndented`)?void 0:4)}function T7(e){if(e===null||b7(e)||rJe(e))return 1;if(nJe(e))return 2}function E7(e,t,n){let r=[],i=-1;for(;++i1&&e[n][1].end.offset-e[n][1].start.offset>1?2:1;let d={...e[r][1].end},f={...e[n][1].start};fJe(d,-c),fJe(f,c),o={type:c>1?`strongSequence`:`emphasisSequence`,start:d,end:{...e[r][1].end}},s={type:c>1?`strongSequence`:`emphasisSequence`,start:{...e[n][1].start},end:f},a={type:c>1?`strongText`:`emphasisText`,start:{...e[r][1].end},end:{...e[n][1].start}},i={type:c>1?`strong`:`emphasis`,start:{...o.start},end:{...s.end}},e[r][1].end={...o.start},e[n][1].start={...s.end},l=[],e[r][1].end.offset-e[r][1].start.offset&&(l=p7(l,[[`enter`,e[r][1],t],[`exit`,e[r][1],t]])),l=p7(l,[[`enter`,i,t],[`enter`,o,t],[`exit`,o,t],[`enter`,a,t]]),l=p7(l,E7(t.parser.constructs.insideSpan.null,e.slice(r+1,n),t)),l=p7(l,[[`exit`,a,t],[`enter`,s,t],[`exit`,s,t],[`exit`,i,t]]),e[n][1].end.offset-e[n][1].start.offset?(u=2,l=p7(l,[[`enter`,e[n][1],t],[`exit`,e[n][1],t]])):u=0,f7(e,r-1,n-r+3,l),n=r+l.length-u-2;break}}for(n=-1;++n0&&x7(t)?w7(e,v,`linePrefix`,a+1)(t):v(t)}function v(t){return t===null||y7(t)?e.check(wJe,h,b)(t):(e.enter(`codeFlowValue`),y(t))}function y(t){return t===null||y7(t)?(e.exit(`codeFlowValue`),v(t)):(e.consume(t),y)}function b(n){return e.exit(`codeFenced`),t(n)}function x(e,t,n){let i=0;return a;function a(t){return e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),c}function c(t){return e.enter(`codeFencedFence`),x7(t)?w7(e,l,`linePrefix`,r.parser.constructs.disable.null.includes(`codeIndented`)?void 0:4)(t):l(t)}function l(t){return t===s?(e.enter(`codeFencedFenceSequence`),u(t)):n(t)}function u(t){return t===s?(i++,e.consume(t),u):i>=o?(e.exit(`codeFencedFenceSequence`),x7(t)?w7(e,d,`whitespace`)(t):d(t)):n(t)}function d(r){return r===null||y7(r)?(e.exit(`codeFencedFence`),t(r)):n(r)}}}function DJe(e,t,n){let r=this;return i;function i(t){return t===null?n(t):(e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),a)}function a(e){return r.parser.lazy[r.now().line]?n(e):t(e)}}var k7={name:`codeIndented`,tokenize:kJe},OJe={partial:!0,tokenize:AJe};function kJe(e,t,n){let r=this;return i;function i(t){return e.enter(`codeIndented`),w7(e,a,`linePrefix`,5)(t)}function a(e){let t=r.events[r.events.length-1];return t&&t[1].type===`linePrefix`&&t[2].sliceSerialize(t[1],!0).length>=4?o(e):n(e)}function o(t){return t===null?c(t):y7(t)?e.attempt(OJe,o,c)(t):(e.enter(`codeFlowValue`),s(t))}function s(t){return t===null||y7(t)?(e.exit(`codeFlowValue`),o(t)):(e.consume(t),s)}function c(n){return e.exit(`codeIndented`),t(n)}}function AJe(e,t,n){let r=this;return i;function i(t){return r.parser.lazy[r.now().line]?n(t):y7(t)?(e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),i):w7(e,a,`linePrefix`,5)(t)}function a(e){let a=r.events[r.events.length-1];return a&&a[1].type===`linePrefix`&&a[2].sliceSerialize(a[1],!0).length>=4?t(e):y7(e)?i(e):n(e)}}var jJe={name:`codeText`,previous:NJe,resolve:MJe,tokenize:PJe};function MJe(e){let t=e.length-4,n=3,r,i;if((e[n][1].type===`lineEnding`||e[n][1].type===`space`)&&(e[t][1].type===`lineEnding`||e[t][1].type===`space`)){for(r=n;++r=this.left.length+this.right.length)throw RangeError("Cannot access index `"+e+"` in a splice buffer of size `"+(this.left.length+this.right.length)+"`");return ethis.left.length?this.right.slice(this.right.length-n+this.left.length,this.right.length-e+this.left.length).reverse():this.left.slice(e).concat(this.right.slice(this.right.length-n+this.left.length).reverse())}splice(e,t,n){let r=t||0;this.setCursor(Math.trunc(e));let i=this.right.splice(this.right.length-r,1/0);return n&&A7(this.left,n),i.reverse()}pop(){return this.setCursor(1/0),this.left.pop()}push(e){this.setCursor(1/0),this.left.push(e)}pushMany(e){this.setCursor(1/0),A7(this.left,e)}unshift(e){this.setCursor(0),this.right.push(e)}unshiftMany(e){this.setCursor(0),A7(this.right,e.reverse())}setCursor(e){if(!(e===this.left.length||e>this.left.length&&this.right.length===0||e<0&&this.left.length===0))if(e=4?t(i):e.interrupt(r.parser.constructs.flow,n,t)(i)}}function UJe(e,t,n,r,i,a,o,s,c){let l=c||1/0,u=0;return d;function d(t){return t===60?(e.enter(r),e.enter(i),e.enter(a),e.consume(t),e.exit(a),f):t===null||t===32||t===41||_7(t)?n(t):(e.enter(r),e.enter(o),e.enter(s),e.enter(`chunkString`,{contentType:`string`}),h(t))}function f(n){return n===62?(e.enter(a),e.consume(n),e.exit(a),e.exit(i),e.exit(r),t):(e.enter(s),e.enter(`chunkString`,{contentType:`string`}),p(n))}function p(t){return t===62?(e.exit(`chunkString`),e.exit(s),f(t)):t===null||t===60||y7(t)?n(t):(e.consume(t),t===92?m:p)}function m(t){return t===60||t===62||t===92?(e.consume(t),p):p(t)}function h(i){return!u&&(i===null||i===41||b7(i))?(e.exit(`chunkString`),e.exit(s),e.exit(o),e.exit(r),t(i)):u999||l===null||l===91||l===93&&!c||l===94&&!s&&`_hiddenFootnoteSupport`in o.parser.constructs?n(l):l===93?(e.exit(a),e.enter(i),e.consume(l),e.exit(i),e.exit(r),t):y7(l)?(e.enter(`lineEnding`),e.consume(l),e.exit(`lineEnding`),u):(e.enter(`chunkString`,{contentType:`string`}),d(l))}function d(t){return t===null||t===91||t===93||y7(t)||s++>999?(e.exit(`chunkString`),u(t)):(e.consume(t),c||=!x7(t),t===92?f:d)}function f(t){return t===91||t===92||t===93?(e.consume(t),s++,d):d(t)}}function GJe(e,t,n,r,i,a){let o;return s;function s(t){return t===34||t===39||t===40?(e.enter(r),e.enter(i),e.consume(t),e.exit(i),o=t===40?41:t,c):n(t)}function c(n){return n===o?(e.enter(i),e.consume(n),e.exit(i),e.exit(r),t):(e.enter(a),l(n))}function l(t){return t===o?(e.exit(a),c(o)):t===null?n(t):y7(t)?(e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),w7(e,l,`linePrefix`)):(e.enter(`chunkString`,{contentType:`string`}),u(t))}function u(t){return t===o||t===null||y7(t)?(e.exit(`chunkString`),l(t)):(e.consume(t),t===92?d:u)}function d(t){return t===o||t===92?(e.consume(t),u):u(t)}}function j7(e,t){let n;return r;function r(i){return y7(i)?(e.enter(`lineEnding`),e.consume(i),e.exit(`lineEnding`),n=!0,r):x7(i)?w7(e,r,n?`linePrefix`:`lineSuffix`)(i):t(i)}}var KJe={name:`definition`,tokenize:JJe},qJe={partial:!0,tokenize:YJe};function JJe(e,t,n){let r=this,i;return a;function a(t){return e.enter(`definition`),o(t)}function o(t){return WJe.call(r,e,s,n,`definitionLabel`,`definitionLabelMarker`,`definitionLabelString`)(t)}function s(t){return i=m7(r.sliceSerialize(r.events[r.events.length-1][1]).slice(1,-1)),t===58?(e.enter(`definitionMarker`),e.consume(t),e.exit(`definitionMarker`),c):n(t)}function c(t){return b7(t)?j7(e,l)(t):l(t)}function l(t){return UJe(e,u,n,`definitionDestination`,`definitionDestinationLiteral`,`definitionDestinationLiteralMarker`,`definitionDestinationRaw`,`definitionDestinationString`)(t)}function u(t){return e.attempt(qJe,d,d)(t)}function d(t){return x7(t)?w7(e,f,`whitespace`)(t):f(t)}function f(a){return a===null||y7(a)?(e.exit(`definition`),r.parser.defined.push(i),t(a)):n(a)}}function YJe(e,t,n){return r;function r(t){return b7(t)?j7(e,i)(t):n(t)}function i(t){return GJe(e,a,n,`definitionTitle`,`definitionTitleMarker`,`definitionTitleString`)(t)}function a(t){return x7(t)?w7(e,o,`whitespace`)(t):o(t)}function o(e){return e===null||y7(e)?t(e):n(e)}}var XJe={name:`hardBreakEscape`,tokenize:ZJe};function ZJe(e,t,n){return r;function r(t){return e.enter(`hardBreakEscape`),e.consume(t),i}function i(r){return y7(r)?(e.exit(`hardBreakEscape`),t(r)):n(r)}}var QJe={name:`headingAtx`,resolve:$Je,tokenize:eYe};function $Je(e,t){let n=e.length-2,r=3,i,a;return e[r][1].type===`whitespace`&&(r+=2),n-2>r&&e[n][1].type===`whitespace`&&(n-=2),e[n][1].type===`atxHeadingSequence`&&(r===n-1||n-4>r&&e[n-2][1].type===`whitespace`)&&(n-=r+1===n?2:4),n>r&&(i={type:`atxHeadingText`,start:e[r][1].start,end:e[n][1].end},a={type:`chunkText`,start:e[r][1].start,end:e[n][1].end,contentType:`text`},f7(e,r,n-r+1,[[`enter`,i,t],[`enter`,a,t],[`exit`,a,t],[`exit`,i,t]])),e}function eYe(e,t,n){let r=0;return i;function i(t){return e.enter(`atxHeading`),a(t)}function a(t){return e.enter(`atxHeadingSequence`),o(t)}function o(t){return t===35&&r++<6?(e.consume(t),o):t===null||b7(t)?(e.exit(`atxHeadingSequence`),s(t)):n(t)}function s(n){return n===35?(e.enter(`atxHeadingSequence`),c(n)):n===null||y7(n)?(e.exit(`atxHeading`),t(n)):x7(n)?w7(e,s,`whitespace`)(n):(e.enter(`atxHeadingText`),l(n))}function c(t){return t===35?(e.consume(t),c):(e.exit(`atxHeadingSequence`),s(t))}function l(t){return t===null||t===35||b7(t)?(e.exit(`atxHeadingText`),s(t)):(e.consume(t),l)}}var tYe=`address.article.aside.base.basefont.blockquote.body.caption.center.col.colgroup.dd.details.dialog.dir.div.dl.dt.fieldset.figcaption.figure.footer.form.frame.frameset.h1.h2.h3.h4.h5.h6.head.header.hr.html.iframe.legend.li.link.main.menu.menuitem.nav.noframes.ol.optgroup.option.p.param.search.section.summary.table.tbody.td.tfoot.th.thead.title.tr.track.ul`.split(`.`),nYe=[`pre`,`script`,`style`,`textarea`],rYe={concrete:!0,name:`htmlFlow`,resolveTo:oYe,tokenize:sYe},iYe={partial:!0,tokenize:lYe},aYe={partial:!0,tokenize:cYe};function oYe(e){let t=e.length;for(;t--&&!(e[t][0]===`enter`&&e[t][1].type===`htmlFlow`););return t>1&&e[t-2][1].type===`linePrefix`&&(e[t][1].start=e[t-2][1].start,e[t+1][1].start=e[t-2][1].start,e.splice(t-2,2)),e}function sYe(e,t,n){let r=this,i,a,o,s,c;return l;function l(e){return u(e)}function u(t){return e.enter(`htmlFlow`),e.enter(`htmlFlowData`),e.consume(t),d}function d(s){return s===33?(e.consume(s),f):s===47?(e.consume(s),a=!0,h):s===63?(e.consume(s),i=3,r.interrupt?t:I):h7(s)?(e.consume(s),o=String.fromCharCode(s),g):n(s)}function f(a){return a===45?(e.consume(a),i=2,p):a===91?(e.consume(a),i=5,s=0,m):h7(a)?(e.consume(a),i=4,r.interrupt?t:I):n(a)}function p(i){return i===45?(e.consume(i),r.interrupt?t:I):n(i)}function m(i){return i===`CDATA[`.charCodeAt(s++)?(e.consume(i),s===6?r.interrupt?t:O:m):n(i)}function h(t){return h7(t)?(e.consume(t),o=String.fromCharCode(t),g):n(t)}function g(s){if(s===null||s===47||s===62||b7(s)){let c=s===47,l=o.toLowerCase();return!c&&!a&&nYe.includes(l)?(i=1,r.interrupt?t(s):O(s)):tYe.includes(o.toLowerCase())?(i=6,c?(e.consume(s),_):r.interrupt?t(s):O(s)):(i=7,r.interrupt&&!r.parser.lazy[r.now().line]?n(s):a?v(s):y(s))}return s===45||g7(s)?(e.consume(s),o+=String.fromCharCode(s),g):n(s)}function _(i){return i===62?(e.consume(i),r.interrupt?t:O):n(i)}function v(t){return x7(t)?(e.consume(t),v):E(t)}function y(t){return t===47?(e.consume(t),E):t===58||t===95||h7(t)?(e.consume(t),b):x7(t)?(e.consume(t),y):E(t)}function b(t){return t===45||t===46||t===58||t===95||g7(t)?(e.consume(t),b):x(t)}function x(t){return t===61?(e.consume(t),S):x7(t)?(e.consume(t),x):y(t)}function S(t){return t===null||t===60||t===61||t===62||t===96?n(t):t===34||t===39?(e.consume(t),c=t,C):x7(t)?(e.consume(t),S):w(t)}function C(t){return t===c?(e.consume(t),c=null,T):t===null||y7(t)?n(t):(e.consume(t),C)}function w(t){return t===null||t===34||t===39||t===47||t===60||t===61||t===62||t===96||b7(t)?x(t):(e.consume(t),w)}function T(e){return e===47||e===62||x7(e)?y(e):n(e)}function E(t){return t===62?(e.consume(t),D):n(t)}function D(t){return t===null||y7(t)?O(t):x7(t)?(e.consume(t),D):n(t)}function O(t){return t===45&&i===2?(e.consume(t),M):t===60&&i===1?(e.consume(t),N):t===62&&i===4?(e.consume(t),L):t===63&&i===3?(e.consume(t),I):t===93&&i===5?(e.consume(t),F):y7(t)&&(i===6||i===7)?(e.exit(`htmlFlowData`),e.check(iYe,R,k)(t)):t===null||y7(t)?(e.exit(`htmlFlowData`),k(t)):(e.consume(t),O)}function k(t){return e.check(aYe,A,R)(t)}function A(t){return e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),j}function j(t){return t===null||y7(t)?k(t):(e.enter(`htmlFlowData`),O(t))}function M(t){return t===45?(e.consume(t),I):O(t)}function N(t){return t===47?(e.consume(t),o=``,P):O(t)}function P(t){if(t===62){let n=o.toLowerCase();return nYe.includes(n)?(e.consume(t),L):O(t)}return h7(t)&&o.length<8?(e.consume(t),o+=String.fromCharCode(t),P):O(t)}function F(t){return t===93?(e.consume(t),I):O(t)}function I(t){return t===62?(e.consume(t),L):t===45&&i===2?(e.consume(t),I):O(t)}function L(t){return t===null||y7(t)?(e.exit(`htmlFlowData`),R(t)):(e.consume(t),L)}function R(n){return e.exit(`htmlFlow`),t(n)}}function cYe(e,t,n){let r=this;return i;function i(t){return y7(t)?(e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),a):n(t)}function a(e){return r.parser.lazy[r.now().line]?n(e):t(e)}}function lYe(e,t,n){return r;function r(r){return e.enter(`lineEnding`),e.consume(r),e.exit(`lineEnding`),e.attempt(O7,t,n)}}var uYe={name:`htmlText`,tokenize:dYe};function dYe(e,t,n){let r=this,i,a,o;return s;function s(t){return e.enter(`htmlText`),e.enter(`htmlTextData`),e.consume(t),c}function c(t){return t===33?(e.consume(t),l):t===47?(e.consume(t),x):t===63?(e.consume(t),y):h7(t)?(e.consume(t),w):n(t)}function l(t){return t===45?(e.consume(t),u):t===91?(e.consume(t),a=0,m):h7(t)?(e.consume(t),v):n(t)}function u(t){return t===45?(e.consume(t),p):n(t)}function d(t){return t===null?n(t):t===45?(e.consume(t),f):y7(t)?(o=d,N(t)):(e.consume(t),d)}function f(t){return t===45?(e.consume(t),p):d(t)}function p(e){return e===62?M(e):e===45?f(e):d(e)}function m(t){return t===`CDATA[`.charCodeAt(a++)?(e.consume(t),a===6?h:m):n(t)}function h(t){return t===null?n(t):t===93?(e.consume(t),g):y7(t)?(o=h,N(t)):(e.consume(t),h)}function g(t){return t===93?(e.consume(t),_):h(t)}function _(t){return t===62?M(t):t===93?(e.consume(t),_):h(t)}function v(t){return t===null||t===62?M(t):y7(t)?(o=v,N(t)):(e.consume(t),v)}function y(t){return t===null?n(t):t===63?(e.consume(t),b):y7(t)?(o=y,N(t)):(e.consume(t),y)}function b(e){return e===62?M(e):y(e)}function x(t){return h7(t)?(e.consume(t),S):n(t)}function S(t){return t===45||g7(t)?(e.consume(t),S):C(t)}function C(t){return y7(t)?(o=C,N(t)):x7(t)?(e.consume(t),C):M(t)}function w(t){return t===45||g7(t)?(e.consume(t),w):t===47||t===62||b7(t)?T(t):n(t)}function T(t){return t===47?(e.consume(t),M):t===58||t===95||h7(t)?(e.consume(t),E):y7(t)?(o=T,N(t)):x7(t)?(e.consume(t),T):M(t)}function E(t){return t===45||t===46||t===58||t===95||g7(t)?(e.consume(t),E):D(t)}function D(t){return t===61?(e.consume(t),O):y7(t)?(o=D,N(t)):x7(t)?(e.consume(t),D):T(t)}function O(t){return t===null||t===60||t===61||t===62||t===96?n(t):t===34||t===39?(e.consume(t),i=t,k):y7(t)?(o=O,N(t)):x7(t)?(e.consume(t),O):(e.consume(t),A)}function k(t){return t===i?(e.consume(t),i=void 0,j):t===null?n(t):y7(t)?(o=k,N(t)):(e.consume(t),k)}function A(t){return t===null||t===34||t===39||t===60||t===61||t===96?n(t):t===47||t===62||b7(t)?T(t):(e.consume(t),A)}function j(e){return e===47||e===62||b7(e)?T(e):n(e)}function M(r){return r===62?(e.consume(r),e.exit(`htmlTextData`),e.exit(`htmlText`),t):n(r)}function N(t){return e.exit(`htmlTextData`),e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),P}function P(t){return x7(t)?w7(e,F,`linePrefix`,r.parser.constructs.disable.null.includes(`codeIndented`)?void 0:4)(t):F(t)}function F(t){return e.enter(`htmlTextData`),o(t)}}var M7={name:`labelEnd`,resolveAll:hYe,resolveTo:gYe,tokenize:_Ye},fYe={tokenize:vYe},pYe={tokenize:yYe},mYe={tokenize:bYe};function hYe(e){let t=-1,n=[];for(;++t=3&&(a===null||y7(a))?(e.exit(`thematicBreak`),t(a)):n(a)}function c(t){return t===i?(e.consume(t),r++,c):(e.exit(`thematicBreakSequence`),x7(t)?w7(e,s,`whitespace`)(t):s(t))}}var F7={continuation:{tokenize:AYe},exit:MYe,name:`list`,tokenize:kYe},DYe={partial:!0,tokenize:NYe},OYe={partial:!0,tokenize:jYe};function kYe(e,t,n){let r=this,i=r.events[r.events.length-1],a=i&&i[1].type===`linePrefix`?i[2].sliceSerialize(i[1],!0).length:0,o=0;return s;function s(t){let i=r.containerState.type||(t===42||t===43||t===45?`listUnordered`:`listOrdered`);if(i===`listUnordered`?!r.containerState.marker||t===r.containerState.marker:v7(t)){if(r.containerState.type||(r.containerState.type=i,e.enter(i,{_container:!0})),i===`listUnordered`)return e.enter(`listItemPrefix`),t===42||t===45?e.check(P7,n,l)(t):l(t);if(!r.interrupt||t===49)return e.enter(`listItemPrefix`),e.enter(`listItemValue`),c(t)}return n(t)}function c(t){return v7(t)&&++o<10?(e.consume(t),c):(!r.interrupt||o<2)&&(r.containerState.marker?t===r.containerState.marker:t===41||t===46)?(e.exit(`listItemValue`),l(t)):n(t)}function l(t){return e.enter(`listItemMarker`),e.consume(t),e.exit(`listItemMarker`),r.containerState.marker=r.containerState.marker||t,e.check(O7,r.interrupt?n:u,e.attempt(DYe,f,d))}function u(e){return r.containerState.initialBlankLine=!0,a++,f(e)}function d(t){return x7(t)?(e.enter(`listItemPrefixWhitespace`),e.consume(t),e.exit(`listItemPrefixWhitespace`),f):n(t)}function f(n){return r.containerState.size=a+r.sliceSerialize(e.exit(`listItemPrefix`),!0).length,t(n)}}function AYe(e,t,n){let r=this;return r.containerState._closeFlow=void 0,e.check(O7,i,a);function i(n){return r.containerState.furtherBlankLines=r.containerState.furtherBlankLines||r.containerState.initialBlankLine,w7(e,t,`listItemIndent`,r.containerState.size+1)(n)}function a(n){return r.containerState.furtherBlankLines||!x7(n)?(r.containerState.furtherBlankLines=void 0,r.containerState.initialBlankLine=void 0,o(n)):(r.containerState.furtherBlankLines=void 0,r.containerState.initialBlankLine=void 0,e.attempt(OYe,t,o)(n))}function o(i){return r.containerState._closeFlow=!0,r.interrupt=void 0,w7(e,e.attempt(F7,t,n),`linePrefix`,r.parser.constructs.disable.null.includes(`codeIndented`)?void 0:4)(i)}}function jYe(e,t,n){let r=this;return w7(e,i,`listItemIndent`,r.containerState.size+1);function i(e){let i=r.events[r.events.length-1];return i&&i[1].type===`listItemIndent`&&i[2].sliceSerialize(i[1],!0).length===r.containerState.size?t(e):n(e)}}function MYe(e){e.exit(this.containerState.type)}function NYe(e,t,n){let r=this;return w7(e,i,`listItemPrefixWhitespace`,r.parser.constructs.disable.null.includes(`codeIndented`)?void 0:5);function i(e){let i=r.events[r.events.length-1];return!x7(e)&&i&&i[1].type===`listItemPrefixWhitespace`?t(e):n(e)}}var PYe={name:`setextUnderline`,resolveTo:FYe,tokenize:IYe};function FYe(e,t){let n=e.length,r,i,a;for(;n--;)if(e[n][0]===`enter`){if(e[n][1].type===`content`){r=n;break}e[n][1].type===`paragraph`&&(i=n)}else e[n][1].type===`content`&&e.splice(n,1),!a&&e[n][1].type===`definition`&&(a=n);let o={type:`setextHeading`,start:{...e[r][1].start},end:{...e[e.length-1][1].end}};return e[i][1].type=`setextHeadingText`,a?(e.splice(i,0,[`enter`,o,t]),e.splice(a+1,0,[`exit`,e[r][1],t]),e[r][1].end={...e[a][1].end}):e[r][1]=o,e.push([`exit`,o,t]),e}function IYe(e,t,n){let r=this,i;return a;function a(t){let a=r.events.length,s;for(;a--;)if(r.events[a][1].type!==`lineEnding`&&r.events[a][1].type!==`linePrefix`&&r.events[a][1].type!==`content`){s=r.events[a][1].type===`paragraph`;break}return!r.parser.lazy[r.now().line]&&(r.interrupt||s)?(e.enter(`setextHeadingLine`),i=t,o(t)):n(t)}function o(t){return e.enter(`setextHeadingLineSequence`),s(t)}function s(t){return t===i?(e.consume(t),s):(e.exit(`setextHeadingLineSequence`),x7(t)?w7(e,c,`lineSuffix`)(t):c(t))}function c(r){return r===null||y7(r)?(e.exit(`setextHeadingLine`),t(r)):n(r)}}var LYe={tokenize:RYe};function RYe(e){let t=this,n=e.attempt(O7,r,e.attempt(this.parser.constructs.flowInitial,i,w7(e,e.attempt(this.parser.constructs.flow,i,e.attempt(RJe,i)),`linePrefix`)));return n;function r(r){if(r===null){e.consume(r);return}return e.enter(`lineEndingBlank`),e.consume(r),e.exit(`lineEndingBlank`),t.currentConstruct=void 0,n}function i(r){if(r===null){e.consume(r);return}return e.enter(`lineEnding`),e.consume(r),e.exit(`lineEnding`),t.currentConstruct=void 0,n}}var zYe={resolveAll:UYe()},BYe=HYe(`string`),VYe=HYe(`text`);function HYe(e){return{resolveAll:UYe(e===`text`?WYe:void 0),tokenize:t};function t(t){let n=this,r=this.parser.constructs[e],i=t.attempt(r,a,o);return a;function a(e){return c(e)?i(e):o(e)}function o(e){if(e===null){t.consume(e);return}return t.enter(`data`),t.consume(e),s}function s(e){return c(e)?(t.exit(`data`),i(e)):(t.consume(e),s)}function c(e){if(e===null)return!0;let t=r[e],i=-1;if(t)for(;++i$Ye,contentInitial:()=>qYe,disable:()=>eXe,document:()=>KYe,flow:()=>YYe,flowInitial:()=>JYe,insideSpan:()=>QYe,string:()=>XYe,text:()=>ZYe}),KYe={42:F7,43:F7,45:F7,48:F7,49:F7,50:F7,51:F7,52:F7,53:F7,54:F7,55:F7,56:F7,57:F7,62:gJe},qYe={91:KJe},JYe={[-2]:k7,[-1]:k7,32:k7},YYe={35:QJe,42:P7,45:[PYe,P7],60:rYe,61:PYe,95:P7,96:TJe,126:TJe},XYe={38:SJe,92:bJe},ZYe={[-5]:N7,[-4]:N7,[-3]:N7,33:xYe,38:SJe,42:D7,60:[pJe,uYe],91:CYe,92:[XJe,bJe],93:M7,95:D7,96:jJe},QYe={null:[D7,zYe]},$Ye={null:[42,95]},eXe={null:[]};function tXe(e,t,n){let r={_bufferIndex:-1,_index:0,line:n&&n.line||1,column:n&&n.column||1,offset:n&&n.offset||0},i={},a=[],o=[],s=[],c={attempt:C(x),check:C(S),consume:v,enter:y,exit:b,interrupt:C(S,{interrupt:!0})},l={code:null,containerState:{},defineSkip:h,events:[],now:m,parser:e,previous:null,sliceSerialize:f,sliceStream:p,write:d},u=t.tokenize.call(l,c);return t.resolveAll&&a.push(t),l;function d(e){return o=p7(o,e),g(),o[o.length-1]===null?(w(t,0),l.events=E7(a,l.events,l),l.events):[]}function f(e,t){return rXe(p(e),t)}function p(e){return nXe(o,e)}function m(){let{_bufferIndex:e,_index:t,line:n,column:i,offset:a}=r;return{_bufferIndex:e,_index:t,line:n,column:i,offset:a}}function h(e){i[e.line]=e.column,E()}function g(){let e;for(;r._index-1){let e=o[0];typeof e==`string`?o[0]=e.slice(r):o.shift()}a>0&&o.push(e[i].slice(0,a))}return o}function rXe(e,t){let n=-1,r=[],i;for(;++nZ.getCloudSettingDetail(e.setting_id)}),p=q({mutationFn:()=>Z.deleteCloudSetting(e.setting_id),onSuccess:()=>{s(o(`profiles.presets.toast.deleted`)),c.invalidateQueries({queryKey:[`cloudSettings`]}),n()},onError:e=>s(e.message,`error`)}),m=y5(e.setting_id),h=v5(e.name,d?.setting?.inherits);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)(zd,{className:`w-full max-w-3xl max-h-[90vh] flex flex-col overflow-hidden`,children:(0,G.jsxs)(Vd,{className:`p-0 flex flex-col min-h-0 flex-1`,children:[(0,G.jsxs)(`div`,{className:`flex-shrink-0 flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`h2`,{className:`text-xl font-semibold text-white truncate`,children:e.name}),m&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 text-xs font-medium bg-bambu-green/20 text-bambu-green rounded-full`,children:o(`profiles.presets.editable`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mt-1 text-sm text-bambu-gray`,children:[(0,G.jsx)(`span`,{className:`capitalize`,children:o(`profiles.presets.types.${e.type}`)}),h.printer&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`span`,{children:`•`}),(0,G.jsx)(`span`,{children:h.printer})]})]})]}),(0,G.jsx)(`button`,{onClick:t,className:`p-2 text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary rounded-lg transition-colors`,children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]}),(0,G.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-4`,children:f?(0,G.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,G.jsx)(Y,{className:`w-8 h-8 text-bambu-green animate-spin`})}):d?(0,G.jsx)(`pre`,{className:`text-xs text-bambu-gray font-mono whitespace-pre-wrap break-all bg-bambu-dark p-4 rounded-lg border border-bambu-dark-tertiary overflow-x-auto max-w-full`,children:S5(d)}):(0,G.jsx)(`div`,{className:`text-center py-16 text-bambu-gray`,children:o(`profiles.presets.failedToLoadDetails`)})}),l?(0,G.jsxs)(`div`,{className:`flex-shrink-0 p-4 border-t border-bambu-dark-tertiary bg-red-500/5`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-3 text-red-700 dark:text-red-400`,children:[(0,G.jsx)(Lu,{className:`w-5 h-5`}),(0,G.jsx)(`span`,{className:`font-medium`,children:o(`profiles.presets.deleteConfirm`)})]}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4`,children:o(`profiles.presets.deleteWarning`,{name:e.name})}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>u(!1),disabled:p.isPending,className:`flex-1`,children:o(`common.cancel`)}),(0,G.jsxs)(Q,{variant:`danger`,onClick:()=>p.mutate(),disabled:p.isPending,className:`flex-1`,children:[p.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Pu,{className:`w-4 h-4`}),o(`common.delete`)]})]})]}):(0,G.jsx)(`div`,{className:`flex-shrink-0 p-4 border-t border-bambu-dark-tertiary`,children:(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:t,className:`flex-1`,children:o(`common.close`)}),(0,G.jsxs)(Q,{variant:`secondary`,onClick:r,disabled:!a(`cloud:auth`),title:a(`cloud:auth`)?void 0:o(`profiles.presets.noDuplicatePermission`),children:[(0,G.jsx)(Vs,{className:`w-4 h-4`}),o(`profiles.presets.duplicate`)]}),m&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(Q,{variant:`secondary`,onClick:i,disabled:f||!d||!a(`cloud:auth`),title:a(`cloud:auth`)?void 0:o(`profiles.presets.noEditPermission`),children:[(0,G.jsx)(Al,{className:`w-4 h-4`}),o(`common.edit`)]}),(0,G.jsx)(Q,{variant:`danger`,onClick:()=>u(!0),disabled:!a(`cloud:auth`),title:a(`cloud:auth`)?void 0:o(`profiles.presets.noDeletePermission`),children:(0,G.jsx)(Pu,{className:`w-4 h-4`})})]})]})})]})})})}function C5(){try{let e=localStorage.getItem(`bambusy_preset_templates`);return e?JSON.parse(e):[]}catch{return[]}}function w5(e){localStorage.setItem(`bambusy_preset_templates`,JSON.stringify(e))}function yKe({onClose:e,onApply:t,t:n}){let{showToast:r}=qd(),[i,a]=(0,y.useState)(C5),[o,s]=(0,y.useState)(`all`),[c,l]=(0,y.useState)(null),[u,d]=(0,y.useState)(``),[f,p]=(0,y.useState)(``),[m,h]=(0,y.useState)(`{}`),[g,_]=(0,y.useState)(null),[v,b]=(0,y.useState)(null),x=o===`all`?i:i.filter(e=>e.type===o),S=e=>{a(e),w5(e)},C=e=>{S(i.filter(t=>t.id!==e)),b(null),r(n(`profiles.templates.toast.deleted`))},w=e=>{l(e.id),d(e.name),p(e.description),h(JSON.stringify(e.settings,null,2)),_(null)},T=()=>{if(!(!c||!u.trim()))try{let e=JSON.parse(m);S(i.map(t=>t.id===c?{...t,name:u.trim(),description:f.trim(),settings:e}:t)),l(null),r(n(`profiles.templates.toast.updated`))}catch(e){_(e.message)}},E=()=>{l(null),d(``),p(``),h(`{}`),_(null)},D=e=>{S(i.map(t=>t.id===e?{...t,showInModal:!t.showInModal}:t))},O={filament:{label:n(`profiles.presets.types.filament`),icon:Zs,color:`text-amber-600 dark:text-amber-400`},print:{label:n(`profiles.presets.types.process`),icon:nu,color:`text-blue-600 dark:text-blue-400`},printer:{label:n(`profiles.presets.types.printer`),icon:Rl,color:`text-purple-600 dark:text-purple-400`}},k=v?i.find(e=>e.id===v):null;return(0,y.useEffect)(()=>{let t=t=>{t.key===`Escape`&&(v?b(null):c?E():e())};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[v,c,e]),(0,G.jsxs)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:[k&&(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-60`,children:(0,G.jsx)(zd,{className:`w-full max-w-md`,children:(0,G.jsxs)(Vd,{className:`p-6`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3 mb-4`,children:[(0,G.jsx)(`div`,{className:`p-2 bg-red-500/20 rounded-lg`,children:(0,G.jsx)(Lu,{className:`w-6 h-6 text-red-600 dark:text-red-400`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`text-lg font-semibold text-white`,children:n(`profiles.templates.deleteTitle`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`profiles.templates.deleteWarning`)})]})]}),(0,G.jsx)(`p`,{className:`text-white mb-6`,children:n(`profiles.templates.deleteConfirm`,{name:k.name})}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>b(null),className:`flex-1`,children:n(`common.cancel`)}),(0,G.jsxs)(Q,{onClick:()=>C(v),className:`flex-1 bg-red-500 hover:bg-red-600`,children:[(0,G.jsx)(Pu,{className:`w-4 h-4`}),n(`common.delete`)]})]})]})})}),(0,G.jsx)(zd,{className:`w-full max-w-2xl max-h-[80vh] flex flex-col`,children:(0,G.jsxs)(Vd,{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.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(_u,{className:`w-5 h-5 text-amber-600 dark:text-amber-400`}),n(`profiles.templates.title`)]}),(0,G.jsx)(`button`,{onClick:e,className:`text-bambu-gray hover:text-white`,children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 p-4 border-b border-bambu-dark-tertiary`,children:[(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:n(`profiles.templates.typeFilter`)}),[`all`,`filament`,`print`,`printer`].map(e=>(0,G.jsx)(`button`,{onClick:()=>s(e),className:`px-3 py-1 text-sm rounded-lg transition-colors ${o===e?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white`}`,children:e===`all`?n(`common.all`):O[e].label},e))]}),(0,G.jsx)(`div`,{className:`flex-1 overflow-y-auto p-4`,children:x.length===0?(0,G.jsxs)(`div`,{className:`text-center py-12 text-bambu-gray`,children:[(0,G.jsx)(_u,{className:`w-12 h-12 mx-auto mb-4 opacity-30`}),(0,G.jsx)(`p`,{children:n(`profiles.templates.noTemplates`)}),(0,G.jsx)(`p`,{className:`text-sm mt-1`,children:n(`profiles.templates.createFirst`)})]}):(0,G.jsx)(`div`,{className:`space-y-2`,children:x.map(e=>{let r=O[e.type],i=r.icon;return c===e.id?(0,G.jsxs)(`div`,{className:`p-4 bg-bambu-dark rounded-lg border border-bambu-green`,children:[(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-3 mb-3`,children:[(0,G.jsx)(`input`,{type:`text`,value:u,onChange:e=>d(e.target.value),placeholder:n(`profiles.templates.namePlaceholder`),className:`px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`,autoFocus:!0}),(0,G.jsx)(`input`,{type:`text`,value:f,onChange:e=>p(e.target.value),placeholder:n(`profiles.templates.descriptionPlaceholder`),className:`px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`})]}),(0,G.jsxs)(`div`,{className:`mb-3`,children:[(0,G.jsx)(`label`,{className:`text-xs text-bambu-gray mb-1 block`,children:n(`profiles.templates.settingsJson`)}),(0,G.jsx)(`textarea`,{value:m,onChange:e=>{h(e.target.value),_(null)},rows:6,className:`w-full px-3 py-2 bg-bambu-dark-secondary border rounded text-white text-sm font-mono focus:outline-none ${g?`border-red-500`:`border-bambu-dark-tertiary focus:border-bambu-green`}`}),g&&(0,G.jsx)(`p`,{className:`text-xs text-red-700 dark:text-red-400 mt-1`,children:g})]}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsxs)(Q,{size:`sm`,onClick:T,disabled:!u.trim(),children:[(0,G.jsx)(ql,{className:`w-4 h-4`}),`Save`]}),(0,G.jsx)(Q,{size:`sm`,variant:`secondary`,onClick:E,children:`Cancel`})]})]},e.id):(0,G.jsxs)(`div`,{className:`flex items-center gap-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary hover:border-bambu-gray-dark transition-colors`,children:[(0,G.jsx)(i,{className:`w-5 h-5 ${r.color} flex-shrink-0`}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`p`,{className:`text-sm font-medium text-white`,children:e.name}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray truncate`,children:e.description})]}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray-dark px-2 py-1 bg-bambu-dark-secondary rounded`,children:n(`profiles.templates.fieldsCount`,{count:Object.keys(e.settings).length})}),(0,G.jsx)(`button`,{onClick:()=>D(e.id),className:`p-1 transition-colors ${e.showInModal?`text-bambu-green hover:text-bambu-green/70`:`text-bambu-gray hover:text-white`}`,title:e.showInModal?n(`profiles.templates.shownInModals`):n(`profiles.templates.hiddenInModals`),children:e.showInModal?(0,G.jsx)(ac,{className:`w-4 h-4`}):(0,G.jsx)(ic,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:()=>t(e),className:`px-3 py-1 text-xs bg-bambu-green/20 text-bambu-green rounded hover:bg-bambu-green/30 transition-colors`,children:n(`profiles.templates.apply`)}),(0,G.jsx)(`button`,{onClick:()=>w(e),className:`p-1 text-bambu-gray hover:text-white`,title:n(`common.edit`),children:(0,G.jsx)(Al,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:()=>b(e.id),className:`p-1 text-bambu-gray hover:text-red-600 dark:hover:text-red-400`,title:n(`common.delete`),children:(0,G.jsx)(Pu,{className:`w-4 h-4`})})]},e.id)})})})]})})]})}function T5({onClose:e,leftPreset:t,rightPreset:n,leftLabel:r,rightLabel:i,t:a}){let[o,s]=(0,y.useState)(`changes`),[c,l]=(0,y.useState)(``),u=(0,y.useMemo)(()=>{let e=new Set([...Object.keys(t),...Object.keys(n)]),r=[];for(let i of e){if(i===`inherits`||i===`version`)continue;let e=t[i],a=n[i],o=i in t,s=i in n,c;c=!o&&s?`added`:o&&!s?`removed`:JSON.stringify(e)===JSON.stringify(a)?`same`:`changed`,r.push({key:i,left:e,right:a,status:c})}return r.sort((e,t)=>{let n={changed:0,added:1,removed:2,same:3};return n[e.status]===n[t.status]?e.key.localeCompare(t.key):n[e.status]-n[t.status]})},[t,n]),d=(0,y.useMemo)(()=>{let e=[...u];if(o===`changes`&&(e=e.filter(e=>e.status!==`same`)),c){let t=c.toLowerCase();e=e.filter(e=>e.key.toLowerCase().includes(t)||String(e.left).toLowerCase().includes(t)||String(e.right).toLowerCase().includes(t))}return e},[u,o,c]),f=(0,y.useMemo)(()=>({added:u.filter(e=>e.status===`added`).length,removed:u.filter(e=>e.status===`removed`).length,changed:u.filter(e=>e.status===`changed`).length,same:u.filter(e=>e.status===`same`).length}),[u]),p=e=>{if(e===void 0)return`—`;if(e===null)return`null`;if(Array.isArray(e))return e.length===0?`[]`:e.length===1?String(e[0]):e.join(`, `);if(typeof e==`object`)return JSON.stringify(e);let t=String(e);if(t.includes(`\\n`)||t.length>100){let e=t.split(`\\n`).length;if(e>1)return`[${e} lines of G-code/script]`;if(t.length>100)return t.substring(0,100)+`…`}return t};return(0,y.useEffect)(()=>{let t=t=>{t.key===`Escape`&&e()};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e]),(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,G.jsx)(zd,{className:`w-full max-w-4xl max-h-[85vh] flex flex-col overflow-hidden`,children:(0,G.jsxs)(Vd,{className:`p-0 flex flex-col min-h-0 flex-1`,children:[(0,G.jsxs)(`div`,{className:`flex-shrink-0 flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(Oc,{className:`w-5 h-5 text-blue-600 dark:text-blue-400`}),a(`profiles.diff.title`)]}),(0,G.jsx)(`button`,{onClick:e,className:`text-bambu-gray hover:text-white`,children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]}),(0,G.jsxs)(`div`,{className:`flex-shrink-0 grid grid-cols-2 gap-4 p-4 border-b border-bambu-dark-tertiary bg-bambu-dark`,children:[(0,G.jsxs)(`div`,{className:`text-center`,children:[(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:a(`profiles.diff.left`)}),(0,G.jsx)(`p`,{className:`text-white font-medium truncate`,children:r})]}),(0,G.jsxs)(`div`,{className:`text-center`,children:[(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:a(`profiles.diff.right`)}),(0,G.jsx)(`p`,{className:`text-white font-medium truncate`,children:i})]})]}),(0,G.jsxs)(`div`,{className:`flex-shrink-0 flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-4 text-sm`,children:[(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-green-700 dark:text-green-400`,children:[(0,G.jsx)(Fl,{className:`w-3.5 h-3.5`}),f.added,` `,a(`profiles.diff.added`)]}),(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-red-700 dark:text-red-400`,children:[(0,G.jsx)(ml,{className:`w-3.5 h-3.5`}),f.removed,` `,a(`profiles.diff.removed`)]}),(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-amber-700 dark:text-amber-400`,children:[(0,G.jsx)(zo,{className:`w-3.5 h-3.5`}),f.changed,` `,a(`profiles.diff.changed`)]}),(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-bambu-gray`,children:[(0,G.jsx)(tc,{className:`w-3.5 h-3.5`}),f.same,` `,a(`profiles.diff.same`)]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(Ql,{className:`absolute left-2 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,G.jsx)(`input`,{type:`text`,value:c,onChange:e=>l(e.target.value),placeholder:a(`profiles.diff.searchFields`),className:`pl-8 pr-3 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none w-48`})]}),f.same>0&&(0,G.jsxs)(`div`,{className:`flex rounded overflow-hidden border border-bambu-dark-tertiary`,children:[(0,G.jsx)(`button`,{onClick:()=>s(`changes`),className:`px-3 py-1.5 text-sm transition-colors ${o===`changes`?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white`}`,children:a(`profiles.diff.changes`)}),(0,G.jsx)(`button`,{onClick:()=>s(`all`),className:`px-3 py-1.5 text-sm transition-colors ${o===`all`?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white`}`,children:a(`common.all`)})]})]})]}),(0,G.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto`,children:d.length===0?(0,G.jsxs)(`div`,{className:`text-center py-12 text-bambu-gray`,children:[(0,G.jsx)(tc,{className:`w-12 h-12 mx-auto mb-4 opacity-30`}),(0,G.jsx)(`p`,{children:a(o===`changes`?`profiles.diff.noDifferences`:`profiles.diff.noFieldsMatch`)})]}):(0,G.jsxs)(`table`,{className:`w-full`,children:[(0,G.jsx)(`thead`,{className:`sticky top-0 bg-bambu-dark-secondary`,children:(0,G.jsxs)(`tr`,{className:`text-sm text-bambu-gray border-b border-bambu-dark-tertiary`,children:[(0,G.jsx)(`th`,{className:`text-left p-3 w-1/3`,children:a(`profiles.diff.field`)}),(0,G.jsx)(`th`,{className:`text-left p-3 w-1/3`,children:r}),(0,G.jsx)(`th`,{className:`text-left p-3 w-1/3`,children:i})]})}),(0,G.jsx)(`tbody`,{children:d.map(e=>{let t={added:`bg-green-500/10`,removed:`bg-red-500/10`,changed:`bg-amber-500/10`,same:``}[e.status],n={added:(0,G.jsx)(Fl,{className:`w-3.5 h-3.5 text-green-600 dark:text-green-400`}),removed:(0,G.jsx)(ml,{className:`w-3.5 h-3.5 text-red-600 dark:text-red-400`}),changed:(0,G.jsx)(zo,{className:`w-3.5 h-3.5 text-amber-600 dark:text-amber-400`}),same:(0,G.jsx)(tc,{className:`w-3.5 h-3.5 text-bambu-gray-dark`})}[e.status];return(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary ${t}`,children:[(0,G.jsx)(`td`,{className:`p-3`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[n,(0,G.jsx)(`span`,{className:`text-sm text-white font-mono`,children:e.key})]})}),(0,G.jsx)(`td`,{className:`p-3`,children:(0,G.jsx)(`span`,{className:`text-sm font-mono break-all ${e.status===`removed`?`text-red-700 dark:text-red-300`:e.status===`changed`?`text-white`:`text-bambu-gray`}`,children:p(e.left)})}),(0,G.jsx)(`td`,{className:`p-3`,children:(0,G.jsx)(`span`,{className:`text-sm font-mono break-all ${e.status===`added`?`text-green-700 dark:text-green-300`:e.status===`changed`?`text-white`:`text-bambu-gray`}`,children:p(e.right)})})]},e.key)})})]})})]})})})}function bKe({onClose:e,initialData:t,allPresets:n,t:r}){let{showToast:i}=qd(),a=co(),o=!!t?.setting_id,[s,c]=(0,y.useState)(`common`),[l,u]=(0,y.useState)(t?.type||`filament`),[d,f]=(0,y.useState)(t?.name?o?t.name:`${t.name} (Copy)`:``),[p,m]=(0,y.useState)(t?.base_id||``),[h,g]=(0,y.useState)(``),[_,v]=(0,y.useState)(t?.setting||{inherits:``}),[b,x]=(0,y.useState)(JSON.stringify(t?.setting||{inherits:``},null,2)),[S,C]=(0,y.useState)(null),[w,T]=(0,y.useState)(``),[E,D]=(0,y.useState)(!1),[O,k]=(0,y.useState)(``),[A,j]=(0,y.useState)(!1),[M,N]=(0,y.useState)(C5),[P,F]=(0,y.useState)(!1),[I,L]=(0,y.useState)(``),[R,z]=(0,y.useState)(``),[B,V]=(0,y.useState)(!0),[ee,te]=(0,y.useState)(null),[ne,re]=(0,y.useState)(!1),ie=(0,y.useMemo)(()=>({filament:n.filament,print:n.process,printer:n.printer})[l]||[],[n,l]),ae=(0,y.useMemo)(()=>ie.filter(e=>y5(e.setting_id)),[ie]),{data:oe}=K({queryKey:[`cloudFields`,l],queryFn:()=>Z.getCloudFields(l===`print`?`process`:l),staleTime:1e3*60*60}),{data:se}=K({queryKey:[`allPresetDetails`,l,ae.map(e=>e.setting_id).join(`,`)],queryFn:async()=>{let e={};for(let t=0;t{try{let t=await Z.getCloudSettingDetail(e.setting_id);return{id:e.setting_id,detail:t}}catch{return null}}))).forEach(t=>{t&&(e[t.id]=t.detail)})}return e},enabled:ae.length>0,staleTime:1e3*60*10}),{data:H,isLoading:ce}=K({queryKey:[`cloudSettingDetail`,p],queryFn:()=>Z.getCloudSettingDetail(p),enabled:!!p});(0,y.useEffect)(()=>{s!==`json`&&x(JSON.stringify(_,null,2))},[_,s]);let le=(0,y.useMemo)(()=>({filament:n.filament,print:n.process,printer:n.printer}[l]||[]).filter(e=>!y5(e.setting_id)).sort((e,t)=>e.name.localeCompare(t.name)),[n,l]);(0,y.useEffect)(()=>{if(!p)return;let e=le.find(e=>e.setting_id===p);e&&(g(e.name),o||(v({inherits:e.name}),x(JSON.stringify({inherits:e.name},null,2))))},[p,le,o]);let ue=(0,y.useMemo)(()=>{let e=oe?.fields||[],t=new Set(e.map(e=>e.key)),n=new Set,i=new Set([`inherits`,`updated_time`,`compatible_printers`,`compatible_prints`]);se&&Object.values(se).forEach(e=>{e?.setting&&Object.keys(e.setting).forEach(e=>{!t.has(e)&&!i.has(e)&&n.add(e)})}),Object.keys(_).forEach(e=>{!t.has(e)&&!i.has(e)&&n.add(e)});let a=Array.from(n).sort().map(e=>({key:e,label:e.replace(/_/g,` `).replace(/\b\w/g,e=>e.toUpperCase()),type:`text`,category:`discovered`,description:r(`profiles.presets.discoveredFromPresets`)}));return[...e,...a]},[oe,se,_,r]),de=ue.filter(e=>e.label.toLowerCase().includes(w.toLowerCase())||e.key.toLowerCase().includes(w.toLowerCase())),fe=()=>{if(O.trim()){let e=O.trim().toLowerCase().replace(/\s+/g,`_`);pe(e,``),k(``),j(!1),i(r(`profiles.presets.toast.fieldAdded`,{key:e}))}},pe=(e,t)=>{v(n=>{let r={...n};return t===``||t===void 0?delete r[e]:r[e]=t,r})},me=e=>{v(t=>({...t,...e.settings})),te(e.name),i(r(`profiles.templates.toast.applied`))},he=()=>{if(!I.trim())return;let e={..._};if(delete e.inherits,Object.keys(e).length===0){i(r(`profiles.presets.noOverridesToSave`),`error`);return}let t={id:Date.now().toString(),name:I.trim(),description:R.trim()||r(`profiles.presets.customTemplate`),type:l,settings:e,showInModal:B},n=[...M,t];N(n),w5(n),F(!1),L(``),z(``),V(!0),i(r(`profiles.templates.toast.created`))},ge=(0,y.useMemo)(()=>M.filter(e=>e.type===l&&e.showInModal),[l,M]),_e=e=>{x(e);try{v(JSON.parse(e)),C(null)}catch(e){C(e.message)}},ve=e=>{e.preventDefault(),D(!1);let t=e.dataTransfer.files[0];if(t&&t.name.endsWith(`.json`)){let e=new FileReader;e.onload=e=>{try{let t=e.target?.result,n=JSON.parse(t),a=n.setting||n;v(e=>({...e,...a})),x(JSON.stringify({..._,...a},null,2)),i(r(`profiles.presets.fileImported`))}catch{i(r(`profiles.presets.invalidJsonFile`),`error`)}},e.readAsText(t)}},ye=q({mutationFn:()=>{let e={..._},t=l===`filament`?`filament_settings_id`:l===`print`?`print_settings_id`:`printer_settings_id`;e[t]=`"${d}"`;let n={type:l,name:d,base_id:p,setting:e};return Z.createCloudSetting(n)},onSuccess:async()=>{i(r(`profiles.presets.toast.created`)),await a.refetchQueries({queryKey:[`cloudSettings`]}),e()},onError:e=>i(e.message,`error`)}),be=q({mutationFn:()=>{if(!t?.setting_id)throw Error(r(`profiles.presets.noSettingId`));return Z.updateCloudSetting(t.setting_id,{name:d,setting:_})},onSuccess:async()=>{i(r(`profiles.presets.toast.updated`)),a.removeQueries({queryKey:[`cloudSettingDetail`]}),await a.refetchQueries({queryKey:[`cloudSettings`]}),e()},onError:e=>i(e.message,`error`)}),xe=o?be:ye,Se=H?.setting?.inherits,Ce=Se?le.find(e=>e.name===Se):void 0,{data:we}=K({queryKey:[`cloudSettingDetail`,Ce?.setting_id],queryFn:()=>Z.getCloudSettingDetail(Ce.setting_id),enabled:!!Ce?.setting_id}),Te=(0,y.useMemo)(()=>{let e=we?.setting||{},t=H?.setting||{},n=p&&se?.[p]?.setting?se[p].setting:{};return{...e,...t,...n}},[p,H,we,se]),Ee=e=>{if(e==null)return``;if(Array.isArray(e)){let t=[...new Set(e.map(e=>String(e)))];return t.length===1?t[0]:e.join(`, `)}return String(e)},De=e=>{let t=_[e.key],n=Te[e.key],i=Ee(n),a=ce?r(`common.loading`):i||``,o=`w-full px-3 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`;if(e.type===`boolean`){let r=t===`1`||t===void 0&&n===`1`;return(0,G.jsx)(`button`,{type:`button`,onClick:()=>pe(e.key,t===`1`?`0`:`1`),className:`w-8 h-5 rounded-full transition-colors ${r?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,children:(0,G.jsx)(`div`,{className:`w-4 h-4 rounded-full bg-white shadow transition-transform ${r?`translate-x-3.5`:`translate-x-0.5`}`})})}return e.type===`select`?(0,G.jsxs)(`select`,{value:t||``,onChange:t=>pe(e.key,t.target.value),className:o,children:[(0,G.jsx)(`option`,{value:``,children:a}),e.options?.map(e=>(0,G.jsx)(`option`,{value:e.value,children:e.label},e.value))]}):(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`input`,{type:e.type===`number`?`number`:`text`,value:t===void 0?``:String(t),onChange:t=>pe(e.key,t.target.value),step:e.step,min:e.min,max:e.max,placeholder:a,className:o}),e.unit&&(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:e.unit})]})},Oe=(0,y.useMemo)(()=>H?.setting?H.setting:{},[H]);return(0,G.jsxs)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,onDragOver:e=>{e.preventDefault(),D(!0)},onDragLeave:()=>D(!1),onDrop:ve,children:[ne&&p&&(0,G.jsx)(T5,{onClose:()=>re(!1),leftPreset:Oe,rightPreset:_,leftLabel:r(`profiles.presets.baseLabel`,{name:h||p}),rightLabel:r(`profiles.presets.currentLabel`,{name:d||r(`profiles.presets.newPreset`)}),t:r}),(0,G.jsx)(zd,{className:`w-full max-w-6xl max-h-[90vh] flex flex-col overflow-y-auto`,children:(0,G.jsxs)(Vd,{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.jsxs)(`div`,{children:[(0,G.jsx)(`h2`,{className:`text-xl font-semibold text-white`,children:r(o?`profiles.presets.editPreset`:t?`profiles.presets.duplicatePreset`:`profiles.presets.createNewPreset`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:r(`profiles.presets.customizeSettings`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[p&&(0,G.jsxs)(`button`,{onClick:()=>re(!0),className:`flex items-center gap-2 px-3 py-2 text-sm text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary rounded-lg transition-colors`,title:r(`profiles.presets.compareWithBase`),children:[(0,G.jsx)(Oc,{className:`w-4 h-4`}),r(`profiles.presets.compare`)]}),(0,G.jsx)(`button`,{onClick:e,className:`p-2 text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary rounded-lg transition-colors`,children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]})]}),E&&(0,G.jsx)(`div`,{className:`absolute inset-0 bg-bambu-green/10 border-2 border-dashed border-bambu-green rounded-lg flex items-center justify-center z-10`,children:(0,G.jsxs)(`div`,{className:`text-center`,children:[(0,G.jsx)(Vu,{className:`w-12 h-12 text-bambu-green mx-auto mb-2`}),(0,G.jsx)(`p`,{className:`text-bambu-green font-medium`,children:r(`profiles.presets.dropJsonToImport`)})]})}),(0,G.jsxs)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary space-y-3`,children:[(0,G.jsxs)(`div`,{className:`grid grid-cols-3 gap-4 max-[640px]:grid-cols-1`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`common.type`)}),(0,G.jsxs)(`select`,{value:l,onChange:e=>{u(e.target.value),m(``)},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:`filament`,children:r(`profiles.presets.types.filament`)}),(0,G.jsx)(`option`,{value:`print`,children:r(`profiles.presets.types.process`)}),(0,G.jsx)(`option`,{value:`printer`,children:r(`profiles.presets.types.printer`)})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`profiles.presets.basePreset`)}),(0,G.jsxs)(`select`,{value:p,onChange:e=>m(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,children:[(0,G.jsx)(`option`,{value:``,children:r(`profiles.presets.selectBasePreset`)}),le.map(e=>(0,G.jsx)(`option`,{value:e.setting_id,children:e.name},e.setting_id))]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`profiles.presets.presetName`)}),(0,G.jsx)(`input`,{type:`text`,value:d,onChange:e=>f(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,placeholder:r(`profiles.presets.myCustomPreset`)})]})]}),h&&(0,G.jsx)(`div`,{className:`text-xs text-bambu-gray`,children:(0,G.jsxs)(`p`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(fs,{className:`w-3 h-3 text-bambu-green`}),r(`profiles.presets.inheritsFrom`),` `,(0,G.jsx)(`span`,{className:`text-white`,children:h}),ce&&(0,G.jsx)(Y,{className:`w-3 h-3 animate-spin ml-1`})]})})]}),(0,G.jsxs)(`div`,{className:`flex border-b border-bambu-dark-tertiary max-[640px]:flex-wrap max-[640px]:items-center`,children:[(0,G.jsxs)(`button`,{onClick:()=>c(`common`),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${s===`common`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-white border-transparent`}`,children:[(0,G.jsx)(pu,{className:`w-4 h-4`}),r(`profiles.presets.tabs.common`)]}),(0,G.jsxs)(`button`,{onClick:()=>c(`fields`),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${s===`fields`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-white border-transparent`}`,children:[(0,G.jsx)(el,{className:`w-4 h-4`}),r(`profiles.presets.tabs.allFields`)]}),(0,G.jsxs)(`button`,{onClick:()=>c(`json`),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${s===`json`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-white border-transparent`}`,children:[(0,G.jsx)(Fs,{className:`w-4 h-4`}),`JSON`,S&&(0,G.jsx)(ys,{className:`w-3 h-3 text-red-600 dark:text-red-400`})]}),(0,G.jsx)(`div`,{className:`flex-1 max-[640px]:hidden`}),(0,G.jsxs)(`button`,{onClick:()=>{let e=new Blob([JSON.stringify({name:d,type:l,base_id:p,setting:_},null,2)],{type:`application/json`}),t=URL.createObjectURL(e),n=document.createElement(`a`);n.href=t,n.download=`${d||`preset`}.json`,document.body.appendChild(n),n.click(),document.body.removeChild(n),URL.revokeObjectURL(t),i(r(`profiles.presets.toast.exported`))},className:`flex items-center gap-2 px-4 py-3 text-sm text-bambu-gray hover:text-white transition-colors`,title:r(`profiles.presets.exportToJson`),children:[(0,G.jsx)(Xs,{className:`w-4 h-4`}),r(`common.download`)]}),(0,G.jsxs)(`button`,{onClick:()=>document.getElementById(`file-import`)?.click(),className:`flex items-center gap-2 px-4 py-3 text-sm text-bambu-gray hover:text-white transition-colors`,title:r(`profiles.presets.importFromJson`),children:[(0,G.jsx)(Vu,{className:`w-4 h-4`}),r(`common.upload`)]}),(0,G.jsx)(`input`,{id:`file-import`,type:`file`,accept:`.json`,className:`hidden`,onChange:e=>{let t=e.target.files?.[0];if(t){let e=new FileReader;e.onload=e=>{try{let t=JSON.parse(e.target?.result),n=t.setting||t;v(e=>({...e,...n})),i(r(`profiles.presets.fileImported`))}catch{i(r(`profiles.presets.invalidJson`),`error`)}},e.readAsText(t)}}})]}),(0,G.jsxs)(`div`,{className:`flex-1 p-4`,children:[s===`common`&&(0,G.jsxs)(`div`,{className:`space-y-6`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,G.jsxs)(`h3`,{className:`text-sm font-medium text-white flex items-center gap-2`,children:[(0,G.jsx)(_u,{className:`w-4 h-4 text-amber-600 dark:text-amber-400`}),r(`profiles.templates.title`)]}),Object.keys(_).filter(e=>e!==`inherits`).length>0&&(0,G.jsxs)(`button`,{onClick:()=>F(!P),className:`text-xs text-bambu-gray hover:text-white flex items-center gap-1 transition-colors`,children:[(0,G.jsx)(ql,{className:`w-3 h-3`}),r(`profiles.presets.saveAsTemplate`)]})]}),P&&(0,G.jsxs)(`div`,{className:`mb-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-2 mb-2`,children:[(0,G.jsx)(`input`,{type:`text`,value:I,onChange:e=>L(e.target.value),placeholder:r(`profiles.templates.namePlaceholder`),className:`px-3 py-1.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`,autoFocus:!0}),(0,G.jsx)(`input`,{type:`text`,value:R,onChange:e=>z(e.target.value),placeholder:r(`profiles.templates.descriptionPlaceholder`),className:`px-3 py-1.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsxs)(Q,{size:`sm`,onClick:he,disabled:!I.trim(),children:[(0,G.jsx)(ql,{className:`w-3 h-3`}),r(`common.save`)]}),(0,G.jsx)(Q,{size:`sm`,variant:`secondary`,onClick:()=>F(!1),children:r(`common.cancel`)})]}),(0,G.jsxs)(`button`,{onClick:()=>V(!B),className:`flex items-center gap-1.5 text-xs transition-colors ${B?`text-bambu-green`:`text-bambu-gray hover:text-white`}`,children:[B?(0,G.jsx)(ac,{className:`w-3.5 h-3.5`}):(0,G.jsx)(ic,{className:`w-3.5 h-3.5`}),r(B?`profiles.templates.shownInModals`:`profiles.templates.hiddenInModals`)]})]})]}),ee&&(0,G.jsxs)(`div`,{className:`mb-3 px-3 py-2 bg-bambu-green/10 border border-bambu-green/30 rounded-lg flex items-center gap-2`,children:[(0,G.jsx)(fs,{className:`w-4 h-4 text-bambu-green`}),(0,G.jsxs)(`span`,{className:`text-sm text-bambu-green`,children:[r(`profiles.presets.templateApplied`),` `,(0,G.jsx)(`span`,{className:`font-medium`,children:ee})]}),(0,G.jsx)(`button`,{onClick:()=>te(null),className:`ml-auto text-bambu-green/70 hover:text-bambu-green`,children:(0,G.jsx)(nd,{className:`w-4 h-4`})})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-3 gap-2`,children:[ge.map(e=>(0,G.jsxs)(`button`,{onClick:()=>me(e),className:`p-3 text-left bg-bambu-dark border border-bambu-dark-tertiary rounded-lg hover:border-bambu-gray-dark transition-colors`,children:[(0,G.jsx)(`p`,{className:`text-sm font-medium text-white`,children:e.name}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e.description})]},e.id)),ge.length===0&&(0,G.jsx)(`p`,{className:`col-span-3 text-center text-bambu-gray text-sm py-4`,children:r(`profiles.presets.noTemplatesSelected`)})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray-dark mt-2 text-center`,children:r(`profiles.presets.manageTemplatesHint`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`text-sm font-medium text-white mb-3`,children:r(`profiles.presets.commonSettings`)}),(0,G.jsx)(`div`,{className:`grid grid-cols-2 gap-x-6 gap-y-3`,children:ue.slice(0,10).map(e=>(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-4 max-[640px]:flex-col max-[640px]:items-start`,children:[(0,G.jsx)(`label`,{className:`text-sm text-bambu-gray flex-shrink-0`,children:e.label}),(0,G.jsx)(`div`,{className:`w-48 max-[640px]:w-full`,children:De(e)})]},e.key))})]}),Object.keys(_).length>1&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`text-sm font-medium text-white mb-3`,children:r(`profiles.presets.currentOverrides`)}),(0,G.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:Object.entries(_).filter(([e])=>e!==`inherits`).map(([e,t])=>(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-2 py-1 bg-bambu-green/10 text-bambu-green text-xs rounded`,children:[e,`: `,String(t).slice(0,20),(0,G.jsx)(`button`,{onClick:()=>pe(e,void 0),className:`hover:text-white`,children:(0,G.jsx)(nd,{className:`w-3 h-3`})})]},e))})]})]}),s===`fields`&&(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-6`,style:{height:`400px`},children:[(0,G.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-3 flex-shrink-0`,children:[(0,G.jsx)(`h3`,{className:`text-sm font-medium text-white`,children:r(`profiles.presets.availableFields`)}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:se?r(`profiles.templates.fieldsCount`,{count:ue.length}):r(`common.loading`)})]}),(0,G.jsxs)(`div`,{className:`relative mb-3 flex-shrink-0`,children:[(0,G.jsx)(Ql,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,G.jsx)(`input`,{type:`text`,value:w,onChange:e=>T(e.target.value),placeholder:r(`profiles.presets.searchFieldsPlaceholder`),className:`w-full pl-10 pr-4 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none`})]}),(0,G.jsxs)(`div`,{className:`flex-1 overflow-y-auto space-y-1 pr-2 min-h-0`,children:[de.filter(e=>!(e.key in _)).map(e=>{let t=Te[e.key],n=Ee(t);return(0,G.jsxs)(`div`,{onClick:()=>{v(t=>({...t,[e.key]:n||``}))},className:`flex items-center justify-between gap-2 p-2 rounded-lg hover:bg-bambu-dark-tertiary transition-colors cursor-pointer group`,children:[(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,G.jsx)(`p`,{className:`text-sm text-white truncate`,children:e.label}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray-dark truncate`,children:e.key})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[n&&(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray bg-bambu-dark px-2 py-0.5 rounded max-w-32 truncate`,title:n,children:[n.slice(0,20),n.length>20?`...`:``]}),(0,G.jsx)(`div`,{className:`w-6 h-6 flex items-center justify-center rounded bg-bambu-dark-tertiary group-hover:bg-bambu-green/20 transition-colors`,children:(0,G.jsx)(Fl,{className:`w-4 h-4 text-bambu-gray group-hover:text-bambu-green transition-colors`})})]})]},e.key)}),de.filter(e=>!(e.key in _)).length===0&&(0,G.jsx)(`p`,{className:`text-center text-bambu-gray py-4 text-sm`,children:r(w?`profiles.presets.noMatchingFields`:`profiles.presets.allFieldsAdded`)})]}),(0,G.jsx)(`div`,{className:`pt-3 mt-3 border-t border-bambu-dark-tertiary flex-shrink-0`,children:A?(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsx)(`input`,{type:`text`,value:O,onChange:e=>k(e.target.value),onKeyDown:e=>e.key===`Enter`&&fe(),placeholder:`custom_field_name`,className:`flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white font-mono text-sm placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none`,autoFocus:!0}),(0,G.jsx)(Q,{size:`sm`,onClick:fe,disabled:!O.trim(),children:(0,G.jsx)(Fl,{className:`w-4 h-4`})}),(0,G.jsx)(Q,{size:`sm`,variant:`secondary`,onClick:()=>{j(!1),k(``)},children:(0,G.jsx)(nd,{className:`w-4 h-4`})})]}):(0,G.jsxs)(`button`,{onClick:()=>j(!0),className:`w-full flex items-center justify-center gap-2 p-2 text-sm text-bambu-gray hover:text-white border border-dashed border-bambu-dark-tertiary hover:border-bambu-gray-dark rounded-lg transition-colors`,children:[(0,G.jsx)(Fl,{className:`w-4 h-4`}),r(`profiles.presets.addCustomField`)]})})]}),(0,G.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-3 flex-shrink-0`,children:[(0,G.jsx)(`h3`,{className:`text-sm font-medium text-white`,children:r(`profiles.presets.yourOverrides`)}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:r(`profiles.templates.fieldsCount`,{count:Object.keys(_).filter(e=>e!==`inherits`).length})})]}),(0,G.jsxs)(`div`,{className:`flex-1 overflow-y-auto space-y-2 pr-2 min-h-0`,children:[Object.entries(_).filter(([e])=>e!==`inherits`).map(([e,t])=>{let n=ue.find(t=>t.key===e);return(0,G.jsxs)(`div`,{className:`p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm font-medium text-white`,children:n?.label||e}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray-dark`,children:e})]}),(0,G.jsx)(`button`,{onClick:()=>pe(e,void 0),className:`p-1 text-bambu-gray hover:text-red-600 dark:hover:text-red-400 transition-colors`,children:(0,G.jsx)(nd,{className:`w-4 h-4`})})]}),n?De(n):(0,G.jsx)(`input`,{type:`text`,value:String(t),onChange:t=>pe(e,t.target.value),className:`w-full px-3 py-1.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`})]},e)}),Object.keys(_).filter(e=>e!==`inherits`).length===0&&(0,G.jsxs)(`div`,{className:`text-center py-8 text-bambu-gray`,children:[(0,G.jsx)(pu,{className:`w-8 h-8 mx-auto mb-2 opacity-50`}),(0,G.jsx)(`p`,{className:`text-sm`,children:r(`profiles.presets.noOverridesYet`)}),(0,G.jsx)(`p`,{className:`text-xs mt-1`,children:r(`profiles.presets.clickFieldsToAdd`)})]})]}),Object.keys(_).filter(e=>e!==`inherits`).length>0&&(0,G.jsx)(`div`,{className:`pt-3 mt-3 border-t border-bambu-dark-tertiary flex-shrink-0`,children:(0,G.jsxs)(`button`,{onClick:()=>{F(!0),c(`common`)},className:`w-full flex items-center justify-center gap-2 p-2 text-sm text-bambu-gray hover:text-white border border-dashed border-bambu-dark-tertiary hover:border-bambu-gray-dark rounded-lg transition-colors`,children:[(0,G.jsx)(ql,{className:`w-4 h-4`}),r(`profiles.presets.saveAsTemplate`)]})})]})]}),s===`json`&&(0,G.jsxs)(`div`,{className:`space-y-2`,children:[S&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-red-700 dark:text-red-400 text-sm`,children:[(0,G.jsx)(ys,{className:`w-4 h-4`}),S]}),(0,G.jsx)(`textarea`,{value:b,onChange:e=>_e(e.target.value),className:`w-full h-80 px-3 py-2 bg-bambu-dark border rounded-lg text-white text-xs font-mono focus:outline-none resize-none ${S?`border-red-500 focus:border-red-500`:`border-bambu-dark-tertiary focus:border-bambu-green`}`,spellCheck:!1}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:r(`profiles.presets.jsonTip`)})]})]}),(0,G.jsxs)(`div`,{className:`p-4 border-t border-bambu-dark-tertiary flex gap-2`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:e,className:`flex-1`,children:r(`common.cancel`)}),(0,G.jsxs)(Q,{onClick:()=>xe.mutate(),disabled:xe.isPending||!d.trim()||!o&&!p||!!S,className:`flex-1`,children:[xe.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):o?(0,G.jsx)(ql,{className:`w-4 h-4`}):(0,G.jsx)(Fl,{className:`w-4 h-4`}),r(o?`common.save`:t?`common.duplicate`:`common.create`)]})]})]})})]})}function xKe({settings:e,lastSyncTime:t,onRefresh:n,isRefreshing:r,printers:i,hasPermission:a,t:o}){let[s,c]=(0,y.useState)(``),[l,u]=(0,y.useState)(`all`),[d,f]=(0,y.useState)(`all`),[p,m]=(0,y.useState)(`all`),[h,g]=(0,y.useState)(`all`),[_,v]=(0,y.useState)(`all`),[b,x]=(0,y.useState)(`all`),[S,C]=(0,y.useState)(null),[w,T]=(0,y.useState)(!1),[E,D]=(0,y.useState)(!1),[O,k]=(0,y.useState)(null),[A,j]=(0,y.useState)(null),[M,N]=(0,y.useState)(null),[P,F]=(0,y.useState)(!1),[I,L]=(0,y.useState)([null,null]),[R,z]=(0,y.useState)(!1),[B,V]=(0,y.useState)(null),ee=co(),te=(0,y.useMemo)(()=>[...e.filament.map(e=>({...e,type:`filament`})),...e.printer.map(e=>({...e,type:`printer`})),...e.process.map(e=>({...e,type:`process`}))].map(e=>({...e,meta:v5(e.name)})),[e]),ne=(0,y.useMemo)(()=>{let e=new Set,t=new Set,n=new Set;return te.forEach(r=>{r.meta.nozzle&&e.add(r.meta.nozzle),r.meta.filamentType&&t.add(r.meta.filamentType),r.meta.layerHeight&&n.add(r.meta.layerHeight)}),{printers:i.map(e=>({id:e.id.toString(),name:e.name})),nozzles:Array.from(e).sort((e,t)=>parseFloat(e)-parseFloat(t)),filaments:Array.from(t).sort(),layerHeights:Array.from(n).sort((e,t)=>parseFloat(e)-parseFloat(t))}},[te,i]),re=(0,y.useMemo)(()=>p===`all`?null:i.find(e=>e.id.toString()===p)?.model||null,[p,i]),ie=(0,y.useMemo)(()=>te.filter(e=>l===`all`||e.type===l).filter(e=>{if(d===`all`)return!0;let t=y5(e.setting_id);return d===`custom`?t:!t}).filter(e=>{if(p===`all`||!re)return!0;let t=e.meta.printer?.toLowerCase()||``,n=re.toLowerCase();return t.includes(n)||n.includes(t)}).filter(e=>h===`all`||e.meta.nozzle===h).filter(e=>_===`all`||e.meta.filamentType===_).filter(e=>b===`all`||e.meta.layerHeight===b).filter(e=>s===``||e.name.toLowerCase().includes(s.toLowerCase())).sort((e,t)=>e.name.localeCompare(t.name)),[te,l,d,p,re,h,_,b,s]),ae=e=>{if(P){let t=I[0]?.setting_id===e.setting_id,n=I[1]?.setting_id===e.setting_id;if(t)L([I[1],null]);else if(n)L([I[0],null]);else if(!I[0])L([e,null]);else if(I[1]){if(I[0].type!==e.type)return;L([I[0],e])}else{if(I[0].type!==e.type)return;L([I[0],e])}}else C(e)},oe=e=>{if(I[0]?.setting_id===e.setting_id)return 0;if(I[1]?.setting_id===e.setting_id)return 1},se=async e=>{try{let t=await Z.getCloudSettingDetail(e.setting_id);k({type:e.type===`process`?`print`:e.type,name:e.name,base_id:t.base_id||`GFSA00`,setting:t.setting||{}}),C(null)}catch(e){console.error(`Failed to fetch preset details for duplication:`,e)}},H=async e=>{try{ee.removeQueries({queryKey:[`cloudSettingDetail`,e.setting_id]});let t=await Z.getCloudSettingDetail(e.setting_id);j({type:e.type===`process`?`print`:e.type,name:e.name,base_id:t.base_id||`GFSA00`,setting:t.setting||{},setting_id:e.setting_id}),C(null)}catch(e){console.error(`Failed to fetch preset details for editing:`,e)}},ce=()=>{u(`all`),f(`all`),m(`all`),g(`all`),v(`all`),x(`all`),c(``)},le=l!==`all`||d!==`all`||p!==`all`||h!==`all`||_!==`all`||b!==`all`||s!==``,ue=e.filament.length+e.printer.length+e.process.length;return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`space-y-4 mb-6`,children:[(0,G.jsxs)(`div`,{className:`flex flex-col sm:flex-row gap-3`,children:[(0,G.jsxs)(`div`,{className:`relative flex-1`,children:[(0,G.jsx)(Ql,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,G.jsx)(`input`,{type:`text`,value:s,onChange:e=>c(e.target.value),placeholder:o(`profiles.cloudView.searchPlaceholder`),className:`w-full pl-10 pr-4 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none`})]}),(0,G.jsxs)(`div`,{className:`flex gap-2 max-[550px]:flex-wrap max-[550px]:items-center`,children:[(0,G.jsxs)(Q,{variant:P?`primary`:`secondary`,onClick:()=>{P?(F(!1),L([null,null])):F(!0)},children:[(0,G.jsx)(Oc,{className:`w-4 h-4`}),o(P?`common.cancel`:`profiles.presets.compare`)]}),(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>D(!0),disabled:!a(`cloud:auth`),title:a(`cloud:auth`)?void 0:o(`profiles.cloudView.noTemplatesPermission`),children:[(0,G.jsx)(_u,{className:`w-4 h-4`}),o(`profiles.cloudView.templates`)]}),(0,G.jsxs)(Q,{variant:`secondary`,onClick:n,disabled:r||!a(`cloud:auth`),title:a(`cloud:auth`)?void 0:o(`profiles.cloudView.noRefreshPermission`),children:[(0,G.jsx)(Hl,{className:`w-4 h-4 ${r?`animate-spin`:``}`}),o(`profiles.cloudView.refresh`)]}),(0,G.jsxs)(Q,{onClick:()=>T(!0),disabled:!a(`cloud:auth`),title:a(`cloud:auth`)?void 0:o(`profiles.cloudView.noCreatePermission`),children:[(0,G.jsx)(Fl,{className:`w-4 h-4`}),o(`profiles.cloudView.newPreset`)]})]})]}),(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,G.jsx)(wc,{className:`w-4 h-4 text-bambu-gray`}),(0,G.jsx)(b5,{label:o(`profiles.cloudView.filters.type`),value:l,options:[{value:`all`,label:o(`profiles.cloudView.filters.all`),count:ue},{value:`filament`,label:o(`profiles.cloudView.filters.filament`),count:e.filament.length},{value:`printer`,label:o(`profiles.cloudView.filters.printer`),count:e.printer.length},{value:`process`,label:o(`profiles.cloudView.filters.process`),count:e.process.length}],onChange:e=>u(e)}),(0,G.jsx)(b5,{label:o(`profiles.cloudView.filters.owner`),value:d,options:[{value:`all`,label:o(`profiles.cloudView.filters.all`)},{value:`custom`,label:o(`profiles.cloudView.filters.myPresets`)},{value:`builtin`,label:o(`profiles.cloudView.filters.builtIn`)}],onChange:e=>f(e)}),ne.printers.length>0&&(0,G.jsx)(b5,{label:o(`profiles.cloudView.filters.printer`),value:p,options:[{value:`all`,label:o(`profiles.cloudView.filters.all`)},...ne.printers.map(e=>({value:e.id,label:e.name}))],onChange:m}),ne.nozzles.length>0&&(0,G.jsx)(b5,{label:o(`profiles.cloudView.filters.nozzle`),value:h,options:[{value:`all`,label:o(`profiles.cloudView.filters.all`)},...ne.nozzles.map(e=>({value:e,label:e}))],onChange:g}),ne.filaments.length>0&&(l===`all`||l===`filament`)&&(0,G.jsx)(b5,{label:o(`profiles.cloudView.filters.filament`),value:_,options:[{value:`all`,label:o(`profiles.cloudView.filters.all`)},...ne.filaments.map(e=>({value:e,label:e}))],onChange:v}),ne.layerHeights.length>0&&(l===`all`||l===`process`)&&(0,G.jsx)(b5,{label:o(`profiles.cloudView.filters.layer`),value:b,options:[{value:`all`,label:o(`profiles.cloudView.filters.all`)},...ne.layerHeights.map(e=>({value:e,label:e}))],onChange:x}),le&&(0,G.jsx)(`button`,{onClick:ce,className:`px-3 py-2 text-sm text-bambu-gray hover:text-white transition-colors`,children:o(`profiles.cloudView.clearFilters`)})]})]}),P&&(0,G.jsx)(`div`,{className:`mb-4 p-3 bg-blue-500/10 border border-blue-500/30 rounded-lg`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,G.jsx)(Oc,{className:`w-5 h-5 text-blue-600 dark:text-blue-400`}),(0,G.jsx)(`span`,{className:`text-white font-medium`,children:o(`profiles.cloudView.compareMode`)}),(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:I[0]?o(`profiles.cloudView.selectAnotherPreset`,{type:I[0].type}):o(`profiles.cloudView.clickTwoPresets`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`px-2 py-1 text-sm rounded truncate max-w-[200px] ${I[0]?`bg-blue-500/30 text-blue-700 dark:text-blue-300`:`bg-bambu-dark text-bambu-gray`}`,children:I[0]?I[0].name:o(`profiles.cloudView.selectFirst`)}),(0,G.jsx)(zo,{className:`w-4 h-4 text-bambu-gray`}),(0,G.jsx)(`span`,{className:`px-2 py-1 text-sm rounded truncate max-w-[200px] ${I[1]?`bg-blue-500/30 text-blue-700 dark:text-blue-300`:`bg-bambu-dark text-bambu-gray`}`,children:I[1]?I[1].name:o(`profiles.cloudView.selectSecond`)})]}),I[0]&&I[1]&&(0,G.jsxs)(Q,{size:`sm`,onClick:async()=>{try{let[e,t]=await Promise.all([Z.getCloudSettingDetail(I[0].setting_id),Z.getCloudSettingDetail(I[1].setting_id)]);V([e.setting||{},t.setting||{}]),z(!0)}catch{}},children:[(0,G.jsx)(Oc,{className:`w-4 h-4`}),o(`profiles.cloudView.compareNow`)]})]})]})}),(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4 mb-4 text-sm text-bambu-gray`,children:[t&&(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(js,{className:`w-3 h-3`}),o(`profiles.cloudView.lastSynced`),` `,up(t.toISOString(),`system`,o)]}),(0,G.jsx)(`span`,{children:o(`profiles.cloudView.showingCount`,{showing:ie.length,total:ue})}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-bambu-green`}),(0,G.jsxs)(`span`,{children:[`= `,o(`profiles.presets.myPreset`)]})]})]}),ie.length===0?(0,G.jsxs)(`div`,{className:`text-center py-16`,children:[(0,G.jsx)(Jc,{className:`w-12 h-12 text-bambu-gray-dark mx-auto mb-4`}),(0,G.jsx)(`p`,{className:`text-bambu-gray`,children:o(`profiles.cloudView.noPresetsFound`)}),le&&(0,G.jsx)(`button`,{onClick:ce,className:`mt-2 text-sm text-bambu-green hover:text-bambu-green-light`,children:o(`profiles.cloudView.clearFilters`)})]}):(0,G.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-6`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-3 px-1`,children:[(0,G.jsx)(Zs,{className:`w-4 h-4 text-amber-600 dark:text-amber-400`}),(0,G.jsx)(`h3`,{className:`text-sm font-medium text-bambu-gray`,children:o(`profiles.cloudView.columns.filament`)}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray-dark`,children:[`(`,ie.filter(e=>e.type===`filament`).length,`)`]})]}),(0,G.jsxs)(`div`,{className:`space-y-1 max-h-[calc(100vh-320px)] overflow-y-auto pr-1`,children:[ie.filter(e=>e.type===`filament`).map(e=>(0,G.jsx)(x5,{setting:e,onClick:()=>ae(e),onDuplicate:()=>se(e),compareMode:P,isCompareSelected:oe(e)!==void 0,compareIndex:oe(e),compareDisabled:P&&!!I[0]&&I[0].type!==e.type,t:o},e.setting_id)),ie.filter(e=>e.type===`filament`).length===0&&(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray-dark px-3 py-2`,children:o(`profiles.cloudView.noFilamentPresets`)})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-3 px-1`,children:[(0,G.jsx)(nu,{className:`w-4 h-4 text-blue-600 dark:text-blue-400`}),(0,G.jsx)(`h3`,{className:`text-sm font-medium text-bambu-gray`,children:o(`profiles.cloudView.columns.process`)}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray-dark`,children:[`(`,ie.filter(e=>e.type===`process`).length,`)`]})]}),(0,G.jsxs)(`div`,{className:`space-y-1 max-h-[calc(100vh-320px)] overflow-y-auto pr-1`,children:[ie.filter(e=>e.type===`process`).map(e=>(0,G.jsx)(x5,{setting:e,onClick:()=>ae(e),onDuplicate:()=>se(e),compareMode:P,isCompareSelected:oe(e)!==void 0,compareIndex:oe(e),compareDisabled:P&&!!I[0]&&I[0].type!==e.type,t:o},e.setting_id)),ie.filter(e=>e.type===`process`).length===0&&(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray-dark px-3 py-2`,children:o(`profiles.cloudView.noProcessPresets`)})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-3 px-1`,children:[(0,G.jsx)(Rl,{className:`w-4 h-4 text-purple-600 dark:text-purple-400`}),(0,G.jsx)(`h3`,{className:`text-sm font-medium text-bambu-gray`,children:o(`profiles.cloudView.columns.printer`)}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray-dark`,children:[`(`,ie.filter(e=>e.type===`printer`).length,`)`]})]}),(0,G.jsxs)(`div`,{className:`space-y-1 max-h-[calc(100vh-320px)] overflow-y-auto pr-1`,children:[ie.filter(e=>e.type===`printer`).map(e=>(0,G.jsx)(x5,{setting:e,onClick:()=>ae(e),onDuplicate:()=>se(e),compareMode:P,isCompareSelected:oe(e)!==void 0,compareIndex:oe(e),compareDisabled:P&&!!I[0]&&I[0].type!==e.type,t:o},e.setting_id)),ie.filter(e=>e.type===`printer`).length===0&&(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray-dark px-3 py-2`,children:o(`profiles.cloudView.noPrinterPresets`)})]})]})]}),S&&(0,G.jsx)(vKe,{setting:S,onClose:()=>C(null),onDeleted:()=>C(null),onDuplicate:()=>se(S),onEdit:()=>H(S),hasPermission:a,t:o}),(w||O||A||M)&&(0,G.jsx)(bKe,{onClose:()=>{T(!1),k(null),j(null),N(null)},initialData:A||O||(M?{type:M.type,name:``,base_id:``,setting:M.setting}:void 0),allPresets:e,t:o}),E&&(0,G.jsx)(yKe,{onClose:()=>D(!1),onApply:e=>{N({type:e.type,setting:e.settings}),D(!1)},t:o}),R&&B&&I[0]&&I[1]&&(0,G.jsx)(T5,{onClose:()=>{z(!1),V(null)},leftPreset:B[0],rightPreset:B[1],leftLabel:I[0].name,rightLabel:I[1].name,t:o})]})}function SKe(){let{t:e}=U(),t=co(),{showToast:n}=qd(),{hasPermission:r}=Nd(),[i,a]=(0,y.useState)(`cloud`),[o,s]=(0,y.useState)(),{data:c,isLoading:l}=K({queryKey:[`cloudStatus`],queryFn:Z.getCloudStatus}),{data:u=[]}=K({queryKey:[`printers`],queryFn:Z.getPrinters}),{data:d,isLoading:f,refetch:p,dataUpdatedAt:m}=K({queryKey:[`cloudSettings`],queryFn:()=>Z.getCloudSettings(),enabled:!!c?.is_authenticated,retry:!1,staleTime:1e3*60*5});(0,y.useEffect)(()=>{m&&s(new Date(m))},[m]);let h=q({mutationFn:Z.cloudLogout,onSuccess:()=>{t.invalidateQueries({queryKey:[`cloudStatus`]}),t.removeQueries({queryKey:[`cloudSettings`]}),n(e(`profiles.toast.loggedOut`))}});return l?(0,G.jsx)(`div`,{className:`p-4 md:p-8 flex items-center justify-center min-h-[400px]`,children:(0,G.jsx)(Y,{className:`w-8 h-8 text-bambu-green animate-spin`})}):(0,G.jsxs)(`div`,{className:`p-4 md:p-8`,children:[(0,G.jsxs)(`div`,{className:`mb-6`,children:[(0,G.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,G.jsx)(Ps,{className:`w-7 h-7 text-bambu-green`}),e(`profiles.title`)]}),(0,G.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:e(`profiles.subtitle`)})]}),(0,G.jsxs)(`div`,{className:`flex border-b border-bambu-dark-tertiary mb-6`,children:[(0,G.jsxs)(`button`,{onClick:()=>a(`cloud`),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${i===`cloud`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-white border-transparent`}`,children:[(0,G.jsx)(Ps,{className:`w-4 h-4`}),e(`profiles.tabs.bambuCloud`)]}),(0,G.jsxs)(`button`,{onClick:()=>a(`orca_cloud`),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${i===`orca_cloud`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-white border-transparent`}`,children:[(0,G.jsx)(Ps,{className:`w-4 h-4`}),e(`profiles.tabs.orcaCloud`)]}),(0,G.jsxs)(`button`,{onClick:()=>a(`local`),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${i===`local`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-white border-transparent`}`,children:[(0,G.jsx)(Pc,{className:`w-4 h-4`}),e(`profiles.tabs.local`)]}),(0,G.jsxs)(`button`,{onClick:()=>a(`kprofiles`),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${i===`kprofiles`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-white border-transparent`}`,children:[(0,G.jsx)(Tc,{className:`w-4 h-4`}),e(`profiles.tabs.kprofiles`)]})]}),i===`cloud`&&(0,G.jsxs)(G.Fragment,{children:[c?.is_authenticated&&(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-3 mb-6 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`w-2 h-2 rounded-full bg-bambu-green animate-pulse`}),(0,G.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[e(`profiles.connectedAs`),` `,(0,G.jsx)(`span`,{className:`text-white`,children:c.email}),c.region&&(0,G.jsx)(`span`,{className:`ml-2 px-2 py-0.5 text-xs rounded bg-bambu-dark-tertiary text-bambu-gray`,children:c.region===`china`?e(`profiles.login.regionChina`):e(`profiles.login.regionGlobal`)})]})]}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:()=>h.mutate(),disabled:h.isPending||!r(`cloud:auth`),title:r(`cloud:auth`)?void 0:e(`profiles.noLogoutPermission`),children:[(0,G.jsx)(il,{className:`w-4 h-4`}),e(`profiles.logout`)]})]}),c?.sign_in_expired&&(0,G.jsxs)(`div`,{className:`flex items-start gap-3 p-3 mb-6 rounded-lg border border-yellow-500/40 bg-yellow-500/10`,children:[(0,G.jsx)(Lu,{className:`w-5 h-5 shrink-0 text-yellow-400 mt-0.5`}),(0,G.jsxs)(`div`,{className:`text-sm`,children:[(0,G.jsx)(`p`,{className:`text-white font-medium`,children:e(`profiles.signInExpiredTitle`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray`,children:e(`profiles.signInExpiredBody`)})]})]}),c?.is_authenticated?f?(0,G.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,G.jsx)(Y,{className:`w-8 h-8 text-bambu-green animate-spin`})}):d?(0,G.jsx)(xKe,{settings:d,lastSyncTime:o,onRefresh:()=>p(),isRefreshing:f,printers:u,hasPermission:r,t:e}):(0,G.jsxs)(`div`,{className:`text-center py-16`,children:[(0,G.jsx)(`p`,{className:`text-bambu-gray mb-4`,children:e(`profiles.failedToLoad`)}),(0,G.jsx)(Q,{onClick:()=>p(),children:e(`profiles.retry`)})]}):(0,G.jsx)(gKe,{onSuccess:()=>{t.invalidateQueries({queryKey:[`cloudStatus`]})},t:e})]}),i===`orca_cloud`&&(0,G.jsx)(mKe,{}),i===`local`&&(0,G.jsx)(lKe,{}),i===`kprofiles`&&(0,G.jsx)(aKe,{}),(0,G.jsx)(_Ke,{})]})}function CKe(e,t){let n=(t||``).toUpperCase().replace(/[- ]/g,``),r=n.includes(`X1`),i=n.includes(`P1`),a=n.includes(`A1MINI`),o=n.includes(`A1`)&&!a,s=n.includes(`H2D`),c=n.includes(`H2C`),l=n.includes(`H2S`),u=s||c||l,d=n.includes(`P2S`),f=n.includes(`X2D`),p=d||f;switch(e){case`Lubricate Steel Rods`:return p?`https://wiki.bambulab.com/en/p2s/maintenance/lubricate-x-y-z-axis`:null;case`Clean Steel Rods`:return p?`https://wiki.bambulab.com/en/p2s/maintenance/lubricate-x-y-z-axis`:null;case`Lubricate Linear Rails`:return a?`https://wiki.bambulab.com/en/a1-mini/maintenance/lubricate-y-axis`:o?`https://wiki.bambulab.com/en/a1/maintenance/lubricate-y-axis`:u?`https://wiki.bambulab.com/en/h2/maintenance/x-axis-lubrication`:null;case`Clean Nozzle/Hotend`:return r||i?`https://wiki.bambulab.com/en/x1/troubleshooting/nozzle-clog`:a||o?`https://wiki.bambulab.com/en/a1-mini/troubleshooting/nozzle-clog`:u?`https://wiki.bambulab.com/en/h2/maintenance/nozzl-cold-pull-maintenance-and-cleaning`:p?`https://wiki.bambulab.com/en/p2s/maintenance/cold-pull-maintenance-hotend`:`https://wiki.bambulab.com/en/x1/troubleshooting/nozzle-clog`;case`Check Belt Tension`:return r?`https://wiki.bambulab.com/en/x1/maintenance/belt-tension`:i?`https://wiki.bambulab.com/en/p1/maintenance/p1p-maintenance`:a?`https://wiki.bambulab.com/en/a1-mini/maintenance/belt_tension`:o?`https://wiki.bambulab.com/en/a1/maintenance/belt_tension`:s?`https://wiki.bambulab.com/en/h2/maintenance/belt-tension`:c?`https://wiki.bambulab.com/en/h2c/maintenance/belt-tension`:l?`https://wiki.bambulab.com/en/h2s/maintenance/belt-tension`:p?`https://wiki.bambulab.com/en/p2s/maintenance/belt-tension`:`https://wiki.bambulab.com/en/x1/maintenance/belt-tension`;case`Clean Carbon Rods`:return r||i?`https://wiki.bambulab.com/en/general/carbon-rods-clearance`:null;case`Clean Linear Rails`:return a?`https://wiki.bambulab.com/en/a1-mini/maintenance/lubricate-y-axis`:o?`https://wiki.bambulab.com/en/a1/maintenance/lubricate-y-axis`:u?`https://wiki.bambulab.com/en/h2/maintenance/x-axis-lubrication`:null;case`Clean Build Plate`:return`https://wiki.bambulab.com/en/filament-acc/acc/pei-plate-clean-guide`;case`Check PTFE Tube`:return r||i?`https://wiki.bambulab.com/en/x1/maintenance/replace-ptfe-tube`:a||o?`https://wiki.bambulab.com/en/a1-mini/maintenance/ptfe-tube`:s?`https://wiki.bambulab.com/en/h2/maintenance/replace-ptfe-tube-on-h2d-printer`:l?`https://wiki.bambulab.com/en/h2s/maintenance/replace-ptfe-tube-on-h2s-printer`:c?`https://wiki.bambulab.com/en/h2/maintenance/replace-ptfe-tube-on-h2d-printer`:`https://wiki.bambulab.com/en/x1/maintenance/replace-ptfe-tube`;case`Replace HEPA Filter`:case`HEPA Filter`:case`Replace Carbon Filter`:case`Carbon Filter`:return u?`https://wiki.bambulab.com/en/h2/maintenance/replace-smoke-purifier-air-filte`:`https://wiki.bambulab.com/en/x1/maintenance/replace-carbon-filter`;case`Lubricate Left Nozzle Rail`:case`Left Nozzle Rail`:return u?`https://wiki.bambulab.com/en/h2/maintenance/x-axis-lubrication`:null;default:return null}}var E5={Droplet:Zs,Flame:hc,Ruler:Kl,Sparkles:_u,Square:bu,Cable:ts,Wrench:td,Calendar:as,Timer:Nu,Cog:Rs,Fan:oc,Zap:id,Wind:$u,Thermometer:Mu,Layers:Jc,Box:Zo,Target:Du,RefreshCw:Hl,Settings:ru,Filter:wc,CircleDot:Cs};function D5(e){return e&&E5[e]||td}function O5(e,t,n){if(t===`days`){if(e<1)return n?n(`common.today`):`Today`;if(e===1)return n?n(`maintenance.day`):`1 day`;if(e<7){let t=Math.round(e);return n?n(`maintenance.days`,{count:t}):`${t} days`}if(e<180){let t=Math.round(e/7);return t===1?n?n(`maintenance.week`):`1 week`:n?n(`maintenance.weeks`,{count:t}):`${t} weeks`}let t=Math.round(e/30);return t===1?n?n(`maintenance.month`):`1 month`:n?n(`maintenance.months`,{count:t}):`${t} months`}else{if(e<1)return`${Math.round(e*60)}m`;if(e<24)return`${e<10?e.toFixed(1):Math.round(e)}h`;let t=e/24;if(t<7)return`${t<2?t.toFixed(1):Math.round(t)}d`;let n=t/7;return n<12?`${n<2?n.toFixed(1):Math.round(n)}w`:`${Math.round(n/4)}mo`}}function k5(e,t,n){return t===`days`?e===1?n?n(`maintenance.day`):`1 day`:e===7?n?n(`maintenance.week`):`1 week`:e===14?n?n(`maintenance.weeks`,{count:2}):`2 weeks`:e===30?n?n(`maintenance.month`):`1 month`:e===60?n?n(`maintenance.months`,{count:2}):`2 months`:e===90?n?n(`maintenance.months`,{count:3}):`3 months`:e===180?n?n(`maintenance.months`,{count:6}):`6 months`:e===365?n?n(`maintenance.year`):`1 year`:n?n(`maintenance.days`,{count:e}):`${e} days`:`${e}h`}function wKe({item:e,onPerform:t,onToggle:n,hasPermission:r,t:i}){let a=D5(e.maintenance_type_icon),o=e.interval_type||`hours`,s=(()=>{if(o===`days`){let t=e.days_since_maintenance??0;return Math.max(0,Math.min(100,t/e.interval_hours*100))}return Math.max(0,Math.min(100,(e.interval_hours-e.hours_until_due)/e.interval_hours*100))})(),c=()=>e.enabled?e.is_due?`text-red-700 dark:text-red-400`:e.is_warning?`text-amber-700 dark:text-amber-400`:`text-bambu-green`:`text-bambu-gray`;return(0,G.jsx)(`div`,{className:`rounded-xl border p-4 transition-all ${e.enabled?e.is_due?`bg-red-500/5 border-red-500/20`:e.is_warning?`bg-amber-500/5 border-amber-500/20`:`bg-bambu-dark-secondary border-bambu-dark-tertiary`:`bg-bambu-dark-secondary/50`}`,children:(0,G.jsxs)(`div`,{className:`flex items-start gap-3 max-[550px]:flex-wrap`,children:[(0,G.jsxs)(`div`,{className:`relative p-2.5 rounded-lg shrink-0 ${e.is_due?`bg-red-500/20`:e.is_warning?`bg-amber-500/20`:e.enabled?`bg-bambu-dark`:`bg-bambu-dark/50`}`,children:[(0,G.jsx)(a,{className:`w-5 h-5 ${c()}`}),e.enabled&&(e.is_due||e.is_warning)&&(0,G.jsx)(`span`,{className:`absolute -top-1 -right-1 w-2.5 h-2.5 rounded-full ${e.is_due?`bg-red-500`:`bg-amber-500`} animate-pulse`})]}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`h3`,{className:`font-medium truncate ${e.enabled?`text-white`:`text-bambu-gray`}`,children:e.maintenance_type_name}),o===`days`&&(0,G.jsx)(`span`,{title:i(`maintenance.timeBasedInterval`),children:(0,G.jsx)(as,{className:`w-3.5 h-3.5 text-bambu-gray shrink-0`})}),(()=>{let t=e.maintenance_type_wiki_url||CKe(e.maintenance_type_name,e.printer_model);return t?(0,G.jsx)(`a`,{href:t,target:`_blank`,rel:`noopener noreferrer`,className:`text-bambu-gray hover:text-bambu-green transition-colors shrink-0`,title:i(`maintenance.viewDocumentation`),onClick:e=>e.stopPropagation(),children:(0,G.jsx)(rc,{className:`w-3.5 h-3.5`})}):null})()]}),(0,G.jsx)(`div`,{className:`mt-2 mb-1.5`,children:(0,G.jsx)(`div`,{className:`w-full h-1.5 bg-bambu-dark rounded-full overflow-hidden`,children:(0,G.jsx)(`div`,{className:`h-full rounded-full transition-all duration-500 ${e.enabled?e.is_due?`bg-red-500`:e.is_warning?`bg-amber-500`:`bg-bambu-green`:`bg-bambu-gray/30`}`,style:{width:`${s}%`}})})}),(0,G.jsxs)(`div`,{className:`text-xs flex items-center gap-1 ${c()}`,children:[e.is_due&&(0,G.jsx)(Lu,{className:`w-3 h-3`}),e.is_warning&&!e.is_due&&(0,G.jsx)(js,{className:`w-3 h-3`}),!e.is_due&&!e.is_warning&&e.enabled&&(0,G.jsx)(fs,{className:`w-3 h-3`}),(()=>{if(!e.enabled)return i(`common.disabled`);if(o===`days`){let t=e.days_until_due??0;return e.is_due?i(`maintenance.overdueBy`,{duration:O5(Math.abs(t),`days`,i)}):e.is_warning?i(`maintenance.dueIn`,{duration:O5(t,`days`,i)}):i(`maintenance.timeLeft`,{duration:O5(t,`days`,i)})}else return e.is_due?i(`maintenance.overdueBy`,{duration:O5(Math.abs(e.hours_until_due),`hours`,i)}):e.is_warning?i(`maintenance.dueIn`,{duration:O5(e.hours_until_due,`hours`,i)}):i(`maintenance.timeLeft`,{duration:O5(e.hours_until_due,`hours`,i)})})()]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0 max-[550px]:w-full max-[550px]:justify-end max-[550px]:mt-1`,children:[(0,G.jsx)(`span`,{title:r(`maintenance:update`)?void 0:i(`maintenance.noPermissionUpdate`),children:(0,G.jsx)(fH,{checked:e.enabled,onChange:t=>n(e.id,t),disabled:!r(`maintenance:update`)})}),(0,G.jsxs)(Q,{size:`sm`,variant:e.is_due?`primary`:`secondary`,onClick:()=>t(e.id),disabled:!e.enabled||!r(`maintenance:update`),title:r(`maintenance:update`)?void 0:i(`maintenance.noPermissionPerform`),className:`!px-3`,children:[(0,G.jsx)(Wl,{className:`w-3.5 h-3.5`}),i(`common.reset`)]})]})]})})}function TKe({overview:e,onPerform:t,onToggle:n,onSetHours:r,hasPermission:i,t:a}){let[o,s]=(0,y.useState)(!1),[c,l]=(0,y.useState)(!1),[u,d]=(0,y.useState)(e.total_print_hours.toFixed(1)),f=[...e.maintenance_items].sort((e,t)=>e.is_due&&!t.is_due?-1:!e.is_due&&t.is_due?1:e.is_warning&&!t.is_warning?-1:!e.is_warning&&t.is_warning?1:e.maintenance_type_id-t.maintenance_type_id),p=f.find(e=>e.enabled&&(e.is_due||e.is_warning)),m=()=>{let t=parseFloat(u);!isNaN(t)&&t>=0&&(r(e.printer_id,t),l(!1))};return(0,G.jsxs)(zd,{className:`overflow-hidden`,children:[(0,G.jsxs)(`div`,{className:`p-5`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,G.jsx)(`h2`,{className:`text-xl font-semibold text-white`,children:e.printer_name}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.due_count>0&&(0,G.jsxs)(`span`,{className:`px-2.5 py-1 bg-red-100 text-red-700 dark:bg-red-500/20 dark:text-red-400 text-xs font-medium rounded-full flex items-center gap-1.5`,children:[(0,G.jsx)(Lu,{className:`w-3 h-3`}),a(`maintenance.overdueCount`,{count:e.due_count})]}),e.warning_count>0&&(0,G.jsxs)(`span`,{className:`px-2.5 py-1 bg-amber-100 text-amber-700 dark:bg-amber-500/20 dark:text-amber-400 text-xs font-medium rounded-full flex items-center gap-1.5`,children:[(0,G.jsx)(js,{className:`w-3 h-3`}),a(`maintenance.dueSoonCount`,{count:e.warning_count})]}),e.due_count===0&&e.warning_count===0&&(0,G.jsxs)(`span`,{className:`px-2.5 py-1 bg-bambu-green/20 text-bambu-green text-xs font-medium rounded-full flex items-center gap-1.5`,children:[(0,G.jsx)(fs,{className:`w-3 h-3`}),a(`maintenance.allGood`)]})]})]}),(0,G.jsxs)(`button`,{onClick:()=>s(!o),className:`flex items-center gap-1.5 px-3 py-1.5 text-sm text-bambu-gray hover:text-white hover:bg-bambu-dark rounded-lg transition-colors`,children:[o?(0,G.jsx)(gs,{className:`w-4 h-4`}):(0,G.jsx)(ps,{className:`w-4 h-4`}),a(o?`common.collapse`:`common.expand`)]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-6 mt-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`p-2 bg-bambu-dark/50 rounded-lg`,children:(0,G.jsx)(Nu,{className:`w-4 h-4 text-bambu-gray`})}),c?(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`input`,{type:`number`,value:u,onChange:e=>d(e.target.value),onKeyDown:e=>{e.key===`Enter`&&m(),e.key===`Escape`&&l(!1)},className:`w-24 px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm`,min:`0`,step:`1`,autoFocus:!0}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:a(`common.hours`)}),(0,G.jsx)(Q,{size:`sm`,onClick:m,children:a(`common.save`)}),(0,G.jsx)(Q,{size:`sm`,variant:`secondary`,onClick:()=>l(!1),children:a(`common.cancel`)})]}):(0,G.jsxs)(`button`,{onClick:()=>{i(`maintenance:update`)&&(d(Math.round(e.total_print_hours).toString()),l(!0))},className:`group ${i(`maintenance:update`)?``:`cursor-not-allowed opacity-60`}`,title:i(`maintenance:update`)?void 0:a(`maintenance.noPermissionEditHours`),children:[(0,G.jsxs)(`div`,{className:`text-sm font-medium text-white ${i(`maintenance:update`)?`group-hover:text-bambu-green`:``} transition-colors flex items-center gap-1`,children:[Math.round(e.total_print_hours),` `,a(`common.hours`),(0,G.jsx)(Ol,{className:`w-3 h-3 text-bambu-gray ${i(`maintenance:update`)?`group-hover:text-bambu-green`:``}`})]}),(0,G.jsx)(`div`,{className:`text-xs text-bambu-gray`,children:a(`maintenance.totalPrintTime`)})]})]}),(0,G.jsx)(`div`,{className:`w-px h-10 bg-bambu-dark-tertiary`}),p&&(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`p-2 rounded-lg ${p.is_due?`bg-red-500/20`:`bg-amber-500/20`}`,children:(0,G.jsx)(D5(p.maintenance_type_icon),{className:`w-4 h-4 ${p.is_due?`text-red-600 dark:text-red-400`:`text-amber-600 dark:text-amber-400`}`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`div`,{className:`text-sm font-medium ${p.is_due?`text-red-700 dark:text-red-400`:`text-amber-700 dark:text-amber-400`}`,children:p.maintenance_type_name}),(0,G.jsx)(`div`,{className:`text-xs ${p.is_due?`text-red-700/80 dark:text-red-400/70`:`text-amber-700/80 dark:text-amber-400/70`}`,children:p.is_due?a(`common.overdue`):a(`maintenance.dueSoon`)})]})]})]})]}),o&&(0,G.jsx)(Vd,{className:`pt-0 border-t border-bambu-dark-tertiary`,children:(0,G.jsx)(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-3 pt-4`,children:f.map(e=>(0,G.jsx)(wKe,{item:e,onPerform:t,onToggle:n,hasPermission:i,t:a},e.id))})})]})}function EKe({overview:e,types:t,onUpdateInterval:n,onAddType:r,onUpdateType:i,onDeleteType:a,onRestoreDefaults:o,isRestoringDefaults:s,onAssignType:c,onRemoveItem:l,hasPermission:u,t:d}){let[f,p]=(0,y.useState)(null),[m,h]=(0,y.useState)(``),[g,_]=(0,y.useState)(`hours`),[v,b]=(0,y.useState)(!1),[x,S]=(0,y.useState)(``),[C,w]=(0,y.useState)(`100`),[T,E]=(0,y.useState)(`hours`),[D,O]=(0,y.useState)(`Wrench`),[k,A]=(0,y.useState)(``),[j,M]=(0,y.useState)(new Set),[N,P]=(0,y.useState)(null),[F,I]=(0,y.useState)(null),L=(0,y.useMemo)(()=>e?e.map(e=>({id:e.printer_id,name:e.printer_name})):[],[e]),R=t=>e?e.filter(e=>e.maintenance_items.some(e=>e.maintenance_type_id===t)).map(e=>({printerId:e.printer_id,printerName:e.printer_name,itemId:e.maintenance_items.find(e=>e.maintenance_type_id===t)?.id})):[],z=t=>{if(!e)return[];let n=new Set(R(t).map(e=>e.printerId));return L.filter(e=>!n.has(e.id))},[B,V]=(0,y.useState)(null),[ee,te]=(0,y.useState)(``),[ne,re]=(0,y.useState)(``),[ie,ae]=(0,y.useState)(`hours`),[oe,se]=(0,y.useState)(`Wrench`),[H,ce]=(0,y.useState)(``),le=e=>{V(e),te(e.name),re(e.default_interval_hours.toString()),ae(e.interval_type||`hours`),se(e.icon||`Wrench`),ce(e.wiki_url||``)},ue=()=>{B&&ee.trim()&&parseFloat(ne)>0&&(i(B.id,{name:ee.trim(),default_interval_hours:parseFloat(ne),interval_type:ie,icon:oe,wiki_url:H.trim()||null}),V(null))},de=(e,t,r)=>{let i=parseFloat(m);!isNaN(i)&&i>0&&n(e,{custom_interval_hours:Math.abs(i-t)<.01?null:i,custom_interval_type:g===r?null:g}),p(null)},fe=e=>{e.preventDefault(),x.trim()&&parseFloat(C)>0&&j.size>0&&(r({name:x.trim(),default_interval_hours:parseFloat(C),interval_type:T,icon:D,wiki_url:k.trim()||null},Array.from(j)),S(``),w(`100`),E(`hours`),A(``),M(new Set),b(!1))},pe=e=>{M(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},me=e?.map(e=>({printerId:e.printer_id,printerName:e.printer_name,items:e.maintenance_items.sort((e,t)=>e.maintenance_type_id-t.maintenance_type_id)})).sort((e,t)=>e.printerName.localeCompare(t.printerName))||[],he=t.filter(e=>e.is_system),ge=t.filter(e=>!e.is_system);return(0,G.jsxs)(`div`,{className:`space-y-8`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:d(`maintenance.maintenanceTypes`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:d(`maintenance.maintenanceTypesDescription`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:o,disabled:!u(`maintenance:delete`)||s,title:u(`maintenance:delete`)?void 0:d(`maintenance.noPermissionDeleteTypes`),children:d(`maintenance.restoreDefaults`)}),(0,G.jsxs)(Q,{onClick:()=>b(!v),disabled:!u(`maintenance:create`),title:u(`maintenance:create`)?void 0:d(`maintenance.noPermissionEditTypes`),children:[(0,G.jsx)(Fl,{className:`w-4 h-4`}),d(`maintenance.addCustomType`)]})]})]}),v&&(0,G.jsx)(zd,{className:`mb-6`,children:(0,G.jsx)(Vd,{className:`py-4`,children:(0,G.jsxs)(`form`,{onSubmit:fe,children:[(0,G.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4`,children:[(0,G.jsxs)(`div`,{className:`lg:col-span-2`,children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1.5`,children:d(`common.name`)}),(0,G.jsx)(`input`,{type:`text`,value:x,onChange:e=>S(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,placeholder:d(`maintenance.exampleName`),autoFocus:!0})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1.5`,children:d(`maintenance.intervalType`)}),(0,G.jsxs)(`select`,{value:T,onChange:e=>{E(e.target.value),e.target.value===`days`?w(`30`):w(`100`)},className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,children:[(0,G.jsx)(`option`,{value:`hours`,children:d(`maintenance.printHours`)}),(0,G.jsx)(`option`,{value:`days`,children:d(`maintenance.calendarDays`)})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1.5`,children:d(`maintenance.intervalValue`,{type:T===`days`?d(`maintenance.calendarDays`).toLowerCase():d(`common.hours`)})}),(0,G.jsx)(`input`,{type:`number`,value:C,onChange:e=>w(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,min:`1`})]})]}),(0,G.jsx)(`div`,{className:`mt-4 flex items-end justify-between`,children:(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1.5`,children:d(`maintenance.icon`)}),(0,G.jsx)(`div`,{className:`flex gap-1`,children:Object.keys(E5).map(e=>{let t=E5[e];return(0,G.jsx)(`button`,{type:`button`,onClick:()=>O(e),className:`p-2 rounded-lg transition-colors ${D===e?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary`}`,children:(0,G.jsx)(t,{className:`w-4 h-4`})},e)})})]})}),(0,G.jsxs)(`div`,{className:`mt-4`,children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1.5`,children:d(`maintenance.documentationLink`)}),(0,G.jsx)(`input`,{type:`url`,value:k,onChange:e=>A(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,placeholder:`https://wiki.bambulab.com/...`})]}),(0,G.jsxs)(`div`,{className:`mt-4`,children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1.5`,children:d(`maintenance.assignToPrinters`)}),(0,G.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:L.map(e=>(0,G.jsx)(`button`,{type:`button`,onClick:()=>pe(e.id),className:`px-3 py-1.5 rounded-lg text-sm transition-colors ${j.has(e.id)?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary`}`,children:e.name},e.id))}),j.size===0&&(0,G.jsx)(`p`,{className:`text-xs text-orange-700 dark:text-orange-400 mt-1`,children:d(`maintenance.selectAtLeastOnePrinter`)})]}),(0,G.jsxs)(`div`,{className:`mt-4 flex justify-end gap-2`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:()=>{b(!1),M(new Set)},children:d(`common.cancel`)}),(0,G.jsx)(Q,{type:`submit`,disabled:!x.trim()||j.size===0,children:d(`maintenance.addType`)})]})]})})}),(0,G.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3`,children:[he.map(e=>{let t=D5(e.icon),n=e.interval_type||`hours`;return(0,G.jsx)(`div`,{className:`bg-bambu-dark-secondary rounded-xl p-4 border border-bambu-dark-tertiary`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`p-2.5 bg-bambu-dark rounded-lg`,children:(0,G.jsx)(t,{className:`w-5 h-5 text-bambu-gray`})}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`div`,{className:`text-sm font-medium text-white truncate`,children:e.name}),(0,G.jsxs)(`div`,{className:`text-xs text-bambu-gray mt-0.5 flex items-center gap-1`,children:[n===`days`?(0,G.jsx)(as,{className:`w-3 h-3`}):(0,G.jsx)(Nu,{className:`w-3 h-3`}),k5(e.default_interval_hours,n,d)]})]}),(0,G.jsx)(`button`,{onClick:()=>{u(`maintenance:delete`)&&I(e)},disabled:!u(`maintenance:delete`),title:u(`maintenance:delete`)?void 0:d(`maintenance.noPermissionDeleteTypes`),className:`p-2 rounded-lg hover:bg-bambu-dark text-bambu-gray hover:text-red-600 dark:hover:text-red-400 transition-colors ${u(`maintenance:delete`)?``:`opacity-50 cursor-not-allowed`}`,children:(0,G.jsx)(Pu,{className:`w-4 h-4`})})]})},e.id)}),ge.map(e=>{let t=D5(e.icon),n=e.interval_type||`hours`;if(B?.id===e.id)return(0,G.jsx)(`div`,{className:`bg-bambu-dark-secondary rounded-xl p-4 border border-bambu-green`,children:(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsx)(`input`,{type:`text`,value:ee,onChange:e=>te(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,placeholder:d(`common.name`),autoFocus:!0}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsxs)(`select`,{value:ie,onChange:e=>ae(e.target.value),className:`flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,children:[(0,G.jsx)(`option`,{value:`hours`,children:d(`maintenance.printHours`)}),(0,G.jsx)(`option`,{value:`days`,children:d(`maintenance.calendarDays`)})]}),(0,G.jsx)(`input`,{type:`number`,value:ne,onChange:e=>re(e.target.value),className:`w-24 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,min:`1`})]}),(0,G.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:Object.keys(E5).map(e=>{let t=E5[e];return(0,G.jsx)(`button`,{type:`button`,onClick:()=>se(e),className:`p-1.5 rounded transition-colors ${oe===e?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white`}`,children:(0,G.jsx)(t,{className:`w-3.5 h-3.5`})},e)})}),(0,G.jsx)(`input`,{type:`url`,value:H,onChange:e=>ce(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,placeholder:d(`maintenance.documentationLink`)}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsx)(Q,{size:`sm`,onClick:ue,disabled:!ee.trim(),children:d(`common.save`)}),(0,G.jsx)(Q,{size:`sm`,variant:`secondary`,onClick:()=>V(null),children:d(`common.cancel`)})]})]})},e.id);let r=R(e.id),i=z(e.id),o=N===e.id;return(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl p-4 border border-bambu-green/30`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`p-2.5 bg-bambu-green/20 rounded-lg`,children:(0,G.jsx)(t,{className:`w-5 h-5 text-bambu-green`})}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-sm font-medium text-white truncate`,children:e.name}),(0,G.jsx)(`span`,{className:`px-1.5 py-0.5 bg-bambu-green/20 text-bambu-green text-[10px] font-medium rounded`,children:d(`maintenance.custom`)})]}),(0,G.jsxs)(`div`,{className:`text-xs text-bambu-gray mt-0.5 flex items-center gap-1`,children:[n===`days`?(0,G.jsx)(as,{className:`w-3 h-3`}):(0,G.jsx)(Nu,{className:`w-3 h-3`}),k5(e.default_interval_hours,n,d)]})]}),(0,G.jsxs)(`button`,{onClick:()=>P(o?null:e.id),className:`px-2 py-1 rounded-lg border transition-colors flex items-center gap-1 ${r.length>0?`border-bambu-green/50 bg-bambu-green/10 text-bambu-green hover:bg-bambu-green/20`:`border-orange-300 bg-orange-50 text-orange-700 hover:bg-orange-100 dark:border-orange-400/50 dark:bg-orange-400/10 dark:text-orange-400 dark:hover:bg-orange-400/20`}`,title:d(`maintenance.printersAssignedClick`,{count:r.length}),children:[(0,G.jsx)(Rl,{className:`w-3 h-3`}),(0,G.jsx)(`span`,{className:`text-xs font-medium`,children:r.length}),(0,G.jsx)(ps,{className:`w-3 h-3 transition-transform ${o?`rotate-180`:``}`})]}),(0,G.jsx)(`button`,{onClick:()=>le(e),disabled:!u(`maintenance:update`),title:u(`maintenance:update`)?void 0:d(`maintenance.noPermissionEditTypes`),className:`p-2 rounded-lg hover:bg-bambu-dark text-bambu-gray hover:text-white transition-colors ${u(`maintenance:update`)?``:`opacity-50 cursor-not-allowed`}`,children:(0,G.jsx)(Ol,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:()=>{confirm(d(`maintenance.deleteTypeConfirm`,{name:e.name}))&&a(e.id)},disabled:!u(`maintenance:delete`),title:u(`maintenance:delete`)?void 0:d(`maintenance.noPermissionDeleteTypes`),className:`p-2 rounded-lg hover:bg-bambu-dark text-bambu-gray hover:text-red-600 dark:hover:text-red-400 transition-colors ${u(`maintenance:delete`)?``:`opacity-50 cursor-not-allowed`}`,children:(0,G.jsx)(Pu,{className:`w-4 h-4`})})]}),o&&(0,G.jsxs)(`div`,{className:`mt-3 pt-3 border-t border-bambu-dark-tertiary`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:d(`maintenance.assignedToPrinters`)}),r.length===0?(0,G.jsx)(`p`,{className:`text-xs text-orange-700 dark:text-orange-400`,children:d(`maintenance.noPrintersAssigned`)}):(0,G.jsx)(`div`,{className:`flex flex-wrap gap-1 mb-2`,children:r.map(e=>(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-2 py-1 bg-bambu-dark rounded text-xs text-white`,children:[e.printerName,(0,G.jsx)(`button`,{onClick:()=>e.itemId&&l(e.itemId),disabled:!u(`maintenance:delete`),title:u(`maintenance:delete`)?d(`maintenance.removeFromPrinter`):d(`maintenance.noPermissionRemovePrinter`),className:`ml-1 ${u(`maintenance:delete`)?`hover:text-red-600 dark:hover:text-red-400`:`opacity-50 cursor-not-allowed`}`,children:`×`})]},e.printerId))}),i.length>0&&(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-1`,children:[(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray mr-1`,children:d(`maintenance.addPrinterShort`)}),i.map(t=>(0,G.jsxs)(`button`,{onClick:()=>c(t.id,e.id),disabled:!u(`maintenance:create`),title:u(`maintenance:create`)?void 0:d(`maintenance.noPermissionAssignPrinter`),className:`px-2 py-1 bg-bambu-dark rounded text-xs transition-colors ${u(`maintenance:create`)?`hover:bg-bambu-green/20 text-bambu-gray hover:text-bambu-green`:`opacity-50 cursor-not-allowed text-bambu-gray`}`,children:[`+ `,t.name]},t.id))]})]})]},e.id)})]})]}),me.length>0&&(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`mb-4`,children:[(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:d(`maintenance.intervalOverrides`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:d(`maintenance.intervalOverridesDescription`)})]}),(0,G.jsx)(`div`,{className:`space-y-4`,children:me.map(e=>(0,G.jsx)(zd,{children:(0,G.jsxs)(Vd,{className:`py-4`,children:[(0,G.jsx)(`h3`,{className:`text-sm font-medium text-white mb-3`,children:e.printerName}),(0,G.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-2`,children:e.items.map(e=>{let n=D5(e.maintenance_type_icon),r=t.find(t=>t.id===e.maintenance_type_id),i=r?.default_interval_hours||e.interval_hours,a=r?.interval_type||`hours`,o=e.interval_type||`hours`,s=f===e.id;return(0,G.jsxs)(`div`,{className:`flex items-center gap-2 p-2.5 bg-bambu-dark rounded-lg`,children:[(0,G.jsx)(n,{className:`w-4 h-4 text-bambu-gray shrink-0`}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray flex-1 truncate`,children:e.maintenance_type_name}),s?(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[g===`days`?(0,G.jsx)(as,{className:`w-3.5 h-3.5 text-bambu-gray shrink-0`}):(0,G.jsx)(Nu,{className:`w-3.5 h-3.5 text-bambu-gray shrink-0`}),(0,G.jsxs)(`select`,{value:g,onChange:e=>_(e.target.value),className:`px-1.5 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-xs`,children:[(0,G.jsx)(`option`,{value:`hours`,children:d(`maintenance.printHours`)}),(0,G.jsx)(`option`,{value:`days`,children:d(`maintenance.calendarDays`)})]}),(0,G.jsx)(`input`,{type:`number`,value:m,onChange:e=>h(e.target.value),onKeyDown:t=>{t.key===`Enter`&&de(e.id,i,a),t.key===`Escape`&&p(null)},className:`w-16 px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-xs`,min:`1`}),(0,G.jsx)(Q,{size:`sm`,onClick:()=>de(e.id,i,a),children:`OK`})]}):(0,G.jsxs)(`button`,{onClick:()=>{u(`maintenance:update`)&&(p(e.id),h(e.interval_hours.toString()),_(o))},disabled:!u(`maintenance:update`),title:u(`maintenance:update`)?void 0:d(`maintenance.noPermissionEditIntervals`),className:`px-2 py-1 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-xs font-medium text-white transition-colors flex items-center gap-1 ${u(`maintenance:update`)?`hover:bg-bambu-dark-secondary hover:border-bambu-green`:`opacity-50 cursor-not-allowed`}`,children:[o===`days`?(0,G.jsx)(as,{className:`w-3 h-3`}):(0,G.jsx)(Nu,{className:`w-3 h-3`}),k5(e.interval_hours,o,d),(0,G.jsx)(Ol,{className:`w-3 h-3 text-bambu-gray`})]})]},e.id)})})]})},e.printerId))})]}),me.length===0&&(0,G.jsx)(zd,{children:(0,G.jsxs)(Vd,{className:`text-center py-12`,children:[(0,G.jsx)(js,{className:`w-12 h-12 mx-auto mb-4 text-bambu-gray/30`}),(0,G.jsx)(`p`,{className:`text-bambu-gray`,children:d(`common.noPrinters`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray/70 mt-1`,children:d(`maintenance.intervalOverridesDescription`)})]})}),F&&(0,G.jsx)(of,{title:d(`maintenance.deleteSystemTypeTitle`),message:d(`maintenance.deleteSystemTypeMessage`,{name:F.name}),confirmText:d(`common.delete`),cancelText:d(`common.cancel`),variant:`danger`,cancelVariant:`primary`,cardClassName:`bg-red-950/70 border border-red-800/70`,onConfirm:()=>{a(F.id),I(null)},onCancel:()=>I(null)})]})}function DKe(){let{t:e}=U(),t=co(),{showToast:n}=qd(),{hasPermission:r}=Nd(),[i,a]=(0,y.useState)(`status`),{data:o,isLoading:s}=K({queryKey:[`maintenanceOverview`],queryFn:Z.getMaintenanceOverview}),{data:c}=K({queryKey:[`maintenanceTypes`],queryFn:Z.getMaintenanceTypes}),l=q({mutationFn:({id:e,notes:t})=>Z.performMaintenance(e,t),onSuccess:()=>{t.invalidateQueries({queryKey:[`maintenanceOverview`]}),t.invalidateQueries({queryKey:[`maintenanceSummary`]}),n(e(`maintenance.maintenanceComplete`))},onError:e=>{n(e.message,`error`)}}),u=q({mutationFn:({id:e,data:t})=>Z.updateMaintenanceItem(e,t),onSuccess:()=>{t.invalidateQueries({queryKey:[`maintenanceOverview`]})},onError:e=>{n(e.message,`error`)}}),d=q({mutationFn:({id:e,data:t})=>Z.updateMaintenanceType(e,t),onSuccess:()=>{t.invalidateQueries({queryKey:[`maintenanceTypes`]}),t.invalidateQueries({queryKey:[`maintenanceOverview`]}),n(e(`maintenance.typeUpdated`))},onError:e=>{n(e.message,`error`)}}),f=q({mutationFn:Z.deleteMaintenanceType,onSuccess:()=>{t.invalidateQueries({queryKey:[`maintenanceTypes`]}),t.invalidateQueries({queryKey:[`maintenanceOverview`]}),n(e(`maintenance.typeDeleted`))},onError:e=>{n(e.message,`error`)}}),p=q({mutationFn:Z.restoreDefaultMaintenanceTypes,onSuccess:r=>{t.invalidateQueries({queryKey:[`maintenanceTypes`]}),t.invalidateQueries({queryKey:[`maintenanceOverview`]}),n(e(`maintenance.defaultsRestored`,{count:r.restored}))},onError:e=>{n(e.message,`error`)}}),m=q({mutationFn:({printerId:e,hours:t})=>Z.setPrinterHours(e,t),onSuccess:()=>{t.invalidateQueries({queryKey:[`maintenanceOverview`]}),t.invalidateQueries({queryKey:[`maintenanceSummary`]}),n(e(`maintenance.printHoursUpdated`))},onError:e=>{n(e.message,`error`)}}),h=q({mutationFn:({printerId:e,typeId:t})=>Z.assignMaintenanceType(e,t),onSuccess:()=>{t.invalidateQueries({queryKey:[`maintenanceOverview`]}),n(e(`maintenance.printerAssigned`))},onError:e=>{n(e.message,`error`)}}),g=q({mutationFn:Z.removeMaintenanceItem,onSuccess:()=>{t.invalidateQueries({queryKey:[`maintenanceOverview`]}),n(e(`maintenance.printerRemoved`))},onError:e=>{n(e.message,`error`)}}),_=e=>{l.mutate({id:e})},v=(e,t)=>{u.mutate({id:e,data:{enabled:t}})},b=(e,t)=>{m.mutate({printerId:e,hours:t})};if(s)return(0,G.jsx)(`div`,{className:`p-4 md:p-8 flex justify-center`,children:(0,G.jsx)(Y,{className:`w-8 h-8 text-bambu-green animate-spin`})});let x=o?.reduce((e,t)=>e+t.due_count,0)||0,S=o?.reduce((e,t)=>e+t.warning_count,0)||0;return(0,G.jsxs)(`div`,{className:`p-4 md:p-8`,children:[(0,G.jsxs)(`div`,{className:`mb-6`,children:[(0,G.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,G.jsx)(td,{className:`w-7 h-7 text-bambu-green`}),e(`maintenance.title`)]}),(0,G.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:i===`status`?(0,G.jsxs)(G.Fragment,{children:[x>0&&(0,G.jsx)(`span`,{className:`text-red-700 dark:text-red-400`,children:e(`maintenance.dueCount`,{count:x})}),x>0&&S>0&&` · `,S>0&&(0,G.jsx)(`span`,{className:`text-amber-700 dark:text-amber-400`,children:e(`maintenance.warningCount`,{count:S})}),x===0&&S===0&&(0,G.jsx)(`span`,{className:`text-bambu-green`,children:e(`maintenance.allOk`)})]}):e(`maintenance.configureSettings`)})]}),(0,G.jsxs)(`div`,{className:`flex gap-1 mb-6 border-b border-bambu-dark-tertiary`,children:[(0,G.jsx)(`button`,{onClick:()=>a(`status`),className:`px-4 py-2 text-sm font-medium border-b-2 -mb-px transition-colors ${i===`status`?`text-bambu-green border-bambu-green`:`text-bambu-gray border-transparent hover:text-white`}`,children:e(`maintenance.statusTab`)}),(0,G.jsx)(`button`,{onClick:()=>a(`settings`),className:`px-4 py-2 text-sm font-medium border-b-2 -mb-px transition-colors ${i===`settings`?`text-bambu-green border-bambu-green`:`text-bambu-gray border-transparent hover:text-white`}`,children:e(`maintenance.settingsTab`)})]}),i===`status`?(0,G.jsx)(`div`,{className:`space-y-6`,children:o&&o.length>0?[...o].sort((e,t)=>{let n=e.due_count*10+e.warning_count,r=t.due_count*10+t.warning_count;return n===r?e.printer_name.localeCompare(t.printer_name):r-n}).map(t=>(0,G.jsx)(TKe,{overview:t,onPerform:_,onToggle:v,onSetHours:b,hasPermission:r,t:e},t.printer_id)):(0,G.jsx)(zd,{children:(0,G.jsxs)(Vd,{className:`text-center py-16`,children:[(0,G.jsx)(td,{className:`w-16 h-16 mx-auto mb-4 text-bambu-gray/30`}),(0,G.jsx)(`p`,{className:`text-lg font-medium text-white mb-2`,children:e(`common.noPrinters`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray`,children:e(`maintenance.configureSettings`)})]})})}):(0,G.jsx)(EKe,{overview:o,types:c||[],onUpdateInterval:(e,t)=>u.mutate({id:e,data:t}),onAddType:async(r,i)=>{let a=await Z.createMaintenanceType(r);for(let e of i)await Z.assignMaintenanceType(e,a.id);t.invalidateQueries({queryKey:[`maintenanceTypes`]}),t.invalidateQueries({queryKey:[`maintenanceOverview`]}),n(e(`maintenance.typeUpdated`))},onUpdateType:(e,t)=>d.mutate({id:e,data:t}),onDeleteType:e=>f.mutate(e),onRestoreDefaults:()=>p.mutate(),isRestoringDefaults:p.isPending,onAssignType:(e,t)=>h.mutate({printerId:e,typeId:t}),onRemoveItem:e=>g.mutate(e),hasPermission:r,t:e})]})}var A5=[`#ef4444`,`#f97316`,`#eab308`,`#22c55e`,`#06b6d4`,`#3b82f6`,`#8b5cf6`,`#ec4899`,`#6b7280`];function j5({project:e,onClose:t,onSave:n,isLoading:r,currencySymbol:i,t:a}){let[o,s]=(0,y.useState)(e?.name||``),[c,l]=(0,y.useState)(e?.description||``),[u,d]=(0,y.useState)(e?.color||A5[0]),[f,p]=(0,y.useState)(e?.target_count?.toString()||``),[m,h]=(0,y.useState)(e?.target_parts_count?.toString()||``),[g,_]=(0,y.useState)(e?.target_sets?.toString()||``),[v,b]=(0,y.useState)(e?.status||`active`),[x,S]=(0,y.useState)(e?.tags||``),[C,w]=(0,y.useState)(e?.due_date?.split(`T`)[0]||``),[T,E]=(0,y.useState)(e?.priority||`normal`),[D,O]=(0,y.useState)(e?.budget?.toString()||``),[k,A]=(0,y.useState)(e?.url||``),[j,M]=(0,y.useState)(null),[N,P]=(0,y.useState)(e?.parent_id??null),F=co(),{data:I}=K({queryKey:[`projects`,void 0],queryFn:()=>Z.getProjects()}),L=_je(I||[],e?.id),[R,z]=(0,y.useState)(e?.cover_image_filename||null),B=(0,y.useRef)(null),[V,ee]=(0,y.useState)(!1),[te,ne]=(0,y.useState)(0);return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg w-full max-w-md border border-bambu-dark-tertiary flex flex-col max-h-[calc(100vh-2rem)]`,children:[(0,G.jsx)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary flex-shrink-0`,children:(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:a(e?`projects.editProject`:`projects.newProject`)})}),(0,G.jsxs)(`form`,{onSubmit:t=>{t.preventDefault();let r=k.trim();if(r&&!/^https?:\/\//i.test(r)){M(a(`projects.urlInvalid`));return}M(null),n({name:o.trim(),description:c.trim()||void 0,color:u,target_count:f?parseInt(f,10):void 0,target_parts_count:m?parseInt(m,10):void 0,target_sets:e?g?parseInt(g,10):null:g?parseInt(g,10):void 0,tags:e?x.trim()||null:x.trim()||void 0,due_date:e?C||null:C||void 0,priority:T,budget:D.trim()?parseFloat(D):null,url:e?r||null:r||void 0,parent_id:e?N??0:N??void 0,...e&&{status:v}})},className:`flex flex-col flex-1 min-h-0`,children:[(0,G.jsxs)(`div`,{className:`p-4 space-y-4 overflow-y-auto flex-1`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`common.name`)}),(0,G.jsx)(`input`,{type:`text`,value:o,onChange:e=>s(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:a(`projects.namePlaceholder`),required:!0})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`common.description`)}),(0,G.jsx)(`textarea`,{value:c,onChange:e=>l(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green resize-none`,placeholder:a(`projects.descriptionPlaceholder`),rows:2})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`projects.urlLabel`)}),(0,G.jsx)(`input`,{type:`url`,value:k,onChange:e=>{A(e.target.value),j&&M(null)},className:`w-full bg-bambu-dark border rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none ${j?`border-red-500 focus:border-red-500`:`border-bambu-dark-tertiary focus:border-bambu-green`}`,placeholder:a(`projects.urlPlaceholder`),maxLength:2048}),j&&(0,G.jsx)(`p`,{className:`text-xs text-red-600 dark:text-red-400 mt-1`,children:j})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`projects.parentLabel`)}),(0,G.jsxs)(`select`,{value:N??``,onChange:e=>P(e.target.value?parseInt(e.target.value,10):null),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white focus:outline-none focus:border-bambu-green`,children:[(0,G.jsx)(`option`,{value:``,children:a(`projects.parentNone`)}),L.map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:a(`projects.parentHint`)})]}),e&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`projects.coverImageLabel`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`w-20 h-20 rounded bg-bambu-dark border border-bambu-dark-tertiary overflow-hidden flex items-center justify-center flex-shrink-0`,children:R?(0,G.jsx)(`img`,{src:Z.getProjectCoverImageUrl(e.id,te),alt:a(`projects.coverImageAlt`),className:`w-full h-full object-cover`}):(0,G.jsx)(Hc,{className:`w-6 h-6 text-bambu-gray`})}),(0,G.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,G.jsx)(`input`,{ref:B,type:`file`,accept:`image/jpeg,image/png,image/gif,image/webp`,onChange:async t=>{let n=t.target.files?.[0];if(!(!n||!e)){ee(!0);try{z((await Z.uploadProjectCoverImage(e.id,n)).filename),ne(e=>e+1),F.invalidateQueries({queryKey:[`projects`]})}catch{}finally{ee(!1),B.current&&(B.current.value=``)}}},className:`hidden`}),(0,G.jsxs)(Q,{type:`button`,variant:`secondary`,onClick:()=>B.current?.click(),disabled:V,children:[V?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Vu,{className:`w-4 h-4 mr-1`}),a(R?`projects.coverImageReplace`:`projects.coverImageUpload`)]}),R&&(0,G.jsxs)(Q,{type:`button`,variant:`secondary`,onClick:async()=>{if(e){ee(!0);try{await Z.deleteProjectCoverImage(e.id),z(null),ne(e=>e+1),F.invalidateQueries({queryKey:[`projects`]})}finally{ee(!1)}}},disabled:V,children:[(0,G.jsx)(nd,{className:`w-4 h-4 mr-1`}),a(`projects.coverImageRemove`)]})]})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`projects.color`)}),(0,G.jsx)(`div`,{className:`flex gap-2 flex-wrap`,children:A5.map(e=>(0,G.jsx)(`button`,{type:`button`,onClick:()=>d(e),className:`w-8 h-8 rounded-full transition-transform ${u===e?`ring-2 ring-white ring-offset-2 ring-offset-bambu-dark-secondary scale-110`:``}`,style:{backgroundColor:e}},e))})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`projects.targetPlates`)}),(0,G.jsx)(`input`,{type:`number`,value:f,onChange:e=>p(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:a(`projects.targetPlatesPlaceholder`),min:`1`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:a(`projects.targetPlatesHelp`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`projects.targetParts`)}),(0,G.jsx)(`input`,{type:`number`,value:m,onChange:e=>h(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:a(`projects.targetPartsPlaceholder`),min:`1`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:a(`projects.targetPartsHelp`)})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`projects.targetSets`)}),(0,G.jsx)(`input`,{type:`number`,value:g,onChange:e=>_(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:a(`projects.targetSetsPlaceholder`),min:`1`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:a(`projects.targetSetsHelp`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`projects.tagsLabel`)}),(0,G.jsx)(`input`,{type:`text`,value:x,onChange:e=>S(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:a(`projects.tagsPlaceholder`)})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`projects.dueDate`)}),(0,G.jsx)(`input`,{type:`date`,value:C,onChange:e=>w(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white focus:outline-none focus:border-bambu-green`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`projects.priority`)}),(0,G.jsxs)(`select`,{value:T,onChange:e=>E(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white focus:outline-none focus:border-bambu-green`,children:[(0,G.jsx)(`option`,{value:`low`,children:a(`projects.priorityLow`)}),(0,G.jsx)(`option`,{value:`normal`,children:a(`projects.priorityNormal`)}),(0,G.jsx)(`option`,{value:`high`,children:a(`projects.priorityHigh`)}),(0,G.jsx)(`option`,{value:`urgent`,children:a(`projects.priorityUrgent`)})]})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`projectDetail.cost.budget`)}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(`span`,{className:`absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray pointer-events-none`,children:i}),(0,G.jsx)(`input`,{type:`number`,step:`0.01`,min:`0`,value:D,onChange:e=>O(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded pl-8 pr-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:`0.00`})]})]}),e&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`common.status`)}),(0,G.jsxs)(`select`,{value:v,onChange:e=>b(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white focus:outline-none focus:border-bambu-green`,children:[(0,G.jsx)(`option`,{value:`active`,children:a(`projects.statusActive`)}),(0,G.jsx)(`option`,{value:`completed`,children:a(`projects.statusCompleted`)}),(0,G.jsx)(`option`,{value:`archived`,children:a(`projects.statusArchived`)})]})]})]}),(0,G.jsxs)(`div`,{className:`flex justify-end gap-2 p-4 border-t border-bambu-dark-tertiary flex-shrink-0`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:t,children:a(`common.cancel`)}),(0,G.jsx)(Q,{type:`submit`,disabled:!o.trim()||r,children:r?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):a(e?`common.save`:`projects.create`)})]})]})]})})}function OKe({projectId:e,altText:t}){let n=(0,y.useRef)(null),[r,i]=(0,y.useState)(!1),[a,o]=(0,y.useState)(null);return(0,G.jsxs)(`div`,{ref:n,className:`relative flex-shrink-0`,onMouseEnter:()=>{if(!n.current)return;let e=n.current.getBoundingClientRect(),t=window.innerWidth,r=window.innerHeight,a=e.right+8;a+384>t-8&&(a=e.left-384-8);let s=e.top;s+384>r-8&&(s=r-384-8),s<8&&(s=8),o({left:a,top:s}),i(!0)},onMouseLeave:()=>i(!1),onClick:e=>e.stopPropagation(),children:[(0,G.jsx)(`div`,{className:`w-10 h-10 rounded-lg overflow-hidden bg-bambu-dark border border-bambu-dark-tertiary`,children:(0,G.jsx)(`img`,{src:Z.getProjectCoverImageUrl(e),alt:t,className:`w-full h-full object-cover`,loading:`lazy`})}),r&&a&&(0,At.createPortal)((0,G.jsx)(`div`,{className:`fixed z-[100] w-96 h-96 rounded-lg overflow-hidden border border-bambu-dark-tertiary shadow-2xl bg-bambu-dark pointer-events-none`,style:{left:a.left,top:a.top},"aria-hidden":`true`,children:(0,G.jsx)(`img`,{src:Z.getProjectCoverImageUrl(e),alt:``,className:`w-full h-full object-contain`,loading:`lazy`})}),document.body)]})}function kKe({project:e,parentName:t,onClick:n,onEdit:r,onDelete:i,hasPermission:a,t:o}){let s=e.target_count?Math.round(e.archive_count/e.target_count*100):0,c=e.target_parts_count?Math.round(e.completed_count/e.target_parts_count*100):0,l=e.status===`completed`,u=e.status===`archived`,[d,f]=(0,y.useState)(!1),p=l?{icon:Ss,color:`text-bambu-green`,bg:`bg-bambu-green/10`}:u?{icon:Po,color:`text-bambu-gray`,bg:`bg-bambu-gray/10`}:e.queue_count>0?{icon:js,color:`text-blue-600 dark:text-blue-400`,bg:`bg-blue-50 dark:bg-blue-400/10`}:{icon:_c,color:`text-bambu-gray`,bg:`bg-bambu-gray/10`};return(0,G.jsxs)(`div`,{className:`group relative bg-gradient-to-br from-bambu-card to-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary hover:border-bambu-green/50 hover:shadow-lg hover:shadow-bambu-green/5 transition-all duration-300 cursor-pointer overflow-hidden`,onClick:n,children:[(0,G.jsx)(`div`,{className:`absolute top-0 left-0 w-1.5 h-full`,style:{backgroundColor:e.color||`#6b7280`,boxShadow:`0 0 12px ${e.color||`#6b7280`}40`}}),(0,G.jsxs)(`div`,{className:`p-5 pl-6`,children:[(0,G.jsxs)(`div`,{className:`flex items-start justify-between mb-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 flex-1`,children:[e.cover_image_filename?(0,G.jsx)(OKe,{projectId:e.id,altText:o(`projects.coverImageAlt`)}):(0,G.jsx)(`div`,{className:`p-2 rounded-lg ${p.bg} flex-shrink-0`,children:(0,G.jsx)(p.icon,{className:`w-5 h-5 ${p.color}`})}),(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,G.jsx)(`h3`,{className:`font-semibold text-white truncate`,children:e.name}),e.url&&(0,G.jsx)(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,onClick:e=>e.stopPropagation(),title:e.url,"aria-label":o(`projects.openExternalUrl`),className:`inline-flex items-center justify-center w-6 h-6 rounded bg-bambu-dark border border-bambu-dark-tertiary text-bambu-green hover:bg-bambu-green/10 hover:border-bambu-green transition-colors flex-shrink-0`,children:(0,G.jsx)(rc,{className:`w-3.5 h-3.5`})}),e.target_parts_count?(0,G.jsxs)(`span`,{className:`text-xs px-2 py-0.5 rounded-full whitespace-nowrap font-medium ${c>=100?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark text-bambu-gray`}`,children:[e.completed_count,`/`,e.target_parts_count,` `,o(`projects.parts`)]}):e.target_count?(0,G.jsxs)(`span`,{className:`text-xs px-2 py-0.5 rounded-full whitespace-nowrap font-medium ${s>=100?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark text-bambu-gray`}`,children:[e.archive_count,`/`,e.target_count,` `,o(`projects.plates`)]}):e.completed_count>0?(0,G.jsxs)(`span`,{className:`text-xs px-2 py-0.5 rounded-full whitespace-nowrap font-medium bg-bambu-dark text-bambu-gray`,children:[e.completed_count,` `,o(`projects.parts`)]}):null,l&&(0,G.jsx)(`span`,{className:`text-xs bg-bambu-green/20 text-bambu-green px-2 py-0.5 rounded-full whitespace-nowrap`,children:o(`projects.done`)}),u&&(0,G.jsx)(`span`,{className:`text-xs bg-bambu-gray/20 text-bambu-gray px-2 py-0.5 rounded-full whitespace-nowrap`,children:o(`projects.statusArchived`)}),e.child_count>0&&(0,G.jsxs)(`span`,{className:`text-xs bg-bambu-dark text-bambu-gray px-2 py-0.5 rounded-full whitespace-nowrap inline-flex items-center gap-1`,title:o(`projects.subProjectCount`,{count:e.child_count}),children:[(0,G.jsx)(xc,{className:`w-3 h-3`}),e.child_count]})]}),t&&(0,G.jsxs)(`p`,{className:`text-xs text-bambu-gray mt-1 flex items-center gap-1`,children:[(0,G.jsx)(Jc,{className:`w-3 h-3 flex-shrink-0`}),(0,G.jsx)(`span`,{className:`truncate`,children:o(`projects.partOf`,{name:t})})]}),e.description&&(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray/70 mt-1 line-clamp-1`,children:e.description}),e.archives&&e.archives.length>0&&(()=>{let t=e.archives.map(e=>e.filament_type).filter(Boolean).flatMap(e=>e.split(`,`).map(e=>e.trim())).filter(Boolean),n=[...new Set(t)],r=e.archives.map(e=>e.filament_color).filter(Boolean).flatMap(e=>e.split(`,`).map(e=>e.trim())).filter(e=>e.startsWith(`#`)||/^[0-9A-Fa-f]{6}$/.test(e)),i=[...new Set(r)];return n.length===0&&i.length===0?null:(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mt-1.5`,children:[n.slice(0,3).map(e=>(0,G.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 bg-bambu-dark text-bambu-gray rounded`,children:e},e)),i.length>0&&(0,G.jsxs)(`div`,{className:`flex items-center gap-0.5`,children:[i.slice(0,5).map(e=>(0,G.jsx)(`div`,{className:`w-3 h-3 rounded-full border border-black/20`,style:{backgroundColor:e.startsWith(`#`)?e:`#${e}`},title:e},e)),i.length>5&&(0,G.jsxs)(`span`,{className:`text-[10px] text-bambu-gray ml-0.5`,children:[`+`,i.length-5]})]})]})})()]})]}),(0,G.jsxs)(`div`,{className:`relative`,onClick:e=>e.stopPropagation(),children:[(0,G.jsx)(`button`,{className:`p-1.5 rounded-lg hover:bg-bambu-dark text-bambu-gray hover:text-white transition-colors can-hover:opacity-0 group-hover:opacity-100 focus-visible:opacity-100`,onClick:()=>f(!d),children:(0,G.jsx)($s,{className:`w-4 h-4`})}),d&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`fixed inset-0 z-10`,onClick:()=>f(!1)}),(0,G.jsxs)(`div`,{className:`absolute right-0 top-8 z-20 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl py-1 min-w-[120px]`,children:[(0,G.jsxs)(`button`,{className:`w-full px-3 py-2 text-left text-sm flex items-center gap-2 ${a(`projects:update`)?`text-white hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{a(`projects:update`)&&(r(),f(!1))},disabled:!a(`projects:update`),title:a(`projects:update`)?void 0:o(`projects.noEditPermission`),children:[(0,G.jsx)(Ol,{className:`w-4 h-4`}),o(`common.edit`)]}),(0,G.jsxs)(`button`,{className:`w-full px-3 py-2 text-left text-sm flex items-center gap-2 ${a(`projects:delete`)?`text-red-600 dark:text-red-400 hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{a(`projects:delete`)&&(i(),f(!1))},disabled:!a(`projects:delete`),title:a(`projects:delete`)?void 0:o(`projects.noDeletePermission`),children:[(0,G.jsx)(Pu,{className:`w-4 h-4`}),o(`common.delete`)]})]})]})]})]}),(0,G.jsx)(`div`,{className:`mb-4`,children:e.target_count||e.target_parts_count?(0,G.jsxs)(`div`,{className:`space-y-3`,children:[e.target_count&&(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between text-xs mb-1`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:o(`projects.plates`)}),(0,G.jsxs)(`span`,{className:s>=100?`text-bambu-green font-medium`:`text-white`,children:[e.archive_count,` / `,e.target_count]})]}),(0,G.jsx)(`div`,{className:`h-2 bg-bambu-dark/80 rounded-full overflow-hidden backdrop-blur-sm`,children:(0,G.jsx)(`div`,{className:`h-full transition-all duration-500 ease-out rounded-full relative`,style:{width:`${Math.min(s,100)}%`,background:s>=100?`linear-gradient(90deg, #22c55e, #4ade80)`:`linear-gradient(90deg, ${e.color||`#6b7280`}, ${e.color||`#6b7280`}cc)`,boxShadow:`0 0 8px ${s>=100?`#22c55e`:e.color||`#6b7280`}60`}})})]}),e.target_parts_count&&(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between text-xs mb-1`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:o(`projects.parts`)}),(0,G.jsxs)(`span`,{className:c>=100?`text-bambu-green font-medium`:`text-white`,children:[e.completed_count,` / `,e.target_parts_count]})]}),(0,G.jsx)(`div`,{className:`h-2 bg-bambu-dark/80 rounded-full overflow-hidden backdrop-blur-sm`,children:(0,G.jsx)(`div`,{className:`h-full transition-all duration-500 ease-out rounded-full relative`,style:{width:`${Math.min(c,100)}%`,background:c>=100?`linear-gradient(90deg, #22c55e, #4ade80)`:`linear-gradient(90deg, ${e.color||`#6b7280`}, ${e.color||`#6b7280`}cc)`,boxShadow:`0 0 8px ${c>=100?`#22c55e`:e.color||`#6b7280`}60`}})})]}),e.failed_count>0&&(0,G.jsxs)(`div`,{className:`text-xs text-red-600 dark:text-red-400`,children:[e.failed_count,` `,o(`projects.failed`)]})]}):e.completed_count>0||e.failed_count>0?(0,G.jsxs)(`div`,{className:`flex items-center gap-4 text-xs`,children:[e.completed_count>0&&(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 text-bambu-gray`,children:[(0,G.jsx)(Po,{className:`w-3.5 h-3.5`}),(0,G.jsxs)(`span`,{children:[e.completed_count,` `,o(`projects.completed`)]})]}),e.failed_count>0&&(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 text-red-600 dark:text-red-400`,children:[(0,G.jsx)(Lu,{className:`w-3.5 h-3.5`}),(0,G.jsxs)(`span`,{children:[e.failed_count,` `,o(`projects.failed`)]})]}),e.queue_count>0&&(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 text-blue-600 dark:text-blue-400`,children:[(0,G.jsx)(js,{className:`w-3.5 h-3.5`}),(0,G.jsxs)(`span`,{children:[e.queue_count,` `,o(`projects.inQueue`)]})]})]}):(0,G.jsx)(`div`,{className:`text-xs text-bambu-gray/60 italic`,children:o(`projects.noPrintsYet`)})}),e.archives&&e.archives.length>0&&(0,G.jsxs)(`div`,{className:`mb-4`,children:[(0,G.jsx)(`div`,{className:`grid grid-cols-4 gap-1.5`,children:e.archives.slice(0,4).map(e=>(0,G.jsxs)(`div`,{className:`relative aspect-square rounded-lg bg-bambu-dark overflow-hidden border border-bambu-dark-tertiary`,title:e.print_name||`Unknown`,children:[e.thumbnail_path?(0,G.jsx)(`img`,{src:Z.getArchiveThumbnail(e.id),alt:e.print_name||``,className:`w-full h-full object-cover`}):(0,G.jsx)(`div`,{className:`w-full h-full flex items-center justify-center text-bambu-gray/50`,children:(0,G.jsx)(Cl,{className:`w-6 h-6`})}),e.status===`failed`&&(0,G.jsx)(`div`,{className:`absolute inset-0 bg-red-500/40 flex items-center justify-center`,children:(0,G.jsx)(Lu,{className:`w-4 h-4 text-white`})})]},e.id))}),e.archive_count>4&&(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1.5 text-center`,children:o(`common.more`,{count:e.archive_count-4})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between pt-3 border-t border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-4 text-xs text-bambu-gray`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5`,title:o(`projects.printJobs`),children:[(0,G.jsx)(Jc,{className:`w-3.5 h-3.5 text-blue-600 dark:text-blue-400`}),(0,G.jsxs)(`span`,{children:[e.archive_count,` `,o(`projects.plates`)]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5`,title:o(`projects.partsPrinted`),children:[(0,G.jsx)(Cl,{className:`w-3.5 h-3.5 text-bambu-green`}),(0,G.jsxs)(`span`,{children:[e.completed_count,` `,o(`projects.parts`)]})]}),e.failed_count>0&&(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 text-red-600 dark:text-red-400`,title:o(`projects.failedParts`),children:[(0,G.jsx)(Lu,{className:`w-3.5 h-3.5`}),(0,G.jsx)(`span`,{children:e.failed_count})]}),e.queue_count>0&&(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 text-yellow-600 dark:text-yellow-400`,title:o(`projects.inQueue`),children:[(0,G.jsx)($c,{className:`w-3.5 h-3.5`}),(0,G.jsx)(`span`,{children:e.queue_count})]})]}),(0,G.jsx)(ms,{className:`w-4 h-4 text-bambu-gray/50 group-hover:text-bambu-gray transition-colors`})]})]})]})}function AKe(){let{t:e}=U(),t=or(),n=co(),{showToast:r}=qd(),{hasPermission:i}=Nd(),[a,o]=(0,y.useState)(!1),[s,c]=(0,y.useState)(),[l,u]=(0,y.useState)(`active`),[d,f]=(0,y.useState)(null),[p,m]=(0,y.useState)(()=>localStorage.getItem(`projects-collapse-subprojects`)===`true`),[h,g]=(0,y.useState)({}),_=()=>{let e=!p;m(e),g({}),localStorage.setItem(`projects-collapse-subprojects`,String(e))},{data:v}=K({queryKey:[`settings`],queryFn:Z.getSettings}),b=Lf(v?.currency||`USD`),{data:x,isLoading:S}=K({queryKey:[`projects`,l===`all`?void 0:l],queryFn:()=>Z.getProjects(l===`all`?void 0:l)}),{data:C}=K({queryKey:[`projects`,void 0],queryFn:()=>Z.getProjects()}),w=new Map((C||[]).map(e=>[e.id,e.name])),T=x||[],E=new Set(T.map(e=>e.id)),D=new Map;for(let e of T)if(e.parent_id!==null&&E.has(e.parent_id)){let t=D.get(e.parent_id)||[];t.push(e),D.set(e.parent_id,t)}let O=new Set,k=e=>{if(!O.has(e)){O.add(e);for(let t of D.get(e)||[])k(t.id)}},A=[];for(let e of T)e.parent_id!==null&&E.has(e.parent_id)||(A.push(e),k(e.id));for(let e of T)O.has(e.id)||(A.push(e),k(e.id));let j=(t,n,r)=>{let a=(0,G.jsx)(kKe,{project:t,parentName:n===0&&t.parent_id!==null?w.get(t.parent_id):void 0,onClick:()=>ee(t),onEdit:()=>V(t),onDelete:()=>te(t.id),hasPermission:i,t:e}),o=new Set(r).add(t.id),s=(D.get(t.id)||[]).filter(e=>!o.has(e.id));if(s.length===0)return(0,G.jsx)(`div`,{children:a},t.id);let c=h[t.id]??!p;return(0,G.jsxs)(`div`,{className:c?`col-span-full space-y-4`:`space-y-4`,children:[a,(0,G.jsxs)(`div`,{className:`ml-4 md:ml-8 pl-4 md:pl-6 border-l-2 rounded-l space-y-4`,style:{borderColor:t.color||`#6b7280`},children:[(0,G.jsxs)(`button`,{type:`button`,onClick:()=>g(e=>({...e,[t.id]:!c})),"aria-expanded":c,title:e(c?`projects.collapseSubProjects`:`projects.expandSubProjects`),className:`text-xs uppercase tracking-wide text-bambu-gray hover:text-white transition-colors flex items-center gap-1.5 max-w-full min-w-0`,children:[c?(0,G.jsx)(ps,{className:`w-3.5 h-3.5 flex-shrink-0`}):(0,G.jsx)(ms,{className:`w-3.5 h-3.5 flex-shrink-0`}),(0,G.jsx)(xc,{className:`w-3.5 h-3.5 flex-shrink-0`}),(0,G.jsx)(`span`,{className:`truncate`,children:e(`projects.subProjectsOf`,{name:t.name})}),(0,G.jsx)(`span`,{className:`px-1.5 py-0.5 rounded-full bg-bambu-dark normal-case tracking-normal flex-shrink-0`,children:s.length})]}),c&&(0,G.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-8`,children:s.map(e=>j(e,n+1,o))})]})]},t.id)},M=q({mutationFn:e=>Z.createProject(e),onSuccess:()=>{n.invalidateQueries({queryKey:[`projects`]}),o(!1),r(e(`projects.toast.created`),`success`)},onError:e=>{r(e.message,`error`)}}),N=q({mutationFn:({id:e,data:t})=>Z.updateProject(e,t),onSuccess:()=>{n.invalidateQueries({queryKey:[`projects`]}),o(!1),c(void 0),r(e(`projects.toast.updated`),`success`)},onError:e=>{r(e.message,`error`)}}),P=q({mutationFn:e=>Z.deleteProject(e),onSuccess:()=>{f(null),r(e(`projects.toast.deleted`),`success`),setTimeout(()=>window.location.reload(),100)},onError:e=>{f(null),r(e.message,`error`)}}),F=q({mutationFn:e=>Z.importProject(e),onSuccess:()=>{n.invalidateQueries({queryKey:[`projects`]}),r(e(`projects.toast.imported`),`success`)},onError:e=>{r(e.message,`error`)}}),I=(0,y.useRef)(null),L=async()=>{try{let t=await Z.getProjects(),n=await Promise.all(t.map(async e=>await Z.exportProjectJson(e.id))),i=new Blob([JSON.stringify(n,null,2)],{type:`application/json`}),a=URL.createObjectURL(i),o=document.createElement(`a`);o.href=a,o.download=`bambuddy_projects_${new Date().toISOString().split(`T`)[0]}.json`,o.click(),URL.revokeObjectURL(a),r(e(`projects.toast.exported`),`success`)}catch(e){r(e.message,`error`)}},R=()=>{I.current?.click()},z=async t=>{let i=t.target.files?.[0];if(i){try{if(i.name.toLowerCase().endsWith(`.zip`))await Z.importProjectFile(i),n.invalidateQueries({queryKey:[`projects`]}),r(e(`projects.toast.imported`),`success`);else{let t=await i.text(),n=JSON.parse(t),a=Array.isArray(n)?n:[n];for(let e of a)await F.mutateAsync(e);a.length>1&&r(e(`projects.toast.multipleImported`,{count:a.length}),`success`)}}catch(t){r(`${e(`projects.toast.importFailed`)}: ${t.message}`,`error`)}t.target.value=``}},B=e=>{s?N.mutate({id:s.id,data:e}):M.mutate(e)},V=e=>{c(e),o(!0)},ee=e=>{t(`/projects/${e.id}`)},te=e=>{f(e)},ne=()=>{d!==null&&P.mutate(d)},re=C?.reduce((e,t)=>(e[t.status]=(e[t.status]||0)+1,e.all=(e.all||0)+1,e),{})||{};return(0,G.jsxs)(`div`,{className:`p-4 md:p-8 space-y-8`,children:[(0,G.jsx)(`input`,{ref:I,type:`file`,accept:`.json,.zip`,onChange:z,className:`hidden`}),(0,G.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between gap-4`,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)(_c,{className:`w-7 h-7 text-bambu-green`}),e(`projects.title`)]}),(0,G.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:e(`projects.subtitle`)})]}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsxs)(Q,{variant:`secondary`,onClick:R,disabled:!i(`projects:create`),title:i(`projects:create`)?e(`projects.importProject`):e(`projects.noImportPermission`),children:[(0,G.jsx)(Vu,{className:`w-4 h-4 mr-2`}),e(`projects.import`)]}),(0,G.jsxs)(Q,{variant:`secondary`,onClick:L,disabled:!i(`projects:read`),title:i(`projects:read`)?e(`projects.exportAll`):e(`projects.noExportPermission`),children:[(0,G.jsx)(Xs,{className:`w-4 h-4 mr-2`}),e(`projects.export`)]}),(0,G.jsxs)(Q,{onClick:()=>o(!0),className:`sm:w-auto w-full`,disabled:!i(`projects:create`),title:i(`projects:create`)?void 0:e(`projects.noCreatePermission`),children:[(0,G.jsx)(Fl,{className:`w-4 h-4 mr-2`}),e(`projects.newProject`)]})]})]}),(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`flex gap-1 p-1 bg-bambu-dark rounded-xl w-fit`,children:[{key:`active`,label:e(`projects.statusActive`),icon:js},{key:`completed`,label:e(`projects.statusCompleted`),icon:Ss},{key:`archived`,label:e(`projects.statusArchived`),icon:Po},{key:`all`,label:e(`common.all`),icon:_c}].map(({key:e,label:t,icon:n})=>(0,G.jsxs)(`button`,{onClick:()=>u(e),className:`flex items-center gap-2 px-4 py-2 text-sm rounded-lg transition-all ${l===e?`bg-bambu-card text-white shadow-sm`:`text-bambu-gray hover:text-white`}`,children:[(0,G.jsx)(n,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{children:t}),re[e]>0&&(0,G.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded-full ${l===e?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark-tertiary`}`,children:re[e]})]},e))}),D.size>0&&(0,G.jsxs)(`button`,{type:`button`,onClick:_,"aria-pressed":p,title:e(p?`projects.expandSubProjects`:`projects.collapseSubProjects`),className:`flex items-center gap-2 px-3 py-1.5 text-sm rounded-lg transition-colors ${p?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:text-white hover:bg-bambu-dark`}`,children:[(0,G.jsx)(xc,{className:`w-4 h-4`}),e(`common.collapse`)]})]}),S?(0,G.jsx)(`div`,{className:`flex items-center justify-center py-20`,children:(0,G.jsxs)(`div`,{className:`flex flex-col items-center gap-3`,children:[(0,G.jsx)(Y,{className:`w-8 h-8 animate-spin text-bambu-green`}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`projects.loading`)})]})}):x?.length===0?(0,G.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-20 px-4`,children:[(0,G.jsx)(`div`,{className:`p-4 bg-bambu-dark rounded-2xl mb-4`,children:(0,G.jsx)(_c,{className:`w-12 h-12 text-bambu-gray/50`})}),(0,G.jsx)(`h3`,{className:`text-lg font-medium text-white mb-2`,children:l===`all`?e(`projects.noProjects`):e(`projects.noProjectsFiltered`,{status:l})}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-center max-w-md mb-6`,children:l===`all`?e(`projects.createFirst`):e(`projects.noProjectsFilteredHelp`,{status:l})}),l===`all`&&(0,G.jsxs)(Q,{onClick:()=>o(!0),disabled:!i(`projects:create`),title:i(`projects:create`)?void 0:e(`projects.noCreatePermission`),children:[(0,G.jsx)(Fl,{className:`w-4 h-4 mr-2`}),e(`projects.createFirstButton`)]})]}):(0,G.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-8`,children:A.map(e=>j(e,0,new Set))}),d!==null&&(0,G.jsx)(of,{title:e(`projects.deleteProject`),message:e(`projects.deleteConfirm`),confirmText:e(`projects.deleteProject`),variant:`danger`,onConfirm:ne,onCancel:()=>f(null)}),a&&(0,G.jsx)(j5,{project:s,onClose:()=>{o(!1),c(void 0)},onSave:B,isLoading:M.isPending||N.isPending,currencySymbol:b,t:e})]})}function M5(e){let t=(e.file_type||``).toLowerCase();if(t===`gcode`||t===`gcode.3mf`)return!0;let n=(e.filename||``).toLowerCase();return n.endsWith(`.gcode`)||n.endsWith(`.gcode.3mf`)}function N5(e,t,n){return M5(e)?!1:t?fje(e.filename):dje(e.filename,n)}function P5(e){return e>=1e3?`${(e/1e3).toFixed(2)}kg`:`${Math.round(e)}g`}function jKe({status:e,t}){let n={active:`bg-bambu-green/20 text-bambu-green`,completed:`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`,archived:`bg-bambu-gray/20 text-bambu-gray`},r=n[e]||n.active,i={active:t(`projectDetail.status.active`),completed:t(`projectDetail.status.completed`),archived:t(`projectDetail.status.archived`)};return(0,G.jsx)(`span`,{className:`px-2 py-1 rounded text-sm font-medium ${r}`,children:i[e]||e.charAt(0).toUpperCase()+e.slice(1)})}function F5({icon:e,label:t,value:n,subValue:r,hint:i,color:a=`text-bambu-gray`}){return(0,G.jsx)(zd,{children:(0,G.jsx)(Vd,{className:`p-4`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,title:i,children:[(0,G.jsx)(`div`,{className:`p-2 rounded-lg bg-bambu-dark ${a}`,children:(0,G.jsx)(e,{className:`w-5 h-5`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:t}),(0,G.jsx)(`p`,{className:`text-xl font-semibold text-white`,children:n}),r&&(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray/70`,children:r})]})]})})})}function MKe({archives:e,t}){return e.length===0?(0,G.jsxs)(`div`,{className:`text-center py-8 text-bambu-gray`,children:[(0,G.jsx)(Cl,{className:`w-12 h-12 mx-auto mb-2 opacity-50`}),(0,G.jsx)(`p`,{children:t(`projectDetail.noPrints`)})]}):(0,G.jsx)(`div`,{className:`grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 xl:grid-cols-6 gap-3`,children:e.map(e=>(0,G.jsxs)(Ai,{to:`/archives?search=${encodeURIComponent(e.print_name||``)}`,className:`group relative aspect-square rounded-lg bg-bambu-dark border border-bambu-dark-tertiary overflow-hidden hover:border-bambu-green transition-colors`,children:[e.thumbnail_path?(0,G.jsx)(`img`,{src:Z.getArchiveThumbnail(e.id),alt:e.print_name||`Print`,className:`w-full h-full object-cover`}):(0,G.jsx)(`div`,{className:`w-full h-full flex items-center justify-center text-bambu-gray`,children:(0,G.jsx)(Cl,{className:`w-8 h-8`})}),e.status===`failed`&&(0,G.jsx)(`div`,{className:`absolute inset-0 bg-red-500/30 flex items-center justify-center`,children:(0,G.jsx)(Ds,{className:`w-8 h-8 text-white`})}),e.status===`completed`&&(0,G.jsx)(`div`,{className:`absolute top-1 right-1`,children:(0,G.jsx)(xs,{className:`w-4 h-4 text-bambu-green`})}),(0,G.jsx)(`div`,{className:`absolute inset-x-0 bottom-0 bg-gradient-to-t from-black/80 to-transparent p-2 opacity-0 group-hover:opacity-100 transition-opacity`,children:(0,G.jsx)(`p`,{className:`text-xs text-white truncate`,children:e.print_name||`Unknown`})})]},e.id))})}function NKe({priority:e,t}){let n={low:{color:`bg-gray-500/20 text-gray-400`,label:t(`projectDetail.priority.low`)},normal:{color:`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`,label:t(`projectDetail.priority.normal`)},high:{color:`bg-orange-100 dark:bg-orange-500/20 text-orange-700 dark:text-orange-400`,label:t(`projectDetail.priority.high`)},urgent:{color:`bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400`,label:t(`projectDetail.priority.urgent`)}},{color:r,label:i}=n[e]||n.normal;return(0,G.jsxs)(`span`,{className:`px-2 py-1 rounded text-xs font-medium flex items-center gap-1 ${r}`,children:[e===`urgent`&&(0,G.jsx)(Lu,{className:`w-3 h-3`}),i]})}function I5(e,t){if(!e)return null;let n=rp(e);if(!n)return null;let r=new Date,i=Math.ceil((n.getTime()-r.getTime())/(1e3*60*60*24));return i<0?{color:`text-red-700 dark:text-red-400`,label:t(`projectDetail.dueDate.overdue`)}:i===0?{color:`text-orange-700 dark:text-orange-400`,label:t(`projectDetail.dueDate.today`)}:i<=3?{color:`text-yellow-700 dark:text-yellow-400`,label:t(`projectDetail.dueDate.daysLeft`,{count:i})}:{color:`text-bambu-gray`,label:t(`projectDetail.dueDate.daysLeft`,{count:i})}}function PKe(){let{id:e}=dr(),t=or(),{t:n}=U(),r=co(),{showToast:i}=qd(),{hasPermission:a}=Nd(),[o,s]=(0,y.useState)(!1),[c,l]=(0,y.useState)(!1),[u,d]=(0,y.useState)(``),[f,p]=(0,y.useState)(null),m=parseInt(e||`0`,10),{data:h,isLoading:g,error:_}=K({queryKey:[`project`,m],queryFn:()=>Z.getProject(m),enabled:m>0}),{data:v,isLoading:b}=K({queryKey:[`project-archives`,m],queryFn:()=>Z.getProjectArchives(m),enabled:m>0}),{data:x,isLoading:S}=K({queryKey:[`project-bom`,m],queryFn:()=>Z.getProjectBOM(m),enabled:m>0}),{data:C,isLoading:w}=K({queryKey:[`project-timeline`,m],queryFn:()=>Z.getProjectTimeline(m,20),enabled:m>0}),{data:T}=K({queryKey:[`settings`],queryFn:Z.getSettings}),{data:E}=K({queryKey:[`project-folders`,m],queryFn:()=>Z.getLibraryFoldersByProject(m),enabled:m>0}),{data:D,isLoading:O}=K({queryKey:[`project-files`,m],queryFn:()=>Z.getLibraryFiles(null,!1,m),enabled:m>0}),k=(0,y.useMemo)(()=>{let e=new Map;for(let t of D??[])if(t.folder_id!=null){let n=e.get(t.folder_id)??[];n.push(t),e.set(t.folder_id,n)}return e},[D]),{data:A}=K({queryKey:[`project-file-progress`,m],queryFn:()=>Z.getProjectFileProgress(m),enabled:m>0}),j=(0,y.useMemo)(()=>{let e=new Map;for(let t of A??[])e.set(t.file_id,t.completed_count);return e},[A]),M=(0,y.useMemo)(()=>{let e=h?.target_sets;if(!e||!D)return null;let t=D.filter(e=>M5(e));return t.length===0?null:Math.min(...t.map(t=>Math.min(j.get(t.id)??0,e)))},[h?.target_sets,D,j]),N=Lf(T?.currency||`USD`),P=T?.time_format||`system`,F=q({mutationFn:e=>Z.updateProject(m,e),onSuccess:()=>{r.invalidateQueries({queryKey:[`project`,m]}),r.invalidateQueries({queryKey:[`projects`]}),s(!1),l(!1),i(n(`projectDetail.toast.projectUpdated`),`success`)},onError:e=>{i(e.message,`error`)}}),I=()=>{d(h?.notes||``),l(!0)},L=()=>{F.mutate({notes:u})},R=()=>{l(!1),d(``)},[z,B]=(0,y.useState)(``),[V,ee]=(0,y.useState)(1),[te,ne]=(0,y.useState)(``),[re,ie]=(0,y.useState)(``),[ae,oe]=(0,y.useState)(``),[se,H]=(0,y.useState)(!1),[ce,le]=(0,y.useState)(!1),[ue,de]=(0,y.useState)(null),[fe,pe]=(0,y.useState)(``),[me,he]=(0,y.useState)(1),[ge,_e]=(0,y.useState)(``),[ve,ye]=(0,y.useState)(``),[be,xe]=(0,y.useState)(``),[Se,Ce]=(0,y.useState)({isOpen:!1,title:``,message:``,onConfirm:()=>{}}),we=q({mutationFn:e=>Z.createBOMItem(m,e),onSuccess:()=>{r.invalidateQueries({queryKey:[`project-bom`,m]}),r.invalidateQueries({queryKey:[`project`,m]}),B(``),ee(1),ne(``),ie(``),oe(``),H(!1),i(n(`projectDetail.toast.partAdded`),`success`)},onError:e=>i(e.message,`error`)}),Te=q({mutationFn:({itemId:e,data:t})=>Z.updateBOMItem(m,e,t),onSuccess:()=>{r.invalidateQueries({queryKey:[`project-bom`,m]}),r.invalidateQueries({queryKey:[`project`,m]}),de(null)},onError:e=>i(e.message,`error`)}),Ee=q({mutationFn:e=>Z.deleteBOMItem(m,e),onSuccess:()=>{r.invalidateQueries({queryKey:[`project-bom`,m]}),r.invalidateQueries({queryKey:[`project`,m]}),i(n(`projectDetail.toast.partRemoved`),`success`)},onError:e=>i(e.message,`error`)}),De=e=>{e.preventDefault(),z.trim()&&we.mutate({name:z.trim(),quantity_needed:V,unit_price:te?parseFloat(te):void 0,sourcing_url:re.trim()||void 0,remarks:ae.trim()||void 0})},Oe=e=>{let t=e.is_complete?0:e.quantity_needed;Te.mutate({itemId:e.id,data:{quantity_acquired:t}})},ke=(e,t)=>{Ce({isOpen:!0,title:n(`projectDetail.bom.deletePart`),message:n(`projectDetail.bom.deleteConfirm`,{name:t}),onConfirm:()=>{Ce(e=>({...e,isOpen:!1})),Ee.mutate(e)}})},Ae=e=>{de(e),pe(e.name),he(e.quantity_needed),_e(e.unit_price?.toString()||``),ye(e.sourcing_url||``),xe(e.remarks||``)},je=e=>{e.preventDefault(),!(!ue||!fe.trim())&&Te.mutate({itemId:ue.id,data:{name:fe.trim(),quantity_needed:me,unit_price:ge?parseFloat(ge):void 0,sourcing_url:ve.trim()||void 0,remarks:be.trim()||void 0}})},Me=()=>{de(null)},Ne=async()=>{try{let{blob:e,filename:t}=await Z.exportProjectZip(Number(m)),r=URL.createObjectURL(e),a=document.createElement(`a`);a.href=r,a.download=t||`${h?.name||`project`}_${new Date().toISOString().split(`T`)[0]}.zip`,a.click(),URL.revokeObjectURL(r),i(n(`projectDetail.toast.projectExported`),`success`)}catch(e){i(e.message,`error`)}},Pe=q({mutationFn:()=>Z.createTemplateFromProject(m),onSuccess:()=>{r.invalidateQueries({queryKey:[`projects`]}),i(n(`projectDetail.toast.templateCreated`),`success`)},onError:e=>i(e.message,`error`)}),Fe=e=>op(e,P,{month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`});if(g)return(0,G.jsx)(`div`,{className:`flex items-center justify-center py-24`,children:(0,G.jsx)(Y,{className:`w-8 h-8 animate-spin text-bambu-green`})});if(_||!h)return(0,G.jsxs)(`div`,{className:`text-center py-24`,children:[(0,G.jsx)(`p`,{className:`text-bambu-gray`,children:_?`${n(`common.error`)}: ${_.message}`:n(`projectDetail.notFound`)}),(0,G.jsx)(Q,{variant:`secondary`,className:`mt-4`,onClick:()=>t(`/projects`),children:n(`projectDetail.backToProjects`)})]});let Ie=h.stats,Le=Ie?.progress_percent??0,Re=Ie?.parts_progress_percent??0;return(0,G.jsxs)(`div`,{className:`p-4 md:p-8 space-y-8`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-bambu-gray`,children:[(0,G.jsx)(Ai,{to:`/projects`,className:`hover:text-white transition-colors`,children:n(`nav.projects`)}),(0,G.jsx)(ms,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`text-white`,children:h.name})]}),(0,G.jsxs)(`div`,{className:`flex items-start justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,G.jsx)(`button`,{onClick:()=>t(`/projects`),className:`p-2 rounded-lg bg-bambu-card hover:bg-bambu-dark-tertiary transition-colors`,children:(0,G.jsx)(Lo,{className:`w-5 h-5 text-bambu-gray`})}),(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`w-4 h-4 rounded-full shrink-0`,style:{backgroundColor:h.color||`#6b7280`}}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h1`,{className:`text-2xl font-bold text-white`,children:h.name}),h.description&&(0,G.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:h.description})]})]}),(0,G.jsx)(jKe,{status:h.status,t:n})]}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsxs)(Q,{variant:`secondary`,onClick:Ne,disabled:!a(`projects:read`),title:a(`projects:read`)?n(`projectDetail.exportProject`):n(`projectDetail.noExportPermission`),children:[(0,G.jsx)(Xs,{className:`w-4 h-4 mr-2`}),n(`projectDetail.export`)]}),(0,G.jsxs)(Q,{onClick:()=>s(!0),disabled:!a(`projects:update`),title:a(`projects:update`)?void 0:n(`projectDetail.noEditPermission`),children:[(0,G.jsx)(Ol,{className:`w-4 h-4 mr-2`}),n(`common.edit`)]})]})]}),(h.target_count||h.target_parts_count||h.target_sets)&&(0,G.jsx)(zd,{children:(0,G.jsxs)(Vd,{className:`p-4 space-y-4`,children:[h.target_count&&(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:n(`projectDetail.progress.platesProgress`)}),(0,G.jsxs)(`span`,{className:`text-sm font-medium text-white`,children:[Ie?.total_archives||0,` / `,h.target_count,` `,n(`projectDetail.progress.printJobs`)]})]}),(0,G.jsx)(`div`,{className:`h-3 bg-bambu-dark rounded-full overflow-hidden`,children:(0,G.jsx)(`div`,{className:`h-full transition-all duration-500`,style:{width:`${Math.min(Le,100)}%`,backgroundColor:Le>=100?`#22c55e`:h.color||`#6b7280`}})}),(0,G.jsxs)(`div`,{className:`flex justify-between mt-1`,children:[(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray/70`,children:n(`projectDetail.progress.percentComplete`,{percent:Le.toFixed(0)})}),Ie?.remaining_prints!=null&&Ie.remaining_prints>0&&(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray/70`,children:n(`projectDetail.progress.remaining`,{count:Ie.remaining_prints})})]})]}),h.target_parts_count&&(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:n(`projectDetail.progress.partsProgress`)}),(0,G.jsxs)(`span`,{className:`text-sm font-medium text-white`,children:[Ie?.completed_prints||0,` / `,h.target_parts_count,` `,n(`projectDetail.progress.parts`)]})]}),(0,G.jsx)(`div`,{className:`h-3 bg-bambu-dark rounded-full overflow-hidden`,children:(0,G.jsx)(`div`,{className:`h-full transition-all duration-500`,style:{width:`${Math.min(Re,100)}%`,backgroundColor:Re>=100?`#22c55e`:h.color||`#6b7280`}})}),(0,G.jsxs)(`div`,{className:`flex justify-between mt-1`,children:[(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray/70`,children:n(`projectDetail.progress.percentComplete`,{percent:Re.toFixed(0)})}),Ie?.remaining_parts!=null&&Ie.remaining_parts>0&&(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray/70`,children:n(`projectDetail.progress.remaining`,{count:Ie.remaining_parts})})]})]}),h.target_sets?(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:n(`projectDetail.progress.setsProgress`)}),(0,G.jsxs)(`span`,{className:`text-sm font-medium text-white`,children:[M??0,` / `,h.target_sets,` `,n(`projectDetail.progress.sets`)]})]}),(0,G.jsx)(`div`,{className:`h-3 bg-bambu-dark rounded-full overflow-hidden`,children:(0,G.jsx)(`div`,{className:`h-full transition-all duration-500`,style:{width:`${Math.min((M??0)/h.target_sets*100,100)}%`,backgroundColor:(M??0)>=h.target_sets?`#22c55e`:h.color||`#6b7280`}})}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray/70 mt-1`,children:n(`projectDetail.progress.setsHint`)})]}):null]})}),Ie&&(0,G.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-4`,children:[(0,G.jsx)(zd,{children:(0,G.jsx)(Vd,{className:`p-4`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`p-2 rounded-lg bg-bambu-dark text-bambu-green`,children:(0,G.jsx)(Cl,{className:`w-5 h-5`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`projectDetail.stats.printJobs`)}),(0,G.jsxs)(`p`,{className:`text-xl font-semibold text-white`,children:[Ie.total_archives,` `,(0,G.jsx)(`span`,{className:`text-sm font-normal text-bambu-gray`,children:n(`projectDetail.stats.total`)})]}),Ie.failed_prints>0&&(0,G.jsx)(`p`,{className:`text-sm text-status-error`,children:n(`projectDetail.stats.failed`,{count:Ie.failed_prints})}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`projectDetail.stats.partsPrinted`,{count:Ie.completed_prints})})]})]})})}),(0,G.jsx)(F5,{icon:js,label:n(`projectDetail.stats.printTime`),value:fp(Ie.total_print_time_hours),color:`text-yellow-600 dark:text-yellow-400`}),(0,G.jsx)(F5,{icon:Rl,label:n(`projectDetail.stats.filamentUsed`),value:P5(Ie.total_filament_grams),color:`text-purple-600 dark:text-purple-400`})]}),h.rollup_stats&&(0,G.jsx)(zd,{children:(0,G.jsxs)(Vd,{className:`p-4`,children:[(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2 mb-3`,children:[(0,G.jsx)(xc,{className:`w-5 h-5`}),n(`projectDetail.rollup.title`,{count:h.descendant_count})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.stats.printJobs`)}),(0,G.jsx)(`p`,{className:`text-lg font-semibold text-white`,children:h.rollup_stats.total_archives}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`projectDetail.stats.partsPrinted`,{count:h.rollup_stats.completed_prints})})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.stats.printTime`)}),(0,G.jsx)(`p`,{className:`text-lg font-semibold text-white`,children:fp(h.rollup_stats.total_print_time_hours)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.stats.filamentUsed`)}),(0,G.jsx)(`p`,{className:`text-lg font-semibold text-white`,children:P5(h.rollup_stats.total_filament_grams)})]}),(()=>{let e=h.rollup_stats.estimated_cost+h.rollup_stats.total_energy_cost+h.rollup_stats.bom_cost;return e<=0?null:(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.cost.totalCost`)}),(0,G.jsxs)(`p`,{className:`text-lg font-semibold text-bambu-green`,children:[N,e.toFixed(2)]})]})})()]}),h.rollup_stats.progress_percent!==null&&(0,G.jsxs)(`div`,{className:`mt-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:n(`projectDetail.rollup.progress`)}),(0,G.jsx)(`span`,{className:`text-sm font-medium text-white`,children:n(`projectDetail.rollup.percentComplete`,{percent:h.rollup_stats.progress_percent.toFixed(0)})})]}),(0,G.jsx)(`div`,{className:`h-3 bg-bambu-dark rounded-full overflow-hidden`,children:(0,G.jsx)(`div`,{className:`h-full transition-all duration-500`,style:{width:`${Math.min(h.rollup_stats.progress_percent,100)}%`,backgroundColor:h.rollup_stats.progress_percent>=100?`#22c55e`:h.color||`#6b7280`}})})]})]})}),Ie&&(()=>{let e=Ie.estimated_cost+Ie.total_energy_cost+Ie.bom_cost;return Ie.estimated_cost>0||e>0||h.budget!==null})()&&(0,G.jsx)(zd,{children:(0,G.jsxs)(Vd,{className:`p-4`,children:[(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white mb-3`,children:n(`projectDetail.cost.title`)}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.cost.filamentCost`)}),(0,G.jsxs)(`p`,{className:`text-lg font-semibold text-white`,children:[N,Ie.estimated_cost.toFixed(2)]})]}),Ie.total_energy_kwh>0&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.cost.energy`)}),(0,G.jsxs)(`p`,{className:`text-lg font-semibold text-white`,children:[Ie.total_energy_kwh.toFixed(3),` kWh`,Ie.total_energy_cost>0&&(0,G.jsxs)(`span`,{className:`text-sm text-bambu-gray ml-1`,children:[`(`,N,Ie.total_energy_cost.toFixed(2),`)`]})]})]}),(()=>{let e=Ie.estimated_cost+Ie.total_energy_cost+Ie.bom_cost;return e<=0?null:(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.cost.totalCost`)}),(0,G.jsxs)(`p`,{className:`text-lg font-semibold text-bambu-green`,children:[N,e.toFixed(2)]}),Ie.bom_cost>0&&(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray/70`,children:n(`projectDetail.cost.includesBom`)})]})})(),h.budget!==null&&(()=>{let e=Ie.estimated_cost+Ie.total_energy_cost+Ie.bom_cost,t=h.budget-e;return(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.cost.budget`)}),(0,G.jsxs)(`p`,{className:`text-sm text-bambu-gray`,children:[n(`projectDetail.cost.total`),`: `,(0,G.jsxs)(`span`,{className:`text-white font-semibold`,children:[N,h.budget.toFixed(2)]})]}),(0,G.jsxs)(`p`,{className:`text-sm ${t>=0?`text-bambu-green`:`text-red-700 dark:text-red-400`}`,children:[n(`projectDetail.cost.remaining`),`: `,(0,G.jsxs)(`span`,{className:`font-semibold`,children:[N,t.toFixed(2)]})]})]})})()]})]})}),h.children&&h.children.length>0&&(0,G.jsx)(zd,{children:(0,G.jsxs)(Vd,{className:`p-4`,children:[(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2 mb-3`,children:[(0,G.jsx)(xc,{className:`w-5 h-5`}),n(`projectDetail.subProjects.title`,{count:h.children.length})]}),(0,G.jsx)(`div`,{className:`space-y-2`,children:h.children.map(e=>(0,G.jsxs)(Ai,{to:`/projects/${e.id}`,className:`flex items-center justify-between gap-4 p-3 bg-bambu-dark rounded-lg hover:bg-bambu-dark-tertiary transition-colors`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0`,children:[(0,G.jsx)(`div`,{className:`w-3 h-3 rounded-full flex-shrink-0`,style:{backgroundColor:e.color||`#6b7280`}}),(0,G.jsx)(`span`,{className:`text-white truncate`,children:e.name}),(0,G.jsx)(`span`,{className:`text-xs px-2 py-0.5 rounded flex-shrink-0 ${e.status===`completed`?`bg-status-ok/20 text-status-ok`:e.status===`archived`?`bg-bambu-gray/20 text-bambu-gray`:`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`}`,children:e.status}),e.descendant_count>0&&(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray flex-shrink-0 inline-flex items-center gap-1`,children:[(0,G.jsx)(xc,{className:`w-3 h-3`}),e.descendant_count]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-4 text-sm text-bambu-gray flex-shrink-0`,children:[e.total_archives>0&&(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:n(`projectDetail.subProjects.jobs`,{count:e.total_archives})}),e.total_filament_grams>0&&(0,G.jsx)(`span`,{className:`hidden md:inline`,children:P5(e.total_filament_grams)}),e.total_cost>0&&(0,G.jsxs)(`span`,{className:`hidden md:inline`,children:[N,e.total_cost.toFixed(2)]}),e.progress_percent!==null&&(0,G.jsxs)(`span`,{children:[e.progress_percent.toFixed(0),`%`]})]})]},e.id))})]})}),h.parent_id&&h.parent_name&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,G.jsx)(Jc,{className:`w-4 h-4 text-bambu-gray`}),(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:n(`projectDetail.partOf`)}),(0,G.jsx)(Ai,{to:`/projects/${h.parent_id}`,className:`text-bambu-green hover:underline`,children:h.parent_name})]}),(h.tags||h.due_date||h.priority!==`normal`)&&(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4`,children:[h.priority&&h.priority!==`normal`&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.priorityLabel`)}),(0,G.jsx)(NKe,{priority:h.priority,t:n})]}),h.due_date&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(as,{className:`w-4 h-4 text-bambu-gray`}),(0,G.jsx)(`span`,{className:`text-sm text-white`,children:ap(h.due_date,{year:`numeric`,month:`short`,day:`numeric`})}),I5(h.due_date,n)&&(0,G.jsxs)(`span`,{className:`text-xs ${I5(h.due_date,n).color}`,children:[`(`,I5(h.due_date,n).label,`)`]})]}),h.tags&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Eu,{className:`w-4 h-4 text-bambu-gray`}),(0,G.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:h.tags.split(`,`).map((e,t)=>(0,G.jsx)(`span`,{className:`px-2 py-0.5 bg-bambu-dark-tertiary text-bambu-gray text-xs rounded`,children:e.trim()},t))})]})]}),(0,G.jsx)(zd,{children:(0,G.jsxs)(Vd,{className:`p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(fc,{className:`w-5 h-5`}),n(`projectDetail.notes.title`)]}),c?(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:R,disabled:F.isPending,children:[(0,G.jsx)(nd,{className:`w-4 h-4 mr-1`}),n(`common.cancel`)]}),(0,G.jsxs)(Q,{size:`sm`,onClick:L,disabled:F.isPending,children:[F.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin mr-1`}):(0,G.jsx)(ql,{className:`w-4 h-4 mr-1`}),n(`common.save`)]})]}):(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:I,disabled:!a(`projects:update`),title:a(`projects:update`)?void 0:n(`projectDetail.notes.noEditPermission`),children:[(0,G.jsx)(Ol,{className:`w-4 h-4 mr-1`}),n(`common.edit`)]})]}),c?(0,G.jsx)(B2,{content:u,onChange:d,placeholder:n(`projectDetail.notes.placeholder`)}):h.notes?(0,G.jsx)(`div`,{className:`prose prose-invert prose-sm max-w-none`,dangerouslySetInnerHTML:{__html:JG.sanitize(h.notes)}}):(0,G.jsx)(`p`,{className:`text-bambu-gray/70 text-sm italic`,children:n(`projectDetail.notes.empty`)})]})}),(0,G.jsx)(zd,{children:(0,G.jsxs)(Vd,{className:`p-4`,children:[(0,G.jsx)(`div`,{className:`flex items-center justify-between mb-3`,children:(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(vc,{className:`w-5 h-5`}),n(`projectDetail.files.title`)]})}),(0,G.jsxs)(`p`,{className:`text-xs text-bambu-gray mb-3`,children:[(0,G.jsx)(Ai,{to:`/files`,className:`text-bambu-green hover:underline`,children:n(`projectDetail.files.linkFolders`)}),` `,n(`projectDetail.files.forQuickAccess`)]}),E&&E.length>0?(0,G.jsx)(`div`,{className:`space-y-4`,children:E.map(e=>{let t=k.get(e.id)??[],r=O;return(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(Ai,{to:`/files?folder=${e.id}`,className:`flex items-center justify-between p-3 bg-bambu-dark rounded-lg hover:bg-bambu-dark-tertiary transition-colors mb-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0`,children:[(0,G.jsx)(vc,{className:`w-5 h-5 text-bambu-green shrink-0`}),(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsx)(`p`,{className:`text-sm text-white truncate`,children:e.name}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`projectDetail.files.fileCount`,{count:e.file_count})})]})]}),(0,G.jsx)(ms,{className:`w-4 h-4 text-bambu-gray shrink-0`})]}),r?(0,G.jsx)(`div`,{className:`flex items-center gap-2 px-3 py-2 text-bambu-gray text-sm`,children:(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`})}):t.length===0?(0,G.jsx)(`p`,{className:`text-bambu-gray/60 text-xs italic px-3`,children:n(`projectDetail.files.noFiles`)}):(0,G.jsx)(`div`,{className:`space-y-1 pl-3`,children:t.map(e=>{let t=M5(e);return(0,G.jsxs)(`div`,{className:`flex items-center gap-3 p-2 rounded-lg hover:bg-bambu-dark-tertiary transition-colors`,children:[(0,G.jsx)(`div`,{className:`w-10 h-10 shrink-0 rounded bg-bambu-dark overflow-hidden flex items-center justify-center`,children:e.thumbnail_path?(0,G.jsx)(`img`,{src:Z.getLibraryFileThumbnailUrl(e.id),alt:e.print_name||e.filename,className:`w-full h-full object-cover`}):(0,G.jsx)(sc,{className:`w-5 h-5 text-bambu-gray/40`})}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`p`,{className:`text-sm text-white truncate`,title:e.print_name||e.filename,children:e.print_name||e.filename}),(0,G.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded font-medium ${e.file_type===`3mf`?`bg-bambu-green/20 text-bambu-green`:e.file_type===`gcode`||e.file_type===`gcode.3mf`?`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`:`bg-bambu-gray/20 text-bambu-gray`}`,children:e.file_type.toUpperCase()})]}),t&&(()=>{let t=j.get(e.id)??0,r=h.target_sets;if(!r)return t>0?(0,G.jsxs)(`span`,{className:`shrink-0 text-xs px-1.5 py-0.5 rounded-full bg-bambu-dark text-bambu-gray`,title:n(`projectDetail.files.printedCount`,{count:t}),children:[t,`×`]}):null;let i=Math.min(t/r*100,100),a=t>=r?`text-status-ok`:t>0?`text-status-warning`:`text-bambu-gray`,o=t>=r?`bg-status-ok`:t>0?`bg-status-warning`:`bg-bambu-gray`;return(0,G.jsxs)(`div`,{className:`shrink-0 w-20`,title:n(`projectDetail.files.progressTooltip`,{done:t,target:r}),children:[(0,G.jsxs)(`p`,{className:`text-xs font-medium text-right ${a}`,children:[t,` / `,r]}),(0,G.jsx)(`div`,{className:`h-1 bg-bambu-dark rounded-full overflow-hidden mt-1`,children:(0,G.jsx)(`div`,{className:`h-full ${o}`,style:{width:`${i}%`}})})]})})(),t&&(0,G.jsx)(`div`,{className:`flex items-center gap-1 shrink-0`,children:(0,G.jsx)(`button`,{onClick:()=>p(e),title:n(`common.print`),className:`p-1.5 rounded hover:bg-bambu-green/20 text-bambu-green transition-colors`,children:(0,G.jsx)(Rl,{className:`w-4 h-4`})})})]},e.id)})})]},e.id)})}):(0,G.jsx)(`p`,{className:`text-bambu-gray/70 text-sm italic`,children:n(`projectDetail.files.empty`)})]})}),(0,G.jsx)(zd,{children:(0,G.jsxs)(Vd,{className:`p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-4`,children:[(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(cu,{className:`w-5 h-5`}),n(`projectDetail.bom.title`),Ie&&Ie.bom_total_items>0&&(0,G.jsxs)(`span`,{className:`text-sm font-normal text-bambu-gray`,children:[`(`,n(`projectDetail.bom.acquired`,{completed:Ie.bom_completed_items,total:Ie.bom_total_items}),`)`]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[x&&x.some(e=>e.is_complete)&&(0,G.jsx)(`button`,{onClick:()=>le(!ce),className:`text-xs px-2 py-1 rounded transition-colors ${ce?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark text-bambu-gray hover:text-white`}`,children:n(ce?`projectDetail.bom.showAll`:`projectDetail.bom.hideDone`)}),!se&&(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:()=>H(!0),disabled:!a(`projects:update`),title:a(`projects:update`)?void 0:n(`projectDetail.bom.noAddPermission`),children:[(0,G.jsx)(Fl,{className:`w-4 h-4 mr-1`}),n(`projectDetail.bom.addPart`)]})]})]}),se&&(0,G.jsxs)(`form`,{onSubmit:De,className:`bg-bambu-dark rounded-lg p-4 mb-4 space-y-3`,children:[(0,G.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-3`,children:[(0,G.jsx)(`input`,{type:`text`,value:z,onChange:e=>B(e.target.value),className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:n(`projectDetail.bom.partNamePlaceholder`),autoFocus:!0}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsx)(`input`,{type:`number`,value:V,onChange:e=>ee(parseInt(e.target.value)||1),className:`w-20 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white focus:outline-none focus:border-bambu-green`,min:`1`,placeholder:n(`projectDetail.bom.qty`)}),(0,G.jsx)(`input`,{type:`number`,step:`0.01`,value:te,onChange:e=>ne(e.target.value),className:`flex-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:n(`projectDetail.bom.price`,{currency:N})})]})]}),(0,G.jsx)(`input`,{type:`url`,value:re,onChange:e=>ie(e.target.value),className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:n(`projectDetail.bom.sourcingUrlPlaceholder`)}),(0,G.jsx)(`input`,{type:`text`,value:ae,onChange:e=>oe(e.target.value),className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:n(`projectDetail.bom.remarksPlaceholder`)}),(0,G.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,size:`sm`,onClick:()=>H(!1),children:n(`common.cancel`)}),(0,G.jsx)(Q,{type:`submit`,size:`sm`,disabled:!z.trim()||we.isPending,children:we.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):n(`projectDetail.bom.addPart`)})]})]}),S?(0,G.jsx)(`div`,{className:`flex items-center justify-center py-4`,children:(0,G.jsx)(Y,{className:`w-6 h-6 animate-spin text-bambu-green`})}):x&&x.length>0?(0,G.jsxs)(`div`,{className:`space-y-2`,children:[x.filter(e=>!ce||!e.is_complete).map(e=>(0,G.jsx)(`div`,{className:`p-3 rounded-lg transition-colors ${e.is_complete?`bg-status-ok/10`:`bg-bambu-dark`}`,children:ue?.id===e.id?(0,G.jsxs)(`form`,{onSubmit:je,className:`space-y-3`,children:[(0,G.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-3`,children:[(0,G.jsx)(`input`,{type:`text`,value:fe,onChange:e=>pe(e.target.value),className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:n(`projectDetail.bom.partName`),autoFocus:!0}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsx)(`input`,{type:`number`,value:me,onChange:e=>he(parseInt(e.target.value)||1),className:`w-20 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white focus:outline-none focus:border-bambu-green`,min:`1`,placeholder:n(`projectDetail.bom.qty`)}),(0,G.jsx)(`input`,{type:`number`,step:`0.01`,value:ge,onChange:e=>_e(e.target.value),className:`flex-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:n(`projectDetail.bom.price`,{currency:N})})]})]}),(0,G.jsx)(`input`,{type:`url`,value:ve,onChange:e=>ye(e.target.value),className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:n(`projectDetail.bom.sourcingUrlPlaceholder`)}),(0,G.jsx)(`input`,{type:`text`,value:be,onChange:e=>xe(e.target.value),className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:n(`projectDetail.bom.remarksPlaceholder`)}),(0,G.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,size:`sm`,onClick:Me,children:n(`common.cancel`)}),(0,G.jsx)(Q,{type:`submit`,size:`sm`,disabled:!fe.trim()||Te.isPending,children:Te.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):n(`common.save`)})]})]}):(0,G.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,G.jsx)(`button`,{onClick:()=>a(`projects:update`)&&Oe(e),disabled:Te.isPending||!a(`projects:update`),title:a(`projects:update`)?void 0:n(`projectDetail.bom.noUpdatePermission`),className:`w-5 h-5 mt-0.5 rounded border-2 flex items-center justify-center transition-colors shrink-0 ${e.is_complete?`bg-status-ok border-status-ok text-white`:a(`projects:update`)?`border-bambu-gray hover:border-bambu-green`:`border-bambu-gray/50 cursor-not-allowed`}`,children:e.is_complete&&(0,G.jsx)(xs,{className:`w-3 h-3`})}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,G.jsxs)(`p`,{className:`text-sm font-medium ${e.is_complete?`text-bambu-gray line-through`:`text-white`}`,children:[e.name,(0,G.jsxs)(`span`,{className:`text-bambu-gray font-normal ml-2`,children:[`x`,e.quantity_needed]})]}),e.unit_price!==null&&(0,G.jsxs)(`span`,{className:`text-xs text-bambu-green whitespace-nowrap`,children:[N,(e.unit_price*e.quantity_needed).toFixed(2)]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(`button`,{onClick:()=>a(`projects:update`)&&Ae(e),disabled:!a(`projects:update`),className:`p-1 rounded transition-colors shrink-0 ${a(`projects:update`)?`hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white`:`text-bambu-gray/50 cursor-not-allowed`}`,title:a(`projects:update`)?n(`common.edit`):n(`projectDetail.bom.noEditPermission`),children:(0,G.jsx)(Al,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:()=>a(`projects:update`)&&ke(e.id,e.name),disabled:!a(`projects:update`),className:`p-1 rounded transition-colors shrink-0 ${a(`projects:update`)?`hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-red-400`:`text-bambu-gray/50 cursor-not-allowed`}`,title:a(`projects:update`)?n(`common.delete`):n(`projectDetail.bom.noDeletePermission`),children:(0,G.jsx)(Pu,{className:`w-4 h-4`})})]})]}),e.sourcing_url&&(0,G.jsxs)(`a`,{href:e.sourcing_url,target:`_blank`,rel:`noopener noreferrer`,className:`flex items-center gap-1 mt-1 text-xs text-blue-700 dark:text-blue-400 hover:text-blue-900 dark:hover:text-blue-300 transition-colors`,onClick:e=>e.stopPropagation(),children:[(0,G.jsx)(rc,{className:`w-3 h-3 shrink-0`}),(0,G.jsx)(`span`,{className:`truncate`,children:(()=>{try{return new URL(e.sourcing_url).hostname.replace(`www.`,``)}catch{return e.sourcing_url}})()})]}),e.remarks&&(0,G.jsx)(`p`,{className:`mt-1 text-xs text-bambu-gray/80 italic`,children:e.remarks})]})]})},e.id)),Ie&&Ie.bom_cost>0&&(0,G.jsxs)(`div`,{className:`pt-2 mt-2 border-t border-bambu-dark-tertiary flex justify-between text-sm`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:n(`projectDetail.bom.totalCost`)}),(0,G.jsxs)(`span`,{className:`text-white font-medium`,children:[N,Ie.bom_cost.toFixed(2)]})]})]}):(0,G.jsx)(`p`,{className:`text-bambu-gray/70 text-sm italic`,children:n(`projectDetail.bom.empty`)})]})}),(0,G.jsx)(zd,{children:(0,G.jsxs)(Vd,{className:`p-4`,children:[(0,G.jsx)(`div`,{className:`flex items-center justify-between mb-3`,children:(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(zc,{className:`w-5 h-5`}),n(`projectDetail.timeline.title`)]})}),w?(0,G.jsx)(`div`,{className:`flex items-center justify-center py-4`,children:(0,G.jsx)(Y,{className:`w-6 h-6 animate-spin text-bambu-green`})}):C&&C.length>0?(0,G.jsx)(`div`,{className:`space-y-3`,children:C.slice(0,10).map((e,t)=>(0,G.jsxs)(`div`,{className:`flex gap-3`,children:[(0,G.jsxs)(`div`,{className:`w-8 h-8 rounded-full flex items-center justify-center shrink-0 ${e.event_type===`print_completed`?`bg-status-ok/20 text-status-ok`:e.event_type===`print_failed`?`bg-status-error/20 text-status-error`:e.event_type===`print_started`?`bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400`:`bg-bambu-dark-tertiary text-bambu-gray`}`,children:[e.event_type===`print_completed`&&(0,G.jsx)(xs,{className:`w-4 h-4`}),e.event_type===`print_failed`&&(0,G.jsx)(Ds,{className:`w-4 h-4`}),e.event_type===`print_started`&&(0,G.jsx)(Rl,{className:`w-4 h-4`}),e.event_type===`queued`&&(0,G.jsx)($c,{className:`w-4 h-4`}),e.event_type===`project_created`&&(0,G.jsx)(Fl,{className:`w-4 h-4`})]}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:e.title}),e.description&&(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray truncate`,children:e.description}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray/70`,children:Fe(e.timestamp)})]})]},t))}):(0,G.jsx)(`p`,{className:`text-bambu-gray/70 text-sm italic`,children:n(`projectDetail.timeline.empty`)})]})}),!h.is_template&&(0,G.jsx)(`div`,{className:`flex justify-end`,children:(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:()=>Pe.mutate(),disabled:Pe.isPending||!a(`projects:create`),title:a(`projects:create`)?void 0:n(`projectDetail.template.noCreatePermission`),children:[Pe.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin mr-2`}):(0,G.jsx)(Vs,{className:`w-4 h-4 mr-2`}),n(`projectDetail.template.saveAsTemplate`)]})}),Ie&&(Ie.queued_prints>0||Ie.in_progress_prints>0)&&(0,G.jsx)(zd,{children:(0,G.jsxs)(Vd,{className:`p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)($c,{className:`w-5 h-5`}),n(`projectDetail.queue.title`)]}),(0,G.jsx)(Ai,{to:`/queue?project=${m}`,className:`text-sm text-bambu-green hover:underline`,children:n(`projectDetail.queue.viewAll`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-4 text-sm`,children:[Ie.in_progress_prints>0&&(0,G.jsx)(`span`,{className:`text-yellow-700 dark:text-yellow-400`,children:n(`projectDetail.queue.printing`,{count:Ie.in_progress_prints})}),Ie.queued_prints>0&&(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:n(`projectDetail.queue.queued`,{count:Ie.queued_prints})})]})]})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`div`,{className:`flex items-center justify-between mb-4`,children:(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(Cl,{className:`w-5 h-5`}),n(`projectDetail.prints.title`,{count:v?.length||0})]})}),b?(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-green`})}):(0,G.jsx)(MKe,{archives:v||[],t:n})]}),o&&(0,G.jsx)(j5,{t:n,currencySymbol:N,project:{...h,archive_count:Ie?.total_archives||0,total_items:Ie?.total_items||0,completed_count:Ie?.completed_prints||0,failed_count:Ie?.failed_prints||0,queue_count:Ie?.queued_prints||0,progress_percent:Ie?.progress_percent||null,child_count:h.children?.length??0,archives:[]},onClose:()=>s(!1),onSave:e=>F.mutate(e),isLoading:F.isPending}),Se.isOpen&&(0,G.jsx)(of,{title:Se.title,message:Se.message,confirmText:n(`common.delete`),variant:`danger`,onConfirm:Se.onConfirm,onCancel:()=>Ce(e=>({...e,isOpen:!1}))}),f&&(0,G.jsx)(zU,{mode:`create`,libraryFileId:f.id,archiveName:f.print_name||f.filename,projectId:m,onClose:()=>p(null),onSuccess:()=>{p(null),r.invalidateQueries({queryKey:[`archives`]}),r.invalidateQueries({queryKey:[`queue`]})}})]})}function L5({icon:e,label:t,dropdownLabel:n,onPrimary:r,items:i}){let[a,o]=(0,y.useState)(!1),s=(0,y.useRef)(null);return(0,y.useEffect)(()=>{if(!a)return;let e=e=>{s.current&&!s.current.contains(e.target)&&o(!1)},t=e=>{e.key===`Escape`&&(e.stopPropagation(),o(!1))};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[a]),i.length===0?(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:r,children:[e,t]}):(0,G.jsxs)(`div`,{className:`relative inline-flex`,ref:s,children:[(0,G.jsxs)(`div`,{className:`flex relative z-50`,children:[(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:()=>{o(!1),r()},className:`rounded-r-none`,children:[e,t]}),(0,G.jsx)(Q,{variant:`secondary`,size:`sm`,onClick:()=>o(e=>!e),"aria-label":n,"aria-haspopup":`menu`,"aria-expanded":a,className:`rounded-l-none border-l border-bambu-dark px-2`,children:(0,G.jsx)(ps,{className:`w-4 h-4 transition-transform ${a?`rotate-180`:``}`})})]}),a&&(0,G.jsx)(`div`,{role:`menu`,className:`absolute right-0 top-full mt-1 w-56 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg z-50 py-1`,children:i.map(e=>(0,G.jsxs)(`button`,{type:`button`,role:`menuitem`,onClick:()=>{o(!1),e.onClick()},className:`w-full text-left px-3 py-2 text-sm text-bambu-gray-light hover:bg-bambu-dark-tertiary hover:text-white transition-colors flex items-center gap-2`,children:[(0,G.jsx)(rc,{className:`w-4 h-4 flex-shrink-0`}),e.label]},e.key))})]})}function FKe({archiveId:e,libraryFileId:t,title:n,fileType:r,onClose:i,onSliceWithBambuddy:a}){let{t:o}=U(),{showToast:s}=qd(),{data:c}=K({queryKey:[`settings`],queryFn:Z.getSettings}),l=HW(c?.open_in_slicer,c?.preferred_slicer),u=t!=null,[d,f]=(0,y.useState)(null),[p,m]=(0,y.useState)(null),[h,g]=(0,y.useState)(!0),[_,v]=(0,y.useState)(null),[b,x]=(0,y.useState)(!1),[S,C]=(0,y.useState)(null),[w,T]=(0,y.useState)(0),[E,D]=(0,y.useState)(!1),[O,k]=(0,y.useState)(null),[A,j]=(0,y.useState)(!1),[M,N]=(0,y.useState)(!1),P=(0,y.useRef)(null),F=(0,y.useRef)(null),I=.35;(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&i()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[i]),(0,y.useEffect)(()=>{if(g(!0),u){let e=(r||``).toLowerCase(),t=e===`3mf`||e===`gcode.3mf`||e===`stl`;m({has_model:t,has_source:!1,build_volume:{x:256,y:256,z:256},filament_colors:[]}),f(t?`3d`:null),g(!1);return}if(!e){m(null),f(null),g(!1);return}Z.getArchiveCapabilities(e).then(e=>{m(e),e.has_model&&f(`3d`),g(!1)}).catch(()=>{m({has_model:!0,has_source:!1,build_volume:{x:256,y:256,z:256},filament_colors:[]}),f(`3d`),g(!1)})},[e,r,u]),(0,y.useEffect)(()=>{if(x(!0),C(null),T(0),u){let e=(r||``).toLowerCase();if(!t||!(e===`3mf`||e===`gcode.3mf`)){v(null),x(!1);return}Z.getLibraryFilePlates(t).then(e=>v(e)).catch(()=>v(null)).finally(()=>x(!1));return}if(!e){v(null),x(!1);return}Z.getArchivePlates(e).then(e=>v(e)).catch(()=>v(null)).finally(()=>x(!1))},[e,r,u,t]);let L=(0,y.useMemo)(()=>_?.plates??[],[_]),R=(_?.is_multi_plate??!1)&&L.length>1,z=E&&R,B=S==null?null:L.find(e=>e.index===S)??null,V=e=>e.object_count??e.objects?.length??0,ee=L.reduce((e,t)=>e+V(t),0),te=B?V(B):ee,ne=B?o(`modelViewer.plateNumber`,{number:B.index}):o(`modelViewer.allPlates`),re=L.length>0,ie=(0,y.useRef)(null),ae=(0,y.useRef)(null),[oe,se]=(0,y.useState)(10),[H,ce]=(0,y.useState)(3),le=L.length>oe,ue=Math.max(1,Math.ceil(L.length/oe)),de=le?L.slice(w*oe,(w+1)*oe):L;(0,y.useEffect)(()=>{if(!z){se(10),ce(3);return}let e=ie.current,t=ae.current;if(!e||!t)return;let n=0,r=()=>{let n=t.clientWidth,r=Math.floor(n/210),i=Math.max(3,Math.min(5,r||3));ce(e=>e===i?e:i);let a=window.getComputedStyle(e),o=Number.parseFloat(a.rowGap||`0`),s=e.querySelector(`button`)?.getBoundingClientRect().height??44,c=t.clientHeight,l=Math.max(1,Math.floor((c+o)/(s+o)))*i,u=Math.max(1,l-1);se(e=>e===u?e:u)},i=()=>{n&&cancelAnimationFrame(n),n=requestAnimationFrame(r)};i();let a=new ResizeObserver(i);return a.observe(t),a.observe(e),()=>{n&&cancelAnimationFrame(n),a.disconnect()}},[z,L.length]),(0,y.useEffect)(()=>{if(!le){T(0);return}T(e=>Math.min(e,ue-1))},[L.length,le,ue]),(0,y.useEffect)(()=>{if(!le||S==null)return;let e=L.findIndex(e=>e.index===S);if(e<0)return;let t=Math.floor(e/oe);T(e=>e===t?e:t)},[L,oe,S,le]),(0,y.useEffect)(()=>{if(!z){k(null),N(!1);return}if(M)return;let e=P.current,t=F.current;if(!e||!t)return;let n=e.clientHeight;if(!n)return;let r=Math.max(240,n*I),i=Math.max(160,n-10-r),a=Math.min(t.scrollHeight,i);k(Math.max(160,a))},[z,M,L.length,w,10,160,240,I]),(0,y.useEffect)(()=>{if(!A)return;let e=e=>{let t=P.current;if(!t)return;let n=t.getBoundingClientRect(),r=n.height;if(!r)return;let i=Math.max(240,r*I),a=Math.max(160,r-10-i);k(Math.min(a,Math.max(160,e.clientY-n.top)))},t=()=>{j(!1),N(!0)};return document.addEventListener(`mousemove`,e),document.addEventListener(`mouseup`,t),document.body.style.cursor=`row-resize`,document.body.style.userSelect=`none`,()=>{document.removeEventListener(`mousemove`,e),document.removeEventListener(`mouseup`,t),document.body.style.cursor=``,document.body.style.userSelect=``}},[A,10,160,240,I]);let fe=l===`orcaslicer`?[`orcaslicer`,`bambu_studio`]:[`bambu_studio`,`orcaslicer`],pe=u?fe.filter(e=>uje(r,e)):fe,me=pe.length>0,he=mje(r),ge=!!(u&&c?.use_slicer_api&&a&&he),_e=async r=>{if(!me)return;let i=n||`model`;try{if(u){let{token:e}=await Z.createLibrarySlicerToken(t),n=Z.getLibrarySlicerDownloadUrl(t,e,i);KW(`${window.location.origin}${n}`,r)}else{let{token:t}=await Z.createArchiveSlicerToken(e),n=Z.getArchiveSlicerDownloadUrl(e,t,i);KW(`${window.location.origin}${n}`,r)}}catch{s(o(`modelViewer.openInSlicerFailed`),`error`),KW(u?`${window.location.origin}${Z.getLibraryFileDownloadUrl(t)}`:`${window.location.origin}${Z.getArchiveForSlicer(e,i)}`,r)}},ve=ge?pe:pe.slice(1),ye=e=>o(e===`orcaslicer`?`settings.slicerOrcaSlicer`:`settings.slicerBambuStudio`),be=ve.map(e=>({key:e,label:o(`modelViewer.openInSlicerWith`,{slicer:ye(e)}),onClick:()=>_e(e)}));return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 ${E?`p-0`:`p-8`}`,onClick:i,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary w-full flex flex-col ${E?`h-full max-w-none rounded-none`:`h-[80vh] max-w-4xl rounded-xl`}`,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-3 min-w-0 flex-1 mr-4`,children:[(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white truncate`,children:n}),re&&(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray bg-bambu-dark-tertiary/70 px-2 py-1 rounded whitespace-nowrap`,children:[ne,`: `,o(`modelViewer.objectCount`,{count:te})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[ge?(0,G.jsx)(L5,{icon:(0,G.jsx)(Rs,{className:`w-4 h-4`}),label:o(`slice.action`),dropdownLabel:o(`modelViewer.moreSlicerOptions`),onPrimary:()=>a?.(),items:be}):me?(0,G.jsx)(L5,{icon:(0,G.jsx)(rc,{className:`w-4 h-4`}),label:pe[0]===l?o(`modelViewer.openInSlicer`):o(`modelViewer.openInSlicerWith`,{slicer:ye(pe[0])}),dropdownLabel:o(`modelViewer.moreSlicerOptions`),onPrimary:()=>_e(pe[0]),items:be}):(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,disabled:!0,children:[(0,G.jsx)(rc,{className:`w-4 h-4`}),o(`modelViewer.openInSlicer`)]}),(0,G.jsx)(Q,{variant:`secondary`,size:`sm`,onClick:()=>D(e=>!e),title:E?`Exit fullscreen`:`Enter fullscreen`,children:E?(0,G.jsx)(fl,{className:`w-4 h-4`}):(0,G.jsx)(cl,{className:`w-4 h-4`})}),(0,G.jsx)(Q,{variant:`ghost`,size:`sm`,onClick:i,children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]})]}),p&&(0,G.jsx)(`div`,{className:`flex border-b border-bambu-dark-tertiary`,children:(0,G.jsxs)(`button`,{onClick:()=>p.has_model&&f(`3d`),disabled:!p.has_model,className:`flex items-center gap-2 px-6 py-3 text-sm font-medium transition-colors ${d===`3d`?`text-bambu-green border-b-2 border-bambu-green`:p.has_model?`text-bambu-gray hover:text-white`:`text-bambu-gray/30 cursor-not-allowed`}`,children:[(0,G.jsx)(Zo,{className:`w-4 h-4`}),o(`modelViewer.tabs.model`),!p.has_model&&(0,G.jsxs)(`span`,{className:`text-xs`,children:[`(`,o(`modelViewer.notAvailable`),`)`]})]})}),(0,G.jsx)(`div`,{className:`flex-1 overflow-hidden p-4`,children:h?(0,G.jsx)(`div`,{className:`w-full h-full flex items-center justify-center`,children:(0,G.jsx)(Y,{className:`w-8 h-8 animate-spin text-bambu-green`})}):d===`3d`&&p?(0,G.jsxs)(`div`,{ref:P,className:`w-full h-full flex flex-col ${z?`gap-0 min-h-0`:`gap-3`}`,children:[R&&(0,G.jsxs)(`div`,{ref:F,style:z&&O!=null?{height:O}:void 0,className:`rounded-lg border border-bambu-dark-tertiary bg-bambu-dark p-3 ${z?`flex flex-col shrink-0`:``}`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-bambu-gray mb-2`,children:[(0,G.jsx)(Jc,{className:`w-4 h-4`}),o(`modelViewer.plates`),b&&(0,G.jsx)(Y,{className:`w-3 h-3 animate-spin`})]}),(0,G.jsxs)(`div`,{className:z?`flex flex-col min-h-0 flex-1`:void 0,children:[(0,G.jsx)(`div`,{ref:ae,className:z?`min-h-0 overflow-hidden pr-1 flex-1`:void 0,children:(0,G.jsxs)(`div`,{ref:ie,className:z?`grid gap-2`:`grid grid-cols-2 md:grid-cols-3 gap-2`,style:z?{gridTemplateColumns:`repeat(${H}, minmax(0, 1fr))`}:void 0,children:[(0,G.jsxs)(`button`,{type:`button`,onClick:()=>C(null),className:`flex items-center rounded-lg border text-left transition-colors ${z?`gap-1.5 p-1.5 w-full`:`gap-2 p-2`} ${S==null?`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary bg-bambu-dark-secondary hover:border-bambu-gray`}`,children:[(0,G.jsx)(`div`,{className:`rounded bg-bambu-dark-tertiary flex items-center justify-center ${z?`w-8 h-8`:`w-10 h-10`}`,children:(0,G.jsx)(Jc,{className:`${z?`w-4 h-4`:`w-5 h-5`} text-bambu-gray`})}),(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,G.jsx)(`p`,{className:`${z?`text-xs`:`text-sm`} text-white font-medium truncate`,children:o(`modelViewer.allPlates`)}),(0,G.jsx)(`p`,{className:`${z?`text-[10px]`:`text-xs`} text-bambu-gray truncate`,children:o(`modelViewer.plateCount`,{count:L.length})})]}),S==null&&(0,G.jsx)(fs,{className:`${z?`w-3.5 h-3.5`:`w-4 h-4`} text-bambu-green flex-shrink-0`})]}),de.map(e=>(0,G.jsxs)(`button`,{type:`button`,onClick:()=>C(e.index),className:`flex items-center rounded-lg border text-left transition-colors ${z?`gap-1.5 p-1.5 w-full`:`gap-2 p-2`} ${S===e.index?`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary bg-bambu-dark-secondary hover:border-bambu-gray`}`,children:[e.has_thumbnail&&e.thumbnail_url?(0,G.jsx)(`img`,{src:vd(e.thumbnail_url),alt:`Plate ${e.index}`,className:`${z?`w-8 h-8`:`w-10 h-10`} rounded object-cover bg-bambu-dark-tertiary`}):(0,G.jsx)(`div`,{className:`rounded bg-bambu-dark-tertiary flex items-center justify-center ${z?`w-8 h-8`:`w-10 h-10`}`,children:(0,G.jsx)(Jc,{className:`${z?`w-4 h-4`:`w-5 h-5`} text-bambu-gray`})}),(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,G.jsx)(`p`,{className:`${z?`text-xs`:`text-sm`} text-white font-medium truncate`,children:e.name||o(`modelViewer.plateNumber`,{number:e.index})}),(0,G.jsx)(`p`,{className:`${z?`text-[10px]`:`text-xs`} text-bambu-gray truncate`,children:o(`modelViewer.objectCount`,{count:e.object_count??e.objects?.length??0})})]}),S===e.index&&(0,G.jsx)(fs,{className:`${z?`w-3.5 h-3.5`:`w-4 h-4`} text-bambu-green flex-shrink-0`})]},e.index))]})}),(B||le)&&(0,G.jsxs)(`div`,{className:`mt-auto pt-3 flex items-center gap-4 text-xs text-bambu-gray overflow-x-auto`,children:[B&&(0,G.jsxs)(`div`,{className:`flex items-center gap-3 whitespace-nowrap`,children:[(0,G.jsx)(`span`,{children:o(`modelViewer.plateNumber`,{number:B.index})}),B.print_time_seconds!=null&&(0,G.jsx)(`span`,{children:o(`modelViewer.eta`,{minutes:Math.round(B.print_time_seconds/60)})}),B.filament_used_grams!=null&&(0,G.jsxs)(`span`,{children:[B.filament_used_grams.toFixed(1),` g`]}),B.filaments.length>0&&(0,G.jsx)(`span`,{children:o(`modelViewer.filamentCount`,{count:B.filaments.length})})]}),le&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2 whitespace-nowrap ${B?`ml-auto`:``}`,children:[(0,G.jsx)(`span`,{children:o(`modelViewer.pagination.pageOf`,{current:w+1,total:ue})}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(`button`,{type:`button`,onClick:()=>T(e=>Math.max(e-1,0)),disabled:w===0,className:`px-2 py-1 rounded border text-xs ${w===0?`border-bambu-dark-tertiary text-bambu-gray/40 cursor-not-allowed`:`border-bambu-dark-tertiary text-bambu-gray hover:text-white hover:border-bambu-gray`}`,children:o(`modelViewer.pagination.prev`)}),(()=>{let e=Math.max(0,w-2),t=Math.min(ue,e+5);t-e<5&&(e=Math.max(0,t-5));let n=Array.from({length:t-e},(t,n)=>e+n);return(0,G.jsxs)(G.Fragment,{children:[e>0&&(0,G.jsx)(`button`,{type:`button`,onClick:()=>T(0),className:`px-2 py-1 rounded border text-xs ${w===0?`border-bambu-green text-bambu-green`:`border-bambu-dark-tertiary text-bambu-gray hover:text-white hover:border-bambu-gray`}`,children:`1`}),e>1&&(0,G.jsx)(`span`,{className:`px-1`,children:`…`}),n.map(e=>(0,G.jsx)(`button`,{type:`button`,onClick:()=>T(e),className:`px-2 py-1 rounded border text-xs ${w===e?`border-bambu-green text-bambu-green`:`border-bambu-dark-tertiary text-bambu-gray hover:text-white hover:border-bambu-gray`}`,children:e+1},e)),tT(ue-1),className:`px-2 py-1 rounded border text-xs ${w===ue-1?`border-bambu-green text-bambu-green`:`border-bambu-dark-tertiary text-bambu-gray hover:text-white hover:border-bambu-gray`}`,children:ue})]})})(),(0,G.jsx)(`button`,{type:`button`,onClick:()=>T(e=>Math.min(e+1,ue-1)),disabled:w>=ue-1,className:`px-2 py-1 rounded border text-xs ${w>=ue-1?`border-bambu-dark-tertiary text-bambu-gray/40 cursor-not-allowed`:`border-bambu-dark-tertiary text-bambu-gray hover:text-white hover:border-bambu-gray`}`,children:o(`modelViewer.pagination.next`)})]})]})]})]})]}),z&&(0,G.jsx)(`div`,{role:`separator`,"aria-orientation":`horizontal`,onMouseDown:e=>{e.preventDefault(),j(!0),N(!0)},className:`h-2 cursor-row-resize flex items-center justify-center ${A?`bg-bambu-dark-tertiary`:`bg-bambu-dark-secondary/60 hover:bg-bambu-dark-tertiary`}`,children:(0,G.jsx)(`div`,{className:`w-12 h-1 rounded-full bg-bambu-gray/50`})}),(0,G.jsx)(`div`,{className:`flex-1 ${z?`min-h-0`:``}`,children:(0,G.jsx)(rT,{url:u?Z.getLibraryFileDownloadUrl(t):p.has_source?Z.getSource3mfDownloadUrl(e):Z.getArchiveDownload(e),fileType:r,buildVolume:p.build_volume,filamentColors:p.filament_colors,selectedPlateId:S,className:`w-full h-full`})})]}):(0,G.jsx)(`div`,{className:`w-full h-full flex items-center justify-center text-bambu-gray`,children:o(`modelViewer.noPreview`)})})]})})}var R5=[`library-tags`];function IKe({open:e,fileIds:t,onClose:n}){let{t:r}=U(),i=co(),{showToast:a}=qd(),[o,s]=(0,y.useState)(`add`),[c,l]=(0,y.useState)(new Set),[u,d]=(0,y.useState)(``),[f,p]=(0,y.useState)(``);(0,y.useEffect)(()=>{e||(s(`add`),l(new Set),d(``),p(``))},[e]);let{data:m=[],isLoading:h}=K({queryKey:R5,queryFn:Z.getLibraryTags,enabled:e}),g=(0,y.useMemo)(()=>{let e=u.trim().toLowerCase();return e?m.filter(t=>t.name.toLowerCase().includes(e)):m},[m,u]),_=e=>{l(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},v=q({mutationFn:e=>Z.createLibraryTag(e),onSuccess:e=>{l(t=>new Set(t).add(e.id)),p(``),i.invalidateQueries({queryKey:R5})},onError:e=>{a(e.message||r(`fileManager.tags.saveFailed`),`error`)}}),b=q({mutationFn:()=>Z.bulkAssignLibraryTags(t,Array.from(c),o),onSuccess:e=>{a(o===`add`?r(`fileManager.tags.applyAddSuccess`,{count:e.associations_added,files:e.files_updated}):r(`fileManager.tags.applyRemoveSuccess`,{count:e.associations_removed,files:e.files_updated}),`success`),i.invalidateQueries({queryKey:[`library-files`]}),i.invalidateQueries({queryKey:R5}),n()},onError:e=>{a(e.message||r(`fileManager.tags.applyFailed`),`error`)}});if((0,y.useEffect)(()=>{if(!e)return;let t=e=>{e.key===`Escape`&&!b.isPending&&!v.isPending&&n()};return document.addEventListener(`keydown`,t),()=>document.removeEventListener(`keydown`,t)},[e,n,b.isPending,v.isPending]),!e)return null;let x=!f.trim()||v.isPending||m.some(e=>e.name.toLowerCase()===f.trim().toLowerCase()),S=`bulk-tags-picker-title`;return(0,G.jsxs)(`div`,{className:`fixed inset-0 z-[60] flex items-center justify-center`,children:[(0,G.jsx)(`div`,{className:`absolute inset-0 bg-black/60`,onClick:()=>!b.isPending&&n()}),(0,G.jsxs)(`div`,{className:`relative w-full max-w-md mx-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl shadow-2xl max-h-[90vh] flex flex-col`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":S,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-4 px-5 py-4 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`h3`,{id:S,className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(Eu,{className:`w-4 h-4 text-bambu-green`}),r(`fileManager.tags.bulkTitle`,{count:t.length})]}),(0,G.jsx)(`button`,{type:`button`,className:`p-1.5 text-bambu-gray hover:text-white rounded`,onClick:n,"aria-label":r(`common.close`),children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]}),(0,G.jsxs)(`div`,{className:`px-5 py-3 border-b border-bambu-dark-tertiary flex gap-4 text-sm`,children:[(0,G.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`radio`,name:`bulk-action`,checked:o===`add`,onChange:()=>s(`add`),className:`accent-bambu-green`}),(0,G.jsx)(`span`,{className:`text-white`,children:r(`fileManager.tags.actionAdd`)})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`radio`,name:`bulk-action`,checked:o===`remove`,onChange:()=>s(`remove`),className:`accent-bambu-green`}),(0,G.jsx)(`span`,{className:`text-white`,children:r(`fileManager.tags.actionRemove`)})]})]}),(0,G.jsx)(`div`,{className:`px-5 py-3 border-b border-bambu-dark-tertiary`,children:(0,G.jsx)(`input`,{type:`text`,value:u,onChange:e=>d(e.target.value),placeholder:r(`fileManager.tags.searchPlaceholder`),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`})}),(0,G.jsx)(`div`,{className:`overflow-y-auto flex-1 min-h-[8rem] max-h-[24rem]`,children:h?(0,G.jsxs)(`div`,{className:`flex items-center justify-center py-12 text-bambu-gray`,children:[(0,G.jsx)(Y,{className:`w-5 h-5 animate-spin mr-2`}),r(`common.loading`)]}):g.length===0?(0,G.jsx)(`div`,{className:`py-12 text-center text-bambu-gray text-sm`,children:m.length===0?r(`fileManager.tags.empty`):r(`fileManager.tags.noMatches`)}):(0,G.jsx)(`ul`,{className:`divide-y divide-bambu-dark-tertiary/40`,children:g.map(e=>(0,G.jsx)(`li`,{children:(0,G.jsxs)(`label`,{className:`flex items-center gap-3 px-5 py-2 hover:bg-bambu-dark-tertiary/30 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:c.has(e.id),onChange:()=>_(e.id),className:`accent-bambu-green`}),(0,G.jsx)(`span`,{className:`text-sm text-white truncate flex-1`,children:e.name}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:e.file_count})]})},e.id))})}),o===`add`&&(0,G.jsxs)(`div`,{className:`px-5 py-3 border-t border-bambu-dark-tertiary flex gap-2`,children:[(0,G.jsx)(`input`,{type:`text`,value:f,onChange:e=>p(e.target.value),placeholder:r(`fileManager.tags.createPlaceholder`),maxLength:64,className:`flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,onKeyDown:e=>{e.key===`Enter`&&!x&&(e.preventDefault(),v.mutate(f.trim()))}}),(0,G.jsxs)(Q,{type:`button`,variant:`secondary`,onClick:()=>v.mutate(f.trim()),disabled:x,children:[v.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Fl,{className:`w-4 h-4`}),r(`fileManager.tags.createButton`)]})]}),(0,G.jsxs)(`div`,{className:`px-5 py-4 border-t border-bambu-dark-tertiary flex justify-end gap-2`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:n,disabled:b.isPending,children:r(`common.cancel`)}),(0,G.jsxs)(Q,{type:`button`,onClick:()=>b.mutate(),disabled:c.size===0||b.isPending||t.length===0,children:[b.isPending&&(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),r(o===`add`?`fileManager.tags.applyAdd`:`fileManager.tags.applyRemove`)]})]})]})]})}function LKe(e,t){let n=t||{};return(e[e.length-1]===``?[...e,``]:e).join((n.padRight?` `:``)+`,`+(n.padLeft===!1?``:` `)).trim()}var RKe=/^[$_\p{ID_Start}][$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,zKe=/^[$_\p{ID_Start}][-$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,BKe={};function z5(e,t){return((t||BKe).jsx?zKe:RKe).test(e)}var VKe=/[ \t\n\f\r]/g;function HKe(e){return typeof e==`object`?e.type===`text`?UKe(e.value):!1:UKe(e)}function UKe(e){return e.replace(VKe,``)===``}var B5=class{constructor(e,t,n){this.normal=t,this.property=e,n&&(this.space=n)}};B5.prototype.normal={},B5.prototype.property={},B5.prototype.space=void 0;function WKe(e,t){let n={},r={};for(let t of e)Object.assign(n,t.property),Object.assign(r,t.normal);return new B5(n,r,t)}function V5(e){return e.toLowerCase()}var H5=class{constructor(e,t){this.attribute=t,this.property=e}};H5.prototype.attribute=``,H5.prototype.booleanish=!1,H5.prototype.boolean=!1,H5.prototype.commaOrSpaceSeparated=!1,H5.prototype.commaSeparated=!1,H5.prototype.defined=!1,H5.prototype.mustUseProperty=!1,H5.prototype.number=!1,H5.prototype.overloadedBoolean=!1,H5.prototype.property=``,H5.prototype.spaceSeparated=!1,H5.prototype.space=void 0;var U5=s({boolean:()=>W5,booleanish:()=>G5,commaOrSpaceSeparated:()=>X5,commaSeparated:()=>Y5,number:()=>q5,overloadedBoolean:()=>K5,spaceSeparated:()=>J5}),GKe=0,W5=Z5(),G5=Z5(),K5=Z5(),q5=Z5(),J5=Z5(),Y5=Z5(),X5=Z5();function Z5(){return 2**++GKe}var Q5=Object.keys(U5),$5=class extends H5{constructor(e,t,n,r){let i=-1;if(super(e,t),KKe(this,`space`,r),typeof n==`number`)for(;++i4&&n.slice(0,4)===`data`&&iqe.test(t)){if(t.charAt(4)===`-`){let e=t.slice(5).replace(rqe,sqe);r=`data`+e.charAt(0).toUpperCase()+e.slice(1)}else{let e=t.slice(4);if(!rqe.test(e)){let n=e.replace(nqe,oqe);n.charAt(0)!==`-`&&(n=`-`+n),t=`data`+n}}i=$5}return new i(r,t)}function oqe(e){return`-`+e.toLowerCase()}function sqe(e){return e.charAt(1).toUpperCase()}var cqe=WKe([qKe,XKe,QKe,$Ke,eqe],`html`),t7=WKe([qKe,ZKe,QKe,$Ke,eqe],`svg`);function lqe(e){return e.join(` `).trim()}var uqe=o(((e,t)=>{var n=/\/\*[^*]*\*+([^/*][^*]*\*+)*\//g,r=/\n/g,i=/^\s*/,a=/^(\*?[-#/*\\\w]+(\[[0-9a-z_-]+\])?)\s*/,o=/^:\s*/,s=/^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^)]*?\)|[^};])+)/,c=/^[;\s]*/,l=/^\s+|\s+$/g,u=` +`,d=`/`,f=`*`,p=``,m=`comment`,h=`declaration`;function g(e,t){if(typeof e!=`string`)throw TypeError(`First argument must be a string`);if(!e)return[];t||={};var l=1,g=1;function v(e){var t=e.match(r);t&&(l+=t.length);var n=e.lastIndexOf(u);g=~n?e.length-n:g+e.length}function y(){var e={line:l,column:g};return function(t){return t.position=new b(e),C(),t}}function b(e){this.start=e,this.end={line:l,column:g},this.source=t.source}b.prototype.content=e;function x(n){var r=Error(t.source+`:`+l+`:`+g+`: `+n);if(r.reason=n,r.filename=t.source,r.line=l,r.column=g,r.source=e,!t.silent)throw r}function S(t){var n=t.exec(e);if(n){var r=n[0];return v(r),e=e.slice(r.length),n}}function C(){S(i)}function w(e){var t;for(e||=[];t=T();)t!==!1&&e.push(t);return e}function T(){var t=y();if(!(d!=e.charAt(0)||f!=e.charAt(1))){for(var n=2;p!=e.charAt(n)&&(f!=e.charAt(n)||d!=e.charAt(n+1));)++n;if(n+=2,p===e.charAt(n-1))return x(`End of comment missing`);var r=e.slice(2,n-2);return g+=2,v(r),e=e.slice(n),g+=2,t({type:m,comment:r})}}function E(){var e=y(),t=S(a);if(t){if(T(),!S(o))return x(`property missing ':'`);var r=S(s),i=e({type:h,property:_(t[0].replace(n,p)),value:r?_(r[0].replace(n,p)):p});return S(c),i}}function D(){var e=[];w(e);for(var t;t=E();)t!==!1&&(e.push(t),w(e));return e}return C(),D()}function _(e){return e?e.replace(l,p):p}t.exports=g})),dqe=o((e=>{var t=e&&e.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(e,"__esModule",{value:!0}),e.default=r;var n=t(uqe());function r(e,t){let r=null;if(!e||typeof e!=`string`)return r;let i=(0,n.default)(e),a=typeof t==`function`;return i.forEach(e=>{if(e.type!==`declaration`)return;let{property:n,value:i}=e;a?t(n,i,e):i&&(r||={},r[n]=i)}),r}})),fqe=o((e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.camelCase=void 0;var t=/^--[a-zA-Z0-9_-]+$/,n=/-([a-z])/g,r=/^[^-]+$/,i=/^-(webkit|moz|ms|o|khtml)-/,a=/^-(ms)-/,o=function(e){return!e||r.test(e)||t.test(e)},s=function(e,t){return t.toUpperCase()},c=function(e,t){return`${t}-`};e.camelCase=function(e,t){return t===void 0&&(t={}),o(e)?e:(e=e.toLowerCase(),e=t.reactCompat?e.replace(a,c):e.replace(i,c),e.replace(n,s))}})),pqe=o(((e,t)=>{var n=(e&&e.__importDefault||function(e){return e&&e.__esModule?e:{default:e}})(dqe()),r=fqe();function i(e,t){var i={};return!e||typeof e!=`string`||(0,n.default)(e,function(e,n){e&&n&&(i[(0,r.camelCase)(e,t)]=n)}),i}i.default=i,t.exports=i})),mqe=hqe(`end`),n7=hqe(`start`);function hqe(e){return t;function t(t){let n=t&&t.position&&t.position[e]||{};if(typeof n.line==`number`&&n.line>0&&typeof n.column==`number`&&n.column>0)return{line:n.line,column:n.column,offset:typeof n.offset==`number`&&n.offset>-1?n.offset:void 0}}}function gqe(e){let t=n7(e),n=mqe(e);if(t&&n)return{start:t,end:n}}function r7(e){return!e||typeof e!=`object`?``:`position`in e||`type`in e?_qe(e.position):`start`in e||`end`in e?_qe(e):`line`in e||`column`in e?i7(e):``}function i7(e){return vqe(e&&e.line)+`:`+vqe(e&&e.column)}function _qe(e){return i7(e&&e.start)+`-`+i7(e&&e.end)}function vqe(e){return e&&typeof e==`number`?e:1}var a7=class extends Error{constructor(e,t,n){super(),typeof t==`string`&&(n=t,t=void 0);let r=``,i={},a=!1;if(t&&(i=`line`in t&&`column`in t||`start`in t&&`end`in t?{place:t}:`type`in t?{ancestors:[t],place:t.position}:{...t}),typeof e==`string`?r=e:!i.cause&&e&&(a=!0,r=e.message,i.cause=e),!i.ruleId&&!i.source&&typeof n==`string`){let e=n.indexOf(`:`);e===-1?i.ruleId=n:(i.source=n.slice(0,e),i.ruleId=n.slice(e+1))}if(!i.place&&i.ancestors&&i.ancestors){let e=i.ancestors[i.ancestors.length-1];e&&(i.place=e.position)}let o=i.place&&`start`in i.place?i.place.start:i.place;this.ancestors=i.ancestors||void 0,this.cause=i.cause||void 0,this.column=o?o.column:void 0,this.fatal=void 0,this.file=``,this.message=r,this.line=o?o.line:void 0,this.name=r7(i.place)||`1:1`,this.place=i.place||void 0,this.reason=this.message,this.ruleId=i.ruleId||void 0,this.source=i.source||void 0,this.stack=a&&i.cause&&typeof i.cause.stack==`string`?i.cause.stack:``,this.actual=void 0,this.expected=void 0,this.note=void 0,this.url=void 0}};a7.prototype.file=``,a7.prototype.name=``,a7.prototype.reason=``,a7.prototype.message=``,a7.prototype.stack=``,a7.prototype.column=void 0,a7.prototype.line=void 0,a7.prototype.ancestors=void 0,a7.prototype.cause=void 0,a7.prototype.fatal=void 0,a7.prototype.place=void 0,a7.prototype.ruleId=void 0,a7.prototype.source=void 0;var yqe=l(pqe(),1),o7={}.hasOwnProperty,bqe=new Map,xqe=/[A-Z]/g,Sqe=new Set([`table`,`tbody`,`thead`,`tfoot`,`tr`]),Cqe=new Set([`td`,`th`]);function wqe(e,t){if(!t||t.Fragment===void 0)throw TypeError("Expected `Fragment` in options");let n=t.filePath||void 0,r;if(t.development){if(typeof t.jsxDEV!=`function`)throw TypeError("Expected `jsxDEV` in options when `development: true`");r=Pqe(n,t.jsxDEV)}else{if(typeof t.jsx!=`function`)throw TypeError("Expected `jsx` in production options");if(typeof t.jsxs!=`function`)throw TypeError("Expected `jsxs` in production options");r=Nqe(n,t.jsx,t.jsxs)}let i={Fragment:t.Fragment,ancestors:[],components:t.components||{},create:r,elementAttributeNameCase:t.elementAttributeNameCase||`react`,evaluater:t.createEvaluater?t.createEvaluater():void 0,filePath:n,ignoreInvalidStyle:t.ignoreInvalidStyle||!1,passKeys:t.passKeys!==!1,passNode:t.passNode||!1,schema:t.space===`svg`?t7:cqe,stylePropertyNameCase:t.stylePropertyNameCase||`dom`,tableCellAlignToStyle:t.tableCellAlignToStyle!==!1},a=Tqe(i,e,void 0);return a&&typeof a!=`string`?a:i.create(e,i.Fragment,{children:a||void 0},void 0)}function Tqe(e,t,n){if(t.type===`element`)return Eqe(e,t,n);if(t.type===`mdxFlowExpression`||t.type===`mdxTextExpression`)return Dqe(e,t);if(t.type===`mdxJsxFlowElement`||t.type===`mdxJsxTextElement`)return kqe(e,t,n);if(t.type===`mdxjsEsm`)return Oqe(e,t);if(t.type===`root`)return Aqe(e,t,n);if(t.type===`text`)return jqe(e,t)}function Eqe(e,t,n){let r=e.schema,i=r;t.tagName.toLowerCase()===`svg`&&r.space===`html`&&(i=t7,e.schema=i),e.ancestors.push(t);let a=zqe(e,t.tagName,!1),o=Fqe(e,t),s=c7(e,t);return Sqe.has(t.tagName)&&(s=s.filter(function(e){return typeof e==`string`?!HKe(e):!0})),Mqe(e,o,a,t),s7(o,s),e.ancestors.pop(),e.schema=r,e.create(t,a,o,n)}function Dqe(e,t){if(t.data&&t.data.estree&&e.evaluater){let n=t.data.estree.body[0];return n.type,e.evaluater.evaluateExpression(n.expression)}l7(e,t.position)}function Oqe(e,t){if(t.data&&t.data.estree&&e.evaluater)return e.evaluater.evaluateProgram(t.data.estree);l7(e,t.position)}function kqe(e,t,n){let r=e.schema,i=r;t.name===`svg`&&r.space===`html`&&(i=t7,e.schema=i),e.ancestors.push(t);let a=t.name===null?e.Fragment:zqe(e,t.name,!0),o=Iqe(e,t),s=c7(e,t);return Mqe(e,o,a,t),s7(o,s),e.ancestors.pop(),e.schema=r,e.create(t,a,o,n)}function Aqe(e,t,n){let r={};return s7(r,c7(e,t)),e.create(t,e.Fragment,r,n)}function jqe(e,t){return t.value}function Mqe(e,t,n,r){typeof n!=`string`&&n!==e.Fragment&&e.passNode&&(t.node=r)}function s7(e,t){if(t.length>0){let n=t.length>1?t:t[0];n&&(e.children=n)}}function Nqe(e,t,n){return r;function r(e,r,i,a){let o=Array.isArray(i.children)?n:t;return a?o(r,i,a):o(r,i)}}function Pqe(e,t){return n;function n(n,r,i,a){let o=Array.isArray(i.children),s=n7(n);return t(r,i,a,o,{columnNumber:s?s.column-1:void 0,fileName:e,lineNumber:s?s.line:void 0},void 0)}}function Fqe(e,t){let n={},r,i;for(i in t.properties)if(i!==`children`&&o7.call(t.properties,i)){let a=Lqe(e,i,t.properties[i]);if(a){let[i,o]=a;e.tableCellAlignToStyle&&i===`align`&&typeof o==`string`&&Cqe.has(t.tagName)?r=o:n[i]=o}}if(r){let t=n.style||={};t[e.stylePropertyNameCase===`css`?`text-align`:`textAlign`]=r}return n}function Iqe(e,t){let n={};for(let r of t.attributes)if(r.type===`mdxJsxExpressionAttribute`)if(r.data&&r.data.estree&&e.evaluater){let t=r.data.estree.body[0];t.type;let i=t.expression;i.type;let a=i.properties[0];a.type,Object.assign(n,e.evaluater.evaluateExpression(a.argument))}else l7(e,t.position);else{let i=r.name,a;if(r.value&&typeof r.value==`object`)if(r.value.data&&r.value.data.estree&&e.evaluater){let t=r.value.data.estree.body[0];t.type,a=e.evaluater.evaluateExpression(t.expression)}else l7(e,t.position);else a=r.value===null?!0:r.value;n[i]=a}return n}function c7(e,t){let n=[],r=-1,i=e.passKeys?new Map:bqe;for(;++ri?0:i+t:t>i?i:t,n=n>0?n:0,r.length<1e4)o=Array.from(r),o.unshift(t,n),e.splice(...o);else for(n&&e.splice(t,n);a0?(f7(e,e.length,0,t),e):t}var Yqe={}.hasOwnProperty;function Xqe(e){let t={},n=-1;for(;++n13&&n<32||n>126&&n<160||n>55295&&n<57344||n>64975&&n<65008||(n&65535)==65535||(n&65535)==65534||n>1114111?`�`:String.fromCodePoint(n)}function m7(e){return e.replace(/[\t\n\r ]+/g,` `).replace(/^ | $/g,``).toLowerCase().toUpperCase()}var h7=S7(/[A-Za-z]/),g7=S7(/[\dA-Za-z]/),eJe=S7(/[#-'*+\--9=?A-Z^-~]/);function _7(e){return e!==null&&(e<32||e===127)}var v7=S7(/\d/),tJe=S7(/[\dA-Fa-f]/),nJe=S7(/[!-/:-@[-`{-~]/);function y7(e){return e!==null&&e<-2}function b7(e){return e!==null&&(e<0||e===32)}function x7(e){return e===-2||e===-1||e===32}var rJe=S7(/\p{P}|\p{S}/u),iJe=S7(/\s/);function S7(e){return t;function t(t){return t!==null&&t>-1&&e.test(String.fromCharCode(t))}}function C7(e){let t=[],n=-1,r=0,i=0;for(;++n55295&&a<57344){let t=e.charCodeAt(n+1);a<56320&&t>56319&&t<57344?(o=String.fromCharCode(a,t),i=1):o=`�`}else o=String.fromCharCode(a);o&&=(t.push(e.slice(r,n),encodeURIComponent(o)),r=n+i+1,``),i&&=(n+=i,0)}return t.join(``)+e.slice(r)}function w7(e,t,n,r){let i=r?r-1:1/0,a=0;return o;function o(r){return x7(r)?(e.enter(n),s(r)):t(r)}function s(r){return x7(r)&&a++o))return;let n=t.events.length,a=n,s,c;for(;a--;)if(t.events[a][0]===`exit`&&t.events[a][1].type===`chunkFlow`){if(s){c=t.events[a][1].end;break}s=!0}for(_(r),e=n;er;){let r=n[i];t.containerState=r[1],r[0].exit.call(t,e)}n.length=r}function v(){i.write([null]),a=void 0,i=void 0,t.containerState._closeFlow=void 0}}function uJe(e,t,n){return w7(e,e.attempt(this.parser.constructs.document,t,n),`linePrefix`,this.parser.constructs.disable.null.includes(`codeIndented`)?void 0:4)}function T7(e){if(e===null||b7(e)||iJe(e))return 1;if(rJe(e))return 2}function E7(e,t,n){let r=[],i=-1;for(;++i1&&e[n][1].end.offset-e[n][1].start.offset>1?2:1;let d={...e[r][1].end},f={...e[n][1].start};pJe(d,-c),pJe(f,c),o={type:c>1?`strongSequence`:`emphasisSequence`,start:d,end:{...e[r][1].end}},s={type:c>1?`strongSequence`:`emphasisSequence`,start:{...e[n][1].start},end:f},a={type:c>1?`strongText`:`emphasisText`,start:{...e[r][1].end},end:{...e[n][1].start}},i={type:c>1?`strong`:`emphasis`,start:{...o.start},end:{...s.end}},e[r][1].end={...o.start},e[n][1].start={...s.end},l=[],e[r][1].end.offset-e[r][1].start.offset&&(l=p7(l,[[`enter`,e[r][1],t],[`exit`,e[r][1],t]])),l=p7(l,[[`enter`,i,t],[`enter`,o,t],[`exit`,o,t],[`enter`,a,t]]),l=p7(l,E7(t.parser.constructs.insideSpan.null,e.slice(r+1,n),t)),l=p7(l,[[`exit`,a,t],[`enter`,s,t],[`exit`,s,t],[`exit`,i,t]]),e[n][1].end.offset-e[n][1].start.offset?(u=2,l=p7(l,[[`enter`,e[n][1],t],[`exit`,e[n][1],t]])):u=0,f7(e,r-1,n-r+3,l),n=r+l.length-u-2;break}}for(n=-1;++n0&&x7(t)?w7(e,v,`linePrefix`,a+1)(t):v(t)}function v(t){return t===null||y7(t)?e.check(TJe,h,b)(t):(e.enter(`codeFlowValue`),y(t))}function y(t){return t===null||y7(t)?(e.exit(`codeFlowValue`),v(t)):(e.consume(t),y)}function b(n){return e.exit(`codeFenced`),t(n)}function x(e,t,n){let i=0;return a;function a(t){return e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),c}function c(t){return e.enter(`codeFencedFence`),x7(t)?w7(e,l,`linePrefix`,r.parser.constructs.disable.null.includes(`codeIndented`)?void 0:4)(t):l(t)}function l(t){return t===s?(e.enter(`codeFencedFenceSequence`),u(t)):n(t)}function u(t){return t===s?(i++,e.consume(t),u):i>=o?(e.exit(`codeFencedFenceSequence`),x7(t)?w7(e,d,`whitespace`)(t):d(t)):n(t)}function d(r){return r===null||y7(r)?(e.exit(`codeFencedFence`),t(r)):n(r)}}}function OJe(e,t,n){let r=this;return i;function i(t){return t===null?n(t):(e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),a)}function a(e){return r.parser.lazy[r.now().line]?n(e):t(e)}}var k7={name:`codeIndented`,tokenize:AJe},kJe={partial:!0,tokenize:jJe};function AJe(e,t,n){let r=this;return i;function i(t){return e.enter(`codeIndented`),w7(e,a,`linePrefix`,5)(t)}function a(e){let t=r.events[r.events.length-1];return t&&t[1].type===`linePrefix`&&t[2].sliceSerialize(t[1],!0).length>=4?o(e):n(e)}function o(t){return t===null?c(t):y7(t)?e.attempt(kJe,o,c)(t):(e.enter(`codeFlowValue`),s(t))}function s(t){return t===null||y7(t)?(e.exit(`codeFlowValue`),o(t)):(e.consume(t),s)}function c(n){return e.exit(`codeIndented`),t(n)}}function jJe(e,t,n){let r=this;return i;function i(t){return r.parser.lazy[r.now().line]?n(t):y7(t)?(e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),i):w7(e,a,`linePrefix`,5)(t)}function a(e){let a=r.events[r.events.length-1];return a&&a[1].type===`linePrefix`&&a[2].sliceSerialize(a[1],!0).length>=4?t(e):y7(e)?i(e):n(e)}}var MJe={name:`codeText`,previous:PJe,resolve:NJe,tokenize:FJe};function NJe(e){let t=e.length-4,n=3,r,i;if((e[n][1].type===`lineEnding`||e[n][1].type===`space`)&&(e[t][1].type===`lineEnding`||e[t][1].type===`space`)){for(r=n;++r=this.left.length+this.right.length)throw RangeError("Cannot access index `"+e+"` in a splice buffer of size `"+(this.left.length+this.right.length)+"`");return ethis.left.length?this.right.slice(this.right.length-n+this.left.length,this.right.length-e+this.left.length).reverse():this.left.slice(e).concat(this.right.slice(this.right.length-n+this.left.length).reverse())}splice(e,t,n){let r=t||0;this.setCursor(Math.trunc(e));let i=this.right.splice(this.right.length-r,1/0);return n&&A7(this.left,n),i.reverse()}pop(){return this.setCursor(1/0),this.left.pop()}push(e){this.setCursor(1/0),this.left.push(e)}pushMany(e){this.setCursor(1/0),A7(this.left,e)}unshift(e){this.setCursor(0),this.right.push(e)}unshiftMany(e){this.setCursor(0),A7(this.right,e.reverse())}setCursor(e){if(!(e===this.left.length||e>this.left.length&&this.right.length===0||e<0&&this.left.length===0))if(e=4?t(i):e.interrupt(r.parser.constructs.flow,n,t)(i)}}function WJe(e,t,n,r,i,a,o,s,c){let l=c||1/0,u=0;return d;function d(t){return t===60?(e.enter(r),e.enter(i),e.enter(a),e.consume(t),e.exit(a),f):t===null||t===32||t===41||_7(t)?n(t):(e.enter(r),e.enter(o),e.enter(s),e.enter(`chunkString`,{contentType:`string`}),h(t))}function f(n){return n===62?(e.enter(a),e.consume(n),e.exit(a),e.exit(i),e.exit(r),t):(e.enter(s),e.enter(`chunkString`,{contentType:`string`}),p(n))}function p(t){return t===62?(e.exit(`chunkString`),e.exit(s),f(t)):t===null||t===60||y7(t)?n(t):(e.consume(t),t===92?m:p)}function m(t){return t===60||t===62||t===92?(e.consume(t),p):p(t)}function h(i){return!u&&(i===null||i===41||b7(i))?(e.exit(`chunkString`),e.exit(s),e.exit(o),e.exit(r),t(i)):u999||l===null||l===91||l===93&&!c||l===94&&!s&&`_hiddenFootnoteSupport`in o.parser.constructs?n(l):l===93?(e.exit(a),e.enter(i),e.consume(l),e.exit(i),e.exit(r),t):y7(l)?(e.enter(`lineEnding`),e.consume(l),e.exit(`lineEnding`),u):(e.enter(`chunkString`,{contentType:`string`}),d(l))}function d(t){return t===null||t===91||t===93||y7(t)||s++>999?(e.exit(`chunkString`),u(t)):(e.consume(t),c||=!x7(t),t===92?f:d)}function f(t){return t===91||t===92||t===93?(e.consume(t),s++,d):d(t)}}function KJe(e,t,n,r,i,a){let o;return s;function s(t){return t===34||t===39||t===40?(e.enter(r),e.enter(i),e.consume(t),e.exit(i),o=t===40?41:t,c):n(t)}function c(n){return n===o?(e.enter(i),e.consume(n),e.exit(i),e.exit(r),t):(e.enter(a),l(n))}function l(t){return t===o?(e.exit(a),c(o)):t===null?n(t):y7(t)?(e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),w7(e,l,`linePrefix`)):(e.enter(`chunkString`,{contentType:`string`}),u(t))}function u(t){return t===o||t===null||y7(t)?(e.exit(`chunkString`),l(t)):(e.consume(t),t===92?d:u)}function d(t){return t===o||t===92?(e.consume(t),u):u(t)}}function j7(e,t){let n;return r;function r(i){return y7(i)?(e.enter(`lineEnding`),e.consume(i),e.exit(`lineEnding`),n=!0,r):x7(i)?w7(e,r,n?`linePrefix`:`lineSuffix`)(i):t(i)}}var qJe={name:`definition`,tokenize:YJe},JJe={partial:!0,tokenize:XJe};function YJe(e,t,n){let r=this,i;return a;function a(t){return e.enter(`definition`),o(t)}function o(t){return GJe.call(r,e,s,n,`definitionLabel`,`definitionLabelMarker`,`definitionLabelString`)(t)}function s(t){return i=m7(r.sliceSerialize(r.events[r.events.length-1][1]).slice(1,-1)),t===58?(e.enter(`definitionMarker`),e.consume(t),e.exit(`definitionMarker`),c):n(t)}function c(t){return b7(t)?j7(e,l)(t):l(t)}function l(t){return WJe(e,u,n,`definitionDestination`,`definitionDestinationLiteral`,`definitionDestinationLiteralMarker`,`definitionDestinationRaw`,`definitionDestinationString`)(t)}function u(t){return e.attempt(JJe,d,d)(t)}function d(t){return x7(t)?w7(e,f,`whitespace`)(t):f(t)}function f(a){return a===null||y7(a)?(e.exit(`definition`),r.parser.defined.push(i),t(a)):n(a)}}function XJe(e,t,n){return r;function r(t){return b7(t)?j7(e,i)(t):n(t)}function i(t){return KJe(e,a,n,`definitionTitle`,`definitionTitleMarker`,`definitionTitleString`)(t)}function a(t){return x7(t)?w7(e,o,`whitespace`)(t):o(t)}function o(e){return e===null||y7(e)?t(e):n(e)}}var ZJe={name:`hardBreakEscape`,tokenize:QJe};function QJe(e,t,n){return r;function r(t){return e.enter(`hardBreakEscape`),e.consume(t),i}function i(r){return y7(r)?(e.exit(`hardBreakEscape`),t(r)):n(r)}}var $Je={name:`headingAtx`,resolve:eYe,tokenize:tYe};function eYe(e,t){let n=e.length-2,r=3,i,a;return e[r][1].type===`whitespace`&&(r+=2),n-2>r&&e[n][1].type===`whitespace`&&(n-=2),e[n][1].type===`atxHeadingSequence`&&(r===n-1||n-4>r&&e[n-2][1].type===`whitespace`)&&(n-=r+1===n?2:4),n>r&&(i={type:`atxHeadingText`,start:e[r][1].start,end:e[n][1].end},a={type:`chunkText`,start:e[r][1].start,end:e[n][1].end,contentType:`text`},f7(e,r,n-r+1,[[`enter`,i,t],[`enter`,a,t],[`exit`,a,t],[`exit`,i,t]])),e}function tYe(e,t,n){let r=0;return i;function i(t){return e.enter(`atxHeading`),a(t)}function a(t){return e.enter(`atxHeadingSequence`),o(t)}function o(t){return t===35&&r++<6?(e.consume(t),o):t===null||b7(t)?(e.exit(`atxHeadingSequence`),s(t)):n(t)}function s(n){return n===35?(e.enter(`atxHeadingSequence`),c(n)):n===null||y7(n)?(e.exit(`atxHeading`),t(n)):x7(n)?w7(e,s,`whitespace`)(n):(e.enter(`atxHeadingText`),l(n))}function c(t){return t===35?(e.consume(t),c):(e.exit(`atxHeadingSequence`),s(t))}function l(t){return t===null||t===35||b7(t)?(e.exit(`atxHeadingText`),s(t)):(e.consume(t),l)}}var nYe=`address.article.aside.base.basefont.blockquote.body.caption.center.col.colgroup.dd.details.dialog.dir.div.dl.dt.fieldset.figcaption.figure.footer.form.frame.frameset.h1.h2.h3.h4.h5.h6.head.header.hr.html.iframe.legend.li.link.main.menu.menuitem.nav.noframes.ol.optgroup.option.p.param.search.section.summary.table.tbody.td.tfoot.th.thead.title.tr.track.ul`.split(`.`),rYe=[`pre`,`script`,`style`,`textarea`],iYe={concrete:!0,name:`htmlFlow`,resolveTo:sYe,tokenize:cYe},aYe={partial:!0,tokenize:uYe},oYe={partial:!0,tokenize:lYe};function sYe(e){let t=e.length;for(;t--&&!(e[t][0]===`enter`&&e[t][1].type===`htmlFlow`););return t>1&&e[t-2][1].type===`linePrefix`&&(e[t][1].start=e[t-2][1].start,e[t+1][1].start=e[t-2][1].start,e.splice(t-2,2)),e}function cYe(e,t,n){let r=this,i,a,o,s,c;return l;function l(e){return u(e)}function u(t){return e.enter(`htmlFlow`),e.enter(`htmlFlowData`),e.consume(t),d}function d(s){return s===33?(e.consume(s),f):s===47?(e.consume(s),a=!0,h):s===63?(e.consume(s),i=3,r.interrupt?t:I):h7(s)?(e.consume(s),o=String.fromCharCode(s),g):n(s)}function f(a){return a===45?(e.consume(a),i=2,p):a===91?(e.consume(a),i=5,s=0,m):h7(a)?(e.consume(a),i=4,r.interrupt?t:I):n(a)}function p(i){return i===45?(e.consume(i),r.interrupt?t:I):n(i)}function m(i){return i===`CDATA[`.charCodeAt(s++)?(e.consume(i),s===6?r.interrupt?t:O:m):n(i)}function h(t){return h7(t)?(e.consume(t),o=String.fromCharCode(t),g):n(t)}function g(s){if(s===null||s===47||s===62||b7(s)){let c=s===47,l=o.toLowerCase();return!c&&!a&&rYe.includes(l)?(i=1,r.interrupt?t(s):O(s)):nYe.includes(o.toLowerCase())?(i=6,c?(e.consume(s),_):r.interrupt?t(s):O(s)):(i=7,r.interrupt&&!r.parser.lazy[r.now().line]?n(s):a?v(s):y(s))}return s===45||g7(s)?(e.consume(s),o+=String.fromCharCode(s),g):n(s)}function _(i){return i===62?(e.consume(i),r.interrupt?t:O):n(i)}function v(t){return x7(t)?(e.consume(t),v):E(t)}function y(t){return t===47?(e.consume(t),E):t===58||t===95||h7(t)?(e.consume(t),b):x7(t)?(e.consume(t),y):E(t)}function b(t){return t===45||t===46||t===58||t===95||g7(t)?(e.consume(t),b):x(t)}function x(t){return t===61?(e.consume(t),S):x7(t)?(e.consume(t),x):y(t)}function S(t){return t===null||t===60||t===61||t===62||t===96?n(t):t===34||t===39?(e.consume(t),c=t,C):x7(t)?(e.consume(t),S):w(t)}function C(t){return t===c?(e.consume(t),c=null,T):t===null||y7(t)?n(t):(e.consume(t),C)}function w(t){return t===null||t===34||t===39||t===47||t===60||t===61||t===62||t===96||b7(t)?x(t):(e.consume(t),w)}function T(e){return e===47||e===62||x7(e)?y(e):n(e)}function E(t){return t===62?(e.consume(t),D):n(t)}function D(t){return t===null||y7(t)?O(t):x7(t)?(e.consume(t),D):n(t)}function O(t){return t===45&&i===2?(e.consume(t),M):t===60&&i===1?(e.consume(t),N):t===62&&i===4?(e.consume(t),L):t===63&&i===3?(e.consume(t),I):t===93&&i===5?(e.consume(t),F):y7(t)&&(i===6||i===7)?(e.exit(`htmlFlowData`),e.check(aYe,R,k)(t)):t===null||y7(t)?(e.exit(`htmlFlowData`),k(t)):(e.consume(t),O)}function k(t){return e.check(oYe,A,R)(t)}function A(t){return e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),j}function j(t){return t===null||y7(t)?k(t):(e.enter(`htmlFlowData`),O(t))}function M(t){return t===45?(e.consume(t),I):O(t)}function N(t){return t===47?(e.consume(t),o=``,P):O(t)}function P(t){if(t===62){let n=o.toLowerCase();return rYe.includes(n)?(e.consume(t),L):O(t)}return h7(t)&&o.length<8?(e.consume(t),o+=String.fromCharCode(t),P):O(t)}function F(t){return t===93?(e.consume(t),I):O(t)}function I(t){return t===62?(e.consume(t),L):t===45&&i===2?(e.consume(t),I):O(t)}function L(t){return t===null||y7(t)?(e.exit(`htmlFlowData`),R(t)):(e.consume(t),L)}function R(n){return e.exit(`htmlFlow`),t(n)}}function lYe(e,t,n){let r=this;return i;function i(t){return y7(t)?(e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),a):n(t)}function a(e){return r.parser.lazy[r.now().line]?n(e):t(e)}}function uYe(e,t,n){return r;function r(r){return e.enter(`lineEnding`),e.consume(r),e.exit(`lineEnding`),e.attempt(O7,t,n)}}var dYe={name:`htmlText`,tokenize:fYe};function fYe(e,t,n){let r=this,i,a,o;return s;function s(t){return e.enter(`htmlText`),e.enter(`htmlTextData`),e.consume(t),c}function c(t){return t===33?(e.consume(t),l):t===47?(e.consume(t),x):t===63?(e.consume(t),y):h7(t)?(e.consume(t),w):n(t)}function l(t){return t===45?(e.consume(t),u):t===91?(e.consume(t),a=0,m):h7(t)?(e.consume(t),v):n(t)}function u(t){return t===45?(e.consume(t),p):n(t)}function d(t){return t===null?n(t):t===45?(e.consume(t),f):y7(t)?(o=d,N(t)):(e.consume(t),d)}function f(t){return t===45?(e.consume(t),p):d(t)}function p(e){return e===62?M(e):e===45?f(e):d(e)}function m(t){return t===`CDATA[`.charCodeAt(a++)?(e.consume(t),a===6?h:m):n(t)}function h(t){return t===null?n(t):t===93?(e.consume(t),g):y7(t)?(o=h,N(t)):(e.consume(t),h)}function g(t){return t===93?(e.consume(t),_):h(t)}function _(t){return t===62?M(t):t===93?(e.consume(t),_):h(t)}function v(t){return t===null||t===62?M(t):y7(t)?(o=v,N(t)):(e.consume(t),v)}function y(t){return t===null?n(t):t===63?(e.consume(t),b):y7(t)?(o=y,N(t)):(e.consume(t),y)}function b(e){return e===62?M(e):y(e)}function x(t){return h7(t)?(e.consume(t),S):n(t)}function S(t){return t===45||g7(t)?(e.consume(t),S):C(t)}function C(t){return y7(t)?(o=C,N(t)):x7(t)?(e.consume(t),C):M(t)}function w(t){return t===45||g7(t)?(e.consume(t),w):t===47||t===62||b7(t)?T(t):n(t)}function T(t){return t===47?(e.consume(t),M):t===58||t===95||h7(t)?(e.consume(t),E):y7(t)?(o=T,N(t)):x7(t)?(e.consume(t),T):M(t)}function E(t){return t===45||t===46||t===58||t===95||g7(t)?(e.consume(t),E):D(t)}function D(t){return t===61?(e.consume(t),O):y7(t)?(o=D,N(t)):x7(t)?(e.consume(t),D):T(t)}function O(t){return t===null||t===60||t===61||t===62||t===96?n(t):t===34||t===39?(e.consume(t),i=t,k):y7(t)?(o=O,N(t)):x7(t)?(e.consume(t),O):(e.consume(t),A)}function k(t){return t===i?(e.consume(t),i=void 0,j):t===null?n(t):y7(t)?(o=k,N(t)):(e.consume(t),k)}function A(t){return t===null||t===34||t===39||t===60||t===61||t===96?n(t):t===47||t===62||b7(t)?T(t):(e.consume(t),A)}function j(e){return e===47||e===62||b7(e)?T(e):n(e)}function M(r){return r===62?(e.consume(r),e.exit(`htmlTextData`),e.exit(`htmlText`),t):n(r)}function N(t){return e.exit(`htmlTextData`),e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),P}function P(t){return x7(t)?w7(e,F,`linePrefix`,r.parser.constructs.disable.null.includes(`codeIndented`)?void 0:4)(t):F(t)}function F(t){return e.enter(`htmlTextData`),o(t)}}var M7={name:`labelEnd`,resolveAll:gYe,resolveTo:_Ye,tokenize:vYe},pYe={tokenize:yYe},mYe={tokenize:bYe},hYe={tokenize:xYe};function gYe(e){let t=-1,n=[];for(;++t=3&&(a===null||y7(a))?(e.exit(`thematicBreak`),t(a)):n(a)}function c(t){return t===i?(e.consume(t),r++,c):(e.exit(`thematicBreakSequence`),x7(t)?w7(e,s,`whitespace`)(t):s(t))}}var F7={continuation:{tokenize:jYe},exit:NYe,name:`list`,tokenize:AYe},OYe={partial:!0,tokenize:PYe},kYe={partial:!0,tokenize:MYe};function AYe(e,t,n){let r=this,i=r.events[r.events.length-1],a=i&&i[1].type===`linePrefix`?i[2].sliceSerialize(i[1],!0).length:0,o=0;return s;function s(t){let i=r.containerState.type||(t===42||t===43||t===45?`listUnordered`:`listOrdered`);if(i===`listUnordered`?!r.containerState.marker||t===r.containerState.marker:v7(t)){if(r.containerState.type||(r.containerState.type=i,e.enter(i,{_container:!0})),i===`listUnordered`)return e.enter(`listItemPrefix`),t===42||t===45?e.check(P7,n,l)(t):l(t);if(!r.interrupt||t===49)return e.enter(`listItemPrefix`),e.enter(`listItemValue`),c(t)}return n(t)}function c(t){return v7(t)&&++o<10?(e.consume(t),c):(!r.interrupt||o<2)&&(r.containerState.marker?t===r.containerState.marker:t===41||t===46)?(e.exit(`listItemValue`),l(t)):n(t)}function l(t){return e.enter(`listItemMarker`),e.consume(t),e.exit(`listItemMarker`),r.containerState.marker=r.containerState.marker||t,e.check(O7,r.interrupt?n:u,e.attempt(OYe,f,d))}function u(e){return r.containerState.initialBlankLine=!0,a++,f(e)}function d(t){return x7(t)?(e.enter(`listItemPrefixWhitespace`),e.consume(t),e.exit(`listItemPrefixWhitespace`),f):n(t)}function f(n){return r.containerState.size=a+r.sliceSerialize(e.exit(`listItemPrefix`),!0).length,t(n)}}function jYe(e,t,n){let r=this;return r.containerState._closeFlow=void 0,e.check(O7,i,a);function i(n){return r.containerState.furtherBlankLines=r.containerState.furtherBlankLines||r.containerState.initialBlankLine,w7(e,t,`listItemIndent`,r.containerState.size+1)(n)}function a(n){return r.containerState.furtherBlankLines||!x7(n)?(r.containerState.furtherBlankLines=void 0,r.containerState.initialBlankLine=void 0,o(n)):(r.containerState.furtherBlankLines=void 0,r.containerState.initialBlankLine=void 0,e.attempt(kYe,t,o)(n))}function o(i){return r.containerState._closeFlow=!0,r.interrupt=void 0,w7(e,e.attempt(F7,t,n),`linePrefix`,r.parser.constructs.disable.null.includes(`codeIndented`)?void 0:4)(i)}}function MYe(e,t,n){let r=this;return w7(e,i,`listItemIndent`,r.containerState.size+1);function i(e){let i=r.events[r.events.length-1];return i&&i[1].type===`listItemIndent`&&i[2].sliceSerialize(i[1],!0).length===r.containerState.size?t(e):n(e)}}function NYe(e){e.exit(this.containerState.type)}function PYe(e,t,n){let r=this;return w7(e,i,`listItemPrefixWhitespace`,r.parser.constructs.disable.null.includes(`codeIndented`)?void 0:5);function i(e){let i=r.events[r.events.length-1];return!x7(e)&&i&&i[1].type===`listItemPrefixWhitespace`?t(e):n(e)}}var FYe={name:`setextUnderline`,resolveTo:IYe,tokenize:LYe};function IYe(e,t){let n=e.length,r,i,a;for(;n--;)if(e[n][0]===`enter`){if(e[n][1].type===`content`){r=n;break}e[n][1].type===`paragraph`&&(i=n)}else e[n][1].type===`content`&&e.splice(n,1),!a&&e[n][1].type===`definition`&&(a=n);let o={type:`setextHeading`,start:{...e[r][1].start},end:{...e[e.length-1][1].end}};return e[i][1].type=`setextHeadingText`,a?(e.splice(i,0,[`enter`,o,t]),e.splice(a+1,0,[`exit`,e[r][1],t]),e[r][1].end={...e[a][1].end}):e[r][1]=o,e.push([`exit`,o,t]),e}function LYe(e,t,n){let r=this,i;return a;function a(t){let a=r.events.length,s;for(;a--;)if(r.events[a][1].type!==`lineEnding`&&r.events[a][1].type!==`linePrefix`&&r.events[a][1].type!==`content`){s=r.events[a][1].type===`paragraph`;break}return!r.parser.lazy[r.now().line]&&(r.interrupt||s)?(e.enter(`setextHeadingLine`),i=t,o(t)):n(t)}function o(t){return e.enter(`setextHeadingLineSequence`),s(t)}function s(t){return t===i?(e.consume(t),s):(e.exit(`setextHeadingLineSequence`),x7(t)?w7(e,c,`lineSuffix`)(t):c(t))}function c(r){return r===null||y7(r)?(e.exit(`setextHeadingLine`),t(r)):n(r)}}var RYe={tokenize:zYe};function zYe(e){let t=this,n=e.attempt(O7,r,e.attempt(this.parser.constructs.flowInitial,i,w7(e,e.attempt(this.parser.constructs.flow,i,e.attempt(zJe,i)),`linePrefix`)));return n;function r(r){if(r===null){e.consume(r);return}return e.enter(`lineEndingBlank`),e.consume(r),e.exit(`lineEndingBlank`),t.currentConstruct=void 0,n}function i(r){if(r===null){e.consume(r);return}return e.enter(`lineEnding`),e.consume(r),e.exit(`lineEnding`),t.currentConstruct=void 0,n}}var BYe={resolveAll:WYe()},VYe=UYe(`string`),HYe=UYe(`text`);function UYe(e){return{resolveAll:WYe(e===`text`?GYe:void 0),tokenize:t};function t(t){let n=this,r=this.parser.constructs[e],i=t.attempt(r,a,o);return a;function a(e){return c(e)?i(e):o(e)}function o(e){if(e===null){t.consume(e);return}return t.enter(`data`),t.consume(e),s}function s(e){return c(e)?(t.exit(`data`),i(e)):(t.consume(e),s)}function c(e){if(e===null)return!0;let t=r[e],i=-1;if(t)for(;++ieXe,contentInitial:()=>JYe,disable:()=>tXe,document:()=>qYe,flow:()=>XYe,flowInitial:()=>YYe,insideSpan:()=>$Ye,string:()=>ZYe,text:()=>QYe}),qYe={42:F7,43:F7,45:F7,48:F7,49:F7,50:F7,51:F7,52:F7,53:F7,54:F7,55:F7,56:F7,57:F7,62:_Je},JYe={91:qJe},YYe={[-2]:k7,[-1]:k7,32:k7},XYe={35:$Je,42:P7,45:[FYe,P7],60:iYe,61:FYe,95:P7,96:EJe,126:EJe},ZYe={38:CJe,92:xJe},QYe={[-5]:N7,[-4]:N7,[-3]:N7,33:SYe,38:CJe,42:D7,60:[mJe,dYe],91:wYe,92:[ZJe,xJe],93:M7,95:D7,96:MJe},$Ye={null:[D7,BYe]},eXe={null:[42,95]},tXe={null:[]};function nXe(e,t,n){let r={_bufferIndex:-1,_index:0,line:n&&n.line||1,column:n&&n.column||1,offset:n&&n.offset||0},i={},a=[],o=[],s=[],c={attempt:C(x),check:C(S),consume:v,enter:y,exit:b,interrupt:C(S,{interrupt:!0})},l={code:null,containerState:{},defineSkip:h,events:[],now:m,parser:e,previous:null,sliceSerialize:f,sliceStream:p,write:d},u=t.tokenize.call(l,c);return t.resolveAll&&a.push(t),l;function d(e){return o=p7(o,e),g(),o[o.length-1]===null?(w(t,0),l.events=E7(a,l.events,l),l.events):[]}function f(e,t){return iXe(p(e),t)}function p(e){return rXe(o,e)}function m(){let{_bufferIndex:e,_index:t,line:n,column:i,offset:a}=r;return{_bufferIndex:e,_index:t,line:n,column:i,offset:a}}function h(e){i[e.line]=e.column,E()}function g(){let e;for(;r._index-1){let e=o[0];typeof e==`string`?o[0]=e.slice(r):o.shift()}a>0&&o.push(e[i].slice(0,a))}return o}function iXe(e,t){let n=-1,r=[],i;for(;++n0){let e=a.tokenStack[a.tokenStack.length-1];(e[1]||gXe).call(a,void 0,e[0])}for(r.position={start:I7(e.length>0?e[0][1].start:{line:1,column:1,offset:0}),end:I7(e.length>0?e[e.length-2][1].end:{line:1,column:1,offset:0})},d=-1;++d0&&(r.className=[`language-`+i[0]]);let a={type:`element`,tagName:`code`,properties:r,children:[{type:`text`,value:n}]};return t.meta&&(a.data={meta:t.meta}),e.patch(t,a),a=e.applyData(t,a),a={type:`element`,tagName:`pre`,properties:{},children:[a]},e.patch(t,a),a}function xXe(e,t){let n={type:`element`,tagName:`del`,properties:{},children:e.all(t)};return e.patch(t,n),e.applyData(t,n)}function SXe(e,t){let n={type:`element`,tagName:`em`,properties:{},children:e.all(t)};return e.patch(t,n),e.applyData(t,n)}function CXe(e,t){let n=typeof e.options.clobberPrefix==`string`?e.options.clobberPrefix:`user-content-`,r=String(t.identifier).toUpperCase(),i=C7(r.toLowerCase()),a=e.footnoteOrder.indexOf(r),o,s=e.footnoteCounts.get(r);s===void 0?(s=0,e.footnoteOrder.push(r),o=e.footnoteOrder.length):o=a+1,s+=1,e.footnoteCounts.set(r,s);let c={type:`element`,tagName:`a`,properties:{href:`#`+n+`fn-`+i,id:n+`fnref-`+i+(s>1?`-`+s:``),dataFootnoteRef:!0,ariaDescribedBy:[`footnote-label`]},children:[{type:`text`,value:String(o)}]};e.patch(t,c);let l={type:`element`,tagName:`sup`,properties:{},children:[c]};return e.patch(t,l),e.applyData(t,l)}function wXe(e,t){let n={type:`element`,tagName:`h`+t.depth,properties:{},children:e.all(t)};return e.patch(t,n),e.applyData(t,n)}function TXe(e,t){if(e.options.allowDangerousHtml){let n={type:`raw`,value:t.value};return e.patch(t,n),e.applyData(t,n)}}function EXe(e,t){let n=t.referenceType,r=`]`;if(n===`collapsed`?r+=`[]`:n===`full`&&(r+=`[`+(t.label||t.identifier)+`]`),t.type===`imageReference`)return[{type:`text`,value:`![`+t.alt+r}];let i=e.all(t),a=i[0];a&&a.type===`text`?a.value=`[`+a.value:i.unshift({type:`text`,value:`[`});let o=i[i.length-1];return o&&o.type===`text`?o.value+=r:i.push({type:`text`,value:r}),i}function DXe(e,t){let n=String(t.identifier).toUpperCase(),r=e.definitionById.get(n);if(!r)return EXe(e,t);let i={src:C7(r.url||``),alt:t.alt};r.title!==null&&r.title!==void 0&&(i.title=r.title);let a={type:`element`,tagName:`img`,properties:i,children:[]};return e.patch(t,a),e.applyData(t,a)}function OXe(e,t){let n={src:C7(t.url)};t.alt!==null&&t.alt!==void 0&&(n.alt=t.alt),t.title!==null&&t.title!==void 0&&(n.title=t.title);let r={type:`element`,tagName:`img`,properties:n,children:[]};return e.patch(t,r),e.applyData(t,r)}function kXe(e,t){let n={type:`text`,value:t.value.replace(/\r?\n|\r/g,` `)};e.patch(t,n);let r={type:`element`,tagName:`code`,properties:{},children:[n]};return e.patch(t,r),e.applyData(t,r)}function AXe(e,t){let n=String(t.identifier).toUpperCase(),r=e.definitionById.get(n);if(!r)return EXe(e,t);let i={href:C7(r.url||``)};r.title!==null&&r.title!==void 0&&(i.title=r.title);let a={type:`element`,tagName:`a`,properties:i,children:e.all(t)};return e.patch(t,a),e.applyData(t,a)}function jXe(e,t){let n={href:C7(t.url)};t.title!==null&&t.title!==void 0&&(n.title=t.title);let r={type:`element`,tagName:`a`,properties:n,children:e.all(t)};return e.patch(t,r),e.applyData(t,r)}function MXe(e,t,n){let r=e.all(t),i=n?NXe(n):PXe(t),a={},o=[];if(typeof t.checked==`boolean`){let e=r[0],n;e&&e.type===`element`&&e.tagName===`p`?n=e:(n={type:`element`,tagName:`p`,properties:{},children:[]},r.unshift(n)),n.children.length>0&&n.children.unshift({type:`text`,value:` `}),n.children.unshift({type:`element`,tagName:`input`,properties:{type:`checkbox`,checked:t.checked,disabled:!0},children:[]}),a.className=[`task-list-item`]}let s=-1;for(;++s0){let e=a.tokenStack[a.tokenStack.length-1];(e[1]||_Xe).call(a,void 0,e[0])}for(r.position={start:I7(e.length>0?e[0][1].start:{line:1,column:1,offset:0}),end:I7(e.length>0?e[e.length-2][1].end:{line:1,column:1,offset:0})},d=-1;++d0&&(r.className=[`language-`+i[0]]);let a={type:`element`,tagName:`code`,properties:r,children:[{type:`text`,value:n}]};return t.meta&&(a.data={meta:t.meta}),e.patch(t,a),a=e.applyData(t,a),a={type:`element`,tagName:`pre`,properties:{},children:[a]},e.patch(t,a),a}function SXe(e,t){let n={type:`element`,tagName:`del`,properties:{},children:e.all(t)};return e.patch(t,n),e.applyData(t,n)}function CXe(e,t){let n={type:`element`,tagName:`em`,properties:{},children:e.all(t)};return e.patch(t,n),e.applyData(t,n)}function wXe(e,t){let n=typeof e.options.clobberPrefix==`string`?e.options.clobberPrefix:`user-content-`,r=String(t.identifier).toUpperCase(),i=C7(r.toLowerCase()),a=e.footnoteOrder.indexOf(r),o,s=e.footnoteCounts.get(r);s===void 0?(s=0,e.footnoteOrder.push(r),o=e.footnoteOrder.length):o=a+1,s+=1,e.footnoteCounts.set(r,s);let c={type:`element`,tagName:`a`,properties:{href:`#`+n+`fn-`+i,id:n+`fnref-`+i+(s>1?`-`+s:``),dataFootnoteRef:!0,ariaDescribedBy:[`footnote-label`]},children:[{type:`text`,value:String(o)}]};e.patch(t,c);let l={type:`element`,tagName:`sup`,properties:{},children:[c]};return e.patch(t,l),e.applyData(t,l)}function TXe(e,t){let n={type:`element`,tagName:`h`+t.depth,properties:{},children:e.all(t)};return e.patch(t,n),e.applyData(t,n)}function EXe(e,t){if(e.options.allowDangerousHtml){let n={type:`raw`,value:t.value};return e.patch(t,n),e.applyData(t,n)}}function DXe(e,t){let n=t.referenceType,r=`]`;if(n===`collapsed`?r+=`[]`:n===`full`&&(r+=`[`+(t.label||t.identifier)+`]`),t.type===`imageReference`)return[{type:`text`,value:`![`+t.alt+r}];let i=e.all(t),a=i[0];a&&a.type===`text`?a.value=`[`+a.value:i.unshift({type:`text`,value:`[`});let o=i[i.length-1];return o&&o.type===`text`?o.value+=r:i.push({type:`text`,value:r}),i}function OXe(e,t){let n=String(t.identifier).toUpperCase(),r=e.definitionById.get(n);if(!r)return DXe(e,t);let i={src:C7(r.url||``),alt:t.alt};r.title!==null&&r.title!==void 0&&(i.title=r.title);let a={type:`element`,tagName:`img`,properties:i,children:[]};return e.patch(t,a),e.applyData(t,a)}function kXe(e,t){let n={src:C7(t.url)};t.alt!==null&&t.alt!==void 0&&(n.alt=t.alt),t.title!==null&&t.title!==void 0&&(n.title=t.title);let r={type:`element`,tagName:`img`,properties:n,children:[]};return e.patch(t,r),e.applyData(t,r)}function AXe(e,t){let n={type:`text`,value:t.value.replace(/\r?\n|\r/g,` `)};e.patch(t,n);let r={type:`element`,tagName:`code`,properties:{},children:[n]};return e.patch(t,r),e.applyData(t,r)}function jXe(e,t){let n=String(t.identifier).toUpperCase(),r=e.definitionById.get(n);if(!r)return DXe(e,t);let i={href:C7(r.url||``)};r.title!==null&&r.title!==void 0&&(i.title=r.title);let a={type:`element`,tagName:`a`,properties:i,children:e.all(t)};return e.patch(t,a),e.applyData(t,a)}function MXe(e,t){let n={href:C7(t.url)};t.title!==null&&t.title!==void 0&&(n.title=t.title);let r={type:`element`,tagName:`a`,properties:n,children:e.all(t)};return e.patch(t,r),e.applyData(t,r)}function NXe(e,t,n){let r=e.all(t),i=n?PXe(n):FXe(t),a={},o=[];if(typeof t.checked==`boolean`){let e=r[0],n;e&&e.type===`element`&&e.tagName===`p`?n=e:(n={type:`element`,tagName:`p`,properties:{},children:[]},r.unshift(n)),n.children.length>0&&n.children.unshift({type:`text`,value:` `}),n.children.unshift({type:`element`,tagName:`input`,properties:{type:`checkbox`,checked:t.checked,disabled:!0},children:[]}),a.className=[`task-list-item`]}let s=-1;for(;++s1}function FXe(e,t){let n={},r=e.all(t),i=-1;for(typeof t.start==`number`&&t.start!==1&&(n.start=t.start);++i0){let r={type:`element`,tagName:`tbody`,properties:{},children:e.wrap(n,!0)},a=n7(t.children[1]),o=pqe(t.children[t.children.length-1]);a&&o&&(r.position={start:a,end:o}),i.push(r)}let a={type:`element`,tagName:`table`,properties:{},children:e.wrap(i,!0)};return e.patch(t,a),e.applyData(t,a)}function BXe(e,t,n){let r=n?n.children:void 0,i=(r?r.indexOf(t):1)===0?`th`:`td`,a=n&&n.type===`table`?n.align:void 0,o=a?a.length:t.children.length,s=-1,c=[];for(;++s0,!0),r[0]),i=r.index+r[0].length,r=n.exec(t);return a.push(GXe(t.slice(i),i>0,!1)),a.join(``)}function GXe(e,t,n){let r=0,i=e.length;if(t){let t=e.codePointAt(r);for(;t===HXe||t===UXe;)r++,t=e.codePointAt(r)}if(n){let t=e.codePointAt(i-1);for(;t===HXe||t===UXe;)i--,t=e.codePointAt(i-1)}return i>r?e.slice(r,i):``}function KXe(e,t){let n={type:`text`,value:WXe(String(t.value))};return e.patch(t,n),e.applyData(t,n)}function qXe(e,t){let n={type:`element`,tagName:`hr`,properties:{},children:[]};return e.patch(t,n),e.applyData(t,n)}var JXe={blockquote:vXe,break:yXe,code:bXe,delete:xXe,emphasis:SXe,footnoteReference:CXe,heading:wXe,html:TXe,imageReference:DXe,image:OXe,inlineCode:kXe,linkReference:AXe,link:jXe,listItem:MXe,list:FXe,paragraph:IXe,root:LXe,strong:RXe,table:zXe,tableCell:VXe,tableRow:BXe,text:KXe,thematicBreak:qXe,toml:L7,yaml:L7,definition:L7,footnoteDefinition:L7};function L7(){}var YXe=typeof self==`object`?self:globalThis,XXe=(e,t)=>{switch(e){case`Function`:case`SharedWorker`:case`Worker`:case`eval`:case`setInterval`:case`setTimeout`:throw TypeError(`unable to deserialize `+e)}return new YXe[e](t)},ZXe=(e,t)=>{let n=(t,n)=>(e.set(n,t),t),r=i=>{if(e.has(i))return e.get(i);let[a,o]=t[i];switch(a){case 0:case-1:return n(o,i);case 1:{let e=n([],i);for(let t of o)e.push(r(t));return e}case 2:{let e=n({},i);for(let[t,n]of o)e[r(t)]=r(n);return e}case 3:return n(new Date(o),i);case 4:{let{source:e,flags:t}=o;return n(new RegExp(e,t),i)}case 5:{let e=n(new Map,i);for(let[t,n]of o)e.set(r(t),r(n));return e}case 6:{let e=n(new Set,i);for(let t of o)e.add(r(t));return e}case 7:{let{name:e,message:t}=o;return n(XXe(e,t),i)}case 8:return n(BigInt(o),i);case`BigInt`:return n(Object(BigInt(o)),i);case`ArrayBuffer`:return n(new Uint8Array(o).buffer,o);case`DataView`:{let{buffer:e}=new Uint8Array(o);return n(new DataView(e),o)}}return n(XXe(a,o),i)};return r},QXe=e=>ZXe(new Map,e)(0),R7=``,{toString:$Xe}={},{keys:eZe}=Object,z7=e=>{let t=typeof e;if(t!==`object`||!e)return[0,t];let n=$Xe.call(e).slice(8,-1);switch(n){case`Array`:return[1,R7];case`Object`:return[2,R7];case`Date`:return[3,R7];case`RegExp`:return[4,R7];case`Map`:return[5,R7];case`Set`:return[6,R7];case`DataView`:return[1,n]}return n.includes(`Array`)?[1,n]:n.includes(`Error`)?[7,n]:[2,n]},B7=([e,t])=>e===0&&(t===`function`||t===`symbol`),tZe=(e,t,n,r)=>{let i=(e,t)=>{let i=r.push(e)-1;return n.set(t,i),i},a=r=>{if(n.has(r))return n.get(r);let[o,s]=z7(r);switch(o){case 0:{let t=r;switch(s){case`bigint`:o=8,t=r.toString();break;case`function`:case`symbol`:if(e)throw TypeError(`unable to serialize `+s);t=null;break;case`undefined`:return i([-1],r)}return i([o,t],r)}case 1:{if(s){let e=r;return s===`DataView`?e=new Uint8Array(r.buffer):s===`ArrayBuffer`&&(e=new Uint8Array(r)),i([s,[...e]],r)}let e=[],t=i([o,e],r);for(let t of r)e.push(a(t));return t}case 2:{if(s)switch(s){case`BigInt`:return i([s,r.toString()],r);case`Boolean`:case`Number`:case`String`:return i([s,r.valueOf()],r)}if(t&&`toJSON`in r)return a(r.toJSON());let n=[],c=i([o,n],r);for(let t of eZe(r))(e||!B7(z7(r[t])))&&n.push([a(t),a(r[t])]);return c}case 3:return i([o,r.toISOString()],r);case 4:{let{source:e,flags:t}=r;return i([o,{source:e,flags:t}],r)}case 5:{let t=[],n=i([o,t],r);for(let[n,i]of r)(e||!(B7(z7(n))||B7(z7(i))))&&t.push([a(n),a(i)]);return n}case 6:{let t=[],n=i([o,t],r);for(let n of r)(e||!B7(z7(n)))&&t.push(a(n));return n}}let{message:c}=r;return i([o,{name:s,message:c}],r)};return a},nZe=(e,{json:t,lossy:n}={})=>{let r=[];return tZe(!(t||n),!!t,new Map,r)(e),r},V7=typeof structuredClone==`function`?(e,t)=>t&&(`json`in t||`lossy`in t)?QXe(nZe(e,t)):structuredClone(e):(e,t)=>QXe(nZe(e,t));function rZe(e,t){let n=[{type:`text`,value:`↩`}];return t>1&&n.push({type:`element`,tagName:`sup`,properties:{},children:[{type:`text`,value:String(t)}]}),n}function iZe(e,t){return`Back to reference `+(e+1)+(t>1?`-`+t:``)}function aZe(e){let t=typeof e.options.clobberPrefix==`string`?e.options.clobberPrefix:`user-content-`,n=e.options.footnoteBackContent||rZe,r=e.options.footnoteBackLabel||iZe,i=e.options.footnoteLabel||`Footnotes`,a=e.options.footnoteLabelTagName||`h2`,o=e.options.footnoteLabelProperties||{className:[`sr-only`]},s=[],c=-1;for(;++c0&&d.push({type:`text`,value:` `});let e=typeof n==`string`?n:n(c,u);typeof e==`string`&&(e={type:`text`,value:e}),d.push({type:`element`,tagName:`a`,properties:{href:`#`+t+`fnref-`+l+(u>1?`-`+u:``),dataFootnoteBackref:``,ariaLabel:typeof r==`string`?r:r(c,u),className:[`data-footnote-backref`]},children:Array.isArray(e)?e:[e]})}let p=a[a.length-1];if(p&&p.type===`element`&&p.tagName===`p`){let e=p.children[p.children.length-1];e&&e.type===`text`?e.value+=` `:p.children.push({type:`text`,value:` `}),p.children.push(...d)}else a.push(...d);let m={type:`element`,tagName:`li`,properties:{id:t+`fn-`+l},children:e.wrap(a,!0)};e.patch(i,m),s.push(m)}if(s.length!==0)return{type:`element`,tagName:`section`,properties:{dataFootnotes:!0,className:[`footnotes`]},children:[{type:`element`,tagName:a,properties:{...V7(o),id:`footnote-label`},children:[{type:`text`,value:i}]},{type:`text`,value:` +`});let l={type:`element`,tagName:`li`,properties:a,children:o};return e.patch(t,l),e.applyData(t,l)}function PXe(e){let t=!1;if(e.type===`list`){t=e.spread||!1;let n=e.children,r=-1;for(;!t&&++r1}function IXe(e,t){let n={},r=e.all(t),i=-1;for(typeof t.start==`number`&&t.start!==1&&(n.start=t.start);++i0){let r={type:`element`,tagName:`tbody`,properties:{},children:e.wrap(n,!0)},a=n7(t.children[1]),o=mqe(t.children[t.children.length-1]);a&&o&&(r.position={start:a,end:o}),i.push(r)}let a={type:`element`,tagName:`table`,properties:{},children:e.wrap(i,!0)};return e.patch(t,a),e.applyData(t,a)}function VXe(e,t,n){let r=n?n.children:void 0,i=(r?r.indexOf(t):1)===0?`th`:`td`,a=n&&n.type===`table`?n.align:void 0,o=a?a.length:t.children.length,s=-1,c=[];for(;++s0,!0),r[0]),i=r.index+r[0].length,r=n.exec(t);return a.push(KXe(t.slice(i),i>0,!1)),a.join(``)}function KXe(e,t,n){let r=0,i=e.length;if(t){let t=e.codePointAt(r);for(;t===UXe||t===WXe;)r++,t=e.codePointAt(r)}if(n){let t=e.codePointAt(i-1);for(;t===UXe||t===WXe;)i--,t=e.codePointAt(i-1)}return i>r?e.slice(r,i):``}function qXe(e,t){let n={type:`text`,value:GXe(String(t.value))};return e.patch(t,n),e.applyData(t,n)}function JXe(e,t){let n={type:`element`,tagName:`hr`,properties:{},children:[]};return e.patch(t,n),e.applyData(t,n)}var YXe={blockquote:yXe,break:bXe,code:xXe,delete:SXe,emphasis:CXe,footnoteReference:wXe,heading:TXe,html:EXe,imageReference:OXe,image:kXe,inlineCode:AXe,linkReference:jXe,link:MXe,listItem:NXe,list:IXe,paragraph:LXe,root:RXe,strong:zXe,table:BXe,tableCell:HXe,tableRow:VXe,text:qXe,thematicBreak:JXe,toml:L7,yaml:L7,definition:L7,footnoteDefinition:L7};function L7(){}var XXe=typeof self==`object`?self:globalThis,ZXe=(e,t)=>{switch(e){case`Function`:case`SharedWorker`:case`Worker`:case`eval`:case`setInterval`:case`setTimeout`:throw TypeError(`unable to deserialize `+e)}return new XXe[e](t)},QXe=(e,t)=>{let n=(t,n)=>(e.set(n,t),t),r=i=>{if(e.has(i))return e.get(i);let[a,o]=t[i];switch(a){case 0:case-1:return n(o,i);case 1:{let e=n([],i);for(let t of o)e.push(r(t));return e}case 2:{let e=n({},i);for(let[t,n]of o)e[r(t)]=r(n);return e}case 3:return n(new Date(o),i);case 4:{let{source:e,flags:t}=o;return n(new RegExp(e,t),i)}case 5:{let e=n(new Map,i);for(let[t,n]of o)e.set(r(t),r(n));return e}case 6:{let e=n(new Set,i);for(let t of o)e.add(r(t));return e}case 7:{let{name:e,message:t}=o;return n(ZXe(e,t),i)}case 8:return n(BigInt(o),i);case`BigInt`:return n(Object(BigInt(o)),i);case`ArrayBuffer`:return n(new Uint8Array(o).buffer,o);case`DataView`:{let{buffer:e}=new Uint8Array(o);return n(new DataView(e),o)}}return n(ZXe(a,o),i)};return r},$Xe=e=>QXe(new Map,e)(0),R7=``,{toString:eZe}={},{keys:tZe}=Object,z7=e=>{let t=typeof e;if(t!==`object`||!e)return[0,t];let n=eZe.call(e).slice(8,-1);switch(n){case`Array`:return[1,R7];case`Object`:return[2,R7];case`Date`:return[3,R7];case`RegExp`:return[4,R7];case`Map`:return[5,R7];case`Set`:return[6,R7];case`DataView`:return[1,n]}return n.includes(`Array`)?[1,n]:n.includes(`Error`)?[7,n]:[2,n]},B7=([e,t])=>e===0&&(t===`function`||t===`symbol`),nZe=(e,t,n,r)=>{let i=(e,t)=>{let i=r.push(e)-1;return n.set(t,i),i},a=r=>{if(n.has(r))return n.get(r);let[o,s]=z7(r);switch(o){case 0:{let t=r;switch(s){case`bigint`:o=8,t=r.toString();break;case`function`:case`symbol`:if(e)throw TypeError(`unable to serialize `+s);t=null;break;case`undefined`:return i([-1],r)}return i([o,t],r)}case 1:{if(s){let e=r;return s===`DataView`?e=new Uint8Array(r.buffer):s===`ArrayBuffer`&&(e=new Uint8Array(r)),i([s,[...e]],r)}let e=[],t=i([o,e],r);for(let t of r)e.push(a(t));return t}case 2:{if(s)switch(s){case`BigInt`:return i([s,r.toString()],r);case`Boolean`:case`Number`:case`String`:return i([s,r.valueOf()],r)}if(t&&`toJSON`in r)return a(r.toJSON());let n=[],c=i([o,n],r);for(let t of tZe(r))(e||!B7(z7(r[t])))&&n.push([a(t),a(r[t])]);return c}case 3:return i([o,r.toISOString()],r);case 4:{let{source:e,flags:t}=r;return i([o,{source:e,flags:t}],r)}case 5:{let t=[],n=i([o,t],r);for(let[n,i]of r)(e||!(B7(z7(n))||B7(z7(i))))&&t.push([a(n),a(i)]);return n}case 6:{let t=[],n=i([o,t],r);for(let n of r)(e||!B7(z7(n)))&&t.push(a(n));return n}}let{message:c}=r;return i([o,{name:s,message:c}],r)};return a},rZe=(e,{json:t,lossy:n}={})=>{let r=[];return nZe(!(t||n),!!t,new Map,r)(e),r},V7=typeof structuredClone==`function`?(e,t)=>t&&(`json`in t||`lossy`in t)?$Xe(rZe(e,t)):structuredClone(e):(e,t)=>$Xe(rZe(e,t));function iZe(e,t){let n=[{type:`text`,value:`↩`}];return t>1&&n.push({type:`element`,tagName:`sup`,properties:{},children:[{type:`text`,value:String(t)}]}),n}function aZe(e,t){return`Back to reference `+(e+1)+(t>1?`-`+t:``)}function oZe(e){let t=typeof e.options.clobberPrefix==`string`?e.options.clobberPrefix:`user-content-`,n=e.options.footnoteBackContent||iZe,r=e.options.footnoteBackLabel||aZe,i=e.options.footnoteLabel||`Footnotes`,a=e.options.footnoteLabelTagName||`h2`,o=e.options.footnoteLabelProperties||{className:[`sr-only`]},s=[],c=-1;for(;++c0&&d.push({type:`text`,value:` `});let e=typeof n==`string`?n:n(c,u);typeof e==`string`&&(e={type:`text`,value:e}),d.push({type:`element`,tagName:`a`,properties:{href:`#`+t+`fnref-`+l+(u>1?`-`+u:``),dataFootnoteBackref:``,ariaLabel:typeof r==`string`?r:r(c,u),className:[`data-footnote-backref`]},children:Array.isArray(e)?e:[e]})}let p=a[a.length-1];if(p&&p.type===`element`&&p.tagName===`p`){let e=p.children[p.children.length-1];e&&e.type===`text`?e.value+=` `:p.children.push({type:`text`,value:` `}),p.children.push(...d)}else a.push(...d);let m={type:`element`,tagName:`li`,properties:{id:t+`fn-`+l},children:e.wrap(a,!0)};e.patch(i,m),s.push(m)}if(s.length!==0)return{type:`element`,tagName:`section`,properties:{dataFootnotes:!0,className:[`footnotes`]},children:[{type:`element`,tagName:a,properties:{...V7(o),id:`footnote-label`},children:[{type:`text`,value:i}]},{type:`text`,value:` `},{type:`element`,tagName:`ol`,properties:{},children:e.wrap(s,!0)},{type:`text`,value:` -`}]}}var oZe=(function(e){if(e==null)return uZe;if(typeof e==`function`)return H7(e);if(typeof e==`object`)return Array.isArray(e)?sZe(e):cZe(e);if(typeof e==`string`)return lZe(e);throw Error(`Expected function, string, or object as test`)});function sZe(e){let t=[],n=-1;for(;++n`:``))+`)`})}return u;function u(){let l=pZe,u,d,f;if((!t||a(e,i,c[c.length-1]||void 0))&&(l=hZe(n(e,c)),l[0]===!1))return l;if(`children`in e&&e.children){let t=e;if(t.children&&l[0]!==`skip`)for(d=(r?t.children.length:-1)+o,f=c.concat(t);d>-1&&d`:``))+`)`})}return u;function u(){let l=mZe,u,d,f;if((!t||a(e,i,c[c.length-1]||void 0))&&(l=gZe(n(e,c)),l[0]===!1))return l;if(`children`in e&&e.children){let t=e;if(t.children&&l[0]!==`skip`)for(d=(r?t.children.length:-1)+o,f=c.concat(t);d>-1&&d0&&n.push({type:`text`,value:` -`}),n}function CZe(e){let t=0,n=e.charCodeAt(t);for(;n===9||n===32;)t++,n=e.charCodeAt(t);return e.slice(t)}function wZe(e,t){let n=vZe(e,t),r=n.one(e,void 0),i=aZe(n),a=Array.isArray(r)?{type:`root`,children:r}:r||{type:`root`,children:[]};return i&&(`children`in a,a.children.push({type:`text`,value:` -`},i)),a}function TZe(e,t){return e&&`run`in e?async function(n,r){let i=wZe(n,{file:r,...t});await e.run(i,r)}:function(n,r){return wZe(n,{file:r,...e||t})}}function EZe(e){if(e)throw e}var DZe=o(((e,t)=>{var n=Object.prototype.hasOwnProperty,r=Object.prototype.toString,i=Object.defineProperty,a=Object.getOwnPropertyDescriptor,o=function(e){return typeof Array.isArray==`function`?Array.isArray(e):r.call(e)===`[object Array]`},s=function(e){if(!e||r.call(e)!==`[object Object]`)return!1;var t=n.call(e,`constructor`),i=e.constructor&&e.constructor.prototype&&n.call(e.constructor.prototype,`isPrototypeOf`);if(e.constructor&&!t&&!i)return!1;for(var a in e);return a===void 0||n.call(e,a)},c=function(e,t){i&&t.name===`__proto__`?i(e,t.name,{enumerable:!0,configurable:!0,value:t.newValue,writable:!0}):e[t.name]=t.newValue},l=function(e,t){if(t===`__proto__`){if(!n.call(e,t))return;if(a)return a(e,t).value}return e[t]};t.exports=function e(){var t,n,r,i,a,u,d=arguments[0],f=1,p=arguments.length,m=!1;for(typeof d==`boolean`&&(m=d,d=arguments[1]||{},f=2),(d==null||typeof d!=`object`&&typeof d!=`function`)&&(d={});ft.length,o;r&&t.push(i);try{o=e.apply(this,t)}catch(e){let t=e;if(r&&n)throw t;return i(t)}r||(o&&o.then&&typeof o.then==`function`?o.then(a,i):o instanceof Error?i(o):a(o))}function i(e,...r){n||(n=!0,t(e,...r))}function a(e){i(null,e)}}var G7={basename:AZe,dirname:jZe,extname:MZe,join:NZe,sep:`/`};function AZe(e,t){if(t!==void 0&&typeof t!=`string`)throw TypeError(`"ext" argument must be a string`);K7(e);let n=0,r=-1,i=e.length,a;if(t===void 0||t.length===0||t.length>e.length){for(;i--;)if(e.codePointAt(i)===47){if(a){n=i+1;break}}else r<0&&(a=!0,r=i+1);return r<0?``:e.slice(n,r)}if(t===e)return``;let o=-1,s=t.length-1;for(;i--;)if(e.codePointAt(i)===47){if(a){n=i+1;break}}else o<0&&(a=!0,o=i+1),s>-1&&(e.codePointAt(i)===t.codePointAt(s--)?s<0&&(r=i):(s=-1,r=o));return n===r?r=o:r<0&&(r=e.length),e.slice(n,r)}function jZe(e){if(K7(e),e.length===0)return`.`;let t=-1,n=e.length,r;for(;--n;)if(e.codePointAt(n)===47){if(r){t=n;break}}else r||=!0;return t<0?e.codePointAt(0)===47?`/`:`.`:t===1&&e.codePointAt(0)===47?`//`:e.slice(0,t)}function MZe(e){K7(e);let t=e.length,n=-1,r=0,i=-1,a=0,o;for(;t--;){let s=e.codePointAt(t);if(s===47){if(o){r=t+1;break}continue}n<0&&(o=!0,n=t+1),s===46?i<0?i=t:a!==1&&(a=1):i>-1&&(a=-1)}return i<0||n<0||a===0||a===1&&i===n-1&&i===r+1?``:e.slice(i,n)}function NZe(...e){let t=-1,n;for(;++t0&&e.codePointAt(e.length-1)===47&&(n+=`/`),t?`/`+n:n}function FZe(e,t){let n=``,r=0,i=-1,a=0,o=-1,s,c;for(;++o<=e.length;){if(o2){if(c=n.lastIndexOf(`/`),c!==n.length-1){c<0?(n=``,r=0):(n=n.slice(0,c),r=n.length-1-n.lastIndexOf(`/`)),i=o,a=0;continue}}else if(n.length>0){n=``,r=0,i=o,a=0;continue}}t&&(n=n.length>0?n+`/..`:`..`,r=2)}else n.length>0?n+=`/`+e.slice(i+1,o):n=e.slice(i+1,o),r=o-i-1;i=o,a=0}else s===46&&a>-1?a++:a=-1}return n}function K7(e){if(typeof e!=`string`)throw TypeError(`Path must be a string. Received `+JSON.stringify(e))}var IZe={cwd:LZe};function LZe(){return`/`}function q7(e){return!!(typeof e==`object`&&e&&`href`in e&&e.href&&`protocol`in e&&e.protocol&&e.auth===void 0)}function RZe(e){if(typeof e==`string`)e=new URL(e);else if(!q7(e)){let t=TypeError('The "path" argument must be of type string or an instance of URL. Received `'+e+"`");throw t.code=`ERR_INVALID_ARG_TYPE`,t}if(e.protocol!==`file:`){let e=TypeError(`The URL must be of scheme file`);throw e.code=`ERR_INVALID_URL_SCHEME`,e}return zZe(e)}function zZe(e){if(e.hostname!==``){let e=TypeError(`File URL host must be "localhost" or empty on darwin`);throw e.code=`ERR_INVALID_FILE_URL_HOST`,e}let t=e.pathname,n=-1;for(;++n0){let[r,...a]=t,o=n[i][1];W7(o)&&W7(r)&&(r=(0,Z7.default)(!0,o,r)),n[i]=[e,r,...a]}}}}().freeze();function Q7(e,t){if(typeof t!=`function`)throw TypeError("Cannot `"+e+"` without `parser`")}function $7(e,t){if(typeof t!=`function`)throw TypeError("Cannot `"+e+"` without `compiler`")}function e9(e,t){if(t)throw Error("Cannot call `"+e+"` on a frozen processor.\nCreate a new processor first, by calling it: use `processor()` instead of `processor`.")}function KZe(e){if(!W7(e)||typeof e.type!=`string`)throw TypeError("Expected node, got `"+e+"`")}function qZe(e,t,n){if(!n)throw Error("`"+e+"` finished async. Use `"+t+"` instead")}function t9(e){return JZe(e)?e:new BZe(e)}function JZe(e){return!!(e&&typeof e==`object`&&`message`in e&&`messages`in e)}function YZe(e){return typeof e==`string`||XZe(e)}function XZe(e){return!!(e&&typeof e==`object`&&`byteLength`in e&&`byteOffset`in e)}var ZZe=[],QZe={allowDangerousHtml:!0},$Ze=/^(https?|ircs?|mailto|xmpp)$/i,eQe=[{from:`astPlugins`,id:`remove-buggy-html-in-markdown-parser`},{from:`allowDangerousHtml`,id:`remove-buggy-html-in-markdown-parser`},{from:`allowNode`,id:`replace-allownode-allowedtypes-and-disallowedtypes`,to:`allowElement`},{from:`allowedTypes`,id:`replace-allownode-allowedtypes-and-disallowedtypes`,to:`allowedElements`},{from:`disallowedTypes`,id:`replace-allownode-allowedtypes-and-disallowedtypes`,to:`disallowedElements`},{from:`escapeHtml`,id:`remove-buggy-html-in-markdown-parser`},{from:`includeElementIndex`,id:`#remove-includeelementindex`},{from:`includeNodeIndex`,id:`change-includenodeindex-to-includeelementindex`},{from:`linkTarget`,id:`remove-linktarget`},{from:`plugins`,id:`change-plugins-to-remarkplugins`,to:`remarkPlugins`},{from:`rawSourcePos`,id:`#remove-rawsourcepos`},{from:`renderers`,id:`change-renderers-to-components`,to:`components`},{from:`source`,id:`change-source-to-children`,to:`children`},{from:`sourcePos`,id:`#remove-sourcepos`},{from:`transformImageUri`,id:`#add-urltransform`,to:`urlTransform`},{from:`transformLinkUri`,id:`#add-urltransform`,to:`urlTransform`}];function tQe(e){let t=nQe(e),n=rQe(e);return iQe(t.runSync(t.parse(n),n),e)}function nQe(e){let t=e.rehypePlugins||ZZe,n=e.remarkPlugins||ZZe,r=e.remarkRehypeOptions?{...e.remarkRehypeOptions,...QZe}:QZe;return GZe().use(_Xe).use(n).use(TZe,r).use(t)}function rQe(e){let t=e.children||``,n=new BZe;return typeof t==`string`?n.value=t:``+t,n}function iQe(e,t){let n=t.allowedElements,r=t.allowElement,i=t.components,a=t.disallowedElements,o=t.skipHtml,s=t.unwrapDisallowed,c=t.urlTransform||aQe;for(let e of eQe)Object.hasOwn(t,e.from)&&``+e.from+(e.to?"use `"+e.to+"` instead":`remove it`)+e.id;return t.className&&(e={type:`element`,tagName:`div`,properties:{className:t.className},children:e.type===`root`?e.children:[e]}),gZe(e,l),Cqe(e,{Fragment:G.Fragment,components:i,ignoreInvalidStyle:!0,jsx:G.jsx,jsxs:G.jsxs,passKeys:!0,passNode:!0});function l(e,t,i){if(e.type===`raw`&&i&&typeof t==`number`)return o?i.children.splice(t,1):i.children[t]={type:`text`,value:e.value},t;if(e.type===`element`){let t;for(t in u7)if(Object.hasOwn(u7,t)&&Object.hasOwn(e.properties,t)){let n=e.properties[t],r=u7[t];(r===null||r.includes(e.tagName))&&(e.properties[t]=c(String(n||``),t,e))}}if(e.type===`element`){let o=n?!n.includes(e.tagName):a?a.includes(e.tagName):!1;if(!o&&r&&typeof t==`number`&&(o=!r(e,t,i)),o&&i&&typeof t==`number`)return s&&e.children?i.children.splice(t,1,...e.children):i.children.splice(t,1),t}}}function aQe(e){let t=e.indexOf(`:`),n=e.indexOf(`?`),r=e.indexOf(`#`),i=e.indexOf(`/`);return t===-1||i!==-1&&t>i||n!==-1&&t>n||r!==-1&&t>r||$Ze.test(e.slice(0,t))?e:``}hQe.peek=mQe;function oQe(){this.buffer()}function sQe(e){this.enter({type:`footnoteReference`,identifier:``,label:``},e)}function cQe(){this.buffer()}function lQe(e){this.enter({type:`footnoteDefinition`,identifier:``,label:``,children:[]},e)}function uQe(e){let t=this.resume(),n=this.stack[this.stack.length-1];n.type,n.identifier=m7(this.sliceSerialize(e)).toLowerCase(),n.label=t}function dQe(e){this.exit(e)}function fQe(e){let t=this.resume(),n=this.stack[this.stack.length-1];n.type,n.identifier=m7(this.sliceSerialize(e)).toLowerCase(),n.label=t}function pQe(e){this.exit(e)}function mQe(){return`[`}function hQe(e,t,n,r){let i=n.createTracker(r),a=i.move(`[^`),o=n.enter(`footnoteReference`),s=n.enter(`reference`);return a+=i.move(n.safe(n.associationId(e),{after:`]`,before:a})),s(),o(),a+=i.move(`]`),a}function gQe(){return{enter:{gfmFootnoteCallString:oQe,gfmFootnoteCall:sQe,gfmFootnoteDefinitionLabelString:cQe,gfmFootnoteDefinition:lQe},exit:{gfmFootnoteCallString:uQe,gfmFootnoteCall:dQe,gfmFootnoteDefinitionLabelString:fQe,gfmFootnoteDefinition:pQe}}}bQe.peek=xQe;function _Qe(){return{canContainEols:[`delete`],enter:{strikethrough:vQe},exit:{strikethrough:yQe}}}function vQe(e){this.enter({type:`delete`,children:[]},e)}function yQe(e){this.exit(e)}function bQe(e,t,n,r){let i=n.createTracker(r),a=n.enter(`strikethrough`),o=i.move(`~~`);return o+=n.containerPhrasing(e,{...i.current(),before:o,after:`~`}),o+=i.move(`~~`),a(),o}function xQe(){return`~`}function SQe(){return{enter:{table:CQe,tableData:EQe,tableHeader:EQe,tableRow:TQe},exit:{codeText:DQe,table:wQe,tableData:n9,tableHeader:n9,tableRow:n9}}}function CQe(e){let t=e._align;this.enter({type:`table`,align:t.map(function(e){return e===`none`?null:e}),children:[]},e),this.data.inTable=!0}function wQe(e){this.exit(e),this.data.inTable=void 0}function TQe(e){this.enter({type:`tableRow`,children:[]},e)}function n9(e){this.exit(e)}function EQe(e){this.enter({type:`tableCell`,children:[]},e)}function DQe(e){let t=this.resume();this.data.inTable&&(t=t.replace(/\\([\\|])/g,OQe));let n=this.stack[this.stack.length-1];n.type,n.value=t,this.exit(e)}function OQe(e,t){return t===`|`?t:e}function kQe(){return{exit:{taskListCheckValueChecked:AQe,taskListCheckValueUnchecked:AQe,paragraph:jQe}}}function AQe(e){let t=this.stack[this.stack.length-2];t.type,t.checked=e.type===`taskListCheckValueChecked`}function jQe(e){let t=this.stack[this.stack.length-2];if(t&&t.type===`listItem`&&typeof t.checked==`boolean`){let e=this.stack[this.stack.length-1];e.type;let n=e.children[0];if(n&&n.type===`text`){let r=t.children,i=-1,a;for(;++i999||s===93&&!o||s===null||s===91||b7(s))return n(s);if(s===93){e.exit(`chunkString`);let a=e.exit(`gfmFootnoteCallString`);return i.includes(m7(r.sliceSerialize(a)))?(e.enter(`gfmFootnoteCallLabelMarker`),e.consume(s),e.exit(`gfmFootnoteCallLabelMarker`),e.exit(`gfmFootnoteCall`),t):n(s)}return b7(s)||(o=!0),a++,e.consume(s),s===92?u:l}function u(t){return t===91||t===92||t===93?(e.consume(t),a++,l):l(t)}}function LQe(e,t,n){let r=this,i=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]),a,o=0,s;return c;function c(t){return e.enter(`gfmFootnoteDefinition`)._container=!0,e.enter(`gfmFootnoteDefinitionLabel`),e.enter(`gfmFootnoteDefinitionLabelMarker`),e.consume(t),e.exit(`gfmFootnoteDefinitionLabelMarker`),l}function l(t){return t===94?(e.enter(`gfmFootnoteDefinitionMarker`),e.consume(t),e.exit(`gfmFootnoteDefinitionMarker`),e.enter(`gfmFootnoteDefinitionLabelString`),e.enter(`chunkString`).contentType=`string`,u):n(t)}function u(t){if(o>999||t===93&&!s||t===null||t===91||b7(t))return n(t);if(t===93){e.exit(`chunkString`);let n=e.exit(`gfmFootnoteDefinitionLabelString`);return a=m7(r.sliceSerialize(n)),e.enter(`gfmFootnoteDefinitionLabelMarker`),e.consume(t),e.exit(`gfmFootnoteDefinitionLabelMarker`),e.exit(`gfmFootnoteDefinitionLabel`),f}return b7(t)||(s=!0),o++,e.consume(t),t===92?d:u}function d(t){return t===91||t===92||t===93?(e.consume(t),o++,u):u(t)}function f(t){return t===58?(e.enter(`definitionMarker`),e.consume(t),e.exit(`definitionMarker`),i.includes(a)||i.push(a),w7(e,p,`gfmFootnoteDefinitionWhitespace`)):n(t)}function p(e){return t(e)}}function RQe(e,t,n){return e.check(O7,t,e.attempt(MQe,t,n))}function zQe(e){e.exit(`gfmFootnoteDefinition`)}function BQe(e,t,n){let r=this;return w7(e,i,`gfmFootnoteDefinitionIndent`,5);function i(e){let i=r.events[r.events.length-1];return i&&i[1].type===`gfmFootnoteDefinitionIndent`&&i[2].sliceSerialize(i[1],!0).length===4?t(e):n(e)}}function VQe(e){let t=(e||{}).singleTilde,n={name:`strikethrough`,tokenize:i,resolveAll:r};return t??=!0,{text:{126:n},insideSpan:{null:[n]},attentionMarkers:{null:[126]}};function r(e,t){let n=-1;for(;++n1?r(a):(e.consume(a),o++,c);if(o<2&&!t)return r(a);let l=e.exit(`strikethroughSequenceTemporary`),u=T7(a);return l._open=!u||u===2&&!!s,l._close=!s||s===2&&!!u,n(a)}}}var HQe=class{constructor(){this.map=[]}add(e,t,n){UQe(this,e,t,n)}consume(e){if(this.map.sort(function(e,t){return e[0]-t[0]}),this.map.length===0)return;let t=this.map.length,n=[];for(;t>0;)--t,n.push(e.slice(this.map[t][0]+this.map[t][1]),this.map[t][2]),e.length=this.map[t][0];n.push(e.slice()),e.length=0;let r=n.pop();for(;r;){for(let t of r)e.push(t);r=n.pop()}this.map.length=0}};function UQe(e,t,n,r){let i=0;if(!(n===0&&r.length===0)){for(;i-1;){let e=r.events[t][1].type;if(e===`lineEnding`||e===`linePrefix`)t--;else break}let i=t>-1?r.events[t][1].type:null,a=i===`tableHead`||i===`tableRow`?S:c;return a===S&&r.parser.lazy[r.now().line]?n(e):a(e)}function c(t){return e.enter(`tableHead`),e.enter(`tableRow`),l(t)}function l(e){return e===124?u(e):(o=!0,a+=1,u(e))}function u(t){return t===null?n(t):y7(t)?a>1?(a=0,r.interrupt=!0,e.exit(`tableRow`),e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),p):n(t):x7(t)?w7(e,u,`whitespace`)(t):(a+=1,o&&(o=!1,i+=1),t===124?(e.enter(`tableCellDivider`),e.consume(t),e.exit(`tableCellDivider`),o=!0,u):(e.enter(`data`),d(t)))}function d(t){return t===null||t===124||b7(t)?(e.exit(`data`),u(t)):(e.consume(t),t===92?f:d)}function f(t){return t===92||t===124?(e.consume(t),d):d(t)}function p(t){return r.interrupt=!1,r.parser.lazy[r.now().line]?n(t):(e.enter(`tableDelimiterRow`),o=!1,x7(t)?w7(e,m,`linePrefix`,r.parser.constructs.disable.null.includes(`codeIndented`)?void 0:4)(t):m(t))}function m(t){return t===45||t===58?g(t):t===124?(o=!0,e.enter(`tableCellDivider`),e.consume(t),e.exit(`tableCellDivider`),h):x(t)}function h(t){return x7(t)?w7(e,g,`whitespace`)(t):g(t)}function g(t){return t===58?(a+=1,o=!0,e.enter(`tableDelimiterMarker`),e.consume(t),e.exit(`tableDelimiterMarker`),_):t===45?(a+=1,_(t)):t===null||y7(t)?b(t):x(t)}function _(t){return t===45?(e.enter(`tableDelimiterFiller`),v(t)):x(t)}function v(t){return t===45?(e.consume(t),v):t===58?(o=!0,e.exit(`tableDelimiterFiller`),e.enter(`tableDelimiterMarker`),e.consume(t),e.exit(`tableDelimiterMarker`),y):(e.exit(`tableDelimiterFiller`),y(t))}function y(t){return x7(t)?w7(e,b,`whitespace`)(t):b(t)}function b(n){return n===124?m(n):n===null||y7(n)?!o||i!==a?x(n):(e.exit(`tableDelimiterRow`),e.exit(`tableHead`),t(n)):x(n)}function x(e){return n(e)}function S(t){return e.enter(`tableRow`),C(t)}function C(n){return n===124?(e.enter(`tableCellDivider`),e.consume(n),e.exit(`tableCellDivider`),C):n===null||y7(n)?(e.exit(`tableRow`),t(n)):x7(n)?w7(e,C,`whitespace`)(n):(e.enter(`data`),w(n))}function w(t){return t===null||t===124||b7(t)?(e.exit(`data`),C(t)):(e.consume(t),t===92?T:w)}function T(t){return t===92||t===124?(e.consume(t),w):w(t)}}function qQe(e,t){let n=-1,r=!0,i=0,a=[0,0,0,0],o=[0,0,0,0],s=!1,c=0,l,u,d,f=new HQe;for(;++nn[2]+1){let t=n[2]+1,r=n[3]-n[2]-1;e.add(t,r,[])}}e.add(n[3]+1,0,[[`exit`,o,t]])}return i!==void 0&&(a.end=Object.assign({},i9(t.events,i)),e.add(i,0,[[`exit`,a,t]]),a=void 0),a}function JQe(e,t,n,r,i){let a=[],o=i9(t.events,n);i&&(i.end=Object.assign({},o),a.push([`exit`,i,t])),r.end=Object.assign({},o),a.push([`exit`,r,t]),e.add(n+1,0,a)}function i9(e,t){let n=e[t],r=n[0]===`enter`?`start`:`end`;return n[1][r]}var YQe={name:`tasklistCheck`,tokenize:ZQe};function XQe(){return{text:{91:YQe}}}function ZQe(e,t,n){let r=this;return i;function i(t){return r.previous!==null||!r._gfmTasklistFirstContentOfListItem?n(t):(e.enter(`taskListCheck`),e.enter(`taskListCheckMarker`),e.consume(t),e.exit(`taskListCheckMarker`),a)}function a(t){return b7(t)?(e.enter(`taskListCheckValueUnchecked`),e.consume(t),e.exit(`taskListCheckValueUnchecked`),o):t===88||t===120?(e.enter(`taskListCheckValueChecked`),e.consume(t),e.exit(`taskListCheckValueChecked`),o):n(t)}function o(t){return t===93?(e.enter(`taskListCheckMarker`),e.consume(t),e.exit(`taskListCheckMarker`),e.exit(`taskListCheck`),s):n(t)}function s(r){return y7(r)?t(r):x7(r)?e.check({tokenize:QQe},t,n)(r):n(r)}}function QQe(e,t,n){return w7(e,r,`whitespace`);function r(e){return e===null?n(e):t(e)}}function $Qe(){let e=this.data(),t=e.micromarkExtensions||=[],n=e.fromMarkdownExtensions||=[];t.push(NQe(),VQe(),GQe(),XQe()),n.push(gQe(),_Qe(),SQe(),kQe())}var e$e=`fileManager.readmeCollapsed`;function t$e({folderId:e}){let{t}=U(),[n,r]=(0,y.useState)(()=>localStorage.getItem(e$e)===`1`);(0,y.useEffect)(()=>{localStorage.setItem(e$e,n?`1`:`0`)},[n]);let{data:i,isLoading:a,error:o}=K({queryKey:[`folder-readme`,e],queryFn:()=>Z.getLibraryFolderReadme(e),retry:!1,staleTime:3e4});return a||o||!i?null:n?(0,G.jsxs)(`div`,{className:`mb-2 lg:mb-0 order-first lg:order-none lg:w-10 lg:flex-shrink-0 lg:h-full`,children:[(0,G.jsxs)(`button`,{type:`button`,onClick:()=>r(!1),title:t(`fileManager.readme.show`),"aria-label":t(`fileManager.readme.show`),className:`flex lg:hidden w-full items-center gap-2 px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg hover:bg-bambu-dark/40 transition-colors`,children:[(0,G.jsx)(fc,{className:`w-4 h-4 text-bambu-green flex-shrink-0`}),(0,G.jsx)(`span`,{className:`text-sm font-medium text-white truncate`,children:i.filename}),(0,G.jsx)(El,{className:`w-4 h-4 text-bambu-gray flex-shrink-0 ml-auto`})]}),(0,G.jsxs)(`button`,{type:`button`,onClick:()=>r(!1),title:t(`fileManager.readme.show`),"aria-label":t(`fileManager.readme.show`),className:`hidden lg:flex h-full w-10 flex-col items-center gap-2 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg hover:bg-bambu-dark/40 transition-colors`,children:[(0,G.jsx)(El,{className:`w-4 h-4 text-bambu-green flex-shrink-0`}),(0,G.jsx)(`span`,{className:`text-xs font-medium text-bambu-gray [writing-mode:vertical-rl] rotate-180 select-none`,children:t(`fileManager.readme.label`)})]})]}):(0,G.jsxs)(`div`,{className:`mb-4 lg:mb-0 order-first lg:order-none lg:w-80 xl:w-96 lg:flex-shrink-0 lg:h-full flex flex-col bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg overflow-hidden`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-2 px-3 py-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,G.jsx)(fc,{className:`w-4 h-4 text-bambu-green flex-shrink-0`}),(0,G.jsx)(`span`,{className:`text-sm font-medium text-white truncate`,title:i.filename,children:i.filename}),i.truncated&&(0,G.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-400 flex-shrink-0`,children:t(`fileManager.readme.truncated`)})]}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>r(!0),title:t(`fileManager.readme.hide`),"aria-label":t(`fileManager.readme.hide`),className:`p-1 rounded text-bambu-gray hover:text-white hover:bg-bambu-dark/40 transition-colors flex-shrink-0`,children:(0,G.jsx)(Tl,{className:`w-4 h-4`})})]}),(0,G.jsx)(`div`,{className:`px-4 py-3 border-t border-bambu-dark-tertiary flex-1 overflow-y-auto max-h-96 lg:max-h-none text-sm text-bambu-gray-light leading-relaxed space-y-2`,children:(0,G.jsx)(tQe,{remarkPlugins:[$Qe],components:{h1:({children:e})=>(0,G.jsx)(`h1`,{className:`text-lg font-semibold text-white mt-2 mb-1`,children:e}),h2:({children:e})=>(0,G.jsx)(`h2`,{className:`text-base font-semibold text-white mt-2 mb-1`,children:e}),h3:({children:e})=>(0,G.jsx)(`h3`,{className:`text-sm font-semibold text-white mt-2 mb-1`,children:e}),p:({children:e})=>(0,G.jsx)(`p`,{className:`my-1`,children:e}),ul:({children:e})=>(0,G.jsx)(`ul`,{className:`list-disc list-inside space-y-0.5 ml-2`,children:e}),ol:({children:e})=>(0,G.jsx)(`ol`,{className:`list-decimal list-inside space-y-0.5 ml-2`,children:e}),li:({children:e})=>(0,G.jsx)(`li`,{children:e}),code:({children:e,...t})=>t.className?(0,G.jsx)(`code`,{className:`block p-2 bg-bambu-dark rounded text-xs font-mono text-bambu-gray-light overflow-x-auto`,children:e}):(0,G.jsx)(`code`,{className:`px-1 py-0.5 bg-bambu-dark rounded text-xs font-mono text-bambu-green`,children:e}),pre:({children:e})=>(0,G.jsx)(`pre`,{className:`my-2`,children:e}),blockquote:({children:e})=>(0,G.jsx)(`blockquote`,{className:`border-l-2 border-bambu-dark-tertiary pl-3 text-bambu-gray italic`,children:e}),a:({children:e,href:t})=>(0,G.jsx)(`a`,{href:t,target:`_blank`,rel:`noopener noreferrer`,className:`text-bambu-green hover:underline`,children:e}),table:({children:e})=>(0,G.jsx)(`div`,{className:`overflow-x-auto`,children:(0,G.jsx)(`table`,{className:`min-w-full text-xs border-collapse`,children:e})}),th:({children:e})=>(0,G.jsx)(`th`,{className:`border border-bambu-dark-tertiary px-2 py-1 text-left font-semibold text-white`,children:e}),td:({children:e})=>(0,G.jsx)(`td`,{className:`border border-bambu-dark-tertiary px-2 py-1`,children:e}),hr:()=>(0,G.jsx)(`hr`,{className:`border-bambu-dark-tertiary my-2`})},children:i.content})})]})}function n$e({open:e,onClose:t,onPickTag:n}){let{t:r}=U(),i=co(),{showToast:a}=qd(),[o,s]=(0,y.useState)(!1),[c,l]=(0,y.useState)(null),[u,d]=(0,y.useState)(``),[f,p]=(0,y.useState)(null),{data:m=[],isLoading:h}=K({queryKey:R5,queryFn:Z.getLibraryTags,enabled:e}),g=()=>{i.invalidateQueries({queryKey:R5}),i.invalidateQueries({queryKey:[`library-files`]})},_=q({mutationFn:async()=>{let e=u.trim();if(!e)throw Error(r(`fileManager.tags.nameRequired`));return c?Z.updateLibraryTag(c.id,e):Z.createLibraryTag(e)},onSuccess:()=>{a(r(c?`fileManager.tags.updated`:`fileManager.tags.created`),`success`),s(!1),l(null),d(``),g()},onError:e=>{a(e.message||r(`fileManager.tags.saveFailed`),`error`)}}),v=q({mutationFn:e=>Z.deleteLibraryTag(e),onSuccess:()=>{a(r(`fileManager.tags.deleted`),`success`),p(null),g()},onError:e=>{a(e.message||r(`fileManager.tags.deleteFailed`),`error`)}}),b=()=>{l(null),d(``),s(!0)},x=e=>{l(e),d(e.name),s(!0)},S=(0,y.useCallback)(()=>{_.isPending||(s(!1),l(null),d(``))},[_.isPending]);(0,y.useEffect)(()=>{if(!e)return;let n=e=>{e.key===`Escape`&&(_.isPending||v.isPending||(o?S():f||t()))};return document.addEventListener(`keydown`,n),()=>document.removeEventListener(`keydown`,n)},[e,o,f,_.isPending,v.isPending,S,t]);let C=e=>{e.preventDefault(),_.mutate()};if(!e)return null;let w=`library-tags-modal-title`,T=`library-tag-editor-title`;return(0,G.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[(0,G.jsx)(`div`,{className:`absolute inset-0 bg-black/60`,onClick:()=>{_.isPending||v.isPending||t()}}),(0,G.jsxs)(`div`,{className:`relative w-full max-w-4xl mx-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl shadow-2xl max-h-[90vh] flex flex-col`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":w,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-4 px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,G.jsxs)(`h2`,{id:w,className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(Eu,{className:`w-5 h-5 text-bambu-green`}),r(`fileManager.tags.title`)]}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-sm mt-0.5`,children:r(`fileManager.tags.subtitle`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(Q,{onClick:b,children:[(0,G.jsx)(Fl,{className:`w-4 h-4`}),r(`fileManager.tags.add`)]}),(0,G.jsx)(`button`,{type:`button`,className:`p-1.5 text-bambu-gray hover:text-white rounded`,onClick:t,"aria-label":r(`common.close`),children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]})]}),(0,G.jsx)(`div`,{className:`overflow-y-auto`,children:h?(0,G.jsxs)(`div`,{className:`flex items-center justify-center py-16 text-bambu-gray`,children:[(0,G.jsx)(Y,{className:`w-6 h-6 animate-spin mr-2`}),r(`common.loading`)]}):m.length===0?(0,G.jsx)(`div`,{className:`py-16 text-center text-bambu-gray`,children:r(`fileManager.tags.empty`)}):(0,G.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,G.jsx)(`thead`,{children:(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary text-left text-bambu-gray`,children:[(0,G.jsx)(`th`,{className:`px-4 py-3 font-medium`,children:r(`fileManager.tags.name`)}),(0,G.jsx)(`th`,{className:`px-4 py-3 font-medium text-right`,children:r(`fileManager.tags.fileCount`)}),(0,G.jsx)(`th`,{className:`px-4 py-3 font-medium text-right w-32`,children:r(`common.actions`)})]})}),(0,G.jsx)(`tbody`,{children:m.map(e=>(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/60 hover:bg-bambu-dark-tertiary/30 ${n?`cursor-pointer`:``}`,onClick:()=>{n&&(n(e.id),t())},children:[(0,G.jsx)(`td`,{className:`px-4 py-3 text-white font-medium`,children:e.name}),(0,G.jsx)(`td`,{className:`px-4 py-3 text-right text-bambu-gray`,children:e.file_count}),(0,G.jsx)(`td`,{className:`px-4 py-3 text-right`,onClick:e=>e.stopPropagation(),children:(0,G.jsxs)(`div`,{className:`flex items-center justify-end gap-1`,children:[(0,G.jsx)(`button`,{type:`button`,className:`p-1.5 text-bambu-gray hover:text-bambu-green rounded`,onClick:()=>x(e),title:r(`common.edit`),"aria-label":r(`fileManager.tags.editAria`,{name:e.name}),children:(0,G.jsx)(Al,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{type:`button`,className:`p-1.5 text-bambu-gray hover:text-red-600 dark:hover:text-red-400 rounded`,onClick:()=>p(e),title:r(`common.delete`),"aria-label":r(`fileManager.tags.deleteAria`,{name:e.name}),children:(0,G.jsx)(Pu,{className:`w-4 h-4`})})]})})]},e.id))})]})})]}),o&&(0,G.jsxs)(`div`,{className:`fixed inset-0 z-[60] flex items-center justify-center`,children:[(0,G.jsx)(`div`,{className:`absolute inset-0 bg-black/60`,onClick:S}),(0,G.jsxs)(`div`,{className:`relative w-full max-w-md mx-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl p-6 shadow-2xl`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":T,children:[(0,G.jsx)(`h3`,{id:T,className:`text-lg font-semibold text-white mb-4`,children:r(c?`fileManager.tags.edit`:`fileManager.tags.add`)}),(0,G.jsxs)(`form`,{onSubmit:C,children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,htmlFor:`library-tag-name`,children:r(`fileManager.tags.name`)}),(0,G.jsx)(`input`,{id:`library-tag-name`,type:`text`,maxLength:64,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green mb-4`,placeholder:r(`fileManager.tags.createPlaceholder`),value:u,onChange:e=>d(e.target.value),autoFocus:!0}),(0,G.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:S,children:r(`common.cancel`)}),(0,G.jsxs)(Q,{type:`submit`,disabled:_.isPending||!u.trim(),children:[_.isPending&&(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),r(`common.save`)]})]})]})]})]}),f&&(0,G.jsx)(of,{title:r(`fileManager.tags.confirmDelete`,{name:f.name}),message:f.file_count>0?r(`fileManager.tags.confirmDeleteInUseMessage`,{count:f.file_count}):r(`fileManager.tags.confirmDeleteMessage`),confirmText:r(`common.delete`),variant:`danger`,isLoading:v.isPending,onConfirm:()=>v.mutate(f.id),onCancel:()=>p(null)})]})}var r$e=90;function i$e({onClose:e}){let{t}=U(),n=co(),{showToast:r}=qd(),[i,a]=(0,y.useState)(r$e),[o,s]=(0,y.useState)(!0),[c,l]=(0,y.useState)(i);(0,y.useEffect)(()=>{let e=window.setTimeout(()=>l(i),300);return()=>window.clearTimeout(e)},[i]);let u=K({queryKey:[`library-purge-preview`,c,o],queryFn:()=>Z.previewLibraryPurge(c,o),enabled:c>=1}),d=q({mutationFn:()=>Z.executeLibraryPurge(i,o),onSuccess:i=>{r(t(`libraryPurge.toast.success`,{count:i.moved_to_trash}),`success`),n.invalidateQueries({queryKey:[`library-files`]}),n.invalidateQueries({queryKey:[`library-folders`]}),n.invalidateQueries({queryKey:[`library-trash`]}),n.invalidateQueries({queryKey:[`library-trash-count`]}),e()},onError:e=>r(e.message||t(`libraryPurge.toast.failed`),`error`)});(0,y.useEffect)(()=>{let t=t=>{t.key===`Escape`&&!d.isPending&&e()};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e,d.isPending]);let f=u.data,p=f?.count??0,m=f?.total_bytes??0,h=p>0&&!d.isPending;return(0,G.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4`,children:(0,G.jsxs)(`div`,{className:`bg-white dark:bg-gray-900 rounded-lg shadow-xl max-w-lg w-full`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-gray-200 dark:border-gray-700`,children:[(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-gray-900 dark:text-gray-100 flex items-center gap-2`,children:[(0,G.jsx)(Pu,{className:`w-5 h-5`}),t(`libraryPurge.title`)]}),(0,G.jsx)(`button`,{onClick:e,className:`text-gray-400 hover:text-gray-600 dark:hover:text-gray-200`,"aria-label":t(`common.close`),disabled:d.isPending,children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]}),(0,G.jsxs)(`div`,{className:`p-4 space-y-4`,children:[(0,G.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400`,children:t(`libraryPurge.description`)}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{htmlFor:`purge-days`,className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:t(`libraryPurge.ageLabel`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`input`,{id:`purge-days`,type:`number`,min:1,max:3650,value:i,onChange:e=>a(Math.max(1,Math.min(3650,parseInt(e.target.value||`0`,10)||0))),className:`w-24 rounded border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-800 text-sm px-2 py-1 text-gray-900 dark:text-gray-100`}),(0,G.jsx)(`span`,{className:`text-sm text-gray-600 dark:text-gray-400`,children:t(`libraryPurge.days`)})]})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-gray-700 dark:text-gray-300`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:o,onChange:e=>s(e.target.checked),className:`rounded border-gray-300`}),t(`libraryPurge.includeNeverPrinted`)]}),(0,G.jsxs)(`div`,{className:`rounded border border-gray-200 dark:border-gray-700 bg-gray-50 dark:bg-gray-800/30 p-3`,children:[(0,G.jsx)(`div`,{className:`text-xs font-semibold uppercase tracking-wide text-gray-600 dark:text-gray-300 mb-2`,children:t(`libraryPurge.effectsTitle`)}),(0,G.jsxs)(`ul`,{className:`text-xs text-gray-700 dark:text-gray-300 space-y-1 list-disc pl-4`,children:[(0,G.jsx)(`li`,{children:t(`libraryPurge.effect1`)}),(0,G.jsx)(`li`,{children:t(`libraryPurge.effect2`)}),(0,G.jsx)(`li`,{children:t(`libraryPurge.effect3`)}),(0,G.jsx)(`li`,{children:t(`libraryPurge.effect4`)})]})]}),(0,G.jsx)(`div`,{className:`rounded border border-gray-200 dark:border-gray-700 bg-gray-50 dark:bg-gray-800/50 p-3`,children:u.isLoading||u.isFetching?(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-gray-500 dark:text-gray-400`,children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),` `,t(`libraryPurge.previewLoading`)]}):u.isError?(0,G.jsx)(`div`,{className:`text-sm text-red-600 dark:text-red-400`,children:u.error?.message??t(`libraryPurge.previewFailed`)}):(0,G.jsxs)(`div`,{className:`text-sm text-gray-900 dark:text-gray-100`,children:[(0,G.jsx)(`div`,{className:`font-medium`,children:t(`libraryPurge.previewSummary`,{count:p,size:Gd(m)})}),f?.sample_filenames&&f.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:[f.sample_filenames.map(e=>(0,G.jsx)(`li`,{className:`truncate`,children:e},e)),p>f.sample_filenames.length&&(0,G.jsx)(`li`,{className:`list-none italic text-gray-500`,children:t(`libraryPurge.andMore`,{count:p-f.sample_filenames.length})})]})]})}),(0,G.jsxs)(`div`,{className:`flex gap-2 items-start text-xs text-amber-700 dark:text-amber-400 bg-amber-50 dark:bg-amber-900/20 rounded px-3 py-2`,children:[(0,G.jsx)(Lu,{className:`w-4 h-4 mt-0.5 shrink-0`}),(0,G.jsx)(`span`,{children:t(`libraryPurge.warning`)})]})]}),(0,G.jsxs)(`div`,{className:`flex justify-end gap-2 p-4 border-t border-gray-200 dark:border-gray-700`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:e,disabled:d.isPending,children:t(`common.cancel`)}),(0,G.jsx)(Q,{variant:`danger`,disabled:!h,onClick:()=>d.mutate(),children:d.isPending?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin mr-1`}),t(`libraryPurge.purging`)]}):t(`libraryPurge.confirmCta`,{count:p})})]})]})})}function a$e({parentId:e,onClose:t,onSave:n,isLoading:r,t:i}){let[a,o]=(0,y.useState)(``);return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg w-full max-w-sm border border-bambu-dark-tertiary`,children:[(0,G.jsx)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary`,children:(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(`fileManager.newFolder`)})}),(0,G.jsxs)(`form`,{onSubmit:t=>{t.preventDefault(),n({name:a.trim(),parent_id:e})},className:`p-4 space-y-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:i(`fileManager.folderName`)}),(0,G.jsx)(`input`,{type:`text`,value:a,onChange:e=>o(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:i(`fileManager.folderNamePlaceholder`),autoFocus:!0,required:!0})]}),(0,G.jsxs)(`div`,{className:`flex justify-end gap-2 pt-2`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:t,children:i(`common.cancel`)}),(0,G.jsx)(Q,{type:`submit`,disabled:!a.trim()||r,children:r?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):i(`common.create`)})]})]})]})})}function o$e({onClose:e,onSave:t,isLoading:n,t:r}){let[i,a]=(0,y.useState)(``),[o,s]=(0,y.useState)(``),[c,l]=(0,y.useState)(!0),[u,d]=(0,y.useState)(!1);return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg w-full max-w-md border border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(bc,{className:`w-5 h-5 text-bambu-green`}),r(`fileManager.linkExternalFolder`)]}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:r(`fileManager.linkExternalFolderDescription`)})]}),(0,G.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),t({name:i.trim(),external_path:o.trim(),readonly:c,show_hidden:u})},className:`p-4 space-y-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:r(`fileManager.folderName`)}),(0,G.jsx)(`input`,{type:`text`,value:i,onChange:e=>a(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:r(`fileManager.externalFolderNamePlaceholder`),autoFocus:!0,required:!0})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:r(`fileManager.externalPath`)}),(0,G.jsx)(`input`,{type:`text`,value:o,onChange:e=>s(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green font-mono text-sm`,placeholder:`/mnt/nas/3d-prints`,required:!0}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:r(`fileManager.externalPathHelp`)})]}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:c,onChange:e=>l(e.target.checked),className:`rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,G.jsx)(`span`,{className:`text-sm text-white`,children:r(`fileManager.readOnly`)}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[`(`,r(`fileManager.readOnlyHelp`),`)`]})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:u,onChange:e=>d(e.target.checked),className:`rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,G.jsx)(`span`,{className:`text-sm text-white`,children:r(`fileManager.showHiddenFiles`)})]})]}),(0,G.jsxs)(`div`,{className:`flex justify-end gap-2 pt-2`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:e,children:r(`common.cancel`)}),(0,G.jsx)(Q,{type:`submit`,disabled:!i.trim()||!o.trim()||n,children:n?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):r(`fileManager.linkFolder`)})]})]})]})})}var s$e=`<>:"/\\|?*`;function c$e(e){for(let t of e)if(s$e.includes(t)||t.charCodeAt(0)<32)return t;return null}function l$e({type:e,currentName:t,onClose:n,onSave:r,isLoading:i,t:a}){let o=e===`file`?t.match(/(\.gcode\.3mf|\.3mf|\.gcode)$/i)?.[1]??``:``,s=e===`file`&&o?t.slice(0,-o.length):t,[c,l]=(0,y.useState)(s),u=e===`file`?c$e(c):null,d=u?a(`fileManager.invalidFilenameChar`,{char:u}):null;return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg w-full max-w-sm border border-bambu-dark-tertiary`,children:[(0,G.jsx)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary`,children:(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:a(e===`file`?`fileManager.renameFile`:`fileManager.renameFolder`)})}),(0,G.jsxs)(`form`,{onSubmit:n=>{if(n.preventDefault(),d)return;let i=e===`file`?c.trim()+o:c.trim();c.trim()&&i!==t&&r(i)},className:`p-4 space-y-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`common.name`)}),(0,G.jsxs)(`div`,{className:`flex items-center bg-bambu-dark border rounded focus-within:border-bambu-green ${d?`border-red-500`:`border-bambu-dark-tertiary`}`,children:[(0,G.jsx)(`input`,{type:`text`,value:c,onChange:e=>l(e.target.value),className:`flex-1 bg-transparent px-3 py-2 text-white placeholder-bambu-gray focus:outline-none min-w-0`,autoFocus:!0,required:!0}),o&&(0,G.jsx)(`span`,{className:`pr-3 text-bambu-gray text-sm select-none whitespace-nowrap`,children:o})]}),d&&(0,G.jsx)(`p`,{className:`mt-1 text-xs text-red-700 dark:text-red-400`,children:d})]}),(0,G.jsxs)(`div`,{className:`flex justify-end gap-2 pt-2`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:n,children:a(`common.cancel`)}),(0,G.jsx)(Q,{type:`submit`,disabled:!c.trim()||c.trim()===s||!!d||i,children:i?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):a(`common.rename`)})]})]})]})})}function u$e({folders:e,selectedFiles:t,currentFolderId:n,onClose:r,onMove:i,isLoading:a,t:o}){let[s,c]=(0,y.useState)(null),l=(e,t=0)=>{let n=[];for(let r of e)n.push({id:r.id,name:r.name,depth:t}),r.children.length>0&&n.push(...l(r.children,t+1));return n},u=[{id:null,name:o(`fileManager.rootNoFolder`),depth:0},...l(e)];return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg w-full max-w-sm border border-bambu-dark-tertiary`,children:[(0,G.jsx)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary`,children:(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:o(`fileManager.moveFiles`,{count:t.length})})}),(0,G.jsxs)(`div`,{className:`p-4 space-y-4`,children:[(0,G.jsx)(`div`,{className:`max-h-64 overflow-y-auto space-y-1`,children:u.map(e=>(0,G.jsxs)(`button`,{onClick:()=>c(e.id),disabled:e.id===n,className:`w-full text-left px-3 py-2 rounded transition-colors flex items-center gap-2 ${s===e.id?`bg-bambu-green/20 text-bambu-green`:e.id===n?`opacity-50 cursor-not-allowed text-bambu-gray`:`hover:bg-bambu-dark text-white`}`,style:{paddingLeft:`${12+e.depth*16}px`},children:[(0,G.jsx)(vc,{className:`w-4 h-4`}),e.name,e.id===n&&(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray ml-auto`,children:[`(`,o(`fileManager.current`),`)`]})]},e.id??`root`))}),(0,G.jsxs)(`div`,{className:`flex justify-end gap-2 pt-2`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:r,children:o(`common.cancel`)}),(0,G.jsx)(Q,{onClick:()=>i(s),disabled:a,children:a?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):o(`common.move`)})]})]})]})})}function d$e({folder:e,onClose:t,onLink:n,isLoading:r,t:i}){let[a,o]=(0,y.useState)(`project`),[s,c]=(0,y.useState)(e.project_id||e.archive_id||null);(0,y.useState)(()=>{e.archive_id&&o(`archive`)});let{data:l}=K({queryKey:[`projects`],queryFn:()=>Z.getProjects(),select:t=>JW([...t].sort((e,t)=>e.name.localeCompare(t.name)),e.project_id)}),{data:u}=K({queryKey:[`archives-for-link`],queryFn:()=>Z.getArchives(void 0,void 0,100)}),d=()=>{n(a===`project`?{project_id:s,archive_id:0}:{project_id:0,archive_id:s})},f=()=>{n({project_id:0,archive_id:0})},p=e.project_id||e.archive_id;return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg w-full max-w-md border border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary flex items-center justify-between`,children:[(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(Xc,{className:`w-5 h-5 text-bambu-green`}),i(`fileManager.linkFolder`)]}),(0,G.jsx)(`button`,{onClick:t,className:`p-1 hover:bg-bambu-dark rounded`,children:(0,G.jsx)(nd,{className:`w-5 h-5 text-bambu-gray`})})]}),(0,G.jsxs)(`div`,{className:`p-4 space-y-4`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`fileManager.linkFolderDescription`,{name:e.name})}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsxs)(`button`,{onClick:()=>{o(`project`),c(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg border transition-colors ${a===`project`?`border-bambu-green bg-bambu-green/10 text-bambu-green`:`border-bambu-dark-tertiary text-bambu-gray hover:text-white`}`,children:[(0,G.jsx)(Qo,{className:`w-4 h-4`}),i(`fileManager.project`)]}),(0,G.jsxs)(`button`,{onClick:()=>{o(`archive`),c(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg border transition-colors ${a===`archive`?`border-bambu-green bg-bambu-green/10 text-bambu-green`:`border-bambu-dark-tertiary text-bambu-gray hover:text-white`}`,children:[(0,G.jsx)(Po,{className:`w-4 h-4`}),i(`fileManager.archive`)]})]}),(0,G.jsx)(`div`,{className:`max-h-64 overflow-y-auto space-y-1 bg-bambu-dark rounded-lg p-2`,children:a===`project`?l&&l.length>0?l.map(e=>(0,G.jsxs)(`button`,{onClick:()=>c(e.id),className:`w-full text-left px-3 py-2 rounded transition-colors flex items-center gap-2 ${s===e.id?`bg-bambu-green/20 text-bambu-green`:`hover:bg-bambu-dark-tertiary text-white`}`,children:[(0,G.jsx)(`div`,{className:`w-3 h-3 rounded-full flex-shrink-0`,style:{backgroundColor:e.color||`#00ae42`}}),(0,G.jsx)(`span`,{className:`truncate`,children:e.name})]},e.id)):(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray text-center py-4`,children:i(`fileManager.noProjectsFound`)}):u&&u.length>0?u.map(e=>(0,G.jsxs)(`button`,{onClick:()=>c(e.id),className:`w-full text-left px-3 py-2 rounded transition-colors flex items-center gap-2 ${s===e.id?`bg-bambu-green/20 text-bambu-green`:`hover:bg-bambu-dark-tertiary text-white`}`,children:[(0,G.jsx)(sc,{className:`w-4 h-4 text-bambu-gray flex-shrink-0`}),(0,G.jsx)(`span`,{className:`truncate`,children:e.print_name||e.filename})]},e.id)):(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray text-center py-4`,children:i(`fileManager.noArchivesFound`)})})]}),(0,G.jsxs)(`div`,{className:`p-4 border-t border-bambu-dark-tertiary flex justify-between`,children:[p&&(0,G.jsxs)(Q,{variant:`danger`,onClick:f,disabled:r,children:[(0,G.jsx)(Bu,{className:`w-4 h-4 mr-2`}),i(`fileManager.unlink`)]}),(0,G.jsxs)(`div`,{className:`flex gap-2 ${p?``:`ml-auto`}`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:t,children:i(`common.cancel`)}),(0,G.jsx)(Q,{onClick:d,disabled:!s||r,children:r?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):i(`fileManager.link`)})]})]})]})})}function f$e({folder:e,selectedFolderId:t,onSelect:n,onDelete:r,onLink:i,onRename:a,depth:o=0,wrapNames:s=!1,defaultExpanded:c=!0,showModified:l=!1,hasPermission:u,t:d}){let[f,p]=(0,y.useState)(c),[m,h]=(0,y.useState)(!1),g=e.children.length>0,_=e.project_id||e.archive_id,v=e.is_external,b=u(`library:delete_all`)||u(`library:delete_own`)&&e.file_count===0&&!g&&!v&&!_,x=b?void 0:u(`library:delete_own`)&&!v&&!_?d(`fileManager.onlyEmptyFoldersDeletable`):d(`fileManager.noPermissionDeleteFolder`);return(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`group flex items-center gap-1 px-2 py-1.5 rounded cursor-pointer transition-colors ${t===e.id?`bg-bambu-green/20 text-bambu-green`:`hover:bg-bambu-dark text-white`}`,style:{paddingLeft:`${8+o*12}px`},onClick:()=>n(e.id),children:[g?(0,G.jsx)(`button`,{onClick:e=>{e.stopPropagation(),p(!f)},className:`p-0.5 hover:bg-bambu-dark-tertiary rounded`,children:(0,G.jsx)(ms,{className:`w-3.5 h-3.5 transition-transform ${f?`rotate-90`:``}`})}):(0,G.jsx)(`div`,{className:`w-4.5`}),v?(0,G.jsx)(bc,{className:`w-4 h-4 text-purple-600 dark:text-purple-400 flex-shrink-0`}):(0,G.jsx)(vc,{className:`w-4 h-4 text-bambu-green flex-shrink-0`}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`span`,{className:`block text-sm ${s?`break-all`:`truncate`}`,title:e.name,children:e.name}),l&&e.latest_activity_at&&(0,G.jsxs)(`span`,{className:`mt-0.5 flex items-center gap-1 text-xs text-bambu-gray`,title:d(`fileManager.lastActivity`),children:[(0,G.jsx)(rs,{className:`w-3 h-3 flex-shrink-0`}),(0,G.jsx)(`span`,{className:`truncate`,children:ip(e.latest_activity_at)})]})]}),_&&(0,G.jsxs)(`button`,{onClick:t=>{t.stopPropagation(),i(e)},className:`flex-shrink-0 flex items-center gap-1 text-xs px-1.5 py-0.5 rounded bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400 hover:bg-blue-200 dark:hover:bg-blue-500/30 transition-colors`,title:`${e.project_name?`Project: ${e.project_name}`:`Archive: ${e.archive_name}`} (click to change)`,children:[(0,G.jsx)(Xc,{className:`w-3 h-3`}),e.project_name?(0,G.jsx)(Qo,{className:`w-3 h-3`}):(0,G.jsx)(Po,{className:`w-3 h-3`})]}),v&&e.external_readonly&&(0,G.jsx)(`span`,{title:d(`fileManager.readOnly`),children:(0,G.jsx)(nl,{className:`w-3 h-3 text-amber-600 dark:text-amber-400 flex-shrink-0`})}),e.file_count>0&&(0,G.jsx)(`span`,{className:`flex-shrink-0 text-xs text-bambu-gray`,children:e.file_count}),!_&&!v&&(0,G.jsx)(`button`,{onClick:t=>{t.stopPropagation(),i(e)},className:`flex-shrink-0 p-1 rounded hover:bg-bambu-dark-tertiary`,title:d(`fileManager.linkToProjectOrArchive`),children:(0,G.jsx)(Xc,{className:`w-3.5 h-3.5 text-bambu-gray hover:text-bambu-green`})}),(0,G.jsx)(`div`,{className:`flex-shrink-0 flex items-center gap-0.5 transition-opacity ${s?``:`can-hover:opacity-0 group-hover:opacity-100 group-focus-within:opacity-100`}`,onClick:e=>e.stopPropagation(),children:(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(`button`,{onClick:()=>h(!m),className:`p-1 rounded hover:bg-bambu-dark-tertiary`,children:(0,G.jsx)($s,{className:`w-3.5 h-3.5 text-bambu-gray`})}),m&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`fixed inset-0 z-10`,onClick:()=>h(!1)}),(0,G.jsxs)(`div`,{className:`absolute right-0 top-full mt-1 z-20 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl py-1 min-w-[120px]`,children:[(0,G.jsxs)(`button`,{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${u(`library:update_all`)?`text-white hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{u(`library:update_all`)&&(a(e),h(!1))},disabled:!u(`library:update_all`),title:u(`library:update_all`)?void 0:d(`fileManager.noPermissionRenameFolder`),children:[(0,G.jsx)(Al,{className:`w-3.5 h-3.5`}),d(`common.rename`)]}),(0,G.jsxs)(`button`,{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${u(`library:update_all`)?`text-white hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{u(`library:update_all`)&&(i(e),h(!1))},disabled:!u(`library:update_all`),title:u(`library:update_all`)?void 0:d(`fileManager.noPermissionLinkFolder`),children:[(0,G.jsx)(Xc,{className:`w-3.5 h-3.5`}),d(_?`fileManager.changeLink`:`fileManager.linkTo`)]}),(0,G.jsxs)(`button`,{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${b?`text-red-700 dark:text-red-400 hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{b&&(r(e.id),h(!1))},disabled:!b,title:x,children:[(0,G.jsx)(Pu,{className:`w-3.5 h-3.5`}),d(`common.delete`)]})]})]})]})})]}),g&&f&&(0,G.jsx)(`div`,{children:e.children.map(e=>(0,G.jsx)(f$e,{folder:e,selectedFolderId:t,onSelect:n,onDelete:r,onLink:i,onRename:a,depth:o+1,wrapNames:s,defaultExpanded:c,showModified:l,hasPermission:u,t:d},e.id))})]})}function p$e({file:e,isSelected:t,onSelect:n,onDelete:r,onDownload:i,onPrint:a,onSlice:o,onOpenInSlicer:s,onRunPipeline:c,useSlicerApi:l,desktopSlicer:u,canSlice:d,onPreview3d:f,onRename:p,onGenerateThumbnail:m,onTagClick:h,thumbnailVersion:g,hasPermission:_,canModify:v,authEnabled:b,showModified:x,t:S}){let[C,w]=(0,y.useState)(null),T=_(`library:read`),E=v(`library`,`update`,e.created_by_id),D=v(`library`,`delete`,e.created_by_id),O=[];return a&&M5(e)&&O.push({label:S(`common.print`),icon:(0,G.jsx)(Rl,{className:`w-4 h-4 text-bambu-green`}),onClick:()=>a(e),disabled:!_(`queue:create`),title:_(`queue:create`)?void 0:S(`fileManager.noPermissionAddToQueue`)}),N5(e,!!l,u)&&(l?o:s)&&O.push({label:S(`slice.action`),icon:l?(0,G.jsx)(Rs,{className:`w-4 h-4`}):(0,G.jsx)(rc,{className:`w-4 h-4`}),onClick:()=>{l?o?.(e):s?.(e)},disabled:!d,title:d?void 0:S(l?`fileManager.noPermissionSlice`:`fileManager.noPermissionDownload`)}),c&&l&&N5(e,!0,u)&&O.push({label:S(`library.runWithPipeline.actionLabel`),icon:(0,G.jsx)(Nl,{className:`w-4 h-4`}),onClick:()=>c(e),disabled:!_(`pipelines:run`),title:_(`pipelines:run`)?void 0:S(`library.runWithPipeline.noPermission`)}),f&&(e.file_type===`3mf`||e.file_type===`gcode`||e.file_type===`stl`||e.file_type===`gcode.3mf`)&&O.push({label:S(`fileManager.preview3d`),icon:(0,G.jsx)(Zo,{className:`w-4 h-4`}),onClick:()=>f(e),disabled:!T,title:T?void 0:S(`fileManager.noPermissionPreview`)}),O.push({label:S(`common.download`),icon:(0,G.jsx)(Xs,{className:`w-4 h-4`}),onClick:()=>i(e.id),disabled:!_(`library:read`),title:_(`library:read`)?void 0:S(`fileManager.noPermissionDownload`)}),p&&O.push({label:S(`common.rename`),icon:(0,G.jsx)(Al,{className:`w-4 h-4`}),onClick:()=>p(e),disabled:!E,title:E?void 0:S(`fileManager.noPermissionRenameFile`)}),m&&e.file_type===`stl`&&O.push({label:S(`fileManager.generateThumbnail`),icon:(0,G.jsx)(Hc,{className:`w-4 h-4`}),onClick:()=>m(e),disabled:!E,title:E?void 0:S(`fileManager.noPermissionGenerateThumbnail`)}),O.push({label:S(`common.delete`),icon:(0,G.jsx)(Pu,{className:`w-4 h-4`}),onClick:()=>r(e.id),danger:!0,disabled:!D,title:D?void 0:S(`fileManager.noPermissionDeleteFile`)}),(0,G.jsxs)(`div`,{className:`group relative bg-bambu-dark-secondary rounded-lg border transition-all cursor-pointer ${t?`border-bambu-green ring-1 ring-bambu-green`:`border-bambu-dark-tertiary hover:border-bambu-green/50`}`,onClick:()=>n(e.id),children:[(0,G.jsxs)(`div`,{className:`aspect-square bg-bambu-dark flex items-center justify-center overflow-hidden rounded-t-lg`,children:[e.thumbnail_path?(0,G.jsx)(`img`,{src:`${Z.getLibraryFileThumbnailUrl(e.id)}${g?(Z.getLibraryFileThumbnailUrl(e.id).includes(`?`)?`&`:`?`)+`v=${g}`:``}`,alt:e.filename,className:`w-full h-full object-cover`}):(0,G.jsx)(sc,{className:`w-12 h-12 text-bambu-gray/30`}),(0,G.jsx)(`div`,{className:`absolute top-2 right-2 text-xs px-1.5 py-0.5 rounded font-medium ${e.file_type===`3mf`?`bg-bambu-green/90 text-white`:e.file_type===`gcode`||e.file_type===`gcode.3mf`?`bg-blue-500/90 text-white`:e.file_type===`stl`?`bg-purple-500/90 text-white`:`bg-bambu-gray/90 text-white`}`,children:e.file_type.toUpperCase()})]}),(0,G.jsxs)(`div`,{className:`p-3`,children:[(0,G.jsx)(`h3`,{className:`text-sm font-medium text-white truncate`,title:e.print_name||e.filename,children:e.print_name||e.filename}),(0,G.jsxs)(`div`,{className:`flex items-center gap-3 mt-1 text-xs text-bambu-gray`,children:[(0,G.jsx)(`span`,{children:Gd(e.file_size)}),e.print_time_seconds&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(js,{className:`w-3 h-3`}),lp(e.print_time_seconds)]})]}),e.sliced_for_model&&(0,G.jsxs)(`div`,{className:`mt-1 text-xs text-bambu-gray flex items-center gap-1`,children:[(0,G.jsx)(Rl,{className:`w-3 h-3`}),e.sliced_for_model]}),(e.variant_count??0)>1&&(0,G.jsxs)(`div`,{className:`mt-1 text-xs text-bambu-green flex items-center gap-1`,children:[(0,G.jsx)(Jc,{className:`w-3 h-3`}),S(`fileManager.variants.badge`,{count:e.variant_count})]}),e.print_count>0&&(0,G.jsx)(`div`,{className:`mt-1 text-xs text-bambu-green`,children:S(`fileManager.printedCount`,{count:e.print_count})}),b&&e.created_by_username&&(0,G.jsxs)(`div`,{className:`mt-1 text-xs text-bambu-gray flex items-center gap-1`,children:[(0,G.jsx)(Hu,{className:`w-3 h-3`}),e.created_by_username]}),x&&(0,G.jsxs)(`div`,{className:`mt-1 text-xs text-bambu-gray flex items-center gap-1`,title:S(`fileManager.lastModified`),children:[(0,G.jsx)(rs,{className:`w-3 h-3`}),ip(e.fs_modified_at??e.created_at)]}),(e.tags?.length??0)>0&&(0,G.jsx)(`div`,{className:`mt-2 flex flex-wrap gap-1`,onClick:e=>e.stopPropagation(),children:e.tags.map(e=>(0,G.jsxs)(`button`,{type:`button`,onClick:()=>h?.(e.id),className:`inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded-full text-[10px] bg-bambu-green/10 text-bambu-green hover:bg-bambu-green/20 transition-colors max-w-full`,title:e.name,children:[(0,G.jsx)(Eu,{className:`w-2.5 h-2.5 flex-shrink-0`}),(0,G.jsx)(`span`,{className:`truncate`,children:e.name})]},e.id))})]}),(0,G.jsxs)(`div`,{className:`absolute bottom-2 right-2 transition-opacity can-hover:opacity-0 group-hover:opacity-100 group-focus-within:opacity-100`,onClick:e=>e.stopPropagation(),children:[(0,G.jsx)(`button`,{onClick:e=>{let t=e.currentTarget.getBoundingClientRect();w({x:t.left,y:t.bottom+4})},className:`p-1.5 rounded bg-bambu-dark-secondary/90 hover:bg-bambu-dark-tertiary`,children:(0,G.jsx)($s,{className:`w-4 h-4 text-bambu-gray`})}),C&&(0,G.jsx)(kT,{x:C.x,y:C.y,items:O,onClose:()=>w(null)})]}),(0,G.jsx)(`div`,{className:`absolute top-2 left-2 w-5 h-5 rounded border-2 flex items-center justify-center transition-all ${t?`bg-bambu-green border-bambu-green`:`border-white/30 bg-black/30 can-hover:opacity-0 group-hover:opacity-100 group-focus-within:opacity-100`}`,children:t&&(0,G.jsx)(`div`,{className:`w-2 h-2 bg-white rounded-sm`})})]})}function m$e(){let{t:e}=U(),t=co(),{showToast:n}=qd(),{hasPermission:r,hasAnyPermission:i,canModify:a,authEnabled:o}=Nd(),[s]=Ri(),c=or(),l=s.get(`folder`),[u,d]=(0,y.useState)(l?parseInt(l,10):null),[f,p]=(0,y.useState)(`internal`),[m,h]=(0,y.useState)([]),[g,_]=(0,y.useState)(!1),[v,b]=(0,y.useState)(!1),[x,S]=(0,y.useState)(!1),[C,w]=(0,y.useState)(!1),[T,E]=(0,y.useState)([]),[D,O]=(0,y.useState)(!1),[k,A]=(0,y.useState)(!1),[j,M]=(0,y.useState)(!1),[N,P]=(0,y.useState)([]),[F,I]=(0,y.useState)(null),[L,R]=(0,y.useState)(null),[z,B]=(0,y.useState)(null),[V,ee]=(0,y.useState)(null),[te,ne]=(0,y.useState)(null),[re,ie]=(0,y.useState)(null),[ae,oe]=(0,y.useState)({}),[se,H]=(0,y.useState)(null),[ce,le]=(0,y.useState)(()=>localStorage.getItem(`library-view-mode`)||`grid`),[ue,de]=(0,y.useState)(()=>localStorage.getItem(`library-wrap-folders`)===`true`),[fe,pe]=(0,y.useState)(()=>localStorage.getItem(`library-collapse-folders`)===`true`),[me,he]=(0,y.useState)(()=>localStorage.getItem(`library-folder-sort-field`)===`activity`?`activity`:`name`),[ge,_e]=(0,y.useState)(()=>localStorage.getItem(`library-folder-sort-direction`)===`desc`?`desc`:`asc`),[ve,ye]=(0,y.useState)(()=>{let e=localStorage.getItem(`library-sidebar-width`);return e?parseInt(e,10):256}),[be,xe]=(0,y.useState)(!1),Se=(0,y.useRef)(null);(0,y.useEffect)(()=>{if(!be)return;document.body.style.userSelect=`none`,document.body.style.cursor=`col-resize`;let e=e=>{if(!Se.current)return;let t=Se.current.parentElement?.getBoundingClientRect();if(!t)return;let n=e.clientX-t.left;ye(Math.min(500,Math.max(200,n)))},t=()=>{xe(!1),document.body.style.userSelect=``,document.body.style.cursor=``,localStorage.setItem(`library-sidebar-width`,String(ve))};return document.addEventListener(`mousemove`,e),document.addEventListener(`mouseup`,t),()=>{document.removeEventListener(`mousemove`,e),document.removeEventListener(`mouseup`,t),document.body.style.userSelect=``,document.body.style.cursor=``}},[be,ve]);let[Ce,we]=(0,y.useState)(``),[Te,Ee]=(0,y.useState)(`all`),[De,Oe]=(0,y.useState)(``),[ke,Ae]=(0,y.useState)(()=>localStorage.getItem(`library-sort-field`)||`name`),[je,Me]=(0,y.useState)(()=>localStorage.getItem(`library-sort-direction`)||`asc`),[Ne,Pe]=(0,y.useState)(()=>localStorage.getItem(`library-show-modified`)===`true`);(0,y.useEffect)(()=>{let e=s.get(`folder`);e&&d(parseInt(e,10))},[s]);let{data:Fe}=K({queryKey:[`settings`],queryFn:()=>Z.getSettings()}),Ie=HW(Fe?.open_in_slicer,Fe?.preferred_slicer),Le=(0,y.useCallback)(async t=>{try{let{token:e}=await Z.createLibrarySlicerToken(t.id),n=Z.getLibrarySlicerDownloadUrl(t.id,e,t.filename);KW(`${window.location.origin}${n}`,Ie)}catch{n(e(`fileManager.toast.openInSlicerFailed`),`error`);let r=Z.getLibraryFileDownloadUrl(t.id);KW(`${window.location.origin}${r}`,Ie)}},[Ie,n,e]),Re=(0,y.useCallback)(()=>Fe?.use_slicer_api?r(`library:upload`):i(`library:read_all`,`library:read_own`),[Fe?.use_slicer_api,r,i]),{data:ze,isLoading:Be}=K({queryKey:[`library-folders`],queryFn:()=>Z.getLibraryFolders()}),Ve=(0,y.useMemo)(()=>{if(!ze)return ze;let e=t=>[...t].sort((e,t)=>{let n=0;if(me===`name`)n=e.name.localeCompare(t.name);else{let r=e.latest_activity_at?new Date(e.latest_activity_at).getTime():null,i=t.latest_activity_at?new Date(t.latest_activity_at).getTime():null;if(r===null&&i===null)n=e.name.localeCompare(t.name);else if(r===null)return 1;else if(i===null)return-1;else n=r-i}return ge===`asc`?n:-n}).map(t=>({...t,children:e(t.children)}));return e(ze)},[ze,me,ge]),{data:He}=K({queryKey:[`library-trash-count`],queryFn:async()=>{try{return(await Z.listLibraryTrash(1,0)).total}catch{return 0}},staleTime:3e4}),Ue=u!==null&&Ce.trim().length>0,We=(0,y.useMemo)(()=>[...N].sort((e,t)=>e-t),[N]),{data:Ge=[]}=K({queryKey:[`library-tags`],queryFn:Z.getLibraryTags}),Ke=(0,y.useMemo)(()=>{let e=new Map;for(let t of Ge)e.set(t.id,t.name);return e},[Ge]);(0,y.useEffect)(()=>{Ge.length!==0&&P(e=>{let t=e.filter(e=>Ke.has(e));return t.length===e.length?e:t})},[Ge.length,Ke]);let qe=(0,y.useCallback)(e=>{P(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},[]),{data:Je,isLoading:Ye}=K({queryKey:[`library-files`,u,f,Ue,We],queryFn:()=>Z.getLibraryFiles(u,!1,void 0,u===null?f:void 0,Ue,We)}),{data:Xe}=K({queryKey:[`library-stats`],queryFn:()=>Z.getLibraryStats()}),{data:Ze}=K({queryKey:[`users`,`slim`],queryFn:()=>Z.getUsersSlim()}),Qe=(0,y.useMemo)(()=>{if(!Je)return[];let e=new Set(Je.map(e=>e.file_type));return Array.from(e).sort()},[Je]),$e=(0,y.useMemo)(()=>{if(!Je)return[];let e=[...Je];if(Ce.trim()){let t=Ce.toLowerCase();e=e.filter(e=>e.filename.toLowerCase().includes(t)||e.print_name&&e.print_name.toLowerCase().includes(t))}if(Te!==`all`&&(e=e.filter(e=>e.file_type===Te)),De.trim()){let t=De.toLowerCase();e=e.filter(e=>e.created_by_username&&e.created_by_username.toLowerCase().includes(t))}return e.sort((e,t)=>{let n=0;switch(ke){case`name`:n=(e.print_name||e.filename).localeCompare(t.print_name||t.filename);break;case`date`:n=(rp(e.fs_modified_at??e.created_at)?.getTime()??0)-(rp(t.fs_modified_at??t.created_at)?.getTime()??0);break;case`size`:n=e.file_size-t.file_size;break;case`type`:n=e.file_type.localeCompare(t.file_type);break;case`prints`:n=e.print_count-t.print_count;break}return je===`asc`?n:-n}),e},[Je,Ce,Te,De,ke,je]),et=(0,y.useMemo)(()=>{if(!Xe||!Fe)return!1;let e=(Fe.library_disk_warning_gb||5)*1024*1024*1024;return Xe.disk_free_bytesZ.createLibraryFolder(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`library-folders`]}),_(!1),n(e(`fileManager.toast.folderCreated`),`success`)},onError:e=>n(e.message,`error`)}),nt=q({mutationFn:async e=>{let t=await Z.createExternalFolder(e);return await Z.scanExternalFolder(t.id),t},onSuccess:r=>{t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`library-stats`]}),b(!1),d(r.id),n(e(`fileManager.toast.externalFolderLinked`),`success`)},onError:e=>n(e.message,`error`)}),rt=q({mutationFn:e=>Z.scanExternalFolder(e),onSuccess:r=>{t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`library-stats`]}),n(e(`fileManager.toast.folderScanned`,{added:r.added,removed:r.removed}),`success`)},onError:e=>n(e.message,`error`)}),it=q({mutationFn:e=>Z.deleteLibraryFolder(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`library-stats`]}),u===L?.id&&d(null),R(null),n(e(`fileManager.toast.folderDeleted`),`success`)},onError:e=>{R(null),n(e.message,`error`)}}),at=q({mutationFn:e=>Z.deleteLibraryFile(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`library-stats`]}),t.invalidateQueries({queryKey:[`library-trash-count`]}),h(e=>e.filter(e=>e!==L?.id)),R(null),n(e(`fileManager.toast.fileDeleted`),`success`)},onError:e=>{R(null),n(e.message,`error`)}}),ot=q({mutationFn:e=>Z.createVariantGroup(e.map(e=>({library_file_id:e}))),onSuccess:r=>{t.invalidateQueries({queryKey:[`library-files`]}),n(e(`fileManager.variants.grouped`,{count:r.members.length}),`success`),h([])},onError:e=>n(e.message,`error`)}),st=q({mutationFn:e=>Z.bulkDeleteLibrary(e,[]),onSuccess:(r,i)=>{t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`library-stats`]}),t.invalidateQueries({queryKey:[`library-trash-count`]}),n(e(`fileManager.toast.filesDeleted`,{count:i.length}),`success`),h([]),R(null)},onError:e=>{R(null),n(e.message,`error`)}}),ct=q({mutationFn:({fileIds:e,folderId:t})=>Z.moveLibraryFiles(e,t),onSuccess:()=>{t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`library-folders`]}),h([]),S(!1),n(e(`fileManager.toast.filesMoved`),`success`)},onError:e=>n(e.message,`error`)}),lt=q({mutationFn:({id:e,data:t})=>Z.updateLibraryFolder(e,t),onSuccess:(r,i)=>{t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`project-folders`]}),t.invalidateQueries({queryKey:[`archive-folders`]}),I(null),n(i.data.project_id===0&&i.data.archive_id===0?e(`fileManager.toast.folderUnlinked`):e(`fileManager.toast.folderLinked`),`success`)},onError:e=>n(e.message,`error`)}),ut=q({mutationFn:({id:e,filename:t})=>Z.updateLibraryFile(e,{filename:t}),onSuccess:()=>{t.invalidateQueries({queryKey:[`library-files`]}),ie(null),n(e(`fileManager.toast.fileRenamed`),`success`)},onError:e=>{ie(null),n(e.message,`error`)}}),dt=q({mutationFn:({id:e,name:t})=>Z.updateLibraryFolder(e,{name:t}),onSuccess:()=>{t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`library-files`]}),ie(null),n(e(`fileManager.toast.folderRenamed`),`success`)},onError:e=>{ie(null),n(e.message,`error`)}}),ft=q({mutationFn:()=>Z.batchGenerateStlThumbnails({all_missing:!0}),onSuccess:r=>{if(t.invalidateQueries({queryKey:[`library-files`]}),r.succeeded>0){let e=Date.now(),t={};r.results.forEach(n=>{n.success&&(t[n.file_id]=e)}),oe(e=>({...e,...t}))}r.succeeded>0&&r.failed===0?n(e(`fileManager.toast.thumbnailsGenerated`,{count:r.succeeded}),`success`):r.succeeded>0&&r.failed>0?n(e(`fileManager.toast.thumbnailsGeneratedPartial`,{succeeded:r.succeeded,failed:r.failed}),`success`):r.processed===0?n(e(`fileManager.toast.noStlMissingThumbnails`),`info`):n(e(`fileManager.toast.failedToGenerateThumbnails`,{error:r.results[0]?.error||`Unknown error`}),`error`)},onError:e=>n(e.message,`error`)}),pt=q({mutationFn:e=>Z.batchGenerateStlThumbnails({file_ids:[e]}),onSuccess:r=>{if(t.invalidateQueries({queryKey:[`library-files`]}),r.succeeded>0){let t=r.results[0]?.file_id;t&&oe(e=>({...e,[t]:Date.now()})),n(e(`fileManager.toast.thumbnailGenerated`),`success`)}else n(e(`fileManager.toast.failedToGenerateThumbnail`,{error:r.results[0]?.error||`Unknown error`}),`error`)},onError:e=>n(e.message,`error`)}),mt=(0,y.useMemo)(()=>Je?Je.filter(e=>m.includes(e.id)&&M5(e)):[],[Je,m]),{data:ht}=K({queryKey:[`variant-group`,z?.variant_group_id],queryFn:()=>Z.getVariantGroup(z.variant_group_id),enabled:!!z?.variant_group_id}),gt=(0,y.useMemo)(()=>{if(z){if(mt.length>1)return mt.map(e=>({id:e.id,filename:e.filename,sliced_for_model:e.sliced_for_model}));if(ht&&ht.members.length>1)return ht.members.map(e=>({id:e.library_file_id,filename:e.filename,sliced_for_model:e.target_model}))}},[z,mt,ht]),_t=(0,y.useCallback)(e=>{h(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},[]),vt=(0,y.useCallback)(()=>{$e.length>0&&h($e.map(e=>e.id))},[$e]),yt=(0,y.useCallback)(()=>{h([])},[]),bt=()=>{t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`library-stats`]})},{isDraggingOver:xt,dragHandlers:St}=YW({disabled:!r(`library:upload`)||C,onFiles:e=>{E(e),w(!0)}}),Ct=e=>{Z.downloadLibraryFile(e).catch(e=>{console.error(`Library file download failed:`,e)})},wt=()=>{L&&(L.type===`file`?at.mutate(L.id):L.type===`folder`?it.mutate(L.id):L.type===`bulk`&&st.mutate(m))},Tt=it.isPending||at.isPending||st.isPending,Et=e=>{le(e),localStorage.setItem(`library-view-mode`,e)},Dt=Be||Ye,Ot=(0,y.useMemo)(()=>{if(!u||!ze)return null;let e=t=>{for(let n of t){if(n.id===u)return n;let t=e(n.children);if(t)return t}return null};return e(ze)},[u,ze]);return(0,G.jsxs)(`div`,{className:`p-4 md:p-8 min-h-[calc(100vh-64px)] lg:h-[calc(100vh-64px)] flex flex-col relative`,...St,children:[xt&&(0,G.jsx)(`div`,{className:`fixed inset-0 z-50 bg-bambu-dark/90 flex items-center justify-center pointer-events-none`,children:(0,G.jsxs)(`div`,{className:`border-4 border-dashed border-bambu-green rounded-xl p-12 text-center`,children:[(0,G.jsx)(Vu,{className:`w-16 h-16 mx-auto mb-4 text-bambu-green`}),(0,G.jsx)(`p`,{className:`text-2xl font-semibold text-white mb-2`,children:e(`fileManager.dropFilesHere`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray`,children:e(`fileManager.releaseToUpload`)})]})}),(0,G.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between gap-4 mb-6`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,G.jsx)(vc,{className:`w-7 h-7 text-bambu-green`}),e(`fileManager.title`)]}),(0,G.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:e(`fileManager.subtitle`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center bg-bambu-dark rounded-lg p-1`,children:[(0,G.jsx)(`button`,{onClick:()=>Et(`grid`),className:`p-1.5 rounded transition-colors ${ce===`grid`?`bg-bambu-dark-secondary text-white`:`text-bambu-gray hover:text-white`}`,title:e(`fileManager.gridView`),children:(0,G.jsx)(Yc,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:()=>Et(`list`),className:`p-1.5 rounded transition-colors ${ce===`list`?`bg-bambu-dark-secondary text-white`:`text-bambu-gray hover:text-white`}`,title:e(`fileManager.listView`),children:(0,G.jsx)(el,{className:`w-4 h-4`})})]}),(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>ft.mutate(),disabled:ft.isPending||!i(`library:update_own`,`library:update_all`),title:i(`library:update_own`,`library:update_all`)?e(`fileManager.generateThumbnailsForMissing`):e(`fileManager.noPermissionGenerateThumbnail`),children:[ft.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 mr-2 animate-spin`}):(0,G.jsx)(Hc,{className:`w-4 h-4 mr-2`}),e(`fileManager.generateThumbnails`)]}),(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>b(!0),disabled:!r(`library:upload`),title:r(`library:upload`)?e(`fileManager.linkExternalFolder`):e(`fileManager.noPermissionCreateFolder`),children:[(0,G.jsx)(bc,{className:`w-4 h-4 mr-2`}),e(`fileManager.linkExternal`)]}),(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>_(!0),disabled:!r(`library:upload`),title:r(`library:upload`)?void 0:e(`fileManager.noPermissionCreateFolder`),children:[(0,G.jsx)(yc,{className:`w-4 h-4 mr-2`}),e(`fileManager.newFolder`)]}),(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>A(!0),title:e(`fileManager.tags.manageTitle`),children:[(0,G.jsx)(Eu,{className:`w-4 h-4 mr-2`}),e(`fileManager.tags.manage`)]}),r(`library:purge`)&&(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>O(!0),title:e(`libraryPurge.headerTooltip`),children:[(0,G.jsx)(Pu,{className:`w-4 h-4 mr-2`}),e(`libraryPurge.headerButton`)]}),i(`library:delete_own`,`library:delete_all`)&&(0,G.jsxs)(Ai,{to:`/files/trash`,className:`inline-flex items-center px-3 py-1.5 text-sm rounded bg-bambu-dark-secondary text-bambu-gray hover:text-white hover:bg-bambu-dark transition-colors`,title:e(`libraryTrash.headerTooltip`),children:[(0,G.jsx)(Pu,{className:`w-4 h-4 mr-2`}),e(`libraryTrash.headerButton`),typeof He==`number`&&He>0&&(0,G.jsx)(`span`,{className:`ml-1.5 px-1.5 py-0.5 text-xs rounded-full bg-bambu-green/20 text-bambu-green`,children:He})]}),(0,G.jsxs)(Q,{onClick:()=>w(!0),disabled:!r(`library:upload`),title:r(`library:upload`)?void 0:e(`fileManager.noPermissionUpload`),children:[(0,G.jsx)(Vu,{className:`w-4 h-4 mr-2`}),e(`common.upload`)]})]})]}),et&&Xe&&Fe&&(0,G.jsxs)(`div`,{className:`flex items-center gap-3 mb-4 p-3 bg-amber-500/10 border border-amber-500/30 rounded-lg`,children:[(0,G.jsx)(Lu,{className:`w-5 h-5 text-amber-500 flex-shrink-0`}),(0,G.jsxs)(`div`,{className:`flex-1`,children:[(0,G.jsx)(`p`,{className:`text-sm text-amber-500 font-medium`,children:e(`fileManager.lowDiskSpaceWarning`)}),(0,G.jsx)(`p`,{className:`text-xs text-amber-500/80`,children:e(`fileManager.lowDiskSpaceDetails`,{free:Gd(Xe.disk_free_bytes),total:Gd(Xe.disk_total_bytes),threshold:Fe.library_disk_warning_gb})})]})]}),Xe&&(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 sm:gap-6 mb-6 p-3 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,G.jsx)(pc,{className:`w-4 h-4 text-bambu-green`}),(0,G.jsxs)(`span`,{className:`text-bambu-gray`,children:[e(`fileManager.files`),`:`]}),(0,G.jsx)(`span`,{className:`text-white font-medium`,children:Xe.total_files})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,G.jsx)(vc,{className:`w-4 h-4 text-blue-600 dark:text-blue-400`}),(0,G.jsxs)(`span`,{className:`text-bambu-gray`,children:[e(`fileManager.folders`),`:`]}),(0,G.jsx)(`span`,{className:`text-white font-medium`,children:Xe.total_folders})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,G.jsx)(Pc,{className:`w-4 h-4 text-amber-600 dark:text-amber-400`}),(0,G.jsxs)(`span`,{className:`text-bambu-gray`,children:[e(`fileManager.size`),`:`]}),(0,G.jsx)(`span`,{className:`text-white font-medium`,children:Gd(Xe.total_size_bytes)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm sm:ml-auto`,children:[(0,G.jsxs)(`span`,{className:`text-bambu-gray`,children:[e(`fileManager.free`),`:`]}),(0,G.jsx)(`span`,{className:`font-medium ${et?`text-amber-500`:`text-white`}`,children:Gd(Xe.disk_free_bytes)})]})]}),(0,G.jsxs)(`div`,{className:`flex-1 flex flex-col lg:flex-row gap-4 lg:gap-6 min-h-0`,children:[(0,G.jsx)(`div`,{className:`lg:hidden`,children:(0,G.jsxs)(`select`,{value:u===null?`__top:${f}`:String(u),onChange:e=>{let t=e.target.value;t.startsWith(`__top:`)?(d(null),p(t.slice(6))):d(parseInt(t,10))},className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg px-3 py-2.5 text-white focus:outline-none focus:border-bambu-green`,children:[(0,G.jsxs)(`option`,{value:`__top:internal`,children:[`📁 `,e(`fileManager.allFiles`)]}),ze?.some(e=>e.is_external)&&(0,G.jsxs)(`option`,{value:`__top:external`,children:[`🔗 `,e(`fileManager.allExternal`)]}),Ve&&(()=>{let e=(t,n=0)=>{let r=[];for(let i of t)r.push({id:i.id,name:i.name,fileCount:i.file_count,depth:n}),i.children.length>0&&r.push(...e(i.children,n+1));return r};return e(Ve).map(e=>(0,G.jsxs)(`option`,{value:e.id,children:[`│ `.repeat(e.depth),`📂 `,e.name,` `,e.fileCount>0?`(${e.fileCount})`:``]},e.id))})()]})}),(0,G.jsxs)(`div`,{ref:Se,className:`hidden lg:flex flex-shrink-0 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary overflow-hidden flex-col relative`,style:{width:`${ve}px`},children:[(0,G.jsx)(`div`,{className:`absolute right-0 top-0 bottom-0 w-1.5 cursor-col-resize z-10 group/resize flex items-center justify-center transition-colors ${be?`bg-bambu-green`:`hover:bg-bambu-green/50`}`,onMouseDown:e=>{e.preventDefault(),xe(!0)},onDoubleClick:()=>{ye(256),localStorage.setItem(`library-sidebar-width`,`256`)},title:e(`fileManager.dragToResizeTooltip`),children:(0,G.jsxs)(`div`,{className:`flex flex-col gap-1 opacity-0 group-hover/resize:opacity-100 transition-opacity ${be?`opacity-100`:``}`,children:[(0,G.jsx)(`div`,{className:`w-0.5 h-0.5 rounded-full bg-white/70`}),(0,G.jsx)(`div`,{className:`w-0.5 h-0.5 rounded-full bg-white/70`}),(0,G.jsx)(`div`,{className:`w-0.5 h-0.5 rounded-full bg-white/70`})]})}),(0,G.jsxs)(`div`,{className:`p-3 border-b border-bambu-dark-tertiary flex items-center justify-between`,children:[(0,G.jsx)(`h2`,{className:`text-sm font-medium text-white`,children:e(`fileManager.folders`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,G.jsxs)(`select`,{value:me,onChange:e=>{let t=e.target.value===`activity`?`activity`:`name`;he(t),localStorage.setItem(`library-folder-sort-field`,t)},className:`text-xs px-1 py-0.5 rounded bg-bambu-dark border border-bambu-dark-tertiary text-bambu-gray focus:outline-none focus:border-bambu-green`,title:e(`fileManager.folderSort`),"aria-label":e(`fileManager.folderSort`),children:[(0,G.jsx)(`option`,{value:`name`,children:e(`fileManager.folderSortByName`)}),(0,G.jsx)(`option`,{value:`activity`,children:e(`fileManager.folderSortByActivity`)})]}),(0,G.jsx)(`button`,{onClick:()=>{let e=ge===`asc`?`desc`:`asc`;_e(e),localStorage.setItem(`library-folder-sort-direction`,e)},className:`text-bambu-gray hover:text-white hover:bg-bambu-dark p-1 rounded transition-colors`,title:e(ge===`asc`?`fileManager.ascending`:`fileManager.descending`),"aria-label":e(ge===`asc`?`fileManager.ascending`:`fileManager.descending`),children:ge===`asc`?(0,G.jsx)(Vo,{className:`w-3.5 h-3.5`}):(0,G.jsx)(Fo,{className:`w-3.5 h-3.5`})}),(0,G.jsx)(`button`,{onClick:()=>{let e=!fe;pe(e),localStorage.setItem(`library-collapse-folders`,String(e))},className:`text-xs px-1.5 py-0.5 rounded transition-colors ${fe?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:text-white hover:bg-bambu-dark`}`,title:e(fe?`fileManager.expandFoldersByDefault`:`fileManager.collapseFoldersByDefault`),children:e(`fileManager.collapse`)}),(0,G.jsx)(`button`,{onClick:()=>{let e=!ue;de(e),localStorage.setItem(`library-wrap-folders`,String(e))},className:`text-xs px-1.5 py-0.5 rounded transition-colors ${ue?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:text-white hover:bg-bambu-dark`}`,title:e(ue?`fileManager.disableTextWrapping`:`fileManager.enableTextWrapping`),children:e(`fileManager.wrap`)})]})]}),(0,G.jsxs)(`div`,{className:`flex-1 overflow-y-auto p-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-1.5 rounded cursor-pointer transition-colors ${u===null&&f===`internal`?`bg-bambu-green/20 text-bambu-green`:`hover:bg-bambu-dark text-white`}`,onClick:()=>{d(null),p(`internal`)},children:[(0,G.jsx)(sc,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`text-sm`,children:e(`fileManager.allFiles`)})]}),ze?.some(e=>e.is_external)&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-1.5 rounded cursor-pointer transition-colors ${u===null&&f===`external`?`bg-bambu-green/20 text-bambu-green`:`hover:bg-bambu-dark text-white`}`,onClick:()=>{d(null),p(`external`)},children:[(0,G.jsx)(bc,{className:`w-4 h-4 text-purple-600 dark:text-purple-400`}),(0,G.jsx)(`span`,{className:`text-sm`,children:e(`fileManager.allExternal`)})]}),Ve?.map(t=>(0,G.jsx)(f$e,{folder:t,selectedFolderId:u,onSelect:d,onDelete:e=>R({type:`folder`,id:e}),onLink:I,onRename:e=>ie({type:`folder`,id:e.id,name:e.name}),wrapNames:ue,defaultExpanded:!fe,showModified:Ne,hasPermission:r,t:e},`${t.id}-${fe?`c`:`e`}`))]})]}),(0,G.jsxs)(`div`,{className:`flex-1 flex flex-col lg:flex-row min-w-0 min-h-0 gap-4 lg:gap-6`,children:[(0,G.jsxs)(`div`,{className:`flex-1 flex flex-col min-w-0 min-h-0`,children:[Ge.length>0&&(0,G.jsxs)(`div`,{className:`mb-3 flex flex-wrap items-center gap-2 p-2 sm:p-3 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary`,children:[(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray font-medium shrink-0`,children:e(`fileManager.tags.filterLabel`)}),Ge.map(e=>{let t=N.includes(e.id);return(0,G.jsxs)(`button`,{type:`button`,onClick:()=>qe(e.id),className:t?`inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs bg-bambu-green/20 text-bambu-green border border-bambu-green/40 hover:bg-bambu-green/30 transition-colors`:`inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs bg-bambu-dark text-bambu-gray border border-bambu-dark-tertiary hover:text-white hover:border-bambu-green/40 transition-colors`,title:e.name,children:[(0,G.jsx)(Eu,{className:`w-3 h-3`}),(0,G.jsx)(`span`,{children:e.name}),t&&(0,G.jsx)(nd,{className:`w-3 h-3`})]},e.id)}),N.length>0&&(0,G.jsx)(`button`,{type:`button`,onClick:()=>P([]),className:`ml-auto text-xs text-bambu-gray hover:text-white shrink-0`,children:e(`fileManager.tags.clearAll`)})]}),Ot?.is_external&&(0,G.jsxs)(`div`,{className:`flex items-center gap-3 mb-4 p-3 bg-purple-50 dark:bg-purple-500/10 border border-purple-300 dark:border-purple-500/30 rounded-lg`,children:[(0,G.jsx)(bc,{className:`w-5 h-5 text-purple-600 dark:text-purple-400 flex-shrink-0`}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-sm font-medium text-purple-700 dark:text-purple-300`,children:e(`fileManager.externalFolder`)}),Ot.external_readonly&&(0,G.jsxs)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-400 flex items-center gap-1`,children:[(0,G.jsx)(nl,{className:`w-3 h-3`}),e(`fileManager.readOnly`)]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray truncate font-mono`,title:Ot.external_path||``,children:Ot.external_path})]}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:()=>u&&rt.mutate(u),disabled:rt.isPending,title:e(`fileManager.scanFolder`),children:[rt.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Hl,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`ml-1.5`,children:e(`fileManager.scanFolder`)})]})]}),Je&&Je.length>0&&(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 sm:gap-3 mb-4 p-2 sm:p-3 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary sticky top-0 z-10 lg:static`,children:[(0,G.jsxs)(`div`,{className:`relative w-full sm:w-auto sm:flex-1 sm:max-w-xs`,children:[(0,G.jsx)(Ql,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,G.jsx)(`input`,{type:`text`,placeholder:e(`fileManager.searchFiles`),value:Ce,onChange:e=>we(e.target.value),className:`w-full pl-9 pr-3 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`}),Ue&&(0,G.jsx)(`span`,{className:`absolute -bottom-4 left-0 text-[10px] text-bambu-gray whitespace-nowrap`,title:e(`fileManager.searchSubfoldersHint`),children:e(`fileManager.searchSubfoldersHint`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(wc,{className:`w-4 h-4 text-bambu-gray hidden sm:block`}),(0,G.jsxs)(`select`,{value:Te,onChange:e=>Ee(e.target.value),className:`bg-bambu-dark border border-bambu-dark-tertiary rounded px-2 py-1.5 text-sm text-white focus:outline-none focus:border-bambu-green`,children:[(0,G.jsx)(`option`,{value:`all`,children:e(`fileManager.allTypes`)}),Qe.map(e=>(0,G.jsx)(`option`,{value:e,children:e.toUpperCase()},e))]})]}),o&&(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(`input`,{type:`text`,placeholder:e(`fileManager.filterByUser`,{defaultValue:`Filter by user`}),value:De,onChange:e=>Oe(e.target.value),list:`usernames-list`,className:`w-32 sm:w-40 px-2 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green ${De?`pr-7`:``}`,style:De?{WebkitAppearance:`none`,MozAppearance:`textfield`}:void 0}),De&&(0,G.jsx)(`button`,{onClick:()=>Oe(``),className:`absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white z-10`,children:(0,G.jsx)(nd,{className:`w-3 h-3`})}),(0,G.jsx)(`datalist`,{id:`usernames-list`,children:Ze?.map(e=>(0,G.jsx)(`option`,{value:e.username},e.id))})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`select`,{value:ke,onChange:e=>{let t=e.target.value;Ae(t),localStorage.setItem(`library-sort-field`,t)},className:`bg-bambu-dark border border-bambu-dark-tertiary rounded px-2 py-1.5 text-sm text-white focus:outline-none focus:border-bambu-green`,children:[(0,G.jsx)(`option`,{value:`name`,children:e(`common.name`)}),(0,G.jsx)(`option`,{value:`date`,children:e(`common.date`)}),(0,G.jsx)(`option`,{value:`size`,children:e(`fileManager.size`)}),(0,G.jsx)(`option`,{value:`type`,children:e(`common.type`)}),(0,G.jsx)(`option`,{value:`prints`,children:e(`fileManager.prints`)})]}),(0,G.jsx)(`button`,{onClick:()=>Me(e=>{let t=e===`asc`?`desc`:`asc`;return localStorage.setItem(`library-sort-direction`,t),t}),className:`p-1.5 rounded bg-bambu-dark border border-bambu-dark-tertiary hover:border-bambu-green transition-colors`,title:e(je===`asc`?`fileManager.ascending`:`fileManager.descending`),children:je===`asc`?(0,G.jsx)(Vo,{className:`w-4 h-4 text-white`}):(0,G.jsx)(Fo,{className:`w-4 h-4 text-white`})}),(0,G.jsx)(`button`,{onClick:()=>Pe(e=>{let t=!e;return localStorage.setItem(`library-show-modified`,String(t)),t}),className:`p-1.5 rounded bg-bambu-dark border transition-colors ${Ne?`border-bambu-green text-bambu-green`:`border-bambu-dark-tertiary text-white hover:border-bambu-green`}`,title:e(Ne?`fileManager.hideModified`:`fileManager.showModified`),"aria-pressed":Ne,children:(0,G.jsx)(rs,{className:`w-4 h-4`})})]}),(Ce||Te!==`all`||De)&&(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray hidden sm:inline`,children:e(`fileManager.resultsCount`,{showing:$e.length,total:Je.length})})]}),$e.length>0&&(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 mb-4 p-2 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary sticky top-[52px] z-10 lg:static`,children:[m.length===$e.length&&m.length>0?(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:yt,children:[(0,G.jsx)(bu,{className:`w-4 h-4 sm:mr-1`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`fileManager.deselectAll`)})]}):(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:vt,children:[(0,G.jsx)(vu,{className:`w-4 h-4 sm:mr-1`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`fileManager.selectAll`)})]}),m.length>0&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray ml-2`,children:e(`fileManager.selected`,{count:m.length})}),(0,G.jsx)(`div`,{className:`hidden sm:block flex-1`}),(0,G.jsxs)(`div`,{className:`w-full sm:w-auto flex flex-wrap items-center gap-2 mt-2 sm:mt-0`,children:[mt.length>=1&&(0,G.jsxs)(Q,{variant:`primary`,size:`sm`,onClick:()=>B(mt[0]),disabled:!r(`queue:create`),title:r(`queue:create`)?void 0:e(`fileManager.noPermissionAddToQueue`),children:[(0,G.jsx)(Rl,{className:`w-4 h-4 sm:mr-1`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:mt.length>1?e(`fileManager.variants.printAlternatives`,{count:mt.length}):e(`common.print`)})]}),mt.length>=2&&!mt.some(e=>e.variant_group_id)&&(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:()=>ot.mutate(mt.map(e=>e.id)),disabled:ot.isPending||!i(`library:update_own`,`library:update_all`),title:e(`fileManager.variants.groupTooltip`),children:[(0,G.jsx)(Jc,{className:`w-4 h-4 sm:mr-1`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`fileManager.variants.groupAction`)})]}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:()=>S(!0),disabled:!i(`library:update_own`,`library:update_all`),title:i(`library:update_own`,`library:update_all`)?void 0:e(`fileManager.noPermissionMoveFiles`),children:[(0,G.jsx)(vl,{className:`w-4 h-4 sm:mr-1`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.move`)})]}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:()=>M(!0),disabled:!i(`library:update_own`,`library:update_all`),title:i(`library:update_own`,`library:update_all`)?e(`fileManager.tags.bulkTooltip`):e(`fileManager.tags.noPermission`),children:[(0,G.jsx)(Eu,{className:`w-4 h-4 sm:mr-1`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`fileManager.tags.tagAction`)})]}),(0,G.jsxs)(Q,{variant:`danger`,size:`sm`,onClick:()=>{m.length===1?R({type:`file`,id:m[0]}):R({type:`bulk`,id:0,count:m.length})},disabled:!i(`library:delete_own`,`library:delete_all`),title:i(`library:delete_own`,`library:delete_all`)?void 0:e(`fileManager.noPermissionDeleteFiles`),children:[(0,G.jsx)(Pu,{className:`w-4 h-4 sm:mr-1`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.delete`)})]}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:yt,children:[(0,G.jsx)(nd,{className:`w-4 h-4 sm:mr-1`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.clear`)})]})]})]})]}),Dt?(0,G.jsx)(`div`,{className:`flex-1 flex items-center justify-center`,children:(0,G.jsxs)(`div`,{className:`flex flex-col items-center gap-3`,children:[(0,G.jsx)(Y,{className:`w-8 h-8 animate-spin text-bambu-green`}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`fileManager.loadingFiles`)})]})}):Je?.length===0?(0,G.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center`,children:[(0,G.jsx)(`div`,{className:`p-4 bg-bambu-dark rounded-2xl mb-4`,children:(0,G.jsx)(sc,{className:`w-12 h-12 text-bambu-gray/50`})}),(0,G.jsx)(`h3`,{className:`text-lg font-medium text-white mb-2`,children:e(u===null?f===`external`?`fileManager.externalIsEmpty`:`fileManager.noFilesYet`:`fileManager.folderIsEmpty`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-center max-w-md mb-6`,children:e(u===null?f===`external`?`fileManager.externalEmptyDescription`:`fileManager.noFilesDescription`:`fileManager.folderEmptyDescription`)}),(0,G.jsxs)(Q,{onClick:()=>w(!0),disabled:!r(`library:upload`),title:r(`library:upload`)?void 0:e(`fileManager.noPermissionUpload`),children:[(0,G.jsx)(Fl,{className:`w-4 h-4 mr-2`}),e(`fileManager.uploadFiles`)]})]}):$e.length===0?(0,G.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center`,children:[(0,G.jsx)(`div`,{className:`p-4 bg-bambu-dark rounded-2xl mb-4`,children:(0,G.jsx)(Ql,{className:`w-12 h-12 text-bambu-gray/50`})}),(0,G.jsx)(`h3`,{className:`text-lg font-medium text-white mb-2`,children:e(`fileManager.noMatchingFiles`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-center max-w-md mb-6`,children:e(`fileManager.noMatchingFilesDescription`)}),(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>{we(``),Ee(`all`)},children:e(`fileManager.clearFilters`)})]}):ce===`grid`?(0,G.jsx)(`div`,{className:`flex-1 lg:overflow-y-auto`,children:(0,G.jsx)(`div`,{className:`grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 2xl:grid-cols-6 gap-4`,children:$e.map(t=>(0,G.jsx)(p$e,{file:t,isSelected:m.includes(t.id),t:e,onSelect:_t,onDelete:e=>R({type:`file`,id:e}),onDownload:Ct,onPrint:B,onSlice:ee,onOpenInSlicer:Le,desktopSlicer:Ie,onRunPipeline:ne,useSlicerApi:Fe?.use_slicer_api??!1,canSlice:Re(),onPreview3d:e=>{M5(e)?c(`/gcode-viewer?library_file=${e.id}`):H(e)},onRename:e=>ie({type:`file`,id:e.id,name:e.filename}),onGenerateThumbnail:e=>pt.mutate(e.id),onTagClick:qe,thumbnailVersion:ae[t.id],hasPermission:r,canModify:a,authEnabled:o,showModified:Ne},t.id))})}):(0,G.jsx)(`div`,{className:`flex-1 lg:overflow-y-auto`,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary overflow-x-auto`,children:[(0,G.jsxs)(`div`,{className:`hidden sm:grid ${o?`grid-cols-[auto_1fr_120px_100px_100px_100px_minmax(0,200px)_220px]`:`grid-cols-[auto_1fr_100px_100px_100px_minmax(0,200px)_220px]`} gap-4 px-4 py-2 bg-bambu-dark-secondary border-b border-bambu-dark-tertiary text-xs text-bambu-gray font-medium`,children:[(0,G.jsx)(`div`,{className:`w-6`}),(0,G.jsx)(`div`,{children:e(`common.name`)}),o&&(0,G.jsx)(`div`,{children:e(`fileManager.uploadedBy`,{defaultValue:`Uploaded By`})}),(0,G.jsx)(`div`,{children:e(`common.type`)}),(0,G.jsx)(`div`,{children:e(`fileManager.size`)}),(0,G.jsx)(`div`,{children:e(`fileManager.prints`)}),(0,G.jsx)(`div`,{children:e(`fileManager.tags.title`)}),(0,G.jsx)(`div`,{})]}),$e.map(t=>(0,G.jsxs)(`div`,{className:`grid ${o?`grid-cols-[auto_1fr_120px_100px_100px_100px_minmax(0,200px)_220px]`:`grid-cols-[auto_1fr_100px_100px_100px_minmax(0,200px)_220px]`} gap-4 px-4 py-3 items-center border-b border-bambu-dark-tertiary last:border-b-0 cursor-pointer hover:bg-bambu-dark/50 transition-colors ${m.includes(t.id)?`bg-bambu-green/10`:``}`,onClick:()=>_t(t.id),children:[(0,G.jsx)(`div`,{className:`w-5 h-5 rounded border-2 flex items-center justify-center ${m.includes(t.id)?`bg-bambu-green border-bambu-green`:`border-bambu-gray/50`}`,children:m.includes(t.id)&&(0,G.jsx)(`div`,{className:`w-2 h-2 bg-white rounded-sm`})}),(0,G.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0`,children:[(0,G.jsxs)(`div`,{className:`relative group/thumb`,children:[(0,G.jsx)(`div`,{className:`w-10 h-10 rounded bg-bambu-dark flex-shrink-0 overflow-hidden`,children:t.thumbnail_path?(0,G.jsx)(`img`,{src:`${Z.getLibraryFileThumbnailUrl(t.id)}${ae[t.id]?(Z.getLibraryFileThumbnailUrl(t.id).includes(`?`)?`&`:`?`)+`v=${ae[t.id]}`:``}`,alt:``,className:`w-full h-full object-cover`}):(0,G.jsx)(`div`,{className:`w-full h-full flex items-center justify-center`,children:(0,G.jsx)(sc,{className:`w-5 h-5 text-bambu-gray/50`})})}),t.thumbnail_path&&(0,G.jsx)(`div`,{className:`absolute left-0 top-full mt-2 z-50 hidden group-hover/thumb:block`,children:(0,G.jsx)(`div`,{className:`w-48 h-48 rounded-lg bg-bambu-dark-secondary border border-bambu-dark-tertiary shadow-xl overflow-hidden`,children:(0,G.jsx)(`img`,{src:`${Z.getLibraryFileThumbnailUrl(t.id)}${ae[t.id]?(Z.getLibraryFileThumbnailUrl(t.id).includes(`?`)?`&`:`?`)+`v=${ae[t.id]}`:``}`,alt:t.filename,className:`w-full h-full object-contain`})})})]}),(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsx)(`div`,{className:`text-sm text-white truncate`,children:t.print_name||t.filename}),Ne&&(0,G.jsxs)(`div`,{className:`text-xs text-bambu-gray flex items-center gap-1 mt-0.5`,title:e(`fileManager.lastModified`),children:[(0,G.jsx)(rs,{className:`w-3 h-3 flex-shrink-0`}),(0,G.jsx)(`span`,{className:`truncate`,children:ip(t.fs_modified_at??t.created_at)})]})]})]}),o&&(0,G.jsx)(`div`,{className:`text-sm text-bambu-gray flex items-center gap-1`,children:t.created_by_username?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Hu,{className:`w-3 h-3`}),(0,G.jsx)(`span`,{className:`truncate`,children:t.created_by_username})]}):`-`}),(0,G.jsx)(`div`,{children:(0,G.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded font-medium ${t.file_type===`3mf`?`bg-bambu-green/20 text-bambu-green`:t.file_type===`gcode`||t.file_type===`gcode.3mf`?`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`:t.file_type===`stl`?`bg-purple-100 dark:bg-purple-500/20 text-purple-700 dark:text-purple-400`:`bg-bambu-gray/20 text-bambu-gray`}`,children:t.file_type.toUpperCase()})}),(0,G.jsx)(`div`,{className:`text-sm text-bambu-gray`,children:Gd(t.file_size)}),(0,G.jsx)(`div`,{className:`text-sm text-bambu-gray`,children:t.print_count>0?`${t.print_count}x`:`-`}),(0,G.jsx)(`div`,{className:`min-w-0`,onClick:e=>e.stopPropagation(),children:!t.tags||t.tags.length===0?(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray/50`,children:`-`}):(0,G.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:t.tags.map(e=>(0,G.jsxs)(`button`,{type:`button`,onClick:()=>qe(e.id),className:`inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded-full text-[10px] bg-bambu-green/10 text-bambu-green hover:bg-bambu-green/20 transition-colors max-w-full`,title:e.name,children:[(0,G.jsx)(Eu,{className:`w-2.5 h-2.5 flex-shrink-0`}),(0,G.jsx)(`span`,{className:`truncate`,children:e.name})]},e.id))})}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,onClick:e=>e.stopPropagation(),children:[M5(t)&&(0,G.jsx)(G.Fragment,{children:(0,G.jsx)(`button`,{onClick:()=>r(`queue:create`)&&B(t),className:`p-1.5 rounded transition-colors ${r(`queue:create`)?`hover:bg-bambu-dark text-bambu-gray hover:text-bambu-green`:`text-bambu-gray/50 cursor-not-allowed`}`,title:r(`queue:create`)?e(`common.print`):e(`fileManager.noPermissionAddToQueue`),disabled:!r(`queue:create`),children:(0,G.jsx)(Rl,{className:`w-4 h-4`})})}),N5(t,!!Fe?.use_slicer_api,Ie)&&(0,G.jsx)(`button`,{onClick:()=>{Re()&&(Fe?.use_slicer_api?ee:Le)(t)},className:`p-1.5 rounded transition-colors ${Re()?`hover:bg-bambu-dark text-bambu-gray hover:text-bambu-green`:`text-bambu-gray/50 cursor-not-allowed`}`,title:Re()?e(`slice.action`):Fe?.use_slicer_api?e(`fileManager.noPermissionSlice`):e(`fileManager.noPermissionDownload`),disabled:!Re(),children:Fe?.use_slicer_api?(0,G.jsx)(Rs,{className:`w-4 h-4`}):(0,G.jsx)(rc,{className:`w-4 h-4`})}),(Fe?.use_slicer_api??!1)&&N5(t,!0,Ie)&&(0,G.jsx)(`button`,{onClick:()=>r(`pipelines:run`)&&ne(t),className:`p-1.5 rounded transition-colors ${r(`pipelines:run`)?`hover:bg-bambu-dark text-bambu-gray hover:text-bambu-green`:`text-bambu-gray/50 cursor-not-allowed`}`,title:r(`pipelines:run`)?e(`library.runWithPipeline.actionLabel`,`Run with pipeline`):e(`library.runWithPipeline.noPermission`,`You do not have permission to run pipelines`),disabled:!r(`pipelines:run`),children:(0,G.jsx)(Nl,{className:`w-4 h-4`})}),(t.file_type===`3mf`||t.file_type===`gcode`||t.file_type===`gcode.3mf`||t.file_type===`stl`)&&(0,G.jsx)(`button`,{onClick:()=>{r(`library:read`)&&(M5(t)?c(`/gcode-viewer?library_file=${t.id}`):H(t))},className:`p-1.5 rounded transition-colors ${r(`library:read`)?`hover:bg-bambu-dark text-bambu-gray hover:text-bambu-green`:`text-bambu-gray/50 cursor-not-allowed`}`,title:r(`library:read`)?`3D Preview`:`You do not have permission to preview files`,disabled:!r(`library:read`),children:(0,G.jsx)(Zo,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:()=>r(`library:read`)&&Ct(t.id),className:`p-1.5 rounded transition-colors ${r(`library:read`)?`hover:bg-bambu-dark text-bambu-gray hover:text-white`:`text-bambu-gray/50 cursor-not-allowed`}`,title:r(`library:read`)?e(`common.download`):e(`fileManager.noPermissionDownload`),disabled:!r(`library:read`),children:(0,G.jsx)(Xs,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:()=>a(`library`,`update`,t.created_by_id)&&ie({type:`file`,id:t.id,name:t.filename}),className:`p-1.5 rounded transition-colors ${a(`library`,`update`,t.created_by_id)?`hover:bg-bambu-dark text-bambu-gray hover:text-white`:`text-bambu-gray/50 cursor-not-allowed`}`,title:a(`library`,`update`,t.created_by_id)?e(`common.rename`):e(`fileManager.noPermissionRenameFile`),disabled:!a(`library`,`update`,t.created_by_id),children:(0,G.jsx)(Al,{className:`w-4 h-4`})}),t.file_type===`stl`&&(0,G.jsx)(`button`,{onClick:()=>a(`library`,`update`,t.created_by_id)&&pt.mutate(t.id),className:`p-1.5 rounded transition-colors ${a(`library`,`update`,t.created_by_id)?`hover:bg-bambu-dark text-bambu-gray hover:text-bambu-green`:`text-bambu-gray/50 cursor-not-allowed`}`,title:a(`library`,`update`,t.created_by_id)?e(`fileManager.generateThumbnail`):e(`fileManager.noPermissionGenerateThumbnail`),disabled:pt.isPending||!a(`library`,`update`,t.created_by_id),children:(0,G.jsx)(Hc,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:()=>a(`library`,`delete`,t.created_by_id)&&R({type:`file`,id:t.id}),className:`p-1.5 rounded transition-colors ${a(`library`,`delete`,t.created_by_id)?`hover:bg-bambu-dark text-bambu-gray hover:text-red-700 dark:hover:text-red-400`:`text-bambu-gray/50 cursor-not-allowed`}`,title:a(`library`,`delete`,t.created_by_id)?e(`common.delete`):e(`fileManager.noPermissionDeleteFile`),disabled:!a(`library`,`delete`,t.created_by_id),children:(0,G.jsx)(Pu,{className:`w-4 h-4`})})]})]},t.id))]})})]}),u!==null&&(0,G.jsx)(t$e,{folderId:u})]})]}),g&&(0,G.jsx)(a$e,{parentId:u,onClose:()=>_(!1),onSave:e=>tt.mutate(e),isLoading:tt.isPending,t:e}),v&&(0,G.jsx)(o$e,{onClose:()=>b(!1),onSave:e=>nt.mutate(e),isLoading:nt.isPending,t:e}),x&&ze&&(0,G.jsx)(u$e,{folders:ze,selectedFiles:m,currentFolderId:u,onClose:()=>S(!1),onMove:e=>ct.mutate({fileIds:m,folderId:e}),isLoading:ct.isPending,t:e}),C&&(0,G.jsx)(gU,{folderId:u,onClose:()=>{w(!1),E([])},onUploadComplete:bt,initialFiles:T.length>0?T:void 0}),D&&(0,G.jsx)(i$e,{onClose:()=>O(!1)}),(0,G.jsx)(n$e,{open:k,onClose:()=>A(!1),onPickTag:e=>{N.includes(e)||P(t=>[...t,e])}}),(0,G.jsx)(FKe,{open:j,fileIds:m,onClose:()=>M(!1)}),F&&(0,G.jsx)(d$e,{folder:F,onClose:()=>I(null),onLink:e=>lt.mutate({id:F.id,data:e}),isLoading:lt.isPending,t:e}),L&&(0,G.jsx)(of,{title:L.type===`folder`?e(`fileManager.deleteFolder`):L.type===`bulk`?e(`fileManager.deleteFilesCount`,{count:L.count}):e(`fileManager.deleteFile`),message:L.type===`folder`?e(`fileManager.deleteFolderConfirm`):L.type===`bulk`?e(`fileManager.deleteFilesConfirm`,{count:L.count}):e(`fileManager.deleteFileConfirm`),confirmText:e(`common.delete`),variant:`danger`,isLoading:Tt,loadingText:e(`fileManager.deleting`),onConfirm:wt,onCancel:()=>R(null)}),z&&(!z.variant_group_id||ht!==void 0)&&(0,G.jsx)(zU,{mode:`create`,libraryFileId:gt?.[0]?.id??z.id,variantFiles:gt,archiveName:gt&>.length>1?`${gt[0].filename} ${e(`common.plusNMore`,{count:gt.length-1})}`:z.print_name||z.filename,onClose:()=>B(null),onSuccess:()=>{B(null),h([]),t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`queue`]}),t.invalidateQueries({queryKey:[`archives`]})}}),V&&(0,G.jsx)(RW,{source:{kind:`libraryFile`,id:V.id,filename:V.filename},onClose:()=>ee(null)}),te&&(0,G.jsx)(VW,{source:{kind:`libraryFile`,id:te.id,filename:te.filename},onClose:()=>ne(null)}),se&&(0,G.jsx)(PKe,{libraryFileId:se.id,title:se.print_name||se.filename,fileType:se.file_type,onClose:()=>H(null),onSliceWithBambuddy:N5(se,!0,Ie)&&r(`library:upload`)?()=>{let e=se;H(null),ee(e)}:void 0}),re&&(0,G.jsx)(l$e,{type:re.type,currentName:re.name,onClose:()=>ie(null),onSave:e=>{re.type===`file`?ut.mutate({id:re.id,filename:e}):dt.mutate({id:re.id,name:e})},isLoading:ut.isPending||dt.isPending,t:e})]})}function h$e(e){let t=rp(e);if(!t)return``;let n=Math.ceil((t.getTime()-Date.now())/(1e3*60*60*24));return n<=0?`any moment`:n===1?`1 day`:`${n} days`}function g$e(e){let t=rp(e);return t?t.toLocaleString():e}function _$e(){let{t:e}=U(),t=or(),n=co(),{showToast:r}=qd(),{hasPermission:i,authEnabled:a}=Nd(),[o,s]=(0,y.useState)(null),[c,l]=(0,y.useState)(new Set),u=!a||i(`library:purge`),d=K({queryKey:[`library-trash`],queryFn:()=>Z.listLibraryTrash(200,0)}),f=K({queryKey:[`library-trash-settings`],queryFn:()=>Z.getLibraryTrashSettings(),enabled:u}),[p,m]=(0,y.useState)(null);(0,y.useEffect)(()=>{f.data&&p===null&&m(f.data.retention_days)},[f.data,p]);let h=q({mutationFn:e=>{let t=f.data;return Z.updateLibraryTrashSettings({retention_days:e,auto_purge_enabled:t?.auto_purge_enabled??!1,auto_purge_days:t?.auto_purge_days??90,auto_purge_include_never_printed:t?.auto_purge_include_never_printed??!0})},onSuccess:t=>{r(e(`libraryTrash.toast.retentionSaved`,{days:t.retention_days}),`success`),n.invalidateQueries({queryKey:[`library-trash-settings`]}),n.invalidateQueries({queryKey:[`library-trash`]})},onError:t=>r(t.message||e(`libraryTrash.toast.retentionFailed`),`error`)}),g=q({mutationFn:e=>Z.restoreLibraryTrash(e),onSuccess:()=>{r(e(`libraryTrash.toast.restored`),`success`),n.invalidateQueries({queryKey:[`library-trash`]}),n.invalidateQueries({queryKey:[`library-trash-count`]}),n.invalidateQueries({queryKey:[`library-files`]}),n.invalidateQueries({queryKey:[`library-folders`]})},onError:t=>r(t.message||e(`libraryTrash.toast.restoreFailed`),`error`)}),_=q({mutationFn:e=>Z.hardDeleteLibraryTrash(e),onSuccess:()=>{r(e(`libraryTrash.toast.purged`),`success`),n.invalidateQueries({queryKey:[`library-trash`]}),n.invalidateQueries({queryKey:[`library-trash-count`]})},onError:t=>r(t.message||e(`libraryTrash.toast.purgeFailed`),`error`)}),v=q({mutationFn:()=>Z.emptyLibraryTrash(),onSuccess:t=>{r(e(`libraryTrash.toast.emptied`,{count:t.deleted}),`success`),n.invalidateQueries({queryKey:[`library-trash`]}),n.invalidateQueries({queryKey:[`library-trash-count`]})},onError:t=>r(t.message||e(`libraryTrash.toast.emptyFailed`),`error`)}),b=q({mutationFn:e=>Promise.all(e.map(e=>Z.restoreLibraryTrash(e))),onSuccess:(t,i)=>{r(e(`libraryTrash.toast.bulkRestored`,{count:i.length}),`success`),l(new Set),n.invalidateQueries({queryKey:[`library-trash`]}),n.invalidateQueries({queryKey:[`library-trash-count`]}),n.invalidateQueries({queryKey:[`library-files`]}),n.invalidateQueries({queryKey:[`library-folders`]})},onError:t=>r(t.message||e(`libraryTrash.toast.restoreFailed`),`error`)}),x=q({mutationFn:e=>Promise.all(e.map(e=>Z.hardDeleteLibraryTrash(e))),onSuccess:(t,i)=>{r(e(`libraryTrash.toast.bulkPurged`,{count:i.length}),`success`),l(new Set),n.invalidateQueries({queryKey:[`library-trash`]}),n.invalidateQueries({queryKey:[`library-trash-count`]})},onError:t=>r(t.message||e(`libraryTrash.toast.purgeFailed`),`error`)}),S=(0,y.useMemo)(()=>d.data?.items??[],[d.data?.items]),C=d.data?.retention_days??30,w=(0,y.useMemo)(()=>S.reduce((e,t)=>e+t.file_size,0),[S]),T=S.length>0&&S.every(e=>c.has(e.id)),E=c.size>0&&!T,D=e=>{l(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})};return(0,G.jsxs)(`div`,{className:`p-6 max-w-screen-2xl mx-auto`,children:[(0,G.jsx)(`div`,{className:`flex items-center gap-3 mb-4`,children:(0,G.jsxs)(Ai,{to:`/files`,className:`inline-flex items-center gap-1 text-sm text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-gray-200`,children:[(0,G.jsx)(Lo,{className:`w-4 h-4`}),` `,e(`libraryTrash.backToFiles`)]})}),(0,G.jsxs)(`div`,{className:`flex items-start justify-between mb-6 gap-4 flex-wrap`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h1`,{className:`text-2xl font-bold text-gray-900 dark:text-gray-100`,children:e(`libraryTrash.title`)}),(0,G.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400 mt-1`,children:e(u?`libraryTrash.subtitleAdmin`:`libraryTrash.subtitleUser`,{days:C})})]}),S.length>0&&(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>s({type:`empty`}),className:`text-red-600 dark:text-red-400`,children:[(0,G.jsx)(Pu,{className:`w-4 h-4 mr-1`}),e(`libraryTrash.emptyTrash`)]})]}),u&&f.data&&(0,G.jsxs)(`div`,{className:`mb-4 border border-gray-200 dark:border-gray-700 rounded-lg p-3 flex items-center gap-3 bg-gray-50 dark:bg-gray-800/40`,children:[(0,G.jsx)(`label`,{htmlFor:`retention-days`,className:`text-sm font-medium text-gray-700 dark:text-gray-300`,children:e(`libraryTrash.retentionLabel`)}),(0,G.jsx)(`input`,{id:`retention-days`,type:`number`,min:1,max:365,value:p??f.data.retention_days,onChange:e=>m(Math.max(1,Math.min(365,parseInt(e.target.value||`0`,10)||0))),className:`w-20 rounded border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-800 text-sm px-2 py-1 text-gray-900 dark:text-gray-100`}),(0,G.jsx)(`span`,{className:`text-sm text-gray-600 dark:text-gray-400`,children:e(`libraryTrash.days`)}),(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>p!=null&&h.mutate(p),disabled:h.isPending||p==null||p===f.data.retention_days,className:`ml-auto`,children:[(0,G.jsx)(ql,{className:`w-4 h-4 mr-1`}),e(`common.save`)]})]}),d.isLoading?(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-gray-500 dark:text-gray-400`,children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),` `,e(`libraryTrash.loading`)]}):S.length===0?(0,G.jsx)(`div`,{className:`border border-dashed border-gray-300 dark:border-gray-700 rounded-lg p-12 text-center`,children:(0,G.jsx)(`p`,{className:`text-gray-500 dark:text-gray-400`,children:e(`libraryTrash.empty`)})}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,G.jsx)(`div`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:e(`libraryTrash.summary`,{count:S.length,size:Gd(w)})}),c.size>0&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,G.jsx)(`span`,{className:`text-gray-600 dark:text-gray-400`,children:e(`libraryTrash.selectionCount`,{count:c.size})}),(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>b.mutate(Array.from(c)),disabled:b.isPending,children:[(0,G.jsx)(Wl,{className:`w-4 h-4 mr-1`}),e(`libraryTrash.bulkRestore`)]}),(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>s({type:`bulkDelete`,count:c.size}),disabled:x.isPending,className:`text-red-600 dark:text-red-400`,children:[(0,G.jsx)(Pu,{className:`w-4 h-4 mr-1`}),e(`libraryTrash.bulkPurge`)]})]})]}),(0,G.jsx)(`div`,{className:`border border-gray-200 dark:border-gray-700 rounded-lg overflow-x-auto`,children:(0,G.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,G.jsx)(`thead`,{className:`bg-gray-50 dark:bg-gray-800 text-left text-gray-600 dark:text-gray-300`,children:(0,G.jsxs)(`tr`,{children:[(0,G.jsx)(`th`,{className:`px-3 py-2 w-10`,children:(0,G.jsx)(`input`,{type:`checkbox`,checked:T,ref:e=>{e&&(e.indeterminate=E)},onChange:()=>{l(e=>e.size===S.length?new Set:new Set(S.map(e=>e.id)))},"aria-label":e(`libraryTrash.selectAll`),className:`rounded border-gray-300 cursor-pointer`})}),(0,G.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:e(`libraryTrash.col.filename`)}),(0,G.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:e(`libraryTrash.col.folder`)}),(0,G.jsx)(`th`,{className:`px-3 py-2 font-medium text-right`,children:e(`libraryTrash.col.size`)}),(0,G.jsx)(`th`,{className:`px-3 py-2 font-medium whitespace-nowrap`,children:e(`libraryTrash.col.deleted`)}),(0,G.jsx)(`th`,{className:`px-3 py-2 font-medium whitespace-nowrap`,children:e(`libraryTrash.col.autoPurge`)}),u&&(0,G.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:e(`libraryTrash.col.owner`)}),(0,G.jsx)(`th`,{className:`px-3 py-2 font-medium text-right`,children:e(`libraryTrash.col.actions`)})]})}),(0,G.jsx)(`tbody`,{className:`divide-y divide-gray-100 dark:divide-gray-800`,children:S.map(t=>(0,G.jsxs)(`tr`,{className:`hover:bg-gray-50 dark:hover:bg-gray-800/50`,children:[(0,G.jsx)(`td`,{className:`px-3 py-2`,children:(0,G.jsx)(`input`,{type:`checkbox`,checked:c.has(t.id),onChange:()=>D(t.id),"aria-label":e(`libraryTrash.selectOne`,{filename:t.filename}),className:`rounded border-gray-300 cursor-pointer`})}),(0,G.jsx)(`td`,{className:`px-3 py-2 text-gray-900 dark:text-gray-100 truncate max-w-md`,title:t.filename,children:t.filename}),(0,G.jsx)(`td`,{className:`px-3 py-2 text-gray-600 dark:text-gray-400`,children:t.folder_name??`—`}),(0,G.jsx)(`td`,{className:`px-3 py-2 text-right text-gray-600 dark:text-gray-400 tabular-nums whitespace-nowrap`,children:Gd(t.file_size)}),(0,G.jsx)(`td`,{className:`px-3 py-2 text-gray-600 dark:text-gray-400 whitespace-nowrap`,children:g$e(t.deleted_at)}),(0,G.jsx)(`td`,{className:`px-3 py-2 text-gray-600 dark:text-gray-400 whitespace-nowrap`,children:(0,G.jsx)(`span`,{title:g$e(t.auto_purge_at),children:e(`libraryTrash.autoPurgeIn`,{when:h$e(t.auto_purge_at)})})}),u&&(0,G.jsx)(`td`,{className:`px-3 py-2 text-gray-600 dark:text-gray-400`,children:t.created_by_username??`—`}),(0,G.jsxs)(`td`,{className:`px-3 py-2 text-right whitespace-nowrap`,children:[(0,G.jsxs)(`button`,{onClick:()=>g.mutate(t.id),disabled:g.isPending,className:`inline-flex items-center gap-1 px-2 py-1 text-xs text-blue-600 hover:text-blue-800 dark:text-blue-400 dark:hover:text-blue-300`,children:[(0,G.jsx)(Wl,{className:`w-3.5 h-3.5`}),e(`libraryTrash.restore`)]}),(0,G.jsxs)(`button`,{onClick:()=>s({type:`delete`,id:t.id,filename:t.filename}),disabled:_.isPending,className:`inline-flex items-center gap-1 px-2 py-1 text-xs text-red-600 hover:text-red-800 dark:text-red-400 dark:hover:text-red-300 ml-2`,children:[(0,G.jsx)(Pu,{className:`w-3.5 h-3.5`}),e(`libraryTrash.purgeNow`)]})]})]},t.id))})]})})]}),o&&(0,G.jsx)(of,{onCancel:()=>s(null),onConfirm:()=>{o&&(o.type===`delete`?_.mutate(o.id):o.type===`bulkDelete`?x.mutate(Array.from(c)):v.mutate(),s(null))},title:o.type===`delete`?e(`libraryTrash.confirm.purgeTitle`):o.type===`bulkDelete`?e(`libraryTrash.confirm.bulkPurgeTitle`):e(`libraryTrash.confirm.emptyTitle`),message:o.type===`delete`?e(`libraryTrash.confirm.purgeBody`,{filename:o.filename}):o.type===`bulkDelete`?e(`libraryTrash.confirm.bulkPurgeBody`,{count:o.count}):e(`libraryTrash.confirm.emptyBody`,{count:S.length}),confirmText:e(`libraryTrash.confirm.cta`),variant:`danger`}),d.isError&&(0,G.jsxs)(`div`,{className:`mt-4 text-sm text-red-600 dark:text-red-400`,children:[d.error?.message??e(`libraryTrash.loadError`),(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>t(`/files`),className:`ml-3`,children:e(`libraryTrash.backToFiles`)})]})]})}function v$e(e){return e.includes(`/camera/`)}function y$e(e,t,n){let r=0;return e.querySelectorAll(`img[src*="/api/v1/"], video[src*="/api/v1/"]`).forEach(e=>{let i=e.getAttribute(`src`)||``,a=v$e(i)?n:t;if(!a)return;let o=`token=${encodeURIComponent(a)}`;if(i.includes(o))return;let s=i.replace(/([?&])token=[^&]*(&|$)/,(e,t,n)=>n===`&`?t:``);e.src=`${s}${s.includes(`?`)?`&`:`?`}${o}`,r+=1}),r}function b$e(){let{authEnabled:e,user:t,loading:n,hasPermission:r}=Nd(),i=co(),a=(0,y.useRef)(!1),o=!n&&(!e||t!==null),{data:s}=K({queryKey:[`media-token`,t?.id??null],queryFn:()=>Z.getMediaToken(),enabled:o,staleTime:3e3*1e3,refetchInterval:3e3*1e3}),c=!e||r(`camera:view`),{data:l}=K({queryKey:[`camera-stream-token`,t?.id??null],queryFn:()=>Z.getCameraStreamToken(),enabled:o&&c,staleTime:3e3*1e3,refetchInterval:3e3*1e3}),u=s?.token??null,d=l?.token??null;(0,y.useEffect)(()=>(hd(u),pd(d),(u||d)&&y$e(document,u,d),()=>{hd(null),pd(null)}),[u,d]),(0,y.useEffect)(()=>{if(!e)return;let t=e=>{let t=e.target;if(!(t instanceof HTMLImageElement||t instanceof HTMLVideoElement))return;let n=t.src||``,r=v$e(n),o=r?md():gd();!o||!n.includes(`token=${encodeURIComponent(o)}`)||a.current||(a.current=!0,i.invalidateQueries({queryKey:r?[`camera-stream-token`]:[`media-token`]}),setTimeout(()=>{a.current=!1},5e3))};return document.addEventListener(`error`,t,!0),()=>document.removeEventListener(`error`,t,!0)},[e,i])}var a9=5,x$e=2e3,S$e=3e4,C$e=5e3;function w$e(){let{t:e}=U(),t=co(),{showToast:n}=qd(),{hasPermission:r,authEnabled:i,user:a}=Nd(),{printerId:o}=dr(),s=parseInt(o||`0`,10),[c]=Ri(),l=parseInt(c.get(`fps`)||`15`,10),u=Math.min(Math.max(isNaN(l)?15:l,1),30);b$e();let{data:d,isPending:f}=K({queryKey:[`camera-stream-token`,a?.id??null],queryFn:()=>Z.getCameraStreamToken(),enabled:i?!!a:!0,staleTime:3e3*1e3}),p=d?.token??md(),[m,h]=(0,y.useState)(`stream`),[g,_]=(0,y.useState)(!1),[v,b]=(0,y.useState)(!1),[x,S]=(0,y.useState)(!1),[C,w]=(0,y.useState)(!0),[T,E]=(0,y.useState)(Date.now()),[D,O]=(0,y.useState)(!1),[k,A]=(0,y.useState)(!1),[j,M]=(0,y.useState)(0),[N,P]=(0,y.useState)(!1),[F,I]=(0,y.useState)(0),[L,R]=(0,y.useState)(1),[z,B]=(0,y.useState)({x:0,y:0}),[V,ee]=(0,y.useState)(!1),[te,ne]=(0,y.useState)({x:0,y:0}),[re,ie]=(0,y.useState)(null),[ae,oe]=(0,y.useState)(null),se=(0,y.useRef)(null),H=(0,y.useRef)(null),ce=(0,y.useRef)(null),le=(0,y.useRef)(null),ue=(0,y.useRef)(null),de=(0,y.useRef)(0),{data:fe}=K({queryKey:[`printer`,s],queryFn:()=>Z.getPrinter(s),enabled:s>0}),{data:pe}=K({queryKey:[`printerStatus`,s],queryFn:()=>Z.getPrinterStatus(s),refetchInterval:3e4,enabled:s>0}),me=q({mutationFn:e=>Z.setChamberLight(s,e),onMutate:async e=>{await t.cancelQueries({queryKey:[`printerStatus`,s]});let n=t.getQueryData([`printerStatus`,s]);return t.setQueryData([`printerStatus`,s],t=>({...t,chamber_light:e})),{previousStatus:n}},onSuccess:(e,t)=>{n(`Chamber light ${t?`on`:`off`}`)},onError:(r,i,a)=>{a?.previousStatus&&t.setQueryData([`printerStatus`,s],a.previousStatus),n(r.message||e(`printers.toast.failedToControlChamberLight`),`error`)}}),he=(pe?.state===`RUNNING`||pe?.state===`PAUSE`)&&(pe?.printable_objects_count??0)>=2;(0,y.useEffect)(()=>(fe&&(document.title=`${fe.name} - Camera`),()=>{document.title=`Bambuddy`}),[fe]);let ge=(0,y.useRef)(!1);(0,y.useEffect)(()=>{let e=`/api/v1/printers/${s}/camera/stop`;ge.current=!1;let t=()=>{if(s>0&&!ge.current){ge.current=!0;let t={},n=ud();n&&(t.Authorization=`Bearer ${n}`),fetch(e,{method:`POST`,keepalive:!0,headers:t}).catch(()=>{})}},n=()=>{t()};window.addEventListener(`beforeunload`,n);let r=se.current;return()=>{window.removeEventListener(`beforeunload`,n),r&&(r.src=``),t()}},[s]),(0,y.useEffect)(()=>{if(C&&!D){let e=setTimeout(()=>{w(!1)},m===`stream`?3e3:2e4);return()=>clearTimeout(e)}},[m,C,T,D]),(0,y.useEffect)(()=>{let e=()=>{A(!!document.fullscreenElement),R(1),B({x:0,y:0}),m===`stream`&&!D&&(se.current&&(se.current.src=``),setTimeout(()=>{w(!0),E(Date.now())},200))};return document.addEventListener(`fullscreenchange`,e),()=>document.removeEventListener(`fullscreenchange`,e)},[m,D]),(0,y.useEffect)(()=>{let e,t=()=>{clearTimeout(e),e=setTimeout(()=>{localStorage.setItem(`cameraWindowState`,JSON.stringify({width:window.outerWidth,height:window.outerHeight,left:window.screenX,top:window.screenY}))},500)};return window.addEventListener(`resize`,t),()=>{clearTimeout(e),window.removeEventListener(`resize`,t)}},[]),(0,y.useEffect)(()=>()=>{ce.current&&clearTimeout(ce.current),le.current&&clearInterval(le.current),ue.current&&clearInterval(ue.current)},[]);let _e=(0,y.useCallback)(()=>{if(j>=a9){P(!1),S(!0);return}let e=Math.min(x$e*2**j,S$e);P(!0),I(Math.ceil(e/1e3)),le.current=setInterval(()=>{I(e=>e<=1?(le.current&&clearInterval(le.current),0):e-1)},1e3),ce.current=setTimeout(()=>{M(e=>e+1),P(!1),w(!0),S(!1),se.current&&(se.current.src=``),E(Date.now())},e)},[j]);(0,y.useEffect)(()=>{if(m!==`stream`||C||N||D){ue.current&&=(clearInterval(ue.current),null);return}return de.current=0,ue.current=setInterval(async()=>{try{let e=await Z.getCameraStatus(s);if(!(e.stalled||!e.active&&!x)){de.current=0;return}if(de.current+=1,de.current<2)return;de.current=0,console.log(`Stream issue detected: stalled=${e.stalled}, active=${e.active}, reconnecting...`),ue.current&&=(clearInterval(ue.current),null),w(!1),_e()}catch{}},C$e),()=>{ue.current&&=(clearInterval(ue.current),null)}},[m,C,x,N,D,s,_e]);let ve=()=>{w(!1),m===`stream`&&j{if(w(!1),S(!1),M(0),de.current=0,P(!1),ce.current&&clearTimeout(ce.current),le.current&&clearInterval(le.current),se.current&&!localStorage.getItem(`cameraWindowState`)){let e=se.current,t=e.naturalWidth,n=e.naturalHeight;if(t>0&&n>0){let e=window.outerWidth-window.innerWidth,r=window.outerHeight-window.innerHeight,i=t+16+e,a=n+45+16+r;try{window.resizeTo(i,a)}catch{}}}},be=()=>{if(s>0){let e={},t=ud();t&&(e.Authorization=`Bearer ${t}`),fetch(`/api/v1/printers/${s}/camera/stop`,{method:`POST`,headers:e}).catch(()=>{})}},xe=e=>{m===e||D||(O(!0),w(!0),S(!1),M(0),P(!1),R(1),B({x:0,y:0}),ce.current&&clearTimeout(ce.current),le.current&&clearInterval(le.current),se.current&&(se.current.src=``),m===`stream`&&be(),setTimeout(()=>{h(e),E(Date.now()),O(!1)},100))},Se=()=>{D||(O(!0),w(!0),S(!1),M(0),P(!1),ce.current&&clearTimeout(ce.current),le.current&&clearInterval(le.current),se.current&&(se.current.src=``),m===`stream`&&be(),setTimeout(()=>{E(Date.now()),O(!1)},100))},Ce=()=>{H.current&&(document.fullscreenElement?document.exitFullscreen():H.current.requestFullscreen())},we=()=>{R(e=>Math.min(e+.5,4))},Te=()=>{R(e=>{let t=Math.max(e-.5,1);return t===1&&B({x:0,y:0}),t})},Ee=e=>{e.preventDefault(),e.deltaY<0?we():Te()},De=e=>{L>1&&(e.preventDefault(),ee(!0),ne({x:e.clientX-z.x,y:e.clientY-z.y}))},Oe=(0,y.useCallback)(()=>{if(!H.current)return{x:300,y:200};let e=H.current.getBoundingClientRect(),t=e.width*(L-1)/2,n=e.height*(L-1)/2;return{x:Math.max(50,t),y:Math.max(50,n)}},[L]),ke=e=>{if(V&&L>1){let t=e.clientX-te.x,n=e.clientY-te.y,r=Oe();B({x:Math.max(-r.x,Math.min(r.x,t)),y:Math.max(-r.y,Math.min(r.y,n))})}},Ae=()=>{ee(!1)},je=e=>{if(e.length<2)return 0;let t=e[0].clientX-e[1].clientX,n=e[0].clientY-e[1].clientY;return Math.sqrt(t*t+n*n)},Me=e=>e.length<2?{x:e[0].clientX,y:e[0].clientY}:{x:(e[0].clientX+e[1].clientX)/2,y:(e[0].clientY+e[1].clientY)/2},Ne=e=>{e.touches.length===2?(e.preventDefault(),ie(je(e.touches)),oe(Me(e.touches))):e.touches.length===1&&L>1&&(e.preventDefault(),ee(!0),ne({x:e.touches[0].clientX-z.x,y:e.touches[0].clientY-z.y}))},Pe=e=>{if(e.touches.length===2&&re!==null){e.preventDefault();let t=je(e.touches),n=t/re;R(e=>{let t=Math.max(1,Math.min(4,e*n));return t===1&&B({x:0,y:0}),t}),ie(t);let r=Me(e.touches);if(ae){let e=Oe();B(t=>({x:Math.max(-e.x,Math.min(e.x,t.x+(r.x-ae.x))),y:Math.max(-e.y,Math.min(e.y,t.y+(r.y-ae.y)))}))}oe(r)}else if(e.touches.length===1&&V&&L>1){e.preventDefault();let t=e.touches[0].clientX-te.x,n=e.touches[0].clientY-te.y,r=Oe();B({x:Math.max(-r.x,Math.min(r.x,t)),y:Math.max(-r.y,Math.min(r.y,n))})}},Fe=e=>{e.touches.length<2&&(ie(null),oe(null)),e.touches.length===0&&ee(!1)},Ie=()=>{R(1),B({x:0,y:0})},Le=D||!p&&(i||f)?``:(e=>p?`${e}&token=${encodeURIComponent(p)}`:_d(e))(m===`stream`?`/api/v1/printers/${s}/camera/stream?fps=${u}&t=${T}`:`/api/v1/printers/${s}/camera/snapshot?t=${T}`),Re=C||D||N;return s?(0,G.jsxs)(`div`,{ref:H,className:`min-h-screen bg-black flex flex-col`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2 bg-bambu-dark-secondary border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`h1`,{className:`text-sm font-medium text-white flex items-center gap-2`,children:[(0,G.jsx)(ss,{className:`w-4 h-4`}),fe?.name||`Printer ${s}`]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`div`,{className:`flex bg-bambu-dark rounded p-0.5`,children:[(0,G.jsx)(`button`,{onClick:()=>xe(`stream`),disabled:Re,className:`px-3 py-1 text-xs rounded transition-colors ${m===`stream`?`bg-bambu-green text-white`:`text-bambu-gray hover:text-white disabled:opacity-50`}`,children:e(`camera.live`)}),(0,G.jsx)(`button`,{onClick:()=>xe(`snapshot`),disabled:Re,className:`px-3 py-1 text-xs rounded transition-colors ${m===`snapshot`?`bg-bambu-green text-white`:`text-bambu-gray hover:text-white disabled:opacity-50`}`,children:e(`camera.snapshot`)})]}),(0,G.jsx)(`button`,{onClick:()=>me.mutate(!pe?.chamber_light),disabled:!pe?.connected||me.isPending||!r(`printers:control`),className:`p-1.5 rounded disabled:opacity-50 ${pe?.chamber_light?`bg-yellow-500/20 hover:bg-yellow-500/30`:`hover:bg-bambu-dark-tertiary`}`,title:r(`printers:control`)?e(`camera.chamberLight`):e(`printers.permission.noControl`),children:(0,G.jsx)(vT,{on:pe?.chamber_light??!1,className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:()=>_(!0),disabled:!he||!r(`printers:control`),className:`p-1.5 rounded disabled:opacity-50 ${he&&r(`printers:control`)?`hover:bg-bambu-dark-tertiary`:``}`,title:r(`printers:control`)?e(he?`printers.skipObjects.tooltip`:`printers.skipObjects.onlyWhilePrinting`):e(`printers.permission.noControl`),children:(0,G.jsx)(yT,{className:`w-4 h-4 text-bambu-gray`})}),(0,G.jsx)(`button`,{onClick:Se,disabled:Re,className:`p-1.5 hover:bg-bambu-dark-tertiary rounded disabled:opacity-50`,title:e(m===`stream`?`camera.restartStream`:`camera.refreshSnapshot`),children:(0,G.jsx)(Hl,{className:`w-4 h-4 text-bambu-gray ${Re?`animate-spin`:``}`})}),(0,G.jsx)(`button`,{onClick:()=>b(!0),className:`p-1.5 hover:bg-bambu-dark-tertiary rounded`,title:e(`camera.diagnose.button`),children:(0,G.jsx)(Su,{className:`w-4 h-4 text-bambu-gray`})}),(0,G.jsx)(`button`,{onClick:Ce,className:`p-1.5 hover:bg-bambu-dark-tertiary rounded`,title:e(k?`camera.exitFullscreen`:`camera.fullscreen`),children:k?(0,G.jsx)(pl,{className:`w-4 h-4 text-bambu-gray`}):(0,G.jsx)(ll,{className:`w-4 h-4 text-bambu-gray`})})]})]}),(0,G.jsx)(`div`,{className:`flex-1 flex items-center justify-center p-2 overflow-hidden`,onWheel:Ee,onMouseMove:ke,onMouseUp:Ae,onMouseLeave:Ae,onTouchStart:Ne,onTouchMove:Pe,onTouchEnd:Fe,style:{touchAction:`none`},children:(0,G.jsxs)(`div`,{className:`relative w-full h-full flex items-center justify-center`,children:[(C||D)&&!N&&(0,G.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-black/50 z-10`,children:(0,G.jsxs)(`div`,{className:`text-center`,children:[(0,G.jsx)(Hl,{className:`w-8 h-8 text-bambu-gray animate-spin mx-auto mb-2`}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(m===`stream`?`camera.connectingToCamera`:`camera.capturingSnapshot`)})]})}),N&&(0,G.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-black/80 z-10`,children:(0,G.jsxs)(`div`,{className:`text-center p-4`,children:[(0,G.jsx)(Zu,{className:`w-10 h-10 text-orange-400 mx-auto mb-3`}),(0,G.jsx)(`p`,{className:`text-white mb-2`,children:e(`camera.connectionLost`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mb-3`,children:e(`camera.reconnecting`,{countdown:F,attempt:Math.min(j+1,a9),max:a9})}),(0,G.jsx)(`button`,{onClick:Se,className:`px-4 py-2 bg-bambu-green text-white text-sm rounded hover:bg-bambu-green/80 transition-colors`,children:e(`camera.reconnectNow`)})]})}),x&&!N&&(0,G.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-black z-10`,children:(0,G.jsxs)(`div`,{className:`text-center p-4`,children:[(0,G.jsx)(Lu,{className:`w-12 h-12 text-orange-400 mx-auto mb-3`}),(0,G.jsx)(`p`,{className:`text-white mb-2`,children:e(`camera.cameraUnavailable`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mb-4 max-w-md`,children:e(`camera.cameraUnavailableDesc`)}),(0,G.jsxs)(`div`,{className:`flex gap-2 justify-center`,children:[(0,G.jsx)(`button`,{onClick:Se,className:`px-4 py-2 bg-bambu-green text-white rounded hover:bg-bambu-green/80 transition-colors`,children:e(`camera.retry`)}),(0,G.jsx)(`button`,{onClick:()=>b(!0),className:`px-4 py-2 bg-bambu-dark border border-bambu-dark-tertiary text-bambu-gray hover:text-white rounded transition-colors`,children:e(`camera.diagnose.button`)})]})]})}),(0,G.jsx)(`img`,{ref:se,src:Le,alt:e(`camera.cameraStream`),className:`max-w-full max-h-full object-contain select-none`,style:{transform:`scale(${L}) translate(${z.x/L}px, ${z.y/L}px) rotate(${fe?.camera_rotation||0}deg)`,...fe?.camera_rotation===90||fe?.camera_rotation===270?{maxWidth:`100vh`,maxHeight:`100vw`}:{},cursor:L>1?V?`grabbing`:`grab`:`default`},onError:Le?ve:void 0,onLoad:Le?ye:void 0,onMouseDown:De,draggable:!1},T),(0,G.jsxs)(`div`,{className:`absolute bottom-4 left-4 flex items-center gap-1.5 bg-black/60 rounded-lg px-2 py-1.5`,children:[(0,G.jsx)(`button`,{onClick:Te,disabled:L<=1,className:`p-1.5 hover:bg-white/10 rounded disabled:opacity-30`,title:e(`camera.zoomOut`),children:(0,G.jsx)(ad,{className:`w-4 h-4 text-white`})}),(0,G.jsxs)(`button`,{onClick:Ie,className:`px-2 py-1 text-sm text-white hover:bg-white/10 rounded min-w-[48px]`,title:e(`camera.resetZoom`),children:[Math.round(L*100),`%`]}),(0,G.jsx)(`button`,{onClick:we,disabled:L>=4,className:`p-1.5 hover:bg-white/10 rounded disabled:opacity-30`,title:e(`camera.zoomIn`),children:(0,G.jsx)(rd,{className:`w-4 h-4 text-white`})})]})]})}),(0,G.jsx)(bT,{printerId:s,isOpen:g,onClose:()=>_(!1)}),v&&(0,G.jsx)(xT,{printerId:s,printerName:fe?.name||null,onClose:()=>b(!1)})]}):(0,G.jsx)(`div`,{className:`min-h-screen bg-black flex items-center justify-center`,children:(0,G.jsx)(`p`,{className:`text-white`,children:e(`camera.invalidPrinterId`)})})}var T$e=5e3,E$e=4,D$e=8,O$e=1,k$e=16,A$e=2,j$e=60;function M$e(e,t,n,r){let i=parseInt(e??``,10);return Number.isFinite(i)?Math.min(r,Math.max(n,i)):t}function N$e(e,t,n,r,i,a){return e.has(t)?M$e(e.get(t),r,i,a):M$e(localStorage.getItem(n),r,i,a)}function P$e(){let{t:e}=U(),t=rr(),{authEnabled:n,loading:r,user:i}=Nd(),[a]=Ri(),o=a.get(`token`),s=o!=null&&o!==``,[c,l]=(0,y.useState)(()=>N$e(a,`maxLive`,`camWallMaxLive`,E$e,O$e,k$e)),[u,d]=(0,y.useState)(()=>N$e(a,`interval`,`camWallSnapshotSec`,D$e,A$e,j$e)),[f,p]=(0,y.useState)(()=>{let e=a.get(`status`)??localStorage.getItem(`camWallStatusMode`);return(s?[`off`,`compact`]:[`off`,`compact`,`full`]).includes(e)?e:`compact`});(0,y.useEffect)(()=>{if(s)return pd(o),()=>pd(null)},[s,o]);let m=K({queryKey:[`camwall-printers`,o],queryFn:()=>Z.getCamWallPrinters(o??void 0),enabled:s,refetchInterval:T$e}),h=K({queryKey:[`printers`],queryFn:()=>Z.getPrinters(),enabled:!s&&!r&&(!n||i!==null),refetchInterval:T$e}),g=(0,y.useMemo)(()=>{let e=new Map;for(let t of m.data??[])e.set(t.id,{connected:t.connected,state:t.state,progress:t.progress,remaining_time:t.remaining_time,layer_num:t.layer_num,total_layers:t.total_layers,hms_errors:t.hms_errors});return e},[m.data]);if(!s&&r)return(0,G.jsx)(`div`,{className:`flex min-h-screen items-center justify-center bg-bambu-dark text-bambu-gray`,children:e(`common.loading`)});if(!s&&n&&!i)return(0,G.jsx)(Fr,{to:`/login`,replace:!0,state:{from:t}});let _=s?m:h,v=s?m.data??[]:h.data??[];return _.isError?(0,G.jsx)(`div`,{className:`flex min-h-screen items-center justify-center bg-bambu-dark p-6 text-center`,children:(0,G.jsx)(`p`,{className:`max-w-md text-sm text-red-400`,children:e(s?`printers.camWall.page.tokenRejected`:`printers.camWall.page.loadFailed`)})}):(0,G.jsx)(`div`,{className:`min-h-screen bg-bambu-dark p-4`,children:(0,G.jsx)(OT,{printers:v,maxLive:c,snapshotIntervalSec:u,statusMode:f,statuses:s?g:void 0,showSettings:!s,onTileClick:s?void 0:e=>window.open(`/camera/${e}`,`camera-${e}`),onChangeMaxLive:e=>{l(e),localStorage.setItem(`camWallMaxLive`,String(e))},onChangeSnapshotIntervalSec:e=>{d(e),localStorage.setItem(`camWallSnapshotSec`,String(e))},onChangeStatusMode:e=>{p(e),localStorage.setItem(`camWallStatusMode`,e)}})})}function F$e(e,t,n){if(!e)return``;if(!t)return e;let r=t.match(/plate_(\d+)\.gcode/);return r&&parseInt(r[1],10)>1?`${e} — ${n(`printers.plateNumber`,`Plate {{number}}`,{number:r[1]})}`:e}function I$e(e){let t=e.get(`show`)?.split(`,`)||[`progress`,`layers`,`eta`,`filename`,`status`],n=parseInt(e.get(`fps`)||`15`,10),r=Math.min(Math.max(isNaN(n)?15:n,1),30),i=e.get(`camera`),a=i!==`false`&&i!==`0`;return{size:e.get(`size`)||`medium`,fps:r,showCamera:a,showProgress:t.includes(`progress`),showLayers:t.includes(`layers`),showEta:t.includes(`eta`),showFilename:t.includes(`filename`),showStatus:t.includes(`status`),showPrinter:t.includes(`printer`),showNozzle:t.includes(`nozzle`),showBed:t.includes(`bed`),showChamber:t.includes(`chamber`)}}function L$e(e,t){if(e.stg_cur_name)return e.stg_cur_name;switch(e.state){case`RUNNING`:return t(`streamOverlay.status.printing`);case`PAUSE`:return t(`streamOverlay.status.paused`);case`FINISH`:return t(`streamOverlay.status.finished`);case`FAILED`:return t(`streamOverlay.status.failed`);case`IDLE`:return t(`streamOverlay.status.idle`);default:return e.state||t(`streamOverlay.status.unknown`)}}function o9(e,t){let n=e[t];return typeof n==`number`?n:null}function R$e({icon:e,label:t,current:n,target:r,sizes:i}){let a=r!=null&&r>0&&Math.round(r)!==Math.round(n);return(0,G.jsxs)(`div`,{className:`flex items-center ${i.gap} text-white/70`,children:[e,(0,G.jsxs)(`span`,{className:i.text,children:[(0,G.jsx)(`span`,{className:`mr-1`,children:t}),(0,G.jsxs)(`span`,{className:`text-white`,children:[Math.round(n),`°C`]}),a&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`span`,{className:`mx-1`,children:`/`}),(0,G.jsxs)(`span`,{children:[Math.round(r),`°C`]})]})]})]})}function z$e(e){switch(e){case`small`:return{container:`p-3`,text:`text-sm`,textLarge:`text-lg`,progressHeight:`h-2`,icon:`w-3 h-3`,gap:`gap-2`,logoHeight:`h-12`};case`large`:return{container:`p-6`,text:`text-xl`,textLarge:`text-3xl`,progressHeight:`h-4`,icon:`w-6 h-6`,gap:`gap-4`,logoHeight:`h-24`};default:return{container:`p-4`,text:`text-base`,textLarge:`text-xl`,progressHeight:`h-3`,icon:`w-4 h-4`,gap:`gap-3`,logoHeight:`h-16`}}}function B$e(){let{printerId:e}=dr(),[t]=Ri(),{t:n}=U(),r=co(),i=parseInt(e||`0`,10),[a,o]=(0,y.useState)(Date.now()),s=(0,y.useMemo)(()=>I$e(t),[t]),c=z$e(s.size),l=t.get(`token`),u=l!=null&&l!==``,{data:d}=K({queryKey:[`overlayStatus`,i,l],queryFn:()=>Z.getOverlayStatus(i,l??void 0),enabled:i>0&&u,refetchInterval:2e3}),{data:f}=K({queryKey:[`printer`,i],queryFn:()=>Z.getPrinter(i),enabled:i>0&&!u}),{data:p}=K({queryKey:[`printerStatus`,i],queryFn:()=>Z.getPrinterStatus(i),enabled:i>0&&!u,refetchInterval:2e3}),{data:m}=K({queryKey:[`settings`],queryFn:Z.getSettings,enabled:!u}),h=(0,y.useMemo)(()=>u?d&&{name:d.name,camera_rotation:d.camera_rotation}:f,[u,d,f]),g=u?d:p,_=(u?d?.time_format:m?.time_format)||`system`;(0,y.useEffect)(()=>{if(!i||u)return;let e=null,t=!1;return(async()=>{let n;try{n=(await Z.getWebSocketToken()).token}catch(e){let t=e instanceof sd?e.status:0;if(t===401||t===403)return}if(t)return;let a=window.location.protocol===`https:`?`wss:`:`ws:`,o=n?`?token=${encodeURIComponent(n)}`:``,s=`${a}//${window.location.host}/api/v1/ws${o}`;e=new WebSocket(s),e.onmessage=e=>{try{let t=JSON.parse(e.data);t.type===`printer_status`&&t.printer_id===i&&r.setQueryData([`printerStatus`,i],t.status)}catch{}},e.onerror=()=>{}})(),()=>{t=!0,e&&e.close()}},[i,u,r]),(0,y.useEffect)(()=>(document.title=h?`${h.name} - ${n(`streamOverlay.title`)}`:n(`streamOverlay.title`),()=>{document.title=`Bambuddy`}),[h,n]);let v=()=>{setTimeout(()=>{o(Date.now())},3e3)};if(!i)return(0,G.jsx)(`div`,{className:`min-h-screen bg-black flex items-center justify-center`,children:(0,G.jsx)(`p`,{className:`text-white`,children:n(`streamOverlay.invalidPrinterId`)})});if(!g)return(0,G.jsx)(`div`,{className:`min-h-screen bg-black flex items-center justify-center`,children:(0,G.jsx)(`p`,{className:`text-gray-400`,children:n(`common.loading`)})});let b=g.state===`RUNNING`||g.state===`PAUSE`,x=g.progress||0,S=g.temperatures??{},C=[];if(s.showNozzle){let e=o9(S,`nozzle`),t=o9(S,`nozzle_2`);e!=null&&C.push({key:`nozzle`,icon:(0,G.jsx)(hc,{className:c.icon}),label:n(`printers.heaterHistory.nozzle`,`Nozzle`),current:e,target:o9(S,`nozzle_target`)}),t!=null&&C.push({key:`nozzle_2`,icon:(0,G.jsx)(hc,{className:c.icon}),label:n(`printers.heaterHistory.nozzle2`,`Nozzle 2`),current:t,target:o9(S,`nozzle_2_target`)})}if(s.showBed){let e=o9(S,`bed`);e!=null&&C.push({key:`bed`,icon:(0,G.jsx)(bu,{className:c.icon}),label:n(`printers.heaterHistory.bed`,`Bed`),current:e,target:o9(S,`bed_target`)})}if(s.showChamber){let e=o9(S,`chamber`);e!=null&&C.push({key:`chamber`,icon:(0,G.jsx)(Zo,{className:c.icon}),label:n(`printers.heaterHistory.chamber`,`Chamber`),current:e,target:o9(S,`chamber_target`)})}let w=`/api/v1/printers/${i}/camera/stream?fps=${s.fps}&t=${a}`,T=u&&l?`${w}&token=${encodeURIComponent(l)}`:_d(w);return(0,G.jsxs)(`div`,{className:`min-h-screen bg-black relative overflow-hidden`,children:[s.showCamera&&(0,G.jsx)(`img`,{src:T,alt:n(`streamOverlay.cameraStream`),className:`absolute inset-0 w-full h-full object-contain`,style:h?.camera_rotation?{transform:`rotate(${h.camera_rotation}deg)`}:void 0,onError:v},a),(0,G.jsx)(`a`,{href:`https://github.com/maziggy/bambuddy`,target:`_blank`,rel:`noopener noreferrer`,className:`absolute top-4 right-4 z-10`,children:(0,G.jsx)(`img`,{src:`/img/bambuddy_logo_dark_transparent.png`,alt:`Bambuddy`,className:`${c.logoHeight} object-contain drop-shadow-lg hover:scale-105 transition-transform`})}),(0,G.jsx)(`div`,{className:`absolute bottom-0 left-0 right-0 z-10 bg-gradient-to-t from-black/80 via-black/60 to-transparent`,children:(0,G.jsxs)(`div`,{className:`${c.container}`,children:[s.showPrinter&&h&&(0,G.jsxs)(`div`,{className:`flex items-center ${c.gap} mb-2`,children:[(0,G.jsx)(Rl,{className:`${c.icon} text-white/70`}),(0,G.jsx)(`span`,{className:`${c.text} text-white font-medium`,children:h.name})]}),s.showFilename&&g.current_print&&(0,G.jsx)(`div`,{className:`${c.textLarge} text-white font-semibold mb-2 truncate drop-shadow-md`,children:F$e(g.current_print.replace(/\.gcode\.3mf$|\.3mf$|\.gcode$/i,``),g.gcode_file,n)}),s.showStatus&&(0,G.jsx)(`div`,{className:`${c.text} text-white/70 mb-2`,children:L$e(g,n)}),s.showProgress&&b&&(0,G.jsxs)(`div`,{className:`mb-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-1 ${c.text}`,children:[(0,G.jsx)(`span`,{className:`text-white/70`,children:n(`streamOverlay.progress`)}),(0,G.jsxs)(`span`,{className:`text-white font-bold`,children:[Math.round(x),`%`]})]}),(0,G.jsx)(`div`,{className:`w-full bg-white/20 rounded-full ${c.progressHeight}`,children:(0,G.jsx)(`div`,{className:`bg-bambu-green ${c.progressHeight} rounded-full transition-all duration-500`,style:{width:`${x}%`}})})]}),b&&(s.showLayers||s.showEta)&&(0,G.jsxs)(`div`,{className:`flex items-center ${c.gap} flex-wrap`,children:[s.showLayers&&g.layer_num!=null&&g.total_layers!=null&&g.total_layers>0&&(0,G.jsxs)(`div`,{className:`flex items-center ${c.gap} text-white/70`,children:[(0,G.jsx)(Jc,{className:c.icon}),(0,G.jsxs)(`span`,{className:c.text,children:[(0,G.jsx)(`span`,{className:`text-white`,children:g.layer_num}),(0,G.jsx)(`span`,{className:`mx-1`,children:`/`}),(0,G.jsx)(`span`,{children:g.total_layers})]})]}),s.showEta&&g.remaining_time!=null&&g.remaining_time>0&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`flex items-center ${c.gap} text-white/70`,children:[(0,G.jsx)(Nu,{className:c.icon}),(0,G.jsx)(`span`,{className:`${c.text} text-white`,children:lp(g.remaining_time*60)})]}),(0,G.jsxs)(`div`,{className:`flex items-center ${c.gap} text-white/70`,children:[(0,G.jsx)(js,{className:c.icon}),(0,G.jsxs)(`span`,{className:`${c.text} text-white`,children:[n(`streamOverlay.eta`),` `,cp(g.remaining_time,_,n)]})]})]})]}),!b&&(0,G.jsx)(`div`,{className:`${c.text} text-white/70 py-2`,children:g.connected?n(`streamOverlay.printerIdle`):n(`streamOverlay.printerOffline`)}),C.length>0&&(0,G.jsx)(`div`,{className:`flex items-center ${c.gap} flex-wrap mt-2`,children:C.map(e=>(0,G.jsx)(R$e,{icon:e.icon,label:e.label,current:e.current,target:e.target,sizes:c},e.key))})]})})]})}function V$e(){let{t:e}=U(),{id:t}=dr(),{mode:n}=Id(),{data:r,isLoading:i,error:a}=K({queryKey:[`external-link`,t],queryFn:()=>Z.getExternalLink(Number(t)),enabled:!!t});return i?(0,G.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,G.jsx)(Y,{className:`w-8 h-8 text-bambu-green animate-spin`})}):a||!r?(0,G.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-4 text-bambu-gray`,children:[(0,G.jsx)(Lu,{className:`w-12 h-12`}),(0,G.jsx)(`p`,{children:e(`common.linkNotFound`)})]}):(0,G.jsx)(`iframe`,{src:r.url,className:`h-full w-full border-0`,style:{colorScheme:n},title:r.name,sandbox:`allow-scripts allow-same-origin allow-forms allow-popups allow-popups-to-escape-sandbox`})}function H$e(){let{id:e}=dr(),t=or(),n=co(),{t:r}=U(),{showToast:i}=qd(),a=!!e,[o,s]=(0,y.useState)(``),[c,l]=(0,y.useState)(``),[u,d]=(0,y.useState)([]),[f,p]=(0,y.useState)(``),[m,h]=(0,y.useState)(!1),{data:g,isLoading:_}=K({queryKey:[`group`,e],queryFn:()=>Z.getGroup(Number(e)),enabled:a}),{data:v,isLoading:b}=K({queryKey:[`permissions`],queryFn:()=>Z.getPermissions()});a&&g&&!m&&(s(g.name),l(g.description||``),d(g.permissions),h(!0));let x=q({mutationFn:e=>Z.createGroup(e),onSuccess:()=>{n.invalidateQueries({queryKey:[`groups`]}),n.invalidateQueries({queryKey:[`group`]}),i(r(`groups.toast.created`)),t(`/settings?tab=users`)},onError:e=>{i(e.message,`error`)}}),S=q({mutationFn:t=>Z.updateGroup(Number(e),t),onSuccess:a=>{n.invalidateQueries({queryKey:[`groups`]}),a&&n.setQueryData([`group`,e],a),i(r(`groups.toast.updated`)),t(`/settings?tab=users`)},onError:e=>{i(e.message,`error`)}}),C=x.isPending||S.isPending,w=()=>{if(!o.trim()){i(r(`groups.toast.enterGroupName`),`error`);return}a?S.mutate({name:o===g?.name?void 0:o,description:c,permissions:u}):x.mutate({name:o,description:c||void 0,permissions:u})},T=e=>{d(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},E=(e,t)=>{let n=e.permissions.map(e=>e.value);d(e=>{let r=e.filter(e=>!n.includes(e));return t?[...r,...n]:r})},D=e=>e.permissions.every(e=>u.includes(e.value)),O=e=>{let t=e.permissions.filter(e=>u.includes(e.value)).length;return t>0&&t{v&&d(v.all_permissions)},A=()=>{d([])},j=f.toLowerCase(),M=(0,y.useMemo)(()=>v?j?v.categories.map(e=>({...e,permissions:e.permissions.filter(e=>e.label.toLowerCase().includes(j))})).filter(e=>e.permissions.length>0):v.categories:[],[v,j]),N=v?.all_permissions.length??0;return _||b?(0,G.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,G.jsx)(Y,{className:`w-8 h-8 text-bambu-green animate-spin`})}):(0,G.jsxs)(`div`,{className:`space-y-6 max-w-5xl mx-auto`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`button`,{onClick:()=>t(`/settings?tab=users`),className:`p-2 rounded-lg hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white transition-colors`,children:(0,G.jsx)(Lo,{className:`w-5 h-5`})}),(0,G.jsx)(`h1`,{className:`text-xl font-bold text-white`,children:r(a?`groups.editor.title`:`groups.editor.createTitle`)})]}),a&&g?.is_system&&(0,G.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-3 rounded-lg bg-yellow-50 dark:bg-yellow-500/10 border border-yellow-300 dark:border-yellow-500/20 text-yellow-700 dark:text-yellow-400 text-sm`,children:[(0,G.jsx)(Lu,{className:`w-4 h-4 shrink-0`}),r(`groups.form.systemGroupWarning`)]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:r(`groups.form.groupName`)}),(0,G.jsx)(`input`,{type:`text`,value:o,onChange:e=>s(e.target.value),disabled:a&&g?.is_system,className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors disabled:opacity-50`,placeholder:r(`groups.form.groupNamePlaceholder`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:r(`groups.form.description`)}),(0,G.jsx)(`input`,{type:`text`,value:c,onChange:e=>l(e.target.value),className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:r(`groups.form.descriptionPlaceholder`)})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between flex-wrap gap-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[r(`groups.editor.permissionsSelected`,{count:u.length}),` / `,N]}),(0,G.jsx)(Q,{size:`sm`,variant:`ghost`,onClick:k,children:r(`groups.editor.selectAll`)}),(0,G.jsx)(Q,{size:`sm`,variant:`ghost`,onClick:A,children:r(`groups.editor.clearAll`)})]}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(Ql,{className:`w-4 h-4 absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray`}),(0,G.jsx)(`input`,{type:`text`,value:f,onChange:e=>p(e.target.value),placeholder:r(`groups.editor.search`),className:`pl-9 pr-4 py-2 text-sm bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors w-64`})]})]}),M.length===0?(0,G.jsx)(`div`,{className:`text-center py-12 text-bambu-gray`,children:r(`groups.editor.noResults`)}):(0,G.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:M.map(e=>{let t=v.categories.find(t=>t.name===e.name),n=t.permissions.filter(e=>u.includes(e.value)).length,i=t.permissions.length,a=D(t),o=O(t);return(0,G.jsxs)(zd,{children:[(0,G.jsxs)(`div`,{className:`sticky top-0 z-10 flex items-center justify-between px-4 py-3 bg-bambu-dark-secondary border-b border-bambu-dark-tertiary rounded-t-xl`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsxs)(`button`,{type:`button`,onClick:()=>E(t,!a),className:`w-5 h-5 rounded border flex items-center justify-center transition-colors shrink-0 ${a?`bg-bambu-green border-bambu-green`:o?`bg-bambu-green/50 border-bambu-green`:`border-bambu-gray hover:border-white`}`,children:[a&&(0,G.jsx)(fs,{className:`w-3 h-3 text-white`}),o&&!a&&(0,G.jsx)(ml,{className:`w-3 h-3 text-white`})]}),(0,G.jsx)(su,{className:`w-4 h-4 text-bambu-gray shrink-0`}),(0,G.jsx)(`span`,{className:`text-white font-medium text-sm`,children:e.name})]}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray tabular-nums`,children:[n,`/`,i]})]}),(0,G.jsx)(`div`,{className:`p-3 space-y-1`,children:e.permissions.map(e=>(0,G.jsxs)(`label`,{className:`flex items-center gap-3 px-2 py-1.5 rounded hover:bg-bambu-dark-secondary cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:u.includes(e.value),onChange:()=>T(e.value),className:`w-4 h-4 shrink-0 rounded border-bambu-gray text-bambu-green focus:ring-bambu-green focus:ring-offset-0 bg-bambu-dark-secondary`}),(0,G.jsxs)(`span`,{className:`flex flex-col`,children:[(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.label}),e.value===`websocket:connect`&&(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray/60`,children:r(`groups.editor.websocketHint`)})]})]},e.value))})]},e.name)})}),(0,G.jsx)(`div`,{className:`h-16`}),(0,G.jsxs)(`div`,{className:`fixed bottom-0 left-0 right-0 z-20 px-6 py-3 bg-bambu-dark-secondary border-t border-bambu-dark-tertiary flex items-center justify-center gap-3`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>t(`/settings?tab=users`),children:r(`common.cancel`)}),(0,G.jsx)(Q,{onClick:w,disabled:C||!o.trim(),children:C?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),r(`common.saving`)]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(ql,{className:`w-4 h-4`}),r(`common.save`)]})})]})]})}var U$e=1.65,W$e=[`#1DB954`,`#3B82F6`,`#F59E0B`,`#EF4444`,`#8B5CF6`];function s9(e,t,n,r){return`${e}||${t??``}||${n??``}||${r??``}`}function c9(e,t){let n=new Date(e);return n.setDate(n.getDate()+Math.round(t)),n}function l9(e){return e.toLocaleDateString(void 0,{month:`short`,day:`numeric`,year:`numeric`})}function u9(e){return e.toLocaleDateString(void 0,{month:`short`,day:`numeric`})}function G$e(e){if(e.length<2)return null;let t=new Map;for(let n of e){let e=n.created_at.slice(0,10);t.set(e,(t.get(e)??0)+n.weight_used)}if(t.size<2)return null;let n=[...t.entries()].map(([e,t])=>({ms:new Date(e).getTime(),totalG:t})).sort((e,t)=>e.ms-t.ms),r=Date.now(),i=Math.LN2/30,a=[];for(let e=1;ee+t.weight,0);if(o===0)return null;let s=a.reduce((e,t)=>e+t.rate*t.weight,0)/o,c=a.reduce((e,t)=>e+t.weight*(t.rate-s)**2,0)/o;return{rate:s,stdDev:Math.sqrt(c)}}function K$e(e){let t=e.reduce((e,t)=>e+Math.max(0,t.weight_used-(t.weight_used_baseline??0)),0);if(t===0)return null;let n=Date.now(),r=(n-e.reduce((e,t)=>{let n=new Date(t.created_at).getTime();return nZ.getAllUsageHistory(5e3),staleTime:6e4,enabled:o}),{data:O=[]}=K({queryKey:[`shopping-list`],queryFn:Z.getShoppingList,staleTime:3e4,enabled:o}),k=T?.forecast_global_lead_time_days??0,A=(0,y.useMemo)(()=>{let e=new Map;for(let t of E)e.set(s9(t.material,t.subtype,t.brand,t.color_name),t);return e},[E]),j=(0,y.useMemo)(()=>{let e=new Map;for(let t of D){let n=e.get(t.spool_id)??[];n.push(t),e.set(t.spool_id,n)}return e},[D]),M=(0,y.useMemo)(()=>{let t=new Map;for(let n of e){if(n.archived_at)continue;let e=s9(n.material,n.subtype,n.brand,n.color_name),r=t.get(e)??{key:e,material:n.material,subtype:n.subtype,brand:n.brand,colorName:n.color_name,spools:[]};r.spools.push(n),t.set(e,r)}return[...t.values()]},[e]),N=(0,y.useMemo)(()=>{let e=new Date;return e.setHours(0,0,0,0),M.map(t=>{let n=A.get(t.key)??(t.colorName===null?null:A.get(s9(t.material,t.subtype,t.brand,null))??null),r=n?.lead_time_days??0,i=Math.max(k,r),a=n?.safety_margin_value??14,o=n?.safety_margin_unit??`days`,s=t.spools.reduce((e,t)=>e+Math.max(0,t.label_weight-t.weight_used),0),c=t.spools.reduce((e,t)=>e+t.label_weight,0),l=t.spools.reduce((e,t)=>e+Math.max(0,t.weight_used-(t.weight_used_baseline??0)),0),u=[];for(let e of t.spools)(e.weight_used_baseline??0)===0&&u.push(...j.get(e.id)??[]);let d=null,f=null,p=`none`,m=G$e(u);if(m!==null)d=m.rate,f=m.stdDev,p=`history`;else{let e=K$e(t.spools);e!==null&&(d=e,p=`delta`)}let h=U$e*(f??(d===null?0:d*.2))*Math.sqrt(i)+(o===`g`?a:d===null?a*5:d*a),g=d===null?0:d*i+h,_=d&&d>0?Math.floor(s/d):null,v=_===null?null:c9(e,_),y=d&&d>0?Math.floor((s-g)/d):null,b=y===null?null:c9(e,Math.max(0,y)),x=_!==null&&i>0&&_<=i,S=!x&&y!==null&&y<=0;return{group:t,settings:n,totalRemainingG:s,totalLabelG:c,totalSpools:t.spools.length,totalUsedG:l,dailyRateG:d,dailyRateStdDev:f,rateTier:p,effectiveLeadTimeDays:i,safetyStockG:h,reorderPointG:g,daysRemaining:_,daysUntilROP:y,projectedEmptyDate:v,reorderTriggerDate:b,reorderAlert:S,stockBreakAlert:x}})},[M,A,j,k]),P=(0,y.useMemo)(()=>[...new Set(M.map(e=>e.material))].sort(),[M]),F=(0,y.useMemo)(()=>[...new Set(M.map(e=>e.brand).filter(Boolean))].sort(),[M]),I=(0,y.useMemo)(()=>{let e=[...N];return m&&(e=e.filter(e=>e.group.material===m)),g&&(e=e.filter(e=>e.group.brand===g)),e.sort((e,t)=>{let n=0,r=0;switch(u){case`material`:n=[e.group.material,e.group.subtype??``,e.group.brand??``].join(` `).toLowerCase(),r=[t.group.material,t.group.subtype??``,t.group.brand??``].join(` `).toLowerCase();break;case`used`:n=e.totalUsedG,r=t.totalUsedG;break;case`days_left`:n=e.daysRemaining??999999,r=t.daysRemaining??999999;break;case`stock`:n=e.totalRemainingG,r=t.totalRemainingG;break}let i=nr);return f===`asc`?i:-i}),e},[N,u,f,m,g]),L=(0,y.useMemo)(()=>N.filter(e=>!e.settings?.alerts_snoozed&&(e.stockBreakAlert||e.reorderAlert)),[N]),R=(0,y.useMemo)(()=>[...N].filter(e=>e.dailyRateG!==null).sort((e,t)=>t.totalUsedG-e.totalUsedG).slice(0,5),[N]);if(!o)return(0,G.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-16 text-bambu-gray gap-3`,children:[(0,G.jsx)(nl,{className:`w-8 h-8 opacity-40`}),(0,G.jsx)(`p`,{className:`text-sm`,children:r(`forecast.noReadAccess`)})]});function z(e){u===e?p(e=>e===`asc`?`desc`:`asc`):(d(e),p(e===`days_left`?`asc`:`desc`))}let B=O.length>0?O.length:null;return(0,G.jsxs)(`div`,{className:`space-y-5`,children:[(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[L.length>0&&(0,G.jsxs)(`button`,{onClick:()=>l(e=>!e),className:`flex items-center gap-2 px-3 py-1.5 rounded-lg border text-sm font-medium transition-colors ${L.some(e=>e.stockBreakAlert)?`bg-red-100 dark:bg-red-500/15 border-red-300 dark:border-red-500/30 text-red-700 dark:text-red-300 hover:bg-red-200 dark:hover:bg-red-500/25`:`bg-yellow-100 dark:bg-yellow-500/15 border-yellow-300 dark:border-yellow-500/30 text-yellow-700 dark:text-yellow-300 hover:bg-yellow-200 dark:hover:bg-yellow-500/25`}`,children:[(0,G.jsx)(Lu,{className:`w-4 h-4`}),r(`forecast.alertCount`,{count:L.length}),c?(0,G.jsx)(gs,{className:`w-3.5 h-3.5`}):(0,G.jsx)(ps,{className:`w-3.5 h-3.5`})]}),s&&(0,G.jsx)(Q$e,{value:k,onSave:e=>{Z.updateSettings({forecast_global_lead_time_days:e}).then(()=>{t.invalidateQueries({queryKey:[`settings`]}),n(r(`forecast.globalLeadTimeSaved`),`success`)})}}),(0,G.jsxs)(`select`,{value:m,onChange:e=>h(e.target.value),className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${m?`bg-bambu-green/20 text-bambu-green border-bambu-green/30`:`bg-transparent text-bambu-gray border-bambu-dark-tertiary hover:bg-bambu-dark-tertiary`}`,children:[(0,G.jsx)(`option`,{value:``,children:r(`inventory.material`)}),P.map(e=>(0,G.jsx)(`option`,{value:e,children:e},e))]}),(0,G.jsxs)(`select`,{value:g,onChange:e=>_(e.target.value),className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${g?`bg-bambu-green/20 text-bambu-green border-bambu-green/30`:`bg-transparent text-bambu-gray border-bambu-dark-tertiary hover:bg-bambu-dark-tertiary`}`,children:[(0,G.jsx)(`option`,{value:``,children:r(`inventory.brand`)}),F.map(e=>(0,G.jsx)(`option`,{value:e,children:e},e))]}),(0,G.jsxs)(`button`,{onClick:()=>S(e=>!e),className:`relative flex items-center gap-2 px-3 py-1.5 rounded-lg border border-bambu-dark-tertiary text-bambu-gray hover:bg-bambu-dark-tertiary text-sm transition-colors ml-auto`,children:[(0,G.jsx)(cu,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:r(`forecast.shoppingList`)}),B&&(0,G.jsx)(`span`,{className:`absolute -top-1.5 -right-1.5 w-4 h-4 rounded-full bg-bambu-green text-white text-[10px] font-bold flex items-center justify-center`,children:B})]})]}),c&&L.length>0&&(0,G.jsx)(`div`,{className:`space-y-2`,children:L.map(e=>(0,G.jsx)(Y$e,{forecast:e,onCart:()=>b(e)},e.group.key))}),x&&(0,G.jsx)(r1e,{items:O,forecasts:N,globalLeadTime:k,canWrite:s,onClose:()=>S(!1),onRemove:e=>{Z.removeFromShoppingList(e).then(()=>t.invalidateQueries({queryKey:[`shopping-list`]})).catch(()=>n(r(`forecast.failedSaveSettings`),`error`))},onClear:()=>{Z.clearShoppingList().then(()=>t.invalidateQueries({queryKey:[`shopping-list`]})).catch(()=>n(r(`forecast.failedSaveSettings`),`error`))}}),R.length>0&&(0,G.jsx)(Z$e,{forecasts:R,days:C,onDaysChange:w}),N.length===0?(0,G.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-16 text-bambu-gray`,children:[(0,G.jsx)(Fu,{className:`w-10 h-10 mb-3 opacity-40`}),(0,G.jsx)(`p`,{className:`text-sm`,children:r(`forecast.noSpools`)})]}):(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg overflow-hidden border border-bambu-dark-tertiary`,children:[(0,G.jsx)(`div`,{className:`overflow-x-auto`,children:(0,G.jsxs)(`table`,{className:`w-full`,children:[(0,G.jsx)(`thead`,{children:(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary bg-bambu-dark-tertiary/30`,children:[(0,G.jsx)(`th`,{className:`w-8 px-4 py-3`}),(0,G.jsx)(d9,{col:`material`,active:u,dir:f,onSort:z,children:r(`forecast.sku`)}),(0,G.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:r(`locations.spools`)}),(0,G.jsx)(d9,{col:`stock`,active:u,dir:f,onSort:z,children:r(`forecast.stock`)}),(0,G.jsx)(d9,{col:`used`,active:u,dir:f,onSort:z,children:r(`forecast.dailyRate`)}),(0,G.jsx)(d9,{col:`days_left`,active:u,dir:f,onSort:z,children:r(`forecast.daysLeft`)}),(0,G.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:r(`forecast.emptyBy`)}),(0,G.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:r(`forecast.reorderBy`)}),(0,G.jsx)(`th`,{className:`w-24 px-4 py-3`})]})}),(0,G.jsx)(`tbody`,{className:`divide-y divide-bambu-dark-tertiary`,children:I.map(e=>(0,G.jsx)($$e,{forecast:e,globalLeadTime:k,canWrite:s,onSaved:()=>t.invalidateQueries({queryKey:[`sku-settings`]}),onCart:()=>b(e),showToast:n},e.group.key))})]})}),(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4 px-4 py-3 text-xs text-bambu-gray border-t border-bambu-dark-tertiary bg-bambu-dark-tertiary/20`,children:[(0,G.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,G.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-bambu-green inline-block`}),r(`forecast.trendLegend`)]}),(0,G.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,G.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-blue-400 inline-block`}),r(`forecast.estimatedLegend`)]}),(0,G.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,G.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-bambu-gray/40 inline-block`}),r(`forecast.noDataLegend`)]})]})]}),v&&(0,G.jsx)(a1e,{forecast:v,onClose:()=>b(null),onAdd:e=>{Z.addToShoppingList(e).then(()=>{t.invalidateQueries({queryKey:[`shopping-list`]}),n(r(`forecast.addedToCart`),`success`),b(null),S(!0)}).catch(()=>n(r(`forecast.failedAddItem`),`error`))}})]})}function d9({col:e,active:t,dir:n,onSort:r,children:i}){return(0,G.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide cursor-pointer select-none hover:text-white transition-colors`,onClick:()=>r(e),children:(0,G.jsxs)(`span`,{className:`inline-flex items-center`,children:[i,t===e?n===`asc`?(0,G.jsx)(Ho,{className:`w-3 h-3 ml-1 text-bambu-green`}):(0,G.jsx)(Io,{className:`w-3 h-3 ml-1 text-bambu-green`}):(0,G.jsx)(Bo,{className:`w-3 h-3 ml-1 opacity-40`})]})})}function Y$e({forecast:e,onCart:t}){let{t:n}=U(),r=[e.group.brand,e.group.material,e.group.subtype,e.group.colorName].filter(Boolean).join(` `),i=e.stockBreakAlert;return(0,G.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-3 rounded-lg border text-sm ${i?`bg-red-50 dark:bg-red-500/10 border-red-300 dark:border-red-500/30 text-red-700 dark:text-red-300`:`bg-yellow-50 dark:bg-yellow-500/10 border-yellow-300 dark:border-yellow-500/30 text-yellow-700 dark:text-yellow-300`}`,children:[(0,G.jsx)(Lu,{className:`w-4 h-4 flex-shrink-0`}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`span`,{className:`font-medium`,children:r}),i?(0,G.jsxs)(`span`,{className:`ml-2 text-xs opacity-80`,children:[n(`forecast.stockBreakRisk`),` — `,n(`forecast.stockBreakDetail`,{days:e.daysRemaining,lt:e.effectiveLeadTimeDays})]}):(0,G.jsxs)(`span`,{className:`ml-2 text-xs opacity-80`,children:[n(`forecast.reorderNow`),` — `,n(`forecast.reorderTriggerPassed`,{date:e.reorderTriggerDate?l9(e.reorderTriggerDate):`—`})]})]}),(0,G.jsxs)(`button`,{onClick:t,className:`flex items-center gap-1.5 px-2.5 py-1 rounded border border-current text-xs opacity-70 hover:opacity-100 transition-opacity`,children:[(0,G.jsx)(cu,{className:`w-3 h-3`}),` `,n(`forecast.order`)]})]})}var X$e=[{label:`1W`,value:7},{label:`1M`,value:30},{label:`6M`,value:180}];function Z$e({forecasts:e,days:t,onDaysChange:n}){let{t:r}=U(),i=Array.from({length:t+1},(e,t)=>t),a=e.map((e,n)=>({key:e.group.key,label:[e.group.brand,e.group.material,e.group.subtype,e.group.colorName].filter(Boolean).join(` `),color:W$e[n%W$e.length],rop:e.reorderPointG,points:q$e(e,t)})),o=i.map(e=>{let t={day:e,label:u9(c9(new Date,e))};for(let n of a){let r=n.points.find(t=>t.day===e);t[n.key]=r?.stock??0}return t}),s=(()=>{for(let e=t;e>=0;e--)if(a.some(t=>o[e]?.[t.key]>0))return e;return t})(),c=o.slice(0,s+1),l=a.filter(e=>e.rop>0);return(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg overflow-hidden border border-bambu-dark-tertiary p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-4`,children:[(0,G.jsx)(Fu,{className:`w-4 h-4 text-bambu-green`}),(0,G.jsx)(`h3`,{className:`text-sm font-semibold text-white`,children:r(`forecast.chartTitle`)}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray ml-1 hidden sm:inline`,children:r(`forecast.dashedLinesROP`)}),(0,G.jsx)(`div`,{className:`ml-auto flex items-center bg-bambu-dark-tertiary rounded-lg p-0.5`,children:X$e.map(e=>(0,G.jsx)(`button`,{onClick:()=>n(e.value),className:`px-2.5 py-1 text-xs font-medium rounded-md transition-colors ${t===e.value?`bg-bambu-dark-secondary text-white shadow`:`text-bambu-gray hover:text-white`}`,children:e.label},e.value))})]}),(0,G.jsx)(rA,{width:`100%`,height:220,children:(0,G.jsxs)(uH,{data:c,margin:{top:4,right:8,bottom:0,left:0},children:[(0,G.jsx)(`defs`,{children:a.map(e=>(0,G.jsxs)(`linearGradient`,{id:`grad-${e.key}`,x1:`0`,y1:`0`,x2:`0`,y2:`1`,children:[(0,G.jsx)(`stop`,{offset:`5%`,stopColor:e.color,stopOpacity:.25}),(0,G.jsx)(`stop`,{offset:`95%`,stopColor:e.color,stopOpacity:.02})]},e.key))}),(0,G.jsx)(WB,{strokeDasharray:`3 3`,stroke:`#374151`,strokeOpacity:.5}),(0,G.jsx)(bV,{dataKey:`label`,tick:{fill:`#6B7280`,fontSize:10},interval:Math.max(0,Math.ceil(s/8)-1),axisLine:!1,tickLine:!1}),(0,G.jsx)(TV,{tick:{fill:`#6B7280`,fontSize:10},axisLine:!1,tickLine:!1,tickFormatter:e=>e>=1e3?`${(e/1e3).toFixed(1)}kg`:`${e}g`,width:48}),(0,G.jsx)(sz,{content:({label:e,payload:t})=>t?.length?(0,G.jsxs)(`div`,{style:{background:`#1a1a2e`,border:`1px solid #374151`,borderRadius:8,fontSize:12,padding:`8px 12px`},children:[(0,G.jsx)(`div`,{style:{color:`#9CA3AF`,marginBottom:6},children:e}),t.map(e=>{let t=a.find(t=>t.key===String(e.dataKey));return typeof e.value==`number`?(0,G.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:6,color:`#E5E7EB`,marginBottom:2},children:[(0,G.jsx)(`span`,{style:{color:t?.color??`#9CA3AF`,fontSize:10},children:`●`}),(0,G.jsx)(`span`,{children:t?.label??String(e.dataKey)}),(0,G.jsxs)(`span`,{style:{color:`#9CA3AF`,marginLeft:4},children:[e.value,`g`]})]},String(e.dataKey)):null})]}):null}),(0,G.jsx)(cj,{formatter:e=>(0,G.jsx)(`span`,{style:{color:`#9CA3AF`,fontSize:11},children:a.find(t=>t.key===e)?.label??e})}),a.map(e=>(0,G.jsx)(rV,{type:`monotone`,dataKey:e.key,stroke:e.color,strokeWidth:2,fill:`url(#grad-${e.key})`,dot:!1,activeDot:{r:3}},e.key)),l.map(e=>(0,G.jsx)(NB,{y:e.rop,stroke:e.color,strokeDasharray:`4 3`,strokeOpacity:.6},`rop-${e.key}`))]})})]})}function Q$e({value:e,onSave:t}){let{t:n}=U(),[r,i]=(0,y.useState)(!1),[a,o]=(0,y.useState)(String(e));function s(){let e=parseInt(a,10);isNaN(e)||e<0||(t(e),i(!1))}return(0,G.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-1.5 bg-bambu-dark-tertiary/40 rounded-lg border border-bambu-dark-tertiary text-xs text-bambu-gray`,children:[(0,G.jsx)(Wc,{className:`w-3.5 h-3.5 flex-shrink-0`,"aria-label":n(`forecast.globalLeadTimeHint`)}),(0,G.jsxs)(`span`,{className:`hidden sm:inline`,children:[n(`forecast.globalLeadTime`),`:`]}),r?(0,G.jsxs)(`form`,{className:`flex items-center gap-1.5`,onSubmit:e=>{e.preventDefault(),s()},children:[(0,G.jsx)(`input`,{type:`number`,min:0,max:365,value:a,onChange:e=>o(e.target.value),className:`w-14 px-1.5 py-0.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-sm text-white focus:outline-none focus:border-bambu-green`,autoFocus:!0}),(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:`d`}),(0,G.jsx)(`button`,{type:`submit`,className:`px-2 py-0.5 bg-bambu-green text-white text-xs rounded hover:bg-bambu-green/80`,children:n(`forecast.save`)}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>i(!1),className:`text-xs text-bambu-gray hover:text-white`,children:`✕`})]}):(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,G.jsxs)(`span`,{className:`font-semibold text-white`,children:[e,`d`]}),(0,G.jsx)(`button`,{onClick:()=>{o(String(e)),i(!0)},className:`p-0.5 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,G.jsx)(kl,{className:`w-3 h-3`})})]})]})}function $$e({forecast:e,globalLeadTime:t,canWrite:n,onSaved:r,onCart:i,showToast:a}){let{t:o}=U(),[s,c]=(0,y.useState)(!1),[l,u]=(0,y.useState)(!1),[d,f]=(0,y.useState)(!1),[p,m]=(0,y.useState)(String(e.settings?.lead_time_days??0)),[h,g]=(0,y.useState)(String(e.settings?.safety_margin_value??14)),[_,v]=(0,y.useState)(e.settings?.safety_margin_unit??`days`);(0,y.useEffect)(()=>{l||m(String(e.settings?.lead_time_days??0))},[e.settings?.lead_time_days,l]),(0,y.useEffect)(()=>{d||(g(String(e.settings?.safety_margin_value??14)),v(e.settings?.safety_margin_unit??`days`))},[e.settings?.safety_margin_value,e.settings?.safety_margin_unit,d]);let b=q({mutationFn:Z.upsertSkuSettings,onSuccess:()=>{r(),a(o(`forecast.settingsSaved`),`success`)},onError:()=>a(o(`forecast.failedSaveSettings`),`error`)}),x=e.settings?.alerts_snoozed??!1,S=[e.group.brand,e.group.material,e.group.subtype,e.group.colorName].filter(Boolean).join(` `),C=e.group.spools[0]?.rgba?Mf(e.group.spools[0].rgba):{backgroundColor:`#4B5563`},w=e.totalLabelG>0?Math.round(e.totalRemainingG/e.totalLabelG*100):0,T=x||e.daysRemaining===null?`text-bambu-gray`:e.stockBreakAlert?`text-red-700 dark:text-red-400`:e.reorderAlert||e.daysRemaining<30?`text-yellow-700 dark:text-yellow-400`:`text-green-700 dark:text-green-400`;function E(t,n,r,i=x){b.mutate({material:e.group.material,subtype:e.group.subtype,brand:e.group.brand,color_name:e.group.colorName,lead_time_days:t,safety_margin_value:n,safety_margin_unit:r,alerts_snoozed:i})}function D(t){t.stopPropagation(),E(e.settings?.lead_time_days??0,e.settings?.safety_margin_value??14,e.settings?.safety_margin_unit??`days`,!x)}let O=e.rateTier===`history`?(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-xs px-1.5 py-0.5 rounded bg-bambu-green/15 text-bambu-green`,children:[(0,G.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-bambu-green`}),o(`forecast.trend`)]}):e.rateTier===`delta`?(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-xs px-1.5 py-0.5 rounded bg-blue-100 dark:bg-blue-400/15 text-blue-700 dark:text-blue-400`,children:[(0,G.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-blue-400`}),o(`forecast.estimated`)]}):(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-xs px-1.5 py-0.5 rounded bg-bambu-dark-tertiary text-bambu-gray/60`,children:[(0,G.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-bambu-gray/40`}),o(`forecast.noData`)]});return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/50 cursor-pointer hover:bg-bambu-dark-tertiary/30 transition-colors ${x?``:e.stockBreakAlert?`bg-red-500/5`:e.reorderAlert?`bg-yellow-500/5`:``} ${x?`opacity-50`:``}`,onClick:()=>c(e=>!e),children:[(0,G.jsx)(`td`,{className:`px-4 py-3`,children:(0,G.jsx)(`span`,{className:`block w-5 h-5 rounded-full border border-black/20`,style:C})}),(0,G.jsx)(`td`,{className:`px-4 py-3`,children:(0,G.jsx)(`span`,{className:`text-sm text-white`,children:S})}),(0,G.jsx)(`td`,{className:`px-4 py-3`,children:(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.totalSpools})}),(0,G.jsx)(`td`,{className:`px-4 py-3 min-w-[140px]`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`div`,{className:`flex-1 h-2 bg-bambu-dark-tertiary rounded-full overflow-hidden`,children:(0,G.jsx)(`div`,{className:`h-full rounded-full ${w>50?`bg-bambu-green`:w>20?`bg-yellow-500`:`bg-red-500`}`,style:{width:`${Math.min(w,100)}%`}})}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray min-w-[40px] text-right`,children:[Math.round(e.totalRemainingG),`g`]})]})}),(0,G.jsx)(`td`,{className:`px-4 py-3`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 flex-wrap`,children:[(0,G.jsx)(`span`,{className:`text-sm text-white`,children:e.dailyRateG===null?`—`:`${e.dailyRateG.toFixed(1)}g/d`}),O]})}),(0,G.jsx)(`td`,{className:`px-4 py-3`,children:(0,G.jsx)(`span`,{className:`text-sm font-semibold ${T}`,children:e.daysRemaining===null?(0,G.jsx)(`span`,{className:`text-bambu-gray font-normal`,children:`—`}):`${e.daysRemaining}d`})}),(0,G.jsx)(`td`,{className:`px-4 py-3`,children:(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.projectedEmptyDate?l9(e.projectedEmptyDate):`—`})}),(0,G.jsx)(`td`,{className:`px-4 py-3`,children:(0,G.jsx)(`span`,{className:`text-sm ${!x&&e.reorderAlert?`text-yellow-700 dark:text-yellow-400`:`text-bambu-gray`}`,children:e.reorderTriggerDate?l9(e.reorderTriggerDate):`—`})}),(0,G.jsx)(`td`,{className:`px-4 py-3`,onClick:e=>e.stopPropagation(),children:(0,G.jsxs)(`div`,{className:`flex items-center justify-end gap-1`,children:[n&&(0,G.jsx)(`button`,{onClick:i,className:`p-1.5 text-bambu-gray hover:text-bambu-green rounded transition-colors`,title:o(`forecast.addToCart`),children:(0,G.jsx)(cu,{className:`w-4 h-4`})}),!x&&(e.stockBreakAlert?(0,G.jsx)(Lu,{className:`w-4 h-4 text-red-600 dark:text-red-400`,"aria-label":o(`forecast.stockBreakRisk`)}):e.reorderAlert?(0,G.jsx)(Lu,{className:`w-4 h-4 text-yellow-600 dark:text-yellow-400`,"aria-label":o(`forecast.reorderNow`)}):e.daysRemaining===null?null:(0,G.jsx)(fs,{className:`w-4 h-4 text-bambu-green/50`})),n&&(0,G.jsx)(`button`,{onClick:D,className:`p-1 rounded transition-colors ${x?`text-amber-600/80 dark:text-amber-400/80 hover:text-amber-700 dark:hover:text-amber-300`:`text-slate-400 hover:text-white`}`,title:o(x?`forecast.alertsEnabled`:`forecast.alertsSnoozed`),children:(0,G.jsx)(Ko,{className:`w-3.5 h-3.5`})}),(0,G.jsx)(`button`,{onClick:e=>{e.stopPropagation(),c(e=>!e)},className:`p-1.5 text-bambu-gray hover:text-white rounded transition-colors`,children:s?(0,G.jsx)(gs,{className:`w-4 h-4`}):(0,G.jsx)(ps,{className:`w-4 h-4`})})]})})]}),s&&(0,G.jsx)(`tr`,{className:`bg-bambu-dark-tertiary/10`,children:(0,G.jsx)(`td`,{colSpan:9,className:`px-6 py-4`,children:(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{className:`grid gap-2 ${n?`grid-cols-2 sm:grid-cols-4`:`grid-cols-2`}`,children:[(0,G.jsx)(e1e,{label:o(`forecast.effectiveLeadTime`),value:`${e.effectiveLeadTimeDays}d`,hint:o(`forecast.effectiveLeadTimeHint`,{global:t,sku:e.settings?.lead_time_days??0})}),(0,G.jsx)(e1e,{label:o(`forecast.reorderPoint`),value:`${Math.round(e.reorderPointG)}g`,hint:o(`forecast.reorderPointHint`)}),n&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(t1e,{label:o(`forecast.skuLeadTimeOverride`),hint:o(`forecast.skuLeadTimeHint`),unit:o(`forecast.leadTime`),editing:l,value:e.settings?.lead_time_days??0,inputValue:p,onInputChange:m,onEdit:()=>{m(String(e.settings?.lead_time_days??0)),u(!0)},onSave:()=>{let t=parseInt(p,10);!isNaN(t)&&t>=0&&(E(t,e.settings?.safety_margin_value??14,_),u(!1))},onCancel:()=>u(!1),isPending:b.isPending,saveLabel:o(`forecast.save`),cancelLabel:o(`forecast.cancel`)}),(0,G.jsx)(n1e,{value:e.settings?.safety_margin_value??14,unit:_,editing:d,inputValue:h,dailyRateG:e.dailyRateG,onInputChange:g,onUnitChange:e=>v(e),onEdit:()=>{g(String(e.settings?.safety_margin_value??14)),v(e.settings?.safety_margin_unit??`days`),f(!0)},onSave:()=>{let t=parseInt(h,10);!isNaN(t)&&t>=0&&(E(e.settings?.lead_time_days??0,t,_),f(!1))},onCancel:()=>f(!1),isPending:b.isPending,saveLabel:o(`forecast.save`),cancelLabel:o(`forecast.cancel`),safetyMarginLabel:o(`forecast.safetyMarginLabel`)})]})]}),e.group.spools.length>1&&(0,G.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary pt-3`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:o(`forecast.individualSpools`)}),(0,G.jsx)(`div`,{className:`bg-bambu-dark-secondary rounded-lg overflow-hidden border border-bambu-dark-tertiary`,children:(0,G.jsxs)(`table`,{className:`w-full`,children:[(0,G.jsx)(`thead`,{children:(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary bg-bambu-dark-tertiary/30`,children:[(0,G.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:`#`}),(0,G.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:o(`inventory.remaining`)}),(0,G.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:o(`inventory.used`)}),(0,G.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:o(`forecast.labelWeight`)})]})}),(0,G.jsx)(`tbody`,{className:`divide-y divide-bambu-dark-tertiary`,children:e.group.spools.map(e=>{let t=Math.max(0,e.label_weight-e.weight_used),n=e.label_weight>0?t/e.label_weight*100:0;return(0,G.jsxs)(`tr`,{className:`hover:bg-bambu-dark-tertiary/30 transition-colors`,children:[(0,G.jsx)(`td`,{className:`px-4 py-2`,children:(0,G.jsxs)(`span`,{className:`text-xs font-mono text-bambu-gray/70`,children:[`#`,e.id]})}),(0,G.jsx)(`td`,{className:`px-4 py-2`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`w-24 h-1.5 bg-bambu-dark-tertiary rounded-full overflow-hidden flex-shrink-0`,children:(0,G.jsx)(`div`,{className:`h-full rounded-full ${n>50?`bg-bambu-green`:n>20?`bg-yellow-500`:`bg-red-500`}`,style:{width:`${Math.min(n,100)}%`}})}),(0,G.jsxs)(`span`,{className:`text-sm text-white`,children:[Math.round(t),`g`]})]})}),(0,G.jsx)(`td`,{className:`px-4 py-2`,children:(0,G.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[Math.round(Math.max(0,e.weight_used-(e.weight_used_baseline??0))),`g`]})}),(0,G.jsx)(`td`,{className:`px-4 py-2`,children:(0,G.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[e.label_weight,`g`]})})]},e.id)})})]})})]})]})})})]})}function e1e({label:e,value:t,hint:n}){return(0,G.jsxs)(`div`,{className:`bg-bambu-dark-tertiary/40 rounded-lg p-3`,title:n,children:[(0,G.jsx)(`div`,{className:`text-xs font-medium text-white mb-1`,children:e}),(0,G.jsx)(`div`,{className:`text-lg font-semibold text-white`,children:t})]})}function t1e({label:e,hint:t,unit:n,editing:r,value:i,inputValue:a,onInputChange:o,onEdit:s,onSave:c,onCancel:l,isPending:u,saveLabel:d=`Save`,cancelLabel:f=`Cancel`}){return(0,G.jsxs)(`div`,{className:`bg-bambu-dark-tertiary/40 rounded-lg p-3 space-y-1`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,G.jsx)(`span`,{className:`text-xs font-medium text-white`,children:e}),(0,G.jsx)(`span`,{title:t,children:(0,G.jsx)(Wc,{className:`w-3 h-3 text-bambu-gray/50`})})]}),r?(0,G.jsxs)(`form`,{className:`flex items-center gap-2`,onSubmit:e=>{e.preventDefault(),c()},children:[(0,G.jsx)(`input`,{type:`number`,min:0,max:365,value:a,onChange:e=>o(e.target.value),className:`w-20 px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-sm text-white focus:outline-none focus:border-bambu-green`,autoFocus:!0,disabled:u}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:n}),(0,G.jsx)(`button`,{type:`submit`,disabled:u,className:`px-2 py-1 bg-bambu-green text-white text-xs rounded hover:bg-bambu-green/80 disabled:opacity-50`,children:d}),(0,G.jsx)(`button`,{type:`button`,onClick:l,disabled:u,className:`px-2 py-1 text-xs text-bambu-gray hover:text-white`,children:f})]}):(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-lg font-semibold text-white`,children:i}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:n}),(0,G.jsx)(`button`,{onClick:s,className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,G.jsx)(kl,{className:`w-3 h-3`})})]})]})}function n1e({value:e,unit:t,editing:n,inputValue:r,dailyRateG:i,onInputChange:a,onUnitChange:o,onEdit:s,onSave:c,onCancel:l,isPending:u,saveLabel:d=`Save`,cancelLabel:f=`Cancel`,safetyMarginLabel:p=`Safety Margin`}){let{t:m}=U(),h=t===`g`?e:i===null?null:Math.round(i*e),g=t===`days`?m(`forecast.safetyMarginHintDays`,{approx:h===null?``:m(`forecast.safetyMarginHintDaysApprox`,{g:h})}):m(`forecast.safetyMarginHintG`,{approx:i===null?``:m(`forecast.safetyMarginHintGApprox`,{days:Math.round(e/i)})});return(0,G.jsxs)(`div`,{className:`bg-bambu-dark-tertiary/40 rounded-lg p-3 space-y-1`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,G.jsx)(`span`,{className:`text-xs font-medium text-white`,children:p}),(0,G.jsx)(`span`,{title:g,children:(0,G.jsx)(Wc,{className:`w-3 h-3 text-bambu-gray/50`})})]}),n?(0,G.jsxs)(`form`,{className:`flex items-center gap-2 flex-wrap`,onSubmit:e=>{e.preventDefault(),c()},children:[(0,G.jsx)(`input`,{type:`number`,min:0,max:t===`g`?1e4:365,value:r,onChange:e=>a(e.target.value),className:`w-20 px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-sm text-white focus:outline-none focus:border-bambu-green`,autoFocus:!0,disabled:u}),(0,G.jsxs)(`div`,{className:`flex bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded overflow-hidden text-xs`,children:[(0,G.jsx)(`button`,{type:`button`,onClick:()=>o(`days`),className:`px-2 py-1 transition-colors ${t===`days`?`bg-bambu-green text-white`:`text-bambu-gray hover:text-white`}`,children:`days`}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>o(`g`),className:`px-2 py-1 transition-colors ${t===`g`?`bg-bambu-green text-white`:`text-bambu-gray hover:text-white`}`,children:`g`})]}),(0,G.jsx)(`button`,{type:`submit`,disabled:u,className:`px-2 py-1 bg-bambu-green text-white text-xs rounded hover:bg-bambu-green/80 disabled:opacity-50`,children:d}),(0,G.jsx)(`button`,{type:`button`,onClick:l,disabled:u,className:`px-2 py-1 text-xs text-bambu-gray hover:text-white`,children:f})]}):(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-lg font-semibold text-white`,children:e}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:t}),h!==null&&t===`days`&&(0,G.jsxs)(`span`,{className:`text-lg font-semibold text-white`,children:[`≈ `,h,`g`]}),t===`g`&&i!==null&&(0,G.jsxs)(`span`,{className:`text-lg font-semibold text-white`,children:[`≈ `,Math.round(e/i),`d`]}),(0,G.jsx)(`button`,{onClick:s,className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,G.jsx)(kl,{className:`w-3 h-3`})})]})]})}function r1e({items:e,forecasts:t,globalLeadTime:n,canWrite:r,onClose:i,onRemove:a,onClear:o}){let{t:s}=U(),c=co(),[l,u]=(0,y.useState)(`list`),d=q({mutationFn:async({id:e,status:t,item:n,avgSpoolG:r})=>{if(await Z.updateShoppingListStatus(e,t),t===`received`&&n){let t=r??1e3,i={material:n.material,subtype:n.subtype,brand:n.brand,label_weight:t,core_weight:0,core_weight_catalog_id:null,color_name:n.color_name,rgba:null,extra_colors:null,effect_type:null,nozzle_temp_min:null,nozzle_temp_max:null,note:n.note??null,tag_uid:null,tray_uuid:null,data_origin:`manual`,tag_type:null,cost_per_kg:null,last_scale_weight:null,last_weighed_at:null,weight_used:0,slicer_filament:null,slicer_filament_name:null,added_full:null,last_used:null,encode_time:null,category:`Stock`,low_stock_threshold_pct:null};await Z.bulkCreateSpools(i,n.quantity_spools),await Z.removeFromShoppingList(e)}},onSuccess:()=>{c.invalidateQueries({queryKey:[`shopping-list`]}),c.invalidateQueries({queryKey:[`spools`]})}}),f=(0,y.useMemo)(()=>{let e=new Map;for(let n of t)e.set(n.group.key,n);return e},[t]),p=(0,y.useMemo)(()=>e.map(e=>({item:e,forecast:f.get(s9(e.material,e.subtype,e.brand,e.color_name))??null})),[e,f]),m=(0,y.useMemo)(()=>p.filter(({forecast:e})=>!e||e.dailyRateG===null?!1:e.stockBreakAlert||e.daysRemaining!==null&&e.daysRemaining<=e.effectiveLeadTimeDays),[p]);function h(){let t=[s(`forecast.qty`),s(`forecast.material`),s(`inventory.brand`),s(`inventory.subtype`),s(`inventory.color`),`${s(`forecast.weight`)} (g)`,`${s(`forecast.leadTime`)} (d)`,s(`forecast.expectedRestock`),s(`forecast.status`),s(`forecast.note`)],r=e.map(e=>{let t=f.get(s9(e.material,e.subtype,e.brand,e.color_name))??null,r=t&&t.totalSpools>0?t.totalLabelG/t.totalSpools:1e3,i=Math.round(e.quantity_spools*r),a=t?.effectiveLeadTimeDays??n??0,o=a>0?l9(c9(new Date,a)):``;return[e.quantity_spools,e.material,e.brand??``,e.subtype??``,e.color_name??``,i,a||``,o,e.status,e.note??``].map(e=>`"${String(e).replace(/"/g,`""`)}"`).join(`,`)}),i=[t.join(`,`),...r].join(` -`),a=new Blob([i],{type:`text/csv`}),o=URL.createObjectURL(a),c=document.createElement(`a`);c.href=o,c.download=`shopping-list-${new Date().toISOString().slice(0,10)}.csv`,c.click(),setTimeout(()=>URL.revokeObjectURL(o),100)}return(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg overflow-hidden border border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 border-b border-bambu-dark-tertiary bg-bambu-dark-tertiary/30`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(cu,{className:`w-4 h-4 text-bambu-green`}),(0,G.jsx)(`h3`,{className:`text-sm font-semibold text-white`,children:s(`forecast.shoppingList`)}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:s(`forecast.shoppingListItems`,{count:e.length})}),e.length>0&&(0,G.jsxs)(`div`,{className:`flex bg-bambu-dark-tertiary rounded-md p-0.5 ml-1`,children:[(0,G.jsxs)(`button`,{onClick:()=>u(`list`),className:`flex items-center gap-1.5 px-2 py-0.5 text-xs font-medium rounded transition-colors ${l===`list`?`bg-bambu-dark-secondary text-white shadow`:`text-bambu-gray hover:text-white`}`,children:[(0,G.jsx)(Cl,{className:`w-3 h-3`}),s(`forecast.listView`)]}),(0,G.jsxs)(`button`,{onClick:()=>u(`logistics`),className:`flex items-center gap-1.5 px-2 py-0.5 text-xs font-medium rounded transition-colors ${l===`logistics`?`bg-bambu-dark-secondary text-white shadow`:`text-bambu-gray hover:text-white`}`,children:[(0,G.jsx)(us,{className:`w-3 h-3`}),s(`forecast.logisticsView`),m.length>0&&(0,G.jsx)(`span`,{className:`w-3.5 h-3.5 rounded-full bg-red-500 text-white text-[9px] font-bold flex items-center justify-center`,children:m.length})]})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.length>0&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`button`,{onClick:h,className:`flex items-center gap-1.5 text-xs text-bambu-gray hover:text-white transition-colors px-2 py-1 rounded border border-bambu-dark-tertiary hover:bg-bambu-dark-tertiary`,children:[(0,G.jsx)(Xs,{className:`w-3 h-3`}),s(`forecast.downloadCsv`)]}),r&&(0,G.jsx)(`button`,{onClick:o,className:`text-xs text-red-700 dark:text-red-400 hover:text-red-800 dark:hover:text-red-300 transition-colors px-2 py-1 rounded border border-red-200 dark:border-red-500/20 hover:bg-red-50 dark:hover:bg-red-500/10`,children:s(`forecast.clearAll`)})]}),(0,G.jsx)(`button`,{onClick:i,className:`p-1 text-bambu-gray hover:text-white transition-colors`,children:(0,G.jsx)(nd,{className:`w-4 h-4`})})]})]}),e.length===0?(0,G.jsxs)(`div`,{className:`flex flex-col items-center py-8 text-bambu-gray`,children:[(0,G.jsx)(Cl,{className:`w-8 h-8 mb-2 opacity-30`}),(0,G.jsx)(`p`,{className:`text-sm`,children:s(`forecast.shoppingListEmpty`)})]}):l===`list`?(0,G.jsx)(`div`,{className:`overflow-x-auto`,children:(0,G.jsxs)(`table`,{className:`w-full`,children:[(0,G.jsx)(`thead`,{children:(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary bg-bambu-dark-tertiary/20`,children:[(0,G.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:s(`forecast.qty`)}),(0,G.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:s(`forecast.material`)}),(0,G.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:s(`forecast.weight`)}),(0,G.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:s(`forecast.leadTime`)}),(0,G.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:s(`forecast.expectedRestock`)}),(0,G.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:s(`forecast.status`)}),(0,G.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:s(`forecast.note`)}),(0,G.jsx)(`th`,{className:`px-4 py-2 text-right text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:s(`forecast.actions`)})]})}),(0,G.jsx)(`tbody`,{className:`divide-y divide-bambu-dark-tertiary`,children:e.map(e=>{let t=[e.brand,e.material,e.subtype,e.color_name].filter(Boolean).join(` `),i=m.some(t=>t.item.id===e.id),o=f.get(s9(e.material,e.subtype,e.brand,e.color_name))??null,c=o&&o.totalSpools>0?o.totalLabelG/o.totalSpools:1e3,l=Math.round(e.quantity_spools*c),u=o?.effectiveLeadTimeDays??n??0,p=u>0?c9(new Date,u):null,h=e.status===`purchased`||e.status===`received`,g=e.status===`received`,_=d.isPending;return(0,G.jsxs)(`tr`,{className:`hover:bg-bambu-dark-tertiary/30 transition-colors ${i&&!h?`bg-red-500/5`:``}`,children:[(0,G.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,G.jsxs)(`span`,{className:`text-sm font-semibold text-bambu-green`,children:[e.quantity_spools,`×`]})}),(0,G.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-sm text-white`,children:t}),i&&!h&&(0,G.jsx)(Lu,{className:`w-3.5 h-3.5 text-red-600 dark:text-red-400 flex-shrink-0`,"aria-label":s(`forecast.stockBreakBefore`)})]})}),(0,G.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,G.jsx)(`span`,{className:`text-sm text-white`,children:l>=1e3?`${(l/1e3).toFixed(1)}kg`:`${l}g`})}),(0,G.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:u>0?`${u}d`:`—`})}),(0,G.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:p?l9(p):`—`})}),(0,G.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,G.jsx)(`span`,{className:`inline-flex items-center px-2 py-0.5 rounded text-xs font-medium ${g?`bg-bambu-green/20 text-bambu-green`:h?`bg-blue-100 dark:bg-blue-400/20 text-blue-700 dark:text-blue-400`:`bg-bambu-dark-tertiary text-bambu-gray`}`,children:s(g?`forecast.received`:h?`forecast.purchased`:`forecast.pending`)})}),(0,G.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:e.note||`—`})}),(0,G.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,G.jsx)(`div`,{className:`flex items-center justify-end gap-1`,children:r&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`button`,{onClick:()=>d.mutate({id:e.id,status:h?`pending`:`purchased`}),disabled:_||g,title:s(h?`forecast.resetToPending`:`forecast.markPurchased`),className:`p-1.5 rounded transition-colors disabled:opacity-30 ${h?`text-blue-600 dark:text-blue-400 hover:text-blue-700 dark:hover:text-blue-300`:`text-blue-600/50 dark:text-blue-400/50 hover:text-blue-600 dark:hover:text-blue-400`}`,children:h?(0,G.jsx)(Wl,{className:`w-4 h-4`}):(0,G.jsx)(Us,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:()=>d.mutate({id:e.id,status:`received`,item:e,avgSpoolG:c}),disabled:_||!h||g,title:s(`forecast.markReceived`),className:`p-1.5 rounded transition-colors text-bambu-green/50 hover:text-bambu-green disabled:opacity-30`,children:(0,G.jsx)(xl,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:()=>a(e.id),className:`p-1 text-bambu-gray hover:text-red-600 dark:hover:text-red-400 transition-colors`,title:s(`forecast.remove`),children:(0,G.jsx)(Pu,{className:`w-3.5 h-3.5`})})]})})})]},e.id)})})]})}):(0,G.jsx)(`div`,{className:`divide-y divide-bambu-dark-tertiary`,children:p.filter(({item:e})=>e.status!==`received`).map(({item:e,forecast:t})=>(0,G.jsx)(i1e,{item:e,forecast:t,globalLeadTime:n,canWrite:r,onRemove:()=>a(e.id)},e.id))})]})}function i1e({item:e,forecast:t,globalLeadTime:n,canWrite:r,onRemove:i}){let{t:a}=U(),o=[e.brand,e.material,e.subtype,e.color_name].filter(Boolean).join(` `),s=(0,y.useMemo)(()=>{if(!t||t.dailyRateG===null||t.dailyRateG<=0)return null;let n=t.dailyRateG,r=t.effectiveLeadTimeDays,i=t.totalSpools>0?t.totalLabelG/t.totalSpools:1e3,a=e.quantity_spools*i,o=Math.max(0,t.totalRemainingG-n*r),s=o+a,c=Math.ceil(s/n),l=Math.min(r+c+5,365),u=[];for(let e=0;e<=l;e++){let i=u9(c9(new Date,e));if(e===r)u.push({day:e,label:i,stock:Math.round(o),rop:Math.round(t.reorderPointG),safetyStock:Math.round(t.safetyStockG)}),u.push({day:e,label:i,stock:Math.round(s),rop:Math.round(t.reorderPointG),safetyStock:Math.round(t.safetyStockG),arrival:!0});else{let a=e{if(!t||t.dailyRateG===null||t.dailyRateG<=0)return null;let e=Math.floor(t.totalRemainingG/t.dailyRateG);return ee>=1e3?`${(e/1e3).toFixed(1)}kg`:`${e}g`,width:44}),(0,G.jsx)(sz,{contentStyle:{background:`#1a1a2e`,border:`1px solid #374151`,borderRadius:8,fontSize:11},labelStyle:{color:`#9CA3AF`},formatter:(e,t)=>typeof e==`number`?t===`stock`?`${e}g — ${a(`forecast.stock`)}`:t===`rop`?`${e}g — ${a(`forecast.reorderPoint`)}`:t===`safetyStock`?`${e}g — ${a(`forecast.safetyMarginLabel`)}`:`${e}`:``}),(0,G.jsx)(rV,{type:`linear`,dataKey:`stock`,stroke:`#1DB954`,strokeWidth:2,fill:`url(#cart-post-${e.id})`,dot:!1,activeDot:{r:3}}),t.reorderPointG>0&&(0,G.jsx)(NB,{y:t.reorderPointG,stroke:`#F59E0B`,strokeDasharray:`5 3`,strokeOpacity:.8,label:{value:`ROP`,position:`insideTopRight`,fill:`#F59E0B`,fontSize:9}}),t.safetyStockG>0&&(0,G.jsx)(NB,{y:t.safetyStockG,stroke:`#6B7280`,strokeDasharray:`3 3`,strokeOpacity:.6,label:{value:`SS`,position:`insideTopRight`,fill:`#6B7280`,fontSize:9}}),(0,G.jsx)(NB,{x:u9(c9(new Date,s.lt)),stroke:`#3B82F6`,strokeWidth:1.5,strokeDasharray:`4 3`,strokeOpacity:.9,label:{value:`+${s.arrivalG>=1e3?`${(s.arrivalG/1e3).toFixed(1)}kg`:`${Math.round(s.arrivalG)}g`} arrives (d${s.lt})`,position:`insideTopLeft`,fill:`#3B82F6`,fontSize:9}}),c!==null&&(0,G.jsx)(NB,{x:u9(c9(new Date,c)),stroke:`#EF4444`,strokeWidth:1.5,strokeOpacity:.9,label:{value:`OUT`,position:`insideTopLeft`,fill:`#EF4444`,fontSize:9}})]})}),(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 mt-2 text-[10px] text-bambu-gray`,children:[(0,G.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(`span`,{className:`inline-block w-4 border-t-2 border-yellow-400 border-dashed`}),` `,a(`forecast.ropLabel`)]}),(0,G.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(`span`,{className:`inline-block w-4 border-t border-bambu-gray border-dashed`}),` `,a(`forecast.safetyStockLegend`)]}),(0,G.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(`span`,{className:`inline-block w-4 border-t-2 border-blue-400 border-dashed`}),` `,a(`forecast.stockArrivalLegend`)]}),l&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-red-700 dark:text-red-400`,children:[(0,G.jsx)(`span`,{className:`inline-block w-4 border-t-2 border-red-400`}),` `,a(`forecast.stockoutLegend`)]})]})]}):null]})}function a1e({forecast:e,onClose:t,onAdd:n}){let{t:r}=U(),i=[e.group.brand,e.group.material,e.group.subtype,e.group.colorName].filter(Boolean).join(` `),[a,o]=(0,y.useState)(`qty`),[s,c]=(0,y.useState)(`1`),[l,u]=(0,y.useState)(`30`),[d,f]=(0,y.useState)(``),p=(0,y.useMemo)(()=>{if(!e.dailyRateG||e.dailyRateG<=0)return null;let t=e.dailyRateG*Number(l),n=e.group.spools.length>0?e.group.spools.reduce((e,t)=>e+t.label_weight,0)/e.group.spools.length:1e3;return Math.ceil(t/n)},[e,l]),m=a===`qty`?parseInt(s,10)||1:p??1;function h(t){t.preventDefault(),n({material:e.group.material,subtype:e.group.subtype,brand:e.group.brand,color_name:e.group.colorName,quantity_spools:m,note:d||null})}return(0,G.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm p-4`,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-2xl border border-bambu-dark-tertiary w-full max-w-sm shadow-2xl`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-5 pt-5 pb-4 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(cu,{className:`w-5 h-5 text-bambu-green`}),(0,G.jsx)(`h2`,{className:`text-base font-semibold text-white`,children:r(`forecast.addToCartTitle`)})]}),(0,G.jsx)(`button`,{onClick:t,className:`p-1 text-bambu-gray hover:text-white transition-colors`,children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]}),(0,G.jsxs)(`form`,{onSubmit:h,className:`p-5 space-y-4`,children:[(0,G.jsx)(`div`,{className:`text-sm text-bambu-gray`,children:i}),(0,G.jsxs)(`div`,{className:`flex bg-bambu-dark-tertiary rounded-lg p-0.5`,children:[(0,G.jsx)(`button`,{type:`button`,onClick:()=>o(`qty`),className:`flex-1 py-1.5 text-xs font-medium rounded-md transition-colors ${a===`qty`?`bg-bambu-dark-secondary text-white shadow`:`text-bambu-gray hover:text-white`}`,children:r(`forecast.byQuantity`)}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>o(`duration`),className:`flex-1 py-1.5 text-xs font-medium rounded-md transition-colors ${a===`duration`?`bg-bambu-dark-secondary text-white shadow`:`text-bambu-gray hover:text-white`}`,children:r(`forecast.byDuration`)})]}),a===`qty`?(0,G.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,G.jsx)(`label`,{className:`text-xs text-bambu-gray`,children:r(`forecast.numberOfSpools`)}),(0,G.jsx)(`input`,{type:`number`,min:1,max:99,value:s,onChange:e=>c(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`,autoFocus:!0})]}):(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,G.jsx)(`label`,{className:`text-xs text-bambu-gray`,children:r(`forecast.lastHowManyDays`)}),(0,G.jsx)(`input`,{type:`number`,min:1,max:365,value:l,onChange:e=>u(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`,autoFocus:!0})]}),e.dailyRateG===null?(0,G.jsx)(`div`,{className:`text-xs text-yellow-700 dark:text-yellow-400 px-1`,children:r(`forecast.noUsageQty`)}):(0,G.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2 bg-bambu-dark-tertiary/50 rounded-lg`,children:[(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:`≈`}),(0,G.jsx)(`span`,{className:`text-sm font-semibold text-bambu-green`,children:r(`forecast.spoolCount`,{count:p??0})}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[`at `,e.dailyRateG.toFixed(1),`g/day`]})]})]}),(0,G.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,G.jsx)(`label`,{className:`text-xs text-bambu-gray`,children:r(`forecast.noteOptional`)}),(0,G.jsx)(`input`,{type:`text`,maxLength:200,value:d,onChange:e=>f(e.target.value),placeholder:r(`forecast.notePlaceholder`),className:`w-full px-3 py-2 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/40 focus:outline-none focus:border-bambu-green`})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-3 pt-1`,children:[(0,G.jsx)(`button`,{type:`submit`,className:`flex-1 py-2 bg-bambu-green text-white text-sm font-medium rounded-lg hover:bg-bambu-green/80 transition-colors`,children:r(`forecast.addNSpools`,{count:m})}),(0,G.jsx)(`button`,{type:`button`,onClick:t,className:`px-4 py-2 text-sm text-bambu-gray hover:text-white border border-bambu-dark-tertiary rounded-lg transition-colors`,children:r(`forecast.cancel`)})]})]})]})})}var f9={material:``,subtype:``,brand:``,color_name:``,rgba:`808080FF`,extra_colors:``,effect_type:``,label_weight:1e3,core_weight:250,core_weight_catalog_id:null,weight_used:0,slicer_filament:``,note:``,cost_per_kg:null,category:``,low_stock_threshold_pct:null,location_id:null,spoolman_filament_id:null},o1e=new Set([`material`,`subtype`,`brand`,`rgba`,`color_name`,`label_weight`]);function s1e(e,t=!1,n=!1,r=`create`){let i={};return t||n||r!==`create`?(!e.material&&!e.spoolman_filament_id&&(i.material=`Material is required`),{isValid:Object.keys(i).length===0,errors:i}):(e.slicer_filament||(i.slicer_filament=`Slicer preset is required`),e.material||(i.material=`Material is required`),e.brand||(i.brand=`Brand is required`),e.subtype||(i.subtype=`Subtype is required`),{isValid:Object.keys(i).length===0,errors:i})}var c1e={local:`bg-green-100 dark:bg-green-500/20 text-green-700 dark:text-green-400`,orca_cloud:`bg-purple-100 dark:bg-purple-500/20 text-purple-700 dark:text-purple-400`,cloud:`bg-bambu-blue/20 text-bambu-blue`,builtin:`bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-400`};function p9({source:e}){let{t}=U(),n={local:t(`profiles.localProfiles.badge`),orca_cloud:t(`configureAmsSlot.orcaCloud`),cloud:t(`configureAmsSlot.bambuCloud`),builtin:t(`configureAmsSlot.builtin`)}[e];return(0,G.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded whitespace-nowrap ${c1e[e]}`,children:n})}function l1e({value:e,options:t,inheritLabel:n,onChange:r,disabled:i=!1,ariaLabel:a}){let{t:o}=U(),[s,c]=(0,y.useState)(!1),[l,u]=(0,y.useState)(``),d=(0,y.useRef)(null),f=t.find(t=>t.code===e);(0,y.useEffect)(()=>{if(!s)return;let e=e=>{d.current&&!d.current.contains(e.target)&&c(!1)},t=e=>{e.key===`Escape`&&(e.stopPropagation(),c(!1))};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t,!0),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t,!0)}},[s]);let p=l.trim().toLowerCase(),m=p?t.filter(e=>e.displayName.toLowerCase().includes(p)):t,h=e=>{r(e),c(!1),u(``)};return(0,G.jsxs)(`div`,{className:`relative`,ref:d,children:[(0,G.jsxs)(`button`,{type:`button`,"aria-label":a,"aria-haspopup":`listbox`,"aria-expanded":s,disabled:i,onClick:()=>c(e=>!e),className:`w-full flex items-center gap-2 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-sm text-left focus:outline-none focus:border-bambu-green disabled:opacity-50`,children:[(0,G.jsx)(`span`,{className:`flex-1 min-w-0 truncate ${f?`text-white`:`text-bambu-gray italic`}`,children:f?f.displayName:n}),f&&(0,G.jsx)(p9,{source:f.source}),(0,G.jsx)(ps,{className:`w-3.5 h-3.5 text-bambu-gray shrink-0`})]}),s&&(0,G.jsxs)(`div`,{className:`absolute z-50 mt-1 w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl`,children:[(0,G.jsx)(`div`,{className:`p-2 border-b border-bambu-dark-tertiary`,children:(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(Ql,{className:`w-3.5 h-3.5 text-bambu-gray absolute left-2 top-1/2 -translate-y-1/2`}),(0,G.jsx)(`input`,{autoFocus:!0,type:`text`,value:l,onChange:e=>u(e.target.value),placeholder:o(`inventory.searchPresets`),className:`w-full pl-7 pr-7 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded-md text-sm text-white placeholder:text-bambu-gray/60 focus:outline-none focus:border-bambu-green`}),l&&(0,G.jsx)(`button`,{type:`button`,"aria-label":o(`common.clear`),onClick:()=>u(``),className:`absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white`,children:(0,G.jsx)(nd,{className:`w-3.5 h-3.5`})})]})}),(0,G.jsxs)(`div`,{className:`max-h-56 overflow-y-auto p-1`,role:`listbox`,"aria-label":a,children:[(0,G.jsx)(`button`,{type:`button`,role:`option`,"aria-selected":!f,onClick:()=>h(null),className:`w-full text-left px-2 py-1.5 rounded-md text-sm italic ${f?`text-bambu-gray hover:bg-bambu-dark`:`bg-bambu-green/15 text-bambu-green`}`,children:n}),m.length===0?(0,G.jsx)(`p`,{className:`px-2 py-2 text-sm text-bambu-gray`,children:o(`inventory.noResults`)}):m.map(t=>(0,G.jsxs)(`button`,{type:`button`,role:`option`,"aria-selected":t.code===e,onClick:()=>h(t),className:`w-full flex items-center gap-2 text-left px-2 py-1.5 rounded-md text-sm ${t.code===e?`bg-bambu-green/15 text-bambu-green`:`text-white hover:bg-bambu-dark`}`,children:[(0,G.jsx)(`span`,{className:`flex-1 min-w-0 truncate`,title:t.displayName,children:t.displayName}),(0,G.jsx)(p9,{source:t.source})]},t.code))]})]})]})}function u1e(e,t){if(t.length===0)return{top:[],rest:e};let n=new Set(t.map(e=>e.toLowerCase()));return{top:e.filter(e=>n.has(e.toLowerCase())),rest:e.filter(e=>!n.has(e.toLowerCase()))}}function m9({label:e}){return(0,G.jsx)(`div`,{className:`px-3 py-1 text-[11px] font-semibold uppercase tracking-wide text-bambu-gray/70 bg-bambu-dark-tertiary/40`,children:e})}function d1e({formData:e,updateField:t,cloudAuthenticated:n,loadingCloudPresets:r,presetInputValue:i,setPresetInputValue:a,selectedPresetOption:o,filamentOptions:s,availableBrands:c,availableMaterials:l,suggestedBrands:u,suggestedMaterials:d,quickAdd:f,detailsRequired:p,quantity:m,onQuantityChange:h,errors:g}){let{t:_}=U(),[v,b]=(0,y.useState)(!1),[x,S]=(0,y.useState)(!1),[C,w]=(0,y.useState)(!1),[T,E]=(0,y.useState)(!1),[D,O]=(0,y.useState)(``),[k,A]=(0,y.useState)(``),[j,M]=(0,y.useState)(``),[N,P]=(0,y.useState)(String(e.label_weight)),[F,I]=(0,y.useState)(!1),[L,R]=(0,y.useState)(new Set),z=(0,y.useRef)(null),B=(0,y.useRef)(null),V=(0,y.useRef)(null),ee=(0,y.useRef)(null);(0,y.useEffect)(()=>{let e=e=>{z.current&&!z.current.contains(e.target)&&b(!1),ee.current&&!ee.current.contains(e.target)&&E(!1),B.current&&!B.current.contains(e.target)&&S(!1),V.current&&!V.current.contains(e.target)&&w(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[]);let te=(0,y.useMemo)(()=>{if(!i)return s;let e=i.toLowerCase();return s.filter(t=>t.displayName.toLowerCase().includes(e)||t.code.toLowerCase().includes(e))},[s,i]),ne=(0,y.useMemo)(()=>{if(!D)return c;let e=D.toLowerCase();return c.filter(t=>t.toLowerCase().includes(e)).sort((t,n)=>{let r=t.toLowerCase()===e,i=n.toLowerCase()===e;return r&&!i?-1:!r&&i?1:t.localeCompare(n)})},[c,D]),re=(0,y.useMemo)(()=>{if(!k)return RH;let e=k.toLowerCase();return RH.filter(t=>t.toLowerCase().includes(e))},[k]),ie=(0,y.useMemo)(()=>{if(!j)return l;let e=j.toLowerCase();return l.filter(t=>t.toLowerCase().includes(e)).sort((t,n)=>{let r=t.toLowerCase()===e,i=n.toLowerCase()===e;return r&&!i?-1:!r&&i?1:t.localeCompare(n)})},[j,l]),ae=(0,y.useMemo)(()=>u1e(ne,u),[ne,u]),oe=(0,y.useMemo)(()=>u1e(ie,d),[ie,d]);(0,y.useEffect)(()=>{F||P(String(e.label_weight))},[e.label_weight,F]);let se=n=>{t(`slicer_filament`,n.code),a(n.displayName),b(!1);let r=WH(n.name),i=new Set,o=[[`material`,r.material],[`brand`,r.brand],[`subtype`,r.variant]];for(let[n,r]of o)r&&(e[n]&&!L.has(n)||(t(n,r),i.add(n)));R(i)},H=(e,n)=>{L.has(e)&&R(t=>{let n=new Set(t);return n.delete(e),n}),t(e,n)},ce=t=>(0,G.jsx)(`button`,{type:`button`,className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${e.brand===t?`bg-bambu-green/10 text-bambu-green`:`text-white`}`,onClick:()=>{H(`brand`,t),S(!1),O(``)},children:t},t),le=t=>(0,G.jsx)(`button`,{type:`button`,className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${e.material===t?`bg-bambu-green/10 text-bambu-green`:`text-white`}`,onClick:()=>{H(`material`,t),E(!1),M(``)},children:t},t);return(0,G.jsxs)(`div`,{className:`space-y-4`,children:[!f&&(0,G.jsx)(`div`,{className:`flex items-center gap-2 text-xs text-bambu-gray`,children:r?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-3 h-3 animate-spin`}),` `,_(`inventory.loadingPresets`)]}):n?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Ps,{className:`w-3 h-3 text-bambu-green`}),` `,_(`inventory.cloudConnected`)]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Ms,{className:`w-3 h-3`}),` `,_(`inventory.cloudNotConnected`)]})}),!f&&(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:[_(`inventory.slicerPreset`),p&&` *`]}),(0,G.jsxs)(`div`,{className:`relative`,ref:z,children:[(0,G.jsx)(Ql,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50 pointer-events-none`}),(0,G.jsx)(`input`,{type:`text`,className:`w-full pl-9 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`,placeholder:_(`inventory.searchPresets`),value:i,onChange:e=>{a(e.target.value),b(!0)},onFocus:()=>{b(!0),a(``)}}),v&&(0,G.jsx)(`div`,{className:`absolute z-50 w-full mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-64 overflow-y-auto`,children:te.length===0?(0,G.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:_(`inventory.noPresetsFound`)}):te.map(e=>(0,G.jsxs)(`button`,{type:`button`,className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary flex items-center gap-2 ${o?.code===e.code?`bg-bambu-green/10 text-bambu-green`:`text-white`}`,onClick:()=>se(e),children:[(0,G.jsx)(`span`,{className:`flex-1 min-w-0 truncate`,title:e.displayName,children:e.displayName}),(0,G.jsx)(p9,{source:e.source})]},`${e.code}::${e.name}`))})]}),o&&(0,G.jsxs)(`div`,{className:`mt-1 text-xs text-bambu-gray`,children:[_(`inventory.selectedPreset`),`: `,(0,G.jsx)(`span`,{className:`font-mono text-bambu-green`,children:o.code})]}),g?.slicer_filament&&(0,G.jsx)(`p`,{className:`mt-1 text-xs text-red-700 dark:text-red-400`,children:g.slicer_filament})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:[_(`inventory.material`),` *`]}),(0,G.jsxs)(`div`,{className:`relative`,ref:ee,children:[(0,G.jsx)(`input`,{type:`text`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`,placeholder:_(`inventory.selectMaterial`),value:T?j:e.material,onChange:e=>{M(e.target.value),E(!0)},onFocus:()=>{E(!0),M(``)}}),(0,G.jsx)(ps,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50 pointer-events-none`}),T&&(0,G.jsxs)(`div`,{className:`absolute z-50 w-full mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-48 overflow-y-auto`,children:[ie.length===0?(0,G.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:_(`inventory.noResults`)}):(0,G.jsxs)(G.Fragment,{children:[oe.top.length>0&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(m9,{label:_(`inventory.suggestedOptions`)}),oe.top.map(le)]}),oe.rest.length>0&&(0,G.jsxs)(G.Fragment,{children:[oe.top.length>0&&(0,G.jsx)(m9,{label:_(`inventory.allOptions`)}),oe.rest.map(le)]})]}),j&&!ie.includes(j)&&(0,G.jsx)(`button`,{type:`button`,className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary text-bambu-green border-t border-bambu-dark-tertiary`,onClick:()=>{H(`material`,j),E(!1),M(``)},children:_(`inventory.useCustomMaterial`,{material:j})})]})]}),g?.material&&(0,G.jsx)(`p`,{className:`mt-1 text-xs text-red-700 dark:text-red-400`,children:g.material})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:[_(`inventory.brand`),p&&` *`]}),(0,G.jsxs)(`div`,{className:`relative`,ref:B,children:[(0,G.jsx)(`input`,{type:`text`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`,placeholder:_(`inventory.searchBrand`),value:x?D:e.brand,onChange:e=>{O(e.target.value),S(!0)},onFocus:()=>{S(!0),O(``)}}),(0,G.jsx)(ps,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50 pointer-events-none`}),x&&(0,G.jsxs)(`div`,{className:`absolute z-50 w-full mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-48 overflow-y-auto`,children:[ne.length===0?(0,G.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:_(`inventory.noResults`)}):(0,G.jsxs)(G.Fragment,{children:[ae.top.length>0&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(m9,{label:_(`inventory.suggestedOptions`)}),ae.top.map(ce)]}),ae.rest.length>0&&(0,G.jsxs)(G.Fragment,{children:[ae.top.length>0&&(0,G.jsx)(m9,{label:_(`inventory.allOptions`)}),ae.rest.map(ce)]})]}),D&&!ne.includes(D)&&(0,G.jsx)(`button`,{type:`button`,className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary text-bambu-green border-t border-bambu-dark-tertiary`,onClick:()=>{H(`brand`,D),S(!1),O(``)},children:_(`inventory.useCustomBrand`,{brand:D})})]})]}),g?.brand&&(0,G.jsx)(`p`,{className:`mt-1 text-xs text-red-700 dark:text-red-400`,children:g.brand})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:[_(`inventory.subtype`),p&&` *`]}),(0,G.jsxs)(`div`,{className:`relative`,ref:V,children:[(0,G.jsx)(`input`,{type:`text`,value:C?k:e.subtype,onChange:e=>{A(e.target.value),w(!0)},onFocus:()=>{w(!0),A(``)},placeholder:`Basic, Matte, Silk...`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`}),(0,G.jsx)(ps,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50 pointer-events-none`}),C&&(0,G.jsxs)(`div`,{className:`absolute z-50 w-full mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-48 overflow-y-auto`,children:[re.length===0?(0,G.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:_(`inventory.noResults`)}):re.map(t=>(0,G.jsx)(`button`,{type:`button`,className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${e.subtype===t?`bg-bambu-green/10 text-bambu-green`:`text-white`}`,onClick:()=>{H(`subtype`,t),w(!1),A(``)},children:t},t)),k&&!RH.some(e=>e.toLowerCase()===k.toLowerCase().trim())&&(0,G.jsx)(`button`,{type:`button`,className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary text-bambu-green border-t border-bambu-dark-tertiary`,onClick:()=>{H(`subtype`,k),w(!1),A(``)},children:_(`inventory.useCustomBrand`,{brand:k})})]})]}),g?.subtype&&(0,G.jsx)(`p`,{className:`mt-1 text-xs text-red-700 dark:text-red-400`,children:g.subtype})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:_(`inventory.labelWeight`)}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(`input`,{type:`number`,className:`w-full px-3 py-2 pr-7 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`,value:N,min:0,onFocus:()=>I(!0),onChange:e=>P(e.target.value),onBlur:()=>{I(!1);let n=N.trim(),r=Number(n);if(!n||!Number.isFinite(r)||r<0){P(String(e.label_weight));return}let i=Math.round(r);t(`label_weight`,i),P(String(i))}}),(0,G.jsx)(`span`,{className:`absolute right-2 top-1/2 -translate-y-1/2 text-xs text-bambu-gray`,children:`g`})]})]}),f&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:_(`inventory.quantity`)}),(0,G.jsx)(`input`,{type:`number`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`,value:m,min:1,max:100,onChange:e=>{h(Math.max(1,Math.min(100,parseInt(e.target.value)||1)))}})]})]})}function f1e(e){let t=e.split(/[\s,]+/).map(e=>e.trim().replace(/^#/,``)).filter(Boolean),n=[],r=[];for(let e of t)(e.length===6||e.length===8)&&/^[0-9a-fA-F]+$/.test(e)?n.push(e.toLowerCase()):r.push(e);return{value:n.join(`,`),invalid:r}}function p1e({formData:e,updateField:t,recentColors:n,onColorUsed:r,catalogColors:i}){let{t:a}=U(),[o,s]=(0,y.useState)(!1),[c,l]=(0,y.useState)(``),u=(e.rgba.replace(`#`,``)+`FF`).substring(0,8).toUpperCase(),d=u.substring(0,6),f=u.substring(6,8)===`00`,[p,m]=(0,y.useState)(f?u:d);(0,y.useEffect)(()=>{m(f?u:d)},[d,u,f]);let h=e=>u===(e.replace(`#`,``)+`FF`).substring(0,8).toUpperCase(),g=e=>Mf(e),_=(e,n,i,a)=>{let o=e.replace(`#`,``).toUpperCase();if(t(`rgba`,o.length===8?o:o+`FF`),t(`color_name`,n),i!==void 0){let e=i??``;w(e),E([]),D.current=e,t(`extra_colors`,e)}a!==void 0&&t(`effect_type`,a??``),r({name:n,hex:e})},v=(0,y.useMemo)(()=>{if(i.length===0)return[];let t=e.brand?.trim(),n=e.material?.toLowerCase().trim(),r=e.subtype?.toLowerCase().trim();if(!t&&!n)return[];let a=t?t.toLowerCase().split(/[\s\-_]+/).filter(e=>e.length>=2):[],o=e=>{if(a.length===0)return!0;let t=e.toLowerCase();return a.some(e=>t.includes(e))};if(t&&!n){let e=i.filter(e=>o(e.manufacturer));if(e.length>0)return e.map(e=>({name:e.color_name,hex:e.hex_color.replace(`#`,``).substring(0,6),manufacturer:e.manufacturer,material:typeof e.material==`string`?e.material:void 0,extra_colors:e.extra_colors??null,effect_type:e.effect_type??null}))}let s=n&&r?`${n} ${r}`:``;if(s){let e=i.filter(e=>o(e.manufacturer)&&e.material?.toLowerCase()===s);if(e.length>0)return e.map(e=>({name:e.color_name,hex:e.hex_color.replace(`#`,``).substring(0,6),manufacturer:e.manufacturer,material:typeof e.material==`string`?e.material:void 0,extra_colors:e.extra_colors??null,effect_type:e.effect_type??null}));let t=s.replace(/\+$/,``);if(t!==s){let e=i.filter(e=>o(e.manufacturer)&&e.material?.toLowerCase()===t);if(e.length>0)return e.map(e=>({name:e.color_name,hex:e.hex_color.replace(`#`,``).substring(0,6),manufacturer:e.manufacturer,material:typeof e.material==`string`?e.material:void 0}))}}if(n){let e=i.filter(e=>o(e.manufacturer)&&(!e.material||e.material.toLowerCase().startsWith(n)));if(e.length>0)return e.map(e=>({name:e.color_name,hex:e.hex_color.replace(`#`,``).substring(0,6),manufacturer:e.manufacturer,material:typeof e.material==`string`?e.material:void 0,extra_colors:e.extra_colors??null,effect_type:e.effect_type??null}))}return[]},[i,e.brand,e.material,e.subtype]),b=(0,y.useMemo)(()=>{if(!c)return v;if(v.length===0)return[];let e=c.toLowerCase();return v.filter(t=>t.name.toLowerCase().includes(e)||(t.manufacturer?.toLowerCase().includes(e)??!1)||(t.material?.toLowerCase().includes(e)??!1))},[c,v]),x=v.length>0,S=(0,y.useMemo)(()=>c?BH.filter(e=>e.name.toLowerCase().includes(c.toLowerCase())):o?BH:zH,[c,o]),[C,w]=(0,y.useState)(e.extra_colors),[T,E]=(0,y.useState)([]),D=(0,y.useRef)(e.extra_colors);(0,y.useEffect)(()=>{e.extra_colors!==D.current&&(w(e.extra_colors),E([]),D.current=e.extra_colors)},[e.extra_colors]);let O=(0,y.useMemo)(()=>bH({rgba:e.rgba,extraColors:e.extra_colors,effectType:e.effect_type,subtype:e.subtype,effectSize:`bar`}),[e.rgba,e.extra_colors,e.effect_type,e.subtype]),k=e=>{if(w(e),!e.trim()){E([]),D.current=``,t(`extra_colors`,``);return}let{value:n,invalid:r}=f1e(e);E(r),D.current=n,t(`extra_colors`,n)};return(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsx)(`div`,{className:`h-10 rounded-lg border border-bambu-dark-tertiary`,style:O,"data-testid":`color-preview-banner`}),n.length>0&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 text-xs text-bambu-gray shrink-0`,children:[(0,G.jsx)(js,{className:`w-3 h-3`}),(0,G.jsx)(`span`,{children:a(`inventory.recentColors`)})]}),(0,G.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:n.map(e=>(0,G.jsx)(`button`,{type:`button`,onClick:()=>_(e.hex,e.name),className:`w-6 h-6 rounded border-2 transition-all hover:scale-110 ${h(e.hex)?`border-bambu-green ring-1 ring-bambu-green/30 scale-110`:`border-bambu-dark-tertiary`}`,style:g(e.hex),title:e.name},e.hex))})]}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(Ql,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50 pointer-events-none`}),(0,G.jsx)(`input`,{type:`text`,className:`w-full pl-9 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`,placeholder:a(`inventory.searchColors`),value:c,onChange:e=>l(e.target.value)})]}),x?(0,G.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:c?a(`inventory.searchResults`):`${e.brand}${e.material?` ${e.material}`:``}`}),(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-1.5`,children:[b.map(e=>(0,G.jsx)(`button`,{type:`button`,onClick:()=>_(e.hex,e.name,e.extra_colors,e.effect_type),className:`w-6 h-6 rounded border-2 transition-all hover:scale-110 hover:z-20 relative group ${h(e.hex)?`border-bambu-green ring-1 ring-bambu-green/30 scale-110`:`border-bambu-dark-tertiary`}`,style:g(e.hex),title:e.manufacturer&&e.material?`${e.name} (${e.manufacturer} — ${e.material})`:e.manufacturer?`${e.name} (${e.manufacturer})`:e.name,children:(0,G.jsx)(`span`,{className:`absolute -bottom-7 left-1/2 -translate-x-1/2 px-2 py-0.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-xs whitespace-nowrap opacity-0 group-hover:opacity-100 transition-opacity pointer-events-none z-20 shadow-lg text-white`,children:e.manufacturer&&e.material?`${e.name} (${e.manufacturer} — ${e.material})`:e.manufacturer?`${e.name} (${e.manufacturer})`:e.name})},`${e.hex}-${e.name}-${e.manufacturer??``}`)),b.length===0&&(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray py-1`,children:a(`inventory.noColorsFound`)})]})]}):(0,G.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between text-xs text-bambu-gray`,children:[(0,G.jsx)(`span`,{children:a(c?`inventory.searchResults`:o?`inventory.allColors`:`inventory.commonColors`)}),!c&&(0,G.jsx)(`button`,{type:`button`,onClick:()=>s(!o),className:`flex items-center gap-1 hover:text-white transition-colors`,children:o?(0,G.jsxs)(G.Fragment,{children:[a(`inventory.showLess`),` `,(0,G.jsx)(gs,{className:`w-3 h-3`})]}):(0,G.jsxs)(G.Fragment,{children:[a(`inventory.showAll`),` `,(0,G.jsx)(ps,{className:`w-3 h-3`})]})})]}),(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-1.5`,children:[S.map(e=>(0,G.jsx)(`button`,{type:`button`,onClick:()=>_(e.hex,e.name),className:`w-6 h-6 rounded border-2 transition-all hover:scale-110 hover:z-20 relative group ${h(e.hex)?`border-bambu-green ring-1 ring-bambu-green/30 scale-110`:`border-bambu-dark-tertiary`}`,style:g(e.hex),title:e.name,children:(0,G.jsx)(`span`,{className:`absolute -bottom-7 left-1/2 -translate-x-1/2 px-2 py-0.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-xs whitespace-nowrap opacity-0 group-hover:opacity-100 transition-opacity pointer-events-none z-20 shadow-lg text-white`,children:e.name})},e.hex)),S.length===0&&(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray py-1`,children:a(`inventory.noColorsFound`)})]})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:a(`inventory.colorName`)}),(0,G.jsx)(`input`,{type:`text`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`,placeholder:a(`inventory.colorNamePlaceholder`),value:e.color_name,onChange:e=>t(`color_name`,e.target.value)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:a(`inventory.hexColor`)}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsxs)(`div`,{className:`relative flex-1`,children:[(0,G.jsx)(`span`,{className:`absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray`,children:`#`}),(0,G.jsx)(`input`,{type:`text`,className:`w-full pl-7 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm font-mono uppercase focus:outline-none focus:border-bambu-green`,placeholder:`RRGGBB`,value:p.toUpperCase(),onChange:e=>{let n=e.target.value.replace(`#`,``).replace(/[^0-9A-Fa-f]/g,``).toUpperCase(),r=n.length>8?n.substring(0,8):n;m(r),r.length===6?t(`rgba`,r+`FF`):r.length===8&&t(`rgba`,r)},onBlur:()=>{if(p.length===7){let e=p+`0`;m(e),t(`rgba`,e)}else if(p.length>0&&p.length<6){let e=p.padEnd(6,`0`);m(e),t(`rgba`,e+`FF`)}}})]}),(0,G.jsx)(`input`,{type:`color`,className:`w-11 h-[38px] rounded-lg cursor-pointer border border-bambu-dark-tertiary shrink-0 bg-transparent`,value:`#${d}`,onChange:e=>{t(`rgba`,e.target.value.replace(`#`,``).toUpperCase()+`FF`)},title:a(`inventory.pickColor`)})]})]})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3 pt-2 border-t border-bambu-dark-tertiary/50`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:a(`inventory.extraColorsLabel`)}),(0,G.jsx)(`input`,{type:`text`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm font-mono placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`,placeholder:a(`inventory.extraColorsPlaceholder`),value:C,onChange:e=>k(e.target.value),"data-testid":`extra-colors-input`}),T.length>0&&(0,G.jsx)(`p`,{className:`text-xs text-red-700 dark:text-red-400 mt-1`,children:a(`inventory.extraColorsInvalid`,{tokens:T.join(`, `)})}),!T.length&&(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray/70 mt-1`,children:a(`inventory.extraColorsHint`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1 flex items-center gap-1.5`,children:[(0,G.jsx)(_u,{className:`w-3.5 h-3.5`}),a(`inventory.colorEffectLabel`)]}),(0,G.jsxs)(`div`,{className:`flex gap-2 items-stretch`,children:[(0,G.jsx)(`select`,{className:`flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`,value:e.effect_type,onChange:e=>t(`effect_type`,e.target.value),"data-testid":`effect-type-select`,children:_H.map(e=>(0,G.jsx)(`option`,{value:e.value,children:a(e.labelKey)},e.value||`none`))}),(0,G.jsx)(w8,{rgba:e.rgba,extraColors:e.extra_colors,effectType:e.effect_type,subtype:e.subtype,effectSize:`preview`,className:`w-10 h-10`,shape:`square`})]})]})]})]})}function m1e({catalog:e,value:t,onChange:n,catalogId:r,onCatalogIdChange:i}){let{t:a}=U(),[o,s]=(0,y.useState)(!1),[c,l]=(0,y.useState)(``),u=(0,y.useRef)(null),d=(0,y.useRef)(null);(0,y.useEffect)(()=>{let e=e=>{u.current&&!u.current.contains(e.target)&&s(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[]),(0,y.useEffect)(()=>{if(e.length===0)return;let n=e.filter(e=>e.weight===t);if(r){let n=e.find(e=>e.id===r);if(n&&n.weight===t)return}n.length===1?i(n[0].id):n.length===0&&r!==null&&i(null)},[t,e,r,i]);let f=(0,y.useMemo)(()=>{if(!c)return e;let t=c.toLowerCase();return e.filter(e=>e.name.toLowerCase().includes(t)||e.weight.toString().includes(t))},[e,c]),p=(0,y.useMemo)(()=>e.filter(e=>e.weight===t),[e,t]),m=(0,y.useMemo)(()=>{if(o)return c;if(r){let t=e.find(e=>e.id===r);if(t)return t.name}return p.length>0?p[0].name:``},[o,c,r,e,p]);return(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:(0,G.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Jl,{className:`w-3.5 h-3.5 text-bambu-gray`}),a(`inventory.coreWeight`)]})}),(0,G.jsxs)(`div`,{className:`flex gap-2 items-center`,children:[(0,G.jsxs)(`div`,{className:`flex-1 min-w-0 relative`,ref:u,children:[(0,G.jsx)(`input`,{ref:d,type:`text`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`,placeholder:a(`inventory.searchSpoolWeight`),value:m,onFocus:()=>{s(!0),l(``)},onChange:e=>{l(e.target.value),s(!0)}}),o&&(0,G.jsx)(`div`,{className:`absolute z-50 w-full mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-64 overflow-y-auto`,children:f.length===0?(0,G.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:a(`inventory.noResults`)}):f.map(e=>(0,G.jsxs)(`button`,{type:`button`,className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary flex justify-between items-center ${(r?e.id===r:e.weight===t)?`bg-bambu-green/10 text-bambu-green`:`text-white`}`,onClick:()=>{i(e.id),n(e.weight),s(!1),l(``)},children:[(0,G.jsx)(`span`,{className:`truncate`,children:e.name}),(0,G.jsxs)(`span`,{className:`font-mono text-xs text-bambu-gray ml-2 shrink-0`,children:[e.weight,`g`]})]},e.id))})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[(0,G.jsx)(`input`,{type:`number`,className:`w-16 px-2 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm text-center font-mono focus:outline-none focus:border-bambu-green`,value:t,min:0,max:2e3,onChange:e=>{let t=parseInt(e.target.value);!isNaN(t)&&t>=0&&n(t)}}),(0,G.jsx)(`span`,{className:`text-bambu-gray text-sm`,children:`g`})]})]})]})}function h1e({formData:e,updateField:t,spoolCatalog:n,currencySymbol:r,availableCategories:i,availableLocations:a=[],onCreateLocation:o,globalLowStockThreshold:s,spoolmanMode:c=!1}){let{t:l}=U(),{showToast:u}=qd(),[d,f]=(0,y.useState)(``),[p,m]=(0,y.useState)(!1),[h,g]=(0,y.useState)(``),[_,v]=(0,y.useState)(!1),[b,x]=(0,y.useState)(``),[S,C]=(0,y.useState)(!1),w=Math.max(0,e.label_weight-e.weight_used),T=e.core_weight+w;return(0,y.useEffect)(()=>{p||f(String(T))},[p,T]),(0,y.useEffect)(()=>{_||g(String(w))},[_,w]),(0,G.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-x-4 gap-y-4`,children:[(0,G.jsx)(`div`,{className:`sm:col-span-2`,children:c?(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray px-1`,children:l(`inventory.spoolWeightManagedBySpoolman`)}):(0,G.jsx)(m1e,{catalog:n,value:e.core_weight,onChange:e=>t(`core_weight`,e),catalogId:e.core_weight_catalog_id,onCatalogIdChange:e=>t(`core_weight_catalog_id`,e)})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:l(`inventory.currentWeight`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`div`,{className:`relative flex-1`,children:[(0,G.jsx)(`input`,{type:`number`,value:h,min:0,max:e.label_weight,onFocus:()=>v(!0),onChange:e=>{g(e.target.value)},onBlur:()=>{v(!1);let n=h.trim(),r=Number(n);if(!n||!Number.isFinite(r)||r<0||r>e.label_weight){g(String(w));return}let i=Math.round(r);t(`weight_used`,Math.max(0,e.label_weight-i)),g(String(i))},className:`w-full px-3 py-2 pr-7 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`}),(0,G.jsx)(`span`,{className:`absolute right-2 top-1/2 -translate-y-1/2 text-xs text-bambu-gray`,children:`g`})]}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray shrink-0`,children:[`/ `,e.label_weight,`g`]})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:l(`inventory.measuredWeight`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`div`,{className:`relative flex-1`,children:[(0,G.jsx)(`input`,{type:`number`,value:d,min:0,onFocus:()=>m(!0),onChange:e=>{f(e.target.value)},onBlur:()=>{m(!1);let n=d.trim(),r=Number(n),i=e.core_weight,a=e.core_weight+e.label_weight;if(!n||!Number.isFinite(r)||ra){u(l(`inventory.measuredWeightError`,{min:i,max:a}),`error`),f(String(T));return}let o=Math.round(r),s=Math.max(0,Math.min(e.label_weight,o-e.core_weight));t(`weight_used`,Math.max(0,e.label_weight-s)),f(String(o))},className:`w-full px-3 py-2 pr-7 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`}),(0,G.jsx)(`span`,{className:`absolute right-2 top-1/2 -translate-y-1/2 text-xs text-bambu-gray`,children:`g`})]}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray shrink-0`,children:[`/ `,e.core_weight+e.label_weight,`g`]})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:l(`inventory.costPerKg`,`Cost per kg`)}),(0,G.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,G.jsxs)(`div`,{className:`relative flex-1`,children:[(0,G.jsx)(`span`,{className:`absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray text-sm pointer-events-none`,children:r}),(0,G.jsx)(`input`,{type:`number`,value:e.cost_per_kg??``,min:0,step:.01,placeholder:`0.00`,onChange:e=>{t(`cost_per_kg`,e.target.value===``?null:parseFloat(e.target.value))},style:{paddingLeft:`${Math.max(2,r.length*.6+1)}rem`},className:`w-full py-2 pr-3 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`})]})})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,htmlFor:`spool-category`,children:l(`inventory.category`)}),(0,G.jsx)(`input`,{id:`spool-category`,type:`text`,list:`spool-category-options`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`,placeholder:l(`inventory.categoryPlaceholder`),value:e.category,maxLength:50,onChange:e=>t(`category`,e.target.value)}),i.length>0&&(0,G.jsx)(`datalist`,{id:`spool-category-options`,children:i.map(e=>(0,G.jsx)(`option`,{value:e},e))})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,htmlFor:`spool-low-stock-threshold`,children:l(`inventory.lowStockThresholdOverride`)}),(0,G.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,G.jsxs)(`div`,{className:`relative flex-1`,children:[(0,G.jsx)(`input`,{id:`spool-low-stock-threshold`,type:`number`,className:`w-full px-3 py-2 pr-8 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`,placeholder:String(s),value:e.low_stock_threshold_pct??``,min:1,max:99,step:1,onChange:e=>{let n=e.target.value;if(n===``){t(`low_stock_threshold_pct`,null);return}let r=Number(n);Number.isFinite(r)&&t(`low_stock_threshold_pct`,Math.min(99,Math.max(1,Math.round(r))))}}),(0,G.jsx)(`span`,{className:`absolute right-3 top-1/2 -translate-y-1/2 text-xs text-bambu-gray pointer-events-none`,children:`%`})]})}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:l(`inventory.lowStockThresholdOverrideHelp`,{global:s})})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,htmlFor:`spool-storage-location`,children:l(`inventory.storageLocation`)}),(0,G.jsxs)(`select`,{id:`spool-storage-location`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`,value:e.location_id??``,onChange:e=>{let n=e.target.value;if(!n){t(`location_id`,null);return}t(`location_id`,Number(n))},children:[(0,G.jsx)(`option`,{value:``,children:l(`inventory.storageLocationNone`)}),a.map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),o&&(0,G.jsxs)(`div`,{className:`mt-2 flex gap-2`,children:[(0,G.jsx)(`input`,{type:`text`,maxLength:255,className:`flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`,placeholder:l(`locations.createPlaceholder`),value:b,onChange:e=>x(e.target.value)}),(0,G.jsx)(`button`,{type:`button`,className:`px-3 py-2 text-sm rounded-lg bg-bambu-dark-tertiary text-white hover:bg-bambu-gray-dark disabled:opacity-50`,disabled:!b.trim()||S,onClick:async()=>{let e=b.trim();if(!(!e||!o)){C(!0);try{let n=await o(e);n&&(t(`location_id`,n.id),x(``))}finally{C(!1)}}},children:l(`locations.addShort`)})]})]}),(0,G.jsxs)(`div`,{className:`sm:col-span-2`,children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:l(`inventory.note`)}),(0,G.jsx)(`textarea`,{className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green resize-none min-h-[80px]`,placeholder:l(`inventory.notePlaceholder`),value:e.note,onChange:e=>t(`note`,e.target.value)})]})]})}function g1e({filaments:e,isLoading:t,selectedId:n,onSelect:r}){let{t:i}=U(),[a,o]=(0,y.useState)(!1),[s,c]=(0,y.useState)(``),l=(0,y.useRef)(null),u=(0,y.useRef)(null),d=(0,y.useMemo)(()=>e.find(e=>e.id===n)??null,[e,n]);(0,y.useEffect)(()=>{let e=e=>{l.current&&!l.current.contains(e.target)&&(o(!1),c(``))};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[]);let f=(0,y.useMemo)(()=>{let t=s.toLowerCase().trim();return t?e.filter(e=>e.name.toLowerCase().includes(t)||(e.material?.toLowerCase().includes(t)??!1)||(e.vendor?.name.toLowerCase().includes(t)??!1)||(e.color_name?.toLowerCase().includes(t)??!1)):e},[e,s]);(0,y.useEffect)(()=>{a&&u.current?.focus()},[a]);let p=()=>{o(!0),c(``)},m=e=>{r(e),o(!1),c(``)};return(0,G.jsxs)(`div`,{ref:l,className:`relative`,children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:i(`inventory.pickFromSpoolmanCatalog`)}),(0,G.jsxs)(`button`,{type:`button`,onClick:p,className:`w-full flex items-center gap-2 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-left focus:outline-none focus:border-bambu-green hover:border-bambu-gray transition-colors`,children:[t?(0,G.jsx)(Y,{className:`w-4 h-4 text-bambu-gray animate-spin shrink-0`}):d?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`span`,{className:`w-4 h-4 rounded-full shrink-0 border border-white/20`,style:Mf(d.color_hex),"aria-label":i(`inventory.spoolmanFilamentColorSwatch`)}),(0,G.jsxs)(`span`,{className:`text-white text-sm truncate flex-1`,children:[d.vendor?.name?`${d.vendor.name} — `:``,d.name]})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Cl,{className:`w-4 h-4 text-bambu-gray shrink-0`}),(0,G.jsx)(`span`,{className:`text-bambu-gray text-sm flex-1`,children:i(`inventory.spoolmanFilamentCatalog`)})]}),(0,G.jsx)(ps,{className:`w-4 h-4 text-bambu-gray shrink-0 ml-auto`})]}),a&&(0,G.jsxs)(`div`,{className:`absolute z-50 w-full mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl`,children:[(0,G.jsx)(`div`,{className:`p-2 border-b border-bambu-dark-tertiary`,children:(0,G.jsx)(`input`,{ref:u,type:`text`,value:s,onChange:e=>c(e.target.value),placeholder:i(`inventory.pickFromSpoolmanCatalog`),className:`w-full px-2 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm placeholder-bambu-gray focus:outline-none focus:border-bambu-green`})}),(0,G.jsx)(`ul`,{className:`max-h-56 overflow-y-auto py-1`,children:t?(0,G.jsxs)(`li`,{className:`flex items-center justify-center gap-2 py-4 text-bambu-gray text-sm`,children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),(0,G.jsx)(`span`,{children:i(`common.loading`,`Loading…`)})]}):f.length===0?(0,G.jsx)(`li`,{className:`py-4 text-center text-bambu-gray text-sm`,children:i(`inventory.noSpoolmanFilaments`)}):f.map(e=>(0,G.jsx)(`li`,{children:(0,G.jsxs)(`button`,{type:`button`,onClick:()=>m(e),className:`w-full flex items-center gap-2 px-3 py-2 text-left hover:bg-bambu-dark-tertiary transition-colors ${e.id===n?`bg-bambu-dark-tertiary`:``}`,children:[(0,G.jsx)(`span`,{className:`w-4 h-4 rounded-full shrink-0 border border-white/20`,style:Mf(e.color_hex),"aria-label":i(`inventory.spoolmanFilamentColorSwatch`)}),(0,G.jsxs)(`span`,{className:`flex-1 min-w-0`,children:[(0,G.jsxs)(`span`,{className:`block text-white text-sm truncate`,children:[e.vendor?.name?`${e.vendor.name} — `:``,e.name]}),(0,G.jsxs)(`span`,{className:`block text-bambu-gray text-xs truncate`,children:[[e.material,e.color_name].filter(Boolean).join(` · `),e.weight?` · ${e.weight}g`:``]})]})]})},e.id))})]})]})}function h9(e){let t=(e??``).trim().toUpperCase().slice(0,2);return t===`HH`||t===`HS`?t:null}function g9(e){return e?e===`HH`?`HF`:`S`:null}function _1e(e,t){let n=e.nozzles??[];return h9(n[(e.printer.nozzle_count??1)>1&&t>0?t:0]?.nozzle_type)??h9(n[0]?.nozzle_type)}function v1e(e){let t=new Set;for(let n of e.nozzles??[]){let e=(n?.nozzle_diameter??``).trim();e&&parseFloat(e)>0&&t.add(e)}for(let n of e.calibrations){let e=(n.nozzle_diameter??``).trim();e&&parseFloat(e)>0&&t.add(e)}return Array.from(t).sort((e,t)=>parseFloat(e)-parseFloat(t))}function y1e(e,t){return(e.printer.nozzle_count??1)>1?[{extruder:1,label:t.left},{extruder:0,label:t.right}]:[{extruder:0,label:t.single}]}function b1e({formData:e,printersWithCalibrations:t,filamentOptions:n,modelPresets:r,setModelPresets:i,selectedProfiles:a,setSelectedProfiles:o,selectedGroupId:s,setSelectedGroupId:c,printerModels:l,isLoading:u=!1}){let{t:d}=U(),f=(0,y.useMemo)(()=>{let e=new Map,n=[];for(let r of t){let t=(r.printer.model||``).trim();if(!t){n.push(r);continue}let i=e.get(t);i?i.push(r):e.set(t,[r])}return[...Array.from(e.entries()).map(([e,t])=>({id:`m:${e}`,model:e,printers:t,diameters:Array.from(new Set([...HH,...t.flatMap(v1e)])).sort((e,t)=>parseFloat(e)-parseFloat(t))})).sort((e,t)=>e.model.localeCompare(t.model)),...n.map(e=>({id:`p:${e.printer.id}`,model:``,printers:[e],diameters:Array.from(new Set([...HH,...v1e(e)])).sort((e,t)=>parseFloat(e)-parseFloat(t))}))]},[t]),p=f.find(e=>e.id===s)??f[0],m=(0,y.useMemo)(()=>{let e=new Map;return(t,r)=>{if(!t)return n;let i=e.get(t);if(i||(i=n.filter(e=>{let n=FH(e.name,l??{});return!n||DH(n,t)}),e.set(t,i)),r&&!i.some(e=>e.code===r)){let e=n.find(e=>e.code===r);if(e)return[e,...i]}return i}},[n,l]),h=[e.brand,e.material,e.subtype].map(e=>e.trim()).filter(Boolean).join(` `),g=/^[0-9A-Fa-f]{6,8}$/.test(e.rgba)?`#${e.rgba.slice(0,6)}`:`var(--bambu-gray, #808080)`,_=e=>y1e(e,{left:d(`inventory.leftNozzle`),right:d(`inventory.rightNozzle`),single:d(`inventory.nozzle`)}),v=t=>t.printer.connected?t.calibrations.filter(t=>nU(t,e)):[],b=e=>{let t=0;for(let n of e.printers){let r=v(n);for(let i of _(n))for(let o of e.diameters)r.some(e=>(e.extruder_id??0)===i.extruder&&((e.nozzle_diameter??``).trim()||`0.4`)===o)&&(a.get(eU(n.printer.id,i.extruder,o))||t++)}return t},x=(e,t,n)=>{i(r=>{let i=new Map(r),a=tU(e,t);return n?i.set(a,{code:n.code,name:n.name}):i.delete(a),i})},S=(e,t,n,r)=>{o(i=>{let a=new Map(i),o=eU(e,t,n);return r?a.set(o,r):a.delete(o),a})},C=()=>{let t=n.find(t=>t.code===e.slicer_filament);if(!t)return;let r=t.name.split(`@`)[0].trim().toLowerCase();r&&i(e=>{let t=new Map(e);for(let e of f){if(!e.model)continue;let n=m(e.model,void 0).filter(e=>e.name.toLowerCase().startsWith(r)&&FH(e.name,l??{})!==null);if(n.length!==0)for(let r of e.diameters){let i=n.find(e=>RegExp(`\\b${r.replace(`.`,`\\.`)}\\s*nozzle\\b`,`i`).test(e.name)),a=n.find(e=>!/\b[\d.]+\s*nozzle\b/i.test(e.name)),o=i??a;o&&t.set(tU(e.model,r),{code:o.code,name:o.name})}}return t})};if(t.length===0)return(0,G.jsx)(`div`,{className:`p-6 bg-bambu-dark rounded-lg text-center`,children:(0,G.jsxs)(`p`,{className:`text-bambu-gray flex items-center justify-center gap-2`,children:[u&&(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),d(u?`common.loading`:`inventory.noPrintersConfigured`)]})});let w=(e,t,n)=>{let i=tU(e,t),a=r.get(i),o=m(e,a?.code);return(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,G.jsx)(l1e,{ariaLabel:`${e} ${t}mm ${d(`inventory.filamentPreset`)}`,value:a?.code??``,options:o,inheritLabel:n,disabled:!e,onChange:n=>x(e,t,n)})}),(0,G.jsx)(`span`,{className:`text-[10px] font-semibold uppercase tracking-wide px-2 py-1 rounded-full shrink-0 ${a?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark-tertiary text-bambu-gray`}`,children:d(a?`inventory.presetOverride`:`inventory.presetInherited`)})]})};return(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(h||e.color_name)&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2.5 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg`,children:[(0,G.jsx)(`span`,{className:`w-5 h-5 rounded-full border border-white/15 shrink-0`,style:{background:g},"aria-hidden":`true`}),h&&(0,G.jsx)(`span`,{className:`text-sm text-white truncate`,children:h}),e.color_name&&(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray truncate`,children:e.color_name})]}),(0,G.jsxs)(`div`,{className:`flex flex-col md:flex-row gap-4`,children:[(0,G.jsx)(`div`,{role:`tablist`,"aria-label":d(`inventory.printersTab`),"aria-orientation":`vertical`,className:`md:w-52 md:shrink-0 md:self-start md:sticky md:top-0 flex md:flex-col gap-1.5 overflow-x-auto md:overflow-x-visible`,children:f.map(e=>{let t=e===p,n=b(e);return(0,G.jsxs)(`button`,{type:`button`,role:`tab`,onClick:()=>c(e.id),"aria-selected":t,className:`flex items-center gap-2 px-3 py-2 rounded-lg border text-left transition-colors shrink-0 md:shrink ${t?`bg-bambu-green/10 border-bambu-green/40 text-white`:`bg-transparent border-transparent text-bambu-gray hover:bg-bambu-dark hover:text-white`}`,children:[(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,G.jsx)(`div`,{className:`text-sm font-semibold truncate`,children:e.model||d(`inventory.unknownModel`)}),(0,G.jsx)(`div`,{className:`text-[11px] text-bambu-gray`,children:e.printers.length===1?d(`inventory.onePrinter`):d(`inventory.nPrinters`,{n:e.printers.length})})]}),n>0?(0,G.jsx)(`span`,{className:`text-[10px] font-mono px-1.5 py-0.5 rounded-full bg-bambu-dark-tertiary text-bambu-gray shrink-0`,children:n}):(0,G.jsx)(fs,{className:`w-3.5 h-3.5 text-bambu-green shrink-0`})]},e.id)})}),(0,G.jsx)(`div`,{className:`flex-1 min-w-0`,children:p&&(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsx)(`h4`,{className:`text-base font-semibold text-white truncate`,children:p.model||d(`inventory.unknownModel`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:p.printers.map(e=>e.printer.name).join(`, `)})]}),e.slicer_filament&&(0,G.jsxs)(`button`,{type:`button`,onClick:C,title:d(`inventory.autoMatchPresetsHint`),className:`flex items-center gap-1.5 px-2 py-1 text-xs bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray hover:text-white hover:border-bambu-green transition-colors shrink-0`,children:[(0,G.jsx)(_u,{className:`w-3.5 h-3.5`}),d(`inventory.autoMatchPresets`)]})]}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`p`,{className:`text-xs font-semibold text-bambu-gray uppercase tracking-wide`,children:d(`inventory.filamentPreset`)}),p.model?(0,G.jsx)(`div`,{className:`space-y-2`,children:p.diameters.map(e=>(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsxs)(`span`,{className:`text-xs font-mono text-bambu-gray w-14 shrink-0`,children:[e,`mm`]}),(0,G.jsx)(`div`,{className:`flex-1 min-w-0`,children:w(p.model,e,d(`inventory.presetUseSpoolDefault`))})]},e))}):(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray italic`,children:d(`inventory.presetNeedsModel`)})]}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`p`,{className:`text-xs font-semibold text-bambu-gray uppercase tracking-wide`,children:d(`inventory.kProfilesPerPrinter`)}),e.material?p.printers.map(e=>{let t=v(e);return(0,G.jsxs)(`div`,{className:`p-3 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,G.jsx)(Rl,{className:`w-3.5 h-3.5 text-bambu-gray shrink-0`}),(0,G.jsx)(`span`,{className:`text-sm font-semibold text-white truncate`,children:e.printer.name}),(0,G.jsx)(`span`,{className:`text-[10px] font-semibold uppercase tracking-wide px-2 py-0.5 rounded-full shrink-0 ${e.printer.connected?`bg-green-500/20 text-green-500`:`bg-bambu-dark-tertiary text-bambu-gray`}`,children:e.printer.connected?d(`inventory.connected`):d(`inventory.offline`)})]}),e.printer.connected?t.length===0?(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray italic py-1`,children:d(`inventory.noKProfilesMatch`)}):(0,G.jsxs)(`div`,{className:`grid gap-x-3 gap-y-1.5 items-center`,style:{gridTemplateColumns:`3.5rem repeat(${_(e).length}, minmax(0, 1fr))`},children:[(0,G.jsx)(`span`,{}),_(e).map(e=>(0,G.jsx)(`span`,{className:`text-[11px] font-semibold uppercase tracking-wide text-bambu-gray`,children:e.label},e.extruder)),p.diameters.map(n=>(0,G.jsxs)(y.Fragment,{children:[(0,G.jsxs)(`span`,{className:`text-xs font-mono text-bambu-gray`,children:[n,`mm`]}),_(e).map(r=>{let i=t.filter(e=>(e.extruder_id??0)===r.extruder&&((e.nozzle_diameter??``).trim()||`0.4`)===n),o=eU(e.printer.id,r.extruder,n),s=a.get(o);if(i.length===0)return(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray/50 px-2 py-1.5`,title:d(`inventory.noKProfilesMatch`),children:`—`},o);let c=_1e(e,r.extruder),l=h9(s?.nozzle_id),u=!!(c&&l&&c!==l);return(0,G.jsxs)(`select`,{title:u?d(`inventory.kProfileFlowMismatch`,{profile:g9(l),fitted:g9(c)}):void 0,"aria-label":`${e.printer.name} ${r.label} ${n}mm`,value:s?String(s.cali_idx):``,onChange:t=>{let a=i.find(e=>String(e.cali_idx)===t.target.value)??null;S(e.printer.id,r.extruder,n,a)},className:`min-w-0 px-2 py-1.5 bg-bambu-dark-secondary border rounded-lg text-sm text-white focus:outline-none focus:border-bambu-green ${u?`border-amber-500/60`:`border-bambu-dark-tertiary`}`,children:[(0,G.jsx)(`option`,{value:``,children:d(`inventory.kProfileNotSet`)}),i.map(e=>{let t=g9(h9(e.nozzle_id));return(0,G.jsx)(`option`,{value:e.cali_idx,children:`${t?`[${t}] `:``}${e.name||e.filament_id} K=${e.k_value.toFixed(3)}`},e.cali_idx)})]},o)})]},n))]}):(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray italic py-1`,children:d(`inventory.printerOffline`)})]},e.printer.id)}):(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray italic`,children:d(`inventory.selectMaterialFirst`)})]})]})})]})]})}function x1e(e){let t=rp(e);return t?t.toLocaleDateString(`en-GB`,{day:`2-digit`,month:`2-digit`,year:`2-digit`})+` `+t.toLocaleTimeString(`en-GB`,{hour:`2-digit`,minute:`2-digit`}):``}var S1e={completed:`text-bambu-green`,failed:`text-red-700 dark:text-red-400`,aborted:`text-yellow-700 dark:text-yellow-400`};function C1e({spoolId:e}){let{t}=U(),n=co(),{showToast:r}=qd(),{data:i,isLoading:a}=K({queryKey:[`spool-usage`,e],queryFn:()=>Z.getSpoolUsageHistory(e)}),o=q({mutationFn:()=>Z.clearSpoolUsageHistory(e),onSuccess:()=>{n.invalidateQueries({queryKey:[`spool-usage`,e]}),r(t(`inventory.historyCleared`),`success`)}});return a?(0,G.jsx)(`div`,{className:`flex justify-center py-4`,children:(0,G.jsx)(Y,{className:`w-5 h-5 animate-spin text-bambu-green`})}):!i||i.length===0?(0,G.jsxs)(`div`,{className:`text-center py-4 text-bambu-gray text-sm`,children:[(0,G.jsx)(js,{className:`w-5 h-5 mx-auto mb-2 opacity-50`}),t(`inventory.noUsageHistory`)]}):(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`h4`,{className:`text-sm font-medium text-white`,children:t(`inventory.usageHistory`)}),(0,G.jsxs)(Q,{variant:`ghost`,size:`sm`,onClick:()=>o.mutate(),disabled:o.isPending,className:`text-xs text-bambu-gray hover:text-red-700 dark:hover:text-red-400`,children:[(0,G.jsx)(Pu,{className:`w-3 h-3 mr-1`}),t(`inventory.clearHistory`)]})]}),(0,G.jsx)(`div`,{className:`max-h-48 overflow-y-auto space-y-1`,children:i.map(e=>(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-2 rounded bg-bambu-dark/50 text-xs`,children:[(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:x1e(e.created_at)}),e.print_name&&(0,G.jsx)(`span`,{className:`text-white ml-2 truncate`,title:e.print_name,children:e.print_name})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0 ml-2`,children:[(0,G.jsxs)(`span`,{className:`text-white font-medium`,children:[e.weight_used.toFixed(1),`g`]}),(0,G.jsxs)(`span`,{className:`text-bambu-gray`,children:[`(`,e.percent_used,`%)`]}),(0,G.jsx)(`span`,{className:S1e[e.status]||`text-bambu-gray`,children:e.status})]})]},e.id))})]})}var w1e={tag_uid:null,tray_uuid:null,tag_type:null,data_origin:null};function T1e({isOpen:e,onClose:t,spool:n,mode:r,printersWithCalibrations:i=[],currencySymbol:a,onSpoolsCreated:o,spoolmanMode:s=!1,spoolsQueryKey:c=[`inventory-spools`]}){let{t:l}=U(),u=co(),{showToast:d}=qd(),f=()=>b6(u,c),p=r===`edit`,m=r===`copy`,[h,g]=(0,y.useState)(f9),[_,v]=(0,y.useState)({}),[b,x]=(0,y.useState)(`filament`),[S,C]=(0,y.useState)(!1),[w,T]=(0,y.useState)(!1),[E,D]=(0,y.useState)(!1),[O,k]=(0,y.useState)(1),[A,j]=(0,y.useState)(!1),[M,N]=(0,y.useState)(!1),[P,F]=(0,y.useState)([]),[I,L]=(0,y.useState)(new Set),[R,z]=(0,y.useState)(``),[B,V]=(0,y.useState)([]),[ee,te]=(0,y.useState)([]),[ne,re]=(0,y.useState)([]),[ie,ae]=(0,y.useState)([]),[oe,se]=(0,y.useState)([]),[H,ce]=(0,y.useState)([]),[le,ue]=(0,y.useState)([]),[de,fe]=(0,y.useState)(!1),[pe,me]=(0,y.useState)(new Map),[he,ge]=(0,y.useState)(new Map),[_e,ve]=(0,y.useState)(``),ye=i.length>0?i:le,be=pe.size+he.size,{data:xe=[],isLoading:Se,error:Ce}=K({queryKey:[`spoolman-inventory-filaments`],queryFn:()=>Z.getSpoolmanInventoryFilaments(),enabled:s&&e,staleTime:6e4,retry:!1});(0,y.useEffect)(()=>{ce(XH())},[]),(0,y.useEffect)(()=>{let t=!1;return e&&((async()=>{N(!0);try{let[e,n]=await Promise.allSettled([(async()=>(await Z.getCloudStatus()).is_authenticated?{connected:!0,presets:await Z.getFilamentPresets()}:{connected:!1,presets:[]})(),(async()=>(await Z.orcaCloudStatus()).connected?{connected:!0,presets:(await Z.orcaCloudListProfiles()).filament}:{connected:!1,presets:[]})()]);if(t)return;let r=e.status===`fulfilled`&&e.value.connected,i=n.status===`fulfilled`&&n.value.connected,a=e.status===`fulfilled`?e.value.presets:[],o=n.status===`fulfilled`?n.value.presets:[];j(r||i),F([...a,...o]),L(new Set(o.map(e=>e.setting_id)))}catch(e){if(t)return;console.error(`Failed to fetch cloud presets:`,e),j(!1)}finally{t||N(!1)}})(),s||Z.getSpoolCatalog().then(V).catch(console.error),Z.getColorCatalog().then(se).catch(console.error),Z.getLocalPresets().then(e=>re(e.filament)).catch(console.error),Z.getBuiltinFilaments().then(ae).catch(console.error),Z.getLocations().then(e=>te(e.map(e=>({id:e.id,name:e.name})))).catch(console.error),i.length===0&&(async()=>{fe(!0);try{let e=await Z.getPrinters(),n=await Promise.all(e.map(e=>Z.getPrinterStatus(e.id).catch(()=>null))),r=await Promise.all(e.map(async(e,t)=>{let r=n[t],i=r?.connected??!1,a=[];return i&&(a=await UH(e.id,r)),{printer:{...e,connected:i},calibrations:a,nozzles:r?.nozzles}}));t||ue(r)}catch(e){console.error(`Failed to fetch printer calibrations:`,e)}finally{t||fe(!1)}})()),()=>{t=!0}},[e,i.length]);let we=(0,y.useMemo)(()=>KH(P,new Set,ne,ie,I),[P,ne,ie,I]),Te=(0,y.useMemo)(()=>{let e=GH(P,ne),t=oe.map(e=>e.manufacturer?.trim()).filter(e=>!!e),n=new Set([...e,...t]);return Array.from(n).sort((e,t)=>e.localeCompare(t))},[P,ne,oe]),Ee=(0,y.useMemo)(()=>{let e=oe.map(e=>e.material?.trim()).filter(e=>!!e),t=new Set([...IH,...e]);return Array.from(t).sort((e,t)=>e.localeCompare(t))},[oe]),De=(0,y.useMemo)(()=>{let e=[];for(let t of oe){let n=t.manufacturer?.trim(),r=t.material?.trim();n&&r&&e.push({brand:n,material:r})}for(let t of P){let n=WH(t.name);n.brand&&n.material&&e.push({brand:n.brand,material:n.material})}for(let t of ne){let n=WH(t.name),r=t.filament_vendor?.trim()||n.brand,i=n.material;r&&i&&e.push({brand:r,material:i})}return e},[P,oe,ne]),Oe=(0,y.useMemo)(()=>{let e=new Map;for(let t of De){let n=t.brand.toLowerCase(),r=t.material.toLowerCase();e.has(n)||e.set(n,new Set),e.get(n).add(r)}return e},[De]),ke=(0,y.useMemo)(()=>{let e=new Map;for(let t of De){let n=t.brand.toLowerCase(),r=t.material.toLowerCase();e.has(r)||e.set(r,new Set),e.get(r).add(n)}return e},[De]),Ae=(0,y.useMemo)(()=>JH(Te,h.brand),[Te,h.brand]),je=(0,y.useMemo)(()=>JH(Ee,h.material),[Ee,h.material]),Me=(0,y.useMemo)(()=>YH(Ae,h.material,ke),[Ae,h.material,ke]),Ne=(0,y.useMemo)(()=>YH(je,h.brand,Oe),[je,h.brand,Oe]),Pe=(0,y.useMemo)(()=>qH(h.slicer_filament,we),[h.slicer_filament,we]);(0,y.useEffect)(()=>{if(e){if(n){let e=n.rgba&&/^[0-9A-Fa-f]{8}$/.test(n.rgba)?n.rgba:`808080FF`;if(g({material:n.material||``,subtype:n.subtype||``,brand:n.brand||``,color_name:n.color_name_is_synthesized?``:n.color_name||``,rgba:e,extra_colors:n.extra_colors||``,effect_type:n.effect_type||``,label_weight:n.label_weight||1e3,core_weight:n.core_weight||250,core_weight_catalog_id:n.core_weight_catalog_id??null,weight_used:m?0:n.weight_used||0,slicer_filament:n.slicer_filament||``,note:n.note||``,cost_per_kg:n.cost_per_kg??null,category:n.category||``,low_stock_threshold_pct:n.low_stock_threshold_pct??null,location_id:n.location_id??null,spoolman_filament_id:null}),z(n.slicer_filament_name||n.slicer_filament||``),n.k_profiles&&n.k_profiles.length>0){let e=new Map;for(let t of n.k_profiles){if(t.cali_idx===null||t.cali_idx===void 0)continue;let n=(t.nozzle_diameter||``).trim()||`0.4`,r=t.extruder??0;e.set(eU(t.printer_id,r,n),{cali_idx:t.cali_idx,filament_id:``,setting_id:t.setting_id||``,name:t.name||``,k_value:t.k_value,n_coef:0,extruder_id:r,nozzle_diameter:n,nozzle_id:t.nozzle_type||``})}me(e)}else me(new Map)}else g(f9),z(``),me(new Map);D(!1),k(1),v({}),x(`filament`),ve(``),ge(new Map),C(!1),T(!1)}},[e,n,r,m]),(0,y.useEffect)(()=>{if(!e||!n)return;let t=!1;return(s?Z.getSpoolmanFilamentPresets:Z.getSpoolFilamentPresets)(n.id).then(e=>{if(t)return;let n=new Map;for(let t of e)n.set(tU(t.printer_model,t.nozzle_diameter||``),{code:t.slicer_filament||``,name:t.slicer_filament_name||``});ge(n)}).catch(e=>{t||(console.error(`Failed to load filament preset overrides:`,e),d(l(`inventory.filamentPresetsLoadFailed`),`warning`))}),()=>{t=!0}},[e,n?.id,s]),(0,y.useEffect)(()=>{if(!e||!n||w||h.location_id!=null)return;let t=n.storage_location?.trim();if(!t||ee.length===0)return;let r=ee.find(e=>e.name.toLowerCase()===t.toLowerCase());r&&g(e=>e.location_id===r.id?e:{...e,location_id:r.id})},[e,n,ee,h.location_id,w]);let Fe=(e,t)=>{let n=o1e.has(e);s&&n&&h.spoolman_filament_id!==null&&d(l(`inventory.spoolmanFilamentUnlinked`),`info`),g(r=>({...r,[e]:t,...s&&n&&r.spoolman_filament_id!==null?{spoolman_filament_id:null}:{}})),e===`weight_used`&&C(!0),e===`location_id`&&T(!0),_[e]&&v(t=>({...t,[e]:void 0}))},Ie=e=>{let t=e.material||``,n=e.name||``,r=t&&n.startsWith(t)?n.slice(t.length).trim():n,i=(e.color_hex??``).replace(`#`,``).toUpperCase(),a=/^[0-9A-F]{6}(?:[0-9A-F]{2})?$/.test(i)?i:`808080`,o=a.length===8?a:`${a}FF`;g(n=>({...n,spoolman_filament_id:e.id,material:t,subtype:r,brand:e.vendor?.name||``,rgba:o,color_name:e.color_name||``,label_weight:e.weight??n.label_weight})),d(l(`inventory.spoolmanFilamentSelected`),`success`)},Le=e=>{ce(t=>ZH(e,t))},Re=q({mutationFn:e=>s?Z.createSpoolmanInventorySpool(e):Z.createSpool(e),onSuccess:async e=>{e?.id&&!await Ze(e.id)||(await f(),o&&o([e]),d(l(`inventory.spoolCreated`),`success`),t())},onError:e=>{e instanceof sd&&e.status===503?d(l(`inventory.spoolmanUnreachable`),`error`):d(l(`inventory.saveFailed`),`error`)}}),ze=q({mutationFn:({data:e,qty:t})=>s?Z.bulkCreateSpoolmanInventorySpools(e,t):Z.bulkCreateSpools(e,t),onSuccess:async e=>{let n=s&&`created`in e?e:null,r=n?n.created:e;if(pe.size>0||he.size>0)for(let e of r)await Ze(e.id);await f(),o&&o(r),n&&n.failed_count>0?d(l(`inventory.spoolsPartiallyCreated`,{created:r.length,total:n.requested_count}),`warning`):d(l(`inventory.spoolsCreated`,{count:r.length}),`success`),t()},onError:e=>{e instanceof sd&&e.status===503?d(l(`inventory.spoolmanUnreachable`),`error`):d(l(`inventory.saveFailed`),`error`)}}),Be=q({mutationFn:e=>s?Z.updateSpoolmanInventorySpool(n.id,e):Z.updateSpool(n.id,e),onSuccess:async()=>{n?.id&&!await Ze(n.id)||(await f(),d(l(`inventory.spoolUpdated`),`success`),t())},onError:e=>{e instanceof sd&&e.status===503?d(l(`inventory.spoolmanUnreachable`),`error`):d(l(`inventory.saveFailed`),`error`)}}),Ve=q({mutationFn:()=>s?Z.updateSpoolmanInventorySpool(n.id,w1e):Z.updateSpool(n.id,w1e),onSuccess:async()=>{await f(),d(l(`inventory.rfidCleared`,`RFID tag cleared`),`success`),t()},onError:e=>{e instanceof sd&&e.status===503?d(l(`inventory.spoolmanUnreachable`),`error`):d(l(`inventory.tagClearFailed`),`error`)}}),{data:He}=K({queryKey:[`spool-assignments`],queryFn:()=>Z.getAssignments(),enabled:e&&p&&!s}),{data:Ue}=K({queryKey:[`spoolman-slot-assignments-all`],queryFn:()=>Z.getSpoolmanSlotAssignments(),enabled:e&&p&&s}),We=(()=>{if(n)return s?Ue?.find(e=>e.spoolman_spool_id===n.id):He?.find(e=>e.spool_id===n.id)})(),{data:Ge}=K({queryKey:[`inventory-spools`],queryFn:()=>Z.getSpools(!0),enabled:e}),{data:Ke}=K({queryKey:[`settings`],queryFn:Z.getSettings,enabled:e}),{data:qe}=K({queryKey:[`slicerPrinterModels`],queryFn:Z.getSlicerPrinterModels,enabled:e,staleTime:1/0}),Je=(()=>{let e=new Set;for(let t of Ge??[]){let n=t.category?.trim();n&&e.add(n)}return Array.from(e).sort((e,t)=>e.localeCompare(t))})(),Ye=Ke?.low_stock_threshold??20,Xe=q({mutationFn:async()=>{if(!We)throw Error(`No assignment`);if(s){if(!n)throw Error(`No spool`);await Z.unassignSpoolmanSlot(n.id);return}await Z.unassignSpool(We.printer_id,We.ams_id,We.tray_id)},onSuccess:async()=>{s?(await u.invalidateQueries({queryKey:[`spoolman-slot-assignments-all`]}),await u.invalidateQueries({queryKey:[`spoolman-slot-assignments`]})):await u.invalidateQueries({queryKey:[`spool-assignments`]}),d(l(`inventory.unassignSuccess`,`Spool unassigned`),`success`),t()},onError:e=>{d(e.message,`error`)}}),Ze=async e=>{let t=s?Z.saveSpoolmanKProfiles:Z.saveSpoolKProfiles,n=s?Z.saveSpoolmanFilamentPresets:Z.saveSpoolFilamentPresets,r=[];for(let[e,t]of pe){let[n,i,a]=e.split(`:`);r.push({printer_id:parseInt(n),extruder:parseInt(i),nozzle_diameter:a||`0.4`,nozzle_type:h9(t.nozzle_id),k_value:t.k_value,name:t.name||null,cali_idx:t.cali_idx,setting_id:t.setting_id||null})}let i=[];for(let[e,t]of he){let{model:n,diameter:r}=xke(e);n&&i.push({printer_model:n,nozzle_diameter:r,slicer_filament:t.code||null,slicer_filament_name:t.name||null})}try{await t(e,r)}catch(e){return console.error(`Failed to save K-profiles:`,e),d(l(`inventory.kProfileSaveFailed`),`warning`),!1}try{await n(e,i)}catch(e){return console.error(`Failed to save filament preset overrides:`,e),d(l(`inventory.filamentPresetSaveFailed`),`warning`),!1}return!0};if((0,y.useEffect)(()=>{if(!e)return;let n=e=>{e.key===`Escape`&&t()};return document.addEventListener(`keydown`,n),()=>document.removeEventListener(`keydown`,n)},[e,t]),!e)return null;let Qe=()=>{let e=s1e(h,E,s,r);if(!e.isValid){v(e.errors),(e.errors.slicer_filament||e.errors.material||e.errors.brand||e.errors.subtype)&&x(`filament`);return}let t=Pe?.displayName||R||null,n={material:h.material||null,subtype:h.subtype||null,brand:h.brand||null,color_name:h.color_name||null,rgba:h.rgba||null,extra_colors:h.extra_colors||null,effect_type:h.effect_type||null,label_weight:h.label_weight,...s?{}:{core_weight:h.core_weight,core_weight_catalog_id:h.core_weight_catalog_id},slicer_filament:h.slicer_filament||null,slicer_filament_name:t,nozzle_temp_min:null,nozzle_temp_max:null,note:h.note||null,cost_per_kg:h.cost_per_kg,category:h.category.trim()||null,low_stock_threshold_pct:h.low_stock_threshold_pct,...s?{spoolman_filament_id:h.spoolman_filament_id}:{}};(!p||S)&&(n.weight_used=h.weight_used),(!p||w)&&(n.location_id=h.location_id),p?Be.mutate(n):O>1?ze.mutate({data:n,qty:O}):Re.mutate(n)},$e=Re.isPending||ze.isPending||Be.isPending||Ve.isPending||Xe.isPending;return(0,G.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[(0,G.jsx)(`div`,{className:`absolute inset-0 bg-black/60 backdrop-blur-sm`,onClick:t}),(0,G.jsxs)(`div`,{className:`relative w-full max-w-5xl mx-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl shadow-2xl max-h-[90vh] flex flex-col`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary flex-shrink-0`,children:[(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-baseline gap-2`,children:[l(p?`inventory.editSpool`:m?`inventory.copySpool`:`inventory.addSpool`),p&&n&&(0,G.jsxs)(`span`,{className:`text-sm font-mono text-bambu-gray`,children:[`#`,n.id]})]}),(0,G.jsx)(`button`,{onClick:t,className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]}),r===`create`&&(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2 border-b border-bambu-dark-tertiary flex-shrink-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(id,{className:`w-4 h-4 text-amber-600 dark:text-amber-400`}),(0,G.jsx)(`span`,{className:`text-sm text-white`,children:l(`inventory.quickAdd`)})]}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>{D(!E),E||x(`filament`)},className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors ${E?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,children:(0,G.jsx)(`span`,{className:`inline-block h-3.5 w-3.5 rounded-full bg-white transition-transform ${E?`translate-x-4`:`translate-x-0.5`}`})})]}),(0,G.jsxs)(`div`,{className:`flex border-b border-bambu-dark-tertiary flex-shrink-0`,children:[(0,G.jsxs)(`button`,{onClick:()=>x(`filament`),className:`flex-1 px-4 py-2.5 text-sm font-medium flex items-center justify-center gap-2 transition-colors ${b===`filament`?`text-bambu-green border-b-2 border-bambu-green`:`text-bambu-gray hover:text-white`}`,children:[(0,G.jsx)(Go,{className:`w-4 h-4`}),l(`inventory.filamentInfoTab`)]}),!E&&(0,G.jsxs)(`button`,{onClick:()=>x(`appearance`),className:`flex-1 px-4 py-2.5 text-sm font-medium flex items-center justify-center gap-2 transition-colors ${b===`appearance`?`text-bambu-green border-b-2 border-bambu-green`:`text-bambu-gray hover:text-white`}`,children:[(0,G.jsx)(wl,{className:`w-4 h-4`}),l(`inventory.colorAndCostTab`)]}),!E&&(0,G.jsxs)(`button`,{onClick:()=>x(`printers`),className:`flex-1 px-4 py-2.5 text-sm font-medium flex items-center justify-center gap-2 transition-colors ${b===`printers`?`text-bambu-green border-b-2 border-bambu-green`:`text-bambu-gray hover:text-white`}`,children:[(0,G.jsx)(id,{className:`w-4 h-4`}),l(`inventory.printersTab`),be>0&&(0,G.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded-full bg-bambu-green/20 text-bambu-green`,children:be})]})]}),(0,G.jsx)(`div`,{className:`p-4 overflow-y-auto flex-1`,style:{scrollbarGutter:`stable`},children:b===`filament`?(0,G.jsxs)(`div`,{className:`space-y-6`,children:[s&&!p&&(0,G.jsx)(`div`,{children:Ce?(0,G.jsx)(`p`,{className:`text-sm text-red-700 dark:text-red-400 px-1`,children:l(`inventory.spoolmanCatalogLoadFailed`)}):(0,G.jsx)(g1e,{filaments:xe,isLoading:Se,selectedId:h.spoolman_filament_id,onSelect:Ie})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`text-sm font-semibold text-bambu-gray uppercase tracking-wide mb-3`,children:l(`inventory.filamentInfo`)}),(0,G.jsx)(d1e,{formData:h,updateField:Fe,cloudAuthenticated:A,loadingCloudPresets:M,presetInputValue:R,setPresetInputValue:z,selectedPresetOption:Pe,filamentOptions:we,availableBrands:Ae,availableMaterials:je,suggestedBrands:Me,suggestedMaterials:Ne,quickAdd:E,detailsRequired:!E&&!s&&r===`create`,quantity:O,onQuantityChange:k,errors:_})]})]}):b===`appearance`?(0,G.jsxs)(`div`,{className:`space-y-6`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`text-sm font-semibold text-bambu-gray uppercase tracking-wide mb-3`,children:l(`inventory.color`)}),(0,G.jsx)(p1e,{formData:h,updateField:Fe,recentColors:H,onColorUsed:Le,catalogColors:oe})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`text-sm font-semibold text-bambu-gray uppercase tracking-wide mb-3`,children:l(`inventory.additional`)}),(0,G.jsx)(h1e,{formData:h,updateField:Fe,spoolCatalog:B,currencySymbol:a,availableCategories:Je,availableLocations:ee,onCreateLocation:async e=>{try{let t=await Z.createLocation({name:e});return te(e=>[...e,{id:t.id,name:t.name}].sort((e,t)=>e.name.localeCompare(t.name))),await y6(u),{id:t.id,name:t.name}}catch(e){return console.error(e),d((e instanceof Error?e.message:l(`locations.saveFailed`))||l(`locations.saveFailed`),`error`),null}},globalLowStockThreshold:Ye,spoolmanMode:s})]}),p&&n&&!s&&(0,G.jsx)(`div`,{children:(0,G.jsx)(C1e,{spoolId:n.id})})]}):(0,G.jsx)(b1e,{formData:h,printersWithCalibrations:ye,filamentOptions:we,modelPresets:he,setModelPresets:ge,selectedProfiles:pe,setSelectedProfiles:me,selectedGroupId:_e,setSelectedGroupId:ve,printerModels:qe,isLoading:de})}),(0,G.jsxs)(`div`,{className:`flex gap-2 p-4 border-t border-bambu-dark-tertiary flex-shrink-0`,children:[p&&(0,G.jsxs)(`div`,{className:`flex gap-2 mr-auto`,children:[(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>Ve.mutate(),disabled:$e||!n?.tag_uid,children:[(0,G.jsx)(Eu,{className:`w-4 h-4`}),l(`inventory.clearRfid`,`Clear RFID Tag`)]}),(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>Xe.mutate(),disabled:$e||!We,children:[(0,G.jsx)(Bu,{className:`w-4 h-4`}),l(`inventory.unassignSpool`,`Unassign`)]})]}),(0,G.jsxs)(`div`,{className:`flex gap-2 ml-auto`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:t,children:l(`common.cancel`)}),(0,G.jsx)(Q,{onClick:Qe,disabled:$e,children:$e?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),l(`common.saving`)]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(ql,{className:`w-4 h-4`}),l(p?`common.save`:m?`inventory.copySpool`:`inventory.addSpool`)]})})]})]})]})]})}var E1e=[{value:`ams_holder_74x33`,i18nKey:`amsHolderSmall`,fallbackLabel:`AMS holder — small (74 × 33 mm)`,fallbackHint:`Single label per page; matches the printable label from MakerWorld model 752566 (AMS Filament Label Holder).`},{value:`ams_holder_75x55`,i18nKey:`amsHolderLarge`,fallbackLabel:`AMS holder — large (75 × 55 mm)`,fallbackHint:`Single label per page; fits the cardstock-insert variant of the AMS Filament Label Holder. Roomy enough for swatch, brand, material, ID, and QR code.`},{value:`box_40x30`,i18nKey:`box40x30`,fallbackLabel:`Box label (40 × 30 mm)`,fallbackHint:`Single label per page; common DK/Brother roll size, good for filament-bag and storage-bin labels.`},{value:`box_62x29`,i18nKey:`box`,fallbackLabel:`Box label (62 × 29 mm)`,fallbackHint:`Single label per page; sized for Brother PT/QL and Dymo small labels.`},{value:`avery_l7160`,i18nKey:`averyL7160`,fallbackLabel:`Avery L7160 — A4 sheet (38.1 × 63.5 mm × 21)`,fallbackHint:`EU sheet stock; 21 labels per A4 page.`},{value:`avery_5160`,i18nKey:`avery5160`,fallbackLabel:`Avery 5160 — US Letter sheet (25.4 × 66.7 mm × 30)`,fallbackHint:`US sheet stock; 30 labels per Letter page.`}],_9={avery_l7160:21,avery_5160:30},v9=Math.max(...Object.values(_9));function D1e(e){let t=window.URL.createObjectURL(e);if(!window.open(t,`_blank`)){let e=document.createElement(`a`);e.href=t,e.download=`bambuddy-labels.pdf`,document.body.appendChild(e),e.click(),document.body.removeChild(e)}setTimeout(()=>window.URL.revokeObjectURL(t),6e4)}function O1e(e){return Mf(e)}function k1e(e){return`${e.color_name??`${e.material}${e.subtype?` ${e.subtype}`:``}`}${e.brand?` · ${e.brand}`:``}`}function A1e(e){return[e.color_name,e.material,e.subtype,e.brand,`#${e.id}`].filter(Boolean).join(` `).toLowerCase()}function j1e(e){if(!e)return[1,0];let t=e.replace(/^#/,``).slice(0,6);if(t.length!==6)return[1,0];let n=parseInt(t.slice(0,2),16),r=parseInt(t.slice(2,4),16),i=parseInt(t.slice(4,6),16);if([n,r,i].some(Number.isNaN))return[1,0];let a=n/255,o=r/255,s=i/255,c=Math.max(a,o,s),l=Math.min(a,o,s),u=(c+l)/2,d=c-l;if((d===0?0:d/(1-Math.abs(2*u-1)))<.1)return[1,u];let f=0;return f=c===a?(o-s)/d%6:c===o?(s-a)/d+2:(a-o)/d+4,f*=60,f<0&&(f+=360),[0,f]}function M1e({isOpen:e,onClose:t,availableSpools:n,initialSelectedIds:r,spoolmanMode:i}){let{t:a}=U(),{showToast:o}=qd(),[s,c]=(0,y.useState)(null),[l,u]=(0,y.useState)(new Set),[d,f]=(0,y.useState)(``),[p,m]=(0,y.useState)(``),[h,g]=(0,y.useState)(`id`),[_,v]=(0,y.useState)(!1),[b,x]=(0,y.useState)(`1`);(0,y.useEffect)(()=>{if(e){let e=new Set(n.map(e=>e.id));u(new Set(r.filter(t=>e.has(t)))),f(``),m(``),g(`id`),v(!1),x(`1`),c(null)}},[e]);let S=(0,y.useMemo)(()=>{let e=[...n];return h===`color`?(e.sort((e,t)=>{let n=j1e(e.rgba),r=j1e(t.rgba);return n[0]===r[0]?n[1]===r[1]?e.id-t.id:n[1]-r[1]:n[0]-r[0]}),e):(e.sort((e,t)=>e.id-t.id),e)},[n,h]),C=(0,y.useMemo)(()=>{let e=new Set;for(let t of S)t.material&&e.add(t.material.toUpperCase());return[...e].sort()},[S]),w=(0,y.useMemo)(()=>{let e=d.trim().toLowerCase();return S.filter(t=>!(p&&(t.material||``).toUpperCase()!==p||e&&!A1e(t).includes(e)))},[S,d,p]),T=w.length>0&&w.every(e=>l.has(e.id));if(!e)return null;let E=l.size,D=E===0,O=Number(b),k=Number.isInteger(O)&&O>=1&&O<=v9;function A(e){u(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function j(){u(e=>{let t=new Set(e);for(let e of w)t.add(e.id);return t})}function M(){u(e=>{let t=new Set(e);for(let e of w)t.delete(e.id);return t})}function N(){u(new Set)}async function P(e){if(D||s)return;let n=_9[e];if(n!==void 0&&(!k||O>n)){o(a(`inventory.labels.startingPositionRangeError`,`Starting position must be between 1 and {{capacity}} for this sheet.`,{capacity:n}),`error`);return}let r=S.filter(e=>l.has(e.id)).map(e=>e.id);c(e);try{D1e(i?await Z.printSpoolmanSpoolLabels({spool_ids:r,template:e,monochrome:_,starting_position:n===void 0?1:O}):await Z.printSpoolLabels({spool_ids:r,template:e,monochrome:_,starting_position:n===void 0?1:O})),t()}catch(e){o(a(`inventory.labels.error`,`Could not generate labels: {{msg}}`,{msg:e instanceof Error?e.message:String(e)}),`error`)}finally{c(null)}}return(0,G.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-start sm:items-center justify-center p-4 overflow-y-auto`,children:[(0,G.jsx)(`div`,{className:`absolute inset-0 bg-black/60 backdrop-blur-sm`,onClick:t}),(0,G.jsxs)(`div`,{"data-testid":`label-template-picker-panel`,className:`relative w-full max-w-3xl bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl shadow-2xl max-h-[90vh] overflow-clip flex flex-col my-auto`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Rl,{className:`w-5 h-5 text-bambu-green`}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:a(`inventory.labels.title`,`Print spool labels`)}),E>0&&(0,G.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[`(`,a(`inventory.labels.selectedCount`,`{{count}} selected`,{count:E}),`)`]})]}),(0,G.jsx)(`button`,{onClick:t,className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,"aria-label":a(`common.close`,`Close`),children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]}),(0,G.jsxs)(`div`,{className:`p-4 space-y-2 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(Ql,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`}),(0,G.jsx)(`input`,{type:`search`,value:d,onChange:e=>f(e.target.value),placeholder:a(`inventory.labels.searchPlaceholder`,`Search name, brand, or #ID`),className:`w-full pl-9 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray focus:outline-none focus:border-bambu-green`})]}),C.length>1&&(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray mr-1`,children:a(`inventory.labels.filterByMaterial`,`Material:`)}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>m(``),className:`px-2 py-0.5 text-xs rounded-full border transition ${p===``?`bg-bambu-green text-bambu-dark border-bambu-green`:`bg-bambu-dark text-bambu-gray border-bambu-dark-tertiary hover:border-bambu-gray`}`,children:a(`inventory.labels.allMaterials`,`All`)}),C.map(e=>(0,G.jsx)(`button`,{type:`button`,onClick:()=>m(e),className:`px-2 py-0.5 text-xs rounded-full border transition ${p===e?`bg-bambu-green text-bambu-dark border-bambu-green`:`bg-bambu-dark text-bambu-gray border-bambu-dark-tertiary hover:border-bambu-gray`}`,children:e},e))]}),(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray mr-1`,children:a(`inventory.labels.sortBy.label`)}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>g(`id`),className:`px-2 py-0.5 text-xs rounded-full border transition ${h===`id`?`bg-bambu-green text-bambu-dark border-bambu-green`:`bg-bambu-dark text-bambu-gray border-bambu-dark-tertiary hover:border-bambu-gray`}`,children:a(`inventory.labels.sortBy.id`)}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>g(`color`),className:`px-2 py-0.5 text-xs rounded-full border transition ${h===`color`?`bg-bambu-green text-bambu-dark border-bambu-green`:`bg-bambu-dark text-bambu-gray border-bambu-dark-tertiary hover:border-bambu-gray`}`,children:a(`inventory.labels.sortBy.color`)})]})]}),(0,G.jsxs)(`div`,{className:`px-4 pt-3 pb-2 flex items-center justify-between gap-3 flex-wrap`,children:[(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:a(`inventory.labels.pickSpools`,`Pick which spools to print labels for:`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-3 text-xs`,children:[(0,G.jsx)(`button`,{type:`button`,onClick:T?M:j,disabled:w.length===0,className:`text-bambu-green hover:underline disabled:opacity-50 disabled:no-underline disabled:cursor-not-allowed`,children:T?a(`inventory.labels.deselectVisible`,`Deselect visible`):a(`inventory.labels.selectVisible`,`Select all visible ({{count}})`,{count:w.length})}),(0,G.jsx)(`button`,{type:`button`,onClick:N,disabled:E===0,className:`text-bambu-gray hover:text-white hover:underline disabled:opacity-50 disabled:no-underline disabled:cursor-not-allowed`,children:a(`inventory.labels.clearAll`,`Clear all`)})]})]}),(0,G.jsx)(`div`,{className:`flex-1 overflow-y-auto px-2 pb-2 min-h-0`,children:w.length===0?(0,G.jsx)(`div`,{className:`text-center text-sm text-bambu-gray py-6`,children:S.length===0?a(`inventory.labels.noSpoolsToShow`,`No spools to show. Adjust your filter and try again.`):a(`inventory.labels.noMatches`,`No spools match the current search or filter.`)}):(0,G.jsx)(`ul`,{className:`space-y-0.5`,children:w.map(e=>{let t=l.has(e.id);return(0,G.jsx)(`li`,{children:(0,G.jsxs)(`label`,{className:`flex items-center gap-3 px-2 py-1.5 rounded hover:bg-bambu-dark-tertiary/50 cursor-pointer`,children:[t?(0,G.jsx)(vu,{className:`w-4 h-4 text-bambu-green shrink-0`}):(0,G.jsx)(bu,{className:`w-4 h-4 text-bambu-gray shrink-0`}),(0,G.jsx)(`input`,{type:`checkbox`,checked:t,onChange:()=>A(e.id),className:`sr-only`}),(0,G.jsx)(`span`,{className:`w-4 h-4 rounded border border-black/20 shrink-0`,style:O1e(e.rgba)}),(0,G.jsx)(`span`,{className:`flex-1 min-w-0 truncate text-sm text-white`,children:k1e(e)}),(0,G.jsxs)(`span`,{className:`text-xs font-mono text-bambu-gray shrink-0`,children:[`#`,e.id]})]})},e.id)})})}),(0,G.jsxs)(`div`,{className:`px-4 pt-2 pb-1 border-t border-bambu-dark-tertiary space-y-2`,children:[(0,G.jsxs)(`label`,{className:`inline-flex items-center gap-2 cursor-pointer select-none`,children:[_?(0,G.jsx)(vu,{className:`w-4 h-4 text-bambu-green shrink-0`}):(0,G.jsx)(bu,{className:`w-4 h-4 text-bambu-gray shrink-0`}),(0,G.jsx)(`input`,{type:`checkbox`,checked:_,onChange:e=>v(e.target.checked),className:`sr-only`}),(0,G.jsx)(`span`,{className:`text-sm text-white`,children:a(`inventory.labels.monochrome`,`Monochrome (black & white printer)`)}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:a(`inventory.labels.monochromeHint`,`Drops the colour swatch and widens the text`)})]}),(0,G.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,G.jsx)(`label`,{htmlFor:`label-starting-position`,className:`text-sm text-white whitespace-nowrap pt-1.5`,children:a(`inventory.labels.startingPosition`,`Starting label position`)}),(0,G.jsx)(`input`,{id:`label-starting-position`,"data-testid":`label-starting-position`,type:`number`,min:1,max:v9,step:1,value:b,onChange:e=>x(e.target.value),"aria-describedby":`label-starting-position-help`,className:`w-20 px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:outline-none focus:border-bambu-green`}),(0,G.jsxs)(`div`,{id:`label-starting-position-help`,className:`text-xs text-bambu-gray pt-1.5`,children:[(0,G.jsx)(`div`,{children:a(`inventory.labels.startingPositionRange`,`Sheet templates only: L7160 supports 1–21; 5160 supports 1–30.`)}),(0,G.jsx)(`div`,{"data-testid":`label-starting-position-status`,className:k?``:`text-red-400`,children:k?O===1?a(`inventory.labels.startingPositionFirst`,`Printing starts at position 1.`):a(`inventory.labels.startingPositionSkipped`,`Positions 1 through {{lastPosition}} will be left blank on the first sheet.`,{lastPosition:O-1}):a(`inventory.labels.startingPositionInvalid`,`Enter a whole number from 1 to {{capacity}}.`,{capacity:v9})})]})]})]}),(0,G.jsx)(`div`,{className:`px-3 pt-1 pb-2 grid grid-cols-1 sm:grid-cols-2 gap-2`,children:E1e.map(e=>{let t=s===e.value,n=_9[e.value],r=n!==void 0&&(!k||O>n),i=a(`inventory.labels.templates.${e.i18nKey}.label`,e.fallbackLabel),o=r?a(`inventory.labels.startingPositionRangeError`,`Starting position must be between 1 and {{capacity}} for this sheet.`,{capacity:n}):a(`inventory.labels.templates.${e.i18nKey}.hint`,e.fallbackHint);return(0,G.jsxs)(`button`,{"data-testid":`print-labels-${e.value}`,disabled:D||s!==null||r,onClick:()=>P(e.value),title:`${i} — ${o}`,className:`w-full text-left p-2.5 rounded-lg border border-bambu-dark-tertiary bg-bambu-dark hover:border-bambu-green hover:bg-bambu-green/10 disabled:opacity-50 disabled:cursor-not-allowed disabled:hover:border-bambu-dark-tertiary disabled:hover:bg-bambu-dark transition flex items-center gap-3`,children:[(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`div`,{className:`font-medium text-white text-sm truncate`,children:i}),(0,G.jsx)(`div`,{className:`text-xs text-bambu-gray mt-0.5 truncate`,children:o})]}),t&&(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin text-bambu-green shrink-0`})]},e.value)})}),(0,G.jsx)(`div`,{className:`flex justify-end gap-2 px-5 py-2 border-t border-bambu-dark-tertiary`,children:(0,G.jsx)(Q,{variant:`secondary`,onClick:t,disabled:s!==null,children:a(`common.cancel`,`Cancel`)})})]})]})}function N1e({onClose:e,onImported:t}){let{t:n}=U(),[r,i]=(0,y.useState)(null),[a,o]=(0,y.useState)(!1),[s,c]=(0,y.useState)(null),[l,u]=(0,y.useState)(!1),[d,f]=(0,y.useState)(!1),[p,m]=(0,y.useState)(null),h=(0,y.useRef)(null),g=async e=>{i(e),c(null),m(null),u(!0);try{c(await Z.importSpoolsCsvPreview(e))}catch(e){m(e instanceof Error?e.message:n(`inventory.csv.previewError`,`Could not read the CSV file`))}finally{u(!1)}},_=e=>{let t=e.target.files?.[0];t&&g(t)},v=e=>{e.preventDefault(),o(!1);let t=e.dataTransfer.files?.[0];t&&g(t)},b=async()=>{if(r){f(!0),m(null);try{t((await Z.importSpoolsCsv(r)).created)}catch(e){m(e instanceof Error?e.message:n(`inventory.csv.importError`,`Import failed`)),f(!1)}}},x=e=>e===`valid`?(0,G.jsx)(xs,{className:`w-4 h-4 text-green-500 flex-shrink-0`}):e===`error`?(0,G.jsx)(Ds,{className:`w-4 h-4 text-red-500 flex-shrink-0`}):(0,G.jsx)(ws,{className:`w-4 h-4 text-bambu-gray flex-shrink-0`}),S=s?.valid_count??0;return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg w-full max-w-3xl border border-bambu-dark-tertiary flex flex-col max-h-[90vh]`,children:[(0,G.jsxs)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary flex items-center justify-between`,children:[(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:n(`inventory.csv.modalTitle`,`Import spools from CSV`)}),(0,G.jsx)(`button`,{onClick:e,className:`p-1 hover:bg-bambu-dark rounded`,children:(0,G.jsx)(nd,{className:`w-5 h-5 text-bambu-gray`})})]}),(0,G.jsxs)(`div`,{className:`p-4 space-y-4 overflow-y-auto flex-1`,children:[(0,G.jsxs)(`div`,{onDragOver:e=>{e.preventDefault(),o(!0)},onDragLeave:e=>{e.preventDefault(),o(!1)},onDrop:v,onClick:()=>h.current?.click(),className:`border-2 border-dashed rounded-lg p-6 text-center cursor-pointer transition-colors ${a?`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary hover:border-bambu-green/50`}`,children:[(0,G.jsx)(Vu,{className:`w-9 h-9 mx-auto mb-2 ${a?`text-bambu-green`:`text-bambu-gray`}`}),r?(0,G.jsxs)(`p`,{className:`text-white font-medium flex items-center justify-center gap-2`,children:[(0,G.jsx)(fc,{className:`w-4 h-4`}),` `,r.name]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`p`,{className:`text-white font-medium`,children:n(`inventory.csv.selectFile`,`Choose a CSV file or drag it here`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray/70 mt-1`,children:n(`inventory.csv.dragHint`,`Header: material (required), brand, subtype, color_name, rgba, …`)})]})]}),(0,G.jsx)(`input`,{ref:h,type:`file`,accept:`.csv,text/csv`,className:`hidden`,onChange:_}),l&&(0,G.jsxs)(`div`,{className:`flex items-center justify-center gap-2 text-bambu-gray py-4`,children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),n(`inventory.csv.parsing`,`Reading file…`)]}),p&&(0,G.jsxs)(`div`,{className:`p-3 bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30 rounded-lg flex items-start gap-3`,children:[(0,G.jsx)(Ds,{className:`w-5 h-5 text-red-600 dark:text-red-400 mt-0.5 flex-shrink-0`}),(0,G.jsx)(`p`,{className:`text-sm text-red-700 dark:text-red-300 break-words`,children:p})]}),s&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-3 text-sm`,children:[(0,G.jsx)(`span`,{className:`px-2 py-1 rounded bg-green-50 dark:bg-green-500/10 text-green-700 dark:text-green-400`,children:n(`inventory.csv.validCount`,`{{count}} valid`,{count:s.valid_count})}),(0,G.jsx)(`span`,{className:`px-2 py-1 rounded bg-red-50 dark:bg-red-500/10 text-red-700 dark:text-red-400`,children:n(`inventory.csv.errorCount`,`{{count}} error`,{count:s.error_count})}),(0,G.jsx)(`span`,{className:`px-2 py-1 rounded bg-bambu-dark text-bambu-gray`,children:n(`inventory.csv.skippedCount`,`{{count}} skipped`,{count:s.skipped_count})})]}),s.warnings.length>0&&(0,G.jsx)(`div`,{className:`p-3 bg-yellow-50 dark:bg-yellow-500/10 border border-yellow-300 dark:border-yellow-500/30 rounded-lg space-y-1`,children:s.warnings.map((e,t)=>(0,G.jsx)(`p`,{className:`text-xs text-yellow-700 dark:text-yellow-300`,children:e},t))}),s.rows.length>0&&(0,G.jsx)(`div`,{className:`border border-bambu-dark-tertiary rounded-lg overflow-hidden`,children:(0,G.jsx)(`div`,{className:`max-h-72 overflow-y-auto`,children:(0,G.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,G.jsx)(`thead`,{className:`bg-bambu-dark sticky top-0`,children:(0,G.jsxs)(`tr`,{className:`text-left text-bambu-gray`,children:[(0,G.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:n(`inventory.csv.colRow`,`Row`)}),(0,G.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:n(`inventory.csv.colStatus`,`Status`)}),(0,G.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:n(`inventory.material`,`Material`)}),(0,G.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:n(`inventory.brand`,`Brand`)}),(0,G.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:n(`inventory.csv.colColor`,`Color`)})]})}),(0,G.jsx)(`tbody`,{children:s.rows.map(e=>(0,G.jsxs)(`tr`,{className:`border-t border-bambu-dark-tertiary`,children:[(0,G.jsx)(`td`,{className:`px-3 py-2 text-bambu-gray`,children:e.row_number}),(0,G.jsx)(`td`,{className:`px-3 py-2`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[x(e.status),e.status===`error`&&e.reason&&(0,G.jsx)(`span`,{className:`text-xs text-red-700 dark:text-red-400 break-words`,children:e.reason})]})}),(0,G.jsx)(`td`,{className:`px-3 py-2 text-white`,children:e.material||`—`}),(0,G.jsx)(`td`,{className:`px-3 py-2 text-white`,children:e.brand||`—`}),(0,G.jsx)(`td`,{className:`px-3 py-2`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.rgba&&(0,G.jsx)(`span`,{className:`inline-block w-4 h-4 rounded-full border border-bambu-dark-tertiary flex-shrink-0`,style:Mf(e.rgba)}),(0,G.jsx)(`span`,{className:`text-white`,children:e.color_name||`—`}),e.resolved_color&&!e.cross_material_color&&(0,G.jsx)(`span`,{title:n(`inventory.csv.colorResolved`,`Color filled from catalog`),children:(0,G.jsx)(Yu,{className:`w-3.5 h-3.5 text-bambu-green flex-shrink-0`})}),e.cross_material_color&&(0,G.jsx)(`span`,{title:n(`inventory.csv.colorCrossMaterial`,`Color taken from a different material — no exact match in catalog`),children:(0,G.jsx)(Lu,{className:`w-3.5 h-3.5 text-yellow-500 flex-shrink-0`})}),e.duplicate_of_existing&&(0,G.jsx)(`span`,{title:n(`inventory.csv.duplicateExisting`,`A spool with this material, brand and color already exists — it will still be imported as a new spool`),children:(0,G.jsx)(Vs,{className:`w-3.5 h-3.5 text-amber-600 dark:text-amber-400 flex-shrink-0`})})]})})]},e.row_number))})]})})})]})]}),(0,G.jsxs)(`div`,{className:`p-4 border-t border-bambu-dark-tertiary flex justify-end gap-2`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:e,disabled:d,children:n(`common.cancel`)}),(0,G.jsx)(Q,{onClick:b,disabled:!s||S===0||d,children:d?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 mr-2 animate-spin`}),n(`inventory.csv.importing`,`Importing…`)]}):S>0?n(`inventory.csv.importValidRows`,`Import {{count}} valid rows`,{count:S}):n(`inventory.csv.noValidRows`,`No valid rows`)})]})]})})}var y9=[{id:`material`,type:`searchable`,labelKey:`inventory.material`},{id:`subtype`,type:`searchable`,labelKey:`inventory.subtype`},{id:`brand`,type:`searchable`,labelKey:`inventory.brand`},{id:`color_name`,type:`text`,labelKey:`inventory.colorName`},{id:`rgba`,type:`color`,labelKey:`inventory.color`,pattern:`^[0-9A-Fa-f]{6}([0-9A-Fa-f]{2})?$`},{id:`location_id`,type:`searchableClosed`,labelKey:`inventory.storageLocation`},{id:`slicer_filament_name`,type:`searchable`,labelKey:`inventory.slicerFilamentName`},{id:`slicer_filament`,type:`searchable`,labelKey:`inventory.slicerFilament`},{id:`cost_per_kg`,type:`number`,labelKey:`inventory.costPerKg`,min:0,step:.01},{id:`note`,type:`textarea`,labelKey:`inventory.note`},{id:`label_weight`,type:`number`,labelKey:`inventory.labelWeight`,min:1,step:1},{id:`core_weight`,type:`number`,labelKey:`inventory.coreWeight`,min:0,step:1},{id:`category`,type:`searchable`,labelKey:`inventory.category`},{id:`low_stock_threshold_pct`,type:`number`,labelKey:`inventory.lowStockThresholdOverride`,min:1,max:99,step:1}];function P1e({value:e,onChange:t,options:n,allowCustom:r,placeholderKey:i,disabled:a}){let{t:o}=U(),s=(0,y.useRef)(null),[c,l]=(0,y.useState)(!1),[u,d]=(0,y.useState)(``);(0,y.useEffect)(()=>{if(!c)return;let e=e=>{s.current&&!s.current.contains(e.target)&&(l(!1),d(``))},t=e=>{e.key===`Escape`&&(l(!1),d(``))};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[c]);let f=c?u:n.find(t=>t.value===e)?.label??e,p=(0,y.useMemo)(()=>{if(!c)return n;let e=u.trim().toLowerCase();return e?n.filter(t=>t.label.toLowerCase().includes(e)||t.value.toLowerCase().includes(e)):n},[c,u,n]),m=c&&u.trim()&&!n.some(e=>e.value.toLowerCase()===u.trim().toLowerCase());return(0,G.jsxs)(`div`,{className:`relative`,ref:s,children:[(0,G.jsx)(`input`,{type:`text`,disabled:a,value:f,onChange:e=>{d(e.target.value),l(!0),r&&t(e.target.value)},onFocus:()=>{l(!0),d(``)},placeholder:i?o(i):void 0,className:`w-full px-3 py-2 pr-9 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray/50 focus:border-bambu-green focus:outline-none`}),(0,G.jsx)(ps,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50 pointer-events-none`}),c&&(0,G.jsxs)(`div`,{className:`absolute z-50 left-0 right-0 mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-64 overflow-y-auto`,children:[p.length===0&&!r&&(0,G.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:o(`inventory.noResults`)}),p.map(n=>(0,G.jsx)(`button`,{type:`button`,className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${e===n.value?`bg-bambu-green/10 text-bambu-green`:`text-white`}`,onClick:()=>{t(n.value),l(!1),d(``)},children:n.label},n.value)),r&&m&&(0,G.jsx)(`button`,{type:`button`,className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary text-bambu-green border-t border-bambu-dark-tertiary`,onClick:()=>{t(u.trim()),l(!1),d(``)},children:o(`inventory.bulk.useCustom`,{value:u.trim()})})]})]})}function b9(...e){let t=new Set;for(let n of e)for(let e of n){let n=e?.trim();n&&t.add(n)}return Array.from(t).sort((e,t)=>e.localeCompare(t))}function F1e({isOpen:e,selectedCount:t,isPending:n,availableLocations:r,availableMaterials:i,availableSubtypes:a,availableBrands:o,availableCategories:s,availableSlicerFilaments:c,availableSlicerFilamentNames:l,onClose:u,onApply:d}){let{t:f}=U(),{data:p=[]}=K({queryKey:[`bulk-edit-cloud-presets`],enabled:e,staleTime:300*1e3,queryFn:async()=>{let e=[];try{if((await Z.getCloudStatus()).is_authenticated){let t=await Z.getFilamentPresets();e.push(...t)}}catch{}try{if((await Z.orcaCloudStatus()).connected){let t=await Z.orcaCloudListProfiles();e.push(...t.filament)}}catch{}return e}}),{data:m}=K({queryKey:[`bulk-edit-local-presets`],enabled:e,staleTime:300*1e3,queryFn:Z.getLocalPresets}),{data:h=[]}=K({queryKey:[`builtin-filaments`],enabled:e,staleTime:300*1e3,queryFn:Z.getBuiltinFilaments}),g=(0,y.useMemo)(()=>KH(p,new Set,m?.filament??[],h),[p,m,h]),[_,v]=(0,y.useState)({}),b=(0,y.useMemo)(()=>b9(IH,i).map(e=>({value:e,label:e})),[i]),x=(0,y.useMemo)(()=>b9(RH,a).map(e=>({value:e,label:e})),[a]),S=(0,y.useMemo)(()=>b9(LH,o).map(e=>({value:e,label:e})),[o]),C=(0,y.useMemo)(()=>b9(s).map(e=>({value:e,label:e})),[s]),w=(0,y.useMemo)(()=>{let e=g.map(e=>({value:e.code,label:e.displayName})),t=c.filter(t=>!e.some(e=>e.value===t)).map(e=>({value:e,label:e}));return[...e,...t].sort((e,t)=>e.label.localeCompare(t.label))},[g,c]),T=(0,y.useMemo)(()=>{let e=g.map(e=>({value:e.displayName,label:e.displayName})),t=l.filter(t=>!e.some(e=>e.value===t)).map(e=>({value:e,label:e}));return[...e,...t].sort((e,t)=>e.label.localeCompare(t.label))},[g,l]),E=(0,y.useMemo)(()=>r.map(e=>({value:String(e.id),label:e.name})),[r]);if(!e)return null;let D=(e,t)=>{v(n=>({...n,[e]:t}))},O=e=>{v(t=>{let n={...t};return delete n[e],n})},k=(()=>{let e={};for(let t of y9){let n=_[t.id];if(n===void 0)continue;let r=typeof n==`string`?n.trim():n;if(!(r===``||r===null))if(t.type===`number`){let n=Number(r);Number.isFinite(n)&&(e[t.id]=n)}else if(t.id===`location_id`){let n=Number(r);Number.isFinite(n)&&n>0&&(e[t.id]=n)}else if(t.id===`rgba`){let n=String(r).replace(/^#/,``),i=n.length===6?`${n}FF`:n;/^[0-9A-Fa-f]{8}$/.test(i)&&(e[t.id]=i.toUpperCase())}else e[t.id]=String(r)}return e})(),A=Object.keys(k).length>0,j=y9.some(e=>{let t=_[e.id];return t===void 0||t.trim()===``?!1:k[e.id]===void 0}),M=e=>e===`material`?b:e===`subtype`?x:e===`brand`?S:e===`category`?C:e===`slicer_filament`?w:e===`slicer_filament_name`?T:e===`location_id`?E:[],N=e=>{let t=_[e.id]??``;if(e.type===`searchable`||e.type===`searchableClosed`)return(0,G.jsx)(P1e,{value:t,onChange:t=>{t===``?O(e.id):D(e.id,t)},options:M(e.id),allowCustom:e.type===`searchable`,disabled:n});if(e.type===`textarea`)return(0,G.jsx)(`textarea`,{disabled:n,value:t,onChange:t=>D(e.id,t.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray/50 focus:border-bambu-green focus:outline-none resize-none min-h-[60px]`});if(e.type===`color`){let r=t.trim().replace(/^#/,``),i=r.length===6?`${r}FF`:r,a=t.trim()!==``&&!/^[0-9A-Fa-f]{8}$/.test(i);return(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`input`,{type:`color`,disabled:n,value:`#${(t||`808080`).replace(/^#/,``).slice(0,6)}`,onChange:t=>D(e.id,t.target.value.replace(/^#/,``).toUpperCase()),className:`h-9 w-12 rounded cursor-pointer`}),(0,G.jsx)(`input`,{type:`text`,disabled:n,value:t,onChange:t=>D(e.id,t.target.value.replace(/^#/,``).toUpperCase()),placeholder:`RRGGBB or RRGGBBAA`,className:`flex-1 px-3 py-2 bg-bambu-dark border rounded-lg text-white placeholder-bambu-gray/50 focus:outline-none ${a?`border-red-500 focus:border-red-500`:`border-bambu-dark-tertiary focus:border-bambu-green`}`,pattern:e.pattern})]}),a&&(0,G.jsx)(`p`,{className:`mt-1 text-xs text-red-600 dark:text-red-400`,children:f(`inventory.bulk.invalidHex`)})]})}return(0,G.jsx)(`input`,{type:e.type===`number`?`number`:`text`,disabled:n,value:t,onChange:t=>D(e.id,t.target.value),min:e.min,max:e.max,step:e.step,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray/50 focus:border-bambu-green focus:outline-none`})};return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center p-4 z-50`,onClick:n?void 0:u,children:(0,G.jsxs)(`div`,{className:`w-full max-w-3xl bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg max-h-[90vh] flex flex-col`,onClick:e=>e.stopPropagation(),children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-5 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:f(`inventory.bulk.editTitle`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-0.5`,children:f(`inventory.bulk.editSubtitle`,{count:t})})]}),(0,G.jsx)(`button`,{onClick:u,disabled:n,className:`p-1 text-bambu-gray hover:text-white transition-colors`,"aria-label":f(`common.close`),children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]}),(0,G.jsx)(`p`,{className:`px-5 pt-4 text-xs text-bambu-gray`,children:f(`inventory.bulk.editHint`)}),(0,G.jsx)(`div`,{className:`flex-1 overflow-y-auto p-5 space-y-3`,children:y9.map(e=>{let t=_[e.id]!==void 0;return(0,G.jsxs)(`div`,{className:`flex items-start gap-3 rounded-md p-2 transition-colors ${t?`bg-bambu-green/5 border border-bambu-green/30`:`border border-transparent`}`,children:[(0,G.jsx)(`div`,{className:`pt-2`,children:(0,G.jsx)(`input`,{type:`checkbox`,className:`h-4 w-4 cursor-pointer`,checked:t,onChange:t=>{t.target.checked?D(e.id,``):O(e.id)},"aria-label":f(`inventory.bulk.toggleField`)})}),(0,G.jsxs)(`div`,{className:`flex-1`,children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:f(e.labelKey)}),N(e)]})]},e.id)})}),(0,G.jsxs)(`div`,{className:`flex items-center gap-3 p-5 border-t border-bambu-dark-tertiary`,children:[(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:f(`inventory.bulk.changeCount`,{count:Object.keys(k).length})}),(0,G.jsxs)(`div`,{className:`ml-auto flex gap-2`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:u,disabled:n,children:f(`common.cancel`)}),(0,G.jsx)(Q,{onClick:()=>d(k),disabled:!A||n||j,children:n?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 mr-2 animate-spin`}),f(`inventory.bulk.applyPending`)]}):f(`inventory.bulk.applyButton`,{count:t})})]})]})]})})}function I1e(e){let t=e[0],n=0,r=0,i=0;for(let t of e)n+=t.label_weight,r+=t.weight_used,i+=t.core_weight;return{...t,label_weight:n,weight_used:r,core_weight:i}}function x9(e){let t=new Set;for(let n of e)if(typeof n==`string`){let e=n.trim();e&&t.add(e)}return Array.from(t).sort((e,t)=>e.localeCompare(t))}function L1e(e){return`${e.material}|${e.subtype||``}|${e.brand||``}|${e.color_name||``}|${e.rgba||``}|${e.extra_colors||``}|${e.effect_type||``}|${e.label_weight}`}var R1e=`bambuddy-inventory-columns`,S9=[{id:`id`,label:`#`,visible:!0},{id:`added_time`,label:`Added`,visible:!0},{id:`encode_time`,label:`Encoded`,visible:!1},{id:`last_used_time`,label:`Last Used`,visible:!1},{id:`rgba`,label:`Color`,visible:!0},{id:`material`,label:`Material`,visible:!0},{id:`subtype`,label:`Subtype`,visible:!0},{id:`color_name`,label:`Color Name`,visible:!1},{id:`brand`,label:`Brand`,visible:!0},{id:`slicer_filament`,label:`Slicer Filament`,visible:!1},{id:`location`,label:`Location`,visible:!0},{id:`storage_location`,label:`Storage Location`,visible:!1},{id:`temperature`,label:`Temperature`,visible:!1},{id:`humidity`,label:`Humidity`,visible:!1},{id:`battery`,label:`Battery`,visible:!1},{id:`label_weight`,label:`Label`,visible:!0},{id:`net`,label:`Net`,visible:!0},{id:`gross`,label:`Gross`,visible:!1},{id:`added_full`,label:`Full`,visible:!1},{id:`used`,label:`Used`,visible:!1},{id:`printed_total`,label:`Printed Total`,visible:!1},{id:`printed_since_weight`,label:`Printed Since Weight`,visible:!1},{id:`note`,label:`Note`,visible:!1},{id:`pa_k`,label:`PA(K)`,visible:!0},{id:`tag_id`,label:`Tag ID`,visible:!1},{id:`data_origin`,label:`Data Origin`,visible:!1},{id:`tag_type`,label:`Linked Tag Type`,visible:!1},{id:`stock`,label:`Stock`,visible:!1},{id:`remaining`,label:`Remaining`,visible:!0},{id:`spool_name`,label:`Spool`,visible:!1},{id:`cost_per_kg`,label:`Cost/kg`,visible:!1},{id:`weight_check`,label:`Weight Check`,visible:!1}];function z1e(){try{let e=localStorage.getItem(R1e);if(e){let t=JSON.parse(e),n=new Set(S9.map(e=>e.id)),r=new Set(t.map(e=>e.id)),i=[...t.filter(e=>n.has(e.id))];for(let e of S9){if(r.has(e.id))continue;let t=S9.indexOf(e),n=i.length;for(let e=t-1;e>=0;e--){let t=i.findIndex(t=>t.id===S9[e].id);if(t!==-1){n=t+1;break}}i.splice(n,0,e)}return i}}catch{}return S9.map(e=>({...e}))}function B1e(e){try{localStorage.setItem(R1e,JSON.stringify(e))}catch{}}function C9(e,t=!1){return t&&e>=1e3?`${(e/1e3).toFixed(1)}kg`:`${Math.round(e)}g`}var V1e={PLA:`bg-green-100 dark:bg-green-500/20 text-green-700 dark:text-green-400`,ABS:`bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400`,PETG:`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`,TPU:`bg-purple-100 dark:bg-purple-500/20 text-purple-700 dark:text-purple-400`,ASA:`bg-orange-100 dark:bg-orange-500/20 text-orange-700 dark:text-orange-400`,PA:`bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400`,PC:`bg-cyan-100 dark:bg-cyan-500/20 text-cyan-700 dark:text-cyan-400`,PET:`bg-sky-100 dark:bg-sky-500/20 text-sky-700 dark:text-sky-400`};function w9(e,t=`system`){if(!e)return`-`;let n=rp(e);return n?Yf(n,t):`-`}var H1e={id:()=>`#`,added_time:()=>`Added`,encode_time:()=>`Encoded`,last_used_time:()=>`Last Used`,rgba:e=>e(`inventory.color`),material:e=>e(`inventory.material`),subtype:e=>e(`inventory.subtype`),color_name:e=>e(`inventory.colorName`),brand:e=>e(`inventory.brand`),slicer_filament:e=>e(`inventory.slicerFilament`),location:()=>`Location`,storage_location:e=>e(`inventory.storageLocation`),temperature:e=>e(`inventory.temperature`),humidity:e=>e(`inventory.humidity`),battery:e=>e(`inventory.battery`),label_weight:e=>e(`inventory.labelWeight`),net:e=>e(`inventory.net`),gross:()=>`Gross`,added_full:()=>`Full`,used:e=>e(`inventory.weightUsed`),printed_total:()=>`Printed Total`,printed_since_weight:()=>`Printed Since Weight`,note:e=>e(`inventory.note`),pa_k:()=>`PA(K)`,tag_id:()=>`Tag ID`,data_origin:()=>`Data Origin`,tag_type:()=>`Linked Tag Type`,stock:e=>e(`inventory.stock`),remaining:e=>e(`inventory.remaining`),spool_name:e=>e(`inventory.spoolName`),cost_per_kg:e=>e(`inventory.costPerKg`),weight_check:e=>e(`inventory.weightCheck`)},T9={id:({spool:e})=>(0,G.jsx)(`span`,{className:`text-sm font-medium text-white`,children:e.id}),added_time:({spool:e,dateFormat:t})=>(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:w9(e.created_at,t)}),encode_time:({spool:e,dateFormat:t})=>(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:w9(e.encode_time,t)}),last_used_time:({spool:e,dateFormat:t})=>(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.last_used?w9(e.last_used,t):`Never`}),rgba:({spool:e})=>(0,G.jsx)(`div`,{className:`flex items-center justify-center`,children:(0,G.jsx)(w8,{rgba:e.rgba,extraColors:e.extra_colors,effectType:e.effect_type,effectSize:`table`,subtype:e.subtype})}),material:({spool:e})=>(0,G.jsx)(`span`,{className:`text-sm text-white`,children:e.material}),subtype:({spool:e})=>(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.subtype||`-`}),color_name:({spool:e})=>(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:kf(e.color_name,e.rgba)||`-`}),brand:({spool:e})=>(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.brand||`-`}),slicer_filament:({spool:e})=>(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,title:e.slicer_filament||void 0,children:e.slicer_filament_name||e.slicer_filament||`-`}),location:({spool:e,assignmentMap:t})=>{let n=t[e.id];if(!n)return(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:`-`});let r=n.printer_name||`Printer ${n.printer_id}`,i=n.ams_id===254||n.ams_id===255,a=!i&&n.ams_id>=128;return(0,G.jsxs)(`span`,{className:`inline-flex items-center px-1.5 py-0.5 rounded text-xs font-medium bg-purple-100 dark:bg-purple-500/20 text-purple-700 dark:text-purple-400`,children:[r,` `,jp(n.ams_id,n.tray_id,a,i),n.ams_label?` (${n.ams_label})`:``]})},storage_location:({spool:e})=>e.storage_location?(0,G.jsx)(`span`,{className:`inline-flex items-center px-1.5 py-0.5 rounded text-xs font-medium bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`,children:e.storage_location}):(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:`-`}),temperature:({spool:e,locationReadingsMap:t,t:n,colorizeLocationSensors:r,locationSensorAboveColor:i,locationSensorBelowColor:a,locationSensorOptimalColor:o})=>{let s=e.location_id?t[e.location_id]?.find(e=>e.device_class===`temperature`):void 0;return s?(0,G.jsx)(`span`,{title:s.name,className:`text-sm ${k9(s,r,i,a,o)}`,children:O9(s,n)}):(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray/50`,children:`-`})},humidity:({spool:e,locationReadingsMap:t,t:n,colorizeLocationSensors:r,locationSensorAboveColor:i,locationSensorBelowColor:a,locationSensorOptimalColor:o})=>{let s=e.location_id?t[e.location_id]?.find(e=>e.device_class===`humidity`):void 0;return s?(0,G.jsx)(`span`,{title:s.name,className:`text-sm ${k9(s,r,i,a,o)}`,children:O9(s,n)}):(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray/50`,children:`-`})},battery:({spool:e,locationReadingsMap:t,t:n,colorizeLocationSensors:r,locationSensorAboveColor:i,locationSensorBelowColor:a,locationSensorOptimalColor:o})=>{let s=e.location_id?t[e.location_id]?.find(e=>e.device_class===`battery`):void 0;return s?(0,G.jsx)(`span`,{title:s.name,className:`text-sm ${k9(s,r,i,a,o)}`,children:O9(s,n)}):(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray/50`,children:`-`})},label_weight:({spool:e})=>(0,G.jsx)(`span`,{className:`text-sm text-white`,children:C9(e.label_weight)}),net:({remaining:e})=>(0,G.jsx)(`span`,{className:`text-sm text-white`,children:C9(e)}),gross:({spool:e,remaining:t})=>(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:C9(t+e.core_weight)}),added_full:({spool:e})=>(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.added_full==null?`-`:e.added_full?`Yes`:`No`}),used:({spool:e})=>(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.weight_used>0?C9(e.weight_used):`-`}),printed_total:()=>(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray/50`,children:`-`}),printed_since_weight:()=>(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray/50`,children:`-`}),note:({spool:e})=>(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray max-w-[150px] truncate block`,title:e.note||void 0,children:e.note||`-`}),pa_k:({spool:e})=>(e.k_profiles?.length??0)===0?(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:`-`}):(0,G.jsx)(`span`,{className:`inline-flex items-center px-1.5 py-0.5 rounded text-xs font-medium bg-bambu-green/20 text-bambu-green`,children:`K`}),tag_id:({spool:e})=>{let t=e.tag_uid||e.tray_uuid;return t?(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray font-mono`,title:t,children:t.length>12?`${t.slice(0,6)}...${t.slice(-4)}`:t}):(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray/50`,children:`-`})},data_origin:({spool:e})=>(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.data_origin||`-`}),tag_type:({spool:e})=>(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.tag_type||`-`}),stock:({spool:e,t})=>e.slicer_filament?(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:`-`}):(0,G.jsx)(`span`,{className:`inline-flex items-center px-1.5 py-0.5 rounded text-xs font-medium bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-400`,children:t(`inventory.stock`)}),remaining:({remaining:e,pct:t})=>(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`div`,{className:`flex-1 h-2 bg-bambu-dark-tertiary rounded-full overflow-hidden`,children:(0,G.jsx)(`div`,{className:`h-full rounded-full ${t>50?`bg-bambu-green`:t>20?`bg-yellow-500`:`bg-red-500`}`,style:{width:`${Math.min(t,100)}%`}})}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray min-w-[40px] text-right`,children:[Math.round(e),`g`]})]}),spool_name:({spool:e,catalogMap:t})=>(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:(e.core_weight_catalog_id==null?void 0:t[e.core_weight_catalog_id])?.name||`-`}),cost_per_kg:({spool:e,currencySymbol:t})=>(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.cost_per_kg==null?`-`:`${t}${e.cost_per_kg.toFixed(2)}`}),weight_check:({spool:e,onSyncWeight:t})=>{let n=e.last_scale_weight;if(n==null)return(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray/50`,title:`No scale measurement`,children:`-`});let r=e.core_weight||0,i=Math.max(0,e.label_weight-e.weight_used)+r,a,o;n0?`+${Math.round(a)}`:`${Math.round(a)}`,c=o?`Scale: ${Math.round(n)}g\nCalculated: ${Math.round(i)}g\nDifference: ${s}g (within tolerance)`:`Scale: ${Math.round(n)}g\nCalculated: ${Math.round(i)}g\nDifference: ${s}g (mismatch!)`;return(0,G.jsxs)(`div`,{className:`flex items-center gap-1 text-sm font-medium ${o?`text-green-700 dark:text-green-400`:`text-yellow-700 dark:text-yellow-400`}`,title:c,children:[(0,G.jsxs)(`span`,{children:[Math.round(n),`g`]}),o?(0,G.jsx)(fs,{className:`w-3 h-3`}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Lu,{className:`w-3 h-3`}),t&&(0,G.jsx)(`button`,{type:`button`,onClick:n=>{n.stopPropagation(),n.preventDefault(),t(e)},className:`p-1 hover:bg-bambu-green/20 rounded transition-colors text-bambu-green`,title:`Sync: trust scale weight and reset tracking`,children:(0,G.jsx)(Hl,{className:`w-3.5 h-3.5`})})]})]})}},E9={id:e=>e.id,added_time:e=>e.created_at||``,encode_time:e=>e.encode_time||``,last_used_time:e=>e.last_used||``,material:e=>(e.material||``).toLowerCase(),subtype:e=>(e.subtype||``).toLowerCase(),color_name:e=>(e.color_name||``).toLowerCase(),rgba:e=>Ef(e.rgba),brand:e=>(e.brand||``).toLowerCase(),slicer_filament:e=>(e.slicer_filament_name||e.slicer_filament||``).toLowerCase(),location:(e,t)=>{let n=t[e.id];if(!n)return``;let r=n.ams_id===254||n.ams_id===255,i=!r&&n.ams_id>=128,a=n.ams_label?` (${n.ams_label})`:``;return`${n.printer_name||``} ${jp(n.ams_id,n.tray_id,i,r)}${a}`},storage_location:e=>(e.storage_location||``).toLowerCase(),label_weight:e=>e.label_weight,net:e=>Math.max(0,e.label_weight-e.weight_used),gross:e=>Math.max(0,e.label_weight-e.weight_used)+e.core_weight,used:e=>e.weight_used,remaining:e=>e.label_weight>0?Math.max(0,e.label_weight-e.weight_used)/e.label_weight:0,note:e=>(e.note||``).toLowerCase(),data_origin:e=>(e.data_origin||``).toLowerCase(),tag_type:e=>(e.tag_type||``).toLowerCase(),stock:e=>+!!e.slicer_filament,spool_name:e=>e.core_weight_catalog_id??0,cost_per_kg:e=>e.cost_per_kg??0,weight_check:e=>{if(e.last_scale_weight==null)return-1;let t=Math.max(0,e.label_weight-e.weight_used)+e.core_weight;return Math.abs(e.last_scale_weight-t)},temperature:(e,t,n)=>(e.location_id?n[e.location_id]:void 0)?.find(e=>e.device_class===`temperature`)?.value??-1/0,humidity:(e,t,n)=>(e.location_id?n[e.location_id]:void 0)?.find(e=>e.device_class===`humidity`)?.value??-1/0,battery:(e,t,n)=>(e.location_id?n[e.location_id]:void 0)?.find(e=>e.device_class===`battery`)?.value??-1/0},D9=`bambuddy-inventory-sort`;function U1e(){try{let e=localStorage.getItem(D9);if(e)return JSON.parse(e)}catch{}return null}function W1e(e){try{e?localStorage.setItem(D9,JSON.stringify(e)):localStorage.removeItem(D9)}catch{}}function G1e(){let{data:e}=K({queryKey:[`spoolman-settings`],queryFn:Z.getSpoolmanSettings,staleTime:300*1e3}),t=e!==void 0;return(0,G.jsx)(K1e,{spoolmanMode:e?.spoolman_enabled===`true`&&!!e?.spoolman_url,spoolmanModeReady:t})}function K1e({spoolmanMode:e=!1,spoolmanModeReady:t=!0}){let{t:n}=U(),r=co(),{showToast:i}=qd(),{hasPermission:a,loading:o}=Nd(),s=!o&&a(`inventory:forecast_read`),[c,l]=Ri(),[u,d]=(0,y.useState)(null),f=(0,y.useRef)(!1),[p,m]=(0,y.useState)(null),[h,g]=(0,y.useState)(null),[_,v]=(0,y.useState)(!1),[b,x]=(0,y.useState)(!1),[S,C]=(0,y.useState)(!1),[w,T]=(0,y.useState)(`active`),[E,D]=(0,y.useState)(`all`),[O,k]=(0,y.useState)(``),[A,j]=(0,y.useState)(``),[M,N]=(0,y.useState)(``),[P,F]=(0,y.useState)(``),[I,L]=(0,y.useState)(`all`),[R,z]=(0,y.useState)(``),[B,V]=(0,y.useState)(`table`),[ee,te]=(0,y.useState)(U1e),[ne,re]=(0,y.useState)(z1e),[ie,ae]=(0,y.useState)(!1),[oe,se]=(0,y.useState)(()=>{try{return localStorage.getItem(`bambuddy-inventory-group`)===`true`}catch{return!1}}),[H,ce]=(0,y.useState)(new Set),[le,ue]=(0,y.useState)(new Set),[de,fe]=(0,y.useState)(!1),[pe,me]=(0,y.useState)(null),he=(0,y.useCallback)(e=>{ue(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),ge=(0,y.useCallback)(()=>ue(new Set),[]);(0,y.useEffect)(()=>{ue(new Set)},[w,E,O,A,M,P,I,R]);let[_e,ve]=(0,y.useState)(0),[ye,be]=(0,y.useState)(()=>{try{let e=localStorage.getItem(`bambuddy-inventory-pageSize`);if(e){let t=Number(e);if([15,30,50,100,-1].includes(t))return t}}catch{}return 15}),{data:xe}=K({queryKey:[`settings`],queryFn:Z.getSettings}),Se=xe?.date_format||`system`,Ce=(xe?.location_sensor_poll_interval||120)*1e3,{colorize:we,aboveColor:Te,belowColor:Ee,optimalColor:De}=R6(),Oe=e?[`spoolman-inventory-spools`]:[`inventory-spools`],ke=()=>b6(r,Oe),{data:Ae,isLoading:je}=K({queryKey:Oe,queryFn:()=>e?Z.getSpoolmanInventorySpools(!0):Z.getSpools(!0),refetchInterval:3e4}),Me=(0,y.useCallback)(async()=>{x(!0);try{await Z.exportSpoolsCsv()}catch(e){i(e instanceof Error?e.message:n(`inventory.csv.exportError`,`Export failed`),`error`)}finally{x(!1)}},[i,n]),Ne=e?n(`inventory.csv.spoolmanHint`,`In Spoolman mode, use Spoolman's built-in CSV import/export.`):void 0,{data:Pe=[]}=K({queryKey:v6,queryFn:Z.getLocations}),Fe=c.get(`location_id`),Ie=Fe===`__none__`?`__none__`:Fe&&/^\d+$/.test(Fe)&&Number(Fe)>0?Fe:``,Le=c.get(`spool`),Re=Le&&/^\d+$/.test(Le)&&Number(Le)>0?Number(Le):null,ze=Ae?.find(e=>e.id===Re)??null,Be=(0,y.useCallback)(()=>{f.current=!0,l(e=>(e.delete(`spool`),e),{replace:!0})},[l]),{data:Ve,isError:He,error:Ue}=K({queryKey:e?[`spoolman-inventory-spool`,Re]:[`inventory-spool`,Re],queryFn:()=>e?Z.getSpoolmanInventorySpool(Re):Z.getSpool(Re),enabled:t&&Re!==null&&ze===null,staleTime:1/0,retry:(e,t)=>e<2&&!(t instanceof sd&&t.status===404)});(0,y.useEffect)(()=>{if(!f.current){if(t&&Re&&ze){Be(),d({spool:ze,mode:`edit`});return}if(Ve){Be(),d({spool:Ve,mode:`edit`});return}He&&(Be(),i(n(Ue instanceof sd&&Ue.status===404?`inventory.deepLinkSpoolNotFound`:`inventory.deepLinkFetchFailed`),`error`))}},[t,Re,ze,Ve,He,Ue,Be,i,n]);let{data:We}=K({queryKey:[`spool-assignments`],queryFn:()=>Z.getAssignments(),refetchInterval:3e4}),{data:Ge=[],isError:Ke}=K({queryKey:[`spoolman-slot-assignments-all`],queryFn:()=>Z.getSpoolmanSlotAssignments(),enabled:e,refetchInterval:3e4,staleTime:1e4,retry:1}),qe=(0,y.useRef)(!1);(0,y.useEffect)(()=>{Ke&&!qe.current?(qe.current=!0,i(n(`inventory.spoolmanUnreachable`),`error`)):Ke||(qe.current=!1)},[Ke,i,n]);let{data:Je}=K({queryKey:[`spool-catalog`],queryFn:()=>Z.getSpoolCatalog()}),Ye=q({mutationFn:t=>e?Z.deleteSpoolmanInventorySpool(t):Z.deleteSpool(t),onSuccess:()=>{ke(),i(n(`inventory.spoolDeleted`),`success`)},onError:e=>{e instanceof sd&&e.status===404?i(n(`inventory.deleteSpoolNotFound`),`error`):e instanceof sd&&e.status===503?i(n(`inventory.spoolmanUnreachable`),`error`):i(n(`inventory.deleteFailed`),`error`)}}),Xe=q({mutationFn:t=>e?Z.archiveSpoolmanInventorySpool(t):Z.archiveSpool(t),onSuccess:()=>{ke(),i(n(`inventory.spoolArchived`),`success`)},onError:e=>{e instanceof sd&&e.status===404?i(n(`inventory.archiveSpoolNotFound`),`error`):e instanceof sd&&e.status===503?i(n(`inventory.spoolmanUnreachable`),`error`):i(n(`inventory.archiveFailed`),`error`)}}),Ze=q({mutationFn:t=>e?Z.restoreSpoolmanInventorySpool(t):Z.restoreSpool(t),onSuccess:()=>{ke(),i(n(`inventory.spoolRestored`),`success`)},onError:e=>{e instanceof sd&&e.status===404?i(n(`inventory.restoreSpoolNotFound`),`error`):e instanceof sd&&e.status===503?i(n(`inventory.spoolmanUnreachable`),`error`):i(n(`inventory.restoreFailed`),`error`)}}),Qe=q({mutationFn:t=>e?Z.resetSpoolmanInventorySpoolConsumedCounter(t):Z.resetSpoolConsumedCounter(t),onSuccess:()=>{r.invalidateQueries({queryKey:Oe}),i(n(`inventory.consumedCounterReset`),`success`)},onError:()=>{i(n(`inventory.resetConsumedCounterFailed`),`error`)}}),$e=q({mutationFn:t=>e?Z.bulkResetSpoolmanInventorySpoolConsumedCounter(t):Z.bulkResetSpoolConsumedCounter(t),onSuccess:e=>{r.invalidateQueries({queryKey:Oe}),i(n(`inventory.allConsumedCountersReset`,{count:e.reset}),`success`),me(null),ge()},onError:()=>{i(n(`inventory.resetConsumedCounterFailed`),`error`)}}),et=e=>(e.not_found?.length??0)+(e.errors?.length??0),tt=q({mutationFn:async({ids:t,update:n})=>e?Z.bulkUpdateSpoolmanInventorySpools(t,n):Z.bulkUpdateSpools(t,n),onSuccess:e=>{ke();let t=et(e);if(e.updated===0){i(n(`inventory.bulk.updateAllFailed`,{count:t}),`error`);return}t>0?i(n(`inventory.bulk.updatePartial`,{ok:e.updated,failed:t}),`warning`):i(n(`inventory.bulk.updateSuccess`,{count:e.updated}),`success`),fe(!1),ge()},onError:e=>{i(e.message||n(`inventory.bulk.updateFailed`),`error`)}}),nt=q({mutationFn:async t=>e?Z.bulkDeleteSpoolmanInventorySpools(t):Z.bulkDeleteSpools(t),onSuccess:e=>{ke();let t=et(e);if(e.deleted===0){i(n(`inventory.bulk.deleteAllFailed`,{count:t}),`error`);return}t>0?i(n(`inventory.bulk.deletePartial`,{ok:e.deleted,failed:t}),`warning`):i(n(`inventory.bulk.deleteSuccess`,{count:e.deleted}),`success`),me(null),ge()},onError:e=>{i(e.message||n(`inventory.bulk.deleteFailed`),`error`)}}),rt=q({mutationFn:async t=>e?Z.bulkArchiveSpoolmanInventorySpools(t):Z.bulkArchiveSpools(t),onSuccess:e=>{ke();let t=et(e);if(e.archived===0&&t>0){i(n(`inventory.bulk.archiveAllFailed`,{count:t}),`error`);return}t>0?i(n(`inventory.bulk.archivePartial`,{ok:e.archived,failed:t}),`warning`):i(n(`inventory.bulk.archiveSuccess`,{count:e.archived}),`success`),me(null),ge()},onError:e=>{i(e.message||n(`inventory.bulk.archiveFailed`),`error`)}}),it=q({mutationFn:async t=>e?Z.bulkRestoreSpoolmanInventorySpools(t):Z.bulkRestoreSpools(t),onSuccess:e=>{ke();let t=et(e);if(e.restored===0&&t>0){i(n(`inventory.bulk.restoreAllFailed`,{count:t}),`error`);return}t>0?i(n(`inventory.bulk.restorePartial`,{ok:e.restored,failed:t}),`warning`):i(n(`inventory.bulk.restoreSuccess`,{count:e.restored}),`success`),me(null),ge()},onError:e=>{i(e.message||n(`inventory.bulk.restoreFailed`),`error`)}}),at=(0,y.useMemo)(()=>(Ae??[]).map(e=>e.id),[Ae]),ot=async t=>{if(t.last_scale_weight!=null)try{e?await Z.syncSpoolmanSpoolWeight(t.id,t.last_scale_weight):await Od.updateSpoolWeight(t.id,t.last_scale_weight),r.invalidateQueries({queryKey:Oe}),i(`Synced "${[t.brand,t.material,t.color_name].filter(Boolean).join(` `)}" to scale weight`,`success`)}catch(e){let t=e instanceof sd&&e.status===404,r=e instanceof sd&&e.status===503;i(n(t?`inventory.syncWeightSpoolNotFound`:r?`inventory.syncWeightSpoolmanUnreachable`:`inventory.syncWeightFailed`),`error`)}},st=xe?.low_stock_threshold??20,[ct,lt]=(0,y.useState)(!1),[ut,dt]=(0,y.useState)(st.toString());(0,y.useEffect)(()=>{ct||dt(st.toString())},[st,ct]);let ft=q({mutationFn:e=>Z.updateSettings({low_stock_threshold:e}),onSuccess:()=>{r.invalidateQueries({queryKey:[`settings`]}),i(n(`common.saved`),`success`),lt(!1)},onError:()=>{i(n(`inventory.lowStockThresholdError`),`error`)}}),pt=(0,y.useMemo)(()=>{if(!Ae)return null;let e=0,t=0,n=0,r=0,i={};for(let a of Ae){if(t+=Math.max(0,a.weight_used-(a.weight_used_baseline??0)),a.archived_at)continue;r++;let o=Math.max(0,a.label_weight-a.weight_used);e+=o,(a.label_weight>0?o/a.label_weight*100:0)<(a.low_stock_threshold_pct??st)&&n++;let s=a.material||`Unknown`;i[s]||(i[s]={count:0,weight:0}),i[s].count++,i[s].weight+=o}return{totalWeight:e,totalConsumed:t,lowStock:n,byMaterial:i,totalSpools:r}},[Ae,st]),mt=(We?.length??0)+(e?Ge.length:0),ht=Lf(xe?.currency||`USD`),gt=(0,y.useMemo)(()=>{let e={};for(let t of We||[])e[t.spool_id]={printer_id:t.printer_id,printer_name:t.printer_name,ams_id:t.ams_id,tray_id:t.tray_id,ams_label:t.ams_label??null};for(let t of Ge)typeof t?.spoolman_spool_id!=`number`||t.spoolman_spool_id<=0||typeof t.printer_id!=`number`||typeof t.ams_id!=`number`||typeof t.tray_id!=`number`||e[t.spoolman_spool_id]||(e[t.spoolman_spool_id]={printer_id:t.printer_id,printer_name:t.printer_name??null,ams_id:t.ams_id,tray_id:t.tray_id,ams_label:t.ams_label??null});return e},[We,Ge]),_t=(0,y.useMemo)(()=>{let e={};for(let t of Je||[])e[t.id]=t;return e},[Je]),{data:vt}=K({queryKey:[`locationHaSensors`],queryFn:()=>Z.getLocationHASensors()}),yt=(0,y.useMemo)(()=>new Set((vt??[]).map(e=>e.location_id)),[vt]),bt=(0,y.useMemo)(()=>{let e=new Set;for(let t of Ae||[])t.location_id&&yt.has(t.location_id)&&e.add(t.location_id);return Array.from(e)},[Ae,yt]),xt=B===`cards`||B===`table`&&ne.some(e=>e.visible&&(e.id===`temperature`||e.id===`humidity`||e.id===`battery`)),St=Co({queries:bt.map(e=>({queryKey:[`locationHaSensorReadings`,e],queryFn:()=>Z.getLocationHASensorReadings(e,!1),refetchInterval:Ce,enabled:xt}))}),Ct=(0,y.useMemo)(()=>{let e={};return bt.forEach((t,n)=>{let r=St[n]?.data;r&&(e[t]=r)}),e},[bt,St]),wt=(0,y.useMemo)(()=>pt?Object.entries(pt.byMaterial).sort((e,t)=>t[1].weight-e[1].weight).slice(0,4):[],[pt]),Tt=(0,y.useMemo)(()=>{let e=Ae||[];if(e=w===`active`?e.filter(e=>!e.archived_at):e.filter(e=>!!e.archived_at),E===`used`?e=e.filter(e=>e.weight_used>0):E===`new`?e=e.filter(e=>e.weight_used===0):E===`lowstock`&&(e=e.filter(e=>{let t=Math.max(0,e.label_weight-e.weight_used);return(e.label_weight>0?t/e.label_weight*100:0)<(e.low_stock_threshold_pct??st)})),O&&(e=e.filter(e=>e.material===O)),A&&(e=e.filter(e=>e.brand===A)),M&&(e=M===`__none__`?e.filter(e=>!e.category):e.filter(e=>e.category===M)),P){let t=Number(P);e=e.filter(e=>e.core_weight_catalog_id===t)}if(Ie)if(Ie===`__none__`)e=e.filter(e=>!e.location_id&&!e.storage_location?.trim());else{let t=Number(Ie),n=Pe.find(e=>e.id===t)?.name?.trim().toLowerCase();e=e.filter(e=>e.location_id==null?n?(e.storage_location||``).trim().toLowerCase()===n:!1:e.location_id===t)}return I===`stock`?e=e.filter(e=>!e.slicer_filament):I===`configured`&&(e=e.filter(e=>!!e.slicer_filament)),R&&(e=wH(e,R)),e},[Ae,w,E,O,A,M,P,I,Ie,R,st,Pe]),Et=()=>ve(0),Dt=(0,y.useCallback)(e=>{l(t=>(t.delete(`location_id`),e&&t.set(`location_id`,e),t),{replace:!0}),Et()},[l]),Ot=[...new Set(Ae?.map(e=>e.material)||[])].sort(),kt=[...new Set(Ae?.map(e=>e.brand).filter(Boolean)||[])].sort(),At=[...new Set(Ae?.map(e=>e.category?.trim()).filter(Boolean)||[])].sort(),jt=(Ae??[]).some(e=>!e.category),Mt=[...new Set(Ae?.map(e=>e.core_weight_catalog_id).filter(e=>e!=null)||[])].sort((e,t)=>{let n=(_t[e]?.name||``).toLowerCase(),r=(_t[t]?.name||``).toLowerCase();return n.localeCompare(r)}),Nt=(Ae??[]).some(e=>!e.location_id&&!e.storage_location?.trim()),Pt=w!==`active`||E!==`all`||!!O||!!A||!!M||!!P||!!Ie||I!==`all`||!!R,Ft=e=>{re(e),B1e(e)},It=(0,y.useMemo)(()=>ne.filter(e=>e.visible).map(e=>e.id),[ne]),Lt=e=>{E9[e]&&(te(t=>{let n;return n=t?.column===e?t.direction===`asc`?{column:e,direction:`desc`}:null:{column:e,direction:`asc`},W1e(n),n}),Et())},Rt=(0,y.useMemo)(()=>{if(!ee)return Tt;let e=E9[ee.column];return e?[...Tt].sort((t,n)=>{let r=e(t,gt,Ct),i=e(n,gt,Ct);return ri?ee.direction===`asc`?1:-1:0}):Tt},[Tt,ee,gt,Ct]),zt=(0,y.useMemo)(()=>{if(!oe)return Rt.map(e=>({type:`single`,spool:e}));let e=new Map;for(let t of Rt)if(!(t.weight_used>0||gt[t.id])){let n=L1e(t),r=e.get(n);r?r.push(t):e.set(n,[t])}let t=[],n=new Set;for(let r of Rt){if(r.weight_used>0||gt[r.id]){t.push({type:`single`,spool:r});continue}let i=L1e(r);if(n.has(i))continue;n.add(i);let a=e.get(i);a.length===1?t.push({type:`single`,spool:a[0]}):t.push({type:`group`,key:i,spools:a,representative:a[0]})}return t},[Rt,oe,gt]),Bt=ye===-1,Vt=zt.length,Ht=Bt?Vt||1:ye,Ut=Math.max(1,Math.ceil(Vt/Ht)),Wt=Bt?0:Math.min(_e,Ut-1),Gt=Bt?zt:zt.slice(Wt*Ht,(Wt+1)*Ht),Kt=()=>{let e=!oe;se(e),ce(new Set),Et();try{localStorage.setItem(`bambuddy-inventory-group`,String(e))}catch{}},qt=e=>{ce(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},Jt=e=>{be(e),ve(0);try{localStorage.setItem(`bambuddy-inventory-pageSize`,String(e))}catch{}};return(0,G.jsxs)(`div`,{className:`p-4 md:p-8 space-y-6`,children:[(0,G.jsxs)(`div`,{className:`flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,G.jsx)(Cl,{className:`w-7 h-7 text-bambu-green`}),n(`inventory.title`)]}),(0,G.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:n(`inventory.subtitle`)})]}),(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,G.jsxs)(Q,{variant:`secondary`,disabled:e,onClick:()=>v(!0),title:Ne,children:[(0,G.jsx)(Vu,{className:`w-4 h-4`}),n(`inventory.csv.importButton`,`Import CSV`)]}),(0,G.jsxs)(Q,{variant:`secondary`,disabled:e||b,onClick:Me,title:Ne,children:[b?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Xs,{className:`w-4 h-4`}),n(`inventory.csv.exportButton`,`Export CSV`)]}),(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>C(!0),children:[(0,G.jsx)(ol,{className:`w-4 h-4`}),n(`locations.manage`)]}),(0,G.jsxs)(Q,{variant:`secondary`,disabled:Tt.length===0,onClick:()=>g(Tt.map(e=>e.id)),title:Tt.length===0?n(`inventory.labels.noSpoolsTitle`,`No spools to label`):n(`inventory.labels.bulkTitle`,`Pick spools to print labels for from the {{count}} currently shown`,{count:Tt.length}),children:[(0,G.jsx)(Rl,{className:`w-4 h-4`}),n(`inventory.labels.printLabels`,`Print labels…`)]}),(0,G.jsxs)(Q,{onClick:()=>d({spool:null,mode:`create`}),children:[(0,G.jsx)(Fl,{className:`w-4 h-4`}),n(`inventory.addSpool`)]})]})]}),pt&&!je&&(0,G.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-3 lg:grid-cols-5 gap-3`,children:[(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,G.jsx)(Cl,{className:`w-4 h-4 text-bambu-green`}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray font-medium uppercase tracking-wide`,children:n(`inventory.totalInventory`)})]}),(0,G.jsx)(`div`,{className:`text-xl font-bold text-white`,children:C9(pt.totalWeight,!0)}),(0,G.jsxs)(`div`,{className:`text-xs text-bambu-gray mt-1`,children:[pt.totalSpools,` `,pt.totalSpools===1?n(`inventory.spool`):n(`inventory.spools`)]})]}),(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-2 mb-1`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Fu,{className:`w-4 h-4 text-blue-600 dark:text-blue-400`}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray font-medium uppercase tracking-wide`,children:n(`inventory.totalConsumed`)})]}),pt.totalConsumed>0&&at.length>0&&(0,G.jsx)(`button`,{onClick:()=>m({type:`reset-all-consumed-counters`}),className:`p-1 text-bambu-gray hover:text-red-600 dark:hover:text-red-400 rounded transition-colors`,title:n(`inventory.resetAllConsumedCountersTooltip`),"aria-label":n(`inventory.resetAllConsumedCounters`),children:(0,G.jsx)(nc,{className:`w-3.5 h-3.5`})})]}),(0,G.jsx)(`div`,{className:`text-xl font-bold text-white`,children:C9(pt.totalConsumed,!0)}),(0,G.jsx)(`div`,{className:`text-xs text-bambu-gray mt-1`,children:n(`inventory.sinceTracking`)})]}),(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,G.jsx)(Jc,{className:`w-4 h-4 text-green-600 dark:text-green-400`}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray font-medium uppercase tracking-wide`,children:n(`inventory.byMaterial`)})]}),(0,G.jsx)(`div`,{className:`flex flex-wrap gap-1.5 mt-1`,children:wt.map(([e,t])=>(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-medium ${V1e[e]||`bg-bambu-dark-tertiary text-bambu-gray`}`,children:[e,` `,(0,G.jsx)(`span`,{className:`opacity-70`,children:C9(t.weight,!0)})]},e))})]}),(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,G.jsx)(Rl,{className:`w-4 h-4 text-purple-600 dark:text-purple-400`}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray font-medium uppercase tracking-wide`,children:n(`inventory.inPrinter`)})]}),(0,G.jsx)(`div`,{className:`text-xl font-bold text-white`,children:mt}),(0,G.jsx)(`div`,{className:`text-xs text-bambu-gray mt-1`,children:n(`inventory.loadedInAms`)})]}),(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,G.jsx)(Lu,{className:`w-4 h-4 text-yellow-600 dark:text-yellow-400`}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray font-medium uppercase tracking-wide`,children:n(`inventory.lowStock`)})]}),(0,G.jsx)(`div`,{className:`text-xl font-bold ${pt.lowStock>0?`text-yellow-700 dark:text-yellow-400`:`text-white`}`,children:pt.lowStock}),(0,G.jsx)(`div`,{className:`text-xs text-bambu-gray mt-1 flex items-center gap-2`,children:ct?(0,G.jsxs)(`form`,{onSubmit:e=>{e.preventDefault();let t=parseFloat(ut);!isNaN(t)&&t>=.1&&t<=99.9?ft.mutate(t):i(n(`inventory.lowStockThresholdError`),`error`)},className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:`<`}),(0,G.jsx)(`input`,{type:`text`,inputMode:`decimal`,pattern:`^\\d{0,2}(\\.\\d?)?$`,maxLength:4,value:ut,onChange:e=>{let t=e.target.value.replace(/[^\d.]/g,``);/^\d{0,2}(\.\d?)?$/.test(t)&&dt(t)},className:`px-1.5 py-1 rounded border border-bambu-dark-tertiary text-xs text-white bg-bambu-dark-secondary focus:outline-none focus:border-bambu-green w-14 text-center`,onWheel:e=>e.currentTarget.blur(),disabled:ft.isPending}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:`%`}),(0,G.jsx)(Q,{type:`submit`,size:`sm`,disabled:ft.isPending,children:n(`common.save`)}),(0,G.jsx)(Q,{type:`button`,size:`sm`,variant:`ghost`,onClick:()=>lt(!1),disabled:ft.isPending,children:n(`common.cancel`)})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`span`,{className:`text-bambu-gray`,children:[`< `,st,`%`]}),(0,G.jsx)(`button`,{className:`p-1.5 text-bambu-gray hover:text-white rounded transition-colors`,title:n(`common.edit`),onClick:()=>{dt(st.toString()),lt(!0)},children:(0,G.jsx)(kl,{className:`w-4 h-4`})})]})})]})]}),(0,G.jsxs)(`div`,{className:`flex flex-col sm:flex-row gap-3 items-start sm:items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`relative flex-1 max-w-md ${B===`forecast`?`invisible pointer-events-none`:``}`,children:[(0,G.jsx)(Ql,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50`}),(0,G.jsx)(`input`,{type:`text`,value:R,onChange:e=>{z(e.target.value),Et()},placeholder:n(`inventory.search`),className:`w-full pl-10 pr-8 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`}),R&&(0,G.jsx)(`button`,{onClick:()=>{z(``),Et()},className:`absolute right-3 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white`,children:(0,G.jsx)(nd,{className:`w-4 h-4`})})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[B===`table`&&(0,G.jsxs)(`button`,{onClick:()=>ae(!0),className:`flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium text-bambu-gray border border-bambu-dark-tertiary rounded-lg hover:bg-bambu-dark-tertiary transition-colors`,title:n(`inventory.configureColumns`),children:[(0,G.jsx)(zs,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:n(`inventory.columns`)})]}),B!==`forecast`&&(0,G.jsxs)(`button`,{onClick:Kt,className:`flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium border rounded-lg transition-colors ${oe?`bg-bambu-green/20 text-bambu-green border-bambu-green/30`:`text-bambu-gray border-bambu-dark-tertiary hover:bg-bambu-dark-tertiary`}`,title:n(`inventory.groupSimilar`),children:[(0,G.jsx)(Mc,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:n(`inventory.groupSimilar`)})]}),(0,G.jsxs)(`div`,{className:`flex bg-bambu-dark-primary border border-bambu-dark-tertiary rounded-lg overflow-hidden`,children:[(0,G.jsxs)(`button`,{onClick:()=>V(`table`),className:`flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium transition-colors ${B===`table`?`bg-bambu-green text-white`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:[(0,G.jsx)(Tu,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:n(`inventory.table`)})]}),(0,G.jsxs)(`button`,{onClick:()=>V(`cards`),className:`flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium transition-colors ${B===`cards`?`bg-bambu-green text-white`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:[(0,G.jsx)(Yc,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:n(`inventory.cards`)})]}),(0,G.jsxs)(`button`,{onClick:()=>s&&V(`forecast`),disabled:!s,title:s?void 0:n(`forecast.noReadAccess`),className:`flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium transition-colors disabled:opacity-40 disabled:cursor-not-allowed ${B===`forecast`?`bg-bambu-green text-white`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:[s?(0,G.jsx)(Iu,{className:`w-4 h-4`}):(0,G.jsx)(nl,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:n(`forecast.title`)})]})]})]})]}),(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 ${B===`forecast`?`hidden`:``}`,children:[(0,G.jsxs)(`div`,{className:`flex items-center rounded-lg border border-bambu-dark-tertiary overflow-hidden`,children:[(0,G.jsxs)(`button`,{onClick:()=>{T(`active`),Et()},className:`flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium transition-colors ${w===`active`?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:[(0,G.jsx)(Cl,{className:`w-3.5 h-3.5`}),n(`inventory.active`)]}),(0,G.jsxs)(`button`,{onClick:()=>{T(`archived`),Et()},className:`flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium transition-colors ${w===`archived`?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:[(0,G.jsx)(Po,{className:`w-3.5 h-3.5`}),n(`inventory.archived`)]})]}),(0,G.jsx)(`div`,{className:`w-px h-5 bg-bambu-dark-tertiary`}),(0,G.jsxs)(`div`,{className:`flex items-center rounded-lg border border-bambu-dark-tertiary overflow-hidden`,children:[(0,G.jsx)(`button`,{onClick:()=>{D(`all`),Et()},className:`px-3 py-1.5 text-xs font-medium transition-colors ${E===`all`?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:n(`inventory.all`)}),(0,G.jsxs)(`button`,{onClick:()=>{D(`used`),Et()},className:`flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium transition-colors ${E===`used`?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:[(0,G.jsx)(js,{className:`w-3.5 h-3.5`}),n(`inventory.used`)]}),(0,G.jsx)(`button`,{onClick:()=>{D(`new`),Et()},className:`px-3 py-1.5 text-xs font-medium transition-colors ${E===`new`?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:n(`inventory.new`)}),(0,G.jsxs)(`button`,{onClick:()=>{D(`lowstock`),Et()},className:`flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium transition-colors ${E===`lowstock`?`bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:[(0,G.jsx)(Lu,{className:`w-3.5 h-3.5`}),n(`inventory.lowStock`)]})]}),(0,G.jsxs)(`div`,{className:`flex items-center rounded-lg border border-bambu-dark-tertiary overflow-hidden`,children:[(0,G.jsx)(`button`,{onClick:()=>{L(`all`),Et()},className:`px-3 py-1.5 text-xs font-medium transition-colors ${I===`all`?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:n(`inventory.all`)}),(0,G.jsx)(`button`,{onClick:()=>{L(`stock`),Et()},className:`px-3 py-1.5 text-xs font-medium transition-colors ${I===`stock`?`bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-400`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:n(`inventory.stock`)}),(0,G.jsx)(`button`,{onClick:()=>{L(`configured`),Et()},className:`px-3 py-1.5 text-xs font-medium transition-colors ${I===`configured`?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:n(`inventory.configured`)})]}),(0,G.jsx)(`div`,{className:`w-px h-5 bg-bambu-dark-tertiary`}),(0,G.jsxs)(`select`,{value:O,onChange:e=>{k(e.target.value),Et()},className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${O?`bg-bambu-green/20 text-bambu-green border-bambu-green/30`:`bg-transparent text-bambu-gray border-bambu-dark-tertiary hover:bg-bambu-dark-tertiary`}`,children:[(0,G.jsx)(`option`,{value:``,children:n(`inventory.material`)}),Ot.map(e=>(0,G.jsx)(`option`,{value:e,children:e},e))]}),(0,G.jsxs)(`select`,{value:A,onChange:e=>{j(e.target.value),Et()},className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${A?`bg-bambu-green/20 text-bambu-green border-bambu-green/30`:`bg-transparent text-bambu-gray border-bambu-dark-tertiary hover:bg-bambu-dark-tertiary`}`,children:[(0,G.jsx)(`option`,{value:``,children:n(`inventory.brand`)}),kt.map(e=>(0,G.jsx)(`option`,{value:e,children:e},e))]}),(At.length>0||M)&&(0,G.jsxs)(`select`,{value:M,onChange:e=>{N(e.target.value),Et()},className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${M?`bg-bambu-green/20 text-bambu-green border-bambu-green/30`:`bg-transparent text-bambu-gray border-bambu-dark-tertiary hover:bg-bambu-dark-tertiary`}`,children:[(0,G.jsx)(`option`,{value:``,children:n(`inventory.category`)}),At.map(e=>(0,G.jsx)(`option`,{value:e,children:e},e)),jt&&(0,G.jsx)(`option`,{value:`__none__`,children:n(`inventory.categoryNone`)})]}),Mt.length>0&&(0,G.jsxs)(`select`,{value:P,onChange:e=>{F(e.target.value),Et()},className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${P?`bg-bambu-green/20 text-bambu-green border-bambu-green/30`:`bg-transparent text-bambu-gray border-bambu-dark-tertiary hover:bg-bambu-dark-tertiary`}`,children:[(0,G.jsx)(`option`,{value:``,children:n(`inventory.spoolName`)}),Mt.map(e=>(0,G.jsx)(`option`,{value:e,children:_t[e]?.name||`#${e}`},e))]}),(Pe.length>0||Ie)&&(0,G.jsxs)(`select`,{value:Ie,onChange:e=>{Dt(e.target.value)},className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${Ie?`bg-bambu-green/20 text-bambu-green border-bambu-green/30`:`bg-transparent text-bambu-gray border-bambu-dark-tertiary hover:bg-bambu-dark-tertiary`}`,children:[(0,G.jsx)(`option`,{value:``,children:n(`inventory.storageLocation`)}),Pe.map(e=>(0,G.jsx)(`option`,{value:String(e.id),children:e.name},e.id)),Nt&&(0,G.jsx)(`option`,{value:`__none__`,children:n(`inventory.storageLocationNone`)})]}),Pt&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`w-px h-5 bg-bambu-dark-tertiary`}),(0,G.jsxs)(`button`,{onClick:()=>{T(`active`),D(`all`),k(``),j(``),N(``),F(``),L(`all`),z(``),l(e=>(e.delete(`location_id`),e),{replace:!0}),Et()},className:`flex items-center gap-1 text-xs text-bambu-gray hover:text-bambu-green transition-colors`,children:[(0,G.jsx)(nd,{className:`w-3.5 h-3.5`}),n(`inventory.clearFilters`)]})]}),B!==`forecast`&&(0,G.jsxs)(`span`,{className:`ml-auto text-xs text-bambu-gray`,children:[Rt.length,` `,Rt.length===1?n(`inventory.spool`):n(`inventory.spools`),oe&&Vt0&&B!==`forecast`&&(0,G.jsxs)(`div`,{className:`sticky top-2 z-10 mb-4 flex items-center gap-2 px-3 py-2 bg-bambu-green/10 border border-bambu-green/30 rounded-lg backdrop-blur-sm`,children:[(0,G.jsx)(`span`,{className:`text-sm text-bambu-green font-medium`,children:n(`inventory.bulk.selectionCount`,{count:le.size})}),(0,G.jsxs)(`div`,{className:`ml-auto flex flex-wrap items-center gap-2`,children:[(0,G.jsxs)(Q,{size:`sm`,variant:`secondary`,onClick:()=>fe(!0),children:[(0,G.jsx)(kl,{className:`w-3.5 h-3.5 mr-1.5`}),n(`inventory.bulk.edit`)]}),(0,G.jsxs)(Q,{size:`sm`,variant:`secondary`,onClick:()=>g([...le]),children:[(0,G.jsx)(Rl,{className:`w-3.5 h-3.5 mr-1.5`}),n(`inventory.bulk.printLabels`)]}),(0,G.jsxs)(Q,{size:`sm`,variant:`secondary`,onClick:()=>me(`reset-consumed-counter`),children:[(0,G.jsx)(nc,{className:`w-3.5 h-3.5 mr-1.5`}),n(`inventory.bulk.resetUsage`)]}),w===`archived`?(0,G.jsxs)(Q,{size:`sm`,variant:`secondary`,onClick:()=>me(`restore`),children:[(0,G.jsx)(Wl,{className:`w-3.5 h-3.5 mr-1.5`}),n(`inventory.bulk.restore`)]}):(0,G.jsxs)(Q,{size:`sm`,variant:`secondary`,onClick:()=>me(`archive`),children:[(0,G.jsx)(Po,{className:`w-3.5 h-3.5 mr-1.5`}),n(`inventory.bulk.archive`)]}),(0,G.jsxs)(Q,{size:`sm`,variant:`danger`,onClick:()=>me(`delete`),children:[(0,G.jsx)(Pu,{className:`w-3.5 h-3.5 mr-1.5`}),n(`inventory.bulk.delete`)]}),(0,G.jsx)(`button`,{className:`p-1.5 text-bambu-gray hover:text-white rounded transition-colors`,onClick:ge,title:n(`inventory.bulk.clearSelection`),"aria-label":n(`inventory.bulk.clearSelection`),children:(0,G.jsx)(nd,{className:`w-4 h-4`})})]})]}),je?(0,G.jsx)(`div`,{className:`flex justify-center py-16`,children:(0,G.jsx)(Y,{className:`w-8 h-8 text-bambu-green animate-spin`})}):B===`forecast`?(0,G.jsx)(J$e,{spools:Ae||[]}):B===`cards`?Gt.length>0?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4`,children:Gt.map(e=>{if(e.type===`group`){let{key:t,spools:r,representative:i}=e,a=r.reduce((e,t)=>e+Math.max(0,t.label_weight-t.weight_used),0),o=bH({rgba:i.rgba,extraColors:i.extra_colors,effectType:i.effect_type,subtype:i.subtype,effectSize:`groupheader`}),s=H.has(t);return(0,G.jsxs)(`div`,{className:`col-span-full`,children:[(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg overflow-hidden border border-bambu-green/30 hover:border-bambu-green transition-colors cursor-pointer`,onClick:()=>qt(t),children:[(0,G.jsx)(`div`,{className:`h-10 flex items-center px-4 gap-3`,style:o,children:(0,G.jsx)(`span`,{className:`bg-white/90 text-gray-800 px-3 py-0.5 rounded-full text-sm font-medium`,children:kf(i.color_name,i.rgba)||`-`})}),(0,G.jsxs)(`div`,{className:`px-4 py-3 flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(ps,{className:`w-4 h-4 text-bambu-gray transition-transform ${s?``:`-rotate-90`}`}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`h3`,{className:`font-semibold text-white`,children:[i.material,i.subtype?` ${i.subtype}`:``]}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i.brand||`-`})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,title:n(`inventory.remaining`),children:C9(a)}),(0,G.jsx)(`span`,{className:`text-xs font-medium bg-bambu-green/20 text-bambu-green px-2 py-0.5 rounded-full`,children:n(`inventory.groupedSpools`,{count:r.length})})]})]})]}),s&&(0,G.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4 mt-2 ml-4`,children:r.map(e=>{let t=Math.max(0,e.label_weight-e.weight_used);return(0,G.jsx)(J1e,{spool:e,remaining:t,pct:e.label_weight>0?t/e.label_weight*100:0,onClick:()=>d({spool:e,mode:`edit`}),onPrintLabel:()=>g([e.id]),onCopy:()=>d({spool:e,mode:`copy`}),t:n,colorizeLocationSensors:we,locationSensorAboveColor:Te,locationSensorBelowColor:Ee,locationSensorOptimalColor:De},e.id)})})]},`group-${t}`)}let t=e.spool,r=Math.max(0,t.label_weight-t.weight_used);return(0,G.jsx)(J1e,{spool:t,remaining:r,pct:t.label_weight>0?r/t.label_weight*100:0,onClick:()=>d({spool:t,mode:`edit`}),onPrintLabel:()=>g([t.id]),onCopy:()=>d({spool:t,mode:`copy`}),t:n,colorizeLocationSensors:we,locationSensorAboveColor:Te,locationSensorBelowColor:Ee,locationSensorOptimalColor:De},t.id)})}),(0,G.jsx)(q1e,{pageIndex:Wt,pageSize:ye,totalRows:Vt,totalPages:Ut,onPageChange:ve,onPageSizeChange:Jt,t:n})]}):(0,G.jsx)(e0e,{hasFilters:Pt,onAddSpool:()=>d({spool:null,mode:`create`}),t:n}):Gt.length>0?(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg overflow-hidden border border-bambu-dark-tertiary`,children:[(0,G.jsx)(`div`,{className:`overflow-x-auto`,children:(0,G.jsxs)(`table`,{className:`w-full`,children:[(0,G.jsx)(`thead`,{children:(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary bg-bambu-dark-tertiary/30`,children:[(0,G.jsx)(`th`,{className:`w-10 px-3 py-3`,children:(0,G.jsx)(`input`,{type:`checkbox`,className:`h-4 w-4 cursor-pointer`,"aria-label":n(`inventory.bulk.selectAllVisible`),checked:Gt.length>0&&Gt.every(e=>(e.type===`group`?e.spools.map(e=>e.id):[e.spool.id]).every(e=>le.has(e))),onChange:e=>{if(e.target.checked){let e=new Set(le);for(let t of Gt){let n=t.type===`group`?t.spools.map(e=>e.id):[t.spool.id];for(let t of n)e.add(t)}ue(e)}else{let e=new Set(le);for(let t of Gt){let n=t.type===`group`?t.spools.map(e=>e.id):[t.spool.id];for(let t of n)e.delete(t)}ue(e)}}})}),It.map(e=>{let t=!!E9[e],r=ee?.column===e;return(0,G.jsx)(`th`,{className:`text-left py-3 px-4 text-xs font-medium uppercase tracking-wide select-none ${e===`remaining`?`min-w-[150px]`:``} ${t?`cursor-pointer hover:text-bambu-green transition-colors`:``} ${r?`text-bambu-green`:`text-bambu-gray`}`,onClick:t?()=>Lt(e):void 0,children:(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[H1e[e]?.(n)??e,t&&(r?ee.direction===`asc`?(0,G.jsx)(Ho,{className:`w-3 h-3`}):(0,G.jsx)(Io,{className:`w-3 h-3`}):(0,G.jsx)(Bo,{className:`w-3 h-3 opacity-30`}))]})},e)}),(0,G.jsx)(`th`,{className:`text-right py-3 px-4 text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:n(`common.actions`)})]})}),(0,G.jsx)(`tbody`,{children:Gt.map(e=>{if(e.type===`group`){let{key:t,spools:r}=e,i=H.has(t),a=I1e(r),o=Math.max(0,a.label_weight-a.weight_used);return(0,G.jsx)($1e,{spools:r,headerSpool:a,remaining:o,pct:a.label_weight>0?o/a.label_weight*100:0,isExpanded:i,onToggle:()=>qt(t),selectedIds:le,onToggleSelected:he,onToggleGroupSelected:(e,t)=>{ue(n=>{let r=new Set(n);for(let n of e)t?r.add(n):r.delete(n);return r})},onEdit:e=>d({spool:e,mode:`edit`}),onCopy:e=>d({spool:e,mode:`copy`}),onArchive:e=>m({type:`archive`,spoolId:e}),onDelete:e=>m({type:`delete`,spoolId:e}),onPrintLabel:e=>g([e]),onResetConsumedCounter:e=>m({type:`reset-consumed-counter`,spoolId:e}),visibleColumns:It,assignmentMap:gt,catalogMap:_t,locationReadingsMap:Ct,currencySymbol:ht,dateFormat:Se,t:n,onSyncWeight:ot,colorizeLocationSensors:we,locationSensorAboveColor:Te,locationSensorBelowColor:Ee,locationSensorOptimalColor:De},`group-${t}`)}let t=e.spool,r=Math.max(0,t.label_weight-t.weight_used);return(0,G.jsx)(Q1e,{spool:t,remaining:r,pct:t.label_weight>0?r/t.label_weight*100:0,isSelected:le.has(t.id),onToggleSelected:()=>he(t.id),onEdit:()=>d({spool:t,mode:`edit`}),onCopy:()=>d({spool:t,mode:`copy`}),onRestore:()=>Ze.mutate(t.id),onArchive:()=>m({type:`archive`,spoolId:t.id}),onDelete:()=>m({type:`delete`,spoolId:t.id}),onPrintLabel:()=>g([t.id]),onResetConsumedCounter:()=>m({type:`reset-consumed-counter`,spoolId:t.id}),visibleColumns:It,assignmentMap:gt,catalogMap:_t,locationReadingsMap:Ct,currencySymbol:ht,dateFormat:Se,t:n,onSyncWeight:ot,colorizeLocationSensors:we,locationSensorAboveColor:Te,locationSensorBelowColor:Ee,locationSensorOptimalColor:De},t.id)})})]})}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 bg-bambu-dark-tertiary/50 border-t border-bambu-dark-tertiary text-sm`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:Bt?`${Vt} ${n(Vt===1?`inventory.spool`:`inventory.spools`)}`:(0,G.jsxs)(G.Fragment,{children:[n(`inventory.showing`),` `,Wt*Ht+1,` `,n(`inventory.to`),` `,Math.min((Wt+1)*Ht,Vt),` `,n(`inventory.of`),` `,Vt,` `,n(`inventory.spools`)]})}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:n(`inventory.show`)}),(0,G.jsxs)(`select`,{value:ye,onChange:e=>Jt(Number(e.target.value)),className:`px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:outline-none focus:border-bambu-green`,children:[[15,30,50,100].map(e=>(0,G.jsx)(`option`,{value:e,children:e},e)),(0,G.jsx)(`option`,{value:-1,children:n(`inventory.all`)})]}),!Bt&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`button`,{onClick:()=>ve(0),disabled:Wt===0,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,title:`First page`,children:(0,G.jsx)(_s,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:()=>ve(e=>Math.max(0,e-1)),disabled:Wt===0,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,children:(0,G.jsx)(hs,{className:`w-4 h-4`})}),(0,G.jsxs)(`span`,{className:`text-bambu-gray px-2 whitespace-nowrap`,children:[n(`inventory.page`),` `,Wt+1,` `,n(`inventory.of`),` `,Ut]}),(0,G.jsx)(`button`,{onClick:()=>ve(e=>Math.min(Ut-1,e+1)),disabled:Wt>=Ut-1,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,children:(0,G.jsx)(ms,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:()=>ve(Ut-1),disabled:Wt>=Ut-1,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,title:`Last page`,children:(0,G.jsx)(vs,{className:`w-4 h-4`})})]})]})]})]}):(0,G.jsx)(e0e,{hasFilters:Pt,onAddSpool:()=>d({spool:null,mode:`create`}),t:n}),u!==null&&(0,G.jsx)(T1e,{isOpen:!0,onClose:()=>d(null),spool:u.spool,mode:u.mode,currencySymbol:ht,spoolmanMode:e,spoolsQueryKey:Oe}),p&&(0,G.jsx)(of,{title:p.type===`delete`?n(`common.delete`):p.type===`archive`?n(`inventory.archive`):p.type===`reset-consumed-counter`?n(`inventory.resetConsumedCounter`):n(`inventory.resetAllConsumedCounters`),message:p.type===`delete`?n(`inventory.deleteConfirm`):p.type===`archive`?n(`inventory.archiveConfirm`):p.type===`reset-consumed-counter`?n(`inventory.resetConsumedCounterConfirm`):n(`inventory.resetAllConsumedCountersConfirm`,{count:at.length}),confirmText:p.type===`delete`?n(`common.delete`):p.type===`archive`?n(`inventory.archive`):n(`inventory.resetConsumedCounter`),variant:p.type===`archive`?`warning`:`danger`,onConfirm:()=>{p.type===`delete`?Ye.mutate(p.spoolId):p.type===`archive`?Xe.mutate(p.spoolId):p.type===`reset-consumed-counter`?Qe.mutate(p.spoolId):$e.mutate(at),m(null)},onCancel:()=>m(null)}),(0,G.jsx)(tG,{isOpen:ie,onClose:()=>ae(!1),columns:ne,defaultColumns:S9,onSave:Ft}),(0,G.jsx)(M1e,{isOpen:h!==null,onClose:()=>g(null),availableSpools:Tt,initialSelectedIds:h??[],spoolmanMode:e}),(0,G.jsx)(F1e,{isOpen:de,selectedCount:le.size,isPending:tt.isPending,availableLocations:Pe.map(e=>({id:e.id,name:e.name})),availableMaterials:x9((Ae??[]).map(e=>e.material)),availableSubtypes:x9((Ae??[]).map(e=>e.subtype)),availableBrands:x9((Ae??[]).map(e=>e.brand)),availableCategories:x9((Ae??[]).map(e=>e.category)),availableSlicerFilaments:x9((Ae??[]).map(e=>e.slicer_filament)),availableSlicerFilamentNames:x9((Ae??[]).map(e=>e.slicer_filament_name)),onClose:()=>fe(!1),onApply:e=>tt.mutate({ids:[...le],update:e})}),pe&&(0,G.jsx)(of,{title:n(pe===`delete`?`inventory.bulk.deleteTitle`:pe===`archive`?`inventory.bulk.archiveTitle`:pe===`restore`?`inventory.bulk.restoreTitle`:`inventory.bulk.resetUsageTitle`),message:n(pe===`delete`?`inventory.bulk.deleteMessage`:pe===`archive`?`inventory.bulk.archiveMessage`:pe===`restore`?`inventory.bulk.restoreMessage`:`inventory.bulk.resetUsageMessage`,{count:le.size}),confirmText:n(pe===`delete`?`common.delete`:pe===`archive`?`inventory.archive`:pe===`restore`?`inventory.restore`:`inventory.resetConsumedCounter`),variant:pe===`delete`?`danger`:`warning`,isLoading:nt.isPending||rt.isPending||it.isPending||$e.isPending,onConfirm:()=>{let e=[...le];pe===`delete`?nt.mutate(e):pe===`archive`?rt.mutate(e):pe===`restore`?it.mutate(e):$e.mutate(e)},onCancel:()=>me(null)}),_&&(0,G.jsx)(N1e,{onClose:()=>v(!1),onImported:e=>{v(!1),r.invalidateQueries({queryKey:Oe}),i(n(`inventory.csv.importSuccess`,`{{count}} spools imported`,{count:e}),`success`)}}),(0,G.jsx)(Z6,{open:S,onClose:()=>C(!1),onPickLocation:e=>Dt(String(e))})]})}function q1e({pageIndex:e,pageSize:t,totalRows:n,totalPages:r,onPageChange:i,onPageSizeChange:a,t:o}){let s=t===-1;if(r<=1&&!s)return null;let c=s?n||1:t;return(0,G.jsxs)(`div`,{className:`flex items-center justify-between pt-2 text-sm`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:s?`${n} ${o(n===1?`inventory.spool`:`inventory.spools`)}`:(0,G.jsxs)(G.Fragment,{children:[o(`inventory.showing`),` `,e*c+1,` `,o(`inventory.to`),` `,Math.min((e+1)*c,n),` `,o(`inventory.of`),` `,n,` `,o(`inventory.spools`)]})}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:o(`inventory.show`)}),(0,G.jsxs)(`select`,{value:t,onChange:e=>a(Number(e.target.value)),className:`px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:outline-none focus:border-bambu-green`,children:[[15,30,50,100].map(e=>(0,G.jsx)(`option`,{value:e,children:e},e)),(0,G.jsx)(`option`,{value:-1,children:o(`inventory.all`)})]}),!s&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`button`,{onClick:()=>i(0),disabled:e===0,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,children:(0,G.jsx)(_s,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:()=>i(Math.max(0,e-1)),disabled:e===0,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,children:(0,G.jsx)(hs,{className:`w-4 h-4`})}),(0,G.jsxs)(`span`,{className:`text-bambu-gray px-2 whitespace-nowrap`,children:[o(`inventory.page`),` `,e+1,` `,o(`inventory.of`),` `,r]}),(0,G.jsx)(`button`,{onClick:()=>i(Math.min(r-1,e+1)),disabled:e>=r-1,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,children:(0,G.jsx)(ms,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:()=>i(r-1),disabled:e>=r-1,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,children:(0,G.jsx)(vs,{className:`w-4 h-4`})})]})]})]})}function J1e({spool:e,remaining:t,pct:n,onClick:r,onPrintLabel:i,onCopy:a,t:o,colorizeLocationSensors:s,locationSensorAboveColor:c,locationSensorBelowColor:l,locationSensorOptimalColor:u}){let d=bH({rgba:e.rgba,extraColors:e.extra_colors,effectType:e.effect_type,subtype:e.subtype,effectSize:`card`});return(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg overflow-hidden border border-bambu-dark-tertiary hover:border-bambu-green transition-colors cursor-pointer ${e.archived_at?`opacity-50`:``}`,onClick:r,children:[(0,G.jsxs)(`div`,{className:`h-14 flex items-center justify-center`,style:d,children:[(0,G.jsx)(`span`,{className:`bg-white/90 text-gray-800 px-3 py-0.5 rounded-full text-sm font-medium`,children:kf(e.color_name,e.rgba)||`-`}),a&&(0,G.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),a()},className:`p-1.5 bg-black/20 hover:bg-black/40 text-white rounded-full transition-colors`,title:o(`inventory.copySpool`),children:(0,G.jsx)(Vs,{className:`w-3.5 h-3.5`})})]}),(0,G.jsxs)(`div`,{className:`p-4 space-y-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`h3`,{className:`font-semibold text-white`,children:[e.material,e.subtype?` ${e.subtype}`:``]}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e.brand||`-`})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[i&&(0,G.jsx)(`button`,{onClick:e=>{e.stopPropagation(),i()},className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,title:o(`inventory.labels.printOne`),"aria-label":o(`inventory.labels.printOne`),children:(0,G.jsx)(Rl,{className:`w-4 h-4`})}),(0,G.jsxs)(`span`,{className:`text-xs font-mono text-bambu-gray bg-bambu-dark-tertiary px-2 py-1 rounded`,children:[`#`,e.id]})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex justify-between text-xs text-bambu-gray mb-1`,children:[(0,G.jsx)(`span`,{children:o(`inventory.remaining`)}),(0,G.jsxs)(`span`,{children:[Math.round(n),`%`]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`div`,{className:`flex-1 h-2 bg-bambu-dark-tertiary rounded-full overflow-hidden`,children:(0,G.jsx)(`div`,{className:`h-full rounded-full ${n>50?`bg-bambu-green`:n>20?`bg-yellow-500`:`bg-red-500`}`,style:{width:`${Math.min(n,100)}%`}})}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray min-w-[40px] text-right`,children:[Math.round(t),`g`]})]})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-2 text-xs`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`span`,{className:`text-bambu-gray/60`,children:[o(`inventory.labelWeight`),`: `]}),(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:C9(e.label_weight)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`span`,{className:`text-bambu-gray/60`,children:[o(`inventory.weightUsed`),`: `]}),(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:e.weight_used>0?C9(e.weight_used):`-`})]})]}),e.location_id&&(0,G.jsx)(Z1e,{locationId:e.location_id,locationName:e.storage_location??null,isLast:!e.note,colorize:s,aboveColor:c,belowColor:l,optimalColor:u}),e.note&&(0,G.jsx)(`div`,{className:`text-xs text-bambu-gray/60 pt-3 border-t border-bambu-dark-tertiary truncate`,title:e.note,children:e.note})]})]})}var Y1e={temperature:0,humidity:1,battery:2};function X1e(e){return e===`humidity`?`mr-[2px]`:e===`battery`?`mr-[3px]`:``}function O9(e,t){return PT(e,t,{decimals:2})}function k9(e,t,n,r,i){return t&&B6(z6(e),n,r,i)||`text-bambu-gray`}function Z1e({locationId:e,locationName:t,isLast:n,colorize:r,aboveColor:i,belowColor:a,optimalColor:o}){let{t:s}=U(),{data:c}=K({queryKey:[`settings`],queryFn:Z.getSettings}),l=(c?.location_sensor_poll_interval||120)*1e3,{data:u}=K({queryKey:[`locationHaSensors`],queryFn:()=>Z.getLocationHASensors()}),d=(u??[]).some(t=>t.location_id===e),{data:f}=K({queryKey:[`locationHaSensorReadings`,e],queryFn:()=>Z.getLocationHASensorReadings(e,!1),refetchInterval:l,enabled:d}),p=f?.filter(e=>e.show_on_card);if(!p?.length)return null;let m=p.find(e=>e.device_class===`battery`),h=p.filter(e=>e.device_class!==`battery`).sort((e,t)=>(Y1e[e.device_class??``]??99)-(Y1e[t.device_class??``]??99));return(0,G.jsxs)(`div`,{className:`flex items-center gap-2 pt-3 border-t border-bambu-dark-tertiary text-xs text-bambu-gray ${n?`-mb-1`:``}`,children:[t&&(0,G.jsx)(`span`,{className:`truncate`,children:t}),(0,G.jsx)(`span`,{className:`text-bambu-gray/40`,children:`|`}),(0,G.jsx)(`div`,{className:`flex items-center gap-3`,children:h.map((e,t)=>{let n=FT(e),c=t===0?`ml-[-3.6px]`:``;return(0,G.jsxs)(`span`,{title:e.name,className:`flex items-center gap-[3px]`,children:[(0,G.jsx)(n,{className:`w-3 h-3 ${X1e(e.device_class)} ${c}`}),(0,G.jsx)(`span`,{className:k9(e,r,i,a,o),children:O9(e,s)})]},e.id)})}),m&&(()=>{let e=FT(m);return(0,G.jsxs)(`span`,{title:m.name,className:`flex items-center gap-[3px] ml-auto`,children:[(0,G.jsx)(e,{className:`w-3 h-3 ${X1e(m.device_class)}`}),(0,G.jsx)(`span`,{className:k9(m,r,i,a,o),children:O9(m,s)})]},m.id)})()]})}function Q1e({spool:e,remaining:t,pct:n,isSelected:r,onToggleSelected:i,onEdit:a,onCopy:o,onRestore:s,onArchive:c,onDelete:l,onPrintLabel:u,onResetConsumedCounter:d,visibleColumns:f,assignmentMap:p,catalogMap:m,locationReadingsMap:h,currencySymbol:g,dateFormat:_,t:v,onSyncWeight:y,colorizeLocationSensors:b,locationSensorAboveColor:x,locationSensorBelowColor:S,locationSensorOptimalColor:C}){return(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/50 hover:bg-bambu-dark-tertiary/30 transition-colors cursor-pointer ${e.archived_at?`opacity-50`:``} ${r?`bg-bambu-green/10`:``}`,onClick:a,children:[(0,G.jsx)(`td`,{className:`w-10 px-3 py-3`,onClick:e=>e.stopPropagation(),children:i&&(0,G.jsx)(`input`,{type:`checkbox`,className:`h-4 w-4 cursor-pointer`,"aria-label":v(`inventory.bulk.selectRow`),checked:!!r,onChange:i})}),f.map(r=>(0,G.jsx)(`td`,{className:`py-3 px-4`,children:T9[r]?.({spool:e,remaining:t,pct:n,assignmentMap:p,catalogMap:m,locationReadingsMap:h,currencySymbol:g,dateFormat:_,t:v,onSyncWeight:y,colorizeLocationSensors:b,locationSensorAboveColor:x,locationSensorBelowColor:S,locationSensorOptimalColor:C})},r)),(0,G.jsx)(`td`,{className:`py-3 px-4`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-end gap-1`,onClick:e=>e.stopPropagation(),children:[(0,G.jsx)(`button`,{onClick:a,className:`p-1.5 text-bambu-gray hover:text-white rounded transition-colors`,title:v(`common.edit`),children:(0,G.jsx)(kl,{className:`w-4 h-4`})}),o&&(0,G.jsx)(`button`,{onClick:o,className:`p-1.5 text-bambu-gray hover:text-bambu-green rounded transition-colors`,title:v(`inventory.copySpool`),children:(0,G.jsx)(Vs,{className:`w-4 h-4`})}),u&&(0,G.jsx)(`button`,{onClick:u,className:`p-1.5 text-bambu-gray hover:text-white rounded transition-colors`,title:v(`inventory.labels.printOne`),children:(0,G.jsx)(Rl,{className:`w-4 h-4`})}),d&&e.weight_used>0&&(0,G.jsx)(`button`,{onClick:d,className:`p-1.5 text-bambu-gray hover:text-orange-600 dark:hover:text-orange-400 rounded transition-colors`,title:v(`inventory.resetConsumedCounterTooltip`),children:(0,G.jsx)(nc,{className:`w-4 h-4`})}),e.archived_at?(0,G.jsx)(`button`,{onClick:s,className:`p-1.5 text-bambu-gray hover:text-bambu-green rounded transition-colors`,title:v(`inventory.restore`),children:(0,G.jsx)(Wl,{className:`w-4 h-4`})}):(0,G.jsx)(`button`,{onClick:c,className:`p-1.5 text-bambu-gray hover:text-yellow-600 dark:hover:text-yellow-400 rounded transition-colors`,title:v(`inventory.archive`),children:(0,G.jsx)(Po,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:l,className:`p-1.5 text-bambu-gray hover:text-red-600 dark:hover:text-red-400 rounded transition-colors`,title:v(`common.delete`),children:(0,G.jsx)(Pu,{className:`w-4 h-4`})})]})})]})}function $1e({spools:e,headerSpool:t,remaining:n,pct:r,isExpanded:i,onToggle:a,onEdit:o,onCopy:s,onArchive:c,onDelete:l,onPrintLabel:u,onResetConsumedCounter:d,visibleColumns:f,assignmentMap:p,catalogMap:m,locationReadingsMap:h,currencySymbol:g,dateFormat:_,t:v,onSyncWeight:y,colorizeLocationSensors:b,locationSensorAboveColor:x,locationSensorBelowColor:S,locationSensorOptimalColor:C,selectedIds:w,onToggleSelected:T,onToggleGroupSelected:E}){let D=!!w&&e.every(e=>w.has(e.id));return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/50 hover:bg-bambu-dark-tertiary/30 transition-colors cursor-pointer bg-bambu-green/5`,onClick:a,children:[(0,G.jsx)(`td`,{className:`w-10 px-3 py-3`,onClick:e=>e.stopPropagation(),children:E&&(0,G.jsx)(`input`,{type:`checkbox`,className:`h-4 w-4 cursor-pointer`,"aria-label":v(`inventory.bulk.selectGroup`),checked:D,onChange:t=>E(e.map(e=>e.id),t.target.checked)})}),f.map((a,o)=>(0,G.jsx)(`td`,{className:`py-3 px-4`,children:o===0?(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(ps,{className:`w-4 h-4 text-bambu-gray transition-transform ${i?``:`-rotate-90`}`}),T9[a]?.({spool:t,remaining:n,pct:r,assignmentMap:p,catalogMap:m,locationReadingsMap:h,currencySymbol:g,dateFormat:_,t:v,onSyncWeight:y,colorizeLocationSensors:b,locationSensorAboveColor:x,locationSensorBelowColor:S,locationSensorOptimalColor:C})]}):a===`id`?(0,G.jsx)(`span`,{className:`text-xs font-medium bg-bambu-green/20 text-bambu-green px-2 py-0.5 rounded-full`,children:v(`inventory.groupedSpools`,{count:e.length})}):T9[a]?.({spool:t,remaining:n,pct:r,assignmentMap:p,catalogMap:m,locationReadingsMap:h,currencySymbol:g,dateFormat:_,t:v,onSyncWeight:y,colorizeLocationSensors:b,locationSensorAboveColor:x,locationSensorBelowColor:S,locationSensorOptimalColor:C})},a)),(0,G.jsx)(`td`,{className:`py-3 px-4`,children:(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:e.map(e=>`#${e.id}`).join(`, `)})})]}),i&&e.map(e=>{let t=Math.max(0,e.label_weight-e.weight_used);return(0,G.jsx)(Q1e,{spool:e,remaining:t,pct:e.label_weight>0?t/e.label_weight*100:0,isSelected:w?.has(e.id),onToggleSelected:T?()=>T(e.id):void 0,onEdit:()=>o(e),onCopy:s?()=>s(e):void 0,onRestore:()=>{},onArchive:()=>c(e.id),onDelete:()=>l(e.id),onPrintLabel:u?()=>u(e.id):void 0,onResetConsumedCounter:d?()=>d(e.id):void 0,visibleColumns:f,assignmentMap:p,catalogMap:m,locationReadingsMap:h,currencySymbol:g,dateFormat:_,t:v,onSyncWeight:y,colorizeLocationSensors:b,locationSensorAboveColor:x,locationSensorBelowColor:S,locationSensorOptimalColor:C},e.id)})]})}function e0e({hasFilters:e,onAddSpool:t,t:n}){return(0,G.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-16 px-4`,children:[(0,G.jsxs)(`div`,{className:`relative mb-6`,children:[(0,G.jsx)(`div`,{className:`absolute inset-0 -m-4 bg-bambu-green/5 rounded-full blur-2xl`}),(0,G.jsxs)(`div`,{className:`relative flex items-center justify-center w-24 h-24 rounded-2xl bg-gradient-to-br from-bambu-dark-secondary to-bambu-dark-tertiary border border-bambu-dark-tertiary shadow-lg`,children:[(0,G.jsx)(`div`,{className:`absolute -top-1 -right-1 w-3 h-3 rounded-full bg-bambu-green/30`}),(0,G.jsx)(`div`,{className:`absolute -bottom-2 -left-2 w-2 h-2 rounded-full bg-bambu-green/20`}),e?(0,G.jsx)(Ql,{className:`w-10 h-10 text-bambu-gray/40`,strokeWidth:1.5}):(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(`div`,{className:`w-14 h-14 rounded-full border-4 border-bambu-gray/20 flex items-center justify-center`,children:(0,G.jsx)(`div`,{className:`w-6 h-6 rounded-full bg-bambu-gray/10 border-2 border-bambu-gray/20`})}),(0,G.jsx)(`div`,{className:`absolute -bottom-1 -right-1 w-6 h-6 rounded-full bg-bambu-green flex items-center justify-center shadow-md`,children:(0,G.jsx)(`span`,{className:`text-white text-lg font-bold leading-none`,children:`+`})})]})]})]}),(0,G.jsx)(`h3`,{className:`text-lg font-semibold text-white mb-2 text-center`,children:e?n(`inventory.noSpoolsMatch`):n(`inventory.noSpools`).split(`.`)[0]}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray text-center max-w-sm mb-6`,children:n(e?`inventory.noSpoolsMatchDesc`:`inventory.noSpools`)}),!e&&(0,G.jsxs)(Q,{onClick:t,children:[(0,G.jsx)(Cl,{className:`w-4 h-4`}),n(`inventory.addSpool`)]})]})}function A9(e,t){let n=e?.[t];return typeof n==`string`?n:``}function t0e(e){return e.replace(/(https?:\/\/(?:makerworld|public-cdn)\.bblmw\.com\/[^\s"']+)/gi,e=>`/api/v1/makerworld/thumbnail?url=${encodeURIComponent(e)}`)}function j9(e){return e?/^https?:\/\/(makerworld|public-cdn)\.bblmw\.com\//i.test(e)?`/api/v1/makerworld/thumbnail?url=${encodeURIComponent(e)}`:e:``}function M9(e,t){let n=e?.[t];return typeof n==`number`?n:null}function n0e(e,t){let n=e?.[t];return n&&typeof n==`object`&&!Array.isArray(n)?n:void 0}function r0e(e,t=0,n=[]){n.push({folder:e,depth:t});for(let r of e.children??[])r0e(r,t+1,n);return n}function i0e(e,t){return t(e<1?`makerworld.phaseResolving`:`makerworld.phaseDownloading`)}function a0e(e){let[t,n]=(0,y.useState)(0);return(0,y.useEffect)(()=>{if(!e){n(0);return}let t=Date.now(),r=()=>n(Math.floor((Date.now()-t)/1e3));r();let i=window.setInterval(r,1e3);return()=>window.clearInterval(i)},[e]),t}function o0e(){let{t:e}=U(),{hasPermission:t}=Nd(),{showToast:n}=qd(),r=co(),i=t(`makerworld:import`),[a,o]=(0,y.useState)(``),[s,c]=(0,y.useState)(null),[l,u]=(0,y.useState)(null),[d,f]=(0,y.useState)(null),[p,m]=(0,y.useState)(null),[h,g]=(0,y.useState)(null),[_,v]=(0,y.useState)(``),[b,x]=(0,y.useState)({}),S=K({queryKey:[`makerworld-status`],queryFn:()=>Z.getMakerworldStatus()}),C=K({queryKey:[`library-folders`],queryFn:()=>Z.getLibraryFolders()}),w=K({queryKey:[`makerworld-recent-imports`],queryFn:()=>Z.getMakerworldRecentImports(10)}),T=K({queryKey:[`settings`],queryFn:()=>Z.getSettings()}),E=T.data?.use_slicer_api??!1,D=T.data?.preferred_slicer||`bambu_studio`,O=HW(T.data?.open_in_slicer,T.data?.preferred_slicer),k=E?D:O,A=k===`orcaslicer`?`OrcaSlicer`:`Bambu Studio`,[j,M]=(0,y.useState)(null),N=(e,t)=>{M({kind:`libraryFile`,id:e,filename:t})},P=q({mutationFn:e=>Z.resolveMakerworldUrl(e),onSuccess:(e,t)=>{c(e),v(t),x({})},onError:t=>n(t.message||e(`makerworld.errors.resolveFailed`),`error`)});(0,y.useEffect)(()=>{s!==null&&a.trim()!==_.trim()&&(c(null),v(``),x({}))},[a,s,_]);let F=q({mutationFn:({instanceId:e,profileId:t})=>Z.importMakerworldInstance(s?.model_id??0,e,t,l),onSuccess:t=>{r.invalidateQueries({queryKey:[`library-files`]}),r.invalidateQueries({queryKey:[`library-folders`]}),t.profile_id&&x(e=>({...e,[t.profile_id]:t})),n(t.was_existing?e(`makerworld.alreadyInLibrary`):e(`makerworld.importSuccess`,{filename:t.filename}),`success`)},onError:t=>n(t.message||e(`makerworld.errors.downloadFailed`),`error`)}),I=q({mutationFn:({libraryFileId:e})=>Z.deleteLibraryFile(e),onSuccess:(t,{profileId:i})=>{r.invalidateQueries({queryKey:[`library-files`]}),r.invalidateQueries({queryKey:[`library-folders`]}),r.invalidateQueries({queryKey:[`makerworld-recent-imports`]}),x(e=>{let t={...e};return delete t[i],t}),m(null),n(e(`makerworld.importDeleted`),`success`)},onError:t=>{m(null),n(t.message||e(`makerworld.errors.deleteFailed`),`error`)}}),L=q({mutationFn:({instanceId:e,profileId:t})=>Z.importMakerworldInstance(s?.model_id??0,e,t,l),onSuccess:async e=>{r.invalidateQueries({queryKey:[`library-files`]}),r.invalidateQueries({queryKey:[`library-folders`]}),r.invalidateQueries({queryKey:[`makerworld-recent-imports`]}),e.profile_id&&x(t=>({...t,[e.profile_id]:e})),E?N(e.library_file_id,e.filename):await te(e.library_file_id,e.filename,k)},onError:t=>n(t.message||e(`makerworld.errors.downloadFailed`),`error`)}),R=a0e(F.isPending||L.isPending),z=i0e(R,e),B=e=>{e?.preventDefault();let t=a.trim();t&&P.mutate(t)};(0,y.useEffect)(()=>{if(!h)return;let e=e=>{e.key===`Escape`?g(null):e.key===`ArrowLeft`?g(e=>e&&e.index>0?{...e,index:e.index-1}:e):e.key===`ArrowRight`&&g(e=>e&&e.indexwindow.removeEventListener(`keydown`,e)},[h]);let V=e=>{let t=(Array.isArray(e.pictures)?e.pictures:[]).filter(e=>typeof e==`object`&&!!e).map(e=>({name:A9(e,`name`)||`image`,url:A9(e,`url`)})).filter(e=>e.url);if(t.length>0)return t;let n=A9(e,`cover`);return n?[{name:`cover`,url:n}]:[]},ee=async()=>{if(!s)return;let e=s.instances.filter(e=>{let t=M9(e,`profileId`);return t!==null&&!b[t]});if(e.length!==0){f({current:0,total:e.length});try{for(let t=0;t{try{let{token:r}=await Z.createLibrarySlicerToken(e),i=Z.getLibrarySlicerDownloadUrl(e,r,t);KW(`${window.location.origin}${i}`,n)}catch{let t=Z.getLibraryFileDownloadUrl(e);KW(`${window.location.origin}${t}`,n)}},ne=s?.design,re=n0e(ne,`designCreator`),ie=s?.instances??[],ae=(s?.already_imported_library_ids.length??0)>0,oe=S.data?.can_download??!1,se=S.data?.sign_in_expired??!1,H=(0,y.useMemo)(()=>A9(ne,`coverUrl`),[ne]),ce=A9(ne,`title`),le=A9(ne,`summary`),ue=A9(ne,`license`),de=M9(ne,`downloadCount`);return(0,G.jsxs)(`div`,{className:`p-4 md:p-8 max-w-screen-2xl space-y-6`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,G.jsx)(Ac,{className:`w-7 h-7 text-bambu-green`}),e(`makerworld.title`)]}),(0,G.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:e(`makerworld.description`)})]}),(0,G.jsxs)(`div`,{className:`grid gap-6 lg:grid-cols-[1fr_20rem]`,children:[(0,G.jsxs)(`div`,{className:`space-y-6 min-w-0`,children:[!oe&&(0,G.jsx)(zd,{className:`border-amber-300 dark:border-amber-700 bg-amber-50 dark:bg-amber-900/20`,children:(0,G.jsx)(Vd,{children:(0,G.jsxs)(`div`,{className:`flex items-start gap-3 py-2`,children:[(0,G.jsx)(ys,{className:`w-5 h-5 text-amber-600 dark:text-amber-400 mt-0.5 shrink-0`}),(0,G.jsxs)(`div`,{className:`text-sm`,children:[(0,G.jsx)(`p`,{className:`font-medium text-amber-900 dark:text-amber-100`,children:e(se?`makerworld.signInExpiredTitle`:`makerworld.signInRequiredTitle`)}),(0,G.jsxs)(`p`,{className:`text-amber-800 dark:text-amber-200 mt-1`,children:[e(se?`makerworld.signInExpiredBody`:`makerworld.signInRequiredBody`),` `,(0,G.jsx)(Ai,{to:`/profiles`,className:`underline`,children:e(`makerworld.openCloudSettings`)})]})]})]})})}),(0,G.jsxs)(zd,{children:[(0,G.jsx)(Bd,{children:(0,G.jsx)(`h2`,{className:`text-lg font-semibold`,children:e(`makerworld.pasteUrlHeader`)})}),(0,G.jsx)(Vd,{children:(0,G.jsxs)(`form`,{onSubmit:B,className:`flex gap-2`,children:[(0,G.jsx)(`input`,{type:`text`,value:a,onChange:e=>o(e.target.value),placeholder:e(`makerworld.pasteUrlPlaceholder`),className:`flex-1 min-w-0 px-3 py-2 border rounded bg-white dark:bg-gray-800 border-gray-300 dark:border-gray-700`,autoComplete:`off`}),(0,G.jsxs)(Q,{type:`submit`,variant:`primary`,disabled:!a.trim()||P.isPending,children:[P.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(zo,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`ml-2`,children:e(`makerworld.resolveButton`)})]})]})})]}),s&&(0,G.jsx)(zd,{children:(0,G.jsx)(Vd,{children:(0,G.jsxs)(`div`,{className:`flex gap-4 py-2`,children:[H&&(0,G.jsx)(`img`,{src:j9(H),alt:ce,className:`w-32 h-32 object-cover rounded`,loading:`lazy`}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`h3`,{className:`text-xl font-semibold truncate`,children:ce||e(`makerworld.untitledModel`)}),re&&(0,G.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400 mt-1`,children:e(`makerworld.byCreator`,{name:A9(re,`name`)})}),(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-3 mt-2 text-xs text-gray-500 dark:text-gray-400`,children:[de!==null&&(0,G.jsx)(`span`,{children:e(`makerworld.downloadsCount`,{count:de})}),ue&&(0,G.jsxs)(`span`,{children:[e(`makerworld.licensePrefix`),`: `,ue]}),ae&&(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-emerald-600 dark:text-emerald-400`,children:[(0,G.jsx)(fs,{className:`w-3 h-3`}),` `,e(`makerworld.alreadyImported`)]})]}),le&&(0,G.jsx)(`div`,{className:`mt-3 text-sm prose prose-sm max-w-none dark:prose-invert line-clamp-3`,dangerouslySetInnerHTML:{__html:JG.sanitize(t0e(le))}}),s&&(0,G.jsxs)(`a`,{href:`https://makerworld.com/models/${s.model_id}${s.profile_id?`#profileId-${s.profile_id}`:``}`,target:`_blank`,rel:`noopener noreferrer`,className:`mt-3 inline-flex items-center gap-1 text-xs text-brand-500 hover:underline`,children:[(0,G.jsx)(rc,{className:`w-3 h-3`}),` `,e(`makerworld.openOnMakerworld`)]})]})]})})}),s&&ie.length>0&&(0,G.jsxs)(zd,{children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,G.jsx)(`h2`,{className:`text-lg font-semibold`,children:e(`makerworld.platesHeader`,{count:ie.length})}),(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,G.jsx)(`label`,{className:`text-xs text-gray-600 dark:text-gray-400`,children:e(`makerworld.importTo`)}),(0,G.jsxs)(`select`,{value:l??``,onChange:e=>u(e.target.value?Number(e.target.value):null),className:`text-sm px-2 py-1 border rounded bg-white dark:bg-gray-800 border-gray-300 dark:border-gray-700`,disabled:d!==null,children:[(0,G.jsx)(`option`,{value:``,children:e(`makerworld.folderAuto`)}),(C.data??[]).filter(e=>!(e.is_external&&e.external_readonly)).flatMap(e=>r0e(e)).map(({folder:e,depth:t})=>(0,G.jsx)(`option`,{value:e.id,children:`${`— `.repeat(t)}${e.name}`},e.id))]}),(0,G.jsx)(Q,{variant:`primary`,size:`sm`,disabled:!i||!oe||d!==null||F.isPending||L.isPending,onClick:ee,children:d===null?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Xs,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`ml-2`,children:e(`makerworld.importAll`)})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),(0,G.jsxs)(`span`,{className:`ml-2`,children:[e(`makerworld.importAllProgress`,{current:d.current,total:d.total}),R>0&&` · ${z} · ${R}s`]})]})})]})]})}),(0,G.jsx)(Vd,{children:(0,G.jsx)(`div`,{className:`grid gap-3`,children:ie.map((t,n)=>{let r=M9(t,`id`),a=M9(t,`profileId`),o=A9(t,`title`),s=A9(t,`cover`),c=M9(t,`materialCnt`),l=t?.needAms===!0,u=M9(t,`downloadCount`),f=t?.compatibility??null,p=t?.otherCompatibility??null,h=f?.devProductName??null,_=Array.isArray(p)?p.map(e=>e?.devProductName??``).filter(Boolean):[];if(r==null)return null;let v=F.isPending&&F.variables?.instanceId===r,y=L.isPending&&L.variables?.instanceId===r,x=a===null?void 0:b[a];return(0,G.jsxs)(`div`,{className:`flex flex-col gap-2 p-3 border rounded border-gray-200 dark:border-gray-700`,children:[(0,G.jsxs)(`div`,{className:`flex gap-3 items-center`,children:[(()=>{let n=V(t),r=n.length>0;return(0,G.jsxs)(`button`,{type:`button`,disabled:!r,onClick:()=>r&&g({images:n,index:0}),className:`relative w-16 h-16 shrink-0 rounded overflow-hidden group`,"aria-label":e(`makerworld.openGallery`),children:[s?(0,G.jsx)(`img`,{src:j9(s),alt:``,className:`w-16 h-16 object-cover`,loading:`lazy`}):(0,G.jsx)(`div`,{className:`w-16 h-16 bg-gray-100 dark:bg-gray-800`}),n.length>1&&(0,G.jsxs)(`span`,{className:`absolute bottom-0.5 right-0.5 bg-black/70 text-white text-[10px] px-1.5 py-0.5 rounded flex items-center gap-1`,children:[(0,G.jsx)(Uc,{className:`w-2.5 h-2.5`}),n.length]})]})})(),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`p`,{className:`font-medium truncate`,children:o||e(`makerworld.plateDefaultName`,{n:n+1})}),(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-3 text-xs text-gray-500 dark:text-gray-400 mt-1`,children:[h&&(0,G.jsx)(`span`,{className:`font-medium text-gray-700 dark:text-gray-300`,children:e(`makerworld.slicedFor`,{printer:h,defaultValue:`Sliced for {{printer}}`})}),c!==null&&(0,G.jsx)(`span`,{children:e(`makerworld.materialCount`,{count:c})}),l&&(0,G.jsx)(`span`,{children:e(`makerworld.amsRequired`)}),u!==null&&(0,G.jsx)(`span`,{children:e(`makerworld.downloadsCount`,{count:u})})]}),_.length>0&&(0,G.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mt-1`,title:_.join(`, `),children:e(`makerworld.alsoCompatible`,{printers:_.slice(0,6).join(`, `)+(_.length>6?`…`:``),defaultValue:`Also marked compatible: {{printers}}`})})]}),(0,G.jsxs)(`div`,{className:`flex gap-2 shrink-0`,children:[(0,G.jsx)(Q,{variant:`ghost`,size:`sm`,disabled:!i||!oe||v||y||d!==null,onClick:()=>F.mutate({instanceId:r,profileId:a}),title:oe?void 0:e(`makerworld.signInRequiredTitle`),children:v?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),(0,G.jsxs)(`span`,{className:`ml-2`,children:[z,R>0&&` · ${R}s`]})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Xs,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`ml-2`,children:e(`makerworld.importToLibrary`)})]})}),(0,G.jsx)(Q,{variant:`primary`,size:`sm`,disabled:!i||!oe||v||y||d!==null,onClick:()=>L.mutate({instanceId:r,profileId:a}),title:oe?void 0:e(`makerworld.signInRequiredTitle`),children:y?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),(0,G.jsxs)(`span`,{className:`ml-2`,children:[z,R>0&&` · ${R}s`]})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(rc,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`ml-2`,children:e(`makerworld.sliceIn`,{slicer:A})})]})})]})]}),x&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2 pl-20 text-xs`,children:[(0,G.jsx)(fs,{className:`w-3.5 h-3.5 text-emerald-600 dark:text-emerald-400 shrink-0`}),(0,G.jsx)(`span`,{className:`text-emerald-700 dark:text-emerald-300`,children:x.was_existing?e(`makerworld.lastImportAlreadyInLibrary`):e(`makerworld.lastImportSuccess`)}),(0,G.jsxs)(Q,{variant:`ghost`,size:`sm`,onClick:()=>{let e=x.folder_id?`/files?folder=${x.folder_id}`:`/files`;window.location.assign(e)},children:[(0,G.jsx)(vc,{className:`w-3.5 h-3.5`}),(0,G.jsx)(`span`,{className:`ml-1.5`,children:e(`makerworld.viewInLibrary`)})]}),E?(0,G.jsxs)(Q,{variant:`ghost`,size:`sm`,onClick:()=>N(x.library_file_id,x.filename),children:[(0,G.jsx)(Rs,{className:`w-3.5 h-3.5`}),(0,G.jsx)(`span`,{className:`ml-1.5`,children:e(`slice.action`,`Slice`)})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(Q,{variant:`ghost`,size:`sm`,onClick:()=>te(x.library_file_id,x.filename,`bambu_studio`),children:[(0,G.jsx)(rc,{className:`w-3.5 h-3.5`}),(0,G.jsx)(`span`,{className:`ml-1.5`,children:e(`makerworld.openInBambuStudio`)})]}),(0,G.jsxs)(Q,{variant:`ghost`,size:`sm`,onClick:()=>te(x.library_file_id,x.filename,`orcaslicer`),children:[(0,G.jsx)(rc,{className:`w-3.5 h-3.5`}),(0,G.jsx)(`span`,{className:`ml-1.5`,children:e(`makerworld.openInOrcaSlicer`)})]})]}),(0,G.jsx)(`div`,{className:`ml-auto`,children:(0,G.jsx)(Q,{variant:`ghost`,size:`sm`,disabled:I.isPending&&I.variables?.profileId===a,onClick:()=>{a!==null&&m({libraryFileId:x.library_file_id,profileId:a,filename:x.filename})},title:e(`makerworld.deleteImport`),children:I.isPending&&I.variables?.profileId===a?(0,G.jsx)(Y,{className:`w-3.5 h-3.5 animate-spin`}):(0,G.jsx)(Pu,{className:`w-3.5 h-3.5 text-red-500`})})})]})]},r)})})})]})]}),(0,G.jsx)(`aside`,{className:`lg:sticky lg:top-6 lg:self-start min-w-0`,children:w.data&&w.data.length>0&&(0,G.jsxs)(zd,{children:[(0,G.jsx)(Bd,{children:(0,G.jsx)(`h2`,{className:`text-base font-semibold`,children:e(`makerworld.recentImportsHeader`)})}),(0,G.jsx)(Vd,{children:(0,G.jsx)(`div`,{className:`flex flex-col gap-2 max-h-[28rem] overflow-y-auto -mx-2 px-2`,children:w.data.map(t=>(0,G.jsxs)(`div`,{className:`flex gap-2 p-2 border rounded border-gray-200 dark:border-gray-700`,children:[t.thumbnail_path?(0,G.jsx)(`img`,{src:Z.getLibraryFileThumbnailUrl(t.library_file_id),alt:``,className:`w-12 h-12 shrink-0 object-cover rounded bg-gray-100 dark:bg-gray-800`,loading:`lazy`}):(0,G.jsx)(`div`,{className:`w-12 h-12 shrink-0 rounded bg-gray-100 dark:bg-gray-800`}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0 flex flex-col gap-1`,children:[(0,G.jsx)(`p`,{className:`text-xs font-medium truncate`,title:t.filename,children:t.filename}),(0,G.jsxs)(`div`,{className:`flex gap-0.5`,children:[(0,G.jsx)(Q,{variant:`ghost`,size:`sm`,onClick:()=>{let e=t.folder_id?`/files?folder=${t.folder_id}`:`/files`;window.location.assign(e)},title:e(`makerworld.viewInLibrary`),children:(0,G.jsx)(vc,{className:`w-3.5 h-3.5`})}),E?(0,G.jsx)(Q,{variant:`ghost`,size:`sm`,onClick:()=>N(t.library_file_id,t.filename),title:e(`slice.action`,`Slice`),children:(0,G.jsx)(Rs,{className:`w-3.5 h-3.5`})}):(0,G.jsx)(Q,{variant:`ghost`,size:`sm`,onClick:()=>te(t.library_file_id,t.filename,`bambu_studio`),title:e(`makerworld.openInBambuStudio`),children:(0,G.jsx)(rc,{className:`w-3.5 h-3.5`})}),t.source_url&&(0,G.jsx)(`a`,{href:t.source_url,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center justify-center h-7 w-7 rounded text-gray-500 hover:text-gray-700 dark:hover:text-gray-300`,title:e(`makerworld.openOnMakerworld`),children:(0,G.jsx)(Ac,{className:`w-3.5 h-3.5`})})]})]})]},t.library_file_id))})})]})})]}),(0,G.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 pt-4 border-t border-gray-200 dark:border-gray-700`,children:e(`makerworld.disclaimer`)}),p&&(0,G.jsx)(of,{title:e(`makerworld.deleteImport`),message:e(`makerworld.confirmDelete`,{filename:p.filename}),confirmText:e(`makerworld.deleteImport`),variant:`danger`,isLoading:I.isPending,loadingText:e(`makerworld.importDeleting`),onCancel:()=>m(null),onConfirm:()=>I.mutate({libraryFileId:p.libraryFileId,profileId:p.profileId})}),j&&(0,G.jsx)(RW,{source:j,onClose:()=>M(null)}),h&&(0,G.jsxs)(`div`,{className:`fixed inset-0 bg-black/90 flex items-center justify-center z-50`,onClick:()=>g(null),role:`dialog`,"aria-modal":`true`,children:[(0,G.jsx)(`button`,{type:`button`,className:`absolute top-4 right-4 p-2 bg-white/10 hover:bg-white/20 rounded-full text-white`,onClick:e=>{e.stopPropagation(),g(null)},"aria-label":e(`common.close`,`Close`),children:(0,G.jsx)(nd,{className:`w-5 h-5`})}),h.images.length>1&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`button`,{type:`button`,className:`absolute left-4 p-2 bg-white/10 hover:bg-white/20 rounded-full text-white disabled:opacity-30`,disabled:h.index===0,onClick:e=>{e.stopPropagation(),g(e=>e&&{...e,index:Math.max(0,e.index-1)})},"aria-label":e(`makerworld.galleryPrev`),children:(0,G.jsx)(hs,{className:`w-6 h-6`})}),(0,G.jsx)(`button`,{type:`button`,className:`absolute right-4 p-2 bg-white/10 hover:bg-white/20 rounded-full text-white disabled:opacity-30`,disabled:h.index>=h.images.length-1,onClick:e=>{e.stopPropagation(),g(e=>e&&{...e,index:Math.min(e.images.length-1,e.index+1)})},"aria-label":e(`makerworld.galleryNext`),children:(0,G.jsx)(ms,{className:`w-6 h-6`})})]}),(0,G.jsx)(`img`,{src:j9(h.images[h.index].url),alt:h.images[h.index].name,className:`max-w-[90vw] max-h-[90vh] object-contain`,onClick:e=>e.stopPropagation()}),h.images.length>1&&(0,G.jsxs)(`div`,{className:`absolute bottom-6 left-1/2 -translate-x-1/2 text-white bg-black/60 px-3 py-1 rounded text-xs`,children:[h.index+1,` / `,h.images.length]})]})]})}var s0e=[`DEBUG`,`INFO`,`WARNING`,`ERROR`],N9={DEBUG:`text-gray-400`,INFO:`text-blue-400`,WARNING:`text-yellow-400`,ERROR:`text-red-400`},c0e={DEBUG:$o,INFO:Wc,WARNING:Lu,ERROR:ys};function l0e(){let e=co(),[t,n]=(0,y.useState)(!0),[r,i]=(0,y.useState)(new Set),[a,o]=(0,y.useState)(``),[s,c]=(0,y.useState)(`ALL`),[l,u]=(0,y.useState)(!1),[d,f]=(0,y.useState)(!1),p=(0,y.useRef)(null),{data:m,isLoading:h,refetch:g}=K({queryKey:[`application-logs`,s,a],queryFn:()=>Dd.getLogs({limit:200,level:s===`ALL`?void 0:s,search:a||void 0}),refetchInterval:d?2e3:!1,enabled:l});(0,y.useEffect)(()=>{l||f(!1)},[l]);let _=q({mutationFn:()=>Dd.clearLogs(),onSuccess:()=>{e.invalidateQueries({queryKey:[`application-logs`]})}});(0,y.useEffect)(()=>{t&&p.current&&m?.entries&&(p.current.scrollTop=p.current.scrollHeight)},[m?.entries,t]);let v=e=>{i(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},b=e=>{let t=e.split(` `);return t.length>=2?t[1]:e},x=(0,y.useMemo)(()=>m?.entries??[],[m?.entries]),S=(0,y.useMemo)(()=>[...x].reverse(),[x]),C=({level:e})=>(0,G.jsx)(c0e[e]||Wc,{className:`w-3.5 h-3.5 ${N9[e]||`text-gray-400`}`});return(0,G.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg overflow-hidden`,children:[(0,G.jsxs)(`button`,{onClick:()=>u(!l),className:`w-full flex items-center justify-between p-4 hover:bg-bambu-dark-tertiary/50 transition-colors`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`p-2 rounded-lg ${d?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark-tertiary text-bambu-gray`}`,children:(0,G.jsx)($o,{className:`w-5 h-5`})}),(0,G.jsxs)(`div`,{className:`text-left`,children:[(0,G.jsx)(`p`,{className:`font-medium text-white`,children:`Application Logs`}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:d?`Live streaming - ${m?.filtered_count??0} entries`:`View and filter application logs`})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[d&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1.5 px-2 py-1 bg-bambu-green/20 rounded text-bambu-green text-xs`,children:[(0,G.jsx)(`span`,{className:`w-1.5 h-1.5 bg-bambu-green rounded-full animate-pulse`}),`Live`]}),l?(0,G.jsx)(gs,{className:`w-5 h-5 text-bambu-gray`}):(0,G.jsx)(ps,{className:`w-5 h-5 text-bambu-gray`})]})]}),l&&(0,G.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex flex-col gap-2 p-4 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[d?(0,G.jsxs)(`button`,{onClick:e=>{e.stopPropagation(),f(!1)},className:`flex items-center gap-1.5 px-3 py-1.5 text-sm bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400 hover:bg-red-200 dark:hover:bg-red-500/30 rounded transition-colors`,children:[(0,G.jsx)(bu,{className:`w-4 h-4`}),`Stop`]}):(0,G.jsxs)(`button`,{onClick:e=>{e.stopPropagation(),f(!0),g()},className:`flex items-center gap-1.5 px-3 py-1.5 text-sm bg-bambu-green/20 text-bambu-green hover:bg-bambu-green/30 rounded transition-colors`,children:[(0,G.jsx)(Nl,{className:`w-4 h-4`}),`Start`]}),(0,G.jsxs)(`button`,{onClick:()=>_.mutate(),disabled:_.isPending||x.length===0,className:`flex items-center gap-1.5 px-3 py-1.5 text-sm bg-bambu-dark-tertiary text-bambu-gray hover:text-white hover:bg-bambu-dark-secondary rounded transition-colors disabled:opacity-50`,children:[(0,G.jsx)(Pu,{className:`w-4 h-4`}),`Clear`]}),(0,G.jsx)(`button`,{onClick:()=>g(),disabled:h,className:`flex items-center gap-1.5 px-3 py-1.5 text-sm bg-bambu-dark-tertiary text-bambu-gray hover:text-white hover:bg-bambu-dark-secondary rounded transition-colors disabled:opacity-50`,children:(0,G.jsx)(Hl,{className:`w-4 h-4 ${h?`animate-spin`:``}`})}),(0,G.jsx)(`div`,{className:`flex-1`}),(0,G.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-bambu-gray cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:t,onChange:e=>n(e.target.checked),className:`rounded border-bambu-dark-tertiary bg-bambu-dark-tertiary`}),`Auto-scroll`]}),(0,G.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[m?.filtered_count??0,`/`,m?.total_in_file??0]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`div`,{className:`relative flex-1`,children:[(0,G.jsx)(Ql,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,G.jsx)(`input`,{type:`text`,placeholder:`Search message or logger name...`,value:a,onChange:e=>o(e.target.value),className:`w-full pl-8 pr-8 py-1.5 text-sm bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`}),a&&(0,G.jsx)(`button`,{onClick:()=>o(``),className:`absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white`,children:(0,G.jsx)(nd,{className:`w-4 h-4`})})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1 bg-bambu-dark-secondary rounded border border-bambu-dark-tertiary`,children:[(0,G.jsx)(`button`,{onClick:()=>c(`ALL`),className:`px-2 py-1.5 text-xs rounded-l transition-colors ${s===`ALL`?`bg-bambu-green text-white`:`text-bambu-gray hover:text-white`}`,children:`All`}),s0e.map((e,t)=>(0,G.jsx)(`button`,{onClick:()=>c(e),className:`px-2 py-1.5 text-xs transition-colors flex items-center gap-1 ${t===s0e.length-1?`rounded-r`:``} ${s===e?`${N9[e]} bg-bambu-dark-tertiary`:`text-bambu-gray hover:text-white`}`,children:e},e))]})]})]}),(0,G.jsx)(`div`,{ref:p,className:`overflow-auto font-mono text-xs bg-black min-h-[300px] max-h-[500px]`,children:x.length===0?(0,G.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-[300px] text-bambu-gray`,children:[(0,G.jsx)(`p`,{className:`mb-2`,children:`No log entries found`}),(0,G.jsx)(`p`,{className:`text-sm`,children:`Log file may be empty or cleared`})]}):(0,G.jsx)(`div`,{className:`divide-y divide-bambu-dark-tertiary/30`,children:S.map((e,t)=>{let n=r.has(t),i=e.message.includes(` +`}),n}function wZe(e){let t=0,n=e.charCodeAt(t);for(;n===9||n===32;)t++,n=e.charCodeAt(t);return e.slice(t)}function TZe(e,t){let n=yZe(e,t),r=n.one(e,void 0),i=oZe(n),a=Array.isArray(r)?{type:`root`,children:r}:r||{type:`root`,children:[]};return i&&(`children`in a,a.children.push({type:`text`,value:` +`},i)),a}function EZe(e,t){return e&&`run`in e?async function(n,r){let i=TZe(n,{file:r,...t});await e.run(i,r)}:function(n,r){return TZe(n,{file:r,...e||t})}}function DZe(e){if(e)throw e}var OZe=o(((e,t)=>{var n=Object.prototype.hasOwnProperty,r=Object.prototype.toString,i=Object.defineProperty,a=Object.getOwnPropertyDescriptor,o=function(e){return typeof Array.isArray==`function`?Array.isArray(e):r.call(e)===`[object Array]`},s=function(e){if(!e||r.call(e)!==`[object Object]`)return!1;var t=n.call(e,`constructor`),i=e.constructor&&e.constructor.prototype&&n.call(e.constructor.prototype,`isPrototypeOf`);if(e.constructor&&!t&&!i)return!1;for(var a in e);return a===void 0||n.call(e,a)},c=function(e,t){i&&t.name===`__proto__`?i(e,t.name,{enumerable:!0,configurable:!0,value:t.newValue,writable:!0}):e[t.name]=t.newValue},l=function(e,t){if(t===`__proto__`){if(!n.call(e,t))return;if(a)return a(e,t).value}return e[t]};t.exports=function e(){var t,n,r,i,a,u,d=arguments[0],f=1,p=arguments.length,m=!1;for(typeof d==`boolean`&&(m=d,d=arguments[1]||{},f=2),(d==null||typeof d!=`object`&&typeof d!=`function`)&&(d={});ft.length,o;r&&t.push(i);try{o=e.apply(this,t)}catch(e){let t=e;if(r&&n)throw t;return i(t)}r||(o&&o.then&&typeof o.then==`function`?o.then(a,i):o instanceof Error?i(o):a(o))}function i(e,...r){n||(n=!0,t(e,...r))}function a(e){i(null,e)}}var G7={basename:jZe,dirname:MZe,extname:NZe,join:PZe,sep:`/`};function jZe(e,t){if(t!==void 0&&typeof t!=`string`)throw TypeError(`"ext" argument must be a string`);K7(e);let n=0,r=-1,i=e.length,a;if(t===void 0||t.length===0||t.length>e.length){for(;i--;)if(e.codePointAt(i)===47){if(a){n=i+1;break}}else r<0&&(a=!0,r=i+1);return r<0?``:e.slice(n,r)}if(t===e)return``;let o=-1,s=t.length-1;for(;i--;)if(e.codePointAt(i)===47){if(a){n=i+1;break}}else o<0&&(a=!0,o=i+1),s>-1&&(e.codePointAt(i)===t.codePointAt(s--)?s<0&&(r=i):(s=-1,r=o));return n===r?r=o:r<0&&(r=e.length),e.slice(n,r)}function MZe(e){if(K7(e),e.length===0)return`.`;let t=-1,n=e.length,r;for(;--n;)if(e.codePointAt(n)===47){if(r){t=n;break}}else r||=!0;return t<0?e.codePointAt(0)===47?`/`:`.`:t===1&&e.codePointAt(0)===47?`//`:e.slice(0,t)}function NZe(e){K7(e);let t=e.length,n=-1,r=0,i=-1,a=0,o;for(;t--;){let s=e.codePointAt(t);if(s===47){if(o){r=t+1;break}continue}n<0&&(o=!0,n=t+1),s===46?i<0?i=t:a!==1&&(a=1):i>-1&&(a=-1)}return i<0||n<0||a===0||a===1&&i===n-1&&i===r+1?``:e.slice(i,n)}function PZe(...e){let t=-1,n;for(;++t0&&e.codePointAt(e.length-1)===47&&(n+=`/`),t?`/`+n:n}function IZe(e,t){let n=``,r=0,i=-1,a=0,o=-1,s,c;for(;++o<=e.length;){if(o2){if(c=n.lastIndexOf(`/`),c!==n.length-1){c<0?(n=``,r=0):(n=n.slice(0,c),r=n.length-1-n.lastIndexOf(`/`)),i=o,a=0;continue}}else if(n.length>0){n=``,r=0,i=o,a=0;continue}}t&&(n=n.length>0?n+`/..`:`..`,r=2)}else n.length>0?n+=`/`+e.slice(i+1,o):n=e.slice(i+1,o),r=o-i-1;i=o,a=0}else s===46&&a>-1?a++:a=-1}return n}function K7(e){if(typeof e!=`string`)throw TypeError(`Path must be a string. Received `+JSON.stringify(e))}var LZe={cwd:RZe};function RZe(){return`/`}function q7(e){return!!(typeof e==`object`&&e&&`href`in e&&e.href&&`protocol`in e&&e.protocol&&e.auth===void 0)}function zZe(e){if(typeof e==`string`)e=new URL(e);else if(!q7(e)){let t=TypeError('The "path" argument must be of type string or an instance of URL. Received `'+e+"`");throw t.code=`ERR_INVALID_ARG_TYPE`,t}if(e.protocol!==`file:`){let e=TypeError(`The URL must be of scheme file`);throw e.code=`ERR_INVALID_URL_SCHEME`,e}return BZe(e)}function BZe(e){if(e.hostname!==``){let e=TypeError(`File URL host must be "localhost" or empty on darwin`);throw e.code=`ERR_INVALID_FILE_URL_HOST`,e}let t=e.pathname,n=-1;for(;++n0){let[r,...a]=t,o=n[i][1];W7(o)&&W7(r)&&(r=(0,Z7.default)(!0,o,r)),n[i]=[e,r,...a]}}}}().freeze();function Q7(e,t){if(typeof t!=`function`)throw TypeError("Cannot `"+e+"` without `parser`")}function $7(e,t){if(typeof t!=`function`)throw TypeError("Cannot `"+e+"` without `compiler`")}function e9(e,t){if(t)throw Error("Cannot call `"+e+"` on a frozen processor.\nCreate a new processor first, by calling it: use `processor()` instead of `processor`.")}function qZe(e){if(!W7(e)||typeof e.type!=`string`)throw TypeError("Expected node, got `"+e+"`")}function JZe(e,t,n){if(!n)throw Error("`"+e+"` finished async. Use `"+t+"` instead")}function t9(e){return YZe(e)?e:new VZe(e)}function YZe(e){return!!(e&&typeof e==`object`&&`message`in e&&`messages`in e)}function XZe(e){return typeof e==`string`||ZZe(e)}function ZZe(e){return!!(e&&typeof e==`object`&&`byteLength`in e&&`byteOffset`in e)}var QZe=[],$Ze={allowDangerousHtml:!0},eQe=/^(https?|ircs?|mailto|xmpp)$/i,tQe=[{from:`astPlugins`,id:`remove-buggy-html-in-markdown-parser`},{from:`allowDangerousHtml`,id:`remove-buggy-html-in-markdown-parser`},{from:`allowNode`,id:`replace-allownode-allowedtypes-and-disallowedtypes`,to:`allowElement`},{from:`allowedTypes`,id:`replace-allownode-allowedtypes-and-disallowedtypes`,to:`allowedElements`},{from:`disallowedTypes`,id:`replace-allownode-allowedtypes-and-disallowedtypes`,to:`disallowedElements`},{from:`escapeHtml`,id:`remove-buggy-html-in-markdown-parser`},{from:`includeElementIndex`,id:`#remove-includeelementindex`},{from:`includeNodeIndex`,id:`change-includenodeindex-to-includeelementindex`},{from:`linkTarget`,id:`remove-linktarget`},{from:`plugins`,id:`change-plugins-to-remarkplugins`,to:`remarkPlugins`},{from:`rawSourcePos`,id:`#remove-rawsourcepos`},{from:`renderers`,id:`change-renderers-to-components`,to:`components`},{from:`source`,id:`change-source-to-children`,to:`children`},{from:`sourcePos`,id:`#remove-sourcepos`},{from:`transformImageUri`,id:`#add-urltransform`,to:`urlTransform`},{from:`transformLinkUri`,id:`#add-urltransform`,to:`urlTransform`}];function nQe(e){let t=rQe(e),n=iQe(e);return aQe(t.runSync(t.parse(n),n),e)}function rQe(e){let t=e.rehypePlugins||QZe,n=e.remarkPlugins||QZe,r=e.remarkRehypeOptions?{...e.remarkRehypeOptions,...$Ze}:$Ze;return KZe().use(vXe).use(n).use(EZe,r).use(t)}function iQe(e){let t=e.children||``,n=new VZe;return typeof t==`string`?n.value=t:``+t,n}function aQe(e,t){let n=t.allowedElements,r=t.allowElement,i=t.components,a=t.disallowedElements,o=t.skipHtml,s=t.unwrapDisallowed,c=t.urlTransform||oQe;for(let e of tQe)Object.hasOwn(t,e.from)&&``+e.from+(e.to?"use `"+e.to+"` instead":`remove it`)+e.id;return t.className&&(e={type:`element`,tagName:`div`,properties:{className:t.className},children:e.type===`root`?e.children:[e]}),_Ze(e,l),wqe(e,{Fragment:G.Fragment,components:i,ignoreInvalidStyle:!0,jsx:G.jsx,jsxs:G.jsxs,passKeys:!0,passNode:!0});function l(e,t,i){if(e.type===`raw`&&i&&typeof t==`number`)return o?i.children.splice(t,1):i.children[t]={type:`text`,value:e.value},t;if(e.type===`element`){let t;for(t in u7)if(Object.hasOwn(u7,t)&&Object.hasOwn(e.properties,t)){let n=e.properties[t],r=u7[t];(r===null||r.includes(e.tagName))&&(e.properties[t]=c(String(n||``),t,e))}}if(e.type===`element`){let o=n?!n.includes(e.tagName):a?a.includes(e.tagName):!1;if(!o&&r&&typeof t==`number`&&(o=!r(e,t,i)),o&&i&&typeof t==`number`)return s&&e.children?i.children.splice(t,1,...e.children):i.children.splice(t,1),t}}}function oQe(e){let t=e.indexOf(`:`),n=e.indexOf(`?`),r=e.indexOf(`#`),i=e.indexOf(`/`);return t===-1||i!==-1&&t>i||n!==-1&&t>n||r!==-1&&t>r||eQe.test(e.slice(0,t))?e:``}gQe.peek=hQe;function sQe(){this.buffer()}function cQe(e){this.enter({type:`footnoteReference`,identifier:``,label:``},e)}function lQe(){this.buffer()}function uQe(e){this.enter({type:`footnoteDefinition`,identifier:``,label:``,children:[]},e)}function dQe(e){let t=this.resume(),n=this.stack[this.stack.length-1];n.type,n.identifier=m7(this.sliceSerialize(e)).toLowerCase(),n.label=t}function fQe(e){this.exit(e)}function pQe(e){let t=this.resume(),n=this.stack[this.stack.length-1];n.type,n.identifier=m7(this.sliceSerialize(e)).toLowerCase(),n.label=t}function mQe(e){this.exit(e)}function hQe(){return`[`}function gQe(e,t,n,r){let i=n.createTracker(r),a=i.move(`[^`),o=n.enter(`footnoteReference`),s=n.enter(`reference`);return a+=i.move(n.safe(n.associationId(e),{after:`]`,before:a})),s(),o(),a+=i.move(`]`),a}function _Qe(){return{enter:{gfmFootnoteCallString:sQe,gfmFootnoteCall:cQe,gfmFootnoteDefinitionLabelString:lQe,gfmFootnoteDefinition:uQe},exit:{gfmFootnoteCallString:dQe,gfmFootnoteCall:fQe,gfmFootnoteDefinitionLabelString:pQe,gfmFootnoteDefinition:mQe}}}xQe.peek=SQe;function vQe(){return{canContainEols:[`delete`],enter:{strikethrough:yQe},exit:{strikethrough:bQe}}}function yQe(e){this.enter({type:`delete`,children:[]},e)}function bQe(e){this.exit(e)}function xQe(e,t,n,r){let i=n.createTracker(r),a=n.enter(`strikethrough`),o=i.move(`~~`);return o+=n.containerPhrasing(e,{...i.current(),before:o,after:`~`}),o+=i.move(`~~`),a(),o}function SQe(){return`~`}function CQe(){return{enter:{table:wQe,tableData:DQe,tableHeader:DQe,tableRow:EQe},exit:{codeText:OQe,table:TQe,tableData:n9,tableHeader:n9,tableRow:n9}}}function wQe(e){let t=e._align;this.enter({type:`table`,align:t.map(function(e){return e===`none`?null:e}),children:[]},e),this.data.inTable=!0}function TQe(e){this.exit(e),this.data.inTable=void 0}function EQe(e){this.enter({type:`tableRow`,children:[]},e)}function n9(e){this.exit(e)}function DQe(e){this.enter({type:`tableCell`,children:[]},e)}function OQe(e){let t=this.resume();this.data.inTable&&(t=t.replace(/\\([\\|])/g,kQe));let n=this.stack[this.stack.length-1];n.type,n.value=t,this.exit(e)}function kQe(e,t){return t===`|`?t:e}function AQe(){return{exit:{taskListCheckValueChecked:jQe,taskListCheckValueUnchecked:jQe,paragraph:MQe}}}function jQe(e){let t=this.stack[this.stack.length-2];t.type,t.checked=e.type===`taskListCheckValueChecked`}function MQe(e){let t=this.stack[this.stack.length-2];if(t&&t.type===`listItem`&&typeof t.checked==`boolean`){let e=this.stack[this.stack.length-1];e.type;let n=e.children[0];if(n&&n.type===`text`){let r=t.children,i=-1,a;for(;++i999||s===93&&!o||s===null||s===91||b7(s))return n(s);if(s===93){e.exit(`chunkString`);let a=e.exit(`gfmFootnoteCallString`);return i.includes(m7(r.sliceSerialize(a)))?(e.enter(`gfmFootnoteCallLabelMarker`),e.consume(s),e.exit(`gfmFootnoteCallLabelMarker`),e.exit(`gfmFootnoteCall`),t):n(s)}return b7(s)||(o=!0),a++,e.consume(s),s===92?u:l}function u(t){return t===91||t===92||t===93?(e.consume(t),a++,l):l(t)}}function RQe(e,t,n){let r=this,i=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]),a,o=0,s;return c;function c(t){return e.enter(`gfmFootnoteDefinition`)._container=!0,e.enter(`gfmFootnoteDefinitionLabel`),e.enter(`gfmFootnoteDefinitionLabelMarker`),e.consume(t),e.exit(`gfmFootnoteDefinitionLabelMarker`),l}function l(t){return t===94?(e.enter(`gfmFootnoteDefinitionMarker`),e.consume(t),e.exit(`gfmFootnoteDefinitionMarker`),e.enter(`gfmFootnoteDefinitionLabelString`),e.enter(`chunkString`).contentType=`string`,u):n(t)}function u(t){if(o>999||t===93&&!s||t===null||t===91||b7(t))return n(t);if(t===93){e.exit(`chunkString`);let n=e.exit(`gfmFootnoteDefinitionLabelString`);return a=m7(r.sliceSerialize(n)),e.enter(`gfmFootnoteDefinitionLabelMarker`),e.consume(t),e.exit(`gfmFootnoteDefinitionLabelMarker`),e.exit(`gfmFootnoteDefinitionLabel`),f}return b7(t)||(s=!0),o++,e.consume(t),t===92?d:u}function d(t){return t===91||t===92||t===93?(e.consume(t),o++,u):u(t)}function f(t){return t===58?(e.enter(`definitionMarker`),e.consume(t),e.exit(`definitionMarker`),i.includes(a)||i.push(a),w7(e,p,`gfmFootnoteDefinitionWhitespace`)):n(t)}function p(e){return t(e)}}function zQe(e,t,n){return e.check(O7,t,e.attempt(NQe,t,n))}function BQe(e){e.exit(`gfmFootnoteDefinition`)}function VQe(e,t,n){let r=this;return w7(e,i,`gfmFootnoteDefinitionIndent`,5);function i(e){let i=r.events[r.events.length-1];return i&&i[1].type===`gfmFootnoteDefinitionIndent`&&i[2].sliceSerialize(i[1],!0).length===4?t(e):n(e)}}function HQe(e){let t=(e||{}).singleTilde,n={name:`strikethrough`,tokenize:i,resolveAll:r};return t??=!0,{text:{126:n},insideSpan:{null:[n]},attentionMarkers:{null:[126]}};function r(e,t){let n=-1;for(;++n1?r(a):(e.consume(a),o++,c);if(o<2&&!t)return r(a);let l=e.exit(`strikethroughSequenceTemporary`),u=T7(a);return l._open=!u||u===2&&!!s,l._close=!s||s===2&&!!u,n(a)}}}var UQe=class{constructor(){this.map=[]}add(e,t,n){WQe(this,e,t,n)}consume(e){if(this.map.sort(function(e,t){return e[0]-t[0]}),this.map.length===0)return;let t=this.map.length,n=[];for(;t>0;)--t,n.push(e.slice(this.map[t][0]+this.map[t][1]),this.map[t][2]),e.length=this.map[t][0];n.push(e.slice()),e.length=0;let r=n.pop();for(;r;){for(let t of r)e.push(t);r=n.pop()}this.map.length=0}};function WQe(e,t,n,r){let i=0;if(!(n===0&&r.length===0)){for(;i-1;){let e=r.events[t][1].type;if(e===`lineEnding`||e===`linePrefix`)t--;else break}let i=t>-1?r.events[t][1].type:null,a=i===`tableHead`||i===`tableRow`?S:c;return a===S&&r.parser.lazy[r.now().line]?n(e):a(e)}function c(t){return e.enter(`tableHead`),e.enter(`tableRow`),l(t)}function l(e){return e===124?u(e):(o=!0,a+=1,u(e))}function u(t){return t===null?n(t):y7(t)?a>1?(a=0,r.interrupt=!0,e.exit(`tableRow`),e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),p):n(t):x7(t)?w7(e,u,`whitespace`)(t):(a+=1,o&&(o=!1,i+=1),t===124?(e.enter(`tableCellDivider`),e.consume(t),e.exit(`tableCellDivider`),o=!0,u):(e.enter(`data`),d(t)))}function d(t){return t===null||t===124||b7(t)?(e.exit(`data`),u(t)):(e.consume(t),t===92?f:d)}function f(t){return t===92||t===124?(e.consume(t),d):d(t)}function p(t){return r.interrupt=!1,r.parser.lazy[r.now().line]?n(t):(e.enter(`tableDelimiterRow`),o=!1,x7(t)?w7(e,m,`linePrefix`,r.parser.constructs.disable.null.includes(`codeIndented`)?void 0:4)(t):m(t))}function m(t){return t===45||t===58?g(t):t===124?(o=!0,e.enter(`tableCellDivider`),e.consume(t),e.exit(`tableCellDivider`),h):x(t)}function h(t){return x7(t)?w7(e,g,`whitespace`)(t):g(t)}function g(t){return t===58?(a+=1,o=!0,e.enter(`tableDelimiterMarker`),e.consume(t),e.exit(`tableDelimiterMarker`),_):t===45?(a+=1,_(t)):t===null||y7(t)?b(t):x(t)}function _(t){return t===45?(e.enter(`tableDelimiterFiller`),v(t)):x(t)}function v(t){return t===45?(e.consume(t),v):t===58?(o=!0,e.exit(`tableDelimiterFiller`),e.enter(`tableDelimiterMarker`),e.consume(t),e.exit(`tableDelimiterMarker`),y):(e.exit(`tableDelimiterFiller`),y(t))}function y(t){return x7(t)?w7(e,b,`whitespace`)(t):b(t)}function b(n){return n===124?m(n):n===null||y7(n)?!o||i!==a?x(n):(e.exit(`tableDelimiterRow`),e.exit(`tableHead`),t(n)):x(n)}function x(e){return n(e)}function S(t){return e.enter(`tableRow`),C(t)}function C(n){return n===124?(e.enter(`tableCellDivider`),e.consume(n),e.exit(`tableCellDivider`),C):n===null||y7(n)?(e.exit(`tableRow`),t(n)):x7(n)?w7(e,C,`whitespace`)(n):(e.enter(`data`),w(n))}function w(t){return t===null||t===124||b7(t)?(e.exit(`data`),C(t)):(e.consume(t),t===92?T:w)}function T(t){return t===92||t===124?(e.consume(t),w):w(t)}}function JQe(e,t){let n=-1,r=!0,i=0,a=[0,0,0,0],o=[0,0,0,0],s=!1,c=0,l,u,d,f=new UQe;for(;++nn[2]+1){let t=n[2]+1,r=n[3]-n[2]-1;e.add(t,r,[])}}e.add(n[3]+1,0,[[`exit`,o,t]])}return i!==void 0&&(a.end=Object.assign({},i9(t.events,i)),e.add(i,0,[[`exit`,a,t]]),a=void 0),a}function YQe(e,t,n,r,i){let a=[],o=i9(t.events,n);i&&(i.end=Object.assign({},o),a.push([`exit`,i,t])),r.end=Object.assign({},o),a.push([`exit`,r,t]),e.add(n+1,0,a)}function i9(e,t){let n=e[t],r=n[0]===`enter`?`start`:`end`;return n[1][r]}var XQe={name:`tasklistCheck`,tokenize:QQe};function ZQe(){return{text:{91:XQe}}}function QQe(e,t,n){let r=this;return i;function i(t){return r.previous!==null||!r._gfmTasklistFirstContentOfListItem?n(t):(e.enter(`taskListCheck`),e.enter(`taskListCheckMarker`),e.consume(t),e.exit(`taskListCheckMarker`),a)}function a(t){return b7(t)?(e.enter(`taskListCheckValueUnchecked`),e.consume(t),e.exit(`taskListCheckValueUnchecked`),o):t===88||t===120?(e.enter(`taskListCheckValueChecked`),e.consume(t),e.exit(`taskListCheckValueChecked`),o):n(t)}function o(t){return t===93?(e.enter(`taskListCheckMarker`),e.consume(t),e.exit(`taskListCheckMarker`),e.exit(`taskListCheck`),s):n(t)}function s(r){return y7(r)?t(r):x7(r)?e.check({tokenize:$Qe},t,n)(r):n(r)}}function $Qe(e,t,n){return w7(e,r,`whitespace`);function r(e){return e===null?n(e):t(e)}}function e$e(){let e=this.data(),t=e.micromarkExtensions||=[],n=e.fromMarkdownExtensions||=[];t.push(PQe(),HQe(),KQe(),ZQe()),n.push(_Qe(),vQe(),CQe(),AQe())}var t$e=`fileManager.readmeCollapsed`;function n$e({folderId:e}){let{t}=U(),[n,r]=(0,y.useState)(()=>localStorage.getItem(t$e)===`1`);(0,y.useEffect)(()=>{localStorage.setItem(t$e,n?`1`:`0`)},[n]);let{data:i,isLoading:a,error:o}=K({queryKey:[`folder-readme`,e],queryFn:()=>Z.getLibraryFolderReadme(e),retry:!1,staleTime:3e4});return a||o||!i?null:n?(0,G.jsxs)(`div`,{className:`mb-2 lg:mb-0 order-first lg:order-none lg:w-10 lg:flex-shrink-0 lg:h-full`,children:[(0,G.jsxs)(`button`,{type:`button`,onClick:()=>r(!1),title:t(`fileManager.readme.show`),"aria-label":t(`fileManager.readme.show`),className:`flex lg:hidden w-full items-center gap-2 px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg hover:bg-bambu-dark/40 transition-colors`,children:[(0,G.jsx)(fc,{className:`w-4 h-4 text-bambu-green flex-shrink-0`}),(0,G.jsx)(`span`,{className:`text-sm font-medium text-white truncate`,children:i.filename}),(0,G.jsx)(El,{className:`w-4 h-4 text-bambu-gray flex-shrink-0 ml-auto`})]}),(0,G.jsxs)(`button`,{type:`button`,onClick:()=>r(!1),title:t(`fileManager.readme.show`),"aria-label":t(`fileManager.readme.show`),className:`hidden lg:flex h-full w-10 flex-col items-center gap-2 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg hover:bg-bambu-dark/40 transition-colors`,children:[(0,G.jsx)(El,{className:`w-4 h-4 text-bambu-green flex-shrink-0`}),(0,G.jsx)(`span`,{className:`text-xs font-medium text-bambu-gray [writing-mode:vertical-rl] rotate-180 select-none`,children:t(`fileManager.readme.label`)})]})]}):(0,G.jsxs)(`div`,{className:`mb-4 lg:mb-0 order-first lg:order-none lg:w-80 xl:w-96 lg:flex-shrink-0 lg:h-full flex flex-col bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg overflow-hidden`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-2 px-3 py-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,G.jsx)(fc,{className:`w-4 h-4 text-bambu-green flex-shrink-0`}),(0,G.jsx)(`span`,{className:`text-sm font-medium text-white truncate`,title:i.filename,children:i.filename}),i.truncated&&(0,G.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-400 flex-shrink-0`,children:t(`fileManager.readme.truncated`)})]}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>r(!0),title:t(`fileManager.readme.hide`),"aria-label":t(`fileManager.readme.hide`),className:`p-1 rounded text-bambu-gray hover:text-white hover:bg-bambu-dark/40 transition-colors flex-shrink-0`,children:(0,G.jsx)(Tl,{className:`w-4 h-4`})})]}),(0,G.jsx)(`div`,{className:`px-4 py-3 border-t border-bambu-dark-tertiary flex-1 overflow-y-auto max-h-96 lg:max-h-none text-sm text-bambu-gray-light leading-relaxed space-y-2`,children:(0,G.jsx)(nQe,{remarkPlugins:[e$e],components:{h1:({children:e})=>(0,G.jsx)(`h1`,{className:`text-lg font-semibold text-white mt-2 mb-1`,children:e}),h2:({children:e})=>(0,G.jsx)(`h2`,{className:`text-base font-semibold text-white mt-2 mb-1`,children:e}),h3:({children:e})=>(0,G.jsx)(`h3`,{className:`text-sm font-semibold text-white mt-2 mb-1`,children:e}),p:({children:e})=>(0,G.jsx)(`p`,{className:`my-1`,children:e}),ul:({children:e})=>(0,G.jsx)(`ul`,{className:`list-disc list-inside space-y-0.5 ml-2`,children:e}),ol:({children:e})=>(0,G.jsx)(`ol`,{className:`list-decimal list-inside space-y-0.5 ml-2`,children:e}),li:({children:e})=>(0,G.jsx)(`li`,{children:e}),code:({children:e,...t})=>t.className?(0,G.jsx)(`code`,{className:`block p-2 bg-bambu-dark rounded text-xs font-mono text-bambu-gray-light overflow-x-auto`,children:e}):(0,G.jsx)(`code`,{className:`px-1 py-0.5 bg-bambu-dark rounded text-xs font-mono text-bambu-green`,children:e}),pre:({children:e})=>(0,G.jsx)(`pre`,{className:`my-2`,children:e}),blockquote:({children:e})=>(0,G.jsx)(`blockquote`,{className:`border-l-2 border-bambu-dark-tertiary pl-3 text-bambu-gray italic`,children:e}),a:({children:e,href:t})=>(0,G.jsx)(`a`,{href:t,target:`_blank`,rel:`noopener noreferrer`,className:`text-bambu-green hover:underline`,children:e}),table:({children:e})=>(0,G.jsx)(`div`,{className:`overflow-x-auto`,children:(0,G.jsx)(`table`,{className:`min-w-full text-xs border-collapse`,children:e})}),th:({children:e})=>(0,G.jsx)(`th`,{className:`border border-bambu-dark-tertiary px-2 py-1 text-left font-semibold text-white`,children:e}),td:({children:e})=>(0,G.jsx)(`td`,{className:`border border-bambu-dark-tertiary px-2 py-1`,children:e}),hr:()=>(0,G.jsx)(`hr`,{className:`border-bambu-dark-tertiary my-2`})},children:i.content})})]})}function r$e({open:e,onClose:t,onPickTag:n}){let{t:r}=U(),i=co(),{showToast:a}=qd(),[o,s]=(0,y.useState)(!1),[c,l]=(0,y.useState)(null),[u,d]=(0,y.useState)(``),[f,p]=(0,y.useState)(null),{data:m=[],isLoading:h}=K({queryKey:R5,queryFn:Z.getLibraryTags,enabled:e}),g=()=>{i.invalidateQueries({queryKey:R5}),i.invalidateQueries({queryKey:[`library-files`]})},_=q({mutationFn:async()=>{let e=u.trim();if(!e)throw Error(r(`fileManager.tags.nameRequired`));return c?Z.updateLibraryTag(c.id,e):Z.createLibraryTag(e)},onSuccess:()=>{a(r(c?`fileManager.tags.updated`:`fileManager.tags.created`),`success`),s(!1),l(null),d(``),g()},onError:e=>{a(e.message||r(`fileManager.tags.saveFailed`),`error`)}}),v=q({mutationFn:e=>Z.deleteLibraryTag(e),onSuccess:()=>{a(r(`fileManager.tags.deleted`),`success`),p(null),g()},onError:e=>{a(e.message||r(`fileManager.tags.deleteFailed`),`error`)}}),b=()=>{l(null),d(``),s(!0)},x=e=>{l(e),d(e.name),s(!0)},S=(0,y.useCallback)(()=>{_.isPending||(s(!1),l(null),d(``))},[_.isPending]);(0,y.useEffect)(()=>{if(!e)return;let n=e=>{e.key===`Escape`&&(_.isPending||v.isPending||(o?S():f||t()))};return document.addEventListener(`keydown`,n),()=>document.removeEventListener(`keydown`,n)},[e,o,f,_.isPending,v.isPending,S,t]);let C=e=>{e.preventDefault(),_.mutate()};if(!e)return null;let w=`library-tags-modal-title`,T=`library-tag-editor-title`;return(0,G.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[(0,G.jsx)(`div`,{className:`absolute inset-0 bg-black/60`,onClick:()=>{_.isPending||v.isPending||t()}}),(0,G.jsxs)(`div`,{className:`relative w-full max-w-4xl mx-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl shadow-2xl max-h-[90vh] flex flex-col`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":w,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-4 px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,G.jsxs)(`h2`,{id:w,className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(Eu,{className:`w-5 h-5 text-bambu-green`}),r(`fileManager.tags.title`)]}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-sm mt-0.5`,children:r(`fileManager.tags.subtitle`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(Q,{onClick:b,children:[(0,G.jsx)(Fl,{className:`w-4 h-4`}),r(`fileManager.tags.add`)]}),(0,G.jsx)(`button`,{type:`button`,className:`p-1.5 text-bambu-gray hover:text-white rounded`,onClick:t,"aria-label":r(`common.close`),children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]})]}),(0,G.jsx)(`div`,{className:`overflow-y-auto`,children:h?(0,G.jsxs)(`div`,{className:`flex items-center justify-center py-16 text-bambu-gray`,children:[(0,G.jsx)(Y,{className:`w-6 h-6 animate-spin mr-2`}),r(`common.loading`)]}):m.length===0?(0,G.jsx)(`div`,{className:`py-16 text-center text-bambu-gray`,children:r(`fileManager.tags.empty`)}):(0,G.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,G.jsx)(`thead`,{children:(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary text-left text-bambu-gray`,children:[(0,G.jsx)(`th`,{className:`px-4 py-3 font-medium`,children:r(`fileManager.tags.name`)}),(0,G.jsx)(`th`,{className:`px-4 py-3 font-medium text-right`,children:r(`fileManager.tags.fileCount`)}),(0,G.jsx)(`th`,{className:`px-4 py-3 font-medium text-right w-32`,children:r(`common.actions`)})]})}),(0,G.jsx)(`tbody`,{children:m.map(e=>(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/60 hover:bg-bambu-dark-tertiary/30 ${n?`cursor-pointer`:``}`,onClick:()=>{n&&(n(e.id),t())},children:[(0,G.jsx)(`td`,{className:`px-4 py-3 text-white font-medium`,children:e.name}),(0,G.jsx)(`td`,{className:`px-4 py-3 text-right text-bambu-gray`,children:e.file_count}),(0,G.jsx)(`td`,{className:`px-4 py-3 text-right`,onClick:e=>e.stopPropagation(),children:(0,G.jsxs)(`div`,{className:`flex items-center justify-end gap-1`,children:[(0,G.jsx)(`button`,{type:`button`,className:`p-1.5 text-bambu-gray hover:text-bambu-green rounded`,onClick:()=>x(e),title:r(`common.edit`),"aria-label":r(`fileManager.tags.editAria`,{name:e.name}),children:(0,G.jsx)(Al,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{type:`button`,className:`p-1.5 text-bambu-gray hover:text-red-600 dark:hover:text-red-400 rounded`,onClick:()=>p(e),title:r(`common.delete`),"aria-label":r(`fileManager.tags.deleteAria`,{name:e.name}),children:(0,G.jsx)(Pu,{className:`w-4 h-4`})})]})})]},e.id))})]})})]}),o&&(0,G.jsxs)(`div`,{className:`fixed inset-0 z-[60] flex items-center justify-center`,children:[(0,G.jsx)(`div`,{className:`absolute inset-0 bg-black/60`,onClick:S}),(0,G.jsxs)(`div`,{className:`relative w-full max-w-md mx-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl p-6 shadow-2xl`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":T,children:[(0,G.jsx)(`h3`,{id:T,className:`text-lg font-semibold text-white mb-4`,children:r(c?`fileManager.tags.edit`:`fileManager.tags.add`)}),(0,G.jsxs)(`form`,{onSubmit:C,children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,htmlFor:`library-tag-name`,children:r(`fileManager.tags.name`)}),(0,G.jsx)(`input`,{id:`library-tag-name`,type:`text`,maxLength:64,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green mb-4`,placeholder:r(`fileManager.tags.createPlaceholder`),value:u,onChange:e=>d(e.target.value),autoFocus:!0}),(0,G.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:S,children:r(`common.cancel`)}),(0,G.jsxs)(Q,{type:`submit`,disabled:_.isPending||!u.trim(),children:[_.isPending&&(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),r(`common.save`)]})]})]})]})]}),f&&(0,G.jsx)(of,{title:r(`fileManager.tags.confirmDelete`,{name:f.name}),message:f.file_count>0?r(`fileManager.tags.confirmDeleteInUseMessage`,{count:f.file_count}):r(`fileManager.tags.confirmDeleteMessage`),confirmText:r(`common.delete`),variant:`danger`,isLoading:v.isPending,onConfirm:()=>v.mutate(f.id),onCancel:()=>p(null)})]})}var i$e=90;function a$e({onClose:e}){let{t}=U(),n=co(),{showToast:r}=qd(),[i,a]=(0,y.useState)(i$e),[o,s]=(0,y.useState)(!0),[c,l]=(0,y.useState)(i);(0,y.useEffect)(()=>{let e=window.setTimeout(()=>l(i),300);return()=>window.clearTimeout(e)},[i]);let u=K({queryKey:[`library-purge-preview`,c,o],queryFn:()=>Z.previewLibraryPurge(c,o),enabled:c>=1}),d=q({mutationFn:()=>Z.executeLibraryPurge(i,o),onSuccess:i=>{r(t(`libraryPurge.toast.success`,{count:i.moved_to_trash}),`success`),n.invalidateQueries({queryKey:[`library-files`]}),n.invalidateQueries({queryKey:[`library-folders`]}),n.invalidateQueries({queryKey:[`library-trash`]}),n.invalidateQueries({queryKey:[`library-trash-count`]}),e()},onError:e=>r(e.message||t(`libraryPurge.toast.failed`),`error`)});(0,y.useEffect)(()=>{let t=t=>{t.key===`Escape`&&!d.isPending&&e()};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e,d.isPending]);let f=u.data,p=f?.count??0,m=f?.total_bytes??0,h=p>0&&!d.isPending;return(0,G.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4`,children:(0,G.jsxs)(`div`,{className:`bg-white dark:bg-gray-900 rounded-lg shadow-xl max-w-lg w-full`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-gray-200 dark:border-gray-700`,children:[(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-gray-900 dark:text-gray-100 flex items-center gap-2`,children:[(0,G.jsx)(Pu,{className:`w-5 h-5`}),t(`libraryPurge.title`)]}),(0,G.jsx)(`button`,{onClick:e,className:`text-gray-400 hover:text-gray-600 dark:hover:text-gray-200`,"aria-label":t(`common.close`),disabled:d.isPending,children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]}),(0,G.jsxs)(`div`,{className:`p-4 space-y-4`,children:[(0,G.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400`,children:t(`libraryPurge.description`)}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{htmlFor:`purge-days`,className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:t(`libraryPurge.ageLabel`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`input`,{id:`purge-days`,type:`number`,min:1,max:3650,value:i,onChange:e=>a(Math.max(1,Math.min(3650,parseInt(e.target.value||`0`,10)||0))),className:`w-24 rounded border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-800 text-sm px-2 py-1 text-gray-900 dark:text-gray-100`}),(0,G.jsx)(`span`,{className:`text-sm text-gray-600 dark:text-gray-400`,children:t(`libraryPurge.days`)})]})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-gray-700 dark:text-gray-300`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:o,onChange:e=>s(e.target.checked),className:`rounded border-gray-300`}),t(`libraryPurge.includeNeverPrinted`)]}),(0,G.jsxs)(`div`,{className:`rounded border border-gray-200 dark:border-gray-700 bg-gray-50 dark:bg-gray-800/30 p-3`,children:[(0,G.jsx)(`div`,{className:`text-xs font-semibold uppercase tracking-wide text-gray-600 dark:text-gray-300 mb-2`,children:t(`libraryPurge.effectsTitle`)}),(0,G.jsxs)(`ul`,{className:`text-xs text-gray-700 dark:text-gray-300 space-y-1 list-disc pl-4`,children:[(0,G.jsx)(`li`,{children:t(`libraryPurge.effect1`)}),(0,G.jsx)(`li`,{children:t(`libraryPurge.effect2`)}),(0,G.jsx)(`li`,{children:t(`libraryPurge.effect3`)}),(0,G.jsx)(`li`,{children:t(`libraryPurge.effect4`)})]})]}),(0,G.jsx)(`div`,{className:`rounded border border-gray-200 dark:border-gray-700 bg-gray-50 dark:bg-gray-800/50 p-3`,children:u.isLoading||u.isFetching?(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-gray-500 dark:text-gray-400`,children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),` `,t(`libraryPurge.previewLoading`)]}):u.isError?(0,G.jsx)(`div`,{className:`text-sm text-red-600 dark:text-red-400`,children:u.error?.message??t(`libraryPurge.previewFailed`)}):(0,G.jsxs)(`div`,{className:`text-sm text-gray-900 dark:text-gray-100`,children:[(0,G.jsx)(`div`,{className:`font-medium`,children:t(`libraryPurge.previewSummary`,{count:p,size:Gd(m)})}),f?.sample_filenames&&f.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:[f.sample_filenames.map(e=>(0,G.jsx)(`li`,{className:`truncate`,children:e},e)),p>f.sample_filenames.length&&(0,G.jsx)(`li`,{className:`list-none italic text-gray-500`,children:t(`libraryPurge.andMore`,{count:p-f.sample_filenames.length})})]})]})}),(0,G.jsxs)(`div`,{className:`flex gap-2 items-start text-xs text-amber-700 dark:text-amber-400 bg-amber-50 dark:bg-amber-900/20 rounded px-3 py-2`,children:[(0,G.jsx)(Lu,{className:`w-4 h-4 mt-0.5 shrink-0`}),(0,G.jsx)(`span`,{children:t(`libraryPurge.warning`)})]})]}),(0,G.jsxs)(`div`,{className:`flex justify-end gap-2 p-4 border-t border-gray-200 dark:border-gray-700`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:e,disabled:d.isPending,children:t(`common.cancel`)}),(0,G.jsx)(Q,{variant:`danger`,disabled:!h,onClick:()=>d.mutate(),children:d.isPending?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin mr-1`}),t(`libraryPurge.purging`)]}):t(`libraryPurge.confirmCta`,{count:p})})]})]})})}function o$e({parentId:e,onClose:t,onSave:n,isLoading:r,t:i}){let[a,o]=(0,y.useState)(``);return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg w-full max-w-sm border border-bambu-dark-tertiary`,children:[(0,G.jsx)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary`,children:(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(`fileManager.newFolder`)})}),(0,G.jsxs)(`form`,{onSubmit:t=>{t.preventDefault(),n({name:a.trim(),parent_id:e})},className:`p-4 space-y-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:i(`fileManager.folderName`)}),(0,G.jsx)(`input`,{type:`text`,value:a,onChange:e=>o(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:i(`fileManager.folderNamePlaceholder`),autoFocus:!0,required:!0})]}),(0,G.jsxs)(`div`,{className:`flex justify-end gap-2 pt-2`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:t,children:i(`common.cancel`)}),(0,G.jsx)(Q,{type:`submit`,disabled:!a.trim()||r,children:r?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):i(`common.create`)})]})]})]})})}function s$e({onClose:e,onSave:t,isLoading:n,t:r}){let[i,a]=(0,y.useState)(``),[o,s]=(0,y.useState)(``),[c,l]=(0,y.useState)(!0),[u,d]=(0,y.useState)(!1);return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg w-full max-w-md border border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(bc,{className:`w-5 h-5 text-bambu-green`}),r(`fileManager.linkExternalFolder`)]}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:r(`fileManager.linkExternalFolderDescription`)})]}),(0,G.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),t({name:i.trim(),external_path:o.trim(),readonly:c,show_hidden:u})},className:`p-4 space-y-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:r(`fileManager.folderName`)}),(0,G.jsx)(`input`,{type:`text`,value:i,onChange:e=>a(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:r(`fileManager.externalFolderNamePlaceholder`),autoFocus:!0,required:!0})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:r(`fileManager.externalPath`)}),(0,G.jsx)(`input`,{type:`text`,value:o,onChange:e=>s(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green font-mono text-sm`,placeholder:`/mnt/nas/3d-prints`,required:!0}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:r(`fileManager.externalPathHelp`)})]}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:c,onChange:e=>l(e.target.checked),className:`rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,G.jsx)(`span`,{className:`text-sm text-white`,children:r(`fileManager.readOnly`)}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[`(`,r(`fileManager.readOnlyHelp`),`)`]})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:u,onChange:e=>d(e.target.checked),className:`rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,G.jsx)(`span`,{className:`text-sm text-white`,children:r(`fileManager.showHiddenFiles`)})]})]}),(0,G.jsxs)(`div`,{className:`flex justify-end gap-2 pt-2`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:e,children:r(`common.cancel`)}),(0,G.jsx)(Q,{type:`submit`,disabled:!i.trim()||!o.trim()||n,children:n?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):r(`fileManager.linkFolder`)})]})]})]})})}var c$e=`<>:"/\\|?*`;function l$e(e){for(let t of e)if(c$e.includes(t)||t.charCodeAt(0)<32)return t;return null}function u$e({type:e,currentName:t,onClose:n,onSave:r,isLoading:i,t:a}){let o=e===`file`?t.match(/(\.gcode\.3mf|\.3mf|\.gcode)$/i)?.[1]??``:``,s=e===`file`&&o?t.slice(0,-o.length):t,[c,l]=(0,y.useState)(s),u=e===`file`?l$e(c):null,d=u?a(`fileManager.invalidFilenameChar`,{char:u}):null;return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg w-full max-w-sm border border-bambu-dark-tertiary`,children:[(0,G.jsx)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary`,children:(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:a(e===`file`?`fileManager.renameFile`:`fileManager.renameFolder`)})}),(0,G.jsxs)(`form`,{onSubmit:n=>{if(n.preventDefault(),d)return;let i=e===`file`?c.trim()+o:c.trim();c.trim()&&i!==t&&r(i)},className:`p-4 space-y-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`common.name`)}),(0,G.jsxs)(`div`,{className:`flex items-center bg-bambu-dark border rounded focus-within:border-bambu-green ${d?`border-red-500`:`border-bambu-dark-tertiary`}`,children:[(0,G.jsx)(`input`,{type:`text`,value:c,onChange:e=>l(e.target.value),className:`flex-1 bg-transparent px-3 py-2 text-white placeholder-bambu-gray focus:outline-none min-w-0`,autoFocus:!0,required:!0}),o&&(0,G.jsx)(`span`,{className:`pr-3 text-bambu-gray text-sm select-none whitespace-nowrap`,children:o})]}),d&&(0,G.jsx)(`p`,{className:`mt-1 text-xs text-red-700 dark:text-red-400`,children:d})]}),(0,G.jsxs)(`div`,{className:`flex justify-end gap-2 pt-2`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:n,children:a(`common.cancel`)}),(0,G.jsx)(Q,{type:`submit`,disabled:!c.trim()||c.trim()===s||!!d||i,children:i?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):a(`common.rename`)})]})]})]})})}function d$e({folders:e,selectedFiles:t,currentFolderId:n,onClose:r,onMove:i,isLoading:a,t:o}){let[s,c]=(0,y.useState)(null),l=(e,t=0)=>{let n=[];for(let r of e)n.push({id:r.id,name:r.name,depth:t}),r.children.length>0&&n.push(...l(r.children,t+1));return n},u=[{id:null,name:o(`fileManager.rootNoFolder`),depth:0},...l(e)];return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg w-full max-w-sm border border-bambu-dark-tertiary`,children:[(0,G.jsx)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary`,children:(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:o(`fileManager.moveFiles`,{count:t.length})})}),(0,G.jsxs)(`div`,{className:`p-4 space-y-4`,children:[(0,G.jsx)(`div`,{className:`max-h-64 overflow-y-auto space-y-1`,children:u.map(e=>(0,G.jsxs)(`button`,{onClick:()=>c(e.id),disabled:e.id===n,className:`w-full text-left px-3 py-2 rounded transition-colors flex items-center gap-2 ${s===e.id?`bg-bambu-green/20 text-bambu-green`:e.id===n?`opacity-50 cursor-not-allowed text-bambu-gray`:`hover:bg-bambu-dark text-white`}`,style:{paddingLeft:`${12+e.depth*16}px`},children:[(0,G.jsx)(vc,{className:`w-4 h-4`}),e.name,e.id===n&&(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray ml-auto`,children:[`(`,o(`fileManager.current`),`)`]})]},e.id??`root`))}),(0,G.jsxs)(`div`,{className:`flex justify-end gap-2 pt-2`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:r,children:o(`common.cancel`)}),(0,G.jsx)(Q,{onClick:()=>i(s),disabled:a,children:a?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):o(`common.move`)})]})]})]})})}function f$e({folder:e,onClose:t,onLink:n,isLoading:r,t:i}){let[a,o]=(0,y.useState)(`project`),[s,c]=(0,y.useState)(e.project_id||e.archive_id||null);(0,y.useState)(()=>{e.archive_id&&o(`archive`)});let{data:l}=K({queryKey:[`projects`],queryFn:()=>Z.getProjects(),select:t=>JW([...t].sort((e,t)=>e.name.localeCompare(t.name)),e.project_id)}),{data:u}=K({queryKey:[`archives-for-link`],queryFn:()=>Z.getArchives(void 0,void 0,100)}),d=()=>{n(a===`project`?{project_id:s,archive_id:0}:{project_id:0,archive_id:s})},f=()=>{n({project_id:0,archive_id:0})},p=e.project_id||e.archive_id;return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg w-full max-w-md border border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary flex items-center justify-between`,children:[(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(Xc,{className:`w-5 h-5 text-bambu-green`}),i(`fileManager.linkFolder`)]}),(0,G.jsx)(`button`,{onClick:t,className:`p-1 hover:bg-bambu-dark rounded`,children:(0,G.jsx)(nd,{className:`w-5 h-5 text-bambu-gray`})})]}),(0,G.jsxs)(`div`,{className:`p-4 space-y-4`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`fileManager.linkFolderDescription`,{name:e.name})}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsxs)(`button`,{onClick:()=>{o(`project`),c(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg border transition-colors ${a===`project`?`border-bambu-green bg-bambu-green/10 text-bambu-green`:`border-bambu-dark-tertiary text-bambu-gray hover:text-white`}`,children:[(0,G.jsx)(Qo,{className:`w-4 h-4`}),i(`fileManager.project`)]}),(0,G.jsxs)(`button`,{onClick:()=>{o(`archive`),c(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg border transition-colors ${a===`archive`?`border-bambu-green bg-bambu-green/10 text-bambu-green`:`border-bambu-dark-tertiary text-bambu-gray hover:text-white`}`,children:[(0,G.jsx)(Po,{className:`w-4 h-4`}),i(`fileManager.archive`)]})]}),(0,G.jsx)(`div`,{className:`max-h-64 overflow-y-auto space-y-1 bg-bambu-dark rounded-lg p-2`,children:a===`project`?l&&l.length>0?l.map(e=>(0,G.jsxs)(`button`,{onClick:()=>c(e.id),className:`w-full text-left px-3 py-2 rounded transition-colors flex items-center gap-2 ${s===e.id?`bg-bambu-green/20 text-bambu-green`:`hover:bg-bambu-dark-tertiary text-white`}`,children:[(0,G.jsx)(`div`,{className:`w-3 h-3 rounded-full flex-shrink-0`,style:{backgroundColor:e.color||`#00ae42`}}),(0,G.jsx)(`span`,{className:`truncate`,children:e.name})]},e.id)):(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray text-center py-4`,children:i(`fileManager.noProjectsFound`)}):u&&u.length>0?u.map(e=>(0,G.jsxs)(`button`,{onClick:()=>c(e.id),className:`w-full text-left px-3 py-2 rounded transition-colors flex items-center gap-2 ${s===e.id?`bg-bambu-green/20 text-bambu-green`:`hover:bg-bambu-dark-tertiary text-white`}`,children:[(0,G.jsx)(sc,{className:`w-4 h-4 text-bambu-gray flex-shrink-0`}),(0,G.jsx)(`span`,{className:`truncate`,children:e.print_name||e.filename})]},e.id)):(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray text-center py-4`,children:i(`fileManager.noArchivesFound`)})})]}),(0,G.jsxs)(`div`,{className:`p-4 border-t border-bambu-dark-tertiary flex justify-between`,children:[p&&(0,G.jsxs)(Q,{variant:`danger`,onClick:f,disabled:r,children:[(0,G.jsx)(Bu,{className:`w-4 h-4 mr-2`}),i(`fileManager.unlink`)]}),(0,G.jsxs)(`div`,{className:`flex gap-2 ${p?``:`ml-auto`}`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:t,children:i(`common.cancel`)}),(0,G.jsx)(Q,{onClick:d,disabled:!s||r,children:r?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):i(`fileManager.link`)})]})]})]})})}function p$e({folder:e,selectedFolderId:t,onSelect:n,onDelete:r,onLink:i,onRename:a,depth:o=0,wrapNames:s=!1,defaultExpanded:c=!0,showModified:l=!1,hasPermission:u,t:d}){let[f,p]=(0,y.useState)(c),[m,h]=(0,y.useState)(!1),g=e.children.length>0,_=e.project_id||e.archive_id,v=e.is_external,b=u(`library:delete_all`)||u(`library:delete_own`)&&e.file_count===0&&!g&&!v&&!_,x=b?void 0:u(`library:delete_own`)&&!v&&!_?d(`fileManager.onlyEmptyFoldersDeletable`):d(`fileManager.noPermissionDeleteFolder`);return(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`group flex items-center gap-1 px-2 py-1.5 rounded cursor-pointer transition-colors ${t===e.id?`bg-bambu-green/20 text-bambu-green`:`hover:bg-bambu-dark text-white`}`,style:{paddingLeft:`${8+o*12}px`},onClick:()=>n(e.id),children:[g?(0,G.jsx)(`button`,{onClick:e=>{e.stopPropagation(),p(!f)},className:`p-0.5 hover:bg-bambu-dark-tertiary rounded`,children:(0,G.jsx)(ms,{className:`w-3.5 h-3.5 transition-transform ${f?`rotate-90`:``}`})}):(0,G.jsx)(`div`,{className:`w-4.5`}),v?(0,G.jsx)(bc,{className:`w-4 h-4 text-purple-600 dark:text-purple-400 flex-shrink-0`}):(0,G.jsx)(vc,{className:`w-4 h-4 text-bambu-green flex-shrink-0`}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`span`,{className:`block text-sm ${s?`break-all`:`truncate`}`,title:e.name,children:e.name}),l&&e.latest_activity_at&&(0,G.jsxs)(`span`,{className:`mt-0.5 flex items-center gap-1 text-xs text-bambu-gray`,title:d(`fileManager.lastActivity`),children:[(0,G.jsx)(rs,{className:`w-3 h-3 flex-shrink-0`}),(0,G.jsx)(`span`,{className:`truncate`,children:ip(e.latest_activity_at)})]})]}),_&&(0,G.jsxs)(`button`,{onClick:t=>{t.stopPropagation(),i(e)},className:`flex-shrink-0 flex items-center gap-1 text-xs px-1.5 py-0.5 rounded bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400 hover:bg-blue-200 dark:hover:bg-blue-500/30 transition-colors`,title:`${e.project_name?`Project: ${e.project_name}`:`Archive: ${e.archive_name}`} (click to change)`,children:[(0,G.jsx)(Xc,{className:`w-3 h-3`}),e.project_name?(0,G.jsx)(Qo,{className:`w-3 h-3`}):(0,G.jsx)(Po,{className:`w-3 h-3`})]}),v&&e.external_readonly&&(0,G.jsx)(`span`,{title:d(`fileManager.readOnly`),children:(0,G.jsx)(nl,{className:`w-3 h-3 text-amber-600 dark:text-amber-400 flex-shrink-0`})}),e.file_count>0&&(0,G.jsx)(`span`,{className:`flex-shrink-0 text-xs text-bambu-gray`,children:e.file_count}),!_&&!v&&(0,G.jsx)(`button`,{onClick:t=>{t.stopPropagation(),i(e)},className:`flex-shrink-0 p-1 rounded hover:bg-bambu-dark-tertiary`,title:d(`fileManager.linkToProjectOrArchive`),children:(0,G.jsx)(Xc,{className:`w-3.5 h-3.5 text-bambu-gray hover:text-bambu-green`})}),(0,G.jsx)(`div`,{className:`flex-shrink-0 flex items-center gap-0.5 transition-opacity ${s?``:`can-hover:opacity-0 group-hover:opacity-100 group-focus-within:opacity-100`}`,onClick:e=>e.stopPropagation(),children:(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(`button`,{onClick:()=>h(!m),className:`p-1 rounded hover:bg-bambu-dark-tertiary`,children:(0,G.jsx)($s,{className:`w-3.5 h-3.5 text-bambu-gray`})}),m&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`fixed inset-0 z-10`,onClick:()=>h(!1)}),(0,G.jsxs)(`div`,{className:`absolute right-0 top-full mt-1 z-20 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl py-1 min-w-[120px]`,children:[(0,G.jsxs)(`button`,{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${u(`library:update_all`)?`text-white hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{u(`library:update_all`)&&(a(e),h(!1))},disabled:!u(`library:update_all`),title:u(`library:update_all`)?void 0:d(`fileManager.noPermissionRenameFolder`),children:[(0,G.jsx)(Al,{className:`w-3.5 h-3.5`}),d(`common.rename`)]}),(0,G.jsxs)(`button`,{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${u(`library:update_all`)?`text-white hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{u(`library:update_all`)&&(i(e),h(!1))},disabled:!u(`library:update_all`),title:u(`library:update_all`)?void 0:d(`fileManager.noPermissionLinkFolder`),children:[(0,G.jsx)(Xc,{className:`w-3.5 h-3.5`}),d(_?`fileManager.changeLink`:`fileManager.linkTo`)]}),(0,G.jsxs)(`button`,{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${b?`text-red-700 dark:text-red-400 hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{b&&(r(e.id),h(!1))},disabled:!b,title:x,children:[(0,G.jsx)(Pu,{className:`w-3.5 h-3.5`}),d(`common.delete`)]})]})]})]})})]}),g&&f&&(0,G.jsx)(`div`,{children:e.children.map(e=>(0,G.jsx)(p$e,{folder:e,selectedFolderId:t,onSelect:n,onDelete:r,onLink:i,onRename:a,depth:o+1,wrapNames:s,defaultExpanded:c,showModified:l,hasPermission:u,t:d},e.id))})]})}function m$e({file:e,isSelected:t,onSelect:n,onDelete:r,onDownload:i,onPrint:a,onSlice:o,onOpenInSlicer:s,onRunPipeline:c,useSlicerApi:l,desktopSlicer:u,canSlice:d,onPreview3d:f,onRename:p,onGenerateThumbnail:m,onTagClick:h,thumbnailVersion:g,hasPermission:_,canModify:v,authEnabled:b,showModified:x,t:S}){let[C,w]=(0,y.useState)(null),T=_(`library:read`),E=v(`library`,`update`,e.created_by_id),D=v(`library`,`delete`,e.created_by_id),O=[];return a&&M5(e)&&O.push({label:S(`common.print`),icon:(0,G.jsx)(Rl,{className:`w-4 h-4 text-bambu-green`}),onClick:()=>a(e),disabled:!_(`queue:create`),title:_(`queue:create`)?void 0:S(`fileManager.noPermissionAddToQueue`)}),N5(e,!!l,u)&&(l?o:s)&&O.push({label:S(`slice.action`),icon:l?(0,G.jsx)(Rs,{className:`w-4 h-4`}):(0,G.jsx)(rc,{className:`w-4 h-4`}),onClick:()=>{l?o?.(e):s?.(e)},disabled:!d,title:d?void 0:S(l?`fileManager.noPermissionSlice`:`fileManager.noPermissionDownload`)}),c&&l&&N5(e,!0,u)&&O.push({label:S(`library.runWithPipeline.actionLabel`),icon:(0,G.jsx)(Nl,{className:`w-4 h-4`}),onClick:()=>c(e),disabled:!_(`pipelines:run`),title:_(`pipelines:run`)?void 0:S(`library.runWithPipeline.noPermission`)}),f&&(e.file_type===`3mf`||e.file_type===`gcode`||e.file_type===`stl`||e.file_type===`gcode.3mf`)&&O.push({label:S(`fileManager.preview3d`),icon:(0,G.jsx)(Zo,{className:`w-4 h-4`}),onClick:()=>f(e),disabled:!T,title:T?void 0:S(`fileManager.noPermissionPreview`)}),O.push({label:S(`common.download`),icon:(0,G.jsx)(Xs,{className:`w-4 h-4`}),onClick:()=>i(e.id),disabled:!_(`library:read`),title:_(`library:read`)?void 0:S(`fileManager.noPermissionDownload`)}),p&&O.push({label:S(`common.rename`),icon:(0,G.jsx)(Al,{className:`w-4 h-4`}),onClick:()=>p(e),disabled:!E,title:E?void 0:S(`fileManager.noPermissionRenameFile`)}),m&&e.file_type===`stl`&&O.push({label:S(`fileManager.generateThumbnail`),icon:(0,G.jsx)(Hc,{className:`w-4 h-4`}),onClick:()=>m(e),disabled:!E,title:E?void 0:S(`fileManager.noPermissionGenerateThumbnail`)}),O.push({label:S(`common.delete`),icon:(0,G.jsx)(Pu,{className:`w-4 h-4`}),onClick:()=>r(e.id),danger:!0,disabled:!D,title:D?void 0:S(`fileManager.noPermissionDeleteFile`)}),(0,G.jsxs)(`div`,{className:`group relative bg-bambu-dark-secondary rounded-lg border transition-all cursor-pointer ${t?`border-bambu-green ring-1 ring-bambu-green`:`border-bambu-dark-tertiary hover:border-bambu-green/50`}`,onClick:()=>n(e.id),children:[(0,G.jsxs)(`div`,{className:`aspect-square bg-bambu-dark flex items-center justify-center overflow-hidden rounded-t-lg`,children:[e.thumbnail_path?(0,G.jsx)(`img`,{src:`${Z.getLibraryFileThumbnailUrl(e.id)}${g?(Z.getLibraryFileThumbnailUrl(e.id).includes(`?`)?`&`:`?`)+`v=${g}`:``}`,alt:e.filename,className:`w-full h-full object-cover`}):(0,G.jsx)(sc,{className:`w-12 h-12 text-bambu-gray/30`}),(0,G.jsx)(`div`,{className:`absolute top-2 right-2 text-xs px-1.5 py-0.5 rounded font-medium ${e.file_type===`3mf`?`bg-bambu-green/90 text-white`:e.file_type===`gcode`||e.file_type===`gcode.3mf`?`bg-blue-500/90 text-white`:e.file_type===`stl`?`bg-purple-500/90 text-white`:`bg-bambu-gray/90 text-white`}`,children:e.file_type.toUpperCase()})]}),(0,G.jsxs)(`div`,{className:`p-3`,children:[(0,G.jsx)(`h3`,{className:`text-sm font-medium text-white truncate`,title:e.print_name||e.filename,children:e.print_name||e.filename}),(0,G.jsxs)(`div`,{className:`flex items-center gap-3 mt-1 text-xs text-bambu-gray`,children:[(0,G.jsx)(`span`,{children:Gd(e.file_size)}),e.print_time_seconds&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(js,{className:`w-3 h-3`}),lp(e.print_time_seconds)]})]}),e.sliced_for_model&&(0,G.jsxs)(`div`,{className:`mt-1 text-xs text-bambu-gray flex items-center gap-1`,children:[(0,G.jsx)(Rl,{className:`w-3 h-3`}),e.sliced_for_model]}),(e.variant_count??0)>1&&(0,G.jsxs)(`div`,{className:`mt-1 text-xs text-bambu-green flex items-center gap-1`,children:[(0,G.jsx)(Jc,{className:`w-3 h-3`}),S(`fileManager.variants.badge`,{count:e.variant_count})]}),e.print_count>0&&(0,G.jsx)(`div`,{className:`mt-1 text-xs text-bambu-green`,children:S(`fileManager.printedCount`,{count:e.print_count})}),b&&e.created_by_username&&(0,G.jsxs)(`div`,{className:`mt-1 text-xs text-bambu-gray flex items-center gap-1`,children:[(0,G.jsx)(Hu,{className:`w-3 h-3`}),e.created_by_username]}),x&&(0,G.jsxs)(`div`,{className:`mt-1 text-xs text-bambu-gray flex items-center gap-1`,title:S(`fileManager.lastModified`),children:[(0,G.jsx)(rs,{className:`w-3 h-3`}),ip(e.fs_modified_at??e.created_at)]}),(e.tags?.length??0)>0&&(0,G.jsx)(`div`,{className:`mt-2 flex flex-wrap gap-1`,onClick:e=>e.stopPropagation(),children:e.tags.map(e=>(0,G.jsxs)(`button`,{type:`button`,onClick:()=>h?.(e.id),className:`inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded-full text-[10px] bg-bambu-green/10 text-bambu-green hover:bg-bambu-green/20 transition-colors max-w-full`,title:e.name,children:[(0,G.jsx)(Eu,{className:`w-2.5 h-2.5 flex-shrink-0`}),(0,G.jsx)(`span`,{className:`truncate`,children:e.name})]},e.id))})]}),(0,G.jsxs)(`div`,{className:`absolute bottom-2 right-2 transition-opacity can-hover:opacity-0 group-hover:opacity-100 group-focus-within:opacity-100`,onClick:e=>e.stopPropagation(),children:[(0,G.jsx)(`button`,{onClick:e=>{let t=e.currentTarget.getBoundingClientRect();w({x:t.left,y:t.bottom+4})},className:`p-1.5 rounded bg-bambu-dark-secondary/90 hover:bg-bambu-dark-tertiary`,children:(0,G.jsx)($s,{className:`w-4 h-4 text-bambu-gray`})}),C&&(0,G.jsx)(kT,{x:C.x,y:C.y,items:O,onClose:()=>w(null)})]}),(0,G.jsx)(`div`,{className:`absolute top-2 left-2 w-5 h-5 rounded border-2 flex items-center justify-center transition-all ${t?`bg-bambu-green border-bambu-green`:`border-white/30 bg-black/30 can-hover:opacity-0 group-hover:opacity-100 group-focus-within:opacity-100`}`,children:t&&(0,G.jsx)(`div`,{className:`w-2 h-2 bg-white rounded-sm`})})]})}function h$e(){let{t:e}=U(),t=co(),{showToast:n}=qd(),{hasPermission:r,hasAnyPermission:i,canModify:a,authEnabled:o}=Nd(),[s]=Ri(),c=or(),l=s.get(`folder`),[u,d]=(0,y.useState)(l?parseInt(l,10):null),[f,p]=(0,y.useState)(`internal`),[m,h]=(0,y.useState)([]),[g,_]=(0,y.useState)(!1),[v,b]=(0,y.useState)(!1),[x,S]=(0,y.useState)(!1),[C,w]=(0,y.useState)(!1),[T,E]=(0,y.useState)([]),[D,O]=(0,y.useState)(!1),[k,A]=(0,y.useState)(!1),[j,M]=(0,y.useState)(!1),[N,P]=(0,y.useState)([]),[F,I]=(0,y.useState)(null),[L,R]=(0,y.useState)(null),[z,B]=(0,y.useState)(null),[V,ee]=(0,y.useState)(null),[te,ne]=(0,y.useState)(null),[re,ie]=(0,y.useState)(null),[ae,oe]=(0,y.useState)({}),[se,H]=(0,y.useState)(null),[ce,le]=(0,y.useState)(()=>localStorage.getItem(`library-view-mode`)||`grid`),[ue,de]=(0,y.useState)(()=>localStorage.getItem(`library-wrap-folders`)===`true`),[fe,pe]=(0,y.useState)(()=>localStorage.getItem(`library-collapse-folders`)===`true`),[me,he]=(0,y.useState)(()=>localStorage.getItem(`library-folder-sort-field`)===`activity`?`activity`:`name`),[ge,_e]=(0,y.useState)(()=>localStorage.getItem(`library-folder-sort-direction`)===`desc`?`desc`:`asc`),[ve,ye]=(0,y.useState)(()=>{let e=localStorage.getItem(`library-sidebar-width`);return e?parseInt(e,10):256}),[be,xe]=(0,y.useState)(!1),Se=(0,y.useRef)(null);(0,y.useEffect)(()=>{if(!be)return;document.body.style.userSelect=`none`,document.body.style.cursor=`col-resize`;let e=e=>{if(!Se.current)return;let t=Se.current.parentElement?.getBoundingClientRect();if(!t)return;let n=e.clientX-t.left;ye(Math.min(500,Math.max(200,n)))},t=()=>{xe(!1),document.body.style.userSelect=``,document.body.style.cursor=``,localStorage.setItem(`library-sidebar-width`,String(ve))};return document.addEventListener(`mousemove`,e),document.addEventListener(`mouseup`,t),()=>{document.removeEventListener(`mousemove`,e),document.removeEventListener(`mouseup`,t),document.body.style.userSelect=``,document.body.style.cursor=``}},[be,ve]);let[Ce,we]=(0,y.useState)(``),[Te,Ee]=(0,y.useState)(`all`),[De,Oe]=(0,y.useState)(``),[ke,Ae]=(0,y.useState)(()=>localStorage.getItem(`library-sort-field`)||`name`),[je,Me]=(0,y.useState)(()=>localStorage.getItem(`library-sort-direction`)||`asc`),[Ne,Pe]=(0,y.useState)(()=>localStorage.getItem(`library-show-modified`)===`true`);(0,y.useEffect)(()=>{let e=s.get(`folder`);e&&d(parseInt(e,10))},[s]);let{data:Fe}=K({queryKey:[`settings`],queryFn:()=>Z.getSettings()}),Ie=HW(Fe?.open_in_slicer,Fe?.preferred_slicer),Le=(0,y.useCallback)(async t=>{try{let{token:e}=await Z.createLibrarySlicerToken(t.id),n=Z.getLibrarySlicerDownloadUrl(t.id,e,t.filename);KW(`${window.location.origin}${n}`,Ie)}catch{n(e(`fileManager.toast.openInSlicerFailed`),`error`);let r=Z.getLibraryFileDownloadUrl(t.id);KW(`${window.location.origin}${r}`,Ie)}},[Ie,n,e]),Re=(0,y.useCallback)(()=>Fe?.use_slicer_api?r(`library:upload`):i(`library:read_all`,`library:read_own`),[Fe?.use_slicer_api,r,i]),{data:ze,isLoading:Be}=K({queryKey:[`library-folders`],queryFn:()=>Z.getLibraryFolders()}),Ve=(0,y.useMemo)(()=>{if(!ze)return ze;let e=t=>[...t].sort((e,t)=>{let n=0;if(me===`name`)n=e.name.localeCompare(t.name);else{let r=e.latest_activity_at?new Date(e.latest_activity_at).getTime():null,i=t.latest_activity_at?new Date(t.latest_activity_at).getTime():null;if(r===null&&i===null)n=e.name.localeCompare(t.name);else if(r===null)return 1;else if(i===null)return-1;else n=r-i}return ge===`asc`?n:-n}).map(t=>({...t,children:e(t.children)}));return e(ze)},[ze,me,ge]),{data:He}=K({queryKey:[`library-trash-count`],queryFn:async()=>{try{return(await Z.listLibraryTrash(1,0)).total}catch{return 0}},staleTime:3e4}),Ue=u!==null&&Ce.trim().length>0,We=(0,y.useMemo)(()=>[...N].sort((e,t)=>e-t),[N]),{data:Ge=[]}=K({queryKey:[`library-tags`],queryFn:Z.getLibraryTags}),Ke=(0,y.useMemo)(()=>{let e=new Map;for(let t of Ge)e.set(t.id,t.name);return e},[Ge]);(0,y.useEffect)(()=>{Ge.length!==0&&P(e=>{let t=e.filter(e=>Ke.has(e));return t.length===e.length?e:t})},[Ge.length,Ke]);let qe=(0,y.useCallback)(e=>{P(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},[]),{data:Je,isLoading:Ye}=K({queryKey:[`library-files`,u,f,Ue,We],queryFn:()=>Z.getLibraryFiles(u,!1,void 0,u===null?f:void 0,Ue,We)}),{data:Xe}=K({queryKey:[`library-stats`],queryFn:()=>Z.getLibraryStats()}),{data:Ze}=K({queryKey:[`users`,`slim`],queryFn:()=>Z.getUsersSlim()}),Qe=(0,y.useMemo)(()=>{if(!Je)return[];let e=new Set(Je.map(e=>e.file_type));return Array.from(e).sort()},[Je]),$e=(0,y.useMemo)(()=>{if(!Je)return[];let e=[...Je];if(Ce.trim()){let t=Ce.toLowerCase();e=e.filter(e=>e.filename.toLowerCase().includes(t)||e.print_name&&e.print_name.toLowerCase().includes(t))}if(Te!==`all`&&(e=e.filter(e=>e.file_type===Te)),De.trim()){let t=De.toLowerCase();e=e.filter(e=>e.created_by_username&&e.created_by_username.toLowerCase().includes(t))}return e.sort((e,t)=>{let n=0;switch(ke){case`name`:n=(e.print_name||e.filename).localeCompare(t.print_name||t.filename);break;case`date`:n=(rp(e.fs_modified_at??e.created_at)?.getTime()??0)-(rp(t.fs_modified_at??t.created_at)?.getTime()??0);break;case`size`:n=e.file_size-t.file_size;break;case`type`:n=e.file_type.localeCompare(t.file_type);break;case`prints`:n=e.print_count-t.print_count;break}return je===`asc`?n:-n}),e},[Je,Ce,Te,De,ke,je]),et=(0,y.useMemo)(()=>{if(!Xe||!Fe)return!1;let e=(Fe.library_disk_warning_gb||5)*1024*1024*1024;return Xe.disk_free_bytesZ.createLibraryFolder(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`library-folders`]}),_(!1),n(e(`fileManager.toast.folderCreated`),`success`)},onError:e=>n(e.message,`error`)}),nt=q({mutationFn:async e=>{let t=await Z.createExternalFolder(e);return await Z.scanExternalFolder(t.id),t},onSuccess:r=>{t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`library-stats`]}),b(!1),d(r.id),n(e(`fileManager.toast.externalFolderLinked`),`success`)},onError:e=>n(e.message,`error`)}),rt=q({mutationFn:e=>Z.scanExternalFolder(e),onSuccess:r=>{t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`library-stats`]}),n(e(`fileManager.toast.folderScanned`,{added:r.added,removed:r.removed}),`success`)},onError:e=>n(e.message,`error`)}),it=q({mutationFn:e=>Z.deleteLibraryFolder(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`library-stats`]}),u===L?.id&&d(null),R(null),n(e(`fileManager.toast.folderDeleted`),`success`)},onError:e=>{R(null),n(e.message,`error`)}}),at=q({mutationFn:e=>Z.deleteLibraryFile(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`library-stats`]}),t.invalidateQueries({queryKey:[`library-trash-count`]}),h(e=>e.filter(e=>e!==L?.id)),R(null),n(e(`fileManager.toast.fileDeleted`),`success`)},onError:e=>{R(null),n(e.message,`error`)}}),ot=q({mutationFn:e=>Z.createVariantGroup(e.map(e=>({library_file_id:e}))),onSuccess:r=>{t.invalidateQueries({queryKey:[`library-files`]}),n(e(`fileManager.variants.grouped`,{count:r.members.length}),`success`),h([])},onError:e=>n(e.message,`error`)}),st=q({mutationFn:e=>Z.bulkDeleteLibrary(e,[]),onSuccess:(r,i)=>{t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`library-stats`]}),t.invalidateQueries({queryKey:[`library-trash-count`]}),n(e(`fileManager.toast.filesDeleted`,{count:i.length}),`success`),h([]),R(null)},onError:e=>{R(null),n(e.message,`error`)}}),ct=q({mutationFn:({fileIds:e,folderId:t})=>Z.moveLibraryFiles(e,t),onSuccess:()=>{t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`library-folders`]}),h([]),S(!1),n(e(`fileManager.toast.filesMoved`),`success`)},onError:e=>n(e.message,`error`)}),lt=q({mutationFn:({id:e,data:t})=>Z.updateLibraryFolder(e,t),onSuccess:(r,i)=>{t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`project-folders`]}),t.invalidateQueries({queryKey:[`archive-folders`]}),I(null),n(i.data.project_id===0&&i.data.archive_id===0?e(`fileManager.toast.folderUnlinked`):e(`fileManager.toast.folderLinked`),`success`)},onError:e=>n(e.message,`error`)}),ut=q({mutationFn:({id:e,filename:t})=>Z.updateLibraryFile(e,{filename:t}),onSuccess:()=>{t.invalidateQueries({queryKey:[`library-files`]}),ie(null),n(e(`fileManager.toast.fileRenamed`),`success`)},onError:e=>{ie(null),n(e.message,`error`)}}),dt=q({mutationFn:({id:e,name:t})=>Z.updateLibraryFolder(e,{name:t}),onSuccess:()=>{t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`library-files`]}),ie(null),n(e(`fileManager.toast.folderRenamed`),`success`)},onError:e=>{ie(null),n(e.message,`error`)}}),ft=q({mutationFn:()=>Z.batchGenerateStlThumbnails({all_missing:!0}),onSuccess:r=>{if(t.invalidateQueries({queryKey:[`library-files`]}),r.succeeded>0){let e=Date.now(),t={};r.results.forEach(n=>{n.success&&(t[n.file_id]=e)}),oe(e=>({...e,...t}))}r.succeeded>0&&r.failed===0?n(e(`fileManager.toast.thumbnailsGenerated`,{count:r.succeeded}),`success`):r.succeeded>0&&r.failed>0?n(e(`fileManager.toast.thumbnailsGeneratedPartial`,{succeeded:r.succeeded,failed:r.failed}),`success`):r.processed===0?n(e(`fileManager.toast.noStlMissingThumbnails`),`info`):n(e(`fileManager.toast.failedToGenerateThumbnails`,{error:r.results[0]?.error||`Unknown error`}),`error`)},onError:e=>n(e.message,`error`)}),pt=q({mutationFn:e=>Z.batchGenerateStlThumbnails({file_ids:[e]}),onSuccess:r=>{if(t.invalidateQueries({queryKey:[`library-files`]}),r.succeeded>0){let t=r.results[0]?.file_id;t&&oe(e=>({...e,[t]:Date.now()})),n(e(`fileManager.toast.thumbnailGenerated`),`success`)}else n(e(`fileManager.toast.failedToGenerateThumbnail`,{error:r.results[0]?.error||`Unknown error`}),`error`)},onError:e=>n(e.message,`error`)}),mt=(0,y.useMemo)(()=>Je?Je.filter(e=>m.includes(e.id)&&M5(e)):[],[Je,m]),{data:ht}=K({queryKey:[`variant-group`,z?.variant_group_id],queryFn:()=>Z.getVariantGroup(z.variant_group_id),enabled:!!z?.variant_group_id}),gt=(0,y.useMemo)(()=>{if(z){if(mt.length>1)return mt.map(e=>({id:e.id,filename:e.filename,sliced_for_model:e.sliced_for_model}));if(ht&&ht.members.length>1)return ht.members.map(e=>({id:e.library_file_id,filename:e.filename,sliced_for_model:e.target_model}))}},[z,mt,ht]),_t=(0,y.useCallback)(e=>{h(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},[]),vt=(0,y.useCallback)(()=>{$e.length>0&&h($e.map(e=>e.id))},[$e]),yt=(0,y.useCallback)(()=>{h([])},[]),bt=()=>{t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`library-stats`]})},{isDraggingOver:xt,dragHandlers:St}=YW({disabled:!r(`library:upload`)||C,onFiles:e=>{E(e),w(!0)}}),Ct=e=>{Z.downloadLibraryFile(e).catch(e=>{console.error(`Library file download failed:`,e)})},wt=()=>{L&&(L.type===`file`?at.mutate(L.id):L.type===`folder`?it.mutate(L.id):L.type===`bulk`&&st.mutate(m))},Tt=it.isPending||at.isPending||st.isPending,Et=e=>{le(e),localStorage.setItem(`library-view-mode`,e)},Dt=Be||Ye,Ot=(0,y.useMemo)(()=>{if(!u||!ze)return null;let e=t=>{for(let n of t){if(n.id===u)return n;let t=e(n.children);if(t)return t}return null};return e(ze)},[u,ze]);return(0,G.jsxs)(`div`,{className:`p-4 md:p-8 min-h-[calc(100vh-64px)] lg:h-[calc(100vh-64px)] flex flex-col relative`,...St,children:[xt&&(0,G.jsx)(`div`,{className:`fixed inset-0 z-50 bg-bambu-dark/90 flex items-center justify-center pointer-events-none`,children:(0,G.jsxs)(`div`,{className:`border-4 border-dashed border-bambu-green rounded-xl p-12 text-center`,children:[(0,G.jsx)(Vu,{className:`w-16 h-16 mx-auto mb-4 text-bambu-green`}),(0,G.jsx)(`p`,{className:`text-2xl font-semibold text-white mb-2`,children:e(`fileManager.dropFilesHere`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray`,children:e(`fileManager.releaseToUpload`)})]})}),(0,G.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between gap-4 mb-6`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,G.jsx)(vc,{className:`w-7 h-7 text-bambu-green`}),e(`fileManager.title`)]}),(0,G.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:e(`fileManager.subtitle`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center bg-bambu-dark rounded-lg p-1`,children:[(0,G.jsx)(`button`,{onClick:()=>Et(`grid`),className:`p-1.5 rounded transition-colors ${ce===`grid`?`bg-bambu-dark-secondary text-white`:`text-bambu-gray hover:text-white`}`,title:e(`fileManager.gridView`),children:(0,G.jsx)(Yc,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:()=>Et(`list`),className:`p-1.5 rounded transition-colors ${ce===`list`?`bg-bambu-dark-secondary text-white`:`text-bambu-gray hover:text-white`}`,title:e(`fileManager.listView`),children:(0,G.jsx)(el,{className:`w-4 h-4`})})]}),(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>ft.mutate(),disabled:ft.isPending||!i(`library:update_own`,`library:update_all`),title:i(`library:update_own`,`library:update_all`)?e(`fileManager.generateThumbnailsForMissing`):e(`fileManager.noPermissionGenerateThumbnail`),children:[ft.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 mr-2 animate-spin`}):(0,G.jsx)(Hc,{className:`w-4 h-4 mr-2`}),e(`fileManager.generateThumbnails`)]}),(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>b(!0),disabled:!r(`library:upload`),title:r(`library:upload`)?e(`fileManager.linkExternalFolder`):e(`fileManager.noPermissionCreateFolder`),children:[(0,G.jsx)(bc,{className:`w-4 h-4 mr-2`}),e(`fileManager.linkExternal`)]}),(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>_(!0),disabled:!r(`library:upload`),title:r(`library:upload`)?void 0:e(`fileManager.noPermissionCreateFolder`),children:[(0,G.jsx)(yc,{className:`w-4 h-4 mr-2`}),e(`fileManager.newFolder`)]}),(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>A(!0),title:e(`fileManager.tags.manageTitle`),children:[(0,G.jsx)(Eu,{className:`w-4 h-4 mr-2`}),e(`fileManager.tags.manage`)]}),r(`library:purge`)&&(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>O(!0),title:e(`libraryPurge.headerTooltip`),children:[(0,G.jsx)(Pu,{className:`w-4 h-4 mr-2`}),e(`libraryPurge.headerButton`)]}),i(`library:delete_own`,`library:delete_all`)&&(0,G.jsxs)(Ai,{to:`/files/trash`,className:`inline-flex items-center px-3 py-1.5 text-sm rounded bg-bambu-dark-secondary text-bambu-gray hover:text-white hover:bg-bambu-dark transition-colors`,title:e(`libraryTrash.headerTooltip`),children:[(0,G.jsx)(Pu,{className:`w-4 h-4 mr-2`}),e(`libraryTrash.headerButton`),typeof He==`number`&&He>0&&(0,G.jsx)(`span`,{className:`ml-1.5 px-1.5 py-0.5 text-xs rounded-full bg-bambu-green/20 text-bambu-green`,children:He})]}),(0,G.jsxs)(Q,{onClick:()=>w(!0),disabled:!r(`library:upload`),title:r(`library:upload`)?void 0:e(`fileManager.noPermissionUpload`),children:[(0,G.jsx)(Vu,{className:`w-4 h-4 mr-2`}),e(`common.upload`)]})]})]}),et&&Xe&&Fe&&(0,G.jsxs)(`div`,{className:`flex items-center gap-3 mb-4 p-3 bg-amber-500/10 border border-amber-500/30 rounded-lg`,children:[(0,G.jsx)(Lu,{className:`w-5 h-5 text-amber-500 flex-shrink-0`}),(0,G.jsxs)(`div`,{className:`flex-1`,children:[(0,G.jsx)(`p`,{className:`text-sm text-amber-500 font-medium`,children:e(`fileManager.lowDiskSpaceWarning`)}),(0,G.jsx)(`p`,{className:`text-xs text-amber-500/80`,children:e(`fileManager.lowDiskSpaceDetails`,{free:Gd(Xe.disk_free_bytes),total:Gd(Xe.disk_total_bytes),threshold:Fe.library_disk_warning_gb})})]})]}),Xe&&(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 sm:gap-6 mb-6 p-3 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,G.jsx)(pc,{className:`w-4 h-4 text-bambu-green`}),(0,G.jsxs)(`span`,{className:`text-bambu-gray`,children:[e(`fileManager.files`),`:`]}),(0,G.jsx)(`span`,{className:`text-white font-medium`,children:Xe.total_files})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,G.jsx)(vc,{className:`w-4 h-4 text-blue-600 dark:text-blue-400`}),(0,G.jsxs)(`span`,{className:`text-bambu-gray`,children:[e(`fileManager.folders`),`:`]}),(0,G.jsx)(`span`,{className:`text-white font-medium`,children:Xe.total_folders})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,G.jsx)(Pc,{className:`w-4 h-4 text-amber-600 dark:text-amber-400`}),(0,G.jsxs)(`span`,{className:`text-bambu-gray`,children:[e(`fileManager.size`),`:`]}),(0,G.jsx)(`span`,{className:`text-white font-medium`,children:Gd(Xe.total_size_bytes)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm sm:ml-auto`,children:[(0,G.jsxs)(`span`,{className:`text-bambu-gray`,children:[e(`fileManager.free`),`:`]}),(0,G.jsx)(`span`,{className:`font-medium ${et?`text-amber-500`:`text-white`}`,children:Gd(Xe.disk_free_bytes)})]})]}),(0,G.jsxs)(`div`,{className:`flex-1 flex flex-col lg:flex-row gap-4 lg:gap-6 min-h-0`,children:[(0,G.jsx)(`div`,{className:`lg:hidden`,children:(0,G.jsxs)(`select`,{value:u===null?`__top:${f}`:String(u),onChange:e=>{let t=e.target.value;t.startsWith(`__top:`)?(d(null),p(t.slice(6))):d(parseInt(t,10))},className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg px-3 py-2.5 text-white focus:outline-none focus:border-bambu-green`,children:[(0,G.jsxs)(`option`,{value:`__top:internal`,children:[`📁 `,e(`fileManager.allFiles`)]}),ze?.some(e=>e.is_external)&&(0,G.jsxs)(`option`,{value:`__top:external`,children:[`🔗 `,e(`fileManager.allExternal`)]}),Ve&&(()=>{let e=(t,n=0)=>{let r=[];for(let i of t)r.push({id:i.id,name:i.name,fileCount:i.file_count,depth:n}),i.children.length>0&&r.push(...e(i.children,n+1));return r};return e(Ve).map(e=>(0,G.jsxs)(`option`,{value:e.id,children:[`│ `.repeat(e.depth),`📂 `,e.name,` `,e.fileCount>0?`(${e.fileCount})`:``]},e.id))})()]})}),(0,G.jsxs)(`div`,{ref:Se,className:`hidden lg:flex flex-shrink-0 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary overflow-hidden flex-col relative`,style:{width:`${ve}px`},children:[(0,G.jsx)(`div`,{className:`absolute right-0 top-0 bottom-0 w-1.5 cursor-col-resize z-10 group/resize flex items-center justify-center transition-colors ${be?`bg-bambu-green`:`hover:bg-bambu-green/50`}`,onMouseDown:e=>{e.preventDefault(),xe(!0)},onDoubleClick:()=>{ye(256),localStorage.setItem(`library-sidebar-width`,`256`)},title:e(`fileManager.dragToResizeTooltip`),children:(0,G.jsxs)(`div`,{className:`flex flex-col gap-1 opacity-0 group-hover/resize:opacity-100 transition-opacity ${be?`opacity-100`:``}`,children:[(0,G.jsx)(`div`,{className:`w-0.5 h-0.5 rounded-full bg-white/70`}),(0,G.jsx)(`div`,{className:`w-0.5 h-0.5 rounded-full bg-white/70`}),(0,G.jsx)(`div`,{className:`w-0.5 h-0.5 rounded-full bg-white/70`})]})}),(0,G.jsxs)(`div`,{className:`p-3 border-b border-bambu-dark-tertiary flex items-center justify-between`,children:[(0,G.jsx)(`h2`,{className:`text-sm font-medium text-white`,children:e(`fileManager.folders`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,G.jsxs)(`select`,{value:me,onChange:e=>{let t=e.target.value===`activity`?`activity`:`name`;he(t),localStorage.setItem(`library-folder-sort-field`,t)},className:`text-xs px-1 py-0.5 rounded bg-bambu-dark border border-bambu-dark-tertiary text-bambu-gray focus:outline-none focus:border-bambu-green`,title:e(`fileManager.folderSort`),"aria-label":e(`fileManager.folderSort`),children:[(0,G.jsx)(`option`,{value:`name`,children:e(`fileManager.folderSortByName`)}),(0,G.jsx)(`option`,{value:`activity`,children:e(`fileManager.folderSortByActivity`)})]}),(0,G.jsx)(`button`,{onClick:()=>{let e=ge===`asc`?`desc`:`asc`;_e(e),localStorage.setItem(`library-folder-sort-direction`,e)},className:`text-bambu-gray hover:text-white hover:bg-bambu-dark p-1 rounded transition-colors`,title:e(ge===`asc`?`fileManager.ascending`:`fileManager.descending`),"aria-label":e(ge===`asc`?`fileManager.ascending`:`fileManager.descending`),children:ge===`asc`?(0,G.jsx)(Vo,{className:`w-3.5 h-3.5`}):(0,G.jsx)(Fo,{className:`w-3.5 h-3.5`})}),(0,G.jsx)(`button`,{onClick:()=>{let e=!fe;pe(e),localStorage.setItem(`library-collapse-folders`,String(e))},className:`text-xs px-1.5 py-0.5 rounded transition-colors ${fe?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:text-white hover:bg-bambu-dark`}`,title:e(fe?`fileManager.expandFoldersByDefault`:`fileManager.collapseFoldersByDefault`),children:e(`fileManager.collapse`)}),(0,G.jsx)(`button`,{onClick:()=>{let e=!ue;de(e),localStorage.setItem(`library-wrap-folders`,String(e))},className:`text-xs px-1.5 py-0.5 rounded transition-colors ${ue?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:text-white hover:bg-bambu-dark`}`,title:e(ue?`fileManager.disableTextWrapping`:`fileManager.enableTextWrapping`),children:e(`fileManager.wrap`)})]})]}),(0,G.jsxs)(`div`,{className:`flex-1 overflow-y-auto p-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-1.5 rounded cursor-pointer transition-colors ${u===null&&f===`internal`?`bg-bambu-green/20 text-bambu-green`:`hover:bg-bambu-dark text-white`}`,onClick:()=>{d(null),p(`internal`)},children:[(0,G.jsx)(sc,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`text-sm`,children:e(`fileManager.allFiles`)})]}),ze?.some(e=>e.is_external)&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-1.5 rounded cursor-pointer transition-colors ${u===null&&f===`external`?`bg-bambu-green/20 text-bambu-green`:`hover:bg-bambu-dark text-white`}`,onClick:()=>{d(null),p(`external`)},children:[(0,G.jsx)(bc,{className:`w-4 h-4 text-purple-600 dark:text-purple-400`}),(0,G.jsx)(`span`,{className:`text-sm`,children:e(`fileManager.allExternal`)})]}),Ve?.map(t=>(0,G.jsx)(p$e,{folder:t,selectedFolderId:u,onSelect:d,onDelete:e=>R({type:`folder`,id:e}),onLink:I,onRename:e=>ie({type:`folder`,id:e.id,name:e.name}),wrapNames:ue,defaultExpanded:!fe,showModified:Ne,hasPermission:r,t:e},`${t.id}-${fe?`c`:`e`}`))]})]}),(0,G.jsxs)(`div`,{className:`flex-1 flex flex-col lg:flex-row min-w-0 min-h-0 gap-4 lg:gap-6`,children:[(0,G.jsxs)(`div`,{className:`flex-1 flex flex-col min-w-0 min-h-0`,children:[Ge.length>0&&(0,G.jsxs)(`div`,{className:`mb-3 flex flex-wrap items-center gap-2 p-2 sm:p-3 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary`,children:[(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray font-medium shrink-0`,children:e(`fileManager.tags.filterLabel`)}),Ge.map(e=>{let t=N.includes(e.id);return(0,G.jsxs)(`button`,{type:`button`,onClick:()=>qe(e.id),className:t?`inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs bg-bambu-green/20 text-bambu-green border border-bambu-green/40 hover:bg-bambu-green/30 transition-colors`:`inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs bg-bambu-dark text-bambu-gray border border-bambu-dark-tertiary hover:text-white hover:border-bambu-green/40 transition-colors`,title:e.name,children:[(0,G.jsx)(Eu,{className:`w-3 h-3`}),(0,G.jsx)(`span`,{children:e.name}),t&&(0,G.jsx)(nd,{className:`w-3 h-3`})]},e.id)}),N.length>0&&(0,G.jsx)(`button`,{type:`button`,onClick:()=>P([]),className:`ml-auto text-xs text-bambu-gray hover:text-white shrink-0`,children:e(`fileManager.tags.clearAll`)})]}),Ot?.is_external&&(0,G.jsxs)(`div`,{className:`flex items-center gap-3 mb-4 p-3 bg-purple-50 dark:bg-purple-500/10 border border-purple-300 dark:border-purple-500/30 rounded-lg`,children:[(0,G.jsx)(bc,{className:`w-5 h-5 text-purple-600 dark:text-purple-400 flex-shrink-0`}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-sm font-medium text-purple-700 dark:text-purple-300`,children:e(`fileManager.externalFolder`)}),Ot.external_readonly&&(0,G.jsxs)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-400 flex items-center gap-1`,children:[(0,G.jsx)(nl,{className:`w-3 h-3`}),e(`fileManager.readOnly`)]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray truncate font-mono`,title:Ot.external_path||``,children:Ot.external_path})]}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:()=>u&&rt.mutate(u),disabled:rt.isPending,title:e(`fileManager.scanFolder`),children:[rt.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Hl,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`ml-1.5`,children:e(`fileManager.scanFolder`)})]})]}),Je&&Je.length>0&&(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 sm:gap-3 mb-4 p-2 sm:p-3 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary sticky top-0 z-10 lg:static`,children:[(0,G.jsxs)(`div`,{className:`relative w-full sm:w-auto sm:flex-1 sm:max-w-xs`,children:[(0,G.jsx)(Ql,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,G.jsx)(`input`,{type:`text`,placeholder:e(`fileManager.searchFiles`),value:Ce,onChange:e=>we(e.target.value),className:`w-full pl-9 pr-3 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`}),Ue&&(0,G.jsx)(`span`,{className:`absolute -bottom-4 left-0 text-[10px] text-bambu-gray whitespace-nowrap`,title:e(`fileManager.searchSubfoldersHint`),children:e(`fileManager.searchSubfoldersHint`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(wc,{className:`w-4 h-4 text-bambu-gray hidden sm:block`}),(0,G.jsxs)(`select`,{value:Te,onChange:e=>Ee(e.target.value),className:`bg-bambu-dark border border-bambu-dark-tertiary rounded px-2 py-1.5 text-sm text-white focus:outline-none focus:border-bambu-green`,children:[(0,G.jsx)(`option`,{value:`all`,children:e(`fileManager.allTypes`)}),Qe.map(e=>(0,G.jsx)(`option`,{value:e,children:e.toUpperCase()},e))]})]}),o&&(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(`input`,{type:`text`,placeholder:e(`fileManager.filterByUser`,{defaultValue:`Filter by user`}),value:De,onChange:e=>Oe(e.target.value),list:`usernames-list`,className:`w-32 sm:w-40 px-2 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green ${De?`pr-7`:``}`,style:De?{WebkitAppearance:`none`,MozAppearance:`textfield`}:void 0}),De&&(0,G.jsx)(`button`,{onClick:()=>Oe(``),className:`absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white z-10`,children:(0,G.jsx)(nd,{className:`w-3 h-3`})}),(0,G.jsx)(`datalist`,{id:`usernames-list`,children:Ze?.map(e=>(0,G.jsx)(`option`,{value:e.username},e.id))})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`select`,{value:ke,onChange:e=>{let t=e.target.value;Ae(t),localStorage.setItem(`library-sort-field`,t)},className:`bg-bambu-dark border border-bambu-dark-tertiary rounded px-2 py-1.5 text-sm text-white focus:outline-none focus:border-bambu-green`,children:[(0,G.jsx)(`option`,{value:`name`,children:e(`common.name`)}),(0,G.jsx)(`option`,{value:`date`,children:e(`common.date`)}),(0,G.jsx)(`option`,{value:`size`,children:e(`fileManager.size`)}),(0,G.jsx)(`option`,{value:`type`,children:e(`common.type`)}),(0,G.jsx)(`option`,{value:`prints`,children:e(`fileManager.prints`)})]}),(0,G.jsx)(`button`,{onClick:()=>Me(e=>{let t=e===`asc`?`desc`:`asc`;return localStorage.setItem(`library-sort-direction`,t),t}),className:`p-1.5 rounded bg-bambu-dark border border-bambu-dark-tertiary hover:border-bambu-green transition-colors`,title:e(je===`asc`?`fileManager.ascending`:`fileManager.descending`),children:je===`asc`?(0,G.jsx)(Vo,{className:`w-4 h-4 text-white`}):(0,G.jsx)(Fo,{className:`w-4 h-4 text-white`})}),(0,G.jsx)(`button`,{onClick:()=>Pe(e=>{let t=!e;return localStorage.setItem(`library-show-modified`,String(t)),t}),className:`p-1.5 rounded bg-bambu-dark border transition-colors ${Ne?`border-bambu-green text-bambu-green`:`border-bambu-dark-tertiary text-white hover:border-bambu-green`}`,title:e(Ne?`fileManager.hideModified`:`fileManager.showModified`),"aria-pressed":Ne,children:(0,G.jsx)(rs,{className:`w-4 h-4`})})]}),(Ce||Te!==`all`||De)&&(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray hidden sm:inline`,children:e(`fileManager.resultsCount`,{showing:$e.length,total:Je.length})})]}),$e.length>0&&(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 mb-4 p-2 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary sticky top-[52px] z-10 lg:static`,children:[m.length===$e.length&&m.length>0?(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:yt,children:[(0,G.jsx)(bu,{className:`w-4 h-4 sm:mr-1`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`fileManager.deselectAll`)})]}):(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:vt,children:[(0,G.jsx)(vu,{className:`w-4 h-4 sm:mr-1`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`fileManager.selectAll`)})]}),m.length>0&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray ml-2`,children:e(`fileManager.selected`,{count:m.length})}),(0,G.jsx)(`div`,{className:`hidden sm:block flex-1`}),(0,G.jsxs)(`div`,{className:`w-full sm:w-auto flex flex-wrap items-center gap-2 mt-2 sm:mt-0`,children:[mt.length>=1&&(0,G.jsxs)(Q,{variant:`primary`,size:`sm`,onClick:()=>B(mt[0]),disabled:!r(`queue:create`),title:r(`queue:create`)?void 0:e(`fileManager.noPermissionAddToQueue`),children:[(0,G.jsx)(Rl,{className:`w-4 h-4 sm:mr-1`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:mt.length>1?e(`fileManager.variants.printAlternatives`,{count:mt.length}):e(`common.print`)})]}),mt.length>=2&&!mt.some(e=>e.variant_group_id)&&(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:()=>ot.mutate(mt.map(e=>e.id)),disabled:ot.isPending||!i(`library:update_own`,`library:update_all`),title:e(`fileManager.variants.groupTooltip`),children:[(0,G.jsx)(Jc,{className:`w-4 h-4 sm:mr-1`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`fileManager.variants.groupAction`)})]}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:()=>S(!0),disabled:!i(`library:update_own`,`library:update_all`),title:i(`library:update_own`,`library:update_all`)?void 0:e(`fileManager.noPermissionMoveFiles`),children:[(0,G.jsx)(vl,{className:`w-4 h-4 sm:mr-1`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.move`)})]}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:()=>M(!0),disabled:!i(`library:update_own`,`library:update_all`),title:i(`library:update_own`,`library:update_all`)?e(`fileManager.tags.bulkTooltip`):e(`fileManager.tags.noPermission`),children:[(0,G.jsx)(Eu,{className:`w-4 h-4 sm:mr-1`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`fileManager.tags.tagAction`)})]}),(0,G.jsxs)(Q,{variant:`danger`,size:`sm`,onClick:()=>{m.length===1?R({type:`file`,id:m[0]}):R({type:`bulk`,id:0,count:m.length})},disabled:!i(`library:delete_own`,`library:delete_all`),title:i(`library:delete_own`,`library:delete_all`)?void 0:e(`fileManager.noPermissionDeleteFiles`),children:[(0,G.jsx)(Pu,{className:`w-4 h-4 sm:mr-1`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.delete`)})]}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:yt,children:[(0,G.jsx)(nd,{className:`w-4 h-4 sm:mr-1`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.clear`)})]})]})]})]}),Dt?(0,G.jsx)(`div`,{className:`flex-1 flex items-center justify-center`,children:(0,G.jsxs)(`div`,{className:`flex flex-col items-center gap-3`,children:[(0,G.jsx)(Y,{className:`w-8 h-8 animate-spin text-bambu-green`}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`fileManager.loadingFiles`)})]})}):Je?.length===0?(0,G.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center`,children:[(0,G.jsx)(`div`,{className:`p-4 bg-bambu-dark rounded-2xl mb-4`,children:(0,G.jsx)(sc,{className:`w-12 h-12 text-bambu-gray/50`})}),(0,G.jsx)(`h3`,{className:`text-lg font-medium text-white mb-2`,children:e(u===null?f===`external`?`fileManager.externalIsEmpty`:`fileManager.noFilesYet`:`fileManager.folderIsEmpty`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-center max-w-md mb-6`,children:e(u===null?f===`external`?`fileManager.externalEmptyDescription`:`fileManager.noFilesDescription`:`fileManager.folderEmptyDescription`)}),(0,G.jsxs)(Q,{onClick:()=>w(!0),disabled:!r(`library:upload`),title:r(`library:upload`)?void 0:e(`fileManager.noPermissionUpload`),children:[(0,G.jsx)(Fl,{className:`w-4 h-4 mr-2`}),e(`fileManager.uploadFiles`)]})]}):$e.length===0?(0,G.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center`,children:[(0,G.jsx)(`div`,{className:`p-4 bg-bambu-dark rounded-2xl mb-4`,children:(0,G.jsx)(Ql,{className:`w-12 h-12 text-bambu-gray/50`})}),(0,G.jsx)(`h3`,{className:`text-lg font-medium text-white mb-2`,children:e(`fileManager.noMatchingFiles`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-center max-w-md mb-6`,children:e(`fileManager.noMatchingFilesDescription`)}),(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>{we(``),Ee(`all`)},children:e(`fileManager.clearFilters`)})]}):ce===`grid`?(0,G.jsx)(`div`,{className:`flex-1 lg:overflow-y-auto`,children:(0,G.jsx)(`div`,{className:`grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 2xl:grid-cols-6 gap-4`,children:$e.map(t=>(0,G.jsx)(m$e,{file:t,isSelected:m.includes(t.id),t:e,onSelect:_t,onDelete:e=>R({type:`file`,id:e}),onDownload:Ct,onPrint:B,onSlice:ee,onOpenInSlicer:Le,desktopSlicer:Ie,onRunPipeline:ne,useSlicerApi:Fe?.use_slicer_api??!1,canSlice:Re(),onPreview3d:e=>{M5(e)?c(`/gcode-viewer?library_file=${e.id}`):H(e)},onRename:e=>ie({type:`file`,id:e.id,name:e.filename}),onGenerateThumbnail:e=>pt.mutate(e.id),onTagClick:qe,thumbnailVersion:ae[t.id],hasPermission:r,canModify:a,authEnabled:o,showModified:Ne},t.id))})}):(0,G.jsx)(`div`,{className:`flex-1 lg:overflow-y-auto`,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary overflow-x-auto`,children:[(0,G.jsxs)(`div`,{className:`hidden sm:grid ${o?`grid-cols-[auto_1fr_120px_100px_100px_100px_minmax(0,200px)_220px]`:`grid-cols-[auto_1fr_100px_100px_100px_minmax(0,200px)_220px]`} gap-4 px-4 py-2 bg-bambu-dark-secondary border-b border-bambu-dark-tertiary text-xs text-bambu-gray font-medium`,children:[(0,G.jsx)(`div`,{className:`w-6`}),(0,G.jsx)(`div`,{children:e(`common.name`)}),o&&(0,G.jsx)(`div`,{children:e(`fileManager.uploadedBy`,{defaultValue:`Uploaded By`})}),(0,G.jsx)(`div`,{children:e(`common.type`)}),(0,G.jsx)(`div`,{children:e(`fileManager.size`)}),(0,G.jsx)(`div`,{children:e(`fileManager.prints`)}),(0,G.jsx)(`div`,{children:e(`fileManager.tags.title`)}),(0,G.jsx)(`div`,{})]}),$e.map(t=>(0,G.jsxs)(`div`,{className:`grid ${o?`grid-cols-[auto_1fr_120px_100px_100px_100px_minmax(0,200px)_220px]`:`grid-cols-[auto_1fr_100px_100px_100px_minmax(0,200px)_220px]`} gap-4 px-4 py-3 items-center border-b border-bambu-dark-tertiary last:border-b-0 cursor-pointer hover:bg-bambu-dark/50 transition-colors ${m.includes(t.id)?`bg-bambu-green/10`:``}`,onClick:()=>_t(t.id),children:[(0,G.jsx)(`div`,{className:`w-5 h-5 rounded border-2 flex items-center justify-center ${m.includes(t.id)?`bg-bambu-green border-bambu-green`:`border-bambu-gray/50`}`,children:m.includes(t.id)&&(0,G.jsx)(`div`,{className:`w-2 h-2 bg-white rounded-sm`})}),(0,G.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0`,children:[(0,G.jsxs)(`div`,{className:`relative group/thumb`,children:[(0,G.jsx)(`div`,{className:`w-10 h-10 rounded bg-bambu-dark flex-shrink-0 overflow-hidden`,children:t.thumbnail_path?(0,G.jsx)(`img`,{src:`${Z.getLibraryFileThumbnailUrl(t.id)}${ae[t.id]?(Z.getLibraryFileThumbnailUrl(t.id).includes(`?`)?`&`:`?`)+`v=${ae[t.id]}`:``}`,alt:``,className:`w-full h-full object-cover`}):(0,G.jsx)(`div`,{className:`w-full h-full flex items-center justify-center`,children:(0,G.jsx)(sc,{className:`w-5 h-5 text-bambu-gray/50`})})}),t.thumbnail_path&&(0,G.jsx)(`div`,{className:`absolute left-0 top-full mt-2 z-50 hidden group-hover/thumb:block`,children:(0,G.jsx)(`div`,{className:`w-48 h-48 rounded-lg bg-bambu-dark-secondary border border-bambu-dark-tertiary shadow-xl overflow-hidden`,children:(0,G.jsx)(`img`,{src:`${Z.getLibraryFileThumbnailUrl(t.id)}${ae[t.id]?(Z.getLibraryFileThumbnailUrl(t.id).includes(`?`)?`&`:`?`)+`v=${ae[t.id]}`:``}`,alt:t.filename,className:`w-full h-full object-contain`})})})]}),(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsx)(`div`,{className:`text-sm text-white truncate`,children:t.print_name||t.filename}),Ne&&(0,G.jsxs)(`div`,{className:`text-xs text-bambu-gray flex items-center gap-1 mt-0.5`,title:e(`fileManager.lastModified`),children:[(0,G.jsx)(rs,{className:`w-3 h-3 flex-shrink-0`}),(0,G.jsx)(`span`,{className:`truncate`,children:ip(t.fs_modified_at??t.created_at)})]})]})]}),o&&(0,G.jsx)(`div`,{className:`text-sm text-bambu-gray flex items-center gap-1`,children:t.created_by_username?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Hu,{className:`w-3 h-3`}),(0,G.jsx)(`span`,{className:`truncate`,children:t.created_by_username})]}):`-`}),(0,G.jsx)(`div`,{children:(0,G.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded font-medium ${t.file_type===`3mf`?`bg-bambu-green/20 text-bambu-green`:t.file_type===`gcode`||t.file_type===`gcode.3mf`?`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`:t.file_type===`stl`?`bg-purple-100 dark:bg-purple-500/20 text-purple-700 dark:text-purple-400`:`bg-bambu-gray/20 text-bambu-gray`}`,children:t.file_type.toUpperCase()})}),(0,G.jsx)(`div`,{className:`text-sm text-bambu-gray`,children:Gd(t.file_size)}),(0,G.jsx)(`div`,{className:`text-sm text-bambu-gray`,children:t.print_count>0?`${t.print_count}x`:`-`}),(0,G.jsx)(`div`,{className:`min-w-0`,onClick:e=>e.stopPropagation(),children:!t.tags||t.tags.length===0?(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray/50`,children:`-`}):(0,G.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:t.tags.map(e=>(0,G.jsxs)(`button`,{type:`button`,onClick:()=>qe(e.id),className:`inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded-full text-[10px] bg-bambu-green/10 text-bambu-green hover:bg-bambu-green/20 transition-colors max-w-full`,title:e.name,children:[(0,G.jsx)(Eu,{className:`w-2.5 h-2.5 flex-shrink-0`}),(0,G.jsx)(`span`,{className:`truncate`,children:e.name})]},e.id))})}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,onClick:e=>e.stopPropagation(),children:[M5(t)&&(0,G.jsx)(G.Fragment,{children:(0,G.jsx)(`button`,{onClick:()=>r(`queue:create`)&&B(t),className:`p-1.5 rounded transition-colors ${r(`queue:create`)?`hover:bg-bambu-dark text-bambu-gray hover:text-bambu-green`:`text-bambu-gray/50 cursor-not-allowed`}`,title:r(`queue:create`)?e(`common.print`):e(`fileManager.noPermissionAddToQueue`),disabled:!r(`queue:create`),children:(0,G.jsx)(Rl,{className:`w-4 h-4`})})}),N5(t,!!Fe?.use_slicer_api,Ie)&&(0,G.jsx)(`button`,{onClick:()=>{Re()&&(Fe?.use_slicer_api?ee:Le)(t)},className:`p-1.5 rounded transition-colors ${Re()?`hover:bg-bambu-dark text-bambu-gray hover:text-bambu-green`:`text-bambu-gray/50 cursor-not-allowed`}`,title:Re()?e(`slice.action`):Fe?.use_slicer_api?e(`fileManager.noPermissionSlice`):e(`fileManager.noPermissionDownload`),disabled:!Re(),children:Fe?.use_slicer_api?(0,G.jsx)(Rs,{className:`w-4 h-4`}):(0,G.jsx)(rc,{className:`w-4 h-4`})}),(Fe?.use_slicer_api??!1)&&N5(t,!0,Ie)&&(0,G.jsx)(`button`,{onClick:()=>r(`pipelines:run`)&&ne(t),className:`p-1.5 rounded transition-colors ${r(`pipelines:run`)?`hover:bg-bambu-dark text-bambu-gray hover:text-bambu-green`:`text-bambu-gray/50 cursor-not-allowed`}`,title:r(`pipelines:run`)?e(`library.runWithPipeline.actionLabel`,`Run with pipeline`):e(`library.runWithPipeline.noPermission`,`You do not have permission to run pipelines`),disabled:!r(`pipelines:run`),children:(0,G.jsx)(Nl,{className:`w-4 h-4`})}),(t.file_type===`3mf`||t.file_type===`gcode`||t.file_type===`gcode.3mf`||t.file_type===`stl`)&&(0,G.jsx)(`button`,{onClick:()=>{r(`library:read`)&&(M5(t)?c(`/gcode-viewer?library_file=${t.id}`):H(t))},className:`p-1.5 rounded transition-colors ${r(`library:read`)?`hover:bg-bambu-dark text-bambu-gray hover:text-bambu-green`:`text-bambu-gray/50 cursor-not-allowed`}`,title:r(`library:read`)?`3D Preview`:`You do not have permission to preview files`,disabled:!r(`library:read`),children:(0,G.jsx)(Zo,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:()=>r(`library:read`)&&Ct(t.id),className:`p-1.5 rounded transition-colors ${r(`library:read`)?`hover:bg-bambu-dark text-bambu-gray hover:text-white`:`text-bambu-gray/50 cursor-not-allowed`}`,title:r(`library:read`)?e(`common.download`):e(`fileManager.noPermissionDownload`),disabled:!r(`library:read`),children:(0,G.jsx)(Xs,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:()=>a(`library`,`update`,t.created_by_id)&&ie({type:`file`,id:t.id,name:t.filename}),className:`p-1.5 rounded transition-colors ${a(`library`,`update`,t.created_by_id)?`hover:bg-bambu-dark text-bambu-gray hover:text-white`:`text-bambu-gray/50 cursor-not-allowed`}`,title:a(`library`,`update`,t.created_by_id)?e(`common.rename`):e(`fileManager.noPermissionRenameFile`),disabled:!a(`library`,`update`,t.created_by_id),children:(0,G.jsx)(Al,{className:`w-4 h-4`})}),t.file_type===`stl`&&(0,G.jsx)(`button`,{onClick:()=>a(`library`,`update`,t.created_by_id)&&pt.mutate(t.id),className:`p-1.5 rounded transition-colors ${a(`library`,`update`,t.created_by_id)?`hover:bg-bambu-dark text-bambu-gray hover:text-bambu-green`:`text-bambu-gray/50 cursor-not-allowed`}`,title:a(`library`,`update`,t.created_by_id)?e(`fileManager.generateThumbnail`):e(`fileManager.noPermissionGenerateThumbnail`),disabled:pt.isPending||!a(`library`,`update`,t.created_by_id),children:(0,G.jsx)(Hc,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:()=>a(`library`,`delete`,t.created_by_id)&&R({type:`file`,id:t.id}),className:`p-1.5 rounded transition-colors ${a(`library`,`delete`,t.created_by_id)?`hover:bg-bambu-dark text-bambu-gray hover:text-red-700 dark:hover:text-red-400`:`text-bambu-gray/50 cursor-not-allowed`}`,title:a(`library`,`delete`,t.created_by_id)?e(`common.delete`):e(`fileManager.noPermissionDeleteFile`),disabled:!a(`library`,`delete`,t.created_by_id),children:(0,G.jsx)(Pu,{className:`w-4 h-4`})})]})]},t.id))]})})]}),u!==null&&(0,G.jsx)(n$e,{folderId:u})]})]}),g&&(0,G.jsx)(o$e,{parentId:u,onClose:()=>_(!1),onSave:e=>tt.mutate(e),isLoading:tt.isPending,t:e}),v&&(0,G.jsx)(s$e,{onClose:()=>b(!1),onSave:e=>nt.mutate(e),isLoading:nt.isPending,t:e}),x&&ze&&(0,G.jsx)(d$e,{folders:ze,selectedFiles:m,currentFolderId:u,onClose:()=>S(!1),onMove:e=>ct.mutate({fileIds:m,folderId:e}),isLoading:ct.isPending,t:e}),C&&(0,G.jsx)(gU,{folderId:u,onClose:()=>{w(!1),E([])},onUploadComplete:bt,initialFiles:T.length>0?T:void 0}),D&&(0,G.jsx)(a$e,{onClose:()=>O(!1)}),(0,G.jsx)(r$e,{open:k,onClose:()=>A(!1),onPickTag:e=>{N.includes(e)||P(t=>[...t,e])}}),(0,G.jsx)(IKe,{open:j,fileIds:m,onClose:()=>M(!1)}),F&&(0,G.jsx)(f$e,{folder:F,onClose:()=>I(null),onLink:e=>lt.mutate({id:F.id,data:e}),isLoading:lt.isPending,t:e}),L&&(0,G.jsx)(of,{title:L.type===`folder`?e(`fileManager.deleteFolder`):L.type===`bulk`?e(`fileManager.deleteFilesCount`,{count:L.count}):e(`fileManager.deleteFile`),message:L.type===`folder`?e(`fileManager.deleteFolderConfirm`):L.type===`bulk`?e(`fileManager.deleteFilesConfirm`,{count:L.count}):e(`fileManager.deleteFileConfirm`),confirmText:e(`common.delete`),variant:`danger`,isLoading:Tt,loadingText:e(`fileManager.deleting`),onConfirm:wt,onCancel:()=>R(null)}),z&&(!z.variant_group_id||ht!==void 0)&&(0,G.jsx)(zU,{mode:`create`,libraryFileId:gt?.[0]?.id??z.id,variantFiles:gt,archiveName:gt&>.length>1?`${gt[0].filename} ${e(`common.plusNMore`,{count:gt.length-1})}`:z.print_name||z.filename,onClose:()=>B(null),onSuccess:()=>{B(null),h([]),t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`queue`]}),t.invalidateQueries({queryKey:[`archives`]})}}),V&&(0,G.jsx)(RW,{source:{kind:`libraryFile`,id:V.id,filename:V.filename},onClose:()=>ee(null)}),te&&(0,G.jsx)(VW,{source:{kind:`libraryFile`,id:te.id,filename:te.filename},onClose:()=>ne(null)}),se&&(0,G.jsx)(FKe,{libraryFileId:se.id,title:se.print_name||se.filename,fileType:se.file_type,onClose:()=>H(null),onSliceWithBambuddy:N5(se,!0,Ie)&&r(`library:upload`)?()=>{let e=se;H(null),ee(e)}:void 0}),re&&(0,G.jsx)(u$e,{type:re.type,currentName:re.name,onClose:()=>ie(null),onSave:e=>{re.type===`file`?ut.mutate({id:re.id,filename:e}):dt.mutate({id:re.id,name:e})},isLoading:ut.isPending||dt.isPending,t:e})]})}function g$e(e){let t=rp(e);if(!t)return``;let n=Math.ceil((t.getTime()-Date.now())/(1e3*60*60*24));return n<=0?`any moment`:n===1?`1 day`:`${n} days`}function _$e(e){let t=rp(e);return t?t.toLocaleString():e}function v$e(){let{t:e}=U(),t=or(),n=co(),{showToast:r}=qd(),{hasPermission:i,authEnabled:a}=Nd(),[o,s]=(0,y.useState)(null),[c,l]=(0,y.useState)(new Set),u=!a||i(`library:purge`),d=K({queryKey:[`library-trash`],queryFn:()=>Z.listLibraryTrash(200,0)}),f=K({queryKey:[`library-trash-settings`],queryFn:()=>Z.getLibraryTrashSettings(),enabled:u}),[p,m]=(0,y.useState)(null);(0,y.useEffect)(()=>{f.data&&p===null&&m(f.data.retention_days)},[f.data,p]);let h=q({mutationFn:e=>{let t=f.data;return Z.updateLibraryTrashSettings({retention_days:e,auto_purge_enabled:t?.auto_purge_enabled??!1,auto_purge_days:t?.auto_purge_days??90,auto_purge_include_never_printed:t?.auto_purge_include_never_printed??!0})},onSuccess:t=>{r(e(`libraryTrash.toast.retentionSaved`,{days:t.retention_days}),`success`),n.invalidateQueries({queryKey:[`library-trash-settings`]}),n.invalidateQueries({queryKey:[`library-trash`]})},onError:t=>r(t.message||e(`libraryTrash.toast.retentionFailed`),`error`)}),g=q({mutationFn:e=>Z.restoreLibraryTrash(e),onSuccess:()=>{r(e(`libraryTrash.toast.restored`),`success`),n.invalidateQueries({queryKey:[`library-trash`]}),n.invalidateQueries({queryKey:[`library-trash-count`]}),n.invalidateQueries({queryKey:[`library-files`]}),n.invalidateQueries({queryKey:[`library-folders`]})},onError:t=>r(t.message||e(`libraryTrash.toast.restoreFailed`),`error`)}),_=q({mutationFn:e=>Z.hardDeleteLibraryTrash(e),onSuccess:()=>{r(e(`libraryTrash.toast.purged`),`success`),n.invalidateQueries({queryKey:[`library-trash`]}),n.invalidateQueries({queryKey:[`library-trash-count`]})},onError:t=>r(t.message||e(`libraryTrash.toast.purgeFailed`),`error`)}),v=q({mutationFn:()=>Z.emptyLibraryTrash(),onSuccess:t=>{r(e(`libraryTrash.toast.emptied`,{count:t.deleted}),`success`),n.invalidateQueries({queryKey:[`library-trash`]}),n.invalidateQueries({queryKey:[`library-trash-count`]})},onError:t=>r(t.message||e(`libraryTrash.toast.emptyFailed`),`error`)}),b=q({mutationFn:e=>Promise.all(e.map(e=>Z.restoreLibraryTrash(e))),onSuccess:(t,i)=>{r(e(`libraryTrash.toast.bulkRestored`,{count:i.length}),`success`),l(new Set),n.invalidateQueries({queryKey:[`library-trash`]}),n.invalidateQueries({queryKey:[`library-trash-count`]}),n.invalidateQueries({queryKey:[`library-files`]}),n.invalidateQueries({queryKey:[`library-folders`]})},onError:t=>r(t.message||e(`libraryTrash.toast.restoreFailed`),`error`)}),x=q({mutationFn:e=>Promise.all(e.map(e=>Z.hardDeleteLibraryTrash(e))),onSuccess:(t,i)=>{r(e(`libraryTrash.toast.bulkPurged`,{count:i.length}),`success`),l(new Set),n.invalidateQueries({queryKey:[`library-trash`]}),n.invalidateQueries({queryKey:[`library-trash-count`]})},onError:t=>r(t.message||e(`libraryTrash.toast.purgeFailed`),`error`)}),S=(0,y.useMemo)(()=>d.data?.items??[],[d.data?.items]),C=d.data?.retention_days??30,w=(0,y.useMemo)(()=>S.reduce((e,t)=>e+t.file_size,0),[S]),T=S.length>0&&S.every(e=>c.has(e.id)),E=c.size>0&&!T,D=e=>{l(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})};return(0,G.jsxs)(`div`,{className:`p-6 max-w-screen-2xl mx-auto`,children:[(0,G.jsx)(`div`,{className:`flex items-center gap-3 mb-4`,children:(0,G.jsxs)(Ai,{to:`/files`,className:`inline-flex items-center gap-1 text-sm text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-gray-200`,children:[(0,G.jsx)(Lo,{className:`w-4 h-4`}),` `,e(`libraryTrash.backToFiles`)]})}),(0,G.jsxs)(`div`,{className:`flex items-start justify-between mb-6 gap-4 flex-wrap`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h1`,{className:`text-2xl font-bold text-gray-900 dark:text-gray-100`,children:e(`libraryTrash.title`)}),(0,G.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400 mt-1`,children:e(u?`libraryTrash.subtitleAdmin`:`libraryTrash.subtitleUser`,{days:C})})]}),S.length>0&&(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>s({type:`empty`}),className:`text-red-600 dark:text-red-400`,children:[(0,G.jsx)(Pu,{className:`w-4 h-4 mr-1`}),e(`libraryTrash.emptyTrash`)]})]}),u&&f.data&&(0,G.jsxs)(`div`,{className:`mb-4 border border-gray-200 dark:border-gray-700 rounded-lg p-3 flex items-center gap-3 bg-gray-50 dark:bg-gray-800/40`,children:[(0,G.jsx)(`label`,{htmlFor:`retention-days`,className:`text-sm font-medium text-gray-700 dark:text-gray-300`,children:e(`libraryTrash.retentionLabel`)}),(0,G.jsx)(`input`,{id:`retention-days`,type:`number`,min:1,max:365,value:p??f.data.retention_days,onChange:e=>m(Math.max(1,Math.min(365,parseInt(e.target.value||`0`,10)||0))),className:`w-20 rounded border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-800 text-sm px-2 py-1 text-gray-900 dark:text-gray-100`}),(0,G.jsx)(`span`,{className:`text-sm text-gray-600 dark:text-gray-400`,children:e(`libraryTrash.days`)}),(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>p!=null&&h.mutate(p),disabled:h.isPending||p==null||p===f.data.retention_days,className:`ml-auto`,children:[(0,G.jsx)(ql,{className:`w-4 h-4 mr-1`}),e(`common.save`)]})]}),d.isLoading?(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-gray-500 dark:text-gray-400`,children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),` `,e(`libraryTrash.loading`)]}):S.length===0?(0,G.jsx)(`div`,{className:`border border-dashed border-gray-300 dark:border-gray-700 rounded-lg p-12 text-center`,children:(0,G.jsx)(`p`,{className:`text-gray-500 dark:text-gray-400`,children:e(`libraryTrash.empty`)})}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,G.jsx)(`div`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:e(`libraryTrash.summary`,{count:S.length,size:Gd(w)})}),c.size>0&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,G.jsx)(`span`,{className:`text-gray-600 dark:text-gray-400`,children:e(`libraryTrash.selectionCount`,{count:c.size})}),(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>b.mutate(Array.from(c)),disabled:b.isPending,children:[(0,G.jsx)(Wl,{className:`w-4 h-4 mr-1`}),e(`libraryTrash.bulkRestore`)]}),(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>s({type:`bulkDelete`,count:c.size}),disabled:x.isPending,className:`text-red-600 dark:text-red-400`,children:[(0,G.jsx)(Pu,{className:`w-4 h-4 mr-1`}),e(`libraryTrash.bulkPurge`)]})]})]}),(0,G.jsx)(`div`,{className:`border border-gray-200 dark:border-gray-700 rounded-lg overflow-x-auto`,children:(0,G.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,G.jsx)(`thead`,{className:`bg-gray-50 dark:bg-gray-800 text-left text-gray-600 dark:text-gray-300`,children:(0,G.jsxs)(`tr`,{children:[(0,G.jsx)(`th`,{className:`px-3 py-2 w-10`,children:(0,G.jsx)(`input`,{type:`checkbox`,checked:T,ref:e=>{e&&(e.indeterminate=E)},onChange:()=>{l(e=>e.size===S.length?new Set:new Set(S.map(e=>e.id)))},"aria-label":e(`libraryTrash.selectAll`),className:`rounded border-gray-300 cursor-pointer`})}),(0,G.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:e(`libraryTrash.col.filename`)}),(0,G.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:e(`libraryTrash.col.folder`)}),(0,G.jsx)(`th`,{className:`px-3 py-2 font-medium text-right`,children:e(`libraryTrash.col.size`)}),(0,G.jsx)(`th`,{className:`px-3 py-2 font-medium whitespace-nowrap`,children:e(`libraryTrash.col.deleted`)}),(0,G.jsx)(`th`,{className:`px-3 py-2 font-medium whitespace-nowrap`,children:e(`libraryTrash.col.autoPurge`)}),u&&(0,G.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:e(`libraryTrash.col.owner`)}),(0,G.jsx)(`th`,{className:`px-3 py-2 font-medium text-right`,children:e(`libraryTrash.col.actions`)})]})}),(0,G.jsx)(`tbody`,{className:`divide-y divide-gray-100 dark:divide-gray-800`,children:S.map(t=>(0,G.jsxs)(`tr`,{className:`hover:bg-gray-50 dark:hover:bg-gray-800/50`,children:[(0,G.jsx)(`td`,{className:`px-3 py-2`,children:(0,G.jsx)(`input`,{type:`checkbox`,checked:c.has(t.id),onChange:()=>D(t.id),"aria-label":e(`libraryTrash.selectOne`,{filename:t.filename}),className:`rounded border-gray-300 cursor-pointer`})}),(0,G.jsx)(`td`,{className:`px-3 py-2 text-gray-900 dark:text-gray-100 truncate max-w-md`,title:t.filename,children:t.filename}),(0,G.jsx)(`td`,{className:`px-3 py-2 text-gray-600 dark:text-gray-400`,children:t.folder_name??`—`}),(0,G.jsx)(`td`,{className:`px-3 py-2 text-right text-gray-600 dark:text-gray-400 tabular-nums whitespace-nowrap`,children:Gd(t.file_size)}),(0,G.jsx)(`td`,{className:`px-3 py-2 text-gray-600 dark:text-gray-400 whitespace-nowrap`,children:_$e(t.deleted_at)}),(0,G.jsx)(`td`,{className:`px-3 py-2 text-gray-600 dark:text-gray-400 whitespace-nowrap`,children:(0,G.jsx)(`span`,{title:_$e(t.auto_purge_at),children:e(`libraryTrash.autoPurgeIn`,{when:g$e(t.auto_purge_at)})})}),u&&(0,G.jsx)(`td`,{className:`px-3 py-2 text-gray-600 dark:text-gray-400`,children:t.created_by_username??`—`}),(0,G.jsxs)(`td`,{className:`px-3 py-2 text-right whitespace-nowrap`,children:[(0,G.jsxs)(`button`,{onClick:()=>g.mutate(t.id),disabled:g.isPending,className:`inline-flex items-center gap-1 px-2 py-1 text-xs text-blue-600 hover:text-blue-800 dark:text-blue-400 dark:hover:text-blue-300`,children:[(0,G.jsx)(Wl,{className:`w-3.5 h-3.5`}),e(`libraryTrash.restore`)]}),(0,G.jsxs)(`button`,{onClick:()=>s({type:`delete`,id:t.id,filename:t.filename}),disabled:_.isPending,className:`inline-flex items-center gap-1 px-2 py-1 text-xs text-red-600 hover:text-red-800 dark:text-red-400 dark:hover:text-red-300 ml-2`,children:[(0,G.jsx)(Pu,{className:`w-3.5 h-3.5`}),e(`libraryTrash.purgeNow`)]})]})]},t.id))})]})})]}),o&&(0,G.jsx)(of,{onCancel:()=>s(null),onConfirm:()=>{o&&(o.type===`delete`?_.mutate(o.id):o.type===`bulkDelete`?x.mutate(Array.from(c)):v.mutate(),s(null))},title:o.type===`delete`?e(`libraryTrash.confirm.purgeTitle`):o.type===`bulkDelete`?e(`libraryTrash.confirm.bulkPurgeTitle`):e(`libraryTrash.confirm.emptyTitle`),message:o.type===`delete`?e(`libraryTrash.confirm.purgeBody`,{filename:o.filename}):o.type===`bulkDelete`?e(`libraryTrash.confirm.bulkPurgeBody`,{count:o.count}):e(`libraryTrash.confirm.emptyBody`,{count:S.length}),confirmText:e(`libraryTrash.confirm.cta`),variant:`danger`}),d.isError&&(0,G.jsxs)(`div`,{className:`mt-4 text-sm text-red-600 dark:text-red-400`,children:[d.error?.message??e(`libraryTrash.loadError`),(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>t(`/files`),className:`ml-3`,children:e(`libraryTrash.backToFiles`)})]})]})}function y$e(e){return e.includes(`/camera/`)}function b$e(e,t,n){let r=0;return e.querySelectorAll(`img[src*="/api/v1/"], video[src*="/api/v1/"]`).forEach(e=>{let i=e.getAttribute(`src`)||``,a=y$e(i)?n:t;if(!a)return;let o=`token=${encodeURIComponent(a)}`;if(i.includes(o))return;let s=i.replace(/([?&])token=[^&]*(&|$)/,(e,t,n)=>n===`&`?t:``);e.src=`${s}${s.includes(`?`)?`&`:`?`}${o}`,r+=1}),r}function x$e(){let{authEnabled:e,user:t,loading:n,hasPermission:r}=Nd(),i=co(),a=(0,y.useRef)(!1),o=!n&&(!e||t!==null),{data:s}=K({queryKey:[`media-token`,t?.id??null],queryFn:()=>Z.getMediaToken(),enabled:o,staleTime:3e3*1e3,refetchInterval:3e3*1e3}),c=!e||r(`camera:view`),{data:l}=K({queryKey:[`camera-stream-token`,t?.id??null],queryFn:()=>Z.getCameraStreamToken(),enabled:o&&c,staleTime:3e3*1e3,refetchInterval:3e3*1e3}),u=s?.token??null,d=l?.token??null;(0,y.useEffect)(()=>(hd(u),pd(d),(u||d)&&b$e(document,u,d),()=>{hd(null),pd(null)}),[u,d]),(0,y.useEffect)(()=>{if(!e)return;let t=e=>{let t=e.target;if(!(t instanceof HTMLImageElement||t instanceof HTMLVideoElement))return;let n=t.src||``,r=y$e(n),o=r?md():gd();!o||!n.includes(`token=${encodeURIComponent(o)}`)||a.current||(a.current=!0,i.invalidateQueries({queryKey:r?[`camera-stream-token`]:[`media-token`]}),setTimeout(()=>{a.current=!1},5e3))};return document.addEventListener(`error`,t,!0),()=>document.removeEventListener(`error`,t,!0)},[e,i])}var a9=5,S$e=2e3,C$e=3e4,w$e=5e3;function T$e(){let{t:e}=U(),t=co(),{showToast:n}=qd(),{hasPermission:r,authEnabled:i,user:a}=Nd(),{printerId:o}=dr(),s=parseInt(o||`0`,10),[c]=Ri(),l=parseInt(c.get(`fps`)||`15`,10),u=Math.min(Math.max(isNaN(l)?15:l,1),30);x$e();let{data:d,isPending:f}=K({queryKey:[`camera-stream-token`,a?.id??null],queryFn:()=>Z.getCameraStreamToken(),enabled:i?!!a:!0,staleTime:3e3*1e3}),p=d?.token??md(),[m,h]=(0,y.useState)(`stream`),[g,_]=(0,y.useState)(!1),[v,b]=(0,y.useState)(!1),[x,S]=(0,y.useState)(!1),[C,w]=(0,y.useState)(!0),[T,E]=(0,y.useState)(Date.now()),[D,O]=(0,y.useState)(!1),[k,A]=(0,y.useState)(!1),[j,M]=(0,y.useState)(0),[N,P]=(0,y.useState)(!1),[F,I]=(0,y.useState)(0),[L,R]=(0,y.useState)(1),[z,B]=(0,y.useState)({x:0,y:0}),[V,ee]=(0,y.useState)(!1),[te,ne]=(0,y.useState)({x:0,y:0}),[re,ie]=(0,y.useState)(null),[ae,oe]=(0,y.useState)(null),se=(0,y.useRef)(null),H=(0,y.useRef)(null),ce=(0,y.useRef)(null),le=(0,y.useRef)(null),ue=(0,y.useRef)(null),de=(0,y.useRef)(0),{data:fe}=K({queryKey:[`printer`,s],queryFn:()=>Z.getPrinter(s),enabled:s>0}),{data:pe}=K({queryKey:[`printerStatus`,s],queryFn:()=>Z.getPrinterStatus(s),refetchInterval:3e4,enabled:s>0}),me=q({mutationFn:e=>Z.setChamberLight(s,e),onMutate:async e=>{await t.cancelQueries({queryKey:[`printerStatus`,s]});let n=t.getQueryData([`printerStatus`,s]);return t.setQueryData([`printerStatus`,s],t=>({...t,chamber_light:e})),{previousStatus:n}},onSuccess:(e,t)=>{n(`Chamber light ${t?`on`:`off`}`)},onError:(r,i,a)=>{a?.previousStatus&&t.setQueryData([`printerStatus`,s],a.previousStatus),n(r.message||e(`printers.toast.failedToControlChamberLight`),`error`)}}),he=(pe?.state===`RUNNING`||pe?.state===`PAUSE`)&&(pe?.printable_objects_count??0)>=2;(0,y.useEffect)(()=>(fe&&(document.title=`${fe.name} - Camera`),()=>{document.title=`Bambuddy`}),[fe]);let ge=(0,y.useRef)(!1);(0,y.useEffect)(()=>{let e=`/api/v1/printers/${s}/camera/stop`;ge.current=!1;let t=()=>{if(s>0&&!ge.current){ge.current=!0;let t={},n=ud();n&&(t.Authorization=`Bearer ${n}`),fetch(e,{method:`POST`,keepalive:!0,headers:t}).catch(()=>{})}},n=()=>{t()};window.addEventListener(`beforeunload`,n);let r=se.current;return()=>{window.removeEventListener(`beforeunload`,n),r&&(r.src=``),t()}},[s]),(0,y.useEffect)(()=>{if(C&&!D){let e=setTimeout(()=>{w(!1)},m===`stream`?3e3:2e4);return()=>clearTimeout(e)}},[m,C,T,D]),(0,y.useEffect)(()=>{let e=()=>{A(!!document.fullscreenElement),R(1),B({x:0,y:0}),m===`stream`&&!D&&(se.current&&(se.current.src=``),setTimeout(()=>{w(!0),E(Date.now())},200))};return document.addEventListener(`fullscreenchange`,e),()=>document.removeEventListener(`fullscreenchange`,e)},[m,D]),(0,y.useEffect)(()=>{let e,t=()=>{clearTimeout(e),e=setTimeout(()=>{localStorage.setItem(`cameraWindowState`,JSON.stringify({width:window.outerWidth,height:window.outerHeight,left:window.screenX,top:window.screenY}))},500)};return window.addEventListener(`resize`,t),()=>{clearTimeout(e),window.removeEventListener(`resize`,t)}},[]),(0,y.useEffect)(()=>()=>{ce.current&&clearTimeout(ce.current),le.current&&clearInterval(le.current),ue.current&&clearInterval(ue.current)},[]);let _e=(0,y.useCallback)(()=>{if(j>=a9){P(!1),S(!0);return}let e=Math.min(S$e*2**j,C$e);P(!0),I(Math.ceil(e/1e3)),le.current=setInterval(()=>{I(e=>e<=1?(le.current&&clearInterval(le.current),0):e-1)},1e3),ce.current=setTimeout(()=>{M(e=>e+1),P(!1),w(!0),S(!1),se.current&&(se.current.src=``),E(Date.now())},e)},[j]);(0,y.useEffect)(()=>{if(m!==`stream`||C||N||D){ue.current&&=(clearInterval(ue.current),null);return}return de.current=0,ue.current=setInterval(async()=>{try{let e=await Z.getCameraStatus(s);if(!(e.stalled||!e.active&&!x)){de.current=0;return}if(de.current+=1,de.current<2)return;de.current=0,console.log(`Stream issue detected: stalled=${e.stalled}, active=${e.active}, reconnecting...`),ue.current&&=(clearInterval(ue.current),null),w(!1),_e()}catch{}},w$e),()=>{ue.current&&=(clearInterval(ue.current),null)}},[m,C,x,N,D,s,_e]);let ve=()=>{w(!1),m===`stream`&&j{if(w(!1),S(!1),M(0),de.current=0,P(!1),ce.current&&clearTimeout(ce.current),le.current&&clearInterval(le.current),se.current&&!localStorage.getItem(`cameraWindowState`)){let e=se.current,t=e.naturalWidth,n=e.naturalHeight;if(t>0&&n>0){let e=window.outerWidth-window.innerWidth,r=window.outerHeight-window.innerHeight,i=t+16+e,a=n+45+16+r;try{window.resizeTo(i,a)}catch{}}}},be=()=>{if(s>0){let e={},t=ud();t&&(e.Authorization=`Bearer ${t}`),fetch(`/api/v1/printers/${s}/camera/stop`,{method:`POST`,headers:e}).catch(()=>{})}},xe=e=>{m===e||D||(O(!0),w(!0),S(!1),M(0),P(!1),R(1),B({x:0,y:0}),ce.current&&clearTimeout(ce.current),le.current&&clearInterval(le.current),se.current&&(se.current.src=``),m===`stream`&&be(),setTimeout(()=>{h(e),E(Date.now()),O(!1)},100))},Se=()=>{D||(O(!0),w(!0),S(!1),M(0),P(!1),ce.current&&clearTimeout(ce.current),le.current&&clearInterval(le.current),se.current&&(se.current.src=``),m===`stream`&&be(),setTimeout(()=>{E(Date.now()),O(!1)},100))},Ce=()=>{H.current&&(document.fullscreenElement?document.exitFullscreen():H.current.requestFullscreen())},we=()=>{R(e=>Math.min(e+.5,4))},Te=()=>{R(e=>{let t=Math.max(e-.5,1);return t===1&&B({x:0,y:0}),t})},Ee=e=>{e.preventDefault(),e.deltaY<0?we():Te()},De=e=>{L>1&&(e.preventDefault(),ee(!0),ne({x:e.clientX-z.x,y:e.clientY-z.y}))},Oe=(0,y.useCallback)(()=>{if(!H.current)return{x:300,y:200};let e=H.current.getBoundingClientRect(),t=e.width*(L-1)/2,n=e.height*(L-1)/2;return{x:Math.max(50,t),y:Math.max(50,n)}},[L]),ke=e=>{if(V&&L>1){let t=e.clientX-te.x,n=e.clientY-te.y,r=Oe();B({x:Math.max(-r.x,Math.min(r.x,t)),y:Math.max(-r.y,Math.min(r.y,n))})}},Ae=()=>{ee(!1)},je=e=>{if(e.length<2)return 0;let t=e[0].clientX-e[1].clientX,n=e[0].clientY-e[1].clientY;return Math.sqrt(t*t+n*n)},Me=e=>e.length<2?{x:e[0].clientX,y:e[0].clientY}:{x:(e[0].clientX+e[1].clientX)/2,y:(e[0].clientY+e[1].clientY)/2},Ne=e=>{e.touches.length===2?(e.preventDefault(),ie(je(e.touches)),oe(Me(e.touches))):e.touches.length===1&&L>1&&(e.preventDefault(),ee(!0),ne({x:e.touches[0].clientX-z.x,y:e.touches[0].clientY-z.y}))},Pe=e=>{if(e.touches.length===2&&re!==null){e.preventDefault();let t=je(e.touches),n=t/re;R(e=>{let t=Math.max(1,Math.min(4,e*n));return t===1&&B({x:0,y:0}),t}),ie(t);let r=Me(e.touches);if(ae){let e=Oe();B(t=>({x:Math.max(-e.x,Math.min(e.x,t.x+(r.x-ae.x))),y:Math.max(-e.y,Math.min(e.y,t.y+(r.y-ae.y)))}))}oe(r)}else if(e.touches.length===1&&V&&L>1){e.preventDefault();let t=e.touches[0].clientX-te.x,n=e.touches[0].clientY-te.y,r=Oe();B({x:Math.max(-r.x,Math.min(r.x,t)),y:Math.max(-r.y,Math.min(r.y,n))})}},Fe=e=>{e.touches.length<2&&(ie(null),oe(null)),e.touches.length===0&&ee(!1)},Ie=()=>{R(1),B({x:0,y:0})},Le=D||!p&&(i||f)?``:(e=>p?`${e}&token=${encodeURIComponent(p)}`:_d(e))(m===`stream`?`/api/v1/printers/${s}/camera/stream?fps=${u}&t=${T}`:`/api/v1/printers/${s}/camera/snapshot?t=${T}`),Re=C||D||N;return s?(0,G.jsxs)(`div`,{ref:H,className:`min-h-screen bg-black flex flex-col`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2 bg-bambu-dark-secondary border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`h1`,{className:`text-sm font-medium text-white flex items-center gap-2`,children:[(0,G.jsx)(ss,{className:`w-4 h-4`}),fe?.name||`Printer ${s}`]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`div`,{className:`flex bg-bambu-dark rounded p-0.5`,children:[(0,G.jsx)(`button`,{onClick:()=>xe(`stream`),disabled:Re,className:`px-3 py-1 text-xs rounded transition-colors ${m===`stream`?`bg-bambu-green text-white`:`text-bambu-gray hover:text-white disabled:opacity-50`}`,children:e(`camera.live`)}),(0,G.jsx)(`button`,{onClick:()=>xe(`snapshot`),disabled:Re,className:`px-3 py-1 text-xs rounded transition-colors ${m===`snapshot`?`bg-bambu-green text-white`:`text-bambu-gray hover:text-white disabled:opacity-50`}`,children:e(`camera.snapshot`)})]}),(0,G.jsx)(`button`,{onClick:()=>me.mutate(!pe?.chamber_light),disabled:!pe?.connected||me.isPending||!r(`printers:control`),className:`p-1.5 rounded disabled:opacity-50 ${pe?.chamber_light?`bg-yellow-500/20 hover:bg-yellow-500/30`:`hover:bg-bambu-dark-tertiary`}`,title:r(`printers:control`)?e(`camera.chamberLight`):e(`printers.permission.noControl`),children:(0,G.jsx)(vT,{on:pe?.chamber_light??!1,className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:()=>_(!0),disabled:!he||!r(`printers:control`),className:`p-1.5 rounded disabled:opacity-50 ${he&&r(`printers:control`)?`hover:bg-bambu-dark-tertiary`:``}`,title:r(`printers:control`)?e(he?`printers.skipObjects.tooltip`:`printers.skipObjects.onlyWhilePrinting`):e(`printers.permission.noControl`),children:(0,G.jsx)(yT,{className:`w-4 h-4 text-bambu-gray`})}),(0,G.jsx)(`button`,{onClick:Se,disabled:Re,className:`p-1.5 hover:bg-bambu-dark-tertiary rounded disabled:opacity-50`,title:e(m===`stream`?`camera.restartStream`:`camera.refreshSnapshot`),children:(0,G.jsx)(Hl,{className:`w-4 h-4 text-bambu-gray ${Re?`animate-spin`:``}`})}),(0,G.jsx)(`button`,{onClick:()=>b(!0),className:`p-1.5 hover:bg-bambu-dark-tertiary rounded`,title:e(`camera.diagnose.button`),children:(0,G.jsx)(Su,{className:`w-4 h-4 text-bambu-gray`})}),(0,G.jsx)(`button`,{onClick:Ce,className:`p-1.5 hover:bg-bambu-dark-tertiary rounded`,title:e(k?`camera.exitFullscreen`:`camera.fullscreen`),children:k?(0,G.jsx)(pl,{className:`w-4 h-4 text-bambu-gray`}):(0,G.jsx)(ll,{className:`w-4 h-4 text-bambu-gray`})})]})]}),(0,G.jsx)(`div`,{className:`flex-1 flex items-center justify-center p-2 overflow-hidden`,onWheel:Ee,onMouseMove:ke,onMouseUp:Ae,onMouseLeave:Ae,onTouchStart:Ne,onTouchMove:Pe,onTouchEnd:Fe,style:{touchAction:`none`},children:(0,G.jsxs)(`div`,{className:`relative w-full h-full flex items-center justify-center`,children:[(C||D)&&!N&&(0,G.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-black/50 z-10`,children:(0,G.jsxs)(`div`,{className:`text-center`,children:[(0,G.jsx)(Hl,{className:`w-8 h-8 text-bambu-gray animate-spin mx-auto mb-2`}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(m===`stream`?`camera.connectingToCamera`:`camera.capturingSnapshot`)})]})}),N&&(0,G.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-black/80 z-10`,children:(0,G.jsxs)(`div`,{className:`text-center p-4`,children:[(0,G.jsx)(Zu,{className:`w-10 h-10 text-orange-400 mx-auto mb-3`}),(0,G.jsx)(`p`,{className:`text-white mb-2`,children:e(`camera.connectionLost`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mb-3`,children:e(`camera.reconnecting`,{countdown:F,attempt:Math.min(j+1,a9),max:a9})}),(0,G.jsx)(`button`,{onClick:Se,className:`px-4 py-2 bg-bambu-green text-white text-sm rounded hover:bg-bambu-green/80 transition-colors`,children:e(`camera.reconnectNow`)})]})}),x&&!N&&(0,G.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-black z-10`,children:(0,G.jsxs)(`div`,{className:`text-center p-4`,children:[(0,G.jsx)(Lu,{className:`w-12 h-12 text-orange-400 mx-auto mb-3`}),(0,G.jsx)(`p`,{className:`text-white mb-2`,children:e(`camera.cameraUnavailable`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mb-4 max-w-md`,children:e(`camera.cameraUnavailableDesc`)}),(0,G.jsxs)(`div`,{className:`flex gap-2 justify-center`,children:[(0,G.jsx)(`button`,{onClick:Se,className:`px-4 py-2 bg-bambu-green text-white rounded hover:bg-bambu-green/80 transition-colors`,children:e(`camera.retry`)}),(0,G.jsx)(`button`,{onClick:()=>b(!0),className:`px-4 py-2 bg-bambu-dark border border-bambu-dark-tertiary text-bambu-gray hover:text-white rounded transition-colors`,children:e(`camera.diagnose.button`)})]})]})}),(0,G.jsx)(`img`,{ref:se,src:Le,alt:e(`camera.cameraStream`),className:`max-w-full max-h-full object-contain select-none`,style:{transform:`scale(${L}) translate(${z.x/L}px, ${z.y/L}px) rotate(${fe?.camera_rotation||0}deg)`,...fe?.camera_rotation===90||fe?.camera_rotation===270?{maxWidth:`100vh`,maxHeight:`100vw`}:{},cursor:L>1?V?`grabbing`:`grab`:`default`},onError:Le?ve:void 0,onLoad:Le?ye:void 0,onMouseDown:De,draggable:!1},T),(0,G.jsxs)(`div`,{className:`absolute bottom-4 left-4 flex items-center gap-1.5 bg-black/60 rounded-lg px-2 py-1.5`,children:[(0,G.jsx)(`button`,{onClick:Te,disabled:L<=1,className:`p-1.5 hover:bg-white/10 rounded disabled:opacity-30`,title:e(`camera.zoomOut`),children:(0,G.jsx)(ad,{className:`w-4 h-4 text-white`})}),(0,G.jsxs)(`button`,{onClick:Ie,className:`px-2 py-1 text-sm text-white hover:bg-white/10 rounded min-w-[48px]`,title:e(`camera.resetZoom`),children:[Math.round(L*100),`%`]}),(0,G.jsx)(`button`,{onClick:we,disabled:L>=4,className:`p-1.5 hover:bg-white/10 rounded disabled:opacity-30`,title:e(`camera.zoomIn`),children:(0,G.jsx)(rd,{className:`w-4 h-4 text-white`})})]})]})}),(0,G.jsx)(bT,{printerId:s,isOpen:g,onClose:()=>_(!1)}),v&&(0,G.jsx)(xT,{printerId:s,printerName:fe?.name||null,onClose:()=>b(!1)})]}):(0,G.jsx)(`div`,{className:`min-h-screen bg-black flex items-center justify-center`,children:(0,G.jsx)(`p`,{className:`text-white`,children:e(`camera.invalidPrinterId`)})})}var E$e=5e3,D$e=4,O$e=8,k$e=1,A$e=16,j$e=2,M$e=60;function N$e(e,t,n,r){let i=parseInt(e??``,10);return Number.isFinite(i)?Math.min(r,Math.max(n,i)):t}function P$e(e,t,n,r,i,a){return e.has(t)?N$e(e.get(t),r,i,a):N$e(localStorage.getItem(n),r,i,a)}function F$e(){let{t:e}=U(),t=rr(),{authEnabled:n,loading:r,user:i}=Nd(),[a]=Ri(),o=a.get(`token`),s=o!=null&&o!==``,[c,l]=(0,y.useState)(()=>P$e(a,`maxLive`,`camWallMaxLive`,D$e,k$e,A$e)),[u,d]=(0,y.useState)(()=>P$e(a,`interval`,`camWallSnapshotSec`,O$e,j$e,M$e)),[f,p]=(0,y.useState)(()=>{let e=a.get(`status`)??localStorage.getItem(`camWallStatusMode`);return(s?[`off`,`compact`]:[`off`,`compact`,`full`]).includes(e)?e:`compact`});(0,y.useEffect)(()=>{if(s)return pd(o),()=>pd(null)},[s,o]);let m=K({queryKey:[`camwall-printers`,o],queryFn:()=>Z.getCamWallPrinters(o??void 0),enabled:s,refetchInterval:E$e}),h=K({queryKey:[`printers`],queryFn:()=>Z.getPrinters(),enabled:!s&&!r&&(!n||i!==null),refetchInterval:E$e}),g=(0,y.useMemo)(()=>{let e=new Map;for(let t of m.data??[])e.set(t.id,{connected:t.connected,state:t.state,progress:t.progress,remaining_time:t.remaining_time,layer_num:t.layer_num,total_layers:t.total_layers,hms_errors:t.hms_errors});return e},[m.data]);if(!s&&r)return(0,G.jsx)(`div`,{className:`flex min-h-screen items-center justify-center bg-bambu-dark text-bambu-gray`,children:e(`common.loading`)});if(!s&&n&&!i)return(0,G.jsx)(Fr,{to:`/login`,replace:!0,state:{from:t}});let _=s?m:h,v=s?m.data??[]:h.data??[];return _.isError?(0,G.jsx)(`div`,{className:`flex min-h-screen items-center justify-center bg-bambu-dark p-6 text-center`,children:(0,G.jsx)(`p`,{className:`max-w-md text-sm text-red-400`,children:e(s?`printers.camWall.page.tokenRejected`:`printers.camWall.page.loadFailed`)})}):(0,G.jsx)(`div`,{className:`min-h-screen bg-bambu-dark p-4`,children:(0,G.jsx)(OT,{printers:v,maxLive:c,snapshotIntervalSec:u,statusMode:f,statuses:s?g:void 0,showSettings:!s,onTileClick:s?void 0:e=>window.open(`/camera/${e}`,`camera-${e}`),onChangeMaxLive:e=>{l(e),localStorage.setItem(`camWallMaxLive`,String(e))},onChangeSnapshotIntervalSec:e=>{d(e),localStorage.setItem(`camWallSnapshotSec`,String(e))},onChangeStatusMode:e=>{p(e),localStorage.setItem(`camWallStatusMode`,e)}})})}function I$e(e,t,n){if(!e)return``;if(!t)return e;let r=t.match(/plate_(\d+)\.gcode/);return r&&parseInt(r[1],10)>1?`${e} — ${n(`printers.plateNumber`,`Plate {{number}}`,{number:r[1]})}`:e}function L$e(e){let t=e.get(`show`)?.split(`,`)||[`progress`,`layers`,`eta`,`filename`,`status`],n=parseInt(e.get(`fps`)||`15`,10),r=Math.min(Math.max(isNaN(n)?15:n,1),30),i=e.get(`camera`),a=i!==`false`&&i!==`0`;return{size:e.get(`size`)||`medium`,fps:r,showCamera:a,showProgress:t.includes(`progress`),showLayers:t.includes(`layers`),showEta:t.includes(`eta`),showFilename:t.includes(`filename`),showStatus:t.includes(`status`),showPrinter:t.includes(`printer`),showNozzle:t.includes(`nozzle`),showBed:t.includes(`bed`),showChamber:t.includes(`chamber`)}}function R$e(e,t){if(e.stg_cur_name)return e.stg_cur_name;switch(e.state){case`RUNNING`:return t(`streamOverlay.status.printing`);case`PAUSE`:return t(`streamOverlay.status.paused`);case`FINISH`:return t(`streamOverlay.status.finished`);case`FAILED`:return t(`streamOverlay.status.failed`);case`IDLE`:return t(`streamOverlay.status.idle`);default:return e.state||t(`streamOverlay.status.unknown`)}}function o9(e,t){let n=e[t];return typeof n==`number`?n:null}function z$e({icon:e,label:t,current:n,target:r,sizes:i}){let a=r!=null&&r>0&&Math.round(r)!==Math.round(n);return(0,G.jsxs)(`div`,{className:`flex items-center ${i.gap} text-white/70`,children:[e,(0,G.jsxs)(`span`,{className:i.text,children:[(0,G.jsx)(`span`,{className:`mr-1`,children:t}),(0,G.jsxs)(`span`,{className:`text-white`,children:[Math.round(n),`°C`]}),a&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`span`,{className:`mx-1`,children:`/`}),(0,G.jsxs)(`span`,{children:[Math.round(r),`°C`]})]})]})]})}function B$e(e){switch(e){case`small`:return{container:`p-3`,text:`text-sm`,textLarge:`text-lg`,progressHeight:`h-2`,icon:`w-3 h-3`,gap:`gap-2`,logoHeight:`h-12`};case`large`:return{container:`p-6`,text:`text-xl`,textLarge:`text-3xl`,progressHeight:`h-4`,icon:`w-6 h-6`,gap:`gap-4`,logoHeight:`h-24`};default:return{container:`p-4`,text:`text-base`,textLarge:`text-xl`,progressHeight:`h-3`,icon:`w-4 h-4`,gap:`gap-3`,logoHeight:`h-16`}}}function V$e(){let{printerId:e}=dr(),[t]=Ri(),{t:n}=U(),r=co(),i=parseInt(e||`0`,10),[a,o]=(0,y.useState)(Date.now()),s=(0,y.useMemo)(()=>L$e(t),[t]),c=B$e(s.size),l=t.get(`token`),u=l!=null&&l!==``,{data:d}=K({queryKey:[`overlayStatus`,i,l],queryFn:()=>Z.getOverlayStatus(i,l??void 0),enabled:i>0&&u,refetchInterval:2e3}),{data:f}=K({queryKey:[`printer`,i],queryFn:()=>Z.getPrinter(i),enabled:i>0&&!u}),{data:p}=K({queryKey:[`printerStatus`,i],queryFn:()=>Z.getPrinterStatus(i),enabled:i>0&&!u,refetchInterval:2e3}),{data:m}=K({queryKey:[`settings`],queryFn:Z.getSettings,enabled:!u}),h=(0,y.useMemo)(()=>u?d&&{name:d.name,camera_rotation:d.camera_rotation}:f,[u,d,f]),g=u?d:p,_=(u?d?.time_format:m?.time_format)||`system`;(0,y.useEffect)(()=>{if(!i||u)return;let e=null,t=!1;return(async()=>{let n;try{n=(await Z.getWebSocketToken()).token}catch(e){let t=e instanceof sd?e.status:0;if(t===401||t===403)return}if(t)return;let a=window.location.protocol===`https:`?`wss:`:`ws:`,o=n?`?token=${encodeURIComponent(n)}`:``,s=`${a}//${window.location.host}/api/v1/ws${o}`;e=new WebSocket(s),e.onmessage=e=>{try{let t=JSON.parse(e.data);t.type===`printer_status`&&t.printer_id===i&&r.setQueryData([`printerStatus`,i],t.status)}catch{}},e.onerror=()=>{}})(),()=>{t=!0,e&&e.close()}},[i,u,r]),(0,y.useEffect)(()=>(document.title=h?`${h.name} - ${n(`streamOverlay.title`)}`:n(`streamOverlay.title`),()=>{document.title=`Bambuddy`}),[h,n]);let v=()=>{setTimeout(()=>{o(Date.now())},3e3)};if(!i)return(0,G.jsx)(`div`,{className:`min-h-screen bg-black flex items-center justify-center`,children:(0,G.jsx)(`p`,{className:`text-white`,children:n(`streamOverlay.invalidPrinterId`)})});if(!g)return(0,G.jsx)(`div`,{className:`min-h-screen bg-black flex items-center justify-center`,children:(0,G.jsx)(`p`,{className:`text-gray-400`,children:n(`common.loading`)})});let b=g.state===`RUNNING`||g.state===`PAUSE`,x=g.progress||0,S=g.temperatures??{},C=[];if(s.showNozzle){let e=o9(S,`nozzle`),t=o9(S,`nozzle_2`);e!=null&&C.push({key:`nozzle`,icon:(0,G.jsx)(hc,{className:c.icon}),label:n(`printers.heaterHistory.nozzle`,`Nozzle`),current:e,target:o9(S,`nozzle_target`)}),t!=null&&C.push({key:`nozzle_2`,icon:(0,G.jsx)(hc,{className:c.icon}),label:n(`printers.heaterHistory.nozzle2`,`Nozzle 2`),current:t,target:o9(S,`nozzle_2_target`)})}if(s.showBed){let e=o9(S,`bed`);e!=null&&C.push({key:`bed`,icon:(0,G.jsx)(bu,{className:c.icon}),label:n(`printers.heaterHistory.bed`,`Bed`),current:e,target:o9(S,`bed_target`)})}if(s.showChamber){let e=o9(S,`chamber`);e!=null&&C.push({key:`chamber`,icon:(0,G.jsx)(Zo,{className:c.icon}),label:n(`printers.heaterHistory.chamber`,`Chamber`),current:e,target:o9(S,`chamber_target`)})}let w=`/api/v1/printers/${i}/camera/stream?fps=${s.fps}&t=${a}`,T=u&&l?`${w}&token=${encodeURIComponent(l)}`:_d(w);return(0,G.jsxs)(`div`,{className:`min-h-screen bg-black relative overflow-hidden`,children:[s.showCamera&&(0,G.jsx)(`img`,{src:T,alt:n(`streamOverlay.cameraStream`),className:`absolute inset-0 w-full h-full object-contain`,style:h?.camera_rotation?{transform:`rotate(${h.camera_rotation}deg)`}:void 0,onError:v},a),(0,G.jsx)(`a`,{href:`https://github.com/maziggy/bambuddy`,target:`_blank`,rel:`noopener noreferrer`,className:`absolute top-4 right-4 z-10`,children:(0,G.jsx)(`img`,{src:`/img/bambuddy_logo_dark_transparent.png`,alt:`Bambuddy`,className:`${c.logoHeight} object-contain drop-shadow-lg hover:scale-105 transition-transform`})}),(0,G.jsx)(`div`,{className:`absolute bottom-0 left-0 right-0 z-10 bg-gradient-to-t from-black/80 via-black/60 to-transparent`,children:(0,G.jsxs)(`div`,{className:`${c.container}`,children:[s.showPrinter&&h&&(0,G.jsxs)(`div`,{className:`flex items-center ${c.gap} mb-2`,children:[(0,G.jsx)(Rl,{className:`${c.icon} text-white/70`}),(0,G.jsx)(`span`,{className:`${c.text} text-white font-medium`,children:h.name})]}),s.showFilename&&g.current_print&&(0,G.jsx)(`div`,{className:`${c.textLarge} text-white font-semibold mb-2 truncate drop-shadow-md`,children:I$e(g.current_print.replace(/\.gcode\.3mf$|\.3mf$|\.gcode$/i,``),g.gcode_file,n)}),s.showStatus&&(0,G.jsx)(`div`,{className:`${c.text} text-white/70 mb-2`,children:R$e(g,n)}),s.showProgress&&b&&(0,G.jsxs)(`div`,{className:`mb-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-1 ${c.text}`,children:[(0,G.jsx)(`span`,{className:`text-white/70`,children:n(`streamOverlay.progress`)}),(0,G.jsxs)(`span`,{className:`text-white font-bold`,children:[Math.round(x),`%`]})]}),(0,G.jsx)(`div`,{className:`w-full bg-white/20 rounded-full ${c.progressHeight}`,children:(0,G.jsx)(`div`,{className:`bg-bambu-green ${c.progressHeight} rounded-full transition-all duration-500`,style:{width:`${x}%`}})})]}),b&&(s.showLayers||s.showEta)&&(0,G.jsxs)(`div`,{className:`flex items-center ${c.gap} flex-wrap`,children:[s.showLayers&&g.layer_num!=null&&g.total_layers!=null&&g.total_layers>0&&(0,G.jsxs)(`div`,{className:`flex items-center ${c.gap} text-white/70`,children:[(0,G.jsx)(Jc,{className:c.icon}),(0,G.jsxs)(`span`,{className:c.text,children:[(0,G.jsx)(`span`,{className:`text-white`,children:g.layer_num}),(0,G.jsx)(`span`,{className:`mx-1`,children:`/`}),(0,G.jsx)(`span`,{children:g.total_layers})]})]}),s.showEta&&g.remaining_time!=null&&g.remaining_time>0&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`flex items-center ${c.gap} text-white/70`,children:[(0,G.jsx)(Nu,{className:c.icon}),(0,G.jsx)(`span`,{className:`${c.text} text-white`,children:lp(g.remaining_time*60)})]}),(0,G.jsxs)(`div`,{className:`flex items-center ${c.gap} text-white/70`,children:[(0,G.jsx)(js,{className:c.icon}),(0,G.jsxs)(`span`,{className:`${c.text} text-white`,children:[n(`streamOverlay.eta`),` `,cp(g.remaining_time,_,n)]})]})]})]}),!b&&(0,G.jsx)(`div`,{className:`${c.text} text-white/70 py-2`,children:g.connected?n(`streamOverlay.printerIdle`):n(`streamOverlay.printerOffline`)}),C.length>0&&(0,G.jsx)(`div`,{className:`flex items-center ${c.gap} flex-wrap mt-2`,children:C.map(e=>(0,G.jsx)(z$e,{icon:e.icon,label:e.label,current:e.current,target:e.target,sizes:c},e.key))})]})})]})}function H$e(){let{t:e}=U(),{id:t}=dr(),{mode:n}=Id(),{data:r,isLoading:i,error:a}=K({queryKey:[`external-link`,t],queryFn:()=>Z.getExternalLink(Number(t)),enabled:!!t});return i?(0,G.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,G.jsx)(Y,{className:`w-8 h-8 text-bambu-green animate-spin`})}):a||!r?(0,G.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-4 text-bambu-gray`,children:[(0,G.jsx)(Lu,{className:`w-12 h-12`}),(0,G.jsx)(`p`,{children:e(`common.linkNotFound`)})]}):(0,G.jsx)(`iframe`,{src:r.url,className:`h-full w-full border-0`,style:{colorScheme:n},title:r.name,sandbox:`allow-scripts allow-same-origin allow-forms allow-popups allow-popups-to-escape-sandbox`})}function U$e(){let{id:e}=dr(),t=or(),n=co(),{t:r}=U(),{showToast:i}=qd(),a=!!e,[o,s]=(0,y.useState)(``),[c,l]=(0,y.useState)(``),[u,d]=(0,y.useState)([]),[f,p]=(0,y.useState)(``),[m,h]=(0,y.useState)(!1),{data:g,isLoading:_}=K({queryKey:[`group`,e],queryFn:()=>Z.getGroup(Number(e)),enabled:a}),{data:v,isLoading:b}=K({queryKey:[`permissions`],queryFn:()=>Z.getPermissions()});a&&g&&!m&&(s(g.name),l(g.description||``),d(g.permissions),h(!0));let x=q({mutationFn:e=>Z.createGroup(e),onSuccess:()=>{n.invalidateQueries({queryKey:[`groups`]}),n.invalidateQueries({queryKey:[`group`]}),i(r(`groups.toast.created`)),t(`/settings?tab=users`)},onError:e=>{i(e.message,`error`)}}),S=q({mutationFn:t=>Z.updateGroup(Number(e),t),onSuccess:a=>{n.invalidateQueries({queryKey:[`groups`]}),a&&n.setQueryData([`group`,e],a),i(r(`groups.toast.updated`)),t(`/settings?tab=users`)},onError:e=>{i(e.message,`error`)}}),C=x.isPending||S.isPending,w=()=>{if(!o.trim()){i(r(`groups.toast.enterGroupName`),`error`);return}a?S.mutate({name:o===g?.name?void 0:o,description:c,permissions:u}):x.mutate({name:o,description:c||void 0,permissions:u})},T=e=>{d(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},E=(e,t)=>{let n=e.permissions.map(e=>e.value);d(e=>{let r=e.filter(e=>!n.includes(e));return t?[...r,...n]:r})},D=e=>e.permissions.every(e=>u.includes(e.value)),O=e=>{let t=e.permissions.filter(e=>u.includes(e.value)).length;return t>0&&t{v&&d(v.all_permissions)},A=()=>{d([])},j=f.toLowerCase(),M=(0,y.useMemo)(()=>v?j?v.categories.map(e=>({...e,permissions:e.permissions.filter(e=>e.label.toLowerCase().includes(j))})).filter(e=>e.permissions.length>0):v.categories:[],[v,j]),N=v?.all_permissions.length??0;return _||b?(0,G.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,G.jsx)(Y,{className:`w-8 h-8 text-bambu-green animate-spin`})}):(0,G.jsxs)(`div`,{className:`space-y-6 max-w-5xl mx-auto`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`button`,{onClick:()=>t(`/settings?tab=users`),className:`p-2 rounded-lg hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white transition-colors`,children:(0,G.jsx)(Lo,{className:`w-5 h-5`})}),(0,G.jsx)(`h1`,{className:`text-xl font-bold text-white`,children:r(a?`groups.editor.title`:`groups.editor.createTitle`)})]}),a&&g?.is_system&&(0,G.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-3 rounded-lg bg-yellow-50 dark:bg-yellow-500/10 border border-yellow-300 dark:border-yellow-500/20 text-yellow-700 dark:text-yellow-400 text-sm`,children:[(0,G.jsx)(Lu,{className:`w-4 h-4 shrink-0`}),r(`groups.form.systemGroupWarning`)]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:r(`groups.form.groupName`)}),(0,G.jsx)(`input`,{type:`text`,value:o,onChange:e=>s(e.target.value),disabled:a&&g?.is_system,className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors disabled:opacity-50`,placeholder:r(`groups.form.groupNamePlaceholder`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:r(`groups.form.description`)}),(0,G.jsx)(`input`,{type:`text`,value:c,onChange:e=>l(e.target.value),className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:r(`groups.form.descriptionPlaceholder`)})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between flex-wrap gap-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[r(`groups.editor.permissionsSelected`,{count:u.length}),` / `,N]}),(0,G.jsx)(Q,{size:`sm`,variant:`ghost`,onClick:k,children:r(`groups.editor.selectAll`)}),(0,G.jsx)(Q,{size:`sm`,variant:`ghost`,onClick:A,children:r(`groups.editor.clearAll`)})]}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(Ql,{className:`w-4 h-4 absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray`}),(0,G.jsx)(`input`,{type:`text`,value:f,onChange:e=>p(e.target.value),placeholder:r(`groups.editor.search`),className:`pl-9 pr-4 py-2 text-sm bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors w-64`})]})]}),M.length===0?(0,G.jsx)(`div`,{className:`text-center py-12 text-bambu-gray`,children:r(`groups.editor.noResults`)}):(0,G.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:M.map(e=>{let t=v.categories.find(t=>t.name===e.name),n=t.permissions.filter(e=>u.includes(e.value)).length,i=t.permissions.length,a=D(t),o=O(t);return(0,G.jsxs)(zd,{children:[(0,G.jsxs)(`div`,{className:`sticky top-0 z-10 flex items-center justify-between px-4 py-3 bg-bambu-dark-secondary border-b border-bambu-dark-tertiary rounded-t-xl`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsxs)(`button`,{type:`button`,onClick:()=>E(t,!a),className:`w-5 h-5 rounded border flex items-center justify-center transition-colors shrink-0 ${a?`bg-bambu-green border-bambu-green`:o?`bg-bambu-green/50 border-bambu-green`:`border-bambu-gray hover:border-white`}`,children:[a&&(0,G.jsx)(fs,{className:`w-3 h-3 text-white`}),o&&!a&&(0,G.jsx)(ml,{className:`w-3 h-3 text-white`})]}),(0,G.jsx)(su,{className:`w-4 h-4 text-bambu-gray shrink-0`}),(0,G.jsx)(`span`,{className:`text-white font-medium text-sm`,children:e.name})]}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray tabular-nums`,children:[n,`/`,i]})]}),(0,G.jsx)(`div`,{className:`p-3 space-y-1`,children:e.permissions.map(e=>(0,G.jsxs)(`label`,{className:`flex items-center gap-3 px-2 py-1.5 rounded hover:bg-bambu-dark-secondary cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:u.includes(e.value),onChange:()=>T(e.value),className:`w-4 h-4 shrink-0 rounded border-bambu-gray text-bambu-green focus:ring-bambu-green focus:ring-offset-0 bg-bambu-dark-secondary`}),(0,G.jsxs)(`span`,{className:`flex flex-col`,children:[(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.label}),e.value===`websocket:connect`&&(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray/60`,children:r(`groups.editor.websocketHint`)})]})]},e.value))})]},e.name)})}),(0,G.jsx)(`div`,{className:`h-16`}),(0,G.jsxs)(`div`,{className:`fixed bottom-0 left-0 right-0 z-20 px-6 py-3 bg-bambu-dark-secondary border-t border-bambu-dark-tertiary flex items-center justify-center gap-3`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>t(`/settings?tab=users`),children:r(`common.cancel`)}),(0,G.jsx)(Q,{onClick:w,disabled:C||!o.trim(),children:C?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),r(`common.saving`)]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(ql,{className:`w-4 h-4`}),r(`common.save`)]})})]})]})}var W$e=1.65,G$e=[`#1DB954`,`#3B82F6`,`#F59E0B`,`#EF4444`,`#8B5CF6`];function s9(e,t,n,r){return`${e}||${t??``}||${n??``}||${r??``}`}function c9(e,t){let n=new Date(e);return n.setDate(n.getDate()+Math.round(t)),n}function l9(e){return e.toLocaleDateString(void 0,{month:`short`,day:`numeric`,year:`numeric`})}function u9(e){return e.toLocaleDateString(void 0,{month:`short`,day:`numeric`})}function K$e(e){if(e.length<2)return null;let t=new Map;for(let n of e){let e=n.created_at.slice(0,10);t.set(e,(t.get(e)??0)+n.weight_used)}if(t.size<2)return null;let n=[...t.entries()].map(([e,t])=>({ms:new Date(e).getTime(),totalG:t})).sort((e,t)=>e.ms-t.ms),r=Date.now(),i=Math.LN2/30,a=[];for(let e=1;ee+t.weight,0);if(o===0)return null;let s=a.reduce((e,t)=>e+t.rate*t.weight,0)/o,c=a.reduce((e,t)=>e+t.weight*(t.rate-s)**2,0)/o;return{rate:s,stdDev:Math.sqrt(c)}}function q$e(e){let t=e.reduce((e,t)=>e+Math.max(0,t.weight_used-(t.weight_used_baseline??0)),0);if(t===0)return null;let n=Date.now(),r=(n-e.reduce((e,t)=>{let n=new Date(t.created_at).getTime();return nZ.getAllUsageHistory(5e3),staleTime:6e4,enabled:o}),{data:O=[]}=K({queryKey:[`shopping-list`],queryFn:Z.getShoppingList,staleTime:3e4,enabled:o}),k=T?.forecast_global_lead_time_days??0,A=(0,y.useMemo)(()=>{let e=new Map;for(let t of E)e.set(s9(t.material,t.subtype,t.brand,t.color_name),t);return e},[E]),j=(0,y.useMemo)(()=>{let e=new Map;for(let t of D){let n=e.get(t.spool_id)??[];n.push(t),e.set(t.spool_id,n)}return e},[D]),M=(0,y.useMemo)(()=>{let t=new Map;for(let n of e){if(n.archived_at)continue;let e=s9(n.material,n.subtype,n.brand,n.color_name),r=t.get(e)??{key:e,material:n.material,subtype:n.subtype,brand:n.brand,colorName:n.color_name,spools:[]};r.spools.push(n),t.set(e,r)}return[...t.values()]},[e]),N=(0,y.useMemo)(()=>{let e=new Date;return e.setHours(0,0,0,0),M.map(t=>{let n=A.get(t.key)??(t.colorName===null?null:A.get(s9(t.material,t.subtype,t.brand,null))??null),r=n?.lead_time_days??0,i=Math.max(k,r),a=n?.safety_margin_value??14,o=n?.safety_margin_unit??`days`,s=t.spools.reduce((e,t)=>e+Math.max(0,t.label_weight-t.weight_used),0),c=t.spools.reduce((e,t)=>e+t.label_weight,0),l=t.spools.reduce((e,t)=>e+Math.max(0,t.weight_used-(t.weight_used_baseline??0)),0),u=[];for(let e of t.spools)(e.weight_used_baseline??0)===0&&u.push(...j.get(e.id)??[]);let d=null,f=null,p=`none`,m=K$e(u);if(m!==null)d=m.rate,f=m.stdDev,p=`history`;else{let e=q$e(t.spools);e!==null&&(d=e,p=`delta`)}let h=W$e*(f??(d===null?0:d*.2))*Math.sqrt(i)+(o===`g`?a:d===null?a*5:d*a),g=d===null?0:d*i+h,_=d&&d>0?Math.floor(s/d):null,v=_===null?null:c9(e,_),y=d&&d>0?Math.floor((s-g)/d):null,b=y===null?null:c9(e,Math.max(0,y)),x=_!==null&&i>0&&_<=i,S=!x&&y!==null&&y<=0;return{group:t,settings:n,totalRemainingG:s,totalLabelG:c,totalSpools:t.spools.length,totalUsedG:l,dailyRateG:d,dailyRateStdDev:f,rateTier:p,effectiveLeadTimeDays:i,safetyStockG:h,reorderPointG:g,daysRemaining:_,daysUntilROP:y,projectedEmptyDate:v,reorderTriggerDate:b,reorderAlert:S,stockBreakAlert:x}})},[M,A,j,k]),P=(0,y.useMemo)(()=>[...new Set(M.map(e=>e.material))].sort(),[M]),F=(0,y.useMemo)(()=>[...new Set(M.map(e=>e.brand).filter(Boolean))].sort(),[M]),I=(0,y.useMemo)(()=>{let e=[...N];return m&&(e=e.filter(e=>e.group.material===m)),g&&(e=e.filter(e=>e.group.brand===g)),e.sort((e,t)=>{let n=0,r=0;switch(u){case`material`:n=[e.group.material,e.group.subtype??``,e.group.brand??``].join(` `).toLowerCase(),r=[t.group.material,t.group.subtype??``,t.group.brand??``].join(` `).toLowerCase();break;case`used`:n=e.totalUsedG,r=t.totalUsedG;break;case`days_left`:n=e.daysRemaining??999999,r=t.daysRemaining??999999;break;case`stock`:n=e.totalRemainingG,r=t.totalRemainingG;break}let i=nr);return f===`asc`?i:-i}),e},[N,u,f,m,g]),L=(0,y.useMemo)(()=>N.filter(e=>!e.settings?.alerts_snoozed&&(e.stockBreakAlert||e.reorderAlert)),[N]),R=(0,y.useMemo)(()=>[...N].filter(e=>e.dailyRateG!==null).sort((e,t)=>t.totalUsedG-e.totalUsedG).slice(0,5),[N]);if(!o)return(0,G.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-16 text-bambu-gray gap-3`,children:[(0,G.jsx)(nl,{className:`w-8 h-8 opacity-40`}),(0,G.jsx)(`p`,{className:`text-sm`,children:r(`forecast.noReadAccess`)})]});function z(e){u===e?p(e=>e===`asc`?`desc`:`asc`):(d(e),p(e===`days_left`?`asc`:`desc`))}let B=O.length>0?O.length:null;return(0,G.jsxs)(`div`,{className:`space-y-5`,children:[(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[L.length>0&&(0,G.jsxs)(`button`,{onClick:()=>l(e=>!e),className:`flex items-center gap-2 px-3 py-1.5 rounded-lg border text-sm font-medium transition-colors ${L.some(e=>e.stockBreakAlert)?`bg-red-100 dark:bg-red-500/15 border-red-300 dark:border-red-500/30 text-red-700 dark:text-red-300 hover:bg-red-200 dark:hover:bg-red-500/25`:`bg-yellow-100 dark:bg-yellow-500/15 border-yellow-300 dark:border-yellow-500/30 text-yellow-700 dark:text-yellow-300 hover:bg-yellow-200 dark:hover:bg-yellow-500/25`}`,children:[(0,G.jsx)(Lu,{className:`w-4 h-4`}),r(`forecast.alertCount`,{count:L.length}),c?(0,G.jsx)(gs,{className:`w-3.5 h-3.5`}):(0,G.jsx)(ps,{className:`w-3.5 h-3.5`})]}),s&&(0,G.jsx)($$e,{value:k,onSave:e=>{Z.updateSettings({forecast_global_lead_time_days:e}).then(()=>{t.invalidateQueries({queryKey:[`settings`]}),n(r(`forecast.globalLeadTimeSaved`),`success`)})}}),(0,G.jsxs)(`select`,{value:m,onChange:e=>h(e.target.value),className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${m?`bg-bambu-green/20 text-bambu-green border-bambu-green/30`:`bg-transparent text-bambu-gray border-bambu-dark-tertiary hover:bg-bambu-dark-tertiary`}`,children:[(0,G.jsx)(`option`,{value:``,children:r(`inventory.material`)}),P.map(e=>(0,G.jsx)(`option`,{value:e,children:e},e))]}),(0,G.jsxs)(`select`,{value:g,onChange:e=>_(e.target.value),className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${g?`bg-bambu-green/20 text-bambu-green border-bambu-green/30`:`bg-transparent text-bambu-gray border-bambu-dark-tertiary hover:bg-bambu-dark-tertiary`}`,children:[(0,G.jsx)(`option`,{value:``,children:r(`inventory.brand`)}),F.map(e=>(0,G.jsx)(`option`,{value:e,children:e},e))]}),(0,G.jsxs)(`button`,{onClick:()=>S(e=>!e),className:`relative flex items-center gap-2 px-3 py-1.5 rounded-lg border border-bambu-dark-tertiary text-bambu-gray hover:bg-bambu-dark-tertiary text-sm transition-colors ml-auto`,children:[(0,G.jsx)(cu,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:r(`forecast.shoppingList`)}),B&&(0,G.jsx)(`span`,{className:`absolute -top-1.5 -right-1.5 w-4 h-4 rounded-full bg-bambu-green text-white text-[10px] font-bold flex items-center justify-center`,children:B})]})]}),c&&L.length>0&&(0,G.jsx)(`div`,{className:`space-y-2`,children:L.map(e=>(0,G.jsx)(X$e,{forecast:e,onCart:()=>b(e)},e.group.key))}),x&&(0,G.jsx)(i1e,{items:O,forecasts:N,globalLeadTime:k,canWrite:s,onClose:()=>S(!1),onRemove:e=>{Z.removeFromShoppingList(e).then(()=>t.invalidateQueries({queryKey:[`shopping-list`]})).catch(()=>n(r(`forecast.failedSaveSettings`),`error`))},onClear:()=>{Z.clearShoppingList().then(()=>t.invalidateQueries({queryKey:[`shopping-list`]})).catch(()=>n(r(`forecast.failedSaveSettings`),`error`))}}),R.length>0&&(0,G.jsx)(Q$e,{forecasts:R,days:C,onDaysChange:w}),N.length===0?(0,G.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-16 text-bambu-gray`,children:[(0,G.jsx)(Fu,{className:`w-10 h-10 mb-3 opacity-40`}),(0,G.jsx)(`p`,{className:`text-sm`,children:r(`forecast.noSpools`)})]}):(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg overflow-hidden border border-bambu-dark-tertiary`,children:[(0,G.jsx)(`div`,{className:`overflow-x-auto`,children:(0,G.jsxs)(`table`,{className:`w-full`,children:[(0,G.jsx)(`thead`,{children:(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary bg-bambu-dark-tertiary/30`,children:[(0,G.jsx)(`th`,{className:`w-8 px-4 py-3`}),(0,G.jsx)(d9,{col:`material`,active:u,dir:f,onSort:z,children:r(`forecast.sku`)}),(0,G.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:r(`locations.spools`)}),(0,G.jsx)(d9,{col:`stock`,active:u,dir:f,onSort:z,children:r(`forecast.stock`)}),(0,G.jsx)(d9,{col:`used`,active:u,dir:f,onSort:z,children:r(`forecast.dailyRate`)}),(0,G.jsx)(d9,{col:`days_left`,active:u,dir:f,onSort:z,children:r(`forecast.daysLeft`)}),(0,G.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:r(`forecast.emptyBy`)}),(0,G.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:r(`forecast.reorderBy`)}),(0,G.jsx)(`th`,{className:`w-24 px-4 py-3`})]})}),(0,G.jsx)(`tbody`,{className:`divide-y divide-bambu-dark-tertiary`,children:I.map(e=>(0,G.jsx)(e1e,{forecast:e,globalLeadTime:k,canWrite:s,onSaved:()=>t.invalidateQueries({queryKey:[`sku-settings`]}),onCart:()=>b(e),showToast:n},e.group.key))})]})}),(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4 px-4 py-3 text-xs text-bambu-gray border-t border-bambu-dark-tertiary bg-bambu-dark-tertiary/20`,children:[(0,G.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,G.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-bambu-green inline-block`}),r(`forecast.trendLegend`)]}),(0,G.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,G.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-blue-400 inline-block`}),r(`forecast.estimatedLegend`)]}),(0,G.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,G.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-bambu-gray/40 inline-block`}),r(`forecast.noDataLegend`)]})]})]}),v&&(0,G.jsx)(o1e,{forecast:v,onClose:()=>b(null),onAdd:e=>{Z.addToShoppingList(e).then(()=>{t.invalidateQueries({queryKey:[`shopping-list`]}),n(r(`forecast.addedToCart`),`success`),b(null),S(!0)}).catch(()=>n(r(`forecast.failedAddItem`),`error`))}})]})}function d9({col:e,active:t,dir:n,onSort:r,children:i}){return(0,G.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide cursor-pointer select-none hover:text-white transition-colors`,onClick:()=>r(e),children:(0,G.jsxs)(`span`,{className:`inline-flex items-center`,children:[i,t===e?n===`asc`?(0,G.jsx)(Ho,{className:`w-3 h-3 ml-1 text-bambu-green`}):(0,G.jsx)(Io,{className:`w-3 h-3 ml-1 text-bambu-green`}):(0,G.jsx)(Bo,{className:`w-3 h-3 ml-1 opacity-40`})]})})}function X$e({forecast:e,onCart:t}){let{t:n}=U(),r=[e.group.brand,e.group.material,e.group.subtype,e.group.colorName].filter(Boolean).join(` `),i=e.stockBreakAlert;return(0,G.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-3 rounded-lg border text-sm ${i?`bg-red-50 dark:bg-red-500/10 border-red-300 dark:border-red-500/30 text-red-700 dark:text-red-300`:`bg-yellow-50 dark:bg-yellow-500/10 border-yellow-300 dark:border-yellow-500/30 text-yellow-700 dark:text-yellow-300`}`,children:[(0,G.jsx)(Lu,{className:`w-4 h-4 flex-shrink-0`}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`span`,{className:`font-medium`,children:r}),i?(0,G.jsxs)(`span`,{className:`ml-2 text-xs opacity-80`,children:[n(`forecast.stockBreakRisk`),` — `,n(`forecast.stockBreakDetail`,{days:e.daysRemaining,lt:e.effectiveLeadTimeDays})]}):(0,G.jsxs)(`span`,{className:`ml-2 text-xs opacity-80`,children:[n(`forecast.reorderNow`),` — `,n(`forecast.reorderTriggerPassed`,{date:e.reorderTriggerDate?l9(e.reorderTriggerDate):`—`})]})]}),(0,G.jsxs)(`button`,{onClick:t,className:`flex items-center gap-1.5 px-2.5 py-1 rounded border border-current text-xs opacity-70 hover:opacity-100 transition-opacity`,children:[(0,G.jsx)(cu,{className:`w-3 h-3`}),` `,n(`forecast.order`)]})]})}var Z$e=[{label:`1W`,value:7},{label:`1M`,value:30},{label:`6M`,value:180}];function Q$e({forecasts:e,days:t,onDaysChange:n}){let{t:r}=U(),i=Array.from({length:t+1},(e,t)=>t),a=e.map((e,n)=>({key:e.group.key,label:[e.group.brand,e.group.material,e.group.subtype,e.group.colorName].filter(Boolean).join(` `),color:G$e[n%G$e.length],rop:e.reorderPointG,points:J$e(e,t)})),o=i.map(e=>{let t={day:e,label:u9(c9(new Date,e))};for(let n of a){let r=n.points.find(t=>t.day===e);t[n.key]=r?.stock??0}return t}),s=(()=>{for(let e=t;e>=0;e--)if(a.some(t=>o[e]?.[t.key]>0))return e;return t})(),c=o.slice(0,s+1),l=a.filter(e=>e.rop>0);return(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg overflow-hidden border border-bambu-dark-tertiary p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-4`,children:[(0,G.jsx)(Fu,{className:`w-4 h-4 text-bambu-green`}),(0,G.jsx)(`h3`,{className:`text-sm font-semibold text-white`,children:r(`forecast.chartTitle`)}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray ml-1 hidden sm:inline`,children:r(`forecast.dashedLinesROP`)}),(0,G.jsx)(`div`,{className:`ml-auto flex items-center bg-bambu-dark-tertiary rounded-lg p-0.5`,children:Z$e.map(e=>(0,G.jsx)(`button`,{onClick:()=>n(e.value),className:`px-2.5 py-1 text-xs font-medium rounded-md transition-colors ${t===e.value?`bg-bambu-dark-secondary text-white shadow`:`text-bambu-gray hover:text-white`}`,children:e.label},e.value))})]}),(0,G.jsx)(rA,{width:`100%`,height:220,children:(0,G.jsxs)(uH,{data:c,margin:{top:4,right:8,bottom:0,left:0},children:[(0,G.jsx)(`defs`,{children:a.map(e=>(0,G.jsxs)(`linearGradient`,{id:`grad-${e.key}`,x1:`0`,y1:`0`,x2:`0`,y2:`1`,children:[(0,G.jsx)(`stop`,{offset:`5%`,stopColor:e.color,stopOpacity:.25}),(0,G.jsx)(`stop`,{offset:`95%`,stopColor:e.color,stopOpacity:.02})]},e.key))}),(0,G.jsx)(WB,{strokeDasharray:`3 3`,stroke:`#374151`,strokeOpacity:.5}),(0,G.jsx)(bV,{dataKey:`label`,tick:{fill:`#6B7280`,fontSize:10},interval:Math.max(0,Math.ceil(s/8)-1),axisLine:!1,tickLine:!1}),(0,G.jsx)(TV,{tick:{fill:`#6B7280`,fontSize:10},axisLine:!1,tickLine:!1,tickFormatter:e=>e>=1e3?`${(e/1e3).toFixed(1)}kg`:`${e}g`,width:48}),(0,G.jsx)(sz,{content:({label:e,payload:t})=>t?.length?(0,G.jsxs)(`div`,{style:{background:`#1a1a2e`,border:`1px solid #374151`,borderRadius:8,fontSize:12,padding:`8px 12px`},children:[(0,G.jsx)(`div`,{style:{color:`#9CA3AF`,marginBottom:6},children:e}),t.map(e=>{let t=a.find(t=>t.key===String(e.dataKey));return typeof e.value==`number`?(0,G.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:6,color:`#E5E7EB`,marginBottom:2},children:[(0,G.jsx)(`span`,{style:{color:t?.color??`#9CA3AF`,fontSize:10},children:`●`}),(0,G.jsx)(`span`,{children:t?.label??String(e.dataKey)}),(0,G.jsxs)(`span`,{style:{color:`#9CA3AF`,marginLeft:4},children:[e.value,`g`]})]},String(e.dataKey)):null})]}):null}),(0,G.jsx)(cj,{formatter:e=>(0,G.jsx)(`span`,{style:{color:`#9CA3AF`,fontSize:11},children:a.find(t=>t.key===e)?.label??e})}),a.map(e=>(0,G.jsx)(rV,{type:`monotone`,dataKey:e.key,stroke:e.color,strokeWidth:2,fill:`url(#grad-${e.key})`,dot:!1,activeDot:{r:3}},e.key)),l.map(e=>(0,G.jsx)(NB,{y:e.rop,stroke:e.color,strokeDasharray:`4 3`,strokeOpacity:.6},`rop-${e.key}`))]})})]})}function $$e({value:e,onSave:t}){let{t:n}=U(),[r,i]=(0,y.useState)(!1),[a,o]=(0,y.useState)(String(e));function s(){let e=parseInt(a,10);isNaN(e)||e<0||(t(e),i(!1))}return(0,G.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-1.5 bg-bambu-dark-tertiary/40 rounded-lg border border-bambu-dark-tertiary text-xs text-bambu-gray`,children:[(0,G.jsx)(Wc,{className:`w-3.5 h-3.5 flex-shrink-0`,"aria-label":n(`forecast.globalLeadTimeHint`)}),(0,G.jsxs)(`span`,{className:`hidden sm:inline`,children:[n(`forecast.globalLeadTime`),`:`]}),r?(0,G.jsxs)(`form`,{className:`flex items-center gap-1.5`,onSubmit:e=>{e.preventDefault(),s()},children:[(0,G.jsx)(`input`,{type:`number`,min:0,max:365,value:a,onChange:e=>o(e.target.value),className:`w-14 px-1.5 py-0.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-sm text-white focus:outline-none focus:border-bambu-green`,autoFocus:!0}),(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:`d`}),(0,G.jsx)(`button`,{type:`submit`,className:`px-2 py-0.5 bg-bambu-green text-white text-xs rounded hover:bg-bambu-green/80`,children:n(`forecast.save`)}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>i(!1),className:`text-xs text-bambu-gray hover:text-white`,children:`✕`})]}):(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,G.jsxs)(`span`,{className:`font-semibold text-white`,children:[e,`d`]}),(0,G.jsx)(`button`,{onClick:()=>{o(String(e)),i(!0)},className:`p-0.5 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,G.jsx)(kl,{className:`w-3 h-3`})})]})]})}function e1e({forecast:e,globalLeadTime:t,canWrite:n,onSaved:r,onCart:i,showToast:a}){let{t:o}=U(),[s,c]=(0,y.useState)(!1),[l,u]=(0,y.useState)(!1),[d,f]=(0,y.useState)(!1),[p,m]=(0,y.useState)(String(e.settings?.lead_time_days??0)),[h,g]=(0,y.useState)(String(e.settings?.safety_margin_value??14)),[_,v]=(0,y.useState)(e.settings?.safety_margin_unit??`days`);(0,y.useEffect)(()=>{l||m(String(e.settings?.lead_time_days??0))},[e.settings?.lead_time_days,l]),(0,y.useEffect)(()=>{d||(g(String(e.settings?.safety_margin_value??14)),v(e.settings?.safety_margin_unit??`days`))},[e.settings?.safety_margin_value,e.settings?.safety_margin_unit,d]);let b=q({mutationFn:Z.upsertSkuSettings,onSuccess:()=>{r(),a(o(`forecast.settingsSaved`),`success`)},onError:()=>a(o(`forecast.failedSaveSettings`),`error`)}),x=e.settings?.alerts_snoozed??!1,S=[e.group.brand,e.group.material,e.group.subtype,e.group.colorName].filter(Boolean).join(` `),C=e.group.spools[0]?.rgba?Mf(e.group.spools[0].rgba):{backgroundColor:`#4B5563`},w=e.totalLabelG>0?Math.round(e.totalRemainingG/e.totalLabelG*100):0,T=x||e.daysRemaining===null?`text-bambu-gray`:e.stockBreakAlert?`text-red-700 dark:text-red-400`:e.reorderAlert||e.daysRemaining<30?`text-yellow-700 dark:text-yellow-400`:`text-green-700 dark:text-green-400`;function E(t,n,r,i=x){b.mutate({material:e.group.material,subtype:e.group.subtype,brand:e.group.brand,color_name:e.group.colorName,lead_time_days:t,safety_margin_value:n,safety_margin_unit:r,alerts_snoozed:i})}function D(t){t.stopPropagation(),E(e.settings?.lead_time_days??0,e.settings?.safety_margin_value??14,e.settings?.safety_margin_unit??`days`,!x)}let O=e.rateTier===`history`?(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-xs px-1.5 py-0.5 rounded bg-bambu-green/15 text-bambu-green`,children:[(0,G.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-bambu-green`}),o(`forecast.trend`)]}):e.rateTier===`delta`?(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-xs px-1.5 py-0.5 rounded bg-blue-100 dark:bg-blue-400/15 text-blue-700 dark:text-blue-400`,children:[(0,G.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-blue-400`}),o(`forecast.estimated`)]}):(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-xs px-1.5 py-0.5 rounded bg-bambu-dark-tertiary text-bambu-gray/60`,children:[(0,G.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-bambu-gray/40`}),o(`forecast.noData`)]});return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/50 cursor-pointer hover:bg-bambu-dark-tertiary/30 transition-colors ${x?``:e.stockBreakAlert?`bg-red-500/5`:e.reorderAlert?`bg-yellow-500/5`:``} ${x?`opacity-50`:``}`,onClick:()=>c(e=>!e),children:[(0,G.jsx)(`td`,{className:`px-4 py-3`,children:(0,G.jsx)(`span`,{className:`block w-5 h-5 rounded-full border border-black/20`,style:C})}),(0,G.jsx)(`td`,{className:`px-4 py-3`,children:(0,G.jsx)(`span`,{className:`text-sm text-white`,children:S})}),(0,G.jsx)(`td`,{className:`px-4 py-3`,children:(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.totalSpools})}),(0,G.jsx)(`td`,{className:`px-4 py-3 min-w-[140px]`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`div`,{className:`flex-1 h-2 bg-bambu-dark-tertiary rounded-full overflow-hidden`,children:(0,G.jsx)(`div`,{className:`h-full rounded-full ${w>50?`bg-bambu-green`:w>20?`bg-yellow-500`:`bg-red-500`}`,style:{width:`${Math.min(w,100)}%`}})}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray min-w-[40px] text-right`,children:[Math.round(e.totalRemainingG),`g`]})]})}),(0,G.jsx)(`td`,{className:`px-4 py-3`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 flex-wrap`,children:[(0,G.jsx)(`span`,{className:`text-sm text-white`,children:e.dailyRateG===null?`—`:`${e.dailyRateG.toFixed(1)}g/d`}),O]})}),(0,G.jsx)(`td`,{className:`px-4 py-3`,children:(0,G.jsx)(`span`,{className:`text-sm font-semibold ${T}`,children:e.daysRemaining===null?(0,G.jsx)(`span`,{className:`text-bambu-gray font-normal`,children:`—`}):`${e.daysRemaining}d`})}),(0,G.jsx)(`td`,{className:`px-4 py-3`,children:(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.projectedEmptyDate?l9(e.projectedEmptyDate):`—`})}),(0,G.jsx)(`td`,{className:`px-4 py-3`,children:(0,G.jsx)(`span`,{className:`text-sm ${!x&&e.reorderAlert?`text-yellow-700 dark:text-yellow-400`:`text-bambu-gray`}`,children:e.reorderTriggerDate?l9(e.reorderTriggerDate):`—`})}),(0,G.jsx)(`td`,{className:`px-4 py-3`,onClick:e=>e.stopPropagation(),children:(0,G.jsxs)(`div`,{className:`flex items-center justify-end gap-1`,children:[n&&(0,G.jsx)(`button`,{onClick:i,className:`p-1.5 text-bambu-gray hover:text-bambu-green rounded transition-colors`,title:o(`forecast.addToCart`),children:(0,G.jsx)(cu,{className:`w-4 h-4`})}),!x&&(e.stockBreakAlert?(0,G.jsx)(Lu,{className:`w-4 h-4 text-red-600 dark:text-red-400`,"aria-label":o(`forecast.stockBreakRisk`)}):e.reorderAlert?(0,G.jsx)(Lu,{className:`w-4 h-4 text-yellow-600 dark:text-yellow-400`,"aria-label":o(`forecast.reorderNow`)}):e.daysRemaining===null?null:(0,G.jsx)(fs,{className:`w-4 h-4 text-bambu-green/50`})),n&&(0,G.jsx)(`button`,{onClick:D,className:`p-1 rounded transition-colors ${x?`text-amber-600/80 dark:text-amber-400/80 hover:text-amber-700 dark:hover:text-amber-300`:`text-slate-400 hover:text-white`}`,title:o(x?`forecast.alertsEnabled`:`forecast.alertsSnoozed`),children:(0,G.jsx)(Ko,{className:`w-3.5 h-3.5`})}),(0,G.jsx)(`button`,{onClick:e=>{e.stopPropagation(),c(e=>!e)},className:`p-1.5 text-bambu-gray hover:text-white rounded transition-colors`,children:s?(0,G.jsx)(gs,{className:`w-4 h-4`}):(0,G.jsx)(ps,{className:`w-4 h-4`})})]})})]}),s&&(0,G.jsx)(`tr`,{className:`bg-bambu-dark-tertiary/10`,children:(0,G.jsx)(`td`,{colSpan:9,className:`px-6 py-4`,children:(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{className:`grid gap-2 ${n?`grid-cols-2 sm:grid-cols-4`:`grid-cols-2`}`,children:[(0,G.jsx)(t1e,{label:o(`forecast.effectiveLeadTime`),value:`${e.effectiveLeadTimeDays}d`,hint:o(`forecast.effectiveLeadTimeHint`,{global:t,sku:e.settings?.lead_time_days??0})}),(0,G.jsx)(t1e,{label:o(`forecast.reorderPoint`),value:`${Math.round(e.reorderPointG)}g`,hint:o(`forecast.reorderPointHint`)}),n&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(n1e,{label:o(`forecast.skuLeadTimeOverride`),hint:o(`forecast.skuLeadTimeHint`),unit:o(`forecast.leadTime`),editing:l,value:e.settings?.lead_time_days??0,inputValue:p,onInputChange:m,onEdit:()=>{m(String(e.settings?.lead_time_days??0)),u(!0)},onSave:()=>{let t=parseInt(p,10);!isNaN(t)&&t>=0&&(E(t,e.settings?.safety_margin_value??14,_),u(!1))},onCancel:()=>u(!1),isPending:b.isPending,saveLabel:o(`forecast.save`),cancelLabel:o(`forecast.cancel`)}),(0,G.jsx)(r1e,{value:e.settings?.safety_margin_value??14,unit:_,editing:d,inputValue:h,dailyRateG:e.dailyRateG,onInputChange:g,onUnitChange:e=>v(e),onEdit:()=>{g(String(e.settings?.safety_margin_value??14)),v(e.settings?.safety_margin_unit??`days`),f(!0)},onSave:()=>{let t=parseInt(h,10);!isNaN(t)&&t>=0&&(E(e.settings?.lead_time_days??0,t,_),f(!1))},onCancel:()=>f(!1),isPending:b.isPending,saveLabel:o(`forecast.save`),cancelLabel:o(`forecast.cancel`),safetyMarginLabel:o(`forecast.safetyMarginLabel`)})]})]}),e.group.spools.length>1&&(0,G.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary pt-3`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:o(`forecast.individualSpools`)}),(0,G.jsx)(`div`,{className:`bg-bambu-dark-secondary rounded-lg overflow-hidden border border-bambu-dark-tertiary`,children:(0,G.jsxs)(`table`,{className:`w-full`,children:[(0,G.jsx)(`thead`,{children:(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary bg-bambu-dark-tertiary/30`,children:[(0,G.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:`#`}),(0,G.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:o(`inventory.remaining`)}),(0,G.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:o(`inventory.used`)}),(0,G.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:o(`forecast.labelWeight`)})]})}),(0,G.jsx)(`tbody`,{className:`divide-y divide-bambu-dark-tertiary`,children:e.group.spools.map(e=>{let t=Math.max(0,e.label_weight-e.weight_used),n=e.label_weight>0?t/e.label_weight*100:0;return(0,G.jsxs)(`tr`,{className:`hover:bg-bambu-dark-tertiary/30 transition-colors`,children:[(0,G.jsx)(`td`,{className:`px-4 py-2`,children:(0,G.jsxs)(`span`,{className:`text-xs font-mono text-bambu-gray/70`,children:[`#`,e.id]})}),(0,G.jsx)(`td`,{className:`px-4 py-2`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`w-24 h-1.5 bg-bambu-dark-tertiary rounded-full overflow-hidden flex-shrink-0`,children:(0,G.jsx)(`div`,{className:`h-full rounded-full ${n>50?`bg-bambu-green`:n>20?`bg-yellow-500`:`bg-red-500`}`,style:{width:`${Math.min(n,100)}%`}})}),(0,G.jsxs)(`span`,{className:`text-sm text-white`,children:[Math.round(t),`g`]})]})}),(0,G.jsx)(`td`,{className:`px-4 py-2`,children:(0,G.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[Math.round(Math.max(0,e.weight_used-(e.weight_used_baseline??0))),`g`]})}),(0,G.jsx)(`td`,{className:`px-4 py-2`,children:(0,G.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[e.label_weight,`g`]})})]},e.id)})})]})})]})]})})})]})}function t1e({label:e,value:t,hint:n}){return(0,G.jsxs)(`div`,{className:`bg-bambu-dark-tertiary/40 rounded-lg p-3`,title:n,children:[(0,G.jsx)(`div`,{className:`text-xs font-medium text-white mb-1`,children:e}),(0,G.jsx)(`div`,{className:`text-lg font-semibold text-white`,children:t})]})}function n1e({label:e,hint:t,unit:n,editing:r,value:i,inputValue:a,onInputChange:o,onEdit:s,onSave:c,onCancel:l,isPending:u,saveLabel:d=`Save`,cancelLabel:f=`Cancel`}){return(0,G.jsxs)(`div`,{className:`bg-bambu-dark-tertiary/40 rounded-lg p-3 space-y-1`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,G.jsx)(`span`,{className:`text-xs font-medium text-white`,children:e}),(0,G.jsx)(`span`,{title:t,children:(0,G.jsx)(Wc,{className:`w-3 h-3 text-bambu-gray/50`})})]}),r?(0,G.jsxs)(`form`,{className:`flex items-center gap-2`,onSubmit:e=>{e.preventDefault(),c()},children:[(0,G.jsx)(`input`,{type:`number`,min:0,max:365,value:a,onChange:e=>o(e.target.value),className:`w-20 px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-sm text-white focus:outline-none focus:border-bambu-green`,autoFocus:!0,disabled:u}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:n}),(0,G.jsx)(`button`,{type:`submit`,disabled:u,className:`px-2 py-1 bg-bambu-green text-white text-xs rounded hover:bg-bambu-green/80 disabled:opacity-50`,children:d}),(0,G.jsx)(`button`,{type:`button`,onClick:l,disabled:u,className:`px-2 py-1 text-xs text-bambu-gray hover:text-white`,children:f})]}):(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-lg font-semibold text-white`,children:i}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:n}),(0,G.jsx)(`button`,{onClick:s,className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,G.jsx)(kl,{className:`w-3 h-3`})})]})]})}function r1e({value:e,unit:t,editing:n,inputValue:r,dailyRateG:i,onInputChange:a,onUnitChange:o,onEdit:s,onSave:c,onCancel:l,isPending:u,saveLabel:d=`Save`,cancelLabel:f=`Cancel`,safetyMarginLabel:p=`Safety Margin`}){let{t:m}=U(),h=t===`g`?e:i===null?null:Math.round(i*e),g=t===`days`?m(`forecast.safetyMarginHintDays`,{approx:h===null?``:m(`forecast.safetyMarginHintDaysApprox`,{g:h})}):m(`forecast.safetyMarginHintG`,{approx:i===null?``:m(`forecast.safetyMarginHintGApprox`,{days:Math.round(e/i)})});return(0,G.jsxs)(`div`,{className:`bg-bambu-dark-tertiary/40 rounded-lg p-3 space-y-1`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,G.jsx)(`span`,{className:`text-xs font-medium text-white`,children:p}),(0,G.jsx)(`span`,{title:g,children:(0,G.jsx)(Wc,{className:`w-3 h-3 text-bambu-gray/50`})})]}),n?(0,G.jsxs)(`form`,{className:`flex items-center gap-2 flex-wrap`,onSubmit:e=>{e.preventDefault(),c()},children:[(0,G.jsx)(`input`,{type:`number`,min:0,max:t===`g`?1e4:365,value:r,onChange:e=>a(e.target.value),className:`w-20 px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-sm text-white focus:outline-none focus:border-bambu-green`,autoFocus:!0,disabled:u}),(0,G.jsxs)(`div`,{className:`flex bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded overflow-hidden text-xs`,children:[(0,G.jsx)(`button`,{type:`button`,onClick:()=>o(`days`),className:`px-2 py-1 transition-colors ${t===`days`?`bg-bambu-green text-white`:`text-bambu-gray hover:text-white`}`,children:`days`}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>o(`g`),className:`px-2 py-1 transition-colors ${t===`g`?`bg-bambu-green text-white`:`text-bambu-gray hover:text-white`}`,children:`g`})]}),(0,G.jsx)(`button`,{type:`submit`,disabled:u,className:`px-2 py-1 bg-bambu-green text-white text-xs rounded hover:bg-bambu-green/80 disabled:opacity-50`,children:d}),(0,G.jsx)(`button`,{type:`button`,onClick:l,disabled:u,className:`px-2 py-1 text-xs text-bambu-gray hover:text-white`,children:f})]}):(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-lg font-semibold text-white`,children:e}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:t}),h!==null&&t===`days`&&(0,G.jsxs)(`span`,{className:`text-lg font-semibold text-white`,children:[`≈ `,h,`g`]}),t===`g`&&i!==null&&(0,G.jsxs)(`span`,{className:`text-lg font-semibold text-white`,children:[`≈ `,Math.round(e/i),`d`]}),(0,G.jsx)(`button`,{onClick:s,className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,G.jsx)(kl,{className:`w-3 h-3`})})]})]})}function i1e({items:e,forecasts:t,globalLeadTime:n,canWrite:r,onClose:i,onRemove:a,onClear:o}){let{t:s}=U(),c=co(),[l,u]=(0,y.useState)(`list`),d=q({mutationFn:async({id:e,status:t,item:n,avgSpoolG:r})=>{if(await Z.updateShoppingListStatus(e,t),t===`received`&&n){let t=r??1e3,i={material:n.material,subtype:n.subtype,brand:n.brand,label_weight:t,core_weight:0,core_weight_catalog_id:null,color_name:n.color_name,rgba:null,extra_colors:null,effect_type:null,nozzle_temp_min:null,nozzle_temp_max:null,note:n.note??null,tag_uid:null,tray_uuid:null,data_origin:`manual`,tag_type:null,cost_per_kg:null,last_scale_weight:null,last_weighed_at:null,weight_used:0,slicer_filament:null,slicer_filament_name:null,added_full:null,last_used:null,encode_time:null,category:`Stock`,low_stock_threshold_pct:null};await Z.bulkCreateSpools(i,n.quantity_spools),await Z.removeFromShoppingList(e)}},onSuccess:()=>{c.invalidateQueries({queryKey:[`shopping-list`]}),c.invalidateQueries({queryKey:[`spools`]})}}),f=(0,y.useMemo)(()=>{let e=new Map;for(let n of t)e.set(n.group.key,n);return e},[t]),p=(0,y.useMemo)(()=>e.map(e=>({item:e,forecast:f.get(s9(e.material,e.subtype,e.brand,e.color_name))??null})),[e,f]),m=(0,y.useMemo)(()=>p.filter(({forecast:e})=>!e||e.dailyRateG===null?!1:e.stockBreakAlert||e.daysRemaining!==null&&e.daysRemaining<=e.effectiveLeadTimeDays),[p]);function h(){let t=[s(`forecast.qty`),s(`forecast.material`),s(`inventory.brand`),s(`inventory.subtype`),s(`inventory.color`),`${s(`forecast.weight`)} (g)`,`${s(`forecast.leadTime`)} (d)`,s(`forecast.expectedRestock`),s(`forecast.status`),s(`forecast.note`)],r=e.map(e=>{let t=f.get(s9(e.material,e.subtype,e.brand,e.color_name))??null,r=t&&t.totalSpools>0?t.totalLabelG/t.totalSpools:1e3,i=Math.round(e.quantity_spools*r),a=t?.effectiveLeadTimeDays??n??0,o=a>0?l9(c9(new Date,a)):``;return[e.quantity_spools,e.material,e.brand??``,e.subtype??``,e.color_name??``,i,a||``,o,e.status,e.note??``].map(e=>`"${String(e).replace(/"/g,`""`)}"`).join(`,`)}),i=[t.join(`,`),...r].join(` +`),a=new Blob([i],{type:`text/csv`}),o=URL.createObjectURL(a),c=document.createElement(`a`);c.href=o,c.download=`shopping-list-${new Date().toISOString().slice(0,10)}.csv`,c.click(),setTimeout(()=>URL.revokeObjectURL(o),100)}return(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg overflow-hidden border border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 border-b border-bambu-dark-tertiary bg-bambu-dark-tertiary/30`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(cu,{className:`w-4 h-4 text-bambu-green`}),(0,G.jsx)(`h3`,{className:`text-sm font-semibold text-white`,children:s(`forecast.shoppingList`)}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:s(`forecast.shoppingListItems`,{count:e.length})}),e.length>0&&(0,G.jsxs)(`div`,{className:`flex bg-bambu-dark-tertiary rounded-md p-0.5 ml-1`,children:[(0,G.jsxs)(`button`,{onClick:()=>u(`list`),className:`flex items-center gap-1.5 px-2 py-0.5 text-xs font-medium rounded transition-colors ${l===`list`?`bg-bambu-dark-secondary text-white shadow`:`text-bambu-gray hover:text-white`}`,children:[(0,G.jsx)(Cl,{className:`w-3 h-3`}),s(`forecast.listView`)]}),(0,G.jsxs)(`button`,{onClick:()=>u(`logistics`),className:`flex items-center gap-1.5 px-2 py-0.5 text-xs font-medium rounded transition-colors ${l===`logistics`?`bg-bambu-dark-secondary text-white shadow`:`text-bambu-gray hover:text-white`}`,children:[(0,G.jsx)(us,{className:`w-3 h-3`}),s(`forecast.logisticsView`),m.length>0&&(0,G.jsx)(`span`,{className:`w-3.5 h-3.5 rounded-full bg-red-500 text-white text-[9px] font-bold flex items-center justify-center`,children:m.length})]})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.length>0&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`button`,{onClick:h,className:`flex items-center gap-1.5 text-xs text-bambu-gray hover:text-white transition-colors px-2 py-1 rounded border border-bambu-dark-tertiary hover:bg-bambu-dark-tertiary`,children:[(0,G.jsx)(Xs,{className:`w-3 h-3`}),s(`forecast.downloadCsv`)]}),r&&(0,G.jsx)(`button`,{onClick:o,className:`text-xs text-red-700 dark:text-red-400 hover:text-red-800 dark:hover:text-red-300 transition-colors px-2 py-1 rounded border border-red-200 dark:border-red-500/20 hover:bg-red-50 dark:hover:bg-red-500/10`,children:s(`forecast.clearAll`)})]}),(0,G.jsx)(`button`,{onClick:i,className:`p-1 text-bambu-gray hover:text-white transition-colors`,children:(0,G.jsx)(nd,{className:`w-4 h-4`})})]})]}),e.length===0?(0,G.jsxs)(`div`,{className:`flex flex-col items-center py-8 text-bambu-gray`,children:[(0,G.jsx)(Cl,{className:`w-8 h-8 mb-2 opacity-30`}),(0,G.jsx)(`p`,{className:`text-sm`,children:s(`forecast.shoppingListEmpty`)})]}):l===`list`?(0,G.jsx)(`div`,{className:`overflow-x-auto`,children:(0,G.jsxs)(`table`,{className:`w-full`,children:[(0,G.jsx)(`thead`,{children:(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary bg-bambu-dark-tertiary/20`,children:[(0,G.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:s(`forecast.qty`)}),(0,G.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:s(`forecast.material`)}),(0,G.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:s(`forecast.weight`)}),(0,G.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:s(`forecast.leadTime`)}),(0,G.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:s(`forecast.expectedRestock`)}),(0,G.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:s(`forecast.status`)}),(0,G.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:s(`forecast.note`)}),(0,G.jsx)(`th`,{className:`px-4 py-2 text-right text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:s(`forecast.actions`)})]})}),(0,G.jsx)(`tbody`,{className:`divide-y divide-bambu-dark-tertiary`,children:e.map(e=>{let t=[e.brand,e.material,e.subtype,e.color_name].filter(Boolean).join(` `),i=m.some(t=>t.item.id===e.id),o=f.get(s9(e.material,e.subtype,e.brand,e.color_name))??null,c=o&&o.totalSpools>0?o.totalLabelG/o.totalSpools:1e3,l=Math.round(e.quantity_spools*c),u=o?.effectiveLeadTimeDays??n??0,p=u>0?c9(new Date,u):null,h=e.status===`purchased`||e.status===`received`,g=e.status===`received`,_=d.isPending;return(0,G.jsxs)(`tr`,{className:`hover:bg-bambu-dark-tertiary/30 transition-colors ${i&&!h?`bg-red-500/5`:``}`,children:[(0,G.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,G.jsxs)(`span`,{className:`text-sm font-semibold text-bambu-green`,children:[e.quantity_spools,`×`]})}),(0,G.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-sm text-white`,children:t}),i&&!h&&(0,G.jsx)(Lu,{className:`w-3.5 h-3.5 text-red-600 dark:text-red-400 flex-shrink-0`,"aria-label":s(`forecast.stockBreakBefore`)})]})}),(0,G.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,G.jsx)(`span`,{className:`text-sm text-white`,children:l>=1e3?`${(l/1e3).toFixed(1)}kg`:`${l}g`})}),(0,G.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:u>0?`${u}d`:`—`})}),(0,G.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:p?l9(p):`—`})}),(0,G.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,G.jsx)(`span`,{className:`inline-flex items-center px-2 py-0.5 rounded text-xs font-medium ${g?`bg-bambu-green/20 text-bambu-green`:h?`bg-blue-100 dark:bg-blue-400/20 text-blue-700 dark:text-blue-400`:`bg-bambu-dark-tertiary text-bambu-gray`}`,children:s(g?`forecast.received`:h?`forecast.purchased`:`forecast.pending`)})}),(0,G.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:e.note||`—`})}),(0,G.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,G.jsx)(`div`,{className:`flex items-center justify-end gap-1`,children:r&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`button`,{onClick:()=>d.mutate({id:e.id,status:h?`pending`:`purchased`}),disabled:_||g,title:s(h?`forecast.resetToPending`:`forecast.markPurchased`),className:`p-1.5 rounded transition-colors disabled:opacity-30 ${h?`text-blue-600 dark:text-blue-400 hover:text-blue-700 dark:hover:text-blue-300`:`text-blue-600/50 dark:text-blue-400/50 hover:text-blue-600 dark:hover:text-blue-400`}`,children:h?(0,G.jsx)(Wl,{className:`w-4 h-4`}):(0,G.jsx)(Us,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:()=>d.mutate({id:e.id,status:`received`,item:e,avgSpoolG:c}),disabled:_||!h||g,title:s(`forecast.markReceived`),className:`p-1.5 rounded transition-colors text-bambu-green/50 hover:text-bambu-green disabled:opacity-30`,children:(0,G.jsx)(xl,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:()=>a(e.id),className:`p-1 text-bambu-gray hover:text-red-600 dark:hover:text-red-400 transition-colors`,title:s(`forecast.remove`),children:(0,G.jsx)(Pu,{className:`w-3.5 h-3.5`})})]})})})]},e.id)})})]})}):(0,G.jsx)(`div`,{className:`divide-y divide-bambu-dark-tertiary`,children:p.filter(({item:e})=>e.status!==`received`).map(({item:e,forecast:t})=>(0,G.jsx)(a1e,{item:e,forecast:t,globalLeadTime:n,canWrite:r,onRemove:()=>a(e.id)},e.id))})]})}function a1e({item:e,forecast:t,globalLeadTime:n,canWrite:r,onRemove:i}){let{t:a}=U(),o=[e.brand,e.material,e.subtype,e.color_name].filter(Boolean).join(` `),s=(0,y.useMemo)(()=>{if(!t||t.dailyRateG===null||t.dailyRateG<=0)return null;let n=t.dailyRateG,r=t.effectiveLeadTimeDays,i=t.totalSpools>0?t.totalLabelG/t.totalSpools:1e3,a=e.quantity_spools*i,o=Math.max(0,t.totalRemainingG-n*r),s=o+a,c=Math.ceil(s/n),l=Math.min(r+c+5,365),u=[];for(let e=0;e<=l;e++){let i=u9(c9(new Date,e));if(e===r)u.push({day:e,label:i,stock:Math.round(o),rop:Math.round(t.reorderPointG),safetyStock:Math.round(t.safetyStockG)}),u.push({day:e,label:i,stock:Math.round(s),rop:Math.round(t.reorderPointG),safetyStock:Math.round(t.safetyStockG),arrival:!0});else{let a=e{if(!t||t.dailyRateG===null||t.dailyRateG<=0)return null;let e=Math.floor(t.totalRemainingG/t.dailyRateG);return ee>=1e3?`${(e/1e3).toFixed(1)}kg`:`${e}g`,width:44}),(0,G.jsx)(sz,{contentStyle:{background:`#1a1a2e`,border:`1px solid #374151`,borderRadius:8,fontSize:11},labelStyle:{color:`#9CA3AF`},formatter:(e,t)=>typeof e==`number`?t===`stock`?`${e}g — ${a(`forecast.stock`)}`:t===`rop`?`${e}g — ${a(`forecast.reorderPoint`)}`:t===`safetyStock`?`${e}g — ${a(`forecast.safetyMarginLabel`)}`:`${e}`:``}),(0,G.jsx)(rV,{type:`linear`,dataKey:`stock`,stroke:`#1DB954`,strokeWidth:2,fill:`url(#cart-post-${e.id})`,dot:!1,activeDot:{r:3}}),t.reorderPointG>0&&(0,G.jsx)(NB,{y:t.reorderPointG,stroke:`#F59E0B`,strokeDasharray:`5 3`,strokeOpacity:.8,label:{value:`ROP`,position:`insideTopRight`,fill:`#F59E0B`,fontSize:9}}),t.safetyStockG>0&&(0,G.jsx)(NB,{y:t.safetyStockG,stroke:`#6B7280`,strokeDasharray:`3 3`,strokeOpacity:.6,label:{value:`SS`,position:`insideTopRight`,fill:`#6B7280`,fontSize:9}}),(0,G.jsx)(NB,{x:u9(c9(new Date,s.lt)),stroke:`#3B82F6`,strokeWidth:1.5,strokeDasharray:`4 3`,strokeOpacity:.9,label:{value:`+${s.arrivalG>=1e3?`${(s.arrivalG/1e3).toFixed(1)}kg`:`${Math.round(s.arrivalG)}g`} arrives (d${s.lt})`,position:`insideTopLeft`,fill:`#3B82F6`,fontSize:9}}),c!==null&&(0,G.jsx)(NB,{x:u9(c9(new Date,c)),stroke:`#EF4444`,strokeWidth:1.5,strokeOpacity:.9,label:{value:`OUT`,position:`insideTopLeft`,fill:`#EF4444`,fontSize:9}})]})}),(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 mt-2 text-[10px] text-bambu-gray`,children:[(0,G.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(`span`,{className:`inline-block w-4 border-t-2 border-yellow-400 border-dashed`}),` `,a(`forecast.ropLabel`)]}),(0,G.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(`span`,{className:`inline-block w-4 border-t border-bambu-gray border-dashed`}),` `,a(`forecast.safetyStockLegend`)]}),(0,G.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(`span`,{className:`inline-block w-4 border-t-2 border-blue-400 border-dashed`}),` `,a(`forecast.stockArrivalLegend`)]}),l&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-red-700 dark:text-red-400`,children:[(0,G.jsx)(`span`,{className:`inline-block w-4 border-t-2 border-red-400`}),` `,a(`forecast.stockoutLegend`)]})]})]}):null]})}function o1e({forecast:e,onClose:t,onAdd:n}){let{t:r}=U(),i=[e.group.brand,e.group.material,e.group.subtype,e.group.colorName].filter(Boolean).join(` `),[a,o]=(0,y.useState)(`qty`),[s,c]=(0,y.useState)(`1`),[l,u]=(0,y.useState)(`30`),[d,f]=(0,y.useState)(``),p=(0,y.useMemo)(()=>{if(!e.dailyRateG||e.dailyRateG<=0)return null;let t=e.dailyRateG*Number(l),n=e.group.spools.length>0?e.group.spools.reduce((e,t)=>e+t.label_weight,0)/e.group.spools.length:1e3;return Math.ceil(t/n)},[e,l]),m=a===`qty`?parseInt(s,10)||1:p??1;function h(t){t.preventDefault(),n({material:e.group.material,subtype:e.group.subtype,brand:e.group.brand,color_name:e.group.colorName,quantity_spools:m,note:d||null})}return(0,G.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm p-4`,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-2xl border border-bambu-dark-tertiary w-full max-w-sm shadow-2xl`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-5 pt-5 pb-4 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(cu,{className:`w-5 h-5 text-bambu-green`}),(0,G.jsx)(`h2`,{className:`text-base font-semibold text-white`,children:r(`forecast.addToCartTitle`)})]}),(0,G.jsx)(`button`,{onClick:t,className:`p-1 text-bambu-gray hover:text-white transition-colors`,children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]}),(0,G.jsxs)(`form`,{onSubmit:h,className:`p-5 space-y-4`,children:[(0,G.jsx)(`div`,{className:`text-sm text-bambu-gray`,children:i}),(0,G.jsxs)(`div`,{className:`flex bg-bambu-dark-tertiary rounded-lg p-0.5`,children:[(0,G.jsx)(`button`,{type:`button`,onClick:()=>o(`qty`),className:`flex-1 py-1.5 text-xs font-medium rounded-md transition-colors ${a===`qty`?`bg-bambu-dark-secondary text-white shadow`:`text-bambu-gray hover:text-white`}`,children:r(`forecast.byQuantity`)}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>o(`duration`),className:`flex-1 py-1.5 text-xs font-medium rounded-md transition-colors ${a===`duration`?`bg-bambu-dark-secondary text-white shadow`:`text-bambu-gray hover:text-white`}`,children:r(`forecast.byDuration`)})]}),a===`qty`?(0,G.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,G.jsx)(`label`,{className:`text-xs text-bambu-gray`,children:r(`forecast.numberOfSpools`)}),(0,G.jsx)(`input`,{type:`number`,min:1,max:99,value:s,onChange:e=>c(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`,autoFocus:!0})]}):(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,G.jsx)(`label`,{className:`text-xs text-bambu-gray`,children:r(`forecast.lastHowManyDays`)}),(0,G.jsx)(`input`,{type:`number`,min:1,max:365,value:l,onChange:e=>u(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`,autoFocus:!0})]}),e.dailyRateG===null?(0,G.jsx)(`div`,{className:`text-xs text-yellow-700 dark:text-yellow-400 px-1`,children:r(`forecast.noUsageQty`)}):(0,G.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2 bg-bambu-dark-tertiary/50 rounded-lg`,children:[(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:`≈`}),(0,G.jsx)(`span`,{className:`text-sm font-semibold text-bambu-green`,children:r(`forecast.spoolCount`,{count:p??0})}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[`at `,e.dailyRateG.toFixed(1),`g/day`]})]})]}),(0,G.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,G.jsx)(`label`,{className:`text-xs text-bambu-gray`,children:r(`forecast.noteOptional`)}),(0,G.jsx)(`input`,{type:`text`,maxLength:200,value:d,onChange:e=>f(e.target.value),placeholder:r(`forecast.notePlaceholder`),className:`w-full px-3 py-2 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/40 focus:outline-none focus:border-bambu-green`})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-3 pt-1`,children:[(0,G.jsx)(`button`,{type:`submit`,className:`flex-1 py-2 bg-bambu-green text-white text-sm font-medium rounded-lg hover:bg-bambu-green/80 transition-colors`,children:r(`forecast.addNSpools`,{count:m})}),(0,G.jsx)(`button`,{type:`button`,onClick:t,className:`px-4 py-2 text-sm text-bambu-gray hover:text-white border border-bambu-dark-tertiary rounded-lg transition-colors`,children:r(`forecast.cancel`)})]})]})]})})}var f9={material:``,subtype:``,brand:``,color_name:``,rgba:`808080FF`,extra_colors:``,effect_type:``,label_weight:1e3,core_weight:250,core_weight_catalog_id:null,weight_used:0,slicer_filament:``,note:``,cost_per_kg:null,category:``,low_stock_threshold_pct:null,location_id:null,spoolman_filament_id:null},s1e=new Set([`material`,`subtype`,`brand`,`rgba`,`color_name`,`label_weight`]);function c1e(e,t=!1,n=!1,r=`create`){let i={};return t||n||r!==`create`?(!e.material&&!e.spoolman_filament_id&&(i.material=`Material is required`),{isValid:Object.keys(i).length===0,errors:i}):(e.slicer_filament||(i.slicer_filament=`Slicer preset is required`),e.material||(i.material=`Material is required`),e.brand||(i.brand=`Brand is required`),e.subtype||(i.subtype=`Subtype is required`),{isValid:Object.keys(i).length===0,errors:i})}var l1e={local:`bg-green-100 dark:bg-green-500/20 text-green-700 dark:text-green-400`,orca_cloud:`bg-purple-100 dark:bg-purple-500/20 text-purple-700 dark:text-purple-400`,cloud:`bg-bambu-blue/20 text-bambu-blue`,builtin:`bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-400`};function p9({source:e}){let{t}=U(),n={local:t(`profiles.localProfiles.badge`),orca_cloud:t(`configureAmsSlot.orcaCloud`),cloud:t(`configureAmsSlot.bambuCloud`),builtin:t(`configureAmsSlot.builtin`)}[e];return(0,G.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded whitespace-nowrap ${l1e[e]}`,children:n})}function u1e({value:e,options:t,inheritLabel:n,onChange:r,disabled:i=!1,ariaLabel:a}){let{t:o}=U(),[s,c]=(0,y.useState)(!1),[l,u]=(0,y.useState)(``),d=(0,y.useRef)(null),f=t.find(t=>t.code===e);(0,y.useEffect)(()=>{if(!s)return;let e=e=>{d.current&&!d.current.contains(e.target)&&c(!1)},t=e=>{e.key===`Escape`&&(e.stopPropagation(),c(!1))};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t,!0),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t,!0)}},[s]);let p=l.trim().toLowerCase(),m=p?t.filter(e=>e.displayName.toLowerCase().includes(p)):t,h=e=>{r(e),c(!1),u(``)};return(0,G.jsxs)(`div`,{className:`relative`,ref:d,children:[(0,G.jsxs)(`button`,{type:`button`,"aria-label":a,"aria-haspopup":`listbox`,"aria-expanded":s,disabled:i,onClick:()=>c(e=>!e),className:`w-full flex items-center gap-2 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-sm text-left focus:outline-none focus:border-bambu-green disabled:opacity-50`,children:[(0,G.jsx)(`span`,{className:`flex-1 min-w-0 truncate ${f?`text-white`:`text-bambu-gray italic`}`,children:f?f.displayName:n}),f&&(0,G.jsx)(p9,{source:f.source}),(0,G.jsx)(ps,{className:`w-3.5 h-3.5 text-bambu-gray shrink-0`})]}),s&&(0,G.jsxs)(`div`,{className:`absolute z-50 mt-1 w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl`,children:[(0,G.jsx)(`div`,{className:`p-2 border-b border-bambu-dark-tertiary`,children:(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(Ql,{className:`w-3.5 h-3.5 text-bambu-gray absolute left-2 top-1/2 -translate-y-1/2`}),(0,G.jsx)(`input`,{autoFocus:!0,type:`text`,value:l,onChange:e=>u(e.target.value),placeholder:o(`inventory.searchPresets`),className:`w-full pl-7 pr-7 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded-md text-sm text-white placeholder:text-bambu-gray/60 focus:outline-none focus:border-bambu-green`}),l&&(0,G.jsx)(`button`,{type:`button`,"aria-label":o(`common.clear`),onClick:()=>u(``),className:`absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white`,children:(0,G.jsx)(nd,{className:`w-3.5 h-3.5`})})]})}),(0,G.jsxs)(`div`,{className:`max-h-56 overflow-y-auto p-1`,role:`listbox`,"aria-label":a,children:[(0,G.jsx)(`button`,{type:`button`,role:`option`,"aria-selected":!f,onClick:()=>h(null),className:`w-full text-left px-2 py-1.5 rounded-md text-sm italic ${f?`text-bambu-gray hover:bg-bambu-dark`:`bg-bambu-green/15 text-bambu-green`}`,children:n}),m.length===0?(0,G.jsx)(`p`,{className:`px-2 py-2 text-sm text-bambu-gray`,children:o(`inventory.noResults`)}):m.map(t=>(0,G.jsxs)(`button`,{type:`button`,role:`option`,"aria-selected":t.code===e,onClick:()=>h(t),className:`w-full flex items-center gap-2 text-left px-2 py-1.5 rounded-md text-sm ${t.code===e?`bg-bambu-green/15 text-bambu-green`:`text-white hover:bg-bambu-dark`}`,children:[(0,G.jsx)(`span`,{className:`flex-1 min-w-0 truncate`,title:t.displayName,children:t.displayName}),(0,G.jsx)(p9,{source:t.source})]},t.code))]})]})]})}function d1e(e,t){if(t.length===0)return{top:[],rest:e};let n=new Set(t.map(e=>e.toLowerCase()));return{top:e.filter(e=>n.has(e.toLowerCase())),rest:e.filter(e=>!n.has(e.toLowerCase()))}}function m9({label:e}){return(0,G.jsx)(`div`,{className:`px-3 py-1 text-[11px] font-semibold uppercase tracking-wide text-bambu-gray/70 bg-bambu-dark-tertiary/40`,children:e})}function f1e({formData:e,updateField:t,cloudAuthenticated:n,loadingCloudPresets:r,presetInputValue:i,setPresetInputValue:a,selectedPresetOption:o,filamentOptions:s,availableBrands:c,availableMaterials:l,suggestedBrands:u,suggestedMaterials:d,quickAdd:f,detailsRequired:p,quantity:m,onQuantityChange:h,errors:g}){let{t:_}=U(),[v,b]=(0,y.useState)(!1),[x,S]=(0,y.useState)(!1),[C,w]=(0,y.useState)(!1),[T,E]=(0,y.useState)(!1),[D,O]=(0,y.useState)(``),[k,A]=(0,y.useState)(``),[j,M]=(0,y.useState)(``),[N,P]=(0,y.useState)(String(e.label_weight)),[F,I]=(0,y.useState)(!1),[L,R]=(0,y.useState)(new Set),z=(0,y.useRef)(null),B=(0,y.useRef)(null),V=(0,y.useRef)(null),ee=(0,y.useRef)(null);(0,y.useEffect)(()=>{let e=e=>{z.current&&!z.current.contains(e.target)&&b(!1),ee.current&&!ee.current.contains(e.target)&&E(!1),B.current&&!B.current.contains(e.target)&&S(!1),V.current&&!V.current.contains(e.target)&&w(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[]);let te=(0,y.useMemo)(()=>{if(!i)return s;let e=i.toLowerCase();return s.filter(t=>t.displayName.toLowerCase().includes(e)||t.code.toLowerCase().includes(e))},[s,i]),ne=(0,y.useMemo)(()=>{if(!D)return c;let e=D.toLowerCase();return c.filter(t=>t.toLowerCase().includes(e)).sort((t,n)=>{let r=t.toLowerCase()===e,i=n.toLowerCase()===e;return r&&!i?-1:!r&&i?1:t.localeCompare(n)})},[c,D]),re=(0,y.useMemo)(()=>{if(!k)return RH;let e=k.toLowerCase();return RH.filter(t=>t.toLowerCase().includes(e))},[k]),ie=(0,y.useMemo)(()=>{if(!j)return l;let e=j.toLowerCase();return l.filter(t=>t.toLowerCase().includes(e)).sort((t,n)=>{let r=t.toLowerCase()===e,i=n.toLowerCase()===e;return r&&!i?-1:!r&&i?1:t.localeCompare(n)})},[j,l]),ae=(0,y.useMemo)(()=>d1e(ne,u),[ne,u]),oe=(0,y.useMemo)(()=>d1e(ie,d),[ie,d]);(0,y.useEffect)(()=>{F||P(String(e.label_weight))},[e.label_weight,F]);let se=n=>{t(`slicer_filament`,n.code),a(n.displayName),b(!1);let r=WH(n.name),i=new Set,o=[[`material`,r.material],[`brand`,r.brand],[`subtype`,r.variant]];for(let[n,r]of o)r&&(e[n]&&!L.has(n)||(t(n,r),i.add(n)));R(i)},H=(e,n)=>{L.has(e)&&R(t=>{let n=new Set(t);return n.delete(e),n}),t(e,n)},ce=t=>(0,G.jsx)(`button`,{type:`button`,className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${e.brand===t?`bg-bambu-green/10 text-bambu-green`:`text-white`}`,onClick:()=>{H(`brand`,t),S(!1),O(``)},children:t},t),le=t=>(0,G.jsx)(`button`,{type:`button`,className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${e.material===t?`bg-bambu-green/10 text-bambu-green`:`text-white`}`,onClick:()=>{H(`material`,t),E(!1),M(``)},children:t},t);return(0,G.jsxs)(`div`,{className:`space-y-4`,children:[!f&&(0,G.jsx)(`div`,{className:`flex items-center gap-2 text-xs text-bambu-gray`,children:r?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-3 h-3 animate-spin`}),` `,_(`inventory.loadingPresets`)]}):n?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Ps,{className:`w-3 h-3 text-bambu-green`}),` `,_(`inventory.cloudConnected`)]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Ms,{className:`w-3 h-3`}),` `,_(`inventory.cloudNotConnected`)]})}),!f&&(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:[_(`inventory.slicerPreset`),p&&` *`]}),(0,G.jsxs)(`div`,{className:`relative`,ref:z,children:[(0,G.jsx)(Ql,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50 pointer-events-none`}),(0,G.jsx)(`input`,{type:`text`,className:`w-full pl-9 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`,placeholder:_(`inventory.searchPresets`),value:i,onChange:e=>{a(e.target.value),b(!0)},onFocus:()=>{b(!0),a(``)}}),v&&(0,G.jsx)(`div`,{className:`absolute z-50 w-full mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-64 overflow-y-auto`,children:te.length===0?(0,G.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:_(`inventory.noPresetsFound`)}):te.map(e=>(0,G.jsxs)(`button`,{type:`button`,className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary flex items-center gap-2 ${o?.code===e.code?`bg-bambu-green/10 text-bambu-green`:`text-white`}`,onClick:()=>se(e),children:[(0,G.jsx)(`span`,{className:`flex-1 min-w-0 truncate`,title:e.displayName,children:e.displayName}),(0,G.jsx)(p9,{source:e.source})]},`${e.code}::${e.name}`))})]}),o&&(0,G.jsxs)(`div`,{className:`mt-1 text-xs text-bambu-gray`,children:[_(`inventory.selectedPreset`),`: `,(0,G.jsx)(`span`,{className:`font-mono text-bambu-green`,children:o.code})]}),g?.slicer_filament&&(0,G.jsx)(`p`,{className:`mt-1 text-xs text-red-700 dark:text-red-400`,children:g.slicer_filament})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:[_(`inventory.material`),` *`]}),(0,G.jsxs)(`div`,{className:`relative`,ref:ee,children:[(0,G.jsx)(`input`,{type:`text`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`,placeholder:_(`inventory.selectMaterial`),value:T?j:e.material,onChange:e=>{M(e.target.value),E(!0)},onFocus:()=>{E(!0),M(``)}}),(0,G.jsx)(ps,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50 pointer-events-none`}),T&&(0,G.jsxs)(`div`,{className:`absolute z-50 w-full mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-48 overflow-y-auto`,children:[ie.length===0?(0,G.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:_(`inventory.noResults`)}):(0,G.jsxs)(G.Fragment,{children:[oe.top.length>0&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(m9,{label:_(`inventory.suggestedOptions`)}),oe.top.map(le)]}),oe.rest.length>0&&(0,G.jsxs)(G.Fragment,{children:[oe.top.length>0&&(0,G.jsx)(m9,{label:_(`inventory.allOptions`)}),oe.rest.map(le)]})]}),j&&!ie.includes(j)&&(0,G.jsx)(`button`,{type:`button`,className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary text-bambu-green border-t border-bambu-dark-tertiary`,onClick:()=>{H(`material`,j),E(!1),M(``)},children:_(`inventory.useCustomMaterial`,{material:j})})]})]}),g?.material&&(0,G.jsx)(`p`,{className:`mt-1 text-xs text-red-700 dark:text-red-400`,children:g.material})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:[_(`inventory.brand`),p&&` *`]}),(0,G.jsxs)(`div`,{className:`relative`,ref:B,children:[(0,G.jsx)(`input`,{type:`text`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`,placeholder:_(`inventory.searchBrand`),value:x?D:e.brand,onChange:e=>{O(e.target.value),S(!0)},onFocus:()=>{S(!0),O(``)}}),(0,G.jsx)(ps,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50 pointer-events-none`}),x&&(0,G.jsxs)(`div`,{className:`absolute z-50 w-full mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-48 overflow-y-auto`,children:[ne.length===0?(0,G.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:_(`inventory.noResults`)}):(0,G.jsxs)(G.Fragment,{children:[ae.top.length>0&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(m9,{label:_(`inventory.suggestedOptions`)}),ae.top.map(ce)]}),ae.rest.length>0&&(0,G.jsxs)(G.Fragment,{children:[ae.top.length>0&&(0,G.jsx)(m9,{label:_(`inventory.allOptions`)}),ae.rest.map(ce)]})]}),D&&!ne.includes(D)&&(0,G.jsx)(`button`,{type:`button`,className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary text-bambu-green border-t border-bambu-dark-tertiary`,onClick:()=>{H(`brand`,D),S(!1),O(``)},children:_(`inventory.useCustomBrand`,{brand:D})})]})]}),g?.brand&&(0,G.jsx)(`p`,{className:`mt-1 text-xs text-red-700 dark:text-red-400`,children:g.brand})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:[_(`inventory.subtype`),p&&` *`]}),(0,G.jsxs)(`div`,{className:`relative`,ref:V,children:[(0,G.jsx)(`input`,{type:`text`,value:C?k:e.subtype,onChange:e=>{A(e.target.value),w(!0)},onFocus:()=>{w(!0),A(``)},placeholder:`Basic, Matte, Silk...`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`}),(0,G.jsx)(ps,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50 pointer-events-none`}),C&&(0,G.jsxs)(`div`,{className:`absolute z-50 w-full mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-48 overflow-y-auto`,children:[re.length===0?(0,G.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:_(`inventory.noResults`)}):re.map(t=>(0,G.jsx)(`button`,{type:`button`,className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${e.subtype===t?`bg-bambu-green/10 text-bambu-green`:`text-white`}`,onClick:()=>{H(`subtype`,t),w(!1),A(``)},children:t},t)),k&&!RH.some(e=>e.toLowerCase()===k.toLowerCase().trim())&&(0,G.jsx)(`button`,{type:`button`,className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary text-bambu-green border-t border-bambu-dark-tertiary`,onClick:()=>{H(`subtype`,k),w(!1),A(``)},children:_(`inventory.useCustomBrand`,{brand:k})})]})]}),g?.subtype&&(0,G.jsx)(`p`,{className:`mt-1 text-xs text-red-700 dark:text-red-400`,children:g.subtype})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:_(`inventory.labelWeight`)}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(`input`,{type:`number`,className:`w-full px-3 py-2 pr-7 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`,value:N,min:0,onFocus:()=>I(!0),onChange:e=>P(e.target.value),onBlur:()=>{I(!1);let n=N.trim(),r=Number(n);if(!n||!Number.isFinite(r)||r<0){P(String(e.label_weight));return}let i=Math.round(r);t(`label_weight`,i),P(String(i))}}),(0,G.jsx)(`span`,{className:`absolute right-2 top-1/2 -translate-y-1/2 text-xs text-bambu-gray`,children:`g`})]})]}),f&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:_(`inventory.quantity`)}),(0,G.jsx)(`input`,{type:`number`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`,value:m,min:1,max:100,onChange:e=>{h(Math.max(1,Math.min(100,parseInt(e.target.value)||1)))}})]})]})}function p1e(e){let t=e.split(/[\s,]+/).map(e=>e.trim().replace(/^#/,``)).filter(Boolean),n=[],r=[];for(let e of t)(e.length===6||e.length===8)&&/^[0-9a-fA-F]+$/.test(e)?n.push(e.toLowerCase()):r.push(e);return{value:n.join(`,`),invalid:r}}function m1e({formData:e,updateField:t,recentColors:n,onColorUsed:r,catalogColors:i}){let{t:a}=U(),[o,s]=(0,y.useState)(!1),[c,l]=(0,y.useState)(``),u=(e.rgba.replace(`#`,``)+`FF`).substring(0,8).toUpperCase(),d=u.substring(0,6),f=u.substring(6,8)===`00`,[p,m]=(0,y.useState)(f?u:d);(0,y.useEffect)(()=>{m(f?u:d)},[d,u,f]);let h=e=>u===(e.replace(`#`,``)+`FF`).substring(0,8).toUpperCase(),g=e=>Mf(e),_=(e,n,i,a)=>{let o=e.replace(`#`,``).toUpperCase();if(t(`rgba`,o.length===8?o:o+`FF`),t(`color_name`,n),i!==void 0){let e=i??``;w(e),E([]),D.current=e,t(`extra_colors`,e)}a!==void 0&&t(`effect_type`,a??``),r({name:n,hex:e})},v=(0,y.useMemo)(()=>{if(i.length===0)return[];let t=e.brand?.trim(),n=e.material?.toLowerCase().trim(),r=e.subtype?.toLowerCase().trim();if(!t&&!n)return[];let a=t?t.toLowerCase().split(/[\s\-_]+/).filter(e=>e.length>=2):[],o=e=>{if(a.length===0)return!0;let t=e.toLowerCase();return a.some(e=>t.includes(e))};if(t&&!n){let e=i.filter(e=>o(e.manufacturer));if(e.length>0)return e.map(e=>({name:e.color_name,hex:e.hex_color.replace(`#`,``).substring(0,6),manufacturer:e.manufacturer,material:typeof e.material==`string`?e.material:void 0,extra_colors:e.extra_colors??null,effect_type:e.effect_type??null}))}let s=n&&r?`${n} ${r}`:``;if(s){let e=i.filter(e=>o(e.manufacturer)&&e.material?.toLowerCase()===s);if(e.length>0)return e.map(e=>({name:e.color_name,hex:e.hex_color.replace(`#`,``).substring(0,6),manufacturer:e.manufacturer,material:typeof e.material==`string`?e.material:void 0,extra_colors:e.extra_colors??null,effect_type:e.effect_type??null}));let t=s.replace(/\+$/,``);if(t!==s){let e=i.filter(e=>o(e.manufacturer)&&e.material?.toLowerCase()===t);if(e.length>0)return e.map(e=>({name:e.color_name,hex:e.hex_color.replace(`#`,``).substring(0,6),manufacturer:e.manufacturer,material:typeof e.material==`string`?e.material:void 0}))}}if(n){let e=i.filter(e=>o(e.manufacturer)&&(!e.material||e.material.toLowerCase().startsWith(n)));if(e.length>0)return e.map(e=>({name:e.color_name,hex:e.hex_color.replace(`#`,``).substring(0,6),manufacturer:e.manufacturer,material:typeof e.material==`string`?e.material:void 0,extra_colors:e.extra_colors??null,effect_type:e.effect_type??null}))}return[]},[i,e.brand,e.material,e.subtype]),b=(0,y.useMemo)(()=>{if(!c)return v;if(v.length===0)return[];let e=c.toLowerCase();return v.filter(t=>t.name.toLowerCase().includes(e)||(t.manufacturer?.toLowerCase().includes(e)??!1)||(t.material?.toLowerCase().includes(e)??!1))},[c,v]),x=v.length>0,S=(0,y.useMemo)(()=>c?BH.filter(e=>e.name.toLowerCase().includes(c.toLowerCase())):o?BH:zH,[c,o]),[C,w]=(0,y.useState)(e.extra_colors),[T,E]=(0,y.useState)([]),D=(0,y.useRef)(e.extra_colors);(0,y.useEffect)(()=>{e.extra_colors!==D.current&&(w(e.extra_colors),E([]),D.current=e.extra_colors)},[e.extra_colors]);let O=(0,y.useMemo)(()=>bH({rgba:e.rgba,extraColors:e.extra_colors,effectType:e.effect_type,subtype:e.subtype,effectSize:`bar`}),[e.rgba,e.extra_colors,e.effect_type,e.subtype]),k=e=>{if(w(e),!e.trim()){E([]),D.current=``,t(`extra_colors`,``);return}let{value:n,invalid:r}=p1e(e);E(r),D.current=n,t(`extra_colors`,n)};return(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsx)(`div`,{className:`h-10 rounded-lg border border-bambu-dark-tertiary`,style:O,"data-testid":`color-preview-banner`}),n.length>0&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 text-xs text-bambu-gray shrink-0`,children:[(0,G.jsx)(js,{className:`w-3 h-3`}),(0,G.jsx)(`span`,{children:a(`inventory.recentColors`)})]}),(0,G.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:n.map(e=>(0,G.jsx)(`button`,{type:`button`,onClick:()=>_(e.hex,e.name),className:`w-6 h-6 rounded border-2 transition-all hover:scale-110 ${h(e.hex)?`border-bambu-green ring-1 ring-bambu-green/30 scale-110`:`border-bambu-dark-tertiary`}`,style:g(e.hex),title:e.name},e.hex))})]}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(Ql,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50 pointer-events-none`}),(0,G.jsx)(`input`,{type:`text`,className:`w-full pl-9 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`,placeholder:a(`inventory.searchColors`),value:c,onChange:e=>l(e.target.value)})]}),x?(0,G.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:c?a(`inventory.searchResults`):`${e.brand}${e.material?` ${e.material}`:``}`}),(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-1.5`,children:[b.map(e=>(0,G.jsx)(`button`,{type:`button`,onClick:()=>_(e.hex,e.name,e.extra_colors,e.effect_type),className:`w-6 h-6 rounded border-2 transition-all hover:scale-110 hover:z-20 relative group ${h(e.hex)?`border-bambu-green ring-1 ring-bambu-green/30 scale-110`:`border-bambu-dark-tertiary`}`,style:g(e.hex),title:e.manufacturer&&e.material?`${e.name} (${e.manufacturer} — ${e.material})`:e.manufacturer?`${e.name} (${e.manufacturer})`:e.name,children:(0,G.jsx)(`span`,{className:`absolute -bottom-7 left-1/2 -translate-x-1/2 px-2 py-0.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-xs whitespace-nowrap opacity-0 group-hover:opacity-100 transition-opacity pointer-events-none z-20 shadow-lg text-white`,children:e.manufacturer&&e.material?`${e.name} (${e.manufacturer} — ${e.material})`:e.manufacturer?`${e.name} (${e.manufacturer})`:e.name})},`${e.hex}-${e.name}-${e.manufacturer??``}`)),b.length===0&&(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray py-1`,children:a(`inventory.noColorsFound`)})]})]}):(0,G.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between text-xs text-bambu-gray`,children:[(0,G.jsx)(`span`,{children:a(c?`inventory.searchResults`:o?`inventory.allColors`:`inventory.commonColors`)}),!c&&(0,G.jsx)(`button`,{type:`button`,onClick:()=>s(!o),className:`flex items-center gap-1 hover:text-white transition-colors`,children:o?(0,G.jsxs)(G.Fragment,{children:[a(`inventory.showLess`),` `,(0,G.jsx)(gs,{className:`w-3 h-3`})]}):(0,G.jsxs)(G.Fragment,{children:[a(`inventory.showAll`),` `,(0,G.jsx)(ps,{className:`w-3 h-3`})]})})]}),(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-1.5`,children:[S.map(e=>(0,G.jsx)(`button`,{type:`button`,onClick:()=>_(e.hex,e.name),className:`w-6 h-6 rounded border-2 transition-all hover:scale-110 hover:z-20 relative group ${h(e.hex)?`border-bambu-green ring-1 ring-bambu-green/30 scale-110`:`border-bambu-dark-tertiary`}`,style:g(e.hex),title:e.name,children:(0,G.jsx)(`span`,{className:`absolute -bottom-7 left-1/2 -translate-x-1/2 px-2 py-0.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-xs whitespace-nowrap opacity-0 group-hover:opacity-100 transition-opacity pointer-events-none z-20 shadow-lg text-white`,children:e.name})},e.hex)),S.length===0&&(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray py-1`,children:a(`inventory.noColorsFound`)})]})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:a(`inventory.colorName`)}),(0,G.jsx)(`input`,{type:`text`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`,placeholder:a(`inventory.colorNamePlaceholder`),value:e.color_name,onChange:e=>t(`color_name`,e.target.value)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:a(`inventory.hexColor`)}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsxs)(`div`,{className:`relative flex-1`,children:[(0,G.jsx)(`span`,{className:`absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray`,children:`#`}),(0,G.jsx)(`input`,{type:`text`,className:`w-full pl-7 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm font-mono uppercase focus:outline-none focus:border-bambu-green`,placeholder:`RRGGBB`,value:p.toUpperCase(),onChange:e=>{let n=e.target.value.replace(`#`,``).replace(/[^0-9A-Fa-f]/g,``).toUpperCase(),r=n.length>8?n.substring(0,8):n;m(r),r.length===6?t(`rgba`,r+`FF`):r.length===8&&t(`rgba`,r)},onBlur:()=>{if(p.length===7){let e=p+`0`;m(e),t(`rgba`,e)}else if(p.length>0&&p.length<6){let e=p.padEnd(6,`0`);m(e),t(`rgba`,e+`FF`)}}})]}),(0,G.jsx)(`input`,{type:`color`,className:`w-11 h-[38px] rounded-lg cursor-pointer border border-bambu-dark-tertiary shrink-0 bg-transparent`,value:`#${d}`,onChange:e=>{t(`rgba`,e.target.value.replace(`#`,``).toUpperCase()+`FF`)},title:a(`inventory.pickColor`)})]})]})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3 pt-2 border-t border-bambu-dark-tertiary/50`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:a(`inventory.extraColorsLabel`)}),(0,G.jsx)(`input`,{type:`text`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm font-mono placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`,placeholder:a(`inventory.extraColorsPlaceholder`),value:C,onChange:e=>k(e.target.value),"data-testid":`extra-colors-input`}),T.length>0&&(0,G.jsx)(`p`,{className:`text-xs text-red-700 dark:text-red-400 mt-1`,children:a(`inventory.extraColorsInvalid`,{tokens:T.join(`, `)})}),!T.length&&(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray/70 mt-1`,children:a(`inventory.extraColorsHint`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1 flex items-center gap-1.5`,children:[(0,G.jsx)(_u,{className:`w-3.5 h-3.5`}),a(`inventory.colorEffectLabel`)]}),(0,G.jsxs)(`div`,{className:`flex gap-2 items-stretch`,children:[(0,G.jsx)(`select`,{className:`flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`,value:e.effect_type,onChange:e=>t(`effect_type`,e.target.value),"data-testid":`effect-type-select`,children:_H.map(e=>(0,G.jsx)(`option`,{value:e.value,children:a(e.labelKey)},e.value||`none`))}),(0,G.jsx)(w8,{rgba:e.rgba,extraColors:e.extra_colors,effectType:e.effect_type,subtype:e.subtype,effectSize:`preview`,className:`w-10 h-10`,shape:`square`})]})]})]})]})}function h1e({catalog:e,value:t,onChange:n,catalogId:r,onCatalogIdChange:i}){let{t:a}=U(),[o,s]=(0,y.useState)(!1),[c,l]=(0,y.useState)(``),u=(0,y.useRef)(null),d=(0,y.useRef)(null);(0,y.useEffect)(()=>{let e=e=>{u.current&&!u.current.contains(e.target)&&s(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[]),(0,y.useEffect)(()=>{if(e.length===0)return;let n=e.filter(e=>e.weight===t);if(r){let n=e.find(e=>e.id===r);if(n&&n.weight===t)return}n.length===1?i(n[0].id):n.length===0&&r!==null&&i(null)},[t,e,r,i]);let f=(0,y.useMemo)(()=>{if(!c)return e;let t=c.toLowerCase();return e.filter(e=>e.name.toLowerCase().includes(t)||e.weight.toString().includes(t))},[e,c]),p=(0,y.useMemo)(()=>e.filter(e=>e.weight===t),[e,t]),m=(0,y.useMemo)(()=>{if(o)return c;if(r){let t=e.find(e=>e.id===r);if(t)return t.name}return p.length>0?p[0].name:``},[o,c,r,e,p]);return(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:(0,G.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Jl,{className:`w-3.5 h-3.5 text-bambu-gray`}),a(`inventory.coreWeight`)]})}),(0,G.jsxs)(`div`,{className:`flex gap-2 items-center`,children:[(0,G.jsxs)(`div`,{className:`flex-1 min-w-0 relative`,ref:u,children:[(0,G.jsx)(`input`,{ref:d,type:`text`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`,placeholder:a(`inventory.searchSpoolWeight`),value:m,onFocus:()=>{s(!0),l(``)},onChange:e=>{l(e.target.value),s(!0)}}),o&&(0,G.jsx)(`div`,{className:`absolute z-50 w-full mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-64 overflow-y-auto`,children:f.length===0?(0,G.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:a(`inventory.noResults`)}):f.map(e=>(0,G.jsxs)(`button`,{type:`button`,className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary flex justify-between items-center ${(r?e.id===r:e.weight===t)?`bg-bambu-green/10 text-bambu-green`:`text-white`}`,onClick:()=>{i(e.id),n(e.weight),s(!1),l(``)},children:[(0,G.jsx)(`span`,{className:`truncate`,children:e.name}),(0,G.jsxs)(`span`,{className:`font-mono text-xs text-bambu-gray ml-2 shrink-0`,children:[e.weight,`g`]})]},e.id))})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[(0,G.jsx)(`input`,{type:`number`,className:`w-16 px-2 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm text-center font-mono focus:outline-none focus:border-bambu-green`,value:t,min:0,max:2e3,onChange:e=>{let t=parseInt(e.target.value);!isNaN(t)&&t>=0&&n(t)}}),(0,G.jsx)(`span`,{className:`text-bambu-gray text-sm`,children:`g`})]})]})]})}function g1e({formData:e,updateField:t,spoolCatalog:n,currencySymbol:r,availableCategories:i,availableLocations:a=[],onCreateLocation:o,globalLowStockThreshold:s,spoolmanMode:c=!1}){let{t:l}=U(),{showToast:u}=qd(),[d,f]=(0,y.useState)(``),[p,m]=(0,y.useState)(!1),[h,g]=(0,y.useState)(``),[_,v]=(0,y.useState)(!1),[b,x]=(0,y.useState)(``),[S,C]=(0,y.useState)(!1),w=Math.max(0,e.label_weight-e.weight_used),T=e.core_weight+w;return(0,y.useEffect)(()=>{p||f(String(T))},[p,T]),(0,y.useEffect)(()=>{_||g(String(w))},[_,w]),(0,G.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-x-4 gap-y-4`,children:[(0,G.jsx)(`div`,{className:`sm:col-span-2`,children:c?(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray px-1`,children:l(`inventory.spoolWeightManagedBySpoolman`)}):(0,G.jsx)(h1e,{catalog:n,value:e.core_weight,onChange:e=>t(`core_weight`,e),catalogId:e.core_weight_catalog_id,onCatalogIdChange:e=>t(`core_weight_catalog_id`,e)})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:l(`inventory.currentWeight`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`div`,{className:`relative flex-1`,children:[(0,G.jsx)(`input`,{type:`number`,value:h,min:0,max:e.label_weight,onFocus:()=>v(!0),onChange:e=>{g(e.target.value)},onBlur:()=>{v(!1);let n=h.trim(),r=Number(n);if(!n||!Number.isFinite(r)||r<0||r>e.label_weight){g(String(w));return}let i=Math.round(r);t(`weight_used`,Math.max(0,e.label_weight-i)),g(String(i))},className:`w-full px-3 py-2 pr-7 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`}),(0,G.jsx)(`span`,{className:`absolute right-2 top-1/2 -translate-y-1/2 text-xs text-bambu-gray`,children:`g`})]}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray shrink-0`,children:[`/ `,e.label_weight,`g`]})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:l(`inventory.measuredWeight`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`div`,{className:`relative flex-1`,children:[(0,G.jsx)(`input`,{type:`number`,value:d,min:0,onFocus:()=>m(!0),onChange:e=>{f(e.target.value)},onBlur:()=>{m(!1);let n=d.trim(),r=Number(n),i=e.core_weight,a=e.core_weight+e.label_weight;if(!n||!Number.isFinite(r)||ra){u(l(`inventory.measuredWeightError`,{min:i,max:a}),`error`),f(String(T));return}let o=Math.round(r),s=Math.max(0,Math.min(e.label_weight,o-e.core_weight));t(`weight_used`,Math.max(0,e.label_weight-s)),f(String(o))},className:`w-full px-3 py-2 pr-7 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`}),(0,G.jsx)(`span`,{className:`absolute right-2 top-1/2 -translate-y-1/2 text-xs text-bambu-gray`,children:`g`})]}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray shrink-0`,children:[`/ `,e.core_weight+e.label_weight,`g`]})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:l(`inventory.costPerKg`,`Cost per kg`)}),(0,G.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,G.jsxs)(`div`,{className:`relative flex-1`,children:[(0,G.jsx)(`span`,{className:`absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray text-sm pointer-events-none`,children:r}),(0,G.jsx)(`input`,{type:`number`,value:e.cost_per_kg??``,min:0,step:.01,placeholder:`0.00`,onChange:e=>{t(`cost_per_kg`,e.target.value===``?null:parseFloat(e.target.value))},style:{paddingLeft:`${Math.max(2,r.length*.6+1)}rem`},className:`w-full py-2 pr-3 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`})]})})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,htmlFor:`spool-category`,children:l(`inventory.category`)}),(0,G.jsx)(`input`,{id:`spool-category`,type:`text`,list:`spool-category-options`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`,placeholder:l(`inventory.categoryPlaceholder`),value:e.category,maxLength:50,onChange:e=>t(`category`,e.target.value)}),i.length>0&&(0,G.jsx)(`datalist`,{id:`spool-category-options`,children:i.map(e=>(0,G.jsx)(`option`,{value:e},e))})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,htmlFor:`spool-low-stock-threshold`,children:l(`inventory.lowStockThresholdOverride`)}),(0,G.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,G.jsxs)(`div`,{className:`relative flex-1`,children:[(0,G.jsx)(`input`,{id:`spool-low-stock-threshold`,type:`number`,className:`w-full px-3 py-2 pr-8 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`,placeholder:String(s),value:e.low_stock_threshold_pct??``,min:1,max:99,step:1,onChange:e=>{let n=e.target.value;if(n===``){t(`low_stock_threshold_pct`,null);return}let r=Number(n);Number.isFinite(r)&&t(`low_stock_threshold_pct`,Math.min(99,Math.max(1,Math.round(r))))}}),(0,G.jsx)(`span`,{className:`absolute right-3 top-1/2 -translate-y-1/2 text-xs text-bambu-gray pointer-events-none`,children:`%`})]})}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:l(`inventory.lowStockThresholdOverrideHelp`,{global:s})})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,htmlFor:`spool-storage-location`,children:l(`inventory.storageLocation`)}),(0,G.jsxs)(`select`,{id:`spool-storage-location`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`,value:e.location_id??``,onChange:e=>{let n=e.target.value;if(!n){t(`location_id`,null);return}t(`location_id`,Number(n))},children:[(0,G.jsx)(`option`,{value:``,children:l(`inventory.storageLocationNone`)}),a.map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),o&&(0,G.jsxs)(`div`,{className:`mt-2 flex gap-2`,children:[(0,G.jsx)(`input`,{type:`text`,maxLength:255,className:`flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`,placeholder:l(`locations.createPlaceholder`),value:b,onChange:e=>x(e.target.value)}),(0,G.jsx)(`button`,{type:`button`,className:`px-3 py-2 text-sm rounded-lg bg-bambu-dark-tertiary text-white hover:bg-bambu-gray-dark disabled:opacity-50`,disabled:!b.trim()||S,onClick:async()=>{let e=b.trim();if(!(!e||!o)){C(!0);try{let n=await o(e);n&&(t(`location_id`,n.id),x(``))}finally{C(!1)}}},children:l(`locations.addShort`)})]})]}),(0,G.jsxs)(`div`,{className:`sm:col-span-2`,children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:l(`inventory.note`)}),(0,G.jsx)(`textarea`,{className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green resize-none min-h-[80px]`,placeholder:l(`inventory.notePlaceholder`),value:e.note,onChange:e=>t(`note`,e.target.value)})]})]})}function _1e({filaments:e,isLoading:t,selectedId:n,onSelect:r}){let{t:i}=U(),[a,o]=(0,y.useState)(!1),[s,c]=(0,y.useState)(``),l=(0,y.useRef)(null),u=(0,y.useRef)(null),d=(0,y.useMemo)(()=>e.find(e=>e.id===n)??null,[e,n]);(0,y.useEffect)(()=>{let e=e=>{l.current&&!l.current.contains(e.target)&&(o(!1),c(``))};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[]);let f=(0,y.useMemo)(()=>{let t=s.toLowerCase().trim();return t?e.filter(e=>e.name.toLowerCase().includes(t)||(e.material?.toLowerCase().includes(t)??!1)||(e.vendor?.name.toLowerCase().includes(t)??!1)||(e.color_name?.toLowerCase().includes(t)??!1)):e},[e,s]);(0,y.useEffect)(()=>{a&&u.current?.focus()},[a]);let p=()=>{o(!0),c(``)},m=e=>{r(e),o(!1),c(``)};return(0,G.jsxs)(`div`,{ref:l,className:`relative`,children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:i(`inventory.pickFromSpoolmanCatalog`)}),(0,G.jsxs)(`button`,{type:`button`,onClick:p,className:`w-full flex items-center gap-2 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-left focus:outline-none focus:border-bambu-green hover:border-bambu-gray transition-colors`,children:[t?(0,G.jsx)(Y,{className:`w-4 h-4 text-bambu-gray animate-spin shrink-0`}):d?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`span`,{className:`w-4 h-4 rounded-full shrink-0 border border-white/20`,style:Mf(d.color_hex),"aria-label":i(`inventory.spoolmanFilamentColorSwatch`)}),(0,G.jsxs)(`span`,{className:`text-white text-sm truncate flex-1`,children:[d.vendor?.name?`${d.vendor.name} — `:``,d.name]})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Cl,{className:`w-4 h-4 text-bambu-gray shrink-0`}),(0,G.jsx)(`span`,{className:`text-bambu-gray text-sm flex-1`,children:i(`inventory.spoolmanFilamentCatalog`)})]}),(0,G.jsx)(ps,{className:`w-4 h-4 text-bambu-gray shrink-0 ml-auto`})]}),a&&(0,G.jsxs)(`div`,{className:`absolute z-50 w-full mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl`,children:[(0,G.jsx)(`div`,{className:`p-2 border-b border-bambu-dark-tertiary`,children:(0,G.jsx)(`input`,{ref:u,type:`text`,value:s,onChange:e=>c(e.target.value),placeholder:i(`inventory.pickFromSpoolmanCatalog`),className:`w-full px-2 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm placeholder-bambu-gray focus:outline-none focus:border-bambu-green`})}),(0,G.jsx)(`ul`,{className:`max-h-56 overflow-y-auto py-1`,children:t?(0,G.jsxs)(`li`,{className:`flex items-center justify-center gap-2 py-4 text-bambu-gray text-sm`,children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),(0,G.jsx)(`span`,{children:i(`common.loading`,`Loading…`)})]}):f.length===0?(0,G.jsx)(`li`,{className:`py-4 text-center text-bambu-gray text-sm`,children:i(`inventory.noSpoolmanFilaments`)}):f.map(e=>(0,G.jsx)(`li`,{children:(0,G.jsxs)(`button`,{type:`button`,onClick:()=>m(e),className:`w-full flex items-center gap-2 px-3 py-2 text-left hover:bg-bambu-dark-tertiary transition-colors ${e.id===n?`bg-bambu-dark-tertiary`:``}`,children:[(0,G.jsx)(`span`,{className:`w-4 h-4 rounded-full shrink-0 border border-white/20`,style:Mf(e.color_hex),"aria-label":i(`inventory.spoolmanFilamentColorSwatch`)}),(0,G.jsxs)(`span`,{className:`flex-1 min-w-0`,children:[(0,G.jsxs)(`span`,{className:`block text-white text-sm truncate`,children:[e.vendor?.name?`${e.vendor.name} — `:``,e.name]}),(0,G.jsxs)(`span`,{className:`block text-bambu-gray text-xs truncate`,children:[[e.material,e.color_name].filter(Boolean).join(` · `),e.weight?` · ${e.weight}g`:``]})]})]})},e.id))})]})]})}function h9(e){let t=(e??``).trim().toUpperCase().slice(0,2);return t===`HH`||t===`HS`?t:null}function g9(e){return e?e===`HH`?`HF`:`S`:null}function v1e(e,t){let n=e.nozzles??[];return h9(n[(e.printer.nozzle_count??1)>1&&t>0?t:0]?.nozzle_type)??h9(n[0]?.nozzle_type)}function y1e(e){let t=new Set;for(let n of e.nozzles??[]){let e=(n?.nozzle_diameter??``).trim();e&&parseFloat(e)>0&&t.add(e)}for(let n of e.calibrations){let e=(n.nozzle_diameter??``).trim();e&&parseFloat(e)>0&&t.add(e)}return Array.from(t).sort((e,t)=>parseFloat(e)-parseFloat(t))}function b1e(e,t){return(e.printer.nozzle_count??1)>1?[{extruder:1,label:t.left},{extruder:0,label:t.right}]:[{extruder:0,label:t.single}]}function x1e({formData:e,printersWithCalibrations:t,filamentOptions:n,modelPresets:r,setModelPresets:i,selectedProfiles:a,setSelectedProfiles:o,selectedGroupId:s,setSelectedGroupId:c,printerModels:l,isLoading:u=!1}){let{t:d}=U(),f=(0,y.useMemo)(()=>{let e=new Map,n=[];for(let r of t){let t=(r.printer.model||``).trim();if(!t){n.push(r);continue}let i=e.get(t);i?i.push(r):e.set(t,[r])}return[...Array.from(e.entries()).map(([e,t])=>({id:`m:${e}`,model:e,printers:t,diameters:Array.from(new Set([...HH,...t.flatMap(y1e)])).sort((e,t)=>parseFloat(e)-parseFloat(t))})).sort((e,t)=>e.model.localeCompare(t.model)),...n.map(e=>({id:`p:${e.printer.id}`,model:``,printers:[e],diameters:Array.from(new Set([...HH,...y1e(e)])).sort((e,t)=>parseFloat(e)-parseFloat(t))}))]},[t]),p=f.find(e=>e.id===s)??f[0],m=(0,y.useMemo)(()=>{let e=new Map;return(t,r)=>{if(!t)return n;let i=e.get(t);if(i||(i=n.filter(e=>{let n=FH(e.name,l??{});return!n||DH(n,t)}),e.set(t,i)),r&&!i.some(e=>e.code===r)){let e=n.find(e=>e.code===r);if(e)return[e,...i]}return i}},[n,l]),h=[e.brand,e.material,e.subtype].map(e=>e.trim()).filter(Boolean).join(` `),g=/^[0-9A-Fa-f]{6,8}$/.test(e.rgba)?`#${e.rgba.slice(0,6)}`:`var(--bambu-gray, #808080)`,_=e=>b1e(e,{left:d(`inventory.leftNozzle`),right:d(`inventory.rightNozzle`),single:d(`inventory.nozzle`)}),v=t=>t.printer.connected?t.calibrations.filter(t=>nU(t,e)):[],b=e=>{let t=0;for(let n of e.printers){let r=v(n);for(let i of _(n))for(let o of e.diameters)r.some(e=>(e.extruder_id??0)===i.extruder&&((e.nozzle_diameter??``).trim()||`0.4`)===o)&&(a.get(eU(n.printer.id,i.extruder,o))||t++)}return t},x=(e,t,n)=>{i(r=>{let i=new Map(r),a=tU(e,t);return n?i.set(a,{code:n.code,name:n.name}):i.delete(a),i})},S=(e,t,n,r)=>{o(i=>{let a=new Map(i),o=eU(e,t,n);return r?a.set(o,r):a.delete(o),a})},C=()=>{let t=n.find(t=>t.code===e.slicer_filament);if(!t)return;let r=t.name.split(`@`)[0].trim().toLowerCase();r&&i(e=>{let t=new Map(e);for(let e of f){if(!e.model)continue;let n=m(e.model,void 0).filter(e=>e.name.toLowerCase().startsWith(r)&&FH(e.name,l??{})!==null);if(n.length!==0)for(let r of e.diameters){let i=n.find(e=>RegExp(`\\b${r.replace(`.`,`\\.`)}\\s*nozzle\\b`,`i`).test(e.name)),a=n.find(e=>!/\b[\d.]+\s*nozzle\b/i.test(e.name)),o=i??a;o&&t.set(tU(e.model,r),{code:o.code,name:o.name})}}return t})};if(t.length===0)return(0,G.jsx)(`div`,{className:`p-6 bg-bambu-dark rounded-lg text-center`,children:(0,G.jsxs)(`p`,{className:`text-bambu-gray flex items-center justify-center gap-2`,children:[u&&(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),d(u?`common.loading`:`inventory.noPrintersConfigured`)]})});let w=(e,t,n)=>{let i=tU(e,t),a=r.get(i),o=m(e,a?.code);return(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,G.jsx)(u1e,{ariaLabel:`${e} ${t}mm ${d(`inventory.filamentPreset`)}`,value:a?.code??``,options:o,inheritLabel:n,disabled:!e,onChange:n=>x(e,t,n)})}),(0,G.jsx)(`span`,{className:`text-[10px] font-semibold uppercase tracking-wide px-2 py-1 rounded-full shrink-0 ${a?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark-tertiary text-bambu-gray`}`,children:d(a?`inventory.presetOverride`:`inventory.presetInherited`)})]})};return(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(h||e.color_name)&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2.5 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg`,children:[(0,G.jsx)(`span`,{className:`w-5 h-5 rounded-full border border-white/15 shrink-0`,style:{background:g},"aria-hidden":`true`}),h&&(0,G.jsx)(`span`,{className:`text-sm text-white truncate`,children:h}),e.color_name&&(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray truncate`,children:e.color_name})]}),(0,G.jsxs)(`div`,{className:`flex flex-col md:flex-row gap-4`,children:[(0,G.jsx)(`div`,{role:`tablist`,"aria-label":d(`inventory.printersTab`),"aria-orientation":`vertical`,className:`md:w-52 md:shrink-0 md:self-start md:sticky md:top-0 flex md:flex-col gap-1.5 overflow-x-auto md:overflow-x-visible`,children:f.map(e=>{let t=e===p,n=b(e);return(0,G.jsxs)(`button`,{type:`button`,role:`tab`,onClick:()=>c(e.id),"aria-selected":t,className:`flex items-center gap-2 px-3 py-2 rounded-lg border text-left transition-colors shrink-0 md:shrink ${t?`bg-bambu-green/10 border-bambu-green/40 text-white`:`bg-transparent border-transparent text-bambu-gray hover:bg-bambu-dark hover:text-white`}`,children:[(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,G.jsx)(`div`,{className:`text-sm font-semibold truncate`,children:e.model||d(`inventory.unknownModel`)}),(0,G.jsx)(`div`,{className:`text-[11px] text-bambu-gray`,children:e.printers.length===1?d(`inventory.onePrinter`):d(`inventory.nPrinters`,{n:e.printers.length})})]}),n>0?(0,G.jsx)(`span`,{className:`text-[10px] font-mono px-1.5 py-0.5 rounded-full bg-bambu-dark-tertiary text-bambu-gray shrink-0`,children:n}):(0,G.jsx)(fs,{className:`w-3.5 h-3.5 text-bambu-green shrink-0`})]},e.id)})}),(0,G.jsx)(`div`,{className:`flex-1 min-w-0`,children:p&&(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsx)(`h4`,{className:`text-base font-semibold text-white truncate`,children:p.model||d(`inventory.unknownModel`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:p.printers.map(e=>e.printer.name).join(`, `)})]}),e.slicer_filament&&(0,G.jsxs)(`button`,{type:`button`,onClick:C,title:d(`inventory.autoMatchPresetsHint`),className:`flex items-center gap-1.5 px-2 py-1 text-xs bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray hover:text-white hover:border-bambu-green transition-colors shrink-0`,children:[(0,G.jsx)(_u,{className:`w-3.5 h-3.5`}),d(`inventory.autoMatchPresets`)]})]}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`p`,{className:`text-xs font-semibold text-bambu-gray uppercase tracking-wide`,children:d(`inventory.filamentPreset`)}),p.model?(0,G.jsx)(`div`,{className:`space-y-2`,children:p.diameters.map(e=>(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsxs)(`span`,{className:`text-xs font-mono text-bambu-gray w-14 shrink-0`,children:[e,`mm`]}),(0,G.jsx)(`div`,{className:`flex-1 min-w-0`,children:w(p.model,e,d(`inventory.presetUseSpoolDefault`))})]},e))}):(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray italic`,children:d(`inventory.presetNeedsModel`)})]}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`p`,{className:`text-xs font-semibold text-bambu-gray uppercase tracking-wide`,children:d(`inventory.kProfilesPerPrinter`)}),e.material?p.printers.map(e=>{let t=v(e);return(0,G.jsxs)(`div`,{className:`p-3 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,G.jsx)(Rl,{className:`w-3.5 h-3.5 text-bambu-gray shrink-0`}),(0,G.jsx)(`span`,{className:`text-sm font-semibold text-white truncate`,children:e.printer.name}),(0,G.jsx)(`span`,{className:`text-[10px] font-semibold uppercase tracking-wide px-2 py-0.5 rounded-full shrink-0 ${e.printer.connected?`bg-green-500/20 text-green-500`:`bg-bambu-dark-tertiary text-bambu-gray`}`,children:e.printer.connected?d(`inventory.connected`):d(`inventory.offline`)})]}),e.printer.connected?t.length===0?(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray italic py-1`,children:d(`inventory.noKProfilesMatch`)}):(0,G.jsxs)(`div`,{className:`grid gap-x-3 gap-y-1.5 items-center`,style:{gridTemplateColumns:`3.5rem repeat(${_(e).length}, minmax(0, 1fr))`},children:[(0,G.jsx)(`span`,{}),_(e).map(e=>(0,G.jsx)(`span`,{className:`text-[11px] font-semibold uppercase tracking-wide text-bambu-gray`,children:e.label},e.extruder)),p.diameters.map(n=>(0,G.jsxs)(y.Fragment,{children:[(0,G.jsxs)(`span`,{className:`text-xs font-mono text-bambu-gray`,children:[n,`mm`]}),_(e).map(r=>{let i=t.filter(e=>(e.extruder_id??0)===r.extruder&&((e.nozzle_diameter??``).trim()||`0.4`)===n),o=eU(e.printer.id,r.extruder,n),s=a.get(o);if(i.length===0)return(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray/50 px-2 py-1.5`,title:d(`inventory.noKProfilesMatch`),children:`—`},o);let c=v1e(e,r.extruder),l=h9(s?.nozzle_id),u=!!(c&&l&&c!==l);return(0,G.jsxs)(`select`,{title:u?d(`inventory.kProfileFlowMismatch`,{profile:g9(l),fitted:g9(c)}):void 0,"aria-label":`${e.printer.name} ${r.label} ${n}mm`,value:s?String(s.cali_idx):``,onChange:t=>{let a=i.find(e=>String(e.cali_idx)===t.target.value)??null;S(e.printer.id,r.extruder,n,a)},className:`min-w-0 px-2 py-1.5 bg-bambu-dark-secondary border rounded-lg text-sm text-white focus:outline-none focus:border-bambu-green ${u?`border-amber-500/60`:`border-bambu-dark-tertiary`}`,children:[(0,G.jsx)(`option`,{value:``,children:d(`inventory.kProfileNotSet`)}),i.map(e=>{let t=g9(h9(e.nozzle_id));return(0,G.jsx)(`option`,{value:e.cali_idx,children:`${t?`[${t}] `:``}${e.name||e.filament_id} K=${e.k_value.toFixed(3)}`},e.cali_idx)})]},o)})]},n))]}):(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray italic py-1`,children:d(`inventory.printerOffline`)})]},e.printer.id)}):(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray italic`,children:d(`inventory.selectMaterialFirst`)})]})]})})]})]})}function S1e(e){let t=rp(e);return t?t.toLocaleDateString(`en-GB`,{day:`2-digit`,month:`2-digit`,year:`2-digit`})+` `+t.toLocaleTimeString(`en-GB`,{hour:`2-digit`,minute:`2-digit`}):``}var C1e={completed:`text-bambu-green`,failed:`text-red-700 dark:text-red-400`,aborted:`text-yellow-700 dark:text-yellow-400`};function w1e({spoolId:e}){let{t}=U(),n=co(),{showToast:r}=qd(),{data:i,isLoading:a}=K({queryKey:[`spool-usage`,e],queryFn:()=>Z.getSpoolUsageHistory(e)}),o=q({mutationFn:()=>Z.clearSpoolUsageHistory(e),onSuccess:()=>{n.invalidateQueries({queryKey:[`spool-usage`,e]}),r(t(`inventory.historyCleared`),`success`)}});return a?(0,G.jsx)(`div`,{className:`flex justify-center py-4`,children:(0,G.jsx)(Y,{className:`w-5 h-5 animate-spin text-bambu-green`})}):!i||i.length===0?(0,G.jsxs)(`div`,{className:`text-center py-4 text-bambu-gray text-sm`,children:[(0,G.jsx)(js,{className:`w-5 h-5 mx-auto mb-2 opacity-50`}),t(`inventory.noUsageHistory`)]}):(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`h4`,{className:`text-sm font-medium text-white`,children:t(`inventory.usageHistory`)}),(0,G.jsxs)(Q,{variant:`ghost`,size:`sm`,onClick:()=>o.mutate(),disabled:o.isPending,className:`text-xs text-bambu-gray hover:text-red-700 dark:hover:text-red-400`,children:[(0,G.jsx)(Pu,{className:`w-3 h-3 mr-1`}),t(`inventory.clearHistory`)]})]}),(0,G.jsx)(`div`,{className:`max-h-48 overflow-y-auto space-y-1`,children:i.map(e=>(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-2 rounded bg-bambu-dark/50 text-xs`,children:[(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:S1e(e.created_at)}),e.print_name&&(0,G.jsx)(`span`,{className:`text-white ml-2 truncate`,title:e.print_name,children:e.print_name})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0 ml-2`,children:[(0,G.jsxs)(`span`,{className:`text-white font-medium`,children:[e.weight_used.toFixed(1),`g`]}),(0,G.jsxs)(`span`,{className:`text-bambu-gray`,children:[`(`,e.percent_used,`%)`]}),(0,G.jsx)(`span`,{className:C1e[e.status]||`text-bambu-gray`,children:e.status})]})]},e.id))})]})}var T1e={tag_uid:null,tray_uuid:null,tag_type:null,data_origin:null};function E1e({isOpen:e,onClose:t,spool:n,mode:r,printersWithCalibrations:i=[],currencySymbol:a,onSpoolsCreated:o,spoolmanMode:s=!1,spoolsQueryKey:c=[`inventory-spools`]}){let{t:l}=U(),u=co(),{showToast:d}=qd(),f=()=>b6(u,c),p=r===`edit`,m=r===`copy`,[h,g]=(0,y.useState)(f9),[_,v]=(0,y.useState)({}),[b,x]=(0,y.useState)(`filament`),[S,C]=(0,y.useState)(!1),[w,T]=(0,y.useState)(!1),[E,D]=(0,y.useState)(!1),[O,k]=(0,y.useState)(1),[A,j]=(0,y.useState)(!1),[M,N]=(0,y.useState)(!1),[P,F]=(0,y.useState)([]),[I,L]=(0,y.useState)(new Set),[R,z]=(0,y.useState)(``),[B,V]=(0,y.useState)([]),[ee,te]=(0,y.useState)([]),[ne,re]=(0,y.useState)([]),[ie,ae]=(0,y.useState)([]),[oe,se]=(0,y.useState)([]),[H,ce]=(0,y.useState)([]),[le,ue]=(0,y.useState)([]),[de,fe]=(0,y.useState)(!1),[pe,me]=(0,y.useState)(new Map),[he,ge]=(0,y.useState)(new Map),[_e,ve]=(0,y.useState)(``),ye=i.length>0?i:le,be=pe.size+he.size,{data:xe=[],isLoading:Se,error:Ce}=K({queryKey:[`spoolman-inventory-filaments`],queryFn:()=>Z.getSpoolmanInventoryFilaments(),enabled:s&&e,staleTime:6e4,retry:!1});(0,y.useEffect)(()=>{ce(XH())},[]),(0,y.useEffect)(()=>{let t=!1;return e&&((async()=>{N(!0);try{let[e,n]=await Promise.allSettled([(async()=>(await Z.getCloudStatus()).is_authenticated?{connected:!0,presets:await Z.getFilamentPresets()}:{connected:!1,presets:[]})(),(async()=>(await Z.orcaCloudStatus()).connected?{connected:!0,presets:(await Z.orcaCloudListProfiles()).filament}:{connected:!1,presets:[]})()]);if(t)return;let r=e.status===`fulfilled`&&e.value.connected,i=n.status===`fulfilled`&&n.value.connected,a=e.status===`fulfilled`?e.value.presets:[],o=n.status===`fulfilled`?n.value.presets:[];j(r||i),F([...a,...o]),L(new Set(o.map(e=>e.setting_id)))}catch(e){if(t)return;console.error(`Failed to fetch cloud presets:`,e),j(!1)}finally{t||N(!1)}})(),s||Z.getSpoolCatalog().then(V).catch(console.error),Z.getColorCatalog().then(se).catch(console.error),Z.getLocalPresets().then(e=>re(e.filament)).catch(console.error),Z.getBuiltinFilaments().then(ae).catch(console.error),Z.getLocations().then(e=>te(e.map(e=>({id:e.id,name:e.name})))).catch(console.error),i.length===0&&(async()=>{fe(!0);try{let e=await Z.getPrinters(),n=await Promise.all(e.map(e=>Z.getPrinterStatus(e.id).catch(()=>null))),r=await Promise.all(e.map(async(e,t)=>{let r=n[t],i=r?.connected??!1,a=[];return i&&(a=await UH(e.id,r)),{printer:{...e,connected:i},calibrations:a,nozzles:r?.nozzles}}));t||ue(r)}catch(e){console.error(`Failed to fetch printer calibrations:`,e)}finally{t||fe(!1)}})()),()=>{t=!0}},[e,i.length]);let we=(0,y.useMemo)(()=>KH(P,new Set,ne,ie,I),[P,ne,ie,I]),Te=(0,y.useMemo)(()=>{let e=GH(P,ne),t=oe.map(e=>e.manufacturer?.trim()).filter(e=>!!e),n=new Set([...e,...t]);return Array.from(n).sort((e,t)=>e.localeCompare(t))},[P,ne,oe]),Ee=(0,y.useMemo)(()=>{let e=oe.map(e=>e.material?.trim()).filter(e=>!!e),t=new Set([...IH,...e]);return Array.from(t).sort((e,t)=>e.localeCompare(t))},[oe]),De=(0,y.useMemo)(()=>{let e=[];for(let t of oe){let n=t.manufacturer?.trim(),r=t.material?.trim();n&&r&&e.push({brand:n,material:r})}for(let t of P){let n=WH(t.name);n.brand&&n.material&&e.push({brand:n.brand,material:n.material})}for(let t of ne){let n=WH(t.name),r=t.filament_vendor?.trim()||n.brand,i=n.material;r&&i&&e.push({brand:r,material:i})}return e},[P,oe,ne]),Oe=(0,y.useMemo)(()=>{let e=new Map;for(let t of De){let n=t.brand.toLowerCase(),r=t.material.toLowerCase();e.has(n)||e.set(n,new Set),e.get(n).add(r)}return e},[De]),ke=(0,y.useMemo)(()=>{let e=new Map;for(let t of De){let n=t.brand.toLowerCase(),r=t.material.toLowerCase();e.has(r)||e.set(r,new Set),e.get(r).add(n)}return e},[De]),Ae=(0,y.useMemo)(()=>JH(Te,h.brand),[Te,h.brand]),je=(0,y.useMemo)(()=>JH(Ee,h.material),[Ee,h.material]),Me=(0,y.useMemo)(()=>YH(Ae,h.material,ke),[Ae,h.material,ke]),Ne=(0,y.useMemo)(()=>YH(je,h.brand,Oe),[je,h.brand,Oe]),Pe=(0,y.useMemo)(()=>qH(h.slicer_filament,we),[h.slicer_filament,we]);(0,y.useEffect)(()=>{if(e){if(n){let e=n.rgba&&/^[0-9A-Fa-f]{8}$/.test(n.rgba)?n.rgba:`808080FF`;if(g({material:n.material||``,subtype:n.subtype||``,brand:n.brand||``,color_name:n.color_name_is_synthesized?``:n.color_name||``,rgba:e,extra_colors:n.extra_colors||``,effect_type:n.effect_type||``,label_weight:n.label_weight||1e3,core_weight:n.core_weight||250,core_weight_catalog_id:n.core_weight_catalog_id??null,weight_used:m?0:n.weight_used||0,slicer_filament:n.slicer_filament||``,note:n.note||``,cost_per_kg:n.cost_per_kg??null,category:n.category||``,low_stock_threshold_pct:n.low_stock_threshold_pct??null,location_id:n.location_id??null,spoolman_filament_id:null}),z(n.slicer_filament_name||n.slicer_filament||``),n.k_profiles&&n.k_profiles.length>0){let e=new Map;for(let t of n.k_profiles){if(t.cali_idx===null||t.cali_idx===void 0)continue;let n=(t.nozzle_diameter||``).trim()||`0.4`,r=t.extruder??0;e.set(eU(t.printer_id,r,n),{cali_idx:t.cali_idx,filament_id:``,setting_id:t.setting_id||``,name:t.name||``,k_value:t.k_value,n_coef:0,extruder_id:r,nozzle_diameter:n,nozzle_id:t.nozzle_type||``})}me(e)}else me(new Map)}else g(f9),z(``),me(new Map);D(!1),k(1),v({}),x(`filament`),ve(``),ge(new Map),C(!1),T(!1)}},[e,n,r,m]),(0,y.useEffect)(()=>{if(!e||!n)return;let t=!1;return(s?Z.getSpoolmanFilamentPresets:Z.getSpoolFilamentPresets)(n.id).then(e=>{if(t)return;let n=new Map;for(let t of e)n.set(tU(t.printer_model,t.nozzle_diameter||``),{code:t.slicer_filament||``,name:t.slicer_filament_name||``});ge(n)}).catch(e=>{t||(console.error(`Failed to load filament preset overrides:`,e),d(l(`inventory.filamentPresetsLoadFailed`),`warning`))}),()=>{t=!0}},[e,n?.id,s]),(0,y.useEffect)(()=>{if(!e||!n||w||h.location_id!=null)return;let t=n.storage_location?.trim();if(!t||ee.length===0)return;let r=ee.find(e=>e.name.toLowerCase()===t.toLowerCase());r&&g(e=>e.location_id===r.id?e:{...e,location_id:r.id})},[e,n,ee,h.location_id,w]);let Fe=(e,t)=>{let n=s1e.has(e);s&&n&&h.spoolman_filament_id!==null&&d(l(`inventory.spoolmanFilamentUnlinked`),`info`),g(r=>({...r,[e]:t,...s&&n&&r.spoolman_filament_id!==null?{spoolman_filament_id:null}:{}})),e===`weight_used`&&C(!0),e===`location_id`&&T(!0),_[e]&&v(t=>({...t,[e]:void 0}))},Ie=e=>{let t=e.material||``,n=e.name||``,r=t&&n.startsWith(t)?n.slice(t.length).trim():n,i=(e.color_hex??``).replace(`#`,``).toUpperCase(),a=/^[0-9A-F]{6}(?:[0-9A-F]{2})?$/.test(i)?i:`808080`,o=a.length===8?a:`${a}FF`;g(n=>({...n,spoolman_filament_id:e.id,material:t,subtype:r,brand:e.vendor?.name||``,rgba:o,color_name:e.color_name||``,label_weight:e.weight??n.label_weight})),d(l(`inventory.spoolmanFilamentSelected`),`success`)},Le=e=>{ce(t=>ZH(e,t))},Re=q({mutationFn:e=>s?Z.createSpoolmanInventorySpool(e):Z.createSpool(e),onSuccess:async e=>{e?.id&&!await Ze(e.id)||(await f(),o&&o([e]),d(l(`inventory.spoolCreated`),`success`),t())},onError:e=>{e instanceof sd&&e.status===503?d(l(`inventory.spoolmanUnreachable`),`error`):d(l(`inventory.saveFailed`),`error`)}}),ze=q({mutationFn:({data:e,qty:t})=>s?Z.bulkCreateSpoolmanInventorySpools(e,t):Z.bulkCreateSpools(e,t),onSuccess:async e=>{let n=s&&`created`in e?e:null,r=n?n.created:e;if(pe.size>0||he.size>0)for(let e of r)await Ze(e.id);await f(),o&&o(r),n&&n.failed_count>0?d(l(`inventory.spoolsPartiallyCreated`,{created:r.length,total:n.requested_count}),`warning`):d(l(`inventory.spoolsCreated`,{count:r.length}),`success`),t()},onError:e=>{e instanceof sd&&e.status===503?d(l(`inventory.spoolmanUnreachable`),`error`):d(l(`inventory.saveFailed`),`error`)}}),Be=q({mutationFn:e=>s?Z.updateSpoolmanInventorySpool(n.id,e):Z.updateSpool(n.id,e),onSuccess:async()=>{n?.id&&!await Ze(n.id)||(await f(),d(l(`inventory.spoolUpdated`),`success`),t())},onError:e=>{e instanceof sd&&e.status===503?d(l(`inventory.spoolmanUnreachable`),`error`):d(l(`inventory.saveFailed`),`error`)}}),Ve=q({mutationFn:()=>s?Z.updateSpoolmanInventorySpool(n.id,T1e):Z.updateSpool(n.id,T1e),onSuccess:async()=>{await f(),d(l(`inventory.rfidCleared`,`RFID tag cleared`),`success`),t()},onError:e=>{e instanceof sd&&e.status===503?d(l(`inventory.spoolmanUnreachable`),`error`):d(l(`inventory.tagClearFailed`),`error`)}}),{data:He}=K({queryKey:[`spool-assignments`],queryFn:()=>Z.getAssignments(),enabled:e&&p&&!s}),{data:Ue}=K({queryKey:[`spoolman-slot-assignments-all`],queryFn:()=>Z.getSpoolmanSlotAssignments(),enabled:e&&p&&s}),We=(()=>{if(n)return s?Ue?.find(e=>e.spoolman_spool_id===n.id):He?.find(e=>e.spool_id===n.id)})(),{data:Ge}=K({queryKey:[`inventory-spools`],queryFn:()=>Z.getSpools(!0),enabled:e}),{data:Ke}=K({queryKey:[`settings`],queryFn:Z.getSettings,enabled:e}),{data:qe}=K({queryKey:[`slicerPrinterModels`],queryFn:Z.getSlicerPrinterModels,enabled:e,staleTime:1/0}),Je=(()=>{let e=new Set;for(let t of Ge??[]){let n=t.category?.trim();n&&e.add(n)}return Array.from(e).sort((e,t)=>e.localeCompare(t))})(),Ye=Ke?.low_stock_threshold??20,Xe=q({mutationFn:async()=>{if(!We)throw Error(`No assignment`);if(s){if(!n)throw Error(`No spool`);await Z.unassignSpoolmanSlot(n.id);return}await Z.unassignSpool(We.printer_id,We.ams_id,We.tray_id)},onSuccess:async()=>{s?(await u.invalidateQueries({queryKey:[`spoolman-slot-assignments-all`]}),await u.invalidateQueries({queryKey:[`spoolman-slot-assignments`]})):await u.invalidateQueries({queryKey:[`spool-assignments`]}),d(l(`inventory.unassignSuccess`,`Spool unassigned`),`success`),t()},onError:e=>{d(e.message,`error`)}}),Ze=async e=>{let t=s?Z.saveSpoolmanKProfiles:Z.saveSpoolKProfiles,n=s?Z.saveSpoolmanFilamentPresets:Z.saveSpoolFilamentPresets,r=[];for(let[e,t]of pe){let[n,i,a]=e.split(`:`);r.push({printer_id:parseInt(n),extruder:parseInt(i),nozzle_diameter:a||`0.4`,nozzle_type:h9(t.nozzle_id),k_value:t.k_value,name:t.name||null,cali_idx:t.cali_idx,setting_id:t.setting_id||null})}let i=[];for(let[e,t]of he){let{model:n,diameter:r}=xke(e);n&&i.push({printer_model:n,nozzle_diameter:r,slicer_filament:t.code||null,slicer_filament_name:t.name||null})}try{await t(e,r)}catch(e){return console.error(`Failed to save K-profiles:`,e),d(l(`inventory.kProfileSaveFailed`),`warning`),!1}try{await n(e,i)}catch(e){return console.error(`Failed to save filament preset overrides:`,e),d(l(`inventory.filamentPresetSaveFailed`),`warning`),!1}return!0};if((0,y.useEffect)(()=>{if(!e)return;let n=e=>{e.key===`Escape`&&t()};return document.addEventListener(`keydown`,n),()=>document.removeEventListener(`keydown`,n)},[e,t]),!e)return null;let Qe=()=>{let e=c1e(h,E,s,r);if(!e.isValid){v(e.errors),(e.errors.slicer_filament||e.errors.material||e.errors.brand||e.errors.subtype)&&x(`filament`);return}let t=Pe?.displayName||R||null,n={material:h.material||null,subtype:h.subtype||null,brand:h.brand||null,color_name:h.color_name||null,rgba:h.rgba||null,extra_colors:h.extra_colors||null,effect_type:h.effect_type||null,label_weight:h.label_weight,...s?{}:{core_weight:h.core_weight,core_weight_catalog_id:h.core_weight_catalog_id},slicer_filament:h.slicer_filament||null,slicer_filament_name:t,nozzle_temp_min:null,nozzle_temp_max:null,note:h.note||null,cost_per_kg:h.cost_per_kg,category:h.category.trim()||null,low_stock_threshold_pct:h.low_stock_threshold_pct,...s?{spoolman_filament_id:h.spoolman_filament_id}:{}};(!p||S)&&(n.weight_used=h.weight_used),(!p||w)&&(n.location_id=h.location_id),p?Be.mutate(n):O>1?ze.mutate({data:n,qty:O}):Re.mutate(n)},$e=Re.isPending||ze.isPending||Be.isPending||Ve.isPending||Xe.isPending;return(0,G.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[(0,G.jsx)(`div`,{className:`absolute inset-0 bg-black/60 backdrop-blur-sm`,onClick:t}),(0,G.jsxs)(`div`,{className:`relative w-full max-w-5xl mx-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl shadow-2xl max-h-[90vh] flex flex-col`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary flex-shrink-0`,children:[(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-baseline gap-2`,children:[l(p?`inventory.editSpool`:m?`inventory.copySpool`:`inventory.addSpool`),p&&n&&(0,G.jsxs)(`span`,{className:`text-sm font-mono text-bambu-gray`,children:[`#`,n.id]})]}),(0,G.jsx)(`button`,{onClick:t,className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]}),r===`create`&&(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2 border-b border-bambu-dark-tertiary flex-shrink-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(id,{className:`w-4 h-4 text-amber-600 dark:text-amber-400`}),(0,G.jsx)(`span`,{className:`text-sm text-white`,children:l(`inventory.quickAdd`)})]}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>{D(!E),E||x(`filament`)},className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors ${E?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,children:(0,G.jsx)(`span`,{className:`inline-block h-3.5 w-3.5 rounded-full bg-white transition-transform ${E?`translate-x-4`:`translate-x-0.5`}`})})]}),(0,G.jsxs)(`div`,{className:`flex border-b border-bambu-dark-tertiary flex-shrink-0`,children:[(0,G.jsxs)(`button`,{onClick:()=>x(`filament`),className:`flex-1 px-4 py-2.5 text-sm font-medium flex items-center justify-center gap-2 transition-colors ${b===`filament`?`text-bambu-green border-b-2 border-bambu-green`:`text-bambu-gray hover:text-white`}`,children:[(0,G.jsx)(Go,{className:`w-4 h-4`}),l(`inventory.filamentInfoTab`)]}),!E&&(0,G.jsxs)(`button`,{onClick:()=>x(`appearance`),className:`flex-1 px-4 py-2.5 text-sm font-medium flex items-center justify-center gap-2 transition-colors ${b===`appearance`?`text-bambu-green border-b-2 border-bambu-green`:`text-bambu-gray hover:text-white`}`,children:[(0,G.jsx)(wl,{className:`w-4 h-4`}),l(`inventory.colorAndCostTab`)]}),!E&&(0,G.jsxs)(`button`,{onClick:()=>x(`printers`),className:`flex-1 px-4 py-2.5 text-sm font-medium flex items-center justify-center gap-2 transition-colors ${b===`printers`?`text-bambu-green border-b-2 border-bambu-green`:`text-bambu-gray hover:text-white`}`,children:[(0,G.jsx)(id,{className:`w-4 h-4`}),l(`inventory.printersTab`),be>0&&(0,G.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded-full bg-bambu-green/20 text-bambu-green`,children:be})]})]}),(0,G.jsx)(`div`,{className:`p-4 overflow-y-auto flex-1`,style:{scrollbarGutter:`stable`},children:b===`filament`?(0,G.jsxs)(`div`,{className:`space-y-6`,children:[s&&!p&&(0,G.jsx)(`div`,{children:Ce?(0,G.jsx)(`p`,{className:`text-sm text-red-700 dark:text-red-400 px-1`,children:l(`inventory.spoolmanCatalogLoadFailed`)}):(0,G.jsx)(_1e,{filaments:xe,isLoading:Se,selectedId:h.spoolman_filament_id,onSelect:Ie})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`text-sm font-semibold text-bambu-gray uppercase tracking-wide mb-3`,children:l(`inventory.filamentInfo`)}),(0,G.jsx)(f1e,{formData:h,updateField:Fe,cloudAuthenticated:A,loadingCloudPresets:M,presetInputValue:R,setPresetInputValue:z,selectedPresetOption:Pe,filamentOptions:we,availableBrands:Ae,availableMaterials:je,suggestedBrands:Me,suggestedMaterials:Ne,quickAdd:E,detailsRequired:!E&&!s&&r===`create`,quantity:O,onQuantityChange:k,errors:_})]})]}):b===`appearance`?(0,G.jsxs)(`div`,{className:`space-y-6`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`text-sm font-semibold text-bambu-gray uppercase tracking-wide mb-3`,children:l(`inventory.color`)}),(0,G.jsx)(m1e,{formData:h,updateField:Fe,recentColors:H,onColorUsed:Le,catalogColors:oe})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`text-sm font-semibold text-bambu-gray uppercase tracking-wide mb-3`,children:l(`inventory.additional`)}),(0,G.jsx)(g1e,{formData:h,updateField:Fe,spoolCatalog:B,currencySymbol:a,availableCategories:Je,availableLocations:ee,onCreateLocation:async e=>{try{let t=await Z.createLocation({name:e});return te(e=>[...e,{id:t.id,name:t.name}].sort((e,t)=>e.name.localeCompare(t.name))),await y6(u),{id:t.id,name:t.name}}catch(e){return console.error(e),d((e instanceof Error?e.message:l(`locations.saveFailed`))||l(`locations.saveFailed`),`error`),null}},globalLowStockThreshold:Ye,spoolmanMode:s})]}),p&&n&&!s&&(0,G.jsx)(`div`,{children:(0,G.jsx)(w1e,{spoolId:n.id})})]}):(0,G.jsx)(x1e,{formData:h,printersWithCalibrations:ye,filamentOptions:we,modelPresets:he,setModelPresets:ge,selectedProfiles:pe,setSelectedProfiles:me,selectedGroupId:_e,setSelectedGroupId:ve,printerModels:qe,isLoading:de})}),(0,G.jsxs)(`div`,{className:`flex gap-2 p-4 border-t border-bambu-dark-tertiary flex-shrink-0`,children:[p&&(0,G.jsxs)(`div`,{className:`flex gap-2 mr-auto`,children:[(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>Ve.mutate(),disabled:$e||!n?.tag_uid,children:[(0,G.jsx)(Eu,{className:`w-4 h-4`}),l(`inventory.clearRfid`,`Clear RFID Tag`)]}),(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>Xe.mutate(),disabled:$e||!We,children:[(0,G.jsx)(Bu,{className:`w-4 h-4`}),l(`inventory.unassignSpool`,`Unassign`)]})]}),(0,G.jsxs)(`div`,{className:`flex gap-2 ml-auto`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:t,children:l(`common.cancel`)}),(0,G.jsx)(Q,{onClick:Qe,disabled:$e,children:$e?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),l(`common.saving`)]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(ql,{className:`w-4 h-4`}),l(p?`common.save`:m?`inventory.copySpool`:`inventory.addSpool`)]})})]})]})]})]})}var D1e=[{value:`ams_holder_74x33`,i18nKey:`amsHolderSmall`,fallbackLabel:`AMS holder — small (74 × 33 mm)`,fallbackHint:`Single label per page; matches the printable label from MakerWorld model 752566 (AMS Filament Label Holder).`},{value:`ams_holder_75x55`,i18nKey:`amsHolderLarge`,fallbackLabel:`AMS holder — large (75 × 55 mm)`,fallbackHint:`Single label per page; fits the cardstock-insert variant of the AMS Filament Label Holder. Roomy enough for swatch, brand, material, ID, and QR code.`},{value:`box_40x30`,i18nKey:`box40x30`,fallbackLabel:`Box label (40 × 30 mm)`,fallbackHint:`Single label per page; common DK/Brother roll size, good for filament-bag and storage-bin labels.`},{value:`box_62x29`,i18nKey:`box`,fallbackLabel:`Box label (62 × 29 mm)`,fallbackHint:`Single label per page; sized for Brother PT/QL and Dymo small labels.`},{value:`avery_l7160`,i18nKey:`averyL7160`,fallbackLabel:`Avery L7160 — A4 sheet (38.1 × 63.5 mm × 21)`,fallbackHint:`EU sheet stock; 21 labels per A4 page.`},{value:`avery_5160`,i18nKey:`avery5160`,fallbackLabel:`Avery 5160 — US Letter sheet (25.4 × 66.7 mm × 30)`,fallbackHint:`US sheet stock; 30 labels per Letter page.`}],_9={avery_l7160:21,avery_5160:30},v9=Math.max(...Object.values(_9));function O1e(e){let t=window.URL.createObjectURL(e);if(!window.open(t,`_blank`)){let e=document.createElement(`a`);e.href=t,e.download=`bambuddy-labels.pdf`,document.body.appendChild(e),e.click(),document.body.removeChild(e)}setTimeout(()=>window.URL.revokeObjectURL(t),6e4)}function k1e(e){return Mf(e)}function A1e(e){return`${e.color_name??`${e.material}${e.subtype?` ${e.subtype}`:``}`}${e.brand?` · ${e.brand}`:``}`}function j1e(e){return[e.color_name,e.material,e.subtype,e.brand,`#${e.id}`].filter(Boolean).join(` `).toLowerCase()}function M1e(e){if(!e)return[1,0];let t=e.replace(/^#/,``).slice(0,6);if(t.length!==6)return[1,0];let n=parseInt(t.slice(0,2),16),r=parseInt(t.slice(2,4),16),i=parseInt(t.slice(4,6),16);if([n,r,i].some(Number.isNaN))return[1,0];let a=n/255,o=r/255,s=i/255,c=Math.max(a,o,s),l=Math.min(a,o,s),u=(c+l)/2,d=c-l;if((d===0?0:d/(1-Math.abs(2*u-1)))<.1)return[1,u];let f=0;return f=c===a?(o-s)/d%6:c===o?(s-a)/d+2:(a-o)/d+4,f*=60,f<0&&(f+=360),[0,f]}function N1e({isOpen:e,onClose:t,availableSpools:n,initialSelectedIds:r,spoolmanMode:i}){let{t:a}=U(),{showToast:o}=qd(),[s,c]=(0,y.useState)(null),[l,u]=(0,y.useState)(new Set),[d,f]=(0,y.useState)(``),[p,m]=(0,y.useState)(``),[h,g]=(0,y.useState)(`id`),[_,v]=(0,y.useState)(!1),[b,x]=(0,y.useState)(`1`);(0,y.useEffect)(()=>{if(e){let e=new Set(n.map(e=>e.id));u(new Set(r.filter(t=>e.has(t)))),f(``),m(``),g(`id`),v(!1),x(`1`),c(null)}},[e]);let S=(0,y.useMemo)(()=>{let e=[...n];return h===`color`?(e.sort((e,t)=>{let n=M1e(e.rgba),r=M1e(t.rgba);return n[0]===r[0]?n[1]===r[1]?e.id-t.id:n[1]-r[1]:n[0]-r[0]}),e):(e.sort((e,t)=>e.id-t.id),e)},[n,h]),C=(0,y.useMemo)(()=>{let e=new Set;for(let t of S)t.material&&e.add(t.material.toUpperCase());return[...e].sort()},[S]),w=(0,y.useMemo)(()=>{let e=d.trim().toLowerCase();return S.filter(t=>!(p&&(t.material||``).toUpperCase()!==p||e&&!j1e(t).includes(e)))},[S,d,p]),T=w.length>0&&w.every(e=>l.has(e.id));if(!e)return null;let E=l.size,D=E===0,O=Number(b),k=Number.isInteger(O)&&O>=1&&O<=v9;function A(e){u(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function j(){u(e=>{let t=new Set(e);for(let e of w)t.add(e.id);return t})}function M(){u(e=>{let t=new Set(e);for(let e of w)t.delete(e.id);return t})}function N(){u(new Set)}async function P(e){if(D||s)return;let n=_9[e];if(n!==void 0&&(!k||O>n)){o(a(`inventory.labels.startingPositionRangeError`,`Starting position must be between 1 and {{capacity}} for this sheet.`,{capacity:n}),`error`);return}let r=S.filter(e=>l.has(e.id)).map(e=>e.id);c(e);try{O1e(i?await Z.printSpoolmanSpoolLabels({spool_ids:r,template:e,monochrome:_,starting_position:n===void 0?1:O}):await Z.printSpoolLabels({spool_ids:r,template:e,monochrome:_,starting_position:n===void 0?1:O})),t()}catch(e){o(a(`inventory.labels.error`,`Could not generate labels: {{msg}}`,{msg:e instanceof Error?e.message:String(e)}),`error`)}finally{c(null)}}return(0,G.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-start sm:items-center justify-center p-4 overflow-y-auto`,children:[(0,G.jsx)(`div`,{className:`absolute inset-0 bg-black/60 backdrop-blur-sm`,onClick:t}),(0,G.jsxs)(`div`,{"data-testid":`label-template-picker-panel`,className:`relative w-full max-w-3xl bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl shadow-2xl max-h-[90vh] overflow-clip flex flex-col my-auto`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Rl,{className:`w-5 h-5 text-bambu-green`}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:a(`inventory.labels.title`,`Print spool labels`)}),E>0&&(0,G.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[`(`,a(`inventory.labels.selectedCount`,`{{count}} selected`,{count:E}),`)`]})]}),(0,G.jsx)(`button`,{onClick:t,className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,"aria-label":a(`common.close`,`Close`),children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]}),(0,G.jsxs)(`div`,{className:`p-4 space-y-2 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(Ql,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`}),(0,G.jsx)(`input`,{type:`search`,value:d,onChange:e=>f(e.target.value),placeholder:a(`inventory.labels.searchPlaceholder`,`Search name, brand, or #ID`),className:`w-full pl-9 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray focus:outline-none focus:border-bambu-green`})]}),C.length>1&&(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray mr-1`,children:a(`inventory.labels.filterByMaterial`,`Material:`)}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>m(``),className:`px-2 py-0.5 text-xs rounded-full border transition ${p===``?`bg-bambu-green text-bambu-dark border-bambu-green`:`bg-bambu-dark text-bambu-gray border-bambu-dark-tertiary hover:border-bambu-gray`}`,children:a(`inventory.labels.allMaterials`,`All`)}),C.map(e=>(0,G.jsx)(`button`,{type:`button`,onClick:()=>m(e),className:`px-2 py-0.5 text-xs rounded-full border transition ${p===e?`bg-bambu-green text-bambu-dark border-bambu-green`:`bg-bambu-dark text-bambu-gray border-bambu-dark-tertiary hover:border-bambu-gray`}`,children:e},e))]}),(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray mr-1`,children:a(`inventory.labels.sortBy.label`)}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>g(`id`),className:`px-2 py-0.5 text-xs rounded-full border transition ${h===`id`?`bg-bambu-green text-bambu-dark border-bambu-green`:`bg-bambu-dark text-bambu-gray border-bambu-dark-tertiary hover:border-bambu-gray`}`,children:a(`inventory.labels.sortBy.id`)}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>g(`color`),className:`px-2 py-0.5 text-xs rounded-full border transition ${h===`color`?`bg-bambu-green text-bambu-dark border-bambu-green`:`bg-bambu-dark text-bambu-gray border-bambu-dark-tertiary hover:border-bambu-gray`}`,children:a(`inventory.labels.sortBy.color`)})]})]}),(0,G.jsxs)(`div`,{className:`px-4 pt-3 pb-2 flex items-center justify-between gap-3 flex-wrap`,children:[(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:a(`inventory.labels.pickSpools`,`Pick which spools to print labels for:`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-3 text-xs`,children:[(0,G.jsx)(`button`,{type:`button`,onClick:T?M:j,disabled:w.length===0,className:`text-bambu-green hover:underline disabled:opacity-50 disabled:no-underline disabled:cursor-not-allowed`,children:T?a(`inventory.labels.deselectVisible`,`Deselect visible`):a(`inventory.labels.selectVisible`,`Select all visible ({{count}})`,{count:w.length})}),(0,G.jsx)(`button`,{type:`button`,onClick:N,disabled:E===0,className:`text-bambu-gray hover:text-white hover:underline disabled:opacity-50 disabled:no-underline disabled:cursor-not-allowed`,children:a(`inventory.labels.clearAll`,`Clear all`)})]})]}),(0,G.jsx)(`div`,{className:`flex-1 overflow-y-auto px-2 pb-2 min-h-0`,children:w.length===0?(0,G.jsx)(`div`,{className:`text-center text-sm text-bambu-gray py-6`,children:S.length===0?a(`inventory.labels.noSpoolsToShow`,`No spools to show. Adjust your filter and try again.`):a(`inventory.labels.noMatches`,`No spools match the current search or filter.`)}):(0,G.jsx)(`ul`,{className:`space-y-0.5`,children:w.map(e=>{let t=l.has(e.id);return(0,G.jsx)(`li`,{children:(0,G.jsxs)(`label`,{className:`flex items-center gap-3 px-2 py-1.5 rounded hover:bg-bambu-dark-tertiary/50 cursor-pointer`,children:[t?(0,G.jsx)(vu,{className:`w-4 h-4 text-bambu-green shrink-0`}):(0,G.jsx)(bu,{className:`w-4 h-4 text-bambu-gray shrink-0`}),(0,G.jsx)(`input`,{type:`checkbox`,checked:t,onChange:()=>A(e.id),className:`sr-only`}),(0,G.jsx)(`span`,{className:`w-4 h-4 rounded border border-black/20 shrink-0`,style:k1e(e.rgba)}),(0,G.jsx)(`span`,{className:`flex-1 min-w-0 truncate text-sm text-white`,children:A1e(e)}),(0,G.jsxs)(`span`,{className:`text-xs font-mono text-bambu-gray shrink-0`,children:[`#`,e.id]})]})},e.id)})})}),(0,G.jsxs)(`div`,{className:`px-4 pt-2 pb-1 border-t border-bambu-dark-tertiary space-y-2`,children:[(0,G.jsxs)(`label`,{className:`inline-flex items-center gap-2 cursor-pointer select-none`,children:[_?(0,G.jsx)(vu,{className:`w-4 h-4 text-bambu-green shrink-0`}):(0,G.jsx)(bu,{className:`w-4 h-4 text-bambu-gray shrink-0`}),(0,G.jsx)(`input`,{type:`checkbox`,checked:_,onChange:e=>v(e.target.checked),className:`sr-only`}),(0,G.jsx)(`span`,{className:`text-sm text-white`,children:a(`inventory.labels.monochrome`,`Monochrome (black & white printer)`)}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:a(`inventory.labels.monochromeHint`,`Drops the colour swatch and widens the text`)})]}),(0,G.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,G.jsx)(`label`,{htmlFor:`label-starting-position`,className:`text-sm text-white whitespace-nowrap pt-1.5`,children:a(`inventory.labels.startingPosition`,`Starting label position`)}),(0,G.jsx)(`input`,{id:`label-starting-position`,"data-testid":`label-starting-position`,type:`number`,min:1,max:v9,step:1,value:b,onChange:e=>x(e.target.value),"aria-describedby":`label-starting-position-help`,className:`w-20 px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:outline-none focus:border-bambu-green`}),(0,G.jsxs)(`div`,{id:`label-starting-position-help`,className:`text-xs text-bambu-gray pt-1.5`,children:[(0,G.jsx)(`div`,{children:a(`inventory.labels.startingPositionRange`,`Sheet templates only: L7160 supports 1–21; 5160 supports 1–30.`)}),(0,G.jsx)(`div`,{"data-testid":`label-starting-position-status`,className:k?``:`text-red-400`,children:k?O===1?a(`inventory.labels.startingPositionFirst`,`Printing starts at position 1.`):a(`inventory.labels.startingPositionSkipped`,`Positions 1 through {{lastPosition}} will be left blank on the first sheet.`,{lastPosition:O-1}):a(`inventory.labels.startingPositionInvalid`,`Enter a whole number from 1 to {{capacity}}.`,{capacity:v9})})]})]})]}),(0,G.jsx)(`div`,{className:`px-3 pt-1 pb-2 grid grid-cols-1 sm:grid-cols-2 gap-2`,children:D1e.map(e=>{let t=s===e.value,n=_9[e.value],r=n!==void 0&&(!k||O>n),i=a(`inventory.labels.templates.${e.i18nKey}.label`,e.fallbackLabel),o=r?a(`inventory.labels.startingPositionRangeError`,`Starting position must be between 1 and {{capacity}} for this sheet.`,{capacity:n}):a(`inventory.labels.templates.${e.i18nKey}.hint`,e.fallbackHint);return(0,G.jsxs)(`button`,{"data-testid":`print-labels-${e.value}`,disabled:D||s!==null||r,onClick:()=>P(e.value),title:`${i} — ${o}`,className:`w-full text-left p-2.5 rounded-lg border border-bambu-dark-tertiary bg-bambu-dark hover:border-bambu-green hover:bg-bambu-green/10 disabled:opacity-50 disabled:cursor-not-allowed disabled:hover:border-bambu-dark-tertiary disabled:hover:bg-bambu-dark transition flex items-center gap-3`,children:[(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`div`,{className:`font-medium text-white text-sm truncate`,children:i}),(0,G.jsx)(`div`,{className:`text-xs text-bambu-gray mt-0.5 truncate`,children:o})]}),t&&(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin text-bambu-green shrink-0`})]},e.value)})}),(0,G.jsx)(`div`,{className:`flex justify-end gap-2 px-5 py-2 border-t border-bambu-dark-tertiary`,children:(0,G.jsx)(Q,{variant:`secondary`,onClick:t,disabled:s!==null,children:a(`common.cancel`,`Cancel`)})})]})]})}function P1e({onClose:e,onImported:t}){let{t:n}=U(),[r,i]=(0,y.useState)(null),[a,o]=(0,y.useState)(!1),[s,c]=(0,y.useState)(null),[l,u]=(0,y.useState)(!1),[d,f]=(0,y.useState)(!1),[p,m]=(0,y.useState)(null),h=(0,y.useRef)(null),g=async e=>{i(e),c(null),m(null),u(!0);try{c(await Z.importSpoolsCsvPreview(e))}catch(e){m(e instanceof Error?e.message:n(`inventory.csv.previewError`,`Could not read the CSV file`))}finally{u(!1)}},_=e=>{let t=e.target.files?.[0];t&&g(t)},v=e=>{e.preventDefault(),o(!1);let t=e.dataTransfer.files?.[0];t&&g(t)},b=async()=>{if(r){f(!0),m(null);try{t((await Z.importSpoolsCsv(r)).created)}catch(e){m(e instanceof Error?e.message:n(`inventory.csv.importError`,`Import failed`)),f(!1)}}},x=e=>e===`valid`?(0,G.jsx)(xs,{className:`w-4 h-4 text-green-500 flex-shrink-0`}):e===`error`?(0,G.jsx)(Ds,{className:`w-4 h-4 text-red-500 flex-shrink-0`}):(0,G.jsx)(ws,{className:`w-4 h-4 text-bambu-gray flex-shrink-0`}),S=s?.valid_count??0;return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg w-full max-w-3xl border border-bambu-dark-tertiary flex flex-col max-h-[90vh]`,children:[(0,G.jsxs)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary flex items-center justify-between`,children:[(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:n(`inventory.csv.modalTitle`,`Import spools from CSV`)}),(0,G.jsx)(`button`,{onClick:e,className:`p-1 hover:bg-bambu-dark rounded`,children:(0,G.jsx)(nd,{className:`w-5 h-5 text-bambu-gray`})})]}),(0,G.jsxs)(`div`,{className:`p-4 space-y-4 overflow-y-auto flex-1`,children:[(0,G.jsxs)(`div`,{onDragOver:e=>{e.preventDefault(),o(!0)},onDragLeave:e=>{e.preventDefault(),o(!1)},onDrop:v,onClick:()=>h.current?.click(),className:`border-2 border-dashed rounded-lg p-6 text-center cursor-pointer transition-colors ${a?`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary hover:border-bambu-green/50`}`,children:[(0,G.jsx)(Vu,{className:`w-9 h-9 mx-auto mb-2 ${a?`text-bambu-green`:`text-bambu-gray`}`}),r?(0,G.jsxs)(`p`,{className:`text-white font-medium flex items-center justify-center gap-2`,children:[(0,G.jsx)(fc,{className:`w-4 h-4`}),` `,r.name]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`p`,{className:`text-white font-medium`,children:n(`inventory.csv.selectFile`,`Choose a CSV file or drag it here`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray/70 mt-1`,children:n(`inventory.csv.dragHint`,`Header: material (required), brand, subtype, color_name, rgba, …`)})]})]}),(0,G.jsx)(`input`,{ref:h,type:`file`,accept:`.csv,text/csv`,className:`hidden`,onChange:_}),l&&(0,G.jsxs)(`div`,{className:`flex items-center justify-center gap-2 text-bambu-gray py-4`,children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),n(`inventory.csv.parsing`,`Reading file…`)]}),p&&(0,G.jsxs)(`div`,{className:`p-3 bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30 rounded-lg flex items-start gap-3`,children:[(0,G.jsx)(Ds,{className:`w-5 h-5 text-red-600 dark:text-red-400 mt-0.5 flex-shrink-0`}),(0,G.jsx)(`p`,{className:`text-sm text-red-700 dark:text-red-300 break-words`,children:p})]}),s&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-3 text-sm`,children:[(0,G.jsx)(`span`,{className:`px-2 py-1 rounded bg-green-50 dark:bg-green-500/10 text-green-700 dark:text-green-400`,children:n(`inventory.csv.validCount`,`{{count}} valid`,{count:s.valid_count})}),(0,G.jsx)(`span`,{className:`px-2 py-1 rounded bg-red-50 dark:bg-red-500/10 text-red-700 dark:text-red-400`,children:n(`inventory.csv.errorCount`,`{{count}} error`,{count:s.error_count})}),(0,G.jsx)(`span`,{className:`px-2 py-1 rounded bg-bambu-dark text-bambu-gray`,children:n(`inventory.csv.skippedCount`,`{{count}} skipped`,{count:s.skipped_count})})]}),s.warnings.length>0&&(0,G.jsx)(`div`,{className:`p-3 bg-yellow-50 dark:bg-yellow-500/10 border border-yellow-300 dark:border-yellow-500/30 rounded-lg space-y-1`,children:s.warnings.map((e,t)=>(0,G.jsx)(`p`,{className:`text-xs text-yellow-700 dark:text-yellow-300`,children:e},t))}),s.rows.length>0&&(0,G.jsx)(`div`,{className:`border border-bambu-dark-tertiary rounded-lg overflow-hidden`,children:(0,G.jsx)(`div`,{className:`max-h-72 overflow-y-auto`,children:(0,G.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,G.jsx)(`thead`,{className:`bg-bambu-dark sticky top-0`,children:(0,G.jsxs)(`tr`,{className:`text-left text-bambu-gray`,children:[(0,G.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:n(`inventory.csv.colRow`,`Row`)}),(0,G.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:n(`inventory.csv.colStatus`,`Status`)}),(0,G.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:n(`inventory.material`,`Material`)}),(0,G.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:n(`inventory.brand`,`Brand`)}),(0,G.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:n(`inventory.csv.colColor`,`Color`)})]})}),(0,G.jsx)(`tbody`,{children:s.rows.map(e=>(0,G.jsxs)(`tr`,{className:`border-t border-bambu-dark-tertiary`,children:[(0,G.jsx)(`td`,{className:`px-3 py-2 text-bambu-gray`,children:e.row_number}),(0,G.jsx)(`td`,{className:`px-3 py-2`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[x(e.status),e.status===`error`&&e.reason&&(0,G.jsx)(`span`,{className:`text-xs text-red-700 dark:text-red-400 break-words`,children:e.reason})]})}),(0,G.jsx)(`td`,{className:`px-3 py-2 text-white`,children:e.material||`—`}),(0,G.jsx)(`td`,{className:`px-3 py-2 text-white`,children:e.brand||`—`}),(0,G.jsx)(`td`,{className:`px-3 py-2`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.rgba&&(0,G.jsx)(`span`,{className:`inline-block w-4 h-4 rounded-full border border-bambu-dark-tertiary flex-shrink-0`,style:Mf(e.rgba)}),(0,G.jsx)(`span`,{className:`text-white`,children:e.color_name||`—`}),e.resolved_color&&!e.cross_material_color&&(0,G.jsx)(`span`,{title:n(`inventory.csv.colorResolved`,`Color filled from catalog`),children:(0,G.jsx)(Yu,{className:`w-3.5 h-3.5 text-bambu-green flex-shrink-0`})}),e.cross_material_color&&(0,G.jsx)(`span`,{title:n(`inventory.csv.colorCrossMaterial`,`Color taken from a different material — no exact match in catalog`),children:(0,G.jsx)(Lu,{className:`w-3.5 h-3.5 text-yellow-500 flex-shrink-0`})}),e.duplicate_of_existing&&(0,G.jsx)(`span`,{title:n(`inventory.csv.duplicateExisting`,`A spool with this material, brand and color already exists — it will still be imported as a new spool`),children:(0,G.jsx)(Vs,{className:`w-3.5 h-3.5 text-amber-600 dark:text-amber-400 flex-shrink-0`})})]})})]},e.row_number))})]})})})]})]}),(0,G.jsxs)(`div`,{className:`p-4 border-t border-bambu-dark-tertiary flex justify-end gap-2`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:e,disabled:d,children:n(`common.cancel`)}),(0,G.jsx)(Q,{onClick:b,disabled:!s||S===0||d,children:d?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 mr-2 animate-spin`}),n(`inventory.csv.importing`,`Importing…`)]}):S>0?n(`inventory.csv.importValidRows`,`Import {{count}} valid rows`,{count:S}):n(`inventory.csv.noValidRows`,`No valid rows`)})]})]})})}var y9=[{id:`material`,type:`searchable`,labelKey:`inventory.material`},{id:`subtype`,type:`searchable`,labelKey:`inventory.subtype`},{id:`brand`,type:`searchable`,labelKey:`inventory.brand`},{id:`color_name`,type:`text`,labelKey:`inventory.colorName`},{id:`rgba`,type:`color`,labelKey:`inventory.color`,pattern:`^[0-9A-Fa-f]{6}([0-9A-Fa-f]{2})?$`},{id:`location_id`,type:`searchableClosed`,labelKey:`inventory.storageLocation`},{id:`slicer_filament_name`,type:`searchable`,labelKey:`inventory.slicerFilamentName`},{id:`slicer_filament`,type:`searchable`,labelKey:`inventory.slicerFilament`},{id:`cost_per_kg`,type:`number`,labelKey:`inventory.costPerKg`,min:0,step:.01},{id:`note`,type:`textarea`,labelKey:`inventory.note`},{id:`label_weight`,type:`number`,labelKey:`inventory.labelWeight`,min:1,step:1},{id:`core_weight`,type:`number`,labelKey:`inventory.coreWeight`,min:0,step:1},{id:`category`,type:`searchable`,labelKey:`inventory.category`},{id:`low_stock_threshold_pct`,type:`number`,labelKey:`inventory.lowStockThresholdOverride`,min:1,max:99,step:1}];function F1e({value:e,onChange:t,options:n,allowCustom:r,placeholderKey:i,disabled:a}){let{t:o}=U(),s=(0,y.useRef)(null),[c,l]=(0,y.useState)(!1),[u,d]=(0,y.useState)(``);(0,y.useEffect)(()=>{if(!c)return;let e=e=>{s.current&&!s.current.contains(e.target)&&(l(!1),d(``))},t=e=>{e.key===`Escape`&&(l(!1),d(``))};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[c]);let f=c?u:n.find(t=>t.value===e)?.label??e,p=(0,y.useMemo)(()=>{if(!c)return n;let e=u.trim().toLowerCase();return e?n.filter(t=>t.label.toLowerCase().includes(e)||t.value.toLowerCase().includes(e)):n},[c,u,n]),m=c&&u.trim()&&!n.some(e=>e.value.toLowerCase()===u.trim().toLowerCase());return(0,G.jsxs)(`div`,{className:`relative`,ref:s,children:[(0,G.jsx)(`input`,{type:`text`,disabled:a,value:f,onChange:e=>{d(e.target.value),l(!0),r&&t(e.target.value)},onFocus:()=>{l(!0),d(``)},placeholder:i?o(i):void 0,className:`w-full px-3 py-2 pr-9 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray/50 focus:border-bambu-green focus:outline-none`}),(0,G.jsx)(ps,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50 pointer-events-none`}),c&&(0,G.jsxs)(`div`,{className:`absolute z-50 left-0 right-0 mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-64 overflow-y-auto`,children:[p.length===0&&!r&&(0,G.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:o(`inventory.noResults`)}),p.map(n=>(0,G.jsx)(`button`,{type:`button`,className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${e===n.value?`bg-bambu-green/10 text-bambu-green`:`text-white`}`,onClick:()=>{t(n.value),l(!1),d(``)},children:n.label},n.value)),r&&m&&(0,G.jsx)(`button`,{type:`button`,className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary text-bambu-green border-t border-bambu-dark-tertiary`,onClick:()=>{t(u.trim()),l(!1),d(``)},children:o(`inventory.bulk.useCustom`,{value:u.trim()})})]})]})}function b9(...e){let t=new Set;for(let n of e)for(let e of n){let n=e?.trim();n&&t.add(n)}return Array.from(t).sort((e,t)=>e.localeCompare(t))}function I1e({isOpen:e,selectedCount:t,isPending:n,availableLocations:r,availableMaterials:i,availableSubtypes:a,availableBrands:o,availableCategories:s,availableSlicerFilaments:c,availableSlicerFilamentNames:l,onClose:u,onApply:d}){let{t:f}=U(),{data:p=[]}=K({queryKey:[`bulk-edit-cloud-presets`],enabled:e,staleTime:300*1e3,queryFn:async()=>{let e=[];try{if((await Z.getCloudStatus()).is_authenticated){let t=await Z.getFilamentPresets();e.push(...t)}}catch{}try{if((await Z.orcaCloudStatus()).connected){let t=await Z.orcaCloudListProfiles();e.push(...t.filament)}}catch{}return e}}),{data:m}=K({queryKey:[`bulk-edit-local-presets`],enabled:e,staleTime:300*1e3,queryFn:Z.getLocalPresets}),{data:h=[]}=K({queryKey:[`builtin-filaments`],enabled:e,staleTime:300*1e3,queryFn:Z.getBuiltinFilaments}),g=(0,y.useMemo)(()=>KH(p,new Set,m?.filament??[],h),[p,m,h]),[_,v]=(0,y.useState)({}),b=(0,y.useMemo)(()=>b9(IH,i).map(e=>({value:e,label:e})),[i]),x=(0,y.useMemo)(()=>b9(RH,a).map(e=>({value:e,label:e})),[a]),S=(0,y.useMemo)(()=>b9(LH,o).map(e=>({value:e,label:e})),[o]),C=(0,y.useMemo)(()=>b9(s).map(e=>({value:e,label:e})),[s]),w=(0,y.useMemo)(()=>{let e=g.map(e=>({value:e.code,label:e.displayName})),t=c.filter(t=>!e.some(e=>e.value===t)).map(e=>({value:e,label:e}));return[...e,...t].sort((e,t)=>e.label.localeCompare(t.label))},[g,c]),T=(0,y.useMemo)(()=>{let e=g.map(e=>({value:e.displayName,label:e.displayName})),t=l.filter(t=>!e.some(e=>e.value===t)).map(e=>({value:e,label:e}));return[...e,...t].sort((e,t)=>e.label.localeCompare(t.label))},[g,l]),E=(0,y.useMemo)(()=>r.map(e=>({value:String(e.id),label:e.name})),[r]);if(!e)return null;let D=(e,t)=>{v(n=>({...n,[e]:t}))},O=e=>{v(t=>{let n={...t};return delete n[e],n})},k=(()=>{let e={};for(let t of y9){let n=_[t.id];if(n===void 0)continue;let r=typeof n==`string`?n.trim():n;if(!(r===``||r===null))if(t.type===`number`){let n=Number(r);Number.isFinite(n)&&(e[t.id]=n)}else if(t.id===`location_id`){let n=Number(r);Number.isFinite(n)&&n>0&&(e[t.id]=n)}else if(t.id===`rgba`){let n=String(r).replace(/^#/,``),i=n.length===6?`${n}FF`:n;/^[0-9A-Fa-f]{8}$/.test(i)&&(e[t.id]=i.toUpperCase())}else e[t.id]=String(r)}return e})(),A=Object.keys(k).length>0,j=y9.some(e=>{let t=_[e.id];return t===void 0||t.trim()===``?!1:k[e.id]===void 0}),M=e=>e===`material`?b:e===`subtype`?x:e===`brand`?S:e===`category`?C:e===`slicer_filament`?w:e===`slicer_filament_name`?T:e===`location_id`?E:[],N=e=>{let t=_[e.id]??``;if(e.type===`searchable`||e.type===`searchableClosed`)return(0,G.jsx)(F1e,{value:t,onChange:t=>{t===``?O(e.id):D(e.id,t)},options:M(e.id),allowCustom:e.type===`searchable`,disabled:n});if(e.type===`textarea`)return(0,G.jsx)(`textarea`,{disabled:n,value:t,onChange:t=>D(e.id,t.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray/50 focus:border-bambu-green focus:outline-none resize-none min-h-[60px]`});if(e.type===`color`){let r=t.trim().replace(/^#/,``),i=r.length===6?`${r}FF`:r,a=t.trim()!==``&&!/^[0-9A-Fa-f]{8}$/.test(i);return(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`input`,{type:`color`,disabled:n,value:`#${(t||`808080`).replace(/^#/,``).slice(0,6)}`,onChange:t=>D(e.id,t.target.value.replace(/^#/,``).toUpperCase()),className:`h-9 w-12 rounded cursor-pointer`}),(0,G.jsx)(`input`,{type:`text`,disabled:n,value:t,onChange:t=>D(e.id,t.target.value.replace(/^#/,``).toUpperCase()),placeholder:`RRGGBB or RRGGBBAA`,className:`flex-1 px-3 py-2 bg-bambu-dark border rounded-lg text-white placeholder-bambu-gray/50 focus:outline-none ${a?`border-red-500 focus:border-red-500`:`border-bambu-dark-tertiary focus:border-bambu-green`}`,pattern:e.pattern})]}),a&&(0,G.jsx)(`p`,{className:`mt-1 text-xs text-red-600 dark:text-red-400`,children:f(`inventory.bulk.invalidHex`)})]})}return(0,G.jsx)(`input`,{type:e.type===`number`?`number`:`text`,disabled:n,value:t,onChange:t=>D(e.id,t.target.value),min:e.min,max:e.max,step:e.step,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray/50 focus:border-bambu-green focus:outline-none`})};return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center p-4 z-50`,onClick:n?void 0:u,children:(0,G.jsxs)(`div`,{className:`w-full max-w-3xl bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg max-h-[90vh] flex flex-col`,onClick:e=>e.stopPropagation(),children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-5 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:f(`inventory.bulk.editTitle`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-0.5`,children:f(`inventory.bulk.editSubtitle`,{count:t})})]}),(0,G.jsx)(`button`,{onClick:u,disabled:n,className:`p-1 text-bambu-gray hover:text-white transition-colors`,"aria-label":f(`common.close`),children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]}),(0,G.jsx)(`p`,{className:`px-5 pt-4 text-xs text-bambu-gray`,children:f(`inventory.bulk.editHint`)}),(0,G.jsx)(`div`,{className:`flex-1 overflow-y-auto p-5 space-y-3`,children:y9.map(e=>{let t=_[e.id]!==void 0;return(0,G.jsxs)(`div`,{className:`flex items-start gap-3 rounded-md p-2 transition-colors ${t?`bg-bambu-green/5 border border-bambu-green/30`:`border border-transparent`}`,children:[(0,G.jsx)(`div`,{className:`pt-2`,children:(0,G.jsx)(`input`,{type:`checkbox`,className:`h-4 w-4 cursor-pointer`,checked:t,onChange:t=>{t.target.checked?D(e.id,``):O(e.id)},"aria-label":f(`inventory.bulk.toggleField`)})}),(0,G.jsxs)(`div`,{className:`flex-1`,children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:f(e.labelKey)}),N(e)]})]},e.id)})}),(0,G.jsxs)(`div`,{className:`flex items-center gap-3 p-5 border-t border-bambu-dark-tertiary`,children:[(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:f(`inventory.bulk.changeCount`,{count:Object.keys(k).length})}),(0,G.jsxs)(`div`,{className:`ml-auto flex gap-2`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:u,disabled:n,children:f(`common.cancel`)}),(0,G.jsx)(Q,{onClick:()=>d(k),disabled:!A||n||j,children:n?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 mr-2 animate-spin`}),f(`inventory.bulk.applyPending`)]}):f(`inventory.bulk.applyButton`,{count:t})})]})]})]})})}function L1e(e){let t=e[0],n=0,r=0,i=0;for(let t of e)n+=t.label_weight,r+=t.weight_used,i+=t.core_weight;return{...t,label_weight:n,weight_used:r,core_weight:i}}function x9(e){let t=new Set;for(let n of e)if(typeof n==`string`){let e=n.trim();e&&t.add(e)}return Array.from(t).sort((e,t)=>e.localeCompare(t))}function R1e(e){return`${e.material}|${e.subtype||``}|${e.brand||``}|${e.color_name||``}|${e.rgba||``}|${e.extra_colors||``}|${e.effect_type||``}|${e.label_weight}`}var z1e=`bambuddy-inventory-columns`,S9=[{id:`id`,label:`#`,visible:!0},{id:`added_time`,label:`Added`,visible:!0},{id:`encode_time`,label:`Encoded`,visible:!1},{id:`last_used_time`,label:`Last Used`,visible:!1},{id:`rgba`,label:`Color`,visible:!0},{id:`material`,label:`Material`,visible:!0},{id:`subtype`,label:`Subtype`,visible:!0},{id:`color_name`,label:`Color Name`,visible:!1},{id:`brand`,label:`Brand`,visible:!0},{id:`slicer_filament`,label:`Slicer Filament`,visible:!1},{id:`location`,label:`Location`,visible:!0},{id:`storage_location`,label:`Storage Location`,visible:!1},{id:`temperature`,label:`Temperature`,visible:!1},{id:`humidity`,label:`Humidity`,visible:!1},{id:`battery`,label:`Battery`,visible:!1},{id:`label_weight`,label:`Label`,visible:!0},{id:`net`,label:`Net`,visible:!0},{id:`gross`,label:`Gross`,visible:!1},{id:`added_full`,label:`Full`,visible:!1},{id:`used`,label:`Used`,visible:!1},{id:`printed_total`,label:`Printed Total`,visible:!1},{id:`printed_since_weight`,label:`Printed Since Weight`,visible:!1},{id:`note`,label:`Note`,visible:!1},{id:`pa_k`,label:`PA(K)`,visible:!0},{id:`tag_id`,label:`Tag ID`,visible:!1},{id:`data_origin`,label:`Data Origin`,visible:!1},{id:`tag_type`,label:`Linked Tag Type`,visible:!1},{id:`stock`,label:`Stock`,visible:!1},{id:`remaining`,label:`Remaining`,visible:!0},{id:`spool_name`,label:`Spool`,visible:!1},{id:`cost_per_kg`,label:`Cost/kg`,visible:!1},{id:`weight_check`,label:`Weight Check`,visible:!1}];function B1e(){try{let e=localStorage.getItem(z1e);if(e){let t=JSON.parse(e),n=new Set(S9.map(e=>e.id)),r=new Set(t.map(e=>e.id)),i=[...t.filter(e=>n.has(e.id))];for(let e of S9){if(r.has(e.id))continue;let t=S9.indexOf(e),n=i.length;for(let e=t-1;e>=0;e--){let t=i.findIndex(t=>t.id===S9[e].id);if(t!==-1){n=t+1;break}}i.splice(n,0,e)}return i}}catch{}return S9.map(e=>({...e}))}function V1e(e){try{localStorage.setItem(z1e,JSON.stringify(e))}catch{}}function C9(e,t=!1){return t&&e>=1e3?`${(e/1e3).toFixed(1)}kg`:`${Math.round(e)}g`}var H1e={PLA:`bg-green-100 dark:bg-green-500/20 text-green-700 dark:text-green-400`,ABS:`bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400`,PETG:`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`,TPU:`bg-purple-100 dark:bg-purple-500/20 text-purple-700 dark:text-purple-400`,ASA:`bg-orange-100 dark:bg-orange-500/20 text-orange-700 dark:text-orange-400`,PA:`bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400`,PC:`bg-cyan-100 dark:bg-cyan-500/20 text-cyan-700 dark:text-cyan-400`,PET:`bg-sky-100 dark:bg-sky-500/20 text-sky-700 dark:text-sky-400`};function w9(e,t=`system`){if(!e)return`-`;let n=rp(e);return n?Yf(n,t):`-`}var U1e={id:()=>`#`,added_time:()=>`Added`,encode_time:()=>`Encoded`,last_used_time:()=>`Last Used`,rgba:e=>e(`inventory.color`),material:e=>e(`inventory.material`),subtype:e=>e(`inventory.subtype`),color_name:e=>e(`inventory.colorName`),brand:e=>e(`inventory.brand`),slicer_filament:e=>e(`inventory.slicerFilament`),location:()=>`Location`,storage_location:e=>e(`inventory.storageLocation`),temperature:e=>e(`inventory.temperature`),humidity:e=>e(`inventory.humidity`),battery:e=>e(`inventory.battery`),label_weight:e=>e(`inventory.labelWeight`),net:e=>e(`inventory.net`),gross:()=>`Gross`,added_full:()=>`Full`,used:e=>e(`inventory.weightUsed`),printed_total:()=>`Printed Total`,printed_since_weight:()=>`Printed Since Weight`,note:e=>e(`inventory.note`),pa_k:()=>`PA(K)`,tag_id:()=>`Tag ID`,data_origin:()=>`Data Origin`,tag_type:()=>`Linked Tag Type`,stock:e=>e(`inventory.stock`),remaining:e=>e(`inventory.remaining`),spool_name:e=>e(`inventory.spoolName`),cost_per_kg:e=>e(`inventory.costPerKg`),weight_check:e=>e(`inventory.weightCheck`)},T9={id:({spool:e})=>(0,G.jsx)(`span`,{className:`text-sm font-medium text-white`,children:e.id}),added_time:({spool:e,dateFormat:t})=>(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:w9(e.created_at,t)}),encode_time:({spool:e,dateFormat:t})=>(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:w9(e.encode_time,t)}),last_used_time:({spool:e,dateFormat:t})=>(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.last_used?w9(e.last_used,t):`Never`}),rgba:({spool:e})=>(0,G.jsx)(`div`,{className:`flex items-center justify-center`,children:(0,G.jsx)(w8,{rgba:e.rgba,extraColors:e.extra_colors,effectType:e.effect_type,effectSize:`table`,subtype:e.subtype})}),material:({spool:e})=>(0,G.jsx)(`span`,{className:`text-sm text-white`,children:e.material}),subtype:({spool:e})=>(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.subtype||`-`}),color_name:({spool:e})=>(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:kf(e.color_name,e.rgba)||`-`}),brand:({spool:e})=>(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.brand||`-`}),slicer_filament:({spool:e})=>(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,title:e.slicer_filament||void 0,children:e.slicer_filament_name||e.slicer_filament||`-`}),location:({spool:e,assignmentMap:t})=>{let n=t[e.id];if(!n)return(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:`-`});let r=n.printer_name||`Printer ${n.printer_id}`,i=n.ams_id===254||n.ams_id===255,a=!i&&n.ams_id>=128;return(0,G.jsxs)(`span`,{className:`inline-flex items-center px-1.5 py-0.5 rounded text-xs font-medium bg-purple-100 dark:bg-purple-500/20 text-purple-700 dark:text-purple-400`,children:[r,` `,jp(n.ams_id,n.tray_id,a,i),n.ams_label?` (${n.ams_label})`:``]})},storage_location:({spool:e})=>e.storage_location?(0,G.jsx)(`span`,{className:`inline-flex items-center px-1.5 py-0.5 rounded text-xs font-medium bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`,children:e.storage_location}):(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:`-`}),temperature:({spool:e,locationReadingsMap:t,t:n,colorizeLocationSensors:r,locationSensorAboveColor:i,locationSensorBelowColor:a,locationSensorOptimalColor:o})=>{let s=e.location_id?t[e.location_id]?.find(e=>e.device_class===`temperature`):void 0;return s?(0,G.jsx)(`span`,{title:s.name,className:`text-sm ${k9(s,r,i,a,o)}`,children:O9(s,n)}):(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray/50`,children:`-`})},humidity:({spool:e,locationReadingsMap:t,t:n,colorizeLocationSensors:r,locationSensorAboveColor:i,locationSensorBelowColor:a,locationSensorOptimalColor:o})=>{let s=e.location_id?t[e.location_id]?.find(e=>e.device_class===`humidity`):void 0;return s?(0,G.jsx)(`span`,{title:s.name,className:`text-sm ${k9(s,r,i,a,o)}`,children:O9(s,n)}):(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray/50`,children:`-`})},battery:({spool:e,locationReadingsMap:t,t:n,colorizeLocationSensors:r,locationSensorAboveColor:i,locationSensorBelowColor:a,locationSensorOptimalColor:o})=>{let s=e.location_id?t[e.location_id]?.find(e=>e.device_class===`battery`):void 0;return s?(0,G.jsx)(`span`,{title:s.name,className:`text-sm ${k9(s,r,i,a,o)}`,children:O9(s,n)}):(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray/50`,children:`-`})},label_weight:({spool:e})=>(0,G.jsx)(`span`,{className:`text-sm text-white`,children:C9(e.label_weight)}),net:({remaining:e})=>(0,G.jsx)(`span`,{className:`text-sm text-white`,children:C9(e)}),gross:({spool:e,remaining:t})=>(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:C9(t+e.core_weight)}),added_full:({spool:e})=>(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.added_full==null?`-`:e.added_full?`Yes`:`No`}),used:({spool:e})=>(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.weight_used>0?C9(e.weight_used):`-`}),printed_total:()=>(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray/50`,children:`-`}),printed_since_weight:()=>(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray/50`,children:`-`}),note:({spool:e})=>(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray max-w-[150px] truncate block`,title:e.note||void 0,children:e.note||`-`}),pa_k:({spool:e})=>(e.k_profiles?.length??0)===0?(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:`-`}):(0,G.jsx)(`span`,{className:`inline-flex items-center px-1.5 py-0.5 rounded text-xs font-medium bg-bambu-green/20 text-bambu-green`,children:`K`}),tag_id:({spool:e})=>{let t=e.tag_uid||e.tray_uuid;return t?(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray font-mono`,title:t,children:t.length>12?`${t.slice(0,6)}...${t.slice(-4)}`:t}):(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray/50`,children:`-`})},data_origin:({spool:e})=>(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.data_origin||`-`}),tag_type:({spool:e})=>(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.tag_type||`-`}),stock:({spool:e,t})=>e.slicer_filament?(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:`-`}):(0,G.jsx)(`span`,{className:`inline-flex items-center px-1.5 py-0.5 rounded text-xs font-medium bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-400`,children:t(`inventory.stock`)}),remaining:({remaining:e,pct:t})=>(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`div`,{className:`flex-1 h-2 bg-bambu-dark-tertiary rounded-full overflow-hidden`,children:(0,G.jsx)(`div`,{className:`h-full rounded-full ${t>50?`bg-bambu-green`:t>20?`bg-yellow-500`:`bg-red-500`}`,style:{width:`${Math.min(t,100)}%`}})}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray min-w-[40px] text-right`,children:[Math.round(e),`g`]})]}),spool_name:({spool:e,catalogMap:t})=>(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:(e.core_weight_catalog_id==null?void 0:t[e.core_weight_catalog_id])?.name||`-`}),cost_per_kg:({spool:e,currencySymbol:t})=>(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.cost_per_kg==null?`-`:`${t}${e.cost_per_kg.toFixed(2)}`}),weight_check:({spool:e,onSyncWeight:t})=>{let n=e.last_scale_weight;if(n==null)return(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray/50`,title:`No scale measurement`,children:`-`});let r=e.core_weight||0,i=Math.max(0,e.label_weight-e.weight_used)+r,a,o;n0?`+${Math.round(a)}`:`${Math.round(a)}`,c=o?`Scale: ${Math.round(n)}g\nCalculated: ${Math.round(i)}g\nDifference: ${s}g (within tolerance)`:`Scale: ${Math.round(n)}g\nCalculated: ${Math.round(i)}g\nDifference: ${s}g (mismatch!)`;return(0,G.jsxs)(`div`,{className:`flex items-center gap-1 text-sm font-medium ${o?`text-green-700 dark:text-green-400`:`text-yellow-700 dark:text-yellow-400`}`,title:c,children:[(0,G.jsxs)(`span`,{children:[Math.round(n),`g`]}),o?(0,G.jsx)(fs,{className:`w-3 h-3`}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Lu,{className:`w-3 h-3`}),t&&(0,G.jsx)(`button`,{type:`button`,onClick:n=>{n.stopPropagation(),n.preventDefault(),t(e)},className:`p-1 hover:bg-bambu-green/20 rounded transition-colors text-bambu-green`,title:`Sync: trust scale weight and reset tracking`,children:(0,G.jsx)(Hl,{className:`w-3.5 h-3.5`})})]})]})}},E9={id:e=>e.id,added_time:e=>e.created_at||``,encode_time:e=>e.encode_time||``,last_used_time:e=>e.last_used||``,material:e=>(e.material||``).toLowerCase(),subtype:e=>(e.subtype||``).toLowerCase(),color_name:e=>(e.color_name||``).toLowerCase(),rgba:e=>Ef(e.rgba),brand:e=>(e.brand||``).toLowerCase(),slicer_filament:e=>(e.slicer_filament_name||e.slicer_filament||``).toLowerCase(),location:(e,t)=>{let n=t[e.id];if(!n)return``;let r=n.ams_id===254||n.ams_id===255,i=!r&&n.ams_id>=128,a=n.ams_label?` (${n.ams_label})`:``;return`${n.printer_name||``} ${jp(n.ams_id,n.tray_id,i,r)}${a}`},storage_location:e=>(e.storage_location||``).toLowerCase(),label_weight:e=>e.label_weight,net:e=>Math.max(0,e.label_weight-e.weight_used),gross:e=>Math.max(0,e.label_weight-e.weight_used)+e.core_weight,used:e=>e.weight_used,remaining:e=>e.label_weight>0?Math.max(0,e.label_weight-e.weight_used)/e.label_weight:0,note:e=>(e.note||``).toLowerCase(),data_origin:e=>(e.data_origin||``).toLowerCase(),tag_type:e=>(e.tag_type||``).toLowerCase(),stock:e=>+!!e.slicer_filament,spool_name:e=>e.core_weight_catalog_id??0,cost_per_kg:e=>e.cost_per_kg??0,weight_check:e=>{if(e.last_scale_weight==null)return-1;let t=Math.max(0,e.label_weight-e.weight_used)+e.core_weight;return Math.abs(e.last_scale_weight-t)},temperature:(e,t,n)=>(e.location_id?n[e.location_id]:void 0)?.find(e=>e.device_class===`temperature`)?.value??-1/0,humidity:(e,t,n)=>(e.location_id?n[e.location_id]:void 0)?.find(e=>e.device_class===`humidity`)?.value??-1/0,battery:(e,t,n)=>(e.location_id?n[e.location_id]:void 0)?.find(e=>e.device_class===`battery`)?.value??-1/0},D9=`bambuddy-inventory-sort`;function W1e(){try{let e=localStorage.getItem(D9);if(e)return JSON.parse(e)}catch{}return null}function G1e(e){try{e?localStorage.setItem(D9,JSON.stringify(e)):localStorage.removeItem(D9)}catch{}}function K1e(){let{data:e}=K({queryKey:[`spoolman-settings`],queryFn:Z.getSpoolmanSettings,staleTime:300*1e3}),t=e!==void 0;return(0,G.jsx)(q1e,{spoolmanMode:e?.spoolman_enabled===`true`&&!!e?.spoolman_url,spoolmanModeReady:t})}function q1e({spoolmanMode:e=!1,spoolmanModeReady:t=!0}){let{t:n}=U(),r=co(),{showToast:i}=qd(),{hasPermission:a,loading:o}=Nd(),s=!o&&a(`inventory:forecast_read`),[c,l]=Ri(),[u,d]=(0,y.useState)(null),f=(0,y.useRef)(!1),[p,m]=(0,y.useState)(null),[h,g]=(0,y.useState)(null),[_,v]=(0,y.useState)(!1),[b,x]=(0,y.useState)(!1),[S,C]=(0,y.useState)(!1),[w,T]=(0,y.useState)(`active`),[E,D]=(0,y.useState)(`all`),[O,k]=(0,y.useState)(``),[A,j]=(0,y.useState)(``),[M,N]=(0,y.useState)(``),[P,F]=(0,y.useState)(``),[I,L]=(0,y.useState)(`all`),[R,z]=(0,y.useState)(``),[B,V]=(0,y.useState)(`table`),[ee,te]=(0,y.useState)(W1e),[ne,re]=(0,y.useState)(B1e),[ie,ae]=(0,y.useState)(!1),[oe,se]=(0,y.useState)(()=>{try{return localStorage.getItem(`bambuddy-inventory-group`)===`true`}catch{return!1}}),[H,ce]=(0,y.useState)(new Set),[le,ue]=(0,y.useState)(new Set),[de,fe]=(0,y.useState)(!1),[pe,me]=(0,y.useState)(null),he=(0,y.useCallback)(e=>{ue(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),ge=(0,y.useCallback)(()=>ue(new Set),[]);(0,y.useEffect)(()=>{ue(new Set)},[w,E,O,A,M,P,I,R]);let[_e,ve]=(0,y.useState)(0),[ye,be]=(0,y.useState)(()=>{try{let e=localStorage.getItem(`bambuddy-inventory-pageSize`);if(e){let t=Number(e);if([15,30,50,100,-1].includes(t))return t}}catch{}return 15}),{data:xe}=K({queryKey:[`settings`],queryFn:Z.getSettings}),Se=xe?.date_format||`system`,Ce=(xe?.location_sensor_poll_interval||120)*1e3,{colorize:we,aboveColor:Te,belowColor:Ee,optimalColor:De}=R6(),Oe=e?[`spoolman-inventory-spools`]:[`inventory-spools`],ke=()=>b6(r,Oe),{data:Ae,isLoading:je}=K({queryKey:Oe,queryFn:()=>e?Z.getSpoolmanInventorySpools(!0):Z.getSpools(!0),refetchInterval:3e4}),Me=(0,y.useCallback)(async()=>{x(!0);try{await Z.exportSpoolsCsv()}catch(e){i(e instanceof Error?e.message:n(`inventory.csv.exportError`,`Export failed`),`error`)}finally{x(!1)}},[i,n]),Ne=e?n(`inventory.csv.spoolmanHint`,`In Spoolman mode, use Spoolman's built-in CSV import/export.`):void 0,{data:Pe=[]}=K({queryKey:v6,queryFn:Z.getLocations}),Fe=c.get(`location_id`),Ie=Fe===`__none__`?`__none__`:Fe&&/^\d+$/.test(Fe)&&Number(Fe)>0?Fe:``,Le=c.get(`spool`),Re=Le&&/^\d+$/.test(Le)&&Number(Le)>0?Number(Le):null,ze=Ae?.find(e=>e.id===Re)??null,Be=(0,y.useCallback)(()=>{f.current=!0,l(e=>(e.delete(`spool`),e),{replace:!0})},[l]),{data:Ve,isError:He,error:Ue}=K({queryKey:e?[`spoolman-inventory-spool`,Re]:[`inventory-spool`,Re],queryFn:()=>e?Z.getSpoolmanInventorySpool(Re):Z.getSpool(Re),enabled:t&&Re!==null&&ze===null,staleTime:1/0,retry:(e,t)=>e<2&&!(t instanceof sd&&t.status===404)});(0,y.useEffect)(()=>{if(!f.current){if(t&&Re&&ze){Be(),d({spool:ze,mode:`edit`});return}if(Ve){Be(),d({spool:Ve,mode:`edit`});return}He&&(Be(),i(n(Ue instanceof sd&&Ue.status===404?`inventory.deepLinkSpoolNotFound`:`inventory.deepLinkFetchFailed`),`error`))}},[t,Re,ze,Ve,He,Ue,Be,i,n]);let{data:We}=K({queryKey:[`spool-assignments`],queryFn:()=>Z.getAssignments(),refetchInterval:3e4}),{data:Ge=[],isError:Ke}=K({queryKey:[`spoolman-slot-assignments-all`],queryFn:()=>Z.getSpoolmanSlotAssignments(),enabled:e,refetchInterval:3e4,staleTime:1e4,retry:1}),qe=(0,y.useRef)(!1);(0,y.useEffect)(()=>{Ke&&!qe.current?(qe.current=!0,i(n(`inventory.spoolmanUnreachable`),`error`)):Ke||(qe.current=!1)},[Ke,i,n]);let{data:Je}=K({queryKey:[`spool-catalog`],queryFn:()=>Z.getSpoolCatalog()}),Ye=q({mutationFn:t=>e?Z.deleteSpoolmanInventorySpool(t):Z.deleteSpool(t),onSuccess:()=>{ke(),i(n(`inventory.spoolDeleted`),`success`)},onError:e=>{e instanceof sd&&e.status===404?i(n(`inventory.deleteSpoolNotFound`),`error`):e instanceof sd&&e.status===503?i(n(`inventory.spoolmanUnreachable`),`error`):i(n(`inventory.deleteFailed`),`error`)}}),Xe=q({mutationFn:t=>e?Z.archiveSpoolmanInventorySpool(t):Z.archiveSpool(t),onSuccess:()=>{ke(),i(n(`inventory.spoolArchived`),`success`)},onError:e=>{e instanceof sd&&e.status===404?i(n(`inventory.archiveSpoolNotFound`),`error`):e instanceof sd&&e.status===503?i(n(`inventory.spoolmanUnreachable`),`error`):i(n(`inventory.archiveFailed`),`error`)}}),Ze=q({mutationFn:t=>e?Z.restoreSpoolmanInventorySpool(t):Z.restoreSpool(t),onSuccess:()=>{ke(),i(n(`inventory.spoolRestored`),`success`)},onError:e=>{e instanceof sd&&e.status===404?i(n(`inventory.restoreSpoolNotFound`),`error`):e instanceof sd&&e.status===503?i(n(`inventory.spoolmanUnreachable`),`error`):i(n(`inventory.restoreFailed`),`error`)}}),Qe=q({mutationFn:t=>e?Z.resetSpoolmanInventorySpoolConsumedCounter(t):Z.resetSpoolConsumedCounter(t),onSuccess:()=>{r.invalidateQueries({queryKey:Oe}),i(n(`inventory.consumedCounterReset`),`success`)},onError:()=>{i(n(`inventory.resetConsumedCounterFailed`),`error`)}}),$e=q({mutationFn:t=>e?Z.bulkResetSpoolmanInventorySpoolConsumedCounter(t):Z.bulkResetSpoolConsumedCounter(t),onSuccess:e=>{r.invalidateQueries({queryKey:Oe}),i(n(`inventory.allConsumedCountersReset`,{count:e.reset}),`success`),me(null),ge()},onError:()=>{i(n(`inventory.resetConsumedCounterFailed`),`error`)}}),et=e=>(e.not_found?.length??0)+(e.errors?.length??0),tt=q({mutationFn:async({ids:t,update:n})=>e?Z.bulkUpdateSpoolmanInventorySpools(t,n):Z.bulkUpdateSpools(t,n),onSuccess:e=>{ke();let t=et(e);if(e.updated===0){i(n(`inventory.bulk.updateAllFailed`,{count:t}),`error`);return}t>0?i(n(`inventory.bulk.updatePartial`,{ok:e.updated,failed:t}),`warning`):i(n(`inventory.bulk.updateSuccess`,{count:e.updated}),`success`),fe(!1),ge()},onError:e=>{i(e.message||n(`inventory.bulk.updateFailed`),`error`)}}),nt=q({mutationFn:async t=>e?Z.bulkDeleteSpoolmanInventorySpools(t):Z.bulkDeleteSpools(t),onSuccess:e=>{ke();let t=et(e);if(e.deleted===0){i(n(`inventory.bulk.deleteAllFailed`,{count:t}),`error`);return}t>0?i(n(`inventory.bulk.deletePartial`,{ok:e.deleted,failed:t}),`warning`):i(n(`inventory.bulk.deleteSuccess`,{count:e.deleted}),`success`),me(null),ge()},onError:e=>{i(e.message||n(`inventory.bulk.deleteFailed`),`error`)}}),rt=q({mutationFn:async t=>e?Z.bulkArchiveSpoolmanInventorySpools(t):Z.bulkArchiveSpools(t),onSuccess:e=>{ke();let t=et(e);if(e.archived===0&&t>0){i(n(`inventory.bulk.archiveAllFailed`,{count:t}),`error`);return}t>0?i(n(`inventory.bulk.archivePartial`,{ok:e.archived,failed:t}),`warning`):i(n(`inventory.bulk.archiveSuccess`,{count:e.archived}),`success`),me(null),ge()},onError:e=>{i(e.message||n(`inventory.bulk.archiveFailed`),`error`)}}),it=q({mutationFn:async t=>e?Z.bulkRestoreSpoolmanInventorySpools(t):Z.bulkRestoreSpools(t),onSuccess:e=>{ke();let t=et(e);if(e.restored===0&&t>0){i(n(`inventory.bulk.restoreAllFailed`,{count:t}),`error`);return}t>0?i(n(`inventory.bulk.restorePartial`,{ok:e.restored,failed:t}),`warning`):i(n(`inventory.bulk.restoreSuccess`,{count:e.restored}),`success`),me(null),ge()},onError:e=>{i(e.message||n(`inventory.bulk.restoreFailed`),`error`)}}),at=(0,y.useMemo)(()=>(Ae??[]).map(e=>e.id),[Ae]),ot=async t=>{if(t.last_scale_weight!=null)try{e?await Z.syncSpoolmanSpoolWeight(t.id,t.last_scale_weight):await Od.updateSpoolWeight(t.id,t.last_scale_weight),r.invalidateQueries({queryKey:Oe}),i(`Synced "${[t.brand,t.material,t.color_name].filter(Boolean).join(` `)}" to scale weight`,`success`)}catch(e){let t=e instanceof sd&&e.status===404,r=e instanceof sd&&e.status===503;i(n(t?`inventory.syncWeightSpoolNotFound`:r?`inventory.syncWeightSpoolmanUnreachable`:`inventory.syncWeightFailed`),`error`)}},st=xe?.low_stock_threshold??20,[ct,lt]=(0,y.useState)(!1),[ut,dt]=(0,y.useState)(st.toString());(0,y.useEffect)(()=>{ct||dt(st.toString())},[st,ct]);let ft=q({mutationFn:e=>Z.updateSettings({low_stock_threshold:e}),onSuccess:()=>{r.invalidateQueries({queryKey:[`settings`]}),i(n(`common.saved`),`success`),lt(!1)},onError:()=>{i(n(`inventory.lowStockThresholdError`),`error`)}}),pt=(0,y.useMemo)(()=>{if(!Ae)return null;let e=0,t=0,n=0,r=0,i={};for(let a of Ae){if(t+=Math.max(0,a.weight_used-(a.weight_used_baseline??0)),a.archived_at)continue;r++;let o=Math.max(0,a.label_weight-a.weight_used);e+=o,(a.label_weight>0?o/a.label_weight*100:0)<(a.low_stock_threshold_pct??st)&&n++;let s=a.material||`Unknown`;i[s]||(i[s]={count:0,weight:0}),i[s].count++,i[s].weight+=o}return{totalWeight:e,totalConsumed:t,lowStock:n,byMaterial:i,totalSpools:r}},[Ae,st]),mt=(We?.length??0)+(e?Ge.length:0),ht=Lf(xe?.currency||`USD`),gt=(0,y.useMemo)(()=>{let e={};for(let t of We||[])e[t.spool_id]={printer_id:t.printer_id,printer_name:t.printer_name,ams_id:t.ams_id,tray_id:t.tray_id,ams_label:t.ams_label??null};for(let t of Ge)typeof t?.spoolman_spool_id!=`number`||t.spoolman_spool_id<=0||typeof t.printer_id!=`number`||typeof t.ams_id!=`number`||typeof t.tray_id!=`number`||e[t.spoolman_spool_id]||(e[t.spoolman_spool_id]={printer_id:t.printer_id,printer_name:t.printer_name??null,ams_id:t.ams_id,tray_id:t.tray_id,ams_label:t.ams_label??null});return e},[We,Ge]),_t=(0,y.useMemo)(()=>{let e={};for(let t of Je||[])e[t.id]=t;return e},[Je]),{data:vt}=K({queryKey:[`locationHaSensors`],queryFn:()=>Z.getLocationHASensors()}),yt=(0,y.useMemo)(()=>new Set((vt??[]).map(e=>e.location_id)),[vt]),bt=(0,y.useMemo)(()=>{let e=new Set;for(let t of Ae||[])t.location_id&&yt.has(t.location_id)&&e.add(t.location_id);return Array.from(e)},[Ae,yt]),xt=B===`cards`||B===`table`&&ne.some(e=>e.visible&&(e.id===`temperature`||e.id===`humidity`||e.id===`battery`)),St=Co({queries:bt.map(e=>({queryKey:[`locationHaSensorReadings`,e],queryFn:()=>Z.getLocationHASensorReadings(e,!1),refetchInterval:Ce,enabled:xt}))}),Ct=(0,y.useMemo)(()=>{let e={};return bt.forEach((t,n)=>{let r=St[n]?.data;r&&(e[t]=r)}),e},[bt,St]),wt=(0,y.useMemo)(()=>pt?Object.entries(pt.byMaterial).sort((e,t)=>t[1].weight-e[1].weight).slice(0,4):[],[pt]),Tt=(0,y.useMemo)(()=>{let e=Ae||[];if(e=w===`active`?e.filter(e=>!e.archived_at):e.filter(e=>!!e.archived_at),E===`used`?e=e.filter(e=>e.weight_used>0):E===`new`?e=e.filter(e=>e.weight_used===0):E===`lowstock`&&(e=e.filter(e=>{let t=Math.max(0,e.label_weight-e.weight_used);return(e.label_weight>0?t/e.label_weight*100:0)<(e.low_stock_threshold_pct??st)})),O&&(e=e.filter(e=>e.material===O)),A&&(e=e.filter(e=>e.brand===A)),M&&(e=M===`__none__`?e.filter(e=>!e.category):e.filter(e=>e.category===M)),P){let t=Number(P);e=e.filter(e=>e.core_weight_catalog_id===t)}if(Ie)if(Ie===`__none__`)e=e.filter(e=>!e.location_id&&!e.storage_location?.trim());else{let t=Number(Ie),n=Pe.find(e=>e.id===t)?.name?.trim().toLowerCase();e=e.filter(e=>e.location_id==null?n?(e.storage_location||``).trim().toLowerCase()===n:!1:e.location_id===t)}return I===`stock`?e=e.filter(e=>!e.slicer_filament):I===`configured`&&(e=e.filter(e=>!!e.slicer_filament)),R&&(e=wH(e,R)),e},[Ae,w,E,O,A,M,P,I,Ie,R,st,Pe]),Et=()=>ve(0),Dt=(0,y.useCallback)(e=>{l(t=>(t.delete(`location_id`),e&&t.set(`location_id`,e),t),{replace:!0}),Et()},[l]),Ot=[...new Set(Ae?.map(e=>e.material)||[])].sort(),kt=[...new Set(Ae?.map(e=>e.brand).filter(Boolean)||[])].sort(),At=[...new Set(Ae?.map(e=>e.category?.trim()).filter(Boolean)||[])].sort(),jt=(Ae??[]).some(e=>!e.category),Mt=[...new Set(Ae?.map(e=>e.core_weight_catalog_id).filter(e=>e!=null)||[])].sort((e,t)=>{let n=(_t[e]?.name||``).toLowerCase(),r=(_t[t]?.name||``).toLowerCase();return n.localeCompare(r)}),Nt=(Ae??[]).some(e=>!e.location_id&&!e.storage_location?.trim()),Pt=w!==`active`||E!==`all`||!!O||!!A||!!M||!!P||!!Ie||I!==`all`||!!R,Ft=e=>{re(e),V1e(e)},It=(0,y.useMemo)(()=>ne.filter(e=>e.visible).map(e=>e.id),[ne]),Lt=e=>{E9[e]&&(te(t=>{let n;return n=t?.column===e?t.direction===`asc`?{column:e,direction:`desc`}:null:{column:e,direction:`asc`},G1e(n),n}),Et())},Rt=(0,y.useMemo)(()=>{if(!ee)return Tt;let e=E9[ee.column];return e?[...Tt].sort((t,n)=>{let r=e(t,gt,Ct),i=e(n,gt,Ct);return ri?ee.direction===`asc`?1:-1:0}):Tt},[Tt,ee,gt,Ct]),zt=(0,y.useMemo)(()=>{if(!oe)return Rt.map(e=>({type:`single`,spool:e}));let e=new Map;for(let t of Rt)if(!(t.weight_used>0||gt[t.id])){let n=R1e(t),r=e.get(n);r?r.push(t):e.set(n,[t])}let t=[],n=new Set;for(let r of Rt){if(r.weight_used>0||gt[r.id]){t.push({type:`single`,spool:r});continue}let i=R1e(r);if(n.has(i))continue;n.add(i);let a=e.get(i);a.length===1?t.push({type:`single`,spool:a[0]}):t.push({type:`group`,key:i,spools:a,representative:a[0]})}return t},[Rt,oe,gt]),Bt=ye===-1,Vt=zt.length,Ht=Bt?Vt||1:ye,Ut=Math.max(1,Math.ceil(Vt/Ht)),Wt=Bt?0:Math.min(_e,Ut-1),Gt=Bt?zt:zt.slice(Wt*Ht,(Wt+1)*Ht),Kt=()=>{let e=!oe;se(e),ce(new Set),Et();try{localStorage.setItem(`bambuddy-inventory-group`,String(e))}catch{}},qt=e=>{ce(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},Jt=e=>{be(e),ve(0);try{localStorage.setItem(`bambuddy-inventory-pageSize`,String(e))}catch{}};return(0,G.jsxs)(`div`,{className:`p-4 md:p-8 space-y-6`,children:[(0,G.jsxs)(`div`,{className:`flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,G.jsx)(Cl,{className:`w-7 h-7 text-bambu-green`}),n(`inventory.title`)]}),(0,G.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:n(`inventory.subtitle`)})]}),(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,G.jsxs)(Q,{variant:`secondary`,disabled:e,onClick:()=>v(!0),title:Ne,children:[(0,G.jsx)(Vu,{className:`w-4 h-4`}),n(`inventory.csv.importButton`,`Import CSV`)]}),(0,G.jsxs)(Q,{variant:`secondary`,disabled:e||b,onClick:Me,title:Ne,children:[b?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Xs,{className:`w-4 h-4`}),n(`inventory.csv.exportButton`,`Export CSV`)]}),(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>C(!0),children:[(0,G.jsx)(ol,{className:`w-4 h-4`}),n(`locations.manage`)]}),(0,G.jsxs)(Q,{variant:`secondary`,disabled:Tt.length===0,onClick:()=>g(Tt.map(e=>e.id)),title:Tt.length===0?n(`inventory.labels.noSpoolsTitle`,`No spools to label`):n(`inventory.labels.bulkTitle`,`Pick spools to print labels for from the {{count}} currently shown`,{count:Tt.length}),children:[(0,G.jsx)(Rl,{className:`w-4 h-4`}),n(`inventory.labels.printLabels`,`Print labels…`)]}),(0,G.jsxs)(Q,{onClick:()=>d({spool:null,mode:`create`}),children:[(0,G.jsx)(Fl,{className:`w-4 h-4`}),n(`inventory.addSpool`)]})]})]}),pt&&!je&&(0,G.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-3 lg:grid-cols-5 gap-3`,children:[(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,G.jsx)(Cl,{className:`w-4 h-4 text-bambu-green`}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray font-medium uppercase tracking-wide`,children:n(`inventory.totalInventory`)})]}),(0,G.jsx)(`div`,{className:`text-xl font-bold text-white`,children:C9(pt.totalWeight,!0)}),(0,G.jsxs)(`div`,{className:`text-xs text-bambu-gray mt-1`,children:[pt.totalSpools,` `,pt.totalSpools===1?n(`inventory.spool`):n(`inventory.spools`)]})]}),(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-2 mb-1`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Fu,{className:`w-4 h-4 text-blue-600 dark:text-blue-400`}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray font-medium uppercase tracking-wide`,children:n(`inventory.totalConsumed`)})]}),pt.totalConsumed>0&&at.length>0&&(0,G.jsx)(`button`,{onClick:()=>m({type:`reset-all-consumed-counters`}),className:`p-1 text-bambu-gray hover:text-red-600 dark:hover:text-red-400 rounded transition-colors`,title:n(`inventory.resetAllConsumedCountersTooltip`),"aria-label":n(`inventory.resetAllConsumedCounters`),children:(0,G.jsx)(nc,{className:`w-3.5 h-3.5`})})]}),(0,G.jsx)(`div`,{className:`text-xl font-bold text-white`,children:C9(pt.totalConsumed,!0)}),(0,G.jsx)(`div`,{className:`text-xs text-bambu-gray mt-1`,children:n(`inventory.sinceTracking`)})]}),(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,G.jsx)(Jc,{className:`w-4 h-4 text-green-600 dark:text-green-400`}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray font-medium uppercase tracking-wide`,children:n(`inventory.byMaterial`)})]}),(0,G.jsx)(`div`,{className:`flex flex-wrap gap-1.5 mt-1`,children:wt.map(([e,t])=>(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-medium ${H1e[e]||`bg-bambu-dark-tertiary text-bambu-gray`}`,children:[e,` `,(0,G.jsx)(`span`,{className:`opacity-70`,children:C9(t.weight,!0)})]},e))})]}),(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,G.jsx)(Rl,{className:`w-4 h-4 text-purple-600 dark:text-purple-400`}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray font-medium uppercase tracking-wide`,children:n(`inventory.inPrinter`)})]}),(0,G.jsx)(`div`,{className:`text-xl font-bold text-white`,children:mt}),(0,G.jsx)(`div`,{className:`text-xs text-bambu-gray mt-1`,children:n(`inventory.loadedInAms`)})]}),(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,G.jsx)(Lu,{className:`w-4 h-4 text-yellow-600 dark:text-yellow-400`}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray font-medium uppercase tracking-wide`,children:n(`inventory.lowStock`)})]}),(0,G.jsx)(`div`,{className:`text-xl font-bold ${pt.lowStock>0?`text-yellow-700 dark:text-yellow-400`:`text-white`}`,children:pt.lowStock}),(0,G.jsx)(`div`,{className:`text-xs text-bambu-gray mt-1 flex items-center gap-2`,children:ct?(0,G.jsxs)(`form`,{onSubmit:e=>{e.preventDefault();let t=parseFloat(ut);!isNaN(t)&&t>=.1&&t<=99.9?ft.mutate(t):i(n(`inventory.lowStockThresholdError`),`error`)},className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:`<`}),(0,G.jsx)(`input`,{type:`text`,inputMode:`decimal`,pattern:`^\\d{0,2}(\\.\\d?)?$`,maxLength:4,value:ut,onChange:e=>{let t=e.target.value.replace(/[^\d.]/g,``);/^\d{0,2}(\.\d?)?$/.test(t)&&dt(t)},className:`px-1.5 py-1 rounded border border-bambu-dark-tertiary text-xs text-white bg-bambu-dark-secondary focus:outline-none focus:border-bambu-green w-14 text-center`,onWheel:e=>e.currentTarget.blur(),disabled:ft.isPending}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:`%`}),(0,G.jsx)(Q,{type:`submit`,size:`sm`,disabled:ft.isPending,children:n(`common.save`)}),(0,G.jsx)(Q,{type:`button`,size:`sm`,variant:`ghost`,onClick:()=>lt(!1),disabled:ft.isPending,children:n(`common.cancel`)})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`span`,{className:`text-bambu-gray`,children:[`< `,st,`%`]}),(0,G.jsx)(`button`,{className:`p-1.5 text-bambu-gray hover:text-white rounded transition-colors`,title:n(`common.edit`),onClick:()=>{dt(st.toString()),lt(!0)},children:(0,G.jsx)(kl,{className:`w-4 h-4`})})]})})]})]}),(0,G.jsxs)(`div`,{className:`flex flex-col sm:flex-row gap-3 items-start sm:items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`relative flex-1 max-w-md ${B===`forecast`?`invisible pointer-events-none`:``}`,children:[(0,G.jsx)(Ql,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50`}),(0,G.jsx)(`input`,{type:`text`,value:R,onChange:e=>{z(e.target.value),Et()},placeholder:n(`inventory.search`),className:`w-full pl-10 pr-8 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`}),R&&(0,G.jsx)(`button`,{onClick:()=>{z(``),Et()},className:`absolute right-3 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white`,children:(0,G.jsx)(nd,{className:`w-4 h-4`})})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[B===`table`&&(0,G.jsxs)(`button`,{onClick:()=>ae(!0),className:`flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium text-bambu-gray border border-bambu-dark-tertiary rounded-lg hover:bg-bambu-dark-tertiary transition-colors`,title:n(`inventory.configureColumns`),children:[(0,G.jsx)(zs,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:n(`inventory.columns`)})]}),B!==`forecast`&&(0,G.jsxs)(`button`,{onClick:Kt,className:`flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium border rounded-lg transition-colors ${oe?`bg-bambu-green/20 text-bambu-green border-bambu-green/30`:`text-bambu-gray border-bambu-dark-tertiary hover:bg-bambu-dark-tertiary`}`,title:n(`inventory.groupSimilar`),children:[(0,G.jsx)(Mc,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:n(`inventory.groupSimilar`)})]}),(0,G.jsxs)(`div`,{className:`flex bg-bambu-dark-primary border border-bambu-dark-tertiary rounded-lg overflow-hidden`,children:[(0,G.jsxs)(`button`,{onClick:()=>V(`table`),className:`flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium transition-colors ${B===`table`?`bg-bambu-green text-white`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:[(0,G.jsx)(Tu,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:n(`inventory.table`)})]}),(0,G.jsxs)(`button`,{onClick:()=>V(`cards`),className:`flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium transition-colors ${B===`cards`?`bg-bambu-green text-white`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:[(0,G.jsx)(Yc,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:n(`inventory.cards`)})]}),(0,G.jsxs)(`button`,{onClick:()=>s&&V(`forecast`),disabled:!s,title:s?void 0:n(`forecast.noReadAccess`),className:`flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium transition-colors disabled:opacity-40 disabled:cursor-not-allowed ${B===`forecast`?`bg-bambu-green text-white`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:[s?(0,G.jsx)(Iu,{className:`w-4 h-4`}):(0,G.jsx)(nl,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:n(`forecast.title`)})]})]})]})]}),(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 ${B===`forecast`?`hidden`:``}`,children:[(0,G.jsxs)(`div`,{className:`flex items-center rounded-lg border border-bambu-dark-tertiary overflow-hidden`,children:[(0,G.jsxs)(`button`,{onClick:()=>{T(`active`),Et()},className:`flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium transition-colors ${w===`active`?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:[(0,G.jsx)(Cl,{className:`w-3.5 h-3.5`}),n(`inventory.active`)]}),(0,G.jsxs)(`button`,{onClick:()=>{T(`archived`),Et()},className:`flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium transition-colors ${w===`archived`?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:[(0,G.jsx)(Po,{className:`w-3.5 h-3.5`}),n(`inventory.archived`)]})]}),(0,G.jsx)(`div`,{className:`w-px h-5 bg-bambu-dark-tertiary`}),(0,G.jsxs)(`div`,{className:`flex items-center rounded-lg border border-bambu-dark-tertiary overflow-hidden`,children:[(0,G.jsx)(`button`,{onClick:()=>{D(`all`),Et()},className:`px-3 py-1.5 text-xs font-medium transition-colors ${E===`all`?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:n(`inventory.all`)}),(0,G.jsxs)(`button`,{onClick:()=>{D(`used`),Et()},className:`flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium transition-colors ${E===`used`?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:[(0,G.jsx)(js,{className:`w-3.5 h-3.5`}),n(`inventory.used`)]}),(0,G.jsx)(`button`,{onClick:()=>{D(`new`),Et()},className:`px-3 py-1.5 text-xs font-medium transition-colors ${E===`new`?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:n(`inventory.new`)}),(0,G.jsxs)(`button`,{onClick:()=>{D(`lowstock`),Et()},className:`flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium transition-colors ${E===`lowstock`?`bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:[(0,G.jsx)(Lu,{className:`w-3.5 h-3.5`}),n(`inventory.lowStock`)]})]}),(0,G.jsxs)(`div`,{className:`flex items-center rounded-lg border border-bambu-dark-tertiary overflow-hidden`,children:[(0,G.jsx)(`button`,{onClick:()=>{L(`all`),Et()},className:`px-3 py-1.5 text-xs font-medium transition-colors ${I===`all`?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:n(`inventory.all`)}),(0,G.jsx)(`button`,{onClick:()=>{L(`stock`),Et()},className:`px-3 py-1.5 text-xs font-medium transition-colors ${I===`stock`?`bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-400`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:n(`inventory.stock`)}),(0,G.jsx)(`button`,{onClick:()=>{L(`configured`),Et()},className:`px-3 py-1.5 text-xs font-medium transition-colors ${I===`configured`?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:n(`inventory.configured`)})]}),(0,G.jsx)(`div`,{className:`w-px h-5 bg-bambu-dark-tertiary`}),(0,G.jsxs)(`select`,{value:O,onChange:e=>{k(e.target.value),Et()},className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${O?`bg-bambu-green/20 text-bambu-green border-bambu-green/30`:`bg-transparent text-bambu-gray border-bambu-dark-tertiary hover:bg-bambu-dark-tertiary`}`,children:[(0,G.jsx)(`option`,{value:``,children:n(`inventory.material`)}),Ot.map(e=>(0,G.jsx)(`option`,{value:e,children:e},e))]}),(0,G.jsxs)(`select`,{value:A,onChange:e=>{j(e.target.value),Et()},className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${A?`bg-bambu-green/20 text-bambu-green border-bambu-green/30`:`bg-transparent text-bambu-gray border-bambu-dark-tertiary hover:bg-bambu-dark-tertiary`}`,children:[(0,G.jsx)(`option`,{value:``,children:n(`inventory.brand`)}),kt.map(e=>(0,G.jsx)(`option`,{value:e,children:e},e))]}),(At.length>0||M)&&(0,G.jsxs)(`select`,{value:M,onChange:e=>{N(e.target.value),Et()},className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${M?`bg-bambu-green/20 text-bambu-green border-bambu-green/30`:`bg-transparent text-bambu-gray border-bambu-dark-tertiary hover:bg-bambu-dark-tertiary`}`,children:[(0,G.jsx)(`option`,{value:``,children:n(`inventory.category`)}),At.map(e=>(0,G.jsx)(`option`,{value:e,children:e},e)),jt&&(0,G.jsx)(`option`,{value:`__none__`,children:n(`inventory.categoryNone`)})]}),Mt.length>0&&(0,G.jsxs)(`select`,{value:P,onChange:e=>{F(e.target.value),Et()},className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${P?`bg-bambu-green/20 text-bambu-green border-bambu-green/30`:`bg-transparent text-bambu-gray border-bambu-dark-tertiary hover:bg-bambu-dark-tertiary`}`,children:[(0,G.jsx)(`option`,{value:``,children:n(`inventory.spoolName`)}),Mt.map(e=>(0,G.jsx)(`option`,{value:e,children:_t[e]?.name||`#${e}`},e))]}),(Pe.length>0||Ie)&&(0,G.jsxs)(`select`,{value:Ie,onChange:e=>{Dt(e.target.value)},className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${Ie?`bg-bambu-green/20 text-bambu-green border-bambu-green/30`:`bg-transparent text-bambu-gray border-bambu-dark-tertiary hover:bg-bambu-dark-tertiary`}`,children:[(0,G.jsx)(`option`,{value:``,children:n(`inventory.storageLocation`)}),Pe.map(e=>(0,G.jsx)(`option`,{value:String(e.id),children:e.name},e.id)),Nt&&(0,G.jsx)(`option`,{value:`__none__`,children:n(`inventory.storageLocationNone`)})]}),Pt&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`w-px h-5 bg-bambu-dark-tertiary`}),(0,G.jsxs)(`button`,{onClick:()=>{T(`active`),D(`all`),k(``),j(``),N(``),F(``),L(`all`),z(``),l(e=>(e.delete(`location_id`),e),{replace:!0}),Et()},className:`flex items-center gap-1 text-xs text-bambu-gray hover:text-bambu-green transition-colors`,children:[(0,G.jsx)(nd,{className:`w-3.5 h-3.5`}),n(`inventory.clearFilters`)]})]}),B!==`forecast`&&(0,G.jsxs)(`span`,{className:`ml-auto text-xs text-bambu-gray`,children:[Rt.length,` `,Rt.length===1?n(`inventory.spool`):n(`inventory.spools`),oe&&Vt0&&B!==`forecast`&&(0,G.jsxs)(`div`,{className:`sticky top-2 z-10 mb-4 flex items-center gap-2 px-3 py-2 bg-bambu-green/10 border border-bambu-green/30 rounded-lg backdrop-blur-sm`,children:[(0,G.jsx)(`span`,{className:`text-sm text-bambu-green font-medium`,children:n(`inventory.bulk.selectionCount`,{count:le.size})}),(0,G.jsxs)(`div`,{className:`ml-auto flex flex-wrap items-center gap-2`,children:[(0,G.jsxs)(Q,{size:`sm`,variant:`secondary`,onClick:()=>fe(!0),children:[(0,G.jsx)(kl,{className:`w-3.5 h-3.5 mr-1.5`}),n(`inventory.bulk.edit`)]}),(0,G.jsxs)(Q,{size:`sm`,variant:`secondary`,onClick:()=>g([...le]),children:[(0,G.jsx)(Rl,{className:`w-3.5 h-3.5 mr-1.5`}),n(`inventory.bulk.printLabels`)]}),(0,G.jsxs)(Q,{size:`sm`,variant:`secondary`,onClick:()=>me(`reset-consumed-counter`),children:[(0,G.jsx)(nc,{className:`w-3.5 h-3.5 mr-1.5`}),n(`inventory.bulk.resetUsage`)]}),w===`archived`?(0,G.jsxs)(Q,{size:`sm`,variant:`secondary`,onClick:()=>me(`restore`),children:[(0,G.jsx)(Wl,{className:`w-3.5 h-3.5 mr-1.5`}),n(`inventory.bulk.restore`)]}):(0,G.jsxs)(Q,{size:`sm`,variant:`secondary`,onClick:()=>me(`archive`),children:[(0,G.jsx)(Po,{className:`w-3.5 h-3.5 mr-1.5`}),n(`inventory.bulk.archive`)]}),(0,G.jsxs)(Q,{size:`sm`,variant:`danger`,onClick:()=>me(`delete`),children:[(0,G.jsx)(Pu,{className:`w-3.5 h-3.5 mr-1.5`}),n(`inventory.bulk.delete`)]}),(0,G.jsx)(`button`,{className:`p-1.5 text-bambu-gray hover:text-white rounded transition-colors`,onClick:ge,title:n(`inventory.bulk.clearSelection`),"aria-label":n(`inventory.bulk.clearSelection`),children:(0,G.jsx)(nd,{className:`w-4 h-4`})})]})]}),je?(0,G.jsx)(`div`,{className:`flex justify-center py-16`,children:(0,G.jsx)(Y,{className:`w-8 h-8 text-bambu-green animate-spin`})}):B===`forecast`?(0,G.jsx)(Y$e,{spools:Ae||[]}):B===`cards`?Gt.length>0?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4`,children:Gt.map(e=>{if(e.type===`group`){let{key:t,spools:r,representative:i}=e,a=r.reduce((e,t)=>e+Math.max(0,t.label_weight-t.weight_used),0),o=bH({rgba:i.rgba,extraColors:i.extra_colors,effectType:i.effect_type,subtype:i.subtype,effectSize:`groupheader`}),s=H.has(t);return(0,G.jsxs)(`div`,{className:`col-span-full`,children:[(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg overflow-hidden border border-bambu-green/30 hover:border-bambu-green transition-colors cursor-pointer`,onClick:()=>qt(t),children:[(0,G.jsx)(`div`,{className:`h-10 flex items-center px-4 gap-3`,style:o,children:(0,G.jsx)(`span`,{className:`bg-white/90 text-gray-800 px-3 py-0.5 rounded-full text-sm font-medium`,children:kf(i.color_name,i.rgba)||`-`})}),(0,G.jsxs)(`div`,{className:`px-4 py-3 flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(ps,{className:`w-4 h-4 text-bambu-gray transition-transform ${s?``:`-rotate-90`}`}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`h3`,{className:`font-semibold text-white`,children:[i.material,i.subtype?` ${i.subtype}`:``]}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i.brand||`-`})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,title:n(`inventory.remaining`),children:C9(a)}),(0,G.jsx)(`span`,{className:`text-xs font-medium bg-bambu-green/20 text-bambu-green px-2 py-0.5 rounded-full`,children:n(`inventory.groupedSpools`,{count:r.length})})]})]})]}),s&&(0,G.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4 mt-2 ml-4`,children:r.map(e=>{let t=Math.max(0,e.label_weight-e.weight_used);return(0,G.jsx)(Y1e,{spool:e,remaining:t,pct:e.label_weight>0?t/e.label_weight*100:0,onClick:()=>d({spool:e,mode:`edit`}),onPrintLabel:()=>g([e.id]),onCopy:()=>d({spool:e,mode:`copy`}),t:n,colorizeLocationSensors:we,locationSensorAboveColor:Te,locationSensorBelowColor:Ee,locationSensorOptimalColor:De},e.id)})})]},`group-${t}`)}let t=e.spool,r=Math.max(0,t.label_weight-t.weight_used);return(0,G.jsx)(Y1e,{spool:t,remaining:r,pct:t.label_weight>0?r/t.label_weight*100:0,onClick:()=>d({spool:t,mode:`edit`}),onPrintLabel:()=>g([t.id]),onCopy:()=>d({spool:t,mode:`copy`}),t:n,colorizeLocationSensors:we,locationSensorAboveColor:Te,locationSensorBelowColor:Ee,locationSensorOptimalColor:De},t.id)})}),(0,G.jsx)(J1e,{pageIndex:Wt,pageSize:ye,totalRows:Vt,totalPages:Ut,onPageChange:ve,onPageSizeChange:Jt,t:n})]}):(0,G.jsx)(t0e,{hasFilters:Pt,onAddSpool:()=>d({spool:null,mode:`create`}),t:n}):Gt.length>0?(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg overflow-hidden border border-bambu-dark-tertiary`,children:[(0,G.jsx)(`div`,{className:`overflow-x-auto`,children:(0,G.jsxs)(`table`,{className:`w-full`,children:[(0,G.jsx)(`thead`,{children:(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary bg-bambu-dark-tertiary/30`,children:[(0,G.jsx)(`th`,{className:`w-10 px-3 py-3`,children:(0,G.jsx)(`input`,{type:`checkbox`,className:`h-4 w-4 cursor-pointer`,"aria-label":n(`inventory.bulk.selectAllVisible`),checked:Gt.length>0&&Gt.every(e=>(e.type===`group`?e.spools.map(e=>e.id):[e.spool.id]).every(e=>le.has(e))),onChange:e=>{if(e.target.checked){let e=new Set(le);for(let t of Gt){let n=t.type===`group`?t.spools.map(e=>e.id):[t.spool.id];for(let t of n)e.add(t)}ue(e)}else{let e=new Set(le);for(let t of Gt){let n=t.type===`group`?t.spools.map(e=>e.id):[t.spool.id];for(let t of n)e.delete(t)}ue(e)}}})}),It.map(e=>{let t=!!E9[e],r=ee?.column===e;return(0,G.jsx)(`th`,{className:`text-left py-3 px-4 text-xs font-medium uppercase tracking-wide select-none ${e===`remaining`?`min-w-[150px]`:``} ${t?`cursor-pointer hover:text-bambu-green transition-colors`:``} ${r?`text-bambu-green`:`text-bambu-gray`}`,onClick:t?()=>Lt(e):void 0,children:(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[U1e[e]?.(n)??e,t&&(r?ee.direction===`asc`?(0,G.jsx)(Ho,{className:`w-3 h-3`}):(0,G.jsx)(Io,{className:`w-3 h-3`}):(0,G.jsx)(Bo,{className:`w-3 h-3 opacity-30`}))]})},e)}),(0,G.jsx)(`th`,{className:`text-right py-3 px-4 text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:n(`common.actions`)})]})}),(0,G.jsx)(`tbody`,{children:Gt.map(e=>{if(e.type===`group`){let{key:t,spools:r}=e,i=H.has(t),a=L1e(r),o=Math.max(0,a.label_weight-a.weight_used);return(0,G.jsx)(e0e,{spools:r,headerSpool:a,remaining:o,pct:a.label_weight>0?o/a.label_weight*100:0,isExpanded:i,onToggle:()=>qt(t),selectedIds:le,onToggleSelected:he,onToggleGroupSelected:(e,t)=>{ue(n=>{let r=new Set(n);for(let n of e)t?r.add(n):r.delete(n);return r})},onEdit:e=>d({spool:e,mode:`edit`}),onCopy:e=>d({spool:e,mode:`copy`}),onArchive:e=>m({type:`archive`,spoolId:e}),onDelete:e=>m({type:`delete`,spoolId:e}),onPrintLabel:e=>g([e]),onResetConsumedCounter:e=>m({type:`reset-consumed-counter`,spoolId:e}),visibleColumns:It,assignmentMap:gt,catalogMap:_t,locationReadingsMap:Ct,currencySymbol:ht,dateFormat:Se,t:n,onSyncWeight:ot,colorizeLocationSensors:we,locationSensorAboveColor:Te,locationSensorBelowColor:Ee,locationSensorOptimalColor:De},`group-${t}`)}let t=e.spool,r=Math.max(0,t.label_weight-t.weight_used);return(0,G.jsx)($1e,{spool:t,remaining:r,pct:t.label_weight>0?r/t.label_weight*100:0,isSelected:le.has(t.id),onToggleSelected:()=>he(t.id),onEdit:()=>d({spool:t,mode:`edit`}),onCopy:()=>d({spool:t,mode:`copy`}),onRestore:()=>Ze.mutate(t.id),onArchive:()=>m({type:`archive`,spoolId:t.id}),onDelete:()=>m({type:`delete`,spoolId:t.id}),onPrintLabel:()=>g([t.id]),onResetConsumedCounter:()=>m({type:`reset-consumed-counter`,spoolId:t.id}),visibleColumns:It,assignmentMap:gt,catalogMap:_t,locationReadingsMap:Ct,currencySymbol:ht,dateFormat:Se,t:n,onSyncWeight:ot,colorizeLocationSensors:we,locationSensorAboveColor:Te,locationSensorBelowColor:Ee,locationSensorOptimalColor:De},t.id)})})]})}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 bg-bambu-dark-tertiary/50 border-t border-bambu-dark-tertiary text-sm`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:Bt?`${Vt} ${n(Vt===1?`inventory.spool`:`inventory.spools`)}`:(0,G.jsxs)(G.Fragment,{children:[n(`inventory.showing`),` `,Wt*Ht+1,` `,n(`inventory.to`),` `,Math.min((Wt+1)*Ht,Vt),` `,n(`inventory.of`),` `,Vt,` `,n(`inventory.spools`)]})}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:n(`inventory.show`)}),(0,G.jsxs)(`select`,{value:ye,onChange:e=>Jt(Number(e.target.value)),className:`px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:outline-none focus:border-bambu-green`,children:[[15,30,50,100].map(e=>(0,G.jsx)(`option`,{value:e,children:e},e)),(0,G.jsx)(`option`,{value:-1,children:n(`inventory.all`)})]}),!Bt&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`button`,{onClick:()=>ve(0),disabled:Wt===0,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,title:`First page`,children:(0,G.jsx)(_s,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:()=>ve(e=>Math.max(0,e-1)),disabled:Wt===0,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,children:(0,G.jsx)(hs,{className:`w-4 h-4`})}),(0,G.jsxs)(`span`,{className:`text-bambu-gray px-2 whitespace-nowrap`,children:[n(`inventory.page`),` `,Wt+1,` `,n(`inventory.of`),` `,Ut]}),(0,G.jsx)(`button`,{onClick:()=>ve(e=>Math.min(Ut-1,e+1)),disabled:Wt>=Ut-1,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,children:(0,G.jsx)(ms,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:()=>ve(Ut-1),disabled:Wt>=Ut-1,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,title:`Last page`,children:(0,G.jsx)(vs,{className:`w-4 h-4`})})]})]})]})]}):(0,G.jsx)(t0e,{hasFilters:Pt,onAddSpool:()=>d({spool:null,mode:`create`}),t:n}),u!==null&&(0,G.jsx)(E1e,{isOpen:!0,onClose:()=>d(null),spool:u.spool,mode:u.mode,currencySymbol:ht,spoolmanMode:e,spoolsQueryKey:Oe}),p&&(0,G.jsx)(of,{title:p.type===`delete`?n(`common.delete`):p.type===`archive`?n(`inventory.archive`):p.type===`reset-consumed-counter`?n(`inventory.resetConsumedCounter`):n(`inventory.resetAllConsumedCounters`),message:p.type===`delete`?n(`inventory.deleteConfirm`):p.type===`archive`?n(`inventory.archiveConfirm`):p.type===`reset-consumed-counter`?n(`inventory.resetConsumedCounterConfirm`):n(`inventory.resetAllConsumedCountersConfirm`,{count:at.length}),confirmText:p.type===`delete`?n(`common.delete`):p.type===`archive`?n(`inventory.archive`):n(`inventory.resetConsumedCounter`),variant:p.type===`archive`?`warning`:`danger`,onConfirm:()=>{p.type===`delete`?Ye.mutate(p.spoolId):p.type===`archive`?Xe.mutate(p.spoolId):p.type===`reset-consumed-counter`?Qe.mutate(p.spoolId):$e.mutate(at),m(null)},onCancel:()=>m(null)}),(0,G.jsx)(tG,{isOpen:ie,onClose:()=>ae(!1),columns:ne,defaultColumns:S9,onSave:Ft}),(0,G.jsx)(N1e,{isOpen:h!==null,onClose:()=>g(null),availableSpools:Tt,initialSelectedIds:h??[],spoolmanMode:e}),(0,G.jsx)(I1e,{isOpen:de,selectedCount:le.size,isPending:tt.isPending,availableLocations:Pe.map(e=>({id:e.id,name:e.name})),availableMaterials:x9((Ae??[]).map(e=>e.material)),availableSubtypes:x9((Ae??[]).map(e=>e.subtype)),availableBrands:x9((Ae??[]).map(e=>e.brand)),availableCategories:x9((Ae??[]).map(e=>e.category)),availableSlicerFilaments:x9((Ae??[]).map(e=>e.slicer_filament)),availableSlicerFilamentNames:x9((Ae??[]).map(e=>e.slicer_filament_name)),onClose:()=>fe(!1),onApply:e=>tt.mutate({ids:[...le],update:e})}),pe&&(0,G.jsx)(of,{title:n(pe===`delete`?`inventory.bulk.deleteTitle`:pe===`archive`?`inventory.bulk.archiveTitle`:pe===`restore`?`inventory.bulk.restoreTitle`:`inventory.bulk.resetUsageTitle`),message:n(pe===`delete`?`inventory.bulk.deleteMessage`:pe===`archive`?`inventory.bulk.archiveMessage`:pe===`restore`?`inventory.bulk.restoreMessage`:`inventory.bulk.resetUsageMessage`,{count:le.size}),confirmText:n(pe===`delete`?`common.delete`:pe===`archive`?`inventory.archive`:pe===`restore`?`inventory.restore`:`inventory.resetConsumedCounter`),variant:pe===`delete`?`danger`:`warning`,isLoading:nt.isPending||rt.isPending||it.isPending||$e.isPending,onConfirm:()=>{let e=[...le];pe===`delete`?nt.mutate(e):pe===`archive`?rt.mutate(e):pe===`restore`?it.mutate(e):$e.mutate(e)},onCancel:()=>me(null)}),_&&(0,G.jsx)(P1e,{onClose:()=>v(!1),onImported:e=>{v(!1),r.invalidateQueries({queryKey:Oe}),i(n(`inventory.csv.importSuccess`,`{{count}} spools imported`,{count:e}),`success`)}}),(0,G.jsx)(Z6,{open:S,onClose:()=>C(!1),onPickLocation:e=>Dt(String(e))})]})}function J1e({pageIndex:e,pageSize:t,totalRows:n,totalPages:r,onPageChange:i,onPageSizeChange:a,t:o}){let s=t===-1;if(r<=1&&!s)return null;let c=s?n||1:t;return(0,G.jsxs)(`div`,{className:`flex items-center justify-between pt-2 text-sm`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:s?`${n} ${o(n===1?`inventory.spool`:`inventory.spools`)}`:(0,G.jsxs)(G.Fragment,{children:[o(`inventory.showing`),` `,e*c+1,` `,o(`inventory.to`),` `,Math.min((e+1)*c,n),` `,o(`inventory.of`),` `,n,` `,o(`inventory.spools`)]})}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:o(`inventory.show`)}),(0,G.jsxs)(`select`,{value:t,onChange:e=>a(Number(e.target.value)),className:`px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:outline-none focus:border-bambu-green`,children:[[15,30,50,100].map(e=>(0,G.jsx)(`option`,{value:e,children:e},e)),(0,G.jsx)(`option`,{value:-1,children:o(`inventory.all`)})]}),!s&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`button`,{onClick:()=>i(0),disabled:e===0,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,children:(0,G.jsx)(_s,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:()=>i(Math.max(0,e-1)),disabled:e===0,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,children:(0,G.jsx)(hs,{className:`w-4 h-4`})}),(0,G.jsxs)(`span`,{className:`text-bambu-gray px-2 whitespace-nowrap`,children:[o(`inventory.page`),` `,e+1,` `,o(`inventory.of`),` `,r]}),(0,G.jsx)(`button`,{onClick:()=>i(Math.min(r-1,e+1)),disabled:e>=r-1,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,children:(0,G.jsx)(ms,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:()=>i(r-1),disabled:e>=r-1,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,children:(0,G.jsx)(vs,{className:`w-4 h-4`})})]})]})]})}function Y1e({spool:e,remaining:t,pct:n,onClick:r,onPrintLabel:i,onCopy:a,t:o,colorizeLocationSensors:s,locationSensorAboveColor:c,locationSensorBelowColor:l,locationSensorOptimalColor:u}){let d=bH({rgba:e.rgba,extraColors:e.extra_colors,effectType:e.effect_type,subtype:e.subtype,effectSize:`card`});return(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg overflow-hidden border border-bambu-dark-tertiary hover:border-bambu-green transition-colors cursor-pointer ${e.archived_at?`opacity-50`:``}`,onClick:r,children:[(0,G.jsxs)(`div`,{className:`h-14 flex items-center justify-center`,style:d,children:[(0,G.jsx)(`span`,{className:`bg-white/90 text-gray-800 px-3 py-0.5 rounded-full text-sm font-medium`,children:kf(e.color_name,e.rgba)||`-`}),a&&(0,G.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),a()},className:`p-1.5 bg-black/20 hover:bg-black/40 text-white rounded-full transition-colors`,title:o(`inventory.copySpool`),children:(0,G.jsx)(Vs,{className:`w-3.5 h-3.5`})})]}),(0,G.jsxs)(`div`,{className:`p-4 space-y-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`h3`,{className:`font-semibold text-white`,children:[e.material,e.subtype?` ${e.subtype}`:``]}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e.brand||`-`})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[i&&(0,G.jsx)(`button`,{onClick:e=>{e.stopPropagation(),i()},className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,title:o(`inventory.labels.printOne`),"aria-label":o(`inventory.labels.printOne`),children:(0,G.jsx)(Rl,{className:`w-4 h-4`})}),(0,G.jsxs)(`span`,{className:`text-xs font-mono text-bambu-gray bg-bambu-dark-tertiary px-2 py-1 rounded`,children:[`#`,e.id]})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex justify-between text-xs text-bambu-gray mb-1`,children:[(0,G.jsx)(`span`,{children:o(`inventory.remaining`)}),(0,G.jsxs)(`span`,{children:[Math.round(n),`%`]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`div`,{className:`flex-1 h-2 bg-bambu-dark-tertiary rounded-full overflow-hidden`,children:(0,G.jsx)(`div`,{className:`h-full rounded-full ${n>50?`bg-bambu-green`:n>20?`bg-yellow-500`:`bg-red-500`}`,style:{width:`${Math.min(n,100)}%`}})}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray min-w-[40px] text-right`,children:[Math.round(t),`g`]})]})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-2 text-xs`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`span`,{className:`text-bambu-gray/60`,children:[o(`inventory.labelWeight`),`: `]}),(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:C9(e.label_weight)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`span`,{className:`text-bambu-gray/60`,children:[o(`inventory.weightUsed`),`: `]}),(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:e.weight_used>0?C9(e.weight_used):`-`})]})]}),e.location_id&&(0,G.jsx)(Q1e,{locationId:e.location_id,locationName:e.storage_location??null,isLast:!e.note,colorize:s,aboveColor:c,belowColor:l,optimalColor:u}),e.note&&(0,G.jsx)(`div`,{className:`text-xs text-bambu-gray/60 pt-3 border-t border-bambu-dark-tertiary truncate`,title:e.note,children:e.note})]})]})}var X1e={temperature:0,humidity:1,battery:2};function Z1e(e){return e===`humidity`?`mr-[2px]`:e===`battery`?`mr-[3px]`:``}function O9(e,t){return PT(e,t,{decimals:2})}function k9(e,t,n,r,i){return t&&B6(z6(e),n,r,i)||`text-bambu-gray`}function Q1e({locationId:e,locationName:t,isLast:n,colorize:r,aboveColor:i,belowColor:a,optimalColor:o}){let{t:s}=U(),{data:c}=K({queryKey:[`settings`],queryFn:Z.getSettings}),l=(c?.location_sensor_poll_interval||120)*1e3,{data:u}=K({queryKey:[`locationHaSensors`],queryFn:()=>Z.getLocationHASensors()}),d=(u??[]).some(t=>t.location_id===e),{data:f}=K({queryKey:[`locationHaSensorReadings`,e],queryFn:()=>Z.getLocationHASensorReadings(e,!1),refetchInterval:l,enabled:d}),p=f?.filter(e=>e.show_on_card);if(!p?.length)return null;let m=p.find(e=>e.device_class===`battery`),h=p.filter(e=>e.device_class!==`battery`).sort((e,t)=>(X1e[e.device_class??``]??99)-(X1e[t.device_class??``]??99));return(0,G.jsxs)(`div`,{className:`flex items-center gap-2 pt-3 border-t border-bambu-dark-tertiary text-xs text-bambu-gray ${n?`-mb-1`:``}`,children:[t&&(0,G.jsx)(`span`,{className:`truncate`,children:t}),(0,G.jsx)(`span`,{className:`text-bambu-gray/40`,children:`|`}),(0,G.jsx)(`div`,{className:`flex items-center gap-3`,children:h.map((e,t)=>{let n=FT(e),c=t===0?`ml-[-3.6px]`:``;return(0,G.jsxs)(`span`,{title:e.name,className:`flex items-center gap-[3px]`,children:[(0,G.jsx)(n,{className:`w-3 h-3 ${Z1e(e.device_class)} ${c}`}),(0,G.jsx)(`span`,{className:k9(e,r,i,a,o),children:O9(e,s)})]},e.id)})}),m&&(()=>{let e=FT(m);return(0,G.jsxs)(`span`,{title:m.name,className:`flex items-center gap-[3px] ml-auto`,children:[(0,G.jsx)(e,{className:`w-3 h-3 ${Z1e(m.device_class)}`}),(0,G.jsx)(`span`,{className:k9(m,r,i,a,o),children:O9(m,s)})]},m.id)})()]})}function $1e({spool:e,remaining:t,pct:n,isSelected:r,onToggleSelected:i,onEdit:a,onCopy:o,onRestore:s,onArchive:c,onDelete:l,onPrintLabel:u,onResetConsumedCounter:d,visibleColumns:f,assignmentMap:p,catalogMap:m,locationReadingsMap:h,currencySymbol:g,dateFormat:_,t:v,onSyncWeight:y,colorizeLocationSensors:b,locationSensorAboveColor:x,locationSensorBelowColor:S,locationSensorOptimalColor:C}){return(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/50 hover:bg-bambu-dark-tertiary/30 transition-colors cursor-pointer ${e.archived_at?`opacity-50`:``} ${r?`bg-bambu-green/10`:``}`,onClick:a,children:[(0,G.jsx)(`td`,{className:`w-10 px-3 py-3`,onClick:e=>e.stopPropagation(),children:i&&(0,G.jsx)(`input`,{type:`checkbox`,className:`h-4 w-4 cursor-pointer`,"aria-label":v(`inventory.bulk.selectRow`),checked:!!r,onChange:i})}),f.map(r=>(0,G.jsx)(`td`,{className:`py-3 px-4`,children:T9[r]?.({spool:e,remaining:t,pct:n,assignmentMap:p,catalogMap:m,locationReadingsMap:h,currencySymbol:g,dateFormat:_,t:v,onSyncWeight:y,colorizeLocationSensors:b,locationSensorAboveColor:x,locationSensorBelowColor:S,locationSensorOptimalColor:C})},r)),(0,G.jsx)(`td`,{className:`py-3 px-4`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-end gap-1`,onClick:e=>e.stopPropagation(),children:[(0,G.jsx)(`button`,{onClick:a,className:`p-1.5 text-bambu-gray hover:text-white rounded transition-colors`,title:v(`common.edit`),children:(0,G.jsx)(kl,{className:`w-4 h-4`})}),o&&(0,G.jsx)(`button`,{onClick:o,className:`p-1.5 text-bambu-gray hover:text-bambu-green rounded transition-colors`,title:v(`inventory.copySpool`),children:(0,G.jsx)(Vs,{className:`w-4 h-4`})}),u&&(0,G.jsx)(`button`,{onClick:u,className:`p-1.5 text-bambu-gray hover:text-white rounded transition-colors`,title:v(`inventory.labels.printOne`),children:(0,G.jsx)(Rl,{className:`w-4 h-4`})}),d&&e.weight_used>0&&(0,G.jsx)(`button`,{onClick:d,className:`p-1.5 text-bambu-gray hover:text-orange-600 dark:hover:text-orange-400 rounded transition-colors`,title:v(`inventory.resetConsumedCounterTooltip`),children:(0,G.jsx)(nc,{className:`w-4 h-4`})}),e.archived_at?(0,G.jsx)(`button`,{onClick:s,className:`p-1.5 text-bambu-gray hover:text-bambu-green rounded transition-colors`,title:v(`inventory.restore`),children:(0,G.jsx)(Wl,{className:`w-4 h-4`})}):(0,G.jsx)(`button`,{onClick:c,className:`p-1.5 text-bambu-gray hover:text-yellow-600 dark:hover:text-yellow-400 rounded transition-colors`,title:v(`inventory.archive`),children:(0,G.jsx)(Po,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:l,className:`p-1.5 text-bambu-gray hover:text-red-600 dark:hover:text-red-400 rounded transition-colors`,title:v(`common.delete`),children:(0,G.jsx)(Pu,{className:`w-4 h-4`})})]})})]})}function e0e({spools:e,headerSpool:t,remaining:n,pct:r,isExpanded:i,onToggle:a,onEdit:o,onCopy:s,onArchive:c,onDelete:l,onPrintLabel:u,onResetConsumedCounter:d,visibleColumns:f,assignmentMap:p,catalogMap:m,locationReadingsMap:h,currencySymbol:g,dateFormat:_,t:v,onSyncWeight:y,colorizeLocationSensors:b,locationSensorAboveColor:x,locationSensorBelowColor:S,locationSensorOptimalColor:C,selectedIds:w,onToggleSelected:T,onToggleGroupSelected:E}){let D=!!w&&e.every(e=>w.has(e.id));return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/50 hover:bg-bambu-dark-tertiary/30 transition-colors cursor-pointer bg-bambu-green/5`,onClick:a,children:[(0,G.jsx)(`td`,{className:`w-10 px-3 py-3`,onClick:e=>e.stopPropagation(),children:E&&(0,G.jsx)(`input`,{type:`checkbox`,className:`h-4 w-4 cursor-pointer`,"aria-label":v(`inventory.bulk.selectGroup`),checked:D,onChange:t=>E(e.map(e=>e.id),t.target.checked)})}),f.map((a,o)=>(0,G.jsx)(`td`,{className:`py-3 px-4`,children:o===0?(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(ps,{className:`w-4 h-4 text-bambu-gray transition-transform ${i?``:`-rotate-90`}`}),T9[a]?.({spool:t,remaining:n,pct:r,assignmentMap:p,catalogMap:m,locationReadingsMap:h,currencySymbol:g,dateFormat:_,t:v,onSyncWeight:y,colorizeLocationSensors:b,locationSensorAboveColor:x,locationSensorBelowColor:S,locationSensorOptimalColor:C})]}):a===`id`?(0,G.jsx)(`span`,{className:`text-xs font-medium bg-bambu-green/20 text-bambu-green px-2 py-0.5 rounded-full`,children:v(`inventory.groupedSpools`,{count:e.length})}):T9[a]?.({spool:t,remaining:n,pct:r,assignmentMap:p,catalogMap:m,locationReadingsMap:h,currencySymbol:g,dateFormat:_,t:v,onSyncWeight:y,colorizeLocationSensors:b,locationSensorAboveColor:x,locationSensorBelowColor:S,locationSensorOptimalColor:C})},a)),(0,G.jsx)(`td`,{className:`py-3 px-4`,children:(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:e.map(e=>`#${e.id}`).join(`, `)})})]}),i&&e.map(e=>{let t=Math.max(0,e.label_weight-e.weight_used);return(0,G.jsx)($1e,{spool:e,remaining:t,pct:e.label_weight>0?t/e.label_weight*100:0,isSelected:w?.has(e.id),onToggleSelected:T?()=>T(e.id):void 0,onEdit:()=>o(e),onCopy:s?()=>s(e):void 0,onRestore:()=>{},onArchive:()=>c(e.id),onDelete:()=>l(e.id),onPrintLabel:u?()=>u(e.id):void 0,onResetConsumedCounter:d?()=>d(e.id):void 0,visibleColumns:f,assignmentMap:p,catalogMap:m,locationReadingsMap:h,currencySymbol:g,dateFormat:_,t:v,onSyncWeight:y,colorizeLocationSensors:b,locationSensorAboveColor:x,locationSensorBelowColor:S,locationSensorOptimalColor:C},e.id)})]})}function t0e({hasFilters:e,onAddSpool:t,t:n}){return(0,G.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-16 px-4`,children:[(0,G.jsxs)(`div`,{className:`relative mb-6`,children:[(0,G.jsx)(`div`,{className:`absolute inset-0 -m-4 bg-bambu-green/5 rounded-full blur-2xl`}),(0,G.jsxs)(`div`,{className:`relative flex items-center justify-center w-24 h-24 rounded-2xl bg-gradient-to-br from-bambu-dark-secondary to-bambu-dark-tertiary border border-bambu-dark-tertiary shadow-lg`,children:[(0,G.jsx)(`div`,{className:`absolute -top-1 -right-1 w-3 h-3 rounded-full bg-bambu-green/30`}),(0,G.jsx)(`div`,{className:`absolute -bottom-2 -left-2 w-2 h-2 rounded-full bg-bambu-green/20`}),e?(0,G.jsx)(Ql,{className:`w-10 h-10 text-bambu-gray/40`,strokeWidth:1.5}):(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(`div`,{className:`w-14 h-14 rounded-full border-4 border-bambu-gray/20 flex items-center justify-center`,children:(0,G.jsx)(`div`,{className:`w-6 h-6 rounded-full bg-bambu-gray/10 border-2 border-bambu-gray/20`})}),(0,G.jsx)(`div`,{className:`absolute -bottom-1 -right-1 w-6 h-6 rounded-full bg-bambu-green flex items-center justify-center shadow-md`,children:(0,G.jsx)(`span`,{className:`text-white text-lg font-bold leading-none`,children:`+`})})]})]})]}),(0,G.jsx)(`h3`,{className:`text-lg font-semibold text-white mb-2 text-center`,children:e?n(`inventory.noSpoolsMatch`):n(`inventory.noSpools`).split(`.`)[0]}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray text-center max-w-sm mb-6`,children:n(e?`inventory.noSpoolsMatchDesc`:`inventory.noSpools`)}),!e&&(0,G.jsxs)(Q,{onClick:t,children:[(0,G.jsx)(Cl,{className:`w-4 h-4`}),n(`inventory.addSpool`)]})]})}function A9(e,t){let n=e?.[t];return typeof n==`string`?n:``}function n0e(e){return e.replace(/(https?:\/\/(?:makerworld|public-cdn)\.bblmw\.com\/[^\s"']+)/gi,e=>`/api/v1/makerworld/thumbnail?url=${encodeURIComponent(e)}`)}function j9(e){return e?/^https?:\/\/(makerworld|public-cdn)\.bblmw\.com\//i.test(e)?`/api/v1/makerworld/thumbnail?url=${encodeURIComponent(e)}`:e:``}function M9(e,t){let n=e?.[t];return typeof n==`number`?n:null}function r0e(e,t){let n=e?.[t];return n&&typeof n==`object`&&!Array.isArray(n)?n:void 0}function i0e(e,t=0,n=[]){n.push({folder:e,depth:t});for(let r of e.children??[])i0e(r,t+1,n);return n}function a0e(e,t){return t(e<1?`makerworld.phaseResolving`:`makerworld.phaseDownloading`)}function o0e(e){let[t,n]=(0,y.useState)(0);return(0,y.useEffect)(()=>{if(!e){n(0);return}let t=Date.now(),r=()=>n(Math.floor((Date.now()-t)/1e3));r();let i=window.setInterval(r,1e3);return()=>window.clearInterval(i)},[e]),t}function s0e(){let{t:e}=U(),{hasPermission:t}=Nd(),{showToast:n}=qd(),r=co(),i=t(`makerworld:import`),[a,o]=(0,y.useState)(``),[s,c]=(0,y.useState)(null),[l,u]=(0,y.useState)(null),[d,f]=(0,y.useState)(null),[p,m]=(0,y.useState)(null),[h,g]=(0,y.useState)(null),[_,v]=(0,y.useState)(``),[b,x]=(0,y.useState)({}),S=K({queryKey:[`makerworld-status`],queryFn:()=>Z.getMakerworldStatus()}),C=K({queryKey:[`library-folders`],queryFn:()=>Z.getLibraryFolders()}),w=K({queryKey:[`makerworld-recent-imports`],queryFn:()=>Z.getMakerworldRecentImports(10)}),T=K({queryKey:[`settings`],queryFn:()=>Z.getSettings()}),E=T.data?.use_slicer_api??!1,D=T.data?.preferred_slicer||`bambu_studio`,O=HW(T.data?.open_in_slicer,T.data?.preferred_slicer),k=E?D:O,A=k===`orcaslicer`?`OrcaSlicer`:`Bambu Studio`,[j,M]=(0,y.useState)(null),N=(e,t)=>{M({kind:`libraryFile`,id:e,filename:t})},P=q({mutationFn:e=>Z.resolveMakerworldUrl(e),onSuccess:(e,t)=>{c(e),v(t),x({})},onError:t=>n(t.message||e(`makerworld.errors.resolveFailed`),`error`)});(0,y.useEffect)(()=>{s!==null&&a.trim()!==_.trim()&&(c(null),v(``),x({}))},[a,s,_]);let F=q({mutationFn:({instanceId:e,profileId:t})=>Z.importMakerworldInstance(s?.model_id??0,e,t,l),onSuccess:t=>{r.invalidateQueries({queryKey:[`library-files`]}),r.invalidateQueries({queryKey:[`library-folders`]}),t.profile_id&&x(e=>({...e,[t.profile_id]:t})),n(t.was_existing?e(`makerworld.alreadyInLibrary`):e(`makerworld.importSuccess`,{filename:t.filename}),`success`)},onError:t=>n(t.message||e(`makerworld.errors.downloadFailed`),`error`)}),I=q({mutationFn:({libraryFileId:e})=>Z.deleteLibraryFile(e),onSuccess:(t,{profileId:i})=>{r.invalidateQueries({queryKey:[`library-files`]}),r.invalidateQueries({queryKey:[`library-folders`]}),r.invalidateQueries({queryKey:[`makerworld-recent-imports`]}),x(e=>{let t={...e};return delete t[i],t}),m(null),n(e(`makerworld.importDeleted`),`success`)},onError:t=>{m(null),n(t.message||e(`makerworld.errors.deleteFailed`),`error`)}}),L=q({mutationFn:({instanceId:e,profileId:t})=>Z.importMakerworldInstance(s?.model_id??0,e,t,l),onSuccess:async e=>{r.invalidateQueries({queryKey:[`library-files`]}),r.invalidateQueries({queryKey:[`library-folders`]}),r.invalidateQueries({queryKey:[`makerworld-recent-imports`]}),e.profile_id&&x(t=>({...t,[e.profile_id]:e})),E?N(e.library_file_id,e.filename):await te(e.library_file_id,e.filename,k)},onError:t=>n(t.message||e(`makerworld.errors.downloadFailed`),`error`)}),R=o0e(F.isPending||L.isPending),z=a0e(R,e),B=e=>{e?.preventDefault();let t=a.trim();t&&P.mutate(t)};(0,y.useEffect)(()=>{if(!h)return;let e=e=>{e.key===`Escape`?g(null):e.key===`ArrowLeft`?g(e=>e&&e.index>0?{...e,index:e.index-1}:e):e.key===`ArrowRight`&&g(e=>e&&e.indexwindow.removeEventListener(`keydown`,e)},[h]);let V=e=>{let t=(Array.isArray(e.pictures)?e.pictures:[]).filter(e=>typeof e==`object`&&!!e).map(e=>({name:A9(e,`name`)||`image`,url:A9(e,`url`)})).filter(e=>e.url);if(t.length>0)return t;let n=A9(e,`cover`);return n?[{name:`cover`,url:n}]:[]},ee=async()=>{if(!s)return;let e=s.instances.filter(e=>{let t=M9(e,`profileId`);return t!==null&&!b[t]});if(e.length!==0){f({current:0,total:e.length});try{for(let t=0;t{try{let{token:r}=await Z.createLibrarySlicerToken(e),i=Z.getLibrarySlicerDownloadUrl(e,r,t);KW(`${window.location.origin}${i}`,n)}catch{let t=Z.getLibraryFileDownloadUrl(e);KW(`${window.location.origin}${t}`,n)}},ne=s?.design,re=r0e(ne,`designCreator`),ie=s?.instances??[],ae=(s?.already_imported_library_ids.length??0)>0,oe=S.data?.can_download??!1,se=S.data?.sign_in_expired??!1,H=(0,y.useMemo)(()=>A9(ne,`coverUrl`),[ne]),ce=A9(ne,`title`),le=A9(ne,`summary`),ue=A9(ne,`license`),de=M9(ne,`downloadCount`);return(0,G.jsxs)(`div`,{className:`p-4 md:p-8 max-w-screen-2xl space-y-6`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,G.jsx)(Ac,{className:`w-7 h-7 text-bambu-green`}),e(`makerworld.title`)]}),(0,G.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:e(`makerworld.description`)})]}),(0,G.jsxs)(`div`,{className:`grid gap-6 lg:grid-cols-[1fr_20rem]`,children:[(0,G.jsxs)(`div`,{className:`space-y-6 min-w-0`,children:[!oe&&(0,G.jsx)(zd,{className:`border-amber-300 dark:border-amber-700 bg-amber-50 dark:bg-amber-900/20`,children:(0,G.jsx)(Vd,{children:(0,G.jsxs)(`div`,{className:`flex items-start gap-3 py-2`,children:[(0,G.jsx)(ys,{className:`w-5 h-5 text-amber-600 dark:text-amber-400 mt-0.5 shrink-0`}),(0,G.jsxs)(`div`,{className:`text-sm`,children:[(0,G.jsx)(`p`,{className:`font-medium text-amber-900 dark:text-amber-100`,children:e(se?`makerworld.signInExpiredTitle`:`makerworld.signInRequiredTitle`)}),(0,G.jsxs)(`p`,{className:`text-amber-800 dark:text-amber-200 mt-1`,children:[e(se?`makerworld.signInExpiredBody`:`makerworld.signInRequiredBody`),` `,(0,G.jsx)(Ai,{to:`/profiles`,className:`underline`,children:e(`makerworld.openCloudSettings`)})]})]})]})})}),(0,G.jsxs)(zd,{children:[(0,G.jsx)(Bd,{children:(0,G.jsx)(`h2`,{className:`text-lg font-semibold`,children:e(`makerworld.pasteUrlHeader`)})}),(0,G.jsx)(Vd,{children:(0,G.jsxs)(`form`,{onSubmit:B,className:`flex gap-2`,children:[(0,G.jsx)(`input`,{type:`text`,value:a,onChange:e=>o(e.target.value),placeholder:e(`makerworld.pasteUrlPlaceholder`),className:`flex-1 min-w-0 px-3 py-2 border rounded bg-white dark:bg-gray-800 border-gray-300 dark:border-gray-700`,autoComplete:`off`}),(0,G.jsxs)(Q,{type:`submit`,variant:`primary`,disabled:!a.trim()||P.isPending,children:[P.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(zo,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`ml-2`,children:e(`makerworld.resolveButton`)})]})]})})]}),s&&(0,G.jsx)(zd,{children:(0,G.jsx)(Vd,{children:(0,G.jsxs)(`div`,{className:`flex gap-4 py-2`,children:[H&&(0,G.jsx)(`img`,{src:j9(H),alt:ce,className:`w-32 h-32 object-cover rounded`,loading:`lazy`}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`h3`,{className:`text-xl font-semibold truncate`,children:ce||e(`makerworld.untitledModel`)}),re&&(0,G.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400 mt-1`,children:e(`makerworld.byCreator`,{name:A9(re,`name`)})}),(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-3 mt-2 text-xs text-gray-500 dark:text-gray-400`,children:[de!==null&&(0,G.jsx)(`span`,{children:e(`makerworld.downloadsCount`,{count:de})}),ue&&(0,G.jsxs)(`span`,{children:[e(`makerworld.licensePrefix`),`: `,ue]}),ae&&(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-emerald-600 dark:text-emerald-400`,children:[(0,G.jsx)(fs,{className:`w-3 h-3`}),` `,e(`makerworld.alreadyImported`)]})]}),le&&(0,G.jsx)(`div`,{className:`mt-3 text-sm prose prose-sm max-w-none dark:prose-invert line-clamp-3`,dangerouslySetInnerHTML:{__html:JG.sanitize(n0e(le))}}),s&&(0,G.jsxs)(`a`,{href:`https://makerworld.com/models/${s.model_id}${s.profile_id?`#profileId-${s.profile_id}`:``}`,target:`_blank`,rel:`noopener noreferrer`,className:`mt-3 inline-flex items-center gap-1 text-xs text-brand-500 hover:underline`,children:[(0,G.jsx)(rc,{className:`w-3 h-3`}),` `,e(`makerworld.openOnMakerworld`)]})]})]})})}),s&&ie.length>0&&(0,G.jsxs)(zd,{children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,G.jsx)(`h2`,{className:`text-lg font-semibold`,children:e(`makerworld.platesHeader`,{count:ie.length})}),(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,G.jsx)(`label`,{className:`text-xs text-gray-600 dark:text-gray-400`,children:e(`makerworld.importTo`)}),(0,G.jsxs)(`select`,{value:l??``,onChange:e=>u(e.target.value?Number(e.target.value):null),className:`text-sm px-2 py-1 border rounded bg-white dark:bg-gray-800 border-gray-300 dark:border-gray-700`,disabled:d!==null,children:[(0,G.jsx)(`option`,{value:``,children:e(`makerworld.folderAuto`)}),(C.data??[]).filter(e=>!(e.is_external&&e.external_readonly)).flatMap(e=>i0e(e)).map(({folder:e,depth:t})=>(0,G.jsx)(`option`,{value:e.id,children:`${`— `.repeat(t)}${e.name}`},e.id))]}),(0,G.jsx)(Q,{variant:`primary`,size:`sm`,disabled:!i||!oe||d!==null||F.isPending||L.isPending,onClick:ee,children:d===null?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Xs,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`ml-2`,children:e(`makerworld.importAll`)})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),(0,G.jsxs)(`span`,{className:`ml-2`,children:[e(`makerworld.importAllProgress`,{current:d.current,total:d.total}),R>0&&` · ${z} · ${R}s`]})]})})]})]})}),(0,G.jsx)(Vd,{children:(0,G.jsx)(`div`,{className:`grid gap-3`,children:ie.map((t,n)=>{let r=M9(t,`id`),a=M9(t,`profileId`),o=A9(t,`title`),s=A9(t,`cover`),c=M9(t,`materialCnt`),l=t?.needAms===!0,u=M9(t,`downloadCount`),f=t?.compatibility??null,p=t?.otherCompatibility??null,h=f?.devProductName??null,_=Array.isArray(p)?p.map(e=>e?.devProductName??``).filter(Boolean):[];if(r==null)return null;let v=F.isPending&&F.variables?.instanceId===r,y=L.isPending&&L.variables?.instanceId===r,x=a===null?void 0:b[a];return(0,G.jsxs)(`div`,{className:`flex flex-col gap-2 p-3 border rounded border-gray-200 dark:border-gray-700`,children:[(0,G.jsxs)(`div`,{className:`flex gap-3 items-center`,children:[(()=>{let n=V(t),r=n.length>0;return(0,G.jsxs)(`button`,{type:`button`,disabled:!r,onClick:()=>r&&g({images:n,index:0}),className:`relative w-16 h-16 shrink-0 rounded overflow-hidden group`,"aria-label":e(`makerworld.openGallery`),children:[s?(0,G.jsx)(`img`,{src:j9(s),alt:``,className:`w-16 h-16 object-cover`,loading:`lazy`}):(0,G.jsx)(`div`,{className:`w-16 h-16 bg-gray-100 dark:bg-gray-800`}),n.length>1&&(0,G.jsxs)(`span`,{className:`absolute bottom-0.5 right-0.5 bg-black/70 text-white text-[10px] px-1.5 py-0.5 rounded flex items-center gap-1`,children:[(0,G.jsx)(Uc,{className:`w-2.5 h-2.5`}),n.length]})]})})(),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`p`,{className:`font-medium truncate`,children:o||e(`makerworld.plateDefaultName`,{n:n+1})}),(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-3 text-xs text-gray-500 dark:text-gray-400 mt-1`,children:[h&&(0,G.jsx)(`span`,{className:`font-medium text-gray-700 dark:text-gray-300`,children:e(`makerworld.slicedFor`,{printer:h,defaultValue:`Sliced for {{printer}}`})}),c!==null&&(0,G.jsx)(`span`,{children:e(`makerworld.materialCount`,{count:c})}),l&&(0,G.jsx)(`span`,{children:e(`makerworld.amsRequired`)}),u!==null&&(0,G.jsx)(`span`,{children:e(`makerworld.downloadsCount`,{count:u})})]}),_.length>0&&(0,G.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mt-1`,title:_.join(`, `),children:e(`makerworld.alsoCompatible`,{printers:_.slice(0,6).join(`, `)+(_.length>6?`…`:``),defaultValue:`Also marked compatible: {{printers}}`})})]}),(0,G.jsxs)(`div`,{className:`flex gap-2 shrink-0`,children:[(0,G.jsx)(Q,{variant:`ghost`,size:`sm`,disabled:!i||!oe||v||y||d!==null,onClick:()=>F.mutate({instanceId:r,profileId:a}),title:oe?void 0:e(`makerworld.signInRequiredTitle`),children:v?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),(0,G.jsxs)(`span`,{className:`ml-2`,children:[z,R>0&&` · ${R}s`]})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Xs,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`ml-2`,children:e(`makerworld.importToLibrary`)})]})}),(0,G.jsx)(Q,{variant:`primary`,size:`sm`,disabled:!i||!oe||v||y||d!==null,onClick:()=>L.mutate({instanceId:r,profileId:a}),title:oe?void 0:e(`makerworld.signInRequiredTitle`),children:y?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),(0,G.jsxs)(`span`,{className:`ml-2`,children:[z,R>0&&` · ${R}s`]})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(rc,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`ml-2`,children:e(`makerworld.sliceIn`,{slicer:A})})]})})]})]}),x&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2 pl-20 text-xs`,children:[(0,G.jsx)(fs,{className:`w-3.5 h-3.5 text-emerald-600 dark:text-emerald-400 shrink-0`}),(0,G.jsx)(`span`,{className:`text-emerald-700 dark:text-emerald-300`,children:x.was_existing?e(`makerworld.lastImportAlreadyInLibrary`):e(`makerworld.lastImportSuccess`)}),(0,G.jsxs)(Q,{variant:`ghost`,size:`sm`,onClick:()=>{let e=x.folder_id?`/files?folder=${x.folder_id}`:`/files`;window.location.assign(e)},children:[(0,G.jsx)(vc,{className:`w-3.5 h-3.5`}),(0,G.jsx)(`span`,{className:`ml-1.5`,children:e(`makerworld.viewInLibrary`)})]}),E?(0,G.jsxs)(Q,{variant:`ghost`,size:`sm`,onClick:()=>N(x.library_file_id,x.filename),children:[(0,G.jsx)(Rs,{className:`w-3.5 h-3.5`}),(0,G.jsx)(`span`,{className:`ml-1.5`,children:e(`slice.action`,`Slice`)})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(Q,{variant:`ghost`,size:`sm`,onClick:()=>te(x.library_file_id,x.filename,`bambu_studio`),children:[(0,G.jsx)(rc,{className:`w-3.5 h-3.5`}),(0,G.jsx)(`span`,{className:`ml-1.5`,children:e(`makerworld.openInBambuStudio`)})]}),(0,G.jsxs)(Q,{variant:`ghost`,size:`sm`,onClick:()=>te(x.library_file_id,x.filename,`orcaslicer`),children:[(0,G.jsx)(rc,{className:`w-3.5 h-3.5`}),(0,G.jsx)(`span`,{className:`ml-1.5`,children:e(`makerworld.openInOrcaSlicer`)})]})]}),(0,G.jsx)(`div`,{className:`ml-auto`,children:(0,G.jsx)(Q,{variant:`ghost`,size:`sm`,disabled:I.isPending&&I.variables?.profileId===a,onClick:()=>{a!==null&&m({libraryFileId:x.library_file_id,profileId:a,filename:x.filename})},title:e(`makerworld.deleteImport`),children:I.isPending&&I.variables?.profileId===a?(0,G.jsx)(Y,{className:`w-3.5 h-3.5 animate-spin`}):(0,G.jsx)(Pu,{className:`w-3.5 h-3.5 text-red-500`})})})]})]},r)})})})]})]}),(0,G.jsx)(`aside`,{className:`lg:sticky lg:top-6 lg:self-start min-w-0`,children:w.data&&w.data.length>0&&(0,G.jsxs)(zd,{children:[(0,G.jsx)(Bd,{children:(0,G.jsx)(`h2`,{className:`text-base font-semibold`,children:e(`makerworld.recentImportsHeader`)})}),(0,G.jsx)(Vd,{children:(0,G.jsx)(`div`,{className:`flex flex-col gap-2 max-h-[28rem] overflow-y-auto -mx-2 px-2`,children:w.data.map(t=>(0,G.jsxs)(`div`,{className:`flex gap-2 p-2 border rounded border-gray-200 dark:border-gray-700`,children:[t.thumbnail_path?(0,G.jsx)(`img`,{src:Z.getLibraryFileThumbnailUrl(t.library_file_id),alt:``,className:`w-12 h-12 shrink-0 object-cover rounded bg-gray-100 dark:bg-gray-800`,loading:`lazy`}):(0,G.jsx)(`div`,{className:`w-12 h-12 shrink-0 rounded bg-gray-100 dark:bg-gray-800`}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0 flex flex-col gap-1`,children:[(0,G.jsx)(`p`,{className:`text-xs font-medium truncate`,title:t.filename,children:t.filename}),(0,G.jsxs)(`div`,{className:`flex gap-0.5`,children:[(0,G.jsx)(Q,{variant:`ghost`,size:`sm`,onClick:()=>{let e=t.folder_id?`/files?folder=${t.folder_id}`:`/files`;window.location.assign(e)},title:e(`makerworld.viewInLibrary`),children:(0,G.jsx)(vc,{className:`w-3.5 h-3.5`})}),E?(0,G.jsx)(Q,{variant:`ghost`,size:`sm`,onClick:()=>N(t.library_file_id,t.filename),title:e(`slice.action`,`Slice`),children:(0,G.jsx)(Rs,{className:`w-3.5 h-3.5`})}):(0,G.jsx)(Q,{variant:`ghost`,size:`sm`,onClick:()=>te(t.library_file_id,t.filename,`bambu_studio`),title:e(`makerworld.openInBambuStudio`),children:(0,G.jsx)(rc,{className:`w-3.5 h-3.5`})}),t.source_url&&(0,G.jsx)(`a`,{href:t.source_url,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center justify-center h-7 w-7 rounded text-gray-500 hover:text-gray-700 dark:hover:text-gray-300`,title:e(`makerworld.openOnMakerworld`),children:(0,G.jsx)(Ac,{className:`w-3.5 h-3.5`})})]})]})]},t.library_file_id))})})]})})]}),(0,G.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 pt-4 border-t border-gray-200 dark:border-gray-700`,children:e(`makerworld.disclaimer`)}),p&&(0,G.jsx)(of,{title:e(`makerworld.deleteImport`),message:e(`makerworld.confirmDelete`,{filename:p.filename}),confirmText:e(`makerworld.deleteImport`),variant:`danger`,isLoading:I.isPending,loadingText:e(`makerworld.importDeleting`),onCancel:()=>m(null),onConfirm:()=>I.mutate({libraryFileId:p.libraryFileId,profileId:p.profileId})}),j&&(0,G.jsx)(RW,{source:j,onClose:()=>M(null)}),h&&(0,G.jsxs)(`div`,{className:`fixed inset-0 bg-black/90 flex items-center justify-center z-50`,onClick:()=>g(null),role:`dialog`,"aria-modal":`true`,children:[(0,G.jsx)(`button`,{type:`button`,className:`absolute top-4 right-4 p-2 bg-white/10 hover:bg-white/20 rounded-full text-white`,onClick:e=>{e.stopPropagation(),g(null)},"aria-label":e(`common.close`,`Close`),children:(0,G.jsx)(nd,{className:`w-5 h-5`})}),h.images.length>1&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`button`,{type:`button`,className:`absolute left-4 p-2 bg-white/10 hover:bg-white/20 rounded-full text-white disabled:opacity-30`,disabled:h.index===0,onClick:e=>{e.stopPropagation(),g(e=>e&&{...e,index:Math.max(0,e.index-1)})},"aria-label":e(`makerworld.galleryPrev`),children:(0,G.jsx)(hs,{className:`w-6 h-6`})}),(0,G.jsx)(`button`,{type:`button`,className:`absolute right-4 p-2 bg-white/10 hover:bg-white/20 rounded-full text-white disabled:opacity-30`,disabled:h.index>=h.images.length-1,onClick:e=>{e.stopPropagation(),g(e=>e&&{...e,index:Math.min(e.images.length-1,e.index+1)})},"aria-label":e(`makerworld.galleryNext`),children:(0,G.jsx)(ms,{className:`w-6 h-6`})})]}),(0,G.jsx)(`img`,{src:j9(h.images[h.index].url),alt:h.images[h.index].name,className:`max-w-[90vw] max-h-[90vh] object-contain`,onClick:e=>e.stopPropagation()}),h.images.length>1&&(0,G.jsxs)(`div`,{className:`absolute bottom-6 left-1/2 -translate-x-1/2 text-white bg-black/60 px-3 py-1 rounded text-xs`,children:[h.index+1,` / `,h.images.length]})]})]})}var c0e=[`DEBUG`,`INFO`,`WARNING`,`ERROR`],N9={DEBUG:`text-gray-400`,INFO:`text-blue-400`,WARNING:`text-yellow-400`,ERROR:`text-red-400`},l0e={DEBUG:$o,INFO:Wc,WARNING:Lu,ERROR:ys};function u0e(){let e=co(),[t,n]=(0,y.useState)(!0),[r,i]=(0,y.useState)(new Set),[a,o]=(0,y.useState)(``),[s,c]=(0,y.useState)(`ALL`),[l,u]=(0,y.useState)(!1),[d,f]=(0,y.useState)(!1),p=(0,y.useRef)(null),{data:m,isLoading:h,refetch:g}=K({queryKey:[`application-logs`,s,a],queryFn:()=>Dd.getLogs({limit:200,level:s===`ALL`?void 0:s,search:a||void 0}),refetchInterval:d?2e3:!1,enabled:l});(0,y.useEffect)(()=>{l||f(!1)},[l]);let _=q({mutationFn:()=>Dd.clearLogs(),onSuccess:()=>{e.invalidateQueries({queryKey:[`application-logs`]})}});(0,y.useEffect)(()=>{t&&p.current&&m?.entries&&(p.current.scrollTop=p.current.scrollHeight)},[m?.entries,t]);let v=e=>{i(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},b=e=>{let t=e.split(` `);return t.length>=2?t[1]:e},x=(0,y.useMemo)(()=>m?.entries??[],[m?.entries]),S=(0,y.useMemo)(()=>[...x].reverse(),[x]),C=({level:e})=>(0,G.jsx)(l0e[e]||Wc,{className:`w-3.5 h-3.5 ${N9[e]||`text-gray-400`}`});return(0,G.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg overflow-hidden`,children:[(0,G.jsxs)(`button`,{onClick:()=>u(!l),className:`w-full flex items-center justify-between p-4 hover:bg-bambu-dark-tertiary/50 transition-colors`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`p-2 rounded-lg ${d?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark-tertiary text-bambu-gray`}`,children:(0,G.jsx)($o,{className:`w-5 h-5`})}),(0,G.jsxs)(`div`,{className:`text-left`,children:[(0,G.jsx)(`p`,{className:`font-medium text-white`,children:`Application Logs`}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:d?`Live streaming - ${m?.filtered_count??0} entries`:`View and filter application logs`})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[d&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1.5 px-2 py-1 bg-bambu-green/20 rounded text-bambu-green text-xs`,children:[(0,G.jsx)(`span`,{className:`w-1.5 h-1.5 bg-bambu-green rounded-full animate-pulse`}),`Live`]}),l?(0,G.jsx)(gs,{className:`w-5 h-5 text-bambu-gray`}):(0,G.jsx)(ps,{className:`w-5 h-5 text-bambu-gray`})]})]}),l&&(0,G.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex flex-col gap-2 p-4 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[d?(0,G.jsxs)(`button`,{onClick:e=>{e.stopPropagation(),f(!1)},className:`flex items-center gap-1.5 px-3 py-1.5 text-sm bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400 hover:bg-red-200 dark:hover:bg-red-500/30 rounded transition-colors`,children:[(0,G.jsx)(bu,{className:`w-4 h-4`}),`Stop`]}):(0,G.jsxs)(`button`,{onClick:e=>{e.stopPropagation(),f(!0),g()},className:`flex items-center gap-1.5 px-3 py-1.5 text-sm bg-bambu-green/20 text-bambu-green hover:bg-bambu-green/30 rounded transition-colors`,children:[(0,G.jsx)(Nl,{className:`w-4 h-4`}),`Start`]}),(0,G.jsxs)(`button`,{onClick:()=>_.mutate(),disabled:_.isPending||x.length===0,className:`flex items-center gap-1.5 px-3 py-1.5 text-sm bg-bambu-dark-tertiary text-bambu-gray hover:text-white hover:bg-bambu-dark-secondary rounded transition-colors disabled:opacity-50`,children:[(0,G.jsx)(Pu,{className:`w-4 h-4`}),`Clear`]}),(0,G.jsx)(`button`,{onClick:()=>g(),disabled:h,className:`flex items-center gap-1.5 px-3 py-1.5 text-sm bg-bambu-dark-tertiary text-bambu-gray hover:text-white hover:bg-bambu-dark-secondary rounded transition-colors disabled:opacity-50`,children:(0,G.jsx)(Hl,{className:`w-4 h-4 ${h?`animate-spin`:``}`})}),(0,G.jsx)(`div`,{className:`flex-1`}),(0,G.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-bambu-gray cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:t,onChange:e=>n(e.target.checked),className:`rounded border-bambu-dark-tertiary bg-bambu-dark-tertiary`}),`Auto-scroll`]}),(0,G.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[m?.filtered_count??0,`/`,m?.total_in_file??0]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`div`,{className:`relative flex-1`,children:[(0,G.jsx)(Ql,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,G.jsx)(`input`,{type:`text`,placeholder:`Search message or logger name...`,value:a,onChange:e=>o(e.target.value),className:`w-full pl-8 pr-8 py-1.5 text-sm bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`}),a&&(0,G.jsx)(`button`,{onClick:()=>o(``),className:`absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white`,children:(0,G.jsx)(nd,{className:`w-4 h-4`})})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1 bg-bambu-dark-secondary rounded border border-bambu-dark-tertiary`,children:[(0,G.jsx)(`button`,{onClick:()=>c(`ALL`),className:`px-2 py-1.5 text-xs rounded-l transition-colors ${s===`ALL`?`bg-bambu-green text-white`:`text-bambu-gray hover:text-white`}`,children:`All`}),c0e.map((e,t)=>(0,G.jsx)(`button`,{onClick:()=>c(e),className:`px-2 py-1.5 text-xs transition-colors flex items-center gap-1 ${t===c0e.length-1?`rounded-r`:``} ${s===e?`${N9[e]} bg-bambu-dark-tertiary`:`text-bambu-gray hover:text-white`}`,children:e},e))]})]})]}),(0,G.jsx)(`div`,{ref:p,className:`overflow-auto font-mono text-xs bg-black min-h-[300px] max-h-[500px]`,children:x.length===0?(0,G.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-[300px] text-bambu-gray`,children:[(0,G.jsx)(`p`,{className:`mb-2`,children:`No log entries found`}),(0,G.jsx)(`p`,{className:`text-sm`,children:`Log file may be empty or cleared`})]}):(0,G.jsx)(`div`,{className:`divide-y divide-bambu-dark-tertiary/30`,children:S.map((e,t)=>{let n=r.has(t),i=e.message.includes(` `);return(0,G.jsx)(`div`,{className:`p-2 cursor-pointer hover:bg-bambu-dark-secondary/50 transition-colors ${n?`bg-bambu-dark-secondary/30`:``}`,onClick:()=>i&&v(t),children:(0,G.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray/70 shrink-0 w-20`,children:b(e.timestamp)}),(0,G.jsx)(`span`,{className:`shrink-0`,children:(0,G.jsx)(C,{level:e.level})}),(0,G.jsxs)(`span`,{className:`text-purple-400/80 shrink-0 max-w-[200px] truncate`,title:e.logger_name,children:[`[`,e.logger_name,`]`]}),(0,G.jsx)(`span`,{className:`flex-1 ${N9[e.level]||`text-white/80`} ${!n&&i?`truncate`:``}`,children:n?(0,G.jsx)(`pre`,{className:`whitespace-pre-wrap break-all`,children:e.message}):e.message.split(` -`)[0]}),i&&(0,G.jsx)(`span`,{className:`text-bambu-gray/50 shrink-0`,children:n?(0,G.jsx)(gs,{className:`w-3.5 h-3.5`}):(0,G.jsx)(ps,{className:`w-3.5 h-3.5`})})]})},t)})})}),(0,G.jsx)(`div`,{className:`flex items-center justify-between p-3 border-t border-bambu-dark-tertiary text-sm text-bambu-gray`,children:d?(0,G.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`w-2 h-2 bg-green-500 rounded-full animate-pulse`}),`Auto-refreshing every 2 seconds`]}):(0,G.jsx)(`span`,{children:`Click Start to enable live log streaming`})})]})]})}function u0e(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:e<1024*1024*1024?`${(e/(1024*1024)).toFixed(1)} MB`:`${(e/(1024*1024*1024)).toFixed(2)} GB`}function P9({icon:e,label:t,value:n,subValue:r,color:i=`text-bambu-green`}){return(0,G.jsxs)(`div`,{className:`flex items-start gap-3 p-4 bg-bambu-dark rounded-lg`,children:[(0,G.jsx)(`div`,{className:`p-2 rounded-lg bg-bambu-dark-tertiary ${i}`,children:(0,G.jsx)(e,{className:`w-5 h-5`})}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:t}),(0,G.jsx)(`p`,{className:`text-lg font-semibold text-white truncate`,children:n}),r&&(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:r})]})]})}function d0e({percent:e,color:t=`bg-bambu-green`}){return(0,G.jsx)(`div`,{className:`w-full h-2 bg-bambu-dark rounded-full overflow-hidden`,children:(0,G.jsx)(`div`,{className:`h-full ${t} transition-all duration-300`,style:{width:`${Math.min(100,e)}%`}})})}function F9({title:e,icon:t,children:n}){return(0,G.jsxs)(zd,{className:`p-6`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-4`,children:[(0,G.jsx)(t,{className:`w-5 h-5 text-bambu-green`}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e})]}),n]})}function f0e(){let{t:e}=U(),t=co(),[n,r]=(0,y.useState)(null),[i,a]=(0,y.useState)(!1),[o,s]=(0,y.useState)(!1),[c,l]=(0,y.useState)(null),{data:u,isLoading:d,refetch:f,isFetching:p}=K({queryKey:[`systemInfo`],queryFn:Z.getSystemInfo,refetchInterval:3e4}),{data:m}=K({queryKey:[`debugLogging`],queryFn:Dd.getDebugLoggingState,staleTime:10*1e3,refetchInterval:10*1e3}),{data:h}=K({queryKey:[`settings`],queryFn:Z.getSettings}),{data:g}=K({queryKey:[`library-stats`],queryFn:Z.getLibraryStats}),{data:_}=K({queryKey:[`printers`],queryFn:Z.getPrinters}),{data:v,refetch:b,isFetching:x}=K({queryKey:[`systemHealth`],queryFn:Z.getSystemHealth,staleTime:60*1e3}),S=h?.time_format||`system`,C=async()=>{s(!0);try{let e=await Dd.setDebugLogging(!m?.enabled);t.setQueryData([`debugLogging`],e)}catch(e){console.error(`Failed to toggle debug logging:`,e)}finally{s(!1)}},w=async()=>{r(null),a(!0);try{await Dd.downloadSupportBundle()}catch(e){r(e instanceof Error?e.message:`Failed to download support bundle`)}finally{a(!1)}};if(d)return(0,G.jsx)(`div`,{className:`flex items-center justify-center h-64`,children:(0,G.jsx)(Y,{className:`w-8 h-8 text-bambu-green animate-spin`})});if(!u)return(0,G.jsx)(`div`,{className:`p-6 text-center text-bambu-gray`,children:e(`system.failedToLoad`,`Failed to load system information`)});let T=u.storage.disk_percent_used>90?`bg-red-500`:u.storage.disk_percent_used>75?`bg-yellow-500`:`bg-bambu-green`,E=u.memory.percent_used>90?`bg-red-500`:u.memory.percent_used>75?`bg-yellow-500`:`bg-bambu-green`;return(0,G.jsxs)(`div`,{className:`p-6 space-y-6`,children:[(0,G.jsxs)(`div`,{className:`flex flex-col items-start gap-4 sm:flex-row sm:items-center sm:justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h1`,{className:`text-2xl font-bold text-white`,children:e(`system.title`,`System Information`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:e(`system.subtitle`,`Monitor system resources and database statistics`)})]}),(0,G.jsxs)(`button`,{onClick:()=>f(),disabled:p,className:`flex items-center gap-2 px-4 py-2 bg-bambu-dark-secondary hover:bg-bambu-dark-tertiary rounded-lg transition-colors disabled:opacity-50`,children:[(0,G.jsx)(Hl,{className:`w-4 h-4 ${p?`animate-spin`:``}`}),e(`common.refresh`,`Refresh`)]})]}),(0,G.jsx)(F9,{title:e(`system.application`,`Application`),icon:tu,children:(0,G.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-4`,children:[(0,G.jsx)(P9,{icon:tu,label:e(`system.version`,`Version`),value:`v${u.app.version}`}),(0,G.jsx)(P9,{icon:js,label:e(`system.uptime`,`System Uptime`),value:u.system.uptime_formatted}),(0,G.jsx)(P9,{icon:tu,label:e(`system.hostname`,`Hostname`),value:u.system.hostname})]})}),(0,G.jsx)(F9,{title:e(`support.title`,`Support & Troubleshooting`),icon:Ic,children:(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`support.description`,`Enable debug logging to capture detailed information, then download a support bundle to share when reporting issues.`)}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-4 bg-bambu-dark rounded-lg`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`p-2 rounded-lg ${m?.enabled?`bg-amber-500/20 text-amber-500`:`bg-bambu-dark-tertiary text-bambu-gray`}`,children:(0,G.jsx)($o,{className:`w-5 h-5`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`font-medium text-white`,children:e(`support.debugLogging`,`Debug Logging`)}),(0,G.jsxs)(`p`,{className:`text-sm text-bambu-gray`,children:[m?.enabled?e(`support.debugLoggingEnabled`,`Capturing detailed logs`):e(`support.debugLoggingDisabled`,`Normal logging level`),m?.enabled&&m.duration_seconds!==null&&(0,G.jsxs)(`span`,{className:`text-amber-700 dark:text-amber-400 ml-2`,children:[`(`,Math.floor(m.duration_seconds/60),`m `,m.duration_seconds%60,`s)`]})]})]})]}),(0,G.jsxs)(`button`,{onClick:C,disabled:o,className:`px-4 py-2 rounded-lg font-medium transition-colors flex items-center gap-2 ${m?.enabled?`bg-amber-100 text-amber-700 hover:bg-amber-200 dark:bg-amber-500/20 dark:text-amber-400 dark:hover:bg-amber-500/30`:`bg-bambu-green/20 text-bambu-green hover:bg-bambu-green/30`} disabled:opacity-50`,children:[o&&(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),m?.enabled?e(`support.disableDebug`,`Disable`):e(`support.enableDebug`,`Enable`)]})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-4 bg-bambu-dark rounded-lg`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`p-2 rounded-lg bg-bambu-dark-tertiary text-bambu-green`,children:(0,G.jsx)(Xs,{className:`w-5 h-5`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`font-medium text-white`,children:e(`support.supportBundle`,`Support Bundle`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`support.supportBundleDescription`,`Download system info and logs as a ZIP file`)})]})]}),(0,G.jsxs)(`button`,{onClick:w,disabled:i||!m?.enabled,className:`px-4 py-2 rounded-lg font-medium bg-bambu-green/20 text-bambu-green hover:bg-bambu-green/30 transition-colors flex items-center gap-2 disabled:opacity-50 disabled:cursor-not-allowed`,title:m?.enabled?void 0:e(`support.enableDebugFirst`,`Enable debug logging first`),children:[i&&(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),i?e(`support.bundleGenerating`,`Generating...`):e(`common.download`,`Download`)]})]}),i&&(0,G.jsxs)(`div`,{className:`p-3 bg-bambu-dark-tertiary/40 rounded-lg space-y-1`,children:[(0,G.jsxs)(`p`,{className:`text-sm font-medium text-white flex items-center gap-2`,children:[(0,G.jsx)(Y,{className:`w-3.5 h-3.5 animate-spin text-bambu-green`}),e(`support.bundleGenerating`,`Generating...`)]}),(0,G.jsxs)(`ul`,{className:`text-xs text-bambu-gray list-disc list-inside space-y-0.5 pl-1`,children:[(0,G.jsx)(`li`,{children:e(`support.bundleStepConnection`,`Running printer connectivity checks`)}),(0,G.jsx)(`li`,{children:e(`support.bundleStepVirtualPrinters`,`Running virtual-printer setup checks`)}),(0,G.jsx)(`li`,{children:e(`support.bundleStepLogScan`,`Scanning recent logs for known issues`)}),(0,G.jsx)(`li`,{children:e(`support.bundleStepBuild`,`Building the support bundle ZIP`)})]})]}),n&&(0,G.jsx)(`div`,{className:`p-3 bg-red-100 border border-red-300 rounded-lg text-red-700 dark:bg-red-500/20 dark:border-red-500/30 dark:text-red-400 text-sm`,children:n}),!m?.enabled&&(0,G.jsx)(`div`,{className:`p-4 bg-bambu-dark-tertiary/50 rounded-lg`,children:(0,G.jsxs)(`p`,{className:`text-sm text-bambu-gray`,children:[(0,G.jsx)(`span`,{className:`text-amber-700 dark:text-amber-400 font-medium`,children:e(`support.instructions`,`To report an issue:`)}),(0,G.jsx)(`br`,{}),`1. `,e(`support.step1`,`Enable debug logging`),(0,G.jsx)(`br`,{}),`2. `,e(`support.step2`,`Reproduce the issue`),(0,G.jsx)(`br`,{}),`3. `,e(`support.step3`,`Download the support bundle`),(0,G.jsx)(`br`,{}),`4. `,e(`support.step4`,`Attach the ZIP file to your issue report`)]})}),(0,G.jsxs)(`div`,{className:`p-4 bg-bambu-dark rounded-lg space-y-3`,children:[(0,G.jsx)(`p`,{className:`text-sm font-medium text-white`,children:e(`support.privacyTitle`,`What's in the support bundle?`)}),(0,G.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4 text-sm`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-bambu-green font-medium mb-1`,children:e(`support.collected`,`Collected:`)}),(0,G.jsxs)(`ul`,{className:`text-bambu-gray space-y-0.5`,children:[(0,G.jsxs)(`li`,{children:[`• `,e(`support.collectItem1`,`App version and debug mode`)]}),(0,G.jsxs)(`li`,{children:[`• `,e(`support.collectItem2`,`OS, architecture, Python version`)]}),(0,G.jsxs)(`li`,{children:[`• `,e(`support.collectItem3`,`Database statistics (counts only)`)]}),(0,G.jsxs)(`li`,{children:[`• `,e(`support.collectItem4`,`Printer models and nozzle counts`)]}),(0,G.jsxs)(`li`,{children:[`• `,e(`support.collectItem5`,`Non-sensitive settings (themes, formats)`)]}),(0,G.jsxs)(`li`,{children:[`• `,e(`support.collectItem6`,`Debug logs (sanitized)`)]}),(0,G.jsxs)(`li`,{children:[`• `,e(`support.collectItem7`,`Printer connectivity and firmware versions`)]}),(0,G.jsxs)(`li`,{children:[`• `,e(`support.collectItem8`,`Integration status (Spoolman, MQTT, HA)`)]}),(0,G.jsxs)(`li`,{children:[`• `,e(`support.collectItem9`,`Network interfaces (subnets only)`)]}),(0,G.jsxs)(`li`,{children:[`• `,e(`support.collectItem10`,`Python package versions`)]}),(0,G.jsxs)(`li`,{children:[`• `,e(`support.collectItem11`,`Database health checks`)]}),(0,G.jsxs)(`li`,{children:[`• `,e(`support.collectItem12`,`Docker environment details`)]})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-red-700 dark:text-red-400 font-medium mb-1`,children:e(`support.notCollected`,`NOT collected:`)}),(0,G.jsxs)(`ul`,{className:`text-bambu-gray space-y-0.5`,children:[(0,G.jsxs)(`li`,{children:[`• `,e(`support.notItem1`,`Printer names and serial numbers`)]}),(0,G.jsxs)(`li`,{children:[`• `,e(`support.notItem2`,`Access codes and passwords`)]}),(0,G.jsxs)(`li`,{children:[`• `,e(`support.notItem3`,`Email addresses`)]}),(0,G.jsxs)(`li`,{children:[`• `,e(`support.notItem4`,`API keys and tokens`)]}),(0,G.jsxs)(`li`,{children:[`• `,e(`support.notItem5`,`Webhook URLs`)]}),(0,G.jsxs)(`li`,{children:[`• `,e(`support.notItem6`,`Your hostname or username`)]}),(0,G.jsxs)(`li`,{children:[`• `,e(`support.notItem7`,`IP addresses`)]})]})]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray/70`,children:e(`support.privacyNote`,`Email addresses in logs are replaced with [EMAIL], printer names with [PRINTER], serial numbers with [SERIAL], and IP addresses with [IP].`)})]}),(0,G.jsx)(l0e,{})]})}),(0,G.jsxs)(F9,{title:e(`diagnostic.sectionTitle`,`Connection Diagnostic`),icon:Su,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4`,children:e(`diagnostic.sectionDescription`,`Check why a printer won't connect or won't print — port reachability, LAN developer mode, Docker network mode, and credentials.`)}),_&&_.length>0?(0,G.jsx)(`div`,{className:`space-y-2`,children:_.map(t=>(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-3 bg-bambu-dark rounded-lg`,children:[(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsx)(`span`,{className:`font-medium text-white`,children:t.name}),(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray ml-2`,children:t.ip_address})]}),(0,G.jsxs)(`button`,{onClick:()=>l(t),className:`flex items-center gap-2 px-3 py-1.5 text-sm bg-bambu-dark-secondary hover:bg-bambu-dark-tertiary text-white rounded-lg transition-colors flex-shrink-0`,children:[(0,G.jsx)(Su,{className:`w-4 h-4`}),e(`diagnostic.runButton`,`Run diagnostic`)]})]},t.id))}):(0,G.jsx)(`p`,{className:`text-bambu-gray`,children:e(`diagnostic.noPrinters`,`No printers configured.`)})]}),(0,G.jsxs)(F9,{title:e(`systemHealth.sectionTitle`),icon:Lc,children:[(0,G.jsxs)(`div`,{className:`flex items-start justify-between gap-3 mb-3`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`systemHealth.sectionDescription`)}),(0,G.jsxs)(`button`,{onClick:()=>b(),disabled:x,className:`flex items-center gap-2 px-3 py-1.5 text-sm bg-bambu-dark-secondary hover:bg-bambu-dark-tertiary text-white rounded-lg transition-colors flex-shrink-0 disabled:opacity-50`,children:[(0,G.jsx)(Hl,{className:`w-4 h-4 ${x?`animate-spin`:``}`}),e(`systemHealth.rescan`)]})]}),v?(0,G.jsx)(Qp,{result:v}):(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`common.loading`)})]}),(0,G.jsxs)(F9,{title:e(`system.database`,`Database`),icon:Gs,children:[(0,G.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4 mb-4`,children:[(0,G.jsx)(P9,{icon:Gs,label:e(`system.dbEngine`,`Database Engine`),value:u.database.engine||`SQLite`}),(0,G.jsx)(P9,{icon:Gs,label:e(`system.dbVersion`,`Version`),value:u.database.version||`unknown`})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-4 mb-4`,children:[(0,G.jsx)(P9,{icon:Po,label:e(`system.totalArchives`,`Total Archives`),value:u.database.archives}),(0,G.jsx)(P9,{icon:Ss,label:e(`system.completed`,`Completed`),value:u.database.archives_completed,color:`text-green-500`}),(0,G.jsx)(P9,{icon:Ds,label:e(`system.failed`,`Failed`),value:u.database.archives_failed,color:`text-red-500`}),(0,G.jsx)(P9,{icon:Y,label:e(`system.printing`,`Printing`),value:u.database.archives_printing,color:`text-yellow-500`})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-4`,children:[(0,G.jsx)(P9,{icon:Rl,label:e(`system.printers`,`Printers`),value:u.database.printers}),(0,G.jsx)(P9,{icon:wl,label:e(`system.filaments`,`Filaments`),value:u.database.filaments}),(0,G.jsx)(P9,{icon:_c,label:e(`system.projects`,`Projects`),value:u.database.projects}),(0,G.jsx)(P9,{icon:Pl,label:e(`system.smartPlugs`,`Smart Plugs`),value:u.database.smart_plugs})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4 mt-4`,children:[(0,G.jsx)(P9,{icon:js,label:e(`system.totalPrintTime`,`Total Print Time`),value:u.database.total_print_time_formatted}),(0,G.jsx)(P9,{icon:Po,label:e(`system.totalFilament`,`Total Filament Used`),value:`${u.database.total_filament_kg} kg`,subValue:`${u.database.total_filament_grams.toLocaleString()} g`})]})]}),(0,G.jsxs)(F9,{title:e(`system.connectedPrinters`,`Connected Printers`),icon:Rl,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-4 mb-4`,children:[(0,G.jsx)(`div`,{className:`text-3xl font-bold text-bambu-green`,children:u.printers.connected}),(0,G.jsx)(`div`,{className:`text-bambu-gray`,children:e(`system.ofTotal`,`of {{total}} printers connected`,{total:u.printers.total})})]}),u.printers.connected_list.length>0?(0,G.jsx)(`div`,{className:`space-y-2`,children:u.printers.connected_list.map(e=>(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-3 bg-bambu-dark rounded-lg`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`w-2 h-2 rounded-full bg-bambu-green`}),(0,G.jsx)(`span`,{className:`font-medium text-white`,children:e.name})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-4 text-sm text-bambu-gray`,children:[(0,G.jsx)(`span`,{children:e.model}),(0,G.jsx)(`span`,{className:`px-2 py-0.5 rounded ${e.state===`RUNNING`?`bg-bambu-green/20 text-bambu-green`:e.state===`IDLE`?`bg-blue-100 text-blue-700 dark:bg-blue-500/20 dark:text-blue-400`:`bg-bambu-dark-tertiary`}`,children:e.state})]})]},e.id))}):(0,G.jsx)(`p`,{className:`text-bambu-gray`,children:e(`system.noPrintersConnected`,`No printers connected`)})]}),(0,G.jsx)(F9,{title:e(`system.storage`,`Storage`),icon:Pc,children:(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex justify-between text-sm mb-1`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:e(`system.diskUsage`,`Disk Usage`)}),(0,G.jsxs)(`span`,{className:`text-white`,children:[u.storage.disk_used_formatted,` / `,u.storage.disk_total_formatted]})]}),(0,G.jsx)(d0e,{percent:u.storage.disk_percent_used,color:T}),(0,G.jsxs)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:[u.storage.disk_free_formatted,` `,e(`system.free`,`free`),` (`,(100-u.storage.disk_percent_used).toFixed(1),`%)`]})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-4`,children:[(0,G.jsx)(P9,{icon:Po,label:e(`system.archiveStorage`,`Archive Storage`),value:u.storage.archive_size_formatted}),(0,G.jsx)(P9,{icon:Gs,label:e(`system.databaseSize`,`Database Size`),value:u.storage.database_size_formatted}),g&&(0,G.jsx)(P9,{icon:vc,label:e(`system.fileManagerStorage`,`File Manager`),value:u0e(g.total_size_bytes),subValue:`${g.total_files} files, ${g.total_folders} folders`})]})]})}),(0,G.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-6`,children:[(0,G.jsx)(F9,{title:e(`system.memory`,`Memory`),icon:ul,children:(0,G.jsx)(`div`,{className:`space-y-4`,children:(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex justify-between text-sm mb-1`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:e(`system.memoryUsage`,`Memory Usage`)}),(0,G.jsxs)(`span`,{className:`text-white`,children:[u.memory.used_formatted,` / `,u.memory.total_formatted]})]}),(0,G.jsx)(d0e,{percent:u.memory.percent_used,color:E}),(0,G.jsxs)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:[u.memory.available_formatted,` `,e(`system.available`,`available`)]})]})})}),(0,G.jsx)(F9,{title:e(`system.cpu`,`CPU`),icon:Hs,children:(0,G.jsx)(`div`,{className:`space-y-4`,children:(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,G.jsx)(P9,{icon:Hs,label:e(`system.cores`,`Cores`),value:u.cpu.count,subValue:`${u.cpu.count_logical} logical`}),(0,G.jsx)(P9,{icon:Hs,label:e(`system.usage`,`Usage`),value:`${u.cpu.percent}%`})]})})})]}),(0,G.jsx)(F9,{title:e(`system.systemDetails`,`System Details`),icon:tu,children:(0,G.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-4`,children:[(0,G.jsx)(P9,{icon:tu,label:e(`system.os`,`Operating System`),value:u.system.platform,subValue:u.system.platform_release}),(0,G.jsx)(P9,{icon:Hs,label:e(`system.architecture`,`Architecture`),value:u.system.architecture}),(0,G.jsx)(P9,{icon:tu,label:e(`system.python`,`Python`),value:u.system.python_version}),(0,G.jsx)(P9,{icon:js,label:e(`system.bootTime`,`Boot Time`),value:op(u.system.boot_time,S)})]})}),c&&(0,G.jsx)(Xp,{printerId:c.id,printerName:c.name,onClose:()=>l(null)})]})}var I9=`auth_remember_me`,L9=`auth_post_login_redirect`;function R9(e){return e?`persistent`:`session`}function p0e(){try{let e=sessionStorage.getItem(I9)===`1`;return sessionStorage.removeItem(I9),e}catch(e){return console.warn(`consumeSavedRememberMe: sessionStorage unavailable, Remember Me preference lost across OIDC redirect`,e),!1}}function z9(e){return!e||!e.startsWith(`/`)||e.startsWith(`//`)||e.startsWith(`/login`)?null:e}function m0e(e){let t=z9(e);if(t)try{sessionStorage.setItem(L9,t)}catch(e){console.warn(`stashPostLoginRedirect: sessionStorage unavailable, post-login target will be lost across OIDC redirect`,e)}}function h0e(){try{let e=sessionStorage.getItem(L9);return sessionStorage.removeItem(L9),z9(e)}catch(e){return console.warn(`consumePostLoginRedirect: sessionStorage unavailable`,e),null}}function g0e({provider:e,onClick:t,disabled:n}){let{t:r}=U(),[i,a]=(0,y.useState)(!1);return(0,G.jsxs)(`button`,{type:`button`,onClick:t,disabled:n,className:`w-full flex items-center justify-center gap-3 py-3 px-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary hover:border-bambu-green/50 rounded-lg text-white font-medium transition-colors disabled:opacity-50`,children:[e.has_icon&&!i?(0,G.jsx)(`img`,{src:Z.oidcProviderIconUrl(e.id),alt:``,className:`w-5 h-5 object-contain`,onError:()=>a(!0)}):(0,G.jsx)(su,{className:`w-5 h-5 text-bambu-green`}),r(`login.twoFA.signInWith`,{provider:e.name})]})}function _0e(){let e=or(),t=rr(),[n]=Ri(),{t:r}=U(),{login:i,loginWithToken:a,user:o,loading:s}=Nd(),{showToast:c}=qd(),{mode:l}=Id();function u(){let e=t.state?.from;if(e?.pathname){let t=z9(`${e.pathname}${e.search??``}`);if(t)return t}return h0e()??`/`}let[d,f]=(0,y.useState)(``),[p,m]=(0,y.useState)(``),[h,g]=(0,y.useState)(!1),[_,v]=(0,y.useState)(``),[b,x]=(0,y.useState)(`credentials`),[S,C]=(0,y.useState)(``),[w,T]=(0,y.useState)([]),[E,D]=(0,y.useState)(`totp`),[O,k]=(0,y.useState)(``),[A,j]=(0,y.useState)(!1),M=(0,y.useRef)(null),[N,P]=(0,y.useState)(!1),[F,I]=(0,y.useState)(``),[L,R]=(0,y.useState)(``),[z,B]=(0,y.useState)(``),{data:V}=K({queryKey:[`advancedAuthStatus`],queryFn:()=>Z.getAdvancedAuthStatus()}),{data:ee}=K({queryKey:[`oidcProviders`],queryFn:()=>Z.getOIDCProviders()}),[te,ne]=(0,y.useState)(!1);(0,y.useEffect)(()=>{!s&&o&&b===`credentials`&&e(`/`,{replace:!0})},[s,o,b,e]);let re=(0,y.useRef)(!1);(0,y.useEffect)(()=>{if(re.current||n.get(`fallback`)===`local`||!V||!V.autologin_provider_id||window.location.hash.startsWith(`#oidc_token=`)||n.get(`oidc_error`))return;re.current=!0;let e=V.autologin_provider_id,t=new Promise((e,t)=>setTimeout(()=>t(Error(`autologin timeout`)),5e3));Promise.race([Z.getOIDCAuthorizeUrl(e),t]).then(e=>{window.location.href=e.auth_url}).catch(()=>{ne(!0)})},[V,n]);let ie=V?.local_login_enabled!==!1,ae=te&&V?.autologin_provider_id!=null;(0,y.useEffect)(()=>{let t=window.location.hash,n=t.startsWith(`#reset_token=`)?t.slice(13):null;n&&(I(n),x(`reset-password`),e(`/login`,{replace:!0}))},[]),(0,y.useEffect)(()=>{let t=window.location.hash,i=t.startsWith(`#oidc_token=`)?t.slice(12):null,o=n.get(`oidc_error`);if(!i&&!o)return;let s=p0e();if(o){c({oidc_provider_error:r(`login.oidcErrors.providerError`),missing_parameters:r(`login.oidcErrors.missingParameters`),invalid_state:r(`login.oidcErrors.invalidState`),state_expired:r(`login.oidcErrors.stateExpired`),provider_not_found:r(`login.oidcErrors.providerNotFound`),discovery_failed:r(`login.oidcErrors.discoveryFailed`),invalid_discovery_document:r(`login.oidcErrors.invalidDiscovery`),token_exchange_network_error:r(`login.oidcErrors.networkError`),token_exchange_bad_response:r(`login.oidcErrors.badResponse`),no_id_token:r(`login.oidcErrors.noIdToken`),token_validation_failed:r(`login.oidcErrors.validationFailed`),nonce_mismatch:r(`login.oidcErrors.nonceMismatch`),missing_sub_claim:r(`login.oidcErrors.missingSubClaim`),no_linked_account:r(`login.oidcErrors.noLinkedAccount`),account_inactive:r(`login.oidcErrors.accountInactive`),user_resolution_failed:r(`login.oidcErrors.userResolutionFailed`),internal_error:r(`login.oidcErrors.internalError`)}[o]??(o.startsWith(`token_exchange_`)?r(`login.oidcErrors.tokenExchangeFailed`):r(`login.oidcLoginFailed`)),`error`),e(`/login`,{replace:!0});return}i&&Z.exchangeOIDCToken(i).then(t=>{if(t.requires_2fa&&t.pre_auth_token){P(s),C(t.pre_auth_token);let n=t.two_fa_methods??[];T(n),n.includes(`totp`)?D(`totp`):n.includes(`email`)?D(`email`):D(`backup`),x(`2fa`),e(`/login`,{replace:!0})}else t.access_token&&t.user?(a(t.access_token,t.user,R9(s)),c(r(`login.loginSuccess`)),e(u(),{replace:!0})):(c(r(`login.oidcLoginFailed`),`error`),e(`/login`,{replace:!0}))}).catch(t=>{console.error(`OIDC token exchange failed`,t),c(r(`login.oidcLoginFailed`),`error`),e(`/login`,{replace:!0})})},[n]);let oe=q({mutationFn:()=>i(d,p,R9(N)),onSuccess:t=>{if(t.requires_2fa&&t.pre_auth_token){C(t.pre_auth_token);let e=t.two_fa_methods??[];T(e),e.includes(`totp`)?D(`totp`):e.includes(`email`)?D(`email`):D(`backup`),x(`2fa`)}else t.access_token&&t.user&&(c(r(`login.loginSuccess`)),e(u(),{replace:!0}))},onError:e=>{c(e.message||r(`login.loginFailed`),`error`)}}),se=q({mutationFn:e=>Z.forgotPassword({email:e}),onSuccess:e=>{c(e.message,`success`),g(!1),v(``)},onError:e=>{c(e.message,`error`)}}),H=q({mutationFn:()=>Z.forgotPasswordConfirm(F,L),onSuccess:e=>{c(e.message,`success`),x(`credentials`),I(``),R(``),B(``)},onError:e=>{c(e.message||r(`login.resetPassword.resetFailed`),`error`)}}),ce=q({mutationFn:()=>Z.sendEmailOTP(S),onSuccess:e=>{j(!0),e.pre_auth_token&&C(e.pre_auth_token),c(e.message,`success`)},onError:e=>{c(e.message||r(`login.twoFA.sendCodeFailed`),`error`)}}),le=q({mutationFn:()=>Z.verify2FA({pre_auth_token:S,code:O,method:E}),onSuccess:t=>{t.access_token&&t.user?(a(t.access_token,t.user,R9(N)),c(r(`login.loginSuccess`)),e(u(),{replace:!0})):(console.error(`2FA verify: unexpected response shape`,t),c(r(`login.loginFailed`),`error`))},onError:e=>{c(e.message||r(`login.twoFA.invalidCode`),`error`),k(``)}}),ue=q({mutationFn:e=>Z.getOIDCAuthorizeUrl(e),onSuccess:e=>{if(N)try{sessionStorage.setItem(I9,`1`)}catch(e){console.warn(`setItem auth_remember_me failed, Remember Me will not carry through OIDC redirect`,e)}let n=t.state?.from;n?.pathname&&m0e(`${n.pathname}${n.search??``}`),window.location.href=e.auth_url},onError:e=>{c(e.message||r(`login.oidcLoginFailed`),`error`)}}),de=e=>{if(e.preventDefault(),!d||!p){c(r(`login.enterCredentials`),`error`);return}oe.mutate()},fe=e=>{if(e.preventDefault(),!O.trim()){c(r(`login.twoFA.enterCode`),`error`);return}le.mutate()},pe=e=>{if(e.preventDefault(),!_){c(r(`login.enterEmail`),`error`);return}se.mutate(_)},me=e=>{D(e),k(``),j(!1),setTimeout(()=>M.current?.focus(),0)};return b===`reset-password`?(0,G.jsx)(`div`,{className:`min-h-screen flex items-center justify-center bg-bambu-dark p-4`,children:(0,G.jsxs)(`div`,{className:`max-w-md w-full space-y-8 p-8 bg-gradient-to-br from-bambu-card to-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary shadow-lg`,children:[(0,G.jsxs)(`div`,{className:`text-center`,children:[(0,G.jsx)(`div`,{className:`flex items-center justify-center mb-4`,children:(0,G.jsx)(`div`,{className:`w-14 h-14 rounded-full bg-bambu-green/20 flex items-center justify-center`,children:(0,G.jsx)(Kc,{className:`w-7 h-7 text-bambu-green`})})}),(0,G.jsx)(`h2`,{className:`text-2xl font-bold text-white`,children:r(`login.resetPassword.title`)}),(0,G.jsx)(`p`,{className:`mt-2 text-sm text-bambu-gray`,children:r(`login.resetPassword.subtitle`)})]}),(0,G.jsxs)(`form`,{onSubmit:e=>{if(e.preventDefault(),L!==z){c(r(`login.resetPassword.passwordsDoNotMatch`),`error`);return}if(L.length<8){c(r(`login.resetPassword.passwordTooShort`),`error`);return}H.mutate()},className:`space-y-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{htmlFor:`new-password`,className:`block text-sm font-medium text-white mb-2`,children:r(`login.resetPassword.newPassword`)}),(0,G.jsx)(`input`,{id:`new-password`,type:`password`,required:!0,value:L,onChange:e=>R(e.target.value),className:`block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:r(`login.resetPassword.newPasswordPlaceholder`),autoFocus:!0,autoComplete:`new-password`,minLength:8})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{htmlFor:`confirm-password`,className:`block text-sm font-medium text-white mb-2`,children:r(`login.resetPassword.confirmPassword`)}),(0,G.jsx)(`input`,{id:`confirm-password`,type:`password`,required:!0,value:z,onChange:e=>B(e.target.value),className:`block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:r(`login.resetPassword.confirmPasswordPlaceholder`),autoComplete:`new-password`})]}),(0,G.jsx)(`button`,{type:`submit`,disabled:H.isPending||!L||!z,className:`w-full flex justify-center py-3 px-4 bg-bambu-green hover:bg-bambu-green-light text-white font-medium rounded-lg shadow-lg shadow-bambu-green/20 hover:shadow-bambu-green/30 focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:ring-offset-2 focus:ring-offset-bambu-dark-secondary transition-all disabled:opacity-50 disabled:cursor-not-allowed`,children:H.isPending?r(`login.resetPassword.saving`):r(`login.resetPassword.submit`)})]}),(0,G.jsx)(`div`,{className:`text-center`,children:(0,G.jsx)(`button`,{type:`button`,onClick:()=>{x(`credentials`),I(``),R(``),B(``)},className:`text-sm text-bambu-gray hover:text-bambu-green transition-colors`,children:r(`login.resetPassword.backToLogin`)})})]})}):b===`2fa`?(0,G.jsx)(`div`,{className:`min-h-screen flex items-center justify-center bg-bambu-dark p-4`,children:(0,G.jsxs)(`div`,{className:`max-w-md w-full space-y-8 p-8 bg-gradient-to-br from-bambu-card to-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary shadow-lg`,children:[(0,G.jsxs)(`div`,{className:`text-center`,children:[(0,G.jsx)(`div`,{className:`flex items-center justify-center mb-4`,children:(0,G.jsx)(`div`,{className:`w-14 h-14 rounded-full bg-bambu-green/20 flex items-center justify-center`,children:(0,G.jsx)(su,{className:`w-7 h-7 text-bambu-green`})})}),(0,G.jsx)(`h2`,{className:`text-2xl font-bold text-white`,children:r(`login.twoFA.title`)}),(0,G.jsx)(`p`,{className:`mt-2 text-sm text-bambu-gray`,children:r(`login.twoFA.subtitle`)})]}),w.length>1&&(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[w.includes(`totp`)&&(0,G.jsxs)(`button`,{type:`button`,onClick:()=>me(`totp`),className:`flex-1 flex flex-col items-center gap-1 py-2 px-3 rounded-lg border text-xs font-medium transition-colors ${E===`totp`?`border-bambu-green bg-bambu-green/10 text-bambu-green`:`border-bambu-dark-tertiary text-bambu-gray hover:border-bambu-green/50`}`,children:[(0,G.jsx)(mu,{className:`w-4 h-4`}),r(`login.twoFA.methodAuthenticator`)]}),w.includes(`email`)&&(0,G.jsxs)(`button`,{type:`button`,onClick:()=>me(`email`),className:`flex-1 flex flex-col items-center gap-1 py-2 px-3 rounded-lg border text-xs font-medium transition-colors ${E===`email`?`border-bambu-green bg-bambu-green/10 text-bambu-green`:`border-bambu-dark-tertiary text-bambu-gray hover:border-bambu-green/50`}`,children:[(0,G.jsx)(al,{className:`w-4 h-4`}),r(`login.twoFA.methodEmail`)]}),w.includes(`backup`)&&(0,G.jsxs)(`button`,{type:`button`,onClick:()=>me(`backup`),className:`flex-1 flex flex-col items-center gap-1 py-2 px-3 rounded-lg border text-xs font-medium transition-colors ${E===`backup`?`border-bambu-green bg-bambu-green/10 text-bambu-green`:`border-bambu-dark-tertiary text-bambu-gray hover:border-bambu-green/50`}`,children:[(0,G.jsx)(Kc,{className:`w-4 h-4`}),r(`login.twoFA.methodBackup`)]})]}),(0,G.jsxs)(`form`,{onSubmit:fe,className:`space-y-4`,children:[E===`totp`&&(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:r(`login.twoFA.instructionsTotp`)}),E===`email`&&(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:r(A?`login.twoFA.instructionsEmail`:`login.twoFA.instructionsEmailNotSent`)}),!A&&(0,G.jsx)(Q,{type:`button`,variant:`secondary`,className:`w-full`,onClick:()=>ce.mutate(),disabled:ce.isPending,children:ce.isPending?r(`login.twoFA.sendingCode`):r(`login.twoFA.sendCodeButton`)}),A&&(0,G.jsx)(`button`,{type:`button`,onClick:()=>{j(!1),ce.mutate()},className:`text-xs text-bambu-gray hover:text-bambu-green transition-colors`,children:r(`login.twoFA.resendCode`)})]}),E===`backup`&&(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:r(`login.twoFA.instructionsBackup`)}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{htmlFor:`twofa-code`,className:`block text-sm font-medium text-white mb-2`,children:r(E===`backup`?`login.twoFA.backupCodeLabel`:`login.twoFA.codeLabel`)}),(0,G.jsx)(`input`,{ref:M,id:`twofa-code`,type:`text`,inputMode:E===`backup`?`text`:`numeric`,autoComplete:`one-time-code`,value:O,onChange:e=>k(e.target.value.trim()),disabled:E===`email`&&!A,className:`block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray text-center tracking-widest text-xl font-mono focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors disabled:opacity-40`,placeholder:r(E===`backup`?`login.twoFA.backupCodePlaceholder`:`login.twoFA.codePlaceholder`),maxLength:E===`backup`?8:6,autoFocus:!0})]}),(0,G.jsx)(`button`,{type:`submit`,disabled:le.isPending||!O.trim()||E===`email`&&!A,className:`w-full flex justify-center py-3 px-4 bg-bambu-green hover:bg-bambu-green-light text-white font-medium rounded-lg shadow-lg shadow-bambu-green/20 hover:shadow-bambu-green/30 focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:ring-offset-2 focus:ring-offset-bambu-dark-secondary transition-all disabled:opacity-50 disabled:cursor-not-allowed`,children:le.isPending?r(`login.twoFA.verifyingButton`):r(`login.twoFA.verifyButton`)})]}),(0,G.jsx)(`div`,{className:`text-center`,children:(0,G.jsx)(`button`,{type:`button`,onClick:()=>{x(`credentials`),C(``),k(``),j(!1)},className:`text-sm text-bambu-gray hover:text-bambu-green transition-colors`,children:r(`login.twoFA.backToLogin`)})})]})}):(0,G.jsxs)(`div`,{className:`min-h-screen flex items-center justify-center bg-bambu-dark p-4`,children:[(0,G.jsxs)(`div`,{className:`max-w-md w-full space-y-8 p-8 bg-gradient-to-br from-bambu-card to-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary shadow-lg`,children:[(0,G.jsxs)(`div`,{className:`text-center`,children:[(0,G.jsx)(`div`,{className:`flex items-center justify-center mb-6`,children:(0,G.jsx)(`img`,{src:l===`dark`?`/img/bambuddy_logo_dark_transparent.png`:`/img/bambuddy_logo_light.png`,alt:`Bambuddy`,className:`h-16`})}),(0,G.jsx)(`h2`,{className:`text-3xl font-bold text-white`,children:r(`login.title`)}),(0,G.jsx)(`p`,{className:`mt-2 text-sm text-bambu-gray`,children:r(`login.subtitle`)})]}),ae&&(0,G.jsx)(`div`,{className:`mt-6 rounded-lg border border-amber-300 dark:border-amber-500/40 bg-amber-50 dark:bg-amber-500/10 px-4 py-3 text-sm text-amber-800 dark:text-amber-200`,children:r(`login.autologinFailed`)}),!ie&&(0,G.jsx)(`div`,{className:`mt-6 rounded-lg border border-bambu-dark-tertiary bg-bambu-dark/40 px-4 py-3 text-sm text-bambu-gray`,children:r(`login.localDisabledNotice`)}),ie&&(0,G.jsxs)(`form`,{className:`mt-8 space-y-6`,onSubmit:de,children:[(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{htmlFor:`username`,className:`block text-sm font-medium text-white mb-2`,children:V?.advanced_auth_enabled?r(`login.usernameOrEmail`):r(`login.username`)}),(0,G.jsx)(`input`,{id:`username`,type:`text`,required:!0,value:d,onChange:e=>f(e.target.value),className:`block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:V?.advanced_auth_enabled?r(`login.usernameOrEmailPlaceholder`):r(`login.usernamePlaceholder`),autoComplete:`username`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{htmlFor:`password`,className:`block text-sm font-medium text-white mb-2`,children:r(`login.password`)||`Password`}),(0,G.jsx)(`input`,{id:`password`,type:`password`,required:!0,value:p,onChange:e=>m(e.target.value),className:`block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:r(`login.passwordPlaceholder`),autoComplete:`current-password`})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`input`,{id:`remember-me`,type:`checkbox`,checked:N,onChange:e=>P(e.target.checked),className:`h-4 w-4 rounded border-bambu-dark-tertiary bg-bambu-dark-secondary text-bambu-green focus:ring-bambu-green/50 cursor-pointer`}),(0,G.jsx)(`label`,{htmlFor:`remember-me`,className:`text-sm text-bambu-gray cursor-pointer`,children:r(`login.rememberMe`)})]}),(0,G.jsx)(`div`,{children:(0,G.jsx)(`button`,{type:`submit`,disabled:oe.isPending,className:`w-full flex justify-center py-3 px-4 bg-bambu-green hover:bg-bambu-green-light text-white font-medium rounded-lg shadow-lg shadow-bambu-green/20 hover:shadow-bambu-green/30 focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:ring-offset-2 focus:ring-offset-bambu-dark-secondary transition-all disabled:opacity-50 disabled:cursor-not-allowed disabled:hover:bg-bambu-green`,children:oe.isPending?r(`login.signingIn`):r(`login.signIn`)})}),(0,G.jsx)(`div`,{className:`text-center`,children:(0,G.jsx)(`button`,{type:`button`,onClick:()=>g(!0),className:`text-sm text-bambu-gray hover:text-bambu-green transition-colors`,children:r(`login.forgotPassword`)})})]}),ee&&ee.length>0&&(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(`div`,{className:`absolute inset-0 flex items-center`,children:(0,G.jsx)(`div`,{className:`w-full border-t border-bambu-dark-tertiary`})}),(0,G.jsx)(`div`,{className:`relative flex justify-center text-sm`,children:(0,G.jsx)(`span`,{className:`px-2 bg-bambu-dark-secondary text-bambu-gray`,children:r(`login.twoFA.orContinueWith`)})})]}),(0,G.jsx)(`div`,{className:`space-y-2`,children:ee.map(e=>(0,G.jsx)(g0e,{provider:e,onClick:()=>ue.mutate(e.id),disabled:ue.isPending},e.id))})]})]}),h&&(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:()=>g(!1),children:(0,G.jsxs)(zd,{className:`w-full max-w-md`,onClick:e=>e.stopPropagation(),children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(al,{className:`w-5 h-5 text-bambu-green`}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:r(`login.forgotPasswordTitle`)})]}),(0,G.jsx)(Q,{variant:`ghost`,size:`sm`,onClick:()=>{g(!1),v(``)},children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]})}),(0,G.jsx)(Vd,{children:V?.advanced_auth_enabled?(0,G.jsxs)(`form`,{onSubmit:pe,className:`space-y-4`,children:[(0,G.jsx)(`p`,{className:`text-bambu-gray text-sm`,children:r(`login.forgotPasswordEmailMessage`)}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{htmlFor:`forgot-email`,className:`block text-sm font-medium text-white mb-2`,children:r(`login.emailAddress`)}),(0,G.jsx)(`input`,{id:`forgot-email`,type:`email`,required:!0,value:_,onChange:e=>v(e.target.value),className:`block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:r(`login.emailPlaceholder`)})]}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,className:`flex-1`,onClick:()=>{g(!1),v(``)},children:r(`login.cancel`)}),(0,G.jsx)(Q,{type:`submit`,className:`flex-1`,disabled:se.isPending,children:se.isPending?r(`login.sending`):r(`login.sendResetEmail`)})]})]}):(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsx)(`p`,{className:`text-bambu-gray`,children:r(`login.forgotPasswordMessage`)}),(0,G.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4 space-y-2`,children:[(0,G.jsx)(`p`,{className:`text-sm text-white font-medium`,children:r(`login.howToReset`)}),(0,G.jsxs)(`ol`,{className:`text-sm text-bambu-gray space-y-1 list-decimal list-inside`,children:[(0,G.jsx)(`li`,{children:r(`login.resetStep1`)}),(0,G.jsx)(`li`,{children:r(`login.resetStep2`)}),(0,G.jsx)(`li`,{children:r(`login.resetStep3`)}),(0,G.jsx)(`li`,{children:r(`login.resetStep4`)})]})]}),(0,G.jsx)(Q,{variant:`secondary`,className:`w-full`,onClick:()=>g(!1),children:r(`login.gotIt`)})]})})]})})]})}function v0e(){let e=or(),{t}=U(),{showToast:n}=qd(),{mode:r}=Id(),{refreshAuth:i}=Nd(),[a,o]=(0,y.useState)(!1),[s,c]=(0,y.useState)(``),[l,u]=(0,y.useState)(``),[d,f]=(0,y.useState)(``),p=q({mutationFn:()=>Z.setupAuth({auth_enabled:a,admin_username:a?s:void 0,admin_password:a?l:void 0}),onSuccess:async r=>{await i(),r.auth_enabled?r.admin_created?(n(t(`setup.toast.authEnabledAdminCreated`)),e(`/login`)):(n(t(`setup.toast.authEnabledExistingAdmins`)),e(`/login`)):(n(t(`setup.toast.setupCompleted`)),e(`/`))},onError:e=>{n(e.message,`error`)}});return(0,G.jsx)(`div`,{className:`min-h-screen flex items-center justify-center bg-bambu-dark p-4`,children:(0,G.jsxs)(`div`,{className:`max-w-md w-full space-y-8 p-8 bg-gradient-to-br from-bambu-card to-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary shadow-lg`,children:[(0,G.jsxs)(`div`,{className:`text-center`,children:[(0,G.jsx)(`div`,{className:`flex items-center justify-center mb-6`,children:(0,G.jsx)(`img`,{src:r===`dark`?`/img/bambuddy_logo_dark_transparent.png`:`/img/bambuddy_logo_light.png`,alt:`Bambuddy`,className:`h-16`})}),(0,G.jsx)(`h2`,{className:`text-3xl font-bold text-white`,children:t(`setup.title`)}),(0,G.jsx)(`p`,{className:`mt-2 text-sm text-bambu-gray`,children:t(`setup.subtitle`)})]}),(0,G.jsxs)(`form`,{className:`mt-8 space-y-6`,onSubmit:e=>{if(e.preventDefault(),a&&(s||l)){if(!s||!l){n(t(`setup.toast.enterBothCredentials`),`error`);return}if(l!==d){n(t(`setup.toast.passwordsDoNotMatch`),`error`);return}if(l.length<6){n(t(`setup.toast.passwordTooShort`),`error`);return}}p.mutate()},children:[(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center p-4 bg-bambu-dark-secondary/50 rounded-lg border border-bambu-dark-tertiary`,children:[(0,G.jsx)(`input`,{id:`auth-enabled`,type:`checkbox`,checked:a,onChange:e=>o(e.target.checked),className:`h-4 w-4 text-bambu-green focus:ring-bambu-green border-bambu-dark-tertiary rounded bg-bambu-dark-secondary`}),(0,G.jsx)(`label`,{htmlFor:`auth-enabled`,className:`ml-3 block text-sm font-medium text-white`,children:t(`setup.enableAuth`)})]}),a&&(0,G.jsxs)(`div`,{className:`space-y-4 mt-4`,children:[(0,G.jsx)(`div`,{className:`p-3 bg-bambu-dark-secondary/50 border border-bambu-dark-tertiary rounded-lg`,children:(0,G.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,G.jsx)(Wc,{className:`w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0`}),(0,G.jsxs)(`div`,{className:`text-sm text-bambu-gray`,children:[(0,G.jsx)(`p`,{className:`text-white font-medium mb-1`,children:t(`setup.adminAccount`)}),(0,G.jsx)(`p`,{children:t(`setup.adminAccountDesc`)})]})]})}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{htmlFor:`admin-username`,className:`block text-sm font-medium text-white mb-2`,children:[t(`setup.adminUsername`),` `,(0,G.jsx)(`span`,{className:`text-bambu-gray text-xs`,children:t(`setup.optionalIfAdminExists`)})]}),(0,G.jsx)(`input`,{id:`admin-username`,type:`text`,value:s,onChange:e=>c(e.target.value),className:`block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:t(`setup.adminUsernamePlaceholder`),autoComplete:`username`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{htmlFor:`admin-password`,className:`block text-sm font-medium text-white mb-2`,children:[t(`setup.adminPassword`),` `,(0,G.jsx)(`span`,{className:`text-bambu-gray text-xs`,children:t(`setup.optionalIfAdminExists`)})]}),(0,G.jsx)(`input`,{id:`admin-password`,type:`password`,value:l,onChange:e=>u(e.target.value),className:`block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:t(`setup.adminPasswordPlaceholder`),minLength:6,autoComplete:`new-password`})]}),l&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{htmlFor:`confirm-password`,className:`block text-sm font-medium text-white mb-2`,children:t(`setup.confirmPassword`)}),(0,G.jsx)(`input`,{id:`confirm-password`,type:`password`,value:d,onChange:e=>f(e.target.value),className:`block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:t(`setup.confirmPasswordPlaceholder`),minLength:6,autoComplete:`new-password`})]})]})]}),(0,G.jsx)(`div`,{children:(0,G.jsx)(`button`,{type:`submit`,disabled:p.isPending,className:`w-full flex justify-center py-3 px-4 bg-bambu-green hover:bg-bambu-green-light text-white font-medium rounded-lg shadow-lg shadow-bambu-green/20 hover:shadow-bambu-green/30 focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:ring-offset-2 focus:ring-offset-bambu-dark-secondary transition-all disabled:opacity-50 disabled:cursor-not-allowed disabled:hover:bg-bambu-green`,children:p.isPending?t(`setup.settingUp`):t(`setup.completeSetup`)})})]})]})})}function y0e(){let{t:e}=U(),{user:t}=Nd(),{showToast:n}=qd(),r=co(),i=or(),[a,o]=(0,y.useState)(!0),[s,c]=(0,y.useState)(!0),[l,u]=(0,y.useState)(!0),[d,f]=(0,y.useState)(!0),[p,m]=(0,y.useState)(!1),{data:h,isLoading:g}=K({queryKey:[`advancedAuthStatus`],queryFn:Z.getAdvancedAuthStatus,staleTime:300*1e3}),{data:_,isLoading:v}=K({queryKey:[`settings`],queryFn:Z.getSettings,staleTime:300*1e3}),{data:b,isLoading:x}=K({queryKey:[`user-email-preferences`],queryFn:()=>Z.getUserEmailPreferences()});(0,y.useEffect)(()=>{(h&&!h.advanced_auth_enabled||_&&!_.user_notifications_enabled)&&i(`/settings`,{replace:!0})},[h,_,i]),(0,y.useEffect)(()=>{b&&(o(b.notify_print_start),c(b.notify_print_complete),u(b.notify_print_failed),f(b.notify_print_stopped),m(!1))},[b]);let S=q({mutationFn:()=>Z.updateUserEmailPreferences({notify_print_start:a,notify_print_complete:s,notify_print_failed:l,notify_print_stopped:d}),onSuccess:()=>{r.invalidateQueries({queryKey:[`user-email-preferences`]}),m(!1),n(e(`notifications.userEmail.saveSuccess`),`success`)},onError:t=>{n(t.message||e(`notifications.userEmail.saveError`),`error`)}}),C=(e,t)=>{e(!t),m(!0)};return x||g||v?(0,G.jsx)(`div`,{className:`flex items-center justify-center h-64`,children:(0,G.jsx)(Y,{className:`w-8 h-8 animate-spin text-bambu-green`})}):(0,G.jsxs)(`div`,{className:`p-4 md:p-6 max-w-2xl mx-auto`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3 mb-6`,children:[(0,G.jsx)(qo,{className:`w-7 h-7 text-bambu-green`}),(0,G.jsx)(`h1`,{className:`text-2xl font-bold text-white`,children:e(`notifications.userEmail.title`)})]}),(0,G.jsx)(zd,{className:`mb-6 border-blue-300 bg-blue-50 dark:border-blue-500/30 dark:bg-blue-500/5`,children:(0,G.jsx)(Vd,{className:`py-4`,children:(0,G.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,G.jsx)(`div`,{className:`w-10 h-10 rounded-full flex items-center justify-center bg-blue-100 dark:bg-blue-500/20 flex-shrink-0`,children:(0,G.jsx)(al,{className:`w-5 h-5 text-blue-600 dark:text-blue-400`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`text-white font-medium`,children:e(`notifications.userEmail.emailNotifications`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:e(`notifications.userEmail.emailNotificationsDesc`)}),t?.email?(0,G.jsxs)(`p`,{className:`text-sm text-blue-700 dark:text-blue-400 mt-2`,children:[e(`notifications.userEmail.sendingTo`),`: `,(0,G.jsx)(`strong`,{children:t.email})]}):(0,G.jsx)(`p`,{className:`text-sm text-yellow-700 dark:text-yellow-400 mt-2`,children:e(`notifications.userEmail.noEmailWarning`)})]})]})})}),(0,G.jsxs)(zd,{className:`mb-6`,children:[(0,G.jsxs)(Bd,{children:[(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`notifications.userEmail.printJobNotifications`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:e(`notifications.userEmail.printJobNotificationsDesc`)})]}),(0,G.jsxs)(Vd,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-4 bg-bambu-dark rounded-lg`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`w-10 h-10 rounded-full flex items-center justify-center ${a?`bg-bambu-green/20`:`bg-bambu-dark-tertiary`}`,children:(0,G.jsx)(Ss,{className:`w-5 h-5 ${a?`text-bambu-green`:`text-bambu-gray`}`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white font-medium`,children:e(`notifications.userEmail.printJobStarts`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`notifications.userEmail.printJobStartsDesc`)})]})]}),(0,G.jsx)(`button`,{onClick:()=>C(o,a),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors focus:outline-none focus:ring-2 focus:ring-bambu-green focus:ring-offset-2 focus:ring-offset-bambu-dark ${a?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,role:`switch`,"aria-checked":a,children:(0,G.jsx)(`span`,{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${a?`translate-x-6`:`translate-x-1`}`})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-4 bg-bambu-dark rounded-lg`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`w-10 h-10 rounded-full flex items-center justify-center ${s?`bg-bambu-green/20`:`bg-bambu-dark-tertiary`}`,children:(0,G.jsx)(Ss,{className:`w-5 h-5 ${s?`text-bambu-green`:`text-bambu-gray`}`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white font-medium`,children:e(`notifications.userEmail.printJobFinishes`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`notifications.userEmail.printJobFinishesDesc`)})]})]}),(0,G.jsx)(`button`,{onClick:()=>C(c,s),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors focus:outline-none focus:ring-2 focus:ring-bambu-green focus:ring-offset-2 focus:ring-offset-bambu-dark ${s?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,role:`switch`,"aria-checked":s,children:(0,G.jsx)(`span`,{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${s?`translate-x-6`:`translate-x-1`}`})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-4 bg-bambu-dark rounded-lg`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`w-10 h-10 rounded-full flex items-center justify-center ${l?`bg-bambu-green/20`:`bg-bambu-dark-tertiary`}`,children:(0,G.jsx)(Ss,{className:`w-5 h-5 ${l?`text-bambu-green`:`text-bambu-gray`}`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white font-medium`,children:e(`notifications.userEmail.printErrors`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`notifications.userEmail.printErrorsDesc`)})]})]}),(0,G.jsx)(`button`,{onClick:()=>C(u,l),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors focus:outline-none focus:ring-2 focus:ring-bambu-green focus:ring-offset-2 focus:ring-offset-bambu-dark ${l?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,role:`switch`,"aria-checked":l,children:(0,G.jsx)(`span`,{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${l?`translate-x-6`:`translate-x-1`}`})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-4 bg-bambu-dark rounded-lg`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`w-10 h-10 rounded-full flex items-center justify-center ${d?`bg-bambu-green/20`:`bg-bambu-dark-tertiary`}`,children:(0,G.jsx)(Ss,{className:`w-5 h-5 ${d?`text-bambu-green`:`text-bambu-gray`}`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white font-medium`,children:e(`notifications.userEmail.printJobStops`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`notifications.userEmail.printJobStopsDesc`)})]})]}),(0,G.jsx)(`button`,{onClick:()=>C(f,d),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors focus:outline-none focus:ring-2 focus:ring-bambu-green focus:ring-offset-2 focus:ring-offset-bambu-dark ${d?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,role:`switch`,"aria-checked":d,children:(0,G.jsx)(`span`,{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${d?`translate-x-6`:`translate-x-1`}`})})]})]})]}),(0,G.jsx)(`div`,{className:`flex justify-end`,children:(0,G.jsx)(Q,{onClick:()=>S.mutate(),disabled:!p||S.isPending||!t?.email,children:S.isPending?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),e(`common.saving`)]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(ql,{className:`w-4 h-4`}),e(`common.save`)]})})})]})}function b0e(){let e=or(),[t,n]=Ri(),{t:r}=U(),i=t.get(`archive`),a=t.get(`library_file`),o=t.get(`plate`),s=K({queryKey:[`gcode-viewer-archive-colors`,i],queryFn:()=>Z.getArchiveCapabilities(Number(i)),enabled:!!i,staleTime:5*6e4,retry:!1}),c=K({queryKey:[`gcode-viewer-library-colors`,a],queryFn:()=>Z.getLibraryFilePlates(Number(a)),enabled:!!a,staleTime:5*6e4,retry:!1}),l=K({queryKey:[`gcode-viewer-archive-plates`,i],queryFn:()=>Z.getArchivePlates(Number(i)),enabled:!!i,staleTime:5*6e4,retry:!1}),u=(0,y.useMemo)(()=>(i?l.data?.plates:c.data?.plates)??[],[i,l.data,c.data]),d=(0,y.useMemo)(()=>o?Number(o):u.length===0?null:Math.min(...u.map(e=>e.index)),[o,u]),f=e=>{if(e===d)return;let r=new URLSearchParams(t);r.set(`plate`,String(e)),n(r,{replace:!0})},p=(0,y.useMemo)(()=>{if(i)return s.data?.filament_colors;let e=u.find(e=>e.index===d)||u[0];if(!e?.filaments?.length)return;let t=[];for(let n of e.filaments){let e=Math.max(0,(n.slot_id??1)-1);n.color&&(t[e]=n.color)}return t.length>0?t:void 0},[i,s.data,u,d]),m=(0,y.useMemo)(()=>{let e=e=>o?`${e}?plate=${encodeURIComponent(o)}`:e;return i?e(Z.getArchiveGcode(Number(i))):a?e(Z.getLibraryFileGcodeUrl(Number(a))):null},[i,a,o]),h=()=>{window.history.length>1?e(-1):e(i?`/archives`:`/files`)},g=i?r(`gcodeViewer.backToArchives`,`Back to Archives`):r(`gcodeViewer.backToFiles`,`Back to File Manager`);return(0,G.jsxs)(`div`,{className:`flex flex-col min-h-[calc(100vh-64px)] lg:h-[calc(100vh-64px)]`,children:[(0,G.jsxs)(`div`,{className:`flex-shrink-0 px-4 py-2 border-b border-bambu-dark-tertiary flex flex-wrap items-center gap-x-4 gap-y-2`,children:[(0,G.jsxs)(`button`,{type:`button`,onClick:h,className:`inline-flex items-center gap-1.5 text-sm text-gray-700 dark:text-gray-300 hover:text-gray-900 dark:hover:text-white transition-colors`,children:[(0,G.jsx)(Lo,{className:`w-4 h-4`}),g]}),u.length>1&&(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:r(`gcodeViewer.plates`,`Plates`)}),u.map(e=>(0,G.jsx)(`button`,{type:`button`,onClick:()=>f(e.index),"aria-pressed":e.index===d,title:e.name??void 0,className:`px-2 py-0.5 rounded text-xs transition-colors ${e.index===d?`bg-bambu-green text-white`:`bg-bambu-dark-tertiary text-gray-700 dark:text-gray-300 hover:text-gray-900 dark:hover:text-white`}`,children:r(`gcodeViewer.plateN`,`Plate {{n}}`,{n:e.index})},e.index))]})]}),m?(0,G.jsx)(gT,{gcodeUrl:m,filamentColors:p,className:`flex-1 min-h-0`}):(0,G.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-sm text-bambu-gray`,children:r(`gcodeViewer.noSource`,`No file was given to preview.`)})]})}var x0e=4401;function S0e(){let e=(0,y.useRef)(null),t=(0,y.useRef)(null),n=(0,y.useRef)(!1),r=co(),[i,a]=(0,y.useState)(!1),o=(0,y.useRef)(new Map),{showToast:s}=qd(),{t:c}=U(),l=(0,y.useRef)(new Set),u=(0,y.useRef)(null),d=(0,y.useRef)(new Map),f=(0,y.useRef)(null),p=(0,y.useRef)([]),m=(0,y.useRef)(!1),h=(0,y.useRef)(()=>{}),g=(0,y.useCallback)(()=>{if(m.current||p.current.length===0)return;m.current=!0;let e=()=>{let t=p.current.shift();t?(h.current(t),p.current.length>0?setTimeout(e,16):m.current=!1):m.current=!1};e()},[]),_=(0,y.useCallback)(async()=>{if(n.current||e.current?.readyState===WebSocket.OPEN)return;let r;try{r=(await Z.getWebSocketToken()).token}catch(e){let t=e instanceof sd?e.status:0;if(t===401||t===403)return}if(n.current)return;let i=window.location.protocol===`https:`?`wss:`:`ws:`,o=r?`?token=${encodeURIComponent(r)}`:``,s=`${i}//${window.location.host}/api/v1/ws${o}`,c=new WebSocket(s),l=null;c.onopen=()=>{console.log(`[WebSocket] Connected`),a(!0),l=window.setInterval(()=>{c.readyState===WebSocket.OPEN&&c.send(JSON.stringify({type:`ping`}))},3e4)},c.onmessage=e=>{try{let t=JSON.parse(e.data);t.type===`printer_status`&&t.printer_id!==void 0&&t.data?h.current(t):(p.current.push(t),g())}catch{}},c.onclose=r=>{console.log(`[WebSocket] Closed`,r.code,r.reason),l&&=(clearInterval(l),null),a(!1),e.current=null,!(n.current||r.code===x0e)&&(t.current=window.setTimeout(()=>{_()},3e3))},c.onerror=e=>{console.error(`[WebSocket] Error`,e),c.close()},e.current=c},[g]),v=(0,y.useCallback)(()=>{f.current&&=(clearTimeout(f.current),null);let e=new Map(d.current);d.current.clear(),e.forEach((e,t)=>{r.setQueryData([`printerStatus`,t],t=>{let n={...t,...e};return n.wifi_signal==null&&t?.wifi_signal!=null&&(n.wifi_signal=t.wifi_signal),n})})},[r]),b=(0,y.useCallback)((e,t)=>{let n=d.current.get(e)||{};if(d.current.set(e,{...n,...t}),document.hidden){v();return}f.current||=window.setTimeout(v,100)},[v]),x=(0,y.useCallback)(e=>{l.current.add(e),u.current&&clearTimeout(u.current),u.current=window.setTimeout(()=>{let e=Array.from(l.current);l.current.clear(),u.current=null;let t=0;e.forEach(e=>{setTimeout(()=>{r.invalidateQueries({queryKey:[e]})},t),t+=500})},3e3)},[r]),S=(0,y.useCallback)(()=>{r.invalidateQueries({queryKey:[`spool-assignments`]}),r.invalidateQueries({queryKey:[`spoolman-slot-assignments`]}),r.invalidateQueries({queryKey:[`slotPresets`]})},[r]),C=(0,y.useCallback)(e=>{switch(e.type){case`printer_status`:e.printer_id!==void 0&&e.data&&b(e.printer_id,e.data);break;case`print_start`:e.printer_id!==void 0&&r.invalidateQueries({queryKey:[`printerStatus`,e.printer_id]});break;case`missing_spool_assignment`:{if(e.printer_id===void 0||!Array.isArray(e.missing_slots))break;let t=e.missing_slots.map(e=>e&&typeof e.slot==`string`?e.slot:`Unknown`).filter(e=>e.length>0);if(t.length===0){o.current.delete(e.printer_id);break}let n=t.join(`|`);if(o.current.get(e.printer_id)===n)break;o.current.set(e.printer_id,n),s(c(`printers.toast.missingSpoolAssignment`,{printer:e.printer_name||`Printer ${e.printer_id}`,slots:t.join(`, `)}),`warning`);break}case`print_complete`:x(`archives`),x(`archiveStats`);break;case`kill_switch_triggered`:s(c(`printers.toast.killSwitchTriggered`,{printer:e.printer_name||`Printer ${e.printer_id??`?`}`,filename:e.filename||c(`common.unknown`)}),`error`);break;case`billing_charge_failed`:s(c(`printers.toast.billingChargeFailed`,{printer:e.printer_name||`Printer ${e.printer_id??`?`}`,filename:e.filename||c(`common.unknown`)}),`error`);break;case`archive_created`:x(`archives`),x(`archiveStats`);break;case`archive_updated`:x(`archives`);break;case`pong`:break;case`plate_not_empty`:window.dispatchEvent(new CustomEvent(`plate-not-empty`,{detail:{printer_id:e.printer_id,printer_name:e.printer_name,message:e.message}}));break;case`inventory_changed`:x(`inventory-spools`),x(`spoolman-inventory-spools`),x(v6[0]);break;case`spool_assignment_changed`:S();break;case`spool_assignment_verified`:{let t=e.printer_name||`Printer`,n=e.slot||`?`;e.verified?e.kprofile_applied===!1?s(c(`printers.toast.assignmentVerifiedNoKprofile`,{slot:n,printer:t}),`warning`):s(c(`printers.toast.assignmentVerified`,{slot:n,printer:t}),`success`):s(c(`printers.toast.assignmentNotConfirmed`,{slot:n,printer:t}),`warning`);break}case`spool_auto_assigned`:x(`inventory-spools`),S();break;case`spool_usage_logged`:x(`inventory-spools`);break;case`unknown_tag`:{let t=e;window.dispatchEvent(new CustomEvent(`unknown-tag`,{detail:{printer_id:t.printer_id,ams_id:t.ams_id,tray_id:t.tray_id,tag_uid:t.tag_uid,tray_uuid:t.tray_uuid,tray_type:t.tray_type,tray_color:t.tray_color,tray_sub_brands:t.tray_sub_brands,tray_count:t.tray_count}}));break}case`spoolbuddy_weight`:window.dispatchEvent(new CustomEvent(`spoolbuddy-weight`,{detail:e}));break;case`spoolbuddy_tag_matched`:window.dispatchEvent(new CustomEvent(`spoolbuddy-tag-matched`,{detail:e})),x(`inventory-spools`);break;case`spoolbuddy_unknown_tag`:window.dispatchEvent(new CustomEvent(`spoolbuddy-unknown-tag`,{detail:e}));break;case`spoolbuddy_tag_removed`:window.dispatchEvent(new CustomEvent(`spoolbuddy-tag-removed`,{detail:e}));break;case`spoolbuddy_tag_written`:window.dispatchEvent(new CustomEvent(`spoolbuddy-tag-written`,{detail:e})),x(`inventory-spools`);break;case`spoolbuddy_tag_write_failed`:window.dispatchEvent(new CustomEvent(`spoolbuddy-tag-write-failed`,{detail:e}));break;case`spoolbuddy_online`:window.dispatchEvent(new CustomEvent(`spoolbuddy-online`,{detail:e})),x(`spoolbuddy-devices`),x(`spoolbuddy-update-check`);break;case`spoolbuddy_offline`:window.dispatchEvent(new CustomEvent(`spoolbuddy-offline`,{detail:e})),x(`spoolbuddy-devices`);break;case`spoolbuddy_update`:x(`spoolbuddy-devices`),x(`spoolbuddy-update-check`);break;case`queue_item_uploading`:case`queue_item_upload_progress`:case`queue_item_acked`:case`queue_item_failed`:window.dispatchEvent(new CustomEvent(`bambuddy:dispatch-toast`,{detail:e}));break;case`pipeline_run_updated`:r.invalidateQueries({queryKey:[`pipeline-runs-all`]}),e.run?.pipeline_id&&r.invalidateQueries({queryKey:[`pipeline-runs`,e.run.pipeline_id]});break}},[r,x,S,b,s,c]);return(0,y.useEffect)(()=>{h.current=C},[C]),(0,y.useEffect)(()=>(n.current=!1,_(),()=>{n.current=!0,t.current&&clearTimeout(t.current),u.current&&clearTimeout(u.current),f.current&&clearTimeout(f.current),e.current&&e.current.close()}),[_]),{isConnected:i,sendMessage:(0,y.useCallback)(t=>{e.current?.readyState===WebSocket.OPEN&&e.current.send(JSON.stringify(t))},[])}}var C0e=`#00ae42`,w0e=e=>e!=null&&e>0?e:1/0;function T0e(e){let t=null;for(let n of e){if(!n||n.state!==`RUNNING`||n.progress==null)continue;if(t===null){t=n;continue}let e=w0e(n.remaining_time),r=w0e(t.remaining_time);(e(t.progress??0))&&(t=n)}return t}function E0e(e){let t=document.createElement(`canvas`);t.width=32,t.height=32;let n=t.getContext(`2d`);if(!n)return null;let r=getComputedStyle(document.documentElement).getPropertyValue(`--accent`).trim()||C0e,i=Math.max(0,Math.min(100,e))/100,a=-Math.PI/2;return n.lineWidth=4,n.beginPath(),n.arc(16,16,13,0,Math.PI*2),n.strokeStyle=`rgba(128,128,128,0.3)`,n.stroke(),n.beginPath(),n.arc(16,16,13,a,a+i*Math.PI*2),n.strokeStyle=r,n.lineCap=`round`,n.stroke(),t.toDataURL(`image/png`)}function B9(e,t){document.querySelectorAll(`link[rel~="icon"]`).forEach(n=>{if(e)t.has(n)||t.set(n,n.href),n.href=e;else{let e=t.get(n);e!==void 0&&(n.href=e)}}),e||t.clear()}function D0e(){let{progressInTitle:e,resolvedMode:t,darkAccent:n,lightAccent:r}=Id(),i=t===`dark`?n:r,{data:a}=K({queryKey:[`printers`],queryFn:Z.getPrinters,enabled:e}),o=Co({queries:(e?a??[]:[]).map(e=>({queryKey:[`printerStatus`,e.id],queryFn:()=>Z.getPrinterStatus(e.id)}))}),s=(0,y.useRef)(new Map),c=(0,y.useRef)(document.title),l=(0,y.useRef)(!1),u=e?T0e(o.map(e=>e.data)):null,d=u&&u.progress!=null?Math.round(u.progress):null;(0,y.useEffect)(()=>{e&&d!=null?(document.title=`${d}% · ${c.current}`,B9(E0e(d),s.current),l.current=!0):l.current&&=(document.title=c.current,B9(null,s.current),!1)},[e,d,i]),(0,y.useEffect)(()=>{let e=s.current,t=l,n=c.current;return()=>{t.current&&(document.title=n,B9(null,e))}},[])}function O0e({children:e}){let{authEnabled:t,user:n,loading:r}=Nd(),{data:i}=K({queryKey:[`color-catalog-map`],queryFn:async()=>{let e=await Z.getColorNameMap();return{colors:e.colors,byMaterial:e.by_material??{}}},staleTime:1/0,gcTime:1/0,retry:2,enabled:!r&&(!t||n!==null)});return(0,y.useEffect)(()=>{i&&vf(i.colors,i.byMaterial)},[i]),(0,G.jsx)(G.Fragment,{children:e})}function k0e({selectedPrinterId:e,onPrinterChange:t,deviceOnline:n}){let{t:r}=U(),[i,a]=(0,y.useState)(new Date),{data:o=[]}=K({queryKey:[`printers`],queryFn:()=>Z.getPrinters()}),s=Co({queries:o.map(e=>({queryKey:[`printerStatus`,e.id],queryFn:()=>Z.getPrinterStatus(e.id),refetchInterval:1e4}))}),c=(0,y.useMemo)(()=>o.filter((e,t)=>s[t]?.data?.connected),[o,s]);(0,y.useEffect)(()=>{let n=c.some(t=>t.id===e);(!e||!n)&&c.length>0&&t(c[0].id)},[c,e,t]);let{data:l}=K({queryKey:[`settings`],queryFn:Z.getSettings});return(0,y.useEffect)(()=>{let e=setInterval(()=>a(new Date),1e3);return()=>clearInterval(e)},[]),(0,G.jsxs)(`div`,{className:`h-12 bg-bambu-dark-secondary border-b border-bambu-dark-tertiary flex items-center px-3 gap-4 shrink-0`,children:[(0,G.jsx)(`div`,{className:`flex items-center shrink-0`,children:(0,G.jsx)(`img`,{src:`/img/spoolbuddy_logo_dark_small.png`,alt:`SpoolBuddy`,width:113,height:28,className:`h-7 w-auto`})}),(0,G.jsx)(`div`,{className:`flex-1 flex justify-center`,children:(0,G.jsx)(`select`,{value:e??``,onChange:e=>t(Number(e.target.value)),className:`bg-bambu-dark text-white text-base px-4 py-2 rounded border border-bambu-dark-tertiary focus:outline-none focus:border-bambu-green min-w-[180px]`,children:c.length===0?(0,G.jsx)(`option`,{value:``,children:r(`spoolbuddy.status.noPrinters`,`No printers online`)}):c.map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.name},e.id))})}),(0,G.jsxs)(`div`,{className:`flex items-center gap-3 shrink-0`,children:[(0,G.jsx)(`div`,{className:`flex items-center`,title:n?r(`spoolbuddy.status.backend`,`Backend`):r(`spoolbuddy.status.offline`,`Offline`),children:n?(0,G.jsx)(`div`,{className:`flex items-end gap-0.5 h-4`,children:[1,2,3,4].map(e=>(0,G.jsx)(`div`,{className:`w-1 rounded-sm ${e<=4?`bg-white`:`bg-bambu-dark-tertiary`}`,style:{height:`${e*4}px`}},e))}):(0,G.jsx)(Zu,{className:`w-5 h-5 text-red-400`})}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,G.jsx)(`div`,{className:`w-3 h-3 rounded-full ${n?`bg-bambu-green shadow-[0_0_6px_rgba(34,197,94,0.5)]`:`bg-bambu-gray`}`}),(0,G.jsx)(`span`,{className:`text-sm text-white/50`,children:n?r(`spoolbuddy.status.backend`,`Backend`):r(`spoolbuddy.status.offline`,`Offline`)})]}),(0,G.jsx)(`span`,{className:`text-white/50 text-base font-mono min-w-[50px] text-right`,children:sp(i,l?.time_format||`system`)})]})]})}var A0e=[{to:`/spoolbuddy`,labelKey:`spoolbuddy.nav.dashboard`,fallback:`Dashboard`,icon:(0,G.jsx)(`svg`,{className:`w-6 h-6`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M3 12l2-2m0 0l7-7 7 7M5 10v10a1 1 0 001 1h3m10-11l2 2m-2-2v10a1 1 0 01-1 1h-3m-6 0a1 1 0 001-1v-4a1 1 0 011-1h2a1 1 0 011 1v4a1 1 0 001 1m-6 0h6`})})},{to:`/spoolbuddy/ams`,labelKey:`spoolbuddy.nav.ams`,fallback:`AMS`,icon:(0,G.jsx)(`svg`,{className:`w-6 h-6`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10`})})},{to:`/spoolbuddy/write-tag`,labelKey:`spoolbuddy.nav.writeTag`,fallback:`Write`,icon:(0,G.jsxs)(`svg`,{className:`w-6 h-6`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:2,children:[(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M8.288 15.038a5.25 5.25 0 017.424 0M5.106 11.856c3.807-3.808 9.98-3.808 13.788 0M1.924 8.674c5.565-5.565 14.587-5.565 20.152 0`}),(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M12.53 18.22l-.53.53-.53-.53a.75.75 0 011.06 0z`})]})},{to:`/spoolbuddy/inventory`,labelKey:`spoolbuddy.nav.inventory`,fallback:`Inventory`,icon:(0,G.jsx)(`svg`,{className:`w-6 h-6`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M20 7l-8-4-8 4m16 0l-8 4m8-4v10l-8 4m0-10L4 7m8 4v10M4 7v10l8 4`})})},{to:`/spoolbuddy/settings`,labelKey:`spoolbuddy.nav.settings`,fallback:`Settings`,icon:(0,G.jsxs)(`svg`,{className:`w-6 h-6`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:[(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.066 2.573c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.573 1.066c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.066-2.573c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z`}),(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M15 12a3 3 0 11-6 0 3 3 0 016 0z`})]})}];function j0e(){let{t:e}=U();return(0,G.jsx)(`nav`,{className:`h-14 bg-bambu-dark-secondary border-t border-bambu-dark-tertiary flex items-stretch shrink-0`,children:A0e.map(t=>(0,G.jsxs)(ji,{to:t.to,end:t.to===`/spoolbuddy`,className:({isActive:e})=>`flex-1 flex flex-col items-center justify-center gap-1 transition-colors ${e?`text-bambu-green bg-bambu-dark`:`text-white/50 hover:text-white/70 hover:bg-bambu-dark-tertiary`}`,children:[t.icon,(0,G.jsx)(`span`,{className:`text-xs font-medium`,children:e(t.labelKey,t.fallback)})]},t.to))})}function M0e({alert:e}){let{t}=U(),n=e?e.type===`error`?`bg-red-500`:e.type===`warning`?`bg-amber-500`:`bg-bambu-green`:`bg-bambu-green`;return(0,G.jsxs)(`div`,{className:`h-9 bg-bambu-dark-secondary border-t-2 ${e?e.type===`error`?`border-red-500`:e.type===`warning`?`border-amber-500`:`border-bambu-dark-tertiary`:`border-bambu-dark-tertiary`} flex items-center px-3 gap-3 shrink-0`,children:[(0,G.jsx)(`div`,{className:`w-3.5 h-3.5 rounded-full ${n}`}),(0,G.jsx)(`div`,{className:`flex-1 text-sm text-white/50 truncate`,children:e?(0,G.jsx)(`span`,{children:e.message}):(0,G.jsx)(`span`,{className:`text-bambu-green`,children:t(`spoolbuddy.status.systemReady`,`System Ready`)})})]})}function N0e({isOpen:e,onClose:t,deviceId:n,deviceOnline:r}){let{t:i}=U(),[a,o]=(0,y.useState)(null),[s,c]=(0,y.useState)(!1),[l,u]=(0,y.useState)(new Map),{data:d=[]}=K({queryKey:[`printers`],queryFn:()=>Z.getPrinters(),enabled:e}),{data:f=[]}=K({queryKey:[`smart-plugs`],queryFn:()=>Z.getSmartPlugs(),enabled:e}),p=d.map(e=>{let t=f.find(t=>t.printer_id===e.id&&t.plug_type!==`mqtt`&&t.enabled);if(!t)return null;let n=l.get(t.id);return{plug:t,printer:e,status:n?{state:n.state,reachable:!0,device_name:null,energy:null}:null,loading:n?.loading??!1}}).filter(Boolean);(0,y.useEffect)(()=>{!e||f.length===0||f.filter(e=>e.printer_id!==null&&e.plug_type!==`mqtt`&&e.enabled).forEach(async e=>{try{let t=await Z.getSmartPlugStatus(e.id);u(n=>{let r=new Map(n);return r.set(e.id,{loading:!1,state:t.state}),r})}catch{u(t=>{let n=new Map(t);return n.set(e.id,{loading:!1,state:null}),n})}})},[e,f]),(0,y.useEffect)(()=>{e||(o(null),c(!1))},[e]);let m=(0,y.useCallback)(async e=>{u(t=>{let n=new Map(t),r=n.get(e.id);return n.set(e.id,{loading:!0,state:r?.state??null}),n});try{await Z.controlSmartPlug(e.id,`toggle`);let t=await Z.getSmartPlugStatus(e.id);u(n=>{let r=new Map(n);return r.set(e.id,{loading:!1,state:t.state}),r})}catch{u(t=>{let n=new Map(t),r=n.get(e.id);return n.set(e.id,{loading:!1,state:r?.state??null}),n})}},[]),h=(0,y.useCallback)(async e=>{if(n){c(!0);try{await Od.systemCommand(n,e),setTimeout(()=>t(),500)}catch{c(!1)}}},[n,t]),g=(0,y.useCallback)(()=>{a&&(a.type===`system`?h(a.command):m(a.plug),o(null))},[a,h,m]);if(!e)return null;let _=e=>e===`ON`||e===`on`;return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`fixed inset-0 z-40 bg-black/50`,onPointerDown:t}),(0,G.jsxs)(`div`,{className:`fixed top-0 left-0 right-0 z-50 bg-bambu-dark-secondary border-b border-bambu-dark-tertiary rounded-b-2xl shadow-2xl animate-slide-down`,children:[(0,G.jsx)(`div`,{className:`flex justify-center pt-2 pb-1`,children:(0,G.jsx)(`div`,{className:`w-10 h-1 rounded-full bg-zinc-600`})}),(0,G.jsxs)(`div`,{className:`px-4 pb-4 max-h-[80vh] overflow-y-auto`,children:[p.length>0&&(0,G.jsxs)(`div`,{className:`mb-4`,children:[(0,G.jsx)(`h3`,{className:`text-xs font-semibold text-zinc-500 uppercase tracking-wide mb-2`,children:i(`spoolbuddy.quickMenu.printerPower`,`Printer Power`)}),(0,G.jsx)(`div`,{className:`space-y-1`,children:p.map(({plug:e,printer:t,loading:n})=>{let r=l.get(e.id),i=_(r?.state??null);return(0,G.jsxs)(`button`,{onClick:()=>o({type:`plug`,plug:e,printer:t,currentState:r?.state??null}),disabled:n,className:`w-full flex items-center gap-2 px-3 py-1.5 rounded-lg bg-zinc-800/60 hover:bg-zinc-700/60 transition-colors min-h-[36px]`,children:[(0,G.jsx)(`div`,{className:`w-2 h-2 rounded-full shrink-0 ${i?`bg-green-500`:`bg-zinc-600`}`}),n&&(0,G.jsx)(Y,{className:`w-3 h-3 animate-spin text-zinc-400 shrink-0`}),(0,G.jsx)(`span`,{className:`flex-1 text-sm text-zinc-200 text-left truncate`,children:t.name}),(0,G.jsx)(`span`,{className:`text-xs font-medium ${i?`text-green-400`:`text-zinc-500`}`,children:r?.state??`—`})]},e.id)})})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`text-xs font-semibold text-zinc-500 uppercase tracking-wide mb-2`,children:i(`spoolbuddy.quickMenu.systemControls`,`System`)}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,G.jsx)(V9,{icon:(0,G.jsx)(Gl,{className:`w-4 h-4`}),label:i(`spoolbuddy.quickMenu.restartDaemon`,`Restart Daemon`),onClick:()=>o({type:`system`,command:`restart_daemon`}),disabled:!n||!r||s}),(0,G.jsx)(V9,{icon:(0,G.jsx)(gl,{className:`w-4 h-4`}),label:i(`spoolbuddy.quickMenu.restartBrowser`,`Restart Browser`),onClick:()=>o({type:`system`,command:`restart_browser`}),disabled:!n||!r||s}),(0,G.jsx)(V9,{icon:(0,G.jsx)(Gl,{className:`w-4 h-4`}),label:i(`spoolbuddy.quickMenu.reboot`,`Reboot`),onClick:()=>o({type:`system`,command:`reboot`}),disabled:!n||!r||s,variant:`warning`}),(0,G.jsx)(V9,{icon:(0,G.jsx)(Il,{className:`w-4 h-4`}),label:i(`spoolbuddy.quickMenu.shutdown`,`Shutdown`),onClick:()=>o({type:`system`,command:`shutdown`}),disabled:!n||!r||s,variant:`danger`})]})]}),(0,G.jsx)(`div`,{className:`flex justify-center mt-3`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-1 text-xs text-zinc-600`,children:[(0,G.jsx)(ps,{className:`w-3 h-3`}),(0,G.jsx)(`span`,{children:i(`spoolbuddy.quickMenu.swipeToClose`,`Swipe down to close`)})]})})]})]}),a&&(0,G.jsx)(`div`,{className:`fixed inset-0 z-[60] flex items-center justify-center bg-black/60`,children:(0,G.jsxs)(`div`,{className:`bg-zinc-800 rounded-2xl p-5 mx-4 max-w-sm w-full border border-zinc-700`,children:[(0,G.jsx)(`h3`,{className:`text-lg font-semibold text-zinc-100 mb-2`,children:i(`spoolbuddy.quickMenu.confirmTitle`,`Confirm`)}),(0,G.jsx)(`p`,{className:`text-sm text-zinc-400 mb-5`,children:a.type===`plug`?_(a.currentState)?i(`spoolbuddy.quickMenu.confirmPlugOff`,`Turn off {{name}}?`,{name:a.printer.name}):i(`spoolbuddy.quickMenu.confirmPlugOn`,`Turn on {{name}}?`,{name:a.printer.name}):a.command===`shutdown`?i(`spoolbuddy.quickMenu.confirmShutdown`,`Are you sure you want to shut down the SpoolBuddy? You will need physical access to turn it back on.`):a.command===`reboot`?i(`spoolbuddy.quickMenu.confirmReboot`,`Are you sure you want to reboot the SpoolBuddy?`):a.command===`restart_daemon`?i(`spoolbuddy.quickMenu.confirmRestartDaemon`,`Restart the SpoolBuddy daemon? NFC and scale will be temporarily unavailable.`):i(`spoolbuddy.quickMenu.confirmRestartBrowser`,`Restart the kiosk browser? The display will briefly go blank.`)}),(0,G.jsxs)(`div`,{className:`flex gap-3`,children:[(0,G.jsx)(`button`,{onClick:()=>o(null),className:`flex-1 px-4 py-2.5 rounded-lg text-sm font-medium bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors min-h-[44px]`,children:i(`common.cancel`,`Cancel`)}),(0,G.jsx)(`button`,{onClick:g,disabled:s,className:`flex-1 px-4 py-2.5 rounded-lg text-sm font-medium text-white transition-colors min-h-[44px] ${a.type===`plug`?_(a.currentState)?`bg-red-600 hover:bg-red-700`:`bg-green-600 hover:bg-green-700`:a.command===`shutdown`?`bg-red-600 hover:bg-red-700`:a.command===`reboot`?`bg-amber-600 hover:bg-amber-700`:`bg-blue-600 hover:bg-blue-700`} disabled:opacity-50`,children:s?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin mx-auto`}):a.type===`plug`?_(a.currentState)?i(`spoolbuddy.quickMenu.turnOff`,`Turn Off`):i(`spoolbuddy.quickMenu.turnOn`,`Turn On`):i(`spoolbuddy.quickMenu.confirm`,`Confirm`)})]})]})})]})}function V9({icon:e,label:t,onClick:n,disabled:r,variant:i=`default`}){return(0,G.jsxs)(`button`,{onClick:n,disabled:r,className:`flex items-center gap-2.5 p-3 rounded-xl transition-colors min-h-[48px] disabled:opacity-40 ${{default:`bg-zinc-800/60 hover:bg-zinc-700/60 text-zinc-300`,warning:`bg-amber-900/30 hover:bg-amber-900/50 text-amber-400`,danger:`bg-red-900/30 hover:bg-red-900/50 text-red-400`}[i]}`,children:[e,(0,G.jsx)(`span`,{className:`text-sm font-medium`,children:t})]})}var P0e={weight:null,weightStable:!1,rawAdc:null,matchedSpool:null,unknownTagUid:null,unknownTrayUuid:null,deviceOnline:!1,deviceId:null};function F0e(e,t){switch(t.type){case`WEIGHT_UPDATE`:return{...e,weight:t.weight,weightStable:t.stable,rawAdc:t.rawAdc,deviceId:t.deviceId,deviceOnline:!0};case`TAG_MATCHED`:return{...e,matchedSpool:t.spool,unknownTagUid:null,unknownTrayUuid:null,deviceId:t.deviceId};case`UNKNOWN_TAG`:return{...e,matchedSpool:null,unknownTagUid:t.tagUid,unknownTrayUuid:t.trayUuid??null,deviceId:t.deviceId};case`TAG_REMOVED`:return{...e,matchedSpool:null,unknownTagUid:null,unknownTrayUuid:null};case`DEVICE_ONLINE`:return{...e,deviceOnline:!0,deviceId:t.deviceId};case`DEVICE_OFFLINE`:return{...e,deviceOnline:!1,weight:null,weightStable:!1,rawAdc:null};default:return e}}function I0e(){let[e,t]=(0,y.useReducer)(F0e,P0e),n=(0,y.useCallback)(e=>{let n=e.detail;t({type:`WEIGHT_UPDATE`,weight:n.weight_grams??n.data?.weight_grams,stable:n.stable??n.data?.stable??!1,rawAdc:n.raw_adc??n.data?.raw_adc??null,deviceId:n.device_id??n.data?.device_id??``})},[]),r=(0,y.useCallback)(e=>{let n=e.detail,r=n.spool??n.data?.spool;r&&t({type:`TAG_MATCHED`,spool:{id:r.id,tag_uid:n.tag_uid??n.data?.tag_uid??``,material:r.material??``,subtype:r.subtype??null,color_name:r.color_name??null,rgba:r.rgba??null,brand:r.brand??null,label_weight:r.label_weight??0,core_weight:r.core_weight??0,weight_used:r.weight_used??0},deviceId:n.device_id??n.data?.device_id??``})},[]),i=(0,y.useCallback)(e=>{let n=e.detail;t({type:`UNKNOWN_TAG`,tagUid:n.tag_uid??n.data?.tag_uid??``,trayUuid:n.tray_uuid??n.data?.tray_uuid??null,deviceId:n.device_id??n.data?.device_id??``})},[]),a=(0,y.useCallback)(e=>{let n=e.detail;t({type:`TAG_REMOVED`,deviceId:n.device_id??n.data?.device_id??``})},[]),o=(0,y.useCallback)(e=>{let n=e.detail;t({type:`DEVICE_ONLINE`,deviceId:n.device_id??n.data?.device_id??``})},[]),s=(0,y.useCallback)(e=>{let n=e.detail;t({type:`DEVICE_OFFLINE`,deviceId:n.device_id??n.data?.device_id??``})},[]);(0,y.useEffect)(()=>(window.addEventListener(`spoolbuddy-weight`,n),window.addEventListener(`spoolbuddy-tag-matched`,r),window.addEventListener(`spoolbuddy-unknown-tag`,i),window.addEventListener(`spoolbuddy-tag-removed`,a),window.addEventListener(`spoolbuddy-online`,o),window.addEventListener(`spoolbuddy-offline`,s),()=>{window.removeEventListener(`spoolbuddy-weight`,n),window.removeEventListener(`spoolbuddy-tag-matched`,r),window.removeEventListener(`spoolbuddy-unknown-tag`,i),window.removeEventListener(`spoolbuddy-tag-removed`,a),window.removeEventListener(`spoolbuddy-online`,o),window.removeEventListener(`spoolbuddy-offline`,s)}),[n,r,i,a,o,s]);let c=e.matchedSpool?Math.max(0,e.matchedSpool.label_weight-e.matchedSpool.weight_used):null,l=e.weight!==null&&e.matchedSpool?Math.max(0,e.weight-e.matchedSpool.core_weight):null;return{...e,remainingWeight:c,netWeight:l}}var L0e=l(o(((e,t)=>{(function(n,r){typeof e==`object`&&typeof t==`object`?t.exports=r(f()):typeof define==`function`&&define.amd?define([`react`],r):typeof e==`object`?e.ReactSimpleKeyboard=r(f()):n.ReactSimpleKeyboard=r(n.React)})(e,(function(e){return function(){var t={981:function(){typeof Element>`u`||`remove`in Element.prototype||(Element.prototype.remove=function(){this.parentNode&&this.parentNode.removeChild(this)}),typeof self<`u`&&`document`in self&&((!(`classList`in document.createElement(`_`))||document.createElementNS&&!(`classList`in document.createElementNS(`http://www.w3.org/2000/svg`,`g`)))&&function(e){if(`Element`in e){var t=`classList`,n=`prototype`,r=e.Element[n],i=Object,a=String[n].trim||function(){return this.replace(/^\s+|\s+$/g,``)},o=Array[n].indexOf||function(e){for(var t=0,n=this.length;t1?arguments[1]:void 0)}},7916:function(e,t,n){var r=n(6080),i=n(9565),a=n(8981),o=n(6319),s=n(4209),c=n(3517),l=n(6198),u=n(4659),d=n(4527),f=n(81),p=n(851),m=Array;e.exports=function(e){var t=a(e),n=c(this),h=arguments.length,g=h>1?arguments[1]:void 0,_=g!==void 0;_&&(g=r(g,h>2?arguments[2]:void 0));var v,y,b,x,S,C,w=p(t),T=0;if(!w||this===m&&s(w))for(v=l(t),y=n?new this(v):m(v);v>T;T++)C=_?g(t[T],T):t[T],u(y,T,C);else for(y=n?new this:[],S=(x=f(t,w)).next;!(b=i(S,x)).done;T++)C=_?o(x,g,[b.value,T],!0):b.value,u(y,T,C);return d(y,T),y}},9617:function(e,t,n){var r=n(5397),i=n(5610),a=n(6198),o=function(e){return function(t,n,o){var s=r(t),c=a(s);if(c===0)return!e&&-1;var l,u=i(o,c);if(e&&n!=n){for(;c>u;)if((l=s[u++])!=l)return!0}else for(;c>u;u++)if((e||u in s)&&s[u]===n)return e||u||0;return!e&&-1}};e.exports={includes:o(!0),indexOf:o(!1)}},9213:function(e,t,n){var r=n(6080),i=n(7055),a=n(8981),o=n(6198),s=n(1469),c=n(4659),l=function(e){var t=e===1,n=e===2,l=e===3,u=e===4,d=e===6,f=e===7,p=e===5||d;return function(m,h,g){for(var _,v,y=a(m),b=i(y),x=o(b),S=r(h,g),C=0,w=0,T=t?s(m,x):n||f?s(m,0):void 0;x>C;C++)if((p||C in b)&&(v=S(_=b[C],C,y),e))if(t)c(T,C,v);else if(v)switch(e){case 3:return!0;case 5:return _;case 6:return C;case 2:c(T,w++,_)}else switch(e){case 4:return!1;case 7:c(T,w++,_)}return d?-1:l||u?u:T}};e.exports={forEach:l(0),map:l(1),filter:l(2),some:l(3),every:l(4),find:l(5),findIndex:l(6),filterReject:l(7)}},597:function(e,t,n){var r=n(9039),i=n(8227),a=n(9519),o=i(`species`);e.exports=function(e){return a>=51||!r((function(){var t=[];return(t.constructor={})[o]=function(){return{foo:1}},t[e](Boolean).foo!==1}))}},4598:function(e,t,n){var r=n(9039);e.exports=function(e,t){var n=[][e];return!!n&&r((function(){n.call(null,t||function(){return 1},1)}))}},926:function(e,t,n){var r=n(9306),i=n(8981),a=n(7055),o=n(6198),s=TypeError,c=`Reduce of empty array with no initial value`,l=function(e){return function(t,n,l,u){var d=i(t),f=a(d),p=o(d);if(r(n),p===0&&l<2)throw new s(c);var m=e?p-1:0,h=e?-1:1;if(l<2)for(;;){if(m in f){u=f[m],m+=h;break}if(m+=h,e?m<0:p<=m)throw new s(c)}for(;e?m>=0:p>m;m+=h)m in f&&(u=n(u,f[m],m,d));return u}};e.exports={left:l(!1),right:l(!0)}},4527:function(e,t,n){var r=n(3724),i=n(4376),a=TypeError,o=Object.getOwnPropertyDescriptor;e.exports=r&&!function(){if(this!==void 0)return!0;try{Object.defineProperty([],"length",{writable:!1}).length=1}catch(e){return e instanceof TypeError}}()?function(e,t){if(i(e)&&!o(e,`length`).writable)throw new a(`Cannot set read only .length`);return e.length=t}:function(e,t){return e.length=t}},7680:function(e,t,n){e.exports=n(9504)([].slice)},4488:function(e,t,n){var r=n(7680),i=Math.floor,a=function(e,t){var n=e.length;if(n<8)for(var o,s,c=1;c0;)e[s]=e[--s];s!==c++&&(e[s]=o)}else for(var l=i(n/2),u=a(r(e,0,l),t),d=a(r(e,l),t),f=u.length,p=d.length,m=0,h=0;m9007199254740991)throw t(`Maximum allowed index exceeded`);return e}},7400:function(e){e.exports={CSSRuleList:0,CSSStyleDeclaration:0,CSSValueList:0,ClientRectList:0,DOMRectList:0,DOMStringList:0,DOMTokenList:1,DataTransferItemList:0,FileList:0,HTMLAllCollection:0,HTMLCollection:0,HTMLFormElement:0,HTMLSelectElement:0,MediaList:0,MimeTypeArray:0,NamedNodeMap:0,NodeList:1,PaintRequestList:0,Plugin:0,PluginArray:0,SVGLengthList:0,SVGNumberList:0,SVGPathSegList:0,SVGPointList:0,SVGStringList:0,SVGTransformList:0,SourceBufferList:0,StyleSheetList:0,TextTrackCueList:0,TextTrackList:0,TouchList:0}},9296:function(e,t,n){var r=n(4055)(`span`).classList,i=r&&r.constructor&&r.constructor.prototype;e.exports=i===Object.prototype?void 0:i},8727:function(e){e.exports=[`constructor`,`hasOwnProperty`,`isPrototypeOf`,`propertyIsEnumerable`,`toLocaleString`,`toString`,`valueOf`]},3709:function(e,t,n){var r=n(2839).match(/firefox\/(\d+)/i);e.exports=!!r&&+r[1]},3763:function(e,t,n){var r=n(2839);e.exports=/MSIE|Trident/.test(r)},6193:function(e,t,n){e.exports=n(4215)===`NODE`},2839:function(e,t,n){var r=n(4576).navigator,i=r&&r.userAgent;e.exports=i?String(i):``},9519:function(e,t,n){var r,i,a=n(4576),o=n(2839),s=a.process,c=a.Deno,l=s&&s.versions||c&&c.version,u=l&&l.v8;u&&(i=(r=u.split(`.`))[0]>0&&r[0]<4?1:+(r[0]+r[1])),!i&&o&&(!(r=o.match(/Edge\/(\d+)/))||r[1]>=74)&&(r=o.match(/Chrome\/(\d+)/))&&(i=+r[1]),e.exports=i},3607:function(e,t,n){var r=n(2839).match(/AppleWebKit\/(\d+)\./);e.exports=!!r&&+r[1]},4215:function(e,t,n){var r=n(4576),i=n(2839),a=n(2195),o=function(e){return i.slice(0,e.length)===e};e.exports=o(`Bun/`)?`BUN`:o(`Cloudflare-Workers`)?`CLOUDFLARE`:o(`Deno/`)?`DENO`:o(`Node.js/`)?`NODE`:r.Bun&&typeof Bun.version==`string`?`BUN`:r.Deno&&typeof Deno.version==`object`?`DENO`:a(r.process)===`process`?`NODE`:r.window&&r.document?`BROWSER`:`REST`},6518:function(e,t,n){var r=n(4576),i=n(7347).f,a=n(6699),o=n(6840),s=n(9433),c=n(7740),l=n(2796);e.exports=function(e,t){var n,u,d,f,p,m=e.target,h=e.global,g=e.stat;if(n=h?r:g?r[m]||s(m,{}):r[m]&&r[m].prototype)for(u in t){if(f=t[u],d=e.dontCallGetSet?(p=i(n,u))&&p.value:n[u],!l(h?u:m+(g?`.`:`#`)+u,e.forced)&&d!==void 0){if(typeof f==typeof d)continue;c(f,d)}(e.sham||d&&d.sham)&&a(f,`sham`,!0),o(n,u,f,e)}}},9039:function(e){e.exports=function(e){try{return!!e()}catch{return!0}}},9228:function(e,t,n){n(7495);var r=n(9565),i=n(6840),a=n(7323),o=n(9039),s=n(8227),c=n(6699),l=s(`species`),u=RegExp.prototype;e.exports=function(e,t,n,d){var f=s(e),p=!o((function(){var t={};return t[f]=function(){return 7},``[e](t)!==7})),m=p&&!o((function(){var t=!1,n=/a/;if(e===`split`){var r={};r[l]=function(){return n},(n={constructor:r,flags:``})[f]=/./[f]}return n.exec=function(){return t=!0,null},n[f](``),!t}));if(!p||!m||n){var h=/./[f],g=t(f,``[e],(function(e,t,n,i,o){var s=t.exec;return s===a||s===u.exec?p&&!o?{done:!0,value:r(h,t,n,i)}:{done:!0,value:r(e,n,t,i)}:{done:!1}}));i(String.prototype,e,g[0]),i(u,f,g[1])}d&&c(u[f],`sham`,!0)}},8745:function(e,t,n){var r=n(616),i=Function.prototype,a=i.apply,o=i.call;e.exports=typeof Reflect==`object`&&Reflect.apply||(r?o.bind(a):function(){return o.apply(a,arguments)})},6080:function(e,t,n){var r=n(7476),i=n(9306),a=n(616),o=r(r.bind);e.exports=function(e,t){return i(e),t===void 0?e:a?o(e,t):function(){return e.apply(t,arguments)}}},616:function(e,t,n){e.exports=!n(9039)((function(){var e=function(){}.bind();return typeof e!=`function`||e.hasOwnProperty(`prototype`)}))},566:function(e,t,n){var r=n(9504),i=n(9306),a=n(34),o=n(9297),s=n(7680),c=n(616),l=Function,u=r([].concat),d=r([].join),f={};e.exports=c?l.bind:function(e){var t=i(this),n=t.prototype,r=s(arguments,1),c=function(){var n=u(r,s(arguments));return this instanceof c?function(e,t,n){if(!o(f,t)){for(var r=[],i=0;i]*>)/g,u=/\$([$&'`]|\d{1,2})/g;e.exports=function(e,t,n,r,d,f){var p=n+e.length,m=r.length,h=u;return d!==void 0&&(d=i(d),h=l),s(f,h,(function(i,s){var l;switch(o(s,0)){case`$`:return`$`;case`&`:return e;case"`":return c(t,0,n);case`'`:return c(t,p);case`<`:l=d[c(s,1,-1)];break;default:var u=+s;if(u===0)return i;if(u>m){var f=a(u/10);return f===0?i:f<=m?r[f-1]===void 0?o(s,1):r[f-1]+o(s,1):i}l=r[u-1]}return l===void 0?``:l}))}},4576:function(e,t,n){var r=function(e){return e&&e.Math===Math&&e};e.exports=r(typeof globalThis==`object`&&globalThis)||r(typeof window==`object`&&window)||r(typeof self==`object`&&self)||r(typeof n.g==`object`&&n.g)||r(typeof this==`object`&&this)||function(){return this}()||Function(`return this`)()},9297:function(e,t,n){var r=n(9504),i=n(8981),a=r({}.hasOwnProperty);e.exports=Object.hasOwn||function(e,t){return a(i(e),t)}},421:function(e){e.exports={}},397:function(e,t,n){e.exports=n(7751)(`document`,`documentElement`)},5917:function(e,t,n){var r=n(3724),i=n(9039),a=n(4055);e.exports=!r&&!i((function(){return Object.defineProperty(a(`div`),"a",{get:function(){return 7}}).a!==7}))},7055:function(e,t,n){var r=n(9504),i=n(9039),a=n(2195),o=Object,s=r(``.split);e.exports=i((function(){return!o(`z`).propertyIsEnumerable(0)}))?function(e){return a(e)===`String`?s(e,``):o(e)}:o},3167:function(e,t,n){var r=n(4901),i=n(34),a=n(2967);e.exports=function(e,t,n){var o,s;return a&&r(o=t.constructor)&&o!==n&&i(s=o.prototype)&&s!==n.prototype&&a(e,s),e}},3706:function(e,t,n){var r=n(9504),i=n(4901),a=n(7629),o=r(Function.toString);i(a.inspectSource)||(a.inspectSource=function(e){return o(e)}),e.exports=a.inspectSource},1181:function(e,t,n){var r,i,a,o=n(8622),s=n(4576),c=n(34),l=n(6699),u=n(9297),d=n(7629),f=n(6119),p=n(421),m=`Object already initialized`,h=s.TypeError,g=s.WeakMap;if(o||d.state){var _=d.state||=new g;_.get=_.get,_.has=_.has,_.set=_.set,r=function(e,t){if(_.has(e))throw new h(m);return t.facade=e,_.set(e,t),t},i=function(e){return _.get(e)||{}},a=function(e){return _.has(e)}}else{var v=f(`state`);p[v]=!0,r=function(e,t){if(u(e,v))throw new h(m);return t.facade=e,l(e,v,t),t},i=function(e){return u(e,v)?e[v]:{}},a=function(e){return u(e,v)}}e.exports={set:r,get:i,has:a,enforce:function(e){return a(e)?i(e):r(e,{})},getterFor:function(e){return function(t){var n;if(!c(t)||(n=i(t)).type!==e)throw new h(`Incompatible receiver, `+e+` required`);return n}}}},4209:function(e,t,n){var r=n(8227),i=n(6269),a=r(`iterator`),o=Array.prototype;e.exports=function(e){return e!==void 0&&(i.Array===e||o[a]===e)}},4376:function(e,t,n){var r=n(2195);e.exports=Array.isArray||function(e){return r(e)===`Array`}},4901:function(e){var t=typeof document==`object`&&document.all;e.exports=t===void 0&&t!==void 0?function(e){return typeof e==`function`||e===t}:function(e){return typeof e==`function`}},3517:function(e,t,n){var r=n(9504),i=n(9039),a=n(4901),o=n(6955),s=n(7751),c=n(3706),l=function(){},u=s(`Reflect`,`construct`),d=/^\s*(?:class|function)\b/,f=r(d.exec),p=!d.test(l),m=function(e){if(!a(e))return!1;try{return u(l,[],e),!0}catch{return!1}},h=function(e){if(!a(e))return!1;switch(o(e)){case`AsyncFunction`:case`GeneratorFunction`:case`AsyncGeneratorFunction`:return!1}try{return p||!!f(d,c(e))}catch{return!0}};h.sham=!0,e.exports=!u||i((function(){var e;return m(m.call)||!m(Object)||!m((function(){e=!0}))||e}))?h:m},2796:function(e,t,n){var r=n(9039),i=n(4901),a=/#|\.prototype\./,o=function(e,t){var n=c[s(e)];return n===u||n!==l&&(i(t)?r(t):!!t)},s=o.normalize=function(e){return String(e).replace(a,`.`).toLowerCase()},c=o.data={},l=o.NATIVE=`N`,u=o.POLYFILL=`P`;e.exports=o},2087:function(e,t,n){var r=n(34),i=Math.floor;e.exports=Number.isInteger||function(e){return!r(e)&&isFinite(e)&&i(e)===e}},4117:function(e){e.exports=function(e){return e==null}},34:function(e,t,n){var r=n(4901);e.exports=function(e){return typeof e==`object`?e!==null:r(e)}},3925:function(e,t,n){var r=n(34);e.exports=function(e){return r(e)||e===null}},6395:function(e){e.exports=!1},5810:function(e,t,n){var r=n(34),i=n(1181).get;e.exports=function(e){if(!r(e))return!1;var t=i(e);return!!t&&t.type===`RawJSON`}},788:function(e,t,n){var r=n(34),i=n(2195),a=n(8227)(`match`);e.exports=function(e){var t;return r(e)&&((t=e[a])===void 0?i(e)===`RegExp`:!!t)}},757:function(e,t,n){var r=n(7751),i=n(4901),a=n(1625),o=n(7040),s=Object;e.exports=o?function(e){return typeof e==`symbol`}:function(e){var t=r(`Symbol`);return i(t)&&a(t.prototype,s(e))}},9539:function(e,t,n){var r=n(9565),i=n(8551),a=n(5966);e.exports=function(e,t,n){var o,s;i(e);try{if(!(o=a(e,`return`))){if(t===`throw`)throw n;return n}o=r(o,e)}catch(e){s=!0,o=e}if(t===`throw`)throw n;if(s)throw o;return i(o),n}},3994:function(e,t,n){var r=n(7657).IteratorPrototype,i=n(2360),a=n(6980),o=n(687),s=n(6269),c=function(){return this};e.exports=function(e,t,n,l){var u=t+` Iterator`;return e.prototype=i(r,{next:a(+!l,n)}),o(e,u,!1,!0),s[u]=c,e}},1088:function(e,t,n){var r=n(6518),i=n(9565),a=n(6395),o=n(350),s=n(4901),c=n(3994),l=n(2787),u=n(2967),d=n(687),f=n(6699),p=n(6840),m=n(8227),h=n(6269),g=n(7657),_=o.PROPER,v=o.CONFIGURABLE,y=g.IteratorPrototype,b=g.BUGGY_SAFARI_ITERATORS,x=m(`iterator`),S=`keys`,C=`values`,w=`entries`,T=function(){return this};e.exports=function(e,t,n,o,m,g,E){c(n,t,o);var D,O,k,A=function(e){if(e===m&&F)return F;if(!b&&e&&e in N)return N[e];switch(e){case S:case C:case w:return function(){return new n(this,e)}}return function(){return new n(this)}},j=t+` Iterator`,M=!1,N=e.prototype,P=N[x]||N[`@@iterator`]||m&&N[m],F=!b&&P||A(m),I=t===`Array`&&N.entries||P;if(I&&(D=l(I.call(new e)))!==Object.prototype&&D.next&&(a||l(D)===y||(u?u(D,y):s(D[x])||p(D,x,T)),d(D,j,!0,!0),a&&(h[j]=T)),_&&m===C&&P&&P.name!==C&&(!a&&v?f(N,`name`,C):(M=!0,F=function(){return i(P,this)})),m)if(O={values:A(C),keys:g?F:A(S),entries:A(w)},E)for(k in O)(b||M||!(k in N))&&p(N,k,O[k]);else r({target:t,proto:!0,forced:b||M},O);return a&&!E||N[x]===F||p(N,x,F,{name:m}),h[t]=F,O}},7657:function(e,t,n){var r,i,a,o=n(9039),s=n(4901),c=n(34),l=n(2360),u=n(2787),d=n(6840),f=n(8227),p=n(6395),m=f(`iterator`),h=!1;[].keys&&(`next`in(a=[].keys())?(i=u(u(a)))!==Object.prototype&&(r=i):h=!0),!c(r)||o((function(){var e={};return r[m].call(e)!==e}))?r={}:p&&(r=l(r)),s(r[m])||d(r,m,(function(){return this})),e.exports={IteratorPrototype:r,BUGGY_SAFARI_ITERATORS:h}},6269:function(e){e.exports={}},6198:function(e,t,n){var r=n(8014);e.exports=function(e){return r(e.length)}},283:function(e,t,n){var r=n(9504),i=n(9039),a=n(4901),o=n(9297),s=n(3724),c=n(350).CONFIGURABLE,l=n(3706),u=n(1181),d=u.enforce,f=u.get,p=String,m=Object.defineProperty,h=r(``.slice),g=r(``.replace),_=r([].join),v=s&&!i((function(){return m((function(){}),`length`,{value:8}).length!==8})),y=String(String).split(`String`),b=e.exports=function(e,t,n){h(p(t),0,7)===`Symbol(`&&(t=`[`+g(p(t),/^Symbol\(([^)]*)\).*$/,`$1`)+`]`),n&&n.getter&&(t=`get `+t),n&&n.setter&&(t=`set `+t),(!o(e,`name`)||c&&e.name!==t)&&(s?m(e,`name`,{value:t,configurable:!0}):e.name=t),v&&n&&o(n,`arity`)&&e.length!==n.arity&&m(e,`length`,{value:n.arity});try{n&&o(n,`constructor`)&&n.constructor?s&&m(e,`prototype`,{writable:!1}):e.prototype&&=void 0}catch{}var r=d(e);return o(r,`source`)||(r.source=_(y,typeof t==`string`?t:``)),e};Function.prototype.toString=b((function(){return a(this)&&f(this).source||l(this)}),`toString`)},741:function(e){var t=Math.ceil,n=Math.floor;e.exports=Math.trunc||function(e){var r=+e;return(r>0?n:t)(r)}},7819:function(e,t,n){e.exports=!n(9039)((function(){var e=`9007199254740993`,t=JSON.rawJSON(e);return!JSON.isRawJSON(t)||JSON.stringify(t)!==e}))},5749:function(e,t,n){var r=n(788),i=TypeError;e.exports=function(e){if(r(e))throw new i(`The method doesn't accept regular expressions`);return e}},4213:function(e,t,n){var r=n(3724),i=n(9504),a=n(9565),o=n(9039),s=n(1072),c=n(3717),l=n(8773),u=n(8981),d=n(7055),f=Object.assign,p=Object.defineProperty,m=i([].concat);e.exports=!f||o((function(){if(r&&f({b:1},f(p({},`a`,{enumerable:!0,get:function(){p(this,`b`,{value:3,enumerable:!1})}}),{b:2})).b!==1)return!0;var e={},t={},n=Symbol(`assign detection`),i=`abcdefghijklmnopqrst`;return e[n]=7,i.split(``).forEach((function(e){t[e]=e})),f({},e)[n]!==7||s(f({},t)).join(``)!==i}))?function(e,t){for(var n=u(e),i=arguments.length,o=1,f=c.f,p=l.f;i>o;)for(var h,g=d(arguments[o++]),_=f?m(s(g),f(g)):s(g),v=_.length,y=0;v>y;)h=_[y++],r&&!a(p,g,h)||(n[h]=g[h]);return n}:f},2360:function(e,t,n){var r,i=n(8551),a=n(6801),o=n(8727),s=n(421),c=n(397),l=n(4055),u=n(6119),d=`prototype`,f=`script`,p=u(`IE_PROTO`),m=function(){},h=function(e){return`<`+f+`>`+e+``},g=function(e){e.write(h(``)),e.close();var t=e.parentWindow.Object;return e=null,t},_=function(){try{r=new ActiveXObject(`htmlfile`)}catch{}var e,t,n;_=typeof document<`u`?document.domain&&r?g(r):(t=l(`iframe`),n=`java`+f+`:`,t.style.display=`none`,c.appendChild(t),t.src=String(n),(e=t.contentWindow.document).open(),e.write(h(`document.F=Object`)),e.close(),e.F):g(r);for(var i=o.length;i--;)delete _[d][o[i]];return _()};s[p]=!0,e.exports=Object.create||function(e,t){var n;return e===null?n=_():(m[d]=i(e),n=new m,m[d]=null,n[p]=e),t===void 0?n:a.f(n,t)}},6801:function(e,t,n){var r=n(3724),i=n(8686),a=n(4913),o=n(8551),s=n(5397),c=n(1072);t.f=r&&!i?Object.defineProperties:function(e,t){o(e);for(var n,r=s(t),i=c(t),l=i.length,u=0;l>u;)a.f(e,n=i[u++],r[n]);return e}},4913:function(e,t,n){var r=n(3724),i=n(5917),a=n(8686),o=n(8551),s=n(6969),c=TypeError,l=Object.defineProperty,u=Object.getOwnPropertyDescriptor,d=`enumerable`,f=`configurable`,p=`writable`;t.f=r?a?function(e,t,n){if(o(e),t=s(t),o(n),typeof e==`function`&&t===`prototype`&&`value`in n&&p in n&&!n[p]){var r=u(e,t);r&&r[p]&&(e[t]=n.value,n={configurable:f in n?n[f]:r[f],enumerable:d in n?n[d]:r[d],writable:!1})}return l(e,t,n)}:l:function(e,t,n){if(o(e),t=s(t),o(n),i)try{return l(e,t,n)}catch{}if(`get`in n||`set`in n)throw new c(`Accessors not supported`);return`value`in n&&(e[t]=n.value),e}},7347:function(e,t,n){var r=n(3724),i=n(9565),a=n(8773),o=n(6980),s=n(5397),c=n(6969),l=n(9297),u=n(5917),d=Object.getOwnPropertyDescriptor;t.f=r?d:function(e,t){if(e=s(e),t=c(t),u)try{return d(e,t)}catch{}if(l(e,t))return o(!i(a.f,e,t),e[t])}},298:function(e,t,n){var r=n(2195),i=n(5397),a=n(8480).f,o=n(7680),s=typeof window==`object`&&window&&Object.getOwnPropertyNames?Object.getOwnPropertyNames(window):[];e.exports.f=function(e){return s&&r(e)===`Window`?function(e){try{return a(e)}catch{return o(s)}}(e):a(i(e))}},8480:function(e,t,n){var r=n(1828),i=n(8727).concat(`length`,`prototype`);t.f=Object.getOwnPropertyNames||function(e){return r(e,i)}},3717:function(e,t){t.f=Object.getOwnPropertySymbols},2787:function(e,t,n){var r=n(9297),i=n(4901),a=n(8981),o=n(6119),s=n(2211),c=o(`IE_PROTO`),l=Object,u=l.prototype;e.exports=s?l.getPrototypeOf:function(e){var t=a(e);if(r(t,c))return t[c];var n=t.constructor;return i(n)&&t instanceof n?n.prototype:t instanceof l?u:null}},1625:function(e,t,n){e.exports=n(9504)({}.isPrototypeOf)},1828:function(e,t,n){var r=n(9504),i=n(9297),a=n(5397),o=n(9617).indexOf,s=n(421),c=r([].push);e.exports=function(e,t){var n,r=a(e),l=0,u=[];for(n in r)!i(s,n)&&i(r,n)&&c(u,n);for(;t.length>l;)i(r,n=t[l++])&&(~o(u,n)||c(u,n));return u}},1072:function(e,t,n){var r=n(1828),i=n(8727);e.exports=Object.keys||function(e){return r(e,i)}},8773:function(e,t){var n={}.propertyIsEnumerable,r=Object.getOwnPropertyDescriptor;t.f=r&&!n.call({1:2},1)?function(e){var t=r(this,e);return!!t&&t.enumerable}:n},2551:function(e,t,n){var r=n(6395),i=n(4576),a=n(9039),o=n(3607);e.exports=r||!a((function(){if(!(o&&o<535)){var e=Math.random();__defineSetter__.call(null,e,(function(){})),delete i[e]}}))},2967:function(e,t,n){var r=n(6706),i=n(34),a=n(7750),o=n(3506);e.exports=Object.setPrototypeOf||(`__proto__`in{}?function(){var e,t=!1,n={};try{(e=r(Object.prototype,`__proto__`,`set`))(n,[]),t=n instanceof Array}catch{}return function(n,r){return a(n),o(r),i(n)&&(t?e(n,r):n.__proto__=r),n}}():void 0)},3179:function(e,t,n){var r=n(2140),i=n(6955);e.exports=r?{}.toString:function(){return`[object `+i(this)+`]`}},4270:function(e,t,n){var r=n(9565),i=n(4901),a=n(34),o=TypeError;e.exports=function(e,t){var n,s;if(t===`string`&&i(n=e.toString)&&!a(s=r(n,e))||i(n=e.valueOf)&&!a(s=r(n,e))||t!==`string`&&i(n=e.toString)&&!a(s=r(n,e)))return s;throw new o(`Can't convert object to primitive value`)}},5031:function(e,t,n){var r=n(7751),i=n(9504),a=n(8480),o=n(3717),s=n(8551),c=i([].concat);e.exports=r(`Reflect`,`ownKeys`)||function(e){var t=a.f(s(e)),n=o.f;return n?c(t,n(e)):t}},8235:function(e,t,n){var r=n(9504),i=n(9297),a=SyntaxError,o=parseInt,s=String.fromCharCode,c=r(``.charAt),l=r(``.slice),u=r(/./.exec),d={'\\"':`"`,"\\\\":`\\`,"\\/":`/`,"\\b":`\b`,"\\f":`\f`,"\\n":` +`)[0]}),i&&(0,G.jsx)(`span`,{className:`text-bambu-gray/50 shrink-0`,children:n?(0,G.jsx)(gs,{className:`w-3.5 h-3.5`}):(0,G.jsx)(ps,{className:`w-3.5 h-3.5`})})]})},t)})})}),(0,G.jsx)(`div`,{className:`flex items-center justify-between p-3 border-t border-bambu-dark-tertiary text-sm text-bambu-gray`,children:d?(0,G.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`w-2 h-2 bg-green-500 rounded-full animate-pulse`}),`Auto-refreshing every 2 seconds`]}):(0,G.jsx)(`span`,{children:`Click Start to enable live log streaming`})})]})]})}function d0e(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:e<1024*1024*1024?`${(e/(1024*1024)).toFixed(1)} MB`:`${(e/(1024*1024*1024)).toFixed(2)} GB`}function P9({icon:e,label:t,value:n,subValue:r,color:i=`text-bambu-green`}){return(0,G.jsxs)(`div`,{className:`flex items-start gap-3 p-4 bg-bambu-dark rounded-lg`,children:[(0,G.jsx)(`div`,{className:`p-2 rounded-lg bg-bambu-dark-tertiary ${i}`,children:(0,G.jsx)(e,{className:`w-5 h-5`})}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:t}),(0,G.jsx)(`p`,{className:`text-lg font-semibold text-white truncate`,children:n}),r&&(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:r})]})]})}function f0e({percent:e,color:t=`bg-bambu-green`}){return(0,G.jsx)(`div`,{className:`w-full h-2 bg-bambu-dark rounded-full overflow-hidden`,children:(0,G.jsx)(`div`,{className:`h-full ${t} transition-all duration-300`,style:{width:`${Math.min(100,e)}%`}})})}function F9({title:e,icon:t,children:n}){return(0,G.jsxs)(zd,{className:`p-6`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-4`,children:[(0,G.jsx)(t,{className:`w-5 h-5 text-bambu-green`}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e})]}),n]})}function p0e(){let{t:e}=U(),t=co(),[n,r]=(0,y.useState)(null),[i,a]=(0,y.useState)(!1),[o,s]=(0,y.useState)(!1),[c,l]=(0,y.useState)(null),{data:u,isLoading:d,refetch:f,isFetching:p}=K({queryKey:[`systemInfo`],queryFn:Z.getSystemInfo,refetchInterval:3e4}),{data:m}=K({queryKey:[`debugLogging`],queryFn:Dd.getDebugLoggingState,staleTime:10*1e3,refetchInterval:10*1e3}),{data:h}=K({queryKey:[`settings`],queryFn:Z.getSettings}),{data:g}=K({queryKey:[`library-stats`],queryFn:Z.getLibraryStats}),{data:_}=K({queryKey:[`printers`],queryFn:Z.getPrinters}),{data:v,refetch:b,isFetching:x}=K({queryKey:[`systemHealth`],queryFn:Z.getSystemHealth,staleTime:60*1e3}),S=h?.time_format||`system`,C=async()=>{s(!0);try{let e=await Dd.setDebugLogging(!m?.enabled);t.setQueryData([`debugLogging`],e)}catch(e){console.error(`Failed to toggle debug logging:`,e)}finally{s(!1)}},w=async()=>{r(null),a(!0);try{await Dd.downloadSupportBundle()}catch(e){r(e instanceof Error?e.message:`Failed to download support bundle`)}finally{a(!1)}};if(d)return(0,G.jsx)(`div`,{className:`flex items-center justify-center h-64`,children:(0,G.jsx)(Y,{className:`w-8 h-8 text-bambu-green animate-spin`})});if(!u)return(0,G.jsx)(`div`,{className:`p-6 text-center text-bambu-gray`,children:e(`system.failedToLoad`,`Failed to load system information`)});let T=u.storage.disk_percent_used>90?`bg-red-500`:u.storage.disk_percent_used>75?`bg-yellow-500`:`bg-bambu-green`,E=u.memory.percent_used>90?`bg-red-500`:u.memory.percent_used>75?`bg-yellow-500`:`bg-bambu-green`;return(0,G.jsxs)(`div`,{className:`p-6 space-y-6`,children:[(0,G.jsxs)(`div`,{className:`flex flex-col items-start gap-4 sm:flex-row sm:items-center sm:justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h1`,{className:`text-2xl font-bold text-white`,children:e(`system.title`,`System Information`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:e(`system.subtitle`,`Monitor system resources and database statistics`)})]}),(0,G.jsxs)(`button`,{onClick:()=>f(),disabled:p,className:`flex items-center gap-2 px-4 py-2 bg-bambu-dark-secondary hover:bg-bambu-dark-tertiary rounded-lg transition-colors disabled:opacity-50`,children:[(0,G.jsx)(Hl,{className:`w-4 h-4 ${p?`animate-spin`:``}`}),e(`common.refresh`,`Refresh`)]})]}),(0,G.jsx)(F9,{title:e(`system.application`,`Application`),icon:tu,children:(0,G.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-4`,children:[(0,G.jsx)(P9,{icon:tu,label:e(`system.version`,`Version`),value:`v${u.app.version}`}),(0,G.jsx)(P9,{icon:js,label:e(`system.uptime`,`System Uptime`),value:u.system.uptime_formatted}),(0,G.jsx)(P9,{icon:tu,label:e(`system.hostname`,`Hostname`),value:u.system.hostname})]})}),(0,G.jsx)(F9,{title:e(`support.title`,`Support & Troubleshooting`),icon:Ic,children:(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`support.description`,`Enable debug logging to capture detailed information, then download a support bundle to share when reporting issues.`)}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-4 bg-bambu-dark rounded-lg`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`p-2 rounded-lg ${m?.enabled?`bg-amber-500/20 text-amber-500`:`bg-bambu-dark-tertiary text-bambu-gray`}`,children:(0,G.jsx)($o,{className:`w-5 h-5`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`font-medium text-white`,children:e(`support.debugLogging`,`Debug Logging`)}),(0,G.jsxs)(`p`,{className:`text-sm text-bambu-gray`,children:[m?.enabled?e(`support.debugLoggingEnabled`,`Capturing detailed logs`):e(`support.debugLoggingDisabled`,`Normal logging level`),m?.enabled&&m.duration_seconds!==null&&(0,G.jsxs)(`span`,{className:`text-amber-700 dark:text-amber-400 ml-2`,children:[`(`,Math.floor(m.duration_seconds/60),`m `,m.duration_seconds%60,`s)`]})]})]})]}),(0,G.jsxs)(`button`,{onClick:C,disabled:o,className:`px-4 py-2 rounded-lg font-medium transition-colors flex items-center gap-2 ${m?.enabled?`bg-amber-100 text-amber-700 hover:bg-amber-200 dark:bg-amber-500/20 dark:text-amber-400 dark:hover:bg-amber-500/30`:`bg-bambu-green/20 text-bambu-green hover:bg-bambu-green/30`} disabled:opacity-50`,children:[o&&(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),m?.enabled?e(`support.disableDebug`,`Disable`):e(`support.enableDebug`,`Enable`)]})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-4 bg-bambu-dark rounded-lg`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`p-2 rounded-lg bg-bambu-dark-tertiary text-bambu-green`,children:(0,G.jsx)(Xs,{className:`w-5 h-5`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`font-medium text-white`,children:e(`support.supportBundle`,`Support Bundle`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`support.supportBundleDescription`,`Download system info and logs as a ZIP file`)})]})]}),(0,G.jsxs)(`button`,{onClick:w,disabled:i||!m?.enabled,className:`px-4 py-2 rounded-lg font-medium bg-bambu-green/20 text-bambu-green hover:bg-bambu-green/30 transition-colors flex items-center gap-2 disabled:opacity-50 disabled:cursor-not-allowed`,title:m?.enabled?void 0:e(`support.enableDebugFirst`,`Enable debug logging first`),children:[i&&(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),i?e(`support.bundleGenerating`,`Generating...`):e(`common.download`,`Download`)]})]}),i&&(0,G.jsxs)(`div`,{className:`p-3 bg-bambu-dark-tertiary/40 rounded-lg space-y-1`,children:[(0,G.jsxs)(`p`,{className:`text-sm font-medium text-white flex items-center gap-2`,children:[(0,G.jsx)(Y,{className:`w-3.5 h-3.5 animate-spin text-bambu-green`}),e(`support.bundleGenerating`,`Generating...`)]}),(0,G.jsxs)(`ul`,{className:`text-xs text-bambu-gray list-disc list-inside space-y-0.5 pl-1`,children:[(0,G.jsx)(`li`,{children:e(`support.bundleStepConnection`,`Running printer connectivity checks`)}),(0,G.jsx)(`li`,{children:e(`support.bundleStepVirtualPrinters`,`Running virtual-printer setup checks`)}),(0,G.jsx)(`li`,{children:e(`support.bundleStepLogScan`,`Scanning recent logs for known issues`)}),(0,G.jsx)(`li`,{children:e(`support.bundleStepBuild`,`Building the support bundle ZIP`)})]})]}),n&&(0,G.jsx)(`div`,{className:`p-3 bg-red-100 border border-red-300 rounded-lg text-red-700 dark:bg-red-500/20 dark:border-red-500/30 dark:text-red-400 text-sm`,children:n}),!m?.enabled&&(0,G.jsx)(`div`,{className:`p-4 bg-bambu-dark-tertiary/50 rounded-lg`,children:(0,G.jsxs)(`p`,{className:`text-sm text-bambu-gray`,children:[(0,G.jsx)(`span`,{className:`text-amber-700 dark:text-amber-400 font-medium`,children:e(`support.instructions`,`To report an issue:`)}),(0,G.jsx)(`br`,{}),`1. `,e(`support.step1`,`Enable debug logging`),(0,G.jsx)(`br`,{}),`2. `,e(`support.step2`,`Reproduce the issue`),(0,G.jsx)(`br`,{}),`3. `,e(`support.step3`,`Download the support bundle`),(0,G.jsx)(`br`,{}),`4. `,e(`support.step4`,`Attach the ZIP file to your issue report`)]})}),(0,G.jsxs)(`div`,{className:`p-4 bg-bambu-dark rounded-lg space-y-3`,children:[(0,G.jsx)(`p`,{className:`text-sm font-medium text-white`,children:e(`support.privacyTitle`,`What's in the support bundle?`)}),(0,G.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4 text-sm`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-bambu-green font-medium mb-1`,children:e(`support.collected`,`Collected:`)}),(0,G.jsxs)(`ul`,{className:`text-bambu-gray space-y-0.5`,children:[(0,G.jsxs)(`li`,{children:[`• `,e(`support.collectItem1`,`App version and debug mode`)]}),(0,G.jsxs)(`li`,{children:[`• `,e(`support.collectItem2`,`OS, architecture, Python version`)]}),(0,G.jsxs)(`li`,{children:[`• `,e(`support.collectItem3`,`Database statistics (counts only)`)]}),(0,G.jsxs)(`li`,{children:[`• `,e(`support.collectItem4`,`Printer models and nozzle counts`)]}),(0,G.jsxs)(`li`,{children:[`• `,e(`support.collectItem5`,`Non-sensitive settings (themes, formats)`)]}),(0,G.jsxs)(`li`,{children:[`• `,e(`support.collectItem6`,`Debug logs (sanitized)`)]}),(0,G.jsxs)(`li`,{children:[`• `,e(`support.collectItem7`,`Printer connectivity and firmware versions`)]}),(0,G.jsxs)(`li`,{children:[`• `,e(`support.collectItem8`,`Integration status (Spoolman, MQTT, HA)`)]}),(0,G.jsxs)(`li`,{children:[`• `,e(`support.collectItem9`,`Network interfaces (subnets only)`)]}),(0,G.jsxs)(`li`,{children:[`• `,e(`support.collectItem10`,`Python package versions`)]}),(0,G.jsxs)(`li`,{children:[`• `,e(`support.collectItem11`,`Database health checks`)]}),(0,G.jsxs)(`li`,{children:[`• `,e(`support.collectItem12`,`Docker environment details`)]})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-red-700 dark:text-red-400 font-medium mb-1`,children:e(`support.notCollected`,`NOT collected:`)}),(0,G.jsxs)(`ul`,{className:`text-bambu-gray space-y-0.5`,children:[(0,G.jsxs)(`li`,{children:[`• `,e(`support.notItem1`,`Printer names and serial numbers`)]}),(0,G.jsxs)(`li`,{children:[`• `,e(`support.notItem2`,`Access codes and passwords`)]}),(0,G.jsxs)(`li`,{children:[`• `,e(`support.notItem3`,`Email addresses`)]}),(0,G.jsxs)(`li`,{children:[`• `,e(`support.notItem4`,`API keys and tokens`)]}),(0,G.jsxs)(`li`,{children:[`• `,e(`support.notItem5`,`Webhook URLs`)]}),(0,G.jsxs)(`li`,{children:[`• `,e(`support.notItem6`,`Your hostname or username`)]}),(0,G.jsxs)(`li`,{children:[`• `,e(`support.notItem7`,`IP addresses`)]})]})]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray/70`,children:e(`support.privacyNote`,`Email addresses in logs are replaced with [EMAIL], printer names with [PRINTER], serial numbers with [SERIAL], and IP addresses with [IP].`)})]}),(0,G.jsx)(u0e,{})]})}),(0,G.jsxs)(F9,{title:e(`diagnostic.sectionTitle`,`Connection Diagnostic`),icon:Su,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4`,children:e(`diagnostic.sectionDescription`,`Check why a printer won't connect or won't print — port reachability, LAN developer mode, Docker network mode, and credentials.`)}),_&&_.length>0?(0,G.jsx)(`div`,{className:`space-y-2`,children:_.map(t=>(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-3 bg-bambu-dark rounded-lg`,children:[(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsx)(`span`,{className:`font-medium text-white`,children:t.name}),(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray ml-2`,children:t.ip_address})]}),(0,G.jsxs)(`button`,{onClick:()=>l(t),className:`flex items-center gap-2 px-3 py-1.5 text-sm bg-bambu-dark-secondary hover:bg-bambu-dark-tertiary text-white rounded-lg transition-colors flex-shrink-0`,children:[(0,G.jsx)(Su,{className:`w-4 h-4`}),e(`diagnostic.runButton`,`Run diagnostic`)]})]},t.id))}):(0,G.jsx)(`p`,{className:`text-bambu-gray`,children:e(`diagnostic.noPrinters`,`No printers configured.`)})]}),(0,G.jsxs)(F9,{title:e(`systemHealth.sectionTitle`),icon:Lc,children:[(0,G.jsxs)(`div`,{className:`flex items-start justify-between gap-3 mb-3`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`systemHealth.sectionDescription`)}),(0,G.jsxs)(`button`,{onClick:()=>b(),disabled:x,className:`flex items-center gap-2 px-3 py-1.5 text-sm bg-bambu-dark-secondary hover:bg-bambu-dark-tertiary text-white rounded-lg transition-colors flex-shrink-0 disabled:opacity-50`,children:[(0,G.jsx)(Hl,{className:`w-4 h-4 ${x?`animate-spin`:``}`}),e(`systemHealth.rescan`)]})]}),v?(0,G.jsx)(Qp,{result:v}):(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`common.loading`)})]}),(0,G.jsxs)(F9,{title:e(`system.database`,`Database`),icon:Gs,children:[(0,G.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4 mb-4`,children:[(0,G.jsx)(P9,{icon:Gs,label:e(`system.dbEngine`,`Database Engine`),value:u.database.engine||`SQLite`}),(0,G.jsx)(P9,{icon:Gs,label:e(`system.dbVersion`,`Version`),value:u.database.version||`unknown`})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-4 mb-4`,children:[(0,G.jsx)(P9,{icon:Po,label:e(`system.totalArchives`,`Total Archives`),value:u.database.archives}),(0,G.jsx)(P9,{icon:Ss,label:e(`system.completed`,`Completed`),value:u.database.archives_completed,color:`text-green-500`}),(0,G.jsx)(P9,{icon:Ds,label:e(`system.failed`,`Failed`),value:u.database.archives_failed,color:`text-red-500`}),(0,G.jsx)(P9,{icon:Y,label:e(`system.printing`,`Printing`),value:u.database.archives_printing,color:`text-yellow-500`})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-4`,children:[(0,G.jsx)(P9,{icon:Rl,label:e(`system.printers`,`Printers`),value:u.database.printers}),(0,G.jsx)(P9,{icon:wl,label:e(`system.filaments`,`Filaments`),value:u.database.filaments}),(0,G.jsx)(P9,{icon:_c,label:e(`system.projects`,`Projects`),value:u.database.projects}),(0,G.jsx)(P9,{icon:Pl,label:e(`system.smartPlugs`,`Smart Plugs`),value:u.database.smart_plugs})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4 mt-4`,children:[(0,G.jsx)(P9,{icon:js,label:e(`system.totalPrintTime`,`Total Print Time`),value:u.database.total_print_time_formatted}),(0,G.jsx)(P9,{icon:Po,label:e(`system.totalFilament`,`Total Filament Used`),value:`${u.database.total_filament_kg} kg`,subValue:`${u.database.total_filament_grams.toLocaleString()} g`})]})]}),(0,G.jsxs)(F9,{title:e(`system.connectedPrinters`,`Connected Printers`),icon:Rl,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-4 mb-4`,children:[(0,G.jsx)(`div`,{className:`text-3xl font-bold text-bambu-green`,children:u.printers.connected}),(0,G.jsx)(`div`,{className:`text-bambu-gray`,children:e(`system.ofTotal`,`of {{total}} printers connected`,{total:u.printers.total})})]}),u.printers.connected_list.length>0?(0,G.jsx)(`div`,{className:`space-y-2`,children:u.printers.connected_list.map(e=>(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-3 bg-bambu-dark rounded-lg`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`w-2 h-2 rounded-full bg-bambu-green`}),(0,G.jsx)(`span`,{className:`font-medium text-white`,children:e.name})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-4 text-sm text-bambu-gray`,children:[(0,G.jsx)(`span`,{children:e.model}),(0,G.jsx)(`span`,{className:`px-2 py-0.5 rounded ${e.state===`RUNNING`?`bg-bambu-green/20 text-bambu-green`:e.state===`IDLE`?`bg-blue-100 text-blue-700 dark:bg-blue-500/20 dark:text-blue-400`:`bg-bambu-dark-tertiary`}`,children:e.state})]})]},e.id))}):(0,G.jsx)(`p`,{className:`text-bambu-gray`,children:e(`system.noPrintersConnected`,`No printers connected`)})]}),(0,G.jsx)(F9,{title:e(`system.storage`,`Storage`),icon:Pc,children:(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex justify-between text-sm mb-1`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:e(`system.diskUsage`,`Disk Usage`)}),(0,G.jsxs)(`span`,{className:`text-white`,children:[u.storage.disk_used_formatted,` / `,u.storage.disk_total_formatted]})]}),(0,G.jsx)(f0e,{percent:u.storage.disk_percent_used,color:T}),(0,G.jsxs)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:[u.storage.disk_free_formatted,` `,e(`system.free`,`free`),` (`,(100-u.storage.disk_percent_used).toFixed(1),`%)`]})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-4`,children:[(0,G.jsx)(P9,{icon:Po,label:e(`system.archiveStorage`,`Archive Storage`),value:u.storage.archive_size_formatted}),(0,G.jsx)(P9,{icon:Gs,label:e(`system.databaseSize`,`Database Size`),value:u.storage.database_size_formatted}),g&&(0,G.jsx)(P9,{icon:vc,label:e(`system.fileManagerStorage`,`File Manager`),value:d0e(g.total_size_bytes),subValue:`${g.total_files} files, ${g.total_folders} folders`})]})]})}),(0,G.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-6`,children:[(0,G.jsx)(F9,{title:e(`system.memory`,`Memory`),icon:ul,children:(0,G.jsx)(`div`,{className:`space-y-4`,children:(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex justify-between text-sm mb-1`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:e(`system.memoryUsage`,`Memory Usage`)}),(0,G.jsxs)(`span`,{className:`text-white`,children:[u.memory.used_formatted,` / `,u.memory.total_formatted]})]}),(0,G.jsx)(f0e,{percent:u.memory.percent_used,color:E}),(0,G.jsxs)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:[u.memory.available_formatted,` `,e(`system.available`,`available`)]})]})})}),(0,G.jsx)(F9,{title:e(`system.cpu`,`CPU`),icon:Hs,children:(0,G.jsx)(`div`,{className:`space-y-4`,children:(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,G.jsx)(P9,{icon:Hs,label:e(`system.cores`,`Cores`),value:u.cpu.count,subValue:`${u.cpu.count_logical} logical`}),(0,G.jsx)(P9,{icon:Hs,label:e(`system.usage`,`Usage`),value:`${u.cpu.percent}%`})]})})})]}),(0,G.jsx)(F9,{title:e(`system.systemDetails`,`System Details`),icon:tu,children:(0,G.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-4`,children:[(0,G.jsx)(P9,{icon:tu,label:e(`system.os`,`Operating System`),value:u.system.platform,subValue:u.system.platform_release}),(0,G.jsx)(P9,{icon:Hs,label:e(`system.architecture`,`Architecture`),value:u.system.architecture}),(0,G.jsx)(P9,{icon:tu,label:e(`system.python`,`Python`),value:u.system.python_version}),(0,G.jsx)(P9,{icon:js,label:e(`system.bootTime`,`Boot Time`),value:op(u.system.boot_time,S)})]})}),c&&(0,G.jsx)(Xp,{printerId:c.id,printerName:c.name,onClose:()=>l(null)})]})}var I9=`auth_remember_me`,L9=`auth_post_login_redirect`;function R9(e){return e?`persistent`:`session`}function m0e(){try{let e=sessionStorage.getItem(I9)===`1`;return sessionStorage.removeItem(I9),e}catch(e){return console.warn(`consumeSavedRememberMe: sessionStorage unavailable, Remember Me preference lost across OIDC redirect`,e),!1}}function z9(e){return!e||!e.startsWith(`/`)||e.startsWith(`//`)||e.startsWith(`/login`)?null:e}function h0e(e){let t=z9(e);if(t)try{sessionStorage.setItem(L9,t)}catch(e){console.warn(`stashPostLoginRedirect: sessionStorage unavailable, post-login target will be lost across OIDC redirect`,e)}}function g0e(){try{let e=sessionStorage.getItem(L9);return sessionStorage.removeItem(L9),z9(e)}catch(e){return console.warn(`consumePostLoginRedirect: sessionStorage unavailable`,e),null}}function _0e({provider:e,onClick:t,disabled:n}){let{t:r}=U(),[i,a]=(0,y.useState)(!1);return(0,G.jsxs)(`button`,{type:`button`,onClick:t,disabled:n,className:`w-full flex items-center justify-center gap-3 py-3 px-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary hover:border-bambu-green/50 rounded-lg text-white font-medium transition-colors disabled:opacity-50`,children:[e.has_icon&&!i?(0,G.jsx)(`img`,{src:Z.oidcProviderIconUrl(e.id),alt:``,className:`w-5 h-5 object-contain`,onError:()=>a(!0)}):(0,G.jsx)(su,{className:`w-5 h-5 text-bambu-green`}),r(`login.twoFA.signInWith`,{provider:e.name})]})}function v0e(){let e=or(),t=rr(),[n]=Ri(),{t:r}=U(),{login:i,loginWithToken:a,user:o,loading:s}=Nd(),{showToast:c}=qd(),{mode:l}=Id();function u(){let e=t.state?.from;if(e?.pathname){let t=z9(`${e.pathname}${e.search??``}`);if(t)return t}return g0e()??`/`}let[d,f]=(0,y.useState)(``),[p,m]=(0,y.useState)(``),[h,g]=(0,y.useState)(!1),[_,v]=(0,y.useState)(``),[b,x]=(0,y.useState)(`credentials`),[S,C]=(0,y.useState)(``),[w,T]=(0,y.useState)([]),[E,D]=(0,y.useState)(`totp`),[O,k]=(0,y.useState)(``),[A,j]=(0,y.useState)(!1),M=(0,y.useRef)(null),[N,P]=(0,y.useState)(!1),[F,I]=(0,y.useState)(``),[L,R]=(0,y.useState)(``),[z,B]=(0,y.useState)(``),{data:V}=K({queryKey:[`advancedAuthStatus`],queryFn:()=>Z.getAdvancedAuthStatus()}),{data:ee}=K({queryKey:[`oidcProviders`],queryFn:()=>Z.getOIDCProviders()}),[te,ne]=(0,y.useState)(!1);(0,y.useEffect)(()=>{!s&&o&&b===`credentials`&&e(`/`,{replace:!0})},[s,o,b,e]);let re=(0,y.useRef)(!1);(0,y.useEffect)(()=>{if(re.current||n.get(`fallback`)===`local`||!V||!V.autologin_provider_id||window.location.hash.startsWith(`#oidc_token=`)||n.get(`oidc_error`))return;re.current=!0;let e=V.autologin_provider_id,t=new Promise((e,t)=>setTimeout(()=>t(Error(`autologin timeout`)),5e3));Promise.race([Z.getOIDCAuthorizeUrl(e),t]).then(e=>{window.location.href=e.auth_url}).catch(()=>{ne(!0)})},[V,n]);let ie=V?.local_login_enabled!==!1,ae=te&&V?.autologin_provider_id!=null;(0,y.useEffect)(()=>{let t=window.location.hash,n=t.startsWith(`#reset_token=`)?t.slice(13):null;n&&(I(n),x(`reset-password`),e(`/login`,{replace:!0}))},[]),(0,y.useEffect)(()=>{let t=window.location.hash,i=t.startsWith(`#oidc_token=`)?t.slice(12):null,o=n.get(`oidc_error`);if(!i&&!o)return;let s=m0e();if(o){c({oidc_provider_error:r(`login.oidcErrors.providerError`),missing_parameters:r(`login.oidcErrors.missingParameters`),invalid_state:r(`login.oidcErrors.invalidState`),state_expired:r(`login.oidcErrors.stateExpired`),provider_not_found:r(`login.oidcErrors.providerNotFound`),discovery_failed:r(`login.oidcErrors.discoveryFailed`),invalid_discovery_document:r(`login.oidcErrors.invalidDiscovery`),token_exchange_network_error:r(`login.oidcErrors.networkError`),token_exchange_bad_response:r(`login.oidcErrors.badResponse`),no_id_token:r(`login.oidcErrors.noIdToken`),token_validation_failed:r(`login.oidcErrors.validationFailed`),nonce_mismatch:r(`login.oidcErrors.nonceMismatch`),missing_sub_claim:r(`login.oidcErrors.missingSubClaim`),no_linked_account:r(`login.oidcErrors.noLinkedAccount`),account_inactive:r(`login.oidcErrors.accountInactive`),user_resolution_failed:r(`login.oidcErrors.userResolutionFailed`),internal_error:r(`login.oidcErrors.internalError`)}[o]??(o.startsWith(`token_exchange_`)?r(`login.oidcErrors.tokenExchangeFailed`):r(`login.oidcLoginFailed`)),`error`),e(`/login`,{replace:!0});return}i&&Z.exchangeOIDCToken(i).then(t=>{if(t.requires_2fa&&t.pre_auth_token){P(s),C(t.pre_auth_token);let n=t.two_fa_methods??[];T(n),n.includes(`totp`)?D(`totp`):n.includes(`email`)?D(`email`):D(`backup`),x(`2fa`),e(`/login`,{replace:!0})}else t.access_token&&t.user?(a(t.access_token,t.user,R9(s)),c(r(`login.loginSuccess`)),e(u(),{replace:!0})):(c(r(`login.oidcLoginFailed`),`error`),e(`/login`,{replace:!0}))}).catch(t=>{console.error(`OIDC token exchange failed`,t),c(r(`login.oidcLoginFailed`),`error`),e(`/login`,{replace:!0})})},[n]);let oe=q({mutationFn:()=>i(d,p,R9(N)),onSuccess:t=>{if(t.requires_2fa&&t.pre_auth_token){C(t.pre_auth_token);let e=t.two_fa_methods??[];T(e),e.includes(`totp`)?D(`totp`):e.includes(`email`)?D(`email`):D(`backup`),x(`2fa`)}else t.access_token&&t.user&&(c(r(`login.loginSuccess`)),e(u(),{replace:!0}))},onError:e=>{c(e.message||r(`login.loginFailed`),`error`)}}),se=q({mutationFn:e=>Z.forgotPassword({email:e}),onSuccess:e=>{c(e.message,`success`),g(!1),v(``)},onError:e=>{c(e.message,`error`)}}),H=q({mutationFn:()=>Z.forgotPasswordConfirm(F,L),onSuccess:e=>{c(e.message,`success`),x(`credentials`),I(``),R(``),B(``)},onError:e=>{c(e.message||r(`login.resetPassword.resetFailed`),`error`)}}),ce=q({mutationFn:()=>Z.sendEmailOTP(S),onSuccess:e=>{j(!0),e.pre_auth_token&&C(e.pre_auth_token),c(e.message,`success`)},onError:e=>{c(e.message||r(`login.twoFA.sendCodeFailed`),`error`)}}),le=q({mutationFn:()=>Z.verify2FA({pre_auth_token:S,code:O,method:E}),onSuccess:t=>{t.access_token&&t.user?(a(t.access_token,t.user,R9(N)),c(r(`login.loginSuccess`)),e(u(),{replace:!0})):(console.error(`2FA verify: unexpected response shape`,t),c(r(`login.loginFailed`),`error`))},onError:e=>{c(e.message||r(`login.twoFA.invalidCode`),`error`),k(``)}}),ue=q({mutationFn:e=>Z.getOIDCAuthorizeUrl(e),onSuccess:e=>{if(N)try{sessionStorage.setItem(I9,`1`)}catch(e){console.warn(`setItem auth_remember_me failed, Remember Me will not carry through OIDC redirect`,e)}let n=t.state?.from;n?.pathname&&h0e(`${n.pathname}${n.search??``}`),window.location.href=e.auth_url},onError:e=>{c(e.message||r(`login.oidcLoginFailed`),`error`)}}),de=e=>{if(e.preventDefault(),!d||!p){c(r(`login.enterCredentials`),`error`);return}oe.mutate()},fe=e=>{if(e.preventDefault(),!O.trim()){c(r(`login.twoFA.enterCode`),`error`);return}le.mutate()},pe=e=>{if(e.preventDefault(),!_){c(r(`login.enterEmail`),`error`);return}se.mutate(_)},me=e=>{D(e),k(``),j(!1),setTimeout(()=>M.current?.focus(),0)};return b===`reset-password`?(0,G.jsx)(`div`,{className:`min-h-screen flex items-center justify-center bg-bambu-dark p-4`,children:(0,G.jsxs)(`div`,{className:`max-w-md w-full space-y-8 p-8 bg-gradient-to-br from-bambu-card to-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary shadow-lg`,children:[(0,G.jsxs)(`div`,{className:`text-center`,children:[(0,G.jsx)(`div`,{className:`flex items-center justify-center mb-4`,children:(0,G.jsx)(`div`,{className:`w-14 h-14 rounded-full bg-bambu-green/20 flex items-center justify-center`,children:(0,G.jsx)(Kc,{className:`w-7 h-7 text-bambu-green`})})}),(0,G.jsx)(`h2`,{className:`text-2xl font-bold text-white`,children:r(`login.resetPassword.title`)}),(0,G.jsx)(`p`,{className:`mt-2 text-sm text-bambu-gray`,children:r(`login.resetPassword.subtitle`)})]}),(0,G.jsxs)(`form`,{onSubmit:e=>{if(e.preventDefault(),L!==z){c(r(`login.resetPassword.passwordsDoNotMatch`),`error`);return}if(L.length<8){c(r(`login.resetPassword.passwordTooShort`),`error`);return}H.mutate()},className:`space-y-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{htmlFor:`new-password`,className:`block text-sm font-medium text-white mb-2`,children:r(`login.resetPassword.newPassword`)}),(0,G.jsx)(`input`,{id:`new-password`,type:`password`,required:!0,value:L,onChange:e=>R(e.target.value),className:`block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:r(`login.resetPassword.newPasswordPlaceholder`),autoFocus:!0,autoComplete:`new-password`,minLength:8})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{htmlFor:`confirm-password`,className:`block text-sm font-medium text-white mb-2`,children:r(`login.resetPassword.confirmPassword`)}),(0,G.jsx)(`input`,{id:`confirm-password`,type:`password`,required:!0,value:z,onChange:e=>B(e.target.value),className:`block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:r(`login.resetPassword.confirmPasswordPlaceholder`),autoComplete:`new-password`})]}),(0,G.jsx)(`button`,{type:`submit`,disabled:H.isPending||!L||!z,className:`w-full flex justify-center py-3 px-4 bg-bambu-green hover:bg-bambu-green-light text-white font-medium rounded-lg shadow-lg shadow-bambu-green/20 hover:shadow-bambu-green/30 focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:ring-offset-2 focus:ring-offset-bambu-dark-secondary transition-all disabled:opacity-50 disabled:cursor-not-allowed`,children:H.isPending?r(`login.resetPassword.saving`):r(`login.resetPassword.submit`)})]}),(0,G.jsx)(`div`,{className:`text-center`,children:(0,G.jsx)(`button`,{type:`button`,onClick:()=>{x(`credentials`),I(``),R(``),B(``)},className:`text-sm text-bambu-gray hover:text-bambu-green transition-colors`,children:r(`login.resetPassword.backToLogin`)})})]})}):b===`2fa`?(0,G.jsx)(`div`,{className:`min-h-screen flex items-center justify-center bg-bambu-dark p-4`,children:(0,G.jsxs)(`div`,{className:`max-w-md w-full space-y-8 p-8 bg-gradient-to-br from-bambu-card to-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary shadow-lg`,children:[(0,G.jsxs)(`div`,{className:`text-center`,children:[(0,G.jsx)(`div`,{className:`flex items-center justify-center mb-4`,children:(0,G.jsx)(`div`,{className:`w-14 h-14 rounded-full bg-bambu-green/20 flex items-center justify-center`,children:(0,G.jsx)(su,{className:`w-7 h-7 text-bambu-green`})})}),(0,G.jsx)(`h2`,{className:`text-2xl font-bold text-white`,children:r(`login.twoFA.title`)}),(0,G.jsx)(`p`,{className:`mt-2 text-sm text-bambu-gray`,children:r(`login.twoFA.subtitle`)})]}),w.length>1&&(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[w.includes(`totp`)&&(0,G.jsxs)(`button`,{type:`button`,onClick:()=>me(`totp`),className:`flex-1 flex flex-col items-center gap-1 py-2 px-3 rounded-lg border text-xs font-medium transition-colors ${E===`totp`?`border-bambu-green bg-bambu-green/10 text-bambu-green`:`border-bambu-dark-tertiary text-bambu-gray hover:border-bambu-green/50`}`,children:[(0,G.jsx)(mu,{className:`w-4 h-4`}),r(`login.twoFA.methodAuthenticator`)]}),w.includes(`email`)&&(0,G.jsxs)(`button`,{type:`button`,onClick:()=>me(`email`),className:`flex-1 flex flex-col items-center gap-1 py-2 px-3 rounded-lg border text-xs font-medium transition-colors ${E===`email`?`border-bambu-green bg-bambu-green/10 text-bambu-green`:`border-bambu-dark-tertiary text-bambu-gray hover:border-bambu-green/50`}`,children:[(0,G.jsx)(al,{className:`w-4 h-4`}),r(`login.twoFA.methodEmail`)]}),w.includes(`backup`)&&(0,G.jsxs)(`button`,{type:`button`,onClick:()=>me(`backup`),className:`flex-1 flex flex-col items-center gap-1 py-2 px-3 rounded-lg border text-xs font-medium transition-colors ${E===`backup`?`border-bambu-green bg-bambu-green/10 text-bambu-green`:`border-bambu-dark-tertiary text-bambu-gray hover:border-bambu-green/50`}`,children:[(0,G.jsx)(Kc,{className:`w-4 h-4`}),r(`login.twoFA.methodBackup`)]})]}),(0,G.jsxs)(`form`,{onSubmit:fe,className:`space-y-4`,children:[E===`totp`&&(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:r(`login.twoFA.instructionsTotp`)}),E===`email`&&(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:r(A?`login.twoFA.instructionsEmail`:`login.twoFA.instructionsEmailNotSent`)}),!A&&(0,G.jsx)(Q,{type:`button`,variant:`secondary`,className:`w-full`,onClick:()=>ce.mutate(),disabled:ce.isPending,children:ce.isPending?r(`login.twoFA.sendingCode`):r(`login.twoFA.sendCodeButton`)}),A&&(0,G.jsx)(`button`,{type:`button`,onClick:()=>{j(!1),ce.mutate()},className:`text-xs text-bambu-gray hover:text-bambu-green transition-colors`,children:r(`login.twoFA.resendCode`)})]}),E===`backup`&&(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:r(`login.twoFA.instructionsBackup`)}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{htmlFor:`twofa-code`,className:`block text-sm font-medium text-white mb-2`,children:r(E===`backup`?`login.twoFA.backupCodeLabel`:`login.twoFA.codeLabel`)}),(0,G.jsx)(`input`,{ref:M,id:`twofa-code`,type:`text`,inputMode:E===`backup`?`text`:`numeric`,autoComplete:`one-time-code`,value:O,onChange:e=>k(e.target.value.trim()),disabled:E===`email`&&!A,className:`block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray text-center tracking-widest text-xl font-mono focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors disabled:opacity-40`,placeholder:r(E===`backup`?`login.twoFA.backupCodePlaceholder`:`login.twoFA.codePlaceholder`),maxLength:E===`backup`?8:6,autoFocus:!0})]}),(0,G.jsx)(`button`,{type:`submit`,disabled:le.isPending||!O.trim()||E===`email`&&!A,className:`w-full flex justify-center py-3 px-4 bg-bambu-green hover:bg-bambu-green-light text-white font-medium rounded-lg shadow-lg shadow-bambu-green/20 hover:shadow-bambu-green/30 focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:ring-offset-2 focus:ring-offset-bambu-dark-secondary transition-all disabled:opacity-50 disabled:cursor-not-allowed`,children:le.isPending?r(`login.twoFA.verifyingButton`):r(`login.twoFA.verifyButton`)})]}),(0,G.jsx)(`div`,{className:`text-center`,children:(0,G.jsx)(`button`,{type:`button`,onClick:()=>{x(`credentials`),C(``),k(``),j(!1)},className:`text-sm text-bambu-gray hover:text-bambu-green transition-colors`,children:r(`login.twoFA.backToLogin`)})})]})}):(0,G.jsxs)(`div`,{className:`min-h-screen flex items-center justify-center bg-bambu-dark p-4`,children:[(0,G.jsxs)(`div`,{className:`max-w-md w-full space-y-8 p-8 bg-gradient-to-br from-bambu-card to-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary shadow-lg`,children:[(0,G.jsxs)(`div`,{className:`text-center`,children:[(0,G.jsx)(`div`,{className:`flex items-center justify-center mb-6`,children:(0,G.jsx)(`img`,{src:l===`dark`?`/img/bambuddy_logo_dark_transparent.png`:`/img/bambuddy_logo_light.png`,alt:`Bambuddy`,className:`h-16`})}),(0,G.jsx)(`h2`,{className:`text-3xl font-bold text-white`,children:r(`login.title`)}),(0,G.jsx)(`p`,{className:`mt-2 text-sm text-bambu-gray`,children:r(`login.subtitle`)})]}),ae&&(0,G.jsx)(`div`,{className:`mt-6 rounded-lg border border-amber-300 dark:border-amber-500/40 bg-amber-50 dark:bg-amber-500/10 px-4 py-3 text-sm text-amber-800 dark:text-amber-200`,children:r(`login.autologinFailed`)}),!ie&&(0,G.jsx)(`div`,{className:`mt-6 rounded-lg border border-bambu-dark-tertiary bg-bambu-dark/40 px-4 py-3 text-sm text-bambu-gray`,children:r(`login.localDisabledNotice`)}),ie&&(0,G.jsxs)(`form`,{className:`mt-8 space-y-6`,onSubmit:de,children:[(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{htmlFor:`username`,className:`block text-sm font-medium text-white mb-2`,children:V?.advanced_auth_enabled?r(`login.usernameOrEmail`):r(`login.username`)}),(0,G.jsx)(`input`,{id:`username`,type:`text`,required:!0,value:d,onChange:e=>f(e.target.value),className:`block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:V?.advanced_auth_enabled?r(`login.usernameOrEmailPlaceholder`):r(`login.usernamePlaceholder`),autoComplete:`username`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{htmlFor:`password`,className:`block text-sm font-medium text-white mb-2`,children:r(`login.password`)||`Password`}),(0,G.jsx)(`input`,{id:`password`,type:`password`,required:!0,value:p,onChange:e=>m(e.target.value),className:`block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:r(`login.passwordPlaceholder`),autoComplete:`current-password`})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`input`,{id:`remember-me`,type:`checkbox`,checked:N,onChange:e=>P(e.target.checked),className:`h-4 w-4 rounded border-bambu-dark-tertiary bg-bambu-dark-secondary text-bambu-green focus:ring-bambu-green/50 cursor-pointer`}),(0,G.jsx)(`label`,{htmlFor:`remember-me`,className:`text-sm text-bambu-gray cursor-pointer`,children:r(`login.rememberMe`)})]}),(0,G.jsx)(`div`,{children:(0,G.jsx)(`button`,{type:`submit`,disabled:oe.isPending,className:`w-full flex justify-center py-3 px-4 bg-bambu-green hover:bg-bambu-green-light text-white font-medium rounded-lg shadow-lg shadow-bambu-green/20 hover:shadow-bambu-green/30 focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:ring-offset-2 focus:ring-offset-bambu-dark-secondary transition-all disabled:opacity-50 disabled:cursor-not-allowed disabled:hover:bg-bambu-green`,children:oe.isPending?r(`login.signingIn`):r(`login.signIn`)})}),(0,G.jsx)(`div`,{className:`text-center`,children:(0,G.jsx)(`button`,{type:`button`,onClick:()=>g(!0),className:`text-sm text-bambu-gray hover:text-bambu-green transition-colors`,children:r(`login.forgotPassword`)})})]}),ee&&ee.length>0&&(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(`div`,{className:`absolute inset-0 flex items-center`,children:(0,G.jsx)(`div`,{className:`w-full border-t border-bambu-dark-tertiary`})}),(0,G.jsx)(`div`,{className:`relative flex justify-center text-sm`,children:(0,G.jsx)(`span`,{className:`px-2 bg-bambu-dark-secondary text-bambu-gray`,children:r(`login.twoFA.orContinueWith`)})})]}),(0,G.jsx)(`div`,{className:`space-y-2`,children:ee.map(e=>(0,G.jsx)(_0e,{provider:e,onClick:()=>ue.mutate(e.id),disabled:ue.isPending},e.id))})]})]}),h&&(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:()=>g(!1),children:(0,G.jsxs)(zd,{className:`w-full max-w-md`,onClick:e=>e.stopPropagation(),children:[(0,G.jsx)(Bd,{children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(al,{className:`w-5 h-5 text-bambu-green`}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:r(`login.forgotPasswordTitle`)})]}),(0,G.jsx)(Q,{variant:`ghost`,size:`sm`,onClick:()=>{g(!1),v(``)},children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]})}),(0,G.jsx)(Vd,{children:V?.advanced_auth_enabled?(0,G.jsxs)(`form`,{onSubmit:pe,className:`space-y-4`,children:[(0,G.jsx)(`p`,{className:`text-bambu-gray text-sm`,children:r(`login.forgotPasswordEmailMessage`)}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{htmlFor:`forgot-email`,className:`block text-sm font-medium text-white mb-2`,children:r(`login.emailAddress`)}),(0,G.jsx)(`input`,{id:`forgot-email`,type:`email`,required:!0,value:_,onChange:e=>v(e.target.value),className:`block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:r(`login.emailPlaceholder`)})]}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,className:`flex-1`,onClick:()=>{g(!1),v(``)},children:r(`login.cancel`)}),(0,G.jsx)(Q,{type:`submit`,className:`flex-1`,disabled:se.isPending,children:se.isPending?r(`login.sending`):r(`login.sendResetEmail`)})]})]}):(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsx)(`p`,{className:`text-bambu-gray`,children:r(`login.forgotPasswordMessage`)}),(0,G.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4 space-y-2`,children:[(0,G.jsx)(`p`,{className:`text-sm text-white font-medium`,children:r(`login.howToReset`)}),(0,G.jsxs)(`ol`,{className:`text-sm text-bambu-gray space-y-1 list-decimal list-inside`,children:[(0,G.jsx)(`li`,{children:r(`login.resetStep1`)}),(0,G.jsx)(`li`,{children:r(`login.resetStep2`)}),(0,G.jsx)(`li`,{children:r(`login.resetStep3`)}),(0,G.jsx)(`li`,{children:r(`login.resetStep4`)})]})]}),(0,G.jsx)(Q,{variant:`secondary`,className:`w-full`,onClick:()=>g(!1),children:r(`login.gotIt`)})]})})]})})]})}function y0e(){let e=or(),{t}=U(),{showToast:n}=qd(),{mode:r}=Id(),{refreshAuth:i}=Nd(),[a,o]=(0,y.useState)(!1),[s,c]=(0,y.useState)(``),[l,u]=(0,y.useState)(``),[d,f]=(0,y.useState)(``),p=q({mutationFn:()=>Z.setupAuth({auth_enabled:a,admin_username:a?s:void 0,admin_password:a?l:void 0}),onSuccess:async r=>{await i(),r.auth_enabled?r.admin_created?(n(t(`setup.toast.authEnabledAdminCreated`)),e(`/login`)):(n(t(`setup.toast.authEnabledExistingAdmins`)),e(`/login`)):(n(t(`setup.toast.setupCompleted`)),e(`/`))},onError:e=>{n(e.message,`error`)}});return(0,G.jsx)(`div`,{className:`min-h-screen flex items-center justify-center bg-bambu-dark p-4`,children:(0,G.jsxs)(`div`,{className:`max-w-md w-full space-y-8 p-8 bg-gradient-to-br from-bambu-card to-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary shadow-lg`,children:[(0,G.jsxs)(`div`,{className:`text-center`,children:[(0,G.jsx)(`div`,{className:`flex items-center justify-center mb-6`,children:(0,G.jsx)(`img`,{src:r===`dark`?`/img/bambuddy_logo_dark_transparent.png`:`/img/bambuddy_logo_light.png`,alt:`Bambuddy`,className:`h-16`})}),(0,G.jsx)(`h2`,{className:`text-3xl font-bold text-white`,children:t(`setup.title`)}),(0,G.jsx)(`p`,{className:`mt-2 text-sm text-bambu-gray`,children:t(`setup.subtitle`)})]}),(0,G.jsxs)(`form`,{className:`mt-8 space-y-6`,onSubmit:e=>{if(e.preventDefault(),a&&(s||l)){if(!s||!l){n(t(`setup.toast.enterBothCredentials`),`error`);return}if(l!==d){n(t(`setup.toast.passwordsDoNotMatch`),`error`);return}if(l.length<6){n(t(`setup.toast.passwordTooShort`),`error`);return}}p.mutate()},children:[(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center p-4 bg-bambu-dark-secondary/50 rounded-lg border border-bambu-dark-tertiary`,children:[(0,G.jsx)(`input`,{id:`auth-enabled`,type:`checkbox`,checked:a,onChange:e=>o(e.target.checked),className:`h-4 w-4 text-bambu-green focus:ring-bambu-green border-bambu-dark-tertiary rounded bg-bambu-dark-secondary`}),(0,G.jsx)(`label`,{htmlFor:`auth-enabled`,className:`ml-3 block text-sm font-medium text-white`,children:t(`setup.enableAuth`)})]}),a&&(0,G.jsxs)(`div`,{className:`space-y-4 mt-4`,children:[(0,G.jsx)(`div`,{className:`p-3 bg-bambu-dark-secondary/50 border border-bambu-dark-tertiary rounded-lg`,children:(0,G.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,G.jsx)(Wc,{className:`w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0`}),(0,G.jsxs)(`div`,{className:`text-sm text-bambu-gray`,children:[(0,G.jsx)(`p`,{className:`text-white font-medium mb-1`,children:t(`setup.adminAccount`)}),(0,G.jsx)(`p`,{children:t(`setup.adminAccountDesc`)})]})]})}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{htmlFor:`admin-username`,className:`block text-sm font-medium text-white mb-2`,children:[t(`setup.adminUsername`),` `,(0,G.jsx)(`span`,{className:`text-bambu-gray text-xs`,children:t(`setup.optionalIfAdminExists`)})]}),(0,G.jsx)(`input`,{id:`admin-username`,type:`text`,value:s,onChange:e=>c(e.target.value),className:`block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:t(`setup.adminUsernamePlaceholder`),autoComplete:`username`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{htmlFor:`admin-password`,className:`block text-sm font-medium text-white mb-2`,children:[t(`setup.adminPassword`),` `,(0,G.jsx)(`span`,{className:`text-bambu-gray text-xs`,children:t(`setup.optionalIfAdminExists`)})]}),(0,G.jsx)(`input`,{id:`admin-password`,type:`password`,value:l,onChange:e=>u(e.target.value),className:`block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:t(`setup.adminPasswordPlaceholder`),minLength:6,autoComplete:`new-password`})]}),l&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{htmlFor:`confirm-password`,className:`block text-sm font-medium text-white mb-2`,children:t(`setup.confirmPassword`)}),(0,G.jsx)(`input`,{id:`confirm-password`,type:`password`,value:d,onChange:e=>f(e.target.value),className:`block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:t(`setup.confirmPasswordPlaceholder`),minLength:6,autoComplete:`new-password`})]})]})]}),(0,G.jsx)(`div`,{children:(0,G.jsx)(`button`,{type:`submit`,disabled:p.isPending,className:`w-full flex justify-center py-3 px-4 bg-bambu-green hover:bg-bambu-green-light text-white font-medium rounded-lg shadow-lg shadow-bambu-green/20 hover:shadow-bambu-green/30 focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:ring-offset-2 focus:ring-offset-bambu-dark-secondary transition-all disabled:opacity-50 disabled:cursor-not-allowed disabled:hover:bg-bambu-green`,children:p.isPending?t(`setup.settingUp`):t(`setup.completeSetup`)})})]})]})})}function b0e(){let{t:e}=U(),{user:t}=Nd(),{showToast:n}=qd(),r=co(),i=or(),[a,o]=(0,y.useState)(!0),[s,c]=(0,y.useState)(!0),[l,u]=(0,y.useState)(!0),[d,f]=(0,y.useState)(!0),[p,m]=(0,y.useState)(!1),{data:h,isLoading:g}=K({queryKey:[`advancedAuthStatus`],queryFn:Z.getAdvancedAuthStatus,staleTime:300*1e3}),{data:_,isLoading:v}=K({queryKey:[`settings`],queryFn:Z.getSettings,staleTime:300*1e3}),{data:b,isLoading:x}=K({queryKey:[`user-email-preferences`],queryFn:()=>Z.getUserEmailPreferences()});(0,y.useEffect)(()=>{(h&&!h.advanced_auth_enabled||_&&!_.user_notifications_enabled)&&i(`/settings`,{replace:!0})},[h,_,i]),(0,y.useEffect)(()=>{b&&(o(b.notify_print_start),c(b.notify_print_complete),u(b.notify_print_failed),f(b.notify_print_stopped),m(!1))},[b]);let S=q({mutationFn:()=>Z.updateUserEmailPreferences({notify_print_start:a,notify_print_complete:s,notify_print_failed:l,notify_print_stopped:d}),onSuccess:()=>{r.invalidateQueries({queryKey:[`user-email-preferences`]}),m(!1),n(e(`notifications.userEmail.saveSuccess`),`success`)},onError:t=>{n(t.message||e(`notifications.userEmail.saveError`),`error`)}}),C=(e,t)=>{e(!t),m(!0)};return x||g||v?(0,G.jsx)(`div`,{className:`flex items-center justify-center h-64`,children:(0,G.jsx)(Y,{className:`w-8 h-8 animate-spin text-bambu-green`})}):(0,G.jsxs)(`div`,{className:`p-4 md:p-6 max-w-2xl mx-auto`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3 mb-6`,children:[(0,G.jsx)(qo,{className:`w-7 h-7 text-bambu-green`}),(0,G.jsx)(`h1`,{className:`text-2xl font-bold text-white`,children:e(`notifications.userEmail.title`)})]}),(0,G.jsx)(zd,{className:`mb-6 border-blue-300 bg-blue-50 dark:border-blue-500/30 dark:bg-blue-500/5`,children:(0,G.jsx)(Vd,{className:`py-4`,children:(0,G.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,G.jsx)(`div`,{className:`w-10 h-10 rounded-full flex items-center justify-center bg-blue-100 dark:bg-blue-500/20 flex-shrink-0`,children:(0,G.jsx)(al,{className:`w-5 h-5 text-blue-600 dark:text-blue-400`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`text-white font-medium`,children:e(`notifications.userEmail.emailNotifications`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:e(`notifications.userEmail.emailNotificationsDesc`)}),t?.email?(0,G.jsxs)(`p`,{className:`text-sm text-blue-700 dark:text-blue-400 mt-2`,children:[e(`notifications.userEmail.sendingTo`),`: `,(0,G.jsx)(`strong`,{children:t.email})]}):(0,G.jsx)(`p`,{className:`text-sm text-yellow-700 dark:text-yellow-400 mt-2`,children:e(`notifications.userEmail.noEmailWarning`)})]})]})})}),(0,G.jsxs)(zd,{className:`mb-6`,children:[(0,G.jsxs)(Bd,{children:[(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`notifications.userEmail.printJobNotifications`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:e(`notifications.userEmail.printJobNotificationsDesc`)})]}),(0,G.jsxs)(Vd,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-4 bg-bambu-dark rounded-lg`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`w-10 h-10 rounded-full flex items-center justify-center ${a?`bg-bambu-green/20`:`bg-bambu-dark-tertiary`}`,children:(0,G.jsx)(Ss,{className:`w-5 h-5 ${a?`text-bambu-green`:`text-bambu-gray`}`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white font-medium`,children:e(`notifications.userEmail.printJobStarts`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`notifications.userEmail.printJobStartsDesc`)})]})]}),(0,G.jsx)(`button`,{onClick:()=>C(o,a),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors focus:outline-none focus:ring-2 focus:ring-bambu-green focus:ring-offset-2 focus:ring-offset-bambu-dark ${a?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,role:`switch`,"aria-checked":a,children:(0,G.jsx)(`span`,{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${a?`translate-x-6`:`translate-x-1`}`})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-4 bg-bambu-dark rounded-lg`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`w-10 h-10 rounded-full flex items-center justify-center ${s?`bg-bambu-green/20`:`bg-bambu-dark-tertiary`}`,children:(0,G.jsx)(Ss,{className:`w-5 h-5 ${s?`text-bambu-green`:`text-bambu-gray`}`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white font-medium`,children:e(`notifications.userEmail.printJobFinishes`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`notifications.userEmail.printJobFinishesDesc`)})]})]}),(0,G.jsx)(`button`,{onClick:()=>C(c,s),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors focus:outline-none focus:ring-2 focus:ring-bambu-green focus:ring-offset-2 focus:ring-offset-bambu-dark ${s?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,role:`switch`,"aria-checked":s,children:(0,G.jsx)(`span`,{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${s?`translate-x-6`:`translate-x-1`}`})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-4 bg-bambu-dark rounded-lg`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`w-10 h-10 rounded-full flex items-center justify-center ${l?`bg-bambu-green/20`:`bg-bambu-dark-tertiary`}`,children:(0,G.jsx)(Ss,{className:`w-5 h-5 ${l?`text-bambu-green`:`text-bambu-gray`}`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white font-medium`,children:e(`notifications.userEmail.printErrors`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`notifications.userEmail.printErrorsDesc`)})]})]}),(0,G.jsx)(`button`,{onClick:()=>C(u,l),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors focus:outline-none focus:ring-2 focus:ring-bambu-green focus:ring-offset-2 focus:ring-offset-bambu-dark ${l?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,role:`switch`,"aria-checked":l,children:(0,G.jsx)(`span`,{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${l?`translate-x-6`:`translate-x-1`}`})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-4 bg-bambu-dark rounded-lg`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`w-10 h-10 rounded-full flex items-center justify-center ${d?`bg-bambu-green/20`:`bg-bambu-dark-tertiary`}`,children:(0,G.jsx)(Ss,{className:`w-5 h-5 ${d?`text-bambu-green`:`text-bambu-gray`}`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white font-medium`,children:e(`notifications.userEmail.printJobStops`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`notifications.userEmail.printJobStopsDesc`)})]})]}),(0,G.jsx)(`button`,{onClick:()=>C(f,d),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors focus:outline-none focus:ring-2 focus:ring-bambu-green focus:ring-offset-2 focus:ring-offset-bambu-dark ${d?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,role:`switch`,"aria-checked":d,children:(0,G.jsx)(`span`,{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${d?`translate-x-6`:`translate-x-1`}`})})]})]})]}),(0,G.jsx)(`div`,{className:`flex justify-end`,children:(0,G.jsx)(Q,{onClick:()=>S.mutate(),disabled:!p||S.isPending||!t?.email,children:S.isPending?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),e(`common.saving`)]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(ql,{className:`w-4 h-4`}),e(`common.save`)]})})})]})}function x0e(){let e=or(),[t,n]=Ri(),{t:r}=U(),i=t.get(`archive`),a=t.get(`library_file`),o=t.get(`plate`),s=K({queryKey:[`gcode-viewer-archive-colors`,i],queryFn:()=>Z.getArchiveCapabilities(Number(i)),enabled:!!i,staleTime:5*6e4,retry:!1}),c=K({queryKey:[`gcode-viewer-library-colors`,a],queryFn:()=>Z.getLibraryFilePlates(Number(a)),enabled:!!a,staleTime:5*6e4,retry:!1}),l=K({queryKey:[`gcode-viewer-archive-plates`,i],queryFn:()=>Z.getArchivePlates(Number(i)),enabled:!!i,staleTime:5*6e4,retry:!1}),u=(0,y.useMemo)(()=>(i?l.data?.plates:c.data?.plates)??[],[i,l.data,c.data]),d=(0,y.useMemo)(()=>o?Number(o):u.length===0?null:Math.min(...u.map(e=>e.index)),[o,u]),f=e=>{if(e===d)return;let r=new URLSearchParams(t);r.set(`plate`,String(e)),n(r,{replace:!0})},p=(0,y.useMemo)(()=>{if(i)return s.data?.filament_colors;let e=u.find(e=>e.index===d)||u[0];if(!e?.filaments?.length)return;let t=[];for(let n of e.filaments){let e=Math.max(0,(n.slot_id??1)-1);n.color&&(t[e]=n.color)}return t.length>0?t:void 0},[i,s.data,u,d]),m=(0,y.useMemo)(()=>{let e=e=>o?`${e}?plate=${encodeURIComponent(o)}`:e;return i?e(Z.getArchiveGcode(Number(i))):a?e(Z.getLibraryFileGcodeUrl(Number(a))):null},[i,a,o]),h=()=>{window.history.length>1?e(-1):e(i?`/archives`:`/files`)},g=i?r(`gcodeViewer.backToArchives`,`Back to Archives`):r(`gcodeViewer.backToFiles`,`Back to File Manager`);return(0,G.jsxs)(`div`,{className:`flex flex-col min-h-[calc(100vh-64px)] lg:h-[calc(100vh-64px)]`,children:[(0,G.jsxs)(`div`,{className:`flex-shrink-0 px-4 py-2 border-b border-bambu-dark-tertiary flex flex-wrap items-center gap-x-4 gap-y-2`,children:[(0,G.jsxs)(`button`,{type:`button`,onClick:h,className:`inline-flex items-center gap-1.5 text-sm text-gray-700 dark:text-gray-300 hover:text-gray-900 dark:hover:text-white transition-colors`,children:[(0,G.jsx)(Lo,{className:`w-4 h-4`}),g]}),u.length>1&&(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:r(`gcodeViewer.plates`,`Plates`)}),u.map(e=>(0,G.jsx)(`button`,{type:`button`,onClick:()=>f(e.index),"aria-pressed":e.index===d,title:e.name??void 0,className:`px-2 py-0.5 rounded text-xs transition-colors ${e.index===d?`bg-bambu-green text-white`:`bg-bambu-dark-tertiary text-gray-700 dark:text-gray-300 hover:text-gray-900 dark:hover:text-white`}`,children:r(`gcodeViewer.plateN`,`Plate {{n}}`,{n:e.index})},e.index))]})]}),m?(0,G.jsx)(gT,{gcodeUrl:m,filamentColors:p,className:`flex-1 min-h-0`}):(0,G.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-sm text-bambu-gray`,children:r(`gcodeViewer.noSource`,`No file was given to preview.`)})]})}var S0e=4401;function C0e(){let e=(0,y.useRef)(null),t=(0,y.useRef)(null),n=(0,y.useRef)(!1),r=co(),[i,a]=(0,y.useState)(!1),o=(0,y.useRef)(new Map),{showToast:s}=qd(),{t:c}=U(),l=(0,y.useRef)(new Set),u=(0,y.useRef)(null),d=(0,y.useRef)(new Map),f=(0,y.useRef)(null),p=(0,y.useRef)([]),m=(0,y.useRef)(!1),h=(0,y.useRef)(()=>{}),g=(0,y.useCallback)(()=>{if(m.current||p.current.length===0)return;m.current=!0;let e=()=>{let t=p.current.shift();t?(h.current(t),p.current.length>0?setTimeout(e,16):m.current=!1):m.current=!1};e()},[]),_=(0,y.useCallback)(async()=>{if(n.current||e.current?.readyState===WebSocket.OPEN)return;let r;try{r=(await Z.getWebSocketToken()).token}catch(e){let t=e instanceof sd?e.status:0;if(t===401||t===403)return}if(n.current)return;let i=window.location.protocol===`https:`?`wss:`:`ws:`,o=r?`?token=${encodeURIComponent(r)}`:``,s=`${i}//${window.location.host}/api/v1/ws${o}`,c=new WebSocket(s),l=null;c.onopen=()=>{console.log(`[WebSocket] Connected`),a(!0),l=window.setInterval(()=>{c.readyState===WebSocket.OPEN&&c.send(JSON.stringify({type:`ping`}))},3e4)},c.onmessage=e=>{try{let t=JSON.parse(e.data);t.type===`printer_status`&&t.printer_id!==void 0&&t.data?h.current(t):(p.current.push(t),g())}catch{}},c.onclose=r=>{console.log(`[WebSocket] Closed`,r.code,r.reason),l&&=(clearInterval(l),null),a(!1),e.current=null,!(n.current||r.code===S0e)&&(t.current=window.setTimeout(()=>{_()},3e3))},c.onerror=e=>{console.error(`[WebSocket] Error`,e),c.close()},e.current=c},[g]),v=(0,y.useCallback)(()=>{f.current&&=(clearTimeout(f.current),null);let e=new Map(d.current);d.current.clear(),e.forEach((e,t)=>{r.setQueryData([`printerStatus`,t],t=>{let n={...t,...e};return n.wifi_signal==null&&t?.wifi_signal!=null&&(n.wifi_signal=t.wifi_signal),n})})},[r]),b=(0,y.useCallback)((e,t)=>{let n=d.current.get(e)||{};if(d.current.set(e,{...n,...t}),document.hidden){v();return}f.current||=window.setTimeout(v,100)},[v]),x=(0,y.useCallback)(e=>{l.current.add(e),u.current&&clearTimeout(u.current),u.current=window.setTimeout(()=>{let e=Array.from(l.current);l.current.clear(),u.current=null;let t=0;e.forEach(e=>{setTimeout(()=>{r.invalidateQueries({queryKey:[e]})},t),t+=500})},3e3)},[r]),S=(0,y.useCallback)(()=>{r.invalidateQueries({queryKey:[`spool-assignments`]}),r.invalidateQueries({queryKey:[`spoolman-slot-assignments`]}),r.invalidateQueries({queryKey:[`slotPresets`]})},[r]),C=(0,y.useCallback)(e=>{switch(e.type){case`printer_status`:e.printer_id!==void 0&&e.data&&b(e.printer_id,e.data);break;case`print_start`:e.printer_id!==void 0&&r.invalidateQueries({queryKey:[`printerStatus`,e.printer_id]});break;case`missing_spool_assignment`:{if(e.printer_id===void 0||!Array.isArray(e.missing_slots))break;let t=e.missing_slots.map(e=>e&&typeof e.slot==`string`?e.slot:`Unknown`).filter(e=>e.length>0);if(t.length===0){o.current.delete(e.printer_id);break}let n=t.join(`|`);if(o.current.get(e.printer_id)===n)break;o.current.set(e.printer_id,n),s(c(`printers.toast.missingSpoolAssignment`,{printer:e.printer_name||`Printer ${e.printer_id}`,slots:t.join(`, `)}),`warning`);break}case`print_complete`:x(`archives`),x(`archiveStats`);break;case`kill_switch_triggered`:s(c(`printers.toast.killSwitchTriggered`,{printer:e.printer_name||`Printer ${e.printer_id??`?`}`,filename:e.filename||c(`common.unknown`)}),`error`);break;case`billing_charge_failed`:s(c(`printers.toast.billingChargeFailed`,{printer:e.printer_name||`Printer ${e.printer_id??`?`}`,filename:e.filename||c(`common.unknown`)}),`error`);break;case`archive_created`:x(`archives`),x(`archiveStats`);break;case`archive_updated`:x(`archives`);break;case`pong`:break;case`plate_not_empty`:window.dispatchEvent(new CustomEvent(`plate-not-empty`,{detail:{printer_id:e.printer_id,printer_name:e.printer_name,message:e.message}}));break;case`inventory_changed`:x(`inventory-spools`),x(`spoolman-inventory-spools`),x(v6[0]);break;case`spool_assignment_changed`:S();break;case`spool_assignment_verified`:{let t=e.printer_name||`Printer`,n=e.slot||`?`;e.verified?e.kprofile_applied===!1?s(c(`printers.toast.assignmentVerifiedNoKprofile`,{slot:n,printer:t}),`warning`):s(c(`printers.toast.assignmentVerified`,{slot:n,printer:t}),`success`):s(c(`printers.toast.assignmentNotConfirmed`,{slot:n,printer:t}),`warning`);break}case`spool_auto_assigned`:x(`inventory-spools`),S();break;case`spool_usage_logged`:x(`inventory-spools`);break;case`unknown_tag`:{let t=e;window.dispatchEvent(new CustomEvent(`unknown-tag`,{detail:{printer_id:t.printer_id,ams_id:t.ams_id,tray_id:t.tray_id,tag_uid:t.tag_uid,tray_uuid:t.tray_uuid,tray_type:t.tray_type,tray_color:t.tray_color,tray_sub_brands:t.tray_sub_brands,tray_count:t.tray_count}}));break}case`spoolbuddy_weight`:window.dispatchEvent(new CustomEvent(`spoolbuddy-weight`,{detail:e}));break;case`spoolbuddy_tag_matched`:window.dispatchEvent(new CustomEvent(`spoolbuddy-tag-matched`,{detail:e})),x(`inventory-spools`);break;case`spoolbuddy_unknown_tag`:window.dispatchEvent(new CustomEvent(`spoolbuddy-unknown-tag`,{detail:e}));break;case`spoolbuddy_tag_removed`:window.dispatchEvent(new CustomEvent(`spoolbuddy-tag-removed`,{detail:e}));break;case`spoolbuddy_tag_written`:window.dispatchEvent(new CustomEvent(`spoolbuddy-tag-written`,{detail:e})),x(`inventory-spools`);break;case`spoolbuddy_tag_write_failed`:window.dispatchEvent(new CustomEvent(`spoolbuddy-tag-write-failed`,{detail:e}));break;case`spoolbuddy_online`:window.dispatchEvent(new CustomEvent(`spoolbuddy-online`,{detail:e})),x(`spoolbuddy-devices`),x(`spoolbuddy-update-check`);break;case`spoolbuddy_offline`:window.dispatchEvent(new CustomEvent(`spoolbuddy-offline`,{detail:e})),x(`spoolbuddy-devices`);break;case`spoolbuddy_update`:x(`spoolbuddy-devices`),x(`spoolbuddy-update-check`);break;case`queue_item_uploading`:case`queue_item_upload_progress`:case`queue_item_acked`:case`queue_item_failed`:window.dispatchEvent(new CustomEvent(`bambuddy:dispatch-toast`,{detail:e}));break;case`pipeline_run_updated`:r.invalidateQueries({queryKey:[`pipeline-runs-all`]}),e.run?.pipeline_id&&r.invalidateQueries({queryKey:[`pipeline-runs`,e.run.pipeline_id]});break}},[r,x,S,b,s,c]);return(0,y.useEffect)(()=>{h.current=C},[C]),(0,y.useEffect)(()=>(n.current=!1,_(),()=>{n.current=!0,t.current&&clearTimeout(t.current),u.current&&clearTimeout(u.current),f.current&&clearTimeout(f.current),e.current&&e.current.close()}),[_]),{isConnected:i,sendMessage:(0,y.useCallback)(t=>{e.current?.readyState===WebSocket.OPEN&&e.current.send(JSON.stringify(t))},[])}}var w0e=`#00ae42`,T0e=e=>e!=null&&e>0?e:1/0;function E0e(e){let t=null;for(let n of e){if(!n||n.state!==`RUNNING`||n.progress==null)continue;if(t===null){t=n;continue}let e=T0e(n.remaining_time),r=T0e(t.remaining_time);(e(t.progress??0))&&(t=n)}return t}function D0e(e){let t=document.createElement(`canvas`);t.width=32,t.height=32;let n=t.getContext(`2d`);if(!n)return null;let r=getComputedStyle(document.documentElement).getPropertyValue(`--accent`).trim()||w0e,i=Math.max(0,Math.min(100,e))/100,a=-Math.PI/2;return n.lineWidth=4,n.beginPath(),n.arc(16,16,13,0,Math.PI*2),n.strokeStyle=`rgba(128,128,128,0.3)`,n.stroke(),n.beginPath(),n.arc(16,16,13,a,a+i*Math.PI*2),n.strokeStyle=r,n.lineCap=`round`,n.stroke(),t.toDataURL(`image/png`)}function B9(e,t){document.querySelectorAll(`link[rel~="icon"]`).forEach(n=>{if(e)t.has(n)||t.set(n,n.href),n.href=e;else{let e=t.get(n);e!==void 0&&(n.href=e)}}),e||t.clear()}function O0e(){let{progressInTitle:e,resolvedMode:t,darkAccent:n,lightAccent:r}=Id(),i=t===`dark`?n:r,{data:a}=K({queryKey:[`printers`],queryFn:Z.getPrinters,enabled:e}),o=Co({queries:(e?a??[]:[]).map(e=>({queryKey:[`printerStatus`,e.id],queryFn:()=>Z.getPrinterStatus(e.id)}))}),s=(0,y.useRef)(new Map),c=(0,y.useRef)(document.title),l=(0,y.useRef)(!1),u=e?E0e(o.map(e=>e.data)):null,d=u&&u.progress!=null?Math.round(u.progress):null;(0,y.useEffect)(()=>{e&&d!=null?(document.title=`${d}% · ${c.current}`,B9(D0e(d),s.current),l.current=!0):l.current&&=(document.title=c.current,B9(null,s.current),!1)},[e,d,i]),(0,y.useEffect)(()=>{let e=s.current,t=l,n=c.current;return()=>{t.current&&(document.title=n,B9(null,e))}},[])}function k0e({children:e}){let{authEnabled:t,user:n,loading:r}=Nd(),{data:i}=K({queryKey:[`color-catalog-map`],queryFn:async()=>{let e=await Z.getColorNameMap();return{colors:e.colors,byMaterial:e.by_material??{}}},staleTime:1/0,gcTime:1/0,retry:2,enabled:!r&&(!t||n!==null)});return(0,y.useEffect)(()=>{i&&vf(i.colors,i.byMaterial)},[i]),(0,G.jsx)(G.Fragment,{children:e})}function A0e({selectedPrinterId:e,onPrinterChange:t,deviceOnline:n}){let{t:r}=U(),[i,a]=(0,y.useState)(new Date),{data:o=[]}=K({queryKey:[`printers`],queryFn:()=>Z.getPrinters()}),s=Co({queries:o.map(e=>({queryKey:[`printerStatus`,e.id],queryFn:()=>Z.getPrinterStatus(e.id),refetchInterval:1e4}))}),c=(0,y.useMemo)(()=>o.filter((e,t)=>s[t]?.data?.connected),[o,s]);(0,y.useEffect)(()=>{let n=c.some(t=>t.id===e);(!e||!n)&&c.length>0&&t(c[0].id)},[c,e,t]);let{data:l}=K({queryKey:[`settings`],queryFn:Z.getSettings});return(0,y.useEffect)(()=>{let e=setInterval(()=>a(new Date),1e3);return()=>clearInterval(e)},[]),(0,G.jsxs)(`div`,{className:`h-12 bg-bambu-dark-secondary border-b border-bambu-dark-tertiary flex items-center px-3 gap-4 shrink-0`,children:[(0,G.jsx)(`div`,{className:`flex items-center shrink-0`,children:(0,G.jsx)(`img`,{src:`/img/spoolbuddy_logo_dark_small.png`,alt:`SpoolBuddy`,width:113,height:28,className:`h-7 w-auto`})}),(0,G.jsx)(`div`,{className:`flex-1 flex justify-center`,children:(0,G.jsx)(`select`,{value:e??``,onChange:e=>t(Number(e.target.value)),className:`bg-bambu-dark text-white text-base px-4 py-2 rounded border border-bambu-dark-tertiary focus:outline-none focus:border-bambu-green min-w-[180px]`,children:c.length===0?(0,G.jsx)(`option`,{value:``,children:r(`spoolbuddy.status.noPrinters`,`No printers online`)}):c.map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.name},e.id))})}),(0,G.jsxs)(`div`,{className:`flex items-center gap-3 shrink-0`,children:[(0,G.jsx)(`div`,{className:`flex items-center`,title:n?r(`spoolbuddy.status.backend`,`Backend`):r(`spoolbuddy.status.offline`,`Offline`),children:n?(0,G.jsx)(`div`,{className:`flex items-end gap-0.5 h-4`,children:[1,2,3,4].map(e=>(0,G.jsx)(`div`,{className:`w-1 rounded-sm ${e<=4?`bg-white`:`bg-bambu-dark-tertiary`}`,style:{height:`${e*4}px`}},e))}):(0,G.jsx)(Zu,{className:`w-5 h-5 text-red-400`})}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,G.jsx)(`div`,{className:`w-3 h-3 rounded-full ${n?`bg-bambu-green shadow-[0_0_6px_rgba(34,197,94,0.5)]`:`bg-bambu-gray`}`}),(0,G.jsx)(`span`,{className:`text-sm text-white/50`,children:n?r(`spoolbuddy.status.backend`,`Backend`):r(`spoolbuddy.status.offline`,`Offline`)})]}),(0,G.jsx)(`span`,{className:`text-white/50 text-base font-mono min-w-[50px] text-right`,children:sp(i,l?.time_format||`system`)})]})]})}var j0e=[{to:`/spoolbuddy`,labelKey:`spoolbuddy.nav.dashboard`,fallback:`Dashboard`,icon:(0,G.jsx)(`svg`,{className:`w-6 h-6`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M3 12l2-2m0 0l7-7 7 7M5 10v10a1 1 0 001 1h3m10-11l2 2m-2-2v10a1 1 0 01-1 1h-3m-6 0a1 1 0 001-1v-4a1 1 0 011-1h2a1 1 0 011 1v4a1 1 0 001 1m-6 0h6`})})},{to:`/spoolbuddy/ams`,labelKey:`spoolbuddy.nav.ams`,fallback:`AMS`,icon:(0,G.jsx)(`svg`,{className:`w-6 h-6`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10`})})},{to:`/spoolbuddy/write-tag`,labelKey:`spoolbuddy.nav.writeTag`,fallback:`Write`,icon:(0,G.jsxs)(`svg`,{className:`w-6 h-6`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:2,children:[(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M8.288 15.038a5.25 5.25 0 017.424 0M5.106 11.856c3.807-3.808 9.98-3.808 13.788 0M1.924 8.674c5.565-5.565 14.587-5.565 20.152 0`}),(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M12.53 18.22l-.53.53-.53-.53a.75.75 0 011.06 0z`})]})},{to:`/spoolbuddy/inventory`,labelKey:`spoolbuddy.nav.inventory`,fallback:`Inventory`,icon:(0,G.jsx)(`svg`,{className:`w-6 h-6`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M20 7l-8-4-8 4m16 0l-8 4m8-4v10l-8 4m0-10L4 7m8 4v10M4 7v10l8 4`})})},{to:`/spoolbuddy/settings`,labelKey:`spoolbuddy.nav.settings`,fallback:`Settings`,icon:(0,G.jsxs)(`svg`,{className:`w-6 h-6`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:[(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.066 2.573c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.573 1.066c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.066-2.573c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z`}),(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M15 12a3 3 0 11-6 0 3 3 0 016 0z`})]})}];function M0e(){let{t:e}=U();return(0,G.jsx)(`nav`,{className:`h-14 bg-bambu-dark-secondary border-t border-bambu-dark-tertiary flex items-stretch shrink-0`,children:j0e.map(t=>(0,G.jsxs)(ji,{to:t.to,end:t.to===`/spoolbuddy`,className:({isActive:e})=>`flex-1 flex flex-col items-center justify-center gap-1 transition-colors ${e?`text-bambu-green bg-bambu-dark`:`text-white/50 hover:text-white/70 hover:bg-bambu-dark-tertiary`}`,children:[t.icon,(0,G.jsx)(`span`,{className:`text-xs font-medium`,children:e(t.labelKey,t.fallback)})]},t.to))})}function N0e({alert:e}){let{t}=U(),n=e?e.type===`error`?`bg-red-500`:e.type===`warning`?`bg-amber-500`:`bg-bambu-green`:`bg-bambu-green`;return(0,G.jsxs)(`div`,{className:`h-9 bg-bambu-dark-secondary border-t-2 ${e?e.type===`error`?`border-red-500`:e.type===`warning`?`border-amber-500`:`border-bambu-dark-tertiary`:`border-bambu-dark-tertiary`} flex items-center px-3 gap-3 shrink-0`,children:[(0,G.jsx)(`div`,{className:`w-3.5 h-3.5 rounded-full ${n}`}),(0,G.jsx)(`div`,{className:`flex-1 text-sm text-white/50 truncate`,children:e?(0,G.jsx)(`span`,{children:e.message}):(0,G.jsx)(`span`,{className:`text-bambu-green`,children:t(`spoolbuddy.status.systemReady`,`System Ready`)})})]})}function P0e({isOpen:e,onClose:t,deviceId:n,deviceOnline:r}){let{t:i}=U(),[a,o]=(0,y.useState)(null),[s,c]=(0,y.useState)(!1),[l,u]=(0,y.useState)(new Map),{data:d=[]}=K({queryKey:[`printers`],queryFn:()=>Z.getPrinters(),enabled:e}),{data:f=[]}=K({queryKey:[`smart-plugs`],queryFn:()=>Z.getSmartPlugs(),enabled:e}),p=d.map(e=>{let t=f.find(t=>t.printer_id===e.id&&t.plug_type!==`mqtt`&&t.enabled);if(!t)return null;let n=l.get(t.id);return{plug:t,printer:e,status:n?{state:n.state,reachable:!0,device_name:null,energy:null}:null,loading:n?.loading??!1}}).filter(Boolean);(0,y.useEffect)(()=>{!e||f.length===0||f.filter(e=>e.printer_id!==null&&e.plug_type!==`mqtt`&&e.enabled).forEach(async e=>{try{let t=await Z.getSmartPlugStatus(e.id);u(n=>{let r=new Map(n);return r.set(e.id,{loading:!1,state:t.state}),r})}catch{u(t=>{let n=new Map(t);return n.set(e.id,{loading:!1,state:null}),n})}})},[e,f]),(0,y.useEffect)(()=>{e||(o(null),c(!1))},[e]);let m=(0,y.useCallback)(async e=>{u(t=>{let n=new Map(t),r=n.get(e.id);return n.set(e.id,{loading:!0,state:r?.state??null}),n});try{await Z.controlSmartPlug(e.id,`toggle`);let t=await Z.getSmartPlugStatus(e.id);u(n=>{let r=new Map(n);return r.set(e.id,{loading:!1,state:t.state}),r})}catch{u(t=>{let n=new Map(t),r=n.get(e.id);return n.set(e.id,{loading:!1,state:r?.state??null}),n})}},[]),h=(0,y.useCallback)(async e=>{if(n){c(!0);try{await Od.systemCommand(n,e),setTimeout(()=>t(),500)}catch{c(!1)}}},[n,t]),g=(0,y.useCallback)(()=>{a&&(a.type===`system`?h(a.command):m(a.plug),o(null))},[a,h,m]);if(!e)return null;let _=e=>e===`ON`||e===`on`;return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`fixed inset-0 z-40 bg-black/50`,onPointerDown:t}),(0,G.jsxs)(`div`,{className:`fixed top-0 left-0 right-0 z-50 bg-bambu-dark-secondary border-b border-bambu-dark-tertiary rounded-b-2xl shadow-2xl animate-slide-down`,children:[(0,G.jsx)(`div`,{className:`flex justify-center pt-2 pb-1`,children:(0,G.jsx)(`div`,{className:`w-10 h-1 rounded-full bg-zinc-600`})}),(0,G.jsxs)(`div`,{className:`px-4 pb-4 max-h-[80vh] overflow-y-auto`,children:[p.length>0&&(0,G.jsxs)(`div`,{className:`mb-4`,children:[(0,G.jsx)(`h3`,{className:`text-xs font-semibold text-zinc-500 uppercase tracking-wide mb-2`,children:i(`spoolbuddy.quickMenu.printerPower`,`Printer Power`)}),(0,G.jsx)(`div`,{className:`space-y-1`,children:p.map(({plug:e,printer:t,loading:n})=>{let r=l.get(e.id),i=_(r?.state??null);return(0,G.jsxs)(`button`,{onClick:()=>o({type:`plug`,plug:e,printer:t,currentState:r?.state??null}),disabled:n,className:`w-full flex items-center gap-2 px-3 py-1.5 rounded-lg bg-zinc-800/60 hover:bg-zinc-700/60 transition-colors min-h-[36px]`,children:[(0,G.jsx)(`div`,{className:`w-2 h-2 rounded-full shrink-0 ${i?`bg-green-500`:`bg-zinc-600`}`}),n&&(0,G.jsx)(Y,{className:`w-3 h-3 animate-spin text-zinc-400 shrink-0`}),(0,G.jsx)(`span`,{className:`flex-1 text-sm text-zinc-200 text-left truncate`,children:t.name}),(0,G.jsx)(`span`,{className:`text-xs font-medium ${i?`text-green-400`:`text-zinc-500`}`,children:r?.state??`—`})]},e.id)})})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`text-xs font-semibold text-zinc-500 uppercase tracking-wide mb-2`,children:i(`spoolbuddy.quickMenu.systemControls`,`System`)}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,G.jsx)(V9,{icon:(0,G.jsx)(Gl,{className:`w-4 h-4`}),label:i(`spoolbuddy.quickMenu.restartDaemon`,`Restart Daemon`),onClick:()=>o({type:`system`,command:`restart_daemon`}),disabled:!n||!r||s}),(0,G.jsx)(V9,{icon:(0,G.jsx)(gl,{className:`w-4 h-4`}),label:i(`spoolbuddy.quickMenu.restartBrowser`,`Restart Browser`),onClick:()=>o({type:`system`,command:`restart_browser`}),disabled:!n||!r||s}),(0,G.jsx)(V9,{icon:(0,G.jsx)(Gl,{className:`w-4 h-4`}),label:i(`spoolbuddy.quickMenu.reboot`,`Reboot`),onClick:()=>o({type:`system`,command:`reboot`}),disabled:!n||!r||s,variant:`warning`}),(0,G.jsx)(V9,{icon:(0,G.jsx)(Il,{className:`w-4 h-4`}),label:i(`spoolbuddy.quickMenu.shutdown`,`Shutdown`),onClick:()=>o({type:`system`,command:`shutdown`}),disabled:!n||!r||s,variant:`danger`})]})]}),(0,G.jsx)(`div`,{className:`flex justify-center mt-3`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-1 text-xs text-zinc-600`,children:[(0,G.jsx)(ps,{className:`w-3 h-3`}),(0,G.jsx)(`span`,{children:i(`spoolbuddy.quickMenu.swipeToClose`,`Swipe down to close`)})]})})]})]}),a&&(0,G.jsx)(`div`,{className:`fixed inset-0 z-[60] flex items-center justify-center bg-black/60`,children:(0,G.jsxs)(`div`,{className:`bg-zinc-800 rounded-2xl p-5 mx-4 max-w-sm w-full border border-zinc-700`,children:[(0,G.jsx)(`h3`,{className:`text-lg font-semibold text-zinc-100 mb-2`,children:i(`spoolbuddy.quickMenu.confirmTitle`,`Confirm`)}),(0,G.jsx)(`p`,{className:`text-sm text-zinc-400 mb-5`,children:a.type===`plug`?_(a.currentState)?i(`spoolbuddy.quickMenu.confirmPlugOff`,`Turn off {{name}}?`,{name:a.printer.name}):i(`spoolbuddy.quickMenu.confirmPlugOn`,`Turn on {{name}}?`,{name:a.printer.name}):a.command===`shutdown`?i(`spoolbuddy.quickMenu.confirmShutdown`,`Are you sure you want to shut down the SpoolBuddy? You will need physical access to turn it back on.`):a.command===`reboot`?i(`spoolbuddy.quickMenu.confirmReboot`,`Are you sure you want to reboot the SpoolBuddy?`):a.command===`restart_daemon`?i(`spoolbuddy.quickMenu.confirmRestartDaemon`,`Restart the SpoolBuddy daemon? NFC and scale will be temporarily unavailable.`):i(`spoolbuddy.quickMenu.confirmRestartBrowser`,`Restart the kiosk browser? The display will briefly go blank.`)}),(0,G.jsxs)(`div`,{className:`flex gap-3`,children:[(0,G.jsx)(`button`,{onClick:()=>o(null),className:`flex-1 px-4 py-2.5 rounded-lg text-sm font-medium bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors min-h-[44px]`,children:i(`common.cancel`,`Cancel`)}),(0,G.jsx)(`button`,{onClick:g,disabled:s,className:`flex-1 px-4 py-2.5 rounded-lg text-sm font-medium text-white transition-colors min-h-[44px] ${a.type===`plug`?_(a.currentState)?`bg-red-600 hover:bg-red-700`:`bg-green-600 hover:bg-green-700`:a.command===`shutdown`?`bg-red-600 hover:bg-red-700`:a.command===`reboot`?`bg-amber-600 hover:bg-amber-700`:`bg-blue-600 hover:bg-blue-700`} disabled:opacity-50`,children:s?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin mx-auto`}):a.type===`plug`?_(a.currentState)?i(`spoolbuddy.quickMenu.turnOff`,`Turn Off`):i(`spoolbuddy.quickMenu.turnOn`,`Turn On`):i(`spoolbuddy.quickMenu.confirm`,`Confirm`)})]})]})})]})}function V9({icon:e,label:t,onClick:n,disabled:r,variant:i=`default`}){return(0,G.jsxs)(`button`,{onClick:n,disabled:r,className:`flex items-center gap-2.5 p-3 rounded-xl transition-colors min-h-[48px] disabled:opacity-40 ${{default:`bg-zinc-800/60 hover:bg-zinc-700/60 text-zinc-300`,warning:`bg-amber-900/30 hover:bg-amber-900/50 text-amber-400`,danger:`bg-red-900/30 hover:bg-red-900/50 text-red-400`}[i]}`,children:[e,(0,G.jsx)(`span`,{className:`text-sm font-medium`,children:t})]})}var F0e={weight:null,weightStable:!1,rawAdc:null,matchedSpool:null,unknownTagUid:null,unknownTrayUuid:null,deviceOnline:!1,deviceId:null};function I0e(e,t){switch(t.type){case`WEIGHT_UPDATE`:return{...e,weight:t.weight,weightStable:t.stable,rawAdc:t.rawAdc,deviceId:t.deviceId,deviceOnline:!0};case`TAG_MATCHED`:return{...e,matchedSpool:t.spool,unknownTagUid:null,unknownTrayUuid:null,deviceId:t.deviceId};case`UNKNOWN_TAG`:return{...e,matchedSpool:null,unknownTagUid:t.tagUid,unknownTrayUuid:t.trayUuid??null,deviceId:t.deviceId};case`TAG_REMOVED`:return{...e,matchedSpool:null,unknownTagUid:null,unknownTrayUuid:null};case`DEVICE_ONLINE`:return{...e,deviceOnline:!0,deviceId:t.deviceId};case`DEVICE_OFFLINE`:return{...e,deviceOnline:!1,weight:null,weightStable:!1,rawAdc:null};default:return e}}function L0e(){let[e,t]=(0,y.useReducer)(I0e,F0e),n=(0,y.useCallback)(e=>{let n=e.detail;t({type:`WEIGHT_UPDATE`,weight:n.weight_grams??n.data?.weight_grams,stable:n.stable??n.data?.stable??!1,rawAdc:n.raw_adc??n.data?.raw_adc??null,deviceId:n.device_id??n.data?.device_id??``})},[]),r=(0,y.useCallback)(e=>{let n=e.detail,r=n.spool??n.data?.spool;r&&t({type:`TAG_MATCHED`,spool:{id:r.id,tag_uid:n.tag_uid??n.data?.tag_uid??``,material:r.material??``,subtype:r.subtype??null,color_name:r.color_name??null,rgba:r.rgba??null,brand:r.brand??null,label_weight:r.label_weight??0,core_weight:r.core_weight??0,weight_used:r.weight_used??0},deviceId:n.device_id??n.data?.device_id??``})},[]),i=(0,y.useCallback)(e=>{let n=e.detail;t({type:`UNKNOWN_TAG`,tagUid:n.tag_uid??n.data?.tag_uid??``,trayUuid:n.tray_uuid??n.data?.tray_uuid??null,deviceId:n.device_id??n.data?.device_id??``})},[]),a=(0,y.useCallback)(e=>{let n=e.detail;t({type:`TAG_REMOVED`,deviceId:n.device_id??n.data?.device_id??``})},[]),o=(0,y.useCallback)(e=>{let n=e.detail;t({type:`DEVICE_ONLINE`,deviceId:n.device_id??n.data?.device_id??``})},[]),s=(0,y.useCallback)(e=>{let n=e.detail;t({type:`DEVICE_OFFLINE`,deviceId:n.device_id??n.data?.device_id??``})},[]);(0,y.useEffect)(()=>(window.addEventListener(`spoolbuddy-weight`,n),window.addEventListener(`spoolbuddy-tag-matched`,r),window.addEventListener(`spoolbuddy-unknown-tag`,i),window.addEventListener(`spoolbuddy-tag-removed`,a),window.addEventListener(`spoolbuddy-online`,o),window.addEventListener(`spoolbuddy-offline`,s),()=>{window.removeEventListener(`spoolbuddy-weight`,n),window.removeEventListener(`spoolbuddy-tag-matched`,r),window.removeEventListener(`spoolbuddy-unknown-tag`,i),window.removeEventListener(`spoolbuddy-tag-removed`,a),window.removeEventListener(`spoolbuddy-online`,o),window.removeEventListener(`spoolbuddy-offline`,s)}),[n,r,i,a,o,s]);let c=e.matchedSpool?Math.max(0,e.matchedSpool.label_weight-e.matchedSpool.weight_used):null,l=e.weight!==null&&e.matchedSpool?Math.max(0,e.weight-e.matchedSpool.core_weight):null;return{...e,remainingWeight:c,netWeight:l}}var R0e=l(o(((e,t)=>{(function(n,r){typeof e==`object`&&typeof t==`object`?t.exports=r(f()):typeof define==`function`&&define.amd?define([`react`],r):typeof e==`object`?e.ReactSimpleKeyboard=r(f()):n.ReactSimpleKeyboard=r(n.React)})(e,(function(e){return function(){var t={981:function(){typeof Element>`u`||`remove`in Element.prototype||(Element.prototype.remove=function(){this.parentNode&&this.parentNode.removeChild(this)}),typeof self<`u`&&`document`in self&&((!(`classList`in document.createElement(`_`))||document.createElementNS&&!(`classList`in document.createElementNS(`http://www.w3.org/2000/svg`,`g`)))&&function(e){if(`Element`in e){var t=`classList`,n=`prototype`,r=e.Element[n],i=Object,a=String[n].trim||function(){return this.replace(/^\s+|\s+$/g,``)},o=Array[n].indexOf||function(e){for(var t=0,n=this.length;t1?arguments[1]:void 0)}},7916:function(e,t,n){var r=n(6080),i=n(9565),a=n(8981),o=n(6319),s=n(4209),c=n(3517),l=n(6198),u=n(4659),d=n(4527),f=n(81),p=n(851),m=Array;e.exports=function(e){var t=a(e),n=c(this),h=arguments.length,g=h>1?arguments[1]:void 0,_=g!==void 0;_&&(g=r(g,h>2?arguments[2]:void 0));var v,y,b,x,S,C,w=p(t),T=0;if(!w||this===m&&s(w))for(v=l(t),y=n?new this(v):m(v);v>T;T++)C=_?g(t[T],T):t[T],u(y,T,C);else for(y=n?new this:[],S=(x=f(t,w)).next;!(b=i(S,x)).done;T++)C=_?o(x,g,[b.value,T],!0):b.value,u(y,T,C);return d(y,T),y}},9617:function(e,t,n){var r=n(5397),i=n(5610),a=n(6198),o=function(e){return function(t,n,o){var s=r(t),c=a(s);if(c===0)return!e&&-1;var l,u=i(o,c);if(e&&n!=n){for(;c>u;)if((l=s[u++])!=l)return!0}else for(;c>u;u++)if((e||u in s)&&s[u]===n)return e||u||0;return!e&&-1}};e.exports={includes:o(!0),indexOf:o(!1)}},9213:function(e,t,n){var r=n(6080),i=n(7055),a=n(8981),o=n(6198),s=n(1469),c=n(4659),l=function(e){var t=e===1,n=e===2,l=e===3,u=e===4,d=e===6,f=e===7,p=e===5||d;return function(m,h,g){for(var _,v,y=a(m),b=i(y),x=o(b),S=r(h,g),C=0,w=0,T=t?s(m,x):n||f?s(m,0):void 0;x>C;C++)if((p||C in b)&&(v=S(_=b[C],C,y),e))if(t)c(T,C,v);else if(v)switch(e){case 3:return!0;case 5:return _;case 6:return C;case 2:c(T,w++,_)}else switch(e){case 4:return!1;case 7:c(T,w++,_)}return d?-1:l||u?u:T}};e.exports={forEach:l(0),map:l(1),filter:l(2),some:l(3),every:l(4),find:l(5),findIndex:l(6),filterReject:l(7)}},597:function(e,t,n){var r=n(9039),i=n(8227),a=n(9519),o=i(`species`);e.exports=function(e){return a>=51||!r((function(){var t=[];return(t.constructor={})[o]=function(){return{foo:1}},t[e](Boolean).foo!==1}))}},4598:function(e,t,n){var r=n(9039);e.exports=function(e,t){var n=[][e];return!!n&&r((function(){n.call(null,t||function(){return 1},1)}))}},926:function(e,t,n){var r=n(9306),i=n(8981),a=n(7055),o=n(6198),s=TypeError,c=`Reduce of empty array with no initial value`,l=function(e){return function(t,n,l,u){var d=i(t),f=a(d),p=o(d);if(r(n),p===0&&l<2)throw new s(c);var m=e?p-1:0,h=e?-1:1;if(l<2)for(;;){if(m in f){u=f[m],m+=h;break}if(m+=h,e?m<0:p<=m)throw new s(c)}for(;e?m>=0:p>m;m+=h)m in f&&(u=n(u,f[m],m,d));return u}};e.exports={left:l(!1),right:l(!0)}},4527:function(e,t,n){var r=n(3724),i=n(4376),a=TypeError,o=Object.getOwnPropertyDescriptor;e.exports=r&&!function(){if(this!==void 0)return!0;try{Object.defineProperty([],"length",{writable:!1}).length=1}catch(e){return e instanceof TypeError}}()?function(e,t){if(i(e)&&!o(e,`length`).writable)throw new a(`Cannot set read only .length`);return e.length=t}:function(e,t){return e.length=t}},7680:function(e,t,n){e.exports=n(9504)([].slice)},4488:function(e,t,n){var r=n(7680),i=Math.floor,a=function(e,t){var n=e.length;if(n<8)for(var o,s,c=1;c0;)e[s]=e[--s];s!==c++&&(e[s]=o)}else for(var l=i(n/2),u=a(r(e,0,l),t),d=a(r(e,l),t),f=u.length,p=d.length,m=0,h=0;m9007199254740991)throw t(`Maximum allowed index exceeded`);return e}},7400:function(e){e.exports={CSSRuleList:0,CSSStyleDeclaration:0,CSSValueList:0,ClientRectList:0,DOMRectList:0,DOMStringList:0,DOMTokenList:1,DataTransferItemList:0,FileList:0,HTMLAllCollection:0,HTMLCollection:0,HTMLFormElement:0,HTMLSelectElement:0,MediaList:0,MimeTypeArray:0,NamedNodeMap:0,NodeList:1,PaintRequestList:0,Plugin:0,PluginArray:0,SVGLengthList:0,SVGNumberList:0,SVGPathSegList:0,SVGPointList:0,SVGStringList:0,SVGTransformList:0,SourceBufferList:0,StyleSheetList:0,TextTrackCueList:0,TextTrackList:0,TouchList:0}},9296:function(e,t,n){var r=n(4055)(`span`).classList,i=r&&r.constructor&&r.constructor.prototype;e.exports=i===Object.prototype?void 0:i},8727:function(e){e.exports=[`constructor`,`hasOwnProperty`,`isPrototypeOf`,`propertyIsEnumerable`,`toLocaleString`,`toString`,`valueOf`]},3709:function(e,t,n){var r=n(2839).match(/firefox\/(\d+)/i);e.exports=!!r&&+r[1]},3763:function(e,t,n){var r=n(2839);e.exports=/MSIE|Trident/.test(r)},6193:function(e,t,n){e.exports=n(4215)===`NODE`},2839:function(e,t,n){var r=n(4576).navigator,i=r&&r.userAgent;e.exports=i?String(i):``},9519:function(e,t,n){var r,i,a=n(4576),o=n(2839),s=a.process,c=a.Deno,l=s&&s.versions||c&&c.version,u=l&&l.v8;u&&(i=(r=u.split(`.`))[0]>0&&r[0]<4?1:+(r[0]+r[1])),!i&&o&&(!(r=o.match(/Edge\/(\d+)/))||r[1]>=74)&&(r=o.match(/Chrome\/(\d+)/))&&(i=+r[1]),e.exports=i},3607:function(e,t,n){var r=n(2839).match(/AppleWebKit\/(\d+)\./);e.exports=!!r&&+r[1]},4215:function(e,t,n){var r=n(4576),i=n(2839),a=n(2195),o=function(e){return i.slice(0,e.length)===e};e.exports=o(`Bun/`)?`BUN`:o(`Cloudflare-Workers`)?`CLOUDFLARE`:o(`Deno/`)?`DENO`:o(`Node.js/`)?`NODE`:r.Bun&&typeof Bun.version==`string`?`BUN`:r.Deno&&typeof Deno.version==`object`?`DENO`:a(r.process)===`process`?`NODE`:r.window&&r.document?`BROWSER`:`REST`},6518:function(e,t,n){var r=n(4576),i=n(7347).f,a=n(6699),o=n(6840),s=n(9433),c=n(7740),l=n(2796);e.exports=function(e,t){var n,u,d,f,p,m=e.target,h=e.global,g=e.stat;if(n=h?r:g?r[m]||s(m,{}):r[m]&&r[m].prototype)for(u in t){if(f=t[u],d=e.dontCallGetSet?(p=i(n,u))&&p.value:n[u],!l(h?u:m+(g?`.`:`#`)+u,e.forced)&&d!==void 0){if(typeof f==typeof d)continue;c(f,d)}(e.sham||d&&d.sham)&&a(f,`sham`,!0),o(n,u,f,e)}}},9039:function(e){e.exports=function(e){try{return!!e()}catch{return!0}}},9228:function(e,t,n){n(7495);var r=n(9565),i=n(6840),a=n(7323),o=n(9039),s=n(8227),c=n(6699),l=s(`species`),u=RegExp.prototype;e.exports=function(e,t,n,d){var f=s(e),p=!o((function(){var t={};return t[f]=function(){return 7},``[e](t)!==7})),m=p&&!o((function(){var t=!1,n=/a/;if(e===`split`){var r={};r[l]=function(){return n},(n={constructor:r,flags:``})[f]=/./[f]}return n.exec=function(){return t=!0,null},n[f](``),!t}));if(!p||!m||n){var h=/./[f],g=t(f,``[e],(function(e,t,n,i,o){var s=t.exec;return s===a||s===u.exec?p&&!o?{done:!0,value:r(h,t,n,i)}:{done:!0,value:r(e,n,t,i)}:{done:!1}}));i(String.prototype,e,g[0]),i(u,f,g[1])}d&&c(u[f],`sham`,!0)}},8745:function(e,t,n){var r=n(616),i=Function.prototype,a=i.apply,o=i.call;e.exports=typeof Reflect==`object`&&Reflect.apply||(r?o.bind(a):function(){return o.apply(a,arguments)})},6080:function(e,t,n){var r=n(7476),i=n(9306),a=n(616),o=r(r.bind);e.exports=function(e,t){return i(e),t===void 0?e:a?o(e,t):function(){return e.apply(t,arguments)}}},616:function(e,t,n){e.exports=!n(9039)((function(){var e=function(){}.bind();return typeof e!=`function`||e.hasOwnProperty(`prototype`)}))},566:function(e,t,n){var r=n(9504),i=n(9306),a=n(34),o=n(9297),s=n(7680),c=n(616),l=Function,u=r([].concat),d=r([].join),f={};e.exports=c?l.bind:function(e){var t=i(this),n=t.prototype,r=s(arguments,1),c=function(){var n=u(r,s(arguments));return this instanceof c?function(e,t,n){if(!o(f,t)){for(var r=[],i=0;i]*>)/g,u=/\$([$&'`]|\d{1,2})/g;e.exports=function(e,t,n,r,d,f){var p=n+e.length,m=r.length,h=u;return d!==void 0&&(d=i(d),h=l),s(f,h,(function(i,s){var l;switch(o(s,0)){case`$`:return`$`;case`&`:return e;case"`":return c(t,0,n);case`'`:return c(t,p);case`<`:l=d[c(s,1,-1)];break;default:var u=+s;if(u===0)return i;if(u>m){var f=a(u/10);return f===0?i:f<=m?r[f-1]===void 0?o(s,1):r[f-1]+o(s,1):i}l=r[u-1]}return l===void 0?``:l}))}},4576:function(e,t,n){var r=function(e){return e&&e.Math===Math&&e};e.exports=r(typeof globalThis==`object`&&globalThis)||r(typeof window==`object`&&window)||r(typeof self==`object`&&self)||r(typeof n.g==`object`&&n.g)||r(typeof this==`object`&&this)||function(){return this}()||Function(`return this`)()},9297:function(e,t,n){var r=n(9504),i=n(8981),a=r({}.hasOwnProperty);e.exports=Object.hasOwn||function(e,t){return a(i(e),t)}},421:function(e){e.exports={}},397:function(e,t,n){e.exports=n(7751)(`document`,`documentElement`)},5917:function(e,t,n){var r=n(3724),i=n(9039),a=n(4055);e.exports=!r&&!i((function(){return Object.defineProperty(a(`div`),"a",{get:function(){return 7}}).a!==7}))},7055:function(e,t,n){var r=n(9504),i=n(9039),a=n(2195),o=Object,s=r(``.split);e.exports=i((function(){return!o(`z`).propertyIsEnumerable(0)}))?function(e){return a(e)===`String`?s(e,``):o(e)}:o},3167:function(e,t,n){var r=n(4901),i=n(34),a=n(2967);e.exports=function(e,t,n){var o,s;return a&&r(o=t.constructor)&&o!==n&&i(s=o.prototype)&&s!==n.prototype&&a(e,s),e}},3706:function(e,t,n){var r=n(9504),i=n(4901),a=n(7629),o=r(Function.toString);i(a.inspectSource)||(a.inspectSource=function(e){return o(e)}),e.exports=a.inspectSource},1181:function(e,t,n){var r,i,a,o=n(8622),s=n(4576),c=n(34),l=n(6699),u=n(9297),d=n(7629),f=n(6119),p=n(421),m=`Object already initialized`,h=s.TypeError,g=s.WeakMap;if(o||d.state){var _=d.state||=new g;_.get=_.get,_.has=_.has,_.set=_.set,r=function(e,t){if(_.has(e))throw new h(m);return t.facade=e,_.set(e,t),t},i=function(e){return _.get(e)||{}},a=function(e){return _.has(e)}}else{var v=f(`state`);p[v]=!0,r=function(e,t){if(u(e,v))throw new h(m);return t.facade=e,l(e,v,t),t},i=function(e){return u(e,v)?e[v]:{}},a=function(e){return u(e,v)}}e.exports={set:r,get:i,has:a,enforce:function(e){return a(e)?i(e):r(e,{})},getterFor:function(e){return function(t){var n;if(!c(t)||(n=i(t)).type!==e)throw new h(`Incompatible receiver, `+e+` required`);return n}}}},4209:function(e,t,n){var r=n(8227),i=n(6269),a=r(`iterator`),o=Array.prototype;e.exports=function(e){return e!==void 0&&(i.Array===e||o[a]===e)}},4376:function(e,t,n){var r=n(2195);e.exports=Array.isArray||function(e){return r(e)===`Array`}},4901:function(e){var t=typeof document==`object`&&document.all;e.exports=t===void 0&&t!==void 0?function(e){return typeof e==`function`||e===t}:function(e){return typeof e==`function`}},3517:function(e,t,n){var r=n(9504),i=n(9039),a=n(4901),o=n(6955),s=n(7751),c=n(3706),l=function(){},u=s(`Reflect`,`construct`),d=/^\s*(?:class|function)\b/,f=r(d.exec),p=!d.test(l),m=function(e){if(!a(e))return!1;try{return u(l,[],e),!0}catch{return!1}},h=function(e){if(!a(e))return!1;switch(o(e)){case`AsyncFunction`:case`GeneratorFunction`:case`AsyncGeneratorFunction`:return!1}try{return p||!!f(d,c(e))}catch{return!0}};h.sham=!0,e.exports=!u||i((function(){var e;return m(m.call)||!m(Object)||!m((function(){e=!0}))||e}))?h:m},2796:function(e,t,n){var r=n(9039),i=n(4901),a=/#|\.prototype\./,o=function(e,t){var n=c[s(e)];return n===u||n!==l&&(i(t)?r(t):!!t)},s=o.normalize=function(e){return String(e).replace(a,`.`).toLowerCase()},c=o.data={},l=o.NATIVE=`N`,u=o.POLYFILL=`P`;e.exports=o},2087:function(e,t,n){var r=n(34),i=Math.floor;e.exports=Number.isInteger||function(e){return!r(e)&&isFinite(e)&&i(e)===e}},4117:function(e){e.exports=function(e){return e==null}},34:function(e,t,n){var r=n(4901);e.exports=function(e){return typeof e==`object`?e!==null:r(e)}},3925:function(e,t,n){var r=n(34);e.exports=function(e){return r(e)||e===null}},6395:function(e){e.exports=!1},5810:function(e,t,n){var r=n(34),i=n(1181).get;e.exports=function(e){if(!r(e))return!1;var t=i(e);return!!t&&t.type===`RawJSON`}},788:function(e,t,n){var r=n(34),i=n(2195),a=n(8227)(`match`);e.exports=function(e){var t;return r(e)&&((t=e[a])===void 0?i(e)===`RegExp`:!!t)}},757:function(e,t,n){var r=n(7751),i=n(4901),a=n(1625),o=n(7040),s=Object;e.exports=o?function(e){return typeof e==`symbol`}:function(e){var t=r(`Symbol`);return i(t)&&a(t.prototype,s(e))}},9539:function(e,t,n){var r=n(9565),i=n(8551),a=n(5966);e.exports=function(e,t,n){var o,s;i(e);try{if(!(o=a(e,`return`))){if(t===`throw`)throw n;return n}o=r(o,e)}catch(e){s=!0,o=e}if(t===`throw`)throw n;if(s)throw o;return i(o),n}},3994:function(e,t,n){var r=n(7657).IteratorPrototype,i=n(2360),a=n(6980),o=n(687),s=n(6269),c=function(){return this};e.exports=function(e,t,n,l){var u=t+` Iterator`;return e.prototype=i(r,{next:a(+!l,n)}),o(e,u,!1,!0),s[u]=c,e}},1088:function(e,t,n){var r=n(6518),i=n(9565),a=n(6395),o=n(350),s=n(4901),c=n(3994),l=n(2787),u=n(2967),d=n(687),f=n(6699),p=n(6840),m=n(8227),h=n(6269),g=n(7657),_=o.PROPER,v=o.CONFIGURABLE,y=g.IteratorPrototype,b=g.BUGGY_SAFARI_ITERATORS,x=m(`iterator`),S=`keys`,C=`values`,w=`entries`,T=function(){return this};e.exports=function(e,t,n,o,m,g,E){c(n,t,o);var D,O,k,A=function(e){if(e===m&&F)return F;if(!b&&e&&e in N)return N[e];switch(e){case S:case C:case w:return function(){return new n(this,e)}}return function(){return new n(this)}},j=t+` Iterator`,M=!1,N=e.prototype,P=N[x]||N[`@@iterator`]||m&&N[m],F=!b&&P||A(m),I=t===`Array`&&N.entries||P;if(I&&(D=l(I.call(new e)))!==Object.prototype&&D.next&&(a||l(D)===y||(u?u(D,y):s(D[x])||p(D,x,T)),d(D,j,!0,!0),a&&(h[j]=T)),_&&m===C&&P&&P.name!==C&&(!a&&v?f(N,`name`,C):(M=!0,F=function(){return i(P,this)})),m)if(O={values:A(C),keys:g?F:A(S),entries:A(w)},E)for(k in O)(b||M||!(k in N))&&p(N,k,O[k]);else r({target:t,proto:!0,forced:b||M},O);return a&&!E||N[x]===F||p(N,x,F,{name:m}),h[t]=F,O}},7657:function(e,t,n){var r,i,a,o=n(9039),s=n(4901),c=n(34),l=n(2360),u=n(2787),d=n(6840),f=n(8227),p=n(6395),m=f(`iterator`),h=!1;[].keys&&(`next`in(a=[].keys())?(i=u(u(a)))!==Object.prototype&&(r=i):h=!0),!c(r)||o((function(){var e={};return r[m].call(e)!==e}))?r={}:p&&(r=l(r)),s(r[m])||d(r,m,(function(){return this})),e.exports={IteratorPrototype:r,BUGGY_SAFARI_ITERATORS:h}},6269:function(e){e.exports={}},6198:function(e,t,n){var r=n(8014);e.exports=function(e){return r(e.length)}},283:function(e,t,n){var r=n(9504),i=n(9039),a=n(4901),o=n(9297),s=n(3724),c=n(350).CONFIGURABLE,l=n(3706),u=n(1181),d=u.enforce,f=u.get,p=String,m=Object.defineProperty,h=r(``.slice),g=r(``.replace),_=r([].join),v=s&&!i((function(){return m((function(){}),`length`,{value:8}).length!==8})),y=String(String).split(`String`),b=e.exports=function(e,t,n){h(p(t),0,7)===`Symbol(`&&(t=`[`+g(p(t),/^Symbol\(([^)]*)\).*$/,`$1`)+`]`),n&&n.getter&&(t=`get `+t),n&&n.setter&&(t=`set `+t),(!o(e,`name`)||c&&e.name!==t)&&(s?m(e,`name`,{value:t,configurable:!0}):e.name=t),v&&n&&o(n,`arity`)&&e.length!==n.arity&&m(e,`length`,{value:n.arity});try{n&&o(n,`constructor`)&&n.constructor?s&&m(e,`prototype`,{writable:!1}):e.prototype&&=void 0}catch{}var r=d(e);return o(r,`source`)||(r.source=_(y,typeof t==`string`?t:``)),e};Function.prototype.toString=b((function(){return a(this)&&f(this).source||l(this)}),`toString`)},741:function(e){var t=Math.ceil,n=Math.floor;e.exports=Math.trunc||function(e){var r=+e;return(r>0?n:t)(r)}},7819:function(e,t,n){e.exports=!n(9039)((function(){var e=`9007199254740993`,t=JSON.rawJSON(e);return!JSON.isRawJSON(t)||JSON.stringify(t)!==e}))},5749:function(e,t,n){var r=n(788),i=TypeError;e.exports=function(e){if(r(e))throw new i(`The method doesn't accept regular expressions`);return e}},4213:function(e,t,n){var r=n(3724),i=n(9504),a=n(9565),o=n(9039),s=n(1072),c=n(3717),l=n(8773),u=n(8981),d=n(7055),f=Object.assign,p=Object.defineProperty,m=i([].concat);e.exports=!f||o((function(){if(r&&f({b:1},f(p({},`a`,{enumerable:!0,get:function(){p(this,`b`,{value:3,enumerable:!1})}}),{b:2})).b!==1)return!0;var e={},t={},n=Symbol(`assign detection`),i=`abcdefghijklmnopqrst`;return e[n]=7,i.split(``).forEach((function(e){t[e]=e})),f({},e)[n]!==7||s(f({},t)).join(``)!==i}))?function(e,t){for(var n=u(e),i=arguments.length,o=1,f=c.f,p=l.f;i>o;)for(var h,g=d(arguments[o++]),_=f?m(s(g),f(g)):s(g),v=_.length,y=0;v>y;)h=_[y++],r&&!a(p,g,h)||(n[h]=g[h]);return n}:f},2360:function(e,t,n){var r,i=n(8551),a=n(6801),o=n(8727),s=n(421),c=n(397),l=n(4055),u=n(6119),d=`prototype`,f=`script`,p=u(`IE_PROTO`),m=function(){},h=function(e){return`<`+f+`>`+e+``},g=function(e){e.write(h(``)),e.close();var t=e.parentWindow.Object;return e=null,t},_=function(){try{r=new ActiveXObject(`htmlfile`)}catch{}var e,t,n;_=typeof document<`u`?document.domain&&r?g(r):(t=l(`iframe`),n=`java`+f+`:`,t.style.display=`none`,c.appendChild(t),t.src=String(n),(e=t.contentWindow.document).open(),e.write(h(`document.F=Object`)),e.close(),e.F):g(r);for(var i=o.length;i--;)delete _[d][o[i]];return _()};s[p]=!0,e.exports=Object.create||function(e,t){var n;return e===null?n=_():(m[d]=i(e),n=new m,m[d]=null,n[p]=e),t===void 0?n:a.f(n,t)}},6801:function(e,t,n){var r=n(3724),i=n(8686),a=n(4913),o=n(8551),s=n(5397),c=n(1072);t.f=r&&!i?Object.defineProperties:function(e,t){o(e);for(var n,r=s(t),i=c(t),l=i.length,u=0;l>u;)a.f(e,n=i[u++],r[n]);return e}},4913:function(e,t,n){var r=n(3724),i=n(5917),a=n(8686),o=n(8551),s=n(6969),c=TypeError,l=Object.defineProperty,u=Object.getOwnPropertyDescriptor,d=`enumerable`,f=`configurable`,p=`writable`;t.f=r?a?function(e,t,n){if(o(e),t=s(t),o(n),typeof e==`function`&&t===`prototype`&&`value`in n&&p in n&&!n[p]){var r=u(e,t);r&&r[p]&&(e[t]=n.value,n={configurable:f in n?n[f]:r[f],enumerable:d in n?n[d]:r[d],writable:!1})}return l(e,t,n)}:l:function(e,t,n){if(o(e),t=s(t),o(n),i)try{return l(e,t,n)}catch{}if(`get`in n||`set`in n)throw new c(`Accessors not supported`);return`value`in n&&(e[t]=n.value),e}},7347:function(e,t,n){var r=n(3724),i=n(9565),a=n(8773),o=n(6980),s=n(5397),c=n(6969),l=n(9297),u=n(5917),d=Object.getOwnPropertyDescriptor;t.f=r?d:function(e,t){if(e=s(e),t=c(t),u)try{return d(e,t)}catch{}if(l(e,t))return o(!i(a.f,e,t),e[t])}},298:function(e,t,n){var r=n(2195),i=n(5397),a=n(8480).f,o=n(7680),s=typeof window==`object`&&window&&Object.getOwnPropertyNames?Object.getOwnPropertyNames(window):[];e.exports.f=function(e){return s&&r(e)===`Window`?function(e){try{return a(e)}catch{return o(s)}}(e):a(i(e))}},8480:function(e,t,n){var r=n(1828),i=n(8727).concat(`length`,`prototype`);t.f=Object.getOwnPropertyNames||function(e){return r(e,i)}},3717:function(e,t){t.f=Object.getOwnPropertySymbols},2787:function(e,t,n){var r=n(9297),i=n(4901),a=n(8981),o=n(6119),s=n(2211),c=o(`IE_PROTO`),l=Object,u=l.prototype;e.exports=s?l.getPrototypeOf:function(e){var t=a(e);if(r(t,c))return t[c];var n=t.constructor;return i(n)&&t instanceof n?n.prototype:t instanceof l?u:null}},1625:function(e,t,n){e.exports=n(9504)({}.isPrototypeOf)},1828:function(e,t,n){var r=n(9504),i=n(9297),a=n(5397),o=n(9617).indexOf,s=n(421),c=r([].push);e.exports=function(e,t){var n,r=a(e),l=0,u=[];for(n in r)!i(s,n)&&i(r,n)&&c(u,n);for(;t.length>l;)i(r,n=t[l++])&&(~o(u,n)||c(u,n));return u}},1072:function(e,t,n){var r=n(1828),i=n(8727);e.exports=Object.keys||function(e){return r(e,i)}},8773:function(e,t){var n={}.propertyIsEnumerable,r=Object.getOwnPropertyDescriptor;t.f=r&&!n.call({1:2},1)?function(e){var t=r(this,e);return!!t&&t.enumerable}:n},2551:function(e,t,n){var r=n(6395),i=n(4576),a=n(9039),o=n(3607);e.exports=r||!a((function(){if(!(o&&o<535)){var e=Math.random();__defineSetter__.call(null,e,(function(){})),delete i[e]}}))},2967:function(e,t,n){var r=n(6706),i=n(34),a=n(7750),o=n(3506);e.exports=Object.setPrototypeOf||(`__proto__`in{}?function(){var e,t=!1,n={};try{(e=r(Object.prototype,`__proto__`,`set`))(n,[]),t=n instanceof Array}catch{}return function(n,r){return a(n),o(r),i(n)&&(t?e(n,r):n.__proto__=r),n}}():void 0)},3179:function(e,t,n){var r=n(2140),i=n(6955);e.exports=r?{}.toString:function(){return`[object `+i(this)+`]`}},4270:function(e,t,n){var r=n(9565),i=n(4901),a=n(34),o=TypeError;e.exports=function(e,t){var n,s;if(t===`string`&&i(n=e.toString)&&!a(s=r(n,e))||i(n=e.valueOf)&&!a(s=r(n,e))||t!==`string`&&i(n=e.toString)&&!a(s=r(n,e)))return s;throw new o(`Can't convert object to primitive value`)}},5031:function(e,t,n){var r=n(7751),i=n(9504),a=n(8480),o=n(3717),s=n(8551),c=i([].concat);e.exports=r(`Reflect`,`ownKeys`)||function(e){var t=a.f(s(e)),n=o.f;return n?c(t,n(e)):t}},8235:function(e,t,n){var r=n(9504),i=n(9297),a=SyntaxError,o=parseInt,s=String.fromCharCode,c=r(``.charAt),l=r(``.slice),u=r(/./.exec),d={'\\"':`"`,"\\\\":`\\`,"\\/":`/`,"\\b":`\b`,"\\f":`\f`,"\\n":` `,"\\r":`\r`,"\\t":` `},f=/^[\da-f]{4}$/i,p=/^[\u0000-\u001F]$/;e.exports=function(e,t){for(var n=!0,r=``;t0&&(!p.multiline||p.multiline&&v(T,p.lastIndex-1)!==` `)&&(A=`(?: `+A+`)`,M=` `+M,j++),n=RegExp(`^(?:`+A+`)`,k)),w&&(n=RegExp(`^`+A+`$(?!\\s)`,k)),S&&(r=p.lastIndex),i=a(g,O?n:p,M),O?i?(i.input=x(i.input,j),i[0]=x(i[0],j),i.index=p.lastIndex,p.lastIndex+=i[0].length):p.lastIndex=0:S&&i&&(p.lastIndex=p.global?i.index+i[0].length:r),w&&i&&i.length>1&&a(h,i[0],n,(function(){for(o=1;ob)`,`g`);return e.exec(`b`).groups.a!==`b`||`b`.replace(e,`$c`)!==`bc`}))},7750:function(e,t,n){var r=n(4117),i=TypeError;e.exports=function(e){if(r(e))throw new i(`Can't call method on `+e);return e}},7633:function(e,t,n){var r=n(7751),i=n(2106),a=n(8227),o=n(3724),s=a(`species`);e.exports=function(e){var t=r(e);o&&t&&!t[s]&&i(t,s,{configurable:!0,get:function(){return this}})}},687:function(e,t,n){var r=n(4913).f,i=n(9297),a=n(8227)(`toStringTag`);e.exports=function(e,t,n){e&&!n&&(e=e.prototype),e&&!i(e,a)&&r(e,a,{configurable:!0,value:t})}},6119:function(e,t,n){var r=n(5745),i=n(3392),a=r(`keys`);e.exports=function(e){return a[e]||(a[e]=i(e))}},7629:function(e,t,n){var r=n(6395),i=n(4576),a=n(9433),o=`__core-js_shared__`,s=e.exports=i[o]||a(o,{});(s.versions||=[]).push({version:`3.48.0`,mode:r?`pure`:`global`,copyright:`© 2013–2025 Denis Pushkarev (zloirock.ru), 2025–2026 CoreJS Company (core-js.io). All rights reserved.`,license:`https://github.com/zloirock/core-js/blob/v3.48.0/LICENSE`,source:`https://github.com/zloirock/core-js`})},5745:function(e,t,n){var r=n(7629);e.exports=function(e,t){return r[e]||(r[e]=t||{})}},2293:function(e,t,n){var r=n(8551),i=n(5548),a=n(4117),o=n(8227)(`species`);e.exports=function(e,t){var n,s=r(e).constructor;return s===void 0||a(n=r(s)[o])?t:i(n)}},8183:function(e,t,n){var r=n(9504),i=n(1291),a=n(655),o=n(7750),s=r(``.charAt),c=r(``.charCodeAt),l=r(``.slice),u=function(e){return function(t,n){var r,u,d=a(o(t)),f=i(n),p=d.length;return f<0||f>=p?e?``:void 0:(r=c(d,f))<55296||r>56319||f+1===p||(u=c(d,f+1))<56320||u>57343?e?s(d,f):r:e?l(d,f,f+2):u-56320+(r-55296<<10)+65536}};e.exports={codeAt:u(!1),charAt:u(!0)}},706:function(e,t,n){var r=n(350).PROPER,i=n(9039),a=n(7452);e.exports=function(e){return i((function(){return!!a[e]()||`​…᠎`[e]()!==`​…᠎`||r&&a[e].name!==e}))}},3802:function(e,t,n){var r=n(9504),i=n(7750),a=n(655),o=n(7452),s=r(``.replace),c=RegExp(`^[`+o+`]+`),l=RegExp(`(^|[^`+o+`])[`+o+`]+$`),u=function(e){return function(t){var n=a(i(t));return 1&e&&(n=s(n,c,``)),2&e&&(n=s(n,l,`$1`)),n}};e.exports={start:u(1),end:u(2),trim:u(3)}},4495:function(e,t,n){var r=n(9519),i=n(9039),a=n(4576).String;e.exports=!!Object.getOwnPropertySymbols&&!i((function(){var e=Symbol(`symbol detection`);return!a(e)||!(Object(e)instanceof Symbol)||!Symbol.sham&&r&&r<41}))},8242:function(e,t,n){var r=n(9565),i=n(7751),a=n(8227),o=n(6840);e.exports=function(){var e=i(`Symbol`),t=e&&e.prototype,n=t&&t.valueOf,s=a(`toPrimitive`);t&&!t[s]&&o(t,s,(function(e){return r(n,this)}),{arity:1})}},1296:function(e,t,n){e.exports=n(4495)&&!!Symbol.for&&!!Symbol.keyFor},1240:function(e,t,n){e.exports=n(9504)(1.1.valueOf)},5610:function(e,t,n){var r=n(1291),i=Math.max,a=Math.min;e.exports=function(e,t){var n=r(e);return n<0?i(n+t,0):a(n,t)}},5397:function(e,t,n){var r=n(7055),i=n(7750);e.exports=function(e){return r(i(e))}},1291:function(e,t,n){var r=n(741);e.exports=function(e){var t=+e;return t!=t||t===0?0:r(t)}},8014:function(e,t,n){var r=n(1291),i=Math.min;e.exports=function(e){var t=r(e);return t>0?i(t,9007199254740991):0}},8981:function(e,t,n){var r=n(7750),i=Object;e.exports=function(e){return i(r(e))}},2777:function(e,t,n){var r=n(9565),i=n(34),a=n(757),o=n(5966),s=n(4270),c=n(8227),l=TypeError,u=c(`toPrimitive`);e.exports=function(e,t){if(!i(e)||a(e))return e;var n,c=o(e,u);if(c){if(t===void 0&&(t=`default`),n=r(c,e,t),!i(n)||a(n))return n;throw new l(`Can't convert object to primitive value`)}return t===void 0&&(t=`number`),s(e,t)}},6969:function(e,t,n){var r=n(2777),i=n(757);e.exports=function(e){var t=r(e,`string`);return i(t)?t:t+``}},2140:function(e,t,n){var r={};r[n(8227)(`toStringTag`)]=`z`,e.exports=String(r)===`[object z]`},655:function(e,t,n){var r=n(6955),i=String;e.exports=function(e){if(r(e)===`Symbol`)throw TypeError(`Cannot convert a Symbol value to a string`);return i(e)}},6823:function(e){var t=String;e.exports=function(e){try{return t(e)}catch{return`Object`}}},3392:function(e,t,n){var r=n(9504),i=0,a=Math.random(),o=r(1.1.toString);e.exports=function(e){return`Symbol(`+(e===void 0?``:e)+`)_`+o(++i+a,36)}},7040:function(e,t,n){e.exports=n(4495)&&!Symbol.sham&&typeof Symbol.iterator==`symbol`},8686:function(e,t,n){var r=n(3724),i=n(9039);e.exports=r&&i((function(){return Object.defineProperty((function(){}),"prototype",{value:42,writable:!1}).prototype!==42}))},8622:function(e,t,n){var r=n(4576),i=n(4901),a=r.WeakMap;e.exports=i(a)&&/native code/.test(String(a))},511:function(e,t,n){var r=n(9167),i=n(9297),a=n(1951),o=n(4913).f;e.exports=function(e){var t=r.Symbol||={};i(t,e)||o(t,e,{value:a.f(e)})}},1951:function(e,t,n){t.f=n(8227)},8227:function(e,t,n){var r=n(4576),i=n(5745),a=n(9297),o=n(3392),s=n(4495),c=n(7040),l=r.Symbol,u=i(`wks`),d=c?l.for||l:l&&l.withoutSetter||o;e.exports=function(e){return a(u,e)||(u[e]=s&&a(l,e)?l[e]:d(`Symbol.`+e)),u[e]}},7452:function(e){e.exports=` @@ -4405,5 +4405,5 @@ img.ProseMirror-separator { In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}()}function a(e,t){if(e){if(typeof e==`string`)return o(e,t);var n={}.toString.call(e).slice(8,-1);return n===`Object`&&e.constructor&&(n=e.constructor.name),n===`Map`||n===`Set`?Array.from(e):n===`Arguments`||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?o(e,t):void 0}}function o(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n`u`||`remove`in Element.prototype||(Element.prototype.remove=function(){this.parentNode&&this.parentNode.removeChild(this)}),typeof self<`u`&&`document`in self&&((!(`classList`in document.createElement(`_`))||document.createElementNS&&!(`classList`in document.createElementNS(`http://www.w3.org/2000/svg`,`g`)))&&function(e){if(`Element`in e){var t=`classList`,n=`prototype`,r=e.Element[n],i=Object,a=String[n].trim||function(){return this.replace(/^\s+|\s+$/g,``)},o=Array[n].indexOf||function(e){for(var t=0,n=this.length;t2&&arguments[2]!==void 0&&arguments[2]?Object.assign({},this.getDefaultDiplay(),t):t||this.getDefaultDiplay())[e]||e}},{key:`getUpdatedInput`,value:function(e,t,n){var r=arguments.length>3&&arguments[3]!==void 0?arguments[3]:n,i=arguments.length>4&&arguments[4]!==void 0&&arguments[4],a=this.getOptions(),o=[n,r,i],s=t;return(e===`{bksp}`||e===`{backspace}`)&&s.length>0?s=this.removeAt.apply(this,[s].concat(o)):(e===`{delete}`||e===`{forwarddelete}`)&&s.length>0?s=this.removeForwardsAt.apply(this,[s].concat(o)):e===`{space}`?s=this.addStringAt.apply(this,[s,` `].concat(o)):e!==`{tab}`||typeof a.tabCharOnTab==`boolean`&&!1===a.tabCharOnTab?e!==`{enter}`&&e!==`{numpadenter}`||!a.newLineOnEnter?e.includes(`numpad`)&&Number.isInteger(Number(e[e.length-2]))?s=this.addStringAt.apply(this,[s,e[e.length-2]].concat(o)):e===`{numpaddivide}`?s=this.addStringAt.apply(this,[s,`/`].concat(o)):e===`{numpadmultiply}`?s=this.addStringAt.apply(this,[s,`*`].concat(o)):e===`{numpadsubtract}`?s=this.addStringAt.apply(this,[s,`-`].concat(o)):e===`{numpadadd}`?s=this.addStringAt.apply(this,[s,`+`].concat(o)):e===`{numpaddecimal}`?s=this.addStringAt.apply(this,[s,`.`].concat(o)):e===`{`||e===`}`?s=this.addStringAt.apply(this,[s,e].concat(o)):e.includes(`{`)||e.includes(`}`)||(s=this.addStringAt.apply(this,[s,e].concat(o))):s=this.addStringAt.apply(this,[s,` `].concat(o)):s=this.addStringAt.apply(this,[s,` `].concat(o)),a.debug&&console.log(`Input will be: `+s),s}},{key:`updateCaretPos`,value:function(e){var t=arguments.length>1&&arguments[1]!==void 0&&arguments[1],n=this.updateCaretPosAction(e,t);this.dispatch((function(e){e.setCaretPosition(n)}))}},{key:`updateCaretPosAction`,value:function(e){var t=arguments.length>1&&arguments[1]!==void 0&&arguments[1],n=this.getOptions(),r=this.getCaretPosition();return r!=null&&(t?r>0&&(r-=e):r+=e),n.debug&&console.log(`Caret at:`,r),r}},{key:`addStringAt`,value:function(e,t){var n,r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:e.length,i=arguments.length>3&&arguments[3]!==void 0?arguments[3]:e.length,a=arguments.length>4&&arguments[4]!==void 0&&arguments[4];return r||r===0?(n=[e.slice(0,r),t,e.slice(i)].join(``),this.isMaxLengthReached()||a&&this.updateCaretPos(t.length)):n=e+t,n}},{key:`removeAt`,value:function(e){var t,n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:e.length,r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:e.length,i=arguments.length>3&&arguments[3]!==void 0&&arguments[3];if(n===0&&r===0)return e;if(n===r){var a=/([\uD800-\uDBFF][\uDC00-\uDFFF])/g;n&&n>=0?e.substring(n-2,n).match(a)?(t=e.substr(0,n-2)+e.substr(n),i&&this.updateCaretPos(2,!0)):(t=e.substr(0,n-1)+e.substr(n),i&&this.updateCaretPos(1,!0)):e.slice(-2).match(a)?(t=e.slice(0,-2),i&&this.updateCaretPos(2,!0)):(t=e.slice(0,-1),i&&this.updateCaretPos(1,!0))}else t=e.slice(0,n)+e.slice(r),i&&this.dispatch((function(e){e.setCaretPosition(n)}));return t}},{key:`removeForwardsAt`,value:function(e){var t,n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:e.length,r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:e.length,i=arguments.length>3&&arguments[3]!==void 0&&arguments[3];return e!=null&&e.length&&n!==null?(n===r?t=e.substring(n,n+2).match(/([\uD800-\uDBFF][\uDC00-\uDFFF])/g)?e.substr(0,n)+e.substr(n+2):e.substr(0,n)+e.substr(n+1):(t=e.slice(0,n)+e.slice(r),i&&this.dispatch((function(e){e.setCaretPosition(n)}))),t):e}},{key:`handleMaxLength`,value:function(e,t){var n=this.getOptions(),r=n.maxLength,i=e[n.inputName||`default`],a=t.length-1>=r;if(t.length<=i.length)return!1;if(Number.isInteger(r))return n.debug&&console.log(`maxLength (num) reached:`,a),a?(this.maxLengthReached=!0,!0):(this.maxLengthReached=!1,!1);if(s(r)===`object`){var o=t.length-1>=r[n.inputName||`default`];return n.debug&&console.log(`maxLength (obj) reached:`,o),o?(this.maxLengthReached=!0,!0):(this.maxLengthReached=!1,!1)}}},{key:`isMaxLengthReached`,value:function(){return!!this.maxLengthReached}},{key:`isTouchDevice`,value:function(){return`ontouchstart`in window||navigator.maxTouchPoints}},{key:`pointerEventsSupported`,value:function(){return!!window.PointerEvent}},{key:`camelCase`,value:function(e){return e?e.toLowerCase().trim().split(/[.\-_\s]/g).reduce((function(e,t){return t.length?e+t[0].toUpperCase()+t.slice(1):e})):``}},{key:`chunkArray`,value:function(e,t){return i(Array(Math.ceil(e.length/t))).map((function(n,r){return e.slice(t*r,t+t*r)}))}},{key:`escapeRegex`,value:function(e){return e.replace(/[-\/\\^$*+?.()|[\]{}]/g,`\\$&`)}},{key:`getRtlOffset`,value:function(e,t){var n=e,r=t.indexOf(`‫`);return r=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}throw TypeError(`Invalid attempt to iterate non-iterable instance. In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var o,s=!0,c=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return s=e.done,e},e:function(e){c=!0,o=e},f:function(){try{s||n.return==null||n.return()}finally{if(c)throw o}}}}(Object.getOwnPropertyNames(e.prototype));try{for(r.s();!(n=r.n()).done;){var i=n.value;i===`constructor`||i===`bindMethods`||(t[i]=t[i].bind(t))}}catch(e){r.e(e)}finally{r.f()}}}],t&&c(e.prototype,t),n&&c(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,n}();l(d,`noop`,(function(){}));var f=d;function p(e){return p=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},p(e)}function m(e,t){for(var n=0;n1?t?.toLowerCase():t}},{key:`keyCodeToKey`,value:function(e){return{8:`Backspace`,9:`Tab`,13:`Enter`,16:`Shift`,17:`Ctrl`,18:`Alt`,19:`Pause`,20:`CapsLock`,27:`Esc`,32:`Space`,33:`PageUp`,34:`PageDown`,35:`End`,36:`Home`,37:`ArrowLeft`,38:`ArrowUp`,39:`ArrowRight`,40:`ArrowDown`,45:`Insert`,46:`Delete`,48:`0`,49:`1`,50:`2`,51:`3`,52:`4`,53:`5`,54:`6`,55:`7`,56:`8`,57:`9`,65:`A`,66:`B`,67:`C`,68:`D`,69:`E`,70:`F`,71:`G`,72:`H`,73:`I`,74:`J`,75:`K`,76:`L`,77:`M`,78:`N`,79:`O`,80:`P`,81:`Q`,82:`R`,83:`S`,84:`T`,85:`U`,86:`V`,87:`W`,88:`X`,89:`Y`,90:`Z`,91:`Meta`,96:`Numpad0`,97:`Numpad1`,98:`Numpad2`,99:`Numpad3`,100:`Numpad4`,101:`Numpad5`,102:`Numpad6`,103:`Numpad7`,104:`Numpad8`,105:`Numpad9`,106:`NumpadMultiply`,107:`NumpadAdd`,109:`NumpadSubtract`,110:`NumpadDecimal`,111:`NumpadDivide`,112:`F1`,113:`F2`,114:`F3`,115:`F4`,116:`F5`,117:`F6`,118:`F7`,119:`F8`,120:`F9`,121:`F10`,122:`F11`,123:`F12`,144:`NumLock`,145:`ScrollLock`,186:`;`,187:`=`,188:`,`,189:`-`,190:`.`,191:`/`,192:"`",219:`[`,220:`\\`,221:`]`,222:`'`}[e]||``}}],t&&m(e.prototype,t),n&&m(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,n}();function v(e){return v=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},v(e)}function y(e,t){for(var n=0;n0&&arguments[0]!==void 0?arguments[0]:r())},c.appendChild(t)}));var l=a>0,u=document.createElement(`div`);u.classList.add(`hg-candidate-box-prev`),l&&u.classList.add(`hg-candidate-box-btn-active`);var d=function(){l&&n.renderPage({candidateListPages:r,targetElement:i,pageIndex:a-1,nbPages:o,onItemSelected:s})};this.options.useTouchEvents?u.ontouchstart=d:u.onclick=d,this.candidateBoxElement.appendChild(u),this.candidateBoxElement.appendChild(c);var f=ae.length)&&(t=e.length);for(var n=0,r=Array(t);n1&&arguments[1]!==void 0?arguments[1]:e;this.caretPosition=e,this.caretPositionEnd=t}},{key:`getInputCandidates`,value:function(e){var t=this,n=this.options,r=n.layoutCandidates,i=n.layoutCandidatesCaseSensitiveMatch;if(!r||T(r)!==`object`)return{};var a=Object.keys(r).filter((function(n){var r=e.substring(0,t.getCaretPositionEnd()||0)||e,a=RegExp(`${t.utilities.escapeRegex(n)}\$`,i?`g`:`gi`);return!!C(r.matchAll(a)).length}));if(a.length>1){var o=a.sort((function(e,t){return t.length-e.length}))[0];return{candidateKey:o,candidateValue:r[o]}}if(a.length){var s=a[0];return{candidateKey:s,candidateValue:r[s]}}return{}}},{key:`showCandidatesBox`,value:function(e,t,n){var r=this;this.candidateBox&&this.candidateBox.show({candidateValue:t,targetElement:n,onSelect:function(t,n){var i=r.options,a=i.layoutCandidatesCaseSensitiveMatch,o=i.disableCandidateNormalization,s=i.enableLayoutCandidatesKeyPress,c=t;o||(c=t.normalize(`NFD`)),typeof r.options.beforeInputUpdate==`function`&&r.options.beforeInputUpdate(r);var l=r.getInput(r.options.inputName,!0),u=r.getCaretPositionEnd()||0,d=l.substring(0,u||0)||l,f=RegExp(`${r.utilities.escapeRegex(e)}\$`,a?`g`:`gi`),p=d.replace(f,c),m=l.replace(d,p),h=p.length-d.length,g=(u||l.length)+h;g<0&&(g=0),r.setInput(m,r.options.inputName,!0),r.setCaretPosition(g),s&&typeof r.options.onKeyPress==`function`&&r.options.onKeyPress(t,n),typeof r.options.onChange==`function`&&r.options.onChange(r.getInput(r.options.inputName,!0),n),typeof r.options.onChangeAll==`function`&&r.options.onChangeAll(r.getAllInputs(),n)}})}},{key:`handleButtonClicked`,value:function(e,t){var n=this.options,r=n.inputName,i=r===void 0?this.defaultName:r,a=n.debug;if(e!==`{//}`){this.input[i]||(this.input[i]=``),typeof this.options.beforeInputUpdate==`function`&&this.options.beforeInputUpdate(this);var o=this.utilities.getUpdatedInput(e,this.input[i],this.caretPosition,this.caretPositionEnd);if(this.utilities.isStandardButton(e)&&this.activeInputElement&&this.input[i]&&this.input[i]===o&&this.caretPosition===0&&this.caretPositionEnd===o.length)return this.setInput(``,this.options.inputName,!0),this.setCaretPosition(0),this.activeInputElement.value=``,this.activeInputElement.setSelectionRange(0,0),void this.handleButtonClicked(e,t);if(typeof this.options.onKeyPress==`function`&&this.options.onKeyPress(e,t),this.input[i]!==o&&(!this.options.inputPattern||this.options.inputPattern&&this.inputPatternIsValid(o))){if(this.options.maxLength&&this.utilities.handleMaxLength(this.input,o))return;var s=this.utilities.getUpdatedInput(e,this.input[i],this.caretPosition,this.caretPositionEnd,!0);if(this.setInput(s,this.options.inputName,!0),a&&console.log(`Input changed:`,this.getAllInputs()),this.options.debug&&console.log(`Caret at: `,this.getCaretPosition(),this.getCaretPositionEnd(),`(${this.keyboardDOMClass})`,t?.type),this.options.syncInstanceInputs&&this.syncInstanceInputs(),typeof this.options.onChange==`function`&&this.options.onChange(this.getInput(this.options.inputName,!0),t),typeof this.options.onChangeAll==`function`&&this.options.onChangeAll(this.getAllInputs(),t),t!=null&&t.target&&this.options.enableLayoutCandidates){var c,l=this.getInputCandidates(o),u=l.candidateKey,d=l.candidateValue;u&&d?this.showCandidatesBox(u,d,this.keyboardDOM):(c=this.candidateBox)==null||c.destroy()}}this.caretPositionEnd&&this.caretPosition!==this.caretPositionEnd&&(this.setCaretPosition(this.caretPositionEnd,this.caretPositionEnd),this.activeInputElement&&this.activeInputElement.setSelectionRange(this.caretPositionEnd,this.caretPositionEnd),this.options.debug&&console.log(`Caret position aligned`,this.caretPosition)),a&&console.log(`Key pressed:`,e)}}},{key:`getMouseHold`,value:function(){return this.isMouseHold}},{key:`setMouseHold`,value:function(e){this.options.syncInstanceInputs?this.dispatch((function(t){t.isMouseHold=e})):this.isMouseHold=e}},{key:`handleButtonMouseDown`,value:function(e,t){var n=this;t&&(this.options.preventMouseDownDefault&&t.preventDefault(),this.options.stopMouseDownPropagation&&t.stopPropagation(),t.target.classList.add(this.activeButtonClass)),this.holdInteractionTimeout&&clearTimeout(this.holdInteractionTimeout),this.holdTimeout&&clearTimeout(this.holdTimeout),this.setMouseHold(!0),this.options.disableButtonHold||(this.holdTimeout=window.setTimeout((function(){(n.getMouseHold()&&(!e.includes(`{`)&&!e.includes(`}`)||e===`{delete}`||e===`{backspace}`||e===`{bksp}`||e===`{space}`||e===`{tab}`)||e===`{arrowright}`||e===`{arrowleft}`||e===`{arrowup}`||e===`{arrowdown}`)&&(n.options.debug&&console.log(`Button held:`,e),n.handleButtonHold(e)),clearTimeout(n.holdTimeout)}),500))}},{key:`handleButtonMouseUp`,value:function(e,t){var n=this;t&&(this.options.preventMouseUpDefault&&t.preventDefault&&t.preventDefault(),this.options.stopMouseUpPropagation&&t.stopPropagation&&t.stopPropagation(),!(t.target===this.keyboardDOM||t.target&&this.keyboardDOM.contains(t.target)||this.candidateBox&&this.candidateBox.candidateBoxElement&&(t.target===this.candidateBox.candidateBoxElement||t.target&&this.candidateBox.candidateBoxElement.contains(t.target)))&&this.candidateBox&&this.candidateBox.destroy()),this.recurseButtons((function(e){e.classList.remove(n.activeButtonClass)})),this.setMouseHold(!1),this.holdInteractionTimeout&&clearTimeout(this.holdInteractionTimeout),e&&typeof this.options.onKeyReleased==`function`&&this.options.onKeyReleased(e,t)}},{key:`handleKeyboardContainerMouseDown`,value:function(e){this.options.preventMouseDownDefault&&e.preventDefault()}},{key:`handleButtonHold`,value:function(e){var t=this;this.holdInteractionTimeout&&clearTimeout(this.holdInteractionTimeout),this.holdInteractionTimeout=window.setTimeout((function(){t.getMouseHold()?(t.handleButtonClicked(e),t.handleButtonHold(e)):clearTimeout(t.holdInteractionTimeout)}),100)}},{key:`syncInstanceInputs`,value:function(){var e=this;this.dispatch((function(t){t.replaceInput(e.input),t.setCaretPosition(e.caretPosition,e.caretPositionEnd)}))}},{key:`clearInput`,value:function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.options.inputName||this.defaultName;this.input[e]=``,this.setCaretPosition(0),this.options.syncInstanceInputs&&this.syncInstanceInputs()}},{key:`getInput`,value:function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.options.inputName||this.defaultName,t=arguments.length>1&&arguments[1]!==void 0&&arguments[1];return this.options.syncInstanceInputs&&!t&&this.syncInstanceInputs(),this.options.rtl?`‫`+this.input[e].replace(`‫`,``).replace(`‬`,``)+`‬`:this.input[e]}},{key:`getAllInputs`,value:function(){var e=this,t={};return Object.keys(this.input).forEach((function(n){t[n]=e.getInput(n,!0)})),t}},{key:`setInput`,value:function(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:this.options.inputName||this.defaultName,n=arguments.length>2?arguments[2]:void 0;this.input[t]=e,!n&&this.options.syncInstanceInputs&&this.syncInstanceInputs()}},{key:`replaceInput`,value:function(e){this.input=e}},{key:`setOptions`,value:function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},t=this.changedOptions(e);this.options=Object.assign(this.options,e),t.length&&(this.options.debug&&console.log(`changedOptions`,t),this.onSetOptions(t),this.render())}},{key:`changedOptions`,value:function(e){var t=this;return Object.keys(e).filter((function(n){return JSON.stringify(e[n])!==JSON.stringify(t.options[n])}))}},{key:`onSetOptions`,value:function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];e.includes(`layoutName`)&&this.candidateBox&&this.candidateBox.destroy(),(e.includes(`layoutCandidatesPageSize`)||e.includes(`layoutCandidates`))&&this.candidateBox&&(this.candidateBox.destroy(),this.candidateBox=new S({utilities:this.utilities,options:this.options}))}},{key:`resetRows`,value:function(){this.keyboardRowsDOM&&this.keyboardRowsDOM.remove(),this.keyboardDOM.className=this.keyboardDOMClass,this.keyboardDOM.setAttribute(`data-skInstance`,this.currentInstanceName),this.buttonElements={}}},{key:`dispatch`,value:function(e){if(!window.SimpleKeyboardInstances)throw console.warn(`SimpleKeyboardInstances is not defined. Dispatch cannot be called.`),Error(`INSTANCES_VAR_ERROR`);return Object.keys(window.SimpleKeyboardInstances).forEach((function(t){e(window.SimpleKeyboardInstances[t],t)}))}},{key:`addButtonTheme`,value:function(e,t){var n=this;t&&e&&(e.split(` `).forEach((function(r){t.split(` `).forEach((function(t){n.options.buttonTheme||(n.options.buttonTheme=[]);var i=!1;n.options.buttonTheme.map((function(e){if(e!=null&&e.class.split(` `).includes(t)){i=!0;var n=e.buttons.split(` `);n.includes(r)||(i=!0,n.push(r),e.buttons=n.join(` `))}return e})),i||n.options.buttonTheme.push({class:t,buttons:e})}))})),this.render())}},{key:`removeButtonTheme`,value:function(e,t){var n=this;if(!e&&!t)return this.options.buttonTheme=[],void this.render();e&&Array.isArray(this.options.buttonTheme)&&this.options.buttonTheme.length&&(e.split(` `).forEach((function(e){var r;(r=n.options)==null||(r=r.buttonTheme)==null||r.map((function(r,i){if(r&&t&&t.includes(r.class)||!t){var a,o=r?.buttons.split(` `).filter((function(t){return t!==e}));r&&o!=null&&o.length?r.buttons=o.join(` `):((a=n.options.buttonTheme)==null||a.splice(i,1),r=null)}return r}))})),this.render())}},{key:`getButtonElement`,value:function(e){var t,n=this.buttonElements[e];return n&&(t=n.length>1?n:n[0]),t}},{key:`inputPatternIsValid`,value:function(e){var t,n=this.options.inputPattern;if((t=n instanceof RegExp?n:n[this.options.inputName||this.defaultName])&&e){var r=t.test(e);return this.options.debug&&console.log(`inputPattern ("${t}"): ${r?`passed`:`did not pass!`}`),r}return!0}},{key:`setEventListeners`,value:function(){if(this.isFirstKeyboardInstance||!this.allKeyboardInstances){this.options.debug&&console.log(`Caret handling started (${this.keyboardDOMClass})`);var e=this.options.physicalKeyboardHighlightPreventDefault,t=e!==void 0&&e;document.addEventListener(`keyup`,this.handleKeyUp,t),document.addEventListener(`keydown`,this.handleKeyDown,t),document.addEventListener(`mouseup`,this.handleMouseUp),document.addEventListener(`touchend`,this.handleTouchEnd),this.options.updateCaretOnSelectionChange&&document.addEventListener(`selectionchange`,this.handleSelectionChange),document.addEventListener(`select`,this.handleSelect)}}},{key:`handleKeyUp`,value:function(e){this.caretEventHandler(e),this.options.physicalKeyboardHighlight&&this.physicalKeyboard.handleHighlightKeyUp(e)}},{key:`handleKeyDown`,value:function(e){this.options.physicalKeyboardHighlight&&this.physicalKeyboard.handleHighlightKeyDown(e)}},{key:`handleMouseUp`,value:function(e){this.caretEventHandler(e)}},{key:`handleTouchEnd`,value:function(e){this.caretEventHandler(e)}},{key:`handleSelect`,value:function(e){this.caretEventHandler(e)}},{key:`handleSelectionChange`,value:function(e){navigator.userAgent.includes(`Firefox`)||this.caretEventHandler(e)}},{key:`caretEventHandler`,value:function(e){var t,n=this;e.target.tagName&&(t=e.target.tagName.toLowerCase()),this.dispatch((function(r){var i=e.target===r.keyboardDOM||e.target&&r.keyboardDOM.contains(e.target);if(n.options.syncInstanceInputs&&Array.isArray(e.path)&&(i=e.path.some((function(e){var t;return e==null||(t=e.hasAttribute)==null?void 0:t.call(e,`data-skInstance`)}))),(t===`textarea`||t===`input`&&[`text`,`search`,`url`,`tel`,`password`].includes(e.target.type))&&!r.options.disableCaretPositioning){var a=e.target.selectionStart,o=e.target.selectionEnd;r.options.rtl&&(a=r.utilities.getRtlOffset(a,r.getInput()),o=r.utilities.getRtlOffset(o,r.getInput())),r.setCaretPosition(a,o),r.activeInputElement=e.target,r.options.debug&&console.log(`Caret at: `,r.getCaretPosition(),r.getCaretPositionEnd(),e&&e.target.tagName.toLowerCase(),`(${r.keyboardDOMClass})`,e?.type)}else !r.options.disableCaretPositioning&&i||e?.type===`selectionchange`||(r.setCaretPosition(null),r.activeInputElement=null,r.options.debug&&console.log(`Caret position reset due to "${e?.type}" event`,e))}))}},{key:`recurseButtons`,value:function(e){var t=this;e&&Object.keys(this.buttonElements).forEach((function(n){return t.buttonElements[n].forEach(e)}))}},{key:`destroy`,value:function(){this.options.debug&&console.log(`Destroying simple-keyboard instance: ${this.currentInstanceName}`);var e=this.options.physicalKeyboardHighlightPreventDefault,t=e!==void 0&&e;document.removeEventListener(`keyup`,this.handleKeyUp,t),document.removeEventListener(`keydown`,this.handleKeyDown,t),document.removeEventListener(`mouseup`,this.handleMouseUp),document.removeEventListener(`touchend`,this.handleTouchEnd),document.removeEventListener(`select`,this.handleSelect),this.options.updateCaretOnSelectionChange&&document.removeEventListener(`selectionchange`,this.handleSelectionChange),document.onpointerup=null,document.ontouchend=null,document.ontouchcancel=null,document.onmouseup=null,this.recurseButtons((function(e){e&&=(e.onpointerdown=null,e.onpointerup=null,e.onpointercancel=null,e.ontouchstart=null,e.ontouchend=null,e.ontouchcancel=null,e.onclick=null,e.onmousedown=null,e.onmouseup=null,e.remove(),null)})),this.keyboardDOM.onpointerdown=null,this.keyboardDOM.ontouchstart=null,this.keyboardDOM.onmousedown=null,this.resetRows(),this.candidateBox&&=(this.candidateBox.destroy(),null),this.activeInputElement=null,this.keyboardDOM.removeAttribute(`data-skInstance`),this.keyboardDOM.innerHTML=``,window.SimpleKeyboardInstances[this.currentInstanceName]=null,delete window.SimpleKeyboardInstances[this.currentInstanceName],this.initialized=!1}},{key:`getButtonThemeClasses`,value:function(e){var t=this.options.buttonTheme,n=[];return Array.isArray(t)&&t.forEach((function(t){if(t&&t.class&&typeof t.class==`string`&&t.buttons&&typeof t.buttons==`string`){var r=t.class.split(` `);t.buttons.split(` `).includes(e)&&(n=[].concat(C(n),C(r)))}else console.warn(`Incorrect "buttonTheme". Please check the documentation.`,t)})),n}},{key:`setDOMButtonAttributes`,value:function(e,t){var n=this.options.buttonAttributes;Array.isArray(n)&&n.forEach((function(n){n.attribute&&typeof n.attribute==`string`&&n.value&&typeof n.value==`string`?n.buttons&&typeof n.buttons==`string`?n.buttons.split(` `).includes(e)&&t(n.attribute,n.value):t(n.attribute,n.value):console.warn(`Incorrect "buttonAttributes". Please check the documentation.`,n)}))}},{key:`onTouchDeviceDetected`,value:function(){this.processAutoTouchEvents(),this.disableContextualWindow()}},{key:`disableContextualWindow`,value:function(){window.oncontextmenu=function(e){var t;if((t=e.target.classList)!=null&&t.contains(`hg-button`))return e.preventDefault(),e.stopPropagation(),!1}}},{key:`processAutoTouchEvents`,value:function(){this.options.autoUseTouchEvents&&(this.options.useTouchEvents=!0,this.options.debug&&console.log(`autoUseTouchEvents: Touch device detected, useTouchEvents enabled.`))}},{key:`onInit`,value:function(){this.options.debug&&console.log(`${this.keyboardDOMClass} Initialized`),this.setEventListeners(),typeof this.options.onInit==`function`&&this.options.onInit(this)}},{key:`beforeFirstRender`,value:function(){this.utilities.isTouchDevice()&&this.onTouchDeviceDetected(),typeof this.options.beforeFirstRender==`function`&&this.options.beforeFirstRender(this),this.isFirstKeyboardInstance&&this.utilities.pointerEventsSupported()&&!this.options.useTouchEvents&&!this.options.useMouseEvents&&this.options.debug&&console.log(`Using PointerEvents as it is supported by this browser`),this.options.useTouchEvents&&this.options.debug&&console.log(`useTouchEvents has been enabled. Only touch events will be used.`)}},{key:`beforeRender`,value:function(){typeof this.options.beforeRender==`function`&&this.options.beforeRender(this)}},{key:`onRender`,value:function(){typeof this.options.onRender==`function`&&this.options.onRender(this)}},{key:`onModulesLoaded`,value:function(){typeof this.options.onModulesLoaded==`function`&&this.options.onModulesLoaded(this)}},{key:`loadModules`,value:function(){var e=this;Array.isArray(this.options.modules)&&(this.options.modules.forEach((function(t){var n=e.utilities.isConstructor(t)?new t(e):t(e);n.init&&n.init(e)})),this.keyboardPluginClasses=`modules-loaded`,this.render(),this.onModulesLoaded())}},{key:`getModuleProp`,value:function(e,t){return!!this.modules[e]&&this.modules[e][t]}},{key:`getModulesList`,value:function(){return Object.keys(this.modules)}},{key:`parseRowDOMContainers`,value:function(e,t,n,r){var i=this,a=Array.from(e.children),o=0;return a.length&&n.forEach((function(n,s){var c=r[s];if(!(c&&c>n))return!1;var l=n-o,u=c-o,d=document.createElement(`div`);d.className+=`hg-button-container`;var f=`${i.options.layoutName}-r${t}c${s}`;d.setAttribute(`data-skUID`,f);var p=a.splice(l,u-l+1);o+=u-l,p.forEach((function(e){return d.appendChild(e)})),a.splice(l,0,d),e.innerHTML=``,a.forEach((function(t){return e.appendChild(t)})),i.options.debug&&console.log(`rowDOMContainer`,p,l,u,o+1)})),e}},{key:`render`,value:function(){var e=this;this.resetRows(),this.initialized||this.beforeFirstRender(),this.beforeRender();var t=`hg-layout-${this.options.layoutName}`,n=this.options.layout||{default:["` 1 2 3 4 5 6 7 8 9 0 - = {bksp}",`{tab} q w e r t y u i o p [ ] \\`,`{lock} a s d f g h j k l ; ' {enter}`,`{shift} z x c v b n m , . / {shift}`,`.com @ {space}`],shift:[`~ ! @ # $ % ^ & * ( ) _ + {bksp}`,`{tab} Q W E R T Y U I O P { } |`,`{lock} A S D F G H J K L : " {enter}`,`{shift} Z X C V B N M < > ? {shift}`,`.com @ {space}`]},r=this.options.useTouchEvents||!1,i=r?`hg-touch-events`:``,a=this.options.useMouseEvents||!1,o=this.options.disableRowButtonContainers;this.keyboardDOM.className=this.getKeyboardClassString(this.options.theme,t,this.keyboardPluginClasses,i),this.keyboardDOM.setAttribute(`data-skInstance`,this.currentInstanceName),this.keyboardRowsDOM=document.createElement(`div`),this.keyboardRowsDOM.className=`hg-rows`,n[this.options.layoutName||this.defaultName].forEach((function(t,n){var i=t.split(` `);e.options.excludeFromLayout&&e.options.excludeFromLayout[e.options.layoutName||e.defaultName]&&(i=i.filter((function(t){return e.options.excludeFromLayout&&!e.options.excludeFromLayout[e.options.layoutName||e.defaultName].includes(t)})));var s=document.createElement(`div`);s.className+=`hg-row`;var c=[],l=[];i.forEach((function(t,i){var u,d=!o&&typeof t==`string`&&t.length>1&&t.indexOf(`[`)===0,f=!o&&typeof t==`string`&&t.length>1&&t.indexOf(`]`)===t.length-1;d&&(c.push(i),t=t.replace(/\[/g,``)),f&&(l.push(i),t=t.replace(/\]/g,``));var p=e.utilities.getButtonClass(t),m=e.utilities.getButtonDisplayName(t,e.options.display,e.options.mergeDisplay),h=e.options.useButtonTag?`button`:`div`,g=document.createElement(h);g.className+=`hg-button ${p}`,(u=g.classList).add.apply(u,C(e.getButtonThemeClasses(t))),e.setDOMButtonAttributes(t,(function(e,t){g.setAttribute(e,t)})),e.activeButtonClass=`hg-activeButton`,!e.utilities.pointerEventsSupported()||r||a?r?(g.ontouchstart=function(n){e.handleButtonClicked(t,n),e.handleButtonMouseDown(t,n)},g.ontouchend=function(n){e.handleButtonMouseUp(t,n)},g.ontouchcancel=function(n){e.handleButtonMouseUp(t,n)}):(g.onclick=function(n){e.setMouseHold(!1),typeof e.options.onKeyReleased==`function`||e.options.useMouseEvents&&e.options.clickOnMouseDown||e.handleButtonClicked(t,n)},g.onmousedown=function(n){(typeof e.options.onKeyReleased==`function`||e.options.useMouseEvents&&e.options.clickOnMouseDown)&&!e.isMouseHold&&e.handleButtonClicked(t,n),e.handleButtonMouseDown(t,n)},g.onmouseup=function(n){e.handleButtonMouseUp(t,n)}):(g.onpointerdown=function(n){e.handleButtonClicked(t,n),e.handleButtonMouseDown(t,n)},g.onpointerup=function(n){e.handleButtonMouseUp(t,n)},g.onpointercancel=function(n){e.handleButtonMouseUp(t,n)}),g.setAttribute(`data-skBtn`,t);var _=`${e.options.layoutName}-r${n}b${i}`;g.setAttribute(`data-skBtnUID`,_);var v=document.createElement(`span`);v.innerHTML=m,g.appendChild(v),e.buttonElements[t]||(e.buttonElements[t]=[]),e.buttonElements[t].push(g),s.appendChild(g)})),s=e.parseRowDOMContainers(s,n,c,l),e.keyboardRowsDOM.appendChild(s)})),this.keyboardDOM.appendChild(this.keyboardRowsDOM),this.onRender(),this.initialized||(this.initialized=!0,!this.utilities.pointerEventsSupported()||r||a?r?(document.ontouchend=function(t){return e.handleButtonMouseUp(void 0,t)},document.ontouchcancel=function(t){return e.handleButtonMouseUp(void 0,t)},this.keyboardDOM.ontouchstart=function(t){return e.handleKeyboardContainerMouseDown(t)}):r||(document.onmouseup=function(t){return e.handleButtonMouseUp(void 0,t)},this.keyboardDOM.onmousedown=function(t){return e.handleKeyboardContainerMouseDown(t)}):(document.onpointerup=function(t){return e.handleButtonMouseUp(void 0,t)},this.keyboardDOM.onpointerdown=function(t){return e.handleKeyboardContainerMouseDown(t)}),this.onInit())}}],t&&D(e.prototype,t),n&&D(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,n}(),j=A;return r}()},442:function(t){t.exports=e}},n={};function r(e){var i=n[e];if(i!==void 0)return i.exports;var a=n[e]={exports:{}};return t[e].call(a.exports,a,a.exports,r),a.exports}r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,{a:t}),t},r.d=function(e,t){for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.r=function(e){typeof Symbol<`u`&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:`Module`}),Object.defineProperty(e,"__esModule",{value:!0})};var i={};return function(){r.r(i),r.d(i,{KeyboardReact:function(){return u},default:function(){return d}}),r(981);var e=r(442),t=r(548),n=r.n(t);function a(e){return a=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},a(e)}function o(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function s(e){for(var t=1;t{e?.(t)},[t,e]);let d=(0,y.useCallback)(e=>{if(a.current)return;let t=e.target;if(!t.closest(`[data-vkb="false"]`)){if(t instanceof HTMLInputElement){if(!B0e.has(t.type))return}else if(!(t instanceof HTMLTextAreaElement))return;c.current=t,n(!0),s(`default`),l.current?.setInput?.(c.current.value),setTimeout(()=>{(t.closest(`.bg-zinc-800, .rounded-lg, [data-vkb-group]`)??t).scrollIntoView({behavior:`smooth`,block:`nearest`})},100)}},[]),f=(0,y.useCallback)(()=>{setTimeout(()=>{let e=document.activeElement;e&&(u.current?.contains(e)||e===c.current)||(n(!1),c.current=null)},150)},[]);(0,y.useEffect)(()=>(document.addEventListener(`focusin`,d),document.addEventListener(`focusout`,f),()=>{document.removeEventListener(`focusin`,d),document.removeEventListener(`focusout`,f)}),[d,f]);let p=(0,y.useCallback)(()=>{a.current=!0,i(!0),c.current?.blur(),c.current=null,setTimeout(()=>{n(!1),i(!1),a.current=!1},400)},[]),m=(0,y.useCallback)(e=>{let t=c.current;if(t){if(e===`{shift}`){s(e=>e==="default"?`shift`:`default`);return}if(e===`{lock}`){s(e=>e==="default"?`shift`:`default`);return}if(e===`{close}`){p();return}e===`{bksp}`?U9(t,t.value.slice(0,-1)):e===`{space}`?U9(t,t.value+` `):(U9(t,t.value+e),o===`shift`&&s(`default`)),t.focus(),l.current?.setInput?.(t.value)}},[o,p]);return t?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`fixed inset-0 z-[9998] bg-transparent`,onMouseDown:e=>{e.preventDefault(),e.stopPropagation(),r||p()},onTouchStart:e=>{e.preventDefault(),e.stopPropagation(),r||p()},onClick:e=>{e.preventDefault(),e.stopPropagation()}}),!r&&(0,G.jsx)(`div`,{ref:u,className:`relative z-[9999] shrink-0`,onMouseDown:e=>e.preventDefault(),onTouchStart:e=>{e.target.closest(`.hg-button`)||e.preventDefault()},children:(0,G.jsx)(z0e,{keyboardRef:e=>{l.current=e},layoutName:o,onKeyPress:m,theme:`simple-keyboard vkb-theme`,layout:{default:[`1 2 3 4 5 6 7 8 9 0 {bksp}`,`q w e r t y u i o p`,`{lock} a s d f g h j k l`,`{shift} z x c v b n m . @`,`{space} {close}`],shift:[`! @ # $ % ^ & * ( ) {bksp}`,`Q W E R T Y U I O P`,`{lock} A S D F G H J K L`,`{shift} Z X C V B N M , _`,`{space} {close}`]},display:{"{bksp}":`⌫`,"{close}":`✕ Close`,"{shift}":`⇧`,"{lock}":`⇪`,"{space}":` `}})})]}):null}function H0e(){Ff();let[e,t]=(0,y.useState)(null),[n,r]=(0,y.useState)(null),[i,a]=(0,y.useState)(100),{i18n:o}=U(),s=or(),c=rr(),l=I0e(),{setViewportSuppressed:u}=qd();(0,y.useEffect)(()=>(u(!0),()=>u(!1)),[u]);let{data:d}=K({queryKey:[`settings`],queryFn:Z.getSettings});(0,y.useEffect)(()=>{d?.language&&d.language!==o.language&&o.changeLanguage(d.language)},[d?.language,o]);let{data:f=[]}=K({queryKey:[`spoolbuddy-devices`],queryFn:()=>Od.getDevices(),refetchInterval:3e4}),p=f[0],m=l.deviceOnline||!!p?.online,h=(0,y.useMemo)(()=>({...l,deviceOnline:m}),[l,m]),g=(0,y.useRef)(!1);(0,y.useEffect)(()=>{p&&!g.current&&(a(p.display_brightness),g.current=!0)},[p]),(0,y.useEffect)(()=>{let e=document.documentElement,t=e.classList.contains(`dark`);return e.classList.add(`dark`),()=>{t||e.classList.remove(`dark`)}},[]);let{data:_}=K({queryKey:[`spoolbuddy-update-check`,p?.device_id],queryFn:()=>p?Od.checkDaemonUpdate(p.device_id):Promise.resolve(null),enabled:!!p,refetchInterval:300*1e3,staleTime:0}),v=(0,y.useRef)(null);(0,y.useEffect)(()=>{if(!m){let e=`SpoolBuddy device disconnected`;r({type:`warning`,message:e}),v.current=e}else if(_?.update_available&&_.latest_version){let e=`Update available: v${_.latest_version}`;r({type:`info`,message:e}),v.current=e}else v.current&&=(r(null),null)},[m,_?.update_available,_?.latest_version]);let b=!!(l.matchedSpool||l.unknownTagUid||l.unknownTrayUuid),x=(0,y.useRef)(!1);(0,y.useEffect)(()=>{b&&!x.current&&c.pathname!==`/spoolbuddy`&&s(`/spoolbuddy`),x.current=b},[b,c.pathname,s]);let{data:S=[]}=K({queryKey:[`printers`],queryFn:()=>Z.getPrinters()}),C=Co({queries:S.map(e=>({queryKey:[`printerStatus`,e.id],queryFn:()=>Z.getPrinterStatus(e.id),refetchInterval:1e4,select:e=>({connected:e?.connected})}))}),w=(0,y.useMemo)(()=>S.filter((e,t)=>C[t]?.data?.connected),[S,C]),T=(0,y.useRef)(null),E=(0,y.useRef)(!1),D=(0,y.useRef)(null),O=(0,y.useCallback)(e=>{T.current={x:e.touches[0].clientX,y:e.touches[0].clientY},E.current=!1},[]),k=(0,y.useCallback)(n=>{if(!T.current)return;let r=n.changedTouches[0].clientX-T.current.x,i=n.changedTouches[0].clientY-T.current.y,a=T.current.y;if(T.current=null,E.current=!1,i>=50&&Math.abs(i)>Math.abs(r)&&a<120){N(!0);return}if(w.length<2||Math.abs(r)<50||Math.abs(i)>Math.abs(r))return;let o=w.findIndex(t=>t.id===e);t(w[r<0?(o+1)%w.length:(o-1+w.length)%w.length].id)},[w,e,t]);(0,y.useEffect)(()=>{let e=D.current;if(!e)return;let t=e=>{if(!T.current)return;let t=Math.abs(e.touches[0].clientX-T.current.x),n=Math.abs(e.touches[0].clientY-T.current.y);if(E.current){e.preventDefault();return}t>10&&t>n&&(E.current=!0,e.preventDefault())};return e.addEventListener(`touchmove`,t,{passive:!1}),()=>e.removeEventListener(`touchmove`,t)},[]);let[A,j]=(0,y.useState)(!1),[M,N]=(0,y.useState)(!1);return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{ref:D,"data-spoolbuddy-kiosk":!0,className:`w-screen h-screen bg-bambu-dark text-white flex flex-col overflow-hidden`,style:{...i<100?{filter:`brightness(${i/100})`}:void 0,overscrollBehaviorX:`none`},onTouchStart:O,onTouchEnd:k,children:[(0,G.jsx)(`button`,{onClick:()=>N(!0),className:`w-full h-1.5 bg-bambu-dark-secondary flex justify-center items-center shrink-0 touch-none`,"aria-label":`Open quick menu`,children:(0,G.jsx)(`div`,{className:`w-8 h-0.5 rounded-full bg-zinc-600`})}),(0,G.jsx)(k0e,{selectedPrinterId:e,onPrinterChange:t,deviceOnline:m}),(0,G.jsx)(`main`,{className:`flex-1 overflow-y-auto`,children:(0,G.jsx)(Ir,{context:{selectedPrinterId:e,setSelectedPrinterId:t,sbState:h,setAlert:r,displayBrightness:i,setDisplayBrightness:a}})}),!A&&(0,G.jsx)(M0e,{alert:n}),!A&&(0,G.jsx)(j0e,{}),(0,G.jsx)(V0e,{onVisibilityChange:j})]}),(0,G.jsx)(N0e,{isOpen:M,onClose:()=>N(!1),deviceId:p?.device_id??null,deviceOnline:m})]})}function W9({color:e,isEmpty:t,size:n=32}){return t?(0,G.jsx)(`div`,{className:`rounded-full border-2 border-dashed border-zinc-500 flex items-center justify-center`,style:{width:n,height:n},children:(0,G.jsx)(`div`,{className:`w-2 h-2 rounded-full bg-zinc-600`})}):(0,G.jsxs)(`svg`,{width:n,height:n,viewBox:`0 0 32 32`,children:[(0,G.jsx)(`circle`,{cx:`16`,cy:`16`,r:`14`,fill:e,stroke:`white`,strokeWidth:`1.5`,strokeOpacity:`0.7`}),(0,G.jsx)(`circle`,{cx:`16`,cy:`16`,r:`11`,fill:e,style:{filter:`brightness(0.85)`}})]})}var U0e=`spoolbuddy-default-core-weight`;function W0e(){try{let e=localStorage.getItem(U0e);if(e){let t=parseInt(e,10);if(t>=0&&t<=500)return t}}catch{}return 250}function G0e({spool:e,scaleWeight:t,onClose:n,onSyncWeight:r,onAssignToAms:i,isAssigned:a,onUnassignFromAms:o}){let{t:s}=U(),[c,l]=(0,y.useState)(!1),[u,d]=(0,y.useState)(!1),f=Af(e.rgba),p=e.core_weight&&e.core_weight>0?e.core_weight:W0e(),m=t===null?null:Math.round(Math.max(0,t)),h=m===null?null:Math.round(Math.max(0,m-p)),g=Math.round(e.label_weight||1e3),_=h===null?null:Math.min(100,Math.round(h/g*100)),v=_===null?`#808080`:_>50?`#22c55e`:_>20?`#eab308`:`#ef4444`,b=Math.max(0,(e.label_weight||0)-(e.weight_used||0))+p,x=m===null?null:m-b,S=x===null?null:Math.abs(x)<=50,C=async()=>{if(t!==null){l(!0);try{await Od.updateSpoolWeight(e.id,Math.round(t)),d(!0),r?.(),setTimeout(()=>d(!1),3e3)}catch(e){console.error(`Failed to sync weight:`,e)}finally{l(!1)}}};return(0,G.jsxs)(`div`,{className:`flex flex-col items-center space-y-4 max-w-md`,children:[(0,G.jsxs)(`div`,{className:`flex items-start gap-5`,children:[(0,G.jsxs)(`div`,{className:`relative shrink-0`,children:[(0,G.jsx)(W9,{color:f,isEmpty:!1,size:100}),_!==null&&(0,G.jsxs)(`div`,{className:`absolute -bottom-2 -right-2 px-2 py-0.5 rounded-full text-xs font-bold text-white shadow-lg`,style:{backgroundColor:v},children:[_,`%`]})]}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0 pt-1`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`h3`,{className:`text-lg font-semibold text-zinc-100`,children:e.color_name||`Unknown color`}),(0,G.jsxs)(`span`,{className:`text-xs font-mono text-zinc-500 shrink-0`,children:[`#`,e.id]})]}),(0,G.jsxs)(`p`,{className:`text-sm text-zinc-400`,children:[e.brand,` • `,e.material,e.subtype&&` ${e.subtype}`]}),h!==null&&(0,G.jsxs)(`div`,{className:`mt-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,G.jsxs)(`span`,{className:`text-3xl font-bold font-mono text-zinc-100`,children:[h,`g`]}),(0,G.jsxs)(`span`,{className:`text-sm text-zinc-500`,children:[`/ `,g,`g`]})]}),(0,G.jsx)(`p`,{className:`text-xs text-zinc-500 mt-0.5`,children:s(`spoolbuddy.spool.remaining`,`Remaining`)}),(0,G.jsx)(`div`,{className:`mt-2 max-w-xs`,children:(0,G.jsx)(`div`,{className:`h-2 bg-zinc-700 rounded-full overflow-hidden`,children:(0,G.jsx)(`div`,{className:`h-full rounded-full transition-all duration-500`,style:{width:`${_}%`,backgroundColor:v}})})})]})]})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-x-6 gap-y-2 text-sm bg-zinc-800 rounded-lg p-4 w-full`,children:[(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:s(`spoolbuddy.dashboard.grossWeight`,`Gross weight`)}),(0,G.jsx)(`span`,{className:`font-mono text-zinc-300`,children:m===null?`—`:`${m}g`})]}),(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:s(`spoolbuddy.spool.coreWeight`,`Core`)}),(0,G.jsxs)(`span`,{className:`font-mono text-zinc-300`,children:[p,`g`]})]}),(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:s(`spoolbuddy.dashboard.spoolSize`,`Spool size`)}),(0,G.jsxs)(`span`,{className:`font-mono text-zinc-300`,children:[g,`g`]})]}),(0,G.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:s(`spoolbuddy.spool.scaleWeight`,`Scale`)}),m===null?(0,G.jsx)(`span`,{className:`text-zinc-500`,children:`—`}):(0,G.jsxs)(`span`,{className:`flex items-center gap-1 font-mono ${S?`text-green-500`:`text-yellow-500`}`,children:[m,`g`,S?(0,G.jsx)(fs,{className:`w-3.5 h-3.5`}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Lu,{className:`w-3.5 h-3.5`}),(0,G.jsx)(`button`,{onClick:C,className:`p-1 hover:bg-green-500/20 rounded transition-colors text-green-500`,title:s(`spoolbuddy.dashboard.syncWeight`,`Sync Weight`),children:(0,G.jsx)(Hl,{className:`w-4 h-4`})})]})]})]}),(0,G.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:s(`spoolbuddy.dashboard.tagId`,`Tag`)}),(0,G.jsx)(`span`,{className:`font-mono text-xs text-zinc-400 truncate max-w-[120px]`,title:e.tag_uid||``,children:e.tag_uid?e.tag_uid.slice(-8):`—`})]})]}),(0,G.jsxs)(`div`,{className:`flex gap-2 justify-center`,children:[i&&(0,G.jsx)(`button`,{onClick:a?void 0:i,disabled:!!a,className:`px-5 py-2.5 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 transition-colors min-h-[44px] disabled:opacity-50 disabled:cursor-not-allowed`,children:s(`spoolbuddy.modal.assignToAms`,`Assign to AMS`)}),o&&(0,G.jsxs)(`button`,{onClick:o,className:`px-5 py-2.5 rounded-lg text-sm font-medium bg-red-600/20 text-red-400 hover:bg-red-600/30 transition-colors min-h-[44px]`,children:[(0,G.jsx)(Bu,{className:`w-4 h-4 inline mr-1`}),s(`inventory.unassignSpool`)]}),(0,G.jsx)(`button`,{onClick:C,disabled:t===null||c,className:`px-5 py-2.5 rounded-lg text-sm font-medium transition-colors min-h-[44px] ${u?`bg-green-600/20 text-green-400`:i?`bg-zinc-700 text-zinc-300 hover:bg-zinc-600 disabled:opacity-40 disabled:cursor-not-allowed`:`bg-green-600 text-white hover:bg-green-700 disabled:opacity-40 disabled:cursor-not-allowed`}`,children:c?`...`:u?s(`spoolbuddy.dashboard.weightSynced`,`Synced!`):s(`spoolbuddy.dashboard.syncWeight`,`Sync Weight`)}),n&&(0,G.jsx)(`button`,{onClick:n,className:`px-5 py-2.5 rounded-lg text-sm font-medium bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors min-h-[44px]`,children:s(`spoolbuddy.dashboard.close`,`Close`)})]})]})}function K0e({tagUid:e,scaleWeight:t,coreWeight:n,onLinkSpool:r,onAddToInventory:i,onClose:a}){let{t:o}=U(),s=n??W0e(),c=t===null?null:Math.round(Math.max(0,t)),l=c===null?null:Math.round(Math.max(0,c-s));return(0,G.jsxs)(`div`,{className:`flex flex-col items-center text-center space-y-5`,children:[(0,G.jsx)(`div`,{className:`w-20 h-20 rounded-2xl bg-green-500/15 flex items-center justify-center`,children:(0,G.jsx)(`svg`,{className:`w-10 h-10 text-green-500`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`2`,d:`M7 7h.01M7 3h5c.512 0 1.024.195 1.414.586l7 7a2 2 0 010 2.828l-7 7a2 2 0 01-2.828 0l-7-7A2 2 0 013 12V7a4 4 0 014-4z`})})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`text-lg font-semibold text-zinc-100`,children:o(`spoolbuddy.dashboard.newTag`,`New Tag Detected`)}),(0,G.jsx)(`p`,{className:`text-sm text-zinc-500 font-mono mt-1`,children:e})]}),c!==null&&(0,G.jsxs)(`div`,{className:`text-sm text-zinc-400`,children:[(0,G.jsxs)(`span`,{className:`font-mono font-semibold`,children:[c,`g`]}),` `,o(`spoolbuddy.dashboard.onScale`,`on scale`),l!==null&&l>0&&(0,G.jsxs)(`span`,{className:`text-zinc-500`,children:[` • ~`,l,`g filament`]})]}),(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-2 justify-center`,children:[i&&(0,G.jsx)(`button`,{onClick:i,className:`px-5 py-2.5 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 transition-colors min-h-[44px]`,children:o(`spoolbuddy.modal.addToInventory`,`Add to Inventory`)}),r&&(0,G.jsxs)(`button`,{onClick:r,className:`px-5 py-2.5 rounded-lg text-sm font-medium bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors min-h-[44px]`,children:[(0,G.jsx)(`svg`,{className:`w-4 h-4 inline-block mr-1.5 -mt-0.5`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`2`,d:`M13.828 10.172a4 4 0 00-5.656 0l-4 4a4 4 0 105.656 5.656l1.102-1.101m-.758-4.899a4 4 0 005.656 0l4-4a4 4 0 00-5.656-5.656l-1.1 1.1`})}),o(`inventory.assignSpool`,`Assign Spool`)]}),a&&(0,G.jsx)(`button`,{onClick:a,className:`px-5 py-2.5 rounded-lg text-sm font-medium bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors min-h-[44px]`,children:o(`spoolbuddy.dashboard.close`,`Close`)})]})]})}function q0e(e){return e?`#${e.slice(0,6)}`:`#808080`}function J0e(e){return!e.tray_type||e.tray_type===``}function Y0e(e){if(e.tray_type)return null;if(e.exists===!0)return`reset`;if(e.exists===!1)return`physical`;let t=e.state??null;return t===9||t===10?`physical`:`reset`}function X0e(e){return e<=3?`AMS ${String.fromCharCode(65+e)}`:e>=128&&e<=135?`AMS HT ${String.fromCharCode(65+e-128)}`:`AMS ${e}`}function Z0e({className:e}){return(0,G.jsx)(`svg`,{className:e,viewBox:`0 0 36 54`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:(0,G.jsx)(`path`,{d:`M17.8131 0.00538C18.4463 -0.15091 20.3648 3.14642 20.8264 3.84781C25.4187 10.816 35.3089 26.9368 35.9383 34.8694C37.4182 53.5822 11.882 61.3357 2.53721 45.3789C-1.73471 38.0791 0.016 32.2049 3.178 25.0232C6.99221 16.3662 12.6411 7.90372 17.8131 0.00538ZM18.3738 7.24807L17.5881 7.48441C14.4452 12.9431 10.917 18.2341 8.19369 23.9368C4.6808 31.29 1.18317 38.5479 7.69403 45.5657C17.3058 55.9228 34.9847 46.8808 31.4604 32.8681C29.2558 24.0969 22.4207 15.2913 18.3776 7.24807H18.3738Z`,fill:`#C3C2C1`})})}function Q0e({className:e}){return(0,G.jsxs)(`svg`,{className:e,viewBox:`0 0 35 53`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:[(0,G.jsx)(`path`,{d:`M17.3165 0.0038C17.932 -0.14959 19.7971 3.08645 20.2458 3.77481C24.7103 10.6135 34.3251 26.4346 34.937 34.2198C36.3757 52.5848 11.5505 60.1942 2.46584 44.534C-1.68714 37.3735 0.0148 31.6085 3.08879 24.5603C6.79681 16.0605 12.2884 7.75907 17.3165 0.0038ZM17.8615 7.11561L17.0977 7.34755C14.0423 12.7048 10.6124 17.8974 7.96483 23.4941C4.54975 30.7107 1.14949 37.8337 7.47908 44.721C16.8233 54.8856 34.01 46.0117 30.5838 32.2595C28.4405 23.6512 21.7957 15.0093 17.8652 7.11561H17.8615Z`,fill:`#C3C2C1`}),(0,G.jsx)(`path`,{d:`M5.03547 30.112C9.64453 30.4936 11.632 35.7985 16.4154 35.791C19.6339 35.7873 20.2161 33.2283 22.3853 31.6197C31.6776 24.7286 33.5835 37.4894 27.9881 44.4254C18.1878 56.5653 -1.16063 44.6013 5.03917 30.1158L5.03547 30.112Z`,fill:`#1F8FEB`})]})}function $0e({className:e}){return(0,G.jsxs)(`svg`,{className:e,viewBox:`0 0 36 54`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:[(0,G.jsx)(`path`,{d:`M17.9625 4.48059L4.77216 26.3154L2.08228 40.2175L10.0224 50.8414H23.1594L33.3246 42.1693V30.2455L17.9625 4.48059Z`,fill:`#1F8FEB`}),(0,G.jsx)(`path`,{d:`M17.7948 0.00538C18.4273 -0.15091 20.3438 3.14642 20.8048 3.84781C25.3921 10.816 35.2715 26.9368 35.9001 34.8694C37.3784 53.5822 11.8702 61.3357 2.53562 45.3789C-1.73163 38.0829 0.0134 32.2087 3.1757 25.027C6.98574 16.3662 12.6284 7.90372 17.7948 0.00538ZM18.3549 7.24807L17.57 7.48441C14.4306 12.9431 10.9063 18.2341 8.1859 23.9368C4.67686 31.29 1.18305 38.5479 7.68679 45.5657C17.2881 55.9228 34.9476 46.8808 31.4271 32.8681C29.2249 24.0969 22.3974 15.2913 18.3587 7.24807H18.3549Z`,fill:`#C3C2C1`})]})}function e2e({className:e}){return(0,G.jsxs)(`svg`,{className:e,viewBox:`0 0 12 20`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:[(0,G.jsx)(`path`,{d:`M6 0.5C4.6 0.5 3.5 1.6 3.5 3V12.1C2.6 12.8 2 13.9 2 15C2 17.2 3.8 19 6 19C8.2 19 10 17.2 10 15C10 13.9 9.4 12.8 8.5 12.1V3C8.5 1.6 7.4 0.5 6 0.5Z`,stroke:`#C3C2C1`,strokeWidth:`1`,fill:`none`}),(0,G.jsx)(`circle`,{cx:`6`,cy:`15`,r:`2.5`,stroke:`#C3C2C1`,strokeWidth:`1`,fill:`none`})]})}function t2e({className:e}){return(0,G.jsxs)(`svg`,{className:e,viewBox:`0 0 12 20`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:[(0,G.jsx)(`rect`,{x:`4.5`,y:`8`,width:`3`,height:`4.5`,fill:`#d4a017`,rx:`0.5`}),(0,G.jsx)(`circle`,{cx:`6`,cy:`15`,r:`2`,fill:`#d4a017`}),(0,G.jsx)(`path`,{d:`M6 0.5C4.6 0.5 3.5 1.6 3.5 3V12.1C2.6 12.8 2 13.9 2 15C2 17.2 3.8 19 6 19C8.2 19 10 17.2 10 15C10 13.9 9.4 12.8 8.5 12.1V3C8.5 1.6 7.4 0.5 6 0.5Z`,stroke:`#C3C2C1`,strokeWidth:`1`,fill:`none`})]})}function n2e({className:e}){return(0,G.jsxs)(`svg`,{className:e,viewBox:`0 0 12 20`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:[(0,G.jsx)(`rect`,{x:`4.5`,y:`3`,width:`3`,height:`9.5`,fill:`#c62828`,rx:`0.5`}),(0,G.jsx)(`circle`,{cx:`6`,cy:`15`,r:`2`,fill:`#c62828`}),(0,G.jsx)(`path`,{d:`M6 0.5C4.6 0.5 3.5 1.6 3.5 3V12.1C2.6 12.8 2 13.9 2 15C2 17.2 3.8 19 6 19C8.2 19 10 17.2 10 15C10 13.9 9.4 12.8 8.5 12.1V3C8.5 1.6 7.4 0.5 6 0.5Z`,stroke:`#C3C2C1`,strokeWidth:`1`,fill:`none`})]})}function r2e({humidity:e,goodThreshold:t=40,fairThreshold:n=60}){let r,i;return e<=t?(r=`#22a352`,i=Z0e):e<=n?(r=`#d4a017`,i=Q0e):(r=`#c62828`,i=$0e),(0,G.jsxs)(`div`,{className:`flex items-center gap-0.5`,children:[(0,G.jsx)(i,{className:`w-3 h-3.5`}),(0,G.jsxs)(`span`,{className:`font-medium tabular-nums text-xs`,style:{color:r},children:[e,`%`]})]})}function i2e({temp:e,goodThreshold:t=28,fairThreshold:n=35}){let r,i;return e<=t?(r=`#22a352`,i=e2e):e<=n?(r=`#d4a017`,i=t2e):(r=`#c62828`,i=n2e),(0,G.jsxs)(`div`,{className:`flex items-center gap-0.5`,children:[(0,G.jsx)(i,{className:`w-3 h-3.5`}),(0,G.jsxs)(`span`,{className:`font-medium tabular-nums text-xs`,style:{color:r},children:[e,`°C`]})]})}function G9({side:e}){return(0,G.jsx)(`span`,{className:`inline-flex items-center justify-center w-4 h-4 text-[9px] font-bold rounded`,style:{backgroundColor:`#1a4d2e`,color:`#00ae42`},children:e})}function a2e({tray:e,slotIndex:t,isActive:n,fillOverride:r,spoolmanFill:i,onClick:a}){let o=J0e(e),s=Y0e(e),c=q0e(e.tray_color),l=e.remain!==null&&e.remain!==void 0&&e.remain>=0?e.remain:null,u=i??(r===0&&l!==null&&l>0?null:r)??l;return(0,G.jsxs)(`div`,{className:`relative flex flex-col items-center p-2.5 rounded-lg transition-all ${n?`ring-2 ring-bambu-green`:``} ${a?`cursor-pointer hover:bg-white/5`:``}`,onClick:a,title:a?`AMS Slot ${t+1}`:void 0,children:[(0,G.jsxs)(`div`,{className:`relative w-16 h-16 mb-1`,children:[o?(0,G.jsx)(`div`,{className:`w-full h-full rounded-full border-2 border-dashed border-gray-500 flex items-center justify-center`,children:(0,G.jsx)(`div`,{className:`w-3 h-3 rounded-full bg-gray-600`})}):(0,G.jsxs)(`svg`,{viewBox:`0 0 56 56`,className:`w-full h-full`,children:[(0,G.jsx)(`circle`,{cx:`28`,cy:`28`,r:`26`,fill:c}),(0,G.jsx)(`circle`,{cx:`28`,cy:`28`,r:`20`,fill:c,style:{filter:`brightness(0.85)`}}),(0,G.jsx)(`ellipse`,{cx:`20`,cy:`20`,rx:`6`,ry:`4`,fill:`white`,opacity:`0.3`}),(0,G.jsx)(`circle`,{cx:`28`,cy:`28`,r:`8`,fill:`#2d2d2d`}),(0,G.jsx)(`circle`,{cx:`28`,cy:`28`,r:`5`,fill:`#1a1a1a`})]}),n&&(0,G.jsx)(`div`,{className:`absolute -bottom-1 left-1/2 -translate-x-1/2 w-2.5 h-2.5 bg-bambu-green rounded-full`})]}),(0,G.jsx)(`span`,{className:`text-sm text-white/70 truncate max-w-full`,title:s===`reset`?`Spool loaded — slot not configured`:void 0,children:o?s===`reset`?`?`:`Empty`:e.tray_type||`Unknown`}),!o&&u!==null&&u>=0&&(0,G.jsx)(`div`,{className:`w-full h-1 bg-bambu-dark-tertiary rounded-full overflow-hidden mt-1`,children:(0,G.jsx)(`div`,{className:`h-full rounded-full transition-all`,style:{width:`${u}%`,backgroundColor:Np(u)}})}),(0,G.jsx)(`span`,{className:`absolute top-1 right-1 text-xs text-white/30`,children:t+1})]})}function o2e({unit:e,activeSlot:t,onConfigureSlot:n,isDualNozzle:r,nozzleSide:i,thresholds:a,fillOverrides:o,spoolmanFillOverrides:s}){let c=e.tray||[],l=e.is_ams_ht,u=l?1:4;return(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg p-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,G.jsx)(`span`,{className:`text-white font-medium text-base`,children:X0e(e.id)}),r&&i&&(0,G.jsx)(G9,{side:i})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.temp!=null&&(0,G.jsx)(i2e,{temp:e.temp,goodThreshold:a?.tempGood,fairThreshold:a?.tempFair}),e.humidity!=null&&(0,G.jsx)(r2e,{humidity:e.humidity,goodThreshold:a?.humidityGood,fairThreshold:a?.humidityFair})]})]}),(0,G.jsx)(`div`,{className:`grid ${l?`grid-cols-1 max-w-[100px] mx-auto`:`grid-cols-4`} gap-2`,children:Array.from({length:u}).map((r,i)=>{let a=c[i]||{id:i,tray_color:null,tray_type:``,tray_sub_brands:null,tray_id_name:null,tray_info_idx:null,remain:-1,k:null,cali_idx:null,tag_uid:null,tray_uuid:null,nozzle_temp_min:null,nozzle_temp_max:null};return(0,G.jsx)(a2e,{tray:a,slotIndex:i,isActive:t===i,fillOverride:o?.[`${e.id}-${i}`]??null,spoolmanFill:s?.[`${e.id}-${i}`]??null,onClick:n?()=>n(e.id,i,J0e(a)?null:a):void 0},i)})})]})}function K9(e){return e<=3?`AMS ${String.fromCharCode(65+e)}`:e>=128&&e<=135?`AMS HT ${String.fromCharCode(65+e-128)}`:`AMS ${e}`}function q9(e){return!e.tray_type||e.tray_type===``}function s2e(e){return e?`#${e.slice(0,6)}`:`#808080`}var J9=e=>(e??``).trim().toUpperCase();function c2e(e,t){let n=J9(e),r=J9(t);return!n||!r?`none`:n===r?`exact`:r.includes(n)||n.includes(r)?`partial`:`none`}function l2e(e,t){let n=J9(e),r=J9(t);return!n||!r?!1:n===r}function Y9({isOpen:e,onClose:t,spool:n,printerId:r,spoolmanMode:i=!1}){let{t:a}=U(),o=co(),[s,c]=(0,y.useState)(null),[l,u]=(0,y.useState)(null),[d,f]=(0,y.useState)(!1),[p,m]=(0,y.useState)(null),[h,g]=(0,y.useState)(null);(0,y.useEffect)(()=>{e&&(c(null),u(null),f(!1),m(null),g(null))},[e]);let _=(0,y.useCallback)(e=>{e.key===`Escape`&&t()},[t]);(0,y.useEffect)(()=>(e&&document.addEventListener(`keydown`,_),()=>document.removeEventListener(`keydown`,_)),[e,_]);let{data:v}=K({queryKey:[`printerStatus`,r],queryFn:()=>Z.getPrinterStatus(r),enabled:e&&r!==null,refetchInterval:5e3}),{data:b}=K({queryKey:[`printer`,r],queryFn:()=>Z.getPrinter(r),enabled:e&&r!==null}),{data:x}=K({queryKey:[`settings`],queryFn:()=>Z.getSettings(),enabled:e,staleTime:300*1e3}),{data:S}=K({queryKey:[`spool-assignments`,r],queryFn:()=>Z.getAssignments(r),enabled:e&&r!==null,staleTime:30*1e3}),{data:C=[]}=K({queryKey:[`spoolman-slot-assignments`,r],queryFn:()=>Z.getSpoolmanSlotAssignments(r??void 0),enabled:e&&!!i&&r!==null,staleTime:30*1e3}),w=i?C.find(e=>e.spoolman_spool_id===n.id):void 0,T=(0,y.useMemo)(()=>{let e={};if(!S)return e;for(let t of S){let n=t.spool;if(n&&n.label_weight>0&&n.weight_used!=null){let r=Math.round(Math.max(0,n.label_weight-n.weight_used)/n.label_weight*100);e[`${t.ams_id}-${t.tray_id}`]=r}}return e},[S]),E=x?{humidityGood:Number(x.ams_humidity_good)||40,humidityFair:Number(x.ams_humidity_fair)||60,tempGood:Number(x.ams_temp_good)||28,tempFair:Number(x.ams_temp_fair)||35}:void 0,D=v?.connected??!1,O=(0,y.useMemo)(()=>v?.ams??[],[v?.ams]),k=(0,y.useMemo)(()=>O.filter(e=>!e.is_ams_ht),[O]),A=(0,y.useMemo)(()=>O.filter(e=>e.is_ams_ht),[O]),j=(0,y.useMemo)(()=>[...v?.vt_tray??[]].sort((e,t)=>(e.id??254)-(t.id??254)),[v?.vt_tray]),M=b?.nozzle_count===2||v?.temperatures?.nozzle_2!==void 0,N=(0,y.useRef)({});(0,y.useEffect)(()=>{v?.ams_extruder_map&&Object.keys(v.ams_extruder_map).length>0&&(N.current=v.ams_extruder_map)},[v?.ams_extruder_map]);let P=v?.ams_extruder_map&&Object.keys(v.ams_extruder_map).length>0?v.ams_extruder_map:N.current,F=v?.fila_switch?.installed===!0,I=(0,y.useCallback)(e=>{if(!M)return null;let t=P[String(e)];return t===void 0?F?null:(e>=128?e-128:e)===1?`L`:`R`:t===1?`L`:`R`},[M,P,F]),L=q({mutationFn:async({amsId:e,trayId:t})=>{if(!r)throw Error(`No printer selected`);return i?await Z.assignSpoolmanSlot({spoolman_spool_id:n.id,printer_id:r,ams_id:e,tray_id:t}):await Z.assignSpool({spool_id:n.id,printer_id:r,ams_id:e,tray_id:t})},onSuccess:e=>{u(`success`);let n=e&&`pending_config`in e&&e.pending_config;c(n?a(`spoolbuddy.modal.assignPendingInsert`,`Assigned. Slot will configure when you insert the spool.`):a(`spoolbuddy.modal.assignSuccess`,`Assigned!`)),o.invalidateQueries({queryKey:[`slotPresets`]}),o.invalidateQueries({queryKey:[`spoolman-slot-assignments`]}),o.invalidateQueries({queryKey:[`spoolman-slot-assignments-all`]}),setTimeout(()=>t(),n?2500:1500)},onError:e=>{u(`error`),c(e instanceof Error?e.message:a(`spoolbuddy.modal.assignError`,`Failed to assign spool.`))}}),R=L.isPending,z=(0,y.useCallback)((e,t)=>{if(e===254||e===255){let n=e===254?254:254+t;return j.find(e=>(e.id??254)===n)||null}return O.find(t=>t.id===e)?.tray?.find(e=>e.id===t)||null},[O,j]),B=(0,y.useCallback)((e,t)=>e<=3?`${K9(e)} ${a(`ams.slot`,`Slot`)} ${t+1}`:e>=128&&e<=135?K9(e):e===254?a(`printers.extL`,`Ext-L`):M?a(`printers.extR`,`Ext-R`):a(`printers.ext`,`Ext`),[a,M]),V=(0,y.useCallback)((e,t)=>{u(`info`),c(a(`spoolbuddy.modal.assigning`,`Configuring slot...`)),L.mutate({amsId:e,trayId:t})},[L,a]),ee=(0,y.useCallback)((e,t)=>{if(!R){if(!x?.disable_filament_warnings){let r=z(e,t);if(r&&!q9(r)){let i=r.tray_sub_brands||r.tray_type||``,a=c2e(n.material,i),o=n.slicer_filament_name||n.slicer_filament,s=r.tray_type||``,c=l2e(o,s);if(a!==`exact`){let r;r=a===`none`&&!c?`material_profile`:a===`partial`&&!c?`partial_profile`:a===`none`?`material`:`partial`;let l=B(e,t);g({amsId:e,trayId:t}),m({type:r,spoolMaterial:n.material||``,trayMaterial:i||``,spoolProfile:o||void 0,trayProfile:s||void 0,location:l}),f(!0);return}}}V(e,t)}},[R,x?.disable_filament_warnings,n,z,B,V]),te=(0,y.useCallback)(()=>{h&&(f(!1),m(null),V(h.amsId,h.trayId),g(null))},[h,V]),ne=(0,y.useMemo)(()=>{let e=[];for(let t of A){let n=t.tray?.[0]||{id:0,tray_color:null,tray_type:``,tray_sub_brands:null,tray_id_name:null,tray_info_idx:null,remain:-1,k:null,cali_idx:null,tag_uid:null,tray_uuid:null,nozzle_temp_min:null,nozzle_temp_max:null},r=T[`${t.id}-0`]??null,i=n.remain!=null&&n.remain>=0?n.remain:null,a=r===0&&i!==null&&i>0?null:r;e.push({key:`ht-${t.id}`,label:K9(t.id),amsId:t.id,trayId:0,tray:n,isEmpty:q9(n),nozzleSide:I(t.id),effectiveFill:a??i})}for(let t of j){let n=t.id??254,r=n-254,i=T[`255-${r}`]??null,o=t.remain!=null&&t.remain>=0?t.remain:null,s=i===0&&o!==null&&o>0?null:i;e.push({key:`ext-${n}`,label:M?n===254?a(`printers.extL`,`Ext-L`):a(`printers.extR`,`Ext-R`):a(`printers.ext`,`Ext`),amsId:255,trayId:r,tray:t,isEmpty:q9(t),nozzleSide:M?n===254?`L`:`R`:null,effectiveFill:s??o})}return e},[A,j,M,a,I,T]);return e?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`fixed inset-0 z-[60] bg-bambu-dark flex flex-col`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-5 py-3 border-b border-zinc-800 shrink-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0`,children:[(0,G.jsx)(`div`,{className:`w-7 h-7 rounded-full shrink-0`,style:Mf(n.rgba)}),(0,G.jsx)(`div`,{className:`min-w-0`,children:(0,G.jsxs)(`h2`,{className:`text-sm font-semibold text-zinc-100 truncate`,children:[a(`spoolbuddy.modal.assignToAmsTitle`,`Assign to AMS`),(0,G.jsxs)(`span`,{className:`font-normal text-zinc-500 ml-2`,children:[n.color_name||`Unknown`,` • `,n.brand,` `,n.material,n.subtype&&` ${n.subtype}`]}),(0,G.jsxs)(`span`,{className:`text-[10px] font-mono text-zinc-500 ml-2 shrink-0`,children:[`#`,n.id]})]})})]}),(0,G.jsx)(`button`,{onClick:t,disabled:R,className:`p-2 rounded-lg text-zinc-500 hover:text-zinc-300 hover:bg-zinc-800 transition-colors shrink-0 disabled:opacity-50`,children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]}),s&&(0,G.jsxs)(`div`,{className:`mx-5 mt-3 p-3 rounded-lg flex items-center gap-3 border shrink-0 ${l===`info`?`bg-blue-500/10 border-blue-500/40`:l===`success`?`bg-green-500/10 border-green-500/40`:`bg-red-500/10 border-red-500/40`}`,children:[l===`info`&&(0,G.jsx)(Y,{className:`w-4 h-4 text-blue-400 animate-spin shrink-0`}),l===`success`&&(0,G.jsx)(xs,{className:`w-4 h-4 text-green-400 shrink-0`}),l===`error`&&(0,G.jsx)(Ds,{className:`w-4 h-4 text-red-400 shrink-0`}),(0,G.jsx)(`span`,{className:`text-sm ${l===`info`?`text-blue-300`:l===`success`?`text-green-300`:`text-red-300`}`,children:s})]}),(0,G.jsx)(`div`,{className:`flex-1 flex flex-col gap-3 p-4 min-h-0 overflow-y-auto`,children:!D&&r?(0,G.jsx)(`div`,{className:`flex-1 flex items-center justify-center`,children:(0,G.jsx)(`div`,{className:`text-center text-white/50`,children:(0,G.jsx)(`p`,{className:`text-lg mb-2`,children:a(`spoolbuddy.ams.printerDisconnected`,`Printer disconnected`)})})}):O.length===0&&j.length===0?(0,G.jsx)(`div`,{className:`flex-1 flex items-center justify-center`,children:(0,G.jsxs)(`div`,{className:`text-center text-white/50`,children:[(0,G.jsx)(Jc,{className:`w-12 h-12 mx-auto mb-3 opacity-50`}),(0,G.jsx)(`p`,{className:`text-lg mb-2`,children:a(`spoolbuddy.ams.noData`,`No AMS detected`)}),(0,G.jsx)(`p`,{className:`text-sm`,children:a(`spoolbuddy.ams.connectAms`,`Connect an AMS to see filament slots`)})]})}):(0,G.jsxs)(G.Fragment,{children:[k.length>0&&(0,G.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-3 flex-1 min-h-0`,children:k.map(e=>(0,G.jsx)(o2e,{unit:e,activeSlot:w?.ams_id===e.id?w.tray_id??null:null,onConfigureSlot:(t,n)=>ee(e.id,n),isDualNozzle:M,nozzleSide:I(e.id),thresholds:E,fillOverrides:T},e.id))}),ne.length>0&&(0,G.jsx)(`div`,{className:`flex gap-2 shrink-0`,children:ne.map(({key:e,label:t,amsId:n,trayId:r,tray:i,isEmpty:a,nozzleSide:o,effectiveFill:s})=>{let c=s2e(i.tray_color);return(0,G.jsxs)(`div`,{onClick:()=>ee(n,r),className:`bg-bambu-dark-secondary rounded-lg px-3 py-2 cursor-pointer hover:bg-bambu-dark-secondary/80 transition-all flex items-center gap-2 ${w&&w.ams_id===n&&w.tray_id===r?`ring-2 ring-bambu-green`:``} ${R?`opacity-50 pointer-events-none`:``}`,children:[(0,G.jsx)(`div`,{className:`relative w-10 h-10 shrink-0`,children:a?(0,G.jsx)(`div`,{className:`w-full h-full rounded-full border-2 border-dashed border-gray-500 flex items-center justify-center`,children:(0,G.jsx)(`div`,{className:`w-1.5 h-1.5 rounded-full bg-gray-600`})}):(0,G.jsxs)(`svg`,{viewBox:`0 0 56 56`,className:`w-full h-full`,children:[(0,G.jsx)(`circle`,{cx:`28`,cy:`28`,r:`26`,fill:c}),(0,G.jsx)(`circle`,{cx:`28`,cy:`28`,r:`20`,fill:c,style:{filter:`brightness(0.85)`}}),(0,G.jsx)(`ellipse`,{cx:`20`,cy:`20`,rx:`6`,ry:`4`,fill:`white`,opacity:`0.3`}),(0,G.jsx)(`circle`,{cx:`28`,cy:`28`,r:`8`,fill:`#2d2d2d`}),(0,G.jsx)(`circle`,{cx:`28`,cy:`28`,r:`5`,fill:`#1a1a1a`})]})}),(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(`span`,{className:`text-xs text-white/50 font-medium`,children:t}),o&&(0,G.jsx)(G9,{side:o})]}),(0,G.jsx)(`div`,{className:`text-sm text-white/80 truncate`,children:a?`Empty`:i.tray_type||`?`})]}),!a&&s!=null&&s>=0&&(0,G.jsx)(`div`,{className:`w-1.5 h-8 bg-bambu-dark-tertiary rounded-full overflow-hidden shrink-0 flex flex-col-reverse`,children:(0,G.jsx)(`div`,{className:`w-full rounded-full`,style:{height:`${s}%`,backgroundColor:Np(s)}})})]},e)})})]})}),(0,G.jsx)(`div`,{className:`flex justify-end gap-3 px-5 py-3 border-t border-zinc-800 shrink-0`,children:(0,G.jsx)(`button`,{onClick:t,disabled:R,className:`px-5 py-2.5 rounded-lg text-sm font-medium bg-zinc-800 text-zinc-300 hover:bg-zinc-700 transition-colors min-h-[44px] disabled:opacity-50`,children:l===`success`?a(`spoolbuddy.dashboard.close`,`Close`):a(`spoolbuddy.modal.cancel`,`Cancel`)})})]}),d&&p&&(()=>{let e=``;return p.type===`material`?e=a(`inventory.assignMismatchMessage`,{spoolMaterial:p.spoolMaterial,trayMaterial:p.trayMaterial,location:p.location}):p.type===`partial`?e=a(`inventory.assignPartialMismatchMessage`,{spoolMaterial:p.spoolMaterial,trayMaterial:p.trayMaterial,location:p.location}):p.type===`material_profile`?e=`${a(`inventory.assignMismatchMessage`,{spoolMaterial:p.spoolMaterial,trayMaterial:p.trayMaterial,location:p.location})}\n\n${a(`inventory.assignProfileMismatchMessage`,{spoolProfile:p.spoolProfile||a(`common.unknown`),trayProfile:p.trayProfile||a(`common.unknown`),location:p.location})}`:p.type===`partial_profile`&&(e=`${a(`inventory.assignPartialMismatchMessage`,{spoolMaterial:p.spoolMaterial,trayMaterial:p.trayMaterial,location:p.location})}\n\n${a(`inventory.assignProfileMismatchMessage`,{spoolProfile:p.spoolProfile||a(`common.unknown`),trayProfile:p.trayProfile||a(`common.unknown`),location:p.location})}`),e=`${e}\n\n${a(`inventory.assignReconfigureNote`)}`,(0,G.jsx)(of,{title:a(`inventory.assignMismatchTitle`),message:e,confirmText:a(`inventory.assignMismatchConfirm`),variant:`warning`,isLoading:L.isPending,onConfirm:te,onCancel:()=>{L.isPending||(f(!1),g(null),m(null))}})})()]}):null}function u2e({isOpen:e,onClose:t,tagId:n,untaggedSpools:r,onLink:i}){let{t:a}=U(),[o,s]=(0,y.useState)(null),c=(0,y.useCallback)(()=>{s(null),t()},[t]),l=(0,y.useCallback)(e=>{e.key===`Escape`&&c()},[c]);return(0,y.useEffect)(()=>(e&&(document.addEventListener(`keydown`,l),document.body.style.overflow=`hidden`),()=>{document.removeEventListener(`keydown`,l),document.body.style.overflow=``}),[e,l]),e?(0,G.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/70 animate-fade-in`,onClick:c,children:(0,G.jsxs)(`div`,{className:`bg-zinc-800 rounded-xl shadow-2xl w-full max-w-lg mx-4 animate-slide-up`,onClick:e=>e.stopPropagation(),children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-5 py-4 border-b border-zinc-700`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h2`,{className:`text-base font-semibold text-zinc-100`,children:a(`spoolbuddy.dashboard.linkTagTitle`,`Link Tag to Spool`)}),(0,G.jsx)(`p`,{className:`text-sm text-zinc-500 font-mono`,children:n})]}),(0,G.jsx)(`button`,{onClick:c,className:`p-2 rounded-lg text-zinc-500 hover:text-zinc-300 hover:bg-zinc-700 transition-colors`,children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]}),(0,G.jsxs)(`div`,{className:`px-5 py-4 space-y-3 max-h-[400px] overflow-y-auto`,children:[(0,G.jsx)(`p`,{className:`text-sm text-zinc-400`,children:a(`spoolbuddy.dashboard.selectSpool`,`Select a spool to link this tag to:`)}),r.length===0?(0,G.jsx)(`div`,{className:`text-center py-8 text-zinc-500`,children:a(`spoolbuddy.dashboard.noUntagged`,`No spools without tags found`)}):(0,G.jsx)(`div`,{className:`space-y-2`,children:r.map(e=>(0,G.jsxs)(`button`,{type:`button`,onClick:()=>s(e),className:`w-full flex items-center gap-3 p-3 rounded-lg border-2 transition-all text-left ${o?.id===e.id?`border-green-500 bg-green-500/10`:`border-zinc-700 hover:border-green-500/50 hover:bg-zinc-700/50`}`,children:[(0,G.jsx)(W9,{color:Af(e.rgba),isEmpty:!1,size:40}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`div`,{className:`font-medium text-zinc-100 truncate`,children:e.color_name||`Unknown color`}),(0,G.jsxs)(`span`,{className:`text-[10px] font-mono text-zinc-500 shrink-0`,children:[`#`,e.id]})]}),(0,G.jsxs)(`div`,{className:`text-sm text-zinc-400 truncate`,children:[e.brand,` • `,e.material,e.subtype&&` ${e.subtype}`]})]}),(0,G.jsxs)(`div`,{className:`text-sm font-mono text-zinc-500`,children:[Math.max(0,e.label_weight-e.weight_used),`g`]})]},e.id))})]}),(0,G.jsxs)(`div`,{className:`flex justify-end gap-2 px-5 py-4 border-t border-zinc-700`,children:[(0,G.jsx)(`button`,{onClick:c,className:`px-4 py-2.5 rounded-lg text-sm font-medium bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors min-h-[44px]`,children:a(`common.cancel`,`Cancel`)}),(0,G.jsx)(`button`,{onClick:()=>{o&&(i(o),s(null))},disabled:!o,className:`px-4 py-2.5 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 disabled:opacity-40 disabled:cursor-not-allowed transition-colors min-h-[44px]`,children:a(`spoolbuddy.dashboard.linkTag`,`Link Tag`)})]})]})}):null}function d2e(e){return e?e.replace(/[^0-9a-f]/gi,``).toUpperCase():``}function f2e(e,t){let n=d2e(e),r=d2e(t);return!n||!r?!1:n===r?!0:n.endsWith(r)||r.endsWith(n)}var p2e=[`#00AE42`,`#FF6B35`,`#3B82F6`,`#EF4444`,`#A855F7`,`#FBBF24`,`#14B8A6`,`#EC4899`,`#F97316`,`#22C55E`];function m2e(){let{t:e}=U(),[t,n]=(0,y.useState)(0);(0,y.useEffect)(()=>{let e=setInterval(()=>{n(e=>(e+1)%p2e.length)},5e3);return()=>clearInterval(e)},[]);let r=p2e[t];return(0,G.jsxs)(`div`,{className:`flex flex-col items-center text-center`,children:[(0,G.jsxs)(`div`,{className:`relative mb-6 flex items-center justify-center`,style:{width:160,height:160},children:[(0,G.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center pointer-events-none`,children:[0,1].map(e=>(0,G.jsx)(`div`,{className:`absolute rounded-full border spoolbuddy-optimized-ping`,style:{width:80,height:80,borderColor:`${r}4D`,transition:`border-color 140ms linear`,animationDelay:`${e*.8}s`}},e))}),(0,G.jsxs)(`div`,{className:`relative overflow-hidden rounded-full`,children:[(0,G.jsx)(`div`,{className:`absolute inset-0 rounded-full opacity-30 spoolbuddy-spool-glow`,style:{background:`radial-gradient(circle, ${r} 0%, transparent 70%)`}}),(0,G.jsx)(`div`,{className:`relative`,style:{transition:`opacity 140ms linear`},children:(0,G.jsx)(W9,{color:r,isEmpty:!1,size:100})})]})]}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`p`,{className:`text-xl font-medium text-zinc-300`,children:e(`spoolbuddy.dashboard.readyToScan`,`Ready to scan`)}),(0,G.jsx)(`p`,{className:`text-sm text-zinc-500`,children:e(`spoolbuddy.dashboard.idleMessage`,`Place a spool on the scale to identify it`)})]}),(0,G.jsxs)(`div`,{className:`mt-6 flex items-center gap-2 text-sm text-zinc-600`,children:[(0,G.jsx)(`svg`,{className:`w-4 h-4`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`2`,d:`M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z`})}),(0,G.jsx)(`span`,{children:e(`spoolbuddy.dashboard.nfcHint`,`NFC tag will be read automatically`)})]})]})}function h2e(){let{t:e}=U();return(0,G.jsxs)(`div`,{className:`flex flex-col items-center text-center`,children:[(0,G.jsx)(`div`,{className:`relative mb-6 flex items-center justify-center`,style:{width:160,height:160},children:(0,G.jsx)(`div`,{className:`w-24 h-24 rounded-full bg-zinc-800 flex items-center justify-center`,children:(0,G.jsx)(`svg`,{className:`w-12 h-12 text-zinc-600`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`1.5`,d:`M18.364 5.636a9 9 0 010 12.728m0 0l-12.728-12.728m12.728 12.728L5.636 5.636m12.728 0a9 9 0 00-12.728 0m0 12.728a9 9 0 010-12.728`})})})}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`p`,{className:`text-lg font-medium text-zinc-500`,children:e(`spoolbuddy.status.deviceOffline`,`Device Offline`)}),(0,G.jsx)(`p`,{className:`text-sm text-zinc-600`,children:e(`spoolbuddy.status.connectDisplay`,`Connect the SpoolBuddy display to scan spools`)})]}),(0,G.jsxs)(`div`,{className:`mt-6 flex items-center gap-2 text-xs text-zinc-600`,children:[(0,G.jsx)(`svg`,{className:`w-4 h-4`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`2`,d:`M8.111 16.404a5.5 5.5 0 017.778 0M12 20h.01m-7.08-7.071c3.904-3.905 10.236-3.905 14.14 0M1.394 9.393c5.857-5.857 15.355-5.857 21.213 0`})}),(0,G.jsx)(`span`,{children:e(`spoolbuddy.status.waitingConnection`,`Waiting for device connection...`)})]})]})}function g2e(){let{sbState:e,selectedPrinterId:t}=lr(),{t:n}=U(),{showToast:r}=qd(),{data:i}=K({queryKey:[`spoolman-settings`],queryFn:Z.getSpoolmanSettings,staleTime:300*1e3}),a=i?.spoolman_enabled===`true`&&!!i?.spoolman_url,{data:o=[],refetch:s}=K({queryKey:a?[`spoolman-inventory-spools`]:[`inventory-spools`],queryFn:()=>a?Z.getSpoolmanInventorySpools(!1):Z.getSpools(!1),enabled:i!==void 0}),{data:c=[]}=K({queryKey:[`spoolman-slot-assignments`],queryFn:()=>Z.getSpoolmanSlotAssignments(),enabled:a,staleTime:3*1e3,refetchInterval:3*1e3,refetchIntervalInBackground:!1}),{data:l=[]}=K({queryKey:[`printers`],queryFn:()=>Z.getPrinters()}),u=Co({queries:l.map(e=>({queryKey:[`printerStatus`,e.id],queryFn:()=>Z.getPrinterStatus(e.id),refetchInterval:1e4,select:e=>({connected:e?.connected,awaiting_plate_clear:e?.awaiting_plate_clear===!0})}))}),d=l.map((e,t)=>({printer:e,pending:u[t]?.data?.awaiting_plate_clear===!0})).filter(e=>e.pending),f=co(),p=q({mutationFn:e=>Z.clearPlate(e),onSuccess:(e,t)=>{f.setQueryData([`printerStatus`,t],e=>e&&{...e,awaiting_plate_clear:!1}),r(n(`spoolbuddy.dashboard.plateClearedToast`,`Plate marked as cleared`),`success`)},onError:()=>{r(n(`spoolbuddy.dashboard.plateClearFailed`,`Could not mark plate as cleared`),`error`)}}),m=q({mutationFn:e=>Z.unassignSpoolmanSlot(e),onSuccess:()=>{f.invalidateQueries({queryKey:[`spoolman-slot-assignments`]}),f.invalidateQueries({queryKey:[`spoolman-inventory-spools`]})},onError:()=>r(n(`inventory.unassignFailed`,`Failed to unassign spool`),`error`)}),[h,g]=(0,y.useState)(null),[_,v]=(0,y.useState)(null),[b,x]=(0,y.useState)(null),[S,C]=(0,y.useState)(!1),[w,T]=(0,y.useState)(!1),[E,D]=(0,y.useState)(!1),[O,k]=(0,y.useState)(!1),[A,j]=(0,y.useState)(null),M=e.matchedSpool?.tag_uid??e.unknownTagUid??null,N=e.weight,P=e.weightStable,F=(0,y.useRef)(null);N===null?F.current=null:(F.current===null||Math.abs(N-F.current)>=3||P)&&(F.current=N);let I=F.current,L=(0,y.useMemo)(()=>{if(e.matchedSpool?.id){let t=o.find(t=>t.id===e.matchedSpool?.id);if(t)return t}return h&&(o.find(e=>f2e(e.tag_uid,h))||A)||null},[h,e.matchedSpool,o,A]),R=(0,y.useMemo)(()=>{if(L&&!A)return L;let t=e.matchedSpool;return t?{id:t.id,tag_uid:t.tag_uid,material:t.material,subtype:t.subtype,color_name:t.color_name,rgba:t.rgba,brand:t.brand,label_weight:t.label_weight,core_weight:t.core_weight,weight_used:t.weight_used}:null},[L,A,e.matchedSpool]),z=a&&R!=null?c.some(e=>e.spoolman_spool_id===R.id):!1,B=(0,y.useMemo)(()=>a?o.filter(e=>!e.tag_uid&&!e.tray_uuid&&!e.archived_at):o.filter(e=>!e.tag_uid&&!e.archived_at),[o,a]);(0,y.useEffect)(()=>{if(M){let e=b===M;(h!==null&&h!==M||!e&&h!==M)&&(g(M),v(null),x(null),j(null)),!e&&N!==null&&P&&v(Math.round(Math.max(0,N)))}else b&&(g(null),x(null),v(null),j(null))},[M,N,P,h,b]);let V=()=>{x(h)},ee=async t=>{if(h)try{if(a){let i=e.unknownTagUid||void 0,a=!e.unknownTagUid&&e.unknownTrayUuid?e.unknownTrayUuid:void 0;if(!i&&!a){r(n(`spoolman.linkFailed`),`error`);return}let o=await Z.linkTagToSpoolmanSpool(t.id,{tray_uuid:a,tag_uid:i});if(!o){r(n(`spoolman.linkFailed`),`error`);return}let{id:s,material:c,subtype:l,color_name:u,rgba:d,brand:f,label_weight:p,core_weight:m,weight_used:h}=o;j({id:s,material:c,subtype:l,color_name:u,rgba:d,brand:f,label_weight:p,core_weight:m,weight_used:h}),r(n(`spoolman.linkSuccess`),`success`)}else await Z.linkTagToSpool(t.id,{tag_uid:h,tag_type:`generic`,data_origin:`nfc_link`});s()}catch(e){console.error(`Failed to link tag:`,e),r(n(`spoolman.linkFailed`),`error`)}finally{C(!1)}},te=async()=>{if(h){k(!0);try{let t=ne??_;if(a){let n=await Z.createSpoolmanInventorySpool({material:`PLA`,subtype:null,color_name:null,rgba:null,extra_colors:null,effect_type:null,brand:null,label_weight:1e3,core_weight:250,core_weight_catalog_id:null,weight_used:0,slicer_filament:null,slicer_filament_name:null,nozzle_temp_min:null,nozzle_temp_max:null,note:null,added_full:null,last_used:null,encode_time:null,tag_uid:null,tray_uuid:null,data_origin:null,tag_type:null,cost_per_kg:null,last_scale_weight:t===null?null:Math.round(t),last_weighed_at:t===null?null:new Date().toISOString(),category:null,low_stock_threshold_pct:null});await Z.linkTagToSpoolmanSpool(n.id,{tag_uid:e.unknownTagUid||void 0,tray_uuid:!e.unknownTagUid&&e.unknownTrayUuid?e.unknownTrayUuid:void 0})}else await Z.createSpool({material:`PLA`,subtype:null,color_name:null,rgba:null,extra_colors:null,effect_type:null,brand:null,label_weight:1e3,core_weight:250,core_weight_catalog_id:null,weight_used:0,slicer_filament:null,slicer_filament_name:null,nozzle_temp_min:null,nozzle_temp_max:null,note:null,added_full:null,last_used:null,encode_time:null,tag_uid:h,tray_uuid:null,data_origin:`spoolbuddy`,tag_type:`generic`,cost_per_kg:null,last_scale_weight:t===null?null:Math.round(t),last_weighed_at:t===null?null:new Date().toISOString(),category:null,low_stock_threshold_pct:null})}catch(e){let t=e instanceof Error?e.message:String(e);console.error(`Failed to quick-add spool:`,t),r(t||n(`spoolbuddy.errors.quickAddFailed`,`Failed to add spool`),`error`)}finally{D(!1),k(!1),s()}}},ne=N!==null&&(M===h||M===null&&h!==null)?N:null,re=o.length,ie=new Set(o.map(e=>e.material)).size,ae=new Set(o.filter(e=>e.brand).map(e=>e.brand)).size;return(0,G.jsxs)(`div`,{className:`h-full flex flex-col p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-6 px-4 py-1.5 bg-zinc-800/50 rounded-xl border border-zinc-700/50 mb-3 shrink-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-xl font-bold text-zinc-100`,children:re}),(0,G.jsx)(`span`,{className:`text-sm text-zinc-500`,children:n(`spoolbuddy.inventory.spools`,`Spools`)})]}),(0,G.jsx)(`div`,{className:`w-px h-5 bg-zinc-700`}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-xl font-bold text-zinc-100`,children:ie}),(0,G.jsx)(`span`,{className:`text-sm text-zinc-500`,children:n(`spoolbuddy.spool.material`,`Materials`)})]}),(0,G.jsx)(`div`,{className:`w-px h-5 bg-zinc-700`}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-xl font-bold text-zinc-100`,children:ae}),(0,G.jsx)(`span`,{className:`text-sm text-zinc-500`,children:n(`spoolbuddy.spool.brand`,`Brands`)})]})]}),(0,G.jsxs)(`div`,{className:`flex-1 flex gap-4 min-h-0`,children:[(0,G.jsxs)(`div`,{className:`w-5/12 flex flex-col min-h-0`,children:[(0,G.jsxs)(`div`,{className:`border border-dashed border-zinc-700/50 rounded-xl p-4`,children:[(0,G.jsx)(`h2`,{className:`text-sm font-semibold text-zinc-400 uppercase tracking-wide mb-3`,children:n(`spoolbuddy.dashboard.device`,`Device`)}),(0,G.jsxs)(`div`,{className:`space-y-2.5`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`w-2.5 h-2.5 rounded-full ${e.deviceOnline?`bg-green-500`:`bg-red-500`}`}),(0,G.jsx)(`span`,{className:`text-base text-zinc-400`,children:e.deviceOnline?n(`spoolbuddy.status.online`,`Online`):n(`spoolbuddy.status.offline`,`Disconnected`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-3 bg-zinc-800/50 rounded-lg`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`svg`,{className:`w-4 h-4 ${e.deviceOnline?`text-green-500`:`text-zinc-500`}`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`2`,d:`M3 6l3 1m0 0l-3 9a5.002 5.002 0 006.001 0M6 7l3 9M6 7l6-2m6 2l3-1m-3 1l-3 9a5.002 5.002 0 006.001 0M18 7l3 9m-3-9l-6-2m0-2v2m0 16V5m0 16H9m3 0h3`})}),(0,G.jsx)(`span`,{className:`text-sm text-zinc-500`,children:n(`spoolbuddy.spool.scaleWeight`,`Scale`)})]}),(0,G.jsx)(`span`,{className:`text-lg font-mono font-semibold text-zinc-100`,children:I===null?`—`:`${Math.abs(I)<=20?0:Math.round(Math.max(0,I))}g`})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-3 bg-zinc-800/50 rounded-lg`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`svg`,{className:`w-4 h-4 ${e.deviceOnline?`text-green-500`:`text-zinc-500`}`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`2`,d:`M7 7h.01M7 3h5c.512 0 1.024.195 1.414.586l7 7a2 2 0 010 2.828l-7 7a2 2 0 01-2.828 0l-7-7A2 2 0 013 12V7a4 4 0 014-4z`})}),(0,G.jsx)(`span`,{className:`text-sm text-zinc-500`,children:`NFC`})]}),(0,G.jsx)(`span`,{className:`text-sm font-medium ${M?`text-green-500`:`text-zinc-500`}`,children:M?n(`spoolbuddy.dashboard.tagDetected`,`Tag detected`):n(`spoolbuddy.dashboard.noTag`,`No tag`)})]})]})]}),l.length>0&&(0,G.jsxs)(`div`,{className:`mt-3 border border-dashed border-zinc-700/50 rounded-xl p-4`,children:[(0,G.jsx)(`h2`,{className:`text-sm font-semibold text-zinc-400 uppercase tracking-wide mb-2.5`,children:n(`spoolbuddy.dashboard.printers`,`Printers`)}),(0,G.jsx)(`div`,{className:`flex flex-wrap gap-2 overflow-hidden`,children:l.map((e,t)=>{let n=u[t]?.data?.connected??!1;return(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 px-2.5 py-1 bg-zinc-800/50 rounded-lg`,title:`${e.name} — ${n?`Online`:`Offline`}`,children:[(0,G.jsx)(`div`,{className:`w-2 h-2 rounded-full shrink-0 ${n?`bg-green-500`:`bg-zinc-600`}`}),(0,G.jsx)(`span`,{className:`text-xs text-zinc-400 truncate max-w-[100px]`,children:e.name})]},e.id)})}),d.length>0&&(0,G.jsx)(`div`,{className:`mt-2 flex flex-wrap gap-2`,"data-testid":`plate-clear-section`,"aria-label":n(`spoolbuddy.dashboard.plateReadyLabel`,`Plates ready to clear`),children:d.map(({printer:e})=>(0,G.jsxs)(`button`,{type:`button`,onClick:()=>p.mutate(e.id),disabled:p.isPending,"data-testid":`plate-clear-button-${e.id}`,title:n(`spoolbuddy.dashboard.plateReady`,`Plate ready: {{name}}`,{name:e.name}),className:`flex items-center gap-1.5 px-2.5 py-1 rounded-lg bg-amber-500/10 hover:bg-amber-500/20 active:bg-amber-500/30 border border-amber-500/30 text-amber-200 transition-colors disabled:opacity-60 disabled:cursor-wait`,children:[(0,G.jsxs)(`svg`,{className:`w-3 h-3 shrink-0`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:[(0,G.jsx)(`path`,{d:`M12 9v4`}),(0,G.jsx)(`path`,{d:`M12 17h.01`}),(0,G.jsx)(`path`,{d:`M10.29 3.86 1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z`})]}),(0,G.jsx)(`span`,{className:`text-xs truncate max-w-[100px]`,children:e.name}),(0,G.jsx)(`span`,{className:`text-xs opacity-70`,"aria-hidden":`true`,children:`·`}),(0,G.jsx)(`span`,{className:`text-xs font-medium`,children:n(`spoolbuddy.dashboard.plateClearAction`,`Clear`)})]},e.id))})]})]}),(0,G.jsx)(`div`,{className:`w-7/12 min-h-0`,children:(0,G.jsxs)(`div`,{className:`border border-dashed border-zinc-700/50 rounded-xl p-6 h-full flex flex-col`,children:[(0,G.jsx)(`h2`,{className:`text-sm font-semibold text-zinc-400 uppercase tracking-wide mb-4 shrink-0`,children:n(`spoolbuddy.dashboard.currentSpool`,`Current Spool`)}),(0,G.jsx)(`div`,{className:`flex-1 flex items-center justify-center min-h-0`,children:e.deviceOnline?(L||e.matchedSpool)&&h&&b!==h?(0,G.jsx)(G0e,{spool:(()=>{let t=L??e.matchedSpool;return{id:t.id,tag_uid:h,material:t.material,subtype:t.subtype,color_name:t.color_name,rgba:t.rgba,brand:t.brand,label_weight:t.label_weight,core_weight:t.core_weight,weight_used:t.weight_used}})(),scaleWeight:ne??_,onSyncWeight:()=>s(),onAssignToAms:()=>T(!0),isAssigned:z,onUnassignFromAms:z&&L?.id!=null?()=>m.mutate(L.id):void 0,onClose:V}):M&&h&&!L&&!e.matchedSpool&&b!==h?(0,G.jsx)(K0e,{tagUid:h,scaleWeight:ne??_,onLinkSpool:B.length>0?()=>C(!0):void 0,onAddToInventory:()=>D(!0),onClose:V}):(0,G.jsx)(m2e,{}):(0,G.jsx)(h2e,{})})]})})]}),R&&!A&&h&&(0,G.jsx)(Y9,{isOpen:w,onClose:()=>T(!1),spool:R,printerId:t,spoolmanMode:a}),h&&(0,G.jsx)(u2e,{isOpen:S,onClose:()=>C(!1),tagId:h,untaggedSpools:B,onLink:ee}),E&&h&&(0,G.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60`,children:(0,G.jsxs)(`div`,{className:`bg-zinc-800 rounded-2xl p-6 mx-4 max-w-sm w-full border border-zinc-700`,children:[(0,G.jsx)(`h3`,{className:`text-lg font-semibold text-zinc-100 mb-3`,children:n(`spoolbuddy.modal.addToInventory`,`Add to Inventory`)}),(0,G.jsxs)(`div`,{className:`flex gap-2.5 p-3 bg-amber-500/10 border border-amber-500/20 rounded-lg mb-4`,children:[(0,G.jsx)(`svg`,{className:`w-5 h-5 text-amber-500 shrink-0 mt-0.5`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`2`,d:`M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z`})}),(0,G.jsx)(`p`,{className:`text-sm text-amber-200/80`,children:n(`spoolbuddy.modal.quickAddHint`,`For best results, add the spool in the Bambuddy web interface first (with material, color, brand), then use "Assign Spool" here to assign the NFC tag.`)})]}),(0,G.jsx)(`p`,{className:`text-sm text-zinc-400 mb-1`,children:n(`spoolbuddy.modal.quickAddDesc`,`This will create a basic PLA spool entry with this NFC tag. You can edit the details later in Bambuddy.`)}),(0,G.jsx)(`p`,{className:`text-xs text-zinc-500 font-mono mb-5`,children:h}),(0,G.jsxs)(`div`,{className:`flex gap-3`,children:[(0,G.jsx)(`button`,{onClick:()=>D(!1),className:`flex-1 px-4 py-2.5 rounded-lg text-sm font-medium bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors min-h-[44px]`,children:n(`common.cancel`,`Cancel`)}),(0,G.jsx)(`button`,{onClick:te,disabled:O,className:`flex-1 px-4 py-2.5 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 disabled:opacity-50 transition-colors min-h-[44px]`,children:O?n(`common.saving`,`Saving...`):n(`spoolbuddy.modal.addAnyway`,`Add Anyway`)})]})]})})]})}function _2e(e){return e<=3?`AMS ${String.fromCharCode(65+e)}`:e>=128&&e<=135?`AMS HT ${String.fromCharCode(65+e-128)}`:`AMS ${e}`}function v2e(e){return e?{O1D:`H2D`,O1E:`H2D Pro`,O2D:`H2D Pro`,O1C:`H2C`,O1C2:`H2C`,O1S:`H2S`,"BL-P001":`X1C`,"BL-P002":`X1`,"BL-P003":`X1E`,N6:`X2D`,N9:`A2L`,C11:`P1S`,C12:`P1P`,C13:`P2S`,N2S:`A1`,N1:`A1 Mini`,X1C:`X1C`,X1:`X1`,X1E:`X1E`,X2D:`X2D`,P1S:`P1S`,P1P:`P1P`,P2S:`P2S`,A1:`A1`,"A1 Mini":`A1 Mini`,A2L:`A2L`,H2D:`H2D`,"H2D Pro":`H2D Pro`,H2C:`H2C`,H2S:`H2S`}[e]||e:``}function X9(e){return!e.tray_type||e.tray_type===``}function y2e(e){return e?`#${e.slice(0,6)}`:`#808080`}function b2e(){let{selectedPrinterId:e,setAlert:t}=lr(),{t:n}=U(),r=co(),{showToast:i}=qd(),{data:a}=K({queryKey:[`printerStatus`,e],queryFn:()=>Z.getPrinterStatus(e),enabled:e!==null,staleTime:30*1e3}),{data:o}=K({queryKey:[`printer`,e],queryFn:()=>Z.getPrinter(e),enabled:e!==null,staleTime:60*1e3}),{data:s}=K({queryKey:[`slotPresets`,e],queryFn:()=>Z.getSlotPresets(e),enabled:e!==null,staleTime:120*1e3}),{data:c}=K({queryKey:[`settings`],queryFn:()=>Z.getSettings(),staleTime:300*1e3}),{data:l}=K({queryKey:[`spoolman-status`],queryFn:Z.getSpoolmanStatus,staleTime:60*1e3}),u=l?.enabled&&l?.connected,{data:d}=K({queryKey:[`linked-spools`],queryFn:Z.getLinkedSpools,enabled:!!u,staleTime:30*1e3}),f=d?.linked,{data:p=[]}=K({queryKey:[`spoolman-slot-assignments-all`],queryFn:()=>Z.getSpoolmanSlotAssignments(),enabled:!!u,staleTime:30*1e3}),{data:m=[]}=K({queryKey:[`spoolman-inventory-spools`],queryFn:()=>Z.getSpoolmanInventorySpools(!1),enabled:!!u,staleTime:30*1e3}),{data:h}=K({queryKey:[`spool-assignments`,e],queryFn:()=>Z.getAssignments(e),enabled:e!==null,staleTime:30*1e3}),g=(0,y.useMemo)(()=>{let e={};if(!h)return e;for(let t of h){let n=t.spool;if(n&&n.label_weight>0&&n.weight_used!=null){let r=Math.round(Math.max(0,n.label_weight-n.weight_used)/n.label_weight*100);e[`${t.ams_id}-${t.tray_id}`]=r}}return e},[h]),_=o?.serial_number??``,v=(0,y.useCallback)((t,n,r)=>{if(e!==null&&p.length&&m.length){let r=p.find(r=>r.printer_id===e&&r.ams_id===t&&r.tray_id===n);if(r){let e=m.find(e=>e.id===r.spoolman_spool_id);if(e&&(e.label_weight??0)>0)return Math.round(Math.max(0,e.label_weight-e.weight_used)/e.label_weight*100)}}if(f&&_){let e=(r?.tray_uuid||r?.tag_uid||Lp(_,t,n))?.toUpperCase(),i=Pp(e?f[e]:void 0);if(i!==null)return i}return null},[f,_,e,p,m]),b=a?.connected??!1,x=(0,y.useRef)({});(0,y.useEffect)(()=>{e&&a?.ams&&a.ams.length>0&&(x.current[e]=a.ams)},[a?.ams,e]);let S=(0,y.useMemo)(()=>{let t=a?.ams;return t&&t.length>0?t:(e?x.current[e]:null)??[]},[a?.ams,e]),C=(0,y.useMemo)(()=>S.filter(e=>!e.is_ams_ht),[S]),w=(0,y.useMemo)(()=>S.filter(e=>e.is_ams_ht),[S]),T=(0,y.useMemo)(()=>{let e={};if(!f||!_)return e;for(let t of C)for(let n=0;n<(t.tray?.length??0);n++){let r=t.tray[n],i=v(t.id,n,X9(r)?null:r);i!==null&&(e[`${t.id}-${n}`]=i)}return e},[f,_,C,v]),E=(0,y.useRef)(void 0),D=a?.tray_now;D!==void 0&&D!==255?E.current=D:D===255&&(E.current=void 0);let O=D!==void 0&&D!==255?D:E.current,k=o?.nozzle_count===2||a?.temperatures?.nozzle_2!==void 0,A=(0,y.useMemo)(()=>[...a?.vt_tray??[]].sort((e,t)=>(e.id??254)-(t.id??254)),[a?.vt_tray]),j=c?{humidityGood:Number(c.ams_humidity_good)||40,humidityFair:Number(c.ams_humidity_fair)||60,tempGood:Number(c.ams_temp_good)||28,tempFair:Number(c.ams_temp_fair)||35}:void 0,M=(0,y.useRef)({});(0,y.useEffect)(()=>{a?.ams_extruder_map&&Object.keys(a.ams_extruder_map).length>0&&(M.current=a.ams_extruder_map)},[a?.ams_extruder_map]);let N=a?.ams_extruder_map&&Object.keys(a.ams_extruder_map).length>0?a.ams_extruder_map:M.current,P=(0,y.useCallback)(e=>{if(!k)return null;let t=N[String(e)],n=e>=128?e-128:e;return(t===void 0?n:t)===1?`L`:`R`},[k,N]),[F,I]=(0,y.useState)(null),[L,R]=(0,y.useState)(null),[z,B]=(0,y.useState)(null),[V,ee]=(0,y.useState)(null),te=(0,y.useCallback)((e,t)=>h?.find(n=>n.ams_id===Number(e)&&n.tray_id===Number(t)),[h]),ne=(0,y.useCallback)((e,t,n)=>{if(!f||!_)return;let r=(n?.tray_uuid||n?.tag_uid||Lp(_,e,t))?.toUpperCase();return r?f[r]:void 0},[f,_]),re=q({mutationFn:({printerId:e,amsId:t,trayId:n})=>Z.unassignSpool(e,t,n),onSuccess:()=>{r.invalidateQueries({queryKey:[`spool-assignments`,e]}),r.invalidateQueries({queryKey:[`spool-assignments`]}),i(n(`inventory.unassignSuccess`,`Spool unassigned`),`success`),R(null)}}),ie=q({mutationFn:e=>Z.unlinkSpool(e),onSuccess:e=>{i(n(`spoolman.unlinkSuccess`)||e?.message,`success`),r.invalidateQueries({queryKey:[`linked-spools`]}),r.invalidateQueries({queryKey:[`unlinked-spools`]}),r.invalidateQueries({queryKey:[`spoolman-slot-assignments`]}),r.invalidateQueries({queryKey:[`spoolman-slot-assignments-all`]}),r.invalidateQueries({queryKey:[`spoolman-inventory-spools`]}),R(null)},onError:e=>{i(e.message||n(`spoolman.unlinkFailed`),`error`)}}),ae=q({mutationFn:e=>Z.unassignSpoolmanSlot(e),onSuccess:()=>{i(n(`inventory.unassignSuccess`,`Spool unassigned`),`success`),r.invalidateQueries({queryKey:[`spoolman-slot-assignments`]}),r.invalidateQueries({queryKey:[`spoolman-slot-assignments-all`]}),r.invalidateQueries({queryKey:[`spoolman-inventory-spools`]}),r.invalidateQueries({queryKey:[`unlinked-spools`]}),r.invalidateQueries({queryKey:[`linked-spools`]}),R(null)},onError:e=>{i(e.message||n(`inventory.assignFailed`,`Failed to unassign spool`),`error`)}}),oe=(0,y.useCallback)(e=>O===void 0?null:e<=3&&Math.floor(O/4)===e?O%4:e>=128&&e<=135&&O===Mp(e,0,!1)?0:null,[O]),se=(0,y.useCallback)((e,t,n)=>{let r=Mp(e,t,!1),i=s?.[r],a=N[String(e)],o=e>=128?e-128:e,c=a===void 0?o:a;R({amsId:e,trayId:t,trayCount:n&&e>=128?1:4,tray:n,trayType:n?.tray_type||void 0,trayColor:n?.tray_color||void 0,traySubBrands:n?.tray_sub_brands||void 0,trayInfoIdx:n?.tray_info_idx||void 0,extruderId:k?c:void 0,caliIdx:n?.cali_idx,savedPresetId:i?.preset_id,location:`${_2e(e)} Slot ${t+1}`})},[s,N,k]),H=(0,y.useCallback)(e=>{let t=e.id??254,n=t-254,r=s?.[1020+n];R({amsId:255,trayId:n,trayCount:1,tray:X9(e)?null:e,trayType:e.tray_type||void 0,trayColor:e.tray_color||void 0,traySubBrands:e.tray_sub_brands||void 0,trayInfoIdx:e.tray_info_idx||void 0,extruderId:k?+(t===254):void 0,caliIdx:e.cali_idx,savedPresetId:r?.preset_id,location:k?t===254?`Ext-L`:`Ext-R`:`External`})},[s,k]),ce=(0,y.useCallback)(()=>{if(!L)return;let{tray:e,location:t,...n}=L;R(null),I(n)},[L]),le=(0,y.useCallback)(()=>{if(!L||!e)return;let{amsId:t,trayId:n,trayType:r,trayColor:i,location:a}=L;R(null),B({printerId:e,amsId:t,trayId:n,trayInfo:{type:r||``,material:r,color:i?.slice(0,6)||``,location:a}})},[L,e]),ue=(0,y.useCallback)(()=>{if(!L||!e)return;let{amsId:t,trayId:n,tray:r}=L,i=(r?.tray_uuid||r?.tag_uid||Lp(_,t,n))?.toUpperCase()||``;R(null),ee({tagUid:r?.tag_uid||i,trayUuid:r?.tray_uuid||``,printerId:e,amsId:t,trayId:n})},[L,e,_]),de=(0,y.useCallback)(()=>{if(!L||!e)return;let{amsId:t,trayId:n}=L;re.mutate({printerId:e,amsId:t,trayId:n})},[L,e,re]);(0,y.useEffect)(()=>{if(!b&&e){t({type:`warning`,message:n(`spoolbuddy.ams.printerDisconnected`,`Printer disconnected`)});return}for(let e of S){let n=e.tray||[];for(let r=0;r=0&&i.remain<15&&i.tray_type){let n=e.id===254||e.id===255,a=!n&&e.id>=128,o=jp(e.id,r,a,n);t({type:`warning`,message:`Low Filament: ${i.tray_type} (${o}) - ${i.remain}% remaining`});return}}}t(null)},[S,b,e,t,n]);let fe=(0,y.useMemo)(()=>{let e=[];for(let t of w){let n=t.tray?.[0]||{id:0,tray_color:null,tray_type:``,tray_sub_brands:null,tray_id_name:null,tray_info_idx:null,remain:-1,k:null,cali_idx:null,tag_uid:null,tray_uuid:null,nozzle_temp_min:null,nozzle_temp_max:null},r=v(t.id,0,X9(n)?null:n),i=g[`${t.id}-0`]??null,a=n.remain!=null&&n.remain>=0?n.remain:null,o=i===0&&a!==null&&a>0?null:i;e.push({key:`ht-${t.id}`,label:_2e(t.id),tray:n,isEmpty:X9(n),isActive:oe(t.id)===0,temp:t.temp,humidity:t.humidity,nozzleSide:P(t.id),effectiveFill:r??o??a,onClick:()=>se(t.id,0,X9(n)?null:n)})}for(let t of A){let r=t.id??254,i=k&&O===254?r===254&&a?.active_extruder===1||r===255&&a?.active_extruder===0:O===r,o=r-254,s=v(255,o,X9(t)?null:t),c=g[`255-${o}`]??null,l=t.remain!=null&&t.remain>=0?t.remain:null,u=c===0&&l!==null&&l>0?null:c;e.push({key:`ext-${r}`,label:k?r===254?n(`printers.extL`,`Ext-L`):n(`printers.extR`,`Ext-R`):n(`printers.ext`,`Ext`),tray:t,isEmpty:X9(t),isActive:i,nozzleSide:null,effectiveFill:s??u??l,onClick:()=>H(t)})}return e},[w,A,k,O,a?.active_extruder,n,oe,P,se,H,g,v]);return(0,G.jsxs)(`div`,{className:`h-full flex flex-col p-4`,children:[(0,G.jsx)(`div`,{className:`flex-1 min-h-0`,children:e?b?S.length===0&&A.length===0?(0,G.jsx)(`div`,{className:`flex-1 flex items-center justify-center h-full`,children:(0,G.jsxs)(`div`,{className:`text-center text-white/50`,children:[(0,G.jsx)(Jc,{className:`w-12 h-12 mx-auto mb-3 opacity-50`}),(0,G.jsx)(`p`,{className:`text-lg mb-2`,children:n(`spoolbuddy.ams.noData`,`No AMS detected`)}),(0,G.jsx)(`p`,{className:`text-sm`,children:n(`spoolbuddy.ams.connectAms`,`Connect an AMS to see filament slots`)})]})}):(0,G.jsxs)(`div`,{className:`flex flex-col gap-3 h-full`,children:[(0,G.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-3`,children:C.map(e=>(0,G.jsx)(o2e,{unit:e,activeSlot:oe(e.id),onConfigureSlot:se,isDualNozzle:k,nozzleSide:P(e.id),thresholds:j,fillOverrides:g,spoolmanFillOverrides:T},e.id))}),fe.length>0&&(0,G.jsx)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-3`,children:fe.map(({key:e,label:t,tray:n,isEmpty:r,isActive:i,temp:a,humidity:o,nozzleSide:s,effectiveFill:c,onClick:l})=>{let u=y2e(n.tray_color);return(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg px-3 py-2 cursor-pointer hover:bg-bambu-dark-secondary/80 transition-all flex items-center gap-3 ${i?`ring-2 ring-bambu-green`:``}`,onClick:l,children:[(0,G.jsxs)(`div`,{className:`relative w-10 h-10 flex-shrink-0`,children:[r?(0,G.jsx)(`div`,{className:`w-full h-full rounded-full border-2 border-dashed border-gray-500 flex items-center justify-center`,children:(0,G.jsx)(`div`,{className:`w-1.5 h-1.5 rounded-full bg-gray-600`})}):(0,G.jsxs)(`svg`,{viewBox:`0 0 56 56`,className:`w-full h-full`,children:[(0,G.jsx)(`circle`,{cx:`28`,cy:`28`,r:`26`,fill:u}),(0,G.jsx)(`circle`,{cx:`28`,cy:`28`,r:`20`,fill:u,style:{filter:`brightness(0.85)`}}),(0,G.jsx)(`ellipse`,{cx:`20`,cy:`20`,rx:`6`,ry:`4`,fill:`white`,opacity:`0.3`}),(0,G.jsx)(`circle`,{cx:`28`,cy:`28`,r:`8`,fill:`#2d2d2d`}),(0,G.jsx)(`circle`,{cx:`28`,cy:`28`,r:`5`,fill:`#1a1a1a`})]}),i&&(0,G.jsx)(`div`,{className:`absolute -bottom-0.5 left-1/2 -translate-x-1/2 w-1.5 h-1.5 bg-bambu-green rounded-full`})]}),(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(`span`,{className:`text-xs text-white/50 font-medium truncate`,children:t}),s&&(0,G.jsx)(G9,{side:s})]}),(0,G.jsx)(`div`,{className:`text-sm text-white/80 truncate`,children:r?`Empty`:n.tray_type||`?`}),(a!=null||o!=null)&&(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[a!=null&&(0,G.jsx)(i2e,{temp:a,goodThreshold:j?.tempGood,fairThreshold:j?.tempFair}),o!=null&&(0,G.jsx)(r2e,{humidity:o,goodThreshold:j?.humidityGood,fairThreshold:j?.humidityFair})]})]}),!r&&c!=null&&c>=0&&(0,G.jsx)(`div`,{className:`w-1.5 h-8 bg-bambu-dark-tertiary rounded-full overflow-hidden flex-shrink-0 flex flex-col-reverse`,children:(0,G.jsx)(`div`,{className:`w-full rounded-full`,style:{height:`${c}%`,backgroundColor:Np(c)}})})]},e)})})]}):(0,G.jsx)(`div`,{className:`flex-1 flex items-center justify-center h-full`,children:(0,G.jsx)(`div`,{className:`text-center text-white/50`,children:(0,G.jsx)(`p`,{className:`text-lg mb-2`,children:n(`spoolbuddy.ams.printerDisconnected`,`Printer disconnected`)})})}):(0,G.jsx)(`div`,{className:`flex-1 flex items-center justify-center h-full`,children:(0,G.jsxs)(`div`,{className:`text-center text-white/50`,children:[(0,G.jsx)(`p`,{className:`text-lg mb-2`,children:n(`spoolbuddy.ams.noPrinter`,`No printer selected`)}),(0,G.jsx)(`p`,{className:`text-sm`,children:n(`spoolbuddy.ams.selectPrinter`,`Select a printer from the top bar`)})]})})}),F&&e&&(0,G.jsx)(mU,{isOpen:!!F,onClose:()=>I(null),printerId:e,slotInfo:F,printerModel:v2e(o?.model??null)||void 0,nozzleDiameter:Gp(a,F.amsId),fullScreen:!0,onSuccess:()=>{r.invalidateQueries({queryKey:[`slotPresets`,e]}),r.invalidateQueries({queryKey:[`printerStatus`,e]})}}),L&&e&&(()=>{let t=te(L.amsId,L.trayId),r=ne(L.amsId,L.trayId,L.tray),i=u?p.find(t=>t.printer_id===e&&t.ams_id===L.amsId&&t.tray_id===L.trayId):void 0,a=i?m.find(e=>e.id===i.spoolman_spool_id)??null:null;return(0,G.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[(0,G.jsx)(`div`,{className:`absolute inset-0 bg-black/60 backdrop-blur-sm`,onClick:()=>R(null)}),(0,G.jsxs)(`div`,{className:`relative w-full max-w-sm mx-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl shadow-2xl`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[L.trayColor&&(0,G.jsx)(`span`,{className:`w-4 h-4 rounded-full border border-black/20`,style:{backgroundColor:`#${L.trayColor.slice(0,6)}`}}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:L.location}),L.traySubBrands&&(0,G.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[`(`,L.traySubBrands,`)`]})]}),(0,G.jsx)(`button`,{onClick:()=>R(null),className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]}),(0,G.jsxs)(`div`,{className:`p-4 space-y-2`,children:[!u&&t?.spool&&(0,G.jsxs)(`div`,{className:`p-2.5 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary mb-3`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mb-1`,children:n(`inventory.assignedSpool`,`Assigned spool`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[t.spool.rgba&&(0,G.jsx)(`span`,{className:`w-3 h-3 rounded-full border border-black/20 flex-shrink-0`,style:Mf(t.spool.rgba)}),(0,G.jsxs)(`span`,{className:`text-sm text-white`,children:[t.spool.brand?`${t.spool.brand} `:``,t.spool.material,t.spool.subtype?` ${t.spool.subtype}`:``,t.spool.color_name?` - ${t.spool.color_name}`:``]}),(0,G.jsxs)(`span`,{className:`text-[10px] font-mono text-zinc-500 shrink-0 ml-auto`,children:[`#`,t.spool.id]})]})]}),u&&r&&!a&&(0,G.jsxs)(`div`,{className:`p-2.5 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary mb-3`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mb-1`,children:n(`spoolman.linkedSpool`,`Linked spool`)}),(0,G.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,G.jsxs)(`span`,{className:`text-sm text-white`,children:[`Spoolman #`,r.id,r.remaining_weight==null?``:` (${Math.round(r.remaining_weight)}g)`]})})]}),u&&a&&(0,G.jsxs)(`div`,{className:`p-2.5 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary mb-3`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mb-1`,children:n(`inventory.assignedSpool`,`Assigned spool`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[a.rgba&&(0,G.jsx)(`span`,{className:`w-3 h-3 rounded-full border border-black/20 flex-shrink-0`,style:Mf(a.rgba)}),(0,G.jsxs)(`span`,{className:`text-sm text-white`,children:[a.brand?`${a.brand} `:``,a.material,a.subtype?` ${a.subtype}`:``,a.color_name?` - ${a.color_name}`:``]})]})]}),(0,G.jsxs)(`button`,{onClick:ce,className:`w-full flex items-center gap-3 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary hover:border-bambu-blue transition-colors text-left`,children:[(0,G.jsx)(nu,{className:`w-5 h-5 text-bambu-blue flex-shrink-0`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white font-medium`,children:n(`configureAmsSlot.title`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`spoolbuddy.ams.configureDesc`,`Set filament preset, K-profile, and color`)})]})]}),!u&&(Kp(L?.tray)?null:t?(0,G.jsxs)(`button`,{onClick:de,disabled:re.isPending,className:`w-full flex items-center gap-3 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary hover:border-amber-500 transition-colors text-left`,children:[(0,G.jsx)(Bu,{className:`w-5 h-5 text-amber-400 flex-shrink-0`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-amber-400 font-medium`,children:n(`inventory.unassignSpool`,`Unassign`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`spoolbuddy.ams.unassignDesc`,`Remove inventory spool from this slot`)})]})]}):(0,G.jsxs)(`button`,{onClick:le,className:`w-full flex items-center gap-3 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary hover:border-bambu-green transition-colors text-left`,children:[(0,G.jsx)(Cl,{className:`w-5 h-5 text-bambu-green flex-shrink-0`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white font-medium`,children:n(`inventory.assignSpool`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`spoolbuddy.ams.assignDesc`,`Track a spool from your inventory`)})]})]})),u&&(r?.id?(0,G.jsxs)(`button`,{onClick:()=>ie.mutate(r.id),disabled:ie.isPending,className:`w-full flex items-center gap-3 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary hover:border-amber-500 transition-colors text-left active:opacity-50`,children:[(0,G.jsx)(Bu,{className:`w-5 h-5 text-amber-400 flex-shrink-0`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-amber-400 font-medium`,children:n(`inventory.unassignSpool`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`spoolbuddy.ams.unlinkDesc`,`Remove Spoolman link from this slot`)})]})]}):a?(0,G.jsxs)(`button`,{onClick:()=>ae.mutate(a.id),disabled:ae.isPending,className:`w-full flex items-center gap-3 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary hover:border-amber-500 transition-colors text-left active:opacity-50`,children:[(0,G.jsx)(Bu,{className:`w-5 h-5 text-amber-400 flex-shrink-0`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-amber-400 font-medium`,children:n(`inventory.unassignSpool`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`spoolbuddy.ams.unassignDesc`,`Remove inventory spool from this slot`)})]})]}):(0,G.jsxs)(`button`,{onClick:ue,className:`w-full flex items-center gap-3 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary hover:border-bambu-green transition-colors text-left`,children:[(0,G.jsx)(Xc,{className:`w-5 h-5 text-bambu-green flex-shrink-0`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white font-medium`,children:n(`inventory.assignSpool`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`spoolbuddy.ams.linkDesc`,`Link a Spoolman spool to this slot`)})]})]}))]})]})]})})(),z&&(0,G.jsx)(TH,{isOpen:!!z,onClose:()=>{B(null),r.invalidateQueries({queryKey:[`spool-assignments`,e]}),r.invalidateQueries({queryKey:[`spool-assignments`]})},printerId:z.printerId,amsId:z.amsId,trayId:z.trayId,trayInfo:z.trayInfo,spoolmanEnabled:!!u}),V&&(0,G.jsx)(CH,{isOpen:!!V,onClose:()=>ee(null),tagUid:V.tagUid,trayUuid:V.trayUuid,printerId:V.printerId,amsId:V.amsId,trayId:V.trayId})]})}function x2e({type:e,deviceId:t,onClose:n}){let{t:r}=U(),[i,a]=(0,y.useState)(!1),[o,s]=(0,y.useState)(``),[c,l]=(0,y.useState)(``),[u,d]=(0,y.useState)(!1);(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&!i&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[i,n]);let f=(0,y.useCallback)(async()=>{a(!0),s(``),l(``),d(!0);try{s(r(`spoolbuddy.diagnostic.queuing`,`Queuing diagnostic on device... -`)),await Od.queueDiagnostics(t,e);let n=null,i=0;for(;i<60&&!n;){await new Promise(e=>setTimeout(e,500));try{n=await Od.getDiagnosticResult(t,e);break}catch{i++,i%4==0&&s(e=>e+`.`)}}if(!n)throw Error(`Diagnostic timed out - device did not report results`);s(n.output),n.success||l(`Exit code: ${n.exit_code}`)}catch(e){l(e instanceof Error?e.message:`Unknown error`),s(``)}finally{a(!1)}},[e,t,r]);return(0,G.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/70 animate-fade-in`,onClick:n,children:(0,G.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg shadow-xl w-full max-w-2xl mx-4 max-h-[80vh] flex flex-col animate-slide-up`,onClick:e=>e.stopPropagation(),children:[(0,G.jsxs)(`div`,{className:`flex justify-between items-center p-4 border-b border-zinc-700`,children:[(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e===`scale`?r(`spoolbuddy.diagnostic.scaleTitle`,`Scale Diagnostic`):e===`read_tag`?r(`spoolbuddy.diagnostic.readTagTitle`,`Read Tag Diagnostic`):r(`spoolbuddy.diagnostic.nfcTitle`,`NFC Reader Diagnostic`)}),(0,G.jsx)(`button`,{onClick:n,className:`text-zinc-400 hover:text-white transition-colors`,"aria-label":`Close`,children:(0,G.jsx)(nd,{size:20})})]}),(0,G.jsx)(`div`,{className:`flex-1 overflow-auto p-4 bg-black/50 font-mono text-sm`,children:i?(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-green-400`,children:[(0,G.jsx)(`div`,{className:`animate-spin w-4 h-4 border-2 border-green-400 border-t-transparent rounded-full`}),(0,G.jsx)(`span`,{children:r(`spoolbuddy.diagnostic.running`,`Running diagnostic on device...`)})]}):o?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`text-green-400 whitespace-pre-wrap break-words`,children:o}),c&&(0,G.jsxs)(`div`,{className:`text-red-400 mt-2`,children:[`❌ `,c]})]}):u?(0,G.jsx)(`div`,{children:c?(0,G.jsxs)(`div`,{className:`text-red-400`,children:[`ERROR: `,c]}):(0,G.jsx)(`span`,{className:`text-green-400`,children:r(`spoolbuddy.diagnostic.completed`,`Diagnostic completed successfully.`)})}):(0,G.jsxs)(`div`,{className:`text-zinc-500`,children:[r(`spoolbuddy.diagnostic.clickStart`,`Click "Run Diagnostic" to start the hardware diagnostic on`),` `,t,`.`]})}),(0,G.jsxs)(`div`,{className:`flex gap-2 p-4 border-t border-zinc-700 bg-zinc-800`,children:[(0,G.jsx)(`button`,{onClick:f,disabled:i,className:`flex-1 flex items-center justify-center gap-2 bg-green-600 hover:bg-green-700 disabled:bg-gray-600 disabled:cursor-not-allowed px-4 py-2 rounded font-semibold text-white transition-colors`,children:i?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`animate-spin w-4 h-4 border-2 border-white border-t-transparent rounded-full`}),r(`spoolbuddy.diagnostic.runningBtn`,`Running...`)]}):u?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Gl,{size:16}),r(`spoolbuddy.diagnostic.runAgain`,`Run Again`)]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Nl,{size:16}),r(`spoolbuddy.diagnostic.runBtn`,`Run Diagnostic`)]})}),(0,G.jsx)(`button`,{onClick:n,className:`px-4 py-2 rounded bg-zinc-700 hover:bg-zinc-600 text-white font-semibold transition-colors`,children:r(`spoolbuddy.diagnostic.close`,`Close`)})]})]})})}function S2e(e){return e<60?`${e}s`:e<3600?`${Math.floor(e/60)}m`:`${Math.floor(e/3600)}h ${Math.floor(e%3600/60)}m`}function C2e(e){if(!e)return`-`;let t=rp(e);return t?t.toLocaleDateString(void 0,{month:`short`,day:`numeric`})+` `+t.toLocaleTimeString(void 0,{hour:`2-digit`,minute:`2-digit`}):`-`}var w2e=[{label:`Off`,value:0},{label:`1m`,value:60},{label:`2m`,value:120},{label:`5m`,value:300},{label:`10m`,value:600},{label:`30m`,value:1800}];function T2e({device:e}){let{t}=U(),[n,r]=(0,y.useState)(null),[i,a]=(0,y.useState)(``),[o,s]=(0,y.useState)(``),[c,l]=(0,y.useState)(!1),[u,d]=(0,y.useState)(null);return(0,y.useEffect)(()=>{!i&&e.backend_url&&a(e.backend_url)},[e.backend_url,i]),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,G.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-3`,children:[(0,G.jsx)(`h3`,{className:`text-sm font-semibold text-zinc-300 mb-2`,children:t(`spoolbuddy.settings.nfcReader`,`NFC Reader`)}),(0,G.jsxs)(`div`,{className:`space-y-1.5 text-xs`,children:[(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.type`,`Type`)}),(0,G.jsx)(`span`,{className:`text-zinc-300 font-mono`,children:e.nfc_reader_type||`N/A`})]}),(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.connection`,`Connection`)}),(0,G.jsx)(`span`,{className:`text-zinc-300 font-mono`,children:e.nfc_connection||`N/A`})]}),(0,G.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.status.status`,`Status`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,G.jsx)(`div`,{className:`w-2 h-2 rounded-full ${e.nfc_ok?`bg-green-500`:e.nfc_reader_type?`bg-red-500`:`bg-zinc-600`}`}),(0,G.jsx)(`span`,{className:e.nfc_ok?`text-green-400`:e.nfc_reader_type?`text-red-400`:`text-zinc-500`,children:e.nfc_ok?t(`spoolbuddy.status.nfcReady`,`Ready`):e.nfc_reader_type?t(`common.error`,`Error`):t(`spoolbuddy.settings.notConnected`,`N/A`)})]})]})]})]}),(0,G.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-3`,children:[(0,G.jsx)(`h3`,{className:`text-sm font-semibold text-zinc-300 mb-2`,children:t(`spoolbuddy.settings.deviceInfo`,`Device Info`)}),(0,G.jsxs)(`div`,{className:`space-y-1.5 text-xs`,children:[(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.hostname`,`Host`)}),(0,G.jsx)(`span`,{className:`text-zinc-300 truncate ml-2`,children:e.hostname})]}),(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:`IP`}),(0,G.jsx)(`span`,{className:`text-zinc-300`,children:e.ip_address})]}),(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.uptime`,`Uptime`)}),(0,G.jsx)(`span`,{className:`text-zinc-300`,children:S2e(e.uptime_s)})]}),(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:`ID`}),(0,G.jsx)(`span`,{className:`text-zinc-400 font-mono truncate ml-2`,children:e.device_id})]})]})]})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,G.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-3 space-y-2`,children:[(0,G.jsx)(`h3`,{className:`text-sm font-semibold text-zinc-300`,children:t(`spoolbuddy.settings.systemConfig`,`Backend & Auth`)}),(0,G.jsx)(`input`,{value:i,onChange:e=>a(e.target.value),placeholder:`http://192.168.1.100:5000`,className:`w-full px-2 py-1.5 rounded bg-zinc-900 border border-zinc-700 text-zinc-100 text-xs`}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsx)(`input`,{type:`password`,value:o,onChange:e=>s(e.target.value),placeholder:t(`spoolbuddy.settings.apiTokenPlaceholder`,`API token`),className:`flex-1 px-2 py-1.5 rounded bg-zinc-900 border border-zinc-700 text-zinc-100 text-xs`}),(0,G.jsx)(`button`,{onClick:async()=>{if(!i.trim()){d({type:`error`,text:t(`spoolbuddy.settings.systemFieldsRequired`,`Backend URL is required.`)});return}l(!0),d(null);try{await Od.updateSystemConfig(e.device_id,i.trim(),o.trim()||void 0),d({type:`ok`,text:t(`spoolbuddy.settings.systemQueued`,`Config queued.`)})}catch(e){d({type:`error`,text:e instanceof Error?e.message:t(`common.error`,`Error`)})}finally{l(!1)}},disabled:c,className:`px-3 py-1.5 rounded bg-green-700 hover:bg-green-600 disabled:bg-zinc-700 text-xs font-medium text-zinc-100`,children:t(`spoolbuddy.settings.saveConfig`,`Save`)})]}),u&&(0,G.jsx)(`div`,{className:`text-xs ${u.type===`ok`?`text-green-400`:`text-red-400`}`,children:u.text})]}),(0,G.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-3 flex flex-col gap-2`,children:[(0,G.jsxs)(`button`,{onClick:()=>r(`nfc`),className:`flex-1 bg-blue-700 hover:bg-blue-600 transition-colors rounded-lg p-2 flex items-center gap-2`,children:[(0,G.jsx)(Yu,{className:`w-4 h-4 text-blue-300 shrink-0`}),(0,G.jsx)(`span`,{className:`text-xs font-medium text-blue-100`,children:t(`spoolbuddy.settings.nfcDiagnostic`,`NFC Diagnostic`)})]}),(0,G.jsxs)(`button`,{onClick:()=>r(`scale`),className:`flex-1 bg-yellow-700 hover:bg-yellow-600 transition-colors rounded-lg p-2 flex items-center gap-2`,children:[(0,G.jsx)(id,{className:`w-4 h-4 text-yellow-300 shrink-0`}),(0,G.jsx)(`span`,{className:`text-xs font-medium text-yellow-100`,children:t(`spoolbuddy.settings.scaleDiagnostic`,`Scale Diagnostic`)})]}),(0,G.jsxs)(`button`,{onClick:()=>r(`read_tag`),className:`flex-1 bg-emerald-700 hover:bg-emerald-600 transition-colors rounded-lg p-2 flex items-center gap-2`,children:[(0,G.jsx)(fc,{className:`w-4 h-4 text-emerald-300 shrink-0`}),(0,G.jsx)(`span`,{className:`text-xs font-medium text-emerald-100`,children:t(`spoolbuddy.settings.readTagDiagnostic`,`Read Tag`)})]})]})]}),n&&e&&(0,G.jsx)(x2e,{type:n,deviceId:e.device_id,onClose:()=>r(null)})]})}function E2e({device:e,onBrightnessChange:t}){let{t:n}=U(),[r,i]=(0,y.useState)(e.display_brightness),[a,o]=(0,y.useState)(e.display_blank_timeout),[s,c]=(0,y.useState)(!1),l=(0,y.useRef)(void 0),u=(0,y.useRef)(void 0);(0,y.useEffect)(()=>{i(e.display_brightness),o(e.display_blank_timeout)},[e.display_brightness,e.display_blank_timeout]);let d=(0,y.useCallback)(()=>{c(!0),u.current&&clearTimeout(u.current),u.current=setTimeout(()=>c(!1),1500)},[]),f=(0,y.useCallback)((t,n)=>{l.current&&clearTimeout(l.current),l.current=setTimeout(()=>{Od.updateDisplay(e.device_id,t,n).then(()=>d()).catch(e=>console.error(`Failed to update display:`,e))},300)},[e.device_id,d]),p=e=>{i(e),t(e),f(e,a)},m=e=>{o(e),f(r,e)};return(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,G.jsx)(`h3`,{className:`text-sm font-semibold text-zinc-300`,children:n(`spoolbuddy.settings.brightness`,`Brightness`)}),s&&(0,G.jsxs)(`span`,{className:`text-xs text-green-400 flex items-center gap-1 animate-pulse`,children:[(0,G.jsx)(`svg`,{className:`w-3 h-3`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:3,children:(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M5 13l4 4L19 7`})}),n(`spoolbuddy.settings.saved`,`Saved`)]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`svg`,{className:`w-4 h-4 text-zinc-500 flex-shrink-0`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:2,children:(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M12 3v1m0 16v1m9-9h-1M4 12H3m15.364 6.364l-.707-.707M6.343 6.343l-.707-.707m12.728 0l-.707.707M6.343 17.657l-.707.707M16 12a4 4 0 11-8 0 4 4 0 018 0z`})}),(0,G.jsx)(`input`,{type:`range`,min:0,max:100,value:r,onChange:e=>p(parseInt(e.target.value)),className:`flex-1 h-2 bg-zinc-700 rounded-lg appearance-none cursor-pointer accent-green-500`}),(0,G.jsxs)(`span`,{className:`text-sm font-mono text-zinc-400 w-10 text-right`,children:[r,`%`]})]}),!e.has_backlight&&(0,G.jsx)(`p`,{className:`text-xs text-zinc-600 mt-2`,children:n(`spoolbuddy.settings.noBacklight`,`No DSI backlight detected. Brightness control requires a DSI display.`)})]}),(0,G.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-4`,children:[(0,G.jsx)(`h3`,{className:`text-sm font-semibold text-zinc-300 mb-1`,children:n(`spoolbuddy.settings.screenBlank`,`Screen Blank Timeout`)}),(0,G.jsx)(`p`,{className:`text-xs text-zinc-500 mb-3`,children:n(`spoolbuddy.settings.screenBlankDesc`,`Screen turns off after inactivity. Touch to wake.`)}),(0,G.jsx)(`div`,{className:`grid grid-cols-3 gap-2`,children:w2e.map(e=>(0,G.jsx)(`button`,{onClick:()=>m(e.value),className:`px-3 py-2 rounded-lg text-sm font-medium transition-colors min-h-[40px] ${a===e.value?`bg-green-600 text-white`:`bg-zinc-700 text-zinc-300 hover:bg-zinc-600`}`,children:e.label},e.value))})]}),(0,G.jsx)(`p`,{className:`text-xs text-zinc-600 text-center`,children:n(`spoolbuddy.settings.displayNote`,`Brightness is applied as a software filter.`)})]})}function D2e({step:e,labels:t}){return(0,G.jsxs)(`div`,{className:`flex flex-col items-center w-16 shrink-0 pt-1`,children:[(0,G.jsx)(`div`,{className:`flex items-center justify-center w-7 h-7 rounded-full text-xs font-bold ${e===`tare`?`bg-green-600 text-white`:`bg-green-600/20 text-green-400`}`,children:e===`weight`?(0,G.jsx)(`svg`,{className:`w-3.5 h-3.5`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:3,children:(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M5 13l4 4L19 7`})}):`1`}),(0,G.jsx)(`span`,{className:`text-[10px] mt-0.5 ${e===`tare`?`text-green-400 font-medium`:`text-green-400/60`}`,children:t.tare}),(0,G.jsx)(`div`,{className:`w-px h-5 my-1 ${e===`weight`?`bg-green-600/40`:`bg-zinc-700`}`}),(0,G.jsx)(`div`,{className:`flex items-center justify-center w-7 h-7 rounded-full text-xs font-bold ${e===`weight`?`bg-green-600 text-white`:`bg-zinc-700 text-zinc-500`}`,children:`2`}),(0,G.jsx)(`span`,{className:`text-[10px] mt-0.5 ${e===`weight`?`text-green-400 font-medium`:`text-zinc-600`}`,children:t.weight})]})}function O2e({device:e,weight:t,weightStable:n,rawAdc:r}){let{t:i}=U(),a=co(),[o,s]=(0,y.useState)(`idle`),[c,l]=(0,y.useState)(`500`),[u,d]=(0,y.useState)(null),[f,p]=(0,y.useState)(!1),[m,h]=(0,y.useState)(null),[g,_]=(0,y.useState)(null),v=(0,y.useRef)(null);(0,y.useEffect)(()=>()=>{v.current&&clearTimeout(v.current)},[]);let b=(0,y.useCallback)(e=>{v.current&&clearTimeout(v.current),v.current=setTimeout(()=>h(null),e)},[]);(0,y.useEffect)(()=>{if(!g)return;let e=()=>Date.now()-g.startedAtMs,t=setInterval(()=>{a.invalidateQueries({queryKey:[`spoolbuddy-devices`]})},1e3),n=setTimeout(()=>{_(null),h({type:`error`,msg:i(`spoolbuddy.settings.tareTimedOut`,`Tare timed out — is the SpoolBuddy daemon running?`)}),b(5e3)},Math.max(0,15e3-e()));return()=>{clearInterval(t),clearTimeout(n)}},[g,a,i,b]),(0,y.useEffect)(()=>{g&&(e?.last_calibrated_at??null)!==g.snapshot&&(_(null),h({type:`ok`,msg:i(`spoolbuddy.settings.tareComplete`,`Tare complete!`)}),b(3e3))},[e?.last_calibrated_at,g,i,b]);let x=e=>{e===`backspace`?l(e=>e.slice(0,-1)||``):e===`.`&&!c.includes(`.`)?l(e=>e+`.`):e>=`0`&&e<=`9`&&l(t=>t===`0`?e:t+e)};return o===`idle`?(0,G.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,G.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-3 mb-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`div`,{className:`w-2 h-2 rounded-full ${n?`bg-green-500`:`bg-amber-500 animate-pulse`}`}),(0,G.jsx)(`span`,{className:`text-lg font-mono text-zinc-200`,children:t===null?`-- g`:`${t.toFixed(1)} g`})]}),(0,G.jsxs)(`div`,{className:`text-xs text-zinc-500 text-right`,children:[(0,G.jsxs)(`span`,{children:[i(`spoolbuddy.settings.tareOffset`,`Tare`),`: `,e.tare_offset]}),(0,G.jsx)(`span`,{className:`mx-1.5`,children:`·`}),(0,G.jsxs)(`span`,{children:[i(`spoolbuddy.settings.calFactor`,`Factor`),`: `,e.calibration_factor.toFixed(2)]})]})]}),e.last_calibrated_at&&(0,G.jsxs)(`div`,{className:`text-xs text-zinc-600 mt-1`,children:[i(`spoolbuddy.settings.lastCalibrated`,`Last calibrated`),`: `,C2e(e.last_calibrated_at)]})]}),m&&(0,G.jsx)(`div`,{className:`rounded-lg px-3 py-2 mb-3 text-sm ${m.type===`ok`?`bg-green-900/30 text-green-300 border border-green-800`:`bg-red-900/30 text-red-300 border border-red-800`}`,children:m.msg}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsxs)(`button`,{onClick:async()=>{p(!0),h(null),v.current&&=(clearTimeout(v.current),null);let t=e?.last_calibrated_at??null;try{await Od.tare(e.device_id),h({type:`ok`,msg:i(`spoolbuddy.settings.tareSet`,`Tare command sent. Waiting for device...`)}),_({snapshot:t,startedAtMs:Date.now()})}catch{h({type:`error`,msg:i(`spoolbuddy.settings.tareFailed`,`Failed to send tare command`)}),b(5e3)}finally{p(!1)}},disabled:f,className:`flex-1 px-4 py-2.5 rounded-lg text-sm font-medium bg-zinc-700 text-zinc-200 hover:bg-zinc-600 disabled:opacity-40 transition-colors min-h-[44px] flex items-center justify-center gap-2`,children:[f&&(0,G.jsxs)(`svg`,{className:`w-4 h-4 animate-spin`,viewBox:`0 0 24 24`,fill:`none`,children:[(0,G.jsx)(`circle`,{className:`opacity-25`,cx:`12`,cy:`12`,r:`10`,stroke:`currentColor`,strokeWidth:`4`}),(0,G.jsx)(`path`,{className:`opacity-75`,fill:`currentColor`,d:`M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z`})]}),i(`spoolbuddy.weight.tare`,`Tare`)]}),(0,G.jsx)(`button`,{onClick:()=>{s(`tare`),h(null)},className:`flex-1 px-4 py-2.5 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 transition-colors min-h-[44px]`,children:i(`spoolbuddy.weight.calibrate`,`Calibrate`)})]})]}):(0,G.jsxs)(`div`,{className:`flex gap-3`,children:[(0,G.jsx)(D2e,{step:o,labels:{tare:i(`spoolbuddy.weight.tare`,`Tare`),weight:i(`spoolbuddy.settings.knownWeight`,`Known weight`)}}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 bg-zinc-800 rounded-lg px-3 py-1.5 mb-1.5`,children:[(0,G.jsx)(`div`,{className:`w-2 h-2 rounded-full shrink-0 ${n?`bg-green-500`:`bg-amber-500 animate-pulse`}`}),(0,G.jsx)(`span`,{className:`text-sm font-mono text-zinc-200`,children:t===null?`-- g`:`${t.toFixed(1)} g`}),(0,G.jsx)(`span`,{className:`text-xs ml-auto ${n?`text-green-400`:`text-amber-400`}`,children:n?i(`spoolbuddy.settings.stable`,`Stable`):i(`spoolbuddy.settings.settling`,`Settling...`)})]}),m&&(0,G.jsx)(`div`,{className:`rounded-lg px-3 py-1.5 mb-1.5 text-xs ${m.type===`ok`?`bg-green-900/30 text-green-300 border border-green-800`:`bg-red-900/30 text-red-300 border border-red-800`}`,children:m.msg}),o===`tare`?(0,G.jsx)(`p`,{className:`text-sm text-zinc-300 mb-3`,children:i(`spoolbuddy.settings.calStep1`,`Remove all items from the scale and press Set Zero.`)}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-1.5`,children:[(0,G.jsx)(`span`,{className:`text-xs text-zinc-400 shrink-0`,children:i(`spoolbuddy.settings.knownWeight`,`Known weight`)}),(0,G.jsxs)(`div`,{className:`flex-1 bg-zinc-900 border border-zinc-600 rounded px-3 py-1 text-right text-lg font-mono text-zinc-100`,children:[c||`0`,(0,G.jsx)(`span`,{className:`text-zinc-500 ml-1`,children:`g`})]})]}),(0,G.jsx)(`div`,{className:`grid grid-cols-4 gap-1 mb-1.5`,children:[`7`,`8`,`9`,`backspace`,`4`,`5`,`6`,`.`,`1`,`2`,`3`,`0`].map(e=>(0,G.jsx)(`button`,{onClick:()=>x(e),className:`rounded text-lg font-medium transition-colors h-[48px] active:scale-95 ${e===`backspace`?`bg-zinc-700 text-zinc-300 hover:bg-zinc-600`:`bg-zinc-800 text-zinc-100 hover:bg-zinc-700 border border-zinc-700`}`,children:e===`backspace`?`⌫`:e},e))})]}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsx)(`button`,{onClick:()=>{s(`idle`),h(null)},className:`flex-1 px-4 py-2 rounded-lg text-sm bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors h-[40px]`,children:i(`common.cancel`,`Cancel`)}),(0,G.jsxs)(`button`,{onClick:async()=>{if(o===`tare`){p(!0),h(null);try{d(r),await Od.tare(e.device_id),h({type:`ok`,msg:i(`spoolbuddy.settings.zeroSet`,`Zero point set. Place known weight on scale.`)}),s(`weight`)}catch{h({type:`error`,msg:i(`spoolbuddy.settings.tareFailed`,`Failed to send tare command`)})}finally{p(!1)}}else if(o===`weight`){let t=parseFloat(c);if(r===null||!t||t<=0)return;p(!0),h(null);try{await Od.setCalibrationFactor(e.device_id,t,r,u??void 0),h({type:`ok`,msg:i(`spoolbuddy.settings.calibrationDone`,`Calibration complete!`)}),b(3e3),s(`idle`)}catch{h({type:`error`,msg:i(`spoolbuddy.settings.calibrationFailed`,`Calibration failed`)}),b(5e3)}finally{p(!1)}}},disabled:f,className:`flex-1 px-4 py-2 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 disabled:opacity-40 transition-colors h-[40px] flex items-center justify-center gap-2`,children:[f&&(0,G.jsxs)(`svg`,{className:`w-4 h-4 animate-spin`,viewBox:`0 0 24 24`,fill:`none`,children:[(0,G.jsx)(`circle`,{className:`opacity-25`,cx:`12`,cy:`12`,r:`10`,stroke:`currentColor`,strokeWidth:`4`}),(0,G.jsx)(`path`,{className:`opacity-75`,fill:`currentColor`,d:`M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z`})]}),o===`tare`?i(`spoolbuddy.settings.setZero`,`Set Zero`):i(`spoolbuddy.settings.calibrateNow`,`Calibrate`)]})]})]})]})}function k2e({device:e}){let{t}=U(),[n,r]=(0,y.useState)(null),[i,a]=(0,y.useState)(null),[o,s]=(0,y.useState)(!1),[c,l]=(0,y.useState)(!1),u=e.update_status===`pending`||e.update_status===`updating`;(0,y.useEffect)(()=>{u&&n===`applying`&&r(null)},[u,n]),(0,y.useEffect)(()=>{let e=()=>{u&&setTimeout(()=>window.location.reload(),1e3)};return window.addEventListener(`spoolbuddy-online`,e),()=>window.removeEventListener(`spoolbuddy-online`,e)},[u]);let{data:d,refetch:f}=K({queryKey:[`spoolbuddy-update-check`,e.device_id],queryFn:()=>Od.checkDaemonUpdate(e.device_id),staleTime:0}),{data:p}=K({queryKey:[`spoolbuddy-ssh-key`],queryFn:()=>Od.getSSHPublicKey(),enabled:o,staleTime:1/0}),m=async()=>{r(`checking`),a(null);try{await f()}finally{r(null)}},h=async()=>{r(`applying`),a(null);try{await Od.triggerUpdate(e.device_id)}catch(e){a(e instanceof Error?e.message:`Failed to trigger update`),r(null)}},g=n!=null||u,_=()=>{p?.public_key&&(navigator.clipboard.writeText(p.public_key),l(!0),setTimeout(()=>l(!1),2e3))},v=e.firmware_version||(d?.current_version&&d.current_version!==`0.0.0`?d.current_version:null);return(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-3 space-y-3`,children:[(0,G.jsxs)(`div`,{className:`flex justify-between items-center text-sm`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.currentVersion`,`Current Version`)}),(0,G.jsx)(`span`,{className:`text-zinc-200 font-mono`,children:v||(0,G.jsx)(`span`,{className:`text-zinc-500 italic text-xs`,children:t(`spoolbuddy.settings.versionPending`,`Waiting for daemon...`)})})]}),g?(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`svg`,{className:`w-4 h-4 animate-spin text-green-400 flex-shrink-0`,viewBox:`0 0 24 24`,fill:`none`,children:[(0,G.jsx)(`circle`,{className:`opacity-25`,cx:`12`,cy:`12`,r:`10`,stroke:`currentColor`,strokeWidth:`4`}),(0,G.jsx)(`path`,{className:`opacity-75`,fill:`currentColor`,d:`M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z`})]}),(0,G.jsx)(`span`,{className:`text-green-300 text-xs`,children:n===`checking`?t(`spoolbuddy.settings.checking`,`Checking for updates...`):e.update_message||t(`spoolbuddy.settings.updateWaiting`,`Updating...`)})]}):e.update_status===`error`?(0,G.jsx)(`p`,{className:`text-xs text-red-300`,children:e.update_message||t(`spoolbuddy.settings.updateFailed`,`Update failed`)}):i?(0,G.jsx)(`p`,{className:`text-xs text-red-300`,children:i}):d?.update_available?(0,G.jsxs)(`p`,{className:`text-xs text-green-300`,children:[t(`spoolbuddy.settings.updateAvailable`,`Update available`),`: `,v,` → `,d.latest_version]}):null,!g&&(d?.update_available?(0,G.jsx)(`button`,{onClick:h,disabled:!e.online,className:`w-full px-3 py-2 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 disabled:opacity-40 transition-colors`,children:e.online?t(`spoolbuddy.settings.applyUpdate`,`Apply Update`):t(`spoolbuddy.settings.deviceOffline`,`Device Offline`)}):(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsx)(`button`,{onClick:m,className:`flex-1 px-3 py-2 rounded-lg text-xs font-medium bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors`,children:t(`spoolbuddy.settings.checkUpdates`,`Check for Updates`)}),(0,G.jsx)(`button`,{onClick:h,disabled:!e.online,className:`px-3 py-2 rounded-lg text-xs font-medium bg-zinc-700 text-zinc-400 hover:bg-zinc-600 hover:text-zinc-200 disabled:opacity-40 transition-colors`,children:t(`spoolbuddy.settings.forceUpdate`,`Force Update`)})]}))]}),(0,G.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-3`,children:[(0,G.jsxs)(`button`,{onClick:()=>s(!o),className:`w-full flex justify-between items-center text-xs`,children:[(0,G.jsx)(`span`,{className:`font-medium text-zinc-400`,children:t(`spoolbuddy.settings.sshSetup`,`SSH Setup`)}),(0,G.jsx)(`svg`,{className:`w-3 h-3 text-zinc-500 transition-transform ${o?`rotate-180`:``}`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:2,children:(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M19 9l-7 7-7-7`})})]}),o&&(0,G.jsxs)(`div`,{className:`mt-2 space-y-2`,children:[(0,G.jsx)(`p`,{className:`text-xs text-zinc-500`,children:t(`spoolbuddy.settings.sshDescription`,`SSH key is deployed automatically. For manual setup, add this key to ~/.ssh/authorized_keys on the device.`)}),p?.public_key?(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(`pre`,{className:`bg-zinc-900 rounded p-2 text-[10px] text-zinc-400 font-mono break-all whitespace-pre-wrap`,children:p.public_key}),(0,G.jsx)(`button`,{onClick:_,className:`absolute top-1 right-1 px-1.5 py-0.5 rounded text-[10px] bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors`,children:c?t(`common.copied`,`Copied!`):t(`common.copy`,`Copy`)})]}):(0,G.jsx)(`span`,{className:`text-[10px] text-zinc-500 italic`,children:t(`spoolbuddy.settings.sshKeyLoading`,`Loading...`)})]})]})]})}function A2e({percent:e,color:t}){return(0,G.jsx)(`div`,{className:`w-full h-2 bg-zinc-700 rounded-full overflow-hidden`,children:(0,G.jsx)(`div`,{className:`h-full rounded-full transition-all ${t}`,style:{width:`${Math.min(100,Math.max(0,e))}%`}})})}function j2e(e){let t=Math.floor(e/86400),n=Math.floor(e%86400/3600),r=Math.floor(e%3600/60);return t>0?`${t}d ${n}h ${r}m`:n>0?`${n}h ${r}m`:`${r}m`}function M2e({device:e}){let{t}=U(),n=e.system_stats;if(!n)return(0,G.jsx)(`div`,{className:`flex items-center justify-center h-32`,children:(0,G.jsx)(`p`,{className:`text-sm text-zinc-500`,children:t(`spoolbuddy.settings.systemStatsWaiting`,`Waiting for system stats...`)})});let r=n.memory,i=n.disk,a=(n.cpu_temp_c??0)>=80?`text-red-400`:(n.cpu_temp_c??0)>=65?`text-amber-400`:`text-green-400`,o=(r?.percent??0)>=90?`bg-red-500`:(r?.percent??0)>=70?`bg-amber-500`:`bg-green-500`,s=(i?.percent??0)>=90?`bg-red-500`:(i?.percent??0)>=70?`bg-amber-500`:`bg-green-500`;return(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,G.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-3`,children:[(0,G.jsx)(`h3`,{className:`text-sm font-semibold text-zinc-300 mb-2`,children:`CPU`}),(0,G.jsxs)(`div`,{className:`space-y-1.5 text-xs`,children:[(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.cores`,`Cores`)}),(0,G.jsx)(`span`,{className:`text-zinc-300 font-mono`,children:n.cpu_count??`-`})]}),(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.loadAvg`,`Load Avg`)}),(0,G.jsx)(`span`,{className:`text-zinc-300 font-mono`,children:n.load_avg?n.load_avg.join(` / `):`-`})]}),(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.temp`,`Temp`)}),(0,G.jsx)(`span`,{className:`font-mono font-medium ${a}`,children:n.cpu_temp_c==null?`-`:`${n.cpu_temp_c}\u00B0C`})]})]})]}),(0,G.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-3`,children:[(0,G.jsx)(`h3`,{className:`text-sm font-semibold text-zinc-300 mb-2`,children:t(`spoolbuddy.settings.memory`,`Memory`)}),r?(0,G.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,G.jsx)(A2e,{percent:r.percent??0,color:o}),(0,G.jsxs)(`div`,{className:`space-y-1 text-xs`,children:[(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.used`,`Used`)}),(0,G.jsxs)(`span`,{className:`text-zinc-300 font-mono`,children:[r.used_mb,` / `,r.total_mb,` MB`]})]}),(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.available`,`Free`)}),(0,G.jsxs)(`span`,{className:`text-zinc-300 font-mono`,children:[r.available_mb,` MB`]})]})]})]}):(0,G.jsx)(`span`,{className:`text-xs text-zinc-500`,children:`-`})]})]}),(0,G.jsx)(`div`,{className:`bg-zinc-800 rounded-lg px-3 py-2`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`h3`,{className:`text-sm font-semibold text-zinc-300 shrink-0`,children:t(`spoolbuddy.settings.disk`,`Disk`)}),i?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`flex-1`,children:(0,G.jsx)(A2e,{percent:i.percent??0,color:s})}),(0,G.jsxs)(`span`,{className:`text-xs text-zinc-300 font-mono shrink-0`,children:[i.used_gb,` / `,i.total_gb,` GB`]})]}):(0,G.jsx)(`span`,{className:`text-xs text-zinc-500`,children:`-`})]})}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,G.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-3`,children:[(0,G.jsx)(`h3`,{className:`text-sm font-semibold text-zinc-300 mb-1.5`,children:t(`spoolbuddy.settings.osInfo`,`OS`)}),(0,G.jsxs)(`div`,{className:`space-y-1 text-xs`,children:[n.os?.os&&(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.distro`,`Distro`)}),(0,G.jsx)(`span`,{className:`text-zinc-300 truncate ml-2`,children:n.os.os})]}),n.os?.kernel&&(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.kernel`,`Kernel`)}),(0,G.jsx)(`span`,{className:`text-zinc-300 font-mono truncate ml-2`,children:n.os.kernel})]}),n.os?.arch&&(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.arch`,`Arch`)}),(0,G.jsx)(`span`,{className:`text-zinc-300 font-mono`,children:n.os.arch})]})]})]}),(0,G.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-3`,children:[(0,G.jsx)(`h3`,{className:`text-sm font-semibold text-zinc-300 mb-1.5`,children:t(`spoolbuddy.settings.runtime`,`Runtime`)}),(0,G.jsxs)(`div`,{className:`space-y-1 text-xs`,children:[n.os?.python&&(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:`Python`}),(0,G.jsx)(`span`,{className:`text-zinc-300 font-mono`,children:n.os.python})]}),n.system_uptime_s!=null&&(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.systemUptime`,`Uptime`)}),(0,G.jsx)(`span`,{className:`text-zinc-300`,children:j2e(n.system_uptime_s)})]})]})]})]})]})}function N2e(){let{sbState:e,setDisplayBrightness:t}=lr(),{t:n}=U(),[r,i]=(0,y.useState)(`device`),{data:a=[]}=K({queryKey:[`spoolbuddy-devices`],queryFn:()=>Od.getDevices(),refetchInterval:1e4}),o=e.deviceId?a.find(t=>t.device_id===e.deviceId)??a[0]:a[0],s=[{id:`device`,label:n(`spoolbuddy.settings.tabDevice`,`Device`)},{id:`display`,label:n(`spoolbuddy.settings.tabDisplay`,`Display`)},{id:`scale`,label:n(`spoolbuddy.settings.tabScale`,`Scale`)},{id:`updates`,label:n(`spoolbuddy.settings.tabUpdates`,`Updates`)},{id:`system`,label:n(`spoolbuddy.settings.tabSystem`,`System`)}];return(0,G.jsxs)(`div`,{className:`h-full flex flex-col p-4`,children:[(0,G.jsx)(`h1`,{className:`text-xl font-semibold text-zinc-100 mb-3`,children:n(`spoolbuddy.nav.settings`,`Settings`)}),(0,G.jsx)(`div`,{className:`flex gap-1 bg-zinc-800/50 rounded-lg p-1 mb-4`,children:s.map(e=>(0,G.jsx)(`button`,{onClick:()=>i(e.id),className:`flex-1 px-2 py-2 rounded-md text-sm font-medium transition-colors min-h-[36px] ${r===e.id?`bg-zinc-700 text-zinc-100`:`text-zinc-500 hover:text-zinc-300`}`,children:e.label},e.id))}),(0,G.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto`,children:o?(0,G.jsxs)(G.Fragment,{children:[r===`device`&&(0,G.jsx)(T2e,{device:o}),r===`display`&&(0,G.jsx)(E2e,{device:o,onBrightnessChange:t}),r===`scale`&&(0,G.jsx)(O2e,{device:o,weight:e.weight,weightStable:e.weightStable,rawAdc:e.rawAdc}),r===`updates`&&(0,G.jsx)(k2e,{device:o}),r===`system`&&(0,G.jsx)(M2e,{device:o})]}):(0,G.jsx)(`div`,{className:`flex items-center justify-center h-32`,children:(0,G.jsx)(`div`,{className:`text-center text-zinc-500`,children:(0,G.jsx)(`p`,{className:`text-sm`,children:n(`spoolbuddy.settings.noDevice`,`No SpoolBuddy device found`)})})})})]})}function P2e({device:e,weight:t,weightStable:n,rawAdc:r}){let{t:i}=U(),[a,o]=(0,y.useState)(!1),[s,c]=(0,y.useState)(`idle`),[l,u]=(0,y.useState)(`500`),[d,f]=(0,y.useState)(null),[p,m]=(0,y.useState)(!1),h=e=>{e===`backspace`?u(e=>e.slice(0,-1)||``):e===`.`&&!l.includes(`.`)?u(e=>e+`.`):e>=`0`&&e<=`9`&&u(t=>t===`0`?e:t+e)};return(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`span`,{className:`text-sm text-zinc-400`,children:i(`spoolbuddy.settings.currentWeight`,`Current weight`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`div`,{className:`w-2 h-2 rounded-full ${n?`bg-green-500`:`bg-amber-500 animate-pulse`}`}),(0,G.jsx)(`span`,{className:`text-lg font-mono text-zinc-200`,children:t===null?`-- g`:`${t.toFixed(1)} g`})]})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-4 mt-3 text-xs`,children:[(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:i(`spoolbuddy.settings.tareOffset`,`Tare offset`)}),(0,G.jsx)(`span`,{className:`text-zinc-400 font-mono`,children:e.tare_offset})]}),(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:i(`spoolbuddy.settings.calFactor`,`Cal. factor`)}),(0,G.jsx)(`span`,{className:`text-zinc-400 font-mono`,children:e.calibration_factor.toFixed(2)})]})]})]}),s===`idle`?(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsx)(`button`,{onClick:async()=>{m(!0);try{await Od.tare(e.device_id)}catch(e){console.error(`Failed to tare:`,e)}finally{m(!1)}},disabled:p,className:`flex-1 px-4 py-2.5 rounded-lg text-sm font-medium bg-zinc-700 text-zinc-200 hover:bg-zinc-600 disabled:opacity-40 transition-colors min-h-[44px]`,children:p?`...`:i(`spoolbuddy.weight.tare`,`Tare`)}),(0,G.jsx)(`button`,{onClick:()=>{c(`tare`)},className:`flex-1 px-4 py-2.5 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 transition-colors min-h-[44px]`,children:i(`spoolbuddy.weight.calibrate`,`Calibrate`)})]}):(0,G.jsxs)(`div`,{className:`bg-zinc-800 border border-zinc-700 rounded-lg p-3 space-y-2`,children:[(0,G.jsx)(`div`,{className:`text-sm font-medium text-zinc-200`,children:s===`tare`?i(`spoolbuddy.settings.calStep1`,`Step 1: Remove all items from the scale`):i(`spoolbuddy.settings.calStep2`,`Step 2: Place known weight on scale`)}),s===`weight`&&(0,G.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-xs text-zinc-400`,children:i(`spoolbuddy.settings.knownWeight`,`Known weight (g)`)}),(0,G.jsxs)(`div`,{className:`flex-1 bg-zinc-900 border border-zinc-600 rounded px-3 py-1.5 text-right text-base font-mono text-zinc-100`,children:[l||`0`,(0,G.jsx)(`span`,{className:`text-zinc-500 ml-1`,children:`g`})]})]}),(0,G.jsx)(`div`,{className:`grid grid-cols-4 gap-1`,children:[`7`,`8`,`9`,`backspace`,`4`,`5`,`6`,`.`,`1`,`2`,`3`,`0`].map(e=>(0,G.jsx)(`button`,{onClick:()=>h(e),className:`py-2 rounded text-sm font-medium transition-colors min-h-[36px] ${e===`backspace`?`bg-zinc-700 text-zinc-300 hover:bg-zinc-600`:`bg-zinc-800 text-zinc-100 hover:bg-zinc-700 border border-zinc-700`}`,children:e===`backspace`?`⌫`:e},e))})]}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsx)(`button`,{onClick:()=>c(`idle`),className:`flex-1 px-4 py-2 rounded-lg text-sm bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors min-h-[40px]`,children:i(`common.cancel`,`Cancel`)}),(0,G.jsx)(`button`,{onClick:async()=>{if(s===`tare`){o(!0);try{f(r),await Od.tare(e.device_id),c(`weight`)}catch(e){console.error(`Failed to tare:`,e)}finally{o(!1)}}else if(s===`weight`){let t=parseFloat(l);if(r===null||!t||t<=0)return;o(!0);try{await Od.setCalibrationFactor(e.device_id,t,r,d??void 0),c(`idle`)}catch(e){console.error(`Failed to calibrate:`,e)}finally{o(!1)}}},disabled:a,className:`flex-1 px-4 py-2 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 disabled:opacity-40 transition-colors min-h-[40px]`,children:a?`...`:s===`tare`?i(`spoolbuddy.settings.setZero`,`Set Zero`):i(`spoolbuddy.settings.calibrateNow`,`Calibrate`)})]})]})]})}function F2e(){let{sbState:e}=lr(),{t}=U(),n=or(),{data:r=[]}=K({queryKey:[`spoolbuddy-devices`],queryFn:()=>Od.getDevices(),refetchInterval:1e4}),i=e.deviceId?r.find(t=>t.device_id===e.deviceId)??r[0]:r[0];return(0,G.jsxs)(`div`,{className:`h-full flex flex-col p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3 mb-4`,children:[(0,G.jsx)(`button`,{onClick:()=>n(`/spoolbuddy/settings`),className:`p-1.5 rounded-lg text-zinc-400 hover:text-zinc-200 hover:bg-zinc-800 transition-colors`,children:(0,G.jsx)(`svg`,{className:`w-5 h-5`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:2,children:(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M15 19l-7-7 7-7`})})}),(0,G.jsx)(`h1`,{className:`text-xl font-semibold text-zinc-100`,children:t(`spoolbuddy.settings.scaleCalibration`,`Scale Calibration`)})]}),(0,G.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto`,children:i?(0,G.jsx)(P2e,{device:i,weight:e.weight,weightStable:e.weightStable,rawAdc:e.rawAdc}):(0,G.jsx)(`div`,{className:`flex items-center justify-center h-32`,children:(0,G.jsx)(`div`,{className:`text-center text-zinc-500`,children:(0,G.jsx)(`p`,{className:`text-sm`,children:t(`spoolbuddy.settings.noDevice`,`No SpoolBuddy device found`)})})})})]})}function I2e({formData:e,printersWithCalibrations:t,selectedProfiles:n,setSelectedProfiles:r,expandedPrinters:i,setExpandedPrinters:a}){let{t:o}=U(),s=e=>{a(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},c=(e,t,n)=>{let i=`${e}:${t}:${n??`null`}`,a=`${e}:${n??`null`}`;r(e=>{let t=new Set(e);if(t.has(i))t.delete(i);else{for(let e of Array.from(t)){let n=e.split(`:`);`${n[0]}:${n[2]}`===a&&t.delete(e)}t.add(i)}return t})},l=()=>{let n=new Set;for(let{printer:r,calibrations:i}of t){if(!r.connected)continue;let t=i.filter(t=>nU(t,e)),a=new Map;for(let e of t){let t=`${e.extruder_id??`null`}`;a.has(t)||a.set(t,[]),a.get(t).push(e)}for(let[e,t]of a)if(t.length>0){let i=[...t].sort((e,t)=>t.k_value-e.k_value)[0];n.add(`${r.id}:${i.cali_idx}:${e}`)}}r(n)};if(!e.material)return(0,G.jsx)(`div`,{className:`p-6 bg-bambu-dark rounded-lg text-center`,children:(0,G.jsx)(`p`,{className:`text-bambu-gray`,children:o(`inventory.selectMaterialFirst`)})});if(t.length===0)return(0,G.jsx)(`div`,{className:`p-6 bg-bambu-dark rounded-lg text-center`,children:(0,G.jsx)(`p`,{className:`text-bambu-gray`,children:o(`inventory.noPrintersConfigured`)})});let u=t.reduce((t,{printer:n,calibrations:r})=>n.connected?t+r.filter(t=>nU(t,e)).length:t,0),d=(e,t)=>{let r=`${e.id}:${t.cali_idx}:${t.extruder_id??`null`}`,i=n.has(r);return(0,G.jsxs)(`label`,{className:`flex items-center gap-3 p-3 rounded-lg cursor-pointer transition-all border ${i?`bg-bambu-green/10 border-bambu-green/30`:`bg-bambu-dark border-transparent hover:bg-bambu-dark/80`}`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:i,onChange:()=>c(String(e.id),t.cali_idx,t.extruder_id),className:`w-4 h-4 rounded border-bambu-dark-tertiary text-bambu-green focus:ring-bambu-green`}),(0,G.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,G.jsx)(`span`,{className:`text-sm font-medium ${i?`text-bambu-green`:`text-white`}`,children:t.name||t.filament_id})}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[t.nozzle_diameter&&(0,G.jsxs)(`span`,{className:`text-xs font-mono px-2 py-0.5 rounded bg-bambu-dark text-bambu-gray`,children:[t.nozzle_diameter,`mm`]}),(0,G.jsxs)(`span`,{className:`text-xs font-mono px-2 py-0.5 rounded bg-bambu-dark text-bambu-gray`,children:[`K=`,t.k_value.toFixed(3)]})]})]},`${t.cali_idx}-${t.extruder_id}`)};return(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`p`,{className:`text-xs text-bambu-gray`,children:[o(`inventory.matchingFilter`),`: `,e.brand||o(`inventory.anyBrand`),` / `,e.material,` / `,e.subtype||o(`inventory.anyVariant`)]}),u>0&&(0,G.jsxs)(`button`,{type:`button`,onClick:l,className:`flex items-center gap-1.5 px-2 py-1 text-xs bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray hover:text-white hover:border-bambu-green transition-colors`,children:[(0,G.jsx)(_u,{className:`w-3.5 h-3.5`}),o(`inventory.autoSelect`),` (`,u,`)`]})]}),(0,G.jsx)(`div`,{className:`space-y-3`,children:t.map(({printer:t,calibrations:n})=>{let r=i.has(String(t.id)),a=n.filter(t=>nU(t,e)),c=a.length,l=a.some(e=>e.extruder_id!==void 0&&e.extruder_id!==null&&e.extruder_id>0),u=a.filter(e=>e.extruder_id===1),f=a.filter(e=>e.extruder_id===0||e.extruder_id===void 0||e.extruder_id===null);return(0,G.jsxs)(`div`,{className:`border border-bambu-dark-tertiary rounded-lg overflow-hidden`,children:[(0,G.jsxs)(`button`,{type:`button`,onClick:()=>s(String(t.id)),className:`w-full px-4 py-3 flex items-center justify-between bg-bambu-dark-secondary hover:bg-bambu-dark-tertiary transition-colors`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[r?(0,G.jsx)(ps,{className:`w-4 h-4 text-bambu-gray`}):(0,G.jsx)(ms,{className:`w-4 h-4 text-bambu-gray`}),(0,G.jsx)(`span`,{className:`font-medium text-white`,children:t.name}),c>0?(0,G.jsxs)(`span`,{className:`text-xs px-2 py-0.5 rounded-full bg-bambu-green/20 text-bambu-green`,children:[c,` `,o(c===1?`inventory.match`:`inventory.matches`)]}):(0,G.jsx)(`span`,{className:`text-xs px-2 py-0.5 rounded-full bg-bambu-dark-tertiary text-bambu-gray`,children:o(`inventory.noMatches`)})]}),(0,G.jsx)(`span`,{className:`text-xs px-2 py-1 rounded-full ${t.connected?`bg-green-500/20 text-green-500`:`bg-bambu-gray/20 text-bambu-gray`}`,children:t.connected?o(`inventory.connected`):o(`inventory.offline`)})]}),r&&(0,G.jsx)(`div`,{className:`px-4 py-3 space-y-3 bg-bambu-dark border-t border-bambu-dark-tertiary`,children:t.connected?c===0?(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray italic py-2`,children:o(`inventory.noKProfilesMatch`)}):l?(0,G.jsxs)(G.Fragment,{children:[u.length>0&&(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`p`,{className:`text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:o(`inventory.leftNozzle`)}),(0,G.jsx)(`div`,{className:`space-y-2`,children:u.map(e=>d(t,e))})]}),f.length>0&&(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`p`,{className:`text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:o(`inventory.rightNozzle`)}),(0,G.jsx)(`div`,{className:`space-y-2`,children:f.map(e=>d(t,e))})]})]}):(0,G.jsx)(`div`,{className:`space-y-2`,children:a.map(e=>d(t,e))}):(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray italic py-2`,children:o(`inventory.printerOffline`)})})]},t.id)})}),n.size>0&&(0,G.jsx)(`div`,{className:`p-3 bg-bambu-green/10 border border-bambu-green/30 rounded-lg`,children:(0,G.jsxs)(`p`,{className:`text-sm text-white`,children:[(0,G.jsx)(`span`,{className:`font-semibold`,children:n.size}),` `,o(`inventory.profilesSelected`)]})})]})}var L2e=[`PLA`,`PETG`,`ABS`,`ASA`,`TPU`,`PA`,`PC`,`PVA`,`HIPS`];function R2e(){let{t:e}=U(),{showToast:t}=qd(),{sbState:n}=lr(),[r,i]=(0,y.useState)(`existing`),[a,o]=(0,y.useState)(null),[s,c]=(0,y.useState)(``),[l,u]=(0,y.useState)(`idle`),[d,f]=(0,y.useState)(``),[p,m]=(0,y.useState)(!1),[h,g]=(0,y.useState)(!1),[_,v]=(0,y.useState)(null),{data:b}=K({queryKey:[`spoolman-settings`],queryFn:Z.getSpoolmanSettings,staleTime:300*1e3}),x=b!==void 0,S=b?.spoolman_enabled===`true`&&!!b?.spoolman_url,{data:C=[],refetch:w}=K({queryKey:[S?`spoolman-inventory-spools`:`inventory-spools`,`write-tag`],queryFn:()=>S?Z.getSpoolmanInventorySpools(!1):Z.getSpools(!1),refetchInterval:1e4,enabled:x}),{data:T=[]}=K({queryKey:[`spoolbuddy-devices`],queryFn:()=>Od.getDevices(),refetchInterval:5e3}),{data:E}=K({queryKey:[`settings`],queryFn:Z.getSettings}),D=T[0],O=n.deviceOnline,k=Lf(E?.currency||`USD`),A=(0,y.useMemo)(()=>{let e;if(r===`existing`)e=C.filter(e=>!e.tag_uid&&!e.archived_at);else if(r===`replace`)e=C.filter(e=>(e.tag_uid||e.tray_uuid)&&!e.archived_at);else return[];if(s){let t=s.toLowerCase();e=e.filter(e=>e.material?.toLowerCase().includes(t)||e.color_name?.toLowerCase().includes(t)||e.brand?.toLowerCase().includes(t)||e.subtype?.toLowerCase().includes(t))}return e},[C,r,s]),j=(0,y.useCallback)(e=>{let t=e.detail;(t.sak??t.data?.sak)===0&&(g(!0),v(t.tag_uid??t.data?.tag_uid??null))},[]),M=(0,y.useCallback)(e=>{let t=e.detail;g(!0),v(t.tag_uid??t.data?.tag_uid??null)},[]),N=(0,y.useCallback)(()=>{g(!1),v(null)},[]),P=(0,y.useCallback)(t=>{let n=t.detail;(n.spool_id===a?.id||n.data?.spool_id===a?.id)&&(u(`success`),f(e(`spoolbuddy.writeTag.writeSuccess`,`Tag written successfully!`)),w(),setTimeout(()=>{u(`idle`),o(null),f(``)},5e3))},[a,e,w]),F=(0,y.useCallback)(t=>{let n=t.detail;(n.spool_id===a?.id||n.data?.spool_id===a?.id)&&(u(`error`),f(n.message??n.data?.message??e(`spoolbuddy.writeTag.writeFailed`,`Write failed`)))},[a,e]);(0,y.useEffect)(()=>(window.addEventListener(`spoolbuddy-unknown-tag`,j),window.addEventListener(`spoolbuddy-tag-matched`,M),window.addEventListener(`spoolbuddy-tag-removed`,N),window.addEventListener(`spoolbuddy-tag-written`,P),window.addEventListener(`spoolbuddy-tag-write-failed`,F),()=>{window.removeEventListener(`spoolbuddy-unknown-tag`,j),window.removeEventListener(`spoolbuddy-tag-matched`,M),window.removeEventListener(`spoolbuddy-tag-removed`,N),window.removeEventListener(`spoolbuddy-tag-written`,P),window.removeEventListener(`spoolbuddy-tag-write-failed`,F)}),[j,M,N,P,F]),(0,y.useEffect)(()=>{o(null),u(`idle`),f(``),c(``)},[r]);let I=async()=>{if(!(!a||!D)){u(`writing`),f(e(`spoolbuddy.writeTag.waiting`,`Waiting for SpoolBuddy...`));try{let e=await Od.writeTag(D.device_id,a.id);if(e?.warnings?.length)for(let n of e.warnings)t(n,`warning`)}catch{u(`error`),f(e(`spoolbuddy.writeTag.queueFailed`,`Failed to queue write command`))}}},L=async()=>{if(D){try{await Od.cancelWrite(D.device_id)}catch{}u(`idle`),f(``)}},R=async()=>{if(!(!a||!z2e(a))){m(!0),u(`idle`),f(``);try{S?await Z.linkTagToSpoolmanSpool(a.id,{tag_uid:``,tray_uuid:``}):await Z.linkTagToSpool(a.id,{tag_uid:``,tray_uuid:``,data_origin:`manual`}),await w(),o(null),u(`success`),f(e(`spoolbuddy.writeTag.untagSuccess`,`Tag removed from spool`)),setTimeout(()=>{u(`idle`),f(``)},2500)}catch{u(`error`),f(e(`spoolbuddy.writeTag.untagFailed`,`Failed to remove tag from spool`))}finally{m(!1)}}},z=(0,y.useCallback)(e=>{o(e),u(`idle`),f(``),w()},[w]),B=a&&O&&l!==`writing`&&l!==`success`;return(0,G.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,G.jsx)(`div`,{className:`flex border-b border-bambu-dark-tertiary shrink-0`,children:[{key:`existing`,label:e(`spoolbuddy.writeTag.tabExisting`,`Existing Spool`)},{key:`new`,label:e(`spoolbuddy.writeTag.tabNew`,`New Spool`)},{key:`replace`,label:e(`spoolbuddy.writeTag.tabReplace`,`Replace Tag`)}].map(e=>(0,G.jsx)(`button`,{onClick:()=>i(e.key),className:`flex-1 py-3 text-sm font-medium transition-colors ${r===e.key?`text-bambu-green border-b-2 border-bambu-green bg-bambu-dark`:`text-zinc-400 hover:text-zinc-200 hover:bg-bambu-dark-tertiary`}`,children:e.label},e.key))}),(0,G.jsxs)(`div`,{className:`flex flex-1 overflow-hidden`,children:[(0,G.jsx)(`div`,{className:`flex-1 flex flex-col overflow-hidden border-r border-bambu-dark-tertiary`,children:r===`new`?(0,G.jsx)(V2e,{currencySymbol:k,onCreated:z,selectedSpool:a,spoolmanMode:S,t:e}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`p-3 shrink-0`,children:(0,G.jsx)(`input`,{type:`text`,value:s,onChange:e=>c(e.target.value),placeholder:e(`spoolbuddy.writeTag.searchPlaceholder`,`Search by material, color, brand...`),className:`w-full px-3 py-2 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-sm text-white placeholder-zinc-500 focus:outline-none focus:border-bambu-green`})}),(0,G.jsx)(`div`,{className:`flex-1 overflow-y-auto px-3 pb-3 space-y-2`,children:A.length===0?(0,G.jsx)(`div`,{className:`text-center text-zinc-500 py-8 text-sm`,children:r===`existing`?e(`spoolbuddy.writeTag.noUntaggedSpools`,`No spools without tags`):e(`spoolbuddy.writeTag.noTaggedSpools`,`No spools with tags`)}):A.map(e=>(0,G.jsx)(B2e,{spool:e,selected:a?.id===e.id,showTag:r===`replace`,onClick:()=>{o(e),u(`idle`),f(``)}},e.id))})]})}),(0,G.jsx)(`div`,{className:`w-[340px] flex flex-col items-center justify-center p-6 shrink-0`,children:(0,G.jsx)(H2e,{writeStatus:l,writeMessage:d,selectedSpool:a,tagOnReader:h,tagUid:_,deviceOnline:O,canWrite:!!B,isReplace:r===`replace`,canUntag:r===`replace`&&!!a&&z2e(a),untagging:p,onWrite:I,onUntag:R,onCancel:L,onRetry:()=>{u(`idle`),f(``)},t:e})})]})]})}function z2e(e){return!!(e.tag_uid||e.tray_uuid)}function B2e({spool:e,selected:t,showTag:n,onClick:r}){let i=Math.max(0,e.label_weight-e.weight_used),a=e.label_weight>0?Math.round(i/e.label_weight*100):0;return(0,G.jsxs)(`button`,{onClick:r,className:`w-full flex items-center gap-3 p-3 rounded-lg text-left transition-colors ${t?`bg-bambu-green/15 border border-bambu-green/50`:`bg-bambu-dark-secondary hover:bg-bambu-dark-tertiary border border-transparent`}`,children:[(0,G.jsx)(`div`,{className:`w-8 h-8 rounded-full shrink-0 border border-white/10`,style:e.rgba?Mf(e.rgba):{backgroundColor:`#666`}}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`span`,{className:`text-sm font-medium text-white truncate`,children:[e.brand?`${e.brand} `:``,e.material,e.subtype?` ${e.subtype}`:``]}),(0,G.jsxs)(`span`,{className:`text-[10px] font-mono text-zinc-500 shrink-0`,children:[`#`,e.id]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-zinc-400`,children:[e.color_name&&(0,G.jsx)(`span`,{children:e.color_name}),(0,G.jsxs)(`span`,{children:[i,`g / `,e.label_weight,`g (`,a,`%)`]})]}),n&&e.tag_uid&&(0,G.jsx)(`div`,{className:`text-xs text-zinc-500 mt-0.5 font-mono`,children:e.tag_uid})]}),t&&(0,G.jsx)(`svg`,{className:`w-5 h-5 text-bambu-green shrink-0`,fill:`currentColor`,viewBox:`0 0 20 20`,children:(0,G.jsx)(`path`,{fillRule:`evenodd`,d:`M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z`,clipRule:`evenodd`})})]})}function V2e({currencySymbol:e,onCreated:t,selectedSpool:n,spoolmanMode:r,t:i}){let{data:a=[]}=K({queryKey:[r?`spoolman-inventory-spools`:`inventory-spools`,`write-tag-form`],queryFn:()=>r?Z.getSpoolmanInventorySpools(!0):Z.getSpools(!0)}),{data:o}=K({queryKey:[`settings`],queryFn:Z.getSettings}),[s,c]=(0,y.useState)(`simple`),[l,u]=(0,y.useState)(`filament`),[d,f]=(0,y.useState)(f9),[p,m]=(0,y.useState)({}),[h,g]=(0,y.useState)(!1),[_,v]=(0,y.useState)(1),[b,x]=(0,y.useState)(!1),[S,C]=(0,y.useState)(null),[w,T]=(0,y.useState)(!1),[E,D]=(0,y.useState)(!1),[O,k]=(0,y.useState)([]),[A,j]=(0,y.useState)([]),[M,N]=(0,y.useState)([]),[P,F]=(0,y.useState)([]),[I,L]=(0,y.useState)([]),[R,z]=(0,y.useState)(``),[B,V]=(0,y.useState)([]),[ee,te]=(0,y.useState)([]),[ne,re]=(0,y.useState)(new Set),[ie,ae]=(0,y.useState)(new Set);(0,y.useEffect)(()=>{V(XH())},[]),(0,y.useEffect)(()=>{let e=!1;return(async()=>{if(s===`full`){D(!0);try{let[t,n]=await Promise.allSettled([(async()=>(await Z.getCloudStatus()).is_authenticated?{connected:!0,presets:await Z.getFilamentPresets()}:{connected:!1,presets:[]})(),(async()=>(await Z.orcaCloudStatus()).connected?{connected:!0,presets:(await Z.orcaCloudListProfiles()).filament}:{connected:!1,presets:[]})()]);if(e)return;let r=t.status===`fulfilled`&&t.value.connected,i=n.status===`fulfilled`&&n.value.connected,a=t.status===`fulfilled`?t.value.presets:[],o=n.status===`fulfilled`?n.value.presets:[];T(r||i),k([...a,...o])}catch{e||T(!1)}finally{e||D(!1)}Z.getSpoolCatalog().then(t=>{e||F(t)}).catch(()=>void 0),Z.getColorCatalog().then(t=>{e||L(t)}).catch(()=>void 0),Z.getLocalPresets().then(t=>{e||j(t.filament)}).catch(()=>void 0),Z.getBuiltinFilaments().then(t=>{e||N(t)}).catch(()=>void 0);try{let t=await Z.getPrinters(),n=await Promise.all(t.map(e=>Z.getPrinterStatus(e.id).catch(()=>null))),r=[];for(let e=0;e{e=!0}},[s]),(0,y.useEffect)(()=>{ee.length>0&&ae(new Set(ee.map(e=>String(e.printer.id))))},[ee]);let oe=(0,y.useMemo)(()=>KH(O,new Set,A,M),[O,A,M]),se=(0,y.useMemo)(()=>qH(d.slicer_filament,oe),[d.slicer_filament,oe]),H=(0,y.useMemo)(()=>{let e=GH(O,A),t=I.map(e=>e.manufacturer?.trim()).filter(e=>!!e);return Array.from(new Set([...e,...t])).sort((e,t)=>e.localeCompare(t))},[O,A,I]),ce=(0,y.useMemo)(()=>{let e=I.map(e=>e.material?.trim()).filter(e=>!!e);return Array.from(new Set([...IH,...e])).sort((e,t)=>e.localeCompare(t))},[I]),le=(0,y.useMemo)(()=>{let e=[];for(let t of I){let n=t.manufacturer?.trim(),r=t.material?.trim();n&&r&&e.push({brand:n,material:r})}for(let t of O){let n=WH(t.name);n.brand&&n.material&&e.push({brand:n.brand,material:n.material})}for(let t of A){let n=WH(t.name),r=t.filament_vendor?.trim()||n.brand,i=n.material;r&&i&&e.push({brand:r,material:i})}return e},[O,I,A]),ue=(0,y.useMemo)(()=>{let e=new Map;for(let t of le){let n=t.brand.toLowerCase(),r=t.material.toLowerCase();e.has(n)||e.set(n,new Set),e.get(n).add(r)}return e},[le]),de=(0,y.useMemo)(()=>{let e=new Map;for(let t of le){let n=t.brand.toLowerCase(),r=t.material.toLowerCase();e.has(r)||e.set(r,new Set),e.get(r).add(n)}return e},[le]),fe=(0,y.useMemo)(()=>JH(H,d.brand),[H,d.brand]),pe=(0,y.useMemo)(()=>JH(ce,d.material),[ce,d.material]),me=(0,y.useMemo)(()=>YH(fe,d.material,de),[fe,d.material,de]),he=(0,y.useMemo)(()=>YH(pe,d.brand,ue),[pe,d.brand,ue]),ge=(e,t)=>{f(n=>({...n,[e]:t})),p[e]&&m(t=>({...t,[e]:void 0}))},_e=e=>{V(t=>ZH(e,t))},ve=async e=>{let t=r?Z.saveSpoolmanKProfiles:Z.saveSpoolKProfiles;if(ne.size===0){try{await t(e,[])}catch{}return}let n=[];for(let e of ne){let[t,r,i]=e.split(`:`),a=parseInt(t),o=parseInt(r),s=i===`null`?0:parseInt(i),c=ee.find(e=>e.printer.id===a);if(c){let e=c.calibrations.find(e=>e.cali_idx===o&&(e.extruder_id??0)===s);e&&n.push({printer_id:a,extruder:s,nozzle_diameter:e.nozzle_diameter||`0.4`,k_value:e.k_value,name:e.name||null,cali_idx:e.cali_idx,setting_id:e.setting_id||null})}}n.length>0&&await t(e,n)},ye=async()=>{C(null);let e=s1e(d,s===`simple`?!0:h);if(!e.isValid){m(e.errors),u(`filament`);return}let n=se?.displayName||R||null,a={material:d.material,subtype:d.subtype||null,brand:d.brand||null,color_name:d.color_name||null,rgba:d.rgba||null,extra_colors:d.extra_colors||null,effect_type:d.effect_type||null,label_weight:d.label_weight,core_weight:d.core_weight,core_weight_catalog_id:d.core_weight_catalog_id,weight_used:d.weight_used,slicer_filament:d.slicer_filament||null,slicer_filament_name:n,nozzle_temp_min:null,nozzle_temp_max:null,note:d.note||null,cost_per_kg:d.cost_per_kg,added_full:null,last_used:null,encode_time:null,tag_uid:null,tray_uuid:null,data_origin:null,tag_type:null,last_scale_weight:null,last_weighed_at:null,category:d.category.trim()||null,low_stock_threshold_pct:d.low_stock_threshold_pct};x(!0);try{if(_>1){let e=r?await Z.bulkCreateSpoolmanInventorySpools(a,_):await Z.bulkCreateSpools(a,_),n=r&&e&&typeof e==`object`&&`created`in e?e.created:e;for(let e of n)await ve(e.id);n.length>0&&t(n[0])}else{let e=r?await Z.createSpoolmanInventorySpool(a):await Z.createSpool(a);await ve(e.id),t(e)}}catch{C(i(`spoolbuddy.writeTag.createFailed`,`Failed to create spool`))}finally{x(!1)}},be=`#${(d.rgba||`808080FF`).slice(0,6)}`;return(0,G.jsxs)(`div`,{className:`p-3 space-y-3 overflow-y-auto h-full`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-2 py-2 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary`,children:[(0,G.jsx)(`span`,{className:`text-sm text-zinc-200`,children:i(`spoolbuddy.writeTag.viewMode`,`View`)}),(0,G.jsxs)(`div`,{className:`flex rounded-lg overflow-hidden border border-bambu-dark-tertiary`,children:[(0,G.jsx)(`button`,{type:`button`,onClick:()=>c(`simple`),className:`px-3 py-1.5 text-xs font-medium ${s===`simple`?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark text-zinc-400`}`,children:i(`spoolbuddy.writeTag.simpleView`,`Simple`)}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>c(`full`),className:`px-3 py-1.5 text-xs font-medium ${s===`full`?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark text-zinc-400`}`,children:i(`spoolbuddy.writeTag.fullView`,`Full`)})]})]}),s===`simple`?n?(0,G.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full p-6 text-center bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg`,children:[(0,G.jsx)(`div`,{className:`w-12 h-12 rounded-full mb-4 border border-white/10`,style:n.rgba?Mf(n.rgba):{backgroundColor:`#666`}}),(0,G.jsxs)(`p`,{className:`text-white font-medium`,children:[n.brand?`${n.brand} `:``,n.material]}),n.color_name&&(0,G.jsx)(`p`,{className:`text-zinc-400 text-sm`,children:n.color_name}),(0,G.jsxs)(`p`,{className:`text-zinc-500 text-xs mt-1`,children:[n.label_weight,`g`]}),(0,G.jsx)(`p`,{className:`text-bambu-green text-sm mt-4`,children:i(`spoolbuddy.writeTag.spoolCreated`,`Spool created! Ready to write.`)})]}):(0,G.jsxs)(`div`,{className:`p-4 space-y-4 overflow-y-auto bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs text-zinc-400 mb-1`,children:i(`spoolbuddy.writeTag.material`,`Material`)}),(0,G.jsx)(`select`,{value:d.material,onChange:e=>ge(`material`,e.target.value),className:`w-full px-3 py-2 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-sm text-white focus:outline-none focus:border-bambu-green`,children:L2e.map(e=>(0,G.jsx)(`option`,{value:e,children:e},e))})]}),(0,G.jsxs)(`div`,{className:`flex gap-3`,children:[(0,G.jsxs)(`div`,{className:`flex-1`,children:[(0,G.jsx)(`label`,{className:`block text-xs text-zinc-400 mb-1`,children:i(`spoolbuddy.writeTag.colorName`,`Color Name`)}),(0,G.jsx)(`input`,{type:`text`,value:d.color_name,onChange:e=>ge(`color_name`,e.target.value),placeholder:`Jade White`,className:`w-full px-3 py-2 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-sm text-white placeholder-zinc-500 focus:outline-none focus:border-bambu-green`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs text-zinc-400 mb-1`,children:i(`spoolbuddy.writeTag.color`,`Color`)}),(0,G.jsx)(`input`,{type:`color`,value:be,onChange:e=>ge(`rgba`,e.target.value.replace(`#`,``).toUpperCase()+`FF`),className:`w-10 h-9 bg-transparent border border-bambu-dark-tertiary rounded cursor-pointer`})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs text-zinc-400 mb-1`,children:i(`spoolbuddy.writeTag.brand`,`Brand`)}),(0,G.jsx)(`input`,{type:`text`,value:d.brand,onChange:e=>ge(`brand`,e.target.value),placeholder:`Polymaker`,className:`w-full px-3 py-2 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-sm text-white placeholder-zinc-500 focus:outline-none focus:border-bambu-green`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs text-zinc-400 mb-1`,children:i(`spoolbuddy.writeTag.weight`,`Weight (g)`)}),(0,G.jsx)(`input`,{type:`number`,value:d.label_weight,onChange:e=>ge(`label_weight`,parseInt(e.target.value)||0),min:0,max:1e4,className:`w-full px-3 py-2 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-sm text-white focus:outline-none focus:border-bambu-green`})]}),(0,G.jsx)(`button`,{onClick:ye,disabled:b||!d.material,className:`w-full py-2.5 bg-bambu-green hover:bg-bambu-green/80 disabled:opacity-50 disabled:cursor-not-allowed text-white text-sm font-medium rounded transition-colors`,children:b?i(`spoolbuddy.writeTag.creating`,`Creating...`):i(`spoolbuddy.writeTag.createSpool`,`Create Spool`)})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-2 py-2 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary`,children:[(0,G.jsx)(`span`,{className:`text-sm text-zinc-200`,children:i(`inventory.quickAdd`,`Quick Add`)}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>g(e=>!e),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors ${h?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,children:(0,G.jsx)(`span`,{className:`inline-block h-4.5 w-4.5 rounded-full bg-white transition-transform ${h?`translate-x-6`:`translate-x-1`}`})})]}),(0,G.jsxs)(`div`,{className:`flex border border-bambu-dark-tertiary rounded-lg overflow-hidden`,children:[(0,G.jsx)(`button`,{onClick:()=>u(`filament`),className:`flex-1 py-2.5 text-sm font-medium ${l===`filament`?`bg-bambu-green/15 text-bambu-green`:`bg-bambu-dark-secondary text-zinc-400`}`,children:i(`inventory.filamentInfoTab`,`Filament`)}),!h&&(0,G.jsx)(`button`,{onClick:()=>u(`pa-profile`),className:`flex-1 py-2.5 text-sm font-medium ${l===`pa-profile`?`bg-bambu-green/15 text-bambu-green`:`bg-bambu-dark-secondary text-zinc-400`}`,children:i(`inventory.paProfileTab`,`PA Profile`)})]}),(0,G.jsx)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg p-3`,children:l===`filament`?(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsx)(d1e,{formData:d,updateField:ge,cloudAuthenticated:w,loadingCloudPresets:E,presetInputValue:R,setPresetInputValue:z,selectedPresetOption:se,filamentOptions:oe,availableBrands:fe,availableMaterials:pe,suggestedBrands:me,suggestedMaterials:he,quickAdd:h,detailsRequired:!h,quantity:_,onQuantityChange:v,errors:p}),(0,G.jsx)(p1e,{formData:d,updateField:ge,recentColors:B,onColorUsed:_e,catalogColors:I}),(0,G.jsx)(h1e,{formData:d,updateField:ge,spoolCatalog:P,currencySymbol:e,availableCategories:Array.from(new Set(a.map(e=>e.category?.trim()).filter(e=>!!e))).sort((e,t)=>e.localeCompare(t)),globalLowStockThreshold:o?.low_stock_threshold??20})]}):(0,G.jsx)(I2e,{formData:d,updateField:ge,printersWithCalibrations:ee,selectedProfiles:ne,setSelectedProfiles:re,expandedPrinters:ie,setExpandedPrinters:ae})})]}),S&&(0,G.jsx)(`div`,{className:`text-sm text-red-400 bg-red-900/20 border border-red-900/40 rounded-lg px-3 py-2`,children:S}),s===`full`&&(0,G.jsx)(`button`,{onClick:ye,disabled:b,className:`w-full py-3 bg-bambu-green hover:bg-bambu-green/80 disabled:opacity-50 disabled:cursor-not-allowed text-white text-sm font-medium rounded transition-colors`,children:b?i(`spoolbuddy.writeTag.creating`,`Creating...`):i(`spoolbuddy.writeTag.createSpool`,`Create Spool`)}),s===`full`&&n&&(0,G.jsxs)(`div`,{className:`flex flex-col items-center justify-center p-4 text-center bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg`,children:[(0,G.jsx)(`div`,{className:`w-12 h-12 rounded-full mb-4 border border-white/10`,style:n.rgba?Mf(n.rgba):{backgroundColor:`#666`}}),(0,G.jsxs)(`p`,{className:`text-white font-medium`,children:[n.brand?`${n.brand} `:``,n.material]}),n.color_name&&(0,G.jsx)(`p`,{className:`text-zinc-400 text-sm`,children:n.color_name}),(0,G.jsxs)(`p`,{className:`text-zinc-500 text-xs mt-1`,children:[n.label_weight,`g`]}),(0,G.jsx)(`p`,{className:`text-bambu-green text-sm mt-4`,children:i(`spoolbuddy.writeTag.spoolCreated`,`Spool created! Ready to write.`)})]})]})}function H2e({writeStatus:e,writeMessage:t,selectedSpool:n,tagOnReader:r,tagUid:i,deviceOnline:a,canWrite:o,isReplace:s,canUntag:c,untagging:l,onWrite:u,onUntag:d,onCancel:f,onRetry:p,t:m}){if(e===`success`)return(0,G.jsxs)(`div`,{className:`flex flex-col items-center text-center space-y-4`,children:[(0,G.jsx)(`div`,{className:`w-16 h-16 rounded-full bg-green-500/20 flex items-center justify-center`,children:(0,G.jsx)(`svg`,{className:`w-8 h-8 text-green-400`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M5 13l4 4L19 7`})})}),(0,G.jsx)(`p`,{className:`text-green-400 font-medium`,children:t}),n&&(0,G.jsxs)(`p`,{className:`text-zinc-400 text-sm`,children:[n.brand?`${n.brand} `:``,n.material,n.subtype?` ${n.subtype}`:``,n.color_name?` - ${n.color_name}`:``]})]});if(e===`error`)return(0,G.jsxs)(`div`,{className:`flex flex-col items-center text-center space-y-4`,children:[(0,G.jsx)(`div`,{className:`w-16 h-16 rounded-full bg-red-500/20 flex items-center justify-center`,children:(0,G.jsx)(`svg`,{className:`w-8 h-8 text-red-400`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M6 18L18 6M6 6l12 12`})})}),(0,G.jsx)(`p`,{className:`text-red-400 font-medium`,children:t}),(0,G.jsx)(`button`,{onClick:p,className:`px-4 py-2 bg-bambu-dark-tertiary hover:bg-bambu-dark-secondary text-white text-sm rounded transition-colors`,children:m(`spoolbuddy.writeTag.tryAgain`,`Try Again`)})]});if(e===`writing`)return(0,G.jsxs)(`div`,{className:`flex flex-col items-center text-center space-y-4`,children:[(0,G.jsxs)(`div`,{className:`relative w-16 h-16`,children:[(0,G.jsx)(`div`,{className:`absolute inset-0 rounded-full border-2 border-bambu-green/30 animate-ping`}),(0,G.jsx)(`div`,{className:`absolute inset-2 rounded-full border-2 border-bambu-green/50 animate-pulse`}),(0,G.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center`,children:(0,G.jsx)(Z9,{className:`w-8 h-8 text-bambu-green`})})]}),(0,G.jsx)(`p`,{className:`text-bambu-green font-medium`,children:m(`spoolbuddy.writeTag.writing`,`Writing tag...`)}),(0,G.jsx)(`p`,{className:`text-zinc-500 text-xs`,children:t}),(0,G.jsx)(`button`,{onClick:f,className:`px-4 py-2 bg-bambu-dark-tertiary hover:bg-bambu-dark-secondary text-zinc-400 text-sm rounded transition-colors`,children:m(`spoolbuddy.writeTag.cancel`,`Cancel`)})]});if(!a)return(0,G.jsxs)(`div`,{className:`flex flex-col items-center text-center space-y-3`,children:[(0,G.jsx)(Z9,{className:`w-12 h-12 text-zinc-600`}),(0,G.jsx)(`p`,{className:`text-zinc-500 text-sm`,children:m(`spoolbuddy.writeTag.deviceOffline`,`SpoolBuddy is offline`)})]});if(!n)return(0,G.jsxs)(`div`,{className:`flex flex-col items-center text-center space-y-3`,children:[(0,G.jsx)(Z9,{className:`w-12 h-12 text-zinc-600`}),(0,G.jsx)(`p`,{className:`text-zinc-400 text-sm`,children:m(`spoolbuddy.writeTag.selectSpool`,`Select a spool, then place a blank NTAG on the reader`)})]});let h=n.rgba?Mf(n.rgba):{backgroundColor:`#666`};return(0,G.jsxs)(`div`,{className:`flex flex-col items-center text-center space-y-4 w-full`,children:[(0,G.jsx)(`div`,{className:`relative w-16 h-16`,children:r?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`absolute inset-0 rounded-full bg-bambu-green/10`}),(0,G.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center`,children:(0,G.jsx)(Z9,{className:`w-8 h-8 text-bambu-green`})})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`absolute inset-0 rounded-full border-2 border-zinc-600 animate-pulse`}),(0,G.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center`,children:(0,G.jsx)(Z9,{className:`w-8 h-8 text-zinc-500`})})]})}),r?(0,G.jsxs)(`div`,{className:`space-y-1`,children:[(0,G.jsx)(`p`,{className:`text-bambu-green text-sm font-medium`,children:m(`spoolbuddy.writeTag.tagReady`,`Tag detected — ready to write`)}),i&&(0,G.jsx)(`p`,{className:`text-zinc-500 text-xs font-mono`,children:i})]}):(0,G.jsx)(`p`,{className:`text-zinc-400 text-sm`,children:m(`spoolbuddy.writeTag.placeTag`,`Place an NTAG on the reader`)}),(0,G.jsxs)(`div`,{className:`w-full bg-bambu-dark-secondary rounded-lg p-3 space-y-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`w-8 h-8 rounded-full border border-white/10 shrink-0`,style:h}),(0,G.jsxs)(`div`,{className:`text-left min-w-0`,children:[(0,G.jsxs)(`p`,{className:`text-white text-sm font-medium truncate`,children:[n.brand?`${n.brand} `:``,n.material]}),n.color_name&&(0,G.jsx)(`p`,{className:`text-zinc-400 text-xs`,children:n.color_name})]})]}),(0,G.jsxs)(`div`,{className:`text-xs text-zinc-500`,children:[n.label_weight,`g`]})]}),s&&n.tag_uid&&(0,G.jsx)(`p`,{className:`text-yellow-500/80 text-xs`,children:m(`spoolbuddy.writeTag.replaceWarning`,`Old tag will be unlinked. New tag will replace it.`)}),(0,G.jsx)(`button`,{onClick:u,disabled:!o,className:`w-full py-3 bg-bambu-green hover:bg-bambu-green/80 disabled:opacity-40 disabled:cursor-not-allowed text-white font-medium rounded-lg transition-colors text-sm`,children:s?m(`spoolbuddy.writeTag.replaceTag`,`Replace Tag`):m(`spoolbuddy.writeTag.writeTag`,`Write Tag`)}),s&&c&&(0,G.jsx)(`button`,{onClick:d,disabled:l,className:`w-full py-2.5 bg-bambu-dark-tertiary hover:bg-bambu-dark-secondary disabled:opacity-40 disabled:cursor-not-allowed text-zinc-200 rounded-lg transition-colors text-sm`,children:l?m(`spoolbuddy.writeTag.untagging`,`Removing tag...`):m(`spoolbuddy.writeTag.untagSpool`,`Untag Selected Spool`)})]})}function Z9({className:e}){return(0,G.jsxs)(`svg`,{className:e,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:1.5,children:[(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M8.288 15.038a5.25 5.25 0 017.424 0M5.106 11.856c3.807-3.808 9.98-3.808 13.788 0M1.924 8.674c5.565-5.565 14.587-5.565 20.152 0`}),(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M12.53 18.22l-.53.53-.53-.53a.75.75 0 011.06 0z`})]})}var U2e=`spoolbuddy-default-core-weight`;function W2e(){try{let e=localStorage.getItem(U2e);if(e){let t=parseInt(e,10);if(t>=0&&t<=500)return t}}catch{}return 250}function G2e({spool:e,liveScaleWeight:t,persistedGrossWeight:n,onClose:r,onSyncWeight:i,onAssignToAms:a,isAssigned:o,onUnassignFromAms:s,className:c}){let{t:l}=U(),[u,d]=(0,y.useState)(!1),[f,p]=(0,y.useState)(!1),[m,h]=(0,y.useState)(null),{data:g}=K({queryKey:[`spool-k-profiles`,e.id],queryFn:()=>Z.getSpoolKProfiles(e.id),enabled:!e.k_profiles||e.k_profiles.length===0,staleTime:300*1e3}),_=e.k_profiles&&e.k_profiles.length>0?e.k_profiles:g,v=Af(e.rgba),b=e.core_weight&&e.core_weight>0?e.core_weight:W2e(),x=t===null?null:Math.round(Math.max(0,t)),S=m??(n===void 0?x:n===null?null:Math.round(Math.max(0,n))),C=Math.round(Math.max(0,(e.label_weight||0)-(e.weight_used||0))),w=x!==null&&x>=10?Math.round(Math.max(0,x-b)):C,T=Math.round(e.label_weight||1e3),E=T>0?Math.min(100,Math.round(w/T*100)):null,D=E===null?`#808080`:E>50?`#22c55e`:E>20?`#eab308`:`#ef4444`,O=Math.max(0,(e.label_weight||0)-(e.weight_used||0))+b,k=x===null?null:x-O,A=k===null?null:Math.abs(k)<=50,j=S??Math.round(O),M=e.nozzle_temp_min!=null&&e.nozzle_temp_max!=null?`${e.nozzle_temp_min}-${e.nozzle_temp_max}\u00B0C`:null,N=e.slicer_filament_name||e.slicer_filament||null,P=e.note?.trim()||null,F=_&&_.length>0?Array.from(new Set(_.map(e=>e.k_value.toFixed(3)))).join(`, `):null,I=async()=>{if(t===null)return;let n=Math.round(Math.max(0,t));d(!0);try{await Od.updateSpoolWeight(e.id,n),h(n),p(!0),i?.(),setTimeout(()=>p(!1),3e3)}catch(e){console.error(`Failed to sync weight:`,e)}finally{d(!1)}};return(0,G.jsxs)(`div`,{className:`flex flex-col items-center space-y-4 max-w-md ${c??``}`,children:[(0,G.jsxs)(`div`,{className:`flex items-start gap-5`,children:[(0,G.jsxs)(`div`,{className:`relative shrink-0`,children:[(0,G.jsx)(W9,{color:v,isEmpty:!1,size:100}),E!==null&&(0,G.jsxs)(`div`,{className:`absolute -bottom-2 -right-2 px-2 py-0.5 rounded-full text-xs font-bold text-white shadow-lg`,style:{backgroundColor:D},children:[E,`%`]})]}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0 pt-1`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`h3`,{className:`text-lg font-semibold text-zinc-100`,children:e.color_name||`Unknown color`}),(0,G.jsxs)(`span`,{className:`text-xs font-mono text-zinc-500 shrink-0`,children:[`#`,e.id]})]}),(0,G.jsxs)(`p`,{className:`text-sm text-zinc-400`,children:[e.brand,` • `,e.material,e.subtype&&` ${e.subtype}`]}),(0,G.jsxs)(`div`,{className:`mt-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,G.jsxs)(`span`,{className:`text-3xl font-bold font-mono text-zinc-100`,children:[w,`g`]}),(0,G.jsxs)(`span`,{className:`text-sm text-zinc-500`,children:[`/ `,T,`g`]})]}),(0,G.jsx)(`p`,{className:`text-xs text-zinc-500 mt-0.5`,children:l(`spoolbuddy.spool.remaining`,`Remaining`)}),(0,G.jsx)(`div`,{className:`mt-2 max-w-xs`,children:(0,G.jsx)(`div`,{className:`h-2 bg-zinc-700 rounded-full overflow-hidden`,children:(0,G.jsx)(`div`,{className:`h-full rounded-full transition-all duration-500`,style:{width:`${E??0}%`,backgroundColor:D}})})})]})]})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-x-6 gap-y-2 text-sm bg-zinc-800 rounded-lg p-4 w-full`,children:[(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:l(`spoolbuddy.dashboard.grossWeight`,`Gross weight`)}),(0,G.jsxs)(`span`,{className:`font-mono text-zinc-300`,children:[j,`g`]})]}),(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:l(`spoolbuddy.spool.coreWeight`,`Core`)}),(0,G.jsxs)(`span`,{className:`font-mono text-zinc-300`,children:[b,`g`]})]}),(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:l(`spoolbuddy.dashboard.spoolSize`,`Spool size`)}),(0,G.jsxs)(`span`,{className:`font-mono text-zinc-300`,children:[T,`g`]})]}),(0,G.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:l(`spoolbuddy.spool.scaleWeight`,`Scale`)}),x===null?(0,G.jsx)(`span`,{className:`text-zinc-500`,children:`—`}):(0,G.jsxs)(`span`,{className:`flex items-center gap-1 font-mono ${A?`text-green-500`:`text-yellow-500`}`,children:[x,`g`,A?(0,G.jsx)(fs,{className:`w-3.5 h-3.5`}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Lu,{className:`w-3.5 h-3.5`}),(0,G.jsx)(`button`,{onClick:I,className:`p-1 hover:bg-green-500/20 rounded transition-colors text-green-500`,title:l(`spoolbuddy.dashboard.syncWeight`,`Sync Weight`),children:(0,G.jsx)(Hl,{className:`w-4 h-4`})})]})]})]}),(0,G.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:l(`spoolbuddy.dashboard.tagId`,`Tag`)}),(0,G.jsx)(`span`,{className:`font-mono text-xs text-zinc-400 truncate max-w-[120px]`,title:e.tag_uid||``,children:e.tag_uid?e.tag_uid.slice(-8):`—`})]}),M&&(0,G.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:l(`spoolbuddy.inventory.nozzleTemp`,`Nozzle`)}),(0,G.jsx)(`span`,{className:`font-mono text-zinc-300`,children:M})]}),e.cost_per_kg!=null&&e.cost_per_kg>0&&(0,G.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:l(`spoolbuddy.inventory.costPerKg`,`Cost/kg`)}),(0,G.jsxs)(`span`,{className:`font-mono text-zinc-300`,children:[e.cost_per_kg.toFixed(2),`/kg`]})]}),F&&(0,G.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:l(`spoolbuddy.inventory.kProfiles`,`K-Profile`)}),(0,G.jsx)(`span`,{className:`font-mono text-zinc-300 truncate max-w-[220px] text-right`,title:F,children:F})]}),N&&(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsx)(`p`,{className:`text-xs text-zinc-500 mb-1`,children:l(`spoolbuddy.inventory.slicerFilament`,`Slicer Filament`)}),(0,G.jsx)(`p`,{className:`text-sm text-zinc-300 whitespace-pre-wrap break-words`,children:N})]}),P&&(0,G.jsxs)(`div`,{className:`col-span-2`,children:[(0,G.jsx)(`p`,{className:`text-xs text-zinc-500 mb-1`,children:l(`spoolbuddy.inventory.note`,`Note`)}),(0,G.jsx)(`p`,{className:`text-sm leading-5 text-zinc-300 whitespace-pre-wrap break-words max-h-[3.75rem] overflow-y-auto pr-1`,children:P})]})]}),(0,G.jsxs)(`div`,{className:`flex gap-2 justify-center`,children:[a&&(0,G.jsx)(`button`,{onClick:o?void 0:a,disabled:!!o,className:`px-5 py-2.5 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 transition-colors min-h-[44px] disabled:opacity-50 disabled:cursor-not-allowed`,children:l(`spoolbuddy.modal.assignToAms`,`Assign to AMS`)}),s&&(0,G.jsxs)(`button`,{onClick:s,className:`px-5 py-2.5 rounded-lg text-sm font-medium bg-red-600/20 text-red-400 hover:bg-red-600/30 transition-colors min-h-[44px]`,children:[(0,G.jsx)(Bu,{className:`w-4 h-4 inline mr-1`}),l(`inventory.unassignSpool`)]}),(0,G.jsx)(`button`,{onClick:I,disabled:t===null||u,className:`px-5 py-2.5 rounded-lg text-sm font-medium transition-colors min-h-[44px] ${f?`bg-green-600/20 text-green-400`:a?`bg-zinc-700 text-zinc-300 hover:bg-zinc-600 disabled:opacity-40 disabled:cursor-not-allowed`:`bg-green-600 text-white hover:bg-green-700 disabled:opacity-40 disabled:cursor-not-allowed`}`,children:u?`...`:f?l(`spoolbuddy.dashboard.weightSynced`,`Synced!`):l(`spoolbuddy.dashboard.syncWeight`,`Sync Weight`)}),r&&(0,G.jsx)(`button`,{onClick:r,className:`px-5 py-2.5 rounded-lg text-sm font-medium bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors min-h-[44px]`,children:l(`spoolbuddy.dashboard.close`,`Close`)})]})]})}function K2e(e){return Af(e.rgba)}function q2e(e){return Math.max(0,e.label_weight-e.weight_used)}function J2e(e){return e.label_weight<=0?0:Math.max(0,Math.min(100,(e.label_weight-e.weight_used)/e.label_weight*100))}function Y2e(e){let t=[e.material];return e.subtype&&t.push(e.subtype),t.join(` `)}function X2e(e){let t=e.ams_id===254||e.ams_id===255,n=!t&&e.ams_id>=128;return jp(e.ams_id,e.tray_id,n,t)}function Z2e({color:e,size:t=56}){return(0,G.jsxs)(`svg`,{width:t,height:t,viewBox:`0 0 56 56`,children:[(0,G.jsx)(`circle`,{cx:`28`,cy:`28`,r:`26`,fill:e}),(0,G.jsx)(`circle`,{cx:`28`,cy:`28`,r:`20`,fill:e,style:{filter:`brightness(0.85)`}}),(0,G.jsx)(`ellipse`,{cx:`20`,cy:`20`,rx:`6`,ry:`4`,fill:`white`,opacity:`0.3`}),(0,G.jsx)(`circle`,{cx:`28`,cy:`28`,r:`8`,fill:`#2d2d2d`}),(0,G.jsx)(`circle`,{cx:`28`,cy:`28`,r:`5`,fill:`#1a1a1a`})]})}function Q2e(){let{sbState:e,selectedPrinterId:t}=lr(),{t:n}=U(),{showToast:r}=qd(),i=co(),[a,o]=(0,y.useState)(``),[s,c]=(0,y.useState)(`all`),[l,u]=(0,y.useState)(null),[d,f]=(0,y.useState)(!1),{data:p}=K({queryKey:[`spoolman-settings`],queryFn:Z.getSpoolmanSettings,staleTime:300*1e3}),m=p?.spoolman_enabled===`true`&&!!p?.spoolman_url,{data:h=[],isLoading:g,refetch:_}=K({queryKey:m?[`spoolman-inventory-spools`]:[`inventory-spools`],queryFn:()=>m?Z.getSpoolmanInventorySpools(!1):Z.getSpools(!1),enabled:p!==void 0,refetchInterval:3e4}),{data:v=[]}=K({queryKey:[`spool-assignments`],queryFn:()=>Z.getAssignments(),refetchInterval:3e4,enabled:!m}),{data:b=[]}=K({queryKey:[`spoolman-slot-assignments`],queryFn:()=>Z.getSpoolmanSlotAssignments(),refetchInterval:3e4,enabled:m}),x=q({mutationFn:e=>Z.unassignSpoolmanSlot(e),onSuccess:()=>{i.invalidateQueries({queryKey:[`spoolman-slot-assignments`]}),i.invalidateQueries({queryKey:[`spoolman-inventory-spools`]})},onError:()=>r(n(`inventory.unassignFailed`,`Failed to unassign spool`),`error`)}),S=(0,y.useMemo)(()=>{if(m){let e={};return b.forEach(t=>{e[t.spoolman_spool_id]={ams_id:t.ams_id,tray_id:t.tray_id}}),e}let e={};return v.forEach(t=>{e[t.spool_id]={ams_id:t.ams_id,tray_id:t.tray_id,printer_name:t.printer_name}}),e},[m,v,b]),C=(0,y.useMemo)(()=>h.filter(e=>!e.archived_at),[h]),w=(0,y.useMemo)(()=>new Set(Object.keys(S).map(Number)),[S]),T=(0,y.useMemo)(()=>C.filter(e=>w.has(e.id)).length,[C,w]),E=(0,y.useMemo)(()=>{let e=new Set;return C.forEach(t=>e.add(t.material)),Array.from(e).sort()},[C]),D=(0,y.useMemo)(()=>{let e=C;return s===`in_ams`?e=e.filter(e=>w.has(e.id)):s!==`all`&&(e=e.filter(e=>e.material===s)),e=wH(e,a.trim()),[...e].sort((e,t)=>{let n=+!w.has(e.id),r=+!w.has(t.id);return n===r?new Date(t.updated_at).getTime()-new Date(e.updated_at).getTime():n-r})},[C,s,a,w]);return(0,G.jsxs)(`div`,{className:`h-full flex flex-col`,children:[(0,G.jsxs)(`div`,{className:`px-3 pt-3 pb-2 space-y-2.5`,children:[(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(Ql,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-white/40`}),(0,G.jsx)(`input`,{type:`text`,value:a,onChange:e=>o(e.target.value),placeholder:n(`spoolbuddy.inventory.searchPlaceholder`,`Search spools...`),className:`w-full pl-9 pr-8 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-sm text-white placeholder-white/30 focus:outline-none focus:border-bambu-green`}),a&&(0,G.jsx)(`button`,{onClick:()=>o(``),className:`absolute right-2 top-1/2 -translate-y-1/2 text-white/40 hover:text-white/60`,children:(0,G.jsx)(nd,{className:`w-4 h-4`})})]}),(0,G.jsxs)(`div`,{className:`flex gap-1.5 overflow-x-auto no-scrollbar`,children:[(0,G.jsx)(Q9,{active:s===`all`,onClick:()=>c(`all`),label:`${n(`spoolbuddy.inventory.all`,`All`)} (${C.length})`,green:!0}),T>0&&(0,G.jsx)(Q9,{active:s===`in_ams`,onClick:()=>c(`in_ams`),label:`${n(`spoolbuddy.inventory.inAms`,`In AMS`)} (${T})`}),E.map(e=>(0,G.jsx)(Q9,{active:s===e,onClick:()=>c(s===e?`all`:e),label:e},e))]})]}),(0,G.jsx)(`div`,{className:`flex-1 overflow-y-auto px-3 pb-3`,children:g?(0,G.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,G.jsx)(`div`,{className:`w-8 h-8 border-2 border-bambu-green border-t-transparent rounded-full animate-spin`})}):D.length===0?(0,G.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-16 text-white/30`,children:[(0,G.jsx)(Cl,{className:`w-12 h-12 mb-3`}),(0,G.jsx)(`p`,{className:`text-sm`,children:a||s!==`all`?n(`spoolbuddy.inventory.noResults`,`No spools match your filters`):n(`spoolbuddy.inventory.empty`,`No spools in inventory`)})]}):(0,G.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(130px,1fr))] gap-2`,children:D.map(e=>(0,G.jsx)($2e,{spool:e,assignment:S[e.id],onClick:()=>u(e.id)},e.id))})}),l!=null&&(()=>{let n=h.find(e=>e.id===l);return n?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(e4e,{spool:n,assignment:S[n.id],sbState:e,onSyncWeight:()=>{_()},onAssignToAms:()=>f(!0),onUnassignFromAms:m&&S[n.id]?()=>x.mutate(n.id):void 0,onClose:()=>{u(null),f(!1)}}),(0,G.jsx)(Y9,{isOpen:d,onClose:()=>f(!1),spool:n,printerId:t,spoolmanMode:m})]}):null})()]})}function Q9({active:e,onClick:t,label:n,green:r}){return(0,G.jsx)(`button`,{onClick:t,className:`px-4 py-1.5 rounded-full text-sm font-medium border whitespace-nowrap shrink-0 transition-colors ${e?r?`bg-bambu-green/20 text-bambu-green border-bambu-green/50`:`bg-white/10 text-white border-white/20`:`bg-transparent text-white/40 border-bambu-dark-tertiary hover:text-white/60`}`,children:n})}function $2e({spool:e,assignment:t,onClick:n}){let r=K2e(e),i=J2e(e),a=q2e(e),o=kf(e.color_name,e.rgba);return(0,G.jsxs)(`button`,{onClick:n,className:`bg-bambu-dark-secondary rounded-xl p-3 flex flex-col items-center text-center gap-1.5 border border-transparent hover:border-bambu-green/50 transition-colors`,children:[(0,G.jsx)(Z2e,{color:r,size:56}),(0,G.jsx)(`p`,{className:`text-xs font-semibold text-white leading-tight truncate w-full`,children:Y2e(e)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1 min-w-0 max-w-full`,children:[(0,G.jsx)(`span`,{className:`w-2.5 h-2.5 rounded-full shrink-0 border border-white/10`,style:Mf(e.rgba)}),(0,G.jsx)(`span`,{className:`text-[11px] text-white/50 truncate`,children:o||`-`})]}),(0,G.jsxs)(`div`,{className:`w-full space-y-0.5`,children:[(0,G.jsx)(`div`,{className:`h-1.5 bg-bambu-dark-tertiary rounded-full overflow-hidden`,children:(0,G.jsx)(`div`,{className:`h-full rounded-full ${i>50?`bg-bambu-green`:i>20?`bg-yellow-500`:`bg-red-500`}`,style:{width:`${Math.min(i,100)}%`}})}),(0,G.jsxs)(`p`,{className:`text-[11px] text-white/40`,children:[Math.round(a),`g (`,Math.round(i),`%)`]})]}),t&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 rounded text-[10px] font-bold bg-bambu-green/20 text-bambu-green`,children:X2e(t)})]})}function e4e({spool:e,assignment:t,sbState:n,onSyncWeight:r,onAssignToAms:i,onUnassignFromAms:a,onClose:o}){let s=n.deviceOnline&&n.weight!==null?Math.round(n.weight):null,c=e.last_scale_weight==null?null:Math.round(e.last_scale_weight);return(0,G.jsx)(`div`,{className:`fixed inset-0 z-50 bg-black/70 flex items-center justify-center p-4`,onClick:o,children:(0,G.jsx)(`div`,{className:`w-full max-w-md bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-2xl p-4 overflow-y-auto max-h-[90vh]`,onClick:e=>e.stopPropagation(),children:(0,G.jsxs)(`div`,{className:`space-y-3`,children:[t&&(0,G.jsxs)(`div`,{className:`flex items-center justify-center gap-2`,children:[(0,G.jsx)(`span`,{className:`px-2.5 py-1 rounded-md text-xs font-bold bg-bambu-green/20 text-bambu-green`,children:X2e(t)}),t.printer_name&&(0,G.jsx)(`span`,{className:`text-xs text-zinc-400`,children:t.printer_name})]}),(0,G.jsx)(`div`,{className:`flex justify-center`,children:(0,G.jsx)(G2e,{spool:e,liveScaleWeight:s,persistedGrossWeight:c,onSyncWeight:r,onAssignToAms:i,isAssigned:!!t,onUnassignFromAms:a,onClose:o,className:`max-w-md`})})]})})})}var t4e=class extends y.Component{state={error:null,errorInfo:null};static getDerivedStateFromError(e){return{error:e}}componentDidCatch(e,t){this.setState({errorInfo:t}),console.error(`React crash:`,e,t)}render(){return this.state.error?(0,G.jsxs)(`div`,{style:{padding:24,color:`#ef4444`,backgroundColor:`#18181b`,minHeight:`100vh`,fontFamily:`monospace`},children:[(0,G.jsx)(`h1`,{style:{fontSize:20,marginBottom:12},children:`UI Crash`}),(0,G.jsx)(`pre`,{style:{whiteSpace:`pre-wrap`,fontSize:14},children:this.state.error.message}),(0,G.jsx)(`pre`,{style:{whiteSpace:`pre-wrap`,fontSize:12,color:`#a1a1aa`,marginTop:12},children:this.state.error.stack}),(0,G.jsx)(`button`,{onClick:()=>{this.setState({error:null,errorInfo:null})},style:{marginTop:16,padding:`8px 16px`,backgroundColor:`#3b82f6`,color:`#fff`,border:`none`,borderRadius:8,cursor:`pointer`},children:`Retry`})]}):this.props.children}},n4e=new ao({defaultOptions:{queries:{staleTime:1e3*60,retry:1}}});function r4e(){return b$e(),null}function i4e({children:e}){return S0e(),D0e(),(0,G.jsx)(G.Fragment,{children:e})}function a4e({children:e}){let{authEnabled:t,loading:n,user:r}=Nd(),i=rr();return n?(0,G.jsx)(`div`,{className:`min-h-screen flex items-center justify-center`,children:`Loading...`}):t&&!r?(0,G.jsx)(Fr,{to:`/login`,replace:!0,state:{from:i}}):(0,G.jsx)(G.Fragment,{children:e})}function $9({permission:e,children:t}){let{authEnabled:n,loading:r,user:i,hasPermission:a}=Nd(),o=rr();return r?(0,G.jsx)(`div`,{className:`min-h-screen flex items-center justify-center`,children:`Loading...`}):n?i?a(e)?(0,G.jsx)(G.Fragment,{children:t}):(0,G.jsx)(Fr,{to:`/`,replace:!0}):(0,G.jsx)(Fr,{to:`/login`,replace:!0,state:{from:o}}):(0,G.jsx)(G.Fragment,{children:t})}function o4e({children:e}){let{authEnabled:t,loading:n}=Nd();return n?(0,G.jsx)(`div`,{className:`min-h-screen flex items-center justify-center`,children:`Loading...`}):t?(0,G.jsx)(Fr,{to:`/login`,replace:!0}):(0,G.jsx)(G.Fragment,{children:e})}function s4e(){return(0,G.jsx)(t4e,{children:(0,G.jsx)(rf,{children:(0,G.jsx)(lo,{client:n4e,children:(0,G.jsx)(Md,{children:(0,G.jsx)(Fd,{children:(0,G.jsx)(O0e,{children:(0,G.jsxs)(kAe,{children:[(0,G.jsx)(r4e,{}),(0,G.jsx)(Oi,{children:(0,G.jsxs)(zr,{children:[(0,G.jsx)(Lr,{path:`/setup`,element:(0,G.jsx)(o4e,{children:(0,G.jsx)(v0e,{})})}),(0,G.jsx)(Lr,{path:`/login`,element:(0,G.jsx)(_0e,{})}),(0,G.jsx)(Lr,{path:`/camera/:printerId`,element:(0,G.jsx)(w$e,{})}),(0,G.jsx)(Lr,{path:`/overlay/:printerId`,element:(0,G.jsx)(B$e,{})}),(0,G.jsx)(Lr,{path:`/camwall`,element:(0,G.jsx)(P$e,{})}),(0,G.jsxs)(Lr,{element:(0,G.jsx)(a4e,{children:(0,G.jsx)(i4e,{children:(0,G.jsx)(H0e,{})})}),children:[(0,G.jsx)(Lr,{path:`spoolbuddy`,element:(0,G.jsx)(g2e,{})}),(0,G.jsx)(Lr,{path:`spoolbuddy/ams`,element:(0,G.jsx)(b2e,{})}),(0,G.jsx)(Lr,{path:`spoolbuddy/write-tag`,element:(0,G.jsx)(R2e,{})}),(0,G.jsx)(Lr,{path:`spoolbuddy/inventory`,element:(0,G.jsx)(Q2e,{})}),(0,G.jsx)(Lr,{path:`spoolbuddy/settings`,element:(0,G.jsx)(N2e,{})}),(0,G.jsx)(Lr,{path:`spoolbuddy/calibration`,element:(0,G.jsx)(F2e,{})})]}),(0,G.jsxs)(Lr,{element:(0,G.jsx)(a4e,{children:(0,G.jsx)(i4e,{children:(0,G.jsx)(gee,{})})}),children:[(0,G.jsx)(Lr,{index:!0,element:(0,G.jsx)(wAe,{})}),(0,G.jsx)(Lr,{path:`archives`,element:(0,G.jsx)(LVe,{})}),(0,G.jsx)(Lr,{path:`queue`,element:(0,G.jsx)(GUe,{})}),(0,G.jsx)(Lr,{path:`pipelines/runs`,element:(0,G.jsx)(Fr,{to:`/queue?tab=pipelines`,replace:!0})}),(0,G.jsx)(Lr,{path:`stats`,element:(0,G.jsx)(uWe,{})}),(0,G.jsx)(Lr,{path:`profiles`,element:(0,G.jsx)(xKe,{})}),(0,G.jsx)(Lr,{path:`finance`,element:(0,G.jsx)($9,{permission:`cost_centers:read_own`,children:(0,G.jsx)(eKe,{})})}),(0,G.jsx)(Lr,{path:`maintenance`,element:(0,G.jsx)(EKe,{})}),(0,G.jsx)(Lr,{path:`projects`,element:(0,G.jsx)(kKe,{})}),(0,G.jsx)(Lr,{path:`projects/:id`,element:(0,G.jsx)(NKe,{})}),(0,G.jsx)(Lr,{path:`inventory`,element:(0,G.jsx)(G1e,{})}),(0,G.jsx)(Lr,{path:`files`,element:(0,G.jsx)(m$e,{})}),(0,G.jsx)(Lr,{path:`files/trash`,element:(0,G.jsx)(_$e,{})}),(0,G.jsx)(Lr,{path:`makerworld`,element:(0,G.jsx)($9,{permission:`makerworld:view`,children:(0,G.jsx)(o0e,{})})}),(0,G.jsx)(Lr,{path:`settings`,element:(0,G.jsx)($9,{permission:`settings:read`,children:(0,G.jsx)(XGe,{})})}),(0,G.jsx)(Lr,{path:`groups/new`,element:(0,G.jsx)($9,{permission:`groups:create`,children:(0,G.jsx)(H$e,{})})}),(0,G.jsx)(Lr,{path:`groups/:id/edit`,element:(0,G.jsx)($9,{permission:`groups:update`,children:(0,G.jsx)(H$e,{})})}),(0,G.jsx)(Lr,{path:`users`,element:(0,G.jsx)(Fr,{to:`/settings?tab=users`,replace:!0})}),(0,G.jsx)(Lr,{path:`groups`,element:(0,G.jsx)(Fr,{to:`/settings?tab=users`,replace:!0})}),(0,G.jsx)(Lr,{path:`system`,element:(0,G.jsx)(f0e,{})}),(0,G.jsx)(Lr,{path:`notifications`,element:(0,G.jsx)(y0e,{})}),(0,G.jsx)(Lr,{path:`gcode-viewer`,element:(0,G.jsx)(b0e,{})}),(0,G.jsx)(Lr,{path:`external/:id`,element:(0,G.jsx)(V$e,{})}),(0,G.jsx)(Lr,{path:`camera-tokens`,element:(0,G.jsx)(Fr,{to:`/settings?tab=apikeys#card-camera-tokens`,replace:!0})})]})]})})]})})})})})})})}(0,b.createRoot)(document.getElementById(`root`)).render((0,G.jsx)(y.StrictMode,{children:(0,G.jsx)(s4e,{})})); \ No newline at end of file +In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}()}function w(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n1&&arguments[1]!==void 0?arguments[1]:e;this.caretPosition=e,this.caretPositionEnd=t}},{key:`getInputCandidates`,value:function(e){var t=this,n=this.options,r=n.layoutCandidates,i=n.layoutCandidatesCaseSensitiveMatch;if(!r||T(r)!==`object`)return{};var a=Object.keys(r).filter((function(n){var r=e.substring(0,t.getCaretPositionEnd()||0)||e,a=RegExp(`${t.utilities.escapeRegex(n)}\$`,i?`g`:`gi`);return!!C(r.matchAll(a)).length}));if(a.length>1){var o=a.sort((function(e,t){return t.length-e.length}))[0];return{candidateKey:o,candidateValue:r[o]}}if(a.length){var s=a[0];return{candidateKey:s,candidateValue:r[s]}}return{}}},{key:`showCandidatesBox`,value:function(e,t,n){var r=this;this.candidateBox&&this.candidateBox.show({candidateValue:t,targetElement:n,onSelect:function(t,n){var i=r.options,a=i.layoutCandidatesCaseSensitiveMatch,o=i.disableCandidateNormalization,s=i.enableLayoutCandidatesKeyPress,c=t;o||(c=t.normalize(`NFD`)),typeof r.options.beforeInputUpdate==`function`&&r.options.beforeInputUpdate(r);var l=r.getInput(r.options.inputName,!0),u=r.getCaretPositionEnd()||0,d=l.substring(0,u||0)||l,f=RegExp(`${r.utilities.escapeRegex(e)}\$`,a?`g`:`gi`),p=d.replace(f,c),m=l.replace(d,p),h=p.length-d.length,g=(u||l.length)+h;g<0&&(g=0),r.setInput(m,r.options.inputName,!0),r.setCaretPosition(g),s&&typeof r.options.onKeyPress==`function`&&r.options.onKeyPress(t,n),typeof r.options.onChange==`function`&&r.options.onChange(r.getInput(r.options.inputName,!0),n),typeof r.options.onChangeAll==`function`&&r.options.onChangeAll(r.getAllInputs(),n)}})}},{key:`handleButtonClicked`,value:function(e,t){var n=this.options,r=n.inputName,i=r===void 0?this.defaultName:r,a=n.debug;if(e!==`{//}`){this.input[i]||(this.input[i]=``),typeof this.options.beforeInputUpdate==`function`&&this.options.beforeInputUpdate(this);var o=this.utilities.getUpdatedInput(e,this.input[i],this.caretPosition,this.caretPositionEnd);if(this.utilities.isStandardButton(e)&&this.activeInputElement&&this.input[i]&&this.input[i]===o&&this.caretPosition===0&&this.caretPositionEnd===o.length)return this.setInput(``,this.options.inputName,!0),this.setCaretPosition(0),this.activeInputElement.value=``,this.activeInputElement.setSelectionRange(0,0),void this.handleButtonClicked(e,t);if(typeof this.options.onKeyPress==`function`&&this.options.onKeyPress(e,t),this.input[i]!==o&&(!this.options.inputPattern||this.options.inputPattern&&this.inputPatternIsValid(o))){if(this.options.maxLength&&this.utilities.handleMaxLength(this.input,o))return;var s=this.utilities.getUpdatedInput(e,this.input[i],this.caretPosition,this.caretPositionEnd,!0);if(this.setInput(s,this.options.inputName,!0),a&&console.log(`Input changed:`,this.getAllInputs()),this.options.debug&&console.log(`Caret at: `,this.getCaretPosition(),this.getCaretPositionEnd(),`(${this.keyboardDOMClass})`,t?.type),this.options.syncInstanceInputs&&this.syncInstanceInputs(),typeof this.options.onChange==`function`&&this.options.onChange(this.getInput(this.options.inputName,!0),t),typeof this.options.onChangeAll==`function`&&this.options.onChangeAll(this.getAllInputs(),t),t!=null&&t.target&&this.options.enableLayoutCandidates){var c,l=this.getInputCandidates(o),u=l.candidateKey,d=l.candidateValue;u&&d?this.showCandidatesBox(u,d,this.keyboardDOM):(c=this.candidateBox)==null||c.destroy()}}this.caretPositionEnd&&this.caretPosition!==this.caretPositionEnd&&(this.setCaretPosition(this.caretPositionEnd,this.caretPositionEnd),this.activeInputElement&&this.activeInputElement.setSelectionRange(this.caretPositionEnd,this.caretPositionEnd),this.options.debug&&console.log(`Caret position aligned`,this.caretPosition)),a&&console.log(`Key pressed:`,e)}}},{key:`getMouseHold`,value:function(){return this.isMouseHold}},{key:`setMouseHold`,value:function(e){this.options.syncInstanceInputs?this.dispatch((function(t){t.isMouseHold=e})):this.isMouseHold=e}},{key:`handleButtonMouseDown`,value:function(e,t){var n=this;t&&(this.options.preventMouseDownDefault&&t.preventDefault(),this.options.stopMouseDownPropagation&&t.stopPropagation(),t.target.classList.add(this.activeButtonClass)),this.holdInteractionTimeout&&clearTimeout(this.holdInteractionTimeout),this.holdTimeout&&clearTimeout(this.holdTimeout),this.setMouseHold(!0),this.options.disableButtonHold||(this.holdTimeout=window.setTimeout((function(){(n.getMouseHold()&&(!e.includes(`{`)&&!e.includes(`}`)||e===`{delete}`||e===`{backspace}`||e===`{bksp}`||e===`{space}`||e===`{tab}`)||e===`{arrowright}`||e===`{arrowleft}`||e===`{arrowup}`||e===`{arrowdown}`)&&(n.options.debug&&console.log(`Button held:`,e),n.handleButtonHold(e)),clearTimeout(n.holdTimeout)}),500))}},{key:`handleButtonMouseUp`,value:function(e,t){var n=this;t&&(this.options.preventMouseUpDefault&&t.preventDefault&&t.preventDefault(),this.options.stopMouseUpPropagation&&t.stopPropagation&&t.stopPropagation(),!(t.target===this.keyboardDOM||t.target&&this.keyboardDOM.contains(t.target)||this.candidateBox&&this.candidateBox.candidateBoxElement&&(t.target===this.candidateBox.candidateBoxElement||t.target&&this.candidateBox.candidateBoxElement.contains(t.target)))&&this.candidateBox&&this.candidateBox.destroy()),this.recurseButtons((function(e){e.classList.remove(n.activeButtonClass)})),this.setMouseHold(!1),this.holdInteractionTimeout&&clearTimeout(this.holdInteractionTimeout),e&&typeof this.options.onKeyReleased==`function`&&this.options.onKeyReleased(e,t)}},{key:`handleKeyboardContainerMouseDown`,value:function(e){this.options.preventMouseDownDefault&&e.preventDefault()}},{key:`handleButtonHold`,value:function(e){var t=this;this.holdInteractionTimeout&&clearTimeout(this.holdInteractionTimeout),this.holdInteractionTimeout=window.setTimeout((function(){t.getMouseHold()?(t.handleButtonClicked(e),t.handleButtonHold(e)):clearTimeout(t.holdInteractionTimeout)}),100)}},{key:`syncInstanceInputs`,value:function(){var e=this;this.dispatch((function(t){t.replaceInput(e.input),t.setCaretPosition(e.caretPosition,e.caretPositionEnd)}))}},{key:`clearInput`,value:function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.options.inputName||this.defaultName;this.input[e]=``,this.setCaretPosition(0),this.options.syncInstanceInputs&&this.syncInstanceInputs()}},{key:`getInput`,value:function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:this.options.inputName||this.defaultName,t=arguments.length>1&&arguments[1]!==void 0&&arguments[1];return this.options.syncInstanceInputs&&!t&&this.syncInstanceInputs(),this.options.rtl?`‫`+this.input[e].replace(`‫`,``).replace(`‬`,``)+`‬`:this.input[e]}},{key:`getAllInputs`,value:function(){var e=this,t={};return Object.keys(this.input).forEach((function(n){t[n]=e.getInput(n,!0)})),t}},{key:`setInput`,value:function(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:this.options.inputName||this.defaultName,n=arguments.length>2?arguments[2]:void 0;this.input[t]=e,!n&&this.options.syncInstanceInputs&&this.syncInstanceInputs()}},{key:`replaceInput`,value:function(e){this.input=e}},{key:`setOptions`,value:function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},t=this.changedOptions(e);this.options=Object.assign(this.options,e),t.length&&(this.options.debug&&console.log(`changedOptions`,t),this.onSetOptions(t),this.render())}},{key:`changedOptions`,value:function(e){var t=this;return Object.keys(e).filter((function(n){return JSON.stringify(e[n])!==JSON.stringify(t.options[n])}))}},{key:`onSetOptions`,value:function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];e.includes(`layoutName`)&&this.candidateBox&&this.candidateBox.destroy(),(e.includes(`layoutCandidatesPageSize`)||e.includes(`layoutCandidates`))&&this.candidateBox&&(this.candidateBox.destroy(),this.candidateBox=new S({utilities:this.utilities,options:this.options}))}},{key:`resetRows`,value:function(){this.keyboardRowsDOM&&this.keyboardRowsDOM.remove(),this.keyboardDOM.className=this.keyboardDOMClass,this.keyboardDOM.setAttribute(`data-skInstance`,this.currentInstanceName),this.buttonElements={}}},{key:`dispatch`,value:function(e){if(!window.SimpleKeyboardInstances)throw console.warn(`SimpleKeyboardInstances is not defined. Dispatch cannot be called.`),Error(`INSTANCES_VAR_ERROR`);return Object.keys(window.SimpleKeyboardInstances).forEach((function(t){e(window.SimpleKeyboardInstances[t],t)}))}},{key:`addButtonTheme`,value:function(e,t){var n=this;t&&e&&(e.split(` `).forEach((function(r){t.split(` `).forEach((function(t){n.options.buttonTheme||(n.options.buttonTheme=[]);var i=!1;n.options.buttonTheme.map((function(e){if(e!=null&&e.class.split(` `).includes(t)){i=!0;var n=e.buttons.split(` `);n.includes(r)||(i=!0,n.push(r),e.buttons=n.join(` `))}return e})),i||n.options.buttonTheme.push({class:t,buttons:e})}))})),this.render())}},{key:`removeButtonTheme`,value:function(e,t){var n=this;if(!e&&!t)return this.options.buttonTheme=[],void this.render();e&&Array.isArray(this.options.buttonTheme)&&this.options.buttonTheme.length&&(e.split(` `).forEach((function(e){var r;(r=n.options)==null||(r=r.buttonTheme)==null||r.map((function(r,i){if(r&&t&&t.includes(r.class)||!t){var a,o=r?.buttons.split(` `).filter((function(t){return t!==e}));r&&o!=null&&o.length?r.buttons=o.join(` `):((a=n.options.buttonTheme)==null||a.splice(i,1),r=null)}return r}))})),this.render())}},{key:`getButtonElement`,value:function(e){var t,n=this.buttonElements[e];return n&&(t=n.length>1?n:n[0]),t}},{key:`inputPatternIsValid`,value:function(e){var t,n=this.options.inputPattern;if((t=n instanceof RegExp?n:n[this.options.inputName||this.defaultName])&&e){var r=t.test(e);return this.options.debug&&console.log(`inputPattern ("${t}"): ${r?`passed`:`did not pass!`}`),r}return!0}},{key:`setEventListeners`,value:function(){if(this.isFirstKeyboardInstance||!this.allKeyboardInstances){this.options.debug&&console.log(`Caret handling started (${this.keyboardDOMClass})`);var e=this.options.physicalKeyboardHighlightPreventDefault,t=e!==void 0&&e;document.addEventListener(`keyup`,this.handleKeyUp,t),document.addEventListener(`keydown`,this.handleKeyDown,t),document.addEventListener(`mouseup`,this.handleMouseUp),document.addEventListener(`touchend`,this.handleTouchEnd),this.options.updateCaretOnSelectionChange&&document.addEventListener(`selectionchange`,this.handleSelectionChange),document.addEventListener(`select`,this.handleSelect)}}},{key:`handleKeyUp`,value:function(e){this.caretEventHandler(e),this.options.physicalKeyboardHighlight&&this.physicalKeyboard.handleHighlightKeyUp(e)}},{key:`handleKeyDown`,value:function(e){this.options.physicalKeyboardHighlight&&this.physicalKeyboard.handleHighlightKeyDown(e)}},{key:`handleMouseUp`,value:function(e){this.caretEventHandler(e)}},{key:`handleTouchEnd`,value:function(e){this.caretEventHandler(e)}},{key:`handleSelect`,value:function(e){this.caretEventHandler(e)}},{key:`handleSelectionChange`,value:function(e){navigator.userAgent.includes(`Firefox`)||this.caretEventHandler(e)}},{key:`caretEventHandler`,value:function(e){var t,n=this;e.target.tagName&&(t=e.target.tagName.toLowerCase()),this.dispatch((function(r){var i=e.target===r.keyboardDOM||e.target&&r.keyboardDOM.contains(e.target);if(n.options.syncInstanceInputs&&Array.isArray(e.path)&&(i=e.path.some((function(e){var t;return e==null||(t=e.hasAttribute)==null?void 0:t.call(e,`data-skInstance`)}))),(t===`textarea`||t===`input`&&[`text`,`search`,`url`,`tel`,`password`].includes(e.target.type))&&!r.options.disableCaretPositioning){var a=e.target.selectionStart,o=e.target.selectionEnd;r.options.rtl&&(a=r.utilities.getRtlOffset(a,r.getInput()),o=r.utilities.getRtlOffset(o,r.getInput())),r.setCaretPosition(a,o),r.activeInputElement=e.target,r.options.debug&&console.log(`Caret at: `,r.getCaretPosition(),r.getCaretPositionEnd(),e&&e.target.tagName.toLowerCase(),`(${r.keyboardDOMClass})`,e?.type)}else !r.options.disableCaretPositioning&&i||e?.type===`selectionchange`||(r.setCaretPosition(null),r.activeInputElement=null,r.options.debug&&console.log(`Caret position reset due to "${e?.type}" event`,e))}))}},{key:`recurseButtons`,value:function(e){var t=this;e&&Object.keys(this.buttonElements).forEach((function(n){return t.buttonElements[n].forEach(e)}))}},{key:`destroy`,value:function(){this.options.debug&&console.log(`Destroying simple-keyboard instance: ${this.currentInstanceName}`);var e=this.options.physicalKeyboardHighlightPreventDefault,t=e!==void 0&&e;document.removeEventListener(`keyup`,this.handleKeyUp,t),document.removeEventListener(`keydown`,this.handleKeyDown,t),document.removeEventListener(`mouseup`,this.handleMouseUp),document.removeEventListener(`touchend`,this.handleTouchEnd),document.removeEventListener(`select`,this.handleSelect),this.options.updateCaretOnSelectionChange&&document.removeEventListener(`selectionchange`,this.handleSelectionChange),document.onpointerup=null,document.ontouchend=null,document.ontouchcancel=null,document.onmouseup=null,this.recurseButtons((function(e){e&&=(e.onpointerdown=null,e.onpointerup=null,e.onpointercancel=null,e.ontouchstart=null,e.ontouchend=null,e.ontouchcancel=null,e.onclick=null,e.onmousedown=null,e.onmouseup=null,e.remove(),null)})),this.keyboardDOM.onpointerdown=null,this.keyboardDOM.ontouchstart=null,this.keyboardDOM.onmousedown=null,this.resetRows(),this.candidateBox&&=(this.candidateBox.destroy(),null),this.activeInputElement=null,this.keyboardDOM.removeAttribute(`data-skInstance`),this.keyboardDOM.innerHTML=``,window.SimpleKeyboardInstances[this.currentInstanceName]=null,delete window.SimpleKeyboardInstances[this.currentInstanceName],this.initialized=!1}},{key:`getButtonThemeClasses`,value:function(e){var t=this.options.buttonTheme,n=[];return Array.isArray(t)&&t.forEach((function(t){if(t&&t.class&&typeof t.class==`string`&&t.buttons&&typeof t.buttons==`string`){var r=t.class.split(` `);t.buttons.split(` `).includes(e)&&(n=[].concat(C(n),C(r)))}else console.warn(`Incorrect "buttonTheme". Please check the documentation.`,t)})),n}},{key:`setDOMButtonAttributes`,value:function(e,t){var n=this.options.buttonAttributes;Array.isArray(n)&&n.forEach((function(n){n.attribute&&typeof n.attribute==`string`&&n.value&&typeof n.value==`string`?n.buttons&&typeof n.buttons==`string`?n.buttons.split(` `).includes(e)&&t(n.attribute,n.value):t(n.attribute,n.value):console.warn(`Incorrect "buttonAttributes". Please check the documentation.`,n)}))}},{key:`onTouchDeviceDetected`,value:function(){this.processAutoTouchEvents(),this.disableContextualWindow()}},{key:`disableContextualWindow`,value:function(){window.oncontextmenu=function(e){var t;if((t=e.target.classList)!=null&&t.contains(`hg-button`))return e.preventDefault(),e.stopPropagation(),!1}}},{key:`processAutoTouchEvents`,value:function(){this.options.autoUseTouchEvents&&(this.options.useTouchEvents=!0,this.options.debug&&console.log(`autoUseTouchEvents: Touch device detected, useTouchEvents enabled.`))}},{key:`onInit`,value:function(){this.options.debug&&console.log(`${this.keyboardDOMClass} Initialized`),this.setEventListeners(),typeof this.options.onInit==`function`&&this.options.onInit(this)}},{key:`beforeFirstRender`,value:function(){this.utilities.isTouchDevice()&&this.onTouchDeviceDetected(),typeof this.options.beforeFirstRender==`function`&&this.options.beforeFirstRender(this),this.isFirstKeyboardInstance&&this.utilities.pointerEventsSupported()&&!this.options.useTouchEvents&&!this.options.useMouseEvents&&this.options.debug&&console.log(`Using PointerEvents as it is supported by this browser`),this.options.useTouchEvents&&this.options.debug&&console.log(`useTouchEvents has been enabled. Only touch events will be used.`)}},{key:`beforeRender`,value:function(){typeof this.options.beforeRender==`function`&&this.options.beforeRender(this)}},{key:`onRender`,value:function(){typeof this.options.onRender==`function`&&this.options.onRender(this)}},{key:`onModulesLoaded`,value:function(){typeof this.options.onModulesLoaded==`function`&&this.options.onModulesLoaded(this)}},{key:`loadModules`,value:function(){var e=this;Array.isArray(this.options.modules)&&(this.options.modules.forEach((function(t){var n=e.utilities.isConstructor(t)?new t(e):t(e);n.init&&n.init(e)})),this.keyboardPluginClasses=`modules-loaded`,this.render(),this.onModulesLoaded())}},{key:`getModuleProp`,value:function(e,t){return!!this.modules[e]&&this.modules[e][t]}},{key:`getModulesList`,value:function(){return Object.keys(this.modules)}},{key:`parseRowDOMContainers`,value:function(e,t,n,r){var i=this,a=Array.from(e.children),o=0;return a.length&&n.forEach((function(n,s){var c=r[s];if(!(c&&c>n))return!1;var l=n-o,u=c-o,d=document.createElement(`div`);d.className+=`hg-button-container`;var f=`${i.options.layoutName}-r${t}c${s}`;d.setAttribute(`data-skUID`,f);var p=a.splice(l,u-l+1);o+=u-l,p.forEach((function(e){return d.appendChild(e)})),a.splice(l,0,d),e.innerHTML=``,a.forEach((function(t){return e.appendChild(t)})),i.options.debug&&console.log(`rowDOMContainer`,p,l,u,o+1)})),e}},{key:`render`,value:function(){var e=this;this.resetRows(),this.initialized||this.beforeFirstRender(),this.beforeRender();var t=`hg-layout-${this.options.layoutName}`,n=this.options.layout||{default:["` 1 2 3 4 5 6 7 8 9 0 - = {bksp}",`{tab} q w e r t y u i o p [ ] \\`,`{lock} a s d f g h j k l ; ' {enter}`,`{shift} z x c v b n m , . / {shift}`,`.com @ {space}`],shift:[`~ ! @ # $ % ^ & * ( ) _ + {bksp}`,`{tab} Q W E R T Y U I O P { } |`,`{lock} A S D F G H J K L : " {enter}`,`{shift} Z X C V B N M < > ? {shift}`,`.com @ {space}`]},r=this.options.useTouchEvents||!1,i=r?`hg-touch-events`:``,a=this.options.useMouseEvents||!1,o=this.options.disableRowButtonContainers;this.keyboardDOM.className=this.getKeyboardClassString(this.options.theme,t,this.keyboardPluginClasses,i),this.keyboardDOM.setAttribute(`data-skInstance`,this.currentInstanceName),this.keyboardRowsDOM=document.createElement(`div`),this.keyboardRowsDOM.className=`hg-rows`,n[this.options.layoutName||this.defaultName].forEach((function(t,n){var i=t.split(` `);e.options.excludeFromLayout&&e.options.excludeFromLayout[e.options.layoutName||e.defaultName]&&(i=i.filter((function(t){return e.options.excludeFromLayout&&!e.options.excludeFromLayout[e.options.layoutName||e.defaultName].includes(t)})));var s=document.createElement(`div`);s.className+=`hg-row`;var c=[],l=[];i.forEach((function(t,i){var u,d=!o&&typeof t==`string`&&t.length>1&&t.indexOf(`[`)===0,f=!o&&typeof t==`string`&&t.length>1&&t.indexOf(`]`)===t.length-1;d&&(c.push(i),t=t.replace(/\[/g,``)),f&&(l.push(i),t=t.replace(/\]/g,``));var p=e.utilities.getButtonClass(t),m=e.utilities.getButtonDisplayName(t,e.options.display,e.options.mergeDisplay),h=e.options.useButtonTag?`button`:`div`,g=document.createElement(h);g.className+=`hg-button ${p}`,(u=g.classList).add.apply(u,C(e.getButtonThemeClasses(t))),e.setDOMButtonAttributes(t,(function(e,t){g.setAttribute(e,t)})),e.activeButtonClass=`hg-activeButton`,!e.utilities.pointerEventsSupported()||r||a?r?(g.ontouchstart=function(n){e.handleButtonClicked(t,n),e.handleButtonMouseDown(t,n)},g.ontouchend=function(n){e.handleButtonMouseUp(t,n)},g.ontouchcancel=function(n){e.handleButtonMouseUp(t,n)}):(g.onclick=function(n){e.setMouseHold(!1),typeof e.options.onKeyReleased==`function`||e.options.useMouseEvents&&e.options.clickOnMouseDown||e.handleButtonClicked(t,n)},g.onmousedown=function(n){(typeof e.options.onKeyReleased==`function`||e.options.useMouseEvents&&e.options.clickOnMouseDown)&&!e.isMouseHold&&e.handleButtonClicked(t,n),e.handleButtonMouseDown(t,n)},g.onmouseup=function(n){e.handleButtonMouseUp(t,n)}):(g.onpointerdown=function(n){e.handleButtonClicked(t,n),e.handleButtonMouseDown(t,n)},g.onpointerup=function(n){e.handleButtonMouseUp(t,n)},g.onpointercancel=function(n){e.handleButtonMouseUp(t,n)}),g.setAttribute(`data-skBtn`,t);var _=`${e.options.layoutName}-r${n}b${i}`;g.setAttribute(`data-skBtnUID`,_);var v=document.createElement(`span`);v.innerHTML=m,g.appendChild(v),e.buttonElements[t]||(e.buttonElements[t]=[]),e.buttonElements[t].push(g),s.appendChild(g)})),s=e.parseRowDOMContainers(s,n,c,l),e.keyboardRowsDOM.appendChild(s)})),this.keyboardDOM.appendChild(this.keyboardRowsDOM),this.onRender(),this.initialized||(this.initialized=!0,!this.utilities.pointerEventsSupported()||r||a?r?(document.ontouchend=function(t){return e.handleButtonMouseUp(void 0,t)},document.ontouchcancel=function(t){return e.handleButtonMouseUp(void 0,t)},this.keyboardDOM.ontouchstart=function(t){return e.handleKeyboardContainerMouseDown(t)}):r||(document.onmouseup=function(t){return e.handleButtonMouseUp(void 0,t)},this.keyboardDOM.onmousedown=function(t){return e.handleKeyboardContainerMouseDown(t)}):(document.onpointerup=function(t){return e.handleButtonMouseUp(void 0,t)},this.keyboardDOM.onpointerdown=function(t){return e.handleKeyboardContainerMouseDown(t)}),this.onInit())}}],t&&D(e.prototype,t),n&&D(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,n}(),j=A;return r}()},442:function(t){t.exports=e}},n={};function r(e){var i=n[e];if(i!==void 0)return i.exports;var a=n[e]={exports:{}};return t[e].call(a.exports,a,a.exports,r),a.exports}r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,{a:t}),t},r.d=function(e,t){for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.r=function(e){typeof Symbol<`u`&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:`Module`}),Object.defineProperty(e,"__esModule",{value:!0})};var i={};return function(){r.r(i),r.d(i,{KeyboardReact:function(){return u},default:function(){return d}}),r(981);var e=r(442),t=r(548),n=r.n(t);function a(e){return a=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},a(e)}function o(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function s(e){for(var t=1;t{e?.(t)},[t,e]);let d=(0,y.useCallback)(e=>{if(a.current)return;let t=e.target;if(!t.closest(`[data-vkb="false"]`)){if(t instanceof HTMLInputElement){if(!V0e.has(t.type))return}else if(!(t instanceof HTMLTextAreaElement))return;c.current=t,n(!0),s(`default`),l.current?.setInput?.(c.current.value),setTimeout(()=>{(t.closest(`.bg-zinc-800, .rounded-lg, [data-vkb-group]`)??t).scrollIntoView({behavior:`smooth`,block:`nearest`})},100)}},[]),f=(0,y.useCallback)(()=>{setTimeout(()=>{let e=document.activeElement;e&&(u.current?.contains(e)||e===c.current)||(n(!1),c.current=null)},150)},[]);(0,y.useEffect)(()=>(document.addEventListener(`focusin`,d),document.addEventListener(`focusout`,f),()=>{document.removeEventListener(`focusin`,d),document.removeEventListener(`focusout`,f)}),[d,f]);let p=(0,y.useCallback)(()=>{a.current=!0,i(!0),c.current?.blur(),c.current=null,setTimeout(()=>{n(!1),i(!1),a.current=!1},400)},[]),m=(0,y.useCallback)(e=>{let t=c.current;if(t){if(e===`{shift}`){s(e=>e==="default"?`shift`:`default`);return}if(e===`{lock}`){s(e=>e==="default"?`shift`:`default`);return}if(e===`{close}`){p();return}e===`{bksp}`?U9(t,t.value.slice(0,-1)):e===`{space}`?U9(t,t.value+` `):(U9(t,t.value+e),o===`shift`&&s(`default`)),t.focus(),l.current?.setInput?.(t.value)}},[o,p]);return t?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`fixed inset-0 z-[9998] bg-transparent`,onMouseDown:e=>{e.preventDefault(),e.stopPropagation(),r||p()},onTouchStart:e=>{e.preventDefault(),e.stopPropagation(),r||p()},onClick:e=>{e.preventDefault(),e.stopPropagation()}}),!r&&(0,G.jsx)(`div`,{ref:u,className:`relative z-[9999] shrink-0`,onMouseDown:e=>e.preventDefault(),onTouchStart:e=>{e.target.closest(`.hg-button`)||e.preventDefault()},children:(0,G.jsx)(B0e,{keyboardRef:e=>{l.current=e},layoutName:o,onKeyPress:m,theme:`simple-keyboard vkb-theme`,layout:{default:[`1 2 3 4 5 6 7 8 9 0 {bksp}`,`q w e r t y u i o p`,`{lock} a s d f g h j k l`,`{shift} z x c v b n m . @`,`{space} {close}`],shift:[`! @ # $ % ^ & * ( ) {bksp}`,`Q W E R T Y U I O P`,`{lock} A S D F G H J K L`,`{shift} Z X C V B N M , _`,`{space} {close}`]},display:{"{bksp}":`⌫`,"{close}":`✕ Close`,"{shift}":`⇧`,"{lock}":`⇪`,"{space}":` `}})})]}):null}function U0e(){Ff();let[e,t]=(0,y.useState)(null),[n,r]=(0,y.useState)(null),[i,a]=(0,y.useState)(100),{i18n:o}=U(),s=or(),c=rr(),l=L0e(),{setViewportSuppressed:u}=qd();(0,y.useEffect)(()=>(u(!0),()=>u(!1)),[u]);let{data:d}=K({queryKey:[`settings`],queryFn:Z.getSettings});(0,y.useEffect)(()=>{d?.language&&d.language!==o.language&&o.changeLanguage(d.language)},[d?.language,o]);let{data:f=[]}=K({queryKey:[`spoolbuddy-devices`],queryFn:()=>Od.getDevices(),refetchInterval:3e4}),p=f[0],m=l.deviceOnline||!!p?.online,h=(0,y.useMemo)(()=>({...l,deviceOnline:m}),[l,m]),g=(0,y.useRef)(!1);(0,y.useEffect)(()=>{p&&!g.current&&(a(p.display_brightness),g.current=!0)},[p]),(0,y.useEffect)(()=>{let e=document.documentElement,t=e.classList.contains(`dark`);return e.classList.add(`dark`),()=>{t||e.classList.remove(`dark`)}},[]);let{data:_}=K({queryKey:[`spoolbuddy-update-check`,p?.device_id],queryFn:()=>p?Od.checkDaemonUpdate(p.device_id):Promise.resolve(null),enabled:!!p,refetchInterval:300*1e3,staleTime:0}),v=(0,y.useRef)(null);(0,y.useEffect)(()=>{if(!m){let e=`SpoolBuddy device disconnected`;r({type:`warning`,message:e}),v.current=e}else if(_?.update_available&&_.latest_version){let e=`Update available: v${_.latest_version}`;r({type:`info`,message:e}),v.current=e}else v.current&&=(r(null),null)},[m,_?.update_available,_?.latest_version]);let b=!!(l.matchedSpool||l.unknownTagUid||l.unknownTrayUuid),x=(0,y.useRef)(!1);(0,y.useEffect)(()=>{b&&!x.current&&c.pathname!==`/spoolbuddy`&&s(`/spoolbuddy`),x.current=b},[b,c.pathname,s]);let{data:S=[]}=K({queryKey:[`printers`],queryFn:()=>Z.getPrinters()}),C=Co({queries:S.map(e=>({queryKey:[`printerStatus`,e.id],queryFn:()=>Z.getPrinterStatus(e.id),refetchInterval:1e4,select:e=>({connected:e?.connected})}))}),w=(0,y.useMemo)(()=>S.filter((e,t)=>C[t]?.data?.connected),[S,C]),T=(0,y.useRef)(null),E=(0,y.useRef)(!1),D=(0,y.useRef)(null),O=(0,y.useCallback)(e=>{T.current={x:e.touches[0].clientX,y:e.touches[0].clientY},E.current=!1},[]),k=(0,y.useCallback)(n=>{if(!T.current)return;let r=n.changedTouches[0].clientX-T.current.x,i=n.changedTouches[0].clientY-T.current.y,a=T.current.y;if(T.current=null,E.current=!1,i>=50&&Math.abs(i)>Math.abs(r)&&a<120){N(!0);return}if(w.length<2||Math.abs(r)<50||Math.abs(i)>Math.abs(r))return;let o=w.findIndex(t=>t.id===e);t(w[r<0?(o+1)%w.length:(o-1+w.length)%w.length].id)},[w,e,t]);(0,y.useEffect)(()=>{let e=D.current;if(!e)return;let t=e=>{if(!T.current)return;let t=Math.abs(e.touches[0].clientX-T.current.x),n=Math.abs(e.touches[0].clientY-T.current.y);if(E.current){e.preventDefault();return}t>10&&t>n&&(E.current=!0,e.preventDefault())};return e.addEventListener(`touchmove`,t,{passive:!1}),()=>e.removeEventListener(`touchmove`,t)},[]);let[A,j]=(0,y.useState)(!1),[M,N]=(0,y.useState)(!1);return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{ref:D,"data-spoolbuddy-kiosk":!0,className:`w-screen h-screen bg-bambu-dark text-white flex flex-col overflow-hidden`,style:{...i<100?{filter:`brightness(${i/100})`}:void 0,overscrollBehaviorX:`none`},onTouchStart:O,onTouchEnd:k,children:[(0,G.jsx)(`button`,{onClick:()=>N(!0),className:`w-full h-1.5 bg-bambu-dark-secondary flex justify-center items-center shrink-0 touch-none`,"aria-label":`Open quick menu`,children:(0,G.jsx)(`div`,{className:`w-8 h-0.5 rounded-full bg-zinc-600`})}),(0,G.jsx)(A0e,{selectedPrinterId:e,onPrinterChange:t,deviceOnline:m}),(0,G.jsx)(`main`,{className:`flex-1 overflow-y-auto`,children:(0,G.jsx)(Ir,{context:{selectedPrinterId:e,setSelectedPrinterId:t,sbState:h,setAlert:r,displayBrightness:i,setDisplayBrightness:a}})}),!A&&(0,G.jsx)(N0e,{alert:n}),!A&&(0,G.jsx)(M0e,{}),(0,G.jsx)(H0e,{onVisibilityChange:j})]}),(0,G.jsx)(P0e,{isOpen:M,onClose:()=>N(!1),deviceId:p?.device_id??null,deviceOnline:m})]})}function W9({color:e,isEmpty:t,size:n=32}){return t?(0,G.jsx)(`div`,{className:`rounded-full border-2 border-dashed border-zinc-500 flex items-center justify-center`,style:{width:n,height:n},children:(0,G.jsx)(`div`,{className:`w-2 h-2 rounded-full bg-zinc-600`})}):(0,G.jsxs)(`svg`,{width:n,height:n,viewBox:`0 0 32 32`,children:[(0,G.jsx)(`circle`,{cx:`16`,cy:`16`,r:`14`,fill:e,stroke:`white`,strokeWidth:`1.5`,strokeOpacity:`0.7`}),(0,G.jsx)(`circle`,{cx:`16`,cy:`16`,r:`11`,fill:e,style:{filter:`brightness(0.85)`}})]})}var W0e=`spoolbuddy-default-core-weight`;function G0e(){try{let e=localStorage.getItem(W0e);if(e){let t=parseInt(e,10);if(t>=0&&t<=500)return t}}catch{}return 250}function K0e({spool:e,scaleWeight:t,onClose:n,onSyncWeight:r,onAssignToAms:i,isAssigned:a,onUnassignFromAms:o}){let{t:s}=U(),[c,l]=(0,y.useState)(!1),[u,d]=(0,y.useState)(!1),f=Af(e.rgba),p=e.core_weight&&e.core_weight>0?e.core_weight:G0e(),m=t===null?null:Math.round(Math.max(0,t)),h=m===null?null:Math.round(Math.max(0,m-p)),g=Math.round(e.label_weight||1e3),_=h===null?null:Math.min(100,Math.round(h/g*100)),v=_===null?`#808080`:_>50?`#22c55e`:_>20?`#eab308`:`#ef4444`,b=Math.max(0,(e.label_weight||0)-(e.weight_used||0))+p,x=m===null?null:m-b,S=x===null?null:Math.abs(x)<=50,C=async()=>{if(t!==null){l(!0);try{await Od.updateSpoolWeight(e.id,Math.round(t)),d(!0),r?.(),setTimeout(()=>d(!1),3e3)}catch(e){console.error(`Failed to sync weight:`,e)}finally{l(!1)}}};return(0,G.jsxs)(`div`,{className:`flex flex-col items-center space-y-4 max-w-md`,children:[(0,G.jsxs)(`div`,{className:`flex items-start gap-5`,children:[(0,G.jsxs)(`div`,{className:`relative shrink-0`,children:[(0,G.jsx)(W9,{color:f,isEmpty:!1,size:100}),_!==null&&(0,G.jsxs)(`div`,{className:`absolute -bottom-2 -right-2 px-2 py-0.5 rounded-full text-xs font-bold text-white shadow-lg`,style:{backgroundColor:v},children:[_,`%`]})]}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0 pt-1`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`h3`,{className:`text-lg font-semibold text-zinc-100`,children:e.color_name||`Unknown color`}),(0,G.jsxs)(`span`,{className:`text-xs font-mono text-zinc-500 shrink-0`,children:[`#`,e.id]})]}),(0,G.jsxs)(`p`,{className:`text-sm text-zinc-400`,children:[e.brand,` • `,e.material,e.subtype&&` ${e.subtype}`]}),h!==null&&(0,G.jsxs)(`div`,{className:`mt-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,G.jsxs)(`span`,{className:`text-3xl font-bold font-mono text-zinc-100`,children:[h,`g`]}),(0,G.jsxs)(`span`,{className:`text-sm text-zinc-500`,children:[`/ `,g,`g`]})]}),(0,G.jsx)(`p`,{className:`text-xs text-zinc-500 mt-0.5`,children:s(`spoolbuddy.spool.remaining`,`Remaining`)}),(0,G.jsx)(`div`,{className:`mt-2 max-w-xs`,children:(0,G.jsx)(`div`,{className:`h-2 bg-zinc-700 rounded-full overflow-hidden`,children:(0,G.jsx)(`div`,{className:`h-full rounded-full transition-all duration-500`,style:{width:`${_}%`,backgroundColor:v}})})})]})]})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-x-6 gap-y-2 text-sm bg-zinc-800 rounded-lg p-4 w-full`,children:[(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:s(`spoolbuddy.dashboard.grossWeight`,`Gross weight`)}),(0,G.jsx)(`span`,{className:`font-mono text-zinc-300`,children:m===null?`—`:`${m}g`})]}),(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:s(`spoolbuddy.spool.coreWeight`,`Core`)}),(0,G.jsxs)(`span`,{className:`font-mono text-zinc-300`,children:[p,`g`]})]}),(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:s(`spoolbuddy.dashboard.spoolSize`,`Spool size`)}),(0,G.jsxs)(`span`,{className:`font-mono text-zinc-300`,children:[g,`g`]})]}),(0,G.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:s(`spoolbuddy.spool.scaleWeight`,`Scale`)}),m===null?(0,G.jsx)(`span`,{className:`text-zinc-500`,children:`—`}):(0,G.jsxs)(`span`,{className:`flex items-center gap-1 font-mono ${S?`text-green-500`:`text-yellow-500`}`,children:[m,`g`,S?(0,G.jsx)(fs,{className:`w-3.5 h-3.5`}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Lu,{className:`w-3.5 h-3.5`}),(0,G.jsx)(`button`,{onClick:C,className:`p-1 hover:bg-green-500/20 rounded transition-colors text-green-500`,title:s(`spoolbuddy.dashboard.syncWeight`,`Sync Weight`),children:(0,G.jsx)(Hl,{className:`w-4 h-4`})})]})]})]}),(0,G.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:s(`spoolbuddy.dashboard.tagId`,`Tag`)}),(0,G.jsx)(`span`,{className:`font-mono text-xs text-zinc-400 truncate max-w-[120px]`,title:e.tag_uid||``,children:e.tag_uid?e.tag_uid.slice(-8):`—`})]})]}),(0,G.jsxs)(`div`,{className:`flex gap-2 justify-center`,children:[i&&(0,G.jsx)(`button`,{onClick:a?void 0:i,disabled:!!a,className:`px-5 py-2.5 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 transition-colors min-h-[44px] disabled:opacity-50 disabled:cursor-not-allowed`,children:s(`spoolbuddy.modal.assignToAms`,`Assign to AMS`)}),o&&(0,G.jsxs)(`button`,{onClick:o,className:`px-5 py-2.5 rounded-lg text-sm font-medium bg-red-600/20 text-red-400 hover:bg-red-600/30 transition-colors min-h-[44px]`,children:[(0,G.jsx)(Bu,{className:`w-4 h-4 inline mr-1`}),s(`inventory.unassignSpool`)]}),(0,G.jsx)(`button`,{onClick:C,disabled:t===null||c,className:`px-5 py-2.5 rounded-lg text-sm font-medium transition-colors min-h-[44px] ${u?`bg-green-600/20 text-green-400`:i?`bg-zinc-700 text-zinc-300 hover:bg-zinc-600 disabled:opacity-40 disabled:cursor-not-allowed`:`bg-green-600 text-white hover:bg-green-700 disabled:opacity-40 disabled:cursor-not-allowed`}`,children:c?`...`:u?s(`spoolbuddy.dashboard.weightSynced`,`Synced!`):s(`spoolbuddy.dashboard.syncWeight`,`Sync Weight`)}),n&&(0,G.jsx)(`button`,{onClick:n,className:`px-5 py-2.5 rounded-lg text-sm font-medium bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors min-h-[44px]`,children:s(`spoolbuddy.dashboard.close`,`Close`)})]})]})}function q0e({tagUid:e,scaleWeight:t,coreWeight:n,onLinkSpool:r,onAddToInventory:i,onClose:a}){let{t:o}=U(),s=n??G0e(),c=t===null?null:Math.round(Math.max(0,t)),l=c===null?null:Math.round(Math.max(0,c-s));return(0,G.jsxs)(`div`,{className:`flex flex-col items-center text-center space-y-5`,children:[(0,G.jsx)(`div`,{className:`w-20 h-20 rounded-2xl bg-green-500/15 flex items-center justify-center`,children:(0,G.jsx)(`svg`,{className:`w-10 h-10 text-green-500`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`2`,d:`M7 7h.01M7 3h5c.512 0 1.024.195 1.414.586l7 7a2 2 0 010 2.828l-7 7a2 2 0 01-2.828 0l-7-7A2 2 0 013 12V7a4 4 0 014-4z`})})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`text-lg font-semibold text-zinc-100`,children:o(`spoolbuddy.dashboard.newTag`,`New Tag Detected`)}),(0,G.jsx)(`p`,{className:`text-sm text-zinc-500 font-mono mt-1`,children:e})]}),c!==null&&(0,G.jsxs)(`div`,{className:`text-sm text-zinc-400`,children:[(0,G.jsxs)(`span`,{className:`font-mono font-semibold`,children:[c,`g`]}),` `,o(`spoolbuddy.dashboard.onScale`,`on scale`),l!==null&&l>0&&(0,G.jsxs)(`span`,{className:`text-zinc-500`,children:[` • ~`,l,`g filament`]})]}),(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-2 justify-center`,children:[i&&(0,G.jsx)(`button`,{onClick:i,className:`px-5 py-2.5 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 transition-colors min-h-[44px]`,children:o(`spoolbuddy.modal.addToInventory`,`Add to Inventory`)}),r&&(0,G.jsxs)(`button`,{onClick:r,className:`px-5 py-2.5 rounded-lg text-sm font-medium bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors min-h-[44px]`,children:[(0,G.jsx)(`svg`,{className:`w-4 h-4 inline-block mr-1.5 -mt-0.5`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`2`,d:`M13.828 10.172a4 4 0 00-5.656 0l-4 4a4 4 0 105.656 5.656l1.102-1.101m-.758-4.899a4 4 0 005.656 0l4-4a4 4 0 00-5.656-5.656l-1.1 1.1`})}),o(`inventory.assignSpool`,`Assign Spool`)]}),a&&(0,G.jsx)(`button`,{onClick:a,className:`px-5 py-2.5 rounded-lg text-sm font-medium bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors min-h-[44px]`,children:o(`spoolbuddy.dashboard.close`,`Close`)})]})]})}function J0e(e){return e?`#${e.slice(0,6)}`:`#808080`}function Y0e(e){return!e.tray_type||e.tray_type===``}function X0e(e){if(e.tray_type)return null;if(e.exists===!0)return`reset`;if(e.exists===!1)return`physical`;let t=e.state??null;return t===9||t===10?`physical`:`reset`}function Z0e(e){return e<=3?`AMS ${String.fromCharCode(65+e)}`:e>=128&&e<=135?`AMS HT ${String.fromCharCode(65+e-128)}`:`AMS ${e}`}function Q0e({className:e}){return(0,G.jsx)(`svg`,{className:e,viewBox:`0 0 36 54`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:(0,G.jsx)(`path`,{d:`M17.8131 0.00538C18.4463 -0.15091 20.3648 3.14642 20.8264 3.84781C25.4187 10.816 35.3089 26.9368 35.9383 34.8694C37.4182 53.5822 11.882 61.3357 2.53721 45.3789C-1.73471 38.0791 0.016 32.2049 3.178 25.0232C6.99221 16.3662 12.6411 7.90372 17.8131 0.00538ZM18.3738 7.24807L17.5881 7.48441C14.4452 12.9431 10.917 18.2341 8.19369 23.9368C4.6808 31.29 1.18317 38.5479 7.69403 45.5657C17.3058 55.9228 34.9847 46.8808 31.4604 32.8681C29.2558 24.0969 22.4207 15.2913 18.3776 7.24807H18.3738Z`,fill:`#C3C2C1`})})}function $0e({className:e}){return(0,G.jsxs)(`svg`,{className:e,viewBox:`0 0 35 53`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:[(0,G.jsx)(`path`,{d:`M17.3165 0.0038C17.932 -0.14959 19.7971 3.08645 20.2458 3.77481C24.7103 10.6135 34.3251 26.4346 34.937 34.2198C36.3757 52.5848 11.5505 60.1942 2.46584 44.534C-1.68714 37.3735 0.0148 31.6085 3.08879 24.5603C6.79681 16.0605 12.2884 7.75907 17.3165 0.0038ZM17.8615 7.11561L17.0977 7.34755C14.0423 12.7048 10.6124 17.8974 7.96483 23.4941C4.54975 30.7107 1.14949 37.8337 7.47908 44.721C16.8233 54.8856 34.01 46.0117 30.5838 32.2595C28.4405 23.6512 21.7957 15.0093 17.8652 7.11561H17.8615Z`,fill:`#C3C2C1`}),(0,G.jsx)(`path`,{d:`M5.03547 30.112C9.64453 30.4936 11.632 35.7985 16.4154 35.791C19.6339 35.7873 20.2161 33.2283 22.3853 31.6197C31.6776 24.7286 33.5835 37.4894 27.9881 44.4254C18.1878 56.5653 -1.16063 44.6013 5.03917 30.1158L5.03547 30.112Z`,fill:`#1F8FEB`})]})}function e2e({className:e}){return(0,G.jsxs)(`svg`,{className:e,viewBox:`0 0 36 54`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:[(0,G.jsx)(`path`,{d:`M17.9625 4.48059L4.77216 26.3154L2.08228 40.2175L10.0224 50.8414H23.1594L33.3246 42.1693V30.2455L17.9625 4.48059Z`,fill:`#1F8FEB`}),(0,G.jsx)(`path`,{d:`M17.7948 0.00538C18.4273 -0.15091 20.3438 3.14642 20.8048 3.84781C25.3921 10.816 35.2715 26.9368 35.9001 34.8694C37.3784 53.5822 11.8702 61.3357 2.53562 45.3789C-1.73163 38.0829 0.0134 32.2087 3.1757 25.027C6.98574 16.3662 12.6284 7.90372 17.7948 0.00538ZM18.3549 7.24807L17.57 7.48441C14.4306 12.9431 10.9063 18.2341 8.1859 23.9368C4.67686 31.29 1.18305 38.5479 7.68679 45.5657C17.2881 55.9228 34.9476 46.8808 31.4271 32.8681C29.2249 24.0969 22.3974 15.2913 18.3587 7.24807H18.3549Z`,fill:`#C3C2C1`})]})}function t2e({className:e}){return(0,G.jsxs)(`svg`,{className:e,viewBox:`0 0 12 20`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:[(0,G.jsx)(`path`,{d:`M6 0.5C4.6 0.5 3.5 1.6 3.5 3V12.1C2.6 12.8 2 13.9 2 15C2 17.2 3.8 19 6 19C8.2 19 10 17.2 10 15C10 13.9 9.4 12.8 8.5 12.1V3C8.5 1.6 7.4 0.5 6 0.5Z`,stroke:`#C3C2C1`,strokeWidth:`1`,fill:`none`}),(0,G.jsx)(`circle`,{cx:`6`,cy:`15`,r:`2.5`,stroke:`#C3C2C1`,strokeWidth:`1`,fill:`none`})]})}function n2e({className:e}){return(0,G.jsxs)(`svg`,{className:e,viewBox:`0 0 12 20`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:[(0,G.jsx)(`rect`,{x:`4.5`,y:`8`,width:`3`,height:`4.5`,fill:`#d4a017`,rx:`0.5`}),(0,G.jsx)(`circle`,{cx:`6`,cy:`15`,r:`2`,fill:`#d4a017`}),(0,G.jsx)(`path`,{d:`M6 0.5C4.6 0.5 3.5 1.6 3.5 3V12.1C2.6 12.8 2 13.9 2 15C2 17.2 3.8 19 6 19C8.2 19 10 17.2 10 15C10 13.9 9.4 12.8 8.5 12.1V3C8.5 1.6 7.4 0.5 6 0.5Z`,stroke:`#C3C2C1`,strokeWidth:`1`,fill:`none`})]})}function r2e({className:e}){return(0,G.jsxs)(`svg`,{className:e,viewBox:`0 0 12 20`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:[(0,G.jsx)(`rect`,{x:`4.5`,y:`3`,width:`3`,height:`9.5`,fill:`#c62828`,rx:`0.5`}),(0,G.jsx)(`circle`,{cx:`6`,cy:`15`,r:`2`,fill:`#c62828`}),(0,G.jsx)(`path`,{d:`M6 0.5C4.6 0.5 3.5 1.6 3.5 3V12.1C2.6 12.8 2 13.9 2 15C2 17.2 3.8 19 6 19C8.2 19 10 17.2 10 15C10 13.9 9.4 12.8 8.5 12.1V3C8.5 1.6 7.4 0.5 6 0.5Z`,stroke:`#C3C2C1`,strokeWidth:`1`,fill:`none`})]})}function i2e({humidity:e,goodThreshold:t=40,fairThreshold:n=60}){let r,i;return e<=t?(r=`#22a352`,i=Q0e):e<=n?(r=`#d4a017`,i=$0e):(r=`#c62828`,i=e2e),(0,G.jsxs)(`div`,{className:`flex items-center gap-0.5`,children:[(0,G.jsx)(i,{className:`w-3 h-3.5`}),(0,G.jsxs)(`span`,{className:`font-medium tabular-nums text-xs`,style:{color:r},children:[e,`%`]})]})}function a2e({temp:e,goodThreshold:t=28,fairThreshold:n=35}){let r,i;return e<=t?(r=`#22a352`,i=t2e):e<=n?(r=`#d4a017`,i=n2e):(r=`#c62828`,i=r2e),(0,G.jsxs)(`div`,{className:`flex items-center gap-0.5`,children:[(0,G.jsx)(i,{className:`w-3 h-3.5`}),(0,G.jsxs)(`span`,{className:`font-medium tabular-nums text-xs`,style:{color:r},children:[e,`°C`]})]})}function G9({side:e}){return(0,G.jsx)(`span`,{className:`inline-flex items-center justify-center w-4 h-4 text-[9px] font-bold rounded`,style:{backgroundColor:`#1a4d2e`,color:`#00ae42`},children:e})}function o2e({tray:e,slotIndex:t,isActive:n,fillOverride:r,spoolmanFill:i,onClick:a}){let o=Y0e(e),s=X0e(e),c=J0e(e.tray_color),l=e.remain!==null&&e.remain!==void 0&&e.remain>=0?e.remain:null,u=i??(r===0&&l!==null&&l>0?null:r)??l;return(0,G.jsxs)(`div`,{className:`relative flex flex-col items-center p-2.5 rounded-lg transition-all ${n?`ring-2 ring-bambu-green`:``} ${a?`cursor-pointer hover:bg-white/5`:``}`,onClick:a,title:a?`AMS Slot ${t+1}`:void 0,children:[(0,G.jsxs)(`div`,{className:`relative w-16 h-16 mb-1`,children:[o?(0,G.jsx)(`div`,{className:`w-full h-full rounded-full border-2 border-dashed border-gray-500 flex items-center justify-center`,children:(0,G.jsx)(`div`,{className:`w-3 h-3 rounded-full bg-gray-600`})}):(0,G.jsxs)(`svg`,{viewBox:`0 0 56 56`,className:`w-full h-full`,children:[(0,G.jsx)(`circle`,{cx:`28`,cy:`28`,r:`26`,fill:c}),(0,G.jsx)(`circle`,{cx:`28`,cy:`28`,r:`20`,fill:c,style:{filter:`brightness(0.85)`}}),(0,G.jsx)(`ellipse`,{cx:`20`,cy:`20`,rx:`6`,ry:`4`,fill:`white`,opacity:`0.3`}),(0,G.jsx)(`circle`,{cx:`28`,cy:`28`,r:`8`,fill:`#2d2d2d`}),(0,G.jsx)(`circle`,{cx:`28`,cy:`28`,r:`5`,fill:`#1a1a1a`})]}),n&&(0,G.jsx)(`div`,{className:`absolute -bottom-1 left-1/2 -translate-x-1/2 w-2.5 h-2.5 bg-bambu-green rounded-full`})]}),(0,G.jsx)(`span`,{className:`text-sm text-white/70 truncate max-w-full`,title:s===`reset`?`Spool loaded — slot not configured`:void 0,children:o?s===`reset`?`?`:`Empty`:e.tray_type||`Unknown`}),!o&&u!==null&&u>=0&&(0,G.jsx)(`div`,{className:`w-full h-1 bg-bambu-dark-tertiary rounded-full overflow-hidden mt-1`,children:(0,G.jsx)(`div`,{className:`h-full rounded-full transition-all`,style:{width:`${u}%`,backgroundColor:Np(u)}})}),(0,G.jsx)(`span`,{className:`absolute top-1 right-1 text-xs text-white/30`,children:t+1})]})}function s2e({unit:e,activeSlot:t,onConfigureSlot:n,isDualNozzle:r,nozzleSide:i,thresholds:a,fillOverrides:o,spoolmanFillOverrides:s}){let c=e.tray||[],l=e.is_ams_ht,u=l?1:4;return(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg p-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,G.jsx)(`span`,{className:`text-white font-medium text-base`,children:Z0e(e.id)}),r&&i&&(0,G.jsx)(G9,{side:i})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.temp!=null&&(0,G.jsx)(a2e,{temp:e.temp,goodThreshold:a?.tempGood,fairThreshold:a?.tempFair}),e.humidity!=null&&(0,G.jsx)(i2e,{humidity:e.humidity,goodThreshold:a?.humidityGood,fairThreshold:a?.humidityFair})]})]}),(0,G.jsx)(`div`,{className:`grid ${l?`grid-cols-1 max-w-[100px] mx-auto`:`grid-cols-4`} gap-2`,children:Array.from({length:u}).map((r,i)=>{let a=c[i]||{id:i,tray_color:null,tray_type:``,tray_sub_brands:null,tray_id_name:null,tray_info_idx:null,remain:-1,k:null,cali_idx:null,tag_uid:null,tray_uuid:null,nozzle_temp_min:null,nozzle_temp_max:null};return(0,G.jsx)(o2e,{tray:a,slotIndex:i,isActive:t===i,fillOverride:o?.[`${e.id}-${i}`]??null,spoolmanFill:s?.[`${e.id}-${i}`]??null,onClick:n?()=>n(e.id,i,Y0e(a)?null:a):void 0},i)})})]})}function K9(e){return e<=3?`AMS ${String.fromCharCode(65+e)}`:e>=128&&e<=135?`AMS HT ${String.fromCharCode(65+e-128)}`:`AMS ${e}`}function q9(e){return!e.tray_type||e.tray_type===``}function c2e(e){return e?`#${e.slice(0,6)}`:`#808080`}var J9=e=>(e??``).trim().toUpperCase();function l2e(e,t){let n=J9(e),r=J9(t);return!n||!r?`none`:n===r?`exact`:r.includes(n)||n.includes(r)?`partial`:`none`}function u2e(e,t){let n=J9(e),r=J9(t);return!n||!r?!1:n===r}function Y9({isOpen:e,onClose:t,spool:n,printerId:r,spoolmanMode:i=!1}){let{t:a}=U(),o=co(),[s,c]=(0,y.useState)(null),[l,u]=(0,y.useState)(null),[d,f]=(0,y.useState)(!1),[p,m]=(0,y.useState)(null),[h,g]=(0,y.useState)(null);(0,y.useEffect)(()=>{e&&(c(null),u(null),f(!1),m(null),g(null))},[e]);let _=(0,y.useCallback)(e=>{e.key===`Escape`&&t()},[t]);(0,y.useEffect)(()=>(e&&document.addEventListener(`keydown`,_),()=>document.removeEventListener(`keydown`,_)),[e,_]);let{data:v}=K({queryKey:[`printerStatus`,r],queryFn:()=>Z.getPrinterStatus(r),enabled:e&&r!==null,refetchInterval:5e3}),{data:b}=K({queryKey:[`printer`,r],queryFn:()=>Z.getPrinter(r),enabled:e&&r!==null}),{data:x}=K({queryKey:[`settings`],queryFn:()=>Z.getSettings(),enabled:e,staleTime:300*1e3}),{data:S}=K({queryKey:[`spool-assignments`,r],queryFn:()=>Z.getAssignments(r),enabled:e&&r!==null,staleTime:30*1e3}),{data:C=[]}=K({queryKey:[`spoolman-slot-assignments`,r],queryFn:()=>Z.getSpoolmanSlotAssignments(r??void 0),enabled:e&&!!i&&r!==null,staleTime:30*1e3}),w=i?C.find(e=>e.spoolman_spool_id===n.id):void 0,T=(0,y.useMemo)(()=>{let e={};if(!S)return e;for(let t of S){let n=t.spool;if(n&&n.label_weight>0&&n.weight_used!=null){let r=Math.round(Math.max(0,n.label_weight-n.weight_used)/n.label_weight*100);e[`${t.ams_id}-${t.tray_id}`]=r}}return e},[S]),E=x?{humidityGood:Number(x.ams_humidity_good)||40,humidityFair:Number(x.ams_humidity_fair)||60,tempGood:Number(x.ams_temp_good)||28,tempFair:Number(x.ams_temp_fair)||35}:void 0,D=v?.connected??!1,O=(0,y.useMemo)(()=>v?.ams??[],[v?.ams]),k=(0,y.useMemo)(()=>O.filter(e=>!e.is_ams_ht),[O]),A=(0,y.useMemo)(()=>O.filter(e=>e.is_ams_ht),[O]),j=(0,y.useMemo)(()=>[...v?.vt_tray??[]].sort((e,t)=>(e.id??254)-(t.id??254)),[v?.vt_tray]),M=b?.nozzle_count===2||v?.temperatures?.nozzle_2!==void 0,N=(0,y.useRef)({});(0,y.useEffect)(()=>{v?.ams_extruder_map&&Object.keys(v.ams_extruder_map).length>0&&(N.current=v.ams_extruder_map)},[v?.ams_extruder_map]);let P=v?.ams_extruder_map&&Object.keys(v.ams_extruder_map).length>0?v.ams_extruder_map:N.current,F=v?.fila_switch?.installed===!0,I=(0,y.useCallback)(e=>{if(!M)return null;let t=P[String(e)];return t===void 0?F?null:(e>=128?e-128:e)===1?`L`:`R`:t===1?`L`:`R`},[M,P,F]),L=q({mutationFn:async({amsId:e,trayId:t})=>{if(!r)throw Error(`No printer selected`);return i?await Z.assignSpoolmanSlot({spoolman_spool_id:n.id,printer_id:r,ams_id:e,tray_id:t}):await Z.assignSpool({spool_id:n.id,printer_id:r,ams_id:e,tray_id:t})},onSuccess:e=>{u(`success`);let n=e&&`pending_config`in e&&e.pending_config;c(n?a(`spoolbuddy.modal.assignPendingInsert`,`Assigned. Slot will configure when you insert the spool.`):a(`spoolbuddy.modal.assignSuccess`,`Assigned!`)),o.invalidateQueries({queryKey:[`slotPresets`]}),o.invalidateQueries({queryKey:[`spoolman-slot-assignments`]}),o.invalidateQueries({queryKey:[`spoolman-slot-assignments-all`]}),setTimeout(()=>t(),n?2500:1500)},onError:e=>{u(`error`),c(e instanceof Error?e.message:a(`spoolbuddy.modal.assignError`,`Failed to assign spool.`))}}),R=L.isPending,z=(0,y.useCallback)((e,t)=>{if(e===254||e===255){let n=e===254?254:254+t;return j.find(e=>(e.id??254)===n)||null}return O.find(t=>t.id===e)?.tray?.find(e=>e.id===t)||null},[O,j]),B=(0,y.useCallback)((e,t)=>e<=3?`${K9(e)} ${a(`ams.slot`,`Slot`)} ${t+1}`:e>=128&&e<=135?K9(e):e===254?a(`printers.extL`,`Ext-L`):M?a(`printers.extR`,`Ext-R`):a(`printers.ext`,`Ext`),[a,M]),V=(0,y.useCallback)((e,t)=>{u(`info`),c(a(`spoolbuddy.modal.assigning`,`Configuring slot...`)),L.mutate({amsId:e,trayId:t})},[L,a]),ee=(0,y.useCallback)((e,t)=>{if(!R){if(!x?.disable_filament_warnings){let r=z(e,t);if(r&&!q9(r)){let i=r.tray_sub_brands||r.tray_type||``,a=l2e(n.material,i),o=n.slicer_filament_name||n.slicer_filament,s=r.tray_type||``,c=u2e(o,s);if(a!==`exact`){let r;r=a===`none`&&!c?`material_profile`:a===`partial`&&!c?`partial_profile`:a===`none`?`material`:`partial`;let l=B(e,t);g({amsId:e,trayId:t}),m({type:r,spoolMaterial:n.material||``,trayMaterial:i||``,spoolProfile:o||void 0,trayProfile:s||void 0,location:l}),f(!0);return}}}V(e,t)}},[R,x?.disable_filament_warnings,n,z,B,V]),te=(0,y.useCallback)(()=>{h&&(f(!1),m(null),V(h.amsId,h.trayId),g(null))},[h,V]),ne=(0,y.useMemo)(()=>{let e=[];for(let t of A){let n=t.tray?.[0]||{id:0,tray_color:null,tray_type:``,tray_sub_brands:null,tray_id_name:null,tray_info_idx:null,remain:-1,k:null,cali_idx:null,tag_uid:null,tray_uuid:null,nozzle_temp_min:null,nozzle_temp_max:null},r=T[`${t.id}-0`]??null,i=n.remain!=null&&n.remain>=0?n.remain:null,a=r===0&&i!==null&&i>0?null:r;e.push({key:`ht-${t.id}`,label:K9(t.id),amsId:t.id,trayId:0,tray:n,isEmpty:q9(n),nozzleSide:I(t.id),effectiveFill:a??i})}for(let t of j){let n=t.id??254,r=n-254,i=T[`255-${r}`]??null,o=t.remain!=null&&t.remain>=0?t.remain:null,s=i===0&&o!==null&&o>0?null:i;e.push({key:`ext-${n}`,label:M?n===254?a(`printers.extL`,`Ext-L`):a(`printers.extR`,`Ext-R`):a(`printers.ext`,`Ext`),amsId:255,trayId:r,tray:t,isEmpty:q9(t),nozzleSide:M?n===254?`L`:`R`:null,effectiveFill:s??o})}return e},[A,j,M,a,I,T]);return e?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`fixed inset-0 z-[60] bg-bambu-dark flex flex-col`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-5 py-3 border-b border-zinc-800 shrink-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0`,children:[(0,G.jsx)(`div`,{className:`w-7 h-7 rounded-full shrink-0`,style:Mf(n.rgba)}),(0,G.jsx)(`div`,{className:`min-w-0`,children:(0,G.jsxs)(`h2`,{className:`text-sm font-semibold text-zinc-100 truncate`,children:[a(`spoolbuddy.modal.assignToAmsTitle`,`Assign to AMS`),(0,G.jsxs)(`span`,{className:`font-normal text-zinc-500 ml-2`,children:[n.color_name||`Unknown`,` • `,n.brand,` `,n.material,n.subtype&&` ${n.subtype}`]}),(0,G.jsxs)(`span`,{className:`text-[10px] font-mono text-zinc-500 ml-2 shrink-0`,children:[`#`,n.id]})]})})]}),(0,G.jsx)(`button`,{onClick:t,disabled:R,className:`p-2 rounded-lg text-zinc-500 hover:text-zinc-300 hover:bg-zinc-800 transition-colors shrink-0 disabled:opacity-50`,children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]}),s&&(0,G.jsxs)(`div`,{className:`mx-5 mt-3 p-3 rounded-lg flex items-center gap-3 border shrink-0 ${l===`info`?`bg-blue-500/10 border-blue-500/40`:l===`success`?`bg-green-500/10 border-green-500/40`:`bg-red-500/10 border-red-500/40`}`,children:[l===`info`&&(0,G.jsx)(Y,{className:`w-4 h-4 text-blue-400 animate-spin shrink-0`}),l===`success`&&(0,G.jsx)(xs,{className:`w-4 h-4 text-green-400 shrink-0`}),l===`error`&&(0,G.jsx)(Ds,{className:`w-4 h-4 text-red-400 shrink-0`}),(0,G.jsx)(`span`,{className:`text-sm ${l===`info`?`text-blue-300`:l===`success`?`text-green-300`:`text-red-300`}`,children:s})]}),(0,G.jsx)(`div`,{className:`flex-1 flex flex-col gap-3 p-4 min-h-0 overflow-y-auto`,children:!D&&r?(0,G.jsx)(`div`,{className:`flex-1 flex items-center justify-center`,children:(0,G.jsx)(`div`,{className:`text-center text-white/50`,children:(0,G.jsx)(`p`,{className:`text-lg mb-2`,children:a(`spoolbuddy.ams.printerDisconnected`,`Printer disconnected`)})})}):O.length===0&&j.length===0?(0,G.jsx)(`div`,{className:`flex-1 flex items-center justify-center`,children:(0,G.jsxs)(`div`,{className:`text-center text-white/50`,children:[(0,G.jsx)(Jc,{className:`w-12 h-12 mx-auto mb-3 opacity-50`}),(0,G.jsx)(`p`,{className:`text-lg mb-2`,children:a(`spoolbuddy.ams.noData`,`No AMS detected`)}),(0,G.jsx)(`p`,{className:`text-sm`,children:a(`spoolbuddy.ams.connectAms`,`Connect an AMS to see filament slots`)})]})}):(0,G.jsxs)(G.Fragment,{children:[k.length>0&&(0,G.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-3 flex-1 min-h-0`,children:k.map(e=>(0,G.jsx)(s2e,{unit:e,activeSlot:w?.ams_id===e.id?w.tray_id??null:null,onConfigureSlot:(t,n)=>ee(e.id,n),isDualNozzle:M,nozzleSide:I(e.id),thresholds:E,fillOverrides:T},e.id))}),ne.length>0&&(0,G.jsx)(`div`,{className:`flex gap-2 shrink-0`,children:ne.map(({key:e,label:t,amsId:n,trayId:r,tray:i,isEmpty:a,nozzleSide:o,effectiveFill:s})=>{let c=c2e(i.tray_color);return(0,G.jsxs)(`div`,{onClick:()=>ee(n,r),className:`bg-bambu-dark-secondary rounded-lg px-3 py-2 cursor-pointer hover:bg-bambu-dark-secondary/80 transition-all flex items-center gap-2 ${w&&w.ams_id===n&&w.tray_id===r?`ring-2 ring-bambu-green`:``} ${R?`opacity-50 pointer-events-none`:``}`,children:[(0,G.jsx)(`div`,{className:`relative w-10 h-10 shrink-0`,children:a?(0,G.jsx)(`div`,{className:`w-full h-full rounded-full border-2 border-dashed border-gray-500 flex items-center justify-center`,children:(0,G.jsx)(`div`,{className:`w-1.5 h-1.5 rounded-full bg-gray-600`})}):(0,G.jsxs)(`svg`,{viewBox:`0 0 56 56`,className:`w-full h-full`,children:[(0,G.jsx)(`circle`,{cx:`28`,cy:`28`,r:`26`,fill:c}),(0,G.jsx)(`circle`,{cx:`28`,cy:`28`,r:`20`,fill:c,style:{filter:`brightness(0.85)`}}),(0,G.jsx)(`ellipse`,{cx:`20`,cy:`20`,rx:`6`,ry:`4`,fill:`white`,opacity:`0.3`}),(0,G.jsx)(`circle`,{cx:`28`,cy:`28`,r:`8`,fill:`#2d2d2d`}),(0,G.jsx)(`circle`,{cx:`28`,cy:`28`,r:`5`,fill:`#1a1a1a`})]})}),(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(`span`,{className:`text-xs text-white/50 font-medium`,children:t}),o&&(0,G.jsx)(G9,{side:o})]}),(0,G.jsx)(`div`,{className:`text-sm text-white/80 truncate`,children:a?`Empty`:i.tray_type||`?`})]}),!a&&s!=null&&s>=0&&(0,G.jsx)(`div`,{className:`w-1.5 h-8 bg-bambu-dark-tertiary rounded-full overflow-hidden shrink-0 flex flex-col-reverse`,children:(0,G.jsx)(`div`,{className:`w-full rounded-full`,style:{height:`${s}%`,backgroundColor:Np(s)}})})]},e)})})]})}),(0,G.jsx)(`div`,{className:`flex justify-end gap-3 px-5 py-3 border-t border-zinc-800 shrink-0`,children:(0,G.jsx)(`button`,{onClick:t,disabled:R,className:`px-5 py-2.5 rounded-lg text-sm font-medium bg-zinc-800 text-zinc-300 hover:bg-zinc-700 transition-colors min-h-[44px] disabled:opacity-50`,children:l===`success`?a(`spoolbuddy.dashboard.close`,`Close`):a(`spoolbuddy.modal.cancel`,`Cancel`)})})]}),d&&p&&(()=>{let e=``;return p.type===`material`?e=a(`inventory.assignMismatchMessage`,{spoolMaterial:p.spoolMaterial,trayMaterial:p.trayMaterial,location:p.location}):p.type===`partial`?e=a(`inventory.assignPartialMismatchMessage`,{spoolMaterial:p.spoolMaterial,trayMaterial:p.trayMaterial,location:p.location}):p.type===`material_profile`?e=`${a(`inventory.assignMismatchMessage`,{spoolMaterial:p.spoolMaterial,trayMaterial:p.trayMaterial,location:p.location})}\n\n${a(`inventory.assignProfileMismatchMessage`,{spoolProfile:p.spoolProfile||a(`common.unknown`),trayProfile:p.trayProfile||a(`common.unknown`),location:p.location})}`:p.type===`partial_profile`&&(e=`${a(`inventory.assignPartialMismatchMessage`,{spoolMaterial:p.spoolMaterial,trayMaterial:p.trayMaterial,location:p.location})}\n\n${a(`inventory.assignProfileMismatchMessage`,{spoolProfile:p.spoolProfile||a(`common.unknown`),trayProfile:p.trayProfile||a(`common.unknown`),location:p.location})}`),e=`${e}\n\n${a(`inventory.assignReconfigureNote`)}`,(0,G.jsx)(of,{title:a(`inventory.assignMismatchTitle`),message:e,confirmText:a(`inventory.assignMismatchConfirm`),variant:`warning`,isLoading:L.isPending,onConfirm:te,onCancel:()=>{L.isPending||(f(!1),g(null),m(null))}})})()]}):null}function d2e({isOpen:e,onClose:t,tagId:n,untaggedSpools:r,onLink:i}){let{t:a}=U(),[o,s]=(0,y.useState)(null),c=(0,y.useCallback)(()=>{s(null),t()},[t]),l=(0,y.useCallback)(e=>{e.key===`Escape`&&c()},[c]);return(0,y.useEffect)(()=>(e&&(document.addEventListener(`keydown`,l),document.body.style.overflow=`hidden`),()=>{document.removeEventListener(`keydown`,l),document.body.style.overflow=``}),[e,l]),e?(0,G.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/70 animate-fade-in`,onClick:c,children:(0,G.jsxs)(`div`,{className:`bg-zinc-800 rounded-xl shadow-2xl w-full max-w-lg mx-4 animate-slide-up`,onClick:e=>e.stopPropagation(),children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-5 py-4 border-b border-zinc-700`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h2`,{className:`text-base font-semibold text-zinc-100`,children:a(`spoolbuddy.dashboard.linkTagTitle`,`Link Tag to Spool`)}),(0,G.jsx)(`p`,{className:`text-sm text-zinc-500 font-mono`,children:n})]}),(0,G.jsx)(`button`,{onClick:c,className:`p-2 rounded-lg text-zinc-500 hover:text-zinc-300 hover:bg-zinc-700 transition-colors`,children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]}),(0,G.jsxs)(`div`,{className:`px-5 py-4 space-y-3 max-h-[400px] overflow-y-auto`,children:[(0,G.jsx)(`p`,{className:`text-sm text-zinc-400`,children:a(`spoolbuddy.dashboard.selectSpool`,`Select a spool to link this tag to:`)}),r.length===0?(0,G.jsx)(`div`,{className:`text-center py-8 text-zinc-500`,children:a(`spoolbuddy.dashboard.noUntagged`,`No spools without tags found`)}):(0,G.jsx)(`div`,{className:`space-y-2`,children:r.map(e=>(0,G.jsxs)(`button`,{type:`button`,onClick:()=>s(e),className:`w-full flex items-center gap-3 p-3 rounded-lg border-2 transition-all text-left ${o?.id===e.id?`border-green-500 bg-green-500/10`:`border-zinc-700 hover:border-green-500/50 hover:bg-zinc-700/50`}`,children:[(0,G.jsx)(W9,{color:Af(e.rgba),isEmpty:!1,size:40}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`div`,{className:`font-medium text-zinc-100 truncate`,children:e.color_name||`Unknown color`}),(0,G.jsxs)(`span`,{className:`text-[10px] font-mono text-zinc-500 shrink-0`,children:[`#`,e.id]})]}),(0,G.jsxs)(`div`,{className:`text-sm text-zinc-400 truncate`,children:[e.brand,` • `,e.material,e.subtype&&` ${e.subtype}`]})]}),(0,G.jsxs)(`div`,{className:`text-sm font-mono text-zinc-500`,children:[Math.max(0,e.label_weight-e.weight_used),`g`]})]},e.id))})]}),(0,G.jsxs)(`div`,{className:`flex justify-end gap-2 px-5 py-4 border-t border-zinc-700`,children:[(0,G.jsx)(`button`,{onClick:c,className:`px-4 py-2.5 rounded-lg text-sm font-medium bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors min-h-[44px]`,children:a(`common.cancel`,`Cancel`)}),(0,G.jsx)(`button`,{onClick:()=>{o&&(i(o),s(null))},disabled:!o,className:`px-4 py-2.5 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 disabled:opacity-40 disabled:cursor-not-allowed transition-colors min-h-[44px]`,children:a(`spoolbuddy.dashboard.linkTag`,`Link Tag`)})]})]})}):null}function f2e(e){return e?e.replace(/[^0-9a-f]/gi,``).toUpperCase():``}function p2e(e,t){let n=f2e(e),r=f2e(t);return!n||!r?!1:n===r?!0:n.endsWith(r)||r.endsWith(n)}var m2e=[`#00AE42`,`#FF6B35`,`#3B82F6`,`#EF4444`,`#A855F7`,`#FBBF24`,`#14B8A6`,`#EC4899`,`#F97316`,`#22C55E`];function h2e(){let{t:e}=U(),[t,n]=(0,y.useState)(0);(0,y.useEffect)(()=>{let e=setInterval(()=>{n(e=>(e+1)%m2e.length)},5e3);return()=>clearInterval(e)},[]);let r=m2e[t];return(0,G.jsxs)(`div`,{className:`flex flex-col items-center text-center`,children:[(0,G.jsxs)(`div`,{className:`relative mb-6 flex items-center justify-center`,style:{width:160,height:160},children:[(0,G.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center pointer-events-none`,children:[0,1].map(e=>(0,G.jsx)(`div`,{className:`absolute rounded-full border spoolbuddy-optimized-ping`,style:{width:80,height:80,borderColor:`${r}4D`,transition:`border-color 140ms linear`,animationDelay:`${e*.8}s`}},e))}),(0,G.jsxs)(`div`,{className:`relative overflow-hidden rounded-full`,children:[(0,G.jsx)(`div`,{className:`absolute inset-0 rounded-full opacity-30 spoolbuddy-spool-glow`,style:{background:`radial-gradient(circle, ${r} 0%, transparent 70%)`}}),(0,G.jsx)(`div`,{className:`relative`,style:{transition:`opacity 140ms linear`},children:(0,G.jsx)(W9,{color:r,isEmpty:!1,size:100})})]})]}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`p`,{className:`text-xl font-medium text-zinc-300`,children:e(`spoolbuddy.dashboard.readyToScan`,`Ready to scan`)}),(0,G.jsx)(`p`,{className:`text-sm text-zinc-500`,children:e(`spoolbuddy.dashboard.idleMessage`,`Place a spool on the scale to identify it`)})]}),(0,G.jsxs)(`div`,{className:`mt-6 flex items-center gap-2 text-sm text-zinc-600`,children:[(0,G.jsx)(`svg`,{className:`w-4 h-4`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`2`,d:`M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z`})}),(0,G.jsx)(`span`,{children:e(`spoolbuddy.dashboard.nfcHint`,`NFC tag will be read automatically`)})]})]})}function g2e(){let{t:e}=U();return(0,G.jsxs)(`div`,{className:`flex flex-col items-center text-center`,children:[(0,G.jsx)(`div`,{className:`relative mb-6 flex items-center justify-center`,style:{width:160,height:160},children:(0,G.jsx)(`div`,{className:`w-24 h-24 rounded-full bg-zinc-800 flex items-center justify-center`,children:(0,G.jsx)(`svg`,{className:`w-12 h-12 text-zinc-600`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`1.5`,d:`M18.364 5.636a9 9 0 010 12.728m0 0l-12.728-12.728m12.728 12.728L5.636 5.636m12.728 0a9 9 0 00-12.728 0m0 12.728a9 9 0 010-12.728`})})})}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`p`,{className:`text-lg font-medium text-zinc-500`,children:e(`spoolbuddy.status.deviceOffline`,`Device Offline`)}),(0,G.jsx)(`p`,{className:`text-sm text-zinc-600`,children:e(`spoolbuddy.status.connectDisplay`,`Connect the SpoolBuddy display to scan spools`)})]}),(0,G.jsxs)(`div`,{className:`mt-6 flex items-center gap-2 text-xs text-zinc-600`,children:[(0,G.jsx)(`svg`,{className:`w-4 h-4`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`2`,d:`M8.111 16.404a5.5 5.5 0 017.778 0M12 20h.01m-7.08-7.071c3.904-3.905 10.236-3.905 14.14 0M1.394 9.393c5.857-5.857 15.355-5.857 21.213 0`})}),(0,G.jsx)(`span`,{children:e(`spoolbuddy.status.waitingConnection`,`Waiting for device connection...`)})]})]})}function _2e(){let{sbState:e,selectedPrinterId:t}=lr(),{t:n}=U(),{showToast:r}=qd(),{data:i}=K({queryKey:[`spoolman-settings`],queryFn:Z.getSpoolmanSettings,staleTime:300*1e3}),a=i?.spoolman_enabled===`true`&&!!i?.spoolman_url,{data:o=[],refetch:s}=K({queryKey:a?[`spoolman-inventory-spools`]:[`inventory-spools`],queryFn:()=>a?Z.getSpoolmanInventorySpools(!1):Z.getSpools(!1),enabled:i!==void 0}),{data:c=[]}=K({queryKey:[`spoolman-slot-assignments`],queryFn:()=>Z.getSpoolmanSlotAssignments(),enabled:a,staleTime:3*1e3,refetchInterval:3*1e3,refetchIntervalInBackground:!1}),{data:l=[]}=K({queryKey:[`printers`],queryFn:()=>Z.getPrinters()}),u=Co({queries:l.map(e=>({queryKey:[`printerStatus`,e.id],queryFn:()=>Z.getPrinterStatus(e.id),refetchInterval:1e4,select:e=>({connected:e?.connected,awaiting_plate_clear:e?.awaiting_plate_clear===!0})}))}),d=l.map((e,t)=>({printer:e,pending:u[t]?.data?.awaiting_plate_clear===!0})).filter(e=>e.pending),f=co(),p=q({mutationFn:e=>Z.clearPlate(e),onSuccess:(e,t)=>{f.setQueryData([`printerStatus`,t],e=>e&&{...e,awaiting_plate_clear:!1}),r(n(`spoolbuddy.dashboard.plateClearedToast`,`Plate marked as cleared`),`success`)},onError:()=>{r(n(`spoolbuddy.dashboard.plateClearFailed`,`Could not mark plate as cleared`),`error`)}}),m=q({mutationFn:e=>Z.unassignSpoolmanSlot(e),onSuccess:()=>{f.invalidateQueries({queryKey:[`spoolman-slot-assignments`]}),f.invalidateQueries({queryKey:[`spoolman-inventory-spools`]})},onError:()=>r(n(`inventory.unassignFailed`,`Failed to unassign spool`),`error`)}),[h,g]=(0,y.useState)(null),[_,v]=(0,y.useState)(null),[b,x]=(0,y.useState)(null),[S,C]=(0,y.useState)(!1),[w,T]=(0,y.useState)(!1),[E,D]=(0,y.useState)(!1),[O,k]=(0,y.useState)(!1),[A,j]=(0,y.useState)(null),M=e.matchedSpool?.tag_uid??e.unknownTagUid??null,N=e.weight,P=e.weightStable,F=(0,y.useRef)(null);N===null?F.current=null:(F.current===null||Math.abs(N-F.current)>=3||P)&&(F.current=N);let I=F.current,L=(0,y.useMemo)(()=>{if(e.matchedSpool?.id){let t=o.find(t=>t.id===e.matchedSpool?.id);if(t)return t}return h&&(o.find(e=>p2e(e.tag_uid,h))||A)||null},[h,e.matchedSpool,o,A]),R=(0,y.useMemo)(()=>{if(L&&!A)return L;let t=e.matchedSpool;return t?{id:t.id,tag_uid:t.tag_uid,material:t.material,subtype:t.subtype,color_name:t.color_name,rgba:t.rgba,brand:t.brand,label_weight:t.label_weight,core_weight:t.core_weight,weight_used:t.weight_used}:null},[L,A,e.matchedSpool]),z=a&&R!=null?c.some(e=>e.spoolman_spool_id===R.id):!1,B=(0,y.useMemo)(()=>a?o.filter(e=>!e.tag_uid&&!e.tray_uuid&&!e.archived_at):o.filter(e=>!e.tag_uid&&!e.archived_at),[o,a]);(0,y.useEffect)(()=>{if(M){let e=b===M;(h!==null&&h!==M||!e&&h!==M)&&(g(M),v(null),x(null),j(null)),!e&&N!==null&&P&&v(Math.round(Math.max(0,N)))}else b&&(g(null),x(null),v(null),j(null))},[M,N,P,h,b]);let V=()=>{x(h)},ee=async t=>{if(h)try{if(a){let i=e.unknownTagUid||void 0,a=!e.unknownTagUid&&e.unknownTrayUuid?e.unknownTrayUuid:void 0;if(!i&&!a){r(n(`spoolman.linkFailed`),`error`);return}let o=await Z.linkTagToSpoolmanSpool(t.id,{tray_uuid:a,tag_uid:i});if(!o){r(n(`spoolman.linkFailed`),`error`);return}let{id:s,material:c,subtype:l,color_name:u,rgba:d,brand:f,label_weight:p,core_weight:m,weight_used:h}=o;j({id:s,material:c,subtype:l,color_name:u,rgba:d,brand:f,label_weight:p,core_weight:m,weight_used:h}),r(n(`spoolman.linkSuccess`),`success`)}else await Z.linkTagToSpool(t.id,{tag_uid:h,tag_type:`generic`,data_origin:`nfc_link`});s()}catch(e){console.error(`Failed to link tag:`,e),r(n(`spoolman.linkFailed`),`error`)}finally{C(!1)}},te=async()=>{if(h){k(!0);try{let t=ne??_;if(a){let n=await Z.createSpoolmanInventorySpool({material:`PLA`,subtype:null,color_name:null,rgba:null,extra_colors:null,effect_type:null,brand:null,label_weight:1e3,core_weight:250,core_weight_catalog_id:null,weight_used:0,slicer_filament:null,slicer_filament_name:null,nozzle_temp_min:null,nozzle_temp_max:null,note:null,added_full:null,last_used:null,encode_time:null,tag_uid:null,tray_uuid:null,data_origin:null,tag_type:null,cost_per_kg:null,last_scale_weight:t===null?null:Math.round(t),last_weighed_at:t===null?null:new Date().toISOString(),category:null,low_stock_threshold_pct:null});await Z.linkTagToSpoolmanSpool(n.id,{tag_uid:e.unknownTagUid||void 0,tray_uuid:!e.unknownTagUid&&e.unknownTrayUuid?e.unknownTrayUuid:void 0})}else await Z.createSpool({material:`PLA`,subtype:null,color_name:null,rgba:null,extra_colors:null,effect_type:null,brand:null,label_weight:1e3,core_weight:250,core_weight_catalog_id:null,weight_used:0,slicer_filament:null,slicer_filament_name:null,nozzle_temp_min:null,nozzle_temp_max:null,note:null,added_full:null,last_used:null,encode_time:null,tag_uid:h,tray_uuid:null,data_origin:`spoolbuddy`,tag_type:`generic`,cost_per_kg:null,last_scale_weight:t===null?null:Math.round(t),last_weighed_at:t===null?null:new Date().toISOString(),category:null,low_stock_threshold_pct:null})}catch(e){let t=e instanceof Error?e.message:String(e);console.error(`Failed to quick-add spool:`,t),r(t||n(`spoolbuddy.errors.quickAddFailed`,`Failed to add spool`),`error`)}finally{D(!1),k(!1),s()}}},ne=N!==null&&(M===h||M===null&&h!==null)?N:null,re=o.length,ie=new Set(o.map(e=>e.material)).size,ae=new Set(o.filter(e=>e.brand).map(e=>e.brand)).size;return(0,G.jsxs)(`div`,{className:`h-full flex flex-col p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-6 px-4 py-1.5 bg-zinc-800/50 rounded-xl border border-zinc-700/50 mb-3 shrink-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-xl font-bold text-zinc-100`,children:re}),(0,G.jsx)(`span`,{className:`text-sm text-zinc-500`,children:n(`spoolbuddy.inventory.spools`,`Spools`)})]}),(0,G.jsx)(`div`,{className:`w-px h-5 bg-zinc-700`}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-xl font-bold text-zinc-100`,children:ie}),(0,G.jsx)(`span`,{className:`text-sm text-zinc-500`,children:n(`spoolbuddy.spool.material`,`Materials`)})]}),(0,G.jsx)(`div`,{className:`w-px h-5 bg-zinc-700`}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-xl font-bold text-zinc-100`,children:ae}),(0,G.jsx)(`span`,{className:`text-sm text-zinc-500`,children:n(`spoolbuddy.spool.brand`,`Brands`)})]})]}),(0,G.jsxs)(`div`,{className:`flex-1 flex gap-4 min-h-0`,children:[(0,G.jsxs)(`div`,{className:`w-5/12 flex flex-col min-h-0`,children:[(0,G.jsxs)(`div`,{className:`border border-dashed border-zinc-700/50 rounded-xl p-4`,children:[(0,G.jsx)(`h2`,{className:`text-sm font-semibold text-zinc-400 uppercase tracking-wide mb-3`,children:n(`spoolbuddy.dashboard.device`,`Device`)}),(0,G.jsxs)(`div`,{className:`space-y-2.5`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`w-2.5 h-2.5 rounded-full ${e.deviceOnline?`bg-green-500`:`bg-red-500`}`}),(0,G.jsx)(`span`,{className:`text-base text-zinc-400`,children:e.deviceOnline?n(`spoolbuddy.status.online`,`Online`):n(`spoolbuddy.status.offline`,`Disconnected`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-3 bg-zinc-800/50 rounded-lg`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`svg`,{className:`w-4 h-4 ${e.deviceOnline?`text-green-500`:`text-zinc-500`}`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`2`,d:`M3 6l3 1m0 0l-3 9a5.002 5.002 0 006.001 0M6 7l3 9M6 7l6-2m6 2l3-1m-3 1l-3 9a5.002 5.002 0 006.001 0M18 7l3 9m-3-9l-6-2m0-2v2m0 16V5m0 16H9m3 0h3`})}),(0,G.jsx)(`span`,{className:`text-sm text-zinc-500`,children:n(`spoolbuddy.spool.scaleWeight`,`Scale`)})]}),(0,G.jsx)(`span`,{className:`text-lg font-mono font-semibold text-zinc-100`,children:I===null?`—`:`${Math.abs(I)<=20?0:Math.round(Math.max(0,I))}g`})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-3 bg-zinc-800/50 rounded-lg`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`svg`,{className:`w-4 h-4 ${e.deviceOnline?`text-green-500`:`text-zinc-500`}`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`2`,d:`M7 7h.01M7 3h5c.512 0 1.024.195 1.414.586l7 7a2 2 0 010 2.828l-7 7a2 2 0 01-2.828 0l-7-7A2 2 0 013 12V7a4 4 0 014-4z`})}),(0,G.jsx)(`span`,{className:`text-sm text-zinc-500`,children:`NFC`})]}),(0,G.jsx)(`span`,{className:`text-sm font-medium ${M?`text-green-500`:`text-zinc-500`}`,children:M?n(`spoolbuddy.dashboard.tagDetected`,`Tag detected`):n(`spoolbuddy.dashboard.noTag`,`No tag`)})]})]})]}),l.length>0&&(0,G.jsxs)(`div`,{className:`mt-3 border border-dashed border-zinc-700/50 rounded-xl p-4`,children:[(0,G.jsx)(`h2`,{className:`text-sm font-semibold text-zinc-400 uppercase tracking-wide mb-2.5`,children:n(`spoolbuddy.dashboard.printers`,`Printers`)}),(0,G.jsx)(`div`,{className:`flex flex-wrap gap-2 overflow-hidden`,children:l.map((e,t)=>{let n=u[t]?.data?.connected??!1;return(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 px-2.5 py-1 bg-zinc-800/50 rounded-lg`,title:`${e.name} — ${n?`Online`:`Offline`}`,children:[(0,G.jsx)(`div`,{className:`w-2 h-2 rounded-full shrink-0 ${n?`bg-green-500`:`bg-zinc-600`}`}),(0,G.jsx)(`span`,{className:`text-xs text-zinc-400 truncate max-w-[100px]`,children:e.name})]},e.id)})}),d.length>0&&(0,G.jsx)(`div`,{className:`mt-2 flex flex-wrap gap-2`,"data-testid":`plate-clear-section`,"aria-label":n(`spoolbuddy.dashboard.plateReadyLabel`,`Plates ready to clear`),children:d.map(({printer:e})=>(0,G.jsxs)(`button`,{type:`button`,onClick:()=>p.mutate(e.id),disabled:p.isPending,"data-testid":`plate-clear-button-${e.id}`,title:n(`spoolbuddy.dashboard.plateReady`,`Plate ready: {{name}}`,{name:e.name}),className:`flex items-center gap-1.5 px-2.5 py-1 rounded-lg bg-amber-500/10 hover:bg-amber-500/20 active:bg-amber-500/30 border border-amber-500/30 text-amber-200 transition-colors disabled:opacity-60 disabled:cursor-wait`,children:[(0,G.jsxs)(`svg`,{className:`w-3 h-3 shrink-0`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:[(0,G.jsx)(`path`,{d:`M12 9v4`}),(0,G.jsx)(`path`,{d:`M12 17h.01`}),(0,G.jsx)(`path`,{d:`M10.29 3.86 1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z`})]}),(0,G.jsx)(`span`,{className:`text-xs truncate max-w-[100px]`,children:e.name}),(0,G.jsx)(`span`,{className:`text-xs opacity-70`,"aria-hidden":`true`,children:`·`}),(0,G.jsx)(`span`,{className:`text-xs font-medium`,children:n(`spoolbuddy.dashboard.plateClearAction`,`Clear`)})]},e.id))})]})]}),(0,G.jsx)(`div`,{className:`w-7/12 min-h-0`,children:(0,G.jsxs)(`div`,{className:`border border-dashed border-zinc-700/50 rounded-xl p-6 h-full flex flex-col`,children:[(0,G.jsx)(`h2`,{className:`text-sm font-semibold text-zinc-400 uppercase tracking-wide mb-4 shrink-0`,children:n(`spoolbuddy.dashboard.currentSpool`,`Current Spool`)}),(0,G.jsx)(`div`,{className:`flex-1 flex items-center justify-center min-h-0`,children:e.deviceOnline?(L||e.matchedSpool)&&h&&b!==h?(0,G.jsx)(K0e,{spool:(()=>{let t=L??e.matchedSpool;return{id:t.id,tag_uid:h,material:t.material,subtype:t.subtype,color_name:t.color_name,rgba:t.rgba,brand:t.brand,label_weight:t.label_weight,core_weight:t.core_weight,weight_used:t.weight_used}})(),scaleWeight:ne??_,onSyncWeight:()=>s(),onAssignToAms:()=>T(!0),isAssigned:z,onUnassignFromAms:z&&L?.id!=null?()=>m.mutate(L.id):void 0,onClose:V}):M&&h&&!L&&!e.matchedSpool&&b!==h?(0,G.jsx)(q0e,{tagUid:h,scaleWeight:ne??_,onLinkSpool:B.length>0?()=>C(!0):void 0,onAddToInventory:()=>D(!0),onClose:V}):(0,G.jsx)(h2e,{}):(0,G.jsx)(g2e,{})})]})})]}),R&&!A&&h&&(0,G.jsx)(Y9,{isOpen:w,onClose:()=>T(!1),spool:R,printerId:t,spoolmanMode:a}),h&&(0,G.jsx)(d2e,{isOpen:S,onClose:()=>C(!1),tagId:h,untaggedSpools:B,onLink:ee}),E&&h&&(0,G.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60`,children:(0,G.jsxs)(`div`,{className:`bg-zinc-800 rounded-2xl p-6 mx-4 max-w-sm w-full border border-zinc-700`,children:[(0,G.jsx)(`h3`,{className:`text-lg font-semibold text-zinc-100 mb-3`,children:n(`spoolbuddy.modal.addToInventory`,`Add to Inventory`)}),(0,G.jsxs)(`div`,{className:`flex gap-2.5 p-3 bg-amber-500/10 border border-amber-500/20 rounded-lg mb-4`,children:[(0,G.jsx)(`svg`,{className:`w-5 h-5 text-amber-500 shrink-0 mt-0.5`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:`2`,d:`M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z`})}),(0,G.jsx)(`p`,{className:`text-sm text-amber-200/80`,children:n(`spoolbuddy.modal.quickAddHint`,`For best results, add the spool in the Bambuddy web interface first (with material, color, brand), then use "Assign Spool" here to assign the NFC tag.`)})]}),(0,G.jsx)(`p`,{className:`text-sm text-zinc-400 mb-1`,children:n(`spoolbuddy.modal.quickAddDesc`,`This will create a basic PLA spool entry with this NFC tag. You can edit the details later in Bambuddy.`)}),(0,G.jsx)(`p`,{className:`text-xs text-zinc-500 font-mono mb-5`,children:h}),(0,G.jsxs)(`div`,{className:`flex gap-3`,children:[(0,G.jsx)(`button`,{onClick:()=>D(!1),className:`flex-1 px-4 py-2.5 rounded-lg text-sm font-medium bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors min-h-[44px]`,children:n(`common.cancel`,`Cancel`)}),(0,G.jsx)(`button`,{onClick:te,disabled:O,className:`flex-1 px-4 py-2.5 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 disabled:opacity-50 transition-colors min-h-[44px]`,children:O?n(`common.saving`,`Saving...`):n(`spoolbuddy.modal.addAnyway`,`Add Anyway`)})]})]})})]})}function v2e(e){return e<=3?`AMS ${String.fromCharCode(65+e)}`:e>=128&&e<=135?`AMS HT ${String.fromCharCode(65+e-128)}`:`AMS ${e}`}function y2e(e){return e?{O1D:`H2D`,O1E:`H2D Pro`,O2D:`H2D Pro`,O1C:`H2C`,O1C2:`H2C`,O1S:`H2S`,"BL-P001":`X1C`,"BL-P002":`X1`,"BL-P003":`X1E`,N6:`X2D`,N9:`A2L`,C11:`P1S`,C12:`P1P`,C13:`P2S`,N2S:`A1`,N1:`A1 Mini`,X1C:`X1C`,X1:`X1`,X1E:`X1E`,X2D:`X2D`,P1S:`P1S`,P1P:`P1P`,P2S:`P2S`,A1:`A1`,"A1 Mini":`A1 Mini`,A2L:`A2L`,H2D:`H2D`,"H2D Pro":`H2D Pro`,H2C:`H2C`,H2S:`H2S`}[e]||e:``}function X9(e){return!e.tray_type||e.tray_type===``}function b2e(e){return e?`#${e.slice(0,6)}`:`#808080`}function x2e(){let{selectedPrinterId:e,setAlert:t}=lr(),{t:n}=U(),r=co(),{showToast:i}=qd(),{data:a}=K({queryKey:[`printerStatus`,e],queryFn:()=>Z.getPrinterStatus(e),enabled:e!==null,staleTime:30*1e3}),{data:o}=K({queryKey:[`printer`,e],queryFn:()=>Z.getPrinter(e),enabled:e!==null,staleTime:60*1e3}),{data:s}=K({queryKey:[`slotPresets`,e],queryFn:()=>Z.getSlotPresets(e),enabled:e!==null,staleTime:120*1e3}),{data:c}=K({queryKey:[`settings`],queryFn:()=>Z.getSettings(),staleTime:300*1e3}),{data:l}=K({queryKey:[`spoolman-status`],queryFn:Z.getSpoolmanStatus,staleTime:60*1e3}),u=l?.enabled&&l?.connected,{data:d}=K({queryKey:[`linked-spools`],queryFn:Z.getLinkedSpools,enabled:!!u,staleTime:30*1e3}),f=d?.linked,{data:p=[]}=K({queryKey:[`spoolman-slot-assignments-all`],queryFn:()=>Z.getSpoolmanSlotAssignments(),enabled:!!u,staleTime:30*1e3}),{data:m=[]}=K({queryKey:[`spoolman-inventory-spools`],queryFn:()=>Z.getSpoolmanInventorySpools(!1),enabled:!!u,staleTime:30*1e3}),{data:h}=K({queryKey:[`spool-assignments`,e],queryFn:()=>Z.getAssignments(e),enabled:e!==null,staleTime:30*1e3}),g=(0,y.useMemo)(()=>{let e={};if(!h)return e;for(let t of h){let n=t.spool;if(n&&n.label_weight>0&&n.weight_used!=null){let r=Math.round(Math.max(0,n.label_weight-n.weight_used)/n.label_weight*100);e[`${t.ams_id}-${t.tray_id}`]=r}}return e},[h]),_=o?.serial_number??``,v=(0,y.useCallback)((t,n,r)=>{if(e!==null&&p.length&&m.length){let r=p.find(r=>r.printer_id===e&&r.ams_id===t&&r.tray_id===n);if(r){let e=m.find(e=>e.id===r.spoolman_spool_id);if(e&&(e.label_weight??0)>0)return Math.round(Math.max(0,e.label_weight-e.weight_used)/e.label_weight*100)}}if(f&&_){let e=(r?.tray_uuid||r?.tag_uid||Lp(_,t,n))?.toUpperCase(),i=Pp(e?f[e]:void 0);if(i!==null)return i}return null},[f,_,e,p,m]),b=a?.connected??!1,x=(0,y.useRef)({});(0,y.useEffect)(()=>{e&&a?.ams&&a.ams.length>0&&(x.current[e]=a.ams)},[a?.ams,e]);let S=(0,y.useMemo)(()=>{let t=a?.ams;return t&&t.length>0?t:(e?x.current[e]:null)??[]},[a?.ams,e]),C=(0,y.useMemo)(()=>S.filter(e=>!e.is_ams_ht),[S]),w=(0,y.useMemo)(()=>S.filter(e=>e.is_ams_ht),[S]),T=(0,y.useMemo)(()=>{let e={};if(!f||!_)return e;for(let t of C)for(let n=0;n<(t.tray?.length??0);n++){let r=t.tray[n],i=v(t.id,n,X9(r)?null:r);i!==null&&(e[`${t.id}-${n}`]=i)}return e},[f,_,C,v]),E=(0,y.useRef)(void 0),D=a?.tray_now;D!==void 0&&D!==255?E.current=D:D===255&&(E.current=void 0);let O=D!==void 0&&D!==255?D:E.current,k=o?.nozzle_count===2||a?.temperatures?.nozzle_2!==void 0,A=(0,y.useMemo)(()=>[...a?.vt_tray??[]].sort((e,t)=>(e.id??254)-(t.id??254)),[a?.vt_tray]),j=c?{humidityGood:Number(c.ams_humidity_good)||40,humidityFair:Number(c.ams_humidity_fair)||60,tempGood:Number(c.ams_temp_good)||28,tempFair:Number(c.ams_temp_fair)||35}:void 0,M=(0,y.useRef)({});(0,y.useEffect)(()=>{a?.ams_extruder_map&&Object.keys(a.ams_extruder_map).length>0&&(M.current=a.ams_extruder_map)},[a?.ams_extruder_map]);let N=a?.ams_extruder_map&&Object.keys(a.ams_extruder_map).length>0?a.ams_extruder_map:M.current,P=(0,y.useCallback)(e=>{if(!k)return null;let t=N[String(e)],n=e>=128?e-128:e;return(t===void 0?n:t)===1?`L`:`R`},[k,N]),[F,I]=(0,y.useState)(null),[L,R]=(0,y.useState)(null),[z,B]=(0,y.useState)(null),[V,ee]=(0,y.useState)(null),te=(0,y.useCallback)((e,t)=>h?.find(n=>n.ams_id===Number(e)&&n.tray_id===Number(t)),[h]),ne=(0,y.useCallback)((e,t,n)=>{if(!f||!_)return;let r=(n?.tray_uuid||n?.tag_uid||Lp(_,e,t))?.toUpperCase();return r?f[r]:void 0},[f,_]),re=q({mutationFn:({printerId:e,amsId:t,trayId:n})=>Z.unassignSpool(e,t,n),onSuccess:()=>{r.invalidateQueries({queryKey:[`spool-assignments`,e]}),r.invalidateQueries({queryKey:[`spool-assignments`]}),i(n(`inventory.unassignSuccess`,`Spool unassigned`),`success`),R(null)}}),ie=q({mutationFn:e=>Z.unlinkSpool(e),onSuccess:e=>{i(n(`spoolman.unlinkSuccess`)||e?.message,`success`),r.invalidateQueries({queryKey:[`linked-spools`]}),r.invalidateQueries({queryKey:[`unlinked-spools`]}),r.invalidateQueries({queryKey:[`spoolman-slot-assignments`]}),r.invalidateQueries({queryKey:[`spoolman-slot-assignments-all`]}),r.invalidateQueries({queryKey:[`spoolman-inventory-spools`]}),R(null)},onError:e=>{i(e.message||n(`spoolman.unlinkFailed`),`error`)}}),ae=q({mutationFn:e=>Z.unassignSpoolmanSlot(e),onSuccess:()=>{i(n(`inventory.unassignSuccess`,`Spool unassigned`),`success`),r.invalidateQueries({queryKey:[`spoolman-slot-assignments`]}),r.invalidateQueries({queryKey:[`spoolman-slot-assignments-all`]}),r.invalidateQueries({queryKey:[`spoolman-inventory-spools`]}),r.invalidateQueries({queryKey:[`unlinked-spools`]}),r.invalidateQueries({queryKey:[`linked-spools`]}),R(null)},onError:e=>{i(e.message||n(`inventory.assignFailed`,`Failed to unassign spool`),`error`)}}),oe=(0,y.useCallback)(e=>O===void 0?null:e<=3&&Math.floor(O/4)===e?O%4:e>=128&&e<=135&&O===Mp(e,0,!1)?0:null,[O]),se=(0,y.useCallback)((e,t,n)=>{let r=Mp(e,t,!1),i=s?.[r],a=N[String(e)],o=e>=128?e-128:e,c=a===void 0?o:a;R({amsId:e,trayId:t,trayCount:n&&e>=128?1:4,tray:n,trayType:n?.tray_type||void 0,trayColor:n?.tray_color||void 0,traySubBrands:n?.tray_sub_brands||void 0,trayInfoIdx:n?.tray_info_idx||void 0,extruderId:k?c:void 0,caliIdx:n?.cali_idx,savedPresetId:i?.preset_id,location:`${v2e(e)} Slot ${t+1}`})},[s,N,k]),H=(0,y.useCallback)(e=>{let t=e.id??254,n=t-254,r=s?.[1020+n];R({amsId:255,trayId:n,trayCount:1,tray:X9(e)?null:e,trayType:e.tray_type||void 0,trayColor:e.tray_color||void 0,traySubBrands:e.tray_sub_brands||void 0,trayInfoIdx:e.tray_info_idx||void 0,extruderId:k?+(t===254):void 0,caliIdx:e.cali_idx,savedPresetId:r?.preset_id,location:k?t===254?`Ext-L`:`Ext-R`:`External`})},[s,k]),ce=(0,y.useCallback)(()=>{if(!L)return;let{tray:e,location:t,...n}=L;R(null),I(n)},[L]),le=(0,y.useCallback)(()=>{if(!L||!e)return;let{amsId:t,trayId:n,trayType:r,trayColor:i,location:a}=L;R(null),B({printerId:e,amsId:t,trayId:n,trayInfo:{type:r||``,material:r,color:i?.slice(0,6)||``,location:a}})},[L,e]),ue=(0,y.useCallback)(()=>{if(!L||!e)return;let{amsId:t,trayId:n,tray:r}=L,i=(r?.tray_uuid||r?.tag_uid||Lp(_,t,n))?.toUpperCase()||``;R(null),ee({tagUid:r?.tag_uid||i,trayUuid:r?.tray_uuid||``,printerId:e,amsId:t,trayId:n})},[L,e,_]),de=(0,y.useCallback)(()=>{if(!L||!e)return;let{amsId:t,trayId:n}=L;re.mutate({printerId:e,amsId:t,trayId:n})},[L,e,re]);(0,y.useEffect)(()=>{if(!b&&e){t({type:`warning`,message:n(`spoolbuddy.ams.printerDisconnected`,`Printer disconnected`)});return}for(let e of S){let n=e.tray||[];for(let r=0;r=0&&i.remain<15&&i.tray_type){let n=e.id===254||e.id===255,a=!n&&e.id>=128,o=jp(e.id,r,a,n);t({type:`warning`,message:`Low Filament: ${i.tray_type} (${o}) - ${i.remain}% remaining`});return}}}t(null)},[S,b,e,t,n]);let fe=(0,y.useMemo)(()=>{let e=[];for(let t of w){let n=t.tray?.[0]||{id:0,tray_color:null,tray_type:``,tray_sub_brands:null,tray_id_name:null,tray_info_idx:null,remain:-1,k:null,cali_idx:null,tag_uid:null,tray_uuid:null,nozzle_temp_min:null,nozzle_temp_max:null},r=v(t.id,0,X9(n)?null:n),i=g[`${t.id}-0`]??null,a=n.remain!=null&&n.remain>=0?n.remain:null,o=i===0&&a!==null&&a>0?null:i;e.push({key:`ht-${t.id}`,label:v2e(t.id),tray:n,isEmpty:X9(n),isActive:oe(t.id)===0,temp:t.temp,humidity:t.humidity,nozzleSide:P(t.id),effectiveFill:r??o??a,onClick:()=>se(t.id,0,X9(n)?null:n)})}for(let t of A){let r=t.id??254,i=k&&O===254?r===254&&a?.active_extruder===1||r===255&&a?.active_extruder===0:O===r,o=r-254,s=v(255,o,X9(t)?null:t),c=g[`255-${o}`]??null,l=t.remain!=null&&t.remain>=0?t.remain:null,u=c===0&&l!==null&&l>0?null:c;e.push({key:`ext-${r}`,label:k?r===254?n(`printers.extL`,`Ext-L`):n(`printers.extR`,`Ext-R`):n(`printers.ext`,`Ext`),tray:t,isEmpty:X9(t),isActive:i,nozzleSide:null,effectiveFill:s??u??l,onClick:()=>H(t)})}return e},[w,A,k,O,a?.active_extruder,n,oe,P,se,H,g,v]);return(0,G.jsxs)(`div`,{className:`h-full flex flex-col p-4`,children:[(0,G.jsx)(`div`,{className:`flex-1 min-h-0`,children:e?b?S.length===0&&A.length===0?(0,G.jsx)(`div`,{className:`flex-1 flex items-center justify-center h-full`,children:(0,G.jsxs)(`div`,{className:`text-center text-white/50`,children:[(0,G.jsx)(Jc,{className:`w-12 h-12 mx-auto mb-3 opacity-50`}),(0,G.jsx)(`p`,{className:`text-lg mb-2`,children:n(`spoolbuddy.ams.noData`,`No AMS detected`)}),(0,G.jsx)(`p`,{className:`text-sm`,children:n(`spoolbuddy.ams.connectAms`,`Connect an AMS to see filament slots`)})]})}):(0,G.jsxs)(`div`,{className:`flex flex-col gap-3 h-full`,children:[(0,G.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-3`,children:C.map(e=>(0,G.jsx)(s2e,{unit:e,activeSlot:oe(e.id),onConfigureSlot:se,isDualNozzle:k,nozzleSide:P(e.id),thresholds:j,fillOverrides:g,spoolmanFillOverrides:T},e.id))}),fe.length>0&&(0,G.jsx)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-3`,children:fe.map(({key:e,label:t,tray:n,isEmpty:r,isActive:i,temp:a,humidity:o,nozzleSide:s,effectiveFill:c,onClick:l})=>{let u=b2e(n.tray_color);return(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg px-3 py-2 cursor-pointer hover:bg-bambu-dark-secondary/80 transition-all flex items-center gap-3 ${i?`ring-2 ring-bambu-green`:``}`,onClick:l,children:[(0,G.jsxs)(`div`,{className:`relative w-10 h-10 flex-shrink-0`,children:[r?(0,G.jsx)(`div`,{className:`w-full h-full rounded-full border-2 border-dashed border-gray-500 flex items-center justify-center`,children:(0,G.jsx)(`div`,{className:`w-1.5 h-1.5 rounded-full bg-gray-600`})}):(0,G.jsxs)(`svg`,{viewBox:`0 0 56 56`,className:`w-full h-full`,children:[(0,G.jsx)(`circle`,{cx:`28`,cy:`28`,r:`26`,fill:u}),(0,G.jsx)(`circle`,{cx:`28`,cy:`28`,r:`20`,fill:u,style:{filter:`brightness(0.85)`}}),(0,G.jsx)(`ellipse`,{cx:`20`,cy:`20`,rx:`6`,ry:`4`,fill:`white`,opacity:`0.3`}),(0,G.jsx)(`circle`,{cx:`28`,cy:`28`,r:`8`,fill:`#2d2d2d`}),(0,G.jsx)(`circle`,{cx:`28`,cy:`28`,r:`5`,fill:`#1a1a1a`})]}),i&&(0,G.jsx)(`div`,{className:`absolute -bottom-0.5 left-1/2 -translate-x-1/2 w-1.5 h-1.5 bg-bambu-green rounded-full`})]}),(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(`span`,{className:`text-xs text-white/50 font-medium truncate`,children:t}),s&&(0,G.jsx)(G9,{side:s})]}),(0,G.jsx)(`div`,{className:`text-sm text-white/80 truncate`,children:r?`Empty`:n.tray_type||`?`}),(a!=null||o!=null)&&(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[a!=null&&(0,G.jsx)(a2e,{temp:a,goodThreshold:j?.tempGood,fairThreshold:j?.tempFair}),o!=null&&(0,G.jsx)(i2e,{humidity:o,goodThreshold:j?.humidityGood,fairThreshold:j?.humidityFair})]})]}),!r&&c!=null&&c>=0&&(0,G.jsx)(`div`,{className:`w-1.5 h-8 bg-bambu-dark-tertiary rounded-full overflow-hidden flex-shrink-0 flex flex-col-reverse`,children:(0,G.jsx)(`div`,{className:`w-full rounded-full`,style:{height:`${c}%`,backgroundColor:Np(c)}})})]},e)})})]}):(0,G.jsx)(`div`,{className:`flex-1 flex items-center justify-center h-full`,children:(0,G.jsx)(`div`,{className:`text-center text-white/50`,children:(0,G.jsx)(`p`,{className:`text-lg mb-2`,children:n(`spoolbuddy.ams.printerDisconnected`,`Printer disconnected`)})})}):(0,G.jsx)(`div`,{className:`flex-1 flex items-center justify-center h-full`,children:(0,G.jsxs)(`div`,{className:`text-center text-white/50`,children:[(0,G.jsx)(`p`,{className:`text-lg mb-2`,children:n(`spoolbuddy.ams.noPrinter`,`No printer selected`)}),(0,G.jsx)(`p`,{className:`text-sm`,children:n(`spoolbuddy.ams.selectPrinter`,`Select a printer from the top bar`)})]})})}),F&&e&&(0,G.jsx)(mU,{isOpen:!!F,onClose:()=>I(null),printerId:e,slotInfo:F,printerModel:y2e(o?.model??null)||void 0,nozzleDiameter:Gp(a,F.amsId),fullScreen:!0,onSuccess:()=>{r.invalidateQueries({queryKey:[`slotPresets`,e]}),r.invalidateQueries({queryKey:[`printerStatus`,e]})}}),L&&e&&(()=>{let t=te(L.amsId,L.trayId),r=ne(L.amsId,L.trayId,L.tray),i=u?p.find(t=>t.printer_id===e&&t.ams_id===L.amsId&&t.tray_id===L.trayId):void 0,a=i?m.find(e=>e.id===i.spoolman_spool_id)??null:null;return(0,G.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[(0,G.jsx)(`div`,{className:`absolute inset-0 bg-black/60 backdrop-blur-sm`,onClick:()=>R(null)}),(0,G.jsxs)(`div`,{className:`relative w-full max-w-sm mx-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl shadow-2xl`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[L.trayColor&&(0,G.jsx)(`span`,{className:`w-4 h-4 rounded-full border border-black/20`,style:{backgroundColor:`#${L.trayColor.slice(0,6)}`}}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:L.location}),L.traySubBrands&&(0,G.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[`(`,L.traySubBrands,`)`]})]}),(0,G.jsx)(`button`,{onClick:()=>R(null),className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,G.jsx)(nd,{className:`w-5 h-5`})})]}),(0,G.jsxs)(`div`,{className:`p-4 space-y-2`,children:[!u&&t?.spool&&(0,G.jsxs)(`div`,{className:`p-2.5 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary mb-3`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mb-1`,children:n(`inventory.assignedSpool`,`Assigned spool`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[t.spool.rgba&&(0,G.jsx)(`span`,{className:`w-3 h-3 rounded-full border border-black/20 flex-shrink-0`,style:Mf(t.spool.rgba)}),(0,G.jsxs)(`span`,{className:`text-sm text-white`,children:[t.spool.brand?`${t.spool.brand} `:``,t.spool.material,t.spool.subtype?` ${t.spool.subtype}`:``,t.spool.color_name?` - ${t.spool.color_name}`:``]}),(0,G.jsxs)(`span`,{className:`text-[10px] font-mono text-zinc-500 shrink-0 ml-auto`,children:[`#`,t.spool.id]})]})]}),u&&r&&!a&&(0,G.jsxs)(`div`,{className:`p-2.5 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary mb-3`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mb-1`,children:n(`spoolman.linkedSpool`,`Linked spool`)}),(0,G.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,G.jsxs)(`span`,{className:`text-sm text-white`,children:[`Spoolman #`,r.id,r.remaining_weight==null?``:` (${Math.round(r.remaining_weight)}g)`]})})]}),u&&a&&(0,G.jsxs)(`div`,{className:`p-2.5 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary mb-3`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mb-1`,children:n(`inventory.assignedSpool`,`Assigned spool`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[a.rgba&&(0,G.jsx)(`span`,{className:`w-3 h-3 rounded-full border border-black/20 flex-shrink-0`,style:Mf(a.rgba)}),(0,G.jsxs)(`span`,{className:`text-sm text-white`,children:[a.brand?`${a.brand} `:``,a.material,a.subtype?` ${a.subtype}`:``,a.color_name?` - ${a.color_name}`:``]})]})]}),(0,G.jsxs)(`button`,{onClick:ce,className:`w-full flex items-center gap-3 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary hover:border-bambu-blue transition-colors text-left`,children:[(0,G.jsx)(nu,{className:`w-5 h-5 text-bambu-blue flex-shrink-0`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white font-medium`,children:n(`configureAmsSlot.title`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`spoolbuddy.ams.configureDesc`,`Set filament preset, K-profile, and color`)})]})]}),!u&&(Kp(L?.tray)?null:t?(0,G.jsxs)(`button`,{onClick:de,disabled:re.isPending,className:`w-full flex items-center gap-3 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary hover:border-amber-500 transition-colors text-left`,children:[(0,G.jsx)(Bu,{className:`w-5 h-5 text-amber-400 flex-shrink-0`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-amber-400 font-medium`,children:n(`inventory.unassignSpool`,`Unassign`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`spoolbuddy.ams.unassignDesc`,`Remove inventory spool from this slot`)})]})]}):(0,G.jsxs)(`button`,{onClick:le,className:`w-full flex items-center gap-3 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary hover:border-bambu-green transition-colors text-left`,children:[(0,G.jsx)(Cl,{className:`w-5 h-5 text-bambu-green flex-shrink-0`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white font-medium`,children:n(`inventory.assignSpool`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`spoolbuddy.ams.assignDesc`,`Track a spool from your inventory`)})]})]})),u&&(r?.id?(0,G.jsxs)(`button`,{onClick:()=>ie.mutate(r.id),disabled:ie.isPending,className:`w-full flex items-center gap-3 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary hover:border-amber-500 transition-colors text-left active:opacity-50`,children:[(0,G.jsx)(Bu,{className:`w-5 h-5 text-amber-400 flex-shrink-0`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-amber-400 font-medium`,children:n(`inventory.unassignSpool`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`spoolbuddy.ams.unlinkDesc`,`Remove Spoolman link from this slot`)})]})]}):a?(0,G.jsxs)(`button`,{onClick:()=>ae.mutate(a.id),disabled:ae.isPending,className:`w-full flex items-center gap-3 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary hover:border-amber-500 transition-colors text-left active:opacity-50`,children:[(0,G.jsx)(Bu,{className:`w-5 h-5 text-amber-400 flex-shrink-0`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-amber-400 font-medium`,children:n(`inventory.unassignSpool`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`spoolbuddy.ams.unassignDesc`,`Remove inventory spool from this slot`)})]})]}):(0,G.jsxs)(`button`,{onClick:ue,className:`w-full flex items-center gap-3 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary hover:border-bambu-green transition-colors text-left`,children:[(0,G.jsx)(Xc,{className:`w-5 h-5 text-bambu-green flex-shrink-0`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white font-medium`,children:n(`inventory.assignSpool`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`spoolbuddy.ams.linkDesc`,`Link a Spoolman spool to this slot`)})]})]}))]})]})]})})(),z&&(0,G.jsx)(TH,{isOpen:!!z,onClose:()=>{B(null),r.invalidateQueries({queryKey:[`spool-assignments`,e]}),r.invalidateQueries({queryKey:[`spool-assignments`]})},printerId:z.printerId,amsId:z.amsId,trayId:z.trayId,trayInfo:z.trayInfo,spoolmanEnabled:!!u}),V&&(0,G.jsx)(CH,{isOpen:!!V,onClose:()=>ee(null),tagUid:V.tagUid,trayUuid:V.trayUuid,printerId:V.printerId,amsId:V.amsId,trayId:V.trayId})]})}function S2e({type:e,deviceId:t,onClose:n}){let{t:r}=U(),[i,a]=(0,y.useState)(!1),[o,s]=(0,y.useState)(``),[c,l]=(0,y.useState)(``),[u,d]=(0,y.useState)(!1);(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&!i&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[i,n]);let f=(0,y.useCallback)(async()=>{a(!0),s(``),l(``),d(!0);try{s(r(`spoolbuddy.diagnostic.queuing`,`Queuing diagnostic on device... +`)),await Od.queueDiagnostics(t,e);let n=null,i=0;for(;i<60&&!n;){await new Promise(e=>setTimeout(e,500));try{n=await Od.getDiagnosticResult(t,e);break}catch{i++,i%4==0&&s(e=>e+`.`)}}if(!n)throw Error(`Diagnostic timed out - device did not report results`);s(n.output),n.success||l(`Exit code: ${n.exit_code}`)}catch(e){l(e instanceof Error?e.message:`Unknown error`),s(``)}finally{a(!1)}},[e,t,r]);return(0,G.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/70 animate-fade-in`,onClick:n,children:(0,G.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg shadow-xl w-full max-w-2xl mx-4 max-h-[80vh] flex flex-col animate-slide-up`,onClick:e=>e.stopPropagation(),children:[(0,G.jsxs)(`div`,{className:`flex justify-between items-center p-4 border-b border-zinc-700`,children:[(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e===`scale`?r(`spoolbuddy.diagnostic.scaleTitle`,`Scale Diagnostic`):e===`read_tag`?r(`spoolbuddy.diagnostic.readTagTitle`,`Read Tag Diagnostic`):r(`spoolbuddy.diagnostic.nfcTitle`,`NFC Reader Diagnostic`)}),(0,G.jsx)(`button`,{onClick:n,className:`text-zinc-400 hover:text-white transition-colors`,"aria-label":`Close`,children:(0,G.jsx)(nd,{size:20})})]}),(0,G.jsx)(`div`,{className:`flex-1 overflow-auto p-4 bg-black/50 font-mono text-sm`,children:i?(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-green-400`,children:[(0,G.jsx)(`div`,{className:`animate-spin w-4 h-4 border-2 border-green-400 border-t-transparent rounded-full`}),(0,G.jsx)(`span`,{children:r(`spoolbuddy.diagnostic.running`,`Running diagnostic on device...`)})]}):o?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`text-green-400 whitespace-pre-wrap break-words`,children:o}),c&&(0,G.jsxs)(`div`,{className:`text-red-400 mt-2`,children:[`❌ `,c]})]}):u?(0,G.jsx)(`div`,{children:c?(0,G.jsxs)(`div`,{className:`text-red-400`,children:[`ERROR: `,c]}):(0,G.jsx)(`span`,{className:`text-green-400`,children:r(`spoolbuddy.diagnostic.completed`,`Diagnostic completed successfully.`)})}):(0,G.jsxs)(`div`,{className:`text-zinc-500`,children:[r(`spoolbuddy.diagnostic.clickStart`,`Click "Run Diagnostic" to start the hardware diagnostic on`),` `,t,`.`]})}),(0,G.jsxs)(`div`,{className:`flex gap-2 p-4 border-t border-zinc-700 bg-zinc-800`,children:[(0,G.jsx)(`button`,{onClick:f,disabled:i,className:`flex-1 flex items-center justify-center gap-2 bg-green-600 hover:bg-green-700 disabled:bg-gray-600 disabled:cursor-not-allowed px-4 py-2 rounded font-semibold text-white transition-colors`,children:i?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`animate-spin w-4 h-4 border-2 border-white border-t-transparent rounded-full`}),r(`spoolbuddy.diagnostic.runningBtn`,`Running...`)]}):u?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Gl,{size:16}),r(`spoolbuddy.diagnostic.runAgain`,`Run Again`)]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Nl,{size:16}),r(`spoolbuddy.diagnostic.runBtn`,`Run Diagnostic`)]})}),(0,G.jsx)(`button`,{onClick:n,className:`px-4 py-2 rounded bg-zinc-700 hover:bg-zinc-600 text-white font-semibold transition-colors`,children:r(`spoolbuddy.diagnostic.close`,`Close`)})]})]})})}function C2e(e){return e<60?`${e}s`:e<3600?`${Math.floor(e/60)}m`:`${Math.floor(e/3600)}h ${Math.floor(e%3600/60)}m`}function w2e(e){if(!e)return`-`;let t=rp(e);return t?t.toLocaleDateString(void 0,{month:`short`,day:`numeric`})+` `+t.toLocaleTimeString(void 0,{hour:`2-digit`,minute:`2-digit`}):`-`}var T2e=[{label:`Off`,value:0},{label:`1m`,value:60},{label:`2m`,value:120},{label:`5m`,value:300},{label:`10m`,value:600},{label:`30m`,value:1800}];function E2e({device:e}){let{t}=U(),[n,r]=(0,y.useState)(null),[i,a]=(0,y.useState)(``),[o,s]=(0,y.useState)(``),[c,l]=(0,y.useState)(!1),[u,d]=(0,y.useState)(null);return(0,y.useEffect)(()=>{!i&&e.backend_url&&a(e.backend_url)},[e.backend_url,i]),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,G.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-3`,children:[(0,G.jsx)(`h3`,{className:`text-sm font-semibold text-zinc-300 mb-2`,children:t(`spoolbuddy.settings.nfcReader`,`NFC Reader`)}),(0,G.jsxs)(`div`,{className:`space-y-1.5 text-xs`,children:[(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.type`,`Type`)}),(0,G.jsx)(`span`,{className:`text-zinc-300 font-mono`,children:e.nfc_reader_type||`N/A`})]}),(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.connection`,`Connection`)}),(0,G.jsx)(`span`,{className:`text-zinc-300 font-mono`,children:e.nfc_connection||`N/A`})]}),(0,G.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.status.status`,`Status`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,G.jsx)(`div`,{className:`w-2 h-2 rounded-full ${e.nfc_ok?`bg-green-500`:e.nfc_reader_type?`bg-red-500`:`bg-zinc-600`}`}),(0,G.jsx)(`span`,{className:e.nfc_ok?`text-green-400`:e.nfc_reader_type?`text-red-400`:`text-zinc-500`,children:e.nfc_ok?t(`spoolbuddy.status.nfcReady`,`Ready`):e.nfc_reader_type?t(`common.error`,`Error`):t(`spoolbuddy.settings.notConnected`,`N/A`)})]})]})]})]}),(0,G.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-3`,children:[(0,G.jsx)(`h3`,{className:`text-sm font-semibold text-zinc-300 mb-2`,children:t(`spoolbuddy.settings.deviceInfo`,`Device Info`)}),(0,G.jsxs)(`div`,{className:`space-y-1.5 text-xs`,children:[(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.hostname`,`Host`)}),(0,G.jsx)(`span`,{className:`text-zinc-300 truncate ml-2`,children:e.hostname})]}),(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:`IP`}),(0,G.jsx)(`span`,{className:`text-zinc-300`,children:e.ip_address})]}),(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.uptime`,`Uptime`)}),(0,G.jsx)(`span`,{className:`text-zinc-300`,children:C2e(e.uptime_s)})]}),(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:`ID`}),(0,G.jsx)(`span`,{className:`text-zinc-400 font-mono truncate ml-2`,children:e.device_id})]})]})]})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,G.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-3 space-y-2`,children:[(0,G.jsx)(`h3`,{className:`text-sm font-semibold text-zinc-300`,children:t(`spoolbuddy.settings.systemConfig`,`Backend & Auth`)}),(0,G.jsx)(`input`,{value:i,onChange:e=>a(e.target.value),placeholder:`http://192.168.1.100:5000`,className:`w-full px-2 py-1.5 rounded bg-zinc-900 border border-zinc-700 text-zinc-100 text-xs`}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsx)(`input`,{type:`password`,value:o,onChange:e=>s(e.target.value),placeholder:t(`spoolbuddy.settings.apiTokenPlaceholder`,`API token`),className:`flex-1 px-2 py-1.5 rounded bg-zinc-900 border border-zinc-700 text-zinc-100 text-xs`}),(0,G.jsx)(`button`,{onClick:async()=>{if(!i.trim()){d({type:`error`,text:t(`spoolbuddy.settings.systemFieldsRequired`,`Backend URL is required.`)});return}l(!0),d(null);try{await Od.updateSystemConfig(e.device_id,i.trim(),o.trim()||void 0),d({type:`ok`,text:t(`spoolbuddy.settings.systemQueued`,`Config queued.`)})}catch(e){d({type:`error`,text:e instanceof Error?e.message:t(`common.error`,`Error`)})}finally{l(!1)}},disabled:c,className:`px-3 py-1.5 rounded bg-green-700 hover:bg-green-600 disabled:bg-zinc-700 text-xs font-medium text-zinc-100`,children:t(`spoolbuddy.settings.saveConfig`,`Save`)})]}),u&&(0,G.jsx)(`div`,{className:`text-xs ${u.type===`ok`?`text-green-400`:`text-red-400`}`,children:u.text})]}),(0,G.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-3 flex flex-col gap-2`,children:[(0,G.jsxs)(`button`,{onClick:()=>r(`nfc`),className:`flex-1 bg-blue-700 hover:bg-blue-600 transition-colors rounded-lg p-2 flex items-center gap-2`,children:[(0,G.jsx)(Yu,{className:`w-4 h-4 text-blue-300 shrink-0`}),(0,G.jsx)(`span`,{className:`text-xs font-medium text-blue-100`,children:t(`spoolbuddy.settings.nfcDiagnostic`,`NFC Diagnostic`)})]}),(0,G.jsxs)(`button`,{onClick:()=>r(`scale`),className:`flex-1 bg-yellow-700 hover:bg-yellow-600 transition-colors rounded-lg p-2 flex items-center gap-2`,children:[(0,G.jsx)(id,{className:`w-4 h-4 text-yellow-300 shrink-0`}),(0,G.jsx)(`span`,{className:`text-xs font-medium text-yellow-100`,children:t(`spoolbuddy.settings.scaleDiagnostic`,`Scale Diagnostic`)})]}),(0,G.jsxs)(`button`,{onClick:()=>r(`read_tag`),className:`flex-1 bg-emerald-700 hover:bg-emerald-600 transition-colors rounded-lg p-2 flex items-center gap-2`,children:[(0,G.jsx)(fc,{className:`w-4 h-4 text-emerald-300 shrink-0`}),(0,G.jsx)(`span`,{className:`text-xs font-medium text-emerald-100`,children:t(`spoolbuddy.settings.readTagDiagnostic`,`Read Tag`)})]})]})]}),n&&e&&(0,G.jsx)(S2e,{type:n,deviceId:e.device_id,onClose:()=>r(null)})]})}function D2e({device:e,onBrightnessChange:t}){let{t:n}=U(),[r,i]=(0,y.useState)(e.display_brightness),[a,o]=(0,y.useState)(e.display_blank_timeout),[s,c]=(0,y.useState)(!1),l=(0,y.useRef)(void 0),u=(0,y.useRef)(void 0);(0,y.useEffect)(()=>{i(e.display_brightness),o(e.display_blank_timeout)},[e.display_brightness,e.display_blank_timeout]);let d=(0,y.useCallback)(()=>{c(!0),u.current&&clearTimeout(u.current),u.current=setTimeout(()=>c(!1),1500)},[]),f=(0,y.useCallback)((t,n)=>{l.current&&clearTimeout(l.current),l.current=setTimeout(()=>{Od.updateDisplay(e.device_id,t,n).then(()=>d()).catch(e=>console.error(`Failed to update display:`,e))},300)},[e.device_id,d]),p=e=>{i(e),t(e),f(e,a)},m=e=>{o(e),f(r,e)};return(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,G.jsx)(`h3`,{className:`text-sm font-semibold text-zinc-300`,children:n(`spoolbuddy.settings.brightness`,`Brightness`)}),s&&(0,G.jsxs)(`span`,{className:`text-xs text-green-400 flex items-center gap-1 animate-pulse`,children:[(0,G.jsx)(`svg`,{className:`w-3 h-3`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:3,children:(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M5 13l4 4L19 7`})}),n(`spoolbuddy.settings.saved`,`Saved`)]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`svg`,{className:`w-4 h-4 text-zinc-500 flex-shrink-0`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:2,children:(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M12 3v1m0 16v1m9-9h-1M4 12H3m15.364 6.364l-.707-.707M6.343 6.343l-.707-.707m12.728 0l-.707.707M6.343 17.657l-.707.707M16 12a4 4 0 11-8 0 4 4 0 018 0z`})}),(0,G.jsx)(`input`,{type:`range`,min:0,max:100,value:r,onChange:e=>p(parseInt(e.target.value)),className:`flex-1 h-2 bg-zinc-700 rounded-lg appearance-none cursor-pointer accent-green-500`}),(0,G.jsxs)(`span`,{className:`text-sm font-mono text-zinc-400 w-10 text-right`,children:[r,`%`]})]}),!e.has_backlight&&(0,G.jsx)(`p`,{className:`text-xs text-zinc-600 mt-2`,children:n(`spoolbuddy.settings.noBacklight`,`No DSI backlight detected. Brightness control requires a DSI display.`)})]}),(0,G.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-4`,children:[(0,G.jsx)(`h3`,{className:`text-sm font-semibold text-zinc-300 mb-1`,children:n(`spoolbuddy.settings.screenBlank`,`Screen Blank Timeout`)}),(0,G.jsx)(`p`,{className:`text-xs text-zinc-500 mb-3`,children:n(`spoolbuddy.settings.screenBlankDesc`,`Screen turns off after inactivity. Touch to wake.`)}),(0,G.jsx)(`div`,{className:`grid grid-cols-3 gap-2`,children:T2e.map(e=>(0,G.jsx)(`button`,{onClick:()=>m(e.value),className:`px-3 py-2 rounded-lg text-sm font-medium transition-colors min-h-[40px] ${a===e.value?`bg-green-600 text-white`:`bg-zinc-700 text-zinc-300 hover:bg-zinc-600`}`,children:e.label},e.value))})]}),(0,G.jsx)(`p`,{className:`text-xs text-zinc-600 text-center`,children:n(`spoolbuddy.settings.displayNote`,`Brightness is applied as a software filter.`)})]})}function O2e({step:e,labels:t}){return(0,G.jsxs)(`div`,{className:`flex flex-col items-center w-16 shrink-0 pt-1`,children:[(0,G.jsx)(`div`,{className:`flex items-center justify-center w-7 h-7 rounded-full text-xs font-bold ${e===`tare`?`bg-green-600 text-white`:`bg-green-600/20 text-green-400`}`,children:e===`weight`?(0,G.jsx)(`svg`,{className:`w-3.5 h-3.5`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:3,children:(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M5 13l4 4L19 7`})}):`1`}),(0,G.jsx)(`span`,{className:`text-[10px] mt-0.5 ${e===`tare`?`text-green-400 font-medium`:`text-green-400/60`}`,children:t.tare}),(0,G.jsx)(`div`,{className:`w-px h-5 my-1 ${e===`weight`?`bg-green-600/40`:`bg-zinc-700`}`}),(0,G.jsx)(`div`,{className:`flex items-center justify-center w-7 h-7 rounded-full text-xs font-bold ${e===`weight`?`bg-green-600 text-white`:`bg-zinc-700 text-zinc-500`}`,children:`2`}),(0,G.jsx)(`span`,{className:`text-[10px] mt-0.5 ${e===`weight`?`text-green-400 font-medium`:`text-zinc-600`}`,children:t.weight})]})}function k2e({device:e,weight:t,weightStable:n,rawAdc:r}){let{t:i}=U(),a=co(),[o,s]=(0,y.useState)(`idle`),[c,l]=(0,y.useState)(`500`),[u,d]=(0,y.useState)(null),[f,p]=(0,y.useState)(!1),[m,h]=(0,y.useState)(null),[g,_]=(0,y.useState)(null),v=(0,y.useRef)(null);(0,y.useEffect)(()=>()=>{v.current&&clearTimeout(v.current)},[]);let b=(0,y.useCallback)(e=>{v.current&&clearTimeout(v.current),v.current=setTimeout(()=>h(null),e)},[]);(0,y.useEffect)(()=>{if(!g)return;let e=()=>Date.now()-g.startedAtMs,t=setInterval(()=>{a.invalidateQueries({queryKey:[`spoolbuddy-devices`]})},1e3),n=setTimeout(()=>{_(null),h({type:`error`,msg:i(`spoolbuddy.settings.tareTimedOut`,`Tare timed out — is the SpoolBuddy daemon running?`)}),b(5e3)},Math.max(0,15e3-e()));return()=>{clearInterval(t),clearTimeout(n)}},[g,a,i,b]),(0,y.useEffect)(()=>{g&&(e?.last_calibrated_at??null)!==g.snapshot&&(_(null),h({type:`ok`,msg:i(`spoolbuddy.settings.tareComplete`,`Tare complete!`)}),b(3e3))},[e?.last_calibrated_at,g,i,b]);let x=e=>{e===`backspace`?l(e=>e.slice(0,-1)||``):e===`.`&&!c.includes(`.`)?l(e=>e+`.`):e>=`0`&&e<=`9`&&l(t=>t===`0`?e:t+e)};return o===`idle`?(0,G.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,G.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-3 mb-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`div`,{className:`w-2 h-2 rounded-full ${n?`bg-green-500`:`bg-amber-500 animate-pulse`}`}),(0,G.jsx)(`span`,{className:`text-lg font-mono text-zinc-200`,children:t===null?`-- g`:`${t.toFixed(1)} g`})]}),(0,G.jsxs)(`div`,{className:`text-xs text-zinc-500 text-right`,children:[(0,G.jsxs)(`span`,{children:[i(`spoolbuddy.settings.tareOffset`,`Tare`),`: `,e.tare_offset]}),(0,G.jsx)(`span`,{className:`mx-1.5`,children:`·`}),(0,G.jsxs)(`span`,{children:[i(`spoolbuddy.settings.calFactor`,`Factor`),`: `,e.calibration_factor.toFixed(2)]})]})]}),e.last_calibrated_at&&(0,G.jsxs)(`div`,{className:`text-xs text-zinc-600 mt-1`,children:[i(`spoolbuddy.settings.lastCalibrated`,`Last calibrated`),`: `,w2e(e.last_calibrated_at)]})]}),m&&(0,G.jsx)(`div`,{className:`rounded-lg px-3 py-2 mb-3 text-sm ${m.type===`ok`?`bg-green-900/30 text-green-300 border border-green-800`:`bg-red-900/30 text-red-300 border border-red-800`}`,children:m.msg}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsxs)(`button`,{onClick:async()=>{p(!0),h(null),v.current&&=(clearTimeout(v.current),null);let t=e?.last_calibrated_at??null;try{await Od.tare(e.device_id),h({type:`ok`,msg:i(`spoolbuddy.settings.tareSet`,`Tare command sent. Waiting for device...`)}),_({snapshot:t,startedAtMs:Date.now()})}catch{h({type:`error`,msg:i(`spoolbuddy.settings.tareFailed`,`Failed to send tare command`)}),b(5e3)}finally{p(!1)}},disabled:f,className:`flex-1 px-4 py-2.5 rounded-lg text-sm font-medium bg-zinc-700 text-zinc-200 hover:bg-zinc-600 disabled:opacity-40 transition-colors min-h-[44px] flex items-center justify-center gap-2`,children:[f&&(0,G.jsxs)(`svg`,{className:`w-4 h-4 animate-spin`,viewBox:`0 0 24 24`,fill:`none`,children:[(0,G.jsx)(`circle`,{className:`opacity-25`,cx:`12`,cy:`12`,r:`10`,stroke:`currentColor`,strokeWidth:`4`}),(0,G.jsx)(`path`,{className:`opacity-75`,fill:`currentColor`,d:`M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z`})]}),i(`spoolbuddy.weight.tare`,`Tare`)]}),(0,G.jsx)(`button`,{onClick:()=>{s(`tare`),h(null)},className:`flex-1 px-4 py-2.5 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 transition-colors min-h-[44px]`,children:i(`spoolbuddy.weight.calibrate`,`Calibrate`)})]})]}):(0,G.jsxs)(`div`,{className:`flex gap-3`,children:[(0,G.jsx)(O2e,{step:o,labels:{tare:i(`spoolbuddy.weight.tare`,`Tare`),weight:i(`spoolbuddy.settings.knownWeight`,`Known weight`)}}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 bg-zinc-800 rounded-lg px-3 py-1.5 mb-1.5`,children:[(0,G.jsx)(`div`,{className:`w-2 h-2 rounded-full shrink-0 ${n?`bg-green-500`:`bg-amber-500 animate-pulse`}`}),(0,G.jsx)(`span`,{className:`text-sm font-mono text-zinc-200`,children:t===null?`-- g`:`${t.toFixed(1)} g`}),(0,G.jsx)(`span`,{className:`text-xs ml-auto ${n?`text-green-400`:`text-amber-400`}`,children:n?i(`spoolbuddy.settings.stable`,`Stable`):i(`spoolbuddy.settings.settling`,`Settling...`)})]}),m&&(0,G.jsx)(`div`,{className:`rounded-lg px-3 py-1.5 mb-1.5 text-xs ${m.type===`ok`?`bg-green-900/30 text-green-300 border border-green-800`:`bg-red-900/30 text-red-300 border border-red-800`}`,children:m.msg}),o===`tare`?(0,G.jsx)(`p`,{className:`text-sm text-zinc-300 mb-3`,children:i(`spoolbuddy.settings.calStep1`,`Remove all items from the scale and press Set Zero.`)}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-1.5`,children:[(0,G.jsx)(`span`,{className:`text-xs text-zinc-400 shrink-0`,children:i(`spoolbuddy.settings.knownWeight`,`Known weight`)}),(0,G.jsxs)(`div`,{className:`flex-1 bg-zinc-900 border border-zinc-600 rounded px-3 py-1 text-right text-lg font-mono text-zinc-100`,children:[c||`0`,(0,G.jsx)(`span`,{className:`text-zinc-500 ml-1`,children:`g`})]})]}),(0,G.jsx)(`div`,{className:`grid grid-cols-4 gap-1 mb-1.5`,children:[`7`,`8`,`9`,`backspace`,`4`,`5`,`6`,`.`,`1`,`2`,`3`,`0`].map(e=>(0,G.jsx)(`button`,{onClick:()=>x(e),className:`rounded text-lg font-medium transition-colors h-[48px] active:scale-95 ${e===`backspace`?`bg-zinc-700 text-zinc-300 hover:bg-zinc-600`:`bg-zinc-800 text-zinc-100 hover:bg-zinc-700 border border-zinc-700`}`,children:e===`backspace`?`⌫`:e},e))})]}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsx)(`button`,{onClick:()=>{s(`idle`),h(null)},className:`flex-1 px-4 py-2 rounded-lg text-sm bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors h-[40px]`,children:i(`common.cancel`,`Cancel`)}),(0,G.jsxs)(`button`,{onClick:async()=>{if(o===`tare`){p(!0),h(null);try{d(r),await Od.tare(e.device_id),h({type:`ok`,msg:i(`spoolbuddy.settings.zeroSet`,`Zero point set. Place known weight on scale.`)}),s(`weight`)}catch{h({type:`error`,msg:i(`spoolbuddy.settings.tareFailed`,`Failed to send tare command`)})}finally{p(!1)}}else if(o===`weight`){let t=parseFloat(c);if(r===null||!t||t<=0)return;p(!0),h(null);try{await Od.setCalibrationFactor(e.device_id,t,r,u??void 0),h({type:`ok`,msg:i(`spoolbuddy.settings.calibrationDone`,`Calibration complete!`)}),b(3e3),s(`idle`)}catch{h({type:`error`,msg:i(`spoolbuddy.settings.calibrationFailed`,`Calibration failed`)}),b(5e3)}finally{p(!1)}}},disabled:f,className:`flex-1 px-4 py-2 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 disabled:opacity-40 transition-colors h-[40px] flex items-center justify-center gap-2`,children:[f&&(0,G.jsxs)(`svg`,{className:`w-4 h-4 animate-spin`,viewBox:`0 0 24 24`,fill:`none`,children:[(0,G.jsx)(`circle`,{className:`opacity-25`,cx:`12`,cy:`12`,r:`10`,stroke:`currentColor`,strokeWidth:`4`}),(0,G.jsx)(`path`,{className:`opacity-75`,fill:`currentColor`,d:`M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z`})]}),o===`tare`?i(`spoolbuddy.settings.setZero`,`Set Zero`):i(`spoolbuddy.settings.calibrateNow`,`Calibrate`)]})]})]})]})}function A2e({device:e}){let{t}=U(),[n,r]=(0,y.useState)(null),[i,a]=(0,y.useState)(null),[o,s]=(0,y.useState)(!1),[c,l]=(0,y.useState)(!1),u=e.update_status===`pending`||e.update_status===`updating`;(0,y.useEffect)(()=>{u&&n===`applying`&&r(null)},[u,n]),(0,y.useEffect)(()=>{let e=()=>{u&&setTimeout(()=>window.location.reload(),1e3)};return window.addEventListener(`spoolbuddy-online`,e),()=>window.removeEventListener(`spoolbuddy-online`,e)},[u]);let{data:d,refetch:f}=K({queryKey:[`spoolbuddy-update-check`,e.device_id],queryFn:()=>Od.checkDaemonUpdate(e.device_id),staleTime:0}),{data:p}=K({queryKey:[`spoolbuddy-ssh-key`],queryFn:()=>Od.getSSHPublicKey(),enabled:o,staleTime:1/0}),m=async()=>{r(`checking`),a(null);try{await f()}finally{r(null)}},h=async()=>{r(`applying`),a(null);try{await Od.triggerUpdate(e.device_id)}catch(e){a(e instanceof Error?e.message:`Failed to trigger update`),r(null)}},g=n!=null||u,_=()=>{p?.public_key&&(navigator.clipboard.writeText(p.public_key),l(!0),setTimeout(()=>l(!1),2e3))},v=e.firmware_version||(d?.current_version&&d.current_version!==`0.0.0`?d.current_version:null);return(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-3 space-y-3`,children:[(0,G.jsxs)(`div`,{className:`flex justify-between items-center text-sm`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.currentVersion`,`Current Version`)}),(0,G.jsx)(`span`,{className:`text-zinc-200 font-mono`,children:v||(0,G.jsx)(`span`,{className:`text-zinc-500 italic text-xs`,children:t(`spoolbuddy.settings.versionPending`,`Waiting for daemon...`)})})]}),g?(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`svg`,{className:`w-4 h-4 animate-spin text-green-400 flex-shrink-0`,viewBox:`0 0 24 24`,fill:`none`,children:[(0,G.jsx)(`circle`,{className:`opacity-25`,cx:`12`,cy:`12`,r:`10`,stroke:`currentColor`,strokeWidth:`4`}),(0,G.jsx)(`path`,{className:`opacity-75`,fill:`currentColor`,d:`M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z`})]}),(0,G.jsx)(`span`,{className:`text-green-300 text-xs`,children:n===`checking`?t(`spoolbuddy.settings.checking`,`Checking for updates...`):e.update_message||t(`spoolbuddy.settings.updateWaiting`,`Updating...`)})]}):e.update_status===`error`?(0,G.jsx)(`p`,{className:`text-xs text-red-300`,children:e.update_message||t(`spoolbuddy.settings.updateFailed`,`Update failed`)}):i?(0,G.jsx)(`p`,{className:`text-xs text-red-300`,children:i}):d?.update_available?(0,G.jsxs)(`p`,{className:`text-xs text-green-300`,children:[t(`spoolbuddy.settings.updateAvailable`,`Update available`),`: `,v,` → `,d.latest_version]}):null,!g&&(d?.update_available?(0,G.jsx)(`button`,{onClick:h,disabled:!e.online,className:`w-full px-3 py-2 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 disabled:opacity-40 transition-colors`,children:e.online?t(`spoolbuddy.settings.applyUpdate`,`Apply Update`):t(`spoolbuddy.settings.deviceOffline`,`Device Offline`)}):(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsx)(`button`,{onClick:m,className:`flex-1 px-3 py-2 rounded-lg text-xs font-medium bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors`,children:t(`spoolbuddy.settings.checkUpdates`,`Check for Updates`)}),(0,G.jsx)(`button`,{onClick:h,disabled:!e.online,className:`px-3 py-2 rounded-lg text-xs font-medium bg-zinc-700 text-zinc-400 hover:bg-zinc-600 hover:text-zinc-200 disabled:opacity-40 transition-colors`,children:t(`spoolbuddy.settings.forceUpdate`,`Force Update`)})]}))]}),(0,G.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-3`,children:[(0,G.jsxs)(`button`,{onClick:()=>s(!o),className:`w-full flex justify-between items-center text-xs`,children:[(0,G.jsx)(`span`,{className:`font-medium text-zinc-400`,children:t(`spoolbuddy.settings.sshSetup`,`SSH Setup`)}),(0,G.jsx)(`svg`,{className:`w-3 h-3 text-zinc-500 transition-transform ${o?`rotate-180`:``}`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:2,children:(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M19 9l-7 7-7-7`})})]}),o&&(0,G.jsxs)(`div`,{className:`mt-2 space-y-2`,children:[(0,G.jsx)(`p`,{className:`text-xs text-zinc-500`,children:t(`spoolbuddy.settings.sshDescription`,`SSH key is deployed automatically. For manual setup, add this key to ~/.ssh/authorized_keys on the device.`)}),p?.public_key?(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(`pre`,{className:`bg-zinc-900 rounded p-2 text-[10px] text-zinc-400 font-mono break-all whitespace-pre-wrap`,children:p.public_key}),(0,G.jsx)(`button`,{onClick:_,className:`absolute top-1 right-1 px-1.5 py-0.5 rounded text-[10px] bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors`,children:c?t(`common.copied`,`Copied!`):t(`common.copy`,`Copy`)})]}):(0,G.jsx)(`span`,{className:`text-[10px] text-zinc-500 italic`,children:t(`spoolbuddy.settings.sshKeyLoading`,`Loading...`)})]})]})]})}function j2e({percent:e,color:t}){return(0,G.jsx)(`div`,{className:`w-full h-2 bg-zinc-700 rounded-full overflow-hidden`,children:(0,G.jsx)(`div`,{className:`h-full rounded-full transition-all ${t}`,style:{width:`${Math.min(100,Math.max(0,e))}%`}})})}function M2e(e){let t=Math.floor(e/86400),n=Math.floor(e%86400/3600),r=Math.floor(e%3600/60);return t>0?`${t}d ${n}h ${r}m`:n>0?`${n}h ${r}m`:`${r}m`}function N2e({device:e}){let{t}=U(),n=e.system_stats;if(!n)return(0,G.jsx)(`div`,{className:`flex items-center justify-center h-32`,children:(0,G.jsx)(`p`,{className:`text-sm text-zinc-500`,children:t(`spoolbuddy.settings.systemStatsWaiting`,`Waiting for system stats...`)})});let r=n.memory,i=n.disk,a=(n.cpu_temp_c??0)>=80?`text-red-400`:(n.cpu_temp_c??0)>=65?`text-amber-400`:`text-green-400`,o=(r?.percent??0)>=90?`bg-red-500`:(r?.percent??0)>=70?`bg-amber-500`:`bg-green-500`,s=(i?.percent??0)>=90?`bg-red-500`:(i?.percent??0)>=70?`bg-amber-500`:`bg-green-500`;return(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,G.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-3`,children:[(0,G.jsx)(`h3`,{className:`text-sm font-semibold text-zinc-300 mb-2`,children:`CPU`}),(0,G.jsxs)(`div`,{className:`space-y-1.5 text-xs`,children:[(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.cores`,`Cores`)}),(0,G.jsx)(`span`,{className:`text-zinc-300 font-mono`,children:n.cpu_count??`-`})]}),(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.loadAvg`,`Load Avg`)}),(0,G.jsx)(`span`,{className:`text-zinc-300 font-mono`,children:n.load_avg?n.load_avg.join(` / `):`-`})]}),(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.temp`,`Temp`)}),(0,G.jsx)(`span`,{className:`font-mono font-medium ${a}`,children:n.cpu_temp_c==null?`-`:`${n.cpu_temp_c}\u00B0C`})]})]})]}),(0,G.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-3`,children:[(0,G.jsx)(`h3`,{className:`text-sm font-semibold text-zinc-300 mb-2`,children:t(`spoolbuddy.settings.memory`,`Memory`)}),r?(0,G.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,G.jsx)(j2e,{percent:r.percent??0,color:o}),(0,G.jsxs)(`div`,{className:`space-y-1 text-xs`,children:[(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.used`,`Used`)}),(0,G.jsxs)(`span`,{className:`text-zinc-300 font-mono`,children:[r.used_mb,` / `,r.total_mb,` MB`]})]}),(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.available`,`Free`)}),(0,G.jsxs)(`span`,{className:`text-zinc-300 font-mono`,children:[r.available_mb,` MB`]})]})]})]}):(0,G.jsx)(`span`,{className:`text-xs text-zinc-500`,children:`-`})]})]}),(0,G.jsx)(`div`,{className:`bg-zinc-800 rounded-lg px-3 py-2`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`h3`,{className:`text-sm font-semibold text-zinc-300 shrink-0`,children:t(`spoolbuddy.settings.disk`,`Disk`)}),i?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`flex-1`,children:(0,G.jsx)(j2e,{percent:i.percent??0,color:s})}),(0,G.jsxs)(`span`,{className:`text-xs text-zinc-300 font-mono shrink-0`,children:[i.used_gb,` / `,i.total_gb,` GB`]})]}):(0,G.jsx)(`span`,{className:`text-xs text-zinc-500`,children:`-`})]})}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,G.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-3`,children:[(0,G.jsx)(`h3`,{className:`text-sm font-semibold text-zinc-300 mb-1.5`,children:t(`spoolbuddy.settings.osInfo`,`OS`)}),(0,G.jsxs)(`div`,{className:`space-y-1 text-xs`,children:[n.os?.os&&(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.distro`,`Distro`)}),(0,G.jsx)(`span`,{className:`text-zinc-300 truncate ml-2`,children:n.os.os})]}),n.os?.kernel&&(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.kernel`,`Kernel`)}),(0,G.jsx)(`span`,{className:`text-zinc-300 font-mono truncate ml-2`,children:n.os.kernel})]}),n.os?.arch&&(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.arch`,`Arch`)}),(0,G.jsx)(`span`,{className:`text-zinc-300 font-mono`,children:n.os.arch})]})]})]}),(0,G.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-3`,children:[(0,G.jsx)(`h3`,{className:`text-sm font-semibold text-zinc-300 mb-1.5`,children:t(`spoolbuddy.settings.runtime`,`Runtime`)}),(0,G.jsxs)(`div`,{className:`space-y-1 text-xs`,children:[n.os?.python&&(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:`Python`}),(0,G.jsx)(`span`,{className:`text-zinc-300 font-mono`,children:n.os.python})]}),n.system_uptime_s!=null&&(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:t(`spoolbuddy.settings.systemUptime`,`Uptime`)}),(0,G.jsx)(`span`,{className:`text-zinc-300`,children:M2e(n.system_uptime_s)})]})]})]})]})]})}function P2e(){let{sbState:e,setDisplayBrightness:t}=lr(),{t:n}=U(),[r,i]=(0,y.useState)(`device`),{data:a=[]}=K({queryKey:[`spoolbuddy-devices`],queryFn:()=>Od.getDevices(),refetchInterval:1e4}),o=e.deviceId?a.find(t=>t.device_id===e.deviceId)??a[0]:a[0],s=[{id:`device`,label:n(`spoolbuddy.settings.tabDevice`,`Device`)},{id:`display`,label:n(`spoolbuddy.settings.tabDisplay`,`Display`)},{id:`scale`,label:n(`spoolbuddy.settings.tabScale`,`Scale`)},{id:`updates`,label:n(`spoolbuddy.settings.tabUpdates`,`Updates`)},{id:`system`,label:n(`spoolbuddy.settings.tabSystem`,`System`)}];return(0,G.jsxs)(`div`,{className:`h-full flex flex-col p-4`,children:[(0,G.jsx)(`h1`,{className:`text-xl font-semibold text-zinc-100 mb-3`,children:n(`spoolbuddy.nav.settings`,`Settings`)}),(0,G.jsx)(`div`,{className:`flex gap-1 bg-zinc-800/50 rounded-lg p-1 mb-4`,children:s.map(e=>(0,G.jsx)(`button`,{onClick:()=>i(e.id),className:`flex-1 px-2 py-2 rounded-md text-sm font-medium transition-colors min-h-[36px] ${r===e.id?`bg-zinc-700 text-zinc-100`:`text-zinc-500 hover:text-zinc-300`}`,children:e.label},e.id))}),(0,G.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto`,children:o?(0,G.jsxs)(G.Fragment,{children:[r===`device`&&(0,G.jsx)(E2e,{device:o}),r===`display`&&(0,G.jsx)(D2e,{device:o,onBrightnessChange:t}),r===`scale`&&(0,G.jsx)(k2e,{device:o,weight:e.weight,weightStable:e.weightStable,rawAdc:e.rawAdc}),r===`updates`&&(0,G.jsx)(A2e,{device:o}),r===`system`&&(0,G.jsx)(N2e,{device:o})]}):(0,G.jsx)(`div`,{className:`flex items-center justify-center h-32`,children:(0,G.jsx)(`div`,{className:`text-center text-zinc-500`,children:(0,G.jsx)(`p`,{className:`text-sm`,children:n(`spoolbuddy.settings.noDevice`,`No SpoolBuddy device found`)})})})})]})}function F2e({device:e,weight:t,weightStable:n,rawAdc:r}){let{t:i}=U(),[a,o]=(0,y.useState)(!1),[s,c]=(0,y.useState)(`idle`),[l,u]=(0,y.useState)(`500`),[d,f]=(0,y.useState)(null),[p,m]=(0,y.useState)(!1),h=e=>{e===`backspace`?u(e=>e.slice(0,-1)||``):e===`.`&&!l.includes(`.`)?u(e=>e+`.`):e>=`0`&&e<=`9`&&u(t=>t===`0`?e:t+e)};return(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{className:`bg-zinc-800 rounded-lg p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`span`,{className:`text-sm text-zinc-400`,children:i(`spoolbuddy.settings.currentWeight`,`Current weight`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`div`,{className:`w-2 h-2 rounded-full ${n?`bg-green-500`:`bg-amber-500 animate-pulse`}`}),(0,G.jsx)(`span`,{className:`text-lg font-mono text-zinc-200`,children:t===null?`-- g`:`${t.toFixed(1)} g`})]})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-4 mt-3 text-xs`,children:[(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:i(`spoolbuddy.settings.tareOffset`,`Tare offset`)}),(0,G.jsx)(`span`,{className:`text-zinc-400 font-mono`,children:e.tare_offset})]}),(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:i(`spoolbuddy.settings.calFactor`,`Cal. factor`)}),(0,G.jsx)(`span`,{className:`text-zinc-400 font-mono`,children:e.calibration_factor.toFixed(2)})]})]})]}),s===`idle`?(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsx)(`button`,{onClick:async()=>{m(!0);try{await Od.tare(e.device_id)}catch(e){console.error(`Failed to tare:`,e)}finally{m(!1)}},disabled:p,className:`flex-1 px-4 py-2.5 rounded-lg text-sm font-medium bg-zinc-700 text-zinc-200 hover:bg-zinc-600 disabled:opacity-40 transition-colors min-h-[44px]`,children:p?`...`:i(`spoolbuddy.weight.tare`,`Tare`)}),(0,G.jsx)(`button`,{onClick:()=>{c(`tare`)},className:`flex-1 px-4 py-2.5 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 transition-colors min-h-[44px]`,children:i(`spoolbuddy.weight.calibrate`,`Calibrate`)})]}):(0,G.jsxs)(`div`,{className:`bg-zinc-800 border border-zinc-700 rounded-lg p-3 space-y-2`,children:[(0,G.jsx)(`div`,{className:`text-sm font-medium text-zinc-200`,children:s===`tare`?i(`spoolbuddy.settings.calStep1`,`Step 1: Remove all items from the scale`):i(`spoolbuddy.settings.calStep2`,`Step 2: Place known weight on scale`)}),s===`weight`&&(0,G.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-xs text-zinc-400`,children:i(`spoolbuddy.settings.knownWeight`,`Known weight (g)`)}),(0,G.jsxs)(`div`,{className:`flex-1 bg-zinc-900 border border-zinc-600 rounded px-3 py-1.5 text-right text-base font-mono text-zinc-100`,children:[l||`0`,(0,G.jsx)(`span`,{className:`text-zinc-500 ml-1`,children:`g`})]})]}),(0,G.jsx)(`div`,{className:`grid grid-cols-4 gap-1`,children:[`7`,`8`,`9`,`backspace`,`4`,`5`,`6`,`.`,`1`,`2`,`3`,`0`].map(e=>(0,G.jsx)(`button`,{onClick:()=>h(e),className:`py-2 rounded text-sm font-medium transition-colors min-h-[36px] ${e===`backspace`?`bg-zinc-700 text-zinc-300 hover:bg-zinc-600`:`bg-zinc-800 text-zinc-100 hover:bg-zinc-700 border border-zinc-700`}`,children:e===`backspace`?`⌫`:e},e))})]}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsx)(`button`,{onClick:()=>c(`idle`),className:`flex-1 px-4 py-2 rounded-lg text-sm bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors min-h-[40px]`,children:i(`common.cancel`,`Cancel`)}),(0,G.jsx)(`button`,{onClick:async()=>{if(s===`tare`){o(!0);try{f(r),await Od.tare(e.device_id),c(`weight`)}catch(e){console.error(`Failed to tare:`,e)}finally{o(!1)}}else if(s===`weight`){let t=parseFloat(l);if(r===null||!t||t<=0)return;o(!0);try{await Od.setCalibrationFactor(e.device_id,t,r,d??void 0),c(`idle`)}catch(e){console.error(`Failed to calibrate:`,e)}finally{o(!1)}}},disabled:a,className:`flex-1 px-4 py-2 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 disabled:opacity-40 transition-colors min-h-[40px]`,children:a?`...`:s===`tare`?i(`spoolbuddy.settings.setZero`,`Set Zero`):i(`spoolbuddy.settings.calibrateNow`,`Calibrate`)})]})]})]})}function I2e(){let{sbState:e}=lr(),{t}=U(),n=or(),{data:r=[]}=K({queryKey:[`spoolbuddy-devices`],queryFn:()=>Od.getDevices(),refetchInterval:1e4}),i=e.deviceId?r.find(t=>t.device_id===e.deviceId)??r[0]:r[0];return(0,G.jsxs)(`div`,{className:`h-full flex flex-col p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3 mb-4`,children:[(0,G.jsx)(`button`,{onClick:()=>n(`/spoolbuddy/settings`),className:`p-1.5 rounded-lg text-zinc-400 hover:text-zinc-200 hover:bg-zinc-800 transition-colors`,children:(0,G.jsx)(`svg`,{className:`w-5 h-5`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:2,children:(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M15 19l-7-7 7-7`})})}),(0,G.jsx)(`h1`,{className:`text-xl font-semibold text-zinc-100`,children:t(`spoolbuddy.settings.scaleCalibration`,`Scale Calibration`)})]}),(0,G.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto`,children:i?(0,G.jsx)(F2e,{device:i,weight:e.weight,weightStable:e.weightStable,rawAdc:e.rawAdc}):(0,G.jsx)(`div`,{className:`flex items-center justify-center h-32`,children:(0,G.jsx)(`div`,{className:`text-center text-zinc-500`,children:(0,G.jsx)(`p`,{className:`text-sm`,children:t(`spoolbuddy.settings.noDevice`,`No SpoolBuddy device found`)})})})})]})}function L2e({formData:e,printersWithCalibrations:t,selectedProfiles:n,setSelectedProfiles:r,expandedPrinters:i,setExpandedPrinters:a}){let{t:o}=U(),s=e=>{a(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},c=(e,t,n)=>{let i=`${e}:${t}:${n??`null`}`,a=`${e}:${n??`null`}`;r(e=>{let t=new Set(e);if(t.has(i))t.delete(i);else{for(let e of Array.from(t)){let n=e.split(`:`);`${n[0]}:${n[2]}`===a&&t.delete(e)}t.add(i)}return t})},l=()=>{let n=new Set;for(let{printer:r,calibrations:i}of t){if(!r.connected)continue;let t=i.filter(t=>nU(t,e)),a=new Map;for(let e of t){let t=`${e.extruder_id??`null`}`;a.has(t)||a.set(t,[]),a.get(t).push(e)}for(let[e,t]of a)if(t.length>0){let i=[...t].sort((e,t)=>t.k_value-e.k_value)[0];n.add(`${r.id}:${i.cali_idx}:${e}`)}}r(n)};if(!e.material)return(0,G.jsx)(`div`,{className:`p-6 bg-bambu-dark rounded-lg text-center`,children:(0,G.jsx)(`p`,{className:`text-bambu-gray`,children:o(`inventory.selectMaterialFirst`)})});if(t.length===0)return(0,G.jsx)(`div`,{className:`p-6 bg-bambu-dark rounded-lg text-center`,children:(0,G.jsx)(`p`,{className:`text-bambu-gray`,children:o(`inventory.noPrintersConfigured`)})});let u=t.reduce((t,{printer:n,calibrations:r})=>n.connected?t+r.filter(t=>nU(t,e)).length:t,0),d=(e,t)=>{let r=`${e.id}:${t.cali_idx}:${t.extruder_id??`null`}`,i=n.has(r);return(0,G.jsxs)(`label`,{className:`flex items-center gap-3 p-3 rounded-lg cursor-pointer transition-all border ${i?`bg-bambu-green/10 border-bambu-green/30`:`bg-bambu-dark border-transparent hover:bg-bambu-dark/80`}`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:i,onChange:()=>c(String(e.id),t.cali_idx,t.extruder_id),className:`w-4 h-4 rounded border-bambu-dark-tertiary text-bambu-green focus:ring-bambu-green`}),(0,G.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,G.jsx)(`span`,{className:`text-sm font-medium ${i?`text-bambu-green`:`text-white`}`,children:t.name||t.filament_id})}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[t.nozzle_diameter&&(0,G.jsxs)(`span`,{className:`text-xs font-mono px-2 py-0.5 rounded bg-bambu-dark text-bambu-gray`,children:[t.nozzle_diameter,`mm`]}),(0,G.jsxs)(`span`,{className:`text-xs font-mono px-2 py-0.5 rounded bg-bambu-dark text-bambu-gray`,children:[`K=`,t.k_value.toFixed(3)]})]})]},`${t.cali_idx}-${t.extruder_id}`)};return(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`p`,{className:`text-xs text-bambu-gray`,children:[o(`inventory.matchingFilter`),`: `,e.brand||o(`inventory.anyBrand`),` / `,e.material,` / `,e.subtype||o(`inventory.anyVariant`)]}),u>0&&(0,G.jsxs)(`button`,{type:`button`,onClick:l,className:`flex items-center gap-1.5 px-2 py-1 text-xs bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray hover:text-white hover:border-bambu-green transition-colors`,children:[(0,G.jsx)(_u,{className:`w-3.5 h-3.5`}),o(`inventory.autoSelect`),` (`,u,`)`]})]}),(0,G.jsx)(`div`,{className:`space-y-3`,children:t.map(({printer:t,calibrations:n})=>{let r=i.has(String(t.id)),a=n.filter(t=>nU(t,e)),c=a.length,l=a.some(e=>e.extruder_id!==void 0&&e.extruder_id!==null&&e.extruder_id>0),u=a.filter(e=>e.extruder_id===1),f=a.filter(e=>e.extruder_id===0||e.extruder_id===void 0||e.extruder_id===null);return(0,G.jsxs)(`div`,{className:`border border-bambu-dark-tertiary rounded-lg overflow-hidden`,children:[(0,G.jsxs)(`button`,{type:`button`,onClick:()=>s(String(t.id)),className:`w-full px-4 py-3 flex items-center justify-between bg-bambu-dark-secondary hover:bg-bambu-dark-tertiary transition-colors`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[r?(0,G.jsx)(ps,{className:`w-4 h-4 text-bambu-gray`}):(0,G.jsx)(ms,{className:`w-4 h-4 text-bambu-gray`}),(0,G.jsx)(`span`,{className:`font-medium text-white`,children:t.name}),c>0?(0,G.jsxs)(`span`,{className:`text-xs px-2 py-0.5 rounded-full bg-bambu-green/20 text-bambu-green`,children:[c,` `,o(c===1?`inventory.match`:`inventory.matches`)]}):(0,G.jsx)(`span`,{className:`text-xs px-2 py-0.5 rounded-full bg-bambu-dark-tertiary text-bambu-gray`,children:o(`inventory.noMatches`)})]}),(0,G.jsx)(`span`,{className:`text-xs px-2 py-1 rounded-full ${t.connected?`bg-green-500/20 text-green-500`:`bg-bambu-gray/20 text-bambu-gray`}`,children:t.connected?o(`inventory.connected`):o(`inventory.offline`)})]}),r&&(0,G.jsx)(`div`,{className:`px-4 py-3 space-y-3 bg-bambu-dark border-t border-bambu-dark-tertiary`,children:t.connected?c===0?(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray italic py-2`,children:o(`inventory.noKProfilesMatch`)}):l?(0,G.jsxs)(G.Fragment,{children:[u.length>0&&(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`p`,{className:`text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:o(`inventory.leftNozzle`)}),(0,G.jsx)(`div`,{className:`space-y-2`,children:u.map(e=>d(t,e))})]}),f.length>0&&(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`p`,{className:`text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:o(`inventory.rightNozzle`)}),(0,G.jsx)(`div`,{className:`space-y-2`,children:f.map(e=>d(t,e))})]})]}):(0,G.jsx)(`div`,{className:`space-y-2`,children:a.map(e=>d(t,e))}):(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray italic py-2`,children:o(`inventory.printerOffline`)})})]},t.id)})}),n.size>0&&(0,G.jsx)(`div`,{className:`p-3 bg-bambu-green/10 border border-bambu-green/30 rounded-lg`,children:(0,G.jsxs)(`p`,{className:`text-sm text-white`,children:[(0,G.jsx)(`span`,{className:`font-semibold`,children:n.size}),` `,o(`inventory.profilesSelected`)]})})]})}var R2e=[`PLA`,`PETG`,`ABS`,`ASA`,`TPU`,`PA`,`PC`,`PVA`,`HIPS`];function z2e(){let{t:e}=U(),{showToast:t}=qd(),{sbState:n}=lr(),[r,i]=(0,y.useState)(`existing`),[a,o]=(0,y.useState)(null),[s,c]=(0,y.useState)(``),[l,u]=(0,y.useState)(`idle`),[d,f]=(0,y.useState)(``),[p,m]=(0,y.useState)(!1),[h,g]=(0,y.useState)(!1),[_,v]=(0,y.useState)(null),{data:b}=K({queryKey:[`spoolman-settings`],queryFn:Z.getSpoolmanSettings,staleTime:300*1e3}),x=b!==void 0,S=b?.spoolman_enabled===`true`&&!!b?.spoolman_url,{data:C=[],refetch:w}=K({queryKey:[S?`spoolman-inventory-spools`:`inventory-spools`,`write-tag`],queryFn:()=>S?Z.getSpoolmanInventorySpools(!1):Z.getSpools(!1),refetchInterval:1e4,enabled:x}),{data:T=[]}=K({queryKey:[`spoolbuddy-devices`],queryFn:()=>Od.getDevices(),refetchInterval:5e3}),{data:E}=K({queryKey:[`settings`],queryFn:Z.getSettings}),D=T[0],O=n.deviceOnline,k=Lf(E?.currency||`USD`),A=(0,y.useMemo)(()=>{let e;if(r===`existing`)e=C.filter(e=>!e.tag_uid&&!e.archived_at);else if(r===`replace`)e=C.filter(e=>(e.tag_uid||e.tray_uuid)&&!e.archived_at);else return[];if(s){let t=s.toLowerCase();e=e.filter(e=>e.material?.toLowerCase().includes(t)||e.color_name?.toLowerCase().includes(t)||e.brand?.toLowerCase().includes(t)||e.subtype?.toLowerCase().includes(t))}return e},[C,r,s]),j=(0,y.useCallback)(e=>{let t=e.detail;(t.sak??t.data?.sak)===0&&(g(!0),v(t.tag_uid??t.data?.tag_uid??null))},[]),M=(0,y.useCallback)(e=>{let t=e.detail;g(!0),v(t.tag_uid??t.data?.tag_uid??null)},[]),N=(0,y.useCallback)(()=>{g(!1),v(null)},[]),P=(0,y.useCallback)(t=>{let n=t.detail;(n.spool_id===a?.id||n.data?.spool_id===a?.id)&&(u(`success`),f(e(`spoolbuddy.writeTag.writeSuccess`,`Tag written successfully!`)),w(),setTimeout(()=>{u(`idle`),o(null),f(``)},5e3))},[a,e,w]),F=(0,y.useCallback)(t=>{let n=t.detail;(n.spool_id===a?.id||n.data?.spool_id===a?.id)&&(u(`error`),f(n.message??n.data?.message??e(`spoolbuddy.writeTag.writeFailed`,`Write failed`)))},[a,e]);(0,y.useEffect)(()=>(window.addEventListener(`spoolbuddy-unknown-tag`,j),window.addEventListener(`spoolbuddy-tag-matched`,M),window.addEventListener(`spoolbuddy-tag-removed`,N),window.addEventListener(`spoolbuddy-tag-written`,P),window.addEventListener(`spoolbuddy-tag-write-failed`,F),()=>{window.removeEventListener(`spoolbuddy-unknown-tag`,j),window.removeEventListener(`spoolbuddy-tag-matched`,M),window.removeEventListener(`spoolbuddy-tag-removed`,N),window.removeEventListener(`spoolbuddy-tag-written`,P),window.removeEventListener(`spoolbuddy-tag-write-failed`,F)}),[j,M,N,P,F]),(0,y.useEffect)(()=>{o(null),u(`idle`),f(``),c(``)},[r]);let I=async()=>{if(!(!a||!D)){u(`writing`),f(e(`spoolbuddy.writeTag.waiting`,`Waiting for SpoolBuddy...`));try{let e=await Od.writeTag(D.device_id,a.id);if(e?.warnings?.length)for(let n of e.warnings)t(n,`warning`)}catch{u(`error`),f(e(`spoolbuddy.writeTag.queueFailed`,`Failed to queue write command`))}}},L=async()=>{if(D){try{await Od.cancelWrite(D.device_id)}catch{}u(`idle`),f(``)}},R=async()=>{if(!(!a||!B2e(a))){m(!0),u(`idle`),f(``);try{S?await Z.linkTagToSpoolmanSpool(a.id,{tag_uid:``,tray_uuid:``}):await Z.linkTagToSpool(a.id,{tag_uid:``,tray_uuid:``,data_origin:`manual`}),await w(),o(null),u(`success`),f(e(`spoolbuddy.writeTag.untagSuccess`,`Tag removed from spool`)),setTimeout(()=>{u(`idle`),f(``)},2500)}catch{u(`error`),f(e(`spoolbuddy.writeTag.untagFailed`,`Failed to remove tag from spool`))}finally{m(!1)}}},z=(0,y.useCallback)(e=>{o(e),u(`idle`),f(``),w()},[w]),B=a&&O&&l!==`writing`&&l!==`success`;return(0,G.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,G.jsx)(`div`,{className:`flex border-b border-bambu-dark-tertiary shrink-0`,children:[{key:`existing`,label:e(`spoolbuddy.writeTag.tabExisting`,`Existing Spool`)},{key:`new`,label:e(`spoolbuddy.writeTag.tabNew`,`New Spool`)},{key:`replace`,label:e(`spoolbuddy.writeTag.tabReplace`,`Replace Tag`)}].map(e=>(0,G.jsx)(`button`,{onClick:()=>i(e.key),className:`flex-1 py-3 text-sm font-medium transition-colors ${r===e.key?`text-bambu-green border-b-2 border-bambu-green bg-bambu-dark`:`text-zinc-400 hover:text-zinc-200 hover:bg-bambu-dark-tertiary`}`,children:e.label},e.key))}),(0,G.jsxs)(`div`,{className:`flex flex-1 overflow-hidden`,children:[(0,G.jsx)(`div`,{className:`flex-1 flex flex-col overflow-hidden border-r border-bambu-dark-tertiary`,children:r===`new`?(0,G.jsx)(H2e,{currencySymbol:k,onCreated:z,selectedSpool:a,spoolmanMode:S,t:e}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`p-3 shrink-0`,children:(0,G.jsx)(`input`,{type:`text`,value:s,onChange:e=>c(e.target.value),placeholder:e(`spoolbuddy.writeTag.searchPlaceholder`,`Search by material, color, brand...`),className:`w-full px-3 py-2 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-sm text-white placeholder-zinc-500 focus:outline-none focus:border-bambu-green`})}),(0,G.jsx)(`div`,{className:`flex-1 overflow-y-auto px-3 pb-3 space-y-2`,children:A.length===0?(0,G.jsx)(`div`,{className:`text-center text-zinc-500 py-8 text-sm`,children:r===`existing`?e(`spoolbuddy.writeTag.noUntaggedSpools`,`No spools without tags`):e(`spoolbuddy.writeTag.noTaggedSpools`,`No spools with tags`)}):A.map(e=>(0,G.jsx)(V2e,{spool:e,selected:a?.id===e.id,showTag:r===`replace`,onClick:()=>{o(e),u(`idle`),f(``)}},e.id))})]})}),(0,G.jsx)(`div`,{className:`w-[340px] flex flex-col items-center justify-center p-6 shrink-0`,children:(0,G.jsx)(U2e,{writeStatus:l,writeMessage:d,selectedSpool:a,tagOnReader:h,tagUid:_,deviceOnline:O,canWrite:!!B,isReplace:r===`replace`,canUntag:r===`replace`&&!!a&&B2e(a),untagging:p,onWrite:I,onUntag:R,onCancel:L,onRetry:()=>{u(`idle`),f(``)},t:e})})]})]})}function B2e(e){return!!(e.tag_uid||e.tray_uuid)}function V2e({spool:e,selected:t,showTag:n,onClick:r}){let i=Math.max(0,e.label_weight-e.weight_used),a=e.label_weight>0?Math.round(i/e.label_weight*100):0;return(0,G.jsxs)(`button`,{onClick:r,className:`w-full flex items-center gap-3 p-3 rounded-lg text-left transition-colors ${t?`bg-bambu-green/15 border border-bambu-green/50`:`bg-bambu-dark-secondary hover:bg-bambu-dark-tertiary border border-transparent`}`,children:[(0,G.jsx)(`div`,{className:`w-8 h-8 rounded-full shrink-0 border border-white/10`,style:e.rgba?Mf(e.rgba):{backgroundColor:`#666`}}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`span`,{className:`text-sm font-medium text-white truncate`,children:[e.brand?`${e.brand} `:``,e.material,e.subtype?` ${e.subtype}`:``]}),(0,G.jsxs)(`span`,{className:`text-[10px] font-mono text-zinc-500 shrink-0`,children:[`#`,e.id]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-zinc-400`,children:[e.color_name&&(0,G.jsx)(`span`,{children:e.color_name}),(0,G.jsxs)(`span`,{children:[i,`g / `,e.label_weight,`g (`,a,`%)`]})]}),n&&e.tag_uid&&(0,G.jsx)(`div`,{className:`text-xs text-zinc-500 mt-0.5 font-mono`,children:e.tag_uid})]}),t&&(0,G.jsx)(`svg`,{className:`w-5 h-5 text-bambu-green shrink-0`,fill:`currentColor`,viewBox:`0 0 20 20`,children:(0,G.jsx)(`path`,{fillRule:`evenodd`,d:`M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z`,clipRule:`evenodd`})})]})}function H2e({currencySymbol:e,onCreated:t,selectedSpool:n,spoolmanMode:r,t:i}){let{data:a=[]}=K({queryKey:[r?`spoolman-inventory-spools`:`inventory-spools`,`write-tag-form`],queryFn:()=>r?Z.getSpoolmanInventorySpools(!0):Z.getSpools(!0)}),{data:o}=K({queryKey:[`settings`],queryFn:Z.getSettings}),[s,c]=(0,y.useState)(`simple`),[l,u]=(0,y.useState)(`filament`),[d,f]=(0,y.useState)(f9),[p,m]=(0,y.useState)({}),[h,g]=(0,y.useState)(!1),[_,v]=(0,y.useState)(1),[b,x]=(0,y.useState)(!1),[S,C]=(0,y.useState)(null),[w,T]=(0,y.useState)(!1),[E,D]=(0,y.useState)(!1),[O,k]=(0,y.useState)([]),[A,j]=(0,y.useState)([]),[M,N]=(0,y.useState)([]),[P,F]=(0,y.useState)([]),[I,L]=(0,y.useState)([]),[R,z]=(0,y.useState)(``),[B,V]=(0,y.useState)([]),[ee,te]=(0,y.useState)([]),[ne,re]=(0,y.useState)(new Set),[ie,ae]=(0,y.useState)(new Set);(0,y.useEffect)(()=>{V(XH())},[]),(0,y.useEffect)(()=>{let e=!1;return(async()=>{if(s===`full`){D(!0);try{let[t,n]=await Promise.allSettled([(async()=>(await Z.getCloudStatus()).is_authenticated?{connected:!0,presets:await Z.getFilamentPresets()}:{connected:!1,presets:[]})(),(async()=>(await Z.orcaCloudStatus()).connected?{connected:!0,presets:(await Z.orcaCloudListProfiles()).filament}:{connected:!1,presets:[]})()]);if(e)return;let r=t.status===`fulfilled`&&t.value.connected,i=n.status===`fulfilled`&&n.value.connected,a=t.status===`fulfilled`?t.value.presets:[],o=n.status===`fulfilled`?n.value.presets:[];T(r||i),k([...a,...o])}catch{e||T(!1)}finally{e||D(!1)}Z.getSpoolCatalog().then(t=>{e||F(t)}).catch(()=>void 0),Z.getColorCatalog().then(t=>{e||L(t)}).catch(()=>void 0),Z.getLocalPresets().then(t=>{e||j(t.filament)}).catch(()=>void 0),Z.getBuiltinFilaments().then(t=>{e||N(t)}).catch(()=>void 0);try{let t=await Z.getPrinters(),n=await Promise.all(t.map(e=>Z.getPrinterStatus(e.id).catch(()=>null))),r=[];for(let e=0;e{e=!0}},[s]),(0,y.useEffect)(()=>{ee.length>0&&ae(new Set(ee.map(e=>String(e.printer.id))))},[ee]);let oe=(0,y.useMemo)(()=>KH(O,new Set,A,M),[O,A,M]),se=(0,y.useMemo)(()=>qH(d.slicer_filament,oe),[d.slicer_filament,oe]),H=(0,y.useMemo)(()=>{let e=GH(O,A),t=I.map(e=>e.manufacturer?.trim()).filter(e=>!!e);return Array.from(new Set([...e,...t])).sort((e,t)=>e.localeCompare(t))},[O,A,I]),ce=(0,y.useMemo)(()=>{let e=I.map(e=>e.material?.trim()).filter(e=>!!e);return Array.from(new Set([...IH,...e])).sort((e,t)=>e.localeCompare(t))},[I]),le=(0,y.useMemo)(()=>{let e=[];for(let t of I){let n=t.manufacturer?.trim(),r=t.material?.trim();n&&r&&e.push({brand:n,material:r})}for(let t of O){let n=WH(t.name);n.brand&&n.material&&e.push({brand:n.brand,material:n.material})}for(let t of A){let n=WH(t.name),r=t.filament_vendor?.trim()||n.brand,i=n.material;r&&i&&e.push({brand:r,material:i})}return e},[O,I,A]),ue=(0,y.useMemo)(()=>{let e=new Map;for(let t of le){let n=t.brand.toLowerCase(),r=t.material.toLowerCase();e.has(n)||e.set(n,new Set),e.get(n).add(r)}return e},[le]),de=(0,y.useMemo)(()=>{let e=new Map;for(let t of le){let n=t.brand.toLowerCase(),r=t.material.toLowerCase();e.has(r)||e.set(r,new Set),e.get(r).add(n)}return e},[le]),fe=(0,y.useMemo)(()=>JH(H,d.brand),[H,d.brand]),pe=(0,y.useMemo)(()=>JH(ce,d.material),[ce,d.material]),me=(0,y.useMemo)(()=>YH(fe,d.material,de),[fe,d.material,de]),he=(0,y.useMemo)(()=>YH(pe,d.brand,ue),[pe,d.brand,ue]),ge=(e,t)=>{f(n=>({...n,[e]:t})),p[e]&&m(t=>({...t,[e]:void 0}))},_e=e=>{V(t=>ZH(e,t))},ve=async e=>{let t=r?Z.saveSpoolmanKProfiles:Z.saveSpoolKProfiles;if(ne.size===0){try{await t(e,[])}catch{}return}let n=[];for(let e of ne){let[t,r,i]=e.split(`:`),a=parseInt(t),o=parseInt(r),s=i===`null`?0:parseInt(i),c=ee.find(e=>e.printer.id===a);if(c){let e=c.calibrations.find(e=>e.cali_idx===o&&(e.extruder_id??0)===s);e&&n.push({printer_id:a,extruder:s,nozzle_diameter:e.nozzle_diameter||`0.4`,k_value:e.k_value,name:e.name||null,cali_idx:e.cali_idx,setting_id:e.setting_id||null})}}n.length>0&&await t(e,n)},ye=async()=>{C(null);let e=c1e(d,s===`simple`?!0:h);if(!e.isValid){m(e.errors),u(`filament`);return}let n=se?.displayName||R||null,a={material:d.material,subtype:d.subtype||null,brand:d.brand||null,color_name:d.color_name||null,rgba:d.rgba||null,extra_colors:d.extra_colors||null,effect_type:d.effect_type||null,label_weight:d.label_weight,core_weight:d.core_weight,core_weight_catalog_id:d.core_weight_catalog_id,weight_used:d.weight_used,slicer_filament:d.slicer_filament||null,slicer_filament_name:n,nozzle_temp_min:null,nozzle_temp_max:null,note:d.note||null,cost_per_kg:d.cost_per_kg,added_full:null,last_used:null,encode_time:null,tag_uid:null,tray_uuid:null,data_origin:null,tag_type:null,last_scale_weight:null,last_weighed_at:null,category:d.category.trim()||null,low_stock_threshold_pct:d.low_stock_threshold_pct};x(!0);try{if(_>1){let e=r?await Z.bulkCreateSpoolmanInventorySpools(a,_):await Z.bulkCreateSpools(a,_),n=r&&e&&typeof e==`object`&&`created`in e?e.created:e;for(let e of n)await ve(e.id);n.length>0&&t(n[0])}else{let e=r?await Z.createSpoolmanInventorySpool(a):await Z.createSpool(a);await ve(e.id),t(e)}}catch{C(i(`spoolbuddy.writeTag.createFailed`,`Failed to create spool`))}finally{x(!1)}},be=`#${(d.rgba||`808080FF`).slice(0,6)}`;return(0,G.jsxs)(`div`,{className:`p-3 space-y-3 overflow-y-auto h-full`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-2 py-2 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary`,children:[(0,G.jsx)(`span`,{className:`text-sm text-zinc-200`,children:i(`spoolbuddy.writeTag.viewMode`,`View`)}),(0,G.jsxs)(`div`,{className:`flex rounded-lg overflow-hidden border border-bambu-dark-tertiary`,children:[(0,G.jsx)(`button`,{type:`button`,onClick:()=>c(`simple`),className:`px-3 py-1.5 text-xs font-medium ${s===`simple`?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark text-zinc-400`}`,children:i(`spoolbuddy.writeTag.simpleView`,`Simple`)}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>c(`full`),className:`px-3 py-1.5 text-xs font-medium ${s===`full`?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark text-zinc-400`}`,children:i(`spoolbuddy.writeTag.fullView`,`Full`)})]})]}),s===`simple`?n?(0,G.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full p-6 text-center bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg`,children:[(0,G.jsx)(`div`,{className:`w-12 h-12 rounded-full mb-4 border border-white/10`,style:n.rgba?Mf(n.rgba):{backgroundColor:`#666`}}),(0,G.jsxs)(`p`,{className:`text-white font-medium`,children:[n.brand?`${n.brand} `:``,n.material]}),n.color_name&&(0,G.jsx)(`p`,{className:`text-zinc-400 text-sm`,children:n.color_name}),(0,G.jsxs)(`p`,{className:`text-zinc-500 text-xs mt-1`,children:[n.label_weight,`g`]}),(0,G.jsx)(`p`,{className:`text-bambu-green text-sm mt-4`,children:i(`spoolbuddy.writeTag.spoolCreated`,`Spool created! Ready to write.`)})]}):(0,G.jsxs)(`div`,{className:`p-4 space-y-4 overflow-y-auto bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs text-zinc-400 mb-1`,children:i(`spoolbuddy.writeTag.material`,`Material`)}),(0,G.jsx)(`select`,{value:d.material,onChange:e=>ge(`material`,e.target.value),className:`w-full px-3 py-2 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-sm text-white focus:outline-none focus:border-bambu-green`,children:R2e.map(e=>(0,G.jsx)(`option`,{value:e,children:e},e))})]}),(0,G.jsxs)(`div`,{className:`flex gap-3`,children:[(0,G.jsxs)(`div`,{className:`flex-1`,children:[(0,G.jsx)(`label`,{className:`block text-xs text-zinc-400 mb-1`,children:i(`spoolbuddy.writeTag.colorName`,`Color Name`)}),(0,G.jsx)(`input`,{type:`text`,value:d.color_name,onChange:e=>ge(`color_name`,e.target.value),placeholder:`Jade White`,className:`w-full px-3 py-2 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-sm text-white placeholder-zinc-500 focus:outline-none focus:border-bambu-green`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs text-zinc-400 mb-1`,children:i(`spoolbuddy.writeTag.color`,`Color`)}),(0,G.jsx)(`input`,{type:`color`,value:be,onChange:e=>ge(`rgba`,e.target.value.replace(`#`,``).toUpperCase()+`FF`),className:`w-10 h-9 bg-transparent border border-bambu-dark-tertiary rounded cursor-pointer`})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs text-zinc-400 mb-1`,children:i(`spoolbuddy.writeTag.brand`,`Brand`)}),(0,G.jsx)(`input`,{type:`text`,value:d.brand,onChange:e=>ge(`brand`,e.target.value),placeholder:`Polymaker`,className:`w-full px-3 py-2 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-sm text-white placeholder-zinc-500 focus:outline-none focus:border-bambu-green`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs text-zinc-400 mb-1`,children:i(`spoolbuddy.writeTag.weight`,`Weight (g)`)}),(0,G.jsx)(`input`,{type:`number`,value:d.label_weight,onChange:e=>ge(`label_weight`,parseInt(e.target.value)||0),min:0,max:1e4,className:`w-full px-3 py-2 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-sm text-white focus:outline-none focus:border-bambu-green`})]}),(0,G.jsx)(`button`,{onClick:ye,disabled:b||!d.material,className:`w-full py-2.5 bg-bambu-green hover:bg-bambu-green/80 disabled:opacity-50 disabled:cursor-not-allowed text-white text-sm font-medium rounded transition-colors`,children:b?i(`spoolbuddy.writeTag.creating`,`Creating...`):i(`spoolbuddy.writeTag.createSpool`,`Create Spool`)})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-2 py-2 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary`,children:[(0,G.jsx)(`span`,{className:`text-sm text-zinc-200`,children:i(`inventory.quickAdd`,`Quick Add`)}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>g(e=>!e),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors ${h?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,children:(0,G.jsx)(`span`,{className:`inline-block h-4.5 w-4.5 rounded-full bg-white transition-transform ${h?`translate-x-6`:`translate-x-1`}`})})]}),(0,G.jsxs)(`div`,{className:`flex border border-bambu-dark-tertiary rounded-lg overflow-hidden`,children:[(0,G.jsx)(`button`,{onClick:()=>u(`filament`),className:`flex-1 py-2.5 text-sm font-medium ${l===`filament`?`bg-bambu-green/15 text-bambu-green`:`bg-bambu-dark-secondary text-zinc-400`}`,children:i(`inventory.filamentInfoTab`,`Filament`)}),!h&&(0,G.jsx)(`button`,{onClick:()=>u(`pa-profile`),className:`flex-1 py-2.5 text-sm font-medium ${l===`pa-profile`?`bg-bambu-green/15 text-bambu-green`:`bg-bambu-dark-secondary text-zinc-400`}`,children:i(`inventory.paProfileTab`,`PA Profile`)})]}),(0,G.jsx)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg p-3`,children:l===`filament`?(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsx)(f1e,{formData:d,updateField:ge,cloudAuthenticated:w,loadingCloudPresets:E,presetInputValue:R,setPresetInputValue:z,selectedPresetOption:se,filamentOptions:oe,availableBrands:fe,availableMaterials:pe,suggestedBrands:me,suggestedMaterials:he,quickAdd:h,detailsRequired:!h,quantity:_,onQuantityChange:v,errors:p}),(0,G.jsx)(m1e,{formData:d,updateField:ge,recentColors:B,onColorUsed:_e,catalogColors:I}),(0,G.jsx)(g1e,{formData:d,updateField:ge,spoolCatalog:P,currencySymbol:e,availableCategories:Array.from(new Set(a.map(e=>e.category?.trim()).filter(e=>!!e))).sort((e,t)=>e.localeCompare(t)),globalLowStockThreshold:o?.low_stock_threshold??20})]}):(0,G.jsx)(L2e,{formData:d,updateField:ge,printersWithCalibrations:ee,selectedProfiles:ne,setSelectedProfiles:re,expandedPrinters:ie,setExpandedPrinters:ae})})]}),S&&(0,G.jsx)(`div`,{className:`text-sm text-red-400 bg-red-900/20 border border-red-900/40 rounded-lg px-3 py-2`,children:S}),s===`full`&&(0,G.jsx)(`button`,{onClick:ye,disabled:b,className:`w-full py-3 bg-bambu-green hover:bg-bambu-green/80 disabled:opacity-50 disabled:cursor-not-allowed text-white text-sm font-medium rounded transition-colors`,children:b?i(`spoolbuddy.writeTag.creating`,`Creating...`):i(`spoolbuddy.writeTag.createSpool`,`Create Spool`)}),s===`full`&&n&&(0,G.jsxs)(`div`,{className:`flex flex-col items-center justify-center p-4 text-center bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg`,children:[(0,G.jsx)(`div`,{className:`w-12 h-12 rounded-full mb-4 border border-white/10`,style:n.rgba?Mf(n.rgba):{backgroundColor:`#666`}}),(0,G.jsxs)(`p`,{className:`text-white font-medium`,children:[n.brand?`${n.brand} `:``,n.material]}),n.color_name&&(0,G.jsx)(`p`,{className:`text-zinc-400 text-sm`,children:n.color_name}),(0,G.jsxs)(`p`,{className:`text-zinc-500 text-xs mt-1`,children:[n.label_weight,`g`]}),(0,G.jsx)(`p`,{className:`text-bambu-green text-sm mt-4`,children:i(`spoolbuddy.writeTag.spoolCreated`,`Spool created! Ready to write.`)})]})]})}function U2e({writeStatus:e,writeMessage:t,selectedSpool:n,tagOnReader:r,tagUid:i,deviceOnline:a,canWrite:o,isReplace:s,canUntag:c,untagging:l,onWrite:u,onUntag:d,onCancel:f,onRetry:p,t:m}){if(e===`success`)return(0,G.jsxs)(`div`,{className:`flex flex-col items-center text-center space-y-4`,children:[(0,G.jsx)(`div`,{className:`w-16 h-16 rounded-full bg-green-500/20 flex items-center justify-center`,children:(0,G.jsx)(`svg`,{className:`w-8 h-8 text-green-400`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M5 13l4 4L19 7`})})}),(0,G.jsx)(`p`,{className:`text-green-400 font-medium`,children:t}),n&&(0,G.jsxs)(`p`,{className:`text-zinc-400 text-sm`,children:[n.brand?`${n.brand} `:``,n.material,n.subtype?` ${n.subtype}`:``,n.color_name?` - ${n.color_name}`:``]})]});if(e===`error`)return(0,G.jsxs)(`div`,{className:`flex flex-col items-center text-center space-y-4`,children:[(0,G.jsx)(`div`,{className:`w-16 h-16 rounded-full bg-red-500/20 flex items-center justify-center`,children:(0,G.jsx)(`svg`,{className:`w-8 h-8 text-red-400`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M6 18L18 6M6 6l12 12`})})}),(0,G.jsx)(`p`,{className:`text-red-400 font-medium`,children:t}),(0,G.jsx)(`button`,{onClick:p,className:`px-4 py-2 bg-bambu-dark-tertiary hover:bg-bambu-dark-secondary text-white text-sm rounded transition-colors`,children:m(`spoolbuddy.writeTag.tryAgain`,`Try Again`)})]});if(e===`writing`)return(0,G.jsxs)(`div`,{className:`flex flex-col items-center text-center space-y-4`,children:[(0,G.jsxs)(`div`,{className:`relative w-16 h-16`,children:[(0,G.jsx)(`div`,{className:`absolute inset-0 rounded-full border-2 border-bambu-green/30 animate-ping`}),(0,G.jsx)(`div`,{className:`absolute inset-2 rounded-full border-2 border-bambu-green/50 animate-pulse`}),(0,G.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center`,children:(0,G.jsx)(Z9,{className:`w-8 h-8 text-bambu-green`})})]}),(0,G.jsx)(`p`,{className:`text-bambu-green font-medium`,children:m(`spoolbuddy.writeTag.writing`,`Writing tag...`)}),(0,G.jsx)(`p`,{className:`text-zinc-500 text-xs`,children:t}),(0,G.jsx)(`button`,{onClick:f,className:`px-4 py-2 bg-bambu-dark-tertiary hover:bg-bambu-dark-secondary text-zinc-400 text-sm rounded transition-colors`,children:m(`spoolbuddy.writeTag.cancel`,`Cancel`)})]});if(!a)return(0,G.jsxs)(`div`,{className:`flex flex-col items-center text-center space-y-3`,children:[(0,G.jsx)(Z9,{className:`w-12 h-12 text-zinc-600`}),(0,G.jsx)(`p`,{className:`text-zinc-500 text-sm`,children:m(`spoolbuddy.writeTag.deviceOffline`,`SpoolBuddy is offline`)})]});if(!n)return(0,G.jsxs)(`div`,{className:`flex flex-col items-center text-center space-y-3`,children:[(0,G.jsx)(Z9,{className:`w-12 h-12 text-zinc-600`}),(0,G.jsx)(`p`,{className:`text-zinc-400 text-sm`,children:m(`spoolbuddy.writeTag.selectSpool`,`Select a spool, then place a blank NTAG on the reader`)})]});let h=n.rgba?Mf(n.rgba):{backgroundColor:`#666`};return(0,G.jsxs)(`div`,{className:`flex flex-col items-center text-center space-y-4 w-full`,children:[(0,G.jsx)(`div`,{className:`relative w-16 h-16`,children:r?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`absolute inset-0 rounded-full bg-bambu-green/10`}),(0,G.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center`,children:(0,G.jsx)(Z9,{className:`w-8 h-8 text-bambu-green`})})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`absolute inset-0 rounded-full border-2 border-zinc-600 animate-pulse`}),(0,G.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center`,children:(0,G.jsx)(Z9,{className:`w-8 h-8 text-zinc-500`})})]})}),r?(0,G.jsxs)(`div`,{className:`space-y-1`,children:[(0,G.jsx)(`p`,{className:`text-bambu-green text-sm font-medium`,children:m(`spoolbuddy.writeTag.tagReady`,`Tag detected — ready to write`)}),i&&(0,G.jsx)(`p`,{className:`text-zinc-500 text-xs font-mono`,children:i})]}):(0,G.jsx)(`p`,{className:`text-zinc-400 text-sm`,children:m(`spoolbuddy.writeTag.placeTag`,`Place an NTAG on the reader`)}),(0,G.jsxs)(`div`,{className:`w-full bg-bambu-dark-secondary rounded-lg p-3 space-y-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`w-8 h-8 rounded-full border border-white/10 shrink-0`,style:h}),(0,G.jsxs)(`div`,{className:`text-left min-w-0`,children:[(0,G.jsxs)(`p`,{className:`text-white text-sm font-medium truncate`,children:[n.brand?`${n.brand} `:``,n.material]}),n.color_name&&(0,G.jsx)(`p`,{className:`text-zinc-400 text-xs`,children:n.color_name})]})]}),(0,G.jsxs)(`div`,{className:`text-xs text-zinc-500`,children:[n.label_weight,`g`]})]}),s&&n.tag_uid&&(0,G.jsx)(`p`,{className:`text-yellow-500/80 text-xs`,children:m(`spoolbuddy.writeTag.replaceWarning`,`Old tag will be unlinked. New tag will replace it.`)}),(0,G.jsx)(`button`,{onClick:u,disabled:!o,className:`w-full py-3 bg-bambu-green hover:bg-bambu-green/80 disabled:opacity-40 disabled:cursor-not-allowed text-white font-medium rounded-lg transition-colors text-sm`,children:s?m(`spoolbuddy.writeTag.replaceTag`,`Replace Tag`):m(`spoolbuddy.writeTag.writeTag`,`Write Tag`)}),s&&c&&(0,G.jsx)(`button`,{onClick:d,disabled:l,className:`w-full py-2.5 bg-bambu-dark-tertiary hover:bg-bambu-dark-secondary disabled:opacity-40 disabled:cursor-not-allowed text-zinc-200 rounded-lg transition-colors text-sm`,children:l?m(`spoolbuddy.writeTag.untagging`,`Removing tag...`):m(`spoolbuddy.writeTag.untagSpool`,`Untag Selected Spool`)})]})}function Z9({className:e}){return(0,G.jsxs)(`svg`,{className:e,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:1.5,children:[(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M8.288 15.038a5.25 5.25 0 017.424 0M5.106 11.856c3.807-3.808 9.98-3.808 13.788 0M1.924 8.674c5.565-5.565 14.587-5.565 20.152 0`}),(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M12.53 18.22l-.53.53-.53-.53a.75.75 0 011.06 0z`})]})}var W2e=`spoolbuddy-default-core-weight`;function G2e(){try{let e=localStorage.getItem(W2e);if(e){let t=parseInt(e,10);if(t>=0&&t<=500)return t}}catch{}return 250}function K2e({spool:e,liveScaleWeight:t,persistedGrossWeight:n,onClose:r,onSyncWeight:i,onAssignToAms:a,isAssigned:o,onUnassignFromAms:s,className:c}){let{t:l}=U(),[u,d]=(0,y.useState)(!1),[f,p]=(0,y.useState)(!1),[m,h]=(0,y.useState)(null),{data:g}=K({queryKey:[`spool-k-profiles`,e.id],queryFn:()=>Z.getSpoolKProfiles(e.id),enabled:!e.k_profiles||e.k_profiles.length===0,staleTime:300*1e3}),_=e.k_profiles&&e.k_profiles.length>0?e.k_profiles:g,v=Af(e.rgba),b=e.core_weight&&e.core_weight>0?e.core_weight:G2e(),x=t===null?null:Math.round(Math.max(0,t)),S=m??(n===void 0?x:n===null?null:Math.round(Math.max(0,n))),C=Math.round(Math.max(0,(e.label_weight||0)-(e.weight_used||0))),w=x!==null&&x>=10?Math.round(Math.max(0,x-b)):C,T=Math.round(e.label_weight||1e3),E=T>0?Math.min(100,Math.round(w/T*100)):null,D=E===null?`#808080`:E>50?`#22c55e`:E>20?`#eab308`:`#ef4444`,O=Math.max(0,(e.label_weight||0)-(e.weight_used||0))+b,k=x===null?null:x-O,A=k===null?null:Math.abs(k)<=50,j=S??Math.round(O),M=e.nozzle_temp_min!=null&&e.nozzle_temp_max!=null?`${e.nozzle_temp_min}-${e.nozzle_temp_max}\u00B0C`:null,N=e.slicer_filament_name||e.slicer_filament||null,P=e.note?.trim()||null,F=_&&_.length>0?Array.from(new Set(_.map(e=>e.k_value.toFixed(3)))).join(`, `):null,I=async()=>{if(t===null)return;let n=Math.round(Math.max(0,t));d(!0);try{await Od.updateSpoolWeight(e.id,n),h(n),p(!0),i?.(),setTimeout(()=>p(!1),3e3)}catch(e){console.error(`Failed to sync weight:`,e)}finally{d(!1)}};return(0,G.jsxs)(`div`,{className:`flex flex-col items-center space-y-4 max-w-md ${c??``}`,children:[(0,G.jsxs)(`div`,{className:`flex items-start gap-5`,children:[(0,G.jsxs)(`div`,{className:`relative shrink-0`,children:[(0,G.jsx)(W9,{color:v,isEmpty:!1,size:100}),E!==null&&(0,G.jsxs)(`div`,{className:`absolute -bottom-2 -right-2 px-2 py-0.5 rounded-full text-xs font-bold text-white shadow-lg`,style:{backgroundColor:D},children:[E,`%`]})]}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0 pt-1`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`h3`,{className:`text-lg font-semibold text-zinc-100`,children:e.color_name||`Unknown color`}),(0,G.jsxs)(`span`,{className:`text-xs font-mono text-zinc-500 shrink-0`,children:[`#`,e.id]})]}),(0,G.jsxs)(`p`,{className:`text-sm text-zinc-400`,children:[e.brand,` • `,e.material,e.subtype&&` ${e.subtype}`]}),(0,G.jsxs)(`div`,{className:`mt-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,G.jsxs)(`span`,{className:`text-3xl font-bold font-mono text-zinc-100`,children:[w,`g`]}),(0,G.jsxs)(`span`,{className:`text-sm text-zinc-500`,children:[`/ `,T,`g`]})]}),(0,G.jsx)(`p`,{className:`text-xs text-zinc-500 mt-0.5`,children:l(`spoolbuddy.spool.remaining`,`Remaining`)}),(0,G.jsx)(`div`,{className:`mt-2 max-w-xs`,children:(0,G.jsx)(`div`,{className:`h-2 bg-zinc-700 rounded-full overflow-hidden`,children:(0,G.jsx)(`div`,{className:`h-full rounded-full transition-all duration-500`,style:{width:`${E??0}%`,backgroundColor:D}})})})]})]})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-x-6 gap-y-2 text-sm bg-zinc-800 rounded-lg p-4 w-full`,children:[(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:l(`spoolbuddy.dashboard.grossWeight`,`Gross weight`)}),(0,G.jsxs)(`span`,{className:`font-mono text-zinc-300`,children:[j,`g`]})]}),(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:l(`spoolbuddy.spool.coreWeight`,`Core`)}),(0,G.jsxs)(`span`,{className:`font-mono text-zinc-300`,children:[b,`g`]})]}),(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:l(`spoolbuddy.dashboard.spoolSize`,`Spool size`)}),(0,G.jsxs)(`span`,{className:`font-mono text-zinc-300`,children:[T,`g`]})]}),(0,G.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:l(`spoolbuddy.spool.scaleWeight`,`Scale`)}),x===null?(0,G.jsx)(`span`,{className:`text-zinc-500`,children:`—`}):(0,G.jsxs)(`span`,{className:`flex items-center gap-1 font-mono ${A?`text-green-500`:`text-yellow-500`}`,children:[x,`g`,A?(0,G.jsx)(fs,{className:`w-3.5 h-3.5`}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Lu,{className:`w-3.5 h-3.5`}),(0,G.jsx)(`button`,{onClick:I,className:`p-1 hover:bg-green-500/20 rounded transition-colors text-green-500`,title:l(`spoolbuddy.dashboard.syncWeight`,`Sync Weight`),children:(0,G.jsx)(Hl,{className:`w-4 h-4`})})]})]})]}),(0,G.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:l(`spoolbuddy.dashboard.tagId`,`Tag`)}),(0,G.jsx)(`span`,{className:`font-mono text-xs text-zinc-400 truncate max-w-[120px]`,title:e.tag_uid||``,children:e.tag_uid?e.tag_uid.slice(-8):`—`})]}),M&&(0,G.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:l(`spoolbuddy.inventory.nozzleTemp`,`Nozzle`)}),(0,G.jsx)(`span`,{className:`font-mono text-zinc-300`,children:M})]}),e.cost_per_kg!=null&&e.cost_per_kg>0&&(0,G.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:l(`spoolbuddy.inventory.costPerKg`,`Cost/kg`)}),(0,G.jsxs)(`span`,{className:`font-mono text-zinc-300`,children:[e.cost_per_kg.toFixed(2),`/kg`]})]}),F&&(0,G.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,G.jsx)(`span`,{className:`text-zinc-500`,children:l(`spoolbuddy.inventory.kProfiles`,`K-Profile`)}),(0,G.jsx)(`span`,{className:`font-mono text-zinc-300 truncate max-w-[220px] text-right`,title:F,children:F})]}),N&&(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsx)(`p`,{className:`text-xs text-zinc-500 mb-1`,children:l(`spoolbuddy.inventory.slicerFilament`,`Slicer Filament`)}),(0,G.jsx)(`p`,{className:`text-sm text-zinc-300 whitespace-pre-wrap break-words`,children:N})]}),P&&(0,G.jsxs)(`div`,{className:`col-span-2`,children:[(0,G.jsx)(`p`,{className:`text-xs text-zinc-500 mb-1`,children:l(`spoolbuddy.inventory.note`,`Note`)}),(0,G.jsx)(`p`,{className:`text-sm leading-5 text-zinc-300 whitespace-pre-wrap break-words max-h-[3.75rem] overflow-y-auto pr-1`,children:P})]})]}),(0,G.jsxs)(`div`,{className:`flex gap-2 justify-center`,children:[a&&(0,G.jsx)(`button`,{onClick:o?void 0:a,disabled:!!o,className:`px-5 py-2.5 rounded-lg text-sm font-medium bg-green-600 text-white hover:bg-green-700 transition-colors min-h-[44px] disabled:opacity-50 disabled:cursor-not-allowed`,children:l(`spoolbuddy.modal.assignToAms`,`Assign to AMS`)}),s&&(0,G.jsxs)(`button`,{onClick:s,className:`px-5 py-2.5 rounded-lg text-sm font-medium bg-red-600/20 text-red-400 hover:bg-red-600/30 transition-colors min-h-[44px]`,children:[(0,G.jsx)(Bu,{className:`w-4 h-4 inline mr-1`}),l(`inventory.unassignSpool`)]}),(0,G.jsx)(`button`,{onClick:I,disabled:t===null||u,className:`px-5 py-2.5 rounded-lg text-sm font-medium transition-colors min-h-[44px] ${f?`bg-green-600/20 text-green-400`:a?`bg-zinc-700 text-zinc-300 hover:bg-zinc-600 disabled:opacity-40 disabled:cursor-not-allowed`:`bg-green-600 text-white hover:bg-green-700 disabled:opacity-40 disabled:cursor-not-allowed`}`,children:u?`...`:f?l(`spoolbuddy.dashboard.weightSynced`,`Synced!`):l(`spoolbuddy.dashboard.syncWeight`,`Sync Weight`)}),r&&(0,G.jsx)(`button`,{onClick:r,className:`px-5 py-2.5 rounded-lg text-sm font-medium bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors min-h-[44px]`,children:l(`spoolbuddy.dashboard.close`,`Close`)})]})]})}function q2e(e){return Af(e.rgba)}function J2e(e){return Math.max(0,e.label_weight-e.weight_used)}function Y2e(e){return e.label_weight<=0?0:Math.max(0,Math.min(100,(e.label_weight-e.weight_used)/e.label_weight*100))}function X2e(e){let t=[e.material];return e.subtype&&t.push(e.subtype),t.join(` `)}function Z2e(e){let t=e.ams_id===254||e.ams_id===255,n=!t&&e.ams_id>=128;return jp(e.ams_id,e.tray_id,n,t)}function Q2e({color:e,size:t=56}){return(0,G.jsxs)(`svg`,{width:t,height:t,viewBox:`0 0 56 56`,children:[(0,G.jsx)(`circle`,{cx:`28`,cy:`28`,r:`26`,fill:e}),(0,G.jsx)(`circle`,{cx:`28`,cy:`28`,r:`20`,fill:e,style:{filter:`brightness(0.85)`}}),(0,G.jsx)(`ellipse`,{cx:`20`,cy:`20`,rx:`6`,ry:`4`,fill:`white`,opacity:`0.3`}),(0,G.jsx)(`circle`,{cx:`28`,cy:`28`,r:`8`,fill:`#2d2d2d`}),(0,G.jsx)(`circle`,{cx:`28`,cy:`28`,r:`5`,fill:`#1a1a1a`})]})}function $2e(){let{sbState:e,selectedPrinterId:t}=lr(),{t:n}=U(),{showToast:r}=qd(),i=co(),[a,o]=(0,y.useState)(``),[s,c]=(0,y.useState)(`all`),[l,u]=(0,y.useState)(null),[d,f]=(0,y.useState)(!1),{data:p}=K({queryKey:[`spoolman-settings`],queryFn:Z.getSpoolmanSettings,staleTime:300*1e3}),m=p?.spoolman_enabled===`true`&&!!p?.spoolman_url,{data:h=[],isLoading:g,refetch:_}=K({queryKey:m?[`spoolman-inventory-spools`]:[`inventory-spools`],queryFn:()=>m?Z.getSpoolmanInventorySpools(!1):Z.getSpools(!1),enabled:p!==void 0,refetchInterval:3e4}),{data:v=[]}=K({queryKey:[`spool-assignments`],queryFn:()=>Z.getAssignments(),refetchInterval:3e4,enabled:!m}),{data:b=[]}=K({queryKey:[`spoolman-slot-assignments`],queryFn:()=>Z.getSpoolmanSlotAssignments(),refetchInterval:3e4,enabled:m}),x=q({mutationFn:e=>Z.unassignSpoolmanSlot(e),onSuccess:()=>{i.invalidateQueries({queryKey:[`spoolman-slot-assignments`]}),i.invalidateQueries({queryKey:[`spoolman-inventory-spools`]})},onError:()=>r(n(`inventory.unassignFailed`,`Failed to unassign spool`),`error`)}),S=(0,y.useMemo)(()=>{if(m){let e={};return b.forEach(t=>{e[t.spoolman_spool_id]={ams_id:t.ams_id,tray_id:t.tray_id}}),e}let e={};return v.forEach(t=>{e[t.spool_id]={ams_id:t.ams_id,tray_id:t.tray_id,printer_name:t.printer_name}}),e},[m,v,b]),C=(0,y.useMemo)(()=>h.filter(e=>!e.archived_at),[h]),w=(0,y.useMemo)(()=>new Set(Object.keys(S).map(Number)),[S]),T=(0,y.useMemo)(()=>C.filter(e=>w.has(e.id)).length,[C,w]),E=(0,y.useMemo)(()=>{let e=new Set;return C.forEach(t=>e.add(t.material)),Array.from(e).sort()},[C]),D=(0,y.useMemo)(()=>{let e=C;return s===`in_ams`?e=e.filter(e=>w.has(e.id)):s!==`all`&&(e=e.filter(e=>e.material===s)),e=wH(e,a.trim()),[...e].sort((e,t)=>{let n=+!w.has(e.id),r=+!w.has(t.id);return n===r?new Date(t.updated_at).getTime()-new Date(e.updated_at).getTime():n-r})},[C,s,a,w]);return(0,G.jsxs)(`div`,{className:`h-full flex flex-col`,children:[(0,G.jsxs)(`div`,{className:`px-3 pt-3 pb-2 space-y-2.5`,children:[(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(Ql,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-white/40`}),(0,G.jsx)(`input`,{type:`text`,value:a,onChange:e=>o(e.target.value),placeholder:n(`spoolbuddy.inventory.searchPlaceholder`,`Search spools...`),className:`w-full pl-9 pr-8 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-sm text-white placeholder-white/30 focus:outline-none focus:border-bambu-green`}),a&&(0,G.jsx)(`button`,{onClick:()=>o(``),className:`absolute right-2 top-1/2 -translate-y-1/2 text-white/40 hover:text-white/60`,children:(0,G.jsx)(nd,{className:`w-4 h-4`})})]}),(0,G.jsxs)(`div`,{className:`flex gap-1.5 overflow-x-auto no-scrollbar`,children:[(0,G.jsx)(Q9,{active:s===`all`,onClick:()=>c(`all`),label:`${n(`spoolbuddy.inventory.all`,`All`)} (${C.length})`,green:!0}),T>0&&(0,G.jsx)(Q9,{active:s===`in_ams`,onClick:()=>c(`in_ams`),label:`${n(`spoolbuddy.inventory.inAms`,`In AMS`)} (${T})`}),E.map(e=>(0,G.jsx)(Q9,{active:s===e,onClick:()=>c(s===e?`all`:e),label:e},e))]})]}),(0,G.jsx)(`div`,{className:`flex-1 overflow-y-auto px-3 pb-3`,children:g?(0,G.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,G.jsx)(`div`,{className:`w-8 h-8 border-2 border-bambu-green border-t-transparent rounded-full animate-spin`})}):D.length===0?(0,G.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-16 text-white/30`,children:[(0,G.jsx)(Cl,{className:`w-12 h-12 mb-3`}),(0,G.jsx)(`p`,{className:`text-sm`,children:a||s!==`all`?n(`spoolbuddy.inventory.noResults`,`No spools match your filters`):n(`spoolbuddy.inventory.empty`,`No spools in inventory`)})]}):(0,G.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(130px,1fr))] gap-2`,children:D.map(e=>(0,G.jsx)(e4e,{spool:e,assignment:S[e.id],onClick:()=>u(e.id)},e.id))})}),l!=null&&(()=>{let n=h.find(e=>e.id===l);return n?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(t4e,{spool:n,assignment:S[n.id],sbState:e,onSyncWeight:()=>{_()},onAssignToAms:()=>f(!0),onUnassignFromAms:m&&S[n.id]?()=>x.mutate(n.id):void 0,onClose:()=>{u(null),f(!1)}}),(0,G.jsx)(Y9,{isOpen:d,onClose:()=>f(!1),spool:n,printerId:t,spoolmanMode:m})]}):null})()]})}function Q9({active:e,onClick:t,label:n,green:r}){return(0,G.jsx)(`button`,{onClick:t,className:`px-4 py-1.5 rounded-full text-sm font-medium border whitespace-nowrap shrink-0 transition-colors ${e?r?`bg-bambu-green/20 text-bambu-green border-bambu-green/50`:`bg-white/10 text-white border-white/20`:`bg-transparent text-white/40 border-bambu-dark-tertiary hover:text-white/60`}`,children:n})}function e4e({spool:e,assignment:t,onClick:n}){let r=q2e(e),i=Y2e(e),a=J2e(e),o=kf(e.color_name,e.rgba);return(0,G.jsxs)(`button`,{onClick:n,className:`bg-bambu-dark-secondary rounded-xl p-3 flex flex-col items-center text-center gap-1.5 border border-transparent hover:border-bambu-green/50 transition-colors`,children:[(0,G.jsx)(Q2e,{color:r,size:56}),(0,G.jsx)(`p`,{className:`text-xs font-semibold text-white leading-tight truncate w-full`,children:X2e(e)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1 min-w-0 max-w-full`,children:[(0,G.jsx)(`span`,{className:`w-2.5 h-2.5 rounded-full shrink-0 border border-white/10`,style:Mf(e.rgba)}),(0,G.jsx)(`span`,{className:`text-[11px] text-white/50 truncate`,children:o||`-`})]}),(0,G.jsxs)(`div`,{className:`w-full space-y-0.5`,children:[(0,G.jsx)(`div`,{className:`h-1.5 bg-bambu-dark-tertiary rounded-full overflow-hidden`,children:(0,G.jsx)(`div`,{className:`h-full rounded-full ${i>50?`bg-bambu-green`:i>20?`bg-yellow-500`:`bg-red-500`}`,style:{width:`${Math.min(i,100)}%`}})}),(0,G.jsxs)(`p`,{className:`text-[11px] text-white/40`,children:[Math.round(a),`g (`,Math.round(i),`%)`]})]}),t&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 rounded text-[10px] font-bold bg-bambu-green/20 text-bambu-green`,children:Z2e(t)})]})}function t4e({spool:e,assignment:t,sbState:n,onSyncWeight:r,onAssignToAms:i,onUnassignFromAms:a,onClose:o}){let s=n.deviceOnline&&n.weight!==null?Math.round(n.weight):null,c=e.last_scale_weight==null?null:Math.round(e.last_scale_weight);return(0,G.jsx)(`div`,{className:`fixed inset-0 z-50 bg-black/70 flex items-center justify-center p-4`,onClick:o,children:(0,G.jsx)(`div`,{className:`w-full max-w-md bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-2xl p-4 overflow-y-auto max-h-[90vh]`,onClick:e=>e.stopPropagation(),children:(0,G.jsxs)(`div`,{className:`space-y-3`,children:[t&&(0,G.jsxs)(`div`,{className:`flex items-center justify-center gap-2`,children:[(0,G.jsx)(`span`,{className:`px-2.5 py-1 rounded-md text-xs font-bold bg-bambu-green/20 text-bambu-green`,children:Z2e(t)}),t.printer_name&&(0,G.jsx)(`span`,{className:`text-xs text-zinc-400`,children:t.printer_name})]}),(0,G.jsx)(`div`,{className:`flex justify-center`,children:(0,G.jsx)(K2e,{spool:e,liveScaleWeight:s,persistedGrossWeight:c,onSyncWeight:r,onAssignToAms:i,isAssigned:!!t,onUnassignFromAms:a,onClose:o,className:`max-w-md`})})]})})})}var n4e=class extends y.Component{state={error:null,errorInfo:null};static getDerivedStateFromError(e){return{error:e}}componentDidCatch(e,t){this.setState({errorInfo:t}),console.error(`React crash:`,e,t)}render(){return this.state.error?(0,G.jsxs)(`div`,{style:{padding:24,color:`#ef4444`,backgroundColor:`#18181b`,minHeight:`100vh`,fontFamily:`monospace`},children:[(0,G.jsx)(`h1`,{style:{fontSize:20,marginBottom:12},children:`UI Crash`}),(0,G.jsx)(`pre`,{style:{whiteSpace:`pre-wrap`,fontSize:14},children:this.state.error.message}),(0,G.jsx)(`pre`,{style:{whiteSpace:`pre-wrap`,fontSize:12,color:`#a1a1aa`,marginTop:12},children:this.state.error.stack}),(0,G.jsx)(`button`,{onClick:()=>{this.setState({error:null,errorInfo:null})},style:{marginTop:16,padding:`8px 16px`,backgroundColor:`#3b82f6`,color:`#fff`,border:`none`,borderRadius:8,cursor:`pointer`},children:`Retry`})]}):this.props.children}},r4e=new ao({defaultOptions:{queries:{staleTime:1e3*60,retry:1}}});function i4e(){return x$e(),null}function a4e({children:e}){return C0e(),O0e(),(0,G.jsx)(G.Fragment,{children:e})}function o4e({children:e}){let{authEnabled:t,loading:n,user:r}=Nd(),i=rr();return n?(0,G.jsx)(`div`,{className:`min-h-screen flex items-center justify-center`,children:`Loading...`}):t&&!r?(0,G.jsx)(Fr,{to:`/login`,replace:!0,state:{from:i}}):(0,G.jsx)(G.Fragment,{children:e})}function $9({permission:e,children:t}){let{authEnabled:n,loading:r,user:i,hasPermission:a}=Nd(),o=rr();return r?(0,G.jsx)(`div`,{className:`min-h-screen flex items-center justify-center`,children:`Loading...`}):n?i?a(e)?(0,G.jsx)(G.Fragment,{children:t}):(0,G.jsx)(Fr,{to:`/`,replace:!0}):(0,G.jsx)(Fr,{to:`/login`,replace:!0,state:{from:o}}):(0,G.jsx)(G.Fragment,{children:t})}function s4e({children:e}){let{authEnabled:t,loading:n}=Nd();return n?(0,G.jsx)(`div`,{className:`min-h-screen flex items-center justify-center`,children:`Loading...`}):t?(0,G.jsx)(Fr,{to:`/login`,replace:!0}):(0,G.jsx)(G.Fragment,{children:e})}function c4e(){return(0,G.jsx)(n4e,{children:(0,G.jsx)(rf,{children:(0,G.jsx)(lo,{client:r4e,children:(0,G.jsx)(Md,{children:(0,G.jsx)(Fd,{children:(0,G.jsx)(k0e,{children:(0,G.jsxs)(kAe,{children:[(0,G.jsx)(i4e,{}),(0,G.jsx)(Oi,{children:(0,G.jsxs)(zr,{children:[(0,G.jsx)(Lr,{path:`/setup`,element:(0,G.jsx)(s4e,{children:(0,G.jsx)(y0e,{})})}),(0,G.jsx)(Lr,{path:`/login`,element:(0,G.jsx)(v0e,{})}),(0,G.jsx)(Lr,{path:`/camera/:printerId`,element:(0,G.jsx)(T$e,{})}),(0,G.jsx)(Lr,{path:`/overlay/:printerId`,element:(0,G.jsx)(V$e,{})}),(0,G.jsx)(Lr,{path:`/camwall`,element:(0,G.jsx)(F$e,{})}),(0,G.jsxs)(Lr,{element:(0,G.jsx)(o4e,{children:(0,G.jsx)(a4e,{children:(0,G.jsx)(U0e,{})})}),children:[(0,G.jsx)(Lr,{path:`spoolbuddy`,element:(0,G.jsx)(_2e,{})}),(0,G.jsx)(Lr,{path:`spoolbuddy/ams`,element:(0,G.jsx)(x2e,{})}),(0,G.jsx)(Lr,{path:`spoolbuddy/write-tag`,element:(0,G.jsx)(z2e,{})}),(0,G.jsx)(Lr,{path:`spoolbuddy/inventory`,element:(0,G.jsx)($2e,{})}),(0,G.jsx)(Lr,{path:`spoolbuddy/settings`,element:(0,G.jsx)(P2e,{})}),(0,G.jsx)(Lr,{path:`spoolbuddy/calibration`,element:(0,G.jsx)(I2e,{})})]}),(0,G.jsxs)(Lr,{element:(0,G.jsx)(o4e,{children:(0,G.jsx)(a4e,{children:(0,G.jsx)(gee,{})})}),children:[(0,G.jsx)(Lr,{index:!0,element:(0,G.jsx)(wAe,{})}),(0,G.jsx)(Lr,{path:`archives`,element:(0,G.jsx)(LVe,{})}),(0,G.jsx)(Lr,{path:`queue`,element:(0,G.jsx)(KUe,{})}),(0,G.jsx)(Lr,{path:`pipelines/runs`,element:(0,G.jsx)(Fr,{to:`/queue?tab=pipelines`,replace:!0})}),(0,G.jsx)(Lr,{path:`stats`,element:(0,G.jsx)(dWe,{})}),(0,G.jsx)(Lr,{path:`profiles`,element:(0,G.jsx)(SKe,{})}),(0,G.jsx)(Lr,{path:`finance`,element:(0,G.jsx)($9,{permission:`cost_centers:read_own`,children:(0,G.jsx)(tKe,{})})}),(0,G.jsx)(Lr,{path:`maintenance`,element:(0,G.jsx)(DKe,{})}),(0,G.jsx)(Lr,{path:`projects`,element:(0,G.jsx)(AKe,{})}),(0,G.jsx)(Lr,{path:`projects/:id`,element:(0,G.jsx)(PKe,{})}),(0,G.jsx)(Lr,{path:`inventory`,element:(0,G.jsx)(K1e,{})}),(0,G.jsx)(Lr,{path:`files`,element:(0,G.jsx)(h$e,{})}),(0,G.jsx)(Lr,{path:`files/trash`,element:(0,G.jsx)(v$e,{})}),(0,G.jsx)(Lr,{path:`makerworld`,element:(0,G.jsx)($9,{permission:`makerworld:view`,children:(0,G.jsx)(s0e,{})})}),(0,G.jsx)(Lr,{path:`settings`,element:(0,G.jsx)($9,{permission:`settings:read`,children:(0,G.jsx)(ZGe,{})})}),(0,G.jsx)(Lr,{path:`groups/new`,element:(0,G.jsx)($9,{permission:`groups:create`,children:(0,G.jsx)(U$e,{})})}),(0,G.jsx)(Lr,{path:`groups/:id/edit`,element:(0,G.jsx)($9,{permission:`groups:update`,children:(0,G.jsx)(U$e,{})})}),(0,G.jsx)(Lr,{path:`users`,element:(0,G.jsx)(Fr,{to:`/settings?tab=users`,replace:!0})}),(0,G.jsx)(Lr,{path:`groups`,element:(0,G.jsx)(Fr,{to:`/settings?tab=users`,replace:!0})}),(0,G.jsx)(Lr,{path:`system`,element:(0,G.jsx)(p0e,{})}),(0,G.jsx)(Lr,{path:`notifications`,element:(0,G.jsx)(b0e,{})}),(0,G.jsx)(Lr,{path:`gcode-viewer`,element:(0,G.jsx)(x0e,{})}),(0,G.jsx)(Lr,{path:`external/:id`,element:(0,G.jsx)(H$e,{})}),(0,G.jsx)(Lr,{path:`camera-tokens`,element:(0,G.jsx)(Fr,{to:`/settings?tab=apikeys#card-camera-tokens`,replace:!0})})]})]})})]})})})})})})})}(0,b.createRoot)(document.getElementById(`root`)).render((0,G.jsx)(y.StrictMode,{children:(0,G.jsx)(c4e,{})})); \ No newline at end of file diff --git a/static/index.html b/static/index.html index 7d3f1146d..a472e1c7d 100644 --- a/static/index.html +++ b/static/index.html @@ -26,7 +26,7 @@ - +