Files
bambuddy/static/assets/InventoryPage-LSqoic6w.js
T

2 lines
214 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,n as i,r as a,t as o,v as s,w as c}from"./client-D0Q3EIO2.js";import{n as l}from"./QueryClientProvider-CsMjD-7g.js";import{t as u}from"./useQuery-DGJURrv0.js";import{t as d}from"./useMutation-D33XgzjB.js";import{t as f}from"./useQueries-pOASHEMB.js";import{t as p}from"./createLucideIcon-BTg337Gy.js";import{i as m,n as h,r as g}from"./haSensorDisplay-CLpndC52.js";import{t as _}from"./arrow-down--cYuQXi2.js";import{t as v}from"./arrow-up-down-MZZbOqYJ.js";import{t as y}from"./arrow-up-DAnOQUuf.js";import{i as b,n as x,r as S,t as C}from"./ReferenceLine-ytCyPKIK.js";import{t as w}from"./check-lecuNcPc.js";import{a as T,i as E,n as D,t as O}from"./info-CYfZ08vK.js";import{n as ee,t as k}from"./chevrons-right-BtGjiArF.js";import{n as te,r as A}from"./ToastContext-DvXi5snE.js";import{t as j}from"./columns-2-4ppMhNZX.js";import{t as M}from"./copy-BSydjjpn.js";import{t as N}from"./layout-grid-soOVnMEc.js";import{t as P}from"./link-2-DapXrb9r.js";import{t as F}from"./loader-circle-sObvdo_1.js";import{t as ne}from"./lock-DUp1b_h_.js";import{_ as I,c as L,g as re,h as R,s as ie,v as ae}from"./locationSensorDefaults-WfOsrPZS.js";import{t as oe}from"./package-C-zqQjgX.js";import{t as se}from"./search-C6Jj-J3M.js";import{t as z}from"./sparkles-BNpGSLu_.js";import{L as ce,Rn as le,Xt as ue,c as de,p as fe,s as pe}from"./CartesianChart-CkznuDC2.js";import{t as B}from"./triangle-alert-boCB5mQC.js";import{t as me}from"./unlink-CUrTAIsU.js";import{t as he}from"./x-B8rbip0P.js";import{t as V}from"./Button-BAwcIdV7.js";import{r as ge,v as H,y as _e}from"./date-G9KUauqz.js";import{n as ve}from"./filamentSwatchHelpers-D3oXQSGk.js";import{$t as ye,At as be,Cn as xe,Gt as Se,H as Ce,Jt as U,Kt as we,Ln as Te,Lt as Ee,Mn as De,On as Oe,Pt as ke,Rt as Ae,Tt as je,Ut as Me,Wn as Ne,Zt as Pe,_t as Fe,a as Ie,at as Le,bt as Re,cn as ze,en as Be,ft as Ve,i as He,jn as Ue,kn as We,kt as Ge,lt as Ke,o as qe,ot as Je,r as Ye,s as Xe,st as W,w as Ze,wn as Qe,xn as $e,yt as et,zt as tt}from"./index-C-0w3pwY.js";import{i as nt,r as rt}from"./slicerPrinterMatch-CUdoNag2.js";import{t as it}from"./ColumnConfigModal-C66OrmbM.js";import{n as at,t as ot}from"./AreaChart-5Jo0NTVy.js";import{a as st,i as ct,n as lt,o as ut,r as G,s as dt,t as ft}from"./AdditionalSection-CvIljGzG.js";import{_ as pt,a as K,b as mt,c as ht,d as gt,f as _t,g as vt,i as yt,l as bt,m as xt,n as St,o as Ct,r as wt,s as Tt,t as Et,u as Dt,v as Ot}from"./utils-ui-YAEyJ.js";import{t as kt}from"./AssignToAmsModal-DVH0AGlC.js";import{t as At}from"./inventorySearch-Ch1PI4QC.js";var q=p(`beaker`,[[`path`,{d:`M4.5 3h15`,key:`c7n0jr`}],[`path`,{d:`M6 3v16a2 2 0 0 0 2 2h8a2 2 0 0 0 2-2V3`,key:`m1uhx7`}],[`path`,{d:`M6 14h12`,key:`4cwo0f`}]]),jt=p(`chart-no-axes-column`,[[`path`,{d:`M5 21v-6`,key:`1hz6c0`}],[`path`,{d:`M12 21V3`,key:`1lcnhd`}],[`path`,{d:`M19 21V9`,key:`unv183`}]]),Mt=p(`credit-card`,[[`rect`,{width:`20`,height:`14`,x:`2`,y:`5`,rx:`2`,key:`ynyp8z`}],[`line`,{x1:`2`,x2:`22`,y1:`10`,y2:`10`,key:`1b3vmo`}]]),Nt=p(`group`,[[`path`,{d:`M3 7V5c0-1.1.9-2 2-2h2`,key:`adw53z`}],[`path`,{d:`M17 3h2c1.1 0 2 .9 2 2v2`,key:`an4l38`}],[`path`,{d:`M21 17v2c0 1.1-.9 2-2 2h-2`,key:`144t0e`}],[`path`,{d:`M7 21H5c-1.1 0-2-.9-2-2v-2`,key:`rtnfgi`}],[`rect`,{width:`7`,height:`5`,x:`7`,y:`7`,rx:`1`,key:`1eyiv7`}],[`rect`,{width:`7`,height:`5`,x:`10`,y:`12`,rx:`1`,key:`1qlmkx`}]]),Pt=p(`package-check`,[[`path`,{d:`m16 16 2 2 4-4`,key:`gfu2re`}],[`path`,{d:`M21 10V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l2-1.14`,key:`e7tb2h`}],[`path`,{d:`m7.5 4.27 9 5.15`,key:`1c824w`}],[`polyline`,{points:`3.29 7 12 12 20.71 7`,key:`ousv84`}],[`line`,{x1:`12`,x2:`12`,y1:`22`,y2:`12`,key:`a4e8g8`}]]),Ft=p(`store`,[[`path`,{d:`M15 21v-5a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v5`,key:`slp6dd`}],[`path`,{d:`M17.774 10.31a1.12 1.12 0 0 0-1.549 0 2.5 2.5 0 0 1-3.451 0 1.12 1.12 0 0 0-1.548 0 2.5 2.5 0 0 1-3.452 0 1.12 1.12 0 0 0-1.549 0 2.5 2.5 0 0 1-3.77-3.248l2.889-4.184A2 2 0 0 1 7 2h10a2 2 0 0 1 1.653.873l2.895 4.192a2.5 2.5 0 0 1-3.774 3.244`,key:`o0xfot`}],[`path`,{d:`M4 10.95V19a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-8.05`,key:`wn3emo`}]]),It=p(`table-properties`,[[`path`,{d:`M15 3v18`,key:`14nvp0`}],[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M21 9H3`,key:`1338ky`}],[`path`,{d:`M21 15H3`,key:`9uk58r`}]]),J=e(n(),1),Y=t(),Lt=1.65,Rt=[`#1DB954`,`#3B82F6`,`#F59E0B`,`#EF4444`,`#8B5CF6`];function X(e,t,n,r){return`${e}||${t??``}||${n??``}||${r??``}`}function Z(e,t){let n=new Date(e);return n.setDate(n.getDate()+Math.round(t)),n}function zt(e){return e.toLocaleDateString(void 0,{month:`short`,day:`numeric`,year:`numeric`})}function Bt(e){return e.toLocaleDateString(void 0,{month:`short`,day:`numeric`})}function Vt(e){if(e.length<2)return null;let t=new Map;for(let n of e){let e=n.created_at.slice(0,10);t.set(e,(t.get(e)??0)+n.weight_used)}if(t.size<2)return null;let n=[...t.entries()].map(([e,t])=>({ms:new Date(e).getTime(),totalG:t})).sort((e,t)=>e.ms-t.ms),r=Date.now(),i=Math.LN2/30,a=[];for(let e=1;e<n.length;e++){let t=Math.max((n[e].ms-n[e-1].ms)/864e5,1),o=(r-n[e].ms)/864e5,s=n[e].totalG/t,c=Math.exp(-i*o);a.push({rate:s,weight:c})}let o=a.reduce((e,t)=>e+t.weight,0);if(o===0)return null;let s=a.reduce((e,t)=>e+t.rate*t.weight,0)/o,c=a.reduce((e,t)=>e+t.weight*(t.rate-s)**2,0)/o;return{rate:s,stdDev:Math.sqrt(c)}}function Ht(e){let t=e.reduce((e,t)=>e+Math.max(0,t.weight_used-(t.weight_used_baseline??0)),0);if(t===0)return null;let n=Date.now(),r=(n-e.reduce((e,t)=>{let n=new Date(t.created_at).getTime();return n<e?n:e},n))/864e5;return r<1?null:t/r}function Ut(e,t=60){if(e.dailyRateG===null)return[];let n=e.dailyRateG,r=[];for(let i=0;i<=t;i++){let t=Math.max(0,e.totalRemainingG-n*i);if(r.push({day:i,label:Bt(Z(new Date,i)),stock:Math.round(t),rop:Math.round(e.reorderPointG)}),t===0)break}return r}function Wt({spools:e}){let t=l(),{showToast:n}=te(),{t:i}=c(),{hasPermission:a,hasAnyPermission:o}=et(),s=a(`inventory:forecast_read`),d=o(`inventory:forecast_write`,`inventory:update`),[f,p]=(0,J.useState)(!1),[m,h]=(0,J.useState)(`material`),[g,_]=(0,J.useState)(`asc`),[v,y]=(0,J.useState)(``),[b,x]=(0,J.useState)(``),[S,C]=(0,J.useState)(null),[w,D]=(0,J.useState)(!1),[O,ee]=(0,J.useState)(30),{data:k}=u({queryKey:[`settings`],queryFn:r.getSettings,enabled:s}),{data:A=[]}=u({queryKey:[`sku-settings`],queryFn:r.getSkuSettings,staleTime:6e4,enabled:s}),{data:j=[]}=u({queryKey:[`all-usage-history-forecast`],queryFn:()=>r.getAllUsageHistory(5e3),staleTime:6e4,enabled:s}),{data:M=[]}=u({queryKey:[`shopping-list`],queryFn:r.getShoppingList,staleTime:3e4,enabled:s}),N=k?.forecast_global_lead_time_days??0,P=(0,J.useMemo)(()=>{let e=new Map;for(let t of A)e.set(X(t.material,t.subtype,t.brand,t.color_name),t);return e},[A]),F=(0,J.useMemo)(()=>{let e=new Map;for(let t of j){let n=e.get(t.spool_id)??[];n.push(t),e.set(t.spool_id,n)}return e},[j]),I=(0,J.useMemo)(()=>{let t=new Map;for(let n of e){if(n.archived_at)continue;let e=X(n.material,n.subtype,n.brand,n.color_name),r=t.get(e)??{key:e,material:n.material,subtype:n.subtype,brand:n.brand,colorName:n.color_name,spools:[]};r.spools.push(n),t.set(e,r)}return[...t.values()]},[e]),L=(0,J.useMemo)(()=>{let e=new Date;return e.setHours(0,0,0,0),I.map(t=>{let n=P.get(t.key)??(t.colorName===null?null:P.get(X(t.material,t.subtype,t.brand,null))??null),r=n?.lead_time_days??0,i=Math.max(N,r),a=n?.safety_margin_value??14,o=n?.safety_margin_unit??`days`,s=t.spools.reduce((e,t)=>e+Math.max(0,t.label_weight-t.weight_used),0),c=t.spools.reduce((e,t)=>e+t.label_weight,0),l=t.spools.reduce((e,t)=>e+Math.max(0,t.weight_used-(t.weight_used_baseline??0)),0),u=[];for(let e of t.spools)(e.weight_used_baseline??0)===0&&u.push(...F.get(e.id)??[]);let d=null,f=null,p=`none`,m=Vt(u);if(m!==null)d=m.rate,f=m.stdDev,p=`history`;else{let e=Ht(t.spools);e!==null&&(d=e,p=`delta`)}let h=Lt*(f??(d===null?0:d*.2))*Math.sqrt(i)+(o===`g`?a:d===null?a*5:d*a),g=d===null?0:d*i+h,_=d&&d>0?Math.floor(s/d):null,v=_===null?null:Z(e,_),y=d&&d>0?Math.floor((s-g)/d):null,b=y===null?null:Z(e,Math.max(0,y)),x=_!==null&&i>0&&_<=i,S=!x&&y!==null&&y<=0;return{group:t,settings:n,totalRemainingG:s,totalLabelG:c,totalSpools:t.spools.length,totalUsedG:l,dailyRateG:d,dailyRateStdDev:f,rateTier:p,effectiveLeadTimeDays:i,safetyStockG:h,reorderPointG:g,daysRemaining:_,daysUntilROP:y,projectedEmptyDate:v,reorderTriggerDate:b,reorderAlert:S,stockBreakAlert:x}})},[I,P,F,N]),re=(0,J.useMemo)(()=>[...new Set(I.map(e=>e.material))].sort(),[I]),R=(0,J.useMemo)(()=>[...new Set(I.map(e=>e.brand).filter(Boolean))].sort(),[I]),ie=(0,J.useMemo)(()=>{let e=[...L];return v&&(e=e.filter(e=>e.group.material===v)),b&&(e=e.filter(e=>e.group.brand===b)),e.sort((e,t)=>{let n=0,r=0;switch(m){case`material`:n=[e.group.material,e.group.subtype??``,e.group.brand??``].join(` `).toLowerCase(),r=[t.group.material,t.group.subtype??``,t.group.brand??``].join(` `).toLowerCase();break;case`used`:n=e.totalUsedG,r=t.totalUsedG;break;case`days_left`:n=e.daysRemaining??999999,r=t.daysRemaining??999999;break;case`stock`:n=e.totalRemainingG,r=t.totalRemainingG;break}let i=n<r?-1:+(n>r);return g===`asc`?i:-i}),e},[L,m,g,v,b]),ae=(0,J.useMemo)(()=>L.filter(e=>!e.settings?.alerts_snoozed&&(e.stockBreakAlert||e.reorderAlert)),[L]),oe=(0,J.useMemo)(()=>[...L].filter(e=>e.dailyRateG!==null).sort((e,t)=>t.totalUsedG-e.totalUsedG).slice(0,5),[L]);if(!s)return(0,Y.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-16 text-bambu-gray gap-3`,children:[(0,Y.jsx)(ne,{className:`w-8 h-8 opacity-40`}),(0,Y.jsx)(`p`,{className:`text-sm`,children:i(`forecast.noReadAccess`)})]});function se(e){m===e?_(e=>e===`asc`?`desc`:`asc`):(h(e),_(e===`days_left`?`asc`:`desc`))}let z=M.length>0?M.length:null;return(0,Y.jsxs)(`div`,{className:`space-y-5`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[ae.length>0&&(0,Y.jsxs)(`button`,{onClick:()=>p(e=>!e),className:`flex items-center gap-2 px-3 py-1.5 rounded-lg border text-sm font-medium transition-colors ${ae.some(e=>e.stockBreakAlert)?`bg-red-100 dark:bg-red-500/15 border-red-300 dark:border-red-500/30 text-red-700 dark:text-red-300 hover:bg-red-200 dark:hover:bg-red-500/25`:`bg-yellow-100 dark:bg-yellow-500/15 border-yellow-300 dark:border-yellow-500/30 text-yellow-700 dark:text-yellow-300 hover:bg-yellow-200 dark:hover:bg-yellow-500/25`}`,children:[(0,Y.jsx)(B,{className:`w-4 h-4`}),i(`forecast.alertCount`,{count:ae.length}),f?(0,Y.jsx)(E,{className:`w-3.5 h-3.5`}):(0,Y.jsx)(T,{className:`w-3.5 h-3.5`})]}),d&&(0,Y.jsx)(Yt,{value:N,onSave:e=>{r.updateSettings({forecast_global_lead_time_days:e}).then(()=>{t.invalidateQueries({queryKey:[`settings`]}),n(i(`forecast.globalLeadTimeSaved`),`success`)})}}),(0,Y.jsxs)(`select`,{value:v,onChange:e=>y(e.target.value),className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${v?`bg-bambu-green/20 text-bambu-green border-bambu-green/30`:`bg-transparent text-bambu-gray border-bambu-dark-tertiary hover:bg-bambu-dark-tertiary`}`,children:[(0,Y.jsx)(`option`,{value:``,children:i(`inventory.material`)}),re.map(e=>(0,Y.jsx)(`option`,{value:e,children:e},e))]}),(0,Y.jsxs)(`select`,{value:b,onChange:e=>x(e.target.value),className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${b?`bg-bambu-green/20 text-bambu-green border-bambu-green/30`:`bg-transparent text-bambu-gray border-bambu-dark-tertiary hover:bg-bambu-dark-tertiary`}`,children:[(0,Y.jsx)(`option`,{value:``,children:i(`inventory.brand`)}),R.map(e=>(0,Y.jsx)(`option`,{value:e,children:e},e))]}),(0,Y.jsxs)(`button`,{onClick:()=>D(e=>!e),className:`relative flex items-center gap-2 px-3 py-1.5 rounded-lg border border-bambu-dark-tertiary text-bambu-gray hover:bg-bambu-dark-tertiary text-sm transition-colors ml-auto`,children:[(0,Y.jsx)(tt,{className:`w-4 h-4`}),(0,Y.jsx)(`span`,{className:`hidden sm:inline`,children:i(`forecast.shoppingList`)}),z&&(0,Y.jsx)(`span`,{className:`absolute -top-1.5 -right-1.5 w-4 h-4 rounded-full bg-bambu-green text-white text-[10px] font-bold flex items-center justify-center`,children:z})]})]}),f&&ae.length>0&&(0,Y.jsx)(`div`,{className:`space-y-2`,children:ae.map(e=>(0,Y.jsx)(Kt,{forecast:e,onCart:()=>C(e)},e.group.key))}),w&&(0,Y.jsx)(en,{items:M,forecasts:L,globalLeadTime:N,canWrite:d,onClose:()=>D(!1),onRemove:e=>{r.removeFromShoppingList(e).then(()=>t.invalidateQueries({queryKey:[`shopping-list`]})).catch(()=>n(i(`forecast.failedSaveSettings`),`error`))},onClear:()=>{r.clearShoppingList().then(()=>t.invalidateQueries({queryKey:[`shopping-list`]})).catch(()=>n(i(`forecast.failedSaveSettings`),`error`))}}),oe.length>0&&(0,Y.jsx)(Jt,{forecasts:oe,days:O,onDaysChange:ee}),L.length===0?(0,Y.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-16 text-bambu-gray`,children:[(0,Y.jsx)(le,{className:`w-10 h-10 mb-3 opacity-40`}),(0,Y.jsx)(`p`,{className:`text-sm`,children:i(`forecast.noSpools`)})]}):(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg overflow-hidden border border-bambu-dark-tertiary`,children:[(0,Y.jsx)(`div`,{className:`overflow-x-auto`,children:(0,Y.jsxs)(`table`,{className:`w-full`,children:[(0,Y.jsx)(`thead`,{children:(0,Y.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary bg-bambu-dark-tertiary/30`,children:[(0,Y.jsx)(`th`,{className:`w-8 px-4 py-3`}),(0,Y.jsx)(Gt,{col:`material`,active:m,dir:g,onSort:se,children:i(`forecast.sku`)}),(0,Y.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:i(`locations.spools`)}),(0,Y.jsx)(Gt,{col:`stock`,active:m,dir:g,onSort:se,children:i(`forecast.stock`)}),(0,Y.jsx)(Gt,{col:`used`,active:m,dir:g,onSort:se,children:i(`forecast.dailyRate`)}),(0,Y.jsx)(Gt,{col:`days_left`,active:m,dir:g,onSort:se,children:i(`forecast.daysLeft`)}),(0,Y.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:i(`forecast.emptyBy`)}),(0,Y.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:i(`forecast.reorderBy`)}),(0,Y.jsx)(`th`,{className:`w-24 px-4 py-3`})]})}),(0,Y.jsx)(`tbody`,{className:`divide-y divide-bambu-dark-tertiary`,children:ie.map(e=>(0,Y.jsx)(Xt,{forecast:e,globalLeadTime:N,canWrite:d,onSaved:()=>t.invalidateQueries({queryKey:[`sku-settings`]}),onCart:()=>C(e),showToast:n},e.group.key))})]})}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4 px-4 py-3 text-xs text-bambu-gray border-t border-bambu-dark-tertiary bg-bambu-dark-tertiary/20`,children:[(0,Y.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-bambu-green inline-block`}),i(`forecast.trendLegend`)]}),(0,Y.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-blue-400 inline-block`}),i(`forecast.estimatedLegend`)]}),(0,Y.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-bambu-gray/40 inline-block`}),i(`forecast.noDataLegend`)]})]})]}),S&&(0,Y.jsx)(nn,{forecast:S,onClose:()=>C(null),onAdd:e=>{r.addToShoppingList(e).then(()=>{t.invalidateQueries({queryKey:[`shopping-list`]}),n(i(`forecast.addedToCart`),`success`),C(null),D(!0)}).catch(()=>n(i(`forecast.failedAddItem`),`error`))}})]})}function Gt({col:e,active:t,dir:n,onSort:r,children:i}){return(0,Y.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide cursor-pointer select-none hover:text-white transition-colors`,onClick:()=>r(e),children:(0,Y.jsxs)(`span`,{className:`inline-flex items-center`,children:[i,t===e?n===`asc`?(0,Y.jsx)(y,{className:`w-3 h-3 ml-1 text-bambu-green`}):(0,Y.jsx)(_,{className:`w-3 h-3 ml-1 text-bambu-green`}):(0,Y.jsx)(v,{className:`w-3 h-3 ml-1 opacity-40`})]})})}function Kt({forecast:e,onCart:t}){let{t:n}=c(),r=[e.group.brand,e.group.material,e.group.subtype,e.group.colorName].filter(Boolean).join(` `),i=e.stockBreakAlert;return(0,Y.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-3 rounded-lg border text-sm ${i?`bg-red-50 dark:bg-red-500/10 border-red-300 dark:border-red-500/30 text-red-700 dark:text-red-300`:`bg-yellow-50 dark:bg-yellow-500/10 border-yellow-300 dark:border-yellow-500/30 text-yellow-700 dark:text-yellow-300`}`,children:[(0,Y.jsx)(B,{className:`w-4 h-4 flex-shrink-0`}),(0,Y.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Y.jsx)(`span`,{className:`font-medium`,children:r}),i?(0,Y.jsxs)(`span`,{className:`ml-2 text-xs opacity-80`,children:[n(`forecast.stockBreakRisk`),` — `,n(`forecast.stockBreakDetail`,{days:e.daysRemaining,lt:e.effectiveLeadTimeDays})]}):(0,Y.jsxs)(`span`,{className:`ml-2 text-xs opacity-80`,children:[n(`forecast.reorderNow`),` — `,n(`forecast.reorderTriggerPassed`,{date:e.reorderTriggerDate?zt(e.reorderTriggerDate):`—`})]})]}),(0,Y.jsxs)(`button`,{onClick:t,className:`flex items-center gap-1.5 px-2.5 py-1 rounded border border-current text-xs opacity-70 hover:opacity-100 transition-opacity`,children:[(0,Y.jsx)(tt,{className:`w-3 h-3`}),` `,n(`forecast.order`)]})]})}var qt=[{label:`1W`,value:7},{label:`1M`,value:30},{label:`6M`,value:180}];function Jt({forecasts:e,days:t,onDaysChange:n}){let{t:r}=c(),i=Array.from({length:t+1},(e,t)=>t),a=e.map((e,n)=>({key:e.group.key,label:[e.group.brand,e.group.material,e.group.subtype,e.group.colorName].filter(Boolean).join(` `),color:Rt[n%Rt.length],rop:e.reorderPointG,points:Ut(e,t)})),o=i.map(e=>{let t={day:e,label:Bt(Z(new Date,e))};for(let n of a){let r=n.points.find(t=>t.day===e);t[n.key]=r?.stock??0}return t}),s=(()=>{for(let e=t;e>=0;e--)if(a.some(t=>o[e]?.[t.key]>0))return e;return t})(),l=o.slice(0,s+1),u=a.filter(e=>e.rop>0);return(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg overflow-hidden border border-bambu-dark-tertiary p-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 mb-4`,children:[(0,Y.jsx)(le,{className:`w-4 h-4 text-bambu-green`}),(0,Y.jsx)(`h3`,{className:`text-sm font-semibold text-white`,children:r(`forecast.chartTitle`)}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray ml-1 hidden sm:inline`,children:r(`forecast.dashedLinesROP`)}),(0,Y.jsx)(`div`,{className:`ml-auto flex items-center bg-bambu-dark-tertiary rounded-lg p-0.5`,children:qt.map(e=>(0,Y.jsx)(`button`,{onClick:()=>n(e.value),className:`px-2.5 py-1 text-xs font-medium rounded-md transition-colors ${t===e.value?`bg-bambu-dark-secondary text-white shadow`:`text-bambu-gray hover:text-white`}`,children:e.label},e.value))})]}),(0,Y.jsx)(ue,{width:`100%`,height:220,children:(0,Y.jsxs)(ot,{data:l,margin:{top:4,right:8,bottom:0,left:0},children:[(0,Y.jsx)(`defs`,{children:a.map(e=>(0,Y.jsxs)(`linearGradient`,{id:`grad-${e.key}`,x1:`0`,y1:`0`,x2:`0`,y2:`1`,children:[(0,Y.jsx)(`stop`,{offset:`5%`,stopColor:e.color,stopOpacity:.25}),(0,Y.jsx)(`stop`,{offset:`95%`,stopColor:e.color,stopOpacity:.02})]},e.key))}),(0,Y.jsx)(fe,{strokeDasharray:`3 3`,stroke:`#374151`,strokeOpacity:.5}),(0,Y.jsx)(de,{dataKey:`label`,tick:{fill:`#6B7280`,fontSize:10},interval:Math.max(0,Math.ceil(s/8)-1),axisLine:!1,tickLine:!1}),(0,Y.jsx)(pe,{tick:{fill:`#6B7280`,fontSize:10},axisLine:!1,tickLine:!1,tickFormatter:e=>e>=1e3?`${(e/1e3).toFixed(1)}kg`:`${e}g`,width:48}),(0,Y.jsx)(ce,{content:({label:e,payload:t})=>t?.length?(0,Y.jsxs)(`div`,{style:{background:`#1a1a2e`,border:`1px solid #374151`,borderRadius:8,fontSize:12,padding:`8px 12px`},children:[(0,Y.jsx)(`div`,{style:{color:`#9CA3AF`,marginBottom:6},children:e}),t.map(e=>{let t=a.find(t=>t.key===String(e.dataKey));return typeof e.value==`number`?(0,Y.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:6,color:`#E5E7EB`,marginBottom:2},children:[(0,Y.jsx)(`span`,{style:{color:t?.color??`#9CA3AF`,fontSize:10},children:`●`}),(0,Y.jsx)(`span`,{children:t?.label??String(e.dataKey)}),(0,Y.jsxs)(`span`,{style:{color:`#9CA3AF`,marginLeft:4},children:[e.value,`g`]})]},String(e.dataKey)):null})]}):null}),(0,Y.jsx)(x,{formatter:e=>(0,Y.jsx)(`span`,{style:{color:`#9CA3AF`,fontSize:11},children:a.find(t=>t.key===e)?.label??e})}),a.map(e=>(0,Y.jsx)(at,{type:`monotone`,dataKey:e.key,stroke:e.color,strokeWidth:2,fill:`url(#grad-${e.key})`,dot:!1,activeDot:{r:3}},e.key)),u.map(e=>(0,Y.jsx)(C,{y:e.rop,stroke:e.color,strokeDasharray:`4 3`,strokeOpacity:.6},`rop-${e.key}`))]})})]})}function Yt({value:e,onSave:t}){let{t:n}=c(),[r,i]=(0,J.useState)(!1),[a,o]=(0,J.useState)(String(e));function s(){let e=parseInt(a,10);isNaN(e)||e<0||(t(e),i(!1))}return(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-1.5 bg-bambu-dark-tertiary/40 rounded-lg border border-bambu-dark-tertiary text-xs text-bambu-gray`,children:[(0,Y.jsx)(O,{className:`w-3.5 h-3.5 flex-shrink-0`,"aria-label":n(`forecast.globalLeadTimeHint`)}),(0,Y.jsxs)(`span`,{className:`hidden sm:inline`,children:[n(`forecast.globalLeadTime`),`:`]}),r?(0,Y.jsxs)(`form`,{className:`flex items-center gap-1.5`,onSubmit:e=>{e.preventDefault(),s()},children:[(0,Y.jsx)(`input`,{type:`number`,min:0,max:365,value:a,onChange:e=>o(e.target.value),className:`w-14 px-1.5 py-0.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-sm text-white focus:outline-none focus:border-bambu-green`,autoFocus:!0}),(0,Y.jsx)(`span`,{className:`text-bambu-gray`,children:`d`}),(0,Y.jsx)(`button`,{type:`submit`,className:`px-2 py-0.5 bg-bambu-green text-white text-xs rounded hover:bg-bambu-green/80`,children:n(`forecast.save`)}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>i(!1),className:`text-xs text-bambu-gray hover:text-white`,children:`✕`})]}):(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsxs)(`span`,{className:`font-semibold text-white`,children:[e,`d`]}),(0,Y.jsx)(`button`,{onClick:()=>{o(String(e)),i(!0)},className:`p-0.5 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,Y.jsx)(I,{className:`w-3 h-3`})})]})]})}function Xt({forecast:e,globalLeadTime:t,canWrite:n,onSaved:i,onCart:a,showToast:o}){let{t:s}=c(),[l,u]=(0,J.useState)(!1),[f,p]=(0,J.useState)(!1),[m,h]=(0,J.useState)(!1),[g,_]=(0,J.useState)(String(e.settings?.lead_time_days??0)),[v,y]=(0,J.useState)(String(e.settings?.safety_margin_value??14)),[x,S]=(0,J.useState)(e.settings?.safety_margin_unit??`days`);(0,J.useEffect)(()=>{f||_(String(e.settings?.lead_time_days??0))},[e.settings?.lead_time_days,f]),(0,J.useEffect)(()=>{m||(y(String(e.settings?.safety_margin_value??14)),S(e.settings?.safety_margin_unit??`days`))},[e.settings?.safety_margin_value,e.settings?.safety_margin_unit,m]);let C=d({mutationFn:r.upsertSkuSettings,onSuccess:()=>{i(),o(s(`forecast.settingsSaved`),`success`)},onError:()=>o(s(`forecast.failedSaveSettings`),`error`)}),D=e.settings?.alerts_snoozed??!1,O=[e.group.brand,e.group.material,e.group.subtype,e.group.colorName].filter(Boolean).join(` `),ee=e.group.spools[0]?.rgba?Ke(e.group.spools[0].rgba):{backgroundColor:`#4B5563`},k=e.totalLabelG>0?Math.round(e.totalRemainingG/e.totalLabelG*100):0,te=D||e.daysRemaining===null?`text-bambu-gray`:e.stockBreakAlert?`text-red-700 dark:text-red-400`:e.reorderAlert||e.daysRemaining<30?`text-yellow-700 dark:text-yellow-400`:`text-green-700 dark:text-green-400`;function A(t,n,r,i=D){C.mutate({material:e.group.material,subtype:e.group.subtype,brand:e.group.brand,color_name:e.group.colorName,lead_time_days:t,safety_margin_value:n,safety_margin_unit:r,alerts_snoozed:i})}function j(t){t.stopPropagation(),A(e.settings?.lead_time_days??0,e.settings?.safety_margin_value??14,e.settings?.safety_margin_unit??`days`,!D)}let M=e.rateTier===`history`?(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-xs px-1.5 py-0.5 rounded bg-bambu-green/15 text-bambu-green`,children:[(0,Y.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-bambu-green`}),s(`forecast.trend`)]}):e.rateTier===`delta`?(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-xs px-1.5 py-0.5 rounded bg-blue-100 dark:bg-blue-400/15 text-blue-700 dark:text-blue-400`,children:[(0,Y.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-blue-400`}),s(`forecast.estimated`)]}):(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-xs px-1.5 py-0.5 rounded bg-bambu-dark-tertiary text-bambu-gray/60`,children:[(0,Y.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-bambu-gray/40`}),s(`forecast.noData`)]});return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/50 cursor-pointer hover:bg-bambu-dark-tertiary/30 transition-colors ${D?``:e.stockBreakAlert?`bg-red-500/5`:e.reorderAlert?`bg-yellow-500/5`:``} ${D?`opacity-50`:``}`,onClick:()=>u(e=>!e),children:[(0,Y.jsx)(`td`,{className:`px-4 py-3`,children:(0,Y.jsx)(`span`,{className:`block w-5 h-5 rounded-full border border-black/20`,style:ee})}),(0,Y.jsx)(`td`,{className:`px-4 py-3`,children:(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:O})}),(0,Y.jsx)(`td`,{className:`px-4 py-3`,children:(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.totalSpools})}),(0,Y.jsx)(`td`,{className:`px-4 py-3 min-w-[140px]`,children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`div`,{className:`flex-1 h-2 bg-bambu-dark-tertiary rounded-full overflow-hidden`,children:(0,Y.jsx)(`div`,{className:`h-full rounded-full ${k>50?`bg-bambu-green`:k>20?`bg-yellow-500`:`bg-red-500`}`,style:{width:`${Math.min(k,100)}%`}})}),(0,Y.jsxs)(`span`,{className:`text-xs text-bambu-gray min-w-[40px] text-right`,children:[Math.round(e.totalRemainingG),`g`]})]})}),(0,Y.jsx)(`td`,{className:`px-4 py-3`,children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 flex-wrap`,children:[(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:e.dailyRateG===null?`—`:`${e.dailyRateG.toFixed(1)}g/d`}),M]})}),(0,Y.jsx)(`td`,{className:`px-4 py-3`,children:(0,Y.jsx)(`span`,{className:`text-sm font-semibold ${te}`,children:e.daysRemaining===null?(0,Y.jsx)(`span`,{className:`text-bambu-gray font-normal`,children:`—`}):`${e.daysRemaining}d`})}),(0,Y.jsx)(`td`,{className:`px-4 py-3`,children:(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.projectedEmptyDate?zt(e.projectedEmptyDate):`—`})}),(0,Y.jsx)(`td`,{className:`px-4 py-3`,children:(0,Y.jsx)(`span`,{className:`text-sm ${!D&&e.reorderAlert?`text-yellow-700 dark:text-yellow-400`:`text-bambu-gray`}`,children:e.reorderTriggerDate?zt(e.reorderTriggerDate):`—`})}),(0,Y.jsx)(`td`,{className:`px-4 py-3`,onClick:e=>e.stopPropagation(),children:(0,Y.jsxs)(`div`,{className:`flex items-center justify-end gap-1`,children:[n&&(0,Y.jsx)(`button`,{onClick:a,className:`p-1.5 text-bambu-gray hover:text-bambu-green rounded transition-colors`,title:s(`forecast.addToCart`),children:(0,Y.jsx)(tt,{className:`w-4 h-4`})}),!D&&(e.stockBreakAlert?(0,Y.jsx)(B,{className:`w-4 h-4 text-red-600 dark:text-red-400`,"aria-label":s(`forecast.stockBreakRisk`)}):e.reorderAlert?(0,Y.jsx)(B,{className:`w-4 h-4 text-yellow-600 dark:text-yellow-400`,"aria-label":s(`forecast.reorderNow`)}):e.daysRemaining===null?null:(0,Y.jsx)(w,{className:`w-4 h-4 text-bambu-green/50`})),n&&(0,Y.jsx)(`button`,{onClick:j,className:`p-1 rounded transition-colors ${D?`text-amber-600/80 dark:text-amber-400/80 hover:text-amber-700 dark:hover:text-amber-300`:`text-slate-400 hover:text-white`}`,title:s(D?`forecast.alertsEnabled`:`forecast.alertsSnoozed`),children:(0,Y.jsx)(b,{className:`w-3.5 h-3.5`})}),(0,Y.jsx)(`button`,{onClick:e=>{e.stopPropagation(),u(e=>!e)},className:`p-1.5 text-bambu-gray hover:text-white rounded transition-colors`,children:l?(0,Y.jsx)(E,{className:`w-4 h-4`}):(0,Y.jsx)(T,{className:`w-4 h-4`})})]})})]}),l&&(0,Y.jsx)(`tr`,{className:`bg-bambu-dark-tertiary/10`,children:(0,Y.jsx)(`td`,{colSpan:9,className:`px-6 py-4`,children:(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsxs)(`div`,{className:`grid gap-2 ${n?`grid-cols-2 sm:grid-cols-4`:`grid-cols-2`}`,children:[(0,Y.jsx)(Zt,{label:s(`forecast.effectiveLeadTime`),value:`${e.effectiveLeadTimeDays}d`,hint:s(`forecast.effectiveLeadTimeHint`,{global:t,sku:e.settings?.lead_time_days??0})}),(0,Y.jsx)(Zt,{label:s(`forecast.reorderPoint`),value:`${Math.round(e.reorderPointG)}g`,hint:s(`forecast.reorderPointHint`)}),n&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(Qt,{label:s(`forecast.skuLeadTimeOverride`),hint:s(`forecast.skuLeadTimeHint`),unit:s(`forecast.leadTime`),editing:f,value:e.settings?.lead_time_days??0,inputValue:g,onInputChange:_,onEdit:()=>{_(String(e.settings?.lead_time_days??0)),p(!0)},onSave:()=>{let t=parseInt(g,10);!isNaN(t)&&t>=0&&(A(t,e.settings?.safety_margin_value??14,x),p(!1))},onCancel:()=>p(!1),isPending:C.isPending,saveLabel:s(`forecast.save`),cancelLabel:s(`forecast.cancel`)}),(0,Y.jsx)($t,{value:e.settings?.safety_margin_value??14,unit:x,editing:m,inputValue:v,dailyRateG:e.dailyRateG,onInputChange:y,onUnitChange:e=>S(e),onEdit:()=>{y(String(e.settings?.safety_margin_value??14)),S(e.settings?.safety_margin_unit??`days`),h(!0)},onSave:()=>{let t=parseInt(v,10);!isNaN(t)&&t>=0&&(A(e.settings?.lead_time_days??0,t,x),h(!1))},onCancel:()=>h(!1),isPending:C.isPending,saveLabel:s(`forecast.save`),cancelLabel:s(`forecast.cancel`),safetyMarginLabel:s(`forecast.safetyMarginLabel`)})]})]}),e.group.spools.length>1&&(0,Y.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary pt-3`,children:[(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:s(`forecast.individualSpools`)}),(0,Y.jsx)(`div`,{className:`bg-bambu-dark-secondary rounded-lg overflow-hidden border border-bambu-dark-tertiary`,children:(0,Y.jsxs)(`table`,{className:`w-full`,children:[(0,Y.jsx)(`thead`,{children:(0,Y.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary bg-bambu-dark-tertiary/30`,children:[(0,Y.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:`#`}),(0,Y.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:s(`inventory.remaining`)}),(0,Y.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:s(`inventory.used`)}),(0,Y.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:s(`forecast.labelWeight`)})]})}),(0,Y.jsx)(`tbody`,{className:`divide-y divide-bambu-dark-tertiary`,children:e.group.spools.map(e=>{let t=Math.max(0,e.label_weight-e.weight_used),n=e.label_weight>0?t/e.label_weight*100:0;return(0,Y.jsxs)(`tr`,{className:`hover:bg-bambu-dark-tertiary/30 transition-colors`,children:[(0,Y.jsx)(`td`,{className:`px-4 py-2`,children:(0,Y.jsxs)(`span`,{className:`text-xs font-mono text-bambu-gray/70`,children:[`#`,e.id]})}),(0,Y.jsx)(`td`,{className:`px-4 py-2`,children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Y.jsx)(`div`,{className:`w-24 h-1.5 bg-bambu-dark-tertiary rounded-full overflow-hidden flex-shrink-0`,children:(0,Y.jsx)(`div`,{className:`h-full rounded-full ${n>50?`bg-bambu-green`:n>20?`bg-yellow-500`:`bg-red-500`}`,style:{width:`${Math.min(n,100)}%`}})}),(0,Y.jsxs)(`span`,{className:`text-sm text-white`,children:[Math.round(t),`g`]})]})}),(0,Y.jsx)(`td`,{className:`px-4 py-2`,children:(0,Y.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[Math.round(Math.max(0,e.weight_used-(e.weight_used_baseline??0))),`g`]})}),(0,Y.jsx)(`td`,{className:`px-4 py-2`,children:(0,Y.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[e.label_weight,`g`]})})]},e.id)})})]})})]})]})})})]})}function Zt({label:e,value:t,hint:n}){return(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-tertiary/40 rounded-lg p-3`,title:n,children:[(0,Y.jsx)(`div`,{className:`text-xs font-medium text-white mb-1`,children:e}),(0,Y.jsx)(`div`,{className:`text-lg font-semibold text-white`,children:t})]})}function Qt({label:e,hint:t,unit:n,editing:r,value:i,inputValue:a,onInputChange:o,onEdit:s,onSave:c,onCancel:l,isPending:u,saveLabel:d=`Save`,cancelLabel:f=`Cancel`}){return(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-tertiary/40 rounded-lg p-3 space-y-1`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(`span`,{className:`text-xs font-medium text-white`,children:e}),(0,Y.jsx)(`span`,{title:t,children:(0,Y.jsx)(O,{className:`w-3 h-3 text-bambu-gray/50`})})]}),r?(0,Y.jsxs)(`form`,{className:`flex items-center gap-2`,onSubmit:e=>{e.preventDefault(),c()},children:[(0,Y.jsx)(`input`,{type:`number`,min:0,max:365,value:a,onChange:e=>o(e.target.value),className:`w-20 px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-sm text-white focus:outline-none focus:border-bambu-green`,autoFocus:!0,disabled:u}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:n}),(0,Y.jsx)(`button`,{type:`submit`,disabled:u,className:`px-2 py-1 bg-bambu-green text-white text-xs rounded hover:bg-bambu-green/80 disabled:opacity-50`,children:d}),(0,Y.jsx)(`button`,{type:`button`,onClick:l,disabled:u,className:`px-2 py-1 text-xs text-bambu-gray hover:text-white`,children:f})]}):(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`span`,{className:`text-lg font-semibold text-white`,children:i}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:n}),(0,Y.jsx)(`button`,{onClick:s,className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,Y.jsx)(I,{className:`w-3 h-3`})})]})]})}function $t({value:e,unit:t,editing:n,inputValue:r,dailyRateG:i,onInputChange:a,onUnitChange:o,onEdit:s,onSave:l,onCancel:u,isPending:d,saveLabel:f=`Save`,cancelLabel:p=`Cancel`,safetyMarginLabel:m=`Safety Margin`}){let{t:h}=c(),g=t===`g`?e:i===null?null:Math.round(i*e),_=t===`days`?h(`forecast.safetyMarginHintDays`,{approx:g===null?``:h(`forecast.safetyMarginHintDaysApprox`,{g})}):h(`forecast.safetyMarginHintG`,{approx:i===null?``:h(`forecast.safetyMarginHintGApprox`,{days:Math.round(e/i)})});return(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-tertiary/40 rounded-lg p-3 space-y-1`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(`span`,{className:`text-xs font-medium text-white`,children:m}),(0,Y.jsx)(`span`,{title:_,children:(0,Y.jsx)(O,{className:`w-3 h-3 text-bambu-gray/50`})})]}),n?(0,Y.jsxs)(`form`,{className:`flex items-center gap-2 flex-wrap`,onSubmit:e=>{e.preventDefault(),l()},children:[(0,Y.jsx)(`input`,{type:`number`,min:0,max:t===`g`?1e4:365,value:r,onChange:e=>a(e.target.value),className:`w-20 px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-sm text-white focus:outline-none focus:border-bambu-green`,autoFocus:!0,disabled:d}),(0,Y.jsxs)(`div`,{className:`flex bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded overflow-hidden text-xs`,children:[(0,Y.jsx)(`button`,{type:`button`,onClick:()=>o(`days`),className:`px-2 py-1 transition-colors ${t===`days`?`bg-bambu-green text-white`:`text-bambu-gray hover:text-white`}`,children:`days`}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>o(`g`),className:`px-2 py-1 transition-colors ${t===`g`?`bg-bambu-green text-white`:`text-bambu-gray hover:text-white`}`,children:`g`})]}),(0,Y.jsx)(`button`,{type:`submit`,disabled:d,className:`px-2 py-1 bg-bambu-green text-white text-xs rounded hover:bg-bambu-green/80 disabled:opacity-50`,children:f}),(0,Y.jsx)(`button`,{type:`button`,onClick:u,disabled:d,className:`px-2 py-1 text-xs text-bambu-gray hover:text-white`,children:p})]}):(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`span`,{className:`text-lg font-semibold text-white`,children:e}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:t}),g!==null&&t===`days`&&(0,Y.jsxs)(`span`,{className:`text-lg font-semibold text-white`,children:[`≈ `,g,`g`]}),t===`g`&&i!==null&&(0,Y.jsxs)(`span`,{className:`text-lg font-semibold text-white`,children:[`≈ `,Math.round(e/i),`d`]}),(0,Y.jsx)(`button`,{onClick:s,className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,Y.jsx)(I,{className:`w-3 h-3`})})]})]})}function en({items:e,forecasts:t,globalLeadTime:n,canWrite:i,onClose:a,onRemove:o,onClear:s}){let{t:u}=c(),f=l(),[p,m]=(0,J.useState)(`list`),h=d({mutationFn:async({id:e,status:t,item:n,avgSpoolG:i})=>{if(await r.updateShoppingListStatus(e,t),t===`received`&&n){let t=i??1e3,a={material:n.material,subtype:n.subtype,brand:n.brand,label_weight:t,core_weight:0,core_weight_catalog_id:null,color_name:n.color_name,rgba:null,extra_colors:null,effect_type:null,nozzle_temp_min:null,nozzle_temp_max:null,note:n.note??null,tag_uid:null,tray_uuid:null,data_origin:`manual`,tag_type:null,cost_per_kg:null,last_scale_weight:null,last_weighed_at:null,weight_used:0,slicer_filament:null,slicer_filament_name:null,added_full:null,last_used:null,encode_time:null,category:`Stock`,low_stock_threshold_pct:null,material_number:null};await r.bulkCreateSpools(a,n.quantity_spools),await r.removeFromShoppingList(e)}},onSuccess:()=>{f.invalidateQueries({queryKey:[`shopping-list`]}),f.invalidateQueries({queryKey:[`spools`]})}}),g=(0,J.useMemo)(()=>{let e=new Map;for(let n of t)e.set(n.group.key,n);return e},[t]),_=(0,J.useMemo)(()=>e.map(e=>({item:e,forecast:g.get(X(e.material,e.subtype,e.brand,e.color_name))??null})),[e,g]),v=(0,J.useMemo)(()=>_.filter(({forecast:e})=>!e||e.dailyRateG===null?!1:e.stockBreakAlert||e.daysRemaining!==null&&e.daysRemaining<=e.effectiveLeadTimeDays),[_]);function y(){let t=[u(`forecast.qty`),u(`forecast.material`),u(`inventory.brand`),u(`inventory.subtype`),u(`inventory.color`),`${u(`forecast.weight`)} (g)`,`${u(`forecast.leadTime`)} (d)`,u(`forecast.expectedRestock`),u(`forecast.status`),u(`forecast.note`)],r=e.map(e=>{let t=g.get(X(e.material,e.subtype,e.brand,e.color_name))??null,r=t&&t.totalSpools>0?t.totalLabelG/t.totalSpools:1e3,i=Math.round(e.quantity_spools*r),a=t?.effectiveLeadTimeDays??n??0,o=a>0?zt(Z(new Date,a)):``;return[e.quantity_spools,e.material,e.brand??``,e.subtype??``,e.color_name??``,i,a||``,o,e.status,e.note??``].map(e=>`"${String(e).replace(/"/g,`""`)}"`).join(`,`)}),i=[t.join(`,`),...r].join(`
`),a=new Blob([i],{type:`text/csv`}),o=URL.createObjectURL(a),s=document.createElement(`a`);s.href=o,s.download=`shopping-list-${new Date().toISOString().slice(0,10)}.csv`,s.click(),setTimeout(()=>URL.revokeObjectURL(o),100)}return(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg overflow-hidden border border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 border-b border-bambu-dark-tertiary bg-bambu-dark-tertiary/30`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Y.jsx)(tt,{className:`w-4 h-4 text-bambu-green`}),(0,Y.jsx)(`h3`,{className:`text-sm font-semibold text-white`,children:u(`forecast.shoppingList`)}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:u(`forecast.shoppingListItems`,{count:e.length})}),e.length>0&&(0,Y.jsxs)(`div`,{className:`flex bg-bambu-dark-tertiary rounded-md p-0.5 ml-1`,children:[(0,Y.jsxs)(`button`,{onClick:()=>m(`list`),className:`flex items-center gap-1.5 px-2 py-0.5 text-xs font-medium rounded transition-colors ${p===`list`?`bg-bambu-dark-secondary text-white shadow`:`text-bambu-gray hover:text-white`}`,children:[(0,Y.jsx)(oe,{className:`w-3 h-3`}),u(`forecast.listView`)]}),(0,Y.jsxs)(`button`,{onClick:()=>m(`logistics`),className:`flex items-center gap-1.5 px-2 py-0.5 text-xs font-medium rounded transition-colors ${p===`logistics`?`bg-bambu-dark-secondary text-white shadow`:`text-bambu-gray hover:text-white`}`,children:[(0,Y.jsx)(jt,{className:`w-3 h-3`}),u(`forecast.logisticsView`),v.length>0&&(0,Y.jsx)(`span`,{className:`w-3.5 h-3.5 rounded-full bg-red-500 text-white text-[9px] font-bold flex items-center justify-center`,children:v.length})]})]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.length>0&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`button`,{onClick:y,className:`flex items-center gap-1.5 text-xs text-bambu-gray hover:text-white transition-colors px-2 py-1 rounded border border-bambu-dark-tertiary hover:bg-bambu-dark-tertiary`,children:[(0,Y.jsx)(Qe,{className:`w-3 h-3`}),u(`forecast.downloadCsv`)]}),i&&(0,Y.jsx)(`button`,{onClick:s,className:`text-xs text-red-700 dark:text-red-400 hover:text-red-800 dark:hover:text-red-300 transition-colors px-2 py-1 rounded border border-red-200 dark:border-red-500/20 hover:bg-red-50 dark:hover:bg-red-500/10`,children:u(`forecast.clearAll`)})]}),(0,Y.jsx)(`button`,{onClick:a,className:`p-1 text-bambu-gray hover:text-white transition-colors`,children:(0,Y.jsx)(he,{className:`w-4 h-4`})})]})]}),e.length===0?(0,Y.jsxs)(`div`,{className:`flex flex-col items-center py-8 text-bambu-gray`,children:[(0,Y.jsx)(oe,{className:`w-8 h-8 mb-2 opacity-30`}),(0,Y.jsx)(`p`,{className:`text-sm`,children:u(`forecast.shoppingListEmpty`)})]}):p===`list`?(0,Y.jsx)(`div`,{className:`overflow-x-auto`,children:(0,Y.jsxs)(`table`,{className:`w-full`,children:[(0,Y.jsx)(`thead`,{children:(0,Y.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary bg-bambu-dark-tertiary/20`,children:[(0,Y.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:u(`forecast.qty`)}),(0,Y.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:u(`forecast.material`)}),(0,Y.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:u(`forecast.weight`)}),(0,Y.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:u(`forecast.leadTime`)}),(0,Y.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:u(`forecast.expectedRestock`)}),(0,Y.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:u(`forecast.status`)}),(0,Y.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:u(`forecast.note`)}),(0,Y.jsx)(`th`,{className:`px-4 py-2 text-right text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:u(`forecast.actions`)})]})}),(0,Y.jsx)(`tbody`,{className:`divide-y divide-bambu-dark-tertiary`,children:e.map(e=>{let t=[e.brand,e.material,e.subtype,e.color_name].filter(Boolean).join(` `),r=v.some(t=>t.item.id===e.id),a=g.get(X(e.material,e.subtype,e.brand,e.color_name))??null,s=a&&a.totalSpools>0?a.totalLabelG/a.totalSpools:1e3,c=Math.round(e.quantity_spools*s),l=a?.effectiveLeadTimeDays??n??0,d=l>0?Z(new Date,l):null,f=e.status===`purchased`||e.status===`received`,p=e.status===`received`,m=h.isPending;return(0,Y.jsxs)(`tr`,{className:`hover:bg-bambu-dark-tertiary/30 transition-colors ${r&&!f?`bg-red-500/5`:``}`,children:[(0,Y.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,Y.jsxs)(`span`,{className:`text-sm font-semibold text-bambu-green`,children:[e.quantity_spools,`×`]})}),(0,Y.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:t}),r&&!f&&(0,Y.jsx)(B,{className:`w-3.5 h-3.5 text-red-600 dark:text-red-400 flex-shrink-0`,"aria-label":u(`forecast.stockBreakBefore`)})]})}),(0,Y.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:c>=1e3?`${(c/1e3).toFixed(1)}kg`:`${c}g`})}),(0,Y.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:l>0?`${l}d`:`—`})}),(0,Y.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:d?zt(d):`—`})}),(0,Y.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,Y.jsx)(`span`,{className:`inline-flex items-center px-2 py-0.5 rounded text-xs font-medium ${p?`bg-bambu-green/20 text-bambu-green`:f?`bg-blue-100 dark:bg-blue-400/20 text-blue-700 dark:text-blue-400`:`bg-bambu-dark-tertiary text-bambu-gray`}`,children:u(p?`forecast.received`:f?`forecast.purchased`:`forecast.pending`)})}),(0,Y.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:e.note||`—`})}),(0,Y.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,Y.jsx)(`div`,{className:`flex items-center justify-end gap-1`,children:i&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`button`,{onClick:()=>h.mutate({id:e.id,status:f?`pending`:`purchased`}),disabled:m||p,title:u(f?`forecast.resetToPending`:`forecast.markPurchased`),className:`p-1.5 rounded transition-colors disabled:opacity-30 ${f?`text-blue-600 dark:text-blue-400 hover:text-blue-700 dark:hover:text-blue-300`:`text-blue-600/50 dark:text-blue-400/50 hover:text-blue-600 dark:hover:text-blue-400`}`,children:f?(0,Y.jsx)(Se,{className:`w-4 h-4`}):(0,Y.jsx)(Mt,{className:`w-4 h-4`})}),(0,Y.jsx)(`button`,{onClick:()=>h.mutate({id:e.id,status:`received`,item:e,avgSpoolG:s}),disabled:m||!f||p,title:u(`forecast.markReceived`),className:`p-1.5 rounded transition-colors text-bambu-green/50 hover:text-bambu-green disabled:opacity-30`,children:(0,Y.jsx)(Pt,{className:`w-4 h-4`})}),(0,Y.jsx)(`button`,{onClick:()=>o(e.id),className:`p-1 text-bambu-gray hover:text-red-600 dark:hover:text-red-400 transition-colors`,title:u(`forecast.remove`),children:(0,Y.jsx)(be,{className:`w-3.5 h-3.5`})})]})})})]},e.id)})})]})}):(0,Y.jsx)(`div`,{className:`divide-y divide-bambu-dark-tertiary`,children:_.filter(({item:e})=>e.status!==`received`).map(({item:e,forecast:t})=>(0,Y.jsx)(tn,{item:e,forecast:t,globalLeadTime:n,canWrite:i,onRemove:()=>o(e.id)},e.id))})]})}function tn({item:e,forecast:t,globalLeadTime:n,canWrite:r,onRemove:i}){let{t:a}=c(),o=[e.brand,e.material,e.subtype,e.color_name].filter(Boolean).join(` `),s=(0,J.useMemo)(()=>{if(!t||t.dailyRateG===null||t.dailyRateG<=0)return null;let n=t.dailyRateG,r=t.effectiveLeadTimeDays,i=t.totalSpools>0?t.totalLabelG/t.totalSpools:1e3,a=e.quantity_spools*i,o=Math.max(0,t.totalRemainingG-n*r),s=o+a,c=Math.ceil(s/n),l=Math.min(r+c+5,365),u=[];for(let e=0;e<=l;e++){let i=Bt(Z(new Date,e));if(e===r)u.push({day:e,label:i,stock:Math.round(o),rop:Math.round(t.reorderPointG),safetyStock:Math.round(t.safetyStockG)}),u.push({day:e,label:i,stock:Math.round(s),rop:Math.round(t.reorderPointG),safetyStock:Math.round(t.safetyStockG),arrival:!0});else{let a=e<r?Math.max(0,t.totalRemainingG-n*e):Math.max(0,s-n*(e-r));u.push({day:e,label:i,stock:Math.round(a),rop:Math.round(t.reorderPointG),safetyStock:Math.round(t.safetyStockG)})}}return{points:u,lt:r,maxDays:l,arrivalG:a,peakG:s,stockAtArrival:o}},[t,e.quantity_spools]),l=(0,J.useMemo)(()=>{if(!t||t.dailyRateG===null||t.dailyRateG<=0)return null;let e=Math.floor(t.totalRemainingG/t.dailyRateG);return e<t.effectiveLeadTimeDays?e:null},[t]),u=l!==null;return(0,Y.jsxs)(`div`,{className:`px-4 py-4 ${u?`bg-red-500/5`:``}`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[u?(0,Y.jsx)(B,{className:`w-4 h-4 text-red-600 dark:text-red-400 flex-shrink-0`}):(0,Y.jsx)(w,{className:`w-4 h-4 text-bambu-green/60 flex-shrink-0`}),(0,Y.jsx)(`span`,{className:`text-sm font-medium text-white truncate`,children:o}),(0,Y.jsxs)(`span`,{className:`text-xs text-bambu-gray flex-shrink-0`,children:[a(`forecast.spoolCount`,{count:e.quantity_spools}),` ordered`]})]}),r&&(0,Y.jsx)(`button`,{onClick:i,className:`p-1 text-bambu-gray hover:text-red-600 dark:hover:text-red-400 transition-colors flex-shrink-0`,children:(0,Y.jsx)(be,{className:`w-3.5 h-3.5`})})]}),u&&(0,Y.jsxs)(`div`,{className:`mb-3 px-3 py-2 rounded-lg bg-red-50 dark:bg-red-500/10 border border-red-200 dark:border-red-500/20 text-xs text-red-700 dark:text-red-300`,children:[(0,Y.jsx)(`span`,{className:`font-medium`,children:a(`forecast.stockBreakIn`,{days:l})}),` `,a(`forecast.stockRunsOutBefore`,{lt:t.effectiveLeadTimeDays}),t.dailyRateG!==null&&(0,Y.jsxs)(`span`,{children:[` `,a(`forecast.atRate`,{rate:t.dailyRateG.toFixed(1)}),` `,(0,Y.jsx)(`span`,{className:`font-semibold`,children:a(`forecast.moreSpools`,{count:Math.ceil((t.dailyRateG*t.effectiveLeadTimeDays-t.totalRemainingG)/(t.totalLabelG/(t.totalSpools||1)||1e3))})}),` `,a(`forecast.bridgeGap`)]})]}),!t||t.dailyRateG===null?(0,Y.jsx)(`div`,{className:`py-4 text-center text-xs text-bambu-gray`,children:a(`forecast.noUsageData`)}):s?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`div`,{className:`grid grid-cols-5 gap-2 mb-3`,children:[(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-tertiary/40 rounded-lg px-2.5 py-2 text-center`,children:[(0,Y.jsx)(`div`,{className:`text-xs text-bambu-gray mb-0.5`,children:a(`forecast.stock`)}),(0,Y.jsxs)(`div`,{className:`text-sm font-semibold text-white`,children:[Math.round(t.totalRemainingG),`g`]})]}),(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-tertiary/40 rounded-lg px-2.5 py-2 text-center`,children:[(0,Y.jsx)(`div`,{className:`text-xs text-bambu-gray mb-0.5`,children:a(`forecast.leadTime`)}),(0,Y.jsxs)(`div`,{className:`text-sm font-semibold text-white`,children:[t.effectiveLeadTimeDays,`d`]}),(0,Y.jsxs)(`div`,{className:`text-[10px] text-bambu-gray/60`,children:[`max(g:`,n,`, sku:`,t.settings?.lead_time_days??0,`)`]})]}),(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-tertiary/40 rounded-lg px-2.5 py-2 text-center`,children:[(0,Y.jsx)(`div`,{className:`text-xs text-bambu-gray mb-0.5`,children:a(`forecast.safetyMarginLabel`)}),(0,Y.jsxs)(`div`,{className:`text-sm font-semibold text-white`,children:[Math.round(t.safetyStockG),`g`]})]}),(0,Y.jsxs)(`div`,{className:`rounded-lg px-2.5 py-2 text-center ${u?`bg-red-100 dark:bg-red-500/15`:`bg-bambu-dark-tertiary/40`}`,children:[(0,Y.jsx)(`div`,{className:`text-xs text-bambu-gray mb-0.5`,children:a(`forecast.daysLeft`)}),(0,Y.jsxs)(`div`,{className:`text-sm font-semibold ${u?`text-red-700 dark:text-red-400`:`text-green-700 dark:text-green-400`}`,children:[t.daysRemaining??`—`,`d`]})]}),s&&(0,Y.jsxs)(`div`,{className:`bg-bambu-green/15 rounded-lg px-2.5 py-2 text-center`,children:[(0,Y.jsx)(`div`,{className:`text-xs text-bambu-gray mb-0.5`,children:a(`forecast.onArrival`)}),(0,Y.jsxs)(`div`,{className:`text-sm font-semibold text-bambu-green`,children:[Math.round(s.arrivalG),`g`]}),(0,Y.jsxs)(`div`,{className:`text-[10px] text-bambu-gray/60`,children:[`+`,a(`forecast.spoolCount`,{count:e.quantity_spools})]})]})]}),(0,Y.jsx)(ue,{width:`100%`,height:180,children:(0,Y.jsxs)(ot,{data:s.points,margin:{top:8,right:8,bottom:0,left:0},children:[(0,Y.jsxs)(`defs`,{children:[(0,Y.jsxs)(`linearGradient`,{id:`cart-pre-${e.id}`,x1:`0`,y1:`0`,x2:`0`,y2:`1`,children:[(0,Y.jsx)(`stop`,{offset:`5%`,stopColor:u?`#EF4444`:`#1DB954`,stopOpacity:.25}),(0,Y.jsx)(`stop`,{offset:`95%`,stopColor:u?`#EF4444`:`#1DB954`,stopOpacity:.02})]}),(0,Y.jsxs)(`linearGradient`,{id:`cart-post-${e.id}`,x1:`0`,y1:`0`,x2:`0`,y2:`1`,children:[(0,Y.jsx)(`stop`,{offset:`5%`,stopColor:`#1DB954`,stopOpacity:.3}),(0,Y.jsx)(`stop`,{offset:`95%`,stopColor:`#1DB954`,stopOpacity:.03})]})]}),(0,Y.jsx)(fe,{strokeDasharray:`3 3`,stroke:`#374151`,strokeOpacity:.4}),(0,Y.jsx)(de,{dataKey:`label`,tick:{fill:`#6B7280`,fontSize:9},interval:Math.max(0,Math.ceil(s.maxDays/6)-1),axisLine:!1,tickLine:!1}),(0,Y.jsx)(pe,{tick:{fill:`#6B7280`,fontSize:9},axisLine:!1,tickLine:!1,tickFormatter:e=>e>=1e3?`${(e/1e3).toFixed(1)}kg`:`${e}g`,width:44}),(0,Y.jsx)(ce,{contentStyle:{background:`#1a1a2e`,border:`1px solid #374151`,borderRadius:8,fontSize:11},labelStyle:{color:`#9CA3AF`},formatter:(e,t)=>typeof e==`number`?t===`stock`?`${e}g — ${a(`forecast.stock`)}`:t===`rop`?`${e}g — ${a(`forecast.reorderPoint`)}`:t===`safetyStock`?`${e}g — ${a(`forecast.safetyMarginLabel`)}`:`${e}`:``}),(0,Y.jsx)(at,{type:`linear`,dataKey:`stock`,stroke:`#1DB954`,strokeWidth:2,fill:`url(#cart-post-${e.id})`,dot:!1,activeDot:{r:3}}),t.reorderPointG>0&&(0,Y.jsx)(C,{y:t.reorderPointG,stroke:`#F59E0B`,strokeDasharray:`5 3`,strokeOpacity:.8,label:{value:`ROP`,position:`insideTopRight`,fill:`#F59E0B`,fontSize:9}}),t.safetyStockG>0&&(0,Y.jsx)(C,{y:t.safetyStockG,stroke:`#6B7280`,strokeDasharray:`3 3`,strokeOpacity:.6,label:{value:`SS`,position:`insideTopRight`,fill:`#6B7280`,fontSize:9}}),(0,Y.jsx)(C,{x:Bt(Z(new Date,s.lt)),stroke:`#3B82F6`,strokeWidth:1.5,strokeDasharray:`4 3`,strokeOpacity:.9,label:{value:`+${s.arrivalG>=1e3?`${(s.arrivalG/1e3).toFixed(1)}kg`:`${Math.round(s.arrivalG)}g`} arrives (d${s.lt})`,position:`insideTopLeft`,fill:`#3B82F6`,fontSize:9}}),l!==null&&(0,Y.jsx)(C,{x:Bt(Z(new Date,l)),stroke:`#EF4444`,strokeWidth:1.5,strokeOpacity:.9,label:{value:`OUT`,position:`insideTopLeft`,fill:`#EF4444`,fontSize:9}})]})}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 mt-2 text-[10px] text-bambu-gray`,children:[(0,Y.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,Y.jsx)(`span`,{className:`inline-block w-4 border-t-2 border-yellow-400 border-dashed`}),` `,a(`forecast.ropLabel`)]}),(0,Y.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,Y.jsx)(`span`,{className:`inline-block w-4 border-t border-bambu-gray border-dashed`}),` `,a(`forecast.safetyStockLegend`)]}),(0,Y.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,Y.jsx)(`span`,{className:`inline-block w-4 border-t-2 border-blue-400 border-dashed`}),` `,a(`forecast.stockArrivalLegend`)]}),u&&(0,Y.jsxs)(`span`,{className:`flex items-center gap-1 text-red-700 dark:text-red-400`,children:[(0,Y.jsx)(`span`,{className:`inline-block w-4 border-t-2 border-red-400`}),` `,a(`forecast.stockoutLegend`)]})]})]}):null]})}function nn({forecast:e,onClose:t,onAdd:n}){let{t:r}=c(),i=[e.group.brand,e.group.material,e.group.subtype,e.group.colorName].filter(Boolean).join(` `),[a,o]=(0,J.useState)(`qty`),[s,l]=(0,J.useState)(`1`),[u,d]=(0,J.useState)(`30`),[f,p]=(0,J.useState)(``),m=(0,J.useMemo)(()=>{if(!e.dailyRateG||e.dailyRateG<=0)return null;let t=e.dailyRateG*Number(u),n=e.group.spools.length>0?e.group.spools.reduce((e,t)=>e+t.label_weight,0)/e.group.spools.length:1e3;return Math.ceil(t/n)},[e,u]),h=a===`qty`?parseInt(s,10)||1:m??1;function g(t){t.preventDefault(),n({material:e.group.material,subtype:e.group.subtype,brand:e.group.brand,color_name:e.group.colorName,quantity_spools:h,note:f||null})}return(0,Y.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm p-4`,children:(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-2xl border border-bambu-dark-tertiary w-full max-w-sm shadow-2xl`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between px-5 pt-5 pb-4 border-b border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(tt,{className:`w-5 h-5 text-bambu-green`}),(0,Y.jsx)(`h2`,{className:`text-base font-semibold text-white`,children:r(`forecast.addToCartTitle`)})]}),(0,Y.jsx)(`button`,{onClick:t,className:`p-1 text-bambu-gray hover:text-white transition-colors`,children:(0,Y.jsx)(he,{className:`w-5 h-5`})})]}),(0,Y.jsxs)(`form`,{onSubmit:g,className:`p-5 space-y-4`,children:[(0,Y.jsx)(`div`,{className:`text-sm text-bambu-gray`,children:i}),(0,Y.jsxs)(`div`,{className:`flex bg-bambu-dark-tertiary rounded-lg p-0.5`,children:[(0,Y.jsx)(`button`,{type:`button`,onClick:()=>o(`qty`),className:`flex-1 py-1.5 text-xs font-medium rounded-md transition-colors ${a===`qty`?`bg-bambu-dark-secondary text-white shadow`:`text-bambu-gray hover:text-white`}`,children:r(`forecast.byQuantity`)}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>o(`duration`),className:`flex-1 py-1.5 text-xs font-medium rounded-md transition-colors ${a===`duration`?`bg-bambu-dark-secondary text-white shadow`:`text-bambu-gray hover:text-white`}`,children:r(`forecast.byDuration`)})]}),a===`qty`?(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(`label`,{className:`text-xs text-bambu-gray`,children:r(`forecast.numberOfSpools`)}),(0,Y.jsx)(`input`,{type:`number`,min:1,max:99,value:s,onChange:e=>l(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`,autoFocus:!0})]}):(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(`label`,{className:`text-xs text-bambu-gray`,children:r(`forecast.lastHowManyDays`)}),(0,Y.jsx)(`input`,{type:`number`,min:1,max:365,value:u,onChange:e=>d(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`,autoFocus:!0})]}),e.dailyRateG===null?(0,Y.jsx)(`div`,{className:`text-xs text-yellow-700 dark:text-yellow-400 px-1`,children:r(`forecast.noUsageQty`)}):(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2 bg-bambu-dark-tertiary/50 rounded-lg`,children:[(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:`≈`}),(0,Y.jsx)(`span`,{className:`text-sm font-semibold text-bambu-green`,children:r(`forecast.spoolCount`,{count:m??0})}),(0,Y.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[`at `,e.dailyRateG.toFixed(1),`g/day`]})]})]}),(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(`label`,{className:`text-xs text-bambu-gray`,children:r(`forecast.noteOptional`)}),(0,Y.jsx)(`input`,{type:`text`,maxLength:200,value:f,onChange:e=>p(e.target.value),placeholder:r(`forecast.notePlaceholder`),className:`w-full px-3 py-2 bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/40 focus:outline-none focus:border-bambu-green`})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-3 pt-1`,children:[(0,Y.jsx)(`button`,{type:`submit`,className:`flex-1 py-2 bg-bambu-green text-white text-sm font-medium rounded-lg hover:bg-bambu-green/80 transition-colors`,children:r(`forecast.addNSpools`,{count:h})}),(0,Y.jsx)(`button`,{type:`button`,onClick:t,className:`px-4 py-2 text-sm text-bambu-gray hover:text-white border border-bambu-dark-tertiary rounded-lg transition-colors`,children:r(`forecast.cancel`)})]})]})]})})}function rn({links:e,onChange:t,currencySymbol:n}){let{t:i}=c(),{showToast:a}=te(),s=l(),d=(0,J.useRef)(null),[f,p]=(0,J.useState)(!1),[m,h]=(0,J.useState)(``),[g,_]=(0,J.useState)(!1),{data:v=[],isLoading:y,isError:b}=u({queryKey:Xe,queryFn:r.getSuppliers});(0,J.useEffect)(()=>{if(!f)return;let e=e=>{d.current&&!d.current.contains(e.target)&&(p(!1),h(``))};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[f]);let x=(0,J.useMemo)(()=>new Set(e.map(e=>e.supplier_id)),[e]),S=(0,J.useMemo)(()=>v.filter(e=>!x.has(e.id)).filter(e=>e.name.toLowerCase().includes(m.trim().toLowerCase())),[v,x,m]),C=v.some(e=>e.name.toLowerCase()===m.trim().toLowerCase()),w=n=>{t([...e,{supplier_id:n.id,supplier_name:n.name,supplier_article_number:``,quoted_price_per_kg:null,is_purchase_source:!1}]),p(!1),h(``)},E=async()=>{let e=m.trim();if(e){_(!0);try{let t=await r.createSupplier({name:e});await He(s),w(t)}catch(e){console.error(`SupplierSection.createAndAdd failed:`,e),a(i(e instanceof o&&e.status===409?`inventory.suppliers.duplicateName`:`inventory.suppliers.createFailed`),`error`)}finally{_(!1)}}},D=(n,r)=>{t(e.map(e=>e.supplier_id===n?{...e,...r}:r.is_purchase_source?{...e,is_purchase_source:!1}:e))},O=n=>{t(e.filter(e=>e.supplier_id!==n))};return(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:i(`inventory.suppliers.label`)}),e.length>0&&(0,Y.jsx)(`div`,{className:`space-y-2 mb-2`,children:e.map(e=>(0,Y.jsxs)(`div`,{className:`p-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs bg-bambu-green/10 text-bambu-green`,children:[(0,Y.jsx)(Ft,{className:`w-3 h-3`}),e.supplier_name]}),(0,Y.jsxs)(`label`,{className:`ml-auto flex items-center gap-1.5 text-xs text-bambu-gray cursor-pointer`,title:i(`inventory.suppliers.purchaseSourceHelp`),children:[(0,Y.jsx)(`input`,{type:`checkbox`,className:`w-3.5 h-3.5 accent-bambu-green`,checked:e.is_purchase_source,onChange:t=>D(e.supplier_id,{is_purchase_source:t.target.checked})}),i(`inventory.suppliers.purchaseSource`)]}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>O(e.supplier_id),className:`p-1 rounded text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary`,"aria-label":i(`common.remove`),children:(0,Y.jsx)(he,{className:`w-3.5 h-3.5`})})]}),(0,Y.jsxs)(`div`,{className:`flex gap-2 mt-2`,children:[(0,Y.jsx)(`input`,{type:`text`,className:`flex-1 min-w-0 px-2 py-1.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-xs placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`,placeholder:i(`inventory.suppliers.articleNumberPlaceholder`),value:e.supplier_article_number,maxLength:100,onChange:t=>D(e.supplier_id,{supplier_article_number:t.target.value})}),(0,Y.jsxs)(`div`,{className:`relative w-28`,children:[(0,Y.jsx)(`span`,{className:`absolute left-2 top-1/2 -translate-y-1/2 text-xs text-bambu-gray pointer-events-none`,children:n}),(0,Y.jsx)(`input`,{type:`number`,className:`w-full pl-6 pr-2 py-1.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-xs text-right placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`,placeholder:i(`inventory.suppliers.pricePlaceholder`),title:i(`inventory.suppliers.priceHelp`),min:0,step:.01,value:e.quoted_price_per_kg??``,onChange:t=>D(e.supplier_id,{quoted_price_per_kg:t.target.value===``?null:parseFloat(t.target.value)})})]})]})]},e.supplier_id))}),(0,Y.jsxs)(`div`,{className:`relative`,ref:d,children:[(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>p(e=>!e),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-sm text-bambu-gray hover:text-white flex items-center justify-between transition-colors focus:outline-none focus:border-bambu-green`,children:[(0,Y.jsx)(`span`,{children:i(`inventory.suppliers.addSupplier`)}),(0,Y.jsx)(T,{className:`w-4 h-4 transition-transform ${f?`rotate-180`:``}`})]}),f&&(0,Y.jsxs)(`div`,{className:`absolute z-50 w-full mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg`,children:[(0,Y.jsx)(`div`,{className:`p-2 border-b border-bambu-dark-tertiary`,children:(0,Y.jsx)(`input`,{type:`text`,autoFocus:!0,className:`w-full px-2 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`,placeholder:i(`inventory.suppliers.searchPlaceholder`),value:m,onChange:e=>h(e.target.value)})}),(0,Y.jsx)(`div`,{className:`max-h-48 overflow-y-auto py-1`,children:y?(0,Y.jsxs)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray flex items-center gap-2`,children:[(0,Y.jsx)(F,{className:`w-4 h-4 animate-spin`}),i(`common.loading`)]}):b?(0,Y.jsxs)(`div`,{className:`px-3 py-2 text-sm text-red-400 flex items-center gap-2`,children:[(0,Y.jsx)(B,{className:`w-4 h-4`}),i(`inventory.suppliers.loadFailed`)]}):(0,Y.jsxs)(Y.Fragment,{children:[S.map(e=>(0,Y.jsx)(`button`,{type:`button`,onClick:()=>w(e),className:`w-full px-3 py-2 text-left text-sm text-white hover:bg-bambu-dark-tertiary`,children:e.name},e.id)),S.length===0&&!m.trim()&&(0,Y.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:i(`inventory.suppliers.noneLeft`)}),m.trim()&&!C&&(0,Y.jsxs)(`button`,{type:`button`,onClick:E,disabled:g,className:`w-full px-3 py-2 text-left text-sm text-bambu-green hover:bg-bambu-dark-tertiary flex items-center gap-1.5`,children:[g?(0,Y.jsx)(F,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(Pe,{className:`w-4 h-4`}),i(`inventory.suppliers.createNew`,{name:m.trim()})]})]})})]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`inventory.suppliers.help`)})]})}function an({filaments:e,isLoading:t,selectedId:n,onSelect:r}){let{t:i}=c(),[a,o]=(0,J.useState)(!1),[s,l]=(0,J.useState)(``),u=(0,J.useRef)(null),d=(0,J.useRef)(null),f=(0,J.useMemo)(()=>e.find(e=>e.id===n)??null,[e,n]);(0,J.useEffect)(()=>{let e=e=>{u.current&&!u.current.contains(e.target)&&(o(!1),l(``))};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[]);let p=(0,J.useMemo)(()=>{let t=s.toLowerCase().trim();return t?e.filter(e=>e.name.toLowerCase().includes(t)||(e.material?.toLowerCase().includes(t)??!1)||(e.vendor?.name.toLowerCase().includes(t)??!1)||(e.color_name?.toLowerCase().includes(t)??!1)):e},[e,s]);(0,J.useEffect)(()=>{a&&d.current?.focus()},[a]);let m=()=>{o(!0),l(``)},h=e=>{r(e),o(!1),l(``)};return(0,Y.jsxs)(`div`,{ref:u,className:`relative`,children:[(0,Y.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:i(`inventory.pickFromSpoolmanCatalog`)}),(0,Y.jsxs)(`button`,{type:`button`,onClick:m,className:`w-full flex items-center gap-2 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-left focus:outline-none focus:border-bambu-green hover:border-bambu-gray transition-colors`,children:[t?(0,Y.jsx)(F,{className:`w-4 h-4 text-bambu-gray animate-spin shrink-0`}):f?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`span`,{className:`w-4 h-4 rounded-full shrink-0 border border-white/20`,style:Ke(f.color_hex),"aria-label":i(`inventory.spoolmanFilamentColorSwatch`)}),(0,Y.jsxs)(`span`,{className:`text-white text-sm truncate flex-1`,children:[f.vendor?.name?`${f.vendor.name} — `:``,f.name]})]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(oe,{className:`w-4 h-4 text-bambu-gray shrink-0`}),(0,Y.jsx)(`span`,{className:`text-bambu-gray text-sm flex-1`,children:i(`inventory.spoolmanFilamentCatalog`)})]}),(0,Y.jsx)(T,{className:`w-4 h-4 text-bambu-gray shrink-0 ml-auto`})]}),a&&(0,Y.jsxs)(`div`,{className:`absolute z-50 w-full mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl`,children:[(0,Y.jsx)(`div`,{className:`p-2 border-b border-bambu-dark-tertiary`,children:(0,Y.jsx)(`input`,{ref:d,type:`text`,value:s,onChange:e=>l(e.target.value),placeholder:i(`inventory.pickFromSpoolmanCatalog`),className:`w-full px-2 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm placeholder-bambu-gray focus:outline-none focus:border-bambu-green`})}),(0,Y.jsx)(`ul`,{className:`max-h-56 overflow-y-auto py-1`,children:t?(0,Y.jsxs)(`li`,{className:`flex items-center justify-center gap-2 py-4 text-bambu-gray text-sm`,children:[(0,Y.jsx)(F,{className:`w-4 h-4 animate-spin`}),(0,Y.jsx)(`span`,{children:i(`common.loading`,`Loading…`)})]}):p.length===0?(0,Y.jsx)(`li`,{className:`py-4 text-center text-bambu-gray text-sm`,children:i(`inventory.noSpoolmanFilaments`)}):p.map(e=>(0,Y.jsx)(`li`,{children:(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>h(e),className:`w-full flex items-center gap-2 px-3 py-2 text-left hover:bg-bambu-dark-tertiary transition-colors ${e.id===n?`bg-bambu-dark-tertiary`:``}`,children:[(0,Y.jsx)(`span`,{className:`w-4 h-4 rounded-full shrink-0 border border-white/20`,style:Ke(e.color_hex),"aria-label":i(`inventory.spoolmanFilamentColorSwatch`)}),(0,Y.jsxs)(`span`,{className:`flex-1 min-w-0`,children:[(0,Y.jsxs)(`span`,{className:`block text-white text-sm truncate`,children:[e.vendor?.name?`${e.vendor.name} — `:``,e.name]}),(0,Y.jsxs)(`span`,{className:`block text-bambu-gray text-xs truncate`,children:[[e.material,e.color_name].filter(Boolean).join(` · `),e.weight?` · ${e.weight}g`:``]})]})]})},e.id))})]})]})}function on(e){let t=(e??``).trim().toUpperCase().slice(0,2);return t===`HH`||t===`HS`?t:null}function sn(e){return e?e===`HH`?`HF`:`S`:null}function cn(e,t){let n=e.nozzles??[];return on(n[(e.printer.nozzle_count??1)>1&&t>0?t:0]?.nozzle_type)??on(n[0]?.nozzle_type)}function ln(e){let t=new Set;for(let n of e.nozzles??[]){let e=(n?.nozzle_diameter??``).trim();e&&parseFloat(e)>0&&t.add(e)}for(let n of e.calibrations){let e=(n.nozzle_diameter??``).trim();e&&parseFloat(e)>0&&t.add(e)}return Array.from(t).sort((e,t)=>parseFloat(e)-parseFloat(t))}function un(e,t){return(e.printer.nozzle_count??1)>1?[{extruder:1,label:t.left},{extruder:0,label:t.right}]:[{extruder:0,label:t.single}]}function dn({formData:e,printersWithCalibrations:t,filamentOptions:n,modelPresets:r,setModelPresets:i,selectedProfiles:a,setSelectedProfiles:o,selectedGroupId:s,setSelectedGroupId:l,printerModels:u,isLoading:d=!1}){let{t:f}=c(),p=(0,J.useMemo)(()=>{let e=new Map,n=[];for(let r of t){let t=(r.printer.model||``).trim();if(!t){n.push(r);continue}let i=e.get(t);i?i.push(r):e.set(t,[r])}return[...Array.from(e.entries()).map(([e,t])=>({id:`m:${e}`,model:e,printers:t,diameters:Array.from(new Set([...mt,...t.flatMap(ln)])).sort((e,t)=>parseFloat(e)-parseFloat(t))})).sort((e,t)=>e.model.localeCompare(t.model)),...n.map(e=>({id:`p:${e.printer.id}`,model:``,printers:[e],diameters:Array.from(new Set([...mt,...ln(e)])).sort((e,t)=>parseFloat(e)-parseFloat(t))}))]},[t]),m=p.find(e=>e.id===s)??p[0],h=(0,J.useMemo)(()=>{let e=new Map;return(t,r)=>{if(!t)return n;let i=e.get(t);if(i||(i=n.filter(e=>{let n=rt(e.name,u??{});return!n||nt(n,t)}),e.set(t,i)),r&&!i.some(e=>e.code===r)){let e=n.find(e=>e.code===r);if(e)return[e,...i]}return i}},[n,u]),g=[e.brand,e.material,e.subtype].map(e=>e.trim()).filter(Boolean).join(` `),_=/^[0-9A-Fa-f]{6,8}$/.test(e.rgba)?`#${e.rgba.slice(0,6)}`:`var(--bambu-gray, #808080)`,v=e=>un(e,{left:f(`inventory.leftNozzle`),right:f(`inventory.rightNozzle`),single:f(`inventory.nozzle`)}),y=t=>t.printer.connected?t.calibrations.filter(t=>Ct(t,e)):[],b=e=>{let t=0;for(let n of e.printers){let r=y(n);for(let i of v(n))for(let o of e.diameters)r.some(e=>(e.extruder_id??0)===i.extruder&&((e.nozzle_diameter??``).trim()||`0.4`)===o)&&(a.get(K(n.printer.id,i.extruder,o))||t++)}return t},x=(e,t,n)=>{i(r=>{let i=new Map(r),a=gt(e,t);return n?i.set(a,{code:n.code,name:n.name}):i.delete(a),i})},S=(e,t,n,r)=>{o(i=>{let a=new Map(i),o=K(e,t,n);return r?a.set(o,r):a.delete(o),a})},C=()=>{let t=n.find(t=>t.code===e.slicer_filament);if(!t)return;let r=t.name.split(`@`)[0].trim().toLowerCase();r&&i(e=>{let t=new Map(e);for(let e of p){if(!e.model)continue;let n=h(e.model,void 0).filter(e=>e.name.toLowerCase().startsWith(r)&&rt(e.name,u??{})!==null);if(n.length!==0)for(let r of e.diameters){let i=n.find(e=>RegExp(`\\b${r.replace(`.`,`\\.`)}\\s*nozzle\\b`,`i`).test(e.name)),a=n.find(e=>!/\b[\d.]+\s*nozzle\b/i.test(e.name)),o=i??a;o&&t.set(gt(e.model,r),{code:o.code,name:o.name})}}return t})};if(t.length===0)return(0,Y.jsx)(`div`,{className:`p-6 bg-bambu-dark rounded-lg text-center`,children:(0,Y.jsxs)(`p`,{className:`text-bambu-gray flex items-center justify-center gap-2`,children:[d&&(0,Y.jsx)(F,{className:`w-4 h-4 animate-spin`}),f(d?`common.loading`:`inventory.noPrintersConfigured`)]})});let T=(e,t,n)=>{let i=gt(e,t),a=r.get(i),o=h(e,a?.code);return(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,Y.jsx)(ct,{ariaLabel:`${e} ${t}mm ${f(`inventory.filamentPreset`)}`,value:a?.code??``,options:o,inheritLabel:n,disabled:!e,onChange:n=>x(e,t,n)})}),(0,Y.jsx)(`span`,{className:`text-[10px] font-semibold uppercase tracking-wide px-2 py-1 rounded-full shrink-0 ${a?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark-tertiary text-bambu-gray`}`,children:f(a?`inventory.presetOverride`:`inventory.presetInherited`)})]})};return(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(g||e.color_name)&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-2.5 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg`,children:[(0,Y.jsx)(`span`,{className:`w-5 h-5 rounded-full border border-white/15 shrink-0`,style:{background:_},"aria-hidden":`true`}),g&&(0,Y.jsx)(`span`,{className:`text-sm text-white truncate`,children:g}),e.color_name&&(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray truncate`,children:e.color_name})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col md:flex-row gap-4`,children:[(0,Y.jsx)(`div`,{role:`tablist`,"aria-label":f(`inventory.printersTab`),"aria-orientation":`vertical`,className:`md:w-52 md:shrink-0 md:self-start md:sticky md:top-0 flex md:flex-col gap-1.5 overflow-x-auto md:overflow-x-visible`,children:p.map(e=>{let t=e===m,n=b(e);return(0,Y.jsxs)(`button`,{type:`button`,role:`tab`,onClick:()=>l(e.id),"aria-selected":t,className:`flex items-center gap-2 px-3 py-2 rounded-lg border text-left transition-colors shrink-0 md:shrink ${t?`bg-bambu-green/10 border-bambu-green/40 text-white`:`bg-transparent border-transparent text-bambu-gray hover:bg-bambu-dark hover:text-white`}`,children:[(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsx)(`div`,{className:`text-sm font-semibold truncate`,children:e.model||f(`inventory.unknownModel`)}),(0,Y.jsx)(`div`,{className:`text-[11px] text-bambu-gray`,children:e.printers.length===1?f(`inventory.onePrinter`):f(`inventory.nPrinters`,{n:e.printers.length})})]}),n>0?(0,Y.jsx)(`span`,{className:`text-[10px] font-mono px-1.5 py-0.5 rounded-full bg-bambu-dark-tertiary text-bambu-gray shrink-0`,children:n}):(0,Y.jsx)(w,{className:`w-3.5 h-3.5 text-bambu-green shrink-0`})]},e.id)})}),(0,Y.jsx)(`div`,{className:`flex-1 min-w-0`,children:m&&(0,Y.jsxs)(`div`,{className:`space-y-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,Y.jsxs)(`div`,{className:`min-w-0`,children:[(0,Y.jsx)(`h4`,{className:`text-base font-semibold text-white truncate`,children:m.model||f(`inventory.unknownModel`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:m.printers.map(e=>e.printer.name).join(`, `)})]}),e.slicer_filament&&(0,Y.jsxs)(`button`,{type:`button`,onClick:C,title:f(`inventory.autoMatchPresetsHint`),className:`flex items-center gap-1.5 px-2 py-1 text-xs bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray hover:text-white hover:border-bambu-green transition-colors shrink-0`,children:[(0,Y.jsx)(z,{className:`w-3.5 h-3.5`}),f(`inventory.autoMatchPresets`)]})]}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(`p`,{className:`text-xs font-semibold text-bambu-gray uppercase tracking-wide`,children:f(`inventory.filamentPreset`)}),m.model?(0,Y.jsx)(`div`,{className:`space-y-2`,children:m.diameters.map(e=>(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Y.jsxs)(`span`,{className:`text-xs font-mono text-bambu-gray w-14 shrink-0`,children:[e,`mm`]}),(0,Y.jsx)(`div`,{className:`flex-1 min-w-0`,children:T(m.model,e,f(`inventory.presetUseSpoolDefault`))})]},e))}):(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray italic`,children:f(`inventory.presetNeedsModel`)})]}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(`p`,{className:`text-xs font-semibold text-bambu-gray uppercase tracking-wide`,children:f(`inventory.kProfilesPerPrinter`)}),e.material?m.printers.map(e=>{let t=y(e);return(0,Y.jsxs)(`div`,{className:`p-3 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,Y.jsx)(U,{className:`w-3.5 h-3.5 text-bambu-gray shrink-0`}),(0,Y.jsx)(`span`,{className:`text-sm font-semibold text-white truncate`,children:e.printer.name}),(0,Y.jsx)(`span`,{className:`text-[10px] font-semibold uppercase tracking-wide px-2 py-0.5 rounded-full shrink-0 ${e.printer.connected?`bg-green-500/20 text-green-500`:`bg-bambu-dark-tertiary text-bambu-gray`}`,children:e.printer.connected?f(`inventory.connected`):f(`inventory.offline`)})]}),e.printer.connected?t.length===0?(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray italic py-1`,children:f(`inventory.noKProfilesMatch`)}):(0,Y.jsxs)(`div`,{className:`grid gap-x-3 gap-y-1.5 items-center`,style:{gridTemplateColumns:`3.5rem repeat(${v(e).length}, minmax(0, 1fr))`},children:[(0,Y.jsx)(`span`,{}),v(e).map(e=>(0,Y.jsx)(`span`,{className:`text-[11px] font-semibold uppercase tracking-wide text-bambu-gray`,children:e.label},e.extruder)),m.diameters.map(n=>(0,Y.jsxs)(J.Fragment,{children:[(0,Y.jsxs)(`span`,{className:`text-xs font-mono text-bambu-gray`,children:[n,`mm`]}),v(e).map(r=>{let i=t.filter(e=>(e.extruder_id??0)===r.extruder&&((e.nozzle_diameter??``).trim()||`0.4`)===n),o=K(e.printer.id,r.extruder,n),s=a.get(o);if(i.length===0)return(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray/50 px-2 py-1.5`,title:f(`inventory.noKProfilesMatch`),children:`—`},o);let c=cn(e,r.extruder),l=on(s?.nozzle_id),u=!!(c&&l&&c!==l);return(0,Y.jsxs)(`select`,{title:u?f(`inventory.kProfileFlowMismatch`,{profile:sn(l),fitted:sn(c)}):void 0,"aria-label":`${e.printer.name} ${r.label} ${n}mm`,value:s?String(s.cali_idx):``,onChange:t=>{let a=i.find(e=>String(e.cali_idx)===t.target.value)??null;S(e.printer.id,r.extruder,n,a)},className:`min-w-0 px-2 py-1.5 bg-bambu-dark-secondary border rounded-lg text-sm text-white focus:outline-none focus:border-bambu-green ${u?`border-amber-500/60`:`border-bambu-dark-tertiary`}`,children:[(0,Y.jsx)(`option`,{value:``,children:f(`inventory.kProfileNotSet`)}),i.map(e=>{let t=sn(on(e.nozzle_id));return(0,Y.jsx)(`option`,{value:e.cali_idx,children:`${t?`[${t}] `:``}${e.name||e.filament_id} K=${e.k_value.toFixed(3)}`},e.cali_idx)})]},o)})]},n))]}):(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray italic py-1`,children:f(`inventory.printerOffline`)})]},e.printer.id)}):(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray italic`,children:f(`inventory.selectMaterialFirst`)})]})]})})]})]})}function fn(e){let t=H(e);return t?t.toLocaleDateString(`en-GB`,{day:`2-digit`,month:`2-digit`,year:`2-digit`})+` `+t.toLocaleTimeString(`en-GB`,{hour:`2-digit`,minute:`2-digit`}):``}var pn={completed:`text-bambu-green`,failed:`text-red-700 dark:text-red-400`,aborted:`text-yellow-700 dark:text-yellow-400`};function mn({spoolId:e}){let{t}=c(),n=l(),{showToast:i}=te(),{data:a,isLoading:o}=u({queryKey:[`spool-usage`,e],queryFn:()=>r.getSpoolUsageHistory(e)}),s=d({mutationFn:()=>r.clearSpoolUsageHistory(e),onSuccess:()=>{n.invalidateQueries({queryKey:[`spool-usage`,e]}),i(t(`inventory.historyCleared`),`success`)}});return o?(0,Y.jsx)(`div`,{className:`flex justify-center py-4`,children:(0,Y.jsx)(F,{className:`w-5 h-5 animate-spin text-bambu-green`})}):!a||a.length===0?(0,Y.jsxs)(`div`,{className:`text-center py-4 text-bambu-gray text-sm`,children:[(0,Y.jsx)(Oe,{className:`w-5 h-5 mx-auto mb-2 opacity-50`}),t(`inventory.noUsageHistory`)]}):(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(`h4`,{className:`text-sm font-medium text-white`,children:t(`inventory.usageHistory`)}),(0,Y.jsxs)(V,{variant:`ghost`,size:`sm`,onClick:()=>s.mutate(),disabled:s.isPending,className:`text-xs text-bambu-gray hover:text-red-700 dark:hover:text-red-400`,children:[(0,Y.jsx)(be,{className:`w-3 h-3 mr-1`}),t(`inventory.clearHistory`)]})]}),(0,Y.jsx)(`div`,{className:`max-h-48 overflow-y-auto space-y-1`,children:a.map(e=>(0,Y.jsxs)(`div`,{className:`flex items-center justify-between p-2 rounded bg-bambu-dark/50 text-xs`,children:[(0,Y.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Y.jsx)(`span`,{className:`text-bambu-gray`,children:fn(e.created_at)}),e.print_name&&(0,Y.jsx)(`span`,{className:`text-white ml-2 truncate`,title:e.print_name,children:e.print_name})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0 ml-2`,children:[(0,Y.jsxs)(`span`,{className:`text-white font-medium`,children:[e.weight_used.toFixed(1),`g`]}),(0,Y.jsxs)(`span`,{className:`text-bambu-gray`,children:[`(`,e.percent_used,`%)`]}),(0,Y.jsx)(`span`,{className:pn[e.status]||`text-bambu-gray`,children:e.status})]})]},e.id))})]})}var hn={tag_uid:null,tray_uuid:null,tag_type:null,data_origin:null};function gn({isOpen:e,onClose:t,spool:n,mode:i,printersWithCalibrations:a=[],currencySymbol:s,onSpoolsCreated:f,spoolmanMode:p=!1,spoolsQueryKey:m=[`inventory-spools`]}){let{t:h}=c(),g=l(),{showToast:_}=te(),v=()=>Ie(g,m),y=i===`edit`,b=i===`copy`,[x,S]=(0,J.useState)(ut),[C,w]=(0,J.useState)({}),[T,E]=(0,J.useState)(`filament`),[D,O]=(0,J.useState)(!1),[ee,k]=(0,J.useState)(!1),[A,j]=(0,J.useState)(!1),[M,N]=(0,J.useState)(!1),[ne,I]=(0,J.useState)([]),[L,re]=(0,J.useState)(!1),[R,ie]=(0,J.useState)(!1),[ae,oe]=(0,J.useState)(1),[se,z]=(0,J.useState)(!1);(0,J.useEffect)(()=>{z(!1)},[e,n?.id]);let[ce,le]=(0,J.useState)(!1),[ue,de]=(0,J.useState)(!1),[fe,pe]=(0,J.useState)([]),[B,ge]=(0,J.useState)(new Set),[ve,ye]=(0,J.useState)(``),[be,xe]=(0,J.useState)([]),[Se,Ce]=(0,J.useState)([]),[U,we]=(0,J.useState)([]),[Te,Ee]=(0,J.useState)([]),[De,Oe]=(0,J.useState)([]),[Ae,je]=(0,J.useState)([]),[Ne,Pe]=(0,J.useState)([]),[Fe,Le]=(0,J.useState)(!1),[ze,Ve]=(0,J.useState)(new Map),[He,Ue]=(0,J.useState)(new Map),[We,Ge]=(0,J.useState)(``),Ke=a.length>0?a:Ne,qe=ze.size+He.size,{data:Je=[],isLoading:Xe,error:W}=u({queryKey:[`spoolman-inventory-filaments`],queryFn:()=>r.getSpoolmanInventoryFilaments(),enabled:p&&e,staleTime:6e4,retry:!1});(0,J.useEffect)(()=>{je(Tt())},[]),(0,J.useEffect)(()=>{let t=!1;return e&&((async()=>{de(!0);try{let[e,n]=await Promise.allSettled([(async()=>(await r.getCloudStatus()).is_authenticated?{connected:!0,presets:await r.getFilamentPresets()}:{connected:!1,presets:[]})(),(async()=>(await r.orcaCloudStatus()).connected?{connected:!0,presets:(await r.orcaCloudListProfiles()).filament}:{connected:!1,presets:[]})()]);if(t)return;let i=e.status===`fulfilled`&&e.value.connected,a=n.status===`fulfilled`&&n.value.connected,o=e.status===`fulfilled`?e.value.presets:[],s=n.status===`fulfilled`?n.value.presets:[];le(i||a),pe([...o,...s]),ge(new Set(s.map(e=>e.setting_id)))}catch(e){if(t)return;console.error(`Failed to fetch cloud presets:`,e),le(!1)}finally{t||de(!1)}})(),r.getSpoolCatalog().then(xe).catch(console.error),r.getColorCatalog().then(Oe).catch(console.error),r.getLocalPresets().then(e=>we(e.filament)).catch(console.error),r.getBuiltinFilaments().then(Ee).catch(console.error),r.getLocations().then(e=>Ce(e.map(e=>({id:e.id,name:e.name})))).catch(console.error),a.length===0&&(async()=>{Le(!0);try{let e=await r.getPrinters(),n=await Promise.all(e.map(e=>r.getPrinterStatus(e.id).catch(()=>null))),i=await Promise.all(e.map(async(e,t)=>{let r=n[t],i=r?.connected??!1,a=[];return i&&(a=await wt(e.id,r)),{printer:{...e,connected:i},calibrations:a,nozzles:r?.nozzles}}));t||Pe(i)}catch(e){console.error(`Failed to fetch printer calibrations:`,e)}finally{t||Le(!1)}})()),()=>{t=!0}},[e,a.length]);let Ze=(0,J.useMemo)(()=>Et(fe,new Set,U,Te,B),[fe,U,Te,B]),Qe=(0,J.useMemo)(()=>{let e=St(fe,U),t=De.map(e=>e.manufacturer?.trim()).filter(e=>!!e),n=new Set([...e,...t]);return Array.from(n).sort((e,t)=>e.localeCompare(t))},[fe,U,De]),$e=(0,J.useMemo)(()=>{let e=De.map(e=>e.material?.trim()).filter(e=>!!e),t=new Set([...Ot,...e]);return Array.from(t).sort((e,t)=>e.localeCompare(t))},[De]),et=(0,J.useMemo)(()=>{let e=[];for(let t of De){let n=t.manufacturer?.trim(),r=t.material?.trim();n&&r&&e.push({brand:n,material:r})}for(let t of fe){let n=Dt(t.name);n.brand&&n.material&&e.push({brand:n.brand,material:n.material})}for(let t of U){let n=Dt(t.name),r=t.filament_vendor?.trim()||n.brand,i=n.material;r&&i&&e.push({brand:r,material:i})}return e},[fe,De,U]),tt=(0,J.useMemo)(()=>{let e=new Map;for(let t of et){let n=t.brand.toLowerCase(),r=t.material.toLowerCase();e.has(n)||e.set(n,new Set),e.get(n).add(r)}return e},[et]),nt=(0,J.useMemo)(()=>{let e=new Map;for(let t of et){let n=t.brand.toLowerCase(),r=t.material.toLowerCase();e.has(r)||e.set(r,new Set),e.get(r).add(n)}return e},[et]),rt=(0,J.useMemo)(()=>xt(Qe,x.brand),[Qe,x.brand]),it=(0,J.useMemo)(()=>xt($e,x.material),[$e,x.material]),at=(0,J.useMemo)(()=>ht(rt,x.material,nt),[rt,x.material,nt]),ot=(0,J.useMemo)(()=>ht(it,x.brand,tt),[it,x.brand,tt]),ct=(0,J.useMemo)(()=>yt(x.slicer_filament,Ze),[x.slicer_filament,Ze]);(0,J.useEffect)(()=>{if(e){if(n){let e=n.rgba&&/^[0-9A-Fa-f]{8}$/.test(n.rgba)?n.rgba:`808080FF`;if(S({material:n.material||``,subtype:n.subtype||``,brand:n.brand||``,color_name:n.color_name_is_synthesized?``:n.color_name||``,rgba:e,extra_colors:n.extra_colors||``,effect_type:n.effect_type||``,label_weight:n.label_weight||1e3,core_weight:n.core_weight??250,core_weight_catalog_id:n.core_weight_catalog_id??null,weight_used:b?0:n.weight_used||0,slicer_filament:n.slicer_filament||``,note:n.note||``,cost_per_kg:n.cost_per_kg??null,category:n.category||``,low_stock_threshold_pct:n.low_stock_threshold_pct??null,material_number:n.material_number||``,location_id:n.location_id??null,last_dried_at:(()=>{let e=b?null:H(n.last_dried_at);return e?_e(e):``})(),spoolman_filament_id:null}),ye(n.slicer_filament_name||n.slicer_filament||``),n.k_profiles&&n.k_profiles.length>0){let e=new Map;for(let t of n.k_profiles){if(t.cali_idx===null||t.cali_idx===void 0)continue;let n=(t.nozzle_diameter||``).trim()||`0.4`,r=t.extruder??0;e.set(K(t.printer_id,r,n),{cali_idx:t.cali_idx,filament_id:``,setting_id:t.setting_id||``,name:t.name||``,k_value:t.k_value,n_coef:0,extruder_id:r,nozzle_diameter:n,nozzle_id:t.nozzle_type||``})}Ve(e)}else Ve(new Map);I((n.suppliers??[]).map(e=>({supplier_id:e.supplier_id,supplier_name:e.supplier_name,supplier_article_number:e.supplier_article_number??``,quoted_price_per_kg:e.quoted_price_per_kg,is_purchase_source:b?!1:e.is_purchase_source})))}else S(ut),ye(``),Ve(new Map),I([]);ie(!1),oe(1),w({}),E(`filament`),Ge(``),Ue(new Map),O(!1),N(!1),k(b&&n?.core_weight_is_inherited===!1),j(!1),re(!1)}},[e,n,i,b]),(0,J.useEffect)(()=>{if(!e||!n)return;let t=!1;return(p?r.getSpoolmanFilamentPresets:r.getSpoolFilamentPresets)(n.id).then(e=>{if(t)return;let n=new Map;for(let t of e)n.set(gt(t.printer_model,t.nozzle_diameter||``),{code:t.slicer_filament||``,name:t.slicer_filament_name||``});Ue(n)}).catch(e=>{t||(console.error(`Failed to load filament preset overrides:`,e),_(h(`inventory.filamentPresetsLoadFailed`),`warning`))}),()=>{t=!0}},[e,n?.id,p]),(0,J.useEffect)(()=>{if(!e||!n||A||x.location_id!=null)return;let t=n.storage_location?.trim();if(!t||Se.length===0)return;let r=Se.find(e=>e.name.toLowerCase()===t.toLowerCase());r&&S(e=>e.location_id===r.id?e:{...e,location_id:r.id})},[e,n,Se,x.location_id,A]);let pt=(e,t)=>{let n=st.has(e);p&&n&&x.spoolman_filament_id!==null&&_(h(`inventory.spoolmanFilamentUnlinked`),`info`),S(r=>({...r,[e]:t,...p&&n&&r.spoolman_filament_id!==null?{spoolman_filament_id:null}:{}})),e===`weight_used`&&O(!0),e===`core_weight`&&k(!0),e===`location_id`&&j(!0),e===`last_dried_at`&&N(!0),C[e]&&w(t=>({...t,[e]:void 0}))},mt=e=>{let t=e.material||``,n=e.name||``,r=t&&n.startsWith(t)?n.slice(t.length).trim():n,i=(e.color_hex??``).replace(`#`,``).toUpperCase(),a=/^[0-9A-F]{6}(?:[0-9A-F]{2})?$/.test(i)?i:`808080`,o=a.length===8?a:`${a}FF`;S(n=>({...n,spoolman_filament_id:e.id,material:t,subtype:r,brand:e.vendor?.name||``,rgba:o,color_name:e.color_name||``,label_weight:e.weight??n.label_weight})),_(h(`inventory.spoolmanFilamentSelected`),`success`)},vt=e=>{je(t=>_t(e,t))},Ct=d({mutationFn:e=>p?r.createSpoolmanInventorySpool(e):r.createSpool(e),onSuccess:async e=>{e?.id&&(!await Kt(e.id)||!await Gt(e.id))||(await v(),f&&f([e]),_(h(`inventory.spoolCreated`),`success`),t())},onError:e=>{e instanceof o&&e.status===503?_(h(`inventory.spoolmanUnreachable`),`error`):_(h(`inventory.saveFailed`),`error`)}}),At=d({mutationFn:({data:e,qty:t})=>p?r.bulkCreateSpoolmanInventorySpools(e,t):r.bulkCreateSpools(e,t),onSuccess:async e=>{let n=p&&`created`in e?e:null,r=n?n.created:e;if(ze.size>0||He.size>0)for(let e of r)await Kt(e.id);if(Wt)for(let e of r)await Gt(e.id);await v(),f&&f(r),n&&n.failed_count>0?_(h(`inventory.spoolsPartiallyCreated`,{created:r.length,total:n.requested_count}),`warning`):_(h(`inventory.spoolsCreated`,{count:r.length}),`success`),t()},onError:e=>{e instanceof o&&e.status===503?_(h(`inventory.spoolmanUnreachable`),`error`):_(h(`inventory.saveFailed`),`error`)}}),jt=d({mutationFn:e=>p?r.updateSpoolmanInventorySpool(n.id,e):r.updateSpool(n.id,e),onSuccess:async()=>{n?.id&&(!await Kt(n.id)||!await Gt(n.id))||(await v(),_(h(`inventory.spoolUpdated`),`success`),t())},onError:e=>{e instanceof o&&e.status===503?_(h(`inventory.spoolmanUnreachable`),`error`):_(h(`inventory.saveFailed`),`error`)}}),Mt=d({mutationFn:()=>p?r.updateSpoolmanInventorySpool(n.id,hn):r.updateSpool(n.id,hn),onSuccess:async()=>{await v(),_(h(`inventory.rfidCleared`,`RFID tag cleared`),`success`),t()},onError:e=>{e instanceof o&&e.status===503?_(h(`inventory.spoolmanUnreachable`),`error`):_(h(`inventory.tagClearFailed`),`error`)}}),{data:Nt,isLoading:Pt}=u({queryKey:[`spool-assignments`],queryFn:()=>r.getAssignments(),enabled:e&&y&&!p}),{data:Ft,isLoading:It}=u({queryKey:[`spoolman-slot-assignments-all`],queryFn:()=>r.getSpoolmanSlotAssignments(),enabled:e&&y&&p}),Lt=(()=>{if(n)return p?Ft?.find(e=>e.spoolman_spool_id===n.id):Nt?.find(e=>e.spool_id===n.id)})(),Rt=p?It:Pt,{data:X}=u({queryKey:[`inventory-spools`],queryFn:()=>r.getSpools(!0),enabled:e}),{data:Z}=u({queryKey:[`settings`],queryFn:r.getSettings,enabled:e}),{data:zt}=u({queryKey:[`slicerPrinterModels`],queryFn:r.getSlicerPrinterModels,enabled:e,staleTime:1/0}),Bt=(()=>{let e=new Set;for(let t of X??[]){let n=t.category?.trim();n&&e.add(n)}return Array.from(e).sort((e,t)=>e.localeCompare(t))})(),Vt=(()=>{let e=new Set;for(let t of X??[]){let n=t.material_number?.trim();n&&e.add(n)}return Array.from(e).sort((e,t)=>e.localeCompare(t,void 0,{numeric:!0}))})(),Ht=Z?.low_stock_threshold??20,Ut=d({mutationFn:async()=>{if(!Lt)throw Error(`No assignment`);if(p){if(!n)throw Error(`No spool`);await r.unassignSpoolmanSlot(n.id);return}await r.unassignSpool(Lt.printer_id,Lt.ams_id,Lt.tray_id)},onSuccess:async()=>{p?(await g.invalidateQueries({queryKey:[`spoolman-slot-assignments-all`]}),await g.invalidateQueries({queryKey:[`spoolman-slot-assignments`]})):await g.invalidateQueries({queryKey:[`spool-assignments`]}),_(h(`inventory.unassignSuccess`,`Spool unassigned`),`success`),t()},onError:e=>{_(e.message,`error`)}}),Wt=L||b,Gt=async e=>{if(!Wt)return!0;let t=p?r.setSpoolmanSpoolSuppliers:r.setSpoolSuppliers;try{return await t(e,ne.map(e=>({supplier_id:e.supplier_id,supplier_article_number:e.supplier_article_number.trim()||null,quoted_price_per_kg:e.quoted_price_per_kg,is_purchase_source:e.is_purchase_source}))),!0}catch(e){return console.error(`SpoolFormModal.saveSupplierLinks failed:`,e),_(h(`inventory.suppliers.saveFailed`),`error`),!1}},Kt=async e=>{let t=p?r.saveSpoolmanKProfiles:r.saveSpoolKProfiles,n=p?r.saveSpoolmanFilamentPresets:r.saveSpoolFilamentPresets,i=[];for(let[e,t]of ze){let[n,r,a]=e.split(`:`);i.push({printer_id:parseInt(n),extruder:parseInt(r),nozzle_diameter:a||`0.4`,nozzle_type:on(t.nozzle_id),k_value:t.k_value,name:t.name||null,cali_idx:t.cali_idx,setting_id:t.setting_id||null})}let a=[];for(let[e,t]of He){let{model:n,diameter:r}=bt(e);n&&a.push({printer_model:n,nozzle_diameter:r,slicer_filament:t.code||null,slicer_filament_name:t.name||null})}try{await t(e,i)}catch(e){return console.error(`Failed to save K-profiles:`,e),_(h(`inventory.kProfileSaveFailed`),`warning`),!1}try{await n(e,a)}catch(e){return console.error(`Failed to save filament preset overrides:`,e),_(h(`inventory.filamentPresetSaveFailed`),`warning`),!1}return!0};if((0,J.useEffect)(()=>{if(!e)return;let n=e=>{e.key===`Escape`&&!se&&t()};return document.addEventListener(`keydown`,n),()=>document.removeEventListener(`keydown`,n)},[e,t,se]),!e)return null;let qt=()=>{let e=dt(x,R,p,i);if(!e.isValid){w(e.errors),(e.errors.slicer_filament||e.errors.material||e.errors.brand||e.errors.subtype)&&E(`filament`);return}let t=ct?.displayName||ve||null,n={material:x.material||null,subtype:x.subtype||null,brand:x.brand||null,color_name:x.color_name||null,rgba:x.rgba||null,extra_colors:x.extra_colors||null,effect_type:x.effect_type||null,label_weight:x.label_weight,...p?ee?{core_weight:x.core_weight}:{}:{core_weight:x.core_weight,core_weight_catalog_id:x.core_weight_catalog_id},slicer_filament:x.slicer_filament||null,slicer_filament_name:t,nozzle_temp_min:null,nozzle_temp_max:null,note:x.note||null,cost_per_kg:x.cost_per_kg,category:x.category.trim()||null,low_stock_threshold_pct:x.low_stock_threshold_pct,material_number:x.material_number.trim()||null,...p?{spoolman_filament_id:x.spoolman_filament_id}:{}};(!y||D)&&(n.weight_used=x.weight_used),(!y||A)&&(n.location_id=x.location_id),y&&M&&(n.last_dried_at=x.last_dried_at?new Date(x.last_dried_at).toISOString():null),y?jt.mutate(n):ae>1?At.mutate({data:n,qty:ae}):Ct.mutate(n)},Jt=Ct.isPending||At.isPending||jt.isPending||Mt.isPending||Ut.isPending;return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[(0,Y.jsx)(`div`,{className:`absolute inset-0 bg-black/60 backdrop-blur-sm`,onClick:t}),(0,Y.jsxs)(`div`,{className:`relative w-full max-w-5xl mx-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl shadow-2xl max-h-[90vh] flex flex-col`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary flex-shrink-0`,children:[(0,Y.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-baseline gap-2`,children:[h(y?`inventory.editSpool`:b?`inventory.copySpool`:`inventory.addSpool`),y&&n&&(0,Y.jsxs)(`span`,{className:`text-sm font-mono text-bambu-gray`,children:[`#`,n.id]})]}),(0,Y.jsx)(`button`,{onClick:t,className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,Y.jsx)(he,{className:`w-5 h-5`})})]}),i===`create`&&(0,Y.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2 border-b border-bambu-dark-tertiary flex-shrink-0`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(Re,{className:`w-4 h-4 text-amber-600 dark:text-amber-400`}),(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:h(`inventory.quickAdd`)})]}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>{ie(!R),R||E(`filament`)},className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors ${R?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,children:(0,Y.jsx)(`span`,{className:`inline-block h-3.5 w-3.5 rounded-full bg-white transition-transform ${R?`translate-x-4`:`translate-x-0.5`}`})})]}),(0,Y.jsxs)(`div`,{className:`flex border-b border-bambu-dark-tertiary flex-shrink-0`,children:[(0,Y.jsxs)(`button`,{onClick:()=>E(`filament`),className:`flex-1 px-4 py-2.5 text-sm font-medium flex items-center justify-center gap-2 transition-colors ${T===`filament`?`text-bambu-green border-b-2 border-bambu-green`:`text-bambu-gray hover:text-white`}`,children:[(0,Y.jsx)(q,{className:`w-4 h-4`}),h(`inventory.filamentInfoTab`)]}),!R&&(0,Y.jsxs)(`button`,{onClick:()=>E(`appearance`),className:`flex-1 px-4 py-2.5 text-sm font-medium flex items-center justify-center gap-2 transition-colors ${T===`appearance`?`text-bambu-green border-b-2 border-bambu-green`:`text-bambu-gray hover:text-white`}`,children:[(0,Y.jsx)(Be,{className:`w-4 h-4`}),h(`inventory.colorAndCostTab`)]}),!R&&(0,Y.jsxs)(`button`,{onClick:()=>E(`printers`),className:`flex-1 px-4 py-2.5 text-sm font-medium flex items-center justify-center gap-2 transition-colors ${T===`printers`?`text-bambu-green border-b-2 border-bambu-green`:`text-bambu-gray hover:text-white`}`,children:[(0,Y.jsx)(Re,{className:`w-4 h-4`}),h(`inventory.printersTab`),qe>0&&(0,Y.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded-full bg-bambu-green/20 text-bambu-green`,children:qe})]})]}),(0,Y.jsx)(`div`,{className:`p-4 overflow-y-auto flex-1`,style:{scrollbarGutter:`stable`},children:T===`filament`?(0,Y.jsxs)(`div`,{className:`space-y-6`,children:[p&&!y&&(0,Y.jsx)(`div`,{children:W?(0,Y.jsx)(`p`,{className:`text-sm text-red-700 dark:text-red-400 px-1`,children:h(`inventory.spoolmanCatalogLoadFailed`)}):(0,Y.jsx)(an,{filaments:Je,isLoading:Xe,selectedId:x.spoolman_filament_id,onSelect:mt})}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h3`,{className:`text-sm font-semibold text-bambu-gray uppercase tracking-wide mb-3`,children:h(`inventory.filamentInfo`)}),(0,Y.jsx)(G,{formData:x,updateField:pt,cloudAuthenticated:ce,loadingCloudPresets:ue,presetInputValue:ve,setPresetInputValue:ye,selectedPresetOption:ct,filamentOptions:Ze,availableBrands:rt,availableMaterials:it,suggestedBrands:at,suggestedMaterials:ot,quickAdd:R,detailsRequired:!R&&!p&&i===`create`,quantity:ae,onQuantityChange:oe,errors:C})]})]}):T===`appearance`?(0,Y.jsxs)(`div`,{className:`space-y-6`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h3`,{className:`text-sm font-semibold text-bambu-gray uppercase tracking-wide mb-3`,children:h(`inventory.color`)}),(0,Y.jsx)(lt,{formData:x,updateField:pt,recentColors:Ae,onColorUsed:vt,catalogColors:De})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h3`,{className:`text-sm font-semibold text-bambu-gray uppercase tracking-wide mb-3`,children:h(`inventory.additional`)}),(0,Y.jsx)(ft,{formData:x,updateField:pt,spoolCatalog:be,currencySymbol:s,availableCategories:Bt,availableMaterialNumbers:Vt,availableLocations:Se,showLastDried:y,onCreateLocation:async e=>{try{let t=await r.createLocation({name:e});return Ce(e=>[...e,{id:t.id,name:t.name}].sort((e,t)=>e.name.localeCompare(t.name))),await Ye(g),{id:t.id,name:t.name}}catch(e){return console.error(e),_((e instanceof Error?e.message:h(`locations.saveFailed`))||h(`locations.saveFailed`),`error`),null}},globalLowStockThreshold:Ht,spoolmanMode:p})]}),(0,Y.jsx)(`div`,{children:(0,Y.jsx)(rn,{links:ne,onChange:e=>{I(e),re(!0)},currencySymbol:s})}),y&&n&&!p&&(0,Y.jsx)(`div`,{children:(0,Y.jsx)(mn,{spoolId:n.id})})]}):(0,Y.jsx)(dn,{formData:x,printersWithCalibrations:Ke,filamentOptions:Ze,modelPresets:He,setModelPresets:Ue,selectedProfiles:ze,setSelectedProfiles:Ve,selectedGroupId:We,setSelectedGroupId:Ge,printerModels:zt,isLoading:Fe})}),(0,Y.jsxs)(`div`,{className:`flex gap-2 p-4 border-t border-bambu-dark-tertiary flex-shrink-0`,children:[y&&(0,Y.jsxs)(`div`,{className:`flex gap-2 mr-auto`,children:[(0,Y.jsxs)(V,{variant:`secondary`,onClick:()=>Mt.mutate(),disabled:Jt||!(n?.tag_uid||n?.tray_uuid),children:[(0,Y.jsx)(ke,{className:`w-4 h-4`}),h(`inventory.clearRfid`,`Clear RFID Tag`)]}),Lt?(0,Y.jsxs)(V,{variant:`secondary`,onClick:()=>Ut.mutate(),disabled:Jt||Rt,children:[(0,Y.jsx)(me,{className:`w-4 h-4`}),h(`inventory.unassignSpool`,`Unassign`)]}):(0,Y.jsxs)(V,{variant:`secondary`,onClick:()=>z(!0),disabled:Jt||Rt,children:[(0,Y.jsx)(P,{className:`w-4 h-4`}),h(`inventory.assignSpool`,`Assign Spool`)]})]}),(0,Y.jsxs)(`div`,{className:`flex gap-2 ml-auto`,children:[(0,Y.jsx)(V,{variant:`secondary`,onClick:t,children:h(`common.cancel`)}),(0,Y.jsx)(V,{onClick:qt,disabled:Jt,children:Jt?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(F,{className:`w-4 h-4 animate-spin`}),h(`common.saving`)]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(Me,{className:`w-4 h-4`}),h(y?`common.save`:b?`inventory.copySpool`:`inventory.addSpool`)]})})]})]})]})]}),y&&n&&(0,Y.jsx)(kt,{isOpen:se,onClose:()=>z(!1),spool:n,printerId:null,variant:`dialog`,spoolmanMode:p})]})}var Q=[{value:`ams_holder_74x33`,i18nKey:`amsHolderSmall`,fallbackLabel:`AMS holder — small (74 × 33 mm)`,fallbackHint:`Single label per page; matches the printable label from MakerWorld model 752566 (AMS Filament Label Holder).`},{value:`ams_holder_75x55`,i18nKey:`amsHolderLarge`,fallbackLabel:`AMS holder — large (75 × 55 mm)`,fallbackHint:`Single label per page; fits the cardstock-insert variant of the AMS Filament Label Holder. Roomy enough for swatch, brand, material, ID, and QR code.`},{value:`box_40x30`,i18nKey:`box40x30`,fallbackLabel:`Box label (40 × 30 mm)`,fallbackHint:`Single label per page; common DK/Brother roll size, good for filament-bag and storage-bin labels.`},{value:`box_62x29`,i18nKey:`box`,fallbackLabel:`Box label (62 × 29 mm)`,fallbackHint:`Single label per page; sized for Brother PT/QL and Dymo small labels.`},{value:`avery_l7160`,i18nKey:`averyL7160`,fallbackLabel:`Avery L7160 — A4 sheet (38.1 × 63.5 mm × 21)`,fallbackHint:`EU sheet stock; 21 labels per A4 page.`},{value:`avery_5160`,i18nKey:`avery5160`,fallbackLabel:`Avery 5160 — US Letter sheet (25.4 × 66.7 mm × 30)`,fallbackHint:`US sheet stock; 30 labels per Letter page.`}],_n={avery_l7160:21,avery_5160:30},vn=[203,300,600],yn={brand:{i18nKey:`brand`,fallback:`Brand`},material:{i18nKey:`material`,fallback:`Material and subtype`},hex:{i18nKey:`hex`,fallback:`Colour code`},name:{i18nKey:`name`,fallback:`Colour or filament name`},location:{i18nKey:`location`,fallback:`Storage location`},material_number:{i18nKey:`materialNumber`,fallback:`Material number`},temps:{i18nKey:`temps`,fallback:`Nozzle temperature`},weight:{i18nKey:`weight`,fallback:`Net weight`},note:{i18nKey:`note`,fallback:`Note`},added:{i18nKey:`added`,fallback:`Date added`},qr:{i18nKey:`qr`,fallback:`QR code`},spool_id:{i18nKey:`spoolId`,fallback:`Spool ID`}},bn=`bambuddy-label-print-options`,xn={template:Q[0].value,fields:{},monochrome:!1,format:`pdf`,dpi:300};function Sn(){let e;try{e=JSON.parse(localStorage.getItem(bn)??`null`)}catch{return xn}if(!e||typeof e!=`object`)return xn;let t=e,n=Q.map(e=>e.value),r={};if(t.fields&&typeof t.fields==`object`)for(let[e,i]of Object.entries(t.fields))!n.includes(e)||!Array.isArray(i)||(r[e]=i.filter(e=>a.includes(e)));return{template:n.includes(t.template)?t.template:xn.template,fields:r,monochrome:t.monochrome===!0,format:t.format===`png`?`png`:`pdf`,dpi:vn.includes(t.dpi)?t.dpi:xn.dpi}}function Cn(e){try{localStorage.setItem(bn,JSON.stringify(e))}catch{}}function wn(e,t){return e.fields[t]??i}function Tn(e){let t=window.URL.createObjectURL(e);if(!window.open(t,`_blank`)){let e=document.createElement(`a`);e.href=t,e.download=`bambuddy-labels.pdf`,document.body.appendChild(e),e.click(),document.body.removeChild(e)}setTimeout(()=>window.URL.revokeObjectURL(t),6e4)}function En(e,t){let n=window.URL.createObjectURL(e),r=document.createElement(`a`);r.href=n,r.download=`bambuddy-labels-${t}.${e.type===`application/zip`?`zip`:`png`}`,document.body.appendChild(r),r.click(),document.body.removeChild(r),setTimeout(()=>window.URL.revokeObjectURL(n),6e4)}function Dn(e){return Ke(e)}function On(e){return Ve(e.color_name,e.rgba,e.color_name_is_synthesized)}function $(e){return`${On(e)??`${e.material}${e.subtype?` ${e.subtype}`:``}`}${e.brand?` · ${e.brand}`:``}`}function kn(e){return[On(e),e.color_name,e.material,e.subtype,e.brand,`#${e.id}`].filter(Boolean).join(` `).toLowerCase()}function An(e){if(!e)return[1,0];let t=e.replace(/^#/,``).slice(0,6);if(t.length!==6)return[1,0];let n=parseInt(t.slice(0,2),16),r=parseInt(t.slice(2,4),16),i=parseInt(t.slice(4,6),16);if([n,r,i].some(Number.isNaN))return[1,0];let a=n/255,o=r/255,s=i/255,c=Math.max(a,o,s),l=Math.min(a,o,s),u=(c+l)/2,d=c-l;if((d===0?0:d/(1-Math.abs(2*u-1)))<.1)return[1,u];let f=0;return f=c===a?(o-s)/d%6:c===o?(s-a)/d+2:(a-o)/d+4,f*=60,f<0&&(f+=360),[0,f]}function jn({isOpen:e,onClose:t,availableSpools:n,initialSelectedIds:o,spoolmanMode:s}){let{t:l}=c(),u=Je(),{showToast:d}=te(),[f,p]=(0,J.useState)(!1),[m,h]=(0,J.useState)(new Set),[g,_]=(0,J.useState)(``),[v,y]=(0,J.useState)(``),[b,x]=(0,J.useState)(`id`),[S,C]=(0,J.useState)(xn),[w,T]=(0,J.useState)(`1`),[E,D]=(0,J.useState)(null),[O,ee]=(0,J.useState)(!1),[k,A]=(0,J.useState)(null),j=(0,J.useRef)(null);(0,J.useEffect)(()=>{if(e){let e=new Set(n.map(e=>e.id));h(new Set(o.filter(t=>e.has(t)))),_(``),y(``),x(`id`),C(Sn()),T(`1`),p(!1)}},[e]);let M=(0,J.useMemo)(()=>{let e=[...n];return b===`color`?(e.sort((e,t)=>{let n=An(e.rgba),r=An(t.rgba);return n[0]===r[0]?n[1]===r[1]?e.id-t.id:n[1]-r[1]:n[0]-r[0]}),e):(e.sort((e,t)=>e.id-t.id),e)},[n,b]),N=(0,J.useMemo)(()=>{let e=new Set;for(let t of M)t.material&&e.add(t.material.toUpperCase());return[...e].sort()},[M]),P=(0,J.useMemo)(()=>{let e=g.trim().toLowerCase();return M.filter(t=>!(v&&(t.material||``).toUpperCase()!==v||e&&!kn(t).includes(e)))},[M,g,v,u]),ne=P.length>0&&P.every(e=>m.has(e.id)),I=S.template,L=wn(S,I),re=L.join(`,`),R=M.find(e=>m.has(e.id))?.id??null;function ie(e){j.current&&window.URL.revokeObjectURL(j.current),j.current=e,D(e)}if((0,J.useEffect)(()=>{if(!e||R===null){ie(null),A(null),ee(!1);return}let t=new AbortController;ee(!0);let n=window.setTimeout(async()=>{let e={spool_id:R,template:I,monochrome:S.monochrome,fields:re?re.split(`,`):[]};try{let n=s?await r.previewSpoolmanSpoolLabel(e,t.signal):await r.previewSpoolLabel(e,t.signal);if(t.signal.aborted)return;ie(window.URL.createObjectURL(n)),A(null)}catch(e){if(t.signal.aborted)return;ie(null),A(e instanceof Error?e.message:String(e))}finally{t.signal.aborted||ee(!1)}},250);return()=>{window.clearTimeout(n),t.abort()}},[e,R,I,re,S.monochrome,s]),(0,J.useEffect)(()=>()=>{j.current&&window.URL.revokeObjectURL(j.current)},[]),!e)return null;let ae=m.size,oe=ae===0,z=_n[I],ce=Number(w),le=z===void 0||Number.isInteger(ce)&&ce>=1&&ce<=z,ue=Q.find(e=>e.value===I)??Q[0];function de(e){C(t=>{let n={...t,...e};return Cn(n),n})}function fe(e){let t=a.filter(t=>e.includes(t));de({fields:{...S.fields,[I]:t}})}function pe(e){fe(L.includes(e)?L.filter(t=>t!==e):[...L,e])}function B(e){h(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function me(){h(e=>{let t=new Set(e);for(let e of P)t.add(e.id);return t})}function ge(){h(e=>{let t=new Set(e);for(let e of P)t.delete(e.id);return t})}function H(){h(new Set)}async function _e(){if(oe||f||!le)return;let e={spool_ids:M.filter(e=>m.has(e.id)).map(e=>e.id),template:I,monochrome:S.monochrome,starting_position:z===void 0?1:ce,fields:L,format:S.format,dpi:S.dpi};p(!0);try{let n=s?await r.printSpoolmanSpoolLabels(e):await r.printSpoolLabels(e);S.format===`pdf`?Tn(n):En(n,I),t()}catch(e){d(l(`inventory.labels.error`,`Could not generate labels: {{msg}}`,{msg:e instanceof Error?e.message:String(e)}),`error`)}finally{p(!1)}}let ve=e=>`px-2 py-0.5 text-xs rounded-full border transition ${e?`bg-bambu-green text-bambu-dark border-bambu-green`:`bg-bambu-dark text-bambu-gray border-bambu-dark-tertiary hover:border-bambu-gray`}`;return(0,Y.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-start sm:items-center justify-center p-4 overflow-y-auto`,children:[(0,Y.jsx)(`div`,{className:`absolute inset-0 bg-black/60 backdrop-blur-sm`,onClick:t}),(0,Y.jsxs)(`div`,{"data-testid":`label-template-picker-panel`,className:`relative w-full max-w-5xl bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl shadow-2xl max-h-[90vh] overflow-clip flex flex-col my-auto`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(U,{className:`w-5 h-5 text-bambu-green`}),(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:l(`inventory.labels.title`,`Print spool labels`)}),ae>0&&(0,Y.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[`(`,l(`inventory.labels.selectedCount`,`{{count}} selected`,{count:ae}),`)`]})]}),(0,Y.jsx)(`button`,{onClick:t,className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,"aria-label":l(`common.close`,`Close`),children:(0,Y.jsx)(he,{className:`w-5 h-5`})})]}),(0,Y.jsxs)(`div`,{className:`flex-1 min-h-0 overflow-y-auto md:overflow-hidden grid grid-cols-1 md:grid-cols-2`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-col min-h-0 md:border-r border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`div`,{className:`p-4 space-y-2 border-b border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsx)(se,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`}),(0,Y.jsx)(`input`,{type:`search`,value:g,onChange:e=>_(e.target.value),placeholder:l(`inventory.labels.searchPlaceholder`,`Search name, brand, or #ID`),className:`w-full pl-9 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray focus:outline-none focus:border-bambu-green`})]}),N.length>1&&(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray mr-1`,children:l(`inventory.labels.filterByMaterial`,`Material:`)}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>y(``),className:`px-2 py-0.5 text-xs rounded-full border transition ${v===``?`bg-bambu-green text-bambu-dark border-bambu-green`:`bg-bambu-dark text-bambu-gray border-bambu-dark-tertiary hover:border-bambu-gray`}`,children:l(`inventory.labels.allMaterials`,`All`)}),N.map(e=>(0,Y.jsx)(`button`,{type:`button`,onClick:()=>y(e),className:`px-2 py-0.5 text-xs rounded-full border transition ${v===e?`bg-bambu-green text-bambu-dark border-bambu-green`:`bg-bambu-dark text-bambu-gray border-bambu-dark-tertiary hover:border-bambu-gray`}`,children:e},e))]}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray mr-1`,children:l(`inventory.labels.sortBy.label`)}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>x(`id`),className:`px-2 py-0.5 text-xs rounded-full border transition ${b===`id`?`bg-bambu-green text-bambu-dark border-bambu-green`:`bg-bambu-dark text-bambu-gray border-bambu-dark-tertiary hover:border-bambu-gray`}`,children:l(`inventory.labels.sortBy.id`)}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>x(`color`),className:`px-2 py-0.5 text-xs rounded-full border transition ${b===`color`?`bg-bambu-green text-bambu-dark border-bambu-green`:`bg-bambu-dark text-bambu-gray border-bambu-dark-tertiary hover:border-bambu-gray`}`,children:l(`inventory.labels.sortBy.color`)})]})]}),(0,Y.jsxs)(`div`,{className:`px-4 pt-3 pb-2 flex items-center justify-between gap-3 flex-wrap`,children:[(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:l(`inventory.labels.pickSpools`,`Pick which spools to print labels for:`)}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-3 text-xs`,children:[(0,Y.jsx)(`button`,{type:`button`,onClick:ne?ge:me,disabled:P.length===0,className:`text-bambu-green hover:underline disabled:opacity-50 disabled:no-underline disabled:cursor-not-allowed`,children:ne?l(`inventory.labels.deselectVisible`,`Deselect visible`):l(`inventory.labels.selectVisible`,`Select all visible ({{count}})`,{count:P.length})}),(0,Y.jsx)(`button`,{type:`button`,onClick:H,disabled:ae===0,className:`text-bambu-gray hover:text-white hover:underline disabled:opacity-50 disabled:no-underline disabled:cursor-not-allowed`,children:l(`inventory.labels.clearAll`,`Clear all`)})]})]}),(0,Y.jsx)(`div`,{className:`flex-1 overflow-y-auto px-2 pb-2 min-h-0 max-h-72 md:max-h-none`,children:P.length===0?(0,Y.jsx)(`div`,{className:`text-center text-sm text-bambu-gray py-6`,children:M.length===0?l(`inventory.labels.noSpoolsToShow`,`No spools to show. Adjust your filter and try again.`):l(`inventory.labels.noMatches`,`No spools match the current search or filter.`)}):(0,Y.jsx)(`ul`,{className:`space-y-0.5`,children:P.map(e=>{let t=m.has(e.id);return(0,Y.jsx)(`li`,{children:(0,Y.jsxs)(`label`,{className:`flex items-center gap-3 px-2 py-1.5 rounded hover:bg-bambu-dark-tertiary/50 cursor-pointer`,children:[t?(0,Y.jsx)(Ae,{className:`w-4 h-4 text-bambu-green shrink-0`}):(0,Y.jsx)(Ee,{className:`w-4 h-4 text-bambu-gray shrink-0`}),(0,Y.jsx)(`input`,{type:`checkbox`,checked:t,onChange:()=>B(e.id),className:`sr-only`}),(0,Y.jsx)(`span`,{className:`w-4 h-4 rounded border border-black/20 shrink-0`,style:Dn(e.rgba)}),(0,Y.jsx)(`span`,{className:`flex-1 min-w-0 truncate text-sm text-white`,children:$(e)}),(0,Y.jsxs)(`span`,{className:`text-xs font-mono text-bambu-gray shrink-0`,children:[`#`,e.id]})]})},e.id)})})})]}),(0,Y.jsxs)(`div`,{className:`md:overflow-y-auto p-4 space-y-4 border-t md:border-t-0 border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(`label`,{htmlFor:`label-template`,className:`text-sm font-medium text-white`,children:l(`inventory.labels.template`,`Label size`)}),(0,Y.jsx)(`select`,{id:`label-template`,"data-testid":`label-template-select`,value:I,onChange:e=>de({template:e.target.value}),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`,children:Q.map(e=>(0,Y.jsx)(`option`,{value:e.value,children:l(`inventory.labels.templates.${e.i18nKey}.label`,e.fallbackLabel)},e.value))}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:l(`inventory.labels.templates.${ue.i18nKey}.hint`,ue.fallbackHint)})]}),(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium text-white`,children:R===null?l(`inventory.labels.preview`,`Preview`):l(`inventory.labels.previewOf`,`Preview of #{{id}}`,{id:R})}),(0,Y.jsxs)(`div`,{"data-testid":`label-preview`,className:`relative flex items-center justify-center min-h-40 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary`,children:[R===null?(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray text-center`,children:l(`inventory.labels.previewNoSelection`,`Select a spool to see its label.`)}):k?(0,Y.jsx)(`span`,{className:`text-sm text-red-400 text-center`,children:l(`inventory.labels.previewError`,`Could not render the preview: {{msg}}`,{msg:k})}):E?(0,Y.jsx)(`img`,{src:E,alt:l(`inventory.labels.previewAlt`,`Label preview`),className:`max-h-56 max-w-full object-contain bg-white shadow`}):null,O&&(0,Y.jsx)(F,{className:`absolute top-2 right-2 w-4 h-4 animate-spin text-bambu-green`})]}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:l(`inventory.labels.previewHint`,`Lines that don't fit on this label size are left out.`)})]}),(0,Y.jsxs)(`fieldset`,{className:`space-y-2`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Y.jsx)(`legend`,{className:`text-sm font-medium text-white`,children:l(`inventory.labels.content`,`Print on the label`)}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>fe(i),className:`text-xs text-bambu-green hover:underline`,children:l(`inventory.labels.resetFields`,`Reset to default`)})]}),(0,Y.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-x-3 gap-y-1`,children:a.map(e=>{let t=L.includes(e),{i18nKey:n,fallback:r}=yn[e];return(0,Y.jsxs)(`label`,{className:`flex items-center gap-2 py-0.5 cursor-pointer select-none`,children:[t?(0,Y.jsx)(Ae,{className:`w-4 h-4 text-bambu-green shrink-0`}):(0,Y.jsx)(Ee,{className:`w-4 h-4 text-bambu-gray shrink-0`}),(0,Y.jsx)(`input`,{type:`checkbox`,"data-testid":`label-field-${e}`,checked:t,onChange:()=>pe(e),className:`sr-only`}),(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:l(`inventory.labels.fields.${n}`,r)})]},e)})})]}),(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsxs)(`label`,{className:`inline-flex items-center gap-2 cursor-pointer select-none`,children:[S.monochrome?(0,Y.jsx)(Ae,{className:`w-4 h-4 text-bambu-green shrink-0`}):(0,Y.jsx)(Ee,{className:`w-4 h-4 text-bambu-gray shrink-0`}),(0,Y.jsx)(`input`,{type:`checkbox`,checked:S.monochrome,onChange:e=>de({monochrome:e.target.checked}),className:`sr-only`}),(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:l(`inventory.labels.monochrome`,`Monochrome (black & white printer)`)}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:l(`inventory.labels.monochromeHint`,`Drops the colour swatch and widens the text`)})]}),z!==void 0&&(0,Y.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,Y.jsx)(`label`,{htmlFor:`label-starting-position`,className:`text-sm text-white whitespace-nowrap pt-1.5`,children:l(`inventory.labels.startingPosition`,`Starting label position`)}),(0,Y.jsx)(`input`,{id:`label-starting-position`,"data-testid":`label-starting-position`,type:`number`,min:1,max:z,step:1,value:w,onChange:e=>T(e.target.value),"aria-describedby":`label-starting-position-help`,className:`w-20 px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:outline-none focus:border-bambu-green`}),(0,Y.jsx)(`div`,{id:`label-starting-position-help`,"data-testid":`label-starting-position-status`,className:`text-xs pt-1.5 ${le?`text-bambu-gray`:`text-red-400`}`,children:le?ce===1?l(`inventory.labels.startingPositionFirst`,`Printing starts at position 1.`):l(`inventory.labels.startingPositionSkipped`,`Positions 1 through {{lastPosition}} will be left blank on the first sheet.`,{lastPosition:ce-1}):l(`inventory.labels.startingPositionInvalid`,`Enter a whole number from 1 to {{capacity}}.`,{capacity:z})})]}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,Y.jsx)(`span`,{className:`text-sm text-white mr-1`,children:l(`inventory.labels.format`,`Output:`)}),(0,Y.jsx)(`button`,{type:`button`,"data-testid":`label-format-pdf`,"aria-pressed":S.format===`pdf`,onClick:()=>de({format:`pdf`}),className:ve(S.format===`pdf`),children:`PDF`}),(0,Y.jsx)(`button`,{type:`button`,"data-testid":`label-format-png`,"aria-pressed":S.format===`png`,onClick:()=>de({format:`png`}),className:ve(S.format===`png`),children:`PNG`}),S.format===`png`&&(0,Y.jsx)(`select`,{"data-testid":`label-dpi-select`,"aria-label":l(`inventory.labels.dpi`,`Resolution`),value:S.dpi,onChange:e=>de({dpi:Number(e.target.value)}),className:`ml-2 px-2 py-0.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-xs focus:outline-none focus:border-bambu-green`,children:vn.map(e=>(0,Y.jsxs)(`option`,{value:e,children:[e,` dpi`]},e))})]}),S.format===`png`&&(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:l(`inventory.labels.pngHint`,`For label printer software that takes images. Match your printer's resolution; several labels come as a ZIP.`)})]})]})]}),(0,Y.jsxs)(`div`,{className:`flex justify-end gap-2 px-5 py-3 border-t border-bambu-dark-tertiary`,children:[(0,Y.jsx)(V,{variant:`secondary`,onClick:t,disabled:f,children:l(`common.cancel`,`Cancel`)}),(0,Y.jsxs)(V,{"data-testid":`label-print-button`,onClick:_e,disabled:oe||f||!le,children:[f?(0,Y.jsx)(F,{className:`w-4 h-4 animate-spin`}):S.format===`pdf`?(0,Y.jsx)(U,{className:`w-4 h-4`}):(0,Y.jsx)(Qe,{className:`w-4 h-4`}),S.format===`pdf`?l(`inventory.labels.createPdf`,`Create PDF`):l(`inventory.labels.downloadPng`,`Download PNG`)]})]})]})]})}function Mn({onClose:e,onImported:t}){let{t:n}=c(),[i,a]=(0,J.useState)(null),[o,s]=(0,J.useState)(!1),[l,u]=(0,J.useState)(null),[d,f]=(0,J.useState)(!1),[p,m]=(0,J.useState)(!1),[h,g]=(0,J.useState)(null),_=(0,J.useRef)(null),v=async e=>{a(e),u(null),g(null),f(!0);try{u(await r.importSpoolsCsvPreview(e))}catch(e){g(e instanceof Error?e.message:n(`inventory.csv.previewError`,`Could not read the CSV file`))}finally{f(!1)}},y=e=>{let t=e.target.files?.[0];t&&v(t)},b=e=>{e.preventDefault(),s(!1);let t=e.dataTransfer.files?.[0];t&&v(t)},x=async()=>{if(i){m(!0),g(null);try{t((await r.importSpoolsCsv(i)).created)}catch(e){g(e instanceof Error?e.message:n(`inventory.csv.importError`,`Import failed`)),m(!1)}}},S=e=>e===`valid`?(0,Y.jsx)(A,{className:`w-4 h-4 text-green-500 flex-shrink-0`}):e===`error`?(0,Y.jsx)(D,{className:`w-4 h-4 text-red-500 flex-shrink-0`}):(0,Y.jsx)(We,{className:`w-4 h-4 text-bambu-gray flex-shrink-0`}),C=l?.valid_count??0;return(0,Y.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg w-full max-w-3xl border border-bambu-dark-tertiary flex flex-col max-h-[90vh]`,children:[(0,Y.jsxs)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary flex items-center justify-between`,children:[(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:n(`inventory.csv.modalTitle`,`Import spools from CSV`)}),(0,Y.jsx)(`button`,{onClick:e,className:`p-1 hover:bg-bambu-dark rounded`,children:(0,Y.jsx)(he,{className:`w-5 h-5 text-bambu-gray`})})]}),(0,Y.jsxs)(`div`,{className:`p-4 space-y-4 overflow-y-auto flex-1`,children:[(0,Y.jsxs)(`div`,{onDragOver:e=>{e.preventDefault(),s(!0)},onDragLeave:e=>{e.preventDefault(),s(!1)},onDrop:b,onClick:()=>_.current?.click(),className:`border-2 border-dashed rounded-lg p-6 text-center cursor-pointer transition-colors ${o?`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary hover:border-bambu-green/50`}`,children:[(0,Y.jsx)(Ge,{className:`w-9 h-9 mx-auto mb-2 ${o?`text-bambu-green`:`text-bambu-gray`}`}),i?(0,Y.jsxs)(`p`,{className:`text-white font-medium flex items-center justify-center gap-2`,children:[(0,Y.jsx)($e,{className:`w-4 h-4`}),` `,i.name]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`p`,{className:`text-white font-medium`,children:n(`inventory.csv.selectFile`,`Choose a CSV file or drag it here`)}),(0,Y.jsx)(`p`,{className:`text-xs text-bambu-gray/70 mt-1`,children:n(`inventory.csv.dragHint`,`Header: material (required), brand, subtype, color_name, rgba, …`)})]})]}),(0,Y.jsx)(`input`,{ref:_,type:`file`,accept:`.csv,text/csv`,className:`hidden`,onChange:y}),d&&(0,Y.jsxs)(`div`,{className:`flex items-center justify-center gap-2 text-bambu-gray py-4`,children:[(0,Y.jsx)(F,{className:`w-4 h-4 animate-spin`}),n(`inventory.csv.parsing`,`Reading file…`)]}),h&&(0,Y.jsxs)(`div`,{className:`p-3 bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30 rounded-lg flex items-start gap-3`,children:[(0,Y.jsx)(D,{className:`w-5 h-5 text-red-600 dark:text-red-400 mt-0.5 flex-shrink-0`}),(0,Y.jsx)(`p`,{className:`text-sm text-red-700 dark:text-red-300 break-words`,children:h})]}),l&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap gap-3 text-sm`,children:[(0,Y.jsx)(`span`,{className:`px-2 py-1 rounded bg-green-50 dark:bg-green-500/10 text-green-700 dark:text-green-400`,children:n(`inventory.csv.validCount`,`{{count}} valid`,{count:l.valid_count})}),(0,Y.jsx)(`span`,{className:`px-2 py-1 rounded bg-red-50 dark:bg-red-500/10 text-red-700 dark:text-red-400`,children:n(`inventory.csv.errorCount`,`{{count}} error`,{count:l.error_count})}),(0,Y.jsx)(`span`,{className:`px-2 py-1 rounded bg-bambu-dark text-bambu-gray`,children:n(`inventory.csv.skippedCount`,`{{count}} skipped`,{count:l.skipped_count})})]}),l.warnings.length>0&&(0,Y.jsx)(`div`,{className:`p-3 bg-yellow-50 dark:bg-yellow-500/10 border border-yellow-300 dark:border-yellow-500/30 rounded-lg space-y-1`,children:l.warnings.map((e,t)=>(0,Y.jsx)(`p`,{className:`text-xs text-yellow-700 dark:text-yellow-300`,children:e},t))}),l.rows.length>0&&(0,Y.jsx)(`div`,{className:`border border-bambu-dark-tertiary rounded-lg overflow-hidden`,children:(0,Y.jsx)(`div`,{className:`max-h-72 overflow-y-auto`,children:(0,Y.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,Y.jsx)(`thead`,{className:`bg-bambu-dark sticky top-0`,children:(0,Y.jsxs)(`tr`,{className:`text-left text-bambu-gray`,children:[(0,Y.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:n(`inventory.csv.colRow`,`Row`)}),(0,Y.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:n(`inventory.csv.colStatus`,`Status`)}),(0,Y.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:n(`inventory.material`,`Material`)}),(0,Y.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:n(`inventory.brand`,`Brand`)}),(0,Y.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:n(`inventory.csv.colColor`,`Color`)})]})}),(0,Y.jsx)(`tbody`,{children:l.rows.map(e=>(0,Y.jsxs)(`tr`,{className:`border-t border-bambu-dark-tertiary`,children:[(0,Y.jsx)(`td`,{className:`px-3 py-2 text-bambu-gray`,children:e.row_number}),(0,Y.jsx)(`td`,{className:`px-3 py-2`,children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[S(e.status),e.status===`error`&&e.reason&&(0,Y.jsx)(`span`,{className:`text-xs text-red-700 dark:text-red-400 break-words`,children:e.reason})]})}),(0,Y.jsx)(`td`,{className:`px-3 py-2 text-white`,children:e.material||`—`}),(0,Y.jsx)(`td`,{className:`px-3 py-2 text-white`,children:e.brand||`—`}),(0,Y.jsx)(`td`,{className:`px-3 py-2`,children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.rgba&&(0,Y.jsx)(`span`,{className:`inline-block w-4 h-4 rounded-full border border-bambu-dark-tertiary flex-shrink-0`,style:Ke(e.rgba)}),(0,Y.jsx)(`span`,{className:`text-white`,children:e.color_name||`—`}),e.resolved_color&&!e.cross_material_color&&(0,Y.jsx)(`span`,{title:n(`inventory.csv.colorResolved`,`Color filled from catalog`),children:(0,Y.jsx)(je,{className:`w-3.5 h-3.5 text-bambu-green flex-shrink-0`})}),e.cross_material_color&&(0,Y.jsx)(`span`,{title:n(`inventory.csv.colorCrossMaterial`,`Color taken from a different material — no exact match in catalog`),children:(0,Y.jsx)(B,{className:`w-3.5 h-3.5 text-yellow-500 flex-shrink-0`})}),e.duplicate_of_existing&&(0,Y.jsx)(`span`,{title:n(`inventory.csv.duplicateExisting`,`A spool with this material, brand and color already exists — it will still be imported as a new spool`),children:(0,Y.jsx)(M,{className:`w-3.5 h-3.5 text-amber-600 dark:text-amber-400 flex-shrink-0`})})]})})]},e.row_number))})]})})})]})]}),(0,Y.jsxs)(`div`,{className:`p-4 border-t border-bambu-dark-tertiary flex justify-end gap-2`,children:[(0,Y.jsx)(V,{variant:`secondary`,onClick:e,disabled:p,children:n(`common.cancel`)}),(0,Y.jsx)(V,{onClick:x,disabled:!l||C===0||p,children:p?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(F,{className:`w-4 h-4 mr-2 animate-spin`}),n(`inventory.csv.importing`,`Importing…`)]}):C>0?n(`inventory.csv.importValidRows`,`Import {{count}} valid rows`,{count:C}):n(`inventory.csv.noValidRows`,`No valid rows`)})]})]})})}function Nn({open:e,onClose:t}){let{t:n}=c(),{showToast:i}=te(),a=l(),{data:s=[],isLoading:d,isError:f}=u({queryKey:Xe,queryFn:r.getSuppliers,enabled:e}),[p,m]=(0,J.useState)(``),[h,g]=(0,J.useState)(!1),[_,v]=(0,J.useState)(null),[y,b]=(0,J.useState)(``),[x,S]=(0,J.useState)(``),[C,T]=(0,J.useState)(``),[E,D]=(0,J.useState)(``),[O,ee]=(0,J.useState)(!1),[k,A]=(0,J.useState)(null);if((0,J.useEffect)(()=>{if(!e)return;let n=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,n),()=>window.removeEventListener(`keydown`,n)},[e,t]),!e)return null;let j=s.filter(e=>e.name.toLowerCase().includes(p.toLowerCase())),M=()=>{b(``),S(``),T(``),D(``)},N=()=>({name:y.trim(),website:x.trim()||null,customer_number:C.trim()||null,note:E.trim()||null}),P=async()=>{if(!y.trim()){i(n(`inventory.suppliers.nameRequired`),`error`);return}ee(!0);try{await r.createSupplier(N()),await He(a),g(!1),M(),i(n(`inventory.suppliers.added`),`success`)}catch(e){console.error(`SuppliersModal.handleAdd failed:`,e),i(n(e instanceof o&&e.status===409?`inventory.suppliers.duplicateName`:`inventory.suppliers.addFailed`),`error`)}finally{ee(!1)}},ne=e=>{v(e.id),b(e.name),S(e.website??``),T(e.customer_number??``),D(e.note??``)},I=()=>{v(null),M()},L=async e=>{if(!y.trim()){i(n(`inventory.suppliers.nameRequired`),`error`);return}ee(!0);try{await r.updateSupplier(e,N()),await He(a),I(),i(n(`inventory.suppliers.updated`),`success`)}catch(e){console.error(`SuppliersModal.handleUpdate failed:`,e),i(n(e instanceof o&&e.status===409?`inventory.suppliers.duplicateName`:`inventory.suppliers.updateFailed`),`error`)}finally{ee(!1)}},re=async()=>{if(k)try{await r.deleteSupplier(k.id),await He(a),i(n(`inventory.suppliers.deleted`),`success`)}catch(e){console.error(`SuppliersModal.handleDelete failed:`,e),e instanceof o&&e.status===409?i(n(`inventory.suppliers.deleteBlocked`,{count:k.spool_count}),`error`):i(n(`inventory.suppliers.deleteFailed`),`error`)}finally{A(null)}},R=(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(`input`,{type:`text`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`,placeholder:n(`inventory.suppliers.namePlaceholder`),value:y,maxLength:200,onChange:e=>b(e.target.value)}),(0,Y.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Y.jsx)(`input`,{type:`text`,className:`flex-1 min-w-0 px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`,placeholder:n(`inventory.suppliers.websitePlaceholder`),value:x,maxLength:500,onChange:e=>S(e.target.value)}),(0,Y.jsx)(`input`,{type:`text`,className:`w-40 px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`,placeholder:n(`inventory.suppliers.customerNumberPlaceholder`),value:C,maxLength:100,onChange:e=>T(e.target.value)})]}),(0,Y.jsx)(`input`,{type:`text`,className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`,placeholder:n(`inventory.suppliers.notePlaceholder`),value:E,maxLength:500,onChange:e=>D(e.target.value)})]});return(0,Y.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[(0,Y.jsx)(`div`,{className:`absolute inset-0 bg-black/60`,onClick:t}),(0,Y.jsxs)(`div`,{className:`relative w-full max-w-3xl mx-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl shadow-2xl max-h-[90vh] flex flex-col`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":`suppliers-modal-title`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-4 px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(Ft,{className:`w-5 h-5 text-bambu-gray`}),(0,Y.jsx)(`h2`,{id:`suppliers-modal-title`,className:`text-lg font-semibold text-white`,children:n(`inventory.suppliers.title`)}),(0,Y.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[`(`,s.length,`)`]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsxs)(`button`,{onClick:()=>{g(!0),v(null),M()},className:`px-3 py-1.5 text-sm bg-bambu-green text-white rounded-lg hover:bg-bambu-green/80 transition-colors flex items-center gap-1.5`,children:[(0,Y.jsx)(Pe,{className:`w-4 h-4`}),(0,Y.jsx)(`span`,{className:`hidden sm:inline`,children:n(`common.add`)})]}),(0,Y.jsx)(`button`,{onClick:t,className:`p-1.5 rounded hover:bg-bambu-dark text-bambu-gray hover:text-white transition-colors`,"aria-label":n(`common.close`),children:(0,Y.jsx)(he,{className:`w-5 h-5`})})]})]}),(0,Y.jsxs)(`div`,{className:`flex-1 min-h-0 overflow-y-auto px-6 py-4 space-y-4`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`inventory.suppliers.description`)}),(0,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsx)(se,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,Y.jsx)(`input`,{type:`text`,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`,placeholder:n(`inventory.suppliers.search`),value:p,onChange:e=>m(e.target.value)})]}),h&&(0,Y.jsxs)(`div`,{className:`p-4 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary space-y-3`,children:[(0,Y.jsx)(`h3`,{className:`text-sm font-medium text-white`,children:n(`inventory.suppliers.addNew`)}),R,(0,Y.jsxs)(`div`,{className:`flex gap-2 justify-end`,children:[(0,Y.jsx)(`button`,{onClick:()=>{g(!1),M()},className:`px-3 py-2 rounded-lg text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary`,children:n(`common.cancel`)}),(0,Y.jsxs)(`button`,{onClick:P,disabled:O,className:`px-3 py-2 bg-bambu-green text-white rounded-lg hover:bg-bambu-green/80 flex items-center gap-1`,children:[O?(0,Y.jsx)(F,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(w,{className:`w-4 h-4`}),n(`common.add`)]})]})]}),d?(0,Y.jsxs)(`div`,{className:`flex items-center justify-center py-8 text-bambu-gray`,children:[(0,Y.jsx)(F,{className:`w-5 h-5 animate-spin mr-2`}),n(`common.loading`)]}):f?(0,Y.jsxs)(`div`,{className:`flex items-center justify-center gap-2 py-8 text-sm text-red-400`,children:[(0,Y.jsx)(B,{className:`w-4 h-4`}),n(`inventory.suppliers.loadFailed`)]}):(0,Y.jsx)(`div`,{className:`border border-bambu-dark-tertiary rounded-lg`,children:(0,Y.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,Y.jsx)(`thead`,{className:`bg-bambu-dark sticky top-0`,children:(0,Y.jsxs)(`tr`,{children:[(0,Y.jsx)(`th`,{className:`px-4 py-2 text-left text-bambu-gray font-medium`,children:n(`common.name`)}),(0,Y.jsx)(`th`,{className:`px-4 py-2 text-left text-bambu-gray font-medium hidden sm:table-cell`,children:n(`inventory.suppliers.customerNumber`)}),(0,Y.jsx)(`th`,{className:`px-4 py-2 text-right text-bambu-gray font-medium w-20`,children:n(`inventory.suppliers.spools`)}),(0,Y.jsx)(`th`,{className:`px-4 py-2 w-24`})]})}),(0,Y.jsx)(`tbody`,{children:j.length===0?(0,Y.jsx)(`tr`,{children:(0,Y.jsx)(`td`,{colSpan:4,className:`px-4 py-8 text-center text-bambu-gray`,children:n(p?`inventory.suppliers.noMatch`:`inventory.suppliers.empty`)})}):j.map(e=>(0,Y.jsx)(`tr`,{className:`border-t border-bambu-dark-tertiary hover:bg-bambu-dark align-top`,children:_===e.id?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`td`,{className:`px-4 py-2`,colSpan:3,children:R}),(0,Y.jsx)(`td`,{className:`px-4 py-2`,children:(0,Y.jsxs)(`div`,{className:`flex justify-end gap-1`,children:[(0,Y.jsx)(`button`,{onClick:()=>L(e.id),disabled:O,className:`p-1.5 rounded hover:bg-green-500/20 text-green-500`,children:O?(0,Y.jsx)(F,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(w,{className:`w-4 h-4`})}),(0,Y.jsx)(`button`,{onClick:I,className:`p-1.5 rounded hover:bg-bambu-dark-tertiary text-bambu-gray`,children:(0,Y.jsx)(he,{className:`w-4 h-4`})})]})})]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`td`,{className:`px-4 py-2 text-white`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(`span`,{children:e.name}),e.website&&(0,Y.jsx)(`a`,{href:e.website,target:`_blank`,rel:`noopener noreferrer`,className:`text-bambu-gray hover:text-bambu-green`,title:e.website,children:(0,Y.jsx)(xe,{className:`w-3.5 h-3.5`})})]}),e.note&&(0,Y.jsx)(`div`,{className:`text-xs text-bambu-gray mt-0.5`,children:e.note})]}),(0,Y.jsx)(`td`,{className:`px-4 py-2 text-bambu-gray hidden sm:table-cell`,children:e.customer_number||`-`}),(0,Y.jsx)(`td`,{className:`px-4 py-2 text-right font-mono text-bambu-gray`,children:e.spool_count}),(0,Y.jsx)(`td`,{className:`px-4 py-2`,children:(0,Y.jsxs)(`div`,{className:`flex justify-end gap-1`,children:[(0,Y.jsx)(`button`,{onClick:()=>{ne(e),g(!1)},className:`p-1.5 rounded hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white`,children:(0,Y.jsx)(ye,{className:`w-4 h-4`})}),(0,Y.jsx)(`button`,{onClick:()=>A(e),className:`p-1.5 rounded bg-red-500/10 hover:bg-red-500/20 text-red-500`,children:(0,Y.jsx)(be,{className:`w-4 h-4`})})]})})]})},e.id))})]})})]})]}),k&&(0,Y.jsx)(Fe,{title:n(`inventory.suppliers.deleteTitle`),message:k.spool_count>0?n(`inventory.suppliers.deleteConfirmReferenced`,{name:k.name,count:k.spool_count}):n(`inventory.suppliers.deleteConfirm`,{name:k.name}),confirmText:n(`common.delete`),variant:`danger`,onConfirm:re,onCancel:()=>A(null)})]})}var Pn=[{id:`material`,type:`searchable`,labelKey:`inventory.material`},{id:`subtype`,type:`searchable`,labelKey:`inventory.subtype`},{id:`brand`,type:`searchable`,labelKey:`inventory.brand`},{id:`color_name`,type:`text`,labelKey:`inventory.colorName`},{id:`rgba`,type:`color`,labelKey:`inventory.color`,pattern:`^[0-9A-Fa-f]{6}([0-9A-Fa-f]{2})?$`},{id:`location_id`,type:`searchableClosed`,labelKey:`inventory.storageLocation`},{id:`slicer_filament_name`,type:`searchable`,labelKey:`inventory.slicerFilamentName`},{id:`slicer_filament`,type:`searchable`,labelKey:`inventory.slicerFilament`},{id:`cost_per_kg`,type:`number`,labelKey:`inventory.costPerKg`,min:0,step:.01},{id:`note`,type:`textarea`,labelKey:`inventory.note`},{id:`label_weight`,type:`number`,labelKey:`inventory.labelWeight`,min:1,step:1},{id:`core_weight`,type:`number`,labelKey:`inventory.coreWeight`,min:0,step:1},{id:`category`,type:`searchable`,labelKey:`inventory.category`,internalOnly:!0},{id:`low_stock_threshold_pct`,type:`number`,labelKey:`inventory.lowStockThresholdOverride`,min:1,max:99,step:1,internalOnly:!0},{id:`material_number`,type:`searchable`,labelKey:`inventory.materialNumber`,internalOnly:!0}];function Fn({value:e,onChange:t,options:n,allowCustom:r,placeholderKey:i,disabled:a}){let{t:o}=c(),s=(0,J.useRef)(null),[l,u]=(0,J.useState)(!1),[d,f]=(0,J.useState)(``);(0,J.useEffect)(()=>{if(!l)return;let e=e=>{s.current&&!s.current.contains(e.target)&&(u(!1),f(``))},t=e=>{e.key===`Escape`&&(u(!1),f(``))};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[l]);let p=l?d:n.find(t=>t.value===e)?.label??e,m=(0,J.useMemo)(()=>{if(!l)return n;let e=d.trim().toLowerCase();return e?n.filter(t=>t.label.toLowerCase().includes(e)||t.value.toLowerCase().includes(e)):n},[l,d,n]),h=l&&d.trim()&&!n.some(e=>e.value.toLowerCase()===d.trim().toLowerCase());return(0,Y.jsxs)(`div`,{className:`relative`,ref:s,children:[(0,Y.jsx)(`input`,{type:`text`,disabled:a,value:p,onChange:e=>{f(e.target.value),u(!0),r&&t(e.target.value)},onFocus:()=>{u(!0),f(``)},placeholder:i?o(i):void 0,className:`w-full px-3 py-2 pr-9 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray/50 focus:border-bambu-green focus:outline-none`}),(0,Y.jsx)(T,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50 pointer-events-none`}),l&&(0,Y.jsxs)(`div`,{className:`absolute z-50 left-0 right-0 mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-64 overflow-y-auto`,children:[m.length===0&&!r&&(0,Y.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:o(`inventory.noResults`)}),m.map(n=>(0,Y.jsx)(`button`,{type:`button`,className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${e===n.value?`bg-bambu-green/10 text-bambu-green`:`text-white`}`,onClick:()=>{t(n.value),u(!1),f(``)},children:n.label},n.value)),r&&h&&(0,Y.jsx)(`button`,{type:`button`,className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary text-bambu-green border-t border-bambu-dark-tertiary`,onClick:()=>{t(d.trim()),u(!1),f(``)},children:o(`inventory.bulk.useCustom`,{value:d.trim()})})]})]})}function In(...e){let t=new Set;for(let n of e)for(let e of n){let n=e?.trim();n&&t.add(n)}return Array.from(t).sort((e,t)=>e.localeCompare(t))}function Ln({isOpen:e,selectedCount:t,isPending:n,availableLocations:i,availableMaterials:a,availableSubtypes:o,availableBrands:s,availableCategories:l,availableMaterialNumbers:d,availableSlicerFilaments:f,availableSlicerFilamentNames:p,spoolmanMode:m=!1,onClose:h,onApply:g}){let{t:_}=c(),v=(0,J.useMemo)(()=>Pn.filter(e=>!(m&&e.internalOnly)),[m]),{data:y=[]}=u({queryKey:[`bulk-edit-cloud-presets`],enabled:e,staleTime:300*1e3,queryFn:async()=>{let e=[];try{if((await r.getCloudStatus()).is_authenticated){let t=await r.getFilamentPresets();e.push(...t)}}catch{}try{if((await r.orcaCloudStatus()).connected){let t=await r.orcaCloudListProfiles();e.push(...t.filament)}}catch{}return e}}),{data:b}=u({queryKey:[`bulk-edit-local-presets`],enabled:e,staleTime:300*1e3,queryFn:r.getLocalPresets}),{data:x=[]}=u({queryKey:[`builtin-filaments`],enabled:e,staleTime:300*1e3,queryFn:r.getBuiltinFilaments}),S=(0,J.useMemo)(()=>Et(y,new Set,b?.filament??[],x),[y,b,x]),[C,w]=(0,J.useState)({}),T=(0,J.useMemo)(()=>In(Ot,a).map(e=>({value:e,label:e})),[a]),E=(0,J.useMemo)(()=>In(pt,o).map(e=>({value:e,label:e})),[o]),D=(0,J.useMemo)(()=>In(vt,s).map(e=>({value:e,label:e})),[s]),O=(0,J.useMemo)(()=>In(l).map(e=>({value:e,label:e})),[l]),ee=(0,J.useMemo)(()=>In(d).map(e=>({value:e,label:e})),[d]),k=(0,J.useMemo)(()=>{let e=S.map(e=>({value:e.code,label:e.displayName})),t=f.filter(t=>!e.some(e=>e.value===t)).map(e=>({value:e,label:e}));return[...e,...t].sort((e,t)=>e.label.localeCompare(t.label))},[S,f]),te=(0,J.useMemo)(()=>{let e=S.map(e=>({value:e.displayName,label:e.displayName})),t=p.filter(t=>!e.some(e=>e.value===t)).map(e=>({value:e,label:e}));return[...e,...t].sort((e,t)=>e.label.localeCompare(t.label))},[S,p]),A=(0,J.useMemo)(()=>i.map(e=>({value:String(e.id),label:e.name})),[i]);if(!e)return null;let j=(e,t)=>{w(n=>({...n,[e]:t}))},M=e=>{w(t=>{let n={...t};return delete n[e],n})},N=(()=>{let e={};for(let t of v){let n=C[t.id];if(n===void 0)continue;let r=typeof n==`string`?n.trim():n;if(!(r===``||r===null))if(t.type===`number`){let n=Number(r);Number.isFinite(n)&&(e[t.id]=n)}else if(t.id===`location_id`){let n=Number(r);Number.isFinite(n)&&n>0&&(e[t.id]=n)}else if(t.id===`rgba`){let n=String(r).replace(/^#/,``),i=n.length===6?`${n}FF`:n;/^[0-9A-Fa-f]{8}$/.test(i)&&(e[t.id]=i.toUpperCase())}else e[t.id]=String(r)}return e})(),P=Object.keys(N).length>0,ne=v.some(e=>{let t=C[e.id];return t===void 0||t.trim()===``?!1:N[e.id]===void 0}),I=e=>e===`material`?T:e===`subtype`?E:e===`brand`?D:e===`category`?O:e===`material_number`?ee:e===`slicer_filament`?k:e===`slicer_filament_name`?te:e===`location_id`?A:[],L=e=>{let t=C[e.id]??``;if(e.type===`searchable`||e.type===`searchableClosed`)return(0,Y.jsx)(Fn,{value:t,onChange:t=>{t===``?M(e.id):j(e.id,t)},options:I(e.id),allowCustom:e.type===`searchable`,disabled:n});if(e.type===`textarea`)return(0,Y.jsx)(`textarea`,{disabled:n,value:t,onChange:t=>j(e.id,t.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray/50 focus:border-bambu-green focus:outline-none resize-none min-h-[60px]`});if(e.type===`color`){let r=t.trim().replace(/^#/,``),i=r.length===6?`${r}FF`:r,a=t.trim()!==``&&!/^[0-9A-Fa-f]{8}$/.test(i);return(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`input`,{type:`color`,disabled:n,value:`#${(t||`808080`).replace(/^#/,``).slice(0,6)}`,onChange:t=>j(e.id,t.target.value.replace(/^#/,``).toUpperCase()),className:`h-9 w-12 rounded cursor-pointer`}),(0,Y.jsx)(`input`,{type:`text`,disabled:n,value:t,onChange:t=>j(e.id,t.target.value.replace(/^#/,``).toUpperCase()),placeholder:`RRGGBB or RRGGBBAA`,className:`flex-1 px-3 py-2 bg-bambu-dark border rounded-lg text-white placeholder-bambu-gray/50 focus:outline-none ${a?`border-red-500 focus:border-red-500`:`border-bambu-dark-tertiary focus:border-bambu-green`}`,pattern:e.pattern})]}),a&&(0,Y.jsx)(`p`,{className:`mt-1 text-xs text-red-600 dark:text-red-400`,children:_(`inventory.bulk.invalidHex`)})]})}return(0,Y.jsx)(`input`,{type:e.type===`number`?`number`:`text`,disabled:n,value:t,onChange:t=>j(e.id,t.target.value),min:e.min,max:e.max,step:e.step,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray/50 focus:border-bambu-green focus:outline-none`})};return(0,Y.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center p-4 z-50`,onClick:n?void 0:h,children:(0,Y.jsxs)(`div`,{className:`w-full max-w-3xl bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg max-h-[90vh] flex flex-col`,onClick:e=>e.stopPropagation(),children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between p-5 border-b border-bambu-dark-tertiary`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:_(`inventory.bulk.editTitle`)}),(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray mt-0.5`,children:_(`inventory.bulk.editSubtitle`,{count:t})})]}),(0,Y.jsx)(`button`,{onClick:h,disabled:n,className:`p-1 text-bambu-gray hover:text-white transition-colors`,"aria-label":_(`common.close`),children:(0,Y.jsx)(he,{className:`w-5 h-5`})})]}),(0,Y.jsx)(`p`,{className:`px-5 pt-4 text-xs text-bambu-gray`,children:_(`inventory.bulk.editHint`)}),(0,Y.jsx)(`div`,{className:`flex-1 overflow-y-auto p-5 space-y-3`,children:v.map(e=>{let t=C[e.id]!==void 0;return(0,Y.jsxs)(`div`,{className:`flex items-start gap-3 rounded-md p-2 transition-colors ${t?`bg-bambu-green/5 border border-bambu-green/30`:`border border-transparent`}`,children:[(0,Y.jsx)(`div`,{className:`pt-2`,children:(0,Y.jsx)(`input`,{type:`checkbox`,className:`h-4 w-4 cursor-pointer`,checked:t,onChange:t=>{t.target.checked?j(e.id,``):M(e.id)},"aria-label":_(`inventory.bulk.toggleField`)})}),(0,Y.jsxs)(`div`,{className:`flex-1`,children:[(0,Y.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:_(e.labelKey)}),L(e)]})]},e.id)})}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-3 p-5 border-t border-bambu-dark-tertiary`,children:[(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:_(`inventory.bulk.changeCount`,{count:Object.keys(N).length})}),(0,Y.jsxs)(`div`,{className:`ml-auto flex gap-2`,children:[(0,Y.jsx)(V,{variant:`secondary`,onClick:h,disabled:n,children:_(`common.cancel`)}),(0,Y.jsx)(V,{onClick:()=>g(N),disabled:!P||n||ne,children:n?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(F,{className:`w-4 h-4 mr-2 animate-spin`}),_(`inventory.bulk.applyPending`)]}):_(`inventory.bulk.applyButton`,{count:t})})]})]})]})})}function Rn(e){let t=e[0],n=0,r=0,i=0;for(let t of e)n+=t.label_weight,r+=t.weight_used,i+=t.core_weight;return{...t,label_weight:n,weight_used:r,core_weight:i}}function zn(e){let t=new Set;for(let n of e)if(typeof n==`string`){let e=n.trim();e&&t.add(e)}return Array.from(t).sort((e,t)=>e.localeCompare(t))}function Bn(e){return`${e.material}|${e.subtype||``}|${e.brand||``}|${e.color_name||``}|${e.rgba||``}|${e.extra_colors||``}|${e.effect_type||``}|${e.label_weight}|${e.last_dried_at||``}`}var Vn=`bambuddy-inventory-columns`,Hn=`none`.padStart(65,`_`);function Un(e){return(e||``).toLowerCase().replace(/\d+/g,e=>e.padStart(64,`0`))}var Wn=[{id:`id`,label:`#`,visible:!0},{id:`added_time`,label:`Added`,visible:!0},{id:`encode_time`,label:`Encoded`,visible:!1},{id:`last_used_time`,label:`Last Used`,visible:!1},{id:`rgba`,label:`Color`,visible:!0},{id:`material`,label:`Material`,visible:!0},{id:`subtype`,label:`Subtype`,visible:!0},{id:`color_name`,label:`Color Name`,visible:!1},{id:`brand`,label:`Brand`,visible:!0},{id:`slicer_filament`,label:`Slicer Filament`,visible:!1},{id:`location`,label:`Location`,visible:!0},{id:`storage_location`,label:`Storage Location`,visible:!1},{id:`temperature`,label:`Temperature`,visible:!1},{id:`humidity`,label:`Humidity`,visible:!1},{id:`last_dried`,label:`Last Dried`,visible:!0},{id:`battery`,label:`Battery`,visible:!1},{id:`label_weight`,label:`Label`,visible:!0},{id:`net`,label:`Net`,visible:!0},{id:`gross`,label:`Gross`,visible:!1},{id:`added_full`,label:`Full`,visible:!1},{id:`used`,label:`Used`,visible:!1},{id:`printed_total`,label:`Printed Total`,visible:!1},{id:`printed_since_weight`,label:`Printed Since Weight`,visible:!1},{id:`note`,label:`Note`,visible:!1},{id:`material_number`,label:`Material No.`,visible:!1},{id:`suppliers`,label:`Suppliers`,visible:!1},{id:`pa_k`,label:`PA(K)`,visible:!0},{id:`tag_id`,label:`Tag ID`,visible:!1},{id:`data_origin`,label:`Data Origin`,visible:!1},{id:`tag_type`,label:`Linked Tag Type`,visible:!1},{id:`stock`,label:`Stock`,visible:!1},{id:`remaining`,label:`Remaining`,visible:!0},{id:`spool_name`,label:`Spool`,visible:!1},{id:`cost_per_kg`,label:`Cost/kg`,visible:!1},{id:`weight_check`,label:`Weight Check`,visible:!1}];function Gn(){try{let e=localStorage.getItem(Vn);if(e){let t=JSON.parse(e),n=new Set(Wn.map(e=>e.id)),r=new Set(t.map(e=>e.id)),i=[...t.filter(e=>n.has(e.id))];for(let e of Wn){if(r.has(e.id))continue;let t=Wn.indexOf(e),n=i.length;for(let e=t-1;e>=0;e--){let t=i.findIndex(t=>t.id===Wn[e].id);if(t!==-1){n=t+1;break}}i.splice(n,0,e)}return i}}catch{}return Wn.map(e=>({...e}))}function Kn(e){try{localStorage.setItem(Vn,JSON.stringify(e))}catch{}}function qn(e,t=!1){return t&&e>=1e3?`${(e/1e3).toFixed(1)}kg`:`${Math.round(e)}g`}var Jn={PLA:`bg-green-100 dark:bg-green-500/20 text-green-700 dark:text-green-400`,ABS:`bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400`,PETG:`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`,TPU:`bg-purple-100 dark:bg-purple-500/20 text-purple-700 dark:text-purple-400`,ASA:`bg-orange-100 dark:bg-orange-500/20 text-orange-700 dark:text-orange-400`,PA:`bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400`,PC:`bg-cyan-100 dark:bg-cyan-500/20 text-cyan-700 dark:text-cyan-400`,PET:`bg-sky-100 dark:bg-sky-500/20 text-sky-700 dark:text-sky-400`};function Yn(e){let t=[];return e.last_dried_temp!=null&&t.push(`${e.last_dried_temp}°C`),e.last_dried_hours!=null&&t.push(`${Number(e.last_dried_hours.toFixed(1))}h`),t.join(` · `)}function Xn(e,t=`system`){if(!e)return`-`;let n=H(e);return n?ge(n,t):`-`}var Zn={id:()=>`#`,added_time:()=>`Added`,encode_time:()=>`Encoded`,last_used_time:()=>`Last Used`,rgba:e=>e(`inventory.color`),material:e=>e(`inventory.material`),subtype:e=>e(`inventory.subtype`),color_name:e=>e(`inventory.colorName`),brand:e=>e(`inventory.brand`),slicer_filament:e=>e(`inventory.slicerFilament`),location:()=>`Location`,storage_location:e=>e(`inventory.storageLocation`),temperature:e=>e(`inventory.temperature`),humidity:e=>e(`inventory.humidity`),last_dried:e=>e(`inventory.lastDried`),battery:e=>e(`inventory.battery`),label_weight:e=>e(`inventory.labelWeight`),net:e=>e(`inventory.net`),gross:()=>`Gross`,added_full:()=>`Full`,used:e=>e(`inventory.weightUsed`),printed_total:()=>`Printed Total`,printed_since_weight:()=>`Printed Since Weight`,note:e=>e(`inventory.note`),material_number:e=>e(`inventory.materialNumber`),suppliers:e=>e(`inventory.suppliers.label`),pa_k:()=>`PA(K)`,tag_id:()=>`Tag ID`,data_origin:()=>`Data Origin`,tag_type:()=>`Linked Tag Type`,stock:e=>e(`inventory.stock`),remaining:e=>e(`inventory.remaining`),spool_name:e=>e(`inventory.spoolName`),cost_per_kg:e=>e(`inventory.costPerKg`),weight_check:e=>e(`inventory.weightCheck`)},Qn={id:({spool:e})=>(0,Y.jsx)(`span`,{className:`text-sm font-medium text-white`,children:e.id}),added_time:({spool:e,dateFormat:t})=>(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:Xn(e.created_at,t)}),encode_time:({spool:e,dateFormat:t})=>(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:Xn(e.encode_time,t)}),last_used_time:({spool:e,dateFormat:t})=>(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.last_used?Xn(e.last_used,t):`Never`}),last_dried:({spool:e,dateFormat:t})=>{if(!e.last_dried_at)return(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:`-`});let n=Yn(e);return(0,Y.jsxs)(`div`,{className:`text-sm text-bambu-gray`,children:[(0,Y.jsx)(`div`,{children:Xn(e.last_dried_at,t)}),n&&(0,Y.jsx)(`div`,{className:`text-xs text-bambu-gray/60`,children:n})]})},rgba:({spool:e})=>(0,Y.jsx)(`div`,{className:`flex items-center justify-center`,children:(0,Y.jsx)(Ze,{rgba:e.rgba,extraColors:e.extra_colors,effectType:e.effect_type,effectSize:`table`,subtype:e.subtype})}),material:({spool:e})=>(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:e.material}),subtype:({spool:e})=>(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.subtype||`-`}),color_name:({spool:e})=>(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:Ve(e.color_name,e.rgba,e.color_name_is_synthesized)||`-`}),brand:({spool:e})=>(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.brand||`-`}),slicer_filament:({spool:e})=>(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,title:e.slicer_filament||void 0,children:e.slicer_filament_name||e.slicer_filament||`-`}),location:({spool:e,assignmentMap:t})=>{let n=t[e.id];if(!n)return(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:`-`});let r=n.printer_name||`Printer ${n.printer_id}`,i=n.ams_id===254||n.ams_id===255,a=!i&&n.ams_id>=128;return(0,Y.jsxs)(`span`,{className:`inline-flex items-center px-1.5 py-0.5 rounded text-xs font-medium bg-purple-100 dark:bg-purple-500/20 text-purple-700 dark:text-purple-400`,children:[r,` `,Ce(n.ams_id,n.tray_id,a,i),n.ams_label?` (${n.ams_label})`:``]})},storage_location:({spool:e})=>e.storage_location?(0,Y.jsx)(`span`,{className:`inline-flex items-center px-1.5 py-0.5 rounded text-xs font-medium bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`,children:e.storage_location}):(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:`-`}),temperature:({spool:e,locationReadingsMap:t,t:n,colorizeLocationSensors:r,locationSensorAboveColor:i,locationSensorBelowColor:a,locationSensorOptimalColor:o})=>{let s=e.location_id?t[e.location_id]?.find(e=>e.device_class===`temperature`):void 0;return s?(0,Y.jsx)(`span`,{title:s.name,className:`text-sm ${ur(s,r,i,a,o)}`,children:lr(s,n)}):(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray/50`,children:`-`})},humidity:({spool:e,locationReadingsMap:t,t:n,colorizeLocationSensors:r,locationSensorAboveColor:i,locationSensorBelowColor:a,locationSensorOptimalColor:o})=>{let s=e.location_id?t[e.location_id]?.find(e=>e.device_class===`humidity`):void 0;return s?(0,Y.jsx)(`span`,{title:s.name,className:`text-sm ${ur(s,r,i,a,o)}`,children:lr(s,n)}):(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray/50`,children:`-`})},battery:({spool:e,locationReadingsMap:t,t:n,colorizeLocationSensors:r,locationSensorAboveColor:i,locationSensorBelowColor:a,locationSensorOptimalColor:o})=>{let s=e.location_id?t[e.location_id]?.find(e=>e.device_class===`battery`):void 0;return s?(0,Y.jsx)(`span`,{title:s.name,className:`text-sm ${ur(s,r,i,a,o)}`,children:lr(s,n)}):(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray/50`,children:`-`})},label_weight:({spool:e})=>(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:qn(e.label_weight)}),net:({remaining:e})=>(0,Y.jsx)(`span`,{className:`text-sm text-white`,children:qn(e)}),gross:({spool:e,remaining:t})=>(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:qn(t+e.core_weight)}),added_full:({spool:e})=>(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.added_full==null?`-`:e.added_full?`Yes`:`No`}),used:({spool:e})=>(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.weight_used>0?qn(e.weight_used):`-`}),printed_total:()=>(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray/50`,children:`-`}),printed_since_weight:()=>(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray/50`,children:`-`}),note:({spool:e})=>(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray max-w-[150px] truncate block`,title:e.note||void 0,children:e.note||`-`}),material_number:({spool:e})=>(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.material_number||`-`}),suppliers:({spool:e})=>{let t=e.suppliers??[];return t.length===0?(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:`-`}):(0,Y.jsx)(`div`,{className:`flex flex-wrap gap-1 max-w-[220px]`,children:[...t].sort((e,t)=>Number(t.is_purchase_source)-Number(e.is_purchase_source)).map(e=>(0,Y.jsx)(`span`,{title:e.supplier_article_number||void 0,className:`inline-flex items-center px-1.5 py-0.5 rounded-full text-[10px] font-medium ${e.is_purchase_source?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-gray/10 text-bambu-gray`}`,children:e.supplier_name},e.id))})},pa_k:({spool:e})=>(e.k_profiles?.length??0)===0?(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:`-`}):(0,Y.jsx)(`span`,{className:`inline-flex items-center px-1.5 py-0.5 rounded text-xs font-medium bg-bambu-green/20 text-bambu-green`,children:`K`}),tag_id:({spool:e})=>{let t=e.tag_uid||e.tray_uuid;return t?(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray font-mono`,title:t,children:t.length>12?`${t.slice(0,6)}...${t.slice(-4)}`:t}):(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray/50`,children:`-`})},data_origin:({spool:e})=>(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.data_origin||`-`}),tag_type:({spool:e})=>(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.tag_type||`-`}),stock:({spool:e,t})=>e.slicer_filament?(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:`-`}):(0,Y.jsx)(`span`,{className:`inline-flex items-center px-1.5 py-0.5 rounded text-xs font-medium bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-400`,children:t(`inventory.stock`)}),remaining:({remaining:e,pct:t})=>(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`div`,{className:`flex-1 h-2 bg-bambu-dark-tertiary rounded-full overflow-hidden`,children:(0,Y.jsx)(`div`,{className:`h-full rounded-full ${t>50?`bg-bambu-green`:t>20?`bg-yellow-500`:`bg-red-500`}`,style:{width:`${Math.min(t,100)}%`}})}),(0,Y.jsxs)(`span`,{className:`text-xs text-bambu-gray min-w-[40px] text-right`,children:[Math.round(e),`g`]})]}),spool_name:({spool:e,catalogMap:t})=>(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:(e.core_weight_catalog_id==null?void 0:t[e.core_weight_catalog_id])?.name||`-`}),cost_per_kg:({spool:e,currencySymbol:t})=>(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.cost_per_kg==null?`-`:`${t}${e.cost_per_kg.toFixed(2)}`}),weight_check:({spool:e,onSyncWeight:t})=>{let n=e.last_scale_weight;if(n==null)return(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray/50`,title:`No scale measurement`,children:`-`});let r=e.core_weight||0,i=Math.max(0,e.label_weight-e.weight_used)+r,a,o;n<r?(a=n-r,o=!0):(a=n-i,o=Math.abs(a)<=50);let s=a>0?`+${Math.round(a)}`:`${Math.round(a)}`,c=o?`Scale: ${Math.round(n)}g\nCalculated: ${Math.round(i)}g\nDifference: ${s}g (within tolerance)`:`Scale: ${Math.round(n)}g\nCalculated: ${Math.round(i)}g\nDifference: ${s}g (mismatch!)`;return(0,Y.jsxs)(`div`,{className:`flex items-center gap-1 text-sm font-medium ${o?`text-green-700 dark:text-green-400`:`text-yellow-700 dark:text-yellow-400`}`,title:c,children:[(0,Y.jsxs)(`span`,{children:[Math.round(n),`g`]}),o?(0,Y.jsx)(w,{className:`w-3 h-3`}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(B,{className:`w-3 h-3`}),t&&(0,Y.jsx)(`button`,{type:`button`,onClick:n=>{n.stopPropagation(),n.preventDefault(),t(e)},className:`p-1 hover:bg-bambu-green/20 rounded transition-colors text-bambu-green`,title:`Sync: trust scale weight and reset tracking`,children:(0,Y.jsx)(we,{className:`w-3.5 h-3.5`})})]})]})}},$n={id:e=>e.id,added_time:e=>e.created_at||``,encode_time:e=>e.encode_time||``,last_used_time:e=>e.last_used||``,last_dried:e=>e.last_dried_at||``,material:e=>(e.material||``).toLowerCase(),subtype:e=>(e.subtype||``).toLowerCase(),color_name:e=>(e.color_name||``).toLowerCase(),rgba:e=>W(e.rgba),brand:e=>(e.brand||``).toLowerCase(),slicer_filament:e=>(e.slicer_filament_name||e.slicer_filament||``).toLowerCase(),location:(e,t)=>{let n=t[e.id];if(!n)return``;let r=n.ams_id===254||n.ams_id===255,i=!r&&n.ams_id>=128,a=n.ams_label?` (${n.ams_label})`:``;return`${n.printer_name||``} ${Ce(n.ams_id,n.tray_id,i,r)}${a}`},storage_location:e=>(e.storage_location||``).toLowerCase(),label_weight:e=>e.label_weight,net:e=>Math.max(0,e.label_weight-e.weight_used),gross:e=>Math.max(0,e.label_weight-e.weight_used)+e.core_weight,used:e=>e.weight_used,remaining:e=>e.label_weight>0?Math.max(0,e.label_weight-e.weight_used)/e.label_weight:0,note:e=>(e.note||``).toLowerCase(),material_number:e=>Un(e.material_number),suppliers:e=>{let t=e.suppliers??[];return((t.find(e=>e.is_purchase_source)??t[0])?.supplier_name||``).toLowerCase()},data_origin:e=>(e.data_origin||``).toLowerCase(),tag_type:e=>(e.tag_type||``).toLowerCase(),stock:e=>+!!e.slicer_filament,spool_name:e=>e.core_weight_catalog_id??0,cost_per_kg:e=>e.cost_per_kg??0,weight_check:e=>{if(e.last_scale_weight==null)return-1;let t=Math.max(0,e.label_weight-e.weight_used)+e.core_weight;return Math.abs(e.last_scale_weight-t)},temperature:(e,t,n)=>(e.location_id?n[e.location_id]:void 0)?.find(e=>e.device_class===`temperature`)?.value??-1/0,humidity:(e,t,n)=>(e.location_id?n[e.location_id]:void 0)?.find(e=>e.device_class===`humidity`)?.value??-1/0,battery:(e,t,n)=>(e.location_id?n[e.location_id]:void 0)?.find(e=>e.device_class===`battery`)?.value??-1/0},er=`bambuddy-inventory-sort`;function tr(){try{let e=localStorage.getItem(er);if(e)return JSON.parse(e)}catch{}return null}function nr(e){try{e?localStorage.setItem(er,JSON.stringify(e)):localStorage.removeItem(er)}catch{}}function rr(){let{data:e}=u({queryKey:[`spoolman-settings`],queryFn:r.getSpoolmanSettings,staleTime:300*1e3}),t=e!==void 0;return(0,Y.jsx)(ir,{spoolmanMode:e?.spoolman_enabled===`true`&&!!e?.spoolman_url,spoolmanModeReady:t})}function ir({spoolmanMode:e=!1,spoolmanModeReady:t=!0}){let{t:n}=c(),i=Je(),a=l(),{showToast:p}=te(),{hasPermission:h,loading:g}=et(),b=!g&&h(`inventory:forecast_read`),[x,C]=Ne(),[w,E]=(0,J.useState)(null),D=(0,J.useRef)(!1),[O,A]=(0,J.useState)(null),[M,P]=(0,J.useState)(null),[L,ie]=(0,J.useState)(!1),[z,ce]=(0,J.useState)(!1),[ue,de]=(0,J.useState)(!1),[fe,pe]=(0,J.useState)(!1),[me,ge]=(0,J.useState)(`active`),[H,_e]=(0,J.useState)(`all`),[ye,xe]=(0,J.useState)(``),[Ce,we]=(0,J.useState)(``),[Ee,ke]=(0,J.useState)(``),[Ae,je]=(0,J.useState)(``),[Me,Re]=(0,J.useState)(``),[Be,He]=(0,J.useState)(``),[We,Ke]=(0,J.useState)(`all`),[Ye,Xe]=(0,J.useState)(``),[W,Ze]=(0,J.useState)(`table`),[$e,tt]=(0,J.useState)(tr),[nt,rt]=(0,J.useState)(Gn),[at,ot]=(0,J.useState)(!1),[st,ct]=(0,J.useState)(()=>{try{return localStorage.getItem(`bambuddy-inventory-group`)===`true`}catch{return!1}}),[lt,ut]=(0,J.useState)(new Set),[G,dt]=(0,J.useState)(new Set),[ft,pt]=(0,J.useState)(!1),[K,mt]=(0,J.useState)(null),ht=(0,J.useCallback)(e=>{dt(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),gt=(0,J.useCallback)(()=>dt(new Set),[]);(0,J.useEffect)(()=>{dt(new Set)},[me,H,ye,Ce,Ee,Ae,Me,Be,We,Ye]);let[_t,vt]=(0,J.useState)(0),[yt,bt]=(0,J.useState)(()=>{try{let e=localStorage.getItem(`bambuddy-inventory-pageSize`);if(e){let t=Number(e);if([15,30,50,100,-1].includes(t))return t}}catch{}return 15}),{data:xt}=u({queryKey:[`settings`],queryFn:r.getSettings}),St=xt?.date_format||`system`,Ct=(xt?.location_sensor_poll_interval||120)*1e3,{colorize:wt,aboveColor:Tt,belowColor:Et,optimalColor:Dt}=R(),Ot=e?[`spoolman-inventory-spools`]:[`inventory-spools`],kt=()=>Ie(a,Ot),{data:q,isLoading:jt}=u({queryKey:Ot,queryFn:()=>e?r.getSpoolmanInventorySpools(!0):r.getSpools(!0),refetchInterval:3e4}),Mt=(0,J.useCallback)(async()=>{ce(!0);try{await r.exportSpoolsCsv()}catch(e){p(e instanceof Error?e.message:n(`inventory.csv.exportError`,`Export failed`),`error`)}finally{ce(!1)}},[p,n]),Pt=e?n(`inventory.csv.spoolmanHint`,`In Spoolman mode, use Spoolman's built-in CSV import/export.`):void 0,{data:Lt=[]}=u({queryKey:qe,queryFn:r.getLocations}),Rt=x.get(`location_id`),X=Rt===`__none__`?`__none__`:Rt&&/^\d+$/.test(Rt)&&Number(Rt)>0?Rt:``,Z=x.get(`spool`),zt=Z&&/^\d+$/.test(Z)&&Number(Z)>0?Number(Z):null,Bt=q?.find(e=>e.id===zt)??null,Vt=(0,J.useCallback)(()=>{D.current=!0,C(e=>(e.delete(`spool`),e),{replace:!0})},[C]),{data:Ht,isError:Ut,error:Gt}=u({queryKey:e?[`spoolman-inventory-spool`,zt]:[`inventory-spool`,zt],queryFn:()=>e?r.getSpoolmanInventorySpool(zt):r.getSpool(zt),enabled:t&&zt!==null&&Bt===null,staleTime:1/0,retry:(e,t)=>e<2&&!(t instanceof o&&t.status===404)});(0,J.useEffect)(()=>{if(!D.current){if(t&&zt&&Bt){Vt(),E({spool:Bt,mode:`edit`});return}if(Ht){Vt(),E({spool:Ht,mode:`edit`});return}Ut&&(Vt(),p(n(Gt instanceof o&&Gt.status===404?`inventory.deepLinkSpoolNotFound`:`inventory.deepLinkFetchFailed`),`error`))}},[t,zt,Bt,Ht,Ut,Gt,Vt,p,n]);let{data:Kt}=u({queryKey:[`spool-assignments`],queryFn:()=>r.getAssignments(),refetchInterval:3e4}),{data:qt=[],isError:Jt}=u({queryKey:[`spoolman-slot-assignments-all`],queryFn:()=>r.getSpoolmanSlotAssignments(),enabled:e,refetchInterval:3e4,staleTime:1e4,retry:1}),Yt=(0,J.useRef)(!1);(0,J.useEffect)(()=>{Jt&&!Yt.current?(Yt.current=!0,p(n(`inventory.spoolmanUnreachable`),`error`)):Jt||(Yt.current=!1)},[Jt,p,n]);let{data:Xt}=u({queryKey:[`spool-catalog`],queryFn:()=>r.getSpoolCatalog()}),Zt=d({mutationFn:t=>e?r.deleteSpoolmanInventorySpool(t):r.deleteSpool(t),onSuccess:()=>{kt(),p(n(`inventory.spoolDeleted`),`success`)},onError:e=>{e instanceof o&&e.status===404?p(n(`inventory.deleteSpoolNotFound`),`error`):e instanceof o&&e.status===503?p(n(`inventory.spoolmanUnreachable`),`error`):p(n(`inventory.deleteFailed`),`error`)}}),Qt=d({mutationFn:t=>e?r.archiveSpoolmanInventorySpool(t):r.archiveSpool(t),onSuccess:()=>{kt(),p(n(`inventory.spoolArchived`),`success`)},onError:e=>{e instanceof o&&e.status===404?p(n(`inventory.archiveSpoolNotFound`),`error`):e instanceof o&&e.status===503?p(n(`inventory.spoolmanUnreachable`),`error`):p(n(`inventory.archiveFailed`),`error`)}}),$t=d({mutationFn:t=>e?r.restoreSpoolmanInventorySpool(t):r.restoreSpool(t),onSuccess:()=>{kt(),p(n(`inventory.spoolRestored`),`success`)},onError:e=>{e instanceof o&&e.status===404?p(n(`inventory.restoreSpoolNotFound`),`error`):e instanceof o&&e.status===503?p(n(`inventory.spoolmanUnreachable`),`error`):p(n(`inventory.restoreFailed`),`error`)}}),en=d({mutationFn:t=>e?r.resetSpoolmanInventorySpoolConsumedCounter(t):r.resetSpoolConsumedCounter(t),onSuccess:()=>{a.invalidateQueries({queryKey:Ot}),p(n(`inventory.consumedCounterReset`),`success`)},onError:()=>{p(n(`inventory.resetConsumedCounterFailed`),`error`)}}),tn=d({mutationFn:t=>e?r.bulkResetSpoolmanInventorySpoolConsumedCounter(t):r.bulkResetSpoolConsumedCounter(t),onSuccess:e=>{a.invalidateQueries({queryKey:Ot}),p(n(`inventory.allConsumedCountersReset`,{count:e.reset}),`success`),mt(null),gt()},onError:()=>{p(n(`inventory.resetConsumedCounterFailed`),`error`)}}),nn=e=>(e.not_found?.length??0)+(e.errors?.length??0),rn=d({mutationFn:async({ids:t,update:n})=>e?r.bulkUpdateSpoolmanInventorySpools(t,n):r.bulkUpdateSpools(t,n),onSuccess:e=>{kt();let t=nn(e);if(e.updated===0){p(n(`inventory.bulk.updateAllFailed`,{count:t}),`error`);return}t>0?p(n(`inventory.bulk.updatePartial`,{ok:e.updated,failed:t}),`warning`):p(n(`inventory.bulk.updateSuccess`,{count:e.updated}),`success`),pt(!1),gt()},onError:e=>{p(e.message||n(`inventory.bulk.updateFailed`),`error`)}}),an=d({mutationFn:async t=>e?r.bulkDeleteSpoolmanInventorySpools(t):r.bulkDeleteSpools(t),onSuccess:e=>{kt();let t=nn(e);if(e.deleted===0){p(n(`inventory.bulk.deleteAllFailed`,{count:t}),`error`);return}t>0?p(n(`inventory.bulk.deletePartial`,{ok:e.deleted,failed:t}),`warning`):p(n(`inventory.bulk.deleteSuccess`,{count:e.deleted}),`success`),mt(null),gt()},onError:e=>{p(e.message||n(`inventory.bulk.deleteFailed`),`error`)}}),on=d({mutationFn:async t=>e?r.bulkArchiveSpoolmanInventorySpools(t):r.bulkArchiveSpools(t),onSuccess:e=>{kt();let t=nn(e);if(e.archived===0&&t>0){p(n(`inventory.bulk.archiveAllFailed`,{count:t}),`error`);return}t>0?p(n(`inventory.bulk.archivePartial`,{ok:e.archived,failed:t}),`warning`):p(n(`inventory.bulk.archiveSuccess`,{count:e.archived}),`success`),mt(null),gt()},onError:e=>{p(e.message||n(`inventory.bulk.archiveFailed`),`error`)}}),sn=d({mutationFn:async t=>e?r.bulkRestoreSpoolmanInventorySpools(t):r.bulkRestoreSpools(t),onSuccess:e=>{kt();let t=nn(e);if(e.restored===0&&t>0){p(n(`inventory.bulk.restoreAllFailed`,{count:t}),`error`);return}t>0?p(n(`inventory.bulk.restorePartial`,{ok:e.restored,failed:t}),`warning`):p(n(`inventory.bulk.restoreSuccess`,{count:e.restored}),`success`),mt(null),gt()},onError:e=>{p(e.message||n(`inventory.bulk.restoreFailed`),`error`)}}),cn=(0,J.useMemo)(()=>(q??[]).map(e=>e.id),[q]),ln=async t=>{if(t.last_scale_weight!=null)try{e?await r.syncSpoolmanSpoolWeight(t.id,t.last_scale_weight):await s.updateSpoolWeight(t.id,t.last_scale_weight),a.invalidateQueries({queryKey:Ot}),p(`Synced "${[t.brand,t.material,Ve(t.color_name,t.rgba,t.color_name_is_synthesized)].filter(Boolean).join(` `)}" to scale weight`,`success`)}catch(e){let t=e instanceof o&&e.status===404,r=e instanceof o&&e.status===503;p(n(t?`inventory.syncWeightSpoolNotFound`:r?`inventory.syncWeightSpoolmanUnreachable`:`inventory.syncWeightFailed`),`error`)}},un=xt?.low_stock_threshold??20,[dn,fn]=(0,J.useState)(!1),[pn,mn]=(0,J.useState)(un.toString());(0,J.useEffect)(()=>{dn||mn(un.toString())},[un,dn]);let hn=d({mutationFn:e=>r.updateSettings({low_stock_threshold:e}),onSuccess:()=>{a.invalidateQueries({queryKey:[`settings`]}),p(n(`common.saved`),`success`),fn(!1)},onError:()=>{p(n(`inventory.lowStockThresholdError`),`error`)}}),Q=(0,J.useMemo)(()=>{if(!q)return null;let e=0,t=0,n=0,r=0,i={};for(let a of q){if(t+=Math.max(0,a.weight_used-(a.weight_used_baseline??0)),a.archived_at)continue;r++;let o=Math.max(0,a.label_weight-a.weight_used);e+=o,(a.label_weight>0?o/a.label_weight*100:0)<(a.low_stock_threshold_pct??un)&&n++;let s=a.material||`Unknown`;i[s]||(i[s]={count:0,weight:0}),i[s].count++,i[s].weight+=o}return{totalWeight:e,totalConsumed:t,lowStock:n,byMaterial:i,totalSpools:r}},[q,un]),_n=(Kt?.length??0)+(e?qt.length:0),vn=Le(xt?.currency||`USD`),yn=(0,J.useMemo)(()=>{let e={};for(let t of Kt||[])e[t.spool_id]={printer_id:t.printer_id,printer_name:t.printer_name,ams_id:t.ams_id,tray_id:t.tray_id,ams_label:t.ams_label??null};for(let t of qt)typeof t?.spoolman_spool_id!=`number`||t.spoolman_spool_id<=0||typeof t.printer_id!=`number`||typeof t.ams_id!=`number`||typeof t.tray_id!=`number`||e[t.spoolman_spool_id]||(e[t.spoolman_spool_id]={printer_id:t.printer_id,printer_name:t.printer_name??null,ams_id:t.ams_id,tray_id:t.tray_id,ams_label:t.ams_label??null});return e},[Kt,qt]),bn=(0,J.useMemo)(()=>{let e={};for(let t of Xt||[])e[t.id]=t;return e},[Xt]),{data:xn}=u({queryKey:[`locationHaSensors`],queryFn:()=>r.getLocationHASensors()}),Sn=(0,J.useMemo)(()=>new Set((xn??[]).map(e=>e.location_id)),[xn]),Cn=(0,J.useMemo)(()=>{let e=new Set;for(let t of q||[])t.location_id&&Sn.has(t.location_id)&&e.add(t.location_id);return Array.from(e)},[q,Sn]),wn=W===`cards`||W===`table`&&nt.some(e=>e.visible&&(e.id===`temperature`||e.id===`humidity`||e.id===`battery`)),Tn=f({queries:Cn.map(e=>({queryKey:[`locationHaSensorReadings`,e],queryFn:()=>r.getLocationHASensorReadings(e,!1),refetchInterval:Ct,enabled:wn}))}),En=(0,J.useMemo)(()=>{let e={};return Cn.forEach((t,n)=>{let r=Tn[n]?.data;r&&(e[t]=r)}),e},[Cn,Tn]),Dn=(0,J.useMemo)(()=>Q?Object.entries(Q.byMaterial).sort((e,t)=>t[1].weight-e[1].weight).slice(0,4):[],[Q]),On=(0,J.useMemo)(()=>{let e=q||[];if(e=me===`active`?e.filter(e=>!e.archived_at):e.filter(e=>!!e.archived_at),H===`used`?e=e.filter(e=>e.weight_used>0):H===`new`?e=e.filter(e=>e.weight_used===0):H===`lowstock`&&(e=e.filter(e=>{let t=Math.max(0,e.label_weight-e.weight_used);return(e.label_weight>0?t/e.label_weight*100:0)<(e.low_stock_threshold_pct??un)})),ye&&(e=e.filter(e=>e.material===ye)),Ce&&(e=e.filter(e=>e.brand===Ce)),Ee&&(e=Ee===`__none__`?e.filter(e=>!e.category):e.filter(e=>e.category===Ee)),Ae&&(e=Ae===Hn?e.filter(e=>!e.material_number?.trim()):e.filter(e=>e.material_number===Ae)),Me)if(Me===`__none__`)e=e.filter(e=>(e.suppliers??[]).length===0);else{let t=Number(Me);e=e.filter(e=>(e.suppliers??[]).some(e=>e.supplier_id===t))}if(Be){let t=Number(Be);e=e.filter(e=>e.core_weight_catalog_id===t)}if(X)if(X===`__none__`)e=e.filter(e=>!e.location_id&&!e.storage_location?.trim());else{let t=Number(X),n=Lt.find(e=>e.id===t)?.name?.trim().toLowerCase();e=e.filter(e=>e.location_id==null?n?(e.storage_location||``).trim().toLowerCase()===n:!1:e.location_id===t)}return We===`stock`?e=e.filter(e=>!e.slicer_filament):We===`configured`&&(e=e.filter(e=>!!e.slicer_filament)),Ye&&(e=At(e,Ye)),e},[q,me,H,ye,Ce,Ee,Ae,Me,Be,We,X,Ye,un,Lt,i]),$=()=>vt(0),kn=(0,J.useCallback)(e=>{C(t=>(t.delete(`location_id`),e&&t.set(`location_id`,e),t),{replace:!0}),$()},[C]),An=[...new Set(q?.map(e=>e.material)||[])].sort(),Pn=[...new Set(q?.map(e=>e.brand).filter(Boolean)||[])].sort(),Fn=[...new Set(q?.map(e=>e.category?.trim()).filter(Boolean)||[])].sort(),In=(q??[]).some(e=>!e.category),Vn=[...new Set(q?.map(e=>e.material_number?.trim()).filter(Boolean)||[])].sort((e,t)=>e.localeCompare(t,void 0,{numeric:!0})),Un=(q??[]).some(e=>!e.material_number?.trim()),Yn=(0,J.useMemo)(()=>{let e=new Map;for(let t of q??[])for(let n of t.suppliers??[])e.set(n.supplier_id,n.supplier_name);return[...e.entries()].map(([e,t])=>({id:e,name:t})).sort((e,t)=>e.name.localeCompare(t.name))},[q]),Xn=(q??[]).some(e=>(e.suppliers??[]).length===0),Qn=[...new Set(q?.map(e=>e.core_weight_catalog_id).filter(e=>e!=null)||[])].sort((e,t)=>{let n=(bn[e]?.name||``).toLowerCase(),r=(bn[t]?.name||``).toLowerCase();return n.localeCompare(r)}),er=(q??[]).some(e=>!e.location_id&&!e.storage_location?.trim()),rr=me!==`active`||H!==`all`||!!ye||!!Ce||!!Ee||!!Ae||!!Me||!!Be||!!X||We!==`all`||!!Ye,ir=e=>{rt(e),Kn(e)},sr=(0,J.useMemo)(()=>nt.filter(e=>e.visible).map(e=>e.id),[nt]),cr=e=>{$n[e]&&(tt(t=>{let n;return n=t?.column===e?t.direction===`asc`?{column:e,direction:`desc`}:null:{column:e,direction:`asc`},nr(n),n}),$())},lr=(0,J.useMemo)(()=>{if(!$e)return On;let e=$n[$e.column];return e?[...On].sort((t,n)=>{let r=e(t,yn,En),i=e(n,yn,En);return r<i?$e.direction===`asc`?-1:1:r>i?$e.direction===`asc`?1:-1:0}):On},[On,$e,yn,En]),ur=(0,J.useMemo)(()=>{if(!st)return lr.map(e=>({type:`single`,spool:e}));let e=new Map;for(let t of lr)if(!(t.weight_used>0||yn[t.id])){let n=Bn(t),r=e.get(n);r?r.push(t):e.set(n,[t])}let t=[],n=new Set;for(let r of lr){if(r.weight_used>0||yn[r.id]){t.push({type:`single`,spool:r});continue}let i=Bn(r);if(n.has(i))continue;n.add(i);let a=e.get(i);a.length===1?t.push({type:`single`,spool:a[0]}):t.push({type:`group`,key:i,spools:a,representative:a[0]})}return t},[lr,st,yn]),dr=yt===-1,hr=ur.length,gr=dr?hr||1:yt,_r=Math.max(1,Math.ceil(hr/gr)),vr=dr?0:Math.min(_t,_r-1),yr=dr?ur:ur.slice(vr*gr,(vr+1)*gr),br=()=>{let e=!st;ct(e),ut(new Set),$();try{localStorage.setItem(`bambuddy-inventory-group`,String(e))}catch{}},xr=e=>{ut(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},Sr=e=>{bt(e),vt(0);try{localStorage.setItem(`bambuddy-inventory-pageSize`,String(e))}catch{}};return(0,Y.jsxs)(`div`,{className:`p-4 md:p-8 space-y-6`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,Y.jsx)(oe,{className:`w-7 h-7 text-bambu-green`}),n(`inventory.title`)]}),(0,Y.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:n(`inventory.subtitle`)})]}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Y.jsxs)(V,{variant:`secondary`,disabled:e,onClick:()=>ie(!0),title:Pt,children:[(0,Y.jsx)(Ge,{className:`w-4 h-4`}),n(`inventory.csv.importButton`,`Import CSV`)]}),(0,Y.jsxs)(V,{variant:`secondary`,disabled:e||z,onClick:Mt,title:Pt,children:[z?(0,Y.jsx)(F,{className:`w-4 h-4 animate-spin`}):(0,Y.jsx)(Qe,{className:`w-4 h-4`}),n(`inventory.csv.exportButton`,`Export CSV`)]}),(0,Y.jsxs)(V,{variant:`secondary`,onClick:()=>de(!0),children:[(0,Y.jsx)(ae,{className:`w-4 h-4`}),n(`locations.manage`)]}),(0,Y.jsxs)(V,{variant:`secondary`,onClick:()=>pe(!0),children:[(0,Y.jsx)(Ft,{className:`w-4 h-4`}),n(`inventory.suppliers.title`)]}),(0,Y.jsxs)(V,{variant:`secondary`,disabled:On.length===0,onClick:()=>P(G.size>0?[...G]:On.map(e=>e.id)),title:On.length===0?n(`inventory.labels.noSpoolsTitle`,`No spools to label`):G.size>0?n(`inventory.labels.selectedTitle`,`Print labels for the {{count}} selected spools`,{count:G.size}):n(`inventory.labels.bulkTitle`,`Pick spools to print labels for from the {{count}} currently shown`,{count:On.length}),children:[(0,Y.jsx)(U,{className:`w-4 h-4`}),n(`inventory.labels.printLabels`,`Print labels…`)]}),(0,Y.jsxs)(V,{onClick:()=>E({spool:null,mode:`create`}),children:[(0,Y.jsx)(Pe,{className:`w-4 h-4`}),n(`inventory.addSpool`)]})]})]}),Q&&!jt&&(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-3 lg:grid-cols-5 gap-3`,children:[(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg p-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,Y.jsx)(oe,{className:`w-4 h-4 text-bambu-green`}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray font-medium uppercase tracking-wide`,children:n(`inventory.totalInventory`)})]}),(0,Y.jsx)(`div`,{className:`text-xl font-bold text-white`,children:qn(Q.totalWeight,!0)}),(0,Y.jsxs)(`div`,{className:`text-xs text-bambu-gray mt-1`,children:[Q.totalSpools,` `,Q.totalSpools===1?n(`inventory.spool`):n(`inventory.spools`)]})]}),(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg p-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-2 mb-1`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(le,{className:`w-4 h-4 text-blue-600 dark:text-blue-400`}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray font-medium uppercase tracking-wide`,children:n(`inventory.totalConsumed`)})]}),Q.totalConsumed>0&&cn.length>0&&(0,Y.jsx)(`button`,{onClick:()=>A({type:`reset-all-consumed-counters`}),className:`p-1 text-bambu-gray hover:text-red-600 dark:hover:text-red-400 rounded transition-colors`,title:n(`inventory.resetAllConsumedCountersTooltip`),"aria-label":n(`inventory.resetAllConsumedCounters`),children:(0,Y.jsx)(S,{className:`w-3.5 h-3.5`})})]}),(0,Y.jsx)(`div`,{className:`text-xl font-bold text-white`,children:qn(Q.totalConsumed,!0)}),(0,Y.jsx)(`div`,{className:`text-xs text-bambu-gray mt-1`,children:n(`inventory.sinceTracking`)})]}),(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg p-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,Y.jsx)(ze,{className:`w-4 h-4 text-green-600 dark:text-green-400`}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray font-medium uppercase tracking-wide`,children:n(`inventory.byMaterial`)})]}),(0,Y.jsx)(`div`,{className:`flex flex-wrap gap-1.5 mt-1`,children:Dn.map(([e,t])=>(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-medium ${Jn[e]||`bg-bambu-dark-tertiary text-bambu-gray`}`,children:[e,` `,(0,Y.jsx)(`span`,{className:`opacity-70`,children:qn(t.weight,!0)})]},e))})]}),(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg p-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,Y.jsx)(U,{className:`w-4 h-4 text-purple-600 dark:text-purple-400`}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray font-medium uppercase tracking-wide`,children:n(`inventory.inPrinter`)})]}),(0,Y.jsx)(`div`,{className:`text-xl font-bold text-white`,children:_n}),(0,Y.jsx)(`div`,{className:`text-xs text-bambu-gray mt-1`,children:n(`inventory.loadedInAms`)})]}),(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg p-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,Y.jsx)(B,{className:`w-4 h-4 text-yellow-600 dark:text-yellow-400`}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray font-medium uppercase tracking-wide`,children:n(`inventory.lowStock`)})]}),(0,Y.jsx)(`div`,{className:`text-xl font-bold ${Q.lowStock>0?`text-yellow-700 dark:text-yellow-400`:`text-white`}`,children:Q.lowStock}),(0,Y.jsx)(`div`,{className:`text-xs text-bambu-gray mt-1 flex items-center gap-2`,children:dn?(0,Y.jsxs)(`form`,{onSubmit:e=>{e.preventDefault();let t=parseFloat(pn);!isNaN(t)&&t>=.1&&t<=99.9?hn.mutate(t):p(n(`inventory.lowStockThresholdError`),`error`)},className:`flex items-center gap-2`,children:[(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:`<`}),(0,Y.jsx)(`input`,{type:`text`,inputMode:`decimal`,pattern:`^\\d{0,2}(\\.\\d?)?$`,maxLength:4,value:pn,onChange:e=>{let t=e.target.value.replace(/[^\d.]/g,``);/^\d{0,2}(\.\d?)?$/.test(t)&&mn(t)},className:`px-1.5 py-1 rounded border border-bambu-dark-tertiary text-xs text-white bg-bambu-dark-secondary focus:outline-none focus:border-bambu-green w-14 text-center`,onWheel:e=>e.currentTarget.blur(),disabled:hn.isPending}),(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:`%`}),(0,Y.jsx)(V,{type:`submit`,size:`sm`,disabled:hn.isPending,children:n(`common.save`)}),(0,Y.jsx)(V,{type:`button`,size:`sm`,variant:`ghost`,onClick:()=>fn(!1),disabled:hn.isPending,children:n(`common.cancel`)})]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`span`,{className:`text-bambu-gray`,children:[`< `,un,`%`]}),(0,Y.jsx)(`button`,{className:`p-1.5 text-bambu-gray hover:text-white rounded transition-colors`,title:n(`common.edit`),onClick:()=>{mn(un.toString()),fn(!0)},children:(0,Y.jsx)(I,{className:`w-4 h-4`})})]})})]})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col sm:flex-row gap-3 items-start sm:items-center justify-between`,children:[(0,Y.jsxs)(`div`,{className:`relative flex-1 max-w-md ${W===`forecast`?`invisible pointer-events-none`:``}`,children:[(0,Y.jsx)(se,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50`}),(0,Y.jsx)(`input`,{type:`text`,value:Ye,onChange:e=>{Xe(e.target.value),$()},placeholder:n(`inventory.search`),className:`w-full pl-10 pr-8 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`}),Ye&&(0,Y.jsx)(`button`,{onClick:()=>{Xe(``),$()},className:`absolute right-3 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white`,children:(0,Y.jsx)(he,{className:`w-4 h-4`})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[W===`table`&&(0,Y.jsxs)(`button`,{onClick:()=>ot(!0),className:`flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium text-bambu-gray border border-bambu-dark-tertiary rounded-lg hover:bg-bambu-dark-tertiary transition-colors`,title:n(`inventory.configureColumns`),children:[(0,Y.jsx)(j,{className:`w-4 h-4`}),(0,Y.jsx)(`span`,{className:`hidden sm:inline`,children:n(`inventory.columns`)})]}),W!==`forecast`&&(0,Y.jsxs)(`button`,{onClick:br,className:`flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium border rounded-lg transition-colors ${st?`bg-bambu-green/20 text-bambu-green border-bambu-green/30`:`text-bambu-gray border-bambu-dark-tertiary hover:bg-bambu-dark-tertiary`}`,title:n(`inventory.groupSimilar`),children:[(0,Y.jsx)(Nt,{className:`w-4 h-4`}),(0,Y.jsx)(`span`,{className:`hidden sm:inline`,children:n(`inventory.groupSimilar`)})]}),(0,Y.jsxs)(`div`,{className:`flex bg-bambu-dark-primary border border-bambu-dark-tertiary rounded-lg overflow-hidden`,children:[(0,Y.jsxs)(`button`,{onClick:()=>Ze(`table`),className:`flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium transition-colors ${W===`table`?`bg-bambu-green text-white`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:[(0,Y.jsx)(It,{className:`w-4 h-4`}),(0,Y.jsx)(`span`,{className:`hidden sm:inline`,children:n(`inventory.table`)})]}),(0,Y.jsxs)(`button`,{onClick:()=>Ze(`cards`),className:`flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium transition-colors ${W===`cards`?`bg-bambu-green text-white`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:[(0,Y.jsx)(N,{className:`w-4 h-4`}),(0,Y.jsx)(`span`,{className:`hidden sm:inline`,children:n(`inventory.cards`)})]}),(0,Y.jsxs)(`button`,{onClick:()=>b&&Ze(`forecast`),disabled:!b,title:b?void 0:n(`forecast.noReadAccess`),className:`flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium transition-colors disabled:opacity-40 disabled:cursor-not-allowed ${W===`forecast`?`bg-bambu-green text-white`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:[b?(0,Y.jsx)(m,{className:`w-4 h-4`}):(0,Y.jsx)(ne,{className:`w-4 h-4`}),(0,Y.jsx)(`span`,{className:`hidden sm:inline`,children:n(`forecast.title`)})]})]})]})]}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 ${W===`forecast`?`hidden`:``}`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center rounded-lg border border-bambu-dark-tertiary overflow-hidden`,children:[(0,Y.jsxs)(`button`,{onClick:()=>{ge(`active`),$()},className:`flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium transition-colors ${me===`active`?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:[(0,Y.jsx)(oe,{className:`w-3.5 h-3.5`}),n(`inventory.active`)]}),(0,Y.jsxs)(`button`,{onClick:()=>{ge(`archived`),$()},className:`flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium transition-colors ${me===`archived`?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:[(0,Y.jsx)(Te,{className:`w-3.5 h-3.5`}),n(`inventory.archived`)]})]}),(0,Y.jsx)(`div`,{className:`w-px h-5 bg-bambu-dark-tertiary`}),(0,Y.jsxs)(`div`,{className:`flex items-center rounded-lg border border-bambu-dark-tertiary overflow-hidden`,children:[(0,Y.jsx)(`button`,{onClick:()=>{_e(`all`),$()},className:`px-3 py-1.5 text-xs font-medium transition-colors ${H===`all`?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:n(`inventory.all`)}),(0,Y.jsxs)(`button`,{onClick:()=>{_e(`used`),$()},className:`flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium transition-colors ${H===`used`?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:[(0,Y.jsx)(Oe,{className:`w-3.5 h-3.5`}),n(`inventory.used`)]}),(0,Y.jsx)(`button`,{onClick:()=>{_e(`new`),$()},className:`px-3 py-1.5 text-xs font-medium transition-colors ${H===`new`?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:n(`inventory.new`)}),(0,Y.jsxs)(`button`,{onClick:()=>{_e(`lowstock`),$()},className:`flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium transition-colors ${H===`lowstock`?`bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:[(0,Y.jsx)(B,{className:`w-3.5 h-3.5`}),n(`inventory.lowStock`)]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center rounded-lg border border-bambu-dark-tertiary overflow-hidden`,children:[(0,Y.jsx)(`button`,{onClick:()=>{Ke(`all`),$()},className:`px-3 py-1.5 text-xs font-medium transition-colors ${We===`all`?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:n(`inventory.all`)}),(0,Y.jsx)(`button`,{onClick:()=>{Ke(`stock`),$()},className:`px-3 py-1.5 text-xs font-medium transition-colors ${We===`stock`?`bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-400`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:n(`inventory.stock`)}),(0,Y.jsx)(`button`,{onClick:()=>{Ke(`configured`),$()},className:`px-3 py-1.5 text-xs font-medium transition-colors ${We===`configured`?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:n(`inventory.configured`)})]}),(0,Y.jsx)(`div`,{className:`w-px h-5 bg-bambu-dark-tertiary`}),(0,Y.jsxs)(`select`,{value:ye,onChange:e=>{xe(e.target.value),$()},className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${ye?`bg-bambu-green/20 text-bambu-green border-bambu-green/30`:`bg-transparent text-bambu-gray border-bambu-dark-tertiary hover:bg-bambu-dark-tertiary`}`,children:[(0,Y.jsx)(`option`,{value:``,children:n(`inventory.material`)}),An.map(e=>(0,Y.jsx)(`option`,{value:e,children:e},e))]}),(0,Y.jsxs)(`select`,{value:Ce,onChange:e=>{we(e.target.value),$()},className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${Ce?`bg-bambu-green/20 text-bambu-green border-bambu-green/30`:`bg-transparent text-bambu-gray border-bambu-dark-tertiary hover:bg-bambu-dark-tertiary`}`,children:[(0,Y.jsx)(`option`,{value:``,children:n(`inventory.brand`)}),Pn.map(e=>(0,Y.jsx)(`option`,{value:e,children:e},e))]}),(Fn.length>0||Ee)&&(0,Y.jsxs)(`select`,{value:Ee,onChange:e=>{ke(e.target.value),$()},className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${Ee?`bg-bambu-green/20 text-bambu-green border-bambu-green/30`:`bg-transparent text-bambu-gray border-bambu-dark-tertiary hover:bg-bambu-dark-tertiary`}`,children:[(0,Y.jsx)(`option`,{value:``,children:n(`inventory.category`)}),Fn.map(e=>(0,Y.jsx)(`option`,{value:e,children:e},e)),In&&(0,Y.jsx)(`option`,{value:`__none__`,children:n(`inventory.categoryNone`)})]}),(Vn.length>0||Ae)&&(0,Y.jsxs)(`select`,{value:Ae,onChange:e=>{je(e.target.value),$()},className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${Ae?`bg-bambu-green/20 text-bambu-green border-bambu-green/30`:`bg-transparent text-bambu-gray border-bambu-dark-tertiary hover:bg-bambu-dark-tertiary`}`,children:[(0,Y.jsx)(`option`,{value:``,children:n(`inventory.materialNumber`)}),Vn.map(e=>(0,Y.jsx)(`option`,{value:e,children:e},e)),Un&&(0,Y.jsx)(`option`,{value:Hn,children:n(`inventory.materialNumberNone`)})]}),(Yn.length>0||Me)&&(0,Y.jsxs)(`select`,{value:Me,onChange:e=>{Re(e.target.value),$()},className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${Me?`bg-bambu-green/20 text-bambu-green border-bambu-green/30`:`bg-transparent text-bambu-gray border-bambu-dark-tertiary hover:bg-bambu-dark-tertiary`}`,children:[(0,Y.jsx)(`option`,{value:``,children:n(`inventory.suppliers.label`)}),Yn.map(e=>(0,Y.jsx)(`option`,{value:String(e.id),children:e.name},e.id)),Xn&&(0,Y.jsx)(`option`,{value:`__none__`,children:n(`inventory.suppliers.none`)})]}),Qn.length>0&&(0,Y.jsxs)(`select`,{value:Be,onChange:e=>{He(e.target.value),$()},className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${Be?`bg-bambu-green/20 text-bambu-green border-bambu-green/30`:`bg-transparent text-bambu-gray border-bambu-dark-tertiary hover:bg-bambu-dark-tertiary`}`,children:[(0,Y.jsx)(`option`,{value:``,children:n(`inventory.spoolName`)}),Qn.map(e=>(0,Y.jsx)(`option`,{value:e,children:bn[e]?.name||`#${e}`},e))]}),(Lt.length>0||X)&&(0,Y.jsxs)(`select`,{value:X,onChange:e=>{kn(e.target.value)},className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${X?`bg-bambu-green/20 text-bambu-green border-bambu-green/30`:`bg-transparent text-bambu-gray border-bambu-dark-tertiary hover:bg-bambu-dark-tertiary`}`,children:[(0,Y.jsx)(`option`,{value:``,children:n(`inventory.storageLocation`)}),Lt.map(e=>(0,Y.jsx)(`option`,{value:String(e.id),children:e.name},e.id)),er&&(0,Y.jsx)(`option`,{value:`__none__`,children:n(`inventory.storageLocationNone`)})]}),rr&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`div`,{className:`w-px h-5 bg-bambu-dark-tertiary`}),(0,Y.jsxs)(`button`,{onClick:()=>{ge(`active`),_e(`all`),xe(``),we(``),ke(``),je(``),Re(``),He(``),Ke(`all`),Xe(``),C(e=>(e.delete(`location_id`),e),{replace:!0}),$()},className:`flex items-center gap-1 text-xs text-bambu-gray hover:text-bambu-green transition-colors`,children:[(0,Y.jsx)(he,{className:`w-3.5 h-3.5`}),n(`inventory.clearFilters`)]})]}),W!==`forecast`&&(0,Y.jsxs)(`span`,{className:`ml-auto text-xs text-bambu-gray`,children:[lr.length,` `,lr.length===1?n(`inventory.spool`):n(`inventory.spools`),st&&hr<lr.length&&` (${hr} ${n(`inventory.groupedRows`)})`]})]}),G.size>0&&W!==`forecast`&&(0,Y.jsxs)(`div`,{className:`sticky top-2 z-10 mb-4 flex items-center gap-2 px-3 py-2 bg-bambu-green/10 border border-bambu-green/30 rounded-lg backdrop-blur-sm`,children:[(0,Y.jsx)(`span`,{className:`text-sm text-bambu-green font-medium`,children:n(`inventory.bulk.selectionCount`,{count:G.size})}),(0,Y.jsxs)(`div`,{className:`ml-auto flex flex-wrap items-center gap-2`,children:[(0,Y.jsxs)(V,{size:`sm`,variant:`secondary`,onClick:()=>pt(!0),children:[(0,Y.jsx)(I,{className:`w-3.5 h-3.5 mr-1.5`}),n(`inventory.bulk.edit`)]}),(0,Y.jsxs)(V,{size:`sm`,variant:`secondary`,onClick:()=>P([...G]),children:[(0,Y.jsx)(U,{className:`w-3.5 h-3.5 mr-1.5`}),n(`inventory.bulk.printLabels`)]}),(0,Y.jsxs)(V,{size:`sm`,variant:`secondary`,onClick:()=>mt(`reset-consumed-counter`),children:[(0,Y.jsx)(S,{className:`w-3.5 h-3.5 mr-1.5`}),n(`inventory.bulk.resetUsage`)]}),me===`archived`?(0,Y.jsxs)(V,{size:`sm`,variant:`secondary`,onClick:()=>mt(`restore`),children:[(0,Y.jsx)(Se,{className:`w-3.5 h-3.5 mr-1.5`}),n(`inventory.bulk.restore`)]}):(0,Y.jsxs)(V,{size:`sm`,variant:`secondary`,onClick:()=>mt(`archive`),children:[(0,Y.jsx)(Te,{className:`w-3.5 h-3.5 mr-1.5`}),n(`inventory.bulk.archive`)]}),(0,Y.jsxs)(V,{size:`sm`,variant:`danger`,onClick:()=>mt(`delete`),children:[(0,Y.jsx)(be,{className:`w-3.5 h-3.5 mr-1.5`}),n(`inventory.bulk.delete`)]}),(0,Y.jsx)(`button`,{className:`p-1.5 text-bambu-gray hover:text-white rounded transition-colors`,onClick:gt,title:n(`inventory.bulk.clearSelection`),"aria-label":n(`inventory.bulk.clearSelection`),children:(0,Y.jsx)(he,{className:`w-4 h-4`})})]})]}),jt?(0,Y.jsx)(`div`,{className:`flex justify-center py-16`,children:(0,Y.jsx)(F,{className:`w-8 h-8 text-bambu-green animate-spin`})}):W===`forecast`?(0,Y.jsx)(Wt,{spools:q||[]}):W===`cards`?yr.length>0?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4`,children:yr.map(e=>{if(e.type===`group`){let{key:t,spools:r,representative:i}=e,a=r.reduce((e,t)=>e+Math.max(0,t.label_weight-t.weight_used),0),o=ve({rgba:i.rgba,extraColors:i.extra_colors,effectType:i.effect_type,subtype:i.subtype,effectSize:`groupheader`}),s=lt.has(t);return(0,Y.jsxs)(`div`,{className:`col-span-full`,children:[(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg overflow-hidden border border-bambu-green/30 hover:border-bambu-green transition-colors cursor-pointer`,onClick:()=>xr(t),children:[(0,Y.jsx)(`div`,{className:`h-10 flex items-center px-4 gap-3`,style:o,children:(0,Y.jsx)(`span`,{className:`bg-white/90 text-gray-800 px-3 py-0.5 rounded-full text-sm font-medium`,children:Ve(i.color_name,i.rgba,i.color_name_is_synthesized)||`-`})}),(0,Y.jsxs)(`div`,{className:`px-4 py-3 flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Y.jsx)(T,{className:`w-4 h-4 text-bambu-gray transition-transform ${s?``:`-rotate-90`}`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`h3`,{className:`font-semibold text-white`,children:[i.material,i.subtype?` ${i.subtype}`:``]}),(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i.brand||`-`})]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`span`,{className:`text-sm text-bambu-gray`,title:n(`inventory.remaining`),children:qn(a)}),(0,Y.jsx)(`span`,{className:`text-xs font-medium bg-bambu-green/20 text-bambu-green px-2 py-0.5 rounded-full`,children:n(`inventory.groupedSpools`,{count:r.length})})]})]})]}),s&&(0,Y.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4 mt-2 ml-4`,children:r.map(e=>{let t=Math.max(0,e.label_weight-e.weight_used);return(0,Y.jsx)(or,{spool:e,remaining:t,pct:e.label_weight>0?t/e.label_weight*100:0,onClick:()=>E({spool:e,mode:`edit`}),onPrintLabel:()=>P([e.id]),onCopy:()=>E({spool:e,mode:`copy`}),t:n,colorizeLocationSensors:wt,locationSensorAboveColor:Tt,locationSensorBelowColor:Et,locationSensorOptimalColor:Dt,dateFormat:St},e.id)})})]},`group-${t}`)}let t=e.spool,r=Math.max(0,t.label_weight-t.weight_used);return(0,Y.jsx)(or,{spool:t,remaining:r,pct:t.label_weight>0?r/t.label_weight*100:0,onClick:()=>E({spool:t,mode:`edit`}),onPrintLabel:()=>P([t.id]),onCopy:()=>E({spool:t,mode:`copy`}),t:n,colorizeLocationSensors:wt,locationSensorAboveColor:Tt,locationSensorBelowColor:Et,locationSensorOptimalColor:Dt,dateFormat:St},t.id)})}),(0,Y.jsx)(ar,{pageIndex:vr,pageSize:yt,totalRows:hr,totalPages:_r,onPageChange:vt,onPageSizeChange:Sr,t:n})]}):(0,Y.jsx)(mr,{hasFilters:rr,onAddSpool:()=>E({spool:null,mode:`create`}),t:n}):yr.length>0?(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg overflow-hidden border border-bambu-dark-tertiary`,children:[(0,Y.jsx)(`div`,{className:`overflow-x-auto`,children:(0,Y.jsxs)(`table`,{className:`w-full`,children:[(0,Y.jsx)(`thead`,{children:(0,Y.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary bg-bambu-dark-tertiary/30`,children:[(0,Y.jsx)(`th`,{className:`w-10 px-3 py-3`,children:(0,Y.jsx)(`input`,{type:`checkbox`,className:`h-4 w-4 cursor-pointer`,"aria-label":n(`inventory.bulk.selectAllVisible`),checked:yr.length>0&&yr.every(e=>(e.type===`group`?e.spools.map(e=>e.id):[e.spool.id]).every(e=>G.has(e))),onChange:e=>{if(e.target.checked){let e=new Set(G);for(let t of yr){let n=t.type===`group`?t.spools.map(e=>e.id):[t.spool.id];for(let t of n)e.add(t)}dt(e)}else{let e=new Set(G);for(let t of yr){let n=t.type===`group`?t.spools.map(e=>e.id):[t.spool.id];for(let t of n)e.delete(t)}dt(e)}}})}),sr.map(e=>{let t=!!$n[e],r=$e?.column===e;return(0,Y.jsx)(`th`,{className:`text-left py-3 px-4 text-xs font-medium uppercase tracking-wide select-none ${e===`remaining`?`min-w-[150px]`:``} ${t?`cursor-pointer hover:text-bambu-green transition-colors`:``} ${r?`text-bambu-green`:`text-bambu-gray`}`,onClick:t?()=>cr(e):void 0,children:(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[Zn[e]?.(n)??e,t&&(r?$e.direction===`asc`?(0,Y.jsx)(y,{className:`w-3 h-3`}):(0,Y.jsx)(_,{className:`w-3 h-3`}):(0,Y.jsx)(v,{className:`w-3 h-3 opacity-30`}))]})},e)}),(0,Y.jsx)(`th`,{className:`text-right py-3 px-4 text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:n(`common.actions`)})]})}),(0,Y.jsx)(`tbody`,{children:yr.map(e=>{if(e.type===`group`){let{key:t,spools:r}=e,i=lt.has(t),a=Rn(r),o=Math.max(0,a.label_weight-a.weight_used);return(0,Y.jsx)(pr,{spools:r,headerSpool:a,remaining:o,pct:a.label_weight>0?o/a.label_weight*100:0,isExpanded:i,onToggle:()=>xr(t),selectedIds:G,onToggleSelected:ht,onToggleGroupSelected:(e,t)=>{dt(n=>{let r=new Set(n);for(let n of e)t?r.add(n):r.delete(n);return r})},onEdit:e=>E({spool:e,mode:`edit`}),onCopy:e=>E({spool:e,mode:`copy`}),onArchive:e=>A({type:`archive`,spoolId:e}),onDelete:e=>A({type:`delete`,spoolId:e}),onPrintLabel:e=>P([e]),onResetConsumedCounter:e=>A({type:`reset-consumed-counter`,spoolId:e}),visibleColumns:sr,assignmentMap:yn,catalogMap:bn,locationReadingsMap:En,currencySymbol:vn,dateFormat:St,t:n,onSyncWeight:ln,colorizeLocationSensors:wt,locationSensorAboveColor:Tt,locationSensorBelowColor:Et,locationSensorOptimalColor:Dt},`group-${t}`)}let t=e.spool,r=Math.max(0,t.label_weight-t.weight_used);return(0,Y.jsx)(fr,{spool:t,remaining:r,pct:t.label_weight>0?r/t.label_weight*100:0,isSelected:G.has(t.id),onToggleSelected:()=>ht(t.id),onEdit:()=>E({spool:t,mode:`edit`}),onCopy:()=>E({spool:t,mode:`copy`}),onRestore:()=>$t.mutate(t.id),onArchive:()=>A({type:`archive`,spoolId:t.id}),onDelete:()=>A({type:`delete`,spoolId:t.id}),onPrintLabel:()=>P([t.id]),onResetConsumedCounter:()=>A({type:`reset-consumed-counter`,spoolId:t.id}),visibleColumns:sr,assignmentMap:yn,catalogMap:bn,locationReadingsMap:En,currencySymbol:vn,dateFormat:St,t:n,onSyncWeight:ln,colorizeLocationSensors:wt,locationSensorAboveColor:Tt,locationSensorBelowColor:Et,locationSensorOptimalColor:Dt},t.id)})})]})}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 bg-bambu-dark-tertiary/50 border-t border-bambu-dark-tertiary text-sm`,children:[(0,Y.jsx)(`span`,{className:`text-bambu-gray`,children:dr?`${hr} ${n(hr===1?`inventory.spool`:`inventory.spools`)}`:(0,Y.jsxs)(Y.Fragment,{children:[n(`inventory.showing`),` `,vr*gr+1,` `,n(`inventory.to`),` `,Math.min((vr+1)*gr,hr),` `,n(`inventory.of`),` `,hr,` `,n(`inventory.spools`)]})}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`span`,{className:`text-bambu-gray`,children:n(`inventory.show`)}),(0,Y.jsxs)(`select`,{value:yt,onChange:e=>Sr(Number(e.target.value)),className:`px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:outline-none focus:border-bambu-green`,children:[[15,30,50,100].map(e=>(0,Y.jsx)(`option`,{value:e,children:e},e)),(0,Y.jsx)(`option`,{value:-1,children:n(`inventory.all`)})]}),!dr&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`button`,{onClick:()=>vt(0),disabled:vr===0,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,title:`First page`,children:(0,Y.jsx)(ee,{className:`w-4 h-4`})}),(0,Y.jsx)(`button`,{onClick:()=>vt(e=>Math.max(0,e-1)),disabled:vr===0,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,children:(0,Y.jsx)(Ue,{className:`w-4 h-4`})}),(0,Y.jsxs)(`span`,{className:`text-bambu-gray px-2 whitespace-nowrap`,children:[n(`inventory.page`),` `,vr+1,` `,n(`inventory.of`),` `,_r]}),(0,Y.jsx)(`button`,{onClick:()=>vt(e=>Math.min(_r-1,e+1)),disabled:vr>=_r-1,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,children:(0,Y.jsx)(De,{className:`w-4 h-4`})}),(0,Y.jsx)(`button`,{onClick:()=>vt(_r-1),disabled:vr>=_r-1,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,title:`Last page`,children:(0,Y.jsx)(k,{className:`w-4 h-4`})})]})]})]})]}):(0,Y.jsx)(mr,{hasFilters:rr,onAddSpool:()=>E({spool:null,mode:`create`}),t:n}),w!==null&&(0,Y.jsx)(gn,{isOpen:!0,onClose:()=>E(null),spool:w.spool,mode:w.mode,currencySymbol:vn,spoolmanMode:e,spoolsQueryKey:Ot}),O&&(0,Y.jsx)(Fe,{title:O.type===`delete`?n(`common.delete`):O.type===`archive`?n(`inventory.archive`):O.type===`reset-consumed-counter`?n(`inventory.resetConsumedCounter`):n(`inventory.resetAllConsumedCounters`),message:O.type===`delete`?n(`inventory.deleteConfirm`):O.type===`archive`?n(`inventory.archiveConfirm`):O.type===`reset-consumed-counter`?n(`inventory.resetConsumedCounterConfirm`):n(`inventory.resetAllConsumedCountersConfirm`,{count:cn.length}),confirmText:O.type===`delete`?n(`common.delete`):O.type===`archive`?n(`inventory.archive`):n(`inventory.resetConsumedCounter`),variant:O.type===`archive`?`warning`:`danger`,onConfirm:()=>{O.type===`delete`?Zt.mutate(O.spoolId):O.type===`archive`?Qt.mutate(O.spoolId):O.type===`reset-consumed-counter`?en.mutate(O.spoolId):tn.mutate(cn),A(null)},onCancel:()=>A(null)}),(0,Y.jsx)(it,{isOpen:at,onClose:()=>ot(!1),columns:nt,defaultColumns:Wn,onSave:ir}),(0,Y.jsx)(jn,{isOpen:M!==null,onClose:()=>P(null),availableSpools:On,initialSelectedIds:M??[],spoolmanMode:e}),(0,Y.jsx)(Ln,{isOpen:ft,selectedCount:G.size,isPending:rn.isPending,availableLocations:Lt.map(e=>({id:e.id,name:e.name})),availableMaterials:zn((q??[]).map(e=>e.material)),availableSubtypes:zn((q??[]).map(e=>e.subtype)),availableBrands:zn((q??[]).map(e=>e.brand)),availableCategories:zn((q??[]).map(e=>e.category)),availableMaterialNumbers:zn((q??[]).map(e=>e.material_number)),availableSlicerFilaments:zn((q??[]).map(e=>e.slicer_filament)),availableSlicerFilamentNames:zn((q??[]).map(e=>e.slicer_filament_name)),spoolmanMode:e,onClose:()=>pt(!1),onApply:e=>rn.mutate({ids:[...G],update:e})}),K&&(0,Y.jsx)(Fe,{title:n(K===`delete`?`inventory.bulk.deleteTitle`:K===`archive`?`inventory.bulk.archiveTitle`:K===`restore`?`inventory.bulk.restoreTitle`:`inventory.bulk.resetUsageTitle`),message:n(K===`delete`?`inventory.bulk.deleteMessage`:K===`archive`?`inventory.bulk.archiveMessage`:K===`restore`?`inventory.bulk.restoreMessage`:`inventory.bulk.resetUsageMessage`,{count:G.size}),confirmText:n(K===`delete`?`common.delete`:K===`archive`?`inventory.archive`:K===`restore`?`inventory.restore`:`inventory.resetConsumedCounter`),variant:K===`delete`?`danger`:`warning`,isLoading:an.isPending||on.isPending||sn.isPending||tn.isPending,onConfirm:()=>{let e=[...G];K===`delete`?an.mutate(e):K===`archive`?on.mutate(e):K===`restore`?sn.mutate(e):tn.mutate(e)},onCancel:()=>mt(null)}),L&&(0,Y.jsx)(Mn,{onClose:()=>ie(!1),onImported:e=>{ie(!1),a.invalidateQueries({queryKey:Ot}),p(n(`inventory.csv.importSuccess`,`{{count}} spools imported`,{count:e}),`success`)}}),(0,Y.jsx)(re,{open:ue,onClose:()=>de(!1),onPickLocation:e=>kn(String(e))}),(0,Y.jsx)(Nn,{open:fe,onClose:()=>pe(!1)})]})}function ar({pageIndex:e,pageSize:t,totalRows:n,totalPages:r,onPageChange:i,onPageSizeChange:a,t:o}){let s=t===-1;if(r<=1&&!s)return null;let c=s?n||1:t;return(0,Y.jsxs)(`div`,{className:`flex items-center justify-between pt-2 text-sm`,children:[(0,Y.jsx)(`span`,{className:`text-bambu-gray`,children:s?`${n} ${o(n===1?`inventory.spool`:`inventory.spools`)}`:(0,Y.jsxs)(Y.Fragment,{children:[o(`inventory.showing`),` `,e*c+1,` `,o(`inventory.to`),` `,Math.min((e+1)*c,n),` `,o(`inventory.of`),` `,n,` `,o(`inventory.spools`)]})}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`span`,{className:`text-bambu-gray`,children:o(`inventory.show`)}),(0,Y.jsxs)(`select`,{value:t,onChange:e=>a(Number(e.target.value)),className:`px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:outline-none focus:border-bambu-green`,children:[[15,30,50,100].map(e=>(0,Y.jsx)(`option`,{value:e,children:e},e)),(0,Y.jsx)(`option`,{value:-1,children:o(`inventory.all`)})]}),!s&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`button`,{onClick:()=>i(0),disabled:e===0,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,children:(0,Y.jsx)(ee,{className:`w-4 h-4`})}),(0,Y.jsx)(`button`,{onClick:()=>i(Math.max(0,e-1)),disabled:e===0,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,children:(0,Y.jsx)(Ue,{className:`w-4 h-4`})}),(0,Y.jsxs)(`span`,{className:`text-bambu-gray px-2 whitespace-nowrap`,children:[o(`inventory.page`),` `,e+1,` `,o(`inventory.of`),` `,r]}),(0,Y.jsx)(`button`,{onClick:()=>i(Math.min(r-1,e+1)),disabled:e>=r-1,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,children:(0,Y.jsx)(De,{className:`w-4 h-4`})}),(0,Y.jsx)(`button`,{onClick:()=>i(r-1),disabled:e>=r-1,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,children:(0,Y.jsx)(k,{className:`w-4 h-4`})})]})]})]})}function or({spool:e,remaining:t,pct:n,onClick:r,onPrintLabel:i,onCopy:a,t:o,colorizeLocationSensors:s,locationSensorAboveColor:c,locationSensorBelowColor:l,locationSensorOptimalColor:u,dateFormat:d}){let f=ve({rgba:e.rgba,extraColors:e.extra_colors,effectType:e.effect_type,subtype:e.subtype,effectSize:`card`});return(0,Y.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg overflow-hidden border border-bambu-dark-tertiary hover:border-bambu-green transition-colors cursor-pointer ${e.archived_at?`opacity-50`:``}`,onClick:r,children:[(0,Y.jsxs)(`div`,{className:`h-14 flex items-center justify-center`,style:f,children:[(0,Y.jsx)(`span`,{className:`bg-white/90 text-gray-800 px-3 py-0.5 rounded-full text-sm font-medium`,children:Ve(e.color_name,e.rgba,e.color_name_is_synthesized)||`-`}),a&&(0,Y.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),a()},className:`p-1.5 bg-black/20 hover:bg-black/40 text-white rounded-full transition-colors`,title:o(`inventory.copySpool`),children:(0,Y.jsx)(M,{className:`w-3.5 h-3.5`})})]}),(0,Y.jsxs)(`div`,{className:`p-4 space-y-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`h3`,{className:`font-semibold text-white`,children:[e.material,e.subtype?` ${e.subtype}`:``]}),(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e.brand||`-`})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1`,children:[i&&(0,Y.jsx)(`button`,{onClick:e=>{e.stopPropagation(),i()},className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,title:o(`inventory.labels.printOne`),"aria-label":o(`inventory.labels.printOne`),children:(0,Y.jsx)(U,{className:`w-4 h-4`})}),(0,Y.jsxs)(`span`,{className:`text-xs font-mono text-bambu-gray bg-bambu-dark-tertiary px-2 py-1 rounded`,children:[`#`,e.id]})]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`div`,{className:`flex justify-between text-xs text-bambu-gray mb-1`,children:[(0,Y.jsx)(`span`,{children:o(`inventory.remaining`)}),(0,Y.jsxs)(`span`,{children:[Math.round(n),`%`]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`div`,{className:`flex-1 h-2 bg-bambu-dark-tertiary rounded-full overflow-hidden`,children:(0,Y.jsx)(`div`,{className:`h-full rounded-full ${n>50?`bg-bambu-green`:n>20?`bg-yellow-500`:`bg-red-500`}`,style:{width:`${Math.min(n,100)}%`}})}),(0,Y.jsxs)(`span`,{className:`text-xs text-bambu-gray min-w-[40px] text-right`,children:[Math.round(t),`g`]})]})]}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-2 text-xs`,children:[e.last_dried_at&&(0,Y.jsxs)(`div`,{className:`col-span-2`,children:[(0,Y.jsxs)(`span`,{className:`text-bambu-gray/60`,children:[o(`inventory.lastDried`),`: `]}),(0,Y.jsx)(`span`,{className:`text-bambu-gray`,children:[Xn(e.last_dried_at,d),Yn(e)].filter(Boolean).join(` · `)})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`span`,{className:`text-bambu-gray/60`,children:[o(`inventory.labelWeight`),`: `]}),(0,Y.jsx)(`span`,{className:`text-bambu-gray`,children:qn(e.label_weight)})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`span`,{className:`text-bambu-gray/60`,children:[o(`inventory.weightUsed`),`: `]}),(0,Y.jsx)(`span`,{className:`text-bambu-gray`,children:e.weight_used>0?qn(e.weight_used):`-`})]})]}),e.location_id&&(0,Y.jsx)(dr,{locationId:e.location_id,locationName:e.storage_location??null,isLast:!e.note,colorize:s,aboveColor:c,belowColor:l,optimalColor:u}),e.note&&(0,Y.jsx)(`div`,{className:`text-xs text-bambu-gray/60 pt-3 border-t border-bambu-dark-tertiary truncate`,title:e.note,children:e.note})]})]})}var sr={temperature:0,humidity:1,battery:2};function cr(e){return e===`humidity`?`mr-[2px]`:e===`battery`?`mr-[3px]`:``}function lr(e,t){return h(e,t,{decimals:2})}function ur(e,t,n,r,i){return t&&L(ie(e),n,r,i)||`text-bambu-gray`}function dr({locationId:e,locationName:t,isLast:n,colorize:i,aboveColor:a,belowColor:o,optimalColor:s}){let{t:l}=c(),{data:d}=u({queryKey:[`settings`],queryFn:r.getSettings}),f=(d?.location_sensor_poll_interval||120)*1e3,{data:p}=u({queryKey:[`locationHaSensors`],queryFn:()=>r.getLocationHASensors()}),m=(p??[]).some(t=>t.location_id===e),{data:h}=u({queryKey:[`locationHaSensorReadings`,e],queryFn:()=>r.getLocationHASensorReadings(e,!1),refetchInterval:f,enabled:m}),_=h?.filter(e=>e.show_on_card);if(!_?.length)return null;let v=_.find(e=>e.device_class===`battery`),y=_.filter(e=>e.device_class!==`battery`).sort((e,t)=>(sr[e.device_class??``]??99)-(sr[t.device_class??``]??99));return(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 pt-3 border-t border-bambu-dark-tertiary text-xs text-bambu-gray ${n?`-mb-1`:``}`,children:[t&&(0,Y.jsx)(`span`,{className:`truncate`,children:t}),(0,Y.jsx)(`span`,{className:`text-bambu-gray/40`,children:`|`}),(0,Y.jsx)(`div`,{className:`flex items-center gap-3`,children:y.map((e,t)=>{let n=g(e),r=t===0?`ml-[-3.6px]`:``;return(0,Y.jsxs)(`span`,{title:e.name,className:`flex items-center gap-[3px]`,children:[(0,Y.jsx)(n,{className:`w-3 h-3 ${cr(e.device_class)} ${r}`}),(0,Y.jsx)(`span`,{className:ur(e,i,a,o,s),children:lr(e,l)})]},e.id)})}),v&&(()=>{let e=g(v);return(0,Y.jsxs)(`span`,{title:v.name,className:`flex items-center gap-[3px] ml-auto`,children:[(0,Y.jsx)(e,{className:`w-3 h-3 ${cr(v.device_class)}`}),(0,Y.jsx)(`span`,{className:ur(v,i,a,o,s),children:lr(v,l)})]},v.id)})()]})}function fr({spool:e,remaining:t,pct:n,isSelected:r,onToggleSelected:i,onEdit:a,onCopy:o,onRestore:s,onArchive:c,onDelete:l,onPrintLabel:u,onResetConsumedCounter:d,visibleColumns:f,assignmentMap:p,catalogMap:m,locationReadingsMap:h,currencySymbol:g,dateFormat:_,t:v,onSyncWeight:y,colorizeLocationSensors:b,locationSensorAboveColor:x,locationSensorBelowColor:C,locationSensorOptimalColor:w}){return(0,Y.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/50 hover:bg-bambu-dark-tertiary/30 transition-colors cursor-pointer ${e.archived_at?`opacity-50`:``} ${r?`bg-bambu-green/10`:``}`,onClick:a,children:[(0,Y.jsx)(`td`,{className:`w-10 px-3 py-3`,onClick:e=>e.stopPropagation(),children:i&&(0,Y.jsx)(`input`,{type:`checkbox`,className:`h-4 w-4 cursor-pointer`,"aria-label":v(`inventory.bulk.selectRow`),checked:!!r,onChange:i})}),f.map(r=>(0,Y.jsx)(`td`,{className:`py-3 px-4`,children:Qn[r]?.({spool:e,remaining:t,pct:n,assignmentMap:p,catalogMap:m,locationReadingsMap:h,currencySymbol:g,dateFormat:_,t:v,onSyncWeight:y,colorizeLocationSensors:b,locationSensorAboveColor:x,locationSensorBelowColor:C,locationSensorOptimalColor:w})},r)),(0,Y.jsx)(`td`,{className:`py-3 px-4`,children:(0,Y.jsxs)(`div`,{className:`flex items-center justify-end gap-1`,onClick:e=>e.stopPropagation(),children:[(0,Y.jsx)(`button`,{onClick:a,className:`p-1.5 text-bambu-gray hover:text-white rounded transition-colors`,title:v(`common.edit`),children:(0,Y.jsx)(I,{className:`w-4 h-4`})}),o&&(0,Y.jsx)(`button`,{onClick:o,className:`p-1.5 text-bambu-gray hover:text-bambu-green rounded transition-colors`,title:v(`inventory.copySpool`),children:(0,Y.jsx)(M,{className:`w-4 h-4`})}),u&&(0,Y.jsx)(`button`,{onClick:u,className:`p-1.5 text-bambu-gray hover:text-white rounded transition-colors`,title:v(`inventory.labels.printOne`),children:(0,Y.jsx)(U,{className:`w-4 h-4`})}),d&&e.weight_used>0&&(0,Y.jsx)(`button`,{onClick:d,className:`p-1.5 text-bambu-gray hover:text-orange-600 dark:hover:text-orange-400 rounded transition-colors`,title:v(`inventory.resetConsumedCounterTooltip`),children:(0,Y.jsx)(S,{className:`w-4 h-4`})}),e.archived_at?(0,Y.jsx)(`button`,{onClick:s,className:`p-1.5 text-bambu-gray hover:text-bambu-green rounded transition-colors`,title:v(`inventory.restore`),children:(0,Y.jsx)(Se,{className:`w-4 h-4`})}):(0,Y.jsx)(`button`,{onClick:c,className:`p-1.5 text-bambu-gray hover:text-yellow-600 dark:hover:text-yellow-400 rounded transition-colors`,title:v(`inventory.archive`),children:(0,Y.jsx)(Te,{className:`w-4 h-4`})}),(0,Y.jsx)(`button`,{onClick:l,className:`p-1.5 text-bambu-gray hover:text-red-600 dark:hover:text-red-400 rounded transition-colors`,title:v(`common.delete`),children:(0,Y.jsx)(be,{className:`w-4 h-4`})})]})})]})}function pr({spools:e,headerSpool:t,remaining:n,pct:r,isExpanded:i,onToggle:a,onEdit:o,onCopy:s,onArchive:c,onDelete:l,onPrintLabel:u,onResetConsumedCounter:d,visibleColumns:f,assignmentMap:p,catalogMap:m,locationReadingsMap:h,currencySymbol:g,dateFormat:_,t:v,onSyncWeight:y,colorizeLocationSensors:b,locationSensorAboveColor:x,locationSensorBelowColor:S,locationSensorOptimalColor:C,selectedIds:w,onToggleSelected:E,onToggleGroupSelected:D}){let O=!!w&&e.every(e=>w.has(e.id));return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/50 hover:bg-bambu-dark-tertiary/30 transition-colors cursor-pointer bg-bambu-green/5`,onClick:a,children:[(0,Y.jsx)(`td`,{className:`w-10 px-3 py-3`,onClick:e=>e.stopPropagation(),children:D&&(0,Y.jsx)(`input`,{type:`checkbox`,className:`h-4 w-4 cursor-pointer`,"aria-label":v(`inventory.bulk.selectGroup`),checked:O,onChange:t=>D(e.map(e=>e.id),t.target.checked)})}),f.map((a,o)=>(0,Y.jsx)(`td`,{className:`py-3 px-4`,children:o===0?(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(T,{className:`w-4 h-4 text-bambu-gray transition-transform ${i?``:`-rotate-90`}`}),Qn[a]?.({spool:t,remaining:n,pct:r,assignmentMap:p,catalogMap:m,locationReadingsMap:h,currencySymbol:g,dateFormat:_,t:v,onSyncWeight:y,colorizeLocationSensors:b,locationSensorAboveColor:x,locationSensorBelowColor:S,locationSensorOptimalColor:C})]}):a===`id`?(0,Y.jsx)(`span`,{className:`text-xs font-medium bg-bambu-green/20 text-bambu-green px-2 py-0.5 rounded-full`,children:v(`inventory.groupedSpools`,{count:e.length})}):Qn[a]?.({spool:t,remaining:n,pct:r,assignmentMap:p,catalogMap:m,locationReadingsMap:h,currencySymbol:g,dateFormat:_,t:v,onSyncWeight:y,colorizeLocationSensors:b,locationSensorAboveColor:x,locationSensorBelowColor:S,locationSensorOptimalColor:C})},a)),(0,Y.jsx)(`td`,{className:`py-3 px-4`,children:(0,Y.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:e.map(e=>`#${e.id}`).join(`, `)})})]}),i&&e.map(e=>{let t=Math.max(0,e.label_weight-e.weight_used);return(0,Y.jsx)(fr,{spool:e,remaining:t,pct:e.label_weight>0?t/e.label_weight*100:0,isSelected:w?.has(e.id),onToggleSelected:E?()=>E(e.id):void 0,onEdit:()=>o(e),onCopy:s?()=>s(e):void 0,onRestore:()=>{},onArchive:()=>c(e.id),onDelete:()=>l(e.id),onPrintLabel:u?()=>u(e.id):void 0,onResetConsumedCounter:d?()=>d(e.id):void 0,visibleColumns:f,assignmentMap:p,catalogMap:m,locationReadingsMap:h,currencySymbol:g,dateFormat:_,t:v,onSyncWeight:y,colorizeLocationSensors:b,locationSensorAboveColor:x,locationSensorBelowColor:S,locationSensorOptimalColor:C},e.id)})]})}function mr({hasFilters:e,onAddSpool:t,t:n}){return(0,Y.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-16 px-4`,children:[(0,Y.jsxs)(`div`,{className:`relative mb-6`,children:[(0,Y.jsx)(`div`,{className:`absolute inset-0 -m-4 bg-bambu-green/5 rounded-full blur-2xl`}),(0,Y.jsxs)(`div`,{className:`relative flex items-center justify-center w-24 h-24 rounded-2xl bg-gradient-to-br from-bambu-dark-secondary to-bambu-dark-tertiary border border-bambu-dark-tertiary shadow-lg`,children:[(0,Y.jsx)(`div`,{className:`absolute -top-1 -right-1 w-3 h-3 rounded-full bg-bambu-green/30`}),(0,Y.jsx)(`div`,{className:`absolute -bottom-2 -left-2 w-2 h-2 rounded-full bg-bambu-green/20`}),e?(0,Y.jsx)(se,{className:`w-10 h-10 text-bambu-gray/40`,strokeWidth:1.5}):(0,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsx)(`div`,{className:`w-14 h-14 rounded-full border-4 border-bambu-gray/20 flex items-center justify-center`,children:(0,Y.jsx)(`div`,{className:`w-6 h-6 rounded-full bg-bambu-gray/10 border-2 border-bambu-gray/20`})}),(0,Y.jsx)(`div`,{className:`absolute -bottom-1 -right-1 w-6 h-6 rounded-full bg-bambu-green flex items-center justify-center shadow-md`,children:(0,Y.jsx)(`span`,{className:`text-white text-lg font-bold leading-none`,children:`+`})})]})]})]}),(0,Y.jsx)(`h3`,{className:`text-lg font-semibold text-white mb-2 text-center`,children:e?n(`inventory.noSpoolsMatch`):n(`inventory.noSpools`).split(`.`)[0]}),(0,Y.jsx)(`p`,{className:`text-sm text-bambu-gray text-center max-w-sm mb-6`,children:n(e?`inventory.noSpoolsMatchDesc`:`inventory.noSpools`)}),!e&&(0,Y.jsxs)(V,{onClick:t,children:[(0,Y.jsx)(oe,{className:`w-4 h-4`}),n(`inventory.addSpool`)]})]})}export{rr as default};