From a42ec820f614c66e6c678a3b902c8a729c1b8cba Mon Sep 17 00:00:00 2001
From: maziggy
Date: Wed, 13 May 2026 09:08:30 +0200
Subject: [PATCH] fix(makerworld): point Open Cloud settings link to
/profiles (#1300)
The "Open Cloud settings" link in the MakerWorld sign-in-required banner
pointed at /settings?tab=cloud, but Settings has no cloud tab so the URL
fell back to the General tab. Bambu Cloud login lives on /profiles, which
already defaults its sub-tab to cloud.
---
CHANGELOG.md | 2 ++
frontend/src/pages/MakerworldPage.tsx | 2 +-
static/assets/{index-Dk-aHJ3a.js => index-C-E97wE_.js} | 2 +-
static/index.html | 2 +-
4 files changed, 5 insertions(+), 3 deletions(-)
rename static/assets/{index-Dk-aHJ3a.js => index-C-E97wE_.js} (99%)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index fc1e911bb..5c7636fe0 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,6 +12,8 @@ All notable changes to Bambuddy will be documented in this file.
- **Spoolman weight tracking now uses per-print grams for all spools, matching the internal Filament Inventory** ([#1119](https://github.com/maziggy/bambuddy/issues/1119), reported by @Moskito99) — Spoolman previously had two mutually-exclusive weight paths: AMS remain%×tray_weight auto-sync (default; only worked for Bambu Lab spools with valid RFID tray_weight) and per-print 3MF-grams tracking (only enabled when "Disable AMS Weight Sync" was toggled on). Non-BL spools without RFID fell through both paths — AMS auto-sync had no tray_weight to multiply, and the inventory_remaining fallback was wiped because activating Spoolman deletes the internal `spool_assignment` table — so Spoolman never saw a weight update for them. The internal Filament Inventory has no such gap: it always uses per-print 3MF grams as the primary path with AMS-remain% delta as fallback, and it works for every spool type. Spoolman now does the same: per-print tracking runs whenever Spoolman is enabled and is the only writer of `remaining_weight`. AMS auto-sync continues to maintain spool metadata and slot assignments but no longer touches weight (eliminating the double-count that would otherwise occur for BL spools with both paths active). `store_print_data` ([`spoolman_tracking.py:159`](backend/app/services/spoolman_tracking.py)) had its `disable_weight_sync` early-return removed; the three `sync_ams_tray` callsites (`main.py:1450` auto-sync, `spoolman.py:318` per-printer manual, `spoolman.py:517` sync-all) now hard-code `disable_weight_sync=True`. The `spoolman_disable_weight_sync` setting is now deprecated and a no-op — kept in the DB/UI for backwards compat. Behavioral consequence for existing users on the default flag (False): live AMS-based remaining_weight updates between prints stop happening; weight updates now arrive once per print completion with 3MF gram precision. Regression test in `test_spoolman_tracking.py::test_stores_tracking_when_disable_weight_sync_is_false` proves the early-return is gone.
### Fixed
+- **MakerWorld "Open Cloud settings" link landed on the wrong page** ([#1300](https://github.com/maziggy/bambuddy/issues/1300)) — On the MakerWorld page, the "Open Cloud settings" hyperlink shown in the sign-in-required banner (when no Bambu Cloud token is stored) pointed at `/settings?tab=cloud`. The Settings page has no `cloud` tab (its tabs are general/plugs/notifications/queue/filament/network/apikeys/virtual-printer/spoolbuddy/failure-detection/users/backup), so the URL-param check at `SettingsPage.tsx:179` (`validTabs.includes(tabParam) ? tabParam : 'general'`) silently fell back to the General tab. The Bambu Cloud login UI actually lives on the Profiles page (`/profiles`), which already defaults its sub-tab to `cloud` — the same destination the existing `backup.cloudLoginRequired` i18n string ("Sign in under Profiles → Cloud Profiles…") documents. One-line fix in `MakerworldPage.tsx:438`: `to="/settings?tab=cloud"` → `to="/profiles"`. The Profiles page's `useState('cloud')` (line 2822) means no query param is needed — landing on `/profiles` opens the Cloud sub-tab directly.
+
- **External-spool prints no longer credit usage to AMS slot 0's Spoolman spool** ([#1276](https://github.com/maziggy/bambuddy/issues/1276), reported and diagnosed by @ojimpo — regression of #853) — On a single-filament external-spool print (TPU loaded in `vir_slot id=254` on the reporter's H2S + AMS 2 Pro), `_resolve_global_tray_id` in `spoolman_tracking.py` was crediting the usage to whatever Spoolman spool happened to be linked to AMS slot 0 — a completely unrelated material in the reporter's case. ~48.94 g of TPU was credited to a PLA spool across 4 prints before they noticed. Root cause: BambuStudio encodes virtual tray IDs (254/255) as `-1` in the flat `ams_mapping` array it sends to the printer (a convention already documented in `bambu_mqtt.py:start_print()`), but the spoolman tracking helper was treating `-1` as "unmapped → use position-based default" and the default mapped `slot_id=1` → `global_tray_id=0`. When `slot_to_tray[slot_id-1] == -1` and `ams_trays` contains an external slot (254 or 255), the helper now returns the external tray ID directly, matching the convention `start_print()` uses on the other side of the pipeline. Prefers 254 over 255 (consistent with single-nozzle `tray_now` reporting and the `vir_slot` id=255→254 remap in `bambu_mqtt.py:864`). Legacy behavior preserved when `ams_trays` is empty or contains no external slot (callers that don't pass `ams_trays` keep the position-based fallback). Two regression tests cover the reporter's exact scenario (`ams_trays={0,1,2,3,254}, slot_to_tray=[-1]` → 254) plus the H2D-deputy case and the fall-through-when-no-external case. **Root cause investigation and patch by @ojimpo.**
- **Virtual-printer queue mode now honors workflow default print options** ([#1235](https://github.com/maziggy/bambuddy/issues/1235), reported by @jc21, root cause and patch by @jc21 in #1277) — Prints sent from Bambu Studio (or any slicer) to a VP in `print_queue` mode arrived in the queue with `bed_levelling`, `flow_cali`, `vibration_cali`, `layer_inspect`, and `timelapse` set to the SQLAlchemy column-level defaults, never the user's workflow preferences. The reporter happened to have every workflow default set to the opposite of the column defaults, so prints appeared to have all five options inverted; every queue item required hand-editing before dispatch. The manual `POST /print-queue/` endpoint reads these fields off the request body (the frontend pulls them from settings before submitting), but the VP-FTP-receive path at `backend/app/services/virtual_printer/manager.py:_add_to_print_queue` constructed `PrintQueueItem` without touching them at all — SQLAlchemy then filled in `bed_levelling=True, flow_cali=False, vibration_cali=True, layer_inspect=False, timelapse=False` regardless of what was in the DB. Fix reads `default_bed_levelling` / `default_flow_cali` / `default_vibration_cali` / `default_layer_inspect` / `default_timelapse` via the existing `get_setting()` helper (same pattern already used in the function for `virtual_printer_archive_name_source`) and passes them explicitly to `PrintQueueItem`. A small `_bool_setting()` helper maps `None → AppSettings schema default`, so a fresh install with no workflow page customization behaves identically to before. Regression tests: `test_add_to_print_queue_uses_workflow_defaults_from_settings` (verifies all five settings flow through with values opposite to the column defaults, matching the reporter's exact scenario) and `test_add_to_print_queue_falls_back_to_schema_defaults_when_unset` (verifies the no-DB-row path).
diff --git a/frontend/src/pages/MakerworldPage.tsx b/frontend/src/pages/MakerworldPage.tsx
index 77951cd62..2a41d26a1 100644
--- a/frontend/src/pages/MakerworldPage.tsx
+++ b/frontend/src/pages/MakerworldPage.tsx
@@ -435,7 +435,7 @@ export function MakerworldPage() {
{t('makerworld.signInRequiredBody')}{' '}
-
+
{t('makerworld.openCloudSettings')}
diff --git a/static/assets/index-Dk-aHJ3a.js b/static/assets/index-C-E97wE_.js
similarity index 99%
rename from static/assets/index-Dk-aHJ3a.js
rename to static/assets/index-C-E97wE_.js
index dfe3a476a..c8d331322 100644
--- a/static/assets/index-Dk-aHJ3a.js
+++ b/static/assets/index-C-E97wE_.js
@@ -8726,7 +8726,7 @@ Accuracy: ${t.time_accuracy.toFixed(0)}%`:t.actual_time_seconds?`Actual: ${ds(t.
Calculated: ${Math.round(i)}g
Difference: ${l}g (within tolerance)`:`Scale: ${Math.round(n)}g
Calculated: ${Math.round(i)}g
-Difference: ${l}g (mismatch!)`;return r.jsxs("div",{className:`flex items-center gap-1 text-sm font-medium ${o?"text-green-400":"text-yellow-400"}`,title:c,children:[r.jsxs("span",{children:[Math.round(n),"g"]}),o?r.jsx(_r,{className:"w-3 h-3"}):r.jsxs(r.Fragment,{children:[r.jsx(Nn,{className:"w-3 h-3"}),e&&r.jsx("button",{type:"button",onClick:d=>{d.stopPropagation(),d.preventDefault(),e(t)},className:"p-1 hover:bg-bambu-green/20 rounded transition-colors text-bambu-green",title:"Sync: trust scale weight and reset tracking",children:r.jsx(sr,{className:"w-3.5 h-3.5"})})]})]})}},gF={id:t=>t.id,added_time:t=>t.created_at||"",encode_time:t=>t.encode_time||"",last_used_time:t=>t.last_used||"",material:t=>(t.material||"").toLowerCase(),subtype:t=>(t.subtype||"").toLowerCase(),color_name:t=>(t.color_name||"").toLowerCase(),brand:t=>(t.brand||"").toLowerCase(),slicer_filament:t=>(t.slicer_filament_name||t.slicer_filament||"").toLowerCase(),location:(t,e)=>{const n=e[t.id];if(!n)return"";const a=n.ams_id===254||n.ams_id===255,i=!a&&n.ams_id>=128,s=n.ams_label?` (${n.ams_label})`:"";return`${n.printer_name||""} ${c_(n.ams_id,n.tray_id,i,a)}${s}`},storage_location:t=>(t.storage_location||"").toLowerCase(),label_weight:t=>t.label_weight,net:t=>Math.max(0,t.label_weight-t.weight_used),gross:t=>Math.max(0,t.label_weight-t.weight_used)+t.core_weight,used:t=>t.weight_used,remaining:t=>t.label_weight>0?Math.max(0,t.label_weight-t.weight_used)/t.label_weight:0,note:t=>(t.note||"").toLowerCase(),data_origin:t=>(t.data_origin||"").toLowerCase(),tag_type:t=>(t.tag_type||"").toLowerCase(),stock:t=>t.slicer_filament?1:0,spool_name:t=>t.core_weight_catalog_id??0,cost_per_kg:t=>t.cost_per_kg??0,weight_check:t=>{if(t.last_scale_weight==null)return-1;const e=Math.max(0,t.label_weight-t.weight_used)+t.core_weight;return Math.abs(t.last_scale_weight-e)}},XI="bambuddy-inventory-sort";function rst(){try{const t=localStorage.getItem(XI);if(t)return JSON.parse(t)}catch{}return null}function ast(t){try{t?localStorage.setItem(XI,JSON.stringify(t)):localStorage.removeItem(XI)}catch{}}function ist(){const{data:t}=We({queryKey:["spoolman-settings"],queryFn:se.getSpoolmanSettings,staleTime:3e5}),e=t!==void 0,n=t?.spoolman_enabled==="true"&&!!t?.spoolman_url;return r.jsx(sst,{spoolmanMode:n,spoolmanModeReady:e})}function sst({spoolmanMode:t=!1,spoolmanModeReady:e=!0}){const{t:n}=kt(),a=en(),{showToast:i}=rn(),{hasPermission:s,loading:o}=cr(),l=!o&&s("inventory:forecast_read"),[c,d]=ab(),[u,m]=v.useState(null),p=v.useRef(!1),[f,b]=v.useState(null),[w,g]=v.useState(null),[x,_]=v.useState("active"),[N,C]=v.useState("all"),[P,T]=v.useState(""),[A,F]=v.useState(""),[S,M]=v.useState(""),[z,I]=v.useState(""),[H,L]=v.useState("all"),[Z,re]=v.useState(""),[J,de]=v.useState("table"),[me,ue]=v.useState(rst),[W,ae]=v.useState(Jit),[pe,ye]=v.useState(!1),[Te,$]=v.useState(()=>{try{return localStorage.getItem("bambuddy-inventory-group")==="true"}catch{return!1}}),[K,D]=v.useState(new Set),[j,B]=v.useState(0),[X,O]=v.useState(()=>{try{const he=localStorage.getItem("bambuddy-inventory-pageSize");if(he){const Fe=Number(he);if([15,30,50,100,-1].includes(Fe))return Fe}}catch{}return 15}),{data:ie}=We({queryKey:["settings"],queryFn:se.getSettings}),U=ie?.date_format||"system",G=t?["spoolman-inventory-spools"]:["inventory-spools"],{data:Y,isLoading:Q}=We({queryKey:G,queryFn:()=>t?se.getSpoolmanInventorySpools(!0):se.getSpools(!0),refetchInterval:3e4}),oe=c.get("spool"),ee=oe&&/^\d+$/.test(oe)&&Number(oe)>0?Number(oe):null,ge=Y?.find(he=>he.id===ee)??null,ce=v.useCallback(()=>{p.current=!0,d(he=>(he.delete("spool"),he),{replace:!0})},[d]),{data:le,isError:q,error:R}=We({queryKey:t?["spoolman-inventory-spool",ee]:["inventory-spool",ee],queryFn:()=>t?se.getSpoolmanInventorySpool(ee):se.getSpool(ee),enabled:e&&ee!==null&&ge===null,staleTime:1/0,retry:(he,Fe)=>he<2&&!(Fe instanceof _i&&Fe.status===404)});v.useEffect(()=>{if(!p.current){if(e&&ee&&ge){ce(),m({spool:ge,mode:"edit"});return}if(le){ce(),m({spool:le,mode:"edit"});return}if(q){ce();const he=R instanceof _i&&R.status===404;i(n(he?"inventory.deepLinkSpoolNotFound":"inventory.deepLinkFetchFailed"),"error")}}},[e,ee,ge,le,q,R,ce,i,n]);const{data:ne}=We({queryKey:["spool-assignments"],queryFn:()=>se.getAssignments(),refetchInterval:3e4}),{data:xe=[],isError:we}=We({queryKey:["spoolman-slot-assignments-all"],queryFn:()=>se.getSpoolmanSlotAssignments(),enabled:t,refetchInterval:3e4,staleTime:1e4,retry:1}),Ne=v.useRef(!1);v.useEffect(()=>{we&&!Ne.current?(Ne.current=!0,i(n("inventory.spoolmanUnreachable"),"error")):we||(Ne.current=!1)},[we,i,n]);const{data:ve}=We({queryKey:["spool-catalog"],queryFn:()=>se.getSpoolCatalog()}),be=it({mutationFn:he=>t?se.deleteSpoolmanInventorySpool(he):se.deleteSpool(he),onSuccess:()=>{a.invalidateQueries({queryKey:G}),i(n("inventory.spoolDeleted"),"success")},onError:he=>{he instanceof _i&&he.status===404?i(n("inventory.deleteSpoolNotFound"),"error"):he instanceof _i&&he.status===503?i(n("inventory.spoolmanUnreachable"),"error"):i(n("inventory.deleteFailed"),"error")}}),Ee=it({mutationFn:he=>t?se.archiveSpoolmanInventorySpool(he):se.archiveSpool(he),onSuccess:()=>{a.invalidateQueries({queryKey:G}),i(n("inventory.spoolArchived"),"success")},onError:he=>{he instanceof _i&&he.status===404?i(n("inventory.archiveSpoolNotFound"),"error"):he instanceof _i&&he.status===503?i(n("inventory.spoolmanUnreachable"),"error"):i(n("inventory.archiveFailed"),"error")}}),ze=it({mutationFn:he=>t?se.restoreSpoolmanInventorySpool(he):se.restoreSpool(he),onSuccess:()=>{a.invalidateQueries({queryKey:G}),i(n("inventory.spoolRestored"),"success")},onError:he=>{he instanceof _i&&he.status===404?i(n("inventory.restoreSpoolNotFound"),"error"):he instanceof _i&&he.status===503?i(n("inventory.spoolmanUnreachable"),"error"):i(n("inventory.restoreFailed"),"error")}}),_e=async he=>{if(he.last_scale_weight!=null)try{t?await se.syncSpoolmanSpoolWeight(he.id,he.last_scale_weight):await Xr.updateSpoolWeight(he.id,he.last_scale_weight),a.invalidateQueries({queryKey:G});const Fe=[he.brand,he.material,he.color_name].filter(Boolean).join(" ");i(`Synced "${Fe}" to scale weight`,"success")}catch(Fe){const Qe=Fe instanceof _i&&Fe.status===404,Ze=Fe instanceof _i&&Fe.status===503;i(n(Qe?"inventory.syncWeightSpoolNotFound":Ze?"inventory.syncWeightSpoolmanUnreachable":"inventory.syncWeightFailed"),"error")}},Oe=ie?.low_stock_threshold??20,[Ie,Ke]=v.useState(!1),[rt,st]=v.useState(Oe.toString());v.useEffect(()=>{Ie||st(Oe.toString())},[Oe,Ie]);const Re=it({mutationFn:he=>se.updateSettings({low_stock_threshold:he}),onSuccess:()=>{a.invalidateQueries({queryKey:["settings"]}),i(n("common.saved"),"success"),Ke(!1)},onError:()=>{i(n("inventory.lowStockThresholdError"),"error")}}),tt=v.useMemo(()=>{if(!Y)return null;let he=0,Fe=0,Qe=0,Ze=0;const Ye={};for(const ft of Y){if(ft.archived_at)continue;Ze++;const et=Math.max(0,ft.label_weight-ft.weight_used);he+=et,Fe+=ft.weight_used;const jt=ft.label_weight>0?et/ft.label_weight*100:0,St=ft.low_stock_threshold_pct??Oe;jt{const he={};for(const Fe of ne||[])he[Fe.spool_id]={printer_id:Fe.printer_id,printer_name:Fe.printer_name,ams_id:Fe.ams_id,tray_id:Fe.tray_id,ams_label:Fe.ams_label??null};for(const Fe of xe)typeof Fe?.spoolman_spool_id!="number"||Fe.spoolman_spool_id<=0||typeof Fe.printer_id!="number"||typeof Fe.ams_id!="number"||typeof Fe.tray_id!="number"||he[Fe.spoolman_spool_id]||(he[Fe.spoolman_spool_id]={printer_id:Fe.printer_id,printer_name:Fe.printer_name??null,ams_id:Fe.ams_id,tray_id:Fe.tray_id,ams_label:Fe.ams_label??null});return he},[ne,xe]),fe=v.useMemo(()=>{const he={};for(const Fe of ve||[])he[Fe.id]=Fe;return he},[ve]),Ae=v.useMemo(()=>tt?Object.entries(tt.byMaterial).sort((he,Fe)=>Fe[1].weight-he[1].weight).slice(0,4):[],[tt]),$e=v.useMemo(()=>{let he=Y||[];if(x==="active"?he=he.filter(Fe=>!Fe.archived_at):he=he.filter(Fe=>!!Fe.archived_at),N==="used"?he=he.filter(Fe=>Fe.weight_used>0):N==="new"?he=he.filter(Fe=>Fe.weight_used===0):N==="lowstock"&&(he=he.filter(Fe=>{const Qe=Math.max(0,Fe.label_weight-Fe.weight_used),Ze=Fe.label_weight>0?Qe/Fe.label_weight*100:0,Ye=Fe.low_stock_threshold_pct??Oe;return ZeFe.material===P)),A&&(he=he.filter(Fe=>Fe.brand===A)),S&&(S==="__none__"?he=he.filter(Fe=>!Fe.category):he=he.filter(Fe=>Fe.category===S)),z){const Fe=Number(z);he=he.filter(Qe=>Qe.core_weight_catalog_id===Fe)}return H==="stock"?he=he.filter(Fe=>!Fe.slicer_filament):H==="configured"&&(he=he.filter(Fe=>!!Fe.slicer_filament)),Z&&(he=rI(he,Z)),he},[Y,x,N,P,A,S,z,H,Z,Oe]),Be=()=>B(0),nt=[...new Set(Y?.map(he=>he.material)||[])].sort(),gt=[...new Set(Y?.map(he=>he.brand).filter(Boolean)||[])].sort(),yt=[...new Set(Y?.map(he=>he.category?.trim()).filter(Boolean)||[])].sort(),ot=(Y??[]).some(he=>!he.category),Ht=[...new Set(Y?.map(he=>he.core_weight_catalog_id).filter(he=>he!=null)||[])].sort((he,Fe)=>{const Qe=(fe[he]?.name||"").toLowerCase(),Ze=(fe[Fe]?.name||"").toLowerCase();return Qe.localeCompare(Ze)}),Kt=x!=="active"||N!=="all"||!!P||!!A||!!S||!!z||H!=="all"||!!Z,Zt=he=>{ae(he),est(he)},Yt=v.useMemo(()=>W.filter(he=>he.visible).map(he=>he.id),[W]),gn=he=>{gF[he]&&(ue(Fe=>{let Qe;return Fe?.column===he?Qe=Fe.direction==="asc"?{column:he,direction:"desc"}:null:Qe={column:he,direction:"asc"},ast(Qe),Qe}),Be())},ln=v.useMemo(()=>{if(!me)return $e;const he=gF[me.column];return he?[...$e].sort((Qe,Ze)=>{const Ye=he(Qe,Ue),ft=he(Ze,Ue);return Yeft?me.direction==="asc"?1:-1:0}):$e},[$e,me,Ue]),pt=v.useMemo(()=>{if(!Te)return ln.map(Ze=>({type:"single",spool:Ze}));const he=new Map;for(const Ze of ln)if(!(Ze.weight_used>0||Ue[Ze.id])){const Ye=xQ(Ze),ft=he.get(Ye);ft?ft.push(Ze):he.set(Ye,[Ze])}const Fe=[],Qe=new Set;for(const Ze of ln){if(Ze.weight_used>0||Ue[Ze.id]){Fe.push({type:"single",spool:Ze});continue}const Ye=xQ(Ze);if(Qe.has(Ye))continue;Qe.add(Ye);const ft=he.get(Ye);ft.length===1?Fe.push({type:"single",spool:ft[0]}):Fe.push({type:"group",key:Ye,spools:ft,representative:ft[0]})}return Fe},[ln,Te,Ue]),at=X===-1,vt=pt.length,_t=at?vt||1:X,Dt=Math.max(1,Math.ceil(vt/_t)),De=at?0:Math.min(j,Dt-1),je=at?pt:pt.slice(De*_t,(De+1)*_t),Ve=()=>{const he=!Te;$(he),D(new Set),Be();try{localStorage.setItem("bambuddy-inventory-group",String(he))}catch{}},Je=he=>{D(Fe=>{const Qe=new Set(Fe);return Qe.has(he)?Qe.delete(he):Qe.add(he),Qe})},Le=he=>{O(he),B(0);try{localStorage.setItem("bambuddy-inventory-pageSize",String(he))}catch{}},dt=()=>{_("active"),C("all"),T(""),F(""),M(""),I(""),L("all"),re(""),Be()};return r.jsxs("div",{className:"p-4 md:p-8 space-y-6",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsxs("h1",{className:"text-2xl font-bold text-white flex items-center gap-3",children:[r.jsx(Br,{className:"w-7 h-7 text-bambu-green"}),n("inventory.title")]}),r.jsx("p",{className:"text-bambu-gray mt-1",children:n("inventory.subtitle")})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsxs(Me,{variant:"secondary",disabled:$e.length===0,onClick:()=>g($e.map(he=>he.id)),title:$e.length===0?n("inventory.labels.noSpoolsTitle","No spools to label"):n("inventory.labels.bulkTitle","Pick spools to print labels for from the {{count}} currently shown",{count:$e.length}),children:[r.jsx(pr,{className:"w-4 h-4"}),n("inventory.labels.printLabels","Print labels…")]}),r.jsxs(Me,{onClick:()=>m({spool:null,mode:"create"}),children:[r.jsx(ar,{className:"w-4 h-4"}),n("inventory.addSpool")]})]})]}),tt&&!Q&&r.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-5 gap-3",children:[r.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg p-4",children:[r.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[r.jsx(Br,{className:"w-4 h-4 text-bambu-green"}),r.jsx("span",{className:"text-xs text-bambu-gray font-medium uppercase tracking-wide",children:n("inventory.totalInventory")})]}),r.jsx("div",{className:"text-xl font-bold text-white",children:au(tt.totalWeight,!0)}),r.jsxs("div",{className:"text-xs text-bambu-gray mt-1",children:[tt.totalSpools," ",tt.totalSpools!==1?n("inventory.spools"):n("inventory.spool")]})]}),r.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg p-4",children:[r.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[r.jsx(RS,{className:"w-4 h-4 text-blue-400"}),r.jsx("span",{className:"text-xs text-bambu-gray font-medium uppercase tracking-wide",children:n("inventory.totalConsumed")})]}),r.jsx("div",{className:"text-xl font-bold text-white",children:au(tt.totalConsumed,!0)}),r.jsx("div",{className:"text-xs text-bambu-gray mt-1",children:n("inventory.sinceTracking")})]}),r.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg p-4",children:[r.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[r.jsx(oa,{className:"w-4 h-4 text-green-400"}),r.jsx("span",{className:"text-xs text-bambu-gray font-medium uppercase tracking-wide",children:n("inventory.byMaterial")})]}),r.jsx("div",{className:"flex flex-wrap gap-1.5 mt-1",children:Ae.map(([he,Fe])=>r.jsxs("span",{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-medium ${tst[he]||"bg-bambu-dark-tertiary text-bambu-gray"}`,children:[he," ",r.jsx("span",{className:"opacity-70",children:au(Fe.weight,!0)})]},he))})]}),r.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg p-4",children:[r.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[r.jsx(pr,{className:"w-4 h-4 text-purple-400"}),r.jsx("span",{className:"text-xs text-bambu-gray font-medium uppercase tracking-wide",children:n("inventory.inPrinter")})]}),r.jsx("div",{className:"text-xl font-bold text-white",children:Ce}),r.jsx("div",{className:"text-xs text-bambu-gray mt-1",children:n("inventory.loadedInAms")})]}),r.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg p-4",children:[r.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[r.jsx(Nn,{className:"w-4 h-4 text-yellow-400"}),r.jsx("span",{className:"text-xs text-bambu-gray font-medium uppercase tracking-wide",children:n("inventory.lowStock")})]}),r.jsx("div",{className:`text-xl font-bold ${tt.lowStock>0?"text-yellow-400":"text-white"}`,children:tt.lowStock}),r.jsx("div",{className:"text-xs text-bambu-gray mt-1 flex items-center gap-2",children:Ie?r.jsxs("form",{onSubmit:he=>{he.preventDefault();const Fe=parseFloat(rt);!isNaN(Fe)&&Fe>=.1&&Fe<=99.9?Re.mutate(Fe):i(n("inventory.lowStockThresholdError"),"error")},className:"flex items-center gap-2",children:[r.jsx("span",{className:"text-xs text-bambu-gray",children:"<"}),r.jsx("input",{type:"text",inputMode:"decimal",pattern:"^\\d{0,2}(\\.\\d?)?$",maxLength:4,value:rt,onChange:he=>{const Fe=he.target.value.replace(/[^\d.]/g,"");/^\d{0,2}(\.\d?)?$/.test(Fe)&&st(Fe)},className:"px-1.5 py-1 rounded border border-bambu-dark-tertiary text-xs text-white bg-bambu-dark-secondary focus:outline-none focus:border-bambu-green w-14 text-center",onWheel:he=>he.currentTarget.blur(),disabled:Re.isPending}),r.jsx("span",{className:"text-xs text-bambu-gray",children:"%"}),r.jsx(Me,{type:"submit",size:"sm",disabled:Re.isPending,children:n("common.save")}),r.jsx(Me,{type:"button",size:"sm",variant:"ghost",onClick:()=>Ke(!1),disabled:Re.isPending,children:n("common.cancel")})]}):r.jsxs(r.Fragment,{children:[r.jsxs("span",{className:"text-bambu-gray",children:["< ",Oe,"%"]}),r.jsx("button",{className:"p-1.5 text-bambu-gray hover:text-white rounded transition-colors",title:n("common.edit"),onClick:()=>{st(Oe.toString()),Ke(!0)},children:r.jsx(fc,{className:"w-4 h-4"})})]})})]})]}),r.jsxs("div",{className:"flex flex-col sm:flex-row gap-3 items-start sm:items-center justify-between",children:[r.jsxs("div",{className:`relative flex-1 max-w-md ${J==="forecast"?"invisible pointer-events-none":""}`,children:[r.jsx(Sr,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50"}),r.jsx("input",{type:"text",value:Z,onChange:he=>{re(he.target.value),Be()},placeholder:n("inventory.search"),className:"w-full pl-10 pr-8 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green"}),Z&&r.jsx("button",{onClick:()=>{re(""),Be()},className:"absolute right-3 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white",children:r.jsx(Bt,{className:"w-4 h-4"})})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[J==="table"&&r.jsxs("button",{onClick:()=>ye(!0),className:"flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium text-bambu-gray border border-bambu-dark-tertiary rounded-lg hover:bg-bambu-dark-tertiary transition-colors",title:n("inventory.configureColumns"),children:[r.jsx(wge,{className:"w-4 h-4"}),r.jsx("span",{className:"hidden sm:inline",children:n("inventory.columns")})]}),J!=="forecast"&&r.jsxs("button",{onClick:Ve,className:`flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium border rounded-lg transition-colors ${Te?"bg-bambu-green/20 text-bambu-green border-bambu-green/30":"text-bambu-gray border-bambu-dark-tertiary hover:bg-bambu-dark-tertiary"}`,title:n("inventory.groupSimilar"),children:[r.jsx(Tbe,{className:"w-4 h-4"}),r.jsx("span",{className:"hidden sm:inline",children:n("inventory.groupSimilar")})]}),r.jsxs("div",{className:"flex bg-bambu-dark-primary border border-bambu-dark-tertiary rounded-lg overflow-hidden",children:[r.jsxs("button",{onClick:()=>de("table"),className:`flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium transition-colors ${J==="table"?"bg-bambu-green text-white":"text-bambu-gray hover:bg-bambu-dark-tertiary"}`,children:[r.jsx(Dye,{className:"w-4 h-4"}),r.jsx("span",{className:"hidden sm:inline",children:n("inventory.table")})]}),r.jsxs("button",{onClick:()=>de("cards"),className:`flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium transition-colors ${J==="cards"?"bg-bambu-green text-white":"text-bambu-gray hover:bg-bambu-dark-tertiary"}`,children:[r.jsx(TS,{className:"w-4 h-4"}),r.jsx("span",{className:"hidden sm:inline",children:n("inventory.cards")})]}),r.jsxs("button",{onClick:()=>l&&de("forecast"),disabled:!l,title:l?void 0:n("forecast.noReadAccess"),className:`flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium transition-colors disabled:opacity-40 disabled:cursor-not-allowed ${J==="forecast"?"bg-bambu-green text-white":"text-bambu-gray hover:bg-bambu-dark-tertiary"}`,children:[l?r.jsx(rC,{className:"w-4 h-4"}):r.jsx(lc,{className:"w-4 h-4"}),r.jsx("span",{className:"hidden sm:inline",children:n("forecast.title")})]})]})]})]}),r.jsxs("div",{className:`flex flex-wrap items-center gap-2 ${J==="forecast"?"hidden":""}`,children:[r.jsxs("div",{className:"flex items-center rounded-lg border border-bambu-dark-tertiary overflow-hidden",children:[r.jsxs("button",{onClick:()=>{_("active"),Be()},className:`flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium transition-colors ${x==="active"?"bg-bambu-green/20 text-bambu-green":"text-bambu-gray hover:bg-bambu-dark-tertiary"}`,children:[r.jsx(Br,{className:"w-3.5 h-3.5"}),n("inventory.active")]}),r.jsxs("button",{onClick:()=>{_("archived"),Be()},className:`flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium transition-colors ${x==="archived"?"bg-bambu-green/20 text-bambu-green":"text-bambu-gray hover:bg-bambu-dark-tertiary"}`,children:[r.jsx(ro,{className:"w-3.5 h-3.5"}),n("inventory.archived")]})]}),r.jsx("div",{className:"w-px h-5 bg-bambu-dark-tertiary"}),r.jsxs("div",{className:"flex items-center rounded-lg border border-bambu-dark-tertiary overflow-hidden",children:[r.jsx("button",{onClick:()=>{C("all"),Be()},className:`px-3 py-1.5 text-xs font-medium transition-colors ${N==="all"?"bg-bambu-green/20 text-bambu-green":"text-bambu-gray hover:bg-bambu-dark-tertiary"}`,children:n("inventory.all")}),r.jsxs("button",{onClick:()=>{C("used"),Be()},className:`flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium transition-colors ${N==="used"?"bg-bambu-green/20 text-bambu-green":"text-bambu-gray hover:bg-bambu-dark-tertiary"}`,children:[r.jsx(Zn,{className:"w-3.5 h-3.5"}),n("inventory.used")]}),r.jsx("button",{onClick:()=>{C("new"),Be()},className:`px-3 py-1.5 text-xs font-medium transition-colors ${N==="new"?"bg-bambu-green/20 text-bambu-green":"text-bambu-gray hover:bg-bambu-dark-tertiary"}`,children:n("inventory.new")}),r.jsxs("button",{onClick:()=>{C("lowstock"),Be()},className:`flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium transition-colors ${N==="lowstock"?"bg-yellow-500/20 text-yellow-400":"text-bambu-gray hover:bg-bambu-dark-tertiary"}`,children:[r.jsx(Nn,{className:"w-3.5 h-3.5"}),n("inventory.lowStock")]})]}),r.jsxs("div",{className:"flex items-center rounded-lg border border-bambu-dark-tertiary overflow-hidden",children:[r.jsx("button",{onClick:()=>{L("all"),Be()},className:`px-3 py-1.5 text-xs font-medium transition-colors ${H==="all"?"bg-bambu-green/20 text-bambu-green":"text-bambu-gray hover:bg-bambu-dark-tertiary"}`,children:n("inventory.all")}),r.jsx("button",{onClick:()=>{L("stock"),Be()},className:`px-3 py-1.5 text-xs font-medium transition-colors ${H==="stock"?"bg-amber-500/20 text-amber-400":"text-bambu-gray hover:bg-bambu-dark-tertiary"}`,children:n("inventory.stock")}),r.jsx("button",{onClick:()=>{L("configured"),Be()},className:`px-3 py-1.5 text-xs font-medium transition-colors ${H==="configured"?"bg-bambu-green/20 text-bambu-green":"text-bambu-gray hover:bg-bambu-dark-tertiary"}`,children:n("inventory.configured")})]}),r.jsx("div",{className:"w-px h-5 bg-bambu-dark-tertiary"}),r.jsxs("select",{value:P,onChange:he=>{T(he.target.value),Be()},className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${P?"bg-bambu-green/20 text-bambu-green border-bambu-green/30":"bg-transparent text-bambu-gray border-bambu-dark-tertiary hover:bg-bambu-dark-tertiary"}`,children:[r.jsx("option",{value:"",children:n("inventory.material")}),nt.map(he=>r.jsx("option",{value:he,children:he},he))]}),r.jsxs("select",{value:A,onChange:he=>{F(he.target.value),Be()},className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${A?"bg-bambu-green/20 text-bambu-green border-bambu-green/30":"bg-transparent text-bambu-gray border-bambu-dark-tertiary hover:bg-bambu-dark-tertiary"}`,children:[r.jsx("option",{value:"",children:n("inventory.brand")}),gt.map(he=>r.jsx("option",{value:he,children:he},he))]}),(yt.length>0||S)&&r.jsxs("select",{value:S,onChange:he=>{M(he.target.value),Be()},className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${S?"bg-bambu-green/20 text-bambu-green border-bambu-green/30":"bg-transparent text-bambu-gray border-bambu-dark-tertiary hover:bg-bambu-dark-tertiary"}`,children:[r.jsx("option",{value:"",children:n("inventory.category")}),yt.map(he=>r.jsx("option",{value:he,children:he},he)),ot&&r.jsx("option",{value:"__none__",children:n("inventory.categoryNone")})]}),Ht.length>0&&r.jsxs("select",{value:z,onChange:he=>{I(he.target.value),Be()},className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${z?"bg-bambu-green/20 text-bambu-green border-bambu-green/30":"bg-transparent text-bambu-gray border-bambu-dark-tertiary hover:bg-bambu-dark-tertiary"}`,children:[r.jsx("option",{value:"",children:n("inventory.spoolName")}),Ht.map(he=>r.jsx("option",{value:he,children:fe[he]?.name||`#${he}`},he))]}),Kt&&r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"w-px h-5 bg-bambu-dark-tertiary"}),r.jsxs("button",{onClick:dt,className:"flex items-center gap-1 text-xs text-bambu-gray hover:text-bambu-green transition-colors",children:[r.jsx(Bt,{className:"w-3.5 h-3.5"}),n("inventory.clearFilters")]})]}),J!=="forecast"&&r.jsxs("span",{className:"ml-auto text-xs text-bambu-gray",children:[ln.length," ",ln.length!==1?n("inventory.spools"):n("inventory.spool"),Te&&vt0?r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4",children:je.map(he=>{if(he.type==="group"){const{key:Ye,spools:ft,representative:et}=he,jt=nj({rgba:et.rgba,extraColors:et.extra_colors,effectType:et.effect_type,subtype:et.subtype,effectSize:"groupheader"}),St=K.has(Ye);return r.jsxs("div",{className:"col-span-full",children:[r.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg overflow-hidden border border-bambu-green/30 hover:border-bambu-green transition-colors cursor-pointer",onClick:()=>Je(Ye),children:[r.jsx("div",{className:"h-10 flex items-center px-4 gap-3",style:jt,children:r.jsx("span",{className:"bg-white/90 text-gray-800 px-3 py-0.5 rounded-full text-sm font-medium",children:CT(et.color_name,et.rgba)||"-"})}),r.jsxs("div",{className:"px-4 py-3 flex items-center justify-between",children:[r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx(Rn,{className:`w-4 h-4 text-bambu-gray transition-transform ${St?"":"-rotate-90"}`}),r.jsxs("div",{children:[r.jsxs("h3",{className:"font-semibold text-white",children:[et.material,et.subtype?` ${et.subtype}`:""]}),r.jsx("p",{className:"text-sm text-bambu-gray",children:et.brand||"-"})]})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"text-sm text-bambu-gray",children:au(et.label_weight)}),r.jsx("span",{className:"text-xs font-medium bg-bambu-green/20 text-bambu-green px-2 py-0.5 rounded-full",children:n("inventory.groupedSpools",{count:ft.length})})]})]})]}),St&&r.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4 mt-2 ml-4",children:ft.map(Lt=>{const Ot=Math.max(0,Lt.label_weight-Lt.weight_used),qe=Lt.label_weight>0?Ot/Lt.label_weight*100:0;return r.jsx(yQ,{spool:Lt,remaining:Ot,pct:qe,onClick:()=>m({spool:Lt,mode:"edit"}),onPrintLabel:()=>g([Lt.id]),onCopy:()=>m({spool:Lt,mode:"copy"}),t:n},Lt.id)})})]},`group-${Ye}`)}const Fe=he.spool,Qe=Math.max(0,Fe.label_weight-Fe.weight_used),Ze=Fe.label_weight>0?Qe/Fe.label_weight*100:0;return r.jsx(yQ,{spool:Fe,remaining:Qe,pct:Ze,onClick:()=>m({spool:Fe,mode:"edit"}),onPrintLabel:()=>g([Fe.id]),onCopy:()=>m({spool:Fe,mode:"copy"}),t:n},Fe.id)})}),r.jsx(ost,{pageIndex:De,pageSize:X,totalRows:vt,totalPages:Dt,onPageChange:B,onPageSizeChange:Le,t:n})]}):r.jsx(vQ,{hasFilters:Kt,onAddSpool:()=>m({spool:null,mode:"create"}),t:n}):je.length>0?r.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg overflow-hidden border border-bambu-dark-tertiary",children:[r.jsx("div",{className:"overflow-x-auto",children:r.jsxs("table",{className:"w-full",children:[r.jsx("thead",{children:r.jsxs("tr",{className:"border-b border-bambu-dark-tertiary bg-bambu-dark-tertiary/30",children:[Yt.map(he=>{const Fe=!!gF[he],Qe=me?.column===he;return r.jsx("th",{className:`text-left py-3 px-4 text-xs font-medium uppercase tracking-wide select-none ${he==="remaining"?"min-w-[150px]":""} ${Fe?"cursor-pointer hover:text-bambu-green transition-colors":""} ${Qe?"text-bambu-green":"text-bambu-gray"}`,onClick:Fe?()=>gn(he):void 0,children:r.jsxs("span",{className:"inline-flex items-center gap-1",children:[nst[he]?.(n)??he,Fe&&(Qe?me.direction==="asc"?r.jsx(Hm,{className:"w-3 h-3"}):r.jsx(Bh,{className:"w-3 h-3"}):r.jsx(vT,{className:"w-3 h-3 opacity-30"}))]})},he)}),r.jsx("th",{className:"text-right py-3 px-4 text-xs font-medium text-bambu-gray uppercase tracking-wide",children:n("common.actions")})]})}),r.jsx("tbody",{children:je.map(he=>{if(he.type==="group"){const{key:Ye,spools:ft,representative:et}=he,jt=K.has(Ye),St=Math.max(0,et.label_weight-et.weight_used),Lt=et.label_weight>0?St/et.label_weight*100:0;return r.jsx(lst,{spools:ft,representative:et,remaining:St,pct:Lt,isExpanded:jt,onToggle:()=>Je(Ye),onEdit:Ot=>m({spool:Ot,mode:"edit"}),onCopy:Ot=>m({spool:Ot,mode:"copy"}),onArchive:Ot=>b({type:"archive",spoolId:Ot}),onDelete:Ot=>b({type:"delete",spoolId:Ot}),onPrintLabel:Ot=>g([Ot]),visibleColumns:Yt,assignmentMap:Ue,catalogMap:fe,currencySymbol:Xe,dateFormat:U,t:n,onSyncWeight:_e},`group-${Ye}`)}const Fe=he.spool,Qe=Math.max(0,Fe.label_weight-Fe.weight_used),Ze=Fe.label_weight>0?Qe/Fe.label_weight*100:0;return r.jsx(Zce,{spool:Fe,remaining:Qe,pct:Ze,onEdit:()=>m({spool:Fe,mode:"edit"}),onCopy:()=>m({spool:Fe,mode:"copy"}),onRestore:()=>ze.mutate(Fe.id),onArchive:()=>b({type:"archive",spoolId:Fe.id}),onDelete:()=>b({type:"delete",spoolId:Fe.id}),onPrintLabel:()=>g([Fe.id]),visibleColumns:Yt,assignmentMap:Ue,catalogMap:fe,currencySymbol:Xe,dateFormat:U,t:n,onSyncWeight:_e},Fe.id)})})]})}),r.jsxs("div",{className:"flex items-center justify-between px-4 py-3 bg-bambu-dark-tertiary/50 border-t border-bambu-dark-tertiary text-sm",children:[r.jsx("span",{className:"text-bambu-gray",children:at?`${vt} ${n(vt!==1?"inventory.spools":"inventory.spool")}`:r.jsxs(r.Fragment,{children:[n("inventory.showing")," ",De*_t+1," ",n("inventory.to")," ",Math.min((De+1)*_t,vt)," ",n("inventory.of")," ",vt," ",n("inventory.spools")]})}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"text-bambu-gray",children:n("inventory.show")}),r.jsxs("select",{value:X,onChange:he=>Le(Number(he.target.value)),className:"px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:outline-none focus:border-bambu-green",children:[[15,30,50,100].map(he=>r.jsx("option",{value:he,children:he},he)),r.jsx("option",{value:-1,children:n("inventory.all")})]}),!at&&r.jsxs(r.Fragment,{children:[r.jsx("button",{onClick:()=>B(0),disabled:De===0,className:"p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors",title:"First page",children:r.jsx(hO,{className:"w-4 h-4"})}),r.jsx("button",{onClick:()=>B(he=>Math.max(0,he-1)),disabled:De===0,className:"p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors",children:r.jsx(el,{className:"w-4 h-4"})}),r.jsxs("span",{className:"text-bambu-gray px-2 whitespace-nowrap",children:[n("inventory.page")," ",De+1," ",n("inventory.of")," ",Dt]}),r.jsx("button",{onClick:()=>B(he=>Math.min(Dt-1,he+1)),disabled:De>=Dt-1,className:"p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors",children:r.jsx(Va,{className:"w-4 h-4"})}),r.jsx("button",{onClick:()=>B(Dt-1),disabled:De>=Dt-1,className:"p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors",title:"Last page",children:r.jsx(fO,{className:"w-4 h-4"})})]})]})]})]}):r.jsx(vQ,{hasFilters:Kt,onAddSpool:()=>m({spool:null,mode:"create"}),t:n}),u!==null&&r.jsx(Vit,{isOpen:!0,onClose:()=>m(null),spool:u.spool,mode:u.mode,currencySymbol:Xe,spoolmanMode:t,spoolsQueryKey:G}),f&&r.jsx(vn,{title:f.type==="delete"?n("common.delete"):n("inventory.archive"),message:f.type==="delete"?n("inventory.deleteConfirm"):n("inventory.archiveConfirm"),confirmText:f.type==="delete"?n("common.delete"):n("inventory.archive"),variant:f.type==="delete"?"danger":"warning",onConfirm:()=>{f.type==="delete"?be.mutate(f.spoolId):Ee.mutate(f.spoolId),b(null)},onCancel:()=>b(null)}),r.jsx(Git,{isOpen:pe,onClose:()=>ye(!1),columns:W,defaultColumns:BN,onSave:Zt}),r.jsx(Zit,{isOpen:w!==null,onClose:()=>g(null),availableSpools:$e,initialSelectedIds:w??[],spoolmanMode:!1})]})}function ost({pageIndex:t,pageSize:e,totalRows:n,totalPages:a,onPageChange:i,onPageSizeChange:s,t:o}){const l=e===-1;if(a<=1&&!l)return null;const c=l?n||1:e;return r.jsxs("div",{className:"flex items-center justify-between pt-2 text-sm",children:[r.jsx("span",{className:"text-bambu-gray",children:l?`${n} ${o(n!==1?"inventory.spools":"inventory.spool")}`:r.jsxs(r.Fragment,{children:[o("inventory.showing")," ",t*c+1," ",o("inventory.to")," ",Math.min((t+1)*c,n)," ",o("inventory.of")," ",n," ",o("inventory.spools")]})}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"text-bambu-gray",children:o("inventory.show")}),r.jsxs("select",{value:e,onChange:d=>s(Number(d.target.value)),className:"px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:outline-none focus:border-bambu-green",children:[[15,30,50,100].map(d=>r.jsx("option",{value:d,children:d},d)),r.jsx("option",{value:-1,children:o("inventory.all")})]}),!l&&r.jsxs(r.Fragment,{children:[r.jsx("button",{onClick:()=>i(0),disabled:t===0,className:"p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors",children:r.jsx(hO,{className:"w-4 h-4"})}),r.jsx("button",{onClick:()=>i(Math.max(0,t-1)),disabled:t===0,className:"p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors",children:r.jsx(el,{className:"w-4 h-4"})}),r.jsxs("span",{className:"text-bambu-gray px-2 whitespace-nowrap",children:[o("inventory.page")," ",t+1," ",o("inventory.of")," ",a]}),r.jsx("button",{onClick:()=>i(Math.min(a-1,t+1)),disabled:t>=a-1,className:"p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors",children:r.jsx(Va,{className:"w-4 h-4"})}),r.jsx("button",{onClick:()=>i(a-1),disabled:t>=a-1,className:"p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors",children:r.jsx(fO,{className:"w-4 h-4"})})]})]})]})}function yQ({spool:t,remaining:e,pct:n,onClick:a,onPrintLabel:i,onCopy:s,t:o}){const l=nj({rgba:t.rgba,extraColors:t.extra_colors,effectType:t.effect_type,subtype:t.subtype,effectSize:"card"});return r.jsxs("div",{className:`bg-bambu-dark-secondary rounded-lg overflow-hidden border border-bambu-dark-tertiary hover:border-bambu-green transition-colors cursor-pointer ${t.archived_at?"opacity-50":""}`,onClick:a,children:[r.jsxs("div",{className:"h-14 flex items-center justify-center",style:l,children:[r.jsx("span",{className:"bg-white/90 text-gray-800 px-3 py-0.5 rounded-full text-sm font-medium",children:CT(t.color_name,t.rgba)||"-"}),s&&r.jsx("button",{type:"button",onClick:c=>{c.stopPropagation(),s()},className:"p-1.5 bg-black/20 hover:bg-black/40 text-white rounded-full transition-colors",title:o("inventory.copySpool"),children:r.jsx(Mi,{className:"w-3.5 h-3.5"})})]}),r.jsxs("div",{className:"p-4 space-y-3",children:[r.jsxs("div",{className:"flex items-start justify-between gap-2",children:[r.jsxs("div",{children:[r.jsxs("h3",{className:"font-semibold text-white",children:[t.material,t.subtype?` ${t.subtype}`:""]}),r.jsx("p",{className:"text-sm text-bambu-gray",children:t.brand||"-"})]}),r.jsxs("div",{className:"flex items-center gap-1",children:[i&&r.jsx("button",{onClick:c=>{c.stopPropagation(),i()},className:"p-1 text-bambu-gray hover:text-white rounded transition-colors",title:o("inventory.labels.printOne"),"aria-label":o("inventory.labels.printOne"),children:r.jsx(pr,{className:"w-4 h-4"})}),r.jsxs("span",{className:"text-xs font-mono text-bambu-gray bg-bambu-dark-tertiary px-2 py-1 rounded",children:["#",t.id]})]})]}),r.jsxs("div",{children:[r.jsxs("div",{className:"flex justify-between text-xs text-bambu-gray mb-1",children:[r.jsx("span",{children:o("inventory.remaining")}),r.jsxs("span",{children:[Math.round(n),"%"]})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("div",{className:"flex-1 h-2 bg-bambu-dark-tertiary rounded-full overflow-hidden",children:r.jsx("div",{className:`h-full rounded-full ${n>50?"bg-bambu-green":n>20?"bg-yellow-500":"bg-red-500"}`,style:{width:`${Math.min(n,100)}%`}})}),r.jsxs("span",{className:"text-xs text-bambu-gray min-w-[40px] text-right",children:[Math.round(e),"g"]})]})]}),r.jsxs("div",{className:"grid grid-cols-2 gap-2 text-xs",children:[r.jsxs("div",{children:[r.jsxs("span",{className:"text-bambu-gray/60",children:[o("inventory.labelWeight"),": "]}),r.jsx("span",{className:"text-bambu-gray",children:au(t.label_weight)})]}),r.jsxs("div",{children:[r.jsxs("span",{className:"text-bambu-gray/60",children:[o("inventory.weightUsed"),": "]}),r.jsx("span",{className:"text-bambu-gray",children:t.weight_used>0?au(t.weight_used):"-"})]})]}),t.note&&r.jsx("div",{className:"text-xs text-bambu-gray/60 pt-2 border-t border-bambu-dark-tertiary truncate",title:t.note,children:t.note})]})]})}function Zce({spool:t,remaining:e,pct:n,onEdit:a,onCopy:i,onRestore:s,onArchive:o,onDelete:l,onPrintLabel:c,visibleColumns:d,assignmentMap:u,catalogMap:m,currencySymbol:p,dateFormat:f,t:b,onSyncWeight:w}){return r.jsxs("tr",{className:`border-b border-bambu-dark-tertiary/50 hover:bg-bambu-dark-tertiary/30 transition-colors cursor-pointer ${t.archived_at?"opacity-50":""}`,onClick:a,children:[d.map(g=>r.jsx("td",{className:"py-3 px-4",children:YI[g]?.({spool:t,remaining:e,pct:n,assignmentMap:u,catalogMap:m,currencySymbol:p,dateFormat:f,t:b,onSyncWeight:w})},g)),r.jsx("td",{className:"py-3 px-4",children:r.jsxs("div",{className:"flex items-center justify-end gap-1",onClick:g=>g.stopPropagation(),children:[r.jsx("button",{onClick:a,className:"p-1.5 text-bambu-gray hover:text-white rounded transition-colors",title:b("common.edit"),children:r.jsx(fc,{className:"w-4 h-4"})}),i&&r.jsx("button",{onClick:i,className:"p-1.5 text-bambu-gray hover:text-bambu-green rounded transition-colors",title:b("inventory.copySpool"),children:r.jsx(Mi,{className:"w-4 h-4"})}),c&&r.jsx("button",{onClick:c,className:"p-1.5 text-bambu-gray hover:text-white rounded transition-colors",title:b("inventory.labels.printOne"),children:r.jsx(pr,{className:"w-4 h-4"})}),t.archived_at?r.jsx("button",{onClick:s,className:"p-1.5 text-bambu-gray hover:text-bambu-green rounded transition-colors",title:b("inventory.restore"),children:r.jsx(gs,{className:"w-4 h-4"})}):r.jsx("button",{onClick:o,className:"p-1.5 text-bambu-gray hover:text-yellow-400 rounded transition-colors",title:b("inventory.archive"),children:r.jsx(ro,{className:"w-4 h-4"})}),r.jsx("button",{onClick:l,className:"p-1.5 text-bambu-gray hover:text-red-400 rounded transition-colors",title:b("common.delete"),children:r.jsx(Jt,{className:"w-4 h-4"})})]})})]})}function lst({spools:t,representative:e,remaining:n,pct:a,isExpanded:i,onToggle:s,onEdit:o,onCopy:l,onArchive:c,onDelete:d,onPrintLabel:u,visibleColumns:m,assignmentMap:p,catalogMap:f,currencySymbol:b,dateFormat:w,t:g,onSyncWeight:x}){return r.jsxs(r.Fragment,{children:[r.jsxs("tr",{className:"border-b border-bambu-dark-tertiary/50 hover:bg-bambu-dark-tertiary/30 transition-colors cursor-pointer bg-bambu-green/5",onClick:s,children:[m.map((_,N)=>r.jsx("td",{className:"py-3 px-4",children:N===0?r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(Rn,{className:`w-4 h-4 text-bambu-gray transition-transform ${i?"":"-rotate-90"}`}),YI[_]?.({spool:e,remaining:n,pct:a,assignmentMap:p,catalogMap:f,currencySymbol:b,dateFormat:w,t:g,onSyncWeight:x})]}):_==="id"?r.jsx("span",{className:"text-xs font-medium bg-bambu-green/20 text-bambu-green px-2 py-0.5 rounded-full",children:g("inventory.groupedSpools",{count:t.length})}):YI[_]?.({spool:e,remaining:n,pct:a,assignmentMap:p,catalogMap:f,currencySymbol:b,dateFormat:w,t:g,onSyncWeight:x})},_)),r.jsx("td",{className:"py-3 px-4",children:r.jsx("span",{className:"text-xs text-bambu-gray",children:t.map(_=>`#${_.id}`).join(", ")})})]}),i&&t.map(_=>{const N=Math.max(0,_.label_weight-_.weight_used),C=_.label_weight>0?N/_.label_weight*100:0;return r.jsx(Zce,{spool:_,remaining:N,pct:C,onEdit:()=>o(_),onCopy:l?()=>l(_):void 0,onRestore:()=>{},onArchive:()=>c(_.id),onDelete:()=>d(_.id),onPrintLabel:u?()=>u(_.id):void 0,visibleColumns:m,assignmentMap:p,catalogMap:f,currencySymbol:b,dateFormat:w,t:g,onSyncWeight:x},_.id)})]})}function vQ({hasFilters:t,onAddSpool:e,t:n}){return r.jsxs("div",{className:"flex flex-col items-center justify-center py-16 px-4",children:[r.jsxs("div",{className:"relative mb-6",children:[r.jsx("div",{className:"absolute inset-0 -m-4 bg-bambu-green/5 rounded-full blur-2xl"}),r.jsxs("div",{className:"relative flex items-center justify-center w-24 h-24 rounded-2xl bg-gradient-to-br from-bambu-dark-secondary to-bambu-dark-tertiary border border-bambu-dark-tertiary shadow-lg",children:[r.jsx("div",{className:"absolute -top-1 -right-1 w-3 h-3 rounded-full bg-bambu-green/30"}),r.jsx("div",{className:"absolute -bottom-2 -left-2 w-2 h-2 rounded-full bg-bambu-green/20"}),t?r.jsx(Sr,{className:"w-10 h-10 text-bambu-gray/40",strokeWidth:1.5}):r.jsxs("div",{className:"relative",children:[r.jsx("div",{className:"w-14 h-14 rounded-full border-4 border-bambu-gray/20 flex items-center justify-center",children:r.jsx("div",{className:"w-6 h-6 rounded-full bg-bambu-gray/10 border-2 border-bambu-gray/20"})}),r.jsx("div",{className:"absolute -bottom-1 -right-1 w-6 h-6 rounded-full bg-bambu-green flex items-center justify-center shadow-md",children:r.jsx("span",{className:"text-white text-lg font-bold leading-none",children:"+"})})]})]})]}),r.jsx("h3",{className:"text-lg font-semibold text-white mb-2 text-center",children:t?n("inventory.noSpoolsMatch"):n("inventory.noSpools").split(".")[0]}),r.jsx("p",{className:"text-sm text-bambu-gray text-center max-w-sm mb-6",children:n(t?"inventory.noSpoolsMatchDesc":"inventory.noSpools")}),!t&&r.jsxs(Me,{onClick:e,children:[r.jsx(Br,{className:"w-4 h-4"}),n("inventory.addSpool")]})]})}function zd(t,e){const n=t?.[e];return typeof n=="string"?n:""}function cst(t){return t.replace(/(https?:\/\/(?:makerworld|public-cdn)\.bblmw\.com\/[^\s"']+)/gi,e=>`/api/v1/makerworld/thumbnail?url=${encodeURIComponent(e)}`)}function bF(t){return t?/^https?:\/\/(makerworld|public-cdn)\.bblmw\.com\//i.test(t)?`/api/v1/makerworld/thumbnail?url=${encodeURIComponent(t)}`:t:""}function Xp(t,e){const n=t?.[e];return typeof n=="number"?n:null}function dst(t,e){const n=t?.[e];return n&&typeof n=="object"&&!Array.isArray(n)?n:void 0}function Jce(t,e=0,n=[]){n.push({folder:t,depth:e});for(const a of t.children??[])Jce(a,e+1,n);return n}function ust(t,e){return t<1?e("makerworld.phaseResolving"):e("makerworld.phaseDownloading")}function mst(t){const[e,n]=v.useState(0);return v.useEffect(()=>{if(!t){n(0);return}const a=Date.now(),i=()=>n(Math.floor((Date.now()-a)/1e3));i();const s=window.setInterval(i,1e3);return()=>window.clearInterval(s)},[t]),e}function pst(){const{t}=kt(),{hasPermission:e}=cr(),{showToast:n}=rn(),a=en(),i=e("makerworld:import"),[s,o]=v.useState(""),[l,c]=v.useState(null),[d,u]=v.useState(null),[m,p]=v.useState(null),[f,b]=v.useState(null),[w,g]=v.useState(null),[x,_]=v.useState(""),[N,C]=v.useState({}),P=We({queryKey:["makerworld-status"],queryFn:()=>se.getMakerworldStatus()}),T=We({queryKey:["library-folders"],queryFn:()=>se.getLibraryFolders()}),A=We({queryKey:["makerworld-recent-imports"],queryFn:()=>se.getMakerworldRecentImports(10)}),F=We({queryKey:["settings"],queryFn:()=>se.getSettings()}),S=F.data?.preferred_slicer||"bambu_studio",M=S==="orcaslicer"?"OrcaSlicer":"Bambu Studio",z=F.data?.use_slicer_api??!1,[I,H]=v.useState(null),L=(Y,Q)=>{H({kind:"libraryFile",id:Y,filename:Q})},Z=it({mutationFn:Y=>se.resolveMakerworldUrl(Y),onSuccess:(Y,Q)=>{c(Y),_(Q),C({})},onError:Y=>n(Y.message||t("makerworld.errors.resolveFailed"),"error")});v.useEffect(()=>{l!==null&&s.trim()!==x.trim()&&(c(null),_(""),C({}))},[s,l,x]);const re=it({mutationFn:({instanceId:Y,profileId:Q})=>se.importMakerworldInstance(l?.model_id??0,Y,Q,d),onSuccess:Y=>{a.invalidateQueries({queryKey:["library-files"]}),a.invalidateQueries({queryKey:["library-folders"]}),Y.profile_id&&C(Q=>({...Q,[Y.profile_id]:Y})),n(Y.was_existing?t("makerworld.alreadyInLibrary"):t("makerworld.importSuccess",{filename:Y.filename}),"success")},onError:Y=>n(Y.message||t("makerworld.errors.downloadFailed"),"error")}),J=it({mutationFn:({libraryFileId:Y})=>se.deleteLibraryFile(Y),onSuccess:(Y,{profileId:Q})=>{a.invalidateQueries({queryKey:["library-files"]}),a.invalidateQueries({queryKey:["library-folders"]}),a.invalidateQueries({queryKey:["makerworld-recent-imports"]}),C(oe=>{const ee={...oe};return delete ee[Q],ee}),b(null),n(t("makerworld.importDeleted"),"success")},onError:Y=>{b(null),n(Y.message||t("makerworld.errors.deleteFailed"),"error")}}),de=it({mutationFn:({instanceId:Y,profileId:Q})=>se.importMakerworldInstance(l?.model_id??0,Y,Q,d),onSuccess:async Y=>{a.invalidateQueries({queryKey:["library-files"]}),a.invalidateQueries({queryKey:["library-folders"]}),a.invalidateQueries({queryKey:["makerworld-recent-imports"]}),Y.profile_id&&C(Q=>({...Q,[Y.profile_id]:Y})),z?L(Y.library_file_id,Y.filename):await ye(Y.library_file_id,Y.filename,S)},onError:Y=>n(Y.message||t("makerworld.errors.downloadFailed"),"error")}),me=mst(re.isPending||de.isPending),ue=ust(me,t),W=Y=>{Y?.preventDefault();const Q=s.trim();Q&&Z.mutate(Q)};v.useEffect(()=>{if(!w)return;const Y=Q=>{Q.key==="Escape"?g(null):Q.key==="ArrowLeft"?g(oe=>oe&&oe.index>0?{...oe,index:oe.index-1}:oe):Q.key==="ArrowRight"&&g(oe=>oe&&oe.indexwindow.removeEventListener("keydown",Y)},[w]);const ae=Y=>{const oe=(Array.isArray(Y.pictures)?Y.pictures:[]).filter(ge=>ge!==null&&typeof ge=="object").map(ge=>({name:zd(ge,"name")||"image",url:zd(ge,"url")})).filter(ge=>ge.url);if(oe.length>0)return oe;const ee=zd(Y,"cover");return ee?[{name:"cover",url:ee}]:[]},pe=async()=>{if(!l)return;const Y=l.instances.filter(Q=>{const oe=Xp(Q,"profileId");return oe!==null&&!N[oe]});if(Y.length!==0){p({current:0,total:Y.length});try{for(let Q=0;Q{try{const{token:ee}=await se.createLibrarySlicerToken(Y),ge=se.getLibrarySlicerDownloadUrl(Y,ee,Q);Am(`${window.location.origin}${ge}`,oe)}catch{const ee=se.getLibraryFileDownloadUrl(Y);Am(`${window.location.origin}${ee}`,oe)}},Te=l?.design,$=dst(Te,"designCreator"),K=l?.instances??[],D=(l?.already_imported_library_ids.length??0)>0,j=P.data?.has_cloud_token??!1,B=P.data?.can_download??!1,X=v.useMemo(()=>zd(Te,"coverUrl"),[Te]),O=zd(Te,"title"),ie=zd(Te,"summary"),U=zd(Te,"license"),G=Xp(Te,"downloadCount");return r.jsxs("div",{className:"p-4 md:p-8 max-w-screen-2xl space-y-6",children:[r.jsxs("div",{children:[r.jsxs("h1",{className:"text-2xl font-bold text-white flex items-center gap-3",children:[r.jsx(no,{className:"w-7 h-7 text-bambu-green"}),t("makerworld.title")]}),r.jsx("p",{className:"text-bambu-gray mt-1",children:t("makerworld.description")})]}),r.jsxs("div",{className:"grid gap-6 lg:grid-cols-[1fr_20rem]",children:[r.jsxs("div",{className:"space-y-6 min-w-0",children:[!j&&r.jsx(Ct,{className:"border-amber-300 dark:border-amber-700 bg-amber-50 dark:bg-amber-900/20",children:r.jsx(At,{children:r.jsxs("div",{className:"flex items-start gap-3 py-2",children:[r.jsx($a,{className:"w-5 h-5 text-amber-600 dark:text-amber-400 mt-0.5 shrink-0"}),r.jsxs("div",{className:"text-sm",children:[r.jsx("p",{className:"font-medium text-amber-900 dark:text-amber-100",children:t("makerworld.signInRequiredTitle")}),r.jsxs("p",{className:"text-amber-800 dark:text-amber-200 mt-1",children:[t("makerworld.signInRequiredBody")," ",r.jsx(Is,{to:"/settings?tab=cloud",className:"underline",children:t("makerworld.openCloudSettings")})]})]})]})})}),r.jsxs(Ct,{children:[r.jsx(pn,{children:r.jsx("h2",{className:"text-lg font-semibold",children:t("makerworld.pasteUrlHeader")})}),r.jsx(At,{children:r.jsxs("form",{onSubmit:W,className:"flex gap-2",children:[r.jsx("input",{type:"text",value:s,onChange:Y=>o(Y.target.value),placeholder:t("makerworld.pasteUrlPlaceholder"),className:"flex-1 min-w-0 px-3 py-2 border rounded bg-white dark:bg-gray-800 border-gray-300 dark:border-gray-700",autoComplete:"off"}),r.jsxs(Me,{type:"submit",variant:"primary",disabled:!s.trim()||Z.isPending,children:[Z.isPending?r.jsx(ut,{className:"w-4 h-4 animate-spin"}):r.jsx(YN,{className:"w-4 h-4"}),r.jsx("span",{className:"ml-2",children:t("makerworld.resolveButton")})]})]})})]}),l&&r.jsx(Ct,{children:r.jsx(At,{children:r.jsxs("div",{className:"flex gap-4 py-2",children:[X&&r.jsx("img",{src:bF(X),alt:O,className:"w-32 h-32 object-cover rounded",loading:"lazy"}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("h3",{className:"text-xl font-semibold truncate",children:O||t("makerworld.untitledModel")}),$&&r.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400 mt-1",children:t("makerworld.byCreator",{name:zd($,"name")})}),r.jsxs("div",{className:"flex flex-wrap gap-3 mt-2 text-xs text-gray-500 dark:text-gray-400",children:[G!==null&&r.jsx("span",{children:t("makerworld.downloadsCount",{count:G})}),U&&r.jsxs("span",{children:[t("makerworld.licensePrefix"),": ",U]}),D&&r.jsxs("span",{className:"inline-flex items-center gap-1 text-emerald-600 dark:text-emerald-400",children:[r.jsx(_r,{className:"w-3 h-3"})," ",t("makerworld.alreadyImported")]})]}),ie&&r.jsx("div",{className:"mt-3 text-sm prose prose-sm max-w-none dark:prose-invert line-clamp-3",dangerouslySetInnerHTML:{__html:l5.sanitize(cst(ie))}}),l&&r.jsxs("a",{href:`https://makerworld.com/models/${l.model_id}${l.profile_id?`#profileId-${l.profile_id}`:""}`,target:"_blank",rel:"noopener noreferrer",className:"mt-3 inline-flex items-center gap-1 text-xs text-brand-500 hover:underline",children:[r.jsx(Lr,{className:"w-3 h-3"})," ",t("makerworld.openOnMakerworld")]})]})]})})}),l&&K.length>0&&r.jsxs(Ct,{children:[r.jsx(pn,{children:r.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[r.jsx("h2",{className:"text-lg font-semibold",children:t("makerworld.platesHeader",{count:K.length})}),r.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[r.jsx("label",{className:"text-xs text-gray-600 dark:text-gray-400",children:t("makerworld.importTo")}),r.jsxs("select",{value:d??"",onChange:Y=>u(Y.target.value?Number(Y.target.value):null),className:"text-sm px-2 py-1 border rounded bg-white dark:bg-gray-800 border-gray-300 dark:border-gray-700",disabled:m!==null,children:[r.jsx("option",{value:"",children:t("makerworld.folderAuto")}),(T.data??[]).filter(Y=>!(Y.is_external&&Y.external_readonly)).flatMap(Y=>Jce(Y)).map(({folder:Y,depth:Q})=>r.jsx("option",{value:Y.id,children:`${"— ".repeat(Q)}${Y.name}`},Y.id))]}),r.jsx(Me,{variant:"primary",size:"sm",disabled:!i||!B||m!==null||re.isPending||de.isPending,onClick:pe,children:m!==null?r.jsxs(r.Fragment,{children:[r.jsx(ut,{className:"w-4 h-4 animate-spin"}),r.jsxs("span",{className:"ml-2",children:[t("makerworld.importAllProgress",{current:m.current,total:m.total}),me>0&&` · ${ue} · ${me}s`]})]}):r.jsxs(r.Fragment,{children:[r.jsx(Yr,{className:"w-4 h-4"}),r.jsx("span",{className:"ml-2",children:t("makerworld.importAll")})]})})]})]})}),r.jsx(At,{children:r.jsx("div",{className:"grid gap-3",children:K.map((Y,Q)=>{const oe=Xp(Y,"id"),ee=Xp(Y,"profileId"),ge=zd(Y,"title"),ce=zd(Y,"cover"),le=Xp(Y,"materialCnt"),q=Y?.needAms===!0,R=Xp(Y,"downloadCount"),ne=Y?.compatibility??null,xe=Y?.otherCompatibility??null,we=ne?.devProductName??null,Ne=Array.isArray(xe)?xe.map(ze=>ze?.devProductName??"").filter(Boolean):[];if(oe==null)return null;const ve=re.isPending&&re.variables?.instanceId===oe,be=de.isPending&&de.variables?.instanceId===oe,Ee=ee!==null?N[ee]:void 0;return r.jsxs("div",{className:"flex flex-col gap-2 p-3 border rounded border-gray-200 dark:border-gray-700",children:[r.jsxs("div",{className:"flex gap-3 items-center",children:[(()=>{const ze=ae(Y),_e=ze.length>0;return r.jsxs("button",{type:"button",disabled:!_e,onClick:()=>_e&&g({images:ze,index:0}),className:"relative w-16 h-16 shrink-0 rounded overflow-hidden group","aria-label":t("makerworld.openGallery"),children:[ce?r.jsx("img",{src:bF(ce),alt:"",className:"w-16 h-16 object-cover",loading:"lazy"}):r.jsx("div",{className:"w-16 h-16 bg-gray-100 dark:bg-gray-800"}),ze.length>1&&r.jsxs("span",{className:"absolute bottom-0.5 right-0.5 bg-black/70 text-white text-[10px] px-1.5 py-0.5 rounded flex items-center gap-1",children:[r.jsx(Bbe,{className:"w-2.5 h-2.5"}),ze.length]})]})})(),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("p",{className:"font-medium truncate",children:ge||t("makerworld.plateDefaultName",{n:Q+1})}),r.jsxs("div",{className:"flex flex-wrap gap-3 text-xs text-gray-500 dark:text-gray-400 mt-1",children:[we&&r.jsx("span",{className:"font-medium text-gray-700 dark:text-gray-300",children:t("makerworld.slicedFor",{printer:we,defaultValue:"Sliced for {{printer}}"})}),le!==null&&r.jsx("span",{children:t("makerworld.materialCount",{count:le})}),q&&r.jsx("span",{children:t("makerworld.amsRequired")}),R!==null&&r.jsx("span",{children:t("makerworld.downloadsCount",{count:R})})]}),Ne.length>0&&r.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400 mt-1",title:Ne.join(", "),children:t("makerworld.alsoCompatible",{printers:Ne.slice(0,6).join(", ")+(Ne.length>6?"…":""),defaultValue:"Also marked compatible: {{printers}}"})})]}),r.jsxs("div",{className:"flex gap-2 shrink-0",children:[r.jsx(Me,{variant:"ghost",size:"sm",disabled:!i||!B||ve||be||m!==null,onClick:()=>re.mutate({instanceId:oe,profileId:ee}),title:B?void 0:t("makerworld.signInRequiredTitle"),children:ve?r.jsxs(r.Fragment,{children:[r.jsx(ut,{className:"w-4 h-4 animate-spin"}),r.jsxs("span",{className:"ml-2",children:[ue,me>0&&` · ${me}s`]})]}):r.jsxs(r.Fragment,{children:[r.jsx(Yr,{className:"w-4 h-4"}),r.jsx("span",{className:"ml-2",children:t("makerworld.importToLibrary")})]})}),r.jsx(Me,{variant:"primary",size:"sm",disabled:!i||!B||ve||be||m!==null,onClick:()=>de.mutate({instanceId:oe,profileId:ee}),title:B?void 0:t("makerworld.signInRequiredTitle"),children:be?r.jsxs(r.Fragment,{children:[r.jsx(ut,{className:"w-4 h-4 animate-spin"}),r.jsxs("span",{className:"ml-2",children:[ue,me>0&&` · ${me}s`]})]}):r.jsxs(r.Fragment,{children:[r.jsx(Lr,{className:"w-4 h-4"}),r.jsx("span",{className:"ml-2",children:t("makerworld.sliceIn",{slicer:M})})]})})]})]}),Ee&&r.jsxs("div",{className:"flex items-center gap-2 pl-20 text-xs",children:[r.jsx(_r,{className:"w-3.5 h-3.5 text-emerald-600 dark:text-emerald-400 shrink-0"}),r.jsx("span",{className:"text-emerald-700 dark:text-emerald-300",children:Ee.was_existing?t("makerworld.lastImportAlreadyInLibrary"):t("makerworld.lastImportSuccess")}),r.jsxs(Me,{variant:"ghost",size:"sm",onClick:()=>{const ze=Ee.folder_id?`/files?folder=${Ee.folder_id}`:"/files";window.location.assign(ze)},children:[r.jsx(Fl,{className:"w-3.5 h-3.5"}),r.jsx("span",{className:"ml-1.5",children:t("makerworld.viewInLibrary")})]}),z?r.jsxs(Me,{variant:"ghost",size:"sm",onClick:()=>L(Ee.library_file_id,Ee.filename),children:[r.jsx(cu,{className:"w-3.5 h-3.5"}),r.jsx("span",{className:"ml-1.5",children:t("slice.action","Slice")})]}):r.jsxs(r.Fragment,{children:[r.jsxs(Me,{variant:"ghost",size:"sm",onClick:()=>ye(Ee.library_file_id,Ee.filename,"bambu_studio"),children:[r.jsx(Lr,{className:"w-3.5 h-3.5"}),r.jsx("span",{className:"ml-1.5",children:t("makerworld.openInBambuStudio")})]}),r.jsxs(Me,{variant:"ghost",size:"sm",onClick:()=>ye(Ee.library_file_id,Ee.filename,"orcaslicer"),children:[r.jsx(Lr,{className:"w-3.5 h-3.5"}),r.jsx("span",{className:"ml-1.5",children:t("makerworld.openInOrcaSlicer")})]})]}),r.jsx("div",{className:"ml-auto",children:r.jsx(Me,{variant:"ghost",size:"sm",disabled:J.isPending&&J.variables?.profileId===ee,onClick:()=>{ee!==null&&b({libraryFileId:Ee.library_file_id,profileId:ee,filename:Ee.filename})},title:t("makerworld.deleteImport"),children:J.isPending&&J.variables?.profileId===ee?r.jsx(ut,{className:"w-3.5 h-3.5 animate-spin"}):r.jsx(Jt,{className:"w-3.5 h-3.5 text-red-500"})})})]})]},oe)})})})]})]}),r.jsx("aside",{className:"lg:sticky lg:top-6 lg:self-start min-w-0",children:A.data&&A.data.length>0&&r.jsxs(Ct,{children:[r.jsx(pn,{children:r.jsx("h2",{className:"text-base font-semibold",children:t("makerworld.recentImportsHeader")})}),r.jsx(At,{children:r.jsx("div",{className:"flex flex-col gap-2 max-h-[28rem] overflow-y-auto -mx-2 px-2",children:A.data.map(Y=>r.jsxs("div",{className:"flex gap-2 p-2 border rounded border-gray-200 dark:border-gray-700",children:[Y.thumbnail_path?r.jsx("img",{src:se.getLibraryFileThumbnailUrl(Y.library_file_id),alt:"",className:"w-12 h-12 shrink-0 object-cover rounded bg-gray-100 dark:bg-gray-800",loading:"lazy"}):r.jsx("div",{className:"w-12 h-12 shrink-0 rounded bg-gray-100 dark:bg-gray-800"}),r.jsxs("div",{className:"flex-1 min-w-0 flex flex-col gap-1",children:[r.jsx("p",{className:"text-xs font-medium truncate",title:Y.filename,children:Y.filename}),r.jsxs("div",{className:"flex gap-0.5",children:[r.jsx(Me,{variant:"ghost",size:"sm",onClick:()=>{const Q=Y.folder_id?`/files?folder=${Y.folder_id}`:"/files";window.location.assign(Q)},title:t("makerworld.viewInLibrary"),children:r.jsx(Fl,{className:"w-3.5 h-3.5"})}),z?r.jsx(Me,{variant:"ghost",size:"sm",onClick:()=>L(Y.library_file_id,Y.filename),title:t("slice.action","Slice"),children:r.jsx(cu,{className:"w-3.5 h-3.5"})}):r.jsx(Me,{variant:"ghost",size:"sm",onClick:()=>ye(Y.library_file_id,Y.filename,"bambu_studio"),title:t("makerworld.openInBambuStudio"),children:r.jsx(Lr,{className:"w-3.5 h-3.5"})}),Y.source_url&&r.jsx("a",{href:Y.source_url,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center justify-center h-7 w-7 rounded text-gray-500 hover:text-gray-700 dark:hover:text-gray-300",title:t("makerworld.openOnMakerworld"),children:r.jsx(no,{className:"w-3.5 h-3.5"})})]})]})]},Y.library_file_id))})})]})})]}),r.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400 pt-4 border-t border-gray-200 dark:border-gray-700",children:t("makerworld.disclaimer")}),f&&r.jsx(vn,{title:t("makerworld.deleteImport"),message:t("makerworld.confirmDelete",{filename:f.filename}),confirmText:t("makerworld.deleteImport"),variant:"danger",isLoading:J.isPending,loadingText:t("makerworld.importDeleting"),onCancel:()=>b(null),onConfirm:()=>J.mutate({libraryFileId:f.libraryFileId,profileId:f.profileId})}),I&&r.jsx(DA,{source:I,onClose:()=>H(null)}),w&&r.jsxs("div",{className:"fixed inset-0 bg-black/90 flex items-center justify-center z-50",onClick:()=>g(null),role:"dialog","aria-modal":"true",children:[r.jsx("button",{type:"button",className:"absolute top-4 right-4 p-2 bg-white/10 hover:bg-white/20 rounded-full text-white",onClick:Y=>{Y.stopPropagation(),g(null)},"aria-label":t("common.close","Close"),children:r.jsx(Bt,{className:"w-5 h-5"})}),w.images.length>1&&r.jsxs(r.Fragment,{children:[r.jsx("button",{type:"button",className:"absolute left-4 p-2 bg-white/10 hover:bg-white/20 rounded-full text-white disabled:opacity-30",disabled:w.index===0,onClick:Y=>{Y.stopPropagation(),g(Q=>Q&&{...Q,index:Math.max(0,Q.index-1)})},"aria-label":t("makerworld.galleryPrev"),children:r.jsx(el,{className:"w-6 h-6"})}),r.jsx("button",{type:"button",className:"absolute right-4 p-2 bg-white/10 hover:bg-white/20 rounded-full text-white disabled:opacity-30",disabled:w.index>=w.images.length-1,onClick:Y=>{Y.stopPropagation(),g(Q=>Q&&{...Q,index:Math.min(Q.images.length-1,Q.index+1)})},"aria-label":t("makerworld.galleryNext"),children:r.jsx(Va,{className:"w-6 h-6"})})]}),r.jsx("img",{src:bF(w.images[w.index].url),alt:w.images[w.index].name,className:"max-w-[90vw] max-h-[90vh] object-contain",onClick:Y=>Y.stopPropagation()}),w.images.length>1&&r.jsxs("div",{className:"absolute bottom-6 left-1/2 -translate-x-1/2 text-white bg-black/60 px-3 py-1 rounded text-xs",children:[w.index+1," / ",w.images.length]})]})]})}const wQ=["DEBUG","INFO","WARNING","ERROR"],xF={DEBUG:"text-gray-400",INFO:"text-blue-400",WARNING:"text-yellow-400",ERROR:"text-red-400"},hst={DEBUG:hy,INFO:Ci,WARNING:Nn,ERROR:$a};function fst(){const t=en(),[e,n]=v.useState(!0),[a,i]=v.useState(new Set),[s,o]=v.useState(""),[l,c]=v.useState("ALL"),[d,u]=v.useState(!1),[m,p]=v.useState(!1),f=v.useRef(null),{data:b,isLoading:w,refetch:g}=We({queryKey:["application-logs",l,s],queryFn:()=>ey.getLogs({limit:200,level:l==="ALL"?void 0:l,search:s||void 0}),refetchInterval:m?2e3:!1,enabled:d});v.useEffect(()=>{d||p(!1)},[d]);const x=it({mutationFn:()=>ey.clearLogs(),onSuccess:()=>{t.invalidateQueries({queryKey:["application-logs"]})}});v.useEffect(()=>{e&&f.current&&b?.entries&&(f.current.scrollTop=f.current.scrollHeight)},[b?.entries,e]);const _=A=>{i(F=>{const S=new Set(F);return S.has(A)?S.delete(A):S.add(A),S})},N=A=>{const F=A.split(" ");return F.length>=2?F[1]:A},C=v.useMemo(()=>b?.entries??[],[b?.entries]),P=v.useMemo(()=>[...C].reverse(),[C]),T=({level:A})=>{const F=hst[A]||Ci;return r.jsx(F,{className:`w-3.5 h-3.5 ${xF[A]||"text-gray-400"}`})};return r.jsxs("div",{className:"bg-bambu-dark rounded-lg overflow-hidden",children:[r.jsxs("button",{onClick:()=>u(!d),className:"w-full flex items-center justify-between p-4 hover:bg-bambu-dark-tertiary/50 transition-colors",children:[r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx("div",{className:`p-2 rounded-lg ${m?"bg-bambu-green/20 text-bambu-green":"bg-bambu-dark-tertiary text-bambu-gray"}`,children:r.jsx(hy,{className:"w-5 h-5"})}),r.jsxs("div",{className:"text-left",children:[r.jsx("p",{className:"font-medium text-white",children:"Application Logs"}),r.jsx("p",{className:"text-sm text-bambu-gray",children:m?`Live streaming - ${b?.filtered_count??0} entries`:"View and filter application logs"})]})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[m&&r.jsxs("span",{className:"flex items-center gap-1.5 px-2 py-1 bg-bambu-green/20 rounded text-bambu-green text-xs",children:[r.jsx("span",{className:"w-1.5 h-1.5 bg-bambu-green rounded-full animate-pulse"}),"Live"]}),d?r.jsx(tl,{className:"w-5 h-5 text-bambu-gray"}):r.jsx(Rn,{className:"w-5 h-5 text-bambu-gray"})]})]}),d&&r.jsxs("div",{className:"border-t border-bambu-dark-tertiary",children:[r.jsxs("div",{className:"flex flex-col gap-2 p-4 border-b border-bambu-dark-tertiary",children:[r.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[m?r.jsxs("button",{onClick:A=>{A.stopPropagation(),p(!1)},className:"flex items-center gap-1.5 px-3 py-1.5 text-sm bg-red-500/20 text-red-400 hover:bg-red-500/30 rounded transition-colors",children:[r.jsx(so,{className:"w-4 h-4"}),"Stop"]}):r.jsxs("button",{onClick:A=>{A.stopPropagation(),p(!0),g()},className:"flex items-center gap-1.5 px-3 py-1.5 text-sm bg-bambu-green/20 text-bambu-green hover:bg-bambu-green/30 rounded transition-colors",children:[r.jsx(fs,{className:"w-4 h-4"}),"Start"]}),r.jsxs("button",{onClick:()=>x.mutate(),disabled:x.isPending||C.length===0,className:"flex items-center gap-1.5 px-3 py-1.5 text-sm bg-bambu-dark-tertiary text-bambu-gray hover:text-white hover:bg-bambu-dark-secondary rounded transition-colors disabled:opacity-50",children:[r.jsx(Jt,{className:"w-4 h-4"}),"Clear"]}),r.jsx("button",{onClick:()=>g(),disabled:w,className:"flex items-center gap-1.5 px-3 py-1.5 text-sm bg-bambu-dark-tertiary text-bambu-gray hover:text-white hover:bg-bambu-dark-secondary rounded transition-colors disabled:opacity-50",children:r.jsx(sr,{className:`w-4 h-4 ${w?"animate-spin":""}`})}),r.jsx("div",{className:"flex-1"}),r.jsxs("label",{className:"flex items-center gap-2 text-sm text-bambu-gray cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:e,onChange:A=>n(A.target.checked),className:"rounded border-bambu-dark-tertiary bg-bambu-dark-tertiary"}),"Auto-scroll"]}),r.jsxs("span",{className:"text-sm text-bambu-gray",children:[b?.filtered_count??0,"/",b?.total_in_file??0]})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsxs("div",{className:"relative flex-1",children:[r.jsx(Sr,{className:"absolute left-2.5 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),r.jsx("input",{type:"text",placeholder:"Search message or logger name...",value:s,onChange:A=>o(A.target.value),className:"w-full pl-8 pr-8 py-1.5 text-sm bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none"}),s&&r.jsx("button",{onClick:()=>o(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white",children:r.jsx(Bt,{className:"w-4 h-4"})})]}),r.jsxs("div",{className:"flex items-center gap-1 bg-bambu-dark-secondary rounded border border-bambu-dark-tertiary",children:[r.jsx("button",{onClick:()=>c("ALL"),className:`px-2 py-1.5 text-xs rounded-l transition-colors ${l==="ALL"?"bg-bambu-green text-white":"text-bambu-gray hover:text-white"}`,children:"All"}),wQ.map((A,F)=>r.jsx("button",{onClick:()=>c(A),className:`px-2 py-1.5 text-xs transition-colors flex items-center gap-1 ${F===wQ.length-1?"rounded-r":""} ${l===A?`${xF[A]} bg-bambu-dark-tertiary`:"text-bambu-gray hover:text-white"}`,children:A},A))]})]})]}),r.jsx("div",{ref:f,className:"overflow-auto font-mono text-xs bg-black min-h-[300px] max-h-[500px]",children:C.length===0?r.jsxs("div",{className:"flex flex-col items-center justify-center h-[300px] text-bambu-gray",children:[r.jsx("p",{className:"mb-2",children:"No log entries found"}),r.jsx("p",{className:"text-sm",children:"Log file may be empty or cleared"})]}):r.jsx("div",{className:"divide-y divide-bambu-dark-tertiary/30",children:P.map((A,F)=>{const S=a.has(F),M=A.message.includes(`
+Difference: ${l}g (mismatch!)`;return r.jsxs("div",{className:`flex items-center gap-1 text-sm font-medium ${o?"text-green-400":"text-yellow-400"}`,title:c,children:[r.jsxs("span",{children:[Math.round(n),"g"]}),o?r.jsx(_r,{className:"w-3 h-3"}):r.jsxs(r.Fragment,{children:[r.jsx(Nn,{className:"w-3 h-3"}),e&&r.jsx("button",{type:"button",onClick:d=>{d.stopPropagation(),d.preventDefault(),e(t)},className:"p-1 hover:bg-bambu-green/20 rounded transition-colors text-bambu-green",title:"Sync: trust scale weight and reset tracking",children:r.jsx(sr,{className:"w-3.5 h-3.5"})})]})]})}},gF={id:t=>t.id,added_time:t=>t.created_at||"",encode_time:t=>t.encode_time||"",last_used_time:t=>t.last_used||"",material:t=>(t.material||"").toLowerCase(),subtype:t=>(t.subtype||"").toLowerCase(),color_name:t=>(t.color_name||"").toLowerCase(),brand:t=>(t.brand||"").toLowerCase(),slicer_filament:t=>(t.slicer_filament_name||t.slicer_filament||"").toLowerCase(),location:(t,e)=>{const n=e[t.id];if(!n)return"";const a=n.ams_id===254||n.ams_id===255,i=!a&&n.ams_id>=128,s=n.ams_label?` (${n.ams_label})`:"";return`${n.printer_name||""} ${c_(n.ams_id,n.tray_id,i,a)}${s}`},storage_location:t=>(t.storage_location||"").toLowerCase(),label_weight:t=>t.label_weight,net:t=>Math.max(0,t.label_weight-t.weight_used),gross:t=>Math.max(0,t.label_weight-t.weight_used)+t.core_weight,used:t=>t.weight_used,remaining:t=>t.label_weight>0?Math.max(0,t.label_weight-t.weight_used)/t.label_weight:0,note:t=>(t.note||"").toLowerCase(),data_origin:t=>(t.data_origin||"").toLowerCase(),tag_type:t=>(t.tag_type||"").toLowerCase(),stock:t=>t.slicer_filament?1:0,spool_name:t=>t.core_weight_catalog_id??0,cost_per_kg:t=>t.cost_per_kg??0,weight_check:t=>{if(t.last_scale_weight==null)return-1;const e=Math.max(0,t.label_weight-t.weight_used)+t.core_weight;return Math.abs(t.last_scale_weight-e)}},XI="bambuddy-inventory-sort";function rst(){try{const t=localStorage.getItem(XI);if(t)return JSON.parse(t)}catch{}return null}function ast(t){try{t?localStorage.setItem(XI,JSON.stringify(t)):localStorage.removeItem(XI)}catch{}}function ist(){const{data:t}=We({queryKey:["spoolman-settings"],queryFn:se.getSpoolmanSettings,staleTime:3e5}),e=t!==void 0,n=t?.spoolman_enabled==="true"&&!!t?.spoolman_url;return r.jsx(sst,{spoolmanMode:n,spoolmanModeReady:e})}function sst({spoolmanMode:t=!1,spoolmanModeReady:e=!0}){const{t:n}=kt(),a=en(),{showToast:i}=rn(),{hasPermission:s,loading:o}=cr(),l=!o&&s("inventory:forecast_read"),[c,d]=ab(),[u,m]=v.useState(null),p=v.useRef(!1),[f,b]=v.useState(null),[w,g]=v.useState(null),[x,_]=v.useState("active"),[N,C]=v.useState("all"),[P,T]=v.useState(""),[A,F]=v.useState(""),[S,M]=v.useState(""),[z,I]=v.useState(""),[H,L]=v.useState("all"),[Z,re]=v.useState(""),[J,de]=v.useState("table"),[me,ue]=v.useState(rst),[W,ae]=v.useState(Jit),[pe,ye]=v.useState(!1),[Te,$]=v.useState(()=>{try{return localStorage.getItem("bambuddy-inventory-group")==="true"}catch{return!1}}),[K,D]=v.useState(new Set),[j,B]=v.useState(0),[X,O]=v.useState(()=>{try{const he=localStorage.getItem("bambuddy-inventory-pageSize");if(he){const Fe=Number(he);if([15,30,50,100,-1].includes(Fe))return Fe}}catch{}return 15}),{data:ie}=We({queryKey:["settings"],queryFn:se.getSettings}),U=ie?.date_format||"system",G=t?["spoolman-inventory-spools"]:["inventory-spools"],{data:Y,isLoading:Q}=We({queryKey:G,queryFn:()=>t?se.getSpoolmanInventorySpools(!0):se.getSpools(!0),refetchInterval:3e4}),oe=c.get("spool"),ee=oe&&/^\d+$/.test(oe)&&Number(oe)>0?Number(oe):null,ge=Y?.find(he=>he.id===ee)??null,ce=v.useCallback(()=>{p.current=!0,d(he=>(he.delete("spool"),he),{replace:!0})},[d]),{data:le,isError:q,error:R}=We({queryKey:t?["spoolman-inventory-spool",ee]:["inventory-spool",ee],queryFn:()=>t?se.getSpoolmanInventorySpool(ee):se.getSpool(ee),enabled:e&&ee!==null&&ge===null,staleTime:1/0,retry:(he,Fe)=>he<2&&!(Fe instanceof _i&&Fe.status===404)});v.useEffect(()=>{if(!p.current){if(e&&ee&&ge){ce(),m({spool:ge,mode:"edit"});return}if(le){ce(),m({spool:le,mode:"edit"});return}if(q){ce();const he=R instanceof _i&&R.status===404;i(n(he?"inventory.deepLinkSpoolNotFound":"inventory.deepLinkFetchFailed"),"error")}}},[e,ee,ge,le,q,R,ce,i,n]);const{data:ne}=We({queryKey:["spool-assignments"],queryFn:()=>se.getAssignments(),refetchInterval:3e4}),{data:xe=[],isError:we}=We({queryKey:["spoolman-slot-assignments-all"],queryFn:()=>se.getSpoolmanSlotAssignments(),enabled:t,refetchInterval:3e4,staleTime:1e4,retry:1}),Ne=v.useRef(!1);v.useEffect(()=>{we&&!Ne.current?(Ne.current=!0,i(n("inventory.spoolmanUnreachable"),"error")):we||(Ne.current=!1)},[we,i,n]);const{data:ve}=We({queryKey:["spool-catalog"],queryFn:()=>se.getSpoolCatalog()}),be=it({mutationFn:he=>t?se.deleteSpoolmanInventorySpool(he):se.deleteSpool(he),onSuccess:()=>{a.invalidateQueries({queryKey:G}),i(n("inventory.spoolDeleted"),"success")},onError:he=>{he instanceof _i&&he.status===404?i(n("inventory.deleteSpoolNotFound"),"error"):he instanceof _i&&he.status===503?i(n("inventory.spoolmanUnreachable"),"error"):i(n("inventory.deleteFailed"),"error")}}),Ee=it({mutationFn:he=>t?se.archiveSpoolmanInventorySpool(he):se.archiveSpool(he),onSuccess:()=>{a.invalidateQueries({queryKey:G}),i(n("inventory.spoolArchived"),"success")},onError:he=>{he instanceof _i&&he.status===404?i(n("inventory.archiveSpoolNotFound"),"error"):he instanceof _i&&he.status===503?i(n("inventory.spoolmanUnreachable"),"error"):i(n("inventory.archiveFailed"),"error")}}),ze=it({mutationFn:he=>t?se.restoreSpoolmanInventorySpool(he):se.restoreSpool(he),onSuccess:()=>{a.invalidateQueries({queryKey:G}),i(n("inventory.spoolRestored"),"success")},onError:he=>{he instanceof _i&&he.status===404?i(n("inventory.restoreSpoolNotFound"),"error"):he instanceof _i&&he.status===503?i(n("inventory.spoolmanUnreachable"),"error"):i(n("inventory.restoreFailed"),"error")}}),_e=async he=>{if(he.last_scale_weight!=null)try{t?await se.syncSpoolmanSpoolWeight(he.id,he.last_scale_weight):await Xr.updateSpoolWeight(he.id,he.last_scale_weight),a.invalidateQueries({queryKey:G});const Fe=[he.brand,he.material,he.color_name].filter(Boolean).join(" ");i(`Synced "${Fe}" to scale weight`,"success")}catch(Fe){const Qe=Fe instanceof _i&&Fe.status===404,Ze=Fe instanceof _i&&Fe.status===503;i(n(Qe?"inventory.syncWeightSpoolNotFound":Ze?"inventory.syncWeightSpoolmanUnreachable":"inventory.syncWeightFailed"),"error")}},Oe=ie?.low_stock_threshold??20,[Ie,Ke]=v.useState(!1),[rt,st]=v.useState(Oe.toString());v.useEffect(()=>{Ie||st(Oe.toString())},[Oe,Ie]);const Re=it({mutationFn:he=>se.updateSettings({low_stock_threshold:he}),onSuccess:()=>{a.invalidateQueries({queryKey:["settings"]}),i(n("common.saved"),"success"),Ke(!1)},onError:()=>{i(n("inventory.lowStockThresholdError"),"error")}}),tt=v.useMemo(()=>{if(!Y)return null;let he=0,Fe=0,Qe=0,Ze=0;const Ye={};for(const ft of Y){if(ft.archived_at)continue;Ze++;const et=Math.max(0,ft.label_weight-ft.weight_used);he+=et,Fe+=ft.weight_used;const jt=ft.label_weight>0?et/ft.label_weight*100:0,St=ft.low_stock_threshold_pct??Oe;jt{const he={};for(const Fe of ne||[])he[Fe.spool_id]={printer_id:Fe.printer_id,printer_name:Fe.printer_name,ams_id:Fe.ams_id,tray_id:Fe.tray_id,ams_label:Fe.ams_label??null};for(const Fe of xe)typeof Fe?.spoolman_spool_id!="number"||Fe.spoolman_spool_id<=0||typeof Fe.printer_id!="number"||typeof Fe.ams_id!="number"||typeof Fe.tray_id!="number"||he[Fe.spoolman_spool_id]||(he[Fe.spoolman_spool_id]={printer_id:Fe.printer_id,printer_name:Fe.printer_name??null,ams_id:Fe.ams_id,tray_id:Fe.tray_id,ams_label:Fe.ams_label??null});return he},[ne,xe]),fe=v.useMemo(()=>{const he={};for(const Fe of ve||[])he[Fe.id]=Fe;return he},[ve]),Ae=v.useMemo(()=>tt?Object.entries(tt.byMaterial).sort((he,Fe)=>Fe[1].weight-he[1].weight).slice(0,4):[],[tt]),$e=v.useMemo(()=>{let he=Y||[];if(x==="active"?he=he.filter(Fe=>!Fe.archived_at):he=he.filter(Fe=>!!Fe.archived_at),N==="used"?he=he.filter(Fe=>Fe.weight_used>0):N==="new"?he=he.filter(Fe=>Fe.weight_used===0):N==="lowstock"&&(he=he.filter(Fe=>{const Qe=Math.max(0,Fe.label_weight-Fe.weight_used),Ze=Fe.label_weight>0?Qe/Fe.label_weight*100:0,Ye=Fe.low_stock_threshold_pct??Oe;return ZeFe.material===P)),A&&(he=he.filter(Fe=>Fe.brand===A)),S&&(S==="__none__"?he=he.filter(Fe=>!Fe.category):he=he.filter(Fe=>Fe.category===S)),z){const Fe=Number(z);he=he.filter(Qe=>Qe.core_weight_catalog_id===Fe)}return H==="stock"?he=he.filter(Fe=>!Fe.slicer_filament):H==="configured"&&(he=he.filter(Fe=>!!Fe.slicer_filament)),Z&&(he=rI(he,Z)),he},[Y,x,N,P,A,S,z,H,Z,Oe]),Be=()=>B(0),nt=[...new Set(Y?.map(he=>he.material)||[])].sort(),gt=[...new Set(Y?.map(he=>he.brand).filter(Boolean)||[])].sort(),yt=[...new Set(Y?.map(he=>he.category?.trim()).filter(Boolean)||[])].sort(),ot=(Y??[]).some(he=>!he.category),Ht=[...new Set(Y?.map(he=>he.core_weight_catalog_id).filter(he=>he!=null)||[])].sort((he,Fe)=>{const Qe=(fe[he]?.name||"").toLowerCase(),Ze=(fe[Fe]?.name||"").toLowerCase();return Qe.localeCompare(Ze)}),Kt=x!=="active"||N!=="all"||!!P||!!A||!!S||!!z||H!=="all"||!!Z,Zt=he=>{ae(he),est(he)},Yt=v.useMemo(()=>W.filter(he=>he.visible).map(he=>he.id),[W]),gn=he=>{gF[he]&&(ue(Fe=>{let Qe;return Fe?.column===he?Qe=Fe.direction==="asc"?{column:he,direction:"desc"}:null:Qe={column:he,direction:"asc"},ast(Qe),Qe}),Be())},ln=v.useMemo(()=>{if(!me)return $e;const he=gF[me.column];return he?[...$e].sort((Qe,Ze)=>{const Ye=he(Qe,Ue),ft=he(Ze,Ue);return Yeft?me.direction==="asc"?1:-1:0}):$e},[$e,me,Ue]),pt=v.useMemo(()=>{if(!Te)return ln.map(Ze=>({type:"single",spool:Ze}));const he=new Map;for(const Ze of ln)if(!(Ze.weight_used>0||Ue[Ze.id])){const Ye=xQ(Ze),ft=he.get(Ye);ft?ft.push(Ze):he.set(Ye,[Ze])}const Fe=[],Qe=new Set;for(const Ze of ln){if(Ze.weight_used>0||Ue[Ze.id]){Fe.push({type:"single",spool:Ze});continue}const Ye=xQ(Ze);if(Qe.has(Ye))continue;Qe.add(Ye);const ft=he.get(Ye);ft.length===1?Fe.push({type:"single",spool:ft[0]}):Fe.push({type:"group",key:Ye,spools:ft,representative:ft[0]})}return Fe},[ln,Te,Ue]),at=X===-1,vt=pt.length,_t=at?vt||1:X,Dt=Math.max(1,Math.ceil(vt/_t)),De=at?0:Math.min(j,Dt-1),je=at?pt:pt.slice(De*_t,(De+1)*_t),Ve=()=>{const he=!Te;$(he),D(new Set),Be();try{localStorage.setItem("bambuddy-inventory-group",String(he))}catch{}},Je=he=>{D(Fe=>{const Qe=new Set(Fe);return Qe.has(he)?Qe.delete(he):Qe.add(he),Qe})},Le=he=>{O(he),B(0);try{localStorage.setItem("bambuddy-inventory-pageSize",String(he))}catch{}},dt=()=>{_("active"),C("all"),T(""),F(""),M(""),I(""),L("all"),re(""),Be()};return r.jsxs("div",{className:"p-4 md:p-8 space-y-6",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsxs("h1",{className:"text-2xl font-bold text-white flex items-center gap-3",children:[r.jsx(Br,{className:"w-7 h-7 text-bambu-green"}),n("inventory.title")]}),r.jsx("p",{className:"text-bambu-gray mt-1",children:n("inventory.subtitle")})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsxs(Me,{variant:"secondary",disabled:$e.length===0,onClick:()=>g($e.map(he=>he.id)),title:$e.length===0?n("inventory.labels.noSpoolsTitle","No spools to label"):n("inventory.labels.bulkTitle","Pick spools to print labels for from the {{count}} currently shown",{count:$e.length}),children:[r.jsx(pr,{className:"w-4 h-4"}),n("inventory.labels.printLabels","Print labels…")]}),r.jsxs(Me,{onClick:()=>m({spool:null,mode:"create"}),children:[r.jsx(ar,{className:"w-4 h-4"}),n("inventory.addSpool")]})]})]}),tt&&!Q&&r.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-5 gap-3",children:[r.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg p-4",children:[r.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[r.jsx(Br,{className:"w-4 h-4 text-bambu-green"}),r.jsx("span",{className:"text-xs text-bambu-gray font-medium uppercase tracking-wide",children:n("inventory.totalInventory")})]}),r.jsx("div",{className:"text-xl font-bold text-white",children:au(tt.totalWeight,!0)}),r.jsxs("div",{className:"text-xs text-bambu-gray mt-1",children:[tt.totalSpools," ",tt.totalSpools!==1?n("inventory.spools"):n("inventory.spool")]})]}),r.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg p-4",children:[r.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[r.jsx(RS,{className:"w-4 h-4 text-blue-400"}),r.jsx("span",{className:"text-xs text-bambu-gray font-medium uppercase tracking-wide",children:n("inventory.totalConsumed")})]}),r.jsx("div",{className:"text-xl font-bold text-white",children:au(tt.totalConsumed,!0)}),r.jsx("div",{className:"text-xs text-bambu-gray mt-1",children:n("inventory.sinceTracking")})]}),r.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg p-4",children:[r.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[r.jsx(oa,{className:"w-4 h-4 text-green-400"}),r.jsx("span",{className:"text-xs text-bambu-gray font-medium uppercase tracking-wide",children:n("inventory.byMaterial")})]}),r.jsx("div",{className:"flex flex-wrap gap-1.5 mt-1",children:Ae.map(([he,Fe])=>r.jsxs("span",{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-medium ${tst[he]||"bg-bambu-dark-tertiary text-bambu-gray"}`,children:[he," ",r.jsx("span",{className:"opacity-70",children:au(Fe.weight,!0)})]},he))})]}),r.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg p-4",children:[r.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[r.jsx(pr,{className:"w-4 h-4 text-purple-400"}),r.jsx("span",{className:"text-xs text-bambu-gray font-medium uppercase tracking-wide",children:n("inventory.inPrinter")})]}),r.jsx("div",{className:"text-xl font-bold text-white",children:Ce}),r.jsx("div",{className:"text-xs text-bambu-gray mt-1",children:n("inventory.loadedInAms")})]}),r.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg p-4",children:[r.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[r.jsx(Nn,{className:"w-4 h-4 text-yellow-400"}),r.jsx("span",{className:"text-xs text-bambu-gray font-medium uppercase tracking-wide",children:n("inventory.lowStock")})]}),r.jsx("div",{className:`text-xl font-bold ${tt.lowStock>0?"text-yellow-400":"text-white"}`,children:tt.lowStock}),r.jsx("div",{className:"text-xs text-bambu-gray mt-1 flex items-center gap-2",children:Ie?r.jsxs("form",{onSubmit:he=>{he.preventDefault();const Fe=parseFloat(rt);!isNaN(Fe)&&Fe>=.1&&Fe<=99.9?Re.mutate(Fe):i(n("inventory.lowStockThresholdError"),"error")},className:"flex items-center gap-2",children:[r.jsx("span",{className:"text-xs text-bambu-gray",children:"<"}),r.jsx("input",{type:"text",inputMode:"decimal",pattern:"^\\d{0,2}(\\.\\d?)?$",maxLength:4,value:rt,onChange:he=>{const Fe=he.target.value.replace(/[^\d.]/g,"");/^\d{0,2}(\.\d?)?$/.test(Fe)&&st(Fe)},className:"px-1.5 py-1 rounded border border-bambu-dark-tertiary text-xs text-white bg-bambu-dark-secondary focus:outline-none focus:border-bambu-green w-14 text-center",onWheel:he=>he.currentTarget.blur(),disabled:Re.isPending}),r.jsx("span",{className:"text-xs text-bambu-gray",children:"%"}),r.jsx(Me,{type:"submit",size:"sm",disabled:Re.isPending,children:n("common.save")}),r.jsx(Me,{type:"button",size:"sm",variant:"ghost",onClick:()=>Ke(!1),disabled:Re.isPending,children:n("common.cancel")})]}):r.jsxs(r.Fragment,{children:[r.jsxs("span",{className:"text-bambu-gray",children:["< ",Oe,"%"]}),r.jsx("button",{className:"p-1.5 text-bambu-gray hover:text-white rounded transition-colors",title:n("common.edit"),onClick:()=>{st(Oe.toString()),Ke(!0)},children:r.jsx(fc,{className:"w-4 h-4"})})]})})]})]}),r.jsxs("div",{className:"flex flex-col sm:flex-row gap-3 items-start sm:items-center justify-between",children:[r.jsxs("div",{className:`relative flex-1 max-w-md ${J==="forecast"?"invisible pointer-events-none":""}`,children:[r.jsx(Sr,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50"}),r.jsx("input",{type:"text",value:Z,onChange:he=>{re(he.target.value),Be()},placeholder:n("inventory.search"),className:"w-full pl-10 pr-8 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green"}),Z&&r.jsx("button",{onClick:()=>{re(""),Be()},className:"absolute right-3 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white",children:r.jsx(Bt,{className:"w-4 h-4"})})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[J==="table"&&r.jsxs("button",{onClick:()=>ye(!0),className:"flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium text-bambu-gray border border-bambu-dark-tertiary rounded-lg hover:bg-bambu-dark-tertiary transition-colors",title:n("inventory.configureColumns"),children:[r.jsx(wge,{className:"w-4 h-4"}),r.jsx("span",{className:"hidden sm:inline",children:n("inventory.columns")})]}),J!=="forecast"&&r.jsxs("button",{onClick:Ve,className:`flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium border rounded-lg transition-colors ${Te?"bg-bambu-green/20 text-bambu-green border-bambu-green/30":"text-bambu-gray border-bambu-dark-tertiary hover:bg-bambu-dark-tertiary"}`,title:n("inventory.groupSimilar"),children:[r.jsx(Tbe,{className:"w-4 h-4"}),r.jsx("span",{className:"hidden sm:inline",children:n("inventory.groupSimilar")})]}),r.jsxs("div",{className:"flex bg-bambu-dark-primary border border-bambu-dark-tertiary rounded-lg overflow-hidden",children:[r.jsxs("button",{onClick:()=>de("table"),className:`flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium transition-colors ${J==="table"?"bg-bambu-green text-white":"text-bambu-gray hover:bg-bambu-dark-tertiary"}`,children:[r.jsx(Dye,{className:"w-4 h-4"}),r.jsx("span",{className:"hidden sm:inline",children:n("inventory.table")})]}),r.jsxs("button",{onClick:()=>de("cards"),className:`flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium transition-colors ${J==="cards"?"bg-bambu-green text-white":"text-bambu-gray hover:bg-bambu-dark-tertiary"}`,children:[r.jsx(TS,{className:"w-4 h-4"}),r.jsx("span",{className:"hidden sm:inline",children:n("inventory.cards")})]}),r.jsxs("button",{onClick:()=>l&&de("forecast"),disabled:!l,title:l?void 0:n("forecast.noReadAccess"),className:`flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium transition-colors disabled:opacity-40 disabled:cursor-not-allowed ${J==="forecast"?"bg-bambu-green text-white":"text-bambu-gray hover:bg-bambu-dark-tertiary"}`,children:[l?r.jsx(rC,{className:"w-4 h-4"}):r.jsx(lc,{className:"w-4 h-4"}),r.jsx("span",{className:"hidden sm:inline",children:n("forecast.title")})]})]})]})]}),r.jsxs("div",{className:`flex flex-wrap items-center gap-2 ${J==="forecast"?"hidden":""}`,children:[r.jsxs("div",{className:"flex items-center rounded-lg border border-bambu-dark-tertiary overflow-hidden",children:[r.jsxs("button",{onClick:()=>{_("active"),Be()},className:`flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium transition-colors ${x==="active"?"bg-bambu-green/20 text-bambu-green":"text-bambu-gray hover:bg-bambu-dark-tertiary"}`,children:[r.jsx(Br,{className:"w-3.5 h-3.5"}),n("inventory.active")]}),r.jsxs("button",{onClick:()=>{_("archived"),Be()},className:`flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium transition-colors ${x==="archived"?"bg-bambu-green/20 text-bambu-green":"text-bambu-gray hover:bg-bambu-dark-tertiary"}`,children:[r.jsx(ro,{className:"w-3.5 h-3.5"}),n("inventory.archived")]})]}),r.jsx("div",{className:"w-px h-5 bg-bambu-dark-tertiary"}),r.jsxs("div",{className:"flex items-center rounded-lg border border-bambu-dark-tertiary overflow-hidden",children:[r.jsx("button",{onClick:()=>{C("all"),Be()},className:`px-3 py-1.5 text-xs font-medium transition-colors ${N==="all"?"bg-bambu-green/20 text-bambu-green":"text-bambu-gray hover:bg-bambu-dark-tertiary"}`,children:n("inventory.all")}),r.jsxs("button",{onClick:()=>{C("used"),Be()},className:`flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium transition-colors ${N==="used"?"bg-bambu-green/20 text-bambu-green":"text-bambu-gray hover:bg-bambu-dark-tertiary"}`,children:[r.jsx(Zn,{className:"w-3.5 h-3.5"}),n("inventory.used")]}),r.jsx("button",{onClick:()=>{C("new"),Be()},className:`px-3 py-1.5 text-xs font-medium transition-colors ${N==="new"?"bg-bambu-green/20 text-bambu-green":"text-bambu-gray hover:bg-bambu-dark-tertiary"}`,children:n("inventory.new")}),r.jsxs("button",{onClick:()=>{C("lowstock"),Be()},className:`flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium transition-colors ${N==="lowstock"?"bg-yellow-500/20 text-yellow-400":"text-bambu-gray hover:bg-bambu-dark-tertiary"}`,children:[r.jsx(Nn,{className:"w-3.5 h-3.5"}),n("inventory.lowStock")]})]}),r.jsxs("div",{className:"flex items-center rounded-lg border border-bambu-dark-tertiary overflow-hidden",children:[r.jsx("button",{onClick:()=>{L("all"),Be()},className:`px-3 py-1.5 text-xs font-medium transition-colors ${H==="all"?"bg-bambu-green/20 text-bambu-green":"text-bambu-gray hover:bg-bambu-dark-tertiary"}`,children:n("inventory.all")}),r.jsx("button",{onClick:()=>{L("stock"),Be()},className:`px-3 py-1.5 text-xs font-medium transition-colors ${H==="stock"?"bg-amber-500/20 text-amber-400":"text-bambu-gray hover:bg-bambu-dark-tertiary"}`,children:n("inventory.stock")}),r.jsx("button",{onClick:()=>{L("configured"),Be()},className:`px-3 py-1.5 text-xs font-medium transition-colors ${H==="configured"?"bg-bambu-green/20 text-bambu-green":"text-bambu-gray hover:bg-bambu-dark-tertiary"}`,children:n("inventory.configured")})]}),r.jsx("div",{className:"w-px h-5 bg-bambu-dark-tertiary"}),r.jsxs("select",{value:P,onChange:he=>{T(he.target.value),Be()},className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${P?"bg-bambu-green/20 text-bambu-green border-bambu-green/30":"bg-transparent text-bambu-gray border-bambu-dark-tertiary hover:bg-bambu-dark-tertiary"}`,children:[r.jsx("option",{value:"",children:n("inventory.material")}),nt.map(he=>r.jsx("option",{value:he,children:he},he))]}),r.jsxs("select",{value:A,onChange:he=>{F(he.target.value),Be()},className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${A?"bg-bambu-green/20 text-bambu-green border-bambu-green/30":"bg-transparent text-bambu-gray border-bambu-dark-tertiary hover:bg-bambu-dark-tertiary"}`,children:[r.jsx("option",{value:"",children:n("inventory.brand")}),gt.map(he=>r.jsx("option",{value:he,children:he},he))]}),(yt.length>0||S)&&r.jsxs("select",{value:S,onChange:he=>{M(he.target.value),Be()},className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${S?"bg-bambu-green/20 text-bambu-green border-bambu-green/30":"bg-transparent text-bambu-gray border-bambu-dark-tertiary hover:bg-bambu-dark-tertiary"}`,children:[r.jsx("option",{value:"",children:n("inventory.category")}),yt.map(he=>r.jsx("option",{value:he,children:he},he)),ot&&r.jsx("option",{value:"__none__",children:n("inventory.categoryNone")})]}),Ht.length>0&&r.jsxs("select",{value:z,onChange:he=>{I(he.target.value),Be()},className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${z?"bg-bambu-green/20 text-bambu-green border-bambu-green/30":"bg-transparent text-bambu-gray border-bambu-dark-tertiary hover:bg-bambu-dark-tertiary"}`,children:[r.jsx("option",{value:"",children:n("inventory.spoolName")}),Ht.map(he=>r.jsx("option",{value:he,children:fe[he]?.name||`#${he}`},he))]}),Kt&&r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"w-px h-5 bg-bambu-dark-tertiary"}),r.jsxs("button",{onClick:dt,className:"flex items-center gap-1 text-xs text-bambu-gray hover:text-bambu-green transition-colors",children:[r.jsx(Bt,{className:"w-3.5 h-3.5"}),n("inventory.clearFilters")]})]}),J!=="forecast"&&r.jsxs("span",{className:"ml-auto text-xs text-bambu-gray",children:[ln.length," ",ln.length!==1?n("inventory.spools"):n("inventory.spool"),Te&&vt0?r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4",children:je.map(he=>{if(he.type==="group"){const{key:Ye,spools:ft,representative:et}=he,jt=nj({rgba:et.rgba,extraColors:et.extra_colors,effectType:et.effect_type,subtype:et.subtype,effectSize:"groupheader"}),St=K.has(Ye);return r.jsxs("div",{className:"col-span-full",children:[r.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg overflow-hidden border border-bambu-green/30 hover:border-bambu-green transition-colors cursor-pointer",onClick:()=>Je(Ye),children:[r.jsx("div",{className:"h-10 flex items-center px-4 gap-3",style:jt,children:r.jsx("span",{className:"bg-white/90 text-gray-800 px-3 py-0.5 rounded-full text-sm font-medium",children:CT(et.color_name,et.rgba)||"-"})}),r.jsxs("div",{className:"px-4 py-3 flex items-center justify-between",children:[r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx(Rn,{className:`w-4 h-4 text-bambu-gray transition-transform ${St?"":"-rotate-90"}`}),r.jsxs("div",{children:[r.jsxs("h3",{className:"font-semibold text-white",children:[et.material,et.subtype?` ${et.subtype}`:""]}),r.jsx("p",{className:"text-sm text-bambu-gray",children:et.brand||"-"})]})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"text-sm text-bambu-gray",children:au(et.label_weight)}),r.jsx("span",{className:"text-xs font-medium bg-bambu-green/20 text-bambu-green px-2 py-0.5 rounded-full",children:n("inventory.groupedSpools",{count:ft.length})})]})]})]}),St&&r.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4 mt-2 ml-4",children:ft.map(Lt=>{const Ot=Math.max(0,Lt.label_weight-Lt.weight_used),qe=Lt.label_weight>0?Ot/Lt.label_weight*100:0;return r.jsx(yQ,{spool:Lt,remaining:Ot,pct:qe,onClick:()=>m({spool:Lt,mode:"edit"}),onPrintLabel:()=>g([Lt.id]),onCopy:()=>m({spool:Lt,mode:"copy"}),t:n},Lt.id)})})]},`group-${Ye}`)}const Fe=he.spool,Qe=Math.max(0,Fe.label_weight-Fe.weight_used),Ze=Fe.label_weight>0?Qe/Fe.label_weight*100:0;return r.jsx(yQ,{spool:Fe,remaining:Qe,pct:Ze,onClick:()=>m({spool:Fe,mode:"edit"}),onPrintLabel:()=>g([Fe.id]),onCopy:()=>m({spool:Fe,mode:"copy"}),t:n},Fe.id)})}),r.jsx(ost,{pageIndex:De,pageSize:X,totalRows:vt,totalPages:Dt,onPageChange:B,onPageSizeChange:Le,t:n})]}):r.jsx(vQ,{hasFilters:Kt,onAddSpool:()=>m({spool:null,mode:"create"}),t:n}):je.length>0?r.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg overflow-hidden border border-bambu-dark-tertiary",children:[r.jsx("div",{className:"overflow-x-auto",children:r.jsxs("table",{className:"w-full",children:[r.jsx("thead",{children:r.jsxs("tr",{className:"border-b border-bambu-dark-tertiary bg-bambu-dark-tertiary/30",children:[Yt.map(he=>{const Fe=!!gF[he],Qe=me?.column===he;return r.jsx("th",{className:`text-left py-3 px-4 text-xs font-medium uppercase tracking-wide select-none ${he==="remaining"?"min-w-[150px]":""} ${Fe?"cursor-pointer hover:text-bambu-green transition-colors":""} ${Qe?"text-bambu-green":"text-bambu-gray"}`,onClick:Fe?()=>gn(he):void 0,children:r.jsxs("span",{className:"inline-flex items-center gap-1",children:[nst[he]?.(n)??he,Fe&&(Qe?me.direction==="asc"?r.jsx(Hm,{className:"w-3 h-3"}):r.jsx(Bh,{className:"w-3 h-3"}):r.jsx(vT,{className:"w-3 h-3 opacity-30"}))]})},he)}),r.jsx("th",{className:"text-right py-3 px-4 text-xs font-medium text-bambu-gray uppercase tracking-wide",children:n("common.actions")})]})}),r.jsx("tbody",{children:je.map(he=>{if(he.type==="group"){const{key:Ye,spools:ft,representative:et}=he,jt=K.has(Ye),St=Math.max(0,et.label_weight-et.weight_used),Lt=et.label_weight>0?St/et.label_weight*100:0;return r.jsx(lst,{spools:ft,representative:et,remaining:St,pct:Lt,isExpanded:jt,onToggle:()=>Je(Ye),onEdit:Ot=>m({spool:Ot,mode:"edit"}),onCopy:Ot=>m({spool:Ot,mode:"copy"}),onArchive:Ot=>b({type:"archive",spoolId:Ot}),onDelete:Ot=>b({type:"delete",spoolId:Ot}),onPrintLabel:Ot=>g([Ot]),visibleColumns:Yt,assignmentMap:Ue,catalogMap:fe,currencySymbol:Xe,dateFormat:U,t:n,onSyncWeight:_e},`group-${Ye}`)}const Fe=he.spool,Qe=Math.max(0,Fe.label_weight-Fe.weight_used),Ze=Fe.label_weight>0?Qe/Fe.label_weight*100:0;return r.jsx(Zce,{spool:Fe,remaining:Qe,pct:Ze,onEdit:()=>m({spool:Fe,mode:"edit"}),onCopy:()=>m({spool:Fe,mode:"copy"}),onRestore:()=>ze.mutate(Fe.id),onArchive:()=>b({type:"archive",spoolId:Fe.id}),onDelete:()=>b({type:"delete",spoolId:Fe.id}),onPrintLabel:()=>g([Fe.id]),visibleColumns:Yt,assignmentMap:Ue,catalogMap:fe,currencySymbol:Xe,dateFormat:U,t:n,onSyncWeight:_e},Fe.id)})})]})}),r.jsxs("div",{className:"flex items-center justify-between px-4 py-3 bg-bambu-dark-tertiary/50 border-t border-bambu-dark-tertiary text-sm",children:[r.jsx("span",{className:"text-bambu-gray",children:at?`${vt} ${n(vt!==1?"inventory.spools":"inventory.spool")}`:r.jsxs(r.Fragment,{children:[n("inventory.showing")," ",De*_t+1," ",n("inventory.to")," ",Math.min((De+1)*_t,vt)," ",n("inventory.of")," ",vt," ",n("inventory.spools")]})}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"text-bambu-gray",children:n("inventory.show")}),r.jsxs("select",{value:X,onChange:he=>Le(Number(he.target.value)),className:"px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:outline-none focus:border-bambu-green",children:[[15,30,50,100].map(he=>r.jsx("option",{value:he,children:he},he)),r.jsx("option",{value:-1,children:n("inventory.all")})]}),!at&&r.jsxs(r.Fragment,{children:[r.jsx("button",{onClick:()=>B(0),disabled:De===0,className:"p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors",title:"First page",children:r.jsx(hO,{className:"w-4 h-4"})}),r.jsx("button",{onClick:()=>B(he=>Math.max(0,he-1)),disabled:De===0,className:"p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors",children:r.jsx(el,{className:"w-4 h-4"})}),r.jsxs("span",{className:"text-bambu-gray px-2 whitespace-nowrap",children:[n("inventory.page")," ",De+1," ",n("inventory.of")," ",Dt]}),r.jsx("button",{onClick:()=>B(he=>Math.min(Dt-1,he+1)),disabled:De>=Dt-1,className:"p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors",children:r.jsx(Va,{className:"w-4 h-4"})}),r.jsx("button",{onClick:()=>B(Dt-1),disabled:De>=Dt-1,className:"p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors",title:"Last page",children:r.jsx(fO,{className:"w-4 h-4"})})]})]})]})]}):r.jsx(vQ,{hasFilters:Kt,onAddSpool:()=>m({spool:null,mode:"create"}),t:n}),u!==null&&r.jsx(Vit,{isOpen:!0,onClose:()=>m(null),spool:u.spool,mode:u.mode,currencySymbol:Xe,spoolmanMode:t,spoolsQueryKey:G}),f&&r.jsx(vn,{title:f.type==="delete"?n("common.delete"):n("inventory.archive"),message:f.type==="delete"?n("inventory.deleteConfirm"):n("inventory.archiveConfirm"),confirmText:f.type==="delete"?n("common.delete"):n("inventory.archive"),variant:f.type==="delete"?"danger":"warning",onConfirm:()=>{f.type==="delete"?be.mutate(f.spoolId):Ee.mutate(f.spoolId),b(null)},onCancel:()=>b(null)}),r.jsx(Git,{isOpen:pe,onClose:()=>ye(!1),columns:W,defaultColumns:BN,onSave:Zt}),r.jsx(Zit,{isOpen:w!==null,onClose:()=>g(null),availableSpools:$e,initialSelectedIds:w??[],spoolmanMode:!1})]})}function ost({pageIndex:t,pageSize:e,totalRows:n,totalPages:a,onPageChange:i,onPageSizeChange:s,t:o}){const l=e===-1;if(a<=1&&!l)return null;const c=l?n||1:e;return r.jsxs("div",{className:"flex items-center justify-between pt-2 text-sm",children:[r.jsx("span",{className:"text-bambu-gray",children:l?`${n} ${o(n!==1?"inventory.spools":"inventory.spool")}`:r.jsxs(r.Fragment,{children:[o("inventory.showing")," ",t*c+1," ",o("inventory.to")," ",Math.min((t+1)*c,n)," ",o("inventory.of")," ",n," ",o("inventory.spools")]})}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"text-bambu-gray",children:o("inventory.show")}),r.jsxs("select",{value:e,onChange:d=>s(Number(d.target.value)),className:"px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:outline-none focus:border-bambu-green",children:[[15,30,50,100].map(d=>r.jsx("option",{value:d,children:d},d)),r.jsx("option",{value:-1,children:o("inventory.all")})]}),!l&&r.jsxs(r.Fragment,{children:[r.jsx("button",{onClick:()=>i(0),disabled:t===0,className:"p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors",children:r.jsx(hO,{className:"w-4 h-4"})}),r.jsx("button",{onClick:()=>i(Math.max(0,t-1)),disabled:t===0,className:"p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors",children:r.jsx(el,{className:"w-4 h-4"})}),r.jsxs("span",{className:"text-bambu-gray px-2 whitespace-nowrap",children:[o("inventory.page")," ",t+1," ",o("inventory.of")," ",a]}),r.jsx("button",{onClick:()=>i(Math.min(a-1,t+1)),disabled:t>=a-1,className:"p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors",children:r.jsx(Va,{className:"w-4 h-4"})}),r.jsx("button",{onClick:()=>i(a-1),disabled:t>=a-1,className:"p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors",children:r.jsx(fO,{className:"w-4 h-4"})})]})]})]})}function yQ({spool:t,remaining:e,pct:n,onClick:a,onPrintLabel:i,onCopy:s,t:o}){const l=nj({rgba:t.rgba,extraColors:t.extra_colors,effectType:t.effect_type,subtype:t.subtype,effectSize:"card"});return r.jsxs("div",{className:`bg-bambu-dark-secondary rounded-lg overflow-hidden border border-bambu-dark-tertiary hover:border-bambu-green transition-colors cursor-pointer ${t.archived_at?"opacity-50":""}`,onClick:a,children:[r.jsxs("div",{className:"h-14 flex items-center justify-center",style:l,children:[r.jsx("span",{className:"bg-white/90 text-gray-800 px-3 py-0.5 rounded-full text-sm font-medium",children:CT(t.color_name,t.rgba)||"-"}),s&&r.jsx("button",{type:"button",onClick:c=>{c.stopPropagation(),s()},className:"p-1.5 bg-black/20 hover:bg-black/40 text-white rounded-full transition-colors",title:o("inventory.copySpool"),children:r.jsx(Mi,{className:"w-3.5 h-3.5"})})]}),r.jsxs("div",{className:"p-4 space-y-3",children:[r.jsxs("div",{className:"flex items-start justify-between gap-2",children:[r.jsxs("div",{children:[r.jsxs("h3",{className:"font-semibold text-white",children:[t.material,t.subtype?` ${t.subtype}`:""]}),r.jsx("p",{className:"text-sm text-bambu-gray",children:t.brand||"-"})]}),r.jsxs("div",{className:"flex items-center gap-1",children:[i&&r.jsx("button",{onClick:c=>{c.stopPropagation(),i()},className:"p-1 text-bambu-gray hover:text-white rounded transition-colors",title:o("inventory.labels.printOne"),"aria-label":o("inventory.labels.printOne"),children:r.jsx(pr,{className:"w-4 h-4"})}),r.jsxs("span",{className:"text-xs font-mono text-bambu-gray bg-bambu-dark-tertiary px-2 py-1 rounded",children:["#",t.id]})]})]}),r.jsxs("div",{children:[r.jsxs("div",{className:"flex justify-between text-xs text-bambu-gray mb-1",children:[r.jsx("span",{children:o("inventory.remaining")}),r.jsxs("span",{children:[Math.round(n),"%"]})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("div",{className:"flex-1 h-2 bg-bambu-dark-tertiary rounded-full overflow-hidden",children:r.jsx("div",{className:`h-full rounded-full ${n>50?"bg-bambu-green":n>20?"bg-yellow-500":"bg-red-500"}`,style:{width:`${Math.min(n,100)}%`}})}),r.jsxs("span",{className:"text-xs text-bambu-gray min-w-[40px] text-right",children:[Math.round(e),"g"]})]})]}),r.jsxs("div",{className:"grid grid-cols-2 gap-2 text-xs",children:[r.jsxs("div",{children:[r.jsxs("span",{className:"text-bambu-gray/60",children:[o("inventory.labelWeight"),": "]}),r.jsx("span",{className:"text-bambu-gray",children:au(t.label_weight)})]}),r.jsxs("div",{children:[r.jsxs("span",{className:"text-bambu-gray/60",children:[o("inventory.weightUsed"),": "]}),r.jsx("span",{className:"text-bambu-gray",children:t.weight_used>0?au(t.weight_used):"-"})]})]}),t.note&&r.jsx("div",{className:"text-xs text-bambu-gray/60 pt-2 border-t border-bambu-dark-tertiary truncate",title:t.note,children:t.note})]})]})}function Zce({spool:t,remaining:e,pct:n,onEdit:a,onCopy:i,onRestore:s,onArchive:o,onDelete:l,onPrintLabel:c,visibleColumns:d,assignmentMap:u,catalogMap:m,currencySymbol:p,dateFormat:f,t:b,onSyncWeight:w}){return r.jsxs("tr",{className:`border-b border-bambu-dark-tertiary/50 hover:bg-bambu-dark-tertiary/30 transition-colors cursor-pointer ${t.archived_at?"opacity-50":""}`,onClick:a,children:[d.map(g=>r.jsx("td",{className:"py-3 px-4",children:YI[g]?.({spool:t,remaining:e,pct:n,assignmentMap:u,catalogMap:m,currencySymbol:p,dateFormat:f,t:b,onSyncWeight:w})},g)),r.jsx("td",{className:"py-3 px-4",children:r.jsxs("div",{className:"flex items-center justify-end gap-1",onClick:g=>g.stopPropagation(),children:[r.jsx("button",{onClick:a,className:"p-1.5 text-bambu-gray hover:text-white rounded transition-colors",title:b("common.edit"),children:r.jsx(fc,{className:"w-4 h-4"})}),i&&r.jsx("button",{onClick:i,className:"p-1.5 text-bambu-gray hover:text-bambu-green rounded transition-colors",title:b("inventory.copySpool"),children:r.jsx(Mi,{className:"w-4 h-4"})}),c&&r.jsx("button",{onClick:c,className:"p-1.5 text-bambu-gray hover:text-white rounded transition-colors",title:b("inventory.labels.printOne"),children:r.jsx(pr,{className:"w-4 h-4"})}),t.archived_at?r.jsx("button",{onClick:s,className:"p-1.5 text-bambu-gray hover:text-bambu-green rounded transition-colors",title:b("inventory.restore"),children:r.jsx(gs,{className:"w-4 h-4"})}):r.jsx("button",{onClick:o,className:"p-1.5 text-bambu-gray hover:text-yellow-400 rounded transition-colors",title:b("inventory.archive"),children:r.jsx(ro,{className:"w-4 h-4"})}),r.jsx("button",{onClick:l,className:"p-1.5 text-bambu-gray hover:text-red-400 rounded transition-colors",title:b("common.delete"),children:r.jsx(Jt,{className:"w-4 h-4"})})]})})]})}function lst({spools:t,representative:e,remaining:n,pct:a,isExpanded:i,onToggle:s,onEdit:o,onCopy:l,onArchive:c,onDelete:d,onPrintLabel:u,visibleColumns:m,assignmentMap:p,catalogMap:f,currencySymbol:b,dateFormat:w,t:g,onSyncWeight:x}){return r.jsxs(r.Fragment,{children:[r.jsxs("tr",{className:"border-b border-bambu-dark-tertiary/50 hover:bg-bambu-dark-tertiary/30 transition-colors cursor-pointer bg-bambu-green/5",onClick:s,children:[m.map((_,N)=>r.jsx("td",{className:"py-3 px-4",children:N===0?r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(Rn,{className:`w-4 h-4 text-bambu-gray transition-transform ${i?"":"-rotate-90"}`}),YI[_]?.({spool:e,remaining:n,pct:a,assignmentMap:p,catalogMap:f,currencySymbol:b,dateFormat:w,t:g,onSyncWeight:x})]}):_==="id"?r.jsx("span",{className:"text-xs font-medium bg-bambu-green/20 text-bambu-green px-2 py-0.5 rounded-full",children:g("inventory.groupedSpools",{count:t.length})}):YI[_]?.({spool:e,remaining:n,pct:a,assignmentMap:p,catalogMap:f,currencySymbol:b,dateFormat:w,t:g,onSyncWeight:x})},_)),r.jsx("td",{className:"py-3 px-4",children:r.jsx("span",{className:"text-xs text-bambu-gray",children:t.map(_=>`#${_.id}`).join(", ")})})]}),i&&t.map(_=>{const N=Math.max(0,_.label_weight-_.weight_used),C=_.label_weight>0?N/_.label_weight*100:0;return r.jsx(Zce,{spool:_,remaining:N,pct:C,onEdit:()=>o(_),onCopy:l?()=>l(_):void 0,onRestore:()=>{},onArchive:()=>c(_.id),onDelete:()=>d(_.id),onPrintLabel:u?()=>u(_.id):void 0,visibleColumns:m,assignmentMap:p,catalogMap:f,currencySymbol:b,dateFormat:w,t:g,onSyncWeight:x},_.id)})]})}function vQ({hasFilters:t,onAddSpool:e,t:n}){return r.jsxs("div",{className:"flex flex-col items-center justify-center py-16 px-4",children:[r.jsxs("div",{className:"relative mb-6",children:[r.jsx("div",{className:"absolute inset-0 -m-4 bg-bambu-green/5 rounded-full blur-2xl"}),r.jsxs("div",{className:"relative flex items-center justify-center w-24 h-24 rounded-2xl bg-gradient-to-br from-bambu-dark-secondary to-bambu-dark-tertiary border border-bambu-dark-tertiary shadow-lg",children:[r.jsx("div",{className:"absolute -top-1 -right-1 w-3 h-3 rounded-full bg-bambu-green/30"}),r.jsx("div",{className:"absolute -bottom-2 -left-2 w-2 h-2 rounded-full bg-bambu-green/20"}),t?r.jsx(Sr,{className:"w-10 h-10 text-bambu-gray/40",strokeWidth:1.5}):r.jsxs("div",{className:"relative",children:[r.jsx("div",{className:"w-14 h-14 rounded-full border-4 border-bambu-gray/20 flex items-center justify-center",children:r.jsx("div",{className:"w-6 h-6 rounded-full bg-bambu-gray/10 border-2 border-bambu-gray/20"})}),r.jsx("div",{className:"absolute -bottom-1 -right-1 w-6 h-6 rounded-full bg-bambu-green flex items-center justify-center shadow-md",children:r.jsx("span",{className:"text-white text-lg font-bold leading-none",children:"+"})})]})]})]}),r.jsx("h3",{className:"text-lg font-semibold text-white mb-2 text-center",children:t?n("inventory.noSpoolsMatch"):n("inventory.noSpools").split(".")[0]}),r.jsx("p",{className:"text-sm text-bambu-gray text-center max-w-sm mb-6",children:n(t?"inventory.noSpoolsMatchDesc":"inventory.noSpools")}),!t&&r.jsxs(Me,{onClick:e,children:[r.jsx(Br,{className:"w-4 h-4"}),n("inventory.addSpool")]})]})}function zd(t,e){const n=t?.[e];return typeof n=="string"?n:""}function cst(t){return t.replace(/(https?:\/\/(?:makerworld|public-cdn)\.bblmw\.com\/[^\s"']+)/gi,e=>`/api/v1/makerworld/thumbnail?url=${encodeURIComponent(e)}`)}function bF(t){return t?/^https?:\/\/(makerworld|public-cdn)\.bblmw\.com\//i.test(t)?`/api/v1/makerworld/thumbnail?url=${encodeURIComponent(t)}`:t:""}function Xp(t,e){const n=t?.[e];return typeof n=="number"?n:null}function dst(t,e){const n=t?.[e];return n&&typeof n=="object"&&!Array.isArray(n)?n:void 0}function Jce(t,e=0,n=[]){n.push({folder:t,depth:e});for(const a of t.children??[])Jce(a,e+1,n);return n}function ust(t,e){return t<1?e("makerworld.phaseResolving"):e("makerworld.phaseDownloading")}function mst(t){const[e,n]=v.useState(0);return v.useEffect(()=>{if(!t){n(0);return}const a=Date.now(),i=()=>n(Math.floor((Date.now()-a)/1e3));i();const s=window.setInterval(i,1e3);return()=>window.clearInterval(s)},[t]),e}function pst(){const{t}=kt(),{hasPermission:e}=cr(),{showToast:n}=rn(),a=en(),i=e("makerworld:import"),[s,o]=v.useState(""),[l,c]=v.useState(null),[d,u]=v.useState(null),[m,p]=v.useState(null),[f,b]=v.useState(null),[w,g]=v.useState(null),[x,_]=v.useState(""),[N,C]=v.useState({}),P=We({queryKey:["makerworld-status"],queryFn:()=>se.getMakerworldStatus()}),T=We({queryKey:["library-folders"],queryFn:()=>se.getLibraryFolders()}),A=We({queryKey:["makerworld-recent-imports"],queryFn:()=>se.getMakerworldRecentImports(10)}),F=We({queryKey:["settings"],queryFn:()=>se.getSettings()}),S=F.data?.preferred_slicer||"bambu_studio",M=S==="orcaslicer"?"OrcaSlicer":"Bambu Studio",z=F.data?.use_slicer_api??!1,[I,H]=v.useState(null),L=(Y,Q)=>{H({kind:"libraryFile",id:Y,filename:Q})},Z=it({mutationFn:Y=>se.resolveMakerworldUrl(Y),onSuccess:(Y,Q)=>{c(Y),_(Q),C({})},onError:Y=>n(Y.message||t("makerworld.errors.resolveFailed"),"error")});v.useEffect(()=>{l!==null&&s.trim()!==x.trim()&&(c(null),_(""),C({}))},[s,l,x]);const re=it({mutationFn:({instanceId:Y,profileId:Q})=>se.importMakerworldInstance(l?.model_id??0,Y,Q,d),onSuccess:Y=>{a.invalidateQueries({queryKey:["library-files"]}),a.invalidateQueries({queryKey:["library-folders"]}),Y.profile_id&&C(Q=>({...Q,[Y.profile_id]:Y})),n(Y.was_existing?t("makerworld.alreadyInLibrary"):t("makerworld.importSuccess",{filename:Y.filename}),"success")},onError:Y=>n(Y.message||t("makerworld.errors.downloadFailed"),"error")}),J=it({mutationFn:({libraryFileId:Y})=>se.deleteLibraryFile(Y),onSuccess:(Y,{profileId:Q})=>{a.invalidateQueries({queryKey:["library-files"]}),a.invalidateQueries({queryKey:["library-folders"]}),a.invalidateQueries({queryKey:["makerworld-recent-imports"]}),C(oe=>{const ee={...oe};return delete ee[Q],ee}),b(null),n(t("makerworld.importDeleted"),"success")},onError:Y=>{b(null),n(Y.message||t("makerworld.errors.deleteFailed"),"error")}}),de=it({mutationFn:({instanceId:Y,profileId:Q})=>se.importMakerworldInstance(l?.model_id??0,Y,Q,d),onSuccess:async Y=>{a.invalidateQueries({queryKey:["library-files"]}),a.invalidateQueries({queryKey:["library-folders"]}),a.invalidateQueries({queryKey:["makerworld-recent-imports"]}),Y.profile_id&&C(Q=>({...Q,[Y.profile_id]:Y})),z?L(Y.library_file_id,Y.filename):await ye(Y.library_file_id,Y.filename,S)},onError:Y=>n(Y.message||t("makerworld.errors.downloadFailed"),"error")}),me=mst(re.isPending||de.isPending),ue=ust(me,t),W=Y=>{Y?.preventDefault();const Q=s.trim();Q&&Z.mutate(Q)};v.useEffect(()=>{if(!w)return;const Y=Q=>{Q.key==="Escape"?g(null):Q.key==="ArrowLeft"?g(oe=>oe&&oe.index>0?{...oe,index:oe.index-1}:oe):Q.key==="ArrowRight"&&g(oe=>oe&&oe.indexwindow.removeEventListener("keydown",Y)},[w]);const ae=Y=>{const oe=(Array.isArray(Y.pictures)?Y.pictures:[]).filter(ge=>ge!==null&&typeof ge=="object").map(ge=>({name:zd(ge,"name")||"image",url:zd(ge,"url")})).filter(ge=>ge.url);if(oe.length>0)return oe;const ee=zd(Y,"cover");return ee?[{name:"cover",url:ee}]:[]},pe=async()=>{if(!l)return;const Y=l.instances.filter(Q=>{const oe=Xp(Q,"profileId");return oe!==null&&!N[oe]});if(Y.length!==0){p({current:0,total:Y.length});try{for(let Q=0;Q{try{const{token:ee}=await se.createLibrarySlicerToken(Y),ge=se.getLibrarySlicerDownloadUrl(Y,ee,Q);Am(`${window.location.origin}${ge}`,oe)}catch{const ee=se.getLibraryFileDownloadUrl(Y);Am(`${window.location.origin}${ee}`,oe)}},Te=l?.design,$=dst(Te,"designCreator"),K=l?.instances??[],D=(l?.already_imported_library_ids.length??0)>0,j=P.data?.has_cloud_token??!1,B=P.data?.can_download??!1,X=v.useMemo(()=>zd(Te,"coverUrl"),[Te]),O=zd(Te,"title"),ie=zd(Te,"summary"),U=zd(Te,"license"),G=Xp(Te,"downloadCount");return r.jsxs("div",{className:"p-4 md:p-8 max-w-screen-2xl space-y-6",children:[r.jsxs("div",{children:[r.jsxs("h1",{className:"text-2xl font-bold text-white flex items-center gap-3",children:[r.jsx(no,{className:"w-7 h-7 text-bambu-green"}),t("makerworld.title")]}),r.jsx("p",{className:"text-bambu-gray mt-1",children:t("makerworld.description")})]}),r.jsxs("div",{className:"grid gap-6 lg:grid-cols-[1fr_20rem]",children:[r.jsxs("div",{className:"space-y-6 min-w-0",children:[!j&&r.jsx(Ct,{className:"border-amber-300 dark:border-amber-700 bg-amber-50 dark:bg-amber-900/20",children:r.jsx(At,{children:r.jsxs("div",{className:"flex items-start gap-3 py-2",children:[r.jsx($a,{className:"w-5 h-5 text-amber-600 dark:text-amber-400 mt-0.5 shrink-0"}),r.jsxs("div",{className:"text-sm",children:[r.jsx("p",{className:"font-medium text-amber-900 dark:text-amber-100",children:t("makerworld.signInRequiredTitle")}),r.jsxs("p",{className:"text-amber-800 dark:text-amber-200 mt-1",children:[t("makerworld.signInRequiredBody")," ",r.jsx(Is,{to:"/profiles",className:"underline",children:t("makerworld.openCloudSettings")})]})]})]})})}),r.jsxs(Ct,{children:[r.jsx(pn,{children:r.jsx("h2",{className:"text-lg font-semibold",children:t("makerworld.pasteUrlHeader")})}),r.jsx(At,{children:r.jsxs("form",{onSubmit:W,className:"flex gap-2",children:[r.jsx("input",{type:"text",value:s,onChange:Y=>o(Y.target.value),placeholder:t("makerworld.pasteUrlPlaceholder"),className:"flex-1 min-w-0 px-3 py-2 border rounded bg-white dark:bg-gray-800 border-gray-300 dark:border-gray-700",autoComplete:"off"}),r.jsxs(Me,{type:"submit",variant:"primary",disabled:!s.trim()||Z.isPending,children:[Z.isPending?r.jsx(ut,{className:"w-4 h-4 animate-spin"}):r.jsx(YN,{className:"w-4 h-4"}),r.jsx("span",{className:"ml-2",children:t("makerworld.resolveButton")})]})]})})]}),l&&r.jsx(Ct,{children:r.jsx(At,{children:r.jsxs("div",{className:"flex gap-4 py-2",children:[X&&r.jsx("img",{src:bF(X),alt:O,className:"w-32 h-32 object-cover rounded",loading:"lazy"}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("h3",{className:"text-xl font-semibold truncate",children:O||t("makerworld.untitledModel")}),$&&r.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400 mt-1",children:t("makerworld.byCreator",{name:zd($,"name")})}),r.jsxs("div",{className:"flex flex-wrap gap-3 mt-2 text-xs text-gray-500 dark:text-gray-400",children:[G!==null&&r.jsx("span",{children:t("makerworld.downloadsCount",{count:G})}),U&&r.jsxs("span",{children:[t("makerworld.licensePrefix"),": ",U]}),D&&r.jsxs("span",{className:"inline-flex items-center gap-1 text-emerald-600 dark:text-emerald-400",children:[r.jsx(_r,{className:"w-3 h-3"})," ",t("makerworld.alreadyImported")]})]}),ie&&r.jsx("div",{className:"mt-3 text-sm prose prose-sm max-w-none dark:prose-invert line-clamp-3",dangerouslySetInnerHTML:{__html:l5.sanitize(cst(ie))}}),l&&r.jsxs("a",{href:`https://makerworld.com/models/${l.model_id}${l.profile_id?`#profileId-${l.profile_id}`:""}`,target:"_blank",rel:"noopener noreferrer",className:"mt-3 inline-flex items-center gap-1 text-xs text-brand-500 hover:underline",children:[r.jsx(Lr,{className:"w-3 h-3"})," ",t("makerworld.openOnMakerworld")]})]})]})})}),l&&K.length>0&&r.jsxs(Ct,{children:[r.jsx(pn,{children:r.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[r.jsx("h2",{className:"text-lg font-semibold",children:t("makerworld.platesHeader",{count:K.length})}),r.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[r.jsx("label",{className:"text-xs text-gray-600 dark:text-gray-400",children:t("makerworld.importTo")}),r.jsxs("select",{value:d??"",onChange:Y=>u(Y.target.value?Number(Y.target.value):null),className:"text-sm px-2 py-1 border rounded bg-white dark:bg-gray-800 border-gray-300 dark:border-gray-700",disabled:m!==null,children:[r.jsx("option",{value:"",children:t("makerworld.folderAuto")}),(T.data??[]).filter(Y=>!(Y.is_external&&Y.external_readonly)).flatMap(Y=>Jce(Y)).map(({folder:Y,depth:Q})=>r.jsx("option",{value:Y.id,children:`${"— ".repeat(Q)}${Y.name}`},Y.id))]}),r.jsx(Me,{variant:"primary",size:"sm",disabled:!i||!B||m!==null||re.isPending||de.isPending,onClick:pe,children:m!==null?r.jsxs(r.Fragment,{children:[r.jsx(ut,{className:"w-4 h-4 animate-spin"}),r.jsxs("span",{className:"ml-2",children:[t("makerworld.importAllProgress",{current:m.current,total:m.total}),me>0&&` · ${ue} · ${me}s`]})]}):r.jsxs(r.Fragment,{children:[r.jsx(Yr,{className:"w-4 h-4"}),r.jsx("span",{className:"ml-2",children:t("makerworld.importAll")})]})})]})]})}),r.jsx(At,{children:r.jsx("div",{className:"grid gap-3",children:K.map((Y,Q)=>{const oe=Xp(Y,"id"),ee=Xp(Y,"profileId"),ge=zd(Y,"title"),ce=zd(Y,"cover"),le=Xp(Y,"materialCnt"),q=Y?.needAms===!0,R=Xp(Y,"downloadCount"),ne=Y?.compatibility??null,xe=Y?.otherCompatibility??null,we=ne?.devProductName??null,Ne=Array.isArray(xe)?xe.map(ze=>ze?.devProductName??"").filter(Boolean):[];if(oe==null)return null;const ve=re.isPending&&re.variables?.instanceId===oe,be=de.isPending&&de.variables?.instanceId===oe,Ee=ee!==null?N[ee]:void 0;return r.jsxs("div",{className:"flex flex-col gap-2 p-3 border rounded border-gray-200 dark:border-gray-700",children:[r.jsxs("div",{className:"flex gap-3 items-center",children:[(()=>{const ze=ae(Y),_e=ze.length>0;return r.jsxs("button",{type:"button",disabled:!_e,onClick:()=>_e&&g({images:ze,index:0}),className:"relative w-16 h-16 shrink-0 rounded overflow-hidden group","aria-label":t("makerworld.openGallery"),children:[ce?r.jsx("img",{src:bF(ce),alt:"",className:"w-16 h-16 object-cover",loading:"lazy"}):r.jsx("div",{className:"w-16 h-16 bg-gray-100 dark:bg-gray-800"}),ze.length>1&&r.jsxs("span",{className:"absolute bottom-0.5 right-0.5 bg-black/70 text-white text-[10px] px-1.5 py-0.5 rounded flex items-center gap-1",children:[r.jsx(Bbe,{className:"w-2.5 h-2.5"}),ze.length]})]})})(),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("p",{className:"font-medium truncate",children:ge||t("makerworld.plateDefaultName",{n:Q+1})}),r.jsxs("div",{className:"flex flex-wrap gap-3 text-xs text-gray-500 dark:text-gray-400 mt-1",children:[we&&r.jsx("span",{className:"font-medium text-gray-700 dark:text-gray-300",children:t("makerworld.slicedFor",{printer:we,defaultValue:"Sliced for {{printer}}"})}),le!==null&&r.jsx("span",{children:t("makerworld.materialCount",{count:le})}),q&&r.jsx("span",{children:t("makerworld.amsRequired")}),R!==null&&r.jsx("span",{children:t("makerworld.downloadsCount",{count:R})})]}),Ne.length>0&&r.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400 mt-1",title:Ne.join(", "),children:t("makerworld.alsoCompatible",{printers:Ne.slice(0,6).join(", ")+(Ne.length>6?"…":""),defaultValue:"Also marked compatible: {{printers}}"})})]}),r.jsxs("div",{className:"flex gap-2 shrink-0",children:[r.jsx(Me,{variant:"ghost",size:"sm",disabled:!i||!B||ve||be||m!==null,onClick:()=>re.mutate({instanceId:oe,profileId:ee}),title:B?void 0:t("makerworld.signInRequiredTitle"),children:ve?r.jsxs(r.Fragment,{children:[r.jsx(ut,{className:"w-4 h-4 animate-spin"}),r.jsxs("span",{className:"ml-2",children:[ue,me>0&&` · ${me}s`]})]}):r.jsxs(r.Fragment,{children:[r.jsx(Yr,{className:"w-4 h-4"}),r.jsx("span",{className:"ml-2",children:t("makerworld.importToLibrary")})]})}),r.jsx(Me,{variant:"primary",size:"sm",disabled:!i||!B||ve||be||m!==null,onClick:()=>de.mutate({instanceId:oe,profileId:ee}),title:B?void 0:t("makerworld.signInRequiredTitle"),children:be?r.jsxs(r.Fragment,{children:[r.jsx(ut,{className:"w-4 h-4 animate-spin"}),r.jsxs("span",{className:"ml-2",children:[ue,me>0&&` · ${me}s`]})]}):r.jsxs(r.Fragment,{children:[r.jsx(Lr,{className:"w-4 h-4"}),r.jsx("span",{className:"ml-2",children:t("makerworld.sliceIn",{slicer:M})})]})})]})]}),Ee&&r.jsxs("div",{className:"flex items-center gap-2 pl-20 text-xs",children:[r.jsx(_r,{className:"w-3.5 h-3.5 text-emerald-600 dark:text-emerald-400 shrink-0"}),r.jsx("span",{className:"text-emerald-700 dark:text-emerald-300",children:Ee.was_existing?t("makerworld.lastImportAlreadyInLibrary"):t("makerworld.lastImportSuccess")}),r.jsxs(Me,{variant:"ghost",size:"sm",onClick:()=>{const ze=Ee.folder_id?`/files?folder=${Ee.folder_id}`:"/files";window.location.assign(ze)},children:[r.jsx(Fl,{className:"w-3.5 h-3.5"}),r.jsx("span",{className:"ml-1.5",children:t("makerworld.viewInLibrary")})]}),z?r.jsxs(Me,{variant:"ghost",size:"sm",onClick:()=>L(Ee.library_file_id,Ee.filename),children:[r.jsx(cu,{className:"w-3.5 h-3.5"}),r.jsx("span",{className:"ml-1.5",children:t("slice.action","Slice")})]}):r.jsxs(r.Fragment,{children:[r.jsxs(Me,{variant:"ghost",size:"sm",onClick:()=>ye(Ee.library_file_id,Ee.filename,"bambu_studio"),children:[r.jsx(Lr,{className:"w-3.5 h-3.5"}),r.jsx("span",{className:"ml-1.5",children:t("makerworld.openInBambuStudio")})]}),r.jsxs(Me,{variant:"ghost",size:"sm",onClick:()=>ye(Ee.library_file_id,Ee.filename,"orcaslicer"),children:[r.jsx(Lr,{className:"w-3.5 h-3.5"}),r.jsx("span",{className:"ml-1.5",children:t("makerworld.openInOrcaSlicer")})]})]}),r.jsx("div",{className:"ml-auto",children:r.jsx(Me,{variant:"ghost",size:"sm",disabled:J.isPending&&J.variables?.profileId===ee,onClick:()=>{ee!==null&&b({libraryFileId:Ee.library_file_id,profileId:ee,filename:Ee.filename})},title:t("makerworld.deleteImport"),children:J.isPending&&J.variables?.profileId===ee?r.jsx(ut,{className:"w-3.5 h-3.5 animate-spin"}):r.jsx(Jt,{className:"w-3.5 h-3.5 text-red-500"})})})]})]},oe)})})})]})]}),r.jsx("aside",{className:"lg:sticky lg:top-6 lg:self-start min-w-0",children:A.data&&A.data.length>0&&r.jsxs(Ct,{children:[r.jsx(pn,{children:r.jsx("h2",{className:"text-base font-semibold",children:t("makerworld.recentImportsHeader")})}),r.jsx(At,{children:r.jsx("div",{className:"flex flex-col gap-2 max-h-[28rem] overflow-y-auto -mx-2 px-2",children:A.data.map(Y=>r.jsxs("div",{className:"flex gap-2 p-2 border rounded border-gray-200 dark:border-gray-700",children:[Y.thumbnail_path?r.jsx("img",{src:se.getLibraryFileThumbnailUrl(Y.library_file_id),alt:"",className:"w-12 h-12 shrink-0 object-cover rounded bg-gray-100 dark:bg-gray-800",loading:"lazy"}):r.jsx("div",{className:"w-12 h-12 shrink-0 rounded bg-gray-100 dark:bg-gray-800"}),r.jsxs("div",{className:"flex-1 min-w-0 flex flex-col gap-1",children:[r.jsx("p",{className:"text-xs font-medium truncate",title:Y.filename,children:Y.filename}),r.jsxs("div",{className:"flex gap-0.5",children:[r.jsx(Me,{variant:"ghost",size:"sm",onClick:()=>{const Q=Y.folder_id?`/files?folder=${Y.folder_id}`:"/files";window.location.assign(Q)},title:t("makerworld.viewInLibrary"),children:r.jsx(Fl,{className:"w-3.5 h-3.5"})}),z?r.jsx(Me,{variant:"ghost",size:"sm",onClick:()=>L(Y.library_file_id,Y.filename),title:t("slice.action","Slice"),children:r.jsx(cu,{className:"w-3.5 h-3.5"})}):r.jsx(Me,{variant:"ghost",size:"sm",onClick:()=>ye(Y.library_file_id,Y.filename,"bambu_studio"),title:t("makerworld.openInBambuStudio"),children:r.jsx(Lr,{className:"w-3.5 h-3.5"})}),Y.source_url&&r.jsx("a",{href:Y.source_url,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center justify-center h-7 w-7 rounded text-gray-500 hover:text-gray-700 dark:hover:text-gray-300",title:t("makerworld.openOnMakerworld"),children:r.jsx(no,{className:"w-3.5 h-3.5"})})]})]})]},Y.library_file_id))})})]})})]}),r.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400 pt-4 border-t border-gray-200 dark:border-gray-700",children:t("makerworld.disclaimer")}),f&&r.jsx(vn,{title:t("makerworld.deleteImport"),message:t("makerworld.confirmDelete",{filename:f.filename}),confirmText:t("makerworld.deleteImport"),variant:"danger",isLoading:J.isPending,loadingText:t("makerworld.importDeleting"),onCancel:()=>b(null),onConfirm:()=>J.mutate({libraryFileId:f.libraryFileId,profileId:f.profileId})}),I&&r.jsx(DA,{source:I,onClose:()=>H(null)}),w&&r.jsxs("div",{className:"fixed inset-0 bg-black/90 flex items-center justify-center z-50",onClick:()=>g(null),role:"dialog","aria-modal":"true",children:[r.jsx("button",{type:"button",className:"absolute top-4 right-4 p-2 bg-white/10 hover:bg-white/20 rounded-full text-white",onClick:Y=>{Y.stopPropagation(),g(null)},"aria-label":t("common.close","Close"),children:r.jsx(Bt,{className:"w-5 h-5"})}),w.images.length>1&&r.jsxs(r.Fragment,{children:[r.jsx("button",{type:"button",className:"absolute left-4 p-2 bg-white/10 hover:bg-white/20 rounded-full text-white disabled:opacity-30",disabled:w.index===0,onClick:Y=>{Y.stopPropagation(),g(Q=>Q&&{...Q,index:Math.max(0,Q.index-1)})},"aria-label":t("makerworld.galleryPrev"),children:r.jsx(el,{className:"w-6 h-6"})}),r.jsx("button",{type:"button",className:"absolute right-4 p-2 bg-white/10 hover:bg-white/20 rounded-full text-white disabled:opacity-30",disabled:w.index>=w.images.length-1,onClick:Y=>{Y.stopPropagation(),g(Q=>Q&&{...Q,index:Math.min(Q.images.length-1,Q.index+1)})},"aria-label":t("makerworld.galleryNext"),children:r.jsx(Va,{className:"w-6 h-6"})})]}),r.jsx("img",{src:bF(w.images[w.index].url),alt:w.images[w.index].name,className:"max-w-[90vw] max-h-[90vh] object-contain",onClick:Y=>Y.stopPropagation()}),w.images.length>1&&r.jsxs("div",{className:"absolute bottom-6 left-1/2 -translate-x-1/2 text-white bg-black/60 px-3 py-1 rounded text-xs",children:[w.index+1," / ",w.images.length]})]})]})}const wQ=["DEBUG","INFO","WARNING","ERROR"],xF={DEBUG:"text-gray-400",INFO:"text-blue-400",WARNING:"text-yellow-400",ERROR:"text-red-400"},hst={DEBUG:hy,INFO:Ci,WARNING:Nn,ERROR:$a};function fst(){const t=en(),[e,n]=v.useState(!0),[a,i]=v.useState(new Set),[s,o]=v.useState(""),[l,c]=v.useState("ALL"),[d,u]=v.useState(!1),[m,p]=v.useState(!1),f=v.useRef(null),{data:b,isLoading:w,refetch:g}=We({queryKey:["application-logs",l,s],queryFn:()=>ey.getLogs({limit:200,level:l==="ALL"?void 0:l,search:s||void 0}),refetchInterval:m?2e3:!1,enabled:d});v.useEffect(()=>{d||p(!1)},[d]);const x=it({mutationFn:()=>ey.clearLogs(),onSuccess:()=>{t.invalidateQueries({queryKey:["application-logs"]})}});v.useEffect(()=>{e&&f.current&&b?.entries&&(f.current.scrollTop=f.current.scrollHeight)},[b?.entries,e]);const _=A=>{i(F=>{const S=new Set(F);return S.has(A)?S.delete(A):S.add(A),S})},N=A=>{const F=A.split(" ");return F.length>=2?F[1]:A},C=v.useMemo(()=>b?.entries??[],[b?.entries]),P=v.useMemo(()=>[...C].reverse(),[C]),T=({level:A})=>{const F=hst[A]||Ci;return r.jsx(F,{className:`w-3.5 h-3.5 ${xF[A]||"text-gray-400"}`})};return r.jsxs("div",{className:"bg-bambu-dark rounded-lg overflow-hidden",children:[r.jsxs("button",{onClick:()=>u(!d),className:"w-full flex items-center justify-between p-4 hover:bg-bambu-dark-tertiary/50 transition-colors",children:[r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx("div",{className:`p-2 rounded-lg ${m?"bg-bambu-green/20 text-bambu-green":"bg-bambu-dark-tertiary text-bambu-gray"}`,children:r.jsx(hy,{className:"w-5 h-5"})}),r.jsxs("div",{className:"text-left",children:[r.jsx("p",{className:"font-medium text-white",children:"Application Logs"}),r.jsx("p",{className:"text-sm text-bambu-gray",children:m?`Live streaming - ${b?.filtered_count??0} entries`:"View and filter application logs"})]})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[m&&r.jsxs("span",{className:"flex items-center gap-1.5 px-2 py-1 bg-bambu-green/20 rounded text-bambu-green text-xs",children:[r.jsx("span",{className:"w-1.5 h-1.5 bg-bambu-green rounded-full animate-pulse"}),"Live"]}),d?r.jsx(tl,{className:"w-5 h-5 text-bambu-gray"}):r.jsx(Rn,{className:"w-5 h-5 text-bambu-gray"})]})]}),d&&r.jsxs("div",{className:"border-t border-bambu-dark-tertiary",children:[r.jsxs("div",{className:"flex flex-col gap-2 p-4 border-b border-bambu-dark-tertiary",children:[r.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[m?r.jsxs("button",{onClick:A=>{A.stopPropagation(),p(!1)},className:"flex items-center gap-1.5 px-3 py-1.5 text-sm bg-red-500/20 text-red-400 hover:bg-red-500/30 rounded transition-colors",children:[r.jsx(so,{className:"w-4 h-4"}),"Stop"]}):r.jsxs("button",{onClick:A=>{A.stopPropagation(),p(!0),g()},className:"flex items-center gap-1.5 px-3 py-1.5 text-sm bg-bambu-green/20 text-bambu-green hover:bg-bambu-green/30 rounded transition-colors",children:[r.jsx(fs,{className:"w-4 h-4"}),"Start"]}),r.jsxs("button",{onClick:()=>x.mutate(),disabled:x.isPending||C.length===0,className:"flex items-center gap-1.5 px-3 py-1.5 text-sm bg-bambu-dark-tertiary text-bambu-gray hover:text-white hover:bg-bambu-dark-secondary rounded transition-colors disabled:opacity-50",children:[r.jsx(Jt,{className:"w-4 h-4"}),"Clear"]}),r.jsx("button",{onClick:()=>g(),disabled:w,className:"flex items-center gap-1.5 px-3 py-1.5 text-sm bg-bambu-dark-tertiary text-bambu-gray hover:text-white hover:bg-bambu-dark-secondary rounded transition-colors disabled:opacity-50",children:r.jsx(sr,{className:`w-4 h-4 ${w?"animate-spin":""}`})}),r.jsx("div",{className:"flex-1"}),r.jsxs("label",{className:"flex items-center gap-2 text-sm text-bambu-gray cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:e,onChange:A=>n(A.target.checked),className:"rounded border-bambu-dark-tertiary bg-bambu-dark-tertiary"}),"Auto-scroll"]}),r.jsxs("span",{className:"text-sm text-bambu-gray",children:[b?.filtered_count??0,"/",b?.total_in_file??0]})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsxs("div",{className:"relative flex-1",children:[r.jsx(Sr,{className:"absolute left-2.5 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),r.jsx("input",{type:"text",placeholder:"Search message or logger name...",value:s,onChange:A=>o(A.target.value),className:"w-full pl-8 pr-8 py-1.5 text-sm bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none"}),s&&r.jsx("button",{onClick:()=>o(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white",children:r.jsx(Bt,{className:"w-4 h-4"})})]}),r.jsxs("div",{className:"flex items-center gap-1 bg-bambu-dark-secondary rounded border border-bambu-dark-tertiary",children:[r.jsx("button",{onClick:()=>c("ALL"),className:`px-2 py-1.5 text-xs rounded-l transition-colors ${l==="ALL"?"bg-bambu-green text-white":"text-bambu-gray hover:text-white"}`,children:"All"}),wQ.map((A,F)=>r.jsx("button",{onClick:()=>c(A),className:`px-2 py-1.5 text-xs transition-colors flex items-center gap-1 ${F===wQ.length-1?"rounded-r":""} ${l===A?`${xF[A]} bg-bambu-dark-tertiary`:"text-bambu-gray hover:text-white"}`,children:A},A))]})]})]}),r.jsx("div",{ref:f,className:"overflow-auto font-mono text-xs bg-black min-h-[300px] max-h-[500px]",children:C.length===0?r.jsxs("div",{className:"flex flex-col items-center justify-center h-[300px] text-bambu-gray",children:[r.jsx("p",{className:"mb-2",children:"No log entries found"}),r.jsx("p",{className:"text-sm",children:"Log file may be empty or cleared"})]}):r.jsx("div",{className:"divide-y divide-bambu-dark-tertiary/30",children:P.map((A,F)=>{const S=a.has(F),M=A.message.includes(`
`);return r.jsx("div",{className:`p-2 cursor-pointer hover:bg-bambu-dark-secondary/50 transition-colors ${S?"bg-bambu-dark-secondary/30":""}`,onClick:()=>M&&_(F),children:r.jsxs("div",{className:"flex items-start gap-2",children:[r.jsx("span",{className:"text-bambu-gray/70 shrink-0 w-20",children:N(A.timestamp)}),r.jsx("span",{className:"shrink-0",children:r.jsx(T,{level:A.level})}),r.jsxs("span",{className:"text-purple-400/80 shrink-0 max-w-[200px] truncate",title:A.logger_name,children:["[",A.logger_name,"]"]}),r.jsx("span",{className:`flex-1 ${xF[A.level]||"text-white/80"} ${!S&&M?"truncate":""}`,children:S?r.jsx("pre",{className:"whitespace-pre-wrap break-all",children:A.message}):A.message.split(`
`)[0]}),M&&r.jsx("span",{className:"text-bambu-gray/50 shrink-0",children:S?r.jsx(tl,{className:"w-3.5 h-3.5"}):r.jsx(Rn,{className:"w-3.5 h-3.5"})})]})},F)})})}),r.jsx("div",{className:"flex items-center justify-between p-3 border-t border-bambu-dark-tertiary text-sm text-bambu-gray",children:m?r.jsxs("span",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"w-2 h-2 bg-green-500 rounded-full animate-pulse"}),"Auto-refreshing every 2 seconds"]}):r.jsx("span",{children:"Click Start to enable live log streaming"})})]})]})}function gst(t){return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:t<1024*1024*1024?`${(t/(1024*1024)).toFixed(1)} MB`:`${(t/(1024*1024*1024)).toFixed(2)} GB`}function Ra({icon:t,label:e,value:n,subValue:a,color:i="text-bambu-green"}){return r.jsxs("div",{className:"flex items-start gap-3 p-4 bg-bambu-dark rounded-lg",children:[r.jsx("div",{className:`p-2 rounded-lg bg-bambu-dark-tertiary ${i}`,children:r.jsx(t,{className:"w-5 h-5"})}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("p",{className:"text-sm text-bambu-gray",children:e}),r.jsx("p",{className:"text-lg font-semibold text-white truncate",children:n}),a&&r.jsx("p",{className:"text-xs text-bambu-gray mt-0.5",children:a})]})]})}function SQ({percent:t,color:e="bg-bambu-green"}){return r.jsx("div",{className:"w-full h-2 bg-bambu-dark rounded-full overflow-hidden",children:r.jsx("div",{className:`h-full ${e} transition-all duration-300`,style:{width:`${Math.min(100,t)}%`}})})}function Qp({title:t,icon:e,children:n}){return r.jsxs(Ct,{className:"p-6",children:[r.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[r.jsx(e,{className:"w-5 h-5 text-bambu-green"}),r.jsx("h2",{className:"text-lg font-semibold text-white",children:t})]}),n]})}function bst(){const{t}=kt(),e=en(),[n,a]=v.useState(null),[i,s]=v.useState(!1),[o,l]=v.useState(!1),{data:c,isLoading:d,refetch:u,isFetching:m}=We({queryKey:["systemInfo"],queryFn:se.getSystemInfo,refetchInterval:3e4}),{data:p}=We({queryKey:["debugLogging"],queryFn:ey.getDebugLoggingState,staleTime:10*1e3,refetchInterval:10*1e3}),{data:f}=We({queryKey:["settings"],queryFn:se.getSettings}),{data:b}=We({queryKey:["library-stats"],queryFn:se.getLibraryStats}),w=f?.time_format||"system",g=async()=>{l(!0);try{const C=await ey.setDebugLogging(!p?.enabled);e.setQueryData(["debugLogging"],C)}catch(C){console.error("Failed to toggle debug logging:",C)}finally{l(!1)}},x=async()=>{a(null),s(!0);try{await ey.downloadSupportBundle()}catch(C){a(C instanceof Error?C.message:"Failed to download support bundle")}finally{s(!1)}};if(d)return r.jsx("div",{className:"flex items-center justify-center h-64",children:r.jsx(ut,{className:"w-8 h-8 text-bambu-green animate-spin"})});if(!c)return r.jsx("div",{className:"p-6 text-center text-bambu-gray",children:t("system.failedToLoad","Failed to load system information")});const _=c.storage.disk_percent_used>90?"bg-red-500":c.storage.disk_percent_used>75?"bg-yellow-500":"bg-bambu-green",N=c.memory.percent_used>90?"bg-red-500":c.memory.percent_used>75?"bg-yellow-500":"bg-bambu-green";return r.jsxs("div",{className:"p-6 space-y-6",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("h1",{className:"text-2xl font-bold text-white",children:t("system.title","System Information")}),r.jsx("p",{className:"text-bambu-gray mt-1",children:t("system.subtitle","Monitor system resources and database statistics")})]}),r.jsxs("button",{onClick:()=>u(),disabled:m,className:"flex items-center gap-2 px-4 py-2 bg-bambu-dark-secondary hover:bg-bambu-dark-tertiary rounded-lg transition-colors disabled:opacity-50",children:[r.jsx(sr,{className:`w-4 h-4 ${m?"animate-spin":""}`}),t("common.refresh","Refresh")]})]}),r.jsx(Qp,{title:t("system.application","Application"),icon:Kf,children:r.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[r.jsx(Ra,{icon:Kf,label:t("system.version","Version"),value:`v${c.app.version}`}),r.jsx(Ra,{icon:Zn,label:t("system.uptime","System Uptime"),value:c.system.uptime_formatted}),r.jsx(Ra,{icon:Kf,label:t("system.hostname","Hostname"),value:c.system.hostname})]})}),r.jsx(Qp,{title:t("support.title","Support & Troubleshooting"),icon:Fbe,children:r.jsxs("div",{className:"space-y-4",children:[r.jsx("p",{className:"text-sm text-bambu-gray",children:t("support.description","Enable debug logging to capture detailed information, then download a support bundle to share when reporting issues.")}),r.jsxs("div",{className:"flex items-center justify-between p-4 bg-bambu-dark rounded-lg",children:[r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx("div",{className:`p-2 rounded-lg ${p?.enabled?"bg-amber-500/20 text-amber-500":"bg-bambu-dark-tertiary text-bambu-gray"}`,children:r.jsx(hy,{className:"w-5 h-5"})}),r.jsxs("div",{children:[r.jsx("p",{className:"font-medium text-white",children:t("support.debugLogging","Debug Logging")}),r.jsxs("p",{className:"text-sm text-bambu-gray",children:[p?.enabled?t("support.debugLoggingEnabled","Capturing detailed logs"):t("support.debugLoggingDisabled","Normal logging level"),p?.enabled&&p.duration_seconds!==null&&r.jsxs("span",{className:"text-amber-400 ml-2",children:["(",Math.floor(p.duration_seconds/60),"m ",p.duration_seconds%60,"s)"]})]})]})]}),r.jsxs("button",{onClick:g,disabled:o,className:`px-4 py-2 rounded-lg font-medium transition-colors flex items-center gap-2 ${p?.enabled?"bg-amber-500/20 text-amber-400 hover:bg-amber-500/30":"bg-bambu-green/20 text-bambu-green hover:bg-bambu-green/30"} disabled:opacity-50`,children:[o&&r.jsx(ut,{className:"w-4 h-4 animate-spin"}),p?.enabled?t("support.disableDebug","Disable"):t("support.enableDebug","Enable")]})]}),r.jsxs("div",{className:"flex items-center justify-between p-4 bg-bambu-dark rounded-lg",children:[r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark-tertiary text-bambu-green",children:r.jsx(Yr,{className:"w-5 h-5"})}),r.jsxs("div",{children:[r.jsx("p",{className:"font-medium text-white",children:t("support.supportBundle","Support Bundle")}),r.jsx("p",{className:"text-sm text-bambu-gray",children:t("support.supportBundleDescription","Download system info and logs as a ZIP file")})]})]}),r.jsxs("button",{onClick:x,disabled:i||!p?.enabled,className:"px-4 py-2 rounded-lg font-medium bg-bambu-green/20 text-bambu-green hover:bg-bambu-green/30 transition-colors flex items-center gap-2 disabled:opacity-50 disabled:cursor-not-allowed",title:p?.enabled?void 0:t("support.enableDebugFirst","Enable debug logging first"),children:[i&&r.jsx(ut,{className:"w-4 h-4 animate-spin"}),t("common.download","Download")]})]}),n&&r.jsx("div",{className:"p-3 bg-red-500/20 border border-red-500/30 rounded-lg text-red-400 text-sm",children:n}),!p?.enabled&&r.jsx("div",{className:"p-4 bg-bambu-dark-tertiary/50 rounded-lg",children:r.jsxs("p",{className:"text-sm text-bambu-gray",children:[r.jsx("span",{className:"text-amber-400 font-medium",children:t("support.instructions","To report an issue:")}),r.jsx("br",{}),"1. ",t("support.step1","Enable debug logging"),r.jsx("br",{}),"2. ",t("support.step2","Reproduce the issue"),r.jsx("br",{}),"3. ",t("support.step3","Download the support bundle"),r.jsx("br",{}),"4. ",t("support.step4","Attach the ZIP file to your issue report")]})}),r.jsxs("div",{className:"p-4 bg-bambu-dark rounded-lg space-y-3",children:[r.jsx("p",{className:"text-sm font-medium text-white",children:t("support.privacyTitle","What's in the support bundle?")}),r.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4 text-sm",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-bambu-green font-medium mb-1",children:t("support.collected","Collected:")}),r.jsxs("ul",{className:"text-bambu-gray space-y-0.5",children:[r.jsxs("li",{children:["• ",t("support.collectItem1","App version and debug mode")]}),r.jsxs("li",{children:["• ",t("support.collectItem2","OS, architecture, Python version")]}),r.jsxs("li",{children:["• ",t("support.collectItem3","Database statistics (counts only)")]}),r.jsxs("li",{children:["• ",t("support.collectItem4","Printer models and nozzle counts")]}),r.jsxs("li",{children:["• ",t("support.collectItem5","Non-sensitive settings (themes, formats)")]}),r.jsxs("li",{children:["• ",t("support.collectItem6","Debug logs (sanitized)")]}),r.jsxs("li",{children:["• ",t("support.collectItem7","Printer connectivity and firmware versions")]}),r.jsxs("li",{children:["• ",t("support.collectItem8","Integration status (Spoolman, MQTT, HA)")]}),r.jsxs("li",{children:["• ",t("support.collectItem9","Network interfaces (subnets only)")]}),r.jsxs("li",{children:["• ",t("support.collectItem10","Python package versions")]}),r.jsxs("li",{children:["• ",t("support.collectItem11","Database health checks")]}),r.jsxs("li",{children:["• ",t("support.collectItem12","Docker environment details")]})]})]}),r.jsxs("div",{children:[r.jsx("p",{className:"text-red-400 font-medium mb-1",children:t("support.notCollected","NOT collected:")}),r.jsxs("ul",{className:"text-bambu-gray space-y-0.5",children:[r.jsxs("li",{children:["• ",t("support.notItem1","Printer names and serial numbers")]}),r.jsxs("li",{children:["• ",t("support.notItem2","Access codes and passwords")]}),r.jsxs("li",{children:["• ",t("support.notItem3","Email addresses")]}),r.jsxs("li",{children:["• ",t("support.notItem4","API keys and tokens")]}),r.jsxs("li",{children:["• ",t("support.notItem5","Webhook URLs")]}),r.jsxs("li",{children:["• ",t("support.notItem6","Your hostname or username")]}),r.jsxs("li",{children:["• ",t("support.notItem7","IP addresses")]})]})]})]}),r.jsx("p",{className:"text-xs text-bambu-gray/70",children:t("support.privacyNote","Email addresses in logs are replaced with [EMAIL], printer names with [PRINTER], serial numbers with [SERIAL], and IP addresses with [IP].")})]}),r.jsx(fst,{})]})}),r.jsxs(Qp,{title:t("system.database","Database"),icon:hc,children:[r.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4 mb-4",children:[r.jsx(Ra,{icon:hc,label:t("system.dbEngine","Database Engine"),value:c.database.engine||"SQLite"}),r.jsx(Ra,{icon:hc,label:t("system.dbVersion","Version"),value:c.database.version||"unknown"})]}),r.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4 mb-4",children:[r.jsx(Ra,{icon:ro,label:t("system.totalArchives","Total Archives"),value:c.database.archives}),r.jsx(Ra,{icon:rd,label:t("system.completed","Completed"),value:c.database.archives_completed,color:"text-green-500"}),r.jsx(Ra,{icon:Da,label:t("system.failed","Failed"),value:c.database.archives_failed,color:"text-red-500"}),r.jsx(Ra,{icon:ut,label:t("system.printing","Printing"),value:c.database.archives_printing,color:"text-yellow-500"})]}),r.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[r.jsx(Ra,{icon:pr,label:t("system.printers","Printers"),value:c.database.printers}),r.jsx(Ra,{icon:jS,label:t("system.filaments","Filaments"),value:c.database.filaments}),r.jsx(Ra,{icon:ao,label:t("system.projects","Projects"),value:c.database.projects}),r.jsx(Ra,{icon:xc,label:t("system.smartPlugs","Smart Plugs"),value:c.database.smart_plugs})]}),r.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4 mt-4",children:[r.jsx(Ra,{icon:Zn,label:t("system.totalPrintTime","Total Print Time"),value:c.database.total_print_time_formatted}),r.jsx(Ra,{icon:ro,label:t("system.totalFilament","Total Filament Used"),value:`${c.database.total_filament_kg} kg`,subValue:`${c.database.total_filament_grams.toLocaleString()} g`})]})]}),r.jsxs(Qp,{title:t("system.connectedPrinters","Connected Printers"),icon:pr,children:[r.jsxs("div",{className:"flex items-center gap-4 mb-4",children:[r.jsx("div",{className:"text-3xl font-bold text-bambu-green",children:c.printers.connected}),r.jsx("div",{className:"text-bambu-gray",children:t("system.ofTotal","of {{total}} printers connected",{total:c.printers.total})})]}),c.printers.connected_list.length>0?r.jsx("div",{className:"space-y-2",children:c.printers.connected_list.map(C=>r.jsxs("div",{className:"flex items-center justify-between p-3 bg-bambu-dark rounded-lg",children:[r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx("div",{className:"w-2 h-2 rounded-full bg-bambu-green"}),r.jsx("span",{className:"font-medium text-white",children:C.name})]}),r.jsxs("div",{className:"flex items-center gap-4 text-sm text-bambu-gray",children:[r.jsx("span",{children:C.model}),r.jsx("span",{className:`px-2 py-0.5 rounded ${C.state==="RUNNING"?"bg-bambu-green/20 text-bambu-green":C.state==="IDLE"?"bg-blue-500/20 text-blue-400":"bg-bambu-dark-tertiary"}`,children:C.state})]})]},C.id))}):r.jsx("p",{className:"text-bambu-gray",children:t("system.noPrintersConnected","No printers connected")})]}),r.jsx(Qp,{title:t("system.storage","Storage"),icon:ob,children:r.jsxs("div",{className:"space-y-4",children:[r.jsxs("div",{children:[r.jsxs("div",{className:"flex justify-between text-sm mb-1",children:[r.jsx("span",{className:"text-bambu-gray",children:t("system.diskUsage","Disk Usage")}),r.jsxs("span",{className:"text-white",children:[c.storage.disk_used_formatted," / ",c.storage.disk_total_formatted]})]}),r.jsx(SQ,{percent:c.storage.disk_percent_used,color:_}),r.jsxs("p",{className:"text-xs text-bambu-gray mt-1",children:[c.storage.disk_free_formatted," ",t("system.free","free")," (",(100-c.storage.disk_percent_used).toFixed(1),"%)"]})]}),r.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[r.jsx(Ra,{icon:ro,label:t("system.archiveStorage","Archive Storage"),value:c.storage.archive_size_formatted}),r.jsx(Ra,{icon:hc,label:t("system.databaseSize","Database Size"),value:c.storage.database_size_formatted}),b&&r.jsx(Ra,{icon:Fl,label:t("system.fileManagerStorage","File Manager"),value:gst(b.total_size_bytes),subValue:`${b.total_files} files, ${b.total_folders} folders`})]})]})}),r.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[r.jsx(Qp,{title:t("system.memory","Memory"),icon:hxe,children:r.jsx("div",{className:"space-y-4",children:r.jsxs("div",{children:[r.jsxs("div",{className:"flex justify-between text-sm mb-1",children:[r.jsx("span",{className:"text-bambu-gray",children:t("system.memoryUsage","Memory Usage")}),r.jsxs("span",{className:"text-white",children:[c.memory.used_formatted," / ",c.memory.total_formatted]})]}),r.jsx(SQ,{percent:c.memory.percent_used,color:N}),r.jsxs("p",{className:"text-xs text-bambu-gray mt-1",children:[c.memory.available_formatted," ",t("system.available","available")]})]})})}),r.jsx(Qp,{title:t("system.cpu","CPU"),icon:M0,children:r.jsx("div",{className:"space-y-4",children:r.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[r.jsx(Ra,{icon:M0,label:t("system.cores","Cores"),value:c.cpu.count,subValue:`${c.cpu.count_logical} logical`}),r.jsx(Ra,{icon:M0,label:t("system.usage","Usage"),value:`${c.cpu.percent}%`})]})})})]}),r.jsx(Qp,{title:t("system.systemDetails","System Details"),icon:Kf,children:r.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[r.jsx(Ra,{icon:Kf,label:t("system.os","Operating System"),value:c.system.platform,subValue:c.system.platform_release}),r.jsx(Ra,{icon:M0,label:t("system.architecture","Architecture"),value:c.system.architecture}),r.jsx(Ra,{icon:Kf,label:t("system.python","Python"),value:c.system.python_version}),r.jsx(Ra,{icon:Zn,label:t("system.bootTime","Boot Time"),value:Lg(c.system.boot_time,w)})]})})]})}const QI="auth_remember_me";function yF(t){return t?"persistent":"session"}function xst(){try{const t=sessionStorage.getItem(QI)==="1";return sessionStorage.removeItem(QI),t}catch(t){return console.warn("consumeSavedRememberMe: sessionStorage unavailable, Remember Me preference lost across OIDC redirect",t),!1}}function yst(){const t=Di(),[e]=ab(),{t:n}=kt(),{login:a,loginWithToken:i}=cr(),{showToast:s}=rn(),{mode:o}=cb(),[l,c]=v.useState(""),[d,u]=v.useState(""),[m,p]=v.useState(!1),[f,b]=v.useState(""),[w,g]=v.useState("credentials"),[x,_]=v.useState(""),[N,C]=v.useState([]),[P,T]=v.useState("totp"),[A,F]=v.useState(""),[S,M]=v.useState(!1),z=v.useRef(null),[I,H]=v.useState(!1),[L,Z]=v.useState(""),[re,J]=v.useState(""),[de,me]=v.useState(""),{data:ue}=We({queryKey:["advancedAuthStatus"],queryFn:()=>se.getAdvancedAuthStatus()}),{data:W}=We({queryKey:["oidcProviders"],queryFn:()=>se.getOIDCProviders()});v.useEffect(()=>{const O=window.location.hash,ie=O.startsWith("#reset_token=")?O.slice(13):null;ie&&(Z(ie),g("reset-password"),t("/login",{replace:!0}))},[]),v.useEffect(()=>{const O=window.location.hash,ie=O.startsWith("#oidc_token=")?O.slice(12):null,U=e.get("oidc_error");if(!ie&&!U)return;const G=xst();if(U){const Q={oidc_provider_error:n("login.oidcErrors.providerError"),missing_parameters:n("login.oidcErrors.missingParameters"),invalid_state:n("login.oidcErrors.invalidState"),state_expired:n("login.oidcErrors.stateExpired"),provider_not_found:n("login.oidcErrors.providerNotFound"),discovery_failed:n("login.oidcErrors.discoveryFailed"),invalid_discovery_document:n("login.oidcErrors.invalidDiscovery"),token_exchange_network_error:n("login.oidcErrors.networkError"),token_exchange_bad_response:n("login.oidcErrors.badResponse"),no_id_token:n("login.oidcErrors.noIdToken"),token_validation_failed:n("login.oidcErrors.validationFailed"),nonce_mismatch:n("login.oidcErrors.nonceMismatch"),missing_sub_claim:n("login.oidcErrors.missingSubClaim"),no_linked_account:n("login.oidcErrors.noLinkedAccount"),account_inactive:n("login.oidcErrors.accountInactive"),user_resolution_failed:n("login.oidcErrors.userResolutionFailed"),internal_error:n("login.oidcErrors.internalError")}[U]??(U.startsWith("token_exchange_")?n("login.oidcErrors.tokenExchangeFailed"):n("login.oidcLoginFailed"));s(Q,"error"),t("/login",{replace:!0});return}ie&&se.exchangeOIDCToken(ie).then(Y=>{if(Y.requires_2fa&&Y.pre_auth_token){H(G),_(Y.pre_auth_token);const Q=Y.two_fa_methods??[];C(Q),Q.includes("totp")?T("totp"):Q.includes("email")?T("email"):T("backup"),g("2fa"),t("/login",{replace:!0})}else Y.access_token&&Y.user?(i(Y.access_token,Y.user,yF(G)),s(n("login.loginSuccess")),t("/",{replace:!0})):(s(n("login.oidcLoginFailed"),"error"),t("/login",{replace:!0}))}).catch(Y=>{console.error("OIDC token exchange failed",Y),s(n("login.oidcLoginFailed"),"error"),t("/login",{replace:!0})})},[e]);const ae=it({mutationFn:()=>a(l,d,yF(I)),onSuccess:O=>{if(O.requires_2fa&&O.pre_auth_token){_(O.pre_auth_token);const ie=O.two_fa_methods??[];C(ie),ie.includes("totp")?T("totp"):ie.includes("email")?T("email"):T("backup"),g("2fa")}else O.access_token&&O.user&&(s(n("login.loginSuccess")),t("/"))},onError:O=>{s(O.message||n("login.loginFailed"),"error")}}),pe=it({mutationFn:O=>se.forgotPassword({email:O}),onSuccess:O=>{s(O.message,"success"),p(!1),b("")},onError:O=>{s(O.message,"error")}}),ye=it({mutationFn:()=>se.forgotPasswordConfirm(L,re),onSuccess:O=>{s(O.message,"success"),g("credentials"),Z(""),J(""),me("")},onError:O=>{s(O.message||n("login.resetPassword.resetFailed"),"error")}}),Te=it({mutationFn:()=>se.sendEmailOTP(x),onSuccess:O=>{M(!0),O.pre_auth_token&&_(O.pre_auth_token),s(O.message,"success")},onError:O=>{s(O.message||n("login.twoFA.sendCodeFailed"),"error")}}),$=it({mutationFn:()=>se.verify2FA({pre_auth_token:x,code:A,method:P}),onSuccess:O=>{O.access_token&&O.user?(i(O.access_token,O.user,yF(I)),s(n("login.loginSuccess")),t("/")):(console.error("2FA verify: unexpected response shape",O),s(n("login.loginFailed"),"error"))},onError:O=>{s(O.message||n("login.twoFA.invalidCode"),"error"),F("")}}),K=it({mutationFn:O=>se.getOIDCAuthorizeUrl(O),onSuccess:O=>{if(I)try{sessionStorage.setItem(QI,"1")}catch(ie){console.warn("setItem auth_remember_me failed, Remember Me will not carry through OIDC redirect",ie)}window.location.href=O.auth_url},onError:O=>{s(O.message||n("login.oidcLoginFailed"),"error")}}),D=O=>{if(O.preventDefault(),!l||!d){s(n("login.enterCredentials"),"error");return}ae.mutate()},j=O=>{if(O.preventDefault(),!A.trim()){s(n("login.twoFA.enterCode"),"error");return}$.mutate()},B=O=>{if(O.preventDefault(),!f){s(n("login.enterEmail"),"error");return}pe.mutate(f)},X=O=>{T(O),F(""),M(!1),setTimeout(()=>z.current?.focus(),0)};if(w==="reset-password"){const O=ie=>{if(ie.preventDefault(),re!==de){s(n("login.resetPassword.passwordsDoNotMatch"),"error");return}if(re.length<8){s(n("login.resetPassword.passwordTooShort"),"error");return}ye.mutate()};return r.jsx("div",{className:"min-h-screen flex items-center justify-center bg-bambu-dark p-4",children:r.jsxs("div",{className:"max-w-md w-full space-y-8 p-8 bg-gradient-to-br from-bambu-card to-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary shadow-lg",children:[r.jsxs("div",{className:"text-center",children:[r.jsx("div",{className:"flex items-center justify-center mb-4",children:r.jsx("div",{className:"w-14 h-14 rounded-full bg-bambu-green/20 flex items-center justify-center",children:r.jsx(vo,{className:"w-7 h-7 text-bambu-green"})})}),r.jsx("h2",{className:"text-2xl font-bold text-white",children:n("login.resetPassword.title")}),r.jsx("p",{className:"mt-2 text-sm text-bambu-gray",children:n("login.resetPassword.subtitle")})]}),r.jsxs("form",{onSubmit:O,className:"space-y-4",children:[r.jsxs("div",{children:[r.jsx("label",{htmlFor:"new-password",className:"block text-sm font-medium text-white mb-2",children:n("login.resetPassword.newPassword")}),r.jsx("input",{id:"new-password",type:"password",required:!0,value:re,onChange:ie=>J(ie.target.value),className:"block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors",placeholder:n("login.resetPassword.newPasswordPlaceholder"),autoFocus:!0,autoComplete:"new-password",minLength:8})]}),r.jsxs("div",{children:[r.jsx("label",{htmlFor:"confirm-password",className:"block text-sm font-medium text-white mb-2",children:n("login.resetPassword.confirmPassword")}),r.jsx("input",{id:"confirm-password",type:"password",required:!0,value:de,onChange:ie=>me(ie.target.value),className:"block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors",placeholder:n("login.resetPassword.confirmPasswordPlaceholder"),autoComplete:"new-password"})]}),r.jsx("button",{type:"submit",disabled:ye.isPending||!re||!de,className:"w-full flex justify-center py-3 px-4 bg-bambu-green hover:bg-bambu-green-light text-white font-medium rounded-lg shadow-lg shadow-bambu-green/20 hover:shadow-bambu-green/30 focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:ring-offset-2 focus:ring-offset-bambu-dark-secondary transition-all disabled:opacity-50 disabled:cursor-not-allowed",children:ye.isPending?n("login.resetPassword.saving"):n("login.resetPassword.submit")})]}),r.jsx("div",{className:"text-center",children:r.jsx("button",{type:"button",onClick:()=>{g("credentials"),Z(""),J(""),me("")},className:"text-sm text-bambu-gray hover:text-bambu-green transition-colors",children:n("login.resetPassword.backToLogin")})})]})})}return w==="2fa"?r.jsx("div",{className:"min-h-screen flex items-center justify-center bg-bambu-dark p-4",children:r.jsxs("div",{className:"max-w-md w-full space-y-8 p-8 bg-gradient-to-br from-bambu-card to-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary shadow-lg",children:[r.jsxs("div",{className:"text-center",children:[r.jsx("div",{className:"flex items-center justify-center mb-4",children:r.jsx("div",{className:"w-14 h-14 rounded-full bg-bambu-green/20 flex items-center justify-center",children:r.jsx(Sl,{className:"w-7 h-7 text-bambu-green"})})}),r.jsx("h2",{className:"text-2xl font-bold text-white",children:n("login.twoFA.title")}),r.jsx("p",{className:"mt-2 text-sm text-bambu-gray",children:n("login.twoFA.subtitle")})]}),N.length>1&&r.jsxs("div",{className:"flex gap-2",children:[N.includes("totp")&&r.jsxs("button",{type:"button",onClick:()=>X("totp"),className:`flex-1 flex flex-col items-center gap-1 py-2 px-3 rounded-lg border text-xs font-medium transition-colors ${P==="totp"?"border-bambu-green bg-bambu-green/10 text-bambu-green":"border-bambu-dark-tertiary text-bambu-gray hover:border-bambu-green/50"}`,children:[r.jsx(VF,{className:"w-4 h-4"}),n("login.twoFA.methodAuthenticator")]}),N.includes("email")&&r.jsxs("button",{type:"button",onClick:()=>X("email"),className:`flex-1 flex flex-col items-center gap-1 py-2 px-3 rounded-lg border text-xs font-medium transition-colors ${P==="email"?"border-bambu-green bg-bambu-green/10 text-bambu-green":"border-bambu-dark-tertiary text-bambu-gray hover:border-bambu-green/50"}`,children:[r.jsx(qm,{className:"w-4 h-4"}),n("login.twoFA.methodEmail")]}),N.includes("backup")&&r.jsxs("button",{type:"button",onClick:()=>X("backup"),className:`flex-1 flex flex-col items-center gap-1 py-2 px-3 rounded-lg border text-xs font-medium transition-colors ${P==="backup"?"border-bambu-green bg-bambu-green/10 text-bambu-green":"border-bambu-dark-tertiary text-bambu-gray hover:border-bambu-green/50"}`,children:[r.jsx(vo,{className:"w-4 h-4"}),n("login.twoFA.methodBackup")]})]}),r.jsxs("form",{onSubmit:j,className:"space-y-4",children:[P==="totp"&&r.jsx("p",{className:"text-sm text-bambu-gray",children:n("login.twoFA.instructionsTotp")}),P==="email"&&r.jsxs("div",{className:"space-y-3",children:[r.jsx("p",{className:"text-sm text-bambu-gray",children:n(S?"login.twoFA.instructionsEmail":"login.twoFA.instructionsEmailNotSent")}),!S&&r.jsx(Me,{type:"button",variant:"secondary",className:"w-full",onClick:()=>Te.mutate(),disabled:Te.isPending,children:Te.isPending?n("login.twoFA.sendingCode"):n("login.twoFA.sendCodeButton")}),S&&r.jsx("button",{type:"button",onClick:()=>{M(!1),Te.mutate()},className:"text-xs text-bambu-gray hover:text-bambu-green transition-colors",children:n("login.twoFA.resendCode")})]}),P==="backup"&&r.jsx("p",{className:"text-sm text-bambu-gray",children:n("login.twoFA.instructionsBackup")}),r.jsxs("div",{children:[r.jsx("label",{htmlFor:"twofa-code",className:"block text-sm font-medium text-white mb-2",children:n(P==="backup"?"login.twoFA.backupCodeLabel":"login.twoFA.codeLabel")}),r.jsx("input",{ref:z,id:"twofa-code",type:"text",inputMode:P==="backup"?"text":"numeric",autoComplete:"one-time-code",value:A,onChange:O=>F(O.target.value.trim()),disabled:P==="email"&&!S,className:"block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray text-center tracking-widest text-xl font-mono focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors disabled:opacity-40",placeholder:n(P==="backup"?"login.twoFA.backupCodePlaceholder":"login.twoFA.codePlaceholder"),maxLength:P==="backup"?8:6,autoFocus:!0})]}),r.jsx("button",{type:"submit",disabled:$.isPending||!A.trim()||P==="email"&&!S,className:"w-full flex justify-center py-3 px-4 bg-bambu-green hover:bg-bambu-green-light text-white font-medium rounded-lg shadow-lg shadow-bambu-green/20 hover:shadow-bambu-green/30 focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:ring-offset-2 focus:ring-offset-bambu-dark-secondary transition-all disabled:opacity-50 disabled:cursor-not-allowed",children:$.isPending?n("login.twoFA.verifyingButton"):n("login.twoFA.verifyButton")})]}),r.jsx("div",{className:"text-center",children:r.jsx("button",{type:"button",onClick:()=>{g("credentials"),_(""),F(""),M(!1)},className:"text-sm text-bambu-gray hover:text-bambu-green transition-colors",children:n("login.twoFA.backToLogin")})})]})}):r.jsxs("div",{className:"min-h-screen flex items-center justify-center bg-bambu-dark p-4",children:[r.jsxs("div",{className:"max-w-md w-full space-y-8 p-8 bg-gradient-to-br from-bambu-card to-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary shadow-lg",children:[r.jsxs("div",{className:"text-center",children:[r.jsx("div",{className:"flex items-center justify-center mb-6",children:r.jsx("img",{src:o==="dark"?"/img/bambuddy_logo_dark_transparent.png":"/img/bambuddy_logo_light.png",alt:"Bambuddy",className:"h-16"})}),r.jsx("h2",{className:"text-3xl font-bold text-white",children:n("login.title")}),r.jsx("p",{className:"mt-2 text-sm text-bambu-gray",children:n("login.subtitle")})]}),r.jsxs("form",{className:"mt-8 space-y-6",onSubmit:D,children:[r.jsxs("div",{className:"space-y-4",children:[r.jsxs("div",{children:[r.jsx("label",{htmlFor:"username",className:"block text-sm font-medium text-white mb-2",children:ue?.advanced_auth_enabled?n("login.usernameOrEmail"):n("login.username")}),r.jsx("input",{id:"username",type:"text",required:!0,value:l,onChange:O=>c(O.target.value),className:"block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors",placeholder:ue?.advanced_auth_enabled?n("login.usernameOrEmailPlaceholder"):n("login.usernamePlaceholder"),autoComplete:"username"})]}),r.jsxs("div",{children:[r.jsx("label",{htmlFor:"password",className:"block text-sm font-medium text-white mb-2",children:n("login.password")||"Password"}),r.jsx("input",{id:"password",type:"password",required:!0,value:d,onChange:O=>u(O.target.value),className:"block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors",placeholder:n("login.passwordPlaceholder"),autoComplete:"current-password"})]})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("input",{id:"remember-me",type:"checkbox",checked:I,onChange:O=>H(O.target.checked),className:"h-4 w-4 rounded border-bambu-dark-tertiary bg-bambu-dark-secondary text-bambu-green focus:ring-bambu-green/50 cursor-pointer"}),r.jsx("label",{htmlFor:"remember-me",className:"text-sm text-bambu-gray cursor-pointer",children:n("login.rememberMe")})]}),r.jsx("div",{children:r.jsx("button",{type:"submit",disabled:ae.isPending,className:"w-full flex justify-center py-3 px-4 bg-bambu-green hover:bg-bambu-green-light text-white font-medium rounded-lg shadow-lg shadow-bambu-green/20 hover:shadow-bambu-green/30 focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:ring-offset-2 focus:ring-offset-bambu-dark-secondary transition-all disabled:opacity-50 disabled:cursor-not-allowed disabled:hover:bg-bambu-green",children:ae.isPending?n("login.signingIn"):n("login.signIn")})}),r.jsx("div",{className:"text-center",children:r.jsx("button",{type:"button",onClick:()=>p(!0),className:"text-sm text-bambu-gray hover:text-bambu-green transition-colors",children:n("login.forgotPassword")})})]}),W&&W.length>0&&r.jsxs("div",{className:"space-y-3",children:[r.jsxs("div",{className:"relative",children:[r.jsx("div",{className:"absolute inset-0 flex items-center",children:r.jsx("div",{className:"w-full border-t border-bambu-dark-tertiary"})}),r.jsx("div",{className:"relative flex justify-center text-sm",children:r.jsx("span",{className:"px-2 bg-bambu-dark-secondary text-bambu-gray",children:n("login.twoFA.orContinueWith")})})]}),r.jsx("div",{className:"space-y-2",children:W.map(O=>r.jsxs("button",{type:"button",onClick:()=>K.mutate(O.id),disabled:K.isPending,className:"w-full flex items-center justify-center gap-3 py-3 px-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary hover:border-bambu-green/50 rounded-lg text-white font-medium transition-colors disabled:opacity-50",children:[O.icon_url?r.jsx("img",{src:O.icon_url,alt:"",className:"w-5 h-5 object-contain"}):r.jsx(Sl,{className:"w-5 h-5 text-bambu-green"}),n("login.twoFA.signInWith",{provider:O.name})]},O.id))})]})]}),m&&r.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",onClick:()=>p(!1),children:r.jsxs(Ct,{className:"w-full max-w-md",onClick:O=>O.stopPropagation(),children:[r.jsx(pn,{children:r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(qm,{className:"w-5 h-5 text-bambu-green"}),r.jsx("h2",{className:"text-lg font-semibold text-white",children:n("login.forgotPasswordTitle")})]}),r.jsx(Me,{variant:"ghost",size:"sm",onClick:()=>{p(!1),b("")},children:r.jsx(Bt,{className:"w-5 h-5"})})]})}),r.jsx(At,{children:ue?.advanced_auth_enabled?r.jsxs("form",{onSubmit:B,className:"space-y-4",children:[r.jsx("p",{className:"text-bambu-gray text-sm",children:n("login.forgotPasswordEmailMessage")}),r.jsxs("div",{children:[r.jsx("label",{htmlFor:"forgot-email",className:"block text-sm font-medium text-white mb-2",children:n("login.emailAddress")}),r.jsx("input",{id:"forgot-email",type:"email",required:!0,value:f,onChange:O=>b(O.target.value),className:"block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors",placeholder:n("login.emailPlaceholder")})]}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx(Me,{type:"button",variant:"secondary",className:"flex-1",onClick:()=>{p(!1),b("")},children:n("login.cancel")}),r.jsx(Me,{type:"submit",className:"flex-1",disabled:pe.isPending,children:pe.isPending?n("login.sending"):n("login.sendResetEmail")})]})]}):r.jsxs("div",{className:"space-y-4",children:[r.jsx("p",{className:"text-bambu-gray",children:n("login.forgotPasswordMessage")}),r.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4 space-y-2",children:[r.jsx("p",{className:"text-sm text-white font-medium",children:n("login.howToReset")}),r.jsxs("ol",{className:"text-sm text-bambu-gray space-y-1 list-decimal list-inside",children:[r.jsx("li",{children:n("login.resetStep1")}),r.jsx("li",{children:n("login.resetStep2")}),r.jsx("li",{children:n("login.resetStep3")}),r.jsx("li",{children:n("login.resetStep4")})]})]}),r.jsx(Me,{variant:"secondary",className:"w-full",onClick:()=>p(!1),children:n("login.gotIt")})]})})]})})]})}function vst(){const t=Di(),{t:e}=kt(),{showToast:n}=rn(),{mode:a}=cb(),{refreshAuth:i}=cr(),[s,o]=v.useState(!1),[l,c]=v.useState(""),[d,u]=v.useState(""),[m,p]=v.useState(""),f=it({mutationFn:()=>se.setupAuth({auth_enabled:s,admin_username:s?l:void 0,admin_password:s?d:void 0}),onSuccess:async w=>{await i(),w.auth_enabled?w.admin_created?(n(e("setup.toast.authEnabledAdminCreated")),t("/login")):(n(e("setup.toast.authEnabledExistingAdmins")),t("/login")):(n(e("setup.toast.setupCompleted")),t("/"))},onError:w=>{n(w.message,"error")}}),b=w=>{if(w.preventDefault(),s&&(l||d)){if(!l||!d){n(e("setup.toast.enterBothCredentials"),"error");return}if(d!==m){n(e("setup.toast.passwordsDoNotMatch"),"error");return}if(d.length<6){n(e("setup.toast.passwordTooShort"),"error");return}}f.mutate()};return r.jsx("div",{className:"min-h-screen flex items-center justify-center bg-bambu-dark p-4",children:r.jsxs("div",{className:"max-w-md w-full space-y-8 p-8 bg-gradient-to-br from-bambu-card to-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary shadow-lg",children:[r.jsxs("div",{className:"text-center",children:[r.jsx("div",{className:"flex items-center justify-center mb-6",children:r.jsx("img",{src:a==="dark"?"/img/bambuddy_logo_dark_transparent.png":"/img/bambuddy_logo_light.png",alt:"Bambuddy",className:"h-16"})}),r.jsx("h2",{className:"text-3xl font-bold text-white",children:e("setup.title")}),r.jsx("p",{className:"mt-2 text-sm text-bambu-gray",children:e("setup.subtitle")})]}),r.jsxs("form",{className:"mt-8 space-y-6",onSubmit:b,children:[r.jsxs("div",{className:"space-y-4",children:[r.jsxs("div",{className:"flex items-center p-4 bg-bambu-dark-secondary/50 rounded-lg border border-bambu-dark-tertiary",children:[r.jsx("input",{id:"auth-enabled",type:"checkbox",checked:s,onChange:w=>o(w.target.checked),className:"h-4 w-4 text-bambu-green focus:ring-bambu-green border-bambu-dark-tertiary rounded bg-bambu-dark-secondary"}),r.jsx("label",{htmlFor:"auth-enabled",className:"ml-3 block text-sm font-medium text-white",children:e("setup.enableAuth")})]}),s&&r.jsxs("div",{className:"space-y-4 mt-4",children:[r.jsx("div",{className:"p-3 bg-bambu-dark-secondary/50 border border-bambu-dark-tertiary rounded-lg",children:r.jsxs("div",{className:"flex items-start gap-2",children:[r.jsx(Ci,{className:"w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0"}),r.jsxs("div",{className:"text-sm text-bambu-gray",children:[r.jsx("p",{className:"text-white font-medium mb-1",children:e("setup.adminAccount")}),r.jsx("p",{children:e("setup.adminAccountDesc")})]})]})}),r.jsxs("div",{children:[r.jsxs("label",{htmlFor:"admin-username",className:"block text-sm font-medium text-white mb-2",children:[e("setup.adminUsername")," ",r.jsx("span",{className:"text-bambu-gray text-xs",children:e("setup.optionalIfAdminExists")})]}),r.jsx("input",{id:"admin-username",type:"text",value:l,onChange:w=>c(w.target.value),className:"block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors",placeholder:e("setup.adminUsernamePlaceholder"),autoComplete:"username"})]}),r.jsxs("div",{children:[r.jsxs("label",{htmlFor:"admin-password",className:"block text-sm font-medium text-white mb-2",children:[e("setup.adminPassword")," ",r.jsx("span",{className:"text-bambu-gray text-xs",children:e("setup.optionalIfAdminExists")})]}),r.jsx("input",{id:"admin-password",type:"password",value:d,onChange:w=>u(w.target.value),className:"block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors",placeholder:e("setup.adminPasswordPlaceholder"),minLength:6,autoComplete:"new-password"})]}),d&&r.jsxs("div",{children:[r.jsx("label",{htmlFor:"confirm-password",className:"block text-sm font-medium text-white mb-2",children:e("setup.confirmPassword")}),r.jsx("input",{id:"confirm-password",type:"password",value:m,onChange:w=>p(w.target.value),className:"block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors",placeholder:e("setup.confirmPasswordPlaceholder"),minLength:6,autoComplete:"new-password"})]})]})]}),r.jsx("div",{children:r.jsx("button",{type:"submit",disabled:f.isPending,className:"w-full flex justify-center py-3 px-4 bg-bambu-green hover:bg-bambu-green-light text-white font-medium rounded-lg shadow-lg shadow-bambu-green/20 hover:shadow-bambu-green/30 focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:ring-offset-2 focus:ring-offset-bambu-dark-secondary transition-all disabled:opacity-50 disabled:cursor-not-allowed disabled:hover:bg-bambu-green",children:f.isPending?e("setup.settingUp"):e("setup.completeSetup")})})]})]})})}function wst(){const{t}=kt(),{user:e}=cr(),{showToast:n}=rn(),a=en(),i=Di(),[s,o]=v.useState(!0),[l,c]=v.useState(!0),[d,u]=v.useState(!0),[m,p]=v.useState(!0),[f,b]=v.useState(!1),{data:w,isLoading:g}=We({queryKey:["advancedAuthStatus"],queryFn:se.getAdvancedAuthStatus,staleTime:300*1e3}),{data:x,isLoading:_}=We({queryKey:["settings"],queryFn:se.getSettings,staleTime:300*1e3}),{data:N,isLoading:C}=We({queryKey:["user-email-preferences"],queryFn:()=>se.getUserEmailPreferences()});v.useEffect(()=>{(w&&!w.advanced_auth_enabled||x&&!x.user_notifications_enabled)&&i("/settings",{replace:!0})},[w,x,i]),v.useEffect(()=>{N&&(o(N.notify_print_start),c(N.notify_print_complete),u(N.notify_print_failed),p(N.notify_print_stopped),b(!1))},[N]);const P=it({mutationFn:()=>se.updateUserEmailPreferences({notify_print_start:s,notify_print_complete:l,notify_print_failed:d,notify_print_stopped:m}),onSuccess:()=>{a.invalidateQueries({queryKey:["user-email-preferences"]}),b(!1),n(t("notifications.userEmail.saveSuccess"),"success")},onError:A=>{n(A.message||t("notifications.userEmail.saveError"),"error")}}),T=(A,F)=>{A(!F),b(!0)};return C||g||_?r.jsx("div",{className:"flex items-center justify-center h-64",children:r.jsx(ut,{className:"w-8 h-8 animate-spin text-bambu-green"})}):r.jsxs("div",{className:"p-4 md:p-6 max-w-2xl mx-auto",children:[r.jsxs("div",{className:"flex items-center gap-3 mb-6",children:[r.jsx(kh,{className:"w-7 h-7 text-bambu-green"}),r.jsx("h1",{className:"text-2xl font-bold text-white",children:t("notifications.userEmail.title")})]}),r.jsx(Ct,{className:"mb-6 border-blue-500/30 bg-blue-500/5",children:r.jsx(At,{className:"py-4",children:r.jsxs("div",{className:"flex items-start gap-3",children:[r.jsx("div",{className:"w-10 h-10 rounded-full flex items-center justify-center bg-blue-500/20 flex-shrink-0",children:r.jsx(qm,{className:"w-5 h-5 text-blue-400"})}),r.jsxs("div",{children:[r.jsx("h3",{className:"text-white font-medium",children:t("notifications.userEmail.emailNotifications")}),r.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:t("notifications.userEmail.emailNotificationsDesc")}),e?.email?r.jsxs("p",{className:"text-sm text-blue-400 mt-2",children:[t("notifications.userEmail.sendingTo"),": ",r.jsx("strong",{children:e.email})]}):r.jsx("p",{className:"text-sm text-yellow-400 mt-2",children:t("notifications.userEmail.noEmailWarning")})]})]})})}),r.jsxs(Ct,{className:"mb-6",children:[r.jsxs(pn,{children:[r.jsx("h2",{className:"text-lg font-semibold text-white",children:t("notifications.userEmail.printJobNotifications")}),r.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:t("notifications.userEmail.printJobNotificationsDesc")})]}),r.jsxs(At,{className:"space-y-4",children:[r.jsxs("div",{className:"flex items-center justify-between p-4 bg-bambu-dark rounded-lg",children:[r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx("div",{className:`w-10 h-10 rounded-full flex items-center justify-center ${s?"bg-bambu-green/20":"bg-bambu-dark-tertiary"}`,children:r.jsx(rd,{className:`w-5 h-5 ${s?"text-bambu-green":"text-bambu-gray"}`})}),r.jsxs("div",{children:[r.jsx("p",{className:"text-white font-medium",children:t("notifications.userEmail.printJobStarts")}),r.jsx("p",{className:"text-sm text-bambu-gray",children:t("notifications.userEmail.printJobStartsDesc")})]})]}),r.jsx("button",{onClick:()=>T(o,s),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors focus:outline-none focus:ring-2 focus:ring-bambu-green focus:ring-offset-2 focus:ring-offset-bambu-dark ${s?"bg-bambu-green":"bg-bambu-dark-tertiary"}`,role:"switch","aria-checked":s,children:r.jsx("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${s?"translate-x-6":"translate-x-1"}`})})]}),r.jsxs("div",{className:"flex items-center justify-between p-4 bg-bambu-dark rounded-lg",children:[r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx("div",{className:`w-10 h-10 rounded-full flex items-center justify-center ${l?"bg-bambu-green/20":"bg-bambu-dark-tertiary"}`,children:r.jsx(rd,{className:`w-5 h-5 ${l?"text-bambu-green":"text-bambu-gray"}`})}),r.jsxs("div",{children:[r.jsx("p",{className:"text-white font-medium",children:t("notifications.userEmail.printJobFinishes")}),r.jsx("p",{className:"text-sm text-bambu-gray",children:t("notifications.userEmail.printJobFinishesDesc")})]})]}),r.jsx("button",{onClick:()=>T(c,l),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors focus:outline-none focus:ring-2 focus:ring-bambu-green focus:ring-offset-2 focus:ring-offset-bambu-dark ${l?"bg-bambu-green":"bg-bambu-dark-tertiary"}`,role:"switch","aria-checked":l,children:r.jsx("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${l?"translate-x-6":"translate-x-1"}`})})]}),r.jsxs("div",{className:"flex items-center justify-between p-4 bg-bambu-dark rounded-lg",children:[r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx("div",{className:`w-10 h-10 rounded-full flex items-center justify-center ${d?"bg-bambu-green/20":"bg-bambu-dark-tertiary"}`,children:r.jsx(rd,{className:`w-5 h-5 ${d?"text-bambu-green":"text-bambu-gray"}`})}),r.jsxs("div",{children:[r.jsx("p",{className:"text-white font-medium",children:t("notifications.userEmail.printErrors")}),r.jsx("p",{className:"text-sm text-bambu-gray",children:t("notifications.userEmail.printErrorsDesc")})]})]}),r.jsx("button",{onClick:()=>T(u,d),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors focus:outline-none focus:ring-2 focus:ring-bambu-green focus:ring-offset-2 focus:ring-offset-bambu-dark ${d?"bg-bambu-green":"bg-bambu-dark-tertiary"}`,role:"switch","aria-checked":d,children:r.jsx("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${d?"translate-x-6":"translate-x-1"}`})})]}),r.jsxs("div",{className:"flex items-center justify-between p-4 bg-bambu-dark rounded-lg",children:[r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx("div",{className:`w-10 h-10 rounded-full flex items-center justify-center ${m?"bg-bambu-green/20":"bg-bambu-dark-tertiary"}`,children:r.jsx(rd,{className:`w-5 h-5 ${m?"text-bambu-green":"text-bambu-gray"}`})}),r.jsxs("div",{children:[r.jsx("p",{className:"text-white font-medium",children:t("notifications.userEmail.printJobStops")}),r.jsx("p",{className:"text-sm text-bambu-gray",children:t("notifications.userEmail.printJobStopsDesc")})]})]}),r.jsx("button",{onClick:()=>T(p,m),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors focus:outline-none focus:ring-2 focus:ring-bambu-green focus:ring-offset-2 focus:ring-offset-bambu-dark ${m?"bg-bambu-green":"bg-bambu-dark-tertiary"}`,role:"switch","aria-checked":m,children:r.jsx("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${m?"translate-x-6":"translate-x-1"}`})})]})]})]}),r.jsx("div",{className:"flex justify-end",children:r.jsx(Me,{onClick:()=>P.mutate(),disabled:!f||P.isPending||!e?.email,children:P.isPending?r.jsxs(r.Fragment,{children:[r.jsx(ut,{className:"w-4 h-4 animate-spin"}),t("common.saving")]}):r.jsxs(r.Fragment,{children:[r.jsx(us,{className:"w-4 h-4"}),t("common.save")]})})})]})}function Sst(){const t=Di(),[e]=ab(),{t:n}=kt();if(window!==window.top)return r.jsxs("div",{style:{padding:32,color:"#f88"},children:["GCode viewer static files not found. Check that the"," ",r.jsx("code",{children:"gcode_viewer/"})," directory exists and restart uvicorn."]});const a=e.has("archive"),i=e.has("library_file"),s=a?"/archives":i?"/files":"/",o=n(a?"gcodeViewer.backToArchives":i?"gcodeViewer.backToFiles":"gcodeViewer.back"),l=()=>{window.history.length>1?t(-1):t(s)},c=`/gcode-viewer/${window.location.search}`;return r.jsxs("div",{style:{height:"calc(100vh - 3.5rem)",display:"flex",flexDirection:"column"},children:[r.jsx("div",{className:"flex items-center gap-2 px-4 py-2 border-b border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-900",children:r.jsxs("button",{type:"button",onClick:l,className:"inline-flex items-center gap-1.5 text-sm text-gray-700 dark:text-gray-300 hover:text-gray-900 dark:hover:text-white transition-colors",children:[r.jsx(yT,{className:"w-4 h-4"}),o]})}),r.jsx("iframe",{src:c,title:"GCode Viewer",style:{display:"block",width:"100%",flex:1,border:"none"}})]})}function _st(){const t=v.useRef(null),e=v.useRef(null),n=en(),[a,i]=v.useState(!1),s=v.useRef(new Map),{showToast:o}=rn(),{t:l}=kt(),c=v.useRef(new Set),d=v.useRef(null),u=v.useRef(new Map),m=v.useRef(null),p=v.useRef([]),f=v.useRef(!1),b=v.useRef(()=>{}),w=v.useCallback(()=>{if(f.current||p.current.length===0)return;f.current=!0;const P=()=>{const T=p.current.shift();T?requestAnimationFrame(()=>{b.current(T),p.current.length>0?setTimeout(P,16):f.current=!1}):f.current=!1};P()},[]),g=v.useCallback(()=>{if(t.current?.readyState===WebSocket.OPEN)return;const T=`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/api/v1/ws`,A=new WebSocket(T);let F=null;A.onopen=()=>{console.log("[WebSocket] Connected"),i(!0),F=window.setInterval(()=>{A.readyState===WebSocket.OPEN&&A.send(JSON.stringify({type:"ping"}))},3e4)},A.onmessage=S=>{try{const M=JSON.parse(S.data);M.type==="printer_status"&&M.printer_id!==void 0&&M.data?b.current(M):(p.current.push(M),w())}catch{}},A.onclose=S=>{console.log("[WebSocket] Closed",S.code,S.reason),F&&(clearInterval(F),F=null),i(!1),t.current=null,e.current=window.setTimeout(()=>{g()},3e3)},A.onerror=S=>{console.error("[WebSocket] Error",S),A.close()},t.current=A},[w]),x=v.useCallback((P,T)=>{const A=u.current.get(P)||{};u.current.set(P,{...A,...T}),m.current||(m.current=window.setTimeout(()=>{const F=new Map(u.current);u.current.clear(),m.current=null,requestAnimationFrame(()=>{F.forEach((S,M)=>{n.setQueryData(["printerStatus",M],z=>{const I={...z,...S};return I.wifi_signal==null&&z?.wifi_signal!=null&&(I.wifi_signal=z.wifi_signal),I})})})},100))},[n]),_=v.useCallback(P=>{c.current.add(P),d.current&&clearTimeout(d.current),d.current=window.setTimeout(()=>{const T=Array.from(c.current);c.current.clear(),d.current=null;let A=0;T.forEach(F=>{setTimeout(()=>{requestAnimationFrame(()=>{n.invalidateQueries({queryKey:[F]})})},A),A+=500})},3e3)},[n]),N=v.useCallback(P=>{switch(P.type){case"printer_status":P.printer_id!==void 0&&P.data&&x(P.printer_id,P.data);break;case"print_start":P.printer_id!==void 0&&n.invalidateQueries({queryKey:["printerStatus",P.printer_id]});break;case"missing_spool_assignment":{if(P.printer_id===void 0||!Array.isArray(P.missing_slots))break;const T=P.missing_slots.map(M=>M&&typeof M.slot=="string"?M.slot:"Unknown").filter(M=>M.length>0);if(T.length===0){s.current.delete(P.printer_id);break}const A=T.join("|");if(s.current.get(P.printer_id)===A)break;s.current.set(P.printer_id,A);const F=P.printer_name||`Printer ${P.printer_id}`,S=l("printers.toast.missingSpoolAssignment",{printer:F,slots:T.join(", ")});o(S,"warning");break}case"print_complete":_("archives"),_("archiveStats");break;case"archive_created":_("archives"),_("archiveStats");break;case"archive_updated":_("archives");break;case"pong":break;case"plate_not_empty":window.dispatchEvent(new CustomEvent("plate-not-empty",{detail:{printer_id:P.printer_id,printer_name:P.printer_name,message:P.message}}));break;case"inventory_changed":_("inventory-spools");break;case"spool_assignment_changed":_("spool-assignments"),_("slotPresets");break;case"spool_auto_assigned":_("inventory-spools"),_("spool-assignments");break;case"spool_usage_logged":_("inventory-spools");break;case"unknown_tag":window.dispatchEvent(new CustomEvent("unknown-tag",{detail:{printer_id:P.printer_id,ams_id:P.ams_id,tray_id:P.tray_id,tag_uid:P.tag_uid,tray_uuid:P.tray_uuid}}));break;case"background_dispatch":window.dispatchEvent(new CustomEvent("background-dispatch",{detail:P.data||{}}));break;case"spoolbuddy_weight":window.dispatchEvent(new CustomEvent("spoolbuddy-weight",{detail:P}));break;case"spoolbuddy_tag_matched":window.dispatchEvent(new CustomEvent("spoolbuddy-tag-matched",{detail:P})),_("inventory-spools");break;case"spoolbuddy_unknown_tag":window.dispatchEvent(new CustomEvent("spoolbuddy-unknown-tag",{detail:P}));break;case"spoolbuddy_tag_removed":window.dispatchEvent(new CustomEvent("spoolbuddy-tag-removed",{detail:P}));break;case"spoolbuddy_tag_written":window.dispatchEvent(new CustomEvent("spoolbuddy-tag-written",{detail:P})),_("inventory-spools");break;case"spoolbuddy_tag_write_failed":window.dispatchEvent(new CustomEvent("spoolbuddy-tag-write-failed",{detail:P}));break;case"spoolbuddy_online":window.dispatchEvent(new CustomEvent("spoolbuddy-online",{detail:P})),_("spoolbuddy-devices"),_("spoolbuddy-update-check");break;case"spoolbuddy_offline":window.dispatchEvent(new CustomEvent("spoolbuddy-offline",{detail:P})),_("spoolbuddy-devices");break;case"spoolbuddy_update":_("spoolbuddy-devices"),_("spoolbuddy-update-check");break}},[n,_,x,o,l]);v.useEffect(()=>{b.current=N},[N]),v.useEffect(()=>(g(),()=>{e.current&&clearTimeout(e.current),d.current&&clearTimeout(d.current),m.current&&clearTimeout(m.current),t.current&&t.current.close()}),[g]);const C=v.useCallback(P=>{t.current?.readyState===WebSocket.OPEN&&t.current.send(JSON.stringify(P))},[]);return{isConnected:a,sendMessage:C}}function kst({children:t}){const{authEnabled:e,user:n,loading:a}=cr(),i=!a&&(!e||n!==null),{data:s}=We({queryKey:["color-catalog-map"],queryFn:async()=>(await se.getColorNameMap()).colors,staleTime:1/0,gcTime:1/0,retry:2,enabled:i});return v.useEffect(()=>{s&&_ve(s)},[s]),r.jsx(r.Fragment,{children:t})}function Nst({selectedPrinterId:t,onPrinterChange:e,deviceOnline:n}){const{t:a}=kt(),[i,s]=v.useState(new Date),{data:o=[]}=We({queryKey:["printers"],queryFn:()=>se.getPrinters()}),l=ef({queries:o.map(u=>({queryKey:["printerStatus",u.id],queryFn:()=>se.getPrinterStatus(u.id),refetchInterval:1e4}))}),c=v.useMemo(()=>o.filter((u,m)=>l[m]?.data?.connected),[o,l]);v.useEffect(()=>{const u=c.some(m=>m.id===t);(!t||!u)&&c.length>0&&e(c[0].id)},[c,t,e]);const{data:d}=We({queryKey:["settings"],queryFn:se.getSettings});return v.useEffect(()=>{const u=setInterval(()=>s(new Date),1e3);return()=>clearInterval(u)},[]),r.jsxs("div",{className:"h-12 bg-bambu-dark-secondary border-b border-bambu-dark-tertiary flex items-center px-3 gap-4 shrink-0",children:[r.jsx("div",{className:"flex items-center shrink-0",children:r.jsx("img",{src:"/img/spoolbuddy_logo_dark_small.png",alt:"SpoolBuddy",width:113,height:28,className:"h-7 w-auto"})}),r.jsx("div",{className:"flex-1 flex justify-center",children:r.jsx("select",{value:t??"",onChange:u=>e(Number(u.target.value)),className:"bg-bambu-dark text-white text-base px-4 py-2 rounded border border-bambu-dark-tertiary focus:outline-none focus:border-bambu-green min-w-[180px]",children:c.length===0?r.jsx("option",{value:"",children:a("spoolbuddy.status.noPrinters","No printers online")}):c.map(u=>r.jsx("option",{value:u.id,children:u.name},u.id))})}),r.jsxs("div",{className:"flex items-center gap-3 shrink-0",children:[r.jsx("div",{className:"flex items-center",title:n?a("spoolbuddy.status.backend","Backend"):a("spoolbuddy.status.offline","Offline"),children:n?r.jsx("div",{className:"flex items-end gap-0.5 h-4",children:[1,2,3,4].map(u=>r.jsx("div",{className:`w-1 rounded-sm ${u<=4?"bg-white":"bg-bambu-dark-tertiary"}`,style:{height:`${u*4}px`}},u))}):r.jsx(mu,{className:"w-5 h-5 text-red-400"})}),r.jsxs("div",{className:"flex items-center gap-1.5",children:[r.jsx("div",{className:`w-3 h-3 rounded-full ${n?"bg-bambu-green shadow-[0_0_6px_rgba(34,197,94,0.5)]":"bg-bambu-gray"}`}),r.jsx("span",{className:"text-sm text-white/50",children:n?a("spoolbuddy.status.backend","Backend"):a("spoolbuddy.status.offline","Offline")})]}),r.jsx("span",{className:"text-white/50 text-base font-mono min-w-[50px] text-right",children:QZ(i,d?.time_format||"system")})]})]})}const Cst=[{to:"/spoolbuddy",labelKey:"spoolbuddy.nav.dashboard",fallback:"Dashboard",icon:r.jsx("svg",{className:"w-6 h-6",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:r.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M3 12l2-2m0 0l7-7 7 7M5 10v10a1 1 0 001 1h3m10-11l2 2m-2-2v10a1 1 0 01-1 1h-3m-6 0a1 1 0 001-1v-4a1 1 0 011-1h2a1 1 0 011 1v4a1 1 0 001 1m-6 0h6"})})},{to:"/spoolbuddy/ams",labelKey:"spoolbuddy.nav.ams",fallback:"AMS",icon:r.jsx("svg",{className:"w-6 h-6",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:r.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10"})})},{to:"/spoolbuddy/write-tag",labelKey:"spoolbuddy.nav.writeTag",fallback:"Write",icon:r.jsxs("svg",{className:"w-6 h-6",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,children:[r.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M8.288 15.038a5.25 5.25 0 017.424 0M5.106 11.856c3.807-3.808 9.98-3.808 13.788 0M1.924 8.674c5.565-5.565 14.587-5.565 20.152 0"}),r.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M12.53 18.22l-.53.53-.53-.53a.75.75 0 011.06 0z"})]})},{to:"/spoolbuddy/inventory",labelKey:"spoolbuddy.nav.inventory",fallback:"Inventory",icon:r.jsx("svg",{className:"w-6 h-6",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:r.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M20 7l-8-4-8 4m16 0l-8 4m8-4v10l-8 4m0-10L4 7m8 4v10M4 7v10l8 4"})})},{to:"/spoolbuddy/settings",labelKey:"spoolbuddy.nav.settings",fallback:"Settings",icon:r.jsxs("svg",{className:"w-6 h-6",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:[r.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.066 2.573c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.573 1.066c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.066-2.573c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z"}),r.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 12a3 3 0 11-6 0 3 3 0 016 0z"})]})}];function Pst(){const{t}=kt();return r.jsx("nav",{className:"h-14 bg-bambu-dark-secondary border-t border-bambu-dark-tertiary flex items-stretch shrink-0",children:Cst.map(e=>r.jsxs($x,{to:e.to,end:e.to==="/spoolbuddy",className:({isActive:n})=>`flex-1 flex flex-col items-center justify-center gap-1 transition-colors ${n?"text-bambu-green bg-bambu-dark":"text-white/50 hover:text-white/70 hover:bg-bambu-dark-tertiary"}`,children:[e.icon,r.jsx("span",{className:"text-xs font-medium",children:t(e.labelKey,e.fallback)})]},e.to))})}function Tst({alert:t}){const{t:e}=kt(),n=t?t.type==="error"?"bg-red-500":t.type==="warning"?"bg-amber-500":"bg-bambu-green":"bg-bambu-green",a=t?t.type==="error"?"border-red-500":t.type==="warning"?"border-amber-500":"border-bambu-dark-tertiary":"border-bambu-dark-tertiary";return r.jsxs("div",{className:`h-9 bg-bambu-dark-secondary border-t-2 ${a} flex items-center px-3 gap-3 shrink-0`,children:[r.jsx("div",{className:`w-3.5 h-3.5 rounded-full ${n}`}),r.jsx("div",{className:"flex-1 text-sm text-white/50 truncate",children:t?r.jsx("span",{children:t.message}):r.jsx("span",{className:"text-bambu-green",children:e("spoolbuddy.status.systemReady","System Ready")})})]})}function Ast({isOpen:t,onClose:e,deviceId:n,deviceOnline:a}){const{t:i}=kt(),[s,o]=v.useState(null),[l,c]=v.useState(!1),[d,u]=v.useState(new Map),{data:m=[]}=We({queryKey:["printers"],queryFn:()=>se.getPrinters(),enabled:t}),{data:p=[]}=We({queryKey:["smart-plugs"],queryFn:()=>se.getSmartPlugs(),enabled:t}),f=m.map(_=>{const N=p.find(P=>P.printer_id===_.id&&P.plug_type!=="mqtt"&&P.enabled);if(!N)return null;const C=d.get(N.id);return{plug:N,printer:_,status:C?{state:C.state,reachable:!0,device_name:null,energy:null}:null,loading:C?.loading??!1}}).filter(Boolean);v.useEffect(()=>{if(!t||p.length===0)return;p.filter(N=>N.printer_id!==null&&N.plug_type!=="mqtt"&&N.enabled).forEach(async N=>{try{const C=await se.getSmartPlugStatus(N.id);u(P=>{const T=new Map(P);return T.set(N.id,{loading:!1,state:C.state}),T})}catch{u(C=>{const P=new Map(C);return P.set(N.id,{loading:!1,state:null}),P})}})},[t,p]),v.useEffect(()=>{t||(o(null),c(!1))},[t]);const b=v.useCallback(async _=>{u(N=>{const C=new Map(N),P=C.get(_.id);return C.set(_.id,{loading:!0,state:P?.state??null}),C});try{await se.controlSmartPlug(_.id,"toggle");const N=await se.getSmartPlugStatus(_.id);u(C=>{const P=new Map(C);return P.set(_.id,{loading:!1,state:N.state}),P})}catch{u(N=>{const C=new Map(N),P=C.get(_.id);return C.set(_.id,{loading:!1,state:P?.state??null}),C})}},[]),w=v.useCallback(async _=>{if(n){c(!0);try{await Xr.systemCommand(n,_),setTimeout(()=>e(),500)}catch{c(!1)}}},[n,e]),g=v.useCallback(()=>{s&&(s.type==="system"?w(s.command):b(s.plug),o(null))},[s,w,b]);if(!t)return null;const x=_=>_==="ON"||_==="on";return r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"fixed inset-0 z-40 bg-black/50",onPointerDown:e}),r.jsxs("div",{className:"fixed top-0 left-0 right-0 z-50 bg-bambu-dark-secondary border-b border-bambu-dark-tertiary rounded-b-2xl shadow-2xl animate-slide-down",children:[r.jsx("div",{className:"flex justify-center pt-2 pb-1",children:r.jsx("div",{className:"w-10 h-1 rounded-full bg-zinc-600"})}),r.jsxs("div",{className:"px-4 pb-4 max-h-[80vh] overflow-y-auto",children:[f.length>0&&r.jsxs("div",{className:"mb-4",children:[r.jsx("h3",{className:"text-xs font-semibold text-zinc-500 uppercase tracking-wide mb-2",children:i("spoolbuddy.quickMenu.printerPower","Printer Power")}),r.jsx("div",{className:"space-y-1",children:f.map(({plug:_,printer:N,loading:C})=>{const P=d.get(_.id),T=x(P?.state??null);return r.jsxs("button",{onClick:()=>o({type:"plug",plug:_,printer:N,currentState:P?.state??null}),disabled:C,className:"w-full flex items-center gap-2 px-3 py-1.5 rounded-lg bg-zinc-800/60 hover:bg-zinc-700/60 transition-colors min-h-[36px]",children:[r.jsx("div",{className:`w-2 h-2 rounded-full shrink-0 ${T?"bg-green-500":"bg-zinc-600"}`}),C&&r.jsx(ut,{className:"w-3 h-3 animate-spin text-zinc-400 shrink-0"}),r.jsx("span",{className:"flex-1 text-sm text-zinc-200 text-left truncate",children:N.name}),r.jsx("span",{className:`text-xs font-medium ${T?"text-green-400":"text-zinc-500"}`,children:P?.state??"—"})]},_.id)})})]}),r.jsxs("div",{children:[r.jsx("h3",{className:"text-xs font-semibold text-zinc-500 uppercase tracking-wide mb-2",children:i("spoolbuddy.quickMenu.systemControls","System")}),r.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[r.jsx(mN,{icon:r.jsx(Mw,{className:"w-4 h-4"}),label:i("spoolbuddy.quickMenu.restartDaemon","Restart Daemon"),onClick:()=>o({type:"system",command:"restart_daemon"}),disabled:!n||!a||l}),r.jsx(mN,{icon:r.jsx(xO,{className:"w-4 h-4"}),label:i("spoolbuddy.quickMenu.restartBrowser","Restart Browser"),onClick:()=>o({type:"system",command:"restart_browser"}),disabled:!n||!a||l}),r.jsx(mN,{icon:r.jsx(Mw,{className:"w-4 h-4"}),label:i("spoolbuddy.quickMenu.reboot","Reboot"),onClick:()=>o({type:"system",command:"reboot"}),disabled:!n||!a||l,variant:"warning"}),r.jsx(mN,{icon:r.jsx(ES,{className:"w-4 h-4"}),label:i("spoolbuddy.quickMenu.shutdown","Shutdown"),onClick:()=>o({type:"system",command:"shutdown"}),disabled:!n||!a||l,variant:"danger"})]})]}),r.jsx("div",{className:"flex justify-center mt-3",children:r.jsxs("div",{className:"flex items-center gap-1 text-xs text-zinc-600",children:[r.jsx(Rn,{className:"w-3 h-3"}),r.jsx("span",{children:i("spoolbuddy.quickMenu.swipeToClose","Swipe down to close")})]})})]})]}),s&&r.jsx("div",{className:"fixed inset-0 z-[60] flex items-center justify-center bg-black/60",children:r.jsxs("div",{className:"bg-zinc-800 rounded-2xl p-5 mx-4 max-w-sm w-full border border-zinc-700",children:[r.jsx("h3",{className:"text-lg font-semibold text-zinc-100 mb-2",children:i("spoolbuddy.quickMenu.confirmTitle","Confirm")}),r.jsx("p",{className:"text-sm text-zinc-400 mb-5",children:s.type==="plug"?x(s.currentState)?i("spoolbuddy.quickMenu.confirmPlugOff","Turn off {{name}}?",{name:s.printer.name}):i("spoolbuddy.quickMenu.confirmPlugOn","Turn on {{name}}?",{name:s.printer.name}):s.command==="shutdown"?i("spoolbuddy.quickMenu.confirmShutdown","Are you sure you want to shut down the SpoolBuddy? You will need physical access to turn it back on."):s.command==="reboot"?i("spoolbuddy.quickMenu.confirmReboot","Are you sure you want to reboot the SpoolBuddy?"):s.command==="restart_daemon"?i("spoolbuddy.quickMenu.confirmRestartDaemon","Restart the SpoolBuddy daemon? NFC and scale will be temporarily unavailable."):i("spoolbuddy.quickMenu.confirmRestartBrowser","Restart the kiosk browser? The display will briefly go blank.")}),r.jsxs("div",{className:"flex gap-3",children:[r.jsx("button",{onClick:()=>o(null),className:"flex-1 px-4 py-2.5 rounded-lg text-sm font-medium bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors min-h-[44px]",children:i("common.cancel","Cancel")}),r.jsx("button",{onClick:g,disabled:l,className:`flex-1 px-4 py-2.5 rounded-lg text-sm font-medium text-white transition-colors min-h-[44px] ${s.type==="plug"?x(s.currentState)?"bg-red-600 hover:bg-red-700":"bg-green-600 hover:bg-green-700":s.command==="shutdown"?"bg-red-600 hover:bg-red-700":s.command==="reboot"?"bg-amber-600 hover:bg-amber-700":"bg-blue-600 hover:bg-blue-700"} disabled:opacity-50`,children:l?r.jsx(ut,{className:"w-4 h-4 animate-spin mx-auto"}):s.type==="plug"?x(s.currentState)?i("spoolbuddy.quickMenu.turnOff","Turn Off"):i("spoolbuddy.quickMenu.turnOn","Turn On"):i("spoolbuddy.quickMenu.confirm","Confirm")})]})]})})]})}function mN({icon:t,label:e,onClick:n,disabled:a,variant:i="default"}){const s={default:"bg-zinc-800/60 hover:bg-zinc-700/60 text-zinc-300",warning:"bg-amber-900/30 hover:bg-amber-900/50 text-amber-400",danger:"bg-red-900/30 hover:bg-red-900/50 text-red-400"};return r.jsxs("button",{onClick:n,disabled:a,className:`flex items-center gap-2.5 p-3 rounded-xl transition-colors min-h-[48px] disabled:opacity-40 ${s[i]}`,children:[t,r.jsx("span",{className:"text-sm font-medium",children:e})]})}const jst={weight:null,weightStable:!1,rawAdc:null,matchedSpool:null,unknownTagUid:null,unknownTrayUuid:null,deviceOnline:!1,deviceId:null};function Mst(t,e){switch(e.type){case"WEIGHT_UPDATE":return{...t,weight:e.weight,weightStable:e.stable,rawAdc:e.rawAdc,deviceId:e.deviceId,deviceOnline:!0};case"TAG_MATCHED":return{...t,matchedSpool:e.spool,unknownTagUid:null,unknownTrayUuid:null,deviceId:e.deviceId};case"UNKNOWN_TAG":return{...t,matchedSpool:null,unknownTagUid:e.tagUid,unknownTrayUuid:e.trayUuid??null,deviceId:e.deviceId};case"TAG_REMOVED":return{...t,matchedSpool:null,unknownTagUid:null,unknownTrayUuid:null};case"DEVICE_ONLINE":return{...t,deviceOnline:!0,deviceId:e.deviceId};case"DEVICE_OFFLINE":return{...t,deviceOnline:!1,weight:null,weightStable:!1,rawAdc:null};default:return t}}function Est(){const[t,e]=v.useReducer(Mst,jst),n=v.useCallback(u=>{const m=u.detail;e({type:"WEIGHT_UPDATE",weight:m.weight_grams??m.data?.weight_grams,stable:m.stable??m.data?.stable??!1,rawAdc:m.raw_adc??m.data?.raw_adc??null,deviceId:m.device_id??m.data?.device_id??""})},[]),a=v.useCallback(u=>{const m=u.detail,p=m.spool??m.data?.spool;p&&e({type:"TAG_MATCHED",spool:{id:p.id,tag_uid:m.tag_uid??m.data?.tag_uid??"",material:p.material??"",subtype:p.subtype??null,color_name:p.color_name??null,rgba:p.rgba??null,brand:p.brand??null,label_weight:p.label_weight??0,core_weight:p.core_weight??0,weight_used:p.weight_used??0},deviceId:m.device_id??m.data?.device_id??""})},[]),i=v.useCallback(u=>{const m=u.detail;e({type:"UNKNOWN_TAG",tagUid:m.tag_uid??m.data?.tag_uid??"",trayUuid:m.tray_uuid??m.data?.tray_uuid??null,deviceId:m.device_id??m.data?.device_id??""})},[]),s=v.useCallback(u=>{const m=u.detail;e({type:"TAG_REMOVED",deviceId:m.device_id??m.data?.device_id??""})},[]),o=v.useCallback(u=>{const m=u.detail;e({type:"DEVICE_ONLINE",deviceId:m.device_id??m.data?.device_id??""})},[]),l=v.useCallback(u=>{const m=u.detail;e({type:"DEVICE_OFFLINE",deviceId:m.device_id??m.data?.device_id??""})},[]);v.useEffect(()=>(window.addEventListener("spoolbuddy-weight",n),window.addEventListener("spoolbuddy-tag-matched",a),window.addEventListener("spoolbuddy-unknown-tag",i),window.addEventListener("spoolbuddy-tag-removed",s),window.addEventListener("spoolbuddy-online",o),window.addEventListener("spoolbuddy-offline",l),()=>{window.removeEventListener("spoolbuddy-weight",n),window.removeEventListener("spoolbuddy-tag-matched",a),window.removeEventListener("spoolbuddy-unknown-tag",i),window.removeEventListener("spoolbuddy-tag-removed",s),window.removeEventListener("spoolbuddy-online",o),window.removeEventListener("spoolbuddy-offline",l)}),[n,a,i,s,o,l]);const c=t.matchedSpool?Math.max(0,t.matchedSpool.label_weight-t.matchedSpool.weight_used):null,d=t.weight!==null&&t.matchedSpool?Math.max(0,t.weight-t.matchedSpool.core_weight):null;return{...t,remainingWeight:c,netWeight:d}}var HN={exports:{}};var Dst=HN.exports,_Q;function Fst(){return _Q||(_Q=1,(function(t,e){(function(n,a){t.exports=a(rb())})(Dst,(function(n){return(function(){var a={981:function(){typeof Element>"u"||"remove"in Element.prototype||(Element.prototype.remove=function(){this.parentNode&&this.parentNode.removeChild(this)}),typeof self<"u"&&"document"in self&&((!("classList"in document.createElement("_"))||document.createElementNS&&!("classList"in document.createElementNS("http://www.w3.org/2000/svg","g")))&&(function(l){if("Element"in l){var c="classList",d="prototype",u=l.Element[d],m=Object,p=String[d].trim||function(){return this.replace(/^\s+|\s+$/g,"")},f=Array[d].indexOf||function(C){for(var P=0,T=this.length;P1?arguments[1]:void 0)}},7916:function($,K,D){var j=D(6080),B=D(9565),X=D(8981),O=D(6319),ie=D(4209),U=D(3517),G=D(6198),Y=D(4659),Q=D(4527),oe=D(81),ee=D(851),ge=Array;$.exports=function(ce){var le=X(ce),q=U(this),R=arguments.length,ne=R>1?arguments[1]:void 0,xe=ne!==void 0;xe&&(ne=j(ne,R>2?arguments[2]:void 0));var we,Ne,ve,be,Ee,ze,_e=ee(le),Oe=0;if(!_e||this===ge&&ie(_e))for(we=G(le),Ne=q?new this(we):ge(we);we>Oe;Oe++)ze=xe?ne(le[Oe],Oe):le[Oe],Y(Ne,Oe,ze);else for(Ne=q?new this:[],Ee=(be=oe(le,_e)).next;!(ve=B(Ee,be)).done;Oe++)ze=xe?O(be,ne,[ve.value,Oe],!0):ve.value,Y(Ne,Oe,ze);return Q(Ne,Oe),Ne}},9617:function($,K,D){var j=D(5397),B=D(5610),X=D(6198),O=function(ie){return function(U,G,Y){var Q=j(U),oe=X(Q);if(oe===0)return!ie&&-1;var ee,ge=B(Y,oe);if(ie&&G!=G){for(;oe>ge;)if((ee=Q[ge++])!=ee)return!0}else for(;oe>ge;ge++)if((ie||ge in Q)&&Q[ge]===G)return ie||ge||0;return!ie&&-1}};$.exports={includes:O(!0),indexOf:O(!1)}},9213:function($,K,D){var j=D(6080),B=D(7055),X=D(8981),O=D(6198),ie=D(1469),U=D(4659),G=function(Y){var Q=Y===1,oe=Y===2,ee=Y===3,ge=Y===4,ce=Y===6,le=Y===7,q=Y===5||ce;return function(R,ne,xe){for(var we,Ne,ve=X(R),be=B(ve),Ee=O(be),ze=j(ne,xe),_e=0,Oe=0,Ie=Q?ie(R,Ee):oe||le?ie(R,0):void 0;Ee>_e;_e++)if((q||_e in be)&&(Ne=ze(we=be[_e],_e,ve),Y))if(Q)U(Ie,_e,Ne);else if(Ne)switch(Y){case 3:return!0;case 5:return we;case 6:return _e;case 2:U(Ie,Oe++,we)}else switch(Y){case 4:return!1;case 7:U(Ie,Oe++,we)}return ce?-1:ee||ge?ge:Ie}};$.exports={forEach:G(0),map:G(1),filter:G(2),some:G(3),every:G(4),find:G(5),findIndex:G(6),filterReject:G(7)}},597:function($,K,D){var j=D(9039),B=D(8227),X=D(9519),O=B("species");$.exports=function(ie){return X>=51||!j((function(){var U=[];return(U.constructor={})[O]=function(){return{foo:1}},U[ie](Boolean).foo!==1}))}},4598:function($,K,D){var j=D(9039);$.exports=function(B,X){var O=[][B];return!!O&&j((function(){O.call(null,X||function(){return 1},1)}))}},926:function($,K,D){var j=D(9306),B=D(8981),X=D(7055),O=D(6198),ie=TypeError,U="Reduce of empty array with no initial value",G=function(Y){return function(Q,oe,ee,ge){var ce=B(Q),le=X(ce),q=O(ce);if(j(oe),q===0&&ee<2)throw new ie(U);var R=Y?q-1:0,ne=Y?-1:1;if(ee<2)for(;;){if(R in le){ge=le[R],R+=ne;break}if(R+=ne,Y?R<0:q<=R)throw new ie(U)}for(;Y?R>=0:q>R;R+=ne)R in le&&(ge=oe(ge,le[R],R,ce));return ge}};$.exports={left:G(!1),right:G(!0)}},4527:function($,K,D){var j=D(3724),B=D(4376),X=TypeError,O=Object.getOwnPropertyDescriptor,ie=j&&!(function(){if(this!==void 0)return!0;try{Object.defineProperty([],"length",{writable:!1}).length=1}catch(U){return U instanceof TypeError}})();$.exports=ie?function(U,G){if(B(U)&&!O(U,"length").writable)throw new X("Cannot set read only .length");return U.length=G}:function(U,G){return U.length=G}},7680:function($,K,D){var j=D(9504);$.exports=j([].slice)},4488:function($,K,D){var j=D(7680),B=Math.floor,X=function(O,ie){var U=O.length;if(U<8)for(var G,Y,Q=1;Q0;)O[Y]=O[--Y];Y!==Q++&&(O[Y]=G)}else for(var oe=B(U/2),ee=X(j(O,0,oe),ie),ge=X(j(O,oe),ie),ce=ee.length,le=ge.length,q=0,R=0;q9007199254740991)throw K("Maximum allowed index exceeded");return D}},7400:function($){$.exports={CSSRuleList:0,CSSStyleDeclaration:0,CSSValueList:0,ClientRectList:0,DOMRectList:0,DOMStringList:0,DOMTokenList:1,DataTransferItemList:0,FileList:0,HTMLAllCollection:0,HTMLCollection:0,HTMLFormElement:0,HTMLSelectElement:0,MediaList:0,MimeTypeArray:0,NamedNodeMap:0,NodeList:1,PaintRequestList:0,Plugin:0,PluginArray:0,SVGLengthList:0,SVGNumberList:0,SVGPathSegList:0,SVGPointList:0,SVGStringList:0,SVGTransformList:0,SourceBufferList:0,StyleSheetList:0,TextTrackCueList:0,TextTrackList:0,TouchList:0}},9296:function($,K,D){var j=D(4055)("span").classList,B=j&&j.constructor&&j.constructor.prototype;$.exports=B===Object.prototype?void 0:B},8727:function($){$.exports=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"]},3709:function($,K,D){var j=D(2839).match(/firefox\/(\d+)/i);$.exports=!!j&&+j[1]},3763:function($,K,D){var j=D(2839);$.exports=/MSIE|Trident/.test(j)},6193:function($,K,D){var j=D(4215);$.exports=j==="NODE"},2839:function($,K,D){var j=D(4576).navigator,B=j&&j.userAgent;$.exports=B?String(B):""},9519:function($,K,D){var j,B,X=D(4576),O=D(2839),ie=X.process,U=X.Deno,G=ie&&ie.versions||U&&U.version,Y=G&&G.v8;Y&&(B=(j=Y.split("."))[0]>0&&j[0]<4?1:+(j[0]+j[1])),!B&&O&&(!(j=O.match(/Edge\/(\d+)/))||j[1]>=74)&&(j=O.match(/Chrome\/(\d+)/))&&(B=+j[1]),$.exports=B},3607:function($,K,D){var j=D(2839).match(/AppleWebKit\/(\d+)\./);$.exports=!!j&&+j[1]},4215:function($,K,D){var j=D(4576),B=D(2839),X=D(2195),O=function(ie){return B.slice(0,ie.length)===ie};$.exports=O("Bun/")?"BUN":O("Cloudflare-Workers")?"CLOUDFLARE":O("Deno/")?"DENO":O("Node.js/")?"NODE":j.Bun&&typeof Bun.version=="string"?"BUN":j.Deno&&typeof Deno.version=="object"?"DENO":X(j.process)==="process"?"NODE":j.window&&j.document?"BROWSER":"REST"},6518:function($,K,D){var j=D(4576),B=D(7347).f,X=D(6699),O=D(6840),ie=D(9433),U=D(7740),G=D(2796);$.exports=function(Y,Q){var oe,ee,ge,ce,le,q=Y.target,R=Y.global,ne=Y.stat;if(oe=R?j:ne?j[q]||ie(q,{}):j[q]&&j[q].prototype)for(ee in Q){if(ce=Q[ee],ge=Y.dontCallGetSet?(le=B(oe,ee))&&le.value:oe[ee],!G(R?ee:q+(ne?".":"#")+ee,Y.forced)&&ge!==void 0){if(typeof ce==typeof ge)continue;U(ce,ge)}(Y.sham||ge&&ge.sham)&&X(ce,"sham",!0),O(oe,ee,ce,Y)}}},9039:function($){$.exports=function(K){try{return!!K()}catch{return!0}}},9228:function($,K,D){D(7495);var j=D(9565),B=D(6840),X=D(7323),O=D(9039),ie=D(8227),U=D(6699),G=ie("species"),Y=RegExp.prototype;$.exports=function(Q,oe,ee,ge){var ce=ie(Q),le=!O((function(){var xe={};return xe[ce]=function(){return 7},""[Q](xe)!==7})),q=le&&!O((function(){var xe=!1,we=/a/;if(Q==="split"){var Ne={};Ne[G]=function(){return we},(we={constructor:Ne,flags:""})[ce]=/./[ce]}return we.exec=function(){return xe=!0,null},we[ce](""),!xe}));if(!le||!q||ee){var R=/./[ce],ne=oe(ce,""[Q],(function(xe,we,Ne,ve,be){var Ee=we.exec;return Ee===X||Ee===Y.exec?le&&!be?{done:!0,value:j(R,we,Ne,ve)}:{done:!0,value:j(xe,Ne,we,ve)}:{done:!1}}));B(String.prototype,Q,ne[0]),B(Y,ce,ne[1])}ge&&U(Y[ce],"sham",!0)}},8745:function($,K,D){var j=D(616),B=Function.prototype,X=B.apply,O=B.call;$.exports=typeof Reflect=="object"&&Reflect.apply||(j?O.bind(X):function(){return O.apply(X,arguments)})},6080:function($,K,D){var j=D(7476),B=D(9306),X=D(616),O=j(j.bind);$.exports=function(ie,U){return B(ie),U===void 0?ie:X?O(ie,U):function(){return ie.apply(U,arguments)}}},616:function($,K,D){var j=D(9039);$.exports=!j((function(){var B=(function(){}).bind();return typeof B!="function"||B.hasOwnProperty("prototype")}))},566:function($,K,D){var j=D(9504),B=D(9306),X=D(34),O=D(9297),ie=D(7680),U=D(616),G=Function,Y=j([].concat),Q=j([].join),oe={};$.exports=U?G.bind:function(ee){var ge=B(this),ce=ge.prototype,le=ie(arguments,1),q=function(){var R=Y(le,ie(arguments));return this instanceof q?(function(ne,xe,we){if(!O(oe,xe)){for(var Ne=[],ve=0;ve]*>)/g,Y=/\$([$&'`]|\d{1,2})/g;$.exports=function(Q,oe,ee,ge,ce,le){var q=ee+Q.length,R=ge.length,ne=Y;return ce!==void 0&&(ce=B(ce),ne=G),ie(le,ne,(function(xe,we){var Ne;switch(O(we,0)){case"$":return"$";case"&":return Q;case"`":return U(oe,0,ee);case"'":return U(oe,q);case"<":Ne=ce[U(we,1,-1)];break;default:var ve=+we;if(ve===0)return xe;if(ve>R){var be=X(ve/10);return be===0?xe:be<=R?ge[be-1]===void 0?O(we,1):ge[be-1]+O(we,1):xe}Ne=ge[ve-1]}return Ne===void 0?"":Ne}))}},4576:function($,K,D){var j=function(B){return B&&B.Math===Math&&B};$.exports=j(typeof globalThis=="object"&&globalThis)||j(typeof window=="object"&&window)||j(typeof self=="object"&&self)||j(typeof D.g=="object"&&D.g)||j(typeof this=="object"&&this)||(function(){return this})()||Function("return this")()},9297:function($,K,D){var j=D(9504),B=D(8981),X=j({}.hasOwnProperty);$.exports=Object.hasOwn||function(O,ie){return X(B(O),ie)}},421:function($){$.exports={}},397:function($,K,D){var j=D(7751);$.exports=j("document","documentElement")},5917:function($,K,D){var j=D(3724),B=D(9039),X=D(4055);$.exports=!j&&!B((function(){return Object.defineProperty(X("div"),"a",{get:function(){return 7}}).a!==7}))},7055:function($,K,D){var j=D(9504),B=D(9039),X=D(2195),O=Object,ie=j("".split);$.exports=B((function(){return!O("z").propertyIsEnumerable(0)}))?function(U){return X(U)==="String"?ie(U,""):O(U)}:O},3167:function($,K,D){var j=D(4901),B=D(34),X=D(2967);$.exports=function(O,ie,U){var G,Y;return X&&j(G=ie.constructor)&&G!==U&&B(Y=G.prototype)&&Y!==U.prototype&&X(O,Y),O}},3706:function($,K,D){var j=D(9504),B=D(4901),X=D(7629),O=j(Function.toString);B(X.inspectSource)||(X.inspectSource=function(ie){return O(ie)}),$.exports=X.inspectSource},1181:function($,K,D){var j,B,X,O=D(8622),ie=D(4576),U=D(34),G=D(6699),Y=D(9297),Q=D(7629),oe=D(6119),ee=D(421),ge="Object already initialized",ce=ie.TypeError,le=ie.WeakMap;if(O||Q.state){var q=Q.state||(Q.state=new le);q.get=q.get,q.has=q.has,q.set=q.set,j=function(ne,xe){if(q.has(ne))throw new ce(ge);return xe.facade=ne,q.set(ne,xe),xe},B=function(ne){return q.get(ne)||{}},X=function(ne){return q.has(ne)}}else{var R=oe("state");ee[R]=!0,j=function(ne,xe){if(Y(ne,R))throw new ce(ge);return xe.facade=ne,G(ne,R,xe),xe},B=function(ne){return Y(ne,R)?ne[R]:{}},X=function(ne){return Y(ne,R)}}$.exports={set:j,get:B,has:X,enforce:function(ne){return X(ne)?B(ne):j(ne,{})},getterFor:function(ne){return function(xe){var we;if(!U(xe)||(we=B(xe)).type!==ne)throw new ce("Incompatible receiver, "+ne+" required");return we}}}},4209:function($,K,D){var j=D(8227),B=D(6269),X=j("iterator"),O=Array.prototype;$.exports=function(ie){return ie!==void 0&&(B.Array===ie||O[X]===ie)}},4376:function($,K,D){var j=D(2195);$.exports=Array.isArray||function(B){return j(B)==="Array"}},4901:function($){var K=typeof document=="object"&&document.all;$.exports=K===void 0&&K!==void 0?function(D){return typeof D=="function"||D===K}:function(D){return typeof D=="function"}},3517:function($,K,D){var j=D(9504),B=D(9039),X=D(4901),O=D(6955),ie=D(7751),U=D(3706),G=function(){},Y=ie("Reflect","construct"),Q=/^\s*(?:class|function)\b/,oe=j(Q.exec),ee=!Q.test(G),ge=function(le){if(!X(le))return!1;try{return Y(G,[],le),!0}catch{return!1}},ce=function(le){if(!X(le))return!1;switch(O(le)){case"AsyncFunction":case"GeneratorFunction":case"AsyncGeneratorFunction":return!1}try{return ee||!!oe(Q,U(le))}catch{return!0}};ce.sham=!0,$.exports=!Y||B((function(){var le;return ge(ge.call)||!ge(Object)||!ge((function(){le=!0}))||le}))?ce:ge},2796:function($,K,D){var j=D(9039),B=D(4901),X=/#|\.prototype\./,O=function(Q,oe){var ee=U[ie(Q)];return ee===Y||ee!==G&&(B(oe)?j(oe):!!oe)},ie=O.normalize=function(Q){return String(Q).replace(X,".").toLowerCase()},U=O.data={},G=O.NATIVE="N",Y=O.POLYFILL="P";$.exports=O},2087:function($,K,D){var j=D(34),B=Math.floor;$.exports=Number.isInteger||function(X){return!j(X)&&isFinite(X)&&B(X)===X}},4117:function($){$.exports=function(K){return K==null}},34:function($,K,D){var j=D(4901);$.exports=function(B){return typeof B=="object"?B!==null:j(B)}},3925:function($,K,D){var j=D(34);$.exports=function(B){return j(B)||B===null}},6395:function($){$.exports=!1},5810:function($,K,D){var j=D(34),B=D(1181).get;$.exports=function(X){if(!j(X))return!1;var O=B(X);return!!O&&O.type==="RawJSON"}},788:function($,K,D){var j=D(34),B=D(2195),X=D(8227)("match");$.exports=function(O){var ie;return j(O)&&((ie=O[X])!==void 0?!!ie:B(O)==="RegExp")}},757:function($,K,D){var j=D(7751),B=D(4901),X=D(1625),O=D(7040),ie=Object;$.exports=O?function(U){return typeof U=="symbol"}:function(U){var G=j("Symbol");return B(G)&&X(G.prototype,ie(U))}},9539:function($,K,D){var j=D(9565),B=D(8551),X=D(5966);$.exports=function(O,ie,U){var G,Y;B(O);try{if(!(G=X(O,"return"))){if(ie==="throw")throw U;return U}G=j(G,O)}catch(Q){Y=!0,G=Q}if(ie==="throw")throw U;if(Y)throw G;return B(G),U}},3994:function($,K,D){var j=D(7657).IteratorPrototype,B=D(2360),X=D(6980),O=D(687),ie=D(6269),U=function(){return this};$.exports=function(G,Y,Q,oe){var ee=Y+" Iterator";return G.prototype=B(j,{next:X(+!oe,Q)}),O(G,ee,!1,!0),ie[ee]=U,G}},1088:function($,K,D){var j=D(6518),B=D(9565),X=D(6395),O=D(350),ie=D(4901),U=D(3994),G=D(2787),Y=D(2967),Q=D(687),oe=D(6699),ee=D(6840),ge=D(8227),ce=D(6269),le=D(7657),q=O.PROPER,R=O.CONFIGURABLE,ne=le.IteratorPrototype,xe=le.BUGGY_SAFARI_ITERATORS,we=ge("iterator"),Ne="keys",ve="values",be="entries",Ee=function(){return this};$.exports=function(ze,_e,Oe,Ie,Ke,rt,st){U(Oe,_e,Ie);var Re,tt,Ce,Xe=function(gt){if(gt===Ke&&Be)return Be;if(!xe&>&> in Ae)return Ae[gt];switch(gt){case Ne:case ve:case be:return function(){return new Oe(this,gt)}}return function(){return new Oe(this)}},Ue=_e+" Iterator",fe=!1,Ae=ze.prototype,$e=Ae[we]||Ae["@@iterator"]||Ke&&Ae[Ke],Be=!xe&&$e||Xe(Ke),nt=_e==="Array"&&Ae.entries||$e;if(nt&&(Re=G(nt.call(new ze)))!==Object.prototype&&Re.next&&(X||G(Re)===ne||(Y?Y(Re,ne):ie(Re[we])||ee(Re,we,Ee)),Q(Re,Ue,!0,!0),X&&(ce[Ue]=Ee)),q&&Ke===ve&&$e&&$e.name!==ve&&(!X&&R?oe(Ae,"name",ve):(fe=!0,Be=function(){return B($e,this)})),Ke)if(tt={values:Xe(ve),keys:rt?Be:Xe(Ne),entries:Xe(be)},st)for(Ce in tt)(xe||fe||!(Ce in Ae))&&ee(Ae,Ce,tt[Ce]);else j({target:_e,proto:!0,forced:xe||fe},tt);return X&&!st||Ae[we]===Be||ee(Ae,we,Be,{name:Ke}),ce[_e]=Be,tt}},7657:function($,K,D){var j,B,X,O=D(9039),ie=D(4901),U=D(34),G=D(2360),Y=D(2787),Q=D(6840),oe=D(8227),ee=D(6395),ge=oe("iterator"),ce=!1;[].keys&&("next"in(X=[].keys())?(B=Y(Y(X)))!==Object.prototype&&(j=B):ce=!0),!U(j)||O((function(){var le={};return j[ge].call(le)!==le}))?j={}:ee&&(j=G(j)),ie(j[ge])||Q(j,ge,(function(){return this})),$.exports={IteratorPrototype:j,BUGGY_SAFARI_ITERATORS:ce}},6269:function($){$.exports={}},6198:function($,K,D){var j=D(8014);$.exports=function(B){return j(B.length)}},283:function($,K,D){var j=D(9504),B=D(9039),X=D(4901),O=D(9297),ie=D(3724),U=D(350).CONFIGURABLE,G=D(3706),Y=D(1181),Q=Y.enforce,oe=Y.get,ee=String,ge=Object.defineProperty,ce=j("".slice),le=j("".replace),q=j([].join),R=ie&&!B((function(){return ge((function(){}),"length",{value:8}).length!==8})),ne=String(String).split("String"),xe=$.exports=function(we,Ne,ve){ce(ee(Ne),0,7)==="Symbol("&&(Ne="["+le(ee(Ne),/^Symbol\(([^)]*)\).*$/,"$1")+"]"),ve&&ve.getter&&(Ne="get "+Ne),ve&&ve.setter&&(Ne="set "+Ne),(!O(we,"name")||U&&we.name!==Ne)&&(ie?ge(we,"name",{value:Ne,configurable:!0}):we.name=Ne),R&&ve&&O(ve,"arity")&&we.length!==ve.arity&&ge(we,"length",{value:ve.arity});try{ve&&O(ve,"constructor")&&ve.constructor?ie&&ge(we,"prototype",{writable:!1}):we.prototype&&(we.prototype=void 0)}catch{}var be=Q(we);return O(be,"source")||(be.source=q(ne,typeof Ne=="string"?Ne:"")),we};Function.prototype.toString=xe((function(){return X(this)&&oe(this).source||G(this)}),"toString")},741:function($){var K=Math.ceil,D=Math.floor;$.exports=Math.trunc||function(j){var B=+j;return(B>0?D:K)(B)}},7819:function($,K,D){var j=D(9039);$.exports=!j((function(){var B="9007199254740993",X=JSON.rawJSON(B);return!JSON.isRawJSON(X)||JSON.stringify(X)!==B}))},5749:function($,K,D){var j=D(788),B=TypeError;$.exports=function(X){if(j(X))throw new B("The method doesn't accept regular expressions");return X}},4213:function($,K,D){var j=D(3724),B=D(9504),X=D(9565),O=D(9039),ie=D(1072),U=D(3717),G=D(8773),Y=D(8981),Q=D(7055),oe=Object.assign,ee=Object.defineProperty,ge=B([].concat);$.exports=!oe||O((function(){if(j&&oe({b:1},oe(ee({},"a",{enumerable:!0,get:function(){ee(this,"b",{value:3,enumerable:!1})}}),{b:2})).b!==1)return!0;var ce={},le={},q=Symbol("assign detection"),R="abcdefghijklmnopqrst";return ce[q]=7,R.split("").forEach((function(ne){le[ne]=ne})),oe({},ce)[q]!==7||ie(oe({},le)).join("")!==R}))?function(ce,le){for(var q=Y(ce),R=arguments.length,ne=1,xe=U.f,we=G.f;R>ne;)for(var Ne,ve=Q(arguments[ne++]),be=xe?ge(ie(ve),xe(ve)):ie(ve),Ee=be.length,ze=0;Ee>ze;)Ne=be[ze++],j&&!X(we,ve,Ne)||(q[Ne]=ve[Ne]);return q}:oe},2360:function($,K,D){var j,B=D(8551),X=D(6801),O=D(8727),ie=D(421),U=D(397),G=D(4055),Y=D(6119),Q="prototype",oe="script",ee=Y("IE_PROTO"),ge=function(){},ce=function(R){return"<"+oe+">"+R+""+oe+">"},le=function(R){R.write(ce("")),R.close();var ne=R.parentWindow.Object;return R=null,ne},q=function(){try{j=new ActiveXObject("htmlfile")}catch{}var R,ne,xe;q=typeof document<"u"?document.domain&&j?le(j):(ne=G("iframe"),xe="java"+oe+":",ne.style.display="none",U.appendChild(ne),ne.src=String(xe),(R=ne.contentWindow.document).open(),R.write(ce("document.F=Object")),R.close(),R.F):le(j);for(var we=O.length;we--;)delete q[Q][O[we]];return q()};ie[ee]=!0,$.exports=Object.create||function(R,ne){var xe;return R!==null?(ge[Q]=B(R),xe=new ge,ge[Q]=null,xe[ee]=R):xe=q(),ne===void 0?xe:X.f(xe,ne)}},6801:function($,K,D){var j=D(3724),B=D(8686),X=D(4913),O=D(8551),ie=D(5397),U=D(1072);K.f=j&&!B?Object.defineProperties:function(G,Y){O(G);for(var Q,oe=ie(Y),ee=U(Y),ge=ee.length,ce=0;ge>ce;)X.f(G,Q=ee[ce++],oe[Q]);return G}},4913:function($,K,D){var j=D(3724),B=D(5917),X=D(8686),O=D(8551),ie=D(6969),U=TypeError,G=Object.defineProperty,Y=Object.getOwnPropertyDescriptor,Q="enumerable",oe="configurable",ee="writable";K.f=j?X?function(ge,ce,le){if(O(ge),ce=ie(ce),O(le),typeof ge=="function"&&ce==="prototype"&&"value"in le&&ee in le&&!le[ee]){var q=Y(ge,ce);q&&q[ee]&&(ge[ce]=le.value,le={configurable:oe in le?le[oe]:q[oe],enumerable:Q in le?le[Q]:q[Q],writable:!1})}return G(ge,ce,le)}:G:function(ge,ce,le){if(O(ge),ce=ie(ce),O(le),B)try{return G(ge,ce,le)}catch{}if("get"in le||"set"in le)throw new U("Accessors not supported");return"value"in le&&(ge[ce]=le.value),ge}},7347:function($,K,D){var j=D(3724),B=D(9565),X=D(8773),O=D(6980),ie=D(5397),U=D(6969),G=D(9297),Y=D(5917),Q=Object.getOwnPropertyDescriptor;K.f=j?Q:function(oe,ee){if(oe=ie(oe),ee=U(ee),Y)try{return Q(oe,ee)}catch{}if(G(oe,ee))return O(!B(X.f,oe,ee),oe[ee])}},298:function($,K,D){var j=D(2195),B=D(5397),X=D(8480).f,O=D(7680),ie=typeof window=="object"&&window&&Object.getOwnPropertyNames?Object.getOwnPropertyNames(window):[];$.exports.f=function(U){return ie&&j(U)==="Window"?(function(G){try{return X(G)}catch{return O(ie)}})(U):X(B(U))}},8480:function($,K,D){var j=D(1828),B=D(8727).concat("length","prototype");K.f=Object.getOwnPropertyNames||function(X){return j(X,B)}},3717:function($,K){K.f=Object.getOwnPropertySymbols},2787:function($,K,D){var j=D(9297),B=D(4901),X=D(8981),O=D(6119),ie=D(2211),U=O("IE_PROTO"),G=Object,Y=G.prototype;$.exports=ie?G.getPrototypeOf:function(Q){var oe=X(Q);if(j(oe,U))return oe[U];var ee=oe.constructor;return B(ee)&&oe instanceof ee?ee.prototype:oe instanceof G?Y:null}},1625:function($,K,D){var j=D(9504);$.exports=j({}.isPrototypeOf)},1828:function($,K,D){var j=D(9504),B=D(9297),X=D(5397),O=D(9617).indexOf,ie=D(421),U=j([].push);$.exports=function(G,Y){var Q,oe=X(G),ee=0,ge=[];for(Q in oe)!B(ie,Q)&&B(oe,Q)&&U(ge,Q);for(;Y.length>ee;)B(oe,Q=Y[ee++])&&(~O(ge,Q)||U(ge,Q));return ge}},1072:function($,K,D){var j=D(1828),B=D(8727);$.exports=Object.keys||function(X){return j(X,B)}},8773:function($,K){var D={}.propertyIsEnumerable,j=Object.getOwnPropertyDescriptor,B=j&&!D.call({1:2},1);K.f=B?function(X){var O=j(this,X);return!!O&&O.enumerable}:D},2551:function($,K,D){var j=D(6395),B=D(4576),X=D(9039),O=D(3607);$.exports=j||!X((function(){if(!(O&&O<535)){var ie=Math.random();__defineSetter__.call(null,ie,(function(){})),delete B[ie]}}))},2967:function($,K,D){var j=D(6706),B=D(34),X=D(7750),O=D(3506);$.exports=Object.setPrototypeOf||("__proto__"in{}?(function(){var ie,U=!1,G={};try{(ie=j(Object.prototype,"__proto__","set"))(G,[]),U=G instanceof Array}catch{}return function(Y,Q){return X(Y),O(Q),B(Y)&&(U?ie(Y,Q):Y.__proto__=Q),Y}})():void 0)},3179:function($,K,D){var j=D(2140),B=D(6955);$.exports=j?{}.toString:function(){return"[object "+B(this)+"]"}},4270:function($,K,D){var j=D(9565),B=D(4901),X=D(34),O=TypeError;$.exports=function(ie,U){var G,Y;if(U==="string"&&B(G=ie.toString)&&!X(Y=j(G,ie))||B(G=ie.valueOf)&&!X(Y=j(G,ie))||U!=="string"&&B(G=ie.toString)&&!X(Y=j(G,ie)))return Y;throw new O("Can't convert object to primitive value")}},5031:function($,K,D){var j=D(7751),B=D(9504),X=D(8480),O=D(3717),ie=D(8551),U=B([].concat);$.exports=j("Reflect","ownKeys")||function(G){var Y=X.f(ie(G)),Q=O.f;return Q?U(Y,Q(G)):Y}},8235:function($,K,D){var j=D(9504),B=D(9297),X=SyntaxError,O=parseInt,ie=String.fromCharCode,U=j("".charAt),G=j("".slice),Y=j(/./.exec),Q={'\\"':'"',"\\\\":"\\","\\/":"/","\\b":"\b","\\f":"\f","\\n":`
`,"\\r":"\r","\\t":" "},oe=/^[\da-f]{4}$/i,ee=/^[\u0000-\u001F]$/;$.exports=function(ge,ce){for(var le=!0,q="";ce0&&(!Re.multiline||Re.multiline&&R(Ce,Re.lastIndex-1)!==`
diff --git a/static/index.html b/static/index.html
index 33bf59243..aa413eaaa 100644
--- a/static/index.html
+++ b/static/index.html
@@ -26,7 +26,7 @@
-
+