From c640ddc1f761e4e7fb2c6d05712e0ba237cf7f6b Mon Sep 17 00:00:00 2001 From: maziggy Date: Mon, 13 Jul 2026 08:59:36 +0200 Subject: [PATCH] fix(projects): carry tags, due date and priority in the list payload (#2536) The edit dialog is shared between the projects list and the project detail page and seeds itself from whichever project object it is handed. The list payload never carried tags, due_date or priority, so editing from the list showed a blank tags field -- and, unreported, submitted the dialog's default priority over a stored high/urgent one. The component read those fields through a cast, so the compiler never flagged that they were always absent. Put them on ProjectListResponse and ProjectListItem, drop the casts, and let an explicit null clear tags and due date the way it already clears budget and url -- an emptied field was previously sent as undefined and silently reverted. The template list was missing target_parts_count, which the same dialog edits. --- CHANGELOG.md | 1 + backend/app/api/routes/projects.py | 14 ++- backend/app/schemas/project.py | 7 ++ .../tests/integration/test_projects_api.py | 95 +++++++++++++++++++ .../src/__tests__/pages/ProjectsPage.test.tsx | 89 ++++++++++++++++- frontend/src/api/client.ts | 7 +- frontend/src/pages/ProjectsPage.tsx | 15 +-- .../{index-PHP-xpqR.js => index-xvC2pmGi.js} | 2 +- static/index.html | 2 +- 9 files changed, 218 insertions(+), 14 deletions(-) rename static/assets/{index-PHP-xpqR.js => index-xvC2pmGi.js} (98%) diff --git a/CHANGELOG.md b/CHANGELOG.md index faa1b06aa..67664bfbf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ All notable changes to Bambuddy will be documented in this file. ## [0.2.5b2] - Unreleased ### Fixed +- **A project's tags vanished from the edit dialog when you opened it from the projects list — and its priority was quietly reset when you saved (#2536, reporter @fireboyff)** — Editing a project from the Projects list showed an empty tags field; opening the same project first and editing it from inside showed the tags correctly. **One dialog, two callers.** `ProjectModal` is shared: the detail page hands it a full project, the list hands it a list item. The list endpoint's payload never carried `tags`, `due_date` or `priority`, so from the list the dialog seeded those three fields from `undefined` and rendered them blank. It compiled because the component read them through a cast (`project as ProjectListItem & { tags?: string }`), which asserts a field the type does not have — so TypeScript never pointed out that the value was always missing. The fields are now on `ProjectListResponse` and on `ProjectListItem`, the casts are gone, and the compiler enforces the two shapes agreeing from here on. **The part nobody reported.** The dialog does not send tags when the field is empty, so the tags themselves survived — they were only invisible. Priority is not so lucky: it is *always* sent, defaulting to `normal`. So editing a **high** or **urgent** project from the list silently demoted it, and the reporter would have had no reason to connect that to the empty field he did see. Fixing the payload fixes both, since the dialog now receives the real priority to send back. **Clearing a tag list also never worked, from either view.** An emptied field was sent as `undefined`, which drops the key from the request, and the backend only applied values that were not null — so the old tags came straight back. Tags and due date now behave like budget and URL already did: sent as null, cleared explicitly, and an omitted key still means "leave it alone". **Tests.** 4 backend cases (the list and the template list both carry the fields the dialog renders; a partial update does not disturb a stored priority or tags; an explicit null clears tags and due date) — mutation-verified, three of them fail against the old payload. 3 frontend cases pin the dialog: it prefills all three from a list item, it round-trips a stored `high` instead of submitting its default, and clearing the tags field sends null. The templates list was missing `target_parts_count` too, which the same dialog edits; that is fixed in passing. - **Scheduled backups to a NAS failed with "Read-only file system" — and our own systemd unit was the reason (#2544, reporter @pwostran)** — Nightly backups to a mounted NAS share had run since May and then stopped, failing every night with `[Errno 30] Read-only file system`. The reporter checked the folder permissions, which were correct: his mount is `gid=backup,dir_mode=0775`, the service user is in `backup`, and his own shell writes to the share fine. **Errno 30 is EROFS, and EROFS is not a permission error** — a permission problem is errno 13. EROFS means the filesystem itself refused the write, and the filesystem refused it because *we told it to*. Bambuddy's systemd unit ships `ProtectSystem=strict`, which mounts the entire filesystem read-only inside the service's own mount namespace and carves back out only `ReadWritePaths= `. A NAS share is not one of those three. Reads still work — which is why the UI happily listed his existing backups from the share while being unable to create a new one — and the operator's shell is outside the namespace entirely, so every check he could think to run said the directory was fine. **How a working install broke.** Both installers write `/etc/systemd/system/bambuddy.service` wholesale, so any `ReadWritePaths` an operator had added by hand disappeared on the next install, along with their backups. That is now fixed at the source: the installers back the old unit up (`.bak-`) and **carry the operator's extra writable paths forward** into the new one, reporting which ones they kept. The unit template also documents the carve-out, since the next person to read it has to be able to work out why a directory they can write to is read-only for the service. **The failure is no longer silent, or cryptic.** The output directory is now probed with a real write when you save it and when the backup card loads, so a directory Bambuddy cannot write to is caught there and then rather than at 03:00 for a week. When the probe fails, the card names the actual cause and hands over the exact fix with the operator's own path already in it — `sudo systemctl edit bambuddy` → `[Service]` → `ReadWritePaths=/mnt/nasbackup` — instead of quoting an errno. A failed backup run reports the same diagnosis rather than the raw OSError. EROFS outside systemd, permission-denied, out-of-space, not-a-directory and missing are told apart and worded accordingly, in all 11 locales. **A Docker trap caught on the way past.** A backup path inside the container that was never bind-mounted from the host is *writable* — the write lands in the container's ephemeral layer and vanishes on the next `compose up`. A backup that silently goes nowhere is the one failure mode a backup feature must not have, so the probe compares the directory's device against the container root and warns when they match, with the compose snippet that mounts it properly. **Tests.** 15 backend cases: EROFS under systemd is diagnosed as the sandbox and yields a copy-pasteable drop-in; EROFS *outside* systemd does not blame a unit that doesn't exist; EACCES stays a permission problem; the unit name is read from the cgroup (plain, templated, and the fallback when there's no `.service` in it); the probe leaves no file behind in the backup list; a container-layer path is flagged while a mounted volume is not; a failed run surfaces the diagnosis and not the errno; and four pin the installers, so a reinstall can never again drop a writable path or overwrite a unit without a backup. Verified against a real read-only mount, not a mocked one — the classifier was run against an actual `mount -o ro` tmpfs and returned the reporter's exact errno with the right remedy. 4 frontend cases on the banner. - **Docker never shut down gracefully — every stop, restart and update was a SIGKILL** — `CMD ["sh", "-c", "uvicorn ..."]` left the shell as PID 1 with uvicorn as its child, and dash does not forward signals. So `docker stop` SIGTERMed the shell and **uvicorn never heard about it**. Measured on the shipped image: the stop ran the full 10-second grace period, the container exited **137** (SIGKILL), and the log contained no "Shutting down" line at all — it simply stopped dead after `Uvicorn running on ...`. That means the entire shutdown path had never once executed in Docker: no SQLite WAL checkpoint, no MQTT disconnect (the broker saw an ungraceful drop every time), no virtual-printer teardown, no printer disconnect, no `engine.dispose()`. Not "when a camera is streaming" — *always*, on every `docker stop`, `docker restart`, `compose down` and image update. The fix is one word: `CMD ["sh", "-c", "exec uvicorn ..."]`. With `exec`, uvicorn *is* PID 1 and receives the signal. Verified on a rebuilt image: PID 1 is now `uvicorn`, `docker stop` completes in **1 second** with **exit code 0**, and the log shows `Shutting down` → `WAL checkpoint completed` → `Application shutdown complete`. - **`systemctl restart` could hang for 90 seconds and end in SIGKILL** — with a camera tile open, stopping Bambuddy would sit at `Waiting for connections to close.` until systemd gave up and killed it. Uvicorn's `timeout_graceful_shutdown` defaults to `None`, i.e. **wait forever** for in-flight requests, and an MJPEG camera stream is a response that never completes — `httptools`'s connection `shutdown()` only flips `keep_alive = False` on an in-flight cycle, it never closes the transport. So a single open stream pinned the process. Worse, the ordering is inverted: uvicorn only fires the **lifespan shutdown** — the code that would tear those streams down — *after* the connections drain, so the cleanup that would unblock the wait was itself blocked by the wait. Every launcher now passes `--timeout-graceful-shutdown 5`: the Dockerfile, the shipped `deploy/bambuddy.service`, the systemd unit and launchd plist emitted by `install/install.sh`, the SpoolBuddy installer's unit (a kiosk parked on the printers page holds exactly such a stream open, so this bit it on every reboot), and the Windows NSSM registration. On timeout uvicorn cancels the request tasks and the camera generators unwind cleanly on `CancelledError` — a path they already handled. `TimeoutStopSec` is raised to 30s on the systemd units as a backstop rather than the mechanism, and `stop_grace_period: 30s` added to the compose file so a slow teardown on a Pi isn't clipped. On Windows, NSSM's stop sequence was also force-killing uvicorn mid-teardown: its default `AppStopMethodConsole` is **1500 ms**, far less than uvicorn needs, so that is raised to 15s and the useless WM_CLOSE / thread-message stages (uvicorn is a console app with no window and no message loop) are skipped. **Tests.** 9 cases pinning every launcher — that the Dockerfile `exec`s, that each of the six launch points carries the timeout flag, that the systemd stop timeouts leave room for the teardown, and that NSSM waits long enough for the Ctrl-C. None of this shows up in a functional test: the app is perfectly healthy right up until you ask it to stop. diff --git a/backend/app/api/routes/projects.py b/backend/app/api/routes/projects.py index 28bf9852a..9cac1dcac 100644 --- a/backend/app/api/routes/projects.py +++ b/backend/app/api/routes/projects.py @@ -263,6 +263,9 @@ async def list_projects( target_count=project.target_count, target_parts_count=project.target_parts_count, budget=project.budget, + tags=project.tags, + due_date=project.due_date, + priority=project.priority, created_at=project.created_at, archive_count=archive_count, total_items=total_items, @@ -370,7 +373,11 @@ async def list_templates( color=project.color, status=project.status, target_count=project.target_count, + target_parts_count=project.target_parts_count, budget=project.budget, + tags=project.tags, + due_date=project.due_date, + priority=project.priority, created_at=project.created_at, archive_count=archive_count, queue_count=0, @@ -585,9 +592,12 @@ async def update_project( project.target_parts_count = data.target_parts_count if data.notes is not None: project.notes = data.notes - if data.tags is not None: + # Sent-but-null clears the field; omitted leaves it alone. Guarding on + # ``is not None`` would make an emptied tags field or a removed due date + # silently revert to the stored value (#2536). + if "tags" in data.model_fields_set: project.tags = data.tags - if data.due_date is not None: + if "due_date" in data.model_fields_set: project.due_date = data.due_date if data.priority is not None: if data.priority not in ["low", "normal", "high", "urgent"]: diff --git a/backend/app/schemas/project.py b/backend/app/schemas/project.py index 500fc3fae..2730e655f 100644 --- a/backend/app/schemas/project.py +++ b/backend/app/schemas/project.py @@ -151,6 +151,13 @@ class ProjectListResponse(BaseModel): target_count: int | None target_parts_count: int | None = None budget: float | None = None + # The edit dialog is shared with the project detail page and seeds its fields + # from whichever project object it is handed, so the list payload has to carry + # everything the dialog edits — otherwise a save from the list view submits a + # blank tags field and a default priority over the stored values (#2536). + tags: str | None = None + due_date: datetime | None = None + priority: str = "normal" created_at: datetime # Quick stats archive_count: int = 0 # Number of print jobs diff --git a/backend/tests/integration/test_projects_api.py b/backend/tests/integration/test_projects_api.py index a9540d12e..b5dae483a 100644 --- a/backend/tests/integration/test_projects_api.py +++ b/backend/tests/integration/test_projects_api.py @@ -1298,3 +1298,98 @@ class TestProjectExportImport: assert response.status_code == 200, response.text data = response.json() assert data["name"] == "nested-ok" + + +class TestProjectListEditableFields: + """Tests for #2536 — the project list payload must carry every field the + shared edit dialog renders. The dialog is opened from both the project list + and the project detail page and seeds itself from whichever project object it + is handed, so a field missing from the list payload shows up blank there and + is saved back over the stored value.""" + + @pytest.fixture + async def project_factory(self, db_session): + async def _create(**kwargs): + from backend.app.models.project import Project + + defaults = {"name": "Editable Fields Project", "color": "#123456"} + defaults.update(kwargs) + project = Project(**defaults) + db_session.add(project) + await db_session.commit() + await db_session.refresh(project) + return project + + return _create + + @pytest.mark.asyncio + @pytest.mark.integration + async def test_list_carries_the_fields_the_edit_dialog_renders(self, async_client: AsyncClient, project_factory): + """The list view is where the reporter saw an empty tags field.""" + from datetime import datetime + + await project_factory( + name="Tagged Project", + tags="prototype,client-work", + due_date=datetime(2026, 8, 1, 12, 0, 0), + priority="high", + target_parts_count=7, + ) + + response = await async_client.get("/api/v1/projects/") + assert response.status_code == 200 + item = next(p for p in response.json() if p["name"] == "Tagged Project") + + assert item["tags"] == "prototype,client-work" + assert item["due_date"].startswith("2026-08-01") + assert item["priority"] == "high" + assert item["target_parts_count"] == 7 + + @pytest.mark.asyncio + @pytest.mark.integration + async def test_template_list_carries_them_too(self, async_client: AsyncClient, project_factory): + """Templates feed the same dialog, so they need the same payload.""" + await project_factory( + name="Tagged Template", + is_template=True, + tags="reusable", + priority="urgent", + target_parts_count=3, + ) + + response = await async_client.get("/api/v1/projects/templates") + assert response.status_code == 200 + item = next(p for p in response.json() if p["name"] == "Tagged Template") + + assert item["tags"] == "reusable" + assert item["priority"] == "urgent" + assert item["target_parts_count"] == 3 + + @pytest.mark.asyncio + @pytest.mark.integration + async def test_priority_survives_an_edit_that_does_not_touch_it(self, async_client: AsyncClient, project_factory): + """A save from the list view used to submit the default priority over a + stored 'high' — the dialog never received the real one.""" + project = await project_factory(name="Important", priority="high", tags="keep-me") + + response = await async_client.patch(f"/api/v1/projects/{project.id}", json={"name": "Still Important"}) + assert response.status_code == 200 + + result = response.json() + assert result["priority"] == "high" + assert result["tags"] == "keep-me" + + @pytest.mark.asyncio + @pytest.mark.integration + async def test_explicit_null_clears_tags_and_due_date(self, async_client: AsyncClient, project_factory): + """Emptying the field in the dialog has to actually remove the value.""" + from datetime import datetime + + project = await project_factory(name="Clearable", tags="obsolete", due_date=datetime(2026, 8, 1, 12, 0, 0)) + + response = await async_client.patch(f"/api/v1/projects/{project.id}", json={"tags": None, "due_date": None}) + assert response.status_code == 200 + + result = response.json() + assert result["tags"] is None + assert result["due_date"] is None diff --git a/frontend/src/__tests__/pages/ProjectsPage.test.tsx b/frontend/src/__tests__/pages/ProjectsPage.test.tsx index 53c201135..3d5bdd918 100644 --- a/frontend/src/__tests__/pages/ProjectsPage.test.tsx +++ b/frontend/src/__tests__/pages/ProjectsPage.test.tsx @@ -2,7 +2,7 @@ * Tests for the ProjectsPage component. */ -import { describe, it, expect, beforeEach } from 'vitest'; +import { describe, it, expect, beforeEach, vi } from 'vitest'; import { screen, waitFor } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import { render } from '../utils'; @@ -379,4 +379,91 @@ describe('ProjectsPage', () => { expect(card).not.toBeNull(); }); }); + + describe('edit dialog seeds itself from the list payload (#2536)', () => { + /** + * The same ProjectModal is opened from the projects list and from the + * project detail page. The detail page hands it a full project; the list + * hands it a list item. Reporter saw an empty tags field when editing from + * the list, because the list payload didn't carry tags — and, unreported, + * the dialog then submitted its default priority over the stored one. + */ + const listItem = { + id: 7, + name: 'Spool holder', + description: null, + color: '#00ae42', + status: 'active', + target_count: null, + target_parts_count: null, + budget: null, + tags: 'prototype,client-work', + due_date: '2026-08-01T12:00:00Z', + priority: 'high', + created_at: '2024-01-01T00:00:00Z', + archive_count: 0, + total_items: 0, + completed_count: 0, + failed_count: 0, + queue_count: 0, + progress_percent: null, + archives: [], + url: null, + cover_image_filename: null, + }; + + const renderModal = (onSave: (data: unknown) => void) => + render( + {}} + onSave={onSave as never} + isLoading={false} + currencySymbol="€" + t={((k: string) => k) as never} + />, + ); + + const tagsInput = () => screen.getByPlaceholderText('projects.tagsPlaceholder') as HTMLInputElement; + const dueDateInput = () => document.querySelector('input[type="date"]') as HTMLInputElement; + const prioritySelect = () => + Array.from(document.querySelectorAll('select')).find((s) => + s.querySelector('option[value="urgent"]'), + ) as HTMLSelectElement; + + it('prefills tags, due date and priority from a list item', () => { + renderModal(() => {}); + + expect(tagsInput().value).toBe('prototype,client-work'); + expect(dueDateInput().value).toBe('2026-08-01'); + expect(prioritySelect().value).toBe('high'); + }); + + it('does not downgrade a stored priority when saving an untouched field', async () => { + const user = userEvent.setup(); + const onSave = vi.fn(); + renderModal(onSave); + + await user.click(screen.getByRole('button', { name: 'common.save' })); + + // Before the fix the dialog fell back to its 'normal' default and sent + // that, silently demoting a high/urgent project edited from the list. + expect(onSave).toHaveBeenCalledWith( + expect.objectContaining({ priority: 'high', tags: 'prototype,client-work' }), + ); + }); + + it('sends null when an existing tag list is cleared', async () => { + const user = userEvent.setup(); + const onSave = vi.fn(); + renderModal(onSave); + + await user.clear(tagsInput()); + await user.click(screen.getByRole('button', { name: 'common.save' })); + + // undefined would drop the key from the PATCH body and the backend would + // keep the old tags — the field has to be cleared explicitly. + expect(onSave).toHaveBeenCalledWith(expect.objectContaining({ tags: null })); + }); + }); }); diff --git a/frontend/src/api/client.ts b/frontend/src/api/client.ts index 5e188e42e..dc821ff55 100644 --- a/frontend/src/api/client.ts +++ b/frontend/src/api/client.ts @@ -923,6 +923,9 @@ export interface ProjectListItem { target_count: number | null; // Target number of plates/print jobs target_parts_count: number | null; // Target number of parts/objects budget: number | null; + tags: string | null; // #2536 — the shared edit dialog seeds itself from this + due_date: string | null; // #2536 + priority: string; // #2536 created_at: string; archive_count: number; // Number of print jobs (plates) total_items: number; // Sum of quantities (total items printed, including failed) @@ -958,8 +961,8 @@ export interface ProjectUpdate { target_count?: number; target_parts_count?: number; notes?: string; - tags?: string; - due_date?: string; + tags?: string | null; // #2536 — explicit null clears the tags + due_date?: string | null; // #2536 — explicit null clears the due date priority?: string; budget?: number | null; parent_id?: number; diff --git a/frontend/src/pages/ProjectsPage.tsx b/frontend/src/pages/ProjectsPage.tsx index 9d5daf6af..afe5d60b0 100644 --- a/frontend/src/pages/ProjectsPage.tsx +++ b/frontend/src/pages/ProjectsPage.tsx @@ -62,9 +62,9 @@ export function ProjectModal({ project, onClose, onSave, isLoading, currencySymb const [targetCount, setTargetCount] = useState(project?.target_count?.toString() || ''); const [targetPartsCount, setTargetPartsCount] = useState(project?.target_parts_count?.toString() || ''); const [status, setStatus] = useState(project?.status || 'active'); - const [tags, setTags] = useState((project as ProjectListItem & { tags?: string })?.tags || ''); - const [dueDate, setDueDate] = useState((project as ProjectListItem & { due_date?: string })?.due_date?.split('T')[0] || ''); - const [priority, setPriority] = useState((project as ProjectListItem & { priority?: string })?.priority || 'normal'); + const [tags, setTags] = useState(project?.tags || ''); + const [dueDate, setDueDate] = useState(project?.due_date?.split('T')[0] || ''); + const [priority, setPriority] = useState(project?.priority || 'normal'); const [budget, setBudget] = useState(project?.budget?.toString() || ''); const [url, setUrl] = useState(project?.url || ''); const [urlError, setUrlError] = useState(null); @@ -120,13 +120,14 @@ export function ProjectModal({ project, onClose, onSave, isLoading, currencySymb color, target_count: targetCount ? parseInt(targetCount, 10) : undefined, target_parts_count: targetPartsCount ? parseInt(targetPartsCount, 10) : undefined, - tags: tags.trim() || undefined, - due_date: dueDate || undefined, + // Null clears the stored value on edit; undefined omits the key on create. + // Sending undefined on edit would make an emptied field un-clearable. + tags: project ? (tags.trim() || null) : (tags.trim() || undefined), + due_date: project ? (dueDate || null) : (dueDate || undefined), priority, budget: budget.trim() ? parseFloat(budget) : null, // Pydantic accepts null to clear the URL; an empty string would fail the - // http(s) prefix validator. Use undefined for create (omit) and null for - // edit-with-cleared-value. + // http(s) prefix validator. url: project ? (trimmedUrl || null) : (trimmedUrl || undefined), ...(project && { status }), }); diff --git a/static/assets/index-PHP-xpqR.js b/static/assets/index-xvC2pmGi.js similarity index 98% rename from static/assets/index-PHP-xpqR.js rename to static/assets/index-xvC2pmGi.js index b9569369f..5c15bb579 100644 --- a/static/assets/index-PHP-xpqR.js +++ b/static/assets/index-xvC2pmGi.js @@ -8718,7 +8718,7 @@ ${t.slice(l+2)}`,d+=1;else break}t.push({indent:l,number:parseInt(s,10),content: `+n+`]`;if(typeof e==`object`){let r=Object.entries(e);return r.length===0?`{}`:`{ `+r.map(([e,r])=>n+` `+JSON.stringify(e)+`: `+O6(r,t+1)).join(`, `)+` -`+n+`}`}return String(e)}function GUe({setting:e,onClose:t,onDeleted:n,onDuplicate:r,onEdit:i,hasPermission:a,t:o}){let{showToast:s}=kd(),c=to(),[l,u]=(0,y.useState)(!1),{data:d,isLoading:f}=q({queryKey:[`cloudSettingDetail`,e.setting_id],queryFn:()=>Q.getCloudSettingDetail(e.setting_id)}),p=J({mutationFn:()=>Q.deleteCloudSetting(e.setting_id),onSuccess:()=>{s(o(`profiles.presets.toast.deleted`)),c.invalidateQueries({queryKey:[`cloudSettings`]}),n()},onError:e=>s(e.message,`error`)}),m=T6(e.setting_id),h=w6(e.name,d?.setting?.inherits);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)(xd,{className:`w-full max-w-3xl max-h-[90vh] flex flex-col overflow-hidden`,children:(0,K.jsxs)(Cd,{className:`p-0 flex flex-col min-h-0 flex-1`,children:[(0,K.jsxs)(`div`,{className:`flex-shrink-0 flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`h2`,{className:`text-xl font-semibold text-white truncate`,children:e.name}),m&&(0,K.jsx)(`span`,{className:`px-2 py-0.5 text-xs font-medium bg-bambu-green/20 text-bambu-green rounded-full`,children:o(`profiles.presets.editable`)})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mt-1 text-sm text-bambu-gray`,children:[(0,K.jsx)(`span`,{className:`capitalize`,children:o(`profiles.presets.types.${e.type}`)}),h.printer&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`span`,{children:`•`}),(0,K.jsx)(`span`,{children:h.printer})]})]})]}),(0,K.jsx)(`button`,{onClick:t,className:`p-2 text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary rounded-lg transition-colors`,children:(0,K.jsx)(Hu,{className:`w-5 h-5`})})]}),(0,K.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-4`,children:f?(0,K.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,K.jsx)(X,{className:`w-8 h-8 text-bambu-green animate-spin`})}):d?(0,K.jsx)(`pre`,{className:`text-xs text-bambu-gray font-mono whitespace-pre-wrap break-all bg-bambu-dark p-4 rounded-lg border border-bambu-dark-tertiary overflow-x-auto max-w-full`,children:O6(d)}):(0,K.jsx)(`div`,{className:`text-center py-16 text-bambu-gray`,children:o(`profiles.presets.failedToLoadDetails`)})}),l?(0,K.jsxs)(`div`,{className:`flex-shrink-0 p-4 border-t border-bambu-dark-tertiary bg-red-500/5`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-3 text-red-700 dark:text-red-400`,children:[(0,K.jsx)(wu,{className:`w-5 h-5`}),(0,K.jsx)(`span`,{className:`font-medium`,children:o(`profiles.presets.deleteConfirm`)})]}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4`,children:o(`profiles.presets.deleteWarning`,{name:e.name})}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:()=>u(!1),disabled:p.isPending,className:`flex-1`,children:o(`common.cancel`)}),(0,K.jsxs)($,{variant:`danger`,onClick:()=>p.mutate(),disabled:p.isPending,className:`flex-1`,children:[p.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(xu,{className:`w-4 h-4`}),o(`common.delete`)]})]})]}):(0,K.jsx)(`div`,{className:`flex-shrink-0 p-4 border-t border-bambu-dark-tertiary`,children:(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:t,className:`flex-1`,children:o(`common.close`)}),(0,K.jsxs)($,{variant:`secondary`,onClick:r,disabled:!a(`cloud:auth`),title:a(`cloud:auth`)?void 0:o(`profiles.presets.noDuplicatePermission`),children:[(0,K.jsx)(As,{className:`w-4 h-4`}),o(`profiles.presets.duplicate`)]}),m&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)($,{variant:`secondary`,onClick:i,disabled:f||!d||!a(`cloud:auth`),title:a(`cloud:auth`)?void 0:o(`profiles.presets.noEditPermission`),children:[(0,K.jsx)(yl,{className:`w-4 h-4`}),o(`common.edit`)]}),(0,K.jsx)($,{variant:`danger`,onClick:()=>u(!0),disabled:!a(`cloud:auth`),title:a(`cloud:auth`)?void 0:o(`profiles.presets.noDeletePermission`),children:(0,K.jsx)(xu,{className:`w-4 h-4`})})]})]})})]})})})}function k6(){try{let e=localStorage.getItem(`bambusy_preset_templates`);return e?JSON.parse(e):[]}catch{return[]}}function A6(e){localStorage.setItem(`bambusy_preset_templates`,JSON.stringify(e))}function KUe({onClose:e,onApply:t,t:n}){let{showToast:r}=kd(),[i,a]=(0,y.useState)(k6),[o,s]=(0,y.useState)(`all`),[c,l]=(0,y.useState)(null),[u,d]=(0,y.useState)(``),[f,p]=(0,y.useState)(``),[m,h]=(0,y.useState)(`{}`),[g,_]=(0,y.useState)(null),[v,b]=(0,y.useState)(null),x=o===`all`?i:i.filter(e=>e.type===o),S=e=>{a(e),A6(e)},C=e=>{S(i.filter(t=>t.id!==e)),b(null),r(n(`profiles.templates.toast.deleted`))},w=e=>{l(e.id),d(e.name),p(e.description),h(JSON.stringify(e.settings,null,2)),_(null)},T=()=>{if(!(!c||!u.trim()))try{let e=JSON.parse(m);S(i.map(t=>t.id===c?{...t,name:u.trim(),description:f.trim(),settings:e}:t)),l(null),r(n(`profiles.templates.toast.updated`))}catch(e){_(e.message)}},E=()=>{l(null),d(``),p(``),h(`{}`),_(null)},D=e=>{S(i.map(t=>t.id===e?{...t,showInModal:!t.showInModal}:t))},O={filament:{label:n(`profiles.presets.types.filament`),icon:Bs,color:`text-amber-600 dark:text-amber-400`},print:{label:n(`profiles.presets.types.process`),icon:Ul,color:`text-blue-600 dark:text-blue-400`},printer:{label:n(`profiles.presets.types.printer`),icon:El,color:`text-purple-600 dark:text-purple-400`}},k=v?i.find(e=>e.id===v):null;return(0,y.useEffect)(()=>{let t=t=>{t.key===`Escape`&&(v?b(null):c?E():e())};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[v,c,e]),(0,K.jsxs)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:[k&&(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-60`,children:(0,K.jsx)(xd,{className:`w-full max-w-md`,children:(0,K.jsxs)(Cd,{className:`p-6`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3 mb-4`,children:[(0,K.jsx)(`div`,{className:`p-2 bg-red-500/20 rounded-lg`,children:(0,K.jsx)(wu,{className:`w-6 h-6 text-red-600 dark:text-red-400`})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h3`,{className:`text-lg font-semibold text-white`,children:n(`profiles.templates.deleteTitle`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`profiles.templates.deleteWarning`)})]})]}),(0,K.jsx)(`p`,{className:`text-white mb-6`,children:n(`profiles.templates.deleteConfirm`,{name:k.name})}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:()=>b(null),className:`flex-1`,children:n(`common.cancel`)}),(0,K.jsxs)($,{onClick:()=>C(v),className:`flex-1 bg-red-500 hover:bg-red-600`,children:[(0,K.jsx)(xu,{className:`w-4 h-4`}),n(`common.delete`)]})]})]})})}),(0,K.jsx)(xd,{className:`w-full max-w-2xl max-h-[80vh] flex flex-col`,children:(0,K.jsxs)(Cd,{className:`p-0 flex flex-col h-full`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(iu,{className:`w-5 h-5 text-amber-600 dark:text-amber-400`}),n(`profiles.templates.title`)]}),(0,K.jsx)(`button`,{onClick:e,className:`text-bambu-gray hover:text-white`,children:(0,K.jsx)(Hu,{className:`w-5 h-5`})})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 p-4 border-b border-bambu-dark-tertiary`,children:[(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:n(`profiles.templates.typeFilter`)}),[`all`,`filament`,`print`,`printer`].map(e=>(0,K.jsx)(`button`,{onClick:()=>s(e),className:`px-3 py-1 text-sm rounded-lg transition-colors ${o===e?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white`}`,children:e===`all`?n(`common.all`):O[e].label},e))]}),(0,K.jsx)(`div`,{className:`flex-1 overflow-y-auto p-4`,children:x.length===0?(0,K.jsxs)(`div`,{className:`text-center py-12 text-bambu-gray`,children:[(0,K.jsx)(iu,{className:`w-12 h-12 mx-auto mb-4 opacity-30`}),(0,K.jsx)(`p`,{children:n(`profiles.templates.noTemplates`)}),(0,K.jsx)(`p`,{className:`text-sm mt-1`,children:n(`profiles.templates.createFirst`)})]}):(0,K.jsx)(`div`,{className:`space-y-2`,children:x.map(e=>{let r=O[e.type],i=r.icon;return c===e.id?(0,K.jsxs)(`div`,{className:`p-4 bg-bambu-dark rounded-lg border border-bambu-green`,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-3 mb-3`,children:[(0,K.jsx)(`input`,{type:`text`,value:u,onChange:e=>d(e.target.value),placeholder:n(`profiles.templates.namePlaceholder`),className:`px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`,autoFocus:!0}),(0,K.jsx)(`input`,{type:`text`,value:f,onChange:e=>p(e.target.value),placeholder:n(`profiles.templates.descriptionPlaceholder`),className:`px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`})]}),(0,K.jsxs)(`div`,{className:`mb-3`,children:[(0,K.jsx)(`label`,{className:`text-xs text-bambu-gray mb-1 block`,children:n(`profiles.templates.settingsJson`)}),(0,K.jsx)(`textarea`,{value:m,onChange:e=>{h(e.target.value),_(null)},rows:6,className:`w-full px-3 py-2 bg-bambu-dark-secondary border rounded text-white text-sm font-mono focus:outline-none ${g?`border-red-500`:`border-bambu-dark-tertiary focus:border-bambu-green`}`}),g&&(0,K.jsx)(`p`,{className:`text-xs text-red-700 dark:text-red-400 mt-1`,children:g})]}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsxs)($,{size:`sm`,onClick:T,disabled:!u.trim(),children:[(0,K.jsx)(Pl,{className:`w-4 h-4`}),`Save`]}),(0,K.jsx)($,{size:`sm`,variant:`secondary`,onClick:E,children:`Cancel`})]})]},e.id):(0,K.jsxs)(`div`,{className:`flex items-center gap-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary hover:border-bambu-gray-dark transition-colors`,children:[(0,K.jsx)(i,{className:`w-5 h-5 ${r.color} flex-shrink-0`}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsx)(`p`,{className:`text-sm font-medium text-white`,children:e.name}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray truncate`,children:e.description})]}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray-dark px-2 py-1 bg-bambu-dark-secondary rounded`,children:n(`profiles.templates.fieldsCount`,{count:Object.keys(e.settings).length})}),(0,K.jsx)(`button`,{onClick:()=>D(e.id),className:`p-1 transition-colors ${e.showInModal?`text-bambu-green hover:text-bambu-green/70`:`text-bambu-gray hover:text-white`}`,title:e.showInModal?n(`profiles.templates.shownInModals`):n(`profiles.templates.hiddenInModals`),children:e.showInModal?(0,K.jsx)(Js,{className:`w-4 h-4`}):(0,K.jsx)(qs,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>t(e),className:`px-3 py-1 text-xs bg-bambu-green/20 text-bambu-green rounded hover:bg-bambu-green/30 transition-colors`,children:n(`profiles.templates.apply`)}),(0,K.jsx)(`button`,{onClick:()=>w(e),className:`p-1 text-bambu-gray hover:text-white`,title:n(`common.edit`),children:(0,K.jsx)(yl,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>b(e.id),className:`p-1 text-bambu-gray hover:text-red-600 dark:hover:text-red-400`,title:n(`common.delete`),children:(0,K.jsx)(xu,{className:`w-4 h-4`})})]},e.id)})})})]})})]})}function j6({onClose:e,leftPreset:t,rightPreset:n,leftLabel:r,rightLabel:i,t:a}){let[o,s]=(0,y.useState)(`changes`),[c,l]=(0,y.useState)(``),u=(0,y.useMemo)(()=>{let e=new Set([...Object.keys(t),...Object.keys(n)]),r=[];for(let i of e){if(i===`inherits`||i===`version`)continue;let e=t[i],a=n[i],o=i in t,s=i in n,c;c=!o&&s?`added`:o&&!s?`removed`:JSON.stringify(e)===JSON.stringify(a)?`same`:`changed`,r.push({key:i,left:e,right:a,status:c})}return r.sort((e,t)=>{let n={changed:0,added:1,removed:2,same:3};return n[e.status]===n[t.status]?e.key.localeCompare(t.key):n[e.status]-n[t.status]})},[t,n]),d=(0,y.useMemo)(()=>{let e=[...u];if(o===`changes`&&(e=e.filter(e=>e.status!==`same`)),c){let t=c.toLowerCase();e=e.filter(e=>e.key.toLowerCase().includes(t)||String(e.left).toLowerCase().includes(t)||String(e.right).toLowerCase().includes(t))}return e},[u,o,c]),f=(0,y.useMemo)(()=>({added:u.filter(e=>e.status===`added`).length,removed:u.filter(e=>e.status===`removed`).length,changed:u.filter(e=>e.status===`changed`).length,same:u.filter(e=>e.status===`same`).length}),[u]),p=e=>{if(e===void 0)return`—`;if(e===null)return`null`;if(Array.isArray(e))return e.length===0?`[]`:e.length===1?String(e[0]):e.join(`, `);if(typeof e==`object`)return JSON.stringify(e);let t=String(e);if(t.includes(`\\n`)||t.length>100){let e=t.split(`\\n`).length;if(e>1)return`[${e} lines of G-code/script]`;if(t.length>100)return t.substring(0,100)+`…`}return t};return(0,y.useEffect)(()=>{let t=t=>{t.key===`Escape`&&e()};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e]),(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,K.jsx)(xd,{className:`w-full max-w-4xl max-h-[85vh] flex flex-col overflow-hidden`,children:(0,K.jsxs)(Cd,{className:`p-0 flex flex-col min-h-0 flex-1`,children:[(0,K.jsxs)(`div`,{className:`flex-shrink-0 flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(gc,{className:`w-5 h-5 text-blue-600 dark:text-blue-400`}),a(`profiles.diff.title`)]}),(0,K.jsx)(`button`,{onClick:e,className:`text-bambu-gray hover:text-white`,children:(0,K.jsx)(Hu,{className:`w-5 h-5`})})]}),(0,K.jsxs)(`div`,{className:`flex-shrink-0 grid grid-cols-2 gap-4 p-4 border-b border-bambu-dark-tertiary bg-bambu-dark`,children:[(0,K.jsxs)(`div`,{className:`text-center`,children:[(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:a(`profiles.diff.left`)}),(0,K.jsx)(`p`,{className:`text-white font-medium truncate`,children:r})]}),(0,K.jsxs)(`div`,{className:`text-center`,children:[(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:a(`profiles.diff.right`)}),(0,K.jsx)(`p`,{className:`text-white font-medium truncate`,children:i})]})]}),(0,K.jsxs)(`div`,{className:`flex-shrink-0 flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-4 text-sm`,children:[(0,K.jsxs)(`span`,{className:`flex items-center gap-1 text-green-700 dark:text-green-400`,children:[(0,K.jsx)(Cl,{className:`w-3.5 h-3.5`}),f.added,` `,a(`profiles.diff.added`)]}),(0,K.jsxs)(`span`,{className:`flex items-center gap-1 text-red-700 dark:text-red-400`,children:[(0,K.jsx)(rl,{className:`w-3.5 h-3.5`}),f.removed,` `,a(`profiles.diff.removed`)]}),(0,K.jsxs)(`span`,{className:`flex items-center gap-1 text-amber-700 dark:text-amber-400`,children:[(0,K.jsx)(Mo,{className:`w-3.5 h-3.5`}),f.changed,` `,a(`profiles.diff.changed`)]}),(0,K.jsxs)(`span`,{className:`flex items-center gap-1 text-bambu-gray`,children:[(0,K.jsx)(Ws,{className:`w-3.5 h-3.5`}),f.same,` `,a(`profiles.diff.same`)]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(zl,{className:`absolute left-2 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,K.jsx)(`input`,{type:`text`,value:c,onChange:e=>l(e.target.value),placeholder:a(`profiles.diff.searchFields`),className:`pl-8 pr-3 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none w-48`})]}),f.same>0&&(0,K.jsxs)(`div`,{className:`flex rounded overflow-hidden border border-bambu-dark-tertiary`,children:[(0,K.jsx)(`button`,{onClick:()=>s(`changes`),className:`px-3 py-1.5 text-sm transition-colors ${o===`changes`?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white`}`,children:a(`profiles.diff.changes`)}),(0,K.jsx)(`button`,{onClick:()=>s(`all`),className:`px-3 py-1.5 text-sm transition-colors ${o===`all`?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white`}`,children:a(`common.all`)})]})]})]}),(0,K.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto`,children:d.length===0?(0,K.jsxs)(`div`,{className:`text-center py-12 text-bambu-gray`,children:[(0,K.jsx)(Ws,{className:`w-12 h-12 mx-auto mb-4 opacity-30`}),(0,K.jsx)(`p`,{children:a(o===`changes`?`profiles.diff.noDifferences`:`profiles.diff.noFieldsMatch`)})]}):(0,K.jsxs)(`table`,{className:`w-full`,children:[(0,K.jsx)(`thead`,{className:`sticky top-0 bg-bambu-dark-secondary`,children:(0,K.jsxs)(`tr`,{className:`text-sm text-bambu-gray border-b border-bambu-dark-tertiary`,children:[(0,K.jsx)(`th`,{className:`text-left p-3 w-1/3`,children:a(`profiles.diff.field`)}),(0,K.jsx)(`th`,{className:`text-left p-3 w-1/3`,children:r}),(0,K.jsx)(`th`,{className:`text-left p-3 w-1/3`,children:i})]})}),(0,K.jsx)(`tbody`,{children:d.map(e=>{let t={added:`bg-green-500/10`,removed:`bg-red-500/10`,changed:`bg-amber-500/10`,same:``}[e.status],n={added:(0,K.jsx)(Cl,{className:`w-3.5 h-3.5 text-green-600 dark:text-green-400`}),removed:(0,K.jsx)(rl,{className:`w-3.5 h-3.5 text-red-600 dark:text-red-400`}),changed:(0,K.jsx)(Mo,{className:`w-3.5 h-3.5 text-amber-600 dark:text-amber-400`}),same:(0,K.jsx)(Ws,{className:`w-3.5 h-3.5 text-bambu-gray-dark`})}[e.status];return(0,K.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary ${t}`,children:[(0,K.jsx)(`td`,{className:`p-3`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[n,(0,K.jsx)(`span`,{className:`text-sm text-white font-mono`,children:e.key})]})}),(0,K.jsx)(`td`,{className:`p-3`,children:(0,K.jsx)(`span`,{className:`text-sm font-mono break-all ${e.status===`removed`?`text-red-700 dark:text-red-300`:e.status===`changed`?`text-white`:`text-bambu-gray`}`,children:p(e.left)})}),(0,K.jsx)(`td`,{className:`p-3`,children:(0,K.jsx)(`span`,{className:`text-sm font-mono break-all ${e.status===`added`?`text-green-700 dark:text-green-300`:e.status===`changed`?`text-white`:`text-bambu-gray`}`,children:p(e.right)})})]},e.key)})})]})})]})})})}function qUe({onClose:e,initialData:t,allPresets:n,t:r}){let{showToast:i}=kd(),a=to(),o=!!t?.setting_id,[s,c]=(0,y.useState)(`common`),[l,u]=(0,y.useState)(t?.type||`filament`),[d,f]=(0,y.useState)(t?.name?o?t.name:`${t.name} (Copy)`:``),[p,m]=(0,y.useState)(t?.base_id||``),[h,g]=(0,y.useState)(``),[_,v]=(0,y.useState)(t?.setting||{inherits:``}),[b,x]=(0,y.useState)(JSON.stringify(t?.setting||{inherits:``},null,2)),[S,C]=(0,y.useState)(null),[w,T]=(0,y.useState)(``),[E,D]=(0,y.useState)(!1),[O,k]=(0,y.useState)(``),[A,j]=(0,y.useState)(!1),[M,N]=(0,y.useState)(k6),[P,F]=(0,y.useState)(!1),[I,L]=(0,y.useState)(``),[R,z]=(0,y.useState)(``),[B,V]=(0,y.useState)(!0),[ee,te]=(0,y.useState)(null),[ne,re]=(0,y.useState)(!1),ie=(0,y.useMemo)(()=>({filament:n.filament,print:n.process,printer:n.printer})[l]||[],[n,l]),H=(0,y.useMemo)(()=>ie.filter(e=>T6(e.setting_id)),[ie]),{data:ae}=q({queryKey:[`cloudFields`,l],queryFn:()=>Q.getCloudFields(l===`print`?`process`:l),staleTime:1e3*60*60}),{data:oe}=q({queryKey:[`allPresetDetails`,l,H.map(e=>e.setting_id).join(`,`)],queryFn:async()=>{let e={};for(let t=0;t{try{let t=await Q.getCloudSettingDetail(e.setting_id);return{id:e.setting_id,detail:t}}catch{return null}}))).forEach(t=>{t&&(e[t.id]=t.detail)})}return e},enabled:H.length>0,staleTime:1e3*60*10}),{data:U,isLoading:se}=q({queryKey:[`cloudSettingDetail`,p],queryFn:()=>Q.getCloudSettingDetail(p),enabled:!!p});(0,y.useEffect)(()=>{s!==`json`&&x(JSON.stringify(_,null,2))},[_,s]);let ce=(0,y.useMemo)(()=>({filament:n.filament,print:n.process,printer:n.printer}[l]||[]).filter(e=>!T6(e.setting_id)).sort((e,t)=>e.name.localeCompare(t.name)),[n,l]);(0,y.useEffect)(()=>{if(!p)return;let e=ce.find(e=>e.setting_id===p);e&&(g(e.name),o||(v({inherits:e.name}),x(JSON.stringify({inherits:e.name},null,2))))},[p,ce,o]);let le=(0,y.useMemo)(()=>{let e=ae?.fields||[],t=new Set(e.map(e=>e.key)),n=new Set,i=new Set([`inherits`,`updated_time`,`compatible_printers`,`compatible_prints`]);oe&&Object.values(oe).forEach(e=>{e?.setting&&Object.keys(e.setting).forEach(e=>{!t.has(e)&&!i.has(e)&&n.add(e)})}),Object.keys(_).forEach(e=>{!t.has(e)&&!i.has(e)&&n.add(e)});let a=Array.from(n).sort().map(e=>({key:e,label:e.replace(/_/g,` `).replace(/\b\w/g,e=>e.toUpperCase()),type:`text`,category:`discovered`,description:r(`profiles.presets.discoveredFromPresets`)}));return[...e,...a]},[ae,oe,_,r]),ue=le.filter(e=>e.label.toLowerCase().includes(w.toLowerCase())||e.key.toLowerCase().includes(w.toLowerCase())),de=()=>{if(O.trim()){let e=O.trim().toLowerCase().replace(/\s+/g,`_`);fe(e,``),k(``),j(!1),i(r(`profiles.presets.toast.fieldAdded`,{key:e}))}},fe=(e,t)=>{v(n=>{let r={...n};return t===``||t===void 0?delete r[e]:r[e]=t,r})},pe=e=>{v(t=>({...t,...e.settings})),te(e.name),i(r(`profiles.templates.toast.applied`))},me=()=>{if(!I.trim())return;let e={..._};if(delete e.inherits,Object.keys(e).length===0){i(r(`profiles.presets.noOverridesToSave`),`error`);return}let t={id:Date.now().toString(),name:I.trim(),description:R.trim()||r(`profiles.presets.customTemplate`),type:l,settings:e,showInModal:B},n=[...M,t];N(n),A6(n),F(!1),L(``),z(``),V(!0),i(r(`profiles.templates.toast.created`))},he=(0,y.useMemo)(()=>M.filter(e=>e.type===l&&e.showInModal),[l,M]),ge=e=>{x(e);try{v(JSON.parse(e)),C(null)}catch(e){C(e.message)}},_e=e=>{e.preventDefault(),D(!1);let t=e.dataTransfer.files[0];if(t&&t.name.endsWith(`.json`)){let e=new FileReader;e.onload=e=>{try{let t=e.target?.result,n=JSON.parse(t),a=n.setting||n;v(e=>({...e,...a})),x(JSON.stringify({..._,...a},null,2)),i(r(`profiles.presets.fileImported`))}catch{i(r(`profiles.presets.invalidJsonFile`),`error`)}},e.readAsText(t)}},ve=J({mutationFn:()=>{let e={..._},t=l===`filament`?`filament_settings_id`:l===`print`?`print_settings_id`:`printer_settings_id`;e[t]=`"${d}"`;let n={type:l,name:d,base_id:p,setting:e};return Q.createCloudSetting(n)},onSuccess:async()=>{i(r(`profiles.presets.toast.created`)),await a.refetchQueries({queryKey:[`cloudSettings`]}),e()},onError:e=>i(e.message,`error`)}),ye=J({mutationFn:()=>{if(!t?.setting_id)throw Error(r(`profiles.presets.noSettingId`));return Q.updateCloudSetting(t.setting_id,{name:d,setting:_})},onSuccess:async()=>{i(r(`profiles.presets.toast.updated`)),a.removeQueries({queryKey:[`cloudSettingDetail`]}),await a.refetchQueries({queryKey:[`cloudSettings`]}),e()},onError:e=>i(e.message,`error`)}),be=o?ye:ve,xe=U?.setting?.inherits,Se=xe?ce.find(e=>e.name===xe):void 0,{data:Ce}=q({queryKey:[`cloudSettingDetail`,Se?.setting_id],queryFn:()=>Q.getCloudSettingDetail(Se.setting_id),enabled:!!Se?.setting_id}),we=(0,y.useMemo)(()=>{let e=Ce?.setting||{},t=U?.setting||{},n=p&&oe?.[p]?.setting?oe[p].setting:{};return{...e,...t,...n}},[p,U,Ce,oe]),Te=e=>{if(e==null)return``;if(Array.isArray(e)){let t=[...new Set(e.map(e=>String(e)))];return t.length===1?t[0]:e.join(`, `)}return String(e)},Ee=e=>{let t=_[e.key],n=we[e.key],i=Te(n),a=se?r(`common.loading`):i||``,o=`w-full px-3 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`;if(e.type===`boolean`){let r=t===`1`||t===void 0&&n===`1`;return(0,K.jsx)(`button`,{type:`button`,onClick:()=>fe(e.key,t===`1`?`0`:`1`),className:`w-8 h-5 rounded-full transition-colors ${r?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,children:(0,K.jsx)(`div`,{className:`w-4 h-4 rounded-full bg-white shadow transition-transform ${r?`translate-x-3.5`:`translate-x-0.5`}`})})}return e.type===`select`?(0,K.jsxs)(`select`,{value:t||``,onChange:t=>fe(e.key,t.target.value),className:o,children:[(0,K.jsx)(`option`,{value:``,children:a}),e.options?.map(e=>(0,K.jsx)(`option`,{value:e.value,children:e.label},e.value))]}):(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`input`,{type:e.type===`number`?`number`:`text`,value:t===void 0?``:String(t),onChange:t=>fe(e.key,t.target.value),step:e.step,min:e.min,max:e.max,placeholder:a,className:o}),e.unit&&(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:e.unit})]})},De=(0,y.useMemo)(()=>U?.setting?U.setting:{},[U]);return(0,K.jsxs)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,onDragOver:e=>{e.preventDefault(),D(!0)},onDragLeave:()=>D(!1),onDrop:_e,children:[ne&&p&&(0,K.jsx)(j6,{onClose:()=>re(!1),leftPreset:De,rightPreset:_,leftLabel:r(`profiles.presets.baseLabel`,{name:h||p}),rightLabel:r(`profiles.presets.currentLabel`,{name:d||r(`profiles.presets.newPreset`)}),t:r}),(0,K.jsx)(xd,{className:`w-full max-w-6xl max-h-[90vh] flex flex-col overflow-y-auto`,children:(0,K.jsxs)(Cd,{className:`p-0 flex flex-col h-full`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h2`,{className:`text-xl font-semibold text-white`,children:r(o?`profiles.presets.editPreset`:t?`profiles.presets.duplicatePreset`:`profiles.presets.createNewPreset`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:r(`profiles.presets.customizeSettings`)})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[p&&(0,K.jsxs)(`button`,{onClick:()=>re(!0),className:`flex items-center gap-2 px-3 py-2 text-sm text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary rounded-lg transition-colors`,title:r(`profiles.presets.compareWithBase`),children:[(0,K.jsx)(gc,{className:`w-4 h-4`}),r(`profiles.presets.compare`)]}),(0,K.jsx)(`button`,{onClick:e,className:`p-2 text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary rounded-lg transition-colors`,children:(0,K.jsx)(Hu,{className:`w-5 h-5`})})]})]}),E&&(0,K.jsx)(`div`,{className:`absolute inset-0 bg-bambu-green/10 border-2 border-dashed border-bambu-green rounded-lg flex items-center justify-center z-10`,children:(0,K.jsxs)(`div`,{className:`text-center`,children:[(0,K.jsx)(Ou,{className:`w-12 h-12 text-bambu-green mx-auto mb-2`}),(0,K.jsx)(`p`,{className:`text-bambu-green font-medium`,children:r(`profiles.presets.dropJsonToImport`)})]})}),(0,K.jsxs)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary space-y-3`,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-3 gap-4 max-[640px]:grid-cols-1`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`common.type`)}),(0,K.jsxs)(`select`,{value:l,onChange:e=>{u(e.target.value),m(``)},className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,K.jsx)(`option`,{value:`filament`,children:r(`profiles.presets.types.filament`)}),(0,K.jsx)(`option`,{value:`print`,children:r(`profiles.presets.types.process`)}),(0,K.jsx)(`option`,{value:`printer`,children:r(`profiles.presets.types.printer`)})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`profiles.presets.basePreset`)}),(0,K.jsxs)(`select`,{value:p,onChange:e=>m(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,children:[(0,K.jsx)(`option`,{value:``,children:r(`profiles.presets.selectBasePreset`)}),ce.map(e=>(0,K.jsx)(`option`,{value:e.setting_id,children:e.name},e.setting_id))]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`profiles.presets.presetName`)}),(0,K.jsx)(`input`,{type:`text`,value:d,onChange:e=>f(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,placeholder:r(`profiles.presets.myCustomPreset`)})]})]}),h&&(0,K.jsx)(`div`,{className:`text-xs text-bambu-gray`,children:(0,K.jsxs)(`p`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(ts,{className:`w-3 h-3 text-bambu-green`}),r(`profiles.presets.inheritsFrom`),` `,(0,K.jsx)(`span`,{className:`text-white`,children:h}),se&&(0,K.jsx)(X,{className:`w-3 h-3 animate-spin ml-1`})]})})]}),(0,K.jsxs)(`div`,{className:`flex border-b border-bambu-dark-tertiary max-[640px]:flex-wrap max-[640px]:items-center`,children:[(0,K.jsxs)(`button`,{onClick:()=>c(`common`),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${s===`common`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-white border-transparent`}`,children:[(0,K.jsx)(eu,{className:`w-4 h-4`}),r(`profiles.presets.tabs.common`)]}),(0,K.jsxs)(`button`,{onClick:()=>c(`fields`),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${s===`fields`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-white border-transparent`}`,children:[(0,K.jsx)(Uc,{className:`w-4 h-4`}),r(`profiles.presets.tabs.allFields`)]}),(0,K.jsxs)(`button`,{onClick:()=>c(`json`),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${s===`json`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-white border-transparent`}`,children:[(0,K.jsx)(ws,{className:`w-4 h-4`}),`JSON`,S&&(0,K.jsx)(ls,{className:`w-3 h-3 text-red-600 dark:text-red-400`})]}),(0,K.jsx)(`div`,{className:`flex-1 max-[640px]:hidden`}),(0,K.jsxs)(`button`,{onClick:()=>{let e=new Blob([JSON.stringify({name:d,type:l,base_id:p,setting:_},null,2)],{type:`application/json`}),t=URL.createObjectURL(e),n=document.createElement(`a`);n.href=t,n.download=`${d||`preset`}.json`,document.body.appendChild(n),n.click(),document.body.removeChild(n),URL.revokeObjectURL(t),i(r(`profiles.presets.toast.exported`))},className:`flex items-center gap-2 px-4 py-3 text-sm text-bambu-gray hover:text-white transition-colors`,title:r(`profiles.presets.exportToJson`),children:[(0,K.jsx)(zs,{className:`w-4 h-4`}),r(`common.download`)]}),(0,K.jsxs)(`button`,{onClick:()=>document.getElementById(`file-import`)?.click(),className:`flex items-center gap-2 px-4 py-3 text-sm text-bambu-gray hover:text-white transition-colors`,title:r(`profiles.presets.importFromJson`),children:[(0,K.jsx)(Ou,{className:`w-4 h-4`}),r(`common.upload`)]}),(0,K.jsx)(`input`,{id:`file-import`,type:`file`,accept:`.json`,className:`hidden`,onChange:e=>{let t=e.target.files?.[0];if(t){let e=new FileReader;e.onload=e=>{try{let t=JSON.parse(e.target?.result),n=t.setting||t;v(e=>({...e,...n})),i(r(`profiles.presets.fileImported`))}catch{i(r(`profiles.presets.invalidJson`),`error`)}},e.readAsText(t)}}})]}),(0,K.jsxs)(`div`,{className:`flex-1 p-4`,children:[s===`common`&&(0,K.jsxs)(`div`,{className:`space-y-6`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,K.jsxs)(`h3`,{className:`text-sm font-medium text-white flex items-center gap-2`,children:[(0,K.jsx)(iu,{className:`w-4 h-4 text-amber-600 dark:text-amber-400`}),r(`profiles.templates.title`)]}),Object.keys(_).filter(e=>e!==`inherits`).length>0&&(0,K.jsxs)(`button`,{onClick:()=>F(!P),className:`text-xs text-bambu-gray hover:text-white flex items-center gap-1 transition-colors`,children:[(0,K.jsx)(Pl,{className:`w-3 h-3`}),r(`profiles.presets.saveAsTemplate`)]})]}),P&&(0,K.jsxs)(`div`,{className:`mb-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-2 mb-2`,children:[(0,K.jsx)(`input`,{type:`text`,value:I,onChange:e=>L(e.target.value),placeholder:r(`profiles.templates.namePlaceholder`),className:`px-3 py-1.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`,autoFocus:!0}),(0,K.jsx)(`input`,{type:`text`,value:R,onChange:e=>z(e.target.value),placeholder:r(`profiles.templates.descriptionPlaceholder`),className:`px-3 py-1.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsxs)($,{size:`sm`,onClick:me,disabled:!I.trim(),children:[(0,K.jsx)(Pl,{className:`w-3 h-3`}),r(`common.save`)]}),(0,K.jsx)($,{size:`sm`,variant:`secondary`,onClick:()=>F(!1),children:r(`common.cancel`)})]}),(0,K.jsxs)(`button`,{onClick:()=>V(!B),className:`flex items-center gap-1.5 text-xs transition-colors ${B?`text-bambu-green`:`text-bambu-gray hover:text-white`}`,children:[B?(0,K.jsx)(Js,{className:`w-3.5 h-3.5`}):(0,K.jsx)(qs,{className:`w-3.5 h-3.5`}),r(B?`profiles.templates.shownInModals`:`profiles.templates.hiddenInModals`)]})]})]}),ee&&(0,K.jsxs)(`div`,{className:`mb-3 px-3 py-2 bg-bambu-green/10 border border-bambu-green/30 rounded-lg flex items-center gap-2`,children:[(0,K.jsx)(ts,{className:`w-4 h-4 text-bambu-green`}),(0,K.jsxs)(`span`,{className:`text-sm text-bambu-green`,children:[r(`profiles.presets.templateApplied`),` `,(0,K.jsx)(`span`,{className:`font-medium`,children:ee})]}),(0,K.jsx)(`button`,{onClick:()=>te(null),className:`ml-auto text-bambu-green/70 hover:text-bambu-green`,children:(0,K.jsx)(Hu,{className:`w-4 h-4`})})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-3 gap-2`,children:[he.map(e=>(0,K.jsxs)(`button`,{onClick:()=>pe(e),className:`p-3 text-left bg-bambu-dark border border-bambu-dark-tertiary rounded-lg hover:border-bambu-gray-dark transition-colors`,children:[(0,K.jsx)(`p`,{className:`text-sm font-medium text-white`,children:e.name}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e.description})]},e.id)),he.length===0&&(0,K.jsx)(`p`,{className:`col-span-3 text-center text-bambu-gray text-sm py-4`,children:r(`profiles.presets.noTemplatesSelected`)})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray-dark mt-2 text-center`,children:r(`profiles.presets.manageTemplatesHint`)})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h3`,{className:`text-sm font-medium text-white mb-3`,children:r(`profiles.presets.commonSettings`)}),(0,K.jsx)(`div`,{className:`grid grid-cols-2 gap-x-6 gap-y-3`,children:le.slice(0,10).map(e=>(0,K.jsxs)(`div`,{className:`flex items-center justify-between gap-4 max-[640px]:flex-col max-[640px]:items-start`,children:[(0,K.jsx)(`label`,{className:`text-sm text-bambu-gray flex-shrink-0`,children:e.label}),(0,K.jsx)(`div`,{className:`w-48 max-[640px]:w-full`,children:Ee(e)})]},e.key))})]}),Object.keys(_).length>1&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h3`,{className:`text-sm font-medium text-white mb-3`,children:r(`profiles.presets.currentOverrides`)}),(0,K.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:Object.entries(_).filter(([e])=>e!==`inherits`).map(([e,t])=>(0,K.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-2 py-1 bg-bambu-green/10 text-bambu-green text-xs rounded`,children:[e,`: `,String(t).slice(0,20),(0,K.jsx)(`button`,{onClick:()=>fe(e,void 0),className:`hover:text-white`,children:(0,K.jsx)(Hu,{className:`w-3 h-3`})})]},e))})]})]}),s===`fields`&&(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-6`,style:{height:`400px`},children:[(0,K.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-3 flex-shrink-0`,children:[(0,K.jsx)(`h3`,{className:`text-sm font-medium text-white`,children:r(`profiles.presets.availableFields`)}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:oe?r(`profiles.templates.fieldsCount`,{count:le.length}):r(`common.loading`)})]}),(0,K.jsxs)(`div`,{className:`relative mb-3 flex-shrink-0`,children:[(0,K.jsx)(zl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,K.jsx)(`input`,{type:`text`,value:w,onChange:e=>T(e.target.value),placeholder:r(`profiles.presets.searchFieldsPlaceholder`),className:`w-full pl-10 pr-4 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none`})]}),(0,K.jsxs)(`div`,{className:`flex-1 overflow-y-auto space-y-1 pr-2 min-h-0`,children:[ue.filter(e=>!(e.key in _)).map(e=>{let t=we[e.key],n=Te(t);return(0,K.jsxs)(`div`,{onClick:()=>{v(t=>({...t,[e.key]:n||``}))},className:`flex items-center justify-between gap-2 p-2 rounded-lg hover:bg-bambu-dark-tertiary transition-colors cursor-pointer group`,children:[(0,K.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,K.jsx)(`p`,{className:`text-sm text-white truncate`,children:e.label}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray-dark truncate`,children:e.key})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[n&&(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray bg-bambu-dark px-2 py-0.5 rounded max-w-32 truncate`,title:n,children:[n.slice(0,20),n.length>20?`...`:``]}),(0,K.jsx)(`div`,{className:`w-6 h-6 flex items-center justify-center rounded bg-bambu-dark-tertiary group-hover:bg-bambu-green/20 transition-colors`,children:(0,K.jsx)(Cl,{className:`w-4 h-4 text-bambu-gray group-hover:text-bambu-green transition-colors`})})]})]},e.key)}),ue.filter(e=>!(e.key in _)).length===0&&(0,K.jsx)(`p`,{className:`text-center text-bambu-gray py-4 text-sm`,children:r(w?`profiles.presets.noMatchingFields`:`profiles.presets.allFieldsAdded`)})]}),(0,K.jsx)(`div`,{className:`pt-3 mt-3 border-t border-bambu-dark-tertiary flex-shrink-0`,children:A?(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)(`input`,{type:`text`,value:O,onChange:e=>k(e.target.value),onKeyDown:e=>e.key===`Enter`&&de(),placeholder:`custom_field_name`,className:`flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white font-mono text-sm placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none`,autoFocus:!0}),(0,K.jsx)($,{size:`sm`,onClick:de,disabled:!O.trim(),children:(0,K.jsx)(Cl,{className:`w-4 h-4`})}),(0,K.jsx)($,{size:`sm`,variant:`secondary`,onClick:()=>{j(!1),k(``)},children:(0,K.jsx)(Hu,{className:`w-4 h-4`})})]}):(0,K.jsxs)(`button`,{onClick:()=>j(!0),className:`w-full flex items-center justify-center gap-2 p-2 text-sm text-bambu-gray hover:text-white border border-dashed border-bambu-dark-tertiary hover:border-bambu-gray-dark rounded-lg transition-colors`,children:[(0,K.jsx)(Cl,{className:`w-4 h-4`}),r(`profiles.presets.addCustomField`)]})})]}),(0,K.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-3 flex-shrink-0`,children:[(0,K.jsx)(`h3`,{className:`text-sm font-medium text-white`,children:r(`profiles.presets.yourOverrides`)}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:r(`profiles.templates.fieldsCount`,{count:Object.keys(_).filter(e=>e!==`inherits`).length})})]}),(0,K.jsxs)(`div`,{className:`flex-1 overflow-y-auto space-y-2 pr-2 min-h-0`,children:[Object.entries(_).filter(([e])=>e!==`inherits`).map(([e,t])=>{let n=le.find(t=>t.key===e);return(0,K.jsxs)(`div`,{className:`p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm font-medium text-white`,children:n?.label||e}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray-dark`,children:e})]}),(0,K.jsx)(`button`,{onClick:()=>fe(e,void 0),className:`p-1 text-bambu-gray hover:text-red-600 dark:hover:text-red-400 transition-colors`,children:(0,K.jsx)(Hu,{className:`w-4 h-4`})})]}),n?Ee(n):(0,K.jsx)(`input`,{type:`text`,value:String(t),onChange:t=>fe(e,t.target.value),className:`w-full px-3 py-1.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`})]},e)}),Object.keys(_).filter(e=>e!==`inherits`).length===0&&(0,K.jsxs)(`div`,{className:`text-center py-8 text-bambu-gray`,children:[(0,K.jsx)(eu,{className:`w-8 h-8 mx-auto mb-2 opacity-50`}),(0,K.jsx)(`p`,{className:`text-sm`,children:r(`profiles.presets.noOverridesYet`)}),(0,K.jsx)(`p`,{className:`text-xs mt-1`,children:r(`profiles.presets.clickFieldsToAdd`)})]})]}),Object.keys(_).filter(e=>e!==`inherits`).length>0&&(0,K.jsx)(`div`,{className:`pt-3 mt-3 border-t border-bambu-dark-tertiary flex-shrink-0`,children:(0,K.jsxs)(`button`,{onClick:()=>{F(!0),c(`common`)},className:`w-full flex items-center justify-center gap-2 p-2 text-sm text-bambu-gray hover:text-white border border-dashed border-bambu-dark-tertiary hover:border-bambu-gray-dark rounded-lg transition-colors`,children:[(0,K.jsx)(Pl,{className:`w-4 h-4`}),r(`profiles.presets.saveAsTemplate`)]})})]})]}),s===`json`&&(0,K.jsxs)(`div`,{className:`space-y-2`,children:[S&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-red-700 dark:text-red-400 text-sm`,children:[(0,K.jsx)(ls,{className:`w-4 h-4`}),S]}),(0,K.jsx)(`textarea`,{value:b,onChange:e=>ge(e.target.value),className:`w-full h-80 px-3 py-2 bg-bambu-dark border rounded-lg text-white text-xs font-mono focus:outline-none resize-none ${S?`border-red-500 focus:border-red-500`:`border-bambu-dark-tertiary focus:border-bambu-green`}`,spellCheck:!1}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:r(`profiles.presets.jsonTip`)})]})]}),(0,K.jsxs)(`div`,{className:`p-4 border-t border-bambu-dark-tertiary flex gap-2`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:e,className:`flex-1`,children:r(`common.cancel`)}),(0,K.jsxs)($,{onClick:()=>be.mutate(),disabled:be.isPending||!d.trim()||!o&&!p||!!S,className:`flex-1`,children:[be.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):o?(0,K.jsx)(Pl,{className:`w-4 h-4`}):(0,K.jsx)(Cl,{className:`w-4 h-4`}),r(o?`common.save`:t?`common.duplicate`:`common.create`)]})]})]})})]})}function JUe({settings:e,lastSyncTime:t,onRefresh:n,isRefreshing:r,printers:i,hasPermission:a,t:o}){let[s,c]=(0,y.useState)(``),[l,u]=(0,y.useState)(`all`),[d,f]=(0,y.useState)(`all`),[p,m]=(0,y.useState)(`all`),[h,g]=(0,y.useState)(`all`),[_,v]=(0,y.useState)(`all`),[b,x]=(0,y.useState)(`all`),[S,C]=(0,y.useState)(null),[w,T]=(0,y.useState)(!1),[E,D]=(0,y.useState)(!1),[O,k]=(0,y.useState)(null),[A,j]=(0,y.useState)(null),[M,N]=(0,y.useState)(null),[P,F]=(0,y.useState)(!1),[I,L]=(0,y.useState)([null,null]),[R,z]=(0,y.useState)(!1),[B,V]=(0,y.useState)(null),ee=to(),te=(0,y.useMemo)(()=>[...e.filament.map(e=>({...e,type:`filament`})),...e.printer.map(e=>({...e,type:`printer`})),...e.process.map(e=>({...e,type:`process`}))].map(e=>({...e,meta:w6(e.name)})),[e]),ne=(0,y.useMemo)(()=>{let e=new Set,t=new Set,n=new Set;return te.forEach(r=>{r.meta.nozzle&&e.add(r.meta.nozzle),r.meta.filamentType&&t.add(r.meta.filamentType),r.meta.layerHeight&&n.add(r.meta.layerHeight)}),{printers:i.map(e=>({id:e.id.toString(),name:e.name})),nozzles:Array.from(e).sort((e,t)=>parseFloat(e)-parseFloat(t)),filaments:Array.from(t).sort(),layerHeights:Array.from(n).sort((e,t)=>parseFloat(e)-parseFloat(t))}},[te,i]),re=(0,y.useMemo)(()=>p===`all`?null:i.find(e=>e.id.toString()===p)?.model||null,[p,i]),ie=(0,y.useMemo)(()=>te.filter(e=>l===`all`||e.type===l).filter(e=>{if(d===`all`)return!0;let t=T6(e.setting_id);return d===`custom`?t:!t}).filter(e=>{if(p===`all`||!re)return!0;let t=e.meta.printer?.toLowerCase()||``,n=re.toLowerCase();return t.includes(n)||n.includes(t)}).filter(e=>h===`all`||e.meta.nozzle===h).filter(e=>_===`all`||e.meta.filamentType===_).filter(e=>b===`all`||e.meta.layerHeight===b).filter(e=>s===``||e.name.toLowerCase().includes(s.toLowerCase())).sort((e,t)=>e.name.localeCompare(t.name)),[te,l,d,p,re,h,_,b,s]),H=e=>{if(P){let t=I[0]?.setting_id===e.setting_id,n=I[1]?.setting_id===e.setting_id;if(t)L([I[1],null]);else if(n)L([I[0],null]);else if(!I[0])L([e,null]);else if(I[1]){if(I[0].type!==e.type)return;L([I[0],e])}else{if(I[0].type!==e.type)return;L([I[0],e])}}else C(e)},ae=e=>{if(I[0]?.setting_id===e.setting_id)return 0;if(I[1]?.setting_id===e.setting_id)return 1},oe=async e=>{try{let t=await Q.getCloudSettingDetail(e.setting_id);k({type:e.type===`process`?`print`:e.type,name:e.name,base_id:t.base_id||`GFSA00`,setting:t.setting||{}}),C(null)}catch(e){console.error(`Failed to fetch preset details for duplication:`,e)}},U=async e=>{try{ee.removeQueries({queryKey:[`cloudSettingDetail`,e.setting_id]});let t=await Q.getCloudSettingDetail(e.setting_id);j({type:e.type===`process`?`print`:e.type,name:e.name,base_id:t.base_id||`GFSA00`,setting:t.setting||{},setting_id:e.setting_id}),C(null)}catch(e){console.error(`Failed to fetch preset details for editing:`,e)}},se=()=>{u(`all`),f(`all`),m(`all`),g(`all`),v(`all`),x(`all`),c(``)},ce=l!==`all`||d!==`all`||p!==`all`||h!==`all`||_!==`all`||b!==`all`||s!==``,le=e.filament.length+e.printer.length+e.process.length;return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`space-y-4 mb-6`,children:[(0,K.jsxs)(`div`,{className:`flex flex-col sm:flex-row gap-3`,children:[(0,K.jsxs)(`div`,{className:`relative flex-1`,children:[(0,K.jsx)(zl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,K.jsx)(`input`,{type:`text`,value:s,onChange:e=>c(e.target.value),placeholder:o(`profiles.cloudView.searchPlaceholder`),className:`w-full pl-10 pr-4 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none`})]}),(0,K.jsxs)(`div`,{className:`flex gap-2 max-[550px]:flex-wrap max-[550px]:items-center`,children:[(0,K.jsxs)($,{variant:P?`primary`:`secondary`,onClick:()=>{P?(F(!1),L([null,null])):F(!0)},children:[(0,K.jsx)(gc,{className:`w-4 h-4`}),o(P?`common.cancel`:`profiles.presets.compare`)]}),(0,K.jsxs)($,{variant:`secondary`,onClick:()=>D(!0),disabled:!a(`cloud:auth`),title:a(`cloud:auth`)?void 0:o(`profiles.cloudView.noTemplatesPermission`),children:[(0,K.jsx)(iu,{className:`w-4 h-4`}),o(`profiles.cloudView.templates`)]}),(0,K.jsxs)($,{variant:`secondary`,onClick:n,disabled:r||!a(`cloud:auth`),title:a(`cloud:auth`)?void 0:o(`profiles.cloudView.noRefreshPermission`),children:[(0,K.jsx)(kl,{className:`w-4 h-4 ${r?`animate-spin`:``}`}),o(`profiles.cloudView.refresh`)]}),(0,K.jsxs)($,{onClick:()=>T(!0),disabled:!a(`cloud:auth`),title:a(`cloud:auth`)?void 0:o(`profiles.cloudView.noCreatePermission`),children:[(0,K.jsx)(Cl,{className:`w-4 h-4`}),o(`profiles.cloudView.newPreset`)]})]})]}),(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,K.jsx)(fc,{className:`w-4 h-4 text-bambu-gray`}),(0,K.jsx)(E6,{label:o(`profiles.cloudView.filters.type`),value:l,options:[{value:`all`,label:o(`profiles.cloudView.filters.all`),count:le},{value:`filament`,label:o(`profiles.cloudView.filters.filament`),count:e.filament.length},{value:`printer`,label:o(`profiles.cloudView.filters.printer`),count:e.printer.length},{value:`process`,label:o(`profiles.cloudView.filters.process`),count:e.process.length}],onChange:e=>u(e)}),(0,K.jsx)(E6,{label:o(`profiles.cloudView.filters.owner`),value:d,options:[{value:`all`,label:o(`profiles.cloudView.filters.all`)},{value:`custom`,label:o(`profiles.cloudView.filters.myPresets`)},{value:`builtin`,label:o(`profiles.cloudView.filters.builtIn`)}],onChange:e=>f(e)}),ne.printers.length>0&&(0,K.jsx)(E6,{label:o(`profiles.cloudView.filters.printer`),value:p,options:[{value:`all`,label:o(`profiles.cloudView.filters.all`)},...ne.printers.map(e=>({value:e.id,label:e.name}))],onChange:m}),ne.nozzles.length>0&&(0,K.jsx)(E6,{label:o(`profiles.cloudView.filters.nozzle`),value:h,options:[{value:`all`,label:o(`profiles.cloudView.filters.all`)},...ne.nozzles.map(e=>({value:e,label:e}))],onChange:g}),ne.filaments.length>0&&(l===`all`||l===`filament`)&&(0,K.jsx)(E6,{label:o(`profiles.cloudView.filters.filament`),value:_,options:[{value:`all`,label:o(`profiles.cloudView.filters.all`)},...ne.filaments.map(e=>({value:e,label:e}))],onChange:v}),ne.layerHeights.length>0&&(l===`all`||l===`process`)&&(0,K.jsx)(E6,{label:o(`profiles.cloudView.filters.layer`),value:b,options:[{value:`all`,label:o(`profiles.cloudView.filters.all`)},...ne.layerHeights.map(e=>({value:e,label:e}))],onChange:x}),ce&&(0,K.jsx)(`button`,{onClick:se,className:`px-3 py-2 text-sm text-bambu-gray hover:text-white transition-colors`,children:o(`profiles.cloudView.clearFilters`)})]})]}),P&&(0,K.jsx)(`div`,{className:`mb-4 p-3 bg-blue-500/10 border border-blue-500/30 rounded-lg`,children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,K.jsx)(gc,{className:`w-5 h-5 text-blue-600 dark:text-blue-400`}),(0,K.jsx)(`span`,{className:`text-white font-medium`,children:o(`profiles.cloudView.compareMode`)}),(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:I[0]?o(`profiles.cloudView.selectAnotherPreset`,{type:I[0].type}):o(`profiles.cloudView.clickTwoPresets`)})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`px-2 py-1 text-sm rounded truncate max-w-[200px] ${I[0]?`bg-blue-500/30 text-blue-700 dark:text-blue-300`:`bg-bambu-dark text-bambu-gray`}`,children:I[0]?I[0].name:o(`profiles.cloudView.selectFirst`)}),(0,K.jsx)(Mo,{className:`w-4 h-4 text-bambu-gray`}),(0,K.jsx)(`span`,{className:`px-2 py-1 text-sm rounded truncate max-w-[200px] ${I[1]?`bg-blue-500/30 text-blue-700 dark:text-blue-300`:`bg-bambu-dark text-bambu-gray`}`,children:I[1]?I[1].name:o(`profiles.cloudView.selectSecond`)})]}),I[0]&&I[1]&&(0,K.jsxs)($,{size:`sm`,onClick:async()=>{try{let[e,t]=await Promise.all([Q.getCloudSettingDetail(I[0].setting_id),Q.getCloudSettingDetail(I[1].setting_id)]);V([e.setting||{},t.setting||{}]),z(!0)}catch{}},children:[(0,K.jsx)(gc,{className:`w-4 h-4`}),o(`profiles.cloudView.compareNow`)]})]})]})}),(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4 mb-4 text-sm text-bambu-gray`,children:[t&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(bs,{className:`w-3 h-3`}),o(`profiles.cloudView.lastSynced`),` `,jf(t.toISOString(),`system`,o)]}),(0,K.jsx)(`span`,{children:o(`profiles.cloudView.showingCount`,{showing:ie.length,total:le})}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-bambu-green`}),(0,K.jsxs)(`span`,{children:[`= `,o(`profiles.presets.myPreset`)]})]})]}),ie.length===0?(0,K.jsxs)(`div`,{className:`text-center py-16`,children:[(0,K.jsx)(Ic,{className:`w-12 h-12 text-bambu-gray-dark mx-auto mb-4`}),(0,K.jsx)(`p`,{className:`text-bambu-gray`,children:o(`profiles.cloudView.noPresetsFound`)}),ce&&(0,K.jsx)(`button`,{onClick:se,className:`mt-2 text-sm text-bambu-green hover:text-bambu-green-light`,children:o(`profiles.cloudView.clearFilters`)})]}):(0,K.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-6`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-3 px-1`,children:[(0,K.jsx)(Bs,{className:`w-4 h-4 text-amber-600 dark:text-amber-400`}),(0,K.jsx)(`h3`,{className:`text-sm font-medium text-bambu-gray`,children:o(`profiles.cloudView.columns.filament`)}),(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray-dark`,children:[`(`,ie.filter(e=>e.type===`filament`).length,`)`]})]}),(0,K.jsxs)(`div`,{className:`space-y-1 max-h-[calc(100vh-320px)] overflow-y-auto pr-1`,children:[ie.filter(e=>e.type===`filament`).map(e=>(0,K.jsx)(D6,{setting:e,onClick:()=>H(e),onDuplicate:()=>oe(e),compareMode:P,isCompareSelected:ae(e)!==void 0,compareIndex:ae(e),compareDisabled:P&&!!I[0]&&I[0].type!==e.type,t:o},e.setting_id)),ie.filter(e=>e.type===`filament`).length===0&&(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray-dark px-3 py-2`,children:o(`profiles.cloudView.noFilamentPresets`)})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-3 px-1`,children:[(0,K.jsx)(Ul,{className:`w-4 h-4 text-blue-600 dark:text-blue-400`}),(0,K.jsx)(`h3`,{className:`text-sm font-medium text-bambu-gray`,children:o(`profiles.cloudView.columns.process`)}),(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray-dark`,children:[`(`,ie.filter(e=>e.type===`process`).length,`)`]})]}),(0,K.jsxs)(`div`,{className:`space-y-1 max-h-[calc(100vh-320px)] overflow-y-auto pr-1`,children:[ie.filter(e=>e.type===`process`).map(e=>(0,K.jsx)(D6,{setting:e,onClick:()=>H(e),onDuplicate:()=>oe(e),compareMode:P,isCompareSelected:ae(e)!==void 0,compareIndex:ae(e),compareDisabled:P&&!!I[0]&&I[0].type!==e.type,t:o},e.setting_id)),ie.filter(e=>e.type===`process`).length===0&&(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray-dark px-3 py-2`,children:o(`profiles.cloudView.noProcessPresets`)})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-3 px-1`,children:[(0,K.jsx)(El,{className:`w-4 h-4 text-purple-600 dark:text-purple-400`}),(0,K.jsx)(`h3`,{className:`text-sm font-medium text-bambu-gray`,children:o(`profiles.cloudView.columns.printer`)}),(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray-dark`,children:[`(`,ie.filter(e=>e.type===`printer`).length,`)`]})]}),(0,K.jsxs)(`div`,{className:`space-y-1 max-h-[calc(100vh-320px)] overflow-y-auto pr-1`,children:[ie.filter(e=>e.type===`printer`).map(e=>(0,K.jsx)(D6,{setting:e,onClick:()=>H(e),onDuplicate:()=>oe(e),compareMode:P,isCompareSelected:ae(e)!==void 0,compareIndex:ae(e),compareDisabled:P&&!!I[0]&&I[0].type!==e.type,t:o},e.setting_id)),ie.filter(e=>e.type===`printer`).length===0&&(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray-dark px-3 py-2`,children:o(`profiles.cloudView.noPrinterPresets`)})]})]})]}),S&&(0,K.jsx)(GUe,{setting:S,onClose:()=>C(null),onDeleted:()=>C(null),onDuplicate:()=>oe(S),onEdit:()=>U(S),hasPermission:a,t:o}),(w||O||A||M)&&(0,K.jsx)(qUe,{onClose:()=>{T(!1),k(null),j(null),N(null)},initialData:A||O||(M?{type:M.type,name:``,base_id:``,setting:M.setting}:void 0),allPresets:e,t:o}),E&&(0,K.jsx)(KUe,{onClose:()=>D(!1),onApply:e=>{N({type:e.type,setting:e.settings}),D(!1)},t:o}),R&&B&&I[0]&&I[1]&&(0,K.jsx)(j6,{onClose:()=>{z(!1),V(null)},leftPreset:B[0],rightPreset:B[1],leftLabel:I[0].name,rightLabel:I[1].name,t:o})]})}function YUe(){let{t:e}=W(),t=to(),{showToast:n}=kd(),{hasPermission:r}=hd(),[i,a]=(0,y.useState)(`cloud`),[o,s]=(0,y.useState)(),{data:c,isLoading:l}=q({queryKey:[`cloudStatus`],queryFn:Q.getCloudStatus}),{data:u=[]}=q({queryKey:[`printers`],queryFn:Q.getPrinters}),{data:d,isLoading:f,refetch:p,dataUpdatedAt:m}=q({queryKey:[`cloudSettings`],queryFn:()=>Q.getCloudSettings(),enabled:!!c?.is_authenticated,retry:!1,staleTime:1e3*60*5});(0,y.useEffect)(()=>{m&&s(new Date(m))},[m]);let h=J({mutationFn:Q.cloudLogout,onSuccess:()=>{t.invalidateQueries({queryKey:[`cloudStatus`]}),t.removeQueries({queryKey:[`cloudSettings`]}),n(e(`profiles.toast.loggedOut`))}});return l?(0,K.jsx)(`div`,{className:`p-4 md:p-8 flex items-center justify-center min-h-[400px]`,children:(0,K.jsx)(X,{className:`w-8 h-8 text-bambu-green animate-spin`})}):(0,K.jsxs)(`div`,{className:`p-4 md:p-8`,children:[(0,K.jsxs)(`div`,{className:`mb-6`,children:[(0,K.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,K.jsx)(Ss,{className:`w-7 h-7 text-bambu-green`}),e(`profiles.title`)]}),(0,K.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:e(`profiles.subtitle`)})]}),(0,K.jsxs)(`div`,{className:`flex border-b border-bambu-dark-tertiary mb-6`,children:[(0,K.jsxs)(`button`,{onClick:()=>a(`cloud`),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${i===`cloud`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-white border-transparent`}`,children:[(0,K.jsx)(Ss,{className:`w-4 h-4`}),e(`profiles.tabs.bambuCloud`)]}),(0,K.jsxs)(`button`,{onClick:()=>a(`orca_cloud`),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${i===`orca_cloud`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-white border-transparent`}`,children:[(0,K.jsx)(Ss,{className:`w-4 h-4`}),e(`profiles.tabs.orcaCloud`)]}),(0,K.jsxs)(`button`,{onClick:()=>a(`local`),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${i===`local`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-white border-transparent`}`,children:[(0,K.jsx)(Sc,{className:`w-4 h-4`}),e(`profiles.tabs.local`)]}),(0,K.jsxs)(`button`,{onClick:()=>a(`kprofiles`),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${i===`kprofiles`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-white border-transparent`}`,children:[(0,K.jsx)(pc,{className:`w-4 h-4`}),e(`profiles.tabs.kprofiles`)]})]}),i===`cloud`&&(0,K.jsxs)(K.Fragment,{children:[c?.is_authenticated&&(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-3 mb-6 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`w-2 h-2 rounded-full bg-bambu-green animate-pulse`}),(0,K.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[e(`profiles.connectedAs`),` `,(0,K.jsx)(`span`,{className:`text-white`,children:c.email}),c.region&&(0,K.jsx)(`span`,{className:`ml-2 px-2 py-0.5 text-xs rounded bg-bambu-dark-tertiary text-bambu-gray`,children:c.region===`china`?e(`profiles.login.regionChina`):e(`profiles.login.regionGlobal`)})]})]}),(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:()=>h.mutate(),disabled:h.isPending||!r(`cloud:auth`),title:r(`cloud:auth`)?void 0:e(`profiles.noLogoutPermission`),children:[(0,K.jsx)(qc,{className:`w-4 h-4`}),e(`profiles.logout`)]})]}),c?.is_authenticated?f?(0,K.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,K.jsx)(X,{className:`w-8 h-8 text-bambu-green animate-spin`})}):d?(0,K.jsx)(JUe,{settings:d,lastSyncTime:o,onRefresh:()=>p(),isRefreshing:f,printers:u,hasPermission:r,t:e}):(0,K.jsxs)(`div`,{className:`text-center py-16`,children:[(0,K.jsx)(`p`,{className:`text-bambu-gray mb-4`,children:e(`profiles.failedToLoad`)}),(0,K.jsx)($,{onClick:()=>p(),children:e(`profiles.retry`)})]}):(0,K.jsx)(UUe,{onSuccess:()=>{t.invalidateQueries({queryKey:[`cloudStatus`]})},t:e})]}),i===`orca_cloud`&&(0,K.jsx)(RUe,{}),i===`local`&&(0,K.jsx)(NUe,{}),i===`kprofiles`&&(0,K.jsx)(kUe,{}),(0,K.jsx)(WUe,{})]})}function XUe(e,t){let n=(t||``).toUpperCase().replace(/[- ]/g,``),r=n.includes(`X1`),i=n.includes(`P1`),a=n.includes(`A1MINI`),o=n.includes(`A1`)&&!a,s=n.includes(`H2D`),c=n.includes(`H2C`),l=n.includes(`H2S`),u=s||c||l,d=n.includes(`P2S`),f=n.includes(`X2D`),p=d||f;switch(e){case`Lubricate Steel Rods`:return p?`https://wiki.bambulab.com/en/p2s/maintenance/lubricate-x-y-z-axis`:null;case`Clean Steel Rods`:return p?`https://wiki.bambulab.com/en/p2s/maintenance/lubricate-x-y-z-axis`:null;case`Lubricate Linear Rails`:return a?`https://wiki.bambulab.com/en/a1-mini/maintenance/lubricate-y-axis`:o?`https://wiki.bambulab.com/en/a1/maintenance/lubricate-y-axis`:u?`https://wiki.bambulab.com/en/h2/maintenance/x-axis-lubrication`:null;case`Clean Nozzle/Hotend`:return r||i?`https://wiki.bambulab.com/en/x1/troubleshooting/nozzle-clog`:a||o?`https://wiki.bambulab.com/en/a1-mini/troubleshooting/nozzle-clog`:u?`https://wiki.bambulab.com/en/h2/maintenance/nozzl-cold-pull-maintenance-and-cleaning`:p?`https://wiki.bambulab.com/en/p2s/maintenance/cold-pull-maintenance-hotend`:`https://wiki.bambulab.com/en/x1/troubleshooting/nozzle-clog`;case`Check Belt Tension`:return r?`https://wiki.bambulab.com/en/x1/maintenance/belt-tension`:i?`https://wiki.bambulab.com/en/p1/maintenance/p1p-maintenance`:a?`https://wiki.bambulab.com/en/a1-mini/maintenance/belt_tension`:o?`https://wiki.bambulab.com/en/a1/maintenance/belt_tension`:s?`https://wiki.bambulab.com/en/h2/maintenance/belt-tension`:c?`https://wiki.bambulab.com/en/h2c/maintenance/belt-tension`:l?`https://wiki.bambulab.com/en/h2s/maintenance/belt-tension`:p?`https://wiki.bambulab.com/en/p2s/maintenance/belt-tension`:`https://wiki.bambulab.com/en/x1/maintenance/belt-tension`;case`Clean Carbon Rods`:return r||i?`https://wiki.bambulab.com/en/general/carbon-rods-clearance`:null;case`Clean Linear Rails`:return a?`https://wiki.bambulab.com/en/a1-mini/maintenance/lubricate-y-axis`:o?`https://wiki.bambulab.com/en/a1/maintenance/lubricate-y-axis`:u?`https://wiki.bambulab.com/en/h2/maintenance/x-axis-lubrication`:null;case`Clean Build Plate`:return`https://wiki.bambulab.com/en/filament-acc/acc/pei-plate-clean-guide`;case`Check PTFE Tube`:return r||i?`https://wiki.bambulab.com/en/x1/maintenance/replace-ptfe-tube`:a||o?`https://wiki.bambulab.com/en/a1-mini/maintenance/ptfe-tube`:s?`https://wiki.bambulab.com/en/h2/maintenance/replace-ptfe-tube-on-h2d-printer`:l?`https://wiki.bambulab.com/en/h2s/maintenance/replace-ptfe-tube-on-h2s-printer`:c?`https://wiki.bambulab.com/en/h2/maintenance/replace-ptfe-tube-on-h2d-printer`:`https://wiki.bambulab.com/en/x1/maintenance/replace-ptfe-tube`;case`Replace HEPA Filter`:case`HEPA Filter`:case`Replace Carbon Filter`:case`Carbon Filter`:return u?`https://wiki.bambulab.com/en/h2/maintenance/replace-smoke-purifier-air-filte`:`https://wiki.bambulab.com/en/x1/maintenance/replace-carbon-filter`;case`Lubricate Left Nozzle Rail`:case`Left Nozzle Rail`:return u?`https://wiki.bambulab.com/en/h2/maintenance/x-axis-lubrication`:null;default:return null}}var M6={Droplet:Bs,Flame:rc,Ruler:Nl,Sparkles:iu,Square:su,Cable:Ko,Wrench:Vu,Calendar:Yo,Timer:bu,Cog:Ds,Fan:Ys,Zap:Wu,Wind:zu,Thermometer:yu,Layers:Ic,Box:Uo,Target:mu,RefreshCw:kl,Settings:Wl,Filter:fc,CircleDot:ps};function N6(e){return e&&M6[e]||Vu}function P6(e,t,n){if(t===`days`){if(e<1)return n?n(`common.today`):`Today`;if(e===1)return n?n(`maintenance.day`):`1 day`;if(e<7){let t=Math.round(e);return n?n(`maintenance.days`,{count:t}):`${t} days`}if(e<180){let t=Math.round(e/7);return t===1?n?n(`maintenance.week`):`1 week`:n?n(`maintenance.weeks`,{count:t}):`${t} weeks`}let t=Math.round(e/30);return t===1?n?n(`maintenance.month`):`1 month`:n?n(`maintenance.months`,{count:t}):`${t} months`}else{if(e<1)return`${Math.round(e*60)}m`;if(e<24)return`${e<10?e.toFixed(1):Math.round(e)}h`;let t=e/24;if(t<7)return`${t<2?t.toFixed(1):Math.round(t)}d`;let n=t/7;return n<12?`${n<2?n.toFixed(1):Math.round(n)}w`:`${Math.round(n/4)}mo`}}function F6(e,t,n){return t===`days`?e===1?n?n(`maintenance.day`):`1 day`:e===7?n?n(`maintenance.week`):`1 week`:e===14?n?n(`maintenance.weeks`,{count:2}):`2 weeks`:e===30?n?n(`maintenance.month`):`1 month`:e===60?n?n(`maintenance.months`,{count:2}):`2 months`:e===90?n?n(`maintenance.months`,{count:3}):`3 months`:e===180?n?n(`maintenance.months`,{count:6}):`6 months`:e===365?n?n(`maintenance.year`):`1 year`:n?n(`maintenance.days`,{count:e}):`${e} days`:`${e}h`}function ZUe({item:e,onPerform:t,onToggle:n,hasPermission:r,t:i}){let a=N6(e.maintenance_type_icon),o=e.interval_type||`hours`,s=(()=>{if(o===`days`){let t=e.days_since_maintenance??0;return Math.max(0,Math.min(100,t/e.interval_hours*100))}return Math.max(0,Math.min(100,(e.interval_hours-e.hours_until_due)/e.interval_hours*100))})(),c=()=>e.enabled?e.is_due?`text-red-700 dark:text-red-400`:e.is_warning?`text-amber-700 dark:text-amber-400`:`text-bambu-green`:`text-bambu-gray`;return(0,K.jsx)(`div`,{className:`rounded-xl border p-4 transition-all ${e.enabled?e.is_due?`bg-red-500/5 border-red-500/20`:e.is_warning?`bg-amber-500/5 border-amber-500/20`:`bg-bambu-dark-secondary border-bambu-dark-tertiary`:`bg-bambu-dark-secondary/50`}`,children:(0,K.jsxs)(`div`,{className:`flex items-start gap-3 max-[550px]:flex-wrap`,children:[(0,K.jsxs)(`div`,{className:`relative p-2.5 rounded-lg shrink-0 ${e.is_due?`bg-red-500/20`:e.is_warning?`bg-amber-500/20`:e.enabled?`bg-bambu-dark`:`bg-bambu-dark/50`}`,children:[(0,K.jsx)(a,{className:`w-5 h-5 ${c()}`}),e.enabled&&(e.is_due||e.is_warning)&&(0,K.jsx)(`span`,{className:`absolute -top-1 -right-1 w-2.5 h-2.5 rounded-full ${e.is_due?`bg-red-500`:`bg-amber-500`} animate-pulse`})]}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`h3`,{className:`font-medium truncate ${e.enabled?`text-white`:`text-bambu-gray`}`,children:e.maintenance_type_name}),o===`days`&&(0,K.jsx)(`span`,{title:i(`maintenance.timeBasedInterval`),children:(0,K.jsx)(Yo,{className:`w-3.5 h-3.5 text-bambu-gray shrink-0`})}),(()=>{let t=e.maintenance_type_wiki_url||XUe(e.maintenance_type_name,e.printer_model);return t?(0,K.jsx)(`a`,{href:t,target:`_blank`,rel:`noopener noreferrer`,className:`text-bambu-gray hover:text-bambu-green transition-colors shrink-0`,title:i(`maintenance.viewDocumentation`),onClick:e=>e.stopPropagation(),children:(0,K.jsx)(Ks,{className:`w-3.5 h-3.5`})}):null})()]}),(0,K.jsx)(`div`,{className:`mt-2 mb-1.5`,children:(0,K.jsx)(`div`,{className:`w-full h-1.5 bg-bambu-dark rounded-full overflow-hidden`,children:(0,K.jsx)(`div`,{className:`h-full rounded-full transition-all duration-500 ${e.enabled?e.is_due?`bg-red-500`:e.is_warning?`bg-amber-500`:`bg-bambu-green`:`bg-bambu-gray/30`}`,style:{width:`${s}%`}})})}),(0,K.jsxs)(`div`,{className:`text-xs flex items-center gap-1 ${c()}`,children:[e.is_due&&(0,K.jsx)(wu,{className:`w-3 h-3`}),e.is_warning&&!e.is_due&&(0,K.jsx)(bs,{className:`w-3 h-3`}),!e.is_due&&!e.is_warning&&e.enabled&&(0,K.jsx)(ts,{className:`w-3 h-3`}),(()=>{if(!e.enabled)return i(`common.disabled`);if(o===`days`){let t=e.days_until_due??0;return e.is_due?i(`maintenance.overdueBy`,{duration:P6(Math.abs(t),`days`,i)}):e.is_warning?i(`maintenance.dueIn`,{duration:P6(t,`days`,i)}):i(`maintenance.timeLeft`,{duration:P6(t,`days`,i)})}else return e.is_due?i(`maintenance.overdueBy`,{duration:P6(Math.abs(e.hours_until_due),`hours`,i)}):e.is_warning?i(`maintenance.dueIn`,{duration:P6(e.hours_until_due,`hours`,i)}):i(`maintenance.timeLeft`,{duration:P6(e.hours_until_due,`hours`,i)})})()]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0 max-[550px]:w-full max-[550px]:justify-end max-[550px]:mt-1`,children:[(0,K.jsx)(`span`,{title:r(`maintenance:update`)?void 0:i(`maintenance.noPermissionUpdate`),children:(0,K.jsx)(fU,{checked:e.enabled,onChange:t=>n(e.id,t),disabled:!r(`maintenance:update`)})}),(0,K.jsxs)($,{size:`sm`,variant:e.is_due?`primary`:`secondary`,onClick:()=>t(e.id),disabled:!e.enabled||!r(`maintenance:update`),title:r(`maintenance:update`)?void 0:i(`maintenance.noPermissionPerform`),className:`!px-3`,children:[(0,K.jsx)(jl,{className:`w-3.5 h-3.5`}),i(`common.reset`)]})]})]})})}function QUe({overview:e,onPerform:t,onToggle:n,onSetHours:r,hasPermission:i,t:a}){let[o,s]=(0,y.useState)(!1),[c,l]=(0,y.useState)(!1),[u,d]=(0,y.useState)(e.total_print_hours.toFixed(1)),f=[...e.maintenance_items].sort((e,t)=>e.is_due&&!t.is_due?-1:!e.is_due&&t.is_due?1:e.is_warning&&!t.is_warning?-1:!e.is_warning&&t.is_warning?1:e.maintenance_type_id-t.maintenance_type_id),p=f.find(e=>e.enabled&&(e.is_due||e.is_warning)),m=()=>{let t=parseFloat(u);!isNaN(t)&&t>=0&&(r(e.printer_id,t),l(!1))};return(0,K.jsxs)(xd,{className:`overflow-hidden`,children:[(0,K.jsxs)(`div`,{className:`p-5`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,K.jsx)(`h2`,{className:`text-xl font-semibold text-white`,children:e.printer_name}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.due_count>0&&(0,K.jsxs)(`span`,{className:`px-2.5 py-1 bg-red-100 text-red-700 dark:bg-red-500/20 dark:text-red-400 text-xs font-medium rounded-full flex items-center gap-1.5`,children:[(0,K.jsx)(wu,{className:`w-3 h-3`}),a(`maintenance.overdueCount`,{count:e.due_count})]}),e.warning_count>0&&(0,K.jsxs)(`span`,{className:`px-2.5 py-1 bg-amber-100 text-amber-700 dark:bg-amber-500/20 dark:text-amber-400 text-xs font-medium rounded-full flex items-center gap-1.5`,children:[(0,K.jsx)(bs,{className:`w-3 h-3`}),a(`maintenance.dueSoonCount`,{count:e.warning_count})]}),e.due_count===0&&e.warning_count===0&&(0,K.jsxs)(`span`,{className:`px-2.5 py-1 bg-bambu-green/20 text-bambu-green text-xs font-medium rounded-full flex items-center gap-1.5`,children:[(0,K.jsx)(ts,{className:`w-3 h-3`}),a(`maintenance.allGood`)]})]})]}),(0,K.jsxs)(`button`,{onClick:()=>s(!o),className:`flex items-center gap-1.5 px-3 py-1.5 text-sm text-bambu-gray hover:text-white hover:bg-bambu-dark rounded-lg transition-colors`,children:[o?(0,K.jsx)(as,{className:`w-4 h-4`}):(0,K.jsx)(ns,{className:`w-4 h-4`}),a(o?`common.collapse`:`common.expand`)]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-6 mt-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`p-2 bg-bambu-dark/50 rounded-lg`,children:(0,K.jsx)(bu,{className:`w-4 h-4 text-bambu-gray`})}),c?(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`input`,{type:`number`,value:u,onChange:e=>d(e.target.value),onKeyDown:e=>{e.key===`Enter`&&m(),e.key===`Escape`&&l(!1)},className:`w-24 px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm`,min:`0`,step:`1`,autoFocus:!0}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:a(`common.hours`)}),(0,K.jsx)($,{size:`sm`,onClick:m,children:a(`common.save`)}),(0,K.jsx)($,{size:`sm`,variant:`secondary`,onClick:()=>l(!1),children:a(`common.cancel`)})]}):(0,K.jsxs)(`button`,{onClick:()=>{i(`maintenance:update`)&&(d(Math.round(e.total_print_hours).toString()),l(!0))},className:`group ${i(`maintenance:update`)?``:`cursor-not-allowed opacity-60`}`,title:i(`maintenance:update`)?void 0:a(`maintenance.noPermissionEditHours`),children:[(0,K.jsxs)(`div`,{className:`text-sm font-medium text-white ${i(`maintenance:update`)?`group-hover:text-bambu-green`:``} transition-colors flex items-center gap-1`,children:[Math.round(e.total_print_hours),` `,a(`common.hours`),(0,K.jsx)(_l,{className:`w-3 h-3 text-bambu-gray ${i(`maintenance:update`)?`group-hover:text-bambu-green`:``}`})]}),(0,K.jsx)(`div`,{className:`text-xs text-bambu-gray`,children:a(`maintenance.totalPrintTime`)})]})]}),(0,K.jsx)(`div`,{className:`w-px h-10 bg-bambu-dark-tertiary`}),p&&(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`p-2 rounded-lg ${p.is_due?`bg-red-500/20`:`bg-amber-500/20`}`,children:(0,K.jsx)(N6(p.maintenance_type_icon),{className:`w-4 h-4 ${p.is_due?`text-red-600 dark:text-red-400`:`text-amber-600 dark:text-amber-400`}`})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`div`,{className:`text-sm font-medium ${p.is_due?`text-red-700 dark:text-red-400`:`text-amber-700 dark:text-amber-400`}`,children:p.maintenance_type_name}),(0,K.jsx)(`div`,{className:`text-xs ${p.is_due?`text-red-700/80 dark:text-red-400/70`:`text-amber-700/80 dark:text-amber-400/70`}`,children:p.is_due?a(`common.overdue`):a(`maintenance.dueSoon`)})]})]})]})]}),o&&(0,K.jsx)(Cd,{className:`pt-0 border-t border-bambu-dark-tertiary`,children:(0,K.jsx)(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-3 pt-4`,children:f.map(e=>(0,K.jsx)(ZUe,{item:e,onPerform:t,onToggle:n,hasPermission:i,t:a},e.id))})})]})}function $Ue({overview:e,types:t,onUpdateInterval:n,onAddType:r,onUpdateType:i,onDeleteType:a,onRestoreDefaults:o,isRestoringDefaults:s,onAssignType:c,onRemoveItem:l,hasPermission:u,t:d}){let[f,p]=(0,y.useState)(null),[m,h]=(0,y.useState)(``),[g,_]=(0,y.useState)(`hours`),[v,b]=(0,y.useState)(!1),[x,S]=(0,y.useState)(``),[C,w]=(0,y.useState)(`100`),[T,E]=(0,y.useState)(`hours`),[D,O]=(0,y.useState)(`Wrench`),[k,A]=(0,y.useState)(``),[j,M]=(0,y.useState)(new Set),[N,P]=(0,y.useState)(null),[F,I]=(0,y.useState)(null),L=(0,y.useMemo)(()=>e?e.map(e=>({id:e.printer_id,name:e.printer_name})):[],[e]),R=t=>e?e.filter(e=>e.maintenance_items.some(e=>e.maintenance_type_id===t)).map(e=>({printerId:e.printer_id,printerName:e.printer_name,itemId:e.maintenance_items.find(e=>e.maintenance_type_id===t)?.id})):[],z=t=>{if(!e)return[];let n=new Set(R(t).map(e=>e.printerId));return L.filter(e=>!n.has(e.id))},[B,V]=(0,y.useState)(null),[ee,te]=(0,y.useState)(``),[ne,re]=(0,y.useState)(``),[ie,H]=(0,y.useState)(`hours`),[ae,oe]=(0,y.useState)(`Wrench`),[U,se]=(0,y.useState)(``),ce=e=>{V(e),te(e.name),re(e.default_interval_hours.toString()),H(e.interval_type||`hours`),oe(e.icon||`Wrench`),se(e.wiki_url||``)},le=()=>{B&&ee.trim()&&parseFloat(ne)>0&&(i(B.id,{name:ee.trim(),default_interval_hours:parseFloat(ne),interval_type:ie,icon:ae,wiki_url:U.trim()||null}),V(null))},ue=(e,t,r)=>{let i=parseFloat(m);!isNaN(i)&&i>0&&n(e,{custom_interval_hours:Math.abs(i-t)<.01?null:i,custom_interval_type:g===r?null:g}),p(null)},de=e=>{e.preventDefault(),x.trim()&&parseFloat(C)>0&&j.size>0&&(r({name:x.trim(),default_interval_hours:parseFloat(C),interval_type:T,icon:D,wiki_url:k.trim()||null},Array.from(j)),S(``),w(`100`),E(`hours`),A(``),M(new Set),b(!1))},fe=e=>{M(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},pe=e?.map(e=>({printerId:e.printer_id,printerName:e.printer_name,items:e.maintenance_items.sort((e,t)=>e.maintenance_type_id-t.maintenance_type_id)})).sort((e,t)=>e.printerName.localeCompare(t.printerName))||[],me=t.filter(e=>e.is_system),he=t.filter(e=>!e.is_system);return(0,K.jsxs)(`div`,{className:`space-y-8`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-4`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:d(`maintenance.maintenanceTypes`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:d(`maintenance.maintenanceTypesDescription`)})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:o,disabled:!u(`maintenance:delete`)||s,title:u(`maintenance:delete`)?void 0:d(`maintenance.noPermissionDeleteTypes`),children:d(`maintenance.restoreDefaults`)}),(0,K.jsxs)($,{onClick:()=>b(!v),disabled:!u(`maintenance:create`),title:u(`maintenance:create`)?void 0:d(`maintenance.noPermissionEditTypes`),children:[(0,K.jsx)(Cl,{className:`w-4 h-4`}),d(`maintenance.addCustomType`)]})]})]}),v&&(0,K.jsx)(xd,{className:`mb-6`,children:(0,K.jsx)(Cd,{className:`py-4`,children:(0,K.jsxs)(`form`,{onSubmit:de,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4`,children:[(0,K.jsxs)(`div`,{className:`lg:col-span-2`,children:[(0,K.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1.5`,children:d(`common.name`)}),(0,K.jsx)(`input`,{type:`text`,value:x,onChange:e=>S(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,placeholder:d(`maintenance.exampleName`),autoFocus:!0})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1.5`,children:d(`maintenance.intervalType`)}),(0,K.jsxs)(`select`,{value:T,onChange:e=>{E(e.target.value),e.target.value===`days`?w(`30`):w(`100`)},className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,children:[(0,K.jsx)(`option`,{value:`hours`,children:d(`maintenance.printHours`)}),(0,K.jsx)(`option`,{value:`days`,children:d(`maintenance.calendarDays`)})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1.5`,children:d(`maintenance.intervalValue`,{type:T===`days`?d(`maintenance.calendarDays`).toLowerCase():d(`common.hours`)})}),(0,K.jsx)(`input`,{type:`number`,value:C,onChange:e=>w(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,min:`1`})]})]}),(0,K.jsx)(`div`,{className:`mt-4 flex items-end justify-between`,children:(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1.5`,children:d(`maintenance.icon`)}),(0,K.jsx)(`div`,{className:`flex gap-1`,children:Object.keys(M6).map(e=>{let t=M6[e];return(0,K.jsx)(`button`,{type:`button`,onClick:()=>O(e),className:`p-2 rounded-lg transition-colors ${D===e?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary`}`,children:(0,K.jsx)(t,{className:`w-4 h-4`})},e)})})]})}),(0,K.jsxs)(`div`,{className:`mt-4`,children:[(0,K.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1.5`,children:d(`maintenance.documentationLink`)}),(0,K.jsx)(`input`,{type:`url`,value:k,onChange:e=>A(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,placeholder:`https://wiki.bambulab.com/...`})]}),(0,K.jsxs)(`div`,{className:`mt-4`,children:[(0,K.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1.5`,children:d(`maintenance.assignToPrinters`)}),(0,K.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:L.map(e=>(0,K.jsx)(`button`,{type:`button`,onClick:()=>fe(e.id),className:`px-3 py-1.5 rounded-lg text-sm transition-colors ${j.has(e.id)?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary`}`,children:e.name},e.id))}),j.size===0&&(0,K.jsx)(`p`,{className:`text-xs text-orange-700 dark:text-orange-400 mt-1`,children:d(`maintenance.selectAtLeastOnePrinter`)})]}),(0,K.jsxs)(`div`,{className:`mt-4 flex justify-end gap-2`,children:[(0,K.jsx)($,{type:`button`,variant:`secondary`,onClick:()=>{b(!1),M(new Set)},children:d(`common.cancel`)}),(0,K.jsx)($,{type:`submit`,disabled:!x.trim()||j.size===0,children:d(`maintenance.addType`)})]})]})})}),(0,K.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3`,children:[me.map(e=>{let t=N6(e.icon),n=e.interval_type||`hours`;return(0,K.jsx)(`div`,{className:`bg-bambu-dark-secondary rounded-xl p-4 border border-bambu-dark-tertiary`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`p-2.5 bg-bambu-dark rounded-lg`,children:(0,K.jsx)(t,{className:`w-5 h-5 text-bambu-gray`})}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsx)(`div`,{className:`text-sm font-medium text-white truncate`,children:e.name}),(0,K.jsxs)(`div`,{className:`text-xs text-bambu-gray mt-0.5 flex items-center gap-1`,children:[n===`days`?(0,K.jsx)(Yo,{className:`w-3 h-3`}):(0,K.jsx)(bu,{className:`w-3 h-3`}),F6(e.default_interval_hours,n,d)]})]}),(0,K.jsx)(`button`,{onClick:()=>{u(`maintenance:delete`)&&I(e)},disabled:!u(`maintenance:delete`),title:u(`maintenance:delete`)?void 0:d(`maintenance.noPermissionDeleteTypes`),className:`p-2 rounded-lg hover:bg-bambu-dark text-bambu-gray hover:text-red-600 dark:hover:text-red-400 transition-colors ${u(`maintenance:delete`)?``:`opacity-50 cursor-not-allowed`}`,children:(0,K.jsx)(xu,{className:`w-4 h-4`})})]})},e.id)}),he.map(e=>{let t=N6(e.icon),n=e.interval_type||`hours`;if(B?.id===e.id)return(0,K.jsx)(`div`,{className:`bg-bambu-dark-secondary rounded-xl p-4 border border-bambu-green`,children:(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsx)(`input`,{type:`text`,value:ee,onChange:e=>te(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,placeholder:d(`common.name`),autoFocus:!0}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsxs)(`select`,{value:ie,onChange:e=>H(e.target.value),className:`flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,children:[(0,K.jsx)(`option`,{value:`hours`,children:d(`maintenance.printHours`)}),(0,K.jsx)(`option`,{value:`days`,children:d(`maintenance.calendarDays`)})]}),(0,K.jsx)(`input`,{type:`number`,value:ne,onChange:e=>re(e.target.value),className:`w-24 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,min:`1`})]}),(0,K.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:Object.keys(M6).map(e=>{let t=M6[e];return(0,K.jsx)(`button`,{type:`button`,onClick:()=>oe(e),className:`p-1.5 rounded transition-colors ${ae===e?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white`}`,children:(0,K.jsx)(t,{className:`w-3.5 h-3.5`})},e)})}),(0,K.jsx)(`input`,{type:`url`,value:U,onChange:e=>se(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,placeholder:d(`maintenance.documentationLink`)}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)($,{size:`sm`,onClick:le,disabled:!ee.trim(),children:d(`common.save`)}),(0,K.jsx)($,{size:`sm`,variant:`secondary`,onClick:()=>V(null),children:d(`common.cancel`)})]})]})},e.id);let r=R(e.id),i=z(e.id),o=N===e.id;return(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl p-4 border border-bambu-green/30`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`p-2.5 bg-bambu-green/20 rounded-lg`,children:(0,K.jsx)(t,{className:`w-5 h-5 text-bambu-green`})}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`text-sm font-medium text-white truncate`,children:e.name}),(0,K.jsx)(`span`,{className:`px-1.5 py-0.5 bg-bambu-green/20 text-bambu-green text-[10px] font-medium rounded`,children:d(`maintenance.custom`)})]}),(0,K.jsxs)(`div`,{className:`text-xs text-bambu-gray mt-0.5 flex items-center gap-1`,children:[n===`days`?(0,K.jsx)(Yo,{className:`w-3 h-3`}):(0,K.jsx)(bu,{className:`w-3 h-3`}),F6(e.default_interval_hours,n,d)]})]}),(0,K.jsxs)(`button`,{onClick:()=>P(o?null:e.id),className:`px-2 py-1 rounded-lg border transition-colors flex items-center gap-1 ${r.length>0?`border-bambu-green/50 bg-bambu-green/10 text-bambu-green hover:bg-bambu-green/20`:`border-orange-300 bg-orange-50 text-orange-700 hover:bg-orange-100 dark:border-orange-400/50 dark:bg-orange-400/10 dark:text-orange-400 dark:hover:bg-orange-400/20`}`,title:d(`maintenance.printersAssignedClick`,{count:r.length}),children:[(0,K.jsx)(El,{className:`w-3 h-3`}),(0,K.jsx)(`span`,{className:`text-xs font-medium`,children:r.length}),(0,K.jsx)(ns,{className:`w-3 h-3 transition-transform ${o?`rotate-180`:``}`})]}),(0,K.jsx)(`button`,{onClick:()=>ce(e),disabled:!u(`maintenance:update`),title:u(`maintenance:update`)?void 0:d(`maintenance.noPermissionEditTypes`),className:`p-2 rounded-lg hover:bg-bambu-dark text-bambu-gray hover:text-white transition-colors ${u(`maintenance:update`)?``:`opacity-50 cursor-not-allowed`}`,children:(0,K.jsx)(_l,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>{confirm(d(`maintenance.deleteTypeConfirm`,{name:e.name}))&&a(e.id)},disabled:!u(`maintenance:delete`),title:u(`maintenance:delete`)?void 0:d(`maintenance.noPermissionDeleteTypes`),className:`p-2 rounded-lg hover:bg-bambu-dark text-bambu-gray hover:text-red-600 dark:hover:text-red-400 transition-colors ${u(`maintenance:delete`)?``:`opacity-50 cursor-not-allowed`}`,children:(0,K.jsx)(xu,{className:`w-4 h-4`})})]}),o&&(0,K.jsxs)(`div`,{className:`mt-3 pt-3 border-t border-bambu-dark-tertiary`,children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:d(`maintenance.assignedToPrinters`)}),r.length===0?(0,K.jsx)(`p`,{className:`text-xs text-orange-700 dark:text-orange-400`,children:d(`maintenance.noPrintersAssigned`)}):(0,K.jsx)(`div`,{className:`flex flex-wrap gap-1 mb-2`,children:r.map(e=>(0,K.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-2 py-1 bg-bambu-dark rounded text-xs text-white`,children:[e.printerName,(0,K.jsx)(`button`,{onClick:()=>e.itemId&&l(e.itemId),disabled:!u(`maintenance:delete`),title:u(`maintenance:delete`)?d(`maintenance.removeFromPrinter`):d(`maintenance.noPermissionRemovePrinter`),className:`ml-1 ${u(`maintenance:delete`)?`hover:text-red-600 dark:hover:text-red-400`:`opacity-50 cursor-not-allowed`}`,children:`×`})]},e.printerId))}),i.length>0&&(0,K.jsxs)(`div`,{className:`flex flex-wrap gap-1`,children:[(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray mr-1`,children:d(`maintenance.addPrinterShort`)}),i.map(t=>(0,K.jsxs)(`button`,{onClick:()=>c(t.id,e.id),disabled:!u(`maintenance:create`),title:u(`maintenance:create`)?void 0:d(`maintenance.noPermissionAssignPrinter`),className:`px-2 py-1 bg-bambu-dark rounded text-xs transition-colors ${u(`maintenance:create`)?`hover:bg-bambu-green/20 text-bambu-gray hover:text-bambu-green`:`opacity-50 cursor-not-allowed text-bambu-gray`}`,children:[`+ `,t.name]},t.id))]})]})]},e.id)})]})]}),pe.length>0&&(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`mb-4`,children:[(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:d(`maintenance.intervalOverrides`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:d(`maintenance.intervalOverridesDescription`)})]}),(0,K.jsx)(`div`,{className:`space-y-4`,children:pe.map(e=>(0,K.jsx)(xd,{children:(0,K.jsxs)(Cd,{className:`py-4`,children:[(0,K.jsx)(`h3`,{className:`text-sm font-medium text-white mb-3`,children:e.printerName}),(0,K.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-2`,children:e.items.map(e=>{let n=N6(e.maintenance_type_icon),r=t.find(t=>t.id===e.maintenance_type_id),i=r?.default_interval_hours||e.interval_hours,a=r?.interval_type||`hours`,o=e.interval_type||`hours`,s=f===e.id;return(0,K.jsxs)(`div`,{className:`flex items-center gap-2 p-2.5 bg-bambu-dark rounded-lg`,children:[(0,K.jsx)(n,{className:`w-4 h-4 text-bambu-gray shrink-0`}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray flex-1 truncate`,children:e.maintenance_type_name}),s?(0,K.jsxs)(`div`,{className:`flex items-center gap-1`,children:[g===`days`?(0,K.jsx)(Yo,{className:`w-3.5 h-3.5 text-bambu-gray shrink-0`}):(0,K.jsx)(bu,{className:`w-3.5 h-3.5 text-bambu-gray shrink-0`}),(0,K.jsxs)(`select`,{value:g,onChange:e=>_(e.target.value),className:`px-1.5 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-xs`,children:[(0,K.jsx)(`option`,{value:`hours`,children:d(`maintenance.printHours`)}),(0,K.jsx)(`option`,{value:`days`,children:d(`maintenance.calendarDays`)})]}),(0,K.jsx)(`input`,{type:`number`,value:m,onChange:e=>h(e.target.value),onKeyDown:t=>{t.key===`Enter`&&ue(e.id,i,a),t.key===`Escape`&&p(null)},className:`w-16 px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-xs`,min:`1`}),(0,K.jsx)($,{size:`sm`,onClick:()=>ue(e.id,i,a),children:`OK`})]}):(0,K.jsxs)(`button`,{onClick:()=>{u(`maintenance:update`)&&(p(e.id),h(e.interval_hours.toString()),_(o))},disabled:!u(`maintenance:update`),title:u(`maintenance:update`)?void 0:d(`maintenance.noPermissionEditIntervals`),className:`px-2 py-1 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-xs font-medium text-white transition-colors flex items-center gap-1 ${u(`maintenance:update`)?`hover:bg-bambu-dark-secondary hover:border-bambu-green`:`opacity-50 cursor-not-allowed`}`,children:[o===`days`?(0,K.jsx)(Yo,{className:`w-3 h-3`}):(0,K.jsx)(bu,{className:`w-3 h-3`}),F6(e.interval_hours,o,d),(0,K.jsx)(_l,{className:`w-3 h-3 text-bambu-gray`})]})]},e.id)})})]})},e.printerId))})]}),pe.length===0&&(0,K.jsx)(xd,{children:(0,K.jsxs)(Cd,{className:`text-center py-12`,children:[(0,K.jsx)(bs,{className:`w-12 h-12 mx-auto mb-4 text-bambu-gray/30`}),(0,K.jsx)(`p`,{className:`text-bambu-gray`,children:d(`common.noPrinters`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray/70 mt-1`,children:d(`maintenance.intervalOverridesDescription`)})]})}),F&&(0,K.jsx)(Rd,{title:d(`maintenance.deleteSystemTypeTitle`),message:d(`maintenance.deleteSystemTypeMessage`,{name:F.name}),confirmText:d(`common.delete`),cancelText:d(`common.cancel`),variant:`danger`,cancelVariant:`primary`,cardClassName:`bg-red-950/70 border border-red-800/70`,onConfirm:()=>{a(F.id),I(null)},onCancel:()=>I(null)})]})}function eWe(){let{t:e}=W(),t=to(),{showToast:n}=kd(),{hasPermission:r}=hd(),[i,a]=(0,y.useState)(`status`),{data:o,isLoading:s}=q({queryKey:[`maintenanceOverview`],queryFn:Q.getMaintenanceOverview}),{data:c}=q({queryKey:[`maintenanceTypes`],queryFn:Q.getMaintenanceTypes}),l=J({mutationFn:({id:e,notes:t})=>Q.performMaintenance(e,t),onSuccess:()=>{t.invalidateQueries({queryKey:[`maintenanceOverview`]}),t.invalidateQueries({queryKey:[`maintenanceSummary`]}),n(e(`maintenance.maintenanceComplete`))},onError:e=>{n(e.message,`error`)}}),u=J({mutationFn:({id:e,data:t})=>Q.updateMaintenanceItem(e,t),onSuccess:()=>{t.invalidateQueries({queryKey:[`maintenanceOverview`]})},onError:e=>{n(e.message,`error`)}}),d=J({mutationFn:({id:e,data:t})=>Q.updateMaintenanceType(e,t),onSuccess:()=>{t.invalidateQueries({queryKey:[`maintenanceTypes`]}),t.invalidateQueries({queryKey:[`maintenanceOverview`]}),n(e(`maintenance.typeUpdated`))},onError:e=>{n(e.message,`error`)}}),f=J({mutationFn:Q.deleteMaintenanceType,onSuccess:()=>{t.invalidateQueries({queryKey:[`maintenanceTypes`]}),t.invalidateQueries({queryKey:[`maintenanceOverview`]}),n(e(`maintenance.typeDeleted`))},onError:e=>{n(e.message,`error`)}}),p=J({mutationFn:Q.restoreDefaultMaintenanceTypes,onSuccess:r=>{t.invalidateQueries({queryKey:[`maintenanceTypes`]}),t.invalidateQueries({queryKey:[`maintenanceOverview`]}),n(e(`maintenance.defaultsRestored`,{count:r.restored}))},onError:e=>{n(e.message,`error`)}}),m=J({mutationFn:({printerId:e,hours:t})=>Q.setPrinterHours(e,t),onSuccess:()=>{t.invalidateQueries({queryKey:[`maintenanceOverview`]}),t.invalidateQueries({queryKey:[`maintenanceSummary`]}),n(e(`maintenance.printHoursUpdated`))},onError:e=>{n(e.message,`error`)}}),h=J({mutationFn:({printerId:e,typeId:t})=>Q.assignMaintenanceType(e,t),onSuccess:()=>{t.invalidateQueries({queryKey:[`maintenanceOverview`]}),n(e(`maintenance.printerAssigned`))},onError:e=>{n(e.message,`error`)}}),g=J({mutationFn:Q.removeMaintenanceItem,onSuccess:()=>{t.invalidateQueries({queryKey:[`maintenanceOverview`]}),n(e(`maintenance.printerRemoved`))},onError:e=>{n(e.message,`error`)}}),_=e=>{l.mutate({id:e})},v=(e,t)=>{u.mutate({id:e,data:{enabled:t}})},b=(e,t)=>{m.mutate({printerId:e,hours:t})};if(s)return(0,K.jsx)(`div`,{className:`p-4 md:p-8 flex justify-center`,children:(0,K.jsx)(X,{className:`w-8 h-8 text-bambu-green animate-spin`})});let x=o?.reduce((e,t)=>e+t.due_count,0)||0,S=o?.reduce((e,t)=>e+t.warning_count,0)||0;return(0,K.jsxs)(`div`,{className:`p-4 md:p-8`,children:[(0,K.jsxs)(`div`,{className:`mb-6`,children:[(0,K.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,K.jsx)(Vu,{className:`w-7 h-7 text-bambu-green`}),e(`maintenance.title`)]}),(0,K.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:i===`status`?(0,K.jsxs)(K.Fragment,{children:[x>0&&(0,K.jsx)(`span`,{className:`text-red-700 dark:text-red-400`,children:e(`maintenance.dueCount`,{count:x})}),x>0&&S>0&&` · `,S>0&&(0,K.jsx)(`span`,{className:`text-amber-700 dark:text-amber-400`,children:e(`maintenance.warningCount`,{count:S})}),x===0&&S===0&&(0,K.jsx)(`span`,{className:`text-bambu-green`,children:e(`maintenance.allOk`)})]}):e(`maintenance.configureSettings`)})]}),(0,K.jsxs)(`div`,{className:`flex gap-1 mb-6 border-b border-bambu-dark-tertiary`,children:[(0,K.jsx)(`button`,{onClick:()=>a(`status`),className:`px-4 py-2 text-sm font-medium border-b-2 -mb-px transition-colors ${i===`status`?`text-bambu-green border-bambu-green`:`text-bambu-gray border-transparent hover:text-white`}`,children:e(`maintenance.statusTab`)}),(0,K.jsx)(`button`,{onClick:()=>a(`settings`),className:`px-4 py-2 text-sm font-medium border-b-2 -mb-px transition-colors ${i===`settings`?`text-bambu-green border-bambu-green`:`text-bambu-gray border-transparent hover:text-white`}`,children:e(`maintenance.settingsTab`)})]}),i===`status`?(0,K.jsx)(`div`,{className:`space-y-6`,children:o&&o.length>0?[...o].sort((e,t)=>{let n=e.due_count*10+e.warning_count,r=t.due_count*10+t.warning_count;return n===r?e.printer_name.localeCompare(t.printer_name):r-n}).map(t=>(0,K.jsx)(QUe,{overview:t,onPerform:_,onToggle:v,onSetHours:b,hasPermission:r,t:e},t.printer_id)):(0,K.jsx)(xd,{children:(0,K.jsxs)(Cd,{className:`text-center py-16`,children:[(0,K.jsx)(Vu,{className:`w-16 h-16 mx-auto mb-4 text-bambu-gray/30`}),(0,K.jsx)(`p`,{className:`text-lg font-medium text-white mb-2`,children:e(`common.noPrinters`)}),(0,K.jsx)(`p`,{className:`text-bambu-gray`,children:e(`maintenance.configureSettings`)})]})})}):(0,K.jsx)($Ue,{overview:o,types:c||[],onUpdateInterval:(e,t)=>u.mutate({id:e,data:t}),onAddType:async(r,i)=>{let a=await Q.createMaintenanceType(r);for(let e of i)await Q.assignMaintenanceType(e,a.id);t.invalidateQueries({queryKey:[`maintenanceTypes`]}),t.invalidateQueries({queryKey:[`maintenanceOverview`]}),n(e(`maintenance.typeUpdated`))},onUpdateType:(e,t)=>d.mutate({id:e,data:t}),onDeleteType:e=>f.mutate(e),onRestoreDefaults:()=>p.mutate(),isRestoringDefaults:p.isPending,onAssignType:(e,t)=>h.mutate({printerId:e,typeId:t}),onRemoveItem:e=>g.mutate(e),hasPermission:r,t:e})]})}var I6=[`#ef4444`,`#f97316`,`#eab308`,`#22c55e`,`#06b6d4`,`#3b82f6`,`#8b5cf6`,`#ec4899`,`#6b7280`];function L6({project:e,onClose:t,onSave:n,isLoading:r,currencySymbol:i,t:a}){let[o,s]=(0,y.useState)(e?.name||``),[c,l]=(0,y.useState)(e?.description||``),[u,d]=(0,y.useState)(e?.color||I6[0]),[f,p]=(0,y.useState)(e?.target_count?.toString()||``),[m,h]=(0,y.useState)(e?.target_parts_count?.toString()||``),[g,_]=(0,y.useState)(e?.status||`active`),[v,b]=(0,y.useState)(e?.tags||``),[x,S]=(0,y.useState)(e?.due_date?.split(`T`)[0]||``),[C,w]=(0,y.useState)(e?.priority||`normal`),[T,E]=(0,y.useState)(e?.budget?.toString()||``),[D,O]=(0,y.useState)(e?.url||``),[k,A]=(0,y.useState)(null),j=to(),[M,N]=(0,y.useState)(e?.cover_image_filename||null),P=(0,y.useRef)(null),[F,I]=(0,y.useState)(!1),[L,R]=(0,y.useState)(0);return(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg w-full max-w-md border border-bambu-dark-tertiary flex flex-col max-h-[calc(100vh-2rem)]`,children:[(0,K.jsx)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary flex-shrink-0`,children:(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:a(e?`projects.editProject`:`projects.newProject`)})}),(0,K.jsxs)(`form`,{onSubmit:t=>{t.preventDefault();let r=D.trim();if(r&&!/^https?:\/\//i.test(r)){A(a(`projects.urlInvalid`));return}A(null),n({name:o.trim(),description:c.trim()||void 0,color:u,target_count:f?parseInt(f,10):void 0,target_parts_count:m?parseInt(m,10):void 0,tags:v.trim()||void 0,due_date:x||void 0,priority:C,budget:T.trim()?parseFloat(T):null,url:e?r||null:r||void 0,...e&&{status:g}})},className:`flex flex-col flex-1 min-h-0`,children:[(0,K.jsxs)(`div`,{className:`p-4 space-y-4 overflow-y-auto flex-1`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`common.name`)}),(0,K.jsx)(`input`,{type:`text`,value:o,onChange:e=>s(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:a(`projects.namePlaceholder`),required:!0})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`common.description`)}),(0,K.jsx)(`textarea`,{value:c,onChange:e=>l(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green resize-none`,placeholder:a(`projects.descriptionPlaceholder`),rows:2})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`projects.urlLabel`)}),(0,K.jsx)(`input`,{type:`url`,value:D,onChange:e=>{O(e.target.value),k&&A(null)},className:`w-full bg-bambu-dark border rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none ${k?`border-red-500 focus:border-red-500`:`border-bambu-dark-tertiary focus:border-bambu-green`}`,placeholder:a(`projects.urlPlaceholder`),maxLength:2048}),k&&(0,K.jsx)(`p`,{className:`text-xs text-red-600 dark:text-red-400 mt-1`,children:k})]}),e&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`projects.coverImageLabel`)}),(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`w-20 h-20 rounded bg-bambu-dark border border-bambu-dark-tertiary overflow-hidden flex items-center justify-center flex-shrink-0`,children:M?(0,K.jsx)(`img`,{src:`${Q.getProjectCoverImageUrl(e.id)}?v=${L}`,alt:a(`projects.coverImageAlt`),className:`w-full h-full object-cover`}):(0,K.jsx)(Ac,{className:`w-6 h-6 text-bambu-gray`})}),(0,K.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,K.jsx)(`input`,{ref:P,type:`file`,accept:`image/jpeg,image/png,image/gif,image/webp`,onChange:async t=>{let n=t.target.files?.[0];if(!(!n||!e)){I(!0);try{N((await Q.uploadProjectCoverImage(e.id,n)).filename),R(e=>e+1),j.invalidateQueries({queryKey:[`projects`]})}catch{}finally{I(!1),P.current&&(P.current.value=``)}}},className:`hidden`}),(0,K.jsxs)($,{type:`button`,variant:`secondary`,onClick:()=>P.current?.click(),disabled:F,children:[F?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(Ou,{className:`w-4 h-4 mr-1`}),a(M?`projects.coverImageReplace`:`projects.coverImageUpload`)]}),M&&(0,K.jsxs)($,{type:`button`,variant:`secondary`,onClick:async()=>{if(e){I(!0);try{await Q.deleteProjectCoverImage(e.id),N(null),R(e=>e+1),j.invalidateQueries({queryKey:[`projects`]})}finally{I(!1)}}},disabled:F,children:[(0,K.jsx)(Hu,{className:`w-4 h-4 mr-1`}),a(`projects.coverImageRemove`)]})]})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`projects.color`)}),(0,K.jsx)(`div`,{className:`flex gap-2 flex-wrap`,children:I6.map(e=>(0,K.jsx)(`button`,{type:`button`,onClick:()=>d(e),className:`w-8 h-8 rounded-full transition-transform ${u===e?`ring-2 ring-white ring-offset-2 ring-offset-bambu-dark-secondary scale-110`:``}`,style:{backgroundColor:e}},e))})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`projects.targetPlates`)}),(0,K.jsx)(`input`,{type:`number`,value:f,onChange:e=>p(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:a(`projects.targetPlatesPlaceholder`),min:`1`}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:a(`projects.targetPlatesHelp`)})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`projects.targetParts`)}),(0,K.jsx)(`input`,{type:`number`,value:m,onChange:e=>h(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:a(`projects.targetPartsPlaceholder`),min:`1`}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:a(`projects.targetPartsHelp`)})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`projects.tagsLabel`)}),(0,K.jsx)(`input`,{type:`text`,value:v,onChange:e=>b(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:a(`projects.tagsPlaceholder`)})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`projects.dueDate`)}),(0,K.jsx)(`input`,{type:`date`,value:x,onChange:e=>S(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white focus:outline-none focus:border-bambu-green`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`projects.priority`)}),(0,K.jsxs)(`select`,{value:C,onChange:e=>w(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white focus:outline-none focus:border-bambu-green`,children:[(0,K.jsx)(`option`,{value:`low`,children:a(`projects.priorityLow`)}),(0,K.jsx)(`option`,{value:`normal`,children:a(`projects.priorityNormal`)}),(0,K.jsx)(`option`,{value:`high`,children:a(`projects.priorityHigh`)}),(0,K.jsx)(`option`,{value:`urgent`,children:a(`projects.priorityUrgent`)})]})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`projectDetail.cost.budget`)}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(`span`,{className:`absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray pointer-events-none`,children:i}),(0,K.jsx)(`input`,{type:`number`,step:`0.01`,min:`0`,value:T,onChange:e=>E(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded pl-8 pr-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:`0.00`})]})]}),e&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`common.status`)}),(0,K.jsxs)(`select`,{value:g,onChange:e=>_(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white focus:outline-none focus:border-bambu-green`,children:[(0,K.jsx)(`option`,{value:`active`,children:a(`projects.statusActive`)}),(0,K.jsx)(`option`,{value:`completed`,children:a(`projects.statusCompleted`)}),(0,K.jsx)(`option`,{value:`archived`,children:a(`projects.statusArchived`)})]})]})]}),(0,K.jsxs)(`div`,{className:`flex justify-end gap-2 p-4 border-t border-bambu-dark-tertiary flex-shrink-0`,children:[(0,K.jsx)($,{type:`button`,variant:`secondary`,onClick:t,children:a(`common.cancel`)}),(0,K.jsx)($,{type:`submit`,disabled:!o.trim()||r,children:r?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):a(e?`common.save`:`projects.create`)})]})]})]})})}function tWe({projectId:e,altText:t}){let n=(0,y.useRef)(null),[r,i]=(0,y.useState)(!1),[a,o]=(0,y.useState)(null);return(0,K.jsxs)(`div`,{ref:n,className:`relative flex-shrink-0`,onMouseEnter:()=>{if(!n.current)return;let e=n.current.getBoundingClientRect(),t=window.innerWidth,r=window.innerHeight,a=e.right+8;a+384>t-8&&(a=e.left-384-8);let s=e.top;s+384>r-8&&(s=r-384-8),s<8&&(s=8),o({left:a,top:s}),i(!0)},onMouseLeave:()=>i(!1),onClick:e=>e.stopPropagation(),children:[(0,K.jsx)(`div`,{className:`w-10 h-10 rounded-lg overflow-hidden bg-bambu-dark border border-bambu-dark-tertiary`,children:(0,K.jsx)(`img`,{src:Q.getProjectCoverImageUrl(e),alt:t,className:`w-full h-full object-cover`,loading:`lazy`})}),r&&a&&(0,Lp.createPortal)((0,K.jsx)(`div`,{className:`fixed z-[100] w-96 h-96 rounded-lg overflow-hidden border border-bambu-dark-tertiary shadow-2xl bg-bambu-dark pointer-events-none`,style:{left:a.left,top:a.top},"aria-hidden":`true`,children:(0,K.jsx)(`img`,{src:Q.getProjectCoverImageUrl(e),alt:``,className:`w-full h-full object-contain`,loading:`lazy`})}),document.body)]})}function nWe({project:e,onClick:t,onEdit:n,onDelete:r,hasPermission:i,t:a}){let o=e.target_count?Math.round(e.archive_count/e.target_count*100):0,s=e.target_parts_count?Math.round(e.completed_count/e.target_parts_count*100):0,c=e.status===`completed`,l=e.status===`archived`,[u,d]=(0,y.useState)(!1),f=c?{icon:fs,color:`text-bambu-green`,bg:`bg-bambu-green/10`}:l?{icon:Do,color:`text-bambu-gray`,bg:`bg-bambu-gray/10`}:e.queue_count>0?{icon:bs,color:`text-blue-600 dark:text-blue-400`,bg:`bg-blue-50 dark:bg-blue-400/10`}:{icon:ac,color:`text-bambu-gray`,bg:`bg-bambu-gray/10`};return(0,K.jsxs)(`div`,{className:`group relative bg-gradient-to-br from-bambu-card to-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary hover:border-bambu-green/50 hover:shadow-lg hover:shadow-bambu-green/5 transition-all duration-300 cursor-pointer overflow-hidden`,onClick:t,children:[(0,K.jsx)(`div`,{className:`absolute top-0 left-0 w-1.5 h-full`,style:{backgroundColor:e.color||`#6b7280`,boxShadow:`0 0 12px ${e.color||`#6b7280`}40`}}),(0,K.jsxs)(`div`,{className:`p-5 pl-6`,children:[(0,K.jsxs)(`div`,{className:`flex items-start justify-between mb-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 flex-1`,children:[e.cover_image_filename?(0,K.jsx)(tWe,{projectId:e.id,altText:a(`projects.coverImageAlt`)}):(0,K.jsx)(`div`,{className:`p-2 rounded-lg ${f.bg} flex-shrink-0`,children:(0,K.jsx)(f.icon,{className:`w-5 h-5 ${f.color}`})}),(0,K.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,K.jsx)(`h3`,{className:`font-semibold text-white truncate`,children:e.name}),e.url&&(0,K.jsx)(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,onClick:e=>e.stopPropagation(),title:e.url,"aria-label":a(`projects.openExternalUrl`),className:`inline-flex items-center justify-center w-6 h-6 rounded bg-bambu-dark border border-bambu-dark-tertiary text-bambu-green hover:bg-bambu-green/10 hover:border-bambu-green transition-colors flex-shrink-0`,children:(0,K.jsx)(Ks,{className:`w-3.5 h-3.5`})}),e.target_parts_count?(0,K.jsxs)(`span`,{className:`text-xs px-2 py-0.5 rounded-full whitespace-nowrap font-medium ${s>=100?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark text-bambu-gray`}`,children:[e.completed_count,`/`,e.target_parts_count,` `,a(`projects.parts`)]}):e.target_count?(0,K.jsxs)(`span`,{className:`text-xs px-2 py-0.5 rounded-full whitespace-nowrap font-medium ${o>=100?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark text-bambu-gray`}`,children:[e.archive_count,`/`,e.target_count,` `,a(`projects.plates`)]}):e.completed_count>0?(0,K.jsxs)(`span`,{className:`text-xs px-2 py-0.5 rounded-full whitespace-nowrap font-medium bg-bambu-dark text-bambu-gray`,children:[e.completed_count,` `,a(`projects.parts`)]}):null,c&&(0,K.jsx)(`span`,{className:`text-xs bg-bambu-green/20 text-bambu-green px-2 py-0.5 rounded-full whitespace-nowrap`,children:a(`projects.done`)}),l&&(0,K.jsx)(`span`,{className:`text-xs bg-bambu-gray/20 text-bambu-gray px-2 py-0.5 rounded-full whitespace-nowrap`,children:a(`projects.statusArchived`)})]}),e.description&&(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray/70 mt-1 line-clamp-1`,children:e.description}),e.archives&&e.archives.length>0&&(()=>{let t=e.archives.map(e=>e.filament_type).filter(Boolean).flatMap(e=>e.split(`,`).map(e=>e.trim())).filter(Boolean),n=[...new Set(t)],r=e.archives.map(e=>e.filament_color).filter(Boolean).flatMap(e=>e.split(`,`).map(e=>e.trim())).filter(e=>e.startsWith(`#`)||/^[0-9A-Fa-f]{6}$/.test(e)),i=[...new Set(r)];return n.length===0&&i.length===0?null:(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mt-1.5`,children:[n.slice(0,3).map(e=>(0,K.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 bg-bambu-dark text-bambu-gray rounded`,children:e},e)),i.length>0&&(0,K.jsxs)(`div`,{className:`flex items-center gap-0.5`,children:[i.slice(0,5).map(e=>(0,K.jsx)(`div`,{className:`w-3 h-3 rounded-full border border-black/20`,style:{backgroundColor:e.startsWith(`#`)?e:`#${e}`},title:e},e)),i.length>5&&(0,K.jsxs)(`span`,{className:`text-[10px] text-bambu-gray ml-0.5`,children:[`+`,i.length-5]})]})]})})()]})]}),(0,K.jsxs)(`div`,{className:`relative`,onClick:e=>e.stopPropagation(),children:[(0,K.jsx)(`button`,{className:`p-1.5 rounded-lg hover:bg-bambu-dark text-bambu-gray hover:text-white transition-colors opacity-0 group-hover:opacity-100`,onClick:()=>d(!u),children:(0,K.jsx)(Hs,{className:`w-4 h-4`})}),u&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`fixed inset-0 z-10`,onClick:()=>d(!1)}),(0,K.jsxs)(`div`,{className:`absolute right-0 top-8 z-20 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl py-1 min-w-[120px]`,children:[(0,K.jsxs)(`button`,{className:`w-full px-3 py-2 text-left text-sm flex items-center gap-2 ${i(`projects:update`)?`text-white hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{i(`projects:update`)&&(n(),d(!1))},disabled:!i(`projects:update`),title:i(`projects:update`)?void 0:a(`projects.noEditPermission`),children:[(0,K.jsx)(_l,{className:`w-4 h-4`}),a(`common.edit`)]}),(0,K.jsxs)(`button`,{className:`w-full px-3 py-2 text-left text-sm flex items-center gap-2 ${i(`projects:delete`)?`text-red-600 dark:text-red-400 hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{i(`projects:delete`)&&(r(),d(!1))},disabled:!i(`projects:delete`),title:i(`projects:delete`)?void 0:a(`projects.noDeletePermission`),children:[(0,K.jsx)(xu,{className:`w-4 h-4`}),a(`common.delete`)]})]})]})]})]}),(0,K.jsx)(`div`,{className:`mb-4`,children:e.target_count||e.target_parts_count?(0,K.jsxs)(`div`,{className:`space-y-3`,children:[e.target_count&&(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between text-xs mb-1`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:a(`projects.plates`)}),(0,K.jsxs)(`span`,{className:o>=100?`text-bambu-green font-medium`:`text-white`,children:[e.archive_count,` / `,e.target_count]})]}),(0,K.jsx)(`div`,{className:`h-2 bg-bambu-dark/80 rounded-full overflow-hidden backdrop-blur-sm`,children:(0,K.jsx)(`div`,{className:`h-full transition-all duration-500 ease-out rounded-full relative`,style:{width:`${Math.min(o,100)}%`,background:o>=100?`linear-gradient(90deg, #22c55e, #4ade80)`:`linear-gradient(90deg, ${e.color||`#6b7280`}, ${e.color||`#6b7280`}cc)`,boxShadow:`0 0 8px ${o>=100?`#22c55e`:e.color||`#6b7280`}60`}})})]}),e.target_parts_count&&(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between text-xs mb-1`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:a(`projects.parts`)}),(0,K.jsxs)(`span`,{className:s>=100?`text-bambu-green font-medium`:`text-white`,children:[e.completed_count,` / `,e.target_parts_count]})]}),(0,K.jsx)(`div`,{className:`h-2 bg-bambu-dark/80 rounded-full overflow-hidden backdrop-blur-sm`,children:(0,K.jsx)(`div`,{className:`h-full transition-all duration-500 ease-out rounded-full relative`,style:{width:`${Math.min(s,100)}%`,background:s>=100?`linear-gradient(90deg, #22c55e, #4ade80)`:`linear-gradient(90deg, ${e.color||`#6b7280`}, ${e.color||`#6b7280`}cc)`,boxShadow:`0 0 8px ${s>=100?`#22c55e`:e.color||`#6b7280`}60`}})})]}),e.failed_count>0&&(0,K.jsxs)(`div`,{className:`text-xs text-red-600 dark:text-red-400`,children:[e.failed_count,` `,a(`projects.failed`)]})]}):e.completed_count>0||e.failed_count>0?(0,K.jsxs)(`div`,{className:`flex items-center gap-4 text-xs`,children:[e.completed_count>0&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 text-bambu-gray`,children:[(0,K.jsx)(Do,{className:`w-3.5 h-3.5`}),(0,K.jsxs)(`span`,{children:[e.completed_count,` `,a(`projects.completed`)]})]}),e.failed_count>0&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 text-red-600 dark:text-red-400`,children:[(0,K.jsx)(wu,{className:`w-3.5 h-3.5`}),(0,K.jsxs)(`span`,{children:[e.failed_count,` `,a(`projects.failed`)]})]}),e.queue_count>0&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 text-blue-600 dark:text-blue-400`,children:[(0,K.jsx)(bs,{className:`w-3.5 h-3.5`}),(0,K.jsxs)(`span`,{children:[e.queue_count,` `,a(`projects.inQueue`)]})]})]}):(0,K.jsx)(`div`,{className:`text-xs text-bambu-gray/60 italic`,children:a(`projects.noPrintsYet`)})}),e.archives&&e.archives.length>0&&(0,K.jsxs)(`div`,{className:`mb-4`,children:[(0,K.jsx)(`div`,{className:`grid grid-cols-4 gap-1.5`,children:e.archives.slice(0,4).map(e=>(0,K.jsxs)(`div`,{className:`relative aspect-square rounded-lg bg-bambu-dark overflow-hidden border border-bambu-dark-tertiary`,title:e.print_name||`Unknown`,children:[e.thumbnail_path?(0,K.jsx)(`img`,{src:Q.getArchiveThumbnail(e.id),alt:e.print_name||``,className:`w-full h-full object-cover`}):(0,K.jsx)(`div`,{className:`w-full h-full flex items-center justify-center text-bambu-gray/50`,children:(0,K.jsx)(fl,{className:`w-6 h-6`})}),e.status===`failed`&&(0,K.jsx)(`div`,{className:`absolute inset-0 bg-red-500/40 flex items-center justify-center`,children:(0,K.jsx)(wu,{className:`w-4 h-4 text-white`})})]},e.id))}),e.archive_count>4&&(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1.5 text-center`,children:a(`common.more`,{count:e.archive_count-4})})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between pt-3 border-t border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-4 text-xs text-bambu-gray`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5`,title:a(`projects.printJobs`),children:[(0,K.jsx)(Ic,{className:`w-3.5 h-3.5 text-blue-600 dark:text-blue-400`}),(0,K.jsxs)(`span`,{children:[e.archive_count,` `,a(`projects.plates`)]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5`,title:a(`projects.partsPrinted`),children:[(0,K.jsx)(fl,{className:`w-3.5 h-3.5 text-bambu-green`}),(0,K.jsxs)(`span`,{children:[e.completed_count,` `,a(`projects.parts`)]})]}),e.failed_count>0&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 text-red-600 dark:text-red-400`,title:a(`projects.failedParts`),children:[(0,K.jsx)(wu,{className:`w-3.5 h-3.5`}),(0,K.jsx)(`span`,{children:e.failed_count})]}),e.queue_count>0&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 text-yellow-600 dark:text-yellow-400`,title:a(`projects.inQueue`),children:[(0,K.jsx)(Hc,{className:`w-3.5 h-3.5`}),(0,K.jsx)(`span`,{children:e.queue_count})]})]}),(0,K.jsx)(rs,{className:`w-4 h-4 text-bambu-gray/50 group-hover:text-bambu-gray transition-colors`})]})]})]})}function rWe(){let{t:e}=W(),t=$n(),n=to(),{showToast:r}=kd(),{hasPermission:i}=hd(),[a,o]=(0,y.useState)(!1),[s,c]=(0,y.useState)(),[l,u]=(0,y.useState)(`active`),[d,f]=(0,y.useState)(null),{data:p}=q({queryKey:[`settings`],queryFn:Q.getSettings}),m=sf(p?.currency||`USD`),{data:h,isLoading:g}=q({queryKey:[`projects`,l===`all`?void 0:l],queryFn:()=>Q.getProjects(l===`all`?void 0:l)}),_=J({mutationFn:e=>Q.createProject(e),onSuccess:()=>{n.invalidateQueries({queryKey:[`projects`]}),o(!1),r(e(`projects.toast.created`),`success`)},onError:e=>{r(e.message,`error`)}}),v=J({mutationFn:({id:e,data:t})=>Q.updateProject(e,t),onSuccess:()=>{n.invalidateQueries({queryKey:[`projects`]}),o(!1),c(void 0),r(e(`projects.toast.updated`),`success`)},onError:e=>{r(e.message,`error`)}}),b=J({mutationFn:e=>Q.deleteProject(e),onSuccess:()=>{f(null),r(e(`projects.toast.deleted`),`success`),setTimeout(()=>window.location.reload(),100)},onError:e=>{f(null),r(e.message,`error`)}}),x=J({mutationFn:e=>Q.importProject(e),onSuccess:()=>{n.invalidateQueries({queryKey:[`projects`]}),r(e(`projects.toast.imported`),`success`)},onError:e=>{r(e.message,`error`)}}),S=(0,y.useRef)(null),C=async()=>{try{let t=await Q.getProjects(),n=await Promise.all(t.map(async e=>await Q.exportProjectJson(e.id))),i=new Blob([JSON.stringify(n,null,2)],{type:`application/json`}),a=URL.createObjectURL(i),o=document.createElement(`a`);o.href=a,o.download=`bambuddy_projects_${new Date().toISOString().split(`T`)[0]}.json`,o.click(),URL.revokeObjectURL(a),r(e(`projects.toast.exported`),`success`)}catch(e){r(e.message,`error`)}},w=()=>{S.current?.click()},T=async t=>{let i=t.target.files?.[0];if(i){try{if(i.name.toLowerCase().endsWith(`.zip`))await Q.importProjectFile(i),n.invalidateQueries({queryKey:[`projects`]}),r(e(`projects.toast.imported`),`success`);else{let t=await i.text(),n=JSON.parse(t),a=Array.isArray(n)?n:[n];for(let e of a)await x.mutateAsync(e);a.length>1&&r(e(`projects.toast.multipleImported`,{count:a.length}),`success`)}}catch(t){r(`${e(`projects.toast.importFailed`)}: ${t.message}`,`error`)}t.target.value=``}},E=e=>{s?v.mutate({id:s.id,data:e}):_.mutate(e)},D=e=>{c(e),o(!0)},O=e=>{t(`/projects/${e.id}`)},k=e=>{f(e)},A=()=>{d!==null&&b.mutate(d)},j=h?.reduce((e,t)=>(e[t.status]=(e[t.status]||0)+1,e.all=(e.all||0)+1,e),{})||{};return(0,K.jsxs)(`div`,{className:`p-4 md:p-8 space-y-8`,children:[(0,K.jsx)(`input`,{ref:S,type:`file`,accept:`.json,.zip`,onChange:T,className:`hidden`}),(0,K.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between gap-4`,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)(ac,{className:`w-7 h-7 text-bambu-green`}),e(`projects.title`)]}),(0,K.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:e(`projects.subtitle`)})]}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsxs)($,{variant:`secondary`,onClick:w,disabled:!i(`projects:create`),title:i(`projects:create`)?e(`projects.importProject`):e(`projects.noImportPermission`),children:[(0,K.jsx)(Ou,{className:`w-4 h-4 mr-2`}),e(`projects.import`)]}),(0,K.jsxs)($,{variant:`secondary`,onClick:C,disabled:!i(`projects:read`),title:i(`projects:read`)?e(`projects.exportAll`):e(`projects.noExportPermission`),children:[(0,K.jsx)(zs,{className:`w-4 h-4 mr-2`}),e(`projects.export`)]}),(0,K.jsxs)($,{onClick:()=>o(!0),className:`sm:w-auto w-full`,disabled:!i(`projects:create`),title:i(`projects:create`)?void 0:e(`projects.noCreatePermission`),children:[(0,K.jsx)(Cl,{className:`w-4 h-4 mr-2`}),e(`projects.newProject`)]})]})]}),(0,K.jsx)(`div`,{className:`flex gap-1 p-1 bg-bambu-dark rounded-xl w-fit`,children:[{key:`active`,label:e(`projects.statusActive`),icon:bs},{key:`completed`,label:e(`projects.statusCompleted`),icon:fs},{key:`archived`,label:e(`projects.statusArchived`),icon:Do},{key:`all`,label:e(`common.all`),icon:ac}].map(({key:e,label:t,icon:n})=>(0,K.jsxs)(`button`,{onClick:()=>u(e),className:`flex items-center gap-2 px-4 py-2 text-sm rounded-lg transition-all ${l===e?`bg-bambu-card text-white shadow-sm`:`text-bambu-gray hover:text-white`}`,children:[(0,K.jsx)(n,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{children:t}),j[e]>0&&(0,K.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded-full ${l===e?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark-tertiary`}`,children:j[e]})]},e))}),g?(0,K.jsx)(`div`,{className:`flex items-center justify-center py-20`,children:(0,K.jsxs)(`div`,{className:`flex flex-col items-center gap-3`,children:[(0,K.jsx)(X,{className:`w-8 h-8 animate-spin text-bambu-green`}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`projects.loading`)})]})}):h?.length===0?(0,K.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-20 px-4`,children:[(0,K.jsx)(`div`,{className:`p-4 bg-bambu-dark rounded-2xl mb-4`,children:(0,K.jsx)(ac,{className:`w-12 h-12 text-bambu-gray/50`})}),(0,K.jsx)(`h3`,{className:`text-lg font-medium text-white mb-2`,children:l===`all`?e(`projects.noProjects`):e(`projects.noProjectsFiltered`,{status:l})}),(0,K.jsx)(`p`,{className:`text-bambu-gray text-center max-w-md mb-6`,children:l===`all`?e(`projects.createFirst`):e(`projects.noProjectsFilteredHelp`,{status:l})}),l===`all`&&(0,K.jsxs)($,{onClick:()=>o(!0),disabled:!i(`projects:create`),title:i(`projects:create`)?void 0:e(`projects.noCreatePermission`),children:[(0,K.jsx)(Cl,{className:`w-4 h-4 mr-2`}),e(`projects.createFirstButton`)]})]}):(0,K.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-8`,children:h?.map(t=>(0,K.jsx)(nWe,{project:t,onClick:()=>O(t),onEdit:()=>D(t),onDelete:()=>k(t.id),hasPermission:i,t:e},t.id))}),d!==null&&(0,K.jsx)(Rd,{title:e(`projects.deleteProject`),message:e(`projects.deleteConfirm`),confirmText:e(`projects.deleteProject`),variant:`danger`,onConfirm:A,onCancel:()=>f(null)}),a&&(0,K.jsx)(L6,{project:s,onClose:()=>{o(!1),c(void 0)},onSave:E,isLoading:_.isPending||v.isPending,currencySymbol:m,t:e})]})}function iWe(e){let t=e.toLowerCase();return t.endsWith(`.gcode`)||t.endsWith(`.gcode.3mf`)}function aWe(e){return e>=1e3?`${(e/1e3).toFixed(2)}kg`:`${Math.round(e)}g`}function oWe({status:e,t}){let n={active:`bg-bambu-green/20 text-bambu-green`,completed:`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`,archived:`bg-bambu-gray/20 text-bambu-gray`},r=n[e]||n.active,i={active:t(`projectDetail.status.active`),completed:t(`projectDetail.status.completed`),archived:t(`projectDetail.status.archived`)};return(0,K.jsx)(`span`,{className:`px-2 py-1 rounded text-sm font-medium ${r}`,children:i[e]||e.charAt(0).toUpperCase()+e.slice(1)})}function R6({icon:e,label:t,value:n,subValue:r,hint:i,color:a=`text-bambu-gray`}){return(0,K.jsx)(xd,{children:(0,K.jsx)(Cd,{className:`p-4`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,title:i,children:[(0,K.jsx)(`div`,{className:`p-2 rounded-lg bg-bambu-dark ${a}`,children:(0,K.jsx)(e,{className:`w-5 h-5`})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:t}),(0,K.jsx)(`p`,{className:`text-xl font-semibold text-white`,children:n}),r&&(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray/70`,children:r})]})]})})})}function sWe({archives:e,t}){return e.length===0?(0,K.jsxs)(`div`,{className:`text-center py-8 text-bambu-gray`,children:[(0,K.jsx)(fl,{className:`w-12 h-12 mx-auto mb-2 opacity-50`}),(0,K.jsx)(`p`,{children:t(`projectDetail.noPrints`)})]}):(0,K.jsx)(`div`,{className:`grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 xl:grid-cols-6 gap-3`,children:e.map(e=>(0,K.jsxs)(Ci,{to:`/archives?search=${encodeURIComponent(e.print_name||``)}`,className:`group relative aspect-square rounded-lg bg-bambu-dark border border-bambu-dark-tertiary overflow-hidden hover:border-bambu-green transition-colors`,children:[e.thumbnail_path?(0,K.jsx)(`img`,{src:Q.getArchiveThumbnail(e.id),alt:e.print_name||`Print`,className:`w-full h-full object-cover`}):(0,K.jsx)(`div`,{className:`w-full h-full flex items-center justify-center text-bambu-gray`,children:(0,K.jsx)(fl,{className:`w-8 h-8`})}),e.status===`failed`&&(0,K.jsx)(`div`,{className:`absolute inset-0 bg-red-500/30 flex items-center justify-center`,children:(0,K.jsx)(_s,{className:`w-8 h-8 text-white`})}),e.status===`completed`&&(0,K.jsx)(`div`,{className:`absolute top-1 right-1`,children:(0,K.jsx)(ds,{className:`w-4 h-4 text-bambu-green`})}),(0,K.jsx)(`div`,{className:`absolute inset-x-0 bottom-0 bg-gradient-to-t from-black/80 to-transparent p-2 opacity-0 group-hover:opacity-100 transition-opacity`,children:(0,K.jsx)(`p`,{className:`text-xs text-white truncate`,children:e.print_name||`Unknown`})})]},e.id))})}function cWe({priority:e,t}){let n={low:{color:`bg-gray-500/20 text-gray-400`,label:t(`projectDetail.priority.low`)},normal:{color:`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`,label:t(`projectDetail.priority.normal`)},high:{color:`bg-orange-100 dark:bg-orange-500/20 text-orange-700 dark:text-orange-400`,label:t(`projectDetail.priority.high`)},urgent:{color:`bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400`,label:t(`projectDetail.priority.urgent`)}},{color:r,label:i}=n[e]||n.normal;return(0,K.jsxs)(`span`,{className:`px-2 py-1 rounded text-xs font-medium flex items-center gap-1 ${r}`,children:[e===`urgent`&&(0,K.jsx)(wu,{className:`w-3 h-3`}),i]})}function z6(e,t){if(!e)return null;let n=Tf(e);if(!n)return null;let r=new Date,i=Math.ceil((n.getTime()-r.getTime())/(1e3*60*60*24));return i<0?{color:`text-red-700 dark:text-red-400`,label:t(`projectDetail.dueDate.overdue`)}:i===0?{color:`text-orange-700 dark:text-orange-400`,label:t(`projectDetail.dueDate.today`)}:i<=3?{color:`text-yellow-700 dark:text-yellow-400`,label:t(`projectDetail.dueDate.daysLeft`,{count:i})}:{color:`text-bambu-gray`,label:t(`projectDetail.dueDate.daysLeft`,{count:i})}}function lWe(){let{id:e}=ir(),t=$n(),{t:n}=W(),r=to(),{showToast:i}=kd(),{hasPermission:a}=hd(),[o,s]=(0,y.useState)(!1),[c,l]=(0,y.useState)(!1),[u,d]=(0,y.useState)(``),[f,p]=(0,y.useState)(null),m=parseInt(e||`0`,10),{data:h,isLoading:g,error:_}=q({queryKey:[`project`,m],queryFn:()=>Q.getProject(m),enabled:m>0}),{data:v,isLoading:b}=q({queryKey:[`project-archives`,m],queryFn:()=>Q.getProjectArchives(m),enabled:m>0}),{data:x,isLoading:S}=q({queryKey:[`project-bom`,m],queryFn:()=>Q.getProjectBOM(m),enabled:m>0}),{data:C,isLoading:w}=q({queryKey:[`project-timeline`,m],queryFn:()=>Q.getProjectTimeline(m,20),enabled:m>0}),{data:T}=q({queryKey:[`settings`],queryFn:Q.getSettings}),{data:E}=q({queryKey:[`project-folders`,m],queryFn:()=>Q.getLibraryFoldersByProject(m),enabled:m>0}),{data:D,isLoading:O}=q({queryKey:[`project-files`,m],queryFn:()=>Q.getLibraryFiles(null,!1,m),enabled:m>0}),k=(0,y.useMemo)(()=>{let e=new Map;for(let t of D??[])if(t.folder_id!=null){let n=e.get(t.folder_id)??[];n.push(t),e.set(t.folder_id,n)}return e},[D]),A=sf(T?.currency||`USD`),j=T?.time_format||`system`,M=J({mutationFn:e=>Q.updateProject(m,e),onSuccess:()=>{r.invalidateQueries({queryKey:[`project`,m]}),r.invalidateQueries({queryKey:[`projects`]}),s(!1),l(!1),i(n(`projectDetail.toast.projectUpdated`),`success`)},onError:e=>{i(e.message,`error`)}}),N=()=>{d(h?.notes||``),l(!0)},P=()=>{M.mutate({notes:u})},F=()=>{l(!1),d(``)},[I,L]=(0,y.useState)(``),[R,z]=(0,y.useState)(1),[B,V]=(0,y.useState)(``),[ee,te]=(0,y.useState)(``),[ne,re]=(0,y.useState)(``),[ie,H]=(0,y.useState)(!1),[ae,oe]=(0,y.useState)(!1),[U,se]=(0,y.useState)(null),[ce,le]=(0,y.useState)(``),[ue,de]=(0,y.useState)(1),[fe,pe]=(0,y.useState)(``),[me,he]=(0,y.useState)(``),[ge,_e]=(0,y.useState)(``),[ve,ye]=(0,y.useState)({isOpen:!1,title:``,message:``,onConfirm:()=>{}}),be=J({mutationFn:e=>Q.createBOMItem(m,e),onSuccess:()=>{r.invalidateQueries({queryKey:[`project-bom`,m]}),r.invalidateQueries({queryKey:[`project`,m]}),L(``),z(1),V(``),te(``),re(``),H(!1),i(n(`projectDetail.toast.partAdded`),`success`)},onError:e=>i(e.message,`error`)}),xe=J({mutationFn:({itemId:e,data:t})=>Q.updateBOMItem(m,e,t),onSuccess:()=>{r.invalidateQueries({queryKey:[`project-bom`,m]}),r.invalidateQueries({queryKey:[`project`,m]}),se(null)},onError:e=>i(e.message,`error`)}),Se=J({mutationFn:e=>Q.deleteBOMItem(m,e),onSuccess:()=>{r.invalidateQueries({queryKey:[`project-bom`,m]}),r.invalidateQueries({queryKey:[`project`,m]}),i(n(`projectDetail.toast.partRemoved`),`success`)},onError:e=>i(e.message,`error`)}),Ce=e=>{e.preventDefault(),I.trim()&&be.mutate({name:I.trim(),quantity_needed:R,unit_price:B?parseFloat(B):void 0,sourcing_url:ee.trim()||void 0,remarks:ne.trim()||void 0})},we=e=>{let t=e.is_complete?0:e.quantity_needed;xe.mutate({itemId:e.id,data:{quantity_acquired:t}})},Te=(e,t)=>{ye({isOpen:!0,title:n(`projectDetail.bom.deletePart`),message:n(`projectDetail.bom.deleteConfirm`,{name:t}),onConfirm:()=>{ye(e=>({...e,isOpen:!1})),Se.mutate(e)}})},Ee=e=>{se(e),le(e.name),de(e.quantity_needed),pe(e.unit_price?.toString()||``),he(e.sourcing_url||``),_e(e.remarks||``)},De=e=>{e.preventDefault(),!(!U||!ce.trim())&&xe.mutate({itemId:U.id,data:{name:ce.trim(),quantity_needed:ue,unit_price:fe?parseFloat(fe):void 0,sourcing_url:me.trim()||void 0,remarks:ge.trim()||void 0}})},Oe=()=>{se(null)},ke=async()=>{try{let{blob:e,filename:t}=await Q.exportProjectZip(Number(m)),r=URL.createObjectURL(e),a=document.createElement(`a`);a.href=r,a.download=t||`${h?.name||`project`}_${new Date().toISOString().split(`T`)[0]}.zip`,a.click(),URL.revokeObjectURL(r),i(n(`projectDetail.toast.projectExported`),`success`)}catch(e){i(e.message,`error`)}},Ae=J({mutationFn:()=>Q.createTemplateFromProject(m),onSuccess:()=>{r.invalidateQueries({queryKey:[`projects`]}),i(n(`projectDetail.toast.templateCreated`),`success`)},onError:e=>i(e.message,`error`)}),je=e=>Df(e,j,{month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`});if(g)return(0,K.jsx)(`div`,{className:`flex items-center justify-center py-24`,children:(0,K.jsx)(X,{className:`w-8 h-8 animate-spin text-bambu-green`})});if(_||!h)return(0,K.jsxs)(`div`,{className:`text-center py-24`,children:[(0,K.jsx)(`p`,{className:`text-bambu-gray`,children:_?`${n(`common.error`)}: ${_.message}`:n(`projectDetail.notFound`)}),(0,K.jsx)($,{variant:`secondary`,className:`mt-4`,onClick:()=>t(`/projects`),children:n(`projectDetail.backToProjects`)})]});let Me=h.stats,Ne=Me?.progress_percent??0,Pe=Me?.parts_progress_percent??0;return(0,K.jsxs)(`div`,{className:`p-4 md:p-8 space-y-8`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-bambu-gray`,children:[(0,K.jsx)(Ci,{to:`/projects`,className:`hover:text-white transition-colors`,children:n(`nav.projects`)}),(0,K.jsx)(rs,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{className:`text-white`,children:h.name})]}),(0,K.jsxs)(`div`,{className:`flex items-start justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,K.jsx)(`button`,{onClick:()=>t(`/projects`),className:`p-2 rounded-lg bg-bambu-card hover:bg-bambu-dark-tertiary transition-colors`,children:(0,K.jsx)(Ao,{className:`w-5 h-5 text-bambu-gray`})}),(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`w-4 h-4 rounded-full shrink-0`,style:{backgroundColor:h.color||`#6b7280`}}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h1`,{className:`text-2xl font-bold text-white`,children:h.name}),h.description&&(0,K.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:h.description})]})]}),(0,K.jsx)(oWe,{status:h.status,t:n})]}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsxs)($,{variant:`secondary`,onClick:ke,disabled:!a(`projects:read`),title:a(`projects:read`)?n(`projectDetail.exportProject`):n(`projectDetail.noExportPermission`),children:[(0,K.jsx)(zs,{className:`w-4 h-4 mr-2`}),n(`projectDetail.export`)]}),(0,K.jsxs)($,{onClick:()=>s(!0),disabled:!a(`projects:update`),title:a(`projects:update`)?void 0:n(`projectDetail.noEditPermission`),children:[(0,K.jsx)(_l,{className:`w-4 h-4 mr-2`}),n(`common.edit`)]})]})]}),(h.target_count||h.target_parts_count)&&(0,K.jsx)(xd,{children:(0,K.jsxs)(Cd,{className:`p-4 space-y-4`,children:[h.target_count&&(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:n(`projectDetail.progress.platesProgress`)}),(0,K.jsxs)(`span`,{className:`text-sm font-medium text-white`,children:[Me?.total_archives||0,` / `,h.target_count,` `,n(`projectDetail.progress.printJobs`)]})]}),(0,K.jsx)(`div`,{className:`h-3 bg-bambu-dark rounded-full overflow-hidden`,children:(0,K.jsx)(`div`,{className:`h-full transition-all duration-500`,style:{width:`${Math.min(Ne,100)}%`,backgroundColor:Ne>=100?`#22c55e`:h.color||`#6b7280`}})}),(0,K.jsxs)(`div`,{className:`flex justify-between mt-1`,children:[(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray/70`,children:n(`projectDetail.progress.percentComplete`,{percent:Ne.toFixed(0)})}),Me?.remaining_prints!=null&&Me.remaining_prints>0&&(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray/70`,children:n(`projectDetail.progress.remaining`,{count:Me.remaining_prints})})]})]}),h.target_parts_count&&(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:n(`projectDetail.progress.partsProgress`)}),(0,K.jsxs)(`span`,{className:`text-sm font-medium text-white`,children:[Me?.completed_prints||0,` / `,h.target_parts_count,` `,n(`projectDetail.progress.parts`)]})]}),(0,K.jsx)(`div`,{className:`h-3 bg-bambu-dark rounded-full overflow-hidden`,children:(0,K.jsx)(`div`,{className:`h-full transition-all duration-500`,style:{width:`${Math.min(Pe,100)}%`,backgroundColor:Pe>=100?`#22c55e`:h.color||`#6b7280`}})}),(0,K.jsxs)(`div`,{className:`flex justify-between mt-1`,children:[(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray/70`,children:n(`projectDetail.progress.percentComplete`,{percent:Pe.toFixed(0)})}),Me?.remaining_parts!=null&&Me.remaining_parts>0&&(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray/70`,children:n(`projectDetail.progress.remaining`,{count:Me.remaining_parts})})]})]})]})}),Me&&(0,K.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-4`,children:[(0,K.jsx)(xd,{children:(0,K.jsx)(Cd,{className:`p-4`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`p-2 rounded-lg bg-bambu-dark text-bambu-green`,children:(0,K.jsx)(fl,{className:`w-5 h-5`})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`projectDetail.stats.printJobs`)}),(0,K.jsxs)(`p`,{className:`text-xl font-semibold text-white`,children:[Me.total_archives,` `,(0,K.jsx)(`span`,{className:`text-sm font-normal text-bambu-gray`,children:n(`projectDetail.stats.total`)})]}),Me.failed_prints>0&&(0,K.jsx)(`p`,{className:`text-sm text-status-error`,children:n(`projectDetail.stats.failed`,{count:Me.failed_prints})}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`projectDetail.stats.partsPrinted`,{count:Me.completed_prints})})]})]})})}),(0,K.jsx)(R6,{icon:bs,label:n(`projectDetail.stats.printTime`),value:Nf(Me.total_print_time_hours),color:`text-yellow-600 dark:text-yellow-400`}),(0,K.jsx)(R6,{icon:El,label:n(`projectDetail.stats.filamentUsed`),value:aWe(Me.total_filament_grams),color:`text-purple-600 dark:text-purple-400`})]}),Me&&(()=>{let e=Me.estimated_cost+Me.total_energy_cost+Me.bom_cost;return Me.estimated_cost>0||e>0||h.budget!==null})()&&(0,K.jsx)(xd,{children:(0,K.jsxs)(Cd,{className:`p-4`,children:[(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white mb-3`,children:n(`projectDetail.cost.title`)}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-4`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.cost.filamentCost`)}),(0,K.jsxs)(`p`,{className:`text-lg font-semibold text-white`,children:[A,Me.estimated_cost.toFixed(2)]})]}),Me.total_energy_kwh>0&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.cost.energy`)}),(0,K.jsxs)(`p`,{className:`text-lg font-semibold text-white`,children:[Me.total_energy_kwh.toFixed(3),` kWh`,Me.total_energy_cost>0&&(0,K.jsxs)(`span`,{className:`text-sm text-bambu-gray ml-1`,children:[`(`,A,Me.total_energy_cost.toFixed(2),`)`]})]})]}),(()=>{let e=Me.estimated_cost+Me.total_energy_cost+Me.bom_cost;return e<=0?null:(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.cost.totalCost`)}),(0,K.jsxs)(`p`,{className:`text-lg font-semibold text-bambu-green`,children:[A,e.toFixed(2)]}),Me.bom_cost>0&&(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray/70`,children:n(`projectDetail.cost.includesBom`)})]})})(),h.budget!==null&&(()=>{let e=Me.estimated_cost+Me.total_energy_cost+Me.bom_cost,t=h.budget-e;return(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.cost.budget`)}),(0,K.jsxs)(`p`,{className:`text-sm text-bambu-gray`,children:[n(`projectDetail.cost.total`),`: `,(0,K.jsxs)(`span`,{className:`text-white font-semibold`,children:[A,h.budget.toFixed(2)]})]}),(0,K.jsxs)(`p`,{className:`text-sm ${t>=0?`text-bambu-green`:`text-red-700 dark:text-red-400`}`,children:[n(`projectDetail.cost.remaining`),`: `,(0,K.jsxs)(`span`,{className:`font-semibold`,children:[A,t.toFixed(2)]})]})]})})()]})]})}),h.children&&h.children.length>0&&(0,K.jsx)(xd,{children:(0,K.jsxs)(Cd,{className:`p-4`,children:[(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2 mb-3`,children:[(0,K.jsx)(lc,{className:`w-5 h-5`}),n(`projectDetail.subProjects.title`,{count:h.children.length})]}),(0,K.jsx)(`div`,{className:`space-y-2`,children:h.children.map(e=>(0,K.jsxs)(Ci,{to:`/projects/${e.id}`,className:`flex items-center justify-between p-3 bg-bambu-dark rounded-lg hover:bg-bambu-dark-tertiary transition-colors`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`w-3 h-3 rounded-full`,style:{backgroundColor:e.color||`#6b7280`}}),(0,K.jsx)(`span`,{className:`text-white`,children:e.name}),(0,K.jsx)(`span`,{className:`text-xs px-2 py-0.5 rounded ${e.status===`completed`?`bg-status-ok/20 text-status-ok`:e.status===`archived`?`bg-bambu-gray/20 text-bambu-gray`:`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`}`,children:e.status})]}),e.progress_percent!==null&&(0,K.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[e.progress_percent.toFixed(0),`%`]})]},e.id))})]})}),h.parent_id&&h.parent_name&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,K.jsx)(Ic,{className:`w-4 h-4 text-bambu-gray`}),(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:n(`projectDetail.partOf`)}),(0,K.jsx)(Ci,{to:`/projects/${h.parent_id}`,className:`text-bambu-green hover:underline`,children:h.parent_name})]}),(h.tags||h.due_date||h.priority!==`normal`)&&(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4`,children:[h.priority&&h.priority!==`normal`&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.priorityLabel`)}),(0,K.jsx)(cWe,{priority:h.priority,t:n})]}),h.due_date&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(Yo,{className:`w-4 h-4 text-bambu-gray`}),(0,K.jsx)(`span`,{className:`text-sm text-white`,children:Ef(h.due_date,{year:`numeric`,month:`short`,day:`numeric`})}),z6(h.due_date,n)&&(0,K.jsxs)(`span`,{className:`text-xs ${z6(h.due_date,n).color}`,children:[`(`,z6(h.due_date,n).label,`)`]})]}),h.tags&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(pu,{className:`w-4 h-4 text-bambu-gray`}),(0,K.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:h.tags.split(`,`).map((e,t)=>(0,K.jsx)(`span`,{className:`px-2 py-0.5 bg-bambu-dark-tertiary text-bambu-gray text-xs rounded`,children:e.trim()},t))})]})]}),(0,K.jsx)(xd,{children:(0,K.jsxs)(Cd,{className:`p-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(ec,{className:`w-5 h-5`}),n(`projectDetail.notes.title`)]}),c?(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:F,disabled:M.isPending,children:[(0,K.jsx)(Hu,{className:`w-4 h-4 mr-1`}),n(`common.cancel`)]}),(0,K.jsxs)($,{size:`sm`,onClick:P,disabled:M.isPending,children:[M.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin mr-1`}):(0,K.jsx)(Pl,{className:`w-4 h-4 mr-1`}),n(`common.save`)]})]}):(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:N,disabled:!a(`projects:update`),title:a(`projects:update`)?void 0:n(`projectDetail.notes.noEditPermission`),children:[(0,K.jsx)(_l,{className:`w-4 h-4 mr-1`}),n(`common.edit`)]})]}),c?(0,K.jsx)(Q0,{content:u,onChange:d,placeholder:n(`projectDetail.notes.placeholder`)}):h.notes?(0,K.jsx)(`div`,{className:`prose prose-invert prose-sm max-w-none`,dangerouslySetInnerHTML:{__html:UG.sanitize(h.notes)}}):(0,K.jsx)(`p`,{className:`text-bambu-gray/70 text-sm italic`,children:n(`projectDetail.notes.empty`)})]})}),(0,K.jsx)(xd,{children:(0,K.jsxs)(Cd,{className:`p-4`,children:[(0,K.jsx)(`div`,{className:`flex items-center justify-between mb-3`,children:(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(oc,{className:`w-5 h-5`}),n(`projectDetail.files.title`)]})}),(0,K.jsxs)(`p`,{className:`text-xs text-bambu-gray mb-3`,children:[(0,K.jsx)(Ci,{to:`/files`,className:`text-bambu-green hover:underline`,children:n(`projectDetail.files.linkFolders`)}),` `,n(`projectDetail.files.forQuickAccess`)]}),E&&E.length>0?(0,K.jsx)(`div`,{className:`space-y-4`,children:E.map(e=>{let t=k.get(e.id)??[],r=O;return(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(Ci,{to:`/files?folder=${e.id}`,className:`flex items-center justify-between p-3 bg-bambu-dark rounded-lg hover:bg-bambu-dark-tertiary transition-colors mb-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0`,children:[(0,K.jsx)(oc,{className:`w-5 h-5 text-bambu-green shrink-0`}),(0,K.jsxs)(`div`,{className:`min-w-0`,children:[(0,K.jsx)(`p`,{className:`text-sm text-white truncate`,children:e.name}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`projectDetail.files.fileCount`,{count:e.file_count})})]})]}),(0,K.jsx)(rs,{className:`w-4 h-4 text-bambu-gray shrink-0`})]}),r?(0,K.jsx)(`div`,{className:`flex items-center gap-2 px-3 py-2 text-bambu-gray text-sm`,children:(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`})}):t.length===0?(0,K.jsx)(`p`,{className:`text-bambu-gray/60 text-xs italic px-3`,children:n(`projectDetail.files.noFiles`)}):(0,K.jsx)(`div`,{className:`space-y-1 pl-3`,children:t.map(e=>{let t=iWe(e.filename);return(0,K.jsxs)(`div`,{className:`flex items-center gap-3 p-2 rounded-lg hover:bg-bambu-dark-tertiary transition-colors`,children:[(0,K.jsx)(`div`,{className:`w-10 h-10 shrink-0 rounded bg-bambu-dark overflow-hidden flex items-center justify-center`,children:e.thumbnail_path?(0,K.jsx)(`img`,{src:Q.getLibraryFileThumbnailUrl(e.id),alt:e.print_name||e.filename,className:`w-full h-full object-cover`}):(0,K.jsx)(Xs,{className:`w-5 h-5 text-bambu-gray/40`})}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsx)(`p`,{className:`text-sm text-white truncate`,title:e.print_name||e.filename,children:e.print_name||e.filename}),(0,K.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded font-medium ${e.file_type===`3mf`?`bg-bambu-green/20 text-bambu-green`:e.file_type===`gcode`||e.file_type===`gcode.3mf`?`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`:`bg-bambu-gray/20 text-bambu-gray`}`,children:e.file_type.toUpperCase()})]}),t&&(0,K.jsx)(`div`,{className:`flex items-center gap-1 shrink-0`,children:(0,K.jsx)(`button`,{onClick:()=>p(e),title:n(`common.print`),className:`p-1.5 rounded hover:bg-bambu-green/20 text-bambu-green transition-colors`,children:(0,K.jsx)(El,{className:`w-4 h-4`})})})]},e.id)})})]},e.id)})}):(0,K.jsx)(`p`,{className:`text-bambu-gray/70 text-sm italic`,children:n(`projectDetail.files.empty`)})]})}),(0,K.jsx)(xd,{children:(0,K.jsxs)(Cd,{className:`p-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-4`,children:[(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(Yl,{className:`w-5 h-5`}),n(`projectDetail.bom.title`),Me&&Me.bom_total_items>0&&(0,K.jsxs)(`span`,{className:`text-sm font-normal text-bambu-gray`,children:[`(`,n(`projectDetail.bom.acquired`,{completed:Me.bom_completed_items,total:Me.bom_total_items}),`)`]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[x&&x.some(e=>e.is_complete)&&(0,K.jsx)(`button`,{onClick:()=>oe(!ae),className:`text-xs px-2 py-1 rounded transition-colors ${ae?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark text-bambu-gray hover:text-white`}`,children:n(ae?`projectDetail.bom.showAll`:`projectDetail.bom.hideDone`)}),!ie&&(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:()=>H(!0),disabled:!a(`projects:update`),title:a(`projects:update`)?void 0:n(`projectDetail.bom.noAddPermission`),children:[(0,K.jsx)(Cl,{className:`w-4 h-4 mr-1`}),n(`projectDetail.bom.addPart`)]})]})]}),ie&&(0,K.jsxs)(`form`,{onSubmit:Ce,className:`bg-bambu-dark rounded-lg p-4 mb-4 space-y-3`,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-3`,children:[(0,K.jsx)(`input`,{type:`text`,value:I,onChange:e=>L(e.target.value),className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:n(`projectDetail.bom.partNamePlaceholder`),autoFocus:!0}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)(`input`,{type:`number`,value:R,onChange:e=>z(parseInt(e.target.value)||1),className:`w-20 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white focus:outline-none focus:border-bambu-green`,min:`1`,placeholder:n(`projectDetail.bom.qty`)}),(0,K.jsx)(`input`,{type:`number`,step:`0.01`,value:B,onChange:e=>V(e.target.value),className:`flex-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:n(`projectDetail.bom.price`,{currency:A})})]})]}),(0,K.jsx)(`input`,{type:`url`,value:ee,onChange:e=>te(e.target.value),className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:n(`projectDetail.bom.sourcingUrlPlaceholder`)}),(0,K.jsx)(`input`,{type:`text`,value:ne,onChange:e=>re(e.target.value),className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:n(`projectDetail.bom.remarksPlaceholder`)}),(0,K.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,K.jsx)($,{type:`button`,variant:`secondary`,size:`sm`,onClick:()=>H(!1),children:n(`common.cancel`)}),(0,K.jsx)($,{type:`submit`,size:`sm`,disabled:!I.trim()||be.isPending,children:be.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):n(`projectDetail.bom.addPart`)})]})]}),S?(0,K.jsx)(`div`,{className:`flex items-center justify-center py-4`,children:(0,K.jsx)(X,{className:`w-6 h-6 animate-spin text-bambu-green`})}):x&&x.length>0?(0,K.jsxs)(`div`,{className:`space-y-2`,children:[x.filter(e=>!ae||!e.is_complete).map(e=>(0,K.jsx)(`div`,{className:`p-3 rounded-lg transition-colors ${e.is_complete?`bg-status-ok/10`:`bg-bambu-dark`}`,children:U?.id===e.id?(0,K.jsxs)(`form`,{onSubmit:De,className:`space-y-3`,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-3`,children:[(0,K.jsx)(`input`,{type:`text`,value:ce,onChange:e=>le(e.target.value),className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:n(`projectDetail.bom.partName`),autoFocus:!0}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)(`input`,{type:`number`,value:ue,onChange:e=>de(parseInt(e.target.value)||1),className:`w-20 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white focus:outline-none focus:border-bambu-green`,min:`1`,placeholder:n(`projectDetail.bom.qty`)}),(0,K.jsx)(`input`,{type:`number`,step:`0.01`,value:fe,onChange:e=>pe(e.target.value),className:`flex-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:n(`projectDetail.bom.price`,{currency:A})})]})]}),(0,K.jsx)(`input`,{type:`url`,value:me,onChange:e=>he(e.target.value),className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:n(`projectDetail.bom.sourcingUrlPlaceholder`)}),(0,K.jsx)(`input`,{type:`text`,value:ge,onChange:e=>_e(e.target.value),className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:n(`projectDetail.bom.remarksPlaceholder`)}),(0,K.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,K.jsx)($,{type:`button`,variant:`secondary`,size:`sm`,onClick:Oe,children:n(`common.cancel`)}),(0,K.jsx)($,{type:`submit`,size:`sm`,disabled:!ce.trim()||xe.isPending,children:xe.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):n(`common.save`)})]})]}):(0,K.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,K.jsx)(`button`,{onClick:()=>a(`projects:update`)&&we(e),disabled:xe.isPending||!a(`projects:update`),title:a(`projects:update`)?void 0:n(`projectDetail.bom.noUpdatePermission`),className:`w-5 h-5 mt-0.5 rounded border-2 flex items-center justify-center transition-colors shrink-0 ${e.is_complete?`bg-status-ok border-status-ok text-white`:a(`projects:update`)?`border-bambu-gray hover:border-bambu-green`:`border-bambu-gray/50 cursor-not-allowed`}`,children:e.is_complete&&(0,K.jsx)(ds,{className:`w-3 h-3`})}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,K.jsxs)(`p`,{className:`text-sm font-medium ${e.is_complete?`text-bambu-gray line-through`:`text-white`}`,children:[e.name,(0,K.jsxs)(`span`,{className:`text-bambu-gray font-normal ml-2`,children:[`x`,e.quantity_needed]})]}),e.unit_price!==null&&(0,K.jsxs)(`span`,{className:`text-xs text-bambu-green whitespace-nowrap`,children:[A,(e.unit_price*e.quantity_needed).toFixed(2)]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(`button`,{onClick:()=>a(`projects:update`)&&Ee(e),disabled:!a(`projects:update`),className:`p-1 rounded transition-colors shrink-0 ${a(`projects:update`)?`hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white`:`text-bambu-gray/50 cursor-not-allowed`}`,title:a(`projects:update`)?n(`common.edit`):n(`projectDetail.bom.noEditPermission`),children:(0,K.jsx)(yl,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>a(`projects:update`)&&Te(e.id,e.name),disabled:!a(`projects:update`),className:`p-1 rounded transition-colors shrink-0 ${a(`projects:update`)?`hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-red-400`:`text-bambu-gray/50 cursor-not-allowed`}`,title:a(`projects:update`)?n(`common.delete`):n(`projectDetail.bom.noDeletePermission`),children:(0,K.jsx)(xu,{className:`w-4 h-4`})})]})]}),e.sourcing_url&&(0,K.jsxs)(`a`,{href:e.sourcing_url,target:`_blank`,rel:`noopener noreferrer`,className:`flex items-center gap-1 mt-1 text-xs text-blue-700 dark:text-blue-400 hover:text-blue-900 dark:hover:text-blue-300 transition-colors`,onClick:e=>e.stopPropagation(),children:[(0,K.jsx)(Ks,{className:`w-3 h-3 shrink-0`}),(0,K.jsx)(`span`,{className:`truncate`,children:(()=>{try{return new URL(e.sourcing_url).hostname.replace(`www.`,``)}catch{return e.sourcing_url}})()})]}),e.remarks&&(0,K.jsx)(`p`,{className:`mt-1 text-xs text-bambu-gray/80 italic`,children:e.remarks})]})]})},e.id)),Me&&Me.bom_cost>0&&(0,K.jsxs)(`div`,{className:`pt-2 mt-2 border-t border-bambu-dark-tertiary flex justify-between text-sm`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:n(`projectDetail.bom.totalCost`)}),(0,K.jsxs)(`span`,{className:`text-white font-medium`,children:[A,Me.bom_cost.toFixed(2)]})]})]}):(0,K.jsx)(`p`,{className:`text-bambu-gray/70 text-sm italic`,children:n(`projectDetail.bom.empty`)})]})}),(0,K.jsx)(xd,{children:(0,K.jsxs)(Cd,{className:`p-4`,children:[(0,K.jsx)(`div`,{className:`flex items-center justify-between mb-3`,children:(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(Dc,{className:`w-5 h-5`}),n(`projectDetail.timeline.title`)]})}),w?(0,K.jsx)(`div`,{className:`flex items-center justify-center py-4`,children:(0,K.jsx)(X,{className:`w-6 h-6 animate-spin text-bambu-green`})}):C&&C.length>0?(0,K.jsx)(`div`,{className:`space-y-3`,children:C.slice(0,10).map((e,t)=>(0,K.jsxs)(`div`,{className:`flex gap-3`,children:[(0,K.jsxs)(`div`,{className:`w-8 h-8 rounded-full flex items-center justify-center shrink-0 ${e.event_type===`print_completed`?`bg-status-ok/20 text-status-ok`:e.event_type===`print_failed`?`bg-status-error/20 text-status-error`:e.event_type===`print_started`?`bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400`:`bg-bambu-dark-tertiary text-bambu-gray`}`,children:[e.event_type===`print_completed`&&(0,K.jsx)(ds,{className:`w-4 h-4`}),e.event_type===`print_failed`&&(0,K.jsx)(_s,{className:`w-4 h-4`}),e.event_type===`print_started`&&(0,K.jsx)(El,{className:`w-4 h-4`}),e.event_type===`queued`&&(0,K.jsx)(Hc,{className:`w-4 h-4`}),e.event_type===`project_created`&&(0,K.jsx)(Cl,{className:`w-4 h-4`})]}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsx)(`p`,{className:`text-sm text-white`,children:e.title}),e.description&&(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray truncate`,children:e.description}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray/70`,children:je(e.timestamp)})]})]},t))}):(0,K.jsx)(`p`,{className:`text-bambu-gray/70 text-sm italic`,children:n(`projectDetail.timeline.empty`)})]})}),!h.is_template&&(0,K.jsx)(`div`,{className:`flex justify-end`,children:(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:()=>Ae.mutate(),disabled:Ae.isPending||!a(`projects:create`),title:a(`projects:create`)?void 0:n(`projectDetail.template.noCreatePermission`),children:[Ae.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin mr-2`}):(0,K.jsx)(As,{className:`w-4 h-4 mr-2`}),n(`projectDetail.template.saveAsTemplate`)]})}),Me&&(Me.queued_prints>0||Me.in_progress_prints>0)&&(0,K.jsx)(xd,{children:(0,K.jsxs)(Cd,{className:`p-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(Hc,{className:`w-5 h-5`}),n(`projectDetail.queue.title`)]}),(0,K.jsx)(Ci,{to:`/queue?project=${m}`,className:`text-sm text-bambu-green hover:underline`,children:n(`projectDetail.queue.viewAll`)})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-4 text-sm`,children:[Me.in_progress_prints>0&&(0,K.jsx)(`span`,{className:`text-yellow-700 dark:text-yellow-400`,children:n(`projectDetail.queue.printing`,{count:Me.in_progress_prints})}),Me.queued_prints>0&&(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:n(`projectDetail.queue.queued`,{count:Me.queued_prints})})]})]})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`div`,{className:`flex items-center justify-between mb-4`,children:(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(fl,{className:`w-5 h-5`}),n(`projectDetail.prints.title`,{count:v?.length||0})]})}),b?(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-green`})}):(0,K.jsx)(sWe,{archives:v||[],t:n})]}),o&&(0,K.jsx)(L6,{t:n,currencySymbol:A,project:{...h,archive_count:Me?.total_archives||0,total_items:Me?.total_items||0,completed_count:Me?.completed_prints||0,failed_count:Me?.failed_prints||0,queue_count:Me?.queued_prints||0,progress_percent:Me?.progress_percent||null,archives:[]},onClose:()=>s(!1),onSave:e=>M.mutate(e),isLoading:M.isPending}),ve.isOpen&&(0,K.jsx)(Rd,{title:ve.title,message:ve.message,confirmText:n(`common.delete`),variant:`danger`,onConfirm:ve.onConfirm,onCancel:()=>ye(e=>({...e,isOpen:!1}))}),f&&(0,K.jsx)(oW,{mode:`create`,libraryFileId:f.id,archiveName:f.print_name||f.filename,projectId:m,onClose:()=>p(null),onSuccess:()=>{p(null),r.invalidateQueries({queryKey:[`archives`]}),r.invalidateQueries({queryKey:[`queue`]})}})]})}function uWe({archiveId:e,libraryFileId:t,title:n,fileType:r,onClose:i,onSliceWithBambuddy:a}){let{t:o}=W(),{data:s}=q({queryKey:[`settings`],queryFn:Q.getSettings}),c=s?.open_in_slicer||s?.preferred_slicer||`bambu_studio`,l=t!=null,[u,d]=(0,y.useState)(null),[f,p]=(0,y.useState)(null),[m,h]=(0,y.useState)(!0),[g,_]=(0,y.useState)(null),[v,b]=(0,y.useState)(!1),[x,S]=(0,y.useState)(null),[C,w]=(0,y.useState)(0),[T,E]=(0,y.useState)(!1),[D,O]=(0,y.useState)(null),[k,A]=(0,y.useState)(!1),[j,M]=(0,y.useState)(!1),N=(0,y.useRef)(null),P=(0,y.useRef)(null),F=.35;(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&i()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[i]),(0,y.useEffect)(()=>{if(h(!0),l){let e=(r||``).toLowerCase(),t=e===`3mf`||e===`gcode.3mf`,n=t||e===`stl`,i=t||e===`gcode`;p({has_model:n,has_gcode:i,has_source:!1,build_volume:{x:256,y:256,z:256},filament_colors:[]}),d(n?`3d`:i?`gcode`:null),h(!1);return}if(!e){p(null),d(null),h(!1);return}Q.getArchiveCapabilities(e).then(e=>{p(e),e.has_model?d(`3d`):e.has_gcode&&d(`gcode`),h(!1)}).catch(()=>{p({has_model:!0,has_gcode:!1,has_source:!1,build_volume:{x:256,y:256,z:256},filament_colors:[]}),d(`3d`),h(!1)})},[e,r,l]),(0,y.useEffect)(()=>{if(b(!0),S(null),w(0),l){let e=(r||``).toLowerCase();if(!t||!(e===`3mf`||e===`gcode.3mf`)){_(null),b(!1);return}Q.getLibraryFilePlates(t).then(e=>_(e)).catch(()=>_(null)).finally(()=>b(!1));return}if(!e){_(null),b(!1);return}Q.getArchivePlates(e).then(e=>_(e)).catch(()=>_(null)).finally(()=>b(!1))},[e,r,l,t]);let I=(0,y.useMemo)(()=>g?.plates??[],[g]),L=(g?.is_multi_plate??!1)&&I.length>1,R=T&&L,z=x==null?null:I.find(e=>e.index===x)??null,B=e=>e.object_count??e.objects?.length??0,V=I.reduce((e,t)=>e+B(t),0),ee=z?B(z):V,te=z?o(`modelViewer.plateNumber`,{number:z.index}):o(`modelViewer.allPlates`),ne=I.length>0,re=(0,y.useRef)(null),ie=(0,y.useRef)(null),[H,ae]=(0,y.useState)(10),[oe,U]=(0,y.useState)(3),se=I.length>H,ce=Math.max(1,Math.ceil(I.length/H)),le=se?I.slice(C*H,(C+1)*H):I;(0,y.useEffect)(()=>{if(!R){ae(10),U(3);return}let e=re.current,t=ie.current;if(!e||!t)return;let n=0,r=()=>{let n=t.clientWidth,r=Math.floor(n/210),i=Math.max(3,Math.min(5,r||3));U(e=>e===i?e:i);let a=window.getComputedStyle(e),o=Number.parseFloat(a.rowGap||`0`),s=e.querySelector(`button`)?.getBoundingClientRect().height??44,c=t.clientHeight,l=Math.max(1,Math.floor((c+o)/(s+o)))*i,u=Math.max(1,l-1);ae(e=>e===u?e:u)},i=()=>{n&&cancelAnimationFrame(n),n=requestAnimationFrame(r)};i();let a=new ResizeObserver(i);return a.observe(t),a.observe(e),()=>{n&&cancelAnimationFrame(n),a.disconnect()}},[R,I.length]),(0,y.useEffect)(()=>{if(!se){w(0);return}w(e=>Math.min(e,ce-1))},[I.length,se,ce]),(0,y.useEffect)(()=>{if(!se||x==null)return;let e=I.findIndex(e=>e.index===x);if(e<0)return;let t=Math.floor(e/H);w(e=>e===t?e:t)},[I,H,x,se]),(0,y.useEffect)(()=>{if(!R){O(null),M(!1);return}if(j)return;let e=N.current,t=P.current;if(!e||!t)return;let n=e.clientHeight;if(!n)return;let r=Math.max(240,n*F),i=Math.max(160,n-10-r),a=Math.min(t.scrollHeight,i);O(Math.max(160,a))},[R,j,I.length,C,10,160,240,F]),(0,y.useEffect)(()=>{if(!k)return;let e=e=>{let t=N.current;if(!t)return;let n=t.getBoundingClientRect(),r=n.height;if(!r)return;let i=Math.max(240,r*F),a=Math.max(160,r-10-i);O(Math.min(a,Math.max(160,e.clientY-n.top)))},t=()=>{A(!1),M(!0)};return document.addEventListener(`mousemove`,e),document.addEventListener(`mouseup`,t),document.body.style.cursor=`row-resize`,document.body.style.userSelect=`none`,()=>{document.removeEventListener(`mousemove`,e),document.removeEventListener(`mouseup`,t),document.body.style.cursor=``,document.body.style.userSelect=``}},[k,10,160,240,F]);let ue=l?(r||``).toLowerCase()===`3mf`:!0,de=(()=>{let e=(r||``).toLowerCase();return e===`3mf`||e===`stl`||e===`step`||e===`stp`})(),fe=!!(l&&s?.use_slicer_api&&a&&de);return(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 ${T?`p-0`:`p-8`}`,onClick:i,children:(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary w-full flex flex-col ${T?`h-full max-w-none rounded-none`:`h-[80vh] max-w-4xl rounded-xl`}`,onClick:e=>e.stopPropagation(),children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 flex-1 mr-4`,children:[(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white truncate`,children:n}),ne&&(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray bg-bambu-dark-tertiary/70 px-2 py-1 rounded whitespace-nowrap`,children:[te,`: `,o(`modelViewer.objectCount`,{count:ee})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[fe?(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:a,children:[(0,K.jsx)(Ds,{className:`w-4 h-4`}),o(`slice.action`)]}):(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:async()=>{if(!ue)return;let r=n||`model`;try{if(l){let{token:e}=await Q.createLibrarySlicerToken(t),n=Q.getLibrarySlicerDownloadUrl(t,e,r);UW(`${window.location.origin}${n}`,c)}else{let{token:t}=await Q.createArchiveSlicerToken(e),n=Q.getArchiveSlicerDownloadUrl(e,t,r);UW(`${window.location.origin}${n}`,c)}}catch{UW(l?`${window.location.origin}${Q.getLibraryFileDownloadUrl(t)}`:`${window.location.origin}${Q.getArchiveForSlicer(e,r)}`,c)}},disabled:!ue,children:[(0,K.jsx)(Ks,{className:`w-4 h-4`}),o(`modelViewer.openInSlicer`)]}),(0,K.jsx)($,{variant:`secondary`,size:`sm`,onClick:()=>E(e=>!e),title:T?`Exit fullscreen`:`Enter fullscreen`,children:T?(0,K.jsx)(tl,{className:`w-4 h-4`}):(0,K.jsx)(Zc,{className:`w-4 h-4`})}),(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:i,children:(0,K.jsx)(Hu,{className:`w-5 h-5`})})]})]}),f&&(0,K.jsxs)(`div`,{className:`flex border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`button`,{onClick:()=>f.has_model&&d(`3d`),disabled:!f.has_model,className:`flex items-center gap-2 px-6 py-3 text-sm font-medium transition-colors ${u===`3d`?`text-bambu-green border-b-2 border-bambu-green`:f.has_model?`text-bambu-gray hover:text-white`:`text-bambu-gray/30 cursor-not-allowed`}`,children:[(0,K.jsx)(Uo,{className:`w-4 h-4`}),o(`modelViewer.tabs.model`),!f.has_model&&(0,K.jsxs)(`span`,{className:`text-xs`,children:[`(`,o(`modelViewer.notAvailable`),`)`]})]}),(0,K.jsxs)(`button`,{onClick:()=>f.has_gcode&&d(`gcode`),disabled:!f.has_gcode,className:`flex items-center gap-2 px-6 py-3 text-sm font-medium transition-colors ${u===`gcode`?`text-bambu-green border-b-2 border-bambu-green`:f.has_gcode?`text-bambu-gray hover:text-white`:`text-bambu-gray/30 cursor-not-allowed`}`,children:[(0,K.jsx)(Cs,{className:`w-4 h-4`}),o(`modelViewer.tabs.gcode`),!f.has_gcode&&(0,K.jsxs)(`span`,{className:`text-xs`,children:[`(`,o(`modelViewer.notSliced`),`)`]})]})]}),(0,K.jsx)(`div`,{className:`flex-1 overflow-hidden p-4`,children:m?(0,K.jsx)(`div`,{className:`w-full h-full flex items-center justify-center`,children:(0,K.jsx)(X,{className:`w-8 h-8 animate-spin text-bambu-green`})}):u===`3d`&&f?(0,K.jsxs)(`div`,{ref:N,className:`w-full h-full flex flex-col ${R?`gap-0 min-h-0`:`gap-3`}`,children:[L&&(0,K.jsxs)(`div`,{ref:P,style:R&&D!=null?{height:D}:void 0,className:`rounded-lg border border-bambu-dark-tertiary bg-bambu-dark p-3 ${R?`flex flex-col shrink-0`:``}`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-bambu-gray mb-2`,children:[(0,K.jsx)(Ic,{className:`w-4 h-4`}),o(`modelViewer.plates`),v&&(0,K.jsx)(X,{className:`w-3 h-3 animate-spin`})]}),(0,K.jsxs)(`div`,{className:R?`flex flex-col min-h-0 flex-1`:void 0,children:[(0,K.jsx)(`div`,{ref:ie,className:R?`min-h-0 overflow-hidden pr-1 flex-1`:void 0,children:(0,K.jsxs)(`div`,{ref:re,className:R?`grid gap-2`:`grid grid-cols-2 md:grid-cols-3 gap-2`,style:R?{gridTemplateColumns:`repeat(${oe}, minmax(0, 1fr))`}:void 0,children:[(0,K.jsxs)(`button`,{type:`button`,onClick:()=>S(null),className:`flex items-center rounded-lg border text-left transition-colors ${R?`gap-1.5 p-1.5 w-full`:`gap-2 p-2`} ${x==null?`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary bg-bambu-dark-secondary hover:border-bambu-gray`}`,children:[(0,K.jsx)(`div`,{className:`rounded bg-bambu-dark-tertiary flex items-center justify-center ${R?`w-8 h-8`:`w-10 h-10`}`,children:(0,K.jsx)(Ic,{className:`${R?`w-4 h-4`:`w-5 h-5`} text-bambu-gray`})}),(0,K.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,K.jsx)(`p`,{className:`${R?`text-xs`:`text-sm`} text-white font-medium truncate`,children:o(`modelViewer.allPlates`)}),(0,K.jsx)(`p`,{className:`${R?`text-[10px]`:`text-xs`} text-bambu-gray truncate`,children:o(`modelViewer.plateCount`,{count:I.length})})]}),x==null&&(0,K.jsx)(ts,{className:`${R?`w-3.5 h-3.5`:`w-4 h-4`} text-bambu-green flex-shrink-0`})]}),le.map(e=>(0,K.jsxs)(`button`,{type:`button`,onClick:()=>S(e.index),className:`flex items-center rounded-lg border text-left transition-colors ${R?`gap-1.5 p-1.5 w-full`:`gap-2 p-2`} ${x===e.index?`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary bg-bambu-dark-secondary hover:border-bambu-gray`}`,children:[e.has_thumbnail&&e.thumbnail_url?(0,K.jsx)(`img`,{src:e.thumbnail_url,alt:`Plate ${e.index}`,className:`${R?`w-8 h-8`:`w-10 h-10`} rounded object-cover bg-bambu-dark-tertiary`}):(0,K.jsx)(`div`,{className:`rounded bg-bambu-dark-tertiary flex items-center justify-center ${R?`w-8 h-8`:`w-10 h-10`}`,children:(0,K.jsx)(Ic,{className:`${R?`w-4 h-4`:`w-5 h-5`} text-bambu-gray`})}),(0,K.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,K.jsx)(`p`,{className:`${R?`text-xs`:`text-sm`} text-white font-medium truncate`,children:e.name||o(`modelViewer.plateNumber`,{number:e.index})}),(0,K.jsx)(`p`,{className:`${R?`text-[10px]`:`text-xs`} text-bambu-gray truncate`,children:o(`modelViewer.objectCount`,{count:e.object_count??e.objects?.length??0})})]}),x===e.index&&(0,K.jsx)(ts,{className:`${R?`w-3.5 h-3.5`:`w-4 h-4`} text-bambu-green flex-shrink-0`})]},e.index))]})}),(z||se)&&(0,K.jsxs)(`div`,{className:`mt-auto pt-3 flex items-center gap-4 text-xs text-bambu-gray overflow-x-auto`,children:[z&&(0,K.jsxs)(`div`,{className:`flex items-center gap-3 whitespace-nowrap`,children:[(0,K.jsx)(`span`,{children:o(`modelViewer.plateNumber`,{number:z.index})}),z.print_time_seconds!=null&&(0,K.jsx)(`span`,{children:o(`modelViewer.eta`,{minutes:Math.round(z.print_time_seconds/60)})}),z.filament_used_grams!=null&&(0,K.jsxs)(`span`,{children:[z.filament_used_grams.toFixed(1),` g`]}),z.filaments.length>0&&(0,K.jsx)(`span`,{children:o(`modelViewer.filamentCount`,{count:z.filaments.length})})]}),se&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2 whitespace-nowrap ${z?`ml-auto`:``}`,children:[(0,K.jsx)(`span`,{children:o(`modelViewer.pagination.pageOf`,{current:C+1,total:ce})}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(`button`,{type:`button`,onClick:()=>w(e=>Math.max(e-1,0)),disabled:C===0,className:`px-2 py-1 rounded border text-xs ${C===0?`border-bambu-dark-tertiary text-bambu-gray/40 cursor-not-allowed`:`border-bambu-dark-tertiary text-bambu-gray hover:text-white hover:border-bambu-gray`}`,children:o(`modelViewer.pagination.prev`)}),(()=>{let e=Math.max(0,C-2),t=Math.min(ce,e+5);t-e<5&&(e=Math.max(0,t-5));let n=Array.from({length:t-e},(t,n)=>e+n);return(0,K.jsxs)(K.Fragment,{children:[e>0&&(0,K.jsx)(`button`,{type:`button`,onClick:()=>w(0),className:`px-2 py-1 rounded border text-xs ${C===0?`border-bambu-green text-bambu-green`:`border-bambu-dark-tertiary text-bambu-gray hover:text-white hover:border-bambu-gray`}`,children:`1`}),e>1&&(0,K.jsx)(`span`,{className:`px-1`,children:`…`}),n.map(e=>(0,K.jsx)(`button`,{type:`button`,onClick:()=>w(e),className:`px-2 py-1 rounded border text-xs ${C===e?`border-bambu-green text-bambu-green`:`border-bambu-dark-tertiary text-bambu-gray hover:text-white hover:border-bambu-gray`}`,children:e+1},e)),tw(ce-1),className:`px-2 py-1 rounded border text-xs ${C===ce-1?`border-bambu-green text-bambu-green`:`border-bambu-dark-tertiary text-bambu-gray hover:text-white hover:border-bambu-gray`}`,children:ce})]})})(),(0,K.jsx)(`button`,{type:`button`,onClick:()=>w(e=>Math.min(e+1,ce-1)),disabled:C>=ce-1,className:`px-2 py-1 rounded border text-xs ${C>=ce-1?`border-bambu-dark-tertiary text-bambu-gray/40 cursor-not-allowed`:`border-bambu-dark-tertiary text-bambu-gray hover:text-white hover:border-bambu-gray`}`,children:o(`modelViewer.pagination.next`)})]})]})]})]})]}),R&&(0,K.jsx)(`div`,{role:`separator`,"aria-orientation":`horizontal`,onMouseDown:e=>{e.preventDefault(),A(!0),M(!0)},className:`h-2 cursor-row-resize flex items-center justify-center ${k?`bg-bambu-dark-tertiary`:`bg-bambu-dark-secondary/60 hover:bg-bambu-dark-tertiary`}`,children:(0,K.jsx)(`div`,{className:`w-12 h-1 rounded-full bg-bambu-gray/50`})}),(0,K.jsx)(`div`,{className:`flex-1 ${R?`min-h-0`:``}`,children:(0,K.jsx)(gy,{url:l?Q.getLibraryFileDownloadUrl(t):f.has_source?Q.getSource3mfDownloadUrl(e):Q.getArchiveDownload(e),fileType:r,buildVolume:f.build_volume,filamentColors:f.filament_colors,selectedPlateId:x,className:`w-full h-full`})})]}):u===`gcode`&&f?(0,K.jsx)(dT,{gcodeUrl:l?Q.getLibraryFileGcodeUrl(t):Q.getArchiveGcode(e),filamentColors:f.filament_colors,className:`w-full h-full`}):(0,K.jsx)(`div`,{className:`w-full h-full flex items-center justify-center text-bambu-gray`,children:o(`modelViewer.noPreview`)})})]})})}var B6=[`library-tags`];function dWe({open:e,fileIds:t,onClose:n}){let{t:r}=W(),i=to(),{showToast:a}=kd(),[o,s]=(0,y.useState)(`add`),[c,l]=(0,y.useState)(new Set),[u,d]=(0,y.useState)(``),[f,p]=(0,y.useState)(``);(0,y.useEffect)(()=>{e||(s(`add`),l(new Set),d(``),p(``))},[e]);let{data:m=[],isLoading:h}=q({queryKey:B6,queryFn:Q.getLibraryTags,enabled:e}),g=(0,y.useMemo)(()=>{let e=u.trim().toLowerCase();return e?m.filter(t=>t.name.toLowerCase().includes(e)):m},[m,u]),_=e=>{l(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},v=J({mutationFn:e=>Q.createLibraryTag(e),onSuccess:e=>{l(t=>new Set(t).add(e.id)),p(``),i.invalidateQueries({queryKey:B6})},onError:e=>{a(e.message||r(`fileManager.tags.saveFailed`),`error`)}}),b=J({mutationFn:()=>Q.bulkAssignLibraryTags(t,Array.from(c),o),onSuccess:e=>{a(o===`add`?r(`fileManager.tags.applyAddSuccess`,{count:e.associations_added,files:e.files_updated}):r(`fileManager.tags.applyRemoveSuccess`,{count:e.associations_removed,files:e.files_updated}),`success`),i.invalidateQueries({queryKey:[`library-files`]}),i.invalidateQueries({queryKey:B6}),n()},onError:e=>{a(e.message||r(`fileManager.tags.applyFailed`),`error`)}});if((0,y.useEffect)(()=>{if(!e)return;let t=e=>{e.key===`Escape`&&!b.isPending&&!v.isPending&&n()};return document.addEventListener(`keydown`,t),()=>document.removeEventListener(`keydown`,t)},[e,n,b.isPending,v.isPending]),!e)return null;let x=!f.trim()||v.isPending||m.some(e=>e.name.toLowerCase()===f.trim().toLowerCase()),S=`bulk-tags-picker-title`;return(0,K.jsxs)(`div`,{className:`fixed inset-0 z-[60] flex items-center justify-center`,children:[(0,K.jsx)(`div`,{className:`absolute inset-0 bg-black/60`,onClick:()=>!b.isPending&&n()}),(0,K.jsxs)(`div`,{className:`relative w-full max-w-md mx-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl shadow-2xl max-h-[90vh] flex flex-col`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":S,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between gap-4 px-5 py-4 border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`h3`,{id:S,className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(pu,{className:`w-4 h-4 text-bambu-green`}),r(`fileManager.tags.bulkTitle`,{count:t.length})]}),(0,K.jsx)(`button`,{type:`button`,className:`p-1.5 text-bambu-gray hover:text-white rounded`,onClick:n,"aria-label":r(`common.close`),children:(0,K.jsx)(Hu,{className:`w-5 h-5`})})]}),(0,K.jsxs)(`div`,{className:`px-5 py-3 border-b border-bambu-dark-tertiary flex gap-4 text-sm`,children:[(0,K.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`radio`,name:`bulk-action`,checked:o===`add`,onChange:()=>s(`add`),className:`accent-bambu-green`}),(0,K.jsx)(`span`,{className:`text-white`,children:r(`fileManager.tags.actionAdd`)})]}),(0,K.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`radio`,name:`bulk-action`,checked:o===`remove`,onChange:()=>s(`remove`),className:`accent-bambu-green`}),(0,K.jsx)(`span`,{className:`text-white`,children:r(`fileManager.tags.actionRemove`)})]})]}),(0,K.jsx)(`div`,{className:`px-5 py-3 border-b border-bambu-dark-tertiary`,children:(0,K.jsx)(`input`,{type:`text`,value:u,onChange:e=>d(e.target.value),placeholder:r(`fileManager.tags.searchPlaceholder`),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`})}),(0,K.jsx)(`div`,{className:`overflow-y-auto flex-1 min-h-[8rem] max-h-[24rem]`,children:h?(0,K.jsxs)(`div`,{className:`flex items-center justify-center py-12 text-bambu-gray`,children:[(0,K.jsx)(X,{className:`w-5 h-5 animate-spin mr-2`}),r(`common.loading`)]}):g.length===0?(0,K.jsx)(`div`,{className:`py-12 text-center text-bambu-gray text-sm`,children:m.length===0?r(`fileManager.tags.empty`):r(`fileManager.tags.noMatches`)}):(0,K.jsx)(`ul`,{className:`divide-y divide-bambu-dark-tertiary/40`,children:g.map(e=>(0,K.jsx)(`li`,{children:(0,K.jsxs)(`label`,{className:`flex items-center gap-3 px-5 py-2 hover:bg-bambu-dark-tertiary/30 cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:c.has(e.id),onChange:()=>_(e.id),className:`accent-bambu-green`}),(0,K.jsx)(`span`,{className:`text-sm text-white truncate flex-1`,children:e.name}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:e.file_count})]})},e.id))})}),o===`add`&&(0,K.jsxs)(`div`,{className:`px-5 py-3 border-t border-bambu-dark-tertiary flex gap-2`,children:[(0,K.jsx)(`input`,{type:`text`,value:f,onChange:e=>p(e.target.value),placeholder:r(`fileManager.tags.createPlaceholder`),maxLength:64,className:`flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,onKeyDown:e=>{e.key===`Enter`&&!x&&(e.preventDefault(),v.mutate(f.trim()))}}),(0,K.jsxs)($,{type:`button`,variant:`secondary`,onClick:()=>v.mutate(f.trim()),disabled:x,children:[v.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(Cl,{className:`w-4 h-4`}),r(`fileManager.tags.createButton`)]})]}),(0,K.jsxs)(`div`,{className:`px-5 py-4 border-t border-bambu-dark-tertiary flex justify-end gap-2`,children:[(0,K.jsx)($,{type:`button`,variant:`secondary`,onClick:n,disabled:b.isPending,children:r(`common.cancel`)}),(0,K.jsxs)($,{type:`button`,onClick:()=>b.mutate(),disabled:c.size===0||b.isPending||t.length===0,children:[b.isPending&&(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),r(o===`add`?`fileManager.tags.applyAdd`:`fileManager.tags.applyRemove`)]})]})]})]})}function fWe(e,t){let n=t||{};return(e[e.length-1]===``?[...e,``]:e).join((n.padRight?` `:``)+`,`+(n.padLeft===!1?``:` `)).trim()}var pWe=/^[$_\p{ID_Start}][$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,mWe=/^[$_\p{ID_Start}][-$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,hWe={};function V6(e,t){return((t||hWe).jsx?mWe:pWe).test(e)}var gWe=/[ \t\n\f\r]/g;function _We(e){return typeof e==`object`?e.type===`text`?H6(e.value):!1:H6(e)}function H6(e){return e.replace(gWe,``)===``}var U6=class{constructor(e,t,n){this.normal=t,this.property=e,n&&(this.space=n)}};U6.prototype.normal={},U6.prototype.property={},U6.prototype.space=void 0;function W6(e,t){let n={},r={};for(let t of e)Object.assign(n,t.property),Object.assign(r,t.normal);return new U6(n,r,t)}function G6(e){return e.toLowerCase()}var K6=class{constructor(e,t){this.attribute=t,this.property=e}};K6.prototype.attribute=``,K6.prototype.booleanish=!1,K6.prototype.boolean=!1,K6.prototype.commaOrSpaceSeparated=!1,K6.prototype.commaSeparated=!1,K6.prototype.defined=!1,K6.prototype.mustUseProperty=!1,K6.prototype.number=!1,K6.prototype.overloadedBoolean=!1,K6.prototype.property=``,K6.prototype.spaceSeparated=!1,K6.prototype.space=void 0;var q6=s({boolean:()=>J6,booleanish:()=>Y6,commaOrSpaceSeparated:()=>e8,commaSeparated:()=>$6,number:()=>Z6,overloadedBoolean:()=>X6,spaceSeparated:()=>Q6}),vWe=0,J6=t8(),Y6=t8(),X6=t8(),Z6=t8(),Q6=t8(),$6=t8(),e8=t8();function t8(){return 2**++vWe}var n8=Object.keys(q6),r8=class extends K6{constructor(e,t,n,r){let i=-1;if(super(e,t),i8(this,`space`,r),typeof n==`number`)for(;++i4&&n.slice(0,4)===`data`&&CWe.test(t)){if(t.charAt(4)===`-`){let e=t.slice(5).replace(f8,EWe);r=`data`+e.charAt(0).toUpperCase()+e.slice(1)}else{let e=t.slice(4);if(!f8.test(e)){let n=e.replace(SWe,TWe);n.charAt(0)!==`-`&&(n=`-`+n),t=`data`+n}}i=r8}return new i(r,t)}function TWe(e){return`-`+e.toLowerCase()}function EWe(e){return e.charAt(1).toUpperCase()}var DWe=W6([o8,yWe,l8,u8,d8],`html`),p8=W6([o8,bWe,l8,u8,d8],`svg`);function OWe(e){return e.join(` `).trim()}var kWe=o(((e,t)=>{var n=/\/\*[^*]*\*+([^/*][^*]*\*+)*\//g,r=/\n/g,i=/^\s*/,a=/^(\*?[-#/*\\\w]+(\[[0-9a-z_-]+\])?)\s*/,o=/^:\s*/,s=/^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^)]*?\)|[^};])+)/,c=/^[;\s]*/,l=/^\s+|\s+$/g,u=` +`+n+`}`}return String(e)}function GUe({setting:e,onClose:t,onDeleted:n,onDuplicate:r,onEdit:i,hasPermission:a,t:o}){let{showToast:s}=kd(),c=to(),[l,u]=(0,y.useState)(!1),{data:d,isLoading:f}=q({queryKey:[`cloudSettingDetail`,e.setting_id],queryFn:()=>Q.getCloudSettingDetail(e.setting_id)}),p=J({mutationFn:()=>Q.deleteCloudSetting(e.setting_id),onSuccess:()=>{s(o(`profiles.presets.toast.deleted`)),c.invalidateQueries({queryKey:[`cloudSettings`]}),n()},onError:e=>s(e.message,`error`)}),m=T6(e.setting_id),h=w6(e.name,d?.setting?.inherits);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)(xd,{className:`w-full max-w-3xl max-h-[90vh] flex flex-col overflow-hidden`,children:(0,K.jsxs)(Cd,{className:`p-0 flex flex-col min-h-0 flex-1`,children:[(0,K.jsxs)(`div`,{className:`flex-shrink-0 flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`h2`,{className:`text-xl font-semibold text-white truncate`,children:e.name}),m&&(0,K.jsx)(`span`,{className:`px-2 py-0.5 text-xs font-medium bg-bambu-green/20 text-bambu-green rounded-full`,children:o(`profiles.presets.editable`)})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mt-1 text-sm text-bambu-gray`,children:[(0,K.jsx)(`span`,{className:`capitalize`,children:o(`profiles.presets.types.${e.type}`)}),h.printer&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`span`,{children:`•`}),(0,K.jsx)(`span`,{children:h.printer})]})]})]}),(0,K.jsx)(`button`,{onClick:t,className:`p-2 text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary rounded-lg transition-colors`,children:(0,K.jsx)(Hu,{className:`w-5 h-5`})})]}),(0,K.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-4`,children:f?(0,K.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,K.jsx)(X,{className:`w-8 h-8 text-bambu-green animate-spin`})}):d?(0,K.jsx)(`pre`,{className:`text-xs text-bambu-gray font-mono whitespace-pre-wrap break-all bg-bambu-dark p-4 rounded-lg border border-bambu-dark-tertiary overflow-x-auto max-w-full`,children:O6(d)}):(0,K.jsx)(`div`,{className:`text-center py-16 text-bambu-gray`,children:o(`profiles.presets.failedToLoadDetails`)})}),l?(0,K.jsxs)(`div`,{className:`flex-shrink-0 p-4 border-t border-bambu-dark-tertiary bg-red-500/5`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-3 text-red-700 dark:text-red-400`,children:[(0,K.jsx)(wu,{className:`w-5 h-5`}),(0,K.jsx)(`span`,{className:`font-medium`,children:o(`profiles.presets.deleteConfirm`)})]}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4`,children:o(`profiles.presets.deleteWarning`,{name:e.name})}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:()=>u(!1),disabled:p.isPending,className:`flex-1`,children:o(`common.cancel`)}),(0,K.jsxs)($,{variant:`danger`,onClick:()=>p.mutate(),disabled:p.isPending,className:`flex-1`,children:[p.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(xu,{className:`w-4 h-4`}),o(`common.delete`)]})]})]}):(0,K.jsx)(`div`,{className:`flex-shrink-0 p-4 border-t border-bambu-dark-tertiary`,children:(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:t,className:`flex-1`,children:o(`common.close`)}),(0,K.jsxs)($,{variant:`secondary`,onClick:r,disabled:!a(`cloud:auth`),title:a(`cloud:auth`)?void 0:o(`profiles.presets.noDuplicatePermission`),children:[(0,K.jsx)(As,{className:`w-4 h-4`}),o(`profiles.presets.duplicate`)]}),m&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)($,{variant:`secondary`,onClick:i,disabled:f||!d||!a(`cloud:auth`),title:a(`cloud:auth`)?void 0:o(`profiles.presets.noEditPermission`),children:[(0,K.jsx)(yl,{className:`w-4 h-4`}),o(`common.edit`)]}),(0,K.jsx)($,{variant:`danger`,onClick:()=>u(!0),disabled:!a(`cloud:auth`),title:a(`cloud:auth`)?void 0:o(`profiles.presets.noDeletePermission`),children:(0,K.jsx)(xu,{className:`w-4 h-4`})})]})]})})]})})})}function k6(){try{let e=localStorage.getItem(`bambusy_preset_templates`);return e?JSON.parse(e):[]}catch{return[]}}function A6(e){localStorage.setItem(`bambusy_preset_templates`,JSON.stringify(e))}function KUe({onClose:e,onApply:t,t:n}){let{showToast:r}=kd(),[i,a]=(0,y.useState)(k6),[o,s]=(0,y.useState)(`all`),[c,l]=(0,y.useState)(null),[u,d]=(0,y.useState)(``),[f,p]=(0,y.useState)(``),[m,h]=(0,y.useState)(`{}`),[g,_]=(0,y.useState)(null),[v,b]=(0,y.useState)(null),x=o===`all`?i:i.filter(e=>e.type===o),S=e=>{a(e),A6(e)},C=e=>{S(i.filter(t=>t.id!==e)),b(null),r(n(`profiles.templates.toast.deleted`))},w=e=>{l(e.id),d(e.name),p(e.description),h(JSON.stringify(e.settings,null,2)),_(null)},T=()=>{if(!(!c||!u.trim()))try{let e=JSON.parse(m);S(i.map(t=>t.id===c?{...t,name:u.trim(),description:f.trim(),settings:e}:t)),l(null),r(n(`profiles.templates.toast.updated`))}catch(e){_(e.message)}},E=()=>{l(null),d(``),p(``),h(`{}`),_(null)},D=e=>{S(i.map(t=>t.id===e?{...t,showInModal:!t.showInModal}:t))},O={filament:{label:n(`profiles.presets.types.filament`),icon:Bs,color:`text-amber-600 dark:text-amber-400`},print:{label:n(`profiles.presets.types.process`),icon:Ul,color:`text-blue-600 dark:text-blue-400`},printer:{label:n(`profiles.presets.types.printer`),icon:El,color:`text-purple-600 dark:text-purple-400`}},k=v?i.find(e=>e.id===v):null;return(0,y.useEffect)(()=>{let t=t=>{t.key===`Escape`&&(v?b(null):c?E():e())};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[v,c,e]),(0,K.jsxs)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:[k&&(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-60`,children:(0,K.jsx)(xd,{className:`w-full max-w-md`,children:(0,K.jsxs)(Cd,{className:`p-6`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3 mb-4`,children:[(0,K.jsx)(`div`,{className:`p-2 bg-red-500/20 rounded-lg`,children:(0,K.jsx)(wu,{className:`w-6 h-6 text-red-600 dark:text-red-400`})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h3`,{className:`text-lg font-semibold text-white`,children:n(`profiles.templates.deleteTitle`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`profiles.templates.deleteWarning`)})]})]}),(0,K.jsx)(`p`,{className:`text-white mb-6`,children:n(`profiles.templates.deleteConfirm`,{name:k.name})}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:()=>b(null),className:`flex-1`,children:n(`common.cancel`)}),(0,K.jsxs)($,{onClick:()=>C(v),className:`flex-1 bg-red-500 hover:bg-red-600`,children:[(0,K.jsx)(xu,{className:`w-4 h-4`}),n(`common.delete`)]})]})]})})}),(0,K.jsx)(xd,{className:`w-full max-w-2xl max-h-[80vh] flex flex-col`,children:(0,K.jsxs)(Cd,{className:`p-0 flex flex-col h-full`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(iu,{className:`w-5 h-5 text-amber-600 dark:text-amber-400`}),n(`profiles.templates.title`)]}),(0,K.jsx)(`button`,{onClick:e,className:`text-bambu-gray hover:text-white`,children:(0,K.jsx)(Hu,{className:`w-5 h-5`})})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 p-4 border-b border-bambu-dark-tertiary`,children:[(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:n(`profiles.templates.typeFilter`)}),[`all`,`filament`,`print`,`printer`].map(e=>(0,K.jsx)(`button`,{onClick:()=>s(e),className:`px-3 py-1 text-sm rounded-lg transition-colors ${o===e?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white`}`,children:e===`all`?n(`common.all`):O[e].label},e))]}),(0,K.jsx)(`div`,{className:`flex-1 overflow-y-auto p-4`,children:x.length===0?(0,K.jsxs)(`div`,{className:`text-center py-12 text-bambu-gray`,children:[(0,K.jsx)(iu,{className:`w-12 h-12 mx-auto mb-4 opacity-30`}),(0,K.jsx)(`p`,{children:n(`profiles.templates.noTemplates`)}),(0,K.jsx)(`p`,{className:`text-sm mt-1`,children:n(`profiles.templates.createFirst`)})]}):(0,K.jsx)(`div`,{className:`space-y-2`,children:x.map(e=>{let r=O[e.type],i=r.icon;return c===e.id?(0,K.jsxs)(`div`,{className:`p-4 bg-bambu-dark rounded-lg border border-bambu-green`,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-3 mb-3`,children:[(0,K.jsx)(`input`,{type:`text`,value:u,onChange:e=>d(e.target.value),placeholder:n(`profiles.templates.namePlaceholder`),className:`px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`,autoFocus:!0}),(0,K.jsx)(`input`,{type:`text`,value:f,onChange:e=>p(e.target.value),placeholder:n(`profiles.templates.descriptionPlaceholder`),className:`px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`})]}),(0,K.jsxs)(`div`,{className:`mb-3`,children:[(0,K.jsx)(`label`,{className:`text-xs text-bambu-gray mb-1 block`,children:n(`profiles.templates.settingsJson`)}),(0,K.jsx)(`textarea`,{value:m,onChange:e=>{h(e.target.value),_(null)},rows:6,className:`w-full px-3 py-2 bg-bambu-dark-secondary border rounded text-white text-sm font-mono focus:outline-none ${g?`border-red-500`:`border-bambu-dark-tertiary focus:border-bambu-green`}`}),g&&(0,K.jsx)(`p`,{className:`text-xs text-red-700 dark:text-red-400 mt-1`,children:g})]}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsxs)($,{size:`sm`,onClick:T,disabled:!u.trim(),children:[(0,K.jsx)(Pl,{className:`w-4 h-4`}),`Save`]}),(0,K.jsx)($,{size:`sm`,variant:`secondary`,onClick:E,children:`Cancel`})]})]},e.id):(0,K.jsxs)(`div`,{className:`flex items-center gap-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary hover:border-bambu-gray-dark transition-colors`,children:[(0,K.jsx)(i,{className:`w-5 h-5 ${r.color} flex-shrink-0`}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsx)(`p`,{className:`text-sm font-medium text-white`,children:e.name}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray truncate`,children:e.description})]}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray-dark px-2 py-1 bg-bambu-dark-secondary rounded`,children:n(`profiles.templates.fieldsCount`,{count:Object.keys(e.settings).length})}),(0,K.jsx)(`button`,{onClick:()=>D(e.id),className:`p-1 transition-colors ${e.showInModal?`text-bambu-green hover:text-bambu-green/70`:`text-bambu-gray hover:text-white`}`,title:e.showInModal?n(`profiles.templates.shownInModals`):n(`profiles.templates.hiddenInModals`),children:e.showInModal?(0,K.jsx)(Js,{className:`w-4 h-4`}):(0,K.jsx)(qs,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>t(e),className:`px-3 py-1 text-xs bg-bambu-green/20 text-bambu-green rounded hover:bg-bambu-green/30 transition-colors`,children:n(`profiles.templates.apply`)}),(0,K.jsx)(`button`,{onClick:()=>w(e),className:`p-1 text-bambu-gray hover:text-white`,title:n(`common.edit`),children:(0,K.jsx)(yl,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>b(e.id),className:`p-1 text-bambu-gray hover:text-red-600 dark:hover:text-red-400`,title:n(`common.delete`),children:(0,K.jsx)(xu,{className:`w-4 h-4`})})]},e.id)})})})]})})]})}function j6({onClose:e,leftPreset:t,rightPreset:n,leftLabel:r,rightLabel:i,t:a}){let[o,s]=(0,y.useState)(`changes`),[c,l]=(0,y.useState)(``),u=(0,y.useMemo)(()=>{let e=new Set([...Object.keys(t),...Object.keys(n)]),r=[];for(let i of e){if(i===`inherits`||i===`version`)continue;let e=t[i],a=n[i],o=i in t,s=i in n,c;c=!o&&s?`added`:o&&!s?`removed`:JSON.stringify(e)===JSON.stringify(a)?`same`:`changed`,r.push({key:i,left:e,right:a,status:c})}return r.sort((e,t)=>{let n={changed:0,added:1,removed:2,same:3};return n[e.status]===n[t.status]?e.key.localeCompare(t.key):n[e.status]-n[t.status]})},[t,n]),d=(0,y.useMemo)(()=>{let e=[...u];if(o===`changes`&&(e=e.filter(e=>e.status!==`same`)),c){let t=c.toLowerCase();e=e.filter(e=>e.key.toLowerCase().includes(t)||String(e.left).toLowerCase().includes(t)||String(e.right).toLowerCase().includes(t))}return e},[u,o,c]),f=(0,y.useMemo)(()=>({added:u.filter(e=>e.status===`added`).length,removed:u.filter(e=>e.status===`removed`).length,changed:u.filter(e=>e.status===`changed`).length,same:u.filter(e=>e.status===`same`).length}),[u]),p=e=>{if(e===void 0)return`—`;if(e===null)return`null`;if(Array.isArray(e))return e.length===0?`[]`:e.length===1?String(e[0]):e.join(`, `);if(typeof e==`object`)return JSON.stringify(e);let t=String(e);if(t.includes(`\\n`)||t.length>100){let e=t.split(`\\n`).length;if(e>1)return`[${e} lines of G-code/script]`;if(t.length>100)return t.substring(0,100)+`…`}return t};return(0,y.useEffect)(()=>{let t=t=>{t.key===`Escape`&&e()};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e]),(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,K.jsx)(xd,{className:`w-full max-w-4xl max-h-[85vh] flex flex-col overflow-hidden`,children:(0,K.jsxs)(Cd,{className:`p-0 flex flex-col min-h-0 flex-1`,children:[(0,K.jsxs)(`div`,{className:`flex-shrink-0 flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(gc,{className:`w-5 h-5 text-blue-600 dark:text-blue-400`}),a(`profiles.diff.title`)]}),(0,K.jsx)(`button`,{onClick:e,className:`text-bambu-gray hover:text-white`,children:(0,K.jsx)(Hu,{className:`w-5 h-5`})})]}),(0,K.jsxs)(`div`,{className:`flex-shrink-0 grid grid-cols-2 gap-4 p-4 border-b border-bambu-dark-tertiary bg-bambu-dark`,children:[(0,K.jsxs)(`div`,{className:`text-center`,children:[(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:a(`profiles.diff.left`)}),(0,K.jsx)(`p`,{className:`text-white font-medium truncate`,children:r})]}),(0,K.jsxs)(`div`,{className:`text-center`,children:[(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:a(`profiles.diff.right`)}),(0,K.jsx)(`p`,{className:`text-white font-medium truncate`,children:i})]})]}),(0,K.jsxs)(`div`,{className:`flex-shrink-0 flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-4 text-sm`,children:[(0,K.jsxs)(`span`,{className:`flex items-center gap-1 text-green-700 dark:text-green-400`,children:[(0,K.jsx)(Cl,{className:`w-3.5 h-3.5`}),f.added,` `,a(`profiles.diff.added`)]}),(0,K.jsxs)(`span`,{className:`flex items-center gap-1 text-red-700 dark:text-red-400`,children:[(0,K.jsx)(rl,{className:`w-3.5 h-3.5`}),f.removed,` `,a(`profiles.diff.removed`)]}),(0,K.jsxs)(`span`,{className:`flex items-center gap-1 text-amber-700 dark:text-amber-400`,children:[(0,K.jsx)(Mo,{className:`w-3.5 h-3.5`}),f.changed,` `,a(`profiles.diff.changed`)]}),(0,K.jsxs)(`span`,{className:`flex items-center gap-1 text-bambu-gray`,children:[(0,K.jsx)(Ws,{className:`w-3.5 h-3.5`}),f.same,` `,a(`profiles.diff.same`)]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(zl,{className:`absolute left-2 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,K.jsx)(`input`,{type:`text`,value:c,onChange:e=>l(e.target.value),placeholder:a(`profiles.diff.searchFields`),className:`pl-8 pr-3 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none w-48`})]}),f.same>0&&(0,K.jsxs)(`div`,{className:`flex rounded overflow-hidden border border-bambu-dark-tertiary`,children:[(0,K.jsx)(`button`,{onClick:()=>s(`changes`),className:`px-3 py-1.5 text-sm transition-colors ${o===`changes`?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white`}`,children:a(`profiles.diff.changes`)}),(0,K.jsx)(`button`,{onClick:()=>s(`all`),className:`px-3 py-1.5 text-sm transition-colors ${o===`all`?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white`}`,children:a(`common.all`)})]})]})]}),(0,K.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto`,children:d.length===0?(0,K.jsxs)(`div`,{className:`text-center py-12 text-bambu-gray`,children:[(0,K.jsx)(Ws,{className:`w-12 h-12 mx-auto mb-4 opacity-30`}),(0,K.jsx)(`p`,{children:a(o===`changes`?`profiles.diff.noDifferences`:`profiles.diff.noFieldsMatch`)})]}):(0,K.jsxs)(`table`,{className:`w-full`,children:[(0,K.jsx)(`thead`,{className:`sticky top-0 bg-bambu-dark-secondary`,children:(0,K.jsxs)(`tr`,{className:`text-sm text-bambu-gray border-b border-bambu-dark-tertiary`,children:[(0,K.jsx)(`th`,{className:`text-left p-3 w-1/3`,children:a(`profiles.diff.field`)}),(0,K.jsx)(`th`,{className:`text-left p-3 w-1/3`,children:r}),(0,K.jsx)(`th`,{className:`text-left p-3 w-1/3`,children:i})]})}),(0,K.jsx)(`tbody`,{children:d.map(e=>{let t={added:`bg-green-500/10`,removed:`bg-red-500/10`,changed:`bg-amber-500/10`,same:``}[e.status],n={added:(0,K.jsx)(Cl,{className:`w-3.5 h-3.5 text-green-600 dark:text-green-400`}),removed:(0,K.jsx)(rl,{className:`w-3.5 h-3.5 text-red-600 dark:text-red-400`}),changed:(0,K.jsx)(Mo,{className:`w-3.5 h-3.5 text-amber-600 dark:text-amber-400`}),same:(0,K.jsx)(Ws,{className:`w-3.5 h-3.5 text-bambu-gray-dark`})}[e.status];return(0,K.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary ${t}`,children:[(0,K.jsx)(`td`,{className:`p-3`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[n,(0,K.jsx)(`span`,{className:`text-sm text-white font-mono`,children:e.key})]})}),(0,K.jsx)(`td`,{className:`p-3`,children:(0,K.jsx)(`span`,{className:`text-sm font-mono break-all ${e.status===`removed`?`text-red-700 dark:text-red-300`:e.status===`changed`?`text-white`:`text-bambu-gray`}`,children:p(e.left)})}),(0,K.jsx)(`td`,{className:`p-3`,children:(0,K.jsx)(`span`,{className:`text-sm font-mono break-all ${e.status===`added`?`text-green-700 dark:text-green-300`:e.status===`changed`?`text-white`:`text-bambu-gray`}`,children:p(e.right)})})]},e.key)})})]})})]})})})}function qUe({onClose:e,initialData:t,allPresets:n,t:r}){let{showToast:i}=kd(),a=to(),o=!!t?.setting_id,[s,c]=(0,y.useState)(`common`),[l,u]=(0,y.useState)(t?.type||`filament`),[d,f]=(0,y.useState)(t?.name?o?t.name:`${t.name} (Copy)`:``),[p,m]=(0,y.useState)(t?.base_id||``),[h,g]=(0,y.useState)(``),[_,v]=(0,y.useState)(t?.setting||{inherits:``}),[b,x]=(0,y.useState)(JSON.stringify(t?.setting||{inherits:``},null,2)),[S,C]=(0,y.useState)(null),[w,T]=(0,y.useState)(``),[E,D]=(0,y.useState)(!1),[O,k]=(0,y.useState)(``),[A,j]=(0,y.useState)(!1),[M,N]=(0,y.useState)(k6),[P,F]=(0,y.useState)(!1),[I,L]=(0,y.useState)(``),[R,z]=(0,y.useState)(``),[B,V]=(0,y.useState)(!0),[ee,te]=(0,y.useState)(null),[ne,re]=(0,y.useState)(!1),ie=(0,y.useMemo)(()=>({filament:n.filament,print:n.process,printer:n.printer})[l]||[],[n,l]),H=(0,y.useMemo)(()=>ie.filter(e=>T6(e.setting_id)),[ie]),{data:ae}=q({queryKey:[`cloudFields`,l],queryFn:()=>Q.getCloudFields(l===`print`?`process`:l),staleTime:1e3*60*60}),{data:oe}=q({queryKey:[`allPresetDetails`,l,H.map(e=>e.setting_id).join(`,`)],queryFn:async()=>{let e={};for(let t=0;t{try{let t=await Q.getCloudSettingDetail(e.setting_id);return{id:e.setting_id,detail:t}}catch{return null}}))).forEach(t=>{t&&(e[t.id]=t.detail)})}return e},enabled:H.length>0,staleTime:1e3*60*10}),{data:U,isLoading:se}=q({queryKey:[`cloudSettingDetail`,p],queryFn:()=>Q.getCloudSettingDetail(p),enabled:!!p});(0,y.useEffect)(()=>{s!==`json`&&x(JSON.stringify(_,null,2))},[_,s]);let ce=(0,y.useMemo)(()=>({filament:n.filament,print:n.process,printer:n.printer}[l]||[]).filter(e=>!T6(e.setting_id)).sort((e,t)=>e.name.localeCompare(t.name)),[n,l]);(0,y.useEffect)(()=>{if(!p)return;let e=ce.find(e=>e.setting_id===p);e&&(g(e.name),o||(v({inherits:e.name}),x(JSON.stringify({inherits:e.name},null,2))))},[p,ce,o]);let le=(0,y.useMemo)(()=>{let e=ae?.fields||[],t=new Set(e.map(e=>e.key)),n=new Set,i=new Set([`inherits`,`updated_time`,`compatible_printers`,`compatible_prints`]);oe&&Object.values(oe).forEach(e=>{e?.setting&&Object.keys(e.setting).forEach(e=>{!t.has(e)&&!i.has(e)&&n.add(e)})}),Object.keys(_).forEach(e=>{!t.has(e)&&!i.has(e)&&n.add(e)});let a=Array.from(n).sort().map(e=>({key:e,label:e.replace(/_/g,` `).replace(/\b\w/g,e=>e.toUpperCase()),type:`text`,category:`discovered`,description:r(`profiles.presets.discoveredFromPresets`)}));return[...e,...a]},[ae,oe,_,r]),ue=le.filter(e=>e.label.toLowerCase().includes(w.toLowerCase())||e.key.toLowerCase().includes(w.toLowerCase())),de=()=>{if(O.trim()){let e=O.trim().toLowerCase().replace(/\s+/g,`_`);fe(e,``),k(``),j(!1),i(r(`profiles.presets.toast.fieldAdded`,{key:e}))}},fe=(e,t)=>{v(n=>{let r={...n};return t===``||t===void 0?delete r[e]:r[e]=t,r})},pe=e=>{v(t=>({...t,...e.settings})),te(e.name),i(r(`profiles.templates.toast.applied`))},me=()=>{if(!I.trim())return;let e={..._};if(delete e.inherits,Object.keys(e).length===0){i(r(`profiles.presets.noOverridesToSave`),`error`);return}let t={id:Date.now().toString(),name:I.trim(),description:R.trim()||r(`profiles.presets.customTemplate`),type:l,settings:e,showInModal:B},n=[...M,t];N(n),A6(n),F(!1),L(``),z(``),V(!0),i(r(`profiles.templates.toast.created`))},he=(0,y.useMemo)(()=>M.filter(e=>e.type===l&&e.showInModal),[l,M]),ge=e=>{x(e);try{v(JSON.parse(e)),C(null)}catch(e){C(e.message)}},_e=e=>{e.preventDefault(),D(!1);let t=e.dataTransfer.files[0];if(t&&t.name.endsWith(`.json`)){let e=new FileReader;e.onload=e=>{try{let t=e.target?.result,n=JSON.parse(t),a=n.setting||n;v(e=>({...e,...a})),x(JSON.stringify({..._,...a},null,2)),i(r(`profiles.presets.fileImported`))}catch{i(r(`profiles.presets.invalidJsonFile`),`error`)}},e.readAsText(t)}},ve=J({mutationFn:()=>{let e={..._},t=l===`filament`?`filament_settings_id`:l===`print`?`print_settings_id`:`printer_settings_id`;e[t]=`"${d}"`;let n={type:l,name:d,base_id:p,setting:e};return Q.createCloudSetting(n)},onSuccess:async()=>{i(r(`profiles.presets.toast.created`)),await a.refetchQueries({queryKey:[`cloudSettings`]}),e()},onError:e=>i(e.message,`error`)}),ye=J({mutationFn:()=>{if(!t?.setting_id)throw Error(r(`profiles.presets.noSettingId`));return Q.updateCloudSetting(t.setting_id,{name:d,setting:_})},onSuccess:async()=>{i(r(`profiles.presets.toast.updated`)),a.removeQueries({queryKey:[`cloudSettingDetail`]}),await a.refetchQueries({queryKey:[`cloudSettings`]}),e()},onError:e=>i(e.message,`error`)}),be=o?ye:ve,xe=U?.setting?.inherits,Se=xe?ce.find(e=>e.name===xe):void 0,{data:Ce}=q({queryKey:[`cloudSettingDetail`,Se?.setting_id],queryFn:()=>Q.getCloudSettingDetail(Se.setting_id),enabled:!!Se?.setting_id}),we=(0,y.useMemo)(()=>{let e=Ce?.setting||{},t=U?.setting||{},n=p&&oe?.[p]?.setting?oe[p].setting:{};return{...e,...t,...n}},[p,U,Ce,oe]),Te=e=>{if(e==null)return``;if(Array.isArray(e)){let t=[...new Set(e.map(e=>String(e)))];return t.length===1?t[0]:e.join(`, `)}return String(e)},Ee=e=>{let t=_[e.key],n=we[e.key],i=Te(n),a=se?r(`common.loading`):i||``,o=`w-full px-3 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`;if(e.type===`boolean`){let r=t===`1`||t===void 0&&n===`1`;return(0,K.jsx)(`button`,{type:`button`,onClick:()=>fe(e.key,t===`1`?`0`:`1`),className:`w-8 h-5 rounded-full transition-colors ${r?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,children:(0,K.jsx)(`div`,{className:`w-4 h-4 rounded-full bg-white shadow transition-transform ${r?`translate-x-3.5`:`translate-x-0.5`}`})})}return e.type===`select`?(0,K.jsxs)(`select`,{value:t||``,onChange:t=>fe(e.key,t.target.value),className:o,children:[(0,K.jsx)(`option`,{value:``,children:a}),e.options?.map(e=>(0,K.jsx)(`option`,{value:e.value,children:e.label},e.value))]}):(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`input`,{type:e.type===`number`?`number`:`text`,value:t===void 0?``:String(t),onChange:t=>fe(e.key,t.target.value),step:e.step,min:e.min,max:e.max,placeholder:a,className:o}),e.unit&&(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:e.unit})]})},De=(0,y.useMemo)(()=>U?.setting?U.setting:{},[U]);return(0,K.jsxs)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,onDragOver:e=>{e.preventDefault(),D(!0)},onDragLeave:()=>D(!1),onDrop:_e,children:[ne&&p&&(0,K.jsx)(j6,{onClose:()=>re(!1),leftPreset:De,rightPreset:_,leftLabel:r(`profiles.presets.baseLabel`,{name:h||p}),rightLabel:r(`profiles.presets.currentLabel`,{name:d||r(`profiles.presets.newPreset`)}),t:r}),(0,K.jsx)(xd,{className:`w-full max-w-6xl max-h-[90vh] flex flex-col overflow-y-auto`,children:(0,K.jsxs)(Cd,{className:`p-0 flex flex-col h-full`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h2`,{className:`text-xl font-semibold text-white`,children:r(o?`profiles.presets.editPreset`:t?`profiles.presets.duplicatePreset`:`profiles.presets.createNewPreset`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:r(`profiles.presets.customizeSettings`)})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[p&&(0,K.jsxs)(`button`,{onClick:()=>re(!0),className:`flex items-center gap-2 px-3 py-2 text-sm text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary rounded-lg transition-colors`,title:r(`profiles.presets.compareWithBase`),children:[(0,K.jsx)(gc,{className:`w-4 h-4`}),r(`profiles.presets.compare`)]}),(0,K.jsx)(`button`,{onClick:e,className:`p-2 text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary rounded-lg transition-colors`,children:(0,K.jsx)(Hu,{className:`w-5 h-5`})})]})]}),E&&(0,K.jsx)(`div`,{className:`absolute inset-0 bg-bambu-green/10 border-2 border-dashed border-bambu-green rounded-lg flex items-center justify-center z-10`,children:(0,K.jsxs)(`div`,{className:`text-center`,children:[(0,K.jsx)(Ou,{className:`w-12 h-12 text-bambu-green mx-auto mb-2`}),(0,K.jsx)(`p`,{className:`text-bambu-green font-medium`,children:r(`profiles.presets.dropJsonToImport`)})]})}),(0,K.jsxs)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary space-y-3`,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-3 gap-4 max-[640px]:grid-cols-1`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`common.type`)}),(0,K.jsxs)(`select`,{value:l,onChange:e=>{u(e.target.value),m(``)},className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,K.jsx)(`option`,{value:`filament`,children:r(`profiles.presets.types.filament`)}),(0,K.jsx)(`option`,{value:`print`,children:r(`profiles.presets.types.process`)}),(0,K.jsx)(`option`,{value:`printer`,children:r(`profiles.presets.types.printer`)})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`profiles.presets.basePreset`)}),(0,K.jsxs)(`select`,{value:p,onChange:e=>m(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,children:[(0,K.jsx)(`option`,{value:``,children:r(`profiles.presets.selectBasePreset`)}),ce.map(e=>(0,K.jsx)(`option`,{value:e.setting_id,children:e.name},e.setting_id))]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`profiles.presets.presetName`)}),(0,K.jsx)(`input`,{type:`text`,value:d,onChange:e=>f(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,placeholder:r(`profiles.presets.myCustomPreset`)})]})]}),h&&(0,K.jsx)(`div`,{className:`text-xs text-bambu-gray`,children:(0,K.jsxs)(`p`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(ts,{className:`w-3 h-3 text-bambu-green`}),r(`profiles.presets.inheritsFrom`),` `,(0,K.jsx)(`span`,{className:`text-white`,children:h}),se&&(0,K.jsx)(X,{className:`w-3 h-3 animate-spin ml-1`})]})})]}),(0,K.jsxs)(`div`,{className:`flex border-b border-bambu-dark-tertiary max-[640px]:flex-wrap max-[640px]:items-center`,children:[(0,K.jsxs)(`button`,{onClick:()=>c(`common`),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${s===`common`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-white border-transparent`}`,children:[(0,K.jsx)(eu,{className:`w-4 h-4`}),r(`profiles.presets.tabs.common`)]}),(0,K.jsxs)(`button`,{onClick:()=>c(`fields`),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${s===`fields`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-white border-transparent`}`,children:[(0,K.jsx)(Uc,{className:`w-4 h-4`}),r(`profiles.presets.tabs.allFields`)]}),(0,K.jsxs)(`button`,{onClick:()=>c(`json`),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${s===`json`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-white border-transparent`}`,children:[(0,K.jsx)(ws,{className:`w-4 h-4`}),`JSON`,S&&(0,K.jsx)(ls,{className:`w-3 h-3 text-red-600 dark:text-red-400`})]}),(0,K.jsx)(`div`,{className:`flex-1 max-[640px]:hidden`}),(0,K.jsxs)(`button`,{onClick:()=>{let e=new Blob([JSON.stringify({name:d,type:l,base_id:p,setting:_},null,2)],{type:`application/json`}),t=URL.createObjectURL(e),n=document.createElement(`a`);n.href=t,n.download=`${d||`preset`}.json`,document.body.appendChild(n),n.click(),document.body.removeChild(n),URL.revokeObjectURL(t),i(r(`profiles.presets.toast.exported`))},className:`flex items-center gap-2 px-4 py-3 text-sm text-bambu-gray hover:text-white transition-colors`,title:r(`profiles.presets.exportToJson`),children:[(0,K.jsx)(zs,{className:`w-4 h-4`}),r(`common.download`)]}),(0,K.jsxs)(`button`,{onClick:()=>document.getElementById(`file-import`)?.click(),className:`flex items-center gap-2 px-4 py-3 text-sm text-bambu-gray hover:text-white transition-colors`,title:r(`profiles.presets.importFromJson`),children:[(0,K.jsx)(Ou,{className:`w-4 h-4`}),r(`common.upload`)]}),(0,K.jsx)(`input`,{id:`file-import`,type:`file`,accept:`.json`,className:`hidden`,onChange:e=>{let t=e.target.files?.[0];if(t){let e=new FileReader;e.onload=e=>{try{let t=JSON.parse(e.target?.result),n=t.setting||t;v(e=>({...e,...n})),i(r(`profiles.presets.fileImported`))}catch{i(r(`profiles.presets.invalidJson`),`error`)}},e.readAsText(t)}}})]}),(0,K.jsxs)(`div`,{className:`flex-1 p-4`,children:[s===`common`&&(0,K.jsxs)(`div`,{className:`space-y-6`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,K.jsxs)(`h3`,{className:`text-sm font-medium text-white flex items-center gap-2`,children:[(0,K.jsx)(iu,{className:`w-4 h-4 text-amber-600 dark:text-amber-400`}),r(`profiles.templates.title`)]}),Object.keys(_).filter(e=>e!==`inherits`).length>0&&(0,K.jsxs)(`button`,{onClick:()=>F(!P),className:`text-xs text-bambu-gray hover:text-white flex items-center gap-1 transition-colors`,children:[(0,K.jsx)(Pl,{className:`w-3 h-3`}),r(`profiles.presets.saveAsTemplate`)]})]}),P&&(0,K.jsxs)(`div`,{className:`mb-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-2 mb-2`,children:[(0,K.jsx)(`input`,{type:`text`,value:I,onChange:e=>L(e.target.value),placeholder:r(`profiles.templates.namePlaceholder`),className:`px-3 py-1.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`,autoFocus:!0}),(0,K.jsx)(`input`,{type:`text`,value:R,onChange:e=>z(e.target.value),placeholder:r(`profiles.templates.descriptionPlaceholder`),className:`px-3 py-1.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsxs)($,{size:`sm`,onClick:me,disabled:!I.trim(),children:[(0,K.jsx)(Pl,{className:`w-3 h-3`}),r(`common.save`)]}),(0,K.jsx)($,{size:`sm`,variant:`secondary`,onClick:()=>F(!1),children:r(`common.cancel`)})]}),(0,K.jsxs)(`button`,{onClick:()=>V(!B),className:`flex items-center gap-1.5 text-xs transition-colors ${B?`text-bambu-green`:`text-bambu-gray hover:text-white`}`,children:[B?(0,K.jsx)(Js,{className:`w-3.5 h-3.5`}):(0,K.jsx)(qs,{className:`w-3.5 h-3.5`}),r(B?`profiles.templates.shownInModals`:`profiles.templates.hiddenInModals`)]})]})]}),ee&&(0,K.jsxs)(`div`,{className:`mb-3 px-3 py-2 bg-bambu-green/10 border border-bambu-green/30 rounded-lg flex items-center gap-2`,children:[(0,K.jsx)(ts,{className:`w-4 h-4 text-bambu-green`}),(0,K.jsxs)(`span`,{className:`text-sm text-bambu-green`,children:[r(`profiles.presets.templateApplied`),` `,(0,K.jsx)(`span`,{className:`font-medium`,children:ee})]}),(0,K.jsx)(`button`,{onClick:()=>te(null),className:`ml-auto text-bambu-green/70 hover:text-bambu-green`,children:(0,K.jsx)(Hu,{className:`w-4 h-4`})})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-3 gap-2`,children:[he.map(e=>(0,K.jsxs)(`button`,{onClick:()=>pe(e),className:`p-3 text-left bg-bambu-dark border border-bambu-dark-tertiary rounded-lg hover:border-bambu-gray-dark transition-colors`,children:[(0,K.jsx)(`p`,{className:`text-sm font-medium text-white`,children:e.name}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e.description})]},e.id)),he.length===0&&(0,K.jsx)(`p`,{className:`col-span-3 text-center text-bambu-gray text-sm py-4`,children:r(`profiles.presets.noTemplatesSelected`)})]}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray-dark mt-2 text-center`,children:r(`profiles.presets.manageTemplatesHint`)})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h3`,{className:`text-sm font-medium text-white mb-3`,children:r(`profiles.presets.commonSettings`)}),(0,K.jsx)(`div`,{className:`grid grid-cols-2 gap-x-6 gap-y-3`,children:le.slice(0,10).map(e=>(0,K.jsxs)(`div`,{className:`flex items-center justify-between gap-4 max-[640px]:flex-col max-[640px]:items-start`,children:[(0,K.jsx)(`label`,{className:`text-sm text-bambu-gray flex-shrink-0`,children:e.label}),(0,K.jsx)(`div`,{className:`w-48 max-[640px]:w-full`,children:Ee(e)})]},e.key))})]}),Object.keys(_).length>1&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h3`,{className:`text-sm font-medium text-white mb-3`,children:r(`profiles.presets.currentOverrides`)}),(0,K.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:Object.entries(_).filter(([e])=>e!==`inherits`).map(([e,t])=>(0,K.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-2 py-1 bg-bambu-green/10 text-bambu-green text-xs rounded`,children:[e,`: `,String(t).slice(0,20),(0,K.jsx)(`button`,{onClick:()=>fe(e,void 0),className:`hover:text-white`,children:(0,K.jsx)(Hu,{className:`w-3 h-3`})})]},e))})]})]}),s===`fields`&&(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-6`,style:{height:`400px`},children:[(0,K.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-3 flex-shrink-0`,children:[(0,K.jsx)(`h3`,{className:`text-sm font-medium text-white`,children:r(`profiles.presets.availableFields`)}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:oe?r(`profiles.templates.fieldsCount`,{count:le.length}):r(`common.loading`)})]}),(0,K.jsxs)(`div`,{className:`relative mb-3 flex-shrink-0`,children:[(0,K.jsx)(zl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,K.jsx)(`input`,{type:`text`,value:w,onChange:e=>T(e.target.value),placeholder:r(`profiles.presets.searchFieldsPlaceholder`),className:`w-full pl-10 pr-4 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none`})]}),(0,K.jsxs)(`div`,{className:`flex-1 overflow-y-auto space-y-1 pr-2 min-h-0`,children:[ue.filter(e=>!(e.key in _)).map(e=>{let t=we[e.key],n=Te(t);return(0,K.jsxs)(`div`,{onClick:()=>{v(t=>({...t,[e.key]:n||``}))},className:`flex items-center justify-between gap-2 p-2 rounded-lg hover:bg-bambu-dark-tertiary transition-colors cursor-pointer group`,children:[(0,K.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,K.jsx)(`p`,{className:`text-sm text-white truncate`,children:e.label}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray-dark truncate`,children:e.key})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[n&&(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray bg-bambu-dark px-2 py-0.5 rounded max-w-32 truncate`,title:n,children:[n.slice(0,20),n.length>20?`...`:``]}),(0,K.jsx)(`div`,{className:`w-6 h-6 flex items-center justify-center rounded bg-bambu-dark-tertiary group-hover:bg-bambu-green/20 transition-colors`,children:(0,K.jsx)(Cl,{className:`w-4 h-4 text-bambu-gray group-hover:text-bambu-green transition-colors`})})]})]},e.key)}),ue.filter(e=>!(e.key in _)).length===0&&(0,K.jsx)(`p`,{className:`text-center text-bambu-gray py-4 text-sm`,children:r(w?`profiles.presets.noMatchingFields`:`profiles.presets.allFieldsAdded`)})]}),(0,K.jsx)(`div`,{className:`pt-3 mt-3 border-t border-bambu-dark-tertiary flex-shrink-0`,children:A?(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)(`input`,{type:`text`,value:O,onChange:e=>k(e.target.value),onKeyDown:e=>e.key===`Enter`&&de(),placeholder:`custom_field_name`,className:`flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white font-mono text-sm placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none`,autoFocus:!0}),(0,K.jsx)($,{size:`sm`,onClick:de,disabled:!O.trim(),children:(0,K.jsx)(Cl,{className:`w-4 h-4`})}),(0,K.jsx)($,{size:`sm`,variant:`secondary`,onClick:()=>{j(!1),k(``)},children:(0,K.jsx)(Hu,{className:`w-4 h-4`})})]}):(0,K.jsxs)(`button`,{onClick:()=>j(!0),className:`w-full flex items-center justify-center gap-2 p-2 text-sm text-bambu-gray hover:text-white border border-dashed border-bambu-dark-tertiary hover:border-bambu-gray-dark rounded-lg transition-colors`,children:[(0,K.jsx)(Cl,{className:`w-4 h-4`}),r(`profiles.presets.addCustomField`)]})})]}),(0,K.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-3 flex-shrink-0`,children:[(0,K.jsx)(`h3`,{className:`text-sm font-medium text-white`,children:r(`profiles.presets.yourOverrides`)}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:r(`profiles.templates.fieldsCount`,{count:Object.keys(_).filter(e=>e!==`inherits`).length})})]}),(0,K.jsxs)(`div`,{className:`flex-1 overflow-y-auto space-y-2 pr-2 min-h-0`,children:[Object.entries(_).filter(([e])=>e!==`inherits`).map(([e,t])=>{let n=le.find(t=>t.key===e);return(0,K.jsxs)(`div`,{className:`p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm font-medium text-white`,children:n?.label||e}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray-dark`,children:e})]}),(0,K.jsx)(`button`,{onClick:()=>fe(e,void 0),className:`p-1 text-bambu-gray hover:text-red-600 dark:hover:text-red-400 transition-colors`,children:(0,K.jsx)(Hu,{className:`w-4 h-4`})})]}),n?Ee(n):(0,K.jsx)(`input`,{type:`text`,value:String(t),onChange:t=>fe(e,t.target.value),className:`w-full px-3 py-1.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`})]},e)}),Object.keys(_).filter(e=>e!==`inherits`).length===0&&(0,K.jsxs)(`div`,{className:`text-center py-8 text-bambu-gray`,children:[(0,K.jsx)(eu,{className:`w-8 h-8 mx-auto mb-2 opacity-50`}),(0,K.jsx)(`p`,{className:`text-sm`,children:r(`profiles.presets.noOverridesYet`)}),(0,K.jsx)(`p`,{className:`text-xs mt-1`,children:r(`profiles.presets.clickFieldsToAdd`)})]})]}),Object.keys(_).filter(e=>e!==`inherits`).length>0&&(0,K.jsx)(`div`,{className:`pt-3 mt-3 border-t border-bambu-dark-tertiary flex-shrink-0`,children:(0,K.jsxs)(`button`,{onClick:()=>{F(!0),c(`common`)},className:`w-full flex items-center justify-center gap-2 p-2 text-sm text-bambu-gray hover:text-white border border-dashed border-bambu-dark-tertiary hover:border-bambu-gray-dark rounded-lg transition-colors`,children:[(0,K.jsx)(Pl,{className:`w-4 h-4`}),r(`profiles.presets.saveAsTemplate`)]})})]})]}),s===`json`&&(0,K.jsxs)(`div`,{className:`space-y-2`,children:[S&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-red-700 dark:text-red-400 text-sm`,children:[(0,K.jsx)(ls,{className:`w-4 h-4`}),S]}),(0,K.jsx)(`textarea`,{value:b,onChange:e=>ge(e.target.value),className:`w-full h-80 px-3 py-2 bg-bambu-dark border rounded-lg text-white text-xs font-mono focus:outline-none resize-none ${S?`border-red-500 focus:border-red-500`:`border-bambu-dark-tertiary focus:border-bambu-green`}`,spellCheck:!1}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:r(`profiles.presets.jsonTip`)})]})]}),(0,K.jsxs)(`div`,{className:`p-4 border-t border-bambu-dark-tertiary flex gap-2`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:e,className:`flex-1`,children:r(`common.cancel`)}),(0,K.jsxs)($,{onClick:()=>be.mutate(),disabled:be.isPending||!d.trim()||!o&&!p||!!S,className:`flex-1`,children:[be.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):o?(0,K.jsx)(Pl,{className:`w-4 h-4`}):(0,K.jsx)(Cl,{className:`w-4 h-4`}),r(o?`common.save`:t?`common.duplicate`:`common.create`)]})]})]})})]})}function JUe({settings:e,lastSyncTime:t,onRefresh:n,isRefreshing:r,printers:i,hasPermission:a,t:o}){let[s,c]=(0,y.useState)(``),[l,u]=(0,y.useState)(`all`),[d,f]=(0,y.useState)(`all`),[p,m]=(0,y.useState)(`all`),[h,g]=(0,y.useState)(`all`),[_,v]=(0,y.useState)(`all`),[b,x]=(0,y.useState)(`all`),[S,C]=(0,y.useState)(null),[w,T]=(0,y.useState)(!1),[E,D]=(0,y.useState)(!1),[O,k]=(0,y.useState)(null),[A,j]=(0,y.useState)(null),[M,N]=(0,y.useState)(null),[P,F]=(0,y.useState)(!1),[I,L]=(0,y.useState)([null,null]),[R,z]=(0,y.useState)(!1),[B,V]=(0,y.useState)(null),ee=to(),te=(0,y.useMemo)(()=>[...e.filament.map(e=>({...e,type:`filament`})),...e.printer.map(e=>({...e,type:`printer`})),...e.process.map(e=>({...e,type:`process`}))].map(e=>({...e,meta:w6(e.name)})),[e]),ne=(0,y.useMemo)(()=>{let e=new Set,t=new Set,n=new Set;return te.forEach(r=>{r.meta.nozzle&&e.add(r.meta.nozzle),r.meta.filamentType&&t.add(r.meta.filamentType),r.meta.layerHeight&&n.add(r.meta.layerHeight)}),{printers:i.map(e=>({id:e.id.toString(),name:e.name})),nozzles:Array.from(e).sort((e,t)=>parseFloat(e)-parseFloat(t)),filaments:Array.from(t).sort(),layerHeights:Array.from(n).sort((e,t)=>parseFloat(e)-parseFloat(t))}},[te,i]),re=(0,y.useMemo)(()=>p===`all`?null:i.find(e=>e.id.toString()===p)?.model||null,[p,i]),ie=(0,y.useMemo)(()=>te.filter(e=>l===`all`||e.type===l).filter(e=>{if(d===`all`)return!0;let t=T6(e.setting_id);return d===`custom`?t:!t}).filter(e=>{if(p===`all`||!re)return!0;let t=e.meta.printer?.toLowerCase()||``,n=re.toLowerCase();return t.includes(n)||n.includes(t)}).filter(e=>h===`all`||e.meta.nozzle===h).filter(e=>_===`all`||e.meta.filamentType===_).filter(e=>b===`all`||e.meta.layerHeight===b).filter(e=>s===``||e.name.toLowerCase().includes(s.toLowerCase())).sort((e,t)=>e.name.localeCompare(t.name)),[te,l,d,p,re,h,_,b,s]),H=e=>{if(P){let t=I[0]?.setting_id===e.setting_id,n=I[1]?.setting_id===e.setting_id;if(t)L([I[1],null]);else if(n)L([I[0],null]);else if(!I[0])L([e,null]);else if(I[1]){if(I[0].type!==e.type)return;L([I[0],e])}else{if(I[0].type!==e.type)return;L([I[0],e])}}else C(e)},ae=e=>{if(I[0]?.setting_id===e.setting_id)return 0;if(I[1]?.setting_id===e.setting_id)return 1},oe=async e=>{try{let t=await Q.getCloudSettingDetail(e.setting_id);k({type:e.type===`process`?`print`:e.type,name:e.name,base_id:t.base_id||`GFSA00`,setting:t.setting||{}}),C(null)}catch(e){console.error(`Failed to fetch preset details for duplication:`,e)}},U=async e=>{try{ee.removeQueries({queryKey:[`cloudSettingDetail`,e.setting_id]});let t=await Q.getCloudSettingDetail(e.setting_id);j({type:e.type===`process`?`print`:e.type,name:e.name,base_id:t.base_id||`GFSA00`,setting:t.setting||{},setting_id:e.setting_id}),C(null)}catch(e){console.error(`Failed to fetch preset details for editing:`,e)}},se=()=>{u(`all`),f(`all`),m(`all`),g(`all`),v(`all`),x(`all`),c(``)},ce=l!==`all`||d!==`all`||p!==`all`||h!==`all`||_!==`all`||b!==`all`||s!==``,le=e.filament.length+e.printer.length+e.process.length;return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`space-y-4 mb-6`,children:[(0,K.jsxs)(`div`,{className:`flex flex-col sm:flex-row gap-3`,children:[(0,K.jsxs)(`div`,{className:`relative flex-1`,children:[(0,K.jsx)(zl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,K.jsx)(`input`,{type:`text`,value:s,onChange:e=>c(e.target.value),placeholder:o(`profiles.cloudView.searchPlaceholder`),className:`w-full pl-10 pr-4 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none`})]}),(0,K.jsxs)(`div`,{className:`flex gap-2 max-[550px]:flex-wrap max-[550px]:items-center`,children:[(0,K.jsxs)($,{variant:P?`primary`:`secondary`,onClick:()=>{P?(F(!1),L([null,null])):F(!0)},children:[(0,K.jsx)(gc,{className:`w-4 h-4`}),o(P?`common.cancel`:`profiles.presets.compare`)]}),(0,K.jsxs)($,{variant:`secondary`,onClick:()=>D(!0),disabled:!a(`cloud:auth`),title:a(`cloud:auth`)?void 0:o(`profiles.cloudView.noTemplatesPermission`),children:[(0,K.jsx)(iu,{className:`w-4 h-4`}),o(`profiles.cloudView.templates`)]}),(0,K.jsxs)($,{variant:`secondary`,onClick:n,disabled:r||!a(`cloud:auth`),title:a(`cloud:auth`)?void 0:o(`profiles.cloudView.noRefreshPermission`),children:[(0,K.jsx)(kl,{className:`w-4 h-4 ${r?`animate-spin`:``}`}),o(`profiles.cloudView.refresh`)]}),(0,K.jsxs)($,{onClick:()=>T(!0),disabled:!a(`cloud:auth`),title:a(`cloud:auth`)?void 0:o(`profiles.cloudView.noCreatePermission`),children:[(0,K.jsx)(Cl,{className:`w-4 h-4`}),o(`profiles.cloudView.newPreset`)]})]})]}),(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,K.jsx)(fc,{className:`w-4 h-4 text-bambu-gray`}),(0,K.jsx)(E6,{label:o(`profiles.cloudView.filters.type`),value:l,options:[{value:`all`,label:o(`profiles.cloudView.filters.all`),count:le},{value:`filament`,label:o(`profiles.cloudView.filters.filament`),count:e.filament.length},{value:`printer`,label:o(`profiles.cloudView.filters.printer`),count:e.printer.length},{value:`process`,label:o(`profiles.cloudView.filters.process`),count:e.process.length}],onChange:e=>u(e)}),(0,K.jsx)(E6,{label:o(`profiles.cloudView.filters.owner`),value:d,options:[{value:`all`,label:o(`profiles.cloudView.filters.all`)},{value:`custom`,label:o(`profiles.cloudView.filters.myPresets`)},{value:`builtin`,label:o(`profiles.cloudView.filters.builtIn`)}],onChange:e=>f(e)}),ne.printers.length>0&&(0,K.jsx)(E6,{label:o(`profiles.cloudView.filters.printer`),value:p,options:[{value:`all`,label:o(`profiles.cloudView.filters.all`)},...ne.printers.map(e=>({value:e.id,label:e.name}))],onChange:m}),ne.nozzles.length>0&&(0,K.jsx)(E6,{label:o(`profiles.cloudView.filters.nozzle`),value:h,options:[{value:`all`,label:o(`profiles.cloudView.filters.all`)},...ne.nozzles.map(e=>({value:e,label:e}))],onChange:g}),ne.filaments.length>0&&(l===`all`||l===`filament`)&&(0,K.jsx)(E6,{label:o(`profiles.cloudView.filters.filament`),value:_,options:[{value:`all`,label:o(`profiles.cloudView.filters.all`)},...ne.filaments.map(e=>({value:e,label:e}))],onChange:v}),ne.layerHeights.length>0&&(l===`all`||l===`process`)&&(0,K.jsx)(E6,{label:o(`profiles.cloudView.filters.layer`),value:b,options:[{value:`all`,label:o(`profiles.cloudView.filters.all`)},...ne.layerHeights.map(e=>({value:e,label:e}))],onChange:x}),ce&&(0,K.jsx)(`button`,{onClick:se,className:`px-3 py-2 text-sm text-bambu-gray hover:text-white transition-colors`,children:o(`profiles.cloudView.clearFilters`)})]})]}),P&&(0,K.jsx)(`div`,{className:`mb-4 p-3 bg-blue-500/10 border border-blue-500/30 rounded-lg`,children:(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,K.jsx)(gc,{className:`w-5 h-5 text-blue-600 dark:text-blue-400`}),(0,K.jsx)(`span`,{className:`text-white font-medium`,children:o(`profiles.cloudView.compareMode`)}),(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:I[0]?o(`profiles.cloudView.selectAnotherPreset`,{type:I[0].type}):o(`profiles.cloudView.clickTwoPresets`)})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`px-2 py-1 text-sm rounded truncate max-w-[200px] ${I[0]?`bg-blue-500/30 text-blue-700 dark:text-blue-300`:`bg-bambu-dark text-bambu-gray`}`,children:I[0]?I[0].name:o(`profiles.cloudView.selectFirst`)}),(0,K.jsx)(Mo,{className:`w-4 h-4 text-bambu-gray`}),(0,K.jsx)(`span`,{className:`px-2 py-1 text-sm rounded truncate max-w-[200px] ${I[1]?`bg-blue-500/30 text-blue-700 dark:text-blue-300`:`bg-bambu-dark text-bambu-gray`}`,children:I[1]?I[1].name:o(`profiles.cloudView.selectSecond`)})]}),I[0]&&I[1]&&(0,K.jsxs)($,{size:`sm`,onClick:async()=>{try{let[e,t]=await Promise.all([Q.getCloudSettingDetail(I[0].setting_id),Q.getCloudSettingDetail(I[1].setting_id)]);V([e.setting||{},t.setting||{}]),z(!0)}catch{}},children:[(0,K.jsx)(gc,{className:`w-4 h-4`}),o(`profiles.cloudView.compareNow`)]})]})]})}),(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4 mb-4 text-sm text-bambu-gray`,children:[t&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(bs,{className:`w-3 h-3`}),o(`profiles.cloudView.lastSynced`),` `,jf(t.toISOString(),`system`,o)]}),(0,K.jsx)(`span`,{children:o(`profiles.cloudView.showingCount`,{showing:ie.length,total:le})}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-bambu-green`}),(0,K.jsxs)(`span`,{children:[`= `,o(`profiles.presets.myPreset`)]})]})]}),ie.length===0?(0,K.jsxs)(`div`,{className:`text-center py-16`,children:[(0,K.jsx)(Ic,{className:`w-12 h-12 text-bambu-gray-dark mx-auto mb-4`}),(0,K.jsx)(`p`,{className:`text-bambu-gray`,children:o(`profiles.cloudView.noPresetsFound`)}),ce&&(0,K.jsx)(`button`,{onClick:se,className:`mt-2 text-sm text-bambu-green hover:text-bambu-green-light`,children:o(`profiles.cloudView.clearFilters`)})]}):(0,K.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-6`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-3 px-1`,children:[(0,K.jsx)(Bs,{className:`w-4 h-4 text-amber-600 dark:text-amber-400`}),(0,K.jsx)(`h3`,{className:`text-sm font-medium text-bambu-gray`,children:o(`profiles.cloudView.columns.filament`)}),(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray-dark`,children:[`(`,ie.filter(e=>e.type===`filament`).length,`)`]})]}),(0,K.jsxs)(`div`,{className:`space-y-1 max-h-[calc(100vh-320px)] overflow-y-auto pr-1`,children:[ie.filter(e=>e.type===`filament`).map(e=>(0,K.jsx)(D6,{setting:e,onClick:()=>H(e),onDuplicate:()=>oe(e),compareMode:P,isCompareSelected:ae(e)!==void 0,compareIndex:ae(e),compareDisabled:P&&!!I[0]&&I[0].type!==e.type,t:o},e.setting_id)),ie.filter(e=>e.type===`filament`).length===0&&(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray-dark px-3 py-2`,children:o(`profiles.cloudView.noFilamentPresets`)})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-3 px-1`,children:[(0,K.jsx)(Ul,{className:`w-4 h-4 text-blue-600 dark:text-blue-400`}),(0,K.jsx)(`h3`,{className:`text-sm font-medium text-bambu-gray`,children:o(`profiles.cloudView.columns.process`)}),(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray-dark`,children:[`(`,ie.filter(e=>e.type===`process`).length,`)`]})]}),(0,K.jsxs)(`div`,{className:`space-y-1 max-h-[calc(100vh-320px)] overflow-y-auto pr-1`,children:[ie.filter(e=>e.type===`process`).map(e=>(0,K.jsx)(D6,{setting:e,onClick:()=>H(e),onDuplicate:()=>oe(e),compareMode:P,isCompareSelected:ae(e)!==void 0,compareIndex:ae(e),compareDisabled:P&&!!I[0]&&I[0].type!==e.type,t:o},e.setting_id)),ie.filter(e=>e.type===`process`).length===0&&(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray-dark px-3 py-2`,children:o(`profiles.cloudView.noProcessPresets`)})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mb-3 px-1`,children:[(0,K.jsx)(El,{className:`w-4 h-4 text-purple-600 dark:text-purple-400`}),(0,K.jsx)(`h3`,{className:`text-sm font-medium text-bambu-gray`,children:o(`profiles.cloudView.columns.printer`)}),(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray-dark`,children:[`(`,ie.filter(e=>e.type===`printer`).length,`)`]})]}),(0,K.jsxs)(`div`,{className:`space-y-1 max-h-[calc(100vh-320px)] overflow-y-auto pr-1`,children:[ie.filter(e=>e.type===`printer`).map(e=>(0,K.jsx)(D6,{setting:e,onClick:()=>H(e),onDuplicate:()=>oe(e),compareMode:P,isCompareSelected:ae(e)!==void 0,compareIndex:ae(e),compareDisabled:P&&!!I[0]&&I[0].type!==e.type,t:o},e.setting_id)),ie.filter(e=>e.type===`printer`).length===0&&(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray-dark px-3 py-2`,children:o(`profiles.cloudView.noPrinterPresets`)})]})]})]}),S&&(0,K.jsx)(GUe,{setting:S,onClose:()=>C(null),onDeleted:()=>C(null),onDuplicate:()=>oe(S),onEdit:()=>U(S),hasPermission:a,t:o}),(w||O||A||M)&&(0,K.jsx)(qUe,{onClose:()=>{T(!1),k(null),j(null),N(null)},initialData:A||O||(M?{type:M.type,name:``,base_id:``,setting:M.setting}:void 0),allPresets:e,t:o}),E&&(0,K.jsx)(KUe,{onClose:()=>D(!1),onApply:e=>{N({type:e.type,setting:e.settings}),D(!1)},t:o}),R&&B&&I[0]&&I[1]&&(0,K.jsx)(j6,{onClose:()=>{z(!1),V(null)},leftPreset:B[0],rightPreset:B[1],leftLabel:I[0].name,rightLabel:I[1].name,t:o})]})}function YUe(){let{t:e}=W(),t=to(),{showToast:n}=kd(),{hasPermission:r}=hd(),[i,a]=(0,y.useState)(`cloud`),[o,s]=(0,y.useState)(),{data:c,isLoading:l}=q({queryKey:[`cloudStatus`],queryFn:Q.getCloudStatus}),{data:u=[]}=q({queryKey:[`printers`],queryFn:Q.getPrinters}),{data:d,isLoading:f,refetch:p,dataUpdatedAt:m}=q({queryKey:[`cloudSettings`],queryFn:()=>Q.getCloudSettings(),enabled:!!c?.is_authenticated,retry:!1,staleTime:1e3*60*5});(0,y.useEffect)(()=>{m&&s(new Date(m))},[m]);let h=J({mutationFn:Q.cloudLogout,onSuccess:()=>{t.invalidateQueries({queryKey:[`cloudStatus`]}),t.removeQueries({queryKey:[`cloudSettings`]}),n(e(`profiles.toast.loggedOut`))}});return l?(0,K.jsx)(`div`,{className:`p-4 md:p-8 flex items-center justify-center min-h-[400px]`,children:(0,K.jsx)(X,{className:`w-8 h-8 text-bambu-green animate-spin`})}):(0,K.jsxs)(`div`,{className:`p-4 md:p-8`,children:[(0,K.jsxs)(`div`,{className:`mb-6`,children:[(0,K.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,K.jsx)(Ss,{className:`w-7 h-7 text-bambu-green`}),e(`profiles.title`)]}),(0,K.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:e(`profiles.subtitle`)})]}),(0,K.jsxs)(`div`,{className:`flex border-b border-bambu-dark-tertiary mb-6`,children:[(0,K.jsxs)(`button`,{onClick:()=>a(`cloud`),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${i===`cloud`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-white border-transparent`}`,children:[(0,K.jsx)(Ss,{className:`w-4 h-4`}),e(`profiles.tabs.bambuCloud`)]}),(0,K.jsxs)(`button`,{onClick:()=>a(`orca_cloud`),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${i===`orca_cloud`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-white border-transparent`}`,children:[(0,K.jsx)(Ss,{className:`w-4 h-4`}),e(`profiles.tabs.orcaCloud`)]}),(0,K.jsxs)(`button`,{onClick:()=>a(`local`),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${i===`local`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-white border-transparent`}`,children:[(0,K.jsx)(Sc,{className:`w-4 h-4`}),e(`profiles.tabs.local`)]}),(0,K.jsxs)(`button`,{onClick:()=>a(`kprofiles`),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${i===`kprofiles`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-white border-transparent`}`,children:[(0,K.jsx)(pc,{className:`w-4 h-4`}),e(`profiles.tabs.kprofiles`)]})]}),i===`cloud`&&(0,K.jsxs)(K.Fragment,{children:[c?.is_authenticated&&(0,K.jsxs)(`div`,{className:`flex items-center justify-between p-3 mb-6 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`w-2 h-2 rounded-full bg-bambu-green animate-pulse`}),(0,K.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[e(`profiles.connectedAs`),` `,(0,K.jsx)(`span`,{className:`text-white`,children:c.email}),c.region&&(0,K.jsx)(`span`,{className:`ml-2 px-2 py-0.5 text-xs rounded bg-bambu-dark-tertiary text-bambu-gray`,children:c.region===`china`?e(`profiles.login.regionChina`):e(`profiles.login.regionGlobal`)})]})]}),(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:()=>h.mutate(),disabled:h.isPending||!r(`cloud:auth`),title:r(`cloud:auth`)?void 0:e(`profiles.noLogoutPermission`),children:[(0,K.jsx)(qc,{className:`w-4 h-4`}),e(`profiles.logout`)]})]}),c?.is_authenticated?f?(0,K.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,K.jsx)(X,{className:`w-8 h-8 text-bambu-green animate-spin`})}):d?(0,K.jsx)(JUe,{settings:d,lastSyncTime:o,onRefresh:()=>p(),isRefreshing:f,printers:u,hasPermission:r,t:e}):(0,K.jsxs)(`div`,{className:`text-center py-16`,children:[(0,K.jsx)(`p`,{className:`text-bambu-gray mb-4`,children:e(`profiles.failedToLoad`)}),(0,K.jsx)($,{onClick:()=>p(),children:e(`profiles.retry`)})]}):(0,K.jsx)(UUe,{onSuccess:()=>{t.invalidateQueries({queryKey:[`cloudStatus`]})},t:e})]}),i===`orca_cloud`&&(0,K.jsx)(RUe,{}),i===`local`&&(0,K.jsx)(NUe,{}),i===`kprofiles`&&(0,K.jsx)(kUe,{}),(0,K.jsx)(WUe,{})]})}function XUe(e,t){let n=(t||``).toUpperCase().replace(/[- ]/g,``),r=n.includes(`X1`),i=n.includes(`P1`),a=n.includes(`A1MINI`),o=n.includes(`A1`)&&!a,s=n.includes(`H2D`),c=n.includes(`H2C`),l=n.includes(`H2S`),u=s||c||l,d=n.includes(`P2S`),f=n.includes(`X2D`),p=d||f;switch(e){case`Lubricate Steel Rods`:return p?`https://wiki.bambulab.com/en/p2s/maintenance/lubricate-x-y-z-axis`:null;case`Clean Steel Rods`:return p?`https://wiki.bambulab.com/en/p2s/maintenance/lubricate-x-y-z-axis`:null;case`Lubricate Linear Rails`:return a?`https://wiki.bambulab.com/en/a1-mini/maintenance/lubricate-y-axis`:o?`https://wiki.bambulab.com/en/a1/maintenance/lubricate-y-axis`:u?`https://wiki.bambulab.com/en/h2/maintenance/x-axis-lubrication`:null;case`Clean Nozzle/Hotend`:return r||i?`https://wiki.bambulab.com/en/x1/troubleshooting/nozzle-clog`:a||o?`https://wiki.bambulab.com/en/a1-mini/troubleshooting/nozzle-clog`:u?`https://wiki.bambulab.com/en/h2/maintenance/nozzl-cold-pull-maintenance-and-cleaning`:p?`https://wiki.bambulab.com/en/p2s/maintenance/cold-pull-maintenance-hotend`:`https://wiki.bambulab.com/en/x1/troubleshooting/nozzle-clog`;case`Check Belt Tension`:return r?`https://wiki.bambulab.com/en/x1/maintenance/belt-tension`:i?`https://wiki.bambulab.com/en/p1/maintenance/p1p-maintenance`:a?`https://wiki.bambulab.com/en/a1-mini/maintenance/belt_tension`:o?`https://wiki.bambulab.com/en/a1/maintenance/belt_tension`:s?`https://wiki.bambulab.com/en/h2/maintenance/belt-tension`:c?`https://wiki.bambulab.com/en/h2c/maintenance/belt-tension`:l?`https://wiki.bambulab.com/en/h2s/maintenance/belt-tension`:p?`https://wiki.bambulab.com/en/p2s/maintenance/belt-tension`:`https://wiki.bambulab.com/en/x1/maintenance/belt-tension`;case`Clean Carbon Rods`:return r||i?`https://wiki.bambulab.com/en/general/carbon-rods-clearance`:null;case`Clean Linear Rails`:return a?`https://wiki.bambulab.com/en/a1-mini/maintenance/lubricate-y-axis`:o?`https://wiki.bambulab.com/en/a1/maintenance/lubricate-y-axis`:u?`https://wiki.bambulab.com/en/h2/maintenance/x-axis-lubrication`:null;case`Clean Build Plate`:return`https://wiki.bambulab.com/en/filament-acc/acc/pei-plate-clean-guide`;case`Check PTFE Tube`:return r||i?`https://wiki.bambulab.com/en/x1/maintenance/replace-ptfe-tube`:a||o?`https://wiki.bambulab.com/en/a1-mini/maintenance/ptfe-tube`:s?`https://wiki.bambulab.com/en/h2/maintenance/replace-ptfe-tube-on-h2d-printer`:l?`https://wiki.bambulab.com/en/h2s/maintenance/replace-ptfe-tube-on-h2s-printer`:c?`https://wiki.bambulab.com/en/h2/maintenance/replace-ptfe-tube-on-h2d-printer`:`https://wiki.bambulab.com/en/x1/maintenance/replace-ptfe-tube`;case`Replace HEPA Filter`:case`HEPA Filter`:case`Replace Carbon Filter`:case`Carbon Filter`:return u?`https://wiki.bambulab.com/en/h2/maintenance/replace-smoke-purifier-air-filte`:`https://wiki.bambulab.com/en/x1/maintenance/replace-carbon-filter`;case`Lubricate Left Nozzle Rail`:case`Left Nozzle Rail`:return u?`https://wiki.bambulab.com/en/h2/maintenance/x-axis-lubrication`:null;default:return null}}var M6={Droplet:Bs,Flame:rc,Ruler:Nl,Sparkles:iu,Square:su,Cable:Ko,Wrench:Vu,Calendar:Yo,Timer:bu,Cog:Ds,Fan:Ys,Zap:Wu,Wind:zu,Thermometer:yu,Layers:Ic,Box:Uo,Target:mu,RefreshCw:kl,Settings:Wl,Filter:fc,CircleDot:ps};function N6(e){return e&&M6[e]||Vu}function P6(e,t,n){if(t===`days`){if(e<1)return n?n(`common.today`):`Today`;if(e===1)return n?n(`maintenance.day`):`1 day`;if(e<7){let t=Math.round(e);return n?n(`maintenance.days`,{count:t}):`${t} days`}if(e<180){let t=Math.round(e/7);return t===1?n?n(`maintenance.week`):`1 week`:n?n(`maintenance.weeks`,{count:t}):`${t} weeks`}let t=Math.round(e/30);return t===1?n?n(`maintenance.month`):`1 month`:n?n(`maintenance.months`,{count:t}):`${t} months`}else{if(e<1)return`${Math.round(e*60)}m`;if(e<24)return`${e<10?e.toFixed(1):Math.round(e)}h`;let t=e/24;if(t<7)return`${t<2?t.toFixed(1):Math.round(t)}d`;let n=t/7;return n<12?`${n<2?n.toFixed(1):Math.round(n)}w`:`${Math.round(n/4)}mo`}}function F6(e,t,n){return t===`days`?e===1?n?n(`maintenance.day`):`1 day`:e===7?n?n(`maintenance.week`):`1 week`:e===14?n?n(`maintenance.weeks`,{count:2}):`2 weeks`:e===30?n?n(`maintenance.month`):`1 month`:e===60?n?n(`maintenance.months`,{count:2}):`2 months`:e===90?n?n(`maintenance.months`,{count:3}):`3 months`:e===180?n?n(`maintenance.months`,{count:6}):`6 months`:e===365?n?n(`maintenance.year`):`1 year`:n?n(`maintenance.days`,{count:e}):`${e} days`:`${e}h`}function ZUe({item:e,onPerform:t,onToggle:n,hasPermission:r,t:i}){let a=N6(e.maintenance_type_icon),o=e.interval_type||`hours`,s=(()=>{if(o===`days`){let t=e.days_since_maintenance??0;return Math.max(0,Math.min(100,t/e.interval_hours*100))}return Math.max(0,Math.min(100,(e.interval_hours-e.hours_until_due)/e.interval_hours*100))})(),c=()=>e.enabled?e.is_due?`text-red-700 dark:text-red-400`:e.is_warning?`text-amber-700 dark:text-amber-400`:`text-bambu-green`:`text-bambu-gray`;return(0,K.jsx)(`div`,{className:`rounded-xl border p-4 transition-all ${e.enabled?e.is_due?`bg-red-500/5 border-red-500/20`:e.is_warning?`bg-amber-500/5 border-amber-500/20`:`bg-bambu-dark-secondary border-bambu-dark-tertiary`:`bg-bambu-dark-secondary/50`}`,children:(0,K.jsxs)(`div`,{className:`flex items-start gap-3 max-[550px]:flex-wrap`,children:[(0,K.jsxs)(`div`,{className:`relative p-2.5 rounded-lg shrink-0 ${e.is_due?`bg-red-500/20`:e.is_warning?`bg-amber-500/20`:e.enabled?`bg-bambu-dark`:`bg-bambu-dark/50`}`,children:[(0,K.jsx)(a,{className:`w-5 h-5 ${c()}`}),e.enabled&&(e.is_due||e.is_warning)&&(0,K.jsx)(`span`,{className:`absolute -top-1 -right-1 w-2.5 h-2.5 rounded-full ${e.is_due?`bg-red-500`:`bg-amber-500`} animate-pulse`})]}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`h3`,{className:`font-medium truncate ${e.enabled?`text-white`:`text-bambu-gray`}`,children:e.maintenance_type_name}),o===`days`&&(0,K.jsx)(`span`,{title:i(`maintenance.timeBasedInterval`),children:(0,K.jsx)(Yo,{className:`w-3.5 h-3.5 text-bambu-gray shrink-0`})}),(()=>{let t=e.maintenance_type_wiki_url||XUe(e.maintenance_type_name,e.printer_model);return t?(0,K.jsx)(`a`,{href:t,target:`_blank`,rel:`noopener noreferrer`,className:`text-bambu-gray hover:text-bambu-green transition-colors shrink-0`,title:i(`maintenance.viewDocumentation`),onClick:e=>e.stopPropagation(),children:(0,K.jsx)(Ks,{className:`w-3.5 h-3.5`})}):null})()]}),(0,K.jsx)(`div`,{className:`mt-2 mb-1.5`,children:(0,K.jsx)(`div`,{className:`w-full h-1.5 bg-bambu-dark rounded-full overflow-hidden`,children:(0,K.jsx)(`div`,{className:`h-full rounded-full transition-all duration-500 ${e.enabled?e.is_due?`bg-red-500`:e.is_warning?`bg-amber-500`:`bg-bambu-green`:`bg-bambu-gray/30`}`,style:{width:`${s}%`}})})}),(0,K.jsxs)(`div`,{className:`text-xs flex items-center gap-1 ${c()}`,children:[e.is_due&&(0,K.jsx)(wu,{className:`w-3 h-3`}),e.is_warning&&!e.is_due&&(0,K.jsx)(bs,{className:`w-3 h-3`}),!e.is_due&&!e.is_warning&&e.enabled&&(0,K.jsx)(ts,{className:`w-3 h-3`}),(()=>{if(!e.enabled)return i(`common.disabled`);if(o===`days`){let t=e.days_until_due??0;return e.is_due?i(`maintenance.overdueBy`,{duration:P6(Math.abs(t),`days`,i)}):e.is_warning?i(`maintenance.dueIn`,{duration:P6(t,`days`,i)}):i(`maintenance.timeLeft`,{duration:P6(t,`days`,i)})}else return e.is_due?i(`maintenance.overdueBy`,{duration:P6(Math.abs(e.hours_until_due),`hours`,i)}):e.is_warning?i(`maintenance.dueIn`,{duration:P6(e.hours_until_due,`hours`,i)}):i(`maintenance.timeLeft`,{duration:P6(e.hours_until_due,`hours`,i)})})()]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0 max-[550px]:w-full max-[550px]:justify-end max-[550px]:mt-1`,children:[(0,K.jsx)(`span`,{title:r(`maintenance:update`)?void 0:i(`maintenance.noPermissionUpdate`),children:(0,K.jsx)(fU,{checked:e.enabled,onChange:t=>n(e.id,t),disabled:!r(`maintenance:update`)})}),(0,K.jsxs)($,{size:`sm`,variant:e.is_due?`primary`:`secondary`,onClick:()=>t(e.id),disabled:!e.enabled||!r(`maintenance:update`),title:r(`maintenance:update`)?void 0:i(`maintenance.noPermissionPerform`),className:`!px-3`,children:[(0,K.jsx)(jl,{className:`w-3.5 h-3.5`}),i(`common.reset`)]})]})]})})}function QUe({overview:e,onPerform:t,onToggle:n,onSetHours:r,hasPermission:i,t:a}){let[o,s]=(0,y.useState)(!1),[c,l]=(0,y.useState)(!1),[u,d]=(0,y.useState)(e.total_print_hours.toFixed(1)),f=[...e.maintenance_items].sort((e,t)=>e.is_due&&!t.is_due?-1:!e.is_due&&t.is_due?1:e.is_warning&&!t.is_warning?-1:!e.is_warning&&t.is_warning?1:e.maintenance_type_id-t.maintenance_type_id),p=f.find(e=>e.enabled&&(e.is_due||e.is_warning)),m=()=>{let t=parseFloat(u);!isNaN(t)&&t>=0&&(r(e.printer_id,t),l(!1))};return(0,K.jsxs)(xd,{className:`overflow-hidden`,children:[(0,K.jsxs)(`div`,{className:`p-5`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,K.jsx)(`h2`,{className:`text-xl font-semibold text-white`,children:e.printer_name}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.due_count>0&&(0,K.jsxs)(`span`,{className:`px-2.5 py-1 bg-red-100 text-red-700 dark:bg-red-500/20 dark:text-red-400 text-xs font-medium rounded-full flex items-center gap-1.5`,children:[(0,K.jsx)(wu,{className:`w-3 h-3`}),a(`maintenance.overdueCount`,{count:e.due_count})]}),e.warning_count>0&&(0,K.jsxs)(`span`,{className:`px-2.5 py-1 bg-amber-100 text-amber-700 dark:bg-amber-500/20 dark:text-amber-400 text-xs font-medium rounded-full flex items-center gap-1.5`,children:[(0,K.jsx)(bs,{className:`w-3 h-3`}),a(`maintenance.dueSoonCount`,{count:e.warning_count})]}),e.due_count===0&&e.warning_count===0&&(0,K.jsxs)(`span`,{className:`px-2.5 py-1 bg-bambu-green/20 text-bambu-green text-xs font-medium rounded-full flex items-center gap-1.5`,children:[(0,K.jsx)(ts,{className:`w-3 h-3`}),a(`maintenance.allGood`)]})]})]}),(0,K.jsxs)(`button`,{onClick:()=>s(!o),className:`flex items-center gap-1.5 px-3 py-1.5 text-sm text-bambu-gray hover:text-white hover:bg-bambu-dark rounded-lg transition-colors`,children:[o?(0,K.jsx)(as,{className:`w-4 h-4`}):(0,K.jsx)(ns,{className:`w-4 h-4`}),a(o?`common.collapse`:`common.expand`)]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-6 mt-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`p-2 bg-bambu-dark/50 rounded-lg`,children:(0,K.jsx)(bu,{className:`w-4 h-4 text-bambu-gray`})}),c?(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`input`,{type:`number`,value:u,onChange:e=>d(e.target.value),onKeyDown:e=>{e.key===`Enter`&&m(),e.key===`Escape`&&l(!1)},className:`w-24 px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm`,min:`0`,step:`1`,autoFocus:!0}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:a(`common.hours`)}),(0,K.jsx)($,{size:`sm`,onClick:m,children:a(`common.save`)}),(0,K.jsx)($,{size:`sm`,variant:`secondary`,onClick:()=>l(!1),children:a(`common.cancel`)})]}):(0,K.jsxs)(`button`,{onClick:()=>{i(`maintenance:update`)&&(d(Math.round(e.total_print_hours).toString()),l(!0))},className:`group ${i(`maintenance:update`)?``:`cursor-not-allowed opacity-60`}`,title:i(`maintenance:update`)?void 0:a(`maintenance.noPermissionEditHours`),children:[(0,K.jsxs)(`div`,{className:`text-sm font-medium text-white ${i(`maintenance:update`)?`group-hover:text-bambu-green`:``} transition-colors flex items-center gap-1`,children:[Math.round(e.total_print_hours),` `,a(`common.hours`),(0,K.jsx)(_l,{className:`w-3 h-3 text-bambu-gray ${i(`maintenance:update`)?`group-hover:text-bambu-green`:``}`})]}),(0,K.jsx)(`div`,{className:`text-xs text-bambu-gray`,children:a(`maintenance.totalPrintTime`)})]})]}),(0,K.jsx)(`div`,{className:`w-px h-10 bg-bambu-dark-tertiary`}),p&&(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`p-2 rounded-lg ${p.is_due?`bg-red-500/20`:`bg-amber-500/20`}`,children:(0,K.jsx)(N6(p.maintenance_type_icon),{className:`w-4 h-4 ${p.is_due?`text-red-600 dark:text-red-400`:`text-amber-600 dark:text-amber-400`}`})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`div`,{className:`text-sm font-medium ${p.is_due?`text-red-700 dark:text-red-400`:`text-amber-700 dark:text-amber-400`}`,children:p.maintenance_type_name}),(0,K.jsx)(`div`,{className:`text-xs ${p.is_due?`text-red-700/80 dark:text-red-400/70`:`text-amber-700/80 dark:text-amber-400/70`}`,children:p.is_due?a(`common.overdue`):a(`maintenance.dueSoon`)})]})]})]})]}),o&&(0,K.jsx)(Cd,{className:`pt-0 border-t border-bambu-dark-tertiary`,children:(0,K.jsx)(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-3 pt-4`,children:f.map(e=>(0,K.jsx)(ZUe,{item:e,onPerform:t,onToggle:n,hasPermission:i,t:a},e.id))})})]})}function $Ue({overview:e,types:t,onUpdateInterval:n,onAddType:r,onUpdateType:i,onDeleteType:a,onRestoreDefaults:o,isRestoringDefaults:s,onAssignType:c,onRemoveItem:l,hasPermission:u,t:d}){let[f,p]=(0,y.useState)(null),[m,h]=(0,y.useState)(``),[g,_]=(0,y.useState)(`hours`),[v,b]=(0,y.useState)(!1),[x,S]=(0,y.useState)(``),[C,w]=(0,y.useState)(`100`),[T,E]=(0,y.useState)(`hours`),[D,O]=(0,y.useState)(`Wrench`),[k,A]=(0,y.useState)(``),[j,M]=(0,y.useState)(new Set),[N,P]=(0,y.useState)(null),[F,I]=(0,y.useState)(null),L=(0,y.useMemo)(()=>e?e.map(e=>({id:e.printer_id,name:e.printer_name})):[],[e]),R=t=>e?e.filter(e=>e.maintenance_items.some(e=>e.maintenance_type_id===t)).map(e=>({printerId:e.printer_id,printerName:e.printer_name,itemId:e.maintenance_items.find(e=>e.maintenance_type_id===t)?.id})):[],z=t=>{if(!e)return[];let n=new Set(R(t).map(e=>e.printerId));return L.filter(e=>!n.has(e.id))},[B,V]=(0,y.useState)(null),[ee,te]=(0,y.useState)(``),[ne,re]=(0,y.useState)(``),[ie,H]=(0,y.useState)(`hours`),[ae,oe]=(0,y.useState)(`Wrench`),[U,se]=(0,y.useState)(``),ce=e=>{V(e),te(e.name),re(e.default_interval_hours.toString()),H(e.interval_type||`hours`),oe(e.icon||`Wrench`),se(e.wiki_url||``)},le=()=>{B&&ee.trim()&&parseFloat(ne)>0&&(i(B.id,{name:ee.trim(),default_interval_hours:parseFloat(ne),interval_type:ie,icon:ae,wiki_url:U.trim()||null}),V(null))},ue=(e,t,r)=>{let i=parseFloat(m);!isNaN(i)&&i>0&&n(e,{custom_interval_hours:Math.abs(i-t)<.01?null:i,custom_interval_type:g===r?null:g}),p(null)},de=e=>{e.preventDefault(),x.trim()&&parseFloat(C)>0&&j.size>0&&(r({name:x.trim(),default_interval_hours:parseFloat(C),interval_type:T,icon:D,wiki_url:k.trim()||null},Array.from(j)),S(``),w(`100`),E(`hours`),A(``),M(new Set),b(!1))},fe=e=>{M(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},pe=e?.map(e=>({printerId:e.printer_id,printerName:e.printer_name,items:e.maintenance_items.sort((e,t)=>e.maintenance_type_id-t.maintenance_type_id)})).sort((e,t)=>e.printerName.localeCompare(t.printerName))||[],me=t.filter(e=>e.is_system),he=t.filter(e=>!e.is_system);return(0,K.jsxs)(`div`,{className:`space-y-8`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-4`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:d(`maintenance.maintenanceTypes`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:d(`maintenance.maintenanceTypesDescription`)})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)($,{variant:`secondary`,onClick:o,disabled:!u(`maintenance:delete`)||s,title:u(`maintenance:delete`)?void 0:d(`maintenance.noPermissionDeleteTypes`),children:d(`maintenance.restoreDefaults`)}),(0,K.jsxs)($,{onClick:()=>b(!v),disabled:!u(`maintenance:create`),title:u(`maintenance:create`)?void 0:d(`maintenance.noPermissionEditTypes`),children:[(0,K.jsx)(Cl,{className:`w-4 h-4`}),d(`maintenance.addCustomType`)]})]})]}),v&&(0,K.jsx)(xd,{className:`mb-6`,children:(0,K.jsx)(Cd,{className:`py-4`,children:(0,K.jsxs)(`form`,{onSubmit:de,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4`,children:[(0,K.jsxs)(`div`,{className:`lg:col-span-2`,children:[(0,K.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1.5`,children:d(`common.name`)}),(0,K.jsx)(`input`,{type:`text`,value:x,onChange:e=>S(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,placeholder:d(`maintenance.exampleName`),autoFocus:!0})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1.5`,children:d(`maintenance.intervalType`)}),(0,K.jsxs)(`select`,{value:T,onChange:e=>{E(e.target.value),e.target.value===`days`?w(`30`):w(`100`)},className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,children:[(0,K.jsx)(`option`,{value:`hours`,children:d(`maintenance.printHours`)}),(0,K.jsx)(`option`,{value:`days`,children:d(`maintenance.calendarDays`)})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1.5`,children:d(`maintenance.intervalValue`,{type:T===`days`?d(`maintenance.calendarDays`).toLowerCase():d(`common.hours`)})}),(0,K.jsx)(`input`,{type:`number`,value:C,onChange:e=>w(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,min:`1`})]})]}),(0,K.jsx)(`div`,{className:`mt-4 flex items-end justify-between`,children:(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1.5`,children:d(`maintenance.icon`)}),(0,K.jsx)(`div`,{className:`flex gap-1`,children:Object.keys(M6).map(e=>{let t=M6[e];return(0,K.jsx)(`button`,{type:`button`,onClick:()=>O(e),className:`p-2 rounded-lg transition-colors ${D===e?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary`}`,children:(0,K.jsx)(t,{className:`w-4 h-4`})},e)})})]})}),(0,K.jsxs)(`div`,{className:`mt-4`,children:[(0,K.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1.5`,children:d(`maintenance.documentationLink`)}),(0,K.jsx)(`input`,{type:`url`,value:k,onChange:e=>A(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,placeholder:`https://wiki.bambulab.com/...`})]}),(0,K.jsxs)(`div`,{className:`mt-4`,children:[(0,K.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1.5`,children:d(`maintenance.assignToPrinters`)}),(0,K.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:L.map(e=>(0,K.jsx)(`button`,{type:`button`,onClick:()=>fe(e.id),className:`px-3 py-1.5 rounded-lg text-sm transition-colors ${j.has(e.id)?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary`}`,children:e.name},e.id))}),j.size===0&&(0,K.jsx)(`p`,{className:`text-xs text-orange-700 dark:text-orange-400 mt-1`,children:d(`maintenance.selectAtLeastOnePrinter`)})]}),(0,K.jsxs)(`div`,{className:`mt-4 flex justify-end gap-2`,children:[(0,K.jsx)($,{type:`button`,variant:`secondary`,onClick:()=>{b(!1),M(new Set)},children:d(`common.cancel`)}),(0,K.jsx)($,{type:`submit`,disabled:!x.trim()||j.size===0,children:d(`maintenance.addType`)})]})]})})}),(0,K.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3`,children:[me.map(e=>{let t=N6(e.icon),n=e.interval_type||`hours`;return(0,K.jsx)(`div`,{className:`bg-bambu-dark-secondary rounded-xl p-4 border border-bambu-dark-tertiary`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`p-2.5 bg-bambu-dark rounded-lg`,children:(0,K.jsx)(t,{className:`w-5 h-5 text-bambu-gray`})}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsx)(`div`,{className:`text-sm font-medium text-white truncate`,children:e.name}),(0,K.jsxs)(`div`,{className:`text-xs text-bambu-gray mt-0.5 flex items-center gap-1`,children:[n===`days`?(0,K.jsx)(Yo,{className:`w-3 h-3`}):(0,K.jsx)(bu,{className:`w-3 h-3`}),F6(e.default_interval_hours,n,d)]})]}),(0,K.jsx)(`button`,{onClick:()=>{u(`maintenance:delete`)&&I(e)},disabled:!u(`maintenance:delete`),title:u(`maintenance:delete`)?void 0:d(`maintenance.noPermissionDeleteTypes`),className:`p-2 rounded-lg hover:bg-bambu-dark text-bambu-gray hover:text-red-600 dark:hover:text-red-400 transition-colors ${u(`maintenance:delete`)?``:`opacity-50 cursor-not-allowed`}`,children:(0,K.jsx)(xu,{className:`w-4 h-4`})})]})},e.id)}),he.map(e=>{let t=N6(e.icon),n=e.interval_type||`hours`;if(B?.id===e.id)return(0,K.jsx)(`div`,{className:`bg-bambu-dark-secondary rounded-xl p-4 border border-bambu-green`,children:(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsx)(`input`,{type:`text`,value:ee,onChange:e=>te(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,placeholder:d(`common.name`),autoFocus:!0}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsxs)(`select`,{value:ie,onChange:e=>H(e.target.value),className:`flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,children:[(0,K.jsx)(`option`,{value:`hours`,children:d(`maintenance.printHours`)}),(0,K.jsx)(`option`,{value:`days`,children:d(`maintenance.calendarDays`)})]}),(0,K.jsx)(`input`,{type:`number`,value:ne,onChange:e=>re(e.target.value),className:`w-24 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,min:`1`})]}),(0,K.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:Object.keys(M6).map(e=>{let t=M6[e];return(0,K.jsx)(`button`,{type:`button`,onClick:()=>oe(e),className:`p-1.5 rounded transition-colors ${ae===e?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white`}`,children:(0,K.jsx)(t,{className:`w-3.5 h-3.5`})},e)})}),(0,K.jsx)(`input`,{type:`url`,value:U,onChange:e=>se(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,placeholder:d(`maintenance.documentationLink`)}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)($,{size:`sm`,onClick:le,disabled:!ee.trim(),children:d(`common.save`)}),(0,K.jsx)($,{size:`sm`,variant:`secondary`,onClick:()=>V(null),children:d(`common.cancel`)})]})]})},e.id);let r=R(e.id),i=z(e.id),o=N===e.id;return(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl p-4 border border-bambu-green/30`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`p-2.5 bg-bambu-green/20 rounded-lg`,children:(0,K.jsx)(t,{className:`w-5 h-5 text-bambu-green`})}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`text-sm font-medium text-white truncate`,children:e.name}),(0,K.jsx)(`span`,{className:`px-1.5 py-0.5 bg-bambu-green/20 text-bambu-green text-[10px] font-medium rounded`,children:d(`maintenance.custom`)})]}),(0,K.jsxs)(`div`,{className:`text-xs text-bambu-gray mt-0.5 flex items-center gap-1`,children:[n===`days`?(0,K.jsx)(Yo,{className:`w-3 h-3`}):(0,K.jsx)(bu,{className:`w-3 h-3`}),F6(e.default_interval_hours,n,d)]})]}),(0,K.jsxs)(`button`,{onClick:()=>P(o?null:e.id),className:`px-2 py-1 rounded-lg border transition-colors flex items-center gap-1 ${r.length>0?`border-bambu-green/50 bg-bambu-green/10 text-bambu-green hover:bg-bambu-green/20`:`border-orange-300 bg-orange-50 text-orange-700 hover:bg-orange-100 dark:border-orange-400/50 dark:bg-orange-400/10 dark:text-orange-400 dark:hover:bg-orange-400/20`}`,title:d(`maintenance.printersAssignedClick`,{count:r.length}),children:[(0,K.jsx)(El,{className:`w-3 h-3`}),(0,K.jsx)(`span`,{className:`text-xs font-medium`,children:r.length}),(0,K.jsx)(ns,{className:`w-3 h-3 transition-transform ${o?`rotate-180`:``}`})]}),(0,K.jsx)(`button`,{onClick:()=>ce(e),disabled:!u(`maintenance:update`),title:u(`maintenance:update`)?void 0:d(`maintenance.noPermissionEditTypes`),className:`p-2 rounded-lg hover:bg-bambu-dark text-bambu-gray hover:text-white transition-colors ${u(`maintenance:update`)?``:`opacity-50 cursor-not-allowed`}`,children:(0,K.jsx)(_l,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>{confirm(d(`maintenance.deleteTypeConfirm`,{name:e.name}))&&a(e.id)},disabled:!u(`maintenance:delete`),title:u(`maintenance:delete`)?void 0:d(`maintenance.noPermissionDeleteTypes`),className:`p-2 rounded-lg hover:bg-bambu-dark text-bambu-gray hover:text-red-600 dark:hover:text-red-400 transition-colors ${u(`maintenance:delete`)?``:`opacity-50 cursor-not-allowed`}`,children:(0,K.jsx)(xu,{className:`w-4 h-4`})})]}),o&&(0,K.jsxs)(`div`,{className:`mt-3 pt-3 border-t border-bambu-dark-tertiary`,children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:d(`maintenance.assignedToPrinters`)}),r.length===0?(0,K.jsx)(`p`,{className:`text-xs text-orange-700 dark:text-orange-400`,children:d(`maintenance.noPrintersAssigned`)}):(0,K.jsx)(`div`,{className:`flex flex-wrap gap-1 mb-2`,children:r.map(e=>(0,K.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-2 py-1 bg-bambu-dark rounded text-xs text-white`,children:[e.printerName,(0,K.jsx)(`button`,{onClick:()=>e.itemId&&l(e.itemId),disabled:!u(`maintenance:delete`),title:u(`maintenance:delete`)?d(`maintenance.removeFromPrinter`):d(`maintenance.noPermissionRemovePrinter`),className:`ml-1 ${u(`maintenance:delete`)?`hover:text-red-600 dark:hover:text-red-400`:`opacity-50 cursor-not-allowed`}`,children:`×`})]},e.printerId))}),i.length>0&&(0,K.jsxs)(`div`,{className:`flex flex-wrap gap-1`,children:[(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray mr-1`,children:d(`maintenance.addPrinterShort`)}),i.map(t=>(0,K.jsxs)(`button`,{onClick:()=>c(t.id,e.id),disabled:!u(`maintenance:create`),title:u(`maintenance:create`)?void 0:d(`maintenance.noPermissionAssignPrinter`),className:`px-2 py-1 bg-bambu-dark rounded text-xs transition-colors ${u(`maintenance:create`)?`hover:bg-bambu-green/20 text-bambu-gray hover:text-bambu-green`:`opacity-50 cursor-not-allowed text-bambu-gray`}`,children:[`+ `,t.name]},t.id))]})]})]},e.id)})]})]}),pe.length>0&&(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`mb-4`,children:[(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:d(`maintenance.intervalOverrides`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:d(`maintenance.intervalOverridesDescription`)})]}),(0,K.jsx)(`div`,{className:`space-y-4`,children:pe.map(e=>(0,K.jsx)(xd,{children:(0,K.jsxs)(Cd,{className:`py-4`,children:[(0,K.jsx)(`h3`,{className:`text-sm font-medium text-white mb-3`,children:e.printerName}),(0,K.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-2`,children:e.items.map(e=>{let n=N6(e.maintenance_type_icon),r=t.find(t=>t.id===e.maintenance_type_id),i=r?.default_interval_hours||e.interval_hours,a=r?.interval_type||`hours`,o=e.interval_type||`hours`,s=f===e.id;return(0,K.jsxs)(`div`,{className:`flex items-center gap-2 p-2.5 bg-bambu-dark rounded-lg`,children:[(0,K.jsx)(n,{className:`w-4 h-4 text-bambu-gray shrink-0`}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray flex-1 truncate`,children:e.maintenance_type_name}),s?(0,K.jsxs)(`div`,{className:`flex items-center gap-1`,children:[g===`days`?(0,K.jsx)(Yo,{className:`w-3.5 h-3.5 text-bambu-gray shrink-0`}):(0,K.jsx)(bu,{className:`w-3.5 h-3.5 text-bambu-gray shrink-0`}),(0,K.jsxs)(`select`,{value:g,onChange:e=>_(e.target.value),className:`px-1.5 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-xs`,children:[(0,K.jsx)(`option`,{value:`hours`,children:d(`maintenance.printHours`)}),(0,K.jsx)(`option`,{value:`days`,children:d(`maintenance.calendarDays`)})]}),(0,K.jsx)(`input`,{type:`number`,value:m,onChange:e=>h(e.target.value),onKeyDown:t=>{t.key===`Enter`&&ue(e.id,i,a),t.key===`Escape`&&p(null)},className:`w-16 px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-xs`,min:`1`}),(0,K.jsx)($,{size:`sm`,onClick:()=>ue(e.id,i,a),children:`OK`})]}):(0,K.jsxs)(`button`,{onClick:()=>{u(`maintenance:update`)&&(p(e.id),h(e.interval_hours.toString()),_(o))},disabled:!u(`maintenance:update`),title:u(`maintenance:update`)?void 0:d(`maintenance.noPermissionEditIntervals`),className:`px-2 py-1 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-xs font-medium text-white transition-colors flex items-center gap-1 ${u(`maintenance:update`)?`hover:bg-bambu-dark-secondary hover:border-bambu-green`:`opacity-50 cursor-not-allowed`}`,children:[o===`days`?(0,K.jsx)(Yo,{className:`w-3 h-3`}):(0,K.jsx)(bu,{className:`w-3 h-3`}),F6(e.interval_hours,o,d),(0,K.jsx)(_l,{className:`w-3 h-3 text-bambu-gray`})]})]},e.id)})})]})},e.printerId))})]}),pe.length===0&&(0,K.jsx)(xd,{children:(0,K.jsxs)(Cd,{className:`text-center py-12`,children:[(0,K.jsx)(bs,{className:`w-12 h-12 mx-auto mb-4 text-bambu-gray/30`}),(0,K.jsx)(`p`,{className:`text-bambu-gray`,children:d(`common.noPrinters`)}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray/70 mt-1`,children:d(`maintenance.intervalOverridesDescription`)})]})}),F&&(0,K.jsx)(Rd,{title:d(`maintenance.deleteSystemTypeTitle`),message:d(`maintenance.deleteSystemTypeMessage`,{name:F.name}),confirmText:d(`common.delete`),cancelText:d(`common.cancel`),variant:`danger`,cancelVariant:`primary`,cardClassName:`bg-red-950/70 border border-red-800/70`,onConfirm:()=>{a(F.id),I(null)},onCancel:()=>I(null)})]})}function eWe(){let{t:e}=W(),t=to(),{showToast:n}=kd(),{hasPermission:r}=hd(),[i,a]=(0,y.useState)(`status`),{data:o,isLoading:s}=q({queryKey:[`maintenanceOverview`],queryFn:Q.getMaintenanceOverview}),{data:c}=q({queryKey:[`maintenanceTypes`],queryFn:Q.getMaintenanceTypes}),l=J({mutationFn:({id:e,notes:t})=>Q.performMaintenance(e,t),onSuccess:()=>{t.invalidateQueries({queryKey:[`maintenanceOverview`]}),t.invalidateQueries({queryKey:[`maintenanceSummary`]}),n(e(`maintenance.maintenanceComplete`))},onError:e=>{n(e.message,`error`)}}),u=J({mutationFn:({id:e,data:t})=>Q.updateMaintenanceItem(e,t),onSuccess:()=>{t.invalidateQueries({queryKey:[`maintenanceOverview`]})},onError:e=>{n(e.message,`error`)}}),d=J({mutationFn:({id:e,data:t})=>Q.updateMaintenanceType(e,t),onSuccess:()=>{t.invalidateQueries({queryKey:[`maintenanceTypes`]}),t.invalidateQueries({queryKey:[`maintenanceOverview`]}),n(e(`maintenance.typeUpdated`))},onError:e=>{n(e.message,`error`)}}),f=J({mutationFn:Q.deleteMaintenanceType,onSuccess:()=>{t.invalidateQueries({queryKey:[`maintenanceTypes`]}),t.invalidateQueries({queryKey:[`maintenanceOverview`]}),n(e(`maintenance.typeDeleted`))},onError:e=>{n(e.message,`error`)}}),p=J({mutationFn:Q.restoreDefaultMaintenanceTypes,onSuccess:r=>{t.invalidateQueries({queryKey:[`maintenanceTypes`]}),t.invalidateQueries({queryKey:[`maintenanceOverview`]}),n(e(`maintenance.defaultsRestored`,{count:r.restored}))},onError:e=>{n(e.message,`error`)}}),m=J({mutationFn:({printerId:e,hours:t})=>Q.setPrinterHours(e,t),onSuccess:()=>{t.invalidateQueries({queryKey:[`maintenanceOverview`]}),t.invalidateQueries({queryKey:[`maintenanceSummary`]}),n(e(`maintenance.printHoursUpdated`))},onError:e=>{n(e.message,`error`)}}),h=J({mutationFn:({printerId:e,typeId:t})=>Q.assignMaintenanceType(e,t),onSuccess:()=>{t.invalidateQueries({queryKey:[`maintenanceOverview`]}),n(e(`maintenance.printerAssigned`))},onError:e=>{n(e.message,`error`)}}),g=J({mutationFn:Q.removeMaintenanceItem,onSuccess:()=>{t.invalidateQueries({queryKey:[`maintenanceOverview`]}),n(e(`maintenance.printerRemoved`))},onError:e=>{n(e.message,`error`)}}),_=e=>{l.mutate({id:e})},v=(e,t)=>{u.mutate({id:e,data:{enabled:t}})},b=(e,t)=>{m.mutate({printerId:e,hours:t})};if(s)return(0,K.jsx)(`div`,{className:`p-4 md:p-8 flex justify-center`,children:(0,K.jsx)(X,{className:`w-8 h-8 text-bambu-green animate-spin`})});let x=o?.reduce((e,t)=>e+t.due_count,0)||0,S=o?.reduce((e,t)=>e+t.warning_count,0)||0;return(0,K.jsxs)(`div`,{className:`p-4 md:p-8`,children:[(0,K.jsxs)(`div`,{className:`mb-6`,children:[(0,K.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,K.jsx)(Vu,{className:`w-7 h-7 text-bambu-green`}),e(`maintenance.title`)]}),(0,K.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:i===`status`?(0,K.jsxs)(K.Fragment,{children:[x>0&&(0,K.jsx)(`span`,{className:`text-red-700 dark:text-red-400`,children:e(`maintenance.dueCount`,{count:x})}),x>0&&S>0&&` · `,S>0&&(0,K.jsx)(`span`,{className:`text-amber-700 dark:text-amber-400`,children:e(`maintenance.warningCount`,{count:S})}),x===0&&S===0&&(0,K.jsx)(`span`,{className:`text-bambu-green`,children:e(`maintenance.allOk`)})]}):e(`maintenance.configureSettings`)})]}),(0,K.jsxs)(`div`,{className:`flex gap-1 mb-6 border-b border-bambu-dark-tertiary`,children:[(0,K.jsx)(`button`,{onClick:()=>a(`status`),className:`px-4 py-2 text-sm font-medium border-b-2 -mb-px transition-colors ${i===`status`?`text-bambu-green border-bambu-green`:`text-bambu-gray border-transparent hover:text-white`}`,children:e(`maintenance.statusTab`)}),(0,K.jsx)(`button`,{onClick:()=>a(`settings`),className:`px-4 py-2 text-sm font-medium border-b-2 -mb-px transition-colors ${i===`settings`?`text-bambu-green border-bambu-green`:`text-bambu-gray border-transparent hover:text-white`}`,children:e(`maintenance.settingsTab`)})]}),i===`status`?(0,K.jsx)(`div`,{className:`space-y-6`,children:o&&o.length>0?[...o].sort((e,t)=>{let n=e.due_count*10+e.warning_count,r=t.due_count*10+t.warning_count;return n===r?e.printer_name.localeCompare(t.printer_name):r-n}).map(t=>(0,K.jsx)(QUe,{overview:t,onPerform:_,onToggle:v,onSetHours:b,hasPermission:r,t:e},t.printer_id)):(0,K.jsx)(xd,{children:(0,K.jsxs)(Cd,{className:`text-center py-16`,children:[(0,K.jsx)(Vu,{className:`w-16 h-16 mx-auto mb-4 text-bambu-gray/30`}),(0,K.jsx)(`p`,{className:`text-lg font-medium text-white mb-2`,children:e(`common.noPrinters`)}),(0,K.jsx)(`p`,{className:`text-bambu-gray`,children:e(`maintenance.configureSettings`)})]})})}):(0,K.jsx)($Ue,{overview:o,types:c||[],onUpdateInterval:(e,t)=>u.mutate({id:e,data:t}),onAddType:async(r,i)=>{let a=await Q.createMaintenanceType(r);for(let e of i)await Q.assignMaintenanceType(e,a.id);t.invalidateQueries({queryKey:[`maintenanceTypes`]}),t.invalidateQueries({queryKey:[`maintenanceOverview`]}),n(e(`maintenance.typeUpdated`))},onUpdateType:(e,t)=>d.mutate({id:e,data:t}),onDeleteType:e=>f.mutate(e),onRestoreDefaults:()=>p.mutate(),isRestoringDefaults:p.isPending,onAssignType:(e,t)=>h.mutate({printerId:e,typeId:t}),onRemoveItem:e=>g.mutate(e),hasPermission:r,t:e})]})}var I6=[`#ef4444`,`#f97316`,`#eab308`,`#22c55e`,`#06b6d4`,`#3b82f6`,`#8b5cf6`,`#ec4899`,`#6b7280`];function L6({project:e,onClose:t,onSave:n,isLoading:r,currencySymbol:i,t:a}){let[o,s]=(0,y.useState)(e?.name||``),[c,l]=(0,y.useState)(e?.description||``),[u,d]=(0,y.useState)(e?.color||I6[0]),[f,p]=(0,y.useState)(e?.target_count?.toString()||``),[m,h]=(0,y.useState)(e?.target_parts_count?.toString()||``),[g,_]=(0,y.useState)(e?.status||`active`),[v,b]=(0,y.useState)(e?.tags||``),[x,S]=(0,y.useState)(e?.due_date?.split(`T`)[0]||``),[C,w]=(0,y.useState)(e?.priority||`normal`),[T,E]=(0,y.useState)(e?.budget?.toString()||``),[D,O]=(0,y.useState)(e?.url||``),[k,A]=(0,y.useState)(null),j=to(),[M,N]=(0,y.useState)(e?.cover_image_filename||null),P=(0,y.useRef)(null),[F,I]=(0,y.useState)(!1),[L,R]=(0,y.useState)(0);return(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg w-full max-w-md border border-bambu-dark-tertiary flex flex-col max-h-[calc(100vh-2rem)]`,children:[(0,K.jsx)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary flex-shrink-0`,children:(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:a(e?`projects.editProject`:`projects.newProject`)})}),(0,K.jsxs)(`form`,{onSubmit:t=>{t.preventDefault();let r=D.trim();if(r&&!/^https?:\/\//i.test(r)){A(a(`projects.urlInvalid`));return}A(null),n({name:o.trim(),description:c.trim()||void 0,color:u,target_count:f?parseInt(f,10):void 0,target_parts_count:m?parseInt(m,10):void 0,tags:e?v.trim()||null:v.trim()||void 0,due_date:e?x||null:x||void 0,priority:C,budget:T.trim()?parseFloat(T):null,url:e?r||null:r||void 0,...e&&{status:g}})},className:`flex flex-col flex-1 min-h-0`,children:[(0,K.jsxs)(`div`,{className:`p-4 space-y-4 overflow-y-auto flex-1`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`common.name`)}),(0,K.jsx)(`input`,{type:`text`,value:o,onChange:e=>s(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:a(`projects.namePlaceholder`),required:!0})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`common.description`)}),(0,K.jsx)(`textarea`,{value:c,onChange:e=>l(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green resize-none`,placeholder:a(`projects.descriptionPlaceholder`),rows:2})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`projects.urlLabel`)}),(0,K.jsx)(`input`,{type:`url`,value:D,onChange:e=>{O(e.target.value),k&&A(null)},className:`w-full bg-bambu-dark border rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none ${k?`border-red-500 focus:border-red-500`:`border-bambu-dark-tertiary focus:border-bambu-green`}`,placeholder:a(`projects.urlPlaceholder`),maxLength:2048}),k&&(0,K.jsx)(`p`,{className:`text-xs text-red-600 dark:text-red-400 mt-1`,children:k})]}),e&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`projects.coverImageLabel`)}),(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`w-20 h-20 rounded bg-bambu-dark border border-bambu-dark-tertiary overflow-hidden flex items-center justify-center flex-shrink-0`,children:M?(0,K.jsx)(`img`,{src:`${Q.getProjectCoverImageUrl(e.id)}?v=${L}`,alt:a(`projects.coverImageAlt`),className:`w-full h-full object-cover`}):(0,K.jsx)(Ac,{className:`w-6 h-6 text-bambu-gray`})}),(0,K.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,K.jsx)(`input`,{ref:P,type:`file`,accept:`image/jpeg,image/png,image/gif,image/webp`,onChange:async t=>{let n=t.target.files?.[0];if(!(!n||!e)){I(!0);try{N((await Q.uploadProjectCoverImage(e.id,n)).filename),R(e=>e+1),j.invalidateQueries({queryKey:[`projects`]})}catch{}finally{I(!1),P.current&&(P.current.value=``)}}},className:`hidden`}),(0,K.jsxs)($,{type:`button`,variant:`secondary`,onClick:()=>P.current?.click(),disabled:F,children:[F?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(Ou,{className:`w-4 h-4 mr-1`}),a(M?`projects.coverImageReplace`:`projects.coverImageUpload`)]}),M&&(0,K.jsxs)($,{type:`button`,variant:`secondary`,onClick:async()=>{if(e){I(!0);try{await Q.deleteProjectCoverImage(e.id),N(null),R(e=>e+1),j.invalidateQueries({queryKey:[`projects`]})}finally{I(!1)}}},disabled:F,children:[(0,K.jsx)(Hu,{className:`w-4 h-4 mr-1`}),a(`projects.coverImageRemove`)]})]})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`projects.color`)}),(0,K.jsx)(`div`,{className:`flex gap-2 flex-wrap`,children:I6.map(e=>(0,K.jsx)(`button`,{type:`button`,onClick:()=>d(e),className:`w-8 h-8 rounded-full transition-transform ${u===e?`ring-2 ring-white ring-offset-2 ring-offset-bambu-dark-secondary scale-110`:``}`,style:{backgroundColor:e}},e))})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`projects.targetPlates`)}),(0,K.jsx)(`input`,{type:`number`,value:f,onChange:e=>p(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:a(`projects.targetPlatesPlaceholder`),min:`1`}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:a(`projects.targetPlatesHelp`)})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`projects.targetParts`)}),(0,K.jsx)(`input`,{type:`number`,value:m,onChange:e=>h(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:a(`projects.targetPartsPlaceholder`),min:`1`}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:a(`projects.targetPartsHelp`)})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`projects.tagsLabel`)}),(0,K.jsx)(`input`,{type:`text`,value:v,onChange:e=>b(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:a(`projects.tagsPlaceholder`)})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`projects.dueDate`)}),(0,K.jsx)(`input`,{type:`date`,value:x,onChange:e=>S(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white focus:outline-none focus:border-bambu-green`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`projects.priority`)}),(0,K.jsxs)(`select`,{value:C,onChange:e=>w(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white focus:outline-none focus:border-bambu-green`,children:[(0,K.jsx)(`option`,{value:`low`,children:a(`projects.priorityLow`)}),(0,K.jsx)(`option`,{value:`normal`,children:a(`projects.priorityNormal`)}),(0,K.jsx)(`option`,{value:`high`,children:a(`projects.priorityHigh`)}),(0,K.jsx)(`option`,{value:`urgent`,children:a(`projects.priorityUrgent`)})]})]})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`projectDetail.cost.budget`)}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(`span`,{className:`absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray pointer-events-none`,children:i}),(0,K.jsx)(`input`,{type:`number`,step:`0.01`,min:`0`,value:T,onChange:e=>E(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded pl-8 pr-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:`0.00`})]})]}),e&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`common.status`)}),(0,K.jsxs)(`select`,{value:g,onChange:e=>_(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white focus:outline-none focus:border-bambu-green`,children:[(0,K.jsx)(`option`,{value:`active`,children:a(`projects.statusActive`)}),(0,K.jsx)(`option`,{value:`completed`,children:a(`projects.statusCompleted`)}),(0,K.jsx)(`option`,{value:`archived`,children:a(`projects.statusArchived`)})]})]})]}),(0,K.jsxs)(`div`,{className:`flex justify-end gap-2 p-4 border-t border-bambu-dark-tertiary flex-shrink-0`,children:[(0,K.jsx)($,{type:`button`,variant:`secondary`,onClick:t,children:a(`common.cancel`)}),(0,K.jsx)($,{type:`submit`,disabled:!o.trim()||r,children:r?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):a(e?`common.save`:`projects.create`)})]})]})]})})}function tWe({projectId:e,altText:t}){let n=(0,y.useRef)(null),[r,i]=(0,y.useState)(!1),[a,o]=(0,y.useState)(null);return(0,K.jsxs)(`div`,{ref:n,className:`relative flex-shrink-0`,onMouseEnter:()=>{if(!n.current)return;let e=n.current.getBoundingClientRect(),t=window.innerWidth,r=window.innerHeight,a=e.right+8;a+384>t-8&&(a=e.left-384-8);let s=e.top;s+384>r-8&&(s=r-384-8),s<8&&(s=8),o({left:a,top:s}),i(!0)},onMouseLeave:()=>i(!1),onClick:e=>e.stopPropagation(),children:[(0,K.jsx)(`div`,{className:`w-10 h-10 rounded-lg overflow-hidden bg-bambu-dark border border-bambu-dark-tertiary`,children:(0,K.jsx)(`img`,{src:Q.getProjectCoverImageUrl(e),alt:t,className:`w-full h-full object-cover`,loading:`lazy`})}),r&&a&&(0,Lp.createPortal)((0,K.jsx)(`div`,{className:`fixed z-[100] w-96 h-96 rounded-lg overflow-hidden border border-bambu-dark-tertiary shadow-2xl bg-bambu-dark pointer-events-none`,style:{left:a.left,top:a.top},"aria-hidden":`true`,children:(0,K.jsx)(`img`,{src:Q.getProjectCoverImageUrl(e),alt:``,className:`w-full h-full object-contain`,loading:`lazy`})}),document.body)]})}function nWe({project:e,onClick:t,onEdit:n,onDelete:r,hasPermission:i,t:a}){let o=e.target_count?Math.round(e.archive_count/e.target_count*100):0,s=e.target_parts_count?Math.round(e.completed_count/e.target_parts_count*100):0,c=e.status===`completed`,l=e.status===`archived`,[u,d]=(0,y.useState)(!1),f=c?{icon:fs,color:`text-bambu-green`,bg:`bg-bambu-green/10`}:l?{icon:Do,color:`text-bambu-gray`,bg:`bg-bambu-gray/10`}:e.queue_count>0?{icon:bs,color:`text-blue-600 dark:text-blue-400`,bg:`bg-blue-50 dark:bg-blue-400/10`}:{icon:ac,color:`text-bambu-gray`,bg:`bg-bambu-gray/10`};return(0,K.jsxs)(`div`,{className:`group relative bg-gradient-to-br from-bambu-card to-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary hover:border-bambu-green/50 hover:shadow-lg hover:shadow-bambu-green/5 transition-all duration-300 cursor-pointer overflow-hidden`,onClick:t,children:[(0,K.jsx)(`div`,{className:`absolute top-0 left-0 w-1.5 h-full`,style:{backgroundColor:e.color||`#6b7280`,boxShadow:`0 0 12px ${e.color||`#6b7280`}40`}}),(0,K.jsxs)(`div`,{className:`p-5 pl-6`,children:[(0,K.jsxs)(`div`,{className:`flex items-start justify-between mb-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 flex-1`,children:[e.cover_image_filename?(0,K.jsx)(tWe,{projectId:e.id,altText:a(`projects.coverImageAlt`)}):(0,K.jsx)(`div`,{className:`p-2 rounded-lg ${f.bg} flex-shrink-0`,children:(0,K.jsx)(f.icon,{className:`w-5 h-5 ${f.color}`})}),(0,K.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,K.jsx)(`h3`,{className:`font-semibold text-white truncate`,children:e.name}),e.url&&(0,K.jsx)(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,onClick:e=>e.stopPropagation(),title:e.url,"aria-label":a(`projects.openExternalUrl`),className:`inline-flex items-center justify-center w-6 h-6 rounded bg-bambu-dark border border-bambu-dark-tertiary text-bambu-green hover:bg-bambu-green/10 hover:border-bambu-green transition-colors flex-shrink-0`,children:(0,K.jsx)(Ks,{className:`w-3.5 h-3.5`})}),e.target_parts_count?(0,K.jsxs)(`span`,{className:`text-xs px-2 py-0.5 rounded-full whitespace-nowrap font-medium ${s>=100?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark text-bambu-gray`}`,children:[e.completed_count,`/`,e.target_parts_count,` `,a(`projects.parts`)]}):e.target_count?(0,K.jsxs)(`span`,{className:`text-xs px-2 py-0.5 rounded-full whitespace-nowrap font-medium ${o>=100?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark text-bambu-gray`}`,children:[e.archive_count,`/`,e.target_count,` `,a(`projects.plates`)]}):e.completed_count>0?(0,K.jsxs)(`span`,{className:`text-xs px-2 py-0.5 rounded-full whitespace-nowrap font-medium bg-bambu-dark text-bambu-gray`,children:[e.completed_count,` `,a(`projects.parts`)]}):null,c&&(0,K.jsx)(`span`,{className:`text-xs bg-bambu-green/20 text-bambu-green px-2 py-0.5 rounded-full whitespace-nowrap`,children:a(`projects.done`)}),l&&(0,K.jsx)(`span`,{className:`text-xs bg-bambu-gray/20 text-bambu-gray px-2 py-0.5 rounded-full whitespace-nowrap`,children:a(`projects.statusArchived`)})]}),e.description&&(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray/70 mt-1 line-clamp-1`,children:e.description}),e.archives&&e.archives.length>0&&(()=>{let t=e.archives.map(e=>e.filament_type).filter(Boolean).flatMap(e=>e.split(`,`).map(e=>e.trim())).filter(Boolean),n=[...new Set(t)],r=e.archives.map(e=>e.filament_color).filter(Boolean).flatMap(e=>e.split(`,`).map(e=>e.trim())).filter(e=>e.startsWith(`#`)||/^[0-9A-Fa-f]{6}$/.test(e)),i=[...new Set(r)];return n.length===0&&i.length===0?null:(0,K.jsxs)(`div`,{className:`flex items-center gap-2 mt-1.5`,children:[n.slice(0,3).map(e=>(0,K.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 bg-bambu-dark text-bambu-gray rounded`,children:e},e)),i.length>0&&(0,K.jsxs)(`div`,{className:`flex items-center gap-0.5`,children:[i.slice(0,5).map(e=>(0,K.jsx)(`div`,{className:`w-3 h-3 rounded-full border border-black/20`,style:{backgroundColor:e.startsWith(`#`)?e:`#${e}`},title:e},e)),i.length>5&&(0,K.jsxs)(`span`,{className:`text-[10px] text-bambu-gray ml-0.5`,children:[`+`,i.length-5]})]})]})})()]})]}),(0,K.jsxs)(`div`,{className:`relative`,onClick:e=>e.stopPropagation(),children:[(0,K.jsx)(`button`,{className:`p-1.5 rounded-lg hover:bg-bambu-dark text-bambu-gray hover:text-white transition-colors opacity-0 group-hover:opacity-100`,onClick:()=>d(!u),children:(0,K.jsx)(Hs,{className:`w-4 h-4`})}),u&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`div`,{className:`fixed inset-0 z-10`,onClick:()=>d(!1)}),(0,K.jsxs)(`div`,{className:`absolute right-0 top-8 z-20 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl py-1 min-w-[120px]`,children:[(0,K.jsxs)(`button`,{className:`w-full px-3 py-2 text-left text-sm flex items-center gap-2 ${i(`projects:update`)?`text-white hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{i(`projects:update`)&&(n(),d(!1))},disabled:!i(`projects:update`),title:i(`projects:update`)?void 0:a(`projects.noEditPermission`),children:[(0,K.jsx)(_l,{className:`w-4 h-4`}),a(`common.edit`)]}),(0,K.jsxs)(`button`,{className:`w-full px-3 py-2 text-left text-sm flex items-center gap-2 ${i(`projects:delete`)?`text-red-600 dark:text-red-400 hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{i(`projects:delete`)&&(r(),d(!1))},disabled:!i(`projects:delete`),title:i(`projects:delete`)?void 0:a(`projects.noDeletePermission`),children:[(0,K.jsx)(xu,{className:`w-4 h-4`}),a(`common.delete`)]})]})]})]})]}),(0,K.jsx)(`div`,{className:`mb-4`,children:e.target_count||e.target_parts_count?(0,K.jsxs)(`div`,{className:`space-y-3`,children:[e.target_count&&(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between text-xs mb-1`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:a(`projects.plates`)}),(0,K.jsxs)(`span`,{className:o>=100?`text-bambu-green font-medium`:`text-white`,children:[e.archive_count,` / `,e.target_count]})]}),(0,K.jsx)(`div`,{className:`h-2 bg-bambu-dark/80 rounded-full overflow-hidden backdrop-blur-sm`,children:(0,K.jsx)(`div`,{className:`h-full transition-all duration-500 ease-out rounded-full relative`,style:{width:`${Math.min(o,100)}%`,background:o>=100?`linear-gradient(90deg, #22c55e, #4ade80)`:`linear-gradient(90deg, ${e.color||`#6b7280`}, ${e.color||`#6b7280`}cc)`,boxShadow:`0 0 8px ${o>=100?`#22c55e`:e.color||`#6b7280`}60`}})})]}),e.target_parts_count&&(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between text-xs mb-1`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:a(`projects.parts`)}),(0,K.jsxs)(`span`,{className:s>=100?`text-bambu-green font-medium`:`text-white`,children:[e.completed_count,` / `,e.target_parts_count]})]}),(0,K.jsx)(`div`,{className:`h-2 bg-bambu-dark/80 rounded-full overflow-hidden backdrop-blur-sm`,children:(0,K.jsx)(`div`,{className:`h-full transition-all duration-500 ease-out rounded-full relative`,style:{width:`${Math.min(s,100)}%`,background:s>=100?`linear-gradient(90deg, #22c55e, #4ade80)`:`linear-gradient(90deg, ${e.color||`#6b7280`}, ${e.color||`#6b7280`}cc)`,boxShadow:`0 0 8px ${s>=100?`#22c55e`:e.color||`#6b7280`}60`}})})]}),e.failed_count>0&&(0,K.jsxs)(`div`,{className:`text-xs text-red-600 dark:text-red-400`,children:[e.failed_count,` `,a(`projects.failed`)]})]}):e.completed_count>0||e.failed_count>0?(0,K.jsxs)(`div`,{className:`flex items-center gap-4 text-xs`,children:[e.completed_count>0&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 text-bambu-gray`,children:[(0,K.jsx)(Do,{className:`w-3.5 h-3.5`}),(0,K.jsxs)(`span`,{children:[e.completed_count,` `,a(`projects.completed`)]})]}),e.failed_count>0&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 text-red-600 dark:text-red-400`,children:[(0,K.jsx)(wu,{className:`w-3.5 h-3.5`}),(0,K.jsxs)(`span`,{children:[e.failed_count,` `,a(`projects.failed`)]})]}),e.queue_count>0&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 text-blue-600 dark:text-blue-400`,children:[(0,K.jsx)(bs,{className:`w-3.5 h-3.5`}),(0,K.jsxs)(`span`,{children:[e.queue_count,` `,a(`projects.inQueue`)]})]})]}):(0,K.jsx)(`div`,{className:`text-xs text-bambu-gray/60 italic`,children:a(`projects.noPrintsYet`)})}),e.archives&&e.archives.length>0&&(0,K.jsxs)(`div`,{className:`mb-4`,children:[(0,K.jsx)(`div`,{className:`grid grid-cols-4 gap-1.5`,children:e.archives.slice(0,4).map(e=>(0,K.jsxs)(`div`,{className:`relative aspect-square rounded-lg bg-bambu-dark overflow-hidden border border-bambu-dark-tertiary`,title:e.print_name||`Unknown`,children:[e.thumbnail_path?(0,K.jsx)(`img`,{src:Q.getArchiveThumbnail(e.id),alt:e.print_name||``,className:`w-full h-full object-cover`}):(0,K.jsx)(`div`,{className:`w-full h-full flex items-center justify-center text-bambu-gray/50`,children:(0,K.jsx)(fl,{className:`w-6 h-6`})}),e.status===`failed`&&(0,K.jsx)(`div`,{className:`absolute inset-0 bg-red-500/40 flex items-center justify-center`,children:(0,K.jsx)(wu,{className:`w-4 h-4 text-white`})})]},e.id))}),e.archive_count>4&&(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1.5 text-center`,children:a(`common.more`,{count:e.archive_count-4})})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between pt-3 border-t border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-4 text-xs text-bambu-gray`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5`,title:a(`projects.printJobs`),children:[(0,K.jsx)(Ic,{className:`w-3.5 h-3.5 text-blue-600 dark:text-blue-400`}),(0,K.jsxs)(`span`,{children:[e.archive_count,` `,a(`projects.plates`)]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5`,title:a(`projects.partsPrinted`),children:[(0,K.jsx)(fl,{className:`w-3.5 h-3.5 text-bambu-green`}),(0,K.jsxs)(`span`,{children:[e.completed_count,` `,a(`projects.parts`)]})]}),e.failed_count>0&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 text-red-600 dark:text-red-400`,title:a(`projects.failedParts`),children:[(0,K.jsx)(wu,{className:`w-3.5 h-3.5`}),(0,K.jsx)(`span`,{children:e.failed_count})]}),e.queue_count>0&&(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 text-yellow-600 dark:text-yellow-400`,title:a(`projects.inQueue`),children:[(0,K.jsx)(Hc,{className:`w-3.5 h-3.5`}),(0,K.jsx)(`span`,{children:e.queue_count})]})]}),(0,K.jsx)(rs,{className:`w-4 h-4 text-bambu-gray/50 group-hover:text-bambu-gray transition-colors`})]})]})]})}function rWe(){let{t:e}=W(),t=$n(),n=to(),{showToast:r}=kd(),{hasPermission:i}=hd(),[a,o]=(0,y.useState)(!1),[s,c]=(0,y.useState)(),[l,u]=(0,y.useState)(`active`),[d,f]=(0,y.useState)(null),{data:p}=q({queryKey:[`settings`],queryFn:Q.getSettings}),m=sf(p?.currency||`USD`),{data:h,isLoading:g}=q({queryKey:[`projects`,l===`all`?void 0:l],queryFn:()=>Q.getProjects(l===`all`?void 0:l)}),_=J({mutationFn:e=>Q.createProject(e),onSuccess:()=>{n.invalidateQueries({queryKey:[`projects`]}),o(!1),r(e(`projects.toast.created`),`success`)},onError:e=>{r(e.message,`error`)}}),v=J({mutationFn:({id:e,data:t})=>Q.updateProject(e,t),onSuccess:()=>{n.invalidateQueries({queryKey:[`projects`]}),o(!1),c(void 0),r(e(`projects.toast.updated`),`success`)},onError:e=>{r(e.message,`error`)}}),b=J({mutationFn:e=>Q.deleteProject(e),onSuccess:()=>{f(null),r(e(`projects.toast.deleted`),`success`),setTimeout(()=>window.location.reload(),100)},onError:e=>{f(null),r(e.message,`error`)}}),x=J({mutationFn:e=>Q.importProject(e),onSuccess:()=>{n.invalidateQueries({queryKey:[`projects`]}),r(e(`projects.toast.imported`),`success`)},onError:e=>{r(e.message,`error`)}}),S=(0,y.useRef)(null),C=async()=>{try{let t=await Q.getProjects(),n=await Promise.all(t.map(async e=>await Q.exportProjectJson(e.id))),i=new Blob([JSON.stringify(n,null,2)],{type:`application/json`}),a=URL.createObjectURL(i),o=document.createElement(`a`);o.href=a,o.download=`bambuddy_projects_${new Date().toISOString().split(`T`)[0]}.json`,o.click(),URL.revokeObjectURL(a),r(e(`projects.toast.exported`),`success`)}catch(e){r(e.message,`error`)}},w=()=>{S.current?.click()},T=async t=>{let i=t.target.files?.[0];if(i){try{if(i.name.toLowerCase().endsWith(`.zip`))await Q.importProjectFile(i),n.invalidateQueries({queryKey:[`projects`]}),r(e(`projects.toast.imported`),`success`);else{let t=await i.text(),n=JSON.parse(t),a=Array.isArray(n)?n:[n];for(let e of a)await x.mutateAsync(e);a.length>1&&r(e(`projects.toast.multipleImported`,{count:a.length}),`success`)}}catch(t){r(`${e(`projects.toast.importFailed`)}: ${t.message}`,`error`)}t.target.value=``}},E=e=>{s?v.mutate({id:s.id,data:e}):_.mutate(e)},D=e=>{c(e),o(!0)},O=e=>{t(`/projects/${e.id}`)},k=e=>{f(e)},A=()=>{d!==null&&b.mutate(d)},j=h?.reduce((e,t)=>(e[t.status]=(e[t.status]||0)+1,e.all=(e.all||0)+1,e),{})||{};return(0,K.jsxs)(`div`,{className:`p-4 md:p-8 space-y-8`,children:[(0,K.jsx)(`input`,{ref:S,type:`file`,accept:`.json,.zip`,onChange:T,className:`hidden`}),(0,K.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between gap-4`,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)(ac,{className:`w-7 h-7 text-bambu-green`}),e(`projects.title`)]}),(0,K.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:e(`projects.subtitle`)})]}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsxs)($,{variant:`secondary`,onClick:w,disabled:!i(`projects:create`),title:i(`projects:create`)?e(`projects.importProject`):e(`projects.noImportPermission`),children:[(0,K.jsx)(Ou,{className:`w-4 h-4 mr-2`}),e(`projects.import`)]}),(0,K.jsxs)($,{variant:`secondary`,onClick:C,disabled:!i(`projects:read`),title:i(`projects:read`)?e(`projects.exportAll`):e(`projects.noExportPermission`),children:[(0,K.jsx)(zs,{className:`w-4 h-4 mr-2`}),e(`projects.export`)]}),(0,K.jsxs)($,{onClick:()=>o(!0),className:`sm:w-auto w-full`,disabled:!i(`projects:create`),title:i(`projects:create`)?void 0:e(`projects.noCreatePermission`),children:[(0,K.jsx)(Cl,{className:`w-4 h-4 mr-2`}),e(`projects.newProject`)]})]})]}),(0,K.jsx)(`div`,{className:`flex gap-1 p-1 bg-bambu-dark rounded-xl w-fit`,children:[{key:`active`,label:e(`projects.statusActive`),icon:bs},{key:`completed`,label:e(`projects.statusCompleted`),icon:fs},{key:`archived`,label:e(`projects.statusArchived`),icon:Do},{key:`all`,label:e(`common.all`),icon:ac}].map(({key:e,label:t,icon:n})=>(0,K.jsxs)(`button`,{onClick:()=>u(e),className:`flex items-center gap-2 px-4 py-2 text-sm rounded-lg transition-all ${l===e?`bg-bambu-card text-white shadow-sm`:`text-bambu-gray hover:text-white`}`,children:[(0,K.jsx)(n,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{children:t}),j[e]>0&&(0,K.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded-full ${l===e?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark-tertiary`}`,children:j[e]})]},e))}),g?(0,K.jsx)(`div`,{className:`flex items-center justify-center py-20`,children:(0,K.jsxs)(`div`,{className:`flex flex-col items-center gap-3`,children:[(0,K.jsx)(X,{className:`w-8 h-8 animate-spin text-bambu-green`}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`projects.loading`)})]})}):h?.length===0?(0,K.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-20 px-4`,children:[(0,K.jsx)(`div`,{className:`p-4 bg-bambu-dark rounded-2xl mb-4`,children:(0,K.jsx)(ac,{className:`w-12 h-12 text-bambu-gray/50`})}),(0,K.jsx)(`h3`,{className:`text-lg font-medium text-white mb-2`,children:l===`all`?e(`projects.noProjects`):e(`projects.noProjectsFiltered`,{status:l})}),(0,K.jsx)(`p`,{className:`text-bambu-gray text-center max-w-md mb-6`,children:l===`all`?e(`projects.createFirst`):e(`projects.noProjectsFilteredHelp`,{status:l})}),l===`all`&&(0,K.jsxs)($,{onClick:()=>o(!0),disabled:!i(`projects:create`),title:i(`projects:create`)?void 0:e(`projects.noCreatePermission`),children:[(0,K.jsx)(Cl,{className:`w-4 h-4 mr-2`}),e(`projects.createFirstButton`)]})]}):(0,K.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-8`,children:h?.map(t=>(0,K.jsx)(nWe,{project:t,onClick:()=>O(t),onEdit:()=>D(t),onDelete:()=>k(t.id),hasPermission:i,t:e},t.id))}),d!==null&&(0,K.jsx)(Rd,{title:e(`projects.deleteProject`),message:e(`projects.deleteConfirm`),confirmText:e(`projects.deleteProject`),variant:`danger`,onConfirm:A,onCancel:()=>f(null)}),a&&(0,K.jsx)(L6,{project:s,onClose:()=>{o(!1),c(void 0)},onSave:E,isLoading:_.isPending||v.isPending,currencySymbol:m,t:e})]})}function iWe(e){let t=e.toLowerCase();return t.endsWith(`.gcode`)||t.endsWith(`.gcode.3mf`)}function aWe(e){return e>=1e3?`${(e/1e3).toFixed(2)}kg`:`${Math.round(e)}g`}function oWe({status:e,t}){let n={active:`bg-bambu-green/20 text-bambu-green`,completed:`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`,archived:`bg-bambu-gray/20 text-bambu-gray`},r=n[e]||n.active,i={active:t(`projectDetail.status.active`),completed:t(`projectDetail.status.completed`),archived:t(`projectDetail.status.archived`)};return(0,K.jsx)(`span`,{className:`px-2 py-1 rounded text-sm font-medium ${r}`,children:i[e]||e.charAt(0).toUpperCase()+e.slice(1)})}function R6({icon:e,label:t,value:n,subValue:r,hint:i,color:a=`text-bambu-gray`}){return(0,K.jsx)(xd,{children:(0,K.jsx)(Cd,{className:`p-4`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,title:i,children:[(0,K.jsx)(`div`,{className:`p-2 rounded-lg bg-bambu-dark ${a}`,children:(0,K.jsx)(e,{className:`w-5 h-5`})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:t}),(0,K.jsx)(`p`,{className:`text-xl font-semibold text-white`,children:n}),r&&(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray/70`,children:r})]})]})})})}function sWe({archives:e,t}){return e.length===0?(0,K.jsxs)(`div`,{className:`text-center py-8 text-bambu-gray`,children:[(0,K.jsx)(fl,{className:`w-12 h-12 mx-auto mb-2 opacity-50`}),(0,K.jsx)(`p`,{children:t(`projectDetail.noPrints`)})]}):(0,K.jsx)(`div`,{className:`grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 xl:grid-cols-6 gap-3`,children:e.map(e=>(0,K.jsxs)(Ci,{to:`/archives?search=${encodeURIComponent(e.print_name||``)}`,className:`group relative aspect-square rounded-lg bg-bambu-dark border border-bambu-dark-tertiary overflow-hidden hover:border-bambu-green transition-colors`,children:[e.thumbnail_path?(0,K.jsx)(`img`,{src:Q.getArchiveThumbnail(e.id),alt:e.print_name||`Print`,className:`w-full h-full object-cover`}):(0,K.jsx)(`div`,{className:`w-full h-full flex items-center justify-center text-bambu-gray`,children:(0,K.jsx)(fl,{className:`w-8 h-8`})}),e.status===`failed`&&(0,K.jsx)(`div`,{className:`absolute inset-0 bg-red-500/30 flex items-center justify-center`,children:(0,K.jsx)(_s,{className:`w-8 h-8 text-white`})}),e.status===`completed`&&(0,K.jsx)(`div`,{className:`absolute top-1 right-1`,children:(0,K.jsx)(ds,{className:`w-4 h-4 text-bambu-green`})}),(0,K.jsx)(`div`,{className:`absolute inset-x-0 bottom-0 bg-gradient-to-t from-black/80 to-transparent p-2 opacity-0 group-hover:opacity-100 transition-opacity`,children:(0,K.jsx)(`p`,{className:`text-xs text-white truncate`,children:e.print_name||`Unknown`})})]},e.id))})}function cWe({priority:e,t}){let n={low:{color:`bg-gray-500/20 text-gray-400`,label:t(`projectDetail.priority.low`)},normal:{color:`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`,label:t(`projectDetail.priority.normal`)},high:{color:`bg-orange-100 dark:bg-orange-500/20 text-orange-700 dark:text-orange-400`,label:t(`projectDetail.priority.high`)},urgent:{color:`bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400`,label:t(`projectDetail.priority.urgent`)}},{color:r,label:i}=n[e]||n.normal;return(0,K.jsxs)(`span`,{className:`px-2 py-1 rounded text-xs font-medium flex items-center gap-1 ${r}`,children:[e===`urgent`&&(0,K.jsx)(wu,{className:`w-3 h-3`}),i]})}function z6(e,t){if(!e)return null;let n=Tf(e);if(!n)return null;let r=new Date,i=Math.ceil((n.getTime()-r.getTime())/(1e3*60*60*24));return i<0?{color:`text-red-700 dark:text-red-400`,label:t(`projectDetail.dueDate.overdue`)}:i===0?{color:`text-orange-700 dark:text-orange-400`,label:t(`projectDetail.dueDate.today`)}:i<=3?{color:`text-yellow-700 dark:text-yellow-400`,label:t(`projectDetail.dueDate.daysLeft`,{count:i})}:{color:`text-bambu-gray`,label:t(`projectDetail.dueDate.daysLeft`,{count:i})}}function lWe(){let{id:e}=ir(),t=$n(),{t:n}=W(),r=to(),{showToast:i}=kd(),{hasPermission:a}=hd(),[o,s]=(0,y.useState)(!1),[c,l]=(0,y.useState)(!1),[u,d]=(0,y.useState)(``),[f,p]=(0,y.useState)(null),m=parseInt(e||`0`,10),{data:h,isLoading:g,error:_}=q({queryKey:[`project`,m],queryFn:()=>Q.getProject(m),enabled:m>0}),{data:v,isLoading:b}=q({queryKey:[`project-archives`,m],queryFn:()=>Q.getProjectArchives(m),enabled:m>0}),{data:x,isLoading:S}=q({queryKey:[`project-bom`,m],queryFn:()=>Q.getProjectBOM(m),enabled:m>0}),{data:C,isLoading:w}=q({queryKey:[`project-timeline`,m],queryFn:()=>Q.getProjectTimeline(m,20),enabled:m>0}),{data:T}=q({queryKey:[`settings`],queryFn:Q.getSettings}),{data:E}=q({queryKey:[`project-folders`,m],queryFn:()=>Q.getLibraryFoldersByProject(m),enabled:m>0}),{data:D,isLoading:O}=q({queryKey:[`project-files`,m],queryFn:()=>Q.getLibraryFiles(null,!1,m),enabled:m>0}),k=(0,y.useMemo)(()=>{let e=new Map;for(let t of D??[])if(t.folder_id!=null){let n=e.get(t.folder_id)??[];n.push(t),e.set(t.folder_id,n)}return e},[D]),A=sf(T?.currency||`USD`),j=T?.time_format||`system`,M=J({mutationFn:e=>Q.updateProject(m,e),onSuccess:()=>{r.invalidateQueries({queryKey:[`project`,m]}),r.invalidateQueries({queryKey:[`projects`]}),s(!1),l(!1),i(n(`projectDetail.toast.projectUpdated`),`success`)},onError:e=>{i(e.message,`error`)}}),N=()=>{d(h?.notes||``),l(!0)},P=()=>{M.mutate({notes:u})},F=()=>{l(!1),d(``)},[I,L]=(0,y.useState)(``),[R,z]=(0,y.useState)(1),[B,V]=(0,y.useState)(``),[ee,te]=(0,y.useState)(``),[ne,re]=(0,y.useState)(``),[ie,H]=(0,y.useState)(!1),[ae,oe]=(0,y.useState)(!1),[U,se]=(0,y.useState)(null),[ce,le]=(0,y.useState)(``),[ue,de]=(0,y.useState)(1),[fe,pe]=(0,y.useState)(``),[me,he]=(0,y.useState)(``),[ge,_e]=(0,y.useState)(``),[ve,ye]=(0,y.useState)({isOpen:!1,title:``,message:``,onConfirm:()=>{}}),be=J({mutationFn:e=>Q.createBOMItem(m,e),onSuccess:()=>{r.invalidateQueries({queryKey:[`project-bom`,m]}),r.invalidateQueries({queryKey:[`project`,m]}),L(``),z(1),V(``),te(``),re(``),H(!1),i(n(`projectDetail.toast.partAdded`),`success`)},onError:e=>i(e.message,`error`)}),xe=J({mutationFn:({itemId:e,data:t})=>Q.updateBOMItem(m,e,t),onSuccess:()=>{r.invalidateQueries({queryKey:[`project-bom`,m]}),r.invalidateQueries({queryKey:[`project`,m]}),se(null)},onError:e=>i(e.message,`error`)}),Se=J({mutationFn:e=>Q.deleteBOMItem(m,e),onSuccess:()=>{r.invalidateQueries({queryKey:[`project-bom`,m]}),r.invalidateQueries({queryKey:[`project`,m]}),i(n(`projectDetail.toast.partRemoved`),`success`)},onError:e=>i(e.message,`error`)}),Ce=e=>{e.preventDefault(),I.trim()&&be.mutate({name:I.trim(),quantity_needed:R,unit_price:B?parseFloat(B):void 0,sourcing_url:ee.trim()||void 0,remarks:ne.trim()||void 0})},we=e=>{let t=e.is_complete?0:e.quantity_needed;xe.mutate({itemId:e.id,data:{quantity_acquired:t}})},Te=(e,t)=>{ye({isOpen:!0,title:n(`projectDetail.bom.deletePart`),message:n(`projectDetail.bom.deleteConfirm`,{name:t}),onConfirm:()=>{ye(e=>({...e,isOpen:!1})),Se.mutate(e)}})},Ee=e=>{se(e),le(e.name),de(e.quantity_needed),pe(e.unit_price?.toString()||``),he(e.sourcing_url||``),_e(e.remarks||``)},De=e=>{e.preventDefault(),!(!U||!ce.trim())&&xe.mutate({itemId:U.id,data:{name:ce.trim(),quantity_needed:ue,unit_price:fe?parseFloat(fe):void 0,sourcing_url:me.trim()||void 0,remarks:ge.trim()||void 0}})},Oe=()=>{se(null)},ke=async()=>{try{let{blob:e,filename:t}=await Q.exportProjectZip(Number(m)),r=URL.createObjectURL(e),a=document.createElement(`a`);a.href=r,a.download=t||`${h?.name||`project`}_${new Date().toISOString().split(`T`)[0]}.zip`,a.click(),URL.revokeObjectURL(r),i(n(`projectDetail.toast.projectExported`),`success`)}catch(e){i(e.message,`error`)}},Ae=J({mutationFn:()=>Q.createTemplateFromProject(m),onSuccess:()=>{r.invalidateQueries({queryKey:[`projects`]}),i(n(`projectDetail.toast.templateCreated`),`success`)},onError:e=>i(e.message,`error`)}),je=e=>Df(e,j,{month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`});if(g)return(0,K.jsx)(`div`,{className:`flex items-center justify-center py-24`,children:(0,K.jsx)(X,{className:`w-8 h-8 animate-spin text-bambu-green`})});if(_||!h)return(0,K.jsxs)(`div`,{className:`text-center py-24`,children:[(0,K.jsx)(`p`,{className:`text-bambu-gray`,children:_?`${n(`common.error`)}: ${_.message}`:n(`projectDetail.notFound`)}),(0,K.jsx)($,{variant:`secondary`,className:`mt-4`,onClick:()=>t(`/projects`),children:n(`projectDetail.backToProjects`)})]});let Me=h.stats,Ne=Me?.progress_percent??0,Pe=Me?.parts_progress_percent??0;return(0,K.jsxs)(`div`,{className:`p-4 md:p-8 space-y-8`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-bambu-gray`,children:[(0,K.jsx)(Ci,{to:`/projects`,className:`hover:text-white transition-colors`,children:n(`nav.projects`)}),(0,K.jsx)(rs,{className:`w-4 h-4`}),(0,K.jsx)(`span`,{className:`text-white`,children:h.name})]}),(0,K.jsxs)(`div`,{className:`flex items-start justify-between`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,K.jsx)(`button`,{onClick:()=>t(`/projects`),className:`p-2 rounded-lg bg-bambu-card hover:bg-bambu-dark-tertiary transition-colors`,children:(0,K.jsx)(Ao,{className:`w-5 h-5 text-bambu-gray`})}),(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`w-4 h-4 rounded-full shrink-0`,style:{backgroundColor:h.color||`#6b7280`}}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h1`,{className:`text-2xl font-bold text-white`,children:h.name}),h.description&&(0,K.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:h.description})]})]}),(0,K.jsx)(oWe,{status:h.status,t:n})]}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsxs)($,{variant:`secondary`,onClick:ke,disabled:!a(`projects:read`),title:a(`projects:read`)?n(`projectDetail.exportProject`):n(`projectDetail.noExportPermission`),children:[(0,K.jsx)(zs,{className:`w-4 h-4 mr-2`}),n(`projectDetail.export`)]}),(0,K.jsxs)($,{onClick:()=>s(!0),disabled:!a(`projects:update`),title:a(`projects:update`)?void 0:n(`projectDetail.noEditPermission`),children:[(0,K.jsx)(_l,{className:`w-4 h-4 mr-2`}),n(`common.edit`)]})]})]}),(h.target_count||h.target_parts_count)&&(0,K.jsx)(xd,{children:(0,K.jsxs)(Cd,{className:`p-4 space-y-4`,children:[h.target_count&&(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:n(`projectDetail.progress.platesProgress`)}),(0,K.jsxs)(`span`,{className:`text-sm font-medium text-white`,children:[Me?.total_archives||0,` / `,h.target_count,` `,n(`projectDetail.progress.printJobs`)]})]}),(0,K.jsx)(`div`,{className:`h-3 bg-bambu-dark rounded-full overflow-hidden`,children:(0,K.jsx)(`div`,{className:`h-full transition-all duration-500`,style:{width:`${Math.min(Ne,100)}%`,backgroundColor:Ne>=100?`#22c55e`:h.color||`#6b7280`}})}),(0,K.jsxs)(`div`,{className:`flex justify-between mt-1`,children:[(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray/70`,children:n(`projectDetail.progress.percentComplete`,{percent:Ne.toFixed(0)})}),Me?.remaining_prints!=null&&Me.remaining_prints>0&&(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray/70`,children:n(`projectDetail.progress.remaining`,{count:Me.remaining_prints})})]})]}),h.target_parts_count&&(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,K.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:n(`projectDetail.progress.partsProgress`)}),(0,K.jsxs)(`span`,{className:`text-sm font-medium text-white`,children:[Me?.completed_prints||0,` / `,h.target_parts_count,` `,n(`projectDetail.progress.parts`)]})]}),(0,K.jsx)(`div`,{className:`h-3 bg-bambu-dark rounded-full overflow-hidden`,children:(0,K.jsx)(`div`,{className:`h-full transition-all duration-500`,style:{width:`${Math.min(Pe,100)}%`,backgroundColor:Pe>=100?`#22c55e`:h.color||`#6b7280`}})}),(0,K.jsxs)(`div`,{className:`flex justify-between mt-1`,children:[(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray/70`,children:n(`projectDetail.progress.percentComplete`,{percent:Pe.toFixed(0)})}),Me?.remaining_parts!=null&&Me.remaining_parts>0&&(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray/70`,children:n(`projectDetail.progress.remaining`,{count:Me.remaining_parts})})]})]})]})}),Me&&(0,K.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-4`,children:[(0,K.jsx)(xd,{children:(0,K.jsx)(Cd,{className:`p-4`,children:(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`p-2 rounded-lg bg-bambu-dark text-bambu-green`,children:(0,K.jsx)(fl,{className:`w-5 h-5`})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`projectDetail.stats.printJobs`)}),(0,K.jsxs)(`p`,{className:`text-xl font-semibold text-white`,children:[Me.total_archives,` `,(0,K.jsx)(`span`,{className:`text-sm font-normal text-bambu-gray`,children:n(`projectDetail.stats.total`)})]}),Me.failed_prints>0&&(0,K.jsx)(`p`,{className:`text-sm text-status-error`,children:n(`projectDetail.stats.failed`,{count:Me.failed_prints})}),(0,K.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`projectDetail.stats.partsPrinted`,{count:Me.completed_prints})})]})]})})}),(0,K.jsx)(R6,{icon:bs,label:n(`projectDetail.stats.printTime`),value:Nf(Me.total_print_time_hours),color:`text-yellow-600 dark:text-yellow-400`}),(0,K.jsx)(R6,{icon:El,label:n(`projectDetail.stats.filamentUsed`),value:aWe(Me.total_filament_grams),color:`text-purple-600 dark:text-purple-400`})]}),Me&&(()=>{let e=Me.estimated_cost+Me.total_energy_cost+Me.bom_cost;return Me.estimated_cost>0||e>0||h.budget!==null})()&&(0,K.jsx)(xd,{children:(0,K.jsxs)(Cd,{className:`p-4`,children:[(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white mb-3`,children:n(`projectDetail.cost.title`)}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-4`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.cost.filamentCost`)}),(0,K.jsxs)(`p`,{className:`text-lg font-semibold text-white`,children:[A,Me.estimated_cost.toFixed(2)]})]}),Me.total_energy_kwh>0&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.cost.energy`)}),(0,K.jsxs)(`p`,{className:`text-lg font-semibold text-white`,children:[Me.total_energy_kwh.toFixed(3),` kWh`,Me.total_energy_cost>0&&(0,K.jsxs)(`span`,{className:`text-sm text-bambu-gray ml-1`,children:[`(`,A,Me.total_energy_cost.toFixed(2),`)`]})]})]}),(()=>{let e=Me.estimated_cost+Me.total_energy_cost+Me.bom_cost;return e<=0?null:(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.cost.totalCost`)}),(0,K.jsxs)(`p`,{className:`text-lg font-semibold text-bambu-green`,children:[A,e.toFixed(2)]}),Me.bom_cost>0&&(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray/70`,children:n(`projectDetail.cost.includesBom`)})]})})(),h.budget!==null&&(()=>{let e=Me.estimated_cost+Me.total_energy_cost+Me.bom_cost,t=h.budget-e;return(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.cost.budget`)}),(0,K.jsxs)(`p`,{className:`text-sm text-bambu-gray`,children:[n(`projectDetail.cost.total`),`: `,(0,K.jsxs)(`span`,{className:`text-white font-semibold`,children:[A,h.budget.toFixed(2)]})]}),(0,K.jsxs)(`p`,{className:`text-sm ${t>=0?`text-bambu-green`:`text-red-700 dark:text-red-400`}`,children:[n(`projectDetail.cost.remaining`),`: `,(0,K.jsxs)(`span`,{className:`font-semibold`,children:[A,t.toFixed(2)]})]})]})})()]})]})}),h.children&&h.children.length>0&&(0,K.jsx)(xd,{children:(0,K.jsxs)(Cd,{className:`p-4`,children:[(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2 mb-3`,children:[(0,K.jsx)(lc,{className:`w-5 h-5`}),n(`projectDetail.subProjects.title`,{count:h.children.length})]}),(0,K.jsx)(`div`,{className:`space-y-2`,children:h.children.map(e=>(0,K.jsxs)(Ci,{to:`/projects/${e.id}`,className:`flex items-center justify-between p-3 bg-bambu-dark rounded-lg hover:bg-bambu-dark-tertiary transition-colors`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,K.jsx)(`div`,{className:`w-3 h-3 rounded-full`,style:{backgroundColor:e.color||`#6b7280`}}),(0,K.jsx)(`span`,{className:`text-white`,children:e.name}),(0,K.jsx)(`span`,{className:`text-xs px-2 py-0.5 rounded ${e.status===`completed`?`bg-status-ok/20 text-status-ok`:e.status===`archived`?`bg-bambu-gray/20 text-bambu-gray`:`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`}`,children:e.status})]}),e.progress_percent!==null&&(0,K.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[e.progress_percent.toFixed(0),`%`]})]},e.id))})]})}),h.parent_id&&h.parent_name&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,K.jsx)(Ic,{className:`w-4 h-4 text-bambu-gray`}),(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:n(`projectDetail.partOf`)}),(0,K.jsx)(Ci,{to:`/projects/${h.parent_id}`,className:`text-bambu-green hover:underline`,children:h.parent_name})]}),(h.tags||h.due_date||h.priority!==`normal`)&&(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4`,children:[h.priority&&h.priority!==`normal`&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray uppercase`,children:n(`projectDetail.priorityLabel`)}),(0,K.jsx)(cWe,{priority:h.priority,t:n})]}),h.due_date&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(Yo,{className:`w-4 h-4 text-bambu-gray`}),(0,K.jsx)(`span`,{className:`text-sm text-white`,children:Ef(h.due_date,{year:`numeric`,month:`short`,day:`numeric`})}),z6(h.due_date,n)&&(0,K.jsxs)(`span`,{className:`text-xs ${z6(h.due_date,n).color}`,children:[`(`,z6(h.due_date,n).label,`)`]})]}),h.tags&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(pu,{className:`w-4 h-4 text-bambu-gray`}),(0,K.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:h.tags.split(`,`).map((e,t)=>(0,K.jsx)(`span`,{className:`px-2 py-0.5 bg-bambu-dark-tertiary text-bambu-gray text-xs rounded`,children:e.trim()},t))})]})]}),(0,K.jsx)(xd,{children:(0,K.jsxs)(Cd,{className:`p-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(ec,{className:`w-5 h-5`}),n(`projectDetail.notes.title`)]}),c?(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:F,disabled:M.isPending,children:[(0,K.jsx)(Hu,{className:`w-4 h-4 mr-1`}),n(`common.cancel`)]}),(0,K.jsxs)($,{size:`sm`,onClick:P,disabled:M.isPending,children:[M.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin mr-1`}):(0,K.jsx)(Pl,{className:`w-4 h-4 mr-1`}),n(`common.save`)]})]}):(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:N,disabled:!a(`projects:update`),title:a(`projects:update`)?void 0:n(`projectDetail.notes.noEditPermission`),children:[(0,K.jsx)(_l,{className:`w-4 h-4 mr-1`}),n(`common.edit`)]})]}),c?(0,K.jsx)(Q0,{content:u,onChange:d,placeholder:n(`projectDetail.notes.placeholder`)}):h.notes?(0,K.jsx)(`div`,{className:`prose prose-invert prose-sm max-w-none`,dangerouslySetInnerHTML:{__html:UG.sanitize(h.notes)}}):(0,K.jsx)(`p`,{className:`text-bambu-gray/70 text-sm italic`,children:n(`projectDetail.notes.empty`)})]})}),(0,K.jsx)(xd,{children:(0,K.jsxs)(Cd,{className:`p-4`,children:[(0,K.jsx)(`div`,{className:`flex items-center justify-between mb-3`,children:(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(oc,{className:`w-5 h-5`}),n(`projectDetail.files.title`)]})}),(0,K.jsxs)(`p`,{className:`text-xs text-bambu-gray mb-3`,children:[(0,K.jsx)(Ci,{to:`/files`,className:`text-bambu-green hover:underline`,children:n(`projectDetail.files.linkFolders`)}),` `,n(`projectDetail.files.forQuickAccess`)]}),E&&E.length>0?(0,K.jsx)(`div`,{className:`space-y-4`,children:E.map(e=>{let t=k.get(e.id)??[],r=O;return(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(Ci,{to:`/files?folder=${e.id}`,className:`flex items-center justify-between p-3 bg-bambu-dark rounded-lg hover:bg-bambu-dark-tertiary transition-colors mb-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0`,children:[(0,K.jsx)(oc,{className:`w-5 h-5 text-bambu-green shrink-0`}),(0,K.jsxs)(`div`,{className:`min-w-0`,children:[(0,K.jsx)(`p`,{className:`text-sm text-white truncate`,children:e.name}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`projectDetail.files.fileCount`,{count:e.file_count})})]})]}),(0,K.jsx)(rs,{className:`w-4 h-4 text-bambu-gray shrink-0`})]}),r?(0,K.jsx)(`div`,{className:`flex items-center gap-2 px-3 py-2 text-bambu-gray text-sm`,children:(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`})}):t.length===0?(0,K.jsx)(`p`,{className:`text-bambu-gray/60 text-xs italic px-3`,children:n(`projectDetail.files.noFiles`)}):(0,K.jsx)(`div`,{className:`space-y-1 pl-3`,children:t.map(e=>{let t=iWe(e.filename);return(0,K.jsxs)(`div`,{className:`flex items-center gap-3 p-2 rounded-lg hover:bg-bambu-dark-tertiary transition-colors`,children:[(0,K.jsx)(`div`,{className:`w-10 h-10 shrink-0 rounded bg-bambu-dark overflow-hidden flex items-center justify-center`,children:e.thumbnail_path?(0,K.jsx)(`img`,{src:Q.getLibraryFileThumbnailUrl(e.id),alt:e.print_name||e.filename,className:`w-full h-full object-cover`}):(0,K.jsx)(Xs,{className:`w-5 h-5 text-bambu-gray/40`})}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsx)(`p`,{className:`text-sm text-white truncate`,title:e.print_name||e.filename,children:e.print_name||e.filename}),(0,K.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded font-medium ${e.file_type===`3mf`?`bg-bambu-green/20 text-bambu-green`:e.file_type===`gcode`||e.file_type===`gcode.3mf`?`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`:`bg-bambu-gray/20 text-bambu-gray`}`,children:e.file_type.toUpperCase()})]}),t&&(0,K.jsx)(`div`,{className:`flex items-center gap-1 shrink-0`,children:(0,K.jsx)(`button`,{onClick:()=>p(e),title:n(`common.print`),className:`p-1.5 rounded hover:bg-bambu-green/20 text-bambu-green transition-colors`,children:(0,K.jsx)(El,{className:`w-4 h-4`})})})]},e.id)})})]},e.id)})}):(0,K.jsx)(`p`,{className:`text-bambu-gray/70 text-sm italic`,children:n(`projectDetail.files.empty`)})]})}),(0,K.jsx)(xd,{children:(0,K.jsxs)(Cd,{className:`p-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-4`,children:[(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(Yl,{className:`w-5 h-5`}),n(`projectDetail.bom.title`),Me&&Me.bom_total_items>0&&(0,K.jsxs)(`span`,{className:`text-sm font-normal text-bambu-gray`,children:[`(`,n(`projectDetail.bom.acquired`,{completed:Me.bom_completed_items,total:Me.bom_total_items}),`)`]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[x&&x.some(e=>e.is_complete)&&(0,K.jsx)(`button`,{onClick:()=>oe(!ae),className:`text-xs px-2 py-1 rounded transition-colors ${ae?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark text-bambu-gray hover:text-white`}`,children:n(ae?`projectDetail.bom.showAll`:`projectDetail.bom.hideDone`)}),!ie&&(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:()=>H(!0),disabled:!a(`projects:update`),title:a(`projects:update`)?void 0:n(`projectDetail.bom.noAddPermission`),children:[(0,K.jsx)(Cl,{className:`w-4 h-4 mr-1`}),n(`projectDetail.bom.addPart`)]})]})]}),ie&&(0,K.jsxs)(`form`,{onSubmit:Ce,className:`bg-bambu-dark rounded-lg p-4 mb-4 space-y-3`,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-3`,children:[(0,K.jsx)(`input`,{type:`text`,value:I,onChange:e=>L(e.target.value),className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:n(`projectDetail.bom.partNamePlaceholder`),autoFocus:!0}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)(`input`,{type:`number`,value:R,onChange:e=>z(parseInt(e.target.value)||1),className:`w-20 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white focus:outline-none focus:border-bambu-green`,min:`1`,placeholder:n(`projectDetail.bom.qty`)}),(0,K.jsx)(`input`,{type:`number`,step:`0.01`,value:B,onChange:e=>V(e.target.value),className:`flex-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:n(`projectDetail.bom.price`,{currency:A})})]})]}),(0,K.jsx)(`input`,{type:`url`,value:ee,onChange:e=>te(e.target.value),className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:n(`projectDetail.bom.sourcingUrlPlaceholder`)}),(0,K.jsx)(`input`,{type:`text`,value:ne,onChange:e=>re(e.target.value),className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:n(`projectDetail.bom.remarksPlaceholder`)}),(0,K.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,K.jsx)($,{type:`button`,variant:`secondary`,size:`sm`,onClick:()=>H(!1),children:n(`common.cancel`)}),(0,K.jsx)($,{type:`submit`,size:`sm`,disabled:!I.trim()||be.isPending,children:be.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):n(`projectDetail.bom.addPart`)})]})]}),S?(0,K.jsx)(`div`,{className:`flex items-center justify-center py-4`,children:(0,K.jsx)(X,{className:`w-6 h-6 animate-spin text-bambu-green`})}):x&&x.length>0?(0,K.jsxs)(`div`,{className:`space-y-2`,children:[x.filter(e=>!ae||!e.is_complete).map(e=>(0,K.jsx)(`div`,{className:`p-3 rounded-lg transition-colors ${e.is_complete?`bg-status-ok/10`:`bg-bambu-dark`}`,children:U?.id===e.id?(0,K.jsxs)(`form`,{onSubmit:De,className:`space-y-3`,children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-3`,children:[(0,K.jsx)(`input`,{type:`text`,value:ce,onChange:e=>le(e.target.value),className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:n(`projectDetail.bom.partName`),autoFocus:!0}),(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsx)(`input`,{type:`number`,value:ue,onChange:e=>de(parseInt(e.target.value)||1),className:`w-20 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white focus:outline-none focus:border-bambu-green`,min:`1`,placeholder:n(`projectDetail.bom.qty`)}),(0,K.jsx)(`input`,{type:`number`,step:`0.01`,value:fe,onChange:e=>pe(e.target.value),className:`flex-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:n(`projectDetail.bom.price`,{currency:A})})]})]}),(0,K.jsx)(`input`,{type:`url`,value:me,onChange:e=>he(e.target.value),className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:n(`projectDetail.bom.sourcingUrlPlaceholder`)}),(0,K.jsx)(`input`,{type:`text`,value:ge,onChange:e=>_e(e.target.value),className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded px-3 py-2 text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:n(`projectDetail.bom.remarksPlaceholder`)}),(0,K.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,K.jsx)($,{type:`button`,variant:`secondary`,size:`sm`,onClick:Oe,children:n(`common.cancel`)}),(0,K.jsx)($,{type:`submit`,size:`sm`,disabled:!ce.trim()||xe.isPending,children:xe.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):n(`common.save`)})]})]}):(0,K.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,K.jsx)(`button`,{onClick:()=>a(`projects:update`)&&we(e),disabled:xe.isPending||!a(`projects:update`),title:a(`projects:update`)?void 0:n(`projectDetail.bom.noUpdatePermission`),className:`w-5 h-5 mt-0.5 rounded border-2 flex items-center justify-center transition-colors shrink-0 ${e.is_complete?`bg-status-ok border-status-ok text-white`:a(`projects:update`)?`border-bambu-gray hover:border-bambu-green`:`border-bambu-gray/50 cursor-not-allowed`}`,children:e.is_complete&&(0,K.jsx)(ds,{className:`w-3 h-3`})}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,K.jsxs)(`p`,{className:`text-sm font-medium ${e.is_complete?`text-bambu-gray line-through`:`text-white`}`,children:[e.name,(0,K.jsxs)(`span`,{className:`text-bambu-gray font-normal ml-2`,children:[`x`,e.quantity_needed]})]}),e.unit_price!==null&&(0,K.jsxs)(`span`,{className:`text-xs text-bambu-green whitespace-nowrap`,children:[A,(e.unit_price*e.quantity_needed).toFixed(2)]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(`button`,{onClick:()=>a(`projects:update`)&&Ee(e),disabled:!a(`projects:update`),className:`p-1 rounded transition-colors shrink-0 ${a(`projects:update`)?`hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white`:`text-bambu-gray/50 cursor-not-allowed`}`,title:a(`projects:update`)?n(`common.edit`):n(`projectDetail.bom.noEditPermission`),children:(0,K.jsx)(yl,{className:`w-4 h-4`})}),(0,K.jsx)(`button`,{onClick:()=>a(`projects:update`)&&Te(e.id,e.name),disabled:!a(`projects:update`),className:`p-1 rounded transition-colors shrink-0 ${a(`projects:update`)?`hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-red-400`:`text-bambu-gray/50 cursor-not-allowed`}`,title:a(`projects:update`)?n(`common.delete`):n(`projectDetail.bom.noDeletePermission`),children:(0,K.jsx)(xu,{className:`w-4 h-4`})})]})]}),e.sourcing_url&&(0,K.jsxs)(`a`,{href:e.sourcing_url,target:`_blank`,rel:`noopener noreferrer`,className:`flex items-center gap-1 mt-1 text-xs text-blue-700 dark:text-blue-400 hover:text-blue-900 dark:hover:text-blue-300 transition-colors`,onClick:e=>e.stopPropagation(),children:[(0,K.jsx)(Ks,{className:`w-3 h-3 shrink-0`}),(0,K.jsx)(`span`,{className:`truncate`,children:(()=>{try{return new URL(e.sourcing_url).hostname.replace(`www.`,``)}catch{return e.sourcing_url}})()})]}),e.remarks&&(0,K.jsx)(`p`,{className:`mt-1 text-xs text-bambu-gray/80 italic`,children:e.remarks})]})]})},e.id)),Me&&Me.bom_cost>0&&(0,K.jsxs)(`div`,{className:`pt-2 mt-2 border-t border-bambu-dark-tertiary flex justify-between text-sm`,children:[(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:n(`projectDetail.bom.totalCost`)}),(0,K.jsxs)(`span`,{className:`text-white font-medium`,children:[A,Me.bom_cost.toFixed(2)]})]})]}):(0,K.jsx)(`p`,{className:`text-bambu-gray/70 text-sm italic`,children:n(`projectDetail.bom.empty`)})]})}),(0,K.jsx)(xd,{children:(0,K.jsxs)(Cd,{className:`p-4`,children:[(0,K.jsx)(`div`,{className:`flex items-center justify-between mb-3`,children:(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(Dc,{className:`w-5 h-5`}),n(`projectDetail.timeline.title`)]})}),w?(0,K.jsx)(`div`,{className:`flex items-center justify-center py-4`,children:(0,K.jsx)(X,{className:`w-6 h-6 animate-spin text-bambu-green`})}):C&&C.length>0?(0,K.jsx)(`div`,{className:`space-y-3`,children:C.slice(0,10).map((e,t)=>(0,K.jsxs)(`div`,{className:`flex gap-3`,children:[(0,K.jsxs)(`div`,{className:`w-8 h-8 rounded-full flex items-center justify-center shrink-0 ${e.event_type===`print_completed`?`bg-status-ok/20 text-status-ok`:e.event_type===`print_failed`?`bg-status-error/20 text-status-error`:e.event_type===`print_started`?`bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400`:`bg-bambu-dark-tertiary text-bambu-gray`}`,children:[e.event_type===`print_completed`&&(0,K.jsx)(ds,{className:`w-4 h-4`}),e.event_type===`print_failed`&&(0,K.jsx)(_s,{className:`w-4 h-4`}),e.event_type===`print_started`&&(0,K.jsx)(El,{className:`w-4 h-4`}),e.event_type===`queued`&&(0,K.jsx)(Hc,{className:`w-4 h-4`}),e.event_type===`project_created`&&(0,K.jsx)(Cl,{className:`w-4 h-4`})]}),(0,K.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,K.jsx)(`p`,{className:`text-sm text-white`,children:e.title}),e.description&&(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray truncate`,children:e.description}),(0,K.jsx)(`p`,{className:`text-xs text-bambu-gray/70`,children:je(e.timestamp)})]})]},t))}):(0,K.jsx)(`p`,{className:`text-bambu-gray/70 text-sm italic`,children:n(`projectDetail.timeline.empty`)})]})}),!h.is_template&&(0,K.jsx)(`div`,{className:`flex justify-end`,children:(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:()=>Ae.mutate(),disabled:Ae.isPending||!a(`projects:create`),title:a(`projects:create`)?void 0:n(`projectDetail.template.noCreatePermission`),children:[Ae.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin mr-2`}):(0,K.jsx)(As,{className:`w-4 h-4 mr-2`}),n(`projectDetail.template.saveAsTemplate`)]})}),Me&&(Me.queued_prints>0||Me.in_progress_prints>0)&&(0,K.jsx)(xd,{children:(0,K.jsxs)(Cd,{className:`p-4`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(Hc,{className:`w-5 h-5`}),n(`projectDetail.queue.title`)]}),(0,K.jsx)(Ci,{to:`/queue?project=${m}`,className:`text-sm text-bambu-green hover:underline`,children:n(`projectDetail.queue.viewAll`)})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-4 text-sm`,children:[Me.in_progress_prints>0&&(0,K.jsx)(`span`,{className:`text-yellow-700 dark:text-yellow-400`,children:n(`projectDetail.queue.printing`,{count:Me.in_progress_prints})}),Me.queued_prints>0&&(0,K.jsx)(`span`,{className:`text-bambu-gray`,children:n(`projectDetail.queue.queued`,{count:Me.queued_prints})})]})]})}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`div`,{className:`flex items-center justify-between mb-4`,children:(0,K.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(fl,{className:`w-5 h-5`}),n(`projectDetail.prints.title`,{count:v?.length||0})]})}),b?(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-green`})}):(0,K.jsx)(sWe,{archives:v||[],t:n})]}),o&&(0,K.jsx)(L6,{t:n,currencySymbol:A,project:{...h,archive_count:Me?.total_archives||0,total_items:Me?.total_items||0,completed_count:Me?.completed_prints||0,failed_count:Me?.failed_prints||0,queue_count:Me?.queued_prints||0,progress_percent:Me?.progress_percent||null,archives:[]},onClose:()=>s(!1),onSave:e=>M.mutate(e),isLoading:M.isPending}),ve.isOpen&&(0,K.jsx)(Rd,{title:ve.title,message:ve.message,confirmText:n(`common.delete`),variant:`danger`,onConfirm:ve.onConfirm,onCancel:()=>ye(e=>({...e,isOpen:!1}))}),f&&(0,K.jsx)(oW,{mode:`create`,libraryFileId:f.id,archiveName:f.print_name||f.filename,projectId:m,onClose:()=>p(null),onSuccess:()=>{p(null),r.invalidateQueries({queryKey:[`archives`]}),r.invalidateQueries({queryKey:[`queue`]})}})]})}function uWe({archiveId:e,libraryFileId:t,title:n,fileType:r,onClose:i,onSliceWithBambuddy:a}){let{t:o}=W(),{data:s}=q({queryKey:[`settings`],queryFn:Q.getSettings}),c=s?.open_in_slicer||s?.preferred_slicer||`bambu_studio`,l=t!=null,[u,d]=(0,y.useState)(null),[f,p]=(0,y.useState)(null),[m,h]=(0,y.useState)(!0),[g,_]=(0,y.useState)(null),[v,b]=(0,y.useState)(!1),[x,S]=(0,y.useState)(null),[C,w]=(0,y.useState)(0),[T,E]=(0,y.useState)(!1),[D,O]=(0,y.useState)(null),[k,A]=(0,y.useState)(!1),[j,M]=(0,y.useState)(!1),N=(0,y.useRef)(null),P=(0,y.useRef)(null),F=.35;(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&i()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[i]),(0,y.useEffect)(()=>{if(h(!0),l){let e=(r||``).toLowerCase(),t=e===`3mf`||e===`gcode.3mf`,n=t||e===`stl`,i=t||e===`gcode`;p({has_model:n,has_gcode:i,has_source:!1,build_volume:{x:256,y:256,z:256},filament_colors:[]}),d(n?`3d`:i?`gcode`:null),h(!1);return}if(!e){p(null),d(null),h(!1);return}Q.getArchiveCapabilities(e).then(e=>{p(e),e.has_model?d(`3d`):e.has_gcode&&d(`gcode`),h(!1)}).catch(()=>{p({has_model:!0,has_gcode:!1,has_source:!1,build_volume:{x:256,y:256,z:256},filament_colors:[]}),d(`3d`),h(!1)})},[e,r,l]),(0,y.useEffect)(()=>{if(b(!0),S(null),w(0),l){let e=(r||``).toLowerCase();if(!t||!(e===`3mf`||e===`gcode.3mf`)){_(null),b(!1);return}Q.getLibraryFilePlates(t).then(e=>_(e)).catch(()=>_(null)).finally(()=>b(!1));return}if(!e){_(null),b(!1);return}Q.getArchivePlates(e).then(e=>_(e)).catch(()=>_(null)).finally(()=>b(!1))},[e,r,l,t]);let I=(0,y.useMemo)(()=>g?.plates??[],[g]),L=(g?.is_multi_plate??!1)&&I.length>1,R=T&&L,z=x==null?null:I.find(e=>e.index===x)??null,B=e=>e.object_count??e.objects?.length??0,V=I.reduce((e,t)=>e+B(t),0),ee=z?B(z):V,te=z?o(`modelViewer.plateNumber`,{number:z.index}):o(`modelViewer.allPlates`),ne=I.length>0,re=(0,y.useRef)(null),ie=(0,y.useRef)(null),[H,ae]=(0,y.useState)(10),[oe,U]=(0,y.useState)(3),se=I.length>H,ce=Math.max(1,Math.ceil(I.length/H)),le=se?I.slice(C*H,(C+1)*H):I;(0,y.useEffect)(()=>{if(!R){ae(10),U(3);return}let e=re.current,t=ie.current;if(!e||!t)return;let n=0,r=()=>{let n=t.clientWidth,r=Math.floor(n/210),i=Math.max(3,Math.min(5,r||3));U(e=>e===i?e:i);let a=window.getComputedStyle(e),o=Number.parseFloat(a.rowGap||`0`),s=e.querySelector(`button`)?.getBoundingClientRect().height??44,c=t.clientHeight,l=Math.max(1,Math.floor((c+o)/(s+o)))*i,u=Math.max(1,l-1);ae(e=>e===u?e:u)},i=()=>{n&&cancelAnimationFrame(n),n=requestAnimationFrame(r)};i();let a=new ResizeObserver(i);return a.observe(t),a.observe(e),()=>{n&&cancelAnimationFrame(n),a.disconnect()}},[R,I.length]),(0,y.useEffect)(()=>{if(!se){w(0);return}w(e=>Math.min(e,ce-1))},[I.length,se,ce]),(0,y.useEffect)(()=>{if(!se||x==null)return;let e=I.findIndex(e=>e.index===x);if(e<0)return;let t=Math.floor(e/H);w(e=>e===t?e:t)},[I,H,x,se]),(0,y.useEffect)(()=>{if(!R){O(null),M(!1);return}if(j)return;let e=N.current,t=P.current;if(!e||!t)return;let n=e.clientHeight;if(!n)return;let r=Math.max(240,n*F),i=Math.max(160,n-10-r),a=Math.min(t.scrollHeight,i);O(Math.max(160,a))},[R,j,I.length,C,10,160,240,F]),(0,y.useEffect)(()=>{if(!k)return;let e=e=>{let t=N.current;if(!t)return;let n=t.getBoundingClientRect(),r=n.height;if(!r)return;let i=Math.max(240,r*F),a=Math.max(160,r-10-i);O(Math.min(a,Math.max(160,e.clientY-n.top)))},t=()=>{A(!1),M(!0)};return document.addEventListener(`mousemove`,e),document.addEventListener(`mouseup`,t),document.body.style.cursor=`row-resize`,document.body.style.userSelect=`none`,()=>{document.removeEventListener(`mousemove`,e),document.removeEventListener(`mouseup`,t),document.body.style.cursor=``,document.body.style.userSelect=``}},[k,10,160,240,F]);let ue=l?(r||``).toLowerCase()===`3mf`:!0,de=(()=>{let e=(r||``).toLowerCase();return e===`3mf`||e===`stl`||e===`step`||e===`stp`})(),fe=!!(l&&s?.use_slicer_api&&a&&de);return(0,K.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 ${T?`p-0`:`p-8`}`,onClick:i,children:(0,K.jsxs)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary w-full flex flex-col ${T?`h-full max-w-none rounded-none`:`h-[80vh] max-w-4xl rounded-xl`}`,onClick:e=>e.stopPropagation(),children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 flex-1 mr-4`,children:[(0,K.jsx)(`h2`,{className:`text-lg font-semibold text-white truncate`,children:n}),ne&&(0,K.jsxs)(`span`,{className:`text-xs text-bambu-gray bg-bambu-dark-tertiary/70 px-2 py-1 rounded whitespace-nowrap`,children:[te,`: `,o(`modelViewer.objectCount`,{count:ee})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[fe?(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:a,children:[(0,K.jsx)(Ds,{className:`w-4 h-4`}),o(`slice.action`)]}):(0,K.jsxs)($,{variant:`secondary`,size:`sm`,onClick:async()=>{if(!ue)return;let r=n||`model`;try{if(l){let{token:e}=await Q.createLibrarySlicerToken(t),n=Q.getLibrarySlicerDownloadUrl(t,e,r);UW(`${window.location.origin}${n}`,c)}else{let{token:t}=await Q.createArchiveSlicerToken(e),n=Q.getArchiveSlicerDownloadUrl(e,t,r);UW(`${window.location.origin}${n}`,c)}}catch{UW(l?`${window.location.origin}${Q.getLibraryFileDownloadUrl(t)}`:`${window.location.origin}${Q.getArchiveForSlicer(e,r)}`,c)}},disabled:!ue,children:[(0,K.jsx)(Ks,{className:`w-4 h-4`}),o(`modelViewer.openInSlicer`)]}),(0,K.jsx)($,{variant:`secondary`,size:`sm`,onClick:()=>E(e=>!e),title:T?`Exit fullscreen`:`Enter fullscreen`,children:T?(0,K.jsx)(tl,{className:`w-4 h-4`}):(0,K.jsx)(Zc,{className:`w-4 h-4`})}),(0,K.jsx)($,{variant:`ghost`,size:`sm`,onClick:i,children:(0,K.jsx)(Hu,{className:`w-5 h-5`})})]})]}),f&&(0,K.jsxs)(`div`,{className:`flex border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`button`,{onClick:()=>f.has_model&&d(`3d`),disabled:!f.has_model,className:`flex items-center gap-2 px-6 py-3 text-sm font-medium transition-colors ${u===`3d`?`text-bambu-green border-b-2 border-bambu-green`:f.has_model?`text-bambu-gray hover:text-white`:`text-bambu-gray/30 cursor-not-allowed`}`,children:[(0,K.jsx)(Uo,{className:`w-4 h-4`}),o(`modelViewer.tabs.model`),!f.has_model&&(0,K.jsxs)(`span`,{className:`text-xs`,children:[`(`,o(`modelViewer.notAvailable`),`)`]})]}),(0,K.jsxs)(`button`,{onClick:()=>f.has_gcode&&d(`gcode`),disabled:!f.has_gcode,className:`flex items-center gap-2 px-6 py-3 text-sm font-medium transition-colors ${u===`gcode`?`text-bambu-green border-b-2 border-bambu-green`:f.has_gcode?`text-bambu-gray hover:text-white`:`text-bambu-gray/30 cursor-not-allowed`}`,children:[(0,K.jsx)(Cs,{className:`w-4 h-4`}),o(`modelViewer.tabs.gcode`),!f.has_gcode&&(0,K.jsxs)(`span`,{className:`text-xs`,children:[`(`,o(`modelViewer.notSliced`),`)`]})]})]}),(0,K.jsx)(`div`,{className:`flex-1 overflow-hidden p-4`,children:m?(0,K.jsx)(`div`,{className:`w-full h-full flex items-center justify-center`,children:(0,K.jsx)(X,{className:`w-8 h-8 animate-spin text-bambu-green`})}):u===`3d`&&f?(0,K.jsxs)(`div`,{ref:N,className:`w-full h-full flex flex-col ${R?`gap-0 min-h-0`:`gap-3`}`,children:[L&&(0,K.jsxs)(`div`,{ref:P,style:R&&D!=null?{height:D}:void 0,className:`rounded-lg border border-bambu-dark-tertiary bg-bambu-dark p-3 ${R?`flex flex-col shrink-0`:``}`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-bambu-gray mb-2`,children:[(0,K.jsx)(Ic,{className:`w-4 h-4`}),o(`modelViewer.plates`),v&&(0,K.jsx)(X,{className:`w-3 h-3 animate-spin`})]}),(0,K.jsxs)(`div`,{className:R?`flex flex-col min-h-0 flex-1`:void 0,children:[(0,K.jsx)(`div`,{ref:ie,className:R?`min-h-0 overflow-hidden pr-1 flex-1`:void 0,children:(0,K.jsxs)(`div`,{ref:re,className:R?`grid gap-2`:`grid grid-cols-2 md:grid-cols-3 gap-2`,style:R?{gridTemplateColumns:`repeat(${oe}, minmax(0, 1fr))`}:void 0,children:[(0,K.jsxs)(`button`,{type:`button`,onClick:()=>S(null),className:`flex items-center rounded-lg border text-left transition-colors ${R?`gap-1.5 p-1.5 w-full`:`gap-2 p-2`} ${x==null?`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary bg-bambu-dark-secondary hover:border-bambu-gray`}`,children:[(0,K.jsx)(`div`,{className:`rounded bg-bambu-dark-tertiary flex items-center justify-center ${R?`w-8 h-8`:`w-10 h-10`}`,children:(0,K.jsx)(Ic,{className:`${R?`w-4 h-4`:`w-5 h-5`} text-bambu-gray`})}),(0,K.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,K.jsx)(`p`,{className:`${R?`text-xs`:`text-sm`} text-white font-medium truncate`,children:o(`modelViewer.allPlates`)}),(0,K.jsx)(`p`,{className:`${R?`text-[10px]`:`text-xs`} text-bambu-gray truncate`,children:o(`modelViewer.plateCount`,{count:I.length})})]}),x==null&&(0,K.jsx)(ts,{className:`${R?`w-3.5 h-3.5`:`w-4 h-4`} text-bambu-green flex-shrink-0`})]}),le.map(e=>(0,K.jsxs)(`button`,{type:`button`,onClick:()=>S(e.index),className:`flex items-center rounded-lg border text-left transition-colors ${R?`gap-1.5 p-1.5 w-full`:`gap-2 p-2`} ${x===e.index?`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary bg-bambu-dark-secondary hover:border-bambu-gray`}`,children:[e.has_thumbnail&&e.thumbnail_url?(0,K.jsx)(`img`,{src:e.thumbnail_url,alt:`Plate ${e.index}`,className:`${R?`w-8 h-8`:`w-10 h-10`} rounded object-cover bg-bambu-dark-tertiary`}):(0,K.jsx)(`div`,{className:`rounded bg-bambu-dark-tertiary flex items-center justify-center ${R?`w-8 h-8`:`w-10 h-10`}`,children:(0,K.jsx)(Ic,{className:`${R?`w-4 h-4`:`w-5 h-5`} text-bambu-gray`})}),(0,K.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,K.jsx)(`p`,{className:`${R?`text-xs`:`text-sm`} text-white font-medium truncate`,children:e.name||o(`modelViewer.plateNumber`,{number:e.index})}),(0,K.jsx)(`p`,{className:`${R?`text-[10px]`:`text-xs`} text-bambu-gray truncate`,children:o(`modelViewer.objectCount`,{count:e.object_count??e.objects?.length??0})})]}),x===e.index&&(0,K.jsx)(ts,{className:`${R?`w-3.5 h-3.5`:`w-4 h-4`} text-bambu-green flex-shrink-0`})]},e.index))]})}),(z||se)&&(0,K.jsxs)(`div`,{className:`mt-auto pt-3 flex items-center gap-4 text-xs text-bambu-gray overflow-x-auto`,children:[z&&(0,K.jsxs)(`div`,{className:`flex items-center gap-3 whitespace-nowrap`,children:[(0,K.jsx)(`span`,{children:o(`modelViewer.plateNumber`,{number:z.index})}),z.print_time_seconds!=null&&(0,K.jsx)(`span`,{children:o(`modelViewer.eta`,{minutes:Math.round(z.print_time_seconds/60)})}),z.filament_used_grams!=null&&(0,K.jsxs)(`span`,{children:[z.filament_used_grams.toFixed(1),` g`]}),z.filaments.length>0&&(0,K.jsx)(`span`,{children:o(`modelViewer.filamentCount`,{count:z.filaments.length})})]}),se&&(0,K.jsxs)(`div`,{className:`flex items-center gap-2 whitespace-nowrap ${z?`ml-auto`:``}`,children:[(0,K.jsx)(`span`,{children:o(`modelViewer.pagination.pageOf`,{current:C+1,total:ce})}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(`button`,{type:`button`,onClick:()=>w(e=>Math.max(e-1,0)),disabled:C===0,className:`px-2 py-1 rounded border text-xs ${C===0?`border-bambu-dark-tertiary text-bambu-gray/40 cursor-not-allowed`:`border-bambu-dark-tertiary text-bambu-gray hover:text-white hover:border-bambu-gray`}`,children:o(`modelViewer.pagination.prev`)}),(()=>{let e=Math.max(0,C-2),t=Math.min(ce,e+5);t-e<5&&(e=Math.max(0,t-5));let n=Array.from({length:t-e},(t,n)=>e+n);return(0,K.jsxs)(K.Fragment,{children:[e>0&&(0,K.jsx)(`button`,{type:`button`,onClick:()=>w(0),className:`px-2 py-1 rounded border text-xs ${C===0?`border-bambu-green text-bambu-green`:`border-bambu-dark-tertiary text-bambu-gray hover:text-white hover:border-bambu-gray`}`,children:`1`}),e>1&&(0,K.jsx)(`span`,{className:`px-1`,children:`…`}),n.map(e=>(0,K.jsx)(`button`,{type:`button`,onClick:()=>w(e),className:`px-2 py-1 rounded border text-xs ${C===e?`border-bambu-green text-bambu-green`:`border-bambu-dark-tertiary text-bambu-gray hover:text-white hover:border-bambu-gray`}`,children:e+1},e)),tw(ce-1),className:`px-2 py-1 rounded border text-xs ${C===ce-1?`border-bambu-green text-bambu-green`:`border-bambu-dark-tertiary text-bambu-gray hover:text-white hover:border-bambu-gray`}`,children:ce})]})})(),(0,K.jsx)(`button`,{type:`button`,onClick:()=>w(e=>Math.min(e+1,ce-1)),disabled:C>=ce-1,className:`px-2 py-1 rounded border text-xs ${C>=ce-1?`border-bambu-dark-tertiary text-bambu-gray/40 cursor-not-allowed`:`border-bambu-dark-tertiary text-bambu-gray hover:text-white hover:border-bambu-gray`}`,children:o(`modelViewer.pagination.next`)})]})]})]})]})]}),R&&(0,K.jsx)(`div`,{role:`separator`,"aria-orientation":`horizontal`,onMouseDown:e=>{e.preventDefault(),A(!0),M(!0)},className:`h-2 cursor-row-resize flex items-center justify-center ${k?`bg-bambu-dark-tertiary`:`bg-bambu-dark-secondary/60 hover:bg-bambu-dark-tertiary`}`,children:(0,K.jsx)(`div`,{className:`w-12 h-1 rounded-full bg-bambu-gray/50`})}),(0,K.jsx)(`div`,{className:`flex-1 ${R?`min-h-0`:``}`,children:(0,K.jsx)(gy,{url:l?Q.getLibraryFileDownloadUrl(t):f.has_source?Q.getSource3mfDownloadUrl(e):Q.getArchiveDownload(e),fileType:r,buildVolume:f.build_volume,filamentColors:f.filament_colors,selectedPlateId:x,className:`w-full h-full`})})]}):u===`gcode`&&f?(0,K.jsx)(dT,{gcodeUrl:l?Q.getLibraryFileGcodeUrl(t):Q.getArchiveGcode(e),filamentColors:f.filament_colors,className:`w-full h-full`}):(0,K.jsx)(`div`,{className:`w-full h-full flex items-center justify-center text-bambu-gray`,children:o(`modelViewer.noPreview`)})})]})})}var B6=[`library-tags`];function dWe({open:e,fileIds:t,onClose:n}){let{t:r}=W(),i=to(),{showToast:a}=kd(),[o,s]=(0,y.useState)(`add`),[c,l]=(0,y.useState)(new Set),[u,d]=(0,y.useState)(``),[f,p]=(0,y.useState)(``);(0,y.useEffect)(()=>{e||(s(`add`),l(new Set),d(``),p(``))},[e]);let{data:m=[],isLoading:h}=q({queryKey:B6,queryFn:Q.getLibraryTags,enabled:e}),g=(0,y.useMemo)(()=>{let e=u.trim().toLowerCase();return e?m.filter(t=>t.name.toLowerCase().includes(e)):m},[m,u]),_=e=>{l(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},v=J({mutationFn:e=>Q.createLibraryTag(e),onSuccess:e=>{l(t=>new Set(t).add(e.id)),p(``),i.invalidateQueries({queryKey:B6})},onError:e=>{a(e.message||r(`fileManager.tags.saveFailed`),`error`)}}),b=J({mutationFn:()=>Q.bulkAssignLibraryTags(t,Array.from(c),o),onSuccess:e=>{a(o===`add`?r(`fileManager.tags.applyAddSuccess`,{count:e.associations_added,files:e.files_updated}):r(`fileManager.tags.applyRemoveSuccess`,{count:e.associations_removed,files:e.files_updated}),`success`),i.invalidateQueries({queryKey:[`library-files`]}),i.invalidateQueries({queryKey:B6}),n()},onError:e=>{a(e.message||r(`fileManager.tags.applyFailed`),`error`)}});if((0,y.useEffect)(()=>{if(!e)return;let t=e=>{e.key===`Escape`&&!b.isPending&&!v.isPending&&n()};return document.addEventListener(`keydown`,t),()=>document.removeEventListener(`keydown`,t)},[e,n,b.isPending,v.isPending]),!e)return null;let x=!f.trim()||v.isPending||m.some(e=>e.name.toLowerCase()===f.trim().toLowerCase()),S=`bulk-tags-picker-title`;return(0,K.jsxs)(`div`,{className:`fixed inset-0 z-[60] flex items-center justify-center`,children:[(0,K.jsx)(`div`,{className:`absolute inset-0 bg-black/60`,onClick:()=>!b.isPending&&n()}),(0,K.jsxs)(`div`,{className:`relative w-full max-w-md mx-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl shadow-2xl max-h-[90vh] flex flex-col`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":S,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between gap-4 px-5 py-4 border-b border-bambu-dark-tertiary`,children:[(0,K.jsxs)(`h3`,{id:S,className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,K.jsx)(pu,{className:`w-4 h-4 text-bambu-green`}),r(`fileManager.tags.bulkTitle`,{count:t.length})]}),(0,K.jsx)(`button`,{type:`button`,className:`p-1.5 text-bambu-gray hover:text-white rounded`,onClick:n,"aria-label":r(`common.close`),children:(0,K.jsx)(Hu,{className:`w-5 h-5`})})]}),(0,K.jsxs)(`div`,{className:`px-5 py-3 border-b border-bambu-dark-tertiary flex gap-4 text-sm`,children:[(0,K.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`radio`,name:`bulk-action`,checked:o===`add`,onChange:()=>s(`add`),className:`accent-bambu-green`}),(0,K.jsx)(`span`,{className:`text-white`,children:r(`fileManager.tags.actionAdd`)})]}),(0,K.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`radio`,name:`bulk-action`,checked:o===`remove`,onChange:()=>s(`remove`),className:`accent-bambu-green`}),(0,K.jsx)(`span`,{className:`text-white`,children:r(`fileManager.tags.actionRemove`)})]})]}),(0,K.jsx)(`div`,{className:`px-5 py-3 border-b border-bambu-dark-tertiary`,children:(0,K.jsx)(`input`,{type:`text`,value:u,onChange:e=>d(e.target.value),placeholder:r(`fileManager.tags.searchPlaceholder`),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`})}),(0,K.jsx)(`div`,{className:`overflow-y-auto flex-1 min-h-[8rem] max-h-[24rem]`,children:h?(0,K.jsxs)(`div`,{className:`flex items-center justify-center py-12 text-bambu-gray`,children:[(0,K.jsx)(X,{className:`w-5 h-5 animate-spin mr-2`}),r(`common.loading`)]}):g.length===0?(0,K.jsx)(`div`,{className:`py-12 text-center text-bambu-gray text-sm`,children:m.length===0?r(`fileManager.tags.empty`):r(`fileManager.tags.noMatches`)}):(0,K.jsx)(`ul`,{className:`divide-y divide-bambu-dark-tertiary/40`,children:g.map(e=>(0,K.jsx)(`li`,{children:(0,K.jsxs)(`label`,{className:`flex items-center gap-3 px-5 py-2 hover:bg-bambu-dark-tertiary/30 cursor-pointer`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:c.has(e.id),onChange:()=>_(e.id),className:`accent-bambu-green`}),(0,K.jsx)(`span`,{className:`text-sm text-white truncate flex-1`,children:e.name}),(0,K.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:e.file_count})]})},e.id))})}),o===`add`&&(0,K.jsxs)(`div`,{className:`px-5 py-3 border-t border-bambu-dark-tertiary flex gap-2`,children:[(0,K.jsx)(`input`,{type:`text`,value:f,onChange:e=>p(e.target.value),placeholder:r(`fileManager.tags.createPlaceholder`),maxLength:64,className:`flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,onKeyDown:e=>{e.key===`Enter`&&!x&&(e.preventDefault(),v.mutate(f.trim()))}}),(0,K.jsxs)($,{type:`button`,variant:`secondary`,onClick:()=>v.mutate(f.trim()),disabled:x,children:[v.isPending?(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}):(0,K.jsx)(Cl,{className:`w-4 h-4`}),r(`fileManager.tags.createButton`)]})]}),(0,K.jsxs)(`div`,{className:`px-5 py-4 border-t border-bambu-dark-tertiary flex justify-end gap-2`,children:[(0,K.jsx)($,{type:`button`,variant:`secondary`,onClick:n,disabled:b.isPending,children:r(`common.cancel`)}),(0,K.jsxs)($,{type:`button`,onClick:()=>b.mutate(),disabled:c.size===0||b.isPending||t.length===0,children:[b.isPending&&(0,K.jsx)(X,{className:`w-4 h-4 animate-spin`}),r(o===`add`?`fileManager.tags.applyAdd`:`fileManager.tags.applyRemove`)]})]})]})]})}function fWe(e,t){let n=t||{};return(e[e.length-1]===``?[...e,``]:e).join((n.padRight?` `:``)+`,`+(n.padLeft===!1?``:` `)).trim()}var pWe=/^[$_\p{ID_Start}][$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,mWe=/^[$_\p{ID_Start}][-$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,hWe={};function V6(e,t){return((t||hWe).jsx?mWe:pWe).test(e)}var gWe=/[ \t\n\f\r]/g;function _We(e){return typeof e==`object`?e.type===`text`?H6(e.value):!1:H6(e)}function H6(e){return e.replace(gWe,``)===``}var U6=class{constructor(e,t,n){this.normal=t,this.property=e,n&&(this.space=n)}};U6.prototype.normal={},U6.prototype.property={},U6.prototype.space=void 0;function W6(e,t){let n={},r={};for(let t of e)Object.assign(n,t.property),Object.assign(r,t.normal);return new U6(n,r,t)}function G6(e){return e.toLowerCase()}var K6=class{constructor(e,t){this.attribute=t,this.property=e}};K6.prototype.attribute=``,K6.prototype.booleanish=!1,K6.prototype.boolean=!1,K6.prototype.commaOrSpaceSeparated=!1,K6.prototype.commaSeparated=!1,K6.prototype.defined=!1,K6.prototype.mustUseProperty=!1,K6.prototype.number=!1,K6.prototype.overloadedBoolean=!1,K6.prototype.property=``,K6.prototype.spaceSeparated=!1,K6.prototype.space=void 0;var q6=s({boolean:()=>J6,booleanish:()=>Y6,commaOrSpaceSeparated:()=>e8,commaSeparated:()=>$6,number:()=>Z6,overloadedBoolean:()=>X6,spaceSeparated:()=>Q6}),vWe=0,J6=t8(),Y6=t8(),X6=t8(),Z6=t8(),Q6=t8(),$6=t8(),e8=t8();function t8(){return 2**++vWe}var n8=Object.keys(q6),r8=class extends K6{constructor(e,t,n,r){let i=-1;if(super(e,t),i8(this,`space`,r),typeof n==`number`)for(;++i4&&n.slice(0,4)===`data`&&CWe.test(t)){if(t.charAt(4)===`-`){let e=t.slice(5).replace(f8,EWe);r=`data`+e.charAt(0).toUpperCase()+e.slice(1)}else{let e=t.slice(4);if(!f8.test(e)){let n=e.replace(SWe,TWe);n.charAt(0)!==`-`&&(n=`-`+n),t=`data`+n}}i=r8}return new i(r,t)}function TWe(e){return`-`+e.toLowerCase()}function EWe(e){return e.charAt(1).toUpperCase()}var DWe=W6([o8,yWe,l8,u8,d8],`html`),p8=W6([o8,bWe,l8,u8,d8],`svg`);function OWe(e){return e.join(` `).trim()}var kWe=o(((e,t)=>{var n=/\/\*[^*]*\*+([^/*][^*]*\*+)*\//g,r=/\n/g,i=/^\s*/,a=/^(\*?[-#/*\\\w]+(\[[0-9a-z_-]+\])?)\s*/,o=/^:\s*/,s=/^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^)]*?\)|[^};])+)/,c=/^[;\s]*/,l=/^\s+|\s+$/g,u=` `,d=`/`,f=`*`,p=``,m=`comment`,h=`declaration`;function g(e,t){if(typeof e!=`string`)throw TypeError(`First argument must be a string`);if(!e)return[];t||={};var l=1,g=1;function v(e){var t=e.match(r);t&&(l+=t.length);var n=e.lastIndexOf(u);g=~n?e.length-n:g+e.length}function y(){var e={line:l,column:g};return function(t){return t.position=new b(e),C(),t}}function b(e){this.start=e,this.end={line:l,column:g},this.source=t.source}b.prototype.content=e;function x(n){var r=Error(t.source+`:`+l+`:`+g+`: `+n);if(r.reason=n,r.filename=t.source,r.line=l,r.column=g,r.source=e,!t.silent)throw r}function S(t){var n=t.exec(e);if(n){var r=n[0];return v(r),e=e.slice(r.length),n}}function C(){S(i)}function w(e){var t;for(e||=[];t=T();)t!==!1&&e.push(t);return e}function T(){var t=y();if(!(d!=e.charAt(0)||f!=e.charAt(1))){for(var n=2;p!=e.charAt(n)&&(f!=e.charAt(n)||d!=e.charAt(n+1));)++n;if(n+=2,p===e.charAt(n-1))return x(`End of comment missing`);var r=e.slice(2,n-2);return g+=2,v(r),e=e.slice(n),g+=2,t({type:m,comment:r})}}function E(){var e=y(),t=S(a);if(t){if(T(),!S(o))return x(`property missing ':'`);var r=S(s),i=e({type:h,property:_(t[0].replace(n,p)),value:r?_(r[0].replace(n,p)):p});return S(c),i}}function D(){var e=[];w(e);for(var t;t=E();)t!==!1&&(e.push(t),w(e));return e}return C(),D()}function _(e){return e?e.replace(l,p):p}t.exports=g})),AWe=o((e=>{var t=e&&e.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(e,"__esModule",{value:!0}),e.default=r;var n=t(kWe());function r(e,t){let r=null;if(!e||typeof e!=`string`)return r;let i=(0,n.default)(e),a=typeof t==`function`;return i.forEach(e=>{if(e.type!==`declaration`)return;let{property:n,value:i}=e;a?t(n,i,e):i&&(r||={},r[n]=i)}),r}})),jWe=o((e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.camelCase=void 0;var t=/^--[a-zA-Z0-9_-]+$/,n=/-([a-z])/g,r=/^[^-]+$/,i=/^-(webkit|moz|ms|o|khtml)-/,a=/^-(ms)-/,o=function(e){return!e||r.test(e)||t.test(e)},s=function(e,t){return t.toUpperCase()},c=function(e,t){return`${t}-`};e.camelCase=function(e,t){return t===void 0&&(t={}),o(e)?e:(e=e.toLowerCase(),e=t.reactCompat?e.replace(a,c):e.replace(i,c),e.replace(n,s))}})),MWe=o(((e,t)=>{var n=(e&&e.__importDefault||function(e){return e&&e.__esModule?e:{default:e}})(AWe()),r=jWe();function i(e,t){var i={};return!e||typeof e!=`string`||(0,n.default)(e,function(e,n){e&&n&&(i[(0,r.camelCase)(e,t)]=n)}),i}i.default=i,t.exports=i})),m8=g8(`end`),h8=g8(`start`);function g8(e){return t;function t(t){let n=t&&t.position&&t.position[e]||{};if(typeof n.line==`number`&&n.line>0&&typeof n.column==`number`&&n.column>0)return{line:n.line,column:n.column,offset:typeof n.offset==`number`&&n.offset>-1?n.offset:void 0}}}function NWe(e){let t=h8(e),n=m8(e);if(t&&n)return{start:t,end:n}}function _8(e){return!e||typeof e!=`object`?``:`position`in e||`type`in e?y8(e.position):`start`in e||`end`in e?y8(e):`line`in e||`column`in e?v8(e):``}function v8(e){return b8(e&&e.line)+`:`+b8(e&&e.column)}function y8(e){return v8(e&&e.start)+`-`+v8(e&&e.end)}function b8(e){return e&&typeof e==`number`?e:1}var x8=class extends Error{constructor(e,t,n){super(),typeof t==`string`&&(n=t,t=void 0);let r=``,i={},a=!1;if(t&&(i=`line`in t&&`column`in t||`start`in t&&`end`in t?{place:t}:`type`in t?{ancestors:[t],place:t.position}:{...t}),typeof e==`string`?r=e:!i.cause&&e&&(a=!0,r=e.message,i.cause=e),!i.ruleId&&!i.source&&typeof n==`string`){let e=n.indexOf(`:`);e===-1?i.ruleId=n:(i.source=n.slice(0,e),i.ruleId=n.slice(e+1))}if(!i.place&&i.ancestors&&i.ancestors){let e=i.ancestors[i.ancestors.length-1];e&&(i.place=e.position)}let o=i.place&&`start`in i.place?i.place.start:i.place;this.ancestors=i.ancestors||void 0,this.cause=i.cause||void 0,this.column=o?o.column:void 0,this.fatal=void 0,this.file=``,this.message=r,this.line=o?o.line:void 0,this.name=_8(i.place)||`1:1`,this.place=i.place||void 0,this.reason=this.message,this.ruleId=i.ruleId||void 0,this.source=i.source||void 0,this.stack=a&&i.cause&&typeof i.cause.stack==`string`?i.cause.stack:``,this.actual=void 0,this.expected=void 0,this.note=void 0,this.url=void 0}};x8.prototype.file=``,x8.prototype.name=``,x8.prototype.reason=``,x8.prototype.message=``,x8.prototype.stack=``,x8.prototype.column=void 0,x8.prototype.line=void 0,x8.prototype.ancestors=void 0,x8.prototype.cause=void 0,x8.prototype.fatal=void 0,x8.prototype.place=void 0,x8.prototype.ruleId=void 0,x8.prototype.source=void 0;var PWe=l(MWe(),1),S8={}.hasOwnProperty,FWe=new Map,IWe=/[A-Z]/g,LWe=new Set([`table`,`tbody`,`thead`,`tfoot`,`tr`]),RWe=new Set([`td`,`th`]);function zWe(e,t){if(!t||t.Fragment===void 0)throw TypeError("Expected `Fragment` in options");let n=t.filePath||void 0,r;if(t.development){if(typeof t.jsxDEV!=`function`)throw TypeError("Expected `jsxDEV` in options when `development: true`");r=qWe(n,t.jsxDEV)}else{if(typeof t.jsx!=`function`)throw TypeError("Expected `jsx` in production options");if(typeof t.jsxs!=`function`)throw TypeError("Expected `jsxs` in production options");r=KWe(n,t.jsx,t.jsxs)}let i={Fragment:t.Fragment,ancestors:[],components:t.components||{},create:r,elementAttributeNameCase:t.elementAttributeNameCase||`react`,evaluater:t.createEvaluater?t.createEvaluater():void 0,filePath:n,ignoreInvalidStyle:t.ignoreInvalidStyle||!1,passKeys:t.passKeys!==!1,passNode:t.passNode||!1,schema:t.space===`svg`?p8:DWe,stylePropertyNameCase:t.stylePropertyNameCase||`dom`,tableCellAlignToStyle:t.tableCellAlignToStyle!==!1},a=C8(i,e,void 0);return a&&typeof a!=`string`?a:i.create(e,i.Fragment,{children:a||void 0},void 0)}function C8(e,t,n){if(t.type===`element`)return BWe(e,t,n);if(t.type===`mdxFlowExpression`||t.type===`mdxTextExpression`)return VWe(e,t);if(t.type===`mdxJsxFlowElement`||t.type===`mdxJsxTextElement`)return UWe(e,t,n);if(t.type===`mdxjsEsm`)return HWe(e,t);if(t.type===`root`)return WWe(e,t,n);if(t.type===`text`)return GWe(e,t)}function BWe(e,t,n){let r=e.schema,i=r;t.tagName.toLowerCase()===`svg`&&r.space===`html`&&(i=p8,e.schema=i),e.ancestors.push(t);let a=D8(e,t.tagName,!1),o=JWe(e,t),s=E8(e,t);return LWe.has(t.tagName)&&(s=s.filter(function(e){return typeof e==`string`?!_We(e):!0})),w8(e,o,a,t),T8(o,s),e.ancestors.pop(),e.schema=r,e.create(t,a,o,n)}function VWe(e,t){if(t.data&&t.data.estree&&e.evaluater){let n=t.data.estree.body[0];return n.type,e.evaluater.evaluateExpression(n.expression)}O8(e,t.position)}function HWe(e,t){if(t.data&&t.data.estree&&e.evaluater)return e.evaluater.evaluateProgram(t.data.estree);O8(e,t.position)}function UWe(e,t,n){let r=e.schema,i=r;t.name===`svg`&&r.space===`html`&&(i=p8,e.schema=i),e.ancestors.push(t);let a=t.name===null?e.Fragment:D8(e,t.name,!0),o=YWe(e,t),s=E8(e,t);return w8(e,o,a,t),T8(o,s),e.ancestors.pop(),e.schema=r,e.create(t,a,o,n)}function WWe(e,t,n){let r={};return T8(r,E8(e,t)),e.create(t,e.Fragment,r,n)}function GWe(e,t){return t.value}function w8(e,t,n,r){typeof n!=`string`&&n!==e.Fragment&&e.passNode&&(t.node=r)}function T8(e,t){if(t.length>0){let n=t.length>1?t:t[0];n&&(e.children=n)}}function KWe(e,t,n){return r;function r(e,r,i,a){let o=Array.isArray(i.children)?n:t;return a?o(r,i,a):o(r,i)}}function qWe(e,t){return n;function n(n,r,i,a){let o=Array.isArray(i.children),s=h8(n);return t(r,i,a,o,{columnNumber:s?s.column-1:void 0,fileName:e,lineNumber:s?s.line:void 0},void 0)}}function JWe(e,t){let n={},r,i;for(i in t.properties)if(i!==`children`&&S8.call(t.properties,i)){let a=XWe(e,i,t.properties[i]);if(a){let[i,o]=a;e.tableCellAlignToStyle&&i===`align`&&typeof o==`string`&&RWe.has(t.tagName)?r=o:n[i]=o}}if(r){let t=n.style||={};t[e.stylePropertyNameCase===`css`?`text-align`:`textAlign`]=r}return n}function YWe(e,t){let n={};for(let r of t.attributes)if(r.type===`mdxJsxExpressionAttribute`)if(r.data&&r.data.estree&&e.evaluater){let t=r.data.estree.body[0];t.type;let i=t.expression;i.type;let a=i.properties[0];a.type,Object.assign(n,e.evaluater.evaluateExpression(a.argument))}else O8(e,t.position);else{let i=r.name,a;if(r.value&&typeof r.value==`object`)if(r.value.data&&r.value.data.estree&&e.evaluater){let t=r.value.data.estree.body[0];t.type,a=e.evaluater.evaluateExpression(t.expression)}else O8(e,t.position);else a=r.value===null?!0:r.value;n[i]=a}return n}function E8(e,t){let n=[],r=-1,i=e.passKeys?new Map:FWe;for(;++ri?0:i+t:t>i?i:t,n=n>0?n:0,r.length<1e4)o=Array.from(r),o.unshift(t,n),e.splice(...o);else for(n&&e.splice(t,n);a0?(F8(e,e.length,0,t),e):t}var L8={}.hasOwnProperty;function R8(e){let t={},n=-1;for(;++n13&&n<32||n>126&&n<160||n>55295&&n<57344||n>64975&&n<65008||(n&65535)==65535||(n&65535)==65534||n>1114111?`�`:String.fromCodePoint(n)}function B8(e){return e.replace(/[\t\n\r ]+/g,` `).replace(/^ | $/g,``).toLowerCase().toUpperCase()}var V8=X8(/[A-Za-z]/),H8=X8(/[\dA-Za-z]/),aGe=X8(/[#-'*+\--9=?A-Z^-~]/);function U8(e){return e!==null&&(e<32||e===127)}var W8=X8(/\d/),oGe=X8(/[\dA-Fa-f]/),sGe=X8(/[!-/:-@[-`{-~]/);function G8(e){return e!==null&&e<-2}function K8(e){return e!==null&&(e<0||e===32)}function q8(e){return e===-2||e===-1||e===32}var J8=X8(/\p{P}|\p{S}/u),Y8=X8(/\s/);function X8(e){return t;function t(t){return t!==null&&t>-1&&e.test(String.fromCharCode(t))}}function Z8(e){let t=[],n=-1,r=0,i=0;for(;++n55295&&a<57344){let t=e.charCodeAt(n+1);a<56320&&t>56319&&t<57344?(o=String.fromCharCode(a,t),i=1):o=`�`}else o=String.fromCharCode(a);o&&=(t.push(e.slice(r,n),encodeURIComponent(o)),r=n+i+1,``),i&&=(n+=i,0)}return t.join(``)+e.slice(r)}function Q8(e,t,n,r){let i=r?r-1:1/0,a=0;return o;function o(r){return q8(r)?(e.enter(n),s(r)):t(r)}function s(r){return q8(r)&&a++o))return;let n=t.events.length,a=n,s,c;for(;a--;)if(t.events[a][0]===`exit`&&t.events[a][1].type===`chunkFlow`){if(s){c=t.events[a][1].end;break}s=!0}for(_(r),e=n;er;){let r=n[i];t.containerState=r[1],r[0].exit.call(t,e)}n.length=r}function v(){i.write([null]),a=void 0,i=void 0,t.containerState._closeFlow=void 0}}function fGe(e,t,n){return Q8(e,e.attempt(this.parser.constructs.document,t,n),`linePrefix`,this.parser.constructs.disable.null.includes(`codeIndented`)?void 0:4)}function e5(e){if(e===null||K8(e)||Y8(e))return 1;if(J8(e))return 2}function t5(e,t,n){let r=[],i=-1;for(;++i1&&e[n][1].end.offset-e[n][1].start.offset>1?2:1;let d={...e[r][1].end},f={...e[n][1].start};r5(d,-c),r5(f,c),o={type:c>1?`strongSequence`:`emphasisSequence`,start:d,end:{...e[r][1].end}},s={type:c>1?`strongSequence`:`emphasisSequence`,start:{...e[n][1].start},end:f},a={type:c>1?`strongText`:`emphasisText`,start:{...e[r][1].end},end:{...e[n][1].start}},i={type:c>1?`strong`:`emphasis`,start:{...o.start},end:{...s.end}},e[r][1].end={...o.start},e[n][1].start={...s.end},l=[],e[r][1].end.offset-e[r][1].start.offset&&(l=I8(l,[[`enter`,e[r][1],t],[`exit`,e[r][1],t]])),l=I8(l,[[`enter`,i,t],[`enter`,o,t],[`exit`,o,t],[`enter`,a,t]]),l=I8(l,t5(t.parser.constructs.insideSpan.null,e.slice(r+1,n),t)),l=I8(l,[[`exit`,a,t],[`enter`,s,t],[`exit`,s,t],[`exit`,i,t]]),e[n][1].end.offset-e[n][1].start.offset?(u=2,l=I8(l,[[`enter`,e[n][1],t],[`exit`,e[n][1],t]])):u=0,F8(e,r-1,n-r+3,l),n=r+l.length-u-2;break}}for(n=-1;++n0&&q8(t)?Q8(e,v,`linePrefix`,a+1)(t):v(t)}function v(t){return t===null||G8(t)?e.check(c5,h,b)(t):(e.enter(`codeFlowValue`),y(t))}function y(t){return t===null||G8(t)?(e.exit(`codeFlowValue`),v(t)):(e.consume(t),y)}function b(n){return e.exit(`codeFenced`),t(n)}function x(e,t,n){let i=0;return a;function a(t){return e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),c}function c(t){return e.enter(`codeFencedFence`),q8(t)?Q8(e,l,`linePrefix`,r.parser.constructs.disable.null.includes(`codeIndented`)?void 0:4)(t):l(t)}function l(t){return t===s?(e.enter(`codeFencedFenceSequence`),u(t)):n(t)}function u(t){return t===s?(i++,e.consume(t),u):i>=o?(e.exit(`codeFencedFenceSequence`),q8(t)?Q8(e,d,`whitespace`)(t):d(t)):n(t)}function d(r){return r===null||G8(r)?(e.exit(`codeFencedFence`),t(r)):n(r)}}}function wGe(e,t,n){let r=this;return i;function i(t){return t===null?n(t):(e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),a)}function a(e){return r.parser.lazy[r.now().line]?n(e):t(e)}}var u5={name:`codeIndented`,tokenize:EGe},TGe={partial:!0,tokenize:DGe};function EGe(e,t,n){let r=this;return i;function i(t){return e.enter(`codeIndented`),Q8(e,a,`linePrefix`,5)(t)}function a(e){let t=r.events[r.events.length-1];return t&&t[1].type===`linePrefix`&&t[2].sliceSerialize(t[1],!0).length>=4?o(e):n(e)}function o(t){return t===null?c(t):G8(t)?e.attempt(TGe,o,c)(t):(e.enter(`codeFlowValue`),s(t))}function s(t){return t===null||G8(t)?(e.exit(`codeFlowValue`),o(t)):(e.consume(t),s)}function c(n){return e.exit(`codeIndented`),t(n)}}function DGe(e,t,n){let r=this;return i;function i(t){return r.parser.lazy[r.now().line]?n(t):G8(t)?(e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),i):Q8(e,a,`linePrefix`,5)(t)}function a(e){let a=r.events[r.events.length-1];return a&&a[1].type===`linePrefix`&&a[2].sliceSerialize(a[1],!0).length>=4?t(e):G8(e)?i(e):n(e)}}var OGe={name:`codeText`,previous:AGe,resolve:kGe,tokenize:jGe};function kGe(e){let t=e.length-4,n=3,r,i;if((e[n][1].type===`lineEnding`||e[n][1].type===`space`)&&(e[t][1].type===`lineEnding`||e[t][1].type===`space`)){for(r=n;++r=this.left.length+this.right.length)throw RangeError("Cannot access index `"+e+"` in a splice buffer of size `"+(this.left.length+this.right.length)+"`");return ethis.left.length?this.right.slice(this.right.length-n+this.left.length,this.right.length-e+this.left.length).reverse():this.left.slice(e).concat(this.right.slice(this.right.length-n+this.left.length).reverse())}splice(e,t,n){let r=t||0;this.setCursor(Math.trunc(e));let i=this.right.splice(this.right.length-r,1/0);return n&&d5(this.left,n),i.reverse()}pop(){return this.setCursor(1/0),this.left.pop()}push(e){this.setCursor(1/0),this.left.push(e)}pushMany(e){this.setCursor(1/0),d5(this.left,e)}unshift(e){this.setCursor(0),this.right.push(e)}unshiftMany(e){this.setCursor(0),d5(this.right,e.reverse())}setCursor(e){if(!(e===this.left.length||e>this.left.length&&this.right.length===0||e<0&&this.left.length===0))if(e=4?t(i):e.interrupt(r.parser.constructs.flow,n,t)(i)}}function p5(e,t,n,r,i,a,o,s,c){let l=c||1/0,u=0;return d;function d(t){return t===60?(e.enter(r),e.enter(i),e.enter(a),e.consume(t),e.exit(a),f):t===null||t===32||t===41||U8(t)?n(t):(e.enter(r),e.enter(o),e.enter(s),e.enter(`chunkString`,{contentType:`string`}),h(t))}function f(n){return n===62?(e.enter(a),e.consume(n),e.exit(a),e.exit(i),e.exit(r),t):(e.enter(s),e.enter(`chunkString`,{contentType:`string`}),p(n))}function p(t){return t===62?(e.exit(`chunkString`),e.exit(s),f(t)):t===null||t===60||G8(t)?n(t):(e.consume(t),t===92?m:p)}function m(t){return t===60||t===62||t===92?(e.consume(t),p):p(t)}function h(i){return!u&&(i===null||i===41||K8(i))?(e.exit(`chunkString`),e.exit(s),e.exit(o),e.exit(r),t(i)):u999||l===null||l===91||l===93&&!c||l===94&&!s&&`_hiddenFootnoteSupport`in o.parser.constructs?n(l):l===93?(e.exit(a),e.enter(i),e.consume(l),e.exit(i),e.exit(r),t):G8(l)?(e.enter(`lineEnding`),e.consume(l),e.exit(`lineEnding`),u):(e.enter(`chunkString`,{contentType:`string`}),d(l))}function d(t){return t===null||t===91||t===93||G8(t)||s++>999?(e.exit(`chunkString`),u(t)):(e.consume(t),c||=!q8(t),t===92?f:d)}function f(t){return t===91||t===92||t===93?(e.consume(t),s++,d):d(t)}}function h5(e,t,n,r,i,a){let o;return s;function s(t){return t===34||t===39||t===40?(e.enter(r),e.enter(i),e.consume(t),e.exit(i),o=t===40?41:t,c):n(t)}function c(n){return n===o?(e.enter(i),e.consume(n),e.exit(i),e.exit(r),t):(e.enter(a),l(n))}function l(t){return t===o?(e.exit(a),c(o)):t===null?n(t):G8(t)?(e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),Q8(e,l,`linePrefix`)):(e.enter(`chunkString`,{contentType:`string`}),u(t))}function u(t){return t===o||t===null||G8(t)?(e.exit(`chunkString`),l(t)):(e.consume(t),t===92?d:u)}function d(t){return t===o||t===92?(e.consume(t),u):u(t)}}function g5(e,t){let n;return r;function r(i){return G8(i)?(e.enter(`lineEnding`),e.consume(i),e.exit(`lineEnding`),n=!0,r):q8(i)?Q8(e,r,n?`linePrefix`:`lineSuffix`)(i):t(i)}}var zGe={name:`definition`,tokenize:VGe},BGe={partial:!0,tokenize:HGe};function VGe(e,t,n){let r=this,i;return a;function a(t){return e.enter(`definition`),o(t)}function o(t){return m5.call(r,e,s,n,`definitionLabel`,`definitionLabelMarker`,`definitionLabelString`)(t)}function s(t){return i=B8(r.sliceSerialize(r.events[r.events.length-1][1]).slice(1,-1)),t===58?(e.enter(`definitionMarker`),e.consume(t),e.exit(`definitionMarker`),c):n(t)}function c(t){return K8(t)?g5(e,l)(t):l(t)}function l(t){return p5(e,u,n,`definitionDestination`,`definitionDestinationLiteral`,`definitionDestinationLiteralMarker`,`definitionDestinationRaw`,`definitionDestinationString`)(t)}function u(t){return e.attempt(BGe,d,d)(t)}function d(t){return q8(t)?Q8(e,f,`whitespace`)(t):f(t)}function f(a){return a===null||G8(a)?(e.exit(`definition`),r.parser.defined.push(i),t(a)):n(a)}}function HGe(e,t,n){return r;function r(t){return K8(t)?g5(e,i)(t):n(t)}function i(t){return h5(e,a,n,`definitionTitle`,`definitionTitleMarker`,`definitionTitleString`)(t)}function a(t){return q8(t)?Q8(e,o,`whitespace`)(t):o(t)}function o(e){return e===null||G8(e)?t(e):n(e)}}var UGe={name:`hardBreakEscape`,tokenize:WGe};function WGe(e,t,n){return r;function r(t){return e.enter(`hardBreakEscape`),e.consume(t),i}function i(r){return G8(r)?(e.exit(`hardBreakEscape`),t(r)):n(r)}}var GGe={name:`headingAtx`,resolve:KGe,tokenize:qGe};function KGe(e,t){let n=e.length-2,r=3,i,a;return e[r][1].type===`whitespace`&&(r+=2),n-2>r&&e[n][1].type===`whitespace`&&(n-=2),e[n][1].type===`atxHeadingSequence`&&(r===n-1||n-4>r&&e[n-2][1].type===`whitespace`)&&(n-=r+1===n?2:4),n>r&&(i={type:`atxHeadingText`,start:e[r][1].start,end:e[n][1].end},a={type:`chunkText`,start:e[r][1].start,end:e[n][1].end,contentType:`text`},F8(e,r,n-r+1,[[`enter`,i,t],[`enter`,a,t],[`exit`,a,t],[`exit`,i,t]])),e}function qGe(e,t,n){let r=0;return i;function i(t){return e.enter(`atxHeading`),a(t)}function a(t){return e.enter(`atxHeadingSequence`),o(t)}function o(t){return t===35&&r++<6?(e.consume(t),o):t===null||K8(t)?(e.exit(`atxHeadingSequence`),s(t)):n(t)}function s(n){return n===35?(e.enter(`atxHeadingSequence`),c(n)):n===null||G8(n)?(e.exit(`atxHeading`),t(n)):q8(n)?Q8(e,s,`whitespace`)(n):(e.enter(`atxHeadingText`),l(n))}function c(t){return t===35?(e.consume(t),c):(e.exit(`atxHeadingSequence`),s(t))}function l(t){return t===null||t===35||K8(t)?(e.exit(`atxHeadingText`),s(t)):(e.consume(t),l)}}var JGe=`address.article.aside.base.basefont.blockquote.body.caption.center.col.colgroup.dd.details.dialog.dir.div.dl.dt.fieldset.figcaption.figure.footer.form.frame.frameset.h1.h2.h3.h4.h5.h6.head.header.hr.html.iframe.legend.li.link.main.menu.menuitem.nav.noframes.ol.optgroup.option.p.param.search.section.summary.table.tbody.td.tfoot.th.thead.title.tr.track.ul`.split(`.`),_5=[`pre`,`script`,`style`,`textarea`],YGe={concrete:!0,name:`htmlFlow`,resolveTo:QGe,tokenize:$Ge},XGe={partial:!0,tokenize:tKe},ZGe={partial:!0,tokenize:eKe};function QGe(e){let t=e.length;for(;t--&&!(e[t][0]===`enter`&&e[t][1].type===`htmlFlow`););return t>1&&e[t-2][1].type===`linePrefix`&&(e[t][1].start=e[t-2][1].start,e[t+1][1].start=e[t-2][1].start,e.splice(t-2,2)),e}function $Ge(e,t,n){let r=this,i,a,o,s,c;return l;function l(e){return u(e)}function u(t){return e.enter(`htmlFlow`),e.enter(`htmlFlowData`),e.consume(t),d}function d(s){return s===33?(e.consume(s),f):s===47?(e.consume(s),a=!0,h):s===63?(e.consume(s),i=3,r.interrupt?t:I):V8(s)?(e.consume(s),o=String.fromCharCode(s),g):n(s)}function f(a){return a===45?(e.consume(a),i=2,p):a===91?(e.consume(a),i=5,s=0,m):V8(a)?(e.consume(a),i=4,r.interrupt?t:I):n(a)}function p(i){return i===45?(e.consume(i),r.interrupt?t:I):n(i)}function m(i){return i===`CDATA[`.charCodeAt(s++)?(e.consume(i),s===6?r.interrupt?t:O:m):n(i)}function h(t){return V8(t)?(e.consume(t),o=String.fromCharCode(t),g):n(t)}function g(s){if(s===null||s===47||s===62||K8(s)){let c=s===47,l=o.toLowerCase();return!c&&!a&&_5.includes(l)?(i=1,r.interrupt?t(s):O(s)):JGe.includes(o.toLowerCase())?(i=6,c?(e.consume(s),_):r.interrupt?t(s):O(s)):(i=7,r.interrupt&&!r.parser.lazy[r.now().line]?n(s):a?v(s):y(s))}return s===45||H8(s)?(e.consume(s),o+=String.fromCharCode(s),g):n(s)}function _(i){return i===62?(e.consume(i),r.interrupt?t:O):n(i)}function v(t){return q8(t)?(e.consume(t),v):E(t)}function y(t){return t===47?(e.consume(t),E):t===58||t===95||V8(t)?(e.consume(t),b):q8(t)?(e.consume(t),y):E(t)}function b(t){return t===45||t===46||t===58||t===95||H8(t)?(e.consume(t),b):x(t)}function x(t){return t===61?(e.consume(t),S):q8(t)?(e.consume(t),x):y(t)}function S(t){return t===null||t===60||t===61||t===62||t===96?n(t):t===34||t===39?(e.consume(t),c=t,C):q8(t)?(e.consume(t),S):w(t)}function C(t){return t===c?(e.consume(t),c=null,T):t===null||G8(t)?n(t):(e.consume(t),C)}function w(t){return t===null||t===34||t===39||t===47||t===60||t===61||t===62||t===96||K8(t)?x(t):(e.consume(t),w)}function T(e){return e===47||e===62||q8(e)?y(e):n(e)}function E(t){return t===62?(e.consume(t),D):n(t)}function D(t){return t===null||G8(t)?O(t):q8(t)?(e.consume(t),D):n(t)}function O(t){return t===45&&i===2?(e.consume(t),M):t===60&&i===1?(e.consume(t),N):t===62&&i===4?(e.consume(t),L):t===63&&i===3?(e.consume(t),I):t===93&&i===5?(e.consume(t),F):G8(t)&&(i===6||i===7)?(e.exit(`htmlFlowData`),e.check(XGe,R,k)(t)):t===null||G8(t)?(e.exit(`htmlFlowData`),k(t)):(e.consume(t),O)}function k(t){return e.check(ZGe,A,R)(t)}function A(t){return e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),j}function j(t){return t===null||G8(t)?k(t):(e.enter(`htmlFlowData`),O(t))}function M(t){return t===45?(e.consume(t),I):O(t)}function N(t){return t===47?(e.consume(t),o=``,P):O(t)}function P(t){if(t===62){let n=o.toLowerCase();return _5.includes(n)?(e.consume(t),L):O(t)}return V8(t)&&o.length<8?(e.consume(t),o+=String.fromCharCode(t),P):O(t)}function F(t){return t===93?(e.consume(t),I):O(t)}function I(t){return t===62?(e.consume(t),L):t===45&&i===2?(e.consume(t),I):O(t)}function L(t){return t===null||G8(t)?(e.exit(`htmlFlowData`),R(t)):(e.consume(t),L)}function R(n){return e.exit(`htmlFlow`),t(n)}}function eKe(e,t,n){let r=this;return i;function i(t){return G8(t)?(e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),a):n(t)}function a(e){return r.parser.lazy[r.now().line]?n(e):t(e)}}function tKe(e,t,n){return r;function r(r){return e.enter(`lineEnding`),e.consume(r),e.exit(`lineEnding`),e.attempt(i5,t,n)}}var nKe={name:`htmlText`,tokenize:rKe};function rKe(e,t,n){let r=this,i,a,o;return s;function s(t){return e.enter(`htmlText`),e.enter(`htmlTextData`),e.consume(t),c}function c(t){return t===33?(e.consume(t),l):t===47?(e.consume(t),x):t===63?(e.consume(t),y):V8(t)?(e.consume(t),w):n(t)}function l(t){return t===45?(e.consume(t),u):t===91?(e.consume(t),a=0,m):V8(t)?(e.consume(t),v):n(t)}function u(t){return t===45?(e.consume(t),p):n(t)}function d(t){return t===null?n(t):t===45?(e.consume(t),f):G8(t)?(o=d,N(t)):(e.consume(t),d)}function f(t){return t===45?(e.consume(t),p):d(t)}function p(e){return e===62?M(e):e===45?f(e):d(e)}function m(t){return t===`CDATA[`.charCodeAt(a++)?(e.consume(t),a===6?h:m):n(t)}function h(t){return t===null?n(t):t===93?(e.consume(t),g):G8(t)?(o=h,N(t)):(e.consume(t),h)}function g(t){return t===93?(e.consume(t),_):h(t)}function _(t){return t===62?M(t):t===93?(e.consume(t),_):h(t)}function v(t){return t===null||t===62?M(t):G8(t)?(o=v,N(t)):(e.consume(t),v)}function y(t){return t===null?n(t):t===63?(e.consume(t),b):G8(t)?(o=y,N(t)):(e.consume(t),y)}function b(e){return e===62?M(e):y(e)}function x(t){return V8(t)?(e.consume(t),S):n(t)}function S(t){return t===45||H8(t)?(e.consume(t),S):C(t)}function C(t){return G8(t)?(o=C,N(t)):q8(t)?(e.consume(t),C):M(t)}function w(t){return t===45||H8(t)?(e.consume(t),w):t===47||t===62||K8(t)?T(t):n(t)}function T(t){return t===47?(e.consume(t),M):t===58||t===95||V8(t)?(e.consume(t),E):G8(t)?(o=T,N(t)):q8(t)?(e.consume(t),T):M(t)}function E(t){return t===45||t===46||t===58||t===95||H8(t)?(e.consume(t),E):D(t)}function D(t){return t===61?(e.consume(t),O):G8(t)?(o=D,N(t)):q8(t)?(e.consume(t),D):T(t)}function O(t){return t===null||t===60||t===61||t===62||t===96?n(t):t===34||t===39?(e.consume(t),i=t,k):G8(t)?(o=O,N(t)):q8(t)?(e.consume(t),O):(e.consume(t),A)}function k(t){return t===i?(e.consume(t),i=void 0,j):t===null?n(t):G8(t)?(o=k,N(t)):(e.consume(t),k)}function A(t){return t===null||t===34||t===39||t===60||t===61||t===96?n(t):t===47||t===62||K8(t)?T(t):(e.consume(t),A)}function j(e){return e===47||e===62||K8(e)?T(e):n(e)}function M(r){return r===62?(e.consume(r),e.exit(`htmlTextData`),e.exit(`htmlText`),t):n(r)}function N(t){return e.exit(`htmlTextData`),e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),P}function P(t){return q8(t)?Q8(e,F,`linePrefix`,r.parser.constructs.disable.null.includes(`codeIndented`)?void 0:4)(t):F(t)}function F(t){return e.enter(`htmlTextData`),o(t)}}var v5={name:`labelEnd`,resolveAll:sKe,resolveTo:cKe,tokenize:lKe},iKe={tokenize:uKe},aKe={tokenize:dKe},oKe={tokenize:fKe};function sKe(e){let t=-1,n=[];for(;++t=3&&(a===null||G8(a))?(e.exit(`thematicBreak`),t(a)):n(a)}function c(t){return t===i?(e.consume(t),r++,c):(e.exit(`thematicBreakSequence`),q8(t)?Q8(e,s,`whitespace`)(t):s(t))}}var x5={continuation:{tokenize:SKe},exit:wKe,name:`list`,tokenize:xKe},yKe={partial:!0,tokenize:TKe},bKe={partial:!0,tokenize:CKe};function xKe(e,t,n){let r=this,i=r.events[r.events.length-1],a=i&&i[1].type===`linePrefix`?i[2].sliceSerialize(i[1],!0).length:0,o=0;return s;function s(t){let i=r.containerState.type||(t===42||t===43||t===45?`listUnordered`:`listOrdered`);if(i===`listUnordered`?!r.containerState.marker||t===r.containerState.marker:W8(t)){if(r.containerState.type||(r.containerState.type=i,e.enter(i,{_container:!0})),i===`listUnordered`)return e.enter(`listItemPrefix`),t===42||t===45?e.check(b5,n,l)(t):l(t);if(!r.interrupt||t===49)return e.enter(`listItemPrefix`),e.enter(`listItemValue`),c(t)}return n(t)}function c(t){return W8(t)&&++o<10?(e.consume(t),c):(!r.interrupt||o<2)&&(r.containerState.marker?t===r.containerState.marker:t===41||t===46)?(e.exit(`listItemValue`),l(t)):n(t)}function l(t){return e.enter(`listItemMarker`),e.consume(t),e.exit(`listItemMarker`),r.containerState.marker=r.containerState.marker||t,e.check(i5,r.interrupt?n:u,e.attempt(yKe,f,d))}function u(e){return r.containerState.initialBlankLine=!0,a++,f(e)}function d(t){return q8(t)?(e.enter(`listItemPrefixWhitespace`),e.consume(t),e.exit(`listItemPrefixWhitespace`),f):n(t)}function f(n){return r.containerState.size=a+r.sliceSerialize(e.exit(`listItemPrefix`),!0).length,t(n)}}function SKe(e,t,n){let r=this;return r.containerState._closeFlow=void 0,e.check(i5,i,a);function i(n){return r.containerState.furtherBlankLines=r.containerState.furtherBlankLines||r.containerState.initialBlankLine,Q8(e,t,`listItemIndent`,r.containerState.size+1)(n)}function a(n){return r.containerState.furtherBlankLines||!q8(n)?(r.containerState.furtherBlankLines=void 0,r.containerState.initialBlankLine=void 0,o(n)):(r.containerState.furtherBlankLines=void 0,r.containerState.initialBlankLine=void 0,e.attempt(bKe,t,o)(n))}function o(i){return r.containerState._closeFlow=!0,r.interrupt=void 0,Q8(e,e.attempt(x5,t,n),`linePrefix`,r.parser.constructs.disable.null.includes(`codeIndented`)?void 0:4)(i)}}function CKe(e,t,n){let r=this;return Q8(e,i,`listItemIndent`,r.containerState.size+1);function i(e){let i=r.events[r.events.length-1];return i&&i[1].type===`listItemIndent`&&i[2].sliceSerialize(i[1],!0).length===r.containerState.size?t(e):n(e)}}function wKe(e){e.exit(this.containerState.type)}function TKe(e,t,n){let r=this;return Q8(e,i,`listItemPrefixWhitespace`,r.parser.constructs.disable.null.includes(`codeIndented`)?void 0:5);function i(e){let i=r.events[r.events.length-1];return!q8(e)&&i&&i[1].type===`listItemPrefixWhitespace`?t(e):n(e)}}var S5={name:`setextUnderline`,resolveTo:EKe,tokenize:DKe};function EKe(e,t){let n=e.length,r,i,a;for(;n--;)if(e[n][0]===`enter`){if(e[n][1].type===`content`){r=n;break}e[n][1].type===`paragraph`&&(i=n)}else e[n][1].type===`content`&&e.splice(n,1),!a&&e[n][1].type===`definition`&&(a=n);let o={type:`setextHeading`,start:{...e[r][1].start},end:{...e[e.length-1][1].end}};return e[i][1].type=`setextHeadingText`,a?(e.splice(i,0,[`enter`,o,t]),e.splice(a+1,0,[`exit`,e[r][1],t]),e[r][1].end={...e[a][1].end}):e[r][1]=o,e.push([`exit`,o,t]),e}function DKe(e,t,n){let r=this,i;return a;function a(t){let a=r.events.length,s;for(;a--;)if(r.events[a][1].type!==`lineEnding`&&r.events[a][1].type!==`linePrefix`&&r.events[a][1].type!==`content`){s=r.events[a][1].type===`paragraph`;break}return!r.parser.lazy[r.now().line]&&(r.interrupt||s)?(e.enter(`setextHeadingLine`),i=t,o(t)):n(t)}function o(t){return e.enter(`setextHeadingLineSequence`),s(t)}function s(t){return t===i?(e.consume(t),s):(e.exit(`setextHeadingLineSequence`),q8(t)?Q8(e,c,`lineSuffix`)(t):c(t))}function c(r){return r===null||G8(r)?(e.exit(`setextHeadingLine`),t(r)):n(r)}}var OKe={tokenize:kKe};function kKe(e){let t=this,n=e.attempt(i5,r,e.attempt(this.parser.constructs.flowInitial,i,Q8(e,e.attempt(this.parser.constructs.flow,i,e.attempt(PGe,i)),`linePrefix`)));return n;function r(r){if(r===null){e.consume(r);return}return e.enter(`lineEndingBlank`),e.consume(r),e.exit(`lineEndingBlank`),t.currentConstruct=void 0,n}function i(r){if(r===null){e.consume(r);return}return e.enter(`lineEnding`),e.consume(r),e.exit(`lineEnding`),t.currentConstruct=void 0,n}}var AKe={resolveAll:w5()},jKe=C5(`string`),MKe=C5(`text`);function C5(e){return{resolveAll:w5(e===`text`?NKe:void 0),tokenize:t};function t(t){let n=this,r=this.parser.constructs[e],i=t.attempt(r,a,o);return a;function a(e){return c(e)?i(e):o(e)}function o(e){if(e===null){t.consume(e);return}return t.enter(`data`),t.consume(e),s}function s(e){return c(e)?(t.exit(`data`),i(e)):(t.consume(e),s)}function c(e){if(e===null)return!0;let t=r[e],i=-1;if(t)for(;++iHKe,contentInitial:()=>IKe,disable:()=>UKe,document:()=>FKe,flow:()=>RKe,flowInitial:()=>LKe,insideSpan:()=>VKe,string:()=>zKe,text:()=>BKe}),FKe={42:x5,43:x5,45:x5,48:x5,49:x5,50:x5,51:x5,52:x5,53:x5,54:x5,55:x5,56:x5,57:x5,62:a5},IKe={91:zGe},LKe={[-2]:u5,[-1]:u5,32:u5},RKe={35:GGe,42:b5,45:[S5,b5],60:YGe,61:S5,95:b5,96:l5,126:l5},zKe={38:s5,92:o5},BKe={[-5]:y5,[-4]:y5,[-3]:y5,33:pKe,38:s5,42:n5,60:[hGe,nKe],91:hKe,92:[UGe,o5],93:v5,95:n5,96:OGe},VKe={null:[n5,AKe]},HKe={null:[42,95]},UKe={null:[]};function WKe(e,t,n){let r={_bufferIndex:-1,_index:0,line:n&&n.line||1,column:n&&n.column||1,offset:n&&n.offset||0},i={},a=[],o=[],s=[],c={attempt:C(x),check:C(S),consume:v,enter:y,exit:b,interrupt:C(S,{interrupt:!0})},l={code:null,containerState:{},defineSkip:h,events:[],now:m,parser:e,previous:null,sliceSerialize:f,sliceStream:p,write:d},u=t.tokenize.call(l,c);return t.resolveAll&&a.push(t),l;function d(e){return o=I8(o,e),g(),o[o.length-1]===null?(w(t,0),l.events=t5(a,l.events,l),l.events):[]}function f(e,t){return KKe(p(e),t)}function p(e){return GKe(o,e)}function m(){let{_bufferIndex:e,_index:t,line:n,column:i,offset:a}=r;return{_bufferIndex:e,_index:t,line:n,column:i,offset:a}}function h(e){i[e.line]=e.column,E()}function g(){let e;for(;r._index-1){let e=o[0];typeof e==`string`?o[0]=e.slice(r):o.shift()}a>0&&o.push(e[i].slice(0,a))}return o}function KKe(e,t){let n=-1,r=[],i;for(;++n0){let e=a.tokenStack[a.tokenStack.length-1];(e[1]||k5).call(a,void 0,e[0])}for(r.position={start:D5(e.length>0?e[0][1].start:{line:1,column:1,offset:0}),end:D5(e.length>0?e[e.length-2][1].end:{line:1,column:1,offset:0})},d=-1;++d - +