diff --git a/backend/app/api/routes/print_queue.py b/backend/app/api/routes/print_queue.py index 16fd7ab7c..bc1e3bb56 100644 --- a/backend/app/api/routes/print_queue.py +++ b/backend/app/api/routes/print_queue.py @@ -199,6 +199,7 @@ def _enrich_response(item: PrintQueueItem) -> PrintQueueItemResponse: "auto_off_after": item.auto_off_after, "manual_start": item.manual_start, "filament_short": bool(item.filament_short), + "skip_filament_check": bool(item.skip_filament_check), "ams_mapping": ams_mapping_parsed, "plate_id": item.plate_id, "bed_levelling": item.bed_levelling, @@ -539,6 +540,7 @@ async def add_to_queue( require_previous_success=data.require_previous_success, auto_off_after=data.auto_off_after, manual_start=data.manual_start, + skip_filament_check=data.skip_filament_check, ams_mapping=ams_mapping_json, plate_id=data.plate_id, bed_levelling=data.bed_levelling, @@ -1096,6 +1098,12 @@ async def start_queue_item( # Print Anyway / no deficit: clear the flags and let the scheduler dispatch. item.manual_start = False item.filament_short = False + # Persist the user's "Print Anyway" decision so the scheduler does not + # immediately re-flag this item on the next tick (#1698-followup). The + # pre-fix behaviour bounced between "user said anyway" and + # "scheduler re-blocked on same deficit" forever. + if skip_filament_check: + item.skip_filament_check = True # Credit the clicker as the item's owner when no prior owner is set — # VP-uploaded queue items arrive over FTP unattributed, so without this # the print log's User column stays blank even when auth is on diff --git a/backend/app/core/database.py b/backend/app/core/database.py index 4bcee6688..476835d2d 100644 --- a/backend/app/core/database.py +++ b/backend/app/core/database.py @@ -935,6 +935,17 @@ async def run_migrations(conn): else: await _safe_execute(conn, "ALTER TABLE print_queue ADD COLUMN filament_short BOOLEAN DEFAULT false") + # Migration: skip_filament_check flag on print_queue (#1698-followup). + # Persists the user's "Print Anyway" acknowledgement so the scheduler + # doesn't re-flag the item every tick after they've confirmed dispatch + # despite the deficit warning. Set from the start route's skip_filament_check + # query param and from PrintModal at queue-creation time. Postgres / SQLite + # boolean default branch matches filament_short above. + if is_sqlite(): + await _safe_execute(conn, "ALTER TABLE print_queue ADD COLUMN skip_filament_check BOOLEAN DEFAULT 0") + else: + await _safe_execute(conn, "ALTER TABLE print_queue ADD COLUMN skip_filament_check BOOLEAN DEFAULT false") + # Migration: Add queue_force_color_match column to virtual_printers (#1188). # Opt-in flag: when true, VP queue-mode uploads pin the per-slot type+color # from the 3MF onto the queue item's filament_overrides so the scheduler diff --git a/backend/app/models/print_queue.py b/backend/app/models/print_queue.py index 07806234c..21b156f06 100644 --- a/backend/app/models/print_queue.py +++ b/backend/app/models/print_queue.py @@ -85,6 +85,14 @@ class PrintQueueItem(Base): # block automatically. filament_short: Mapped[bool] = mapped_column(Boolean, default=False) + # User has acknowledged the filament-shortage warning for this item + # ("Print Anyway"). Set by the start route when the user passes + # skip_filament_check=true, or at queue-creation time if PrintModal's + # frontend deficit warning was acknowledged. Survives scheduler ticks so + # the dispatch no longer bounces between "user said anyway" and + # "scheduler re-flagged" (#1698-followup). + skip_filament_check: Mapped[bool] = mapped_column(Boolean, default=False) + # Tracking started_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True) completed_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True) diff --git a/backend/app/schemas/print_queue.py b/backend/app/schemas/print_queue.py index d16c2ad0a..2decf8cbc 100644 --- a/backend/app/schemas/print_queue.py +++ b/backend/app/schemas/print_queue.py @@ -28,6 +28,10 @@ class PrintQueueItemCreate(BaseModel): require_previous_success: bool = False auto_off_after: bool = False # Power off printer after print completes manual_start: bool = False # Requires manual trigger to start (staged) + # Persistent "Print Anyway" acknowledgement (#1698-followup). When set, + # PrintModal already showed the deficit warning and the user confirmed, + # so the scheduler does not re-flag this item on the next tick. + skip_filament_check: bool = False # AMS mapping: list of global tray IDs for each filament slot # Format: [5, -1, 2, -1] where position = slot_id-1, value = global tray ID (-1 = unused) ams_mapping: list[int] | None = None @@ -96,6 +100,9 @@ class PrintQueueItemResponse(BaseModel): # (#1496). Display-only — the ▶ click recomputes deficit against live # spool state. filament_short: bool = False + # User has acknowledged "Print Anyway" — scheduler skips the deficit check + # for this item (#1698-followup). + skip_filament_check: bool = False ams_mapping: list[int] | None = None plate_id: int | None = None # Plate ID for multi-plate 3MF files # Print options diff --git a/backend/app/services/print_scheduler.py b/backend/app/services/print_scheduler.py index fcc723778..f3c0eba6c 100644 --- a/backend/app/services/print_scheduler.py +++ b/backend/app/services/print_scheduler.py @@ -1846,6 +1846,14 @@ class PrintScheduler: since been swapped to one with enough material clears the flag here so the next scheduler tick dispatches it. """ + # User has explicitly acknowledged the deficit ("Print Anyway") — + # don't re-flag, don't even compute. Without this short-circuit the + # scheduler bounces between "user said anyway" (route clears + # manual_start) and "scheduler re-blocked" (this method re-flags it + # on identical spool state) (#1698-followup). + if item.skip_filament_check: + return False + try: deficit = await compute_deficit_for_queue_item(db, item) except Exception as e: diff --git a/backend/tests/integration/test_print_queue_api.py b/backend/tests/integration/test_print_queue_api.py index d5e3454c4..ba900ff16 100644 --- a/backend/tests/integration/test_print_queue_api.py +++ b/backend/tests/integration/test_print_queue_api.py @@ -147,6 +147,40 @@ class TestPrintQueueAPI: assert result["status"] == "pending" assert result["manual_start"] is True + @pytest.mark.asyncio + @pytest.mark.integration + async def test_add_to_queue_with_skip_filament_check( + self, async_client: AsyncClient, printer_factory, archive_factory, db_session + ): + """PrintModal "Print Anyway" persists skip_filament_check on creation (#1698-followup).""" + printer = await printer_factory() + archive = await archive_factory() + + data = { + "printer_id": printer.id, + "archive_id": archive.id, + "skip_filament_check": True, + } + response = await async_client.post("/api/v1/queue/", json=data) + assert response.status_code == 200 + result = response.json() + assert result["skip_filament_check"] is True + + @pytest.mark.asyncio + @pytest.mark.integration + async def test_add_to_queue_skip_filament_check_defaults_false( + self, async_client: AsyncClient, printer_factory, archive_factory, db_session + ): + """Default add-to-queue has skip_filament_check=False — no silent bypass.""" + printer = await printer_factory() + archive = await archive_factory() + + data = {"printer_id": printer.id, "archive_id": archive.id} + response = await async_client.post("/api/v1/queue/", json=data) + assert response.status_code == 200 + result = response.json() + assert result["skip_filament_check"] is False + @pytest.mark.asyncio @pytest.mark.integration async def test_add_to_queue_with_project_id( @@ -583,6 +617,53 @@ class TestQueueStartEndpoint: # decision to print anyway. assert called_with == {} + @pytest.mark.asyncio + @pytest.mark.integration + async def test_start_with_skip_flag_persists_acknowledgement( + self, + async_client: AsyncClient, + queue_item_factory, + db_session, + ): + """skip_filament_check=true sets the persistent flag on the queue item + so the scheduler doesn't re-flag it on the next tick (#1698-followup). + + Without persistence the route's flag-clearing only survives until the + next scheduler tick re-runs the deficit check on identical spool + state and re-promotes the item — the user has to click Play+Confirm + every single tick. + """ + item = await queue_item_factory(manual_start=True, filament_short=True) + assert item.skip_filament_check is False + + response = await async_client.post(f"/api/v1/queue/{item.id}/start?skip_filament_check=true") + assert response.status_code == 200 + body = response.json() + assert body["skip_filament_check"] is True + + await db_session.refresh(item) + assert item.skip_filament_check is True + + @pytest.mark.asyncio + @pytest.mark.integration + async def test_start_without_skip_flag_does_not_set_acknowledgement( + self, + async_client: AsyncClient, + queue_item_factory, + db_session, + ): + """A successful Play click with no deficit must NOT silently set the + acknowledgement flag — only an explicit Print Anyway should. + """ + item = await queue_item_factory(manual_start=False, filament_short=False) + assert item.skip_filament_check is False + + response = await async_client.post(f"/api/v1/queue/{item.id}/start") + assert response.status_code == 200 + + await db_session.refresh(item) + assert item.skip_filament_check is False + class TestQueueCancelEndpoint: """Tests for the /queue/{item_id}/cancel endpoint.""" diff --git a/backend/tests/unit/test_scheduler_filament_deficit.py b/backend/tests/unit/test_scheduler_filament_deficit.py index d198ba955..30e74bc1c 100644 --- a/backend/tests/unit/test_scheduler_filament_deficit.py +++ b/backend/tests/unit/test_scheduler_filament_deficit.py @@ -117,3 +117,41 @@ async def test_helper_exception_does_not_wedge_dispatch(scheduler, db_session, q assert blocked is False await db_session.refresh(item) assert item.filament_short is False + + +@pytest.mark.asyncio +async def test_skip_filament_check_short_circuits_without_compute(scheduler, db_session, queue_item): + """User clicked Print Anyway (skip_filament_check=True): no compute, no flag (#1698-followup). + + Pre-fix the scheduler re-ran the deficit check on every tick, re-set + manual_start/filament_short to True, and the item bounced between + "user said anyway" (route clears flags) and "scheduler re-blocked" + forever. With the persistent acknowledgement flag the scheduler bails + early without even touching the deficit helper. + """ + item = await queue_item(skip_filament_check=True) + compute_mock = AsyncMock( + return_value=[ + FilamentDeficit( + slot_id=1, + ams_id=0, + tray_id=0, + filament_type="PLA", + required_grams=270.0, + remaining_grams=200.0, + ), + ] + ) + with patch( + "backend.app.services.print_scheduler.compute_deficit_for_queue_item", + compute_mock, + ): + blocked = await scheduler._block_on_filament_deficit(db_session, item) + + assert blocked is False + compute_mock.assert_not_awaited() + await db_session.refresh(item) + # Flags must not get re-set by the scheduler now that the user has + # acknowledged the deficit. + assert item.filament_short is False + assert item.manual_start is False diff --git a/frontend/src/api/client.ts b/frontend/src/api/client.ts index 056038291..de0499e72 100644 --- a/frontend/src/api/client.ts +++ b/frontend/src/api/client.ts @@ -1898,6 +1898,11 @@ export interface PrintQueueItem { // any required slot's grams (#1496). Surfaced on the queue row as a // "filament short" badge; cleared on a successful ▶ click (live recheck). filament_short: boolean; + // Persistent "Print Anyway" acknowledgement — once true the scheduler + // skips the deficit check for this item (#1698-followup). Set by the + // start route when skip_filament_check=true, or at queue creation if + // PrintModal's deficit warning was acknowledged. + skip_filament_check: boolean; ams_mapping: number[] | null; // AMS slot mapping for multi-color prints filament_overrides: Array<{ slot_id: number; type: string; color: string; color_name?: string; force_color_match?: boolean }> | null; // Filament overrides for model-based assignment plate_id: number | null; // Plate ID for multi-plate 3MF files @@ -1966,6 +1971,9 @@ export interface PrintQueueItemCreate { require_previous_success?: boolean; auto_off_after?: boolean; manual_start?: boolean; // Requires manual trigger to start (staged) + // PrintModal "Print Anyway" on the deficit warning — persisted so the + // scheduler doesn't immediately re-flag this item (#1698-followup). + skip_filament_check?: boolean; ams_mapping?: number[] | null; // AMS slot mapping for multi-color prints plate_id?: number | null; // Plate ID for multi-plate 3MF files // Print options diff --git a/frontend/src/components/PrintModal/index.tsx b/frontend/src/components/PrintModal/index.tsx index aeeab753a..fefbd60e7 100644 --- a/frontend/src/components/PrintModal/index.tsx +++ b/frontend/src/components/PrintModal/index.tsx @@ -653,6 +653,10 @@ export function PrintModal({ auto_off_after: scheduleOptions.autoOffAfter, gcode_injection: scheduleOptions.gcodeInjection, manual_start: scheduleOptions.scheduleType === 'manual', + // When the user clicks "Print Anyway" on the frontend deficit warning, + // persist that acknowledgement so the scheduler doesn't immediately + // re-flag the item on its first dispatch tick (#1698-followup). + skip_filament_check: options?.skipFilamentCheck === true ? true : undefined, ams_mapping: printerId ? getMappingForPrinter(printerId) : undefined, plate_id: plateOverride !== undefined ? plateOverride : selectedPlate, scheduled_time: scheduleOptions.scheduleType === 'scheduled' && scheduleOptions.scheduledTime diff --git a/static/assets/index-lEQPGYKn.js b/static/assets/index-Dx3eHcCx.js similarity index 99% rename from static/assets/index-lEQPGYKn.js rename to static/assets/index-Dx3eHcCx.js index c5c4c4245..25ab3df00 100644 --- a/static/assets/index-lEQPGYKn.js +++ b/static/assets/index-Dx3eHcCx.js @@ -8515,7 +8515,7 @@ ${l("inventory.assignProfileMismatchMessage",{spoolProfile:T.spoolProfile||l("co ${l("inventory.assignProfileMismatchMessage",{spoolProfile:T.spoolProfile||l("common.unknown"),trayProfile:T.trayProfile||l("common.unknown"),location:s.location})}`),A=`${A} ${l("inventory.assignReconfigureNote")}`,r.jsx(wa,{title:l("inventory.assignMismatchTitle"),message:A,confirmText:l("inventory.assignMismatchConfirm"),variant:"warning",overlayZIndex:"z-[110]",isLoading:X.isPending,onConfirm:Q,onCancel:()=>{X.isPending||(N(!1),k(null),j(null))}})})()]})}const p9e={process:new Map,filament:new Map,bambuModelByShortCode:{}};function yse(t){return t.replace(/^#\s*/,"").trim()}const eY={"A1 MINI":["A1M"]};function Pz(t,e){const a=t.toUpperCase(),n=e.toUpperCase();if(a===n)return!0;const i=eY[n];if(i&&i.includes(a))return!0;const s=eY[a];return!!(s&&s.includes(n))}function h9e(t){const e={};for(const[a,n]of Object.entries(t))n in e||(e[n]=a.replace(/^Bambu Lab\s+/,""));return e}function f9e(t,e={}){const a=new Map,n=new Map,i=(s,o,l)=>{const c=yse(o);if(!c)return;const d=s.get(c)??new Set;d.add(l),s.set(c,d)};for(const s of t){const o=s.printer_preset_name?.trim();if(o){for(const l of s.process)i(a,l,o);for(const l of s.filament)i(n,l,o)}}return{process:a,filament:n,bambuModelByShortCode:h9e(e)}}function tY(t){return t.replace(/\s+/g,"").toLowerCase()}const g9e="0.4";function vse(t){const e=t.match(/^(.*?)\s+([\d.]+)\s*nozzle\s*$/i);return e?{stripped:e[1].trim(),nozzle:e[2]}:{stripped:t.trim(),nozzle:null}}function b9e(t){const e="@BBL ",a=t.indexOf(e);if(a<0)return null;const n=t.slice(a+e.length).trim(),{stripped:i,nozzle:s}=vse(n);return i?{token:i,nozzle:s}:null}function x9e(t){const e=t.match(/^Bambu Lab\s+(.+)$/i);if(!e)return null;const{stripped:a,nozzle:n}=vse(e[1]);return a?{model:a,nozzle:n}:null}function y9e(t,e,a){const n=b9e(t);if(!n)return"unknown";const i=a[n.token]??n.token,s=x9e(e);return s?tY(s.model)!==tY(i)&&!Pz(n.token,s.model)||s.nozzle!==null&&(n.nozzle??g9e)!==s.nozzle?"mismatch":"match":"unknown"}function Uy(t,e,a,n){if(!a)return"unknown";const i=t.compatible_printers;if(i&&i.length>0)return i.includes(a)?"match":"mismatch";const s=n[e].get(yse(t.name));return s&&s.size>0?s.has(a)?"match":"mismatch":y9e(t.name,a,n.bambuModelByShortCode)}const wse=["PLA","PETG","ABS","TPU","ASA","PC","PA","PVA","HIPS","PA-CF","PETG-CF","PLA-CF"],v9e=["Bambu","PolyLite","PolyTerra","eSUN","Overture","Fiberon","SUNLU","Inland","Hatchbox","Generic"],fw=["Basic","Matte","Silk","Silk+","Tough","Tough+","HF","High Flow","Engineering","CF","GF","Galaxy","Glow","Marble","Metal","Rainbow","Sparkle","Wood","Translucent","Transparent","Clear","Lite","Pro","Plus","Max","Super","Ultra","Flex","Soft","Hard","Strong","Impact","Heat Resistant","UV Resistant","ESD","Conductive","Magnetic","Gradient","Dual Color","Tri Color","Multicolor"],Sse=[{name:"Black",hex:"000000"},{name:"White",hex:"FFFFFF"},{name:"Gray",hex:"808080"},{name:"Red",hex:"FF0000"},{name:"Orange",hex:"FFA500"},{name:"Yellow",hex:"FFFF00"},{name:"Green",hex:"00AE42"},{name:"Blue",hex:"0066FF"},{name:"Purple",hex:"8B00FF"},{name:"Pink",hex:"FF69B4"},{name:"Brown",hex:"8B4513"},{name:"Silver",hex:"C0C0C0"},{name:"Clear",hex:"00000000"}],w9e=[{name:"Dark Red",hex:"8B0000"},{name:"Crimson",hex:"DC143C"},{name:"Coral",hex:"FF7F50"},{name:"Salmon",hex:"FA8072"},{name:"Dark Orange",hex:"FF8C00"},{name:"Peach",hex:"FFDAB9"},{name:"Gold",hex:"FFD700"},{name:"Khaki",hex:"F0E68C"},{name:"Lemon",hex:"FFF44F"},{name:"Lime",hex:"32CD32"},{name:"Forest Green",hex:"228B22"},{name:"Olive",hex:"808000"},{name:"Mint",hex:"98FF98"},{name:"Teal",hex:"008080"},{name:"Navy",hex:"000080"},{name:"Sky Blue",hex:"87CEEB"},{name:"Royal Blue",hex:"4169E1"},{name:"Cyan",hex:"00FFFF"},{name:"Turquoise",hex:"40E0D0"},{name:"Violet",hex:"EE82EE"},{name:"Magenta",hex:"FF00FF"},{name:"Indigo",hex:"4B0082"},{name:"Lavender",hex:"E6E6FA"},{name:"Plum",hex:"DDA0DD"},{name:"Hot Pink",hex:"FF69B4"},{name:"Rose",hex:"FF007F"},{name:"Blush",hex:"FFB6C1"},{name:"Chocolate",hex:"D2691E"},{name:"Tan",hex:"D2B48C"},{name:"Beige",hex:"F5F5DC"},{name:"Maroon",hex:"800000"},{name:"Dark Gray",hex:"404040"},{name:"Light Gray",hex:"D3D3D3"},{name:"Charcoal",hex:"36454F"},{name:"Ivory",hex:"FFFFF0"},{name:"Bambu Green",hex:"00AE42"},{name:"Jade White",hex:"E8E8E8"},{name:"Titan Gray",hex:"5A5A5A"}],aY=[...Sse,...w9e],kse="bambuddy-recent-colors",S9e=8,k9e=[{code:"GFL00",name:"Bambu PLA Basic",displayName:"Bambu PLA Basic",isCustom:!1,allCodes:["GFL00"]},{code:"GFL01",name:"Bambu PLA Matte",displayName:"Bambu PLA Matte",isCustom:!1,allCodes:["GFL01"]},{code:"GFL05",name:"Generic PLA",displayName:"Generic PLA",isCustom:!1,allCodes:["GFL05"]},{code:"GFG00",name:"Bambu PETG Basic",displayName:"Bambu PETG Basic",isCustom:!1,allCodes:["GFG00"]},{code:"GFG05",name:"Generic PETG",displayName:"Generic PETG",isCustom:!1,allCodes:["GFG05"]},{code:"GFB00",name:"Bambu ABS Basic",displayName:"Bambu ABS Basic",isCustom:!1,allCodes:["GFB00"]},{code:"GFB05",name:"Generic ABS",displayName:"Generic ABS",isCustom:!1,allCodes:["GFB05"]},{code:"GFA00",name:"Bambu ASA Basic",displayName:"Bambu ASA Basic",isCustom:!1,allCodes:["GFA00"]},{code:"GFU00",name:"Bambu TPU 95A",displayName:"Bambu TPU 95A",isCustom:!1,allCodes:["GFU00"]},{code:"GFU05",name:"Generic TPU",displayName:"Generic TPU",isCustom:!1,allCodes:["GFU05"]},{code:"GFC00",name:"Bambu PC Basic",displayName:"Bambu PC Basic",isCustom:!1,allCodes:["GFC00"]},{code:"GFN00",name:"Bambu PA Basic",displayName:"Bambu PA Basic",isCustom:!1,allCodes:["GFN00"]},{code:"GFN05",name:"Generic PA",displayName:"Generic PA",isCustom:!1,allCodes:["GFN05"]},{code:"GFS00",name:"Bambu PLA-CF",displayName:"Bambu PLA-CF",isCustom:!1,allCodes:["GFS00"]},{code:"GFT00",name:"Bambu PETG-CF",displayName:"Bambu PETG-CF",isCustom:!1,allCodes:["GFT00"]},{code:"GFNC0",name:"Bambu PA-CF",displayName:"Bambu PA-CF",isCustom:!1,allCodes:["GFNC0"]},{code:"GFV00",name:"Bambu PVA",displayName:"Bambu PVA",isCustom:!1,allCodes:["GFV00"]}];function of(t){let e=t.replace(/@.*$/,"").trim();e=e.replace(/\(Custom\)/i,"").trim(),e=e.replace(/^[#*]+\s*/,"").trim();const a=["PLA-CF","PETG-CF","ABS-GF","ASA-CF","PA-CF","PAHT-CF","PA6-CF","PA6-GF","PPA-CF","PPA-GF","PET-CF","PPS-CF","PC-CF","PC-ABS","ABS-GF","PCTG","PETG","PLA","ABS","ASA","PC","PA","TPU","PVA","HIPS","BVOH","PPS","PEEK","PEI"];let n="",i=-1;for(const c of a){const d=e.toUpperCase().indexOf(c.toUpperCase());if(d!==-1){n=c,i=d;break}}let s="";i>0&&(s=e.substring(0,i).trim(),s=s.replace(/[-_\s]+$/,""));let o="";i!==-1&&n&&(o=e.substring(i+n.length).trim(),o=o.replace(/^[-_\s]+/,""));let l="";for(const c of fw)if(o.toLowerCase().includes(c.toLowerCase())){l=c;break}if(!l&&s)for(const c of fw){const d=new RegExp(`\\s+${c}$`,"i");if(d.test(s)){l=c,s=s.replace(d,"").trim();break}}return{brand:s,material:n,variant:l}}function _se(t,e){const a=new Set(v9e);for(const n of t){const{brand:i}=of(n.name);i&&i.length>1&&a.add(i)}if(e)for(const n of e)if(n.filament_vendor&&n.filament_vendor.length>1)a.add(n.filament_vendor);else{const{brand:i}=of(n.name);i&&i.length>1&&a.add(i)}return Array.from(a).sort((n,i)=>n.localeCompare(i))}function _9e(t){const e=t.filter(n=>n.preset_type==="filament");return e.length===0?[]:e.map(n=>{const i=String(n.id),s=n.filament_type||i,o=Array.from(new Set([i,s]));return{code:i,name:n.name,displayName:n.name,isCustom:!1,allCodes:o}}).sort((n,i)=>n.displayName.localeCompare(i.displayName))}function Pse(t,e,a,n){const i=[],s=[],o=new Set;for(const u of t)if(u.is_custom){const m=u.name.toUpperCase();(e.size===0||Array.from(e).some(f=>m.includes(f))||!m.includes("@"))&&(i.push({code:u.setting_id,name:u.name,displayName:`${u.name} (Custom)`,isCustom:!0,allCodes:[u.setting_id]}),o.add(u.setting_id))}else s.push({code:u.setting_id,name:u.name,displayName:u.name,isCustom:!1,allCodes:[u.setting_id]}),o.add(u.setting_id);const l=a&&a.length>0?_9e(a):[],c=[];if(n&&n.length>0)for(const u of n){const m=u.filament_id.startsWith("GF")?"GFS"+u.filament_id.slice(2):u.filament_id;o.has(u.filament_id)||o.has(m)||c.push({code:u.filament_id,name:u.name,displayName:u.name,isCustom:!1,allCodes:[u.filament_id,m]})}const d=[...i,...s,...l,...c];return d.length===0?k9e:d.sort((u,m)=>u.displayName.localeCompare(m.displayName))}function Cse(t,e){if(!t)return;let a=e.find(n=>n.code===t);if(a||(a=e.find(n=>n.allCodes.includes(t))),!a){const n=t.toLowerCase();a=e.find(i=>i.code.toLowerCase()===n||i.allCodes.some(s=>s.toLowerCase()===n))}return a}function Nse(){try{const t=localStorage.getItem(kse);if(t)return JSON.parse(t)}catch{}return[]}function Tse(t,e){const a=e.filter(i=>i.hex.toUpperCase()!==t.hex.toUpperCase()),n=[t,...a].slice(0,S9e);try{localStorage.setItem(kse,JSON.stringify(n))}catch{}return n}function gw(t){if(!t)return"";let e=t.split("_")[0];return/^GFS/i.test(e)&&(e=e.slice(0,2)+e.slice(3)),e.toUpperCase()}function Ase(t){return!!t&&/^GF[A-Z]99$/i.test(t)}function PF(t,e){if(!e.material)return!1;const a=gw(e.slicer_filament),n=gw(t.filament_id);if(a&&n&&a===n&&!Ase(n))return!0;const s=(t.name||"").replace(/^High Flow[_\s]+/i,"").replace(/^Standard[_\s]+/i,"").replace(/^HF[_\s]+/i,"").replace(/^S[_\s]+/i,"").trim(),o=of(s);return!(!(o.material.toUpperCase()===e.material.toUpperCase())||e.brand&&!(o.brand.toLowerCase().includes(e.brand.toLowerCase())||e.brand.toLowerCase().includes(o.brand.toLowerCase()))||e.subtype&&!(o.variant.toLowerCase().includes(e.subtype.toLowerCase())||e.subtype.toLowerCase().includes(o.variant.toLowerCase())||s.toLowerCase().includes(e.subtype.toLowerCase())))}function rY(t,e){if(t===255)return"External";let a,n=!1;t>=128&&t<=135?(a=t-128,n=!0):t>=0&&t<=3?(a=t,n=e===1):a=0,a=Math.max(0,Math.min(a,7));const i=String.fromCharCode(65+a);return n?`HT-${i}`:`AMS-${i}`}function CF(t){const e=t.includes("_")?t.split("_")[0]:t;return e.startsWith("GFS")?"GF"+e.slice(3):(e.startsWith("PFUS")||e.startsWith("PFSP"),e)}const cg=["PLA","PETG","PCTG","ABS","ASA","TPU","PC","PA","NYLON","PVA","HIPS","PP","PET"];function nY(t){const e=t.replace(/@.+$/,"").trim(),a=e.toUpperCase(),n=a.match(/\bSUPPORT\s+FOR\s+/);if(n){const s=a.slice(n.index+n[0].length);for(const o of cg)if(new RegExp(`\\b${o}\\b`).test(s)){const c=e.slice(0,n.index).trim();return{material:o,brand:c,variant:"Support"}}}for(const s of cg){const o=new RegExp(`\\b${s}\\b`,"i");if(o.test(a)){const l=e.split(o),c=l[0]?.trim()||"",d=l[1]?.trim()||"";return{material:s,brand:c,variant:d}}}const i=e.split(/\s+/);return i.length>=2?{material:i[1],brand:i[0],variant:i.slice(2).join(" ")}:{material:e,brand:"",variant:""}}function P9e(t){return!t.startsWith("GF")&&!t.startsWith("P1")}const C9e={white:"FFFFFF",black:"000000",red:"FF0000",green:"00FF00",blue:"0000FF",yellow:"FFFF00",cyan:"00FFFF",magenta:"FF00FF",orange:"FFA500",purple:"800080",pink:"FFC0CB",brown:"8B4513",gray:"808080",grey:"808080","jade white":"FFFEF2",ivory:"FFFFF0",beige:"F5F5DC",cream:"FFFDD0",silver:"C0C0C0",gold:"FFD700",bronze:"CD7F32",copper:"B87333",navy:"000080",teal:"008080",olive:"808000",maroon:"800000",coral:"FF7F50",salmon:"FA8072",lime:"32CD32",mint:"98FF98","forest green":"228B22","sky blue":"87CEEB","royal blue":"4169E1",turquoise:"40E0D0",lavender:"E6E6FA",violet:"EE82EE",plum:"DDA0DD",tan:"D2B48C",chocolate:"D2691E",charcoal:"36454F",slate:"708090",transparent:"000000",natural:"F5F5DC",wood:"DEB887"},iY=[{name:"White",hex:"FFFFFF"},{name:"Black",hex:"000000"},{name:"Red",hex:"FF0000"},{name:"Blue",hex:"0000FF"},{name:"Green",hex:"00AA00"},{name:"Yellow",hex:"FFFF00"},{name:"Orange",hex:"FFA500"},{name:"Gray",hex:"808080"}],sY=[{name:"Cyan",hex:"00FFFF"},{name:"Magenta",hex:"FF00FF"},{name:"Purple",hex:"800080"},{name:"Pink",hex:"FFC0CB"},{name:"Brown",hex:"8B4513"},{name:"Beige",hex:"F5F5DC"},{name:"Navy",hex:"000080"},{name:"Teal",hex:"008080"},{name:"Lime",hex:"32CD32"},{name:"Gold",hex:"FFD700"},{name:"Silver",hex:"C0C0C0"},{name:"Maroon",hex:"800000"},{name:"Olive",hex:"808000"},{name:"Coral",hex:"FF7F50"},{name:"Salmon",hex:"FA8072"},{name:"Turquoise",hex:"40E0D0"},{name:"Violet",hex:"EE82EE"},{name:"Indigo",hex:"4B0082"},{name:"Chocolate",hex:"D2691E"},{name:"Tan",hex:"D2B48C"},{name:"Slate",hex:"708090"},{name:"Charcoal",hex:"36454F"},{name:"Ivory",hex:"FFFFF0"},{name:"Cream",hex:"FFFDD0"}];function oY(t){const e=t.toLowerCase().trim();return C9e[e]||null}function lY(t){const e=t.indexOf("@");if(e<0)return null;const n=t.slice(e+1).trim().match(/^BBL\s+(.+?)(?:\s+[\d.]+\s*nozzle)?$/i);return n?n[1].trim():null}function jse({isOpen:t,onClose:e,printerId:a,slotInfo:n,nozzleDiameter:i="0.4",printerModel:s,onSuccess:o,fullScreen:l}){const{t:c}=wt(),[d,u]=y.useState(""),[m,p]=y.useState(null),[f,g]=y.useState(""),[v,b]=y.useState(""),[x,S]=y.useState(""),[k,C]=y.useState(!1),[N,T]=y.useState(!1),j=y.useRef(""),{data:D,isLoading:P,isError:E}=$e({queryKey:["cloudSettings"],queryFn:()=>ie.getCloudSettings(),enabled:t,retry:!1}),{data:z}=$e({queryKey:["orcaCloudProfilesForAmsSlot"],queryFn:()=>ie.orcaCloudListProfiles(),enabled:t,retry:!1}),{data:I,isLoading:O}=$e({queryKey:["localPresets"],queryFn:()=>ie.getLocalPresets(),enabled:t}),{data:R,isLoading:K}=$e({queryKey:["builtinFilaments"],queryFn:()=>ie.getBuiltinFilaments(),enabled:t,staleTime:1/0}),{data:J,isLoading:X}=$e({queryKey:["kprofiles",a,i],queryFn:()=>ie.getKProfiles(a,i),enabled:t&&!!a}),{data:ce}=$e({queryKey:["colorCatalog"],queryFn:()=>ie.getColorCatalog(),enabled:t,staleTime:1/0}),de=at({mutationFn:async()=>{if(!d)throw new Error("No filament preset selected");const U=d.startsWith("local_"),$=d.startsWith("builtin_"),H=d.startsWith("orca_")?d.replace("orca_",""):d,le=!U&&!$?z?.filament.find(ze=>ze.setting_id===H):void 0,B=!!le,q=le??null,Z=U?parseInt(d.replace("local_",""),10):null,ee=$?d.replace("builtin_",""):null,re=U?I?.filament.find(ze=>ze.id===Z):null,se=$?R?.find(ze=>ze.filament_id===ee):null,fe=!U&&!$&&!B?D?.filament.find(ze=>ze.setting_id===d):null;if(!U&&!$&&!B&&!fe)throw new Error("Selected preset not found");if(U&&!re)throw new Error("Selected local preset not found");if($&&!se)throw new Error("Selected builtin preset not found");if(B&&!q)throw new Error("Selected Orca Cloud preset not found");const ue=U?re.name:$?se.name:B?q.name:fe.name,he=nY(ue),G=m?.slot_id??-1,L=f||n.trayColor?.slice(0,6)||"FFFFFF",ae=ue.replace(/@.+$/,"").trim();let ge,be;const ve=he.material.toUpperCase(),De={PLA:"GFL99","PLA-CF":"GFL98","PLA SILK":"GFL96","PLA HIGH SPEED":"GFL95",PETG:"GFG99","PETG HF":"GFG96","PETG-CF":"GFG98",PCTG:"GFG97",ABS:"GFB99",ASA:"GFB98",PC:"GFC99",PA:"GFN99","PA-CF":"GFN98",NYLON:"GFN99",TPU:"GFU99",PVA:"GFS99",HIPS:"GFS98",PE:"GFP99",PP:"GFP97"};if(U){const ze=(cg.includes(ve)?ve:re?.filament_type||he.material||"").toUpperCase();ge=De[ze]||De[ze.replace(/[-\s]?CF$/,"")]||De[ze.replace(/\+$/,"")]||De[ze.split(/[-\s]/)[0]]||"",be=""}else if(B){const ze=(cg.includes(ve)?ve:he.material||"").toUpperCase();ge=De[ze]||De[ze.replace(/[-\s]?CF$/,"")]||De[ze.replace(/\+$/,"")]||De[ze.split(/[-\s]/)[0]]||"",be=""}else if($)ge=ee,be="";else if(ge=CF(d),be=d,!d.startsWith("GFS"))try{const ze=await ie.getCloudSettingDetail(d);ze.filament_id&&(ge=ze.filament_id)}catch(ze){console.warn("Failed to fetch preset detail for filament_id:",ze)}let Me=U&&re?.nozzle_temp_min?re.nozzle_temp_min:190,Te=U&&re?.nozzle_temp_max?re.nozzle_temp_max:230;if(!U||$||B||!re?.nozzle_temp_min&&!re?.nozzle_temp_max){const ze=(U?cg.includes(ve)?ve:re?.filament_type||he.material||"":he.material).toUpperCase();ze.includes("PLA")?(Me=190,Te=230):ze.includes("PETG")?(Me=220,Te=260):ze.includes("ABS")||ze.includes("ASA")?(Me=240,Te=280):ze.includes("TPU")?(Me=200,Te=240):ze==="PCTG"?(Me=220,Te=260):ze.includes("PC")?(Me=260,Te=300):(ze.includes("PA")||ze.includes("NYLON"))&&(Me=250,Te=290)}const Ue=m?.k_value?parseFloat(m.k_value):0,Ne=U?cg.includes(ve)?ve:re?.filament_type||he.material||"PLA":B&&cg.includes(ve)?ve:he.material||"PLA",Ie=await ie.configureAmsSlot(a,n.amsId,n.trayId,{tray_info_idx:ge,tray_type:Ne,tray_sub_brands:ae,tray_color:L+"FF",nozzle_temp_min:Me,nozzle_temp_max:Te,cali_idx:G,nozzle_diameter:i,setting_id:be,kprofile_filament_id:m?.filament_id,kprofile_setting_id:m?.setting_id||void 0,k_value:Ue}),Re=U?`local_${Z}`:$?`builtin_${ee}`:d,He=U?"local":$?"builtin":B?"orca_cloud":"cloud";try{await ie.saveSlotPreset(a,n.amsId,n.trayId,Re,ae,He)}catch(ze){console.warn("Failed to save slot preset mapping:",ze)}return Ie},onSuccess:()=>{C(!0),o?.(),setTimeout(()=>{C(!1),e()},1500)}}),oe=at({mutationFn:async()=>ie.resetAmsSlot(a,n.amsId,n.trayId),onSuccess:()=>{C(!0),o?.(),setTimeout(()=>{C(!1),e()},1500)}}),Y=y.useMemo(()=>{const U=x.toLowerCase(),$=[],H=new Set,le=n.savedPresetId,B=n.trayInfoIdx;if(z?.filament)for(const q of z.filament){const Z=`orca_${q.setting_id}`;if(H.add(q.setting_id),H.add(Z),!(U&&!q.name.toLowerCase().includes(U))){if(s){const ee=lY(q.name);if(ee&&!Pz(ee,s))continue}$.push({id:Z,name:q.name,source:"orca_cloud",isUser:!0})}}if(D?.filament)for(const q of D.filament){if(H.has(q.setting_id))continue;H.add(q.setting_id);const ee=le===q.setting_id||B&&(q.setting_id===B||CF(q.setting_id)===B);if(!(U&&!q.name.toLowerCase().includes(U))){if(!ee&&s){const re=lY(q.name);if(re&&!Pz(re,s))continue}$.push({id:q.setting_id,name:q.name,source:"cloud",isUser:P9e(q.setting_id)})}}if(I?.filament)for(const q of I.filament){const Z=`local_${q.id}`;U&&!q.name.toLowerCase().includes(U)||$.push({id:Z,name:q.name,source:"local",isUser:!1})}if(R)for(const q of R){if(H.has(q.filament_id))continue;const Z=q.filament_id.startsWith("GF")?"GFS"+q.filament_id.slice(2):q.filament_id;H.has(Z)||(!U||q.name.toLowerCase().includes(U))&&$.push({id:`builtin_${q.filament_id}`,name:q.name,source:"builtin",isUser:!1})}return $.sort((q,Z)=>{const ee={orca_cloud:0,cloud:1,local:2,builtin:3};return q.source!==Z.source?ee[q.source]-ee[Z.source]:q.isUser&&!Z.isUser?-1:!q.isUser&&Z.isUser?1:q.name.localeCompare(Z.name)})},[z?.filament,D?.filament,I?.filament,R,x,s,n.savedPresetId,n.trayInfoIdx]),ne=y.useMemo(()=>{if(!d)return null;let U=null,$="";if(d.startsWith("local_")){const B=parseInt(d.replace("local_",""),10);U=I?.filament.find(Z=>Z.id===B)?.name||null}else if(d.startsWith("builtin_")){const B=d.replace("builtin_","");U=R?.find(Z=>Z.filament_id===B)?.name||null,$=gw(B)}else{const B=d.startsWith("orca_")?d.replace("orca_",""):d,q=z?.filament.find(Z=>Z.setting_id===B);if(q)U=q.name;else if(D?.filament){const Z=D.filament.find(ee=>ee.setting_id===d);U=Z?.name||null,Z&&($=gw(Z.setting_id))}}if(!U)return null;let H=U.replace(/@.+$/,"").trim();H.startsWith("# ")&&(H=H.slice(2).trim());const le=nY(H);return{fullName:H,material:le.material,brand:le.brand,filamentId:$}},[d,D?.filament,I?.filament,R,z?.filament]),me=ne?.fullName||"",pe=y.useMemo(()=>{if(!ce||!ne)return[];const{fullName:U,brand:$}=ne,H=U.replace(/^(Bambu\s*(Lab)?|eSUN|Polymaker|Overture|Sunlu|Hatchbox)\s*/i,"").trim();return ce.filter(le=>{const B=(le.material||"").toUpperCase(),q=le.manufacturer.toUpperCase();if(!(B===H.toUpperCase()||B.includes(H.toUpperCase())||H.toUpperCase().includes(B)))return!1;if($){const ee=$.toUpperCase();if(!q.includes(ee)&&!ee.includes(q))return!1}return!0})},[ce,ne]),xe=y.useMemo(()=>{if(!J?.profiles||!ne)return[];const{fullName:U,material:$,brand:H,filamentId:le}=ne,B=U.toUpperCase(),q=$.toUpperCase(),Z=H.toUpperCase(),ee=le;if(!q||q.length<2)return[];const re=J.profiles.filter(he=>{if(ee){const ge=gw(he.filament_id);if(ge&&ge===ee&&!Ase(ge))return!0}const G=he.name.toUpperCase();if(Z)return!(!G.includes(Z)||!G.includes(q));if(G.includes(B)||G.includes(q))return!0;const ae={NYLON:["PA","PA-CF","PA6"],PA:["NYLON"]}[q]||[];for(const ge of ae)if(G.includes(ge))return!0;return!1}),se=new Map;for(const he of re){const G=`${he.name}|${he.k_value}`,L=se.get(G);L?n.extruderId!==void 0&&he.extruder_id===n.extruderId&&L.extruder_id!==n.extruderId&&se.set(G,he):se.set(G,he)}const fe=Array.from(se.values()),ue=n.caliIdx;if(ue!=null&&ue>0&&!fe.some(he=>he.slot_id===ue)){const he=J.profiles.find(G=>G.slot_id===ue&&(n.extruderId===void 0||G.extruder_id===n.extruderId));he&&fe.unshift(he)}return fe},[J?.profiles,ne,n.extruderId,n.caliIdx]);y.useEffect(()=>{if(t){if(n.savedPresetId)u(n.savedPresetId);else if(n.trayInfoIdx&&D?.filament){let U=D.filament.find($=>$.setting_id===n.trayInfoIdx);U||(U=D.filament.find($=>CF($.setting_id)===n.trayInfoIdx)),U&&u(U.setting_id)}else if(n.trayInfoIdx&&R?.length){const U=n.trayInfoIdx,$=R.find(H=>H.filament_id===U);$&&u(`builtin_${$.filament_id}`)}if(n.trayColor){const U=n.trayColor.slice(0,6);U&&g(U)}}else u(""),p(null),g(""),b(""),S(""),C(!1),j.current=""},[t,n.savedPresetId,n.trayInfoIdx,n.trayColor,D?.filament,R]),y.useEffect(()=>{if(xe.length>0){if(n.caliIdx!=null&&n.caliIdx>0){const U=xe.find($=>$.slot_id===n.caliIdx);if(U){p(U);return}}p(xe[0])}else p(null)},[d,xe,n.caliIdx]);const V=y.useCallback(U=>{U.key==="Escape"&&e()},[e]);y.useEffect(()=>{if(t)return document.addEventListener("keydown",V),()=>document.removeEventListener("keydown",V)},[t,V]);const Q=P&&!E||O||K||X;if(y.useEffect(()=>{if(!Q&&d&&d!==j.current){const U=requestAnimationFrame(()=>{const H=document.querySelector('[class*="fixed inset-0 z-50"]')?.querySelector(`[data-preset-id="${CSS.escape(d)}"]`);H&&(j.current=d,H.scrollIntoView({block:"nearest"}))});return()=>cancelAnimationFrame(U)}},[d,Q]),!t)return null;const A=d&&!de.isPending,F=f||n.trayColor?.slice(0,6)||"FFFFFF";return r.jsxs("div",{className:`fixed inset-0 z-50 flex ${l?"":"items-center justify-center"}`,children:[!l&&r.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm",onClick:e}),r.jsxs("div",{className:l?"relative w-full h-full bg-bambu-dark-secondary flex flex-col":"relative w-full max-w-lg mx-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl shadow-2xl",children:[r.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary shrink-0",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(gd,{className:"w-5 h-5 text-bambu-blue"}),r.jsx("h2",{className:"text-lg font-semibold text-white",children:c("configureAmsSlot.title")}),l&&r.jsxs("div",{className:"flex items-center gap-2 ml-4 text-sm text-bambu-gray",children:[r.jsx("span",{className:"text-white/30",children:"|"}),n.trayColor&&r.jsx("span",{className:"w-4 h-4 rounded-full border border-black/20",style:{backgroundColor:`#${n.trayColor.slice(0,6)}`}}),r.jsx("span",{className:"text-white/70",children:c("configureAmsSlot.slotLabel",{ams:rY(n.amsId,n.trayCount),slot:n.trayId+1})}),n.traySubBrands&&r.jsxs("span",{children:["(",n.traySubBrands,")"]})]})]}),r.jsx("button",{onClick:e,className:"p-1 text-bambu-gray hover:text-white rounded transition-colors",children:r.jsx(Ht,{className:"w-5 h-5"})})]}),r.jsxs("div",{className:`p-4 overflow-y-auto ${l?"flex-1 min-h-0":"space-y-4 max-h-[60vh]"}`,children:[k&&r.jsx("div",{className:"absolute inset-0 bg-bambu-dark-secondary/95 z-10 flex items-center justify-center rounded-xl",children:r.jsxs("div",{className:"text-center space-y-3",children:[r.jsx(eo,{className:"w-16 h-16 text-bambu-green mx-auto"}),r.jsx("p",{className:"text-lg font-semibold text-white",children:c("configureAmsSlot.slotConfigured")}),r.jsx("p",{className:"text-sm text-bambu-gray",children:c("configureAmsSlot.settingsSentToPrinter")})]})}),!l&&r.jsxs("div",{className:"p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:[r.jsx("p",{className:"text-xs text-bambu-gray mb-1",children:c("configureAmsSlot.configuringSlot")}),r.jsxs("div",{className:"flex items-center gap-2",children:[n.trayColor&&r.jsx("span",{className:"w-4 h-4 rounded-full border border-black/20",style:{backgroundColor:`#${n.trayColor.slice(0,6)}`}}),r.jsx("span",{className:"text-white font-medium",children:c("configureAmsSlot.slotLabel",{ams:rY(n.amsId,n.trayCount),slot:n.trayId+1})}),n.traySubBrands&&r.jsxs("span",{className:"text-bambu-gray",children:["(",n.traySubBrands,")"]})]})]}),Q?r.jsx("div",{className:"flex justify-center py-8",children:r.jsx(lt,{className:"w-6 h-6 text-bambu-green animate-spin"})}):l?r.jsxs("div",{className:"flex gap-4 h-full",children:[r.jsxs("div",{className:"w-1/2 flex flex-col min-h-0",children:[r.jsxs("label",{className:"block text-sm text-bambu-gray mb-2",children:[c("configureAmsSlot.filamentProfile")," ",r.jsx("span",{className:"text-red-400",children:"*"})]}),r.jsx("input",{type:"text",placeholder:c("configureAmsSlot.searchPresets"),value:x,onChange:U=>S(U.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder:text-bambu-gray focus:border-bambu-green focus:outline-none mb-2 shrink-0"}),r.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto space-y-1",children:Y.length===0?r.jsx("p",{className:"text-center py-4 text-bambu-gray",children:D?.filament?.length===0&&!I?.filament?.length?c("configureAmsSlot.noPresetsAvailable"):c("configureAmsSlot.noMatchingPresets")}):Y.map(U=>r.jsx("button",{"data-preset-id":U.id,onClick:()=>u(U.id),className:`group w-full p-2 rounded-lg border text-left transition-colors ${d===U.id?"bg-bambu-green/20 border-bambu-green":"bg-bambu-dark border-bambu-dark-tertiary hover:border-bambu-gray"}`,children:r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsx("span",{className:"text-white text-sm truncate group-hover:whitespace-normal group-hover:break-all",title:U.name,children:U.name}),r.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[U.source==="local"&&r.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-green-500/20 text-green-400",children:c("profiles.localProfiles.badge")}),U.source==="builtin"&&r.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-amber-500/20 text-amber-400",children:c("configureAmsSlot.builtin")}),U.isUser&&r.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-bambu-blue/20 text-bambu-blue",children:c("configureAmsSlot.custom")})]})]})},U.id))})]}),r.jsxs("div",{className:"w-1/2 flex flex-col gap-4 min-h-0 overflow-y-auto",children:[r.jsxs("div",{children:[r.jsxs("label",{className:"block text-sm text-bambu-gray mb-2",children:[c("configureAmsSlot.kProfileLabel"),me&&r.jsx("span",{className:"ml-2 text-xs text-bambu-blue",children:c("configureAmsSlot.filteringFor",{material:me})})]}),xe.length>0?r.jsxs("div",{className:"relative",children:[r.jsxs("select",{value:m?.name||"",onChange:U=>{const $=xe.find(H=>H.name===U.target.value);p($||null)},className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none pr-10",children:[r.jsx("option",{value:"",children:c("configureAmsSlot.noKProfile")}),xe.map(U=>r.jsxs("option",{value:U.name,children:[U.name," (K=",U.k_value,")"]},`${U.name}-${U.extruder_id}`))]}),r.jsx(La,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}):d?r.jsx("p",{className:"text-sm text-bambu-gray italic py-2",children:c("configureAmsSlot.noMatchingKProfiles")}):r.jsx("span",{className:"inline-block text-xs px-2 py-1 rounded bg-amber-500/20 text-amber-400 border border-amber-500/30",children:c("configureAmsSlot.selectFilamentFirst")}),m&&r.jsx("p",{className:"text-xs text-bambu-green mt-1",children:c("configureAmsSlot.kFromCalibration",{value:m.k_value})})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-2",children:c("configureAmsSlot.customColorLabel")}),pe.length>0&&r.jsxs("div",{className:"mb-3",children:[r.jsx("p",{className:"text-xs text-bambu-gray mb-1.5",children:c("configureAmsSlot.presetColors",{name:ne?.fullName})}),r.jsx("div",{className:"flex flex-wrap gap-1.5",children:pe.map(U=>r.jsxs("button",{onClick:()=>{const $=U.hex_color.replace("#","").toUpperCase();g($),b(U.color_name)},className:`h-7 px-2 rounded-md border-2 transition-all flex items-center gap-1.5 ${f===U.hex_color.replace("#","").toUpperCase()?"border-bambu-green scale-105":"border-white/20 hover:border-white/40"}`,title:U.color_name,children:[r.jsx("span",{className:"w-4 h-4 rounded-full border border-black/20 flex-shrink-0",style:{backgroundColor:U.hex_color}}),r.jsx("span",{className:"text-xs text-white/80 whitespace-nowrap",children:U.color_name})]},U.id))})]}),r.jsxs("div",{className:"flex flex-wrap gap-1.5 mb-2",children:[iY.map(U=>r.jsx("button",{onClick:()=>{g(U.hex),b(U.name)},className:`w-7 h-7 rounded-md border-2 transition-all ${f===U.hex?"border-bambu-green scale-110":"border-white/20 hover:border-white/40"}`,style:{backgroundColor:`#${U.hex}`},title:U.name},U.hex)),r.jsx("button",{onClick:()=>T(!N),className:"w-7 h-7 rounded-md border-2 border-white/20 hover:border-white/40 flex items-center justify-center text-white/60 hover:text-white/80 transition-all text-xs",title:c(N?"configureAmsSlot.showLessColors":"configureAmsSlot.showMoreColors"),children:N?"−":"+"})]}),N&&r.jsx("div",{className:"flex flex-wrap gap-1.5 mb-2",children:sY.map(U=>r.jsx("button",{onClick:()=>{g(U.hex),b(U.name)},className:`w-7 h-7 rounded-md border-2 transition-all ${f===U.hex?"border-bambu-green scale-110":"border-white/20 hover:border-white/40"}`,style:{backgroundColor:`#${U.hex}`},title:U.name},U.hex))}),r.jsxs("div",{className:"flex gap-2 items-center",children:[r.jsx("div",{className:"w-10 h-10 rounded-lg border-2 border-white/20 flex-shrink-0",style:{backgroundColor:`#${F}`}}),r.jsx("input",{type:"text",placeholder:c("configureAmsSlot.colorPlaceholder"),value:v,onChange:U=>{const $=U.target.value;b($);const H=oY($);if(H)g(H);else{const le=$.replace(/[^0-9A-Fa-f]/g,"").toUpperCase();le.length===6?g(le):le.length===3&&g(le.split("").map(B=>B+B).join(""))}},className:"flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder:text-bambu-gray focus:border-bambu-green focus:outline-none text-sm"}),f&&r.jsx("button",{onClick:()=>{g(""),b("")},className:"px-2 py-1 text-xs text-bambu-gray hover:text-white bg-bambu-dark-tertiary rounded",title:c("configureAmsSlot.clearCustomColor"),children:c("configureAmsSlot.clear")})]}),f&&r.jsx("p",{className:"text-xs text-bambu-gray mt-1.5",children:c("configureAmsSlot.hexLabel",{hex:f})})]})]})]}):r.jsxs(r.Fragment,{children:[r.jsxs("div",{children:[r.jsxs("label",{className:"block text-sm text-bambu-gray mb-2",children:[c("configureAmsSlot.filamentProfile")," ",r.jsx("span",{className:"text-red-400",children:"*"})]}),r.jsxs("div",{className:"relative",children:[r.jsx("input",{type:"text",placeholder:c("configureAmsSlot.searchPresets"),value:x,onChange:U=>S(U.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder:text-bambu-gray focus:border-bambu-green focus:outline-none mb-2"}),r.jsx("div",{className:"max-h-48 overflow-y-auto space-y-1",children:Y.length===0?r.jsx("p",{className:"text-center py-4 text-bambu-gray",children:D?.filament?.length===0&&!I?.filament?.length?c("configureAmsSlot.noPresetsAvailable"):c("configureAmsSlot.noMatchingPresets")}):Y.map(U=>r.jsx("button",{"data-preset-id":U.id,onClick:()=>u(U.id),className:`group w-full p-2 rounded-lg border text-left transition-colors ${d===U.id?"bg-bambu-green/20 border-bambu-green":"bg-bambu-dark border-bambu-dark-tertiary hover:border-bambu-gray"}`,children:r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsx("span",{className:"text-white text-sm truncate group-hover:whitespace-normal group-hover:break-all",title:U.name,children:U.name}),r.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[U.source==="local"&&r.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-green-500/20 text-green-400",children:c("profiles.localProfiles.badge")}),U.source==="builtin"&&r.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-amber-500/20 text-amber-400",children:c("configureAmsSlot.builtin")}),U.isUser&&r.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-bambu-blue/20 text-bambu-blue",children:c("configureAmsSlot.custom")})]})]})},U.id))})]})]}),r.jsxs("div",{children:[r.jsxs("label",{className:"block text-sm text-bambu-gray mb-2",children:[c("configureAmsSlot.kProfileLabel"),me&&r.jsx("span",{className:"ml-2 text-xs text-bambu-blue",children:c("configureAmsSlot.filteringFor",{material:me})})]}),xe.length>0?r.jsxs("div",{className:"relative",children:[r.jsxs("select",{value:m?.name||"",onChange:U=>{const $=xe.find(H=>H.name===U.target.value);p($||null)},className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none pr-10",children:[r.jsx("option",{value:"",children:c("configureAmsSlot.noKProfile")}),xe.map(U=>r.jsxs("option",{value:U.name,children:[U.name," (K=",U.k_value,")"]},`${U.name}-${U.extruder_id}`))]}),r.jsx(La,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}):d?r.jsx("p",{className:"text-sm text-bambu-gray italic py-2",children:c("configureAmsSlot.noMatchingKProfiles")}):r.jsx("span",{className:"inline-block text-xs px-2 py-1 rounded bg-amber-500/20 text-amber-400 border border-amber-500/30",children:c("configureAmsSlot.selectFilamentFirst")}),m&&r.jsx("p",{className:"text-xs text-bambu-green mt-1",children:c("configureAmsSlot.kFromCalibration",{value:m.k_value})})]}),r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-2",children:c("configureAmsSlot.customColorLabel")}),pe.length>0&&r.jsxs("div",{className:"mb-3",children:[r.jsx("p",{className:"text-xs text-bambu-gray mb-1.5",children:c("configureAmsSlot.presetColors",{name:ne?.fullName})}),r.jsx("div",{className:"flex flex-wrap gap-1.5",children:pe.map(U=>r.jsxs("button",{onClick:()=>{const $=U.hex_color.replace("#","").toUpperCase();g($),b(U.color_name)},className:`h-7 px-2 rounded-md border-2 transition-all flex items-center gap-1.5 ${f===U.hex_color.replace("#","").toUpperCase()?"border-bambu-green scale-105":"border-white/20 hover:border-white/40"}`,title:U.color_name,children:[r.jsx("span",{className:"w-4 h-4 rounded-full border border-black/20 flex-shrink-0",style:{backgroundColor:U.hex_color}}),r.jsx("span",{className:"text-xs text-white/80 whitespace-nowrap",children:U.color_name})]},U.id))})]}),r.jsxs("div",{className:"flex flex-wrap gap-1.5 mb-2",children:[iY.map(U=>r.jsx("button",{onClick:()=>{g(U.hex),b(U.name)},className:`w-7 h-7 rounded-md border-2 transition-all ${f===U.hex?"border-bambu-green scale-110":"border-white/20 hover:border-white/40"}`,style:{backgroundColor:`#${U.hex}`},title:U.name},U.hex)),r.jsx("button",{onClick:()=>T(!N),className:"w-7 h-7 rounded-md border-2 border-white/20 hover:border-white/40 flex items-center justify-center text-white/60 hover:text-white/80 transition-all text-xs",title:c(N?"configureAmsSlot.showLessColors":"configureAmsSlot.showMoreColors"),children:N?"−":"+"})]}),N&&r.jsx("div",{className:"flex flex-wrap gap-1.5 mb-2",children:sY.map(U=>r.jsx("button",{onClick:()=>{g(U.hex),b(U.name)},className:`w-7 h-7 rounded-md border-2 transition-all ${f===U.hex?"border-bambu-green scale-110":"border-white/20 hover:border-white/40"}`,style:{backgroundColor:`#${U.hex}`},title:U.name},U.hex))}),r.jsxs("div",{className:"flex gap-2 items-center",children:[r.jsx("div",{className:"w-10 h-10 rounded-lg border-2 border-white/20 flex-shrink-0",style:{backgroundColor:`#${F}`}}),r.jsx("input",{type:"text",placeholder:c("configureAmsSlot.colorPlaceholder"),value:v,onChange:U=>{const $=U.target.value;b($);const H=oY($);if(H)g(H);else{const le=$.replace(/[^0-9A-Fa-f]/g,"").toUpperCase();le.length===6?g(le):le.length===3&&g(le.split("").map(B=>B+B).join(""))}},className:"flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder:text-bambu-gray focus:border-bambu-green focus:outline-none text-sm"}),f&&r.jsx("button",{onClick:()=>{g(""),b("")},className:"px-2 py-1 text-xs text-bambu-gray hover:text-white bg-bambu-dark-tertiary rounded",title:c("configureAmsSlot.clearCustomColor"),children:c("configureAmsSlot.clear")})]}),f&&r.jsx("p",{className:"text-xs text-bambu-gray mt-1.5",children:c("configureAmsSlot.hexLabel",{hex:f})})]})]})]}),r.jsxs("div",{className:"flex justify-between p-4 border-t border-bambu-dark-tertiary shrink-0",children:[r.jsx(Le,{variant:"secondary",onClick:()=>oe.mutate(),disabled:oe.isPending||de.isPending,className:"text-red-400 hover:text-red-300 hover:bg-red-500/10",children:oe.isPending?r.jsxs(r.Fragment,{children:[r.jsx(lt,{className:"w-4 h-4 animate-spin"}),c("configureAmsSlot.resetting")]}):r.jsxs(r.Fragment,{children:[r.jsx(gs,{className:"w-4 h-4"}),c("configureAmsSlot.resetSlot")]})}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx(Le,{variant:"secondary",onClick:e,children:c("configureAmsSlot.cancel")}),r.jsx(Le,{onClick:()=>de.mutate(),disabled:!A,children:de.isPending?r.jsxs(r.Fragment,{children:[r.jsx(lt,{className:"w-4 h-4 animate-spin"}),c("configureAmsSlot.configuring")]}):r.jsxs(r.Fragment,{children:[r.jsx(gd,{className:"w-4 h-4"}),c("configureAmsSlot.configureSlot")]})})]})]}),(de.isError||oe.isError)&&r.jsx("div",{className:"mx-4 mb-4 p-2 bg-red-500/20 border border-red-500/50 rounded text-sm text-red-400",children:de.error?.message||oe.error?.message})]})]})}function cY({className:t="w-4 h-4"}){return r.jsx("svg",{viewBox:"0 0 1945 1370",fill:"none",className:t,"aria-hidden":"true",children:r.jsxs("g",{transform:"translate(-754.293 -471.685)",children:[r.jsxs("g",{transform:"translate(0.18191 255.976)",children:[r.jsx("g",{transform:"matrix(1.05469 0 0 0.241063 -153.484 1120.2)",children:r.jsx("rect",{x:"922.048",y:"1195.15",width:"1721.5",height:"470.135",stroke:"currentColor",strokeOpacity:"0.99",strokeWidth:"168.84",strokeLinecap:"round",strokeLinejoin:"round"})}),r.jsx("g",{transform:"matrix(0.983656 0 0 1.0767 -62.2035 141.539)",children:r.jsx("path",{d:"M2741.42,1175.93L895.832,1175.93L1125.16,621.902L2512.09,621.902L2741.42,1175.93Z",fill:"currentColor",fillOpacity:"0.05",stroke:"currentColor",strokeOpacity:"0.99",strokeWidth:"125.26",strokeLinecap:"round",strokeLinejoin:"round"})})]}),r.jsx("g",{transform:"translate(21.1916 0.684817)",children:r.jsx("path",{d:"M1981.31,567.518C1954.86,567.518 1933.39,546.047 1933.39,519.601C1933.39,493.156 1954.86,471.685 1981.31,471.685L2146.61,471.685C2173.07,471.685 2194.53,493.138 2194.53,519.601L2194.53,688.741C2194.53,715.187 2173.05,736.658 2146.61,736.658C2120.16,736.658 2098.69,715.187 2098.69,688.741L2098.69,567.518L1981.31,567.518ZM2098.69,1252.54C2098.69,1226.1 2120.16,1204.62 2146.61,1204.62C2173.05,1204.62 2194.53,1226.1 2194.53,1252.54L2194.53,1421.68C2194.53,1448.14 2173.07,1469.6 2146.61,1469.6L1981.31,1469.6C1954.86,1469.6 1933.39,1448.13 1933.39,1421.68C1933.39,1395.24 1954.86,1373.76 1981.31,1373.76L2098.69,1373.76L2098.69,1252.54ZM1430.29,1373.76C1456.74,1373.76 1478.21,1395.24 1478.21,1421.68C1478.21,1448.13 1456.74,1469.6 1430.29,1469.6L1264.99,1469.6C1238.53,1469.6 1217.07,1448.14 1217.07,1421.68L1217.07,1252.54C1217.07,1226.1 1238.55,1204.62 1264.99,1204.62C1291.44,1204.62 1312.91,1226.1 1312.91,1252.54L1312.91,1373.76L1430.29,1373.76ZM1312.91,688.741C1312.91,715.187 1291.44,736.658 1264.99,736.658C1238.55,736.658 1217.07,715.187 1217.07,688.741L1217.07,519.601C1217.07,493.138 1238.53,471.685 1264.99,471.685L1430.29,471.685C1456.74,471.685 1478.21,493.156 1478.21,519.601C1478.21,546.047 1456.74,567.518 1430.29,567.518L1312.91,567.518L1312.91,688.741Z",fill:"currentColor",fillOpacity:"0.99"})})]})})}function Mse({folderId:t,onClose:e,onUploadComplete:a,onFileUploaded:n,autoUpload:i,validateFile:s,accept:o}){const{t:l}=wt(),[c,d]=y.useState([]),[u,m]=y.useState(!1),[p,f]=y.useState(!1),[g,v]=y.useState(!0),[b,x]=y.useState(!1),[S,k]=y.useState(!0),[C,N]=y.useState(null),T=y.useRef(null),j=oe=>{oe.preventDefault(),m(!0)},D=oe=>{oe.preventDefault(),m(!1)},P=oe=>{oe.preventDefault(),m(!1),O(Array.from(oe.dataTransfer.files))},E=oe=>{oe.target.files&&O(Array.from(oe.target.files))},z=(oe,Y)=>{d(ne=>ne.map(me=>me.file===oe?{...me,...Y}:me))},I=async oe=>{f(!0);for(const Y of oe)if(Y.status==="pending"){z(Y.file,{status:"uploading"});try{if(Y.isZip){const ne=await ie.extractZipFile(Y.file,t,g,b,S);z(Y.file,{status:ne.errors.length>0&&ne.extracted===0?"error":"success",extractedCount:ne.extracted,error:ne.errors.length>0?l("fileManager.zipFilesFailed","{{count}} files failed",{count:ne.errors.length}):void 0})}else{const ne=await ie.uploadLibraryFile(Y.file,t,S);z(Y.file,{status:"success"});const me=n?.(ne);if(me){N(me),d([]),f(!1);return}}}catch(ne){z(Y.file,{status:"error",error:ne instanceof Error?ne.message:l("fileManager.uploadFailed","Upload failed")})}}f(!1),a(),d(Y=>(Y.some(me=>me.status==="error")||e(),Y))},O=oe=>{if(N(null),s)for(const ne of oe){const me=s(ne);if(me){N(me);return}}const Y=oe.map(ne=>({file:ne,status:"pending",isZip:ne.name.toLowerCase().endsWith(".zip"),is3mf:ne.name.toLowerCase().endsWith(".3mf")}));d(ne=>[...ne,...Y]),i&&oe.length>0&&I(Y)},R=oe=>{d(Y=>Y.filter((ne,me)=>me!==oe))},K=c.some(oe=>oe.isZip&&oe.status==="pending"),J=c.some(oe=>oe.file.name.toLowerCase().endsWith(".stl")&&oe.status==="pending"),X=c.some(oe=>oe.is3mf&&oe.status==="pending"),ce=c.filter(oe=>oe.status==="pending").length,de=c.length>0&&ce===0&&!p;return r.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",children:r.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg w-full max-w-lg border border-bambu-dark-tertiary",children:[r.jsxs("div",{className:"p-4 border-b border-bambu-dark-tertiary flex items-center justify-between",children:[r.jsx("h2",{className:"text-lg font-semibold text-white",children:l("fileManager.uploadFiles")}),r.jsx("button",{onClick:e,className:"p-1 hover:bg-bambu-dark rounded",children:r.jsx(Ht,{className:"w-5 h-5 text-bambu-gray"})})]}),r.jsxs("div",{className:"p-4 space-y-4",children:[r.jsxs("div",{onDragOver:j,onDragLeave:D,onDrop:P,onClick:()=>T.current?.click(),className:`border-2 border-dashed rounded-lg p-8 text-center cursor-pointer transition-colors ${u?"border-bambu-green bg-bambu-green/10":"border-bambu-dark-tertiary hover:border-bambu-green/50"}`,children:[r.jsx(pn,{className:`w-10 h-10 mx-auto mb-3 ${u?"text-bambu-green":"text-bambu-gray"}`}),r.jsx("p",{className:"text-white font-medium",children:l(u?"fileManager.dropFilesHere":"fileManager.dragDropFiles")}),r.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:l("fileManager.orClickToBrowse")}),r.jsx("p",{className:"text-xs text-bambu-gray/70 mt-2",children:l("fileManager.allFileTypesSupported")})]}),r.jsx("input",{ref:T,type:"file",multiple:!0,accept:o,className:"hidden",onChange:E}),K&&r.jsx("div",{className:"p-3 bg-blue-500/10 border border-blue-500/30 rounded-lg",children:r.jsxs("div",{className:"flex items-start gap-3",children:[r.jsx(ao,{className:"w-5 h-5 text-blue-400 mt-0.5 flex-shrink-0"}),r.jsxs("div",{className:"flex-1",children:[r.jsx("p",{className:"text-sm text-blue-300 font-medium",children:l("fileManager.zipFilesDetected")}),r.jsx("p",{className:"text-xs text-blue-300/70 mt-1",children:l("fileManager.zipExtractOptions")}),r.jsxs("label",{className:"flex items-center gap-2 mt-2 cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:g,onChange:oe=>v(oe.target.checked),className:"w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),r.jsx("span",{className:"text-sm text-white",children:l("fileManager.preserveZipStructure")})]}),r.jsxs("label",{className:"flex items-center gap-2 mt-2 cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:b,onChange:oe=>x(oe.target.checked),className:"w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),r.jsx("span",{className:"text-sm text-white",children:l("fileManager.createFolderFromZip")})]})]})]})}),X&&r.jsx("div",{className:"p-3 bg-purple-500/10 border border-purple-500/30 rounded-lg",children:r.jsxs("div",{className:"flex items-start gap-3",children:[r.jsx(gr,{className:"w-5 h-5 text-purple-400 mt-0.5 flex-shrink-0"}),r.jsxs("div",{className:"flex-1",children:[r.jsx("p",{className:"text-sm text-purple-300 font-medium",children:l("fileManager.threemfDetected")}),r.jsx("p",{className:"text-xs text-purple-300/70 mt-1",children:l("fileManager.threemfExtractionInfo")})]})]})}),(J||K)&&r.jsx("div",{className:"p-3 bg-bambu-green/10 border border-bambu-green/30 rounded-lg",children:r.jsxs("div",{className:"flex items-start gap-3",children:[r.jsx(bu,{className:"w-5 h-5 text-bambu-green mt-0.5 flex-shrink-0"}),r.jsxs("div",{className:"flex-1",children:[r.jsx("p",{className:"text-sm text-bambu-green font-medium",children:l("fileManager.stlThumbnailGeneration")}),r.jsx("p",{className:"text-xs text-bambu-green/70 mt-1",children:l(K&&!J?"fileManager.zipMayContainStl":"fileManager.thumbnailsCanBeGenerated")}),r.jsxs("label",{className:"flex items-center gap-2 mt-2 cursor-pointer",children:[r.jsx("input",{type:"checkbox",checked:S,onChange:oe=>k(oe.target.checked),className:"w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),r.jsx("span",{className:"text-sm text-white",children:l("fileManager.generateThumbnailsForStl")})]})]})]})}),c.length>0&&r.jsx("div",{className:"max-h-48 overflow-y-auto space-y-2",children:c.map((oe,Y)=>r.jsxs("div",{className:"flex items-center gap-3 p-2 bg-bambu-dark rounded-lg",children:[oe.isZip?r.jsx(ao,{className:"w-4 h-4 text-blue-400 flex-shrink-0"}):r.jsx(DT,{className:"w-4 h-4 text-bambu-gray flex-shrink-0"}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("p",{className:"text-sm text-white truncate",children:oe.file.name}),r.jsxs("p",{className:"text-xs text-bambu-gray",children:[(oe.file.size/1024/1024).toFixed(2)," MB",oe.isZip&&oe.status==="pending"&&r.jsxs("span",{className:"text-blue-400 ml-2",children:["• ",l("fileManager.willBeExtracted")]}),oe.extractedCount!==void 0&&r.jsxs("span",{className:"text-green-400 ml-2",children:["• ",l("fileManager.filesExtracted",{count:oe.extractedCount})]})]}),oe.status==="error"&&oe.error&&r.jsx("p",{className:"text-xs text-red-400 mt-1 break-words",children:oe.error})]}),oe.status==="pending"&&r.jsx("button",{onClick:()=>R(Y),className:"p-1 hover:bg-bambu-dark-tertiary rounded",children:r.jsx(Ht,{className:"w-4 h-4 text-bambu-gray"})}),oe.status==="uploading"&&r.jsx(lt,{className:"w-4 h-4 text-bambu-green animate-spin"}),oe.status==="success"&&r.jsx(pr,{className:"w-4 h-4 text-green-500"}),oe.status==="error"&&r.jsx("span",{title:oe.error,children:r.jsx(Er,{className:"w-4 h-4 text-red-500"})})]},Y))}),C&&r.jsx("div",{className:"p-3 bg-red-500/10 border border-red-500/30 rounded-lg",children:r.jsxs("div",{className:"flex items-start gap-3",children:[r.jsx(Er,{className:"w-5 h-5 text-red-400 mt-0.5 flex-shrink-0"}),r.jsx("p",{className:"text-sm text-red-300",children:C})]})})]}),r.jsxs("div",{className:"p-4 border-t border-bambu-dark-tertiary flex justify-end gap-2",children:[r.jsx(Le,{variant:"secondary",onClick:e,children:l("common.cancel")}),!de&&r.jsx(Le,{onClick:()=>I(c),disabled:ce===0||p,children:p?r.jsxs(r.Fragment,{children:[r.jsx(lt,{className:"w-4 h-4 mr-2 animate-spin"}),l("fileManager.uploading")]}):r.jsxs(r.Fragment,{children:[r.jsx(pn,{className:"w-4 h-4 mr-2"}),l("common.upload")," ",ce>0?`(${ce})`:""]})})]})]})})}function dY(t){if(!t)return"#808080";const e=t.replace("#","");return e.length>=8&&e.substring(6,8).toLowerCase()!=="ff"?`#${e.substring(0,8)}`:`#${e.substring(0,6)}`}function In(t){return t?t.replace("#","").toLowerCase().substring(0,6):""}const N9e=[["PA-CF","PA12-CF","PAHT-CF"]],Ese={};for(const t of N9e){const e=t[0];for(const a of t)Ese[a.toUpperCase()]=e.toUpperCase()}function j1(t){if(!t)return"";const e=t.toUpperCase();return Ese[e]??e}function NF(t,e){return j1(t)===j1(e)}function pd(t,e,a=40){const n=In(t),i=In(e);if(!n||!i||n.length<6||i.length<6)return!1;const s=parseInt(n.substring(0,2),16),o=parseInt(n.substring(2,4),16),l=parseInt(n.substring(4,6),16),c=parseInt(i.substring(0,2),16),d=parseInt(i.substring(2,4),16),u=parseInt(i.substring(4,6),16);return Math.abs(s-c)<=a&&Math.abs(o-d)<=a&&Math.abs(l-u)<=a}function yk(t,e,a,n){if(n)return"Ext";const i=String.fromCharCode(65+(t>=128?t-128:t));return a?`HT-${i}`:`${i}${e+1}`}function ib(t,e,a){return a?254+e:t>=128?t:t*4+e}function by(t){return t>50?"#00ae42":t>=15?"#f59e0b":"#ef4444"}function GC(t){return!t?.remaining_weight||!t?.filament_weight||t.filament_weight<=0?null:Math.min(100,Math.round(t.remaining_weight/t.filament_weight*100))}function uY(t,e){return(Number.isFinite(t)?Math.max(0,Math.trunc(t)):0).toString(16).toUpperCase().padStart(e,"0").slice(-e)}function T9e(t){const e=(t||"").trim().toUpperCase();let a=2166136261;for(let n=0;n>>0).toString(16).toUpperCase().padStart(8,"0")}function Sm(t,e,a){return`${T9e(t)}${uY(e,4)}${uY(a,4)}`}function mY(t){if(!t)return!1;const e=Date.now()+4320*60*60*1e3;return(Ua(t)?.getTime()??0)>e}function A9e(t,e,a,n){let i=Dse(e,t.nozzle_id);n&&(i=[...i].sort((c,d)=>{const u=(c.remain??-1)>=0?c.remain??-1:101,m=(d.remain??-1)>=0?d.remain??-1:101;return u-m}));const s=i.find(c=>!a.has(c.globalTrayId)&&NF(c.type,t.type)&&In(c.color)===In(t.color)),o=s?void 0:i.find(c=>!a.has(c.globalTrayId)&&NF(c.type,t.type)&&pd(c.color,t.color)),l=s||o?void 0:i.find(c=>!a.has(c.globalTrayId)&&NF(c.type,t.type));return s??o??l}function Dse(t,e){return t.filter(a=>e==null||a.extruderId===e)}function Ys(t){return t?!!(t.tray_uuid&&t.tray_uuid!=="00000000000000000000000000000000"||t.tag_uid&&t.tag_uid!=="0000000000000000"):!1}function vk(t){const e=[],a=t?.ams_extruder_map,n=!!t?.nozzles?.[1]?.nozzle_diameter||a&&Object.keys(a).length>0||(t?.vt_tray?.length??0)>1;t?.ams?.forEach(i=>{const s=i.tray.length===1;i.tray.forEach(o=>{if(o.tray_type){const l=dY(o.tray_color);e.push({type:o.tray_type,color:l,colorName:Sc(l),amsId:i.id,trayId:o.id,isHt:s,isExternal:!1,label:yk(i.id,o.id,s,!1),globalTrayId:ib(i.id,o.id,!1),trayInfoIdx:o.tray_info_idx||"",traySubBrands:o.tray_sub_brands||"",extruderId:a?.[String(i.id)],remain:o.remain??-1})}})});for(const i of t?.vt_tray??[])if(i.tray_type){const s=dY(i.tray_color),o=i.id??254,l=(t?.vt_tray?.length??0)>1;e.push({type:i.tray_type,color:s,colorName:Sc(s),amsId:-1,trayId:o-254,isHt:!1,isExternal:!0,label:l?o===254?"Ext-L":"Ext-R":"External",globalTrayId:o,trayInfoIdx:i.tray_info_idx||"",traySubBrands:i.tray_sub_brands||"",extruderId:n?255-o:void 0,remain:i.remain??-1})}return e}function pY(t,e,a){if(!t?.filaments||t.filaments.length===0)return;const n=vk(e);if(n.length===0)return;const i=e?.fila_switch?.installed===!0,s=new Set,o=t.filaments.map(d=>{const u=d.tray_info_idx||"";let m=n.filter(x=>!s.has(x.globalTrayId));d.nozzle_id!=null&&!i&&(m=m.filter(x=>x.extruderId===d.nozzle_id)),a&&(m=[...m].sort((x,S)=>{const k=x.remain>=0?x.remain:101,C=S.remain>=0?S.remain:101;return k-C}));let p,f,g,v;if(u){const x=m.filter(S=>S.trayInfoIdx===u);x.length===1?p=x[0]:x.length>1&&(a&&x.sort((S,k)=>{const C=S.remain>=0?S.remain:101,N=k.remain>=0?k.remain:101;return C-N}),f=x.find(S=>S.type?.toUpperCase()===d.type?.toUpperCase()&&In(S.color)===In(d.color)),f||(g=x.find(S=>S.type?.toUpperCase()===d.type?.toUpperCase()&&pd(S.color,d.color))),!f&&!g&&(v=x.find(S=>S.type?.toUpperCase()===d.type?.toUpperCase())))}!p&&!f&&!g&&!v&&(f=m.find(x=>x.type?.toUpperCase()===d.type?.toUpperCase()&&In(x.color)===In(d.color)),f||(g=m.find(x=>x.type?.toUpperCase()===d.type?.toUpperCase()&&pd(x.color,d.color))),!f&&!g&&(v=m.find(x=>x.type?.toUpperCase()===d.type?.toUpperCase())));const b=p||f||g||v||void 0;return b&&s.add(b.globalTrayId),{slot_id:d.slot_id,globalTrayId:b?.globalTrayId??-1}}),l=Math.max(...o.map(d=>d.slot_id||0));if(l<=0)return;const c=new Array(l).fill(-1);return o.forEach(d=>{d.slot_id&&d.slot_id>0&&(c[d.slot_id-1]=d.globalTrayId)}),c}function j9e(t){return y.useMemo(()=>vk(t),[t])}function Fse(t,e,a,n){const i=j9e(e),s=e?.fila_switch?.installed===!0,o=y.useMemo(()=>{if(!t?.filaments||t.filaments.length===0)return[];const u=new Set(Object.values(a));return t.filaments.map(m=>{const p=m.slot_id||0;if(p>0&&a[p]!==void 0){const D=a[p],P=i.find(E=>E.globalTrayId===D);if(P){const E=P.type?.toUpperCase()===m.type?.toUpperCase(),z=In(P.color)===In(m.color)||pd(P.color,m.color);let I;return E&&z?I="match":E?I="type_only":I="mismatch",{...m,loaded:P,hasFilament:!0,typeMatch:E,colorMatch:z,status:I,isManual:!0}}}const f=m.tray_info_idx||"";let g=i.filter(D=>!u.has(D.globalTrayId));m.nozzle_id!=null&&!s&&(g=g.filter(D=>D.extruderId===m.nozzle_id)),n&&(g=[...g].sort((D,P)=>{const E=D.remain>=0?D.remain:101,z=P.remain>=0?P.remain:101;return E-z}));let v,b,x,S;if(f){const D=g.filter(P=>P.trayInfoIdx===f);D.length===1?v=D[0]:D.length>1&&(n&&D.sort((P,E)=>{const z=P.remain>=0?P.remain:101,I=E.remain>=0?E.remain:101;return z-I}),b=D.find(P=>P.type?.toUpperCase()===m.type?.toUpperCase()&&In(P.color)===In(m.color)),b||(x=D.find(P=>P.type?.toUpperCase()===m.type?.toUpperCase()&&pd(P.color,m.color))),!b&&!x&&(S=D.find(P=>P.type?.toUpperCase()===m.type?.toUpperCase())))}!v&&!b&&!x&&!S&&(b=g.find(D=>D.type?.toUpperCase()===m.type?.toUpperCase()&&In(D.color)===In(m.color)),b||(x=g.find(D=>D.type?.toUpperCase()===m.type?.toUpperCase()&&pd(D.color,m.color))),!b&&!x&&(S=g.find(D=>D.type?.toUpperCase()===m.type?.toUpperCase())));const k=v||b||x||S||void 0;k&&u.add(k.globalTrayId);const C=!!k,N=C,T=!!v||!!b||!!x;let j;return v||b||x?j="match":S?j="type_only":j="mismatch",{...m,loaded:k,hasFilament:C,typeMatch:N,colorMatch:T,status:j,isManual:!1}})},[t,i,a,n,s]),l=y.useMemo(()=>{if(o.length===0)return;const u=Math.max(...o.map(p=>p.slot_id||0));if(u<=0)return;const m=new Array(u).fill(-1);return o.forEach(p=>{p.slot_id&&p.slot_id>0&&(m[p.slot_id-1]=p.loaded?.globalTrayId??-1)}),m},[o]),c=o.some(u=>u.status==="mismatch"),d=o.some(u=>u.status==="type_only");return{loadedFilaments:i,filamentComparison:o,amsMapping:l,hasTypeMismatch:c,hasColorMismatch:d}}function M9e(t,e,a,n){if(!t||t.length===0)return{exactMatches:0,typeOnlyMatches:0,missingTypes:0,totalSlots:0,status:"full"};let i=0,s=0,o=0;const l=new Set(Object.values(a));for(const u of t){const m=u.slot_id||0;if(m>0&&a[m]!==void 0){const x=a[m],S=e.find(k=>k.globalTrayId===x);if(S){const k=S.type?.toUpperCase()===u.type?.toUpperCase(),C=In(S.color)===In(u.color)||pd(S.color,u.color);k&&C?i++:k?s++:o++;continue}}let p=e.filter(x=>!l.has(x.globalTrayId));if(u.nozzle_id!=null){const x=p.filter(S=>S.extruderId===u.nozzle_id);x.length>0&&(p=x)}n&&(p=[...p].sort((x,S)=>{const k=x.remain>=0?x.remain:101,C=S.remain>=0?S.remain:101;return k-C}));const f=p.find(x=>x.type?.toUpperCase()===u.type?.toUpperCase()&&In(x.color)===In(u.color)),g=f?void 0:p.find(x=>x.type?.toUpperCase()===u.type?.toUpperCase()&&pd(x.color,u.color)),v=f||g?void 0:p.find(x=>x.type?.toUpperCase()===u.type?.toUpperCase()),b=f??g??v;b&&l.add(b.globalTrayId),f||g?i++:v?s++:o++}const c=t.length;let d="full";return o>0?d="missing":s>0&&(d="partial"),{exactMatches:i,typeOnlyMatches:s,missingTypes:o,totalSlots:c,status:d}}function E9e(t,e,a,n){if(!t?.filaments||t.filaments.length===0)return;const i=vk(e);if(i.length===0)return;const s=new Set(Object.values(a)),o=[];for(const d of t.filaments){const u=d.slot_id||0;if(u>0&&a[u]!==void 0){o.push({slot_id:u,globalTrayId:a[u]});continue}let m=i.filter(b=>!s.has(b.globalTrayId));if(d.nozzle_id!=null){const b=m.filter(x=>x.extruderId===d.nozzle_id);b.length>0&&(m=b)}n&&(m=[...m].sort((b,x)=>{const S=b.remain>=0?b.remain:101,k=x.remain>=0?x.remain:101;return S-k}));const p=m.find(b=>b.type?.toUpperCase()===d.type?.toUpperCase()&&In(b.color)===In(d.color)),f=p?void 0:m.find(b=>b.type?.toUpperCase()===d.type?.toUpperCase()&&pd(b.color,d.color)),g=p||f?void 0:m.find(b=>b.type?.toUpperCase()===d.type?.toUpperCase()),v=p??f??g;v&&s.add(v.globalTrayId),o.push({slot_id:u,globalTrayId:v?.globalTrayId??-1})}const l=Math.max(...o.map(d=>d.slot_id||0));if(l<=0)return;const c=new Array(l).fill(-1);return o.forEach(d=>{d.slot_id&&d.slot_id>0&&(c[d.slot_id-1]=d.globalTrayId)}),c}const hY={useDefault:!0,manualMappings:{},autoConfigured:!1};function D9e(t,e,a,n,i,s,o){const l=df({queries:t.map(v=>({queryKey:["printer-status",v],queryFn:()=>ie.getPrinterStatus(v),enabled:t.length>0,staleTime:5e3}))}),c=y.useMemo(()=>t.map((v,b)=>{const x=l[b],S=x?.data,C=e?.find(z=>z.id===v)?.name||`Printer ${v}`,N=vk(S),T=i[v]||hY,j=pY(a,S,o),D=T.useDefault?n:T.manualMappings,P=E9e(a,S,D,o),E=M9e(a?.filaments,N,D,o);return{printerId:v,printerName:C,status:S,isLoading:x?.isLoading??!1,loadedFilaments:N,autoMapping:j,finalMapping:P,matchStatus:E.status,exactMatches:E.exactMatches,typeOnlyMatches:E.typeOnlyMatches,missingTypes:E.missingTypes,totalSlots:E.totalSlots,config:T}}),[t,l,e,a,i,n,o]),d=l.some(v=>v.isLoading),u=(v,b)=>{s(x=>({...x,[v]:{...x[v]||hY,...b}}))},m=v=>{const b=c.find(k=>k.printerId===v);if(!b||!b.status||!a?.filaments)return;const x=pY(a,b.status,o);if(!x)return;const S={};x.forEach((k,C)=>{k!==-1&&(S[C+1]=k)}),u(v,{useDefault:!1,manualMappings:S,autoConfigured:!0})},p=()=>{for(const v of t)m(v)},f=v=>c.find(x=>x.printerId===v)?.finalMapping,g=c.every(v=>v.matchStatus!=="missing");return{printerResults:c,isLoading:d,perPrinterConfigs:i,updatePrinterConfig:u,autoConfigureAll:p,autoConfigurePrinter:m,getFinalMapping:f,allPrintersReady:g}}const Lse={USD:"$",EUR:"€",GBP:"£",CHF:"Fr.",JPY:"¥",CNY:"¥",CAD:"$",AUD:"$",INR:"₹",HKD:"HK$",KRW:"₩",SEK:"kr",NOK:"kr",DKK:"kr",PLN:"zł",BRL:"R$",TWD:"NT$",SGD:"S$",NZD:"NZ$",MXN:"MX$",BZD:"BZ$",MYR:"RM",CZK:"Kč",THB:"฿",ZAR:"R",TRY:"₺",RUB:"₽",HUF:"Ft",ILS:"₪",UAH:"₴"};function Ho(t){return Lse[t.toUpperCase()]||t}const F9e=Object.entries(Lse).map(([t,e])=>({code:t,label:`${t} (${e})`})),Vd="/img/bed",L9e={"cool plate":{icon:`${Vd}/bed_cool.png`,label:"Cool Plate"},"pc plate":{icon:`${Vd}/bed_cool.png`,label:"Cool Plate"},"cool plate (supertack)":{icon:`${Vd}/bed_cool_supertack.png`,label:"Cool Plate SuperTack"},"supertack plate":{icon:`${Vd}/bed_cool_supertack.png`,label:"Cool Plate SuperTack"},"bambu cool plate supertack":{icon:`${Vd}/bed_cool_supertack.png`,label:"Cool Plate SuperTack"},"engineering plate":{icon:`${Vd}/bed_engineering.png`,label:"Engineering Plate"},"high temp plate":{icon:`${Vd}/bed_high_templ.png`,label:"High Temp Plate"},"textured pei plate":{icon:`${Vd}/bed_pei.png`,label:"Textured PEI Plate"},"pei plate":{icon:`${Vd}/bed_pei.png`,label:"PEI Plate"},"smooth pei plate":{icon:`${Vd}/bed_pei_cool.png`,label:"Smooth PEI Plate"}};function wk(t){return t?L9e[t.trim().toLowerCase()]??null:null}function R9e({printerId:t,filamentReqs:e,manualMappings:a,onManualMappingChange:n,currencySymbol:i,defaultCostPerKg:s,defaultExpanded:o=!1}){const{t:l}=wt(),c=na(),[d,u]=y.useState(!1),[m,p]=y.useState(o),{data:f}=$e({queryKey:["printer-status",t],queryFn:()=>ie.getPrinterStatus(t),enabled:!!t}),{data:g}=$e({queryKey:["spool-assignments",t],queryFn:()=>ie.getAssignments(t),enabled:!!t}),{loadedFilaments:v,filamentComparison:b,hasTypeMismatch:x,hasColorMismatch:S}=Fse(e,f,a),k=y.useMemo(()=>{const R=new Map;for(const K of g||[]){const J=K.ams_id===255,X=ib(K.ams_id,K.tray_id,J);R.set(X,K.spool?.cost_per_kg??null)}return R},[g]),C=y.useMemo(()=>{const R=new Map;for(const K of g||[]){const J=K.ams_id===255,X=ib(K.ams_id,K.tray_id,J),ce=K.spool;if(!ce){R.set(X,null);continue}R.set(X,Math.max(0,Math.round((ce.label_weight??0)-(ce.weight_used??0))))}return R},[g]),N=y.useMemo(()=>{let R=0;for(const K of b){const J=K.loaded?.globalTrayId;if(J==null)continue;const ce=k.get(J)??null??s;ce>0&&(R+=K.used_grams/1e3*ce)}return R},[b,k,s]),T=y.useMemo(()=>Array.from(k.values()).some(R=>R!=null&&R>0),[k]),j=e?.filaments&&e.filaments.length>0,D=e?.filaments?.some(R=>R.nozzle_id!=null)??!1,P=f?.fila_switch?.installed===!0,E=R=>{const K=f?.fila_switch;if(!K?.installed)return null;const J=K.in_slots.indexOf(R);return J<0?null:K.out_extruders[J]??null};if(!j||!f)return null;const z=x?"#f97316":S?"#facc15":"#00ae42",I=(R,K)=>{if(R>0)if(K===""){const J={...a};delete J[R],n(J)}else n({...a,[R]:parseInt(K,10)})},O=async()=>{u(!0);try{await ie.refreshPrinterStatus(t),await new Promise(R=>setTimeout(R,500)),await c.refetchQueries({queryKey:["printer-status",t]})}finally{u(!1)}};return r.jsxs("div",{className:"mb-4",children:[r.jsxs("button",{type:"button",onClick:()=>p(!m),className:"flex items-center gap-2 text-sm text-bambu-gray hover:text-white transition-colors w-full",children:[r.jsx(Bw,{className:"w-4 h-4",fill:z,stroke:"none"}),r.jsx("span",{children:l("printModal.filamentMapping")}),x?r.jsx("span",{className:"text-xs text-orange-400",children:"(Type not found)"}):S?r.jsx("span",{className:"text-xs text-yellow-400",children:"(Color mismatch)"}):r.jsx("span",{className:"text-xs text-bambu-green",children:"(Ready)"}),m?r.jsx(Zo,{className:"w-4 h-4 ml-auto"}):r.jsx(La,{className:"w-4 h-4 ml-auto"})]}),m&&r.jsxs("div",{className:"mt-2 bg-bambu-dark rounded-lg p-3 space-y-2",children:[r.jsxs("div",{className:"flex items-center justify-between mb-2",children:[r.jsx("span",{className:"text-xs text-bambu-gray",children:"Click to change slot assignment"}),r.jsxs("button",{type:"button",onClick:O,className:"flex items-center gap-1 px-2 py-0.5 text-xs rounded border border-bambu-gray/30 hover:border-bambu-gray hover:bg-bambu-dark-tertiary transition-colors text-bambu-gray hover:text-white",disabled:d,children:[r.jsx(Za,{className:`w-3 h-3 ${d?"animate-spin":""}`}),r.jsx("span",{children:"Re-read"})]})]}),b.map((R,K)=>r.jsxs("div",{className:"grid items-center gap-2 text-xs",style:{gridTemplateColumns:"16px minmax(70px, 1fr) auto 2fr 16px"},children:[r.jsx("span",{title:`Required: ${R.type} - ${Sc(R.color)}`,children:r.jsx(Bw,{className:"w-3 h-3",fill:R.color,stroke:R.color})}),r.jsxs("span",{className:"text-white truncate flex items-center gap-1",children:[D&&R.nozzle_id!=null&&r.jsx("span",{className:"inline-flex items-center justify-center w-3.5 h-3.5 rounded text-[9px] font-bold leading-none bg-bambu-gray/20 text-bambu-gray shrink-0",title:R.nozzle_id===1?l("printModal.leftNozzleTooltip"):l("printModal.rightNozzleTooltip"),children:R.nozzle_id===1?l("printModal.leftNozzle"):l("printModal.rightNozzle")}),R.type," ",r.jsxs("span",{className:"text-bambu-gray",children:["(",R.used_grams,"g)"]})]}),r.jsx("span",{className:"text-bambu-gray",children:"→"}),r.jsxs("select",{value:R.loaded?.globalTrayId??"",onChange:J=>I(R.slot_id||0,J.target.value),className:`flex-1 px-2 py-1 rounded border text-xs bg-bambu-dark-secondary focus:outline-none focus:ring-1 focus:ring-bambu-green ${R.status==="match"?"border-bambu-green/50 text-bambu-green":R.status==="type_only"?"border-yellow-400/50 text-yellow-400":"border-orange-400/50 text-orange-400"} ${R.isManual?"ring-1 ring-blue-400/50":""}`,title:R.isManual?"Manually selected":"Auto-matched",children:[r.jsx("option",{value:"",className:"bg-bambu-dark text-bambu-gray",children:"-- Select slot --"}),v.filter(J=>R.nozzle_id==null||P||J.extruderId===R.nozzle_id).map(J=>{const X=C.get(J.globalTrayId),ce=X!=null?l("printModal.slotRemainingShort",{grams:X,defaultValue:` - ${X}g left`}):"",de=P?E(J.globalTrayId):null,oe=de==null?"":` [${l(de===1?"printModal.leftNozzle":"printModal.rightNozzle")}]`;return r.jsxs("option",{value:J.globalTrayId,className:"bg-bambu-dark text-white",children:[J.label,": ",J.traySubBrands||J.type," (",J.colorName,")",ce,oe]},J.globalTrayId)})]}),R.status==="match"?r.jsx(vr,{className:"w-3 h-3 text-bambu-green"}):R.status==="type_only"?r.jsx("span",{title:"Same type, different color",children:r.jsx(ga,{className:"w-3 h-3 text-yellow-400"})}):r.jsx("span",{title:"Filament type not loaded",children:r.jsx(ga,{className:"w-3 h-3 text-orange-400"})})]},K)),r.jsxs("div",{className:"text-xs text-bambu-gray",children:[l("printModal.totalCost")," ",r.jsx("span",{className:"text-white",children:N>0||T?`${i}${N.toFixed(2)}`:"N/A"})]}),x&&r.jsx("p",{className:"text-xs text-orange-400 mt-2",children:"Required filament type not found in printer."})]})]})}function z9e({filamentReqs:t,availableFilaments:e,overrides:a,onChange:n,forceColorMatch:i,onForceColorMatchChange:s}){const{t:o}=wt(),l=y.useMemo(()=>{const u={};for(const m of e){const p=j1(m.type);u[p]||(u[p]=[]),u[p].push(m)}return u},[e]),c=t?.filaments;if(!c||c.length===0||e.length===0)return null;const d=(u,m)=>{if(m===""){const p={...a};delete p[u],n(p)}else{const[p,f]=m.split("|");n({...a,[u]:{type:p,color:f}})}};return r.jsxs("div",{className:"mb-4",children:[r.jsx("div",{className:"flex items-center gap-2 text-sm text-bambu-gray mb-2",children:r.jsx("span",{children:o("printModal.filamentOverride")})}),r.jsx("p",{className:"text-xs text-bambu-gray mb-2",children:o("printModal.filamentOverrideHint")}),r.jsx("div",{className:"bg-bambu-dark rounded-lg p-3 space-y-2",children:c.map(u=>{const m=a[u.slot_id],p=!!m,f=l[j1(u.type)]||[],g=u.nozzle_id!=null?f.filter(v=>v.extruder_id==null||v.extruder_id===u.nozzle_id):f;return r.jsxs("div",{className:"space-y-1",children:[r.jsxs("div",{className:"grid items-center gap-2 text-xs",style:{gridTemplateColumns:"16px minmax(70px, 1fr) auto 2fr 20px"},children:[r.jsx("span",{title:`${o("printModal.originalFilament")}: ${u.type} - ${Sc(u.color)}`,children:r.jsx(Bw,{className:"w-3 h-3",fill:u.color,stroke:u.color})}),r.jsxs("span",{className:"text-white truncate",children:[u.type," ",r.jsxs("span",{className:"text-bambu-gray",children:["(",u.used_grams,"g)"]})]}),r.jsx("span",{className:"text-bambu-gray",children:"→"}),r.jsxs("select",{value:p?`${m.type}|${m.color}`:"",onChange:v=>d(u.slot_id,v.target.value),disabled:g.length===0,className:`flex-1 px-2 py-1 rounded border text-xs bg-bambu-dark-secondary focus:outline-none focus:ring-1 focus:ring-bambu-green ${p?"border-blue-400/50 text-blue-400":"border-bambu-gray/30 text-bambu-gray"}`,children:[r.jsxs("option",{value:"",className:"bg-bambu-dark text-bambu-gray",children:[o("printModal.originalFilament"),": ",u.type," (",Sc(u.color),")"]}),g.map((v,b)=>r.jsxs("option",{value:`${v.type}|${v.color}`,className:"bg-bambu-dark text-white",children:[v.tray_sub_brands||v.type," (",Sc(v.color),")"]},`${v.type}-${v.color}-${v.tray_sub_brands}-${b}`))]}),p?r.jsx("button",{type:"button",onClick:()=>d(u.slot_id,""),className:"text-bambu-gray hover:text-white transition-colors",title:o("printModal.resetToOriginal"),children:r.jsx(gs,{className:"w-3 h-3"})}):r.jsx("span",{className:"w-3"})]}),r.jsxs("label",{className:"inline-flex items-center gap-1.5 text-xs text-bambu-gray cursor-pointer select-none pl-5",children:[r.jsx("input",{type:"checkbox",checked:i?.[u.slot_id]??!1,onChange:v=>s?.(u.slot_id,v.target.checked),className:"accent-bambu-green w-3 h-3"}),r.jsx(BS,{className:"w-3 h-3"}),o("printModal.forceColorMatch")]})]},u.slot_id)})})]})}function I9e({plates:t,isMultiPlate:e,selectedPlates:a,onToggle:n,onSelectAll:i,onDeselectAll:s,multiSelect:o}){const{t:l}=wt();if(!e||t.length<=1)return null;const c=a.size===t.length;return r.jsxs("div",{className:"mb-4",children:[r.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[r.jsx(Zr,{className:"w-4 h-4 text-bambu-gray"}),r.jsxs("span",{className:"text-sm text-bambu-gray",children:["Select Plate",o?"s":""," to Print"]}),a.size===0&&r.jsxs("span",{className:"text-xs text-orange-400 flex items-center gap-1",children:[r.jsx(ga,{className:"w-3 h-3"}),"Selection required"]}),o&&i&&s&&r.jsx("button",{type:"button",onClick:c?s:i,className:`ml-auto text-xs px-2 py-0.5 rounded-full border transition-colors ${c?"border-bambu-green bg-bambu-green/10 text-bambu-green":"border-bambu-dark-tertiary text-bambu-gray hover:border-bambu-gray"}`,children:c?l("queue.deselectAll"):l("queue.selectAllPlates",{count:t.length})})]}),r.jsx("div",{className:"grid grid-cols-2 gap-2",children:t.map(d=>{const u=a.has(d.index);return r.jsxs("button",{type:"button",onClick:()=>n(d.index),className:`flex items-center gap-2 p-2 rounded-lg border transition-colors text-left ${u?"border-bambu-green bg-bambu-green/10":"border-bambu-dark-tertiary bg-bambu-dark hover:border-bambu-gray"}`,children:[o&&(u?r.jsx(bs,{className:"w-4 h-4 text-bambu-green flex-shrink-0"}):r.jsx(io,{className:"w-4 h-4 text-bambu-gray flex-shrink-0"})),d.has_thumbnail&&d.thumbnail_url!=null?r.jsx("img",{src:Rn(d.thumbnail_url),alt:`Plate ${d.index}`,className:"w-10 h-10 rounded object-cover bg-bambu-dark-tertiary"}):r.jsx("div",{className:"w-10 h-10 rounded bg-bambu-dark-tertiary flex items-center justify-center",children:r.jsx(Zr,{className:"w-5 h-5 text-bambu-gray"})}),r.jsxs("div",{className:"min-w-0 flex-1",children:[r.jsx("p",{className:"text-sm text-white font-medium truncate",children:d.name||`Plate ${d.index}`}),r.jsxs("p",{className:"text-xs text-bambu-gray truncate",children:[d.objects.length>0?d.objects.slice(0,3).join(", ")+(d.objects.length>3?"...":""):`${d.filaments.length} filament${d.filaments.length!==1?"s":""}`,d.print_time_seconds!=null?` • ${cs(d.print_time_seconds)}`:""]}),(()=>{const m=wk(d.bed_type);return m?r.jsxs("p",{className:"text-xs text-bambu-gray flex items-center gap-1 mt-0.5 truncate",title:m.label,children:[r.jsx("img",{src:m.icon,alt:"",className:"w-3.5 h-3.5 object-contain flex-shrink-0"}),r.jsx("span",{className:"truncate",children:m.label})]}):null})()]}),!o&&u&&r.jsx(vr,{className:"w-4 h-4 text-bambu-green flex-shrink-0"})]},d.index)})})]})}const O9e=new Set(["IDLE","FINISH","FAILED"]);function B9e({printerResult:t,filamentReqs:e,onUpdateConfig:a}){const n=na(),[i,s]=y.useState(!1),o=(d,u)=>{if(d<=0)return;const m={...t.config.manualMappings};u===""?delete m[d]:m[d]=parseInt(u,10),a({useDefault:!1,manualMappings:m,autoConfigured:!1})},l=async()=>{s(!0);try{await ie.refreshPrinterStatus(t.printerId),await new Promise(d=>setTimeout(d,500)),await n.refetchQueries({queryKey:["printer-status",t.printerId]})}finally{s(!1)}},c=e.map(d=>{const u=d.slot_id||0,m=t.config.manualMappings[u];let p,f=!1;if(m!==void 0)p=t.loadedFilaments.find(v=>v.globalTrayId===m),f=!0;else{const v=new Set(Object.values(t.config.manualMappings)),b=n.getQueryData(["settings"]);p=A9e(d,t.loadedFilaments,v,b?.prefer_lowest_filament)}let g="mismatch";if(p){const v=p.type?.toUpperCase()===d.type?.toUpperCase(),b=In(p.color)===In(d.color)||pd(p.color,d.color);v&&b?g="match":v&&(g="type_only")}return{req:d,loaded:p,status:g,isManual:f}});return r.jsxs("div",{className:"mt-2 bg-bambu-dark rounded-lg p-3 space-y-2",children:[r.jsxs("div",{className:"flex items-center justify-between mb-2",children:[r.jsx("span",{className:"text-xs text-bambu-gray",children:"Custom slot mapping"}),r.jsxs("button",{type:"button",onClick:l,className:"flex items-center gap-1 px-2 py-0.5 text-xs rounded border border-bambu-gray/30 hover:border-bambu-gray hover:bg-bambu-dark-tertiary transition-colors text-bambu-gray hover:text-white",disabled:i,children:[r.jsx(Za,{className:`w-3 h-3 ${i?"animate-spin":""}`}),r.jsx("span",{children:"Re-read"})]})]}),c.map(({req:d,loaded:u,status:m,isManual:p},f)=>r.jsxs("div",{className:"grid items-center gap-2 text-xs",style:{gridTemplateColumns:"16px minmax(70px, 1fr) auto 2fr 16px"},children:[r.jsx("span",{title:`Required: ${d.type} - ${Sc(d.color)}`,children:r.jsx(Bw,{className:"w-3 h-3",fill:d.color,stroke:d.color})}),r.jsxs("span",{className:"text-white truncate",children:[d.type," ",r.jsxs("span",{className:"text-bambu-gray",children:["(",d.used_grams,"g)"]})]}),r.jsx("span",{className:"text-bambu-gray",children:"→"}),r.jsxs("select",{value:u?.globalTrayId??"",onChange:g=>o(d.slot_id||0,g.target.value),className:`flex-1 px-2 py-1 rounded border text-xs bg-bambu-dark-secondary focus:outline-none focus:ring-1 focus:ring-bambu-green ${m==="match"?"border-bambu-green/50 text-bambu-green":m==="type_only"?"border-yellow-400/50 text-yellow-400":"border-orange-400/50 text-orange-400"} ${p?"ring-1 ring-blue-400/50":""}`,title:p?"Manually selected":"Auto-matched",children:[r.jsx("option",{value:"",className:"bg-bambu-dark text-bambu-gray",children:"-- Select slot --"}),Dse(t.loadedFilaments,d.nozzle_id).map(g=>r.jsxs("option",{value:g.globalTrayId,className:"bg-bambu-dark text-white",children:[g.label,": ",g.traySubBrands||g.type," (",g.colorName,")"]},g.globalTrayId))]}),m==="match"?r.jsx(vr,{className:"w-3 h-3 text-bambu-green"}):m==="type_only"?r.jsx("span",{title:"Same type, different color",children:r.jsx(ga,{className:"w-3 h-3 text-yellow-400"})}):r.jsx("span",{title:"Filament type not loaded",children:r.jsx(ga,{className:"w-3 h-3 text-orange-400"})})]},f))]})}function U9e({printers:t,selectedPrinterIds:e,onMultiSelect:a,isLoading:n=!1,allowMultiple:i=!1,showInactive:s=!1,disableBusy:o=!1,printerMappingResults:l,filamentReqs:c,onAutoConfigurePrinter:d,onUpdatePrinterConfig:u,assignmentMode:m="printer",onAssignmentModeChange:p,targetModel:f,onTargetModelChange:g,targetLocation:v,onTargetLocationChange:b,slicedForModel:x}){const[S,k]=y.useState(!1),C=s?t:t.filter(ne=>ne.is_active),N=df({queries:C.map(ne=>({queryKey:["printerStatus",ne.id],queryFn:()=>ie.getPrinterStatus(ne.id),staleTime:5e3}))}),T=y.useMemo(()=>{const ne=new Map;return C.forEach((me,pe)=>{const xe=N[pe];xe?.data&&ne.set(me.id,xe.data)}),ne},[C,N]),j=ne=>{const me=T.get(ne);return me?me.connected?!O9e.has(me.state??""):!0:!1},D=ne=>{const me=T.get(ne);if(!me)return null;if(!me.connected)return"Offline";const pe=me.state;return pe?pe==="RUNNING"?me.stg_cur_name||"Printing":pe==="PREPARE"?"Preparing":pe==="PAUSE"?"Paused":pe==="IDLE"?"Idle":pe==="FINISH"?"Finished":pe==="FAILED"?"Failed":pe:null},P=y.useMemo(()=>{if(m!=="printer"||!x||S)return C;const ne=C.filter(me=>me.model===x);return ne.length>0?ne:C},[C,m,x,S]),E=C.length-P.length,z=y.useMemo(()=>{const ne=C.map(me=>me.model).filter(me=>!!me);return[...new Set(ne)].sort()},[C]),I=y.useMemo(()=>{if(!f)return[];const ne=C.filter(me=>me.model===f&&me.location).map(me=>me.location).filter(me=>!!me);return[...new Set(ne)].sort()},[C,f]),O=p&&g&&z.length>0,R=i&&e.length>1&&l&&c?.filaments&&c.filaments.length>0&&d&&u;if(n)return r.jsx("div",{className:"flex justify-center py-8",children:r.jsx(lt,{className:"w-6 h-6 text-bambu-green animate-spin"})});if(P.length===0)return r.jsxs("div",{className:"flex items-center gap-2 text-red-400 text-sm mb-4",children:[r.jsx(_n,{className:"w-4 h-4"}),"No ",s?"":"active ","printers available"]});const K=ne=>{o&&j(ne)||(i?e.includes(ne)?a(e.filter(me=>me!==ne)):a([...e,ne]):a([ne]))},J=()=>{const ne=o?P.filter(me=>!j(me.id)):P;a(ne.map(me=>me.id))},X=()=>{a([])},ce=(ne,me,pe)=>{pe.stopPropagation(),!(!d||!u)&&(me?d(ne):u(ne,{useDefault:!0,manualMappings:{},autoConfigured:!1}))},de=ne=>e.includes(ne),oe=e.length,Y=ne=>l?.find(me=>me.printerId===ne);return r.jsxs("div",{className:"space-y-2 mb-6",children:[O&&r.jsxs("div",{className:"flex gap-2 mb-4",children:[r.jsxs("button",{type:"button",onClick:()=>{p("printer"),g(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg border transition-colors ${m==="printer"?"border-bambu-green bg-bambu-green/10 text-white":"border-bambu-dark-tertiary bg-bambu-dark text-bambu-gray hover:border-bambu-gray"}`,children:[r.jsx(gr,{className:"w-4 h-4"}),r.jsx("span",{className:"text-sm",children:"Specific Printer"})]}),r.jsxs("button",{type:"button",onClick:()=>{p("model"),a([]);const ne=x&&z.includes(x)?x:z[0];g(ne)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg border transition-colors ${m==="model"?"border-bambu-green bg-bambu-green/10 text-white":"border-bambu-dark-tertiary bg-bambu-dark text-bambu-gray hover:border-bambu-gray"}`,children:[r.jsx(km,{className:"w-4 h-4"}),r.jsxs("span",{className:"text-sm",children:["Any ",x||"Model"]})]})]}),m==="model"&&O&&r.jsxs("div",{className:"space-y-3 mb-4",children:[!x&&r.jsxs("div",{children:[r.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Target Model"}),r.jsxs("select",{value:f||"",onChange:ne=>{g(ne.target.value||null),b&&b(null)},className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none text-sm",children:[r.jsx("option",{value:"",children:"Select a model..."}),z.map(ne=>r.jsx("option",{value:ne,children:ne},ne))]})]}),f&&I.length>0&&b&&r.jsxs("div",{children:[r.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Location Filter (optional)"}),r.jsxs("select",{value:v||"",onChange:ne=>b(ne.target.value||null),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none text-sm",children:[r.jsx("option",{value:"",children:"Any location"}),I.map(ne=>r.jsx("option",{value:ne,children:ne},ne))]})]}),f&&r.jsxs("p",{className:"text-xs text-bambu-gray",children:["Scheduler will assign to first available idle ",f," printer",v?` in ${v}`:""]})]}),m==="printer"&&i&&P.length>1&&r.jsxs("div",{className:"flex items-center justify-between text-xs text-bambu-gray mb-2",children:[r.jsx("span",{children:oe===0?"Select printers":`${oe} printer${oe!==1?"s":""} selected`}),r.jsxs("div",{className:"flex gap-2",children:[oe0&&r.jsx("button",{type:"button",onClick:X,className:"text-bambu-gray hover:text-white transition-colors",children:"Clear"})]})]}),m==="printer"&&P.map(ne=>{const me=de(ne.id),pe=Y(ne.id),xe=pe&&!pe.config.useDefault,V=j(ne.id),Q=o&&V,A=D(ne.id);return r.jsxs("div",{children:[r.jsxs("button",{type:"button",onClick:()=>K(ne.id),disabled:Q,className:`w-full flex items-center gap-3 p-3 rounded-lg border transition-colors ${Q?"border-bambu-dark-tertiary bg-bambu-dark opacity-50 cursor-not-allowed":me?"border-bambu-green bg-bambu-green/10":"border-bambu-dark-tertiary bg-bambu-dark hover:border-bambu-gray"} ${ne.is_active?"":"opacity-60"}`,children:[r.jsx("div",{className:`p-2 rounded-lg ${Q?"bg-bambu-dark-tertiary":me?"bg-bambu-green/20":"bg-bambu-dark-tertiary"}`,children:r.jsx(gr,{className:`w-5 h-5 ${Q?"text-bambu-gray/50":me?"text-bambu-green":"text-bambu-gray"}`})}),r.jsxs("div",{className:"text-left flex-1",children:[r.jsxs("p",{className:`font-medium ${Q?"text-bambu-gray":"text-white"}`,children:[ne.name,!ne.is_active&&r.jsx("span",{className:"text-bambu-gray text-xs ml-2",children:"(inactive)"})]}),r.jsxs("p",{className:"text-xs text-bambu-gray",children:[ne.model||"Unknown model"," • ",ne.ip_address]})]}),A&&r.jsx("span",{className:`text-xs px-2 py-0.5 rounded-full ${V?"bg-yellow-500/20 text-yellow-400":"bg-bambu-green/20 text-bambu-green"}`,children:A}),i&&r.jsx("div",{className:`w-5 h-5 rounded border-2 flex items-center justify-center transition-colors ${Q?"border-bambu-gray/30":me?"bg-bambu-green border-bambu-green":"border-bambu-gray/50"}`,children:me&&r.jsx(vr,{className:"w-3 h-3 text-white"})})]}),me&&R&&pe&&r.jsxs("div",{className:"ml-4 mt-2 mb-3",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",onClick:F=>F.stopPropagation(),children:[r.jsx("input",{type:"checkbox",checked:xe,onChange:F=>ce(ne.id,F.target.checked,F),className:"w-3.5 h-3.5 rounded border-bambu-gray/30 bg-bambu-dark-secondary text-bambu-green focus:ring-bambu-green focus:ring-offset-0"}),r.jsx("span",{className:"text-xs text-bambu-gray",children:"Custom mapping"})]}),r.jsxs("span",{className:`text-xs ml-2 ${pe.matchStatus==="full"?"text-bambu-green":pe.matchStatus==="partial"?"text-yellow-400":"text-orange-400"}`,children:["(",pe.exactMatches,"/",pe.totalSlots," matched)"]}),pe.isLoading&&r.jsx(Za,{className:"w-3 h-3 text-bambu-gray animate-spin"}),xe&&r.jsxs("button",{type:"button",onClick:F=>{F.stopPropagation(),d(ne.id)},className:"ml-auto flex items-center gap-1 px-2 py-0.5 text-xs rounded border border-bambu-gray/30 hover:border-bambu-gray hover:bg-bambu-dark-tertiary transition-colors text-bambu-gray hover:text-white",children:[r.jsx(HI,{className:"w-3 h-3"}),"Auto"]})]}),xe&&r.jsx(B9e,{printerResult:pe,filamentReqs:c.filaments,onUpdateConfig:F=>u(ne.id,F)})]})]},ne.id)}),m==="printer"&&E>0&&!S&&r.jsxs("button",{type:"button",onClick:()=>k(!0),className:"text-xs text-bambu-gray hover:text-white transition-colors mt-2 flex items-center gap-1",children:[r.jsx(ga,{className:"w-3 h-3 text-yellow-400"}),E," other printer",E>1?"s":""," hidden (different model) —",r.jsx("span",{className:"underline",children:"show all"})]}),m==="printer"&&S&&x&&r.jsx("button",{type:"button",onClick:()=>k(!1),className:"text-xs text-bambu-gray hover:text-white transition-colors mt-2",children:r.jsxs("span",{className:"underline",children:["Show only ",x," printers"]})}),m==="printer"&&oe===0&&r.jsxs("p",{className:"text-xs text-orange-400 mt-1 flex items-center gap-1",children:[r.jsx(_n,{className:"w-3 h-3"}),"Select at least one printer"]}),m==="model"&&!f&&r.jsxs("p",{className:"text-xs text-orange-400 mt-1 flex items-center gap-1",children:[r.jsx(_n,{className:"w-3 h-3"}),"Select a target printer model"]})]})}function H9e({options:t,onChange:e,defaultExpanded:a=!1,showDualNozzleOptions:n=!1}){const{t:i}=wt(),[s,o]=y.useState(a),c=[{key:"bed_levelling",label:i("settings.defaultBedLevelling"),desc:i("settings.defaultBedLevellingDesc")},{key:"flow_cali",label:i("settings.defaultFlowCali"),desc:i("settings.defaultFlowCaliDesc")},{key:"vibration_cali",label:i("settings.defaultVibrationCali"),desc:i("settings.defaultVibrationCaliDesc")},{key:"layer_inspect",label:i("settings.defaultLayerInspect"),desc:i("settings.defaultLayerInspectDesc")},{key:"timelapse",label:i("settings.defaultTimelapse"),desc:i("settings.defaultTimelapseDesc")},{key:"nozzle_offset_cali",label:i("settings.defaultNozzleOffsetCali"),desc:i("settings.defaultNozzleOffsetCaliDesc"),dualNozzleOnly:!0}].filter(u=>!u.dualNozzleOnly||n),d=u=>{e({...t,[u]:!t[u]})};return r.jsxs("div",{className:"mb-4",children:[r.jsxs("button",{type:"button",onClick:()=>o(!s),className:"flex items-center gap-2 text-sm text-bambu-gray hover:text-white transition-colors w-full",children:[r.jsx(Sy,{className:"w-4 h-4"}),r.jsx("span",{children:i("queue.bulkEdit.printOptions")}),s?r.jsx(Zo,{className:"w-4 h-4 ml-auto"}):r.jsx(La,{className:"w-4 h-4 ml-auto"})]}),s&&r.jsx("div",{className:"mt-2 bg-bambu-dark rounded-lg p-3 space-y-2",children:c.map(({key:u,label:m,desc:p})=>r.jsxs("label",{className:"flex items-center justify-between cursor-pointer group",children:[r.jsxs("div",{children:[r.jsx("span",{className:"text-sm text-white",children:m}),r.jsx("p",{className:"text-xs text-bambu-gray",children:p})]}),r.jsx("div",{className:`relative w-10 h-5 rounded-full transition-colors ${t[u]?"bg-bambu-green":"bg-bambu-dark-tertiary"}`,onClick:()=>d(u),children:r.jsx("div",{className:`absolute top-0.5 w-4 h-4 rounded-full bg-white transition-transform ${t[u]?"translate-x-5":"translate-x-0.5"}`})})]},u))})]})}function q9e({options:t,onChange:e,dateFormat:a="system",timeFormat:n="system",canControlPrinter:i=!0,showStagger:s=!1,printerCount:o=0,hasGcodeSnippets:l=!1}){const{t:c}=wt(),[d,u]=y.useState(""),[m,p]=y.useState(""),[f,g]=y.useState(!0),[v,b]=y.useState(!0),x=y.useRef(null),S=y.useRef(!1);y.useEffect(()=>{if(t.scheduleType!=="scheduled"){S.current=!1;return}if(!S.current){S.current=!0;let P;t.scheduledTime?(P=new Date(t.scheduledTime),isNaN(P.getTime())&&(P=new Date,P.setHours(P.getHours()+1,0,0,0))):(P=new Date,P.setHours(P.getHours()+1,0,0,0),e({...t,scheduledTime:g3(P)})),u(f3(P,a)),p(U8(P,n)),g(!0),b(!0)}},[t.scheduleType,t.scheduledTime,a,n,e,t]);const k=P=>{e({...t,scheduleType:P})},C=(P,E)=>{const z=D0e(P,a),I=F0e(E);g(!!z),b(!!I),z&&I&&(z.setHours(I.hours,I.minutes,0,0),z>new Date&&e({...t,scheduledTime:g3(z)}))},N=P=>{u(P),C(P,m)},T=P=>{p(P),C(d,P)},j=P=>{const E=P.target.value;if(E){const z=new Date(E);isNaN(z.getTime())||(u(f3(z,a)),p(U8(z,n)),g(!0),b(!0),e({...t,scheduledTime:E}))}},D=()=>{x.current?.showPicker()};return r.jsxs("div",{className:"space-y-4",children:[r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-2",children:"When to print"}),r.jsxs("div",{className:"flex gap-2",children:[r.jsxs("button",{type:"button",className:`flex-1 px-2 py-2 rounded-lg border text-sm flex items-center justify-center gap-1.5 transition-colors ${t.scheduleType==="asap"?"bg-bambu-green border-bambu-green text-white":"bg-bambu-dark border-bambu-dark-tertiary text-bambu-gray hover:text-white"}`,onClick:()=>k("asap"),children:[r.jsx(Ja,{className:"w-4 h-4"}),"ASAP"]}),r.jsxs("button",{type:"button",className:`flex-1 px-2 py-2 rounded-lg border text-sm flex items-center justify-center gap-1.5 transition-colors ${t.scheduleType==="scheduled"?"bg-bambu-green border-bambu-green text-white":"bg-bambu-dark border-bambu-dark-tertiary text-bambu-gray hover:text-white"}`,onClick:()=>k("scheduled"),children:[r.jsx(kn,{className:"w-4 h-4"}),"Scheduled"]}),r.jsxs("button",{type:"button",className:`flex-1 px-2 py-2 rounded-lg border text-sm flex items-center justify-center gap-1.5 transition-colors ${t.scheduleType==="manual"?"bg-bambu-green border-bambu-green text-white":"bg-bambu-dark border-bambu-dark-tertiary text-bambu-gray hover:text-white"}`,onClick:()=>k("manual"),children:[r.jsx(lJ,{className:"w-4 h-4"}),"Queue Only"]})]})]}),t.scheduleType==="scheduled"&&r.jsxs("div",{children:[r.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Date & Time"}),r.jsxs("div",{className:"flex gap-2",children:[r.jsxs("div",{className:"flex-1 relative",children:[r.jsx("input",{type:"text",className:`w-full px-3 py-2 pr-10 bg-bambu-dark border rounded-lg text-white focus:outline-none ${f?"border-bambu-dark-tertiary focus:border-bambu-green":"border-red-500"}`,value:d,onChange:P=>N(P.target.value),placeholder:j0e(a)}),r.jsx("button",{type:"button",onClick:D,className:"absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white",title:"Open calendar",children:r.jsx(kn,{className:"w-4 h-4"})}),r.jsx("input",{ref:x,type:"datetime-local",className:"absolute top-0 left-0 w-0 h-0 opacity-0 pointer-events-none",value:t.scheduledTime,onChange:j,tabIndex:-1})]}),r.jsx("div",{className:"w-32",children:r.jsx("input",{type:"text",className:`w-full px-3 py-2 bg-bambu-dark border rounded-lg text-white focus:outline-none ${v?"border-bambu-dark-tertiary focus:border-bambu-green":"border-red-500"}`,value:m,onChange:P=>T(P.target.value),placeholder:M0e(n)})})]}),(!f||!v)&&r.jsx("p",{className:"mt-1 text-xs text-red-400",children:"Please enter a valid date and time"})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("input",{type:"checkbox",id:"requirePrevious",checked:t.requirePreviousSuccess,onChange:P=>e({...t,requirePreviousSuccess:P.target.checked}),className:"rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),r.jsx("label",{htmlFor:"requirePrevious",className:"text-sm text-bambu-gray",children:"Only start if previous print succeeded"})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("input",{type:"checkbox",id:"autoOffAfter",checked:t.autoOffAfter,onChange:P=>e({...t,autoOffAfter:P.target.checked}),disabled:!i,className:"rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green disabled:opacity-50"}),r.jsxs("label",{htmlFor:"autoOffAfter",className:`text-sm flex items-center gap-1 ${i?"text-bambu-gray":"text-bambu-gray/50"}`,children:[r.jsx(Tu,{className:"w-3.5 h-3.5"}),"Power off printer when done"]})]}),l&&r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("input",{type:"checkbox",id:"gcodeInjection",checked:t.gcodeInjection,onChange:P=>e({...t,gcodeInjection:P.target.checked}),className:"rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),r.jsxs("label",{htmlFor:"gcodeInjection",className:"text-sm flex items-center gap-1 text-bambu-gray",children:[r.jsx(tv,{className:"w-3.5 h-3.5"}),c("printModal.gcodeInjection","Inject auto-print G-code")]})]}),s&&t.scheduleType!=="manual"&&r.jsxs("div",{className:"space-y-3",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("input",{type:"checkbox",id:"staggerEnabled",checked:t.staggerEnabled,onChange:P=>e({...t,staggerEnabled:P.target.checked}),className:"rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),r.jsxs("label",{htmlFor:"staggerEnabled",className:"text-sm flex items-center gap-1 text-bambu-gray",children:[r.jsx(Zr,{className:"w-3.5 h-3.5"}),c("printModal.staggerPrinterStarts","Stagger printer starts")]})]}),t.staggerEnabled&&r.jsxs("div",{className:"ml-6 space-y-3",children:[r.jsxs("div",{className:"flex gap-3",children:[r.jsxs("div",{className:"flex-1",children:[r.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:c("printModal.staggerGroupSize","Group size")}),r.jsx("input",{type:"number",min:1,max:o,value:t.staggerGroupSize,onChange:P=>e({...t,staggerGroupSize:Math.max(1,parseInt(P.target.value)||1)}),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green"})]}),r.jsxs("div",{className:"flex-1",children:[r.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:c("printModal.staggerInterval","Interval (min)")}),r.jsx("input",{type:"number",min:1,max:60,value:t.staggerIntervalMinutes,onChange:P=>e({...t,staggerIntervalMinutes:Math.max(1,parseInt(P.target.value)||1)}),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green"})]})]}),o>0&&(()=>{const P=Math.ceil(o/t.staggerGroupSize),E=o%t.staggerGroupSize,z=(P-1)*t.staggerIntervalMinutes;return r.jsxs("p",{className:"text-xs text-bambu-gray",children:[c("printModal.staggerPreview","{{printers}} printers → {{groups}} groups of {{size}}, starting every {{interval}} min",{printers:o,groups:P,size:t.staggerGroupSize,interval:t.staggerIntervalMinutes}),E!==0&&t.staggerGroupSize1?` (${c("printModal.staggerTotal","total: {{minutes}} min",{minutes:z})})`:""]})})()]})]}),r.jsx("p",{className:"text-xs text-bambu-gray",children:t.scheduleType==="asap"?"Print will start as soon as the printer is idle.":t.scheduleType==="scheduled"?"Print will start at the scheduled time if the printer is idle. If busy, it will wait until the printer becomes available.":"Print will be staged but won't start automatically. Use the Start button to release it to the queue."})]})}const xl={bed_levelling:!0,flow_cali:!1,vibration_cali:!0,layer_inspect:!1,timelapse:!1,nozzle_offset_cali:!0},TF={scheduleType:"asap",scheduledTime:"",requirePreviousSuccess:!1,autoOffAfter:!1,gcodeInjection:!1,staggerEnabled:!1,staggerGroupSize:2,staggerIntervalMinutes:5};function _c({mode:t,archiveId:e,libraryFileId:a,archiveName:n,queueItem:i,initialSelectedPrinterIds:s,onClose:o,onSuccess:l,projectId:c,cleanupLibraryAfterDispatch:d}){const{t:u}=wt(),m=na(),{showToast:p}=sa(),{hasPermission:f}=nr(),g=!!a&&!e,[v,b]=y.useState(()=>t==="edit-queue-item"&&i?.printer_id?[i.printer_id]:s?.length?s:[]),[x,S]=y.useState(()=>t==="edit-queue-item"&&i?.plate_id!=null?new Set([i.plate_id]):new Set),k=x.size===1?[...x][0]:null,[C,N]=y.useState(1),[T,j]=y.useState(()=>t==="edit-queue-item"&&i?{bed_levelling:i.bed_levelling??xl.bed_levelling,flow_cali:i.flow_cali??xl.flow_cali,vibration_cali:i.vibration_cali??xl.vibration_cali,layer_inspect:i.layer_inspect??xl.layer_inspect,timelapse:i.timelapse??xl.timelapse,nozzle_offset_cali:i.nozzle_offset_cali??xl.nozzle_offset_cali}:xl),[D,P]=y.useState(()=>{if(t==="edit-queue-item"&&i){let Ce="asap";i.manual_start?Ce="manual":i.scheduled_time&&!mY(i.scheduled_time)&&(Ce="scheduled");let Ye="";if(i.scheduled_time&&!mY(i.scheduled_time)){const it=Ua(i.scheduled_time)??new Date;Ye=g3(it)}return{scheduleType:Ce,scheduledTime:Ye,requirePreviousSuccess:i.require_previous_success,autoOffAfter:i.auto_off_after,gcodeInjection:i.gcode_injection??!1,staggerEnabled:!1,staggerGroupSize:TF.staggerGroupSize,staggerIntervalMinutes:TF.staggerIntervalMinutes}}return TF}),[E,z]=y.useState(()=>{if(t==="edit-queue-item"&&i?.ams_mapping&&Array.isArray(i.ams_mapping)){const Ce={};return i.ams_mapping.forEach((Ye,it)=>{Ye!==-1&&(Ce[it+1]=Ye)}),Ce}return{}}),[I,O]=y.useState({}),[R,K]=y.useState(()=>t==="edit-queue-item"&&i?.target_model?"model":"printer"),[J,X]=y.useState(()=>t==="edit-queue-item"&&i?.target_model?i.target_model:null),[ce,de]=y.useState(()=>t==="edit-queue-item"&&i?.target_location?i.target_location:null),[oe,Y]=y.useState(()=>{if(t==="edit-queue-item"&&i?.filament_overrides){const Ce={};for(const Ye of i.filament_overrides)Ce[Ye.slot_id]={type:Ye.type,color:Ye.color};return Ce}return{}}),[ne,me]=y.useState(()=>{if(t==="edit-queue-item"&&i?.filament_overrides){const Ce={};for(const Ye of i.filament_overrides)Ce[Ye.slot_id]=Ye.force_color_match===!0;return Ce}return{}}),[pe]=y.useState(()=>t==="edit-queue-item"&&i?.printer_id?[i.printer_id]:[]),[xe]=y.useState(()=>t==="edit-queue-item"&&i?i.plate_id:null),[V,Q]=y.useState(!1),[A,F]=y.useState({current:0,total:0}),[U,$]=y.useState(null),[H,le]=y.useState(new Set),B=v.length,q=v.length>0?v[0]:null,{data:Z}=$e({queryKey:["settings"],queryFn:ie.getSettings}),ee=y.useRef(!1);y.useEffect(()=>{!Z||ee.current||t==="edit-queue-item"||(ee.current=!0,j({bed_levelling:Z.default_bed_levelling??xl.bed_levelling,flow_cali:Z.default_flow_cali??xl.flow_cali,vibration_cali:Z.default_vibration_cali??xl.vibration_cali,layer_inspect:Z.default_layer_inspect??xl.layer_inspect,timelapse:Z.default_timelapse??xl.timelapse,nozzle_offset_cali:Z.default_nozzle_offset_cali??xl.nozzle_offset_cali}))},[Z,t]);const re=y.useRef(!1);y.useEffect(()=>{!Z||re.current||t==="edit-queue-item"||(re.current=!0,P(Ce=>({...Ce,staggerGroupSize:Z.stagger_group_size??Ce.staggerGroupSize,staggerIntervalMinutes:Z.stagger_interval_minutes??Ce.staggerIntervalMinutes})))},[Z,t]);const se=Ho(Z?.currency||"USD"),fe=Z?.default_filament_cost??0,{data:ue,isLoading:he}=$e({queryKey:["printers"],queryFn:ie.getPrinters}),{data:G}=$e({queryKey:["spool-assignments"],queryFn:()=>ie.getAssignments(),staleTime:30*1e3,enabled:(t==="reprint"||t==="add-to-queue")&&R==="printer"||g&&t==="reprint"}),{data:L}=$e({queryKey:["archive",e],queryFn:()=>ie.getArchive(e),enabled:!!e&&!g}),{data:ae}=$e({queryKey:["library-file",a],queryFn:()=>ie.getLibraryFile(a),enabled:g&&!!a}),ge=L?.sliced_for_model||ae?.sliced_for_model||null,{data:be,isError:ve}=$e({queryKey:["archive-plates",e],queryFn:()=>ie.getArchivePlates(e),enabled:!!e&&!g,retry:!1}),{data:De}=$e({queryKey:["library-file-plates",a],queryFn:()=>ie.getLibraryFilePlates(a),enabled:g&&!!a}),Me=g?De:be,{data:Te,isError:Ue}=$e({queryKey:["archive-filaments",e,k],queryFn:()=>ie.getArchiveFilamentRequirements(e,k??void 0),enabled:!!e&&!g&&(k!==null||!Me?.is_multi_plate),retry:!1}),{data:Ne}=$e({queryKey:["library-file-filaments",a,k],queryFn:()=>ie.getLibraryFileFilamentRequirements(a,k??void 0),enabled:g&&!!a&&(k!==null||!Me?.is_multi_plate)}),Ie=!g&&(ve||Ue),Re=g?Ne:Te,He=y.useMemo(()=>{if(!(k===null||!Me?.plates?.length))return Me.plates.find(Ce=>Ce.index===k)?.name||void 0},[Me,k]),{data:ze}=$e({queryKey:["available-filaments",J,ce],queryFn:()=>ie.getAvailableFilaments(J,ce??void 0),enabled:R==="model"&&!!J}),{data:nt}=$e({queryKey:["printer-status",q],queryFn:()=>ie.getPrinterStatus(q),enabled:!!q}),{amsMapping:Oe}=Fse(Re,nt,E,Z?.prefer_lowest_filament),tt=D9e(v,ue,Re,E,I,O,Z?.prefer_lowest_filament);y.useEffect(()=>{Me?.plates&&Me.plates.length>=1&&x.size===0&&S(new Set([Me.plates[0].index]))},[Me,x.size]),y.useEffect(()=>{if(t==="edit-queue-item")return;const Ce=ue?.filter(Ye=>Ye.is_active)||[];Ce.length===1&&v.length===0&&b([Ce[0].id])},[t,ue,v.length]),y.useEffect(()=>{t==="edit-queue-item"?(JSON.stringify(v.sort())!==JSON.stringify(pe.sort())||k!==xe)&&(z({}),O({}),le(new Set)):(z({}),O({}),le(new Set))},[t,v,k,pe,xe]);const[Ee,Xe]=y.useState(J),[Ve,je]=y.useState(k);y.useEffect(()=>{(J!==Ee||k!==Ve)&&(Xe(J),je(k),(t!=="edit-queue-item"||Ee!==null)&&(Y({}),me({})))},[J,k,Ee,Ve,t]),y.useEffect(()=>{if(!Z?.per_printer_mapping_expanded||v.length<=1)return;const Ce=v.filter(Ye=>{if(H.has(Ye))return!1;const it=tt.printerResults.find(Ae=>Ae.printerId===Ye);return it&&it.status&&!it.isLoading});Ce.length>0&&(le(Ye=>{const it=new Set(Ye);return Ce.forEach(Ae=>it.add(Ae)),it}),Ce.forEach(Ye=>{tt.autoConfigurePrinter(Ye)}))},[Z?.per_printer_mapping_expanded,v,H,tt]),y.useEffect(()=>{const Ce=Ye=>{Ye.key==="Escape"&&!V&&o()};return window.addEventListener("keydown",Ce),()=>window.removeEventListener("keydown",Ce)},[o,V]);const Be=Me?.is_multi_plate??!1,Qe=Me?.plates??[],Ge=y.useMemo(()=>{const Ce=new Map;return G&&G.forEach(Ye=>{const it=Ye.ams_id===255,Ae=ib(Ye.ams_id,Ye.tray_id,it),we=Ce.get(Ye.printer_id)??new Map;we.set(Ae,Ye),Ce.set(Ye.printer_id,we)}),Ce},[G]),Fe=y.useMemo(()=>{if(!U||U.length===0)return"";const Ce=U.map(Ye=>u("printModal.insufficientFilamentLine",{printer:Ye.printerName,slot:Ye.slotLabel,required:Math.round(Ye.requiredGrams),remaining:Math.round(Ye.remainingGrams)}));return[u("printModal.insufficientFilamentMessage"),...Ce].join(` -`)},[U,u]),rt=at({mutationFn:Ce=>ie.addToQueue(Ce)}),Je=at({mutationFn:Ce=>ie.updateQueueItem(i.id,Ce),onSuccess:()=>{m.invalidateQueries({queryKey:["queue"]}),p("Queue item updated"),l?.(),o()},onError:Ce=>{p(Ce.message||"Failed to update queue item","error")}}),Ct=D.staggerEnabled&&v.length>1,$t=async(Ce,Ye)=>{if(Ce?.preventDefault(),!Ye?.skipFilamentCheck&&!Z?.disable_filament_warnings&&(t==="reprint"||t==="add-to-queue")&&R==="printer"){const et=[],Ze=Re?.filaments??[];if(Ze.length>0&&Ge.size>0){const St=(ft,_t)=>!Number.isFinite(ft)||ft<=0||!Number.isFinite(_t)||_t<0?null:Math.max(0,ft-_t);for(const ft of v){const _t=v.length>1?tt.getFinalMapping(ft):Oe;if(!_t)continue;const Pt=v.length>1?tt.printerResults.find(ke=>ke.printerId===ft)?.status:nt,Wt=vk(Pt),yt=new Map(Wt.map(ke=>[ke.globalTrayId,ke.label])),Ot=Ge.get(ft),ca=ue?.find(ke=>ke.id===ft)?.name??`Printer ${ft}`;Ot&&Ze.forEach(ke=>{if(!ke.slot_id||ke.slot_id<=0)return;const xt=_t[ke.slot_id-1];if(!Number.isFinite(xt)||xt<0)return;const Lt=Ot.get(xt)?.spool;if(!Lt)return;const qt=St(Lt.label_weight,Lt.weight_used);qt!==null&&(qt>=ke.used_grams||et.push({printerName:ca,slotLabel:yt.get(xt)??`Slot ${ke.slot_id}`,requiredGrams:ke.used_grams,remainingGrams:qt}))})}}if(et.length>0){$(et);return}}if(R==="printer"&&v.length===0){p("Please select at least one printer","error");return}if(R==="model"&&!J){p("Please select a target printer model","error");return}Q(!0);const it=x.size>1?Qe.filter(et=>x.has(et.index)):[null],Ae=R==="model"?it.length:v.length*it.length;F({current:0,total:Ae});const we={success:0,failed:0,errors:[]},ct=et=>{if(v.length>1){const Ze=I[et];if(Ze&&!Ze.useDefault)return tt.getFinalMapping(et)}return Oe},We=(()=>{const et=[];if(Re?.filaments)for(const Ze of Re.filaments){const St=oe[Ze.slot_id],ft=ne[Ze.slot_id]??!1,_t=St?.type??Ze.type,Pt=St?.color??Ze.color;(St||ft)&&et.push({slot_id:Ze.slot_id,type:_t,color:Pt,color_name:Sc(Pt),force_color_match:ft})}else for(const[Ze,{type:St,color:ft}]of Object.entries(oe)){const _t=parseInt(Ze,10),Pt=ne[_t]??!1;et.push({slot_id:_t,type:St,color:ft,color_name:Sc(ft),force_color_match:Pt})}return et.length>0?et:void 0})(),st=(et,Ze)=>({printer_id:R==="printer"?et:null,target_model:R==="model"?J:null,target_location:R==="model"?ce:null,filament_overrides:R==="model"?We:void 0,archive_id:g?void 0:e,library_file_id:g?a:void 0,require_previous_success:D.requirePreviousSuccess,auto_off_after:D.autoOffAfter,gcode_injection:D.gcodeInjection,manual_start:D.scheduleType==="manual",ams_mapping:et?ct(et):void 0,plate_id:Ze!==void 0?Ze:k,scheduled_time:D.scheduleType==="scheduled"&&D.scheduledTime?new Date(D.scheduledTime).toISOString():void 0,...T,project_id:c??void 0});if(R==="model"){if(t==="reprint"){p("Model-based assignment only works with queue mode","error"),Q(!1);return}let et=0;for(const Ze of it){et++,F({current:et,total:Ae});const St=Ze?Ze.index:k;try{if(t==="edit-queue-item"&&!Ze){const ft={printer_id:null,target_model:J,target_location:ce,filament_overrides:We||null,require_previous_success:D.requirePreviousSuccess,auto_off_after:D.autoOffAfter,gcode_injection:D.gcodeInjection,manual_start:D.scheduleType==="manual",ams_mapping:void 0,plate_id:St,scheduled_time:D.scheduleType==="scheduled"&&D.scheduledTime?new Date(D.scheduledTime).toISOString():null,...T};await Je.mutateAsync(ft)}else{const ft=st(null,St);Xt>1&&(ft.quantity=Xt),await rt.mutateAsync(ft)}we.success++}catch(ft){we.failed++;const _t=Ze?Ze.name||`Plate ${Ze.index}`:"";we.errors.push(_t?`${_t}: ${ft.message}`:ft.message)}}}else{const et=D.staggerEnabled&&(t==="add-to-queue"||t==="reprint")&&v.length>1,Ze=et?D.scheduleType==="scheduled"&&D.scheduledTime?new Date(D.scheduledTime).getTime():Date.now():0;let St=0;for(const ft of it){const _t=ft?ft.index:k;for(let Pt=0;Pt1){const Ot=st(Wt,_t);Ot.quantity=Xt-1,await rt.mutateAsync(Ot)}}else if(t==="edit-queue-item"&&St===1){const yt=ct(Wt),Ot={printer_id:Wt,target_model:null,target_location:null,require_previous_success:D.requirePreviousSuccess,auto_off_after:D.autoOffAfter,gcode_injection:D.gcodeInjection,manual_start:D.scheduleType==="manual",ams_mapping:yt,plate_id:_t,scheduled_time:D.scheduleType==="scheduled"&&D.scheduledTime?new Date(D.scheduledTime).toISOString():null,...T};await Je.mutateAsync(Ot)}else{const yt=st(Wt,_t);if(Xt>1&&(yt.quantity=Xt),et){const Ot=Math.floor(Pt/D.staggerGroupSize);if(Ot>0){const ca=Ot*D.staggerIntervalMinutes*6e4;yt.scheduled_time=new Date(Ze+ca).toISOString()}}await rt.mutateAsync(yt)}we.success++}catch(yt){we.failed++;const Ot=ue?.find(xt=>xt.id===Wt)?.name||`Printer ${Wt}`,ca=ft?ft.name||`Plate ${ft.index}`:"",ke=ca?`${Ot} (${ca})`:Ot;we.errors.push(`${ke}: ${yt.message}`)}}}}Q(!1),we.failed===0?(t==="reprint"&&Ct?p(u("queue.itemsQueued",{count:we.success})):t!=="reprint"&&(t==="edit-queue-item"?p("Queue item updated"):we.success===1?p(R==="model"?`Queued for any ${J}`:u("queue.printQueued")):p(u("queue.itemsQueued",{count:we.success}))),m.invalidateQueries({queryKey:["queue"]}),l?.(),o()):we.success===0?p(`Failed: ${we.errors[0]}`,"error"):(p(`${we.success} succeeded, ${we.failed} failed`,"error"),m.invalidateQueries({queryKey:["queue"]}))},ht=V||Je.isPending,Vt=y.useMemo(()=>!(ht||R==="printer"&&v.length===0||R==="model"&&!J||R==="model"&&t==="reprint"||Be&&x.size===0),[v.length,R,J,t,Be,x.size,ht]),Xt=R==="printer"&&v.length>1?1:C,da=(()=>{const Ce=v.length;if(t==="reprint"){const Ye=Ct&&Ce>1;let it=Ye?u("printModal.staggerToPrinters",{count:Ce,defaultValue:"Stagger to {{count}} printers"}):Ce>1?u("queue.printToPrinters",{count:Ce}):u("queue.print");return Xt>1&&(it=`${it} ×${Xt}`),{title:u(g?"queue.print":"queue.reprint"),icon:gr,submitText:it,submitIcon:Ye?kn:gr,loadingText:A.total>1?u("queue.sendingProgress",{current:A.current,total:A.total}):u("queue.sending")}}if(t==="add-to-queue"){let Ye=u("queue.addToQueue");return x.size>1?Ye=u("queue.queueSelectedPlates",{count:x.size}):Ce>1&&(Ye=u("queue.queueToPrinters",{count:Ce})),Xt>1&&(Ye=`${Ye} ×${Xt}`),{title:u("queue.schedulePrint"),icon:kn,submitText:Ye,submitIcon:kn,loadingText:A.total>1?u("queue.addingProgress",{current:A.current,total:A.total}):u("queue.adding")}}return{title:u("queue.editQueueItem"),icon:wi,submitText:u("common.save"),submitIcon:wi,loadingText:A.total>1?u("queue.savingProgress",{current:A.current,total:A.total}):u("common.saving")}})(),ot=da.icon,vt=da.submitIcon,Nt=q&&x.size<=1&&(g||(Be?k!==null:!0)),ta=y.useMemo(()=>new Set(["H2D","H2DPRO","H2C","X2D"]),[]),aa=y.useMemo(()=>R==="model"?J?ta.has(J.toUpperCase().replace(/[\s-]/g,"")):!1:!ue||v.length===0?!1:v.some(Ce=>ue.find(Ye=>Ye.id===Ce)?.nozzle_count===2),[R,J,ue,v,ta]);return r.jsxs("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",onClick:V?void 0:o,children:[r.jsx(Tt,{className:"w-full max-w-2xl max-h-[90vh] overflow-y-auto",onClick:Ce=>Ce.stopPropagation(),children:r.jsxs(jt,{className:t==="reprint"?"":"p-0",children:[r.jsxs("div",{className:`flex items-center justify-between ${t==="reprint"?"mb-4":"p-4 border-b border-bambu-dark-tertiary"}`,children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(ot,{className:"w-5 h-5 text-bambu-green"}),r.jsx("h2",{className:"text-lg font-semibold text-white",children:da.title})]}),r.jsx(Le,{variant:"ghost",size:"sm",onClick:o,disabled:V,children:r.jsx(Ht,{className:"w-5 h-5"})})]}),r.jsxs("form",{onSubmit:$t,className:t==="reprint"?"":"p-4 space-y-4",children:[r.jsx("p",{className:`text-sm text-bambu-gray ${t==="reprint"?"mb-4":""}`,children:t==="reprint"?r.jsxs(r.Fragment,{children:["Send ",r.jsx("span",{className:"text-white",children:n})," to"," ",s?.length===1&&ue?r.jsx("span",{className:"text-white",children:ue.find(Ce=>Ce.id===s[0])?.name??"printer(s)"}):"printer(s)"]}):r.jsxs(r.Fragment,{children:[r.jsx("span",{className:"block text-bambu-gray mb-1",children:"Print Job"}),r.jsx("span",{className:"text-white font-medium truncate block",children:n})]})}),(()=>{if(!Qe.length)return null;const Ce=k!=null?Qe.find(it=>it.index===k):Qe[0],Ye=wk(Ce?.bed_type);return Ye?r.jsxs("p",{className:"flex items-center gap-1.5 text-xs text-bambu-gray -mt-2",title:Ye.label,children:[r.jsx("img",{src:Ye.icon,alt:"",className:"w-4 h-4 object-contain flex-shrink-0"}),r.jsx("span",{className:"truncate",children:Ye.label})]}):null})(),r.jsx(I9e,{plates:Qe,isMultiPlate:Be,selectedPlates:x,onToggle:Ce=>{S(Ye=>{const it=new Set(Ye);return t==="add-to-queue"?it.has(Ce)?it.delete(Ce):it.add(Ce):(it.clear(),it.add(Ce)),it})},onSelectAll:t==="add-to-queue"?()=>S(new Set(Qe.map(Ce=>Ce.index))):void 0,onDeselectAll:t==="add-to-queue"?()=>S(new Set):void 0,multiSelect:t==="add-to-queue"}),!s?.length&&r.jsx(U9e,{printers:ue||[],selectedPrinterIds:v,onMultiSelect:b,isLoading:he,allowMultiple:!0,showInactive:t==="edit-queue-item",disableBusy:t==="reprint",printerMappingResults:tt.printerResults,filamentReqs:Re,onAutoConfigurePrinter:tt.autoConfigurePrinter,onUpdatePrinterConfig:tt.updatePrinterConfig,assignmentMode:t==="reprint"?"printer":R,onAssignmentModeChange:t!=="reprint"?K:void 0,targetModel:J,onTargetModelChange:t!=="reprint"?X:void 0,targetLocation:ce,onTargetLocationChange:t!=="reprint"?de:void 0,slicedForModel:ge}),R==="model"&&J&&Re&&ze&&ze.length>0&&r.jsx(z9e,{filamentReqs:Re,availableFilaments:ze,overrides:oe,onChange:Y,forceColorMatch:ne,onForceColorMatchChange:(Ce,Ye)=>me(it=>({...it,[Ce]:Ye}))}),ge&&R==="printer"&&v.length===1&&(()=>{const Ce=ue?.find(Ye=>Ye.id===v[0]);return Ce&&Ce.model&&ge!==Ce.model?r.jsxs("div",{className:"p-3 mb-2 bg-yellow-500/10 border border-yellow-500/30 rounded-lg flex items-center gap-2",children:[r.jsx(ga,{className:"w-4 h-4 text-yellow-400 flex-shrink-0"}),r.jsxs("span",{className:"text-sm text-yellow-400",children:["File was sliced for ",ge,", but printing on ",Ce.model]})]}):null})(),Ie&&r.jsxs("div",{className:"flex items-start gap-2 p-3 mb-2 bg-orange-500/10 border border-orange-500/30 rounded-lg text-sm",children:[r.jsx(_n,{className:"w-4 h-4 text-orange-400 mt-0.5 flex-shrink-0"}),r.jsx("p",{className:"text-orange-400",children:"Archive data unavailable. The source file may have been deleted. Filament mapping is disabled."})]}),Nt&&!Ie&&v.length===1&&r.jsx(R9e,{printerId:q,filamentReqs:Re,manualMappings:E,onManualMappingChange:z,defaultExpanded:!!s?.length||(Z?.per_printer_mapping_expanded??!1),currencySymbol:se,defaultCostPerKg:fe}),(t==="reprint"||B>0||R==="model"&&J)&&r.jsx(H9e,{options:T,onChange:j,defaultExpanded:!!s?.length,showDualNozzleOptions:aa}),t!=="edit-queue-item"&&(R==="model"||v.length<=1)&&r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx("label",{htmlFor:"printQuantity",className:"text-sm text-bambu-gray whitespace-nowrap",children:u("queue.quantity","Quantity")}),r.jsx("input",{id:"printQuantity",type:"number",min:1,max:999,value:C,onChange:Ce=>N(Math.max(1,Math.min(999,parseInt(Ce.target.value)||1))),className:"w-20 px-2 py-1 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded text-white focus:outline-none focus:ring-1 focus:ring-bambu-green"}),C>1&&r.jsx("span",{className:"text-xs text-bambu-gray",children:u("queue.quantityHint","Creates {{count}} queue items",{count:C})})]}),t==="reprint"&&R==="printer"&&v.length>1&&r.jsxs("div",{className:"space-y-2 pb-2",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("input",{type:"checkbox",id:"staggerEnabledReprint",checked:D.staggerEnabled,onChange:Ce=>P({...D,staggerEnabled:Ce.target.checked}),className:"rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),r.jsxs("label",{htmlFor:"staggerEnabledReprint",className:"text-sm flex items-center gap-1 text-bambu-gray",children:[r.jsx(Zr,{className:"w-3.5 h-3.5"}),u("printModal.staggerPrinterStarts","Stagger printer starts")]})]}),D.staggerEnabled&&(()=>{const Ce=D.staggerGroupSize,Ye=D.staggerIntervalMinutes,it=Math.ceil(v.length/Ce),Ae=(it-1)*Ye;return r.jsxs("p",{className:"ml-6 text-xs text-bambu-gray",children:[u("printModal.staggerPreview","{{printers}} printers → {{groups}} groups of {{size}}, starting every {{interval}} min",{printers:v.length,groups:it,size:Ce,interval:Ye}),it>1?` (${u("printModal.staggerTotal","total: {{minutes}} min",{minutes:Ae})})`:""]})})()]}),t!=="reprint"&&r.jsx(q9e,{options:D,onChange:P,dateFormat:Z?.date_format||"system",timeFormat:Z?.time_format||"system",canControlPrinter:f("printers:control"),showStagger:t==="add-to-queue"&&R==="printer"&&v.length>1,printerCount:v.length,hasGcodeSnippets:!!Z?.gcode_snippets}),t==="reprint"&&!!Z?.gcode_snippets&&Xt>1&&r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("input",{type:"checkbox",id:"gcodeInjectionReprint",checked:D.gcodeInjection,onChange:Ce=>P({...D,gcodeInjection:Ce.target.checked}),className:"rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),r.jsxs("label",{htmlFor:"gcodeInjectionReprint",className:"text-sm flex items-center gap-1 text-bambu-gray",children:[r.jsx(tv,{className:"w-3.5 h-3.5"}),u("printModal.gcodeInjection","Inject auto-print G-code")]})]}),Je.isError&&r.jsx("div",{className:"mb-4 p-3 bg-red-500/20 border border-red-500/50 rounded-lg text-sm text-red-400",children:Je.error?.message||"Failed to complete operation"}),r.jsxs("div",{className:`flex gap-3 ${t==="reprint"?"":"pt-2"}`,children:[r.jsx(Le,{type:"button",variant:"secondary",onClick:o,className:"flex-1",disabled:V,children:"Cancel"}),r.jsx(Le,{type:"submit",disabled:!Vt,className:"flex-1",children:ht?r.jsxs(r.Fragment,{children:[r.jsx(lt,{className:"w-4 h-4 animate-spin"}),da.loadingText]}):r.jsxs(r.Fragment,{children:[r.jsx(vt,{className:"w-4 h-4"}),da.submitText]})})]})]})]})}),U&&U.length>0&&r.jsx(wa,{title:u("printModal.insufficientFilamentTitle"),message:Fe,confirmText:u("printModal.printAnyway"),cancelText:u("common.cancel"),variant:"warning",onConfirm:()=>{$(null),$t(void 0,{skipFilamentCheck:!0})},onCancel:()=>$(null)})]})}function fY({value:t}){const{t:e}=wt(),[a,n]=y.useState(!1),i=async()=>{try{if(navigator.clipboard&&window.isSecureContext)await navigator.clipboard.writeText(t);else{const s=document.createElement("textarea");s.value=t,s.style.position="fixed",s.style.opacity="0",document.body.appendChild(s);try{if(s.select(),!document.execCommand("copy"))return}finally{document.body.removeChild(s)}}n(!0),setTimeout(()=>n(!1),2e3)}catch{}};return r.jsx("button",{onClick:i,className:"ml-2 p-1 rounded hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white transition-colors",title:e(a?"printers.copied":"printers.copyToClipboard"),children:a?r.jsx(vr,{className:"w-3.5 h-3.5 text-bambu-green"}):r.jsx(li,{className:"w-3.5 h-3.5"})})}function V9e({printer:t,status:e,totalPrintHours:a,onClose:n}){const{t:i}=wt();y.useEffect(()=>{const o=l=>{l.key==="Escape"&&n()};return window.addEventListener("keydown",o),()=>window.removeEventListener("keydown",o)},[n]);const s=[];if(s.push({label:i("printers.model"),value:t.model??"—"}),s.push({label:i("common.status"),value:r.jsxs("span",{className:`inline-flex items-center gap-1.5 px-2 py-0.5 rounded-full text-xs font-medium ${e?.connected?"bg-bambu-green/20 text-bambu-green":"bg-red-500/20 text-red-400"}`,children:[r.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${e?.connected?"bg-bambu-green":"bg-red-400"}`}),e?.connected?i("printers.status.available"):i("printers.status.offline")]})}),e?.state){const o={IDLE:"printers.status.idle",RUNNING:"printers.status.printing",PAUSE:"printers.status.paused",FINISH:"printers.status.finished",FAILED:"printers.status.error"};s.push({label:i("printers.state"),value:i(o[e.state]??"printers.status.unknown")})}if(s.push({label:i("printers.ipAddress"),value:r.jsxs("span",{className:"flex items-center",children:[r.jsx("span",{className:"font-mono",children:t.ip_address}),r.jsx(fY,{value:t.ip_address})]})}),s.push({label:i("printers.serialNumber"),value:r.jsxs("span",{className:"flex items-center",children:[r.jsx("span",{className:"font-mono truncate",children:t.serial_number}),r.jsx(fY,{value:t.serial_number})]})}),e?.wired_network)s.push({label:i("printers.networkLabel","Network"),value:r.jsxs("span",{className:"flex items-center gap-2",children:[r.jsx(LI,{className:"w-4 h-4 text-bambu-green"}),r.jsx("span",{className:"text-bambu-green",children:i("printers.connection.ethernet","Ethernet")})]})});else if(e?.wifi_signal!=null){const o=nte(e.wifi_signal);s.push({label:i("printers.wifiSignalLabel"),value:r.jsxs("span",{className:"flex items-center gap-2",children:[r.jsx(pJ,{className:`w-4 h-4 ${o.color}`}),r.jsx("span",{className:o.color,children:i(o.labelKey)}),r.jsxs("span",{className:"text-bambu-gray text-xs",children:["(",e.wifi_signal," dBm)"]})]})})}return s.push({label:i("printers.firmware"),value:e?.firmware_version??"—"}),e?.developer_mode!=null&&s.push({label:i("printers.developerMode"),value:r.jsx("span",{className:`inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium ${e.developer_mode?"bg-bambu-green/20 text-bambu-green":"bg-bambu-dark-tertiary text-bambu-gray"}`,children:e.developer_mode?i("printers.enabled"):i("printers.disabled")})}),s.push({label:i("printers.nozzleCount"),value:t.nozzle_count}),s.push({label:i("printers.autoArchive"),value:r.jsx("span",{className:`inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium ${t.auto_archive?"bg-bambu-green/20 text-bambu-green":"bg-bambu-dark-tertiary text-bambu-gray"}`,children:t.auto_archive?i("printers.enabled"):i("printers.disabled")})}),a!=null&&a>0&&s.push({label:i("printers.totalPrintHours"),value:`${Math.round(a)}h`}),t.location&&s.push({label:i("printers.sort.location"),value:t.location}),s.push({label:i("printers.addedOn"),value:qg(t.created_at)}),r.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",role:"dialog","aria-modal":"true",onClick:n,children:r.jsx(Tt,{className:"w-full max-w-md",onClick:o=>o.stopPropagation(),children:r.jsxs(jt,{children:[r.jsxs("div",{className:"flex items-center justify-between mb-4",children:[r.jsx("h2",{className:"text-lg font-semibold text-white",children:t.name}),r.jsx("button",{onClick:n,className:"p-1 hover:bg-bambu-dark rounded flex-shrink-0",children:r.jsx(Ht,{className:"w-5 h-5 text-bambu-gray"})})]}),r.jsx("div",{className:"flex justify-center mb-4",children:r.jsx("img",{src:rte(t.model),alt:t.model??t.name,className:"h-24 object-contain"})}),r.jsx("div",{className:"space-y-0",children:s.map((o,l)=>r.jsxs("div",{className:"flex items-center justify-between gap-4 py-2.5 border-b border-bambu-dark-tertiary last:border-0",children:[r.jsx("span",{className:"text-sm text-bambu-gray whitespace-nowrap",children:o.label}),r.jsx("span",{className:"text-sm text-white text-right",children:o.value})]},l))})]})})})}function G9e(t){if(!t||t.length<6)return!1;const e=parseInt(t.slice(0,2),16),a=parseInt(t.slice(2,4),16),n=parseInt(t.slice(4,6),16);return(.299*e+.587*a+.114*n)/255>.6}function AF({trayColor:t,trayType:e,isEmpty:a,emptyKind:n,slotNumber:i}){const s=n==="reset"?"#3d3d3d":"#666";return r.jsx("div",{className:"w-3.5 h-3.5 rounded-full mx-auto mb-0.5 border-2 flex items-center justify-center",style:{backgroundColor:t?`#${t}`:e?"#333":"transparent",borderColor:a?s:"rgba(255,255,255,0.1)",borderStyle:a?"dashed":"solid"},children:r.jsx("span",{className:"text-[6px] font-bold leading-none select-none",style:{color:t&&G9e(t)?"#000":"#fff"},children:i})})}const gY=240,bY=320;function jF(t){return(t??.02).toFixed(3)}function xY({side:t}){const{mode:e}=gb(),a=e==="dark"?"#1a4d2e":"#e7f5e9";return r.jsx("span",{className:"inline-flex items-center justify-center w-4 h-4 text-[10px] font-bold rounded",style:{backgroundColor:a,color:"#00ae42"},children:t})}function Rse(t,e){if(!t)return"";if(t.includes("hardened"))return e("printers.nozzleHardenedSteel");if(t.includes("stainless"))return e("printers.nozzleStainlessSteel");if(t.includes("tungsten"))return e("printers.nozzleTungstenCarbide");if(t.length>=4){const a=t.slice(2,4);if(a==="00")return e("printers.nozzleStainlessSteel");if(a==="01")return e("printers.nozzleHardenedSteel");if(a==="05")return e("printers.nozzleTungstenCarbide")}return t==="00"?e("printers.nozzleStainlessSteel"):t==="01"?e("printers.nozzleHardenedSteel"):t==="05"?e("printers.nozzleTungstenCarbide"):t.startsWith("H")?e("printers.nozzleHardenedSteel"):t}function zse(t,e){return t?t.startsWith("HH")?e("printers.nozzleHighFlow"):t.startsWith("HS")?e("printers.nozzleStandardFlow"):"":""}function Ise({slot:t,index:e,activeStatus:a,filamentName:n,children:i}){const{t:s}=wt(),[o,l]=y.useState(!1),[c,d]=y.useState("top"),u=y.useRef(null),m=y.useRef(null),p=y.useRef(null),f=!t.nozzle_diameter&&!t.nozzle_type,g=t.stat===1;y.useEffect(()=>{if(o&&u.current&&m.current){const C=u.current.getBoundingClientRect(),N=m.current.offsetHeight,j=C.top-56,D=window.innerHeight-C.bottom;jj?d("bottom"):d("top")}},[o]);const v=()=>{p.current&&clearTimeout(p.current),p.current=setTimeout(()=>l(!0),80)},b=()=>{p.current&&clearTimeout(p.current),p.current=setTimeout(()=>l(!1),100)};y.useEffect(()=>()=>{p.current&&clearTimeout(p.current)},[]);const x=WI(t.filament_color),S=Rse(t.nozzle_type,s),k=zse(t.nozzle_type,s);return r.jsxs("div",{ref:u,className:"relative",onMouseEnter:v,onMouseLeave:b,children:[i,o&&r.jsxs("div",{ref:m,className:` +`)},[U,u]),rt=at({mutationFn:Ce=>ie.addToQueue(Ce)}),Je=at({mutationFn:Ce=>ie.updateQueueItem(i.id,Ce),onSuccess:()=>{m.invalidateQueries({queryKey:["queue"]}),p("Queue item updated"),l?.(),o()},onError:Ce=>{p(Ce.message||"Failed to update queue item","error")}}),Ct=D.staggerEnabled&&v.length>1,$t=async(Ce,Ye)=>{if(Ce?.preventDefault(),!Ye?.skipFilamentCheck&&!Z?.disable_filament_warnings&&(t==="reprint"||t==="add-to-queue")&&R==="printer"){const et=[],Ze=Re?.filaments??[];if(Ze.length>0&&Ge.size>0){const St=(ft,_t)=>!Number.isFinite(ft)||ft<=0||!Number.isFinite(_t)||_t<0?null:Math.max(0,ft-_t);for(const ft of v){const _t=v.length>1?tt.getFinalMapping(ft):Oe;if(!_t)continue;const Pt=v.length>1?tt.printerResults.find(ke=>ke.printerId===ft)?.status:nt,Wt=vk(Pt),yt=new Map(Wt.map(ke=>[ke.globalTrayId,ke.label])),Ot=Ge.get(ft),ca=ue?.find(ke=>ke.id===ft)?.name??`Printer ${ft}`;Ot&&Ze.forEach(ke=>{if(!ke.slot_id||ke.slot_id<=0)return;const xt=_t[ke.slot_id-1];if(!Number.isFinite(xt)||xt<0)return;const Lt=Ot.get(xt)?.spool;if(!Lt)return;const qt=St(Lt.label_weight,Lt.weight_used);qt!==null&&(qt>=ke.used_grams||et.push({printerName:ca,slotLabel:yt.get(xt)??`Slot ${ke.slot_id}`,requiredGrams:ke.used_grams,remainingGrams:qt}))})}}if(et.length>0){$(et);return}}if(R==="printer"&&v.length===0){p("Please select at least one printer","error");return}if(R==="model"&&!J){p("Please select a target printer model","error");return}Q(!0);const it=x.size>1?Qe.filter(et=>x.has(et.index)):[null],Ae=R==="model"?it.length:v.length*it.length;F({current:0,total:Ae});const we={success:0,failed:0,errors:[]},ct=et=>{if(v.length>1){const Ze=I[et];if(Ze&&!Ze.useDefault)return tt.getFinalMapping(et)}return Oe},We=(()=>{const et=[];if(Re?.filaments)for(const Ze of Re.filaments){const St=oe[Ze.slot_id],ft=ne[Ze.slot_id]??!1,_t=St?.type??Ze.type,Pt=St?.color??Ze.color;(St||ft)&&et.push({slot_id:Ze.slot_id,type:_t,color:Pt,color_name:Sc(Pt),force_color_match:ft})}else for(const[Ze,{type:St,color:ft}]of Object.entries(oe)){const _t=parseInt(Ze,10),Pt=ne[_t]??!1;et.push({slot_id:_t,type:St,color:ft,color_name:Sc(ft),force_color_match:Pt})}return et.length>0?et:void 0})(),st=(et,Ze)=>({printer_id:R==="printer"?et:null,target_model:R==="model"?J:null,target_location:R==="model"?ce:null,filament_overrides:R==="model"?We:void 0,archive_id:g?void 0:e,library_file_id:g?a:void 0,require_previous_success:D.requirePreviousSuccess,auto_off_after:D.autoOffAfter,gcode_injection:D.gcodeInjection,manual_start:D.scheduleType==="manual",skip_filament_check:Ye?.skipFilamentCheck===!0?!0:void 0,ams_mapping:et?ct(et):void 0,plate_id:Ze!==void 0?Ze:k,scheduled_time:D.scheduleType==="scheduled"&&D.scheduledTime?new Date(D.scheduledTime).toISOString():void 0,...T,project_id:c??void 0});if(R==="model"){if(t==="reprint"){p("Model-based assignment only works with queue mode","error"),Q(!1);return}let et=0;for(const Ze of it){et++,F({current:et,total:Ae});const St=Ze?Ze.index:k;try{if(t==="edit-queue-item"&&!Ze){const ft={printer_id:null,target_model:J,target_location:ce,filament_overrides:We||null,require_previous_success:D.requirePreviousSuccess,auto_off_after:D.autoOffAfter,gcode_injection:D.gcodeInjection,manual_start:D.scheduleType==="manual",ams_mapping:void 0,plate_id:St,scheduled_time:D.scheduleType==="scheduled"&&D.scheduledTime?new Date(D.scheduledTime).toISOString():null,...T};await Je.mutateAsync(ft)}else{const ft=st(null,St);Xt>1&&(ft.quantity=Xt),await rt.mutateAsync(ft)}we.success++}catch(ft){we.failed++;const _t=Ze?Ze.name||`Plate ${Ze.index}`:"";we.errors.push(_t?`${_t}: ${ft.message}`:ft.message)}}}else{const et=D.staggerEnabled&&(t==="add-to-queue"||t==="reprint")&&v.length>1,Ze=et?D.scheduleType==="scheduled"&&D.scheduledTime?new Date(D.scheduledTime).getTime():Date.now():0;let St=0;for(const ft of it){const _t=ft?ft.index:k;for(let Pt=0;Pt1){const Ot=st(Wt,_t);Ot.quantity=Xt-1,await rt.mutateAsync(Ot)}}else if(t==="edit-queue-item"&&St===1){const yt=ct(Wt),Ot={printer_id:Wt,target_model:null,target_location:null,require_previous_success:D.requirePreviousSuccess,auto_off_after:D.autoOffAfter,gcode_injection:D.gcodeInjection,manual_start:D.scheduleType==="manual",ams_mapping:yt,plate_id:_t,scheduled_time:D.scheduleType==="scheduled"&&D.scheduledTime?new Date(D.scheduledTime).toISOString():null,...T};await Je.mutateAsync(Ot)}else{const yt=st(Wt,_t);if(Xt>1&&(yt.quantity=Xt),et){const Ot=Math.floor(Pt/D.staggerGroupSize);if(Ot>0){const ca=Ot*D.staggerIntervalMinutes*6e4;yt.scheduled_time=new Date(Ze+ca).toISOString()}}await rt.mutateAsync(yt)}we.success++}catch(yt){we.failed++;const Ot=ue?.find(xt=>xt.id===Wt)?.name||`Printer ${Wt}`,ca=ft?ft.name||`Plate ${ft.index}`:"",ke=ca?`${Ot} (${ca})`:Ot;we.errors.push(`${ke}: ${yt.message}`)}}}}Q(!1),we.failed===0?(t==="reprint"&&Ct?p(u("queue.itemsQueued",{count:we.success})):t!=="reprint"&&(t==="edit-queue-item"?p("Queue item updated"):we.success===1?p(R==="model"?`Queued for any ${J}`:u("queue.printQueued")):p(u("queue.itemsQueued",{count:we.success}))),m.invalidateQueries({queryKey:["queue"]}),l?.(),o()):we.success===0?p(`Failed: ${we.errors[0]}`,"error"):(p(`${we.success} succeeded, ${we.failed} failed`,"error"),m.invalidateQueries({queryKey:["queue"]}))},ht=V||Je.isPending,Vt=y.useMemo(()=>!(ht||R==="printer"&&v.length===0||R==="model"&&!J||R==="model"&&t==="reprint"||Be&&x.size===0),[v.length,R,J,t,Be,x.size,ht]),Xt=R==="printer"&&v.length>1?1:C,da=(()=>{const Ce=v.length;if(t==="reprint"){const Ye=Ct&&Ce>1;let it=Ye?u("printModal.staggerToPrinters",{count:Ce,defaultValue:"Stagger to {{count}} printers"}):Ce>1?u("queue.printToPrinters",{count:Ce}):u("queue.print");return Xt>1&&(it=`${it} ×${Xt}`),{title:u(g?"queue.print":"queue.reprint"),icon:gr,submitText:it,submitIcon:Ye?kn:gr,loadingText:A.total>1?u("queue.sendingProgress",{current:A.current,total:A.total}):u("queue.sending")}}if(t==="add-to-queue"){let Ye=u("queue.addToQueue");return x.size>1?Ye=u("queue.queueSelectedPlates",{count:x.size}):Ce>1&&(Ye=u("queue.queueToPrinters",{count:Ce})),Xt>1&&(Ye=`${Ye} ×${Xt}`),{title:u("queue.schedulePrint"),icon:kn,submitText:Ye,submitIcon:kn,loadingText:A.total>1?u("queue.addingProgress",{current:A.current,total:A.total}):u("queue.adding")}}return{title:u("queue.editQueueItem"),icon:wi,submitText:u("common.save"),submitIcon:wi,loadingText:A.total>1?u("queue.savingProgress",{current:A.current,total:A.total}):u("common.saving")}})(),ot=da.icon,vt=da.submitIcon,Nt=q&&x.size<=1&&(g||(Be?k!==null:!0)),ta=y.useMemo(()=>new Set(["H2D","H2DPRO","H2C","X2D"]),[]),aa=y.useMemo(()=>R==="model"?J?ta.has(J.toUpperCase().replace(/[\s-]/g,"")):!1:!ue||v.length===0?!1:v.some(Ce=>ue.find(Ye=>Ye.id===Ce)?.nozzle_count===2),[R,J,ue,v,ta]);return r.jsxs("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",onClick:V?void 0:o,children:[r.jsx(Tt,{className:"w-full max-w-2xl max-h-[90vh] overflow-y-auto",onClick:Ce=>Ce.stopPropagation(),children:r.jsxs(jt,{className:t==="reprint"?"":"p-0",children:[r.jsxs("div",{className:`flex items-center justify-between ${t==="reprint"?"mb-4":"p-4 border-b border-bambu-dark-tertiary"}`,children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(ot,{className:"w-5 h-5 text-bambu-green"}),r.jsx("h2",{className:"text-lg font-semibold text-white",children:da.title})]}),r.jsx(Le,{variant:"ghost",size:"sm",onClick:o,disabled:V,children:r.jsx(Ht,{className:"w-5 h-5"})})]}),r.jsxs("form",{onSubmit:$t,className:t==="reprint"?"":"p-4 space-y-4",children:[r.jsx("p",{className:`text-sm text-bambu-gray ${t==="reprint"?"mb-4":""}`,children:t==="reprint"?r.jsxs(r.Fragment,{children:["Send ",r.jsx("span",{className:"text-white",children:n})," to"," ",s?.length===1&&ue?r.jsx("span",{className:"text-white",children:ue.find(Ce=>Ce.id===s[0])?.name??"printer(s)"}):"printer(s)"]}):r.jsxs(r.Fragment,{children:[r.jsx("span",{className:"block text-bambu-gray mb-1",children:"Print Job"}),r.jsx("span",{className:"text-white font-medium truncate block",children:n})]})}),(()=>{if(!Qe.length)return null;const Ce=k!=null?Qe.find(it=>it.index===k):Qe[0],Ye=wk(Ce?.bed_type);return Ye?r.jsxs("p",{className:"flex items-center gap-1.5 text-xs text-bambu-gray -mt-2",title:Ye.label,children:[r.jsx("img",{src:Ye.icon,alt:"",className:"w-4 h-4 object-contain flex-shrink-0"}),r.jsx("span",{className:"truncate",children:Ye.label})]}):null})(),r.jsx(I9e,{plates:Qe,isMultiPlate:Be,selectedPlates:x,onToggle:Ce=>{S(Ye=>{const it=new Set(Ye);return t==="add-to-queue"?it.has(Ce)?it.delete(Ce):it.add(Ce):(it.clear(),it.add(Ce)),it})},onSelectAll:t==="add-to-queue"?()=>S(new Set(Qe.map(Ce=>Ce.index))):void 0,onDeselectAll:t==="add-to-queue"?()=>S(new Set):void 0,multiSelect:t==="add-to-queue"}),!s?.length&&r.jsx(U9e,{printers:ue||[],selectedPrinterIds:v,onMultiSelect:b,isLoading:he,allowMultiple:!0,showInactive:t==="edit-queue-item",disableBusy:t==="reprint",printerMappingResults:tt.printerResults,filamentReqs:Re,onAutoConfigurePrinter:tt.autoConfigurePrinter,onUpdatePrinterConfig:tt.updatePrinterConfig,assignmentMode:t==="reprint"?"printer":R,onAssignmentModeChange:t!=="reprint"?K:void 0,targetModel:J,onTargetModelChange:t!=="reprint"?X:void 0,targetLocation:ce,onTargetLocationChange:t!=="reprint"?de:void 0,slicedForModel:ge}),R==="model"&&J&&Re&&ze&&ze.length>0&&r.jsx(z9e,{filamentReqs:Re,availableFilaments:ze,overrides:oe,onChange:Y,forceColorMatch:ne,onForceColorMatchChange:(Ce,Ye)=>me(it=>({...it,[Ce]:Ye}))}),ge&&R==="printer"&&v.length===1&&(()=>{const Ce=ue?.find(Ye=>Ye.id===v[0]);return Ce&&Ce.model&&ge!==Ce.model?r.jsxs("div",{className:"p-3 mb-2 bg-yellow-500/10 border border-yellow-500/30 rounded-lg flex items-center gap-2",children:[r.jsx(ga,{className:"w-4 h-4 text-yellow-400 flex-shrink-0"}),r.jsxs("span",{className:"text-sm text-yellow-400",children:["File was sliced for ",ge,", but printing on ",Ce.model]})]}):null})(),Ie&&r.jsxs("div",{className:"flex items-start gap-2 p-3 mb-2 bg-orange-500/10 border border-orange-500/30 rounded-lg text-sm",children:[r.jsx(_n,{className:"w-4 h-4 text-orange-400 mt-0.5 flex-shrink-0"}),r.jsx("p",{className:"text-orange-400",children:"Archive data unavailable. The source file may have been deleted. Filament mapping is disabled."})]}),Nt&&!Ie&&v.length===1&&r.jsx(R9e,{printerId:q,filamentReqs:Re,manualMappings:E,onManualMappingChange:z,defaultExpanded:!!s?.length||(Z?.per_printer_mapping_expanded??!1),currencySymbol:se,defaultCostPerKg:fe}),(t==="reprint"||B>0||R==="model"&&J)&&r.jsx(H9e,{options:T,onChange:j,defaultExpanded:!!s?.length,showDualNozzleOptions:aa}),t!=="edit-queue-item"&&(R==="model"||v.length<=1)&&r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx("label",{htmlFor:"printQuantity",className:"text-sm text-bambu-gray whitespace-nowrap",children:u("queue.quantity","Quantity")}),r.jsx("input",{id:"printQuantity",type:"number",min:1,max:999,value:C,onChange:Ce=>N(Math.max(1,Math.min(999,parseInt(Ce.target.value)||1))),className:"w-20 px-2 py-1 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded text-white focus:outline-none focus:ring-1 focus:ring-bambu-green"}),C>1&&r.jsx("span",{className:"text-xs text-bambu-gray",children:u("queue.quantityHint","Creates {{count}} queue items",{count:C})})]}),t==="reprint"&&R==="printer"&&v.length>1&&r.jsxs("div",{className:"space-y-2 pb-2",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("input",{type:"checkbox",id:"staggerEnabledReprint",checked:D.staggerEnabled,onChange:Ce=>P({...D,staggerEnabled:Ce.target.checked}),className:"rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),r.jsxs("label",{htmlFor:"staggerEnabledReprint",className:"text-sm flex items-center gap-1 text-bambu-gray",children:[r.jsx(Zr,{className:"w-3.5 h-3.5"}),u("printModal.staggerPrinterStarts","Stagger printer starts")]})]}),D.staggerEnabled&&(()=>{const Ce=D.staggerGroupSize,Ye=D.staggerIntervalMinutes,it=Math.ceil(v.length/Ce),Ae=(it-1)*Ye;return r.jsxs("p",{className:"ml-6 text-xs text-bambu-gray",children:[u("printModal.staggerPreview","{{printers}} printers → {{groups}} groups of {{size}}, starting every {{interval}} min",{printers:v.length,groups:it,size:Ce,interval:Ye}),it>1?` (${u("printModal.staggerTotal","total: {{minutes}} min",{minutes:Ae})})`:""]})})()]}),t!=="reprint"&&r.jsx(q9e,{options:D,onChange:P,dateFormat:Z?.date_format||"system",timeFormat:Z?.time_format||"system",canControlPrinter:f("printers:control"),showStagger:t==="add-to-queue"&&R==="printer"&&v.length>1,printerCount:v.length,hasGcodeSnippets:!!Z?.gcode_snippets}),t==="reprint"&&!!Z?.gcode_snippets&&Xt>1&&r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("input",{type:"checkbox",id:"gcodeInjectionReprint",checked:D.gcodeInjection,onChange:Ce=>P({...D,gcodeInjection:Ce.target.checked}),className:"rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),r.jsxs("label",{htmlFor:"gcodeInjectionReprint",className:"text-sm flex items-center gap-1 text-bambu-gray",children:[r.jsx(tv,{className:"w-3.5 h-3.5"}),u("printModal.gcodeInjection","Inject auto-print G-code")]})]}),Je.isError&&r.jsx("div",{className:"mb-4 p-3 bg-red-500/20 border border-red-500/50 rounded-lg text-sm text-red-400",children:Je.error?.message||"Failed to complete operation"}),r.jsxs("div",{className:`flex gap-3 ${t==="reprint"?"":"pt-2"}`,children:[r.jsx(Le,{type:"button",variant:"secondary",onClick:o,className:"flex-1",disabled:V,children:"Cancel"}),r.jsx(Le,{type:"submit",disabled:!Vt,className:"flex-1",children:ht?r.jsxs(r.Fragment,{children:[r.jsx(lt,{className:"w-4 h-4 animate-spin"}),da.loadingText]}):r.jsxs(r.Fragment,{children:[r.jsx(vt,{className:"w-4 h-4"}),da.submitText]})})]})]})]})}),U&&U.length>0&&r.jsx(wa,{title:u("printModal.insufficientFilamentTitle"),message:Fe,confirmText:u("printModal.printAnyway"),cancelText:u("common.cancel"),variant:"warning",onConfirm:()=>{$(null),$t(void 0,{skipFilamentCheck:!0})},onCancel:()=>$(null)})]})}function fY({value:t}){const{t:e}=wt(),[a,n]=y.useState(!1),i=async()=>{try{if(navigator.clipboard&&window.isSecureContext)await navigator.clipboard.writeText(t);else{const s=document.createElement("textarea");s.value=t,s.style.position="fixed",s.style.opacity="0",document.body.appendChild(s);try{if(s.select(),!document.execCommand("copy"))return}finally{document.body.removeChild(s)}}n(!0),setTimeout(()=>n(!1),2e3)}catch{}};return r.jsx("button",{onClick:i,className:"ml-2 p-1 rounded hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white transition-colors",title:e(a?"printers.copied":"printers.copyToClipboard"),children:a?r.jsx(vr,{className:"w-3.5 h-3.5 text-bambu-green"}):r.jsx(li,{className:"w-3.5 h-3.5"})})}function V9e({printer:t,status:e,totalPrintHours:a,onClose:n}){const{t:i}=wt();y.useEffect(()=>{const o=l=>{l.key==="Escape"&&n()};return window.addEventListener("keydown",o),()=>window.removeEventListener("keydown",o)},[n]);const s=[];if(s.push({label:i("printers.model"),value:t.model??"—"}),s.push({label:i("common.status"),value:r.jsxs("span",{className:`inline-flex items-center gap-1.5 px-2 py-0.5 rounded-full text-xs font-medium ${e?.connected?"bg-bambu-green/20 text-bambu-green":"bg-red-500/20 text-red-400"}`,children:[r.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${e?.connected?"bg-bambu-green":"bg-red-400"}`}),e?.connected?i("printers.status.available"):i("printers.status.offline")]})}),e?.state){const o={IDLE:"printers.status.idle",RUNNING:"printers.status.printing",PAUSE:"printers.status.paused",FINISH:"printers.status.finished",FAILED:"printers.status.error"};s.push({label:i("printers.state"),value:i(o[e.state]??"printers.status.unknown")})}if(s.push({label:i("printers.ipAddress"),value:r.jsxs("span",{className:"flex items-center",children:[r.jsx("span",{className:"font-mono",children:t.ip_address}),r.jsx(fY,{value:t.ip_address})]})}),s.push({label:i("printers.serialNumber"),value:r.jsxs("span",{className:"flex items-center",children:[r.jsx("span",{className:"font-mono truncate",children:t.serial_number}),r.jsx(fY,{value:t.serial_number})]})}),e?.wired_network)s.push({label:i("printers.networkLabel","Network"),value:r.jsxs("span",{className:"flex items-center gap-2",children:[r.jsx(LI,{className:"w-4 h-4 text-bambu-green"}),r.jsx("span",{className:"text-bambu-green",children:i("printers.connection.ethernet","Ethernet")})]})});else if(e?.wifi_signal!=null){const o=nte(e.wifi_signal);s.push({label:i("printers.wifiSignalLabel"),value:r.jsxs("span",{className:"flex items-center gap-2",children:[r.jsx(pJ,{className:`w-4 h-4 ${o.color}`}),r.jsx("span",{className:o.color,children:i(o.labelKey)}),r.jsxs("span",{className:"text-bambu-gray text-xs",children:["(",e.wifi_signal," dBm)"]})]})})}return s.push({label:i("printers.firmware"),value:e?.firmware_version??"—"}),e?.developer_mode!=null&&s.push({label:i("printers.developerMode"),value:r.jsx("span",{className:`inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium ${e.developer_mode?"bg-bambu-green/20 text-bambu-green":"bg-bambu-dark-tertiary text-bambu-gray"}`,children:e.developer_mode?i("printers.enabled"):i("printers.disabled")})}),s.push({label:i("printers.nozzleCount"),value:t.nozzle_count}),s.push({label:i("printers.autoArchive"),value:r.jsx("span",{className:`inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium ${t.auto_archive?"bg-bambu-green/20 text-bambu-green":"bg-bambu-dark-tertiary text-bambu-gray"}`,children:t.auto_archive?i("printers.enabled"):i("printers.disabled")})}),a!=null&&a>0&&s.push({label:i("printers.totalPrintHours"),value:`${Math.round(a)}h`}),t.location&&s.push({label:i("printers.sort.location"),value:t.location}),s.push({label:i("printers.addedOn"),value:qg(t.created_at)}),r.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",role:"dialog","aria-modal":"true",onClick:n,children:r.jsx(Tt,{className:"w-full max-w-md",onClick:o=>o.stopPropagation(),children:r.jsxs(jt,{children:[r.jsxs("div",{className:"flex items-center justify-between mb-4",children:[r.jsx("h2",{className:"text-lg font-semibold text-white",children:t.name}),r.jsx("button",{onClick:n,className:"p-1 hover:bg-bambu-dark rounded flex-shrink-0",children:r.jsx(Ht,{className:"w-5 h-5 text-bambu-gray"})})]}),r.jsx("div",{className:"flex justify-center mb-4",children:r.jsx("img",{src:rte(t.model),alt:t.model??t.name,className:"h-24 object-contain"})}),r.jsx("div",{className:"space-y-0",children:s.map((o,l)=>r.jsxs("div",{className:"flex items-center justify-between gap-4 py-2.5 border-b border-bambu-dark-tertiary last:border-0",children:[r.jsx("span",{className:"text-sm text-bambu-gray whitespace-nowrap",children:o.label}),r.jsx("span",{className:"text-sm text-white text-right",children:o.value})]},l))})]})})})}function G9e(t){if(!t||t.length<6)return!1;const e=parseInt(t.slice(0,2),16),a=parseInt(t.slice(2,4),16),n=parseInt(t.slice(4,6),16);return(.299*e+.587*a+.114*n)/255>.6}function AF({trayColor:t,trayType:e,isEmpty:a,emptyKind:n,slotNumber:i}){const s=n==="reset"?"#3d3d3d":"#666";return r.jsx("div",{className:"w-3.5 h-3.5 rounded-full mx-auto mb-0.5 border-2 flex items-center justify-center",style:{backgroundColor:t?`#${t}`:e?"#333":"transparent",borderColor:a?s:"rgba(255,255,255,0.1)",borderStyle:a?"dashed":"solid"},children:r.jsx("span",{className:"text-[6px] font-bold leading-none select-none",style:{color:t&&G9e(t)?"#000":"#fff"},children:i})})}const gY=240,bY=320;function jF(t){return(t??.02).toFixed(3)}function xY({side:t}){const{mode:e}=gb(),a=e==="dark"?"#1a4d2e":"#e7f5e9";return r.jsx("span",{className:"inline-flex items-center justify-center w-4 h-4 text-[10px] font-bold rounded",style:{backgroundColor:a,color:"#00ae42"},children:t})}function Rse(t,e){if(!t)return"";if(t.includes("hardened"))return e("printers.nozzleHardenedSteel");if(t.includes("stainless"))return e("printers.nozzleStainlessSteel");if(t.includes("tungsten"))return e("printers.nozzleTungstenCarbide");if(t.length>=4){const a=t.slice(2,4);if(a==="00")return e("printers.nozzleStainlessSteel");if(a==="01")return e("printers.nozzleHardenedSteel");if(a==="05")return e("printers.nozzleTungstenCarbide")}return t==="00"?e("printers.nozzleStainlessSteel"):t==="01"?e("printers.nozzleHardenedSteel"):t==="05"?e("printers.nozzleTungstenCarbide"):t.startsWith("H")?e("printers.nozzleHardenedSteel"):t}function zse(t,e){return t?t.startsWith("HH")?e("printers.nozzleHighFlow"):t.startsWith("HS")?e("printers.nozzleStandardFlow"):"":""}function Ise({slot:t,index:e,activeStatus:a,filamentName:n,children:i}){const{t:s}=wt(),[o,l]=y.useState(!1),[c,d]=y.useState("top"),u=y.useRef(null),m=y.useRef(null),p=y.useRef(null),f=!t.nozzle_diameter&&!t.nozzle_type,g=t.stat===1;y.useEffect(()=>{if(o&&u.current&&m.current){const C=u.current.getBoundingClientRect(),N=m.current.offsetHeight,j=C.top-56,D=window.innerHeight-C.bottom;jj?d("bottom"):d("top")}},[o]);const v=()=>{p.current&&clearTimeout(p.current),p.current=setTimeout(()=>l(!0),80)},b=()=>{p.current&&clearTimeout(p.current),p.current=setTimeout(()=>l(!1),100)};y.useEffect(()=>()=>{p.current&&clearTimeout(p.current)},[]);const x=WI(t.filament_color),S=Rse(t.nozzle_type,s),k=zse(t.nozzle_type,s);return r.jsxs("div",{ref:u,className:"relative",onMouseEnter:v,onMouseLeave:b,children:[i,o&&r.jsxs("div",{ref:m,className:` absolute left-1/2 -translate-x-1/2 z-50 ${c==="top"?"bottom-full mb-2":"top-full mt-2"} animate-in fade-in-0 zoom-in-95 duration-150 diff --git a/static/index.html b/static/index.html index 9b668570f..e9a706d3d 100644 --- a/static/index.html +++ b/static/index.html @@ -26,7 +26,7 @@ - +