diff --git a/CHANGELOG.md b/CHANGELOG.md
index a8ddbcaeb..03242cc37 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,6 +8,7 @@ All notable changes to Bambuddy will be documented in this file.
- **Orca Cloud profile sync now connects by approving a code instead of the copy-paste sign-in** — Connecting Bambuddy to Orca Cloud used to mean opening an OAuth sign-in in a new tab, watching it redirect to a `localhost` URL that fails to load, then copying that dead URL out of the address bar and pasting it back into Bambuddy. That dance existed only because Orca's auth backend (Supabase) accepts no redirect target other than `localhost`, and the deliberately-broken redirect page confused nearly everyone who reached it. OrcaSlicer has since shipped a first-class external-app pairing API (the OAuth 2.0 Device Authorization Grant, RFC 8628), so the flow is now: click **Connect**, approve a short code on your Orca Cloud settings page, and Bambuddy pairs itself — no redirect, no paste, no client secret, and it behaves identically from a LAN IP, `localhost`, or behind a reverse proxy. Bambuddy requests **read-only** access (it only lists and views your Orca Cloud profiles), keeps the pairing alive with the API's rotating refresh tokens (validated end-to-end against Orca's staging and production servers), and stores nothing beyond the issued token pair. The profile list and detail views are unchanged, so nothing downstream of the connect step looks different. The old paste-based sign-in and the email/password fallback are removed. Points at production Orca Cloud by default; `ORCA_CLOUD_API_BASE` overrides the endpoint for testing.
### Fixed
+- **Multi-plate queue prints lost the selected plate in Print History and a stopped-while-offline print stayed "printing" (#2603, reporter @Jostxxl)** — Cancelling a print queued from a specific plate of a multi-plate 3MF showed it in Print History as **Plate 1**, so you couldn't tell which plate to requeue. **Root cause.** The archive derives its plate from the *filename*, but a whole multi-plate 3MF uploads under one name with no plate suffix, so the parser defaulted to plate 1 and `extra_data` held all-plates aggregate metadata; the queue row kept the correct plate but nothing copied it onto the archive, which had no plate field at all. **Fix.** `print_archives` gains a nullable `plate_id`, copied from the queue item at dispatch (both the archive-based and library-file paths), exposed in the archive API, and rendered in Print History (falling back to no plate label only when genuinely unknown). A startup backfill copies the plate onto existing archives from their linked queue rows, so already-cancelled prints recover their plate. Additionally, **stopping a printing item while the printer was offline left the linked archive stuck at "printing"** — the queue row was cancelled but, with no printer to send an MQTT completion, nothing ever reconciled the archive. The offline-stop path now closes the archive out directly (status `cancelled`, `failure_reason` "Stopped by user (printer was offline)"); the online path is unchanged and still leaves the archive to the MQTT completion event. Column add + backfill are identical on SQLite and Postgres. Covered by tests for plate persistence, the backfill (including no-clobber/idempotency), and the offline vs online stop reconcile.
- **`queue_max_concurrent_uploads` behaved as a per-batch cap instead of a refillable pool (#2602, reporter @Jostxxl)** — On a large farm, unused upload slots sat idle whenever any upload from the current batch was still running. **Root cause.** `check_queue()` awaited `_dispatch_selected()`, which awaited `asyncio.gather()` over the whole selected batch before returning — so the scheduler's run loop was blocked until the *slowest* FTP transfer in the batch finished. A 96 MB 3MF that took 513 s to upload left 15 of 16 configured slots unused for 8.5 minutes on a 93-printer farm, even as other printers came free; jobs that became eligible during the long upload couldn't be dispatched. The batch-await was load-bearing for one reason: `_start_print` flips a row `pending → printing` only *after* its upload completes, so returning early would have let the next pass re-dispatch the still-`pending` in-flight rows. **Fix.** Uploads now run as independent background tasks tracked in a `_inflight` pool. Each tick excludes in-flight item rows (and their printers) from selection, launches at most `limit − len(_inflight)` new uploads, and returns immediately — so a freed slot refills on the next fast (3 s) tick instead of waiting out the whole batch, and the configured limit finally behaves as a continuously-refillable worker pool. The no-double-dispatch invariant the batch-await used to provide is now carried by the in-flight exclusion; the `pending → printing` CAS, the busy-printer guard (#2598), the per-printer dispatch hold, auto-drying exclusion (in-flight printers stay out, including on the no-pending-items path), and per-item failure isolation are all preserved and run per task. Investigated with the reporter's large-farm hotfix and reproduction; covered by rewritten pool tests (cap holds across refills, freed slot refills, in-flight item/printer excluded from re-selection, check_queue returns without awaiting uploads).
- **Configuring a built-in/generic filament on an AMS slot reverted to the old profile a moment later (#2604, reporter @Jostxxl)** — Selecting a built-in preset (e.g. Generic ABS) through **Printer → AMS slot → Configure** briefly showed the new material on the printer, then the slot snapped back to whatever was there before (e.g. an old Generic PETG). **Root cause.** The Configure AMS Slot modal sends built-in, local, and Orca-generic presets with a `GF*` `tray_info_idx` but an **empty** `setting_id` (those presets carry no Bambu Cloud setting id of their own), and the `configure_ams_slot` route forwarded that empty value straight to `ams_filament_setting`. The firmware treats a slot that has a filament id but no setting id as half-configured: it accepts the update, then reverts to its previously stored profile. The inventory/assignment path already guards against this by deriving the setting id from the filament id, but the manual Configure path didn't, leaving two inconsistent code paths. **Fix.** `configure_ams_slot` now back-fills `setting_id` from the resolved `tray_info_idx` via `filament_id_to_setting_id` whenever the client sent none (e.g. `GFB99` → `GFSB99`), mirroring the inventory path. Doing it server-side also protects API callers and any future frontend. `P*` user presets and already-`GFS*` values are left untouched, and an explicitly-supplied `setting_id` (including the `PFUS*` pair) still passes through unchanged. Covered by tests for the built-in empty-`setting_id` case and the material-only generic-fallback case both publishing a derived `GFS*` id.
- **The HT-A (AMS-HT) spool vanished a few seconds after every power-on (#2594, reporter @GuillaumeHouba)** — On an H2C, the spool in the HT-A high-temp AMS on the left nozzle showed correctly with its RFID assignment on power-on, then disappeared seconds later; the regular AMS spools stayed. **Root cause.** The AMS merge in `_handle_ams_data` clears a tray when it receives a partial `{id, state}` update whose `state != 11` — the rule that lets 4-slot AMS units (e.g. H2D) report an emptied slot with just `{id, state}` and no `tray_type` (#784), where `11` = loaded. But an **AMS-HT** (single-tray high-temp dry box, unit id ≥ 128) reports its *loaded* tray as `state=9`, not 11 — it doesn't feed filament into a shared buffer the way a 4-slot AMS does. So the partial `{id:0, state:9}` the printer sends for the HT tray on power-on was misread as "slot emptied," and Bambuddy wiped the tray's `tray_type` / RFID / Spoolman assignment. The support log showed it plainly: every "state=9 (not loaded) — clearing stale tray data" was on AMS 128, never on the regular AMS unit 0 (which correctly reports 11). **Fix.** The `state != 11 → empty` heuristic is now skipped for AMS-HT units (id ≥ 128); their differing single-tray state semantics mean a partial state update must not clear a present spool. A genuine HT spool removal still clears through the explicit `tray_type == ""` update and the `tray_exist_bits` cleanup, both unchanged, and regular AMS behavior (id < 128) is untouched. Covered by tests for the HT tray surviving a `state=9` partial, the HT still clearing on an explicit empty, and the existing regular-AMS `state=9`/`10`/`11` cases.
diff --git a/backend/app/api/routes/print_queue.py b/backend/app/api/routes/print_queue.py
index b59a54995..55ec1054e 100644
--- a/backend/app/api/routes/print_queue.py
+++ b/backend/app/api/routes/print_queue.py
@@ -1374,6 +1374,22 @@ async def stop_queue_item(
item.status = "cancelled"
item.completed_at = datetime.now(timezone.utc)
item.error_message = "Stopped by user" if stop_sent else "Stopped by user (printer was offline)"
+
+ # Reconcile the linked archive when the printer is offline (#2603). When the
+ # stop command reaches the printer it later reports the stop over MQTT and
+ # on_print_complete flips the archive to cancelled/failed. When the printer is
+ # offline no such event ever arrives, so the archive would stay "printing"
+ # forever (queue row cancelled, archive still printing — the reporter's
+ # archive 436). Close it out here, mirroring what the MQTT path would have
+ # done. Only touch a still-"printing" archive so we never overwrite a real
+ # completion that raced in.
+ if not stop_sent and item.archive_id:
+ archive = await db.get(PrintArchive, item.archive_id)
+ if archive and archive.status == "printing":
+ archive.status = "cancelled"
+ archive.completed_at = datetime.now(timezone.utc)
+ archive.failure_reason = "Stopped by user (printer was offline)"
+
await db.commit()
logger.info("Stopped printing queue item %s (stop command sent: %s)", item_id, stop_sent)
diff --git a/backend/app/core/database.py b/backend/app/core/database.py
index b98c1ae81..cfb7cc1a3 100644
--- a/backend/app/core/database.py
+++ b/backend/app/core/database.py
@@ -852,6 +852,13 @@ async def run_migrations(conn):
# Migration: Add f3d_path column to print_archives for Fusion 360 design files
await _safe_execute(conn, "ALTER TABLE print_archives ADD COLUMN f3d_path VARCHAR(500)")
+ # Migration: Add plate_id column to print_archives (#2603). The selected plate
+ # of a multi-plate 3MF is copied from the queue item at dispatch so Print
+ # History can show the actual plate instead of falling back to Plate 1.
+ # Nullable, no default — identical DDL on SQLite and Postgres. Backfilled from
+ # linked queue rows below.
+ await _safe_execute(conn, "ALTER TABLE print_archives ADD COLUMN plate_id INTEGER")
+
# Migration: Add on_maintenance_due column to notification_providers
await _safe_execute(conn, "ALTER TABLE notification_providers ADD COLUMN on_maintenance_due BOOLEAN DEFAULT 0")
@@ -3509,6 +3516,56 @@ async def run_migrations(conn):
# regardless, so even a NULL row could not disable the retry cap.
await _safe_execute(conn, "ALTER TABLE print_queue ADD COLUMN dispatch_attempts INTEGER DEFAULT 0")
+ # Backfill: copy the selected plate from linked queue rows onto their archives
+ # (#2603). Recovers the plate for archives created before print_archives had a
+ # plate_id column, wherever the queue row still points at the archive and
+ # carries a plate. Runs here — after every print_queue column migration
+ # (plate_id, archive_id) — because it reads print_queue.plate_id, which is
+ # added far earlier in this function but must exist before this DML runs on a
+ # first-ever migration pass. Correlated-subquery form so the DML is identical
+ # on SQLite and Postgres; the WHERE plate_id IS NULL guard makes it idempotent
+ # and keeps it from clobbering values set on later runs.
+ async with conn.begin_nested():
+ # Only do any work (and, on SQLite, the FTS rebuild below) when there is
+ # actually a plate to recover — so this is a one-off cost on the upgrade
+ # boot, not an every-boot tax once every archive is backfilled.
+ has_work = (
+ await conn.execute(
+ text(
+ "SELECT 1 FROM print_archives a "
+ "JOIN print_queue q ON q.archive_id = a.id "
+ "WHERE a.plate_id IS NULL AND q.plate_id IS NOT NULL "
+ "LIMIT 1"
+ )
+ )
+ ).first() is not None
+ if has_work:
+ # SQLite: print_archives has an external-content FTS index (archive_fts,
+ # created above) whose AFTER UPDATE trigger issues an FTS 'delete' for
+ # the row. Archives created before that table existed were never indexed
+ # (its creation runs no rebuild), and updating an un-indexed row trips
+ # "database disk image is malformed". plate_id isn't even an FTS column,
+ # so the trigger's re-index is pointless here — but it still fires. Rebuild
+ # the index from the content table first so every row is present and the
+ # trigger's 'delete' is well-defined. Postgres has no such FTS table.
+ if is_sqlite():
+ await conn.execute(text("INSERT INTO archive_fts(archive_fts) VALUES('rebuild')"))
+ await conn.execute(
+ text(
+ "UPDATE print_archives "
+ "SET plate_id = ("
+ " SELECT pq.plate_id FROM print_queue pq "
+ " WHERE pq.archive_id = print_archives.id AND pq.plate_id IS NOT NULL "
+ " LIMIT 1"
+ ") "
+ "WHERE plate_id IS NULL "
+ "AND EXISTS ("
+ " SELECT 1 FROM print_queue pq "
+ " WHERE pq.archive_id = print_archives.id AND pq.plate_id IS NOT NULL"
+ ")"
+ )
+ )
+
# Migration: Disambiguate the four ``user_print_*`` notification template
# names by appending " Email" (#1792). See ``_migrate_rename_user_print_template_names``.
await _migrate_rename_user_print_template_names(conn)
diff --git a/backend/app/models/archive.py b/backend/app/models/archive.py
index e73903293..462d23c90 100644
--- a/backend/app/models/archive.py
+++ b/backend/app/models/archive.py
@@ -56,6 +56,14 @@ class PrintArchive(Base):
# print and keep the original row instead of cancel-then-create.
subtask_id: Mapped[str | None] = mapped_column(String(64), nullable=True)
+ # Which plate of a multi-plate 3MF this print was for (1-based), copied from
+ # the queue item at dispatch (#2603). A whole multi-plate 3MF is uploaded
+ # under one filename with no plate suffix, so the parser can't recover the
+ # selected plate and extra_data holds all-plates aggregate metadata; without
+ # this the history UI can't tell which plate was printed and falls back to
+ # Plate 1. NULL for archives with no specific selected plate.
+ plate_id: Mapped[int | None] = mapped_column(Integer, nullable=True)
+
# Extended metadata (JSON blob for flexibility)
extra_data: Mapped[dict | None] = mapped_column(JSON)
diff --git a/backend/app/schemas/archive.py b/backend/app/schemas/archive.py
index bac03d5e6..c48174783 100644
--- a/backend/app/schemas/archive.py
+++ b/backend/app/schemas/archive.py
@@ -55,6 +55,7 @@ class ArchiveResponse(BaseModel):
object_count: int | None = None
print_name: str | None
+ plate_id: int | None = None # Selected plate of a multi-plate 3MF (#2603)
print_time_seconds: int | None # Estimated time from slicer
actual_time_seconds: int | None = None # Computed from started_at/completed_at
# Percentage: 100 = perfect, >100 = faster than estimated
diff --git a/backend/app/services/archive.py b/backend/app/services/archive.py
index 240c9cb64..fdd6880d2 100644
--- a/backend/app/services/archive.py
+++ b/backend/app/services/archive.py
@@ -1142,6 +1142,7 @@ class ArchiveService:
project_id: int | None = None,
subtask_id: str | None = None,
prefer_filename_for_name: bool = False,
+ plate_id: int | None = None,
) -> PrintArchive | None:
"""Archive a 3MF file with metadata.
@@ -1314,6 +1315,7 @@ class ArchiveService:
created_by_id=created_by_id,
project_id=project_id,
subtask_id=subtask_id,
+ plate_id=plate_id,
)
self.db.add(archive)
diff --git a/backend/app/services/print_scheduler.py b/backend/app/services/print_scheduler.py
index 641a7de63..ffed45adf 100644
--- a/backend/app/services/print_scheduler.py
+++ b/backend/app/services/print_scheduler.py
@@ -2965,6 +2965,14 @@ class PrintScheduler:
await self._power_off_if_needed(db, item)
return
+ # Persist the queue item's selected plate onto the archive so Print
+ # History can show the actual plate after cancel/fail/complete (#2603).
+ # Only when the archive doesn't already carry one, so a reprint of a
+ # plate-specific archive isn't relabelled by a differently-plated
+ # queue row.
+ if archive.plate_id is None and item.plate_id is not None:
+ archive.plate_id = item.plate_id
+
file_path = settings.base_dir / archive.file_path
filename = archive.filename
@@ -2997,6 +3005,7 @@ class PrintScheduler:
original_filename=filename,
created_by_id=item.created_by_id,
project_id=item.project_id,
+ plate_id=item.plate_id, # selected plate → Print History (#2603)
)
if archive:
item.archive_id = archive.id
diff --git a/backend/tests/integration/test_print_queue_api.py b/backend/tests/integration/test_print_queue_api.py
index 7e48d230f..fd8176ece 100644
--- a/backend/tests/integration/test_print_queue_api.py
+++ b/backend/tests/integration/test_print_queue_api.py
@@ -3164,3 +3164,75 @@ class TestForceColorOverridesAreScopedToThePlate:
)
assert response.status_code == 200
assert [o["color_name"] for o in response.json()["filament_overrides"]] == ["Sunshine Yellow"]
+
+
+@pytest.mark.asyncio
+async def test_stop_offline_reconciles_linked_archive_status_2603(
+ async_client: AsyncClient, printer_factory, archive_factory, db_session
+):
+ """Stopping a printing item while the printer is offline must also close out its
+ archive (#2603).
+
+ When the stop command reaches the printer, the later MQTT completion event flips
+ the archive to cancelled. When the printer is offline no such event ever arrives,
+ so without this the archive stays "printing" forever while the queue row is
+ already cancelled — the reporter's archive 436. The offline branch reconciles the
+ archive directly.
+ """
+ from unittest.mock import MagicMock, patch
+
+ from backend.app.models.print_queue import PrintQueueItem
+
+ printer = await printer_factory(name="Offline printer")
+ archive = await archive_factory(
+ printer.id, status="printing", plate_id=22, filename="heart 3.gcode.3mf", with_run=False
+ )
+ item = PrintQueueItem(printer_id=printer.id, archive_id=archive.id, status="printing")
+ db_session.add(item)
+ await db_session.commit()
+ await db_session.refresh(item)
+
+ # stop_print returns False => printer offline / not connected.
+ with patch(
+ "backend.app.services.printer_manager.printer_manager.stop_print",
+ MagicMock(return_value=False),
+ ):
+ resp = await async_client.post(f"/api/v1/queue/{item.id}/stop")
+
+ assert resp.status_code == 200
+ await db_session.refresh(item)
+ await db_session.refresh(archive)
+ assert item.status == "cancelled"
+ assert archive.status == "cancelled", "an offline stop must reconcile the archive, not leave it 'printing'"
+ assert archive.completed_at is not None
+ assert archive.failure_reason == "Stopped by user (printer was offline)"
+
+
+@pytest.mark.asyncio
+async def test_stop_online_leaves_archive_for_mqtt_to_reconcile_2603(
+ async_client: AsyncClient, printer_factory, archive_factory, db_session
+):
+ """When the stop command reaches the printer, the archive is left to the MQTT
+ completion path — the offline reconcile must NOT fire and pre-empt it."""
+ from unittest.mock import MagicMock, patch
+
+ from backend.app.models.print_queue import PrintQueueItem
+
+ printer = await printer_factory(name="Online printer")
+ archive = await archive_factory(printer.id, status="printing", filename="heart 3.gcode.3mf", with_run=False)
+ item = PrintQueueItem(printer_id=printer.id, archive_id=archive.id, status="printing")
+ db_session.add(item)
+ await db_session.commit()
+ await db_session.refresh(item)
+
+ with patch(
+ "backend.app.services.printer_manager.printer_manager.stop_print",
+ MagicMock(return_value=True),
+ ):
+ resp = await async_client.post(f"/api/v1/queue/{item.id}/stop")
+
+ assert resp.status_code == 200
+ await db_session.refresh(item)
+ await db_session.refresh(archive)
+ assert item.status == "cancelled"
+ assert archive.status == "printing", "an online stop must leave the archive for the MQTT completion path"
diff --git a/backend/tests/unit/test_archive_plate_2603.py b/backend/tests/unit/test_archive_plate_2603.py
new file mode 100644
index 000000000..59d146414
--- /dev/null
+++ b/backend/tests/unit/test_archive_plate_2603.py
@@ -0,0 +1,208 @@
+"""Selected plate persists onto the archive and backfills from the queue (#2603).
+
+A whole multi-plate 3MF is uploaded under one filename with no plate suffix, so
+the archive parser can't recover the selected plate and Print History fell back
+to Plate 1. The queue row keeps the correct ``plate_id``; these tests cover
+copying it onto the archive, the startup backfill for pre-existing rows, and that
+``run_migrations`` applies the new column + backfill cleanly.
+"""
+
+import pytest
+from sqlalchemy import text
+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, run_migrations
+from backend.app.models.archive import PrintArchive
+from backend.app.models.print_queue import PrintQueueItem
+from backend.app.models.printer import Printer
+
+
+@pytest.fixture
+def force_sqlite_dialect(monkeypatch):
+ """Force the SQLite branch of run_migrations regardless of the test env's
+ DATABASE_URL (this sandbox points it at Postgres)."""
+ from backend.app.core import database as database_module, db_dialect
+
+ monkeypatch.setattr(db_dialect, "is_sqlite", lambda: True)
+ monkeypatch.setattr(db_dialect, "is_postgres", lambda: False)
+ monkeypatch.setattr(database_module, "is_sqlite", lambda: True)
+
+
+# The exact backfill statement run by run_migrations (kept in sync deliberately;
+# the run_migrations smoke test below exercises the real one).
+_BACKFILL_SQL = (
+ "UPDATE print_archives "
+ "SET plate_id = ("
+ " SELECT pq.plate_id FROM print_queue pq "
+ " WHERE pq.archive_id = print_archives.id AND pq.plate_id IS NOT NULL "
+ " LIMIT 1"
+ ") "
+ "WHERE plate_id IS NULL "
+ "AND EXISTS ("
+ " SELECT 1 FROM print_queue pq "
+ " WHERE pq.archive_id = print_archives.id AND pq.plate_id IS NOT NULL"
+ ")"
+)
+
+
+@pytest.fixture
+async def sm():
+ engine = create_async_engine("sqlite+aiosqlite:///:memory:", echo=False)
+ async with engine.begin() as conn:
+ await conn.run_sync(Base.metadata.create_all)
+ try:
+ yield async_sessionmaker(engine, expire_on_commit=False)
+ finally:
+ await engine.dispose()
+
+
+async def _printer(db) -> int:
+ printer = Printer(name="P", serial_number="S", ip_address="10.0.0.1", access_code="code", model="X1C")
+ db.add(printer)
+ await db.flush()
+ return printer.id
+
+
+@pytest.mark.asyncio
+async def test_archive_row_stores_plate_id(sm):
+ """The column round-trips a selected plate."""
+ async with sm() as db:
+ archive = PrintArchive(filename="heart 3.gcode.3mf", file_path="x", file_size=1, status="printing", plate_id=22)
+ db.add(archive)
+ await db.commit()
+ await db.refresh(archive)
+ assert archive.plate_id == 22
+
+
+@pytest.mark.asyncio
+async def test_backfill_copies_plate_from_linked_queue_row(sm):
+ """An archive with no plate inherits it from a queue row that still links to it."""
+ async with sm() as db:
+ printer_id = await _printer(db)
+ archive = PrintArchive(
+ filename="heart 3.gcode.3mf", file_path="x", file_size=1, status="cancelled", plate_id=None
+ )
+ db.add(archive)
+ await db.flush()
+ db.add(PrintQueueItem(printer_id=printer_id, archive_id=archive.id, status="cancelled", plate_id=22))
+ await db.commit()
+
+ await db.execute(text(_BACKFILL_SQL))
+ await db.commit()
+ await db.refresh(archive)
+ assert archive.plate_id == 22
+
+
+@pytest.mark.asyncio
+async def test_backfill_does_not_clobber_existing_plate_or_touch_unlinked(sm):
+ """Idempotent: a set plate is left alone, and an archive with no linked queue plate stays NULL."""
+ async with sm() as db:
+ printer_id = await _printer(db)
+ # Archive already carrying a plate; queue row disagrees — must not be overwritten.
+ set_archive = PrintArchive(filename="a.3mf", file_path="a", file_size=1, status="cancelled", plate_id=7)
+ # Archive with no linked queue plate at all — must stay NULL.
+ null_archive = PrintArchive(filename="b.3mf", file_path="b", file_size=1, status="completed", plate_id=None)
+ db.add_all([set_archive, null_archive])
+ await db.flush()
+ db.add(PrintQueueItem(printer_id=printer_id, archive_id=set_archive.id, status="cancelled", plate_id=3))
+ await db.commit()
+
+ # Run twice — second run must be a no-op.
+ await db.execute(text(_BACKFILL_SQL))
+ await db.execute(text(_BACKFILL_SQL))
+ await db.commit()
+ await db.refresh(set_archive)
+ await db.refresh(null_archive)
+ assert set_archive.plate_id == 7, "an archive that already had a plate must not be relabelled"
+ assert null_archive.plate_id is None, "an archive with no linked queue plate must stay NULL"
+
+
+@pytest.mark.asyncio
+async def test_run_migrations_adds_column_and_backfills_in_order(force_sqlite_dialect):
+ """End-to-end: run_migrations adds print_archives.plate_id and backfills it from
+ print_queue.plate_id without crashing (#2603).
+
+ Guards the migration *ordering*: the backfill reads print_queue.plate_id, which is
+ added earlier in run_migrations. If the backfill ran before that column existed
+ (as it did in the first draft), a first-ever migration pass would raise
+ "no such column: print_queue.plate_id" and abort startup. Running the full
+ migration here — twice — proves the order is correct and idempotent. Mirrors the
+ harness in test_cancellation_cascade_recovery_migration.py.
+ """
+ # run_migrations touches many tables; register the full model set so
+ # create_all builds the whole schema (imports for side effects only).
+ from backend.app.models import ( # noqa: F401
+ ams_history,
+ ams_label,
+ api_key,
+ auth_ephemeral,
+ color_catalog,
+ external_link,
+ filament,
+ group,
+ kprofile_note,
+ maintenance,
+ notification,
+ notification_template,
+ oidc_provider,
+ print_log,
+ project,
+ project_bom,
+ slot_preset,
+ smart_plug,
+ smart_plug_energy_snapshot,
+ sponsor_toast_state,
+ spool,
+ spool_assignment,
+ spool_catalog,
+ spool_k_profile,
+ spool_usage_history,
+ spoolbuddy_device,
+ spoolman_k_profile,
+ spoolman_slot_assignment,
+ user,
+ user_email_pref,
+ user_otp_code,
+ user_totp,
+ virtual_printer,
+ )
+
+ engine = create_async_engine("sqlite+aiosqlite:///:memory:", echo=False)
+ try:
+ async with engine.begin() as conn:
+ await conn.run_sync(Base.metadata.create_all)
+
+ # Seed the archive + queue row BEFORE any migration pass — an existing
+ # install upgrading to this version. The archive predates the archive_fts
+ # FTS table (created inside run_migrations), so it is NOT indexed; the
+ # backfill's UPDATE would trip the external-content FTS 'delete' ("database
+ # disk image is malformed") unless the migration rebuilds the FTS index
+ # first. This is the exact shape that failed the force-color migration
+ # tests before the rebuild guard was added.
+ sm = async_sessionmaker(engine, expire_on_commit=False)
+ async with sm() as db:
+ printer_id = await _printer(db)
+ db.add(PrintArchive(id=436, filename="heart 3.gcode.3mf", file_path="x", file_size=1, status="cancelled"))
+ await db.flush()
+ db.add(PrintQueueItem(id=177, printer_id=printer_id, archive_id=436, status="cancelled", plate_id=22))
+ await db.commit()
+
+ # Upgrade boot: run_migrations must add print_archives.plate_id, rebuild the
+ # FTS index, and backfill the plate — without crashing. Also guards the
+ # ordering bug: the full migration runs top-to-bottom, so if the backfill
+ # preceded the print_queue.plate_id column it would raise "no such column".
+ async with engine.begin() as conn:
+ await run_migrations(conn)
+ async with sm() as db:
+ archive = await db.get(PrintArchive, 436)
+ assert archive.plate_id == 22, "run_migrations must backfill the archive's plate from its queue row"
+
+ # A further startup re-runs migrations — idempotent, plate unchanged, and
+ # (plate now set) the rebuild+backfill is skipped entirely.
+ async with engine.begin() as conn:
+ await run_migrations(conn)
+ async with sm() as db:
+ assert (await db.get(PrintArchive, 436)).plate_id == 22
+ finally:
+ await engine.dispose()
diff --git a/backend/tests/unit/test_scheduler_cleanup_library.py b/backend/tests/unit/test_scheduler_cleanup_library.py
index 777e60eff..1de44b0be 100644
--- a/backend/tests/unit/test_scheduler_cleanup_library.py
+++ b/backend/tests/unit/test_scheduler_cleanup_library.py
@@ -110,7 +110,9 @@ async def queue_factory(tmp_path):
async def _dispatch_library_item(ctx, *, archive_failure=False, unlink_side_effect=None):
scheduler = PrintScheduler()
- async def archive_print(self, *, printer_id, source_file, original_filename, created_by_id=None, project_id=None):
+ async def archive_print(
+ self, *, printer_id, source_file, original_filename, created_by_id=None, project_id=None, plate_id=None
+ ):
if archive_failure:
raise RuntimeError("archive copy failed")
diff --git a/frontend/src/api/client.ts b/frontend/src/api/client.ts
index 76f48bf03..8ad82ee3e 100644
--- a/frontend/src/api/client.ts
+++ b/frontend/src/api/client.ts
@@ -653,6 +653,7 @@ export interface Archive {
original_archive_id: number | null; // ID of the first/original archive
object_count: number | null;
print_name: string | null;
+ plate_id: number | null; // Selected plate of a multi-plate 3MF (#2603)
print_time_seconds: number | null;
actual_time_seconds: number | null; // Computed from started_at/completed_at
time_accuracy: number | null; // Percentage: 100 = perfect, >100 = faster than estimated
diff --git a/frontend/src/pages/ArchivesPage.tsx b/frontend/src/pages/ArchivesPage.tsx
index ce8617e9f..7b2cb8618 100644
--- a/frontend/src/pages/ArchivesPage.tsx
+++ b/frontend/src/pages/ArchivesPage.tsx
@@ -948,6 +948,7 @@ function ArchiveCard({
{archive.print_name || archive.filename}
+ {archive.plate_id != null && ` — ${t('printers.plateNumber', { number: archive.plate_id })}`}
{let e=o.current;e&&(e.playbackRate=l)},[l]),(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&i()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[i]),(0,y.useEffect)(()=>{let e=o.current;if(!e)return;let t=()=>f(e.currentTime),n=()=>m(e.duration),r=()=>c(!0),i=()=>c(!1);return e.addEventListener(`timeupdate`,t),e.addEventListener(`durationchange`,n),e.addEventListener(`play`,r),e.addEventListener(`pause`,i),()=>{e.removeEventListener(`timeupdate`,t),e.removeEventListener(`durationchange`,n),e.removeEventListener(`play`,r),e.removeEventListener(`pause`,i)}},[]);let _=()=>{let e=o.current;e&&(s?e.pause():e.play())};return(0,K.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/80`,children:[(0,K.jsxs)(`div`,{className:`relative bg-bambu-dark-secondary rounded-xl max-w-4xl w-full mx-4 overflow-hidden`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`h3`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(ic,{className:`w-5 h-5 text-bambu-green`}),t]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[r&&(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:()=>g(!0),children:[(0,K.jsx)(xl,{className:`w-4 h-4`}),`Edit`]}),(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:()=>{let t=document.createElement(`a`);t.href=e,t.download=n,t.click()},children:[(0,K.jsx)(Vs,{className:`w-4 h-4`}),`Download`]}),(0,K.jsx)(`button`,{onClick:i,className:`p-1 hover:bg-bambu-dark-tertiary rounded transition-colors`,children:(0,K.jsx)(Wu,{className:`w-5 h-5 text-bambu-gray`})})]})]}),(0,K.jsxs)(`div`,{className:`p-4`,children:[(0,K.jsx)(`video`,{ref:o,src:e,autoPlay:!0,className:`w-full rounded-lg`,onClick:_}),(0,K.jsxs)(`div`,{className:`mt-4 space-y-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray w-12 text-right`,children:Lf(d)}),(0,K.jsx)(`input`,{type:`range`,min:0,max:p||100,value:d,onChange:e=>{let t=o.current;t&&(t.currentTime=parseFloat(e.target.value))},className:`flex-1 h-1 bg-bambu-dark-tertiary rounded-lg appearance-none cursor-pointer
[&::-webkit-slider-thumb]:appearance-none [&::-webkit-slider-thumb]:w-3 [&::-webkit-slider-thumb]:h-3
[&::-webkit-slider-thumb]:bg-bambu-green [&::-webkit-slider-thumb]:rounded-full
- [&::-webkit-slider-thumb]:cursor-pointer`}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray w-12`,children:Lf(p)})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`button`,{onClick:()=>{let e=o.current;e&&(e.currentTime=Math.max(0,e.currentTime-5))},className:`p-2 hover:bg-bambu-dark-tertiary rounded-lg transition-colors`,title:`Skip back 5s`,children:(0,K.jsx)($l,{className:`w-5 h-5 text-bambu-gray`})}),(0,K.jsx)(`button`,{onClick:_,className:`p-2 bg-bambu-green hover:bg-bambu-green-dark rounded-lg transition-colors`,children:s?(0,K.jsx)(vl,{className:`w-5 h-5 text-white`}):(0,K.jsx)(Cl,{className:`w-5 h-5 text-white`})}),(0,K.jsx)(`button`,{onClick:()=>{let e=o.current;e&&(e.currentTime=Math.min(p,e.currentTime+5))},className:`p-2 hover:bg-bambu-dark-tertiary rounded-lg transition-colors`,title:`Skip forward 5s`,children:(0,K.jsx)(eu,{className:`w-5 h-5 text-bambu-gray`})})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:`Speed:`}),(0,K.jsx)(`div`,{className:`flex gap-1`,children:xze.map(e=>(0,K.jsxs)(`button`,{onClick:()=>u(e),className:`px-2 py-1 text-xs rounded transition-colors ${l===e?`bg-bambu-green text-white`:`bg-bambu-dark-tertiary text-bambu-gray hover:bg-bambu-dark-tertiary/80`}`,children:[e,`x`]},e))})]})]})]})]})]}),h&&r&&(0,K.jsx)(bze,{archiveId:r,timelapseSrc:e,onClose:()=>g(!1),onSave:a})]})}function Sze({archiveIds:e,onClose:t}){(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]);let{data:n,isLoading:r,error:i}=q({queryKey:[`archive-comparison`,e],queryFn:()=>Q.compareArchives(e)});return(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/80 flex items-center justify-center z-50 p-4`,onClick:t,children:(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg max-w-4xl w-full max-h-[90vh] flex flex-col border border-bambu-dark-tertiary`,onClick:e=>e.stopPropagation(),children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`h3`,{className:`text-lg font-semibold text-white`,children:[`Compare Archives (`,e.length,`)`]}),(0,K.jsx)(`button`,{onClick:t,className:`text-bambu-gray hover:text-white p-1`,children:(0,K.jsx)(Wu,{className:`w-5 h-5`})})]}),(0,K.jsx)(`div`,{className:`flex-1 overflow-auto p-4 bg-bambu-dark-secondary`,children:r?(0,K.jsx)(`div`,{className:`flex items-center justify-center py-12`,children:(0,K.jsx)(X,{className:`w-8 h-8 text-bambu-green animate-spin`})}):i?(0,K.jsxs)(`div`,{className:`text-center py-12 text-red-700 dark:text-red-400`,children:[(0,K.jsx)(Eu,{className:`w-12 h-12 mx-auto mb-4 opacity-50`}),(0,K.jsx)(`p`,{children:`Failed to load comparison`}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mt-2`,children:i instanceof Error?i.message:`Unknown error`})]}):n?(0,K.jsx)(Cze,{comparison:n}):null}),(0,K.jsx)(`div`,{className:`p-4 border-t border-bambu-dark-tertiary`,children:(0,K.jsx)($,{variant:`secondary`,onClick:t,className:`w-full`,children:`Close`})})]})})}function Cze({comparison:e}){return(0,K.jsxs)(`div`,{className:`space-y-6`,children:[(0,K.jsx)(`div`,{className:`overflow-x-auto`,children:(0,K.jsxs)(`table`,{className:`w-full`,children:[(0,K.jsx)(`thead`,{children:(0,K.jsxs)(`tr`,{children:[(0,K.jsx)(`th`,{className:`text-left text-sm text-bambu-gray font-medium pb-2 pr-4 min-w-[150px]`,children:`Setting`}),e.archives.map(e=>(0,K.jsxs)(`th`,{className:`text-left text-sm font-medium pb-2 px-2 min-w-[120px]`,children:[(0,K.jsx)(`div`,{className:`text-white truncate max-w-[150px]`,title:e.print_name,children:e.print_name}),(0,K.jsx)(`div`,{className:`text-xs ${e.status===`completed`?`text-status-ok`:e.status===`failed`?`text-status-error`:`text-bambu-gray`}`,children:e.status})]},e.id))]})}),(0,K.jsx)(`tbody`,{className:`divide-y divide-bambu-gray/20`,children:e.comparison.map(e=>(0,K.jsxs)(`tr`,{className:e.has_difference?`bg-yellow-500/5`:``,children:[(0,K.jsx)(`td`,{className:`py-2 pr-4 text-sm`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.has_difference&&(0,K.jsx)(Eu,{className:`w-3 h-3 text-yellow-600 dark:text-yellow-400 flex-shrink-0`}),(0,K.jsx)(`span`,{className:e.has_difference?`text-yellow-700 dark:text-yellow-400`:`text-bambu-gray`,children:e.label})]})}),e.values.map((t,n)=>(0,K.jsxs)(`td`,{className:`py-2 px-2 text-sm text-white`,children:[t??(0,K.jsx)(`span`,{className:`text-bambu-gray/50`,children:`-`}),e.unit&&t!==null&&(0,K.jsx)(`span`,{className:`text-bambu-gray ml-1`,children:e.unit})]},n))]},e.field))})]})}),e.differences.length>0&&(0,K.jsxs)(`div`,{className:`p-4 bg-yellow-50 border border-yellow-300 dark:bg-yellow-500/10 dark:border-yellow-500/30 rounded-lg`,children:[(0,K.jsxs)(`h4`,{className:`text-sm font-medium text-yellow-700 dark:text-yellow-400 mb-2 flex items-center gap-2`,children:[(0,K.jsx)(Eu,{className:`w-4 h-4`}),e.differences.length,` Difference`,e.differences.length>1?`s`:``,` Found`]}),(0,K.jsxs)(`ul`,{className:`text-sm text-white/80 space-y-1`,children:[e.differences.slice(0,5).map(e=>(0,K.jsxs)(`li`,{children:[(0,K.jsx)(`span`,{className:`text-yellow-700 dark:text-yellow-400`,children:e.label}),`: `,e.values.join(` vs `),` `,e.unit||``]},e.field)),e.differences.length>5&&(0,K.jsxs)(`li`,{className:`text-bambu-gray`,children:[`...and `,e.differences.length-5,` more`]})]})]}),e.success_correlation.has_both_outcomes?(0,K.jsxs)(`div`,{className:`p-4 bg-bambu-dark rounded-lg`,children:[(0,K.jsxs)(`h4`,{className:`text-sm font-medium text-white mb-3 flex items-center gap-2`,children:[(0,K.jsx)(ns,{className:`w-4 h-4 text-bambu-green`}),`Success/Failure Analysis`]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-4 text-sm mb-3`,children:[(0,K.jsxs)(`span`,{className:`text-bambu-green`,children:[e.success_correlation.successful_count,` successful`]}),(0,K.jsxs)(`span`,{className:`text-red-700 dark:text-red-400`,children:[e.success_correlation.failed_count,` failed`]})]}),e.success_correlation.insights&&e.success_correlation.insights.length>0?(0,K.jsx)(`div`,{className:`space-y-2`,children:e.success_correlation.insights.map(e=>(0,K.jsxs)(`div`,{className:`text-sm p-2 bg-bambu-dark-secondary rounded`,children:[(0,K.jsxs)(`span`,{className:`text-white font-medium`,children:[e.label,`:`]}),` `,(0,K.jsx)(`span`,{className:`text-white/80`,children:e.insight})]},e.field))}):(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:`No clear correlations found between settings and outcomes.`})]}):(0,K.jsx)(`div`,{className:`p-4 bg-bambu-dark rounded-lg text-sm text-bambu-gray`,children:(0,K.jsx)(`p`,{children:e.success_correlation.message||`Need both successful and failed prints for correlation analysis.`})})]})}function wze(e){let t=new Date(e),n=new Date().getTime()-t.getTime(),r=Math.floor(n/6e4);if(r<1)return`Just now`;if(r<60)return`${r}m ago`;let i=Math.floor(r/60);return i<24?`${i}h ago`:`${Math.floor(i/24)}d ago`}function Tze({upload:e,projects:t,onArchive:n,onDiscard:r,isArchiving:i,isDiscarding:a}){let[o,s]=(0,y.useState)(!1),[c,l]=(0,y.useState)(e.tags||``),[u,d]=(0,y.useState)(e.notes||``),[f,p]=(0,y.useState)(e.project_id),[m,h]=(0,y.useState)(!1);return(0,K.jsx)(Cd,{children:(0,K.jsxs)(Td,{className:`py-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(Qs,{className:`w-8 h-8 text-bambu-green flex-shrink-0`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white font-medium`,title:e.filename,children:e.display_name||e.filename}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-bambu-gray`,children:[(0,K.jsx)(`span`,{children:kd(e.file_size)}),(0,K.jsx)(`span`,{children:`·`}),(0,K.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(xs,{className:`w-3 h-3`}),wze(e.uploaded_at)]}),e.source_ip&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`span`,{children:`·`}),(0,K.jsxs)(`span`,{children:[`from `,e.source_ip]})]})]})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`button`,{onClick:()=>s(!o),className:`p-1 text-bambu-gray hover:text-white transition-colors`,children:o?(0,K.jsx)(ss,{className:`w-5 h-5`}):(0,K.jsx)(rs,{className:`w-5 h-5`})}),(0,K.jsx)($,{variant:`primary`,size:`sm`,onClick:()=>n(e.id,{tags:c,notes:u,project_id:f||void 0}),disabled:i,children:i?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Oo,{className:`w-4 h-4`}),`Archive`]})}),(0,K.jsx)($,{variant:`secondary`,size:`sm`,onClick:()=>h(!0),disabled:a,children:a?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(Cu,{className:`w-4 h-4 text-red-600 dark:text-red-400`})})]})]}),m&&(0,K.jsx)(Bd,{title:`Discard Upload`,message:`Are you sure you want to discard "${e.filename}"? This cannot be undone.`,confirmText:`Discard`,variant:`danger`,onConfirm:()=>{r(e.id),h(!1)},onCancel:()=>h(!1)}),o&&(0,K.jsxs)(`div`,{className:`mt-4 pt-4 border-t border-bambu-dark-tertiary space-y-3`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:`Tags`}),(0,K.jsx)(`input`,{type:`text`,value:c,onChange:e=>l(e.target.value),placeholder:`e.g., functional, prototype, gift`,className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-2 text-white placeholder-bambu-gray text-sm`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:`Notes`}),(0,K.jsx)(`textarea`,{value:u,onChange:e=>d(e.target.value),placeholder:`Add notes about this print...`,rows:2,className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-2 text-white placeholder-bambu-gray text-sm resize-none`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:`Project`}),(0,K.jsxs)(`select`,{value:f||``,onChange:e=>p(e.target.value?Number(e.target.value):null),className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-2 text-white text-sm`,children:[(0,K.jsx)(`option`,{value:``,children:`No project`}),t.map(e=>(0,K.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]})]})]})})}function Eze(){let e=no(),{showToast:t}=jd(),[n,r]=(0,y.useState)(!1),[i,a]=(0,y.useState)(!1),[o,s]=(0,y.useState)(new Set),[c,l]=(0,y.useState)(new Set),{data:u,isLoading:d}=q({queryKey:[`pending-uploads`],queryFn:ld.list,refetchInterval:1e4}),{data:f}=q({queryKey:[`projects`],queryFn:()=>Q.getProjects(),select:e=>[...e].sort((e,t)=>e.name.localeCompare(t.name))}),p=J({mutationFn:({id:e,data:t})=>ld.archive(e,t),onMutate:({id:e})=>{s(t=>new Set(t).add(e))},onSettled:(e,t,{id:n})=>{s(e=>{let t=new Set(e);return t.delete(n),t})},onSuccess:n=>{e.invalidateQueries({queryKey:[`pending-uploads`]}),e.invalidateQueries({queryKey:[`archives`]}),t(`Archived: ${n.print_name}`)},onError:e=>{t(e.message||`Failed to archive`,`error`)}}),m=J({mutationFn:e=>ld.discard(e),onMutate:e=>{l(t=>new Set(t).add(e))},onSettled:(e,t,n)=>{l(e=>{let t=new Set(e);return t.delete(n),t})},onSuccess:()=>{e.invalidateQueries({queryKey:[`pending-uploads`]}),t(`Upload discarded`)},onError:e=>{t(e.message||`Failed to discard`,`error`)}}),h=J({mutationFn:ld.archiveAll,onSuccess:n=>{e.invalidateQueries({queryKey:[`pending-uploads`]}),e.invalidateQueries({queryKey:[`archives`]}),t(`Archived ${n.archived} files${n.failed>0?`, ${n.failed} failed`:``}`)},onError:e=>{t(e.message||`Failed to archive all`,`error`)}}),g=J({mutationFn:ld.discardAll,onSuccess:n=>{e.invalidateQueries({queryKey:[`pending-uploads`]}),t(`Discarded ${n.discarded} files`)},onError:e=>{t(e.message||`Failed to discard all`,`error`)}});return d?(0,K.jsx)(Cd,{children:(0,K.jsx)(Td,{className:`py-8 flex justify-center`,children:(0,K.jsx)(X,{className:`w-6 h-6 animate-spin text-bambu-green`})})}):!u||u.length===0?null:(0,K.jsxs)(`div`,{className:`mb-6`,children:[(0,K.jsxs)(Cd,{className:`border-l-4 border-l-yellow-500`,children:[(0,K.jsx)(wd,{children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(Au,{className:`w-5 h-5 text-yellow-500`}),(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white`,children:[`Pending Uploads (`,u.length,`)`]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)($,{variant:`primary`,size:`sm`,onClick:()=>r(!0),disabled:h.isPending,children:h.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Oo,{className:`w-4 h-4`}),`Archive All`]})}),(0,K.jsx)($,{variant:`secondary`,size:`sm`,onClick:()=>a(!0),disabled:g.isPending,children:g.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Cu,{className:`w-4 h-4`}),`Discard All`]})})]})]})}),(0,K.jsxs)(Td,{children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4`,children:`These files were uploaded via the virtual printer. Review and archive them to add to your collection.`}),(0,K.jsx)(`div`,{className:`space-y-3`,children:u.map(e=>(0,K.jsx)(Tze,{upload:e,projects:f||[],onArchive:(e,t)=>p.mutate({id:e,data:t}),onDiscard:e=>m.mutate(e),isArchiving:o.has(e.id),isDiscarding:c.has(e.id)},e.id))})]})]}),n&&(0,K.jsx)(Bd,{title:`Archive All Uploads`,message:`Are you sure you want to archive all ${u.length} pending uploads?`,confirmText:`Archive All`,onConfirm:()=>{h.mutate(),r(!1)},onCancel:()=>r(!1)}),i&&(0,K.jsx)(Bd,{title:`Discard All Uploads`,message:`Are you sure you want to discard all ${u.length} pending uploads? This cannot be undone.`,confirmText:`Discard All`,variant:`danger`,onConfirm:()=>{g.mutate(),a(!1)},onCancel:()=>a(!1)})]})}function Dze({onClose:e}){let t=no(),{showToast:n}=jd(),[r,i]=(0,y.useState)(``),[a,o]=(0,y.useState)(null),[s,c]=(0,y.useState)(``),[l,u]=(0,y.useState)(null),[d,f]=(0,y.useState)(`count`);(0,y.useEffect)(()=>{let t=t=>{t.key===`Escape`&&(a?o(null):l?u(null):e())};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e,a,l]);let{data:p,isLoading:m}=q({queryKey:[`tags`],queryFn:Q.getTags}),h=J({mutationFn:({oldName:e,newName:t})=>Q.renameTag(e,t),onSuccess:(e,{oldName:r,newName:i})=>{t.invalidateQueries({queryKey:[`tags`]}),t.invalidateQueries({queryKey:[`archives`]}),n(`Renamed "${r}" to "${i}" in ${e.affected} archive${e.affected===1?``:`s`}`),o(null)},onError:e=>{n(e.message||`Failed to rename tag`,`error`)}}),g=J({mutationFn:e=>Q.deleteTag(e),onSuccess:(e,r)=>{t.invalidateQueries({queryKey:[`tags`]}),t.invalidateQueries({queryKey:[`archives`]}),n(`Deleted "${r}" from ${e.affected} archive${e.affected===1?``:`s`}`),u(null)},onError:e=>{n(e.message||`Failed to delete tag`,`error`)}}),_=e=>{o(e.name),c(e.name),u(null)},v=()=>{o(null),c(``)},b=()=>{if(!a||!s.trim())return;let e=s.trim();if(e===a){v();return}h.mutate({oldName:a,newName:e})},x=e=>{e.key===`Enter`?(e.preventDefault(),b()):e.key===`Escape`&&(e.preventDefault(),v())},S=e=>{u(e),o(null)},C=()=>{l&&g.mutate(l)},w=p?.filter(e=>e.name.toLowerCase().includes(r.toLowerCase())).sort((e,t)=>d===`count`&&t.count-e.count||e.name.localeCompare(t.name)),T=p?.reduce((e,t)=>e+t.count,0)||0;return(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,children:(0,K.jsx)(Cd,{className:`w-full max-w-lg max-h-[80vh] flex flex-col`,children:(0,K.jsxs)(Td,{className:`p-0 flex flex-col min-h-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary flex-shrink-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(hu,{className:`w-5 h-5 text-bambu-green`}),(0,K.jsx)(`h2`,{className:`text-xl font-semibold text-white`,children:`Manage Tags`})]}),(0,K.jsx)(`button`,{onClick:e,className:`text-bambu-gray hover:text-white transition-colors`,children:(0,K.jsx)(Wu,{className:`w-5 h-5`})})]}),(0,K.jsxs)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary flex-shrink-0`,children:[(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsxs)(`div`,{className:`relative flex-1`,children:[(0,K.jsx)(Vl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,K.jsx)(`input`,{type:`text`,placeholder:`Search tags...`,className:`w-full pl-9 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,value:r,onChange:e=>i(e.target.value)})]}),(0,K.jsxs)(`select`,{className:`px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,value:d,onChange:e=>f(e.target.value),children:[(0,K.jsx)(`option`,{value:`count`,children:`Sort by Count`}),(0,K.jsx)(`option`,{value:`name`,children:`Sort by Name`})]})]}),p&&(0,K.jsxs)(`p`,{className:`text-xs text-bambu-gray mt-2`,children:[p.length,` tag`,p.length===1?``:`s`,` across `,T,` usage`,T===1?``:`s`]})]}),(0,K.jsx)(`div`,{className:`flex-1 overflow-y-auto min-h-0 p-4`,children:m?(0,K.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,K.jsx)(X,{className:`w-6 h-6 animate-spin text-bambu-gray`})}):w?.length?(0,K.jsx)(`div`,{className:`space-y-2`,children:w.map(e=>(0,K.jsx)(`div`,{className:`flex items-center gap-2 p-2 rounded-lg bg-bambu-dark hover:bg-bambu-dark-tertiary transition-colors group`,children:a===e.name?(0,K.jsxs)(`div`,{className:`flex-1 flex items-center gap-2`,children:[(0,K.jsx)(`input`,{type:`text`,className:`flex-1 px-2 py-1 bg-bambu-dark-tertiary border border-bambu-green rounded text-white text-sm focus:outline-none`,value:s,onChange:e=>c(e.target.value),onKeyDown:x,autoFocus:!0}),(0,K.jsx)($,{size:`sm`,variant:`primary`,onClick:b,disabled:!s.trim()||h.isPending,className:`p-1.5`,children:h.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(ns,{className:`w-4 h-4`})}),(0,K.jsx)($,{size:`sm`,variant:`ghost`,onClick:v,className:`p-1.5`,children:(0,K.jsx)(Wu,{className:`w-4 h-4`})})]}):l===e.name?(0,K.jsxs)(`div`,{className:`flex-1 flex items-center gap-2`,children:[(0,K.jsx)(Eu,{className:`w-4 h-4 text-yellow-600 dark:text-yellow-400 flex-shrink-0`}),(0,K.jsxs)(`span`,{className:`text-sm text-bambu-gray-light flex-1`,children:[`Delete "`,e.name,`" from `,e.count,` archive`,e.count===1?``:`s`,`?`]}),(0,K.jsx)($,{size:`sm`,variant:`danger`,onClick:C,disabled:g.isPending,className:`p-1.5`,children:g.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(Cu,{className:`w-4 h-4`})}),(0,K.jsx)($,{size:`sm`,variant:`ghost`,onClick:()=>u(null),className:`p-1.5`,children:(0,K.jsx)(Wu,{className:`w-4 h-4`})})]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(hu,{className:`w-4 h-4 text-bambu-gray flex-shrink-0`}),(0,K.jsx)(`span`,{className:`text-white flex-1 truncate`,children:e.name}),(0,K.jsx)(`span`,{className:`px-2 py-0.5 rounded-full bg-bambu-dark-tertiary text-bambu-gray text-xs`,children:e.count}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity`,children:[(0,K.jsx)(`button`,{onClick:()=>_(e),className:`p-1.5 rounded hover:bg-bambu-dark text-bambu-gray hover:text-white transition-colors`,title:`Rename tag`,children:(0,K.jsx)(xl,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>S(e.name),className:`p-1.5 rounded hover:bg-bambu-dark text-bambu-gray hover:text-red-700 dark:hover:text-red-400 transition-colors`,title:`Delete tag`,children:(0,K.jsx)(Cu,{className:`w-4 h-4`})})]})]})},e.name))}):(0,K.jsx)(`div`,{className:`text-center py-8 text-bambu-gray`,children:r?`No tags match your search`:`No tags found`})}),(0,K.jsx)(`div`,{className:`flex gap-3 p-4 border-t border-bambu-dark-tertiary flex-shrink-0`,children:(0,K.jsx)($,{variant:`secondary`,onClick:e,className:`flex-1`,children:`Close`})})]})})})}function a2(e){let t=e.filename;if(t){let e=t.toLowerCase();if(e.endsWith(`.gcode`)||e.includes(`.gcode.`))return!0}return!!(e.total_layers||e.print_time_seconds)}async function o2(e,t,n,r){try{if(n===`source`){let{token:n}=await Q.createSourceSlicerToken(e),i=Q.getSourceSlicerDownloadUrl(e,n,t);qW(`${window.location.origin}${i}`,r)}else{let{token:n}=await Q.createArchiveSlicerToken(e),i=Q.getArchiveSlicerDownloadUrl(e,n,t);qW(`${window.location.origin}${i}`,r)}}catch{let i=n===`source`?Q.getSource3mfForSlicer(e,t):Q.getArchiveForSlicer(e,t);qW(`${window.location.origin}${i}`,r)}}function Oze({archive:e,printerName:t,isSelected:n,onSelect:r,selectionMode:i,projects:a,isHighlighted:o,timeFormat:s=`system`,preferredSlicer:c=`bambu_studio`,useSlicerApi:l=!1,currency:u,t:d,onNavigateToArchive:f}){o&&console.log(`ArchiveCard isHighlighted=true for archive:`,e.id);let p=no(),{showToast:m}=jd(),{hasPermission:h,canModify:g}=_d(),_=YW(),v=$n(),[b,x]=(0,y.useState)(!1),[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=q({queryKey:[`archive`,e.id,`delete-impact`],queryFn:()=>Q.getArchiveDeleteImpact(e.id),enabled:E,staleTime:0}),[j,M]=(0,y.useState)(!1),[N,P]=(0,y.useState)(!1),[F,I]=(0,y.useState)(!1),[L,R]=(0,y.useState)(!1),[z,B]=(0,y.useState)([]),[V,ee]=(0,y.useState)(!1),[te,ne]=(0,y.useState)(!1),[re,ie]=(0,y.useState)(!1),[H,ae]=(0,y.useState)(!1),[oe,U]=(0,y.useState)(!1),[se,ce]=(0,y.useState)(!1),[le,ue]=(0,y.useState)(null),[de,fe]=(0,y.useState)(null),[pe,me]=(0,y.useState)(!1),[he,ge]=(0,y.useState)(null),_e=(0,y.useRef)(null),ve=(0,y.useRef)(null),ye=(0,y.useRef)(null),{data:be}=q({queryKey:[`archive-plates`,e.id],queryFn:()=>Q.getArchivePlates(e.id),enabled:pe,staleTime:300*1e3}),xe=e.duplicate_sequence??0,Se=e.original_archive_id??null,Ce=be?.plates??[],we=be?.is_multi_plate??!1,Te=de??0,Ee=async()=>{try{let t=await Q.getArchivePlates(e.id);if(t.has_gcode===!1){m(d(`archives.platePicker.noGcode`),`info`);return}if(t.is_multi_plate&&t.plates.length>1){ge(t.plates);return}}catch{}v(`/gcode-viewer?archive=${e.id}`)},De=J({mutationFn:()=>Q.deleteArchiveTimelapse(e.id),onSuccess:()=>{p.invalidateQueries({queryKey:[`archives`]}),m(d(`archives.toast.timelapseRemoved`))},onError:e=>{m(e.message||d(`archives.toast.failedRemoveTimelapse`),`error`)}}),Oe=J({mutationFn:t=>Q.uploadArchiveTimelapse(e.id,t),onSuccess:e=>{p.invalidateQueries({queryKey:[`archives`]}),m(d(`archives.toast.timelapseUploaded`,{filename:e.filename}))},onError:e=>{m(e.message||d(`archives.toast.failedUploadTimelapse`),`error`)}}),ke=J({mutationFn:t=>Q.uploadSource3mf(e.id,t),onSuccess:e=>{p.invalidateQueries({queryKey:[`archives`]}),m(d(`archives.toast.source3mfAttached`,{filename:e.filename}))},onError:e=>{m(e.message||d(`archives.toast.failedUploadSource3mf`),`error`)}}),Ae=J({mutationFn:()=>Q.deleteSource3mf(e.id),onSuccess:()=>{p.invalidateQueries({queryKey:[`archives`]}),m(d(`archives.toast.source3mfRemoved`))},onError:e=>{m(e.message||d(`archives.toast.failedRemoveSource3mf`),`error`)}}),je=J({mutationFn:t=>Q.uploadF3d(e.id,t),onSuccess:e=>{p.invalidateQueries({queryKey:[`archives`]}),m(d(`archives.toast.f3dAttached`,{filename:e.filename}))},onError:e=>{m(e.message||d(`archives.toast.failedUploadF3d`),`error`)}}),Me=J({mutationFn:()=>Q.deleteF3d(e.id),onSuccess:()=>{p.invalidateQueries({queryKey:[`archives`]}),m(d(`archives.toast.f3dRemoved`))},onError:e=>{m(e.message||d(`archives.toast.failedRemoveF3d`),`error`)}}),Ne=J({mutationFn:()=>Q.scanArchiveTimelapse(e.id),onSuccess:e=>{e.status===`attached`?(p.invalidateQueries({queryKey:[`archives`]}),m(d(`archives.toast.timelapseAttached`,{filename:e.filename}))):e.status===`exists`?m(d(`archives.toast.timelapseAlreadyAttached`)):e.status===`not_found`&&e.available_files&&e.available_files.length>0?(B(e.available_files),R(!0)):m(e.message||d(`archives.toast.noMatchingTimelapse`),`warning`)},onError:e=>{m(e.message||d(`archives.toast.failedScanTimelapse`),`error`)}}),Pe=J({mutationFn:t=>Q.selectArchiveTimelapse(e.id,t),onSuccess:e=>{p.invalidateQueries({queryKey:[`archives`]}),m(d(`archives.toast.timelapseAttached`,{filename:e.filename})),R(!1),B([])},onError:e=>{m(e.message||d(`archives.toast.failedAttachTimelapse`),`error`)}}),Fe=J({mutationFn:t=>Q.deleteArchive(e.id,t),onSuccess:()=>{p.invalidateQueries({queryKey:[`archives`]}),m(d(`archives.toast.archiveDeleted`))},onError:()=>{m(d(`archives.toast.failedDeleteArchive`),`error`)}}),Ie=J({mutationFn:()=>Q.toggleFavorite(e.id),onSuccess:e=>{p.invalidateQueries({queryKey:[`archives`]}),m(e.is_favorite?d(`archives.toast.addedToFavorites`):d(`archives.toast.removedFromFavorites`))}}),{data:Le}=q({queryKey:[`archive-folders`,e.id],queryFn:()=>Q.getLibraryFoldersByArchive(e.id)}),Re=J({mutationFn:t=>Q.updateArchive(e.id,{project_id:t}),onSuccess:()=>{p.invalidateQueries({queryKey:[`archives`]}),p.invalidateQueries({queryKey:[`projects`]}),m(d(`archives.toast.projectUpdated`))},onError:()=>{m(d(`archives.toast.failedUpdateProject`),`error`)}}),ze=e=>{e.preventDefault(),ue({x:e.clientX,y:e.clientY})},Be=[...a2(e)?[{label:d(`common.print`),icon:(0,K.jsx)(Ol,{className:`w-4 h-4`}),onClick:()=>x(!0),disabled:!e.file_path||!h(`queue:create`)||!g(`archives`,`reprint`,e.created_by_id),title:e.file_path?h(`queue:create`)?g(`archives`,`reprint`,e.created_by_id)?void 0:d(`archives.permission.noReprint`):d(`archives.permission.noAddToQueue`):d(`archives.card.noFileForReprint`)},{label:d(`archives.menu.openInBambuStudio`),icon:(0,K.jsx)(Js,{className:`w-4 h-4`}),onClick:()=>{let t=e.print_name||e.filename||`model`;o2(e.id,t,`file`,c)},disabled:!e.file_path,title:e.file_path?void 0:d(`archives.card.noFileForReprint`)}]:[{label:d(`archives.menu.slice`),icon:l?(0,K.jsx)(ks,{className:`w-4 h-4`}):(0,K.jsx)(Js,{className:`w-4 h-4`}),onClick:()=>{if(l)C(!0);else{let t=e.print_name||e.filename||`model`;o2(e.id,t,`file`,c)}}},...l?[{label:d(`library.runWithPipeline.actionLabel`),icon:(0,K.jsx)(Cl,{className:`w-4 h-4`}),onClick:()=>T(!0),disabled:!h(`pipelines:run`),title:h(`pipelines:run`)?void 0:d(`library.runWithPipeline.noPermission`)}]:[]],{label:e.external_url?d(`archives.menu.externalLink`):d(`archives.menu.viewOnMakerWorld`),icon:(0,K.jsx)(bc,{className:`w-4 h-4`}),onClick:()=>{let t=e.external_url||e.makerworld_url;t&&window.open(t,`_blank`)},disabled:!e.external_url&&!e.makerworld_url},{label:``,divider:!0,onClick:()=>{}},{label:d(`archives.menu.preview3d`),icon:(0,K.jsx)(Wo,{className:`w-4 h-4`}),onClick:()=>{Ee()}},{label:d(`archives.menu.viewTimelapse`),icon:(0,K.jsx)(ic,{className:`w-4 h-4`}),onClick:()=>I(!0),disabled:!e.timelapse_path},{label:d(`archives.menu.scanForTimelapse`),icon:(0,K.jsx)(zl,{className:`w-4 h-4`}),onClick:()=>Ne.mutate(),disabled:!e.printer_id||!!e.timelapse_path||Ne.isPending||!g(`archives`,`update`,e.created_by_id),title:g(`archives`,`update`,e.created_by_id)?void 0:d(`archives.permission.noUpdateArchives`)},{label:d(`archives.menu.uploadTimelapse`),icon:(0,K.jsx)(Au,{className:`w-4 h-4`}),onClick:()=>ye.current?.click(),disabled:!!e.timelapse_path||!g(`archives`,`update`,e.created_by_id),title:g(`archives`,`update`,e.created_by_id)?void 0:d(`archives.permission.noUpdateArchives`)},...e.timelapse_path?[{label:d(`archives.menu.removeTimelapse`),icon:(0,K.jsx)(Cu,{className:`w-4 h-4`}),onClick:()=>ce(!0),danger:!0,disabled:!g(`archives`,`update`,e.created_by_id),title:g(`archives`,`update`,e.created_by_id)?void 0:d(`archives.permission.noUpdateArchives`)}]:[],{label:``,divider:!0,onClick:()=>{}},{label:e.source_3mf_path?d(`archives.menu.downloadSource3mf`):d(`archives.menu.uploadSource3mf`),icon:(0,K.jsx)($s,{className:`w-4 h-4`}),onClick:()=>{e.source_3mf_path?Q.downloadSource3mf(e.id).catch(e=>{console.error(`Source 3MF download failed:`,e)}):_e.current?.click()},disabled:!e.source_3mf_path&&!g(`archives`,`update`,e.created_by_id),title:!e.source_3mf_path&&!g(`archives`,`update`,e.created_by_id)?d(`archives.permission.noUploadFiles`):void 0},...e.source_3mf_path?[{label:d(`archives.menu.replaceSource3mf`),icon:(0,K.jsx)(Au,{className:`w-4 h-4`}),onClick:()=>_e.current?.click(),disabled:!g(`archives`,`update`,e.created_by_id),title:g(`archives`,`update`,e.created_by_id)?void 0:d(`archives.permission.noUpdateArchives`)},{label:d(`archives.menu.removeSource3mf`),icon:(0,K.jsx)(Cu,{className:`w-4 h-4`}),onClick:()=>ae(!0),danger:!0,disabled:!g(`archives`,`update`,e.created_by_id),title:g(`archives`,`update`,e.created_by_id)?void 0:d(`archives.permission.noUpdateArchives`)}]:[],{label:e.f3d_path?d(`archives.menu.replaceF3d`):d(`archives.menu.uploadF3d`),icon:(0,K.jsx)(Wo,{className:`w-4 h-4`}),onClick:()=>ve.current?.click(),disabled:!g(`archives`,`update`,e.created_by_id),title:g(`archives`,`update`,e.created_by_id)?void 0:d(`archives.permission.noUpdateArchives`)},...e.f3d_path?[{label:d(`archives.menu.downloadF3d`),icon:(0,K.jsx)(Vs,{className:`w-4 h-4`}),onClick:()=>{Q.downloadF3d(e.id).catch(e=>{console.error(`F3D download failed:`,e)})}},{label:d(`archives.menu.removeF3d`),icon:(0,K.jsx)(Cu,{className:`w-4 h-4`}),onClick:()=>U(!0),danger:!0,disabled:!g(`archives`,`update`,e.created_by_id),title:g(`archives`,`update`,e.created_by_id)?void 0:d(`archives.permission.noUpdateArchives`)}]:[],{label:``,divider:!0,onClick:()=>{}},{label:d(`archives.menu.download`),icon:(0,K.jsx)(Vs,{className:`w-4 h-4`}),onClick:()=>{Q.downloadArchive(e.id,`${e.print_name||e.filename}.3mf`).catch(e=>{console.error(`Archive download failed:`,e)})},disabled:!h(`archives:read`),title:h(`archives:read`)?void 0:d(`archives.permission.noDownload`)},{label:d(`archives.menu.copyDownloadLink`),icon:(0,K.jsx)(Ms,{className:`w-4 h-4`}),onClick:()=>{let t=`${window.location.origin}${Q.getArchiveDownload(e.id)}`;navigator.clipboard.writeText(t).then(()=>{m(d(`archives.toast.linkCopied`))}).catch(()=>{m(d(`archives.toast.failedCopyLink`),`error`)})},disabled:!h(`archives:read`),title:h(`archives:read`)?void 0:d(`archives.permission.noCopyLink`)},{label:d(`archives.menu.qrCode`),icon:(0,K.jsx)(kl,{className:`w-4 h-4`}),onClick:()=>ee(!0)},{label:e.photos?.length?d(`archives.menu.viewPhotosCount`,{count:e.photos.length}):d(`archives.menu.viewPhotos`),icon:(0,K.jsx)(Zo,{className:`w-4 h-4`}),onClick:()=>ne(!0),disabled:!e.photos?.length},{label:d(`archives.menu.projectPage`),icon:(0,K.jsx)(nc,{className:`w-4 h-4`}),onClick:()=>ie(!0)},{label:``,divider:!0,onClick:()=>{}},{label:e.is_favorite?d(`archives.menu.removeFromFavorites`):d(`archives.menu.addToFavorites`),icon:(0,K.jsx)(uu,{className:`w-4 h-4 ${e.is_favorite?`fill-yellow-400 text-yellow-400`:``}`}),onClick:()=>Ie.mutate(),disabled:!g(`archives`,`update`,e.created_by_id),title:g(`archives`,`update`,e.created_by_id)?void 0:d(`archives.permission.noUpdateArchives`)},{label:d(`archives.menu.edit`),icon:(0,K.jsx)(xl,{className:`w-4 h-4`}),onClick:()=>M(!0),disabled:!g(`archives`,`update`,e.created_by_id),title:g(`archives`,`update`,e.created_by_id)?void 0:d(`archives.permission.noUpdateArchives`)},{label:d(`archives.menu.printLog`),icon:(0,K.jsx)(kc,{className:`w-4 h-4`}),onClick:()=>P(!0)},...e.project_id&&e.project_name?[{label:d(`archives.menu.goToProject`,{name:e.project_name}),icon:(0,K.jsx)(sc,{className:`w-4 h-4 text-bambu-green`}),onClick:()=>window.location.href=`/projects`}]:[],{label:d(`archives.menu.addToProject`),icon:(0,K.jsx)(sc,{className:`w-4 h-4`}),onClick:()=>{},disabled:!g(`archives`,`update`,e.created_by_id),title:g(`archives`,`update`,e.created_by_id)?void 0:d(`archives.permission.noUpdateArchives`),submenuSearchPlaceholder:(a?.filter(e=>e.status===`active`).length??0)>5?d(`archives.menu.searchProjects`):void 0,submenu:(()=>{let t=[];if(e.project_id&&t.push({label:d(`archives.menu.removeFromProject`),icon:(0,K.jsx)(Wu,{className:`w-4 h-4`}),onClick:()=>Re.mutate(null),disabled:!g(`archives`,`update`,e.created_by_id)}),!a)t.push({label:d(`archives.menu.loading`),icon:(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),onClick:()=>{},disabled:!0});else{let n=a.filter(e=>e.status===`active`).sort((e,t)=>e.name.localeCompare(t.name));n.length===0?t.push({label:d(`archives.menu.noProjectsAvailable`),icon:(0,K.jsx)(sc,{className:`w-4 h-4 opacity-50`}),onClick:()=>{},disabled:!0}):n.forEach(n=>{t.push({label:n.name,icon:(0,K.jsx)(`div`,{className:`w-3 h-3 rounded-full flex-shrink-0`,style:{backgroundColor:n.color||`#888`}}),onClick:()=>Re.mutate(n.id),disabled:e.project_id===n.id||!g(`archives`,`update`,e.created_by_id)})})}return t})()},{label:d(n?`archives.menu.deselect`:`archives.menu.select`),icon:n?(0,K.jsx)(su,{className:`w-4 h-4`}):(0,K.jsx)(lu,{className:`w-4 h-4`}),onClick:()=>r(e.id)},{label:``,divider:!0,onClick:()=>{}},{label:d(`archives.menu.delete`),icon:(0,K.jsx)(Cu,{className:`w-4 h-4`}),onClick:()=>D(!0),danger:!0,disabled:!g(`archives`,`delete`,e.created_by_id),title:g(`archives`,`delete`,e.created_by_id)?void 0:d(`archives.permission.noDelete`)}];return(0,K.jsxs)(Cd,{"data-archive-id":e.id,className:`relative flex flex-col group ${n?`ring-2 ring-bambu-green`:``} ${i?`cursor-pointer`:``}`,style:o?{outline:`4px solid #facc15`,outlineOffset:`2px`}:void 0,onContextMenu:ze,onClick:i?()=>r(e.id):void 0,children:[i&&(0,K.jsx)(`button`,{className:`absolute top-2 left-2 z-10 p-1 rounded bg-black/50 hover:bg-black/70 transition-colors`,onClick:t=>{t.stopPropagation(),r(e.id)},children:n?(0,K.jsx)(su,{className:`w-5 h-5 text-bambu-green`}):(0,K.jsx)(lu,{className:`w-5 h-5 text-white`})}),(0,K.jsxs)(`div`,{className:`aspect-video bg-bambu-dark relative flex-shrink-0 overflow-hidden rounded-t-xl`,onMouseEnter:()=>me(!0),onMouseLeave:()=>me(!1),children:[e.thumbnail_path?(0,K.jsx)(`img`,{src:de!==null&&Ce.length>0?Q.getArchivePlateThumbnail(e.id,Ce[Te]?.index??0):Q.getArchiveThumbnail(e.id),alt:e.print_name||e.filename,className:`w-full h-full object-cover`}):(0,K.jsx)(`div`,{className:`w-full h-full flex items-center justify-center`,children:(0,K.jsx)(Mc,{className:`w-12 h-12 text-bambu-dark-tertiary`})}),we&&Ce.length>1&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`button`,{className:`absolute left-1 top-1/2 -translate-y-1/2 p-1 rounded-full bg-black/60 hover:bg-black/80 transition-all ${_?`opacity-100`:`opacity-0 group-hover:opacity-100`}`,onClick:e=>{e.stopPropagation(),fe(e=>{let t=e??0;return t>0?t-1:Ce.length-1})},title:d(`archives.card.previousPlate`),children:(0,K.jsx)(as,{className:`w-4 h-4 text-white`})}),(0,K.jsx)(`button`,{className:`absolute right-1 top-1/2 -translate-y-1/2 p-1 rounded-full bg-black/60 hover:bg-black/80 transition-all ${_?`opacity-100`:`opacity-0 group-hover:opacity-100`}`,onClick:e=>{e.stopPropagation(),fe(e=>{let t=e??0;return t(0,K.jsx)(`button`,{className:`w-2 h-2 rounded-full transition-colors ${t===Te?`bg-bambu-green`:`bg-white/50 hover:bg-white/80`}`,onClick:e=>{e.stopPropagation(),fe(t)},title:e.name||d(`archives.card.plateNumber`,{index:e.index})},e.index))})]}),(0,K.jsx)(`button`,{className:`absolute top-2 left-2 p-1.5 rounded bg-black/50 hover:bg-black/70 transition-all ${_?`opacity-100`:`opacity-0 group-hover:opacity-100`} ${i?`left-10`:``}`,onClick:e=>{e.stopPropagation();let t=e.currentTarget.getBoundingClientRect();ue({x:t.left,y:t.bottom+4})},title:d(`archives.card.moreOptions`),children:(0,K.jsx)(Ws,{className:`w-5 h-5 text-white`})}),(0,K.jsx)(`button`,{className:`absolute top-2 right-2 p-1 rounded transition-colors ${g(`archives`,`update`,e.created_by_id)?`bg-black/50 hover:bg-black/70`:`bg-black/30 cursor-not-allowed`}`,onClick:t=>{t.stopPropagation(),g(`archives`,`update`,e.created_by_id)&&Ie.mutate()},disabled:!g(`archives`,`update`,e.created_by_id),title:g(`archives`,`update`,e.created_by_id)?e.is_favorite?d(`archives.card.removeFromFavorites`):d(`archives.card.addToFavorites`):d(`archives.permission.noUpdateArchives`),children:(0,K.jsx)(uu,{className:`w-5 h-5 ${e.is_favorite?`text-yellow-400 fill-yellow-400`:`text-white`} ${g(`archives`,`update`,e.created_by_id)?``:`opacity-50`}`})}),(e.status===`failed`||e.status===`aborted`)&&(0,K.jsx)(`div`,{className:`absolute top-2 left-12 px-2 py-1 rounded text-xs bg-status-error/80 text-white`,children:e.status===`aborted`?d(`archives.card.cancelled`):d(`archives.card.failed`)}),e.duplicate_count>0&&xe>0&&Se&&(0,K.jsxs)(`button`,{onClick:e=>{e.stopPropagation(),f?.(Se)},className:`absolute top-2 right-12 px-2 py-1 rounded text-xs bg-purple-500/80 hover:bg-purple-600/90 text-white flex items-center gap-1 transition-colors cursor-pointer`,title:d(`archives.viewOriginalPrint`,{id:Se}),children:[(0,K.jsx)(Ms,{className:`w-3 h-3`}),`#`,xe]}),e.duplicate_count>0&&xe===0&&(0,K.jsxs)(`span`,{className:`absolute top-2 right-12 px-2 py-1 rounded text-xs bg-purple-500/80 text-white flex items-center gap-1`,title:`${e.duplicate_count} reprint${e.duplicate_count===1?``:`s`}`,children:[(0,K.jsx)(_c,{className:`w-3 h-3`}),`+`,e.duplicate_count]}),e.source_3mf_path&&(0,K.jsx)(`button`,{className:`absolute bottom-2 left-2 p-1.5 rounded bg-black/60 hover:bg-black/80 transition-colors`,onClick:t=>{t.stopPropagation();let n=(e.print_name||e.filename||`source`).replace(/\.gcode\.3mf$/i,``)+`_source`;o2(e.id,n,`source`,c)},title:d(`archives.card.openSource3mf`),children:(0,K.jsx)($s,{className:`w-4 h-4 text-orange-400`})}),e.f3d_path&&(0,K.jsx)(`button`,{className:`absolute bottom-2 ${e.source_3mf_path?`left-12`:`left-2`} p-1.5 rounded bg-black/60 hover:bg-black/80 transition-colors`,onClick:t=>{t.stopPropagation(),Q.downloadF3d(e.id).catch(e=>{console.error(`F3D download failed:`,e)})},title:d(`archives.card.downloadF3d`),children:(0,K.jsx)(Wo,{className:`w-4 h-4 text-cyan-400`})}),(0,K.jsx)(`button`,{className:`absolute bottom-2 right-2 p-1.5 rounded bg-black/60 hover:bg-black/80 transition-colors`,onClick:e=>{e.stopPropagation(),Ee()},title:d(`archives.card.preview3d`),children:(0,K.jsx)(Rc,{className:`w-4 h-4 text-white`})}),e.timelapse_path&&(0,K.jsx)(`button`,{className:`absolute bottom-2 right-12 p-1.5 rounded bg-black/60 hover:bg-black/80 transition-colors`,onClick:e=>{e.stopPropagation(),I(!0)},title:d(`archives.card.viewTimelapse`),children:(0,K.jsx)(ic,{className:`w-4 h-4 text-bambu-green`})}),e.photos&&e.photos.length>0&&(0,K.jsxs)(`button`,{className:`absolute bottom-2 ${e.timelapse_path?`right-[5.5rem]`:`right-12`} p-1.5 rounded bg-black/60 hover:bg-black/80 transition-colors`,onClick:e=>{e.stopPropagation(),ne(!0)},title:e.photos.length===1?d(`archives.card.viewPhoto`):d(`archives.card.viewPhotos`,{count:e.photos.length}),children:[(0,K.jsx)(Zo,{className:`w-4 h-4 text-blue-400`}),e.photos.length>1&&(0,K.jsx)(`span`,{className:`absolute -top-1 -right-1 w-4 h-4 bg-blue-500 rounded-full text-[10px] text-white flex items-center justify-center`,children:e.photos.length})]}),Le&&Le.length>0&&(0,K.jsx)(wi,{to:`/files?folder=${Le[0].id}`,className:`absolute bottom-2 p-1.5 rounded bg-black/60 hover:bg-black/80 transition-colors`,onClick:e=>e.stopPropagation(),title:d(`archives.card.openFolder`,{name:Le[0].name}),style:{left:e.source_3mf_path?e.f3d_path?`5.5rem`:`3rem`:e.f3d_path?`3rem`:`0.5rem`},children:(0,K.jsx)(cc,{className:`w-4 h-4 text-yellow-400`})})]}),(0,K.jsxs)(Td,{className:`p-4 flex-1 flex flex-col`,children:[(0,K.jsxs)(`p`,{className:`text-[10px] text-bambu-gray/70 mb-1`,children:[`#`,e.id]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between gap-2 mb-1`,children:[(0,K.jsx)(`h3`,{className:`min-w-0 font-medium text-white truncate`,children:e.print_name||e.filename}),(0,K.jsx)($,{variant:`ghost`,size:`sm`,className:`p-1 sm:p-1.5 shrink-0`,onClick:()=>M(!0),disabled:!g(`archives`,`update`,e.created_by_id),title:g(`archives`,`update`,e.created_by_id)?d(`archives.card.edit`):d(`archives.card.noPermissionEdit`),children:(0,K.jsx)(xl,{className:`w-3 h-3 sm:w-4 sm:h-4`})})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-3 flex-wrap`,children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:t}),(()=>{let t=iW(e.bed_type);return t?(0,K.jsx)(`img`,{src:t.icon,alt:t.label,title:t.label,className:`w-4 h-4 flex-shrink-0`}):null})(),(0,K.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded font-medium ${a2(e)?`bg-bambu-green/20 text-bambu-green`:`bg-orange-100 dark:bg-orange-500/20 text-orange-700 dark:text-orange-400`}`,title:a2(e)?d(`archives.card.slicedFile`):d(`archives.card.sourceFile`),children:a2(e)?d(`archives.card.gcode`):d(`archives.card.source`)}),e.content_hash&&(0,K.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded font-mono bg-bambu-dark-tertiary/50 text-bambu-gray-light opacity-0 transition-opacity duration-150 group-hover:opacity-100`,title:`SHA256: ${e.content_hash}`,children:e.content_hash.slice(0,8).toUpperCase()}),e.project_name&&(0,K.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded-full truncate max-w-[120px]`,style:{backgroundColor:`${a?.find(t=>t.id===e.project_id)?.color||`#6b7280`}20`,color:a?.find(t=>t.id===e.project_id)?.color||`#6b7280`},title:d(`archives.card.project`,{name:e.project_name}),children:e.project_name}),e.run_count>1&&(0,K.jsx)(`button`,{className:`text-[10px] px-1.5 py-0.5 rounded font-medium bg-bambu-orange/20 text-bambu-orange hover:bg-bambu-orange/30 transition-colors cursor-pointer`,onClick:e=>{e.stopPropagation(),P(!0)},title:d(`archives.card.runsBadgeTitle`,{count:e.run_count,successful:e.successful_run_count,failed:e.failed_run_count}),children:d(`archives.card.runsBadge`,{count:e.run_count})})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-2 text-xs mb-4 min-h-[48px]`,children:[(e.print_time_seconds||e.actual_time_seconds)&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 text-bambu-gray`,title:e.time_accuracy?`Estimated: ${Ff(e.print_time_seconds||0)}\nActual: ${Ff(e.actual_time_seconds||0)}\nAccuracy: ${e.time_accuracy.toFixed(0)}%`:e.actual_time_seconds?`Actual: ${Ff(e.actual_time_seconds)}`:`Estimated: ${Ff(e.print_time_seconds||0)}`,children:[(0,K.jsx)(xs,{className:`w-3 h-3`}),Ff(e.actual_time_seconds||e.print_time_seconds||0),e.time_accuracy&&(0,K.jsxs)(`span`,{className:`text-[10px] px-1 rounded ${e.time_accuracy>=95&&e.time_accuracy<=105?`bg-bambu-green/20 text-bambu-green`:e.time_accuracy>105?`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`:`bg-orange-100 dark:bg-orange-500/20 text-orange-700 dark:text-orange-400`}`,children:[e.time_accuracy>100?`+`:``,(e.time_accuracy-100).toFixed(0),`%`]})]}),e.filament_used_grams&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 text-bambu-gray`,children:[(0,K.jsx)(ml,{className:`w-3 h-3`}),e.filament_used_grams.toFixed(1),`g`]}),(e.cost!=null||e.energy_cost!=null)&&(0,K.jsxs)(`div`,{className:`flex items-center gap-3 text-bambu-gray`,children:[e.cost!=null&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,K.jsx)(Os,{className:`w-3 h-3`}),u,e.cost.toFixed(2)]}),e.energy_cost!=null&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5`,title:`${d(`stats.energyUsed`)}: ${e.energy_kwh?.toFixed(3)||`N/A`} kWh`,children:[(0,K.jsx)(Ku,{className:`w-3 h-3`}),u,e.energy_cost.toFixed(2)]})]}),(e.layer_height||e.total_layers)&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 text-bambu-gray`,children:[(0,K.jsx)(Rc,{className:`w-3 h-3`}),e.total_layers&&(0,K.jsx)(`span`,{children:e.total_layers===1?d(`archives.card.layer`,{count:e.total_layers}):d(`archives.card.layers`,{count:e.total_layers})}),e.total_layers&&e.layer_height&&(0,K.jsx)(`span`,{className:`text-bambu-gray/50`,children:`·`}),e.layer_height&&(0,K.jsxs)(`span`,{children:[e.layer_height,`mm`]})]}),e.object_count!=null&&e.object_count>0&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 text-bambu-gray`,title:e.object_count===1?d(`archives.card.object`,{count:e.object_count}):d(`archives.card.objects`,{count:e.object_count}),children:[(0,K.jsx)(Wo,{className:`w-3 h-3`}),e.object_count===1?d(`archives.card.object`,{count:e.object_count}):d(`archives.card.objects`,{count:e.object_count})]}),e.sliced_for_model&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 text-bambu-gray`,title:d(`archives.card.slicedFor`,{model:e.sliced_for_model}),children:[(0,K.jsx)(Ol,{className:`w-3 h-3`}),e.sliced_for_model]}),e.filament_type&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 col-span-2`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray text-xs`,children:e.filament_type}),e.filament_color&&(0,K.jsx)(`div`,{className:`flex items-center gap-0.5 flex-wrap`,children:e.filament_color.split(`,`).map((e,t)=>(0,K.jsx)(`div`,{className:`w-3 h-3 rounded-full border border-black/20`,style:{backgroundColor:e},title:e},t))})]})]}),(e.tags||e.notes)&&(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5 mb-3`,children:[e.notes&&(0,K.jsx)(`div`,{className:`flex items-center gap-1 px-1.5 py-0.5 bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400 rounded text-xs`,title:e.notes,children:(0,K.jsx)(fu,{className:`w-3 h-3`})}),e.tags?.split(`,`).map((e,t)=>(0,K.jsx)(`span`,{className:`px-1.5 py-0.5 bg-bambu-dark-tertiary text-bambu-gray-light rounded text-xs`,children:e.trim()},t))]}),(0,K.jsx)(`div`,{className:`flex-1`}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between text-xs text-bambu-gray border-t border-bambu-dark-tertiary pt-3`,children:[(0,K.jsx)(`span`,{children:Mf(e.created_at,s)}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.created_by_username&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1`,title:d(`archives.card.uploadedBy`,{name:e.created_by_username}),children:[(0,K.jsx)(ju,{className:`w-3 h-3`}),e.created_by_username]}),(0,K.jsx)(`span`,{children:kd(e.file_size)})]})]}),(0,K.jsxs)(`div`,{className:`flex gap-1 mt-3`,children:[a2(e)?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)($,{variant:`primary`,size:`sm`,className:`flex-1 min-w-0 overflow-hidden`,onClick:()=>x(!0),disabled:!e.file_path||!h(`queue:create`)||!g(`archives`,`reprint`,e.created_by_id),title:e.file_path?h(`queue:create`)?g(`archives`,`reprint`,e.created_by_id)?void 0:d(`archives.card.noPermissionReprint`):d(`archives.permission.noAddToQueue`):d(`archives.card.noFileForReprint`),children:[(0,K.jsx)(Ol,{className:`w-3 h-3 flex-shrink-0`}),(0,K.jsx)(`span`,{className:`hidden xl:inline truncate`,children:d(`common.print`)})]}),(0,K.jsx)($,{variant:`secondary`,size:`sm`,className:`min-w-0 p-1 sm:p-1.5`,onClick:()=>{let t=e.print_name||e.filename||`model`;o2(e.id,t,`file`,c)},title:d(`archives.card.openInBambuStudio`),children:(0,K.jsx)(Js,{className:`w-3 h-3 sm:w-4 sm:h-4`})})]}):(0,K.jsxs)($,{variant:`primary`,size:`sm`,className:`flex-1 min-w-0 overflow-hidden`,onClick:()=>{if(l)C(!0);else{let t=e.print_name||e.filename||`model`;o2(e.id,t,`file`,c)}},title:d(l?`slice.title`:`archives.card.openInBambuStudioToSlice`),children:[l?(0,K.jsx)(ks,{className:`w-3 h-3 flex-shrink-0`}):(0,K.jsx)(Js,{className:`w-3 h-3 flex-shrink-0`}),(0,K.jsx)(`span`,{className:`hidden xl:inline truncate`,children:d(`archives.card.slice`)})]}),(0,K.jsx)($,{variant:`secondary`,size:`sm`,className:`min-w-0 p-1 sm:p-1.5`,onClick:()=>{let t=e.external_url||e.makerworld_url;t&&window.open(t,`_blank`)},disabled:!e.external_url&&!e.makerworld_url,title:e.external_url?d(`archives.card.externalLink`):e.makerworld_url?d(`archives.card.makerWorld`,{designer:e.designer||d(`archives.card.viewProject`)}):d(`archives.card.noExternalLink`),children:(0,K.jsx)(bc,{className:`w-3 h-3 sm:w-4 sm:h-4 ${!e.external_url&&!e.makerworld_url?`opacity-20`:``}`})}),(0,K.jsx)($,{variant:`secondary`,size:`sm`,className:`min-w-0 p-1 sm:p-1.5`,onClick:()=>{Q.downloadArchive(e.id,`${e.print_name||e.filename}.3mf`).catch(e=>{console.error(`Archive download failed:`,e)})},title:d(`archives.card.download`),children:(0,K.jsx)(Vs,{className:`w-3 h-3 sm:w-4 sm:h-4`})}),(0,K.jsx)($,{variant:`ghost`,size:`sm`,className:`min-w-0 p-1 sm:p-1.5`,onClick:()=>D(!0),disabled:!g(`archives`,`delete`,e.created_by_id),title:g(`archives`,`delete`,e.created_by_id)?d(`archives.card.delete`):d(`archives.card.noPermissionDelete`),children:(0,K.jsx)(Cu,{className:`w-3 h-3 sm:w-4 sm:h-4 text-red-600 dark:text-red-400`})})]})]}),j&&(0,K.jsx)($W,{archive:e,onClose:()=>M(!1)}),N&&(0,K.jsx)(eG,{archiveId:e.id,archiveName:e.print_name||e.filename,onClose:()=>P(!1)}),he&&(0,K.jsx)(RW,{plates:he,onSelect:t=>{ge(null),v(`/gcode-viewer?archive=${e.id}&plate=${t}`)},onClose:()=>ge(null)}),b&&(0,K.jsx)(uW,{mode:`create`,archiveId:e.id,archiveName:e.print_name||e.filename,onClose:()=>x(!1)}),S&&(0,K.jsx)(UW,{source:{kind:`archive`,id:e.id,filename:e.print_name||e.filename||`model`},onClose:()=>C(!1)}),w&&(0,K.jsx)(KW,{source:{kind:`archive`,id:e.id,filename:e.print_name||e.filename||`model`},onClose:()=>T(!1)}),E&&(0,K.jsxs)(Bd,{title:d(`archives.modal.deleteArchive`),message:d(`archives.modal.deleteConfirm`,{name:e.print_name||e.filename}),confirmText:d(`archives.modal.deleteButton`),variant:`danger`,confirmDisabled:(A.data?.currently_printing??0)>0,onConfirm:()=>{Fe.mutate(O),D(!1),k(!1)},onCancel:()=>{D(!1),k(!1)},children:[(A.data?.related_queue_items??0)>0&&(0,K.jsx)(`div`,{className:(A.data?.currently_printing??0)>0?`text-sm text-red-600 dark:text-red-400 mb-2`:`text-sm text-amber-600 dark:text-amber-400 mb-2`,children:(A.data?.currently_printing??0)>0?d(`archives.modal.deleteBlockedByPrinting`,{count:A.data.currently_printing}):d(`archives.modal.deleteQueueItemsWarning`,{count:A.data.related_queue_items})}),(0,K.jsxs)(`label`,{className:`flex items-start gap-2 cursor-pointer text-sm text-bambu-gray`,children:[(0,K.jsx)(`input`,{type:`checkbox`,className:`mt-0.5 accent-red-500`,checked:O,onChange:e=>k(e.target.checked)}),(0,K.jsx)(`span`,{children:d(`archives.modal.deletePurgeStats`)})]})]}),H&&(0,K.jsx)(Bd,{title:d(`archives.modal.removeSource3mf`),message:d(`archives.modal.removeSource3mfConfirm`,{name:e.print_name||e.filename}),confirmText:d(`archives.modal.removeButton`),variant:`danger`,onConfirm:()=>{Ae.mutate(),ae(!1)},onCancel:()=>ae(!1)}),oe&&(0,K.jsx)(Bd,{title:d(`archives.modal.removeF3d`),message:d(`archives.modal.removeF3dConfirm`,{name:e.print_name||e.filename}),confirmText:d(`archives.modal.removeButton`),variant:`danger`,onConfirm:()=>{Me.mutate(),U(!1)},onCancel:()=>U(!1)}),se&&(0,K.jsx)(Bd,{title:d(`archives.modal.removeTimelapse`),message:d(`archives.modal.removeTimelapseConfirm`,{name:e.print_name||e.filename}),confirmText:d(`archives.modal.removeButton`),variant:`danger`,onConfirm:()=>{De.mutate(),ce(!1)},onCancel:()=>ce(!1)}),le&&(0,K.jsx)(tG,{x:le.x,y:le.y,items:Be,onClose:()=>ue(null)}),F&&e.timelapse_path&&(0,K.jsx)(i2,{src:Q.getArchiveTimelapse(e.id),title:d(`archives.modal.timelapse`,{name:e.print_name||e.filename}),downloadFilename:`${e.print_name||e.filename}_timelapse.mp4`,archiveId:e.id,onClose:()=>I(!1),onEdit:()=>{p.invalidateQueries({queryKey:[`archives`]}),I(!1)}}),L&&z.length>0&&(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/80 flex items-center justify-center z-50 p-4`,children:(0,K.jsxs)(`div`,{className:`bg-card-dark rounded-lg max-w-lg w-full max-h-[80vh] flex flex-col`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-gray-700`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h3`,{className:`text-lg font-semibold text-white`,children:d(`archives.modal.selectTimelapse`)}),(0,K.jsx)(`p`,{className:`text-sm text-gray-400 mt-1`,children:d(`archives.modal.selectTimelapseDesc`)})]}),(0,K.jsx)(`button`,{onClick:()=>{R(!1),B([])},className:`text-gray-400 hover:text-white p-1`,children:(0,K.jsx)(Wu,{className:`w-5 h-5`})})]}),(0,K.jsx)(`div`,{className:`overflow-y-auto flex-1 p-2`,children:z.map(e=>(0,K.jsxs)(`button`,{onClick:()=>Pe.mutate(e.name),disabled:Pe.isPending,className:`w-full text-left p-3 rounded-lg hover:bg-gray-700 transition-colors flex items-center gap-3 disabled:opacity-50`,children:[(0,K.jsx)(ic,{className:`w-8 h-8 text-bambu-green flex-shrink-0`}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsx)(`p`,{className:`text-white font-medium truncate`,children:e.name}),(0,K.jsxs)(`p`,{className:`text-sm text-gray-400`,children:[kd(e.size),e.mtime&&` • ${Mf(e.mtime,s)}`]})]})]},e.name))}),(0,K.jsx)(`div`,{className:`p-4 border-t border-gray-700`,children:(0,K.jsx)($,{variant:`secondary`,onClick:()=>{R(!1),B([])},className:`w-full`,children:`Cancel`})})]})}),V&&(0,K.jsx)(nG,{archiveId:e.id,archiveName:e.print_name||e.filename,onClose:()=>ee(!1)}),te&&e.photos&&e.photos.length>0&&(0,K.jsx)(rG,{archiveId:e.id,archiveName:e.print_name||e.filename,photos:e.photos,onClose:()=>ne(!1),onDelete:async t=>{try{await Q.deleteArchivePhoto(e.id,t),p.invalidateQueries({queryKey:[`archives`]}),m(d(`archives.toast.photoDeleted`))}catch{m(d(`archives.toast.failedDeletePhoto`),`error`)}}}),re&&(0,K.jsx)(r2,{archiveId:e.id,archiveName:e.print_name||e.filename,onClose:()=>ie(!1)}),(0,K.jsx)(`input`,{ref:_e,type:`file`,accept:`.3mf`,className:`hidden`,onChange:e=>{let t=e.target.files?.[0];t&&ke.mutate(t),e.target.value=``}}),(0,K.jsx)(`input`,{ref:ve,type:`file`,accept:`.f3d`,className:`hidden`,onChange:e=>{let t=e.target.files?.[0];t&&je.mutate(t),e.target.value=``}}),(0,K.jsx)(`input`,{ref:ye,type:`file`,accept:`.mp4,.avi,.mkv`,className:`hidden`,onChange:e=>{let t=e.target.files?.[0];t&&Oe.mutate(t),e.target.value=``}})]})}function kze({archive:e,printerName:t,isSelected:n,onSelect:r,selectionMode:i,projects:a,isHighlighted:o,preferredSlicer:s=`bambu_studio`,useSlicerApi:c=!1,t:l,onNavigateToArchive:u}){let d=no(),{showToast:f}=jd(),{hasPermission:p,canModify:m}=_d(),[h,g]=(0,y.useState)(!1),[_,v]=(0,y.useState)(!1),[b,x]=(0,y.useState)(!1),[S,C]=(0,y.useState)(!1),w=q({queryKey:[`archive`,e.id,`delete-impact`],queryFn:()=>Q.getArchiveDeleteImpact(e.id),enabled:b,staleTime:0}),T=$n(),[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)(!1),[I,L]=(0,y.useState)([]),[R,z]=(0,y.useState)(!1),[B,V]=(0,y.useState)(!1),[ee,te]=(0,y.useState)(!1),[ne,re]=(0,y.useState)(!1),[ie,H]=(0,y.useState)(!1),[ae,oe]=(0,y.useState)(!1),[U,se]=(0,y.useState)(null),ce=(0,y.useRef)(null),le=(0,y.useRef)(null),ue=(0,y.useRef)(null),[de,fe]=(0,y.useState)(null),pe=e.duplicate_sequence??0,me=e.original_archive_id??null,he=async()=>{try{let t=await Q.getArchivePlates(e.id);if(t.is_multi_plate&&t.plates.length>1){fe(t.plates);return}}catch{}T(`/gcode-viewer?archive=${e.id}`)},ge=J({mutationFn:()=>Q.deleteArchiveTimelapse(e.id),onSuccess:()=>{d.invalidateQueries({queryKey:[`archives`]}),f(l(`archives.toast.timelapseRemoved`))},onError:e=>{f(e.message||l(`archives.toast.failedRemoveTimelapse`),`error`)}}),_e=J({mutationFn:t=>Q.uploadArchiveTimelapse(e.id,t),onSuccess:e=>{d.invalidateQueries({queryKey:[`archives`]}),f(l(`archives.toast.timelapseUploaded`,{filename:e.filename}))},onError:e=>{f(e.message||l(`archives.toast.failedUploadTimelapse`),`error`)}}),ve=J({mutationFn:t=>Q.uploadSource3mf(e.id,t),onSuccess:e=>{d.invalidateQueries({queryKey:[`archives`]}),f(l(`archives.toast.source3mfAttached`,{filename:e.filename}))},onError:e=>{f(e.message||l(`archives.toast.failedUploadSource3mf`),`error`)}}),ye=J({mutationFn:()=>Q.deleteSource3mf(e.id),onSuccess:()=>{d.invalidateQueries({queryKey:[`archives`]}),f(l(`archives.toast.source3mfRemoved`))},onError:e=>{f(e.message||l(`archives.toast.failedRemoveSource3mf`),`error`)}}),be=J({mutationFn:t=>Q.uploadF3d(e.id,t),onSuccess:e=>{d.invalidateQueries({queryKey:[`archives`]}),f(l(`archives.toast.f3dAttached`,{filename:e.filename}))},onError:e=>{f(e.message||l(`archives.toast.failedUploadF3d`),`error`)}}),xe=J({mutationFn:()=>Q.deleteF3d(e.id),onSuccess:()=>{d.invalidateQueries({queryKey:[`archives`]}),f(l(`archives.toast.f3dRemoved`))},onError:e=>{f(e.message||l(`archives.toast.failedRemoveF3d`),`error`)}}),Se=J({mutationFn:()=>Q.scanArchiveTimelapse(e.id),onSuccess:e=>{e.status===`attached`?(d.invalidateQueries({queryKey:[`archives`]}),f(l(`archives.toast.timelapseAttached`,{filename:e.filename}))):e.status===`exists`?f(l(`archives.toast.timelapseAlreadyAttached`)):e.status===`not_found`&&e.available_files&&e.available_files.length>0?(L(e.available_files),F(!0)):f(e.message||l(`archives.toast.noMatchingTimelapse`),`warning`)},onError:e=>{f(e.message||l(`archives.toast.failedScanTimelapse`),`error`)}}),Ce=J({mutationFn:t=>Q.selectArchiveTimelapse(e.id,t),onSuccess:e=>{d.invalidateQueries({queryKey:[`archives`]}),f(l(`archives.toast.timelapseAttached`,{filename:e.filename})),F(!1),L([])},onError:e=>{f(e.message||l(`archives.toast.failedAttachTimelapse`),`error`)}}),we=J({mutationFn:t=>Q.deleteArchive(e.id,t),onSuccess:()=>{d.invalidateQueries({queryKey:[`archives`]}),f(l(`archives.toast.archiveDeleted`))},onError:()=>{f(l(`archives.toast.failedDeleteArchive`),`error`)}}),Te=J({mutationFn:()=>Q.toggleFavorite(e.id),onSuccess:e=>{d.invalidateQueries({queryKey:[`archives`]}),f(e.is_favorite?l(`archives.toast.addedToFavorites`):l(`archives.toast.removedFromFavorites`))}}),{data:Ee}=q({queryKey:[`archive-folders`,e.id],queryFn:()=>Q.getLibraryFoldersByArchive(e.id)}),De=J({mutationFn:t=>Q.updateArchive(e.id,{project_id:t}),onSuccess:()=>{d.invalidateQueries({queryKey:[`archives`]}),d.invalidateQueries({queryKey:[`projects`]}),f(l(`archives.toast.projectUpdated`))},onError:()=>{f(l(`archives.toast.failedUpdateProject`),`error`)}}),Oe=e=>{e.preventDefault(),se({x:e.clientX,y:e.clientY})},ke=[...a2(e)?[{label:l(`common.print`),icon:(0,K.jsx)(Ol,{className:`w-4 h-4`}),onClick:()=>D(!0),disabled:!e.file_path||!p(`queue:create`)||!m(`archives`,`reprint`,e.created_by_id),title:e.file_path?p(`queue:create`)?m(`archives`,`reprint`,e.created_by_id)?void 0:l(`archives.permission.noReprint`):l(`archives.permission.noAddToQueue`):l(`archives.card.noFileForReprint`)},{label:l(`archives.menu.openInBambuStudio`),icon:(0,K.jsx)(Js,{className:`w-4 h-4`}),onClick:()=>{let t=e.print_name||e.filename||`model`;o2(e.id,t,`file`,s)},disabled:!e.file_path,title:e.file_path?void 0:l(`archives.card.noFileForReprint`)}]:[{label:l(`archives.menu.slice`),icon:c?(0,K.jsx)(ks,{className:`w-4 h-4`}):(0,K.jsx)(Js,{className:`w-4 h-4`}),onClick:()=>{if(c)k(!0);else{let t=e.print_name||e.filename||`model`;o2(e.id,t,`file`,s)}}},...c?[{label:l(`library.runWithPipeline.actionLabel`),icon:(0,K.jsx)(Cl,{className:`w-4 h-4`}),onClick:()=>j(!0),disabled:!p(`pipelines:run`),title:p(`pipelines:run`)?void 0:l(`library.runWithPipeline.noPermission`)}]:[]],{label:e.external_url?l(`archives.menu.externalLink`):l(`archives.menu.viewOnMakerWorld`),icon:(0,K.jsx)(bc,{className:`w-4 h-4`}),onClick:()=>{let t=e.external_url||e.makerworld_url;t&&window.open(t,`_blank`)},disabled:!e.external_url&&!e.makerworld_url},{label:``,divider:!0,onClick:()=>{}},{label:l(`archives.menu.preview3d`),icon:(0,K.jsx)(Wo,{className:`w-4 h-4`}),onClick:()=>{he()}},{label:l(`archives.menu.viewTimelapse`),icon:(0,K.jsx)(ic,{className:`w-4 h-4`}),onClick:()=>N(!0),disabled:!e.timelapse_path},{label:l(`archives.menu.scanForTimelapse`),icon:(0,K.jsx)(zl,{className:`w-4 h-4`}),onClick:()=>Se.mutate(),disabled:!e.printer_id||!!e.timelapse_path||Se.isPending||!m(`archives`,`update`,e.created_by_id),title:m(`archives`,`update`,e.created_by_id)?void 0:l(`archives.permission.noUpdateArchives`)},{label:l(`archives.menu.uploadTimelapse`),icon:(0,K.jsx)(Au,{className:`w-4 h-4`}),onClick:()=>ue.current?.click(),disabled:!!e.timelapse_path||!m(`archives`,`update`,e.created_by_id),title:m(`archives`,`update`,e.created_by_id)?void 0:l(`archives.permission.noUpdateArchives`)},...e.timelapse_path?[{label:l(`archives.menu.removeTimelapse`),icon:(0,K.jsx)(Cu,{className:`w-4 h-4`}),onClick:()=>oe(!0),danger:!0,disabled:!m(`archives`,`update`,e.created_by_id),title:m(`archives`,`update`,e.created_by_id)?void 0:l(`archives.permission.noUpdateArchives`)}]:[],{label:``,divider:!0,onClick:()=>{}},{label:e.source_3mf_path?l(`archives.menu.downloadSource3mf`):l(`archives.menu.uploadSource3mf`),icon:(0,K.jsx)($s,{className:`w-4 h-4`}),onClick:()=>{e.source_3mf_path?Q.downloadSource3mf(e.id).catch(e=>{console.error(`Source 3MF download failed:`,e)}):ce.current?.click()},disabled:!e.source_3mf_path&&!m(`archives`,`update`,e.created_by_id),title:!e.source_3mf_path&&!m(`archives`,`update`,e.created_by_id)?l(`archives.permission.noUploadFiles`):void 0},...e.source_3mf_path?[{label:l(`archives.menu.replaceSource3mf`),icon:(0,K.jsx)(Au,{className:`w-4 h-4`}),onClick:()=>ce.current?.click(),disabled:!m(`archives`,`update`,e.created_by_id),title:m(`archives`,`update`,e.created_by_id)?void 0:l(`archives.permission.noUpdateArchives`)},{label:l(`archives.menu.removeSource3mf`),icon:(0,K.jsx)(Cu,{className:`w-4 h-4`}),onClick:()=>re(!0),danger:!0,disabled:!m(`archives`,`update`,e.created_by_id),title:m(`archives`,`update`,e.created_by_id)?void 0:l(`archives.permission.noUpdateArchives`)}]:[],{label:e.f3d_path?l(`archives.menu.replaceF3d`):l(`archives.menu.uploadF3d`),icon:(0,K.jsx)(Wo,{className:`w-4 h-4`}),onClick:()=>le.current?.click(),disabled:!m(`archives`,`update`,e.created_by_id),title:m(`archives`,`update`,e.created_by_id)?void 0:l(`archives.permission.noUpdateArchives`)},...e.f3d_path?[{label:l(`archives.menu.downloadF3d`),icon:(0,K.jsx)(Vs,{className:`w-4 h-4`}),onClick:()=>{Q.downloadF3d(e.id).catch(e=>{console.error(`F3D download failed:`,e)})}},{label:l(`archives.menu.removeF3d`),icon:(0,K.jsx)(Cu,{className:`w-4 h-4`}),onClick:()=>H(!0),danger:!0,disabled:!m(`archives`,`update`,e.created_by_id),title:m(`archives`,`update`,e.created_by_id)?void 0:l(`archives.permission.noUpdateArchives`)}]:[],{label:``,divider:!0,onClick:()=>{}},{label:l(`archives.menu.download`),icon:(0,K.jsx)(Vs,{className:`w-4 h-4`}),onClick:()=>{Q.downloadArchive(e.id,`${e.print_name||e.filename}.3mf`).catch(e=>{console.error(`Archive download failed:`,e)})},disabled:!p(`archives:read`),title:p(`archives:read`)?void 0:l(`archives.permission.noDownload`)},{label:l(`archives.menu.copyDownloadLink`),icon:(0,K.jsx)(Ms,{className:`w-4 h-4`}),onClick:()=>{let t=`${window.location.origin}${Q.getArchiveDownload(e.id)}`;navigator.clipboard.writeText(t).then(()=>{f(l(`archives.toast.linkCopied`))}).catch(()=>{f(l(`archives.toast.failedCopyLink`),`error`)})},disabled:!p(`archives:read`),title:p(`archives:read`)?void 0:l(`archives.permission.noCopyLink`)},{label:l(`archives.menu.qrCode`),icon:(0,K.jsx)(kl,{className:`w-4 h-4`}),onClick:()=>z(!0)},{label:e.photos?.length?l(`archives.menu.viewPhotosCount`,{count:e.photos.length}):l(`archives.menu.viewPhotos`),icon:(0,K.jsx)(Zo,{className:`w-4 h-4`}),onClick:()=>V(!0),disabled:!e.photos?.length},{label:l(`archives.menu.projectPage`),icon:(0,K.jsx)(nc,{className:`w-4 h-4`}),onClick:()=>te(!0)},{label:``,divider:!0,onClick:()=>{}},{label:e.is_favorite?l(`archives.menu.removeFromFavorites`):l(`archives.menu.addToFavorites`),icon:(0,K.jsx)(uu,{className:`w-4 h-4 ${e.is_favorite?`fill-yellow-400 text-yellow-400`:``}`}),onClick:()=>Te.mutate(),disabled:!m(`archives`,`update`,e.created_by_id),title:m(`archives`,`update`,e.created_by_id)?void 0:l(`archives.permission.noUpdateArchives`)},{label:l(`archives.menu.edit`),icon:(0,K.jsx)(xl,{className:`w-4 h-4`}),onClick:()=>g(!0),disabled:!m(`archives`,`update`,e.created_by_id),title:m(`archives`,`update`,e.created_by_id)?void 0:l(`archives.permission.noUpdateArchives`)},{label:l(`archives.menu.printLog`),icon:(0,K.jsx)(kc,{className:`w-4 h-4`}),onClick:()=>v(!0)},...e.project_id&&e.project_name?[{label:l(`archives.menu.goToProject`,{name:e.project_name}),icon:(0,K.jsx)(sc,{className:`w-4 h-4 text-bambu-green`}),onClick:()=>window.location.href=`/projects`}]:[],{label:l(`archives.menu.addToProject`),icon:(0,K.jsx)(sc,{className:`w-4 h-4`}),onClick:()=>{},submenuSearchPlaceholder:(a?.filter(e=>e.status===`active`).length??0)>5?l(`archives.menu.searchProjects`):void 0,submenu:(()=>{let t=[];if(e.project_id&&t.push({label:l(`archives.menu.removeFromProject`),icon:(0,K.jsx)(Wu,{className:`w-4 h-4`}),onClick:()=>De.mutate(null)}),!a)t.push({label:l(`archives.menu.loading`),icon:(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),onClick:()=>{},disabled:!0});else{let n=a.filter(e=>e.status===`active`).sort((e,t)=>e.name.localeCompare(t.name));n.length===0?t.push({label:l(`archives.menu.noProjectsAvailable`),icon:(0,K.jsx)(sc,{className:`w-4 h-4 opacity-50`}),onClick:()=>{},disabled:!0}):n.forEach(n=>{t.push({label:n.name,icon:(0,K.jsx)(`div`,{className:`w-3 h-3 rounded-full flex-shrink-0`,style:{backgroundColor:n.color||`#888`}}),onClick:()=>De.mutate(n.id),disabled:e.project_id===n.id})})}return t})()},{label:l(n?`archives.menu.deselect`:`archives.menu.select`),icon:n?(0,K.jsx)(su,{className:`w-4 h-4`}):(0,K.jsx)(lu,{className:`w-4 h-4`}),onClick:()=>r(e.id)},{label:``,divider:!0,onClick:()=>{}},{label:l(`archives.menu.delete`),icon:(0,K.jsx)(Cu,{className:`w-4 h-4`}),onClick:()=>x(!0),danger:!0,disabled:!m(`archives`,`delete`,e.created_by_id),title:m(`archives`,`delete`,e.created_by_id)?void 0:l(`archives.permission.noDelete`)}];return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{"data-archive-id":e.id,className:`grid grid-cols-12 gap-4 px-4 py-3 items-center hover:bg-bambu-dark-tertiary/30 ${n?`bg-bambu-green/10`:``}`,style:o?{outline:`4px solid #facc15`,outlineOffset:`-4px`}:void 0,onContextMenu:Oe,children:[(0,K.jsxs)(`div`,{className:`col-span-1 flex items-center gap-2`,children:[i&&(0,K.jsx)(`button`,{onClick:()=>r(e.id),children:n?(0,K.jsx)(su,{className:`w-4 h-4 text-bambu-green`}):(0,K.jsx)(lu,{className:`w-4 h-4 text-bambu-gray`})}),e.thumbnail_path?(0,K.jsx)(`img`,{src:Q.getArchiveThumbnail(e.id),alt:``,className:`w-10 h-10 object-cover rounded`}):(0,K.jsx)(`div`,{className:`w-10 h-10 bg-bambu-dark rounded flex items-center justify-center`,children:(0,K.jsx)(Mc,{className:`w-5 h-5 text-bambu-dark-tertiary`})})]}),(0,K.jsxs)(`div`,{className:`col-span-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`p`,{className:`text-white text-sm truncate`,children:e.print_name||e.filename}),(e.status===`failed`||e.status===`aborted`)&&(0,K.jsx)(`span`,{className:`px-1.5 py-0.5 rounded text-[10px] leading-tight bg-status-error/80 text-white flex-shrink-0`,children:e.status===`aborted`?l(`archives.card.cancelled`):l(`archives.card.failed`)}),e.duplicate_count>0&&pe>0&&me&&(0,K.jsxs)(`button`,{onClick:e=>{e.stopPropagation(),u?.(me)},className:`px-1.5 py-0.5 rounded text-[10px] leading-tight bg-purple-500/80 hover:bg-purple-600/90 text-white flex-shrink-0 transition-colors flex items-center gap-1`,title:l(`archives.viewOriginalPrint`,{id:me}),children:[(0,K.jsx)(Ms,{className:`w-3 h-3`}),`#`,pe]}),e.duplicate_count>0&&pe===0&&(0,K.jsxs)(`span`,{className:`px-1.5 py-0.5 rounded text-[10px] leading-tight bg-purple-500/80 text-white flex-shrink-0 flex items-center gap-1`,title:`${e.duplicate_count} reprint${e.duplicate_count===1?``:`s`}`,children:[(0,K.jsx)(_c,{className:`w-3 h-3`}),`+`,e.duplicate_count]}),e.timelapse_path&&(0,K.jsx)(`span`,{title:l(`archives.list.hasTimelapse`),children:(0,K.jsx)(ic,{className:`w-3.5 h-3.5 text-bambu-green flex-shrink-0`})}),Ee&&Ee.length>0&&(0,K.jsx)(wi,{to:`/files?folder=${Ee[0].id}`,className:`flex-shrink-0`,title:l(`archives.card.openFolder`,{name:Ee[0].name}),onClick:e=>e.stopPropagation(),children:(0,K.jsx)(cc,{className:`w-3.5 h-3.5 text-yellow-600 dark:text-yellow-400`})})]}),(e.filament_type||e.sliced_for_model)&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 mt-0.5`,children:[e.sliced_for_model&&(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray flex items-center gap-1`,title:l(`archives.card.slicedFor`,{model:e.sliced_for_model}),children:[(0,K.jsx)(Ol,{className:`w-2.5 h-2.5`}),e.sliced_for_model]}),(()=>{let t=iW(e.bed_type);return t?(0,K.jsx)(`img`,{src:t.icon,alt:t.label,title:t.label,className:`w-3.5 h-3.5 flex-shrink-0`}):null})(),e.sliced_for_model&&e.filament_type&&(0,K.jsx)(`span`,{className:`text-bambu-gray/50`,children:`·`}),e.filament_type&&(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:e.filament_type}),e.filament_color&&(0,K.jsx)(`div`,{className:`flex items-center gap-0.5 flex-wrap`,children:e.filament_color.split(`,`).map((e,t)=>(0,K.jsx)(`div`,{className:`w-2.5 h-2.5 rounded-full border border-black/20`,style:{backgroundColor:e},title:e},t))})]})]}),(0,K.jsx)(`div`,{className:`col-span-2 text-sm text-bambu-gray truncate`,children:t}),(0,K.jsxs)(`div`,{className:`col-span-2 text-sm text-bambu-gray`,children:[(0,K.jsx)(`div`,{children:jf(e.created_at)}),e.created_by_username&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1 text-xs opacity-75`,title:l(`archives.card.uploadedBy`,{name:e.created_by_username}),children:[(0,K.jsx)(ju,{className:`w-3 h-3`}),e.created_by_username]})]}),(0,K.jsx)(`div`,{className:`col-span-1 text-sm text-bambu-gray`,children:kd(e.file_size)}),(0,K.jsxs)(`div`,{className:`col-span-2 flex justify-end gap-1`,children:[a2(e)&&(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:()=>D(!0),disabled:!e.file_path||!p(`queue:create`)||!m(`archives`,`reprint`,e.created_by_id),title:e.file_path?p(`queue:create`)?m(`archives`,`reprint`,e.created_by_id)?l(`common.print`):l(`archives.card.noPermissionReprint`):l(`archives.permission.noAddToQueue`):l(`archives.card.noFileForReprint`),className:`text-bambu-green hover:text-bambu-green-light hover:bg-bambu-green/10`,children:(0,K.jsx)(Cl,{className:`w-4 h-4`})}),(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:()=>{let t=e.print_name||e.filename||`model`;o2(e.id,t,`file`,s)},title:l(`archives.card.openInBambuStudio`),children:(0,K.jsx)(Js,{className:`w-4 h-4`})}),(e.external_url||e.makerworld_url)&&(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:()=>window.open(e.external_url||e.makerworld_url,`_blank`),title:e.external_url?l(`archives.card.externalLink`):`MakerWorld`,children:(0,K.jsx)(bc,{className:`w-4 h-4`})}),(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:()=>{Q.downloadArchive(e.id,`${e.print_name||e.filename}.3mf`).catch(e=>{console.error(`Archive download failed:`,e)})},title:l(`archives.card.download`),children:(0,K.jsx)(Vs,{className:`w-4 h-4`})}),(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:()=>g(!0),disabled:!m(`archives`,`update`,e.created_by_id),title:m(`archives`,`update`,e.created_by_id)?l(`archives.card.edit`):l(`archives.card.noPermissionEdit`),children:(0,K.jsx)(xl,{className:`w-4 h-4`})}),(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:()=>x(!0),disabled:!m(`archives`,`delete`,e.created_by_id),title:m(`archives`,`delete`,e.created_by_id)?l(`archives.card.delete`):l(`archives.card.noPermissionDelete`),children:(0,K.jsx)(Cu,{className:`w-4 h-4 text-red-600 dark:text-red-400`})}),(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:e=>{let t=e.currentTarget.getBoundingClientRect();se({x:t.left,y:t.bottom+4})},title:l(`archives.card.moreOptions`),children:(0,K.jsx)(Ws,{className:`w-4 h-4`})})]})]}),h&&(0,K.jsx)($W,{archive:e,onClose:()=>g(!1)}),_&&(0,K.jsx)(eG,{archiveId:e.id,archiveName:e.print_name||e.filename,onClose:()=>v(!1)}),de&&(0,K.jsx)(RW,{plates:de,onSelect:t=>{fe(null),T(`/gcode-viewer?archive=${e.id}&plate=${t}`)},onClose:()=>fe(null)}),E&&(0,K.jsx)(uW,{mode:`create`,archiveId:e.id,archiveName:e.print_name||e.filename,onClose:()=>D(!1)}),O&&(0,K.jsx)(UW,{source:{kind:`archive`,id:e.id,filename:e.print_name||e.filename||`model`},onClose:()=>k(!1)}),A&&(0,K.jsx)(KW,{source:{kind:`archive`,id:e.id,filename:e.print_name||e.filename||`model`},onClose:()=>j(!1)}),b&&(0,K.jsxs)(Bd,{title:l(`archives.modal.deleteArchive`),message:l(`archives.modal.deleteConfirm`,{name:e.print_name||e.filename}),confirmText:l(`archives.modal.deleteButton`),variant:`danger`,confirmDisabled:(w.data?.currently_printing??0)>0,onConfirm:()=>{we.mutate(S),x(!1),C(!1)},onCancel:()=>{x(!1),C(!1)},children:[(w.data?.related_queue_items??0)>0&&(0,K.jsx)(`div`,{className:(w.data?.currently_printing??0)>0?`text-sm text-red-600 dark:text-red-400 mb-2`:`text-sm text-amber-600 dark:text-amber-400 mb-2`,children:(w.data?.currently_printing??0)>0?l(`archives.modal.deleteBlockedByPrinting`,{count:w.data.currently_printing}):l(`archives.modal.deleteQueueItemsWarning`,{count:w.data.related_queue_items})}),(0,K.jsxs)(`label`,{className:`flex items-start gap-2 cursor-pointer text-sm text-bambu-gray`,children:[(0,K.jsx)(`input`,{type:`checkbox`,className:`mt-0.5 accent-red-500`,checked:S,onChange:e=>C(e.target.checked)}),(0,K.jsx)(`span`,{children:l(`archives.modal.deletePurgeStats`)})]})]}),ne&&(0,K.jsx)(Bd,{title:l(`archives.modal.removeSource3mf`),message:l(`archives.modal.removeSource3mfConfirm`,{name:e.print_name||e.filename}),confirmText:l(`archives.modal.removeButton`),variant:`danger`,onConfirm:()=>{ye.mutate(),re(!1)},onCancel:()=>re(!1)}),ie&&(0,K.jsx)(Bd,{title:l(`archives.modal.removeF3d`),message:l(`archives.modal.removeF3dConfirm`,{name:e.print_name||e.filename}),confirmText:l(`archives.modal.removeButton`),variant:`danger`,onConfirm:()=>{xe.mutate(),H(!1)},onCancel:()=>H(!1)}),ae&&(0,K.jsx)(Bd,{title:l(`archives.modal.removeTimelapse`),message:l(`archives.modal.removeTimelapseConfirm`,{name:e.print_name||e.filename}),confirmText:l(`archives.modal.removeButton`),variant:`danger`,onConfirm:()=>{ge.mutate(),oe(!1)},onCancel:()=>oe(!1)}),U&&(0,K.jsx)(tG,{x:U.x,y:U.y,items:ke,onClose:()=>se(null)}),M&&e.timelapse_path&&(0,K.jsx)(i2,{src:Q.getArchiveTimelapse(e.id),title:l(`archives.modal.timelapse`,{name:e.print_name||e.filename}),downloadFilename:`${e.print_name||e.filename}_timelapse.mp4`,archiveId:e.id,onClose:()=>N(!1),onEdit:()=>{d.invalidateQueries({queryKey:[`archives`]}),N(!1)}}),P&&I.length>0&&(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/80 flex items-center justify-center z-50 p-4`,children:(0,K.jsxs)(`div`,{className:`bg-card-dark rounded-lg max-w-lg w-full max-h-[80vh] flex flex-col`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-gray-700`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h3`,{className:`text-lg font-semibold text-white`,children:l(`archives.modal.selectTimelapse`)}),(0,K.jsx)(`p`,{className:`text-sm text-gray-400 mt-1`,children:l(`archives.modal.selectTimelapseDesc`)})]}),(0,K.jsx)(`button`,{onClick:()=>{F(!1),L([])},className:`text-gray-400 hover:text-white p-1`,children:(0,K.jsx)(Wu,{className:`w-5 h-5`})})]}),(0,K.jsx)(`div`,{className:`overflow-y-auto flex-1 p-2`,children:I.map(e=>(0,K.jsxs)(`button`,{onClick:()=>Ce.mutate(e.name),disabled:Ce.isPending,className:`w-full text-left p-3 rounded-lg hover:bg-gray-700 transition-colors mb-1`,children:[(0,K.jsx)(`div`,{className:`font-medium text-white`,children:e.name}),(0,K.jsxs)(`div`,{className:`text-sm text-gray-400 flex gap-3`,children:[(0,K.jsx)(`span`,{children:kd(e.size)}),e.mtime&&(0,K.jsx)(`span`,{children:jf(e.mtime)})]})]},e.name))})]})}),R&&(0,K.jsx)(nG,{archiveId:e.id,archiveName:e.print_name||e.filename,onClose:()=>z(!1)}),B&&e.photos&&(0,K.jsx)(rG,{archiveId:e.id,archiveName:e.print_name||e.filename,photos:e.photos,onClose:()=>V(!1),onDelete:async t=>{try{await Q.deleteArchivePhoto(e.id,t),d.invalidateQueries({queryKey:[`archives`]}),f(l(`archives.toast.photoDeleted`))}catch{f(l(`archives.toast.failedDeletePhoto`),`error`)}}}),ee&&(0,K.jsx)(r2,{archiveId:e.id,archiveName:e.print_name||e.filename,onClose:()=>te(!1)}),(0,K.jsx)(`input`,{ref:ce,type:`file`,accept:`.3mf`,className:`hidden`,onChange:e=>{let t=e.target.files?.[0];t&&ve.mutate(t),e.target.value=``}}),(0,K.jsx)(`input`,{ref:le,type:`file`,accept:`.f3d`,className:`hidden`,onChange:e=>{let t=e.target.files?.[0];t&&be.mutate(t),e.target.value=``}}),(0,K.jsx)(`input`,{ref:ue,type:`file`,accept:`.mp4,.avi,.mkv`,className:`hidden`,onChange:e=>{let t=e.target.files?.[0];t&&_e.mutate(t),e.target.value=``}})]})}var Aze=[`completed`,`failed`,`aborted`,`cancelled`,`stopped`],jze=[{id:`all`,label:`All Archives`,icon:(0,K.jsx)(cc,{className:`w-4 h-4`})},{id:`recent`,label:`Last 24 Hours`,icon:(0,K.jsx)(xs,{className:`w-4 h-4`})},{id:`this-week`,label:`This Week`,icon:(0,K.jsx)(Xo,{className:`w-4 h-4`})},{id:`this-month`,label:`This Month`,icon:(0,K.jsx)(Xo,{className:`w-4 h-4`})},{id:`favorites`,label:`Favorites`,icon:(0,K.jsx)(uu,{className:`w-4 h-4`})},{id:`not-printed`,label:`Not Printed`,icon:(0,K.jsx)(Au,{className:`w-4 h-4`})},{id:`printed`,label:`Printed`,icon:(0,K.jsx)(Ol,{className:`w-4 h-4`})},{id:`failed`,label:`Failed Prints`,icon:(0,K.jsx)(us,{className:`w-4 h-4`})},{id:`duplicates`,label:`Duplicates`,icon:(0,K.jsx)(Ms,{className:`w-4 h-4`})}];function Mze(){let{t:e}=W(),t=no(),{showToast:n}=jd(),{hasPermission:r,hasAnyPermission:i}=_d(),a=(0,y.useRef)(null),[o,s]=(0,y.useState)(``),[c,l]=(0,y.useState)(()=>{let e=localStorage.getItem(`archiveFilterPrinter`);return e?Number(e):null}),[u,d]=(0,y.useState)(()=>localStorage.getItem(`archiveFilterMaterial`)),[f,p]=(0,y.useState)(()=>{let e=localStorage.getItem(`archiveFilterColors`);return e?new Set(JSON.parse(e)):new Set}),[m,h]=(0,y.useState)(()=>localStorage.getItem(`archiveColorFilterMode`)||`or`),[g,_]=(0,y.useState)(()=>localStorage.getItem(`archiveFilterFavorites`)===`true`),[v,b]=(0,y.useState)(()=>localStorage.getItem(`archiveHideFailed`)===`true`),[x,S]=(0,y.useState)(()=>localStorage.getItem(`archiveHideDuplicates`)===`true`),[C,w]=(0,y.useState)(()=>localStorage.getItem(`archiveFilterTag`)),[T,E]=(0,y.useState)(()=>localStorage.getItem(`archiveFilterFileType`)||`all`),[D,O]=(0,y.useState)(!1),[k,A]=(0,y.useState)([]),[j,M]=(0,y.useState)(new Set),[N,P]=(0,y.useState)(()=>localStorage.getItem(`archiveNo3MFWarningDismissed`)===`true`),{data:F}=q({queryKey:[`archives`,`no-3mf-warning`],queryFn:Q.getNo3MFWarning,staleTime:300*1e3,enabled:!N}),I=()=>{localStorage.setItem(`archiveNo3MFWarningDismissed`,`true`),P(!0)},[L,R]=(0,y.useState)(!1),[z,B]=(0,y.useState)(!1),[V,ee]=(0,y.useState)(!1),[te,ne]=(0,y.useState)(!1),[re,ie]=(0,y.useState)(()=>localStorage.getItem(`archiveViewMode`)||`grid`),[H,ae]=(0,y.useState)(()=>localStorage.getItem(`archiveSortBy`)||`date-desc`),[oe,U]=(0,y.useState)(()=>localStorage.getItem(`archiveCollection`)||`all`),[se,ce]=(0,y.useState)(0),[le,ue]=(0,y.useState)(()=>{try{let e=localStorage.getItem(`archivePageSize`);return e?Number(e):50}catch{return 50}}),[de,fe]=(0,y.useState)(!1),[pe,me]=(0,y.useState)(!1),[he,ge]=(0,y.useState)(!1),[_e,ve]=(0,y.useState)(!1),[ye,be]=(0,y.useState)(!1),[xe,Se]=(0,y.useState)(null),[Ce,we]=(0,y.useState)(null),[Te,Ee]=(0,y.useState)(()=>localStorage.getItem(`logFilterUser`)||null),[De,Oe]=(0,y.useState)(()=>localStorage.getItem(`logFilterStatus`)),[ke,Ae]=(0,y.useState)(()=>localStorage.getItem(`logFilterDateFrom`)||``),[je,Me]=(0,y.useState)(()=>localStorage.getItem(`logFilterDateTo`)||``),[Ne,Pe]=(0,y.useState)(()=>{let e=localStorage.getItem(`logOffset`);return e?Number(e):0}),[Fe,Ie]=(0,y.useState)(!1),[Le,Re]=(0,y.useState)(null),[ze,Be]=(0,y.useState)(null),[Ve,He]=(0,y.useState)(``),[Ue,We]=(0,y.useState)(``),[Ge,Ke]=(0,y.useState)(()=>{let e=localStorage.getItem(`logPageSize`);return e?Number(e):25}),qe=(0,y.useCallback)(e=>{we(e),Se(e)},[]);(0,y.useEffect)(()=>{if(xe){let t=setTimeout(()=>{let t=document.querySelector(`[data-archive-id="${xe}"]`);t?t.scrollIntoView({behavior:`smooth`,block:`center`}):Ce===xe&&n(e(`archives.originalPrintNotVisible`),`warning`),Ce===xe&&we(null)},100),r=setTimeout(()=>Se(null),5e3);return()=>{clearTimeout(t),clearTimeout(r)}}},[xe,Ce,n,e]);let{data:Je,isLoading:Ye}=q({queryKey:[`archives`,c],queryFn:()=>Q.getArchives(c||void 0)}),{data:Xe}=q({queryKey:[`printers`],queryFn:Q.getPrinters}),{data:Ze}=q({queryKey:[`projects`],queryFn:()=>Q.getProjects()}),{data:Qe}=q({queryKey:[`settings`],queryFn:Q.getSettings}),{data:$e}=q({queryKey:[`users`],queryFn:Q.getUsers,enabled:re===`log`}),{data:et,isLoading:tt}=q({queryKey:[`print-log`,c,Te,De,ke,je,o,Ne,Ge],queryFn:()=>Q.getPrintLog({search:o||void 0,printerId:c||void 0,username:Te||void 0,status:De||void 0,dateFrom:ke||void 0,dateTo:je||void 0,limit:Ge,offset:Ne}),enabled:re===`log`}),nt=Qe?.time_format||`system`,rt=Qe?.open_in_slicer||Qe?.preferred_slicer||`bambu_studio`,it=Qe?.use_slicer_api??!1,at=uf(Qe?.currency||`USD`),ot=J({mutationFn:async e=>(await Promise.all(e.map(e=>Q.deleteArchive(e))),e.length),onSuccess:e=>{t.invalidateQueries({queryKey:[`archives`]}),M(new Set),n(`${e} archive${e===1?``:`s`} deleted`)},onError:()=>{n(e(`archives.toast.failedDeleteArchives`),`error`)}}),st=J({mutationFn:()=>Q.clearPrintLog(),onSuccess:r=>{t.invalidateQueries({queryKey:[`print-log`]}),Pe(0),n(e(`archives.log.cleared`,{count:r.deleted}))},onError:()=>{n(e(`archives.log.clearFailed`),`error`)}}),ct=J({mutationFn:e=>Q.deletePrintLogEntry(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`print-log`]}),t.invalidateQueries({queryKey:[`archives-stats`]}),n(e(`archives.log.entryDeleted`))},onError:()=>{n(e(`archives.log.entryDeleteFailed`),`error`)}}),lt=J({mutationFn:({id:e,body:t})=>Q.updatePrintLogEntry(e,t),onSuccess:()=>{t.invalidateQueries({queryKey:[`print-log`]}),t.invalidateQueries({queryKey:[`archives-stats`]}),Be(null),n(e(`archives.log.entryUpdated`))},onError:()=>{n(e(`archives.log.entryUpdateFailed`),`error`)}});(0,y.useEffect)(()=>{c===null?localStorage.removeItem(`archiveFilterPrinter`):localStorage.setItem(`archiveFilterPrinter`,c.toString())},[c]),(0,y.useEffect)(()=>{u?localStorage.setItem(`archiveFilterMaterial`,u):localStorage.removeItem(`archiveFilterMaterial`)},[u]),(0,y.useEffect)(()=>{localStorage.setItem(`archiveFilterColors`,JSON.stringify([...f]))},[f]),(0,y.useEffect)(()=>{localStorage.setItem(`archiveColorFilterMode`,m)},[m]),(0,y.useEffect)(()=>{localStorage.setItem(`archiveFilterFavorites`,g.toString())},[g]),(0,y.useEffect)(()=>{localStorage.setItem(`archiveHideFailed`,v.toString())},[v]),(0,y.useEffect)(()=>{localStorage.setItem(`archiveHideDuplicates`,x.toString())},[x]),(0,y.useEffect)(()=>{C?localStorage.setItem(`archiveFilterTag`,C):localStorage.removeItem(`archiveFilterTag`)},[C]),(0,y.useEffect)(()=>{localStorage.setItem(`archiveFilterFileType`,T)},[T]),(0,y.useEffect)(()=>{ce(0)},[o,c,u,f,m,g,v,x,C,T,H,oe]),(0,y.useEffect)(()=>{try{localStorage.setItem(`archivePageSize`,String(le))}catch{}},[le]),(0,y.useEffect)(()=>{localStorage.setItem(`archiveViewMode`,re)},[re]),(0,y.useEffect)(()=>{localStorage.setItem(`archiveSortBy`,H)},[H]),(0,y.useEffect)(()=>{localStorage.setItem(`archiveCollection`,oe)},[oe]),(0,y.useEffect)(()=>{Te?localStorage.setItem(`logFilterUser`,Te):localStorage.removeItem(`logFilterUser`)},[Te]),(0,y.useEffect)(()=>{De?localStorage.setItem(`logFilterStatus`,De):localStorage.removeItem(`logFilterStatus`)},[De]),(0,y.useEffect)(()=>{ke?localStorage.setItem(`logFilterDateFrom`,ke):localStorage.removeItem(`logFilterDateFrom`)},[ke]),(0,y.useEffect)(()=>{je?localStorage.setItem(`logFilterDateTo`,je):localStorage.removeItem(`logFilterDateTo`)},[je]),(0,y.useEffect)(()=>{localStorage.setItem(`logOffset`,Ne.toString())},[Ne]),(0,y.useEffect)(()=>{localStorage.setItem(`logPageSize`,Ge.toString())},[Ge]);let ut=new Map(Xe?.map(e=>[e.id,e.name])||[]),dt=[...new Set(Je?.flatMap(e=>e.filament_type?.split(`, `)||[]).filter(Boolean)||[])].sort(),ft=[...new Set(Je?.flatMap(e=>e.filament_color?.split(`,`)||[]).filter(Boolean)||[])],pt=[...new Set(Je?.flatMap(e=>e.tags?.split(`,`).map(e=>e.trim())||[]).filter(Boolean)||[])].sort(),mt=Je?.filter(e=>{let t=new Date,n=Af(e.created_at)||new Date(0),r=!0;switch(oe){case`recent`:r=t.getTime()-n.getTime()<1440*60*1e3;break;case`this-week`:r=t.getTime()-n.getTime()<10080*60*1e3;break;case`this-month`:r=n.getMonth()===t.getMonth()&&n.getFullYear()===t.getFullYear();break;case`favorites`:r=e.is_favorite===!0;break;case`not-printed`:r=e.status===`archived`;break;case`printed`:r=Aze.includes(e.status);break;case`failed`:r=e.status===`failed`||e.status===`aborted`;break;case`duplicates`:r=e.duplicate_count>0;break}let i=(e.print_name||e.filename).toLowerCase().includes(o.toLowerCase()),a=!u||e.filament_type?.split(`, `).includes(u),s=e.filament_color?.split(`,`)||[],c=f.size===0||(m===`or`?s.some(e=>f.has(e)):[...f].every(e=>s.includes(e))),l=oe===`favorites`||!g||e.is_favorite,d=oe===`failed`||!v||e.status!==`failed`&&e.status!==`aborted`,p=oe===`duplicates`||!x||e.duplicate_count===0||e.duplicate_sequence===0,h=e.tags?.split(`,`).map(e=>e.trim())||[],_=!C||h.includes(C),y=a2(e);return r&&i&&a&&c&&l&&d&&p&&_&&(T===`all`||T===`gcode`&&y||T===`source`&&!y)}).sort((e,t)=>{switch(H){case`date-desc`:return(Af(t.created_at)?.getTime()||0)-(Af(e.created_at)?.getTime()||0);case`date-asc`:return(Af(e.created_at)?.getTime()||0)-(Af(t.created_at)?.getTime()||0);case`name-asc`:return(e.print_name||e.filename).localeCompare(t.print_name||t.filename);case`name-desc`:return(t.print_name||t.filename).localeCompare(e.print_name||e.filename);case`size-desc`:return t.file_size-e.file_size;case`size-asc`:return e.file_size-t.file_size;default:return 0}}),ht=mt?.length||0,gt=le===-1,_t=gt?ht||1:le,vt=Math.max(1,Math.ceil(ht/_t)),yt=gt?mt:mt?.slice(se*_t,(se+1)*_t);(0,y.useEffect)(()=>{if(xe&&mt&&!gt){let e=mt.findIndex(e=>e.id===xe);if(e>=0){let t=Math.floor(e/_t);t!==se&&ce(t)}}},[xe]);let bt=L||j.size>0,xt=e=>{M(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},St=()=>{mt&&M(new Set(mt.map(e=>e.id)))},Ct=()=>{M(new Set),R(!1)},wt=e=>{p(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},Tt=()=>{p(new Set)},Et=()=>{s(``),l(null),d(null),_(!1),b(!1),S(!1),w(null),E(`all`)},Dt=o||c||u||g||v||x||C||T!==`all`,{isDraggingOver:Ot,dragHandlers:kt}=XW({disabled:D,extensions:[`.3mf`],onFiles:e=>{A(e),O(!0)},onRejected:()=>n(e(`archives.page.only3mfSupported`),`warning`)}),At=(0,y.useCallback)(e=>{let t=e.target;if(t.tagName===`INPUT`||t.tagName===`TEXTAREA`||t.isContentEditable){e.key===`Escape`&&t.blur();return}switch(e.key){case`/`:e.preventDefault(),a.current?.focus();break;case`u`:case`U`:!e.metaKey&&!e.ctrlKey&&(e.preventDefault(),O(!0));break;case`Escape`:bt&&Ct();break}},[bt]);return(0,y.useEffect)(()=>(document.addEventListener(`keydown`,At),()=>document.removeEventListener(`keydown`,At)),[At]),(0,K.jsxs)(`div`,{className:`p-4 md:p-8 relative`,...kt,children:[Ot&&(0,K.jsx)(`div`,{className:`fixed inset-0 z-50 bg-bambu-dark/90 flex items-center justify-center pointer-events-none`,children:(0,K.jsxs)(`div`,{className:`border-4 border-dashed border-bambu-green rounded-xl p-12 text-center`,children:[(0,K.jsx)(Au,{className:`w-16 h-16 mx-auto mb-4 text-bambu-green`}),(0,K.jsx)(`p`,{className:`text-2xl font-semibold text-white mb-2`,children:e(`archives.page.dropFilesHere`)}),(0,K.jsx)(`p`,{className:`text-bambu-gray`,children:e(`archives.releaseToUpload`)})]})}),bt&&(0,K.jsxs)(`div`,{className:`fixed bottom-6 left-1/2 -translate-x-1/2 z-40 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl px-4 py-3 flex items-center gap-4`,children:[(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:Ct,children:[(0,K.jsx)(Wu,{className:`w-4 h-4`}),`Close`]}),(0,K.jsx)(`div`,{className:`w-px h-6 bg-bambu-dark-tertiary`}),(0,K.jsxs)(`span`,{className:`text-white font-medium`,children:[j.size,` selected`]}),(0,K.jsx)(`div`,{className:`w-px h-6 bg-bambu-dark-tertiary`}),(0,K.jsx)($,{variant:`secondary`,size:`sm`,onClick:St,children:`Select All`}),(0,K.jsx)(`div`,{className:`w-px h-6 bg-bambu-dark-tertiary`}),(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:()=>ee(!0),disabled:!i(`archives:update_own`,`archives:update_all`),title:i(`archives:update_own`,`archives:update_all`)?void 0:e(`archives.permission.noUpdateArchives`),children:[(0,K.jsx)(hu,{className:`w-4 h-4`}),`Tags`]}),(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:()=>ne(!0),disabled:!i(`archives:update_own`,`archives:update_all`),title:i(`archives:update_own`,`archives:update_all`)?void 0:e(`archives.permission.noUpdateArchives`),children:[(0,K.jsx)(sc,{className:`w-4 h-4`}),`Project`]}),(0,K.jsxs)($,{variant:`secondary`,size:`sm`,disabled:!i(`archives:update_own`,`archives:update_all`),title:i(`archives:update_own`,`archives:update_all`)?void 0:e(`archives.permission.noUpdateArchives`),onClick:()=>{let r=Array.from(j);Promise.all(r.map(e=>Q.toggleFavorite(e))).then(()=>{t.invalidateQueries({queryKey:[`archives`]}),n(`Toggled favorites for ${r.length} archive${r.length===1?``:`s`}`)}).catch(()=>{n(e(`archives.toast.failedUpdateFavorites`),`error`)})},children:[(0,K.jsx)(uu,{className:`w-4 h-4`}),`Favorite`]}),(0,K.jsxs)($,{size:`sm`,className:`bg-red-500 hover:bg-red-600`,onClick:()=>B(!0),disabled:!i(`archives:delete_own`,`archives:delete_all`),title:i(`archives:delete_own`,`archives:delete_all`)?void 0:e(`archives.permission.noDelete`),children:[(0,K.jsx)(Cu,{className:`w-4 h-4`}),`Delete`]})]}),F?.has_fallback&&!N&&(0,K.jsxs)(`div`,{className:`mb-6 rounded-lg border border-amber-300 dark:border-amber-500/30 bg-amber-50 dark:bg-amber-500/10 px-4 py-3 flex items-start gap-3`,children:[(0,K.jsx)(us,{className:`w-5 h-5 text-amber-600 dark:text-amber-400 flex-shrink-0 mt-0.5`}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsx)(`div`,{className:`text-sm font-medium text-amber-900 dark:text-amber-200`,children:e(`archives.no3mfBanner.title`)}),(0,K.jsxs)(`div`,{className:`text-xs text-amber-800/90 dark:text-amber-200/80 mt-1`,children:[e(`archives.no3mfBanner.body`),` `,(0,K.jsxs)(`a`,{href:`https://wiki.bambuddy.cool/getting-started/#step-4-enable-store-sent-files-on-external-storage`,target:`_blank`,rel:`noreferrer`,className:`underline hover:text-amber-900 dark:hover:text-amber-100 inline-flex items-center gap-1`,children:[e(`archives.no3mfBanner.docsLink`),(0,K.jsx)(Js,{className:`w-3 h-3`})]})]})]}),(0,K.jsx)(`button`,{onClick:I,className:`text-amber-800/70 dark:text-amber-200/60 hover:text-amber-900 dark:hover:text-amber-200 flex-shrink-0 p-1 -m-1`,title:e(`archives.no3mfBanner.dismissLabel`),"aria-label":e(`archives.no3mfBanner.dismissLabel`),children:(0,K.jsx)(Wu,{className:`w-4 h-4`})})]}),(0,K.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4 mb-8`,children:[(0,K.jsx)(`div`,{children:(0,K.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,K.jsx)(Oo,{className:`w-7 h-7 text-bambu-green`}),`Archives`]}),(0,K.jsxs)(`p`,{className:`text-bambu-gray mt-1`,children:[mt?.length||0,` of `,Je?.length||0,` prints`]})]}),(0,K.jsx)(`select`,{className:`mt-0.5 px-3 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray-light text-sm focus:border-bambu-green focus:outline-none`,value:oe,onChange:e=>U(e.target.value),children:jze.map(e=>(0,K.jsx)(`option`,{value:e.id,children:e.label},e.id))})]})}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 sm:gap-3 flex-wrap`,children:[(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsxs)($,{variant:`secondary`,onClick:()=>fe(!de),disabled:pe,children:[pe?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(tc,{className:`w-4 h-4`}),`Export`]}),de&&(0,K.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,K.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:async()=>{fe(!1),me(!0);try{let{blob:t,filename:r}=await Q.exportArchives({format:`csv`,printerId:c||void 0,status:oe===`failed`?`failed`:void 0,search:o||void 0}),i=URL.createObjectURL(t),a=document.createElement(`a`);a.href=i,a.download=r,a.click(),URL.revokeObjectURL(i),n(e(`archives.toast.exportDownloaded`))}catch{n(e(`archives.toast.exportFailed`),`error`)}finally{me(!1)}},children:[(0,K.jsx)(nc,{className:`w-4 h-4`}),`Export as CSV`]}),(0,K.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:async()=>{fe(!1),me(!0);try{let{blob:t,filename:r}=await Q.exportArchives({format:`xlsx`,printerId:c||void 0,status:oe===`failed`?`failed`:void 0,search:o||void 0}),i=URL.createObjectURL(t),a=document.createElement(`a`);a.href=i,a.download=r,a.click(),URL.revokeObjectURL(i),n(e(`archives.toast.exportDownloaded`))}catch{n(e(`archives.toast.exportFailed`),`error`)}finally{me(!1)}},children:[(0,K.jsx)(tc,{className:`w-4 h-4`}),`Export as Excel`]})]})]}),j.size>=2&&j.size<=5&&(0,K.jsxs)($,{variant:`secondary`,onClick:()=>ge(!0),children:[(0,K.jsx)(vc,{className:`w-4 h-4`}),`Compare (`,j.size,`)`]}),!bt&&(0,K.jsxs)($,{variant:`secondary`,onClick:()=>R(!0),children:[(0,K.jsx)(su,{className:`w-4 h-4`}),`Select`]}),(0,K.jsxs)($,{onClick:()=>O(!0),disabled:!r(`archives:create`),title:r(`archives:create`)?void 0:e(`archives.permission.noCreate`),children:[(0,K.jsx)(Au,{className:`w-4 h-4`}),`Upload 3MF`]}),r(`archives:purge`)&&(0,K.jsxs)($,{variant:`secondary`,onClick:()=>be(!0),title:e(`archivePurge.headerTooltip`),children:[(0,K.jsx)(Cu,{className:`w-4 h-4 mr-2`}),e(`archivePurge.headerButton`)]})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center border border-bambu-dark-tertiary rounded-lg overflow-hidden flex-shrink-0 w-fit mb-4`,children:[(0,K.jsx)(`button`,{className:`p-2 ${re===`grid`?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white`}`,onClick:()=>ie(`grid`),title:e(`archives.gridView`),children:(0,K.jsx)(zc,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{className:`p-2 ${re===`list`?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white`}`,onClick:()=>ie(`list`),title:e(`archives.listView`),children:(0,K.jsx)(Gc,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{className:`p-2 ${re===`calendar`?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white`}`,onClick:()=>ie(`calendar`),title:e(`archives.calendarView`),children:(0,K.jsx)(Yo,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{className:`p-2 ${re===`log`?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white`}`,onClick:()=>ie(`log`),title:e(`archives.logView`),children:(0,K.jsx)(bs,{className:`w-4 h-4`})})]}),re!==`log`&&(0,K.jsx)(Cd,{className:`mb-6`,children:(0,K.jsxs)(Td,{className:`py-4`,children:[(0,K.jsxs)(`div`,{className:`flex flex-col md:flex-row gap-3 md:gap-4 md:items-center md:flex-wrap`,children:[(0,K.jsxs)(`div`,{className:`w-full md:flex-1 relative md:min-w-[200px]`,children:[(0,K.jsx)(Vl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,K.jsx)(`input`,{ref:a,type:`text`,placeholder:e(`archives.searchPlaceholder`),className:`w-full pl-10 pr-4 py-3 md:py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,value:o,onChange:e=>s(e.target.value)})]}),(0,K.jsxs)(`div`,{className:`flex gap-2 md:gap-4 overflow-x-auto pb-1 md:pb-0 -mx-4 px-4 md:mx-0 md:px-0 md:flex-wrap scrollbar-hide`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[(0,K.jsx)(mc,{className:`w-4 h-4 text-bambu-gray hidden md:block`}),(0,K.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?Number(e.target.value):null),children:[(0,K.jsx)(`option`,{value:``,children:`All Printers`}),Xe?.map(e=>(0,K.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[(0,K.jsx)(ml,{className:`w-4 h-4 text-bambu-gray hidden md:block`}),(0,K.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:u||``,onChange:e=>d(e.target.value||null),children:[(0,K.jsx)(`option`,{value:``,children:`All Materials`}),dt.map(e=>(0,K.jsx)(`option`,{value:e,children:e},e))]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[(0,K.jsx)($s,{className:`w-4 h-4 text-bambu-gray hidden md:block`}),(0,K.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:T,onChange:e=>E(e.target.value),children:[(0,K.jsx)(`option`,{value:`all`,children:`All Files`}),(0,K.jsx)(`option`,{value:`gcode`,children:`Sliced (GCODE)`}),(0,K.jsx)(`option`,{value:`source`,children:`Source Only`})]})]}),(0,K.jsxs)(`button`,{onClick:()=>_(!g),className:`flex items-center gap-2 px-3 py-2 rounded-lg border transition-colors flex-shrink-0 ${g?`bg-yellow-100 dark:bg-yellow-500/20 border-yellow-500 text-yellow-700 dark:text-yellow-400`:`bg-bambu-dark border-bambu-dark-tertiary text-bambu-gray hover:text-white`}`,title:e(g?`archives.showAll`:`archives.showFavoritesOnly`),children:[(0,K.jsx)(uu,{className:`w-4 h-4 ${g?`fill-yellow-400`:``}`}),(0,K.jsx)(`span`,{className:`text-sm hidden md:inline`,children:`Favorites`})]}),(0,K.jsxs)(`button`,{onClick:()=>b(!v),className:`flex items-center gap-2 px-3 py-2 rounded-lg border transition-colors flex-shrink-0 ${v?`bg-red-100 dark:bg-red-500/20 border-red-500 text-red-700 dark:text-red-400`:`bg-bambu-dark border-bambu-dark-tertiary text-bambu-gray hover:text-white`}`,title:e(v?`archives.showFailedPrints`:`archives.hideFailedPrints`),children:[(0,K.jsx)(us,{className:`w-4 h-4 `}),(0,K.jsx)(`span`,{className:`text-sm hidden md:inline`,children:`Hide Failed`})]}),(0,K.jsxs)(`button`,{onClick:()=>S(!x),className:`flex items-center gap-2 px-3 py-2 rounded-lg border transition-colors flex-shrink-0 ${x?`bg-purple-100 dark:bg-purple-500/20 border-purple-500 text-purple-700 dark:text-purple-400`:`bg-bambu-dark border-bambu-dark-tertiary text-bambu-gray hover:text-white`}`,title:e(`archives.hideDuplicates`),children:[(0,K.jsx)(Ms,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{className:`text-sm hidden md:inline`,children:e(`archives.hideDuplicates`)})]}),pt.length>0&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[(0,K.jsx)(hu,{className:`w-4 h-4 text-bambu-gray hidden md:block`}),(0,K.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=>w(e.target.value||null),children:[(0,K.jsx)(`option`,{value:``,children:`All Tags`}),pt.map(e=>(0,K.jsx)(`option`,{value:e,children:e},e))]}),(0,K.jsx)(`button`,{onClick:()=>ve(!0),className:`p-2 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary text-bambu-gray hover:text-white hover:border-bambu-green transition-colors`,title:e(`archives.manageTags`),children:(0,K.jsx)(Kl,{className:`w-4 h-4`})})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[(0,K.jsx)(Po,{className:`w-4 h-4 text-bambu-gray hidden md:block`}),(0,K.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:H,onChange:e=>ae(e.target.value),children:[(0,K.jsx)(`option`,{value:`date-desc`,children:e(`archives.sortNewest`)}),(0,K.jsx)(`option`,{value:`date-asc`,children:e(`archives.sortOldest`)}),(0,K.jsxs)(`option`,{value:`name-asc`,children:[e(`archives.sortName`),` A-Z`]}),(0,K.jsxs)(`option`,{value:`name-desc`,children:[e(`archives.sortName`),` Z-A`]}),(0,K.jsx)(`option`,{value:`size-desc`,children:e(`archives.sortLargest`)}),(0,K.jsx)(`option`,{value:`size-asc`,children:e(`archives.sortSmallest`)})]})]})]}),Dt&&(0,K.jsxs)($,{variant:`ghost`,size:`sm`,onClick:Et,className:`text-bambu-gray hover:text-white`,children:[(0,K.jsx)(Wu,{className:`w-4 h-4`}),`Reset`]})]}),ft.length>0&&(0,K.jsxs)(`div`,{className:`flex items-center gap-3 mt-4 pt-4 border-t border-bambu-dark-tertiary`,children:[(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:`Colors:`}),f.size>1&&(0,K.jsx)(`button`,{onClick:()=>h(e=>e===`or`?`and`:`or`),className:`px-2 py-0.5 text-xs rounded transition-colors ${m===`and`?`bg-bambu-green text-white`:`bg-bambu-dark-tertiary text-bambu-gray hover:text-white`}`,title:m===`or`?`Match ANY selected color`:`Match ALL selected colors`,children:m.toUpperCase()}),(0,K.jsx)(`div`,{className:`flex items-center gap-1.5 flex-wrap`,children:ft.map(e=>(0,K.jsx)(`button`,{onClick:()=>wt(e),className:`w-6 h-6 rounded-full border-2 transition-all ${f.has(e)?`border-bambu-green scale-110`:`border-white/20 hover:border-white/40`}`,style:{backgroundColor:e},title:e},e))}),f.size>0&&(0,K.jsxs)(`button`,{onClick:Tt,className:`text-xs text-bambu-gray hover:text-white flex items-center gap-1`,children:[(0,K.jsx)(Wu,{className:`w-3 h-3`}),`Clear`]})]})]})}),(0,K.jsx)(Eze,{}),Ye?(0,K.jsx)(`div`,{className:`text-center py-12 text-bambu-gray`,children:e(`archives.loadingArchives`)}):mt?.length===0?(0,K.jsx)(Cd,{children:(0,K.jsxs)(Td,{className:`text-center py-12`,children:[(0,K.jsx)(`p`,{className:`text-bambu-gray`,children:e(o?`archives.noArchivesSearch`:`archives.noArchivesYet`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mt-2`,children:`Archives are created automatically when prints complete`})]})}):re===`calendar`?(0,K.jsx)(Cd,{className:`p-6`,children:(0,K.jsx)(RAe,{archives:mt||[],onArchiveClick:e=>{s(``),ie(`grid`),Se(e.id)},highlightedArchiveId:xe})}):re===`grid`?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-6`,children:yt?.map(t=>(0,K.jsx)(Oze,{archive:t,printerName:t.printer_id?ut.get(t.printer_id)||`Unknown`:t.sliced_for_model||`No Printer`,isSelected:j.has(t.id),onSelect:xt,selectionMode:bt,projects:Ze,isHighlighted:t.id===xe,timeFormat:nt,preferredSlicer:rt,useSlicerApi:it,currency:at,t:e,onNavigateToArchive:qe},t.id))}),(0,K.jsx)(s2,{pageIndex:se,pageSize:le,totalRows:ht,totalPages:vt,onPageChange:ce,onPageSizeChange:e=>{ue(e),ce(0)},t:e})]}):re===`list`?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Cd,{children:(0,K.jsxs)(`div`,{className:`divide-y divide-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-12 gap-4 px-4 py-3 text-xs text-bambu-gray font-medium`,children:[(0,K.jsx)(`div`,{className:`col-span-1`}),(0,K.jsx)(`div`,{className:`col-span-4`,children:`Name`}),(0,K.jsx)(`div`,{className:`col-span-2`,children:`Printer`}),(0,K.jsx)(`div`,{className:`col-span-2`,children:`Date`}),(0,K.jsx)(`div`,{className:`col-span-1`,children:`Size`}),(0,K.jsx)(`div`,{className:`col-span-2 text-right`,children:`Actions`})]}),yt?.map(t=>(0,K.jsx)(kze,{archive:t,printerName:t.printer_id?ut.get(t.printer_id)||`Unknown`:t.sliced_for_model||`No Printer`,isSelected:j.has(t.id),onSelect:xt,selectionMode:bt,projects:Ze,isHighlighted:t.id===xe,preferredSlicer:rt,useSlicerApi:it,t:e,onNavigateToArchive:qe},t.id))]})}),(0,K.jsx)(s2,{pageIndex:se,pageSize:le,totalRows:ht,totalPages:vt,onPageChange:ce,onPageSizeChange:e=>{ue(e),ce(0)},t:e})]}):re===`log`?(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsx)(Cd,{children:(0,K.jsx)(Td,{className:`py-3`,children:(0,K.jsxs)(`div`,{className:`flex flex-col md:flex-row gap-3 md:items-center md:flex-wrap`,children:[(0,K.jsxs)(`div`,{className:`flex-1 relative md:min-w-[200px]`,children:[(0,K.jsx)(Vl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,K.jsx)(`input`,{type:`text`,placeholder:e(`archives.searchPlaceholder`),className:`w-full pl-10 pr-4 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none text-sm`,value:o,onChange:e=>{s(e.target.value),Pe(0)}})]}),(0,K.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 text-sm`,value:c||``,onChange:e=>{l(e.target.value?Number(e.target.value):null),Pe(0)},children:[(0,K.jsx)(`option`,{value:``,children:e(`archives.log.allPrinters`)}),Xe?.map(e=>(0,K.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),(0,K.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 text-sm`,value:Te||``,onChange:e=>{Ee(e.target.value||null),Pe(0)},children:[(0,K.jsx)(`option`,{value:``,children:e(`archives.log.allUsers`)}),$e?.map(e=>(0,K.jsx)(`option`,{value:e.username,children:e.username},e.id))]}),(0,K.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 text-sm`,value:De||``,onChange:e=>{Oe(e.target.value||null),Pe(0)},children:[(0,K.jsx)(`option`,{value:``,children:e(`archives.log.allStatuses`)}),(0,K.jsx)(`option`,{value:`completed`,children:e(`archives.status.completed`)}),(0,K.jsx)(`option`,{value:`failed`,children:e(`archives.status.failed`)}),(0,K.jsx)(`option`,{value:`stopped`,children:e(`archives.status.stopped`)}),(0,K.jsx)(`option`,{value:`cancelled`,children:e(`archives.log.cancelled`)}),(0,K.jsx)(`option`,{value:`skipped`,children:e(`archives.log.skipped`)})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`label`,{className:`text-sm text-bambu-gray`,children:e(`archives.log.dateFrom`)}),(0,K.jsx)(`input`,{type:`date`,className:`px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none text-sm`,value:ke,onChange:e=>{Ae(e.target.value),Pe(0)}})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`label`,{className:`text-sm text-bambu-gray`,children:e(`archives.log.dateTo`)}),(0,K.jsx)(`input`,{type:`date`,className:`px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none text-sm`,value:je,onChange:e=>{Me(e.target.value),Pe(0)}})]}),(0,K.jsx)(`div`,{className:`ml-auto`,children:(0,K.jsxs)($,{variant:`danger`,size:`sm`,onClick:()=>Ie(!0),disabled:!r(`archives:delete_all`)||st.isPending,children:[(0,K.jsx)(Cu,{className:`w-4 h-4`}),e(`archives.log.clearLog`)]})})]})})}),(0,K.jsx)(Cd,{children:tt?(0,K.jsx)(`div`,{className:`flex items-center justify-center py-12`,children:(0,K.jsx)(X,{className:`w-6 h-6 animate-spin text-bambu-green`})}):et?.items.length?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`overflow-x-auto`,children:(0,K.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,K.jsx)(`thead`,{children:(0,K.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary text-bambu-gray text-left`,children:[(0,K.jsx)(`th`,{className:`px-4 py-3 font-medium`,children:e(`archives.log.date`)}),(0,K.jsx)(`th`,{className:`px-4 py-3 font-medium`,children:e(`archives.log.printName`)}),(0,K.jsx)(`th`,{className:`px-4 py-3 font-medium`,children:e(`archives.log.printer`)}),(0,K.jsx)(`th`,{className:`px-4 py-3 font-medium`,children:e(`archives.log.user`)}),(0,K.jsx)(`th`,{className:`px-4 py-3 font-medium`,children:e(`archives.log.status`)}),(0,K.jsx)(`th`,{className:`px-4 py-3 font-medium`,children:e(`archives.log.duration`)}),(0,K.jsx)(`th`,{className:`px-4 py-3 font-medium`,children:e(`archives.log.filament`)}),(0,K.jsx)(`th`,{className:`px-4 py-3 font-medium w-10`,"aria-label":e(`common.actions`)})]})}),(0,K.jsx)(`tbody`,{className:`divide-y divide-bambu-dark-tertiary`,children:et.items.map(t=>(0,K.jsxs)(`tr`,{className:`hover:bg-bambu-dark-secondary/50`,children:[(0,K.jsx)(`td`,{className:`px-4 py-3 text-white whitespace-nowrap`,children:Mf(t.started_at||t.created_at,nt)}),(0,K.jsx)(`td`,{className:`px-4 py-3`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[t.thumbnail_path&&(0,K.jsx)(`img`,{src:Q.getPrintLogThumbnail(t.id),alt:``,className:`w-8 h-8 rounded object-cover flex-shrink-0`,onError:e=>{e.target.style.display=`none`}}),(0,K.jsx)(`span`,{className:`text-white break-words`,title:t.print_name||``,children:t.print_name||`—`})]})}),(0,K.jsx)(`td`,{className:`px-4 py-3 text-bambu-gray-light`,children:t.printer_name||`—`}),(0,K.jsx)(`td`,{className:`px-4 py-3 text-bambu-gray-light`,children:t.created_by_username||`—`}),(0,K.jsxs)(`td`,{className:`px-4 py-3`,children:[(0,K.jsx)(`span`,{className:`inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium ${t.status===`completed`?`bg-green-100 dark:bg-green-500/20 text-green-700 dark:text-green-400`:t.status===`failed`?`bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400`:t.status===`stopped`?`bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400`:t.status===`cancelled`?`bg-orange-100 dark:bg-orange-500/20 text-orange-700 dark:text-orange-400`:t.status===`skipped`?`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`:`bg-gray-500/20 text-gray-400`}`,children:t.status}),t.failure_reason&&(0,K.jsx)(`span`,{className:`block text-[10px] text-bambu-gray mt-0.5`,children:e(`editArchive.failureReasons.${t.failure_reason}`,{defaultValue:t.failure_reason})})]}),(0,K.jsx)(`td`,{className:`px-4 py-3 text-bambu-gray-light whitespace-nowrap`,children:t.duration_seconds?Ff(t.duration_seconds):`—`}),(0,K.jsx)(`td`,{className:`px-4 py-3`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[t.filament_color&&(0,K.jsx)(`div`,{className:`flex items-center gap-0.5 flex-wrap`,children:t.filament_color.split(`,`).map((e,t)=>{let n=e.trim();return(0,K.jsx)(`span`,{className:`w-3 h-3 rounded-full border border-black/20 flex-shrink-0`,style:{backgroundColor:n.startsWith(`#`)?n:void 0},title:n},t)})}),(0,K.jsx)(`span`,{className:`text-bambu-gray-light text-xs`,children:t.filament_type||`—`})]})}),(0,K.jsx)(`td`,{className:`px-4 py-3 text-right`,children:(0,K.jsxs)(`div`,{className:`inline-flex items-center gap-2`,children:[(0,K.jsx)(`button`,{type:`button`,onClick:()=>{Be(t),He(t.failure_reason||``),We(t.status)},disabled:lt.isPending||!(r(`archives:update_all`)||r(`archives:update_own`)),title:r(`archives:update_all`)||r(`archives:update_own`)?e(`archives.log.editEntryTitle`):e(`archives.permission.noEdit`),className:`text-bambu-gray hover:text-bambu-blue disabled:opacity-40 disabled:hover:text-bambu-gray transition-colors`,children:(0,K.jsx)(xl,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>Re(t.id),disabled:ct.isPending||!(r(`archives:delete_all`)||r(`archives:delete_own`)),title:r(`archives:delete_all`)||r(`archives:delete_own`)?e(`archives.log.deleteEntryTitle`):e(`archives.permission.noDelete`),className:`text-bambu-gray hover:text-red-600 dark:hover:text-red-400 disabled:opacity-40 disabled:hover:text-bambu-gray transition-colors`,children:(0,K.jsx)(Cu,{className:`w-4 h-4`})})]})})]},t.id))})]})}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 border-t border-bambu-dark-tertiary flex-wrap gap-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e(`archives.log.showing`,{count:Math.min(Ne+Ge,et.total),total:et.total})}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,K.jsx)(`label`,{className:`text-xs text-bambu-gray`,children:e(`archives.log.rowsPerPage`)}),(0,K.jsxs)(`select`,{className:`px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-xs focus:border-bambu-green focus:outline-none`,value:Ge,onChange:e=>{Ke(Number(e.target.value)),Pe(0)},children:[(0,K.jsx)(`option`,{value:10,children:`10`}),(0,K.jsx)(`option`,{value:25,children:`25`}),(0,K.jsx)(`option`,{value:50,children:`50`}),(0,K.jsx)(`option`,{value:100,children:`100`})]})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[e(`archives.log.page`),` `,Math.floor(Ne/Ge)+1,` / `,Math.max(1,Math.ceil(et.total/Ge))]}),(0,K.jsx)($,{variant:`secondary`,size:`sm`,onClick:()=>Pe(Math.max(0,Ne-Ge)),disabled:Ne===0,children:(0,K.jsx)(as,{className:`w-4 h-4`})}),(0,K.jsx)($,{variant:`secondary`,size:`sm`,onClick:()=>Pe(Ne+Ge),disabled:Ne+Ge>=et.total,children:(0,K.jsx)(is,{className:`w-4 h-4`})})]})]})]}):(0,K.jsx)(`div`,{className:`text-center py-12 text-bambu-gray`,children:e(`archives.log.noEntries`)})})]}):null,D&&(0,K.jsx)(TAe,{onClose:()=>{O(!1),A([])},initialFiles:k}),ye&&(0,K.jsx)(DAe,{onClose:()=>be(!1)}),z&&(0,K.jsx)(Bd,{title:e(`archives.modal.deleteArchives`),message:e(`archives.modal.deleteArchivesConfirm`,{count:j.size}),confirmText:e(`archives.modal.deleteCount`,{count:j.size}),variant:`danger`,onConfirm:()=>{ot.mutate(Array.from(j)),B(!1)},onCancel:()=>B(!1)}),V&&(0,K.jsx)(MAe,{selectedIds:Array.from(j),existingTags:pt,onClose:()=>ee(!1)}),te&&(0,K.jsx)(NAe,{selectedIds:Array.from(j),onClose:()=>ne(!1)}),he&&j.size>=2&&j.size<=5&&(0,K.jsx)(Sze,{archiveIds:Array.from(j),onClose:()=>{ge(!1),M(new Set),R(!1)}}),_e&&(0,K.jsx)(Dze,{onClose:()=>ve(!1)}),Fe&&(0,K.jsx)(Bd,{title:e(`archives.log.clearLogTitle`),message:e(`archives.log.clearLogConfirm`),confirmText:e(`archives.log.clearLogButton`),variant:`danger`,onConfirm:()=>{st.mutate(),Ie(!1)},onCancel:()=>Ie(!1)}),Le!==null&&(0,K.jsx)(Bd,{title:e(`archives.log.deleteEntryTitle`),message:e(`archives.log.deleteEntryConfirm`),confirmText:e(`common.delete`),variant:`danger`,onConfirm:()=>{ct.mutate(Le),Re(null)},onCancel:()=>Re(null)}),ze!==null&&(0,K.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm`,onClick:()=>Be(null),children:(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg w-full max-w-md mx-4 p-6`,onClick:e=>e.stopPropagation(),children:[(0,K.jsx)(`h3`,{className:`text-lg font-semibold text-white mb-4`,children:e(`archives.log.editEntryTitle`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mb-4`,children:e(`archives.log.editEntryDescription`)}),(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:e(`editArchive.status`)}),(0,K.jsxs)(`select`,{value:Ue,onChange:e=>We(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`,children:[(0,K.jsx)(`option`,{value:`completed`,children:e(`archives.log.statuses.completed`,{defaultValue:`completed`})}),(0,K.jsx)(`option`,{value:`failed`,children:e(`archives.log.statuses.failed`,{defaultValue:`failed`})}),(0,K.jsx)(`option`,{value:`stopped`,children:e(`archives.log.statuses.stopped`,{defaultValue:`stopped`})}),(0,K.jsx)(`option`,{value:`cancelled`,children:e(`archives.log.statuses.cancelled`,{defaultValue:`cancelled`})}),(0,K.jsx)(`option`,{value:`skipped`,children:e(`archives.log.statuses.skipped`,{defaultValue:`skipped`})})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:e(`editArchive.failureReason`)}),(0,K.jsxs)(`select`,{value:Ve,onChange:e=>He(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`,children:[(0,K.jsx)(`option`,{value:``,children:e(`editArchive.selectReason`)}),QW.map(t=>(0,K.jsx)(`option`,{value:t,children:e(`editArchive.failureReasons.${t}`)},t))]})]})]}),(0,K.jsxs)(`div`,{className:`flex justify-end gap-2 mt-6`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:()=>Be(null),children:e(`common.cancel`)}),(0,K.jsx)($,{variant:`primary`,onClick:()=>{let e={};if(Ve!==(ze.failure_reason||``)&&(e.failure_reason=Ve||null),Ue!==ze.status&&(e.status=Ue),Object.keys(e).length===0){Be(null);return}lt.mutate({id:ze.id,body:e})},disabled:lt.isPending,children:lt.isPending?e(`editArchive.saving`):e(`common.save`)})]})]})})]})}function s2({pageIndex:e,pageSize:t,totalRows:n,totalPages:r,onPageChange:i,onPageSizeChange:a,t:o}){let s=t===-1;if(r<=1&&!s)return null;let c=s?n||1:t;return(0,K.jsxs)(`div`,{className:`flex items-center justify-between pt-2 text-sm`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:s?`${n} ${o(`archives.prints`)}`:(0,K.jsxs)(K.Fragment,{children:[o(`archives.pagination.showing`),` `,e*c+1,` `,o(`archives.pagination.to`),` `,Math.min((e+1)*c,n),` `,o(`archives.pagination.of`),` `,n,` `,o(`archives.prints`)]})}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:o(`archives.pagination.show`)}),(0,K.jsxs)(`select`,{value:t,onChange:e=>a(Number(e.target.value)),className:`px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:outline-none focus:border-bambu-green`,children:[[25,50,100,200].map(e=>(0,K.jsx)(`option`,{value:e,children:e},e)),(0,K.jsx)(`option`,{value:-1,children:o(`archives.pagination.all`)})]}),!s&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`button`,{onClick:()=>i(0),disabled:e===0,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,children:(0,K.jsx)(cs,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>i(Math.max(0,e-1)),disabled:e===0,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,children:(0,K.jsx)(as,{className:`w-4 h-4`})}),(0,K.jsxs)(`span`,{className:`text-bambu-gray px-2 whitespace-nowrap`,children:[o(`archives.pagination.page`),` `,e+1,` `,o(`archives.pagination.of`),` `,r]}),(0,K.jsx)(`button`,{onClick:()=>i(Math.min(r-1,e+1)),disabled:e>=r-1,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,children:(0,K.jsx)(is,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>i(r-1),disabled:e>=r-1,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,children:(0,K.jsx)(ls,{className:`w-4 h-4`})})]})]})]})}function Nze(){var e=[...arguments];return(0,y.useMemo)(()=>t=>{e.forEach(e=>e(t))},e)}var c2=typeof window<`u`&&window.document!==void 0&&window.document.createElement!==void 0;function l2(e){let t=Object.prototype.toString.call(e);return t===`[object Window]`||t===`[object global]`}function u2(e){return`nodeType`in e}function d2(e){return e?l2(e)?e:u2(e)?e.ownerDocument?.defaultView??window:window:window}function f2(e){let{Document:t}=d2(e);return e instanceof t}function p2(e){return l2(e)?!1:e instanceof d2(e).HTMLElement}function m2(e){return e instanceof d2(e).SVGElement}function h2(e){return e?l2(e)?e.document:u2(e)?f2(e)?e:p2(e)||m2(e)?e.ownerDocument:document:document:document}var g2=c2?y.useLayoutEffect:y.useEffect;function _2(e){let t=(0,y.useRef)(e);return g2(()=>{t.current=e}),(0,y.useCallback)(function(){var e=[...arguments];return t.current==null?void 0:t.current(...e)},[])}function Pze(){let e=(0,y.useRef)(null);return[(0,y.useCallback)((t,n)=>{e.current=setInterval(t,n)},[]),(0,y.useCallback)(()=>{e.current!==null&&(clearInterval(e.current),e.current=null)},[])]}function v2(e,t){t===void 0&&(t=[e]);let n=(0,y.useRef)(e);return g2(()=>{n.current!==e&&(n.current=e)},t),n}function y2(e,t){let n=(0,y.useRef)();return(0,y.useMemo)(()=>{let t=e(n.current);return n.current=t,t},[...t])}function b2(e){let t=_2(e),n=(0,y.useRef)(null);return[n,(0,y.useCallback)(e=>{e!==n.current&&t?.(e,n.current),n.current=e},[])]}function x2(e){let t=(0,y.useRef)();return(0,y.useEffect)(()=>{t.current=e},[e]),t.current}var S2={};function C2(e,t){return(0,y.useMemo)(()=>{if(t)return t;let n=S2[e]==null?0:S2[e]+1;return S2[e]=n,e+`-`+n},[e,t])}function w2(e){return function(t){return[...arguments].slice(1).reduce((t,n)=>{let r=Object.entries(n);for(let[n,i]of r){let r=t[n];r!=null&&(t[n]=r+e*i)}return t},{...t})}}var T2=w2(1),E2=w2(-1);function Fze(e){return`clientX`in e&&`clientY`in e}function D2(e){if(!e)return!1;let{KeyboardEvent:t}=d2(e.target);return t&&e instanceof t}function Ize(e){if(!e)return!1;let{TouchEvent:t}=d2(e.target);return t&&e instanceof t}function O2(e){if(Ize(e)){if(e.touches&&e.touches.length){let{clientX:t,clientY:n}=e.touches[0];return{x:t,y:n}}else if(e.changedTouches&&e.changedTouches.length){let{clientX:t,clientY:n}=e.changedTouches[0];return{x:t,y:n}}}return Fze(e)?{x:e.clientX,y:e.clientY}:null}var k2=Object.freeze({Translate:{toString(e){if(!e)return;let{x:t,y:n}=e;return`translate3d(`+(t?Math.round(t):0)+`px, `+(n?Math.round(n):0)+`px, 0)`}},Scale:{toString(e){if(!e)return;let{scaleX:t,scaleY:n}=e;return`scaleX(`+t+`) scaleY(`+n+`)`}},Transform:{toString(e){if(e)return[k2.Translate.toString(e),k2.Scale.toString(e)].join(` `)}},Transition:{toString(e){let{property:t,duration:n,easing:r}=e;return t+` `+n+`ms `+r}}}),A2=`a,frame,iframe,input:not([type=hidden]):not(:disabled),select:not(:disabled),textarea:not(:disabled),button:not(:disabled),*[tabindex]`;function Lze(e){return e.matches(A2)?e:e.querySelector(A2)}var Rze={display:`none`};function zze(e){let{id:t,value:n}=e;return y.createElement(`div`,{id:t,style:Rze},n)}function Bze(e){let{id:t,announcement:n,ariaLiveType:r=`assertive`}=e;return y.createElement(`div`,{id:t,style:{position:`fixed`,top:0,left:0,width:1,height:1,margin:-1,border:0,padding:0,overflow:`hidden`,clip:`rect(0 0 0 0)`,clipPath:`inset(100%)`,whiteSpace:`nowrap`},role:`status`,"aria-live":r,"aria-atomic":!0},n)}function Vze(){let[e,t]=(0,y.useState)(``);return{announce:(0,y.useCallback)(e=>{e!=null&&t(e)},[]),announcement:e}}var j2=(0,y.createContext)(null);function Hze(e){let t=(0,y.useContext)(j2);(0,y.useEffect)(()=>{if(!t)throw Error(`useDndMonitor must be used within a children of `);return t(e)},[e,t])}function Uze(){let[e]=(0,y.useState)(()=>new Set),t=(0,y.useCallback)(t=>(e.add(t),()=>e.delete(t)),[e]);return[(0,y.useCallback)(t=>{let{type:n,event:r}=t;e.forEach(e=>e[n]?.call(e,r))},[e]),t]}var Wze={draggable:`
+ [&::-webkit-slider-thumb]:cursor-pointer`}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray w-12`,children:Lf(p)})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`button`,{onClick:()=>{let e=o.current;e&&(e.currentTime=Math.max(0,e.currentTime-5))},className:`p-2 hover:bg-bambu-dark-tertiary rounded-lg transition-colors`,title:`Skip back 5s`,children:(0,K.jsx)($l,{className:`w-5 h-5 text-bambu-gray`})}),(0,K.jsx)(`button`,{onClick:_,className:`p-2 bg-bambu-green hover:bg-bambu-green-dark rounded-lg transition-colors`,children:s?(0,K.jsx)(vl,{className:`w-5 h-5 text-white`}):(0,K.jsx)(Cl,{className:`w-5 h-5 text-white`})}),(0,K.jsx)(`button`,{onClick:()=>{let e=o.current;e&&(e.currentTime=Math.min(p,e.currentTime+5))},className:`p-2 hover:bg-bambu-dark-tertiary rounded-lg transition-colors`,title:`Skip forward 5s`,children:(0,K.jsx)(eu,{className:`w-5 h-5 text-bambu-gray`})})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:`Speed:`}),(0,K.jsx)(`div`,{className:`flex gap-1`,children:xze.map(e=>(0,K.jsxs)(`button`,{onClick:()=>u(e),className:`px-2 py-1 text-xs rounded transition-colors ${l===e?`bg-bambu-green text-white`:`bg-bambu-dark-tertiary text-bambu-gray hover:bg-bambu-dark-tertiary/80`}`,children:[e,`x`]},e))})]})]})]})]})]}),h&&r&&(0,K.jsx)(bze,{archiveId:r,timelapseSrc:e,onClose:()=>g(!1),onSave:a})]})}function Sze({archiveIds:e,onClose:t}){(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]);let{data:n,isLoading:r,error:i}=q({queryKey:[`archive-comparison`,e],queryFn:()=>Q.compareArchives(e)});return(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/80 flex items-center justify-center z-50 p-4`,onClick:t,children:(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg max-w-4xl w-full max-h-[90vh] flex flex-col border border-bambu-dark-tertiary`,onClick:e=>e.stopPropagation(),children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`h3`,{className:`text-lg font-semibold text-white`,children:[`Compare Archives (`,e.length,`)`]}),(0,K.jsx)(`button`,{onClick:t,className:`text-bambu-gray hover:text-white p-1`,children:(0,K.jsx)(Wu,{className:`w-5 h-5`})})]}),(0,K.jsx)(`div`,{className:`flex-1 overflow-auto p-4 bg-bambu-dark-secondary`,children:r?(0,K.jsx)(`div`,{className:`flex items-center justify-center py-12`,children:(0,K.jsx)(X,{className:`w-8 h-8 text-bambu-green animate-spin`})}):i?(0,K.jsxs)(`div`,{className:`text-center py-12 text-red-700 dark:text-red-400`,children:[(0,K.jsx)(Eu,{className:`w-12 h-12 mx-auto mb-4 opacity-50`}),(0,K.jsx)(`p`,{children:`Failed to load comparison`}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mt-2`,children:i instanceof Error?i.message:`Unknown error`})]}):n?(0,K.jsx)(Cze,{comparison:n}):null}),(0,K.jsx)(`div`,{className:`p-4 border-t border-bambu-dark-tertiary`,children:(0,K.jsx)($,{variant:`secondary`,onClick:t,className:`w-full`,children:`Close`})})]})})}function Cze({comparison:e}){return(0,K.jsxs)(`div`,{className:`space-y-6`,children:[(0,K.jsx)(`div`,{className:`overflow-x-auto`,children:(0,K.jsxs)(`table`,{className:`w-full`,children:[(0,K.jsx)(`thead`,{children:(0,K.jsxs)(`tr`,{children:[(0,K.jsx)(`th`,{className:`text-left text-sm text-bambu-gray font-medium pb-2 pr-4 min-w-[150px]`,children:`Setting`}),e.archives.map(e=>(0,K.jsxs)(`th`,{className:`text-left text-sm font-medium pb-2 px-2 min-w-[120px]`,children:[(0,K.jsx)(`div`,{className:`text-white truncate max-w-[150px]`,title:e.print_name,children:e.print_name}),(0,K.jsx)(`div`,{className:`text-xs ${e.status===`completed`?`text-status-ok`:e.status===`failed`?`text-status-error`:`text-bambu-gray`}`,children:e.status})]},e.id))]})}),(0,K.jsx)(`tbody`,{className:`divide-y divide-bambu-gray/20`,children:e.comparison.map(e=>(0,K.jsxs)(`tr`,{className:e.has_difference?`bg-yellow-500/5`:``,children:[(0,K.jsx)(`td`,{className:`py-2 pr-4 text-sm`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.has_difference&&(0,K.jsx)(Eu,{className:`w-3 h-3 text-yellow-600 dark:text-yellow-400 flex-shrink-0`}),(0,K.jsx)(`span`,{className:e.has_difference?`text-yellow-700 dark:text-yellow-400`:`text-bambu-gray`,children:e.label})]})}),e.values.map((t,n)=>(0,K.jsxs)(`td`,{className:`py-2 px-2 text-sm text-white`,children:[t??(0,K.jsx)(`span`,{className:`text-bambu-gray/50`,children:`-`}),e.unit&&t!==null&&(0,K.jsx)(`span`,{className:`text-bambu-gray ml-1`,children:e.unit})]},n))]},e.field))})]})}),e.differences.length>0&&(0,K.jsxs)(`div`,{className:`p-4 bg-yellow-50 border border-yellow-300 dark:bg-yellow-500/10 dark:border-yellow-500/30 rounded-lg`,children:[(0,K.jsxs)(`h4`,{className:`text-sm font-medium text-yellow-700 dark:text-yellow-400 mb-2 flex items-center gap-2`,children:[(0,K.jsx)(Eu,{className:`w-4 h-4`}),e.differences.length,` Difference`,e.differences.length>1?`s`:``,` Found`]}),(0,K.jsxs)(`ul`,{className:`text-sm text-white/80 space-y-1`,children:[e.differences.slice(0,5).map(e=>(0,K.jsxs)(`li`,{children:[(0,K.jsx)(`span`,{className:`text-yellow-700 dark:text-yellow-400`,children:e.label}),`: `,e.values.join(` vs `),` `,e.unit||``]},e.field)),e.differences.length>5&&(0,K.jsxs)(`li`,{className:`text-bambu-gray`,children:[`...and `,e.differences.length-5,` more`]})]})]}),e.success_correlation.has_both_outcomes?(0,K.jsxs)(`div`,{className:`p-4 bg-bambu-dark rounded-lg`,children:[(0,K.jsxs)(`h4`,{className:`text-sm font-medium text-white mb-3 flex items-center gap-2`,children:[(0,K.jsx)(ns,{className:`w-4 h-4 text-bambu-green`}),`Success/Failure Analysis`]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-4 text-sm mb-3`,children:[(0,K.jsxs)(`span`,{className:`text-bambu-green`,children:[e.success_correlation.successful_count,` successful`]}),(0,K.jsxs)(`span`,{className:`text-red-700 dark:text-red-400`,children:[e.success_correlation.failed_count,` failed`]})]}),e.success_correlation.insights&&e.success_correlation.insights.length>0?(0,K.jsx)(`div`,{className:`space-y-2`,children:e.success_correlation.insights.map(e=>(0,K.jsxs)(`div`,{className:`text-sm p-2 bg-bambu-dark-secondary rounded`,children:[(0,K.jsxs)(`span`,{className:`text-white font-medium`,children:[e.label,`:`]}),` `,(0,K.jsx)(`span`,{className:`text-white/80`,children:e.insight})]},e.field))}):(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:`No clear correlations found between settings and outcomes.`})]}):(0,K.jsx)(`div`,{className:`p-4 bg-bambu-dark rounded-lg text-sm text-bambu-gray`,children:(0,K.jsx)(`p`,{children:e.success_correlation.message||`Need both successful and failed prints for correlation analysis.`})})]})}function wze(e){let t=new Date(e),n=new Date().getTime()-t.getTime(),r=Math.floor(n/6e4);if(r<1)return`Just now`;if(r<60)return`${r}m ago`;let i=Math.floor(r/60);return i<24?`${i}h ago`:`${Math.floor(i/24)}d ago`}function Tze({upload:e,projects:t,onArchive:n,onDiscard:r,isArchiving:i,isDiscarding:a}){let[o,s]=(0,y.useState)(!1),[c,l]=(0,y.useState)(e.tags||``),[u,d]=(0,y.useState)(e.notes||``),[f,p]=(0,y.useState)(e.project_id),[m,h]=(0,y.useState)(!1);return(0,K.jsx)(Cd,{children:(0,K.jsxs)(Td,{className:`py-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(Qs,{className:`w-8 h-8 text-bambu-green flex-shrink-0`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-white font-medium`,title:e.filename,children:e.display_name||e.filename}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-bambu-gray`,children:[(0,K.jsx)(`span`,{children:kd(e.file_size)}),(0,K.jsx)(`span`,{children:`·`}),(0,K.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(xs,{className:`w-3 h-3`}),wze(e.uploaded_at)]}),e.source_ip&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`span`,{children:`·`}),(0,K.jsxs)(`span`,{children:[`from `,e.source_ip]})]})]})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`button`,{onClick:()=>s(!o),className:`p-1 text-bambu-gray hover:text-white transition-colors`,children:o?(0,K.jsx)(ss,{className:`w-5 h-5`}):(0,K.jsx)(rs,{className:`w-5 h-5`})}),(0,K.jsx)($,{variant:`primary`,size:`sm`,onClick:()=>n(e.id,{tags:c,notes:u,project_id:f||void 0}),disabled:i,children:i?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Oo,{className:`w-4 h-4`}),`Archive`]})}),(0,K.jsx)($,{variant:`secondary`,size:`sm`,onClick:()=>h(!0),disabled:a,children:a?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(Cu,{className:`w-4 h-4 text-red-600 dark:text-red-400`})})]})]}),m&&(0,K.jsx)(Bd,{title:`Discard Upload`,message:`Are you sure you want to discard "${e.filename}"? This cannot be undone.`,confirmText:`Discard`,variant:`danger`,onConfirm:()=>{r(e.id),h(!1)},onCancel:()=>h(!1)}),o&&(0,K.jsxs)(`div`,{className:`mt-4 pt-4 border-t border-bambu-dark-tertiary space-y-3`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:`Tags`}),(0,K.jsx)(`input`,{type:`text`,value:c,onChange:e=>l(e.target.value),placeholder:`e.g., functional, prototype, gift`,className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-2 text-white placeholder-bambu-gray text-sm`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:`Notes`}),(0,K.jsx)(`textarea`,{value:u,onChange:e=>d(e.target.value),placeholder:`Add notes about this print...`,rows:2,className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-2 text-white placeholder-bambu-gray text-sm resize-none`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:`Project`}),(0,K.jsxs)(`select`,{value:f||``,onChange:e=>p(e.target.value?Number(e.target.value):null),className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-2 text-white text-sm`,children:[(0,K.jsx)(`option`,{value:``,children:`No project`}),t.map(e=>(0,K.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]})]})]})})}function Eze(){let e=no(),{showToast:t}=jd(),[n,r]=(0,y.useState)(!1),[i,a]=(0,y.useState)(!1),[o,s]=(0,y.useState)(new Set),[c,l]=(0,y.useState)(new Set),{data:u,isLoading:d}=q({queryKey:[`pending-uploads`],queryFn:ld.list,refetchInterval:1e4}),{data:f}=q({queryKey:[`projects`],queryFn:()=>Q.getProjects(),select:e=>[...e].sort((e,t)=>e.name.localeCompare(t.name))}),p=J({mutationFn:({id:e,data:t})=>ld.archive(e,t),onMutate:({id:e})=>{s(t=>new Set(t).add(e))},onSettled:(e,t,{id:n})=>{s(e=>{let t=new Set(e);return t.delete(n),t})},onSuccess:n=>{e.invalidateQueries({queryKey:[`pending-uploads`]}),e.invalidateQueries({queryKey:[`archives`]}),t(`Archived: ${n.print_name}`)},onError:e=>{t(e.message||`Failed to archive`,`error`)}}),m=J({mutationFn:e=>ld.discard(e),onMutate:e=>{l(t=>new Set(t).add(e))},onSettled:(e,t,n)=>{l(e=>{let t=new Set(e);return t.delete(n),t})},onSuccess:()=>{e.invalidateQueries({queryKey:[`pending-uploads`]}),t(`Upload discarded`)},onError:e=>{t(e.message||`Failed to discard`,`error`)}}),h=J({mutationFn:ld.archiveAll,onSuccess:n=>{e.invalidateQueries({queryKey:[`pending-uploads`]}),e.invalidateQueries({queryKey:[`archives`]}),t(`Archived ${n.archived} files${n.failed>0?`, ${n.failed} failed`:``}`)},onError:e=>{t(e.message||`Failed to archive all`,`error`)}}),g=J({mutationFn:ld.discardAll,onSuccess:n=>{e.invalidateQueries({queryKey:[`pending-uploads`]}),t(`Discarded ${n.discarded} files`)},onError:e=>{t(e.message||`Failed to discard all`,`error`)}});return d?(0,K.jsx)(Cd,{children:(0,K.jsx)(Td,{className:`py-8 flex justify-center`,children:(0,K.jsx)(X,{className:`w-6 h-6 animate-spin text-bambu-green`})})}):!u||u.length===0?null:(0,K.jsxs)(`div`,{className:`mb-6`,children:[(0,K.jsxs)(Cd,{className:`border-l-4 border-l-yellow-500`,children:[(0,K.jsx)(wd,{children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(Au,{className:`w-5 h-5 text-yellow-500`}),(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white`,children:[`Pending Uploads (`,u.length,`)`]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)($,{variant:`primary`,size:`sm`,onClick:()=>r(!0),disabled:h.isPending,children:h.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Oo,{className:`w-4 h-4`}),`Archive All`]})}),(0,K.jsx)($,{variant:`secondary`,size:`sm`,onClick:()=>a(!0),disabled:g.isPending,children:g.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Cu,{className:`w-4 h-4`}),`Discard All`]})})]})]})}),(0,K.jsxs)(Td,{children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4`,children:`These files were uploaded via the virtual printer. Review and archive them to add to your collection.`}),(0,K.jsx)(`div`,{className:`space-y-3`,children:u.map(e=>(0,K.jsx)(Tze,{upload:e,projects:f||[],onArchive:(e,t)=>p.mutate({id:e,data:t}),onDiscard:e=>m.mutate(e),isArchiving:o.has(e.id),isDiscarding:c.has(e.id)},e.id))})]})]}),n&&(0,K.jsx)(Bd,{title:`Archive All Uploads`,message:`Are you sure you want to archive all ${u.length} pending uploads?`,confirmText:`Archive All`,onConfirm:()=>{h.mutate(),r(!1)},onCancel:()=>r(!1)}),i&&(0,K.jsx)(Bd,{title:`Discard All Uploads`,message:`Are you sure you want to discard all ${u.length} pending uploads? This cannot be undone.`,confirmText:`Discard All`,variant:`danger`,onConfirm:()=>{g.mutate(),a(!1)},onCancel:()=>a(!1)})]})}function Dze({onClose:e}){let t=no(),{showToast:n}=jd(),[r,i]=(0,y.useState)(``),[a,o]=(0,y.useState)(null),[s,c]=(0,y.useState)(``),[l,u]=(0,y.useState)(null),[d,f]=(0,y.useState)(`count`);(0,y.useEffect)(()=>{let t=t=>{t.key===`Escape`&&(a?o(null):l?u(null):e())};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e,a,l]);let{data:p,isLoading:m}=q({queryKey:[`tags`],queryFn:Q.getTags}),h=J({mutationFn:({oldName:e,newName:t})=>Q.renameTag(e,t),onSuccess:(e,{oldName:r,newName:i})=>{t.invalidateQueries({queryKey:[`tags`]}),t.invalidateQueries({queryKey:[`archives`]}),n(`Renamed "${r}" to "${i}" in ${e.affected} archive${e.affected===1?``:`s`}`),o(null)},onError:e=>{n(e.message||`Failed to rename tag`,`error`)}}),g=J({mutationFn:e=>Q.deleteTag(e),onSuccess:(e,r)=>{t.invalidateQueries({queryKey:[`tags`]}),t.invalidateQueries({queryKey:[`archives`]}),n(`Deleted "${r}" from ${e.affected} archive${e.affected===1?``:`s`}`),u(null)},onError:e=>{n(e.message||`Failed to delete tag`,`error`)}}),_=e=>{o(e.name),c(e.name),u(null)},v=()=>{o(null),c(``)},b=()=>{if(!a||!s.trim())return;let e=s.trim();if(e===a){v();return}h.mutate({oldName:a,newName:e})},x=e=>{e.key===`Enter`?(e.preventDefault(),b()):e.key===`Escape`&&(e.preventDefault(),v())},S=e=>{u(e),o(null)},C=()=>{l&&g.mutate(l)},w=p?.filter(e=>e.name.toLowerCase().includes(r.toLowerCase())).sort((e,t)=>d===`count`&&t.count-e.count||e.name.localeCompare(t.name)),T=p?.reduce((e,t)=>e+t.count,0)||0;return(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,children:(0,K.jsx)(Cd,{className:`w-full max-w-lg max-h-[80vh] flex flex-col`,children:(0,K.jsxs)(Td,{className:`p-0 flex flex-col min-h-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary flex-shrink-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(hu,{className:`w-5 h-5 text-bambu-green`}),(0,K.jsx)(`h2`,{className:`text-xl font-semibold text-white`,children:`Manage Tags`})]}),(0,K.jsx)(`button`,{onClick:e,className:`text-bambu-gray hover:text-white transition-colors`,children:(0,K.jsx)(Wu,{className:`w-5 h-5`})})]}),(0,K.jsxs)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary flex-shrink-0`,children:[(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsxs)(`div`,{className:`relative flex-1`,children:[(0,K.jsx)(Vl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,K.jsx)(`input`,{type:`text`,placeholder:`Search tags...`,className:`w-full pl-9 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,value:r,onChange:e=>i(e.target.value)})]}),(0,K.jsxs)(`select`,{className:`px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,value:d,onChange:e=>f(e.target.value),children:[(0,K.jsx)(`option`,{value:`count`,children:`Sort by Count`}),(0,K.jsx)(`option`,{value:`name`,children:`Sort by Name`})]})]}),p&&(0,K.jsxs)(`p`,{className:`text-xs text-bambu-gray mt-2`,children:[p.length,` tag`,p.length===1?``:`s`,` across `,T,` usage`,T===1?``:`s`]})]}),(0,K.jsx)(`div`,{className:`flex-1 overflow-y-auto min-h-0 p-4`,children:m?(0,K.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,K.jsx)(X,{className:`w-6 h-6 animate-spin text-bambu-gray`})}):w?.length?(0,K.jsx)(`div`,{className:`space-y-2`,children:w.map(e=>(0,K.jsx)(`div`,{className:`flex items-center gap-2 p-2 rounded-lg bg-bambu-dark hover:bg-bambu-dark-tertiary transition-colors group`,children:a===e.name?(0,K.jsxs)(`div`,{className:`flex-1 flex items-center gap-2`,children:[(0,K.jsx)(`input`,{type:`text`,className:`flex-1 px-2 py-1 bg-bambu-dark-tertiary border border-bambu-green rounded text-white text-sm focus:outline-none`,value:s,onChange:e=>c(e.target.value),onKeyDown:x,autoFocus:!0}),(0,K.jsx)($,{size:`sm`,variant:`primary`,onClick:b,disabled:!s.trim()||h.isPending,className:`p-1.5`,children:h.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(ns,{className:`w-4 h-4`})}),(0,K.jsx)($,{size:`sm`,variant:`ghost`,onClick:v,className:`p-1.5`,children:(0,K.jsx)(Wu,{className:`w-4 h-4`})})]}):l===e.name?(0,K.jsxs)(`div`,{className:`flex-1 flex items-center gap-2`,children:[(0,K.jsx)(Eu,{className:`w-4 h-4 text-yellow-600 dark:text-yellow-400 flex-shrink-0`}),(0,K.jsxs)(`span`,{className:`text-sm text-bambu-gray-light flex-1`,children:[`Delete "`,e.name,`" from `,e.count,` archive`,e.count===1?``:`s`,`?`]}),(0,K.jsx)($,{size:`sm`,variant:`danger`,onClick:C,disabled:g.isPending,className:`p-1.5`,children:g.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(Cu,{className:`w-4 h-4`})}),(0,K.jsx)($,{size:`sm`,variant:`ghost`,onClick:()=>u(null),className:`p-1.5`,children:(0,K.jsx)(Wu,{className:`w-4 h-4`})})]}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(hu,{className:`w-4 h-4 text-bambu-gray flex-shrink-0`}),(0,K.jsx)(`span`,{className:`text-white flex-1 truncate`,children:e.name}),(0,K.jsx)(`span`,{className:`px-2 py-0.5 rounded-full bg-bambu-dark-tertiary text-bambu-gray text-xs`,children:e.count}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity`,children:[(0,K.jsx)(`button`,{onClick:()=>_(e),className:`p-1.5 rounded hover:bg-bambu-dark text-bambu-gray hover:text-white transition-colors`,title:`Rename tag`,children:(0,K.jsx)(xl,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>S(e.name),className:`p-1.5 rounded hover:bg-bambu-dark text-bambu-gray hover:text-red-700 dark:hover:text-red-400 transition-colors`,title:`Delete tag`,children:(0,K.jsx)(Cu,{className:`w-4 h-4`})})]})]})},e.name))}):(0,K.jsx)(`div`,{className:`text-center py-8 text-bambu-gray`,children:r?`No tags match your search`:`No tags found`})}),(0,K.jsx)(`div`,{className:`flex gap-3 p-4 border-t border-bambu-dark-tertiary flex-shrink-0`,children:(0,K.jsx)($,{variant:`secondary`,onClick:e,className:`flex-1`,children:`Close`})})]})})})}function a2(e){let t=e.filename;if(t){let e=t.toLowerCase();if(e.endsWith(`.gcode`)||e.includes(`.gcode.`))return!0}return!!(e.total_layers||e.print_time_seconds)}async function o2(e,t,n,r){try{if(n===`source`){let{token:n}=await Q.createSourceSlicerToken(e),i=Q.getSourceSlicerDownloadUrl(e,n,t);qW(`${window.location.origin}${i}`,r)}else{let{token:n}=await Q.createArchiveSlicerToken(e),i=Q.getArchiveSlicerDownloadUrl(e,n,t);qW(`${window.location.origin}${i}`,r)}}catch{let i=n===`source`?Q.getSource3mfForSlicer(e,t):Q.getArchiveForSlicer(e,t);qW(`${window.location.origin}${i}`,r)}}function Oze({archive:e,printerName:t,isSelected:n,onSelect:r,selectionMode:i,projects:a,isHighlighted:o,timeFormat:s=`system`,preferredSlicer:c=`bambu_studio`,useSlicerApi:l=!1,currency:u,t:d,onNavigateToArchive:f}){o&&console.log(`ArchiveCard isHighlighted=true for archive:`,e.id);let p=no(),{showToast:m}=jd(),{hasPermission:h,canModify:g}=_d(),_=YW(),v=$n(),[b,x]=(0,y.useState)(!1),[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=q({queryKey:[`archive`,e.id,`delete-impact`],queryFn:()=>Q.getArchiveDeleteImpact(e.id),enabled:E,staleTime:0}),[j,M]=(0,y.useState)(!1),[N,P]=(0,y.useState)(!1),[F,I]=(0,y.useState)(!1),[L,R]=(0,y.useState)(!1),[z,B]=(0,y.useState)([]),[V,ee]=(0,y.useState)(!1),[te,ne]=(0,y.useState)(!1),[re,ie]=(0,y.useState)(!1),[H,ae]=(0,y.useState)(!1),[oe,U]=(0,y.useState)(!1),[se,ce]=(0,y.useState)(!1),[le,ue]=(0,y.useState)(null),[de,fe]=(0,y.useState)(null),[pe,me]=(0,y.useState)(!1),[he,ge]=(0,y.useState)(null),_e=(0,y.useRef)(null),ve=(0,y.useRef)(null),ye=(0,y.useRef)(null),{data:be}=q({queryKey:[`archive-plates`,e.id],queryFn:()=>Q.getArchivePlates(e.id),enabled:pe,staleTime:300*1e3}),xe=e.duplicate_sequence??0,Se=e.original_archive_id??null,Ce=be?.plates??[],we=be?.is_multi_plate??!1,Te=de??0,Ee=async()=>{try{let t=await Q.getArchivePlates(e.id);if(t.has_gcode===!1){m(d(`archives.platePicker.noGcode`),`info`);return}if(t.is_multi_plate&&t.plates.length>1){ge(t.plates);return}}catch{}v(`/gcode-viewer?archive=${e.id}`)},De=J({mutationFn:()=>Q.deleteArchiveTimelapse(e.id),onSuccess:()=>{p.invalidateQueries({queryKey:[`archives`]}),m(d(`archives.toast.timelapseRemoved`))},onError:e=>{m(e.message||d(`archives.toast.failedRemoveTimelapse`),`error`)}}),Oe=J({mutationFn:t=>Q.uploadArchiveTimelapse(e.id,t),onSuccess:e=>{p.invalidateQueries({queryKey:[`archives`]}),m(d(`archives.toast.timelapseUploaded`,{filename:e.filename}))},onError:e=>{m(e.message||d(`archives.toast.failedUploadTimelapse`),`error`)}}),ke=J({mutationFn:t=>Q.uploadSource3mf(e.id,t),onSuccess:e=>{p.invalidateQueries({queryKey:[`archives`]}),m(d(`archives.toast.source3mfAttached`,{filename:e.filename}))},onError:e=>{m(e.message||d(`archives.toast.failedUploadSource3mf`),`error`)}}),Ae=J({mutationFn:()=>Q.deleteSource3mf(e.id),onSuccess:()=>{p.invalidateQueries({queryKey:[`archives`]}),m(d(`archives.toast.source3mfRemoved`))},onError:e=>{m(e.message||d(`archives.toast.failedRemoveSource3mf`),`error`)}}),je=J({mutationFn:t=>Q.uploadF3d(e.id,t),onSuccess:e=>{p.invalidateQueries({queryKey:[`archives`]}),m(d(`archives.toast.f3dAttached`,{filename:e.filename}))},onError:e=>{m(e.message||d(`archives.toast.failedUploadF3d`),`error`)}}),Me=J({mutationFn:()=>Q.deleteF3d(e.id),onSuccess:()=>{p.invalidateQueries({queryKey:[`archives`]}),m(d(`archives.toast.f3dRemoved`))},onError:e=>{m(e.message||d(`archives.toast.failedRemoveF3d`),`error`)}}),Ne=J({mutationFn:()=>Q.scanArchiveTimelapse(e.id),onSuccess:e=>{e.status===`attached`?(p.invalidateQueries({queryKey:[`archives`]}),m(d(`archives.toast.timelapseAttached`,{filename:e.filename}))):e.status===`exists`?m(d(`archives.toast.timelapseAlreadyAttached`)):e.status===`not_found`&&e.available_files&&e.available_files.length>0?(B(e.available_files),R(!0)):m(e.message||d(`archives.toast.noMatchingTimelapse`),`warning`)},onError:e=>{m(e.message||d(`archives.toast.failedScanTimelapse`),`error`)}}),Pe=J({mutationFn:t=>Q.selectArchiveTimelapse(e.id,t),onSuccess:e=>{p.invalidateQueries({queryKey:[`archives`]}),m(d(`archives.toast.timelapseAttached`,{filename:e.filename})),R(!1),B([])},onError:e=>{m(e.message||d(`archives.toast.failedAttachTimelapse`),`error`)}}),Fe=J({mutationFn:t=>Q.deleteArchive(e.id,t),onSuccess:()=>{p.invalidateQueries({queryKey:[`archives`]}),m(d(`archives.toast.archiveDeleted`))},onError:()=>{m(d(`archives.toast.failedDeleteArchive`),`error`)}}),Ie=J({mutationFn:()=>Q.toggleFavorite(e.id),onSuccess:e=>{p.invalidateQueries({queryKey:[`archives`]}),m(e.is_favorite?d(`archives.toast.addedToFavorites`):d(`archives.toast.removedFromFavorites`))}}),{data:Le}=q({queryKey:[`archive-folders`,e.id],queryFn:()=>Q.getLibraryFoldersByArchive(e.id)}),Re=J({mutationFn:t=>Q.updateArchive(e.id,{project_id:t}),onSuccess:()=>{p.invalidateQueries({queryKey:[`archives`]}),p.invalidateQueries({queryKey:[`projects`]}),m(d(`archives.toast.projectUpdated`))},onError:()=>{m(d(`archives.toast.failedUpdateProject`),`error`)}}),ze=e=>{e.preventDefault(),ue({x:e.clientX,y:e.clientY})},Be=[...a2(e)?[{label:d(`common.print`),icon:(0,K.jsx)(Ol,{className:`w-4 h-4`}),onClick:()=>x(!0),disabled:!e.file_path||!h(`queue:create`)||!g(`archives`,`reprint`,e.created_by_id),title:e.file_path?h(`queue:create`)?g(`archives`,`reprint`,e.created_by_id)?void 0:d(`archives.permission.noReprint`):d(`archives.permission.noAddToQueue`):d(`archives.card.noFileForReprint`)},{label:d(`archives.menu.openInBambuStudio`),icon:(0,K.jsx)(Js,{className:`w-4 h-4`}),onClick:()=>{let t=e.print_name||e.filename||`model`;o2(e.id,t,`file`,c)},disabled:!e.file_path,title:e.file_path?void 0:d(`archives.card.noFileForReprint`)}]:[{label:d(`archives.menu.slice`),icon:l?(0,K.jsx)(ks,{className:`w-4 h-4`}):(0,K.jsx)(Js,{className:`w-4 h-4`}),onClick:()=>{if(l)C(!0);else{let t=e.print_name||e.filename||`model`;o2(e.id,t,`file`,c)}}},...l?[{label:d(`library.runWithPipeline.actionLabel`),icon:(0,K.jsx)(Cl,{className:`w-4 h-4`}),onClick:()=>T(!0),disabled:!h(`pipelines:run`),title:h(`pipelines:run`)?void 0:d(`library.runWithPipeline.noPermission`)}]:[]],{label:e.external_url?d(`archives.menu.externalLink`):d(`archives.menu.viewOnMakerWorld`),icon:(0,K.jsx)(bc,{className:`w-4 h-4`}),onClick:()=>{let t=e.external_url||e.makerworld_url;t&&window.open(t,`_blank`)},disabled:!e.external_url&&!e.makerworld_url},{label:``,divider:!0,onClick:()=>{}},{label:d(`archives.menu.preview3d`),icon:(0,K.jsx)(Wo,{className:`w-4 h-4`}),onClick:()=>{Ee()}},{label:d(`archives.menu.viewTimelapse`),icon:(0,K.jsx)(ic,{className:`w-4 h-4`}),onClick:()=>I(!0),disabled:!e.timelapse_path},{label:d(`archives.menu.scanForTimelapse`),icon:(0,K.jsx)(zl,{className:`w-4 h-4`}),onClick:()=>Ne.mutate(),disabled:!e.printer_id||!!e.timelapse_path||Ne.isPending||!g(`archives`,`update`,e.created_by_id),title:g(`archives`,`update`,e.created_by_id)?void 0:d(`archives.permission.noUpdateArchives`)},{label:d(`archives.menu.uploadTimelapse`),icon:(0,K.jsx)(Au,{className:`w-4 h-4`}),onClick:()=>ye.current?.click(),disabled:!!e.timelapse_path||!g(`archives`,`update`,e.created_by_id),title:g(`archives`,`update`,e.created_by_id)?void 0:d(`archives.permission.noUpdateArchives`)},...e.timelapse_path?[{label:d(`archives.menu.removeTimelapse`),icon:(0,K.jsx)(Cu,{className:`w-4 h-4`}),onClick:()=>ce(!0),danger:!0,disabled:!g(`archives`,`update`,e.created_by_id),title:g(`archives`,`update`,e.created_by_id)?void 0:d(`archives.permission.noUpdateArchives`)}]:[],{label:``,divider:!0,onClick:()=>{}},{label:e.source_3mf_path?d(`archives.menu.downloadSource3mf`):d(`archives.menu.uploadSource3mf`),icon:(0,K.jsx)($s,{className:`w-4 h-4`}),onClick:()=>{e.source_3mf_path?Q.downloadSource3mf(e.id).catch(e=>{console.error(`Source 3MF download failed:`,e)}):_e.current?.click()},disabled:!e.source_3mf_path&&!g(`archives`,`update`,e.created_by_id),title:!e.source_3mf_path&&!g(`archives`,`update`,e.created_by_id)?d(`archives.permission.noUploadFiles`):void 0},...e.source_3mf_path?[{label:d(`archives.menu.replaceSource3mf`),icon:(0,K.jsx)(Au,{className:`w-4 h-4`}),onClick:()=>_e.current?.click(),disabled:!g(`archives`,`update`,e.created_by_id),title:g(`archives`,`update`,e.created_by_id)?void 0:d(`archives.permission.noUpdateArchives`)},{label:d(`archives.menu.removeSource3mf`),icon:(0,K.jsx)(Cu,{className:`w-4 h-4`}),onClick:()=>ae(!0),danger:!0,disabled:!g(`archives`,`update`,e.created_by_id),title:g(`archives`,`update`,e.created_by_id)?void 0:d(`archives.permission.noUpdateArchives`)}]:[],{label:e.f3d_path?d(`archives.menu.replaceF3d`):d(`archives.menu.uploadF3d`),icon:(0,K.jsx)(Wo,{className:`w-4 h-4`}),onClick:()=>ve.current?.click(),disabled:!g(`archives`,`update`,e.created_by_id),title:g(`archives`,`update`,e.created_by_id)?void 0:d(`archives.permission.noUpdateArchives`)},...e.f3d_path?[{label:d(`archives.menu.downloadF3d`),icon:(0,K.jsx)(Vs,{className:`w-4 h-4`}),onClick:()=>{Q.downloadF3d(e.id).catch(e=>{console.error(`F3D download failed:`,e)})}},{label:d(`archives.menu.removeF3d`),icon:(0,K.jsx)(Cu,{className:`w-4 h-4`}),onClick:()=>U(!0),danger:!0,disabled:!g(`archives`,`update`,e.created_by_id),title:g(`archives`,`update`,e.created_by_id)?void 0:d(`archives.permission.noUpdateArchives`)}]:[],{label:``,divider:!0,onClick:()=>{}},{label:d(`archives.menu.download`),icon:(0,K.jsx)(Vs,{className:`w-4 h-4`}),onClick:()=>{Q.downloadArchive(e.id,`${e.print_name||e.filename}.3mf`).catch(e=>{console.error(`Archive download failed:`,e)})},disabled:!h(`archives:read`),title:h(`archives:read`)?void 0:d(`archives.permission.noDownload`)},{label:d(`archives.menu.copyDownloadLink`),icon:(0,K.jsx)(Ms,{className:`w-4 h-4`}),onClick:()=>{let t=`${window.location.origin}${Q.getArchiveDownload(e.id)}`;navigator.clipboard.writeText(t).then(()=>{m(d(`archives.toast.linkCopied`))}).catch(()=>{m(d(`archives.toast.failedCopyLink`),`error`)})},disabled:!h(`archives:read`),title:h(`archives:read`)?void 0:d(`archives.permission.noCopyLink`)},{label:d(`archives.menu.qrCode`),icon:(0,K.jsx)(kl,{className:`w-4 h-4`}),onClick:()=>ee(!0)},{label:e.photos?.length?d(`archives.menu.viewPhotosCount`,{count:e.photos.length}):d(`archives.menu.viewPhotos`),icon:(0,K.jsx)(Zo,{className:`w-4 h-4`}),onClick:()=>ne(!0),disabled:!e.photos?.length},{label:d(`archives.menu.projectPage`),icon:(0,K.jsx)(nc,{className:`w-4 h-4`}),onClick:()=>ie(!0)},{label:``,divider:!0,onClick:()=>{}},{label:e.is_favorite?d(`archives.menu.removeFromFavorites`):d(`archives.menu.addToFavorites`),icon:(0,K.jsx)(uu,{className:`w-4 h-4 ${e.is_favorite?`fill-yellow-400 text-yellow-400`:``}`}),onClick:()=>Ie.mutate(),disabled:!g(`archives`,`update`,e.created_by_id),title:g(`archives`,`update`,e.created_by_id)?void 0:d(`archives.permission.noUpdateArchives`)},{label:d(`archives.menu.edit`),icon:(0,K.jsx)(xl,{className:`w-4 h-4`}),onClick:()=>M(!0),disabled:!g(`archives`,`update`,e.created_by_id),title:g(`archives`,`update`,e.created_by_id)?void 0:d(`archives.permission.noUpdateArchives`)},{label:d(`archives.menu.printLog`),icon:(0,K.jsx)(kc,{className:`w-4 h-4`}),onClick:()=>P(!0)},...e.project_id&&e.project_name?[{label:d(`archives.menu.goToProject`,{name:e.project_name}),icon:(0,K.jsx)(sc,{className:`w-4 h-4 text-bambu-green`}),onClick:()=>window.location.href=`/projects`}]:[],{label:d(`archives.menu.addToProject`),icon:(0,K.jsx)(sc,{className:`w-4 h-4`}),onClick:()=>{},disabled:!g(`archives`,`update`,e.created_by_id),title:g(`archives`,`update`,e.created_by_id)?void 0:d(`archives.permission.noUpdateArchives`),submenuSearchPlaceholder:(a?.filter(e=>e.status===`active`).length??0)>5?d(`archives.menu.searchProjects`):void 0,submenu:(()=>{let t=[];if(e.project_id&&t.push({label:d(`archives.menu.removeFromProject`),icon:(0,K.jsx)(Wu,{className:`w-4 h-4`}),onClick:()=>Re.mutate(null),disabled:!g(`archives`,`update`,e.created_by_id)}),!a)t.push({label:d(`archives.menu.loading`),icon:(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),onClick:()=>{},disabled:!0});else{let n=a.filter(e=>e.status===`active`).sort((e,t)=>e.name.localeCompare(t.name));n.length===0?t.push({label:d(`archives.menu.noProjectsAvailable`),icon:(0,K.jsx)(sc,{className:`w-4 h-4 opacity-50`}),onClick:()=>{},disabled:!0}):n.forEach(n=>{t.push({label:n.name,icon:(0,K.jsx)(`div`,{className:`w-3 h-3 rounded-full flex-shrink-0`,style:{backgroundColor:n.color||`#888`}}),onClick:()=>Re.mutate(n.id),disabled:e.project_id===n.id||!g(`archives`,`update`,e.created_by_id)})})}return t})()},{label:d(n?`archives.menu.deselect`:`archives.menu.select`),icon:n?(0,K.jsx)(su,{className:`w-4 h-4`}):(0,K.jsx)(lu,{className:`w-4 h-4`}),onClick:()=>r(e.id)},{label:``,divider:!0,onClick:()=>{}},{label:d(`archives.menu.delete`),icon:(0,K.jsx)(Cu,{className:`w-4 h-4`}),onClick:()=>D(!0),danger:!0,disabled:!g(`archives`,`delete`,e.created_by_id),title:g(`archives`,`delete`,e.created_by_id)?void 0:d(`archives.permission.noDelete`)}];return(0,K.jsxs)(Cd,{"data-archive-id":e.id,className:`relative flex flex-col group ${n?`ring-2 ring-bambu-green`:``} ${i?`cursor-pointer`:``}`,style:o?{outline:`4px solid #facc15`,outlineOffset:`2px`}:void 0,onContextMenu:ze,onClick:i?()=>r(e.id):void 0,children:[i&&(0,K.jsx)(`button`,{className:`absolute top-2 left-2 z-10 p-1 rounded bg-black/50 hover:bg-black/70 transition-colors`,onClick:t=>{t.stopPropagation(),r(e.id)},children:n?(0,K.jsx)(su,{className:`w-5 h-5 text-bambu-green`}):(0,K.jsx)(lu,{className:`w-5 h-5 text-white`})}),(0,K.jsxs)(`div`,{className:`aspect-video bg-bambu-dark relative flex-shrink-0 overflow-hidden rounded-t-xl`,onMouseEnter:()=>me(!0),onMouseLeave:()=>me(!1),children:[e.thumbnail_path?(0,K.jsx)(`img`,{src:de!==null&&Ce.length>0?Q.getArchivePlateThumbnail(e.id,Ce[Te]?.index??0):Q.getArchiveThumbnail(e.id),alt:e.print_name||e.filename,className:`w-full h-full object-cover`}):(0,K.jsx)(`div`,{className:`w-full h-full flex items-center justify-center`,children:(0,K.jsx)(Mc,{className:`w-12 h-12 text-bambu-dark-tertiary`})}),we&&Ce.length>1&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`button`,{className:`absolute left-1 top-1/2 -translate-y-1/2 p-1 rounded-full bg-black/60 hover:bg-black/80 transition-all ${_?`opacity-100`:`opacity-0 group-hover:opacity-100`}`,onClick:e=>{e.stopPropagation(),fe(e=>{let t=e??0;return t>0?t-1:Ce.length-1})},title:d(`archives.card.previousPlate`),children:(0,K.jsx)(as,{className:`w-4 h-4 text-white`})}),(0,K.jsx)(`button`,{className:`absolute right-1 top-1/2 -translate-y-1/2 p-1 rounded-full bg-black/60 hover:bg-black/80 transition-all ${_?`opacity-100`:`opacity-0 group-hover:opacity-100`}`,onClick:e=>{e.stopPropagation(),fe(e=>{let t=e??0;return t(0,K.jsx)(`button`,{className:`w-2 h-2 rounded-full transition-colors ${t===Te?`bg-bambu-green`:`bg-white/50 hover:bg-white/80`}`,onClick:e=>{e.stopPropagation(),fe(t)},title:e.name||d(`archives.card.plateNumber`,{index:e.index})},e.index))})]}),(0,K.jsx)(`button`,{className:`absolute top-2 left-2 p-1.5 rounded bg-black/50 hover:bg-black/70 transition-all ${_?`opacity-100`:`opacity-0 group-hover:opacity-100`} ${i?`left-10`:``}`,onClick:e=>{e.stopPropagation();let t=e.currentTarget.getBoundingClientRect();ue({x:t.left,y:t.bottom+4})},title:d(`archives.card.moreOptions`),children:(0,K.jsx)(Ws,{className:`w-5 h-5 text-white`})}),(0,K.jsx)(`button`,{className:`absolute top-2 right-2 p-1 rounded transition-colors ${g(`archives`,`update`,e.created_by_id)?`bg-black/50 hover:bg-black/70`:`bg-black/30 cursor-not-allowed`}`,onClick:t=>{t.stopPropagation(),g(`archives`,`update`,e.created_by_id)&&Ie.mutate()},disabled:!g(`archives`,`update`,e.created_by_id),title:g(`archives`,`update`,e.created_by_id)?e.is_favorite?d(`archives.card.removeFromFavorites`):d(`archives.card.addToFavorites`):d(`archives.permission.noUpdateArchives`),children:(0,K.jsx)(uu,{className:`w-5 h-5 ${e.is_favorite?`text-yellow-400 fill-yellow-400`:`text-white`} ${g(`archives`,`update`,e.created_by_id)?``:`opacity-50`}`})}),(e.status===`failed`||e.status===`aborted`)&&(0,K.jsx)(`div`,{className:`absolute top-2 left-12 px-2 py-1 rounded text-xs bg-status-error/80 text-white`,children:e.status===`aborted`?d(`archives.card.cancelled`):d(`archives.card.failed`)}),e.duplicate_count>0&&xe>0&&Se&&(0,K.jsxs)(`button`,{onClick:e=>{e.stopPropagation(),f?.(Se)},className:`absolute top-2 right-12 px-2 py-1 rounded text-xs bg-purple-500/80 hover:bg-purple-600/90 text-white flex items-center gap-1 transition-colors cursor-pointer`,title:d(`archives.viewOriginalPrint`,{id:Se}),children:[(0,K.jsx)(Ms,{className:`w-3 h-3`}),`#`,xe]}),e.duplicate_count>0&&xe===0&&(0,K.jsxs)(`span`,{className:`absolute top-2 right-12 px-2 py-1 rounded text-xs bg-purple-500/80 text-white flex items-center gap-1`,title:`${e.duplicate_count} reprint${e.duplicate_count===1?``:`s`}`,children:[(0,K.jsx)(_c,{className:`w-3 h-3`}),`+`,e.duplicate_count]}),e.source_3mf_path&&(0,K.jsx)(`button`,{className:`absolute bottom-2 left-2 p-1.5 rounded bg-black/60 hover:bg-black/80 transition-colors`,onClick:t=>{t.stopPropagation();let n=(e.print_name||e.filename||`source`).replace(/\.gcode\.3mf$/i,``)+`_source`;o2(e.id,n,`source`,c)},title:d(`archives.card.openSource3mf`),children:(0,K.jsx)($s,{className:`w-4 h-4 text-orange-400`})}),e.f3d_path&&(0,K.jsx)(`button`,{className:`absolute bottom-2 ${e.source_3mf_path?`left-12`:`left-2`} p-1.5 rounded bg-black/60 hover:bg-black/80 transition-colors`,onClick:t=>{t.stopPropagation(),Q.downloadF3d(e.id).catch(e=>{console.error(`F3D download failed:`,e)})},title:d(`archives.card.downloadF3d`),children:(0,K.jsx)(Wo,{className:`w-4 h-4 text-cyan-400`})}),(0,K.jsx)(`button`,{className:`absolute bottom-2 right-2 p-1.5 rounded bg-black/60 hover:bg-black/80 transition-colors`,onClick:e=>{e.stopPropagation(),Ee()},title:d(`archives.card.preview3d`),children:(0,K.jsx)(Rc,{className:`w-4 h-4 text-white`})}),e.timelapse_path&&(0,K.jsx)(`button`,{className:`absolute bottom-2 right-12 p-1.5 rounded bg-black/60 hover:bg-black/80 transition-colors`,onClick:e=>{e.stopPropagation(),I(!0)},title:d(`archives.card.viewTimelapse`),children:(0,K.jsx)(ic,{className:`w-4 h-4 text-bambu-green`})}),e.photos&&e.photos.length>0&&(0,K.jsxs)(`button`,{className:`absolute bottom-2 ${e.timelapse_path?`right-[5.5rem]`:`right-12`} p-1.5 rounded bg-black/60 hover:bg-black/80 transition-colors`,onClick:e=>{e.stopPropagation(),ne(!0)},title:e.photos.length===1?d(`archives.card.viewPhoto`):d(`archives.card.viewPhotos`,{count:e.photos.length}),children:[(0,K.jsx)(Zo,{className:`w-4 h-4 text-blue-400`}),e.photos.length>1&&(0,K.jsx)(`span`,{className:`absolute -top-1 -right-1 w-4 h-4 bg-blue-500 rounded-full text-[10px] text-white flex items-center justify-center`,children:e.photos.length})]}),Le&&Le.length>0&&(0,K.jsx)(wi,{to:`/files?folder=${Le[0].id}`,className:`absolute bottom-2 p-1.5 rounded bg-black/60 hover:bg-black/80 transition-colors`,onClick:e=>e.stopPropagation(),title:d(`archives.card.openFolder`,{name:Le[0].name}),style:{left:e.source_3mf_path?e.f3d_path?`5.5rem`:`3rem`:e.f3d_path?`3rem`:`0.5rem`},children:(0,K.jsx)(cc,{className:`w-4 h-4 text-yellow-400`})})]}),(0,K.jsxs)(Td,{className:`p-4 flex-1 flex flex-col`,children:[(0,K.jsxs)(`p`,{className:`text-[10px] text-bambu-gray/70 mb-1`,children:[`#`,e.id]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between gap-2 mb-1`,children:[(0,K.jsxs)(`h3`,{className:`min-w-0 font-medium text-white truncate`,children:[e.print_name||e.filename,e.plate_id!=null&&` — ${d(`printers.plateNumber`,{number:e.plate_id})}`]}),(0,K.jsx)($,{variant:`ghost`,size:`sm`,className:`p-1 sm:p-1.5 shrink-0`,onClick:()=>M(!0),disabled:!g(`archives`,`update`,e.created_by_id),title:g(`archives`,`update`,e.created_by_id)?d(`archives.card.edit`):d(`archives.card.noPermissionEdit`),children:(0,K.jsx)(xl,{className:`w-3 h-3 sm:w-4 sm:h-4`})})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-3 flex-wrap`,children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:t}),(()=>{let t=iW(e.bed_type);return t?(0,K.jsx)(`img`,{src:t.icon,alt:t.label,title:t.label,className:`w-4 h-4 flex-shrink-0`}):null})(),(0,K.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded font-medium ${a2(e)?`bg-bambu-green/20 text-bambu-green`:`bg-orange-100 dark:bg-orange-500/20 text-orange-700 dark:text-orange-400`}`,title:a2(e)?d(`archives.card.slicedFile`):d(`archives.card.sourceFile`),children:a2(e)?d(`archives.card.gcode`):d(`archives.card.source`)}),e.content_hash&&(0,K.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded font-mono bg-bambu-dark-tertiary/50 text-bambu-gray-light opacity-0 transition-opacity duration-150 group-hover:opacity-100`,title:`SHA256: ${e.content_hash}`,children:e.content_hash.slice(0,8).toUpperCase()}),e.project_name&&(0,K.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded-full truncate max-w-[120px]`,style:{backgroundColor:`${a?.find(t=>t.id===e.project_id)?.color||`#6b7280`}20`,color:a?.find(t=>t.id===e.project_id)?.color||`#6b7280`},title:d(`archives.card.project`,{name:e.project_name}),children:e.project_name}),e.run_count>1&&(0,K.jsx)(`button`,{className:`text-[10px] px-1.5 py-0.5 rounded font-medium bg-bambu-orange/20 text-bambu-orange hover:bg-bambu-orange/30 transition-colors cursor-pointer`,onClick:e=>{e.stopPropagation(),P(!0)},title:d(`archives.card.runsBadgeTitle`,{count:e.run_count,successful:e.successful_run_count,failed:e.failed_run_count}),children:d(`archives.card.runsBadge`,{count:e.run_count})})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-2 text-xs mb-4 min-h-[48px]`,children:[(e.print_time_seconds||e.actual_time_seconds)&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 text-bambu-gray`,title:e.time_accuracy?`Estimated: ${Ff(e.print_time_seconds||0)}\nActual: ${Ff(e.actual_time_seconds||0)}\nAccuracy: ${e.time_accuracy.toFixed(0)}%`:e.actual_time_seconds?`Actual: ${Ff(e.actual_time_seconds)}`:`Estimated: ${Ff(e.print_time_seconds||0)}`,children:[(0,K.jsx)(xs,{className:`w-3 h-3`}),Ff(e.actual_time_seconds||e.print_time_seconds||0),e.time_accuracy&&(0,K.jsxs)(`span`,{className:`text-[10px] px-1 rounded ${e.time_accuracy>=95&&e.time_accuracy<=105?`bg-bambu-green/20 text-bambu-green`:e.time_accuracy>105?`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`:`bg-orange-100 dark:bg-orange-500/20 text-orange-700 dark:text-orange-400`}`,children:[e.time_accuracy>100?`+`:``,(e.time_accuracy-100).toFixed(0),`%`]})]}),e.filament_used_grams&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 text-bambu-gray`,children:[(0,K.jsx)(ml,{className:`w-3 h-3`}),e.filament_used_grams.toFixed(1),`g`]}),(e.cost!=null||e.energy_cost!=null)&&(0,K.jsxs)(`div`,{className:`flex items-center gap-3 text-bambu-gray`,children:[e.cost!=null&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,K.jsx)(Os,{className:`w-3 h-3`}),u,e.cost.toFixed(2)]}),e.energy_cost!=null&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5`,title:`${d(`stats.energyUsed`)}: ${e.energy_kwh?.toFixed(3)||`N/A`} kWh`,children:[(0,K.jsx)(Ku,{className:`w-3 h-3`}),u,e.energy_cost.toFixed(2)]})]}),(e.layer_height||e.total_layers)&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 text-bambu-gray`,children:[(0,K.jsx)(Rc,{className:`w-3 h-3`}),e.total_layers&&(0,K.jsx)(`span`,{children:e.total_layers===1?d(`archives.card.layer`,{count:e.total_layers}):d(`archives.card.layers`,{count:e.total_layers})}),e.total_layers&&e.layer_height&&(0,K.jsx)(`span`,{className:`text-bambu-gray/50`,children:`·`}),e.layer_height&&(0,K.jsxs)(`span`,{children:[e.layer_height,`mm`]})]}),e.object_count!=null&&e.object_count>0&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 text-bambu-gray`,title:e.object_count===1?d(`archives.card.object`,{count:e.object_count}):d(`archives.card.objects`,{count:e.object_count}),children:[(0,K.jsx)(Wo,{className:`w-3 h-3`}),e.object_count===1?d(`archives.card.object`,{count:e.object_count}):d(`archives.card.objects`,{count:e.object_count})]}),e.sliced_for_model&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 text-bambu-gray`,title:d(`archives.card.slicedFor`,{model:e.sliced_for_model}),children:[(0,K.jsx)(Ol,{className:`w-3 h-3`}),e.sliced_for_model]}),e.filament_type&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 col-span-2`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray text-xs`,children:e.filament_type}),e.filament_color&&(0,K.jsx)(`div`,{className:`flex items-center gap-0.5 flex-wrap`,children:e.filament_color.split(`,`).map((e,t)=>(0,K.jsx)(`div`,{className:`w-3 h-3 rounded-full border border-black/20`,style:{backgroundColor:e},title:e},t))})]})]}),(e.tags||e.notes)&&(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5 mb-3`,children:[e.notes&&(0,K.jsx)(`div`,{className:`flex items-center gap-1 px-1.5 py-0.5 bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400 rounded text-xs`,title:e.notes,children:(0,K.jsx)(fu,{className:`w-3 h-3`})}),e.tags?.split(`,`).map((e,t)=>(0,K.jsx)(`span`,{className:`px-1.5 py-0.5 bg-bambu-dark-tertiary text-bambu-gray-light rounded text-xs`,children:e.trim()},t))]}),(0,K.jsx)(`div`,{className:`flex-1`}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between text-xs text-bambu-gray border-t border-bambu-dark-tertiary pt-3`,children:[(0,K.jsx)(`span`,{children:Mf(e.created_at,s)}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.created_by_username&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1`,title:d(`archives.card.uploadedBy`,{name:e.created_by_username}),children:[(0,K.jsx)(ju,{className:`w-3 h-3`}),e.created_by_username]}),(0,K.jsx)(`span`,{children:kd(e.file_size)})]})]}),(0,K.jsxs)(`div`,{className:`flex gap-1 mt-3`,children:[a2(e)?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)($,{variant:`primary`,size:`sm`,className:`flex-1 min-w-0 overflow-hidden`,onClick:()=>x(!0),disabled:!e.file_path||!h(`queue:create`)||!g(`archives`,`reprint`,e.created_by_id),title:e.file_path?h(`queue:create`)?g(`archives`,`reprint`,e.created_by_id)?void 0:d(`archives.card.noPermissionReprint`):d(`archives.permission.noAddToQueue`):d(`archives.card.noFileForReprint`),children:[(0,K.jsx)(Ol,{className:`w-3 h-3 flex-shrink-0`}),(0,K.jsx)(`span`,{className:`hidden xl:inline truncate`,children:d(`common.print`)})]}),(0,K.jsx)($,{variant:`secondary`,size:`sm`,className:`min-w-0 p-1 sm:p-1.5`,onClick:()=>{let t=e.print_name||e.filename||`model`;o2(e.id,t,`file`,c)},title:d(`archives.card.openInBambuStudio`),children:(0,K.jsx)(Js,{className:`w-3 h-3 sm:w-4 sm:h-4`})})]}):(0,K.jsxs)($,{variant:`primary`,size:`sm`,className:`flex-1 min-w-0 overflow-hidden`,onClick:()=>{if(l)C(!0);else{let t=e.print_name||e.filename||`model`;o2(e.id,t,`file`,c)}},title:d(l?`slice.title`:`archives.card.openInBambuStudioToSlice`),children:[l?(0,K.jsx)(ks,{className:`w-3 h-3 flex-shrink-0`}):(0,K.jsx)(Js,{className:`w-3 h-3 flex-shrink-0`}),(0,K.jsx)(`span`,{className:`hidden xl:inline truncate`,children:d(`archives.card.slice`)})]}),(0,K.jsx)($,{variant:`secondary`,size:`sm`,className:`min-w-0 p-1 sm:p-1.5`,onClick:()=>{let t=e.external_url||e.makerworld_url;t&&window.open(t,`_blank`)},disabled:!e.external_url&&!e.makerworld_url,title:e.external_url?d(`archives.card.externalLink`):e.makerworld_url?d(`archives.card.makerWorld`,{designer:e.designer||d(`archives.card.viewProject`)}):d(`archives.card.noExternalLink`),children:(0,K.jsx)(bc,{className:`w-3 h-3 sm:w-4 sm:h-4 ${!e.external_url&&!e.makerworld_url?`opacity-20`:``}`})}),(0,K.jsx)($,{variant:`secondary`,size:`sm`,className:`min-w-0 p-1 sm:p-1.5`,onClick:()=>{Q.downloadArchive(e.id,`${e.print_name||e.filename}.3mf`).catch(e=>{console.error(`Archive download failed:`,e)})},title:d(`archives.card.download`),children:(0,K.jsx)(Vs,{className:`w-3 h-3 sm:w-4 sm:h-4`})}),(0,K.jsx)($,{variant:`ghost`,size:`sm`,className:`min-w-0 p-1 sm:p-1.5`,onClick:()=>D(!0),disabled:!g(`archives`,`delete`,e.created_by_id),title:g(`archives`,`delete`,e.created_by_id)?d(`archives.card.delete`):d(`archives.card.noPermissionDelete`),children:(0,K.jsx)(Cu,{className:`w-3 h-3 sm:w-4 sm:h-4 text-red-600 dark:text-red-400`})})]})]}),j&&(0,K.jsx)($W,{archive:e,onClose:()=>M(!1)}),N&&(0,K.jsx)(eG,{archiveId:e.id,archiveName:e.print_name||e.filename,onClose:()=>P(!1)}),he&&(0,K.jsx)(RW,{plates:he,onSelect:t=>{ge(null),v(`/gcode-viewer?archive=${e.id}&plate=${t}`)},onClose:()=>ge(null)}),b&&(0,K.jsx)(uW,{mode:`create`,archiveId:e.id,archiveName:e.print_name||e.filename,onClose:()=>x(!1)}),S&&(0,K.jsx)(UW,{source:{kind:`archive`,id:e.id,filename:e.print_name||e.filename||`model`},onClose:()=>C(!1)}),w&&(0,K.jsx)(KW,{source:{kind:`archive`,id:e.id,filename:e.print_name||e.filename||`model`},onClose:()=>T(!1)}),E&&(0,K.jsxs)(Bd,{title:d(`archives.modal.deleteArchive`),message:d(`archives.modal.deleteConfirm`,{name:e.print_name||e.filename}),confirmText:d(`archives.modal.deleteButton`),variant:`danger`,confirmDisabled:(A.data?.currently_printing??0)>0,onConfirm:()=>{Fe.mutate(O),D(!1),k(!1)},onCancel:()=>{D(!1),k(!1)},children:[(A.data?.related_queue_items??0)>0&&(0,K.jsx)(`div`,{className:(A.data?.currently_printing??0)>0?`text-sm text-red-600 dark:text-red-400 mb-2`:`text-sm text-amber-600 dark:text-amber-400 mb-2`,children:(A.data?.currently_printing??0)>0?d(`archives.modal.deleteBlockedByPrinting`,{count:A.data.currently_printing}):d(`archives.modal.deleteQueueItemsWarning`,{count:A.data.related_queue_items})}),(0,K.jsxs)(`label`,{className:`flex items-start gap-2 cursor-pointer text-sm text-bambu-gray`,children:[(0,K.jsx)(`input`,{type:`checkbox`,className:`mt-0.5 accent-red-500`,checked:O,onChange:e=>k(e.target.checked)}),(0,K.jsx)(`span`,{children:d(`archives.modal.deletePurgeStats`)})]})]}),H&&(0,K.jsx)(Bd,{title:d(`archives.modal.removeSource3mf`),message:d(`archives.modal.removeSource3mfConfirm`,{name:e.print_name||e.filename}),confirmText:d(`archives.modal.removeButton`),variant:`danger`,onConfirm:()=>{Ae.mutate(),ae(!1)},onCancel:()=>ae(!1)}),oe&&(0,K.jsx)(Bd,{title:d(`archives.modal.removeF3d`),message:d(`archives.modal.removeF3dConfirm`,{name:e.print_name||e.filename}),confirmText:d(`archives.modal.removeButton`),variant:`danger`,onConfirm:()=>{Me.mutate(),U(!1)},onCancel:()=>U(!1)}),se&&(0,K.jsx)(Bd,{title:d(`archives.modal.removeTimelapse`),message:d(`archives.modal.removeTimelapseConfirm`,{name:e.print_name||e.filename}),confirmText:d(`archives.modal.removeButton`),variant:`danger`,onConfirm:()=>{De.mutate(),ce(!1)},onCancel:()=>ce(!1)}),le&&(0,K.jsx)(tG,{x:le.x,y:le.y,items:Be,onClose:()=>ue(null)}),F&&e.timelapse_path&&(0,K.jsx)(i2,{src:Q.getArchiveTimelapse(e.id),title:d(`archives.modal.timelapse`,{name:e.print_name||e.filename}),downloadFilename:`${e.print_name||e.filename}_timelapse.mp4`,archiveId:e.id,onClose:()=>I(!1),onEdit:()=>{p.invalidateQueries({queryKey:[`archives`]}),I(!1)}}),L&&z.length>0&&(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/80 flex items-center justify-center z-50 p-4`,children:(0,K.jsxs)(`div`,{className:`bg-card-dark rounded-lg max-w-lg w-full max-h-[80vh] flex flex-col`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-gray-700`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h3`,{className:`text-lg font-semibold text-white`,children:d(`archives.modal.selectTimelapse`)}),(0,K.jsx)(`p`,{className:`text-sm text-gray-400 mt-1`,children:d(`archives.modal.selectTimelapseDesc`)})]}),(0,K.jsx)(`button`,{onClick:()=>{R(!1),B([])},className:`text-gray-400 hover:text-white p-1`,children:(0,K.jsx)(Wu,{className:`w-5 h-5`})})]}),(0,K.jsx)(`div`,{className:`overflow-y-auto flex-1 p-2`,children:z.map(e=>(0,K.jsxs)(`button`,{onClick:()=>Pe.mutate(e.name),disabled:Pe.isPending,className:`w-full text-left p-3 rounded-lg hover:bg-gray-700 transition-colors flex items-center gap-3 disabled:opacity-50`,children:[(0,K.jsx)(ic,{className:`w-8 h-8 text-bambu-green flex-shrink-0`}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsx)(`p`,{className:`text-white font-medium truncate`,children:e.name}),(0,K.jsxs)(`p`,{className:`text-sm text-gray-400`,children:[kd(e.size),e.mtime&&` • ${Mf(e.mtime,s)}`]})]})]},e.name))}),(0,K.jsx)(`div`,{className:`p-4 border-t border-gray-700`,children:(0,K.jsx)($,{variant:`secondary`,onClick:()=>{R(!1),B([])},className:`w-full`,children:`Cancel`})})]})}),V&&(0,K.jsx)(nG,{archiveId:e.id,archiveName:e.print_name||e.filename,onClose:()=>ee(!1)}),te&&e.photos&&e.photos.length>0&&(0,K.jsx)(rG,{archiveId:e.id,archiveName:e.print_name||e.filename,photos:e.photos,onClose:()=>ne(!1),onDelete:async t=>{try{await Q.deleteArchivePhoto(e.id,t),p.invalidateQueries({queryKey:[`archives`]}),m(d(`archives.toast.photoDeleted`))}catch{m(d(`archives.toast.failedDeletePhoto`),`error`)}}}),re&&(0,K.jsx)(r2,{archiveId:e.id,archiveName:e.print_name||e.filename,onClose:()=>ie(!1)}),(0,K.jsx)(`input`,{ref:_e,type:`file`,accept:`.3mf`,className:`hidden`,onChange:e=>{let t=e.target.files?.[0];t&&ke.mutate(t),e.target.value=``}}),(0,K.jsx)(`input`,{ref:ve,type:`file`,accept:`.f3d`,className:`hidden`,onChange:e=>{let t=e.target.files?.[0];t&&je.mutate(t),e.target.value=``}}),(0,K.jsx)(`input`,{ref:ye,type:`file`,accept:`.mp4,.avi,.mkv`,className:`hidden`,onChange:e=>{let t=e.target.files?.[0];t&&Oe.mutate(t),e.target.value=``}})]})}function kze({archive:e,printerName:t,isSelected:n,onSelect:r,selectionMode:i,projects:a,isHighlighted:o,preferredSlicer:s=`bambu_studio`,useSlicerApi:c=!1,t:l,onNavigateToArchive:u}){let d=no(),{showToast:f}=jd(),{hasPermission:p,canModify:m}=_d(),[h,g]=(0,y.useState)(!1),[_,v]=(0,y.useState)(!1),[b,x]=(0,y.useState)(!1),[S,C]=(0,y.useState)(!1),w=q({queryKey:[`archive`,e.id,`delete-impact`],queryFn:()=>Q.getArchiveDeleteImpact(e.id),enabled:b,staleTime:0}),T=$n(),[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)(!1),[I,L]=(0,y.useState)([]),[R,z]=(0,y.useState)(!1),[B,V]=(0,y.useState)(!1),[ee,te]=(0,y.useState)(!1),[ne,re]=(0,y.useState)(!1),[ie,H]=(0,y.useState)(!1),[ae,oe]=(0,y.useState)(!1),[U,se]=(0,y.useState)(null),ce=(0,y.useRef)(null),le=(0,y.useRef)(null),ue=(0,y.useRef)(null),[de,fe]=(0,y.useState)(null),pe=e.duplicate_sequence??0,me=e.original_archive_id??null,he=async()=>{try{let t=await Q.getArchivePlates(e.id);if(t.is_multi_plate&&t.plates.length>1){fe(t.plates);return}}catch{}T(`/gcode-viewer?archive=${e.id}`)},ge=J({mutationFn:()=>Q.deleteArchiveTimelapse(e.id),onSuccess:()=>{d.invalidateQueries({queryKey:[`archives`]}),f(l(`archives.toast.timelapseRemoved`))},onError:e=>{f(e.message||l(`archives.toast.failedRemoveTimelapse`),`error`)}}),_e=J({mutationFn:t=>Q.uploadArchiveTimelapse(e.id,t),onSuccess:e=>{d.invalidateQueries({queryKey:[`archives`]}),f(l(`archives.toast.timelapseUploaded`,{filename:e.filename}))},onError:e=>{f(e.message||l(`archives.toast.failedUploadTimelapse`),`error`)}}),ve=J({mutationFn:t=>Q.uploadSource3mf(e.id,t),onSuccess:e=>{d.invalidateQueries({queryKey:[`archives`]}),f(l(`archives.toast.source3mfAttached`,{filename:e.filename}))},onError:e=>{f(e.message||l(`archives.toast.failedUploadSource3mf`),`error`)}}),ye=J({mutationFn:()=>Q.deleteSource3mf(e.id),onSuccess:()=>{d.invalidateQueries({queryKey:[`archives`]}),f(l(`archives.toast.source3mfRemoved`))},onError:e=>{f(e.message||l(`archives.toast.failedRemoveSource3mf`),`error`)}}),be=J({mutationFn:t=>Q.uploadF3d(e.id,t),onSuccess:e=>{d.invalidateQueries({queryKey:[`archives`]}),f(l(`archives.toast.f3dAttached`,{filename:e.filename}))},onError:e=>{f(e.message||l(`archives.toast.failedUploadF3d`),`error`)}}),xe=J({mutationFn:()=>Q.deleteF3d(e.id),onSuccess:()=>{d.invalidateQueries({queryKey:[`archives`]}),f(l(`archives.toast.f3dRemoved`))},onError:e=>{f(e.message||l(`archives.toast.failedRemoveF3d`),`error`)}}),Se=J({mutationFn:()=>Q.scanArchiveTimelapse(e.id),onSuccess:e=>{e.status===`attached`?(d.invalidateQueries({queryKey:[`archives`]}),f(l(`archives.toast.timelapseAttached`,{filename:e.filename}))):e.status===`exists`?f(l(`archives.toast.timelapseAlreadyAttached`)):e.status===`not_found`&&e.available_files&&e.available_files.length>0?(L(e.available_files),F(!0)):f(e.message||l(`archives.toast.noMatchingTimelapse`),`warning`)},onError:e=>{f(e.message||l(`archives.toast.failedScanTimelapse`),`error`)}}),Ce=J({mutationFn:t=>Q.selectArchiveTimelapse(e.id,t),onSuccess:e=>{d.invalidateQueries({queryKey:[`archives`]}),f(l(`archives.toast.timelapseAttached`,{filename:e.filename})),F(!1),L([])},onError:e=>{f(e.message||l(`archives.toast.failedAttachTimelapse`),`error`)}}),we=J({mutationFn:t=>Q.deleteArchive(e.id,t),onSuccess:()=>{d.invalidateQueries({queryKey:[`archives`]}),f(l(`archives.toast.archiveDeleted`))},onError:()=>{f(l(`archives.toast.failedDeleteArchive`),`error`)}}),Te=J({mutationFn:()=>Q.toggleFavorite(e.id),onSuccess:e=>{d.invalidateQueries({queryKey:[`archives`]}),f(e.is_favorite?l(`archives.toast.addedToFavorites`):l(`archives.toast.removedFromFavorites`))}}),{data:Ee}=q({queryKey:[`archive-folders`,e.id],queryFn:()=>Q.getLibraryFoldersByArchive(e.id)}),De=J({mutationFn:t=>Q.updateArchive(e.id,{project_id:t}),onSuccess:()=>{d.invalidateQueries({queryKey:[`archives`]}),d.invalidateQueries({queryKey:[`projects`]}),f(l(`archives.toast.projectUpdated`))},onError:()=>{f(l(`archives.toast.failedUpdateProject`),`error`)}}),Oe=e=>{e.preventDefault(),se({x:e.clientX,y:e.clientY})},ke=[...a2(e)?[{label:l(`common.print`),icon:(0,K.jsx)(Ol,{className:`w-4 h-4`}),onClick:()=>D(!0),disabled:!e.file_path||!p(`queue:create`)||!m(`archives`,`reprint`,e.created_by_id),title:e.file_path?p(`queue:create`)?m(`archives`,`reprint`,e.created_by_id)?void 0:l(`archives.permission.noReprint`):l(`archives.permission.noAddToQueue`):l(`archives.card.noFileForReprint`)},{label:l(`archives.menu.openInBambuStudio`),icon:(0,K.jsx)(Js,{className:`w-4 h-4`}),onClick:()=>{let t=e.print_name||e.filename||`model`;o2(e.id,t,`file`,s)},disabled:!e.file_path,title:e.file_path?void 0:l(`archives.card.noFileForReprint`)}]:[{label:l(`archives.menu.slice`),icon:c?(0,K.jsx)(ks,{className:`w-4 h-4`}):(0,K.jsx)(Js,{className:`w-4 h-4`}),onClick:()=>{if(c)k(!0);else{let t=e.print_name||e.filename||`model`;o2(e.id,t,`file`,s)}}},...c?[{label:l(`library.runWithPipeline.actionLabel`),icon:(0,K.jsx)(Cl,{className:`w-4 h-4`}),onClick:()=>j(!0),disabled:!p(`pipelines:run`),title:p(`pipelines:run`)?void 0:l(`library.runWithPipeline.noPermission`)}]:[]],{label:e.external_url?l(`archives.menu.externalLink`):l(`archives.menu.viewOnMakerWorld`),icon:(0,K.jsx)(bc,{className:`w-4 h-4`}),onClick:()=>{let t=e.external_url||e.makerworld_url;t&&window.open(t,`_blank`)},disabled:!e.external_url&&!e.makerworld_url},{label:``,divider:!0,onClick:()=>{}},{label:l(`archives.menu.preview3d`),icon:(0,K.jsx)(Wo,{className:`w-4 h-4`}),onClick:()=>{he()}},{label:l(`archives.menu.viewTimelapse`),icon:(0,K.jsx)(ic,{className:`w-4 h-4`}),onClick:()=>N(!0),disabled:!e.timelapse_path},{label:l(`archives.menu.scanForTimelapse`),icon:(0,K.jsx)(zl,{className:`w-4 h-4`}),onClick:()=>Se.mutate(),disabled:!e.printer_id||!!e.timelapse_path||Se.isPending||!m(`archives`,`update`,e.created_by_id),title:m(`archives`,`update`,e.created_by_id)?void 0:l(`archives.permission.noUpdateArchives`)},{label:l(`archives.menu.uploadTimelapse`),icon:(0,K.jsx)(Au,{className:`w-4 h-4`}),onClick:()=>ue.current?.click(),disabled:!!e.timelapse_path||!m(`archives`,`update`,e.created_by_id),title:m(`archives`,`update`,e.created_by_id)?void 0:l(`archives.permission.noUpdateArchives`)},...e.timelapse_path?[{label:l(`archives.menu.removeTimelapse`),icon:(0,K.jsx)(Cu,{className:`w-4 h-4`}),onClick:()=>oe(!0),danger:!0,disabled:!m(`archives`,`update`,e.created_by_id),title:m(`archives`,`update`,e.created_by_id)?void 0:l(`archives.permission.noUpdateArchives`)}]:[],{label:``,divider:!0,onClick:()=>{}},{label:e.source_3mf_path?l(`archives.menu.downloadSource3mf`):l(`archives.menu.uploadSource3mf`),icon:(0,K.jsx)($s,{className:`w-4 h-4`}),onClick:()=>{e.source_3mf_path?Q.downloadSource3mf(e.id).catch(e=>{console.error(`Source 3MF download failed:`,e)}):ce.current?.click()},disabled:!e.source_3mf_path&&!m(`archives`,`update`,e.created_by_id),title:!e.source_3mf_path&&!m(`archives`,`update`,e.created_by_id)?l(`archives.permission.noUploadFiles`):void 0},...e.source_3mf_path?[{label:l(`archives.menu.replaceSource3mf`),icon:(0,K.jsx)(Au,{className:`w-4 h-4`}),onClick:()=>ce.current?.click(),disabled:!m(`archives`,`update`,e.created_by_id),title:m(`archives`,`update`,e.created_by_id)?void 0:l(`archives.permission.noUpdateArchives`)},{label:l(`archives.menu.removeSource3mf`),icon:(0,K.jsx)(Cu,{className:`w-4 h-4`}),onClick:()=>re(!0),danger:!0,disabled:!m(`archives`,`update`,e.created_by_id),title:m(`archives`,`update`,e.created_by_id)?void 0:l(`archives.permission.noUpdateArchives`)}]:[],{label:e.f3d_path?l(`archives.menu.replaceF3d`):l(`archives.menu.uploadF3d`),icon:(0,K.jsx)(Wo,{className:`w-4 h-4`}),onClick:()=>le.current?.click(),disabled:!m(`archives`,`update`,e.created_by_id),title:m(`archives`,`update`,e.created_by_id)?void 0:l(`archives.permission.noUpdateArchives`)},...e.f3d_path?[{label:l(`archives.menu.downloadF3d`),icon:(0,K.jsx)(Vs,{className:`w-4 h-4`}),onClick:()=>{Q.downloadF3d(e.id).catch(e=>{console.error(`F3D download failed:`,e)})}},{label:l(`archives.menu.removeF3d`),icon:(0,K.jsx)(Cu,{className:`w-4 h-4`}),onClick:()=>H(!0),danger:!0,disabled:!m(`archives`,`update`,e.created_by_id),title:m(`archives`,`update`,e.created_by_id)?void 0:l(`archives.permission.noUpdateArchives`)}]:[],{label:``,divider:!0,onClick:()=>{}},{label:l(`archives.menu.download`),icon:(0,K.jsx)(Vs,{className:`w-4 h-4`}),onClick:()=>{Q.downloadArchive(e.id,`${e.print_name||e.filename}.3mf`).catch(e=>{console.error(`Archive download failed:`,e)})},disabled:!p(`archives:read`),title:p(`archives:read`)?void 0:l(`archives.permission.noDownload`)},{label:l(`archives.menu.copyDownloadLink`),icon:(0,K.jsx)(Ms,{className:`w-4 h-4`}),onClick:()=>{let t=`${window.location.origin}${Q.getArchiveDownload(e.id)}`;navigator.clipboard.writeText(t).then(()=>{f(l(`archives.toast.linkCopied`))}).catch(()=>{f(l(`archives.toast.failedCopyLink`),`error`)})},disabled:!p(`archives:read`),title:p(`archives:read`)?void 0:l(`archives.permission.noCopyLink`)},{label:l(`archives.menu.qrCode`),icon:(0,K.jsx)(kl,{className:`w-4 h-4`}),onClick:()=>z(!0)},{label:e.photos?.length?l(`archives.menu.viewPhotosCount`,{count:e.photos.length}):l(`archives.menu.viewPhotos`),icon:(0,K.jsx)(Zo,{className:`w-4 h-4`}),onClick:()=>V(!0),disabled:!e.photos?.length},{label:l(`archives.menu.projectPage`),icon:(0,K.jsx)(nc,{className:`w-4 h-4`}),onClick:()=>te(!0)},{label:``,divider:!0,onClick:()=>{}},{label:e.is_favorite?l(`archives.menu.removeFromFavorites`):l(`archives.menu.addToFavorites`),icon:(0,K.jsx)(uu,{className:`w-4 h-4 ${e.is_favorite?`fill-yellow-400 text-yellow-400`:``}`}),onClick:()=>Te.mutate(),disabled:!m(`archives`,`update`,e.created_by_id),title:m(`archives`,`update`,e.created_by_id)?void 0:l(`archives.permission.noUpdateArchives`)},{label:l(`archives.menu.edit`),icon:(0,K.jsx)(xl,{className:`w-4 h-4`}),onClick:()=>g(!0),disabled:!m(`archives`,`update`,e.created_by_id),title:m(`archives`,`update`,e.created_by_id)?void 0:l(`archives.permission.noUpdateArchives`)},{label:l(`archives.menu.printLog`),icon:(0,K.jsx)(kc,{className:`w-4 h-4`}),onClick:()=>v(!0)},...e.project_id&&e.project_name?[{label:l(`archives.menu.goToProject`,{name:e.project_name}),icon:(0,K.jsx)(sc,{className:`w-4 h-4 text-bambu-green`}),onClick:()=>window.location.href=`/projects`}]:[],{label:l(`archives.menu.addToProject`),icon:(0,K.jsx)(sc,{className:`w-4 h-4`}),onClick:()=>{},submenuSearchPlaceholder:(a?.filter(e=>e.status===`active`).length??0)>5?l(`archives.menu.searchProjects`):void 0,submenu:(()=>{let t=[];if(e.project_id&&t.push({label:l(`archives.menu.removeFromProject`),icon:(0,K.jsx)(Wu,{className:`w-4 h-4`}),onClick:()=>De.mutate(null)}),!a)t.push({label:l(`archives.menu.loading`),icon:(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),onClick:()=>{},disabled:!0});else{let n=a.filter(e=>e.status===`active`).sort((e,t)=>e.name.localeCompare(t.name));n.length===0?t.push({label:l(`archives.menu.noProjectsAvailable`),icon:(0,K.jsx)(sc,{className:`w-4 h-4 opacity-50`}),onClick:()=>{},disabled:!0}):n.forEach(n=>{t.push({label:n.name,icon:(0,K.jsx)(`div`,{className:`w-3 h-3 rounded-full flex-shrink-0`,style:{backgroundColor:n.color||`#888`}}),onClick:()=>De.mutate(n.id),disabled:e.project_id===n.id})})}return t})()},{label:l(n?`archives.menu.deselect`:`archives.menu.select`),icon:n?(0,K.jsx)(su,{className:`w-4 h-4`}):(0,K.jsx)(lu,{className:`w-4 h-4`}),onClick:()=>r(e.id)},{label:``,divider:!0,onClick:()=>{}},{label:l(`archives.menu.delete`),icon:(0,K.jsx)(Cu,{className:`w-4 h-4`}),onClick:()=>x(!0),danger:!0,disabled:!m(`archives`,`delete`,e.created_by_id),title:m(`archives`,`delete`,e.created_by_id)?void 0:l(`archives.permission.noDelete`)}];return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{"data-archive-id":e.id,className:`grid grid-cols-12 gap-4 px-4 py-3 items-center hover:bg-bambu-dark-tertiary/30 ${n?`bg-bambu-green/10`:``}`,style:o?{outline:`4px solid #facc15`,outlineOffset:`-4px`}:void 0,onContextMenu:Oe,children:[(0,K.jsxs)(`div`,{className:`col-span-1 flex items-center gap-2`,children:[i&&(0,K.jsx)(`button`,{onClick:()=>r(e.id),children:n?(0,K.jsx)(su,{className:`w-4 h-4 text-bambu-green`}):(0,K.jsx)(lu,{className:`w-4 h-4 text-bambu-gray`})}),e.thumbnail_path?(0,K.jsx)(`img`,{src:Q.getArchiveThumbnail(e.id),alt:``,className:`w-10 h-10 object-cover rounded`}):(0,K.jsx)(`div`,{className:`w-10 h-10 bg-bambu-dark rounded flex items-center justify-center`,children:(0,K.jsx)(Mc,{className:`w-5 h-5 text-bambu-dark-tertiary`})})]}),(0,K.jsxs)(`div`,{className:`col-span-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`p`,{className:`text-white text-sm truncate`,children:e.print_name||e.filename}),(e.status===`failed`||e.status===`aborted`)&&(0,K.jsx)(`span`,{className:`px-1.5 py-0.5 rounded text-[10px] leading-tight bg-status-error/80 text-white flex-shrink-0`,children:e.status===`aborted`?l(`archives.card.cancelled`):l(`archives.card.failed`)}),e.duplicate_count>0&&pe>0&&me&&(0,K.jsxs)(`button`,{onClick:e=>{e.stopPropagation(),u?.(me)},className:`px-1.5 py-0.5 rounded text-[10px] leading-tight bg-purple-500/80 hover:bg-purple-600/90 text-white flex-shrink-0 transition-colors flex items-center gap-1`,title:l(`archives.viewOriginalPrint`,{id:me}),children:[(0,K.jsx)(Ms,{className:`w-3 h-3`}),`#`,pe]}),e.duplicate_count>0&&pe===0&&(0,K.jsxs)(`span`,{className:`px-1.5 py-0.5 rounded text-[10px] leading-tight bg-purple-500/80 text-white flex-shrink-0 flex items-center gap-1`,title:`${e.duplicate_count} reprint${e.duplicate_count===1?``:`s`}`,children:[(0,K.jsx)(_c,{className:`w-3 h-3`}),`+`,e.duplicate_count]}),e.timelapse_path&&(0,K.jsx)(`span`,{title:l(`archives.list.hasTimelapse`),children:(0,K.jsx)(ic,{className:`w-3.5 h-3.5 text-bambu-green flex-shrink-0`})}),Ee&&Ee.length>0&&(0,K.jsx)(wi,{to:`/files?folder=${Ee[0].id}`,className:`flex-shrink-0`,title:l(`archives.card.openFolder`,{name:Ee[0].name}),onClick:e=>e.stopPropagation(),children:(0,K.jsx)(cc,{className:`w-3.5 h-3.5 text-yellow-600 dark:text-yellow-400`})})]}),(e.filament_type||e.sliced_for_model)&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 mt-0.5`,children:[e.sliced_for_model&&(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray flex items-center gap-1`,title:l(`archives.card.slicedFor`,{model:e.sliced_for_model}),children:[(0,K.jsx)(Ol,{className:`w-2.5 h-2.5`}),e.sliced_for_model]}),(()=>{let t=iW(e.bed_type);return t?(0,K.jsx)(`img`,{src:t.icon,alt:t.label,title:t.label,className:`w-3.5 h-3.5 flex-shrink-0`}):null})(),e.sliced_for_model&&e.filament_type&&(0,K.jsx)(`span`,{className:`text-bambu-gray/50`,children:`·`}),e.filament_type&&(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:e.filament_type}),e.filament_color&&(0,K.jsx)(`div`,{className:`flex items-center gap-0.5 flex-wrap`,children:e.filament_color.split(`,`).map((e,t)=>(0,K.jsx)(`div`,{className:`w-2.5 h-2.5 rounded-full border border-black/20`,style:{backgroundColor:e},title:e},t))})]})]}),(0,K.jsx)(`div`,{className:`col-span-2 text-sm text-bambu-gray truncate`,children:t}),(0,K.jsxs)(`div`,{className:`col-span-2 text-sm text-bambu-gray`,children:[(0,K.jsx)(`div`,{children:jf(e.created_at)}),e.created_by_username&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1 text-xs opacity-75`,title:l(`archives.card.uploadedBy`,{name:e.created_by_username}),children:[(0,K.jsx)(ju,{className:`w-3 h-3`}),e.created_by_username]})]}),(0,K.jsx)(`div`,{className:`col-span-1 text-sm text-bambu-gray`,children:kd(e.file_size)}),(0,K.jsxs)(`div`,{className:`col-span-2 flex justify-end gap-1`,children:[a2(e)&&(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:()=>D(!0),disabled:!e.file_path||!p(`queue:create`)||!m(`archives`,`reprint`,e.created_by_id),title:e.file_path?p(`queue:create`)?m(`archives`,`reprint`,e.created_by_id)?l(`common.print`):l(`archives.card.noPermissionReprint`):l(`archives.permission.noAddToQueue`):l(`archives.card.noFileForReprint`),className:`text-bambu-green hover:text-bambu-green-light hover:bg-bambu-green/10`,children:(0,K.jsx)(Cl,{className:`w-4 h-4`})}),(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:()=>{let t=e.print_name||e.filename||`model`;o2(e.id,t,`file`,s)},title:l(`archives.card.openInBambuStudio`),children:(0,K.jsx)(Js,{className:`w-4 h-4`})}),(e.external_url||e.makerworld_url)&&(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:()=>window.open(e.external_url||e.makerworld_url,`_blank`),title:e.external_url?l(`archives.card.externalLink`):`MakerWorld`,children:(0,K.jsx)(bc,{className:`w-4 h-4`})}),(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:()=>{Q.downloadArchive(e.id,`${e.print_name||e.filename}.3mf`).catch(e=>{console.error(`Archive download failed:`,e)})},title:l(`archives.card.download`),children:(0,K.jsx)(Vs,{className:`w-4 h-4`})}),(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:()=>g(!0),disabled:!m(`archives`,`update`,e.created_by_id),title:m(`archives`,`update`,e.created_by_id)?l(`archives.card.edit`):l(`archives.card.noPermissionEdit`),children:(0,K.jsx)(xl,{className:`w-4 h-4`})}),(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:()=>x(!0),disabled:!m(`archives`,`delete`,e.created_by_id),title:m(`archives`,`delete`,e.created_by_id)?l(`archives.card.delete`):l(`archives.card.noPermissionDelete`),children:(0,K.jsx)(Cu,{className:`w-4 h-4 text-red-600 dark:text-red-400`})}),(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:e=>{let t=e.currentTarget.getBoundingClientRect();se({x:t.left,y:t.bottom+4})},title:l(`archives.card.moreOptions`),children:(0,K.jsx)(Ws,{className:`w-4 h-4`})})]})]}),h&&(0,K.jsx)($W,{archive:e,onClose:()=>g(!1)}),_&&(0,K.jsx)(eG,{archiveId:e.id,archiveName:e.print_name||e.filename,onClose:()=>v(!1)}),de&&(0,K.jsx)(RW,{plates:de,onSelect:t=>{fe(null),T(`/gcode-viewer?archive=${e.id}&plate=${t}`)},onClose:()=>fe(null)}),E&&(0,K.jsx)(uW,{mode:`create`,archiveId:e.id,archiveName:e.print_name||e.filename,onClose:()=>D(!1)}),O&&(0,K.jsx)(UW,{source:{kind:`archive`,id:e.id,filename:e.print_name||e.filename||`model`},onClose:()=>k(!1)}),A&&(0,K.jsx)(KW,{source:{kind:`archive`,id:e.id,filename:e.print_name||e.filename||`model`},onClose:()=>j(!1)}),b&&(0,K.jsxs)(Bd,{title:l(`archives.modal.deleteArchive`),message:l(`archives.modal.deleteConfirm`,{name:e.print_name||e.filename}),confirmText:l(`archives.modal.deleteButton`),variant:`danger`,confirmDisabled:(w.data?.currently_printing??0)>0,onConfirm:()=>{we.mutate(S),x(!1),C(!1)},onCancel:()=>{x(!1),C(!1)},children:[(w.data?.related_queue_items??0)>0&&(0,K.jsx)(`div`,{className:(w.data?.currently_printing??0)>0?`text-sm text-red-600 dark:text-red-400 mb-2`:`text-sm text-amber-600 dark:text-amber-400 mb-2`,children:(w.data?.currently_printing??0)>0?l(`archives.modal.deleteBlockedByPrinting`,{count:w.data.currently_printing}):l(`archives.modal.deleteQueueItemsWarning`,{count:w.data.related_queue_items})}),(0,K.jsxs)(`label`,{className:`flex items-start gap-2 cursor-pointer text-sm text-bambu-gray`,children:[(0,K.jsx)(`input`,{type:`checkbox`,className:`mt-0.5 accent-red-500`,checked:S,onChange:e=>C(e.target.checked)}),(0,K.jsx)(`span`,{children:l(`archives.modal.deletePurgeStats`)})]})]}),ne&&(0,K.jsx)(Bd,{title:l(`archives.modal.removeSource3mf`),message:l(`archives.modal.removeSource3mfConfirm`,{name:e.print_name||e.filename}),confirmText:l(`archives.modal.removeButton`),variant:`danger`,onConfirm:()=>{ye.mutate(),re(!1)},onCancel:()=>re(!1)}),ie&&(0,K.jsx)(Bd,{title:l(`archives.modal.removeF3d`),message:l(`archives.modal.removeF3dConfirm`,{name:e.print_name||e.filename}),confirmText:l(`archives.modal.removeButton`),variant:`danger`,onConfirm:()=>{xe.mutate(),H(!1)},onCancel:()=>H(!1)}),ae&&(0,K.jsx)(Bd,{title:l(`archives.modal.removeTimelapse`),message:l(`archives.modal.removeTimelapseConfirm`,{name:e.print_name||e.filename}),confirmText:l(`archives.modal.removeButton`),variant:`danger`,onConfirm:()=>{ge.mutate(),oe(!1)},onCancel:()=>oe(!1)}),U&&(0,K.jsx)(tG,{x:U.x,y:U.y,items:ke,onClose:()=>se(null)}),M&&e.timelapse_path&&(0,K.jsx)(i2,{src:Q.getArchiveTimelapse(e.id),title:l(`archives.modal.timelapse`,{name:e.print_name||e.filename}),downloadFilename:`${e.print_name||e.filename}_timelapse.mp4`,archiveId:e.id,onClose:()=>N(!1),onEdit:()=>{d.invalidateQueries({queryKey:[`archives`]}),N(!1)}}),P&&I.length>0&&(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/80 flex items-center justify-center z-50 p-4`,children:(0,K.jsxs)(`div`,{className:`bg-card-dark rounded-lg max-w-lg w-full max-h-[80vh] flex flex-col`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-gray-700`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h3`,{className:`text-lg font-semibold text-white`,children:l(`archives.modal.selectTimelapse`)}),(0,K.jsx)(`p`,{className:`text-sm text-gray-400 mt-1`,children:l(`archives.modal.selectTimelapseDesc`)})]}),(0,K.jsx)(`button`,{onClick:()=>{F(!1),L([])},className:`text-gray-400 hover:text-white p-1`,children:(0,K.jsx)(Wu,{className:`w-5 h-5`})})]}),(0,K.jsx)(`div`,{className:`overflow-y-auto flex-1 p-2`,children:I.map(e=>(0,K.jsxs)(`button`,{onClick:()=>Ce.mutate(e.name),disabled:Ce.isPending,className:`w-full text-left p-3 rounded-lg hover:bg-gray-700 transition-colors mb-1`,children:[(0,K.jsx)(`div`,{className:`font-medium text-white`,children:e.name}),(0,K.jsxs)(`div`,{className:`text-sm text-gray-400 flex gap-3`,children:[(0,K.jsx)(`span`,{children:kd(e.size)}),e.mtime&&(0,K.jsx)(`span`,{children:jf(e.mtime)})]})]},e.name))})]})}),R&&(0,K.jsx)(nG,{archiveId:e.id,archiveName:e.print_name||e.filename,onClose:()=>z(!1)}),B&&e.photos&&(0,K.jsx)(rG,{archiveId:e.id,archiveName:e.print_name||e.filename,photos:e.photos,onClose:()=>V(!1),onDelete:async t=>{try{await Q.deleteArchivePhoto(e.id,t),d.invalidateQueries({queryKey:[`archives`]}),f(l(`archives.toast.photoDeleted`))}catch{f(l(`archives.toast.failedDeletePhoto`),`error`)}}}),ee&&(0,K.jsx)(r2,{archiveId:e.id,archiveName:e.print_name||e.filename,onClose:()=>te(!1)}),(0,K.jsx)(`input`,{ref:ce,type:`file`,accept:`.3mf`,className:`hidden`,onChange:e=>{let t=e.target.files?.[0];t&&ve.mutate(t),e.target.value=``}}),(0,K.jsx)(`input`,{ref:le,type:`file`,accept:`.f3d`,className:`hidden`,onChange:e=>{let t=e.target.files?.[0];t&&be.mutate(t),e.target.value=``}}),(0,K.jsx)(`input`,{ref:ue,type:`file`,accept:`.mp4,.avi,.mkv`,className:`hidden`,onChange:e=>{let t=e.target.files?.[0];t&&_e.mutate(t),e.target.value=``}})]})}var Aze=[`completed`,`failed`,`aborted`,`cancelled`,`stopped`],jze=[{id:`all`,label:`All Archives`,icon:(0,K.jsx)(cc,{className:`w-4 h-4`})},{id:`recent`,label:`Last 24 Hours`,icon:(0,K.jsx)(xs,{className:`w-4 h-4`})},{id:`this-week`,label:`This Week`,icon:(0,K.jsx)(Xo,{className:`w-4 h-4`})},{id:`this-month`,label:`This Month`,icon:(0,K.jsx)(Xo,{className:`w-4 h-4`})},{id:`favorites`,label:`Favorites`,icon:(0,K.jsx)(uu,{className:`w-4 h-4`})},{id:`not-printed`,label:`Not Printed`,icon:(0,K.jsx)(Au,{className:`w-4 h-4`})},{id:`printed`,label:`Printed`,icon:(0,K.jsx)(Ol,{className:`w-4 h-4`})},{id:`failed`,label:`Failed Prints`,icon:(0,K.jsx)(us,{className:`w-4 h-4`})},{id:`duplicates`,label:`Duplicates`,icon:(0,K.jsx)(Ms,{className:`w-4 h-4`})}];function Mze(){let{t:e}=W(),t=no(),{showToast:n}=jd(),{hasPermission:r,hasAnyPermission:i}=_d(),a=(0,y.useRef)(null),[o,s]=(0,y.useState)(``),[c,l]=(0,y.useState)(()=>{let e=localStorage.getItem(`archiveFilterPrinter`);return e?Number(e):null}),[u,d]=(0,y.useState)(()=>localStorage.getItem(`archiveFilterMaterial`)),[f,p]=(0,y.useState)(()=>{let e=localStorage.getItem(`archiveFilterColors`);return e?new Set(JSON.parse(e)):new Set}),[m,h]=(0,y.useState)(()=>localStorage.getItem(`archiveColorFilterMode`)||`or`),[g,_]=(0,y.useState)(()=>localStorage.getItem(`archiveFilterFavorites`)===`true`),[v,b]=(0,y.useState)(()=>localStorage.getItem(`archiveHideFailed`)===`true`),[x,S]=(0,y.useState)(()=>localStorage.getItem(`archiveHideDuplicates`)===`true`),[C,w]=(0,y.useState)(()=>localStorage.getItem(`archiveFilterTag`)),[T,E]=(0,y.useState)(()=>localStorage.getItem(`archiveFilterFileType`)||`all`),[D,O]=(0,y.useState)(!1),[k,A]=(0,y.useState)([]),[j,M]=(0,y.useState)(new Set),[N,P]=(0,y.useState)(()=>localStorage.getItem(`archiveNo3MFWarningDismissed`)===`true`),{data:F}=q({queryKey:[`archives`,`no-3mf-warning`],queryFn:Q.getNo3MFWarning,staleTime:300*1e3,enabled:!N}),I=()=>{localStorage.setItem(`archiveNo3MFWarningDismissed`,`true`),P(!0)},[L,R]=(0,y.useState)(!1),[z,B]=(0,y.useState)(!1),[V,ee]=(0,y.useState)(!1),[te,ne]=(0,y.useState)(!1),[re,ie]=(0,y.useState)(()=>localStorage.getItem(`archiveViewMode`)||`grid`),[H,ae]=(0,y.useState)(()=>localStorage.getItem(`archiveSortBy`)||`date-desc`),[oe,U]=(0,y.useState)(()=>localStorage.getItem(`archiveCollection`)||`all`),[se,ce]=(0,y.useState)(0),[le,ue]=(0,y.useState)(()=>{try{let e=localStorage.getItem(`archivePageSize`);return e?Number(e):50}catch{return 50}}),[de,fe]=(0,y.useState)(!1),[pe,me]=(0,y.useState)(!1),[he,ge]=(0,y.useState)(!1),[_e,ve]=(0,y.useState)(!1),[ye,be]=(0,y.useState)(!1),[xe,Se]=(0,y.useState)(null),[Ce,we]=(0,y.useState)(null),[Te,Ee]=(0,y.useState)(()=>localStorage.getItem(`logFilterUser`)||null),[De,Oe]=(0,y.useState)(()=>localStorage.getItem(`logFilterStatus`)),[ke,Ae]=(0,y.useState)(()=>localStorage.getItem(`logFilterDateFrom`)||``),[je,Me]=(0,y.useState)(()=>localStorage.getItem(`logFilterDateTo`)||``),[Ne,Pe]=(0,y.useState)(()=>{let e=localStorage.getItem(`logOffset`);return e?Number(e):0}),[Fe,Ie]=(0,y.useState)(!1),[Le,Re]=(0,y.useState)(null),[ze,Be]=(0,y.useState)(null),[Ve,He]=(0,y.useState)(``),[Ue,We]=(0,y.useState)(``),[Ge,Ke]=(0,y.useState)(()=>{let e=localStorage.getItem(`logPageSize`);return e?Number(e):25}),qe=(0,y.useCallback)(e=>{we(e),Se(e)},[]);(0,y.useEffect)(()=>{if(xe){let t=setTimeout(()=>{let t=document.querySelector(`[data-archive-id="${xe}"]`);t?t.scrollIntoView({behavior:`smooth`,block:`center`}):Ce===xe&&n(e(`archives.originalPrintNotVisible`),`warning`),Ce===xe&&we(null)},100),r=setTimeout(()=>Se(null),5e3);return()=>{clearTimeout(t),clearTimeout(r)}}},[xe,Ce,n,e]);let{data:Je,isLoading:Ye}=q({queryKey:[`archives`,c],queryFn:()=>Q.getArchives(c||void 0)}),{data:Xe}=q({queryKey:[`printers`],queryFn:Q.getPrinters}),{data:Ze}=q({queryKey:[`projects`],queryFn:()=>Q.getProjects()}),{data:Qe}=q({queryKey:[`settings`],queryFn:Q.getSettings}),{data:$e}=q({queryKey:[`users`],queryFn:Q.getUsers,enabled:re===`log`}),{data:et,isLoading:tt}=q({queryKey:[`print-log`,c,Te,De,ke,je,o,Ne,Ge],queryFn:()=>Q.getPrintLog({search:o||void 0,printerId:c||void 0,username:Te||void 0,status:De||void 0,dateFrom:ke||void 0,dateTo:je||void 0,limit:Ge,offset:Ne}),enabled:re===`log`}),nt=Qe?.time_format||`system`,rt=Qe?.open_in_slicer||Qe?.preferred_slicer||`bambu_studio`,it=Qe?.use_slicer_api??!1,at=uf(Qe?.currency||`USD`),ot=J({mutationFn:async e=>(await Promise.all(e.map(e=>Q.deleteArchive(e))),e.length),onSuccess:e=>{t.invalidateQueries({queryKey:[`archives`]}),M(new Set),n(`${e} archive${e===1?``:`s`} deleted`)},onError:()=>{n(e(`archives.toast.failedDeleteArchives`),`error`)}}),st=J({mutationFn:()=>Q.clearPrintLog(),onSuccess:r=>{t.invalidateQueries({queryKey:[`print-log`]}),Pe(0),n(e(`archives.log.cleared`,{count:r.deleted}))},onError:()=>{n(e(`archives.log.clearFailed`),`error`)}}),ct=J({mutationFn:e=>Q.deletePrintLogEntry(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`print-log`]}),t.invalidateQueries({queryKey:[`archives-stats`]}),n(e(`archives.log.entryDeleted`))},onError:()=>{n(e(`archives.log.entryDeleteFailed`),`error`)}}),lt=J({mutationFn:({id:e,body:t})=>Q.updatePrintLogEntry(e,t),onSuccess:()=>{t.invalidateQueries({queryKey:[`print-log`]}),t.invalidateQueries({queryKey:[`archives-stats`]}),Be(null),n(e(`archives.log.entryUpdated`))},onError:()=>{n(e(`archives.log.entryUpdateFailed`),`error`)}});(0,y.useEffect)(()=>{c===null?localStorage.removeItem(`archiveFilterPrinter`):localStorage.setItem(`archiveFilterPrinter`,c.toString())},[c]),(0,y.useEffect)(()=>{u?localStorage.setItem(`archiveFilterMaterial`,u):localStorage.removeItem(`archiveFilterMaterial`)},[u]),(0,y.useEffect)(()=>{localStorage.setItem(`archiveFilterColors`,JSON.stringify([...f]))},[f]),(0,y.useEffect)(()=>{localStorage.setItem(`archiveColorFilterMode`,m)},[m]),(0,y.useEffect)(()=>{localStorage.setItem(`archiveFilterFavorites`,g.toString())},[g]),(0,y.useEffect)(()=>{localStorage.setItem(`archiveHideFailed`,v.toString())},[v]),(0,y.useEffect)(()=>{localStorage.setItem(`archiveHideDuplicates`,x.toString())},[x]),(0,y.useEffect)(()=>{C?localStorage.setItem(`archiveFilterTag`,C):localStorage.removeItem(`archiveFilterTag`)},[C]),(0,y.useEffect)(()=>{localStorage.setItem(`archiveFilterFileType`,T)},[T]),(0,y.useEffect)(()=>{ce(0)},[o,c,u,f,m,g,v,x,C,T,H,oe]),(0,y.useEffect)(()=>{try{localStorage.setItem(`archivePageSize`,String(le))}catch{}},[le]),(0,y.useEffect)(()=>{localStorage.setItem(`archiveViewMode`,re)},[re]),(0,y.useEffect)(()=>{localStorage.setItem(`archiveSortBy`,H)},[H]),(0,y.useEffect)(()=>{localStorage.setItem(`archiveCollection`,oe)},[oe]),(0,y.useEffect)(()=>{Te?localStorage.setItem(`logFilterUser`,Te):localStorage.removeItem(`logFilterUser`)},[Te]),(0,y.useEffect)(()=>{De?localStorage.setItem(`logFilterStatus`,De):localStorage.removeItem(`logFilterStatus`)},[De]),(0,y.useEffect)(()=>{ke?localStorage.setItem(`logFilterDateFrom`,ke):localStorage.removeItem(`logFilterDateFrom`)},[ke]),(0,y.useEffect)(()=>{je?localStorage.setItem(`logFilterDateTo`,je):localStorage.removeItem(`logFilterDateTo`)},[je]),(0,y.useEffect)(()=>{localStorage.setItem(`logOffset`,Ne.toString())},[Ne]),(0,y.useEffect)(()=>{localStorage.setItem(`logPageSize`,Ge.toString())},[Ge]);let ut=new Map(Xe?.map(e=>[e.id,e.name])||[]),dt=[...new Set(Je?.flatMap(e=>e.filament_type?.split(`, `)||[]).filter(Boolean)||[])].sort(),ft=[...new Set(Je?.flatMap(e=>e.filament_color?.split(`,`)||[]).filter(Boolean)||[])],pt=[...new Set(Je?.flatMap(e=>e.tags?.split(`,`).map(e=>e.trim())||[]).filter(Boolean)||[])].sort(),mt=Je?.filter(e=>{let t=new Date,n=Af(e.created_at)||new Date(0),r=!0;switch(oe){case`recent`:r=t.getTime()-n.getTime()<1440*60*1e3;break;case`this-week`:r=t.getTime()-n.getTime()<10080*60*1e3;break;case`this-month`:r=n.getMonth()===t.getMonth()&&n.getFullYear()===t.getFullYear();break;case`favorites`:r=e.is_favorite===!0;break;case`not-printed`:r=e.status===`archived`;break;case`printed`:r=Aze.includes(e.status);break;case`failed`:r=e.status===`failed`||e.status===`aborted`;break;case`duplicates`:r=e.duplicate_count>0;break}let i=(e.print_name||e.filename).toLowerCase().includes(o.toLowerCase()),a=!u||e.filament_type?.split(`, `).includes(u),s=e.filament_color?.split(`,`)||[],c=f.size===0||(m===`or`?s.some(e=>f.has(e)):[...f].every(e=>s.includes(e))),l=oe===`favorites`||!g||e.is_favorite,d=oe===`failed`||!v||e.status!==`failed`&&e.status!==`aborted`,p=oe===`duplicates`||!x||e.duplicate_count===0||e.duplicate_sequence===0,h=e.tags?.split(`,`).map(e=>e.trim())||[],_=!C||h.includes(C),y=a2(e);return r&&i&&a&&c&&l&&d&&p&&_&&(T===`all`||T===`gcode`&&y||T===`source`&&!y)}).sort((e,t)=>{switch(H){case`date-desc`:return(Af(t.created_at)?.getTime()||0)-(Af(e.created_at)?.getTime()||0);case`date-asc`:return(Af(e.created_at)?.getTime()||0)-(Af(t.created_at)?.getTime()||0);case`name-asc`:return(e.print_name||e.filename).localeCompare(t.print_name||t.filename);case`name-desc`:return(t.print_name||t.filename).localeCompare(e.print_name||e.filename);case`size-desc`:return t.file_size-e.file_size;case`size-asc`:return e.file_size-t.file_size;default:return 0}}),ht=mt?.length||0,gt=le===-1,_t=gt?ht||1:le,vt=Math.max(1,Math.ceil(ht/_t)),yt=gt?mt:mt?.slice(se*_t,(se+1)*_t);(0,y.useEffect)(()=>{if(xe&&mt&&!gt){let e=mt.findIndex(e=>e.id===xe);if(e>=0){let t=Math.floor(e/_t);t!==se&&ce(t)}}},[xe]);let bt=L||j.size>0,xt=e=>{M(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},St=()=>{mt&&M(new Set(mt.map(e=>e.id)))},Ct=()=>{M(new Set),R(!1)},wt=e=>{p(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},Tt=()=>{p(new Set)},Et=()=>{s(``),l(null),d(null),_(!1),b(!1),S(!1),w(null),E(`all`)},Dt=o||c||u||g||v||x||C||T!==`all`,{isDraggingOver:Ot,dragHandlers:kt}=XW({disabled:D,extensions:[`.3mf`],onFiles:e=>{A(e),O(!0)},onRejected:()=>n(e(`archives.page.only3mfSupported`),`warning`)}),At=(0,y.useCallback)(e=>{let t=e.target;if(t.tagName===`INPUT`||t.tagName===`TEXTAREA`||t.isContentEditable){e.key===`Escape`&&t.blur();return}switch(e.key){case`/`:e.preventDefault(),a.current?.focus();break;case`u`:case`U`:!e.metaKey&&!e.ctrlKey&&(e.preventDefault(),O(!0));break;case`Escape`:bt&&Ct();break}},[bt]);return(0,y.useEffect)(()=>(document.addEventListener(`keydown`,At),()=>document.removeEventListener(`keydown`,At)),[At]),(0,K.jsxs)(`div`,{className:`p-4 md:p-8 relative`,...kt,children:[Ot&&(0,K.jsx)(`div`,{className:`fixed inset-0 z-50 bg-bambu-dark/90 flex items-center justify-center pointer-events-none`,children:(0,K.jsxs)(`div`,{className:`border-4 border-dashed border-bambu-green rounded-xl p-12 text-center`,children:[(0,K.jsx)(Au,{className:`w-16 h-16 mx-auto mb-4 text-bambu-green`}),(0,K.jsx)(`p`,{className:`text-2xl font-semibold text-white mb-2`,children:e(`archives.page.dropFilesHere`)}),(0,K.jsx)(`p`,{className:`text-bambu-gray`,children:e(`archives.releaseToUpload`)})]})}),bt&&(0,K.jsxs)(`div`,{className:`fixed bottom-6 left-1/2 -translate-x-1/2 z-40 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl px-4 py-3 flex items-center gap-4`,children:[(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:Ct,children:[(0,K.jsx)(Wu,{className:`w-4 h-4`}),`Close`]}),(0,K.jsx)(`div`,{className:`w-px h-6 bg-bambu-dark-tertiary`}),(0,K.jsxs)(`span`,{className:`text-white font-medium`,children:[j.size,` selected`]}),(0,K.jsx)(`div`,{className:`w-px h-6 bg-bambu-dark-tertiary`}),(0,K.jsx)($,{variant:`secondary`,size:`sm`,onClick:St,children:`Select All`}),(0,K.jsx)(`div`,{className:`w-px h-6 bg-bambu-dark-tertiary`}),(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:()=>ee(!0),disabled:!i(`archives:update_own`,`archives:update_all`),title:i(`archives:update_own`,`archives:update_all`)?void 0:e(`archives.permission.noUpdateArchives`),children:[(0,K.jsx)(hu,{className:`w-4 h-4`}),`Tags`]}),(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:()=>ne(!0),disabled:!i(`archives:update_own`,`archives:update_all`),title:i(`archives:update_own`,`archives:update_all`)?void 0:e(`archives.permission.noUpdateArchives`),children:[(0,K.jsx)(sc,{className:`w-4 h-4`}),`Project`]}),(0,K.jsxs)($,{variant:`secondary`,size:`sm`,disabled:!i(`archives:update_own`,`archives:update_all`),title:i(`archives:update_own`,`archives:update_all`)?void 0:e(`archives.permission.noUpdateArchives`),onClick:()=>{let r=Array.from(j);Promise.all(r.map(e=>Q.toggleFavorite(e))).then(()=>{t.invalidateQueries({queryKey:[`archives`]}),n(`Toggled favorites for ${r.length} archive${r.length===1?``:`s`}`)}).catch(()=>{n(e(`archives.toast.failedUpdateFavorites`),`error`)})},children:[(0,K.jsx)(uu,{className:`w-4 h-4`}),`Favorite`]}),(0,K.jsxs)($,{size:`sm`,className:`bg-red-500 hover:bg-red-600`,onClick:()=>B(!0),disabled:!i(`archives:delete_own`,`archives:delete_all`),title:i(`archives:delete_own`,`archives:delete_all`)?void 0:e(`archives.permission.noDelete`),children:[(0,K.jsx)(Cu,{className:`w-4 h-4`}),`Delete`]})]}),F?.has_fallback&&!N&&(0,K.jsxs)(`div`,{className:`mb-6 rounded-lg border border-amber-300 dark:border-amber-500/30 bg-amber-50 dark:bg-amber-500/10 px-4 py-3 flex items-start gap-3`,children:[(0,K.jsx)(us,{className:`w-5 h-5 text-amber-600 dark:text-amber-400 flex-shrink-0 mt-0.5`}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsx)(`div`,{className:`text-sm font-medium text-amber-900 dark:text-amber-200`,children:e(`archives.no3mfBanner.title`)}),(0,K.jsxs)(`div`,{className:`text-xs text-amber-800/90 dark:text-amber-200/80 mt-1`,children:[e(`archives.no3mfBanner.body`),` `,(0,K.jsxs)(`a`,{href:`https://wiki.bambuddy.cool/getting-started/#step-4-enable-store-sent-files-on-external-storage`,target:`_blank`,rel:`noreferrer`,className:`underline hover:text-amber-900 dark:hover:text-amber-100 inline-flex items-center gap-1`,children:[e(`archives.no3mfBanner.docsLink`),(0,K.jsx)(Js,{className:`w-3 h-3`})]})]})]}),(0,K.jsx)(`button`,{onClick:I,className:`text-amber-800/70 dark:text-amber-200/60 hover:text-amber-900 dark:hover:text-amber-200 flex-shrink-0 p-1 -m-1`,title:e(`archives.no3mfBanner.dismissLabel`),"aria-label":e(`archives.no3mfBanner.dismissLabel`),children:(0,K.jsx)(Wu,{className:`w-4 h-4`})})]}),(0,K.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4 mb-8`,children:[(0,K.jsx)(`div`,{children:(0,K.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,K.jsx)(Oo,{className:`w-7 h-7 text-bambu-green`}),`Archives`]}),(0,K.jsxs)(`p`,{className:`text-bambu-gray mt-1`,children:[mt?.length||0,` of `,Je?.length||0,` prints`]})]}),(0,K.jsx)(`select`,{className:`mt-0.5 px-3 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray-light text-sm focus:border-bambu-green focus:outline-none`,value:oe,onChange:e=>U(e.target.value),children:jze.map(e=>(0,K.jsx)(`option`,{value:e.id,children:e.label},e.id))})]})}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 sm:gap-3 flex-wrap`,children:[(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsxs)($,{variant:`secondary`,onClick:()=>fe(!de),disabled:pe,children:[pe?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(tc,{className:`w-4 h-4`}),`Export`]}),de&&(0,K.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,K.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:async()=>{fe(!1),me(!0);try{let{blob:t,filename:r}=await Q.exportArchives({format:`csv`,printerId:c||void 0,status:oe===`failed`?`failed`:void 0,search:o||void 0}),i=URL.createObjectURL(t),a=document.createElement(`a`);a.href=i,a.download=r,a.click(),URL.revokeObjectURL(i),n(e(`archives.toast.exportDownloaded`))}catch{n(e(`archives.toast.exportFailed`),`error`)}finally{me(!1)}},children:[(0,K.jsx)(nc,{className:`w-4 h-4`}),`Export as CSV`]}),(0,K.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:async()=>{fe(!1),me(!0);try{let{blob:t,filename:r}=await Q.exportArchives({format:`xlsx`,printerId:c||void 0,status:oe===`failed`?`failed`:void 0,search:o||void 0}),i=URL.createObjectURL(t),a=document.createElement(`a`);a.href=i,a.download=r,a.click(),URL.revokeObjectURL(i),n(e(`archives.toast.exportDownloaded`))}catch{n(e(`archives.toast.exportFailed`),`error`)}finally{me(!1)}},children:[(0,K.jsx)(tc,{className:`w-4 h-4`}),`Export as Excel`]})]})]}),j.size>=2&&j.size<=5&&(0,K.jsxs)($,{variant:`secondary`,onClick:()=>ge(!0),children:[(0,K.jsx)(vc,{className:`w-4 h-4`}),`Compare (`,j.size,`)`]}),!bt&&(0,K.jsxs)($,{variant:`secondary`,onClick:()=>R(!0),children:[(0,K.jsx)(su,{className:`w-4 h-4`}),`Select`]}),(0,K.jsxs)($,{onClick:()=>O(!0),disabled:!r(`archives:create`),title:r(`archives:create`)?void 0:e(`archives.permission.noCreate`),children:[(0,K.jsx)(Au,{className:`w-4 h-4`}),`Upload 3MF`]}),r(`archives:purge`)&&(0,K.jsxs)($,{variant:`secondary`,onClick:()=>be(!0),title:e(`archivePurge.headerTooltip`),children:[(0,K.jsx)(Cu,{className:`w-4 h-4 mr-2`}),e(`archivePurge.headerButton`)]})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center border border-bambu-dark-tertiary rounded-lg overflow-hidden flex-shrink-0 w-fit mb-4`,children:[(0,K.jsx)(`button`,{className:`p-2 ${re===`grid`?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white`}`,onClick:()=>ie(`grid`),title:e(`archives.gridView`),children:(0,K.jsx)(zc,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{className:`p-2 ${re===`list`?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white`}`,onClick:()=>ie(`list`),title:e(`archives.listView`),children:(0,K.jsx)(Gc,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{className:`p-2 ${re===`calendar`?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white`}`,onClick:()=>ie(`calendar`),title:e(`archives.calendarView`),children:(0,K.jsx)(Yo,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{className:`p-2 ${re===`log`?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white`}`,onClick:()=>ie(`log`),title:e(`archives.logView`),children:(0,K.jsx)(bs,{className:`w-4 h-4`})})]}),re!==`log`&&(0,K.jsx)(Cd,{className:`mb-6`,children:(0,K.jsxs)(Td,{className:`py-4`,children:[(0,K.jsxs)(`div`,{className:`flex flex-col md:flex-row gap-3 md:gap-4 md:items-center md:flex-wrap`,children:[(0,K.jsxs)(`div`,{className:`w-full md:flex-1 relative md:min-w-[200px]`,children:[(0,K.jsx)(Vl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,K.jsx)(`input`,{ref:a,type:`text`,placeholder:e(`archives.searchPlaceholder`),className:`w-full pl-10 pr-4 py-3 md:py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,value:o,onChange:e=>s(e.target.value)})]}),(0,K.jsxs)(`div`,{className:`flex gap-2 md:gap-4 overflow-x-auto pb-1 md:pb-0 -mx-4 px-4 md:mx-0 md:px-0 md:flex-wrap scrollbar-hide`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[(0,K.jsx)(mc,{className:`w-4 h-4 text-bambu-gray hidden md:block`}),(0,K.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?Number(e.target.value):null),children:[(0,K.jsx)(`option`,{value:``,children:`All Printers`}),Xe?.map(e=>(0,K.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[(0,K.jsx)(ml,{className:`w-4 h-4 text-bambu-gray hidden md:block`}),(0,K.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:u||``,onChange:e=>d(e.target.value||null),children:[(0,K.jsx)(`option`,{value:``,children:`All Materials`}),dt.map(e=>(0,K.jsx)(`option`,{value:e,children:e},e))]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[(0,K.jsx)($s,{className:`w-4 h-4 text-bambu-gray hidden md:block`}),(0,K.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:T,onChange:e=>E(e.target.value),children:[(0,K.jsx)(`option`,{value:`all`,children:`All Files`}),(0,K.jsx)(`option`,{value:`gcode`,children:`Sliced (GCODE)`}),(0,K.jsx)(`option`,{value:`source`,children:`Source Only`})]})]}),(0,K.jsxs)(`button`,{onClick:()=>_(!g),className:`flex items-center gap-2 px-3 py-2 rounded-lg border transition-colors flex-shrink-0 ${g?`bg-yellow-100 dark:bg-yellow-500/20 border-yellow-500 text-yellow-700 dark:text-yellow-400`:`bg-bambu-dark border-bambu-dark-tertiary text-bambu-gray hover:text-white`}`,title:e(g?`archives.showAll`:`archives.showFavoritesOnly`),children:[(0,K.jsx)(uu,{className:`w-4 h-4 ${g?`fill-yellow-400`:``}`}),(0,K.jsx)(`span`,{className:`text-sm hidden md:inline`,children:`Favorites`})]}),(0,K.jsxs)(`button`,{onClick:()=>b(!v),className:`flex items-center gap-2 px-3 py-2 rounded-lg border transition-colors flex-shrink-0 ${v?`bg-red-100 dark:bg-red-500/20 border-red-500 text-red-700 dark:text-red-400`:`bg-bambu-dark border-bambu-dark-tertiary text-bambu-gray hover:text-white`}`,title:e(v?`archives.showFailedPrints`:`archives.hideFailedPrints`),children:[(0,K.jsx)(us,{className:`w-4 h-4 `}),(0,K.jsx)(`span`,{className:`text-sm hidden md:inline`,children:`Hide Failed`})]}),(0,K.jsxs)(`button`,{onClick:()=>S(!x),className:`flex items-center gap-2 px-3 py-2 rounded-lg border transition-colors flex-shrink-0 ${x?`bg-purple-100 dark:bg-purple-500/20 border-purple-500 text-purple-700 dark:text-purple-400`:`bg-bambu-dark border-bambu-dark-tertiary text-bambu-gray hover:text-white`}`,title:e(`archives.hideDuplicates`),children:[(0,K.jsx)(Ms,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{className:`text-sm hidden md:inline`,children:e(`archives.hideDuplicates`)})]}),pt.length>0&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[(0,K.jsx)(hu,{className:`w-4 h-4 text-bambu-gray hidden md:block`}),(0,K.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=>w(e.target.value||null),children:[(0,K.jsx)(`option`,{value:``,children:`All Tags`}),pt.map(e=>(0,K.jsx)(`option`,{value:e,children:e},e))]}),(0,K.jsx)(`button`,{onClick:()=>ve(!0),className:`p-2 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary text-bambu-gray hover:text-white hover:border-bambu-green transition-colors`,title:e(`archives.manageTags`),children:(0,K.jsx)(Kl,{className:`w-4 h-4`})})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[(0,K.jsx)(Po,{className:`w-4 h-4 text-bambu-gray hidden md:block`}),(0,K.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:H,onChange:e=>ae(e.target.value),children:[(0,K.jsx)(`option`,{value:`date-desc`,children:e(`archives.sortNewest`)}),(0,K.jsx)(`option`,{value:`date-asc`,children:e(`archives.sortOldest`)}),(0,K.jsxs)(`option`,{value:`name-asc`,children:[e(`archives.sortName`),` A-Z`]}),(0,K.jsxs)(`option`,{value:`name-desc`,children:[e(`archives.sortName`),` Z-A`]}),(0,K.jsx)(`option`,{value:`size-desc`,children:e(`archives.sortLargest`)}),(0,K.jsx)(`option`,{value:`size-asc`,children:e(`archives.sortSmallest`)})]})]})]}),Dt&&(0,K.jsxs)($,{variant:`ghost`,size:`sm`,onClick:Et,className:`text-bambu-gray hover:text-white`,children:[(0,K.jsx)(Wu,{className:`w-4 h-4`}),`Reset`]})]}),ft.length>0&&(0,K.jsxs)(`div`,{className:`flex items-center gap-3 mt-4 pt-4 border-t border-bambu-dark-tertiary`,children:[(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:`Colors:`}),f.size>1&&(0,K.jsx)(`button`,{onClick:()=>h(e=>e===`or`?`and`:`or`),className:`px-2 py-0.5 text-xs rounded transition-colors ${m===`and`?`bg-bambu-green text-white`:`bg-bambu-dark-tertiary text-bambu-gray hover:text-white`}`,title:m===`or`?`Match ANY selected color`:`Match ALL selected colors`,children:m.toUpperCase()}),(0,K.jsx)(`div`,{className:`flex items-center gap-1.5 flex-wrap`,children:ft.map(e=>(0,K.jsx)(`button`,{onClick:()=>wt(e),className:`w-6 h-6 rounded-full border-2 transition-all ${f.has(e)?`border-bambu-green scale-110`:`border-white/20 hover:border-white/40`}`,style:{backgroundColor:e},title:e},e))}),f.size>0&&(0,K.jsxs)(`button`,{onClick:Tt,className:`text-xs text-bambu-gray hover:text-white flex items-center gap-1`,children:[(0,K.jsx)(Wu,{className:`w-3 h-3`}),`Clear`]})]})]})}),(0,K.jsx)(Eze,{}),Ye?(0,K.jsx)(`div`,{className:`text-center py-12 text-bambu-gray`,children:e(`archives.loadingArchives`)}):mt?.length===0?(0,K.jsx)(Cd,{children:(0,K.jsxs)(Td,{className:`text-center py-12`,children:[(0,K.jsx)(`p`,{className:`text-bambu-gray`,children:e(o?`archives.noArchivesSearch`:`archives.noArchivesYet`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mt-2`,children:`Archives are created automatically when prints complete`})]})}):re===`calendar`?(0,K.jsx)(Cd,{className:`p-6`,children:(0,K.jsx)(RAe,{archives:mt||[],onArchiveClick:e=>{s(``),ie(`grid`),Se(e.id)},highlightedArchiveId:xe})}):re===`grid`?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-6`,children:yt?.map(t=>(0,K.jsx)(Oze,{archive:t,printerName:t.printer_id?ut.get(t.printer_id)||`Unknown`:t.sliced_for_model||`No Printer`,isSelected:j.has(t.id),onSelect:xt,selectionMode:bt,projects:Ze,isHighlighted:t.id===xe,timeFormat:nt,preferredSlicer:rt,useSlicerApi:it,currency:at,t:e,onNavigateToArchive:qe},t.id))}),(0,K.jsx)(s2,{pageIndex:se,pageSize:le,totalRows:ht,totalPages:vt,onPageChange:ce,onPageSizeChange:e=>{ue(e),ce(0)},t:e})]}):re===`list`?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Cd,{children:(0,K.jsxs)(`div`,{className:`divide-y divide-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-12 gap-4 px-4 py-3 text-xs text-bambu-gray font-medium`,children:[(0,K.jsx)(`div`,{className:`col-span-1`}),(0,K.jsx)(`div`,{className:`col-span-4`,children:`Name`}),(0,K.jsx)(`div`,{className:`col-span-2`,children:`Printer`}),(0,K.jsx)(`div`,{className:`col-span-2`,children:`Date`}),(0,K.jsx)(`div`,{className:`col-span-1`,children:`Size`}),(0,K.jsx)(`div`,{className:`col-span-2 text-right`,children:`Actions`})]}),yt?.map(t=>(0,K.jsx)(kze,{archive:t,printerName:t.printer_id?ut.get(t.printer_id)||`Unknown`:t.sliced_for_model||`No Printer`,isSelected:j.has(t.id),onSelect:xt,selectionMode:bt,projects:Ze,isHighlighted:t.id===xe,preferredSlicer:rt,useSlicerApi:it,t:e,onNavigateToArchive:qe},t.id))]})}),(0,K.jsx)(s2,{pageIndex:se,pageSize:le,totalRows:ht,totalPages:vt,onPageChange:ce,onPageSizeChange:e=>{ue(e),ce(0)},t:e})]}):re===`log`?(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsx)(Cd,{children:(0,K.jsx)(Td,{className:`py-3`,children:(0,K.jsxs)(`div`,{className:`flex flex-col md:flex-row gap-3 md:items-center md:flex-wrap`,children:[(0,K.jsxs)(`div`,{className:`flex-1 relative md:min-w-[200px]`,children:[(0,K.jsx)(Vl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,K.jsx)(`input`,{type:`text`,placeholder:e(`archives.searchPlaceholder`),className:`w-full pl-10 pr-4 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none text-sm`,value:o,onChange:e=>{s(e.target.value),Pe(0)}})]}),(0,K.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 text-sm`,value:c||``,onChange:e=>{l(e.target.value?Number(e.target.value):null),Pe(0)},children:[(0,K.jsx)(`option`,{value:``,children:e(`archives.log.allPrinters`)}),Xe?.map(e=>(0,K.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),(0,K.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 text-sm`,value:Te||``,onChange:e=>{Ee(e.target.value||null),Pe(0)},children:[(0,K.jsx)(`option`,{value:``,children:e(`archives.log.allUsers`)}),$e?.map(e=>(0,K.jsx)(`option`,{value:e.username,children:e.username},e.id))]}),(0,K.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 text-sm`,value:De||``,onChange:e=>{Oe(e.target.value||null),Pe(0)},children:[(0,K.jsx)(`option`,{value:``,children:e(`archives.log.allStatuses`)}),(0,K.jsx)(`option`,{value:`completed`,children:e(`archives.status.completed`)}),(0,K.jsx)(`option`,{value:`failed`,children:e(`archives.status.failed`)}),(0,K.jsx)(`option`,{value:`stopped`,children:e(`archives.status.stopped`)}),(0,K.jsx)(`option`,{value:`cancelled`,children:e(`archives.log.cancelled`)}),(0,K.jsx)(`option`,{value:`skipped`,children:e(`archives.log.skipped`)})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`label`,{className:`text-sm text-bambu-gray`,children:e(`archives.log.dateFrom`)}),(0,K.jsx)(`input`,{type:`date`,className:`px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none text-sm`,value:ke,onChange:e=>{Ae(e.target.value),Pe(0)}})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`label`,{className:`text-sm text-bambu-gray`,children:e(`archives.log.dateTo`)}),(0,K.jsx)(`input`,{type:`date`,className:`px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none text-sm`,value:je,onChange:e=>{Me(e.target.value),Pe(0)}})]}),(0,K.jsx)(`div`,{className:`ml-auto`,children:(0,K.jsxs)($,{variant:`danger`,size:`sm`,onClick:()=>Ie(!0),disabled:!r(`archives:delete_all`)||st.isPending,children:[(0,K.jsx)(Cu,{className:`w-4 h-4`}),e(`archives.log.clearLog`)]})})]})})}),(0,K.jsx)(Cd,{children:tt?(0,K.jsx)(`div`,{className:`flex items-center justify-center py-12`,children:(0,K.jsx)(X,{className:`w-6 h-6 animate-spin text-bambu-green`})}):et?.items.length?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`overflow-x-auto`,children:(0,K.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,K.jsx)(`thead`,{children:(0,K.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary text-bambu-gray text-left`,children:[(0,K.jsx)(`th`,{className:`px-4 py-3 font-medium`,children:e(`archives.log.date`)}),(0,K.jsx)(`th`,{className:`px-4 py-3 font-medium`,children:e(`archives.log.printName`)}),(0,K.jsx)(`th`,{className:`px-4 py-3 font-medium`,children:e(`archives.log.printer`)}),(0,K.jsx)(`th`,{className:`px-4 py-3 font-medium`,children:e(`archives.log.user`)}),(0,K.jsx)(`th`,{className:`px-4 py-3 font-medium`,children:e(`archives.log.status`)}),(0,K.jsx)(`th`,{className:`px-4 py-3 font-medium`,children:e(`archives.log.duration`)}),(0,K.jsx)(`th`,{className:`px-4 py-3 font-medium`,children:e(`archives.log.filament`)}),(0,K.jsx)(`th`,{className:`px-4 py-3 font-medium w-10`,"aria-label":e(`common.actions`)})]})}),(0,K.jsx)(`tbody`,{className:`divide-y divide-bambu-dark-tertiary`,children:et.items.map(t=>(0,K.jsxs)(`tr`,{className:`hover:bg-bambu-dark-secondary/50`,children:[(0,K.jsx)(`td`,{className:`px-4 py-3 text-white whitespace-nowrap`,children:Mf(t.started_at||t.created_at,nt)}),(0,K.jsx)(`td`,{className:`px-4 py-3`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[t.thumbnail_path&&(0,K.jsx)(`img`,{src:Q.getPrintLogThumbnail(t.id),alt:``,className:`w-8 h-8 rounded object-cover flex-shrink-0`,onError:e=>{e.target.style.display=`none`}}),(0,K.jsx)(`span`,{className:`text-white break-words`,title:t.print_name||``,children:t.print_name||`—`})]})}),(0,K.jsx)(`td`,{className:`px-4 py-3 text-bambu-gray-light`,children:t.printer_name||`—`}),(0,K.jsx)(`td`,{className:`px-4 py-3 text-bambu-gray-light`,children:t.created_by_username||`—`}),(0,K.jsxs)(`td`,{className:`px-4 py-3`,children:[(0,K.jsx)(`span`,{className:`inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium ${t.status===`completed`?`bg-green-100 dark:bg-green-500/20 text-green-700 dark:text-green-400`:t.status===`failed`?`bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400`:t.status===`stopped`?`bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400`:t.status===`cancelled`?`bg-orange-100 dark:bg-orange-500/20 text-orange-700 dark:text-orange-400`:t.status===`skipped`?`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`:`bg-gray-500/20 text-gray-400`}`,children:t.status}),t.failure_reason&&(0,K.jsx)(`span`,{className:`block text-[10px] text-bambu-gray mt-0.5`,children:e(`editArchive.failureReasons.${t.failure_reason}`,{defaultValue:t.failure_reason})})]}),(0,K.jsx)(`td`,{className:`px-4 py-3 text-bambu-gray-light whitespace-nowrap`,children:t.duration_seconds?Ff(t.duration_seconds):`—`}),(0,K.jsx)(`td`,{className:`px-4 py-3`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[t.filament_color&&(0,K.jsx)(`div`,{className:`flex items-center gap-0.5 flex-wrap`,children:t.filament_color.split(`,`).map((e,t)=>{let n=e.trim();return(0,K.jsx)(`span`,{className:`w-3 h-3 rounded-full border border-black/20 flex-shrink-0`,style:{backgroundColor:n.startsWith(`#`)?n:void 0},title:n},t)})}),(0,K.jsx)(`span`,{className:`text-bambu-gray-light text-xs`,children:t.filament_type||`—`})]})}),(0,K.jsx)(`td`,{className:`px-4 py-3 text-right`,children:(0,K.jsxs)(`div`,{className:`inline-flex items-center gap-2`,children:[(0,K.jsx)(`button`,{type:`button`,onClick:()=>{Be(t),He(t.failure_reason||``),We(t.status)},disabled:lt.isPending||!(r(`archives:update_all`)||r(`archives:update_own`)),title:r(`archives:update_all`)||r(`archives:update_own`)?e(`archives.log.editEntryTitle`):e(`archives.permission.noEdit`),className:`text-bambu-gray hover:text-bambu-blue disabled:opacity-40 disabled:hover:text-bambu-gray transition-colors`,children:(0,K.jsx)(xl,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>Re(t.id),disabled:ct.isPending||!(r(`archives:delete_all`)||r(`archives:delete_own`)),title:r(`archives:delete_all`)||r(`archives:delete_own`)?e(`archives.log.deleteEntryTitle`):e(`archives.permission.noDelete`),className:`text-bambu-gray hover:text-red-600 dark:hover:text-red-400 disabled:opacity-40 disabled:hover:text-bambu-gray transition-colors`,children:(0,K.jsx)(Cu,{className:`w-4 h-4`})})]})})]},t.id))})]})}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 border-t border-bambu-dark-tertiary flex-wrap gap-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e(`archives.log.showing`,{count:Math.min(Ne+Ge,et.total),total:et.total})}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,K.jsx)(`label`,{className:`text-xs text-bambu-gray`,children:e(`archives.log.rowsPerPage`)}),(0,K.jsxs)(`select`,{className:`px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-xs focus:border-bambu-green focus:outline-none`,value:Ge,onChange:e=>{Ke(Number(e.target.value)),Pe(0)},children:[(0,K.jsx)(`option`,{value:10,children:`10`}),(0,K.jsx)(`option`,{value:25,children:`25`}),(0,K.jsx)(`option`,{value:50,children:`50`}),(0,K.jsx)(`option`,{value:100,children:`100`})]})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[e(`archives.log.page`),` `,Math.floor(Ne/Ge)+1,` / `,Math.max(1,Math.ceil(et.total/Ge))]}),(0,K.jsx)($,{variant:`secondary`,size:`sm`,onClick:()=>Pe(Math.max(0,Ne-Ge)),disabled:Ne===0,children:(0,K.jsx)(as,{className:`w-4 h-4`})}),(0,K.jsx)($,{variant:`secondary`,size:`sm`,onClick:()=>Pe(Ne+Ge),disabled:Ne+Ge>=et.total,children:(0,K.jsx)(is,{className:`w-4 h-4`})})]})]})]}):(0,K.jsx)(`div`,{className:`text-center py-12 text-bambu-gray`,children:e(`archives.log.noEntries`)})})]}):null,D&&(0,K.jsx)(TAe,{onClose:()=>{O(!1),A([])},initialFiles:k}),ye&&(0,K.jsx)(DAe,{onClose:()=>be(!1)}),z&&(0,K.jsx)(Bd,{title:e(`archives.modal.deleteArchives`),message:e(`archives.modal.deleteArchivesConfirm`,{count:j.size}),confirmText:e(`archives.modal.deleteCount`,{count:j.size}),variant:`danger`,onConfirm:()=>{ot.mutate(Array.from(j)),B(!1)},onCancel:()=>B(!1)}),V&&(0,K.jsx)(MAe,{selectedIds:Array.from(j),existingTags:pt,onClose:()=>ee(!1)}),te&&(0,K.jsx)(NAe,{selectedIds:Array.from(j),onClose:()=>ne(!1)}),he&&j.size>=2&&j.size<=5&&(0,K.jsx)(Sze,{archiveIds:Array.from(j),onClose:()=>{ge(!1),M(new Set),R(!1)}}),_e&&(0,K.jsx)(Dze,{onClose:()=>ve(!1)}),Fe&&(0,K.jsx)(Bd,{title:e(`archives.log.clearLogTitle`),message:e(`archives.log.clearLogConfirm`),confirmText:e(`archives.log.clearLogButton`),variant:`danger`,onConfirm:()=>{st.mutate(),Ie(!1)},onCancel:()=>Ie(!1)}),Le!==null&&(0,K.jsx)(Bd,{title:e(`archives.log.deleteEntryTitle`),message:e(`archives.log.deleteEntryConfirm`),confirmText:e(`common.delete`),variant:`danger`,onConfirm:()=>{ct.mutate(Le),Re(null)},onCancel:()=>Re(null)}),ze!==null&&(0,K.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm`,onClick:()=>Be(null),children:(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg w-full max-w-md mx-4 p-6`,onClick:e=>e.stopPropagation(),children:[(0,K.jsx)(`h3`,{className:`text-lg font-semibold text-white mb-4`,children:e(`archives.log.editEntryTitle`)}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mb-4`,children:e(`archives.log.editEntryDescription`)}),(0,K.jsxs)(`div`,{className:`space-y-4`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:e(`editArchive.status`)}),(0,K.jsxs)(`select`,{value:Ue,onChange:e=>We(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`,children:[(0,K.jsx)(`option`,{value:`completed`,children:e(`archives.log.statuses.completed`,{defaultValue:`completed`})}),(0,K.jsx)(`option`,{value:`failed`,children:e(`archives.log.statuses.failed`,{defaultValue:`failed`})}),(0,K.jsx)(`option`,{value:`stopped`,children:e(`archives.log.statuses.stopped`,{defaultValue:`stopped`})}),(0,K.jsx)(`option`,{value:`cancelled`,children:e(`archives.log.statuses.cancelled`,{defaultValue:`cancelled`})}),(0,K.jsx)(`option`,{value:`skipped`,children:e(`archives.log.statuses.skipped`,{defaultValue:`skipped`})})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:e(`editArchive.failureReason`)}),(0,K.jsxs)(`select`,{value:Ve,onChange:e=>He(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`,children:[(0,K.jsx)(`option`,{value:``,children:e(`editArchive.selectReason`)}),QW.map(t=>(0,K.jsx)(`option`,{value:t,children:e(`editArchive.failureReasons.${t}`)},t))]})]})]}),(0,K.jsxs)(`div`,{className:`flex justify-end gap-2 mt-6`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:()=>Be(null),children:e(`common.cancel`)}),(0,K.jsx)($,{variant:`primary`,onClick:()=>{let e={};if(Ve!==(ze.failure_reason||``)&&(e.failure_reason=Ve||null),Ue!==ze.status&&(e.status=Ue),Object.keys(e).length===0){Be(null);return}lt.mutate({id:ze.id,body:e})},disabled:lt.isPending,children:lt.isPending?e(`editArchive.saving`):e(`common.save`)})]})]})})]})}function s2({pageIndex:e,pageSize:t,totalRows:n,totalPages:r,onPageChange:i,onPageSizeChange:a,t:o}){let s=t===-1;if(r<=1&&!s)return null;let c=s?n||1:t;return(0,K.jsxs)(`div`,{className:`flex items-center justify-between pt-2 text-sm`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:s?`${n} ${o(`archives.prints`)}`:(0,K.jsxs)(K.Fragment,{children:[o(`archives.pagination.showing`),` `,e*c+1,` `,o(`archives.pagination.to`),` `,Math.min((e+1)*c,n),` `,o(`archives.pagination.of`),` `,n,` `,o(`archives.prints`)]})}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:o(`archives.pagination.show`)}),(0,K.jsxs)(`select`,{value:t,onChange:e=>a(Number(e.target.value)),className:`px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:outline-none focus:border-bambu-green`,children:[[25,50,100,200].map(e=>(0,K.jsx)(`option`,{value:e,children:e},e)),(0,K.jsx)(`option`,{value:-1,children:o(`archives.pagination.all`)})]}),!s&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`button`,{onClick:()=>i(0),disabled:e===0,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,children:(0,K.jsx)(cs,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>i(Math.max(0,e-1)),disabled:e===0,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,children:(0,K.jsx)(as,{className:`w-4 h-4`})}),(0,K.jsxs)(`span`,{className:`text-bambu-gray px-2 whitespace-nowrap`,children:[o(`archives.pagination.page`),` `,e+1,` `,o(`archives.pagination.of`),` `,r]}),(0,K.jsx)(`button`,{onClick:()=>i(Math.min(r-1,e+1)),disabled:e>=r-1,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,children:(0,K.jsx)(is,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>i(r-1),disabled:e>=r-1,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,children:(0,K.jsx)(ls,{className:`w-4 h-4`})})]})]})]})}function Nze(){var e=[...arguments];return(0,y.useMemo)(()=>t=>{e.forEach(e=>e(t))},e)}var c2=typeof window<`u`&&window.document!==void 0&&window.document.createElement!==void 0;function l2(e){let t=Object.prototype.toString.call(e);return t===`[object Window]`||t===`[object global]`}function u2(e){return`nodeType`in e}function d2(e){return e?l2(e)?e:u2(e)?e.ownerDocument?.defaultView??window:window:window}function f2(e){let{Document:t}=d2(e);return e instanceof t}function p2(e){return l2(e)?!1:e instanceof d2(e).HTMLElement}function m2(e){return e instanceof d2(e).SVGElement}function h2(e){return e?l2(e)?e.document:u2(e)?f2(e)?e:p2(e)||m2(e)?e.ownerDocument:document:document:document}var g2=c2?y.useLayoutEffect:y.useEffect;function _2(e){let t=(0,y.useRef)(e);return g2(()=>{t.current=e}),(0,y.useCallback)(function(){var e=[...arguments];return t.current==null?void 0:t.current(...e)},[])}function Pze(){let e=(0,y.useRef)(null);return[(0,y.useCallback)((t,n)=>{e.current=setInterval(t,n)},[]),(0,y.useCallback)(()=>{e.current!==null&&(clearInterval(e.current),e.current=null)},[])]}function v2(e,t){t===void 0&&(t=[e]);let n=(0,y.useRef)(e);return g2(()=>{n.current!==e&&(n.current=e)},t),n}function y2(e,t){let n=(0,y.useRef)();return(0,y.useMemo)(()=>{let t=e(n.current);return n.current=t,t},[...t])}function b2(e){let t=_2(e),n=(0,y.useRef)(null);return[n,(0,y.useCallback)(e=>{e!==n.current&&t?.(e,n.current),n.current=e},[])]}function x2(e){let t=(0,y.useRef)();return(0,y.useEffect)(()=>{t.current=e},[e]),t.current}var S2={};function C2(e,t){return(0,y.useMemo)(()=>{if(t)return t;let n=S2[e]==null?0:S2[e]+1;return S2[e]=n,e+`-`+n},[e,t])}function w2(e){return function(t){return[...arguments].slice(1).reduce((t,n)=>{let r=Object.entries(n);for(let[n,i]of r){let r=t[n];r!=null&&(t[n]=r+e*i)}return t},{...t})}}var T2=w2(1),E2=w2(-1);function Fze(e){return`clientX`in e&&`clientY`in e}function D2(e){if(!e)return!1;let{KeyboardEvent:t}=d2(e.target);return t&&e instanceof t}function Ize(e){if(!e)return!1;let{TouchEvent:t}=d2(e.target);return t&&e instanceof t}function O2(e){if(Ize(e)){if(e.touches&&e.touches.length){let{clientX:t,clientY:n}=e.touches[0];return{x:t,y:n}}else if(e.changedTouches&&e.changedTouches.length){let{clientX:t,clientY:n}=e.changedTouches[0];return{x:t,y:n}}}return Fze(e)?{x:e.clientX,y:e.clientY}:null}var k2=Object.freeze({Translate:{toString(e){if(!e)return;let{x:t,y:n}=e;return`translate3d(`+(t?Math.round(t):0)+`px, `+(n?Math.round(n):0)+`px, 0)`}},Scale:{toString(e){if(!e)return;let{scaleX:t,scaleY:n}=e;return`scaleX(`+t+`) scaleY(`+n+`)`}},Transform:{toString(e){if(e)return[k2.Translate.toString(e),k2.Scale.toString(e)].join(` `)}},Transition:{toString(e){let{property:t,duration:n,easing:r}=e;return t+` `+n+`ms `+r}}}),A2=`a,frame,iframe,input:not([type=hidden]):not(:disabled),select:not(:disabled),textarea:not(:disabled),button:not(:disabled),*[tabindex]`;function Lze(e){return e.matches(A2)?e:e.querySelector(A2)}var Rze={display:`none`};function zze(e){let{id:t,value:n}=e;return y.createElement(`div`,{id:t,style:Rze},n)}function Bze(e){let{id:t,announcement:n,ariaLiveType:r=`assertive`}=e;return y.createElement(`div`,{id:t,style:{position:`fixed`,top:0,left:0,width:1,height:1,margin:-1,border:0,padding:0,overflow:`hidden`,clip:`rect(0 0 0 0)`,clipPath:`inset(100%)`,whiteSpace:`nowrap`},role:`status`,"aria-live":r,"aria-atomic":!0},n)}function Vze(){let[e,t]=(0,y.useState)(``);return{announce:(0,y.useCallback)(e=>{e!=null&&t(e)},[]),announcement:e}}var j2=(0,y.createContext)(null);function Hze(e){let t=(0,y.useContext)(j2);(0,y.useEffect)(()=>{if(!t)throw Error(`useDndMonitor must be used within a children of `);return t(e)},[e,t])}function Uze(){let[e]=(0,y.useState)(()=>new Set),t=(0,y.useCallback)(t=>(e.add(t),()=>e.delete(t)),[e]);return[(0,y.useCallback)(t=>{let{type:n,event:r}=t;e.forEach(e=>e[n]?.call(e,r))},[e]),t]}var Wze={draggable:`
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.
diff --git a/static/index.html b/static/index.html
index b49bf7d75..aa0be6187 100644
--- a/static/index.html
+++ b/static/index.html
@@ -26,7 +26,7 @@
-
+