diff --git a/backend/app/api/routes/archives.py b/backend/app/api/routes/archives.py index 92c2eab44..3c7bbf3e1 100644 --- a/backend/app/api/routes/archives.py +++ b/backend/app/api/routes/archives.py @@ -209,16 +209,39 @@ async def get_archive_stats(db: AsyncSession = Depends(get_db)): for printer_key, accs in printer_accuracies.items(): accuracy_by_printer[printer_key] = round(sum(accs) / len(accs), 1) - # Energy totals - energy_kwh_result = await db.execute( - select(func.sum(PrintArchive.energy_kwh)) - ) - total_energy_kwh = energy_kwh_result.scalar() or 0 + # Energy totals - check which mode to use + from backend.app.api.routes.settings import get_setting + energy_tracking_mode = await get_setting(db, "energy_tracking_mode") or "total" + energy_cost_per_kwh_str = await get_setting(db, "energy_cost_per_kwh") + energy_cost_per_kwh = float(energy_cost_per_kwh_str) if energy_cost_per_kwh_str else 0.15 - energy_cost_result = await db.execute( - select(func.sum(PrintArchive.energy_cost)) - ) - total_energy_cost = energy_cost_result.scalar() or 0 + if energy_tracking_mode == "total": + # Total mode: sum up 'total' counter from all smart plugs (lifetime consumption) + from backend.app.models.smart_plug import SmartPlug + from backend.app.services.tasmota import tasmota_service + + plugs_result = await db.execute(select(SmartPlug)) + plugs = list(plugs_result.scalars().all()) + + total_energy_kwh = 0.0 + for plug in plugs: + energy = await tasmota_service.get_energy(plug) + if energy and energy.get("total") is not None: + total_energy_kwh += energy["total"] + + total_energy_kwh = round(total_energy_kwh, 3) + total_energy_cost = round(total_energy_kwh * energy_cost_per_kwh, 2) + else: + # Print mode: sum up per-print energy from archives + energy_kwh_result = await db.execute( + select(func.sum(PrintArchive.energy_kwh)) + ) + total_energy_kwh = energy_kwh_result.scalar() or 0 + + energy_cost_result = await db.execute( + select(func.sum(PrintArchive.energy_cost)) + ) + total_energy_cost = energy_cost_result.scalar() or 0 return ArchiveStats( total_prints=total_prints, diff --git a/backend/app/main.py b/backend/app/main.py index 52990b84f..dbc34bdd3 100644 --- a/backend/app/main.py +++ b/backend/app/main.py @@ -555,49 +555,56 @@ async def on_print_complete(printer_id: int, data: dict): "status": status, }) - # Calculate energy used for this print + # Calculate energy used for this print (always per-print: end - start) try: starting_kwh = _print_energy_start.pop(archive_id, None) - logger.info(f"[ENERGY] Print complete for archive {archive_id}, starting_kwh={starting_kwh}, tracked_archives={list(_print_energy_start.keys())}") - if starting_kwh is not None: - async with async_session() as db: - # Get smart plug for this printer (SmartPlug is imported at module level) - plug_result = await db.execute( - select(SmartPlug).where(SmartPlug.printer_id == printer_id) - ) - plug = plug_result.scalar_one_or_none() + logger.info(f"[ENERGY] Print complete for archive {archive_id}, starting_kwh={starting_kwh}") - if plug: - energy = await tasmota_service.get_energy(plug) - logger.info(f"[ENERGY] Print complete - ending energy response: {energy}") - if energy and energy.get("total") is not None: - ending_kwh = energy["total"] - energy_used = round(ending_kwh - starting_kwh, 4) - logger.info(f"[ENERGY] Calculated: ending={ending_kwh}, starting={starting_kwh}, used={energy_used}") + async with async_session() as db: + # Get smart plug for this printer (SmartPlug is imported at module level) + plug_result = await db.execute( + select(SmartPlug).where(SmartPlug.printer_id == printer_id) + ) + plug = plug_result.scalar_one_or_none() - # Get energy cost per kWh from settings (default to 0.15) - from backend.app.api.routes.settings import get_setting - energy_cost_per_kwh = await get_setting(db, "energy_cost_per_kwh") - cost_per_kwh = float(energy_cost_per_kwh) if energy_cost_per_kwh else 0.15 - energy_cost = round(energy_used * cost_per_kwh, 2) + if plug: + energy = await tasmota_service.get_energy(plug) + logger.info(f"[ENERGY] Print complete - energy response: {energy}") - # Update archive with energy data - from backend.app.models.archive import PrintArchive - result = await db.execute( - select(PrintArchive).where(PrintArchive.id == archive_id) - ) - archive = result.scalar_one_or_none() - if archive: - archive.energy_kwh = energy_used - archive.energy_cost = energy_cost - await db.commit() - logger.info(f"[ENERGY] Saved to archive {archive_id}: {energy_used} kWh, cost={energy_cost}") - else: - logger.warning(f"[ENERGY] Archive {archive_id} not found when saving energy") - else: - logger.warning(f"[ENERGY] No 'total' in ending energy response") + energy_used = None + + # Calculate per-print energy: end total - start total + if starting_kwh is not None and energy and energy.get("total") is not None: + ending_kwh = energy["total"] + energy_used = round(ending_kwh - starting_kwh, 4) + logger.info(f"[ENERGY] Per-print energy: ending={ending_kwh}, starting={starting_kwh}, used={energy_used}") + elif starting_kwh is None: + logger.info(f"[ENERGY] No starting energy recorded for this archive") else: - logger.info(f"[ENERGY] No smart plug found for printer {printer_id} at print complete") + logger.warning(f"[ENERGY] No 'total' in ending energy response") + + if energy_used is not None and energy_used >= 0: + # Get energy cost per kWh from settings (default to 0.15) + from backend.app.api.routes.settings import get_setting + energy_cost_per_kwh = await get_setting(db, "energy_cost_per_kwh") + cost_per_kwh = float(energy_cost_per_kwh) if energy_cost_per_kwh else 0.15 + energy_cost = round(energy_used * cost_per_kwh, 2) + + # Update archive with energy data + from backend.app.models.archive import PrintArchive + result = await db.execute( + select(PrintArchive).where(PrintArchive.id == archive_id) + ) + archive = result.scalar_one_or_none() + if archive: + archive.energy_kwh = energy_used + archive.energy_cost = energy_cost + await db.commit() + logger.info(f"[ENERGY] Saved to archive {archive_id}: {energy_used} kWh, cost={energy_cost}") + else: + logger.warning(f"[ENERGY] Archive {archive_id} not found when saving energy") + else: + logger.info(f"[ENERGY] No smart plug found for printer {printer_id} at print complete") except Exception as e: import logging logging.getLogger(__name__).warning(f"Failed to calculate energy: {e}") diff --git a/backend/app/schemas/settings.py b/backend/app/schemas/settings.py index 385176a60..907fae856 100644 --- a/backend/app/schemas/settings.py +++ b/backend/app/schemas/settings.py @@ -10,6 +10,7 @@ class AppSettings(BaseModel): default_filament_cost: float = Field(default=25.0, description="Default filament cost per kg") currency: str = Field(default="USD", description="Currency for cost tracking") energy_cost_per_kwh: float = Field(default=0.15, description="Electricity cost per kWh for energy tracking") + energy_tracking_mode: str = Field(default="total", description="Energy display mode on stats: 'print' shows sum of per-print energy, 'total' shows lifetime plug consumption") class AppSettingsUpdate(BaseModel): @@ -21,3 +22,4 @@ class AppSettingsUpdate(BaseModel): default_filament_cost: float | None = None currency: str | None = None energy_cost_per_kwh: float | None = None + energy_tracking_mode: str | None = None diff --git a/frontend/src/api/client.ts b/frontend/src/api/client.ts index 894b17055..1f6848fe8 100644 --- a/frontend/src/api/client.ts +++ b/frontend/src/api/client.ts @@ -151,6 +151,7 @@ export interface AppSettings { default_filament_cost: number; currency: string; energy_cost_per_kwh: number; + energy_tracking_mode: 'print' | 'total'; } export type AppSettingsUpdate = Partial; diff --git a/frontend/src/pages/SettingsPage.tsx b/frontend/src/pages/SettingsPage.tsx index 6a685fafa..8d5d0a035 100644 --- a/frontend/src/pages/SettingsPage.tsx +++ b/frontend/src/pages/SettingsPage.tsx @@ -59,7 +59,8 @@ export function SettingsPage() { settings.capture_finish_photo !== localSettings.capture_finish_photo || settings.default_filament_cost !== localSettings.default_filament_cost || settings.currency !== localSettings.currency || - settings.energy_cost_per_kwh !== localSettings.energy_cost_per_kwh; + settings.energy_cost_per_kwh !== localSettings.energy_cost_per_kwh || + settings.energy_tracking_mode !== localSettings.energy_tracking_mode; setHasChanges(changed); } }, [settings, localSettings]); @@ -72,6 +73,8 @@ export function SettingsPage() { setHasChanges(false); setShowSaved(true); setTimeout(() => setShowSaved(false), 2000); + // Invalidate archive stats to reflect energy tracking mode change + queryClient.invalidateQueries({ queryKey: ['archiveStats'] }); }, }); @@ -249,8 +252,23 @@ export function SettingsPage() { } 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" /> + +
+ +

- Used for tracking energy costs per print via smart plugs + {localSettings.energy_tracking_mode === 'print' + ? 'Dashboard shows sum of energy used during prints' + : 'Dashboard shows lifetime energy from smart plugs'}

diff --git a/static/assets/index-MvaVdELS.js b/static/assets/index-C2qF9pCa.js similarity index 98% rename from static/assets/index-MvaVdELS.js rename to static/assets/index-C2qF9pCa.js index daa900c30..6f51a3d23 100644 --- a/static/assets/index-MvaVdELS.js +++ b/static/assets/index-C2qF9pCa.js @@ -8591,4 +8591,4 @@ Accuracy: ${t.time_accuracy.toFixed(0)}%`:t.actual_time_seconds?`Actual: ${Ng(t. To pick up a draggable item, press the space bar. While dragging, use the arrow keys to move the item. Press space again to drop the item in its new position, or press escape to cancel. - `},XBe={onDragStart(t){let{active:e}=t;return"Picked up draggable item "+e.id+"."},onDragOver(t){let{active:e,over:n}=t;return n?"Draggable item "+e.id+" was moved over droppable area "+n.id+".":"Draggable item "+e.id+" is no longer over a droppable area."},onDragEnd(t){let{active:e,over:n}=t;return n?"Draggable item "+e.id+" was dropped over droppable area "+n.id:"Draggable item "+e.id+" was dropped."},onDragCancel(t){let{active:e}=t;return"Dragging was cancelled. Draggable item "+e.id+" was dropped."}};function KBe(t){let{announcements:e=XBe,container:n,hiddenTextDescribedById:i,screenReaderInstructions:r=qBe}=t;const{announce:a,announcement:s}=GBe(),o=Gv("DndLiveRegion"),[l,c]=T.useState(!1);if(T.useEffect(()=>{c(!0)},[]),$Be(T.useMemo(()=>({onDragStart(f){let{active:p}=f;a(e.onDragStart({active:p}))},onDragMove(f){let{active:p,over:m}=f;e.onDragMove&&a(e.onDragMove({active:p,over:m}))},onDragOver(f){let{active:p,over:m}=f;a(e.onDragOver({active:p,over:m}))},onDragEnd(f){let{active:p,over:m}=f;a(e.onDragEnd({active:p,over:m}))},onDragCancel(f){let{active:p,over:m}=f;a(e.onDragCancel({active:p,over:m}))}}),[a,e])),!l)return null;const d=li.createElement(li.Fragment,null,li.createElement(HBe,{id:i,value:r.draggable}),li.createElement(VBe,{id:o,announcement:s}));return n?Bl.createPortal(d,n):d}var er;(function(t){t.DragStart="dragStart",t.DragMove="dragMove",t.DragEnd="dragEnd",t.DragCancel="dragCancel",t.DragOver="dragOver",t.RegisterDroppable="registerDroppable",t.SetDroppableDisabled="setDroppableDisabled",t.UnregisterDroppable="unregisterDroppable"})(er||(er={}));function sS(){}function PV(t,e){return T.useMemo(()=>({sensor:t,options:e??{}}),[t,e])}function YBe(){for(var t=arguments.length,e=new Array(t),n=0;n[...e].filter(i=>i!=null),[...e])}const xo=Object.freeze({x:0,y:0});function qZ(t,e){return Math.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2))}function XZ(t,e){let{data:{value:n}}=t,{data:{value:i}}=e;return n-i}function ZBe(t,e){let{data:{value:n}}=t,{data:{value:i}}=e;return i-n}function DV(t){let{left:e,top:n,height:i,width:r}=t;return[{x:e,y:n},{x:e+r,y:n},{x:e,y:n+i},{x:e+r,y:n+i}]}function KZ(t,e){if(!t||t.length===0)return null;const[n]=t;return n[e]}function OV(t,e,n){return e===void 0&&(e=t.left),n===void 0&&(n=t.top),{x:e+t.width*.5,y:n+t.height*.5}}const QBe=t=>{let{collisionRect:e,droppableRects:n,droppableContainers:i}=t;const r=OV(e,e.left,e.top),a=[];for(const s of i){const{id:o}=s,l=n.get(o);if(l){const c=qZ(OV(l),r);a.push({id:o,data:{droppableContainer:s,value:c}})}}return a.sort(XZ)},JBe=t=>{let{collisionRect:e,droppableRects:n,droppableContainers:i}=t;const r=DV(e),a=[];for(const s of i){const{id:o}=s,l=n.get(o);if(l){const c=DV(l),d=r.reduce((p,m,y)=>p+qZ(c[y],m),0),f=Number((d/4).toFixed(4));a.push({id:o,data:{droppableContainer:s,value:f}})}}return a.sort(XZ)};function e5e(t,e){const n=Math.max(e.top,t.top),i=Math.max(e.left,t.left),r=Math.min(e.left+e.width,t.left+t.width),a=Math.min(e.top+e.height,t.top+t.height),s=r-i,o=a-n;if(i{let{collisionRect:e,droppableRects:n,droppableContainers:i}=t;const r=[];for(const a of i){const{id:s}=a,o=n.get(s);if(o){const l=e5e(o,e);l>0&&r.push({id:s,data:{droppableContainer:a,value:l}})}}return r.sort(ZBe)};function n5e(t,e,n){return{...t,scaleX:e&&n?e.width/n.width:1,scaleY:e&&n?e.height/n.height:1}}function YZ(t,e){return t&&e?{x:t.left-e.left,y:t.top-e.top}:xo}function i5e(t){return function(n){for(var i=arguments.length,r=new Array(i>1?i-1:0),a=1;a({...s,top:s.top+t*o.y,bottom:s.bottom+t*o.y,left:s.left+t*o.x,right:s.right+t*o.x}),{...n})}}const r5e=i5e(1);function a5e(t){if(t.startsWith("matrix3d(")){const e=t.slice(9,-1).split(/, /);return{x:+e[12],y:+e[13],scaleX:+e[0],scaleY:+e[5]}}else if(t.startsWith("matrix(")){const e=t.slice(7,-1).split(/, /);return{x:+e[4],y:+e[5],scaleX:+e[0],scaleY:+e[3]}}return null}function s5e(t,e,n){const i=a5e(e);if(!i)return t;const{scaleX:r,scaleY:a,x:s,y:o}=i,l=t.left-s-(1-r)*parseFloat(n),c=t.top-o-(1-a)*parseFloat(n.slice(n.indexOf(" ")+1)),d=r?t.width/r:t.width,f=a?t.height/a:t.height;return{width:d,height:f,top:c,right:l+d,bottom:c+f,left:l}}const o5e={ignoreTransform:!1};function wm(t,e){e===void 0&&(e=o5e);let n=t.getBoundingClientRect();if(e.ignoreTransform){const{transform:c,transformOrigin:d}=za(t).getComputedStyle(t);c&&(n=s5e(n,c,d))}const{top:i,left:r,width:a,height:s,bottom:o,right:l}=n;return{top:i,left:r,width:a,height:s,bottom:o,right:l}}function kV(t){return wm(t,{ignoreTransform:!0})}function l5e(t){const e=t.innerWidth,n=t.innerHeight;return{top:0,left:0,right:e,bottom:n,width:e,height:n}}function c5e(t,e){return e===void 0&&(e=za(t).getComputedStyle(t)),e.position==="fixed"}function u5e(t,e){e===void 0&&(e=za(t).getComputedStyle(t));const n=/(auto|scroll|overlay)/;return["overflow","overflowX","overflowY"].some(r=>{const a=e[r];return typeof a=="string"?n.test(a):!1})}function Ow(t,e){const n=[];function i(r){if(e!=null&&n.length>=e||!r)return n;if(ck(r)&&r.scrollingElement!=null&&!n.includes(r.scrollingElement))return n.push(r.scrollingElement),n;if(!Hv(r)||GZ(r)||n.includes(r))return n;const a=za(t).getComputedStyle(r);return r!==t&&u5e(r,a)&&n.push(r),c5e(r,a)?n:i(r.parentNode)}return t?i(t):n}function ZZ(t){const[e]=Ow(t,1);return e??null}function E2(t){return!Dw||!t?null:_m(t)?t:lk(t)?ck(t)||t===Sm(t).scrollingElement?window:Hv(t)?t:null:null}function QZ(t){return _m(t)?t.scrollX:t.scrollLeft}function JZ(t){return _m(t)?t.scrollY:t.scrollTop}function RN(t){return{x:QZ(t),y:JZ(t)}}var _r;(function(t){t[t.Forward=1]="Forward",t[t.Backward=-1]="Backward"})(_r||(_r={}));function eQ(t){return!Dw||!t?!1:t===document.scrollingElement}function tQ(t){const e={x:0,y:0},n=eQ(t)?{height:window.innerHeight,width:window.innerWidth}:{height:t.clientHeight,width:t.clientWidth},i={x:t.scrollWidth-n.width,y:t.scrollHeight-n.height},r=t.scrollTop<=e.y,a=t.scrollLeft<=e.x,s=t.scrollTop>=i.y,o=t.scrollLeft>=i.x;return{isTop:r,isLeft:a,isBottom:s,isRight:o,maxScroll:i,minScroll:e}}const d5e={x:.2,y:.2};function f5e(t,e,n,i,r){let{top:a,left:s,right:o,bottom:l}=n;i===void 0&&(i=10),r===void 0&&(r=d5e);const{isTop:c,isBottom:d,isLeft:f,isRight:p}=tQ(t),m={x:0,y:0},y={x:0,y:0},b={height:e.height*r.y,width:e.width*r.x};return!c&&a<=e.top+b.height?(m.y=_r.Backward,y.y=i*Math.abs((e.top+b.height-a)/b.height)):!d&&l>=e.bottom-b.height&&(m.y=_r.Forward,y.y=i*Math.abs((e.bottom-b.height-l)/b.height)),!p&&o>=e.right-b.width?(m.x=_r.Forward,y.x=i*Math.abs((e.right-b.width-o)/b.width)):!f&&s<=e.left+b.width&&(m.x=_r.Backward,y.x=i*Math.abs((e.left+b.width-s)/b.width)),{direction:m,speed:y}}function h5e(t){if(t===document.scrollingElement){const{innerWidth:a,innerHeight:s}=window;return{top:0,left:0,right:a,bottom:s,width:a,height:s}}const{top:e,left:n,right:i,bottom:r}=t.getBoundingClientRect();return{top:e,left:n,right:i,bottom:r,width:t.clientWidth,height:t.clientHeight}}function nQ(t){return t.reduce((e,n)=>Mp(e,RN(n)),xo)}function p5e(t){return t.reduce((e,n)=>e+QZ(n),0)}function m5e(t){return t.reduce((e,n)=>e+JZ(n),0)}function g5e(t,e){if(e===void 0&&(e=wm),!t)return;const{top:n,left:i,bottom:r,right:a}=e(t);ZZ(t)&&(r<=0||a<=0||n>=window.innerHeight||i>=window.innerWidth)&&t.scrollIntoView({block:"center",inline:"center"})}const v5e=[["x",["left","right"],p5e],["y",["top","bottom"],m5e]];class fk{constructor(e,n){this.rect=void 0,this.width=void 0,this.height=void 0,this.top=void 0,this.bottom=void 0,this.right=void 0,this.left=void 0;const i=Ow(n),r=nQ(i);this.rect={...e},this.width=e.width,this.height=e.height;for(const[a,s,o]of v5e)for(const l of s)Object.defineProperty(this,l,{get:()=>{const c=o(i),d=r[a]-c;return this.rect[l]+d},enumerable:!0});Object.defineProperty(this,"rect",{enumerable:!1})}}class f0{constructor(e){this.target=void 0,this.listeners=[],this.removeAll=()=>{this.listeners.forEach(n=>{var i;return(i=this.target)==null?void 0:i.removeEventListener(...n)})},this.target=e}add(e,n,i){var r;(r=this.target)==null||r.addEventListener(e,n,i),this.listeners.push([e,n,i])}}function x5e(t){const{EventTarget:e}=za(t);return t instanceof e?t:Sm(t)}function A2(t,e){const n=Math.abs(t.x),i=Math.abs(t.y);return typeof e=="number"?Math.sqrt(n**2+i**2)>e:"x"in e&&"y"in e?n>e.x&&i>e.y:"x"in e?n>e.x:"y"in e?i>e.y:!1}var Ns;(function(t){t.Click="click",t.DragStart="dragstart",t.Keydown="keydown",t.ContextMenu="contextmenu",t.Resize="resize",t.SelectionChange="selectionchange",t.VisibilityChange="visibilitychange"})(Ns||(Ns={}));function LV(t){t.preventDefault()}function y5e(t){t.stopPropagation()}var mn;(function(t){t.Space="Space",t.Down="ArrowDown",t.Right="ArrowRight",t.Left="ArrowLeft",t.Up="ArrowUp",t.Esc="Escape",t.Enter="Enter",t.Tab="Tab"})(mn||(mn={}));const iQ={start:[mn.Space,mn.Enter],cancel:[mn.Esc],end:[mn.Space,mn.Enter,mn.Tab]},b5e=(t,e)=>{let{currentCoordinates:n}=e;switch(t.code){case mn.Right:return{...n,x:n.x+25};case mn.Left:return{...n,x:n.x-25};case mn.Down:return{...n,y:n.y+25};case mn.Up:return{...n,y:n.y-25}}};class hk{constructor(e){this.props=void 0,this.autoScrollEnabled=!1,this.referenceCoordinates=void 0,this.listeners=void 0,this.windowListeners=void 0,this.props=e;const{event:{target:n}}=e;this.props=e,this.listeners=new f0(Sm(n)),this.windowListeners=new f0(za(n)),this.handleKeyDown=this.handleKeyDown.bind(this),this.handleCancel=this.handleCancel.bind(this),this.attach()}attach(){this.handleStart(),this.windowListeners.add(Ns.Resize,this.handleCancel),this.windowListeners.add(Ns.VisibilityChange,this.handleCancel),setTimeout(()=>this.listeners.add(Ns.Keydown,this.handleKeyDown))}handleStart(){const{activeNode:e,onStart:n}=this.props,i=e.node.current;i&&g5e(i),n(xo)}handleKeyDown(e){if(dk(e)){const{active:n,context:i,options:r}=this.props,{keyboardCodes:a=iQ,coordinateGetter:s=b5e,scrollBehavior:o="smooth"}=r,{code:l}=e;if(a.end.includes(l)){this.handleEnd(e);return}if(a.cancel.includes(l)){this.handleCancel(e);return}const{collisionRect:c}=i.current,d=c?{x:c.left,y:c.top}:xo;this.referenceCoordinates||(this.referenceCoordinates=d);const f=s(e,{active:n,context:i.current,currentCoordinates:d});if(f){const p=nv(f,d),m={x:0,y:0},{scrollableAncestors:y}=i.current;for(const b of y){const x=e.code,{isTop:g,isRight:M,isLeft:w,isBottom:E,maxScroll:A,minScroll:P}=tQ(b),C=h5e(b),F={x:Math.min(x===mn.Right?C.right-C.width/2:C.right,Math.max(x===mn.Right?C.left:C.left+C.width/2,f.x)),y:Math.min(x===mn.Down?C.bottom-C.height/2:C.bottom,Math.max(x===mn.Down?C.top:C.top+C.height/2,f.y))},N=x===mn.Right&&!M||x===mn.Left&&!w,O=x===mn.Down&&!E||x===mn.Up&&!g;if(N&&F.x!==f.x){const B=b.scrollLeft+p.x,I=x===mn.Right&&B<=A.x||x===mn.Left&&B>=P.x;if(I&&!p.y){b.scrollTo({left:B,behavior:o});return}I?m.x=b.scrollLeft-B:m.x=x===mn.Right?b.scrollLeft-A.x:b.scrollLeft-P.x,m.x&&b.scrollBy({left:-m.x,behavior:o});break}else if(O&&F.y!==f.y){const B=b.scrollTop+p.y,I=x===mn.Down&&B<=A.y||x===mn.Up&&B>=P.y;if(I&&!p.x){b.scrollTo({top:B,behavior:o});return}I?m.y=b.scrollTop-B:m.y=x===mn.Down?b.scrollTop-A.y:b.scrollTop-P.y,m.y&&b.scrollBy({top:-m.y,behavior:o});break}}this.handleMove(e,Mp(nv(f,this.referenceCoordinates),m))}}}handleMove(e,n){const{onMove:i}=this.props;e.preventDefault(),i(n)}handleEnd(e){const{onEnd:n}=this.props;e.preventDefault(),this.detach(),n()}handleCancel(e){const{onCancel:n}=this.props;e.preventDefault(),this.detach(),n()}detach(){this.listeners.removeAll(),this.windowListeners.removeAll()}}hk.activators=[{eventName:"onKeyDown",handler:(t,e,n)=>{let{keyboardCodes:i=iQ,onActivation:r}=e,{active:a}=n;const{code:s}=t.nativeEvent;if(i.start.includes(s)){const o=a.activatorNode.current;return o&&t.target!==o?!1:(t.preventDefault(),r?.({event:t.nativeEvent}),!0)}return!1}}];function IV(t){return!!(t&&"distance"in t)}function UV(t){return!!(t&&"delay"in t)}class pk{constructor(e,n,i){var r;i===void 0&&(i=x5e(e.event.target)),this.props=void 0,this.events=void 0,this.autoScrollEnabled=!0,this.document=void 0,this.activated=!1,this.initialCoordinates=void 0,this.timeoutId=null,this.listeners=void 0,this.documentListeners=void 0,this.windowListeners=void 0,this.props=e,this.events=n;const{event:a}=e,{target:s}=a;this.props=e,this.events=n,this.document=Sm(s),this.documentListeners=new f0(this.document),this.listeners=new f0(i),this.windowListeners=new f0(za(s)),this.initialCoordinates=(r=CN(a))!=null?r:xo,this.handleStart=this.handleStart.bind(this),this.handleMove=this.handleMove.bind(this),this.handleEnd=this.handleEnd.bind(this),this.handleCancel=this.handleCancel.bind(this),this.handleKeydown=this.handleKeydown.bind(this),this.removeTextSelection=this.removeTextSelection.bind(this),this.attach()}attach(){const{events:e,props:{options:{activationConstraint:n,bypassActivationConstraint:i}}}=this;if(this.listeners.add(e.move.name,this.handleMove,{passive:!1}),this.listeners.add(e.end.name,this.handleEnd),e.cancel&&this.listeners.add(e.cancel.name,this.handleCancel),this.windowListeners.add(Ns.Resize,this.handleCancel),this.windowListeners.add(Ns.DragStart,LV),this.windowListeners.add(Ns.VisibilityChange,this.handleCancel),this.windowListeners.add(Ns.ContextMenu,LV),this.documentListeners.add(Ns.Keydown,this.handleKeydown),n){if(i!=null&&i({event:this.props.event,activeNode:this.props.activeNode,options:this.props.options}))return this.handleStart();if(UV(n)){this.timeoutId=setTimeout(this.handleStart,n.delay),this.handlePending(n);return}if(IV(n)){this.handlePending(n);return}}this.handleStart()}detach(){this.listeners.removeAll(),this.windowListeners.removeAll(),setTimeout(this.documentListeners.removeAll,50),this.timeoutId!==null&&(clearTimeout(this.timeoutId),this.timeoutId=null)}handlePending(e,n){const{active:i,onPending:r}=this.props;r(i,e,this.initialCoordinates,n)}handleStart(){const{initialCoordinates:e}=this,{onStart:n}=this.props;e&&(this.activated=!0,this.documentListeners.add(Ns.Click,y5e,{capture:!0}),this.removeTextSelection(),this.documentListeners.add(Ns.SelectionChange,this.removeTextSelection),n(e))}handleMove(e){var n;const{activated:i,initialCoordinates:r,props:a}=this,{onMove:s,options:{activationConstraint:o}}=a;if(!r)return;const l=(n=CN(e))!=null?n:xo,c=nv(r,l);if(!i&&o){if(IV(o)){if(o.tolerance!=null&&A2(c,o.tolerance))return this.handleCancel();if(A2(c,o.distance))return this.handleStart()}if(UV(o)&&A2(c,o.tolerance))return this.handleCancel();this.handlePending(o,c);return}e.cancelable&&e.preventDefault(),s(l)}handleEnd(){const{onAbort:e,onEnd:n}=this.props;this.detach(),this.activated||e(this.props.active),n()}handleCancel(){const{onAbort:e,onCancel:n}=this.props;this.detach(),this.activated||e(this.props.active),n()}handleKeydown(e){e.code===mn.Esc&&this.handleCancel()}removeTextSelection(){var e;(e=this.document.getSelection())==null||e.removeAllRanges()}}const _5e={cancel:{name:"pointercancel"},move:{name:"pointermove"},end:{name:"pointerup"}};class mk extends pk{constructor(e){const{event:n}=e,i=Sm(n.target);super(e,_5e,i)}}mk.activators=[{eventName:"onPointerDown",handler:(t,e)=>{let{nativeEvent:n}=t,{onActivation:i}=e;return!n.isPrimary||n.button!==0?!1:(i?.({event:n}),!0)}}];const S5e={move:{name:"mousemove"},end:{name:"mouseup"}};var NN;(function(t){t[t.RightClick=2]="RightClick"})(NN||(NN={}));class w5e extends pk{constructor(e){super(e,S5e,Sm(e.event.target))}}w5e.activators=[{eventName:"onMouseDown",handler:(t,e)=>{let{nativeEvent:n}=t,{onActivation:i}=e;return n.button===NN.RightClick?!1:(i?.({event:n}),!0)}}];const T2={cancel:{name:"touchcancel"},move:{name:"touchmove"},end:{name:"touchend"}};class M5e extends pk{constructor(e){super(e,T2)}static setup(){return window.addEventListener(T2.move.name,e,{capture:!1,passive:!1}),function(){window.removeEventListener(T2.move.name,e)};function e(){}}}M5e.activators=[{eventName:"onTouchStart",handler:(t,e)=>{let{nativeEvent:n}=t,{onActivation:i}=e;const{touches:r}=n;return r.length>1?!1:(i?.({event:n}),!0)}}];var h0;(function(t){t[t.Pointer=0]="Pointer",t[t.DraggableRect=1]="DraggableRect"})(h0||(h0={}));var oS;(function(t){t[t.TreeOrder=0]="TreeOrder",t[t.ReversedTreeOrder=1]="ReversedTreeOrder"})(oS||(oS={}));function E5e(t){let{acceleration:e,activator:n=h0.Pointer,canScroll:i,draggingRect:r,enabled:a,interval:s=5,order:o=oS.TreeOrder,pointerCoordinates:l,scrollableAncestors:c,scrollableAncestorRects:d,delta:f,threshold:p}=t;const m=T5e({delta:f,disabled:!a}),[y,b]=UBe(),x=T.useRef({x:0,y:0}),g=T.useRef({x:0,y:0}),M=T.useMemo(()=>{switch(n){case h0.Pointer:return l?{top:l.y,bottom:l.y,left:l.x,right:l.x}:null;case h0.DraggableRect:return r}},[n,r,l]),w=T.useRef(null),E=T.useCallback(()=>{const P=w.current;if(!P)return;const C=x.current.x*g.current.x,F=x.current.y*g.current.y;P.scrollBy(C,F)},[]),A=T.useMemo(()=>o===oS.TreeOrder?[...c].reverse():c,[o,c]);T.useEffect(()=>{if(!a||!c.length||!M){b();return}for(const P of A){if(i?.(P)===!1)continue;const C=c.indexOf(P),F=d[C];if(!F)continue;const{direction:N,speed:O}=f5e(P,F,M,e,p);for(const B of["x","y"])m[B][N[B]]||(O[B]=0,N[B]=0);if(O.x>0||O.y>0){b(),w.current=P,y(E,s),x.current=O,g.current=N;return}}x.current={x:0,y:0},g.current={x:0,y:0},b()},[e,E,i,b,a,s,JSON.stringify(M),JSON.stringify(m),y,c,A,d,JSON.stringify(p)])}const A5e={x:{[_r.Backward]:!1,[_r.Forward]:!1},y:{[_r.Backward]:!1,[_r.Forward]:!1}};function T5e(t){let{delta:e,disabled:n}=t;const i=TN(e);return Vv(r=>{if(n||!i||!r)return A5e;const a={x:Math.sign(e.x-i.x),y:Math.sign(e.y-i.y)};return{x:{[_r.Backward]:r.x[_r.Backward]||a.x===-1,[_r.Forward]:r.x[_r.Forward]||a.x===1},y:{[_r.Backward]:r.y[_r.Backward]||a.y===-1,[_r.Forward]:r.y[_r.Forward]||a.y===1}}},[n,e,i])}function C5e(t,e){const n=e!=null?t.get(e):void 0,i=n?n.node.current:null;return Vv(r=>{var a;return e==null?null:(a=i??r)!=null?a:null},[i,e])}function R5e(t,e){return T.useMemo(()=>t.reduce((n,i)=>{const{sensor:r}=i,a=r.activators.map(s=>({eventName:s.eventName,handler:e(s.handler,i)}));return[...n,...a]},[]),[t,e])}var rv;(function(t){t[t.Always=0]="Always",t[t.BeforeDragging=1]="BeforeDragging",t[t.WhileDragging=2]="WhileDragging"})(rv||(rv={}));var PN;(function(t){t.Optimized="optimized"})(PN||(PN={}));const FV=new Map;function N5e(t,e){let{dragging:n,dependencies:i,config:r}=e;const[a,s]=T.useState(null),{frequency:o,measure:l,strategy:c}=r,d=T.useRef(t),f=x(),p=tv(f),m=T.useCallback(function(g){g===void 0&&(g=[]),!p.current&&s(M=>M===null?g:M.concat(g.filter(w=>!M.includes(w))))},[p]),y=T.useRef(null),b=Vv(g=>{if(f&&!n)return FV;if(!g||g===FV||d.current!==t||a!=null){const M=new Map;for(let w of t){if(!w)continue;if(a&&a.length>0&&!a.includes(w.id)&&w.rect.current){M.set(w.id,w.rect.current);continue}const E=w.node.current,A=E?new fk(l(E),E):null;w.rect.current=A,A&&M.set(w.id,A)}return M}return g},[t,a,n,f,l]);return T.useEffect(()=>{d.current=t},[t]),T.useEffect(()=>{f||m()},[n,f]),T.useEffect(()=>{a&&a.length>0&&s(null)},[JSON.stringify(a)]),T.useEffect(()=>{f||typeof o!="number"||y.current!==null||(y.current=setTimeout(()=>{m(),y.current=null},o))},[o,f,m,...i]),{droppableRects:b,measureDroppableContainers:m,measuringScheduled:a!=null};function x(){switch(c){case rv.Always:return!1;case rv.BeforeDragging:return n;default:return!n}}}function rQ(t,e){return Vv(n=>t?n||(typeof e=="function"?e(t):t):null,[e,t])}function P5e(t,e){return rQ(t,e)}function D5e(t){let{callback:e,disabled:n}=t;const i=uk(e),r=T.useMemo(()=>{if(n||typeof window>"u"||typeof window.MutationObserver>"u")return;const{MutationObserver:a}=window;return new a(i)},[i,n]);return T.useEffect(()=>()=>r?.disconnect(),[r]),r}function kw(t){let{callback:e,disabled:n}=t;const i=uk(e),r=T.useMemo(()=>{if(n||typeof window>"u"||typeof window.ResizeObserver>"u")return;const{ResizeObserver:a}=window;return new a(i)},[n]);return T.useEffect(()=>()=>r?.disconnect(),[r]),r}function O5e(t){return new fk(wm(t),t)}function zV(t,e,n){e===void 0&&(e=O5e);const[i,r]=T.useState(null);function a(){r(l=>{if(!t)return null;if(t.isConnected===!1){var c;return(c=l??n)!=null?c:null}const d=e(t);return JSON.stringify(l)===JSON.stringify(d)?l:d})}const s=D5e({callback(l){if(t)for(const c of l){const{type:d,target:f}=c;if(d==="childList"&&f instanceof HTMLElement&&f.contains(t)){a();break}}}}),o=kw({callback:a});return Ko(()=>{a(),t?(o?.observe(t),s?.observe(document.body,{childList:!0,subtree:!0})):(o?.disconnect(),s?.disconnect())},[t]),i}function k5e(t){const e=rQ(t);return YZ(t,e)}const jV=[];function L5e(t){const e=T.useRef(t),n=Vv(i=>t?i&&i!==jV&&t&&e.current&&t.parentNode===e.current.parentNode?i:Ow(t):jV,[t]);return T.useEffect(()=>{e.current=t},[t]),n}function I5e(t){const[e,n]=T.useState(null),i=T.useRef(t),r=T.useCallback(a=>{const s=E2(a.target);s&&n(o=>o?(o.set(s,RN(s)),new Map(o)):null)},[]);return T.useEffect(()=>{const a=i.current;if(t!==a){s(a);const o=t.map(l=>{const c=E2(l);return c?(c.addEventListener("scroll",r,{passive:!0}),[c,RN(c)]):null}).filter(l=>l!=null);n(o.length?new Map(o):null),i.current=t}return()=>{s(t),s(a)};function s(o){o.forEach(l=>{const c=E2(l);c?.removeEventListener("scroll",r)})}},[r,t]),T.useMemo(()=>t.length?e?Array.from(e.values()).reduce((a,s)=>Mp(a,s),xo):nQ(t):xo,[t,e])}function BV(t,e){e===void 0&&(e=[]);const n=T.useRef(null);return T.useEffect(()=>{n.current=null},e),T.useEffect(()=>{const i=t!==xo;i&&!n.current&&(n.current=t),!i&&n.current&&(n.current=null)},[t]),n.current?nv(t,n.current):xo}function U5e(t){T.useEffect(()=>{if(!Dw)return;const e=t.map(n=>{let{sensor:i}=n;return i.setup==null?void 0:i.setup()});return()=>{for(const n of e)n?.()}},t.map(e=>{let{sensor:n}=e;return n}))}function F5e(t,e){return T.useMemo(()=>t.reduce((n,i)=>{let{eventName:r,handler:a}=i;return n[r]=s=>{a(s,e)},n},{}),[t,e])}function aQ(t){return T.useMemo(()=>t?l5e(t):null,[t])}const HV=[];function z5e(t,e){e===void 0&&(e=wm);const[n]=t,i=aQ(n?za(n):null),[r,a]=T.useState(HV);function s(){a(()=>t.length?t.map(l=>eQ(l)?i:new fk(e(l),l)):HV)}const o=kw({callback:s});return Ko(()=>{o?.disconnect(),s(),t.forEach(l=>o?.observe(l))},[t]),r}function j5e(t){if(!t)return null;if(t.children.length>1)return t;const e=t.children[0];return Hv(e)?e:t}function B5e(t){let{measure:e}=t;const[n,i]=T.useState(null),r=T.useCallback(c=>{for(const{target:d}of c)if(Hv(d)){i(f=>{const p=e(d);return f?{...f,width:p.width,height:p.height}:p});break}},[e]),a=kw({callback:r}),s=T.useCallback(c=>{const d=j5e(c);a?.disconnect(),d&&a?.observe(d),i(d?e(d):null)},[e,a]),[o,l]=aS(s);return T.useMemo(()=>({nodeRef:o,rect:n,setRef:l}),[n,o,l])}const H5e=[{sensor:mk,options:{}},{sensor:hk,options:{}}],V5e={current:{}},n_={draggable:{measure:kV},droppable:{measure:kV,strategy:rv.WhileDragging,frequency:PN.Optimized},dragOverlay:{measure:wm}};class p0 extends Map{get(e){var n;return e!=null&&(n=super.get(e))!=null?n:void 0}toArray(){return Array.from(this.values())}getEnabled(){return this.toArray().filter(e=>{let{disabled:n}=e;return!n})}getNodeFor(e){var n,i;return(n=(i=this.get(e))==null?void 0:i.node.current)!=null?n:void 0}}const G5e={activatorEvent:null,active:null,activeNode:null,activeNodeRect:null,collisions:null,containerNodeRect:null,draggableNodes:new Map,droppableRects:new Map,droppableContainers:new p0,over:null,dragOverlay:{nodeRef:{current:null},rect:null,setRef:sS},scrollableAncestors:[],scrollableAncestorRects:[],measuringConfiguration:n_,measureDroppableContainers:sS,windowRect:null,measuringScheduled:!1},$5e={activatorEvent:null,activators:[],active:null,activeNodeRect:null,ariaDescribedById:{draggable:""},dispatch:sS,draggableNodes:new Map,over:null,measureDroppableContainers:sS},Lw=T.createContext($5e),sQ=T.createContext(G5e);function W5e(){return{draggable:{active:null,initialCoordinates:{x:0,y:0},nodes:new Map,translate:{x:0,y:0}},droppable:{containers:new p0}}}function q5e(t,e){switch(e.type){case er.DragStart:return{...t,draggable:{...t.draggable,initialCoordinates:e.initialCoordinates,active:e.active}};case er.DragMove:return t.draggable.active==null?t:{...t,draggable:{...t.draggable,translate:{x:e.coordinates.x-t.draggable.initialCoordinates.x,y:e.coordinates.y-t.draggable.initialCoordinates.y}}};case er.DragEnd:case er.DragCancel:return{...t,draggable:{...t.draggable,active:null,initialCoordinates:{x:0,y:0},translate:{x:0,y:0}}};case er.RegisterDroppable:{const{element:n}=e,{id:i}=n,r=new p0(t.droppable.containers);return r.set(i,n),{...t,droppable:{...t.droppable,containers:r}}}case er.SetDroppableDisabled:{const{id:n,key:i,disabled:r}=e,a=t.droppable.containers.get(n);if(!a||i!==a.key)return t;const s=new p0(t.droppable.containers);return s.set(n,{...a,disabled:r}),{...t,droppable:{...t.droppable,containers:s}}}case er.UnregisterDroppable:{const{id:n,key:i}=e,r=t.droppable.containers.get(n);if(!r||i!==r.key)return t;const a=new p0(t.droppable.containers);return a.delete(n),{...t,droppable:{...t.droppable,containers:a}}}default:return t}}function X5e(t){let{disabled:e}=t;const{active:n,activatorEvent:i,draggableNodes:r}=T.useContext(Lw),a=TN(i),s=TN(n?.id);return T.useEffect(()=>{if(!e&&!i&&a&&s!=null){if(!dk(a)||document.activeElement===a.target)return;const o=r.get(s);if(!o)return;const{activatorNode:l,node:c}=o;if(!l.current&&!c.current)return;requestAnimationFrame(()=>{for(const d of[l.current,c.current]){if(!d)continue;const f=jBe(d);if(f){f.focus();break}}})}},[i,e,r,s,a]),null}function K5e(t,e){let{transform:n,...i}=e;return t!=null&&t.length?t.reduce((r,a)=>a({transform:r,...i}),n):n}function Y5e(t){return T.useMemo(()=>({draggable:{...n_.draggable,...t?.draggable},droppable:{...n_.droppable,...t?.droppable},dragOverlay:{...n_.dragOverlay,...t?.dragOverlay}}),[t?.draggable,t?.droppable,t?.dragOverlay])}function Z5e(t){let{activeNode:e,measure:n,initialRect:i,config:r=!0}=t;const a=T.useRef(!1),{x:s,y:o}=typeof r=="boolean"?{x:r,y:r}:r;Ko(()=>{if(!s&&!o||!e){a.current=!1;return}if(a.current||!i)return;const c=e?.node.current;if(!c||c.isConnected===!1)return;const d=n(c),f=YZ(d,i);if(s||(f.x=0),o||(f.y=0),a.current=!0,Math.abs(f.x)>0||Math.abs(f.y)>0){const p=ZZ(c);p&&p.scrollBy({top:f.y,left:f.x})}},[e,s,o,i,n])}const oQ=T.createContext({...xo,scaleX:1,scaleY:1});var pu;(function(t){t[t.Uninitialized=0]="Uninitialized",t[t.Initializing=1]="Initializing",t[t.Initialized=2]="Initialized"})(pu||(pu={}));const Q5e=T.memo(function(e){var n,i,r,a;let{id:s,accessibility:o,autoScroll:l=!0,children:c,sensors:d=H5e,collisionDetection:f=t5e,measuring:p,modifiers:m,...y}=e;const b=T.useReducer(q5e,void 0,W5e),[x,g]=b,[M,w]=WBe(),[E,A]=T.useState(pu.Uninitialized),P=E===pu.Initialized,{draggable:{active:C,nodes:F,translate:N},droppable:{containers:O}}=x,B=C!=null?F.get(C):null,I=T.useRef({initial:null,translated:null}),G=T.useMemo(()=>{var ke;return C!=null?{id:C,data:(ke=B?.data)!=null?ke:V5e,rect:I}:null},[C,B]),L=T.useRef(null),[$,q]=T.useState(null),[W,Y]=T.useState(null),J=tv(y,Object.values(y)),se=Gv("DndDescribedBy",s),j=T.useMemo(()=>O.getEnabled(),[O]),X=Y5e(p),{droppableRects:re,measureDroppableContainers:ce,measuringScheduled:xe}=N5e(j,{dragging:P,dependencies:[N.x,N.y],config:X.droppable}),me=C5e(F,C),ye=T.useMemo(()=>W?CN(W):null,[W]),De=de(),he=P5e(me,X.draggable.measure);Z5e({activeNode:C!=null?F.get(C):null,config:De.layoutShiftCompensation,initialRect:he,measure:X.draggable.measure});const we=zV(me,X.draggable.measure,he),je=zV(me?me.parentElement:null),le=T.useRef({activatorEvent:null,active:null,activeNode:me,collisionRect:null,collisions:null,droppableRects:re,draggableNodes:F,draggingNode:null,draggingNodeRect:null,droppableContainers:O,over:null,scrollableAncestors:[],scrollAdjustedTranslate:null}),ut=O.getNodeFor((n=le.current.over)==null?void 0:n.id),z=B5e({measure:X.dragOverlay.measure}),V=(i=z.nodeRef.current)!=null?i:me,ie=P?(r=z.rect)!=null?r:we:null,Q=!!(z.nodeRef.current&&z.rect),ee=k5e(Q?null:we),ae=aQ(V?za(V):null),Pe=L5e(P?ut??me:null),Re=z5e(Pe),te=K5e(m,{transform:{x:N.x-ee.x,y:N.y-ee.y,scaleX:1,scaleY:1},activatorEvent:W,active:G,activeNodeRect:we,containerNodeRect:je,draggingNodeRect:ie,over:le.current.over,overlayNodeRect:z.rect,scrollableAncestors:Pe,scrollableAncestorRects:Re,windowRect:ae}),U=ye?Mp(ye,N):null,k=I5e(Pe),K=BV(k),pe=BV(k,[we]),ve=Mp(te,K),fe=ie?r5e(ie,te):null,Ye=G&&fe?f({active:G,collisionRect:fe,droppableRects:re,droppableContainers:j,pointerCoordinates:U}):null,Le=KZ(Ye,"id"),[qe,it]=T.useState(null),Ie=Q?te:Mp(te,pe),Ne=n5e(Ie,(a=qe?.rect)!=null?a:null,we),ft=T.useRef(null),et=T.useCallback((ke,Me)=>{let{sensor:ge,options:Be}=Me;if(L.current==null)return;const at=F.get(L.current);if(!at)return;const yt=ke.nativeEvent,Ct=new ge({active:L.current,activeNode:at,event:yt,options:Be,context:le,onAbort(Dt){if(!F.get(Dt))return;const{onDragAbort:$n}=J.current,dr={id:Dt};$n?.(dr),M({type:"onDragAbort",event:dr})},onPending(Dt,Tn,$n,dr){if(!F.get(Dt))return;const{onDragPending:fr}=J.current,Tr={id:Dt,constraint:Tn,initialCoordinates:$n,offset:dr};fr?.(Tr),M({type:"onDragPending",event:Tr})},onStart(Dt){const Tn=L.current;if(Tn==null)return;const $n=F.get(Tn);if(!$n)return;const{onDragStart:dr}=J.current,Ki={activatorEvent:yt,active:{id:Tn,data:$n.data,rect:I}};Bl.unstable_batchedUpdates(()=>{dr?.(Ki),A(pu.Initializing),g({type:er.DragStart,initialCoordinates:Dt,active:Tn}),M({type:"onDragStart",event:Ki}),q(ft.current),Y(yt)})},onMove(Dt){g({type:er.DragMove,coordinates:Dt})},onEnd:tn(er.DragEnd),onCancel:tn(er.DragCancel)});ft.current=Ct;function tn(Dt){return async function(){const{active:$n,collisions:dr,over:Ki,scrollAdjustedTranslate:fr}=le.current;let Tr=null;if($n&&fr){const{cancelDrop:Vr}=J.current;Tr={activatorEvent:yt,active:$n,collisions:dr,delta:fr,over:Ki},Dt===er.DragEnd&&typeof Vr=="function"&&await Promise.resolve(Vr(Tr))&&(Dt=er.DragCancel)}L.current=null,Bl.unstable_batchedUpdates(()=>{g({type:Dt}),A(pu.Uninitialized),it(null),q(null),Y(null),ft.current=null;const Vr=Dt===er.DragEnd?"onDragEnd":"onDragCancel";if(Tr){const Di=J.current[Vr];Di?.(Tr),M({type:Vr,event:Tr})}})}}},[F]),Je=T.useCallback((ke,Me)=>(ge,Be)=>{const at=ge.nativeEvent,yt=F.get(Be);if(L.current!==null||!yt||at.dndKit||at.defaultPrevented)return;const Ct={active:yt};ke(ge,Me.options,Ct)===!0&&(at.dndKit={capturedBy:Me.sensor},L.current=Be,et(ge,Me))},[F,et]),st=R5e(d,Je);U5e(d),Ko(()=>{we&&E===pu.Initializing&&A(pu.Initialized)},[we,E]),T.useEffect(()=>{const{onDragMove:ke}=J.current,{active:Me,activatorEvent:ge,collisions:Be,over:at}=le.current;if(!Me||!ge)return;const yt={active:Me,activatorEvent:ge,collisions:Be,delta:{x:ve.x,y:ve.y},over:at};Bl.unstable_batchedUpdates(()=>{ke?.(yt),M({type:"onDragMove",event:yt})})},[ve.x,ve.y]),T.useEffect(()=>{const{active:ke,activatorEvent:Me,collisions:ge,droppableContainers:Be,scrollAdjustedTranslate:at}=le.current;if(!ke||L.current==null||!Me||!at)return;const{onDragOver:yt}=J.current,Ct=Be.get(Le),tn=Ct&&Ct.rect.current?{id:Ct.id,rect:Ct.rect.current,data:Ct.data,disabled:Ct.disabled}:null,Dt={active:ke,activatorEvent:Me,collisions:ge,delta:{x:at.x,y:at.y},over:tn};Bl.unstable_batchedUpdates(()=>{it(tn),yt?.(Dt),M({type:"onDragOver",event:Dt})})},[Le]),Ko(()=>{le.current={activatorEvent:W,active:G,activeNode:me,collisionRect:fe,collisions:Ye,droppableRects:re,draggableNodes:F,draggingNode:V,draggingNodeRect:ie,droppableContainers:O,over:qe,scrollableAncestors:Pe,scrollAdjustedTranslate:ve},I.current={initial:ie,translated:fe}},[G,me,Ye,fe,F,V,ie,re,O,qe,Pe,ve]),E5e({...De,delta:N,draggingRect:fe,pointerCoordinates:U,scrollableAncestors:Pe,scrollableAncestorRects:Re});const ue=T.useMemo(()=>({active:G,activeNode:me,activeNodeRect:we,activatorEvent:W,collisions:Ye,containerNodeRect:je,dragOverlay:z,draggableNodes:F,droppableContainers:O,droppableRects:re,over:qe,measureDroppableContainers:ce,scrollableAncestors:Pe,scrollableAncestorRects:Re,measuringConfiguration:X,measuringScheduled:xe,windowRect:ae}),[G,me,we,W,Ye,je,z,F,O,re,qe,ce,Pe,Re,X,xe,ae]),tt=T.useMemo(()=>({activatorEvent:W,activators:st,active:G,activeNodeRect:we,ariaDescribedById:{draggable:se},dispatch:g,draggableNodes:F,over:qe,measureDroppableContainers:ce}),[W,st,G,we,g,se,F,qe,ce]);return li.createElement(WZ.Provider,{value:w},li.createElement(Lw.Provider,{value:tt},li.createElement(sQ.Provider,{value:ue},li.createElement(oQ.Provider,{value:Ne},c)),li.createElement(X5e,{disabled:o?.restoreFocus===!1})),li.createElement(KBe,{...o,hiddenTextDescribedById:se}));function de(){const ke=$?.autoScrollEnabled===!1,Me=typeof l=="object"?l.enabled===!1:l===!1,ge=P&&!ke&&!Me;return typeof l=="object"?{...l,enabled:ge}:{enabled:ge}}}),J5e=T.createContext(null),VV="button",eHe="Draggable";function tHe(t){let{id:e,data:n,disabled:i=!1,attributes:r}=t;const a=Gv(eHe),{activators:s,activatorEvent:o,active:l,activeNodeRect:c,ariaDescribedById:d,draggableNodes:f,over:p}=T.useContext(Lw),{role:m=VV,roleDescription:y="draggable",tabIndex:b=0}=r??{},x=l?.id===e,g=T.useContext(x?oQ:J5e),[M,w]=aS(),[E,A]=aS(),P=F5e(s,e),C=tv(n);Ko(()=>(f.set(e,{id:e,key:a,node:M,activatorNode:E,data:C}),()=>{const N=f.get(e);N&&N.key===a&&f.delete(e)}),[f,e]);const F=T.useMemo(()=>({role:m,tabIndex:b,"aria-disabled":i,"aria-pressed":x&&m===VV?!0:void 0,"aria-roledescription":y,"aria-describedby":d.draggable}),[i,m,b,x,y,d.draggable]);return{active:l,activatorEvent:o,activeNodeRect:c,attributes:F,isDragging:x,listeners:i?void 0:P,node:M,over:p,setNodeRef:w,setActivatorNodeRef:A,transform:g}}function nHe(){return T.useContext(sQ)}const iHe="Droppable",rHe={timeout:25};function aHe(t){let{data:e,disabled:n=!1,id:i,resizeObserverConfig:r}=t;const a=Gv(iHe),{active:s,dispatch:o,over:l,measureDroppableContainers:c}=T.useContext(Lw),d=T.useRef({disabled:n}),f=T.useRef(!1),p=T.useRef(null),m=T.useRef(null),{disabled:y,updateMeasurementsFor:b,timeout:x}={...rHe,...r},g=tv(b??i),M=T.useCallback(()=>{if(!f.current){f.current=!0;return}m.current!=null&&clearTimeout(m.current),m.current=setTimeout(()=>{c(Array.isArray(g.current)?g.current:[g.current]),m.current=null},x)},[x]),w=kw({callback:M,disabled:y||!s}),E=T.useCallback((F,N)=>{w&&(N&&(w.unobserve(N),f.current=!1),F&&w.observe(F))},[w]),[A,P]=aS(E),C=tv(e);return T.useEffect(()=>{!w||!A.current||(w.disconnect(),f.current=!1,w.observe(A.current))},[A,w]),T.useEffect(()=>(o({type:er.RegisterDroppable,element:{id:i,key:a,disabled:n,node:A,rect:p,data:C}}),()=>o({type:er.UnregisterDroppable,key:a,id:i})),[i]),T.useEffect(()=>{n!==d.current.disabled&&(o({type:er.SetDroppableDisabled,id:i,key:a,disabled:n}),d.current.disabled=n)},[i,a,n,o]),{active:s,rect:p,isOver:l?.id===i,node:A,over:l,setNodeRef:P}}function gk(t,e,n){const i=t.slice();return i.splice(n<0?i.length+n:n,0,i.splice(e,1)[0]),i}function sHe(t,e){return t.reduce((n,i,r)=>{const a=e.get(i);return a&&(n[r]=a),n},Array(t.length))}function Db(t){return t!==null&&t>=0}function oHe(t,e){if(t===e)return!0;if(t.length!==e.length)return!1;for(let n=0;n{let{rects:e,activeIndex:n,overIndex:i,index:r}=t;const a=gk(e,i,n),s=e[r],o=a[r];return!o||!s?null:{x:o.left-s.left,y:o.top-s.top,scaleX:o.width/s.width,scaleY:o.height/s.height}},lQ="Sortable",cQ=li.createContext({activeIndex:-1,containerId:lQ,disableTransforms:!1,items:[],overIndex:-1,useDragOverlay:!1,sortedRects:[],strategy:vk,disabled:{draggable:!1,droppable:!1}});function cHe(t){let{children:e,id:n,items:i,strategy:r=vk,disabled:a=!1}=t;const{active:s,dragOverlay:o,droppableRects:l,over:c,measureDroppableContainers:d}=nHe(),f=Gv(lQ,n),p=o.rect!==null,m=T.useMemo(()=>i.map(P=>typeof P=="object"&&"id"in P?P.id:P),[i]),y=s!=null,b=s?m.indexOf(s.id):-1,x=c?m.indexOf(c.id):-1,g=T.useRef(m),M=!oHe(m,g.current),w=x!==-1&&b===-1||M,E=lHe(a);Ko(()=>{M&&y&&d(m)},[M,m,y,d]),T.useEffect(()=>{g.current=m},[m]);const A=T.useMemo(()=>({activeIndex:b,containerId:f,disabled:E,disableTransforms:w,items:m,overIndex:x,useDragOverlay:p,sortedRects:sHe(m,l),strategy:r}),[b,f,E.draggable,E.droppable,w,m,x,l,p,r]);return li.createElement(cQ.Provider,{value:A},e)}const uHe=t=>{let{id:e,items:n,activeIndex:i,overIndex:r}=t;return gk(n,i,r).indexOf(e)},dHe=t=>{let{containerId:e,isSorting:n,wasDragging:i,index:r,items:a,newIndex:s,previousItems:o,previousContainerId:l,transition:c}=t;return!c||!i||o!==a&&r===s?!1:n?!0:s!==r&&e===l},fHe={duration:200,easing:"ease"},uQ="transform",hHe=iv.Transition.toString({property:uQ,duration:0,easing:"linear"}),pHe={roleDescription:"sortable"};function mHe(t){let{disabled:e,index:n,node:i,rect:r}=t;const[a,s]=T.useState(null),o=T.useRef(n);return Ko(()=>{if(!e&&n!==o.current&&i.current){const l=r.current;if(l){const c=wm(i.current,{ignoreTransform:!0}),d={x:l.left-c.left,y:l.top-c.top,scaleX:l.width/c.width,scaleY:l.height/c.height};(d.x||d.y)&&s(d)}}n!==o.current&&(o.current=n)},[e,n,i,r]),T.useEffect(()=>{a&&s(null)},[a]),a}function gHe(t){let{animateLayoutChanges:e=dHe,attributes:n,disabled:i,data:r,getNewIndex:a=uHe,id:s,strategy:o,resizeObserverConfig:l,transition:c=fHe}=t;const{items:d,containerId:f,activeIndex:p,disabled:m,disableTransforms:y,sortedRects:b,overIndex:x,useDragOverlay:g,strategy:M}=T.useContext(cQ),w=vHe(i,m),E=d.indexOf(s),A=T.useMemo(()=>({sortable:{containerId:f,index:E,items:d},...r}),[f,r,E,d]),P=T.useMemo(()=>d.slice(d.indexOf(s)),[d,s]),{rect:C,node:F,isOver:N,setNodeRef:O}=aHe({id:s,data:A,disabled:w.droppable,resizeObserverConfig:{updateMeasurementsFor:P,...l}}),{active:B,activatorEvent:I,activeNodeRect:G,attributes:L,setNodeRef:$,listeners:q,isDragging:W,over:Y,setActivatorNodeRef:J,transform:se}=tHe({id:s,data:A,attributes:{...pHe,...n},disabled:w.draggable}),j=IBe(O,$),X=!!B,re=X&&!y&&Db(p)&&Db(x),ce=!g&&W,xe=ce&&re?se:null,ye=re?xe??(o??M)({rects:b,activeNodeRect:G,activeIndex:p,overIndex:x,index:E}):null,De=Db(p)&&Db(x)?a({id:s,items:d,activeIndex:p,overIndex:x}):E,he=B?.id,we=T.useRef({activeId:he,items:d,newIndex:De,containerId:f}),je=d!==we.current.items,le=e({active:B,containerId:f,isDragging:W,isSorting:X,id:s,index:E,items:d,newIndex:we.current.newIndex,previousItems:we.current.items,previousContainerId:we.current.containerId,transition:c,wasDragging:we.current.activeId!=null}),ut=mHe({disabled:!le,index:E,node:F,rect:C});return T.useEffect(()=>{X&&we.current.newIndex!==De&&(we.current.newIndex=De),f!==we.current.containerId&&(we.current.containerId=f),d!==we.current.items&&(we.current.items=d)},[X,De,f,d]),T.useEffect(()=>{if(he===we.current.activeId)return;if(he!=null&&we.current.activeId==null){we.current.activeId=he;return}const V=setTimeout(()=>{we.current.activeId=he},50);return()=>clearTimeout(V)},[he]),{active:B,activeIndex:p,attributes:L,data:A,rect:C,index:E,newIndex:De,items:d,isOver:N,isSorting:X,isDragging:W,listeners:q,node:F,overIndex:x,over:Y,setNodeRef:j,setActivatorNodeRef:J,setDroppableNodeRef:O,setDraggableNodeRef:$,transform:ut??ye,transition:z()};function z(){if(ut||je&&we.current.newIndex===E)return hHe;if(!(ce&&!dk(I)||!c)&&(X||le))return iv.Transition.toString({...c,property:uQ})}}function vHe(t,e){var n,i;return typeof t=="boolean"?{draggable:t,droppable:!1}:{draggable:(n=t?.draggable)!=null?n:e.draggable,droppable:(i=t?.droppable)!=null?i:e.droppable}}function lS(t){if(!t)return!1;const e=t.data.current;return!!(e&&"sortable"in e&&typeof e.sortable=="object"&&"containerId"in e.sortable&&"items"in e.sortable&&"index"in e.sortable)}const xHe=[mn.Down,mn.Right,mn.Up,mn.Left],yHe=(t,e)=>{let{context:{active:n,collisionRect:i,droppableRects:r,droppableContainers:a,over:s,scrollableAncestors:o}}=e;if(xHe.includes(t.code)){if(t.preventDefault(),!n||!i)return;const l=[];a.getEnabled().forEach(f=>{if(!f||f!=null&&f.disabled)return;const p=r.get(f.id);if(p)switch(t.code){case mn.Down:i.topp.top&&l.push(f);break;case mn.Left:i.left>p.left&&l.push(f);break;case mn.Right:i.left1&&(d=c[1].id),d!=null){const f=a.get(n.id),p=a.get(d),m=p?r.get(p.id):null,y=p?.node.current;if(y&&m&&f&&p){const x=Ow(y).some((P,C)=>o[C]!==P),g=dQ(f,p),M=bHe(f,p),w=x||!g?{x:0,y:0}:{x:M?i.width-m.width:0,y:M?i.height-m.height:0},E={x:m.left,y:m.top};return w.x&&w.y?E:nv(E,w)}}}};function dQ(t,e){return!lS(t)||!lS(e)?!1:t.data.current.sortable.containerId===e.data.current.sortable.containerId}function bHe(t,e){return!lS(t)||!lS(e)||!dQ(t,e)?!1:t.data.current.sortable.index{const x={};return t.forEach(g=>{x[g.id]=g.defaultSize||4}),x},[r,a]=T.useState(()=>{const x=localStorage.getItem(e);if(x)try{const g=JSON.parse(x);return g.sizes||(g.sizes=i()),g}catch{}return{order:t.map(g=>g.id),hidden:t.filter(g=>g.defaultVisible===!1).map(g=>g.id),sizes:i()}}),[s,o]=T.useState(!1);T.useEffect(()=>{localStorage.setItem(e,JSON.stringify(r))},[r,e]),T.useEffect(()=>{const g=t.map(M=>M.id).filter(M=>!r.order.includes(M));g.length>0&&a(M=>({...M,order:[...M.order,...g]}))},[t,r.order]);const l=YBe(PV(mk,{activationConstraint:{distance:8}}),PV(hk,{coordinateGetter:yHe})),c=x=>{const{active:g,over:M}=x;M&&g.id!==M.id&&a(w=>{const E=w.order.indexOf(g.id),A=w.order.indexOf(M.id);return{...w,order:gk(w.order,E,A)}})},d=x=>{a(g=>({...g,hidden:g.hidden.includes(x)?g.hidden.filter(M=>M!==x):[...g.hidden,x]}))},f=x=>{a(g=>{const M=g.sizes[x]||4,w=M===1?2:M===2?4:1;return{...g,sizes:{...g.sizes,[x]:w}}})},p=()=>{const x={order:t.map(g=>g.id),hidden:t.filter(g=>g.defaultVisible===!1).map(g=>g.id),sizes:i()};a(x)},m=r.order.map(x=>t.find(g=>g.id===x)).filter(Boolean),y=m.filter(x=>!r.hidden.includes(x.id)),b=m.filter(x=>r.hidden.includes(x.id));return _.jsxs("div",{className:"space-y-4",children:[_.jsxs("div",{className:"flex items-center justify-end gap-2",children:[b.length>0&&_.jsxs(mt,{variant:"secondary",size:"sm",onClick:()=>o(!s),children:[_.jsx(T4,{className:"w-4 h-4"}),b.length," Hidden"]}),_.jsxs(mt,{variant:"secondary",size:"sm",onClick:p,children:[_.jsx(WN,{className:"w-4 h-4"}),"Reset Layout"]})]}),s&&b.length>0&&_.jsxs("div",{className:"p-4 bg-bambu-dark rounded-xl border border-bambu-dark-tertiary",children:[_.jsx("p",{className:"text-sm text-bambu-gray mb-3",children:"Hidden widgets (click to show):"}),_.jsx("div",{className:"flex flex-wrap gap-2",children:b.map(x=>_.jsxs("button",{onClick:()=>d(x.id),className:"px-3 py-1.5 bg-bambu-dark-tertiary hover:bg-bambu-green/20 rounded-lg text-sm text-white transition-colors flex items-center gap-2",children:[_.jsx(T4,{className:"w-3 h-3"}),x.title]},x.id))})]}),_.jsx(Q5e,{sensors:l,collisionDetection:QBe,onDragEnd:c,children:_.jsx(cHe,{items:y.map(x=>x.id),strategy:vk,children:_.jsx("div",{className:"grid gap-6",style:{gridTemplateColumns:`repeat(${n}, minmax(0, 1fr))`},children:y.map(x=>_.jsx(_He,{id:x.id,title:x.title,isHidden:r.hidden.includes(x.id),size:r.sizes[x.id]||2,onToggleVisibility:()=>d(x.id),onToggleSize:()=>f(x.id),children:x.component},x.id))})})}),y.length===0&&_.jsxs("div",{className:"text-center py-12 text-bambu-gray",children:[_.jsx("p",{children:"All widgets are hidden."}),_.jsx(mt,{className:"mt-4",onClick:p,children:"Reset Layout"})]})]})}function wHe({stats:t,currency:e}){return _.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-4",children:[_.jsxs("div",{className:"flex items-start gap-3",children:[_.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-bambu-green",children:_.jsx(s_,{className:"w-5 h-5"})}),_.jsxs("div",{children:[_.jsx("p",{className:"text-xs text-bambu-gray",children:"Total Prints"}),_.jsx("p",{className:"text-xl font-bold text-white",children:t?.total_prints||0})]})]}),_.jsxs("div",{className:"flex items-start gap-3",children:[_.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-blue-400",children:_.jsx(Qo,{className:"w-5 h-5"})}),_.jsxs("div",{children:[_.jsx("p",{className:"text-xs text-bambu-gray",children:"Print Time"}),_.jsxs("p",{className:"text-xl font-bold text-white",children:[t?.total_print_time_hours.toFixed(1)||0,"h"]})]})]}),_.jsxs("div",{className:"flex items-start gap-3",children:[_.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-orange-400",children:_.jsx(s_,{className:"w-5 h-5"})}),_.jsxs("div",{children:[_.jsx("p",{className:"text-xs text-bambu-gray",children:"Filament Used"}),_.jsxs("p",{className:"text-xl font-bold text-white",children:[((t?.total_filament_grams||0)/1e3).toFixed(2),"kg"]})]})]}),_.jsxs("div",{className:"flex items-start gap-3",children:[_.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-green-400",children:_.jsx(A4,{className:"w-5 h-5"})}),_.jsxs("div",{children:[_.jsx("p",{className:"text-xs text-bambu-gray",children:"Filament Cost"}),_.jsxs("p",{className:"text-xl font-bold text-white",children:[e," ",t?.total_cost.toFixed(2)||"0.00"]})]})]}),_.jsxs("div",{className:"flex items-start gap-3",children:[_.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-yellow-400",children:_.jsx(NG,{className:"w-5 h-5"})}),_.jsxs("div",{children:[_.jsx("p",{className:"text-xs text-bambu-gray",children:"Energy Used"}),_.jsxs("p",{className:"text-xl font-bold text-white",children:[t?.total_energy_kwh.toFixed(2)||"0.00"," kWh"]})]})]}),_.jsxs("div",{className:"flex items-start gap-3",children:[_.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-yellow-500",children:_.jsx(A4,{className:"w-5 h-5"})}),_.jsxs("div",{children:[_.jsx("p",{className:"text-xs text-bambu-gray",children:"Energy Cost"}),_.jsxs("p",{className:"text-xl font-bold text-white",children:[e," ",t?.total_energy_cost.toFixed(2)||"0.00"]})]})]})]})}function MHe({stats:t}){const e=t?.total_prints?Math.round(t.successful_prints/t.total_prints*100):0;return _.jsxs("div",{className:"flex items-center gap-6",children:[_.jsxs("div",{className:"relative w-28 h-28",children:[_.jsxs("svg",{className:"w-full h-full -rotate-90",children:[_.jsx("circle",{cx:"56",cy:"56",r:"48",fill:"none",stroke:"#3d3d3d",strokeWidth:"10"}),_.jsx("circle",{cx:"56",cy:"56",r:"48",fill:"none",stroke:"#00ae42",strokeWidth:"10",strokeLinecap:"round",strokeDasharray:`${e*3.02} 302`})]}),_.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:_.jsxs("span",{className:"text-xl font-bold text-white",children:[e,"%"]})})]}),_.jsxs("div",{className:"space-y-2",children:[_.jsxs("div",{className:"flex items-center gap-2",children:[_.jsx(nm,{className:"w-4 h-4 text-bambu-green"}),_.jsx("span",{className:"text-sm text-bambu-gray",children:"Successful:"}),_.jsx("span",{className:"text-sm text-white font-medium",children:t?.successful_prints||0})]}),_.jsxs("div",{className:"flex items-center gap-2",children:[_.jsx(HN,{className:"w-4 h-4 text-red-400"}),_.jsx("span",{className:"text-sm text-bambu-gray",children:"Failed:"}),_.jsx("span",{className:"text-sm text-white font-medium",children:t?.failed_prints||0})]})]})]})}function EHe({stats:t,printerMap:e}){const n=t?.average_time_accuracy;if(n==null)return _.jsx("div",{className:"flex items-center justify-center h-full",children:_.jsx("p",{className:"text-bambu-gray text-center py-4",children:"No time accuracy data yet"})});const r=(Math.min(150,Math.max(50,n))-50)/100*100,s=(l=>l>=95&&l<=105?"#00ae42":l>105?"#3b82f6":"#f97316")(n),o=n-100;return _.jsxs("div",{className:"flex items-center gap-6",children:[_.jsxs("div",{className:"relative w-28 h-28",children:[_.jsxs("svg",{className:"w-full h-full -rotate-90",children:[_.jsx("circle",{cx:"56",cy:"56",r:"48",fill:"none",stroke:"#3d3d3d",strokeWidth:"10"}),_.jsx("circle",{cx:"56",cy:"56",r:"48",fill:"none",stroke:s,strokeWidth:"10",strokeLinecap:"round",strokeDasharray:`${r*3.02} 302`})]}),_.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center",children:[_.jsxs("span",{className:"text-xl font-bold text-white",children:[n.toFixed(0),"%"]}),_.jsxs("span",{className:`text-xs ${o>=0?"text-blue-400":"text-orange-400"}`,children:[o>=0?"+":"",o.toFixed(0),"%"]})]})]}),_.jsxs("div",{className:"space-y-2 flex-1",children:[_.jsxs("div",{className:"flex items-center gap-2 text-xs text-bambu-gray",children:[_.jsx(Jre,{className:"w-3 h-3"}),_.jsx("span",{children:"100% = perfect estimate"})]}),t?.time_accuracy_by_printer&&Object.keys(t.time_accuracy_by_printer).length>0&&_.jsx("div",{className:"space-y-1 mt-2",children:Object.entries(t.time_accuracy_by_printer).slice(0,3).map(([l,c])=>_.jsxs("div",{className:"flex items-center justify-between text-xs",children:[_.jsx("span",{className:"text-bambu-gray truncate max-w-[100px]",children:e.get(l)||`Printer ${l}`}),_.jsxs("span",{className:`font-medium ${c>=95&&c<=105?"text-bambu-green":c>105?"text-blue-400":"text-orange-400"}`,children:[c.toFixed(0),"%"]})]},l))})]})]})}function AHe({stats:t}){if(!t?.prints_by_filament_type||Object.keys(t.prints_by_filament_type).length===0)return _.jsx("p",{className:"text-bambu-gray text-center py-4",children:"No filament data available"});const e=Object.entries(t.prints_by_filament_type).sort(([,n],[,i])=>i-n);return _.jsx("div",{className:"space-y-3",children:e.map(([n,i])=>{const r=Math.round(i/(t.total_prints||1)*100);return _.jsxs("div",{children:[_.jsxs("div",{className:"flex justify-between text-sm mb-1",children:[_.jsx("span",{className:"text-white",children:n}),_.jsxs("span",{className:"text-bambu-gray",children:[i," prints"]})]}),_.jsx("div",{className:"h-2 bg-bambu-dark rounded-full",children:_.jsx("div",{className:"h-full bg-bambu-green rounded-full transition-all",style:{width:`${r}%`}})})]},n)})})}function THe({printDates:t}){return _.jsx(CEe,{printDates:t,months:4})}function CHe({stats:t,printerMap:e}){return!t?.prints_by_printer||Object.keys(t.prints_by_printer).length===0?_.jsx("p",{className:"text-bambu-gray text-center py-4",children:"No printer data available"}):_.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:Object.entries(t.prints_by_printer).map(([n,i])=>_.jsxs("div",{className:"flex items-center gap-3 p-3 bg-bambu-dark rounded-lg",children:[_.jsx("div",{className:"p-2 bg-bambu-dark-tertiary rounded-lg",children:_.jsx(ic,{className:"w-4 h-4 text-bambu-green"})}),_.jsxs("div",{children:[_.jsx("p",{className:"text-white font-medium text-sm",children:e.get(n)||`Printer ${n}`}),_.jsxs("p",{className:"text-xs text-bambu-gray",children:[i," prints"]})]})]},n))})}function RHe({archives:t,currency:e}){return!t||t.length===0?_.jsx("p",{className:"text-bambu-gray text-center py-4",children:"No print data available"}):_.jsx(LBe,{archives:t,currency:e})}function NHe(){const{data:t,isLoading:e}=vn({queryKey:["archiveStats"],queryFn:dt.getArchiveStats}),{data:n}=vn({queryKey:["printers"],queryFn:dt.getPrinters}),{data:i}=vn({queryKey:["archives"],queryFn:()=>dt.getArchives(void 0,1e3,0)}),{data:r}=vn({queryKey:["settings"],queryFn:dt.getSettings}),a=r?.currency||"$",s=new Map(n?.map(c=>[String(c.id),c.name])||[]),o=i?.map(c=>c.created_at)||[];if(e)return _.jsx("div",{className:"p-8",children:_.jsx("div",{className:"text-center py-12 text-bambu-gray",children:"Loading statistics..."})});const l=[{id:"quick-stats",title:"Quick Stats",component:_.jsx(wHe,{stats:t,currency:a}),defaultSize:2},{id:"success-rate",title:"Success Rate",component:_.jsx(MHe,{stats:t}),defaultSize:1},{id:"time-accuracy",title:"Time Accuracy",component:_.jsx(EHe,{stats:t,printerMap:s}),defaultSize:1},{id:"filament-types",title:"Filament Types",component:_.jsx(AHe,{stats:t}),defaultSize:1},{id:"print-activity",title:"Print Activity",component:_.jsx(THe,{printDates:o}),defaultSize:2},{id:"prints-by-printer",title:"Prints by Printer",component:_.jsx(CHe,{stats:t,printerMap:s}),defaultSize:2},{id:"filament-trends",title:"Filament Usage Trends",component:_.jsx(RHe,{archives:i||[],currency:a}),defaultSize:4}];return _.jsxs("div",{className:"p-8",children:[_.jsxs("div",{className:"mb-6",children:[_.jsx("h1",{className:"text-2xl font-bold text-white",children:"Dashboard"}),_.jsx("p",{className:"text-bambu-gray",children:"Drag widgets to rearrange. Click the eye icon to hide."})]}),_.jsx(SHe,{widgets:l,storageKey:"bambusy-dashboard-layout"})]})}function PHe({plug:t,onEdit:e}){const n=qi(),[i,r]=T.useState(!1),[a,s]=T.useState(!1),[o,l]=T.useState(!1),[c,d]=T.useState(!1),{data:f,isLoading:p,refetch:m}=vn({queryKey:["smart-plug-status",t.id],queryFn:()=>dt.getSmartPlugStatus(t.id),refetchInterval:3e4}),{data:y}=vn({queryKey:["printers"],queryFn:dt.getPrinters}),b=y?.find(P=>P.id===t.printer_id),x=hn({mutationFn:P=>dt.controlSmartPlug(t.id,P),onSuccess:()=>{m()}}),g=hn({mutationFn:P=>dt.updateSmartPlug(t.id,P),onSuccess:()=>{n.invalidateQueries({queryKey:["smart-plugs"]}),t.printer_id&&n.invalidateQueries({queryKey:["smartPlugByPrinter",t.printer_id]})}}),M=hn({mutationFn:()=>dt.deleteSmartPlug(t.id),onSuccess:()=>{n.invalidateQueries({queryKey:["smart-plugs"]})}}),w=f?.state==="ON",E=f?.reachable??!1,A=x.isPending;return _.jsxs(_.Fragment,{children:[_.jsx(_n,{className:"relative",children:_.jsxs(An,{className:"p-4",children:[_.jsxs("div",{className:"flex items-start justify-between mb-3",children:[_.jsxs("div",{className:"flex items-center gap-3",children:[_.jsx("div",{className:`p-2 rounded-lg ${E?w?"bg-bambu-green/20":"bg-bambu-dark":"bg-red-500/20"}`,children:_.jsx(B2,{className:`w-5 h-5 ${E?w?"text-bambu-green":"text-bambu-gray":"text-red-400"}`})}),_.jsxs("div",{children:[_.jsx("h3",{className:"font-medium text-white",children:t.name}),_.jsx("p",{className:"text-sm text-bambu-gray",children:t.ip_address})]})]}),_.jsx("div",{className:"flex items-center gap-2",children:p?_.jsx(Hn,{className:"w-4 h-4 text-bambu-gray animate-spin"}):E?_.jsxs("div",{className:"flex items-center gap-1 text-sm",children:[_.jsx(qN,{className:"w-4 h-4 text-bambu-green"}),_.jsx("span",{className:w?"text-bambu-green":"text-bambu-gray",children:f?.state||"Unknown"})]}):_.jsxs("div",{className:"flex items-center gap-1 text-sm text-red-400",children:[_.jsx(gS,{className:"w-4 h-4"}),_.jsx("span",{children:"Offline"})]})})]}),b&&_.jsxs("div",{className:"mb-3 px-2 py-1.5 bg-bambu-dark rounded-lg",children:[_.jsx("span",{className:"text-xs text-bambu-gray",children:"Linked to: "}),_.jsx("span",{className:"text-sm text-white",children:b.name})]}),_.jsxs("div",{className:"flex gap-2 mb-3",children:[_.jsxs(mt,{size:"sm",variant:w?"primary":"secondary",disabled:!E||A,onClick:()=>s(!0),className:"flex-1",children:[A?_.jsx(Hn,{className:"w-4 h-4 animate-spin"}):_.jsx(pS,{className:"w-4 h-4"}),"On"]}),_.jsxs(mt,{size:"sm",variant:w?"secondary":"primary",disabled:!E||A,onClick:()=>l(!0),className:"flex-1",children:[A?_.jsx(Hn,{className:"w-4 h-4 animate-spin"}):_.jsx(TG,{className:"w-4 h-4"}),"Off"]})]}),_.jsxs("button",{onClick:()=>d(!c),className:"w-full flex items-center justify-between py-2 text-sm text-bambu-gray hover:text-white transition-colors",children:[_.jsxs("span",{className:"flex items-center gap-2",children:[_.jsx(CG,{className:"w-4 h-4"}),"Automation Settings"]}),_.jsx("span",{children:c?"-":"+"})]}),c&&_.jsxs("div",{className:"pt-3 border-t border-bambu-dark-tertiary space-y-4",children:[_.jsxs("div",{className:"flex items-center justify-between",children:[_.jsxs("div",{children:[_.jsx("p",{className:"text-sm text-white",children:"Enabled"}),_.jsx("p",{className:"text-xs text-bambu-gray",children:"Enable automation for this plug"})]}),_.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[_.jsx("input",{type:"checkbox",checked:t.enabled,onChange:P=>g.mutate({enabled:P.target.checked}),className:"sr-only peer"}),_.jsx("div",{className:"w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green"})]})]}),_.jsxs("div",{className:"flex items-center justify-between",children:[_.jsxs("div",{children:[_.jsx("p",{className:"text-sm text-white",children:"Auto On"}),_.jsx("p",{className:"text-xs text-bambu-gray",children:"Turn on when print starts"})]}),_.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[_.jsx("input",{type:"checkbox",checked:t.auto_on,onChange:P=>g.mutate({auto_on:P.target.checked}),className:"sr-only peer"}),_.jsx("div",{className:"w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green"})]})]}),_.jsxs("div",{className:"flex items-center justify-between",children:[_.jsxs("div",{children:[_.jsx("p",{className:"text-sm text-white",children:"Auto Off"}),_.jsx("p",{className:"text-xs text-bambu-gray",children:"Turn off when print completes (one-shot)"})]}),_.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[_.jsx("input",{type:"checkbox",checked:t.auto_off,onChange:P=>g.mutate({auto_off:P.target.checked}),className:"sr-only peer"}),_.jsx("div",{className:"w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green"})]})]}),t.auto_off&&_.jsxs("div",{className:"space-y-3 pl-4 border-l-2 border-bambu-dark-tertiary",children:[_.jsxs("div",{children:[_.jsx("p",{className:"text-sm text-white mb-2",children:"Turn Off Delay Mode"}),_.jsxs("div",{className:"flex gap-2",children:[_.jsxs("button",{onClick:()=>g.mutate({off_delay_mode:"time"}),className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg text-sm transition-colors ${t.off_delay_mode==="time"?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white"}`,children:[_.jsx(Qo,{className:"w-4 h-4"}),"Time"]}),_.jsxs("button",{onClick:()=>g.mutate({off_delay_mode:"temperature"}),className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg text-sm transition-colors ${t.off_delay_mode==="temperature"?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white"}`,children:[_.jsx(Lb,{className:"w-4 h-4"}),"Temp"]})]})]}),t.off_delay_mode==="time"?_.jsxs("div",{children:[_.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Delay (minutes)"}),_.jsx("input",{type:"number",min:"1",max:"60",value:t.off_delay_minutes,onChange:P=>g.mutate({off_delay_minutes:parseInt(P.target.value)||5}),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none"})]}):_.jsxs("div",{children:[_.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Temperature threshold (C)"}),_.jsx("input",{type:"number",min:"30",max:"100",value:t.off_temp_threshold,onChange:P=>g.mutate({off_temp_threshold:parseInt(P.target.value)||70}),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none"}),_.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Turns off when nozzle cools below this temperature"})]})]}),_.jsxs("div",{className:"flex gap-2 pt-2",children:[_.jsxs(mt,{size:"sm",variant:"secondary",onClick:()=>e(t),className:"flex-1",children:[_.jsx(wre,{className:"w-4 h-4"}),"Edit"]}),_.jsx(mt,{size:"sm",variant:"secondary",onClick:()=>r(!0),className:"text-red-400 hover:text-red-300",children:_.jsx(ns,{className:"w-4 h-4"})})]})]})]})}),i&&_.jsx(is,{title:"Delete Smart Plug",message:`Are you sure you want to delete "${t.name}"? This cannot be undone.`,confirmText:"Delete",variant:"danger",onConfirm:()=>{M.mutate(),r(!1)},onCancel:()=>r(!1)}),a&&_.jsx(is,{title:"Turn On Smart Plug",message:`Are you sure you want to turn on "${t.name}"?`,confirmText:"Turn On",variant:"default",onConfirm:()=>{x.mutate("on"),s(!1)},onCancel:()=>s(!1)}),o&&_.jsx(is,{title:"Turn Off Smart Plug",message:`Are you sure you want to turn off "${t.name}"? This will cut power to the connected device.`,confirmText:"Turn Off",variant:"danger",onConfirm:()=>{x.mutate("off"),l(!1)},onCancel:()=>l(!1)})]})}function DHe({plug:t,onClose:e}){const n=qi(),i=!!t,[r,a]=T.useState(t?.name||""),[s,o]=T.useState(t?.ip_address||""),[l,c]=T.useState(t?.username||""),[d,f]=T.useState(t?.password||""),[p,m]=T.useState(t?.printer_id||null),[y,b]=T.useState(null),[x,g]=T.useState(null),{data:M}=vn({queryKey:["printers"],queryFn:dt.getPrinters}),{data:w}=vn({queryKey:["smart-plugs"],queryFn:dt.getSmartPlugs});T.useEffect(()=>{const O=B=>{B.key==="Escape"&&e()};return window.addEventListener("keydown",O),()=>window.removeEventListener("keydown",O)},[e]);const E=hn({mutationFn:()=>dt.testSmartPlugConnection(s,l||null,d||null),onSuccess:O=>{b(O),g(null),!r&&O.device_name&&a(O.device_name)},onError:O=>{b(null),g(O.message)}}),A=hn({mutationFn:O=>dt.createSmartPlug(O),onSuccess:()=>{n.invalidateQueries({queryKey:["smart-plugs"]}),e()},onError:O=>{g(O.message)}}),P=hn({mutationFn:O=>dt.updateSmartPlug(t.id,O),onSuccess:()=>{n.invalidateQueries({queryKey:["smart-plugs"]}),e()},onError:O=>{g(O.message)}}),C=M?.filter(O=>!w?.some(I=>I.printer_id===O.id&&I.id!==t?.id)),F=O=>{if(O.preventDefault(),g(null),!r.trim()){g("Name is required");return}if(!s.trim()){g("IP address is required");return}const B={name:r.trim(),ip_address:s.trim(),username:l.trim()||null,password:d.trim()||null,printer_id:p};i?P.mutate(B):A.mutate(B)},N=A.isPending||P.isPending;return _.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",onClick:e,children:_.jsxs("div",{className:"bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-md",onClick:O=>O.stopPropagation(),children:[_.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary",children:[_.jsx("h2",{className:"text-lg font-semibold text-white",children:i?"Edit Smart Plug":"Add Smart Plug"}),_.jsx("button",{onClick:e,className:"text-bambu-gray hover:text-white transition-colors",children:_.jsx(Vn,{className:"w-5 h-5"})})]}),_.jsxs("form",{onSubmit:F,className:"p-6 space-y-4",children:[x&&_.jsx("div",{className:"p-3 bg-red-500/20 border border-red-500/50 rounded-lg text-sm text-red-400",children:x}),_.jsxs("div",{children:[_.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"IP Address *"}),_.jsxs("div",{className:"flex gap-2",children:[_.jsx("input",{type:"text",value:s,onChange:O=>{o(O.target.value),b(null)},placeholder:"192.168.1.100",className:"flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"}),_.jsxs(mt,{type:"button",variant:"secondary",onClick:()=>E.mutate(),disabled:!s.trim()||E.isPending,children:[E.isPending?_.jsx(Hn,{className:"w-4 h-4 animate-spin"}):_.jsx(qN,{className:"w-4 h-4"}),"Test"]})]})]}),y&&_.jsx("div",{className:`p-3 rounded-lg flex items-center gap-2 ${y.success?"bg-bambu-green/20 border border-bambu-green/50 text-bambu-green":"bg-red-500/20 border border-red-500/50 text-red-400"}`,children:y.success?_.jsxs(_.Fragment,{children:[_.jsx(nm,{className:"w-5 h-5"}),_.jsxs("div",{children:[_.jsx("p",{className:"font-medium",children:"Connected!"}),_.jsxs("p",{className:"text-sm opacity-80",children:[y.device_name&&`Device: ${y.device_name} - `,"State: ",y.state]})]})]}):_.jsxs(_.Fragment,{children:[_.jsx(gS,{className:"w-5 h-5"}),_.jsx("span",{children:"Connection failed"})]})}),_.jsxs("div",{children:[_.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Name *"}),_.jsx("input",{type:"text",value:r,onChange:O=>a(O.target.value),placeholder:"Living Room Plug",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"})]}),_.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[_.jsxs("div",{children:[_.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Username"}),_.jsx("input",{type:"text",value:l,onChange:O=>c(O.target.value),placeholder:"admin",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),_.jsxs("div",{children:[_.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Password"}),_.jsx("input",{type:"password",value:d,onChange:O=>f(O.target.value),placeholder:"********",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]})]}),_.jsx("p",{className:"text-xs text-bambu-gray -mt-2",children:"Leave empty if your Tasmota device doesn't require authentication"}),_.jsxs("div",{children:[_.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Link to Printer"}),_.jsxs("select",{value:p??"",onChange:O=>m(O.target.value?Number(O.target.value):null),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[_.jsx("option",{value:"",children:"No printer (manual control only)"}),C?.map(O=>_.jsx("option",{value:O.id,children:O.name},O.id))]}),_.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Linking enables automatic on/off when prints start/complete"})]}),_.jsxs("div",{className:"flex gap-3 pt-2",children:[_.jsx(mt,{type:"button",variant:"secondary",onClick:e,className:"flex-1",children:"Cancel"}),_.jsxs(mt,{type:"submit",disabled:N,className:"flex-1",children:[N?_.jsx(Hn,{className:"w-4 h-4 animate-spin"}):_.jsx(mS,{className:"w-4 h-4"}),i?"Save":"Add"]})]})]})]})})}function OHe(){const t=qi(),[e,n]=T.useState(null),[i,r]=T.useState(!1),[a,s]=T.useState(!1),[o,l]=T.useState(!1),[c,d]=T.useState(null),[f,p]=T.useState(DG()),m=C=>{p(C),Pae(C)},y=()=>{localStorage.removeItem("sidebarOrder"),window.location.reload()},{data:b,isLoading:x}=vn({queryKey:["settings"],queryFn:dt.getSettings}),{data:g,isLoading:M}=vn({queryKey:["smart-plugs"],queryFn:dt.getSmartPlugs}),{data:w}=vn({queryKey:["ffmpeg-status"],queryFn:dt.checkFfmpeg});T.useEffect(()=>{b&&!e&&n(b)},[b,e]),T.useEffect(()=>{if(b&&e){const C=b.auto_archive!==e.auto_archive||b.save_thumbnails!==e.save_thumbnails||b.capture_finish_photo!==e.capture_finish_photo||b.default_filament_cost!==e.default_filament_cost||b.currency!==e.currency||b.energy_cost_per_kwh!==e.energy_cost_per_kwh;r(C)}},[b,e]);const E=hn({mutationFn:dt.updateSettings,onSuccess:C=>{t.setQueryData(["settings"],C),n(C),r(!1),s(!0),setTimeout(()=>s(!1),2e3)}}),A=()=>{e&&E.mutate(e)},P=(C,F)=>{e&&n({...e,[C]:F})};return x||!e?_.jsx("div",{className:"p-8 flex justify-center",children:_.jsx(Hn,{className:"w-8 h-8 text-bambu-green animate-spin"})}):_.jsxs("div",{className:"p-8",children:[_.jsxs("div",{className:"mb-8 flex items-center justify-between",children:[_.jsxs("div",{children:[_.jsx("h1",{className:"text-2xl font-bold text-white",children:"Settings"}),_.jsx("p",{className:"text-bambu-gray",children:"Configure Bambusy"})]}),_.jsxs(mt,{onClick:A,disabled:!i||E.isPending,children:[E.isPending?_.jsx(Hn,{className:"w-4 h-4 animate-spin"}):a?_.jsx(rie,{className:"w-4 h-4"}):_.jsx(mS,{className:"w-4 h-4"}),a?"Saved!":"Save"]})]}),E.isError&&_.jsxs("div",{className:"mb-6 p-3 bg-red-500/20 border border-red-500/50 rounded-lg text-sm text-red-400",children:["Failed to save settings: ",E.error.message]}),_.jsxs("div",{className:"flex gap-8",children:[_.jsxs("div",{className:"space-y-6 flex-1 max-w-xl",children:[_.jsxs(_n,{children:[_.jsx(Qh,{children:_.jsx("h2",{className:"text-lg font-semibold text-white",children:"Archive Settings"})}),_.jsxs(An,{className:"space-y-4",children:[_.jsxs("div",{className:"flex items-center justify-between",children:[_.jsxs("div",{children:[_.jsx("p",{className:"text-white",children:"Auto-archive prints"}),_.jsx("p",{className:"text-sm text-bambu-gray",children:"Automatically save 3MF files when prints complete"})]}),_.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[_.jsx("input",{type:"checkbox",checked:e.auto_archive,onChange:C=>P("auto_archive",C.target.checked),className:"sr-only peer"}),_.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),_.jsxs("div",{className:"flex items-center justify-between",children:[_.jsxs("div",{children:[_.jsx("p",{className:"text-white",children:"Save thumbnails"}),_.jsx("p",{className:"text-sm text-bambu-gray",children:"Extract and save preview images from 3MF files"})]}),_.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[_.jsx("input",{type:"checkbox",checked:e.save_thumbnails,onChange:C=>P("save_thumbnails",C.target.checked),className:"sr-only peer"}),_.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),_.jsxs("div",{className:"flex items-center justify-between",children:[_.jsxs("div",{children:[_.jsx("p",{className:"text-white",children:"Capture finish photo"}),_.jsx("p",{className:"text-sm text-bambu-gray",children:"Take a photo from printer camera when print completes"})]}),_.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[_.jsx("input",{type:"checkbox",checked:e.capture_finish_photo,onChange:C=>P("capture_finish_photo",C.target.checked),className:"sr-only peer"}),_.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),e.capture_finish_photo&&w&&!w.installed&&_.jsxs("div",{className:"flex items-start gap-2 p-3 bg-yellow-500/10 border border-yellow-500/30 rounded-lg",children:[_.jsx(Ap,{className:"w-5 h-5 text-yellow-500 flex-shrink-0 mt-0.5"}),_.jsxs("div",{className:"text-sm",children:[_.jsx("p",{className:"text-yellow-500 font-medium",children:"ffmpeg not installed"}),_.jsxs("p",{className:"text-bambu-gray mt-1",children:["Camera capture requires ffmpeg. Install it via"," ",_.jsx("code",{className:"bg-bambu-dark-tertiary px-1 rounded",children:"brew install ffmpeg"})," (macOS) or"," ",_.jsx("code",{className:"bg-bambu-dark-tertiary px-1 rounded",children:"apt install ffmpeg"})," (Linux)."]})]})]})]})]}),_.jsxs(_n,{children:[_.jsx(Qh,{children:_.jsx("h2",{className:"text-lg font-semibold text-white",children:"Cost Tracking"})}),_.jsxs(An,{className:"space-y-4",children:[_.jsxs("div",{children:[_.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Default filament cost (per kg)"}),_.jsx("input",{type:"number",step:"0.01",min:"0",value:e.default_filament_cost,onChange:C=>P("default_filament_cost",parseFloat(C.target.value)||0),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"})]}),_.jsxs("div",{children:[_.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Currency"}),_.jsxs("select",{value:e.currency,onChange:C=>P("currency",C.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[_.jsx("option",{value:"USD",children:"USD ($)"}),_.jsx("option",{value:"EUR",children:"EUR (€)"}),_.jsx("option",{value:"GBP",children:"GBP (£)"}),_.jsx("option",{value:"CHF",children:"CHF (Fr.)"}),_.jsx("option",{value:"JPY",children:"JPY (¥)"}),_.jsx("option",{value:"CNY",children:"CNY (¥)"}),_.jsx("option",{value:"CAD",children:"CAD ($)"}),_.jsx("option",{value:"AUD",children:"AUD ($)"})]})]}),_.jsxs("div",{children:[_.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Electricity cost per kWh"}),_.jsx("input",{type:"number",step:"0.01",min:"0",value:e.energy_cost_per_kwh,onChange:C=>P("energy_cost_per_kwh",parseFloat(C.target.value)||0),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"}),_.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Used for tracking energy costs per print via smart plugs"})]})]})]}),_.jsxs(_n,{children:[_.jsx(Qh,{children:_.jsx("h2",{className:"text-lg font-semibold text-white",children:"Interface"})}),_.jsxs(An,{className:"space-y-4",children:[_.jsxs("div",{children:[_.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Default view on startup"}),_.jsx("select",{value:f,onChange:C=>m(C.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:Ib.map(C=>_.jsx("option",{value:C.to,children:C.label},C.id))}),_.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Page to show when opening the app"})]}),_.jsxs("div",{className:"flex items-center justify-between",children:[_.jsxs("div",{children:[_.jsx("p",{className:"text-white",children:"Sidebar order"}),_.jsx("p",{className:"text-sm text-bambu-gray",children:"Drag items in the sidebar to reorder. Reset to default order here."})]}),_.jsxs(mt,{variant:"secondary",size:"sm",onClick:y,children:[_.jsx(WN,{className:"w-4 h-4"}),"Reset"]})]})]})]}),_.jsxs(_n,{children:[_.jsx(Qh,{children:_.jsx("h2",{className:"text-lg font-semibold text-white",children:"About"})}),_.jsx(An,{children:_.jsxs("div",{className:"space-y-2 text-sm",children:[_.jsx("p",{className:"text-white",children:"Bambusy v0.1.2"}),_.jsx("p",{className:"text-bambu-gray",children:"Archive and manage your Bambu Lab 3MF files"}),_.jsx("p",{className:"text-bambu-gray",children:"Connect to printers via LAN mode (developer mode required)"})]})})]})]}),_.jsx("div",{className:"w-96 flex-shrink-0",children:_.jsxs(_n,{children:[_.jsx(Qh,{children:_.jsxs("div",{className:"flex items-center justify-between",children:[_.jsxs("div",{className:"flex items-center gap-2",children:[_.jsx(B2,{className:"w-5 h-5 text-bambu-green"}),_.jsx("h2",{className:"text-lg font-semibold text-white",children:"Smart Plugs"})]}),_.jsxs(mt,{size:"sm",onClick:()=>{d(null),l(!0)},children:[_.jsx(ff,{className:"w-4 h-4"}),"Add"]})]})}),_.jsxs(An,{children:[_.jsx("p",{className:"text-sm text-bambu-gray mb-4",children:"Connect Tasmota-based smart plugs to automate power control for your printers."}),M?_.jsx("div",{className:"flex justify-center py-8",children:_.jsx(Hn,{className:"w-6 h-6 text-bambu-green animate-spin"})}):g&&g.length>0?_.jsx("div",{className:"space-y-4",children:g.map(C=>_.jsx(PHe,{plug:C,onEdit:F=>{d(F),l(!0)}},C.id))}):_.jsxs("div",{className:"text-center py-8 text-bambu-gray",children:[_.jsx(B2,{className:"w-12 h-12 mx-auto mb-3 opacity-30"}),_.jsx("p",{children:"No smart plugs configured"}),_.jsx("p",{className:"text-sm mt-1",children:"Add a Tasmota plug to get started"})]})]})]})})]}),o&&_.jsx(DHe,{plug:c,onClose:()=>{l(!1),d(null)}})]})}const fQ=t=>{const e=parseFloat(t);return(Math.trunc(e*1e3)/1e3).toFixed(3)},kHe=t=>t.startsWith("HH")?"HF":"S",LHe=t=>{const e=t.match(/^([A-Z]{2}\d{2})/);return e?e[1]:"HH00"},DN=t=>{const e=["High Flow_","High Flow ","Standard_","Standard ","HF_","HF ","S_","S "];for(const i of e)if(t.startsWith(i))return t.slice(i.length);const n=t.indexOf("_");return n>0?t.slice(n+1):t};function C2({profile:t,onEdit:e}){const n=kHe(t.nozzle_id),i=t.nozzle_diameter,r=t.name||"Unnamed",a=DN(t.name||"");return _.jsxs("button",{onClick:e,className:"w-full text-left px-3 py-2 bg-bambu-dark rounded hover:bg-bambu-dark-tertiary transition-colors",children:[_.jsxs("div",{className:"flex items-center gap-2",children:[_.jsx("span",{className:"text-bambu-green font-mono text-sm font-bold whitespace-nowrap",children:fQ(t.k_value)}),_.jsx("span",{className:"text-white text-sm truncate flex-1",title:r,children:r}),_.jsxs("span",{className:"text-xs text-bambu-gray whitespace-nowrap",children:[n," ",i]})]}),_.jsxs("div",{className:"text-xs text-bambu-gray mt-0.5 truncate",title:`Filament: ${a}`,children:["Filament: ",a||t.filament_id]})]})}function GV({profile:t,printerId:e,nozzleDiameter:n,existingProfiles:i=[],isDualNozzle:r=!1,onClose:a,onSave:s}){const{showToast:o}=Jo(),l=qi(),[c,d]=T.useState(t?.name||""),[f,p]=T.useState(t?.k_value?fQ(t.k_value):"0.020"),[m,y]=T.useState(t?.filament_id||""),[b,x]=T.useState(t?.nozzle_id?LHe(t.nozzle_id):"HH00"),[g,M]=T.useState(t?.nozzle_diameter||n),[w,E]=T.useState(t?.extruder_id||0),A=li.useMemo(()=>{const I=new Map;for(const G of i)if(G.filament_id&&!I.has(G.filament_id)){const L=DN(G.name||"");I.set(G.filament_id,{id:G.filament_id,name:L||G.filament_id})}return Array.from(I.values()).sort((G,L)=>G.name.localeCompare(L.name))},[i]),P=hn({mutationFn:I=>(console.log("[KProfile] Calling API..."),dt.setKProfile(e,I)),onSuccess:I=>{console.log("[KProfile] Save success:",I),o("K-profile saved"),l.invalidateQueries({queryKey:["kprofiles",e]}),s()},onError:I=>{console.error("[KProfile] Save error:",I),o(I.message,"error")}}),C=hn({mutationFn:I=>(console.log("[KProfile] Deleting profile..."),dt.deleteKProfile(e,I)),onSuccess:I=>{console.log("[KProfile] Delete success:",I),o("K-profile deleted"),l.invalidateQueries({queryKey:["kprofiles",e]}),a()},onError:I=>{console.error("[KProfile] Delete error:",I),o(I.message,"error")}}),[F,N]=T.useState(!1),O=()=>{t&&C.mutate({slot_id:t.slot_id,extruder_id:t.extruder_id,nozzle_id:t.nozzle_id,nozzle_diameter:t.nozzle_diameter,filament_id:t.filament_id})},B=I=>{I.preventDefault();const G=parseFloat(f).toFixed(6),L=`${b}-${g}`,$={name:c,k_value:G,filament_id:m,nozzle_id:L,nozzle_diameter:g,extruder_id:w,setting_id:t?.setting_id,slot_id:t?.slot_id??0};console.log("[KProfile] Saving profile:",$),P.mutate($)};return _.jsxs("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:[_.jsx(_n,{className:"w-full max-w-md",children:_.jsxs(An,{className:"p-0",children:[_.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[_.jsx("h2",{className:"text-xl font-semibold text-white",children:t?"Edit K-Profile":"Add K-Profile"}),_.jsx("button",{onClick:a,className:"text-bambu-gray hover:text-white transition-colors",children:_.jsx(Vn,{className:"w-5 h-5"})})]}),_.jsxs("form",{onSubmit:B,className:"p-4 space-y-4",children:[_.jsxs("div",{children:[_.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Profile Name"}),_.jsx("input",{type:"text",value:c,onChange:I=>d(I.target.value),disabled:!!t,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none ${t?"opacity-60 cursor-not-allowed":""}`,placeholder:"My PLA Profile",required:!0})]}),_.jsxs("div",{children:[_.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"K-Value"}),_.jsx("input",{type:"text",inputMode:"decimal",value:f,onChange:I=>{const G=I.target.value;(G===""||/^\d*\.?\d*$/.test(G))&&p(G)},onBlur:I=>{const G=parseFloat(I.target.value);isNaN(G)||p((Math.trunc(G*1e3)/1e3).toFixed(3))},className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none font-mono",placeholder:"0.020",required:!0}),_.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Typical range: 0.01 - 0.06 for PLA, 0.02 - 0.10 for PETG"})]}),_.jsxs("div",{children:[_.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Filament"}),_.jsxs("select",{value:m,onChange:I=>{const G=I.target.value;if(y(G),!t&&G&&!c){const L=A.find($=>$.id===G);L&&d(`${b==="HH00"?"HF":"S"} ${L.name}`)}},disabled:!!t,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none ${t?"opacity-60 cursor-not-allowed":""}`,required:!0,children:[_.jsx("option",{value:"",children:"Select filament..."}),t?.filament_id&&_.jsx("option",{value:t.filament_id,children:DN(t.name||t.filament_id)},t.filament_id),!t&&A.map(I=>_.jsx("option",{value:I.id,children:I.name},I.id))]}),!t&&A.length===0&&_.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"No filaments found. Create a K-profile in Bambu Studio first."})]}),_.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[_.jsxs("div",{children:[_.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Flow Type"}),_.jsxs("select",{value:b,onChange:I=>{const G=I.target.value;if(x(G),!t&&m&&!c){const L=A.find($=>$.id===m);L&&d(`${G==="HH00"?"HF":"S"} ${L.name}`)}},disabled:!!t,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none ${t?"opacity-60 cursor-not-allowed":""}`,children:[_.jsx("option",{value:"HH00",children:"High Flow"}),_.jsx("option",{value:"HS00",children:"Standard"})]})]}),_.jsxs("div",{children:[_.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Nozzle Size"}),_.jsxs("select",{value:g,onChange:I=>M(I.target.value),disabled:!!t,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none ${t?"opacity-60 cursor-not-allowed":""}`,children:[_.jsx("option",{value:"0.2",children:"0.2mm"}),_.jsx("option",{value:"0.4",children:"0.4mm"}),_.jsx("option",{value:"0.6",children:"0.6mm"}),_.jsx("option",{value:"0.8",children:"0.8mm"})]})]})]}),r&&_.jsxs("div",{children:[_.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Extruder"}),_.jsxs("select",{value:w,onChange:I=>E(parseInt(I.target.value)),disabled:!!t,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none ${t?"opacity-60 cursor-not-allowed":""}`,children:[_.jsx("option",{value:1,children:"Left"}),_.jsx("option",{value:0,children:"Right"})]})]}),_.jsxs("div",{className:"flex gap-2 pt-4",children:[t&&_.jsx(mt,{type:"button",variant:"secondary",onClick:()=>N(!0),disabled:C.isPending,className:"text-red-500 hover:bg-red-500/10",children:C.isPending?_.jsx(Hn,{className:"w-4 h-4 animate-spin"}):_.jsx(ns,{className:"w-4 h-4"})}),_.jsx(mt,{type:"button",variant:"secondary",onClick:a,className:"flex-1",children:"Cancel"}),_.jsxs(mt,{type:"submit",disabled:P.isPending,className:"flex-1",children:[P.isPending?_.jsx(Hn,{className:"w-4 h-4 animate-spin"}):_.jsx(GN,{className:"w-4 h-4"}),"Save"]})]})]})]})}),F&&_.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-[60]",children:_.jsx(_n,{className:"w-full max-w-sm",children:_.jsxs(An,{className:"p-6",children:[_.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[_.jsx("div",{className:"w-10 h-10 rounded-full bg-red-500/20 flex items-center justify-center",children:_.jsx(ns,{className:"w-5 h-5 text-red-500"})}),_.jsxs("div",{children:[_.jsx("h3",{className:"text-lg font-semibold text-white",children:"Delete Profile"}),_.jsx("p",{className:"text-sm text-bambu-gray",children:"This cannot be undone"})]})]}),_.jsxs("p",{className:"text-bambu-gray mb-6",children:["Are you sure you want to delete ",_.jsxs("span",{className:"text-white font-medium",children:['"',t?.name,'"']})," from the printer?"]}),_.jsxs("div",{className:"flex gap-3",children:[_.jsx(mt,{variant:"secondary",onClick:()=>N(!1),className:"flex-1",children:"Cancel"}),_.jsxs(mt,{onClick:()=>{N(!1),O()},disabled:C.isPending,className:"flex-1 bg-red-500 hover:bg-red-600 text-white",children:[C.isPending?_.jsx(Hn,{className:"w-4 h-4 animate-spin"}):_.jsx(ns,{className:"w-4 h-4"}),"Delete"]})]})]})})})]})}function IHe(){const[t,e]=T.useState(null),[n,i]=T.useState("0.4"),[r,a]=T.useState(null),[s,o]=T.useState(!1),[l,c]=T.useState(""),[d,f]=T.useState("all"),[p,m]=T.useState("all"),{data:y,isLoading:b}=vn({queryKey:["printers"],queryFn:dt.getPrinters}),{data:x,isLoading:g,error:M,refetch:w}=vn({queryKey:["kprofiles",t,n],queryFn:()=>dt.getKProfiles(t,n),enabled:!!t,retry:!1}),E=M?.message?.includes("not connected"),A=li.useMemo(()=>x?.profiles?x.profiles.filter(N=>{const O=l.toLowerCase(),B=!O||N.name.toLowerCase().includes(O)||N.filament_id.toLowerCase().includes(O),I=d==="all"||d==="left"&&N.extruder_id===1||d==="right"&&N.extruder_id===0,G=p==="all"||p==="hf"&&N.nozzle_id.startsWith("HH")||p==="s"&&N.nozzle_id.startsWith("HS");return B&&I&&G}):[],[x?.profiles,l,d,p]),P=y?.filter(N=>N.is_active)||[];!t&&P.length>0&&e(P[0].id);const F=y?.find(N=>N.id===t)?.nozzle_count===2;return b?_.jsx("div",{className:"flex justify-center py-12",children:_.jsx(Hn,{className:"w-8 h-8 text-bambu-green animate-spin"})}):!y||y.length===0?_.jsx(_n,{children:_.jsxs(An,{className:"py-12 text-center",children:[_.jsx(Xu,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),_.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:"No Printers Configured"}),_.jsx("p",{className:"text-bambu-gray",children:"Add a printer in Settings to manage K-profiles"})]})}):P.length===0?_.jsx(_n,{children:_.jsxs(An,{className:"py-12 text-center",children:[_.jsx(ic,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),_.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:"No Active Printers"}),_.jsx("p",{className:"text-bambu-gray",children:"Enable a printer connection to view its K-profiles"})]})}):_.jsxs(_.Fragment,{children:[_.jsxs("div",{className:"flex flex-wrap gap-4 mb-6",children:[_.jsxs("div",{className:"flex-1 min-w-48",children:[_.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Printer"}),_.jsx("select",{value:t||"",onChange:N=>e(parseInt(N.target.value)),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:P.map(N=>_.jsx("option",{value:N.id,children:N.name},N.id))})]}),_.jsxs("div",{className:"w-32",children:[_.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Nozzle"}),_.jsxs("select",{value:n,onChange:N=>i(N.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[_.jsx("option",{value:"0.2",children:"0.2mm"}),_.jsx("option",{value:"0.4",children:"0.4mm"}),_.jsx("option",{value:"0.6",children:"0.6mm"}),_.jsx("option",{value:"0.8",children:"0.8mm"})]})]}),_.jsxs("div",{className:"flex items-end gap-2",children:[_.jsxs(mt,{variant:"secondary",onClick:()=>w(),disabled:g,children:[_.jsx(Ep,{className:`w-4 h-4 ${g?"animate-spin":""}`}),"Refresh"]}),_.jsxs(mt,{onClick:()=>o(!0),children:[_.jsx(ff,{className:"w-4 h-4"}),"Add Profile"]})]})]}),_.jsxs("div",{className:"flex flex-wrap gap-4 mb-6",children:[_.jsxs("div",{className:"flex-1 min-w-48 relative",children:[_.jsx(o_,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),_.jsx("input",{type:"text",value:l,onChange:N=>c(N.target.value),placeholder:"Search by name or filament...",className:"w-full pl-10 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none"})]}),F&&_.jsx("div",{className:"w-36",children:_.jsxs("select",{value:d,onChange:N=>f(N.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[_.jsx("option",{value:"all",children:"All Extruders"}),_.jsx("option",{value:"left",children:"Left Only"}),_.jsx("option",{value:"right",children:"Right Only"})]})}),_.jsx("div",{className:"w-32",children:_.jsxs("select",{value:p,onChange:N=>m(N.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[_.jsx("option",{value:"all",children:"All Flow"}),_.jsx("option",{value:"hf",children:"HF Only"}),_.jsx("option",{value:"s",children:"S Only"})]})})]}),g?_.jsx("div",{className:"flex justify-center py-12",children:_.jsx(Hn,{className:"w-8 h-8 text-bambu-green animate-spin"})}):E?_.jsx(_n,{children:_.jsxs(An,{className:"py-12 text-center",children:[_.jsx(gS,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),_.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:"Printer Offline"}),_.jsx("p",{className:"text-bambu-gray mb-4",children:"The selected printer is not connected. Power it on to view K-profiles."}),_.jsxs(mt,{variant:"secondary",onClick:()=>w(),children:[_.jsx(Ep,{className:"w-4 h-4"}),"Retry"]})]})}):A.length>0?F?_.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[_.jsxs("div",{children:[_.jsx("h3",{className:"text-sm font-medium text-bambu-gray mb-2 px-1",children:"Left Extruder"}),_.jsx("div",{className:"space-y-1",children:A.filter(N=>N.extruder_id===1).map(N=>_.jsx(C2,{profile:N,onEdit:()=>a(N)},N.slot_id))})]}),_.jsxs("div",{children:[_.jsx("h3",{className:"text-sm font-medium text-bambu-gray mb-2 px-1",children:"Right Extruder"}),_.jsx("div",{className:"space-y-1",children:A.filter(N=>N.extruder_id===0).map(N=>_.jsx(C2,{profile:N,onEdit:()=>a(N)},N.slot_id))})]})]}):_.jsx("div",{className:"space-y-1",children:A.map(N=>_.jsx(C2,{profile:N,onEdit:()=>a(N)},N.slot_id))}):l||d!=="all"||p!=="all"?_.jsx(_n,{children:_.jsxs(An,{className:"py-12 text-center",children:[_.jsx(o_,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),_.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:"No Matching Profiles"}),_.jsx("p",{className:"text-bambu-gray",children:"No profiles match your search criteria"})]})}):_.jsx(_n,{children:_.jsxs(An,{className:"py-12 text-center",children:[_.jsx(GN,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),_.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:"No K-Profiles"}),_.jsxs("p",{className:"text-bambu-gray mb-4",children:["No pressure advance profiles found for ",n,"mm nozzle"]}),_.jsxs(mt,{onClick:()=>o(!0),children:[_.jsx(ff,{className:"w-4 h-4"}),"Create First Profile"]})]})}),r&&t&&_.jsx(GV,{profile:r,printerId:t,nozzleDiameter:n,existingProfiles:x?.profiles,isDualNozzle:F,onClose:()=>a(null),onSave:()=>a(null)}),s&&t&&_.jsx(GV,{printerId:t,nozzleDiameter:n,existingProfiles:x?.profiles,isDualNozzle:F,onClose:()=>o(!1),onSave:()=>o(!1)})]})}function UHe({onSuccess:t}){const{showToast:e}=Jo(),[n,i]=T.useState("email"),[r,a]=T.useState(""),[s,o]=T.useState(""),[l,c]=T.useState(""),[d,f]=T.useState(""),[p,m]=T.useState("global"),y=hn({mutationFn:()=>dt.cloudLogin(r,s,p),onSuccess:w=>{w.success?(e("Logged in successfully"),t()):w.needs_verification?(e("Verification code sent to your email"),i("code")):e(w.message,"error")},onError:w=>{e(w.message,"error")}}),b=hn({mutationFn:()=>dt.cloudVerify(r,l),onSuccess:w=>{w.success?(e("Logged in successfully"),t()):e(w.message,"error")},onError:w=>{e(w.message,"error")}}),x=hn({mutationFn:()=>dt.cloudSetToken(d),onSuccess:()=>{e("Token set successfully"),t()},onError:w=>{e(w.message,"error")}}),g=w=>{w.preventDefault(),n==="email"?y.mutate():n==="code"?b.mutate():n==="token"&&x.mutate()},M=y.isPending||b.isPending||x.isPending;return _.jsxs(_n,{className:"max-w-md mx-auto",children:[_.jsx(Qh,{children:_.jsxs("div",{className:"flex items-center gap-2",children:[_.jsx(VN,{className:"w-5 h-5 text-bambu-green"}),_.jsx("h2",{className:"text-xl font-semibold text-white",children:"Connect to Bambu Cloud"})]})}),_.jsx(An,{children:_.jsxs("form",{onSubmit:g,className:"space-y-4",children:[n==="email"&&_.jsxs(_.Fragment,{children:[_.jsxs("div",{children:[_.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Email"}),_.jsx("input",{type:"email",value:r,onChange:w=>a(w.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",placeholder:"your@email.com",required:!0})]}),_.jsxs("div",{children:[_.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Password"}),_.jsx("input",{type:"password",value:s,onChange:w=>o(w.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",placeholder:"••••••••",required:!0})]}),_.jsxs("div",{children:[_.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Region"}),_.jsxs("select",{value:p,onChange:w=>m(w.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[_.jsx("option",{value:"global",children:"Global"}),_.jsx("option",{value:"china",children:"China"})]})]})]}),n==="code"&&_.jsxs("div",{children:[_.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Verification Code"}),_.jsxs("p",{className:"text-xs text-bambu-gray mb-2",children:["Check your email (",r,") for a 6-digit code"]}),_.jsx("input",{type:"text",value:l,onChange:w=>c(w.target.value.replace(/\D/g,"").slice(0,6)),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-center text-2xl tracking-widest focus:border-bambu-green focus:outline-none",placeholder:"000000",maxLength:6,required:!0})]}),n==="token"&&_.jsxs("div",{children:[_.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Access Token"}),_.jsx("p",{className:"text-xs text-bambu-gray mb-2",children:"Paste your Bambu Lab access token (from Bambu Studio)"}),_.jsx("textarea",{value:d,onChange:w=>f(w.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-xs font-mono focus:border-bambu-green focus:outline-none resize-none",placeholder:"eyJ...",rows:3,required:!0})]}),_.jsxs("div",{className:"flex gap-2",children:[n==="code"&&_.jsx(mt,{type:"button",variant:"secondary",onClick:()=>i("email"),className:"flex-1",children:"Back"}),_.jsxs(mt,{type:"submit",disabled:M,className:"flex-1",children:[M?_.jsx(Hn,{className:"w-4 h-4 animate-spin"}):_.jsx(R4,{className:"w-4 h-4"}),n==="email"?"Login":n==="code"?"Verify":"Set Token"]})]}),n==="email"&&_.jsx("div",{className:"pt-4 border-t border-bambu-dark-tertiary",children:_.jsxs("button",{type:"button",onClick:()=>i("token"),className:"text-sm text-bambu-gray hover:text-white flex items-center gap-1",children:[_.jsx(Qie,{className:"w-3 h-3"}),"Use access token instead"]})}),n==="token"&&_.jsx("div",{className:"pt-4 border-t border-bambu-dark-tertiary",children:_.jsxs("button",{type:"button",onClick:()=>i("email"),className:"text-sm text-bambu-gray hover:text-white flex items-center gap-1",children:[_.jsx(R4,{className:"w-3 h-3"}),"Login with email instead"]})})]})})]})}function FHe({setting:t,onClick:e}){return _.jsxs("button",{onClick:e,className:"w-full text-left p-3 bg-bambu-dark rounded-lg hover:bg-bambu-dark-tertiary transition-colors",children:[_.jsx("p",{className:"text-white font-medium truncate",children:t.name}),t.updated_time&&_.jsxs("p",{className:"text-xs text-bambu-gray mt-1",children:["Updated: ",new Date(t.updated_time).toLocaleDateString()]})]})}function zHe({setting:t,onClose:e}){const{data:n,isLoading:i}=vn({queryKey:["cloudSettingDetail",t.setting_id],queryFn:()=>dt.getCloudSettingDetail(t.setting_id)});return _.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:_.jsx(_n,{className:"w-full max-w-2xl max-h-[90vh] flex flex-col",children:_.jsxs(An,{className:"p-0 flex flex-col h-full",children:[_.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[_.jsxs("div",{children:[_.jsx("h2",{className:"text-xl font-semibold text-white",children:t.name}),_.jsxs("p",{className:"text-sm text-bambu-gray capitalize",children:[t.type," preset"]})]}),_.jsx("button",{onClick:e,className:"text-bambu-gray hover:text-white transition-colors",children:_.jsx(Vn,{className:"w-5 h-5"})})]}),_.jsx("div",{className:"flex-1 overflow-y-auto p-4",children:i?_.jsx("div",{className:"flex justify-center py-8",children:_.jsx(Hn,{className:"w-8 h-8 text-bambu-green animate-spin"})}):n?_.jsx("pre",{className:"text-xs text-bambu-gray font-mono whitespace-pre-wrap overflow-x-auto bg-bambu-dark p-4 rounded-lg",children:JSON.stringify(n,null,2)}):_.jsx("p",{className:"text-bambu-gray text-center py-8",children:"Failed to load preset details"})}),_.jsx("div",{className:"p-4 border-t border-bambu-dark-tertiary",children:_.jsx(mt,{variant:"secondary",onClick:e,className:"w-full",children:"Close"})})]})})})}function jHe({settings:t}){const[e,n]=T.useState(new Set),[i,r]=T.useState(null),a=l=>[...l].sort((c,d)=>c.name.localeCompare(d.name)),s=l=>{n(c=>{const d=new Set(c);return d.has(l)?d.delete(l):d.add(l),d})},o=[{key:"filament",label:"Filament Presets",icon:Sie,items:a(t.filament)},{key:"printer",label:"Printer Presets",icon:ic,items:a(t.printer)},{key:"process",label:"Process Presets",icon:CG,items:a(t.process)}];return _.jsxs(_.Fragment,{children:[_.jsx("div",{className:"space-y-4",children:o.map(({key:l,label:c,icon:d,items:f})=>_.jsxs(_n,{children:[_.jsxs("button",{onClick:()=>s(l),className:"w-full flex items-center justify-between p-4",children:[_.jsxs("div",{className:"flex items-center gap-3",children:[_.jsx(d,{className:"w-5 h-5 text-bambu-green"}),_.jsx("span",{className:"text-lg font-semibold text-white",children:c}),_.jsxs("span",{className:"text-sm text-bambu-gray",children:["(",f.length,")"]})]}),e.has(l)?_.jsx(sie,{className:"w-5 h-5 text-bambu-gray"}):_.jsx(Pf,{className:"w-5 h-5 text-bambu-gray"})]}),e.has(l)&&f.length>0&&_.jsx(An,{className:"pt-0",children:_.jsx("div",{className:"grid gap-2 sm:grid-cols-2 lg:grid-cols-3",children:f.map(p=>_.jsx(FHe,{setting:p,onClick:()=>r(p)},p.setting_id))})}),e.has(l)&&f.length===0&&_.jsx(An,{className:"pt-0",children:_.jsx("p",{className:"text-bambu-gray text-sm",children:"No presets found"})})]},l))}),i&&_.jsx(zHe,{setting:i,onClose:()=>r(null)})]})}function BHe(){const t=qi(),{showToast:e}=Jo(),[n,i]=T.useState("kprofiles"),{data:r,isLoading:a}=vn({queryKey:["cloudStatus"],queryFn:dt.getCloudStatus}),{data:s,isLoading:o,refetch:l}=vn({queryKey:["cloudSettings"],queryFn:()=>dt.getCloudSettings(),enabled:!!r?.is_authenticated,retry:!1,staleTime:1e3*60*5}),c=hn({mutationFn:dt.cloudLogout,onSuccess:()=>{t.invalidateQueries({queryKey:["cloudStatus"]}),t.removeQueries({queryKey:["cloudSettings"]}),e("Logged out")}}),d=()=>{t.invalidateQueries({queryKey:["cloudStatus"]})};return a?_.jsx("div",{className:"p-8 flex justify-center",children:_.jsx(Hn,{className:"w-8 h-8 text-bambu-green animate-spin"})}):_.jsxs("div",{className:"p-8",children:[_.jsxs("div",{className:"mb-6",children:[_.jsx("h1",{className:"text-2xl font-bold text-white",children:"Profiles"}),_.jsx("p",{className:"text-bambu-gray",children:"Manage your slicer presets and pressure advance calibrations"})]}),_.jsxs("div",{className:"flex border-b border-bambu-dark-tertiary mb-6",children:[_.jsxs("button",{onClick:()=>i("cloud"),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${n==="cloud"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-white border-transparent"}`,children:[_.jsx(VN,{className:"w-4 h-4"}),"Cloud Profiles"]}),_.jsxs("button",{onClick:()=>i("kprofiles"),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${n==="kprofiles"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-white border-transparent"}`,children:[_.jsx(GN,{className:"w-4 h-4"}),"K-Profiles"]})]}),n==="cloud"&&_.jsxs(_.Fragment,{children:[_.jsxs("div",{className:"mb-6 flex items-center justify-between",children:[_.jsx("p",{className:"text-bambu-gray",children:r?.is_authenticated?`Connected as ${r.email}`:"Connect to Bambu Cloud to access your slicer presets"}),r?.is_authenticated&&_.jsxs("div",{className:"flex gap-2",children:[_.jsxs(mt,{variant:"secondary",onClick:()=>l(),disabled:o,children:[_.jsx(Ep,{className:`w-4 h-4 ${o?"animate-spin":""}`}),"Refresh"]}),_.jsxs(mt,{variant:"secondary",onClick:()=>c.mutate(),disabled:c.isPending,children:[_.jsx(dre,{className:"w-4 h-4"}),"Logout"]})]})]}),r?.is_authenticated?o?_.jsx("div",{className:"flex justify-center py-12",children:_.jsx(Hn,{className:"w-8 h-8 text-bambu-green animate-spin"})}):s?_.jsx(jHe,{settings:s}):_.jsx(_n,{children:_.jsxs(An,{className:"py-8 text-center",children:[_.jsx("p",{className:"text-bambu-gray",children:"Failed to load profiles"}),_.jsx(mt,{className:"mt-4",onClick:()=>l(),children:"Retry"})]})}):_.jsx(UHe,{onSuccess:d})]}),n==="kprofiles"&&_.jsx(IHe,{})]})}function HHe(){const t=T.useRef(null),e=T.useRef(null),n=qi(),[i,r]=T.useState(!1),a=T.useCallback(()=>{if(t.current?.readyState===WebSocket.OPEN)return;const c=`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/api/v1/ws`,d=new WebSocket(c);let f=null;d.onopen=()=>{console.log("[WebSocket] Connected"),r(!0),f=window.setInterval(()=>{d.readyState===WebSocket.OPEN&&d.send(JSON.stringify({type:"ping"}))},3e4)},d.onmessage=p=>{try{const m=JSON.parse(p.data);s(m)}catch{}},d.onclose=p=>{console.log("[WebSocket] Closed",p.code,p.reason),f&&(clearInterval(f),f=null),r(!1),t.current=null,e.current=window.setTimeout(()=>{a()},3e3)},d.onerror=p=>{console.error("[WebSocket] Error",p),d.close()},t.current=d},[]),s=T.useCallback(l=>{switch(l.type){case"printer_status":l.printer_id!==void 0&&n.setQueryData(["printerStatus",l.printer_id],c=>({...c,...l.data}));break;case"print_complete":n.invalidateQueries({queryKey:["archives"]}),n.invalidateQueries({queryKey:["archiveStats"]});break;case"archive_created":n.invalidateQueries({queryKey:["archives"]}),n.invalidateQueries({queryKey:["archiveStats"]});break}},[n]);T.useEffect(()=>(a(),()=>{e.current&&clearTimeout(e.current),t.current&&t.current.close()}),[a]);const o=T.useCallback(l=>{t.current?.readyState===WebSocket.OPEN&&t.current.send(JSON.stringify(l))},[]);return{isConnected:i,sendMessage:o}}const VHe=new Sne({defaultOptions:{queries:{staleTime:1e3*60,retry:1}}});function GHe({children:t}){return HHe(),_.jsx(_.Fragment,{children:t})}function $He(){return _.jsx(Eae,{children:_.jsx(Lae,{children:_.jsx(wne,{client:VHe,children:_.jsx(GHe,{children:_.jsx(Gte,{children:_.jsx(_te,{children:_.jsxs(au,{path:"/",element:_.jsx(Dae,{}),children:[_.jsx(au,{index:!0,element:_.jsx(Zae,{})}),_.jsx(au,{path:"archives",element:_.jsx(MEe,{})}),_.jsx(au,{path:"queue",element:_.jsx(TEe,{})}),_.jsx(au,{path:"stats",element:_.jsx(NHe,{})}),_.jsx(au,{path:"profiles",element:_.jsx(BHe,{})}),_.jsx(au,{path:"settings",element:_.jsx(OHe,{})})]})})})})})})})}Tee.createRoot(document.getElementById("root")).render(_.jsx(T.StrictMode,{children:_.jsx($He,{})})); + `},XBe={onDragStart(t){let{active:e}=t;return"Picked up draggable item "+e.id+"."},onDragOver(t){let{active:e,over:n}=t;return n?"Draggable item "+e.id+" was moved over droppable area "+n.id+".":"Draggable item "+e.id+" is no longer over a droppable area."},onDragEnd(t){let{active:e,over:n}=t;return n?"Draggable item "+e.id+" was dropped over droppable area "+n.id:"Draggable item "+e.id+" was dropped."},onDragCancel(t){let{active:e}=t;return"Dragging was cancelled. Draggable item "+e.id+" was dropped."}};function KBe(t){let{announcements:e=XBe,container:n,hiddenTextDescribedById:i,screenReaderInstructions:r=qBe}=t;const{announce:a,announcement:s}=GBe(),o=Gv("DndLiveRegion"),[l,c]=T.useState(!1);if(T.useEffect(()=>{c(!0)},[]),$Be(T.useMemo(()=>({onDragStart(f){let{active:p}=f;a(e.onDragStart({active:p}))},onDragMove(f){let{active:p,over:m}=f;e.onDragMove&&a(e.onDragMove({active:p,over:m}))},onDragOver(f){let{active:p,over:m}=f;a(e.onDragOver({active:p,over:m}))},onDragEnd(f){let{active:p,over:m}=f;a(e.onDragEnd({active:p,over:m}))},onDragCancel(f){let{active:p,over:m}=f;a(e.onDragCancel({active:p,over:m}))}}),[a,e])),!l)return null;const d=li.createElement(li.Fragment,null,li.createElement(HBe,{id:i,value:r.draggable}),li.createElement(VBe,{id:o,announcement:s}));return n?Bl.createPortal(d,n):d}var er;(function(t){t.DragStart="dragStart",t.DragMove="dragMove",t.DragEnd="dragEnd",t.DragCancel="dragCancel",t.DragOver="dragOver",t.RegisterDroppable="registerDroppable",t.SetDroppableDisabled="setDroppableDisabled",t.UnregisterDroppable="unregisterDroppable"})(er||(er={}));function sS(){}function PV(t,e){return T.useMemo(()=>({sensor:t,options:e??{}}),[t,e])}function YBe(){for(var t=arguments.length,e=new Array(t),n=0;n[...e].filter(i=>i!=null),[...e])}const xo=Object.freeze({x:0,y:0});function qZ(t,e){return Math.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2))}function XZ(t,e){let{data:{value:n}}=t,{data:{value:i}}=e;return n-i}function ZBe(t,e){let{data:{value:n}}=t,{data:{value:i}}=e;return i-n}function DV(t){let{left:e,top:n,height:i,width:r}=t;return[{x:e,y:n},{x:e+r,y:n},{x:e,y:n+i},{x:e+r,y:n+i}]}function KZ(t,e){if(!t||t.length===0)return null;const[n]=t;return n[e]}function OV(t,e,n){return e===void 0&&(e=t.left),n===void 0&&(n=t.top),{x:e+t.width*.5,y:n+t.height*.5}}const QBe=t=>{let{collisionRect:e,droppableRects:n,droppableContainers:i}=t;const r=OV(e,e.left,e.top),a=[];for(const s of i){const{id:o}=s,l=n.get(o);if(l){const c=qZ(OV(l),r);a.push({id:o,data:{droppableContainer:s,value:c}})}}return a.sort(XZ)},JBe=t=>{let{collisionRect:e,droppableRects:n,droppableContainers:i}=t;const r=DV(e),a=[];for(const s of i){const{id:o}=s,l=n.get(o);if(l){const c=DV(l),d=r.reduce((p,m,y)=>p+qZ(c[y],m),0),f=Number((d/4).toFixed(4));a.push({id:o,data:{droppableContainer:s,value:f}})}}return a.sort(XZ)};function e5e(t,e){const n=Math.max(e.top,t.top),i=Math.max(e.left,t.left),r=Math.min(e.left+e.width,t.left+t.width),a=Math.min(e.top+e.height,t.top+t.height),s=r-i,o=a-n;if(i{let{collisionRect:e,droppableRects:n,droppableContainers:i}=t;const r=[];for(const a of i){const{id:s}=a,o=n.get(s);if(o){const l=e5e(o,e);l>0&&r.push({id:s,data:{droppableContainer:a,value:l}})}}return r.sort(ZBe)};function n5e(t,e,n){return{...t,scaleX:e&&n?e.width/n.width:1,scaleY:e&&n?e.height/n.height:1}}function YZ(t,e){return t&&e?{x:t.left-e.left,y:t.top-e.top}:xo}function i5e(t){return function(n){for(var i=arguments.length,r=new Array(i>1?i-1:0),a=1;a({...s,top:s.top+t*o.y,bottom:s.bottom+t*o.y,left:s.left+t*o.x,right:s.right+t*o.x}),{...n})}}const r5e=i5e(1);function a5e(t){if(t.startsWith("matrix3d(")){const e=t.slice(9,-1).split(/, /);return{x:+e[12],y:+e[13],scaleX:+e[0],scaleY:+e[5]}}else if(t.startsWith("matrix(")){const e=t.slice(7,-1).split(/, /);return{x:+e[4],y:+e[5],scaleX:+e[0],scaleY:+e[3]}}return null}function s5e(t,e,n){const i=a5e(e);if(!i)return t;const{scaleX:r,scaleY:a,x:s,y:o}=i,l=t.left-s-(1-r)*parseFloat(n),c=t.top-o-(1-a)*parseFloat(n.slice(n.indexOf(" ")+1)),d=r?t.width/r:t.width,f=a?t.height/a:t.height;return{width:d,height:f,top:c,right:l+d,bottom:c+f,left:l}}const o5e={ignoreTransform:!1};function wm(t,e){e===void 0&&(e=o5e);let n=t.getBoundingClientRect();if(e.ignoreTransform){const{transform:c,transformOrigin:d}=za(t).getComputedStyle(t);c&&(n=s5e(n,c,d))}const{top:i,left:r,width:a,height:s,bottom:o,right:l}=n;return{top:i,left:r,width:a,height:s,bottom:o,right:l}}function kV(t){return wm(t,{ignoreTransform:!0})}function l5e(t){const e=t.innerWidth,n=t.innerHeight;return{top:0,left:0,right:e,bottom:n,width:e,height:n}}function c5e(t,e){return e===void 0&&(e=za(t).getComputedStyle(t)),e.position==="fixed"}function u5e(t,e){e===void 0&&(e=za(t).getComputedStyle(t));const n=/(auto|scroll|overlay)/;return["overflow","overflowX","overflowY"].some(r=>{const a=e[r];return typeof a=="string"?n.test(a):!1})}function Ow(t,e){const n=[];function i(r){if(e!=null&&n.length>=e||!r)return n;if(ck(r)&&r.scrollingElement!=null&&!n.includes(r.scrollingElement))return n.push(r.scrollingElement),n;if(!Hv(r)||GZ(r)||n.includes(r))return n;const a=za(t).getComputedStyle(r);return r!==t&&u5e(r,a)&&n.push(r),c5e(r,a)?n:i(r.parentNode)}return t?i(t):n}function ZZ(t){const[e]=Ow(t,1);return e??null}function E2(t){return!Dw||!t?null:_m(t)?t:lk(t)?ck(t)||t===Sm(t).scrollingElement?window:Hv(t)?t:null:null}function QZ(t){return _m(t)?t.scrollX:t.scrollLeft}function JZ(t){return _m(t)?t.scrollY:t.scrollTop}function RN(t){return{x:QZ(t),y:JZ(t)}}var _r;(function(t){t[t.Forward=1]="Forward",t[t.Backward=-1]="Backward"})(_r||(_r={}));function eQ(t){return!Dw||!t?!1:t===document.scrollingElement}function tQ(t){const e={x:0,y:0},n=eQ(t)?{height:window.innerHeight,width:window.innerWidth}:{height:t.clientHeight,width:t.clientWidth},i={x:t.scrollWidth-n.width,y:t.scrollHeight-n.height},r=t.scrollTop<=e.y,a=t.scrollLeft<=e.x,s=t.scrollTop>=i.y,o=t.scrollLeft>=i.x;return{isTop:r,isLeft:a,isBottom:s,isRight:o,maxScroll:i,minScroll:e}}const d5e={x:.2,y:.2};function f5e(t,e,n,i,r){let{top:a,left:s,right:o,bottom:l}=n;i===void 0&&(i=10),r===void 0&&(r=d5e);const{isTop:c,isBottom:d,isLeft:f,isRight:p}=tQ(t),m={x:0,y:0},y={x:0,y:0},b={height:e.height*r.y,width:e.width*r.x};return!c&&a<=e.top+b.height?(m.y=_r.Backward,y.y=i*Math.abs((e.top+b.height-a)/b.height)):!d&&l>=e.bottom-b.height&&(m.y=_r.Forward,y.y=i*Math.abs((e.bottom-b.height-l)/b.height)),!p&&o>=e.right-b.width?(m.x=_r.Forward,y.x=i*Math.abs((e.right-b.width-o)/b.width)):!f&&s<=e.left+b.width&&(m.x=_r.Backward,y.x=i*Math.abs((e.left+b.width-s)/b.width)),{direction:m,speed:y}}function h5e(t){if(t===document.scrollingElement){const{innerWidth:a,innerHeight:s}=window;return{top:0,left:0,right:a,bottom:s,width:a,height:s}}const{top:e,left:n,right:i,bottom:r}=t.getBoundingClientRect();return{top:e,left:n,right:i,bottom:r,width:t.clientWidth,height:t.clientHeight}}function nQ(t){return t.reduce((e,n)=>Mp(e,RN(n)),xo)}function p5e(t){return t.reduce((e,n)=>e+QZ(n),0)}function m5e(t){return t.reduce((e,n)=>e+JZ(n),0)}function g5e(t,e){if(e===void 0&&(e=wm),!t)return;const{top:n,left:i,bottom:r,right:a}=e(t);ZZ(t)&&(r<=0||a<=0||n>=window.innerHeight||i>=window.innerWidth)&&t.scrollIntoView({block:"center",inline:"center"})}const v5e=[["x",["left","right"],p5e],["y",["top","bottom"],m5e]];class fk{constructor(e,n){this.rect=void 0,this.width=void 0,this.height=void 0,this.top=void 0,this.bottom=void 0,this.right=void 0,this.left=void 0;const i=Ow(n),r=nQ(i);this.rect={...e},this.width=e.width,this.height=e.height;for(const[a,s,o]of v5e)for(const l of s)Object.defineProperty(this,l,{get:()=>{const c=o(i),d=r[a]-c;return this.rect[l]+d},enumerable:!0});Object.defineProperty(this,"rect",{enumerable:!1})}}class f0{constructor(e){this.target=void 0,this.listeners=[],this.removeAll=()=>{this.listeners.forEach(n=>{var i;return(i=this.target)==null?void 0:i.removeEventListener(...n)})},this.target=e}add(e,n,i){var r;(r=this.target)==null||r.addEventListener(e,n,i),this.listeners.push([e,n,i])}}function x5e(t){const{EventTarget:e}=za(t);return t instanceof e?t:Sm(t)}function A2(t,e){const n=Math.abs(t.x),i=Math.abs(t.y);return typeof e=="number"?Math.sqrt(n**2+i**2)>e:"x"in e&&"y"in e?n>e.x&&i>e.y:"x"in e?n>e.x:"y"in e?i>e.y:!1}var Ns;(function(t){t.Click="click",t.DragStart="dragstart",t.Keydown="keydown",t.ContextMenu="contextmenu",t.Resize="resize",t.SelectionChange="selectionchange",t.VisibilityChange="visibilitychange"})(Ns||(Ns={}));function LV(t){t.preventDefault()}function y5e(t){t.stopPropagation()}var mn;(function(t){t.Space="Space",t.Down="ArrowDown",t.Right="ArrowRight",t.Left="ArrowLeft",t.Up="ArrowUp",t.Esc="Escape",t.Enter="Enter",t.Tab="Tab"})(mn||(mn={}));const iQ={start:[mn.Space,mn.Enter],cancel:[mn.Esc],end:[mn.Space,mn.Enter,mn.Tab]},b5e=(t,e)=>{let{currentCoordinates:n}=e;switch(t.code){case mn.Right:return{...n,x:n.x+25};case mn.Left:return{...n,x:n.x-25};case mn.Down:return{...n,y:n.y+25};case mn.Up:return{...n,y:n.y-25}}};class hk{constructor(e){this.props=void 0,this.autoScrollEnabled=!1,this.referenceCoordinates=void 0,this.listeners=void 0,this.windowListeners=void 0,this.props=e;const{event:{target:n}}=e;this.props=e,this.listeners=new f0(Sm(n)),this.windowListeners=new f0(za(n)),this.handleKeyDown=this.handleKeyDown.bind(this),this.handleCancel=this.handleCancel.bind(this),this.attach()}attach(){this.handleStart(),this.windowListeners.add(Ns.Resize,this.handleCancel),this.windowListeners.add(Ns.VisibilityChange,this.handleCancel),setTimeout(()=>this.listeners.add(Ns.Keydown,this.handleKeyDown))}handleStart(){const{activeNode:e,onStart:n}=this.props,i=e.node.current;i&&g5e(i),n(xo)}handleKeyDown(e){if(dk(e)){const{active:n,context:i,options:r}=this.props,{keyboardCodes:a=iQ,coordinateGetter:s=b5e,scrollBehavior:o="smooth"}=r,{code:l}=e;if(a.end.includes(l)){this.handleEnd(e);return}if(a.cancel.includes(l)){this.handleCancel(e);return}const{collisionRect:c}=i.current,d=c?{x:c.left,y:c.top}:xo;this.referenceCoordinates||(this.referenceCoordinates=d);const f=s(e,{active:n,context:i.current,currentCoordinates:d});if(f){const p=nv(f,d),m={x:0,y:0},{scrollableAncestors:y}=i.current;for(const b of y){const x=e.code,{isTop:g,isRight:M,isLeft:w,isBottom:E,maxScroll:A,minScroll:P}=tQ(b),C=h5e(b),F={x:Math.min(x===mn.Right?C.right-C.width/2:C.right,Math.max(x===mn.Right?C.left:C.left+C.width/2,f.x)),y:Math.min(x===mn.Down?C.bottom-C.height/2:C.bottom,Math.max(x===mn.Down?C.top:C.top+C.height/2,f.y))},N=x===mn.Right&&!M||x===mn.Left&&!w,O=x===mn.Down&&!E||x===mn.Up&&!g;if(N&&F.x!==f.x){const B=b.scrollLeft+p.x,I=x===mn.Right&&B<=A.x||x===mn.Left&&B>=P.x;if(I&&!p.y){b.scrollTo({left:B,behavior:o});return}I?m.x=b.scrollLeft-B:m.x=x===mn.Right?b.scrollLeft-A.x:b.scrollLeft-P.x,m.x&&b.scrollBy({left:-m.x,behavior:o});break}else if(O&&F.y!==f.y){const B=b.scrollTop+p.y,I=x===mn.Down&&B<=A.y||x===mn.Up&&B>=P.y;if(I&&!p.x){b.scrollTo({top:B,behavior:o});return}I?m.y=b.scrollTop-B:m.y=x===mn.Down?b.scrollTop-A.y:b.scrollTop-P.y,m.y&&b.scrollBy({top:-m.y,behavior:o});break}}this.handleMove(e,Mp(nv(f,this.referenceCoordinates),m))}}}handleMove(e,n){const{onMove:i}=this.props;e.preventDefault(),i(n)}handleEnd(e){const{onEnd:n}=this.props;e.preventDefault(),this.detach(),n()}handleCancel(e){const{onCancel:n}=this.props;e.preventDefault(),this.detach(),n()}detach(){this.listeners.removeAll(),this.windowListeners.removeAll()}}hk.activators=[{eventName:"onKeyDown",handler:(t,e,n)=>{let{keyboardCodes:i=iQ,onActivation:r}=e,{active:a}=n;const{code:s}=t.nativeEvent;if(i.start.includes(s)){const o=a.activatorNode.current;return o&&t.target!==o?!1:(t.preventDefault(),r?.({event:t.nativeEvent}),!0)}return!1}}];function IV(t){return!!(t&&"distance"in t)}function UV(t){return!!(t&&"delay"in t)}class pk{constructor(e,n,i){var r;i===void 0&&(i=x5e(e.event.target)),this.props=void 0,this.events=void 0,this.autoScrollEnabled=!0,this.document=void 0,this.activated=!1,this.initialCoordinates=void 0,this.timeoutId=null,this.listeners=void 0,this.documentListeners=void 0,this.windowListeners=void 0,this.props=e,this.events=n;const{event:a}=e,{target:s}=a;this.props=e,this.events=n,this.document=Sm(s),this.documentListeners=new f0(this.document),this.listeners=new f0(i),this.windowListeners=new f0(za(s)),this.initialCoordinates=(r=CN(a))!=null?r:xo,this.handleStart=this.handleStart.bind(this),this.handleMove=this.handleMove.bind(this),this.handleEnd=this.handleEnd.bind(this),this.handleCancel=this.handleCancel.bind(this),this.handleKeydown=this.handleKeydown.bind(this),this.removeTextSelection=this.removeTextSelection.bind(this),this.attach()}attach(){const{events:e,props:{options:{activationConstraint:n,bypassActivationConstraint:i}}}=this;if(this.listeners.add(e.move.name,this.handleMove,{passive:!1}),this.listeners.add(e.end.name,this.handleEnd),e.cancel&&this.listeners.add(e.cancel.name,this.handleCancel),this.windowListeners.add(Ns.Resize,this.handleCancel),this.windowListeners.add(Ns.DragStart,LV),this.windowListeners.add(Ns.VisibilityChange,this.handleCancel),this.windowListeners.add(Ns.ContextMenu,LV),this.documentListeners.add(Ns.Keydown,this.handleKeydown),n){if(i!=null&&i({event:this.props.event,activeNode:this.props.activeNode,options:this.props.options}))return this.handleStart();if(UV(n)){this.timeoutId=setTimeout(this.handleStart,n.delay),this.handlePending(n);return}if(IV(n)){this.handlePending(n);return}}this.handleStart()}detach(){this.listeners.removeAll(),this.windowListeners.removeAll(),setTimeout(this.documentListeners.removeAll,50),this.timeoutId!==null&&(clearTimeout(this.timeoutId),this.timeoutId=null)}handlePending(e,n){const{active:i,onPending:r}=this.props;r(i,e,this.initialCoordinates,n)}handleStart(){const{initialCoordinates:e}=this,{onStart:n}=this.props;e&&(this.activated=!0,this.documentListeners.add(Ns.Click,y5e,{capture:!0}),this.removeTextSelection(),this.documentListeners.add(Ns.SelectionChange,this.removeTextSelection),n(e))}handleMove(e){var n;const{activated:i,initialCoordinates:r,props:a}=this,{onMove:s,options:{activationConstraint:o}}=a;if(!r)return;const l=(n=CN(e))!=null?n:xo,c=nv(r,l);if(!i&&o){if(IV(o)){if(o.tolerance!=null&&A2(c,o.tolerance))return this.handleCancel();if(A2(c,o.distance))return this.handleStart()}if(UV(o)&&A2(c,o.tolerance))return this.handleCancel();this.handlePending(o,c);return}e.cancelable&&e.preventDefault(),s(l)}handleEnd(){const{onAbort:e,onEnd:n}=this.props;this.detach(),this.activated||e(this.props.active),n()}handleCancel(){const{onAbort:e,onCancel:n}=this.props;this.detach(),this.activated||e(this.props.active),n()}handleKeydown(e){e.code===mn.Esc&&this.handleCancel()}removeTextSelection(){var e;(e=this.document.getSelection())==null||e.removeAllRanges()}}const _5e={cancel:{name:"pointercancel"},move:{name:"pointermove"},end:{name:"pointerup"}};class mk extends pk{constructor(e){const{event:n}=e,i=Sm(n.target);super(e,_5e,i)}}mk.activators=[{eventName:"onPointerDown",handler:(t,e)=>{let{nativeEvent:n}=t,{onActivation:i}=e;return!n.isPrimary||n.button!==0?!1:(i?.({event:n}),!0)}}];const S5e={move:{name:"mousemove"},end:{name:"mouseup"}};var NN;(function(t){t[t.RightClick=2]="RightClick"})(NN||(NN={}));class w5e extends pk{constructor(e){super(e,S5e,Sm(e.event.target))}}w5e.activators=[{eventName:"onMouseDown",handler:(t,e)=>{let{nativeEvent:n}=t,{onActivation:i}=e;return n.button===NN.RightClick?!1:(i?.({event:n}),!0)}}];const T2={cancel:{name:"touchcancel"},move:{name:"touchmove"},end:{name:"touchend"}};class M5e extends pk{constructor(e){super(e,T2)}static setup(){return window.addEventListener(T2.move.name,e,{capture:!1,passive:!1}),function(){window.removeEventListener(T2.move.name,e)};function e(){}}}M5e.activators=[{eventName:"onTouchStart",handler:(t,e)=>{let{nativeEvent:n}=t,{onActivation:i}=e;const{touches:r}=n;return r.length>1?!1:(i?.({event:n}),!0)}}];var h0;(function(t){t[t.Pointer=0]="Pointer",t[t.DraggableRect=1]="DraggableRect"})(h0||(h0={}));var oS;(function(t){t[t.TreeOrder=0]="TreeOrder",t[t.ReversedTreeOrder=1]="ReversedTreeOrder"})(oS||(oS={}));function E5e(t){let{acceleration:e,activator:n=h0.Pointer,canScroll:i,draggingRect:r,enabled:a,interval:s=5,order:o=oS.TreeOrder,pointerCoordinates:l,scrollableAncestors:c,scrollableAncestorRects:d,delta:f,threshold:p}=t;const m=T5e({delta:f,disabled:!a}),[y,b]=UBe(),x=T.useRef({x:0,y:0}),g=T.useRef({x:0,y:0}),M=T.useMemo(()=>{switch(n){case h0.Pointer:return l?{top:l.y,bottom:l.y,left:l.x,right:l.x}:null;case h0.DraggableRect:return r}},[n,r,l]),w=T.useRef(null),E=T.useCallback(()=>{const P=w.current;if(!P)return;const C=x.current.x*g.current.x,F=x.current.y*g.current.y;P.scrollBy(C,F)},[]),A=T.useMemo(()=>o===oS.TreeOrder?[...c].reverse():c,[o,c]);T.useEffect(()=>{if(!a||!c.length||!M){b();return}for(const P of A){if(i?.(P)===!1)continue;const C=c.indexOf(P),F=d[C];if(!F)continue;const{direction:N,speed:O}=f5e(P,F,M,e,p);for(const B of["x","y"])m[B][N[B]]||(O[B]=0,N[B]=0);if(O.x>0||O.y>0){b(),w.current=P,y(E,s),x.current=O,g.current=N;return}}x.current={x:0,y:0},g.current={x:0,y:0},b()},[e,E,i,b,a,s,JSON.stringify(M),JSON.stringify(m),y,c,A,d,JSON.stringify(p)])}const A5e={x:{[_r.Backward]:!1,[_r.Forward]:!1},y:{[_r.Backward]:!1,[_r.Forward]:!1}};function T5e(t){let{delta:e,disabled:n}=t;const i=TN(e);return Vv(r=>{if(n||!i||!r)return A5e;const a={x:Math.sign(e.x-i.x),y:Math.sign(e.y-i.y)};return{x:{[_r.Backward]:r.x[_r.Backward]||a.x===-1,[_r.Forward]:r.x[_r.Forward]||a.x===1},y:{[_r.Backward]:r.y[_r.Backward]||a.y===-1,[_r.Forward]:r.y[_r.Forward]||a.y===1}}},[n,e,i])}function C5e(t,e){const n=e!=null?t.get(e):void 0,i=n?n.node.current:null;return Vv(r=>{var a;return e==null?null:(a=i??r)!=null?a:null},[i,e])}function R5e(t,e){return T.useMemo(()=>t.reduce((n,i)=>{const{sensor:r}=i,a=r.activators.map(s=>({eventName:s.eventName,handler:e(s.handler,i)}));return[...n,...a]},[]),[t,e])}var rv;(function(t){t[t.Always=0]="Always",t[t.BeforeDragging=1]="BeforeDragging",t[t.WhileDragging=2]="WhileDragging"})(rv||(rv={}));var PN;(function(t){t.Optimized="optimized"})(PN||(PN={}));const FV=new Map;function N5e(t,e){let{dragging:n,dependencies:i,config:r}=e;const[a,s]=T.useState(null),{frequency:o,measure:l,strategy:c}=r,d=T.useRef(t),f=x(),p=tv(f),m=T.useCallback(function(g){g===void 0&&(g=[]),!p.current&&s(M=>M===null?g:M.concat(g.filter(w=>!M.includes(w))))},[p]),y=T.useRef(null),b=Vv(g=>{if(f&&!n)return FV;if(!g||g===FV||d.current!==t||a!=null){const M=new Map;for(let w of t){if(!w)continue;if(a&&a.length>0&&!a.includes(w.id)&&w.rect.current){M.set(w.id,w.rect.current);continue}const E=w.node.current,A=E?new fk(l(E),E):null;w.rect.current=A,A&&M.set(w.id,A)}return M}return g},[t,a,n,f,l]);return T.useEffect(()=>{d.current=t},[t]),T.useEffect(()=>{f||m()},[n,f]),T.useEffect(()=>{a&&a.length>0&&s(null)},[JSON.stringify(a)]),T.useEffect(()=>{f||typeof o!="number"||y.current!==null||(y.current=setTimeout(()=>{m(),y.current=null},o))},[o,f,m,...i]),{droppableRects:b,measureDroppableContainers:m,measuringScheduled:a!=null};function x(){switch(c){case rv.Always:return!1;case rv.BeforeDragging:return n;default:return!n}}}function rQ(t,e){return Vv(n=>t?n||(typeof e=="function"?e(t):t):null,[e,t])}function P5e(t,e){return rQ(t,e)}function D5e(t){let{callback:e,disabled:n}=t;const i=uk(e),r=T.useMemo(()=>{if(n||typeof window>"u"||typeof window.MutationObserver>"u")return;const{MutationObserver:a}=window;return new a(i)},[i,n]);return T.useEffect(()=>()=>r?.disconnect(),[r]),r}function kw(t){let{callback:e,disabled:n}=t;const i=uk(e),r=T.useMemo(()=>{if(n||typeof window>"u"||typeof window.ResizeObserver>"u")return;const{ResizeObserver:a}=window;return new a(i)},[n]);return T.useEffect(()=>()=>r?.disconnect(),[r]),r}function O5e(t){return new fk(wm(t),t)}function zV(t,e,n){e===void 0&&(e=O5e);const[i,r]=T.useState(null);function a(){r(l=>{if(!t)return null;if(t.isConnected===!1){var c;return(c=l??n)!=null?c:null}const d=e(t);return JSON.stringify(l)===JSON.stringify(d)?l:d})}const s=D5e({callback(l){if(t)for(const c of l){const{type:d,target:f}=c;if(d==="childList"&&f instanceof HTMLElement&&f.contains(t)){a();break}}}}),o=kw({callback:a});return Ko(()=>{a(),t?(o?.observe(t),s?.observe(document.body,{childList:!0,subtree:!0})):(o?.disconnect(),s?.disconnect())},[t]),i}function k5e(t){const e=rQ(t);return YZ(t,e)}const jV=[];function L5e(t){const e=T.useRef(t),n=Vv(i=>t?i&&i!==jV&&t&&e.current&&t.parentNode===e.current.parentNode?i:Ow(t):jV,[t]);return T.useEffect(()=>{e.current=t},[t]),n}function I5e(t){const[e,n]=T.useState(null),i=T.useRef(t),r=T.useCallback(a=>{const s=E2(a.target);s&&n(o=>o?(o.set(s,RN(s)),new Map(o)):null)},[]);return T.useEffect(()=>{const a=i.current;if(t!==a){s(a);const o=t.map(l=>{const c=E2(l);return c?(c.addEventListener("scroll",r,{passive:!0}),[c,RN(c)]):null}).filter(l=>l!=null);n(o.length?new Map(o):null),i.current=t}return()=>{s(t),s(a)};function s(o){o.forEach(l=>{const c=E2(l);c?.removeEventListener("scroll",r)})}},[r,t]),T.useMemo(()=>t.length?e?Array.from(e.values()).reduce((a,s)=>Mp(a,s),xo):nQ(t):xo,[t,e])}function BV(t,e){e===void 0&&(e=[]);const n=T.useRef(null);return T.useEffect(()=>{n.current=null},e),T.useEffect(()=>{const i=t!==xo;i&&!n.current&&(n.current=t),!i&&n.current&&(n.current=null)},[t]),n.current?nv(t,n.current):xo}function U5e(t){T.useEffect(()=>{if(!Dw)return;const e=t.map(n=>{let{sensor:i}=n;return i.setup==null?void 0:i.setup()});return()=>{for(const n of e)n?.()}},t.map(e=>{let{sensor:n}=e;return n}))}function F5e(t,e){return T.useMemo(()=>t.reduce((n,i)=>{let{eventName:r,handler:a}=i;return n[r]=s=>{a(s,e)},n},{}),[t,e])}function aQ(t){return T.useMemo(()=>t?l5e(t):null,[t])}const HV=[];function z5e(t,e){e===void 0&&(e=wm);const[n]=t,i=aQ(n?za(n):null),[r,a]=T.useState(HV);function s(){a(()=>t.length?t.map(l=>eQ(l)?i:new fk(e(l),l)):HV)}const o=kw({callback:s});return Ko(()=>{o?.disconnect(),s(),t.forEach(l=>o?.observe(l))},[t]),r}function j5e(t){if(!t)return null;if(t.children.length>1)return t;const e=t.children[0];return Hv(e)?e:t}function B5e(t){let{measure:e}=t;const[n,i]=T.useState(null),r=T.useCallback(c=>{for(const{target:d}of c)if(Hv(d)){i(f=>{const p=e(d);return f?{...f,width:p.width,height:p.height}:p});break}},[e]),a=kw({callback:r}),s=T.useCallback(c=>{const d=j5e(c);a?.disconnect(),d&&a?.observe(d),i(d?e(d):null)},[e,a]),[o,l]=aS(s);return T.useMemo(()=>({nodeRef:o,rect:n,setRef:l}),[n,o,l])}const H5e=[{sensor:mk,options:{}},{sensor:hk,options:{}}],V5e={current:{}},n_={draggable:{measure:kV},droppable:{measure:kV,strategy:rv.WhileDragging,frequency:PN.Optimized},dragOverlay:{measure:wm}};class p0 extends Map{get(e){var n;return e!=null&&(n=super.get(e))!=null?n:void 0}toArray(){return Array.from(this.values())}getEnabled(){return this.toArray().filter(e=>{let{disabled:n}=e;return!n})}getNodeFor(e){var n,i;return(n=(i=this.get(e))==null?void 0:i.node.current)!=null?n:void 0}}const G5e={activatorEvent:null,active:null,activeNode:null,activeNodeRect:null,collisions:null,containerNodeRect:null,draggableNodes:new Map,droppableRects:new Map,droppableContainers:new p0,over:null,dragOverlay:{nodeRef:{current:null},rect:null,setRef:sS},scrollableAncestors:[],scrollableAncestorRects:[],measuringConfiguration:n_,measureDroppableContainers:sS,windowRect:null,measuringScheduled:!1},$5e={activatorEvent:null,activators:[],active:null,activeNodeRect:null,ariaDescribedById:{draggable:""},dispatch:sS,draggableNodes:new Map,over:null,measureDroppableContainers:sS},Lw=T.createContext($5e),sQ=T.createContext(G5e);function W5e(){return{draggable:{active:null,initialCoordinates:{x:0,y:0},nodes:new Map,translate:{x:0,y:0}},droppable:{containers:new p0}}}function q5e(t,e){switch(e.type){case er.DragStart:return{...t,draggable:{...t.draggable,initialCoordinates:e.initialCoordinates,active:e.active}};case er.DragMove:return t.draggable.active==null?t:{...t,draggable:{...t.draggable,translate:{x:e.coordinates.x-t.draggable.initialCoordinates.x,y:e.coordinates.y-t.draggable.initialCoordinates.y}}};case er.DragEnd:case er.DragCancel:return{...t,draggable:{...t.draggable,active:null,initialCoordinates:{x:0,y:0},translate:{x:0,y:0}}};case er.RegisterDroppable:{const{element:n}=e,{id:i}=n,r=new p0(t.droppable.containers);return r.set(i,n),{...t,droppable:{...t.droppable,containers:r}}}case er.SetDroppableDisabled:{const{id:n,key:i,disabled:r}=e,a=t.droppable.containers.get(n);if(!a||i!==a.key)return t;const s=new p0(t.droppable.containers);return s.set(n,{...a,disabled:r}),{...t,droppable:{...t.droppable,containers:s}}}case er.UnregisterDroppable:{const{id:n,key:i}=e,r=t.droppable.containers.get(n);if(!r||i!==r.key)return t;const a=new p0(t.droppable.containers);return a.delete(n),{...t,droppable:{...t.droppable,containers:a}}}default:return t}}function X5e(t){let{disabled:e}=t;const{active:n,activatorEvent:i,draggableNodes:r}=T.useContext(Lw),a=TN(i),s=TN(n?.id);return T.useEffect(()=>{if(!e&&!i&&a&&s!=null){if(!dk(a)||document.activeElement===a.target)return;const o=r.get(s);if(!o)return;const{activatorNode:l,node:c}=o;if(!l.current&&!c.current)return;requestAnimationFrame(()=>{for(const d of[l.current,c.current]){if(!d)continue;const f=jBe(d);if(f){f.focus();break}}})}},[i,e,r,s,a]),null}function K5e(t,e){let{transform:n,...i}=e;return t!=null&&t.length?t.reduce((r,a)=>a({transform:r,...i}),n):n}function Y5e(t){return T.useMemo(()=>({draggable:{...n_.draggable,...t?.draggable},droppable:{...n_.droppable,...t?.droppable},dragOverlay:{...n_.dragOverlay,...t?.dragOverlay}}),[t?.draggable,t?.droppable,t?.dragOverlay])}function Z5e(t){let{activeNode:e,measure:n,initialRect:i,config:r=!0}=t;const a=T.useRef(!1),{x:s,y:o}=typeof r=="boolean"?{x:r,y:r}:r;Ko(()=>{if(!s&&!o||!e){a.current=!1;return}if(a.current||!i)return;const c=e?.node.current;if(!c||c.isConnected===!1)return;const d=n(c),f=YZ(d,i);if(s||(f.x=0),o||(f.y=0),a.current=!0,Math.abs(f.x)>0||Math.abs(f.y)>0){const p=ZZ(c);p&&p.scrollBy({top:f.y,left:f.x})}},[e,s,o,i,n])}const oQ=T.createContext({...xo,scaleX:1,scaleY:1});var pu;(function(t){t[t.Uninitialized=0]="Uninitialized",t[t.Initializing=1]="Initializing",t[t.Initialized=2]="Initialized"})(pu||(pu={}));const Q5e=T.memo(function(e){var n,i,r,a;let{id:s,accessibility:o,autoScroll:l=!0,children:c,sensors:d=H5e,collisionDetection:f=t5e,measuring:p,modifiers:m,...y}=e;const b=T.useReducer(q5e,void 0,W5e),[x,g]=b,[M,w]=WBe(),[E,A]=T.useState(pu.Uninitialized),P=E===pu.Initialized,{draggable:{active:C,nodes:F,translate:N},droppable:{containers:O}}=x,B=C!=null?F.get(C):null,I=T.useRef({initial:null,translated:null}),G=T.useMemo(()=>{var ke;return C!=null?{id:C,data:(ke=B?.data)!=null?ke:V5e,rect:I}:null},[C,B]),L=T.useRef(null),[$,q]=T.useState(null),[W,Y]=T.useState(null),J=tv(y,Object.values(y)),se=Gv("DndDescribedBy",s),j=T.useMemo(()=>O.getEnabled(),[O]),X=Y5e(p),{droppableRects:re,measureDroppableContainers:ce,measuringScheduled:xe}=N5e(j,{dragging:P,dependencies:[N.x,N.y],config:X.droppable}),me=C5e(F,C),ye=T.useMemo(()=>W?CN(W):null,[W]),De=de(),he=P5e(me,X.draggable.measure);Z5e({activeNode:C!=null?F.get(C):null,config:De.layoutShiftCompensation,initialRect:he,measure:X.draggable.measure});const we=zV(me,X.draggable.measure,he),je=zV(me?me.parentElement:null),le=T.useRef({activatorEvent:null,active:null,activeNode:me,collisionRect:null,collisions:null,droppableRects:re,draggableNodes:F,draggingNode:null,draggingNodeRect:null,droppableContainers:O,over:null,scrollableAncestors:[],scrollAdjustedTranslate:null}),ut=O.getNodeFor((n=le.current.over)==null?void 0:n.id),z=B5e({measure:X.dragOverlay.measure}),V=(i=z.nodeRef.current)!=null?i:me,ie=P?(r=z.rect)!=null?r:we:null,Q=!!(z.nodeRef.current&&z.rect),ee=k5e(Q?null:we),ae=aQ(V?za(V):null),Pe=L5e(P?ut??me:null),Re=z5e(Pe),te=K5e(m,{transform:{x:N.x-ee.x,y:N.y-ee.y,scaleX:1,scaleY:1},activatorEvent:W,active:G,activeNodeRect:we,containerNodeRect:je,draggingNodeRect:ie,over:le.current.over,overlayNodeRect:z.rect,scrollableAncestors:Pe,scrollableAncestorRects:Re,windowRect:ae}),U=ye?Mp(ye,N):null,k=I5e(Pe),K=BV(k),pe=BV(k,[we]),ve=Mp(te,K),fe=ie?r5e(ie,te):null,Ye=G&&fe?f({active:G,collisionRect:fe,droppableRects:re,droppableContainers:j,pointerCoordinates:U}):null,Le=KZ(Ye,"id"),[qe,it]=T.useState(null),Ie=Q?te:Mp(te,pe),Ne=n5e(Ie,(a=qe?.rect)!=null?a:null,we),ft=T.useRef(null),et=T.useCallback((ke,Me)=>{let{sensor:ge,options:Be}=Me;if(L.current==null)return;const at=F.get(L.current);if(!at)return;const yt=ke.nativeEvent,Ct=new ge({active:L.current,activeNode:at,event:yt,options:Be,context:le,onAbort(Dt){if(!F.get(Dt))return;const{onDragAbort:$n}=J.current,dr={id:Dt};$n?.(dr),M({type:"onDragAbort",event:dr})},onPending(Dt,Tn,$n,dr){if(!F.get(Dt))return;const{onDragPending:fr}=J.current,Tr={id:Dt,constraint:Tn,initialCoordinates:$n,offset:dr};fr?.(Tr),M({type:"onDragPending",event:Tr})},onStart(Dt){const Tn=L.current;if(Tn==null)return;const $n=F.get(Tn);if(!$n)return;const{onDragStart:dr}=J.current,Ki={activatorEvent:yt,active:{id:Tn,data:$n.data,rect:I}};Bl.unstable_batchedUpdates(()=>{dr?.(Ki),A(pu.Initializing),g({type:er.DragStart,initialCoordinates:Dt,active:Tn}),M({type:"onDragStart",event:Ki}),q(ft.current),Y(yt)})},onMove(Dt){g({type:er.DragMove,coordinates:Dt})},onEnd:tn(er.DragEnd),onCancel:tn(er.DragCancel)});ft.current=Ct;function tn(Dt){return async function(){const{active:$n,collisions:dr,over:Ki,scrollAdjustedTranslate:fr}=le.current;let Tr=null;if($n&&fr){const{cancelDrop:Vr}=J.current;Tr={activatorEvent:yt,active:$n,collisions:dr,delta:fr,over:Ki},Dt===er.DragEnd&&typeof Vr=="function"&&await Promise.resolve(Vr(Tr))&&(Dt=er.DragCancel)}L.current=null,Bl.unstable_batchedUpdates(()=>{g({type:Dt}),A(pu.Uninitialized),it(null),q(null),Y(null),ft.current=null;const Vr=Dt===er.DragEnd?"onDragEnd":"onDragCancel";if(Tr){const Di=J.current[Vr];Di?.(Tr),M({type:Vr,event:Tr})}})}}},[F]),Je=T.useCallback((ke,Me)=>(ge,Be)=>{const at=ge.nativeEvent,yt=F.get(Be);if(L.current!==null||!yt||at.dndKit||at.defaultPrevented)return;const Ct={active:yt};ke(ge,Me.options,Ct)===!0&&(at.dndKit={capturedBy:Me.sensor},L.current=Be,et(ge,Me))},[F,et]),st=R5e(d,Je);U5e(d),Ko(()=>{we&&E===pu.Initializing&&A(pu.Initialized)},[we,E]),T.useEffect(()=>{const{onDragMove:ke}=J.current,{active:Me,activatorEvent:ge,collisions:Be,over:at}=le.current;if(!Me||!ge)return;const yt={active:Me,activatorEvent:ge,collisions:Be,delta:{x:ve.x,y:ve.y},over:at};Bl.unstable_batchedUpdates(()=>{ke?.(yt),M({type:"onDragMove",event:yt})})},[ve.x,ve.y]),T.useEffect(()=>{const{active:ke,activatorEvent:Me,collisions:ge,droppableContainers:Be,scrollAdjustedTranslate:at}=le.current;if(!ke||L.current==null||!Me||!at)return;const{onDragOver:yt}=J.current,Ct=Be.get(Le),tn=Ct&&Ct.rect.current?{id:Ct.id,rect:Ct.rect.current,data:Ct.data,disabled:Ct.disabled}:null,Dt={active:ke,activatorEvent:Me,collisions:ge,delta:{x:at.x,y:at.y},over:tn};Bl.unstable_batchedUpdates(()=>{it(tn),yt?.(Dt),M({type:"onDragOver",event:Dt})})},[Le]),Ko(()=>{le.current={activatorEvent:W,active:G,activeNode:me,collisionRect:fe,collisions:Ye,droppableRects:re,draggableNodes:F,draggingNode:V,draggingNodeRect:ie,droppableContainers:O,over:qe,scrollableAncestors:Pe,scrollAdjustedTranslate:ve},I.current={initial:ie,translated:fe}},[G,me,Ye,fe,F,V,ie,re,O,qe,Pe,ve]),E5e({...De,delta:N,draggingRect:fe,pointerCoordinates:U,scrollableAncestors:Pe,scrollableAncestorRects:Re});const ue=T.useMemo(()=>({active:G,activeNode:me,activeNodeRect:we,activatorEvent:W,collisions:Ye,containerNodeRect:je,dragOverlay:z,draggableNodes:F,droppableContainers:O,droppableRects:re,over:qe,measureDroppableContainers:ce,scrollableAncestors:Pe,scrollableAncestorRects:Re,measuringConfiguration:X,measuringScheduled:xe,windowRect:ae}),[G,me,we,W,Ye,je,z,F,O,re,qe,ce,Pe,Re,X,xe,ae]),tt=T.useMemo(()=>({activatorEvent:W,activators:st,active:G,activeNodeRect:we,ariaDescribedById:{draggable:se},dispatch:g,draggableNodes:F,over:qe,measureDroppableContainers:ce}),[W,st,G,we,g,se,F,qe,ce]);return li.createElement(WZ.Provider,{value:w},li.createElement(Lw.Provider,{value:tt},li.createElement(sQ.Provider,{value:ue},li.createElement(oQ.Provider,{value:Ne},c)),li.createElement(X5e,{disabled:o?.restoreFocus===!1})),li.createElement(KBe,{...o,hiddenTextDescribedById:se}));function de(){const ke=$?.autoScrollEnabled===!1,Me=typeof l=="object"?l.enabled===!1:l===!1,ge=P&&!ke&&!Me;return typeof l=="object"?{...l,enabled:ge}:{enabled:ge}}}),J5e=T.createContext(null),VV="button",eHe="Draggable";function tHe(t){let{id:e,data:n,disabled:i=!1,attributes:r}=t;const a=Gv(eHe),{activators:s,activatorEvent:o,active:l,activeNodeRect:c,ariaDescribedById:d,draggableNodes:f,over:p}=T.useContext(Lw),{role:m=VV,roleDescription:y="draggable",tabIndex:b=0}=r??{},x=l?.id===e,g=T.useContext(x?oQ:J5e),[M,w]=aS(),[E,A]=aS(),P=F5e(s,e),C=tv(n);Ko(()=>(f.set(e,{id:e,key:a,node:M,activatorNode:E,data:C}),()=>{const N=f.get(e);N&&N.key===a&&f.delete(e)}),[f,e]);const F=T.useMemo(()=>({role:m,tabIndex:b,"aria-disabled":i,"aria-pressed":x&&m===VV?!0:void 0,"aria-roledescription":y,"aria-describedby":d.draggable}),[i,m,b,x,y,d.draggable]);return{active:l,activatorEvent:o,activeNodeRect:c,attributes:F,isDragging:x,listeners:i?void 0:P,node:M,over:p,setNodeRef:w,setActivatorNodeRef:A,transform:g}}function nHe(){return T.useContext(sQ)}const iHe="Droppable",rHe={timeout:25};function aHe(t){let{data:e,disabled:n=!1,id:i,resizeObserverConfig:r}=t;const a=Gv(iHe),{active:s,dispatch:o,over:l,measureDroppableContainers:c}=T.useContext(Lw),d=T.useRef({disabled:n}),f=T.useRef(!1),p=T.useRef(null),m=T.useRef(null),{disabled:y,updateMeasurementsFor:b,timeout:x}={...rHe,...r},g=tv(b??i),M=T.useCallback(()=>{if(!f.current){f.current=!0;return}m.current!=null&&clearTimeout(m.current),m.current=setTimeout(()=>{c(Array.isArray(g.current)?g.current:[g.current]),m.current=null},x)},[x]),w=kw({callback:M,disabled:y||!s}),E=T.useCallback((F,N)=>{w&&(N&&(w.unobserve(N),f.current=!1),F&&w.observe(F))},[w]),[A,P]=aS(E),C=tv(e);return T.useEffect(()=>{!w||!A.current||(w.disconnect(),f.current=!1,w.observe(A.current))},[A,w]),T.useEffect(()=>(o({type:er.RegisterDroppable,element:{id:i,key:a,disabled:n,node:A,rect:p,data:C}}),()=>o({type:er.UnregisterDroppable,key:a,id:i})),[i]),T.useEffect(()=>{n!==d.current.disabled&&(o({type:er.SetDroppableDisabled,id:i,key:a,disabled:n}),d.current.disabled=n)},[i,a,n,o]),{active:s,rect:p,isOver:l?.id===i,node:A,over:l,setNodeRef:P}}function gk(t,e,n){const i=t.slice();return i.splice(n<0?i.length+n:n,0,i.splice(e,1)[0]),i}function sHe(t,e){return t.reduce((n,i,r)=>{const a=e.get(i);return a&&(n[r]=a),n},Array(t.length))}function Db(t){return t!==null&&t>=0}function oHe(t,e){if(t===e)return!0;if(t.length!==e.length)return!1;for(let n=0;n{let{rects:e,activeIndex:n,overIndex:i,index:r}=t;const a=gk(e,i,n),s=e[r],o=a[r];return!o||!s?null:{x:o.left-s.left,y:o.top-s.top,scaleX:o.width/s.width,scaleY:o.height/s.height}},lQ="Sortable",cQ=li.createContext({activeIndex:-1,containerId:lQ,disableTransforms:!1,items:[],overIndex:-1,useDragOverlay:!1,sortedRects:[],strategy:vk,disabled:{draggable:!1,droppable:!1}});function cHe(t){let{children:e,id:n,items:i,strategy:r=vk,disabled:a=!1}=t;const{active:s,dragOverlay:o,droppableRects:l,over:c,measureDroppableContainers:d}=nHe(),f=Gv(lQ,n),p=o.rect!==null,m=T.useMemo(()=>i.map(P=>typeof P=="object"&&"id"in P?P.id:P),[i]),y=s!=null,b=s?m.indexOf(s.id):-1,x=c?m.indexOf(c.id):-1,g=T.useRef(m),M=!oHe(m,g.current),w=x!==-1&&b===-1||M,E=lHe(a);Ko(()=>{M&&y&&d(m)},[M,m,y,d]),T.useEffect(()=>{g.current=m},[m]);const A=T.useMemo(()=>({activeIndex:b,containerId:f,disabled:E,disableTransforms:w,items:m,overIndex:x,useDragOverlay:p,sortedRects:sHe(m,l),strategy:r}),[b,f,E.draggable,E.droppable,w,m,x,l,p,r]);return li.createElement(cQ.Provider,{value:A},e)}const uHe=t=>{let{id:e,items:n,activeIndex:i,overIndex:r}=t;return gk(n,i,r).indexOf(e)},dHe=t=>{let{containerId:e,isSorting:n,wasDragging:i,index:r,items:a,newIndex:s,previousItems:o,previousContainerId:l,transition:c}=t;return!c||!i||o!==a&&r===s?!1:n?!0:s!==r&&e===l},fHe={duration:200,easing:"ease"},uQ="transform",hHe=iv.Transition.toString({property:uQ,duration:0,easing:"linear"}),pHe={roleDescription:"sortable"};function mHe(t){let{disabled:e,index:n,node:i,rect:r}=t;const[a,s]=T.useState(null),o=T.useRef(n);return Ko(()=>{if(!e&&n!==o.current&&i.current){const l=r.current;if(l){const c=wm(i.current,{ignoreTransform:!0}),d={x:l.left-c.left,y:l.top-c.top,scaleX:l.width/c.width,scaleY:l.height/c.height};(d.x||d.y)&&s(d)}}n!==o.current&&(o.current=n)},[e,n,i,r]),T.useEffect(()=>{a&&s(null)},[a]),a}function gHe(t){let{animateLayoutChanges:e=dHe,attributes:n,disabled:i,data:r,getNewIndex:a=uHe,id:s,strategy:o,resizeObserverConfig:l,transition:c=fHe}=t;const{items:d,containerId:f,activeIndex:p,disabled:m,disableTransforms:y,sortedRects:b,overIndex:x,useDragOverlay:g,strategy:M}=T.useContext(cQ),w=vHe(i,m),E=d.indexOf(s),A=T.useMemo(()=>({sortable:{containerId:f,index:E,items:d},...r}),[f,r,E,d]),P=T.useMemo(()=>d.slice(d.indexOf(s)),[d,s]),{rect:C,node:F,isOver:N,setNodeRef:O}=aHe({id:s,data:A,disabled:w.droppable,resizeObserverConfig:{updateMeasurementsFor:P,...l}}),{active:B,activatorEvent:I,activeNodeRect:G,attributes:L,setNodeRef:$,listeners:q,isDragging:W,over:Y,setActivatorNodeRef:J,transform:se}=tHe({id:s,data:A,attributes:{...pHe,...n},disabled:w.draggable}),j=IBe(O,$),X=!!B,re=X&&!y&&Db(p)&&Db(x),ce=!g&&W,xe=ce&&re?se:null,ye=re?xe??(o??M)({rects:b,activeNodeRect:G,activeIndex:p,overIndex:x,index:E}):null,De=Db(p)&&Db(x)?a({id:s,items:d,activeIndex:p,overIndex:x}):E,he=B?.id,we=T.useRef({activeId:he,items:d,newIndex:De,containerId:f}),je=d!==we.current.items,le=e({active:B,containerId:f,isDragging:W,isSorting:X,id:s,index:E,items:d,newIndex:we.current.newIndex,previousItems:we.current.items,previousContainerId:we.current.containerId,transition:c,wasDragging:we.current.activeId!=null}),ut=mHe({disabled:!le,index:E,node:F,rect:C});return T.useEffect(()=>{X&&we.current.newIndex!==De&&(we.current.newIndex=De),f!==we.current.containerId&&(we.current.containerId=f),d!==we.current.items&&(we.current.items=d)},[X,De,f,d]),T.useEffect(()=>{if(he===we.current.activeId)return;if(he!=null&&we.current.activeId==null){we.current.activeId=he;return}const V=setTimeout(()=>{we.current.activeId=he},50);return()=>clearTimeout(V)},[he]),{active:B,activeIndex:p,attributes:L,data:A,rect:C,index:E,newIndex:De,items:d,isOver:N,isSorting:X,isDragging:W,listeners:q,node:F,overIndex:x,over:Y,setNodeRef:j,setActivatorNodeRef:J,setDroppableNodeRef:O,setDraggableNodeRef:$,transform:ut??ye,transition:z()};function z(){if(ut||je&&we.current.newIndex===E)return hHe;if(!(ce&&!dk(I)||!c)&&(X||le))return iv.Transition.toString({...c,property:uQ})}}function vHe(t,e){var n,i;return typeof t=="boolean"?{draggable:t,droppable:!1}:{draggable:(n=t?.draggable)!=null?n:e.draggable,droppable:(i=t?.droppable)!=null?i:e.droppable}}function lS(t){if(!t)return!1;const e=t.data.current;return!!(e&&"sortable"in e&&typeof e.sortable=="object"&&"containerId"in e.sortable&&"items"in e.sortable&&"index"in e.sortable)}const xHe=[mn.Down,mn.Right,mn.Up,mn.Left],yHe=(t,e)=>{let{context:{active:n,collisionRect:i,droppableRects:r,droppableContainers:a,over:s,scrollableAncestors:o}}=e;if(xHe.includes(t.code)){if(t.preventDefault(),!n||!i)return;const l=[];a.getEnabled().forEach(f=>{if(!f||f!=null&&f.disabled)return;const p=r.get(f.id);if(p)switch(t.code){case mn.Down:i.topp.top&&l.push(f);break;case mn.Left:i.left>p.left&&l.push(f);break;case mn.Right:i.left1&&(d=c[1].id),d!=null){const f=a.get(n.id),p=a.get(d),m=p?r.get(p.id):null,y=p?.node.current;if(y&&m&&f&&p){const x=Ow(y).some((P,C)=>o[C]!==P),g=dQ(f,p),M=bHe(f,p),w=x||!g?{x:0,y:0}:{x:M?i.width-m.width:0,y:M?i.height-m.height:0},E={x:m.left,y:m.top};return w.x&&w.y?E:nv(E,w)}}}};function dQ(t,e){return!lS(t)||!lS(e)?!1:t.data.current.sortable.containerId===e.data.current.sortable.containerId}function bHe(t,e){return!lS(t)||!lS(e)||!dQ(t,e)?!1:t.data.current.sortable.index{const x={};return t.forEach(g=>{x[g.id]=g.defaultSize||4}),x},[r,a]=T.useState(()=>{const x=localStorage.getItem(e);if(x)try{const g=JSON.parse(x);return g.sizes||(g.sizes=i()),g}catch{}return{order:t.map(g=>g.id),hidden:t.filter(g=>g.defaultVisible===!1).map(g=>g.id),sizes:i()}}),[s,o]=T.useState(!1);T.useEffect(()=>{localStorage.setItem(e,JSON.stringify(r))},[r,e]),T.useEffect(()=>{const g=t.map(M=>M.id).filter(M=>!r.order.includes(M));g.length>0&&a(M=>({...M,order:[...M.order,...g]}))},[t,r.order]);const l=YBe(PV(mk,{activationConstraint:{distance:8}}),PV(hk,{coordinateGetter:yHe})),c=x=>{const{active:g,over:M}=x;M&&g.id!==M.id&&a(w=>{const E=w.order.indexOf(g.id),A=w.order.indexOf(M.id);return{...w,order:gk(w.order,E,A)}})},d=x=>{a(g=>({...g,hidden:g.hidden.includes(x)?g.hidden.filter(M=>M!==x):[...g.hidden,x]}))},f=x=>{a(g=>{const M=g.sizes[x]||4,w=M===1?2:M===2?4:1;return{...g,sizes:{...g.sizes,[x]:w}}})},p=()=>{const x={order:t.map(g=>g.id),hidden:t.filter(g=>g.defaultVisible===!1).map(g=>g.id),sizes:i()};a(x)},m=r.order.map(x=>t.find(g=>g.id===x)).filter(Boolean),y=m.filter(x=>!r.hidden.includes(x.id)),b=m.filter(x=>r.hidden.includes(x.id));return _.jsxs("div",{className:"space-y-4",children:[_.jsxs("div",{className:"flex items-center justify-end gap-2",children:[b.length>0&&_.jsxs(mt,{variant:"secondary",size:"sm",onClick:()=>o(!s),children:[_.jsx(T4,{className:"w-4 h-4"}),b.length," Hidden"]}),_.jsxs(mt,{variant:"secondary",size:"sm",onClick:p,children:[_.jsx(WN,{className:"w-4 h-4"}),"Reset Layout"]})]}),s&&b.length>0&&_.jsxs("div",{className:"p-4 bg-bambu-dark rounded-xl border border-bambu-dark-tertiary",children:[_.jsx("p",{className:"text-sm text-bambu-gray mb-3",children:"Hidden widgets (click to show):"}),_.jsx("div",{className:"flex flex-wrap gap-2",children:b.map(x=>_.jsxs("button",{onClick:()=>d(x.id),className:"px-3 py-1.5 bg-bambu-dark-tertiary hover:bg-bambu-green/20 rounded-lg text-sm text-white transition-colors flex items-center gap-2",children:[_.jsx(T4,{className:"w-3 h-3"}),x.title]},x.id))})]}),_.jsx(Q5e,{sensors:l,collisionDetection:QBe,onDragEnd:c,children:_.jsx(cHe,{items:y.map(x=>x.id),strategy:vk,children:_.jsx("div",{className:"grid gap-6",style:{gridTemplateColumns:`repeat(${n}, minmax(0, 1fr))`},children:y.map(x=>_.jsx(_He,{id:x.id,title:x.title,isHidden:r.hidden.includes(x.id),size:r.sizes[x.id]||2,onToggleVisibility:()=>d(x.id),onToggleSize:()=>f(x.id),children:x.component},x.id))})})}),y.length===0&&_.jsxs("div",{className:"text-center py-12 text-bambu-gray",children:[_.jsx("p",{children:"All widgets are hidden."}),_.jsx(mt,{className:"mt-4",onClick:p,children:"Reset Layout"})]})]})}function wHe({stats:t,currency:e}){return _.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-4",children:[_.jsxs("div",{className:"flex items-start gap-3",children:[_.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-bambu-green",children:_.jsx(s_,{className:"w-5 h-5"})}),_.jsxs("div",{children:[_.jsx("p",{className:"text-xs text-bambu-gray",children:"Total Prints"}),_.jsx("p",{className:"text-xl font-bold text-white",children:t?.total_prints||0})]})]}),_.jsxs("div",{className:"flex items-start gap-3",children:[_.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-blue-400",children:_.jsx(Qo,{className:"w-5 h-5"})}),_.jsxs("div",{children:[_.jsx("p",{className:"text-xs text-bambu-gray",children:"Print Time"}),_.jsxs("p",{className:"text-xl font-bold text-white",children:[t?.total_print_time_hours.toFixed(1)||0,"h"]})]})]}),_.jsxs("div",{className:"flex items-start gap-3",children:[_.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-orange-400",children:_.jsx(s_,{className:"w-5 h-5"})}),_.jsxs("div",{children:[_.jsx("p",{className:"text-xs text-bambu-gray",children:"Filament Used"}),_.jsxs("p",{className:"text-xl font-bold text-white",children:[((t?.total_filament_grams||0)/1e3).toFixed(2),"kg"]})]})]}),_.jsxs("div",{className:"flex items-start gap-3",children:[_.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-green-400",children:_.jsx(A4,{className:"w-5 h-5"})}),_.jsxs("div",{children:[_.jsx("p",{className:"text-xs text-bambu-gray",children:"Filament Cost"}),_.jsxs("p",{className:"text-xl font-bold text-white",children:[e," ",t?.total_cost.toFixed(2)||"0.00"]})]})]}),_.jsxs("div",{className:"flex items-start gap-3",children:[_.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-yellow-400",children:_.jsx(NG,{className:"w-5 h-5"})}),_.jsxs("div",{children:[_.jsx("p",{className:"text-xs text-bambu-gray",children:"Energy Used"}),_.jsxs("p",{className:"text-xl font-bold text-white",children:[t?.total_energy_kwh.toFixed(2)||"0.00"," kWh"]})]})]}),_.jsxs("div",{className:"flex items-start gap-3",children:[_.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-yellow-500",children:_.jsx(A4,{className:"w-5 h-5"})}),_.jsxs("div",{children:[_.jsx("p",{className:"text-xs text-bambu-gray",children:"Energy Cost"}),_.jsxs("p",{className:"text-xl font-bold text-white",children:[e," ",t?.total_energy_cost.toFixed(2)||"0.00"]})]})]})]})}function MHe({stats:t}){const e=t?.total_prints?Math.round(t.successful_prints/t.total_prints*100):0;return _.jsxs("div",{className:"flex items-center gap-6",children:[_.jsxs("div",{className:"relative w-28 h-28",children:[_.jsxs("svg",{className:"w-full h-full -rotate-90",children:[_.jsx("circle",{cx:"56",cy:"56",r:"48",fill:"none",stroke:"#3d3d3d",strokeWidth:"10"}),_.jsx("circle",{cx:"56",cy:"56",r:"48",fill:"none",stroke:"#00ae42",strokeWidth:"10",strokeLinecap:"round",strokeDasharray:`${e*3.02} 302`})]}),_.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:_.jsxs("span",{className:"text-xl font-bold text-white",children:[e,"%"]})})]}),_.jsxs("div",{className:"space-y-2",children:[_.jsxs("div",{className:"flex items-center gap-2",children:[_.jsx(nm,{className:"w-4 h-4 text-bambu-green"}),_.jsx("span",{className:"text-sm text-bambu-gray",children:"Successful:"}),_.jsx("span",{className:"text-sm text-white font-medium",children:t?.successful_prints||0})]}),_.jsxs("div",{className:"flex items-center gap-2",children:[_.jsx(HN,{className:"w-4 h-4 text-red-400"}),_.jsx("span",{className:"text-sm text-bambu-gray",children:"Failed:"}),_.jsx("span",{className:"text-sm text-white font-medium",children:t?.failed_prints||0})]})]})]})}function EHe({stats:t,printerMap:e}){const n=t?.average_time_accuracy;if(n==null)return _.jsx("div",{className:"flex items-center justify-center h-full",children:_.jsx("p",{className:"text-bambu-gray text-center py-4",children:"No time accuracy data yet"})});const r=(Math.min(150,Math.max(50,n))-50)/100*100,s=(l=>l>=95&&l<=105?"#00ae42":l>105?"#3b82f6":"#f97316")(n),o=n-100;return _.jsxs("div",{className:"flex items-center gap-6",children:[_.jsxs("div",{className:"relative w-28 h-28",children:[_.jsxs("svg",{className:"w-full h-full -rotate-90",children:[_.jsx("circle",{cx:"56",cy:"56",r:"48",fill:"none",stroke:"#3d3d3d",strokeWidth:"10"}),_.jsx("circle",{cx:"56",cy:"56",r:"48",fill:"none",stroke:s,strokeWidth:"10",strokeLinecap:"round",strokeDasharray:`${r*3.02} 302`})]}),_.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center",children:[_.jsxs("span",{className:"text-xl font-bold text-white",children:[n.toFixed(0),"%"]}),_.jsxs("span",{className:`text-xs ${o>=0?"text-blue-400":"text-orange-400"}`,children:[o>=0?"+":"",o.toFixed(0),"%"]})]})]}),_.jsxs("div",{className:"space-y-2 flex-1",children:[_.jsxs("div",{className:"flex items-center gap-2 text-xs text-bambu-gray",children:[_.jsx(Jre,{className:"w-3 h-3"}),_.jsx("span",{children:"100% = perfect estimate"})]}),t?.time_accuracy_by_printer&&Object.keys(t.time_accuracy_by_printer).length>0&&_.jsx("div",{className:"space-y-1 mt-2",children:Object.entries(t.time_accuracy_by_printer).slice(0,3).map(([l,c])=>_.jsxs("div",{className:"flex items-center justify-between text-xs",children:[_.jsx("span",{className:"text-bambu-gray truncate max-w-[100px]",children:e.get(l)||`Printer ${l}`}),_.jsxs("span",{className:`font-medium ${c>=95&&c<=105?"text-bambu-green":c>105?"text-blue-400":"text-orange-400"}`,children:[c.toFixed(0),"%"]})]},l))})]})]})}function AHe({stats:t}){if(!t?.prints_by_filament_type||Object.keys(t.prints_by_filament_type).length===0)return _.jsx("p",{className:"text-bambu-gray text-center py-4",children:"No filament data available"});const e=Object.entries(t.prints_by_filament_type).sort(([,n],[,i])=>i-n);return _.jsx("div",{className:"space-y-3",children:e.map(([n,i])=>{const r=Math.round(i/(t.total_prints||1)*100);return _.jsxs("div",{children:[_.jsxs("div",{className:"flex justify-between text-sm mb-1",children:[_.jsx("span",{className:"text-white",children:n}),_.jsxs("span",{className:"text-bambu-gray",children:[i," prints"]})]}),_.jsx("div",{className:"h-2 bg-bambu-dark rounded-full",children:_.jsx("div",{className:"h-full bg-bambu-green rounded-full transition-all",style:{width:`${r}%`}})})]},n)})})}function THe({printDates:t}){return _.jsx(CEe,{printDates:t,months:4})}function CHe({stats:t,printerMap:e}){return!t?.prints_by_printer||Object.keys(t.prints_by_printer).length===0?_.jsx("p",{className:"text-bambu-gray text-center py-4",children:"No printer data available"}):_.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:Object.entries(t.prints_by_printer).map(([n,i])=>_.jsxs("div",{className:"flex items-center gap-3 p-3 bg-bambu-dark rounded-lg",children:[_.jsx("div",{className:"p-2 bg-bambu-dark-tertiary rounded-lg",children:_.jsx(ic,{className:"w-4 h-4 text-bambu-green"})}),_.jsxs("div",{children:[_.jsx("p",{className:"text-white font-medium text-sm",children:e.get(n)||`Printer ${n}`}),_.jsxs("p",{className:"text-xs text-bambu-gray",children:[i," prints"]})]})]},n))})}function RHe({archives:t,currency:e}){return!t||t.length===0?_.jsx("p",{className:"text-bambu-gray text-center py-4",children:"No print data available"}):_.jsx(LBe,{archives:t,currency:e})}function NHe(){const{data:t,isLoading:e}=vn({queryKey:["archiveStats"],queryFn:dt.getArchiveStats}),{data:n}=vn({queryKey:["printers"],queryFn:dt.getPrinters}),{data:i}=vn({queryKey:["archives"],queryFn:()=>dt.getArchives(void 0,1e3,0)}),{data:r}=vn({queryKey:["settings"],queryFn:dt.getSettings}),a=r?.currency||"$",s=new Map(n?.map(c=>[String(c.id),c.name])||[]),o=i?.map(c=>c.created_at)||[];if(e)return _.jsx("div",{className:"p-8",children:_.jsx("div",{className:"text-center py-12 text-bambu-gray",children:"Loading statistics..."})});const l=[{id:"quick-stats",title:"Quick Stats",component:_.jsx(wHe,{stats:t,currency:a}),defaultSize:2},{id:"success-rate",title:"Success Rate",component:_.jsx(MHe,{stats:t}),defaultSize:1},{id:"time-accuracy",title:"Time Accuracy",component:_.jsx(EHe,{stats:t,printerMap:s}),defaultSize:1},{id:"filament-types",title:"Filament Types",component:_.jsx(AHe,{stats:t}),defaultSize:1},{id:"print-activity",title:"Print Activity",component:_.jsx(THe,{printDates:o}),defaultSize:2},{id:"prints-by-printer",title:"Prints by Printer",component:_.jsx(CHe,{stats:t,printerMap:s}),defaultSize:2},{id:"filament-trends",title:"Filament Usage Trends",component:_.jsx(RHe,{archives:i||[],currency:a}),defaultSize:4}];return _.jsxs("div",{className:"p-8",children:[_.jsxs("div",{className:"mb-6",children:[_.jsx("h1",{className:"text-2xl font-bold text-white",children:"Dashboard"}),_.jsx("p",{className:"text-bambu-gray",children:"Drag widgets to rearrange. Click the eye icon to hide."})]}),_.jsx(SHe,{widgets:l,storageKey:"bambusy-dashboard-layout"})]})}function PHe({plug:t,onEdit:e}){const n=qi(),[i,r]=T.useState(!1),[a,s]=T.useState(!1),[o,l]=T.useState(!1),[c,d]=T.useState(!1),{data:f,isLoading:p,refetch:m}=vn({queryKey:["smart-plug-status",t.id],queryFn:()=>dt.getSmartPlugStatus(t.id),refetchInterval:3e4}),{data:y}=vn({queryKey:["printers"],queryFn:dt.getPrinters}),b=y?.find(P=>P.id===t.printer_id),x=hn({mutationFn:P=>dt.controlSmartPlug(t.id,P),onSuccess:()=>{m()}}),g=hn({mutationFn:P=>dt.updateSmartPlug(t.id,P),onSuccess:()=>{n.invalidateQueries({queryKey:["smart-plugs"]}),t.printer_id&&n.invalidateQueries({queryKey:["smartPlugByPrinter",t.printer_id]})}}),M=hn({mutationFn:()=>dt.deleteSmartPlug(t.id),onSuccess:()=>{n.invalidateQueries({queryKey:["smart-plugs"]})}}),w=f?.state==="ON",E=f?.reachable??!1,A=x.isPending;return _.jsxs(_.Fragment,{children:[_.jsx(_n,{className:"relative",children:_.jsxs(An,{className:"p-4",children:[_.jsxs("div",{className:"flex items-start justify-between mb-3",children:[_.jsxs("div",{className:"flex items-center gap-3",children:[_.jsx("div",{className:`p-2 rounded-lg ${E?w?"bg-bambu-green/20":"bg-bambu-dark":"bg-red-500/20"}`,children:_.jsx(B2,{className:`w-5 h-5 ${E?w?"text-bambu-green":"text-bambu-gray":"text-red-400"}`})}),_.jsxs("div",{children:[_.jsx("h3",{className:"font-medium text-white",children:t.name}),_.jsx("p",{className:"text-sm text-bambu-gray",children:t.ip_address})]})]}),_.jsx("div",{className:"flex items-center gap-2",children:p?_.jsx(Hn,{className:"w-4 h-4 text-bambu-gray animate-spin"}):E?_.jsxs("div",{className:"flex items-center gap-1 text-sm",children:[_.jsx(qN,{className:"w-4 h-4 text-bambu-green"}),_.jsx("span",{className:w?"text-bambu-green":"text-bambu-gray",children:f?.state||"Unknown"})]}):_.jsxs("div",{className:"flex items-center gap-1 text-sm text-red-400",children:[_.jsx(gS,{className:"w-4 h-4"}),_.jsx("span",{children:"Offline"})]})})]}),b&&_.jsxs("div",{className:"mb-3 px-2 py-1.5 bg-bambu-dark rounded-lg",children:[_.jsx("span",{className:"text-xs text-bambu-gray",children:"Linked to: "}),_.jsx("span",{className:"text-sm text-white",children:b.name})]}),_.jsxs("div",{className:"flex gap-2 mb-3",children:[_.jsxs(mt,{size:"sm",variant:w?"primary":"secondary",disabled:!E||A,onClick:()=>s(!0),className:"flex-1",children:[A?_.jsx(Hn,{className:"w-4 h-4 animate-spin"}):_.jsx(pS,{className:"w-4 h-4"}),"On"]}),_.jsxs(mt,{size:"sm",variant:w?"secondary":"primary",disabled:!E||A,onClick:()=>l(!0),className:"flex-1",children:[A?_.jsx(Hn,{className:"w-4 h-4 animate-spin"}):_.jsx(TG,{className:"w-4 h-4"}),"Off"]})]}),_.jsxs("button",{onClick:()=>d(!c),className:"w-full flex items-center justify-between py-2 text-sm text-bambu-gray hover:text-white transition-colors",children:[_.jsxs("span",{className:"flex items-center gap-2",children:[_.jsx(CG,{className:"w-4 h-4"}),"Automation Settings"]}),_.jsx("span",{children:c?"-":"+"})]}),c&&_.jsxs("div",{className:"pt-3 border-t border-bambu-dark-tertiary space-y-4",children:[_.jsxs("div",{className:"flex items-center justify-between",children:[_.jsxs("div",{children:[_.jsx("p",{className:"text-sm text-white",children:"Enabled"}),_.jsx("p",{className:"text-xs text-bambu-gray",children:"Enable automation for this plug"})]}),_.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[_.jsx("input",{type:"checkbox",checked:t.enabled,onChange:P=>g.mutate({enabled:P.target.checked}),className:"sr-only peer"}),_.jsx("div",{className:"w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green"})]})]}),_.jsxs("div",{className:"flex items-center justify-between",children:[_.jsxs("div",{children:[_.jsx("p",{className:"text-sm text-white",children:"Auto On"}),_.jsx("p",{className:"text-xs text-bambu-gray",children:"Turn on when print starts"})]}),_.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[_.jsx("input",{type:"checkbox",checked:t.auto_on,onChange:P=>g.mutate({auto_on:P.target.checked}),className:"sr-only peer"}),_.jsx("div",{className:"w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green"})]})]}),_.jsxs("div",{className:"flex items-center justify-between",children:[_.jsxs("div",{children:[_.jsx("p",{className:"text-sm text-white",children:"Auto Off"}),_.jsx("p",{className:"text-xs text-bambu-gray",children:"Turn off when print completes (one-shot)"})]}),_.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[_.jsx("input",{type:"checkbox",checked:t.auto_off,onChange:P=>g.mutate({auto_off:P.target.checked}),className:"sr-only peer"}),_.jsx("div",{className:"w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green"})]})]}),t.auto_off&&_.jsxs("div",{className:"space-y-3 pl-4 border-l-2 border-bambu-dark-tertiary",children:[_.jsxs("div",{children:[_.jsx("p",{className:"text-sm text-white mb-2",children:"Turn Off Delay Mode"}),_.jsxs("div",{className:"flex gap-2",children:[_.jsxs("button",{onClick:()=>g.mutate({off_delay_mode:"time"}),className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg text-sm transition-colors ${t.off_delay_mode==="time"?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white"}`,children:[_.jsx(Qo,{className:"w-4 h-4"}),"Time"]}),_.jsxs("button",{onClick:()=>g.mutate({off_delay_mode:"temperature"}),className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg text-sm transition-colors ${t.off_delay_mode==="temperature"?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white"}`,children:[_.jsx(Lb,{className:"w-4 h-4"}),"Temp"]})]})]}),t.off_delay_mode==="time"?_.jsxs("div",{children:[_.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Delay (minutes)"}),_.jsx("input",{type:"number",min:"1",max:"60",value:t.off_delay_minutes,onChange:P=>g.mutate({off_delay_minutes:parseInt(P.target.value)||5}),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none"})]}):_.jsxs("div",{children:[_.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Temperature threshold (C)"}),_.jsx("input",{type:"number",min:"30",max:"100",value:t.off_temp_threshold,onChange:P=>g.mutate({off_temp_threshold:parseInt(P.target.value)||70}),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none"}),_.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Turns off when nozzle cools below this temperature"})]})]}),_.jsxs("div",{className:"flex gap-2 pt-2",children:[_.jsxs(mt,{size:"sm",variant:"secondary",onClick:()=>e(t),className:"flex-1",children:[_.jsx(wre,{className:"w-4 h-4"}),"Edit"]}),_.jsx(mt,{size:"sm",variant:"secondary",onClick:()=>r(!0),className:"text-red-400 hover:text-red-300",children:_.jsx(ns,{className:"w-4 h-4"})})]})]})]})}),i&&_.jsx(is,{title:"Delete Smart Plug",message:`Are you sure you want to delete "${t.name}"? This cannot be undone.`,confirmText:"Delete",variant:"danger",onConfirm:()=>{M.mutate(),r(!1)},onCancel:()=>r(!1)}),a&&_.jsx(is,{title:"Turn On Smart Plug",message:`Are you sure you want to turn on "${t.name}"?`,confirmText:"Turn On",variant:"default",onConfirm:()=>{x.mutate("on"),s(!1)},onCancel:()=>s(!1)}),o&&_.jsx(is,{title:"Turn Off Smart Plug",message:`Are you sure you want to turn off "${t.name}"? This will cut power to the connected device.`,confirmText:"Turn Off",variant:"danger",onConfirm:()=>{x.mutate("off"),l(!1)},onCancel:()=>l(!1)})]})}function DHe({plug:t,onClose:e}){const n=qi(),i=!!t,[r,a]=T.useState(t?.name||""),[s,o]=T.useState(t?.ip_address||""),[l,c]=T.useState(t?.username||""),[d,f]=T.useState(t?.password||""),[p,m]=T.useState(t?.printer_id||null),[y,b]=T.useState(null),[x,g]=T.useState(null),{data:M}=vn({queryKey:["printers"],queryFn:dt.getPrinters}),{data:w}=vn({queryKey:["smart-plugs"],queryFn:dt.getSmartPlugs});T.useEffect(()=>{const O=B=>{B.key==="Escape"&&e()};return window.addEventListener("keydown",O),()=>window.removeEventListener("keydown",O)},[e]);const E=hn({mutationFn:()=>dt.testSmartPlugConnection(s,l||null,d||null),onSuccess:O=>{b(O),g(null),!r&&O.device_name&&a(O.device_name)},onError:O=>{b(null),g(O.message)}}),A=hn({mutationFn:O=>dt.createSmartPlug(O),onSuccess:()=>{n.invalidateQueries({queryKey:["smart-plugs"]}),e()},onError:O=>{g(O.message)}}),P=hn({mutationFn:O=>dt.updateSmartPlug(t.id,O),onSuccess:()=>{n.invalidateQueries({queryKey:["smart-plugs"]}),e()},onError:O=>{g(O.message)}}),C=M?.filter(O=>!w?.some(I=>I.printer_id===O.id&&I.id!==t?.id)),F=O=>{if(O.preventDefault(),g(null),!r.trim()){g("Name is required");return}if(!s.trim()){g("IP address is required");return}const B={name:r.trim(),ip_address:s.trim(),username:l.trim()||null,password:d.trim()||null,printer_id:p};i?P.mutate(B):A.mutate(B)},N=A.isPending||P.isPending;return _.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",onClick:e,children:_.jsxs("div",{className:"bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-md",onClick:O=>O.stopPropagation(),children:[_.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary",children:[_.jsx("h2",{className:"text-lg font-semibold text-white",children:i?"Edit Smart Plug":"Add Smart Plug"}),_.jsx("button",{onClick:e,className:"text-bambu-gray hover:text-white transition-colors",children:_.jsx(Vn,{className:"w-5 h-5"})})]}),_.jsxs("form",{onSubmit:F,className:"p-6 space-y-4",children:[x&&_.jsx("div",{className:"p-3 bg-red-500/20 border border-red-500/50 rounded-lg text-sm text-red-400",children:x}),_.jsxs("div",{children:[_.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"IP Address *"}),_.jsxs("div",{className:"flex gap-2",children:[_.jsx("input",{type:"text",value:s,onChange:O=>{o(O.target.value),b(null)},placeholder:"192.168.1.100",className:"flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"}),_.jsxs(mt,{type:"button",variant:"secondary",onClick:()=>E.mutate(),disabled:!s.trim()||E.isPending,children:[E.isPending?_.jsx(Hn,{className:"w-4 h-4 animate-spin"}):_.jsx(qN,{className:"w-4 h-4"}),"Test"]})]})]}),y&&_.jsx("div",{className:`p-3 rounded-lg flex items-center gap-2 ${y.success?"bg-bambu-green/20 border border-bambu-green/50 text-bambu-green":"bg-red-500/20 border border-red-500/50 text-red-400"}`,children:y.success?_.jsxs(_.Fragment,{children:[_.jsx(nm,{className:"w-5 h-5"}),_.jsxs("div",{children:[_.jsx("p",{className:"font-medium",children:"Connected!"}),_.jsxs("p",{className:"text-sm opacity-80",children:[y.device_name&&`Device: ${y.device_name} - `,"State: ",y.state]})]})]}):_.jsxs(_.Fragment,{children:[_.jsx(gS,{className:"w-5 h-5"}),_.jsx("span",{children:"Connection failed"})]})}),_.jsxs("div",{children:[_.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Name *"}),_.jsx("input",{type:"text",value:r,onChange:O=>a(O.target.value),placeholder:"Living Room Plug",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"})]}),_.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[_.jsxs("div",{children:[_.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Username"}),_.jsx("input",{type:"text",value:l,onChange:O=>c(O.target.value),placeholder:"admin",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),_.jsxs("div",{children:[_.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Password"}),_.jsx("input",{type:"password",value:d,onChange:O=>f(O.target.value),placeholder:"********",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]})]}),_.jsx("p",{className:"text-xs text-bambu-gray -mt-2",children:"Leave empty if your Tasmota device doesn't require authentication"}),_.jsxs("div",{children:[_.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Link to Printer"}),_.jsxs("select",{value:p??"",onChange:O=>m(O.target.value?Number(O.target.value):null),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[_.jsx("option",{value:"",children:"No printer (manual control only)"}),C?.map(O=>_.jsx("option",{value:O.id,children:O.name},O.id))]}),_.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Linking enables automatic on/off when prints start/complete"})]}),_.jsxs("div",{className:"flex gap-3 pt-2",children:[_.jsx(mt,{type:"button",variant:"secondary",onClick:e,className:"flex-1",children:"Cancel"}),_.jsxs(mt,{type:"submit",disabled:N,className:"flex-1",children:[N?_.jsx(Hn,{className:"w-4 h-4 animate-spin"}):_.jsx(mS,{className:"w-4 h-4"}),i?"Save":"Add"]})]})]})]})})}function OHe(){const t=qi(),[e,n]=T.useState(null),[i,r]=T.useState(!1),[a,s]=T.useState(!1),[o,l]=T.useState(!1),[c,d]=T.useState(null),[f,p]=T.useState(DG()),m=C=>{p(C),Pae(C)},y=()=>{localStorage.removeItem("sidebarOrder"),window.location.reload()},{data:b,isLoading:x}=vn({queryKey:["settings"],queryFn:dt.getSettings}),{data:g,isLoading:M}=vn({queryKey:["smart-plugs"],queryFn:dt.getSmartPlugs}),{data:w}=vn({queryKey:["ffmpeg-status"],queryFn:dt.checkFfmpeg});T.useEffect(()=>{b&&!e&&n(b)},[b,e]),T.useEffect(()=>{if(b&&e){const C=b.auto_archive!==e.auto_archive||b.save_thumbnails!==e.save_thumbnails||b.capture_finish_photo!==e.capture_finish_photo||b.default_filament_cost!==e.default_filament_cost||b.currency!==e.currency||b.energy_cost_per_kwh!==e.energy_cost_per_kwh||b.energy_tracking_mode!==e.energy_tracking_mode;r(C)}},[b,e]);const E=hn({mutationFn:dt.updateSettings,onSuccess:C=>{t.setQueryData(["settings"],C),n(C),r(!1),s(!0),setTimeout(()=>s(!1),2e3),t.invalidateQueries({queryKey:["archiveStats"]})}}),A=()=>{e&&E.mutate(e)},P=(C,F)=>{e&&n({...e,[C]:F})};return x||!e?_.jsx("div",{className:"p-8 flex justify-center",children:_.jsx(Hn,{className:"w-8 h-8 text-bambu-green animate-spin"})}):_.jsxs("div",{className:"p-8",children:[_.jsxs("div",{className:"mb-8 flex items-center justify-between",children:[_.jsxs("div",{children:[_.jsx("h1",{className:"text-2xl font-bold text-white",children:"Settings"}),_.jsx("p",{className:"text-bambu-gray",children:"Configure Bambusy"})]}),_.jsxs(mt,{onClick:A,disabled:!i||E.isPending,children:[E.isPending?_.jsx(Hn,{className:"w-4 h-4 animate-spin"}):a?_.jsx(rie,{className:"w-4 h-4"}):_.jsx(mS,{className:"w-4 h-4"}),a?"Saved!":"Save"]})]}),E.isError&&_.jsxs("div",{className:"mb-6 p-3 bg-red-500/20 border border-red-500/50 rounded-lg text-sm text-red-400",children:["Failed to save settings: ",E.error.message]}),_.jsxs("div",{className:"flex gap-8",children:[_.jsxs("div",{className:"space-y-6 flex-1 max-w-xl",children:[_.jsxs(_n,{children:[_.jsx(Qh,{children:_.jsx("h2",{className:"text-lg font-semibold text-white",children:"Archive Settings"})}),_.jsxs(An,{className:"space-y-4",children:[_.jsxs("div",{className:"flex items-center justify-between",children:[_.jsxs("div",{children:[_.jsx("p",{className:"text-white",children:"Auto-archive prints"}),_.jsx("p",{className:"text-sm text-bambu-gray",children:"Automatically save 3MF files when prints complete"})]}),_.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[_.jsx("input",{type:"checkbox",checked:e.auto_archive,onChange:C=>P("auto_archive",C.target.checked),className:"sr-only peer"}),_.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),_.jsxs("div",{className:"flex items-center justify-between",children:[_.jsxs("div",{children:[_.jsx("p",{className:"text-white",children:"Save thumbnails"}),_.jsx("p",{className:"text-sm text-bambu-gray",children:"Extract and save preview images from 3MF files"})]}),_.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[_.jsx("input",{type:"checkbox",checked:e.save_thumbnails,onChange:C=>P("save_thumbnails",C.target.checked),className:"sr-only peer"}),_.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),_.jsxs("div",{className:"flex items-center justify-between",children:[_.jsxs("div",{children:[_.jsx("p",{className:"text-white",children:"Capture finish photo"}),_.jsx("p",{className:"text-sm text-bambu-gray",children:"Take a photo from printer camera when print completes"})]}),_.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[_.jsx("input",{type:"checkbox",checked:e.capture_finish_photo,onChange:C=>P("capture_finish_photo",C.target.checked),className:"sr-only peer"}),_.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),e.capture_finish_photo&&w&&!w.installed&&_.jsxs("div",{className:"flex items-start gap-2 p-3 bg-yellow-500/10 border border-yellow-500/30 rounded-lg",children:[_.jsx(Ap,{className:"w-5 h-5 text-yellow-500 flex-shrink-0 mt-0.5"}),_.jsxs("div",{className:"text-sm",children:[_.jsx("p",{className:"text-yellow-500 font-medium",children:"ffmpeg not installed"}),_.jsxs("p",{className:"text-bambu-gray mt-1",children:["Camera capture requires ffmpeg. Install it via"," ",_.jsx("code",{className:"bg-bambu-dark-tertiary px-1 rounded",children:"brew install ffmpeg"})," (macOS) or"," ",_.jsx("code",{className:"bg-bambu-dark-tertiary px-1 rounded",children:"apt install ffmpeg"})," (Linux)."]})]})]})]})]}),_.jsxs(_n,{children:[_.jsx(Qh,{children:_.jsx("h2",{className:"text-lg font-semibold text-white",children:"Cost Tracking"})}),_.jsxs(An,{className:"space-y-4",children:[_.jsxs("div",{children:[_.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Default filament cost (per kg)"}),_.jsx("input",{type:"number",step:"0.01",min:"0",value:e.default_filament_cost,onChange:C=>P("default_filament_cost",parseFloat(C.target.value)||0),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"})]}),_.jsxs("div",{children:[_.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Currency"}),_.jsxs("select",{value:e.currency,onChange:C=>P("currency",C.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[_.jsx("option",{value:"USD",children:"USD ($)"}),_.jsx("option",{value:"EUR",children:"EUR (€)"}),_.jsx("option",{value:"GBP",children:"GBP (£)"}),_.jsx("option",{value:"CHF",children:"CHF (Fr.)"}),_.jsx("option",{value:"JPY",children:"JPY (¥)"}),_.jsx("option",{value:"CNY",children:"CNY (¥)"}),_.jsx("option",{value:"CAD",children:"CAD ($)"}),_.jsx("option",{value:"AUD",children:"AUD ($)"})]})]}),_.jsxs("div",{children:[_.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Electricity cost per kWh"}),_.jsx("input",{type:"number",step:"0.01",min:"0",value:e.energy_cost_per_kwh,onChange:C=>P("energy_cost_per_kwh",parseFloat(C.target.value)||0),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"})]}),_.jsxs("div",{children:[_.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Energy display mode"}),_.jsxs("select",{value:e.energy_tracking_mode||"total",onChange:C=>P("energy_tracking_mode",C.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[_.jsx("option",{value:"print",children:"Prints Only"}),_.jsx("option",{value:"total",children:"Total Consumption"})]}),_.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:e.energy_tracking_mode==="print"?"Dashboard shows sum of energy used during prints":"Dashboard shows lifetime energy from smart plugs"})]})]})]}),_.jsxs(_n,{children:[_.jsx(Qh,{children:_.jsx("h2",{className:"text-lg font-semibold text-white",children:"Interface"})}),_.jsxs(An,{className:"space-y-4",children:[_.jsxs("div",{children:[_.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Default view on startup"}),_.jsx("select",{value:f,onChange:C=>m(C.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:Ib.map(C=>_.jsx("option",{value:C.to,children:C.label},C.id))}),_.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Page to show when opening the app"})]}),_.jsxs("div",{className:"flex items-center justify-between",children:[_.jsxs("div",{children:[_.jsx("p",{className:"text-white",children:"Sidebar order"}),_.jsx("p",{className:"text-sm text-bambu-gray",children:"Drag items in the sidebar to reorder. Reset to default order here."})]}),_.jsxs(mt,{variant:"secondary",size:"sm",onClick:y,children:[_.jsx(WN,{className:"w-4 h-4"}),"Reset"]})]})]})]}),_.jsxs(_n,{children:[_.jsx(Qh,{children:_.jsx("h2",{className:"text-lg font-semibold text-white",children:"About"})}),_.jsx(An,{children:_.jsxs("div",{className:"space-y-2 text-sm",children:[_.jsx("p",{className:"text-white",children:"Bambusy v0.1.2"}),_.jsx("p",{className:"text-bambu-gray",children:"Archive and manage your Bambu Lab 3MF files"}),_.jsx("p",{className:"text-bambu-gray",children:"Connect to printers via LAN mode (developer mode required)"})]})})]})]}),_.jsx("div",{className:"w-96 flex-shrink-0",children:_.jsxs(_n,{children:[_.jsx(Qh,{children:_.jsxs("div",{className:"flex items-center justify-between",children:[_.jsxs("div",{className:"flex items-center gap-2",children:[_.jsx(B2,{className:"w-5 h-5 text-bambu-green"}),_.jsx("h2",{className:"text-lg font-semibold text-white",children:"Smart Plugs"})]}),_.jsxs(mt,{size:"sm",onClick:()=>{d(null),l(!0)},children:[_.jsx(ff,{className:"w-4 h-4"}),"Add"]})]})}),_.jsxs(An,{children:[_.jsx("p",{className:"text-sm text-bambu-gray mb-4",children:"Connect Tasmota-based smart plugs to automate power control for your printers."}),M?_.jsx("div",{className:"flex justify-center py-8",children:_.jsx(Hn,{className:"w-6 h-6 text-bambu-green animate-spin"})}):g&&g.length>0?_.jsx("div",{className:"space-y-4",children:g.map(C=>_.jsx(PHe,{plug:C,onEdit:F=>{d(F),l(!0)}},C.id))}):_.jsxs("div",{className:"text-center py-8 text-bambu-gray",children:[_.jsx(B2,{className:"w-12 h-12 mx-auto mb-3 opacity-30"}),_.jsx("p",{children:"No smart plugs configured"}),_.jsx("p",{className:"text-sm mt-1",children:"Add a Tasmota plug to get started"})]})]})]})})]}),o&&_.jsx(DHe,{plug:c,onClose:()=>{l(!1),d(null)}})]})}const fQ=t=>{const e=parseFloat(t);return(Math.trunc(e*1e3)/1e3).toFixed(3)},kHe=t=>t.startsWith("HH")?"HF":"S",LHe=t=>{const e=t.match(/^([A-Z]{2}\d{2})/);return e?e[1]:"HH00"},DN=t=>{const e=["High Flow_","High Flow ","Standard_","Standard ","HF_","HF ","S_","S "];for(const i of e)if(t.startsWith(i))return t.slice(i.length);const n=t.indexOf("_");return n>0?t.slice(n+1):t};function C2({profile:t,onEdit:e}){const n=kHe(t.nozzle_id),i=t.nozzle_diameter,r=t.name||"Unnamed",a=DN(t.name||"");return _.jsxs("button",{onClick:e,className:"w-full text-left px-3 py-2 bg-bambu-dark rounded hover:bg-bambu-dark-tertiary transition-colors",children:[_.jsxs("div",{className:"flex items-center gap-2",children:[_.jsx("span",{className:"text-bambu-green font-mono text-sm font-bold whitespace-nowrap",children:fQ(t.k_value)}),_.jsx("span",{className:"text-white text-sm truncate flex-1",title:r,children:r}),_.jsxs("span",{className:"text-xs text-bambu-gray whitespace-nowrap",children:[n," ",i]})]}),_.jsxs("div",{className:"text-xs text-bambu-gray mt-0.5 truncate",title:`Filament: ${a}`,children:["Filament: ",a||t.filament_id]})]})}function GV({profile:t,printerId:e,nozzleDiameter:n,existingProfiles:i=[],isDualNozzle:r=!1,onClose:a,onSave:s}){const{showToast:o}=Jo(),l=qi(),[c,d]=T.useState(t?.name||""),[f,p]=T.useState(t?.k_value?fQ(t.k_value):"0.020"),[m,y]=T.useState(t?.filament_id||""),[b,x]=T.useState(t?.nozzle_id?LHe(t.nozzle_id):"HH00"),[g,M]=T.useState(t?.nozzle_diameter||n),[w,E]=T.useState(t?.extruder_id||0),A=li.useMemo(()=>{const I=new Map;for(const G of i)if(G.filament_id&&!I.has(G.filament_id)){const L=DN(G.name||"");I.set(G.filament_id,{id:G.filament_id,name:L||G.filament_id})}return Array.from(I.values()).sort((G,L)=>G.name.localeCompare(L.name))},[i]),P=hn({mutationFn:I=>(console.log("[KProfile] Calling API..."),dt.setKProfile(e,I)),onSuccess:I=>{console.log("[KProfile] Save success:",I),o("K-profile saved"),l.invalidateQueries({queryKey:["kprofiles",e]}),s()},onError:I=>{console.error("[KProfile] Save error:",I),o(I.message,"error")}}),C=hn({mutationFn:I=>(console.log("[KProfile] Deleting profile..."),dt.deleteKProfile(e,I)),onSuccess:I=>{console.log("[KProfile] Delete success:",I),o("K-profile deleted"),l.invalidateQueries({queryKey:["kprofiles",e]}),a()},onError:I=>{console.error("[KProfile] Delete error:",I),o(I.message,"error")}}),[F,N]=T.useState(!1),O=()=>{t&&C.mutate({slot_id:t.slot_id,extruder_id:t.extruder_id,nozzle_id:t.nozzle_id,nozzle_diameter:t.nozzle_diameter,filament_id:t.filament_id})},B=I=>{I.preventDefault();const G=parseFloat(f).toFixed(6),L=`${b}-${g}`,$={name:c,k_value:G,filament_id:m,nozzle_id:L,nozzle_diameter:g,extruder_id:w,setting_id:t?.setting_id,slot_id:t?.slot_id??0};console.log("[KProfile] Saving profile:",$),P.mutate($)};return _.jsxs("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:[_.jsx(_n,{className:"w-full max-w-md",children:_.jsxs(An,{className:"p-0",children:[_.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[_.jsx("h2",{className:"text-xl font-semibold text-white",children:t?"Edit K-Profile":"Add K-Profile"}),_.jsx("button",{onClick:a,className:"text-bambu-gray hover:text-white transition-colors",children:_.jsx(Vn,{className:"w-5 h-5"})})]}),_.jsxs("form",{onSubmit:B,className:"p-4 space-y-4",children:[_.jsxs("div",{children:[_.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Profile Name"}),_.jsx("input",{type:"text",value:c,onChange:I=>d(I.target.value),disabled:!!t,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none ${t?"opacity-60 cursor-not-allowed":""}`,placeholder:"My PLA Profile",required:!0})]}),_.jsxs("div",{children:[_.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"K-Value"}),_.jsx("input",{type:"text",inputMode:"decimal",value:f,onChange:I=>{const G=I.target.value;(G===""||/^\d*\.?\d*$/.test(G))&&p(G)},onBlur:I=>{const G=parseFloat(I.target.value);isNaN(G)||p((Math.trunc(G*1e3)/1e3).toFixed(3))},className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none font-mono",placeholder:"0.020",required:!0}),_.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Typical range: 0.01 - 0.06 for PLA, 0.02 - 0.10 for PETG"})]}),_.jsxs("div",{children:[_.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Filament"}),_.jsxs("select",{value:m,onChange:I=>{const G=I.target.value;if(y(G),!t&&G&&!c){const L=A.find($=>$.id===G);L&&d(`${b==="HH00"?"HF":"S"} ${L.name}`)}},disabled:!!t,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none ${t?"opacity-60 cursor-not-allowed":""}`,required:!0,children:[_.jsx("option",{value:"",children:"Select filament..."}),t?.filament_id&&_.jsx("option",{value:t.filament_id,children:DN(t.name||t.filament_id)},t.filament_id),!t&&A.map(I=>_.jsx("option",{value:I.id,children:I.name},I.id))]}),!t&&A.length===0&&_.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"No filaments found. Create a K-profile in Bambu Studio first."})]}),_.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[_.jsxs("div",{children:[_.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Flow Type"}),_.jsxs("select",{value:b,onChange:I=>{const G=I.target.value;if(x(G),!t&&m&&!c){const L=A.find($=>$.id===m);L&&d(`${G==="HH00"?"HF":"S"} ${L.name}`)}},disabled:!!t,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none ${t?"opacity-60 cursor-not-allowed":""}`,children:[_.jsx("option",{value:"HH00",children:"High Flow"}),_.jsx("option",{value:"HS00",children:"Standard"})]})]}),_.jsxs("div",{children:[_.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Nozzle Size"}),_.jsxs("select",{value:g,onChange:I=>M(I.target.value),disabled:!!t,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none ${t?"opacity-60 cursor-not-allowed":""}`,children:[_.jsx("option",{value:"0.2",children:"0.2mm"}),_.jsx("option",{value:"0.4",children:"0.4mm"}),_.jsx("option",{value:"0.6",children:"0.6mm"}),_.jsx("option",{value:"0.8",children:"0.8mm"})]})]})]}),r&&_.jsxs("div",{children:[_.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Extruder"}),_.jsxs("select",{value:w,onChange:I=>E(parseInt(I.target.value)),disabled:!!t,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none ${t?"opacity-60 cursor-not-allowed":""}`,children:[_.jsx("option",{value:1,children:"Left"}),_.jsx("option",{value:0,children:"Right"})]})]}),_.jsxs("div",{className:"flex gap-2 pt-4",children:[t&&_.jsx(mt,{type:"button",variant:"secondary",onClick:()=>N(!0),disabled:C.isPending,className:"text-red-500 hover:bg-red-500/10",children:C.isPending?_.jsx(Hn,{className:"w-4 h-4 animate-spin"}):_.jsx(ns,{className:"w-4 h-4"})}),_.jsx(mt,{type:"button",variant:"secondary",onClick:a,className:"flex-1",children:"Cancel"}),_.jsxs(mt,{type:"submit",disabled:P.isPending,className:"flex-1",children:[P.isPending?_.jsx(Hn,{className:"w-4 h-4 animate-spin"}):_.jsx(GN,{className:"w-4 h-4"}),"Save"]})]})]})]})}),F&&_.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-[60]",children:_.jsx(_n,{className:"w-full max-w-sm",children:_.jsxs(An,{className:"p-6",children:[_.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[_.jsx("div",{className:"w-10 h-10 rounded-full bg-red-500/20 flex items-center justify-center",children:_.jsx(ns,{className:"w-5 h-5 text-red-500"})}),_.jsxs("div",{children:[_.jsx("h3",{className:"text-lg font-semibold text-white",children:"Delete Profile"}),_.jsx("p",{className:"text-sm text-bambu-gray",children:"This cannot be undone"})]})]}),_.jsxs("p",{className:"text-bambu-gray mb-6",children:["Are you sure you want to delete ",_.jsxs("span",{className:"text-white font-medium",children:['"',t?.name,'"']})," from the printer?"]}),_.jsxs("div",{className:"flex gap-3",children:[_.jsx(mt,{variant:"secondary",onClick:()=>N(!1),className:"flex-1",children:"Cancel"}),_.jsxs(mt,{onClick:()=>{N(!1),O()},disabled:C.isPending,className:"flex-1 bg-red-500 hover:bg-red-600 text-white",children:[C.isPending?_.jsx(Hn,{className:"w-4 h-4 animate-spin"}):_.jsx(ns,{className:"w-4 h-4"}),"Delete"]})]})]})})})]})}function IHe(){const[t,e]=T.useState(null),[n,i]=T.useState("0.4"),[r,a]=T.useState(null),[s,o]=T.useState(!1),[l,c]=T.useState(""),[d,f]=T.useState("all"),[p,m]=T.useState("all"),{data:y,isLoading:b}=vn({queryKey:["printers"],queryFn:dt.getPrinters}),{data:x,isLoading:g,error:M,refetch:w}=vn({queryKey:["kprofiles",t,n],queryFn:()=>dt.getKProfiles(t,n),enabled:!!t,retry:!1}),E=M?.message?.includes("not connected"),A=li.useMemo(()=>x?.profiles?x.profiles.filter(N=>{const O=l.toLowerCase(),B=!O||N.name.toLowerCase().includes(O)||N.filament_id.toLowerCase().includes(O),I=d==="all"||d==="left"&&N.extruder_id===1||d==="right"&&N.extruder_id===0,G=p==="all"||p==="hf"&&N.nozzle_id.startsWith("HH")||p==="s"&&N.nozzle_id.startsWith("HS");return B&&I&&G}):[],[x?.profiles,l,d,p]),P=y?.filter(N=>N.is_active)||[];!t&&P.length>0&&e(P[0].id);const F=y?.find(N=>N.id===t)?.nozzle_count===2;return b?_.jsx("div",{className:"flex justify-center py-12",children:_.jsx(Hn,{className:"w-8 h-8 text-bambu-green animate-spin"})}):!y||y.length===0?_.jsx(_n,{children:_.jsxs(An,{className:"py-12 text-center",children:[_.jsx(Xu,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),_.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:"No Printers Configured"}),_.jsx("p",{className:"text-bambu-gray",children:"Add a printer in Settings to manage K-profiles"})]})}):P.length===0?_.jsx(_n,{children:_.jsxs(An,{className:"py-12 text-center",children:[_.jsx(ic,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),_.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:"No Active Printers"}),_.jsx("p",{className:"text-bambu-gray",children:"Enable a printer connection to view its K-profiles"})]})}):_.jsxs(_.Fragment,{children:[_.jsxs("div",{className:"flex flex-wrap gap-4 mb-6",children:[_.jsxs("div",{className:"flex-1 min-w-48",children:[_.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Printer"}),_.jsx("select",{value:t||"",onChange:N=>e(parseInt(N.target.value)),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:P.map(N=>_.jsx("option",{value:N.id,children:N.name},N.id))})]}),_.jsxs("div",{className:"w-32",children:[_.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Nozzle"}),_.jsxs("select",{value:n,onChange:N=>i(N.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[_.jsx("option",{value:"0.2",children:"0.2mm"}),_.jsx("option",{value:"0.4",children:"0.4mm"}),_.jsx("option",{value:"0.6",children:"0.6mm"}),_.jsx("option",{value:"0.8",children:"0.8mm"})]})]}),_.jsxs("div",{className:"flex items-end gap-2",children:[_.jsxs(mt,{variant:"secondary",onClick:()=>w(),disabled:g,children:[_.jsx(Ep,{className:`w-4 h-4 ${g?"animate-spin":""}`}),"Refresh"]}),_.jsxs(mt,{onClick:()=>o(!0),children:[_.jsx(ff,{className:"w-4 h-4"}),"Add Profile"]})]})]}),_.jsxs("div",{className:"flex flex-wrap gap-4 mb-6",children:[_.jsxs("div",{className:"flex-1 min-w-48 relative",children:[_.jsx(o_,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),_.jsx("input",{type:"text",value:l,onChange:N=>c(N.target.value),placeholder:"Search by name or filament...",className:"w-full pl-10 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none"})]}),F&&_.jsx("div",{className:"w-36",children:_.jsxs("select",{value:d,onChange:N=>f(N.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[_.jsx("option",{value:"all",children:"All Extruders"}),_.jsx("option",{value:"left",children:"Left Only"}),_.jsx("option",{value:"right",children:"Right Only"})]})}),_.jsx("div",{className:"w-32",children:_.jsxs("select",{value:p,onChange:N=>m(N.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[_.jsx("option",{value:"all",children:"All Flow"}),_.jsx("option",{value:"hf",children:"HF Only"}),_.jsx("option",{value:"s",children:"S Only"})]})})]}),g?_.jsx("div",{className:"flex justify-center py-12",children:_.jsx(Hn,{className:"w-8 h-8 text-bambu-green animate-spin"})}):E?_.jsx(_n,{children:_.jsxs(An,{className:"py-12 text-center",children:[_.jsx(gS,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),_.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:"Printer Offline"}),_.jsx("p",{className:"text-bambu-gray mb-4",children:"The selected printer is not connected. Power it on to view K-profiles."}),_.jsxs(mt,{variant:"secondary",onClick:()=>w(),children:[_.jsx(Ep,{className:"w-4 h-4"}),"Retry"]})]})}):A.length>0?F?_.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[_.jsxs("div",{children:[_.jsx("h3",{className:"text-sm font-medium text-bambu-gray mb-2 px-1",children:"Left Extruder"}),_.jsx("div",{className:"space-y-1",children:A.filter(N=>N.extruder_id===1).map(N=>_.jsx(C2,{profile:N,onEdit:()=>a(N)},N.slot_id))})]}),_.jsxs("div",{children:[_.jsx("h3",{className:"text-sm font-medium text-bambu-gray mb-2 px-1",children:"Right Extruder"}),_.jsx("div",{className:"space-y-1",children:A.filter(N=>N.extruder_id===0).map(N=>_.jsx(C2,{profile:N,onEdit:()=>a(N)},N.slot_id))})]})]}):_.jsx("div",{className:"space-y-1",children:A.map(N=>_.jsx(C2,{profile:N,onEdit:()=>a(N)},N.slot_id))}):l||d!=="all"||p!=="all"?_.jsx(_n,{children:_.jsxs(An,{className:"py-12 text-center",children:[_.jsx(o_,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),_.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:"No Matching Profiles"}),_.jsx("p",{className:"text-bambu-gray",children:"No profiles match your search criteria"})]})}):_.jsx(_n,{children:_.jsxs(An,{className:"py-12 text-center",children:[_.jsx(GN,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),_.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:"No K-Profiles"}),_.jsxs("p",{className:"text-bambu-gray mb-4",children:["No pressure advance profiles found for ",n,"mm nozzle"]}),_.jsxs(mt,{onClick:()=>o(!0),children:[_.jsx(ff,{className:"w-4 h-4"}),"Create First Profile"]})]})}),r&&t&&_.jsx(GV,{profile:r,printerId:t,nozzleDiameter:n,existingProfiles:x?.profiles,isDualNozzle:F,onClose:()=>a(null),onSave:()=>a(null)}),s&&t&&_.jsx(GV,{printerId:t,nozzleDiameter:n,existingProfiles:x?.profiles,isDualNozzle:F,onClose:()=>o(!1),onSave:()=>o(!1)})]})}function UHe({onSuccess:t}){const{showToast:e}=Jo(),[n,i]=T.useState("email"),[r,a]=T.useState(""),[s,o]=T.useState(""),[l,c]=T.useState(""),[d,f]=T.useState(""),[p,m]=T.useState("global"),y=hn({mutationFn:()=>dt.cloudLogin(r,s,p),onSuccess:w=>{w.success?(e("Logged in successfully"),t()):w.needs_verification?(e("Verification code sent to your email"),i("code")):e(w.message,"error")},onError:w=>{e(w.message,"error")}}),b=hn({mutationFn:()=>dt.cloudVerify(r,l),onSuccess:w=>{w.success?(e("Logged in successfully"),t()):e(w.message,"error")},onError:w=>{e(w.message,"error")}}),x=hn({mutationFn:()=>dt.cloudSetToken(d),onSuccess:()=>{e("Token set successfully"),t()},onError:w=>{e(w.message,"error")}}),g=w=>{w.preventDefault(),n==="email"?y.mutate():n==="code"?b.mutate():n==="token"&&x.mutate()},M=y.isPending||b.isPending||x.isPending;return _.jsxs(_n,{className:"max-w-md mx-auto",children:[_.jsx(Qh,{children:_.jsxs("div",{className:"flex items-center gap-2",children:[_.jsx(VN,{className:"w-5 h-5 text-bambu-green"}),_.jsx("h2",{className:"text-xl font-semibold text-white",children:"Connect to Bambu Cloud"})]})}),_.jsx(An,{children:_.jsxs("form",{onSubmit:g,className:"space-y-4",children:[n==="email"&&_.jsxs(_.Fragment,{children:[_.jsxs("div",{children:[_.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Email"}),_.jsx("input",{type:"email",value:r,onChange:w=>a(w.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",placeholder:"your@email.com",required:!0})]}),_.jsxs("div",{children:[_.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Password"}),_.jsx("input",{type:"password",value:s,onChange:w=>o(w.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",placeholder:"••••••••",required:!0})]}),_.jsxs("div",{children:[_.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Region"}),_.jsxs("select",{value:p,onChange:w=>m(w.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[_.jsx("option",{value:"global",children:"Global"}),_.jsx("option",{value:"china",children:"China"})]})]})]}),n==="code"&&_.jsxs("div",{children:[_.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Verification Code"}),_.jsxs("p",{className:"text-xs text-bambu-gray mb-2",children:["Check your email (",r,") for a 6-digit code"]}),_.jsx("input",{type:"text",value:l,onChange:w=>c(w.target.value.replace(/\D/g,"").slice(0,6)),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-center text-2xl tracking-widest focus:border-bambu-green focus:outline-none",placeholder:"000000",maxLength:6,required:!0})]}),n==="token"&&_.jsxs("div",{children:[_.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Access Token"}),_.jsx("p",{className:"text-xs text-bambu-gray mb-2",children:"Paste your Bambu Lab access token (from Bambu Studio)"}),_.jsx("textarea",{value:d,onChange:w=>f(w.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-xs font-mono focus:border-bambu-green focus:outline-none resize-none",placeholder:"eyJ...",rows:3,required:!0})]}),_.jsxs("div",{className:"flex gap-2",children:[n==="code"&&_.jsx(mt,{type:"button",variant:"secondary",onClick:()=>i("email"),className:"flex-1",children:"Back"}),_.jsxs(mt,{type:"submit",disabled:M,className:"flex-1",children:[M?_.jsx(Hn,{className:"w-4 h-4 animate-spin"}):_.jsx(R4,{className:"w-4 h-4"}),n==="email"?"Login":n==="code"?"Verify":"Set Token"]})]}),n==="email"&&_.jsx("div",{className:"pt-4 border-t border-bambu-dark-tertiary",children:_.jsxs("button",{type:"button",onClick:()=>i("token"),className:"text-sm text-bambu-gray hover:text-white flex items-center gap-1",children:[_.jsx(Qie,{className:"w-3 h-3"}),"Use access token instead"]})}),n==="token"&&_.jsx("div",{className:"pt-4 border-t border-bambu-dark-tertiary",children:_.jsxs("button",{type:"button",onClick:()=>i("email"),className:"text-sm text-bambu-gray hover:text-white flex items-center gap-1",children:[_.jsx(R4,{className:"w-3 h-3"}),"Login with email instead"]})})]})})]})}function FHe({setting:t,onClick:e}){return _.jsxs("button",{onClick:e,className:"w-full text-left p-3 bg-bambu-dark rounded-lg hover:bg-bambu-dark-tertiary transition-colors",children:[_.jsx("p",{className:"text-white font-medium truncate",children:t.name}),t.updated_time&&_.jsxs("p",{className:"text-xs text-bambu-gray mt-1",children:["Updated: ",new Date(t.updated_time).toLocaleDateString()]})]})}function zHe({setting:t,onClose:e}){const{data:n,isLoading:i}=vn({queryKey:["cloudSettingDetail",t.setting_id],queryFn:()=>dt.getCloudSettingDetail(t.setting_id)});return _.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:_.jsx(_n,{className:"w-full max-w-2xl max-h-[90vh] flex flex-col",children:_.jsxs(An,{className:"p-0 flex flex-col h-full",children:[_.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[_.jsxs("div",{children:[_.jsx("h2",{className:"text-xl font-semibold text-white",children:t.name}),_.jsxs("p",{className:"text-sm text-bambu-gray capitalize",children:[t.type," preset"]})]}),_.jsx("button",{onClick:e,className:"text-bambu-gray hover:text-white transition-colors",children:_.jsx(Vn,{className:"w-5 h-5"})})]}),_.jsx("div",{className:"flex-1 overflow-y-auto p-4",children:i?_.jsx("div",{className:"flex justify-center py-8",children:_.jsx(Hn,{className:"w-8 h-8 text-bambu-green animate-spin"})}):n?_.jsx("pre",{className:"text-xs text-bambu-gray font-mono whitespace-pre-wrap overflow-x-auto bg-bambu-dark p-4 rounded-lg",children:JSON.stringify(n,null,2)}):_.jsx("p",{className:"text-bambu-gray text-center py-8",children:"Failed to load preset details"})}),_.jsx("div",{className:"p-4 border-t border-bambu-dark-tertiary",children:_.jsx(mt,{variant:"secondary",onClick:e,className:"w-full",children:"Close"})})]})})})}function jHe({settings:t}){const[e,n]=T.useState(new Set),[i,r]=T.useState(null),a=l=>[...l].sort((c,d)=>c.name.localeCompare(d.name)),s=l=>{n(c=>{const d=new Set(c);return d.has(l)?d.delete(l):d.add(l),d})},o=[{key:"filament",label:"Filament Presets",icon:Sie,items:a(t.filament)},{key:"printer",label:"Printer Presets",icon:ic,items:a(t.printer)},{key:"process",label:"Process Presets",icon:CG,items:a(t.process)}];return _.jsxs(_.Fragment,{children:[_.jsx("div",{className:"space-y-4",children:o.map(({key:l,label:c,icon:d,items:f})=>_.jsxs(_n,{children:[_.jsxs("button",{onClick:()=>s(l),className:"w-full flex items-center justify-between p-4",children:[_.jsxs("div",{className:"flex items-center gap-3",children:[_.jsx(d,{className:"w-5 h-5 text-bambu-green"}),_.jsx("span",{className:"text-lg font-semibold text-white",children:c}),_.jsxs("span",{className:"text-sm text-bambu-gray",children:["(",f.length,")"]})]}),e.has(l)?_.jsx(sie,{className:"w-5 h-5 text-bambu-gray"}):_.jsx(Pf,{className:"w-5 h-5 text-bambu-gray"})]}),e.has(l)&&f.length>0&&_.jsx(An,{className:"pt-0",children:_.jsx("div",{className:"grid gap-2 sm:grid-cols-2 lg:grid-cols-3",children:f.map(p=>_.jsx(FHe,{setting:p,onClick:()=>r(p)},p.setting_id))})}),e.has(l)&&f.length===0&&_.jsx(An,{className:"pt-0",children:_.jsx("p",{className:"text-bambu-gray text-sm",children:"No presets found"})})]},l))}),i&&_.jsx(zHe,{setting:i,onClose:()=>r(null)})]})}function BHe(){const t=qi(),{showToast:e}=Jo(),[n,i]=T.useState("kprofiles"),{data:r,isLoading:a}=vn({queryKey:["cloudStatus"],queryFn:dt.getCloudStatus}),{data:s,isLoading:o,refetch:l}=vn({queryKey:["cloudSettings"],queryFn:()=>dt.getCloudSettings(),enabled:!!r?.is_authenticated,retry:!1,staleTime:1e3*60*5}),c=hn({mutationFn:dt.cloudLogout,onSuccess:()=>{t.invalidateQueries({queryKey:["cloudStatus"]}),t.removeQueries({queryKey:["cloudSettings"]}),e("Logged out")}}),d=()=>{t.invalidateQueries({queryKey:["cloudStatus"]})};return a?_.jsx("div",{className:"p-8 flex justify-center",children:_.jsx(Hn,{className:"w-8 h-8 text-bambu-green animate-spin"})}):_.jsxs("div",{className:"p-8",children:[_.jsxs("div",{className:"mb-6",children:[_.jsx("h1",{className:"text-2xl font-bold text-white",children:"Profiles"}),_.jsx("p",{className:"text-bambu-gray",children:"Manage your slicer presets and pressure advance calibrations"})]}),_.jsxs("div",{className:"flex border-b border-bambu-dark-tertiary mb-6",children:[_.jsxs("button",{onClick:()=>i("cloud"),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${n==="cloud"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-white border-transparent"}`,children:[_.jsx(VN,{className:"w-4 h-4"}),"Cloud Profiles"]}),_.jsxs("button",{onClick:()=>i("kprofiles"),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${n==="kprofiles"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-white border-transparent"}`,children:[_.jsx(GN,{className:"w-4 h-4"}),"K-Profiles"]})]}),n==="cloud"&&_.jsxs(_.Fragment,{children:[_.jsxs("div",{className:"mb-6 flex items-center justify-between",children:[_.jsx("p",{className:"text-bambu-gray",children:r?.is_authenticated?`Connected as ${r.email}`:"Connect to Bambu Cloud to access your slicer presets"}),r?.is_authenticated&&_.jsxs("div",{className:"flex gap-2",children:[_.jsxs(mt,{variant:"secondary",onClick:()=>l(),disabled:o,children:[_.jsx(Ep,{className:`w-4 h-4 ${o?"animate-spin":""}`}),"Refresh"]}),_.jsxs(mt,{variant:"secondary",onClick:()=>c.mutate(),disabled:c.isPending,children:[_.jsx(dre,{className:"w-4 h-4"}),"Logout"]})]})]}),r?.is_authenticated?o?_.jsx("div",{className:"flex justify-center py-12",children:_.jsx(Hn,{className:"w-8 h-8 text-bambu-green animate-spin"})}):s?_.jsx(jHe,{settings:s}):_.jsx(_n,{children:_.jsxs(An,{className:"py-8 text-center",children:[_.jsx("p",{className:"text-bambu-gray",children:"Failed to load profiles"}),_.jsx(mt,{className:"mt-4",onClick:()=>l(),children:"Retry"})]})}):_.jsx(UHe,{onSuccess:d})]}),n==="kprofiles"&&_.jsx(IHe,{})]})}function HHe(){const t=T.useRef(null),e=T.useRef(null),n=qi(),[i,r]=T.useState(!1),a=T.useCallback(()=>{if(t.current?.readyState===WebSocket.OPEN)return;const c=`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/api/v1/ws`,d=new WebSocket(c);let f=null;d.onopen=()=>{console.log("[WebSocket] Connected"),r(!0),f=window.setInterval(()=>{d.readyState===WebSocket.OPEN&&d.send(JSON.stringify({type:"ping"}))},3e4)},d.onmessage=p=>{try{const m=JSON.parse(p.data);s(m)}catch{}},d.onclose=p=>{console.log("[WebSocket] Closed",p.code,p.reason),f&&(clearInterval(f),f=null),r(!1),t.current=null,e.current=window.setTimeout(()=>{a()},3e3)},d.onerror=p=>{console.error("[WebSocket] Error",p),d.close()},t.current=d},[]),s=T.useCallback(l=>{switch(l.type){case"printer_status":l.printer_id!==void 0&&n.setQueryData(["printerStatus",l.printer_id],c=>({...c,...l.data}));break;case"print_complete":n.invalidateQueries({queryKey:["archives"]}),n.invalidateQueries({queryKey:["archiveStats"]});break;case"archive_created":n.invalidateQueries({queryKey:["archives"]}),n.invalidateQueries({queryKey:["archiveStats"]});break}},[n]);T.useEffect(()=>(a(),()=>{e.current&&clearTimeout(e.current),t.current&&t.current.close()}),[a]);const o=T.useCallback(l=>{t.current?.readyState===WebSocket.OPEN&&t.current.send(JSON.stringify(l))},[]);return{isConnected:i,sendMessage:o}}const VHe=new Sne({defaultOptions:{queries:{staleTime:1e3*60,retry:1}}});function GHe({children:t}){return HHe(),_.jsx(_.Fragment,{children:t})}function $He(){return _.jsx(Eae,{children:_.jsx(Lae,{children:_.jsx(wne,{client:VHe,children:_.jsx(GHe,{children:_.jsx(Gte,{children:_.jsx(_te,{children:_.jsxs(au,{path:"/",element:_.jsx(Dae,{}),children:[_.jsx(au,{index:!0,element:_.jsx(Zae,{})}),_.jsx(au,{path:"archives",element:_.jsx(MEe,{})}),_.jsx(au,{path:"queue",element:_.jsx(TEe,{})}),_.jsx(au,{path:"stats",element:_.jsx(NHe,{})}),_.jsx(au,{path:"profiles",element:_.jsx(BHe,{})}),_.jsx(au,{path:"settings",element:_.jsx(OHe,{})})]})})})})})})})}Tee.createRoot(document.getElementById("root")).render(_.jsx(T.StrictMode,{children:_.jsx($He,{})})); diff --git a/static/index.html b/static/index.html index cfb7c1e73..b287ce675 100644 --- a/static/index.html +++ b/static/index.html @@ -7,7 +7,7 @@ - +