7)throw RangeError(`Invalid value`);let u,d;for(u=a;;u++){let n=t.getNumDataCodewords(u,r)*8,i=o.getTotalBits(e,u);if(i<=n){d=i;break}if(u>=s)throw RangeError(`Data too long`)}for(let e of[t.Ecc.MEDIUM,t.Ecc.QUARTILE,t.Ecc.HIGH])l&&d<=t.getNumDataCodewords(u,e)*8&&(r=e);let f=[];for(let t of e){n(t.mode.modeBits,4,f),n(t.numChars,t.mode.numCharCountBits(u),f);for(let e of t.getData())f.push(e)}i(f.length==d);let p=t.getNumDataCodewords(u,r)*8;i(f.length<=p),n(0,Math.min(4,p-f.length),f),n(0,(8-f.length%8)%8,f),i(f.length%8==0);for(let e=236;f.lengthm[t>>>3]|=e<<7-(t&7)),new t(u,r,m,c)}getModule(e,t){return 0<=e&&e>>9)*1335;let a=(t<<10|n)^21522;i(a>>>15==0);for(let e=0;e<=5;e++)this.setFunctionModule(8,e,r(a,e));this.setFunctionModule(8,7,r(a,6)),this.setFunctionModule(8,8,r(a,7)),this.setFunctionModule(7,8,r(a,8));for(let e=9;e<15;e++)this.setFunctionModule(14-e,8,r(a,e));for(let e=0;e<8;e++)this.setFunctionModule(this.size-1-e,8,r(a,e));for(let e=8;e<15;e++)this.setFunctionModule(8,this.size-15+e,r(a,e));this.setFunctionModule(8,this.size-8,!0)}drawVersion(){if(this.version<7)return;let e=this.version;for(let t=0;t<12;t++)e=e<<1^(e>>>11)*7973;let t=this.version<<12|e;i(t>>>18==0);for(let e=0;e<18;e++){let n=r(t,e),i=this.size-11+e%3,a=Math.floor(e/3);this.setFunctionModule(i,a,n),this.setFunctionModule(a,i,n)}}drawFinderPattern(e,t){for(let n=-4;n<=4;n++)for(let r=-4;r<=4;r++){let i=Math.max(Math.abs(r),Math.abs(n)),a=e+r,o=t+n;0<=a&&a{(e!=l-o||n>=c)&&f.push(t[e])});return i(f.length==s),f}drawCodewords(e){if(e.length!=Math.floor(t.getNumRawDataModules(this.version)/8))throw RangeError(`Invalid argument`);let n=0;for(let t=this.size-1;t>=1;t-=2){t==6&&(t=5);for(let i=0;i>>3],7-(n&7)),n++)}}i(n==e.length*8)}applyMask(e){if(e<0||e>7)throw RangeError(`Mask value out of range`);for(let t=0;t5&&e++):(this.finderPenaltyAddHistory(i,a),r||(e+=this.finderPenaltyCountPatterns(a)*t.PENALTY_N3),r=this.modules[n][o],i=1);e+=this.finderPenaltyTerminateAndCount(r,i,a)*t.PENALTY_N3}for(let n=0;n5&&e++):(this.finderPenaltyAddHistory(i,a),r||(e+=this.finderPenaltyCountPatterns(a)*t.PENALTY_N3),r=this.modules[o][n],i=1);e+=this.finderPenaltyTerminateAndCount(r,i,a)*t.PENALTY_N3}for(let n=0;ne+ +!!t,n);let r=this.size*this.size,a=Math.ceil(Math.abs(n*20-r*10)/r)-1;return i(0<=a&&a<=9),e+=a*t.PENALTY_N4,i(0<=e&&e<=2568888),e}getAlignmentPatternPositions(){if(this.version==1)return[];{let e=Math.floor(this.version/7)+2,t=this.version==32?26:Math.ceil((this.version*4+4)/(e*2-2))*2,n=[6];for(let r=this.size-7;n.lengtht.MAX_VERSION)throw RangeError(`Version number out of range`);let n=(16*e+128)*e+64;if(e>=2){let t=Math.floor(e/7)+2;n-=(25*t-10)*t-55,e>=7&&(n-=36)}return i(208<=n&&n<=29648),n}static getNumDataCodewords(e,n){return Math.floor(t.getNumRawDataModules(e)/8)-t.ECC_CODEWORDS_PER_BLOCK[n.ordinal][e]*t.NUM_ERROR_CORRECTION_BLOCKS[n.ordinal][e]}static reedSolomonComputeDivisor(e){if(e<1||e>255)throw RangeError(`Degree out of range`);let n=[];for(let t=0;t0);for(let i of e){let e=i^r.shift();r.push(0),n.forEach((n,i)=>r[i]^=t.reedSolomonMultiply(n,e))}return r}static reedSolomonMultiply(e,t){if(e>>>8||t>>>8)throw RangeError(`Byte out of range`);let n=0;for(let r=7;r>=0;r--)n=n<<1^(n>>>7)*285,n^=(t>>>r&1)*e;return i(n>>>8==0),n}finderPenaltyCountPatterns(e){let t=e[1];i(t<=this.size*3);let n=t>0&&e[2]==t&&e[3]==t*3&&e[4]==t&&e[5]==t;return(n&&e[0]>=t*4&&e[6]>=t?1:0)+(n&&e[6]>=t*4&&e[0]>=t?1:0)}finderPenaltyTerminateAndCount(e,t,n){return e&&(this.finderPenaltyAddHistory(t,n),t=0),t+=this.size,this.finderPenaltyAddHistory(t,n),this.finderPenaltyCountPatterns(n)}finderPenaltyAddHistory(e,t){t[0]==0&&(e+=this.size),t.pop(),t.unshift(e)}};t.MIN_VERSION=1,t.MAX_VERSION=40,t.PENALTY_N1=3,t.PENALTY_N2=3,t.PENALTY_N3=40,t.PENALTY_N4=10,t.ECC_CODEWORDS_PER_BLOCK=[[-1,7,10,15,20,26,18,20,24,30,18,20,24,26,30,22,24,28,30,28,28,28,28,30,30,26,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,10,16,26,18,24,16,18,22,22,26,30,22,22,24,24,28,28,26,26,26,26,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28],[-1,13,22,18,26,18,24,18,22,20,24,28,26,24,20,30,24,28,28,26,30,28,30,30,30,30,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,17,28,22,16,22,28,26,26,24,28,24,28,22,24,24,30,28,28,26,28,30,24,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30]],t.NUM_ERROR_CORRECTION_BLOCKS=[[-1,1,1,1,1,1,2,2,2,2,4,4,4,4,4,6,6,6,6,7,8,8,9,9,10,12,12,12,13,14,15,16,17,18,19,19,20,21,22,24,25],[-1,1,1,1,2,2,4,4,4,5,5,5,8,9,9,10,10,11,13,14,16,17,17,18,20,21,23,25,26,28,29,31,33,35,37,38,40,43,45,47,49],[-1,1,1,2,2,4,4,6,6,8,8,8,10,12,16,12,17,16,18,21,20,23,23,25,27,29,34,34,35,38,40,43,45,48,51,53,56,59,62,65,68],[-1,1,1,2,4,4,4,5,6,8,8,11,11,16,16,18,16,19,21,25,25,25,34,30,32,35,37,40,42,45,48,51,54,57,60,63,66,70,74,77,81]],e.QrCode=t;function n(e,t,n){if(t<0||t>31||e>>>t)throw RangeError(`Value out of range`);for(let r=t-1;r>=0;r--)n.push(e>>>r&1)}function r(e,t){return(e>>>t&1)!=0}function i(e){if(!e)throw Error(`Assertion error`)}let a=class e{constructor(e,t,n){if(this.mode=e,this.numChars=t,this.bitData=n,t<0)throw RangeError(`Invalid argument`);this.bitData=n.slice()}static makeBytes(t){let r=[];for(let e of t)n(e,8,r);return new e(e.Mode.BYTE,t.length,r)}static makeNumeric(t){if(!e.isNumeric(t))throw RangeError(`String contains non-numeric characters`);let r=[];for(let e=0;e=1<{(e=>{let t=class{constructor(e,t){this.ordinal=e,this.formatBits=t}};t.LOW=new t(0,1),t.MEDIUM=new t(1,0),t.QUARTILE=new t(2,3),t.HIGH=new t(3,2),e.Ecc=t})(e.QrCode||={})})(X3||={}),(e=>{(e=>{let t=class{constructor(e,t){this.modeBits=e,this.numBitsCharCount=t}numCharCountBits(e){return this.numBitsCharCount[Math.floor((e+7)/17)]}};t.NUMERIC=new t(1,[10,12,14]),t.ALPHANUMERIC=new t(2,[9,11,13]),t.BYTE=new t(4,[8,16,16]),t.KANJI=new t(8,[8,10,12]),t.ECI=new t(7,[0,0,0]),e.Mode=t})(e.QrSegment||={})})(X3||={});var Z3=X3,UVe={L:Z3.QrCode.Ecc.LOW,M:Z3.QrCode.Ecc.MEDIUM,Q:Z3.QrCode.Ecc.QUARTILE,H:Z3.QrCode.Ecc.HIGH},Q3=128,$3=`L`,e6=`#FFFFFF`,t6=`#000000`,n6=!1,r6=1,WVe=4,GVe=0,KVe=.1;function i6(e,t=0){let n=[];return e.forEach(function(e,r){let i=null;e.forEach(function(a,o){if(!a&&i!==null){n.push(`M${i+t} ${r+t}h${o-i}v1H${i+t}z`),i=null;return}if(o===e.length-1){if(!a)return;i===null?n.push(`M${o+t},${r+t} h1v1H${o+t}z`):n.push(`M${i+t},${r+t} h${o+1-i}v1H${i+t}z`);return}a&&i===null&&(i=o)})}),n.join(``)}function a6(e,t){return e.slice().map((e,n)=>n=t.y+t.h?e:e.map((e,n)=>n=t.x+t.w?e:!1))}function qVe(e,t,n,r){if(r==null)return null;let i=e.length+n*2,a=Math.floor(t*KVe),o=i/t,s=(r.width||a)*o,c=(r.height||a)*o,l=r.x==null?e.length/2-s/2:r.x*o,u=r.y==null?e.length/2-c/2:r.y*o,d=r.opacity==null?1:r.opacity,f=null;if(r.excavate){let e=Math.floor(l),t=Math.floor(u);f={x:e,y:t,w:Math.ceil(s+l-e),h:Math.ceil(c+u-t)}}let p=r.crossOrigin;return{x:l,y:u,h:c,w:s,excavation:f,opacity:d,crossOrigin:p}}function JVe(e,t){return t==null?e?WVe:GVe:Math.max(Math.floor(t),0)}function o6({value:e,level:t,minVersion:n,includeMargin:r,marginSize:i,imageSettings:a,size:o,boostLevel:s}){let c=y.useMemo(()=>{let r=(Array.isArray(e)?e:[e]).reduce((e,t)=>(e.push(...Z3.QrSegment.makeSegments(t)),e),[]);return Z3.QrCode.encodeSegments(r,UVe[t],n,void 0,void 0,s)},[e,t,n,s]),{cells:l,margin:u,numCells:d,calculatedImageSettings:f}=y.useMemo(()=>{let e=c.getModules(),t=JVe(r,i);return{cells:e,margin:t,numCells:e.length+t*2,calculatedImageSettings:qVe(e,o,t,a)}},[c,o,a,r,i]);return{qrcode:c,margin:u,cells:l,numCells:d,calculatedImageSettings:f}}var YVe=function(){try{new Path2D().addPath(new Path2D)}catch{return!1}return!0}(),XVe=y.forwardRef(function(e,t){let n=e,{value:r,size:i=Q3,level:a=$3,bgColor:o=e6,fgColor:s=t6,includeMargin:c=n6,minVersion:l=r6,boostLevel:u,marginSize:d,imageSettings:f}=n,p=Y3(n,[`value`,`size`,`level`,`bgColor`,`fgColor`,`includeMargin`,`minVersion`,`boostLevel`,`marginSize`,`imageSettings`]),{style:m}=p,h=Y3(p,[`style`]),g=f?.src,_=y.useRef(null),v=y.useRef(null),b=y.useCallback(e=>{_.current=e,typeof t==`function`?t(e):t&&(t.current=e)},[t]),[x,S]=y.useState(!1),{margin:C,cells:w,numCells:T,calculatedImageSettings:E}=o6({value:r,level:a,minVersion:l,boostLevel:u,includeMargin:c,marginSize:d,imageSettings:f,size:i});y.useEffect(()=>{if(_.current!=null){let e=_.current,t=e.getContext(`2d`);if(!t)return;let n=w,r=v.current,a=E!=null&&r!==null&&r.complete&&r.naturalHeight!==0&&r.naturalWidth!==0;a&&E.excavation!=null&&(n=a6(w,E.excavation));let c=window.devicePixelRatio||1;e.height=e.width=i*c;let l=i/T*c;t.scale(l,l),t.fillStyle=o,t.fillRect(0,0,T,T),t.fillStyle=s,YVe?t.fill(new Path2D(i6(n,C))):w.forEach(function(e,n){e.forEach(function(e,r){e&&t.fillRect(r+C,n+C,1,1)})}),E&&(t.globalAlpha=E.opacity),a&&t.drawImage(r,E.x+C,E.y+C,E.w,E.h)}}),y.useEffect(()=>{S(!1)},[g]);let D=J3({height:i,width:i},m),O=null;return g!=null&&(O=y.createElement(`img`,{src:g,key:g,style:{display:`none`},onLoad:()=>{S(!0)},ref:v,crossOrigin:E?.crossOrigin})),y.createElement(y.Fragment,null,y.createElement(`canvas`,J3({style:D,height:i,width:i,ref:b,role:`img`},h)),O)});XVe.displayName=`QRCodeCanvas`;var s6=y.forwardRef(function(e,t){let n=e,{value:r,size:i=Q3,level:a=$3,bgColor:o=e6,fgColor:s=t6,includeMargin:c=n6,minVersion:l=r6,boostLevel:u,title:d,marginSize:f,imageSettings:p}=n,m=Y3(n,[`value`,`size`,`level`,`bgColor`,`fgColor`,`includeMargin`,`minVersion`,`boostLevel`,`title`,`marginSize`,`imageSettings`]),{margin:h,cells:g,numCells:_,calculatedImageSettings:v}=o6({value:r,level:a,minVersion:l,boostLevel:u,includeMargin:c,marginSize:f,imageSettings:p,size:i}),b=g,x=null;p!=null&&v!=null&&(v.excavation!=null&&(b=a6(g,v.excavation)),x=y.createElement(`image`,{href:p.src,height:v.h,width:v.w,x:v.x+h,y:v.y+h,preserveAspectRatio:`none`,opacity:v.opacity,crossOrigin:v.crossOrigin}));let S=i6(b,h);return y.createElement(`svg`,J3({height:i,width:i,viewBox:`0 0 ${_} ${_}`,ref:t,role:`img`},m),!!d&&y.createElement(`title`,null,d),y.createElement(`path`,{fill:o,d:`M0,0 h${_}v${_}H0z`,shapeRendering:`crispEdges`}),y.createElement(`path`,{fill:s,d:S,shapeRendering:`crispEdges`}),x)});s6.displayName=`QRCodeSVG`;function ZVe(e,t){return`bambuddy://config?v=1&url=${encodeURIComponent(e)}&key=${encodeURIComponent(t)}`}function QVe({apiKey:e,baseUrl:t,onClose:n}){let{t:r}=U(),i=ZVe(t??window.location.origin,e);return(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[n]),(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:n,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-sm`,onClick:e=>e.stopPropagation(),children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:r(`settings.apiKeyQrTitle`)}),(0,G.jsx)(`button`,{onClick:n,className:`text-bambu-gray hover:text-white transition-colors`,"aria-label":r(`common.close`),children:(0,G.jsx)($u,{className:`w-5 h-5`})})]}),(0,G.jsxs)(`div`,{className:`p-6 flex flex-col items-center`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4 text-center`,children:r(`settings.apiKeyQrCaption`)}),(0,G.jsx)(`div`,{className:`bg-white p-4 rounded-lg mb-4`,children:(0,G.jsx)(s6,{value:i,size:256})}),(0,G.jsxs)(`div`,{className:`flex items-start gap-2 text-xs text-amber-700 dark:text-amber-400 mb-4`,children:[(0,G.jsx)(Pu,{className:`w-4 h-4 flex-shrink-0 mt-0.5`}),(0,G.jsx)(`span`,{children:r(`settings.apiKeyQrWarning`)})]}),(0,G.jsx)(Q,{onClick:n,className:`w-full`,children:r(`common.close`)})]})]})})}var $Ve=300,c6=2;function l6({onSuccess:e}){let{t}=U(),n=so(),[r,i]=(0,y.useState)(``),[a,o]=(0,y.useState)(``),[s,c]=(0,y.useState)(null),[l,u]=(0,y.useState)(null);(0,y.useEffect)(()=>{let e=r.trim();if(e.lengtho(e),$Ve);return()=>clearTimeout(t)},[r]),(0,y.useEffect)(()=>{c(null),u(null)},[a]);let d=K({queryKey:[`ldap-search`,a],queryFn:()=>Z.searchLDAPDirectory(a),enabled:a.length>=c6,staleTime:3e4}),f=q({mutationFn:e=>Z.provisionLDAPUser(e),onSuccess:t=>{n.invalidateQueries({queryKey:[`users`]}),e(t)},onError:e=>{u(e.message||t(`users.modal.ldapErrorProvision`))}}),p=(0,y.useMemo)(()=>d.data?.find(e=>e.dn===s)??null,[d.data,s]),m=r.trim().length>0&&r.trim().length=c6,g=!!d.data&&d.data.length>0,_=!h&&!!d.data&&d.data.length===0&&a.length>=c6;return(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:t(`users.modal.ldapSearchLabel`)}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(Yl,{className:`w-4 h-4 text-bambu-gray absolute left-3 top-1/2 -translate-y-1/2`}),(0,G.jsx)(`input`,{type:`text`,value:r,onChange:e=>i(e.target.value),className:`w-full pl-9 pr-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:t(`users.modal.ldapSearchPlaceholder`),autoComplete:`off`})]}),m&&(0,G.jsx)(`p`,{className:`mt-1 text-xs text-bambu-gray`,children:t(`users.modal.ldapMinChars`)})]}),(0,G.jsxs)(`div`,{className:`min-h-[8rem] max-h-64 overflow-y-auto bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg`,children:[h&&(0,G.jsxs)(`div`,{className:`flex items-center justify-center py-8 text-bambu-gray`,children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin mr-2`}),(0,G.jsx)(`span`,{children:t(`users.modal.ldapSearching`)})]}),_&&(0,G.jsx)(`div`,{className:`flex items-center justify-center py-8 text-bambu-gray text-sm`,children:t(`users.modal.ldapNoResults`)}),d.isError&&(0,G.jsx)(`div`,{className:`px-3 py-4 text-sm text-red-700 dark:text-red-400`,children:d.error instanceof Error?d.error.message:t(`users.modal.ldapSearchError`)}),!h&&g&&(0,G.jsx)(`ul`,{className:`divide-y divide-bambu-dark-tertiary`,children:d.data.map(e=>(0,G.jsx)(eHe,{result:e,selected:s===e.dn,onSelect:()=>c(e.dn)},e.dn))}),!h&&!d.data&&!d.isError&&(0,G.jsx)(`div`,{className:`flex items-center justify-center py-8 text-bambu-gray text-sm`,children:t(`users.modal.ldapTypeToSearch`)})]}),p&&(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary/50 border border-bambu-green/20 rounded-lg p-3 space-y-1`,children:[(0,G.jsxs)(`p`,{className:`text-sm text-white`,children:[(0,G.jsxs)(`span`,{className:`text-bambu-gray`,children:[t(`users.modal.ldapSelectedLabel`),`: `]}),(0,G.jsx)(`span`,{className:`font-medium`,children:p.username}),p.display_name&&(0,G.jsxs)(`span`,{className:`text-bambu-gray`,children:[` — `,p.display_name]})]}),p.email&&(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:p.email}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray break-all`,children:p.dn})]}),l&&(0,G.jsx)(`div`,{className:`bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30 rounded-lg p-3`,children:(0,G.jsx)(`p`,{className:`text-sm text-red-700 dark:text-red-400`,children:l})}),(0,G.jsx)(`div`,{className:`flex justify-end`,children:(0,G.jsx)(Q,{onClick:()=>{!p||p.already_provisioned||(u(null),f.mutate(p.username))},disabled:!p||p.already_provisioned||f.isPending,children:f.isPending?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),t(`users.modal.ldapProvisioning`)]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Ml,{className:`w-4 h-4`}),t(`users.modal.ldapProvision`)]})})})]})}function eHe({result:e,selected:t,onSelect:n}){let{t:r}=U(),i=e.already_provisioned;return(0,G.jsx)(`li`,{children:(0,G.jsxs)(`button`,{type:`button`,onClick:n,disabled:i,className:`w-full text-left px-3 py-2 flex items-center gap-3 transition-colors ${i?`opacity-50 cursor-not-allowed`:t?`bg-bambu-green/10`:`hover:bg-bambu-dark-tertiary`}`,children:[(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsxs)(`p`,{className:`text-sm text-white truncate`,children:[(0,G.jsx)(`span`,{className:`font-medium`,children:e.username}),e.display_name&&(0,G.jsxs)(`span`,{className:`text-bambu-gray`,children:[` — `,e.display_name]})]}),e.email&&(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray truncate`,children:e.email})]}),i&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-xs text-bambu-gray whitespace-nowrap`,children:[(0,G.jsx)(bs,{className:`w-3.5 h-3.5`}),r(`users.modal.ldapAlreadyProvisioned`)]})]})})}function tHe({formData:e,setFormData:t,groups:n,onClose:r,onCreate:i,isCreating:a,isCreateButtonDisabled:o,ldapEnabled:s=!1,onLdapProvisioned:c}){let{t:l}=U(),[u,d]=(0,y.useState)(`local`);(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&r()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[r]);let f=n=>{t({...e,group_ids:e.group_ids.includes(n)?e.group_ids.filter(e=>e!==n):[...e.group_ids,n]})};return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:r,children:(0,G.jsxs)(Md,{className:`w-full max-w-md`,onClick:e=>e.stopPropagation(),children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Bu,{className:`w-5 h-5 text-bambu-green`}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:l(`users.modal.createUser`)})]}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray ml-7`,children:l(`users.modal.advancedAuthSubtitle`)||`with Advanced Authentication`})]}),(0,G.jsx)(Q,{variant:`ghost`,size:`sm`,onClick:r,children:(0,G.jsx)($u,{className:`w-5 h-5`})})]})}),(0,G.jsxs)(Pd,{children:[s&&(0,G.jsxs)(`div`,{className:`mb-4 flex items-center gap-1 p-1 bg-bambu-dark-secondary rounded-lg`,role:`tablist`,"aria-label":l(`users.modal.tabsAriaLabel`),children:[(0,G.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":u===`local`,onClick:()=>d(`local`),className:`flex-1 px-3 py-2 text-sm rounded-md transition-colors ${u===`local`?`bg-bambu-green/15 text-bambu-green`:`text-bambu-gray hover:text-white`}`,children:l(`users.modal.localTab`)}),(0,G.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":u===`ldap`,onClick:()=>d(`ldap`),className:`flex-1 px-3 py-2 text-sm rounded-md transition-colors ${u===`ldap`?`bg-bambu-green/15 text-bambu-green`:`text-bambu-gray hover:text-white`}`,children:l(`users.modal.ldapTab`)})]}),u===`ldap`&&s?(0,G.jsx)(l6,{onSuccess:e=>{c?.(e)}}):(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:[l(`users.form.username`),` `,(0,G.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:`*`})]}),(0,G.jsx)(`input`,{type:`text`,value:e.username,onChange:n=>t({...e,username:n.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:l(`users.form.usernamePlaceholder`),autoComplete:`username`,required:!0})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:[l(`users.form.email`)||`Email`,` `,(0,G.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:`*`})]}),(0,G.jsx)(`input`,{type:`email`,value:e.email,onChange:n=>t({...e,email:n.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:l(`users.form.emailPlaceholder`)||`user@example.com`,required:!0})]}),(0,G.jsx)(`div`,{className:`bg-bambu-dark-secondary/50 border border-bambu-green/20 rounded-lg p-3`,children:(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:l(`users.form.autoGeneratedPassword`)||`A secure password will be automatically generated and emailed to the user.`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:l(`users.form.groups`)}),(0,G.jsxs)(`div`,{className:`space-y-2 max-h-40 overflow-y-auto p-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg`,children:[n.map(t=>(0,G.jsxs)(`label`,{className:`flex items-center gap-3 px-2 py-1.5 rounded hover:bg-bambu-dark-tertiary cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:e.group_ids.includes(t.id),onChange:()=>f(t.id),className:`w-4 h-4 rounded border-bambu-gray text-bambu-green focus:ring-bambu-green focus:ring-offset-0 bg-bambu-dark`}),(0,G.jsx)(`span`,{className:`text-sm text-white`,children:t.name}),t.is_system&&(0,G.jsxs)(`span`,{className:`text-xs text-yellow-700 dark:text-yellow-400`,children:[`(`,l(`users.system`),`)`]})]},t.id)),n.length===0&&(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:l(`users.noGroupsAvailable`)})]})]})]}),(0,G.jsxs)(`div`,{className:`mt-6 flex justify-end gap-3`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:r,children:l(`users.modal.cancel`)}),u===`local`&&(0,G.jsx)(Q,{onClick:i,disabled:o,children:a?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),l(`users.modal.creating`)]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Ml,{className:`w-4 h-4`}),l(`users.modal.createUser`)]})})]})]})]})})}function nHe(){let{t:e}=U(),t=so(),{showToast:n}=Bd(),[r,i]=(0,y.useState)(!1),[a,o]=(0,y.useState)(``),[s,c]=(0,y.useState)(`auto`),[l,u]=(0,y.useState)(!1),[d,f]=(0,y.useState)(!0),[p,m]=(0,y.useState)(!0),[h,g]=(0,y.useState)(`all`),[_,v]=(0,y.useState)(!1),[b,x]=(0,y.useState)(!1),[S,C]=(0,y.useState)(!1),[w,T]=(0,y.useState)(!1),{data:E,isLoading:D}=K({queryKey:[`spoolman-settings`],queryFn:Z.getSpoolmanSettings}),{data:O,isLoading:k,refetch:A}=K({queryKey:[`spoolman-status`],queryFn:Z.getSpoolmanStatus,refetchInterval:3e4}),{data:j}=K({queryKey:[`printers`],queryFn:Z.getPrinters});(0,y.useEffect)(()=>{E&&(i(E.spoolman_enabled===`true`),o(E.spoolman_url||``),c(E.spoolman_sync_mode||`auto`),u(E.spoolman_disable_weight_sync===`true`),f(E.spoolman_report_partial_usage!==`false`),m(E.auto_add_unknown_rfid!==`false`),v(!0))},[E]),(0,y.useEffect)(()=>{if(!(!_||!E)&&(E.spoolman_enabled===`true`!==r||(E.spoolman_url||``)!==a||(E.spoolman_sync_mode||`auto`)!==s||E.spoolman_disable_weight_sync===`true`!==l||E.spoolman_report_partial_usage!==`false`!==d||E.auto_add_unknown_rfid!==`false`!==p)){let e=setTimeout(()=>{M.mutate()},500);return()=>clearTimeout(e)}},[r,a,s,l,d,p,_]);let M=q({mutationFn:()=>Z.updateSpoolmanSettings({spoolman_enabled:r?`true`:`false`,spoolman_url:a,spoolman_sync_mode:s,spoolman_disable_weight_sync:l?`true`:`false`,spoolman_report_partial_usage:d?`true`:`false`,auto_add_unknown_rfid:p?`true`:`false`}),onSuccess:()=>{t.invalidateQueries({queryKey:[`spoolman-settings`]}),t.invalidateQueries({queryKey:[`spoolman-status`]}),t.invalidateQueries({queryKey:[`spool-assignments`]}),t.invalidateQueries({queryKey:[`settings`]}),t.invalidateQueries({queryKey:[`spoolman-inventory-filaments`]}),n(e(`settings.toast.settingsSaved`))},onError:()=>{n(e(`settings.toast.saveFailed`),`error`)}}),N=q({mutationFn:Z.connectSpoolman,onSuccess:()=>{A()},onError:()=>{n(e(`settings.toast.saveFailed`),`error`)}}),P=q({mutationFn:Z.disconnectSpoolman,onSuccess:()=>{A()},onError:()=>{n(e(`settings.toast.saveFailed`),`error`)}}),F=q({mutationFn:Z.syncAllPrintersAms,onSuccess:t=>{n(e(`settings.spoolmanAmsSyncSuccess`,{synced:t.synced_count,skipped:0}),`success`)},onError:()=>{n(e(`settings.toast.saveFailed`),`error`)}}),I=q({mutationFn:e=>Z.syncPrinterAms(e),onSuccess:t=>{n(e(`settings.spoolmanAmsSyncSuccess`,{synced:t.synced_count,skipped:0}),`success`)},onError:()=>{n(e(`settings.toast.saveFailed`),`error`)}}),L=()=>{h===`all`?F.mutate():I.mutate(h)},R=q({mutationFn:Z.syncWeightsFromAms,onSuccess:r=>{t.invalidateQueries({queryKey:[`spools`]}),t.invalidateQueries({queryKey:[`inventory-spools`]}),n(e(`settings.amsSyncSuccess`,{synced:r.synced,skipped:r.skipped}),`success`),C(!1)},onError:()=>{n(e(`settings.amsSyncError`),`error`),C(!1)}}),z=q({mutationFn:Z.syncSpoolmanAmsWeights,onSuccess:r=>{t.invalidateQueries({queryKey:[`spoolman-inventory-spools`]}),n(e(`settings.spoolmanAmsSyncSuccess`,{synced:r.synced,skipped:r.skipped}),`success`),T(!1)},onError:t=>{t instanceof id&&t.status===503?n(e(`settings.spoolmanAmsSyncErrorUnreachable`),`error`):t instanceof id&&t.status===400?n(e(`settings.spoolmanAmsSyncErrorNotConfigured`),`error`):n(e(`settings.spoolmanAmsSyncError`),`error`),T(!1)}}),B=F.isPending||I.isPending,V=h===`all`?F.data:I.data,ee=h===`all`?F.isSuccess:I.isSuccess;return D?(0,G.jsxs)(Md,{id:`card-spoolman`,children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Us,{className:`w-5 h-5 text-bambu-green`}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`settings.filamentTracking`)})]})}),(0,G.jsx)(Pd,{children:(0,G.jsx)(`div`,{className:`flex justify-center py-8`,children:(0,G.jsx)(Y,{className:`w-6 h-6 text-bambu-green animate-spin`})})})]}):(0,G.jsxs)(Md,{id:`card-spoolman`,children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Us,{className:`w-5 h-5 text-bambu-green`}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`settings.filamentTracking`)})]}),M.isPending&&(0,G.jsx)(Y,{className:`w-4 h-4 text-bambu-green animate-spin`})]})}),(0,G.jsxs)(Pd,{className:`space-y-4`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`settings.filamentTrackingDesc`)}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,G.jsxs)(`button`,{type:`button`,onClick:()=>i(!1),className:`p-3 rounded-lg border-2 text-left transition-colors ${r?`border-bambu-dark-tertiary bg-bambu-dark hover:border-bambu-gray/50`:`border-bambu-green bg-bambu-green/10`}`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-1.5`,children:[(0,G.jsx)(xl,{className:`w-4 h-4 ${r?`text-bambu-gray`:`text-bambu-green`}`}),(0,G.jsx)(`span`,{className:`text-sm font-medium ${r?`text-bambu-gray`:`text-white`}`,children:e(`settings.trackingModeBuiltIn`)})]}),(0,G.jsx)(`p`,{className:`text-xs ${r?`text-bambu-gray/60`:`text-bambu-gray`}`,children:e(`settings.trackingModeBuiltInDesc`)}),!r&&(0,G.jsxs)(`div`,{className:`flex items-center gap-1 mt-2`,children:[(0,G.jsx)(us,{className:`w-3 h-3 text-bambu-green`}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-green`,children:e(`common.enabled`)})]})]}),(0,G.jsxs)(`button`,{type:`button`,onClick:()=>i(!0),className:`p-3 rounded-lg border-2 text-left transition-colors ${r?`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary bg-bambu-dark hover:border-bambu-gray/50`}`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-1.5`,children:[(0,G.jsx)(tc,{className:`w-4 h-4 ${r?`text-bambu-green`:`text-bambu-gray`}`}),(0,G.jsx)(`span`,{className:`text-sm font-medium ${r?`text-white`:`text-bambu-gray`}`,children:`Spoolman`})]}),(0,G.jsx)(`p`,{className:`text-xs ${r?`text-bambu-gray`:`text-bambu-gray/60`}`,children:e(`settings.trackingModeSpoolmanDesc`)}),r&&(0,G.jsxs)(`div`,{className:`flex items-center gap-1 mt-2`,children:[(0,G.jsx)(us,{className:`w-3 h-3 text-bambu-green`}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-green`,children:e(`common.enabled`)})]})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between pt-2 border-t border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`pr-4`,children:[(0,G.jsx)(`p`,{className:`text-white`,children:e(`settings.autoAddUnknownRfid`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`settings.autoAddUnknownRfidDesc`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:p,onChange:e=>m(e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),!r&&(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsx)(`div`,{className:`p-3 bg-bambu-green/5 border border-bambu-green/20 rounded-lg`,children:(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsx)(Vc,{className:`w-4 h-4 text-bambu-green flex-shrink-0 mt-0.5`}),(0,G.jsx)(`div`,{className:`text-xs text-bambu-gray`,children:(0,G.jsxs)(`ul`,{className:`list-disc list-inside space-y-0.5`,children:[(0,G.jsx)(`li`,{children:e(`settings.builtInFeatureRfid`)}),(0,G.jsx)(`li`,{children:e(`settings.builtInFeatureUsage`)}),(0,G.jsx)(`li`,{children:e(`settings.builtInFeatureCatalog`)}),(0,G.jsx)(`li`,{children:e(`settings.builtInFeatureThirdParty`)})]})})]})}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:()=>C(!0),disabled:R.isPending,children:[R.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 mr-2 animate-spin`}):(0,G.jsx)(zl,{className:`w-4 h-4 mr-2`}),e(`settings.amsSyncButton`)]})]}),r&&(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsx)(`div`,{className:`p-3 bg-blue-50 dark:bg-blue-500/10 border border-blue-300 dark:border-blue-500/30 rounded-lg`,children:(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsx)(Vc,{className:`w-4 h-4 text-blue-600 dark:text-blue-400 flex-shrink-0 mt-0.5`}),(0,G.jsxs)(`div`,{className:`text-xs text-blue-700 dark:text-blue-300`,children:[(0,G.jsx)(`p`,{className:`font-medium mb-1`,children:e(`settings.howSyncWorks`)}),(0,G.jsxs)(`ul`,{className:`list-disc list-inside space-y-0.5 text-blue-700/90 dark:text-blue-300/80`,children:[(0,G.jsx)(`li`,{children:e(`settings.syncInfoRfidOnly`)}),(0,G.jsx)(`li`,{children:e(`settings.syncInfoAutoCreate`)}),(0,G.jsx)(`li`,{children:e(`settings.syncInfoThirdPartySkipped`)})]}),(0,G.jsx)(`p`,{className:`font-medium mt-2 mb-1`,children:e(`settings.linkingExistingSpools`)}),(0,G.jsx)(`p`,{className:`text-blue-700/90 dark:text-blue-300/80`,children:e(`settings.linkingExistingSpoolsDesc`)})]})]})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:e(`settings.spoolmanUrl`)}),(0,G.jsx)(`input`,{type:`text`,placeholder:`http://192.168.1.100:7912`,value:a,onChange:e=>o(e.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`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`settings.spoolmanUrlHint`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:e(`settings.syncMode`)}),(0,G.jsxs)(`select`,{value:s,onChange:e=>c(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,G.jsx)(`option`,{value:`auto`,children:e(`settings.syncModeAuto`)}),(0,G.jsx)(`option`,{value:`manual`,children:e(`settings.syncModeManual`)})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(s===`auto`?`settings.syncModeAutoDesc`:`settings.syncModeManualDesc`)})]}),s===`auto`&&(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:e(`spoolman.disableWeightSync`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`spoolman.disableWeightSyncDesc`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:l,onChange:e=>u(e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),l&&(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:e(`spoolman.reportPartialUsage`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`spoolman.reportPartialUsageDesc`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:d,onChange:e=>f(e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,G.jsxs)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[e(`settings.status`),`:`]}),k?(0,G.jsx)(Y,{className:`w-4 h-4 text-bambu-gray animate-spin`}):O?.connected?(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-sm text-green-500`,children:[(0,G.jsx)(us,{className:`w-4 h-4`}),e(`settings.spoolmanConnected`)]}):(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-sm text-red-500`,children:[(0,G.jsx)($u,{className:`w-4 h-4`}),e(`settings.spoolmanDisconnected`)]})]}),(0,G.jsx)(`div`,{className:`flex gap-2`,children:O?.connected?(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:()=>P.mutate(),disabled:P.isPending,children:[P.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(qc,{className:`w-4 h-4`}),e(`settings.disconnect`)]}):(0,G.jsxs)(Q,{size:`sm`,onClick:()=>N.mutate(),disabled:N.isPending||!a,children:[N.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Jc,{className:`w-4 h-4`}),e(`settings.connect`)]})})]}),(N.isError||P.isError)&&(0,G.jsx)(`div`,{className:`mb-3 p-2 bg-red-100 dark:bg-red-500/20 border border-red-300 dark:border-red-500/50 rounded text-sm text-red-700 dark:text-red-400`,children:(N.error||P.error).message}),O?.connected&&(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:e(`settings.syncAmsData`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:e(`settings.syncAmsDataDesc`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`div`,{className:`relative flex-1`,children:[(0,G.jsxs)(`select`,{value:h,onChange:e=>g(e.target.value===`all`?`all`:Number(e.target.value)),className:`w-full px-3 py-2 pr-8 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none appearance-none cursor-pointer`,children:[(0,G.jsx)(`option`,{value:`all`,children:e(`settings.allPrinters`)}),j?.map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),(0,G.jsx)(ds,{className:`absolute right-2 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:L,disabled:B,children:[B?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(zl,{className:`w-4 h-4`}),e(`spoolman.sync`)]})]})]}),O?.connected&&(0,G.jsx)(`div`,{className:`mt-4 pt-4 border-t border-bambu-dark-tertiary`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:e(`settings.spoolmanAmsSyncButton`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:e(`settings.spoolmanAmsSyncMessage`)})]}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:()=>T(!0),disabled:z.isPending,children:[z.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(zl,{className:`w-4 h-4`}),z.isPending?e(`settings.spoolmanAmsSyncing`):e(`settings.spoolmanAmsSyncButton`)]})]})}),ee&&V&&(0,G.jsxs)(`div`,{className:`mt-3 space-y-2`,children:[(0,G.jsx)(`div`,{className:`p-2 rounded text-sm ${V.success?`bg-green-100 dark:bg-green-500/20 border border-green-300 dark:border-green-500/50 text-green-700 dark:text-green-400`:`bg-yellow-100 dark:bg-yellow-500/20 border border-yellow-300 dark:border-yellow-500/50 text-yellow-700 dark:text-yellow-400`}`,children:V.success?`Synced ${V.synced_count} spool${V.synced_count===1?``:`s`} successfully`:`Synced ${V.synced_count} spool${V.synced_count===1?``:`s`} with ${V.errors.length} error${V.errors.length===1?``:`s`}`}),V.skipped_count>0&&(0,G.jsxs)(`div`,{className:`p-2 bg-amber-50 dark:bg-amber-500/10 border border-amber-300 dark:border-amber-500/30 rounded text-sm`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between text-amber-700 dark:text-amber-400 mb-1`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,G.jsx)(Pu,{className:`w-3.5 h-3.5`}),(0,G.jsxs)(`span`,{className:`font-medium`,children:[V.skipped_count,` spool`,V.skipped_count===1?``:`s`,` skipped`]})]}),V.skipped_count>5&&(0,G.jsx)(`button`,{onClick:()=>x(!b),className:`text-xs text-amber-700 dark:text-amber-400 hover:text-amber-800 dark:hover:text-amber-300 underline`,children:b?`Show less`:`Show all`})]}),(0,G.jsxs)(`ul`,{className:`text-xs text-amber-700/90 dark:text-amber-300/80 space-y-0.5`,children:[(b?V.skipped:V.skipped.slice(0,5)).map((e,t)=>(0,G.jsxs)(`li`,{className:`flex items-center gap-2`,children:[e.color&&(0,G.jsx)(`span`,{className:`w-3 h-3 rounded-full border border-black/20`,style:{backgroundColor:`#${e.color}`}}),(0,G.jsx)(`span`,{children:e.location}),(0,G.jsxs)(`span`,{className:`text-amber-700/70 dark:text-amber-300/60`,children:[`- `,e.reason]})]},t)),!b&&V.skipped_count>5&&(0,G.jsxs)(`li`,{className:`text-amber-700/70 dark:text-amber-300/60 italic`,children:[`...and `,V.skipped_count-5,` more`]})]})]}),V.errors.length>0&&(0,G.jsxs)(`div`,{className:`p-2 bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30 rounded text-sm`,children:[(0,G.jsx)(`div`,{className:`text-red-700 dark:text-red-400 font-medium mb-1`,children:`Errors:`}),(0,G.jsx)(`ul`,{className:`text-xs text-red-700/90 dark:text-red-300/80 space-y-0.5`,children:V.errors.map((e,t)=>(0,G.jsx)(`li`,{children:e},t))})]})]})]})]})]}),S&&(0,G.jsx)(Zd,{title:e(`settings.amsSyncTitle`),message:e(`settings.amsSyncMessage`),confirmText:e(`settings.amsSyncButton`),variant:`warning`,isLoading:R.isPending,loadingText:e(`settings.amsSyncing`),onConfirm:()=>R.mutate(),onCancel:()=>C(!1)}),w&&(0,G.jsx)(Zd,{title:e(`settings.spoolmanAmsSyncTitle`),message:e(`settings.spoolmanAmsSyncMessage`),confirmText:e(`settings.spoolmanAmsSyncButton`),variant:`warning`,isLoading:z.isPending,loadingText:e(`settings.spoolmanAmsSyncing`),onConfirm:()=>z.mutate(),onCancel:()=>T(!1)})]})}function rHe(){let{t:e}=U(),{showToast:t}=Bd(),[n,r]=(0,y.useState)([]),[i,a]=(0,y.useState)(!0),[o,s]=(0,y.useState)(``),c=(0,y.useRef)(null),[l,u]=(0,y.useState)(!1),[d,f]=(0,y.useState)(null),[p,m]=(0,y.useState)(``),[h,g]=(0,y.useState)(``),[_,v]=(0,y.useState)(!1),[b,x]=(0,y.useState)(new Set),[S,C]=(0,y.useState)(!1),[w,T]=(0,y.useState)(null),[E,D]=(0,y.useState)(!1),O=(0,y.useCallback)(async()=>{try{r(await Z.getSpoolCatalog())}catch(n){console.error(`SpoolCatalogSettings.loadCatalog failed:`,n),t(e(`settings.catalog.loadFailed`),`error`)}finally{a(!1)}},[t,e]);(0,y.useEffect)(()=>{O()},[O]);let k=n.filter(e=>e.name.toLowerCase().includes(o.toLowerCase())),A=async()=>{if(!p.trim()||!h){t(e(`settings.catalog.nameWeightRequired`),`error`);return}v(!0);try{let n=await Z.addCatalogEntry({name:p.trim(),weight:parseInt(h)});r(e=>[...e,n].sort((e,t)=>e.name.localeCompare(t.name))),u(!1),m(``),g(``),t(e(`settings.catalog.entryAdded`),`success`)}catch(n){console.error(`SpoolCatalogSettings.handleAdd failed:`,n),t(e(`settings.catalog.addFailed`),`error`)}finally{v(!1)}},j=e=>{f(e.id),m(e.name),g(e.weight.toString())},M=()=>{f(null),m(``),g(``)},N=async n=>{if(!p.trim()||!h){t(e(`settings.catalog.nameWeightRequired`),`error`);return}v(!0);try{let i=await Z.updateCatalogEntry(n,{name:p.trim(),weight:parseInt(h)});r(e=>e.map(e=>e.id===n?i:e).sort((e,t)=>e.name.localeCompare(t.name))),f(null),m(``),g(``),t(e(`settings.catalog.entryUpdated`),`success`)}catch(n){console.error(`SpoolCatalogSettings.handleUpdate failed:`,n),t(e(`settings.catalog.updateFailed`),`error`)}finally{v(!1)}},P=async()=>{if(w)try{await Z.deleteCatalogEntry(w.id),r(e=>e.filter(e=>e.id!==w.id)),t(e(`settings.catalog.entryDeleted`),`success`)}catch(n){console.error(`SpoolCatalogSettings.handleDelete failed:`,n),t(e(`settings.catalog.deleteFailed`),`error`)}finally{T(null)}},F=async()=>{D(!1),a(!0);try{await Z.resetSpoolCatalog(),await O(),t(e(`settings.catalog.resetSuccess`),`success`)}catch(n){console.error(`SpoolCatalogSettings.handleReset failed:`,n),t(e(`settings.catalog.resetFailed`),`error`),a(!1)}},I=e=>{x(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})};return(0,G.jsxs)(Md,{id:`card-spool-catalog`,children:[(0,G.jsxs)(Nd,{children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,G.jsx)(Us,{className:`w-5 h-5 text-bambu-gray`}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`settings.catalog.spoolCatalog`)}),(0,G.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[`(`,n.length,`)`]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,G.jsxs)(`button`,{onClick:()=>{let r=n.map(({name:e,weight:t})=>({name:e,weight:t})),i=new Blob([JSON.stringify(r,null,2)],{type:`application/json`}),a=URL.createObjectURL(i),o=document.createElement(`a`);o.href=a,o.download=`spool-catalog.json`,document.body.appendChild(o),o.click(),document.body.removeChild(o),URL.revokeObjectURL(a),t(e(`settings.catalog.exported`,{count:n.length}),`success`)},className:`px-3 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray hover:text-white transition-colors flex items-center gap-1.5`,title:e(`settings.catalog.exportTooltip`),children:[(0,G.jsx)(Js,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.export`)})]}),(0,G.jsxs)(`button`,{onClick:()=>c.current?.click(),className:`px-3 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray hover:text-white transition-colors flex items-center gap-1.5`,title:e(`settings.catalog.importTooltip`),children:[(0,G.jsx)(Ru,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.import`)})]}),(0,G.jsx)(`input`,{ref:c,type:`file`,accept:`.json`,className:`hidden`,onChange:async i=>{let a=i.target.files?.[0];if(a){try{let i=await a.text(),o=JSON.parse(i);if(!Array.isArray(o))throw Error(`Invalid format`);let s=0,c=0;for(let e of o){if(!e.name||typeof e.weight!=`number`){c++;continue}if(n.some(t=>t.name.toLowerCase()===e.name.toLowerCase())){c++;continue}try{let t=await Z.addCatalogEntry({name:e.name,weight:e.weight});r(e=>[...e,t].sort((e,t)=>e.name.localeCompare(t.name))),s++}catch(e){console.error(`SpoolCatalogSettings import item failed:`,e),c++}}t(e(`settings.catalog.imported`,{added:s,skipped:c}),`success`)}catch(n){console.error(`SpoolCatalogSettings.handleImport failed:`,n),t(e(`settings.catalog.importFailed`),`error`)}c.current&&(c.current.value=``)}}}),(0,G.jsxs)(`button`,{onClick:()=>D(!0),className:`px-3 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray hover:text-white transition-colors flex items-center gap-1.5`,title:e(`settings.catalog.resetTooltip`),children:[(0,G.jsx)(Vl,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.reset`)})]}),(0,G.jsxs)(`button`,{onClick:()=>u(!0),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,G.jsx)(Ml,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.add`)})]})]}),b.size>0&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mt-2 px-3 py-2 bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30 rounded-lg`,children:[(0,G.jsx)(`span`,{className:`text-sm text-red-700 dark:text-red-400`,children:e(`settings.catalog.selectedCount`,{count:b.size})}),(0,G.jsxs)(`button`,{onClick:()=>C(!0),className:`ml-auto px-3 py-1.5 text-sm bg-red-500 text-white rounded-lg hover:bg-red-600 transition-colors flex items-center gap-1.5`,children:[(0,G.jsx)(ju,{className:`w-4 h-4`}),e(`settings.catalog.deleteSelected`)]}),(0,G.jsx)(`button`,{onClick:()=>x(new Set),className:`px-3 py-1.5 text-sm text-bambu-gray hover:text-white transition-colors`,children:e(`common.cancel`)})]})]}),(0,G.jsxs)(Pd,{className:`space-y-4`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`settings.catalog.spoolCatalogDescription`)}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(Yl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,G.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:e(`settings.catalog.searchCatalog`),value:o,onChange:e=>s(e.target.value)})]}),l&&(0,G.jsxs)(`div`,{className:`p-4 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,G.jsx)(`h3`,{className:`text-sm font-medium text-white mb-3`,children:e(`settings.catalog.addNewEntry`)}),(0,G.jsxs)(`div`,{className:`flex gap-2 items-center`,children:[(0,G.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,G.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:e(`settings.catalog.namePlaceholder`),value:p,onChange:e=>m(e.target.value)})}),(0,G.jsx)(`input`,{type:`number`,className:`w-20 px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white text-center focus:border-bambu-green focus:outline-none`,placeholder:`g`,value:h,onChange:e=>g(e.target.value)}),(0,G.jsx)(`span`,{className:`text-bambu-gray shrink-0`,children:`g`}),(0,G.jsxs)(`button`,{onClick:A,disabled:_,className:`px-3 py-2 bg-bambu-green text-white rounded-lg hover:bg-bambu-green/80 flex items-center gap-1 shrink-0`,children:[_?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(us,{className:`w-4 h-4`}),e(`common.add`)]}),(0,G.jsx)(`button`,{onClick:()=>{u(!1),m(``),g(``)},className:`p-2 rounded-lg text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary`,children:(0,G.jsx)($u,{className:`w-4 h-4`})})]})]}),i?(0,G.jsxs)(`div`,{className:`flex items-center justify-center py-8 text-bambu-gray`,children:[(0,G.jsx)(Y,{className:`w-5 h-5 animate-spin mr-2`}),e(`common.loading`)]}):(0,G.jsx)(`div`,{className:`max-h-[600px] overflow-y-auto border border-bambu-dark-tertiary rounded-lg`,children:(0,G.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,G.jsx)(`thead`,{className:`bg-bambu-dark sticky top-0`,children:(0,G.jsxs)(`tr`,{children:[(0,G.jsx)(`th`,{className:`px-2 py-2 w-10`,children:(0,G.jsx)(`input`,{type:`checkbox`,checked:k.length>0&&b.size===k.length,onChange:()=>{b.size===k.length?x(new Set):x(new Set(k.map(e=>e.id)))},className:`w-4 h-4 accent-bambu-green cursor-pointer`})}),(0,G.jsx)(`th`,{className:`px-4 py-2 text-left text-bambu-gray font-medium`,children:e(`common.name`)}),(0,G.jsx)(`th`,{className:`px-4 py-2 text-right text-bambu-gray font-medium w-24`,children:e(`settings.catalog.weight`)}),(0,G.jsx)(`th`,{className:`px-4 py-2 text-center text-bambu-gray font-medium w-20`,children:e(`settings.catalog.type`)}),(0,G.jsx)(`th`,{className:`px-4 py-2 w-24`})]})}),(0,G.jsx)(`tbody`,{children:k.length===0?(0,G.jsx)(`tr`,{children:(0,G.jsx)(`td`,{colSpan:5,className:`px-4 py-8 text-center text-bambu-gray`,children:e(o?`settings.catalog.noMatch`:`settings.catalog.empty`)})}):k.map(t=>(0,G.jsx)(`tr`,{className:`border-t border-bambu-dark-tertiary hover:bg-bambu-dark ${b.has(t.id)?`bg-bambu-dark`:``}`,children:d===t.id?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`td`,{className:`px-2 py-2`,children:(0,G.jsx)(`input`,{type:`checkbox`,checked:b.has(t.id),onChange:()=>I(t.id),className:`w-4 h-4 accent-bambu-green cursor-pointer`})}),(0,G.jsx)(`td`,{className:`px-4 py-2`,children:(0,G.jsx)(`input`,{type:`text`,className:`w-full px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white focus:border-bambu-green focus:outline-none`,value:p,onChange:e=>m(e.target.value)})}),(0,G.jsx)(`td`,{className:`px-4 py-2`,children:(0,G.jsx)(`input`,{type:`number`,className:`w-full px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-right focus:border-bambu-green focus:outline-none`,value:h,onChange:e=>g(e.target.value)})}),(0,G.jsx)(`td`,{className:`px-4 py-2 text-center`,children:(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:`-`})}),(0,G.jsx)(`td`,{className:`px-4 py-2`,children:(0,G.jsxs)(`div`,{className:`flex justify-end gap-1`,children:[(0,G.jsx)(`button`,{onClick:()=>N(t.id),disabled:_,className:`p-1.5 rounded hover:bg-green-500/20 text-green-500`,children:_?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(us,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:M,className:`p-1.5 rounded hover:bg-bambu-dark-tertiary text-bambu-gray`,children:(0,G.jsx)($u,{className:`w-4 h-4`})})]})})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`td`,{className:`px-2 py-2`,children:(0,G.jsx)(`input`,{type:`checkbox`,checked:b.has(t.id),onChange:()=>I(t.id),className:`w-4 h-4 accent-bambu-green cursor-pointer`})}),(0,G.jsx)(`td`,{className:`px-4 py-2 text-white`,children:t.name}),(0,G.jsxs)(`td`,{className:`px-4 py-2 text-right font-mono text-white`,children:[t.weight,`g`]}),(0,G.jsx)(`td`,{className:`px-4 py-2 text-center`,children:t.is_default?(0,G.jsx)(`span`,{className:`text-xs px-2 py-0.5 rounded bg-bambu-dark-tertiary text-bambu-gray`,children:e(`settings.catalog.default`)}):(0,G.jsx)(`span`,{className:`text-xs px-2 py-0.5 rounded bg-bambu-green/20 text-bambu-green`,children:e(`settings.catalog.custom`)})}),(0,G.jsx)(`td`,{className:`px-4 py-2`,children:(0,G.jsxs)(`div`,{className:`flex justify-end gap-1`,children:[(0,G.jsx)(`button`,{onClick:()=>j(t),className:`p-1.5 rounded hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white`,children:(0,G.jsx)(Ol,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:()=>T(t),className:`p-1.5 rounded bg-red-500/10 hover:bg-red-500/20 text-red-500`,children:(0,G.jsx)(ju,{className:`w-4 h-4`})})]})})]})},t.id))})]})})]}),w&&(0,G.jsx)(Zd,{title:e(`settings.catalog.deleteEntry`),message:e(`settings.catalog.deleteConfirm`,{name:w.name}),confirmText:e(`common.delete`),variant:`danger`,onConfirm:P,onCancel:()=>T(null)}),S&&(0,G.jsx)(Zd,{title:e(`settings.catalog.deleteSelected`),message:e(`settings.catalog.bulkDeleteConfirm`,{count:b.size}),confirmText:e(`common.delete`),variant:`danger`,onConfirm:async()=>{if(C(!1),b.size!==0)try{let n=await Z.bulkDeleteCatalogEntries([...b]);r(e=>e.filter(e=>!b.has(e.id))),x(new Set),t(e(`settings.catalog.bulkDeleted`,{count:n.deleted}),`success`)}catch(n){console.error(`SpoolCatalogSettings.handleBulkDelete failed:`,n),t(e(`settings.catalog.bulkDeleteFailed`),`error`)}},onCancel:()=>C(!1)}),E&&(0,G.jsx)(Zd,{title:e(`settings.catalog.resetCatalog`),message:e(`settings.catalog.resetConfirm`),confirmText:e(`common.reset`),variant:`danger`,onConfirm:F,onCancel:()=>D(!1)})]})}var iHe=2166136261,aHe=16777619;function oHe(...e){let t=iHe,n=new TextEncoder,r=n.encode(`__|`);for(let i of e)typeof i==`string`?t=u6(t,n.encode(i+`|`)):i??(t=u6(t,r));return t>>>0}function u6(e,t){for(let n of t)e^=n,e=Math.imul(e,aHe)>>>0;return e}function sHe(e){let t=()=>{e|=0,e=e+1831565813|0;let t=Math.imul(e^e>>>15,1|e);return t=t+Math.imul(t^t>>>7,61|t)^t,(t^t>>>14)>>>0},n=(e,n)=>{if(!Number.isFinite(e)||!Number.isFinite(n))throw RangeError(`from and to must be finite numbers`);if(e>n)throw RangeError(`from must be less than or equal to to`);return e===n?e:e+t()/4294967295*(n-e)};return{next:()=>t()/4294967295,floatBetween:(e,t)=>n(e,t),intBetween:(e,t)=>{if(!Number.isInteger(e)||!Number.isInteger(t))throw RangeError(`from and to must be integers`);return Math.round(n(e,t))}}}var d6={table:{dotCount:5,dotScale:1},preview:{dotCount:8,dotScale:1.5},card:{dotCount:40,dotScale:2},bar:{dotCount:20,dotScale:2},groupheader:{dotCount:80,dotScale:2}},f6=[{value:``,labelKey:`inventory.colorEffect.none`},{value:`sparkle`,labelKey:`inventory.colorEffect.sparkle`},{value:`wood`,labelKey:`inventory.colorEffect.wood`},{value:`marble`,labelKey:`inventory.colorEffect.marble`},{value:`glow`,labelKey:`inventory.colorEffect.glow`},{value:`matte`,labelKey:`inventory.colorEffect.matte`},{value:`silk`,labelKey:`inventory.colorEffect.silk`},{value:`galaxy`,labelKey:`inventory.colorEffect.galaxy`},{value:`rainbow`,labelKey:`inventory.colorEffect.rainbow`},{value:`metal`,labelKey:`inventory.colorEffect.metal`},{value:`translucent`,labelKey:`inventory.colorEffect.translucent`},{value:`gradient`,labelKey:`inventory.colorEffect.gradient`},{value:`dual-color`,labelKey:`inventory.colorEffect.dualColor`},{value:`tri-color`,labelKey:`inventory.colorEffect.triColor`},{value:`multicolor`,labelKey:`inventory.colorEffect.multicolor`}],cHe=`repeating-conic-gradient(#979797 0% 25%, #f5f5f5 0% 50%)`,lHe=`12px 12px`,uHe={sparkle:(e=0,t=`table`)=>{let n=sHe(e),r=d6[t]??d6.table,i=[];for(let e=0;e`repeating-linear-gradient(90deg, rgba(0,0,0,0.18) 0 1px, transparent 1px 6px, rgba(0,0,0,0.08) 6px 7px, transparent 7px 12px)`,marble:()=>`repeating-linear-gradient(135deg, rgba(255,255,255,0.18) 0 2px, transparent 2px 8px), repeating-linear-gradient(45deg, rgba(0,0,0,0.10) 0 1px, transparent 1px 7px)`,glow:()=>`radial-gradient(circle at 50% 50%, rgba(255,255,255,0.35) 0%, rgba(255,255,255,0) 70%)`,matte:()=>`linear-gradient(180deg, rgba(0,0,0,0.10) 0%, rgba(0,0,0,0) 50%, rgba(0,0,0,0.10) 100%)`,silk:()=>`linear-gradient(110deg, rgba(255,255,255,0) 30%, rgba(255,255,255,0.30) 50%, rgba(255,255,255,0) 70%)`,galaxy:()=>`linear-gradient(110deg, rgba(255,255,255,0) 25%, rgba(255,255,255,0.40) 50%, rgba(255,255,255,0) 75%)`,metal:()=>`repeating-linear-gradient(90deg, rgba(255,255,255,0.10) 0 1px, transparent 1px 3px), linear-gradient(180deg, rgba(255,255,255,0.18) 0%, rgba(0,0,0,0.18) 100%)`};function p6(e){let t=e.trim().replace(/^#/,``);return t.length!==6&&t.length!==8||!/^[0-9a-fA-F]+$/.test(t)?null:`#${t}`}function m6(e){return e?e.split(`,`).map(e=>p6(e)).filter(e=>!!e):[]}function dHe(e,t,n,r){let i=e?p6(e):null;if(t.length===0)return`linear-gradient(${i??`#808080`}, ${i??`#808080`})`;let a=t.length===1?[t[0],t[0]]:t,o=(n??``).toLowerCase(),s=(r??``).toLowerCase();if(o===`multicolor`||s===`multicolor`){let e=a.length;return`conic-gradient(from 0deg, ${a.map((t,n)=>`${t} ${(n/e*360).toFixed(3)}deg ${((n+1)/e*360).toFixed(3)}deg`).join(`, `)})`}if(s===`dual-color`||s===`tri-color`){let e=a.length;return`linear-gradient(to right, ${a.map((t,n)=>`${t} ${(n/e*100).toFixed(3)}% ${((n+1)/e*100).toFixed(3)}%`).join(`, `)})`}return`linear-gradient(135deg, ${a.join(`, `)})`}function fHe(e,t,n){let r=uHe[e];return r?r(n,t):null}function h6(e){let t=m6(e.extraColors),n=dHe(e.rgba,t,e.subtype,e.effectType),r=oHe(e.rgba,e.extraColors,e.subtype,e.effectType),i=typeof e.effectType==`string`?fHe(e.effectType,e.effectSize,r):null,a=[];return i&&(Array.isArray(i)?i:[i]).forEach(e=>{a.push({image:e,size:`cover`})}),a.push({image:n,size:`cover`}),a.push({image:cHe,size:lHe}),{backgroundImage:a.map(e=>e.image).join(`, `),backgroundSize:a.map(e=>e.size).join(`, `)}}function g6({rgba:e,extraColors:t,effectType:n,subtype:r,className:i=`w-5 h-5`,shape:a=`circle`,style:o,title:s,effectSize:c}){let l=(0,y.useMemo)(()=>m6(t),[t]),u=(0,y.useMemo)(()=>h6({effectSize:c,rgba:e,extraColors:t,effectType:n,subtype:r}),[c,e,t,n,r]),d=u.backgroundImage,f=u.backgroundSize,p=a===`circle`||a===`pill`?`rounded-full`:`rounded`,m=(()=>{if(!e)return;let t=e.replace(/^#/,``);return t.length>=8&&t.substring(6,8).toLowerCase()!==`ff`?`#${t.substring(0,8)}`:`#${t.substring(0,6)}`})(),h=s??(l.length>0?l.join(`, `):m);return(0,G.jsx)(`span`,{"data-testid":`filament-swatch`,className:`${i} ${p} border border-black/20 inline-block flex-shrink-0`,style:{backgroundImage:d,backgroundSize:f,...o},title:h})}function pHe(){let{t:e}=U(),{showToast:t}=Bd(),[n,r]=(0,y.useState)([]),[i,a]=(0,y.useState)(!0),[o,s]=(0,y.useState)(``),[c,l]=(0,y.useState)(``),u=(0,y.useRef)(null),[d,f]=(0,y.useState)(!1),[p,m]=(0,y.useState)(null),[h,g]=(0,y.useState)(``),[_,v]=(0,y.useState)(``),[b,x]=(0,y.useState)(`#FFFFFF`),[S,C]=(0,y.useState)(``),[w,T]=(0,y.useState)(``),[E,D]=(0,y.useState)(``),[O,k]=(0,y.useState)(!1),[A,j]=(0,y.useState)(new Set),[M,N]=(0,y.useState)(!1),[P,F]=(0,y.useState)(!1),[I,L]=(0,y.useState)(null),[R,z]=(0,y.useState)(null),[B,V]=(0,y.useState)(!1),ee=(0,y.useCallback)(async()=>{try{r(await Z.getColorCatalog())}catch{t(e(`settings.colorCatalog.loadFailed`),`error`)}finally{a(!1)}},[t,e]);(0,y.useEffect)(()=>{ee()},[ee]);let te=[...new Set(n.map(e=>e.manufacturer))].sort(),ne=n.filter(e=>{let t=o===``||e.manufacturer.toLowerCase().includes(o.toLowerCase())||e.color_name.toLowerCase().includes(o.toLowerCase())||(e.material?.toLowerCase().includes(o.toLowerCase())??!1),n=c===``||e.manufacturer===c;return t&&n}),re=()=>{g(``),v(``),x(`#FFFFFF`),C(``),T(``),D(``)},ie=async()=>{if(!h.trim()||!_.trim()||!b){t(e(`settings.colorCatalog.fieldsRequired`),`error`);return}k(!0);try{let n=await Z.addColorEntry({manufacturer:h.trim(),color_name:_.trim(),hex_color:b,material:S.trim()||null,extra_colors:w.trim()||null,effect_type:E.trim()||null});r(e=>[...e,n].sort((e,t)=>e.manufacturer.localeCompare(t.manufacturer)||(e.material||``).localeCompare(t.material||``)||e.color_name.localeCompare(t.color_name))),f(!1),re(),t(e(`settings.colorCatalog.colorAdded`),`success`)}catch{t(e(`settings.colorCatalog.addFailed`),`error`)}finally{k(!1)}},ae=e=>{m(e.id),g(e.manufacturer),v(e.color_name),x(e.hex_color),C(e.material||``),T(e.extra_colors||``),D(e.effect_type||``)},oe=()=>{m(null),re()},se=async n=>{if(!h.trim()||!_.trim()||!b){t(e(`settings.colorCatalog.fieldsRequired`),`error`);return}k(!0);try{let i=await Z.updateColorEntry(n,{manufacturer:h.trim(),color_name:_.trim(),hex_color:b,material:S.trim()||null,extra_colors:w.trim()||null,effect_type:E.trim()||null});r(e=>e.map(e=>e.id===n?i:e).sort((e,t)=>e.manufacturer.localeCompare(t.manufacturer)||(e.material||``).localeCompare(t.material||``)||e.color_name.localeCompare(t.color_name))),m(null),re(),t(e(`settings.colorCatalog.colorUpdated`),`success`)}catch{t(e(`settings.colorCatalog.updateFailed`),`error`)}finally{k(!1)}},H=async()=>{if(R)try{await Z.deleteColorEntry(R.id),r(e=>e.filter(e=>e.id!==R.id)),t(e(`settings.colorCatalog.colorDeleted`),`success`)}catch{t(e(`settings.colorCatalog.deleteFailed`),`error`)}finally{z(null)}},ce=async()=>{V(!1),a(!0);try{await Z.resetColorCatalog(),await ee(),t(e(`settings.colorCatalog.resetSuccess`),`success`)}catch{t(e(`settings.colorCatalog.resetFailed`),`error`),a(!1)}},le=async()=>{F(!0),L(null);try{let n={},r=sd();r&&(n.Authorization=`Bearer ${r}`);let i=await fetch(`/api/v1/inventory/colors/sync`,{method:`POST`,headers:n});if(!i.ok)throw Error(`Failed to start sync`);let a=i.body?.getReader();if(!a)throw Error(`No response body`);let o=new TextDecoder,s=``;for(;;){let{done:n,value:r}=await a.read();if(n)break;s+=o.decode(r,{stream:!0});let i=s.split(`
+`),confirmText:e(`queue.filamentShort.printAnyway`),variant:`warning`,onConfirm:()=>{be.mutate({id:ve.itemId,skipFilamentCheck:!0})},onCancel:()=>ye(null)}),v&&(0,G.jsx)(Zd,{title:v.type===`cancel`?e(`queue.confirm.cancelTitle`):v.type===`stop`?e(`queue.confirm.stopTitle`):e(`queue.confirm.removeTitle`),message:v.type===`cancel`?e(`queue.confirm.cancelMessage`,{name:v.item.archive_name||v.item.library_file_name||e(`queue.confirm.thisPrint`)}):v.type===`stop`?e(`queue.confirm.stopMessage`,{name:v.item.archive_name||v.item.library_file_name||e(`queue.confirm.thisPrint`)}):e(`queue.confirm.removeMessage`,{name:v.item.archive_name||v.item.library_file_name||e(`queue.confirm.thisItem`)}),confirmText:v.type===`cancel`?e(`queue.confirm.cancelButton`):v.type===`stop`?e(`queue.confirm.stopButton`):e(`common.remove`),variant:`danger`,onConfirm:()=>{v.type===`cancel`?he.mutate(v.item.id):v.type===`stop`?_e.mutate(v.item.id):ge.mutate(v.item.id),b(null)},onCancel:()=>b(null)}),T&&(0,G.jsx)(Zd,{title:e(`queue.resumeAfterFailure.confirmTitle`),message:e(`queue.resumeAfterFailure.confirmMessage`,{printer:T.printerName,count:T.skippedCount}),confirmText:e(`queue.resumeAfterFailure.button`),variant:`warning`,onConfirm:()=>Te.mutate(T.printerId),onCancel:()=>E(null)}),f&&(0,G.jsx)(Zd,{title:e(`queue.confirm.clearHistoryTitle`),message:e(`queue.confirm.clearHistoryMessage`,{count:He.length}),confirmText:e(`queue.clearHistory`),variant:`danger`,onConfirm:()=>{Se.mutate(),p(!1)},onCancel:()=>p(!1)}),C&&(0,G.jsx)(KBe,{selectedCount:x.length,printers:pe?.map(e=>({id:e.id,name:e.name,nozzle_count:e.nozzle_count}))||[],onSave:e=>{Object.keys(e).length>0&&Ce.mutate({item_ids:x,...e})},onClose:()=>w(!1),isSaving:Ce.isPending,canControlPrinter:r(`printers:control`),t:e}),re&&(0,G.jsx)(XBe,{itemCount:x.length,isSaving:Ee.isPending,defaultName:(()=>{let t=je.find(e=>x.includes(e.id)),n=(t?.archive_name||t?.library_file_name||``).replace(/\.gcode\.3mf$/i,``).replace(/\.3mf$/i,``);return n?`${n}`:e(`queue.batch.defaultName`)})(),onSave:e=>Ee.mutate({name:e,item_ids:x}),onClose:()=>ie(!1),t:e}),ae!==null&&(0,G.jsx)(Zd,{title:e(`queue.batch.ungroupConfirmTitle`),message:e(`queue.batch.ungroupConfirmMessage`),confirmText:e(`queue.batch.ungroup`),variant:`warning`,onConfirm:()=>De.mutate(ae),onCancel:()=>oe(null)})]})}function XBe({itemCount:e,defaultName:t,isSaving:n,onSave:r,onClose:i,t:a}){let[o,s]=(0,y.useState)(t);return(0,G.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-4`,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl p-6 w-full max-w-md`,children:[(0,G.jsxs)(`h3`,{className:`text-lg font-semibold text-white mb-2 flex items-center gap-2`,children:[(0,G.jsx)(xl,{className:`w-5 h-5 text-cyan-700 dark:text-cyan-300`}),a(`queue.batch.groupAsBatch`)]}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4`,children:a(`queue.batch.groupAsBatchDescription`,{count:e})}),(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:a(`queue.batch.nameLabel`)}),(0,G.jsx)(`input`,{type:`text`,autoFocus:!0,value:o,onChange:e=>s(e.target.value),placeholder:a(`queue.batch.namePlaceholder`),maxLength:120,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none mb-5`}),(0,G.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,G.jsx)(Q,{variant:`ghost`,size:`sm`,onClick:i,disabled:n,children:a(`common.cancel`)}),(0,G.jsx)(Q,{variant:`primary`,size:`sm`,onClick:()=>{let e=o.trim();e&&r(e)},disabled:n||!o.trim(),children:a(n?`common.saving`:`queue.batch.create`)})]})]})})}function ZBe({printDates:e,months:t=3}){let n=(0,y.useRef)(null),[r,i]=(0,y.useState)(0);(0,y.useEffect)(()=>{let e=n.current;if(!e)return;let t=new ResizeObserver(e=>{i(e[0]?.contentRect.width||0)});return t.observe(e),()=>t.disconnect()},[]);let{weeks:a,monthLabels:o,printCounts:s}=(0,y.useMemo)(()=>{let n={};e.forEach(e=>{let t=np(e);t&&(n[t]=(n[t]||0)+1)});let r=new Date,i=new Date(r);i.setMonth(i.getMonth()-t),i.setDate(i.getDate()-i.getDay());let a=[],o=[],s=[],c=-1,l=new Date(i),u=0;for(;l<=r;)l.getDay()===0&&s.length>0&&(a.push(s),s=[],u++),l.getMonth()!==c&&(o.push({month:l.toLocaleDateString(`en-US`,{month:`short`}),weekIndex:u}),c=l.getMonth()),s.push(new Date(l)),l.setDate(l.getDate()+1);return s.length>0&&a.push(s),{weeks:a,monthLabels:o,printCounts:n}},[e,t]),c=Math.max(1,...Object.values(s)),l=e=>{if(e===0)return`bg-bambu-dark`;let t=e/c;return t<=.25?`bg-bambu-green/30`:t<=.5?`bg-bambu-green/50`:t<=.75?`bg-bambu-green/75`:`bg-bambu-green`},u=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`],d=a.length,f=r-32-16,p=d>0?Math.floor((f-(d-1)*2)/d):12,m=Math.max(8,Math.min(20,p)),h=m<=10?10:12;return(0,G.jsx)(`div`,{ref:n,className:`w-full flex justify-center`,children:r>0&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`div`,{className:`flex mb-1`,style:{marginLeft:36},children:o.map(({month:e,weekIndex:t},n)=>(0,G.jsx)(`div`,{className:`text-bambu-gray`,style:{fontSize:h,marginLeft:n===0?0:`${(t-(o[n-1]?.weekIndex||0))*(m+2)-24}px`},children:e},n))}),(0,G.jsxs)(`div`,{className:`flex`,style:{gap:2},children:[(0,G.jsx)(`div`,{className:`flex flex-col`,style:{gap:2,marginRight:4,width:32},children:u.map((e,t)=>(0,G.jsx)(`div`,{className:`text-bambu-gray flex items-center`,style:{width:32,height:m,fontSize:h,visibility:t%2==1?`visible`:`hidden`},children:e},e))}),a.map((e,t)=>(0,G.jsx)(`div`,{className:`flex flex-col`,style:{gap:2},children:[0,1,2,3,4,5,6].map(t=>{let n=e.find(e=>e.getDay()===t);if(!n)return(0,G.jsx)(`div`,{style:{width:m,height:m}},t);let r=np(n),i=s[r]||0,a=r===np(new Date);return(0,G.jsx)(`div`,{className:`rounded-sm ${l(i)} ${a?`ring-1 ring-white`:``}`,style:{width:m,height:m},title:`${n.toLocaleDateString()}: ${i} print${i===1?``:`s`}`},t)})},t))]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mt-3 text-bambu-gray`,style:{fontSize:h},children:[(0,G.jsx)(`span`,{children:`Less`}),(0,G.jsxs)(`div`,{className:`flex`,style:{gap:2},children:[(0,G.jsx)(`div`,{className:`rounded-sm bg-bambu-dark`,style:{width:m,height:m}}),(0,G.jsx)(`div`,{className:`rounded-sm bg-bambu-green/30`,style:{width:m,height:m}}),(0,G.jsx)(`div`,{className:`rounded-sm bg-bambu-green/50`,style:{width:m,height:m}}),(0,G.jsx)(`div`,{className:`rounded-sm bg-bambu-green/75`,style:{width:m,height:m}}),(0,G.jsx)(`div`,{className:`rounded-sm bg-bambu-green`,style:{width:m,height:m}})]}),(0,G.jsx)(`span`,{children:`More`})]})]})})}var T3=[`weight`,`prints`,`time`];function E3({value:e,onChange:t,exclude:n}){let{t:r}=U(),i={weight:r(`stats.filamentByWeight`),prints:r(`stats.filamentByPrints`),time:r(`stats.filamentByTime`)};return(0,G.jsx)(`div`,{className:`flex gap-0.5 bg-bambu-dark rounded-lg p-0.5`,children:(n?T3.filter(e=>!n.includes(e)):T3).map(n=>(0,G.jsx)(`button`,{onClick:()=>t(n),className:`px-2 py-0.5 text-xs rounded-md transition-colors ${e===n?`bg-bambu-green text-white`:`text-bambu-gray hover:text-white`}`,children:i[n]},n))})}function D3(e){if(e>=1e6){let t=e/1e6;return`${t%1==0?t.toFixed(0):t.toFixed(1)}t`}if(e>=1e3){let t=e/1e3;return`${t%1==0?t.toFixed(0):t.toFixed(1)}kg`}return`${Math.round(e)}g`}var O3=[`#00ae42`,`#3b82f6`,`#f59e0b`,`#ef4444`,`#8b5cf6`,`#ec4899`,`#14b8a6`,`#f97316`],QBe=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`],k3=[`12am`,`1am`,`2am`,`3am`,`4am`,`5am`,`6am`,`7am`,`8am`,`9am`,`10am`,`11am`,`12pm`,`1pm`,`2pm`,`3pm`,`4pm`,`5pm`,`6pm`,`7pm`,`8pm`,`9pm`,`10pm`,`11pm`];function $Be({archives:e,currency:t=`$`,dateFrom:n,dateTo:r}){let{t:i}=U(),[a,o]=(0,y.useState)(`weight`),[s,c]=(0,y.useState)(`weight`),l=(0,y.useMemo)(()=>{let t=new Map;return e.forEach(e=>{let n=Kf(e.completed_at||e.created_at)||new Date,r=`${n.getFullYear()}-${String(n.getMonth()+1).padStart(2,`0`)}-${String(n.getDate()).padStart(2,`0`)}`,i=t.get(r)||{date:r,filament:0,cost:0,energy:0,prints:0};i.filament+=e.filament_used_grams||0,i.cost+=e.cost||0,i.energy+=e.energy_kwh||0,i.prints+=e.quantity||1,t.set(r,i)}),Array.from(t.values()).sort((e,t)=>e.date.localeCompare(t.date)).map(e=>({...e,dateLabel:new Date(e.date).toLocaleDateString(`en-US`,{month:`short`,day:`numeric`})}))},[e]),u=(0,y.useMemo)(()=>{if(n&&r)return Math.max((new Date(r).getTime()-new Date(n).getTime())/864e5,0)+1;if(n)return Math.max((Date.now()-new Date(n).getTime())/864e5,0)+1;if(e.length<2)return 0;let t=e.map(e=>new Date(e.completed_at||e.created_at).getTime());return(Math.max(...t)-Math.min(...t))/864e5},[e,n,r]),d=(0,y.useMemo)(()=>{if(u>7)return[];let t=new Map,n=u>1;return e.forEach(e=>{let n=Kf(e.completed_at||e.created_at)||new Date,r=n.getHours(),i=`${n.getFullYear()}-${String(n.getMonth()+1).padStart(2,`0`)}-${String(n.getDate()).padStart(2,`0`)}T${String(r).padStart(2,`0`)}`,a=t.get(i)||{date:i,filament:0,cost:0,energy:0,prints:0};a.filament+=e.filament_used_grams||0,a.cost+=e.cost||0,a.energy+=e.energy_kwh||0,a.prints+=e.quantity||1,t.set(i,a)}),Array.from(t.values()).sort((e,t)=>e.date.localeCompare(t.date)).map(e=>{let[t,r]=e.date.split(`T`),i=new Date(t),a=parseInt(r,10),o=n?`${QBe[i.getDay()]} ${k3[a]}`:k3[a];return{...e,dateLabel:o}})},[e,u]),f=(0,y.useMemo)(()=>{if(l.length<=60)return l;let e=new Map;return l.forEach(t=>{let n=new Date(t.date),r=new Date(n);r.setDate(n.getDate()-n.getDay());let i=`${r.getFullYear()}-${String(r.getMonth()+1).padStart(2,`0`)}-${String(r.getDate()).padStart(2,`0`)}`,a=e.get(i)||{week:i,filament:0,cost:0,energy:0,prints:0};a.filament+=t.filament,a.cost+=t.cost,a.energy+=t.energy,a.prints+=t.prints,e.set(i,a)}),Array.from(e.values()).sort((e,t)=>e.week.localeCompare(t.week)).map(e=>({date:e.week,dateLabel:`Week of ${new Date(e.week).toLocaleDateString(`en-US`,{month:`short`,day:`numeric`})}`,...e}))},[l]),p=(0,y.useMemo)(()=>{let t=new Map;return e.forEach(e=>{let n=(e.filament_type||`Unknown`).split(`, `);n.forEach(r=>{let i=(e.filament_used_grams||0)/n.length;t.set(r,(t.get(r)||0)+i)})}),Array.from(t.entries()).map(([e,t])=>({name:e,value:Math.round(t)})).sort((e,t)=>t.value-e.value)},[e]),m=(0,y.useMemo)(()=>{let t=new Map;return e.forEach(e=>{(e.filament_type||`Unknown`).split(`, `).forEach(e=>{t.set(e,(t.get(e)||0)+1)})}),Array.from(t.entries()).map(([e,t])=>({name:e,value:t})).sort((e,t)=>t.value-e.value)},[e]),h=(0,y.useMemo)(()=>{let t=new Map;return e.forEach(e=>{let n=(e.filament_type||`Unknown`).split(`, `),r=(e.actual_time_seconds||e.print_time_seconds||0)/n.length;n.forEach(e=>{t.set(e,(t.get(e)||0)+r)})}),Array.from(t.entries()).map(([e,t])=>({name:e,value:Math.round(t/3600*10)/10})).sort((e,t)=>t.value-e.value)},[e]),g=(0,y.useMemo)(()=>{let t=new Map;return e.forEach(e=>{e.status!==`completed`&&e.status!==`failed`||(e.filament_type||`Unknown`).split(`, `).forEach(n=>{let r=t.get(n)||{completed:0,failed:0};e.status===`completed`?r.completed++:r.failed++,t.set(n,r)})}),Array.from(t.entries()).filter(([,e])=>e.completed+e.failed>=2).map(([e,t])=>{let n=t.completed+t.failed;return{name:e,rate:Math.round(t.completed/n*100),total:n}}).sort((e,t)=>t.rate-e.rate)},[e]),_=(0,y.useMemo)(()=>{let t=new Map;return e.forEach(e=>{if(!e.filament_color)return;let n=e.filament_color.split(`,`).map(e=>e.trim()),r=(e.filament_used_grams||0)/n.length;n.forEach(e=>{let n=t.get(e)||{count:0,weight:0};n.count++,n.weight+=r,t.set(e,n)})}),Array.from(t.entries()).map(([e,t])=>({hex:e,value:s===`prints`?t.count:Math.round(t.weight)})).sort((e,t)=>t.value-e.value)},[e,s]),v=a===`weight`?p:a===`prints`?m:h,b=u<=7&&d.length>0?d:f,x=e.reduce((e,t)=>e+(t.filament_used_grams||0),0),S=e.reduce((e,t)=>e+(t.cost||0),0),C=e.reduce((e,t)=>e+(t.energy_kwh||0),0),w=e.reduce((e,t)=>e+(t.energy_cost||0),0),T=e.reduce((e,t)=>e+(t.quantity||1),0),E=new Set(e.map(e=>e.printer_id).filter(Boolean)).size;return(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{className:`grid grid-cols-3 gap-2 max-[640px]:grid-cols-1`,children:[(0,G.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray leading-none`,children:i(`stats.periodFilament`)}),(0,G.jsx)(`p`,{className:`text-2xl font-bold text-white leading-none`,children:D3(x)})]}),(0,G.jsxs)(`p`,{className:`text-xs text-bambu-gray`,children:[E,` `,i(`nav.printers`).toLowerCase()]})]}),(0,G.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray leading-none`,children:i(`stats.periodCost`)}),(0,G.jsxs)(`p`,{className:`text-2xl font-bold text-white leading-none`,children:[t,S.toFixed(2)]})]}),(0,G.jsxs)(`p`,{className:`text-xs text-bambu-gray`,children:[T,` `,i(`common.prints`)]})]}),(0,G.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray leading-none`,children:i(`stats.avgPerPrint`)}),(0,G.jsxs)(`p`,{className:`text-2xl font-bold text-white leading-none`,children:[T>0?(x/T).toFixed(0):0,`g`]})]}),(0,G.jsxs)(`p`,{className:`text-xs text-bambu-gray`,children:[t,T>0?(S/T).toFixed(2):`0.00`,` avg`]})]})]}),b.length>0?(0,G.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4`,children:[(0,G.jsx)(`h4`,{className:`text-sm font-medium text-bambu-gray mb-4`,children:i(`stats.usageOverTime`)}),(0,G.jsx)(cA,{width:`100%`,height:250,children:(0,G.jsxs)(VH,{data:b,children:[(0,G.jsx)(`defs`,{children:(0,G.jsxs)(`linearGradient`,{id:`colorFilament`,x1:`0`,y1:`0`,x2:`0`,y2:`1`,children:[(0,G.jsx)(`stop`,{offset:`5%`,stopColor:`#00ae42`,stopOpacity:.3}),(0,G.jsx)(`stop`,{offset:`95%`,stopColor:`#00ae42`,stopOpacity:0})]})}),(0,G.jsx)(mV,{strokeDasharray:`3 3`,stroke:`#3d3d3d`}),(0,G.jsx)(ZV,{dataKey:`dateLabel`,stroke:`#9ca3af`,tick:{fontSize:12},interval:`preserveStartEnd`}),(0,G.jsx)(nH,{stroke:`#9ca3af`,tick:{fontSize:12},tickFormatter:e=>`${e}g`}),(0,G.jsx)(tz,{contentStyle:{backgroundColor:`#2d2d2d`,border:`1px solid #3d3d3d`,borderRadius:`8px`},labelStyle:{color:`#fff`},formatter:e=>[`${Number(e??0).toFixed(0)}g`,`Filament`]}),(0,G.jsx)(kV,{type:`monotone`,dataKey:`filament`,stroke:`#00ae42`,strokeWidth:2,fillOpacity:1,fill:`url(#colorFilament)`})]})})]}):(0,G.jsx)(`div`,{className:`bg-bambu-dark rounded-lg p-8 text-center text-bambu-gray`,children:i(`stats.noPrintDataInRange`)}),C>0&&b.length>0&&(0,G.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-4`,children:[(0,G.jsx)(`h4`,{className:`text-sm font-medium text-bambu-gray`,children:i(`stats.energyOverTime`)}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[C.toFixed(3),` kWh · `,t,w.toFixed(2)]})]}),(0,G.jsx)(cA,{width:`100%`,height:250,children:(0,G.jsxs)(VH,{data:b,children:[(0,G.jsx)(`defs`,{children:(0,G.jsxs)(`linearGradient`,{id:`colorEnergy`,x1:`0`,y1:`0`,x2:`0`,y2:`1`,children:[(0,G.jsx)(`stop`,{offset:`5%`,stopColor:`#f59e0b`,stopOpacity:.3}),(0,G.jsx)(`stop`,{offset:`95%`,stopColor:`#f59e0b`,stopOpacity:0})]})}),(0,G.jsx)(mV,{strokeDasharray:`3 3`,stroke:`#3d3d3d`}),(0,G.jsx)(ZV,{dataKey:`dateLabel`,stroke:`#9ca3af`,tick:{fontSize:12},interval:`preserveStartEnd`}),(0,G.jsx)(nH,{stroke:`#9ca3af`,tick:{fontSize:12},tickFormatter:e=>`${e}kWh`}),(0,G.jsx)(tz,{contentStyle:{backgroundColor:`#2d2d2d`,border:`1px solid #3d3d3d`,borderRadius:`8px`},labelStyle:{color:`#fff`},formatter:e=>[`${Number(e??0).toFixed(3)} kWh`,i(`stats.energyUsed`)]}),(0,G.jsx)(kV,{type:`monotone`,dataKey:`energy`,stroke:`#f59e0b`,strokeWidth:2,fillOpacity:1,fill:`url(#colorEnergy)`})]})})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-3 gap-4`,children:[(0,G.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-4`,children:[(0,G.jsx)(`h4`,{className:`text-sm font-medium text-bambu-gray`,children:i(`stats.byMaterial`)}),(0,G.jsx)(E3,{value:a,onChange:o})]}),v.length>0?(0,G.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,G.jsx)(cA,{width:160,height:160,children:(0,G.jsxs)(BH,{children:[(0,G.jsx)(PB,{data:v,cx:`50%`,cy:`50%`,innerRadius:40,outerRadius:70,paddingAngle:2,dataKey:`value`,children:v.map((e,t)=>(0,G.jsx)(nz,{fill:O3[t%O3.length]},`cell-${t}`))}),(0,G.jsx)(tz,{contentStyle:{backgroundColor:`#2d2d2d`,border:`1px solid #3d3d3d`,borderRadius:`8px`},formatter:e=>[a===`weight`?D3(Number(e??0)):a===`time`?`${Number(e??0)}h`:`${e??0}`,a===`weight`?`Usage`:a===`time`?`Time`:`Prints`]})]})}),(0,G.jsx)(`div`,{className:`flex-1 space-y-2 overflow-hidden`,children:v.map((e,t)=>{let n=v.reduce((e,t)=>e+t.value,0),r=n>0?(e.value/n*100).toFixed(0):0;return(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,G.jsx)(`div`,{className:`w-3 h-3 rounded-sm flex-shrink-0`,style:{backgroundColor:O3[t%O3.length]}}),(0,G.jsx)(`span`,{className:`text-white truncate flex-1`,children:e.name}),(0,G.jsxs)(`span`,{className:`text-bambu-gray flex-shrink-0`,children:[a===`weight`?D3(e.value):a===`time`?`${e.value}h`:e.value,` · `,r,`%`]})]},e.name)})})]}):(0,G.jsx)(`div`,{className:`h-[160px] flex items-center justify-center text-bambu-gray`,children:i(`stats.noFilamentData`)})]}),(0,G.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4`,children:[(0,G.jsx)(`h4`,{className:`text-sm font-medium text-bambu-gray mb-4`,children:i(`stats.filamentSuccess`)}),g.length>0?(0,G.jsx)(`div`,{className:`space-y-1.5`,children:g.map(e=>(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,G.jsx)(`span`,{className:`text-white truncate w-20 flex-shrink-0`,children:e.name}),(0,G.jsx)(`div`,{className:`flex-1 h-1.5 bg-bambu-dark-secondary rounded-full`,children:(0,G.jsx)(`div`,{className:`h-full rounded-full transition-all ${e.rate>=90?`bg-status-ok`:e.rate>=70?`bg-status-warning`:`bg-status-error`}`,style:{width:`${e.rate}%`}})}),(0,G.jsxs)(`span`,{className:`font-medium flex-shrink-0 tabular-nums ${e.rate>=90?`text-status-ok`:e.rate>=70?`text-status-warning`:`text-status-error`}`,children:[e.rate,`%`]}),(0,G.jsxs)(`span`,{className:`text-bambu-gray flex-shrink-0 text-xs`,children:[`(`,e.total,`)`]})]},e.name))}):(0,G.jsx)(`div`,{className:`h-[160px] flex items-center justify-center text-bambu-gray`,children:i(`stats.noArchiveData`)})]}),(0,G.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-4`,children:[(0,G.jsx)(`h4`,{className:`text-sm font-medium text-bambu-gray`,children:i(`stats.colorDistribution`)}),(0,G.jsx)(E3,{value:s,onChange:c,exclude:[`time`]})]}),_.length>0?(()=>{let e=_.reduce((e,t)=>e+t.value,0);return(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`relative mx-auto`,style:{width:160,height:160},children:[(0,G.jsx)(cA,{width:`100%`,height:`100%`,children:(0,G.jsxs)(BH,{children:[(0,G.jsx)(PB,{data:_,cx:`50%`,cy:`50%`,innerRadius:45,outerRadius:70,paddingAngle:2,dataKey:`value`,children:_.map((e,t)=>(0,G.jsx)(nz,{fill:e.hex,stroke:`#1a1a1a`,strokeWidth:1},`color-${t}`))}),(0,G.jsx)(tz,{contentStyle:{backgroundColor:`#2d2d2d`,border:`1px solid #3d3d3d`,borderRadius:`8px`},formatter:e=>[s===`weight`?D3(Number(e??0)):`${e??0}`,i(s===`weight`?`stats.filamentByWeight`:`stats.filamentByPrints`)]})]})}),(0,G.jsxs)(`div`,{className:`absolute inset-0 flex flex-col items-center justify-center`,children:[(0,G.jsx)(`span`,{className:`text-lg font-bold text-white`,children:s===`weight`?D3(e):e}),(0,G.jsxs)(`span`,{className:`text-[10px] text-bambu-gray`,children:[_.length,` `,_.length===1?`color`:`colors`]})]})]}),(0,G.jsx)(`div`,{className:`grid grid-cols-2 gap-x-3 gap-y-1 mt-2`,children:_.slice(0,8).map(t=>{let n=e>0?(t.value/e*100).toFixed(0):0;return(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 text-xs min-w-0`,children:[(0,G.jsx)(`div`,{className:`w-2.5 h-2.5 rounded-full flex-shrink-0 border border-black/20`,style:{backgroundColor:t.hex}}),(0,G.jsxs)(`span`,{className:`text-bambu-gray truncate`,children:[n,`%`]})]},t.hex)})}),_.length>8&&(0,G.jsxs)(`p`,{className:`text-[10px] text-bambu-gray mt-1 text-center`,children:[`+`,_.length-8,` more`]})]})})():(0,G.jsx)(`div`,{className:`h-[160px] flex items-center justify-center text-bambu-gray`,children:i(`stats.noColorData`)})]})]})]})}function eVe({id:e,title:t,component:n,isHidden:r,size:i,columnSpan:a,onToggleVisibility:o,onToggleSize:s}){let{attributes:c,listeners:l,setNodeRef:u,transform:d,transition:f,isDragging:p}=o3({id:e}),m={transform:R2.Transform.toString(d),transition:f,opacity:p?.5:1};return r?null:(0,G.jsxs)(`div`,{ref:u,style:{...m,gridColumn:`span ${a}`},className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary overflow-hidden ${p?`ring-2 ring-bambu-green shadow-lg`:``}`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 border-b border-bambu-dark-tertiary bg-bambu-dark/30`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`button`,{...c,...l,className:`cursor-grab active:cursor-grabbing p-1 hover:bg-bambu-dark-tertiary rounded transition-colors`,title:`Drag to reorder`,children:(0,G.jsx)(Oc,{className:`w-6 h-6 md:w-4 md:h-4 text-bambu-gray`})}),(0,G.jsx)(`h3`,{className:`text-sm font-medium text-white`,children:t})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(`button`,{onClick:s,className:`p-1 hover:bg-bambu-dark-tertiary rounded transition-colors`,title:`Size: ${i===1?`1/4`:i===2?`1/2`:`Full`} - Click to cycle`,children:i===4?(0,G.jsx)(ul,{className:`w-4 h-4 text-bambu-gray hover:text-white`}):(0,G.jsx)(ol,{className:`w-4 h-4 text-bambu-gray hover:text-white`})}),(0,G.jsx)(`button`,{onClick:o,className:`p-1 hover:bg-bambu-dark-tertiary rounded transition-colors`,title:`Hide widget`,children:(0,G.jsx)(nc,{className:`w-4 h-4 text-bambu-gray hover:text-white`})})]})]}),(0,G.jsx)(`div`,{className:`p-4`,children:typeof n==`function`?n(i):n})]})}function tVe({widgets:e,storageKey:t,columns:n=4,stackBelow:r,hideControls:i=!1,onResetLayout:a,renderControls:o}){let s=()=>{let t={};return e.forEach(e=>{t[e.id]=e.defaultSize||4}),t},[c,l]=(0,y.useState)(()=>{let n=localStorage.getItem(t);if(n)try{let e=JSON.parse(n);if(!e.sizes)e.sizes=s();else{let t=s();for(let n in t)n in e.sizes||(e.sizes[n]=t[n])}return e}catch{}return{order:e.map(e=>e.id),hidden:e.filter(e=>e.defaultVisible===!1).map(e=>e.id),sizes:s()}}),[u,d]=(0,y.useState)(!1),[f,p]=(0,y.useState)(!1);(0,y.useEffect)(()=>{if(!r)return;let e=window.matchMedia(`(max-width: ${r}px)`),t=e=>{p(e.matches)};t(e);let n=e=>t(e);return e.addEventListener?e.addEventListener(`change`,n):e.addListener(n),()=>{e.removeEventListener?e.removeEventListener(`change`,n):e.removeListener(n)}},[r]);let m=r&&f?1:n;(0,y.useEffect)(()=>{let e=()=>d(e=>!e);return window.addEventListener(`toggle-hidden-panel`,e),()=>window.removeEventListener(`toggle-hidden-panel`,e)},[]),(0,y.useEffect)(()=>{localStorage.setItem(t,JSON.stringify(c))},[c,t]),(0,y.useEffect)(()=>{let t=e.map(e=>e.id).filter(e=>!c.order.includes(e));t.length>0&&l(e=>({...e,order:[...e.order,...t]}))},[e,c.order]);let h=W2(U2(w4,{activationConstraint:{distance:8}}),U2(b4,{coordinateGetter:c3})),g=e=>{let{active:t,over:n}=e;n&&t.id!==n.id&&l(e=>{let r=e.order.indexOf(t.id),i=e.order.indexOf(n.id);return{...e,order:Q4(e.order,r,i)}})},_=e=>{l(t=>({...t,hidden:t.hidden.includes(e)?t.hidden.filter(t=>t!==e):[...t.hidden,e]}))},v=e=>{l(t=>{let n=t.sizes[e]||4,r=n===1?2:n===2?4:1;return{...t,sizes:{...t.sizes,[e]:r}}})},b=()=>{l({order:e.map(e=>e.id),hidden:e.filter(e=>e.defaultVisible===!1).map(e=>e.id),sizes:s()}),a?.()},x=c.order.map(t=>e.find(e=>e.id===t)).filter(Boolean),S=x.filter(e=>!c.hidden.includes(e.id)),C=x.filter(e=>c.hidden.includes(e.id)),w=o?.({hiddenCount:C.length,showHiddenPanel:u,setShowHiddenPanel:d,resetLayout:b});return(0,G.jsxs)(`div`,{className:`space-y-4`,children:[w,!i&&!o&&(0,G.jsxs)(`div`,{className:`flex items-center justify-end gap-2`,children:[(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:b,children:[(0,G.jsx)(Vl,{className:`w-4 h-4`}),`Reset Layout`]}),C.length>0&&(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:()=>d(!u),children:[(0,G.jsx)(rc,{className:`w-4 h-4`}),C.length,` Hidden`]})]}),u&&C.length>0&&(0,G.jsxs)(`div`,{className:`p-4 bg-bambu-dark rounded-xl border border-bambu-dark-tertiary`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mb-3`,children:`Hidden widgets (click to show):`}),(0,G.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:C.map(e=>(0,G.jsxs)(`button`,{onClick:()=>_(e.id),className:`px-3 py-1.5 bg-bambu-dark-tertiary hover:bg-bambu-green/20 rounded-lg text-sm text-white transition-colors flex items-center gap-2`,children:[(0,G.jsx)(rc,{className:`w-3 h-3`}),e.title]},e.id))})]}),(0,G.jsx)(J4,{sensors:h,collisionDetection:Z2,onDragEnd:g,children:(0,G.jsx)(i3,{items:S.map(e=>e.id),strategy:e3,children:(0,G.jsx)(`div`,{className:`grid gap-6`,style:{gridTemplateColumns:`repeat(${m}, minmax(0, 1fr))`},children:S.map(e=>{let t=c.sizes[e.id]||2,n=Math.min(t,m);return(0,G.jsx)(eVe,{id:e.id,title:e.title,component:e.component,isHidden:c.hidden.includes(e.id),size:t,columnSpan:n,onToggleVisibility:()=>_(e.id),onToggleSize:()=>v(e.id)},e.id)})})})}),S.length===0&&(0,G.jsxs)(`div`,{className:`text-center py-12 text-bambu-gray`,children:[(0,G.jsx)(`p`,{children:`All widgets are hidden.`}),(0,G.jsx)(Q,{className:`mt-4`,onClick:b,children:`Reset Layout`})]})]})}function nVe(e){let t=new Date,n=t.getUTCFullYear(),r=t.getUTCMonth(),i=t.getUTCDate(),a=e=>e.toISOString().split(`T`)[0],o=a(t);switch(e){case`today`:return{dateFrom:o,dateTo:o};case`this-week`:{let e=t.getUTCDay();return{dateFrom:a(new Date(Date.UTC(n,r,i-(e===0?6:e-1)))),dateTo:o}}case`this-month`:return{dateFrom:a(new Date(Date.UTC(n,r,1))),dateTo:o};case`last-7`:return{dateFrom:a(new Date(Date.UTC(n,r,i-6))),dateTo:o};case`last-30`:return{dateFrom:a(new Date(Date.UTC(n,r,i-29))),dateTo:o};case`last-90`:return{dateFrom:a(new Date(Date.UTC(n,r,i-89))),dateTo:o};case`this-year`:return{dateFrom:a(new Date(Date.UTC(n,0,1))),dateTo:o};case`all-time`:return{dateFrom:void 0,dateTo:void 0};case`custom`:return{}}}var rVe=[`today`,`this-week`,`this-month`,`last-7`,`last-30`,`last-90`,`this-year`,`all-time`],iVe=[`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`,`Sun`],A3=[`12am`,`1am`,`2am`,`3am`,`4am`,`5am`,`6am`,`7am`,`8am`,`9am`,`10am`,`11am`,`12pm`,`1pm`,`2pm`,`3pm`,`4pm`,`5pm`,`6pm`,`7pm`,`8pm`,`9pm`,`10pm`,`11pm`],j3=[{key:`<30m`,max:1800},{key:`30m-1h`,max:3600},{key:`1-2h`,max:7200},{key:`2-4h`,max:14400},{key:`4-8h`,max:28800},{key:`8-12h`,max:43200},{key:`12-24h`,max:86400},{key:`24h+`,max:1/0}],M3={backgroundColor:`#2d2d2d`,border:`1px solid #3d3d3d`,borderRadius:`8px`};function aVe({stats:e,currency:t}){let{t:n}=U(),r=e?.energy_data_warming_up===!0,i=r?n(`stats.energyWarmingUpTooltip`):void 0;return(0,G.jsx)(`div`,{className:`grid grid-cols-2 sm:grid-cols-3 gap-4`,children:[{icon:xl,color:`text-bambu-green`,label:n(`stats.totalPrints`),value:`${e?.total_prints||0}`},{icon:ks,color:`text-blue-600 dark:text-blue-400`,label:n(`stats.printTime`),value:`${e?.total_print_time_hours?.toFixed(1)??`0`}h`},{icon:xl,color:`text-orange-600 dark:text-orange-400`,label:n(`stats.filamentUsed`),value:D3(e?.total_filament_grams||0)},{icon:Gs,color:`text-green-600 dark:text-green-400`,label:n(`stats.filamentCost`),value:`${t} ${e?.total_cost?.toFixed(2)??`0.00`}`},{icon:td,color:`text-yellow-600 dark:text-yellow-400`,label:n(`stats.energyUsed`),value:`${e?.total_energy_kwh?.toFixed(3)??`0.000`} kWh`,warning:r,tooltip:i},{icon:Gs,color:`text-yellow-500`,label:n(`stats.energyCost`),value:`${t} ${e?.total_energy_cost?.toFixed(2)??`0.00`}`,warning:r,tooltip:i}].map(e=>(0,G.jsxs)(`div`,{className:`flex items-start gap-3`,title:e.tooltip,children:[(0,G.jsx)(`div`,{className:`p-2 rounded-lg bg-bambu-dark ${e.color}`,children:(0,G.jsx)(e.icon,{className:`w-5 h-5`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`p`,{className:`text-xs text-bambu-gray flex items-center gap-1`,children:[e.label,e.warning&&(0,G.jsx)(Pu,{className:`w-3 h-3 text-yellow-600 dark:text-yellow-400`,"aria-label":e.tooltip})]}),(0,G.jsx)(`p`,{className:`text-xl font-bold text-white`,children:e.value})]})]},e.label))})}function oVe({stats:e,printerMap:t,size:n=1}){let{t:r}=U(),i=(e?.successful_prints||0)+(e?.failed_prints||0),a=i?Math.round((e?.successful_prints||0)/i*100):0,o=n===1?112:n===2?128:144,s=o/2-8,c=s*2*Math.PI;return(0,G.jsxs)(`div`,{className:`flex items-center gap-6`,children:[(0,G.jsxs)(`div`,{className:`relative flex-shrink-0`,style:{width:o,height:o},children:[(0,G.jsxs)(`svg`,{className:`w-full h-full -rotate-90`,children:[(0,G.jsx)(`circle`,{cx:o/2,cy:o/2,r:s,fill:`none`,stroke:`#3d3d3d`,strokeWidth:`10`}),(0,G.jsx)(`circle`,{cx:o/2,cy:o/2,r:s,fill:`none`,stroke:`#00ae42`,strokeWidth:`10`,strokeLinecap:`round`,strokeDasharray:`${a/100*c} ${c}`})]}),(0,G.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center`,children:(0,G.jsxs)(`span`,{className:`font-bold text-white ${n>=2?`text-2xl`:`text-xl`}`,children:[a,`%`]})})]}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(ys,{className:`w-4 h-4 text-status-ok flex-shrink-0`}),(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:r(`stats.successful`)}),(0,G.jsx)(`span`,{className:`text-sm text-white font-medium`,children:e?.successful_prints||0})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Ts,{className:`w-4 h-4 text-status-error flex-shrink-0`}),(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:r(`stats.failed`)}),(0,G.jsx)(`span`,{className:`text-sm text-white font-medium`,children:e?.failed_prints||0})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Ho,{className:`w-4 h-4 text-status-warning flex-shrink-0`}),(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:r(`stats.cancelled`)}),(0,G.jsx)(`span`,{className:`text-sm text-white font-medium`,children:e?.cancelled_prints||0})]})]}),n>=2&&e?.prints_by_printer&&Object.keys(e.prints_by_printer).length>0&&(0,G.jsxs)(`div`,{className:`mt-4 pt-4 border-t border-bambu-dark-tertiary`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray font-medium mb-2`,children:r(`stats.printsByPrinter`)}),(0,G.jsx)(`div`,{className:`grid gap-x-6 gap-y-1 ${n===4?`grid-cols-3`:`grid-cols-2`}`,style:{width:`fit-content`},children:Object.entries(e.prints_by_printer).map(([e,n])=>(0,G.jsxs)(`div`,{className:`flex items-center gap-3 text-sm`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray truncate max-w-[120px]`,children:t.get(e)||`${r(`common.printer`)} ${e}`}),(0,G.jsx)(`span`,{className:`text-white font-medium`,children:n})]},e))})]})]})]})}function sVe({stats:e,printerMap:t,size:n=1}){let{t:r}=U(),i=e?.average_time_accuracy;if(i==null)return(0,G.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,G.jsx)(`p`,{className:`text-bambu-gray text-center py-4`,children:r(`stats.noTimeAccuracyData`)})});let a=(Math.min(150,Math.max(50,i))-50)/100*100,o=(e=>e>=95&&e<=105?`#00ae42`:e>105?`#3b82f6`:`#f97316`)(i),s=i-100,c=n===1?112:n===2?128:144,l=c/2-8,u=l*2*Math.PI,d=n===1?3:n===2?6:999,f=e?.time_accuracy_by_printer?Object.entries(e.time_accuracy_by_printer).slice(0,d):[];return(0,G.jsxs)(`div`,{className:`flex items-center gap-6`,children:[(0,G.jsxs)(`div`,{className:`relative flex-shrink-0`,style:{width:c,height:c},children:[(0,G.jsxs)(`svg`,{className:`w-full h-full -rotate-90`,children:[(0,G.jsx)(`circle`,{cx:c/2,cy:c/2,r:l,fill:`none`,stroke:`#3d3d3d`,strokeWidth:`10`}),(0,G.jsx)(`circle`,{cx:c/2,cy:c/2,r:l,fill:`none`,stroke:o,strokeWidth:`10`,strokeLinecap:`round`,strokeDasharray:`${a/100*u} ${u}`})]}),(0,G.jsxs)(`div`,{className:`absolute inset-0 flex flex-col items-center justify-center`,children:[(0,G.jsxs)(`span`,{className:`font-bold text-white ${n>=2?`text-2xl`:`text-xl`}`,children:[i.toFixed(0),`%`]}),(0,G.jsxs)(`span`,{className:`text-xs ${s>=0?`text-blue-700 dark:text-blue-400`:`text-orange-700 dark:text-orange-400`}`,children:[s>=0?`+`:``,s.toFixed(0),`%`]})]})]}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-bambu-gray`,children:[(0,G.jsx)(wu,{className:`w-3 h-3 flex-shrink-0`}),(0,G.jsx)(`span`,{children:r(`stats.perfectEstimate`)})]}),f.length>0&&(0,G.jsx)(`div`,{className:`mt-2 ${n===4?`grid grid-cols-3 gap-x-6 gap-y-1`:n===2?`grid grid-cols-2 gap-x-6 gap-y-1`:`space-y-1`}`,style:{width:`fit-content`},children:f.map(([e,n])=>(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-xs`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray truncate max-w-[100px]`,children:t.get(e)||`${r(`common.printer`)} ${e}`}),(0,G.jsxs)(`span`,{className:`font-medium ${n>=95&&n<=105?`text-status-ok`:n>105?`text-blue-700 dark:text-blue-400`:`text-status-warning`}`,children:[n.toFixed(0),`%`]})]},e))})]})]})}function cVe({printDates:e,dateFrom:t,dateTo:n}){let{days:r,hourlyCounts:i,maxCount:a}=(0,y.useMemo)(()=>{let r=new Date(t+`T00:00:00`),i=new Date(n+`T00:00:00`),a=[],o=e=>`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,`0`)}-${String(e.getDate()).padStart(2,`0`)}`,s=new Date(r);for(;s<=i;)a.push({key:o(s),label:s.toLocaleDateString(void 0,{weekday:`short`,month:`short`,day:`numeric`})}),s.setDate(s.getDate()+1);let c={},l=0;return e.forEach(e=>{let t=Kf(e);if(!t)return;let n=`${`${t.getFullYear()}-${String(t.getMonth()+1).padStart(2,`0`)}-${String(t.getDate()).padStart(2,`0`)}`}-${t.getHours()}`;c[n]=(c[n]||0)+1,c[n]>l&&(l=c[n])}),{days:a,hourlyCounts:c,maxCount:Math.max(1,l)}},[e,t,n]),o=e=>{if(e===0)return`bg-bambu-dark`;let t=e/a;return t<=.25?`bg-bambu-green/30`:t<=.5?`bg-bambu-green/50`:t<=.75?`bg-bambu-green/75`:`bg-bambu-green`};return(0,G.jsxs)(`div`,{className:`w-full overflow-x-auto`,children:[(0,G.jsxs)(`div`,{className:`inline-flex flex-col`,style:{gap:2},children:[(0,G.jsx)(`div`,{className:`flex`,style:{gap:2,marginLeft:84},children:A3.map((e,t)=>(0,G.jsx)(`div`,{className:`text-bambu-gray text-[10px] text-center`,style:{width:20,visibility:t%2==0?`visible`:`hidden`},children:e},t))}),r.map(e=>(0,G.jsxs)(`div`,{className:`flex items-center`,style:{gap:2},children:[(0,G.jsx)(`div`,{className:`text-bambu-gray text-[10px] flex-shrink-0 truncate`,style:{width:80},children:e.label}),Array.from({length:24},(t,n)=>{let r=i[`${e.key}-${n}`]||0;return(0,G.jsx)(`div`,{className:`rounded-sm ${o(r)}`,style:{width:20,height:20},title:`${e.label} ${A3[n]}: ${r} print${r===1?``:`s`}`},n)})]},e.key))]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mt-3 text-bambu-gray text-xs`,children:[(0,G.jsx)(`span`,{children:`Less`}),(0,G.jsxs)(`div`,{className:`flex`,style:{gap:2},children:[(0,G.jsx)(`div`,{className:`rounded-sm bg-bambu-dark`,style:{width:20,height:20}}),(0,G.jsx)(`div`,{className:`rounded-sm bg-bambu-green/30`,style:{width:20,height:20}}),(0,G.jsx)(`div`,{className:`rounded-sm bg-bambu-green/50`,style:{width:20,height:20}}),(0,G.jsx)(`div`,{className:`rounded-sm bg-bambu-green/75`,style:{width:20,height:20}}),(0,G.jsx)(`div`,{className:`rounded-sm bg-bambu-green`,style:{width:20,height:20}})]}),(0,G.jsx)(`span`,{children:`More`})]})]})}function lVe({printDates:e,size:t=2,dateFrom:n,dateTo:r}){let i=(0,y.useMemo)(()=>n&&r?Math.max((new Date(r).getTime()-new Date(n).getTime())/864e5,0)+1:n?Math.max((Date.now()-new Date(n).getTime())/864e5,0)+1:1/0,[n,r]);return i<=7&&n&&r?(0,G.jsx)(cVe,{printDates:e,dateFrom:n,dateTo:r}):(0,G.jsx)(ZBe,{printDates:e,months:i===1/0?t===1?3:t===2?6:12:Math.max(1,Math.ceil(i/30))})}function uVe({stats:e,archives:t,printerMap:n}){let{t:r}=U(),[i,a]=(0,y.useState)(`weight`),[o,s]=(0,y.useState)(`weight`),c=(0,y.useMemo)(()=>{let a=new Map;return e?.prints_by_printer&&Object.entries(e.prints_by_printer).forEach(([e,t])=>{let n=a.get(e)||{prints:0,weight:0,time:0};n.prints=t,a.set(e,n)}),t.forEach(t=>{if(!t.printer_id)return;let n=String(t.printer_id),r=a.get(n)||{prints:0,weight:0,time:0};r.weight+=t.filament_used_grams||0,r.time+=t.actual_time_seconds||t.print_time_seconds||0,e?.prints_by_printer||r.prints++,a.set(n,r)}),Array.from(a.entries()).map(([e,t])=>({name:n.get(e)||`${r(`common.printer`)} ${e}`,value:i===`prints`?t.prints:i===`weight`?Math.round(t.weight):Math.round(t.time/3600*10)/10})).sort((e,t)=>t.value-e.value)},[e,t,n,i,r]),l=(0,y.useMemo)(()=>{let e=Array.from({length:24},(e,t)=>({hour:t,label:A3[t],total:0,failures:0}));return t.forEach(t=>{if(!t.started_at)return;let n=Kf(t.started_at);if(!n)return;let r=n.getHours();e[r].total++,t.status===`failed`&&e[r].failures++}),e},[t]),u=(0,y.useMemo)(()=>{let e=j3.map(e=>({name:e.key,count:0}));return t.forEach(t=>{let n=t.actual_time_seconds||t.print_time_seconds;if(!(!n||n<=0)){for(let t=0;t{let e=[0,0,0,0,0,0,0],n=new Set;t.forEach(t=>{let r=Kf(t.created_at)||new Date(t.created_at),i=r.getDay()-1;i<0&&(i=6),o===`prints`?e[i]++:o===`weight`?e[i]+=t.filament_used_grams||0:e[i]+=(t.actual_time_seconds||t.print_time_seconds||0)/3600;let a=new Date(r);a.setDate(r.getDate()-(r.getDay()+6)%7),n.add(`${a.getFullYear()}-${String(a.getMonth()+1).padStart(2,`0`)}-${String(a.getDate()).padStart(2,`0`)}`)});let r=Math.max(n.size,1);return iVe.map((t,n)=>({name:t,avg:Math.round(e[n]/r*10)/10}))},[t,o]),f=e=>({unit:e===`weight`?`g`:e===`time`?`h`:``,color:e===`weight`?`#00ae42`:e===`time`?`#3b82f6`:`#f59e0b`}),p=f(i),m=r(i===`weight`?`stats.filamentByWeight`:i===`time`?`stats.hours`:`common.prints`),h=f(o),g=r(o===`weight`?`stats.avgWeight`:o===`time`?`stats.avgTime`:`stats.avgPrints`);return(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,G.jsx)(`h4`,{className:`text-sm font-medium text-bambu-gray`,children:r(`stats.printsByPrinter`)}),(0,G.jsx)(E3,{value:i,onChange:a})]}),c.length>0?(0,G.jsx)(cA,{width:`100%`,height:Math.max(140,c.length*40),children:(0,G.jsxs)(FH,{data:c,layout:`vertical`,margin:{left:10},children:[(0,G.jsx)(mV,{strokeDasharray:`3 3`,stroke:`#3d3d3d`}),(0,G.jsx)(ZV,{type:`number`,stroke:`#9ca3af`,tick:{fontSize:11},unit:p.unit}),(0,G.jsx)(nH,{type:`category`,dataKey:`name`,stroke:`#9ca3af`,tick:{fontSize:11},width:100}),(0,G.jsx)(tz,{contentStyle:M3,formatter:e=>[i===`weight`?D3(Number(e??0)):`${e??0}${p.unit}`,m]}),(0,G.jsx)(UV,{dataKey:`value`,fill:p.color,radius:[0,4,4,0]})]})}):(0,G.jsx)(`p`,{className:`text-bambu-gray text-center py-4`,children:r(`stats.noPrinterData`)})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-3 gap-4`,children:[(0,G.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4`,children:[(0,G.jsx)(`h4`,{className:`text-sm font-medium text-bambu-gray mb-3`,children:r(`stats.printDuration`)}),t.length>0?(0,G.jsx)(cA,{width:`100%`,height:160,children:(0,G.jsxs)(FH,{data:u,children:[(0,G.jsx)(mV,{strokeDasharray:`3 3`,stroke:`#3d3d3d`}),(0,G.jsx)(ZV,{dataKey:`name`,stroke:`#9ca3af`,tick:{fontSize:11}}),(0,G.jsx)(nH,{stroke:`#9ca3af`,tick:{fontSize:11},allowDecimals:!1}),(0,G.jsx)(tz,{contentStyle:M3}),(0,G.jsx)(UV,{dataKey:`count`,name:r(`common.prints`),fill:`#00ae42`,radius:[4,4,0,0]})]})}):(0,G.jsx)(`p`,{className:`text-bambu-gray text-center py-4`,children:r(`stats.noArchiveData`)})]}),(0,G.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,G.jsx)(`h4`,{className:`text-sm font-medium text-bambu-gray`,children:r(`stats.printHabits`)}),(0,G.jsx)(E3,{value:o,onChange:s})]}),t.length>0?(0,G.jsx)(cA,{width:`100%`,height:160,children:(0,G.jsxs)(FH,{data:d,children:[(0,G.jsx)(mV,{strokeDasharray:`3 3`,stroke:`#3d3d3d`}),(0,G.jsx)(ZV,{dataKey:`name`,stroke:`#9ca3af`,tick:{fontSize:11}}),(0,G.jsx)(nH,{stroke:`#9ca3af`,tick:{fontSize:11},unit:h.unit}),(0,G.jsx)(tz,{contentStyle:M3,formatter:e=>[`${e??0}${h.unit}`,g]}),(0,G.jsx)(UV,{dataKey:`avg`,fill:h.color,radius:[4,4,0,0]})]})}):(0,G.jsx)(`p`,{className:`text-bambu-gray text-center py-4`,children:r(`stats.noArchiveData`)})]}),(0,G.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4`,children:[(0,G.jsx)(`h4`,{className:`text-sm font-medium text-bambu-gray mb-3`,children:r(`stats.printTimeOfDay`)}),t.length>0?(0,G.jsx)(cA,{width:`100%`,height:160,children:(0,G.jsxs)(FH,{data:l,children:[(0,G.jsx)(mV,{strokeDasharray:`3 3`,stroke:`#3d3d3d`}),(0,G.jsx)(ZV,{dataKey:`label`,stroke:`#9ca3af`,tick:{fontSize:10},interval:5}),(0,G.jsx)(nH,{stroke:`#9ca3af`,tick:{fontSize:11},allowDecimals:!1}),(0,G.jsx)(tz,{contentStyle:M3}),(0,G.jsx)(UV,{dataKey:`total`,name:r(`stats.totalPrints`),fill:`#00ae42`,radius:[2,2,0,0]}),(0,G.jsx)(UV,{dataKey:`failures`,name:r(`stats.failed`),fill:`#ef4444`,radius:[2,2,0,0]})]})}):(0,G.jsx)(`p`,{className:`text-bambu-gray text-center py-4`,children:r(`stats.noArchiveData`)})]})]})]})}function dVe({archives:e,currency:t,dateFrom:n,dateTo:r}){let{t:i}=U();return!e||e.length===0?(0,G.jsx)(`p`,{className:`text-bambu-gray text-center py-4`,children:i(`stats.noPrintData`)}):(0,G.jsx)($Be,{archives:e,currency:t,dateFrom:n,dateTo:r})}function fVe({size:e=1,dateFrom:t,dateTo:n,createdById:r}){let{t:i}=U(),a=!!(t||n),{data:o,isLoading:s}=K({queryKey:[`failureAnalysis`,t,n,r??`all`],queryFn:()=>Z.getFailureAnalysis({...a?{dateFrom:t,dateTo:n}:{days:30},createdById:r})});if(s)return(0,G.jsx)(`div`,{className:`flex justify-center py-4`,children:(0,G.jsx)(Y,{className:`w-6 h-6 text-bambu-green animate-spin`})});if(!o||o.total_prints===0)return(0,G.jsx)(`p`,{className:`text-bambu-gray text-center py-4`,children:i(a?`stats.noPrintDataInRange`:`stats.noPrintDataLast30Days`)});let c=e===1?5:e===2?8:999,l=Object.entries(o.failures_by_reason).sort(([,e],[,t])=>t-e),u=l.slice(0,c),d=l.length>c;return(0,G.jsxs)(`div`,{className:`${e>=2?`flex gap-8`:`space-y-4`}`,children:[(0,G.jsxs)(`div`,{className:e>=2?`flex-shrink-0`:``,children:[(0,G.jsx)(`div`,{className:`flex items-center gap-4`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Pu,{className:`w-5 h-5 ${o.failure_rate>20?`text-status-error`:o.failure_rate>10?`text-status-warning`:`text-status-ok`}`}),(0,G.jsxs)(`span`,{className:`font-bold text-white ${e>=2?`text-3xl`:`text-2xl`}`,children:[o.failure_rate.toFixed(1),`%`]})]})}),(0,G.jsx)(`div`,{className:`text-sm text-bambu-gray mt-1`,children:i(`stats.failedPrintsCount`,{failed:o.failed_prints,total:o.total_prints})}),o.trend&&o.trend.length>=2&&(0,G.jsx)(`div`,{className:`${e>=2?`mt-4`:`mt-2 pt-2 border-t border-bambu-dark-tertiary`}`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,G.jsx)(Mu,{className:`w-4 h-4 ${o.trend[o.trend.length-1].failure_rate0&&(0,G.jsxs)(`div`,{className:`flex-1 ${e>=2?`border-l border-bambu-dark-tertiary pl-8`:`pt-2`}`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray font-medium mb-2`,children:i(e>=2?`stats.failureReasons`:`stats.topFailureReasons`)}),(0,G.jsx)(`div`,{className:`${e===4?`grid grid-cols-2 gap-x-6 gap-y-1`:`space-y-1`}`,children:u.map(([t,n])=>(0,G.jsxs)(`div`,{className:`flex items-center justify-between text-sm`,children:[(0,G.jsx)(`span`,{className:`text-white truncate ${e===4?`max-w-[200px]`:`max-w-[160px]`}`,children:t?i(`editArchive.failureReasons.${t}`,{defaultValue:t}):i(`common.unknown`)}),(0,G.jsx)(`span`,{className:`text-bambu-gray ml-2`,children:n})]},t))}),d&&(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-2`,children:i(`common.more`,{count:l.length-c})})]})]})}function pVe({archives:e,currency:t}){let{t:n}=U(),r=(0,y.useMemo)(()=>{let r=[];if(e.length===0)return r;let i=t=>{let n=null,r=0;return e.forEach(e=>{let i=t(e);i&&i>r&&(r=i,n=e)}),{archive:n,value:r}},a=i(e=>e.status===`completed`?e.actual_time_seconds:null);a.archive&&r.push({icon:ks,iconColor:`text-blue-600 dark:text-blue-400`,label:n(`stats.longestPrint`),value:Qf(a.value),detail:a.archive.print_name||null});let o=i(e=>e.filament_used_grams);o.archive&&r.push({icon:xl,iconColor:`text-orange-600 dark:text-orange-400`,label:n(`stats.heaviestPrint`),value:D3(o.value),detail:o.archive.print_name||null});let s=i(e=>(e.cost??0)+(e.energy_cost??0));s.archive&&r.push({icon:Gs,iconColor:`text-green-600 dark:text-green-400`,label:n(`stats.mostExpensivePrint`),value:`${t}${s.value.toFixed(2)}`,detail:s.archive.print_name||null});let c=new Map;e.forEach(e=>{let t=Kf(e.created_at)||new Date(e.created_at),n=`${t.getFullYear()}-${String(t.getMonth()+1).padStart(2,`0`)}-${String(t.getDate()).padStart(2,`0`)}`;c.set(n,(c.get(n)||0)+1)});let l=``,u=0;c.forEach((e,t)=>{e>u&&(u=e,l=t)}),u>1&&r.push({icon:rs,iconColor:`text-purple-600 dark:text-purple-400`,label:n(`stats.busiestDay`),value:`${u} ${n(`common.prints`)}`,detail:(()=>{let[e,t,n]=l.split(`-`).map(Number);return new Date(e,t-1,n).toLocaleDateString(void 0,{month:`short`,day:`numeric`,year:`numeric`})})()});let d=[...e].filter(e=>e.status===`completed`||e.status===`failed`).sort((e,t)=>new Date(t.completed_at||t.created_at).getTime()-new Date(e.completed_at||e.created_at).getTime()),f=0;for(let e of d)if(e.status===`completed`)f++;else break;return f>0&&r.push({icon:td,iconColor:`text-yellow-600 dark:text-yellow-400`,label:n(`stats.successStreak`),value:`${f}`,detail:f===1?n(`stats.streakPrint`):n(`stats.streakPrints`,{count:f})}),r},[e,t,n]);return r.length===0?(0,G.jsx)(`p`,{className:`text-bambu-gray text-center py-4`,children:n(`stats.noArchiveData`)}):(0,G.jsx)(`div`,{className:`space-y-3`,children:r.map((e,t)=>(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`p-1.5 rounded-lg bg-bambu-dark ${e.iconColor}`,children:(0,G.jsx)(e.icon,{className:`w-4 h-4`})}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:e.label}),(0,G.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,G.jsx)(`span`,{className:`text-sm font-bold text-white`,children:e.value}),e.detail&&(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray truncate`,children:e.detail})]})]})]},t))})}function mVe(){let{t:e}=U(),{showToast:t}=Bd(),{hasPermission:n,authEnabled:r}=Ed(),[i,a]=(0,y.useState)(!1),[o,s]=(0,y.useState)(!1),[c,l]=(0,y.useState)(0),[u,d]=(0,y.useState)(0),[f,p]=(0,y.useState)(!1),[m,h]=(0,y.useState)(null),[g,_]=(0,y.useState)(!1),v=r&&n(`stats:filter_by_user`),[b,x]=(0,y.useState)(()=>{try{let e=localStorage.getItem(`bambusy-stats-timeframe`);if(e){let t=JSON.parse(e);if(t.preset)return t}}catch{}return{preset:`all-time`,dateFrom:void 0,dateTo:void 0}}),[S,C]=(0,y.useState)(!1);(0,y.useEffect)(()=>{localStorage.setItem(`bambusy-stats-timeframe`,JSON.stringify(b))},[b]);let w=(0,y.useMemo)(()=>b.preset===`custom`?{dateFrom:b.dateFrom,dateTo:b.dateTo}:nVe(b.preset),[b]);(0,y.useEffect)(()=>{let e=()=>{try{let e=localStorage.getItem(`bambusy-dashboard-layout-v2`);e&&d(JSON.parse(e).hidden?.length||0)}catch{d(0)}};e(),window.addEventListener(`storage`,e);let t=setInterval(e,2e3);return()=>{window.removeEventListener(`storage`,e),clearInterval(t)}},[c]);let T=m===null?void 0:m,{data:E,isLoading:D,isFetching:O,refetch:k}=K({queryKey:[`archiveStats`,w.dateFrom,w.dateTo,T??`all`],queryFn:()=>Z.getArchiveStats({dateFrom:w.dateFrom,dateTo:w.dateTo,createdById:T})}),{data:A}=K({queryKey:[`printers`],queryFn:Z.getPrinters}),{data:j,isFetching:M,refetch:N}=K({queryKey:[`archivesSlim`,w.dateFrom,w.dateTo,T??`all`],queryFn:()=>Z.getArchivesSlim(w.dateFrom,w.dateTo,T)}),{data:P}=K({queryKey:[`settings`],queryFn:Z.getSettings}),{data:F}=K({queryKey:[`users`,`slim`],queryFn:Z.getUsersSlim,enabled:v}),I=(0,y.useMemo)(()=>m===null?e(`stats.allUsers`,`All Users`):m===-1?e(`stats.noUser`,`No User (System)`):F?.find(e=>e.id===m)?.username??`?`,[m,F,e]),L=async n=>{s(!1),a(!0);try{let{blob:r,filename:i}=await Z.exportStats({format:n,days:90,createdById:T}),a=URL.createObjectURL(r),o=document.createElement(`a`);o.href=a,o.download=i,o.click(),URL.revokeObjectURL(a),t(e(`stats.exportDownloaded`))}catch{t(e(`stats.exportFailed`),`error`)}finally{a(!1)}},R=async()=>{p(!0);try{let n=await Z.recalculateCosts();await Promise.all([k(),N()]),t(e(`stats.recalculatedCosts`,{count:n.updated}))}catch{t(e(`stats.recalculateFailed`),`error`)}finally{p(!1)}},z=(O||M)&&!D,B=Ef(P?.currency||`USD`),V=new Map(A?.map(e=>[String(e.id),e.name])||[]),ee=(0,y.useMemo)(()=>j?.map(e=>e.created_at)||[],[j]);if(D)return(0,G.jsx)(`div`,{className:`p-4 md:p-8`,children:(0,G.jsx)(`div`,{className:`text-center py-12 text-bambu-gray`,children:e(`stats.loadingStats`)})});let te=[{id:`quick-stats`,title:e(`stats.quickStats`),component:(0,G.jsx)(aVe,{stats:E,currency:B}),defaultSize:2},{id:`success-rate`,title:e(`stats.successRate`),component:e=>(0,G.jsx)(oVe,{stats:E,printerMap:V,size:e}),defaultSize:1},{id:`time-accuracy`,title:e(`stats.timeAccuracy`),component:e=>(0,G.jsx)(sVe,{stats:E,printerMap:V,size:e}),defaultSize:1},{id:`failure-analysis`,title:e(`stats.failureAnalysis`),component:e=>(0,G.jsx)(fVe,{size:e,dateFrom:w.dateFrom,dateTo:w.dateTo,createdById:T}),defaultSize:1},{id:`print-activity`,title:e(`stats.printActivity`),component:e=>(0,G.jsx)(lVe,{printDates:ee,size:e,dateFrom:w.dateFrom,dateTo:w.dateTo}),defaultSize:2},{id:`records`,title:e(`stats.records`),component:(0,G.jsx)(pVe,{archives:j||[],currency:B}),defaultSize:1},{id:`printer-stats`,title:e(`stats.printerStats`),component:(0,G.jsx)(uVe,{stats:E,archives:j||[],printerMap:V}),defaultSize:4},{id:`filament-trends`,title:e(`stats.filamentTrends`),component:(0,G.jsx)(dVe,{archives:j||[],currency:B,dateFrom:w.dateFrom,dateTo:w.dateTo}),defaultSize:4}];return(0,G.jsxs)(`div`,{className:`p-4 md:p-8`,children:[(0,G.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4 mb-6`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,G.jsx)(as,{className:`w-7 h-7 text-bambu-green`}),e(`stats.title`)]}),z&&(0,G.jsx)(Y,{className:`w-5 h-5 text-bambu-green animate-spin`})]}),(0,G.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:e(`stats.subtitle`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[u>0&&(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>{window.dispatchEvent(new CustomEvent(`toggle-hidden-panel`))},children:[(0,G.jsx)(rc,{className:`w-4 h-4`}),e(`stats.hiddenCount`,{count:u})]}),(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>{localStorage.removeItem(`bambusy-dashboard-layout-v2`),l(e=>e+1),t(e(`stats.layoutReset`))},disabled:!n(`settings:update`),title:n(`settings:update`)?void 0:e(`stats.noPermissionResetLayout`),children:[(0,G.jsx)(Vl,{className:`w-4 h-4`}),e(`stats.resetLayout`)]}),(0,G.jsxs)(Q,{variant:`secondary`,onClick:R,disabled:f||!n(`archives:update_all`),title:n(`archives:update_all`)?e(`stats.recalculateCostsHint`):e(`stats.noPermissionRecalculate`),children:[f?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(es,{className:`w-4 h-4`}),e(`stats.recalculateCosts`)]}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>s(!o),disabled:i,children:[i?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(cc,{className:`w-4 h-4`}),e(`stats.exportStats`)]}),o&&(0,G.jsxs)(`div`,{className:`absolute right-0 top-full mt-1 w-48 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl z-20`,children:[(0,G.jsxs)(`button`,{className:`w-full px-4 py-2 text-left text-white hover:bg-bambu-dark-tertiary transition-colors flex items-center gap-2 rounded-t-lg`,onClick:()=>L(`csv`),children:[(0,G.jsx)(lc,{className:`w-4 h-4`}),e(`stats.exportAsCsv`)]}),(0,G.jsxs)(`button`,{className:`w-full px-4 py-2 text-left text-white hover:bg-bambu-dark-tertiary transition-colors flex items-center gap-2 rounded-b-lg`,onClick:()=>L(`xlsx`),children:[(0,G.jsx)(cc,{className:`w-4 h-4`}),e(`stats.exportAsExcel`)]})]})]}),v&&F&&F.length>0&&(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>_(!g),children:[(0,G.jsx)(Bu,{className:`w-4 h-4`}),I,(0,G.jsx)(ds,{className:`w-3 h-3`})]}),g&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`fixed inset-0 z-10`,onClick:()=>_(!1)}),(0,G.jsxs)(`div`,{className:`absolute right-0 top-full mt-1 w-48 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl z-20 p-2 max-h-64 overflow-y-auto`,children:[(0,G.jsx)(`button`,{className:`w-full px-3 py-2 text-left text-sm rounded-md transition-colors ${m===null?`bg-bambu-green text-white`:`text-white hover:bg-bambu-dark-tertiary`}`,onClick:()=>{h(null),_(!1)},children:e(`stats.allUsers`,`All Users`)}),(0,G.jsx)(`button`,{className:`w-full px-3 py-2 text-left text-sm rounded-md transition-colors ${m===-1?`bg-bambu-green text-white`:`text-white hover:bg-bambu-dark-tertiary`}`,onClick:()=>{h(-1),_(!1)},children:e(`stats.noUser`,`No User (System)`)}),(0,G.jsx)(`div`,{className:`border-t border-bambu-dark-tertiary my-1`}),F.map(e=>(0,G.jsx)(`button`,{className:`w-full px-3 py-2 text-left text-sm rounded-md transition-colors ${m===e.id?`bg-bambu-green text-white`:`text-white hover:bg-bambu-dark-tertiary`}`,onClick:()=>{h(e.id),_(!1)},children:e.username},e.id))]})]})]}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>C(!S),children:[(0,G.jsx)(rs,{className:`w-4 h-4`}),e(`stats.timeframe.${b.preset}`),(0,G.jsx)(ds,{className:`w-3 h-3`})]}),S&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`fixed inset-0 z-10`,onClick:()=>C(!1)}),(0,G.jsxs)(`div`,{className:`absolute right-0 top-full mt-1 w-64 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl z-20 p-2`,children:[rVe.map(t=>(0,G.jsx)(`button`,{className:`w-full px-3 py-2 text-left text-sm rounded-md transition-colors ${b.preset===t?`bg-bambu-green text-white`:`text-white hover:bg-bambu-dark-tertiary`}`,onClick:()=>{x({preset:t,dateFrom:void 0,dateTo:void 0}),C(!1)},children:e(`stats.timeframe.${t}`)},t)),(0,G.jsx)(`div`,{className:`border-t border-bambu-dark-tertiary my-2`}),(0,G.jsx)(`button`,{className:`w-full px-3 py-2 text-left text-sm rounded-md transition-colors ${b.preset===`custom`?`bg-bambu-green text-white`:`text-white hover:bg-bambu-dark-tertiary`}`,onClick:()=>x(e=>({...e,preset:`custom`})),children:e(`stats.timeframe.custom`)}),b.preset===`custom`&&(0,G.jsxs)(`div`,{className:`mt-2 px-1 pb-1 space-y-2`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`text-xs text-bambu-gray block mb-1`,children:e(`stats.timeframe.from`)}),(0,G.jsx)(`input`,{type:`date`,value:b.dateFrom||``,max:b.dateTo||new Date().toISOString().split(`T`)[0],onChange:e=>x(t=>({...t,dateFrom:e.target.value||void 0})),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded-md px-3 py-1.5 text-sm text-white [color-scheme:dark]`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`text-xs text-bambu-gray block mb-1`,children:e(`stats.timeframe.to`)}),(0,G.jsx)(`input`,{type:`date`,value:b.dateTo||``,min:b.dateFrom,max:new Date().toISOString().split(`T`)[0],onChange:e=>x(t=>({...t,dateTo:e.target.value||void 0})),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded-md px-3 py-1.5 text-sm text-white [color-scheme:dark]`})]}),(0,G.jsx)(Q,{variant:`primary`,onClick:()=>C(!1),className:`w-full`,children:e(`common.apply`)})]})]})]})]})]})]}),(0,G.jsx)(tVe,{widgets:te,storageKey:`bambusy-dashboard-layout-v2`,stackBelow:640,hideControls:!0},c)]})}function N3(e){return e.length<8?`tooShort`:/[A-Z]/.test(e)?/[a-z]/.test(e)?/\d/.test(e)?/[^A-Za-z0-9]/.test(e)?null:`needsSpecial`:`needsDigit`:`needsLowercase`:`needsUppercase`}var P3={PLA:0,PETG:0,"PETG-CF":40,ABS:45,ASA:45,PA:50,"PA-CF":55,PC:50,"PC-FR":50,TPU:0,PVA:0,default:0},F3=[`PA-CF`,`PA`,`PC`,`PC-FR`,`ABS`,`ASA`,`PETG-CF`,`PETG`,`PLA`,`TPU`,`PVA`,`default`];function hVe(e){if(!e)return{...P3};try{let t=JSON.parse(e);if(t&&typeof t==`object`&&!Array.isArray(t)){let e={};for(let[n,r]of Object.entries(t)){let t=typeof r==`number`?r:Number(r);Number.isFinite(t)&&(e[n]=Math.max(0,Math.min(65,Math.round(t))))}return e.default===void 0&&(e.default=P3.default),e}}catch{}return{...P3}}function gVe(e){let t={};for(let n of F3)e[n]!==void 0&&(t[n]=e[n]);for(let[n,r]of Object.entries(e))n in t||(t[n]=r);return JSON.stringify(t)}function _Ve({value:e,onChange:t,disabled:n=!1}){let{t:r}=U(),i=hVe(e),a=(e,n)=>{let r=Math.max(0,Math.min(65,Math.round(n)));t(gVe({...i,[e]:r}))};return(0,G.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-x-3 gap-y-1.5`,children:F3.map(e=>{let t=i[e]??P3[e]??0,o=e==="default"?r(`settings.preheatFilamentTargetsDefaultRow`,`Other / unmapped`):e;return(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,G.jsx)(`span`,{className:`text-xs ${e==="default"?`text-bambu-gray italic`:`text-bambu-gray`}`,children:o}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(`input`,{type:`number`,min:0,max:65,step:1,value:t,onChange:t=>a(e,parseInt(t.target.value,10)||0),disabled:n,className:`w-16 px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-xs text-right focus:outline-none focus:border-bambu-green disabled:opacity-50`}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:`°C`})]})]},e)})})}function vVe(){let{t:e}=U();return(0,G.jsxs)(Md,{children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(xl,{className:`w-4 h-4 text-bambu-gray`}),e(`settings.slicerBundlesRemoved.title`,{defaultValue:`Slicer Bundles (removed)`})]})}),(0,G.jsxs)(Pd,{className:`space-y-2`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`settings.slicerBundlesRemoved.description`,{defaultValue:`Printer Preset Bundle (.bbscfg) import was removed. BambuStudio's bundle export only includes user-customised presets, so the import never delivered standard processes / filaments and slicing fell back to embedded settings.`})}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`settings.slicerBundlesRemoved.alternatives`,{defaultValue:`Use Single Preset Import for individual customs, or sync via Bambu Cloud / Orca Cloud. Stock presets come from the slicer sidecar automatically.`})}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`settings.slicerBundlesRemoved.lookupOrder`,{defaultValue:`Slice-time preset lookup order: 1) Imported (local), 2) Orca Cloud, 3) Bambu Cloud, 4) Standard (sidecar fallback).`})})]})]})}function I3(e,t,n){if(!e)return null;let r=(e[n.source]?.[t]??[]).find(e=>e.id===n.id);return r?r.name:null}var yVe={orca_cloud:`Orca Cloud`,cloud:`Bambu Cloud`,local:`Imported`,standard:`Standard`};function bVe(){let{t:e}=U(),t=so(),{showToast:n}=Bd(),{data:r,isLoading:i,error:a}=K({queryKey:[`slicer-pipelines`],queryFn:()=>Z.listSlicerPipelines()}),{data:o}=K({queryKey:[`slicer-presets`],queryFn:()=>Z.getSlicerPresets()}),{data:s}=K({queryKey:[`printers`],queryFn:()=>Z.getPrinters()}),c=q({mutationFn:({id:e,name:t,description:n,target_printer_id:r,target_kind:i,target_model_class:a,fanout_strategy:o})=>Z.updateSlicerPipeline(e,{name:t,description:n,target_printer_id:r,target_kind:i,target_model_class:a,fanout_strategy:o}),onSuccess:()=>{t.invalidateQueries({queryKey:[`slicer-pipelines`]}),n(e(`settings.pipelines.toast.saved`,`Pipeline saved`),`success`)},onError:t=>{n(t.message||e(`settings.pipelines.toast.saveFailed`,`Save failed`),`error`)}}),l=q({mutationFn:e=>Z.deleteSlicerPipeline(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`slicer-pipelines`]}),n(e(`settings.pipelines.toast.deleted`,`Pipeline deleted`),`success`)},onError:t=>{n(t.message||e(`settings.pipelines.toast.deleteFailed`,`Delete failed`),`error`)}}),[u,d]=(0,y.useState)(``),[f,p]=(0,y.useState)(``),m=(0,y.useMemo)(()=>r?.pipelines??[],[r?.pipelines]),h=(0,y.useMemo)(()=>{let e=new Set,t=new Set,n=!1;for(let r of m)r.target_kind===`printer_class`&&r.target_model_class?t.add(r.target_model_class):r.target_printer_id?e.add(r.target_printer_id):n=!0;return{printers:(s??[]).filter(t=>e.has(t.id)),classes:Array.from(t).sort(),anyWithoutTarget:n}},[m,s]),g=(0,y.useMemo)(()=>{let e=u.trim().toLowerCase();return m.filter(t=>{if(e&&!t.name.toLowerCase().includes(e))return!1;if(f===`none`){if(t.target_kind===`printer_class`?t.target_model_class:t.target_printer_id!==null)return!1}else if(f.startsWith(`p:`)){let e=parseInt(f.slice(2),10);if(t.target_kind===`printer_class`||t.target_printer_id!==e)return!1}else if(f.startsWith(`c:`)){let e=f.slice(2);if(t.target_kind!==`printer_class`||t.target_model_class!==e)return!1}return!0})},[m,u,f]);return(0,G.jsxs)(Md,{children:[(0,G.jsxs)(Nd,{children:[(0,G.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(Zu,{className:`w-4 h-4 text-bambu-green`}),e(`settings.pipelines.title`,`Slicer Pipelines`)]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`settings.pipelines.subtitle`,`Reusable preset bundles (printer + process + filaments + bed type). Save one from the Slice dialog and apply it with a single click on the next file.`)})]}),(0,G.jsxs)(Pd,{children:[i&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-bambu-gray`,children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),e(`settings.pipelines.loading`,`Loading pipelines…`)]}),a&&(0,G.jsx)(`div`,{className:`text-sm text-red-700 dark:text-red-400`,children:e(`settings.pipelines.loadError`,`Could not load pipelines.`)}),!i&&!a&&m.length>0&&(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 mb-3`,children:[(0,G.jsxs)(`div`,{className:`relative flex-1 min-w-[12rem]`,children:[(0,G.jsx)(Yl,{className:`absolute left-2 top-1/2 -translate-y-1/2 w-3.5 h-3.5 text-bambu-gray pointer-events-none`}),(0,G.jsx)(`input`,{type:`search`,value:u,onChange:e=>d(e.target.value),placeholder:e(`settings.pipelines.searchPlaceholder`,`Search pipelines…`),"aria-label":e(`settings.pipelines.searchPlaceholder`,`Search pipelines…`),className:`w-full pl-7 pr-2 py-1 text-xs bg-bambu-dark border border-bambu-dark-tertiary rounded text-white`})]}),(0,G.jsxs)(`select`,{value:f,onChange:e=>p(e.target.value),"aria-label":e(`settings.pipelines.filterTarget`,`Filter by target`),className:`text-xs px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white`,children:[(0,G.jsx)(`option`,{value:``,children:e(`settings.pipelines.filter.all`,`All targets`)}),h.printers.length>0&&(0,G.jsx)(`optgroup`,{label:e(`settings.pipelines.field.targetKindSpecific`,`Specific printer`),children:h.printers.map(e=>(0,G.jsx)(`option`,{value:`p:${e.id}`,children:e.name},`p-${e.id}`))}),h.classes.length>0&&(0,G.jsx)(`optgroup`,{label:e(`settings.pipelines.field.targetKindClass`,`Printer class`),children:h.classes.map(t=>(0,G.jsx)(`option`,{value:`c:${t}`,children:e(`library.runWithPipeline.classTarget`,`Any {{model}}`,{model:t})},`c-${t}`))}),h.anyWithoutTarget&&(0,G.jsx)(`option`,{value:`none`,children:e(`settings.pipelines.filter.noTarget`,`No target set`)})]}),(u||f)&&(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:e(`settings.pipelines.filter.count`,`{{shown}} / {{total}}`,{shown:g.length,total:m.length})})]}),!i&&!a&&m.length===0&&(0,G.jsxs)(`div`,{className:`text-sm text-bambu-gray space-y-2`,children:[(0,G.jsx)(`p`,{children:e(`settings.pipelines.empty.title`,`No pipelines yet.`)}),(0,G.jsx)(`p`,{children:e(`settings.pipelines.empty.howto`,`Open the Slice dialog for any file, pick your printer / process / filaments / bed type, then click "Save as pipeline". Your saved pipelines will appear here.`)})]}),!i&&!a&&m.length>0&&g.length===0&&(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`settings.pipelines.filter.noMatches`,`No pipelines match the current filters.`)}),!i&&!a&&g.length>0&&(0,G.jsx)(`div`,{className:`space-y-2`,children:g.map(t=>(0,G.jsx)(xVe,{pipeline:t,presets:o,printers:s??[],onSave:e=>c.mutate({id:t.id,...e}),onDelete:()=>{confirm(e(`settings.pipelines.confirmDelete`,`Delete this pipeline? This cannot be undone.`))&&l.mutate(t.id)},saving:c.isPending,deleting:l.isPending},t.id))})]})]})}function xVe({pipeline:e,presets:t,printers:n,onSave:r,onDelete:i,saving:a,deleting:o}){let{t:s}=U(),[c,l]=(0,y.useState)(!1),[u,d]=(0,y.useState)(e.name),[f,p]=(0,y.useState)(e.description??``),[m,h]=(0,y.useState)(e.target_printer_id),[g,_]=(0,y.useState)(e.target_kind===`printer_class`?`printer_class`:`specific_printer`),[v,b]=(0,y.useState)(e.target_model_class??``),[x,S]=(0,y.useState)(e.fanout_strategy??`max_parallel`),C=Array.from(new Set(n.map(e=>e.model).filter(e=>!!e))).sort(),{data:w}=K({queryKey:[`pipeline-runs`,e.id],queryFn:()=>Z.listPipelineRuns(e.id,1),enabled:!c,refetchInterval:15e3}),T=w?.runs?.[0],E=I3(t,`printer`,e.printer_preset),D=I3(t,`process`,e.process_preset),O=e.filament_presets.map(e=>I3(t,`filament`,e)),k=e.filament_presets.length>1&&e.filament_presets.every(t=>t.source===e.filament_presets[0].source&&t.id===e.filament_presets[0].id),A=t!==void 0&&(E===null||D===null||O.some(e=>e===null)),j=e.target_printer_id?n.find(t=>t.id===e.target_printer_id):void 0,M=e.target_kind===`printer_class`,N=M?!e.target_model_class:e.target_printer_id===null;return(0,G.jsxs)(`div`,{className:`rounded-md border border-bambu-dark-tertiary bg-bambu-dark/40 px-3 py-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,G.jsx)(`div`,{className:`min-w-0 flex-1`,children:c?(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`input`,{value:u,onChange:e=>d(e.target.value),"aria-label":s(`settings.pipelines.field.name`,`Pipeline name`),placeholder:s(`settings.pipelines.field.name`,`Pipeline name`),className:`w-full px-2 py-1 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded text-white`}),(0,G.jsx)(`textarea`,{value:f,onChange:e=>p(e.target.value),"aria-label":s(`settings.pipelines.field.description`,`Description`),placeholder:s(`settings.pipelines.field.description`,`Description`),rows:2,className:`w-full px-2 py-1 text-xs bg-bambu-dark border border-bambu-dark-tertiary rounded text-white`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`text-xs text-bambu-gray block mb-1`,children:s(`settings.pipelines.field.targetKind`,`Target type`)}),(0,G.jsxs)(`div`,{className:`flex gap-3 text-xs`,children:[(0,G.jsxs)(`label`,{className:`flex items-center gap-1 text-white`,children:[(0,G.jsx)(`input`,{type:`radio`,name:`target-kind-${e.id}`,value:`specific_printer`,checked:g===`specific_printer`,onChange:()=>_(`specific_printer`),"aria-label":s(`settings.pipelines.field.targetKindSpecific`,`Specific printer`)}),s(`settings.pipelines.field.targetKindSpecific`,`Specific printer`)]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-1 text-white`,children:[(0,G.jsx)(`input`,{type:`radio`,name:`target-kind-${e.id}`,value:`printer_class`,checked:g===`printer_class`,onChange:()=>_(`printer_class`),"aria-label":s(`settings.pipelines.field.targetKindClass`,`Printer class`)}),s(`settings.pipelines.field.targetKindClass`,`Printer class`)]})]})]}),g===`specific_printer`?(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`text-xs text-bambu-gray block mb-1`,children:s(`settings.pipelines.field.targetPrinter`,`Target printer`)}),(0,G.jsxs)(`select`,{value:m??``,onChange:e=>h(e.target.value?parseInt(e.target.value,10):null),"aria-label":s(`settings.pipelines.field.targetPrinter`,`Target printer`),className:`w-full px-2 py-1 text-xs bg-bambu-dark border border-bambu-dark-tertiary rounded text-white`,children:[(0,G.jsx)(`option`,{value:``,children:s(`settings.pipelines.field.noTarget`,`— No target —`)}),n.map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}):(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`text-xs text-bambu-gray block mb-1`,children:s(`settings.pipelines.field.targetModelClass`,`Printer model`)}),(0,G.jsxs)(`select`,{value:v,onChange:e=>b(e.target.value),"aria-label":s(`settings.pipelines.field.targetModelClass`,`Printer model`),className:`w-full px-2 py-1 text-xs bg-bambu-dark border border-bambu-dark-tertiary rounded text-white`,children:[(0,G.jsx)(`option`,{value:``,children:s(`settings.pipelines.field.noTarget`,`— No target —`)}),C.map(e=>(0,G.jsx)(`option`,{value:e,children:e},e))]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`text-xs text-bambu-gray block mb-1`,children:s(`settings.pipelines.field.fanoutStrategy`,`Fanout strategy`)}),(0,G.jsxs)(`select`,{value:x,onChange:e=>S(e.target.value),"aria-label":s(`settings.pipelines.field.fanoutStrategy`,`Fanout strategy`),className:`w-full px-2 py-1 text-xs bg-bambu-dark border border-bambu-dark-tertiary rounded text-white`,children:[(0,G.jsx)(`option`,{value:`max_parallel`,children:s(`settings.pipelines.field.fanout.max_parallel`,`Max parallel — distribute across any idle matching printer`)}),(0,G.jsx)(`option`,{value:`round_robin`,children:s(`settings.pipelines.field.fanout.round_robin`,`Round robin — cycle through eligible printers`)}),(0,G.jsx)(`option`,{value:`fill_one_first`,children:s(`settings.pipelines.field.fanout.fill_one_first`,`Fill one first — pin all copies to one printer`)})]})]})]})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2 gap-y-1`,children:[(0,G.jsx)(`h4`,{className:`text-sm font-medium text-white truncate`,children:e.name}),(0,G.jsxs)(`span`,{className:`text-xs px-1.5 py-0.5 rounded inline-flex items-center gap-1 ${N?`bg-amber-100 dark:bg-amber-500/15 text-amber-700 dark:text-amber-400`:`bg-bambu-dark-tertiary text-bambu-gray`}`,children:[(0,G.jsx)(Fl,{className:`w-3 h-3`}),N?s(`settings.pipelines.noTargetHint`,`Set a target printer to run this`):M?(0,G.jsxs)(G.Fragment,{children:[s(`library.runWithPipeline.classTarget`,`Any {{model}}`,{model:e.target_model_class}),e.fanout_strategy&&(0,G.jsxs)(`span`,{className:`text-bambu-gray/60`,children:[` · `,s(`settings.pipelines.field.fanoutShort.${e.fanout_strategy}`,e.fanout_strategy)]})]}):j?.name??``]})]}),e.description&&(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:e.description})]})}),(0,G.jsx)(`div`,{className:`flex items-center gap-1 flex-shrink-0`,children:c?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`button`,{onClick:()=>{let e=u.trim();e&&(r({name:e,description:f.trim()||null,target_kind:g,target_printer_id:g===`specific_printer`?m??0:0,target_model_class:g===`printer_class`&&v||null,fanout_strategy:x}),l(!1))},disabled:a||!u.trim(),"aria-label":s(`settings.pipelines.action.save`,`Save`),className:`p-1.5 text-bambu-green hover:bg-bambu-dark-tertiary rounded disabled:opacity-50`,children:(0,G.jsx)(us,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:()=>{d(e.name),p(e.description??``),h(e.target_printer_id),_(e.target_kind===`printer_class`?`printer_class`:`specific_printer`),b(e.target_model_class??``),S(e.fanout_strategy??`max_parallel`),l(!1)},"aria-label":s(`settings.pipelines.action.cancel`,`Cancel`),className:`p-1.5 text-bambu-gray hover:bg-bambu-dark-tertiary rounded`,children:(0,G.jsx)($u,{className:`w-4 h-4`})})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`button`,{onClick:()=>l(!0),"aria-label":s(`settings.pipelines.action.rename`,`Rename`),className:`p-1.5 text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary rounded`,children:(0,G.jsx)(Dl,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:i,disabled:o,"aria-label":s(`settings.pipelines.action.delete`,`Delete`),className:`p-1.5 text-bambu-gray hover:text-red-600 dark:hover:text-red-400 hover:bg-bambu-dark-tertiary rounded disabled:opacity-50`,children:(0,G.jsx)(ju,{className:`w-4 h-4`})})]})})]}),!c&&(0,G.jsxs)(`div`,{className:`mt-2 grid grid-cols-1 md:grid-cols-2 gap-x-4 gap-y-2 text-xs`,children:[(0,G.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,G.jsx)(`div`,{className:`text-[10px] uppercase tracking-wide text-bambu-gray/60`,children:s(`settings.pipelines.group.profiles`,`Profiles`)}),(0,G.jsx)(L3,{label:s(`settings.pipelines.slot.printer`,`Printer`),ref:e.printer_preset,name:E}),(0,G.jsx)(L3,{label:s(`settings.pipelines.slot.process`,`Process`),ref:e.process_preset,name:D}),e.bed_type&&(0,G.jsxs)(`div`,{className:`text-bambu-gray`,children:[(0,G.jsxs)(`span`,{className:`font-medium text-bambu-gray/80`,children:[s(`settings.pipelines.slot.bed`,`Bed`),`:`]}),` `,(0,G.jsx)(`span`,{className:`text-white`,children:e.bed_type})]})]}),(0,G.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,G.jsxs)(`div`,{className:`text-[10px] uppercase tracking-wide text-bambu-gray/60`,children:[s(`settings.pipelines.group.filaments`,`Filaments`),e.filament_presets.length>1&&(0,G.jsxs)(`span`,{className:`text-bambu-gray/60 normal-case ml-1`,children:[`(`,e.filament_presets.length,`)`]})]}),k?(0,G.jsx)(L3,{label:s(`settings.pipelines.slot.filamentAll`,`All {{n}} slots`,{n:e.filament_presets.length}),ref:e.filament_presets[0],name:O[0]}):e.filament_presets.map((t,n)=>(0,G.jsx)(L3,{label:e.filament_presets.length>1?s(`settings.pipelines.slot.filamentN`,`Filament {{n}}`,{n:n+1}):s(`settings.pipelines.slot.filament`,`Filament`),ref:t,name:O[n]},n))]})]}),!c&&T&&(0,G.jsxs)(`div`,{className:`mt-1.5 text-xs text-bambu-gray flex items-center gap-1`,children:[(0,G.jsxs)(`span`,{className:`font-medium text-bambu-gray/80`,children:[s(`settings.pipelines.runs.lastRun`,`Last run`),`:`]}),` `,(0,G.jsx)(SVe,{status:T.status}),T.created_at&&(0,G.jsxs)(`span`,{className:`text-bambu-gray/60`,children:[`· `,new Date(T.created_at).toLocaleString()]})]}),N&&!c&&(0,G.jsxs)(`div`,{className:`mt-2 flex items-center gap-1.5 text-xs text-amber-700 dark:text-amber-400`,children:[(0,G.jsx)(Pu,{className:`w-3.5 h-3.5`}),s(`settings.pipelines.noTargetWarning`,`Set a target printer before running this pipeline.`)]}),A&&!c&&(0,G.jsxs)(`div`,{className:`mt-2 flex items-center gap-1.5 text-xs text-amber-700 dark:text-amber-400`,children:[(0,G.jsx)(Pu,{className:`w-3.5 h-3.5`}),s(`settings.pipelines.staleWarning`,`One or more referenced presets no longer exist. Re-save this pipeline from the Slice dialog to fix.`)]})]})}function SVe({status:e}){let{t}=U();return(0,G.jsx)(`span`,{className:{queued:`text-bambu-gray`,slicing:`text-blue-700 dark:text-blue-400`,dispatching:`text-blue-700 dark:text-blue-400`,in_progress:`text-bambu-green`,completed:`text-bambu-green`,failed:`text-red-700 dark:text-red-400`,partial_failure:`text-amber-700 dark:text-amber-400`,cancelled:`text-bambu-gray`}[e],children:t(`settings.pipelines.runs.status.${e}`,e)})}function L3({label:e,ref:t,name:n}){return(0,G.jsxs)(`div`,{className:`text-bambu-gray truncate`,children:[(0,G.jsxs)(`span`,{className:`font-medium text-bambu-gray/80`,children:[e,`:`]}),` `,n?(0,G.jsx)(`span`,{className:`text-white`,children:n}):(0,G.jsxs)(`span`,{className:`text-amber-700 dark:text-amber-400`,children:[`[`,yVe[t.source],` #`,t.id,`]`]})]})}var R3=90,z3=365;function B3(e){if(!e)return`—`;let t=Kf(e);return t?t.toLocaleString():`—`}function CVe(e){let t=Kf(e);return t?t.getTime(){if(l.preventDefault(),r.trim()){u(!0);try{e(await Z.createLongLivedCameraToken({name:r.trim(),expires_in_days:a,scope:s})),i(``),o(R3),c(`camera_stream`),n(t(`cameraTokens.toast.created`,`Token created`))}catch(e){n(e instanceof Error?e.message:t(`cameraTokens.toast.createFailed`,`Failed to create token`),`error`)}finally{u(!1)}}},className:`bg-bambu-dark-secondary rounded-lg p-4 mb-6 border border-bambu-dark-tertiary`,children:[(0,G.jsx)(`h3`,{className:`text-base font-semibold text-white mb-3`,children:t(`cameraTokens.create.title`,`Create new token`)}),(0,G.jsxs)(`div`,{className:`grid gap-3 md:grid-cols-[1fr_180px_140px_auto]`,children:[(0,G.jsx)(`input`,{type:`text`,maxLength:100,required:!0,value:r,onChange:e=>i(e.target.value),placeholder:t(`cameraTokens.create.namePlaceholder`,`e.g. Home Assistant`),className:`px-3 py-2 bg-bambu-dark rounded-md text-white border border-bambu-dark-tertiary focus:border-bambu-green focus:outline-none`,"aria-label":t(`cameraTokens.create.nameLabel`,`Token name`)}),(0,G.jsxs)(`select`,{value:s,onChange:e=>c(e.target.value),className:`px-3 py-2 bg-bambu-dark rounded-md text-white border border-bambu-dark-tertiary focus:border-bambu-green focus:outline-none`,"aria-label":t(`cameraTokens.create.scopeLabel`,`Scope`),children:[(0,G.jsx)(`option`,{value:`camera_stream`,children:t(`cameraTokens.scope.camera_stream`,`Camera stream`)}),(0,G.jsx)(`option`,{value:`camwall`,children:t(`cameraTokens.scope.camwall`,`Cam Wall`)}),(0,G.jsx)(`option`,{value:`overlay`,children:t(`cameraTokens.scope.overlay`,`Streaming Overlay`)})]}),(0,G.jsx)(`input`,{type:`number`,min:1,max:z3,required:!0,value:a,onChange:e=>{let t=Number(e.target.value);o(Math.min(Math.max(t,1),z3))},className:`px-3 py-2 bg-bambu-dark rounded-md text-white border border-bambu-dark-tertiary focus:border-bambu-green focus:outline-none`,"aria-label":t(`cameraTokens.create.daysLabel`,`Days until expiry`)}),(0,G.jsxs)(`button`,{type:`submit`,disabled:l||!r.trim(),className:`flex items-center gap-2 px-4 py-2 bg-bambu-green text-white rounded-md hover:bg-bambu-green/90 disabled:opacity-50 disabled:cursor-not-allowed`,children:[(0,G.jsx)(Ml,{className:`w-4 h-4`}),t(`cameraTokens.create.submit`,`Create`)]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-2`,children:s===`camwall`?t(`cameraTokens.create.hintCamWall`,`A Cam Wall token opens /camwall on a screen with no login — it can see every printer's name and state, and their camera streams. It cannot see filenames, addresses or access codes.`):s===`overlay`?t(`cameraTokens.create.hintOverlay`,`A Streaming Overlay token opens /overlay/{printerId} on a screen with no login — for OBS or any live stream. It can see one printer's camera stream plus its live print status, including the filename shown on screen. It cannot see addresses or access codes.`):t(`cameraTokens.create.hintCameraStream`,`A camera-stream token can only fetch camera streams and snapshots. Use it for Home Assistant, Frigate, or anything embedding a single camera.`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:t(`cameraTokens.create.hint`,`Maximum lifetime is 365 days. The token value is shown only once on creation — copy it now.`)})]})}function TVe({token:e,onConfirm:t,onCancel:n}){let{t:r}=U();return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/60 flex items-center justify-center z-50 p-4`,role:`dialog`,"aria-modal":`true`,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg p-6 max-w-md w-full border border-red-500/40`,children:[(0,G.jsxs)(`div`,{className:`flex items-start gap-3 mb-4`,children:[(0,G.jsx)(Pu,{className:`w-6 h-6 text-red-600 dark:text-red-400 flex-shrink-0 mt-0.5`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:r(`cameraTokens.confirmRevoke.title`,`Revoke this token?`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:r(`cameraTokens.confirmRevoke.body`,`Any device using "{{name}}" will lose access immediately. This cannot be undone.`,{name:e.name})})]})]}),(0,G.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,G.jsx)(`button`,{type:`button`,onClick:n,className:`px-4 py-2 bg-bambu-dark-tertiary text-white rounded-md hover:bg-bambu-dark-tertiary/80`,children:r(`cameraTokens.confirmRevoke.cancel`,`Cancel`)}),(0,G.jsx)(`button`,{type:`button`,onClick:t,className:`px-4 py-2 bg-red-500 text-white rounded-md hover:bg-red-600`,children:r(`cameraTokens.confirmRevoke.confirm`,`Revoke`)})]})]})})}function EVe({token:e,onClose:t}){let{t:n}=U(),{showToast:r}=Bd(),i=e.token??``,a=e.scope===`camwall`&&i?`${window.location.origin}/camwall?token=${encodeURIComponent(i)}`:null,o=e.scope===`overlay`&&i?`${window.location.origin}/overlay/1?token=${encodeURIComponent(i)}`:null,s=async e=>{if(e)try{if(navigator.clipboard&&window.isSecureContext)await navigator.clipboard.writeText(e);else{let t=document.createElement(`textarea`);t.value=e,t.style.position=`fixed`,t.style.opacity=`0`,document.body.appendChild(t);try{t.select(),document.execCommand(`copy`)}finally{document.body.removeChild(t)}}r(n(`cameraTokens.toast.copied`,`Copied to clipboard`))}catch{r(n(`cameraTokens.toast.copyFailed`,`Copy failed — select and copy manually`),`error`)}};return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/60 flex items-center justify-center z-50 p-4`,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg p-6 max-w-2xl w-full border border-bambu-green/40`,children:[(0,G.jsxs)(`div`,{className:`flex items-start gap-3 mb-4`,children:[(0,G.jsx)(Pu,{className:`w-6 h-6 text-yellow-600 dark:text-yellow-400 flex-shrink-0 mt-0.5`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:n(`cameraTokens.created.title`,`Token created — copy it now`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:n(`cameraTokens.created.warning`,`This is the only time this token will be visible. After you close this dialog you can never view it again.`)})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-4`,children:[(0,G.jsx)(`code`,{className:`flex-1 px-3 py-2 bg-bambu-dark rounded-md text-bambu-green text-xs break-all font-mono select-all`,children:i}),(0,G.jsxs)(`button`,{type:`button`,onClick:()=>s(i),className:`flex items-center gap-2 px-3 py-2 bg-bambu-green text-white rounded-md hover:bg-bambu-green/90`,children:[(0,G.jsx)(zs,{className:`w-4 h-4`}),n(`cameraTokens.created.copy`,`Copy`)]})]}),a&&(0,G.jsxs)(`div`,{className:`mb-4`,children:[(0,G.jsx)(`p`,{className:`text-sm font-medium text-white mb-1`,children:n(`cameraTokens.created.camWallUrlTitle`,`Cam Wall URL for this display`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:n(`cameraTokens.created.camWallUrlHint`,`Open this on the screen. Anyone who can read the URL can watch the wall, so treat it like a key — revoke the token to cut the display off.`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`code`,{className:`flex-1 px-3 py-2 bg-bambu-dark rounded-md text-bambu-green text-xs break-all font-mono select-all`,children:a}),(0,G.jsxs)(`button`,{type:`button`,onClick:()=>s(a),className:`flex items-center gap-2 px-3 py-2 bg-bambu-green text-white rounded-md hover:bg-bambu-green/90`,children:[(0,G.jsx)(zs,{className:`w-4 h-4`}),n(`cameraTokens.created.copy`,`Copy`)]})]})]}),o&&(0,G.jsxs)(`div`,{className:`mb-4`,children:[(0,G.jsx)(`p`,{className:`text-sm font-medium text-white mb-1`,children:n(`cameraTokens.created.overlayUrlTitle`,`Overlay URL for OBS`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:n(`cameraTokens.created.overlayUrlHint`,`Add this as a Browser Source in OBS. Change the /overlay/1 number to your printer's number (from its URL on the Printers page). Anyone who can read the URL can watch the stream, so treat it like a key — revoke the token to cut it off.`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`code`,{className:`flex-1 px-3 py-2 bg-bambu-dark rounded-md text-bambu-green text-xs break-all font-mono select-all`,children:o}),(0,G.jsxs)(`button`,{type:`button`,onClick:()=>s(o),className:`flex items-center gap-2 px-3 py-2 bg-bambu-green text-white rounded-md hover:bg-bambu-green/90`,children:[(0,G.jsx)(zs,{className:`w-4 h-4`}),n(`cameraTokens.created.copy`,`Copy`)]})]})]}),(0,G.jsx)(`div`,{className:`flex justify-end`,children:(0,G.jsx)(`button`,{type:`button`,onClick:t,className:`px-4 py-2 bg-bambu-dark-tertiary text-white rounded-md hover:bg-bambu-dark-tertiary/80`,children:n(`cameraTokens.created.dismiss`,`I've saved it`)})})]})})}function DVe({token:e,showOwner:t,ownerLabel:n,onRevoke:r}){let{t:i}=U(),a=CVe(e.expires_at);return(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary last:border-b-0`,children:[(0,G.jsx)(`td`,{className:`py-3 px-3 text-white`,children:e.name}),t&&(0,G.jsx)(`td`,{className:`py-3 px-3 text-bambu-gray`,children:n}),(0,G.jsx)(`td`,{className:`py-3 px-3`,children:(0,G.jsx)(`span`,{className:`rounded bg-bambu-dark-tertiary px-2 py-0.5 text-xs text-bambu-gray`,children:i(`cameraTokens.scope.${e.scope}`,e.scope)})}),(0,G.jsxs)(`td`,{className:`py-3 px-3 text-bambu-gray font-mono text-xs`,children:[e.lookup_prefix,`…`]}),(0,G.jsx)(`td`,{className:`py-3 px-3 text-bambu-gray`,children:B3(e.created_at)}),(0,G.jsxs)(`td`,{className:`py-3 px-3 ${a?`text-red-700 dark:text-red-400`:`text-bambu-gray`}`,children:[B3(e.expires_at),a&&(0,G.jsx)(`span`,{className:`ml-2 px-2 py-0.5 text-xs bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-300 rounded`,children:i(`cameraTokens.list.expired`,`Expired`)})]}),(0,G.jsx)(`td`,{className:`py-3 px-3 text-bambu-gray`,children:B3(e.last_used_at)}),(0,G.jsx)(`td`,{className:`py-3 px-3 text-right`,children:(0,G.jsxs)(`button`,{type:`button`,onClick:()=>r(e.id),className:`inline-flex items-center gap-1 px-2 py-1 text-sm text-red-700 dark:text-red-400 hover:text-red-900 dark:hover:text-red-300`,title:i(`cameraTokens.list.revoke`,`Revoke`),children:[(0,G.jsx)(ju,{className:`w-4 h-4`}),i(`cameraTokens.list.revoke`,`Revoke`)]})})]})}function V3({tokens:e,showOwner:t,userIdToName:n,onRevoke:r,emptyMessage:i}){let{t:a}=U();return e.length===0?(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray italic`,children:i}):(0,G.jsx)(`div`,{className:`overflow-x-auto`,children:(0,G.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,G.jsx)(`thead`,{className:`text-bambu-gray text-left border-b border-bambu-dark-tertiary`,children:(0,G.jsxs)(`tr`,{children:[(0,G.jsx)(`th`,{className:`py-2 px-3 font-medium`,children:a(`cameraTokens.list.name`,`Name`)}),t&&(0,G.jsx)(`th`,{className:`py-2 px-3 font-medium`,children:a(`cameraTokens.list.owner`,`Owner`)}),(0,G.jsx)(`th`,{className:`py-2 px-3 font-medium`,children:a(`cameraTokens.list.scope`,`Scope`)}),(0,G.jsx)(`th`,{className:`py-2 px-3 font-medium`,children:a(`cameraTokens.list.prefix`,`Prefix`)}),(0,G.jsx)(`th`,{className:`py-2 px-3 font-medium`,children:a(`cameraTokens.list.created`,`Created`)}),(0,G.jsx)(`th`,{className:`py-2 px-3 font-medium`,children:a(`cameraTokens.list.expires`,`Expires`)}),(0,G.jsx)(`th`,{className:`py-2 px-3 font-medium`,children:a(`cameraTokens.list.lastUsed`,`Last used`)}),(0,G.jsx)(`th`,{className:`py-2 px-3`})]})}),(0,G.jsx)(`tbody`,{children:e.map(e=>(0,G.jsx)(DVe,{token:e,showOwner:t,ownerLabel:n?.get(e.user_id)??`#${e.user_id}`,onRevoke:r},e.id))})]})})}function OVe(){let{t:e}=U(),{user:t,isAdmin:n}=Ed(),{showToast:r}=Bd(),[i,a]=(0,y.useState)([]),[o,s]=(0,y.useState)([]),[c,l]=(0,y.useState)(new Map),[u,d]=(0,y.useState)(!0),[f,p]=(0,y.useState)(null),[m,h]=(0,y.useState)(null),g=async()=>{d(!0);try{if(a(await Z.listMyLongLivedCameraTokens()),n){s(await Z.listAllLongLivedCameraTokens());try{let e=await Z.getUsersSlim();l(new Map(e.map(e=>[e.id,e.username])))}catch{l(new Map)}}}catch(t){r(t instanceof Error?t.message:e(`cameraTokens.toast.loadFailed`,`Failed to load tokens`),`error`)}finally{d(!1)}};(0,y.useEffect)(()=>{g()},[n]);let _=async e=>{let t=[...i,...o].find(t=>t.id===e);t&&h(t)},v=async()=>{if(!m)return;let t=m.id;h(null);try{await Z.revokeLongLivedCameraToken(t),r(e(`cameraTokens.toast.revoked`,`Token revoked`)),await g()}catch(t){r(t instanceof Error?t.message:e(`cameraTokens.toast.revokeFailed`,`Failed to revoke token`),`error`)}},b=(0,y.useMemo)(()=>o.filter(e=>e.user_id!==t?.id),[o,t?.id]);return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4`,children:e(`cameraTokens.description`,`Long-lived tokens for embedding the camera stream into Home Assistant, Frigate, kiosks, or any other tool that needs a stable URL. Each token is camera-stream-only and can be revoked at any time.`)}),(0,G.jsx)(wVe,{onCreated:e=>{p(e),g()}}),(0,G.jsxs)(`div`,{className:`mb-6`,children:[(0,G.jsx)(`h3`,{className:`text-base font-semibold text-white mb-3`,children:e(`cameraTokens.list.myTitle`,`My tokens`)}),u?(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`cameraTokens.loading`,`Loading…`)}):(0,G.jsx)(V3,{tokens:i,onRevoke:_,emptyMessage:e(`cameraTokens.list.empty`,`No tokens yet.`)})]}),n&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`text-base font-semibold text-white mb-3`,children:e(`cameraTokens.list.allTitle`,`All users (admin view)`)}),(0,G.jsx)(V3,{tokens:b,showOwner:!0,userIdToName:c,onRevoke:_,emptyMessage:e(`cameraTokens.list.empty`,`No tokens yet.`)})]}),f&&(0,G.jsx)(EVe,{token:f,onClose:()=>p(null)}),m&&(0,G.jsx)(TVe,{token:m,onConfirm:()=>void v(),onCancel:()=>h(null)})]})}var H3=[{key:`printer`,labelKey:`streamOverlay.builder.fieldPrinter`,fallback:`Printer name`},{key:`filename`,labelKey:`streamOverlay.builder.fieldFilename`,fallback:`File name`},{key:`status`,labelKey:`streamOverlay.builder.fieldStatus`,fallback:`Status`},{key:`progress`,labelKey:`streamOverlay.builder.fieldProgress`,fallback:`Progress bar`},{key:`layers`,labelKey:`streamOverlay.builder.fieldLayers`,fallback:`Layer count`},{key:`eta`,labelKey:`streamOverlay.builder.fieldEta`,fallback:`Time remaining and ETA`},{key:`nozzle`,labelKey:`printers.heaterHistory.nozzle`,fallback:`Nozzle`},{key:`bed`,labelKey:`printers.heaterHistory.bed`,fallback:`Bed`},{key:`chamber`,labelKey:`printers.heaterHistory.chamber`,fallback:`Chamber`}],kVe=[`progress`,`layers`,`eta`,`filename`,`status`],U3=15;function AVe(){let{t:e}=U(),{showToast:t}=Bd(),[n,r]=(0,y.useState)([]),[i,a]=(0,y.useState)(null),[o,s]=(0,y.useState)(kVe),[c,l]=(0,y.useState)(`medium`),[u,d]=(0,y.useState)(U3),[f,p]=(0,y.useState)(!0),[m,h]=(0,y.useState)(``),[g,_]=(0,y.useState)(!1);(0,y.useEffect)(()=>{let e=!1;return(async()=>{try{let t=await Z.getPrinters();if(e)return;r(t),t.length>0&&a(t[0].id)}catch{}})(),()=>{e=!0}},[]);let v=(0,y.useMemo)(()=>{let e=i??1,t=new URLSearchParams,n=H3.filter(e=>o.includes(e.key)).map(e=>e.key);return t.set(`show`,n.join(`,`)),c!==`medium`&&t.set(`size`,c),u!==U3&&t.set(`fps`,String(u)),f||t.set(`camera`,`false`),m.trim()&&t.set(`token`,m.trim()),`${window.location.origin}/overlay/${e}?${t.toString()}`},[i,o,c,u,f,m]),b=e=>{s(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},x=async()=>{try{if(navigator.clipboard&&window.isSecureContext)await navigator.clipboard.writeText(v);else{let e=document.createElement(`textarea`);e.value=v,e.style.position=`fixed`,e.style.opacity=`0`,document.body.appendChild(e);try{e.select(),document.execCommand(`copy`)}finally{document.body.removeChild(e)}}t(e(`cameraTokens.toast.copied`,`Copied to clipboard`))}catch{t(e(`cameraTokens.toast.copyFailed`,`Copy failed — select and copy manually`),`error`)}};return(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4`,children:e(`streamOverlay.builder.description`,`Build the URL for a streaming overlay — a full-screen camera view with live print data drawn over it, for OBS, a wall display, or any browser source. Pick the fields you want and copy the URL.`)}),(0,G.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{htmlFor:`overlay-builder-printer`,className:`block text-sm font-medium text-white mb-1`,children:e(`streamOverlay.builder.printer`,`Printer`)}),(0,G.jsxs)(`select`,{id:`overlay-builder-printer`,value:i??``,onChange:e=>a(Number(e.target.value)),className:`w-full px-3 py-2 bg-bambu-dark rounded-md text-white border border-bambu-dark-tertiary focus:border-bambu-green focus:outline-none`,children:[n.length===0&&(0,G.jsx)(`option`,{value:``,children:e(`common.loading`,`Loading…`)}),n.map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{htmlFor:`overlay-builder-size`,className:`block text-sm font-medium text-white mb-1`,children:e(`streamOverlay.builder.size`,`Text size`)}),(0,G.jsxs)(`select`,{id:`overlay-builder-size`,value:c,onChange:e=>l(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark rounded-md text-white border border-bambu-dark-tertiary focus:border-bambu-green focus:outline-none`,children:[(0,G.jsx)(`option`,{value:`small`,children:e(`streamOverlay.builder.sizeSmall`,`Small`)}),(0,G.jsx)(`option`,{value:`medium`,children:e(`streamOverlay.builder.sizeMedium`,`Medium`)}),(0,G.jsx)(`option`,{value:`large`,children:e(`streamOverlay.builder.sizeLarge`,`Large`)})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{htmlFor:`overlay-builder-fps`,className:`block text-sm font-medium text-white mb-1`,children:e(`streamOverlay.builder.fps`,`Frame rate`)}),(0,G.jsx)(`input`,{id:`overlay-builder-fps`,type:`number`,min:1,max:30,value:u,onChange:e=>d(Math.min(Math.max(Number(e.target.value)||1,1),30)),className:`w-full px-3 py-2 bg-bambu-dark rounded-md text-white border border-bambu-dark-tertiary focus:border-bambu-green focus:outline-none`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`streamOverlay.builder.fpsHint`,`A1 and P1 cameras top out around 5 fps whatever you ask for.`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{htmlFor:`overlay-builder-token`,className:`block text-sm font-medium text-white mb-1`,children:e(`streamOverlay.builder.token`,`Streaming Overlay token (optional)`)}),(0,G.jsx)(`input`,{id:`overlay-builder-token`,type:`text`,value:m,onChange:e=>h(e.target.value),placeholder:`bblt_…`,className:`w-full px-3 py-2 bg-bambu-dark rounded-md text-white border border-bambu-dark-tertiary focus:border-bambu-green focus:outline-none font-mono text-xs`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`streamOverlay.builder.tokenHint`,`Only needed when login is enabled: OBS has no session of its own. Create one above with the Streaming Overlay scope.`)})]})]}),(0,G.jsxs)(`fieldset`,{className:`mt-4`,children:[(0,G.jsx)(`legend`,{className:`text-sm font-medium text-white mb-2`,children:e(`streamOverlay.builder.fields`,`Fields to show`)}),(0,G.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-2 md:grid-cols-3`,children:[H3.map(t=>(0,G.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-bambu-gray`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:o.includes(t.key),onChange:()=>b(t.key),className:`accent-bambu-green`}),e(t.labelKey,t.fallback)]},t.key)),(0,G.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-bambu-gray`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:f,onChange:e=>p(e.target.checked),className:`accent-bambu-green`}),e(`streamOverlay.builder.fieldCamera`,`Camera feed`)]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-2`,children:e(`streamOverlay.builder.chamberHint`,`Chamber temperature only appears on models with a real chamber sensor — P1 and A1 printers report a meaningless value, so it is left out there.`)})]}),(0,G.jsxs)(`div`,{className:`mt-4`,children:[(0,G.jsx)(`p`,{className:`text-sm font-medium text-white mb-1`,children:e(`streamOverlay.builder.urlTitle`,`Overlay URL`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`code`,{className:`flex-1 px-3 py-2 bg-bambu-dark rounded-md text-bambu-green text-xs break-all font-mono select-all`,children:v}),(0,G.jsxs)(`button`,{type:`button`,onClick:()=>void x(),className:`flex items-center gap-2 px-3 py-2 bg-bambu-green text-white rounded-md hover:bg-bambu-green/90`,children:[(0,G.jsx)(zs,{className:`w-4 h-4`}),e(`cameraTokens.created.copy`,`Copy`)]}),(0,G.jsxs)(`a`,{href:v,target:`_blank`,rel:`noopener noreferrer`,className:`flex items-center gap-2 px-3 py-2 bg-bambu-dark-tertiary text-white rounded-md hover:bg-bambu-dark-tertiary/80`,children:[(0,G.jsx)(tc,{className:`w-4 h-4`}),e(`streamOverlay.builder.open`,`Open`)]})]}),m.trim()&&(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-2`,children:e(`streamOverlay.builder.tokenWarning`,`This URL contains a token — anyone who can read it can watch the stream and see the file name. Revoke the token to cut it off.`)})]}),(0,G.jsxs)(`div`,{className:`mt-4`,children:[(0,G.jsxs)(`button`,{type:`button`,onClick:()=>_(e=>!e),className:`flex items-center gap-2 px-3 py-2 bg-bambu-dark-tertiary text-white rounded-md hover:bg-bambu-dark-tertiary/80 text-sm`,children:[g?(0,G.jsx)(nc,{className:`w-4 h-4`}):(0,G.jsx)(rc,{className:`w-4 h-4`}),g?e(`streamOverlay.builder.hidePreview`,`Hide preview`):e(`streamOverlay.builder.showPreview`,`Show preview`)]}),g&&(0,G.jsx)(`iframe`,{src:v,title:e(`streamOverlay.builder.previewTitle`,`Overlay preview`),className:`mt-3 w-full aspect-video rounded-md border border-bambu-dark-tertiary bg-black`},v)]})]})}function jVe({plug:e,onEdit:t}){let{t:n}=U(),r=so(),{showToast:i}=Bd(),[a,o]=(0,y.useState)(!1),[s,c]=(0,y.useState)(!1),[l,u]=(0,y.useState)(!1),[d,f]=(0,y.useState)(!1),{data:p,isLoading:m}=K({queryKey:[`smart-plug-status`,e.id],queryFn:()=>Z.getSmartPlugStatus(e.id),refetchInterval:3e4}),{data:h}=K({queryKey:[`printers`],queryFn:Z.getPrinters}),g=h?.find(t=>t.id===e.printer_id),_=q({mutationFn:t=>Z.controlSmartPlug(e.id,t),onMutate:async t=>{await r.cancelQueries({queryKey:[`smart-plug-status`,e.id]});let n=r.getQueryData([`smart-plug-status`,e.id]),i=t===`on`?`ON`:t===`off`||p?.state===`ON`?`OFF`:`ON`;return r.setQueryData([`smart-plug-status`,e.id],e=>({...e,state:i})),{previousStatus:n}},onError:(t,a,o)=>{o?.previousStatus&&r.setQueryData([`smart-plug-status`,e.id],o.previousStatus),i(n(`smartPlugs.failedToTurn`,{action:a,name:e.name}),`error`)},onSettled:()=>{setTimeout(()=>{r.invalidateQueries({queryKey:[`smart-plug-status`,e.id]}),r.invalidateQueries({queryKey:[`smart-plugs`]})},1e3)}}),v=q({mutationFn:t=>Z.updateSmartPlug(e.id,t),onSuccess:()=>{r.invalidateQueries({queryKey:[`smart-plugs`]}),e.printer_id&&(r.invalidateQueries({queryKey:[`smartPlugByPrinter`,e.printer_id]}),r.invalidateQueries({queryKey:[`scriptPlugsByPrinter`,e.printer_id]}))}}),b=q({mutationFn:()=>Z.deleteSmartPlug(e.id),onSuccess:()=>{r.invalidateQueries({queryKey:[`smart-plugs`]}),e.printer_id&&r.invalidateQueries({queryKey:[`scriptPlugsByPrinter`,e.printer_id]})}}),x=p?.state===`ON`,S=e.plug_type===`mqtt`&&p?.energy?.power!==null&&p?.energy?.power!==void 0,C=(p?.reachable??!1)||S,w=_.isPending,T=(()=>{if(e.plug_type!==`tasmota`||!e.ip_address)return null;let t=e.ip_address;return e.username&&e.password?`http://${encodeURIComponent(e.username)}:${encodeURIComponent(e.password)}@${t}/`:`http://${t}/`})();return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Md,{className:`relative`,children:(0,G.jsxs)(Pd,{className:`p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-start justify-between gap-2 mb-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 flex-1`,children:[(0,G.jsx)(`div`,{className:`p-2 rounded-lg flex-shrink-0 ${e.plug_type===`mqtt`?C?`bg-teal-100 dark:bg-teal-500/20`:`bg-red-100 dark:bg-red-500/20`:C?x?`bg-bambu-green/20`:`bg-bambu-dark`:`bg-red-100 dark:bg-red-500/20`}`,children:e.plug_type===`mqtt`?(0,G.jsx)(Ll,{className:`w-5 h-5 ${C?`text-teal-600 dark:text-teal-400`:`text-red-600 dark:text-red-400`}`}):e.plug_type===`homeassistant`?(0,G.jsx)(Lc,{className:`w-5 h-5 ${C?x?`text-bambu-green`:`text-bambu-gray`:`text-red-600 dark:text-red-400`}`}):e.plug_type===`rest`?(0,G.jsx)(Dc,{className:`w-5 h-5 ${C?x?`text-bambu-green`:`text-bambu-gray`:`text-red-600 dark:text-red-400`}`}):(0,G.jsx)(jl,{className:`w-5 h-5 ${C?x?`text-bambu-green`:`text-bambu-gray`:`text-red-600 dark:text-red-400`}`})}),(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsx)(`h3`,{className:`font-medium text-white truncate`,children:e.name}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray truncate`,title:e.plug_type===`mqtt`?e.mqtt_topic??void 0:e.plug_type===`homeassistant`?e.ha_entity_id??void 0:e.plug_type===`rest`?e.rest_on_url??e.rest_off_url??void 0:e.ip_address??void 0,children:e.plug_type===`mqtt`?e.mqtt_topic:e.plug_type===`homeassistant`?e.ha_entity_id:e.plug_type===`rest`?e.rest_on_url||e.rest_off_url:e.ip_address})]})]}),(0,G.jsxs)(`div`,{className:`flex flex-col items-end gap-1 flex-shrink-0`,children:[m?(0,G.jsx)(Y,{className:`w-4 h-4 text-bambu-gray animate-spin`}):e.plug_type===`mqtt`?(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 text-sm whitespace-nowrap`,children:[(0,G.jsx)(`span`,{className:`px-1.5 py-0.5 bg-teal-100 dark:bg-teal-500/20 text-teal-700 dark:text-teal-400 text-[10px] font-medium rounded flex-shrink-0`,children:`MQTT`}),C&&(0,G.jsx)(`span`,{className:`text-status-ok`,children:`✓`})]}):e.plug_type===`homeassistant`?(0,G.jsxs)(`div`,{className:`flex items-center gap-1 text-sm`,children:[(0,G.jsx)(`span`,{className:`px-1 py-0.5 bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400 text-[10px] font-medium rounded`,children:`HA`}),(0,G.jsx)(`span`,{className:C?x?`text-status-ok`:`text-bambu-gray`:`text-status-error`,children:C?p?.state||`?`:n(`smartPlugs.offline`)})]}):e.plug_type===`rest`?(0,G.jsxs)(`div`,{className:`flex items-center gap-1 text-sm`,children:[(0,G.jsx)(`span`,{className:`px-1 py-0.5 bg-purple-100 dark:bg-purple-500/20 text-purple-700 dark:text-purple-400 text-[10px] font-medium rounded`,children:`REST`}),(0,G.jsx)(`span`,{className:C?x?`text-status-ok`:`text-bambu-gray`:`text-status-error`,children:C?p?.state||`?`:n(`smartPlugs.offline`)})]}):C?(0,G.jsxs)(`div`,{className:`flex items-center gap-1 text-sm`,children:[(0,G.jsx)(Yu,{className:`w-4 h-4 text-status-ok`}),(0,G.jsx)(`span`,{className:x?`text-status-ok`:`text-bambu-gray`,children:p?.state||n(`smartPlugs.unknown`)})]}):(0,G.jsxs)(`div`,{className:`flex items-center gap-1 text-sm text-status-error`,children:[(0,G.jsx)(Ju,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{children:n(`smartPlugs.offline`)})]}),T&&(0,G.jsxs)(`a`,{href:T,target:`_blank`,rel:`noopener noreferrer`,className:`flex items-center gap-1 px-2 py-0.5 bg-bambu-dark hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white text-xs rounded-full transition-colors`,title:n(`smartPlugs.openPlugAdminPage`),children:[(0,G.jsx)(tc,{className:`w-3 h-3`}),n(`smartPlugs.admin`)]})]})]}),g&&(0,G.jsxs)(`div`,{className:`mb-3 px-2 py-1.5 bg-bambu-dark rounded-lg`,children:[(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[n(`smartPlugs.linkedTo`),` `]}),(0,G.jsx)(`span`,{className:`text-sm text-white`,children:g.name})]}),(e.power_alert_enabled||e.schedule_enabled||e.plug_type===`mqtt`)&&(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-1.5 mb-3`,children:[e.plug_type===`mqtt`&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1 px-2 py-0.5 bg-teal-100 dark:bg-teal-500/20 text-teal-700 dark:text-teal-400 text-xs rounded-full`,children:[(0,G.jsx)(rc,{className:`w-3 h-3`}),n(`smartPlugs.monitorOnly`)]}),e.power_alert_enabled&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1 px-2 py-0.5 bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400 text-xs rounded-full`,children:[(0,G.jsx)(Go,{className:`w-3 h-3`}),n(`smartPlugs.alerts`)]}),e.schedule_enabled&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1 px-2 py-0.5 bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400 text-xs rounded-full`,children:[(0,G.jsx)(rs,{className:`w-3 h-3`}),e.schedule_on_time&&e.schedule_off_time?`${e.schedule_on_time} - ${e.schedule_off_time}`:e.schedule_on_time?n(`smartPlugs.scheduleOn`,{time:e.schedule_on_time}):n(`smartPlugs.scheduleOff`,{time:e.schedule_off_time})]})]}),e.plug_type!==`mqtt`&&(0,G.jsxs)(`div`,{className:`flex gap-2 mb-3`,children:[(0,G.jsxs)(Q,{size:`sm`,variant:x?`primary`:`secondary`,disabled:!C||w,onClick:()=>c(!0),className:`flex-1`,children:[w?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Pl,{className:`w-4 h-4`}),n(`smartPlugs.on`)]}),(0,G.jsxs)(Q,{size:`sm`,variant:x?`secondary`:`primary`,disabled:!C||w,onClick:()=>u(!0),className:`flex-1`,children:[w?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Nl,{className:`w-4 h-4`}),n(`smartPlugs.off`)]})]}),e.plug_type===`mqtt`&&p?.energy&&(0,G.jsxs)(`div`,{className:`flex gap-2 mb-3 px-3 py-2 bg-bambu-dark rounded-lg`,children:[p.energy.power!==null&&p.energy.power!==void 0&&(0,G.jsxs)(`div`,{className:`flex-1 text-center`,children:[(0,G.jsxs)(`p`,{className:`text-lg font-semibold text-white`,children:[Math.round(p.energy.power),`W`]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.power`)})]}),p.energy.today!==null&&p.energy.today!==void 0&&(0,G.jsxs)(`div`,{className:`flex-1 text-center border-l border-bambu-dark-tertiary`,children:[(0,G.jsx)(`p`,{className:`text-lg font-semibold text-white`,children:p.energy.today.toFixed(3)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.kwhToday`)})]})]}),(0,G.jsxs)(`button`,{onClick:()=>f(!d),className:`w-full flex items-center justify-between py-2 text-sm text-bambu-gray hover:text-white transition-colors`,children:[(0,G.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,G.jsx)($l,{className:`w-4 h-4`}),e.plug_type===`mqtt`?n(`smartPlugs.settings`):n(`smartPlugs.automationSettings`)]}),(0,G.jsx)(`span`,{children:d?`-`:`+`})]}),d&&(0,G.jsxs)(`div`,{className:`pt-3 border-t border-bambu-dark-tertiary space-y-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Kc,{className:`w-4 h-4 text-bambu-green`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`smartPlugs.showInSwitchbar`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.quickAccessSidebar`)})]})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:e.show_in_switchbar,onChange:e=>v.mutate({show_in_switchbar:e.target.checked}),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green`})]})]}),e.printer_id!=null&&(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Pl,{className:`w-4 h-4 text-bambu-green`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`smartPlugs.controlsPrinterPower`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.controlsPrinterPowerDescription`)})]})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:e.controls_printer_power,onChange:e=>v.mutate({controls_printer_power:e.target.checked}),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green`})]})]}),e.plug_type!==`mqtt`&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`smartPlugs.enabled`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.enableAutomation`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:e.enabled,onChange:e=>v.mutate({enabled:e.target.checked}),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`smartPlugs.autoOn`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.autoOnDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:e.auto_on,onChange:e=>v.mutate({auto_on:e.target.checked}),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`smartPlugs.autoOff`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.autoOffDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:e.auto_off,onChange:e=>v.mutate({auto_off:e.target.checked}),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green`})]})]}),e.auto_off&&(0,G.jsxs)(`div`,{className:`flex items-center justify-between pl-4 border-l-2 border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`smartPlugs.autoOffPersistent`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.autoOffPersistentDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:e.auto_off_persistent,onChange:e=>v.mutate({auto_off_persistent:e.target.checked}),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green`})]})]}),e.auto_off&&(0,G.jsxs)(`div`,{className:`space-y-3 pl-4 border-l-2 border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white mb-2`,children:n(`smartPlugs.turnOffDelayMode`)}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsxs)(`button`,{onClick:()=>v.mutate({off_delay_mode:`time`}),className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg text-sm transition-colors ${e.off_delay_mode===`time`?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white`}`,children:[(0,G.jsx)(ks,{className:`w-4 h-4`}),n(`smartPlugs.time`)]}),(0,G.jsxs)(`button`,{onClick:()=>v.mutate({off_delay_mode:`temperature`}),className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg text-sm transition-colors ${e.off_delay_mode===`temperature`?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white`}`,children:[(0,G.jsx)(ku,{className:`w-4 h-4`}),n(`smartPlugs.temp`)]})]})]}),e.off_delay_mode===`time`?(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:n(`smartPlugs.delayMinutes`)}),(0,G.jsx)(`input`,{type:`number`,min:`1`,max:`60`,value:e.off_delay_minutes,onChange:e=>v.mutate({off_delay_minutes:parseInt(e.target.value)||5}),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`})]}):(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:n(`smartPlugs.tempThreshold`)}),(0,G.jsx)(`input`,{type:`number`,min:`30`,max:`100`,value:e.off_temp_threshold,onChange:e=>v.mutate({off_temp_threshold:parseInt(e.target.value)||70}),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(`smartPlugs.tempThresholdDescription`)})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`smartPlugs.autoOffAfterDrying`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.autoOffAfterDryingDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:e.auto_off_after_drying,onChange:e=>v.mutate({auto_off_after_drying:e.target.checked}),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green`})]})]}),e.auto_off_after_drying&&(0,G.jsxs)(`div`,{className:`pl-4 border-l-2 border-bambu-dark-tertiary`,children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:n(`smartPlugs.delayAfterDryingMinutes`)}),(0,G.jsx)(`input`,{type:`number`,min:`0`,max:`120`,value:e.off_delay_after_drying_minutes,onChange:e=>v.mutate({off_delay_after_drying_minutes:parseInt(e.target.value)||10}),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`})]})]}),(0,G.jsxs)(`div`,{className:`flex gap-2 pt-2`,children:[(0,G.jsxs)(Q,{size:`sm`,variant:`secondary`,onClick:()=>t(e),className:`flex-1`,children:[(0,G.jsx)(Dl,{className:`w-4 h-4`}),n(`smartPlugs.edit`)]}),(0,G.jsx)(Q,{size:`sm`,variant:`secondary`,onClick:()=>o(!0),className:`text-red-600 dark:text-red-400 hover:text-red-700 dark:hover:text-red-300`,children:(0,G.jsx)(ju,{className:`w-4 h-4`})})]})]})]})}),a&&(0,G.jsx)(Zd,{title:n(`smartPlugs.deleteSmartPlug`),message:n(`smartPlugs.deleteConfirm`,{name:e.name}),confirmText:n(`smartPlugs.delete`),variant:`danger`,onConfirm:()=>{b.mutate(),o(!1)},onCancel:()=>o(!1)}),s&&(0,G.jsx)(Zd,{title:n(`smartPlugs.turnOnSmartPlug`),message:n(`smartPlugs.turnOnConfirm`,{name:e.name}),confirmText:n(`smartPlugs.turnOn`),variant:`default`,onConfirm:()=>{_.mutate(`on`),c(!1)},onCancel:()=>c(!1)}),l&&(0,G.jsx)(Zd,{title:n(`smartPlugs.turnOffSmartPlug`),message:n(`smartPlugs.turnOffConfirm`,{name:e.name}),confirmText:n(`smartPlugs.turnOff`),variant:`danger`,onConfirm:()=>{_.mutate(`off`),u(!1)},onCancel:()=>u(!1)})]})}function MVe({plug:e,onClose:t}){let{t:n}=U(),r=so(),i=!!e,[a,o]=(0,y.useState)(e?.plug_type||`tasmota`),[s,c]=(0,y.useState)(e?.name||``),[l,u]=(0,y.useState)(e?.ip_address||``),[d,f]=(0,y.useState)(e?.username||``),[p,m]=(0,y.useState)(e?.password||``),[h,g]=(0,y.useState)(e?.ha_entity_id||``),[_,v]=(0,y.useState)(e?.mqtt_power_topic||e?.mqtt_topic||``),[b,x]=(0,y.useState)(e?.mqtt_power_path||``),[S,C]=(0,y.useState)((e?.mqtt_power_multiplier??e?.mqtt_multiplier??1).toString()),[w,T]=(0,y.useState)(e?.mqtt_energy_topic||``),[E,D]=(0,y.useState)(e?.mqtt_energy_path||``),[O,k]=(0,y.useState)((e?.mqtt_energy_multiplier??1).toString()),[A,j]=(0,y.useState)(e?.mqtt_state_topic||``),[M,N]=(0,y.useState)(e?.mqtt_state_path||``),[P,F]=(0,y.useState)(e?.mqtt_state_on_value||``),[I,L]=(0,y.useState)(e?.rest_on_url||``),[R,z]=(0,y.useState)(e?.rest_on_body||``),[B,V]=(0,y.useState)(e?.rest_off_url||``),[ee,te]=(0,y.useState)(e?.rest_off_body||``),[ne,re]=(0,y.useState)(e?.rest_method||`POST`),[ie,ae]=(0,y.useState)(e?.rest_headers||``),[oe,se]=(0,y.useState)(e?.rest_status_url||``),[H,ce]=(0,y.useState)(e?.rest_status_path||``),[le,ue]=(0,y.useState)(e?.rest_status_on_value||``),[de,fe]=(0,y.useState)(e?.rest_power_url||``),[pe,me]=(0,y.useState)(e?.rest_power_path||``),[he,ge]=(0,y.useState)((e?.rest_power_multiplier??1).toString()),[_e,ve]=(0,y.useState)(e?.rest_energy_url||``),[ye,be]=(0,y.useState)(e?.rest_energy_path||``),[xe,Se]=(0,y.useState)((e?.rest_energy_multiplier??1).toString()),[Ce,we]=(0,y.useState)(e?.rest_energy_total_path||``),[Te,Ee]=(0,y.useState)((e?.rest_energy_total_multiplier??1).toString()),[De,Oe]=(0,y.useState)(e?.ha_power_entity||``),[ke,Ae]=(0,y.useState)(e?.ha_energy_today_entity||``),[je,Me]=(0,y.useState)(e?.ha_energy_total_entity||``),[Ne,Pe]=(0,y.useState)(``),[Fe,Ie]=(0,y.useState)(``),[Le,Re]=(0,y.useState)(!1),ze=(0,y.useRef)(null),[Be,Ve]=(0,y.useState)(``),[He,Ue]=(0,y.useState)(!1),We=(0,y.useRef)(null),[Ge,Ke]=(0,y.useState)(``),[qe,Je]=(0,y.useState)(!1),Ye=(0,y.useRef)(null),[Xe,Ze]=(0,y.useState)(``),[Qe,$e]=(0,y.useState)(!1),et=(0,y.useRef)(null),[tt,nt]=(0,y.useState)(e?.printer_id||null),[rt,it]=(0,y.useState)(e?.controls_printer_power??!0),[at,ot]=(0,y.useState)(null),[st,ct]=(0,y.useState)(null),[lt,ut]=(0,y.useState)(e?.power_alert_enabled||!1),[dt,ft]=(0,y.useState)(e?.power_alert_high?.toString()||``),[pt,mt]=(0,y.useState)(e?.power_alert_low?.toString()||``),[ht,gt]=(0,y.useState)(e?.schedule_enabled||!1),[_t,vt]=(0,y.useState)(e?.schedule_on_time||``),[yt,bt]=(0,y.useState)(e?.schedule_off_time||``),[xt,St]=(0,y.useState)(e?.show_in_switchbar||!1),[Ct,wt]=(0,y.useState)(e?.show_on_printer_card??!0),[Tt,Et]=(0,y.useState)(!1),[Dt,Ot]=(0,y.useState)({scanned:0,total:0}),[kt,At]=(0,y.useState)([]),jt=(0,y.useRef)(null),{data:Mt}=K({queryKey:[`printers`],queryFn:Z.getPrinters}),{data:Nt}=K({queryKey:[`smart-plugs`],queryFn:Z.getSmartPlugs}),{data:Pt}=K({queryKey:[`settings`],queryFn:Z.getSettings}),Ft=!!(Pt?.ha_enabled&&Pt?.ha_url&&Pt?.ha_token);(0,y.useEffect)(()=>{let e=setTimeout(()=>{Ie(Ne)},300);return()=>clearTimeout(e)},[Ne]),(0,y.useEffect)(()=>{let e=e=>{ze.current&&!ze.current.contains(e.target)&&Re(!1),We.current&&!We.current.contains(e.target)&&Ue(!1),Ye.current&&!Ye.current.contains(e.target)&&Je(!1),et.current&&!et.current.contains(e.target)&&$e(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[]);let{data:It,isLoading:Lt,error:Rt}=K({queryKey:[`ha-entities`,Fe],queryFn:()=>Z.getHAEntities(Fe||void 0),enabled:a===`homeassistant`&&Ft,retry:!1,staleTime:0}),{data:zt}=K({queryKey:[`ha-sensor-entities`],queryFn:Z.getHASensorEntities,enabled:a===`homeassistant`&&Ft,retry:!1,staleTime:0});(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,e),()=>{window.removeEventListener(`keydown`,e),jt.current&&clearInterval(jt.current)}},[t]);let Bt=async()=>{Et(!0),At([]),Ot({scanned:0,total:0}),ct(null);try{await Z.startTasmotaScan();let e=async()=>{try{let e=await Z.getTasmotaScanStatus();Ot({scanned:e.scanned,total:e.total}),At(await Z.getDiscoveredTasmotaDevices()),e.running||(Et(!1),jt.current&&=(clearInterval(jt.current),null))}catch(e){console.error(`Polling error:`,e)}};await e(),jt.current=setInterval(e,500)}catch(e){Et(!1),ct((e instanceof Error?e.message:typeof e==`string`?e:JSON.stringify(e))||n(`smartPlugs.failedToStartScan`))}},Vt=async()=>{try{await Z.stopTasmotaScan()}catch{}Et(!1),jt.current&&=(clearInterval(jt.current),null)},W=e=>{u(e.ip_address),c(e.name),ot(null)},Ht=q({mutationFn:()=>Z.testSmartPlugConnection(l,d||null,p||null),onSuccess:e=>{ot(e),ct(null),!s&&e.device_name&&c(e.device_name)},onError:e=>{ot(null),ct(e.message)}}),Ut=q({mutationFn:e=>Z.createSmartPlug(e),onSuccess:()=>{r.invalidateQueries({queryKey:[`smart-plugs`]}),r.invalidateQueries({queryKey:[`scriptPlugsByPrinter`]}),t()},onError:e=>{ct(e.message)}}),Wt=q({mutationFn:t=>Z.updateSmartPlug(e.id,t),onSuccess:()=>{r.invalidateQueries({queryKey:[`smart-plugs`]}),r.invalidateQueries({queryKey:[`scriptPlugsByPrinter`]}),t()},onError:e=>{ct(e.message)}}),Gt=Mt?.filter(t=>a===`tasmota`?!Nt?.some(n=>n.printer_id===t.id&&n.id!==e?.id&&n.plug_type===`tasmota`):!0),Kt=e=>{if(e.preventDefault(),ct(null),!s.trim()){ct(n(`smartPlugs.nameRequired`));return}if(a===`tasmota`&&!l.trim()){ct(`IP address is required for Tasmota plugs`);return}if(a===`homeassistant`&&!h){ct(n(`smartPlugs.entityRequired`));return}if(a===`mqtt`){let e=_.trim(),t=w.trim(),r=A.trim();if(!e&&!t&&!r){ct(n(`smartPlugs.mqttTopicRequired`));return}}if(a===`rest`&&!I.trim()&&!B.trim()){ct(n(`smartPlugs.restUrlRequired`));return}let t={name:s.trim(),plug_type:a,ip_address:a===`tasmota`?l.trim():null,ha_entity_id:a===`homeassistant`?h:null,ha_power_entity:a===`homeassistant`&&De||null,ha_energy_today_entity:a===`homeassistant`&&ke||null,ha_energy_total_entity:a===`homeassistant`&&je||null,mqtt_power_topic:a===`mqtt`&&_.trim()||null,mqtt_power_path:a===`mqtt`&&b.trim()||null,mqtt_power_multiplier:a===`mqtt`&&parseFloat(S)||1,mqtt_energy_topic:a===`mqtt`&&w.trim()||null,mqtt_energy_path:a===`mqtt`&&E.trim()||null,mqtt_energy_multiplier:a===`mqtt`&&parseFloat(O)||1,mqtt_state_topic:a===`mqtt`&&A.trim()||null,mqtt_state_path:a===`mqtt`&&M.trim()||null,mqtt_state_on_value:a===`mqtt`&&P.trim()||null,rest_on_url:a===`rest`&&I.trim()||null,rest_on_body:a===`rest`&&R.trim()||null,rest_off_url:a===`rest`&&B.trim()||null,rest_off_body:a===`rest`&&ee.trim()||null,rest_method:a===`rest`?ne:null,rest_headers:a===`rest`&&ie.trim()||null,rest_status_url:a===`rest`&&oe.trim()||null,rest_status_path:a===`rest`&&H.trim()||null,rest_status_on_value:a===`rest`&&le.trim()||null,rest_power_url:a===`rest`&&de.trim()||null,rest_power_path:a===`rest`&&pe.trim()||null,rest_power_multiplier:a===`rest`&&parseFloat(he)||1,rest_energy_url:a===`rest`&&_e.trim()||null,rest_energy_path:a===`rest`&&ye.trim()||null,rest_energy_multiplier:a===`rest`&&parseFloat(xe)||1,rest_energy_total_path:a===`rest`&&Ce.trim()||null,rest_energy_total_multiplier:a===`rest`&&parseFloat(Te)||1,username:a===`tasmota`&&d.trim()||null,password:a===`tasmota`&&p.trim()||null,printer_id:tt,controls_printer_power:rt,power_alert_enabled:lt,power_alert_high:dt?parseFloat(dt):null,power_alert_low:pt?parseFloat(pt):null,schedule_enabled:ht,schedule_on_time:_t||null,schedule_off_time:yt||null,show_in_switchbar:xt,show_on_printer_card:Ct};i?Wt.mutate(t):Ut.mutate(t)},qt=Ut.isPending||Wt.isPending;return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:t,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-md max-h-[90vh] flex flex-col`,onClick:e=>e.stopPropagation(),children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary flex-shrink-0`,children:[(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:n(i?`smartPlugs.editTitle`:`smartPlugs.addTitle`)}),(0,G.jsx)(`button`,{onClick:t,className:`text-bambu-gray hover:text-white transition-colors`,children:(0,G.jsx)($u,{className:`w-5 h-5`})})]}),(0,G.jsxs)(`form`,{onSubmit:Kt,className:`p-6 space-y-4 overflow-y-auto`,children:[st&&(0,G.jsx)(`div`,{className:`p-3 bg-red-100 dark:bg-red-500/20 border border-red-400 dark:border-red-500/50 rounded-lg text-sm text-red-700 dark:text-red-400`,children:st}),!i&&(0,G.jsxs)(`div`,{className:`flex gap-2 mb-2`,children:[(0,G.jsxs)(`button`,{type:`button`,onClick:()=>{o(`tasmota`),ot(null),ct(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2.5 rounded-lg font-medium transition-colors ${a===`tasmota`?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white border border-bambu-dark-tertiary`}`,children:[(0,G.jsx)(jl,{className:`w-4 h-4`}),`Tasmota`]}),(0,G.jsxs)(`button`,{type:`button`,onClick:()=>{o(`homeassistant`),ot(null),ct(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2.5 rounded-lg font-medium transition-colors ${a===`homeassistant`?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white border border-bambu-dark-tertiary`}`,children:[(0,G.jsx)(Lc,{className:`w-4 h-4`}),`HA`]}),(0,G.jsxs)(`button`,{type:`button`,onClick:()=>{o(`mqtt`),ot(null),ct(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2.5 rounded-lg font-medium transition-colors ${a===`mqtt`?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white border border-bambu-dark-tertiary`}`,children:[(0,G.jsx)(Ll,{className:`w-4 h-4`}),`MQTT`]}),(0,G.jsxs)(`button`,{type:`button`,onClick:()=>{o(`rest`),ot(null),ct(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2.5 rounded-lg font-medium transition-colors ${a===`rest`?`bg-bambu-green text-white`:`bg-bambu-dark text-bambu-gray hover:text-white border border-bambu-dark-tertiary`}`,children:[(0,G.jsx)(Dc,{className:`w-4 h-4`}),`REST`]})]}),!i&&a===`tasmota`&&(0,G.jsxs)(`div`,{className:`space-y-3`,children:[Tt?(0,G.jsxs)(Q,{type:`button`,variant:`secondary`,onClick:Vt,className:`w-full`,children:[(0,G.jsx)($u,{className:`w-4 h-4`}),n(`smartPlugs.stopScanning`)]}):(0,G.jsxs)(Q,{type:`button`,variant:`primary`,onClick:Bt,className:`w-full`,children:[(0,G.jsx)(Yl,{className:`w-4 h-4`}),n(`smartPlugs.discoverTasmota`)]}),Tt&&Dt.total>0&&(0,G.jsxs)(`div`,{className:`space-y-1`,children:[(0,G.jsxs)(`div`,{className:`flex justify-between text-xs text-bambu-gray`,children:[(0,G.jsx)(`span`,{children:n(`smartPlugs.addSmartPlug.scanningNetwork`)}),(0,G.jsxs)(`span`,{children:[Dt.scanned,` / `,Dt.total]})]}),(0,G.jsx)(`div`,{className:`w-full bg-bambu-dark-tertiary rounded-full h-2`,children:(0,G.jsx)(`div`,{className:`bg-bambu-green h-2 rounded-full transition-all duration-300`,style:{width:`${Dt.scanned/Dt.total*100}%`}})})]}),kt.length>0&&(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.foundDevices`,{count:kt.length})}),(0,G.jsx)(`div`,{className:`max-h-40 overflow-y-auto space-y-1`,children:kt.map(e=>(0,G.jsxs)(`button`,{type:`button`,onClick:()=>W(e),className:`w-full flex items-center justify-between p-2 bg-bambu-dark hover:bg-bambu-dark-tertiary rounded-lg transition-colors text-left border border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(jl,{className:`w-4 h-4 text-bambu-green`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:e.name}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:e.ip_address})]})]}),e.state&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-xs ${e.state===`ON`?`text-bambu-green`:`text-bambu-gray`}`,children:[(0,G.jsx)(Pl,{className:`w-3 h-3`}),e.state]})]},e.ip_address))})]}),!Tt&&kt.length===0&&Dt.total>0&&(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray text-center py-2`,children:n(`smartPlugs.noDevicesFound`)})]}),a===`homeassistant`&&(0,G.jsxs)(`div`,{className:`space-y-3`,children:[!Ft&&(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{className:`p-3 bg-yellow-100 dark:bg-yellow-500/20 border border-yellow-400 dark:border-yellow-500/50 rounded-lg text-sm text-yellow-700 dark:text-yellow-400`,children:[n(`smartPlugs.haNotConfigured`),` `,(0,G.jsx)(`span`,{className:`font-medium`,children:n(`smartPlugs.haSettingsPath`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1 opacity-50`,children:n(`smartPlugs.selectEntity`)}),(0,G.jsx)(`select`,{disabled:!0,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray cursor-not-allowed opacity-50`,children:(0,G.jsx)(`option`,{children:n(`smartPlugs.addSmartPlug.chooseEntity`)})})]})]}),Ft&&(0,G.jsxs)(G.Fragment,{children:[Lt&&(0,G.jsxs)(`div`,{className:`flex items-center justify-center py-4 text-bambu-gray`,children:[(0,G.jsx)(Y,{className:`w-5 h-5 animate-spin mr-2`}),n(`smartPlugs.loadingEntities`)]}),Rt&&(0,G.jsx)(`div`,{className:`p-3 bg-red-100 dark:bg-red-500/20 border border-red-400 dark:border-red-500/50 rounded-lg text-sm text-red-700 dark:text-red-400`,children:n(`smartPlugs.failedToLoadEntities`,{error:Rt.message})}),(()=>{let t=Nt?.filter(t=>t.ha_entity_id&&t.id!==e?.id).map(e=>e.ha_entity_id)||[],r=(It||[]).filter(e=>!t.includes(e.entity_id)),i=It?.find(e=>e.entity_id===h);return(0,G.jsxs)(`div`,{ref:ze,className:`relative`,children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.selectEntity`)}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(Yl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`}),(0,G.jsx)(`input`,{type:`text`,value:Le?Ne:i?`${i.friendly_name} (${i.entity_id})`:``,onChange:e=>{Pe(e.target.value),Le||Re(!0)},onFocus:()=>{Re(!0),Pe(``)},placeholder:n(`smartPlugs.addSmartPlug.placeholders.searchEntities`),className:`w-full pl-9 pr-8 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`}),h&&!Le&&(0,G.jsx)(`button`,{type:`button`,onClick:()=>{g(``),Pe(``)},className:`absolute right-2 top-1/2 -translate-y-1/2 p-1 hover:bg-bambu-dark-tertiary rounded`,children:(0,G.jsx)($u,{className:`w-4 h-4 text-bambu-gray hover:text-white`})}),Lt&&(0,G.jsx)(Y,{className:`absolute right-2 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray animate-spin`})]}),Le&&(0,G.jsxs)(`div`,{className:`absolute z-50 w-full mt-1 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-60 overflow-y-auto`,children:[Lt&&(0,G.jsxs)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray flex items-center gap-2`,children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),n(`smartPlugs.loading`)]}),!Lt&&r.length===0&&(0,G.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:Fe?n(`smartPlugs.noEntitiesMatching`,{search:Fe}):n(`smartPlugs.noEntitiesAvailable`)}),!Lt&&r.map(e=>(0,G.jsxs)(`button`,{type:`button`,onClick:()=>{g(e.entity_id),Re(!1),Pe(``),s||c(e.friendly_name)},className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary transition-colors ${e.entity_id===h?`bg-bambu-green/20 text-bambu-green`:`text-white`}`,children:[(0,G.jsx)(`div`,{className:`font-medium`,children:e.friendly_name}),(0,G.jsxs)(`div`,{className:`text-xs text-bambu-gray flex items-center justify-between`,children:[(0,G.jsx)(`span`,{children:e.entity_id}),(0,G.jsx)(`span`,{className:e.state===`on`?`text-bambu-green`:``,children:e.state})]})]},e.entity_id))]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(Fe?`smartPlugs.searchingEntities`:`smartPlugs.showingEntities`,{count:r.length})})]})})(),h&&zt&&zt.length>0&&(0,G.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary pt-4 mt-4 space-y-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white font-medium mb-1`,children:n(`smartPlugs.energyMonitoringOptional`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mb-3`,children:n(`smartPlugs.energyMonitoringHint`)})]}),(()=>{let e=zt.filter(e=>e.unit_of_measurement===`W`||e.unit_of_measurement===`kW`||e.unit_of_measurement===`mW`),t=Be?e.filter(e=>e.entity_id.toLowerCase().includes(Be.toLowerCase())||e.friendly_name.toLowerCase().includes(Be.toLowerCase())):e,r=zt.find(e=>e.entity_id===De);return(0,G.jsxs)(`div`,{ref:We,className:`relative`,children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.powerSensorW`)}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(Yl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`}),(0,G.jsx)(`input`,{type:`text`,value:He?Be:r?`${r.friendly_name} (${r.state} ${r.unit_of_measurement})`:``,onChange:e=>{Ve(e.target.value),He||Ue(!0)},onFocus:()=>{Ue(!0),Ve(``)},placeholder:n(`smartPlugs.addSmartPlug.placeholders.searchPowerSensors`),className:`w-full pl-9 pr-8 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`}),De&&!He&&(0,G.jsx)(`button`,{type:`button`,onClick:()=>{Oe(``),Ve(``)},className:`absolute right-2 top-1/2 -translate-y-1/2 p-1 hover:bg-bambu-dark-tertiary rounded`,children:(0,G.jsx)($u,{className:`w-4 h-4 text-bambu-gray hover:text-white`})})]}),He&&(0,G.jsxs)(`div`,{className:`absolute z-50 w-full mt-1 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-48 overflow-y-auto`,children:[(0,G.jsx)(`button`,{type:`button`,onClick:()=>{Oe(``),Ue(!1),Ve(``)},className:`w-full px-3 py-2 text-left text-sm text-bambu-gray hover:bg-bambu-dark-tertiary`,children:n(`smartPlugs.none`)}),t.map(e=>(0,G.jsxs)(`button`,{type:`button`,onClick:()=>{Oe(e.entity_id),Ue(!1),Ve(``)},className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${e.entity_id===De?`bg-bambu-green/20 text-bambu-green`:`text-white`}`,children:[(0,G.jsx)(`div`,{className:`font-medium`,children:e.friendly_name}),(0,G.jsxs)(`div`,{className:`text-xs text-bambu-gray`,children:[e.entity_id,` • `,e.state,` `,e.unit_of_measurement]})]},e.entity_id)),t.length===0&&(0,G.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:n(`smartPlugs.noMatchingSensors`)})]})]})})(),(()=>{let e=zt.filter(e=>e.unit_of_measurement===`kWh`||e.unit_of_measurement===`Wh`||e.unit_of_measurement===`MWh`),t=Ge?e.filter(e=>e.entity_id.toLowerCase().includes(Ge.toLowerCase())||e.friendly_name.toLowerCase().includes(Ge.toLowerCase())):e,r=zt.find(e=>e.entity_id===ke);return(0,G.jsxs)(`div`,{ref:Ye,className:`relative`,children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.energyTodayKwh`)}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(Yl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`}),(0,G.jsx)(`input`,{type:`text`,value:qe?Ge:r?`${r.friendly_name} (${r.state} ${r.unit_of_measurement})`:``,onChange:e=>{Ke(e.target.value),qe||Je(!0)},onFocus:()=>{Je(!0),Ke(``)},placeholder:n(`smartPlugs.addSmartPlug.placeholders.searchEnergySensors`),className:`w-full pl-9 pr-8 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`}),ke&&!qe&&(0,G.jsx)(`button`,{type:`button`,onClick:()=>{Ae(``),Ke(``)},className:`absolute right-2 top-1/2 -translate-y-1/2 p-1 hover:bg-bambu-dark-tertiary rounded`,children:(0,G.jsx)($u,{className:`w-4 h-4 text-bambu-gray hover:text-white`})})]}),qe&&(0,G.jsxs)(`div`,{className:`absolute z-50 w-full mt-1 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-48 overflow-y-auto`,children:[(0,G.jsx)(`button`,{type:`button`,onClick:()=>{Ae(``),Je(!1),Ke(``)},className:`w-full px-3 py-2 text-left text-sm text-bambu-gray hover:bg-bambu-dark-tertiary`,children:n(`smartPlugs.none`)}),t.map(e=>(0,G.jsxs)(`button`,{type:`button`,onClick:()=>{Ae(e.entity_id),Je(!1),Ke(``)},className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${e.entity_id===ke?`bg-bambu-green/20 text-bambu-green`:`text-white`}`,children:[(0,G.jsx)(`div`,{className:`font-medium`,children:e.friendly_name}),(0,G.jsxs)(`div`,{className:`text-xs text-bambu-gray`,children:[e.entity_id,` • `,e.state,` `,e.unit_of_measurement]})]},e.entity_id)),t.length===0&&(0,G.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:n(`smartPlugs.noMatchingSensors`)})]})]})})(),(()=>{let e=zt.filter(e=>e.unit_of_measurement===`kWh`||e.unit_of_measurement===`Wh`||e.unit_of_measurement===`MWh`),t=Xe?e.filter(e=>e.entity_id.toLowerCase().includes(Xe.toLowerCase())||e.friendly_name.toLowerCase().includes(Xe.toLowerCase())):e,r=zt.find(e=>e.entity_id===je);return(0,G.jsxs)(`div`,{ref:et,className:`relative`,children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.totalEnergyKwh`)}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(Yl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`}),(0,G.jsx)(`input`,{type:`text`,value:Qe?Xe:r?`${r.friendly_name} (${r.state} ${r.unit_of_measurement})`:``,onChange:e=>{Ze(e.target.value),Qe||$e(!0)},onFocus:()=>{$e(!0),Ze(``)},placeholder:n(`smartPlugs.addSmartPlug.placeholders.searchEnergySensors`),className:`w-full pl-9 pr-8 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`}),je&&!Qe&&(0,G.jsx)(`button`,{type:`button`,onClick:()=>{Me(``),Ze(``)},className:`absolute right-2 top-1/2 -translate-y-1/2 p-1 hover:bg-bambu-dark-tertiary rounded`,children:(0,G.jsx)($u,{className:`w-4 h-4 text-bambu-gray hover:text-white`})})]}),Qe&&(0,G.jsxs)(`div`,{className:`absolute z-50 w-full mt-1 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-48 overflow-y-auto`,children:[(0,G.jsx)(`button`,{type:`button`,onClick:()=>{Me(``),$e(!1),Ze(``)},className:`w-full px-3 py-2 text-left text-sm text-bambu-gray hover:bg-bambu-dark-tertiary`,children:n(`smartPlugs.none`)}),t.map(e=>(0,G.jsxs)(`button`,{type:`button`,onClick:()=>{Me(e.entity_id),$e(!1),Ze(``)},className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${e.entity_id===je?`bg-bambu-green/20 text-bambu-green`:`text-white`}`,children:[(0,G.jsx)(`div`,{className:`font-medium`,children:e.friendly_name}),(0,G.jsxs)(`div`,{className:`text-xs text-bambu-gray`,children:[e.entity_id,` • `,e.state,` `,e.unit_of_measurement]})]},e.entity_id)),t.length===0&&(0,G.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:n(`smartPlugs.noMatchingSensors`)})]})]})})()]})]})]}),a===`mqtt`&&(0,G.jsxs)(`div`,{className:`space-y-3`,children:[!Pt?.mqtt_broker&&(0,G.jsxs)(`div`,{className:`p-3 bg-yellow-100 dark:bg-yellow-500/20 border border-yellow-400 dark:border-yellow-500/50 rounded-lg text-sm text-yellow-700 dark:text-yellow-400`,children:[n(`smartPlugs.mqttNotConfigured`),` `,(0,G.jsx)(`span`,{className:`font-medium`,children:n(`smartPlugs.mqttSettingsPath`)}),` `,n(`smartPlugs.mqttNotConfiguredSuffix`)]}),Pt?.mqtt_broker&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`p-3 bg-blue-50 dark:bg-blue-500/10 border border-blue-300 dark:border-blue-500/30 rounded-lg text-sm text-blue-700 dark:text-blue-300`,children:[(0,G.jsx)(`p`,{className:`font-medium mb-1`,children:n(`smartPlugs.monitorOnly`)}),(0,G.jsx)(`p`,{className:`text-xs opacity-80`,children:n(`smartPlugs.mqttMonitorOnlyDescription`)})]}),(0,G.jsxs)(`div`,{className:`space-y-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,G.jsx)(`p`,{className:`text-white font-medium text-sm`,children:n(`smartPlugs.powerMonitoring`)}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.topic`)}),(0,G.jsx)(`input`,{type:`text`,value:_,onChange:e=>v(e.target.value),placeholder:`zigbee2mqtt/shelly-working-room`,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`})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.jsonPath`)}),(0,G.jsx)(`input`,{type:`text`,value:b,onChange:e=>x(e.target.value),placeholder:`power_l1`,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`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.multiplier`)}),(0,G.jsx)(`input`,{type:`text`,value:S,onChange:e=>C(e.target.value),placeholder:`1`,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`})]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,style:{whiteSpace:`pre-line`},children:n(`smartPlugs.mqttPowerHint`)})]}),(0,G.jsxs)(`div`,{className:`space-y-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`p`,{className:`text-white font-medium text-sm`,children:[n(`smartPlugs.energyMonitoring`),` `,(0,G.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,n(`smartPlugs.optional`),`)`]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.topic`)}),(0,G.jsx)(`input`,{type:`text`,value:w,onChange:e=>T(e.target.value),placeholder:`Same as power topic, or different`,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`})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.jsonPath`)}),(0,G.jsx)(`input`,{type:`text`,value:E,onChange:e=>D(e.target.value),placeholder:`energy_l1`,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`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.multiplier`)}),(0,G.jsx)(`input`,{type:`text`,value:O,onChange:e=>k(e.target.value),placeholder:`1`,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`})]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,style:{whiteSpace:`pre-line`},children:n(`smartPlugs.mqttEnergyHint`)})]}),(0,G.jsxs)(`div`,{className:`space-y-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`p`,{className:`text-white font-medium text-sm`,children:[n(`smartPlugs.stateMonitoring`),` `,(0,G.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,n(`smartPlugs.optional`),`)`]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.topic`)}),(0,G.jsx)(`input`,{type:`text`,value:A,onChange:e=>j(e.target.value),placeholder:`Same as power topic, or different`,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`})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.jsonPath`)}),(0,G.jsx)(`input`,{type:`text`,value:M,onChange:e=>N(e.target.value),placeholder:`state_l1`,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`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.onValue`)}),(0,G.jsx)(`input`,{type:`text`,value:P,onChange:e=>F(e.target.value),placeholder:n(`smartPlugs.addSmartPlug.placeholders.mqttStateOnValue`),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`})]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,style:{whiteSpace:`pre-line`},children:n(`smartPlugs.mqttStateHint`)})]})]})]}),a===`rest`&&(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{className:`space-y-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,G.jsx)(`p`,{className:`text-white font-medium text-sm`,children:n(`smartPlugs.restControl`)}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restMethod`)}),(0,G.jsxs)(`select`,{value:ne,onChange:e=>re(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,G.jsx)(`option`,{value:`GET`,children:`GET`}),(0,G.jsx)(`option`,{value:`POST`,children:`POST`}),(0,G.jsx)(`option`,{value:`PUT`,children:`PUT`}),(0,G.jsx)(`option`,{value:`PATCH`,children:`PATCH`})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restOnUrl`)}),(0,G.jsx)(`input`,{type:`text`,value:I,onChange:e=>{L(e.target.value),ot(null)},placeholder:`http://openhab:8080/rest/items/MyPlug`,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`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[n(`smartPlugs.restOnBody`),` `,(0,G.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,n(`smartPlugs.optional`),`)`]})]}),(0,G.jsx)(`input`,{type:`text`,value:R,onChange:e=>z(e.target.value),placeholder:n(`smartPlugs.restBodyHint`),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`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restOffUrl`)}),(0,G.jsx)(`input`,{type:`text`,value:B,onChange:e=>{V(e.target.value),ot(null)},placeholder:`http://openhab:8080/rest/items/MyPlug`,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`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[n(`smartPlugs.restOffBody`),` `,(0,G.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,n(`smartPlugs.optional`),`)`]})]}),(0,G.jsx)(`input`,{type:`text`,value:ee,onChange:e=>te(e.target.value),placeholder:n(`smartPlugs.restBodyHint`),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`})]})]}),(0,G.jsxs)(`div`,{className:`space-y-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`p`,{className:`text-white font-medium text-sm`,children:[n(`smartPlugs.restHeaders`),` `,(0,G.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,n(`smartPlugs.optional`),`)`]})]}),(0,G.jsx)(`div`,{children:(0,G.jsx)(`textarea`,{value:ie,onChange:e=>ae(e.target.value),placeholder:n(`smartPlugs.restHeadersHint`),rows:2,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 font-mono text-sm`})})]}),(0,G.jsxs)(`div`,{className:`space-y-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`p`,{className:`text-white font-medium text-sm`,children:[n(`smartPlugs.stateMonitoring`),` `,(0,G.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,n(`smartPlugs.optional`),`)`]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restStatusUrl`)}),(0,G.jsx)(`input`,{type:`text`,value:oe,onChange:e=>se(e.target.value),placeholder:n(`smartPlugs.restStatusHint`),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`})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restStatusPath`)}),(0,G.jsx)(`input`,{type:`text`,value:H,onChange:e=>ce(e.target.value),placeholder:n(`smartPlugs.restPathHint`),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`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restStatusOnValue`)}),(0,G.jsx)(`input`,{type:`text`,value:le,onChange:e=>ue(e.target.value),placeholder:`ON`,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`})]})]})]}),(0,G.jsxs)(`div`,{className:`space-y-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`p`,{className:`text-white font-medium text-sm`,children:[n(`smartPlugs.energyMonitoring`),` `,(0,G.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,n(`smartPlugs.optional`),`)`]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[n(`smartPlugs.restPowerUrl`),` `,(0,G.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,n(`smartPlugs.optional`),`)`]})]}),(0,G.jsx)(`input`,{type:`text`,value:de,onChange:e=>fe(e.target.value),placeholder:n(`smartPlugs.restPowerUrlHint`),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`})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restPowerPath`)}),(0,G.jsx)(`input`,{type:`text`,value:pe,onChange:e=>me(e.target.value),placeholder:n(`smartPlugs.restPathHint`),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`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restPowerMultiplier`)}),(0,G.jsx)(`input`,{type:`text`,value:he,onChange:e=>ge(e.target.value),placeholder:`1`,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`})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[n(`smartPlugs.restEnergyUrl`),` `,(0,G.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,n(`smartPlugs.optional`),`)`]})]}),(0,G.jsx)(`input`,{type:`text`,value:_e,onChange:e=>ve(e.target.value),placeholder:n(`smartPlugs.restEnergyUrlHint`),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`})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restEnergyPath`)}),(0,G.jsx)(`input`,{type:`text`,value:ye,onChange:e=>be(e.target.value),placeholder:n(`smartPlugs.restPathHint`),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`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restEnergyMultiplier`)}),(0,G.jsx)(`input`,{type:`text`,value:xe,onChange:e=>Se(e.target.value),placeholder:`1`,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`})]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.restEnergyHint`)}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restEnergyTotalPath`)}),(0,G.jsx)(`input`,{type:`text`,value:Ce,onChange:e=>we(e.target.value),placeholder:n(`smartPlugs.restEnergyTotalPathHint`),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`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.restEnergyTotalMultiplier`)}),(0,G.jsx)(`input`,{type:`text`,value:Te,onChange:e=>Ee(e.target.value),placeholder:`1`,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`})]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.restEnergyTotalHint`)})]}),(I.trim()||B.trim())&&(0,G.jsx)(`div`,{className:`flex gap-2`,children:(0,G.jsxs)(Q,{type:`button`,variant:`secondary`,onClick:async()=>{ot(null);try{let e=I.trim()||B.trim(),t=await Z.testRESTConnection(e,ne,ie.trim()||null);ot({success:t.success}),t.success||ct(t.error||n(`smartPlugs.addSmartPlug.connectionFailed`))}catch{ot({success:!1}),ct(n(`smartPlugs.addSmartPlug.connectionFailed`))}},className:`w-full`,children:[(0,G.jsx)(Yu,{className:`w-4 h-4`}),n(`smartPlugs.testConnection`)]})}),at&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm ${at.success?`text-green-700 dark:text-green-400`:`text-red-700 dark:text-red-400`}`,children:[at.success?(0,G.jsx)(ys,{className:`w-4 h-4`}):(0,G.jsx)(Ju,{className:`w-4 h-4`}),at.success?n(`smartPlugs.connectionSuccess`):n(`smartPlugs.addSmartPlug.connectionFailed`)]})]}),a===`tasmota`&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.ipAddress`)}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsx)(`input`,{type:`text`,value:l,onChange:e=>{u(e.target.value),ot(null)},placeholder:`192.168.1.100`,className:`flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,G.jsxs)(Q,{type:`button`,variant:`secondary`,onClick:()=>Ht.mutate(),disabled:!l.trim()||Ht.isPending,children:[Ht.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Yu,{className:`w-4 h-4`}),n(`smartPlugs.test`)]})]})]}),a===`tasmota`&&at&&(0,G.jsx)(`div`,{className:`p-3 rounded-lg flex items-center gap-2 ${at.success?`bg-bambu-green/20 border border-bambu-green/50 text-bambu-green`:`bg-red-100 dark:bg-red-500/20 border border-red-400 dark:border-red-500/50 text-red-700 dark:text-red-400`}`,children:at.success?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(ys,{className:`w-5 h-5`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`font-medium`,children:n(`smartPlugs.connectedResult`)}),(0,G.jsxs)(`p`,{className:`text-sm opacity-80`,children:[at.device_name&&n(`smartPlugs.deviceLabel`,{name:at.device_name}),n(`smartPlugs.stateLabel`,{state:at.state})]})]})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Ju,{className:`w-5 h-5`}),(0,G.jsx)(`span`,{children:n(`smartPlugs.addSmartPlug.connectionFailed`)})]})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.nameLabel`)}),(0,G.jsx)(`input`,{type:`text`,value:s,onChange:e=>c(e.target.value),placeholder:n(`smartPlugs.addSmartPlug.placeholders.plugName`),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),a===`tasmota`&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.username`)}),(0,G.jsx)(`input`,{type:`text`,value:d,onChange:e=>f(e.target.value),placeholder:`admin`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.password`)}),(0,G.jsx)(`input`,{type:`password`,value:p,onChange:e=>m(e.target.value),placeholder:`********`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray -mt-2`,children:n(`smartPlugs.authHint`)})]}),a!==`mqtt`&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.linkToPrinter`)}),(0,G.jsxs)(`select`,{value:tt??``,onChange:e=>nt(e.target.value?Number(e.target.value):null),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,G.jsx)(`option`,{value:``,children:n(`smartPlugs.noPrinter`)}),Gt?.map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(`smartPlugs.linkingDescription`)}),tt!==null&&(0,G.jsxs)(`div`,{className:`flex items-center justify-between mt-3`,children:[(0,G.jsxs)(`div`,{className:`pr-3`,children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`smartPlugs.controlsPrinterPower`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.controlsPrinterPowerDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer shrink-0`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:rt,onChange:e=>it(e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]})]}),(0,G.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary pt-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Go,{className:`w-4 h-4 text-bambu-green`}),(0,G.jsx)(`span`,{className:`text-white font-medium`,children:n(`smartPlugs.powerAlerts`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:lt,onChange:e=>ut(e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),lt&&(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.alertAbove`)}),(0,G.jsx)(`input`,{type:`number`,value:dt,onChange:e=>ft(e.target.value),placeholder:`e.g. 200`,min:`0`,max:`5000`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.alertBelow`)}),(0,G.jsx)(`input`,{type:`number`,value:pt,onChange:e=>mt(e.target.value),placeholder:`e.g. 10`,min:`0`,max:`5000`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.alertDescription`)})]})]}),a!==`mqtt`&&(0,G.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary pt-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(ks,{className:`w-4 h-4 text-bambu-green`}),(0,G.jsx)(`span`,{className:`text-white font-medium`,children:n(`smartPlugs.dailySchedule`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:ht,onChange:e=>gt(e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),ht&&(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.turnOnAt`)}),(0,G.jsx)(`input`,{type:`time`,value:_t,onChange:e=>vt(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`smartPlugs.turnOffAt`)}),(0,G.jsx)(`input`,{type:`time`,value:yt,onChange:e=>bt(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.scheduleDescription`)})]})]}),(0,G.jsx)(`div`,{className:`border-t border-bambu-dark-tertiary pt-4`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Kc,{className:`w-4 h-4 text-bambu-green`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-white font-medium`,children:n(`smartPlugs.showInSwitchbar`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.quickAccessSidebar`)})]})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:xt,onChange:e=>St(e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]})}),a===`homeassistant`&&(0,G.jsx)(`div`,{className:`border-t border-bambu-dark-tertiary pt-4`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(rc,{className:`w-4 h-4 text-bambu-green`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-white font-medium`,children:n(`smartPlugs.showOnPrinterCard`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`smartPlugs.displayOnPrinterCard`)})]})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:Ct,onChange:e=>wt(e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]})}),(0,G.jsxs)(`div`,{className:`flex gap-3 pt-2`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:t,className:`flex-1`,children:n(`smartPlugs.cancel`)}),(0,G.jsxs)(Q,{type:`submit`,disabled:qt,className:`flex-1`,children:[qt?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Wl,{className:`w-4 h-4`}),n(i?`smartPlugs.save`:`smartPlugs.add`)]})]})]})]})})}var NVe={door:{on:`open`,off:`closed`},garage_door:{on:`open`,off:`closed`},window:{on:`open`,off:`closed`},opening:{on:`open`,off:`closed`},lock:{on:`unlocked`,off:`locked`},motion:{on:`detected`,off:`clear`},occupancy:{on:`detected`,off:`clear`},presence:{on:`detected`,off:`clear`},smoke:{on:`detected`,off:`clear`},gas:{on:`detected`,off:`clear`},moisture:{on:`wet`,off:`dry`},problem:{on:`problem`,off:`ok`},safety:{on:`problem`,off:`ok`},running:{on:`running`,off:`stopped`}};function PVe({sensor:e,printers:t,onClose:n}){let{t:r}=U(),i=so(),{showToast:a}=Bd(),o=!!e,[s,c]=(0,y.useState)(e?.printer_id??t[0]?.id??``),[l,u]=(0,y.useState)(e?.entity_id??``),[d,f]=(0,y.useState)(e?.kind??`binary`),[p,m]=(0,y.useState)(e?.device_class??null),[h,g]=(0,y.useState)(e?.unit??null),[_,v]=(0,y.useState)(e?.name??``),[b,x]=(0,y.useState)(e?.alert_state??``),[S,C]=(0,y.useState)(e?.alert_above?.toString()??``),[w,T]=(0,y.useState)(e?.alert_below?.toString()??``),[E,D]=(0,y.useState)(e?.show_on_printer_card??!0),[O,k]=(0,y.useState)(e?.notify_on_alert??!1),[A,j]=(0,y.useState)(e?.block_print??!1),[M,N]=(0,y.useState)(``),[P,F]=(0,y.useState)(null);(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[n]);let{data:I}=K({queryKey:[`settings`],queryFn:Z.getSettings}),L=!!(I?.ha_enabled&&I?.ha_url&&I?.ha_token),{data:R,isLoading:z,error:B}=K({queryKey:[`bindableHAEntities`],queryFn:()=>Z.getBindableHAEntities(),enabled:L}),V=(0,y.useMemo)(()=>{let e=M.trim().toLowerCase(),t=R??[];return e?t.filter(t=>t.entity_id.toLowerCase().includes(e)||t.friendly_name.toLowerCase().includes(e)):t},[R,M]),ee=e=>{u(e.entity_id),m(e.device_class),g(e.unit_of_measurement);let t=e.domain===`binary_sensor`?`binary`:`numeric`;f(t),t===`numeric`?x(``):(C(``),T(``)),_.trim()||v(e.friendly_name.slice(0,100))},te=()=>{i.invalidateQueries({queryKey:[`haSensors`]}),i.invalidateQueries({queryKey:[`haSensorReadings`]})},ne=q({mutationFn:()=>{let t={name:_.trim(),entity_id:l,kind:d,device_class:p,unit:h,alert_state:d===`binary`&&b?b:null,alert_above:d===`numeric`&&S!==``?Number(S):null,alert_below:d===`numeric`&&w!==``?Number(w):null,block_print:A,notify_on_alert:O,show_on_printer_card:E};return o?Z.updateHASensor(e.id,t):Z.createHASensor({...t,printer_id:Number(s)})},onSuccess:()=>{te(),a(r(o?`haSensors.toast.updated`:`haSensors.toast.created`),`success`),n()},onError:e=>F(e.message)}),re=q({mutationFn:()=>Z.deleteHASensor(e.id),onSuccess:()=>{te(),a(r(`haSensors.toast.deleted`),`success`),n()},onError:e=>F(e.message)}),ie=d===`binary`?b!==``:S!==``||w!==``,ae=e=>{if(e.preventDefault(),F(null),!l)return F(r(`haSensors.error.pickEntity`));if(!_.trim())return F(r(`haSensors.error.nameRequired`));if(s===``)return F(r(`haSensors.error.printerRequired`));if((A||O)&&!ie)return F(r(`haSensors.error.alertRequired`));ne.mutate()},oe=NVe[p??``],se=e=>{let t=oe?.[e]??e;return r(`haSensors.states.${t}`,{defaultValue:t})},H=ne.isPending||re.isPending;return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:n,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-lg max-h-[90vh] overflow-y-auto`,onClick:e=>e.stopPropagation(),children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`p-2 rounded-full bg-bambu-green/20 text-bambu-green`,children:(0,G.jsx)(Sc,{className:`w-5 h-5`})}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:r(o?`haSensors.editTitle`:`haSensors.addTitle`)})]}),(0,G.jsx)(`button`,{onClick:n,className:`text-bambu-gray hover:text-white transition-colors`,children:(0,G.jsx)($u,{className:`w-5 h-5`})})]}),(0,G.jsxs)(`form`,{onSubmit:ae,className:`p-6 space-y-4`,children:[P&&(0,G.jsx)(`div`,{className:`p-3 bg-red-100 dark:bg-red-500/20 border border-red-300 dark:border-red-500/50 rounded-lg text-sm text-red-700 dark:text-red-400`,children:P}),!o&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`haSensors.printer`)}),(0,G.jsx)(`select`,{value:s,onChange:e=>c(e.target.value===``?``:Number(e.target.value)),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white`,children:t.map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.name},e.id))})]}),!L&&(0,G.jsxs)(`div`,{className:`p-3 bg-yellow-100 dark:bg-yellow-500/20 border border-yellow-400 dark:border-yellow-500/50 rounded-lg text-sm text-yellow-700 dark:text-yellow-400`,children:[r(`smartPlugs.haNotConfigured`),` `,(0,G.jsx)(`span`,{className:`font-medium`,children:r(`smartPlugs.haSettingsPath`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1 ${L?``:`opacity-50`}`,children:r(`haSensors.entity`)}),B&&(0,G.jsx)(`div`,{className:`p-3 mb-2 bg-red-100 dark:bg-red-500/20 rounded-lg text-sm text-red-700 dark:text-red-400`,children:B.message}),(0,G.jsxs)(`div`,{className:`relative mb-2`,children:[(0,G.jsx)(Yl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,G.jsx)(`input`,{type:`text`,value:M,onChange:e=>N(e.target.value),placeholder:r(`haSensors.searchPlaceholder`),disabled:!L,className:`w-full pl-9 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white disabled:opacity-50 disabled:cursor-not-allowed`})]}),(0,G.jsxs)(`div`,{className:`max-h-44 overflow-y-auto rounded-lg border border-bambu-dark-tertiary ${L?``:`opacity-50`}`,children:[!L&&(0,G.jsx)(`div`,{className:`p-3 text-sm text-bambu-gray`,children:r(`haSensors.noEntities`)}),L&&z&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2 p-3 text-sm text-bambu-gray`,children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),r(`common.loading`)]}),L&&!z&&V.length===0&&(0,G.jsx)(`div`,{className:`p-3 text-sm text-bambu-gray`,children:r(`haSensors.noEntities`)}),L&&!z&&V.map(e=>(0,G.jsxs)(`button`,{type:`button`,onClick:()=>ee(e),className:`w-full text-left px-3 py-2 text-sm transition-colors ${e.entity_id===l?`bg-bambu-green/20 text-bambu-green`:`text-white hover:bg-bambu-dark`}`,children:[(0,G.jsx)(`div`,{className:`font-medium`,children:e.friendly_name}),(0,G.jsxs)(`div`,{className:`text-xs text-bambu-gray`,children:[e.entity_id,e.state!==null&&` — ${e.state}`,e.unit_of_measurement?` ${e.unit_of_measurement}`:``]})]},e.entity_id))]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`haSensors.name`)}),(0,G.jsx)(`input`,{type:`text`,value:_,onChange:e=>v(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`haSensors.alertWhen`)}),d===`binary`?(0,G.jsxs)(`select`,{value:b,onChange:e=>x(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white`,children:[(0,G.jsx)(`option`,{value:``,children:r(`haSensors.alertNever`)}),(0,G.jsx)(`option`,{value:`on`,children:se(`on`)}),(0,G.jsx)(`option`,{value:`off`,children:se(`off`)})]}):(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`span`,{className:`block text-xs text-bambu-gray mb-1`,children:[r(`haSensors.alertAbove`),` `,h??``]}),(0,G.jsx)(`input`,{type:`number`,step:`any`,value:S,onChange:e=>C(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`span`,{className:`block text-xs text-bambu-gray mb-1`,children:[r(`haSensors.alertBelow`),` `,h??``]}),(0,G.jsx)(`input`,{type:`number`,step:`any`,value:w,onChange:e=>T(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white`})]})]}),(0,G.jsx)(`p`,{className:`mt-1 text-xs text-bambu-gray`,children:r(`haSensors.alertHint`)})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:E,onChange:e=>D(e.target.checked),className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`text-sm text-white`,children:r(`haSensors.showOnCard`)})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:O,onChange:e=>k(e.target.checked),disabled:!ie,className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`text-sm ${ie?`text-white`:`text-bambu-gray`}`,children:r(`haSensors.notifyOnAlert`)})]}),(0,G.jsxs)(`label`,{className:`flex items-start gap-3 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A,onChange:e=>j(e.target.checked),disabled:!ie,className:`w-4 h-4 mt-0.5`}),(0,G.jsxs)(`span`,{children:[(0,G.jsx)(`span`,{className:`block text-sm ${ie?`text-white`:`text-bambu-gray`}`,children:r(`haSensors.blockPrint`)}),(0,G.jsx)(`span`,{className:`block text-xs text-bambu-gray`,children:r(`haSensors.blockPrintHint`)})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between pt-2`,children:[o?(0,G.jsx)(Q,{type:`button`,variant:`danger`,onClick:()=>re.mutate(),disabled:H,children:r(`common.delete`)}):(0,G.jsx)(`span`,{}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:n,disabled:H,children:r(`common.cancel`)}),(0,G.jsxs)(Q,{type:`submit`,disabled:H||!L&&!o,children:[H?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Wl,{className:`w-4 h-4`}),r(`common.save`)]})]})]})]})]})})}function FVe({provider:e,onEdit:t}){let{t:n}=U(),r=so(),[i,a]=(0,y.useState)(!1),[o,s]=(0,y.useState)(!1),[c,l]=(0,y.useState)(null),{data:u}=K({queryKey:[`printers`],queryFn:Z.getPrinters}),d=u?.find(t=>t.id===e.printer_id),f=q({mutationFn:t=>Z.updateNotificationProvider(e.id,t),onSuccess:()=>{r.invalidateQueries({queryKey:[`notification-providers`]})}}),p=q({mutationFn:()=>Z.deleteNotificationProvider(e.id),onSuccess:()=>{r.invalidateQueries({queryKey:[`notification-providers`]})}}),m=q({mutationFn:()=>Z.testNotificationProvider(e.id),onSuccess:e=>{l(e),r.invalidateQueries({queryKey:[`notification-providers`]})},onError:e=>{l({success:!1,message:e.message})}}),h=e=>e||``;return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Md,{className:`relative`,children:(0,G.jsxs)(Pd,{className:`p-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-start justify-between ${e.enabled?`mb-3`:`mb-0`}`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`p-2 rounded-lg ${e.enabled?`bg-bambu-green/20`:`bg-bambu-dark`}`,children:(0,G.jsx)(Go,{className:`w-5 h-5 ${e.enabled?`text-bambu-green`:`text-bambu-gray`}`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`font-medium text-white`,children:e.name}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`notifications.providerTypes.${e.provider_type}`,e.provider_type)})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[e.last_success&&(0,G.jsx)(`span`,{className:`text-xs text-status-ok hidden sm:inline`,children:n(`notifications.lastSuccess`,{date:Jf(e.last_success)})}),e.last_error&&e.last_error_at&&(!e.last_success||(Kf(e.last_error_at)?.getTime()||0)>(Kf(e.last_success)?.getTime()||0))&&(0,G.jsx)(`span`,{className:`text-xs text-status-error`,title:e.last_error,children:n(`notifications.error`)}),(0,G.jsx)(UH,{checked:e.enabled,onChange:e=>f.mutate({enabled:e})})]})]}),e.enabled&&(0,G.jsxs)(G.Fragment,{children:[d&&(0,G.jsxs)(`div`,{className:`mb-3 px-2 py-1.5 bg-bambu-dark rounded-lg`,children:[(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[n(`notifications.printer`),` `]}),(0,G.jsx)(`span`,{className:`text-sm text-white`,children:d.name})]}),!d&&!e.printer_id&&(0,G.jsx)(`div`,{className:`mb-3 px-2 py-1.5 bg-bambu-dark rounded-lg`,children:(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:n(`notifications.allPrinters`)})}),(0,G.jsxs)(`div`,{className:`mb-3 flex flex-wrap gap-1`,children:[e.on_print_start&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400 text-xs rounded`,children:n(`notifications.start`)}),e.on_plate_not_empty&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 bg-rose-100 dark:bg-rose-600/20 text-rose-700 dark:text-rose-300 text-xs rounded`,children:n(`notifications.plateCheck`)}),e.on_print_complete&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 bg-bambu-green/20 text-bambu-green text-xs rounded`,children:n(`notifications.complete`)}),e.on_plate_clear_required&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-400 text-xs rounded`,children:n(`notifications.plateClear`)}),e.on_print_failed&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400 text-xs rounded`,children:n(`notifications.failed`)}),e.on_print_stopped&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 bg-orange-100 dark:bg-orange-500/20 text-orange-700 dark:text-orange-400 text-xs rounded`,children:n(`notifications.stopped`)}),e.on_billing_charge_failed&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 bg-red-100 dark:bg-red-600/20 text-red-700 dark:text-red-300 text-xs rounded`,children:n(`notifications.billingChargeFailedLabel`)}),e.on_print_progress&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400 text-xs rounded`,children:n(`notifications.progress`)}),e.on_printer_offline&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 bg-gray-500/20 text-gray-400 text-xs rounded`,children:n(`notifications.offline`)}),e.on_printer_error&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 bg-rose-100 dark:bg-rose-500/20 text-rose-700 dark:text-rose-400 text-xs rounded`,children:n(`notifications.error`)}),e.on_ai_failure_detection&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 bg-fuchsia-100 dark:bg-fuchsia-500/20 text-fuchsia-700 dark:text-fuchsia-300 text-xs rounded`,children:n(`notifications.aiFailureDetection`)}),e.on_ha_sensor_alert&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 bg-indigo-100 dark:bg-indigo-500/20 text-indigo-700 dark:text-indigo-300 text-xs rounded`,children:n(`notifications.haSensorAlert`)}),e.on_filament_low&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 bg-cyan-100 dark:bg-cyan-500/20 text-cyan-700 dark:text-cyan-400 text-xs rounded`,children:n(`notifications.lowFilament`)}),e.on_maintenance_due&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 bg-purple-100 dark:bg-purple-500/20 text-purple-700 dark:text-purple-400 text-xs rounded`,children:n(`notifications.maintenance`)}),e.on_ams_humidity_high&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 bg-blue-100 dark:bg-blue-600/20 text-blue-700 dark:text-blue-300 text-xs rounded`,children:n(`notifications.amsHumidity`)}),e.on_ams_temperature_high&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 bg-orange-100 dark:bg-orange-600/20 text-orange-700 dark:text-orange-300 text-xs rounded`,children:n(`notifications.amsTemp`)}),e.on_ams_drying_suspended&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 bg-rose-100 dark:bg-rose-600/20 text-rose-700 dark:text-rose-300 text-xs rounded`,children:n(`notifications.amsDryingSuspended`)}),e.on_ams_ht_humidity_high&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 bg-cyan-100 dark:bg-cyan-600/20 text-cyan-700 dark:text-cyan-300 text-xs rounded`,children:n(`notifications.amsHtHumidity`)}),e.on_ams_ht_temperature_high&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 bg-amber-100 dark:bg-amber-600/20 text-amber-700 dark:text-amber-300 text-xs rounded`,children:n(`notifications.amsHtTemp`)}),e.on_bed_cooled&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 bg-teal-100 dark:bg-teal-500/20 text-teal-700 dark:text-teal-400 text-xs rounded`,children:n(`notifications.bedCooled`)}),e.on_first_layer_complete&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 bg-emerald-100 dark:bg-emerald-600/20 text-emerald-700 dark:text-emerald-300 text-xs rounded`,children:n(`notifications.firstLayer`)}),e.on_print_missing_spool_assignment&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-300 text-xs rounded`,children:n(`notifications.missingSpoolAssignmentLabel`)}),e.on_stock_reorder_alert&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 bg-lime-100 dark:bg-lime-500/20 text-lime-700 dark:text-lime-400 text-xs rounded`,children:n(`notifications.stockReorderAlert`)}),e.on_stock_break_alert&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 bg-red-100 dark:bg-red-600/20 text-red-700 dark:text-red-300 text-xs rounded`,children:n(`notifications.stockBreakAlert`)}),e.quiet_hours_enabled&&(0,G.jsxs)(`span`,{className:`px-2 py-0.5 bg-indigo-100 dark:bg-indigo-500/20 text-indigo-700 dark:text-indigo-400 text-xs rounded flex items-center gap-1`,children:[(0,G.jsx)(hl,{className:`w-3 h-3`}),n(`notifications.quiet`)]}),e.daily_digest_enabled&&(0,G.jsxs)(`span`,{className:`px-2 py-0.5 bg-emerald-100 dark:bg-emerald-500/20 text-emerald-700 dark:text-emerald-400 text-xs rounded flex items-center gap-1`,children:[(0,G.jsx)(rs,{className:`w-3 h-3`}),n(`notifications.digest`,{time:e.daily_digest_time})]})]}),(0,G.jsx)(`div`,{className:`mb-3`,children:(0,G.jsxs)(Q,{size:`sm`,variant:`secondary`,disabled:m.isPending,onClick:()=>{l(null),m.mutate()},className:`w-full`,children:[m.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Xl,{className:`w-4 h-4`}),n(`notifications.sendTestNotification`)]})}),c&&(0,G.jsxs)(`div`,{className:`mb-3 p-2 rounded-lg flex items-center gap-2 text-sm ${c.success?`bg-bambu-green/20 text-bambu-green`:`bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400`}`,children:[c.success?(0,G.jsx)(ys,{className:`w-4 h-4`}):(0,G.jsx)(Ts,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{children:c.message})]})]}),(0,G.jsxs)(`button`,{onClick:()=>s(!o),className:`w-full flex items-center justify-between py-2 text-sm text-bambu-gray hover:text-white transition-colors ${e.enabled?`border-t border-bambu-dark-tertiary`:`mt-2 border-t border-bambu-dark-tertiary`}`,children:[(0,G.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,G.jsx)($l,{className:`w-4 h-4`}),n(`notifications.eventSettings`)]}),o?(0,G.jsx)(ms,{className:`w-4 h-4`}):(0,G.jsx)(ds,{className:`w-4 h-4`})]}),o&&(0,G.jsxs)(`div`,{className:`pt-3 border-t border-bambu-dark-tertiary space-y-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.enabled`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.sendFromProvider`)})]}),(0,G.jsx)(UH,{checked:e.enabled,onChange:e=>f.mutate({enabled:e})})]}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase tracking-wide`,children:n(`notifications.printEvents`)}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.printStarted`)}),(0,G.jsx)(UH,{checked:e.on_print_start,onChange:e=>f.mutate({on_print_start:e})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.plateNotEmpty`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.plateNotEmptyDescription`)})]}),(0,G.jsx)(UH,{checked:e.on_plate_not_empty??!0,onChange:e=>f.mutate({on_plate_not_empty:e})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.printCompleted`)}),(0,G.jsx)(UH,{checked:e.on_print_complete,onChange:e=>f.mutate({on_print_complete:e})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.plateClearRequired`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.plateClearRequiredDescription`)})]}),(0,G.jsx)(UH,{checked:e.on_plate_clear_required??!1,onChange:e=>f.mutate({on_plate_clear_required:e})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.bedCooledLabel`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.bedCooledDescription`)})]}),(0,G.jsx)(UH,{checked:e.on_bed_cooled??!1,onChange:e=>f.mutate({on_bed_cooled:e})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.firstLayerCompleteLabel`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.firstLayerCompleteDescription`)})]}),(0,G.jsx)(UH,{checked:e.on_first_layer_complete??!1,onChange:e=>f.mutate({on_first_layer_complete:e})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.missingSpoolAssignmentLabel`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.missingSpoolAssignmentDescription`)})]}),(0,G.jsx)(UH,{checked:e.on_print_missing_spool_assignment??!1,onChange:e=>f.mutate({on_print_missing_spool_assignment:e})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.printFailed`)}),(0,G.jsx)(UH,{checked:e.on_print_failed,onChange:e=>f.mutate({on_print_failed:e})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.printStopped`)}),(0,G.jsx)(UH,{checked:e.on_print_stopped,onChange:e=>f.mutate({on_print_stopped:e})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.billingChargeFailedLabel`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.billingChargeFailedDescription`)})]}),(0,G.jsx)(UH,{checked:e.on_billing_charge_failed??!0,onChange:e=>f.mutate({on_billing_charge_failed:e})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.progressMilestones`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.progressMilestonesDescription`)})]}),(0,G.jsx)(UH,{checked:e.on_print_progress,onChange:e=>f.mutate({on_print_progress:e})})]})]}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase tracking-wide`,children:n(`notifications.printerStatus`)}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.printerOffline`)}),(0,G.jsx)(UH,{checked:e.on_printer_offline,onChange:e=>f.mutate({on_printer_offline:e})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.printerError`)}),(0,G.jsx)(UH,{checked:e.on_printer_error,onChange:e=>f.mutate({on_printer_error:e})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.aiFailureDetection`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.aiFailureDetectionDescription`)})]}),(0,G.jsx)(UH,{checked:e.on_ai_failure_detection??!1,onChange:e=>f.mutate({on_ai_failure_detection:e})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.haSensorAlert`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.haSensorAlertDescription`)})]}),(0,G.jsx)(UH,{checked:e.on_ha_sensor_alert??!1,onChange:e=>f.mutate({on_ha_sensor_alert:e})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.lowFilamentLabel`)}),(0,G.jsx)(UH,{checked:e.on_filament_low,onChange:e=>f.mutate({on_filament_low:e})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.maintenanceDue`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.maintenanceDueDescription`)})]}),(0,G.jsx)(UH,{checked:e.on_maintenance_due??!1,onChange:e=>f.mutate({on_maintenance_due:e})})]})]}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase tracking-wide`,children:n(`notifications.amsAlarms`)}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.amsHumidityHigh`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.amsHumidityHighDescription`)})]}),(0,G.jsx)(UH,{checked:e.on_ams_humidity_high??!1,onChange:e=>f.mutate({on_ams_humidity_high:e})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.amsTemperatureHigh`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.amsTemperatureHighDescription`)})]}),(0,G.jsx)(UH,{checked:e.on_ams_temperature_high??!1,onChange:e=>f.mutate({on_ams_temperature_high:e})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.amsDryingSuspendedTitle`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.amsDryingSuspendedDescription`)})]}),(0,G.jsx)(UH,{checked:e.on_ams_drying_suspended??!1,onChange:e=>f.mutate({on_ams_drying_suspended:e})})]})]}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase tracking-wide`,children:n(`notifications.amsHtAlarms`)}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.amsHtHumidityHigh`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.amsHtHumidityHighDescription`)})]}),(0,G.jsx)(UH,{checked:e.on_ams_ht_humidity_high??!1,onChange:e=>f.mutate({on_ams_ht_humidity_high:e})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.amsHtTemperatureHigh`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.amsHtTemperatureHighDescription`)})]}),(0,G.jsx)(UH,{checked:e.on_ams_ht_temperature_high??!1,onChange:e=>f.mutate({on_ams_ht_temperature_high:e})})]})]}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase tracking-wide`,children:n(`notifications.inventoryAlerts`)}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.stockReorderAlert`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.stockReorderAlertDescription`)})]}),(0,G.jsx)(UH,{checked:e.on_stock_reorder_alert??!1,onChange:e=>f.mutate({on_stock_reorder_alert:e})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.stockBreakAlert`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.stockBreakAlertDescription`)})]}),(0,G.jsx)(UH,{checked:e.on_stock_break_alert??!1,onChange:e=>f.mutate({on_stock_break_alert:e})})]})]}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase tracking-wide`,children:n(`notifications.printQueue`)}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.jobAdded`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.jobAddedDescription`)})]}),(0,G.jsx)(UH,{checked:e.on_queue_job_added??!1,onChange:e=>f.mutate({on_queue_job_added:e})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.jobAssigned`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.jobAssignedDescription`)})]}),(0,G.jsx)(UH,{checked:e.on_queue_job_assigned??!1,onChange:e=>f.mutate({on_queue_job_assigned:e})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.jobStarted`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.jobStartedDescription`)})]}),(0,G.jsx)(UH,{checked:e.on_queue_job_started??!1,onChange:e=>f.mutate({on_queue_job_started:e})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.jobWaiting`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.jobWaitingDescription`)})]}),(0,G.jsx)(UH,{checked:e.on_queue_job_waiting??!0,onChange:e=>f.mutate({on_queue_job_waiting:e})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.jobSkipped`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.jobSkippedDescription`)})]}),(0,G.jsx)(UH,{checked:e.on_queue_job_skipped??!0,onChange:e=>f.mutate({on_queue_job_skipped:e})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.jobFailed`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.jobFailedDescription`)})]}),(0,G.jsx)(UH,{checked:e.on_queue_job_failed??!0,onChange:e=>f.mutate({on_queue_job_failed:e})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.queueComplete`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.queueCompleteDescription`)})]}),(0,G.jsx)(UH,{checked:e.on_queue_completed??!1,onChange:e=>f.mutate({on_queue_completed:e})})]})]}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(hl,{className:`w-4 h-4 text-purple-600 dark:text-purple-400`}),(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.quietHours`)})]}),(0,G.jsx)(UH,{checked:e.quiet_hours_enabled,onChange:e=>f.mutate({quiet_hours_enabled:e})})]}),e.quiet_hours_enabled&&(0,G.jsxs)(`div`,{className:`pl-4 border-l-2 border-bambu-dark-tertiary space-y-2`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.noNotificationsDuring`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(ks,{className:`w-4 h-4 text-bambu-gray`}),(0,G.jsxs)(`span`,{className:`text-sm text-white`,children:[h(e.quiet_hours_start)||`22:00`,` - `,h(e.quiet_hours_end)||`07:00`]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.editProviderToChangeQuietHours`)})]})]}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(rs,{className:`w-4 h-4 text-emerald-600 dark:text-emerald-400`}),(0,G.jsx)(`p`,{className:`text-sm text-white`,children:n(`notifications.dailyDigest`)})]}),(0,G.jsx)(UH,{checked:e.daily_digest_enabled,onChange:e=>f.mutate({daily_digest_enabled:e})})]}),e.daily_digest_enabled&&(0,G.jsxs)(`div`,{className:`pl-4 border-l-2 border-bambu-dark-tertiary space-y-2`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.batchNotifications`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(ks,{className:`w-4 h-4 text-bambu-gray`}),(0,G.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.sendAt`,{time:h(e.daily_digest_time)||`08:00`})})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.editProviderToChangeDigestTime`)})]})]}),(0,G.jsxs)(`div`,{className:`flex gap-2 pt-2`,children:[(0,G.jsxs)(Q,{size:`sm`,variant:`secondary`,onClick:()=>t(e),className:`flex-1`,children:[(0,G.jsx)(Dl,{className:`w-4 h-4`}),n(`notifications.edit`)]}),(0,G.jsx)(Q,{size:`sm`,variant:`secondary`,onClick:()=>a(!0),className:`text-red-700 dark:text-red-400 hover:text-red-800 dark:hover:text-red-300`,children:(0,G.jsx)(ju,{className:`w-4 h-4`})})]})]})]})}),i&&(0,G.jsx)(Zd,{title:n(`notifications.deleteProvider`),message:n(`notifications.deleteConfirm`,{name:e.name}),confirmText:n(`notifications.delete`),variant:`danger`,onConfirm:()=>{p.mutate(),a(!1)},onCancel:()=>a(!1)})]})}var IVe=[`email`,`telegram`,`discord`,`ntfy`,`pushover`,`bark`,`callmebot`,`webhook`,`homeassistant`];function LVe({provider:e,onClose:t}){let{t:n}=U(),r=so(),i=!!e,[a,o]=(0,y.useState)(e?.name||``),[s,c]=(0,y.useState)(e?.provider_type||`email`),[l,u]=(0,y.useState)(e?.printer_id||null),[d,f]=(0,y.useState)(e?.quiet_hours_enabled||!1),[p,m]=(0,y.useState)(e?.quiet_hours_start||`22:00`),[h,g]=(0,y.useState)(e?.quiet_hours_end||`07:00`),[_,v]=(0,y.useState)(e?.daily_digest_enabled||!1),[b,x]=(0,y.useState)(e?.daily_digest_time||`08:00`),[S,C]=(0,y.useState)(e?.on_print_start??!1),[w,T]=(0,y.useState)(e?.on_print_complete??!0),[E,D]=(0,y.useState)(e?.on_print_failed??!0),[O,k]=(0,y.useState)(e?.on_print_stopped??!0),[A,j]=(0,y.useState)(e?.on_print_progress??!1),[M,N]=(0,y.useState)(e?.on_billing_charge_failed??!0),[P,F]=(0,y.useState)(e?.on_printer_offline??!1),[I,L]=(0,y.useState)(e?.on_printer_error??!1),[R,z]=(0,y.useState)(e?.on_ai_failure_detection??!1),[B,V]=(0,y.useState)(e?.on_filament_low??!1),[ee,te]=(0,y.useState)(e?.on_maintenance_due??!1),[ne,re]=(0,y.useState)(e?.on_stock_reorder_alert??!1),[ie,ae]=(0,y.useState)(e?.on_stock_break_alert??!1),[oe,se]=(0,y.useState)(e?.on_plate_clear_required??!1),[H,ce]=(0,y.useState)(e?.on_bed_cooled??!1),[le,ue]=(0,y.useState)(e?.on_ha_sensor_alert??!1),[de,fe]=(0,y.useState)(e?.on_first_layer_complete??!1),[pe,me]=(0,y.useState)(e?.config?Object.fromEntries(Object.entries(e.config).filter(([e])=>e!==`event_priorities`).map(([e,t])=>[e,String(t)])):{}),[he,ge]=(0,y.useState)((()=>{let t=e?.config?.event_priorities;if(!t||typeof t!=`object`)return{};let n={};for(let[e,r]of Object.entries(t)){let t=Number(r);Number.isInteger(t)&&t>=1&&t<=5&&(n[e]=t)}return n})()),[_e,ve]=(0,y.useState)(null),[ye,be]=(0,y.useState)(null),{data:xe}=K({queryKey:[`printers`],queryFn:Z.getPrinters});(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]);let Se=q({mutationFn:()=>Z.testNotificationConfig({provider_type:s,config:pe}),onSuccess:e=>{ve(e),be(null)},onError:e=>{ve({success:!1,message:e.message})}}),Ce=q({mutationFn:e=>Z.createNotificationProvider(e),onSuccess:()=>{r.invalidateQueries({queryKey:[`notification-providers`]}),t()},onError:e=>{be(e.message)}}),we=q({mutationFn:t=>Z.updateNotificationProvider(e.id,t),onSuccess:()=>{r.invalidateQueries({queryKey:[`notification-providers`]}),t()},onError:e=>{be(e.message)}}),Te=e=>{if(e.preventDefault(),be(null),!a.trim()){be(n(`notifications.nameRequired`));return}let t=Oe(s);for(let e of t)if(!pe[e.key]?.trim()){be(n(`notifications.fieldRequired`,{field:e.label}));return}if(s===`homeassistant`&&pe.data?.trim()){let e;try{e=JSON.parse(pe.data)}catch{be(n(`notifications.haDataInvalid`));return}if(typeof e!=`object`||!e||Array.isArray(e)){be(n(`notifications.haDataInvalid`));return}}if(s===`telegram`&&pe.message_thread_id?.trim()&&!/^\d+$/.test(pe.message_thread_id.trim())){be(n(`notifications.telegramThreadIdInvalid`));return}let r=s===`ntfy`&&Object.keys(he).length>0?{...pe,event_priorities:he}:pe,o={name:a.trim(),provider_type:s,config:r,printer_id:l,quiet_hours_enabled:d,quiet_hours_start:d?p:null,quiet_hours_end:d?h:null,daily_digest_enabled:_,daily_digest_time:_?b:null,on_print_start:S,on_print_complete:w,on_print_failed:E,on_print_stopped:O,on_print_progress:A,on_billing_charge_failed:M,on_printer_offline:P,on_printer_error:I,on_ai_failure_detection:R,on_filament_low:B,on_maintenance_due:ee,on_stock_reorder_alert:ne,on_stock_break_alert:ie,on_plate_clear_required:oe,on_bed_cooled:H,on_ha_sensor_alert:le,on_first_layer_complete:de};i?we.mutate(o):Ce.mutate(o)},Ee=Ce.isPending||we.isPending,De=e=>{switch(e){case`callmebot`:return[{key:`phone`,label:`Phone Number`,placeholder:`+1234567890`,type:`text`,required:!0},{key:`apikey`,label:`API Key`,placeholder:`Your CallMeBot API key`,type:`text`,required:!0}];case`ntfy`:return[{key:`server`,label:`Server URL`,placeholder:`https://ntfy.sh`,type:`text`,required:!1},{key:`topic`,label:`Topic`,placeholder:`my-bambuddy`,type:`text`,required:!0},{key:`auth_token`,label:`Auth Token`,placeholder:`Optional authentication`,type:`password`,required:!1}];case`pushover`:return[{key:`user_key`,label:`User Key`,placeholder:`Your Pushover user key`,type:`text`,required:!0},{key:`app_token`,label:`App Token`,placeholder:`Your Pushover app token`,type:`text`,required:!0},{key:`priority`,label:`Priority`,placeholder:`0 (normal)`,type:`number`,required:!1},{key:`retry`,label:n(`notifications.pushoverRetry`),placeholder:`60`,type:`number`,required:!1,showIf:e=>e.priority===`2`},{key:`expire`,label:n(`notifications.pushoverExpire`),placeholder:`3600`,type:`number`,required:!1,showIf:e=>e.priority===`2`}];case`telegram`:return[{key:`bot_token`,label:`Bot Token`,placeholder:`Bot token from @BotFather`,type:`password`,required:!0},{key:`chat_id`,label:`Chat ID`,placeholder:`Your chat or group ID`,type:`text`,required:!0},{key:`message_thread_id`,label:n(`notifications.telegramThreadId`),placeholder:`123`,type:`number`,required:!1,help:n(`notifications.telegramThreadIdHelp`)}];case`email`:return[{key:`smtp_server`,label:`SMTP Server`,placeholder:`smtp.gmail.com`,type:`text`,required:!0},{key:`smtp_port`,label:`SMTP Port`,placeholder:`587`,type:`number`,required:!1},{key:`security`,label:`Security`,type:`select`,required:!1,options:[{value:`starttls`,label:`STARTTLS (Port 587)`},{value:`ssl`,label:`SSL/TLS (Port 465)`},{value:`none`,label:`None (Port 25)`}]},{key:`auth_enabled`,label:`Authentication`,type:`select`,required:!1,options:[{value:`true`,label:`Enabled`},{value:`false`,label:`Disabled`}]},{key:`username`,label:`Username`,placeholder:`your@email.com`,type:`text`,required:!1},{key:`password`,label:`Password`,placeholder:`App password`,type:`password`,required:!1},{key:`from_email`,label:`From Email`,placeholder:`your@email.com`,type:`text`,required:!0},{key:`to_email`,label:`To Email`,placeholder:`recipient@email.com`,type:`text`,required:!0}];case`discord`:return[{key:`webhook_url`,label:`Webhook URL`,placeholder:`https://discord.com/api/webhooks/...`,type:`text`,required:!0}];case`webhook`:return[{key:`webhook_url`,label:`Webhook URL`,placeholder:`https://example.com/webhook`,type:`text`,required:!0},{key:`payload_format`,label:`Payload Format`,type:`select`,required:!1,options:[{value:`generic`,label:`Generic JSON`},{value:`slack`,label:`Slack / Mattermost`}]},{key:`auth_header`,label:`Authorization`,placeholder:`Bearer token (optional)`,type:`password`,required:!1},{key:`field_title`,label:`Title Field Name`,placeholder:`title`,type:`text`,required:!1,showIf:e=>e.payload_format!==`slack`},{key:`field_message`,label:`Message Field Name`,placeholder:`message`,type:`text`,required:!1,showIf:e=>e.payload_format!==`slack`}];case`homeassistant`:return[{key:`service`,label:`Home Assistant Service`,placeholder:`notify.mobile_app_myphone`,type:`text`,required:!1},{key:`data`,label:`Data (JSON, optional)`,placeholder:`{"priority": "high", "ttl": 0, "channel": "3D Printing"}`,type:`textarea`,required:!1}];case`bark`:return[{key:`device_key`,label:`Device Key`,placeholder:`Your Bark device key`,type:`text`,required:!0},{key:`server`,label:`Server URL`,placeholder:`https://api.day.app`,type:`text`,required:!1},{key:`group`,label:`Group`,placeholder:`Bambuddy`,type:`text`,required:!1},{key:`sound`,label:`Sound`,placeholder:`minuet`,type:`text`,required:!1},{key:`level`,label:`Interruption Level`,type:`select`,required:!1,options:[{value:``,label:`Default`},{value:`active`,label:`Active`},{value:`timeSensitive`,label:`Time Sensitive`},{value:`critical`,label:`Critical (bypasses Silent/Focus)`},{value:`passive`,label:`Passive (no sound)`}]}];default:return[]}},Oe=e=>De(e).filter(e=>e.required),ke=De(s);return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4 overflow-y-auto`,onClick:t,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-lg my-8 max-h-[90vh] overflow-y-auto`,onClick:e=>e.stopPropagation(),children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:n(i?`notifications.editTitle`:`notifications.addTitle`)}),(0,G.jsx)(`button`,{onClick:t,className:`text-bambu-gray hover:text-white transition-colors`,children:(0,G.jsx)($u,{className:`w-5 h-5`})})]}),(0,G.jsxs)(`form`,{onSubmit:Te,className:`p-6 space-y-4`,children:[ye&&(0,G.jsx)(`div`,{className:`p-3 bg-red-100 dark:bg-red-500/20 border border-red-300 dark:border-red-500/50 rounded-lg text-sm text-red-700 dark:text-red-400`,children:ye}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`notifications.nameLabel`)}),(0,G.jsx)(`input`,{type:`text`,value:a,onChange:e=>o(e.target.value),placeholder:n(`notifications.namePlaceholder`),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`notifications.providerTypeLabel`)}),(0,G.jsx)(`select`,{value:s,onChange:e=>{c(e.target.value),me({}),ve(null)},disabled:i,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none disabled:opacity-50`,children:IVe.map(e=>(0,G.jsx)(`option`,{value:e,children:n(`notifications.providerTypes.${e}`,e)},e))}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(`notifications.providerDescriptions.${s}`,``)})]}),(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`notifications.configuration`)}),ke.filter(e=>!(`showIf`in e)||e.showIf?.(pe)!==!1).map(e=>(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[e.label,` `,e.required&&`*`]}),e.type===`select`&&`options`in e&&e.options?(0,G.jsx)(`select`,{value:pe[e.key]||e.options[0]?.value||``,onChange:t=>{me({...pe,[e.key]:t.target.value}),ve(null)},className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:e.options.map(e=>(0,G.jsx)(`option`,{value:e.value,children:e.label},e.value))}):e.type===`textarea`?(0,G.jsx)(`textarea`,{value:pe[e.key]||``,onChange:t=>{me({...pe,[e.key]:t.target.value}),ve(null)},placeholder:e.placeholder,rows:3,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none font-mono text-sm`}):(0,G.jsx)(`input`,{type:e.type,value:pe[e.key]||``,onChange:t=>{me({...pe,[e.key]:t.target.value}),ve(null)},placeholder:e.placeholder,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),`help`in e&&e.help&&(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e.help})]},e.key))]}),(0,G.jsx)(`div`,{className:`flex gap-2`,children:(0,G.jsxs)(Q,{type:`button`,variant:`secondary`,onClick:()=>{ve(null),Se.mutate()},disabled:Se.isPending||Oe(s).length>0&&!pe[Oe(s)[0]?.key],className:`flex-1`,children:[Se.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Xl,{className:`w-4 h-4`}),n(`notifications.testConfiguration`)]})}),_e&&(0,G.jsx)(`div`,{className:`p-3 rounded-lg flex items-center gap-2 ${_e.success?`bg-bambu-green/20 border border-bambu-green/50 text-bambu-green`:`bg-red-100 dark:bg-red-500/20 border border-red-300 dark:border-red-500/50 text-red-700 dark:text-red-400`}`,children:_e.success?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(ys,{className:`w-5 h-5`}),(0,G.jsx)(`span`,{children:_e.message})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Ts,{className:`w-5 h-5`}),(0,G.jsx)(`span`,{children:_e.message})]})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`notifications.printerFilter`)}),(0,G.jsxs)(`select`,{value:l??``,onChange:e=>u(e.target.value?Number(e.target.value):null),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,G.jsx)(`option`,{value:``,children:n(`notifications.allPrinters`)}),xe?.map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(`notifications.onlyFromPrinter`)})]}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`label`,{className:`text-sm text-white`,children:n(`notifications.quietHoursDnd`)}),(0,G.jsx)(UH,{checked:d,onChange:f})]}),d&&(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:n(`notifications.quietStart`)}),(0,G.jsx)(`input`,{type:`time`,value:p,onChange:e=>m(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:n(`notifications.quietEnd`)}),(0,G.jsx)(`input`,{type:`time`,value:h,onChange:e=>g(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]})]})]}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`text-sm text-white`,children:n(`notifications.dailyDigestLabel`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`notifications.batchNotifications`)})]}),(0,G.jsx)(UH,{checked:_,onChange:v})]}),_&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:n(`notifications.sendDigestAt`)}),(0,G.jsx)(`input`,{type:`time`,value:b,onChange:e=>x(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(`notifications.digestCollected`)})]})]}),(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`notifications.notificationEvents`)}),(0,G.jsxs)(`div`,{className:`space-y-2 p-3 bg-bambu-dark rounded-lg`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase tracking-wide mb-2`,children:n(`notifications.printEvents`)}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.start`)}),(0,G.jsx)(UH,{checked:S,onChange:C})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.complete`)}),(0,G.jsx)(UH,{checked:w,onChange:T})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.failed`)}),(0,G.jsx)(UH,{checked:E,onChange:D})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.stopped`)}),(0,G.jsx)(UH,{checked:O,onChange:k})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between col-span-2`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.progress`)}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray ml-1`,children:n(`notifications.progressPercent`)})]}),(0,G.jsx)(UH,{checked:A,onChange:j})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between col-span-2`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.billingChargeFailedLabel`)}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray ml-1`,children:n(`notifications.billingChargeFailedDescription`)})]}),(0,G.jsx)(UH,{checked:M,onChange:N})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between col-span-2`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.plateClearRequired`)}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray ml-1`,children:n(`notifications.plateClearRequiredDescription`)})]}),(0,G.jsx)(UH,{checked:oe,onChange:se})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between col-span-2`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.bedCooled`)}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray ml-1`,children:n(`notifications.bedCooledAfterPrint`)})]}),(0,G.jsx)(UH,{checked:H,onChange:ce})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between col-span-2`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.firstLayerCompleteLabel`)}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray ml-1`,children:n(`notifications.firstLayerCompleteDescription`)})]}),(0,G.jsx)(UH,{checked:de,onChange:fe})]})]})]}),(0,G.jsxs)(`div`,{className:`space-y-2 p-3 bg-bambu-dark rounded-lg`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase tracking-wide mb-2`,children:n(`notifications.printerStatus`)}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.offline`)}),(0,G.jsx)(UH,{checked:P,onChange:F})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between col-span-2`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.haSensorAlert`)}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray ml-1`,children:n(`notifications.haSensorAlertDescription`)})]}),(0,G.jsx)(UH,{checked:le,onChange:ue})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.error`)}),(0,G.jsx)(UH,{checked:I,onChange:L})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.aiFailureDetection`)}),(0,G.jsx)(UH,{checked:R,onChange:z})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.lowFilament`)}),(0,G.jsx)(UH,{checked:B,onChange:V})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.maintenance`)}),(0,G.jsx)(UH,{checked:ee,onChange:te})]})]})]}),(0,G.jsxs)(`div`,{className:`space-y-2 p-3 bg-bambu-dark rounded-lg`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase tracking-wide mb-2`,children:n(`notifications.inventoryAlerts`)}),(0,G.jsxs)(`div`,{className:`grid grid-cols-1 gap-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.stockReorderAlert`)}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray ml-1`,children:n(`notifications.stockReorderAlertDescription`)})]}),(0,G.jsx)(UH,{checked:ne,onChange:re})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-sm text-white`,children:n(`notifications.stockBreakAlert`)}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray ml-1`,children:n(`notifications.stockBreakAlertDescription`)})]}),(0,G.jsx)(UH,{checked:ie,onChange:ae})]})]})]}),s===`ntfy`&&(()=>{let e=[];return S&&e.push({key:`on_print_start`,label:n(`notifications.start`)}),w&&e.push({key:`on_print_complete`,label:n(`notifications.complete`)}),E&&e.push({key:`on_print_failed`,label:n(`notifications.failed`)}),O&&e.push({key:`on_print_stopped`,label:n(`notifications.stopped`)}),A&&e.push({key:`on_print_progress`,label:n(`notifications.progress`)}),M&&e.push({key:`on_billing_charge_failed`,label:n(`notifications.billingChargeFailedLabel`)}),oe&&e.push({key:`on_plate_clear_required`,label:n(`notifications.plateClearRequired`)}),H&&e.push({key:`on_bed_cooled`,label:n(`notifications.bedCooled`)}),de&&e.push({key:`on_first_layer_complete`,label:n(`notifications.firstLayerCompleteLabel`)}),P&&e.push({key:`on_printer_offline`,label:n(`notifications.offline`)}),I&&e.push({key:`on_printer_error`,label:n(`notifications.error`)}),le&&e.push({key:`on_ha_sensor_alert`,label:n(`notifications.haSensorAlert`)}),R&&e.push({key:`on_ai_failure_detection`,label:n(`notifications.aiFailureDetection`)}),B&&e.push({key:`on_filament_low`,label:n(`notifications.lowFilament`)}),ee&&e.push({key:`on_maintenance_due`,label:n(`notifications.maintenance`)}),ne&&e.push({key:`on_stock_reorder_alert`,label:n(`notifications.stockReorderAlert`)}),ie&&e.push({key:`on_stock_break_alert`,label:n(`notifications.stockBreakAlert`)}),e.length===0?null:(0,G.jsxs)(`div`,{className:`space-y-2 p-3 bg-bambu-dark rounded-lg`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray uppercase tracking-wide mb-1`,children:n(`notifications.eventPriority.sectionTitle`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:n(`notifications.eventPriority.helpNtfy`)}),(0,G.jsx)(`div`,{className:`space-y-2`,children:e.map(e=>(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,G.jsx)(`span`,{className:`text-sm text-white`,children:e.label}),(0,G.jsxs)(`select`,{value:he[e.key]??3,onChange:t=>{let n=Number(t.target.value);ge(t=>({...t,[e.key]:n}))},className:`px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-sm text-white focus:border-bambu-green focus:outline-none`,children:[(0,G.jsx)(`option`,{value:1,children:n(`notifications.eventPriority.min`)}),(0,G.jsx)(`option`,{value:2,children:n(`notifications.eventPriority.low`)}),(0,G.jsx)(`option`,{value:3,children:n(`notifications.eventPriority.default`)}),(0,G.jsx)(`option`,{value:4,children:n(`notifications.eventPriority.high`)}),(0,G.jsx)(`option`,{value:5,children:n(`notifications.eventPriority.urgent`)})]})]},e.key))})]})})()]}),(0,G.jsxs)(`div`,{className:`flex gap-3 pt-2`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:t,className:`flex-1`,children:n(`notifications.cancel`)}),(0,G.jsxs)(Q,{type:`submit`,disabled:Ee,className:`flex-1`,children:[Ee?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Wl,{className:`w-4 h-4`}),n(i?`notifications.save`:`notifications.add`)]})]})]})]})})}function RVe({template:e,onClose:t}){let{t:n}=U(),r=so(),i=(0,y.useRef)(null),[a,o]=(0,y.useState)(e.title_template),[s,c]=(0,y.useState)(e.body_template),[l,u]=(0,y.useState)(null),[d,f]=(0,y.useState)(!0),{data:p}=K({queryKey:[`template-variables`],queryFn:Z.getTemplateVariables}),m=p?.find(t=>t.event_type===e.event_type),{data:h,isLoading:g}=K({queryKey:[`template-preview`,e.event_type,a,s],queryFn:()=>Z.previewTemplate({event_type:e.event_type,title_template:a,body_template:s}),enabled:d&&a.length>0&&s.length>0});(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]);let _=q({mutationFn:t=>Z.updateNotificationTemplate(e.id,t),onSuccess:()=>{r.invalidateQueries({queryKey:[`notification-templates`]}),t()},onError:e=>{u(e.message)}}),v=q({mutationFn:()=>Z.resetNotificationTemplate(e.id),onSuccess:e=>{o(e.title_template),c(e.body_template),r.invalidateQueries({queryKey:[`notification-templates`]})},onError:e=>{u(e.message)}}),b=e=>{if(e.preventDefault(),u(null),!a.trim()){u(n(`notifications.titleRequired`));return}if(!s.trim()){u(n(`notifications.bodyRequired`));return}_.mutate({title_template:a,body_template:s})},x=e=>{let t=i.current;if(!t)return;let n=t.selectionStart,r=t.selectionEnd,a=s,o=a.substring(0,n),l=a.substring(r);c(o+`{${e}}`+l),setTimeout(()=>{t.focus();let r=n+e.length+2;t.setSelectionRange(r,r)},0)},S=a!==e.title_template||s!==e.body_template;return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/80 flex items-center justify-center z-50 p-4`,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg w-full max-w-2xl max-h-[90vh] flex flex-col`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary shrink-0`,children:[(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:n(`notifications.editTemplate`,{name:e.name})}),(0,G.jsx)(`button`,{onClick:t,className:`p-1 hover:bg-bambu-dark-tertiary rounded transition-colors`,children:(0,G.jsx)($u,{className:`w-5 h-5 text-bambu-gray`})})]}),(0,G.jsxs)(`form`,{onSubmit:b,className:`flex-1 overflow-y-auto p-4 space-y-4`,children:[l&&(0,G.jsx)(`div`,{className:`p-3 bg-red-100 dark:bg-red-500/20 border border-red-300 dark:border-red-500/50 rounded text-red-700 dark:text-red-400 text-sm`,children:l}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:n(`notifications.titleLabel`)}),(0,G.jsx)(`input`,{type:`text`,value:a,onChange:e=>o(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white focus:outline-none focus:ring-1 focus:ring-bambu-green`,placeholder:n(`notifications.titlePlaceholder`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:n(`notifications.bodyLabel`)}),(0,G.jsx)(`textarea`,{ref:i,value:s,onChange:e=>c(e.target.value),rows:4,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white focus:outline-none focus:ring-1 focus:ring-bambu-green font-mono text-sm resize-none`,placeholder:n(`notifications.bodyPlaceholder`)})]}),m&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-2`,children:n(`notifications.availableVariables`)}),(0,G.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:m.variables.map(e=>(0,G.jsxs)(`button`,{type:`button`,onClick:()=>x(e),className:`inline-flex items-center gap-1 px-2 py-1 bg-bambu-dark hover:bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-xs text-bambu-gray hover:text-white transition-colors`,children:[(0,G.jsx)(Ml,{className:`w-3 h-3`}),e]},e))}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray/60 mt-1`,children:n(`notifications.clickToInsert`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,G.jsxs)(`label`,{className:`text-sm font-medium text-bambu-gray flex items-center gap-2`,children:[(0,G.jsx)(rc,{className:`w-4 h-4`}),n(`notifications.livePreview`)]}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>f(!d),className:`text-xs text-bambu-green hover:text-bambu-green-light`,children:n(d?`notifications.hide`:`notifications.show`)})]}),d&&(0,G.jsx)(`div`,{className:`bg-bambu-dark border border-bambu-dark-tertiary rounded p-3 space-y-2`,children:g?(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray text-sm`,children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),n(`notifications.loadingPreview`)]}):h?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:n(`notifications.titlePreview`)}),(0,G.jsx)(`div`,{className:`text-white font-medium`,children:h.title})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:n(`notifications.bodyPreview`)}),(0,G.jsx)(`div`,{className:`text-white whitespace-pre-wrap text-sm`,children:h.body})]})]}):(0,G.jsx)(`div`,{className:`text-bambu-gray text-sm`,children:n(`notifications.enterTemplateContent`)})})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-t border-bambu-dark-tertiary shrink-0`,children:[(0,G.jsxs)(Q,{type:`button`,variant:`ghost`,onClick:()=>v.mutate(),disabled:v.isPending,className:`text-orange-600 dark:text-orange-400 hover:text-orange-700 dark:hover:text-orange-300`,children:[v.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin mr-2`}):(0,G.jsx)(Vl,{className:`w-4 h-4 mr-2`}),n(`notifications.resetToDefault`)]}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:t,children:n(`notifications.cancel`)}),(0,G.jsxs)(Q,{onClick:b,disabled:_.isPending||!S,children:[_.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin mr-2`}):(0,G.jsx)(Wl,{className:`w-4 h-4 mr-2`}),n(`notifications.save`)]})]})]})]})})}var zVe={print_start:`text-blue-700 dark:text-blue-400`,print_complete:`text-bambu-green`,print_failed:`text-red-700 dark:text-red-400`,print_stopped:`text-orange-700 dark:text-orange-400`,print_progress:`text-yellow-700 dark:text-yellow-400`,printer_offline:`text-gray-400`,printer_error:`text-rose-700 dark:text-rose-400`,filament_low:`text-cyan-700 dark:text-cyan-400`,maintenance_due:`text-purple-700 dark:text-purple-400`,test:`text-bambu-gray`};function BVe({onClose:e}){let{t}=U(),n=so(),{showToast:r}=Bd(),[i,a]=(0,y.useState)(7),[o,s]=(0,y.useState)(null),[c,l]=(0,y.useState)(!1),{data:u}=K({queryKey:[`settings`],queryFn:Z.getSettings}),d=u?.time_format||`system`,{data:f,isLoading:p,refetch:m,isRefetching:h}=K({queryKey:[`notification-logs`,i,c],queryFn:()=>Z.getNotificationLogs({days:i,limit:100,success:c?!1:void 0})}),{data:g}=K({queryKey:[`notification-log-stats`,i],queryFn:()=>Z.getNotificationLogStats(i)}),_=q({mutationFn:()=>Z.clearNotificationLogs(30),onSuccess:e=>{r(e.message,`success`),n.invalidateQueries({queryKey:[`notification-logs`]}),n.invalidateQueries({queryKey:[`notification-log-stats`]})},onError:e=>{r(`Failed to clear logs: ${e.message}`,`error`)}}),v=e=>{let n=Kf(e);if(!n)return``;let r=new Date().getTime()-n.getTime();return r<6e4?t(`notifications.justNow`):r<36e5?`${Math.floor(r/6e4)}m ago`:r<864e5?`${Math.floor(r/36e5)}h ago`:n.toLocaleDateString()+` `+Xf(n,d)};return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg w-full max-w-3xl max-h-[85vh] flex flex-col`,children:[(0,G.jsxs)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(Ic,{className:`w-5 h-5 text-bambu-green`}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:t(`notifications.notificationLog`)})]}),(0,G.jsx)(`button`,{onClick:e,className:`text-bambu-gray hover:text-white transition-colors`,children:`×`})]}),g&&(0,G.jsx)(`div`,{className:`px-4 py-3 border-b border-bambu-dark-tertiary bg-bambu-dark/50`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-6 text-sm`,children:[(0,G.jsxs)(`span`,{className:`text-bambu-gray`,children:[t(`notifications.statsSummary`,{days:i}),` `,(0,G.jsx)(`span`,{className:`text-white font-medium`,children:g.total}),` `,t(`notifications.statsNotifications`)]}),(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-bambu-green`,children:[(0,G.jsx)(ys,{className:`w-4 h-4`}),t(`notifications.statsSent`,{count:g.success_count})]}),g.failure_count>0&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-red-700 dark:text-red-400`,children:[(0,G.jsx)(Ts,{className:`w-4 h-4`}),t(`notifications.statsFailed`,{count:g.failure_count})]})]})}),(0,G.jsxs)(`div`,{className:`px-4 py-3 border-b border-bambu-dark-tertiary flex items-center gap-4`,children:[(0,G.jsxs)(`select`,{value:i,onChange:e=>a(Number(e.target.value)),className:`px-3 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:outline-none focus:ring-1 focus:ring-bambu-green`,children:[(0,G.jsx)(`option`,{value:1,children:t(`notifications.last24Hours`)}),(0,G.jsx)(`option`,{value:7,children:t(`notifications.last7Days`)}),(0,G.jsx)(`option`,{value:30,children:t(`notifications.last30Days`)}),(0,G.jsx)(`option`,{value:90,children:t(`notifications.last90Days`)})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-bambu-gray cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:c,onChange:e=>l(e.target.checked),className:`rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),t(`notifications.showFailedOnly`)]}),(0,G.jsx)(`div`,{className:`flex-1`}),(0,G.jsxs)(Q,{size:`sm`,variant:`secondary`,onClick:()=>m(),disabled:h,children:[h?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(zl,{className:`w-4 h-4`}),t(`notifications.refresh`)]}),(0,G.jsxs)(Q,{size:`sm`,variant:`secondary`,onClick:()=>_.mutate(),disabled:_.isPending,className:`text-red-700 dark:text-red-400 hover:text-red-800 dark:hover:text-red-300`,children:[_.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(ju,{className:`w-4 h-4`}),t(`notifications.clearOld`)]})]}),(0,G.jsx)(`div`,{className:`flex-1 overflow-y-auto p-4`,children:p?(0,G.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,G.jsx)(Y,{className:`w-6 h-6 text-bambu-green animate-spin`})}):f&&f.length>0?(0,G.jsx)(`div`,{className:`space-y-2`,children:f.map(e=>(0,G.jsx)(VVe,{log:e,isExpanded:o===e.id,onToggle:()=>s(o===e.id?null:e.id),formatDate:v,formatFullDate:e=>Yf(e,d)},e.id))}):(0,G.jsxs)(`div`,{className:`text-center py-12 text-bambu-gray`,children:[(0,G.jsx)(Ic,{className:`w-12 h-12 mx-auto mb-3 opacity-30`}),(0,G.jsx)(`p`,{className:`text-sm`,children:t(c?`notifications.noFailedNotifications`:`notifications.noNotificationsLogged`)})]})})]})})}function VVe({log:e,isExpanded:t,onToggle:n,formatDate:r,formatFullDate:i}){let{t:a}=U();return(0,G.jsxs)(`div`,{className:`border rounded-lg overflow-hidden transition-colors ${e.success?`border-bambu-dark-tertiary bg-bambu-dark/30`:`border-red-500/30 bg-red-500/5`}`,children:[(0,G.jsxs)(`button`,{className:`w-full px-3 py-2 flex items-center gap-3 text-left hover:bg-bambu-dark/50 transition-colors`,onClick:n,children:[e.success?(0,G.jsx)(ys,{className:`w-4 h-4 text-bambu-green shrink-0`}):(0,G.jsx)(Ts,{className:`w-4 h-4 text-red-600 dark:text-red-400 shrink-0`}),(0,G.jsx)(`span`,{className:`text-xs font-medium ${zVe[e.event_type]||`text-bambu-gray`}`,children:a(`notifications.eventTypes.${e.event_type}`,e.event_type)}),(0,G.jsx)(`span`,{className:`text-sm text-white truncate flex-1`,children:e.provider_name||a(`notifications.unknownProvider`)}),e.printer_name&&(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:e.printer_name}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray shrink-0`,children:r(e.created_at)}),t?(0,G.jsx)(ms,{className:`w-4 h-4 text-bambu-gray shrink-0`}):(0,G.jsx)(ds,{className:`w-4 h-4 text-bambu-gray shrink-0`})]}),t&&(0,G.jsxs)(`div`,{className:`px-3 py-2 border-t border-bambu-dark-tertiary bg-bambu-dark/20 space-y-2`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mb-1`,children:a(`notifications.logTitle`)}),(0,G.jsx)(`p`,{className:`text-sm text-white`,children:e.title})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mb-1`,children:a(`notifications.logMessage`)}),(0,G.jsx)(`p`,{className:`text-sm text-white whitespace-pre-wrap`,children:e.message})]}),!e.success&&e.error_message&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-xs text-red-700 dark:text-red-400 mb-1`,children:a(`notifications.logError`)}),(0,G.jsx)(`p`,{className:`text-sm text-red-700 dark:text-red-300`,children:e.error_message})]}),(0,G.jsxs)(`div`,{className:`flex gap-4 text-xs text-bambu-gray pt-1`,children:[(0,G.jsx)(`span`,{children:a(`notifications.logProvider`,{type:e.provider_type})}),(0,G.jsx)(`span`,{children:a(`notifications.logTime`,{time:i(e.created_at)})})]})]})]})}var HVe=Object.defineProperty,W3=Object.getOwnPropertySymbols,G3=Object.prototype.hasOwnProperty,K3=Object.prototype.propertyIsEnumerable,q3=(e,t,n)=>t in e?HVe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,J3=(e,t)=>{for(var n in t||={})G3.call(t,n)&&q3(e,n,t[n]);if(W3)for(var n of W3(t))K3.call(t,n)&&q3(e,n,t[n]);return e},Y3=(e,t)=>{var n={};for(var r in e)G3.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&W3)for(var r of W3(e))t.indexOf(r)<0&&K3.call(e,r)&&(n[r]=e[r]);return n},X3;(e=>{let t=class t{constructor(e,n,r,a){if(this.version=e,this.errorCorrectionLevel=n,this.modules=[],this.isFunction=[],et.MAX_VERSION)throw RangeError(`Version value out of range`);if(a<-1||a>7)throw RangeError(`Mask value out of range`);this.size=e*4+17;let o=[];for(let e=0;e7)throw RangeError(`Invalid value`);let u,d;for(u=a;;u++){let n=t.getNumDataCodewords(u,r)*8,i=o.getTotalBits(e,u);if(i<=n){d=i;break}if(u>=s)throw RangeError(`Data too long`)}for(let e of[t.Ecc.MEDIUM,t.Ecc.QUARTILE,t.Ecc.HIGH])l&&d<=t.getNumDataCodewords(u,e)*8&&(r=e);let f=[];for(let t of e){n(t.mode.modeBits,4,f),n(t.numChars,t.mode.numCharCountBits(u),f);for(let e of t.getData())f.push(e)}i(f.length==d);let p=t.getNumDataCodewords(u,r)*8;i(f.length<=p),n(0,Math.min(4,p-f.length),f),n(0,(8-f.length%8)%8,f),i(f.length%8==0);for(let e=236;f.lengthm[t>>>3]|=e<<7-(t&7)),new t(u,r,m,c)}getModule(e,t){return 0<=e&&e>>9)*1335;let a=(t<<10|n)^21522;i(a>>>15==0);for(let e=0;e<=5;e++)this.setFunctionModule(8,e,r(a,e));this.setFunctionModule(8,7,r(a,6)),this.setFunctionModule(8,8,r(a,7)),this.setFunctionModule(7,8,r(a,8));for(let e=9;e<15;e++)this.setFunctionModule(14-e,8,r(a,e));for(let e=0;e<8;e++)this.setFunctionModule(this.size-1-e,8,r(a,e));for(let e=8;e<15;e++)this.setFunctionModule(8,this.size-15+e,r(a,e));this.setFunctionModule(8,this.size-8,!0)}drawVersion(){if(this.version<7)return;let e=this.version;for(let t=0;t<12;t++)e=e<<1^(e>>>11)*7973;let t=this.version<<12|e;i(t>>>18==0);for(let e=0;e<18;e++){let n=r(t,e),i=this.size-11+e%3,a=Math.floor(e/3);this.setFunctionModule(i,a,n),this.setFunctionModule(a,i,n)}}drawFinderPattern(e,t){for(let n=-4;n<=4;n++)for(let r=-4;r<=4;r++){let i=Math.max(Math.abs(r),Math.abs(n)),a=e+r,o=t+n;0<=a&&a{(e!=l-o||n>=c)&&f.push(t[e])});return i(f.length==s),f}drawCodewords(e){if(e.length!=Math.floor(t.getNumRawDataModules(this.version)/8))throw RangeError(`Invalid argument`);let n=0;for(let t=this.size-1;t>=1;t-=2){t==6&&(t=5);for(let i=0;i>>3],7-(n&7)),n++)}}i(n==e.length*8)}applyMask(e){if(e<0||e>7)throw RangeError(`Mask value out of range`);for(let t=0;t5&&e++):(this.finderPenaltyAddHistory(i,a),r||(e+=this.finderPenaltyCountPatterns(a)*t.PENALTY_N3),r=this.modules[n][o],i=1);e+=this.finderPenaltyTerminateAndCount(r,i,a)*t.PENALTY_N3}for(let n=0;n5&&e++):(this.finderPenaltyAddHistory(i,a),r||(e+=this.finderPenaltyCountPatterns(a)*t.PENALTY_N3),r=this.modules[o][n],i=1);e+=this.finderPenaltyTerminateAndCount(r,i,a)*t.PENALTY_N3}for(let n=0;ne+ +!!t,n);let r=this.size*this.size,a=Math.ceil(Math.abs(n*20-r*10)/r)-1;return i(0<=a&&a<=9),e+=a*t.PENALTY_N4,i(0<=e&&e<=2568888),e}getAlignmentPatternPositions(){if(this.version==1)return[];{let e=Math.floor(this.version/7)+2,t=this.version==32?26:Math.ceil((this.version*4+4)/(e*2-2))*2,n=[6];for(let r=this.size-7;n.lengtht.MAX_VERSION)throw RangeError(`Version number out of range`);let n=(16*e+128)*e+64;if(e>=2){let t=Math.floor(e/7)+2;n-=(25*t-10)*t-55,e>=7&&(n-=36)}return i(208<=n&&n<=29648),n}static getNumDataCodewords(e,n){return Math.floor(t.getNumRawDataModules(e)/8)-t.ECC_CODEWORDS_PER_BLOCK[n.ordinal][e]*t.NUM_ERROR_CORRECTION_BLOCKS[n.ordinal][e]}static reedSolomonComputeDivisor(e){if(e<1||e>255)throw RangeError(`Degree out of range`);let n=[];for(let t=0;t0);for(let i of e){let e=i^r.shift();r.push(0),n.forEach((n,i)=>r[i]^=t.reedSolomonMultiply(n,e))}return r}static reedSolomonMultiply(e,t){if(e>>>8||t>>>8)throw RangeError(`Byte out of range`);let n=0;for(let r=7;r>=0;r--)n=n<<1^(n>>>7)*285,n^=(t>>>r&1)*e;return i(n>>>8==0),n}finderPenaltyCountPatterns(e){let t=e[1];i(t<=this.size*3);let n=t>0&&e[2]==t&&e[3]==t*3&&e[4]==t&&e[5]==t;return(n&&e[0]>=t*4&&e[6]>=t?1:0)+(n&&e[6]>=t*4&&e[0]>=t?1:0)}finderPenaltyTerminateAndCount(e,t,n){return e&&(this.finderPenaltyAddHistory(t,n),t=0),t+=this.size,this.finderPenaltyAddHistory(t,n),this.finderPenaltyCountPatterns(n)}finderPenaltyAddHistory(e,t){t[0]==0&&(e+=this.size),t.pop(),t.unshift(e)}};t.MIN_VERSION=1,t.MAX_VERSION=40,t.PENALTY_N1=3,t.PENALTY_N2=3,t.PENALTY_N3=40,t.PENALTY_N4=10,t.ECC_CODEWORDS_PER_BLOCK=[[-1,7,10,15,20,26,18,20,24,30,18,20,24,26,30,22,24,28,30,28,28,28,28,30,30,26,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,10,16,26,18,24,16,18,22,22,26,30,22,22,24,24,28,28,26,26,26,26,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28],[-1,13,22,18,26,18,24,18,22,20,24,28,26,24,20,30,24,28,28,26,30,28,30,30,30,30,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,17,28,22,16,22,28,26,26,24,28,24,28,22,24,24,30,28,28,26,28,30,24,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30]],t.NUM_ERROR_CORRECTION_BLOCKS=[[-1,1,1,1,1,1,2,2,2,2,4,4,4,4,4,6,6,6,6,7,8,8,9,9,10,12,12,12,13,14,15,16,17,18,19,19,20,21,22,24,25],[-1,1,1,1,2,2,4,4,4,5,5,5,8,9,9,10,10,11,13,14,16,17,17,18,20,21,23,25,26,28,29,31,33,35,37,38,40,43,45,47,49],[-1,1,1,2,2,4,4,6,6,8,8,8,10,12,16,12,17,16,18,21,20,23,23,25,27,29,34,34,35,38,40,43,45,48,51,53,56,59,62,65,68],[-1,1,1,2,4,4,4,5,6,8,8,11,11,16,16,18,16,19,21,25,25,25,34,30,32,35,37,40,42,45,48,51,54,57,60,63,66,70,74,77,81]],e.QrCode=t;function n(e,t,n){if(t<0||t>31||e>>>t)throw RangeError(`Value out of range`);for(let r=t-1;r>=0;r--)n.push(e>>>r&1)}function r(e,t){return(e>>>t&1)!=0}function i(e){if(!e)throw Error(`Assertion error`)}let a=class e{constructor(e,t,n){if(this.mode=e,this.numChars=t,this.bitData=n,t<0)throw RangeError(`Invalid argument`);this.bitData=n.slice()}static makeBytes(t){let r=[];for(let e of t)n(e,8,r);return new e(e.Mode.BYTE,t.length,r)}static makeNumeric(t){if(!e.isNumeric(t))throw RangeError(`String contains non-numeric characters`);let r=[];for(let e=0;e=1<{(e=>{let t=class{constructor(e,t){this.ordinal=e,this.formatBits=t}};t.LOW=new t(0,1),t.MEDIUM=new t(1,0),t.QUARTILE=new t(2,3),t.HIGH=new t(3,2),e.Ecc=t})(e.QrCode||={})})(X3||={}),(e=>{(e=>{let t=class{constructor(e,t){this.modeBits=e,this.numBitsCharCount=t}numCharCountBits(e){return this.numBitsCharCount[Math.floor((e+7)/17)]}};t.NUMERIC=new t(1,[10,12,14]),t.ALPHANUMERIC=new t(2,[9,11,13]),t.BYTE=new t(4,[8,16,16]),t.KANJI=new t(8,[8,10,12]),t.ECI=new t(7,[0,0,0]),e.Mode=t})(e.QrSegment||={})})(X3||={});var Z3=X3,UVe={L:Z3.QrCode.Ecc.LOW,M:Z3.QrCode.Ecc.MEDIUM,Q:Z3.QrCode.Ecc.QUARTILE,H:Z3.QrCode.Ecc.HIGH},Q3=128,$3=`L`,e6=`#FFFFFF`,t6=`#000000`,n6=!1,r6=1,WVe=4,GVe=0,KVe=.1;function i6(e,t=0){let n=[];return e.forEach(function(e,r){let i=null;e.forEach(function(a,o){if(!a&&i!==null){n.push(`M${i+t} ${r+t}h${o-i}v1H${i+t}z`),i=null;return}if(o===e.length-1){if(!a)return;i===null?n.push(`M${o+t},${r+t} h1v1H${o+t}z`):n.push(`M${i+t},${r+t} h${o+1-i}v1H${i+t}z`);return}a&&i===null&&(i=o)})}),n.join(``)}function a6(e,t){return e.slice().map((e,n)=>n=t.y+t.h?e:e.map((e,n)=>n=t.x+t.w?e:!1))}function qVe(e,t,n,r){if(r==null)return null;let i=e.length+n*2,a=Math.floor(t*KVe),o=i/t,s=(r.width||a)*o,c=(r.height||a)*o,l=r.x==null?e.length/2-s/2:r.x*o,u=r.y==null?e.length/2-c/2:r.y*o,d=r.opacity==null?1:r.opacity,f=null;if(r.excavate){let e=Math.floor(l),t=Math.floor(u);f={x:e,y:t,w:Math.ceil(s+l-e),h:Math.ceil(c+u-t)}}let p=r.crossOrigin;return{x:l,y:u,h:c,w:s,excavation:f,opacity:d,crossOrigin:p}}function JVe(e,t){return t==null?e?WVe:GVe:Math.max(Math.floor(t),0)}function o6({value:e,level:t,minVersion:n,includeMargin:r,marginSize:i,imageSettings:a,size:o,boostLevel:s}){let c=y.useMemo(()=>{let r=(Array.isArray(e)?e:[e]).reduce((e,t)=>(e.push(...Z3.QrSegment.makeSegments(t)),e),[]);return Z3.QrCode.encodeSegments(r,UVe[t],n,void 0,void 0,s)},[e,t,n,s]),{cells:l,margin:u,numCells:d,calculatedImageSettings:f}=y.useMemo(()=>{let e=c.getModules(),t=JVe(r,i);return{cells:e,margin:t,numCells:e.length+t*2,calculatedImageSettings:qVe(e,o,t,a)}},[c,o,a,r,i]);return{qrcode:c,margin:u,cells:l,numCells:d,calculatedImageSettings:f}}var YVe=function(){try{new Path2D().addPath(new Path2D)}catch{return!1}return!0}(),XVe=y.forwardRef(function(e,t){let n=e,{value:r,size:i=Q3,level:a=$3,bgColor:o=e6,fgColor:s=t6,includeMargin:c=n6,minVersion:l=r6,boostLevel:u,marginSize:d,imageSettings:f}=n,p=Y3(n,[`value`,`size`,`level`,`bgColor`,`fgColor`,`includeMargin`,`minVersion`,`boostLevel`,`marginSize`,`imageSettings`]),{style:m}=p,h=Y3(p,[`style`]),g=f?.src,_=y.useRef(null),v=y.useRef(null),b=y.useCallback(e=>{_.current=e,typeof t==`function`?t(e):t&&(t.current=e)},[t]),[x,S]=y.useState(!1),{margin:C,cells:w,numCells:T,calculatedImageSettings:E}=o6({value:r,level:a,minVersion:l,boostLevel:u,includeMargin:c,marginSize:d,imageSettings:f,size:i});y.useEffect(()=>{if(_.current!=null){let e=_.current,t=e.getContext(`2d`);if(!t)return;let n=w,r=v.current,a=E!=null&&r!==null&&r.complete&&r.naturalHeight!==0&&r.naturalWidth!==0;a&&E.excavation!=null&&(n=a6(w,E.excavation));let c=window.devicePixelRatio||1;e.height=e.width=i*c;let l=i/T*c;t.scale(l,l),t.fillStyle=o,t.fillRect(0,0,T,T),t.fillStyle=s,YVe?t.fill(new Path2D(i6(n,C))):w.forEach(function(e,n){e.forEach(function(e,r){e&&t.fillRect(r+C,n+C,1,1)})}),E&&(t.globalAlpha=E.opacity),a&&t.drawImage(r,E.x+C,E.y+C,E.w,E.h)}}),y.useEffect(()=>{S(!1)},[g]);let D=J3({height:i,width:i},m),O=null;return g!=null&&(O=y.createElement(`img`,{src:g,key:g,style:{display:`none`},onLoad:()=>{S(!0)},ref:v,crossOrigin:E?.crossOrigin})),y.createElement(y.Fragment,null,y.createElement(`canvas`,J3({style:D,height:i,width:i,ref:b,role:`img`},h)),O)});XVe.displayName=`QRCodeCanvas`;var s6=y.forwardRef(function(e,t){let n=e,{value:r,size:i=Q3,level:a=$3,bgColor:o=e6,fgColor:s=t6,includeMargin:c=n6,minVersion:l=r6,boostLevel:u,title:d,marginSize:f,imageSettings:p}=n,m=Y3(n,[`value`,`size`,`level`,`bgColor`,`fgColor`,`includeMargin`,`minVersion`,`boostLevel`,`title`,`marginSize`,`imageSettings`]),{margin:h,cells:g,numCells:_,calculatedImageSettings:v}=o6({value:r,level:a,minVersion:l,boostLevel:u,includeMargin:c,marginSize:f,imageSettings:p,size:i}),b=g,x=null;p!=null&&v!=null&&(v.excavation!=null&&(b=a6(g,v.excavation)),x=y.createElement(`image`,{href:p.src,height:v.h,width:v.w,x:v.x+h,y:v.y+h,preserveAspectRatio:`none`,opacity:v.opacity,crossOrigin:v.crossOrigin}));let S=i6(b,h);return y.createElement(`svg`,J3({height:i,width:i,viewBox:`0 0 ${_} ${_}`,ref:t,role:`img`},m),!!d&&y.createElement(`title`,null,d),y.createElement(`path`,{fill:o,d:`M0,0 h${_}v${_}H0z`,shapeRendering:`crispEdges`}),y.createElement(`path`,{fill:s,d:S,shapeRendering:`crispEdges`}),x)});s6.displayName=`QRCodeSVG`;function ZVe(e,t){return`bambuddy://config?v=1&url=${encodeURIComponent(e)}&key=${encodeURIComponent(t)}`}function QVe({apiKey:e,baseUrl:t,onClose:n}){let{t:r}=U(),i=ZVe(t??window.location.origin,e);return(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[n]),(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:n,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-sm`,onClick:e=>e.stopPropagation(),children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:r(`settings.apiKeyQrTitle`)}),(0,G.jsx)(`button`,{onClick:n,className:`text-bambu-gray hover:text-white transition-colors`,"aria-label":r(`common.close`),children:(0,G.jsx)($u,{className:`w-5 h-5`})})]}),(0,G.jsxs)(`div`,{className:`p-6 flex flex-col items-center`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4 text-center`,children:r(`settings.apiKeyQrCaption`)}),(0,G.jsx)(`div`,{className:`bg-white p-4 rounded-lg mb-4`,children:(0,G.jsx)(s6,{value:i,size:256})}),(0,G.jsxs)(`div`,{className:`flex items-start gap-2 text-xs text-amber-700 dark:text-amber-400 mb-4`,children:[(0,G.jsx)(Pu,{className:`w-4 h-4 flex-shrink-0 mt-0.5`}),(0,G.jsx)(`span`,{children:r(`settings.apiKeyQrWarning`)})]}),(0,G.jsx)(Q,{onClick:n,className:`w-full`,children:r(`common.close`)})]})]})})}var $Ve=300,c6=2;function l6({onSuccess:e}){let{t}=U(),n=so(),[r,i]=(0,y.useState)(``),[a,o]=(0,y.useState)(``),[s,c]=(0,y.useState)(null),[l,u]=(0,y.useState)(null);(0,y.useEffect)(()=>{let e=r.trim();if(e.lengtho(e),$Ve);return()=>clearTimeout(t)},[r]),(0,y.useEffect)(()=>{c(null),u(null)},[a]);let d=K({queryKey:[`ldap-search`,a],queryFn:()=>Z.searchLDAPDirectory(a),enabled:a.length>=c6,staleTime:3e4}),f=q({mutationFn:e=>Z.provisionLDAPUser(e),onSuccess:t=>{n.invalidateQueries({queryKey:[`users`]}),e(t)},onError:e=>{u(e.message||t(`users.modal.ldapErrorProvision`))}}),p=(0,y.useMemo)(()=>d.data?.find(e=>e.dn===s)??null,[d.data,s]),m=r.trim().length>0&&r.trim().length=c6,g=!!d.data&&d.data.length>0,_=!h&&!!d.data&&d.data.length===0&&a.length>=c6;return(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:t(`users.modal.ldapSearchLabel`)}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(Yl,{className:`w-4 h-4 text-bambu-gray absolute left-3 top-1/2 -translate-y-1/2`}),(0,G.jsx)(`input`,{type:`text`,value:r,onChange:e=>i(e.target.value),className:`w-full pl-9 pr-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:t(`users.modal.ldapSearchPlaceholder`),autoComplete:`off`})]}),m&&(0,G.jsx)(`p`,{className:`mt-1 text-xs text-bambu-gray`,children:t(`users.modal.ldapMinChars`)})]}),(0,G.jsxs)(`div`,{className:`min-h-[8rem] max-h-64 overflow-y-auto bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg`,children:[h&&(0,G.jsxs)(`div`,{className:`flex items-center justify-center py-8 text-bambu-gray`,children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin mr-2`}),(0,G.jsx)(`span`,{children:t(`users.modal.ldapSearching`)})]}),_&&(0,G.jsx)(`div`,{className:`flex items-center justify-center py-8 text-bambu-gray text-sm`,children:t(`users.modal.ldapNoResults`)}),d.isError&&(0,G.jsx)(`div`,{className:`px-3 py-4 text-sm text-red-700 dark:text-red-400`,children:d.error instanceof Error?d.error.message:t(`users.modal.ldapSearchError`)}),!h&&g&&(0,G.jsx)(`ul`,{className:`divide-y divide-bambu-dark-tertiary`,children:d.data.map(e=>(0,G.jsx)(eHe,{result:e,selected:s===e.dn,onSelect:()=>c(e.dn)},e.dn))}),!h&&!d.data&&!d.isError&&(0,G.jsx)(`div`,{className:`flex items-center justify-center py-8 text-bambu-gray text-sm`,children:t(`users.modal.ldapTypeToSearch`)})]}),p&&(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary/50 border border-bambu-green/20 rounded-lg p-3 space-y-1`,children:[(0,G.jsxs)(`p`,{className:`text-sm text-white`,children:[(0,G.jsxs)(`span`,{className:`text-bambu-gray`,children:[t(`users.modal.ldapSelectedLabel`),`: `]}),(0,G.jsx)(`span`,{className:`font-medium`,children:p.username}),p.display_name&&(0,G.jsxs)(`span`,{className:`text-bambu-gray`,children:[` — `,p.display_name]})]}),p.email&&(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:p.email}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray break-all`,children:p.dn})]}),l&&(0,G.jsx)(`div`,{className:`bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30 rounded-lg p-3`,children:(0,G.jsx)(`p`,{className:`text-sm text-red-700 dark:text-red-400`,children:l})}),(0,G.jsx)(`div`,{className:`flex justify-end`,children:(0,G.jsx)(Q,{onClick:()=>{!p||p.already_provisioned||(u(null),f.mutate(p.username))},disabled:!p||p.already_provisioned||f.isPending,children:f.isPending?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),t(`users.modal.ldapProvisioning`)]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Ml,{className:`w-4 h-4`}),t(`users.modal.ldapProvision`)]})})})]})}function eHe({result:e,selected:t,onSelect:n}){let{t:r}=U(),i=e.already_provisioned;return(0,G.jsx)(`li`,{children:(0,G.jsxs)(`button`,{type:`button`,onClick:n,disabled:i,className:`w-full text-left px-3 py-2 flex items-center gap-3 transition-colors ${i?`opacity-50 cursor-not-allowed`:t?`bg-bambu-green/10`:`hover:bg-bambu-dark-tertiary`}`,children:[(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsxs)(`p`,{className:`text-sm text-white truncate`,children:[(0,G.jsx)(`span`,{className:`font-medium`,children:e.username}),e.display_name&&(0,G.jsxs)(`span`,{className:`text-bambu-gray`,children:[` — `,e.display_name]})]}),e.email&&(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray truncate`,children:e.email})]}),i&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-xs text-bambu-gray whitespace-nowrap`,children:[(0,G.jsx)(bs,{className:`w-3.5 h-3.5`}),r(`users.modal.ldapAlreadyProvisioned`)]})]})})}function tHe({formData:e,setFormData:t,groups:n,onClose:r,onCreate:i,isCreating:a,isCreateButtonDisabled:o,ldapEnabled:s=!1,onLdapProvisioned:c}){let{t:l}=U(),[u,d]=(0,y.useState)(`local`);(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&r()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[r]);let f=n=>{t({...e,group_ids:e.group_ids.includes(n)?e.group_ids.filter(e=>e!==n):[...e.group_ids,n]})};return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:r,children:(0,G.jsxs)(Md,{className:`w-full max-w-md`,onClick:e=>e.stopPropagation(),children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Bu,{className:`w-5 h-5 text-bambu-green`}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:l(`users.modal.createUser`)})]}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray ml-7`,children:l(`users.modal.advancedAuthSubtitle`)||`with Advanced Authentication`})]}),(0,G.jsx)(Q,{variant:`ghost`,size:`sm`,onClick:r,children:(0,G.jsx)($u,{className:`w-5 h-5`})})]})}),(0,G.jsxs)(Pd,{children:[s&&(0,G.jsxs)(`div`,{className:`mb-4 flex items-center gap-1 p-1 bg-bambu-dark-secondary rounded-lg`,role:`tablist`,"aria-label":l(`users.modal.tabsAriaLabel`),children:[(0,G.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":u===`local`,onClick:()=>d(`local`),className:`flex-1 px-3 py-2 text-sm rounded-md transition-colors ${u===`local`?`bg-bambu-green/15 text-bambu-green`:`text-bambu-gray hover:text-white`}`,children:l(`users.modal.localTab`)}),(0,G.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":u===`ldap`,onClick:()=>d(`ldap`),className:`flex-1 px-3 py-2 text-sm rounded-md transition-colors ${u===`ldap`?`bg-bambu-green/15 text-bambu-green`:`text-bambu-gray hover:text-white`}`,children:l(`users.modal.ldapTab`)})]}),u===`ldap`&&s?(0,G.jsx)(l6,{onSuccess:e=>{c?.(e)}}):(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:[l(`users.form.username`),` `,(0,G.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:`*`})]}),(0,G.jsx)(`input`,{type:`text`,value:e.username,onChange:n=>t({...e,username:n.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:l(`users.form.usernamePlaceholder`),autoComplete:`username`,required:!0})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:[l(`users.form.email`)||`Email`,` `,(0,G.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:`*`})]}),(0,G.jsx)(`input`,{type:`email`,value:e.email,onChange:n=>t({...e,email:n.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:l(`users.form.emailPlaceholder`)||`user@example.com`,required:!0})]}),(0,G.jsx)(`div`,{className:`bg-bambu-dark-secondary/50 border border-bambu-green/20 rounded-lg p-3`,children:(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:l(`users.form.autoGeneratedPassword`)||`A secure password will be automatically generated and emailed to the user.`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:l(`users.form.groups`)}),(0,G.jsxs)(`div`,{className:`space-y-2 max-h-40 overflow-y-auto p-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg`,children:[n.map(t=>(0,G.jsxs)(`label`,{className:`flex items-center gap-3 px-2 py-1.5 rounded hover:bg-bambu-dark-tertiary cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:e.group_ids.includes(t.id),onChange:()=>f(t.id),className:`w-4 h-4 rounded border-bambu-gray text-bambu-green focus:ring-bambu-green focus:ring-offset-0 bg-bambu-dark`}),(0,G.jsx)(`span`,{className:`text-sm text-white`,children:t.name}),t.is_system&&(0,G.jsxs)(`span`,{className:`text-xs text-yellow-700 dark:text-yellow-400`,children:[`(`,l(`users.system`),`)`]})]},t.id)),n.length===0&&(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:l(`users.noGroupsAvailable`)})]})]})]}),(0,G.jsxs)(`div`,{className:`mt-6 flex justify-end gap-3`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:r,children:l(`users.modal.cancel`)}),u===`local`&&(0,G.jsx)(Q,{onClick:i,disabled:o,children:a?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),l(`users.modal.creating`)]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Ml,{className:`w-4 h-4`}),l(`users.modal.createUser`)]})})]})]})]})})}function nHe(){let{t:e}=U(),t=so(),{showToast:n}=Bd(),[r,i]=(0,y.useState)(!1),[a,o]=(0,y.useState)(``),[s,c]=(0,y.useState)(`auto`),[l,u]=(0,y.useState)(!1),[d,f]=(0,y.useState)(!0),[p,m]=(0,y.useState)(!0),[h,g]=(0,y.useState)(`all`),[_,v]=(0,y.useState)(!1),[b,x]=(0,y.useState)(!1),[S,C]=(0,y.useState)(!1),[w,T]=(0,y.useState)(!1),{data:E,isLoading:D}=K({queryKey:[`spoolman-settings`],queryFn:Z.getSpoolmanSettings}),{data:O,isLoading:k,refetch:A}=K({queryKey:[`spoolman-status`],queryFn:Z.getSpoolmanStatus,refetchInterval:3e4}),{data:j}=K({queryKey:[`printers`],queryFn:Z.getPrinters});(0,y.useEffect)(()=>{E&&(i(E.spoolman_enabled===`true`),o(E.spoolman_url||``),c(E.spoolman_sync_mode||`auto`),u(E.spoolman_disable_weight_sync===`true`),f(E.spoolman_report_partial_usage!==`false`),m(E.auto_add_unknown_rfid!==`false`),v(!0))},[E]),(0,y.useEffect)(()=>{if(!(!_||!E)&&(E.spoolman_enabled===`true`!==r||(E.spoolman_url||``)!==a||(E.spoolman_sync_mode||`auto`)!==s||E.spoolman_disable_weight_sync===`true`!==l||E.spoolman_report_partial_usage!==`false`!==d||E.auto_add_unknown_rfid!==`false`!==p)){let e=setTimeout(()=>{M.mutate()},500);return()=>clearTimeout(e)}},[r,a,s,l,d,p,_]);let M=q({mutationFn:()=>Z.updateSpoolmanSettings({spoolman_enabled:r?`true`:`false`,spoolman_url:a,spoolman_sync_mode:s,spoolman_disable_weight_sync:l?`true`:`false`,spoolman_report_partial_usage:d?`true`:`false`,auto_add_unknown_rfid:p?`true`:`false`}),onSuccess:()=>{t.invalidateQueries({queryKey:[`spoolman-settings`]}),t.invalidateQueries({queryKey:[`spoolman-status`]}),t.invalidateQueries({queryKey:[`spool-assignments`]}),t.invalidateQueries({queryKey:[`settings`]}),t.invalidateQueries({queryKey:[`spoolman-inventory-filaments`]}),n(e(`settings.toast.settingsSaved`))},onError:()=>{n(e(`settings.toast.saveFailed`),`error`)}}),N=q({mutationFn:Z.connectSpoolman,onSuccess:()=>{A()},onError:()=>{n(e(`settings.toast.saveFailed`),`error`)}}),P=q({mutationFn:Z.disconnectSpoolman,onSuccess:()=>{A()},onError:()=>{n(e(`settings.toast.saveFailed`),`error`)}}),F=q({mutationFn:Z.syncAllPrintersAms,onSuccess:t=>{n(e(`settings.spoolmanAmsSyncSuccess`,{synced:t.synced_count,skipped:0}),`success`)},onError:()=>{n(e(`settings.toast.saveFailed`),`error`)}}),I=q({mutationFn:e=>Z.syncPrinterAms(e),onSuccess:t=>{n(e(`settings.spoolmanAmsSyncSuccess`,{synced:t.synced_count,skipped:0}),`success`)},onError:()=>{n(e(`settings.toast.saveFailed`),`error`)}}),L=()=>{h===`all`?F.mutate():I.mutate(h)},R=q({mutationFn:Z.syncWeightsFromAms,onSuccess:r=>{t.invalidateQueries({queryKey:[`spools`]}),t.invalidateQueries({queryKey:[`inventory-spools`]}),n(e(`settings.amsSyncSuccess`,{synced:r.synced,skipped:r.skipped}),`success`),C(!1)},onError:()=>{n(e(`settings.amsSyncError`),`error`),C(!1)}}),z=q({mutationFn:Z.syncSpoolmanAmsWeights,onSuccess:r=>{t.invalidateQueries({queryKey:[`spoolman-inventory-spools`]}),n(e(`settings.spoolmanAmsSyncSuccess`,{synced:r.synced,skipped:r.skipped}),`success`),T(!1)},onError:t=>{t instanceof id&&t.status===503?n(e(`settings.spoolmanAmsSyncErrorUnreachable`),`error`):t instanceof id&&t.status===400?n(e(`settings.spoolmanAmsSyncErrorNotConfigured`),`error`):n(e(`settings.spoolmanAmsSyncError`),`error`),T(!1)}}),B=F.isPending||I.isPending,V=h===`all`?F.data:I.data,ee=h===`all`?F.isSuccess:I.isSuccess;return D?(0,G.jsxs)(Md,{id:`card-spoolman`,children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Us,{className:`w-5 h-5 text-bambu-green`}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`settings.filamentTracking`)})]})}),(0,G.jsx)(Pd,{children:(0,G.jsx)(`div`,{className:`flex justify-center py-8`,children:(0,G.jsx)(Y,{className:`w-6 h-6 text-bambu-green animate-spin`})})})]}):(0,G.jsxs)(Md,{id:`card-spoolman`,children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Us,{className:`w-5 h-5 text-bambu-green`}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`settings.filamentTracking`)})]}),M.isPending&&(0,G.jsx)(Y,{className:`w-4 h-4 text-bambu-green animate-spin`})]})}),(0,G.jsxs)(Pd,{className:`space-y-4`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`settings.filamentTrackingDesc`)}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,G.jsxs)(`button`,{type:`button`,onClick:()=>i(!1),className:`p-3 rounded-lg border-2 text-left transition-colors ${r?`border-bambu-dark-tertiary bg-bambu-dark hover:border-bambu-gray/50`:`border-bambu-green bg-bambu-green/10`}`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-1.5`,children:[(0,G.jsx)(xl,{className:`w-4 h-4 ${r?`text-bambu-gray`:`text-bambu-green`}`}),(0,G.jsx)(`span`,{className:`text-sm font-medium ${r?`text-bambu-gray`:`text-white`}`,children:e(`settings.trackingModeBuiltIn`)})]}),(0,G.jsx)(`p`,{className:`text-xs ${r?`text-bambu-gray/60`:`text-bambu-gray`}`,children:e(`settings.trackingModeBuiltInDesc`)}),!r&&(0,G.jsxs)(`div`,{className:`flex items-center gap-1 mt-2`,children:[(0,G.jsx)(us,{className:`w-3 h-3 text-bambu-green`}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-green`,children:e(`common.enabled`)})]})]}),(0,G.jsxs)(`button`,{type:`button`,onClick:()=>i(!0),className:`p-3 rounded-lg border-2 text-left transition-colors ${r?`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary bg-bambu-dark hover:border-bambu-gray/50`}`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-1.5`,children:[(0,G.jsx)(tc,{className:`w-4 h-4 ${r?`text-bambu-green`:`text-bambu-gray`}`}),(0,G.jsx)(`span`,{className:`text-sm font-medium ${r?`text-white`:`text-bambu-gray`}`,children:`Spoolman`})]}),(0,G.jsx)(`p`,{className:`text-xs ${r?`text-bambu-gray`:`text-bambu-gray/60`}`,children:e(`settings.trackingModeSpoolmanDesc`)}),r&&(0,G.jsxs)(`div`,{className:`flex items-center gap-1 mt-2`,children:[(0,G.jsx)(us,{className:`w-3 h-3 text-bambu-green`}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-green`,children:e(`common.enabled`)})]})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between pt-2 border-t border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`pr-4`,children:[(0,G.jsx)(`p`,{className:`text-white`,children:e(`settings.autoAddUnknownRfid`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`settings.autoAddUnknownRfidDesc`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:p,onChange:e=>m(e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),!r&&(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsx)(`div`,{className:`p-3 bg-bambu-green/5 border border-bambu-green/20 rounded-lg`,children:(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsx)(Vc,{className:`w-4 h-4 text-bambu-green flex-shrink-0 mt-0.5`}),(0,G.jsx)(`div`,{className:`text-xs text-bambu-gray`,children:(0,G.jsxs)(`ul`,{className:`list-disc list-inside space-y-0.5`,children:[(0,G.jsx)(`li`,{children:e(`settings.builtInFeatureRfid`)}),(0,G.jsx)(`li`,{children:e(`settings.builtInFeatureUsage`)}),(0,G.jsx)(`li`,{children:e(`settings.builtInFeatureCatalog`)}),(0,G.jsx)(`li`,{children:e(`settings.builtInFeatureThirdParty`)})]})})]})}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:()=>C(!0),disabled:R.isPending,children:[R.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 mr-2 animate-spin`}):(0,G.jsx)(zl,{className:`w-4 h-4 mr-2`}),e(`settings.amsSyncButton`)]})]}),r&&(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsx)(`div`,{className:`p-3 bg-blue-50 dark:bg-blue-500/10 border border-blue-300 dark:border-blue-500/30 rounded-lg`,children:(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsx)(Vc,{className:`w-4 h-4 text-blue-600 dark:text-blue-400 flex-shrink-0 mt-0.5`}),(0,G.jsxs)(`div`,{className:`text-xs text-blue-700 dark:text-blue-300`,children:[(0,G.jsx)(`p`,{className:`font-medium mb-1`,children:e(`settings.howSyncWorks`)}),(0,G.jsxs)(`ul`,{className:`list-disc list-inside space-y-0.5 text-blue-700/90 dark:text-blue-300/80`,children:[(0,G.jsx)(`li`,{children:e(`settings.syncInfoRfidOnly`)}),(0,G.jsx)(`li`,{children:e(`settings.syncInfoAutoCreate`)}),(0,G.jsx)(`li`,{children:e(`settings.syncInfoThirdPartySkipped`)})]}),(0,G.jsx)(`p`,{className:`font-medium mt-2 mb-1`,children:e(`settings.linkingExistingSpools`)}),(0,G.jsx)(`p`,{className:`text-blue-700/90 dark:text-blue-300/80`,children:e(`settings.linkingExistingSpoolsDesc`)})]})]})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:e(`settings.spoolmanUrl`)}),(0,G.jsx)(`input`,{type:`text`,placeholder:`http://192.168.1.100:7912`,value:a,onChange:e=>o(e.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`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`settings.spoolmanUrlHint`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:e(`settings.syncMode`)}),(0,G.jsxs)(`select`,{value:s,onChange:e=>c(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,G.jsx)(`option`,{value:`auto`,children:e(`settings.syncModeAuto`)}),(0,G.jsx)(`option`,{value:`manual`,children:e(`settings.syncModeManual`)})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(s===`auto`?`settings.syncModeAutoDesc`:`settings.syncModeManualDesc`)})]}),s===`auto`&&(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:e(`spoolman.disableWeightSync`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`spoolman.disableWeightSyncDesc`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:l,onChange:e=>u(e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),l&&(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:e(`spoolman.reportPartialUsage`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`spoolman.reportPartialUsageDesc`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:d,onChange:e=>f(e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,G.jsxs)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[e(`settings.status`),`:`]}),k?(0,G.jsx)(Y,{className:`w-4 h-4 text-bambu-gray animate-spin`}):O?.connected?(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-sm text-green-500`,children:[(0,G.jsx)(us,{className:`w-4 h-4`}),e(`settings.spoolmanConnected`)]}):(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-sm text-red-500`,children:[(0,G.jsx)($u,{className:`w-4 h-4`}),e(`settings.spoolmanDisconnected`)]})]}),(0,G.jsx)(`div`,{className:`flex gap-2`,children:O?.connected?(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:()=>P.mutate(),disabled:P.isPending,children:[P.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(qc,{className:`w-4 h-4`}),e(`settings.disconnect`)]}):(0,G.jsxs)(Q,{size:`sm`,onClick:()=>N.mutate(),disabled:N.isPending||!a,children:[N.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Jc,{className:`w-4 h-4`}),e(`settings.connect`)]})})]}),(N.isError||P.isError)&&(0,G.jsx)(`div`,{className:`mb-3 p-2 bg-red-100 dark:bg-red-500/20 border border-red-300 dark:border-red-500/50 rounded text-sm text-red-700 dark:text-red-400`,children:(N.error||P.error).message}),O?.connected&&(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:e(`settings.syncAmsData`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:e(`settings.syncAmsDataDesc`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`div`,{className:`relative flex-1`,children:[(0,G.jsxs)(`select`,{value:h,onChange:e=>g(e.target.value===`all`?`all`:Number(e.target.value)),className:`w-full px-3 py-2 pr-8 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none appearance-none cursor-pointer`,children:[(0,G.jsx)(`option`,{value:`all`,children:e(`settings.allPrinters`)}),j?.map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),(0,G.jsx)(ds,{className:`absolute right-2 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:L,disabled:B,children:[B?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(zl,{className:`w-4 h-4`}),e(`spoolman.sync`)]})]})]}),O?.connected&&(0,G.jsx)(`div`,{className:`mt-4 pt-4 border-t border-bambu-dark-tertiary`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:e(`settings.spoolmanAmsSyncButton`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:e(`settings.spoolmanAmsSyncMessage`)})]}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:()=>T(!0),disabled:z.isPending,children:[z.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(zl,{className:`w-4 h-4`}),z.isPending?e(`settings.spoolmanAmsSyncing`):e(`settings.spoolmanAmsSyncButton`)]})]})}),ee&&V&&(0,G.jsxs)(`div`,{className:`mt-3 space-y-2`,children:[(0,G.jsx)(`div`,{className:`p-2 rounded text-sm ${V.success?`bg-green-100 dark:bg-green-500/20 border border-green-300 dark:border-green-500/50 text-green-700 dark:text-green-400`:`bg-yellow-100 dark:bg-yellow-500/20 border border-yellow-300 dark:border-yellow-500/50 text-yellow-700 dark:text-yellow-400`}`,children:V.success?`Synced ${V.synced_count} spool${V.synced_count===1?``:`s`} successfully`:`Synced ${V.synced_count} spool${V.synced_count===1?``:`s`} with ${V.errors.length} error${V.errors.length===1?``:`s`}`}),V.skipped_count>0&&(0,G.jsxs)(`div`,{className:`p-2 bg-amber-50 dark:bg-amber-500/10 border border-amber-300 dark:border-amber-500/30 rounded text-sm`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between text-amber-700 dark:text-amber-400 mb-1`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,G.jsx)(Pu,{className:`w-3.5 h-3.5`}),(0,G.jsxs)(`span`,{className:`font-medium`,children:[V.skipped_count,` spool`,V.skipped_count===1?``:`s`,` skipped`]})]}),V.skipped_count>5&&(0,G.jsx)(`button`,{onClick:()=>x(!b),className:`text-xs text-amber-700 dark:text-amber-400 hover:text-amber-800 dark:hover:text-amber-300 underline`,children:b?`Show less`:`Show all`})]}),(0,G.jsxs)(`ul`,{className:`text-xs text-amber-700/90 dark:text-amber-300/80 space-y-0.5`,children:[(b?V.skipped:V.skipped.slice(0,5)).map((e,t)=>(0,G.jsxs)(`li`,{className:`flex items-center gap-2`,children:[e.color&&(0,G.jsx)(`span`,{className:`w-3 h-3 rounded-full border border-black/20`,style:{backgroundColor:`#${e.color}`}}),(0,G.jsx)(`span`,{children:e.location}),(0,G.jsxs)(`span`,{className:`text-amber-700/70 dark:text-amber-300/60`,children:[`- `,e.reason]})]},t)),!b&&V.skipped_count>5&&(0,G.jsxs)(`li`,{className:`text-amber-700/70 dark:text-amber-300/60 italic`,children:[`...and `,V.skipped_count-5,` more`]})]})]}),V.errors.length>0&&(0,G.jsxs)(`div`,{className:`p-2 bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30 rounded text-sm`,children:[(0,G.jsx)(`div`,{className:`text-red-700 dark:text-red-400 font-medium mb-1`,children:`Errors:`}),(0,G.jsx)(`ul`,{className:`text-xs text-red-700/90 dark:text-red-300/80 space-y-0.5`,children:V.errors.map((e,t)=>(0,G.jsx)(`li`,{children:e},t))})]})]})]})]})]}),S&&(0,G.jsx)(Zd,{title:e(`settings.amsSyncTitle`),message:e(`settings.amsSyncMessage`),confirmText:e(`settings.amsSyncButton`),variant:`warning`,isLoading:R.isPending,loadingText:e(`settings.amsSyncing`),onConfirm:()=>R.mutate(),onCancel:()=>C(!1)}),w&&(0,G.jsx)(Zd,{title:e(`settings.spoolmanAmsSyncTitle`),message:e(`settings.spoolmanAmsSyncMessage`),confirmText:e(`settings.spoolmanAmsSyncButton`),variant:`warning`,isLoading:z.isPending,loadingText:e(`settings.spoolmanAmsSyncing`),onConfirm:()=>z.mutate(),onCancel:()=>T(!1)})]})}function rHe(){let{t:e}=U(),{showToast:t}=Bd(),[n,r]=(0,y.useState)([]),[i,a]=(0,y.useState)(!0),[o,s]=(0,y.useState)(``),c=(0,y.useRef)(null),[l,u]=(0,y.useState)(!1),[d,f]=(0,y.useState)(null),[p,m]=(0,y.useState)(``),[h,g]=(0,y.useState)(``),[_,v]=(0,y.useState)(!1),[b,x]=(0,y.useState)(new Set),[S,C]=(0,y.useState)(!1),[w,T]=(0,y.useState)(null),[E,D]=(0,y.useState)(!1),O=(0,y.useCallback)(async()=>{try{r(await Z.getSpoolCatalog())}catch(n){console.error(`SpoolCatalogSettings.loadCatalog failed:`,n),t(e(`settings.catalog.loadFailed`),`error`)}finally{a(!1)}},[t,e]);(0,y.useEffect)(()=>{O()},[O]);let k=n.filter(e=>e.name.toLowerCase().includes(o.toLowerCase())),A=async()=>{if(!p.trim()||!h){t(e(`settings.catalog.nameWeightRequired`),`error`);return}v(!0);try{let n=await Z.addCatalogEntry({name:p.trim(),weight:parseInt(h)});r(e=>[...e,n].sort((e,t)=>e.name.localeCompare(t.name))),u(!1),m(``),g(``),t(e(`settings.catalog.entryAdded`),`success`)}catch(n){console.error(`SpoolCatalogSettings.handleAdd failed:`,n),t(e(`settings.catalog.addFailed`),`error`)}finally{v(!1)}},j=e=>{f(e.id),m(e.name),g(e.weight.toString())},M=()=>{f(null),m(``),g(``)},N=async n=>{if(!p.trim()||!h){t(e(`settings.catalog.nameWeightRequired`),`error`);return}v(!0);try{let i=await Z.updateCatalogEntry(n,{name:p.trim(),weight:parseInt(h)});r(e=>e.map(e=>e.id===n?i:e).sort((e,t)=>e.name.localeCompare(t.name))),f(null),m(``),g(``),t(e(`settings.catalog.entryUpdated`),`success`)}catch(n){console.error(`SpoolCatalogSettings.handleUpdate failed:`,n),t(e(`settings.catalog.updateFailed`),`error`)}finally{v(!1)}},P=async()=>{if(w)try{await Z.deleteCatalogEntry(w.id),r(e=>e.filter(e=>e.id!==w.id)),t(e(`settings.catalog.entryDeleted`),`success`)}catch(n){console.error(`SpoolCatalogSettings.handleDelete failed:`,n),t(e(`settings.catalog.deleteFailed`),`error`)}finally{T(null)}},F=async()=>{D(!1),a(!0);try{await Z.resetSpoolCatalog(),await O(),t(e(`settings.catalog.resetSuccess`),`success`)}catch(n){console.error(`SpoolCatalogSettings.handleReset failed:`,n),t(e(`settings.catalog.resetFailed`),`error`),a(!1)}},I=e=>{x(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})};return(0,G.jsxs)(Md,{id:`card-spool-catalog`,children:[(0,G.jsxs)(Nd,{children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,G.jsx)(Us,{className:`w-5 h-5 text-bambu-gray`}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`settings.catalog.spoolCatalog`)}),(0,G.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[`(`,n.length,`)`]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,G.jsxs)(`button`,{onClick:()=>{let r=n.map(({name:e,weight:t})=>({name:e,weight:t})),i=new Blob([JSON.stringify(r,null,2)],{type:`application/json`}),a=URL.createObjectURL(i),o=document.createElement(`a`);o.href=a,o.download=`spool-catalog.json`,document.body.appendChild(o),o.click(),document.body.removeChild(o),URL.revokeObjectURL(a),t(e(`settings.catalog.exported`,{count:n.length}),`success`)},className:`px-3 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray hover:text-white transition-colors flex items-center gap-1.5`,title:e(`settings.catalog.exportTooltip`),children:[(0,G.jsx)(Js,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.export`)})]}),(0,G.jsxs)(`button`,{onClick:()=>c.current?.click(),className:`px-3 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray hover:text-white transition-colors flex items-center gap-1.5`,title:e(`settings.catalog.importTooltip`),children:[(0,G.jsx)(Ru,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.import`)})]}),(0,G.jsx)(`input`,{ref:c,type:`file`,accept:`.json`,className:`hidden`,onChange:async i=>{let a=i.target.files?.[0];if(a){try{let i=await a.text(),o=JSON.parse(i);if(!Array.isArray(o))throw Error(`Invalid format`);let s=0,c=0;for(let e of o){if(!e.name||typeof e.weight!=`number`){c++;continue}if(n.some(t=>t.name.toLowerCase()===e.name.toLowerCase())){c++;continue}try{let t=await Z.addCatalogEntry({name:e.name,weight:e.weight});r(e=>[...e,t].sort((e,t)=>e.name.localeCompare(t.name))),s++}catch(e){console.error(`SpoolCatalogSettings import item failed:`,e),c++}}t(e(`settings.catalog.imported`,{added:s,skipped:c}),`success`)}catch(n){console.error(`SpoolCatalogSettings.handleImport failed:`,n),t(e(`settings.catalog.importFailed`),`error`)}c.current&&(c.current.value=``)}}}),(0,G.jsxs)(`button`,{onClick:()=>D(!0),className:`px-3 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray hover:text-white transition-colors flex items-center gap-1.5`,title:e(`settings.catalog.resetTooltip`),children:[(0,G.jsx)(Vl,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.reset`)})]}),(0,G.jsxs)(`button`,{onClick:()=>u(!0),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,G.jsx)(Ml,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.add`)})]})]}),b.size>0&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mt-2 px-3 py-2 bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30 rounded-lg`,children:[(0,G.jsx)(`span`,{className:`text-sm text-red-700 dark:text-red-400`,children:e(`settings.catalog.selectedCount`,{count:b.size})}),(0,G.jsxs)(`button`,{onClick:()=>C(!0),className:`ml-auto px-3 py-1.5 text-sm bg-red-500 text-white rounded-lg hover:bg-red-600 transition-colors flex items-center gap-1.5`,children:[(0,G.jsx)(ju,{className:`w-4 h-4`}),e(`settings.catalog.deleteSelected`)]}),(0,G.jsx)(`button`,{onClick:()=>x(new Set),className:`px-3 py-1.5 text-sm text-bambu-gray hover:text-white transition-colors`,children:e(`common.cancel`)})]})]}),(0,G.jsxs)(Pd,{className:`space-y-4`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`settings.catalog.spoolCatalogDescription`)}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(Yl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,G.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:e(`settings.catalog.searchCatalog`),value:o,onChange:e=>s(e.target.value)})]}),l&&(0,G.jsxs)(`div`,{className:`p-4 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,G.jsx)(`h3`,{className:`text-sm font-medium text-white mb-3`,children:e(`settings.catalog.addNewEntry`)}),(0,G.jsxs)(`div`,{className:`flex gap-2 items-center`,children:[(0,G.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,G.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:e(`settings.catalog.namePlaceholder`),value:p,onChange:e=>m(e.target.value)})}),(0,G.jsx)(`input`,{type:`number`,className:`w-20 px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white text-center focus:border-bambu-green focus:outline-none`,placeholder:`g`,value:h,onChange:e=>g(e.target.value)}),(0,G.jsx)(`span`,{className:`text-bambu-gray shrink-0`,children:`g`}),(0,G.jsxs)(`button`,{onClick:A,disabled:_,className:`px-3 py-2 bg-bambu-green text-white rounded-lg hover:bg-bambu-green/80 flex items-center gap-1 shrink-0`,children:[_?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(us,{className:`w-4 h-4`}),e(`common.add`)]}),(0,G.jsx)(`button`,{onClick:()=>{u(!1),m(``),g(``)},className:`p-2 rounded-lg text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary`,children:(0,G.jsx)($u,{className:`w-4 h-4`})})]})]}),i?(0,G.jsxs)(`div`,{className:`flex items-center justify-center py-8 text-bambu-gray`,children:[(0,G.jsx)(Y,{className:`w-5 h-5 animate-spin mr-2`}),e(`common.loading`)]}):(0,G.jsx)(`div`,{className:`max-h-[600px] overflow-y-auto border border-bambu-dark-tertiary rounded-lg`,children:(0,G.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,G.jsx)(`thead`,{className:`bg-bambu-dark sticky top-0`,children:(0,G.jsxs)(`tr`,{children:[(0,G.jsx)(`th`,{className:`px-2 py-2 w-10`,children:(0,G.jsx)(`input`,{type:`checkbox`,checked:k.length>0&&b.size===k.length,onChange:()=>{b.size===k.length?x(new Set):x(new Set(k.map(e=>e.id)))},className:`w-4 h-4 accent-bambu-green cursor-pointer`})}),(0,G.jsx)(`th`,{className:`px-4 py-2 text-left text-bambu-gray font-medium`,children:e(`common.name`)}),(0,G.jsx)(`th`,{className:`px-4 py-2 text-right text-bambu-gray font-medium w-24`,children:e(`settings.catalog.weight`)}),(0,G.jsx)(`th`,{className:`px-4 py-2 text-center text-bambu-gray font-medium w-20`,children:e(`settings.catalog.type`)}),(0,G.jsx)(`th`,{className:`px-4 py-2 w-24`})]})}),(0,G.jsx)(`tbody`,{children:k.length===0?(0,G.jsx)(`tr`,{children:(0,G.jsx)(`td`,{colSpan:5,className:`px-4 py-8 text-center text-bambu-gray`,children:e(o?`settings.catalog.noMatch`:`settings.catalog.empty`)})}):k.map(t=>(0,G.jsx)(`tr`,{className:`border-t border-bambu-dark-tertiary hover:bg-bambu-dark ${b.has(t.id)?`bg-bambu-dark`:``}`,children:d===t.id?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`td`,{className:`px-2 py-2`,children:(0,G.jsx)(`input`,{type:`checkbox`,checked:b.has(t.id),onChange:()=>I(t.id),className:`w-4 h-4 accent-bambu-green cursor-pointer`})}),(0,G.jsx)(`td`,{className:`px-4 py-2`,children:(0,G.jsx)(`input`,{type:`text`,className:`w-full px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white focus:border-bambu-green focus:outline-none`,value:p,onChange:e=>m(e.target.value)})}),(0,G.jsx)(`td`,{className:`px-4 py-2`,children:(0,G.jsx)(`input`,{type:`number`,className:`w-full px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-right focus:border-bambu-green focus:outline-none`,value:h,onChange:e=>g(e.target.value)})}),(0,G.jsx)(`td`,{className:`px-4 py-2 text-center`,children:(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:`-`})}),(0,G.jsx)(`td`,{className:`px-4 py-2`,children:(0,G.jsxs)(`div`,{className:`flex justify-end gap-1`,children:[(0,G.jsx)(`button`,{onClick:()=>N(t.id),disabled:_,className:`p-1.5 rounded hover:bg-green-500/20 text-green-500`,children:_?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(us,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:M,className:`p-1.5 rounded hover:bg-bambu-dark-tertiary text-bambu-gray`,children:(0,G.jsx)($u,{className:`w-4 h-4`})})]})})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`td`,{className:`px-2 py-2`,children:(0,G.jsx)(`input`,{type:`checkbox`,checked:b.has(t.id),onChange:()=>I(t.id),className:`w-4 h-4 accent-bambu-green cursor-pointer`})}),(0,G.jsx)(`td`,{className:`px-4 py-2 text-white`,children:t.name}),(0,G.jsxs)(`td`,{className:`px-4 py-2 text-right font-mono text-white`,children:[t.weight,`g`]}),(0,G.jsx)(`td`,{className:`px-4 py-2 text-center`,children:t.is_default?(0,G.jsx)(`span`,{className:`text-xs px-2 py-0.5 rounded bg-bambu-dark-tertiary text-bambu-gray`,children:e(`settings.catalog.default`)}):(0,G.jsx)(`span`,{className:`text-xs px-2 py-0.5 rounded bg-bambu-green/20 text-bambu-green`,children:e(`settings.catalog.custom`)})}),(0,G.jsx)(`td`,{className:`px-4 py-2`,children:(0,G.jsxs)(`div`,{className:`flex justify-end gap-1`,children:[(0,G.jsx)(`button`,{onClick:()=>j(t),className:`p-1.5 rounded hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white`,children:(0,G.jsx)(Ol,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:()=>T(t),className:`p-1.5 rounded bg-red-500/10 hover:bg-red-500/20 text-red-500`,children:(0,G.jsx)(ju,{className:`w-4 h-4`})})]})})]})},t.id))})]})})]}),w&&(0,G.jsx)(Zd,{title:e(`settings.catalog.deleteEntry`),message:e(`settings.catalog.deleteConfirm`,{name:w.name}),confirmText:e(`common.delete`),variant:`danger`,onConfirm:P,onCancel:()=>T(null)}),S&&(0,G.jsx)(Zd,{title:e(`settings.catalog.deleteSelected`),message:e(`settings.catalog.bulkDeleteConfirm`,{count:b.size}),confirmText:e(`common.delete`),variant:`danger`,onConfirm:async()=>{if(C(!1),b.size!==0)try{let n=await Z.bulkDeleteCatalogEntries([...b]);r(e=>e.filter(e=>!b.has(e.id))),x(new Set),t(e(`settings.catalog.bulkDeleted`,{count:n.deleted}),`success`)}catch(n){console.error(`SpoolCatalogSettings.handleBulkDelete failed:`,n),t(e(`settings.catalog.bulkDeleteFailed`),`error`)}},onCancel:()=>C(!1)}),E&&(0,G.jsx)(Zd,{title:e(`settings.catalog.resetCatalog`),message:e(`settings.catalog.resetConfirm`),confirmText:e(`common.reset`),variant:`danger`,onConfirm:F,onCancel:()=>D(!1)})]})}var iHe=2166136261,aHe=16777619;function oHe(...e){let t=iHe,n=new TextEncoder,r=n.encode(`__|`);for(let i of e)typeof i==`string`?t=u6(t,n.encode(i+`|`)):i??(t=u6(t,r));return t>>>0}function u6(e,t){for(let n of t)e^=n,e=Math.imul(e,aHe)>>>0;return e}function sHe(e){let t=()=>{e|=0,e=e+1831565813|0;let t=Math.imul(e^e>>>15,1|e);return t=t+Math.imul(t^t>>>7,61|t)^t,(t^t>>>14)>>>0},n=(e,n)=>{if(!Number.isFinite(e)||!Number.isFinite(n))throw RangeError(`from and to must be finite numbers`);if(e>n)throw RangeError(`from must be less than or equal to to`);return e===n?e:e+t()/4294967295*(n-e)};return{next:()=>t()/4294967295,floatBetween:(e,t)=>n(e,t),intBetween:(e,t)=>{if(!Number.isInteger(e)||!Number.isInteger(t))throw RangeError(`from and to must be integers`);return Math.round(n(e,t))}}}var d6={table:{dotCount:5,dotScale:1},preview:{dotCount:8,dotScale:1.5},card:{dotCount:40,dotScale:2},bar:{dotCount:20,dotScale:2},groupheader:{dotCount:80,dotScale:2}},f6=[{value:``,labelKey:`inventory.colorEffect.none`},{value:`sparkle`,labelKey:`inventory.colorEffect.sparkle`},{value:`wood`,labelKey:`inventory.colorEffect.wood`},{value:`marble`,labelKey:`inventory.colorEffect.marble`},{value:`glow`,labelKey:`inventory.colorEffect.glow`},{value:`matte`,labelKey:`inventory.colorEffect.matte`},{value:`silk`,labelKey:`inventory.colorEffect.silk`},{value:`galaxy`,labelKey:`inventory.colorEffect.galaxy`},{value:`rainbow`,labelKey:`inventory.colorEffect.rainbow`},{value:`metal`,labelKey:`inventory.colorEffect.metal`},{value:`translucent`,labelKey:`inventory.colorEffect.translucent`},{value:`gradient`,labelKey:`inventory.colorEffect.gradient`},{value:`dual-color`,labelKey:`inventory.colorEffect.dualColor`},{value:`tri-color`,labelKey:`inventory.colorEffect.triColor`},{value:`multicolor`,labelKey:`inventory.colorEffect.multicolor`}],cHe=`repeating-conic-gradient(#979797 0% 25%, #f5f5f5 0% 50%)`,lHe=`12px 12px`,uHe={sparkle:(e=0,t=`table`)=>{let n=sHe(e),r=d6[t]??d6.table,i=[];for(let e=0;e`repeating-linear-gradient(90deg, rgba(0,0,0,0.18) 0 1px, transparent 1px 6px, rgba(0,0,0,0.08) 6px 7px, transparent 7px 12px)`,marble:()=>`repeating-linear-gradient(135deg, rgba(255,255,255,0.18) 0 2px, transparent 2px 8px), repeating-linear-gradient(45deg, rgba(0,0,0,0.10) 0 1px, transparent 1px 7px)`,glow:()=>`radial-gradient(circle at 50% 50%, rgba(255,255,255,0.35) 0%, rgba(255,255,255,0) 70%)`,matte:()=>`linear-gradient(180deg, rgba(0,0,0,0.10) 0%, rgba(0,0,0,0) 50%, rgba(0,0,0,0.10) 100%)`,silk:()=>`linear-gradient(110deg, rgba(255,255,255,0) 30%, rgba(255,255,255,0.30) 50%, rgba(255,255,255,0) 70%)`,galaxy:()=>`linear-gradient(110deg, rgba(255,255,255,0) 25%, rgba(255,255,255,0.40) 50%, rgba(255,255,255,0) 75%)`,metal:()=>`repeating-linear-gradient(90deg, rgba(255,255,255,0.10) 0 1px, transparent 1px 3px), linear-gradient(180deg, rgba(255,255,255,0.18) 0%, rgba(0,0,0,0.18) 100%)`};function p6(e){let t=e.trim().replace(/^#/,``);return t.length!==6&&t.length!==8||!/^[0-9a-fA-F]+$/.test(t)?null:`#${t}`}function m6(e){return e?e.split(`,`).map(e=>p6(e)).filter(e=>!!e):[]}function dHe(e,t,n,r){let i=e?p6(e):null;if(t.length===0)return`linear-gradient(${i??`#808080`}, ${i??`#808080`})`;let a=t.length===1?[t[0],t[0]]:t,o=(n??``).toLowerCase(),s=(r??``).toLowerCase();if(o===`multicolor`||s===`multicolor`){let e=a.length;return`conic-gradient(from 0deg, ${a.map((t,n)=>`${t} ${(n/e*360).toFixed(3)}deg ${((n+1)/e*360).toFixed(3)}deg`).join(`, `)})`}if(s===`dual-color`||s===`tri-color`){let e=a.length;return`linear-gradient(to right, ${a.map((t,n)=>`${t} ${(n/e*100).toFixed(3)}% ${((n+1)/e*100).toFixed(3)}%`).join(`, `)})`}return`linear-gradient(135deg, ${a.join(`, `)})`}function fHe(e,t,n){let r=uHe[e];return r?r(n,t):null}function h6(e){let t=m6(e.extraColors),n=dHe(e.rgba,t,e.subtype,e.effectType),r=oHe(e.rgba,e.extraColors,e.subtype,e.effectType),i=typeof e.effectType==`string`?fHe(e.effectType,e.effectSize,r):null,a=[];return i&&(Array.isArray(i)?i:[i]).forEach(e=>{a.push({image:e,size:`cover`})}),a.push({image:n,size:`cover`}),a.push({image:cHe,size:lHe}),{backgroundImage:a.map(e=>e.image).join(`, `),backgroundSize:a.map(e=>e.size).join(`, `)}}function g6({rgba:e,extraColors:t,effectType:n,subtype:r,className:i=`w-5 h-5`,shape:a=`circle`,style:o,title:s,effectSize:c}){let l=(0,y.useMemo)(()=>m6(t),[t]),u=(0,y.useMemo)(()=>h6({effectSize:c,rgba:e,extraColors:t,effectType:n,subtype:r}),[c,e,t,n,r]),d=u.backgroundImage,f=u.backgroundSize,p=a===`circle`||a===`pill`?`rounded-full`:`rounded`,m=(()=>{if(!e)return;let t=e.replace(/^#/,``);return t.length>=8&&t.substring(6,8).toLowerCase()!==`ff`?`#${t.substring(0,8)}`:`#${t.substring(0,6)}`})(),h=s??(l.length>0?l.join(`, `):m);return(0,G.jsx)(`span`,{"data-testid":`filament-swatch`,className:`${i} ${p} border border-black/20 inline-block flex-shrink-0`,style:{backgroundImage:d,backgroundSize:f,...o},title:h})}function pHe(){let{t:e}=U(),{showToast:t}=Bd(),[n,r]=(0,y.useState)([]),[i,a]=(0,y.useState)(!0),[o,s]=(0,y.useState)(``),[c,l]=(0,y.useState)(``),u=(0,y.useRef)(null),[d,f]=(0,y.useState)(!1),[p,m]=(0,y.useState)(null),[h,g]=(0,y.useState)(``),[_,v]=(0,y.useState)(``),[b,x]=(0,y.useState)(`#FFFFFF`),[S,C]=(0,y.useState)(``),[w,T]=(0,y.useState)(``),[E,D]=(0,y.useState)(``),[O,k]=(0,y.useState)(!1),[A,j]=(0,y.useState)(new Set),[M,N]=(0,y.useState)(!1),[P,F]=(0,y.useState)(!1),[I,L]=(0,y.useState)(null),[R,z]=(0,y.useState)(null),[B,V]=(0,y.useState)(!1),ee=(0,y.useCallback)(async()=>{try{r(await Z.getColorCatalog())}catch{t(e(`settings.colorCatalog.loadFailed`),`error`)}finally{a(!1)}},[t,e]);(0,y.useEffect)(()=>{ee()},[ee]);let te=[...new Set(n.map(e=>e.manufacturer))].sort(),ne=n.filter(e=>{let t=o===``||e.manufacturer.toLowerCase().includes(o.toLowerCase())||e.color_name.toLowerCase().includes(o.toLowerCase())||(e.material?.toLowerCase().includes(o.toLowerCase())??!1),n=c===``||e.manufacturer===c;return t&&n}),re=()=>{g(``),v(``),x(`#FFFFFF`),C(``),T(``),D(``)},ie=async()=>{if(!h.trim()||!_.trim()||!b){t(e(`settings.colorCatalog.fieldsRequired`),`error`);return}k(!0);try{let n=await Z.addColorEntry({manufacturer:h.trim(),color_name:_.trim(),hex_color:b,material:S.trim()||null,extra_colors:w.trim()||null,effect_type:E.trim()||null});r(e=>[...e,n].sort((e,t)=>e.manufacturer.localeCompare(t.manufacturer)||(e.material||``).localeCompare(t.material||``)||e.color_name.localeCompare(t.color_name))),f(!1),re(),t(e(`settings.colorCatalog.colorAdded`),`success`)}catch{t(e(`settings.colorCatalog.addFailed`),`error`)}finally{k(!1)}},ae=e=>{m(e.id),g(e.manufacturer),v(e.color_name),x(e.hex_color),C(e.material||``),T(e.extra_colors||``),D(e.effect_type||``)},oe=()=>{m(null),re()},se=async n=>{if(!h.trim()||!_.trim()||!b){t(e(`settings.colorCatalog.fieldsRequired`),`error`);return}k(!0);try{let i=await Z.updateColorEntry(n,{manufacturer:h.trim(),color_name:_.trim(),hex_color:b,material:S.trim()||null,extra_colors:w.trim()||null,effect_type:E.trim()||null});r(e=>e.map(e=>e.id===n?i:e).sort((e,t)=>e.manufacturer.localeCompare(t.manufacturer)||(e.material||``).localeCompare(t.material||``)||e.color_name.localeCompare(t.color_name))),m(null),re(),t(e(`settings.colorCatalog.colorUpdated`),`success`)}catch{t(e(`settings.colorCatalog.updateFailed`),`error`)}finally{k(!1)}},H=async()=>{if(R)try{await Z.deleteColorEntry(R.id),r(e=>e.filter(e=>e.id!==R.id)),t(e(`settings.colorCatalog.colorDeleted`),`success`)}catch{t(e(`settings.colorCatalog.deleteFailed`),`error`)}finally{z(null)}},ce=async()=>{V(!1),a(!0);try{await Z.resetColorCatalog(),await ee(),t(e(`settings.colorCatalog.resetSuccess`),`success`)}catch{t(e(`settings.colorCatalog.resetFailed`),`error`),a(!1)}},le=async()=>{F(!0),L(null);try{let n={},r=sd();r&&(n.Authorization=`Bearer ${r}`);let i=await fetch(`/api/v1/inventory/colors/sync`,{method:`POST`,headers:n});if(!i.ok)throw Error(`Failed to start sync`);let a=i.body?.getReader();if(!a)throw Error(`No response body`);let o=new TextDecoder,s=``;for(;;){let{done:n,value:r}=await a.read();if(n)break;s+=o.decode(r,{stream:!0});let i=s.split(`
`);s=i.pop()||``;for(let n of i)if(n.startsWith(`data: `))try{let r=JSON.parse(n.slice(6));r.type===`progress`?L({fetched:r.total_fetched,total:r.total_available}):r.type===`complete`?r.added===0?t(e(`settings.colorCatalog.syncUpToDate`,{count:r.total_fetched}),`success`):t(e(`settings.colorCatalog.syncComplete`,{added:r.added,skipped:r.skipped}),`success`):r.type===`error`&&t(`${e(`settings.colorCatalog.syncError`)}: ${r.error}`,`error`)}catch{}}await ee()}catch{t(e(`settings.colorCatalog.syncFailed`),`error`)}finally{F(!1),L(null)}},ue=e=>{j(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})};return(0,G.jsxs)(Md,{id:`card-color-catalog`,children:[(0,G.jsxs)(Nd,{children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,G.jsx)(Sl,{className:`w-5 h-5 text-bambu-gray`}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`settings.colorCatalog.title`)}),(0,G.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[`(`,n.length,`)`]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,G.jsxs)(`button`,{onClick:()=>{let r=n.map(({manufacturer:e,color_name:t,hex_color:n,material:r,extra_colors:i,effect_type:a})=>({manufacturer:e,color_name:t,hex_color:n,material:r,extra_colors:i,effect_type:a})),i=new Blob([JSON.stringify(r,null,2)],{type:`application/json`}),a=URL.createObjectURL(i),o=document.createElement(`a`);o.href=a,o.download=`color-catalog.json`,document.body.appendChild(o),o.click(),document.body.removeChild(o),URL.revokeObjectURL(a),t(e(`settings.colorCatalog.exported`,{count:n.length}),`success`)},className:`px-3 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray hover:text-white transition-colors flex items-center gap-1.5`,children:[(0,G.jsx)(Js,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.export`)})]}),(0,G.jsxs)(`button`,{onClick:()=>u.current?.click(),className:`px-3 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray hover:text-white transition-colors flex items-center gap-1.5`,children:[(0,G.jsx)(Ru,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.import`)})]}),(0,G.jsx)(`input`,{ref:u,type:`file`,accept:`.json`,className:`hidden`,onChange:async i=>{let a=i.target.files?.[0];if(a){try{let i=await a.text(),o=JSON.parse(i);if(!Array.isArray(o))throw Error(`Invalid format`);let s=0,c=0;for(let e of o){if(!e.manufacturer||!e.color_name||!e.hex_color){c++;continue}if(n.some(t=>t.manufacturer.toLowerCase()===e.manufacturer.toLowerCase()&&t.color_name.toLowerCase()===e.color_name.toLowerCase()&&(t.material||``).toLowerCase()===(e.material||``).toLowerCase())){c++;continue}try{let t=await Z.addColorEntry({manufacturer:e.manufacturer,color_name:e.color_name,hex_color:e.hex_color,material:e.material||null,extra_colors:e.extra_colors||null,effect_type:e.effect_type||null});r(e=>[...e,t].sort((e,t)=>e.manufacturer.localeCompare(t.manufacturer)||(e.material||``).localeCompare(t.material||``)||e.color_name.localeCompare(t.color_name))),s++}catch{c++}}t(e(`settings.colorCatalog.imported`,{added:s,skipped:c}),`success`)}catch{t(e(`settings.colorCatalog.importFailed`),`error`)}u.current&&(u.current.value=``)}}}),(0,G.jsxs)(`button`,{onClick:le,disabled:P,className:`px-3 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray hover:text-white transition-colors flex items-center gap-1.5`,title:e(`settings.colorCatalog.syncTooltip`),children:[P?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Ms,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:P?I?`${Math.min(I.fetched,I.total)} / ${I.total}`:e(`settings.colorCatalog.starting`):e(`settings.colorCatalog.sync`)})]}),(0,G.jsxs)(`button`,{onClick:()=>V(!0),className:`px-3 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray hover:text-white transition-colors flex items-center gap-1.5`,children:[(0,G.jsx)(Vl,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.reset`)})]}),(0,G.jsxs)(`button`,{onClick:()=>f(!0),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,G.jsx)(Ml,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.add`)})]})]}),A.size>0&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mt-2 px-3 py-2 bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30 rounded-lg`,children:[(0,G.jsx)(`span`,{className:`text-sm text-red-700 dark:text-red-400`,children:e(`settings.colorCatalog.selectedCount`,{count:A.size})}),(0,G.jsxs)(`button`,{onClick:()=>N(!0),className:`ml-auto px-3 py-1.5 text-sm bg-red-500 text-white rounded-lg hover:bg-red-600 transition-colors flex items-center gap-1.5`,children:[(0,G.jsx)(ju,{className:`w-4 h-4`}),e(`settings.colorCatalog.deleteSelected`)]}),(0,G.jsx)(`button`,{onClick:()=>j(new Set),className:`px-3 py-1.5 text-sm text-bambu-gray hover:text-white transition-colors`,children:e(`common.cancel`)})]})]}),(0,G.jsxs)(Pd,{className:`space-y-4`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`settings.colorCatalog.description`)}),(0,G.jsxs)(`div`,{className:`flex gap-2 flex-wrap`,children:[(0,G.jsxs)(`div`,{className:`relative flex-1 min-w-[200px]`,children:[(0,G.jsx)(Yl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,G.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:e(`settings.colorCatalog.searchColors`),value:o,onChange:e=>s(e.target.value)})]}),(0,G.jsxs)(`select`,{className:`px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,value:c,onChange:e=>l(e.target.value),children:[(0,G.jsx)(`option`,{value:``,children:e(`settings.colorCatalog.allManufacturers`)}),te.map(e=>(0,G.jsx)(`option`,{value:e,children:e},e))]})]}),d&&(0,G.jsxs)(`div`,{className:`p-4 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,G.jsx)(`h3`,{className:`text-sm font-medium text-white mb-3`,children:e(`settings.colorCatalog.addNewColor`)}),(0,G.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-5 gap-2 items-end`,children:[(0,G.jsx)(`input`,{type:`text`,className:`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:e(`settings.colorCatalog.manufacturer`),value:h,onChange:e=>g(e.target.value)}),(0,G.jsx)(`input`,{type:`text`,className:`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:e(`settings.colorCatalog.colorName`),value:_,onChange:e=>v(e.target.value)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`input`,{type:`color`,className:`w-20 h-10 rounded cursor-pointer border border-bambu-dark-tertiary`,value:b,onChange:e=>x(e.target.value)}),(0,G.jsx)(`input`,{type:`text`,className:`w-32 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:`#FFFFFF`,value:b,onChange:e=>x(e.target.value)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(`input`,{type:`text`,className:`flex-1 max-w-lg min-w-[200px] 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:e(`settings.colorCatalog.materialOptional`),value:S,onChange:e=>C(e.target.value)}),(0,G.jsxs)(`button`,{onClick:ie,disabled:O,className:`w-24 px-3 py-2 bg-bambu-green text-white rounded-lg hover:bg-bambu-green/80 flex items-center justify-center gap-3`,children:[O?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(us,{className:`w-4 h-4`}),e(`common.add`)]}),(0,G.jsx)(`button`,{onClick:()=>{f(!1),re()},className:`p-2 ml-2 rounded-lg text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary`,children:(0,G.jsx)($u,{className:`w-4 h-4`})})]})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-2 mt-2`,children:[(0,G.jsx)(`input`,{type:`text`,className:`px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white text-sm font-mono placeholder-bambu-gray focus:border-bambu-green focus:outline-none`,placeholder:e(`inventory.extraColorsPlaceholder`),value:w,onChange:e=>T(e.target.value)}),(0,G.jsx)(`select`,{className:`px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,value:E,onChange:e=>D(e.target.value),children:f6.map(t=>(0,G.jsx)(`option`,{value:t.value,children:e(t.labelKey)},t.value||`none`))})]})]}),(o||c)&&(0,G.jsx)(`div`,{className:`text-xs text-bambu-gray`,children:e(`settings.colorCatalog.showing`,{filtered:ne.length,total:n.length})}),i?(0,G.jsxs)(`div`,{className:`flex items-center justify-center py-8 text-bambu-gray`,children:[(0,G.jsx)(Y,{className:`w-5 h-5 animate-spin mr-2`}),e(`common.loading`)]}):(0,G.jsx)(`div`,{className:`max-h-[600px] overflow-auto border border-bambu-dark-tertiary rounded-lg`,children:(0,G.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,G.jsx)(`thead`,{className:`bg-bambu-dark sticky top-0`,children:(0,G.jsxs)(`tr`,{children:[(0,G.jsx)(`th`,{className:`px-2 py-2 w-10`,children:(0,G.jsx)(`input`,{type:`checkbox`,checked:ne.length>0&&A.size===ne.length,onChange:()=>{A.size===ne.length?j(new Set):j(new Set(ne.map(e=>e.id)))},className:`w-4 h-4 accent-bambu-green cursor-pointer`})}),(0,G.jsx)(`th`,{className:`px-3 py-2 text-left text-bambu-gray font-medium w-12`}),(0,G.jsx)(`th`,{className:`px-3 py-2 text-left text-bambu-gray font-medium`,children:e(`settings.colorCatalog.manufacturer`)}),(0,G.jsx)(`th`,{className:`px-3 py-2 text-left text-bambu-gray font-medium`,children:e(`inventory.material`)}),(0,G.jsx)(`th`,{className:`px-3 py-2 text-left text-bambu-gray font-medium`,children:e(`settings.colorCatalog.colorName`)}),(0,G.jsx)(`th`,{className:`px-3 py-2 text-left text-bambu-gray font-medium w-24`,children:e(`settings.colorCatalog.hex`)}),(0,G.jsx)(`th`,{className:`px-3 py-2 w-16`})]})}),(0,G.jsx)(`tbody`,{children:ne.length===0?(0,G.jsx)(`tr`,{children:(0,G.jsx)(`td`,{colSpan:7,className:`px-3 py-8 text-center text-bambu-gray`,children:e(o||c?`settings.colorCatalog.noMatch`:`settings.colorCatalog.empty`)})}):ne.map(t=>(0,G.jsxs)(y.Fragment,{children:[(0,G.jsx)(`tr`,{className:`border-t border-bambu-dark-tertiary hover:bg-bambu-dark ${A.has(t.id)?`bg-bambu-dark`:``}`,children:p===t.id?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`td`,{className:`px-2 py-2`,children:(0,G.jsx)(`input`,{type:`checkbox`,checked:A.has(t.id),onChange:()=>ue(t.id),className:`w-4 h-4 accent-bambu-green cursor-pointer`})}),(0,G.jsx)(`td`,{className:`px-3 py-2`,children:(0,G.jsx)(`input`,{type:`color`,className:`w-8 h-8 rounded cursor-pointer border border-bambu-dark-tertiary`,value:b,onChange:e=>x(e.target.value)})}),(0,G.jsx)(`td`,{className:`px-3 py-2`,children:(0,G.jsx)(`input`,{type:`text`,className:`w-full px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`,value:h,onChange:e=>g(e.target.value)})}),(0,G.jsx)(`td`,{className:`px-3 py-2`,children:(0,G.jsx)(`input`,{type:`text`,className:`w-full px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`,value:S,onChange:e=>C(e.target.value)})}),(0,G.jsx)(`td`,{className:`px-3 py-2`,children:(0,G.jsx)(`input`,{type:`text`,className:`w-full px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`,value:_,onChange:e=>v(e.target.value)})}),(0,G.jsx)(`td`,{className:`px-3 py-2`,children:(0,G.jsx)(`input`,{type:`text`,className:`w-full px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`,value:b,onChange:e=>x(e.target.value)})}),(0,G.jsx)(`td`,{className:`px-3 py-2`,children:(0,G.jsxs)(`div`,{className:`flex justify-end gap-1`,children:[(0,G.jsx)(`button`,{onClick:()=>se(t.id),disabled:O,className:`p-1.5 rounded hover:bg-green-500/20 text-green-500`,children:O?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(us,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:oe,className:`p-1.5 rounded hover:bg-bambu-dark-tertiary text-bambu-gray`,children:(0,G.jsx)($u,{className:`w-4 h-4`})})]})})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`td`,{className:`px-2 py-2`,children:(0,G.jsx)(`input`,{type:`checkbox`,checked:A.has(t.id),onChange:()=>ue(t.id),className:`w-4 h-4 accent-bambu-green cursor-pointer`})}),(0,G.jsx)(`td`,{className:`px-3 py-2`,children:(0,G.jsx)(g6,{rgba:t.hex_color.replace(/^#/,``)+(t.hex_color.length===7?`FF`:``),extraColors:t.extra_colors,effectType:t.effect_type,className:`w-8 h-8`,shape:`square`,title:t.hex_color,effectSize:`table`})}),(0,G.jsx)(`td`,{className:`px-3 py-2 text-white`,children:t.manufacturer}),(0,G.jsx)(`td`,{className:`px-3 py-2 text-bambu-gray`,children:t.material||`-`}),(0,G.jsx)(`td`,{className:`px-3 py-2 text-white`,children:t.color_name}),(0,G.jsx)(`td`,{className:`px-3 py-2 font-mono text-xs text-bambu-gray`,children:t.hex_color}),(0,G.jsx)(`td`,{className:`px-3 py-2`,children:(0,G.jsxs)(`div`,{className:`flex justify-end gap-1`,children:[(0,G.jsx)(`button`,{onClick:()=>ae(t),className:`p-1.5 rounded hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white`,children:(0,G.jsx)(Ol,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:()=>z(t),className:`p-1.5 rounded bg-red-500/10 hover:bg-red-500/20 text-red-500`,children:(0,G.jsx)(ju,{className:`w-4 h-4`})})]})})]})}),p===t.id&&(0,G.jsxs)(`tr`,{className:`border-t border-bambu-dark-tertiary/50 bg-bambu-dark`,children:[(0,G.jsx)(`td`,{colSpan:2}),(0,G.jsx)(`td`,{className:`px-3 py-2`,colSpan:2,children:(0,G.jsx)(`input`,{type:`text`,className:`w-full px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm font-mono focus:border-bambu-green focus:outline-none`,placeholder:e(`inventory.extraColorsPlaceholder`),value:w,onChange:e=>T(e.target.value)})}),(0,G.jsx)(`td`,{className:`px-3 py-2`,colSpan:2,children:(0,G.jsx)(`select`,{className:`w-full px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`,value:E,onChange:e=>D(e.target.value),children:f6.map(t=>(0,G.jsx)(`option`,{value:t.value,children:e(t.labelKey)},t.value||`none`))})}),(0,G.jsx)(`td`,{})]})]},t.id))})]})})]}),R&&(0,G.jsx)(Zd,{title:e(`settings.colorCatalog.deleteColor`),message:e(`settings.colorCatalog.deleteConfirm`,{name:`${R.manufacturer} - ${R.color_name}`}),confirmText:e(`common.delete`),variant:`danger`,onConfirm:H,onCancel:()=>z(null)}),M&&(0,G.jsx)(Zd,{title:e(`settings.colorCatalog.deleteSelected`),message:e(`settings.colorCatalog.bulkDeleteConfirm`,{count:A.size}),confirmText:e(`common.delete`),variant:`danger`,onConfirm:async()=>{if(N(!1),A.size!==0)try{let n=await Z.bulkDeleteColorEntries([...A]);r(e=>e.filter(e=>!A.has(e.id))),j(new Set),t(e(`settings.colorCatalog.bulkDeleted`,{count:n.deleted}),`success`)}catch{t(e(`settings.colorCatalog.bulkDeleteFailed`),`error`)}},onCancel:()=>N(!1)}),B&&(0,G.jsx)(Zd,{title:e(`settings.colorCatalog.resetCatalog`),message:e(`settings.colorCatalog.resetConfirm`),confirmText:e(`common.reset`),variant:`danger`,onConfirm:ce,onCancel:()=>V(!1)})]})}function mHe({link:e,onClose:t}){let{t:n}=U(),r=so(),i=!!e,a=(0,y.useRef)(null),[o,s]=(0,y.useState)(e?.name||``),[c,l]=(0,y.useState)(e?.url||``),[u,d]=(0,y.useState)(e?.icon||`link`),[f,p]=(0,y.useState)(e?.open_in_new_tab||!1),[m,h]=(0,y.useState)(!!e?.custom_icon),[g,_]=(0,y.useState)(e?.custom_icon?Z.getExternalLinkIconUrl(e.id):null),[v,b]=(0,y.useState)(null),[x,S]=(0,y.useState)(null);(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]);let C=q({mutationFn:async e=>{let t=await Z.createExternalLink(e);return v?await Z.uploadExternalLinkIcon(t.id,v):t},onSuccess:()=>{r.invalidateQueries({queryKey:[`external-links`]}),t()},onError:e=>{S(e.message)}}),w=q({mutationFn:async t=>{let n=await Z.updateExternalLink(e.id,t);return v?n=await Z.uploadExternalLinkIcon(e.id,v):!m&&e?.custom_icon&&(n=await Z.deleteExternalLinkIcon(e.id)),n},onSuccess:()=>{r.invalidateQueries({queryKey:[`external-links`]}),t()},onError:e=>{S(e.message)}}),T=e=>{let t=e.target.files?.[0];if(t){if(![`image/png`,`image/jpeg`,`image/gif`,`image/svg+xml`,`image/webp`,`image/x-icon`].includes(t.type)){S(`Please select a valid image file (PNG, JPG, GIF, SVG, WebP, or ICO)`);return}if(t.size>1024*1024){S(`Image file must be less than 1MB`);return}b(t),h(!0);let e=new FileReader;e.onload=e=>{_(e.target?.result)},e.readAsDataURL(t)}},E=()=>{b(null),_(null),h(!1),a.current&&(a.current.value=``)},D=e=>{if(e.preventDefault(),S(null),!o.trim()){S(`Name is required`);return}if(!c.trim()){S(`URL is required`);return}if(!c.startsWith(`http://`)&&!c.startsWith(`https://`)){S(`URL must start with http:// or https://`);return}let t={name:o.trim(),url:c.trim(),icon:u,open_in_new_tab:f};i?w.mutate(t):C.mutate(t)},O=C.isPending||w.isPending,k=tf(u);return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:t,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-md`,onClick:e=>e.stopPropagation(),children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`p-2 rounded-full bg-bambu-green/20 text-bambu-green`,children:m&&g?(0,G.jsx)(`img`,{src:g,alt:``,className:`w-5 h-5 rounded`}):(0,G.jsx)(k,{className:`w-5 h-5`})}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i?`Edit Link`:`Add External Link`})]}),(0,G.jsx)(`button`,{onClick:t,className:`text-bambu-gray hover:text-white transition-colors`,children:(0,G.jsx)($u,{className:`w-5 h-5`})})]}),(0,G.jsxs)(`form`,{onSubmit:D,className:`p-6 space-y-4`,children:[x&&(0,G.jsx)(`div`,{className:`p-3 bg-red-100 dark:bg-red-500/20 border border-red-300 dark:border-red-500/50 rounded-lg text-sm text-red-700 dark:text-red-400`,children:x}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:`Name *`}),(0,G.jsx)(`input`,{type:`text`,value:o,onChange:e=>s(e.target.value),placeholder:`My Link`,maxLength:50,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:`URL *`}),(0,G.jsx)(`input`,{type:`text`,value:c,onChange:e=>l(e.target.value),placeholder:`https://example.com`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`label`,{className:`text-sm text-bambu-gray`,children:n(`externalLinks.openInNewTab`)}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>p(!f),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors ${f?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,children:(0,G.jsx)(`span`,{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${f?`translate-x-6`:`translate-x-1`}`})})]}),(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray`,children:`Icon`}),(0,G.jsxs)(`div`,{className:`p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,G.jsx)(`span`,{className:`text-sm text-white`,children:`Custom Icon`}),(0,G.jsx)(`input`,{ref:a,type:`file`,accept:`image/png,image/jpeg,image/gif,image/svg+xml,image/webp,image/x-icon`,className:`hidden`,onChange:T}),m&&g?(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`img`,{src:g,alt:`Custom icon`,className:`w-8 h-8 rounded border border-bambu-dark-tertiary`}),(0,G.jsx)(`button`,{type:`button`,onClick:E,className:`p-1 text-red-700 dark:text-red-400 hover:text-red-800 dark:hover:text-red-300 transition-colors`,title:`Remove custom icon`,children:(0,G.jsx)(ju,{className:`w-4 h-4`})})]}):(0,G.jsxs)(Q,{type:`button`,variant:`secondary`,size:`sm`,onClick:()=>a.current?.click(),children:[(0,G.jsx)(Ru,{className:`w-4 h-4`}),`Upload`]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:`PNG, JPG, GIF, SVG, WebP, or ICO. Max 1MB.`})]}),!m&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray block mb-2`,children:`Or choose a preset icon`}),(0,G.jsx)(nf,{value:u,onChange:d})]})]}),(0,G.jsxs)(`div`,{className:`flex gap-3 pt-2`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:t,className:`flex-1`,children:`Cancel`}),(0,G.jsxs)(Q,{type:`submit`,disabled:O,className:`flex-1`,children:[O?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Wl,{className:`w-4 h-4`}),i?`Save`:`Add`]})]})]})]})})}function hHe(){let{t:e}=U(),t=so(),{authEnabled:n,hasPermission:r}=Ed(),{showToast:i}=Bd(),[a,o]=(0,y.useState)(!1),[s,c]=(0,y.useState)(null),[l,u]=(0,y.useState)(null),[d,f]=(0,y.useState)(null),[p,m]=(0,y.useState)(null),[h,g]=(0,y.useState)(Zp),[_,v]=(0,y.useState)(()=>Yp($p.map(e=>e.id))),{data:b,isLoading:x}=K({queryKey:[`external-links`],queryFn:Z.getExternalLinks}),S=q({mutationFn:e=>Z.deleteExternalLink(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`external-links`]})}}),{data:C}=K({queryKey:[`settings`],queryFn:Z.getSettings,enabled:n&&r(`settings:update`)}),w=q({mutationFn:e=>Z.updateSettings({default_sidebar_order:e}),onSuccess:(n,r)=>{t.invalidateQueries({queryKey:[`settings`]}),t.invalidateQueries({queryKey:[`default-sidebar-order`]}),i(e(r?`settings.sidebarDefaultSet`:`settings.sidebarDefaultCleared`),`success`)},onError:()=>{i(e(`settings.sidebarDefaultFailed`),`error`)}}),T=(0,y.useMemo)(()=>{let e=new Map($p.map(e=>[e.id,e])),t=new Map((b||[]).map(e=>[`ext-${e.id}`,e])),n=[],r=new Set,i=i=>{if(r.has(i))return;let a=e.get(i);if(a){n.push({type:`system`,id:i,navItem:a}),r.add(i);return}let o=t.get(i);o&&(n.push({type:`external`,id:i,link:o}),r.add(i))};return _.forEach(i),$p.forEach(e=>i(e.id)),(b||[]).forEach(e=>i(`ext-${e.id}`)),n},[b,_]),E=e=>{v(e),Xp(e)},D=(e,t)=>{f(t),e.dataTransfer.effectAllowed=`move`,e.dataTransfer.setData(`text/plain`,t)},O=(e,t)=>{e.preventDefault(),e.dataTransfer.dropEffect=`move`,m(t)},k=(e,t)=>{if(e.preventDefault(),d===null||d===t){f(null),m(null);return}let n=T.map(e=>e.id),r=n.indexOf(d),i=n.indexOf(t);if(r===-1||i===-1){f(null),m(null);return}n.splice(r,1),n.splice(i,0,d),E(n),f(null),m(null)},A=()=>{f(null),m(null)},j=e=>{u(e)},M=()=>{l&&(S.mutate(l.id),u(null))},N=()=>{let e=[...$p.map(e=>e.id),...(b||[]).map(e=>`ext-${e.id}`)];g([]),v(e),Qp([]),Xp(e)},P=e=>{let t=T.map(e=>e.id);w.mutate(e?JSON.stringify({order:t,hiddenSystemItemIds:h}):``)},F=e=>{if(e===`settings`)return;let t=h.includes(e)?h.filter(t=>t!==e):[...h,e];g(t),Qp(t)},I=n&&r(`settings:update`),L=!!C?.default_sidebar_order;return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(Md,{id:`card-sidebar-links`,children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-y-2 gap-x-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Jc,{className:`w-5 h-5 text-bambu-green`}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`externalLinks.sidebarLayout`)})]}),(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[I&&(0,G.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-bambu-gray`,children:[(0,G.jsx)(`span`,{children:e(`settings.setDefault`)}),(0,G.jsx)(UH,{checked:L,onChange:P,disabled:w.isPending})]}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:N,className:`whitespace-nowrap`,children:[(0,G.jsx)(Vl,{className:`w-4 h-4`}),e(`settings.reset`)]}),(0,G.jsxs)(Q,{size:`sm`,onClick:()=>o(!0),className:`whitespace-nowrap`,children:[(0,G.jsx)(Ml,{className:`w-4 h-4`}),`Add Link`]})]})]})}),(0,G.jsxs)(Pd,{children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4`,children:e(`externalLinks.sidebarLayoutDescription`)}),x?(0,G.jsx)(`div`,{className:`flex justify-center py-8`,children:(0,G.jsx)(Y,{className:`w-6 h-6 text-bambu-green animate-spin`})}):(0,G.jsx)(`div`,{className:`space-y-2`,children:T.map(t=>{let n=t.type===`system`&&h.includes(t.id),r=t.id===`settings`;if(t.type===`system`){let i=t.navItem.icon;return(0,G.jsxs)(`div`,{draggable:!0,onDragStart:e=>D(e,t.id),onDragOver:e=>O(e,t.id),onDragLeave:()=>m(null),onDrop:e=>k(e,t.id),onDragEnd:A,className:`relative flex items-center gap-3 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary transition-colors ${d===t.id?`opacity-50`:n?`opacity-60`:``} ${p===t.id&&d!==t.id?`before:absolute before:left-3 before:right-3 before:top-0 before:h-0.5 before:bg-bambu-green`:``}`,children:[(0,G.jsx)(Oc,{className:`w-6 h-6 md:w-4 md:h-4 text-bambu-gray cursor-grab flex-shrink-0`}),(0,G.jsx)(`div`,{className:`p-2 rounded-lg bg-bambu-dark-tertiary text-bambu-gray`,children:(0,G.jsx)(i,{className:`w-4 h-4`})}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`span`,{className:`text-white font-medium truncate block`,children:e(t.navItem.labelKey)}),(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray truncate block`,children:e(r?`externalLinks.requiredInSidebar`:n?`externalLinks.hiddenFromSidebar`:`externalLinks.visibleInSidebar`)})]}),(0,G.jsx)(`button`,{onClick:()=>F(t.id),disabled:r,className:`p-2 rounded-lg hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white transition-colors flex-shrink-0 disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:bg-transparent disabled:hover:text-bambu-gray`,title:e(r?`externalLinks.settingsCannotBeHidden`:n?`externalLinks.showPage`:`externalLinks.hidePage`),"aria-label":e(r?`externalLinks.settingsCannotBeHidden`:n?`externalLinks.showPage`:`externalLinks.hidePage`),children:n?(0,G.jsx)(nc,{className:`w-4 h-4`}):(0,G.jsx)(rc,{className:`w-4 h-4`})})]},t.id)}let i=t.link,a=tf(i.icon);return(0,G.jsxs)(`div`,{draggable:!0,onDragStart:e=>D(e,t.id),onDragOver:e=>O(e,t.id),onDragLeave:()=>m(null),onDrop:e=>k(e,t.id),onDragEnd:A,className:`relative flex items-center gap-3 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary transition-colors ${d===t.id?`opacity-50`:``} ${p===t.id&&d!==t.id?`before:absolute before:left-3 before:right-3 before:top-0 before:h-0.5 before:bg-bambu-green`:``}`,children:[(0,G.jsx)(Oc,{className:`w-6 h-6 md:w-4 md:h-4 text-bambu-gray cursor-grab flex-shrink-0`}),(0,G.jsx)(`div`,{className:`p-2 rounded-lg bg-bambu-dark-tertiary text-bambu-gray`,children:i.custom_icon?(0,G.jsx)(`img`,{src:Z.getExternalLinkIconUrl(i.id),alt:``,className:`w-4 h-4`}):(0,G.jsx)(a,{className:`w-4 h-4`})}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-white font-medium truncate`,children:i.name}),(0,G.jsx)(tc,{className:`w-3 h-3 text-bambu-gray flex-shrink-0`})]}),(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray truncate block`,children:i.url})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1 flex-shrink-0`,children:[(0,G.jsx)(`button`,{onClick:()=>c(i),className:`p-2 rounded-lg hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white transition-colors`,title:e(`common.edit`),children:(0,G.jsx)(Ol,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:()=>j(i),disabled:S.isPending,className:`p-2 rounded-lg hover:bg-red-100 dark:hover:bg-red-500/20 text-bambu-gray hover:text-red-900 dark:hover:text-red-400 transition-colors disabled:opacity-50`,title:e(`externalLinks.deleteLink`),children:(0,G.jsx)(ju,{className:`w-4 h-4`})})]})]},t.id)})})]})]}),(a||s)&&(0,G.jsx)(mHe,{link:s,onClose:()=>{o(!1),c(null)}}),l&&(0,G.jsx)(Zd,{title:`Delete Link`,message:`Are you sure you want to delete "${l.name}"? This action cannot be undone.`,confirmText:`Delete`,cancelText:`Cancel`,variant:`danger`,onConfirm:M,onCancel:()=>u(null)})]})}async function _6(e){if(navigator.clipboard&&window.isSecureContext)try{return await navigator.clipboard.writeText(e),!0}catch{}let t=document.createElement(`textarea`);t.value=e,t.style.position=`fixed`,t.style.opacity=`0`,document.body.appendChild(t);try{return t.select(),document.execCommand(`copy`)}catch{return!1}finally{t.parentNode&&t.parentNode.removeChild(t)}}function gHe(e,t,n=`text/plain`){let r=new Blob([e],{type:n}),i=URL.createObjectURL(r),a=document.createElement(`a`);a.href=i,a.download=t,document.body.appendChild(a),a.click(),a.remove(),URL.revokeObjectURL(i)}function _He({status:e}){return e===`pass`?(0,G.jsx)(bs,{className:`w-5 h-5 text-bambu-green flex-shrink-0`}):e===`fail`?(0,G.jsx)(Ts,{className:`w-5 h-5 text-red-600 dark:text-red-400 flex-shrink-0`}):e===`warn`?(0,G.jsx)(Pu,{className:`w-5 h-5 text-amber-600 dark:text-amber-400 flex-shrink-0`}):(0,G.jsx)(Ss,{className:`w-5 h-5 text-bambu-gray flex-shrink-0`})}function vHe({vpId:e,vpName:t,onClose:n}){let{t:r}=U(),i=q({mutationFn:()=>_d.diagnose(e)});(0,y.useEffect)(()=>{i.mutate()},[]),(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[n]);let a=i.data,o=a?.overall===`ok`?`bg-bambu-green/10 border-bambu-green/30 text-bambu-green`:a?.overall===`warnings`?`bg-amber-50 dark:bg-amber-500/10 border-amber-300 dark:border-amber-500/30 text-amber-700 dark:text-amber-300`:`bg-red-50 dark:bg-red-500/10 border-red-300 dark:border-red-500/30 text-red-700 dark:text-red-300`;return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:n,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-lg flex flex-col max-h-[85vh]`,onClick:e=>e.stopPropagation(),children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,G.jsx)(yu,{className:`w-5 h-5 text-bambu-green flex-shrink-0`}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white truncate`,children:r(`vpDiagnostic.title`,{name:t})})]}),(0,G.jsx)(`button`,{onClick:n,className:`text-bambu-gray hover:text-white transition-colors`,title:r(`common.close`),children:(0,G.jsx)($u,{className:`w-5 h-5`})})]}),(0,G.jsxs)(`div`,{className:`p-6 space-y-4 overflow-y-auto`,children:[i.isPending&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray`,children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),(0,G.jsx)(`span`,{children:r(`vpDiagnostic.running`)})]}),i.isError&&(0,G.jsx)(`div`,{className:`rounded-lg bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30 px-4 py-3 text-sm text-red-700 dark:text-red-300`,children:r(`vpDiagnostic.runFailed`,{error:i.error.message})}),a&&(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsx)(`ol`,{className:`space-y-2`,children:a.checks.map(e=>{let t=r(`vpDiagnostic.check.${e.id}.${e.status}`,{...e.params,defaultValue:``});return(0,G.jsxs)(`li`,{className:`flex items-start gap-3 bg-bambu-dark rounded-lg px-4 py-2.5 ${e.status===`skip`?`opacity-60`:``}`,children:[(0,G.jsx)(`div`,{className:`mt-0.5`,children:(0,G.jsx)(_He,{status:e.status})}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`div`,{className:`text-sm text-white`,children:r(`vpDiagnostic.check.${e.id}.title`,e.params)}),t&&(0,G.jsx)(`div`,{className:`text-xs text-bambu-gray mt-0.5`,children:t})]})]},e.id)})}),(0,G.jsx)(`div`,{className:`rounded-lg border px-4 py-3 text-sm ${o}`,children:r(`vpDiagnostic.overall.${a.overall}`)})]})]}),(0,G.jsxs)(`div`,{className:`px-6 py-4 border-t border-bambu-dark-tertiary flex justify-end gap-2`,children:[(0,G.jsx)(`button`,{onClick:()=>i.mutate(),disabled:i.isPending,className:`px-4 py-2 bg-bambu-dark hover:bg-bambu-dark-tertiary disabled:opacity-50 text-white text-sm rounded-lg transition-colors`,children:r(`vpDiagnostic.retry`)}),(0,G.jsx)(`button`,{onClick:n,className:`px-4 py-2 bg-bambu-green hover:bg-bambu-green/90 text-white text-sm rounded-lg transition-colors`,children:r(`common.close`)})]})]})})}var v6={archive:`archive`,review:`review`,queue:`queue`,proxy:`proxy`};function y6(e){return e===`immediate`?`archive`:e===`print_queue`||e===`queue`?`queue`:e===`archive`||e===`review`||e===`proxy`?e:`archive`}function yHe({printer:e,models:t}){let{t:n}=U(),r=so(),{showToast:i}=Bd(),[a,o]=(0,y.useState)(!0),[s,c]=(0,y.useState)(e.enabled),[l,u]=(0,y.useState)(e.name),[d,f]=(0,y.useState)(``),[p,m]=(0,y.useState)(y6(e.mode)),[h,g]=(0,y.useState)(e.target_printer_id),[_,v]=(0,y.useState)(e.bind_ip||``),[b,x]=(0,y.useState)(e.remote_interface_ip||``),[S,C]=(0,y.useState)(e.model||``),[w,T]=(0,y.useState)(e.auto_dispatch??!0),[E,D]=(0,y.useState)(e.queue_force_color_match??!1),[O,k]=(0,y.useState)(e.save_ams_mapping??!1),[A,j]=(0,y.useState)(e.gcode_injection??!1),[M,N]=(0,y.useState)(e.tailscale_disabled??!0),[P,F]=(0,y.useState)(!1),[I,L]=(0,y.useState)(null),[R,z]=(0,y.useState)(!1),[B,V]=(0,y.useState)(!1),[ee,te]=(0,y.useState)(!1),{data:ne}=K({queryKey:[`tailscale-status`],queryFn:_d.getTailscaleStatus,enabled:!M,staleTime:6e4}),re=ne?.available?ne.fqdn:``,ie=ne?.available?ne.tailscale_ips?.[0]??``:``,ae=async e=>{e.stopPropagation();let t=re;t&&(await _6(t)?(te(!0),i(n(`printers.copied`)),setTimeout(()=>te(!1),2e3)):i(n(`virtualPrinter.toast.copyFailed`),`error`))};(0,y.useEffect)(()=>{I||(c(e.enabled),m(y6(e.mode)),u(e.name),g(e.target_printer_id),v(e.bind_ip||``),x(e.remote_interface_ip||``),C(e.model||``),T(e.auto_dispatch??!0),D(e.queue_force_color_match??!1),k(e.save_ams_mapping??!1),j(e.gcode_injection??!1),N(e.tailscale_disabled??!0))},[e,I]);let{data:oe}=K({queryKey:[`printers`],queryFn:Z.getPrinters}),{data:se}=K({queryKey:[`network-interfaces`],queryFn:()=>Z.getNetworkInterfaces().then(e=>e.interfaces)}),H=q({mutationFn:t=>_d.update(e.id,t),onSuccess:()=>{r.invalidateQueries({queryKey:[`virtual-printers`]}),i(n(`virtualPrinter.toast.updated`)),L(null)},onError:t=>{i(t.message||n(`virtualPrinter.toast.failedToUpdate`),`error`),c(e.enabled),m(y6(e.mode)),g(e.target_printer_id),v(e.bind_ip||``),N(e.tailscale_disabled??!0),D(e.queue_force_color_match??!1),k(e.save_ams_mapping??!1),j(e.gcode_injection??!1),L(null)}}),ce=q({mutationFn:()=>_d.remove(e.id),onSuccess:()=>{r.invalidateQueries({queryKey:[`virtual-printers`]}),i(n(`virtualPrinter.toast.deleted`)),z(!1)},onError:e=>{i(e.message||n(`virtualPrinter.toast.failedToDelete`),`error`),z(!1)}}),le=t=>{t.stopPropagation();let r=!s;if(r){if(!_){i(n(`virtualPrinter.toast.bindIpRequired`),`error`);return}if(p===`proxy`){if(!h){i(n(`virtualPrinter.toast.targetPrinterRequired`),`error`);return}}else if(!d&&!e.access_code_set){i(n(`virtualPrinter.toast.accessCodeRequired`),`error`);return}}c(r),L(`toggle`),H.mutate({enabled:r})},ue=()=>{l.trim()&&(L(`name`),H.mutate({name:l.trim()}))},de=()=>{if(!d){i(n(`virtualPrinter.toast.accessCodeEmpty`),`error`);return}if(d.length!==8){i(n(`virtualPrinter.toast.accessCodeLength`),`error`);return}L(`accessCode`),H.mutate({access_code:d}),f(``)},fe=e=>{m(e),L(`mode`),H.mutate({mode:e})},pe=e=>{C(e),L(`model`),H.mutate({model:e})},me=e=>{let t=ve?.access_code,r=oe?.find(t=>t.id===e)?.access_code;g(e),L(`targetPrinter`),H.mutate({target_printer_id:e},{onSuccess:()=>{t&&r&&t!==r&&i(n(`virtualPrinter.toast.targetCodeChangedRebind`),`info`)}})},he=e=>{x(e),L(`remoteInterface`),H.mutate({remote_interface_ip:e})},ge=e.status?.running||!1,_e=n(`virtualPrinter.mode.${v6[p]||`archive`}`),ve=oe?.find(e=>e.id===h),ye=ve?.name,be=!!h,xe=be?ve?.access_code??``:``;return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(Md,{children:[(0,G.jsxs)(`div`,{className:`px-4 py-3 flex items-center gap-3 cursor-pointer select-none`,onClick:()=>o(!a),children:[(0,G.jsx)(`button`,{className:`text-bambu-gray flex-shrink-0`,children:a?(0,G.jsx)(ds,{className:`w-4 h-4`}):(0,G.jsx)(fs,{className:`w-4 h-4`})}),(0,G.jsx)(`span`,{className:`w-2 h-2 rounded-full flex-shrink-0 ${ge?`bg-green-400 animate-pulse`:`bg-gray-500`}`}),(0,G.jsx)(`span`,{className:`text-white font-medium truncate`,children:e.name}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray flex-shrink-0`,children:_e}),e.model_name&&(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray flex-shrink-0`,children:e.model_name}),ye&&(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray flex-shrink-0 truncate`,children:[p===`proxy`&&(0,G.jsx)(Lo,{className:`w-3 h-3 inline mr-1`}),ye]}),_&&(0,G.jsx)(`span`,{className:`text-[10px] text-bambu-gray flex-shrink-0 font-mono`,children:_}),b&&(0,G.jsx)(`span`,{className:`text-[10px] text-bambu-gray flex-shrink-0 font-mono`,children:b}),(0,G.jsx)(`div`,{className:`ml-auto flex items-center gap-2 flex-shrink-0`,onClick:e=>e.stopPropagation(),children:(0,G.jsx)(`button`,{onClick:le,disabled:I===`toggle`,className:`relative w-10 h-5 rounded-full transition-colors ${s?`bg-bambu-green`:`bg-bambu-dark-tertiary`} ${I===`toggle`?`opacity-50`:``}`,children:(0,G.jsx)(`span`,{className:`absolute top-0.5 left-0.5 w-4 h-4 bg-white rounded-full transition-transform ${s?`translate-x-5`:``}`})})})]}),a&&(0,G.jsxs)(Pd,{className:`pt-0 space-y-4`,children:[(0,G.jsx)(`div`,{className:`border-t border-bambu-dark-tertiary`}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`input`,{type:`text`,value:l,onChange:e=>u(e.target.value),onBlur:ue,onKeyDown:e=>e.key===`Enter`&&ue(),className:`flex-1 text-sm text-white bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-1.5 focus:border-bambu-green focus:outline-none`}),(0,G.jsx)(`button`,{onClick:()=>V(!0),className:`p-1.5 text-bambu-gray hover:text-bambu-green transition-colors flex-shrink-0`,title:n(`vpDiagnostic.runButton`),children:(0,G.jsx)(yu,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:()=>z(!0),className:`p-1.5 text-bambu-gray hover:text-red-600 dark:hover:text-red-400 transition-colors flex-shrink-0`,title:n(`common.delete`),children:(0,G.jsx)(ju,{className:`w-4 h-4`})})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 -mt-2`,children:[re&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-green-700/80 dark:text-green-400/70 min-w-0`,children:[(0,G.jsx)(nu,{className:`w-3.5 h-3.5 flex-shrink-0`}),(0,G.jsx)(`span`,{className:`font-mono text-xs truncate`,children:ie?`${ie} (${re})`:re}),(0,G.jsx)(`button`,{onClick:ae,className:`p-0.5 rounded hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white transition-colors flex-shrink-0`,title:n(ee?`printers.copied`:`printers.copyToClipboard`),children:ee?(0,G.jsx)(us,{className:`w-3.5 h-3.5 text-bambu-green`}):(0,G.jsx)(zs,{className:`w-3.5 h-3.5`})})]}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray font-mono ml-auto flex-shrink-0`,children:e.serial})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`div`,{className:`text-white text-sm font-medium mb-2`,children:n(`virtualPrinter.mode.title`)}),(0,G.jsx)(`div`,{className:`grid grid-cols-2 gap-2`,children:[`archive`,`review`,`queue`,`proxy`].map(e=>(0,G.jsxs)(`button`,{onClick:()=>fe(e),disabled:I===`mode`,className:`p-2 rounded-lg border text-left transition-colors ${p===e?e===`proxy`?`border-blue-500 bg-blue-500/10`:`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary hover:border-bambu-gray`}`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 text-white text-xs font-medium`,children:[e===`proxy`&&(0,G.jsx)(Lo,{className:`w-3 h-3`}),n(`virtualPrinter.mode.${v6[e]}`)]}),(0,G.jsx)(`div`,{className:`text-[10px] text-bambu-gray`,children:n(`virtualPrinter.mode.${v6[e]}Desc`)})]},e))})]}),p===`queue`&&(0,G.jsx)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsx)(`div`,{className:`text-white text-sm font-medium`,children:n(`virtualPrinter.autoDispatch.title`)}),(0,G.jsx)(`div`,{className:`text-[10px] text-bambu-gray`,children:n(`virtualPrinter.autoDispatch.description`)})]}),(0,G.jsx)(`button`,{onClick:()=>{let e=!w;T(e),L(`autoDispatch`),H.mutate({auto_dispatch:e})},disabled:I===`autoDispatch`,className:`relative w-10 h-5 rounded-full transition-colors flex-shrink-0 ${w?`bg-bambu-green`:`bg-bambu-dark-tertiary`} ${I===`autoDispatch`?`opacity-50`:``}`,children:(0,G.jsx)(`span`,{className:`absolute top-0.5 left-0.5 w-4 h-4 bg-white rounded-full transition-transform ${w?`translate-x-5`:``}`})})]})}),p===`queue`&&(0,G.jsx)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsx)(`div`,{className:`text-white text-sm font-medium`,children:n(`virtualPrinter.queueForceColorMatch.title`)}),(0,G.jsx)(`div`,{className:`text-[10px] text-bambu-gray`,children:n(`virtualPrinter.queueForceColorMatch.description`)})]}),(0,G.jsx)(`button`,{onClick:()=>{let e=!E;D(e),L(`queueForceColorMatch`),H.mutate({queue_force_color_match:e})},disabled:I===`queueForceColorMatch`,className:`relative w-10 h-5 rounded-full transition-colors flex-shrink-0 ${E?`bg-bambu-green`:`bg-bambu-dark-tertiary`} ${I===`queueForceColorMatch`?`opacity-50`:``}`,children:(0,G.jsx)(`span`,{className:`absolute top-0.5 left-0.5 w-4 h-4 bg-white rounded-full transition-transform ${E?`translate-x-5`:``}`})})]})}),p===`queue`&&(0,G.jsx)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsx)(`div`,{className:`text-white text-sm font-medium`,children:n(`virtualPrinter.saveAmsMapping.title`)}),(0,G.jsx)(`div`,{className:`text-[10px] text-bambu-gray`,children:n(`virtualPrinter.saveAmsMapping.description`)})]}),(0,G.jsx)(`button`,{onClick:()=>{let e=!O;k(e),L(`saveAmsMapping`),H.mutate({save_ams_mapping:e})},disabled:I===`saveAmsMapping`,className:`relative w-10 h-5 rounded-full transition-colors flex-shrink-0 ${O?`bg-bambu-green`:`bg-bambu-dark-tertiary`} ${I===`saveAmsMapping`?`opacity-50`:``}`,children:(0,G.jsx)(`span`,{className:`absolute top-0.5 left-0.5 w-4 h-4 bg-white rounded-full transition-transform ${O?`translate-x-5`:``}`})})]})}),p===`queue`&&(0,G.jsx)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsx)(`div`,{className:`text-white text-sm font-medium`,children:n(`virtualPrinter.gcodeInjection.title`)}),(0,G.jsx)(`div`,{className:`text-[10px] text-bambu-gray`,children:n(`virtualPrinter.gcodeInjection.description`)})]}),(0,G.jsx)(`button`,{onClick:()=>{let e=!A;j(e),L(`gcodeInjection`),H.mutate({gcode_injection:e})},disabled:I===`gcodeInjection`,className:`relative w-10 h-5 rounded-full transition-colors flex-shrink-0 ${A?`bg-bambu-green`:`bg-bambu-dark-tertiary`} ${I===`gcodeInjection`?`opacity-50`:``}`,children:(0,G.jsx)(`span`,{className:`absolute top-0.5 left-0.5 w-4 h-4 bg-white rounded-full transition-transform ${A?`translate-x-5`:``}`})})]})}),(0,G.jsx)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsx)(`div`,{className:`text-white text-sm font-medium`,children:n(`virtualPrinter.tailscaleDisabled.title`)}),(0,G.jsx)(`div`,{className:`text-[10px] text-bambu-gray`,children:n(`virtualPrinter.tailscaleDisabled.description`)})]}),(0,G.jsx)(`button`,{onClick:()=>{let e=!M;N(e),L(`tailscaleDisabled`),H.mutate({tailscale_disabled:e})},disabled:I===`tailscaleDisabled`,className:`relative w-10 h-5 rounded-full transition-colors shrink-0 ${M?`bg-bambu-dark-tertiary`:`bg-bambu-green`} ${I===`tailscaleDisabled`?`opacity-50`:``}`,children:(0,G.jsx)(`span`,{className:`absolute top-0.5 left-0.5 w-4 h-4 bg-white rounded-full transition-transform ${M?``:`translate-x-5`}`})})]})}),p!==`proxy`&&(0,G.jsxs)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:[(0,G.jsx)(`div`,{className:`text-white text-sm font-medium mb-1`,children:n(`virtualPrinter.model.title`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:n(`virtualPrinter.model.description`)}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(`select`,{value:S,onChange:e=>pe(e.target.value),disabled:I===`model`,className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-1.5 text-white text-sm appearance-none cursor-pointer disabled:opacity-50 pr-10`,children:Object.entries(t).map(([e,t])=>(0,G.jsxs)(`option`,{value:e,children:[t,` (`,e,`)`]},e))}),(0,G.jsx)(ds,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]})]}),p===`proxy`&&(0,G.jsx)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:(0,G.jsxs)(`div`,{className:`flex items-start gap-2 p-2 rounded bg-blue-50 border border-blue-300 dark:bg-blue-500/10 dark:border-blue-500/30`,children:[(0,G.jsx)(Vc,{className:`w-4 h-4 text-blue-600 dark:text-blue-400 flex-shrink-0 mt-0.5`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`virtualPrinter.proxy.accessCodeHint`)})]})}),p!==`proxy`&&(0,G.jsxs)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,G.jsx)(`div`,{className:`text-white text-sm font-medium`,children:n(`virtualPrinter.accessCode.title`)}),be?(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-xs text-blue-700 dark:text-blue-400`,children:[(0,G.jsx)(Vc,{className:`w-3 h-3`}),n(`virtualPrinter.accessCode.inheritedFromTarget`)]}):e.access_code_set?(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-xs text-green-700 dark:text-green-400`,children:[(0,G.jsx)(us,{className:`w-3 h-3`}),n(`virtualPrinter.accessCode.isSet`)]}):(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-xs text-yellow-700 dark:text-yellow-400`,children:[(0,G.jsx)(Pu,{className:`w-3 h-3`}),n(`virtualPrinter.accessCode.notSet`)]})]}),be?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(`input`,{type:P?`text`:`password`,value:xe,readOnly:!0,"aria-label":n(`virtualPrinter.accessCode.title`),className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-1.5 text-white text-sm pr-10 font-mono opacity-90 cursor-default`}),(0,G.jsx)(`button`,{onClick:()=>F(!P),className:`absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white`,"aria-label":n(P?`virtualPrinter.accessCode.hide`:`virtualPrinter.accessCode.reveal`),children:P?(0,G.jsx)(nc,{className:`w-4 h-4`}):(0,G.jsx)(rc,{className:`w-4 h-4`})})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(`virtualPrinter.accessCode.derivedFromTargetHint`)})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsxs)(`div`,{className:`relative flex-1`,children:[(0,G.jsx)(`input`,{type:P?`text`:`password`,value:d,onChange:e=>f(e.target.value),placeholder:e.access_code_set?n(`virtualPrinter.accessCode.placeholderChange`):n(`virtualPrinter.accessCode.placeholder`),maxLength:8,className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-1.5 text-white text-sm placeholder-bambu-gray pr-10 font-mono`}),(0,G.jsx)(`button`,{onClick:()=>F(!P),className:`absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white`,children:P?(0,G.jsx)(nc,{className:`w-4 h-4`}):(0,G.jsx)(rc,{className:`w-4 h-4`})})]}),(0,G.jsx)(Q,{onClick:de,disabled:!d||I===`accessCode`,variant:`primary`,children:I===`accessCode`?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):n(`common.save`)})]}),d&&(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:(0,G.jsx)(`span`,{className:d.length===8?`text-green-700 dark:text-green-400`:`text-yellow-700 dark:text-yellow-400`,children:n(`virtualPrinter.accessCode.charCount`,{count:d.length})})})]})]}),(0,G.jsxs)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:[(0,G.jsx)(`div`,{className:`text-white text-sm font-medium mb-2`,children:n(`virtualPrinter.targetPrinter.title`)}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsxs)(`select`,{value:h??``,onChange:e=>{let t=parseInt(e.target.value,10);isNaN(t)||me(t)},disabled:I===`targetPrinter`,className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-1.5 text-white text-sm appearance-none cursor-pointer disabled:opacity-50 pr-10`,children:[(0,G.jsx)(`option`,{value:``,children:n(`virtualPrinter.targetPrinter.placeholder`)}),oe?.map(e=>(0,G.jsxs)(`option`,{value:e.id,children:[e.name,` (`,e.ip_address,`)`]},e.id))]}),(0,G.jsx)(ds,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]})]}),(0,G.jsxs)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:[(0,G.jsx)(`div`,{className:`text-white text-sm font-medium mb-1`,children:n(`virtualPrinter.bindIp.title`)}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsxs)(`select`,{value:_,onChange:e=>{v(e.target.value),L(`bindIp`),H.mutate({bind_ip:e.target.value})},disabled:I===`bindIp`,className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-1.5 text-white text-sm appearance-none cursor-pointer disabled:opacity-50 pr-10`,children:[(0,G.jsx)(`option`,{value:``,children:n(`virtualPrinter.bindIp.placeholder`)}),se?.map(e=>(0,G.jsxs)(`option`,{value:e.ip,children:[e.name,` (`,e.ip,`)`,e.is_alias?` [alias]`:``,` - `,e.subnet]},e.ip))]}),(0,G.jsx)(ds,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(`virtualPrinter.bindIp.hint`)})]}),(0,G.jsxs)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,G.jsx)(`div`,{className:`text-white text-sm font-medium`,children:n(`virtualPrinter.remoteInterface.title`)}),b?(0,G.jsx)(`span`,{className:`flex items-center gap-1 text-xs text-green-700 dark:text-green-400`,children:(0,G.jsx)(us,{className:`w-3 h-3`})}):(0,G.jsx)(`span`,{className:`flex items-center gap-1 text-xs text-bambu-gray`,title:n(`virtualPrinter.remoteInterface.optional`),children:(0,G.jsx)(Vc,{className:`w-3 h-3`})})]}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsxs)(`select`,{value:b,onChange:e=>he(e.target.value),disabled:I===`remoteInterface`,className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-1.5 text-white text-sm appearance-none cursor-pointer disabled:opacity-50 pr-10`,children:[(0,G.jsx)(`option`,{value:``,children:n(`virtualPrinter.remoteInterface.placeholder`)}),se?.map(e=>(0,G.jsxs)(`option`,{value:e.ip,children:[e.name,` (`,e.ip,`) - `,e.subnet]},e.ip))]}),(0,G.jsx)(ds,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]})]})]})]}),R&&(0,G.jsx)(Zd,{title:n(`virtualPrinter.deleteConfirm.title`),message:n(`virtualPrinter.deleteConfirm.message`,{name:e.name}),variant:`danger`,confirmText:n(`common.delete`),isLoading:ce.isPending,onConfirm:()=>ce.mutate(),onCancel:()=>z(!1)}),B&&(0,G.jsx)(vHe,{vpId:e.id,vpName:e.name,onClose:()=>V(!1)})]})}var b6={archive:`archive`,review:`review`,queue:`queue`,proxy:`proxy`};function bHe({onClose:e}){let{t}=U(),n=so(),{showToast:r}=Bd(),[i,a]=(0,y.useState)(``),[o,s]=(0,y.useState)(`archive`),[c,l]=(0,y.useState)(null),{data:u}=K({queryKey:[`printers`],queryFn:Z.getPrinters}),d=q({mutationFn:()=>_d.create({name:i.trim()||`Bambuddy`,mode:o,target_printer_id:o===`proxy`?c??void 0:void 0}),onSuccess:()=>{n.invalidateQueries({queryKey:[`virtual-printers`]}),r(t(`virtualPrinter.toast.created`)),e()},onError:e=>{r(e.message||t(`virtualPrinter.toast.failedToCreate`),`error`)}});return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,onClick:e,children:(0,G.jsx)(Md,{className:`w-full max-w-md`,onClick:e=>e.stopPropagation(),children:(0,G.jsxs)(Pd,{className:`p-6 space-y-4`,children:[(0,G.jsx)(`h3`,{className:`text-lg font-semibold text-white`,children:t(`virtualPrinter.addDialog.title`)}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`text-sm text-white font-medium block mb-1`,children:t(`virtualPrinter.addDialog.name`)}),(0,G.jsx)(`input`,{type:`text`,value:i,onChange:e=>a(e.target.value),placeholder:`Bambuddy`,className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-2 text-white text-sm placeholder-bambu-gray`,autoFocus:!0})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`text-sm text-white font-medium block mb-1`,children:t(`virtualPrinter.mode.title`)}),(0,G.jsx)(`div`,{className:`grid grid-cols-2 gap-2`,children:[`archive`,`review`,`queue`,`proxy`].map(e=>(0,G.jsxs)(`button`,{onClick:()=>s(e),className:`p-2 rounded-lg border text-left transition-colors ${o===e?e===`proxy`?`border-blue-500 bg-blue-500/10`:`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary hover:border-bambu-gray`}`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 text-white text-xs font-medium`,children:[e===`proxy`&&(0,G.jsx)(Lo,{className:`w-3 h-3`}),t(`virtualPrinter.mode.${b6[e]}`)]}),(0,G.jsx)(`div`,{className:`text-[10px] text-bambu-gray`,children:t(`virtualPrinter.mode.${b6[e]}Desc`)})]},e))})]}),o===`proxy`&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`text-sm text-white font-medium block mb-1`,children:t(`virtualPrinter.targetPrinter.title`)}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsxs)(`select`,{value:c??``,onChange:e=>{let t=parseInt(e.target.value,10);l(isNaN(t)?null:t)},className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-2 text-white text-sm appearance-none cursor-pointer pr-10`,children:[(0,G.jsx)(`option`,{value:``,children:t(`virtualPrinter.targetPrinter.placeholder`)}),u?.map(e=>(0,G.jsxs)(`option`,{value:e.id,children:[e.name,` (`,e.ip_address,`)`]},e.id))]}),(0,G.jsx)(ds,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:t(`virtualPrinter.addDialog.hint`)}),(0,G.jsxs)(`div`,{className:`flex gap-3 pt-2`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:e,className:`flex-1`,disabled:d.isPending,children:t(`common.cancel`)}),(0,G.jsx)(Q,{variant:`primary`,onClick:()=>d.mutate(),className:`flex-1`,disabled:d.isPending,children:d.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):t(`virtualPrinter.addDialog.create`)})]})]})})})}function xHe(){let{t:e}=U(),t=so(),{showToast:n}=Bd(),[r,i]=(0,y.useState)(!1),{data:a,isLoading:o}=K({queryKey:[`virtual-printers`],queryFn:_d.list,refetchInterval:1e4}),{data:s}=K({queryKey:[`virtual-printer-settings`],queryFn:gd.getSettings}),c=q({mutationFn:e=>gd.updateSettings({archive_name_source:e}),onSuccess:()=>{t.invalidateQueries({queryKey:[`virtual-printer-settings`]}),n(e(`virtualPrinter.toast.updated`))},onError:t=>{n(t.message||e(`virtualPrinter.toast.failedToUpdate`),`error`)}}),l=s?.archive_name_source===`filename`,{data:u}=K({queryKey:[`vp-ca-certificate`],queryFn:_d.getCaCertificate,staleTime:1/0}),[d,f]=(0,y.useState)(!1),p=async()=>{u&&(await _6(u.pem)?(f(!0),n(e(`virtualPrinter.caCert.copied`)),setTimeout(()=>f(!1),2e3)):n(e(`virtualPrinter.toast.copyFailed`),`error`))},m=()=>{u&&gHe(u.pem,`bambuddy-virtual-printer-ca.crt`,`application/x-pem-file`)};if(o)return(0,G.jsx)(Md,{children:(0,G.jsx)(Pd,{className:`py-8 flex justify-center`,children:(0,G.jsx)(Y,{className:`w-6 h-6 animate-spin text-bambu-green`})})});let h=a?.printers||[],g=a?.models||{};return(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-3 gap-4 items-stretch`,children:[(0,G.jsx)(Md,{className:`border-l-4 border-l-yellow-500`,children:(0,G.jsx)(Pd,{className:`py-3 px-4`,children:(0,G.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,G.jsx)(Pu,{className:`w-4 h-4 text-yellow-500 flex-shrink-0 mt-0.5`}),(0,G.jsxs)(`div`,{className:`text-xs`,children:[(0,G.jsx)(`p`,{className:`text-white font-medium`,children:e(`virtualPrinter.setupRequired.title`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:e(`virtualPrinter.setupRequired.description`)}),(0,G.jsxs)(`a`,{href:`https://wiki.bambuddy.cool/features/virtual-printer/`,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center gap-1.5 mt-2 px-3 py-1.5 bg-yellow-100 dark:bg-yellow-500/20 border border-yellow-500/50 rounded text-yellow-700 dark:text-yellow-400 hover:bg-yellow-500/30 transition-colors text-xs`,children:[(0,G.jsx)(tc,{className:`w-3 h-3`}),e(`virtualPrinter.setupRequired.readGuide`)]})]})]})})}),(0,G.jsx)(Md,{className:`lg:col-span-2`,children:(0,G.jsx)(Pd,{className:`py-3 px-4`,children:(0,G.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,G.jsx)(Vc,{className:`w-4 h-4 text-blue-600 dark:text-blue-400 flex-shrink-0 mt-0.5`}),(0,G.jsxs)(`div`,{className:`text-xs text-bambu-gray`,children:[(0,G.jsx)(`p`,{className:`text-white font-medium mb-1`,children:e(`virtualPrinter.howItWorks.title`)}),(0,G.jsxs)(`ul`,{className:`space-y-1 list-disc list-inside`,children:[(0,G.jsx)(`li`,{children:e(`virtualPrinter.howItWorks.step1`)}),(0,G.jsx)(`li`,{children:e(`virtualPrinter.howItWorks.step2`)}),(0,G.jsx)(`li`,{children:e(`virtualPrinter.howItWorks.step3`)})]})]})]})})})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-4 items-stretch`,children:[(0,G.jsx)(Md,{children:(0,G.jsx)(Pd,{className:`py-3 px-4`,children:(0,G.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,G.jsx)(nu,{className:`w-4 h-4 text-bambu-green flex-shrink-0 mt-1`}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,G.jsx)(`p`,{className:`text-sm text-white font-medium`,children:e(`virtualPrinter.caCert.title`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[(0,G.jsxs)(`button`,{onClick:p,disabled:!u,className:`inline-flex items-center gap-1.5 px-2.5 py-1 text-xs rounded bg-bambu-dark-secondary border border-bambu-dark-tertiary text-white hover:border-bambu-gray disabled:opacity-50 transition-colors`,children:[d?(0,G.jsx)(us,{className:`w-3.5 h-3.5 text-bambu-green`}):(0,G.jsx)(zs,{className:`w-3.5 h-3.5`}),e(d?`virtualPrinter.caCert.copied`:`virtualPrinter.caCert.copy`)]}),(0,G.jsxs)(`button`,{onClick:m,disabled:!u,className:`inline-flex items-center gap-1.5 px-2.5 py-1 text-xs rounded bg-bambu-dark-secondary border border-bambu-dark-tertiary text-white hover:border-bambu-gray disabled:opacity-50 transition-colors`,children:[(0,G.jsx)(Js,{className:`w-3.5 h-3.5`}),e(`virtualPrinter.caCert.download`)]})]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`virtualPrinter.caCert.description`)}),u&&(0,G.jsxs)(`p`,{className:`text-[10px] text-bambu-gray font-mono mt-1 truncate`,title:u.fingerprint_sha256,children:[e(`virtualPrinter.caCert.fingerprint`),`: `,u.fingerprint_sha256]})]})]})})}),(0,G.jsx)(Md,{children:(0,G.jsx)(Pd,{className:`py-3 px-4`,children:(0,G.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,G.jsx)(lc,{className:`w-4 h-4 text-bambu-green flex-shrink-0 mt-1`}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,G.jsx)(`p`,{className:`text-sm text-white font-medium`,children:e(`virtualPrinter.archiveNameSource.title`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[(0,G.jsx)(`span`,{className:`text-xs ${l?`text-bambu-gray`:`text-white`}`,children:e(`virtualPrinter.archiveNameSource.metadata`)}),(0,G.jsx)(UH,{checked:l,onChange:e=>c.mutate(e?`filename`:`metadata`),disabled:c.isPending}),(0,G.jsx)(`span`,{className:`text-xs ${l?`text-white`:`text-bambu-gray`}`,children:e(`virtualPrinter.archiveNameSource.filename`)})]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`virtualPrinter.archiveNameSource.description`)})]})]})})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Fl,{className:`w-5 h-5 text-bambu-green`}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`virtualPrinter.list.title`)}),(0,G.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[`(`,h.length,`)`]})]}),(0,G.jsxs)(Q,{variant:`primary`,onClick:()=>i(!0),children:[(0,G.jsx)(Ml,{className:`w-4 h-4 mr-1`}),e(`virtualPrinter.list.add`)]})]}),h.length===0?(0,G.jsx)(Md,{children:(0,G.jsxs)(Pd,{className:`py-8 text-center`,children:[(0,G.jsx)(Fl,{className:`w-12 h-12 text-bambu-gray mx-auto mb-3`}),(0,G.jsx)(`p`,{className:`text-bambu-gray mb-4`,children:e(`virtualPrinter.list.empty`)}),(0,G.jsxs)(Q,{variant:`primary`,onClick:()=>i(!0),children:[(0,G.jsx)(Ml,{className:`w-4 h-4 mr-1`}),e(`virtualPrinter.list.addFirst`)]})]})}):(0,G.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-4 items-start`,children:h.map(e=>(0,G.jsx)(yHe,{printer:e,models:g},e.id))}),r&&(0,G.jsx)(bHe,{onClose:()=>i(!1)})]})}function x6(e){if(e<60)return`${e}s`;let t=Math.floor(e/60);if(t<60)return`${t}m`;let n=Math.floor(t/60),r=t%60;if(n<24)return r?`${n}h ${r}m`:`${n}h`;let i=Math.floor(n/24),a=n%24;return a?`${i}d ${a}h`:`${i}d`}function S6(e){return e==null?`—`:e>=1024?`${(e/1024).toFixed(1)} GB`:`${Math.round(e)} MB`}function SHe({device:e,onUnregister:t,isDeleting:n}){let{t:r}=U(),{showToast:i}=Bd(),a=e.system_stats,o=a?.memory,s=a?.disk,c=e.online,[l,u]=(0,y.useState)(null),[d,f]=(0,y.useState)(null),p=async t=>{f(t);try{t===`update`?await xd.triggerUpdate(e.device_id):await xd.systemCommand(e.device_id,t),i(r(`settings.spoolbuddy.commandQueued`),`success`)}catch(e){i(e instanceof Error?e.message:r(`settings.spoolbuddy.commandError`),`error`)}finally{f(null),u(null)}},m=[{key:`update`,label:r(`settings.spoolbuddy.update`),icon:Js},{key:`restart_browser`,label:r(`settings.spoolbuddy.restartBrowser`),icon:ml},{key:`restart_daemon`,label:r(`settings.spoolbuddy.restartDaemon`),icon:zl},{key:`reboot`,label:r(`settings.spoolbuddy.reboot`),icon:Hl},{key:`shutdown`,label:r(`settings.spoolbuddy.shutdown`),icon:Pl,variant:`danger`}],h={update:r(`settings.spoolbuddy.updateConfirmTitle`),restart_browser:r(`settings.spoolbuddy.restartBrowserConfirmTitle`),restart_daemon:r(`settings.spoolbuddy.restartDaemonConfirmTitle`),reboot:r(`settings.spoolbuddy.rebootConfirmTitle`),shutdown:r(`settings.spoolbuddy.shutdownConfirmTitle`)},g={update:r(`settings.spoolbuddy.updateConfirmBody`,{hostname:e.hostname}),restart_browser:r(`settings.spoolbuddy.restartBrowserConfirmBody`,{hostname:e.hostname}),restart_daemon:r(`settings.spoolbuddy.restartDaemonConfirmBody`,{hostname:e.hostname}),reboot:r(`settings.spoolbuddy.rebootConfirmBody`,{hostname:e.hostname}),shutdown:r(`settings.spoolbuddy.shutdownConfirmBody`,{hostname:e.hostname})};return(0,G.jsxs)(Md,{children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`div`,{className:`flex items-start justify-between gap-3 flex-wrap`,children:[(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`h3`,{className:`text-base font-semibold text-white truncate`,children:e.hostname}),(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-medium ${c?`bg-green-500/15 text-green-400 border border-green-500/40`:`bg-gray-500/15 text-gray-400 border border-gray-500/40`}`,children:[c?(0,G.jsx)(Yu,{className:`w-3 h-3`}):(0,G.jsx)(Ju,{className:`w-3 h-3`}),r(c?`settings.spoolbuddy.online`:`settings.spoolbuddy.offline`)]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray font-mono mt-1 truncate`,children:e.device_id})]}),(0,G.jsxs)(Q,{variant:`danger`,size:`sm`,onClick:()=>t(e),disabled:n,"aria-label":r(`settings.spoolbuddy.unregister`),children:[(0,G.jsx)(ju,{className:`w-3.5 h-3.5`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:r(`settings.spoolbuddy.unregister`)})]})]})}),(0,G.jsxs)(Pd,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{className:`grid grid-cols-2 sm:grid-cols-4 gap-3 text-xs`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`div`,{className:`text-bambu-gray`,children:r(`settings.spoolbuddy.ipAddress`)}),(0,G.jsx)(`div`,{className:`text-white font-mono`,children:e.ip_address})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`div`,{className:`text-bambu-gray`,children:r(`settings.spoolbuddy.firmware`)}),(0,G.jsx)(`div`,{className:`text-white`,children:e.firmware_version??`—`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`text-bambu-gray flex items-center gap-1`,children:[(0,G.jsx)(ks,{className:`w-3 h-3`}),r(`settings.spoolbuddy.lastSeen`)]}),(0,G.jsx)(`div`,{className:`text-white`,children:e.last_seen?$f(e.last_seen):r(`settings.spoolbuddy.never`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`div`,{className:`text-bambu-gray`,children:r(`settings.spoolbuddy.daemonUptime`)}),(0,G.jsx)(`div`,{className:`text-white`,children:x6(e.uptime_s)})]})]}),(0,G.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:m.map(({key:e,label:t,icon:n,variant:r})=>(0,G.jsxs)(Q,{variant:r??`secondary`,size:`sm`,onClick:()=>u(e),disabled:!c||d!==null,"aria-label":t,children:[d===e?(0,G.jsx)(Y,{className:`w-3.5 h-3.5 animate-spin`}):(0,G.jsx)(n,{className:`w-3.5 h-3.5`}),(0,G.jsx)(`span`,{children:t})]},e))}),(0,G.jsxs)(`div`,{className:`flex items-center gap-3 text-xs flex-wrap`,children:[(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-bambu-gray`,children:[e.nfc_ok?(0,G.jsx)(bs,{className:`w-3.5 h-3.5 text-green-400`}):(0,G.jsx)(Ts,{className:`w-3.5 h-3.5 text-red-400`}),r(`settings.spoolbuddy.nfc`),e.nfc_reader_type&&(0,G.jsxs)(`span`,{className:`text-bambu-gray/70`,children:[`(`,e.nfc_reader_type,`)`]})]}),(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-bambu-gray`,children:[e.scale_ok?(0,G.jsx)(bs,{className:`w-3.5 h-3.5 text-green-400`}):(0,G.jsx)(Ts,{className:`w-3.5 h-3.5 text-red-400`}),r(`settings.spoolbuddy.scale`)]})]}),a&&(0,G.jsxs)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-3 text-xs`,children:[a.cpu_temp_c!==void 0&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(ku,{className:`w-3.5 h-3.5 text-bambu-gray`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`div`,{className:`text-bambu-gray`,children:r(`settings.spoolbuddy.cpuTemp`)}),(0,G.jsxs)(`div`,{className:`text-white`,children:[a.cpu_temp_c.toFixed(1),`°C`]})]})]}),a.load_avg&&a.load_avg.length>0&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(jo,{className:`w-3.5 h-3.5 text-bambu-gray`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`div`,{className:`text-bambu-gray`,children:r(`settings.spoolbuddy.cpuLoad`)}),(0,G.jsxs)(`div`,{className:`text-white`,children:[a.load_avg[0].toFixed(2),a.cpu_count?` / ${a.cpu_count} (${Math.round(a.load_avg[0]/a.cpu_count*100)}%)`:``]})]})]}),o&&o.percent!==void 0&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Bs,{className:`w-3.5 h-3.5 text-bambu-gray`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`div`,{className:`text-bambu-gray`,children:r(`settings.spoolbuddy.memory`)}),(0,G.jsxs)(`div`,{className:`text-white`,children:[o.percent.toFixed(0),`% (`,S6(o.used_mb),` / `,S6(o.total_mb),`)`]})]})]}),s&&s.percent!==void 0&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(jc,{className:`w-3.5 h-3.5 text-bambu-gray`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`div`,{className:`text-bambu-gray`,children:r(`settings.spoolbuddy.disk`)}),(0,G.jsxs)(`div`,{className:`text-white`,children:[s.percent.toFixed(0),`% (`,s.used_gb?.toFixed(1),` / `,s.total_gb?.toFixed(1),` GB)`]})]})]}),a.system_uptime_s!==void 0&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(ks,{className:`w-3.5 h-3.5 text-bambu-gray`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`div`,{className:`text-bambu-gray`,children:r(`settings.spoolbuddy.systemUptime`)}),(0,G.jsx)(`div`,{className:`text-white`,children:x6(a.system_uptime_s)})]})]})]}),a.os&&(0,G.jsx)(`div`,{className:`mt-3 text-xs text-bambu-gray font-mono truncate`,children:[a.os.os,a.os.kernel,a.os.arch,a.os.python&&`Python ${a.os.python}`].filter(Boolean).join(` · `)})]})]}),l&&(0,G.jsx)(Zd,{variant:l===`shutdown`||l===`reboot`?`danger`:`default`,title:h[l],message:g[l],confirmText:r(`settings.spoolbuddy.commandConfirm`),isLoading:d!==null,onConfirm:()=>p(l),onCancel:()=>u(null)})]})}function CHe(){let{t:e}=U(),t=so(),{showToast:n}=Bd(),[r,i]=(0,y.useState)(null),{data:a=[],isLoading:o}=K({queryKey:[`spoolbuddy-devices`],queryFn:()=>xd.getDevices(),refetchInterval:15e3}),s=q({mutationFn:e=>xd.deleteDevice(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`spoolbuddy-devices`]}),n(e(`settings.spoolbuddy.unregisterSuccess`),`success`),i(null)},onError:t=>{n(t.message||e(`settings.spoolbuddy.unregisterError`),`error`)}});if(o)return(0,G.jsx)(Md,{children:(0,G.jsx)(Pd,{className:`py-8 flex justify-center`,children:(0,G.jsx)(Y,{className:`w-6 h-6 animate-spin text-bambu-green`})})});let c=a.length>1;return(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsx)(Md,{children:(0,G.jsx)(Pd,{className:`py-3 px-4`,children:(0,G.jsxs)(`div`,{className:`flex items-start gap-2 text-xs`,children:[(0,G.jsx)(Vc,{className:`w-4 h-4 text-blue-400 flex-shrink-0 mt-0.5`}),(0,G.jsxs)(`div`,{className:`text-bambu-gray`,children:[(0,G.jsx)(`p`,{className:`text-white font-medium mb-1`,children:e(`settings.spoolbuddy.infoTitle`)}),(0,G.jsx)(`p`,{children:e(`settings.spoolbuddy.infoBody`)})]})]})})}),c&&(0,G.jsx)(Md,{className:`border-l-4 border-l-yellow-500`,children:(0,G.jsx)(Pd,{className:`py-3 px-4`,children:(0,G.jsxs)(`div`,{className:`flex items-start gap-2 text-xs`,children:[(0,G.jsx)(Pu,{className:`w-4 h-4 text-yellow-500 flex-shrink-0 mt-0.5`}),(0,G.jsxs)(`div`,{className:`text-bambu-gray`,children:[(0,G.jsx)(`p`,{className:`text-white font-medium mb-1`,children:e(`settings.spoolbuddy.duplicatesTitle`,{count:a.length})}),(0,G.jsx)(`p`,{children:e(`settings.spoolbuddy.duplicatesBody`)})]})]})})}),a.length===0?(0,G.jsx)(Md,{children:(0,G.jsx)(Pd,{className:`py-8 text-center text-bambu-gray text-sm`,children:e(`settings.spoolbuddy.empty`)})}):(0,G.jsx)(`div`,{className:`space-y-3`,children:a.map(e=>(0,G.jsx)(SHe,{device:e,onUnregister:i,isDeleting:s.isPending&&s.variables===e.device_id},e.id))}),r&&(0,G.jsx)(Zd,{variant:`danger`,title:e(`settings.spoolbuddy.confirmTitle`),message:e(`settings.spoolbuddy.confirmBody`,{hostname:r.hostname,deviceId:r.device_id}),confirmText:e(`settings.spoolbuddy.unregister`),isLoading:s.isPending,onConfirm:()=>s.mutate(r.device_id),onCancel:()=>i(null)})]})}function C6(e,t,n,r,i){return n?e(`backup.restoreFromGit.${t}.${n}`,{...r??{},defaultValue:i??n}):i}var w6=[{id:`archives`,labelKey:`backup.printArchives`,icon:(0,G.jsx)(No,{className:`w-4 h-4`})},{id:`spools`,labelKey:`backup.spoolInventory`,icon:(0,G.jsx)(Sl,{className:`w-4 h-4`})},{id:`settings`,labelKey:`backup.appSettings`,icon:(0,G.jsx)(eu,{className:`w-4 h-4`})},{id:`kprofiles`,labelKey:`backup.kProfiles`,icon:(0,G.jsx)(ku,{className:`w-4 h-4`})}],T6=Object.fromEntries(w6.map(e=>[e.id,e.labelKey])),E6=`HEAD`;function wHe({onClose:e}){let{t}=U(),n=so(),[r,i]=(0,y.useState)(E6),[a,o]=(0,y.useState)({}),[s,c]=(0,y.useState)(!1),[l,u]=(0,y.useState)(!1),[d,f]=(0,y.useState)(null),p=K({queryKey:[`github-backup-commits`],queryFn:()=>Z.getGitHubBackupCommits(20)}),m=K({queryKey:[`github-restore-preview`,r],queryFn:()=>Z.getGitHubRestorePreview(r)}),h=m.data?.success?m.data.ref:r,g=(0,y.useMemo)(()=>{let e={};return m.data?.categories?.forEach(n=>{e[n.category]={available:n.available,itemCount:n.item_count,detail:C6(t,`details`,n.detail_code,n.detail_params,n.detail)}}),e},[m.data,t]),_=(0,y.useMemo)(()=>w6.filter(e=>a[e.id]&&g[e.id]?.available).map(e=>e.id),[a,g]),v=_.length,b=!s&&_.includes(`kprofiles`),x=q({mutationFn:()=>Z.restoreFromGitHub({ref:h,categories:_,overwrite_existing:s}),onSuccess:e=>{u(!1);let t=Object.keys(e.results??{}).length>0;(e.success||t)&&(f(e),n.invalidateQueries({queryKey:[`spools`]}),n.invalidateQueries({queryKey:[`archives`]}),n.invalidateQueries({queryKey:[`settings`]})),n.invalidateQueries({queryKey:[`github-backup-logs`]}),n.invalidateQueries({queryKey:[`github-backup-status`]})},onError:()=>u(!1)}),S=x.isPending,C=!!(d&&`settings`in d.results),w=(0,y.useCallback)(()=>{if(C){window.location.reload();return}e()},[C,e]);(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&!S&&!l&&w()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[w,S,l]),(0,y.useEffect)(()=>{if(!S)return;let e=e=>{e.preventDefault(),e.returnValue=``};return window.addEventListener(`beforeunload`,e),()=>window.removeEventListener(`beforeunload`,e)},[S]),(0,y.useEffect)(()=>{m.data&&o(e=>{let t={};return w6.forEach(n=>{t[n.id]=!!e[n.id]&&!!g[n.id]?.available}),t})},[m.data,g]);let T=p.data?.commits??[],E=(e,t,n)=>{let r=(t||``).split(`
`)[0],i=n?new Date(n).toLocaleString():``;return`${e.slice(0,7)} — ${i}${r?` — ${r}`:``}`},D=e=>e.isError?e.error?.message||t(`backup.restoreFromGit.loadFailed`):null,O=D(m)??(m.data&&!m.data.success?m.data.message:null),k=D(p)??(p.data&&!p.data.success?p.data.message:null);return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,onClick:S?void 0:w,children:(0,G.jsx)(Md,{className:`w-full max-w-lg`,onClick:e=>e.stopPropagation(),children:(0,G.jsxs)(Pd,{className:`p-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`p-2 rounded-full bg-bambu-green/20 text-bambu-green`,children:(0,G.jsx)(Vl,{className:`w-5 h-5`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`text-lg font-semibold text-white`,children:t(`backup.restoreFromGit.title`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:t(`backup.restoreFromGit.subtitle`)})]})]}),(0,G.jsx)(`button`,{onClick:w,disabled:S,"aria-label":t(`common.close`),className:`p-2 hover:bg-bambu-dark-tertiary rounded-lg transition-colors disabled:opacity-50`,children:(0,G.jsx)($u,{className:`w-5 h-5`})})]}),d?(0,G.jsxs)(`div`,{className:`p-4 space-y-3 max-h-[400px] overflow-y-auto`,children:[(0,G.jsxs)(`div`,{className:`flex items-start gap-2 text-sm`,children:[d.success?(0,G.jsx)(bs,{className:`w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0`}):(0,G.jsx)(Pu,{className:`w-4 h-4 text-yellow-500 mt-0.5 flex-shrink-0`}),(0,G.jsx)(`span`,{className:`text-white`,children:d.message})]}),!d.success&&(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:t(`backup.restoreFromGit.partialHint`)}),Object.entries(d.results).map(([e,n])=>(0,G.jsxs)(`div`,{className:`p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`span`,{className:`text-sm font-medium text-white`,children:T6[e]?t(T6[e]):e}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:t(`backup.restoreFromGit.tally`,{restored:n.restored,skipped:n.skipped,failed:n.failed})})]}),n.notes.length>0&&(0,G.jsx)(`ul`,{className:`mt-2 space-y-1`,children:n.notes.map(e=>(0,G.jsxs)(`li`,{className:`text-xs text-bambu-gray flex items-start gap-1.5`,children:[(0,G.jsx)(Vc,{className:`w-3 h-3 mt-0.5 flex-shrink-0`}),(0,G.jsx)(`span`,{children:C6(t,`notes`,e.code,e.params,e.message)})]},`${e.code}:${JSON.stringify(e.params)}`))})]},e)),(0,G.jsx)(`div`,{className:`p-3 rounded-lg bg-yellow-50 dark:bg-yellow-500/10 border border-yellow-300 dark:border-yellow-500/30`,children:(0,G.jsx)(`p`,{className:`text-xs text-yellow-700 dark:text-yellow-200`,children:t(`backup.restoreFromGit.reloadHint`)})})]}):(0,G.jsxs)(`div`,{className:`p-4 space-y-4 max-h-[400px] overflow-y-auto ${S?`opacity-50 pointer-events-none`:``}`,children:[x.isError&&(0,G.jsx)(`div`,{className:`p-3 rounded-lg bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30`,children:(0,G.jsx)(`p`,{className:`text-sm text-red-700 dark:text-red-400`,children:x.error?.message||t(`backup.restoreFromGit.failed`)})}),x.data&&!x.data.success&&(0,G.jsx)(`div`,{className:`p-3 rounded-lg bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30`,children:(0,G.jsx)(`p`,{className:`text-sm text-red-700 dark:text-red-400`,children:x.data.message})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{htmlFor:`restore-commit`,className:`block text-sm font-medium text-white mb-1`,children:t(`backup.restoreFromGit.commitLabel`)}),(0,G.jsxs)(`select`,{id:`restore-commit`,value:r,onChange:e=>{i(e.target.value),x.reset()},disabled:S||p.isLoading,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:[(0,G.jsx)(`option`,{value:E6,children:t(`backup.restoreFromGit.latestCommit`)}),T.map(e=>(0,G.jsx)(`option`,{value:e.sha,children:E(e.sha,e.message,e.date)},e.sha))]}),k&&(0,G.jsx)(`p`,{className:`mt-1 text-xs text-red-500 dark:text-red-400`,children:k})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm font-medium text-white mb-2`,children:t(`backup.restoreFromGit.categoriesLabel`)}),m.isLoading?(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-bambu-gray p-3`,children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),t(`backup.restoreFromGit.inspecting`)]}):O?(0,G.jsx)(`div`,{className:`p-3 rounded-lg bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30`,children:(0,G.jsx)(`p`,{className:`text-sm text-red-700 dark:text-red-400`,children:O})}):(0,G.jsx)(`div`,{className:`space-y-2`,children:w6.map(e=>{let n=g[e.id],r=!!n?.available,i=!!a[e.id]&&r;return(0,G.jsxs)(`label`,{className:`flex items-center gap-3 p-3 rounded-lg transition-colors ${r?`cursor-pointer`:`cursor-not-allowed opacity-50`} ${i?`bg-bambu-green/10 border border-bambu-green/30`:`bg-bambu-dark hover:bg-bambu-dark-tertiary border border-transparent`}`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:i,disabled:!r||S,onChange:()=>o(t=>({...t,[e.id]:!t[e.id]})),className:`w-4 h-4 rounded border-bambu-gray bg-bambu-dark text-bambu-green focus:ring-bambu-green focus:ring-offset-0`}),(0,G.jsx)(`div`,{className:i?`text-bambu-green`:`text-bambu-gray`,children:e.icon}),(0,G.jsxs)(`div`,{className:`flex-1`,children:[(0,G.jsxs)(`div`,{className:`text-white text-sm font-medium`,children:[t(e.labelKey),r&&n?.itemCount?(0,G.jsx)(`span`,{className:`ml-2 text-xs text-bambu-gray`,children:t(`backup.restoreFromGit.itemCount`,{count:n.itemCount})}):null]}),n?.detail&&(0,G.jsx)(`div`,{className:`text-xs text-bambu-gray`,children:n.detail}),e.id===`kprofiles`&&i&&b&&(0,G.jsx)(`div`,{className:`text-xs text-yellow-700 dark:text-yellow-200`,children:t(`backup.restoreFromGit.kprofilesOverwriteCaveat`)})]})]},e.id)})})]}),(0,G.jsx)(`div`,{className:`p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm font-medium text-white`,children:t(`backup.restoreFromGit.overwriteLabel`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:t(s?`backup.restoreFromGit.overwriteOn`:`backup.restoreFromGit.overwriteOff`)})]}),(0,G.jsx)(UH,{checked:s,onChange:c,disabled:S})]})})]}),(0,G.jsx)(`div`,{className:`flex items-center justify-between p-4 border-t border-bambu-dark-tertiary`,children:d?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`span`,{}),(0,G.jsxs)(`div`,{className:`flex gap-3`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:w,children:t(`common.close`)}),(0,G.jsx)(Q,{onClick:()=>window.location.reload(),className:`bg-bambu-green hover:bg-bambu-green-dark`,children:t(`backup.reloadNow`)})]})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:t(`backup.restoreFromGit.selectedCount`,{count:v})}),(0,G.jsxs)(`div`,{className:`flex gap-3`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:w,disabled:S,children:t(`common.cancel`)}),(0,G.jsx)(Q,{onClick:()=>u(!0),disabled:v===0||S,className:`bg-bambu-green hover:bg-bambu-green-dark disabled:opacity-50 disabled:cursor-not-allowed min-w-[100px]`,children:S?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 mr-2 animate-spin`}),t(`backup.restoreFromGit.restoring`)]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Vl,{className:`w-4 h-4 mr-2`}),t(`backup.restore`)]})})]})]})})]})})}),l&&(0,G.jsx)(Zd,{variant:`danger`,overlayZIndex:`z-[110]`,title:t(`backup.restoreFromGit.confirmTitle`),message:s?t(`backup.restoreFromGit.confirmMessageOverwrite`):b?`${t(`backup.restoreFromGit.confirmMessage`)} ${t(`backup.restoreFromGit.kprofilesOverwriteCaveat`)}`:t(`backup.restoreFromGit.confirmMessage`),confirmText:t(`backup.restore`),isLoading:S,loadingText:t(`backup.restoreFromGit.restoring`),onConfirm:()=>x.mutate(),onCancel:()=>u(!1)})]})}function D6(e){if(!e)return`-`;let t=Kf(e);return t?t.toLocaleString():`-`}function O6({status:e}){if(!e)return null;let t={success:`bg-green-100 dark:bg-green-500/20 text-green-700 dark:text-green-400`,failed:`bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400`,skipped:`bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400`,running:`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`},n={success:(0,G.jsx)(ys,{className:`w-3 h-3`}),failed:(0,G.jsx)(Ts,{className:`w-3 h-3`}),skipped:(0,G.jsx)(cu,{className:`w-3 h-3`}),running:(0,G.jsx)(Y,{className:`w-3 h-3 animate-spin`})};return(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded text-xs font-medium ${t[e]||`bg-gray-500/20 text-gray-400`}`,children:[n[e],e.charAt(0).toUpperCase()+e.slice(1)]})}var THe={github:`backup.repoUrlPlaceholderGitHub`,gitea:`backup.repoUrlPlaceholderGitea`,forgejo:`backup.repoUrlPlaceholderForgejo`,gitlab:`backup.repoUrlPlaceholderGitLab`},EHe={github:`ghp_xxxxxxxxxxxx`,gitea:`your_access_token`,forgejo:`your_access_token`,gitlab:`glpat-xxxxxxxxxxxx`},DHe={github:`backup.tokenHintGitHub`,gitea:`backup.tokenHintGitea`,forgejo:`backup.tokenHintForgejo`,gitlab:`backup.tokenHintGitLab`};function k6(e){return JSON.stringify(e)}function OHe(e,t){if(!t)return e;let n={};for(let r of Object.keys(e))e[r]!==t[r]&&(n[r]=e[r]);return n}function kHe(){let e=so(),{showToast:t}=Bd(),{t:n}=U(),{hasPermission:r}=Ed(),i=r(`github:restore`),[a,o]=(0,y.useState)(``),[s,c]=(0,y.useState)(``),[l,u]=(0,y.useState)(`main`),[d,f]=(0,y.useState)(`github`),[p,m]=(0,y.useState)(!1),[h,g]=(0,y.useState)(`daily`),[_,v]=(0,y.useState)(!0),[b,x]=(0,y.useState)(!0),[S,C]=(0,y.useState)(!1),[w,T]=(0,y.useState)(!1),[E,D]=(0,y.useState)(!1),[O,k]=(0,y.useState)(!1),[A,j]=(0,y.useState)(!0),[M,N]=(0,y.useState)(!1),[P,F]=(0,y.useState)(!1),[I,L]=(0,y.useState)(``),[R,z]=(0,y.useState)(!1),[B,V]=(0,y.useState)(null),[ee,te]=(0,y.useState)(null),ne=(0,y.useRef)(null),[re,ie]=(0,y.useState)(!1),[ae,oe]=(0,y.useState)(null),[se,H]=(0,y.useState)(null),[ce,le]=(0,y.useState)(``),{data:ue,refetch:de}=K({queryKey:[`local-backup-status`],queryFn:Z.getLocalBackupStatus,refetchInterval:e=>e.state.data?.is_running?1e3:1e4}),{data:fe,refetch:pe}=K({queryKey:[`local-backup-files`],queryFn:Z.getLocalBackups,refetchInterval:3e4}),{data:me,refetch:he}=K({queryKey:[`local-backup-path-check`],queryFn:Z.checkLocalBackupPath,enabled:ue?.enabled===!0,refetchOnWindowFocus:!1});(0,y.useEffect)(()=>{ue?.path!==void 0&&le(ue.path)},[ue?.path]);let ge=q({mutationFn:Z.triggerLocalBackup,onSuccess:e=>{e.success?t(n(`backup.scheduledBackupComplete`)):t(e.message,`error`),de(),pe(),he()},onError:()=>t(n(`backup.scheduledBackupFailed`),`error`)}),_e=q({mutationFn:e=>Z.deleteLocalBackup(e),onSuccess:()=>{pe(),oe(null)}}),ve=q({mutationFn:async e=>(H(null),F(!0),te(null),L(n(`backup.restoring`)),Z.restoreLocalBackup(e)),onSuccess:e=>{F(!1),L(``),e.success?(te({success:!0,message:e.message}),t(n(`backup.backupRestoredRestart`),`success`)):(te({success:!1,message:e.message}),t(e.message,`error`))},onError:e=>{F(!1),L(``);let r=e instanceof Error?e.message:n(`backup.failedToRestore`);te({success:!1,message:r}),t(r,`error`)}});(0,y.useEffect)(()=>{if(M||P){let e=e=>(e.preventDefault(),e.returnValue=`A backup operation is in progress. Are you sure you want to leave?`,e.returnValue);return window.addEventListener(`beforeunload`,e),()=>window.removeEventListener(`beforeunload`,e)}},[M,P]);let[ye,be]=(0,y.useState)(!1),[xe,Se]=(0,y.useState)(null),[Ce,we]=(0,y.useState)(null),Te=(0,y.useRef)(null),Ee=(0,y.useRef)(null),De=(0,y.useRef)(null),Oe=(0,y.useRef)(null),ke=(0,y.useRef)(``),[Ae,je]=(0,y.useState)(!1),Me=(0,y.useMemo)(()=>({repository_url:a,branch:l,provider:d,allow_insecure_http:O,schedule_enabled:p,schedule_type:h,backup_kprofiles:_,backup_cloud_profiles:b,backup_settings:S,backup_spools:w,backup_archives:E,enabled:A}),[a,l,d,O,p,h,_,b,S,w,E,A]),Ne=(0,y.useMemo)(()=>k6(Me),[Me]),{data:Pe,isLoading:Fe}=K({queryKey:[`github-backup-config`],queryFn:Z.getGitHubBackupConfig}),{data:Ie}=K({queryKey:[`github-backup-status`],queryFn:Z.getGitHubBackupStatus,refetchInterval:e=>e.state.data?.is_running?500:1e4}),{data:Le}=K({queryKey:[`github-backup-logs`],queryFn:()=>Z.getGitHubBackupLogs(20)}),{data:Re}=K({queryKey:[`cloud-status`],queryFn:Z.getCloudStatus}),{data:ze}=K({queryKey:[`github-backup-cloud-accounts`],queryFn:Z.getGitHubBackupCloudAccounts,staleTime:6e4}),Be=(ze?.bambu??0)+(ze?.orca??0),Ve=ze?Be>0:!!Re?.is_authenticated,{data:He}=K({queryKey:[`printers`],queryFn:Z.getPrinters}),Ue=So({queries:(He??[]).map(e=>({queryKey:[`printerStatus`,e.id],queryFn:()=>Z.getPrinterStatus(e.id),staleTime:1e4,refetchInterval:3e4}))}),We=(He??[]).map((e,t)=>({printer:e,connected:Ue[t]?.data?.connected??!1})),Ge=We.length,Ke=We.filter(e=>e.connected).length,qe=Ge>0&&Ke===0,Je=Ke>0&&Ke(De.current&&clearTimeout(De.current),Pe?(je(!1),Oe.current={repository_url:Pe.repository_url,branch:Pe.branch,provider:Pe.provider??`github`,allow_insecure_http:Pe.allow_insecure_http??!1,schedule_enabled:Pe.schedule_enabled,schedule_type:Pe.schedule_type,backup_kprofiles:Pe.backup_kprofiles,backup_cloud_profiles:Pe.backup_cloud_profiles,backup_settings:Pe.backup_settings,backup_spools:Pe.backup_spools,backup_archives:Pe.backup_archives,enabled:Pe.enabled},o(Pe.repository_url),u(Pe.branch),f(Pe.provider??`github`),m(Pe.schedule_enabled),g(Pe.schedule_type),v(Pe.backup_kprofiles),x(Pe.backup_cloud_profiles),C(Pe.backup_settings),T(Pe.backup_spools),D(Pe.backup_archives),k(Pe.allow_insecure_http??!1),j(Pe.enabled),c(``),De.current=setTimeout(()=>{je(!0)},100)):(je(!1),Oe.current=null,c(``)),()=>{De.current&&clearTimeout(De.current)}),[Pe]);let Ye=(0,y.useCallback)(async(r=!1)=>{if(Pe)try{r&&s?(await Z.saveGitHubBackupConfig({...Me,access_token:s}),c(``),we(null),t(n(`backup.tokenUpdated`)),ke.current=``):(await Z.updateGitHubBackupConfig(OHe(Me,Oe.current)),we(null),t(n(`backup.settingsSaved`))),Oe.current=Me,e.invalidateQueries({queryKey:[`github-backup-config`]}),e.invalidateQueries({queryKey:[`github-backup-status`]})}catch(e){we(e.message)}},[Pe,s,Me,e,t,n]),Xe=(0,y.useRef)(Ye);(0,y.useEffect)(()=>{Xe.current=Ye},[Ye]),(0,y.useEffect)(()=>{if(!(!Ae||!Pe)&&!(Oe.current&&Ne===k6(Oe.current)))return Te.current&&clearTimeout(Te.current),Te.current=setTimeout(()=>{Ye(!1)},500),()=>{Te.current&&clearTimeout(Te.current)}},[Ae,Pe,Ne,Ye]),(0,y.useEffect)(()=>{if(!(!Ae||!Pe||!s)&&s!==ke.current)return ke.current=s,Ee.current&&clearTimeout(Ee.current),Ee.current=setTimeout(()=>{Xe.current(!0)},1e3),()=>{Ee.current&&clearTimeout(Ee.current)}},[Ae,s,Pe]);let Ze=q({mutationFn:e=>Z.saveGitHubBackupConfig(e),onMutate:()=>{we(null)},onSuccess:()=>{e.invalidateQueries({queryKey:[`github-backup-config`]}),e.invalidateQueries({queryKey:[`github-backup-status`]}),t(n(`backup.githubBackupEnabled`)),c(``),je(!0)},onError:e=>{we(e.message)}}),Qe=q({mutationFn:Z.triggerGitHubBackup,onSuccess:r=>{e.invalidateQueries({queryKey:[`github-backup-status`]}),e.invalidateQueries({queryKey:[`github-backup-logs`]}),r.success?r.files_changed>0?t(n(`backup.backupCompleteFiles`,{count:r.files_changed})):t(n(`backup.backupSkippedNoChanges`)):t(n(`backup.backupFailed2`,{message:r.message}),`error`)},onError:e=>{t(n(`backup.backupFailed2`,{message:e.message}),`error`)}}),$e=q({mutationFn:()=>Z.clearGitHubBackupLogs(0),onSuccess:r=>{e.invalidateQueries({queryKey:[`github-backup-logs`]}),t(n(`backup.clearedLogs`,{count:r.deleted}))},onError:e=>{t(n(`backup.failedToClearLogs`,{message:e.message}),`error`)}}),et=async()=>{be(!0),Se(null);try{let e;if(s){if(!a){t(n(`backup.enterRepoUrl`),`error`),be(!1);return}e=await Z.testGitHubConnection(a,s,d)}else if(Pe?.has_token)e=await Z.testGitHubStoredConnection();else{t(n(`backup.enterRepoAndToken`),`error`),be(!1);return}Se({success:e.success,message:e.message,isPrivate:e.is_private})}catch(e){Se({success:!1,message:e.message,isPrivate:null})}finally{be(!1)}};return Fe?(0,G.jsx)(`div`,{className:`flex items-center justify-center py-12`,children:(0,G.jsx)(Y,{className:`w-8 h-8 animate-spin text-bambu-green`})}):(0,G.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-6`,children:[(0,G.jsxs)(`div`,{className:`space-y-6`,children:[(0,G.jsxs)(Md,{id:`card-backup-github`,children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Ec,{className:`w-5 h-5 text-gray-400`}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:n(`backup.githubBackup`)})]}),Pe&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:n(`backup.enabled`)}),(0,G.jsx)(UH,{checked:A,onChange:j})]})]})}),(0,G.jsxs)(Pd,{className:`space-y-4`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`backup.githubDescription`)}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{htmlFor:`git-provider-select`,className:`block text-sm text-bambu-gray mb-1`,children:n(`backup.provider`)}),(0,G.jsxs)(`select`,{id:`git-provider-select`,value:d,onChange:e=>{f(e.target.value),Se(null),we(null)},className:`w-full h-10 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,G.jsx)(`option`,{value:`github`,children:n(`backup.providerGitHub`)}),(0,G.jsx)(`option`,{value:`gitlab`,children:n(`backup.providerGitLab`)}),(0,G.jsx)(`option`,{value:`gitea`,children:n(`backup.providerGitea`)}),(0,G.jsx)(`option`,{value:`forgejo`,children:n(`backup.providerForgejo`)})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`backup.repositoryUrl`)}),(0,G.jsx)(`input`,{type:`text`,value:a,onChange:e=>{o(e.target.value),Se(null),we(null)},placeholder:n(THe[d]),className:`w-full h-10 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,G.jsxs)(`label`,{className:`flex items-start gap-2 mt-2 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:O,onChange:e=>{k(e.target.checked),Se(null)},className:`w-4 h-4 mt-0.5 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-sm text-white`,children:n(`backup.allowInsecureHttp`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`backup.allowInsecureHttpHint`)})]})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[n(`backup.personalAccessToken`),` `,Pe?.has_token&&(0,G.jsx)(`span`,{className:`text-green-700 dark:text-green-400`,children:n(`backup.tokenSaved`)})]}),(0,G.jsx)(`input`,{type:`password`,value:s,onChange:e=>{c(e.target.value),Se(null),we(null)},placeholder:Pe?.has_token?n(`backup.enterNewToken`):EHe[d],className:`w-full h-10 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(DHe[d])})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`backup.branch`)}),(0,G.jsx)(`input`,{type:`text`,value:l,onChange:e=>u(e.target.value),placeholder:`main`,className:`w-full h-10 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`backup.autoBackup`)}),(0,G.jsxs)(`select`,{value:p?h:`disabled`,onChange:e=>{e.target.value===`disabled`?m(!1):(m(!0),g(e.target.value))},className:`w-full h-10 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,G.jsx)(`option`,{value:`disabled`,children:n(`backup.manualOnly`)}),(0,G.jsx)(`option`,{value:`hourly`,children:n(`backup.hourly`)}),(0,G.jsx)(`option`,{value:`daily`,children:n(`backup.daily`)}),(0,G.jsx)(`option`,{value:`weekly`,children:n(`backup.weekly`)})]})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-2`,children:n(`backup.includeInBackup`)}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsxs)(`label`,{className:`flex items-start gap-2 ${qe?`cursor-not-allowed opacity-60`:`cursor-pointer`}`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:_,onChange:e=>v(e.target.checked),className:`w-4 h-4 mt-0.5 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`,disabled:qe}),(0,G.jsxs)(`div`,{className:`flex-1`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-sm ${qe?`text-bambu-gray`:`text-white`}`,children:n(`backup.kProfiles`)}),qe&&(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-xs bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400`,children:[(0,G.jsx)(Pu,{className:`w-3 h-3`}),n(`backup.noPrintersConnected`)]}),Je&&(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-xs bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400`,children:[(0,G.jsx)(Pu,{className:`w-3 h-3`}),n(`backup.printersConnected`,{connected:Ke,total:Ge})]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`backup.kProfilesDescription`)})]})]}),(0,G.jsxs)(`label`,{className:`flex items-start gap-2 ${Ve?`cursor-pointer`:`cursor-not-allowed opacity-60`}`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:b,onChange:e=>x(e.target.checked),className:`w-4 h-4 mt-0.5 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`,disabled:!Ve}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-sm ${Ve?`text-white`:`text-bambu-gray`}`,children:n(`backup.cloudProfiles`)}),!Ve&&(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-xs bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400`,children:[(0,G.jsx)(Pu,{className:`w-3 h-3`}),n(`backup.cloudLoginRequiredShort`)]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`backup.cloudProfilesDescription`)}),Be>0&&(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:n(`backup.cloudProfilesAccounts`,{bambu:ze?.bambu??0,orca:ze?.orca??0})})]})]}),(0,G.jsxs)(`label`,{className:`flex items-start gap-2 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:S,onChange:e=>C(e.target.checked),className:`w-4 h-4 mt-0.5 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-white text-sm`,children:n(`backup.appSettings`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`backup.appSettingsDescription`)})]})]}),(0,G.jsxs)(`label`,{className:`flex items-start gap-2 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:w,onChange:e=>T(e.target.checked),className:`w-4 h-4 mt-0.5 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-white text-sm`,children:n(`backup.spoolInventory`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`backup.spoolInventoryDescription`)})]})]}),(0,G.jsxs)(`label`,{className:`flex items-start gap-2 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:E,onChange:e=>D(e.target.checked),className:`w-4 h-4 mt-0.5 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-white text-sm`,children:n(`backup.printArchives`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`backup.printArchivesDescription`)})]})]})]})]}),(0,G.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary pt-4 space-y-3`,children:[Ie?.configured&&(0,G.jsxs)(`div`,{className:`flex items-center justify-between text-sm`,children:[(0,G.jsx)(`div`,{className:`flex items-center gap-2 text-bambu-gray`,children:Ie.last_backup_at?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`span`,{children:[n(`backup.lastBackupAt`),` `,$f(Ie.last_backup_at,`system`,n)]}),(0,G.jsx)(O6,{status:Ie.last_backup_status})]}):(0,G.jsx)(`span`,{children:n(`backup.noBackupsYet`)})}),Ie.next_scheduled_run&&(0,G.jsxs)(`span`,{className:`text-bambu-gray`,children:[(0,G.jsx)(ks,{className:`w-3 h-3 inline mr-1`}),n(`backup.next`),` `,$f(Ie.next_scheduled_run,`system`,n)]})]}),Ce&&(0,G.jsxs)(`div`,{className:`text-sm text-red-700 dark:text-red-400 bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30 rounded p-3 flex items-start gap-2`,children:[(0,G.jsx)(Ts,{className:`w-4 h-4 mt-0.5 shrink-0`}),(0,G.jsx)(`div`,{className:`flex-1 leading-relaxed whitespace-pre-wrap break-words`,children:Ce}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>we(null),className:`text-bambu-gray hover:text-white shrink-0`,"aria-label":n(`common.dismiss`,`Dismiss`),children:(0,G.jsx)(Ts,{className:`w-4 h-4`})})]}),xe&&(0,G.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,G.jsxs)(`div`,{className:`text-sm flex items-center gap-1 ${xe.success?`text-green-700 dark:text-green-400`:`text-red-700 dark:text-red-400`}`,children:[xe.success?(0,G.jsx)(ys,{className:`w-4 h-4`}):(0,G.jsx)(Ts,{className:`w-4 h-4`}),xe.message]}),xe.success&&xe.isPrivate===!0&&(0,G.jsxs)(`div`,{className:`text-xs flex items-center gap-1 text-green-700 dark:text-green-400`,children:[(0,G.jsx)(ys,{className:`w-3.5 h-3.5`}),n(`backup.repoIsPrivate`,`Repository is private — safe to back up to.`)]}),xe.success&&xe.isPrivate===!1&&(0,G.jsxs)(`div`,{className:`text-xs text-red-700 dark:text-red-400 bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30 rounded p-2 flex items-start gap-1.5`,children:[(0,G.jsx)(Ts,{className:`w-4 h-4 mt-0.5 shrink-0`}),(0,G.jsx)(`span`,{children:n(`backup.repoIsPublicWarning`,`Repository is PUBLIC. Bambuddy backups include MQTT credentials, Home Assistant tokens, Prometheus tokens, your Bambu Cloud email, and printer access codes via K-profiles. Saving is blocked until you make the repository private in your provider's settings.`)})]}),xe.success&&xe.isPrivate===null&&(0,G.jsxs)(`div`,{className:`text-xs text-yellow-700 dark:text-yellow-400 bg-yellow-50 dark:bg-yellow-500/10 border border-yellow-300 dark:border-yellow-500/30 rounded p-2 flex items-start gap-1.5`,children:[(0,G.jsx)(Ts,{className:`w-4 h-4 mt-0.5 shrink-0`}),(0,G.jsx)(`span`,{children:n(`backup.repoVisibilityUnknown`,`Could not determine repository visibility. Bambuddy refuses to back up to anything not confirmed private; saving will be blocked.`)})]})]}),(0,G.jsx)(`div`,{className:`flex flex-wrap items-center gap-2`,children:Ie?.configured?(0,G.jsx)(G.Fragment,{children:Qe.isPending||Ie.is_running?(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-green`,children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),(0,G.jsx)(`span`,{className:`text-sm`,children:Ie.progress||n(`backup.startingBackup`)})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(Q,{variant:`primary`,size:`sm`,onClick:()=>Qe.mutate(),disabled:!Pe?.enabled,children:[(0,G.jsx)(Al,{className:`w-4 h-4`}),n(`backup.backupNow`)]}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:et,disabled:ye,children:[ye?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(zl,{className:`w-4 h-4`}),n(`backup.test`)]}),i&&(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:()=>ie(!0),disabled:Ie.restore_running,children:[(0,G.jsx)(Vl,{className:`w-4 h-4`}),n(`backup.restoreFromGit.button`)]})]})}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(Q,{variant:`primary`,size:`sm`,onClick:()=>{if(!a){t(n(`backup.repoRequired`),`error`);return}if(!s){t(n(`backup.tokenRequired`),`error`);return}Ze.mutate({repository_url:a,access_token:s,branch:l,provider:d,allow_insecure_http:O,schedule_enabled:p,schedule_type:h,backup_kprofiles:_,backup_cloud_profiles:b,backup_settings:S,backup_spools:w,backup_archives:E,enabled:A})},disabled:Ze.isPending||!a||!s,children:[Ze.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(ys,{className:`w-4 h-4`}),n(`backup.enableBackup`)]}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:et,disabled:ye||!a||!s,children:[ye?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(zl,{className:`w-4 h-4`}),n(`backup.testConnection`)]})]})})]})]})]}),Le&&Le.length>0&&(0,G.jsxs)(Md,{id:`card-backup-history`,children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Ic,{className:`w-5 h-5 text-gray-400`}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:n(`backup.history`)})]}),(0,G.jsxs)(Q,{variant:`ghost`,size:`sm`,onClick:()=>$e.mutate(),disabled:$e.isPending,children:[(0,G.jsx)(ju,{className:`w-4 h-4`}),n(`backup.clear`)]})]})}),(0,G.jsx)(Pd,{children:(0,G.jsx)(`div`,{className:`overflow-x-auto`,children:(0,G.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,G.jsx)(`thead`,{children:(0,G.jsxs)(`tr`,{className:`text-bambu-gray border-b border-bambu-dark-tertiary`,children:[(0,G.jsx)(`th`,{className:`text-left py-2 px-2`,children:n(`backup.date`)}),(0,G.jsx)(`th`,{className:`text-left py-2 px-2`,children:n(`backup.trigger`)}),(0,G.jsx)(`th`,{className:`text-left py-2 px-2`,children:n(`backup.status`)}),(0,G.jsx)(`th`,{className:`text-left py-2 px-2`,children:n(`backup.commit`)})]})}),(0,G.jsx)(`tbody`,{children:Le.slice(0,10).map(e=>(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/50 hover:bg-bambu-dark-secondary`,children:[(0,G.jsx)(`td`,{className:`py-2 px-2 text-white`,children:D6(e.started_at)}),(0,G.jsx)(`td`,{className:`py-2 px-2 text-bambu-gray`,children:n(`backup.triggers.${e.trigger}`,{defaultValue:e.trigger})}),(0,G.jsx)(`td`,{className:`py-2 px-2`,children:(0,G.jsx)(O6,{status:e.status})}),(0,G.jsx)(`td`,{className:`py-2 px-2`,children:e.commit_sha?(0,G.jsxs)(`a`,{href:`${Pe?.repository_url}/commit/${e.commit_sha}`,target:`_blank`,rel:`noopener noreferrer`,className:`text-bambu-green hover:underline inline-flex items-center gap-1`,children:[e.commit_sha.substring(0,7),(0,G.jsx)(tc,{className:`w-3 h-3`})]}):(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:`-`})})]},e.id))})]})})})]})]}),(0,G.jsxs)(`div`,{className:`space-y-6`,children:[(0,G.jsxs)(Md,{id:`card-backup-local`,children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Us,{className:`w-5 h-5 text-gray-400`}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:n(`backup.localBackup`)})]})}),(0,G.jsxs)(Pd,{className:`space-y-4`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`backup.localBackupDescription`)}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between py-3 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:n(`backup.downloadBackupLabel`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`backup.completeBackupZip`)})]}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,disabled:M||P,onClick:async()=>{N(!0),L(n(`backup.preparingBackup`));try{L(n(`backup.creatingArchive`));let{blob:e,filename:r}=await Z.exportBackup();L(n(`backup.downloadingFile`));let i=URL.createObjectURL(e),a=document.createElement(`a`);a.href=i,a.download=r,a.click(),URL.revokeObjectURL(i),t(n(`backup.backupDownloaded`))}catch(e){t(n(`backup.failedToCreateBackup`,{message:e instanceof Error?e.message:`Unknown error`}),`error`)}finally{N(!1),L(``)}},children:[(0,G.jsx)(Js,{className:`w-4 h-4`}),n(`backup.download`)]})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between py-3 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:n(`backup.restoreBackup`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`backup.restoreDescription`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray-light mt-1`,children:n(`backup.restoreNote`)})]}),(0,G.jsx)(`input`,{ref:ne,type:`file`,accept:`.zip`,className:`hidden`,onChange:e=>{let t=e.target.files?.[0];t&&(V(t),z(!0)),e.target.value=``}}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,disabled:P||M,onClick:()=>ne.current?.click(),children:[(0,G.jsx)(Ru,{className:`w-4 h-4`}),n(`backup.restore`)]})]}),ee&&(0,G.jsx)(`div`,{className:`p-3 rounded-lg ${ee.success?`bg-green-50 dark:bg-green-500/10 border border-green-300 dark:border-green-500/30`:`bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30`}`,children:(0,G.jsxs)(`div`,{className:`flex items-start gap-2 text-sm`,children:[ee.success?(0,G.jsx)(ys,{className:`w-4 h-4 text-green-600 dark:text-green-400 mt-0.5 flex-shrink-0`}):(0,G.jsx)(Ts,{className:`w-4 h-4 text-red-600 dark:text-red-400 mt-0.5 flex-shrink-0`}),(0,G.jsxs)(`div`,{className:ee.success?`text-green-800 dark:text-green-200`:`text-red-800 dark:text-red-200`,children:[ee.message,ee.success&&(0,G.jsx)(`div`,{className:`mt-2`,children:(0,G.jsxs)(Q,{size:`sm`,onClick:()=>window.location.reload(),children:[(0,G.jsx)(Vl,{className:`w-3 h-3`}),n(`backup.reloadNow`)]})})]})]})}),(0,G.jsx)(`div`,{className:`p-3 rounded-lg bg-yellow-50 dark:bg-yellow-500/10 border border-yellow-300 dark:border-yellow-500/30`,children:(0,G.jsxs)(`div`,{className:`flex items-start gap-2 text-sm`,children:[(0,G.jsx)(Pu,{className:`w-4 h-4 text-yellow-600 dark:text-yellow-400 mt-0.5 flex-shrink-0`}),(0,G.jsxs)(`div`,{className:`text-yellow-800 dark:text-yellow-200`,children:[(0,G.jsx)(`span`,{className:`font-medium`,children:n(`backup.restoreReplacesAll`)}),` `,(0,G.jsx)(`span`,{className:`text-yellow-800/80 dark:text-yellow-200/70`,children:n(`backup.restoreReplacesAllDetail`)})]})]})})]})]}),(0,G.jsxs)(Md,{id:`card-backup-scheduled`,children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(pc,{className:`w-5 h-5 text-gray-400`}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:n(`backup.scheduledBackup`)})]}),(0,G.jsx)(UH,{checked:ue?.enabled??!1,onChange:async r=>{try{await Z.updateSettings({local_backup_enabled:r}),e.invalidateQueries({queryKey:[`settings`]}),t(n(`backup.settingsSaved`))}catch(e){t(n(`backup.failedToSave`,{message:e instanceof Error?e.message:`Unknown error`}),`error`)}de()}})]})}),(0,G.jsxs)(Pd,{className:`space-y-4`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n(`backup.scheduledBackupDescription`)}),ue?.enabled&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`grid grid-cols-3 gap-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`backup.frequency`)}),(0,G.jsxs)(`select`,{value:ue?.schedule??`daily`,className:`w-full h-10 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,onChange:async e=>{try{await Z.updateSettings({local_backup_schedule:e.target.value}),t(n(`backup.settingsSaved`))}catch(e){t(n(`backup.failedToSave`,{message:e instanceof Error?e.message:`Unknown error`}),`error`)}de()},children:[(0,G.jsx)(`option`,{value:`hourly`,children:n(`backup.hourly`)}),(0,G.jsx)(`option`,{value:`daily`,children:n(`backup.daily`)}),(0,G.jsx)(`option`,{value:`weekly`,children:n(`backup.weekly`)})]})]}),(ue?.schedule??`daily`)!==`hourly`&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`backup.backupTime`)}),(0,G.jsx)(`input`,{type:`time`,value:ue?.time??`03:00`,className:`w-full h-10 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none [color-scheme:dark]`,onChange:async e=>{try{await Z.updateSettings({local_backup_time:e.target.value}),t(n(`backup.settingsSaved`))}catch(e){t(n(`backup.failedToSave`,{message:e instanceof Error?e.message:`Unknown error`}),`error`)}de()}}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray-light mt-1`,children:n(`backup.localTimeHint`,{tz:ue?.timezone||`UTC`})})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`backup.retention`)}),(0,G.jsx)(`input`,{type:`number`,min:1,max:100,value:ue?.retention??5,className:`w-full h-10 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,onChange:async e=>{let r=Math.max(1,Math.min(100,parseInt(e.target.value)||5));try{await Z.updateSettings({local_backup_retention:r}),t(n(`backup.settingsSaved`))}catch(e){t(n(`backup.failedToSave`,{message:e instanceof Error?e.message:`Unknown error`}),`error`)}de()}}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray-light mt-1`,children:n(`backup.retentionDescription`)})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`backup.outputPath`)}),(0,G.jsx)(`input`,{type:`text`,value:ce,onChange:e=>le(e.target.value),className:`w-full h-10 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,onBlur:async()=>{try{await Z.updateSettings({local_backup_path:ce}),t(n(`backup.settingsSaved`))}catch(e){t(n(`backup.failedToSave`,{message:e instanceof Error?e.message:`Unknown error`}),`error`)}de(),pe(),he()},onKeyDown:e=>{e.key===`Enter`&&e.target.blur()}}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray-light mt-1`,children:ce?n(`backup.outputPathDescription`):(0,G.jsxs)(G.Fragment,{children:[n(`backup.defaultPathLabel`),` `,(0,G.jsx)(`code`,{className:`text-bambu-gray`,children:ue?.default_path||`...`})]})}),me&&!me.writable&&(0,G.jsx)(`div`,{className:`mt-2 p-3 rounded-lg bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30`,children:(0,G.jsxs)(`div`,{className:`flex items-start gap-2 text-sm`,children:[(0,G.jsx)(Pu,{className:`w-4 h-4 text-red-600 dark:text-red-400 mt-0.5 flex-shrink-0`}),(0,G.jsxs)(`div`,{className:`min-w-0 text-red-800 dark:text-red-200`,children:[(0,G.jsx)(`p`,{className:`font-medium`,children:n(`backup.pathCheck.title`)}),(0,G.jsx)(`p`,{className:`mt-1 text-red-800/80 dark:text-red-200/80`,children:n(`backup.pathCheck.${me.code}`,{path:me.path,defaultValue:me.message})}),me.remedy&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`p`,{className:`mt-2 font-medium`,children:n(`backup.pathCheck.howToFix`)}),(0,G.jsx)(`pre`,{className:`mt-1 p-2 rounded bg-black/10 dark:bg-black/40 text-xs whitespace-pre-wrap break-words`,children:me.remedy})]}),me.detail&&(0,G.jsx)(`p`,{className:`mt-2 text-xs text-red-800/60 dark:text-red-200/60 break-words`,children:me.detail})]})]})}),me?.writable&&me.warning===`container_ephemeral`&&(0,G.jsx)(`div`,{className:`mt-2 p-3 rounded-lg bg-yellow-50 dark:bg-yellow-500/10 border border-yellow-300 dark:border-yellow-500/30`,children:(0,G.jsxs)(`div`,{className:`flex items-start gap-2 text-sm`,children:[(0,G.jsx)(Pu,{className:`w-4 h-4 text-yellow-600 dark:text-yellow-400 mt-0.5 flex-shrink-0`}),(0,G.jsxs)(`div`,{className:`min-w-0 text-yellow-800 dark:text-yellow-200`,children:[(0,G.jsx)(`p`,{className:`font-medium`,children:n(`backup.pathCheck.ephemeralTitle`)}),(0,G.jsx)(`p`,{className:`mt-1 text-yellow-800/80 dark:text-yellow-200/80`,children:n(`backup.pathCheck.container_ephemeral`,{path:me.path})}),me.remedy&&(0,G.jsx)(`pre`,{className:`mt-1 p-2 rounded bg-black/10 dark:bg-black/40 text-xs whitespace-pre-wrap break-words`,children:me.remedy})]})]})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between py-3 border-t border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`text-sm`,children:[ue?.last_backup_at&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray`,children:[(0,G.jsxs)(`span`,{children:[n(`backup.lastBackup`),`:`]}),(0,G.jsx)(O6,{status:ue.last_status}),(0,G.jsx)(`span`,{children:$f(ue.last_backup_at)})]}),ue?.next_run&&(0,G.jsxs)(`div`,{className:`text-bambu-gray mt-1`,children:[(0,G.jsxs)(`span`,{children:[n(`backup.nextBackup`),`: `]}),(0,G.jsx)(`span`,{children:D6(ue.next_run)})]})]}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,disabled:ue?.is_running||ge.isPending,onClick:()=>ge.mutate(),children:[ue?.is_running||ge.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Al,{className:`w-4 h-4`}),ue?.is_running?n(`backup.backupRunning`):n(`backup.runNow`)]})]}),fe&&fe.length>0&&(0,G.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary pt-3`,children:[(0,G.jsx)(`h3`,{className:`text-sm font-medium text-white mb-2`,children:n(`backup.backupFiles`)}),(0,G.jsx)(`div`,{className:`space-y-1`,children:fe.map(e=>(0,G.jsxs)(`div`,{className:`flex items-center justify-between py-1.5 px-2 rounded hover:bg-bambu-dark-tertiary/50 text-sm`,children:[(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`span`,{className:`text-white truncate block`,children:e.filename}),(0,G.jsxs)(`span`,{className:`text-bambu-gray text-xs`,children:[(e.size/1024/1024).toFixed(1),` MB · `,D6(e.created_at)]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1 flex-shrink-0`,children:[(0,G.jsx)(`button`,{className:`text-bambu-gray hover:text-bambu-green p-1`,title:n(`backup.download`),onClick:async()=>{try{let{blob:t,filename:n}=await Z.downloadLocalBackup(e.filename),r=URL.createObjectURL(t),i=document.createElement(`a`);i.href=r,i.download=n,i.click(),URL.revokeObjectURL(r)}catch{t(n(`backup.scheduledBackupFailed`),`error`)}},children:(0,G.jsx)(Js,{className:`w-3.5 h-3.5`})}),(0,G.jsx)(`button`,{className:`text-bambu-gray hover:text-yellow-600 dark:hover:text-yellow-400 p-1`,title:n(`backup.restore`),onClick:()=>H(e.filename),children:(0,G.jsx)(Vl,{className:`w-3.5 h-3.5`})}),(0,G.jsx)(`button`,{className:`text-bambu-gray hover:text-red-600 dark:hover:text-red-400 p-1`,onClick:()=>oe(e.filename),title:n(`backup.deleteBackup`),children:(0,G.jsx)(ju,{className:`w-3.5 h-3.5`})})]})]},e.filename))})]}),fe&&fe.length===0&&(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray text-center py-3 border-t border-bambu-dark-tertiary`,children:n(`backup.noScheduledBackups`)})]})]})]})]}),re&&(0,G.jsx)(wHe,{onClose:()=>ie(!1)}),ae&&(0,G.jsx)(Zd,{title:n(`backup.deleteBackup`),message:n(`backup.deleteBackupConfirm`),confirmText:n(`backup.deleteBackup`),variant:`danger`,onConfirm:()=>_e.mutate(ae),onCancel:()=>oe(null)}),se&&(0,G.jsx)(Zd,{title:n(`backup.restoreConfirmTitle`),message:n(`backup.restoreConfirmMessage`,{filename:se}),confirmText:n(`backup.restoreConfirmButton`),variant:`danger`,onConfirm:()=>ve.mutate(se),onCancel:()=>H(null)}),R&&B&&(0,G.jsx)(Zd,{title:n(`backup.restoreConfirmTitle`),message:n(`backup.restoreConfirmMessage`,{filename:B.name}),confirmText:n(`backup.restoreConfirmButton`),variant:`danger`,onConfirm:async()=>{z(!1),F(!0),te(null);try{L(n(`backup.uploadingFile`));let e=await Z.importBackup(B);te(e),e.success?t(n(`backup.backupRestoredRestart`),`success`):t(e.message,`error`)}catch(e){let r=e instanceof Error?e.message:n(`backup.failedToRestore`);te({success:!1,message:r}),t(r,`error`)}finally{F(!1),L(``),V(null)}},onCancel:()=>{z(!1),V(null)}}),(M||P)&&(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/80 flex items-center justify-center z-[100]`,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl p-8 max-w-md w-full mx-4 text-center`,children:[(0,G.jsx)(`div`,{className:`flex justify-center mb-4`,children:(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(`div`,{className:`w-16 h-16 border-4 border-bambu-dark-tertiary rounded-full`}),(0,G.jsx)(`div`,{className:`w-16 h-16 border-4 border-bambu-green border-t-transparent rounded-full absolute inset-0 animate-spin`})]})}),(0,G.jsx)(`h3`,{className:`text-xl font-semibold text-white mb-2`,children:n(M?`backup.creatingBackup`:`backup.restoringBackup`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray mb-4`,children:I||n(M?`backup.preparing`:`backup.processing`)}),(0,G.jsx)(`div`,{className:`p-3 rounded-lg bg-yellow-50 dark:bg-yellow-500/10 border border-yellow-300 dark:border-yellow-500/30`,children:(0,G.jsxs)(`div`,{className:`flex items-start gap-2 text-sm`,children:[(0,G.jsx)(Pu,{className:`w-4 h-4 text-yellow-600 dark:text-yellow-400 mt-0.5 flex-shrink-0`}),(0,G.jsx)(`p`,{className:`text-yellow-800 dark:text-yellow-200 text-left`,children:n(`backup.doNotClosePage`)})]})})]})})]})}function AHe(){let{t:e}=U(),t=so(),{showToast:n}=Bd(),[r,i]=(0,y.useState)(!1),[a,o]=(0,y.useState)(``),[s,c]=(0,y.useState)(``),[l,u]=(0,y.useState)(`medium`),[d,f]=(0,y.useState)(`notify`),[p,m]=(0,y.useState)(10),[h,g]=(0,y.useState)(null),[_,v]=(0,y.useState)(null),[b,x]=(0,y.useState)(!1),{data:S}=K({queryKey:[`settings`],queryFn:Z.getSettings}),{data:C,refetch:w}=K({queryKey:[`obico-status`],queryFn:Z.getObicoStatus,refetchInterval:1e4}),{data:T}=K({queryKey:[`printers`],queryFn:Z.getPrinters});(0,y.useEffect)(()=>{if(S){i(S.obico_enabled??!1),o(S.obico_ml_url??``),c(S.obico_ml_token??``),u(S.obico_sensitivity??`medium`),f(S.obico_action??`notify`),m(S.obico_poll_interval??10);try{let e=S.obico_enabled_printers?JSON.parse(S.obico_enabled_printers):null;g(Array.isArray(e)?e:null)}catch{g(null)}x(!0)}},[S]);let E=q({mutationFn:()=>Z.updateSettings({obico_enabled:r,obico_ml_url:a,obico_ml_token:s,obico_sensitivity:l,obico_action:d,obico_poll_interval:p,obico_enabled_printers:h===null?``:JSON.stringify(h)}),onSuccess:()=>{t.invalidateQueries({queryKey:[`settings`]}),t.invalidateQueries({queryKey:[`obico-status`]}),t.invalidateQueries({queryKey:[`obico-printer-status`]}),n(e(`settings.toast.settingsSaved`))}});(0,y.useEffect)(()=>{if(!b||!S||!(S.obico_enabled!==r||S.obico_ml_url!==a||(S.obico_ml_token??``)!==s||S.obico_sensitivity!==l||S.obico_action!==d||S.obico_poll_interval!==p||S.obico_enabled_printers!==(h===null?``:JSON.stringify(h))))return;let e=setTimeout(()=>E.mutate(),500);return()=>clearTimeout(e)},[r,a,s,l,d,p,h,b]);let D=async()=>{v(null);try{let t=await Z.testObicoConnection(a,s);t.ok?v({ok:!0,message:t.auth_ok===null?e(`failureDetection.testSuccessTokenUnknown`):e(`failureDetection.testSuccess`)}):v({ok:!1,message:t.error||`HTTP ${t.status_code??`?`} — ${t.body??e(`failureDetection.testFailed`)}`})}catch(e){v({ok:!1,message:e instanceof Error?e.message:String(e)})}},O=(e,t)=>{if(h===null){let n=T?.map(e=>e.id)??[];g(t?n:n.filter(t=>t!==e));return}g(t?[...h,e]:h.filter(t=>t!==e))};return(0,G.jsxs)(`div`,{className:`flex flex-col lg:flex-row gap-4 lg:gap-6`,children:[(0,G.jsxs)(`div`,{className:`space-y-3 flex-1 lg:max-w-xl`,children:[(0,G.jsxs)(Md,{id:`card-fd-ml`,children:[(0,G.jsxs)(Nd,{children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Kl,{className:`w-5 h-5 text-bambu-green`}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`failureDetection.title`)})]}),(0,G.jsx)(UH,{checked:r,onChange:i})]}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-2`,children:e(`failureDetection.description`)})]}),(0,G.jsxs)(Pd,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:e(`failureDetection.mlUrl`)}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsx)(`input`,{type:`text`,value:a,onChange:e=>o(e.target.value),placeholder:`http://192.168.1.10:3333`,className:`flex-1 bg-gray-800 border border-gray-700 rounded px-3 py-2 text-white text-sm`,disabled:!r}),(0,G.jsx)(Q,{onClick:D,disabled:!a||E.isPending,variant:`secondary`,children:e(`failureDetection.test`)})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`failureDetection.mlUrlHint`)}),(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1 mt-3`,children:e(`failureDetection.mlToken`)}),(0,G.jsx)(`input`,{type:`password`,value:s,onChange:e=>c(e.target.value),autoComplete:`off`,placeholder:e(`failureDetection.mlTokenPlaceholder`),className:`w-full bg-gray-800 border border-gray-700 rounded px-3 py-2 text-white text-sm`,disabled:!r}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`failureDetection.mlTokenHint`)}),_&&(0,G.jsxs)(`div`,{className:`flex items-start gap-2 mt-2 text-sm ${_.ok?`text-green-700 dark:text-green-400`:`text-red-700 dark:text-red-400`}`,children:[_.ok?(0,G.jsx)(us,{className:`w-4 h-4 mt-0.5`}):(0,G.jsx)($u,{className:`w-4 h-4 mt-0.5`}),(0,G.jsx)(`span`,{children:_.message})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:e(`failureDetection.sensitivity`)}),(0,G.jsxs)(`select`,{value:l,onChange:e=>u(e.target.value),disabled:!r,className:`w-full bg-gray-800 border border-gray-700 rounded px-3 py-2 text-white text-sm`,children:[(0,G.jsx)(`option`,{value:`low`,children:e(`failureDetection.sensitivityLow`)}),(0,G.jsx)(`option`,{value:`medium`,children:e(`failureDetection.sensitivityMedium`)}),(0,G.jsx)(`option`,{value:`high`,children:e(`failureDetection.sensitivityHigh`)})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`failureDetection.sensitivityHint`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:e(`failureDetection.action`)}),(0,G.jsxs)(`select`,{value:d,onChange:e=>f(e.target.value),disabled:!r,className:`w-full bg-gray-800 border border-gray-700 rounded px-3 py-2 text-white text-sm`,children:[(0,G.jsx)(`option`,{value:`notify`,children:e(`failureDetection.actionNotify`)}),(0,G.jsx)(`option`,{value:`pause`,children:e(`failureDetection.actionPause`)}),(0,G.jsx)(`option`,{value:`pause_and_off`,children:e(`failureDetection.actionPauseOff`)})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:e(`failureDetection.pollInterval`)}),(0,G.jsx)(`input`,{type:`number`,value:p,onChange:e=>m(Math.max(5,Math.min(120,Number(e.target.value)||10))),min:5,max:120,disabled:!r,className:`w-full bg-gray-800 border border-gray-700 rounded px-3 py-2 text-white text-sm`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`failureDetection.pollIntervalHint`)})]}),C&&!C.external_url_configured&&r&&(0,G.jsxs)(`div`,{className:`flex items-start gap-2 p-3 bg-amber-50 dark:bg-amber-900/30 border border-amber-300 dark:border-amber-700 rounded text-sm text-amber-800 dark:text-amber-200`,children:[(0,G.jsx)(Pu,{className:`w-4 h-4 mt-0.5 flex-shrink-0`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`div`,{className:`font-medium`,children:e(`failureDetection.externalUrlMissing`)}),(0,G.jsx)(`div`,{className:`text-xs mt-1`,children:e(`failureDetection.externalUrlHint`)})]})]})]})]}),(0,G.jsxs)(Md,{id:`card-fd-perprinter`,children:[(0,G.jsxs)(Nd,{children:[(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`failureDetection.perPrinterTitle`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:e(`failureDetection.perPrinterHint`)})]}),(0,G.jsxs)(Pd,{className:`space-y-2`,children:[(0,G.jsxs)(`label`,{className:`flex items-center gap-2 text-sm`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:h===null,onChange:e=>g(e.target.checked?null:T?.map(e=>e.id)??[]),disabled:!r}),(0,G.jsx)(`span`,{className:`text-white`,children:e(`failureDetection.monitorAll`)})]}),h!==null&&T&&(0,G.jsx)(`div`,{className:`pl-5 space-y-1 border-l border-gray-700`,children:T.map(e=>(0,G.jsxs)(`label`,{className:`flex items-center gap-2 text-sm`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:h.includes(e.id),onChange:t=>O(e.id,t.target.checked),disabled:!r}),(0,G.jsx)(`span`,{className:`text-white`,children:e.name})]},e.id))})]})]})]}),(0,G.jsxs)(`div`,{className:`space-y-3 flex-1 lg:max-w-xl`,children:[(0,G.jsxs)(Md,{id:`card-fd-status`,children:[(0,G.jsx)(Nd,{children:(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`failureDetection.statusTitle`)})}),(0,G.jsx)(Pd,{children:C?(0,G.jsxs)(`div`,{className:`space-y-3 text-sm`,children:[(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:e(`failureDetection.serviceRunning`)}),(0,G.jsx)(`span`,{className:C.is_running?`text-green-700 dark:text-green-400`:`text-red-700 dark:text-red-400`,children:C.is_running?e(`common.yes`):e(`common.no`)})]}),(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:e(`failureDetection.thresholds`)}),(0,G.jsxs)(`span`,{className:`text-white font-mono`,children:[C.thresholds.low.toFixed(2),` / `,C.thresholds.high.toFixed(2)]})]}),C.last_error&&(0,G.jsxs)(`div`,{className:`flex items-start gap-2 text-red-700 dark:text-red-400`,children:[(0,G.jsx)($u,{className:`w-4 h-4 mt-0.5 flex-shrink-0`}),(0,G.jsx)(`span`,{className:`break-words`,children:C.last_error})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`div`,{className:`text-bambu-gray mb-1`,children:e(`failureDetection.activePrinters`)}),Object.keys(C.per_printer).length===0?(0,G.jsx)(`div`,{className:`text-bambu-gray italic text-xs`,children:e(`failureDetection.noActivePrints`)}):(0,G.jsx)(`div`,{className:`space-y-1`,children:Object.entries(C.per_printer).map(([e,t])=>{let n=T?.find(t=>String(t.id)===e),r=t.class===`failure`?`text-red-700 dark:text-red-400`:t.class===`warning`?`text-amber-700 dark:text-amber-400`:`text-green-700 dark:text-green-400`;return(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-white`,children:n?.name??`Printer ${e}`}),(0,G.jsxs)(`span`,{className:`font-mono ${r}`,children:[t.class,` (`,t.score.toFixed(3),`, `,t.frame_count,`f)`]})]},e)})})]})]}):(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray`,children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),(0,G.jsx)(`span`,{children:e(`common.loading`)})]})})]}),(0,G.jsxs)(Md,{id:`card-fd-history`,children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`failureDetection.historyTitle`)}),(0,G.jsx)(`button`,{onClick:()=>w(),className:`text-xs text-bambu-gray hover:text-white`,children:e(`common.refresh`)})]})}),(0,G.jsx)(Pd,{children:!C||C.history.length===0?(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray text-sm`,children:[(0,G.jsx)(Vc,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{children:e(`failureDetection.noHistory`)})]}):(0,G.jsx)(`div`,{className:`space-y-1 max-h-96 overflow-y-auto text-xs font-mono`,children:C.history.map((e,t)=>{let n=T?.find(t=>t.id===e.printer_id),r=e.class===`failure`?`text-red-700 dark:text-red-400`:e.class===`warning`?`text-amber-700 dark:text-amber-400`:`text-bambu-gray`;return(0,G.jsxs)(`div`,{className:`flex justify-between gap-2 py-1 border-b border-gray-800`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:new Date(e.timestamp).toLocaleTimeString()}),(0,G.jsx)(`span`,{className:`text-white truncate`,children:n?.name??`#${e.printer_id}`}),(0,G.jsxs)(`span`,{className:r,children:[e.class,` `,e.score.toFixed(3)]})]},t)})})})]})]})]})}var jHe={starttls:587,ssl:465,none:25},MHe={587:`starttls`,465:`ssl`,25:`none`};function NHe(){let{t:e}=U(),{showToast:t}=Bd(),n=so(),[r,i]=(0,y.useState)({smtp_host:``,smtp_port:587,smtp_username:``,smtp_password:``,smtp_security:`starttls`,smtp_auth_enabled:!0,smtp_from_email:``,smtp_from_name:`BamBuddy`}),[a,o]=(0,y.useState)(``),{data:s,isLoading:c}=K({queryKey:[`smtpSettings`],queryFn:()=>Z.getSMTPSettings()}),{authEnabled:l}=Ed(),{data:u}=K({queryKey:[`advancedAuthStatus`],queryFn:()=>Z.getAdvancedAuthStatus()});(0,y.useEffect)(()=>{s&&i({...s,smtp_password:``})},[s]);let d=e=>{i({...r,smtp_security:e,smtp_port:jHe[e]})},f=e=>{let t=MHe[e];i({...r,smtp_port:e,...t?{smtp_security:t}:{}})},p=e=>{i({...r,smtp_auth_enabled:e,...e?{}:{smtp_username:``,smtp_password:``}})},m=q({mutationFn:e=>Z.saveSMTPSettings(e),onSuccess:()=>{n.invalidateQueries({queryKey:[`smtpSettings`]}),n.invalidateQueries({queryKey:[`advancedAuthStatus`]}),t(e(`settings.email.success.settingsSaved`),`success`)},onError:e=>{t(e.message,`error`)}}),h=q({mutationFn:e=>Z.testSMTP(e),onSuccess:e=>{t(e.message,e.success?`success`:`error`)},onError:e=>{t(e.message,`error`)}}),g=q({mutationFn:e=>e?Z.enableAdvancedAuth():Z.disableAdvancedAuth(),onSuccess:e=>{n.invalidateQueries({queryKey:[`advancedAuthStatus`]}),t(e.message,`success`)},onError:e=>{t(e.message,`error`)}}),_=()=>{if(!r.smtp_host||!r.smtp_from_email){t(e(`settings.email.errors.requiredFields`),`error`);return}if(r.smtp_auth_enabled&&!r.smtp_username){t(e(`settings.email.errors.usernameRequired`),`error`);return}m.mutate(r)},v=()=>{if(!a){t(e(`settings.email.errors.enterTestEmail`),`error`);return}h.mutate({test_recipient:a})},b=()=>{if(!l){t(e(`settings.email.errors.enableAuthFirst`),`error`);return}if(!u?.advanced_auth_enabled&&!u?.smtp_configured){t(e(`settings.email.errors.configureSmtpFirst`),`error`);return}g.mutate(!u?.advanced_auth_enabled)};if(c)return(0,G.jsx)(`div`,{className:`flex items-center justify-center p-12`,children:(0,G.jsx)(Y,{className:`w-8 h-8 animate-spin text-bambu-green`})});let x=u?.advanced_auth_enabled??!1,S=`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,C=`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white/40 placeholder-bambu-gray/40 cursor-not-allowed`;return(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(Md,{id:`card-email-advanced-auth`,children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(rl,{className:`w-5 h-5 text-bambu-green`}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`settings.email.advancedAuth`)||`Advanced Authentication`})]}),(0,G.jsx)(Q,{onClick:b,disabled:g.isPending,variant:x?`danger`:`primary`,children:x?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)($c,{className:`w-4 h-4`}),e(`settings.email.disable`)||`Disable`]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(el,{className:`w-4 h-4`}),e(`settings.email.enable`)||`Enable`]})})]})}),(0,G.jsx)(Pd,{children:(0,G.jsx)(`div`,{className:`space-y-3`,children:x?(0,G.jsx)(`div`,{className:`bg-green-50 dark:bg-green-500/10 border border-green-300 dark:border-green-500/30 rounded-lg p-4`,children:(0,G.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,G.jsx)(ys,{className:`w-5 h-5 text-green-600 dark:text-green-400 mt-0.5 flex-shrink-0`}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`p`,{className:`text-white font-medium`,children:e(`settings.email.advancedAuthEnabled`)||`Advanced Authentication is enabled`}),(0,G.jsxs)(`ul`,{className:`text-sm text-green-700 dark:text-green-300 space-y-1 list-disc list-inside`,children:[(0,G.jsx)(`li`,{children:e(`settings.email.feature1`)||`Passwords are auto-generated and emailed to new users`}),(0,G.jsx)(`li`,{children:e(`settings.email.feature2`)||`Users can login with username or email`}),(0,G.jsx)(`li`,{children:e(`settings.email.feature3`)||`Forgot password feature is available`}),(0,G.jsx)(`li`,{children:e(`settings.email.feature4`)||`Admins can reset user passwords via email`})]})]})]})}):(0,G.jsx)(`div`,{className:`bg-yellow-50 dark:bg-yellow-500/10 border border-yellow-300 dark:border-yellow-500/30 rounded-lg p-4`,children:(0,G.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,G.jsx)(Pu,{className:`w-5 h-5 text-yellow-600 dark:text-yellow-400 mt-0.5 flex-shrink-0`}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`p`,{className:`text-white font-medium`,children:e(`settings.email.advancedAuthDisabled`)||`Advanced Authentication is disabled`}),(0,G.jsx)(`p`,{className:`text-sm text-yellow-700 dark:text-yellow-300`,children:e(`settings.email.advancedAuthDisabledDesc`)||`Enable advanced authentication to activate email-based features for user management.`})]})]})})})})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-3 gap-4`,children:[(0,G.jsx)(`div`,{className:`lg:col-span-2`,children:(0,G.jsxs)(Md,{id:`card-smtp-config`,children:[(0,G.jsx)(Nd,{children:(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`settings.email.smtpSettings`)||`SMTP Configuration`})}),(0,G.jsx)(Pd,{children:(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:e(`settings.email.authentication`)||`Authentication`}),(0,G.jsxs)(`select`,{value:r.smtp_auth_enabled?`true`:`false`,onChange:e=>p(e.target.value===`true`),className:S,children:[(0,G.jsx)(`option`,{value:`true`,children:e(`settings.email.authOptions.enabled`)}),(0,G.jsx)(`option`,{value:`false`,children:e(`settings.email.authOptions.disabled`)})]})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4 transition-opacity ${r.smtp_auth_enabled?``:`opacity-40 pointer-events-none`}`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:e(`settings.email.username`)||`Username`}),(0,G.jsx)(`input`,{type:`text`,value:r.smtp_username||``,onChange:e=>i({...r,smtp_username:e.target.value}),placeholder:`your.email@gmail.com`,disabled:!r.smtp_auth_enabled,className:r.smtp_auth_enabled?S:C})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:e(`settings.email.password`)||`Password`}),(0,G.jsx)(`input`,{type:`password`,value:r.smtp_password||``,onChange:e=>i({...r,smtp_password:e.target.value}),placeholder:s?`••••••••`:`App password`,disabled:!r.smtp_auth_enabled,className:r.smtp_auth_enabled?S:C})]})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:[e(`settings.email.smtpHost`)||`SMTP Server`,` *`]}),(0,G.jsx)(`input`,{type:`text`,value:r.smtp_host,onChange:e=>i({...r,smtp_host:e.target.value}),placeholder:`smtp.gmail.com`,className:S})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:e(`settings.email.smtpPort`)||`SMTP Port`}),(0,G.jsx)(`input`,{type:`number`,value:r.smtp_port,onChange:e=>f(parseInt(e.target.value)||587),placeholder:`587`,className:S})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:e(`settings.email.security`)||`Security`}),(0,G.jsxs)(`select`,{value:r.smtp_security,onChange:e=>d(e.target.value),className:S,children:[(0,G.jsx)(`option`,{value:`starttls`,children:e(`settings.email.securityOptions.starttls`)}),(0,G.jsx)(`option`,{value:`ssl`,children:e(`settings.email.securityOptions.ssl`)}),(0,G.jsx)(`option`,{value:`none`,children:e(`settings.email.securityOptions.none`)})]})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:[e(`settings.email.fromEmail`)||`From Email`,` *`]}),(0,G.jsx)(`input`,{type:`email`,value:r.smtp_from_email,onChange:e=>i({...r,smtp_from_email:e.target.value}),placeholder:`your@email.com`,className:S})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:e(`settings.email.fromName`)||`From Name`}),(0,G.jsx)(`input`,{type:`text`,value:r.smtp_from_name,onChange:e=>i({...r,smtp_from_name:e.target.value}),placeholder:`BamBuddy`,className:S})]})]}),(0,G.jsx)(`div`,{className:`flex gap-2`,children:(0,G.jsx)(Q,{onClick:_,disabled:m.isPending,className:`flex-1`,children:m.isPending?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),e(`settings.email.saving`)||`Saving...`]}):e(`settings.email.save`)||`Save Settings`})})]})})]})}),(0,G.jsx)(`div`,{children:(0,G.jsxs)(Md,{id:`card-email-test`,children:[(0,G.jsx)(Nd,{children:(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`settings.email.testConnection`)||`Test SMTP Connection`})}),(0,G.jsx)(Pd,{children:(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:e(`settings.email.testRecipient`)||`Test Recipient Email`}),(0,G.jsx)(`input`,{type:`email`,value:a,onChange:e=>o(e.target.value),placeholder:`test@example.com`,className:S})]}),(0,G.jsx)(Q,{onClick:v,disabled:h.isPending,variant:`secondary`,children:h.isPending?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),e(`settings.email.sending`)||`Sending...`]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Xl,{className:`w-4 h-4`}),e(`settings.email.sendTest`)||`Send Test Email`]})})]})})]})})]})]})}var PHe={starttls:`389`,ldaps:`636`};function FHe(){let{t:e}=U(),{showToast:t}=Bd(),n=so(),{authEnabled:r}=Ed(),[i,a]=(0,y.useState)({ldap_server_url:``,ldap_bind_dn:``,ldap_bind_password:``,ldap_search_base:``,ldap_user_filter:`(sAMAccountName={username})`,ldap_security:`starttls`,ldap_group_mapping:``,ldap_auto_provision:!1,ldap_default_group:``}),{data:o,isLoading:s}=K({queryKey:[`settings`],queryFn:()=>Z.getSettings()}),{data:c}=K({queryKey:[`ldapStatus`],queryFn:()=>Z.getLDAPStatus()}),{data:l=[]}=K({queryKey:[`groups`],queryFn:()=>Z.getGroups()});(0,y.useEffect)(()=>{o&&a({ldap_server_url:o.ldap_server_url||``,ldap_bind_dn:o.ldap_bind_dn||``,ldap_bind_password:``,ldap_search_base:o.ldap_search_base||``,ldap_user_filter:o.ldap_user_filter||`(sAMAccountName={username})`,ldap_security:o.ldap_security||`starttls`,ldap_group_mapping:o.ldap_group_mapping||``,ldap_auto_provision:o.ldap_auto_provision??!1,ldap_default_group:o.ldap_default_group||``})},[o]);let u=q({mutationFn:e=>Z.updateSettings(e),onSuccess:()=>{n.invalidateQueries({queryKey:[`settings`]}),n.invalidateQueries({queryKey:[`ldapStatus`]}),t(e(`settings.ldap.settingsSaved`)||`LDAP settings saved`,`success`)},onError:e=>{t(e.message,`error`)}}),d=q({mutationFn:e=>Z.updateSettings({ldap_enabled:e}),onSuccess:()=>{n.invalidateQueries({queryKey:[`settings`]}),n.invalidateQueries({queryKey:[`ldapStatus`]}),t(c?.ldap_enabled?e(`settings.ldap.disabled`)||`LDAP authentication disabled`:e(`settings.ldap.enabled`)||`LDAP authentication enabled`,`success`)},onError:e=>{t(e.message,`error`)}}),f=q({mutationFn:()=>Z.testLDAP(),onSuccess:e=>{t(e.message,e.success?`success`:`error`)},onError:e=>{t(e.message,`error`)}}),p=()=>{if(!i.ldap_server_url){t(e(`settings.ldap.errors.serverRequired`)||`LDAP server URL is required`,`error`);return}if(!i.ldap_search_base){t(e(`settings.ldap.errors.searchBaseRequired`)||`Search base DN is required`,`error`);return}let n={ldap_server_url:i.ldap_server_url,ldap_bind_dn:i.ldap_bind_dn,ldap_search_base:i.ldap_search_base,ldap_user_filter:i.ldap_user_filter,ldap_security:i.ldap_security,ldap_group_mapping:i.ldap_group_mapping,ldap_auto_provision:i.ldap_auto_provision,ldap_default_group:i.ldap_default_group};i.ldap_bind_password&&(n.ldap_bind_password=i.ldap_bind_password),u.mutate(n)},m=()=>{if(!r){t(e(`settings.ldap.errors.enableAuthFirst`)||`Enable authentication first`,`error`);return}if(!c?.ldap_enabled&&!c?.ldap_configured){t(e(`settings.ldap.errors.configureLdapFirst`)||`Save LDAP settings first`,`error`);return}d.mutate(!c?.ldap_enabled)};if(s)return(0,G.jsx)(`div`,{className:`flex items-center justify-center p-12`,children:(0,G.jsx)(Y,{className:`w-8 h-8 animate-spin text-bambu-green`})});let h=c?.ldap_enabled??!1,g=`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`;return(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(Md,{id:`card-ldap-toggle`,children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(iu,{className:`w-5 h-5 text-bambu-green`}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`settings.ldap.title`)||`LDAP Authentication`})]}),(0,G.jsx)(Q,{onClick:m,disabled:d.isPending,variant:h?`danger`:`primary`,children:h?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)($c,{className:`w-4 h-4`}),e(`common.disable`)||`Disable`]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(el,{className:`w-4 h-4`}),e(`common.enable`)||`Enable`]})})]})}),(0,G.jsx)(Pd,{children:h?(0,G.jsx)(`div`,{className:`bg-green-50 dark:bg-green-500/10 border border-green-300 dark:border-green-500/30 rounded-lg p-4`,children:(0,G.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,G.jsx)(ys,{className:`w-5 h-5 text-green-600 dark:text-green-400 mt-0.5 flex-shrink-0`}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`p`,{className:`text-white font-medium`,children:e(`settings.ldap.enabledDesc`)||`LDAP authentication is enabled`}),(0,G.jsxs)(`ul`,{className:`text-sm text-green-700 dark:text-green-300 space-y-1 list-disc list-inside`,children:[(0,G.jsx)(`li`,{children:e(`settings.ldap.feature1`)||`Users can login with LDAP credentials`}),(0,G.jsx)(`li`,{children:e(`settings.ldap.feature2`)||`Local admin account remains as fallback`}),(0,G.jsx)(`li`,{children:e(`settings.ldap.feature3`)||`LDAP groups are mapped to BamBuddy groups on login`})]})]})]})}):(0,G.jsx)(`div`,{className:`bg-yellow-50 dark:bg-yellow-500/10 border border-yellow-300 dark:border-yellow-500/30 rounded-lg p-4`,children:(0,G.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,G.jsx)(Pu,{className:`w-5 h-5 text-yellow-600 dark:text-yellow-400 mt-0.5 flex-shrink-0`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white font-medium`,children:e(`settings.ldap.disabledDesc`)||`LDAP authentication is disabled`}),(0,G.jsx)(`p`,{className:`text-sm text-yellow-700 dark:text-yellow-300 mt-1`,children:e(`settings.ldap.disabledHint`)||`Configure and save LDAP settings below, then enable.`})]})]})})})]}),(0,G.jsxs)(Md,{id:`card-ldap-server`,children:[(0,G.jsx)(Nd,{children:(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`settings.ldap.serverConfig`)||`LDAP Server Configuration`})}),(0,G.jsx)(Pd,{children:(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-3`,children:[(0,G.jsxs)(`div`,{className:`md:col-span-2`,children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:e(`settings.ldap.serverUrl`)||`Server URL`}),(0,G.jsx)(`input`,{type:`text`,className:g,placeholder:`ldaps://ldap.example.com:636`,value:i.ldap_server_url,onChange:e=>a({...i,ldap_server_url:e.target.value})}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`settings.ldap.serverUrlHint`)||`Use ldaps:// for SSL or ldap:// with StartTLS`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:e(`settings.ldap.security`)||`Security`}),(0,G.jsx)(`div`,{className:`flex gap-2`,children:[`starttls`,`ldaps`].map(e=>(0,G.jsx)(`button`,{onClick:()=>a({...i,ldap_security:e}),className:`flex-1 px-2 py-2 rounded-lg text-sm font-medium transition-colors ${i.ldap_security===e?`bg-bambu-green text-black`:`bg-bambu-dark-secondary text-bambu-gray hover:text-white border border-bambu-dark-tertiary`}`,children:e===`starttls`?`StartTLS`:`LDAPS`},e))}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`settings.ldap.securityHint`)||`Default port: ${PHe[i.ldap_security]}`})]})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:e(`settings.ldap.bindDn`)||`Bind DN (Service Account)`}),(0,G.jsx)(`input`,{type:`text`,className:g,placeholder:`cn=service-account,ou=service,dc=example,dc=com`,value:i.ldap_bind_dn,onChange:e=>a({...i,ldap_bind_dn:e.target.value})})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:e(`settings.ldap.bindPassword`)||`Bind Password`}),(0,G.jsx)(`input`,{type:`password`,className:g,placeholder:o?.ldap_bind_dn?`••••••••`:``,value:i.ldap_bind_password,onChange:e=>a({...i,ldap_bind_password:e.target.value})})]})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:e(`settings.ldap.searchBase`)||`Search Base DN`}),(0,G.jsx)(`input`,{type:`text`,className:g,placeholder:`ou=users,dc=example,dc=com`,value:i.ldap_search_base,onChange:e=>a({...i,ldap_search_base:e.target.value})})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:e(`settings.ldap.userFilter`)||`User Search Filter`}),(0,G.jsx)(`input`,{type:`text`,className:g,placeholder:`(sAMAccountName={username})`,value:i.ldap_user_filter,onChange:e=>a({...i,ldap_user_filter:e.target.value})})]})]}),(0,G.jsx)(Vp,{summary:(0,G.jsx)(`span`,{className:`text-sm font-medium text-bambu-gray`,children:e(`settings.ldap.advanced`)||`Advanced`}),className:`border-t border-bambu-dark-tertiary pt-3`,summaryClassName:`py-1`,children:(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white`,children:e(`settings.ldap.autoProvision`)||`Auto-provision users`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:e(`settings.ldap.autoProvisionHint`)||`Automatically create a BamBuddy account on first LDAP login`})]}),(0,G.jsx)(`button`,{onClick:()=>a({...i,ldap_auto_provision:!i.ldap_auto_provision}),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors flex-shrink-0 ${i.ldap_auto_provision?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,children:(0,G.jsx)(`span`,{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${i.ldap_auto_provision?`translate-x-6`:`translate-x-1`}`})})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:e(`settings.ldap.defaultGroup`)||`Default group`}),(0,G.jsxs)(`select`,{className:g,value:i.ldap_default_group,onChange:e=>a({...i,ldap_default_group:e.target.value}),children:[(0,G.jsx)(`option`,{value:``,children:e(`settings.ldap.defaultGroupNone`)||`— None (reject login) —`}),l.map(e=>(0,G.jsx)(`option`,{value:e.name,children:e.name},e.id))]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`settings.ldap.defaultGroupHint`)||`Fallback group assigned when an LDAP user authenticates but is not listed in any mapped group. Leave empty to leave unmapped users without permissions.`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:e(`settings.ldap.groupMapping`)||`Group Mapping (JSON)`}),(0,G.jsx)(`textarea`,{className:`${g} font-mono text-sm`,rows:4,placeholder:`{
"CN=PrintFarm_Admins,OU=Groups,DC=example,DC=com": "Administrators",
"CN=PrintFarm_Users,OU=Groups,DC=example,DC=com": "Operators"
}`,value:i.ldap_group_mapping,onChange:e=>a({...i,ldap_group_mapping:e.target.value})}),(0,G.jsxs)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:[e(`settings.ldap.groupMappingHint`)||`Map LDAP group DNs to BamBuddy groups. Available groups: `,l.map(e=>e.name).join(`, `)]})]})]})}),(0,G.jsxs)(`div`,{className:`flex gap-3 pt-2`,children:[(0,G.jsxs)(Q,{onClick:p,disabled:u.isPending,children:[u.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(ys,{className:`w-4 h-4`}),e(`common.save`)||`Save`]}),(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>f.mutate(),disabled:f.isPending,children:[f.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Xl,{className:`w-4 h-4`}),e(`settings.ldap.testConnection`)||`Test Connection`]})]})]})})]})]})}function A6({value:e,onChange:t,placeholder:n,maxLength:r=6}){return(0,G.jsx)(`input`,{type:`text`,value:e,onChange:e=>t(e.target.value.toUpperCase().replace(/\s/g,``)),maxLength:r,className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors font-mono tracking-widest text-center`,placeholder:n,autoComplete:`one-time-code`})}function j6({codes:e,onDone:t}){let{t:n}=U(),[r,i]=(0,y.useState)(!1);return(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsx)(`div`,{className:`bg-amber-50 dark:bg-amber-500/10 border border-amber-300 dark:border-amber-500/30 rounded-lg p-4`,children:(0,G.jsx)(`p`,{className:`text-amber-700 dark:text-amber-400 text-sm font-medium`,children:n(`settings.twoFa.backupCodesWarning`)})}),(0,G.jsx)(`div`,{className:`grid grid-cols-2 gap-2`,children:e.map((e,t)=>(0,G.jsx)(`code`,{className:`bg-bambu-dark-secondary rounded px-3 py-2 text-center font-mono text-sm text-white tracking-widest`,children:e},t))}),(0,G.jsxs)(`div`,{className:`flex gap-3`,children:[(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:()=>{navigator.clipboard.writeText(e.join(`
-`)),i(!0),setTimeout(()=>i(!1),2e3)},className:`flex items-center gap-2`,children:[(0,G.jsx)(zs,{className:`w-4 h-4`}),n(r?`common.copied`:`common.copy`)]}),(0,G.jsx)(Q,{variant:`primary`,size:`sm`,onClick:t,className:`flex-1`,children:n(`settings.twoFa.savedCodes`)})]})]})}function IHe({onDone:e}){let{t}=U(),n=so(),{showToast:r}=Bd(),[i,a]=(0,y.useState)(`qr`),[o,s]=(0,y.useState)(``),[c,l]=(0,y.useState)([]),[u,d]=(0,y.useState)(!1),{data:f,isLoading:p}=K({queryKey:[`totp-setup`],queryFn:()=>Z.setupTOTP(),staleTime:1/0}),m=q({mutationFn:e=>Z.enableTOTP(e),onSuccess:e=>{l(e.backup_codes),a(`backup`),n.invalidateQueries({queryKey:[`2fa-status`]})},onError:()=>r(t(`settings.twoFa.invalidCode`),`error`)});return p||!f?(0,G.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,G.jsx)(zl,{className:`w-6 h-6 animate-spin text-bambu-green`})}):i===`qr`?(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsx)(`p`,{className:`text-bambu-gray-light text-sm`,children:t(`settings.twoFa.setupInstructions`)}),(0,G.jsx)(`div`,{className:`flex justify-center`,children:(0,G.jsx)(`img`,{src:`data:image/png;base64,${f.qr_code_b64}`,alt:`TOTP QR Code`,className:`w-48 h-48 rounded-lg`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mb-1`,children:t(`settings.twoFa.manualEntry`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 bg-bambu-dark-secondary rounded-lg px-3 py-2`,children:[(0,G.jsx)(`code`,{className:`text-white text-xs font-mono flex-1 break-all`,children:u?f.secret:`••••••••••••••••`}),(0,G.jsx)(`button`,{onClick:()=>d(!u),className:`text-bambu-gray hover:text-white`,children:u?(0,G.jsx)(nc,{className:`w-4 h-4`}):(0,G.jsx)(rc,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:()=>{navigator.clipboard.writeText(f.secret)},className:`text-bambu-gray hover:text-white`,children:(0,G.jsx)(zs,{className:`w-4 h-4`})})]})]}),(0,G.jsx)(Q,{variant:`primary`,className:`w-full`,onClick:()=>a(`confirm`),children:t(`settings.twoFa.scannedContinue`)})]}):i===`confirm`?(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsx)(`p`,{className:`text-bambu-gray-light text-sm`,children:t(`settings.twoFa.enterCodeToConfirm`)}),(0,G.jsx)(A6,{value:o,onChange:s,placeholder:`000000`}),(0,G.jsxs)(`div`,{className:`flex gap-3`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>a(`qr`),className:`flex-1`,children:t(`common.back`)}),(0,G.jsx)(Q,{variant:`primary`,className:`flex-1`,disabled:o.length!==6||m.isPending,onClick:()=>m.mutate(o),children:m.isPending?t(`common.saving`):t(`settings.twoFa.activate`)})]})]}):(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsx)(`h3`,{className:`text-white font-medium`,children:t(`settings.twoFa.backupCodesTitle`)}),(0,G.jsx)(j6,{codes:c,onDone:e})]})}function LHe(){let{t:e}=U(),t=so(),{showToast:n}=Bd(),{user:r}=Ed(),[i,a]=(0,y.useState)(!1),[o,s]=(0,y.useState)(!1),[c,l]=(0,y.useState)(!1),[u,d]=(0,y.useState)(``),[f,p]=(0,y.useState)(``),[m,h]=(0,y.useState)(null),[g,_]=(0,y.useState)(null),[v,b]=(0,y.useState)(``),[x,S]=(0,y.useState)(!1),[C,w]=(0,y.useState)(``),[T,E]=(0,y.useState)(!1),{data:D,isLoading:O}=K({queryKey:[`2fa-status`],queryFn:()=>Z.get2FAStatus()}),{data:k}=K({queryKey:[`oidc-links`],queryFn:()=>Z.getOIDCLinks()}),A=q({mutationFn:()=>Z.enableEmailOTP(),onSuccess:e=>{_(e.setup_token),n(e.message,`success`)},onError:t=>{let r=t.message??``;r.toLowerCase().includes(`smtp`)?n(e(`settings.twoFa.smtpRequired`),`error`):n(r,`error`)}}),j=q({mutationFn:()=>Z.confirmEnableEmailOTP(g,v),onSuccess:()=>{t.invalidateQueries({queryKey:[`2fa-status`]}),_(null),b(``),n(e(`settings.twoFa.emailOtpEnabled`),`success`)},onError:e=>n(e.message,`error`)}),M=q({mutationFn:e=>Z.disableEmailOTP(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`2fa-status`]}),S(!1),w(``),n(e(`settings.twoFa.emailOtpDisabled`),`success`)},onError:e=>n(e.message,`error`)}),N=q({mutationFn:e=>Z.disableTOTP(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`2fa-status`]}),s(!1),d(``),n(e(`settings.twoFa.totpDisabled`),`success`)},onError:()=>n(e(`settings.twoFa.invalidCode`),`error`)}),P=q({mutationFn:e=>Z.regenerateBackupCodes(e),onSuccess:e=>{t.invalidateQueries({queryKey:[`2fa-status`]}),l(!1),p(``),h(e.backup_codes)},onError:()=>n(e(`settings.twoFa.invalidCode`),`error`)}),F=q({mutationFn:e=>Z.deleteOIDCLink(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`oidc-links`]}),n(e(`settings.twoFa.oidcUnlinked`),`success`)},onError:e=>n(e.message,`error`)});if(O)return(0,G.jsx)(`div`,{className:`flex items-center justify-center py-12`,children:(0,G.jsx)(zl,{className:`w-6 h-6 animate-spin text-bambu-green`})});let I=!!r?.email;return(0,G.jsxs)(`div`,{className:`space-y-6`,children:[(0,G.jsxs)(Md,{id:`card-2fa-totp`,children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`w-10 h-10 rounded-full flex items-center justify-center ${D?.totp_enabled?`bg-green-100 dark:bg-green-500/20`:`bg-gray-500/20`}`,children:(0,G.jsx)(du,{className:`w-5 h-5 ${D?.totp_enabled?`text-green-600 dark:text-green-400`:`text-gray-400`}`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`text-white font-semibold`,children:e(`settings.twoFa.totpTitle`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-sm`,children:e(`settings.twoFa.totpDesc`)})]}),(0,G.jsx)(`div`,{className:`ml-auto`,children:D?.totp_enabled?(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-green-700 dark:text-green-400 text-sm font-medium`,children:[(0,G.jsx)(nu,{className:`w-4 h-4`}),` `,e(`common.enabled`)]}):(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-bambu-gray text-sm`,children:[(0,G.jsx)(ru,{className:`w-4 h-4`}),` `,e(`common.disabled`)]})})]})}),(0,G.jsx)(Pd,{children:i?(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,G.jsx)(`h4`,{className:`text-white font-medium`,children:e(`settings.twoFa.setupAuthApp`)}),(0,G.jsx)(`button`,{onClick:()=>{a(!1),t.removeQueries({queryKey:[`totp-setup`]})},className:`text-bambu-gray hover:text-white`,children:(0,G.jsx)($u,{className:`w-5 h-5`})})]}),(0,G.jsx)(IHe,{onDone:()=>{a(!1),t.removeQueries({queryKey:[`totp-setup`]})}})]}):o?(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsx)(`p`,{className:`text-bambu-gray-light text-sm`,children:e(`settings.twoFa.disableConfirmHint`)}),(0,G.jsx)(A6,{value:u,onChange:d,placeholder:`000000 or XXXXXXXX`,maxLength:8}),(0,G.jsxs)(`div`,{className:`flex gap-3`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>{s(!1),d(``)},className:`flex-1`,children:e(`common.cancel`)}),(0,G.jsx)(Q,{variant:`danger`,className:`flex-1`,disabled:u.length<6||N.isPending,onClick:()=>N.mutate(u),children:N.isPending?e(`common.saving`):e(`settings.twoFa.disableTotp`)})]})]}):c?(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsx)(`p`,{className:`text-bambu-gray-light text-sm`,children:e(`settings.twoFa.regenBackupHint`)}),(0,G.jsx)(A6,{value:f,onChange:p,placeholder:`000000 or XXXXXXXX`,maxLength:8}),(0,G.jsxs)(`div`,{className:`flex gap-3`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>{l(!1),p(``)},className:`flex-1`,children:e(`common.cancel`)}),(0,G.jsx)(Q,{variant:`primary`,className:`flex-1`,disabled:f.length<6||P.isPending,onClick:()=>P.mutate(f),children:P.isPending?e(`common.saving`):e(`settings.twoFa.regenBackup`)})]})]}):m?(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsx)(`h4`,{className:`text-white font-medium`,children:e(`settings.twoFa.newBackupCodes`)}),(0,G.jsx)(j6,{codes:m,onDone:()=>h(null)})]}):(0,G.jsx)(`div`,{className:`space-y-3`,children:D?.totp_enabled?(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-bambu-gray-light`,children:[(0,G.jsx)(Uc,{className:`w-4 h-4`}),e(`settings.twoFa.backupCodesRemaining`,{count:D.backup_codes_remaining})]}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:()=>l(!0),className:`flex items-center gap-2`,children:[(0,G.jsx)(zl,{className:`w-4 h-4`}),e(`settings.twoFa.regenBackup`)]}),(0,G.jsxs)(Q,{variant:`danger`,size:`sm`,onClick:()=>s(!0),className:`flex items-center gap-2`,children:[(0,G.jsx)(ju,{className:`w-4 h-4`}),e(`settings.twoFa.disableTotp`)]})]}):(0,G.jsxs)(Q,{variant:`primary`,onClick:()=>a(!0),className:`flex items-center gap-2`,children:[(0,G.jsx)(du,{className:`w-4 h-4`}),e(`settings.twoFa.setupTotp`)]})})})]}),(0,G.jsxs)(Md,{id:`card-2fa-emailotp`,children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`w-10 h-10 rounded-full flex items-center justify-center ${D?.email_otp_enabled?`bg-green-100 dark:bg-green-500/20`:`bg-gray-500/20`}`,children:(0,G.jsx)(rl,{className:`w-5 h-5 ${D?.email_otp_enabled?`text-green-600 dark:text-green-400`:`text-gray-400`}`})}),(0,G.jsxs)(`div`,{className:`flex-1`,children:[(0,G.jsx)(`h3`,{className:`text-white font-semibold`,children:e(`settings.twoFa.emailOtpTitle`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-sm`,children:I?e(`settings.twoFa.emailOtpDesc`,{email:r?.email}):e(`settings.twoFa.emailOtpNoEmail`)})]}),(0,G.jsx)(`div`,{className:`ml-auto`,children:D?.email_otp_enabled?(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-green-700 dark:text-green-400 text-sm font-medium`,children:[(0,G.jsx)(nu,{className:`w-4 h-4`}),` `,e(`common.enabled`)]}):(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-bambu-gray text-sm`,children:[(0,G.jsx)(ru,{className:`w-4 h-4`}),` `,e(`common.disabled`)]})})]})}),(0,G.jsx)(Pd,{children:I?g?(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsx)(`p`,{className:`text-bambu-gray-light text-sm`,children:e(`settings.twoFa.emailSetupEnterCode`)}),(0,G.jsx)(A6,{value:v,onChange:b,placeholder:`000000`}),(0,G.jsxs)(`div`,{className:`flex gap-3`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>{_(null),b(``)},className:`flex-1`,children:e(`common.cancel`)}),(0,G.jsx)(Q,{variant:`primary`,className:`flex-1`,disabled:v.length!==6||j.isPending,onClick:()=>j.mutate(),children:j.isPending?e(`common.saving`):e(`settings.twoFa.verifyAndEnable`)})]})]}):x?(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsx)(`p`,{className:`text-bambu-gray-light text-sm`,children:e(`settings.twoFa.emailDisablePasswordHint`)}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(`input`,{type:T?`text`:`password`,value:C,onChange:e=>w(e.target.value),placeholder:e(`settings.twoFa.passwordPlaceholder`),className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>E(!T),className:`absolute right-3 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white`,children:T?(0,G.jsx)(nc,{className:`w-5 h-5`}):(0,G.jsx)(rc,{className:`w-5 h-5`})})]}),(0,G.jsxs)(`div`,{className:`flex gap-3`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>{S(!1),w(``)},className:`flex-1`,children:e(`common.cancel`)}),(0,G.jsx)(Q,{variant:`danger`,className:`flex-1`,disabled:!C||M.isPending,onClick:()=>M.mutate(C),children:M.isPending?e(`common.saving`):e(`settings.twoFa.disableEmailOtp`)})]})]}):(0,G.jsx)(`div`,{className:`flex gap-3`,children:D?.email_otp_enabled?(0,G.jsxs)(Q,{variant:`danger`,size:`sm`,onClick:()=>S(!0),className:`flex items-center gap-2`,children:[(0,G.jsx)(ju,{className:`w-4 h-4`}),e(`settings.twoFa.disableEmailOtp`)]}):(0,G.jsxs)(Q,{variant:`primary`,disabled:!I||A.isPending,onClick:()=>A.mutate(),className:`flex items-center gap-2`,children:[(0,G.jsx)(rl,{className:`w-4 h-4`}),A.isPending?e(`common.saving`):e(`settings.twoFa.enableEmailOtp`)]})}):(0,G.jsx)(`p`,{className:`text-amber-700 dark:text-amber-400 text-sm`,children:e(`settings.twoFa.addEmailFirst`)})})]}),k&&k.length>0&&(0,G.jsxs)(Md,{id:`card-2fa-linked`,children:[(0,G.jsxs)(Nd,{children:[(0,G.jsx)(`h3`,{className:`text-white font-semibold`,children:e(`settings.twoFa.linkedAccounts`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-sm`,children:e(`settings.twoFa.linkedAccountsDesc`)})]}),(0,G.jsx)(Pd,{children:(0,G.jsx)(`div`,{className:`space-y-3`,children:k.map(e=>(0,G.jsxs)(`div`,{className:`flex items-center justify-between py-2 border-b border-bambu-dark-tertiary last:border-0`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white text-sm font-medium`,children:e.provider_name}),e.provider_email&&(0,G.jsx)(`p`,{className:`text-bambu-gray text-xs`,children:e.provider_email})]}),(0,G.jsx)(Q,{variant:`danger`,size:`sm`,onClick:()=>F.mutate(e.provider_id),disabled:F.isPending,children:(0,G.jsx)(ju,{className:`w-4 h-4`})})]},e.id))})})]})]})}var RHe={name:``,issuer_url:``,client_id:``,client_secret:``,scopes:`openid email profile`,is_enabled:!0,auto_create_users:!1,auto_link_existing_accounts:!1,email_claim:`email`,require_email_verified:!0,icon_url:void 0,default_group_id:null,is_autologin:!1};function M6({initial:e,isEdit:t=!1,groups:n=[],onSave:r,onCancel:i,isPending:a}){let{t:o}=U(),[s,c]=(0,y.useState)(e),[l,u]=(0,y.useState)(!1),d=(e,t)=>c(n=>({...n,[e]:t})),f=`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors text-sm`,p=`block text-sm font-medium text-white mb-1`,m=()=>{let e={...s};t&&!l&&delete e.client_secret,r(e)},h=s.auto_link_existing_accounts===!0,g=s.require_email_verified??!0,_;return _=h?o(`settings.oidc.form.requireEmailVerifiedAutoLink`):g?o(`settings.oidc.form.requireEmailVerifiedDesc`):(0,G.jsx)(`span`,{className:`text-red-700 dark:text-red-400`,children:o(`settings.oidc.form.requireEmailVerifiedWarning`)}),(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:p,children:[o(`settings.oidc.form.name`),` `,(0,G.jsx)(`span`,{className:`text-red-700 dark:text-red-400`,children:`*`})]}),(0,G.jsx)(`input`,{className:f,value:s.name,onChange:e=>d(`name`,e.target.value),placeholder:`Google`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:p,children:[o(`settings.oidc.form.issuerUrl`),` `,(0,G.jsx)(`span`,{className:`text-red-700 dark:text-red-400`,children:`*`})]}),(0,G.jsx)(`input`,{className:f,value:s.issuer_url,onChange:e=>d(`issuer_url`,e.target.value),placeholder:`https://accounts.google.com`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:p,children:[o(`settings.oidc.form.clientId`),` `,(0,G.jsx)(`span`,{className:`text-red-700 dark:text-red-400`,children:`*`})]}),(0,G.jsx)(`input`,{className:f,value:s.client_id,onChange:e=>d(`client_id`,e.target.value),placeholder:`your-client-id`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:p,children:[o(`settings.oidc.form.clientSecret`),!t&&(0,G.jsx)(`span`,{className:`text-red-700 dark:text-red-400`,children:` *`}),t&&(0,G.jsxs)(`span`,{className:`text-bambu-gray text-xs ml-1`,children:[`(`,o(`settings.oidc.form.secretHint`),`)`]})]}),(0,G.jsx)(`input`,{className:f,type:`password`,value:l?s.client_secret:``,placeholder:t&&!l?`••••••••`:o(`settings.oidc.form.secretPlaceholder`),onChange:e=>{u(!0),d(`client_secret`,e.target.value)}})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:p,children:o(`settings.oidc.form.scopes`)}),(0,G.jsx)(`input`,{className:f,value:s.scopes,onChange:e=>d(`scopes`,e.target.value),placeholder:`openid email profile`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:p,children:o(`settings.oidc.form.iconUrl`)}),(0,G.jsx)(`input`,{className:f,value:s.icon_url??``,onChange:e=>d(`icon_url`,e.target.value===``?null:e.target.value),placeholder:`https://...`})]})]}),(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-6 pt-2`,children:[(0,G.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,G.jsx)(UH,{checked:s.is_enabled??!0,onChange:e=>d(`is_enabled`,e)}),(0,G.jsx)(`span`,{className:`text-white text-sm`,children:o(`settings.oidc.form.enabled`)})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,G.jsx)(UH,{checked:s.auto_create_users??!1,onChange:e=>d(`auto_create_users`,e)}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white text-sm`,children:o(`settings.oidc.form.autoCreate`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-xs`,children:o(`settings.oidc.form.autoCreateDesc`)})]})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer w-full`,children:[(0,G.jsx)(UH,{checked:s.auto_link_existing_accounts??!1,onChange:e=>d(`auto_link_existing_accounts`,e)}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white text-sm`,children:o(`settings.oidc.form.autoLink`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-xs`,children:o(`settings.oidc.form.autoLinkDesc`)})]})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer w-full`,children:[(0,G.jsx)(UH,{checked:g,onChange:e=>d(`require_email_verified`,e),disabled:h}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white text-sm`,children:o(`settings.oidc.form.requireEmailVerified`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-xs`,children:_})]})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer w-full`,children:[(0,G.jsx)(UH,{checked:s.is_autologin??!1,onChange:e=>d(`is_autologin`,e)}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white text-sm`,children:o(`settings.oidc.form.autologin`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-xs`,children:o(`settings.oidc.form.autologinDesc`)})]})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:p,children:o(`settings.oidc.form.emailClaim`)}),(0,G.jsx)(`input`,{className:f,value:s.email_claim,onChange:e=>d(`email_claim`,e.target.value||`email`),placeholder:o(`settings.oidc.form.emailClaimPlaceholder`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-xs mt-1`,children:o(`settings.oidc.form.emailClaimDesc`)}),h&&s.email_claim!==`email`&&(0,G.jsx)(`p`,{className:`text-yellow-700 dark:text-yellow-400 text-xs mt-1`,children:o(`settings.oidc.form.emailClaimCustomClaimAutoLinkWarning`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:p,children:o(`settings.oidc.form.defaultGroup`)}),(0,G.jsxs)(`select`,{className:f,value:s.default_group_id??``,onChange:e=>d(`default_group_id`,e.target.value?Number(e.target.value):null),children:[(0,G.jsx)(`option`,{value:``,children:o(`settings.oidc.form.defaultGroupViewersFallback`)}),n.map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-xs mt-1`,children:o(`settings.oidc.form.defaultGroupDesc`)})]}),(0,G.jsxs)(`div`,{className:`flex gap-3 pt-2`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:i,className:`flex-1`,children:o(`common.cancel`)}),(0,G.jsx)(Q,{variant:`primary`,className:`flex-1`,disabled:!s.name||!s.issuer_url||!s.client_id||!t&&!s.client_secret||t&&l&&!s.client_secret||a,onClick:m,children:o(a?`common.saving`:`common.save`)})]})]})}function zHe({provider:e}){let[t,n]=(0,y.useState)(!1);return e.has_icon&&!t?(0,G.jsx)(`img`,{src:Z.oidcProviderIconUrl(e.id),alt:e.name,className:`w-8 h-8 rounded object-contain`,onError:()=>n(!0)}):(0,G.jsx)(`div`,{className:`w-8 h-8 rounded-full bg-bambu-dark-tertiary flex items-center justify-center`,children:(0,G.jsx)(Dc,{className:`w-4 h-4 text-bambu-gray`})})}function BHe(){let{t:e}=U(),t=so(),{showToast:n}=Bd(),[r,i]=(0,y.useState)(!1),[a,o]=(0,y.useState)(null),[s,c]=(0,y.useState)(null),{data:l,isLoading:u}=K({queryKey:[`oidc-providers-all`],queryFn:()=>Z.getOIDCProvidersAll()}),{data:d=[]}=K({queryKey:[`groups`],queryFn:()=>Z.getGroups()}),f=q({mutationFn:e=>Z.createOIDCProvider(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`oidc-providers-all`]}),i(!1),n(e(`settings.oidc.created`),`success`)},onError:e=>n(e.message,`error`)}),p=q({mutationFn:({id:e,data:t})=>Z.updateOIDCProvider(e,t),onSuccess:()=>{t.invalidateQueries({queryKey:[`oidc-providers-all`]}),o(null),n(e(`settings.oidc.updated`),`success`)},onError:e=>n(e.message,`error`)}),m=q({mutationFn:e=>Z.deleteOIDCProvider(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`oidc-providers-all`]}),c(null),n(e(`settings.oidc.deleted`),`success`)},onError:e=>n(e.message,`error`)}),h=q({mutationFn:e=>Z.refreshOIDCProviderIcon(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`oidc-providers-all`]}),t.invalidateQueries({queryKey:[`oidc-providers`]}),n(e(`settings.oidc.iconRefreshed`),`success`)},onError:t=>n(t.message||e(`settings.oidc.iconFetchFailed`),`error`)}),g=q({mutationFn:e=>Z.deleteOIDCProviderIcon(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`oidc-providers-all`]}),t.invalidateQueries({queryKey:[`oidc-providers`]}),n(e(`settings.oidc.iconRemoved`),`success`)},onError:e=>n(e.message,`error`)}),_=e=>p.mutate({id:e.id,data:{is_enabled:!e.is_enabled}});return u?(0,G.jsx)(`div`,{className:`flex items-center justify-center py-12`,children:(0,G.jsx)(zl,{className:`w-6 h-6 animate-spin text-bambu-green`})}):(0,G.jsxs)(`div`,{className:`space-y-6`,children:[(0,G.jsxs)(Md,{id:`card-oidc`,children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`text-white font-semibold`,children:e(`settings.oidc.title`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-sm`,children:e(`settings.oidc.desc`)})]}),!r&&(0,G.jsxs)(Q,{variant:`primary`,size:`sm`,onClick:()=>i(!0),className:`flex items-center gap-2`,children:[(0,G.jsx)(Ml,{className:`w-4 h-4`}),e(`settings.oidc.addProvider`)]})]})}),r&&(0,G.jsx)(Pd,{children:(0,G.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary pt-4`,children:[(0,G.jsx)(`h4`,{className:`text-white font-medium mb-4`,children:e(`settings.oidc.newProvider`)}),(0,G.jsx)(M6,{initial:RHe,groups:d,onSave:e=>f.mutate(e),onCancel:()=>i(!1),isPending:f.isPending})]})})]}),l&&l.length===0&&!r&&(0,G.jsx)(Md,{id:`card-oidc-empty`,children:(0,G.jsx)(Pd,{children:(0,G.jsxs)(`div`,{className:`text-center py-8 space-y-3`,children:[(0,G.jsx)(Dc,{className:`w-12 h-12 text-bambu-gray mx-auto`}),(0,G.jsx)(`p`,{className:`text-bambu-gray`,children:e(`settings.oidc.empty`)}),(0,G.jsxs)(Q,{variant:`primary`,size:`sm`,onClick:()=>i(!0),className:`inline-flex items-center gap-2`,children:[(0,G.jsx)(Ml,{className:`w-4 h-4`}),e(`settings.oidc.addProvider`)]})]})})}),l?.map(t=>(0,G.jsxs)(Md,{children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(zHe,{provider:t}),(0,G.jsxs)(`div`,{className:`flex-1`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`h4`,{className:`text-white font-medium`,children:t.name}),t.is_enabled?(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-xs text-green-700 dark:text-green-400 bg-green-50 dark:bg-green-400/10 px-2 py-0.5 rounded-full`,children:[(0,G.jsx)(us,{className:`w-3 h-3`}),` `,e(`common.enabled`)]}):(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-xs text-bambu-gray bg-bambu-dark-tertiary px-2 py-0.5 rounded-full`,children:[(0,G.jsx)($u,{className:`w-3 h-3`}),` `,e(`common.disabled`)]}),t.is_env_managed&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-xs text-bambu-green`,children:[(0,G.jsx)(el,{className:`w-3 h-3`}),` `,e(`settings.environmentManagedLabel`)]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1 text-bambu-gray text-xs mt-0.5`,children:[(0,G.jsx)(tc,{className:`w-3 h-3`}),(0,G.jsx)(`span`,{children:t.issuer_url})]})]}),(0,G.jsx)(`div`,{className:`flex items-center gap-2`,children:!t.is_env_managed&&(0,G.jsxs)(G.Fragment,{children:[t.icon_url&&(0,G.jsx)(Q,{variant:`secondary`,size:`sm`,onClick:()=>h.mutate(t.id),disabled:h.isPending,title:e(`settings.oidc.refreshIcon`),"data-testid":`refresh-icon-${t.id}`,children:(0,G.jsx)(zl,{className:`w-4 h-4 ${h.isPending?`animate-spin`:``}`})}),t.has_icon&&(0,G.jsx)(Q,{variant:`secondary`,size:`sm`,onClick:()=>g.mutate(t.id),disabled:g.isPending,title:e(`settings.oidc.removeIcon`),"data-testid":`remove-icon-${t.id}`,children:(0,G.jsx)(Rc,{className:`w-4 h-4`})}),(0,G.jsx)(UH,{checked:t.is_enabled,onChange:()=>_(t),disabled:p.isPending}),(0,G.jsx)(Q,{variant:`secondary`,size:`sm`,onClick:()=>o(a===t.id?null:t.id),"data-testid":`edit-provider-${t.id}`,children:(0,G.jsx)(Dl,{className:`w-4 h-4`})}),(0,G.jsx)(Q,{variant:`danger`,size:`sm`,onClick:()=>c(t),"data-testid":`delete-provider-${t.id}`,children:(0,G.jsx)(ju,{className:`w-4 h-4`})})]})})]})}),a===t.id&&(0,G.jsx)(Pd,{children:(0,G.jsx)(`div`,{className:`border-t border-bambu-dark-tertiary pt-4`,children:(0,G.jsx)(M6,{isEdit:!0,groups:d,initial:{name:t.name,issuer_url:t.issuer_url,client_id:t.client_id,client_secret:``,scopes:t.scopes,is_enabled:t.is_enabled,auto_create_users:t.auto_create_users,auto_link_existing_accounts:t.auto_link_existing_accounts,email_claim:t.email_claim,require_email_verified:t.require_email_verified,icon_url:t.icon_url??void 0,default_group_id:t.default_group_id??null,is_autologin:t.is_autologin},onSave:e=>p.mutate({id:t.id,data:e}),onCancel:()=>o(null),isPending:p.isPending})})}),a!==t.id&&(0,G.jsx)(Pd,{children:(0,G.jsxs)(`dl`,{className:`grid grid-cols-2 sm:grid-cols-3 gap-x-6 gap-y-2 text-sm`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`dt`,{className:`text-bambu-gray`,children:e(`settings.oidc.form.clientId`)}),(0,G.jsx)(`dd`,{className:`text-white font-mono truncate`,children:t.client_id})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`dt`,{className:`text-bambu-gray`,children:e(`settings.oidc.form.scopes`)}),(0,G.jsx)(`dd`,{className:`text-white`,children:t.scopes})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`dt`,{className:`text-bambu-gray`,children:e(`settings.oidc.form.autoCreate`)}),(0,G.jsx)(`dd`,{className:t.auto_create_users?`text-green-700 dark:text-green-400`:`text-bambu-gray`,children:t.auto_create_users?e(`common.yes`):e(`common.no`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`dt`,{className:`text-bambu-gray`,children:e(`settings.oidc.form.autoLink`)}),(0,G.jsx)(`dd`,{className:t.auto_link_existing_accounts?`text-green-700 dark:text-green-400`:`text-bambu-gray`,children:t.auto_link_existing_accounts?e(`common.yes`):e(`common.no`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`dt`,{className:`text-bambu-gray`,children:e(`settings.oidc.form.emailClaim`)}),(0,G.jsx)(`dd`,{className:`text-white font-mono`,children:t.email_claim})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`dt`,{className:`text-bambu-gray`,children:e(`settings.oidc.form.requireEmailVerified`)}),(0,G.jsx)(`dd`,{className:t.require_email_verified?`text-green-700 dark:text-green-400`:`text-red-700 dark:text-red-400`,children:t.require_email_verified?e(`common.yes`):e(`common.no`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`dt`,{className:`text-bambu-gray`,children:e(`settings.oidc.form.defaultGroup`)}),(0,G.jsx)(`dd`,{className:`text-white`,children:t.default_group_id?d.find(e=>e.id===t.default_group_id)?.name??e(`settings.oidc.form.defaultGroupViewersFallback`):e(`settings.oidc.form.defaultGroupViewersFallback`)})]})]})})]},t.id)),s&&(0,G.jsx)(Zd,{title:e(`settings.oidc.deleteTitle`),message:e(`settings.oidc.deleteMessage`,{name:s.name}),confirmText:e(`common.delete`),variant:`danger`,onConfirm:()=>m.mutate(s.id),onCancel:()=>c(null)})]})}var N6=new Map;function P6(e){N6.set(e.anchor,e)}function VHe(){return Array.from(N6.values())}P6({labelKey:`settings.encryption.title`,labelFallback:`MFA Encryption Status`,tab:`users`,subTab:`security`,keywords:`mfa encryption status security backup totp oidc fernet`,anchor:`card-mfa-encryption`});function HHe(){let{t:e}=U(),{data:t,isLoading:n,isError:r,refetch:i}=K({queryKey:[`encryptionStatus`],queryFn:()=>Z.getEncryptionStatus(),refetchInterval:e=>{if(!e.state.error)return 3e4;let t=e.state.fetchFailureCount??0;return t<=3?Math.min(5e3*Math.max(1,t),3e4):!1}});if(n)return(0,G.jsxs)(Md,{id:`card-mfa-encryption`,"data-testid":`encryption-status-card`,children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(iu,{className:`text-bambu-gray`,size:20}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold`,children:e(`settings.encryption.title`)})]})}),(0,G.jsx)(Pd,{children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray`,"data-testid":`encryption-loading`,children:[(0,G.jsx)(Y,{className:`animate-spin`,size:16}),(0,G.jsx)(`span`,{children:e(`common.loading`)})]})})]});if(r||!t)return(0,G.jsxs)(Md,{id:`card-mfa-encryption`,"data-testid":`encryption-status-card`,children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(iu,{className:`text-bambu-gray`,size:20}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold`,children:e(`settings.encryption.title`)})]})}),(0,G.jsxs)(Pd,{children:[(0,G.jsx)(`div`,{className:`text-red-700 dark:text-red-400`,"data-testid":`encryption-error`,children:e(`common.errorLoading`)}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>i(),className:`mt-2 text-sm text-blue-700 dark:text-blue-400 underline hover:text-blue-800 dark:hover:text-blue-300`,"data-testid":`encryption-retry-button`,children:e(`common.retry`)})]})]});let a=t.legacy_plaintext_rows.oidc_providers+t.legacy_plaintext_rows.user_totp,o=t.encrypted_rows.oidc_providers+t.encrypted_rows.user_totp,s,c,l,u;t.decryption_broken?(s=`bg-red-100 dark:bg-red-500/20 border-red-400 dark:border-red-500/50 text-red-700 dark:text-red-400`,c=(0,G.jsx)(Ts,{className:`text-red-600 dark:text-red-400`,size:20}),l=e(`settings.encryption.decryptionBrokenTitle`),u=e(`settings.encryption.decryptionBrokenError`,{count:o})):t.key_source===`generated`?(s=`bg-amber-50 dark:bg-amber-500/10 border-amber-300 dark:border-amber-500/30 text-amber-700 dark:text-amber-400`,c=(0,G.jsx)(nu,{className:`text-amber-600 dark:text-amber-400`,size:20}),l=e(`settings.encryption.enabledGenerated`),u=e(`settings.encryption.backupHint`)):a>0?(s=`bg-amber-50 dark:bg-amber-500/10 border-amber-300 dark:border-amber-500/30 text-amber-700 dark:text-amber-400`,c=(0,G.jsx)(Pu,{className:`text-amber-600 dark:text-amber-400`,size:20}),l=t.key_source===`env`?e(`settings.encryption.enabledFromEnv`):e(`settings.encryption.enabledFromFile`),u=e(`settings.encryption.legacyRowsWarning`,{count:a})):t.key_configured?(s=`bg-green-100 dark:bg-green-500/20 border-green-300 dark:border-green-500/30 text-green-700 dark:text-green-400`,c=(0,G.jsx)(nu,{className:`text-green-600 dark:text-green-400`,size:20}),l=t.key_source===`env`?e(`settings.encryption.enabledFromEnv`):e(`settings.encryption.enabledFromFile`),u=e(`settings.encryption.allEncrypted`)):(s=`bg-gray-500/20 border-gray-500/30 text-gray-400`,c=(0,G.jsx)(ru,{className:`text-gray-400`,size:20}),l=e(`settings.encryption.notConfigured`),u=e(`settings.encryption.notConfiguredDesc`));let d=t.key_source===`generated`&&a>0;return(0,G.jsxs)(Md,{id:`card-mfa-encryption`,"data-testid":`encryption-status-card`,children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[c,(0,G.jsx)(`h2`,{className:`text-lg font-semibold`,children:e(`settings.encryption.title`)})]})}),(0,G.jsxs)(Pd,{children:[(0,G.jsxs)(`div`,{className:`p-3 border rounded-lg ${s}`,"data-testid":`encryption-status`,children:[(0,G.jsx)(`p`,{className:`font-medium mb-1`,children:l}),(0,G.jsx)(`p`,{className:`text-sm`,children:u})]}),d&&(0,G.jsx)(`div`,{className:`mt-2 p-3 border rounded-lg bg-amber-50 dark:bg-amber-500/10 border-amber-300 dark:border-amber-500/30 text-amber-700 dark:text-amber-400`,"data-testid":`encryption-legacy-warning`,children:(0,G.jsx)(`p`,{className:`text-sm`,children:e(`settings.encryption.legacyRowsWarning`,{count:a})})}),t.migration_error_count>0&&(0,G.jsx)(`div`,{className:`mt-2 p-3 border rounded-lg bg-amber-50 dark:bg-amber-500/10 border-amber-300 dark:border-amber-500/30 text-amber-700 dark:text-amber-400`,"data-testid":`encryption-migration-warning`,children:(0,G.jsx)(`p`,{className:`text-sm`,children:e(`settings.encryption.migrationErrorWarning`,{count:t.migration_error_count})})}),(0,G.jsxs)(`div`,{className:`mt-4 grid grid-cols-2 gap-4 text-sm`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-bambu-gray`,children:e(`settings.encryption.encryptedRowsLabel`)}),(0,G.jsxs)(`p`,{className:`font-medium`,children:[`OIDC: `,t.encrypted_rows.oidc_providers,` · TOTP: `,t.encrypted_rows.user_totp]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-bambu-gray`,children:e(`settings.encryption.legacyRowsLabel`)}),(0,G.jsxs)(`p`,{className:`font-medium`,children:[`OIDC: `,t.legacy_plaintext_rows.oidc_providers,` · TOTP: `,t.legacy_plaintext_rows.user_totp]})]})]})]})]})}var UHe={get:`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400 border-blue-300 dark:border-blue-500/30`,post:`bg-green-100 dark:bg-green-500/20 text-green-700 dark:text-green-400 border-green-300 dark:border-green-500/30`,put:`bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400 border-yellow-300 dark:border-yellow-500/30`,patch:`bg-orange-100 dark:bg-orange-500/20 text-orange-700 dark:text-orange-400 border-orange-300 dark:border-orange-500/30`,delete:`bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400 border-red-300 dark:border-red-500/30`};function WHe(e,t){let n=t.replace(`#/`,``).split(`/`),r=e;for(let e of n)r=r[e];return r}function F6(e,t,n=0){if(n>5)return`...`;if(t.$ref)return F6(e,WHe(e,t.$ref),n+1);if(t.allOf){let r={};for(let i of t.allOf){let t=F6(e,i,n+1);typeof t==`object`&&t&&Object.assign(r,t)}return r}if(t.example!==void 0)return t.example;if(t.default!==void 0)return t.default;switch(t.type){case`string`:return t.enum?t.enum[0]:`string`;case`integer`:case`number`:return 0;case`boolean`:return!1;case`array`:return t.items?[F6(e,t.items,n+1)]:[];case`object`:if(t.properties){let r={};for(let[i,a]of Object.entries(t.properties))r[i]=F6(e,a,n+1);return r}return{};default:return null}}function GHe({path:e,method:t,spec:n,schema:r,apiKey:i}){let[a,o]=(0,y.useState)(!1),[s,c]=(0,y.useState)({}),[l,u]=(0,y.useState)(``),[d,f]=(0,y.useState)(null),[p,m]=(0,y.useState)(!1),[h,g]=(0,y.useState)(!1);(0,y.useEffect)(()=>{if(a&&n.parameters){let e={};for(let t of n.parameters)t.schema?.default!==void 0&&(e[t.name]=String(t.schema.default));c(t=>({...e,...t}))}},[a,n.parameters]),(0,y.useEffect)(()=>{if(a&&n.requestBody?.content?.[`application/json`]?.schema&&!l){let e=n.requestBody.content[`application/json`].schema,t=F6(r,e);u(JSON.stringify(t,null,2))}},[a,n.requestBody,r,l]);let _=(()=>{let e=[];for(let t of n.parameters||[])if(t.in===`path`||t.required){let n=s[t.name];(n===void 0||n===``)&&e.push(t.name)}return e})(),v=async()=>{if(_.length>0){f({status:0,statusText:`Validation Error`,headers:{},body:`Missing required parameters: ${_.join(`, `)}`,duration:0});return}m(!0),f(null);try{let r=e,a=new URLSearchParams;for(let e of n.parameters||[]){let t=s[e.name];t!==void 0&&t!==``&&(e.in===`path`?r=r.replace(`{${e.name}}`,encodeURIComponent(t)):e.in===`query`&&a.append(e.name,t))}let o=a.toString(),c=`${r}${o?`?${o}`:``}`,u={"Content-Type":`application/json`};i&&(u[`X-API-Key`]=i);let d={method:t.toUpperCase(),headers:u};[`post`,`put`,`patch`].includes(t)&&l&&(d.body=l);let p=performance.now(),m=await fetch(c,d),h=Math.round(performance.now()-p),g={};m.headers.forEach((e,t)=>{g[t]=e});let _;_=m.headers.get(`content-type`)?.includes(`application/json`)?await m.json():await m.text(),f({status:m.status,statusText:m.statusText,headers:g,body:_,duration:h})}catch(e){f({status:0,statusText:`Network Error`,headers:{},body:e instanceof Error?e.message:`Unknown error`,duration:0})}finally{m(!1)}},b=async()=>{if(d){let e=typeof d.body==`string`?d.body:JSON.stringify(d.body,null,2);try{await navigator.clipboard.writeText(e),g(!0),setTimeout(()=>g(!1),2e3)}catch{let t=document.createElement(`textarea`);t.value=e,t.style.position=`fixed`,t.style.left=`-999999px`,document.body.appendChild(t),t.select(),document.execCommand(`copy`),document.body.removeChild(t),g(!0),setTimeout(()=>g(!1),2e3)}}},x=(n.parameters||[]).filter(e=>e.in===`path`),S=(n.parameters||[]).filter(e=>e.in===`query`),C=[`post`,`put`,`patch`].includes(t)&&n.requestBody;return(0,G.jsxs)(`div`,{className:`border border-bambu-dark-tertiary rounded-lg overflow-hidden`,children:[(0,G.jsxs)(`button`,{onClick:()=>o(!a),className:`w-full flex items-center gap-3 p-3 hover:bg-bambu-dark-tertiary/50 transition-colors text-left`,children:[a?(0,G.jsx)(ds,{className:`w-4 h-4 text-bambu-gray flex-shrink-0`}):(0,G.jsx)(fs,{className:`w-4 h-4 text-bambu-gray flex-shrink-0`}),(0,G.jsx)(`span`,{className:`px-2 py-0.5 text-xs font-mono font-semibold uppercase rounded border ${UHe[t]||`bg-gray-500/20 text-gray-400`}`,children:t}),(0,G.jsx)(`code`,{className:`text-sm text-white font-mono flex-1 truncate`,children:e}),n.summary&&(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray truncate max-w-[40%]`,children:n.summary})]}),a&&(0,G.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary p-4 space-y-4 bg-bambu-dark/50`,children:[n.description&&(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n.description}),x.length>0&&(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`h4`,{className:`text-sm font-medium text-white`,children:`Path Parameters`}),(0,G.jsx)(`div`,{className:`space-y-2`,children:x.map(e=>(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`label`,{className:`text-sm text-bambu-gray w-32 flex-shrink-0`,children:[e.name,e.required&&(0,G.jsx)(`span`,{className:`text-red-700 dark:text-red-400 ml-1`,children:`*`})]}),(0,G.jsx)(`input`,{type:`text`,value:s[e.name]||``,onChange:t=>c(n=>({...n,[e.name]:t.target.value})),placeholder:e.description||e.schema?.type||`value`,className:`flex-1 px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm font-mono focus:border-bambu-green focus:outline-none`})]},e.name))})]}),S.length>0&&(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`h4`,{className:`text-sm font-medium text-white`,children:`Query Parameters`}),(0,G.jsx)(`div`,{className:`space-y-2`,children:S.map(e=>(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`label`,{className:`text-sm text-bambu-gray w-32 flex-shrink-0`,children:[e.name,e.required&&(0,G.jsx)(`span`,{className:`text-red-700 dark:text-red-400 ml-1`,children:`*`})]}),e.schema?.enum?(0,G.jsxs)(`select`,{value:s[e.name]||``,onChange:t=>c(n=>({...n,[e.name]:t.target.value})),className:`flex-1 px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`,children:[(0,G.jsx)(`option`,{value:``,children:`-- Select --`}),e.schema.enum.map(e=>(0,G.jsx)(`option`,{value:e,children:e},e))]}):(0,G.jsx)(`input`,{type:`text`,value:s[e.name]||``,onChange:t=>c(n=>({...n,[e.name]:t.target.value})),placeholder:e.description||e.schema?.type||`value`,className:`flex-1 px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm font-mono focus:border-bambu-green focus:outline-none`})]},e.name))})]}),C&&(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`h4`,{className:`text-sm font-medium text-white`,children:`Request Body`}),(0,G.jsx)(`textarea`,{value:l,onChange:e=>u(e.target.value),rows:8,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm font-mono focus:border-bambu-green focus:outline-none resize-y`,placeholder:`JSON request body...`})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(Q,{onClick:v,disabled:p,children:[p?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Al,{className:`w-4 h-4`}),`Execute`]}),_.length>0&&(0,G.jsxs)(`span`,{className:`text-xs text-yellow-700 dark:text-yellow-400 flex items-center gap-1`,children:[(0,G.jsx)(_s,{className:`w-3 h-3`}),`Fill in: `,_.join(`, `)]})]}),d&&(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`h4`,{className:`text-sm font-medium text-white flex items-center gap-2`,children:[`Response`,(0,G.jsxs)(`span`,{className:`px-2 py-0.5 text-xs rounded ${d.status>=200&&d.status<300?`bg-green-100 dark:bg-green-500/20 text-green-700 dark:text-green-400`:d.status>=400?`bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400`:`bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400`}`,children:[d.status,` `,d.statusText]}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[d.duration,`ms`]})]}),(0,G.jsx)(Q,{variant:`secondary`,size:`sm`,onClick:b,children:h?(0,G.jsx)(ys,{className:`w-3 h-3 text-green-600 dark:text-green-400`}):(0,G.jsx)(zs,{className:`w-3 h-3`})})]}),(0,G.jsx)(`pre`,{className:`p-3 bg-bambu-dark rounded-lg text-sm font-mono text-white overflow-auto max-h-96 border border-bambu-dark-tertiary`,children:typeof d.body==`string`?d.body:JSON.stringify(d.body,null,2)})]})]})]})}function KHe({apiKey:e=``}){let[t,n]=(0,y.useState)(null),[r,i]=(0,y.useState)(!0),[a,o]=(0,y.useState)(null),[s,c]=(0,y.useState)(new Set),[l,u]=(0,y.useState)(``);if((0,y.useEffect)(()=>{async function e(){try{let e=await fetch(`/openapi.json`);if(!e.ok)throw Error(`Failed to fetch OpenAPI schema`);n(await e.json())}catch(e){o(e instanceof Error?e.message:`Unknown error`)}finally{i(!1)}}e()},[]),r)return(0,G.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,G.jsx)(Y,{className:`w-8 h-8 text-bambu-green animate-spin`})});if(a||!t)return(0,G.jsx)(Md,{children:(0,G.jsx)(Pd,{className:`py-8`,children:(0,G.jsxs)(`div`,{className:`text-center text-red-700 dark:text-red-400`,children:[(0,G.jsx)(_s,{className:`w-12 h-12 mx-auto mb-3 opacity-50`}),(0,G.jsx)(`p`,{children:`Failed to load API schema`}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:a})]})})});let d={};for(let[e,n]of Object.entries(t.paths))for(let[t,r]of Object.entries(n)){if(t===`parameters`)continue;let n=r.tags||[`Other`];for(let i of n)d[i]||(d[i]=[]),d[i].push({path:e,method:t,spec:r})}let f=Object.entries(d).map(([e,t])=>l?{tag:e,endpoints:t.filter(({path:e,method:t,spec:n})=>{let r=l.toLowerCase();return e.toLowerCase().includes(r)||t.toLowerCase().includes(r)||(n.summary?.toLowerCase()||``).includes(r)||(n.description?.toLowerCase()||``).includes(r)})}:{tag:e,endpoints:t}).filter(({endpoints:e})=>e.length>0).sort((e,t)=>e.tag.localeCompare(t.tag)),p=e=>{c(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})};return(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,G.jsx)(`div`,{className:`flex-1`,children:(0,G.jsx)(`input`,{type:`text`,value:l,onChange:e=>u(e.target.value),placeholder:`Search endpoints...`,className:`w-full max-w-md px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Q,{variant:`secondary`,size:`sm`,onClick:()=>{c(new Set(f.map(e=>e.tag)))},children:`Expand All`}),(0,G.jsx)(Q,{variant:`secondary`,size:`sm`,onClick:()=>{c(new Set)},children:`Collapse All`}),(0,G.jsxs)(`a`,{href:`/docs`,target:`_blank`,rel:`noopener noreferrer`,className:`flex items-center gap-1 text-sm text-bambu-green hover:underline`,children:[(0,G.jsx)(tc,{className:`w-4 h-4`}),`Swagger UI`]})]})]}),(0,G.jsxs)(`p`,{className:`text-sm text-bambu-gray`,children:[f.reduce((e,t)=>e+t.endpoints.length,0),` endpoints in `,f.length,` categories`]}),(0,G.jsx)(`div`,{className:`space-y-3`,children:f.map(({tag:n,endpoints:r})=>(0,G.jsxs)(Md,{children:[(0,G.jsx)(`button`,{onClick:()=>p(n),className:`w-full flex items-center justify-between p-4 hover:bg-bambu-dark-tertiary/30 transition-colors text-left`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[s.has(n)?(0,G.jsx)(ds,{className:`w-5 h-5 text-bambu-gray`}):(0,G.jsx)(fs,{className:`w-5 h-5 text-bambu-gray`}),(0,G.jsx)(`h3`,{className:`text-base font-semibold text-white capitalize`,children:n.replace(/-/g,` `)}),(0,G.jsx)(`span`,{className:`text-xs bg-bambu-dark-tertiary px-2 py-0.5 rounded-full text-bambu-gray`,children:r.length})]})}),s.has(n)&&(0,G.jsx)(Pd,{className:`pt-0 space-y-2`,children:r.map(({path:n,method:r,spec:i})=>(0,G.jsx)(GHe,{path:n,method:r,spec:i,schema:t,apiKey:e},`${r}-${n}`))})]},n))})]})}var qHe=[{id:`sidecar`,labelKey:`settings.sliceEngineSidecar`,descriptionKey:`settings.sliceEngineSidecarHint`,available:!0},{id:`browser`,labelKey:`settings.sliceEngineBrowser`,descriptionKey:`settings.sliceEngineBrowserHint`,available:!1}];function I6(){return qHe.filter(e=>e.available)}function JHe(){return I6().length>1}function L6(e){return I6().find(t=>t.id===e)?.id??`sidecar`}var YHe=[`general`,`plugs`,`notifications`,`queue`,`filament`,`network`,`apikeys`,`virtual-printer`,`spoolbuddy`,`failure-detection`,`users`,`backup`];P6({labelKey:`settings.general`,tab:`general`,keywords:`language date time format printer model printers cards`,anchor:`card-general`}),P6({labelKey:`settings.appearance`,tab:`general`,keywords:`theme dark light mode colors`,anchor:`card-appearance`}),P6({labelKey:`settings.archiveSettings`,tab:`general`,keywords:`archive auto save thumbnails captures`,anchor:`card-archive`}),P6({labelKey:`settings.camera`,tab:`general`,keywords:`camera external video stream`,anchor:`card-camera`}),P6({labelKey:`settings.costTracking`,tab:`general`,keywords:`currency filament cost energy kwh price`,anchor:`card-cost`}),P6({labelKey:`settings.fileManager`,tab:`general`,keywords:`file manager archive mode disk warning storage`,anchor:`card-filemanager`}),P6({labelKey:`settings.updates`,tab:`general`,keywords:`updates version firmware beta check`,anchor:`card-updates`}),P6({labelKey:`settings.dataManagement`,tab:`general`,keywords:`data reset clear logs notifications preferences`,anchor:`card-data`}),P6({labelKey:`settings.smartPlugs`,tab:`plugs`,keywords:`smart plug energy power automation tapo kasa tplink shelly`,anchor:`card-plugs`}),P6({labelKey:`settings.providers`,tab:`notifications`,keywords:`telegram discord email notification providers webhook`,anchor:`card-providers`}),P6({labelKey:`settings.messageTemplates`,tab:`notifications`,keywords:`message templates notification text edit`,anchor:`card-templates`}),P6({labelKey:`settings.defaultPrintOptions`,labelFallback:`Default Print Options`,tab:`queue`,keywords:`print bed leveling flow calibration vibration first layer timelapse`,anchor:`card-print-options`}),P6({labelKey:`settings.tempFanPresetsTitle`,labelFallback:`Temperature & Fan Presets`,tab:`queue`,keywords:`temperature fan presets nozzle bed chamber quick buttons popover`,anchor:`card-temp-fan-presets`}),P6({labelKey:`settings.staggeredStart`,labelFallback:`Staggered Start`,tab:`queue`,keywords:`staggered batch delay start queue group`,anchor:`card-staggered`}),P6({labelKey:`settings.plateClear`,labelFallback:`Plate-Clear Confirmation`,tab:`queue`,keywords:`plate clear confirm auto queue`,anchor:`card-plate`}),P6({labelKey:`settings.concurrentUploadsTitle`,labelFallback:`Concurrent Uploads`,tab:`queue`,keywords:`concurrent parallel upload transfer ftp queue slow farm simultaneous`,anchor:`card-concurrent-uploads`}),P6({labelKey:`settings.gcodeInjection`,labelFallback:`G-code Injection`,tab:`queue`,keywords:`gcode injection start end autoprint farmloop swapmod autoclear printflow`,anchor:`card-gcode`}),P6({labelKey:`settings.slicerCard`,labelFallback:`Slicer`,tab:`queue`,keywords:`slicer orcaslicer bambustudio orca bambu api sidecar url docker preferred`,anchor:`card-slicer`}),P6({labelKey:`settings.queueDrying`,tab:`queue`,keywords:`drying presets temperature time humidity ams`,anchor:`card-drying`}),P6({labelKey:`settings.filamentChecks`,tab:`filament`,keywords:`filament check warning runout remaining`,anchor:`card-filamentchecks`}),P6({labelKey:`settings.printModal`,tab:`filament`,keywords:`print modal custom mapping`,anchor:`card-printmodal`}),P6({labelKey:`settings.amsDisplayThresholds`,tab:`filament`,keywords:`ams humidity temperature threshold history retention`,anchor:`card-amsthresholds`}),P6({labelKey:`settings.externalUrl`,tab:`network`,keywords:`external url reverse proxy public notification link`,anchor:`card-externalurl`}),P6({labelKey:`settings.ftpRetry`,tab:`network`,keywords:`ftp retry upload retries backoff`,anchor:`card-ftpretry`}),P6({labelKey:`settings.homeAssistant`,tab:`network`,keywords:`home assistant ha hass mqtt integration`,anchor:`card-ha`}),P6({labelKey:`settings.mqttPublishing`,tab:`network`,keywords:`mqtt publish broker topic`,anchor:`card-mqtt`}),P6({labelKey:`settings.prometheusMetrics`,tab:`network`,keywords:`prometheus metrics grafana monitoring bearer token`,anchor:`card-prometheus`}),P6({labelKey:`settings.createNewApiKey`,tab:`apikeys`,keywords:`api key create permission scope`,anchor:`card-createapi`}),P6({labelKey:`settings.webhookEndpoints`,tab:`apikeys`,keywords:`webhook endpoint post http`,anchor:`card-webhooks`}),P6({labelKey:`settings.apiBrowser`,tab:`apikeys`,keywords:`api browser endpoint documentation test`,anchor:`card-apibrowser`}),P6({labelKey:`cameraTokens.title`,tab:`apikeys`,keywords:`camera token long-lived home assistant frigate kiosk stream`,anchor:`card-camera-tokens`}),P6({labelKey:`settings.tabs.virtualPrinter`,tab:`virtual-printer`,keywords:`virtual printer proxy archive slicer bambustudio orcaslicer ip bind`,anchor:`card-vp`}),P6({labelKey:`settings.tabs.spoolbuddy`,tab:`spoolbuddy`,keywords:`spoolbuddy device scale nfc rfid kiosk unregister`,anchor:`card-spoolbuddy`}),P6({labelKey:`settings.currentUser`,tab:`users`,subTab:`users`,keywords:`current user profile password change`,anchor:`card-currentuser`}),P6({labelKey:`settings.users`,tab:`users`,subTab:`users`,keywords:`users accounts list`,anchor:`card-users`}),P6({labelKey:`settings.groups`,tab:`users`,subTab:`users`,keywords:`groups roles permissions administrators operators viewers`,anchor:`card-groups`}),P6({labelKey:`settings.sessionPolicy.title`,labelFallback:`Session Policy`,tab:`users`,subTab:`users`,keywords:`session timeout expiry logout remember me jwt token lifetime`,anchor:`card-session-policy`}),P6({labelKey:`settings.email.smtpSettings`,labelFallback:`SMTP Configuration`,tab:`users`,subTab:`email`,keywords:`smtp email send server port password auth starttls ssl`,anchor:`card-smtp`}),P6({labelKey:`settings.ldap.title`,labelFallback:`LDAP Authentication`,tab:`users`,subTab:`ldap`,keywords:`ldap active directory ad authentication bind dn search base group mapping`,anchor:`card-ldap`}),P6({labelKey:`settings.tabs.backup`,tab:`backup`,keywords:`backup github restore download cloud sync profiles archives`,anchor:`card-backup`}),P6({labelKey:`externalLinks.sidebarLayout`,labelFallback:`Sidebar`,tab:`general`,keywords:`sidebar layout links pages hide show external custom navigation url add`,anchor:`card-sidebar-links`}),P6({labelKey:`settings.filamentTracking`,tab:`filament`,keywords:`spoolman filament tracking inventory sync remote integration`,anchor:`card-spoolman`}),P6({labelKey:`settings.catalog.spoolCatalog`,labelFallback:`Spool Catalog`,tab:`filament`,keywords:`spool catalog entries brand material reset import export`,anchor:`card-spool-catalog`}),P6({labelKey:`settings.colorCatalog.title`,labelFallback:`Color Catalog`,tab:`filament`,keywords:`color catalog hex swatch palette sync reset`,anchor:`card-color-catalog`}),P6({labelKey:`settings.tabs.failureDetection`,labelFallback:`Failure Detection`,tab:`failure-detection`,keywords:`failure detection ai ml obico spaghetti detect monitoring`,anchor:`card-fd-ml`}),P6({labelKey:`failureDetection.perPrinterTitle`,labelFallback:`Per-Printer Settings`,tab:`failure-detection`,keywords:`failure detection per printer enable per-printer sensitivity`,anchor:`card-fd-perprinter`}),P6({labelKey:`failureDetection.statusTitle`,labelFallback:`Detection Status`,tab:`failure-detection`,keywords:`failure detection status running connection`,anchor:`card-fd-status`}),P6({labelKey:`failureDetection.historyTitle`,labelFallback:`Detection History`,tab:`failure-detection`,keywords:`failure detection history log events`,anchor:`card-fd-history`}),P6({labelKey:`settings.email.advancedAuth`,labelFallback:`Advanced Email Authentication`,tab:`users`,subTab:`email`,keywords:`email authentication advanced password reset self-service forgot`,anchor:`card-email-advanced-auth`}),P6({labelKey:`settings.email.testConnection`,labelFallback:`Test SMTP Connection`,tab:`users`,subTab:`email`,keywords:`email smtp test connection send check`,anchor:`card-email-test`}),P6({labelKey:`settings.twoFa.totpTitle`,labelFallback:`Authenticator App (TOTP)`,tab:`users`,subTab:`twofa`,keywords:`two factor 2fa totp authenticator app google authy otp`,anchor:`card-2fa-totp`}),P6({labelKey:`settings.twoFa.emailOtpTitle`,labelFallback:`Email One-Time Codes`,tab:`users`,subTab:`twofa`,keywords:`two factor 2fa email otp one time code`,anchor:`card-2fa-emailotp`}),P6({labelKey:`settings.twoFa.linkedAccounts`,labelFallback:`Linked Accounts`,tab:`users`,subTab:`twofa`,keywords:`two factor 2fa linked accounts sso oidc provider google github`,anchor:`card-2fa-linked`}),P6({labelKey:`settings.oidc.title`,labelFallback:`Single Sign-On (OIDC)`,tab:`users`,subTab:`oidc`,keywords:`sso oidc openid single sign-on pocketid authentik keycloak google okta azure provider`,anchor:`card-oidc`}),P6({labelKey:`settings.ldap.serverConfig`,labelFallback:`LDAP Server Configuration`,tab:`users`,subTab:`ldap`,keywords:`ldap server url bind dn user search base group filter tls`,anchor:`card-ldap-server`}),P6({labelKey:`backup.githubBackup`,labelFallback:`GitHub Backup`,tab:`backup`,keywords:`github backup cloud remote sync profiles token`,anchor:`card-backup-github`}),P6({labelKey:`backup.history`,labelFallback:`Backup History`,tab:`backup`,keywords:`backup history log runs github commits`,anchor:`card-backup-history`}),P6({labelKey:`backup.localBackup`,labelFallback:`Local Backup`,tab:`backup`,keywords:`local backup download zip manual export`,anchor:`card-backup-local`}),P6({labelKey:`backup.scheduledBackup`,labelFallback:`Scheduled Backups`,tab:`backup`,keywords:`scheduled backup automatic hourly daily weekly retention local path`,anchor:`card-backup-scheduled`});var R6=20,XHe={database:`bg-blue-600`,library_files:`bg-green-500`,library_thumbnails:`bg-teal-500`,library_other:`bg-emerald-700`,archive_timelapses:`bg-red-500`,archive_thumbnails:`bg-amber-500`,archive_files:`bg-sky-500`,virtual_printer_uploads:`bg-purple-500`,virtual_printer_upload_cache:`bg-fuchsia-500`,virtual_printer_certs:`bg-violet-500`,virtual_printer_other:`bg-purple-700`,downloads:`bg-cyan-500`,plate_calibration:`bg-lime-500`,logs:`bg-orange-500`,other_data:`bg-yellow-500`},z6=[`bg-blue-500`,`bg-green-500`,`bg-yellow-500`,`bg-red-500`,`bg-orange-500`,`bg-teal-500`,`bg-cyan-500`,`bg-purple-500`],B6=(e,t)=>XHe[e]||z6[t%z6.length];function ZHe(){let e=so(),t=or(),[n,r]=Li(),{t:i,i18n:a}=U(),{showToast:o}=Bd(),{authEnabled:s,user:c,isAdmin:l,refreshAuth:u,hasPermission:d}=Ed(),{mode:f,resolvedMode:p,darkStyle:m,darkBackground:h,darkAccent:g,lightStyle:_,lightBackground:v,lightAccent:b,setMode:x,setDarkStyle:S,setDarkBackground:C,setDarkAccent:w,setLightStyle:T,setLightBackground:E,setLightAccent:D,progressInTitle:O,setProgressInTitle:k}=kd(),[A,j]=(0,y.useState)(null),[M,N]=(0,y.useState)({}),[P,F]=(0,y.useState)(!1),[I,L]=(0,y.useState)(null),[R,z]=(0,y.useState)(!1),[B,V]=(0,y.useState)(null),[ee,te]=(0,y.useState)(!1),[ne,re]=(0,y.useState)(null),[ie,ae]=(0,y.useState)(null),[oe,se]=(0,y.useState)(``),[H,ce]=(0,y.useState)(``),[le,ue]=(0,y.useState)(!1),[de,fe]=(0,y.useState)(!1),[pe,me]=(0,y.useState)(!1),[he,ge]=(0,y.useState)(em()),_e=n.get(`tab`),ve=_e===`email`,[ye,be]=(0,y.useState)(ve?`users`:_e&&YHe.includes(_e)?_e:`general`),[xe,Se]=(0,y.useState)(ve?`email`:`users`),[Ce,we]=(0,y.useState)(_e===`queue`&&n.get(`sub`)===`pipelines`?`pipelines`:`dispatch`),Te=e=>{be(e),e===`users`&&Se(`users`),e===`queue`&&(we(`dispatch`),n.delete(`sub`)),e===`general`?n.delete(`tab`):n.set(`tab`,e),r(n,{replace:!0})},Ee=e=>{we(e),e===`pipelines`?n.set(`sub`,`pipelines`):n.delete(`sub`),r(n,{replace:!0})},[De,Oe]=(0,y.useState)(!1),[ke,Ae]=(0,y.useState)(``),[je,Me]=(0,y.useState)({can_queue:!0,can_control_printer:!1,can_read_status:!0,can_manage_library:!0,can_manage_inventory:!0,can_manage_maintenance:!0,can_manage_archives:!0,can_manage_projects:!0,can_access_cloud:!1,can_update_energy_cost:!1}),[Ne,Pe]=(0,y.useState)(null),[Fe,Ie]=(0,y.useState)(!1),[Le,Re]=(0,y.useState)(null),[ze,Be]=(0,y.useState)(``),[Ve,He]=(0,y.useState)(!1),[Ue,We]=(0,y.useState)(!1),[Ge,Ke]=(0,y.useState)(null),[qe,Je]=(0,y.useState)(!1),[Ye,Xe]=(0,y.useState)(!1),[Ze,Qe]=(0,y.useState)(!1),[$e,et]=(0,y.useState)({currentPassword:``,newPassword:``,confirmPassword:``}),[tt,nt]=(0,y.useState)(!1),[rt,it]=(0,y.useState)(!1),[at,ot]=(0,y.useState)(!1),[st,ct]=(0,y.useState)(`local`),[lt,ut]=(0,y.useState)(!1),[dt,ft]=(0,y.useState)(null),[pt,mt]=(0,y.useState)(null),[ht,gt]=(0,y.useState)(null),[_t,vt]=(0,y.useState)(!1),[yt,bt]=(0,y.useState)({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]}),[xt,St]=(0,y.useState)(null),[Ct,wt]=(0,y.useState)(null),[Tt,Et]=(0,y.useState)(!1),[Dt,Ot]=(0,y.useState)({}),[At,jt]=(0,y.useState)({}),Mt=e=>{ge(e),see(e),o(i(`settings.toast.settingsSaved`),`success`)},{data:Nt,isLoading:Pt}=K({queryKey:[`settings`],queryFn:Z.getSettings}),{data:Ft,isLoading:It,isFetching:Lt}=K({queryKey:[`storage-usage`],queryFn:()=>Z.getStorageUsage(),enabled:ye===`general`,staleTime:1/0,refetchInterval:!1,refetchOnWindowFocus:!1,refetchOnReconnect:!1}),Rt=async()=>{it(!0);try{let t=await Z.getStorageUsage({refresh:!0});e.setQueryData([`storage-usage`],t)}catch(e){o(e instanceof Error?e.message:`Failed to refresh storage usage`,`error`)}finally{it(!1)}},{data:zt,isLoading:Bt}=K({queryKey:[`smart-plugs`],queryFn:Z.getSmartPlugs}),{data:Vt,isLoading:W}=K({queryKey:[`smart-plugs-energy`,zt?.map(e=>e.id)],queryFn:async()=>{if(!zt||zt.length===0)return null;let e=await Promise.all(zt.filter(e=>e.enabled).map(async e=>{try{return{plug:e,status:await Z.getSmartPlugStatus(e.id)}}catch{return{plug:e,status:null}}})),t=0,n=0,r=0,i=0,a=0;for(let{plug:o,status:s}of e){let e=o.plug_type===`mqtt`&&s?.energy?.power!=null;(s?.reachable||e)&&s?.energy&&(a++,s.energy?.power!=null&&(t+=s.energy.power),s.energy?.today!=null&&(n+=s.energy.today),s.energy?.yesterday!=null&&(r+=s.energy.yesterday),s.energy?.total!=null&&(i+=s.energy.total))}return{totalPower:t,totalToday:n,totalYesterday:r,totalLifetime:i,reachableCount:a,totalPlugs:zt.filter(e=>e.enabled).length}},enabled:ye===`plugs`&&!!zt&&zt.length>0,refetchInterval:ye===`plugs`?1e4:!1}),{data:Ht,isLoading:Ut}=K({queryKey:[`notification-providers`],queryFn:Z.getNotificationProviders}),{data:Wt,isLoading:Gt}=K({queryKey:[`api-keys`],queryFn:Z.getAPIKeys}),Kt=q({mutationFn:e=>Z.createAPIKey(e),onSuccess:t=>{Pe(t.key||null),Oe(!1),Ae(``),e.invalidateQueries({queryKey:[`api-keys`]}),o(i(`settings.toast.apiKeyCreated`))},onError:e=>{o(`Failed to create API key: ${e.message}`,`error`)}}),qt=q({mutationFn:e=>Z.deleteAPIKey(e),onSuccess:(t,n)=>{e.setQueryData([`api-keys`],e=>(e??[]).filter(e=>e.id!==n)),o(i(`settings.toast.apiKeyDeleted`))},onError:e=>{o(`Failed to delete API key: ${e.message}`,`error`)}}),{data:Jt}=K({queryKey:[`printers`],queryFn:Z.getPrinters}),{data:Yt}=K({queryKey:[`haSensors`],queryFn:()=>Z.getHASensors(),enabled:ye===`plugs`}),Xt=Of(Jt?.length??0),{data:Zt,isLoading:Qt}=K({queryKey:[`notification-templates`],queryFn:Z.getNotificationTemplates}),{data:$t}=K({queryKey:[`virtual-printer-settings`],queryFn:gd.getSettings,refetchInterval:1e4}),en=$t?.status?.running??!1,{data:tn}=K({queryKey:[`spoolbuddy-devices`],queryFn:()=>xd.getDevices(),refetchInterval:15e3}),nn=tn?.length??0,rn=tn?.some(e=>e.online)??!1,{data:an}=K({queryKey:[`obico-status`],queryFn:Z.getObicoStatus,refetchInterval:15e3}),on=!!(an?.is_running&&an?.enabled),{data:sn}=K({queryKey:[`ffmpeg-status`],queryFn:Z.checkFfmpeg}),{data:cn}=K({queryKey:[`version`],queryFn:Z.getVersion}),ln=!s||d(`library:purge`),{data:un}=K({queryKey:[`library-trash-settings`],queryFn:()=>Z.getLibraryTrashSettings(),enabled:ln}),dn=q({mutationFn:e=>Z.updateLibraryTrashSettings(e),onSuccess:()=>{e.invalidateQueries({queryKey:[`library-trash-settings`]}),o(i(`settings.toast.settingsSaved`),`success`)},onError:e=>o(e.message||i(`libraryAutoPurge.saveFailed`),`error`)}),fn=e=>{un&&dn.mutate({retention_days:un.retention_days,auto_purge_enabled:un.auto_purge_enabled,auto_purge_days:un.auto_purge_days,auto_purge_include_never_printed:un.auto_purge_include_never_printed,...e})},pn=!s||d(`archives:purge`),{data:mn}=K({queryKey:[`archive-purge-settings`],queryFn:()=>Z.getArchivePurgeSettings(),enabled:pn}),hn=q({mutationFn:e=>Z.updateArchivePurgeSettings(e),onSuccess:()=>{e.invalidateQueries({queryKey:[`archive-purge-settings`]}),o(i(`settings.toast.settingsSaved`),`success`)},onError:e=>o(e.message||i(`archiveAutoPurge.saveFailed`),`error`)}),gn=e=>{mn&&hn.mutate({enabled:mn.enabled,days:mn.days,purge_stats:mn.purge_stats,...e})},{data:_n,refetch:vn,isRefetching:yn}=K({queryKey:[`updateCheck`],queryFn:Z.checkForUpdates,enabled:Nt?.check_updates!==!1,staleTime:300*1e3}),{data:bn,refetch:xn}=K({queryKey:[`updateStatus`],queryFn:Z.getUpdateStatus,refetchInterval:e=>{let t=e.state.data;return t?.status===`downloading`||t?.status===`installing`?1e3:!1}}),{data:Sn}=K({queryKey:[`mqtt-status`],queryFn:Z.getMQTTStatus,refetchInterval:ye===`network`?5e3:!1}),{data:Cn}=K({queryKey:[`github-backup-status`],queryFn:Z.getGitHubBackupStatus}),{data:wn}=K({queryKey:[`cloud-status`],queryFn:Z.getCloudStatus}),{data:Tn={advanced_auth_enabled:!1,smtp_configured:!1,local_login_enabled:!0,autologin_provider_id:null}}=K({queryKey:[`advancedAuthStatus`],queryFn:()=>Z.getAdvancedAuthStatus()}),{data:En}=K({queryKey:[`ldapStatus`],queryFn:()=>Z.getLDAPStatus()}),{data:Dn}=K({queryKey:[`twoFAStatus`],queryFn:()=>Z.get2FAStatus()}),{data:On=[]}=K({queryKey:[`oidcProvidersAll`],queryFn:()=>Z.getOIDCProvidersAll(),enabled:l}),{data:kn=[],isLoading:An}=K({queryKey:[`users`],queryFn:()=>Z.getUsers(),enabled:s&&d(`users:read`)}),{data:jn=[],isLoading:Mn}=K({queryKey:[`groups`],queryFn:()=>Z.getGroups(),enabled:s&&d(`groups:read`)}),Nn=q({mutationFn:e=>Z.createUser(e),onSuccess:()=>{e.invalidateQueries({queryKey:[`users`]}),e.invalidateQueries({queryKey:[`groups`]}),ot(!1),bt({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]}),o(i(`settings.toast.userCreated`))},onError:e=>{o(e.message,`error`)}}),Pn=q({mutationFn:({id:e,data:t})=>Z.updateUser(e,t),onSuccess:()=>{e.invalidateQueries({queryKey:[`users`]}),e.invalidateQueries({queryKey:[`groups`]}),ut(!1),ft(null),bt({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]}),o(i(`settings.toast.userUpdated`))},onError:e=>{o(e.message,`error`)}}),Fn=q({mutationFn:({id:e,deleteItems:t})=>Z.deleteUser(e,t),onSuccess:()=>{e.invalidateQueries({queryKey:[`users`]}),o(i(`settings.toast.userDeleted`)),mt(null),gt(null)},onError:e=>{o(e.message,`error`)}}),In=q({mutationFn:e=>Z.resetUserPassword({user_id:e}),onSuccess:e=>{o(e.message,`success`)},onError:e=>{o(e.message,`error`)}}),Ln=async e=>{mt(e),vt(!0);try{gt(await Z.getUserItemsCount(e))}catch{gt({archives:0,queue_items:0,library_files:0})}finally{vt(!1)}},Rn=q({mutationFn:e=>Z.deleteGroup(e),onSuccess:()=>{e.invalidateQueries({queryKey:[`groups`]}),o(i(`settings.toast.groupDeleted`))},onError:e=>{o(e.message,`error`)}}),zn=()=>{let e=Tn?.advanced_auth_enabled||!1;if(!yt.username){o(i(`settings.toast.fillRequiredFields`),`error`);return}if(e&&!yt.email){o(`Email is required when advanced authentication is enabled`,`error`);return}if(!e){if(!yt.password){o(i(`settings.toast.fillRequiredFields`),`error`);return}if(yt.password!==yt.confirmPassword){o(i(`settings.toast.passwordsDoNotMatch`),`error`);return}let e=N3(yt.password);if(e){o(i({tooShort:`settings.toast.passwordTooShort`,needsUppercase:`settings.toast.passwordNeedsUppercase`,needsLowercase:`settings.toast.passwordNeedsLowercase`,needsDigit:`settings.toast.passwordNeedsDigit`,needsSpecial:`settings.toast.passwordNeedsSpecial`}[e]),`error`);return}}Nn.mutate({username:yt.username,password:e?void 0:yt.password,email:yt.email||void 0,role:yt.role,group_ids:yt.group_ids.length>0?yt.group_ids:void 0})},Bn=e=>{if(yt.password){if(yt.password!==yt.confirmPassword){o(i(`settings.toast.passwordsDoNotMatch`),`error`);return}let e=N3(yt.password);if(e){o(i({tooShort:`settings.toast.passwordTooShort`,needsUppercase:`settings.toast.passwordNeedsUppercase`,needsLowercase:`settings.toast.passwordNeedsLowercase`,needsDigit:`settings.toast.passwordNeedsDigit`,needsSpecial:`settings.toast.passwordNeedsSpecial`}[e]),`error`);return}}let t={username:yt.username||void 0,password:yt.password||void 0,email:yt.email||void 0,role:yt.role,group_ids:yt.group_ids};t.password||delete t.password,Pn.mutate({id:e,data:t})},Vn=e=>{ft(e.id),bt({username:e.username,password:``,email:e.email||``,confirmPassword:``,role:e.role,group_ids:e.groups?.map(e=>e.id)||[]}),ut(!0)},Hn=e=>{bt(t=>({...t,group_ids:t.group_ids.includes(e)?t.group_ids.filter(t=>t!==e):[...t.group_ids,e]}))},Un=q({mutationFn:Z.applyUpdate,onSuccess:e=>{e.is_ha_addon||e.is_docker||e.is_windows_installer?o(e.message,`error`):xn()}}),[Wn,Gn]=(0,y.useState)(null),Kn=q({mutationFn:Z.testAllNotificationProviders,onSuccess:t=>{Gn(t),e.invalidateQueries({queryKey:[`notification-providers`]}),t.failed===0?o(`All ${t.tested} providers tested successfully!`,`success`):o(`${t.success}/${t.tested} providers succeeded`,t.failed>0?`error`:`success`)},onError:e=>{o(`Failed to test providers: ${e.message}`,`error`)}}),qn=q({mutationFn:async e=>{if(!zt)return{success:0,failed:0};let t=zt.filter(e=>e.enabled),n=await Promise.all(t.map(async t=>{try{return await Z.controlSmartPlug(t.id,e),{success:!0}}catch{return{success:!1}}}));return{success:n.filter(e=>e.success).length,failed:n.filter(e=>!e.success).length}},onSuccess:(t,n)=>{e.invalidateQueries({queryKey:[`smart-plugs`]}),e.invalidateQueries({queryKey:[`smart-plugs-energy`]}),t.failed===0?o(`All ${t.success} plugs turned ${n}`,`success`):o(`${t.success} plugs turned ${n}, ${t.failed} failed`,`error`)},onError:e=>{o(`Failed: ${e.message}`,`error`)}}),Jn=(0,y.useRef)(null),Yn=(0,y.useRef)(null),Xn=(0,y.useRef)(!1),Zn=(0,y.useRef)(!0),Qn=(0,y.useRef)(null);(0,y.useEffect)(()=>{if(Nt&&!A){let e={...Nt,external_url:Nt.external_url||window.location.origin};Qn.current=Nt,j(e),setTimeout(()=>{Zn.current=!1},100)}},[Nt,A]),(0,y.useEffect)(()=>{let e=Qn.current;if(!Nt||!A||!e||Nt===e)return;let t={};for(let n of Object.keys(Nt))Nt[n]!==e[n]&&A[n]===e[n]&&(t[n]=Nt[n]);Qn.current=Nt,Object.keys(t).length>0&&j(e=>e&&{...e,...t})},[Nt,A]);let $n=q({mutationFn:Z.updateSettings,onSuccess:t=>{Qn.current=t,e.setQueryData([`settings`],t),e.invalidateQueries({queryKey:[`archiveStats`]}),o(i(`settings.toast.settingsSaved`),`success`)},onError:e=>{o(`Failed to save: ${e.message}`,`error`)},onSettled:()=>{Xn.current=!1}}),er=q({mutationFn:({id:e,data:t})=>Z.updatePrinter(e,t),onSuccess:()=>{e.invalidateQueries({queryKey:[`printers`]}),o(i(`settings.toast.cameraSettingsSaved`),`success`)},onError:e=>{o(`Failed to update printer: ${e.message}`,`error`)}});(0,y.useEffect)(()=>{let e=Qn.current;if(!(Zn.current||!A||!Nt||!e)&&!(s&&!d(`settings:update`))&&(e.auto_archive!==A.auto_archive||e.save_thumbnails!==A.save_thumbnails||e.capture_finish_photo!==A.capture_finish_photo||(e.finish_photo_restore_plate??!0)!==(A.finish_photo_restore_plate??!0)||e.default_filament_cost!==A.default_filament_cost||e.currency!==A.currency||e.energy_cost_per_kwh!==A.energy_cost_per_kwh||e.energy_tracking_mode!==A.energy_tracking_mode||e.check_updates!==A.check_updates||(e.check_printer_firmware??!0)!==(A.check_printer_firmware??!0)||(e.include_beta_updates??!1)!==(A.include_beta_updates??!1)||(e.local_login_enabled??!0)!==(A.local_login_enabled??!0)||e.notification_language!==A.notification_language||(e.bed_cooled_threshold??35)!==(A.bed_cooled_threshold??35)||e.ams_humidity_good!==A.ams_humidity_good||e.ams_humidity_fair!==A.ams_humidity_fair||e.ams_temp_good!==A.ams_temp_good||e.ams_temp_fair!==A.ams_temp_fair||e.ams_history_retention_days!==A.ams_history_retention_days||e.disable_filament_warnings!==A.disable_filament_warnings||e.prefer_lowest_filament!==A.prefer_lowest_filament||(e.queue_drying_enabled??!1)!==(A.queue_drying_enabled??!1)||(e.queue_drying_block??!1)!==(A.queue_drying_block??!1)||(e.ambient_drying_enabled??!1)!==(A.ambient_drying_enabled??!1)||(e.print_drying_enabled??!1)!==(A.print_drying_enabled??!1)||(e.drying_presets??``)!==(A.drying_presets??``)||(e.ams_humidity_thresholds??``)!==(A.ams_humidity_thresholds??``)||e.per_printer_mapping_expanded!==A.per_printer_mapping_expanded||e.date_format!==A.date_format||e.time_format!==A.time_format||e.default_printer_id!==A.default_printer_id||e.ftp_retry_enabled!==A.ftp_retry_enabled||e.ftp_retry_count!==A.ftp_retry_count||e.ftp_retry_delay!==A.ftp_retry_delay||e.ftp_timeout!==A.ftp_timeout||e.mqtt_enabled!==A.mqtt_enabled||e.mqtt_broker!==A.mqtt_broker||e.mqtt_port!==A.mqtt_port||e.mqtt_username!==A.mqtt_username||e.mqtt_password!==A.mqtt_password||e.mqtt_topic_prefix!==A.mqtt_topic_prefix||e.mqtt_use_tls!==A.mqtt_use_tls||e.external_url!==A.external_url||e.ha_enabled!==A.ha_enabled||e.ha_url!==A.ha_url||e.ha_token!==A.ha_token||(e.library_archive_mode??`ask`)!==(A.library_archive_mode??`ask`)||Number(e.library_disk_warning_gb??5)!==Number(A.library_disk_warning_gb??5)||(e.camera_view_mode??`window`)!==(A.camera_view_mode??`window`)||(e.preferred_slicer??`bambu_studio`)!==(A.preferred_slicer??`bambu_studio`)||L6(e.slice_engine)!==L6(A.slice_engine)||(e.open_in_slicer??null)!==(A.open_in_slicer??null)||(e.use_slicer_api??!1)!==(A.use_slicer_api??!1)||(e.orcaslicer_api_url??``)!==(A.orcaslicer_api_url??``)||(e.slicer_stall_timeout_minutes??15)!==(A.slicer_stall_timeout_minutes??15)||(e.bambu_studio_api_url??``)!==(A.bambu_studio_api_url??``)||e.prometheus_enabled!==A.prometheus_enabled||e.prometheus_token!==A.prometheus_token||(e.user_notifications_enabled??!0)!==(A.user_notifications_enabled??!0)||(e.default_bed_levelling??`auto`)!==(A.default_bed_levelling??`auto`)||(e.default_flow_cali??`auto`)!==(A.default_flow_cali??`auto`)||(e.default_vibration_cali??!0)!==(A.default_vibration_cali??!0)||(e.default_layer_inspect??!1)!==(A.default_layer_inspect??!1)||(e.default_timelapse??!1)!==(A.default_timelapse??!1)||(e.default_nozzle_offset_cali??`auto`)!==(A.default_nozzle_offset_cali??`auto`)||(e.stagger_group_size??2)!==(A.stagger_group_size??2)||(e.stagger_interval_minutes??5)!==(A.stagger_interval_minutes??5)||(e.require_plate_clear??!1)!==(A.require_plate_clear??!1)||(e.queue_max_concurrent_uploads??4)!==(A.queue_max_concurrent_uploads??4)||(e.preheat_enabled??!1)!==(A.preheat_enabled??!1)||(e.preheat_filament_targets??``)!==(A.preheat_filament_targets??``)||(e.preheat_max_wait_seconds??900)!==(A.preheat_max_wait_seconds??900)||(e.preheat_soak_seconds??300)!==(A.preheat_soak_seconds??300)||(e.nozzle_temp_presets??``)!==(A.nozzle_temp_presets??``)||(e.bed_temp_presets??``)!==(A.bed_temp_presets??``)||(e.chamber_temp_presets??``)!==(A.chamber_temp_presets??``)||(e.fan_speed_presets??``)!==(A.fan_speed_presets??``)||(e.session_max_hours??24)!==(A.session_max_hours??24)||(e.billing_enabled??!1)!==(A.billing_enabled??!1)||(e.printer_kill_switch_enabled??!1)!==(A.printer_kill_switch_enabled??!1)||(e.finance_budget_reset_day??1)!==(A.finance_budget_reset_day??1)||(e.finance_budget_reset_timezone??`UTC`)!==(A.finance_budget_reset_timezone??`UTC`))&&!Xn.current)return Jn.current&&clearTimeout(Jn.current),Jn.current=setTimeout(()=>{if(Xn.current)return;Xn.current=!0;let e={auto_archive:A.auto_archive,save_thumbnails:A.save_thumbnails,capture_finish_photo:A.capture_finish_photo,finish_photo_restore_plate:A.finish_photo_restore_plate??!0,default_filament_cost:A.default_filament_cost,currency:A.currency,energy_cost_per_kwh:A.energy_cost_per_kwh,energy_tracking_mode:A.energy_tracking_mode,check_updates:A.check_updates,check_printer_firmware:A.check_printer_firmware,include_beta_updates:A.include_beta_updates,local_login_enabled:A.local_login_enabled,notification_language:A.notification_language,bed_cooled_threshold:A.bed_cooled_threshold,ams_humidity_good:A.ams_humidity_good,ams_humidity_fair:A.ams_humidity_fair,ams_temp_good:A.ams_temp_good,ams_temp_fair:A.ams_temp_fair,ams_history_retention_days:A.ams_history_retention_days,disable_filament_warnings:A.disable_filament_warnings,prefer_lowest_filament:A.prefer_lowest_filament,queue_drying_enabled:A.queue_drying_enabled,queue_drying_block:A.queue_drying_block,ambient_drying_enabled:A.ambient_drying_enabled,print_drying_enabled:A.print_drying_enabled,drying_presets:A.drying_presets,ams_humidity_thresholds:A.ams_humidity_thresholds,per_printer_mapping_expanded:A.per_printer_mapping_expanded,date_format:A.date_format,time_format:A.time_format,default_printer_id:A.default_printer_id,ftp_retry_enabled:A.ftp_retry_enabled,ftp_retry_count:A.ftp_retry_count,ftp_retry_delay:A.ftp_retry_delay,ftp_timeout:A.ftp_timeout,mqtt_enabled:A.mqtt_enabled,mqtt_broker:A.mqtt_broker,mqtt_port:A.mqtt_port,mqtt_username:A.mqtt_username,mqtt_password:A.mqtt_password,mqtt_topic_prefix:A.mqtt_topic_prefix,mqtt_use_tls:A.mqtt_use_tls,external_url:A.external_url,ha_enabled:A.ha_enabled,ha_url:A.ha_url,ha_token:A.ha_token,library_archive_mode:A.library_archive_mode,library_disk_warning_gb:A.library_disk_warning_gb,camera_view_mode:A.camera_view_mode,preferred_slicer:A.preferred_slicer,slice_engine:A.slice_engine,open_in_slicer:A.open_in_slicer,use_slicer_api:A.use_slicer_api,orcaslicer_api_url:A.orcaslicer_api_url,slicer_stall_timeout_minutes:A.slicer_stall_timeout_minutes,bambu_studio_api_url:A.bambu_studio_api_url,prometheus_enabled:A.prometheus_enabled,prometheus_token:A.prometheus_token,user_notifications_enabled:A.user_notifications_enabled,default_bed_levelling:A.default_bed_levelling,default_flow_cali:A.default_flow_cali,default_vibration_cali:A.default_vibration_cali,default_layer_inspect:A.default_layer_inspect,default_timelapse:A.default_timelapse,default_nozzle_offset_cali:A.default_nozzle_offset_cali,stagger_group_size:A.stagger_group_size,stagger_interval_minutes:A.stagger_interval_minutes,require_plate_clear:A.require_plate_clear,queue_max_concurrent_uploads:A.queue_max_concurrent_uploads,preheat_enabled:A.preheat_enabled,preheat_filament_targets:A.preheat_filament_targets,preheat_max_wait_seconds:A.preheat_max_wait_seconds,preheat_soak_seconds:A.preheat_soak_seconds,nozzle_temp_presets:A.nozzle_temp_presets,bed_temp_presets:A.bed_temp_presets,chamber_temp_presets:A.chamber_temp_presets,fan_speed_presets:A.fan_speed_presets,session_max_hours:A.session_max_hours,billing_enabled:A.billing_enabled,printer_kill_switch_enabled:A.printer_kill_switch_enabled,finance_budget_reset_day:A.finance_budget_reset_day,finance_budget_reset_timezone:A.finance_budget_reset_timezone};$n.mutate(e)},500),()=>{Jn.current&&clearTimeout(Jn.current)}},[A,Nt,$n,s,d,o,i]);let tr=(0,y.useCallback)((e,t)=>{if(s&&!d(`settings:update`)){o(i(`settings.toast.noPermissionUpdate`),`error`);return}j(n=>n?{...n,[e]:t}:null)},[s,d,o,i]),nr=async(e,t,n)=>{if(!t){o(i(`settings.toast.enterCameraUrl`),`error`);return}jt(t=>({...t,[e]:!0})),Ot(t=>({...t,[e]:null}));try{let r=await Z.testExternalCamera(e,t,n);Ot(t=>({...t,[e]:r})),r.success?o(r.coalesced?i(`settings.toast.cameraConnectedCoalesced`,{resolution:r.resolution||``}):i(`settings.toast.cameraConnected`,{resolution:r.resolution||``}),`success`):o(r.error||i(`settings.toast.connectionFailed`),`error`)}catch(t){let n=t instanceof Error?t.message:i(`settings.toast.testFailed`);Ot(t=>({...t,[e]:{success:!1,error:n}})),o(n,`error`)}finally{jt(t=>({...t,[e]:!1}))}},[rr,ir]=(0,y.useState)({}),ar=(0,y.useRef)({}),sr=(0,y.useRef)(new Set),[cr,lr]=(0,y.useState)({}),ur=(0,y.useRef)({}),dr=(0,y.useRef)(new Set);(0,y.useEffect)(()=>{if(Jt){let e={},t={};Jt.forEach(n=>{n.external_camera_url&&!sr.current.has(n.id)&&(e[n.id]=n.external_camera_url,sr.current.add(n.id)),n.external_camera_snapshot_url&&!dr.current.has(n.id)&&(t[n.id]=n.external_camera_snapshot_url,dr.current.add(n.id))}),Object.keys(e).length>0&&ir(t=>({...t,...e})),Object.keys(t).length>0&&lr(e=>({...e,...t}))}},[Jt]);let fr=(e,t)=>{ir(n=>({...n,[e]:t})),ar.current[e]&&clearTimeout(ar.current[e]),ar.current[e]=setTimeout(()=>{er.mutate({id:e,data:{external_camera_url:t||null}})},800)},pr=(e,t)=>{lr(n=>({...n,[e]:t})),ur.current[e]&&clearTimeout(ur.current[e]),ur.current[e]=setTimeout(()=>{er.mutate({id:e,data:{external_camera_snapshot_url:t||null}})},800)},mr=(e,t)=>{let n={};t.type!==void 0&&(n.external_camera_type=t.type||null),t.enabled!==void 0&&(n.external_camera_enabled=t.enabled),t.rotation!==void 0&&(n.camera_rotation=t.rotation),er.mutate({id:e,data:n})};if(Pt||!A)return(0,G.jsx)(`div`,{className:`p-4 md:p-8 flex justify-center`,children:(0,G.jsx)(Y,{className:`w-8 h-8 text-bambu-green animate-spin`})});let hr=VHe().map(e=>({...e,label:i(e.labelKey,e.labelFallback??e.labelKey)})),gr=H.trim().toLowerCase(),_r=gr?hr.filter(e=>e.label.toLowerCase().includes(gr)||e.keywords.toLowerCase().includes(gr)).slice(0,8):[],vr=e=>{Te(e.tab),e.subTab&&Se(e.subTab),ce(``),setTimeout(()=>{let t=document.getElementById(e.anchor);t&&(t.scrollIntoView({behavior:`smooth`,block:`start`}),t.classList.add(`ring-2`,`ring-bambu-green`),setTimeout(()=>t.classList.remove(`ring-2`,`ring-bambu-green`),1500))},50)},yr=(A?.docker_compose_dir??``).trim()||(_n?.compose_dir_detected??``),br=yr?`cd ${/\s/.test(yr)?`"${yr}"`:yr} && docker compose pull && docker compose up -d`:`docker compose pull && docker compose up -d`;return(0,G.jsx)(jd,{density:`dense`,children:(0,G.jsxs)(`div`,{className:`p-4 md:p-8`,children:[(0,G.jsxs)(`div`,{className:`mb-4 flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,G.jsx)(eu,{className:`w-7 h-7 text-bambu-green`}),i(`settings.title`)]}),(0,G.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:i(`settings.configureBambuddy`)})]}),(0,G.jsxs)(`div`,{className:`relative sm:w-72`,children:[(0,G.jsx)(Yl,{className:`w-4 h-4 text-bambu-gray absolute left-3 top-1/2 -translate-y-1/2 pointer-events-none`}),(0,G.jsx)(`input`,{type:`text`,value:H,onChange:e=>ce(e.target.value),placeholder:i(`settings.searchPlaceholder`,`Search settings…`),className:`w-full pl-9 pr-8 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`}),H&&(0,G.jsx)(`button`,{onClick:()=>ce(``),className:`absolute right-2 top-1/2 -translate-y-1/2 p-1 text-bambu-gray hover:text-white`,"aria-label":`Clear`,children:(0,G.jsx)($u,{className:`w-3.5 h-3.5`})}),_r.length>0&&(0,G.jsx)(`div`,{className:`absolute top-full left-0 right-0 mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl z-30 overflow-hidden`,children:_r.map(e=>(0,G.jsxs)(`button`,{onClick:()=>vr(e),className:`w-full px-3 py-2 text-left hover:bg-bambu-dark-tertiary transition-colors border-b border-bambu-dark-tertiary last:border-b-0`,children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:e.label}),(0,G.jsxs)(`p`,{className:`text-xs text-bambu-gray`,children:[i(`settings.tabs.${e.tab===`virtual-printer`?`virtualPrinter`:e.tab===`failure-detection`?`failureDetection`:e.tab}`),e.subTab?` › ${i(`settings.tabs.${e.subTab}`,e.subTab)}`:``]})]},e.anchor))}),gr&&_r.length===0&&(0,G.jsx)(`div`,{className:`absolute top-full left-0 right-0 mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl z-30 p-3`,children:(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray italic`,children:i(`settings.noSearchResults`,`No matching settings.`)})})]})]}),(0,G.jsxs)(`div`,{className:`flex flex-col lg:flex-row gap-4 lg:gap-6`,children:[(0,G.jsxs)(`nav`,{className:`flex flex-wrap gap-1 border-b border-bambu-dark-tertiary lg:flex-col lg:flex-nowrap lg:gap-0 lg:border-b-0 lg:border-r lg:w-48 lg:flex-shrink-0 lg:self-start lg:sticky lg:top-4`,children:[(0,G.jsxs)(`button`,{onClick:()=>Te(`general`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${ye===`general`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,G.jsx)(eu,{className:`w-4 h-4`}),i(`settings.tabs.general`)]}),(0,G.jsxs)(`button`,{onClick:()=>Te(`plugs`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${ye===`plugs`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,G.jsx)(jl,{className:`w-4 h-4`}),i(`settings.tabs.smartPlugs`),zt&&zt.length>0&&(0,G.jsx)(`span`,{className:`text-xs bg-bambu-dark-tertiary px-1.5 py-0.5 rounded-full`,children:zt.length})]}),(0,G.jsxs)(`button`,{onClick:()=>Te(`notifications`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${ye===`notifications`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,G.jsx)(Go,{className:`w-4 h-4`}),i(`settings.tabs.notifications`),Ht&&Ht.length>0&&(0,G.jsx)(`span`,{className:`text-xs bg-bambu-dark-tertiary px-1.5 py-0.5 rounded-full`,children:Ht.length})]}),(0,G.jsxs)(`button`,{onClick:()=>Te(`queue`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${ye===`queue`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,G.jsx)(Xc,{className:`w-4 h-4`}),i(`settings.tabs.queue`,`Workflow`)]}),(0,G.jsxs)(`button`,{onClick:()=>Te(`filament`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${ye===`filament`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,G.jsx)(Hs,{className:`w-4 h-4`}),i(`settings.tabs.filament`)]}),(0,G.jsxs)(`button`,{onClick:()=>Te(`network`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${ye===`network`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,G.jsx)(Yu,{className:`w-4 h-4`}),i(`settings.tabs.network`),(0,G.jsx)(`span`,{className:`w-2 h-2 rounded-full ${Sn?.enabled?`bg-green-400`:`bg-gray-500`}`})]}),(0,G.jsxs)(`button`,{onClick:()=>Te(`apikeys`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${ye===`apikeys`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,G.jsx)(Uc,{className:`w-4 h-4`}),i(`settings.tabs.apiKeys`),Wt&&Wt.length>0&&(0,G.jsx)(`span`,{className:`text-xs bg-bambu-dark-tertiary px-1.5 py-0.5 rounded-full`,children:Wt.length})]}),(0,G.jsxs)(`button`,{onClick:()=>Te(`virtual-printer`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${ye===`virtual-printer`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,G.jsx)(Fl,{className:`w-4 h-4`}),i(`settings.tabs.virtualPrinter`),(0,G.jsx)(`span`,{className:`w-2 h-2 rounded-full ${en?`bg-green-400`:`bg-gray-500`}`})]}),(0,G.jsxs)(`button`,{onClick:()=>Te(`spoolbuddy`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${ye===`spoolbuddy`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,G.jsx)(Gl,{className:`w-4 h-4`}),i(`settings.tabs.spoolbuddy`),nn>0&&(0,G.jsx)(`span`,{className:`text-xs bg-bambu-dark-tertiary px-1.5 py-0.5 rounded-full`,children:nn}),(0,G.jsx)(`span`,{className:`w-2 h-2 rounded-full ${rn?`bg-green-400`:`bg-gray-500`}`})]}),(0,G.jsxs)(`button`,{onClick:()=>Te(`failure-detection`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${ye===`failure-detection`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,G.jsx)(Kl,{className:`w-4 h-4`}),i(`settings.tabs.failureDetection`),(0,G.jsx)(`span`,{className:`w-2 h-2 rounded-full ${on?`bg-green-400`:`bg-gray-500`}`})]}),(0,G.jsxs)(`button`,{onClick:()=>Te(`users`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${ye===`users`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,G.jsx)(Bu,{className:`w-4 h-4`}),i(`settings.tabs.users`),s&&(0,G.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-green-400`})]}),(0,G.jsxs)(`button`,{onClick:()=>Te(`backup`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${ye===`backup`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,G.jsx)(Us,{className:`w-4 h-4`}),i(`settings.tabs.backup`),(0,G.jsx)(`span`,{className:`w-2 h-2 rounded-full ${wn?.is_authenticated&&Cn?.configured&&Cn?.enabled||Nt?.local_backup_enabled?`bg-green-400`:`bg-gray-500`}`})]})]}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[ye===`general`&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`a`,{href:kf(Xt,`app-settings`),target:`_blank`,rel:`noopener noreferrer`,className:`group block mb-4 lg:mb-6 rounded-xl border border-bambu-green/30 bg-gradient-to-br from-bambu-green/15 via-bambu-green/5 to-transparent hover:border-bambu-green/50 hover:from-bambu-green/20 transition-colors`,children:(0,G.jsxs)(`div`,{className:`flex flex-col md:flex-row items-start md:items-center gap-4 p-4 md:p-5`,children:[(0,G.jsx)(`div`,{className:`p-3 rounded-lg bg-bambu-green/20 text-bambu-green flex-shrink-0`,children:Xt===`business`?(0,G.jsx)(Xo,{className:`w-6 h-6`}):(0,G.jsx)(Fc,{className:`w-6 h-6`})}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`p`,{className:`text-base font-semibold text-white`,children:Xt===`business`?i(`sponsors.businessTitle`,`Bambuddy for business`):i(`sponsors.sectionTitle`,`Independent & community-funded`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-0.5`,children:Xt===`business`?i(`sponsors.businessTagline`,`You're running {{count}} printers. Priority support, commercial licensing and invoicing are available for teams and print farms.`,{count:Jt?.length??0}):i(`sponsors.tagline`,`Bambuddy is free and stays that way because people choose to support it. No VC, no cloud lock-in.`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 px-4 py-2 rounded-lg bg-bambu-green/20 text-bambu-green group-hover:bg-bambu-green/30 text-sm font-medium whitespace-nowrap self-start md:self-auto`,children:[Xt===`business`?i(`sponsors.businessCta`,`Bambuddy for business`):i(`sponsors.viewSupporters`,`View supporters`),(0,G.jsx)(tc,{className:`w-4 h-4`})]})]})}),(0,G.jsxs)(`div`,{className:`flex flex-col lg:flex-row gap-4 lg:gap-6`,children:[(0,G.jsxs)(`div`,{className:`space-y-3 flex-1 lg:max-w-xl`,children:[(0,G.jsxs)(Md,{id:`card-general`,children:[(0,G.jsx)(Nd,{children:(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(`settings.general`)})}),(0,G.jsxs)(Pd,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[(0,G.jsx)(Dc,{className:`w-4 h-4 inline mr-1`}),i(`settings.language`)]}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(`select`,{value:a.language,onChange:e=>{let t=e.target.value;if(s&&!d(`settings:update`)){o(i(`settings.toast.noPermissionUpdate`),`error`);return}a.changeLanguage(t),$n.mutate({language:t})},className:`w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer`,children:kt.map(e=>(0,G.jsxs)(`option`,{value:e.code,children:[e.nativeName,` (`,e.name,`)`]},e.code))}),(0,G.jsx)(ds,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.languageDescription`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.defaultView`)}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(`select`,{value:he,onChange:e=>Mt(e.target.value),className:`w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer`,children:$p.map(e=>(0,G.jsx)(`option`,{value:e.to,children:i(e.labelKey)},e.id))}),(0,G.jsx)(ds,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.defaultViewDescription`)})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.dateFormat`)}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsxs)(`select`,{value:A.date_format||`system`,onChange:e=>tr(`date_format`,e.target.value),className:`w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer`,children:[(0,G.jsx)(`option`,{value:`system`,children:i(`settings.systemDefault`)}),(0,G.jsx)(`option`,{value:`us`,children:i(`settings.dateFormatUs`)}),(0,G.jsx)(`option`,{value:`eu`,children:i(`settings.dateFormatEu`)}),(0,G.jsx)(`option`,{value:`iso`,children:i(`settings.dateFormatIso`)})]}),(0,G.jsx)(ds,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.timeFormat`)}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsxs)(`select`,{value:A.time_format||`system`,onChange:e=>tr(`time_format`,e.target.value),className:`w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer`,children:[(0,G.jsx)(`option`,{value:`system`,children:i(`settings.systemDefault`)}),(0,G.jsx)(`option`,{value:`12h`,children:i(`settings.timeFormat12`)}),(0,G.jsx)(`option`,{value:`24h`,children:i(`settings.timeFormat24`)})]}),(0,G.jsx)(ds,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.defaultPrinter`)}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsxs)(`select`,{value:A.default_printer_id??``,onChange:e=>tr(`default_printer_id`,e.target.value?Number(e.target.value):null),className:`w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer`,children:[(0,G.jsx)(`option`,{value:``,children:i(`settings.noDefaultPrinter`)}),Jt?.map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),(0,G.jsx)(ds,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.defaultPrinterDescription`)})]})]})]}),(0,G.jsxs)(Md,{id:`card-appearance`,children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(Sl,{className:`w-5 h-5`}),i(`settings.appearance`)]})}),(0,G.jsxs)(Pd,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,G.jsxs)(`label`,{className:`text-sm text-bambu-gray`,children:[i(`settings.theme`),`:`]}),(0,G.jsx)(`div`,{className:`flex gap-1`,children:[{id:`dark`,label:i(`settings.themeDark`)},{id:`light`,label:i(`settings.themeLight`)},{id:`system`,label:i(`settings.themeSystem`)}].map(({id:e,label:t})=>(0,G.jsx)(`button`,{onClick:()=>{x(e),o(i(`settings.toast.settingsSaved`),`success`)},className:`px-3 py-1 text-xs rounded-lg border transition-colors ${f===e?`border-bambu-green bg-bambu-green/10 text-bambu-green`:`border-gray-300 dark:border-bambu-dark-tertiary text-gray-500 dark:text-bambu-gray hover:text-gray-900 dark:hover:text-white cursor-pointer`}`,children:t},e))})]}),(0,G.jsxs)(`div`,{className:`space-y-3 p-4 rounded-lg border ${p===`dark`?`border-bambu-green bg-bambu-green/5`:`border-bambu-dark-tertiary`}`,children:[(0,G.jsxs)(`h3`,{className:`text-sm font-medium text-white flex items-center gap-2`,children:[i(`settings.darkMode`),p===`dark`&&(0,G.jsx)(`span`,{className:`text-xs text-bambu-green`,children:i(`settings.active`)})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-3 gap-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.background`)}),(0,G.jsxs)(`select`,{value:h,onChange:e=>{C(e.target.value),o(i(`settings.toast.settingsSaved`),`success`)},className:`w-full px-2 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,G.jsx)(`option`,{value:`neutral`,children:i(`settings.bgNeutral`)}),(0,G.jsx)(`option`,{value:`warm`,children:i(`settings.bgWarm`)}),(0,G.jsx)(`option`,{value:`cool`,children:i(`settings.bgCool`)}),(0,G.jsx)(`option`,{value:`oled`,children:i(`settings.bgOled`)}),(0,G.jsx)(`option`,{value:`slate`,children:i(`settings.bgSlate`)}),(0,G.jsx)(`option`,{value:`forest`,children:i(`settings.bgForest`)})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.accent`)}),(0,G.jsxs)(`select`,{value:g,onChange:e=>{w(e.target.value),o(i(`settings.toast.settingsSaved`),`success`)},className:`w-full px-2 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,G.jsx)(`option`,{value:`green`,children:i(`settings.accentGreen`)}),(0,G.jsx)(`option`,{value:`teal`,children:i(`settings.accentTeal`)}),(0,G.jsx)(`option`,{value:`blue`,children:i(`settings.accentBlue`)}),(0,G.jsx)(`option`,{value:`orange`,children:i(`settings.accentOrange`)}),(0,G.jsx)(`option`,{value:`purple`,children:i(`settings.accentPurple`)}),(0,G.jsx)(`option`,{value:`red`,children:i(`settings.accentRed`)})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.style`)}),(0,G.jsxs)(`select`,{value:m,onChange:e=>{S(e.target.value),o(i(`settings.toast.settingsSaved`),`success`)},className:`w-full px-2 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,G.jsx)(`option`,{value:`classic`,children:i(`settings.styleClassic`)}),(0,G.jsx)(`option`,{value:`glow`,children:i(`settings.styleGlow`)}),(0,G.jsx)(`option`,{value:`vibrant`,children:i(`settings.styleVibrant`)})]})]})]})]}),(0,G.jsxs)(`div`,{className:`space-y-3 p-4 rounded-lg border ${p===`light`?`border-bambu-green bg-bambu-green/5`:`border-bambu-dark-tertiary`}`,children:[(0,G.jsxs)(`h3`,{className:`text-sm font-medium text-white flex items-center gap-2`,children:[i(`settings.lightMode`),p===`light`&&(0,G.jsx)(`span`,{className:`text-xs text-bambu-green`,children:i(`settings.active`)})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-3 gap-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.background`)}),(0,G.jsxs)(`select`,{value:v,onChange:e=>{E(e.target.value),o(i(`settings.toast.settingsSaved`),`success`)},className:`w-full px-2 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,G.jsx)(`option`,{value:`neutral`,children:i(`settings.bgNeutral`)}),(0,G.jsx)(`option`,{value:`warm`,children:i(`settings.bgWarm`)}),(0,G.jsx)(`option`,{value:`cool`,children:i(`settings.bgCool`)})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.accent`)}),(0,G.jsxs)(`select`,{value:b,onChange:e=>{D(e.target.value),o(i(`settings.toast.settingsSaved`),`success`)},className:`w-full px-2 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,G.jsx)(`option`,{value:`green`,children:i(`settings.accentGreen`)}),(0,G.jsx)(`option`,{value:`teal`,children:i(`settings.accentTeal`)}),(0,G.jsx)(`option`,{value:`blue`,children:i(`settings.accentBlue`)}),(0,G.jsx)(`option`,{value:`orange`,children:i(`settings.accentOrange`)}),(0,G.jsx)(`option`,{value:`purple`,children:i(`settings.accentPurple`)}),(0,G.jsx)(`option`,{value:`red`,children:i(`settings.accentRed`)})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.style`)}),(0,G.jsxs)(`select`,{value:_,onChange:e=>{T(e.target.value),o(i(`settings.toast.settingsSaved`),`success`)},className:`w-full px-2 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,G.jsx)(`option`,{value:`classic`,children:i(`settings.styleClassic`)}),(0,G.jsx)(`option`,{value:`glow`,children:i(`settings.styleGlow`)}),(0,G.jsx)(`option`,{value:`vibrant`,children:i(`settings.styleVibrant`)})]})]})]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.themeToggleHint`)}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between pt-2 border-t border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.progressInTitle`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.progressInTitleDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:O,onChange:e=>{k(e.target.checked),o(i(`settings.toast.settingsSaved`),`success`)},className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]})]})]}),(0,G.jsxs)(Md,{id:`card-archive`,children:[(0,G.jsx)(Nd,{children:(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(`settings.archiveSettings`)})}),(0,G.jsxs)(Pd,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.autoArchivePrints`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.autoArchiveDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.auto_archive,onChange:e=>tr(`auto_archive`,e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.saveThumbnails`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.saveThumbnailsDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.save_thumbnails,onChange:e=>tr(`save_thumbnails`,e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.captureFinishPhoto`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.captureFinishPhotoDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.capture_finish_photo,onChange:e=>tr(`capture_finish_photo`,e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),A.capture_finish_photo&&(0,G.jsxs)(`div`,{className:`flex items-center justify-between pl-4 border-l-2 border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.finishPhotoRestorePlate`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.finishPhotoRestorePlateDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.finish_photo_restore_plate??!0,onChange:e=>tr(`finish_photo_restore_plate`,e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),A.capture_finish_photo&&sn&&!sn.installed&&(0,G.jsxs)(`div`,{className:`flex items-start gap-2 p-3 bg-yellow-500/10 border border-yellow-500/30 rounded-lg`,children:[(0,G.jsx)(Pu,{className:`w-5 h-5 text-yellow-500 flex-shrink-0 mt-0.5`}),(0,G.jsxs)(`div`,{className:`text-sm`,children:[(0,G.jsx)(`p`,{className:`text-yellow-500 font-medium`,children:i(`settings.ffmpegNotInstalled`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:i(`settings.ffmpegRequired`)})]})]}),pn&&mn&&(0,G.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary pt-3 mt-3 space-y-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`archiveAutoPurge.enableLabel`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`archiveAutoPurge.enableDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:mn.enabled,onChange:e=>gn({enabled:e.target.checked}),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`archiveAutoPurge.ageLabel`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`input`,{type:`number`,min:7,max:3650,disabled:!mn.enabled,value:mn.days,onChange:e=>gn({days:Math.max(7,Math.min(3650,parseInt(e.target.value||`0`,10)||0))}),className:`w-24 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none disabled:opacity-50`}),(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:i(`archiveAutoPurge.days`)})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`archiveAutoPurge.ageDescription`)})]}),(0,G.jsxs)(`label`,{className:`flex items-start gap-2 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,disabled:!mn.enabled,checked:mn.purge_stats,onChange:e=>gn({purge_stats:e.target.checked}),className:`mt-0.5 shrink-0 disabled:opacity-50`}),(0,G.jsxs)(`span`,{className:`text-sm`,children:[(0,G.jsx)(`span`,{className:`text-white block`,children:i(`archiveAutoPurge.purgeStatsLabel`)}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray block mt-0.5`,children:i(`archiveAutoPurge.purgeStatsDescription`)})]})]})]})]})]})]}),(0,G.jsxs)(`div`,{className:`space-y-3 flex-1 lg:max-w-md`,children:[(0,G.jsxs)(Md,{id:`card-camera`,children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(Hu,{className:`w-5 h-5 text-bambu-green`}),i(`settings.camera`)]})}),(0,G.jsxs)(Pd,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.cameraViewMode`)}),(0,G.jsxs)(`select`,{value:A.camera_view_mode??`window`,onChange:e=>tr(`camera_view_mode`,e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,G.jsx)(`option`,{value:`window`,children:i(`settings.newWindow`)}),(0,G.jsx)(`option`,{value:`embedded`,children:i(`settings.embeddedOverlay`)})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:A.camera_view_mode===`embedded`?i(`settings.cameraOverlayDescription`):i(`settings.cameraWindowDescription`)})]}),(0,G.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary pt-4 mt-4`,children:[(0,G.jsx)(`h3`,{className:`text-sm font-medium text-white mb-2`,children:i(`settings.externalCameras`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mb-3`,children:i(`settings.externalCamerasDescription`)}),Jt&&Jt.length>0?(0,G.jsx)(`div`,{className:`space-y-3`,children:Jt.map(e=>(0,G.jsxs)(`div`,{className:`p-3 bg-bambu-dark rounded-lg`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,G.jsx)(`span`,{className:`text-white font-medium text-sm`,children:e.name}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:e.external_camera_enabled,onChange:t=>mr(e.id,{enabled:t.target.checked}),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green`})]})]}),e.external_camera_enabled&&(0,G.jsxs)(`div`,{className:`space-y-2 mt-2`,children:[(0,G.jsx)(`input`,{type:`text`,placeholder:e.external_camera_type===`usb`?i(`settings.cameraPlaceholderUsb`):i(`settings.cameraPlaceholderUrl`),value:rr[e.id]??e.external_camera_url??``,onChange:t=>fr(e.id,t.target.value),className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsxs)(`select`,{value:e.external_camera_type||`mjpeg`,onChange:t=>mr(e.id,{type:t.target.value}),className:`flex-1 px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`,children:[(0,G.jsx)(`option`,{value:`mjpeg`,children:i(`settings.cameraTypeMjpeg`)}),(0,G.jsx)(`option`,{value:`rtsp`,children:i(`settings.cameraTypeRtsp`)}),(0,G.jsx)(`option`,{value:`snapshot`,children:i(`settings.cameraTypeSnapshot`)}),(0,G.jsx)(`option`,{value:`usb`,children:i(`settings.cameraTypeUsb`)})]}),(0,G.jsx)(Q,{size:`sm`,variant:`secondary`,onClick:()=>nr(e.id,rr[e.id]??e.external_camera_url??``,e.external_camera_type||`mjpeg`),disabled:At[e.id]||!(rr[e.id]??e.external_camera_url),children:At[e.id]?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):i(`settings.test`)})]}),Dt[e.id]&&(0,G.jsx)(`div`,{className:`text-xs flex items-center gap-1 ${Dt[e.id]?.success?`text-green-500`:`text-red-500`}`,children:Dt[e.id]?.success?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(ys,{className:`w-3 h-3`}),i(`settings.connected`),Dt[e.id]?.resolution&&` (${Dt[e.id]?.resolution})`]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Ts,{className:`w-3 h-3`}),Dt[e.id]?.error||i(`settings.toast.connectionFailed`)]})}),(e.external_camera_type===`mjpeg`||e.external_camera_type===`rtsp`||e.external_camera_type===`usb`)&&(0,G.jsxs)(`div`,{className:`space-y-1`,children:[(0,G.jsx)(`label`,{className:`text-xs text-bambu-gray`,children:i(`settings.cameraSnapshotUrl`,`Snapshot URL (optional)`)}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsx)(`input`,{type:`text`,placeholder:i(`settings.cameraSnapshotUrlPlaceholder`,`http://192.168.1.61:1984/api/frame.jpeg?src=printer`),value:cr[e.id]??e.external_camera_snapshot_url??``,onChange:t=>pr(e.id,t.target.value),className:`flex-1 px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`}),(0,G.jsx)(Q,{size:`sm`,variant:`secondary`,onClick:()=>nr(e.id,cr[e.id]??e.external_camera_snapshot_url??``,`snapshot`),disabled:At[e.id]||!(cr[e.id]??e.external_camera_snapshot_url),children:At[e.id]?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):i(`settings.test`)})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray opacity-75`,children:i(`settings.cameraSnapshotUrlHelp`,`Single-frame URL used for notification thumbnails, finish photos, timelapse and plate detection. Leave blank to capture from the live stream above. Useful for go2rtc (/api/frame.jpeg) and IP cameras with a dedicated snapshot endpoint.`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`label`,{className:`text-xs text-bambu-gray`,children:i(`settings.cameraRotation`)}),(0,G.jsxs)(`select`,{value:e.camera_rotation||0,onChange:t=>mr(e.id,{rotation:parseInt(t.target.value)}),className:`px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-xs focus:border-bambu-green focus:outline-none`,children:[(0,G.jsx)(`option`,{value:0,children:`0°`}),(0,G.jsx)(`option`,{value:90,children:`90°`}),(0,G.jsx)(`option`,{value:180,children:`180°`}),(0,G.jsx)(`option`,{value:270,children:`270°`})]})]})]})]},e.id))}):(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray italic`,children:i(`settings.noPrintersConfigured`)})]})]})]}),(0,G.jsxs)(Md,{id:`card-cost`,children:[(0,G.jsx)(Nd,{children:(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(`settings.costTracking`)})}),(0,G.jsxs)(Pd,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.currency`)}),(0,G.jsx)(`select`,{value:A.currency,onChange:e=>tr(`currency`,e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:Df.map(e=>(0,G.jsx)(`option`,{value:e.code,children:e.label},e.code))})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.defaultFilamentCost`)}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(`span`,{className:`absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray text-sm pointer-events-none`,children:Ef(A.currency)}),(0,G.jsx)(`input`,{type:`number`,step:`0.01`,min:`0`,value:A.default_filament_cost,onChange:e=>tr(`default_filament_cost`,parseFloat(e.target.value)||0),style:{paddingLeft:`${Math.max(2,Ef(A.currency).length*.6+1)}rem`},className:`w-full pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.electricityCost`)}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(`span`,{className:`absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray text-sm pointer-events-none`,children:Ef(A.currency)}),(0,G.jsx)(`input`,{type:`number`,step:`0.001`,min:`0`,value:A.energy_cost_per_kwh,onChange:e=>tr(`energy_cost_per_kwh`,parseFloat(e.target.value)||0),style:{paddingLeft:`${Math.max(2,Ef(A.currency).length*.6+1)}rem`},className:`w-full pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.energyDisplayMode`)}),(0,G.jsxs)(`select`,{value:A.energy_tracking_mode||`total`,onChange:e=>tr(`energy_tracking_mode`,e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,G.jsx)(`option`,{value:`print`,children:i(`settings.printsOnly`)}),(0,G.jsx)(`option`,{value:`total`,children:i(`settings.totalConsumption`)})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:A.energy_tracking_mode===`print`?i(`settings.energyModePrintDescription`):i(`settings.energyModeTotalDescription`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.billingEnabled`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.billingEnabledDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.billing_enabled??!1,onChange:e=>tr(`billing_enabled`,e.target.checked),className:`peer sr-only`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary rounded-full peer-checked:bg-bambu-green peer-checked:after:translate-x-5 after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border after:rounded-full after:h-5 after:w-5 after:transition-all`})]})]}),A.billing_enabled&&(0,G.jsxs)(`div`,{className:`mt-4 flex items-center justify-between gap-4 rounded-lg border border-bambu-dark-tertiary bg-bambu-dark px-4 py-3`,children:[(0,G.jsxs)(`div`,{className:`flex-1`,children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.printerKillSwitch`,`Unauthorized print kill switch`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.printerKillSwitchDescription`,`Immediately stop prints that start without authorization.`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.printer_kill_switch_enabled??!1,onChange:e=>tr(`printer_kill_switch_enabled`,e.target.checked),className:`peer sr-only`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary rounded-full peer-checked:bg-bambu-green peer-checked:after:translate-x-5 after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border after:rounded-full after:h-5 after:w-5 after:transition-all`})]})]}),A.billing_enabled&&(0,G.jsxs)(`div`,{className:`mt-4 rounded-lg border border-bambu-dark-tertiary bg-bambu-dark p-4`,children:[(0,G.jsx)(`div`,{className:`mb-3`,children:(0,G.jsxs)(`h4`,{className:`text-base font-medium text-white flex items-center gap-2`,children:[(0,G.jsx)(rs,{className:`w-4 h-4 text-bambu-green`}),i(`settings.financeBudgetReset`,`Finance Monthly Budget Reset`)]})}),(0,G.jsxs)(`div`,{className:`flex gap-4`,children:[(0,G.jsxs)(`div`,{className:`flex-1`,children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.financeBudgetResetDay`,`Reset Day`)}),(0,G.jsx)(`input`,{type:`number`,min:1,max:31,value:A.finance_budget_reset_day??1,onChange:e=>tr(`finance_budget_reset_day`,Math.max(1,Math.min(31,parseInt(e.target.value,10)||1))),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.financeBudgetResetDayHelp`,`For short months, reset uses the last day of the month.`)})]}),(0,G.jsxs)(`div`,{className:`flex-1`,children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.financeBudgetResetTimezone`,`Reset timezone`)}),(0,G.jsxs)(`select`,{value:A.finance_budget_reset_timezone??`UTC`,onChange:e=>tr(`finance_budget_reset_timezone`,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:[(0,G.jsx)(`option`,{value:`UTC`,children:`UTC`}),(0,G.jsx)(`option`,{value:`Europe/Berlin`,children:`Europe/Berlin`}),(0,G.jsx)(`option`,{value:`Europe/Vienna`,children:`Europe/Vienna`}),(0,G.jsx)(`option`,{value:`Europe/Zurich`,children:`Europe/Zurich`}),(0,G.jsx)(`option`,{value:`America/New_York`,children:`America/New_York`}),(0,G.jsx)(`option`,{value:`America/Chicago`,children:`America/Chicago`}),(0,G.jsx)(`option`,{value:`America/Denver`,children:`America/Denver`}),(0,G.jsx)(`option`,{value:`America/Los_Angeles`,children:`America/Los_Angeles`}),(0,G.jsx)(`option`,{value:`Asia/Tokyo`,children:`Asia/Tokyo`}),(0,G.jsx)(`option`,{value:`Asia/Singapore`,children:`Asia/Singapore`}),(0,G.jsx)(`option`,{value:`Australia/Sydney`,children:`Australia/Sydney`})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.financeBudgetResetTimezoneHelp`,`Budget window start is calculated in this timezone.`)})]})]})]}),A.billing_enabled&&l&&(0,G.jsxs)(`div`,{className:`mt-3`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>fe(!0),disabled:pe,children:pe?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 mr-2 animate-spin`}),i(`settings.rebuildLedgerInProgress`,`Starting...`)]}):i(`settings.rebuildLedger`,`Rebuild wallet ledger`)}),de&&(0,G.jsx)(Zd,{title:i(`settings.rebuildLedgerConfirmTitle`,`Rebuild wallet ledger?`),message:i(`settings.rebuildLedgerConfirmMessage`,`This will rebuild the wallet ledger to repair historical balance values. Run this only if you know what you are doing.`),confirmText:i(`common.run`,`Run`),cancelText:i(`common.cancel`,`Cancel`),isLoading:pe,loadingText:i(`common.running`,`Running`),variant:`warning`,onCancel:()=>fe(!1),onConfirm:async()=>{me(!0);try{await Z.rebuildBalanceLedger(),o(i(`settings.rebuildLedgerStarted`,`Ledger rebuild started`),`success`),fe(!1)}catch(e){o(e.message||`Failed to start ledger rebuild`,`error`)}finally{me(!1)}}})]})]})]})]}),(0,G.jsxs)(Md,{id:`card-filemanager`,children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(lc,{className:`w-5 h-5 text-bambu-green`}),i(`settings.fileManager`)]})}),(0,G.jsxs)(Pd,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.createArchiveEntry`)}),(0,G.jsxs)(`select`,{value:A.library_archive_mode??`ask`,onChange:e=>tr(`library_archive_mode`,e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,G.jsx)(`option`,{value:`always`,children:i(`settings.archiveMode.always`)}),(0,G.jsx)(`option`,{value:`never`,children:i(`settings.archiveMode.never`)}),(0,G.jsx)(`option`,{value:`ask`,children:i(`settings.archiveMode.ask`)})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.createArchiveEntryDescription`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.lowDiskSpaceWarning`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`input`,{type:`number`,min:`0.5`,max:`100`,step:`0.5`,value:A.library_disk_warning_gb??5,onChange:e=>tr(`library_disk_warning_gb`,parseFloat(e.target.value)||5),className:`w-24 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:`GB`})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.lowDiskSpaceDescription`)})]}),ln&&un&&(0,G.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary pt-3 mt-3 space-y-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`libraryAutoPurge.enableLabel`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`libraryAutoPurge.enableDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:un.auto_purge_enabled,onChange:e=>fn({auto_purge_enabled:e.target.checked}),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`libraryAutoPurge.ageLabel`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`input`,{type:`number`,min:7,max:3650,disabled:!un.auto_purge_enabled,value:un.auto_purge_days,onChange:e=>fn({auto_purge_days:Math.max(7,Math.min(3650,parseInt(e.target.value||`0`,10)||0))}),className:`w-24 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none disabled:opacity-50`}),(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:i(`libraryAutoPurge.days`)})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`libraryAutoPurge.ageDescription`)})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-white cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,disabled:!un.auto_purge_enabled,checked:un.auto_purge_include_never_printed,onChange:e=>fn({auto_purge_include_never_printed:e.target.checked}),className:`rounded border-gray-300 disabled:opacity-50`}),i(`libraryAutoPurge.includeNeverPrinted`)]})]})]})]}),(0,G.jsxs)(Md,{id:`card-data`,children:[(0,G.jsx)(Nd,{children:(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(`settings.dataManagement`)})}),(0,G.jsxs)(Pd,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.clearNotificationLogs`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.clearNotificationLogsDescription`)})]}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:()=>He(!0),children:[(0,G.jsx)(ju,{className:`w-4 h-4`}),i(`common.clear`)]})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.resetUiPreferences`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.resetUiPreferencesDescription`)})]}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:()=>We(!0),children:[(0,G.jsx)(ju,{className:`w-4 h-4`}),i(`settings.reset`)]})]}),(0,G.jsxs)(`div`,{className:`pt-4 border-t border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.storageUsage`,`Storage Usage`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.storageUsageDescription`,`Breakdown of data usage by category`)})]}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:Rt,disabled:Lt||rt,children:[(0,G.jsx)(zl,{className:`w-4 h-4 ${Lt||rt?`animate-spin`:``}`}),i(`common.refresh`,`Refresh`)]})]}),(0,G.jsx)(`div`,{className:`mt-3`,children:It?(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-bambu-gray`,children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),i(`common.loading`,`Loading`)]}):Ft?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`w-full h-3 bg-bambu-dark rounded-full overflow-hidden flex`,children:Ft.categories.filter(e=>e.bytes>0).map((e,t)=>(0,G.jsx)(`div`,{className:`${B6(e.key,t)} h-full`,style:{width:`${e.percent_of_total}%`},title:`${e.label}: ${e.formatted}`},e.key))}),(0,G.jsx)(`div`,{className:`mt-3 flex flex-wrap gap-3`,children:Ft.categories.filter(e=>e.bytes>0).map((e,t)=>(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-xs`,children:[(0,G.jsx)(`span`,{className:`w-3 h-3 rounded-full ${B6(e.key,t)}`}),(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:e.label}),(0,G.jsx)(`span`,{className:`text-white`,children:e.formatted}),(0,G.jsxs)(`span`,{className:`text-bambu-gray`,children:[`(`,e.percent_of_total.toFixed(1),`%)`]})]},e.key))}),(0,G.jsxs)(`div`,{className:`mt-2 text-xs text-bambu-gray`,children:[i(`settings.storageUsageTotal`,`Total`),`: `,(0,G.jsx)(`span`,{className:`text-white`,children:Ft.total_formatted}),Ft.scan_errors>0&&(0,G.jsxs)(`span`,{className:`ml-2 text-amber-700 dark:text-amber-400`,children:[i(`settings.storageUsageErrors`,`Scan errors`),`: `,Ft.scan_errors]})]}),Ft.other_breakdown?.length>0&&(0,G.jsxs)(`div`,{className:`mt-4`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:i(`settings.storageUsageOtherBreakdown`,`Other breakdown`)}),(0,G.jsx)(`div`,{className:`space-y-2`,children:Ft.other_breakdown.map(e=>(0,G.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-white`,children:e.label}),(0,G.jsx)(`span`,{className:`px-2 py-0.5 rounded-full border ${e.kind===`system`?`border-slate-500 text-slate-300`:`border-bambu-green text-bambu-green`}`,children:e.kind===`system`?i(`settings.storageUsageSystem`,`System`):i(`settings.storageUsageData`,`Data`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray`,children:[(0,G.jsx)(`span`,{className:`text-white`,children:e.formatted}),(0,G.jsxs)(`span`,{children:[`(`,e.percent_of_total.toFixed(1),`%)`]})]})]},`${e.bucket}-${e.kind}`))})]})]}):(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.storageUsageUnavailable`,`Storage usage data is unavailable`)})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between pt-4 border-t border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.backupRestore`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.backupRestoreDescription`)})]}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:()=>Te(`backup`),children:[(0,G.jsx)(Us,{className:`w-4 h-4`}),i(`settings.goToBackup`)]})]})]})]})]}),(0,G.jsxs)(`div`,{className:`space-y-3 flex-1 lg:max-w-sm`,children:[(0,G.jsxs)(Md,{id:`card-updates`,children:[(0,G.jsx)(Nd,{children:(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(`settings.updates`)})}),(0,G.jsxs)(Pd,{className:`space-y-3`,children:[(0,G.jsx)(`p`,{className:`text-xs font-medium text-bambu-gray uppercase tracking-wider`,children:i(`settings.printerFirmware`)}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.checkPrinterFirmware`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.checkFirmwareDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.check_printer_firmware??!0,onChange:e=>tr(`check_printer_firmware`,e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,G.jsx)(`div`,{className:`border-t border-bambu-dark-tertiary pt-4`,children:(0,G.jsx)(`p`,{className:`text-xs font-medium text-bambu-gray uppercase tracking-wider mb-4`,children:i(`settings.bambuddySoftware`)})}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.checkForUpdatesLabel`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.autoCheckDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.check_updates,onChange:e=>tr(`check_updates`,e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between ${A.check_updates?``:`opacity-50`}`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.includeBetaUpdates`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.includeBetaUpdatesDesc`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.include_beta_updates??!1,onChange:e=>tr(`include_beta_updates`,e.target.checked),disabled:!A.check_updates,className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.currentVersion`)}),(0,G.jsxs)(`p`,{className:`text-sm text-bambu-gray`,children:[`v`,cn?.version||`...`]})]}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:()=>vn(),disabled:yn,children:[yn?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(zl,{className:`w-4 h-4`}),i(`settings.checkNow`)]})]}),_n?.update_available?(0,G.jsxs)(`div`,{className:`mt-4 p-3 bg-bambu-green/10 border border-bambu-green/30 rounded-lg`,children:[(0,G.jsxs)(`div`,{className:`flex items-start justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`p`,{className:`text-bambu-green font-medium`,children:[`Update available: v`,_n.latest_version]}),_n.release_name&&_n.release_name!==_n.latest_version&&(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:_n.release_name})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[_n.release_notes&&(0,G.jsx)(`button`,{onClick:()=>Je(!0),className:`text-bambu-gray hover:text-white transition-colors text-sm underline`,children:i(`settings.releaseNotes`)}),_n.release_url&&(0,G.jsx)(`a`,{href:_n.release_url,target:`_blank`,rel:`noopener noreferrer`,className:`text-bambu-gray hover:text-white transition-colors`,title:i(`settings.viewReleaseOnGitHub`),children:(0,G.jsx)(tc,{className:`w-4 h-4`})})]})]}),bn?.status===`downloading`||bn?.status===`installing`?(0,G.jsxs)(`div`,{className:`mt-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-bambu-gray`,children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),(0,G.jsx)(`span`,{children:bn.message})]}),(0,G.jsx)(`div`,{className:`mt-2 w-full bg-bambu-dark-tertiary rounded-full h-2`,children:(0,G.jsx)(`div`,{className:`bg-bambu-green h-2 rounded-full transition-all duration-300`,style:{width:`${bn.progress}%`}})})]}):bn?.status===`complete`?(0,G.jsx)(`div`,{className:`mt-3 p-2 bg-bambu-green/20 rounded text-sm text-bambu-green`,children:bn.message}):bn?.status===`error`?(0,G.jsx)(`div`,{className:`mt-3 p-2 bg-red-100 dark:bg-red-500/20 rounded text-sm text-red-700 dark:text-red-400`,children:bn.error||bn.message}):_n?.is_ha_addon?(0,G.jsx)(`div`,{className:`mt-3 p-3 bg-bambu-dark-tertiary rounded-lg`,children:(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.updateViaHomeAssistant`)})}):_n?.is_docker?(0,G.jsxs)(`div`,{className:`mt-3 p-3 bg-bambu-dark-tertiary rounded-lg`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mb-2`,children:i(`settings.updateViaDocker`)}),(0,G.jsxs)(`div`,{className:`flex items-start gap-1`,children:[(0,G.jsx)(`code`,{className:`flex-1 block text-xs bg-bambu-dark p-2 rounded text-bambu-green font-mono break-all select-all`,children:br}),(0,G.jsx)(eW,{value:br,titleKey:`settings.copyUpdateCommand`,copiedTitleKey:`printers.copied`,className:`ml-0 p-2 rounded hover:bg-bambu-dark text-bambu-gray hover:text-white transition-colors flex-shrink-0`,iconClassName:`w-4 h-4`})]}),(0,G.jsxs)(`label`,{className:`block mt-3`,children:[(0,G.jsx)(`span`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.composeDirectory`)}),(0,G.jsx)(`input`,{type:`text`,value:A?.docker_compose_dir??``,onChange:e=>tr(`docker_compose_dir`,e.target.value),placeholder:_n?.compose_dir_detected||`/opt/bambuddy`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded text-sm text-white font-mono placeholder:text-bambu-gray/60 focus:outline-none focus:border-bambu-green`}),(0,G.jsx)(`span`,{className:`block text-xs text-bambu-gray mt-1`,children:i(`settings.composeDirectoryHint`)})]})]}):_n?.update_method===`windows_installer`?(0,G.jsxs)(`div`,{className:`mt-3 p-3 bg-bambu-dark-tertiary rounded-lg`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mb-3`,children:i(`settings.updateViaWindowsInstaller`)}),(0,G.jsxs)(`a`,{href:_n.installer_download_url||_n.release_url||`https://github.com/maziggy/bambuddy/releases/tag/v${_n.latest_version}`,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center justify-center font-medium rounded-lg transition-colors focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-offset-bambu-dark disabled:opacity-50 bg-bambu-green hover:bg-bambu-green-light text-white focus:ring-bambu-green px-4 py-2 text-sm gap-2 min-h-[44px] md:min-h-0`,children:[(0,G.jsx)(Js,{className:`w-4 h-4`}),i(`settings.downloadWindowsInstaller`,{version:_n.latest_version})]})]}):(0,G.jsxs)(Q,{className:`mt-3`,onClick:()=>Un.mutate(),disabled:Un.isPending,children:[Un.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Js,{className:`w-4 h-4`}),i(`settings.installUpdate`)]})]}):_n?.error?(0,G.jsx)(`div`,{className:`mt-2 p-2 bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30 rounded text-sm text-red-700 dark:text-red-400`,children:i(`settings.failedToCheckUpdates`,{error:_n.error})}):_n&&!_n.update_available?(0,G.jsx)(`p`,{className:`mt-2 text-sm text-bambu-gray`,children:i(`settings.latestVersionRunning`)}):null]})]})]}),(0,G.jsx)(hHe,{})]})]})]}),ye===`network`&&A&&(0,G.jsxs)(`div`,{className:`flex flex-col lg:flex-row gap-6`,children:[(0,G.jsxs)(`div`,{className:`flex-1 lg:max-w-xl space-y-3`,children:[(0,G.jsxs)(Md,{id:`card-externalurl`,children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(Dc,{className:`w-5 h-5 text-blue-600 dark:text-blue-400`}),i(`settings.externalUrl`)]})}),(0,G.jsxs)(Pd,{className:`space-y-3`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.externalUrlDescription`)}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.bambuddyUrl`)}),(0,G.jsx)(`input`,{type:`text`,value:A.external_url??``,onChange:e=>tr(`external_url`,e.target.value),placeholder:`http://192.168.1.100:8000`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.externalUrlHint`)})]})]})]}),(0,G.jsxs)(Md,{id:`card-ftpretry`,children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(zl,{className:`w-5 h-5 text-blue-600 dark:text-blue-400`}),i(`settings.ftpRetry`)]})}),(0,G.jsxs)(Pd,{className:`space-y-3`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.ftpRetryDescription`)}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.enableRetry`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.autoRetryDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.ftp_retry_enabled??!0,onChange:e=>tr(`ftp_retry_enabled`,e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),A.ftp_retry_enabled&&(0,G.jsxs)(`div`,{className:`space-y-3 pt-2 border-t border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.retryAttempts`)}),(0,G.jsxs)(`div`,{className:`relative w-44`,children:[(0,G.jsx)(`select`,{value:A.ftp_retry_count??3,onChange:e=>tr(`ftp_retry_count`,parseInt(e.target.value)),className:`w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer`,children:[1,2,3,4,5,6,7,8,9,10].map(e=>(0,G.jsx)(`option`,{value:e,children:i(`settings.time`,{count:e})},e))}),(0,G.jsx)(ds,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.retryDelay`)}),(0,G.jsxs)(`div`,{className:`relative w-44`,children:[(0,G.jsx)(`select`,{value:A.ftp_retry_delay??2,onChange:e=>tr(`ftp_retry_delay`,parseInt(e.target.value)),className:`w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer`,children:[1,2,3,5,10,15,20,30].map(e=>(0,G.jsx)(`option`,{value:e,children:i(`settings.second`,{count:e})},e))}),(0,G.jsx)(ds,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.connectionTimeout`)}),(0,G.jsxs)(`div`,{className:`relative w-44`,children:[(0,G.jsx)(`select`,{value:A.ftp_timeout??30,onChange:e=>tr(`ftp_timeout`,parseInt(e.target.value)),className:`w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer`,children:[10,15,20,30,45,60,90,120,180,300].map(e=>(0,G.jsx)(`option`,{value:e,children:i(`settings.nSeconds`,{count:e})},e))}),(0,G.jsx)(ds,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.increaseForWeakWifi`)})]})]})]})]})]}),(0,G.jsxs)(`div`,{className:`flex-1 lg:max-w-xl space-y-3`,children:[(0,G.jsxs)(Md,{id:`card-ha`,children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(Lc,{className:`w-5 h-5 text-bambu-green`}),i(`settings.homeAssistant`)]}),A.ha_enabled&&Ct&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`w-2.5 h-2.5 rounded-full ${Ct.success?`bg-green-400`:`bg-red-400`}`}),(0,G.jsx)(`span`,{className:`text-sm ${Ct.success?`text-green-700 dark:text-green-400`:`text-red-700 dark:text-red-400`}`,children:Ct.success?i(`settings.connected`):i(`settings.disconnected`)})]})]})}),(0,G.jsxs)(Pd,{className:`space-y-3`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.homeAssistantFullDescription`)}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex-1`,children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.enableHomeAssistant`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.homeAssistantDescription`)}),A.ha_env_managed&&(0,G.jsxs)(`div`,{className:`flex items-center gap-1 mt-1`,children:[(0,G.jsx)(el,{className:`w-3 h-3 text-bambu-green`}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-green`,children:i(`settings.autoEnabledViaEnv`)})]})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.ha_enabled??!1,onChange:e=>tr(`ha_enabled`,e.target.checked),disabled:A.ha_env_managed,className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green ${A.ha_env_managed?`opacity-60 cursor-not-allowed`:``}`})]})]}),A.ha_enabled&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[i(`settings.homeAssistantUrl`),A.ha_url_from_env&&(0,G.jsx)(`span`,{className:`ml-2 text-xs text-bambu-green`,children:i(`settings.environmentManagedLabel`)})]}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(`input`,{type:`text`,value:A.ha_url??``,onChange:e=>tr(`ha_url`,e.target.value),placeholder:`http://192.168.1.100:8123`,disabled:A.ha_url_from_env,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none ${A.ha_url_from_env?`opacity-60 cursor-not-allowed`:``}`}),A.ha_url_from_env&&(0,G.jsx)(el,{className:`absolute right-3 top-2.5 w-4 h-4 text-bambu-gray`})]}),A.ha_url_from_env&&(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.urlFromEnvReadOnly`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[i(`settings.longLivedAccessToken`),A.ha_token_from_env&&(0,G.jsx)(`span`,{className:`ml-2 text-xs text-bambu-green`,children:i(`settings.environmentManagedLabel`)})]}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(`input`,{type:`password`,value:A.ha_token??``,onChange:e=>tr(`ha_token`,e.target.value),placeholder:`eyJ0eXAiOiJKV1QiLC...`,disabled:A.ha_token_from_env,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none ${A.ha_token_from_env?`opacity-60 cursor-not-allowed`:``}`}),A.ha_token_from_env&&(0,G.jsx)(el,{className:`absolute right-3 top-2.5 w-4 h-4 text-bambu-gray`})]}),A.ha_token_from_env?(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.tokenFromEnvReadOnly`)}):(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.haTokenHint`)})]}),A.ha_url&&A.ha_token&&(0,G.jsx)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,disabled:Tt,onClick:async()=>{Et(!0),wt(null);try{wt(await Z.testHAConnection(A.ha_url,A.ha_token))}catch(e){wt({success:!1,message:null,error:e instanceof Error?e.message:i(`common.unknownError`)})}finally{Et(!1)}},children:[Tt?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Yu,{className:`w-4 h-4`}),i(`settings.testConnection`)]})})]})]})]}),(0,G.jsxs)(Md,{id:`card-mqtt`,children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(Yu,{className:`w-5 h-5 text-blue-600 dark:text-blue-400`}),i(`settings.mqttPublishing`)]}),Sn?.enabled&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`w-2.5 h-2.5 rounded-full ${Sn.connected?`bg-green-400`:`bg-red-400`}`}),(0,G.jsx)(`span`,{className:`text-sm ${Sn.connected?`text-green-700 dark:text-green-400`:`text-red-700 dark:text-red-400`}`,children:Sn.connected?i(`settings.connected`):i(`settings.disconnected`)})]})]})}),(0,G.jsxs)(Pd,{className:`space-y-3`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.mqttDescription`)}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.enableMqtt`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.mqttEnableDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.mqtt_enabled??!1,onChange:e=>tr(`mqtt_enabled`,e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),A.mqtt_enabled&&(0,G.jsxs)(`div`,{className:`space-y-3 pt-2 border-t border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.brokerHostname`)}),(0,G.jsx)(`input`,{type:`text`,value:A.mqtt_broker??``,onChange:e=>tr(`mqtt_broker`,e.target.value),placeholder:`mqtt.example.com or 192.168.1.100`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,G.jsxs)(`div`,{className:`flex items-end gap-4`,children:[(0,G.jsxs)(`div`,{className:`flex-1`,children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.port`)}),(0,G.jsx)(`input`,{type:`number`,min:`1`,max:`65535`,value:A.mqtt_port??1883,onChange:e=>tr(`mqtt_port`,Math.min(65535,Math.max(1,parseInt(e.target.value)||1883))),className:`w-24 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-3 pb-2`,children:[(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.mqtt_use_tls??!1,onChange:e=>{let t=e.target.checked;tr(`mqtt_use_tls`,t);let n=A.mqtt_port??1883;t&&n===1883?tr(`mqtt_port`,8883):!t&&n===8883&&tr(`mqtt_port`,1883)},className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]}),(0,G.jsx)(`span`,{className:`text-white text-sm`,children:i(`settings.useTls`)})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.usernameOptional`)}),(0,G.jsx)(`input`,{type:`text`,value:A.mqtt_username??``,onChange:e=>tr(`mqtt_username`,e.target.value),placeholder:i(`settings.leaveEmptyForAnonymous`),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.passwordOptional`)}),(0,G.jsx)(`input`,{type:`password`,value:A.mqtt_password??``,onChange:e=>tr(`mqtt_password`,e.target.value),placeholder:i(`settings.leaveEmptyForAnonymous`),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.topicPrefix`)}),(0,G.jsx)(`input`,{type:`text`,value:A.mqtt_topic_prefix??`bambuddy`,onChange:e=>tr(`mqtt_topic_prefix`,e.target.value),placeholder:`bambuddy`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.topicPrefixHint`,{prefix:A.mqtt_topic_prefix||`bambuddy`})})]}),Sn&&(0,G.jsx)(`div`,{className:`pt-3 mt-3 border-t border-bambu-dark-tertiary`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,G.jsx)(`span`,{className:`w-2 h-2 rounded-full ${Sn.connected?`bg-green-400`:`bg-red-400`}`}),(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:Sn.connected?(0,G.jsxs)(G.Fragment,{children:[i(`settings.mqttConnectedTo`),` `,(0,G.jsxs)(`span`,{className:`text-white`,children:[Sn.broker,`:`,Sn.port]})]}):i(`settings.spoolmanDisconnected`)})]})})]})]})]})]}),(0,G.jsx)(`div`,{className:`flex-1 lg:max-w-md space-y-3`,children:(0,G.jsxs)(Md,{id:`card-prometheus`,children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(Nu,{className:`w-5 h-5 text-orange-600 dark:text-orange-400`}),i(`settings.prometheusMetrics`)]})}),(0,G.jsxs)(Pd,{className:`space-y-3`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.prometheusEndpointDescription`)}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.enableMetricsEndpoint`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.prometheusDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.prometheus_enabled??!1,onChange:e=>tr(`prometheus_enabled`,e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),A.prometheus_enabled&&(0,G.jsxs)(`div`,{className:`space-y-3 pt-2 border-t border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.bearerTokenOptional`)}),(0,G.jsx)(`input`,{type:`password`,value:A.prometheus_token??``,onChange:e=>tr(`prometheus_token`,e.target.value),placeholder:i(`settings.leaveEmptyForNoAuth`),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.bearerTokenHint`)})]}),(0,G.jsxs)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:[(0,G.jsx)(`p`,{className:`text-sm text-white mb-2`,children:i(`settings.availableMetrics`)}),(0,G.jsxs)(`div`,{className:`text-xs text-bambu-gray space-y-1`,children:[(0,G.jsxs)(`p`,{children:[(0,G.jsx)(`code`,{className:`text-orange-700 dark:text-orange-400`,children:`bambuddy_printer_connected`}),` - `,i(`settings.metricsConnectionStatus`)]}),(0,G.jsxs)(`p`,{children:[(0,G.jsx)(`code`,{className:`text-orange-700 dark:text-orange-400`,children:`bambuddy_printer_state`}),` - `,i(`settings.metricsPrinterState`)]}),(0,G.jsxs)(`p`,{children:[(0,G.jsx)(`code`,{className:`text-orange-700 dark:text-orange-400`,children:`bambuddy_print_progress`}),` - `,i(`settings.metricsPrintProgress`)]}),(0,G.jsxs)(`p`,{children:[(0,G.jsx)(`code`,{className:`text-orange-700 dark:text-orange-400`,children:`bambuddy_bed_temp_celsius`}),` - `,i(`settings.metricsBedTemp`)]}),(0,G.jsxs)(`p`,{children:[(0,G.jsx)(`code`,{className:`text-orange-700 dark:text-orange-400`,children:`bambuddy_nozzle_temp_celsius`}),` - `,i(`settings.metricsNozzleTemp`)]}),(0,G.jsxs)(`p`,{children:[(0,G.jsx)(`code`,{className:`text-orange-700 dark:text-orange-400`,children:`bambuddy_prints_total`}),` - `,i(`settings.metricsPrintsTotal`)]}),(0,G.jsx)(`p`,{className:`text-bambu-gray/70 italic`,children:i(`settings.metricsMore`)})]})]})]})]})]})})]}),Ct&&(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50`,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg p-6 max-w-md w-full mx-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3 mb-4`,children:[Ct.success?(0,G.jsx)(ys,{className:`w-8 h-8 text-green-600 dark:text-green-400`}):(0,G.jsx)(Ts,{className:`w-8 h-8 text-red-600 dark:text-red-400`}),(0,G.jsx)(`h3`,{className:`text-lg font-medium text-white`,children:Ct.success?i(`settings.connectionSuccessful`):i(`settings.connectionFailed`)})]}),(0,G.jsx)(`p`,{className:`text-bambu-gray mb-6`,children:Ct.success?Ct.message||i(`settings.haConnectionSuccess`):Ct.error||i(`settings.haConnectionFailed`)}),(0,G.jsx)(`div`,{className:`flex justify-end`,children:(0,G.jsx)(Q,{variant:`primary`,onClick:()=>wt(null),children:i(`settings.ok`)})})]})}),ye===`plugs`&&(0,G.jsxs)(`div`,{id:`card-plugs`,children:[(0,G.jsxs)(`div`,{className:`flex items-start justify-between mb-6`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(jl,{className:`w-5 h-5 text-bambu-green`}),i(`settings.smartPlugs`)]}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:i(`settings.smartPlugsDescription`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 pt-1 shrink-0`,children:[zt&&zt.filter(e=>e.enabled).length>1&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,className:`whitespace-nowrap`,onClick:()=>Ke(`on`),disabled:qn.isPending,title:i(`settings.turnAllPlugsOn`),children:[qn.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Pl,{className:`w-4 h-4 text-bambu-green`}),i(`settings.allOn`)]}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,className:`whitespace-nowrap`,onClick:()=>Ke(`off`),disabled:qn.isPending,title:i(`settings.turnAllPlugsOff`),children:[qn.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Nl,{className:`w-4 h-4 text-red-600 dark:text-red-400`}),i(`settings.allOff`)]})]}),(0,G.jsxs)(Q,{className:`whitespace-nowrap`,onClick:()=>{L(null),F(!0)},children:[(0,G.jsx)(Ml,{className:`w-4 h-4`}),i(`settings.addSmartPlug`)]})]})]}),zt&&zt.length>0&&(0,G.jsxs)(Md,{className:`mb-6`,children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(td,{className:`w-4 h-4 text-yellow-600 dark:text-yellow-400`}),i(`settings.energySummary`),W&&(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin text-bambu-gray ml-2`})]})}),(0,G.jsx)(Pd,{children:Vt?(0,G.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-4`,children:[(0,G.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray text-xs mb-1`,children:[(0,G.jsx)(td,{className:`w-3 h-3`}),i(`settings.currentPower`)]}),(0,G.jsxs)(`div`,{className:`text-xl font-bold text-white`,children:[Vt.totalPower.toFixed(1),(0,G.jsx)(`span`,{className:`text-sm font-normal text-bambu-gray ml-1`,children:`W`})]}),(0,G.jsx)(`div`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.plugsOnline`,{reachable:Vt.reachableCount,total:Vt.totalPlugs})})]}),(0,G.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray text-xs mb-1`,children:[(0,G.jsx)(rs,{className:`w-3 h-3`}),i(`settings.today`)]}),(0,G.jsxs)(`div`,{className:`text-xl font-bold text-white`,children:[Vt.totalToday.toFixed(3),(0,G.jsx)(`span`,{className:`text-sm font-normal text-bambu-gray ml-1`,children:`kWh`})]}),(A?.energy_cost_per_kwh??0)>0&&(0,G.jsxs)(`div`,{className:`text-xs text-bambu-gray mt-1`,children:[`~`,(Vt.totalToday*(A?.energy_cost_per_kwh??0)).toFixed(2),` `,Ef(A?.currency||`USD`)]})]}),(0,G.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray text-xs mb-1`,children:[(0,G.jsx)(Nu,{className:`w-3 h-3`}),i(`settings.yesterday`)]}),(0,G.jsxs)(`div`,{className:`text-xl font-bold text-white`,children:[Vt.totalYesterday.toFixed(3),(0,G.jsx)(`span`,{className:`text-sm font-normal text-bambu-gray ml-1`,children:`kWh`})]}),(A?.energy_cost_per_kwh??0)>0&&(0,G.jsxs)(`div`,{className:`text-xs text-bambu-gray mt-1`,children:[`~`,(Vt.totalYesterday*(A?.energy_cost_per_kwh??0)).toFixed(2),` `,Ef(A?.currency||`USD`)]})]}),(0,G.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray text-xs mb-1`,children:[(0,G.jsx)(Gs,{className:`w-3 h-3`}),i(`settings.total`)]}),(0,G.jsxs)(`div`,{className:`text-xl font-bold text-white`,children:[Vt.totalLifetime.toFixed(1),(0,G.jsx)(`span`,{className:`text-sm font-normal text-bambu-gray ml-1`,children:`kWh`})]}),(A?.energy_cost_per_kwh??0)>0&&(0,G.jsxs)(`div`,{className:`text-xs text-bambu-gray mt-1`,children:[`~`,(Vt.totalLifetime*(A?.energy_cost_per_kwh??0)).toFixed(2),` `,Ef(A?.currency||`USD`)]})]})]}):W?null:(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.enablePlugsForSummary`)})})]}),Bt?(0,G.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,G.jsx)(Y,{className:`w-8 h-8 text-bambu-green animate-spin`})}):zt&&zt.length>0?(0,G.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4`,children:zt.map(e=>(0,G.jsx)(jVe,{plug:e,onEdit:e=>{L(e),F(!0)}},e.id))}):(0,G.jsx)(Md,{children:(0,G.jsx)(Pd,{className:`py-12`,children:(0,G.jsxs)(`div`,{className:`text-center text-bambu-gray`,children:[(0,G.jsx)(jl,{className:`w-16 h-16 mx-auto mb-4 opacity-30`}),(0,G.jsx)(`p`,{className:`text-lg font-medium text-white mb-2`,children:i(`settings.noSmartPlugsTitle`)}),(0,G.jsx)(`p`,{className:`text-sm mb-4`,children:i(`settings.noSmartPlugsDescription`)}),(0,G.jsxs)(Q,{onClick:()=>{L(null),F(!0)},children:[(0,G.jsx)(Ml,{className:`w-4 h-4`}),i(`settings.addFirstSmartPlug`)]})]})})}),(0,G.jsxs)(`div`,{className:`mt-8`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-4`,children:[(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(Sc,{className:`w-5 h-5 text-bambu-green`}),i(`haSensors.sectionTitle`)]}),(0,G.jsxs)(Q,{className:`whitespace-nowrap`,disabled:!Jt?.length,onClick:()=>{V(null),z(!0)},children:[(0,G.jsx)(Ml,{className:`w-4 h-4`}),i(`haSensors.add`)]})]}),Yt&&Yt.length>0?(0,G.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4`,children:Yt.map(e=>{let t=Jt?.find(t=>t.id===e.printer_id);return(0,G.jsx)(Md,{children:(0,G.jsxs)(Pd,{className:`py-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsx)(`div`,{className:`text-white font-medium truncate`,children:e.name}),(0,G.jsx)(`div`,{className:`text-xs text-bambu-gray truncate`,children:e.entity_id}),(0,G.jsx)(`div`,{className:`text-xs text-bambu-gray mt-1`,children:t?.name??i(`haSensors.unknownPrinter`)})]}),(0,G.jsx)(Q,{size:`sm`,variant:`secondary`,onClick:()=>{V(e),z(!0)},children:i(`common.edit`)})]}),(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-1 mt-3`,children:[e.block_print&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 text-xs rounded bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-400`,children:i(`haSensors.badgeBlocks`)}),e.notify_on_alert&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 text-xs rounded bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`,children:i(`haSensors.badgeNotifies`)}),!e.show_on_printer_card&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 text-xs rounded bg-bambu-dark-tertiary text-bambu-gray`,children:i(`haSensors.badgeHidden`)})]})]})},e.id)})}):(0,G.jsx)(Md,{children:(0,G.jsx)(Pd,{className:`py-8`,children:(0,G.jsxs)(`div`,{className:`text-center text-bambu-gray`,children:[(0,G.jsx)(Sc,{className:`w-12 h-12 mx-auto mb-3 opacity-30`}),(0,G.jsx)(`p`,{className:`text-sm`,children:i(`haSensors.empty`)})]})})})]})]}),ye===`notifications`&&(0,G.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-4`,children:[(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,id:`card-providers`,children:[(0,G.jsx)(Go,{className:`w-5 h-5 text-bambu-green`}),i(`settings.providers`)]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(Q,{size:`sm`,variant:`secondary`,onClick:()=>ue(!0),children:[(0,G.jsx)(Ic,{className:`w-4 h-4`}),i(`settings.log`)]}),Ht&&Ht.length>0&&(0,G.jsxs)(Q,{size:`sm`,variant:`secondary`,onClick:()=>{Gn(null),Kn.mutate()},disabled:Kn.isPending,children:[Kn.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Xl,{className:`w-4 h-4`}),i(`settings.testAll`)]}),(0,G.jsxs)(Q,{size:`sm`,onClick:()=>{re(null),te(!0)},children:[(0,G.jsx)(Ml,{className:`w-4 h-4`}),i(`settings.addNotificationProvider`)]})]})]}),(0,G.jsx)(Md,{className:`mb-4`,children:(0,G.jsx)(Pd,{className:`py-3`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white text-sm font-medium`,children:i(`settings.notificationLanguage`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.notificationLanguageDescription`)})]}),(0,G.jsx)(`select`,{value:A.notification_language||`en`,onChange:e=>tr(`notification_language`,e.target.value),className:`px-2 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:outline-none focus:ring-1 focus:ring-bambu-green`,children:kt.map(e=>(0,G.jsx)(`option`,{value:e.code,children:e.nativeName},e.code))})]})})}),(0,G.jsx)(Md,{className:`mb-4`,children:(0,G.jsx)(Pd,{className:`py-3`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white text-sm font-medium`,children:i(`settings.bedCooledThreshold`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.bedCooledThresholdDescription`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(`input`,{type:`number`,min:20,max:80,step:1,value:A.bed_cooled_threshold??35,onChange:e=>tr(`bed_cooled_threshold`,Number(e.target.value)),className:`w-16 px-2 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm text-center focus:outline-none focus:ring-1 focus:ring-bambu-green`}),(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:`°C`})]})]})})}),(0,G.jsx)(Md,{className:`mb-4`,children:(0,G.jsx)(Pd,{className:`py-3`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between ${Tn?.advanced_auth_enabled?``:`opacity-50`}`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white text-sm font-medium`,children:i(`settings.userNotificationsEnabled`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:Tn?.advanced_auth_enabled?i(`settings.userNotificationsEnabledDescription`):i(`settings.userNotificationsDisabledHint`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,className:`sr-only peer`,checked:A.user_notifications_enabled??!0,disabled:!Tn?.advanced_auth_enabled,onChange:e=>tr(`user_notifications_enabled`,e.target.checked)}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green peer-disabled:cursor-not-allowed`})]})]})})}),Wn&&(0,G.jsx)(Md,{className:`mb-4`,children:(0,G.jsxs)(Pd,{className:`py-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,G.jsx)(`span`,{className:`text-sm font-medium text-white`,children:i(`settings.testResults`)}),(0,G.jsx)(`button`,{onClick:()=>Gn(null),className:`text-bambu-gray hover:text-white text-xs`,children:i(`common.dismiss`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-4 text-sm mb-2`,children:[(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-bambu-green`,children:[(0,G.jsx)(ys,{className:`w-4 h-4`}),i(`settings.testPassedCount`,{count:Wn.success})]}),Wn.failed>0&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-red-700 dark:text-red-400`,children:[(0,G.jsx)(Ts,{className:`w-4 h-4`}),i(`settings.testFailedCount`,{count:Wn.failed})]})]}),Wn.results.filter(e=>!e.success).length>0&&(0,G.jsx)(`div`,{className:`space-y-1 mt-2 pt-2 border-t border-bambu-dark-tertiary`,children:Wn.results.filter(e=>!e.success).map(e=>(0,G.jsxs)(`div`,{className:`text-xs text-red-700 dark:text-red-400`,children:[(0,G.jsxs)(`span`,{className:`font-medium`,children:[e.provider_name,`:`]}),` `,e.message]},e.provider_id))})]})}),Ut?(0,G.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,G.jsx)(Y,{className:`w-6 h-6 text-bambu-green animate-spin`})}):Ht&&Ht.length>0?(0,G.jsx)(`div`,{className:`space-y-3`,children:Ht.map(e=>(0,G.jsx)(FVe,{provider:e,onEdit:e=>{re(e),te(!0)}},e.id))}):(0,G.jsx)(Md,{children:(0,G.jsx)(Pd,{className:`py-8`,children:(0,G.jsxs)(`div`,{className:`text-center text-bambu-gray`,children:[(0,G.jsx)(Go,{className:`w-12 h-12 mx-auto mb-3 opacity-30`}),(0,G.jsx)(`p`,{className:`text-sm font-medium text-white mb-2`,children:i(`settings.noProvidersTitle`)}),(0,G.jsx)(`p`,{className:`text-xs mb-3`,children:i(`settings.noProvidersDescription`)}),(0,G.jsxs)(Q,{size:`sm`,onClick:()=>{re(null),te(!0)},children:[(0,G.jsx)(Ml,{className:`w-4 h-4`}),i(`settings.addProvider`)]})]})})})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2 mb-2`,id:`card-templates`,children:[(0,G.jsx)(lc,{className:`w-5 h-5 text-bambu-green`}),i(`settings.messageTemplates`)]}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mb-3`,children:i(`settings.messageTemplatesDescription`)}),(0,G.jsxs)(`div`,{className:`relative mb-3`,children:[(0,G.jsx)(Yl,{className:`w-4 h-4 text-bambu-gray absolute left-3 top-1/2 -translate-y-1/2 pointer-events-none`}),(0,G.jsx)(`input`,{type:`text`,value:oe,onChange:e=>se(e.target.value),placeholder:i(`settings.filterTemplates`,`Filter templates…`),className:`w-full pl-9 pr-8 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`}),oe&&(0,G.jsx)(`button`,{onClick:()=>se(``),className:`absolute right-2 top-1/2 -translate-y-1/2 p-1 text-bambu-gray hover:text-white`,"aria-label":`Clear filter`,children:(0,G.jsx)($u,{className:`w-3.5 h-3.5`})})]}),Qt?(0,G.jsx)(`div`,{className:`flex justify-center py-8`,children:(0,G.jsx)(Y,{className:`w-6 h-6 text-bambu-green animate-spin`})}):Zt&&Zt.length>0?(()=>{let e=oe.trim().toLowerCase(),t=[...Zt].sort((e,t)=>e.name.localeCompare(t.name)).filter(t=>!e||t.name.toLowerCase().includes(e)||(t.title_template||``).toLowerCase().includes(e));return t.length===0?(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray italic text-center py-6`,children:i(`settings.noTemplatesMatch`,`No templates match your filter.`)}):(0,G.jsx)(`div`,{className:`space-y-2`,children:t.map(e=>(0,G.jsx)(Md,{className:`cursor-pointer hover:border-bambu-green/50 transition-colors`,onClick:()=>ae(e),children:(0,G.jsx)(Pd,{className:`py-2.5 px-3`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,G.jsx)(`p`,{className:`text-white font-medium text-sm truncate`,children:e.name}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-xs truncate mt-0.5`,children:e.title_template})]}),(0,G.jsx)(`button`,{className:`p-1.5 hover:bg-bambu-dark-tertiary rounded transition-colors shrink-0 ml-2`,onClick:t=>{t.stopPropagation(),ae(e)},children:(0,G.jsx)(Dl,{className:`w-4 h-4 text-bambu-gray`})})]})})},e.id))})})():(0,G.jsx)(Md,{children:(0,G.jsx)(Pd,{className:`py-8`,children:(0,G.jsxs)(`div`,{className:`text-center text-bambu-gray`,children:[(0,G.jsx)(lc,{className:`w-12 h-12 mx-auto mb-3 opacity-30`}),(0,G.jsx)(`p`,{className:`text-sm`,children:i(`settings.noTemplatesAvailable`)})]})})})]})]}),ye===`apikeys`&&(0,G.jsxs)(`div`,{className:d(`api_keys:read`)?`grid grid-cols-1 xl:grid-cols-2 gap-4`:`grid grid-cols-1 gap-4`,children:[(0,G.jsxs)(`div`,{children:[d(`api_keys:read`)&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`flex items-start justify-between gap-4 mb-6`,children:[(0,G.jsxs)(`div`,{className:`flex-1`,children:[(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,id:`card-createapi`,children:[(0,G.jsx)(Uc,{className:`w-5 h-5 text-bambu-green`}),i(`settings.apiKeys`)]}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:i(`settings.apiKeysDescription`)})]}),(0,G.jsxs)(Q,{size:`sm`,onClick:()=>Oe(!0),className:`flex-shrink-0`,children:[(0,G.jsx)(Ml,{className:`w-4 h-4`}),i(`settings.createKey`)]})]}),Ne&&(0,G.jsx)(Md,{className:`mb-6 border-bambu-green`,children:(0,G.jsx)(Pd,{className:`py-4`,children:(0,G.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,G.jsx)(ys,{className:`w-5 h-5 text-bambu-green flex-shrink-0 mt-0.5`}),(0,G.jsxs)(`div`,{className:`flex-1`,children:[(0,G.jsx)(`p`,{className:`text-white font-medium mb-1`,children:i(`settings.apiKeyCreated`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mb-2`,children:i(`settings.apiKeyCopyWarning`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 bg-bambu-dark rounded-lg p-2`,children:[(0,G.jsx)(`code`,{className:`flex-1 text-sm text-bambu-green font-mono break-all`,children:Ne}),(0,G.jsx)(Q,{variant:`secondary`,size:`sm`,onClick:async()=>{try{if(navigator.clipboard&&navigator.clipboard.writeText)await navigator.clipboard.writeText(Ne);else{let e=document.createElement(`textarea`);e.value=Ne,e.style.position=`fixed`,e.style.left=`-999999px`,document.body.appendChild(e),e.select(),document.execCommand(`copy`),document.body.removeChild(e)}o(i(`settings.toast.keyCopied`))}catch{o(i(`settings.toast.copyFailed`),`error`)}},children:(0,G.jsx)(zs,{className:`w-4 h-4`})})]}),(0,G.jsxs)(`div`,{className:`flex gap-2 mt-3`,children:[(0,G.jsx)(Q,{variant:`secondary`,size:`sm`,onClick:()=>{Be(Ne),o(i(`settings.toast.keyAddedToBrowser`))},children:i(`settings.useInApiBrowser`)}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:()=>Ie(!0),children:[(0,G.jsx)(Il,{className:`w-4 h-4`}),i(`settings.apiKeyQrButton`)]}),(0,G.jsx)(Q,{variant:`secondary`,size:`sm`,onClick:()=>{Ie(!1),Pe(null)},children:i(`common.dismiss`)})]})]})]})})}),Fe&&Ne&&(0,G.jsx)(QVe,{apiKey:Ne,baseUrl:A?.external_url||void 0,onClose:()=>Ie(!1)}),De&&(0,G.jsxs)(Md,{className:`mb-6`,children:[(0,G.jsx)(Nd,{children:(0,G.jsx)(`h3`,{className:`text-base font-semibold text-white`,children:i(`settings.createNewApiKey`)})}),(0,G.jsxs)(Pd,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.keyName`)}),(0,G.jsx)(`input`,{type:`text`,value:ke,onChange:e=>Ae(e.target.value),placeholder:i(`settings.keyNamePlaceholder`),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-2`,children:i(`common.permissions`)}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:je.can_read_status,onChange:e=>Me(t=>({...t,can_read_status:e.target.checked})),className:`w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-white`,children:i(`settings.readStatus`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.readStatusDescription`)})]})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:je.can_queue,onChange:e=>Me(t=>({...t,can_queue:e.target.checked})),className:`w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-white`,children:i(`settings.manageQueue`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.manageQueueDescription`)})]})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:je.can_control_printer,onChange:e=>Me(t=>({...t,can_control_printer:e.target.checked})),className:`w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-white`,children:i(`settings.controlPrinter`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.controlPrinterDescription`)})]})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:je.can_manage_library,onChange:e=>Me(t=>({...t,can_manage_library:e.target.checked})),className:`w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-white`,children:i(`settings.manageLibrary`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.manageLibraryDescription`)})]})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:je.can_manage_inventory,onChange:e=>Me(t=>({...t,can_manage_inventory:e.target.checked})),className:`w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-white`,children:i(`settings.manageInventory`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.manageInventoryDescription`)})]})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:je.can_manage_maintenance,onChange:e=>Me(t=>({...t,can_manage_maintenance:e.target.checked})),className:`w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-white`,children:i(`settings.manageMaintenance`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.manageMaintenanceDescription`)})]})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:je.can_manage_archives,onChange:e=>Me(t=>({...t,can_manage_archives:e.target.checked})),className:`w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-white`,children:i(`settings.manageArchives`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.manageArchivesDescription`)})]})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:je.can_manage_projects,onChange:e=>Me(t=>({...t,can_manage_projects:e.target.checked})),className:`w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-white`,children:i(`settings.manageProjects`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.manageProjectsDescription`)})]})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:je.can_access_cloud,onChange:e=>Me(t=>({...t,can_access_cloud:e.target.checked})),className:`w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-white`,children:i(`settings.cloudAccess`,`Allow cloud access`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.cloudAccessDescription`,`Read Bambu Cloud presets and filaments on your behalf. Requires you to be signed into Bambu Cloud.`)})]})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:je.can_update_energy_cost,onChange:e=>Me(t=>({...t,can_update_energy_cost:e.target.checked})),className:`w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-white`,children:i(`settings.updateEnergyCost`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.updateEnergyCostDescription`)})]})]})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 pt-2`,children:[(0,G.jsxs)(Q,{onClick:()=>Kt.mutate({name:ke||i(`settings.unnamedKey`),...je}),disabled:Kt.isPending,children:[Kt.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Ml,{className:`w-4 h-4`}),i(`settings.createKey`)]}),(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>Oe(!1),children:i(`common.cancel`)})]})]})]}),Gt?(0,G.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,G.jsx)(Y,{className:`w-8 h-8 text-bambu-green animate-spin`})}):Wt&&Wt.length>0?(0,G.jsx)(`div`,{className:`space-y-3`,children:Wt.map(e=>(0,G.jsx)(Md,{children:(0,G.jsx)(Pd,{className:`py-3`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(Uc,{className:`w-5 h-5 ${e.enabled?`text-bambu-green`:`text-bambu-gray`}`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white font-medium`,children:e.name}),(0,G.jsxs)(`p`,{className:`text-xs text-bambu-gray`,children:[e.key_prefix,`••••••••`,e.last_used&&` · ${i(`settings.lastUsed`)}: ${Jf(e.last_used)}`]})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`div`,{className:`flex gap-1 text-xs flex-wrap justify-end`,children:[e.can_read_status&&(0,G.jsx)(`span`,{className:`px-1.5 py-0.5 bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400 rounded`,children:i(`settings.read`)}),e.can_queue&&(0,G.jsx)(`span`,{className:`px-1.5 py-0.5 bg-green-100 dark:bg-green-500/20 text-green-700 dark:text-green-400 rounded`,children:i(`queue.title`)}),e.can_control_printer&&(0,G.jsx)(`span`,{className:`px-1.5 py-0.5 bg-orange-100 dark:bg-orange-500/20 text-orange-700 dark:text-orange-400 rounded`,children:i(`settings.control`)}),e.can_manage_library&&(0,G.jsx)(`span`,{className:`px-1.5 py-0.5 bg-cyan-100 dark:bg-cyan-500/20 text-cyan-700 dark:text-cyan-400 rounded`,children:i(`settings.libraryBadge`)}),e.can_manage_inventory&&(0,G.jsx)(`span`,{className:`px-1.5 py-0.5 bg-pink-100 dark:bg-pink-500/20 text-pink-700 dark:text-pink-400 rounded`,children:i(`settings.inventoryBadge`)}),e.can_manage_maintenance&&(0,G.jsx)(`span`,{className:`px-1.5 py-0.5 bg-teal-100 dark:bg-teal-500/20 text-teal-700 dark:text-teal-400 rounded`,children:i(`settings.maintenanceBadge`)}),e.can_manage_archives&&(0,G.jsx)(`span`,{className:`px-1.5 py-0.5 bg-indigo-100 dark:bg-indigo-500/20 text-indigo-700 dark:text-indigo-400 rounded`,children:i(`settings.archivesBadge`)}),e.can_manage_projects&&(0,G.jsx)(`span`,{className:`px-1.5 py-0.5 bg-lime-100 dark:bg-lime-500/20 text-lime-700 dark:text-lime-400 rounded`,children:i(`settings.projectsBadge`)}),e.can_access_cloud&&(0,G.jsx)(`span`,{className:`px-1.5 py-0.5 bg-purple-100 dark:bg-purple-500/20 text-purple-700 dark:text-purple-400 rounded`,children:i(`settings.cloudBadge`,`Cloud`)}),e.can_update_energy_cost&&(0,G.jsx)(`span`,{className:`px-1.5 py-0.5 bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-400 rounded`,children:i(`settings.energyCostBadge`)}),e.user_id===null&&(0,G.jsx)(`span`,{className:`px-1.5 py-0.5 bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400 rounded`,title:i(`settings.legacyKeyTooltip`,`Created before per-user ownership; recreate to use cloud access`),children:i(`settings.legacyKey`,`Legacy`)})]}),(0,G.jsx)(Q,{variant:`secondary`,size:`sm`,onClick:()=>Re(e.id),children:(0,G.jsx)(ju,{className:`w-4 h-4 text-red-600 dark:text-red-400`})})]})]})})},e.id))}):(0,G.jsx)(Md,{children:(0,G.jsx)(Pd,{className:`py-12`,children:(0,G.jsxs)(`div`,{className:`text-center text-bambu-gray`,children:[(0,G.jsx)(Uc,{className:`w-16 h-16 mx-auto mb-4 opacity-30`}),(0,G.jsx)(`p`,{className:`text-lg font-medium text-white mb-2`,children:i(`settings.apiKeysEmptyTitle`)}),(0,G.jsx)(`p`,{className:`text-sm mb-4`,children:i(`settings.apiKeysEmptyDescription`)}),(0,G.jsxs)(Q,{onClick:()=>Oe(!0),children:[(0,G.jsx)(Ml,{className:`w-4 h-4`}),i(`settings.createFirstKey`)]})]})})}),(0,G.jsxs)(Md,{className:`mt-6`,children:[(0,G.jsx)(Nd,{children:(0,G.jsx)(`h3`,{className:`text-base font-semibold text-white`,id:`card-webhooks`,children:i(`settings.webhookEndpoints`)})}),(0,G.jsxs)(Pd,{className:`space-y-3 text-sm`,children:[(0,G.jsx)(`p`,{className:`text-bambu-gray`,children:i(`settings.webhookApiKeyHint`)}),(0,G.jsxs)(`div`,{className:`space-y-2 font-mono text-xs`,children:[(0,G.jsxs)(`div`,{className:`p-2 bg-bambu-dark rounded`,children:[(0,G.jsx)(`span`,{className:`text-blue-700 dark:text-blue-400`,children:`GET`}),` `,(0,G.jsx)(`span`,{className:`text-white`,children:`/api/v1/webhook/status`}),(0,G.jsxs)(`span`,{className:`text-bambu-gray`,children:[` - `,i(`settings.webhook.getAllStatus`)]})]}),(0,G.jsxs)(`div`,{className:`p-2 bg-bambu-dark rounded`,children:[(0,G.jsx)(`span`,{className:`text-blue-700 dark:text-blue-400`,children:`GET`}),` `,(0,G.jsx)(`span`,{className:`text-white`,children:`/api/v1/webhook/status/:id`}),(0,G.jsxs)(`span`,{className:`text-bambu-gray`,children:[` - `,i(`settings.webhook.getSpecificStatus`)]})]}),(0,G.jsxs)(`div`,{className:`p-2 bg-bambu-dark rounded`,children:[(0,G.jsx)(`span`,{className:`text-green-700 dark:text-green-400`,children:`POST`}),` `,(0,G.jsx)(`span`,{className:`text-white`,children:`/api/v1/webhook/queue`}),(0,G.jsxs)(`span`,{className:`text-bambu-gray`,children:[` - `,i(`settings.webhook.addToQueue`)]})]}),(0,G.jsxs)(`div`,{className:`p-2 bg-bambu-dark rounded`,children:[(0,G.jsx)(`span`,{className:`text-orange-700 dark:text-orange-400`,children:`POST`}),` `,(0,G.jsx)(`span`,{className:`text-white`,children:`/api/v1/webhook/printer/:id/pause`}),(0,G.jsxs)(`span`,{className:`text-bambu-gray`,children:[` - `,i(`settings.webhook.pausePrint`)]})]}),(0,G.jsxs)(`div`,{className:`p-2 bg-bambu-dark rounded`,children:[(0,G.jsx)(`span`,{className:`text-orange-700 dark:text-orange-400`,children:`POST`}),` `,(0,G.jsx)(`span`,{className:`text-white`,children:`/api/v1/webhook/printer/:id/resume`}),(0,G.jsxs)(`span`,{className:`text-bambu-gray`,children:[` - `,i(`settings.webhook.resumePrint`)]})]}),(0,G.jsxs)(`div`,{className:`p-2 bg-bambu-dark rounded`,children:[(0,G.jsx)(`span`,{className:`text-red-700 dark:text-red-400`,children:`POST`}),` `,(0,G.jsx)(`span`,{className:`text-white`,children:`/api/v1/webhook/printer/:id/stop`}),(0,G.jsxs)(`span`,{className:`text-bambu-gray`,children:[` - `,i(`settings.webhook.stopPrint`)]})]})]})]})]})]}),(0,G.jsxs)(Md,{className:`mt-6`,children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,id:`card-camera-tokens`,children:[(0,G.jsx)(Hu,{className:`w-4 h-4 text-bambu-green`}),i(`cameraTokens.title`,`Camera API Tokens`)]})}),(0,G.jsx)(Pd,{children:(0,G.jsx)(OVe,{})})]}),(0,G.jsxs)(Md,{className:`mt-6`,children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,id:`card-stream-overlay`,children:[(0,G.jsx)(pl,{className:`w-4 h-4 text-bambu-green`}),i(`streamOverlay.builder.title`,`Streaming Overlay`)]})}),(0,G.jsx)(Pd,{children:(0,G.jsx)(AVe,{})})]})]}),d(`api_keys:read`)&&(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`mb-6`,children:[(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,id:`card-apibrowser`,children:[(0,G.jsx)(Dc,{className:`w-5 h-5 text-bambu-green`}),i(`settings.apiBrowser`)]}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:i(`settings.apiBrowserDescription`)})]}),(0,G.jsx)(Md,{className:`mb-4`,children:(0,G.jsxs)(Pd,{className:`py-3`,children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-2`,children:i(`settings.apiKeyForTesting`)}),(0,G.jsx)(`input`,{type:`text`,value:ze,onChange:e=>Be(e.target.value),placeholder:i(`settings.apiKeyPlaceholder`),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white font-mono text-sm focus:border-bambu-green focus:outline-none`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-2`,children:i(`settings.apiKeyHint`)})]})}),(0,G.jsx)(KHe,{apiKey:ze})]})]}),ye===`virtual-printer`&&(0,G.jsx)(`div`,{id:`card-vp`,children:(0,G.jsx)(xHe,{})}),ye===`spoolbuddy`&&(0,G.jsx)(`div`,{id:`card-spoolbuddy`,children:(0,G.jsx)(CHe,{})}),ye===`queue`&&(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{className:`flex gap-1 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`button`,{onClick:()=>Ee(`dispatch`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${Ce===`dispatch`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,G.jsx)(Xc,{className:`w-4 h-4`}),i(`settings.tabs.queueDispatch`,`Queue & Dispatch`)]}),(0,G.jsxs)(`button`,{onClick:()=>Ee(`pipelines`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${Ce===`pipelines`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,G.jsx)(Zu,{className:`w-4 h-4`}),i(`settings.tabs.queuePipelines`,`Pipelines`)]})]}),Ce===`pipelines`&&(0,G.jsx)(bVe,{}),Ce===`dispatch`&&A&&(0,G.jsxs)(`div`,{className:`flex flex-col lg:flex-row gap-4 lg:gap-6`,children:[(0,G.jsxs)(`div`,{className:`lg:w-1/2 space-y-3`,children:[(0,G.jsxs)(Md,{id:`card-print-options`,children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(Xc,{className:`w-4 h-4 text-bambu-green`}),i(`settings.defaultPrintOptions`,`Default Print Options`)]})}),(0,G.jsxs)(Pd,{className:`space-y-3`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.defaultPrintOptionsDescription`,`Set default values for print options when starting new prints. These can be overridden per print in the print dialog.`)}),[{key:`default_bed_levelling`,label:i(`settings.defaultBedLevelling`,`Bed Levelling`),desc:i(`settings.defaultBedLevellingDesc`,`Auto-level bed before print`),fallback:!0,dualNozzleOnly:!1,tristate:!0},{key:`default_flow_cali`,label:i(`settings.defaultFlowCali`,`Flow Calibration`),desc:i(`settings.defaultFlowCaliDesc`,`Calibrate extrusion flow`),fallback:!1,dualNozzleOnly:!1,tristate:!0},{key:`default_vibration_cali`,label:i(`settings.defaultVibrationCali`,`Vibration Calibration`),desc:i(`settings.defaultVibrationCaliDesc`,`Reduce ringing artifacts`),fallback:!0,dualNozzleOnly:!1,tristate:!1},{key:`default_layer_inspect`,label:i(`settings.defaultLayerInspect`,`First Layer Inspection`),desc:i(`settings.defaultLayerInspectDesc`,`AI inspection of first layer`),fallback:!1,dualNozzleOnly:!1,tristate:!1},{key:`default_timelapse`,label:i(`settings.defaultTimelapse`,`Timelapse`),desc:i(`settings.defaultTimelapseDesc`,`Record timelapse video`),fallback:!1,dualNozzleOnly:!1,tristate:!1},{key:`default_nozzle_offset_cali`,label:i(`settings.defaultNozzleOffsetCali`,`Nozzle Offset Calibration`),desc:i(`settings.defaultNozzleOffsetCaliDesc`,`Calibrate nozzle offsets between extruders`),fallback:!0,dualNozzleOnly:!0,tristate:!0}].filter(({dualNozzleOnly:e})=>!e||(Jt||[]).some(e=>e.nozzle_count===2)).map(({key:e,label:t,desc:n,fallback:r,tristate:a})=>(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex-1 mr-4`,children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:t}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:n})]}),a?(0,G.jsx)(`div`,{className:`flex gap-1 shrink-0`,children:JU.map(t=>(0,G.jsx)(`button`,{type:`button`,onClick:()=>tr(e,t),className:`px-2.5 py-1 text-xs rounded transition-colors ${(A[e]??`auto`)===t?YU[t]:`bg-bambu-dark-tertiary text-bambu-gray hover:text-white`}`,children:i(`settings.calibrationMode_${t}`)},t))}):(0,G.jsx)(`div`,{className:`flex gap-1 shrink-0`,children:[`off`,`on`].map(t=>(0,G.jsx)(`button`,{type:`button`,onClick:()=>tr(e,t===`on`),className:`px-2.5 py-1 text-xs rounded transition-colors ${(A[e]??r?`on`:`off`)===t?YU[t]:`bg-bambu-dark-tertiary text-bambu-gray hover:text-white`}`,children:i(`settings.calibrationMode_${t}`)},t))})]},e))]})]}),(0,G.jsxs)(Md,{id:`card-plate`,children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(iu,{className:`w-4 h-4 text-bambu-green`}),i(`settings.plateClear`,`Plate-Clear Confirmation`)]})}),(0,G.jsx)(Pd,{className:`space-y-3`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex-1 mr-4`,children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:i(`settings.requirePlateClear`,`Require plate-clear confirmation`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.requirePlateClearDescription`,`When enabled, the scheduler waits for per-printer plate-clear confirmation before starting queued prints on printers with finished jobs. Disabling this also hides the plate status badge and the "Mark plate as cleared" button on printer cards.`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.require_plate_clear??!1,onChange:e=>tr(`require_plate_clear`,e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]})})]}),(0,G.jsxs)(Md,{id:`card-temp-fan-presets`,children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(ku,{className:`w-4 h-4 text-bambu-green`}),i(`settings.tempFanPresetsTitle`,`Temperature & Fan Presets`)]})}),(0,G.jsxs)(Pd,{className:`space-y-4`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.tempFanPresetsDescription`,`Customize the quick-select values shown in printer-card temperature and fan-speed popovers. The Off button is always shown.`)}),hee.map(e=>{let t=pm(A?.[e.key]??``,e.defaults,e.lo,e.hi),n=e.unit===`C`?`°C`:`%`;return(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-1`,children:[(0,G.jsxs)(`label`,{className:`text-sm text-white`,children:[i(`settings.${{nozzle_temp_presets:`tempFanPresetsNozzle`,bed_temp_presets:`tempFanPresetsBed`,chamber_temp_presets:`tempFanPresetsChamber`,fan_speed_presets:`tempFanPresetsFan`}[e.key]}`,{nozzle_temp_presets:`Nozzle temperature`,bed_temp_presets:`Bed temperature`,chamber_temp_presets:`Chamber temperature`,fan_speed_presets:`Fan speed`}[e.key]),` `,(0,G.jsxs)(`span`,{className:`text-bambu-gray text-xs`,children:[`(`,n,` · `,e.lo,`–`,e.hi,`)`]})]}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>tr(e.key,``),title:i(`settings.tempFanPresetsReset`,`Reset to defaults`),className:`text-bambu-gray hover:text-white transition-colors p-1 rounded hover:bg-bambu-dark-tertiary`,children:(0,G.jsx)(Vl,{className:`w-3.5 h-3.5`})})]}),(0,G.jsx)(`div`,{className:`flex gap-2`,children:[0,1,2].map(n=>(0,G.jsx)(`input`,{type:`number`,min:e.lo,max:e.hi,value:t[n],onChange:r=>{let i=[t[0],t[1],t[2]],a=parseInt(r.target.value,10);i[n]=Math.max(e.lo,Math.min(e.hi,Number.isFinite(a)?a:e.lo)),tr(e.key,JSON.stringify(i))},className:`flex-1 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`},n))})]},e.key)})]})]}),(0,G.jsxs)(Md,{id:`card-staggered`,children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(Gc,{className:`w-4 h-4 text-bambu-green`}),i(`settings.staggeredStart`,`Staggered Start`)]})}),(0,G.jsxs)(Pd,{className:`space-y-3`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.staggeredStartDescription`,`Default group size and interval when staggering multi-printer batch starts. Can be overridden per batch in the print modal.`)}),(0,G.jsxs)(`div`,{className:`flex gap-4`,children:[(0,G.jsxs)(`div`,{className:`flex-1`,children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.staggerGroupSize`,`Group size`)}),(0,G.jsx)(`input`,{type:`number`,min:1,max:50,value:A.stagger_group_size??2,onChange:e=>tr(`stagger_group_size`,Math.max(1,Math.min(50,parseInt(e.target.value)||1))),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.staggerGroupSizeHelp`,`Printers to start simultaneously per group`)})]}),(0,G.jsxs)(`div`,{className:`flex-1`,children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.staggerInterval`,`Interval (minutes)`)}),(0,G.jsx)(`input`,{type:`number`,min:1,max:60,value:A.stagger_interval_minutes??5,onChange:e=>tr(`stagger_interval_minutes`,Math.max(1,Math.min(60,parseInt(e.target.value)||1))),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.staggerIntervalHelp`,`Delay between each group starting`)})]})]})]})]}),(0,G.jsxs)(Md,{id:`card-concurrent-uploads`,children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(js,{className:`w-4 h-4 text-bambu-green`}),i(`settings.concurrentUploadsTitle`,`Concurrent Uploads`)]})}),(0,G.jsxs)(Pd,{className:`space-y-3`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.concurrentUploadsDescription`,`How many printers the queue may send files to at the same time. Printers receive files slowly (a large print can take several minutes), and each one waits its turn — so on a bigger fleet, raising this is what stops the last printer in a batch from waiting out every transfer before it. Lower it if your network or Bambuddy host struggles with parallel transfers.`)}),(0,G.jsxs)(`div`,{className:`w-full sm:w-1/2`,children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.concurrentUploadsLabel`,`Printers uploaded to at once`)}),(0,G.jsx)(`input`,{type:`number`,min:1,max:16,value:A.queue_max_concurrent_uploads??4,onChange:e=>tr(`queue_max_concurrent_uploads`,Math.max(1,Math.min(16,parseInt(e.target.value)||1))),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.concurrentUploadsHelp`,`1 sends to one printer at a time (the old behaviour). Default is 4.`)})]})]})]}),(0,G.jsxs)(Md,{id:`card-preheat`,children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(fc,{className:`w-4 h-4 text-amber-600 dark:text-amber-400`}),i(`settings.preheatTitle`,`Preheat & Heat Soak`)]})}),(0,G.jsxs)(Pd,{className:`space-y-3`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.preheatDescription`,`Heat the bed (and chamber, if supported) and hold at temperature before each queued print starts. Helpful for engineering filaments (PA, ABS) on printers without an active chamber heater — the bed warms the chamber by radiation while the soak timer runs. The bed target is read from the print file; chamber behaviour depends on printer model.`)}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex-1 mr-4`,children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:i(`settings.preheatEnabled`,`Enable preheat & soak`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:i(`settings.preheatEnabledDesc`,`When off, queued prints dispatch immediately.`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.preheat_enabled??!1,onChange:e=>tr(`preheat_enabled`,e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3 pt-1`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.preheatMaxWait`,`Max wait (seconds)`)}),(0,G.jsx)(`input`,{type:`number`,min:60,max:3600,value:A.preheat_max_wait_seconds??900,onChange:e=>tr(`preheat_max_wait_seconds`,Math.max(60,Math.min(3600,parseInt(e.target.value)||900))),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 disabled:opacity-50`,disabled:!(A.preheat_enabled??!1)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.preheatMaxWaitHelp`,`Cap on the chamber warm-up phase before falling through.`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.preheatSoak`,`Soak (seconds)`)}),(0,G.jsx)(`input`,{type:`number`,min:0,max:1800,value:A.preheat_soak_seconds??300,onChange:e=>tr(`preheat_soak_seconds`,Math.max(0,Math.min(1800,parseInt(e.target.value)||0))),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 disabled:opacity-50`,disabled:!(A.preheat_enabled??!1)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.preheatSoakHelp`,`Hold time after target reached or max-wait elapsed.`)})]})]}),(0,G.jsxs)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary/50`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-1`,children:[(0,G.jsx)(`label`,{className:`text-sm text-white`,children:i(`settings.preheatFilamentTargetsLabel`,`Per-filament chamber target (°C)`)}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>tr(`preheat_filament_targets`,``),title:i(`settings.preheatFilamentTargetsReset`,`Reset to defaults`),className:`text-bambu-gray hover:text-white transition-colors p-1 rounded hover:bg-bambu-dark-tertiary`,children:(0,G.jsx)(Vl,{className:`w-3.5 h-3.5`})})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:i(`settings.preheatFilamentTargetsHint`,`Bambuddy picks the highest target across the loaded AMS slots; PLA-only prints derive 0 and skip the chamber phase automatically.`)}),(0,G.jsx)(_Ve,{value:A.preheat_filament_targets??``,onChange:e=>tr(`preheat_filament_targets`,e),disabled:!(A.preheat_enabled??!1)})]}),(0,G.jsxs)(`p`,{className:`text-xs text-bambu-gray pt-1 border-t border-bambu-dark-tertiary/50`,children:[(0,G.jsx)(`span`,{className:`font-medium text-bambu-gray/90`,children:i(`settings.preheatHardwareTitle`,`Per-printer behaviour:`)}),` `,i(`settings.preheatHardwareDetail`,`H2C/H2D/H2D Pro/H2S/X2D/X1E actively heat the chamber via M141. X1C/P2S read chamber temp but rely on bed-radiation heating. P1S/P1P/A1/A1 Mini have no chamber sensor — only the soak timer applies.`)]})]})]}),(0,G.jsxs)(Md,{id:`card-gcode`,children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(Ns,{className:`w-4 h-4 text-bambu-green`}),i(`settings.gcodeInjection`,`G-code Injection`)]})}),(0,G.jsxs)(Pd,{className:`space-y-3`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.gcodeInjectionDescription`,`Configure custom G-code to inject at the start and/or end of prints for auto-print systems like Farmloop, SwapMod, AutoClear, and Printflow 3D. Snippets are configured per printer model and applied when "Inject G-code" is enabled on a queue item.`)}),(()=>{let e=(()=>{try{return A.gcode_snippets?JSON.parse(A.gcode_snippets):{}}catch{return{}}})(),t=[...new Set((Jt||[]).filter(e=>e.model).map(e=>e.model))].sort(),n=(t,n,r)=>{let i={...e};i[t]||(i[t]={start_gcode:``,end_gcode:``}),i[t][n]=r,!i[t].start_gcode&&!i[t].end_gcode&&delete i[t];let a=Object.keys(i).length>0?JSON.stringify(i):``;j(e=>e?{...e,gcode_snippets:a}:null),Yn.current=a},r=()=>{Yn.current!==null&&($n.mutate({gcode_snippets:Yn.current}),Yn.current=null)};return t.length===0?(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray italic`,children:i(`settings.gcodeInjectionNoPrinters`,`No printers found. Add printers to configure G-code snippets.`)}):t.map(t=>{let a=e[t]||{start_gcode:``,end_gcode:``},o=!!(a.start_gcode||a.end_gcode);return(0,G.jsx)(Vp,{defaultOpen:o,className:`border border-bambu-dark-tertiary rounded-lg px-3 py-2`,summary:(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`h4`,{className:`text-sm font-medium text-white`,children:t}),o&&(0,G.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-bambu-green/20 text-bambu-green`,children:i(`settings.gcodeConfigured`,`Configured`)})]}),children:(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.gcodeStartLabel`,`Start G-code`)}),(0,G.jsx)(`textarea`,{value:a.start_gcode,onChange:e=>n(t,`start_gcode`,e.target.value),onBlur:r,placeholder:i(`settings.gcodeStartPlaceholder`,`G-code prepended before the print starts...`),rows:3,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-xs font-mono focus:outline-none focus:border-bambu-green resize-y`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.gcodeEndLabel`,`End G-code`)}),(0,G.jsx)(`textarea`,{value:a.end_gcode,onChange:e=>n(t,`end_gcode`,e.target.value),onBlur:r,placeholder:i(`settings.gcodeEndPlaceholder`,`G-code appended after the print ends...`),rows:3,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-xs font-mono focus:outline-none focus:border-bambu-green resize-y`})]})]})},t)})})()]})]})]}),(0,G.jsxs)(`div`,{className:`lg:w-1/2 space-y-3`,children:[(0,G.jsxs)(Md,{id:`card-pipelines`,children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(Zu,{className:`w-4 h-4 text-bambu-green`}),i(`settings.pipelineLimits.title`,`Slicer Pipeline limits`)]})}),(0,G.jsx)(Pd,{className:`space-y-2`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,G.jsxs)(`div`,{className:`flex-1`,children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:i(`settings.pipelineLimits.maxCopiesLabel`,`Max copies per run`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:i(`settings.pipelineLimits.maxCopiesDesc`,`Upper bound on the copies operators can request when running a pipeline. Server-side hard cap is 1000.`)})]}),(0,G.jsx)(`input`,{type:`number`,min:1,max:1e3,value:A.pipeline_max_copies??50,onChange:e=>{let t=parseInt(e.target.value,10);Number.isNaN(t)||tr(`pipeline_max_copies`,Math.max(1,Math.min(1e3,t)))},"aria-label":i(`settings.pipelineLimits.maxCopiesLabel`,`Max copies per run`),className:`w-24 px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm`})]})})]}),(0,G.jsxs)(Md,{id:`card-slicer`,children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(Is,{className:`w-4 h-4 text-bambu-green`}),i(`settings.slicerCard`,`Slicer`)]})}),(0,G.jsxs)(Pd,{className:`space-y-3`,children:[JHe()&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.sliceEngine`)}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(`select`,{value:L6(A.slice_engine),onChange:e=>tr(`slice_engine`,e.target.value),className:`w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer`,children:I6().map(e=>(0,G.jsx)(`option`,{value:e.id,children:i(e.labelKey)},e.id))}),(0,G.jsx)(ds,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(I6().find(e=>e.id===L6(A.slice_engine))?.descriptionKey??`settings.sliceEngineSidecarHint`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.preferredSlicer`)}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsxs)(`select`,{value:A.preferred_slicer??`bambu_studio`,onChange:e=>tr(`preferred_slicer`,e.target.value),className:`w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer`,children:[(0,G.jsx)(`option`,{value:`bambu_studio`,children:i(`settings.slicerBambuStudio`)}),(0,G.jsx)(`option`,{value:`orcaslicer`,children:i(`settings.slicerOrcaSlicer`)})]}),(0,G.jsx)(ds,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.preferredSlicerDescription`)}),(A.preferred_slicer??`bambu_studio`)===`orcaslicer`&&(0,G.jsx)(`div`,{role:`alert`,className:`text-xs text-amber-800 dark:text-amber-200 bg-amber-50 dark:bg-amber-900/20 border border-amber-300 dark:border-amber-700/40 rounded p-2 mt-2`,children:i(`settings.orcaslicerKnownIssuesWarning`,`OrcaSlicer 2.3.2 / 2.4.0-dev have known CLI bugs that block slicing many Bambu-authored 3MFs — see upstream issues #12426 (segfault on painted multi-extruder files) and #13386 (parameter-range strict-validation reject). Bambu Studio is recommended until the upstream fixes land.`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.openInSlicerLabel`,`Open in Slicer`)}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsxs)(`select`,{value:A.open_in_slicer??``,onChange:e=>tr(`open_in_slicer`,e.target.value===``?null:e.target.value),className:`w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer`,children:[(0,G.jsx)(`option`,{value:``,children:i(`settings.openInSlicerInherit`,`Same as API slicer`)}),(0,G.jsx)(`option`,{value:`bambu_studio`,children:i(`settings.slicerBambuStudio`)}),(0,G.jsx)(`option`,{value:`orcaslicer`,children:i(`settings.slicerOrcaSlicer`)})]}),(0,G.jsx)(ds,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.openInSlicerDescription`,`Desktop slicer used by the 'Open in Slicer' button. Leave on 'Same as API slicer' to inherit, or pick a different slicer to use locally.`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.useSlicerApi`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.useSlicerApiDescription`)})]}),(0,G.jsxs)(`label`,{className:`flex items-center cursor-pointer shrink-0`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.use_slicer_api??!1,onChange:e=>tr(`use_slicer_api`,e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`relative w-11 h-6 bg-bambu-dark-tertiary rounded-full peer peer-checked:bg-bambu-green peer-focus:outline-none peer-focus:ring-2 peer-focus:ring-bambu-green/50 transition-colors after:content-[''] after:absolute after:top-0.5 after:left-0.5 after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-transform peer-checked:after:translate-x-5`})]})]}),(A.use_slicer_api??!1)&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:(A.preferred_slicer??`bambu_studio`)===`orcaslicer`?i(`settings.orcaslicerApiUrl`,`OrcaSlicer sidecar URL`):i(`settings.bambuStudioApiUrl`,`Bambu Studio sidecar URL`)}),(0,G.jsx)(`input`,{type:`text`,value:((A.preferred_slicer??`bambu_studio`)===`orcaslicer`?A.orcaslicer_api_url:A.bambu_studio_api_url)??``,onChange:e=>tr((A.preferred_slicer??`bambu_studio`)===`orcaslicer`?`orcaslicer_api_url`:`bambu_studio_api_url`,e.target.value),placeholder:(A.preferred_slicer??`bambu_studio`)===`orcaslicer`?`http://localhost:3003`:`http://localhost:3001`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none placeholder:text-bambu-gray/40`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.slicerApiUrlDescription`,`URL of the slicer-API sidecar container. Leave blank to use the SLICER_API_URL / BAMBU_STUDIO_API_URL env var defaults.`)})]}),(A.use_slicer_api??!1)&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.slicerStallTimeout`)}),(0,G.jsx)(`input`,{type:`number`,min:1,max:240,value:A.slicer_stall_timeout_minutes??15,onChange:e=>tr(`slicer_stall_timeout_minutes`,Number(e.target.value)),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.slicerStallTimeoutDescription`)})]})]})]}),(A.use_slicer_api??!1)&&(0,G.jsx)(vVe,{}),(0,G.jsxs)(Md,{children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,id:`card-drying`,children:[(0,G.jsx)(fc,{className:`w-4 h-4 text-amber-600 dark:text-amber-400`}),i(`settings.queueDrying`)]})}),(0,G.jsxs)(Pd,{className:`space-y-3`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.queueDryingDescription`)}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-white`,children:i(`settings.queueDryingEnabled`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:i(`settings.queueDryingEnabledDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.queue_drying_enabled??!1,onChange:e=>tr(`queue_drying_enabled`,e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),A.queue_drying_enabled&&(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-white`,children:i(`settings.queueDryingBlock`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:i(`settings.queueDryingBlockDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.queue_drying_block??!1,onChange:e=>tr(`queue_drying_block`,e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-amber-500`})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-white`,children:i(`settings.ambientDryingEnabled`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:i(`settings.ambientDryingEnabledDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.ambient_drying_enabled??!1,onChange:e=>tr(`ambient_drying_enabled`,e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-white`,children:i(`settings.printDryingEnabled`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:i(`settings.printDryingEnabledDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.print_drying_enabled??!1,onChange:e=>tr(`print_drying_enabled`,e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`p`,{className:`text-sm text-white font-medium`,children:i(`settings.dryingPresets`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.dryingPresetsDescription`)}),(0,G.jsx)(`div`,{className:`overflow-x-auto`,children:(0,G.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,G.jsx)(`thead`,{children:(0,G.jsxs)(`tr`,{className:`text-bambu-gray border-b border-bambu-dark-tertiary`,children:[(0,G.jsx)(`th`,{className:`text-left py-1.5`,children:i(`settings.dryingFilament`)}),(0,G.jsx)(`th`,{className:`text-center py-1.5`,colSpan:2,children:`AMS 2 Pro`}),(0,G.jsx)(`th`,{className:`text-center py-1.5`,colSpan:2,children:`AMS-HT`})]})}),(0,G.jsx)(`tbody`,{children:(()=>{let e={PLA:{n3f:45,n3s:45,n3f_hours:12,n3s_hours:12},PETG:{n3f:65,n3s:65,n3f_hours:12,n3s_hours:12},TPU:{n3f:65,n3s:75,n3f_hours:12,n3s_hours:18},ABS:{n3f:65,n3s:80,n3f_hours:12,n3s_hours:8},ASA:{n3f:65,n3s:80,n3f_hours:12,n3s_hours:8},PA:{n3f:65,n3s:85,n3f_hours:12,n3s_hours:12},PC:{n3f:65,n3s:80,n3f_hours:12,n3s_hours:8},PVA:{n3f:65,n3s:85,n3f_hours:12,n3s_hours:18}},t={...e};try{if(A.drying_presets){let n=JSON.parse(A.drying_presets);typeof n==`object`&&n&&(t={...e,...n})}}catch{}let n=(e,n,r)=>{let i={...t,[e]:{...t[e],[n]:r}};tr(`drying_presets`,JSON.stringify(i))};return Object.entries(t).map(([e,t])=>(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/50`,children:[(0,G.jsx)(`td`,{className:`py-1.5 pr-2 text-white font-medium`,children:e}),(0,G.jsx)(`td`,{className:`py-1 px-1`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-end gap-1`,children:[(0,G.jsx)(`input`,{type:`number`,min:30,max:65,value:t.n3f,onChange:t=>n(e,`n3f`,Math.max(1,parseInt(t.target.value)||0)),className:`w-14 px-1.5 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-center text-xs focus:border-amber-500/50 focus:outline-none [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none`}),(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:`°C`})]})}),(0,G.jsx)(`td`,{className:`py-1 px-1`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(`input`,{type:`number`,min:1,max:24,value:t.n3f_hours,onChange:t=>n(e,`n3f_hours`,Math.max(1,parseInt(t.target.value)||0)),className:`w-14 px-1.5 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-center text-xs focus:border-amber-500/50 focus:outline-none [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none`}),(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:`h`})]})}),(0,G.jsx)(`td`,{className:`py-1 px-1`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-end gap-1`,children:[(0,G.jsx)(`input`,{type:`number`,min:30,max:85,value:t.n3s,onChange:t=>n(e,`n3s`,Math.max(1,parseInt(t.target.value)||0)),className:`w-14 px-1.5 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-center text-xs focus:border-amber-500/50 focus:outline-none [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none`}),(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:`°C`})]})}),(0,G.jsx)(`td`,{className:`py-1 px-1`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(`input`,{type:`number`,min:1,max:24,value:t.n3s_hours,onChange:t=>n(e,`n3s_hours`,Math.max(1,parseInt(t.target.value)||0)),className:`w-14 px-1.5 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-center text-xs focus:border-amber-500/50 focus:outline-none [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none`}),(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:`h`})]})})]},e))})()})]})})]}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`p`,{className:`text-sm text-white font-medium`,children:i(`settings.humidityThresholds`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.humidityThresholdsDescription`)}),(0,G.jsx)(`div`,{className:`overflow-x-auto`,children:(0,G.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,G.jsx)(`thead`,{children:(0,G.jsxs)(`tr`,{className:`text-bambu-gray border-b border-bambu-dark-tertiary`,children:[(0,G.jsx)(`th`,{className:`text-left py-1.5`,children:i(`settings.dryingFilament`)}),(0,G.jsx)(`th`,{className:`text-right py-1.5 pr-2`,children:i(`settings.humidityThresholdCol`)})]})}),(0,G.jsx)(`tbody`,{children:(()=>{let e=A.ams_humidity_fair??60,t=[`PLA`,`PETG`,`TPU`,`ABS`,`ASA`,`PA`,`PC`,`PVA`],n={};try{if(A.ams_humidity_thresholds){let e=JSON.parse(A.ams_humidity_thresholds);typeof e==`object`&&e&&(n=e)}}catch{}let r=[{key:`default`,label:i(`settings.humidityThresholdDefault`),value:Number(n.default??e),isDefault:!0},...t.map(t=>({key:t,label:t,value:Number(n[t]??n.default??e),isDefault:!1}))],a=(e,t)=>{if(t.trim()===``){let t={...n};delete t[e],tr(`ams_humidity_thresholds`,JSON.stringify(t));return}let r=parseInt(t,10);if(Number.isNaN(r))return;let i=Math.max(5,Math.min(95,r)),a={...n,[e]:i};tr(`ams_humidity_thresholds`,JSON.stringify(a))};return r.map(e=>{let t=M[e.key],n=t===void 0?String(e.value):t;return(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/50`,children:[(0,G.jsx)(`td`,{className:`py-1.5 pr-2 font-medium ${e.isDefault?`text-bambu-gray italic`:`text-white`}`,children:e.label}),(0,G.jsx)(`td`,{className:`py-1 pr-2`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-end gap-1`,children:[(0,G.jsx)(`input`,{type:`number`,min:5,max:95,value:n,onChange:t=>N(n=>({...n,[e.key]:t.target.value})),onBlur:t=>{a(e.key,t.target.value),N(t=>{let n={...t};return delete n[e.key],n})},onKeyDown:e=>{e.key===`Enter`&&e.currentTarget.blur()},className:`w-14 px-1.5 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-center text-xs focus:border-amber-500/50 focus:outline-none [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none`}),(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:`%`})]})})]},e.key)})})()})]})})]})]})]})]})]})]}),ye===`filament`&&A&&(0,G.jsx)(G.Fragment,{children:(0,G.jsxs)(`div`,{className:`flex flex-col lg:flex-row gap-4 lg:gap-6`,children:[(0,G.jsxs)(`div`,{className:`lg:w-1/3 space-y-3`,children:[(0,G.jsx)(nHe,{}),(0,G.jsxs)(Md,{id:`card-filamentchecks`,children:[(0,G.jsx)(Nd,{children:(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(`settings.filamentChecks`)})}),(0,G.jsxs)(Pd,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.disableFilamentWarnings`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.disableFilamentWarningsDesc`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.disable_filament_warnings,onChange:e=>tr(`disable_filament_warnings`,e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.preferLowestFilament`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.preferLowestFilamentDesc`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray/70 mt-1`,children:i(`settings.preferLowestFilamentBackupNote`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.prefer_lowest_filament,onChange:e=>tr(`prefer_lowest_filament`,e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]})]})]}),(0,G.jsxs)(Md,{id:`card-printmodal`,children:[(0,G.jsx)(Nd,{children:(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(`settings.printModal`)})}),(0,G.jsx)(Pd,{className:`space-y-3`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.expandCustomMapping`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.expandCustomMappingDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.per_printer_mapping_expanded??!1,onChange:e=>tr(`per_printer_mapping_expanded`,e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]})})]}),(0,G.jsxs)(Md,{id:`card-amsthresholds`,children:[(0,G.jsx)(Nd,{children:(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(`settings.amsDisplayThresholds`)})}),(0,G.jsxs)(Pd,{className:`space-y-3`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.amsThresholdsDescription`)}),(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-white`,children:[(0,G.jsx)(Xs,{className:`w-4 h-4 text-blue-600 dark:text-blue-400`}),(0,G.jsx)(`span`,{className:`font-medium`,children:i(`settings.humidity`)})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[i(`settings.goodGreen`),` ≤`]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`input`,{type:`number`,min:`0`,max:`100`,value:A.ams_humidity_good??40,onChange:e=>tr(`ams_humidity_good`,parseInt(e.target.value)||40),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:`%`})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[i(`settings.fairOrange`),` ≤`]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`input`,{type:`number`,min:`0`,max:`100`,value:A.ams_humidity_fair??60,onChange:e=>tr(`ams_humidity_fair`,parseInt(e.target.value)||60),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:`%`})]})]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.aboveFairBad`)}),(0,G.jsx)(`p`,{className:`text-xs text-amber-700/80 dark:text-amber-400/70`,children:i(`settings.fairAlsoDryingThreshold`)}),(A.ams_humidity_fair??60)tr(`ams_temp_good`,parseFloat(e.target.value)||28),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:`°C`})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[i(`settings.fairOrange`),` ≤`]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`input`,{type:`number`,step:`0.5`,min:`0`,max:`60`,value:A.ams_temp_fair??35,onChange:e=>tr(`ams_temp_fair`,parseFloat(e.target.value)||35),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:`°C`})]})]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.aboveFairHot`)})]}),(0,G.jsxs)(`div`,{className:`space-y-3 pt-4 border-t border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-white`,children:[(0,G.jsx)(Us,{className:`w-4 h-4 text-purple-600 dark:text-purple-400`}),(0,G.jsx)(`span`,{className:`font-medium`,children:i(`settings.historyRetention`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.keepSensorHistory`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`input`,{type:`number`,min:`1`,max:`365`,value:A.ams_history_retention_days??30,onChange:e=>tr(`ams_history_retention_days`,parseInt(e.target.value)||30),className:`w-24 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:i(`common.days`)})]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.historyRetentionDescription`)})]})]})]})]}),(0,G.jsxs)(`div`,{className:`lg:w-2/3 space-y-3`,children:[(0,G.jsx)(rHe,{}),(0,G.jsx)(pHe,{})]})]})}),Le!==null&&(0,G.jsx)(Zd,{title:i(`settings.deleteApiKeyTitle`),message:i(`settings.deleteApiKeyMessage`),confirmText:i(`settings.deleteKey`),variant:`danger`,onConfirm:()=>{qt.mutate(Le),Re(null)},onCancel:()=>Re(null)}),P&&(0,G.jsx)(MVe,{plug:I,onClose:()=>{F(!1),L(null)}}),R&&(0,G.jsx)(PVe,{sensor:B,printers:Jt??[],onClose:()=>{z(!1),V(null)}}),ee&&(0,G.jsx)(LVe,{provider:ne,onClose:()=>{te(!1),re(null)}}),ie&&(0,G.jsx)(RVe,{template:ie,onClose:()=>ae(null)}),le&&(0,G.jsx)(BVe,{onClose:()=>ue(!1)}),Ve&&(0,G.jsx)(Zd,{title:i(`settings.clearNotificationLogs`),message:i(`settings.clearLogsMessage`),confirmText:i(`settings.clearLogs`),variant:`warning`,onConfirm:async()=>{He(!1);try{o((await Z.clearNotificationLogs(30)).message,`success`)}catch{o(i(`settings.toast.clearLogsFailed`),`error`)}},onCancel:()=>He(!1)}),Ue&&(0,G.jsx)(Zd,{title:i(`settings.resetUiPreferences`),message:i(`settings.resetUiPreferencesMessage`),confirmText:i(`settings.resetPreferences`),variant:`default`,onConfirm:()=>{We(!1),localStorage.clear(),o(i(`settings.toast.uiPreferencesReset`),`success`),setTimeout(()=>window.location.reload(),1e3)},onCancel:()=>We(!1)}),Ge&&(0,G.jsx)(Zd,{title:`Turn All Plugs ${Ge===`on`?`On`:`Off`}`,message:`This will turn ${Ge===`on`?`ON`:`OFF`} all ${zt?.filter(e=>e.enabled).length||0} enabled smart plugs. ${Ge===`off`?`Any running printers may be affected!`:``}`,confirmText:`Turn All ${Ge===`on`?`On`:`Off`}`,variant:Ge===`off`?`danger`:`warning`,onConfirm:()=>{let e=Ge;Ke(null),qn.mutate(e)},onCancel:()=>Ke(null)}),qe&&_n?.release_notes&&(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,onClick:()=>Je(!1),children:(0,G.jsxs)(Md,{className:`w-full max-w-2xl max-h-[80vh] flex flex-col`,onClick:e=>e.stopPropagation(),children:[(0,G.jsxs)(Nd,{className:`flex flex-row items-center justify-between shrink-0`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white`,children:[`Release Notes - v`,_n.latest_version]}),_n.release_name&&_n.release_name!==_n.latest_version&&(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:_n.release_name})]}),(0,G.jsx)(`button`,{onClick:()=>Je(!1),className:`p-1 rounded hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white`,children:(0,G.jsx)($u,{className:`w-5 h-5`})})]}),(0,G.jsx)(Pd,{className:`overflow-y-auto flex-1`,children:(0,G.jsx)(`pre`,{className:`text-sm text-bambu-gray whitespace-pre-wrap font-sans`,children:_n.release_notes})}),(0,G.jsxs)(`div`,{className:`p-4 border-t border-bambu-dark-tertiary shrink-0 flex gap-2`,children:[_n.release_url&&(0,G.jsx)(`a`,{href:_n.release_url,target:`_blank`,rel:`noopener noreferrer`,className:`flex-1`,children:(0,G.jsxs)(Q,{variant:`secondary`,className:`w-full`,children:[(0,G.jsx)(tc,{className:`w-4 h-4`}),`View on GitHub`]})}),(0,G.jsx)(Q,{onClick:()=>Je(!1),className:`flex-1`,children:`Close`})]})]})}),ye===`users`&&(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{className:`flex gap-1 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`button`,{onClick:()=>Se(`users`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${xe===`users`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,G.jsx)(Bu,{className:`w-4 h-4`}),i(`settings.tabs.users`)]}),(0,G.jsxs)(`button`,{onClick:()=>Se(`email`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${xe===`email`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,G.jsx)(rl,{className:`w-4 h-4`}),i(`settings.tabs.emailAuth`)||`Email Authentication`,Tn?.advanced_auth_enabled&&(0,G.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-green-400`})]}),(0,G.jsxs)(`button`,{onClick:()=>Se(`ldap`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${xe===`ldap`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,G.jsx)(iu,{className:`w-4 h-4`}),i(`settings.tabs.ldap`)||`LDAP`,En?.ldap_enabled&&(0,G.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-green-400`})]}),(0,G.jsxs)(`button`,{onClick:()=>Se(`twofa`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${xe===`twofa`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,G.jsx)(iu,{className:`w-4 h-4`}),i(`settings.tabs.twoFa`),(0,G.jsx)(`span`,{className:`w-2 h-2 rounded-full ${Dn?.totp_enabled||Dn?.email_otp_enabled?`bg-green-400`:`bg-bambu-gray/40`}`})]}),l&&(0,G.jsxs)(`button`,{onClick:()=>Se(`oidc`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${xe===`oidc`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,G.jsx)(Dc,{className:`w-4 h-4`}),i(`settings.tabs.oidc`),(0,G.jsx)(`span`,{className:`w-2 h-2 rounded-full ${On.some(e=>e.is_enabled)?`bg-green-400`:`bg-bambu-gray/40`}`})]}),l&&(0,G.jsxs)(`button`,{onClick:()=>Se(`security`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${xe===`security`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,G.jsx)(iu,{className:`w-4 h-4`}),i(`settings.tabs.security`)]})]}),xe===`users`&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Md,{children:(0,G.jsx)(Pd,{className:`py-4`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`w-10 h-10 rounded-full flex items-center justify-center ${s?`bg-green-500/20`:`bg-gray-500/20`}`,children:s?(0,G.jsx)(el,{className:`w-5 h-5 text-green-600 dark:text-green-400`}):(0,G.jsx)($c,{className:`w-5 h-5 text-gray-400`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`text-white font-medium`,children:i(`settings.authentication`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(s?`settings.authEnabledDescription`:`settings.authDisabledDescription`)})]})]}),s?c?.is_admin&&(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>Xe(!0),children:[(0,G.jsx)($c,{className:`w-4 h-4`}),i(`common.disable`)]}):(0,G.jsxs)(Q,{onClick:()=>t(`/setup`),children:[(0,G.jsx)(el,{className:`w-4 h-4`}),i(`common.enable`)]})]})})}),Tn?.advanced_auth_enabled&&(0,G.jsx)(Md,{className:`border-blue-500/30 bg-blue-500/5`,children:(0,G.jsx)(Pd,{className:`py-4`,children:(0,G.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,G.jsx)(`div`,{className:`w-10 h-10 rounded-full flex items-center justify-center bg-blue-500/20 flex-shrink-0`,children:(0,G.jsx)(rl,{className:`w-5 h-5 text-blue-600 dark:text-blue-400`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`text-white font-medium`,children:i(`settings.email.advancedAuthEnabled`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:i(`settings.email.advancedAuthEnabledDesc`)})]})]})})}),s&&(0,G.jsxs)(`div`,{className:`grid grid-cols-1 xl:grid-cols-2 gap-6`,children:[(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(Md,{id:`card-session-policy`,children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`h3`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(el,{className:`w-5 h-5 text-bambu-green`}),i(`settings.sessionPolicy.title`)]})}),(0,G.jsxs)(Pd,{children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4`,children:i(`settings.sessionPolicy.description`)}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 sm:grid-cols-4 gap-2 mb-4`,children:[[{hours:24,labelKey:`settings.sessionPolicy.preset24h`},{hours:168,labelKey:`settings.sessionPolicy.preset7d`},{hours:720,labelKey:`settings.sessionPolicy.preset30d`}].map(e=>{let t=(A?.session_max_hours??24)===e.hours;return(0,G.jsx)(`button`,{type:`button`,onClick:()=>tr(`session_max_hours`,e.hours),disabled:s&&!d(`settings:update`),className:`px-3 py-2 rounded-lg text-sm font-medium transition-colors ${t?`bg-bambu-green text-white`:`bg-bambu-dark-tertiary text-bambu-gray hover:text-white hover:bg-bambu-dark`} disabled:opacity-50 disabled:cursor-not-allowed`,children:i(e.labelKey)},e.hours)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(`input`,{type:`number`,min:1,max:720,value:A?.session_max_hours??24,onChange:e=>{let t=parseInt(e.target.value,10);Number.isNaN(t)||tr(`session_max_hours`,Math.max(1,Math.min(720,t)))},disabled:s&&!d(`settings:update`),"aria-label":i(`settings.sessionPolicy.customHoursLabel`),className:`w-20 px-2 py-2 bg-bambu-dark-tertiary text-white text-sm rounded-lg border border-bambu-dark-tertiary focus:border-bambu-green focus:outline-none disabled:opacity-50`}),(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:i(`settings.sessionPolicy.hoursSuffix`)})]})]}),(A?.session_max_hours??24)>24&&(0,G.jsxs)(`div`,{className:`flex items-start gap-2 p-3 rounded-lg bg-yellow-50 dark:bg-yellow-500/10 border border-yellow-300 dark:border-yellow-500/30`,children:[(0,G.jsx)(Pu,{className:`w-4 h-4 text-yellow-600 dark:text-yellow-400 flex-shrink-0 mt-0.5`}),(0,G.jsx)(`p`,{className:`text-xs text-yellow-800 dark:text-yellow-200`,children:i(`settings.sessionPolicy.warning`)})]})]})]}),c&&(0,G.jsxs)(Md,{children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`h3`,{className:`text-lg font-semibold text-white flex items-center gap-2`,id:`card-currentuser`,children:[(0,G.jsx)(Bu,{className:`w-5 h-5 text-bambu-green`}),i(`settings.currentUser`)]}),c.auth_source!==`ldap`&&(0,G.jsxs)(Q,{size:`sm`,variant:`ghost`,onClick:()=>Qe(!0),children:[(0,G.jsx)(Uc,{className:`w-4 h-4`}),i(`settings.changePassword`)]})]})}),(0,G.jsx)(Pd,{children:(0,G.jsx)(`div`,{className:`flex items-center justify-between`,children:(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white font-medium text-lg`,children:c.username}),(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-1 mt-2`,children:[c.is_admin&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 rounded-full text-xs font-medium bg-purple-100 dark:bg-purple-500/20 text-purple-700 dark:text-purple-300`,children:i(`settings.admin`)}),c.groups?.map(e=>(0,G.jsx)(`span`,{className:`px-2 py-0.5 rounded-full text-xs font-medium ${e.name===`Administrators`?`bg-purple-100 dark:bg-purple-500/20 text-purple-700 dark:text-purple-300`:e.name===`Operators`?`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-300`:e.name===`Viewers`?`bg-green-100 dark:bg-green-500/20 text-green-700 dark:text-green-300`:`bg-gray-500/20 text-gray-300`}`,children:e.name},e.id))]})]})})})]}),(0,G.jsxs)(Md,{children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`h3`,{className:`text-lg font-semibold text-white flex items-center gap-2`,id:`card-users`,children:[(0,G.jsx)(Bu,{className:`w-5 h-5 text-bambu-green`}),i(`settings.users`)]}),d(`users:create`)&&(0,G.jsxs)(Q,{size:`sm`,onClick:()=>{ot(!0),bt({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]})},children:[(0,G.jsx)(Ml,{className:`w-4 h-4`}),i(`settings.addUser`)]})]})}),(0,G.jsx)(Pd,{children:An?(0,G.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,G.jsx)(Y,{className:`w-6 h-6 text-bambu-green animate-spin`})}):kn.length===0?(0,G.jsx)(`p`,{className:`text-center text-bambu-gray py-8`,children:i(`settings.noUsersFound`)}):(0,G.jsx)(`div`,{className:`divide-y divide-bambu-dark-tertiary`,children:kn.map(e=>(0,G.jsxs)(`div`,{className:`py-3 flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`p`,{className:`text-white font-medium truncate`,children:e.username}),(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-1 mt-1`,children:[e.auth_source===`ldap`&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 rounded-full text-xs font-medium bg-cyan-100 dark:bg-cyan-500/20 text-cyan-700 dark:text-cyan-300`,children:`LDAP`}),e.is_admin&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 rounded-full text-xs font-medium bg-purple-100 dark:bg-purple-500/20 text-purple-700 dark:text-purple-300`,children:i(`settings.admin`)}),e.groups?.map(e=>(0,G.jsx)(`span`,{className:`px-2 py-0.5 rounded-full text-xs font-medium ${e.name===`Administrators`?`bg-purple-100 dark:bg-purple-500/20 text-purple-700 dark:text-purple-300`:e.name===`Operators`?`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-300`:e.name===`Viewers`?`bg-green-100 dark:bg-green-500/20 text-green-700 dark:text-green-300`:`bg-gray-500/20 text-gray-300`}`,children:e.name},e.id))]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1 ml-4`,children:[d(`users:update`)&&(0,G.jsx)(Q,{size:`sm`,variant:`ghost`,onClick:()=>Vn(e),children:(0,G.jsx)(Dl,{className:`w-4 h-4`})}),d(`users:delete`)&&e.id!==c?.id&&(0,G.jsx)(Q,{size:`sm`,variant:`ghost`,onClick:()=>Ln(e.id),children:(0,G.jsx)(ju,{className:`w-4 h-4`})})]})]},e.id))})})]})]}),(0,G.jsx)(`div`,{children:(0,G.jsxs)(Md,{children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`h3`,{className:`text-lg font-semibold text-white flex items-center gap-2`,id:`card-groups`,children:[(0,G.jsx)(iu,{className:`w-5 h-5 text-bambu-green`}),i(`settings.groups`)]}),d(`groups:create`)&&(0,G.jsxs)(Q,{size:`sm`,onClick:()=>t(`/groups/new`),children:[(0,G.jsx)(Ml,{className:`w-4 h-4`}),i(`settings.addGroup`)]})]})}),(0,G.jsx)(Pd,{children:Mn?(0,G.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,G.jsx)(Y,{className:`w-6 h-6 text-bambu-green animate-spin`})}):jn.length===0?(0,G.jsx)(`p`,{className:`text-center text-bambu-gray py-8`,children:i(`settings.noGroupsFound`)}):(0,G.jsx)(`div`,{className:`divide-y divide-bambu-dark-tertiary`,children:jn.map(e=>(0,G.jsxs)(`div`,{className:`py-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(iu,{className:`w-4 h-4 ${e.name===`Administrators`?`text-purple-600 dark:text-purple-400`:e.name===`Operators`?`text-blue-600 dark:text-blue-400`:e.name===`Viewers`?`text-green-600 dark:text-green-400`:`text-bambu-gray`}`}),(0,G.jsx)(`span`,{className:`text-white font-medium`,children:e.name}),e.is_system&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 rounded text-xs bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400`,children:i(`settings.system`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[d(`groups:update`)&&(0,G.jsx)(Q,{size:`sm`,variant:`ghost`,onClick:()=>t(`/groups/${e.id}/edit`),children:(0,G.jsx)(Dl,{className:`w-4 h-4`})}),d(`groups:delete`)&&!e.is_system&&(0,G.jsx)(Q,{size:`sm`,variant:`ghost`,onClick:()=>St(e.id),children:(0,G.jsx)(ju,{className:`w-4 h-4`})})]})]}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1 ml-6`,children:e.description||i(`settings.noDescription`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-4 mt-2 ml-6 text-xs text-bambu-gray`,children:[(0,G.jsx)(`span`,{children:i(`settings.userCount`,{count:e.user_count})}),(0,G.jsx)(`span`,{children:i(`settings.permissionCount`,{count:e.permissions.length})})]})]},e.id))})})]})})]}),!s&&(0,G.jsx)(Md,{children:(0,G.jsx)(Pd,{className:`py-6`,children:(0,G.jsxs)(`div`,{className:`text-center`,children:[(0,G.jsx)($c,{className:`w-12 h-12 text-bambu-gray mx-auto mb-4`}),(0,G.jsx)(`h3`,{className:`text-lg font-medium text-white mb-2`,children:i(`settings.authDisabledTitle`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4 max-w-md mx-auto`,children:i(`settings.authDisabledMessage`)}),(0,G.jsxs)(`ul`,{className:`space-y-2 text-sm text-bambu-gray mb-6 text-left max-w-xs mx-auto`,children:[(0,G.jsxs)(`li`,{className:`flex items-start gap-2`,children:[(0,G.jsx)(ys,{className:`w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0`}),(0,G.jsx)(`span`,{children:i(`settings.authDisabledFeature1`)})]}),(0,G.jsxs)(`li`,{className:`flex items-start gap-2`,children:[(0,G.jsx)(ys,{className:`w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0`}),(0,G.jsx)(`span`,{children:i(`settings.authDisabledFeature2`)})]}),(0,G.jsxs)(`li`,{className:`flex items-start gap-2`,children:[(0,G.jsx)(ys,{className:`w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0`}),(0,G.jsx)(`span`,{children:i(`settings.authDisabledFeature3`)})]})]}),(0,G.jsxs)(Q,{onClick:()=>t(`/setup`),children:[(0,G.jsx)(el,{className:`w-4 h-4`}),i(`settings.enableAuthentication`)]})]})})})]}),xe===`email`&&(0,G.jsx)(`div`,{className:`max-w-5xl`,id:`card-smtp`,children:(0,G.jsx)(NHe,{})}),xe===`ldap`&&(0,G.jsx)(`div`,{className:`max-w-5xl`,id:`card-ldap`,children:(0,G.jsx)(FHe,{})}),xe===`twofa`&&(0,G.jsx)(`div`,{className:`max-w-2xl`,children:(0,G.jsx)(LHe,{})}),xe===`oidc`&&l&&(0,G.jsxs)(`div`,{className:`max-w-3xl space-y-4`,children:[(0,G.jsx)(Md,{children:(0,G.jsx)(Pd,{className:`space-y-3 p-4`,children:(0,G.jsxs)(`label`,{className:`flex items-start gap-3 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.local_login_enabled===!1,onChange:e=>tr(`local_login_enabled`,!e.target.checked),className:`mt-1 h-4 w-4 rounded border-bambu-dark-tertiary bg-bambu-dark-secondary text-bambu-green focus:ring-bambu-green/50 cursor-pointer`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm font-medium text-white`,children:i(`settings.localLogin.disable`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:i(`settings.localLogin.disableHint`)})]})]})})}),(0,G.jsx)(BHe,{})]}),xe===`security`&&l&&(0,G.jsx)(`div`,{className:`max-w-3xl`,children:(0,G.jsx)(HHe,{})})]}),at&&!Tn?.advanced_auth_enabled&&(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black flex items-center justify-center z-50 p-4`,onClick:()=>{ot(!1),bt({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]})},children:(0,G.jsxs)(Md,{className:`w-full max-w-md`,onClick:e=>e.stopPropagation(),children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Bu,{className:`w-5 h-5 text-bambu-green`}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(`settings.createUser`)})]}),(0,G.jsx)(Q,{variant:`ghost`,size:`sm`,onClick:()=>{ot(!1),bt({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]})},children:(0,G.jsx)($u,{className:`w-5 h-5`})})]})}),(0,G.jsxs)(Pd,{children:[En?.ldap_enabled&&(0,G.jsxs)(`div`,{className:`mb-4 flex items-center gap-1 p-1 bg-bambu-dark-secondary rounded-lg`,role:`tablist`,"aria-label":i(`users.modal.tabsAriaLabel`),children:[(0,G.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":st===`local`,onClick:()=>ct(`local`),className:`flex-1 px-3 py-2 text-sm rounded-md transition-colors ${st===`local`?`bg-bambu-green/15 text-bambu-green`:`text-bambu-gray hover:text-white`}`,children:i(`users.modal.localTab`)}),(0,G.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":st===`ldap`,onClick:()=>ct(`ldap`),className:`flex-1 px-3 py-2 text-sm rounded-md transition-colors ${st===`ldap`?`bg-bambu-green/15 text-bambu-green`:`text-bambu-gray hover:text-white`}`,children:i(`users.modal.ldapTab`)})]}),st===`ldap`&&En?.ldap_enabled?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(l6,{onSuccess:e=>{ot(!1),ct(`local`),bt({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]}),o(i(`users.toast.ldapProvisioned`,{username:e.username}))}}),(0,G.jsx)(`div`,{className:`mt-6 flex justify-end`,children:(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>{ot(!1),ct(`local`),bt({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]})},children:i(`common.cancel`)})})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:i(`settings.username`)}),(0,G.jsx)(`input`,{type:`text`,value:yt.username,onChange:e=>bt({...yt,username:e.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:i(`settings.enterUsername`),autoComplete:`username`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:i(`settings.password`)}),(0,G.jsx)(`input`,{type:`password`,value:yt.password,onChange:e=>bt({...yt,password:e.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:i(`settings.enterPassword`),autoComplete:`new-password`,minLength:8}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-xs mt-1`,children:i(`settings.passwordRequirements`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:i(`settings.confirmPassword`)}),(0,G.jsx)(`input`,{type:`password`,value:yt.confirmPassword,onChange:e=>bt({...yt,confirmPassword:e.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors ${yt.confirmPassword&&yt.password!==yt.confirmPassword?`border-red-500`:`border-bambu-dark-tertiary`}`,placeholder:i(`settings.confirmPasswordPlaceholder`),autoComplete:`new-password`,minLength:6}),yt.confirmPassword&&yt.password!==yt.confirmPassword&&(0,G.jsx)(`p`,{className:`text-red-700 dark:text-red-400 text-xs mt-1`,children:i(`settings.passwordsDoNotMatch`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:i(`settings.groups`)}),(0,G.jsxs)(`div`,{className:`space-y-2 max-h-40 overflow-y-auto p-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg`,children:[jn.map(e=>(0,G.jsxs)(`label`,{className:`flex items-center gap-3 px-2 py-1.5 rounded hover:bg-bambu-dark-tertiary cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:yt.group_ids.includes(e.id),onChange:()=>Hn(e.id),className:`w-4 h-4 rounded border-bambu-gray text-bambu-green focus:ring-bambu-green focus:ring-offset-0 bg-bambu-dark`}),(0,G.jsx)(`span`,{className:`text-sm text-white`,children:e.name}),e.is_system&&(0,G.jsx)(`span`,{className:`text-xs text-yellow-700 dark:text-yellow-400`,children:i(`settings.systemBadge`)})]},e.id)),jn.length===0&&(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.noGroupsAvailable`)})]})]})]}),(0,G.jsxs)(`div`,{className:`mt-6 flex justify-end gap-3`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>{ot(!1),bt({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]})},children:i(`common.cancel`)}),(0,G.jsx)(Q,{onClick:zn,disabled:Nn.isPending||!yt.username||!yt.password||yt.password!==yt.confirmPassword||N3(yt.password)!==null,children:Nn.isPending?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),i(`settings.creating`)]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Ml,{className:`w-4 h-4`}),i(`settings.createUser`)]})})]})]})]})]})}),at&&Tn?.advanced_auth_enabled&&(0,G.jsx)(tHe,{formData:yt,setFormData:bt,groups:jn,onClose:()=>{ot(!1),bt({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]})},onCreate:zn,isCreating:Nn.isPending,isCreateButtonDisabled:Nn.isPending||!yt.username||!yt.email,ldapEnabled:En?.ldap_enabled,onLdapProvisioned:e=>{ot(!1),bt({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]}),o(i(`users.toast.ldapProvisioned`,{username:e.username}))}}),lt&&dt!==null&&(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black flex items-center justify-center z-50 p-4`,onClick:()=>{ut(!1),ft(null),bt({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]})},children:(0,G.jsxs)(Md,{className:`w-full max-w-md`,onClick:e=>e.stopPropagation(),children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Dl,{className:`w-5 h-5 text-bambu-green`}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(`settings.editUser`)})]}),(0,G.jsx)(Q,{variant:`ghost`,size:`sm`,onClick:()=>{ut(!1),ft(null),bt({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]})},children:(0,G.jsx)($u,{className:`w-5 h-5`})})]})}),(0,G.jsxs)(Pd,{children:[(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:[i(`settings.username`),` `,Tn?.advanced_auth_enabled&&(0,G.jsx)(`span`,{className:`text-red-700 dark:text-red-400`,children:`*`})]}),(0,G.jsx)(`input`,{type:`text`,value:yt.username,onChange:e=>bt({...yt,username:e.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:i(`settings.enterUsername`),autoComplete:`username`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:[i(`users.form.email`)||`Email`,` `,Tn?.advanced_auth_enabled?(0,G.jsx)(`span`,{className:`text-red-700 dark:text-red-400`,children:`*`}):(0,G.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,i(`users.form.optional`)||`optional`,`)`]})]}),(0,G.jsx)(`input`,{type:`email`,value:yt.email,onChange:e=>bt({...yt,email:e.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:i(`users.form.emailPlaceholder`)||`user@example.com`,required:Tn?.advanced_auth_enabled})]}),!Tn?.advanced_auth_enabled&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:[i(`users.form.password`)||`Password`,` `,(0,G.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,i(`users.form.leaveBlankToKeep`)||`leave blank to keep current`,`)`]})]}),(0,G.jsx)(`input`,{type:`password`,value:yt.password,onChange:e=>bt({...yt,password:e.target.value,confirmPassword:``}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:i(`settings.enterNewPassword`),autoComplete:`new-password`,minLength:8}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-xs mt-1`,children:i(`settings.passwordRequirements`)})]}),yt.password&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:i(`settings.confirmPassword`)}),(0,G.jsx)(`input`,{type:`password`,value:yt.confirmPassword,onChange:e=>bt({...yt,confirmPassword:e.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors ${yt.confirmPassword&&yt.password!==yt.confirmPassword?`border-red-500`:`border-bambu-dark-tertiary`}`,placeholder:i(`settings.confirmNewPassword`),autoComplete:`new-password`,minLength:6}),yt.confirmPassword&&yt.password!==yt.confirmPassword&&(0,G.jsx)(`p`,{className:`text-red-700 dark:text-red-400 text-xs mt-1`,children:i(`settings.passwordsDoNotMatch`)})]})]}),Tn?.advanced_auth_enabled&&(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary/50 border border-bambu-green/20 rounded-lg p-3 space-y-3`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`users.form.passwordManagedByAdvancedAuth`)||`Password is managed by Advanced Authentication. Use "Reset Password" to send a new password to the user via email.`}),(0,G.jsx)(Q,{variant:`secondary`,size:`sm`,onClick:()=>dt&&In.mutate(dt),disabled:In.isPending||!yt.email,className:`w-full`,children:In.isPending?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),i(`users.form.resettingPassword`)||`Resetting Password...`]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Vl,{className:`w-4 h-4`}),i(`users.form.resetPassword`)||`Reset Password`]})})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:i(`users.form.groups`)||`Groups`}),(0,G.jsx)(`div`,{className:`space-y-2 max-h-40 overflow-y-auto p-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg`,children:jn.map(e=>(0,G.jsxs)(`label`,{className:`flex items-center gap-3 px-2 py-1.5 rounded hover:bg-bambu-dark-tertiary cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:yt.group_ids.includes(e.id),onChange:()=>Hn(e.id),className:`w-4 h-4 rounded border-bambu-gray text-bambu-green focus:ring-bambu-green focus:ring-offset-0 bg-bambu-dark`}),(0,G.jsx)(`span`,{className:`text-sm text-white`,children:e.name}),e.is_system&&(0,G.jsxs)(`span`,{className:`text-xs text-yellow-700 dark:text-yellow-400`,children:[`(`,i(`users.system`)||`System`,`)`]})]},e.id))})]})]}),(0,G.jsxs)(`div`,{className:`mt-6 flex justify-end gap-3`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>{ut(!1),ft(null),bt({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]})},children:i(`users.modal.cancel`)||`Cancel`}),(0,G.jsx)(Q,{onClick:()=>Bn(dt),disabled:Pn.isPending||!yt.username||Tn?.advanced_auth_enabled&&!yt.email||!!(!Tn?.advanced_auth_enabled&&yt.password&&(yt.password!==yt.confirmPassword||N3(yt.password)!==null)),children:Pn.isPending?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),i(`users.modal.saving`)||`Saving...`]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Wl,{className:`w-4 h-4`}),i(`users.modal.saveChanges`)||`Save Changes`]})})]})]})]})}),pt!==null&&(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/80 flex items-center justify-center z-50 p-4`,onClick:()=>{mt(null),gt(null)},children:(0,G.jsxs)(Md,{className:`w-full max-w-md`,onClick:e=>e.stopPropagation(),children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-red-700 dark:text-red-400`,children:[(0,G.jsx)(ju,{className:`w-5 h-5`}),(0,G.jsx)(`h3`,{className:`text-lg font-semibold`,children:i(`settings.deleteUserTitle`)})]})}),(0,G.jsx)(Pd,{className:`space-y-3`,children:_t?(0,G.jsx)(`div`,{className:`flex items-center justify-center py-4`,children:(0,G.jsx)(`div`,{className:`animate-spin rounded-full h-6 w-6 border-2 border-bambu-green border-t-transparent`})}):ht&&ht.archives+ht.queue_items+ht.library_files>0?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.userHasCreated`)}),(0,G.jsxs)(`ul`,{className:`list-disc list-inside text-bambu-gray space-y-1`,children:[ht.archives>0&&(0,G.jsxs)(`li`,{children:[ht.archives,` archive`,ht.archives===1?``:`s`]}),ht.queue_items>0&&(0,G.jsxs)(`li`,{children:[ht.queue_items,` queue item`,ht.queue_items===1?``:`s`]}),ht.library_files>0&&(0,G.jsxs)(`li`,{children:[ht.library_files,` library file`,ht.library_files===1?``:`s`]})]}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-sm`,children:i(`settings.userItemsQuestion`)}),(0,G.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,G.jsx)(Q,{variant:`danger`,onClick:()=>Fn.mutate({id:pt,deleteItems:!0}),disabled:Fn.isPending,className:`justify-center`,children:i(`settings.deleteUserAndItems`)}),(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>Fn.mutate({id:pt,deleteItems:!1}),disabled:Fn.isPending,className:`justify-center`,children:i(`settings.deleteUserKeepItems`)}),(0,G.jsx)(Q,{variant:`ghost`,onClick:()=>{mt(null),gt(null)},disabled:Fn.isPending,className:`justify-center`,children:i(`common.cancel`)})]})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.deleteUserConfirm`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-sm`,children:i(`settings.actionCannotBeUndone`)}),(0,G.jsxs)(`div`,{className:`flex gap-2 justify-end`,children:[(0,G.jsx)(Q,{variant:`ghost`,onClick:()=>{mt(null),gt(null)},disabled:Fn.isPending,children:i(`common.cancel`)}),(0,G.jsx)(Q,{variant:`danger`,onClick:()=>Fn.mutate({id:pt,deleteItems:!1}),disabled:Fn.isPending,children:i(`settings.deleteUserTitle`)})]})]})})]})}),xt!==null&&(0,G.jsx)(Zd,{title:i(`settings.deleteGroupTitle`),message:i(`settings.deleteGroupMessage`),confirmText:i(`settings.deleteGroup`),variant:`danger`,onConfirm:()=>{Rn.mutate(xt),St(null)},onCancel:()=>St(null)}),ye===`failure-detection`&&(0,G.jsx)(`div`,{id:`card-failure-detection`,children:(0,G.jsx)(AHe,{})}),ye===`backup`&&(0,G.jsxs)(`div`,{id:`card-backup`,children:[(0,G.jsxs)(`div`,{className:`mb-4 p-3 bg-amber-50 dark:bg-amber-500/10 border border-amber-300 dark:border-amber-500/30 rounded-lg flex items-start gap-2`,children:[(0,G.jsx)(iu,{className:`text-amber-600 dark:text-amber-400 flex-shrink-0 mt-0.5`,size:16}),(0,G.jsx)(`p`,{className:`text-sm text-amber-700 dark:text-amber-400`,children:i(`backup.includesEncryptionKey`)})]}),(0,G.jsx)(kHe,{})]}),Ye&&(0,G.jsx)(Zd,{title:i(`settings.disableAuthenticationTitle`),message:i(`settings.disableAuthenticationMessage`),confirmText:i(`settings.disableAuthentication`),variant:`danger`,onConfirm:async()=>{try{await Z.disableAuth(),o(i(`settings.toast.authDisabled`),`success`),await u(),Xe(!1),window.location.href=`/`}catch(e){o(e instanceof Error?e.message:i(`settings.toast.authDisableFailed`),`error`)}},onCancel:()=>Xe(!1)}),Ze&&(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:()=>{Qe(!1),et({currentPassword:``,newPassword:``,confirmPassword:``})},children:(0,G.jsxs)(Md,{className:`w-full max-w-md`,onClick:e=>e.stopPropagation(),children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Uc,{className:`w-5 h-5 text-bambu-green`}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(`settings.changePassword`)})]}),(0,G.jsx)(Q,{variant:`ghost`,size:`sm`,onClick:()=>{Qe(!1),et({currentPassword:``,newPassword:``,confirmPassword:``})},children:(0,G.jsx)($u,{className:`w-5 h-5`})})]})}),(0,G.jsxs)(Pd,{children:[(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:`Current Password`}),(0,G.jsx)(`input`,{type:`password`,value:$e.currentPassword,onChange:e=>et({...$e,currentPassword:e.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:i(`settings.enterCurrentPassword`),autoComplete:`current-password`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:`New Password`}),(0,G.jsx)(`input`,{type:`password`,value:$e.newPassword,onChange:e=>et({...$e,newPassword:e.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:i(`settings.enterNewPasswordMin6`),autoComplete:`new-password`,minLength:6})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:`Confirm New Password`}),(0,G.jsx)(`input`,{type:`password`,value:$e.confirmPassword,onChange:e=>et({...$e,confirmPassword:e.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors ${$e.confirmPassword&&$e.newPassword!==$e.confirmPassword?`border-red-500`:`border-bambu-dark-tertiary`}`,placeholder:i(`settings.confirmNewPassword`),autoComplete:`new-password`,minLength:6}),$e.confirmPassword&&$e.newPassword!==$e.confirmPassword&&(0,G.jsx)(`p`,{className:`text-red-700 dark:text-red-400 text-xs mt-1`,children:i(`settings.passwordsDoNotMatch`)})]})]}),(0,G.jsxs)(`div`,{className:`mt-6 flex justify-end gap-3`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>{Qe(!1),et({currentPassword:``,newPassword:``,confirmPassword:``})},children:i(`common.cancel`)}),(0,G.jsx)(Q,{onClick:async()=>{if($e.newPassword!==$e.confirmPassword){o(i(`settings.toast.passwordsDoNotMatch`),`error`);return}if($e.newPassword.length<6){o(i(`settings.toast.passwordTooShort`),`error`);return}nt(!0);try{await Z.changePassword($e.currentPassword,$e.newPassword),o(i(`settings.toast.passwordChanged`),`success`),Qe(!1),et({currentPassword:``,newPassword:``,confirmPassword:``})}catch(e){o(e instanceof Error?e.message:`Failed to change password`,`error`)}finally{nt(!1)}},disabled:tt||!$e.currentPassword||!$e.newPassword||$e.newPassword!==$e.confirmPassword||$e.newPassword.length<6,children:tt?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),i(`settings.changing`)]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Uc,{className:`w-4 h-4`}),i(`settings.changePassword`)]})})]})]})]})})]})]})]})})}var QHe=/\[(aborted|failed|cancelled):\s*([^\]]*)\]/i;function $He(e){if(!e)return{isPartial:!1,partialType:null,cleanedDescription:null};let t=e.match(QHe);if(!t)return{isPartial:!1,partialType:null,cleanedDescription:e};let n=e.replace(t[0],``).trim();return{isPartial:!0,partialType:t[1].toLowerCase(),cleanedDescription:n||null}}function eUe(e,t){if(!e)return`-`;let n=Kf(e);return n?n.toLocaleString(t):e}function V6(e){let t=e.trim();if(!t)return null;let n=Number.parseFloat(t);return Number.isFinite(n)?n:null}function H6(e){return`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,`0`)}-${String(e.getDate()).padStart(2,`0`)}T${String(e.getHours()).padStart(2,`0`)}:${String(e.getMinutes()).padStart(2,`0`)}`}var U6=`w-full px-3 py-2 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded text-white placeholder-bambu-gray focus:outline-none focus:ring-1 focus:ring-bambu-green`,W6=`block text-sm font-medium text-white mb-1`,G6=`px-4 py-3 text-left text-bambu-gray font-medium`,K6=`px-4 py-3 align-top text-white`;function q6({title:e,onClose:t,children:n,size:r=`md`}){let{t:i}=U();return(0,G.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/70 p-4`,children:(0,G.jsxs)(`div`,{className:`w-full ${r===`sm`?`max-w-xl`:r===`lg`?`max-w-6xl`:`max-w-4xl`} overflow-hidden rounded-lg border border-bambu-dark-tertiary bg-bambu-dark-secondary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between border-b border-bambu-dark-tertiary px-4 py-3`,children:[(0,G.jsx)(`h3`,{className:`text-lg font-semibold text-white`,children:e}),(0,G.jsx)(Q,{size:`sm`,variant:`secondary`,onClick:t,children:i(`common.close`,`Close`)})]}),(0,G.jsx)(`div`,{className:`max-h-[75vh] overflow-auto p-4`,children:n})]})})}function tUe(){let{t:e,i18n:t}=U(),{hasPermission:n,user:r}=Ed(),{showToast:i}=Bd(),a=so(),o=n(`cost_centers:read_own`),s=n(`cost_centers:read_all`),c=n(`cost_centers:create`),l=n(`cost_centers:modify`),u=n(`cost_centers:modify`),d=n(`cost_centers:modify`),f=n(`cost_centers:modify`),p=n(`users:read`),m=s||c||l||u||d||f,h=o||m,g=h,[_,v]=(0,y.useState)(``),[b,x]=(0,y.useState)(`monthly`),[S,C]=(0,y.useState)(``),[w,T]=(0,y.useState)(null),[E,D]=(0,y.useState)(`deposit`),[O,k]=(0,y.useState)(``),[A,j]=(0,y.useState)(``),[M,N]=(0,y.useState)(null),[P,F]=(0,y.useState)(null),[I,L]=(0,y.useState)(null),[R,z]=(0,y.useState)(!0),[B,V]=(0,y.useState)(0),[ee,te]=(0,y.useState)(`all`),[ne,re]=(0,y.useState)(`all`),[ie,ae]=(0,y.useState)(!1),[oe,se]=(0,y.useState)(!1),[H,ce]=(0,y.useState)(!1),[le,ue]=(0,y.useState)(!1),[de,fe]=(0,y.useState)(`personal`),[pe,me]=(0,y.useState)(null),[he,ge]=(0,y.useState)(``),[_e,ve]=(0,y.useState)(`monthly`),[ye,be]=(0,y.useState)(``),[xe,Se]=(0,y.useState)(!1),[Ce,we]=(0,y.useState)(null),[Te,Ee]=(0,y.useState)(null),[De,Oe]=(0,y.useState)(null),[ke,Ae]=(0,y.useState)(``),[je,Me]=(0,y.useState)(``),[Ne,Pe]=(0,y.useState)(!1),[Fe,Ie]=(0,y.useState)(null),[Le,Re]=(0,y.useState)(null),[ze,Be]=(0,y.useState)(``),[Ve,He]=(0,y.useState)(``),[Ue,We]=(0,y.useState)(H6(new Date)),[Ge,Ke]=(0,y.useState)(null),[qe,Je]=(0,y.useState)(null),Ye=s||c||l||u||f&&p||d&&p;(0,y.useEffect)(()=>{Ye||fe(`personal`)},[Ye]);let{data:Xe,isLoading:Ze}=K({queryKey:[`finance`,`me`,`balance`],queryFn:Z.getMyBalance,enabled:o}),{data:Qe,isLoading:$e}=K({queryKey:[`finance`,`me`,`transactions`,50,B],queryFn:()=>Z.getMyTransactions(50,B),enabled:o}),{data:et,isLoading:tt}=K({queryKey:[`finance`,`transactions`,50,B],queryFn:()=>Z.getAllTransactions(50,B),enabled:de===`admin`&&s}),{data:nt,isLoading:rt}=K({queryKey:[`finance`,`cost-centers`,de],queryFn:()=>de===`admin`&&m?Z.listCostCenters(!0):Z.getMyCostCenters(),enabled:g}),{data:it}=K({queryKey:[`users`],queryFn:Z.getUsers,enabled:p&&(g||f||d)}),{data:at}=K({queryKey:[`finance`,`cost-center`,P],queryFn:()=>Z.getCostCenter(P),enabled:d&&P!=null});(0,y.useEffect)(()=>{!it||it.length===0||w!=null&&it.some(e=>e.id===w)||T(it[0].id)},[it,w]),(0,y.useEffect)(()=>{if(!d)return;let e=(nt||[]).filter(e=>!e.is_private);if(e.length===0){F(null);return}P!=null&&e.some(e=>e.id===P)||F(e[0].id)},[d,nt,P]),(0,y.useEffect)(()=>{if(!d||!it||it.length===0)return;let e=new Set((at?.members||[]).map(e=>e.user_id)),t=it.find(t=>!e.has(t.id));L(t?t.id:null)},[d,it,at]),(0,y.useEffect)(()=>{if(!le)return;let e=nt||[];if(e.length===0){me(null);return}pe!=null&&e.some(e=>e.id===pe)||me(e[0].id)},[le,pe,nt]),(0,y.useEffect)(()=>{if(!le||pe==null)return;let e=(nt||[]).find(e=>e.id===pe);if(e){if(ge(e.name),e.budget_mode===`total`){ve(`total`),be(e.total_budget==null?``:String(e.total_budget));return}ve(`monthly`),be(e.monthly_budget==null?``:String(e.monthly_budget))}},[le,pe,nt]);let ot=q({mutationFn:()=>Z.createCostCenter({name:_.trim(),total_budget:b===`total`?V6(S):null,monthly_budget:b===`monthly`?V6(S):null,is_active:!0}),onSuccess:()=>{a.invalidateQueries({queryKey:[`finance`]}),v(``),C(``),i(e(`finance.createdCostCenter`,`Cost center created`))},onError:t=>{i(t.message||e(`finance.createCostCenterFailed`,`Failed to create cost center`),`error`)}}),st=q({mutationFn:({costCenterId:e,value:t,mode:n})=>Z.updateCostCenterBudgets(e,{total_budget:n===`total`?V6(t):null,monthly_budget:n===`monthly`?V6(t):null})}),ct=q({mutationFn:({costCenterId:e,name:t})=>Z.updateCostCenter(e,{name:t})}),lt=q({mutationFn:e=>Z.deleteCostCenter(e)}),ut=q({mutationFn:e=>Z.deleteTransaction(e),onSuccess:()=>{a.invalidateQueries({queryKey:[`finance`]}),i(e(`finance.transactionDeleted`,`Transaction deleted`))},onError:t=>{i(t.message||e(`finance.deleteTransactionFailed`,`Failed to delete transaction`),`error`)}}),dt=q({mutationFn:e=>Z.editTransaction(e.transactionId,e.data),onSuccess:()=>{a.invalidateQueries({queryKey:[`finance`]}),i(e(`finance.transactionEdited`,`Transaction updated and ledger recalculated`)),Se(!1)},onError:t=>{i(t.message||e(`finance.editTransactionFailed`,`Failed to edit transaction`),`error`)}}),ft=q({mutationFn:e=>Z.createManualPrint(e),onSuccess:()=>{a.invalidateQueries({queryKey:[`finance`]}),i(e(`finance.manualPrintCreated`,`Manual print charge added and ledger recalculated`)),Pe(!1),Ie(null),Re(null),Be(``),He(``),We(H6(new Date))},onError:t=>{i(t.message||e(`finance.manualPrintFailed`,`Failed to create manual print`),`error`)}}),pt=q({mutationFn:e=>Z.depositUserBalance(e.userId,{amount:e.amount,description:e.description,cost_center_id:e.costCenterId??null})}),mt=q({mutationFn:e=>Z.withdrawUserBalance(e.userId,{amount:e.amount,description:e.description,cost_center_id:e.costCenterId??null})}),ht=q({mutationFn:e=>Z.upsertCostCenterMember(e.costCenterId,{user_id:e.userId,can_print:e.canPrint}),onSuccess:()=>{a.invalidateQueries({queryKey:[`finance`]}),i(e(`finance.memberSaved`,`Member saved`))},onError:t=>{i(t.message||e(`finance.memberSaveFailed`,`Failed to save member`),`error`)}}),gt=q({mutationFn:e=>Z.removeCostCenterMember(e.costCenterId,e.userId),onSuccess:()=>{a.invalidateQueries({queryKey:[`finance`]}),i(e(`finance.memberRemoved`,`Member removed`))},onError:t=>{i(t.message||e(`finance.memberRemoveFailed`,`Failed to remove member`),`error`)}}),_t=pt.isPending||mt.isPending,vt=()=>{if(!_.trim()){i(e(`finance.costCenterNameRequired`,`Cost center name is required`),`error`);return}ot.mutate()},yt=async()=>{if(pe==null){i(e(`finance.selectCostCenter`,`Please select a cost center`),`error`);return}let t=he.trim();if(!t){i(e(`finance.costCenterNameRequired`,`Cost center name is required`),`error`);return}try{l&&await ct.mutateAsync({costCenterId:pe,name:t}),u&&await st.mutateAsync({costCenterId:pe,mode:_e,value:ye}),a.invalidateQueries({queryKey:[`finance`]}),i(e(`finance.costCenterUpdated`,`Cost center updated`)),ue(!1)}catch(t){i(t.message||e(`finance.costCenterUpdateFailed`,`Failed to update cost center`),`error`)}},bt=e=>{let t=(nt||[]).find(t=>t.id===e);t&&(me(t.id),ge(t.name),t.budget_mode===`total`?(ve(`total`),be(t.total_budget==null?``:String(t.total_budget))):(ve(`monthly`),be(t.monthly_budget==null?``:String(t.monthly_budget))),ue(!0))},xt=async()=>{if(Ge)try{await lt.mutateAsync(Ge.id),a.invalidateQueries({queryKey:[`finance`]}),P===Ge.id&&F(null),i(e(`finance.costCenterDeleted`,`Cost center deleted`))}catch(t){i(t.message||e(`finance.costCenterDeleteFailed`,`Failed to delete cost center`),`error`)}finally{Ke(null)}},St=()=>{qe!=null&&ut.mutate(qe,{onSettled:()=>Je(null)})},Ct=e=>{we(e.id),Ee(e.user_id),Oe(e.cost_center_id),Ae(String(e.amount)),Me(e.description||``),Se(!0)},wt=async()=>{if(Ce==null)return;let t=ke?Number.parseFloat(ke):null;if(t!==null&&!Number.isFinite(t)){i(e(`finance.amountInvalid`,`Amount must be a valid number`),`error`);return}dt.mutate({transactionId:Ce,data:{user_id:Te||void 0,cost_center_id:De||void 0,amount:t??void 0,description:je||void 0}})},Tt=async()=>{if(Fe==null){i(e(`finance.userRequired`,`Please select a user`),`error`);return}if(Le==null){i(e(`finance.costCenterRequired`,`Please select a cost center`),`error`);return}let t=ze?Number.parseFloat(ze):null;if(t===null||!Number.isFinite(t)){i(e(`finance.amountInvalid`,`Amount must be a valid number`),`error`);return}t=Math.abs(t),ft.mutate({user_id:Fe,cost_center_id:Le,amount:t,description:Ve||void 0,created_at:Ue?new Date(Ue).toISOString():void 0})},Et=async()=>{if(w==null){i(e(`finance.userRequired`,`Please select a user`),`error`);return}let t=Number.parseFloat(O);if(!Number.isFinite(t)||t<=0){i(e(`finance.amountMustBePositive`,`Amount must be greater than zero`),`error`);return}let n={userId:w,amount:t,description:A.trim()||void 0,costCenterId:M};try{E===`deposit`?await pt.mutateAsync(n):await mt.mutateAsync(n),a.invalidateQueries({queryKey:[`finance`]}),k(``),j(``),i(E===`deposit`?e(`finance.depositSuccess`,`Deposit successful`):e(`finance.withdrawSuccess`,`Withdrawal successful`))}catch(t){i(t.message||e(`finance.adjustmentFailed`,`Wallet adjustment failed`),`error`)}},Dt=()=>{if(P==null){i(e(`finance.selectCostCenter`,`Please select a cost center`),`error`);return}if(I==null){i(e(`finance.noEligibleUsers`,`No eligible users available`),`error`);return}ht.mutate({costCenterId:P,userId:I,canPrint:R})},Ot=e=>{P!=null&>.mutate({costCenterId:P,userId:e})},kt=Ef(Xe?.currency||`EUR`),At=(0,y.useMemo)(()=>[...it||[]].sort((e,t)=>e.username.localeCompare(t.username)),[it]),jt=(0,y.useMemo)(()=>{let e=new Map;for(let t of At)e.set(t.id,t.username);return e},[At]),Mt=(0,y.useMemo)(()=>{let e=new Set((at?.members||[]).map(e=>e.user_id));return At.filter(t=>!e.has(t.id))},[At,at]),Nt=de===`admin`&&s?et:Qe,Pt=de===`admin`&&s?tt:$e,Ft=(0,y.useMemo)(()=>Nt?.items??[],[Nt?.items]),It=Nt?.total??0,Lt=Math.max(1,Math.ceil(It/50)),Rt=(0,y.useMemo)(()=>Ft.filter(e=>!(ee!==`all`&&e.transaction_type!==ee||ne!==`all`&&e.cost_center_id!==ne)),[Ft,ee,ne]),zt=Math.floor(B/50)+1,Bt=de===`admin`,Vt=t=>t===`deposit`?e(`finance.deposit`):t===`withdraw`?e(`finance.withdraw`):t===`print_charge`?e(`finance.printCharge`):t,W=t=>t==null?e(`finance.personal`,`Personal`):jt.get(t)||(r?.id===t&&r.username?r.username:e(`finance.userWithId`,`User #{{id}}`,{id:t})),Ht=t=>t.budget_limit==null||t.budget_available==null?e(`finance.unlimited`,`Unlimited`):`${kt}${t.budget_available.toFixed(2)}/${kt}${t.budget_limit.toFixed(2)}`;return h?(0,G.jsxs)(`div`,{className:`p-4 md:p-8 space-y-8`,children:[(0,G.jsxs)(`div`,{className:`flex flex-col gap-4 lg:flex-row lg:items-start lg:justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Gu,{className:`h-6 w-6 text-bambu-green`}),(0,G.jsx)(`h1`,{className:`text-2xl font-bold text-white`,children:e(`finance.title`,`Finance`)})]}),(0,G.jsx)(`p`,{className:`text-bambu-gray mt-2 max-w-2xl`,children:e(`finance.subtitle`,`Wallet, personal transactions, and cost centers`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1 max-w-2xl`,children:e(`finance.budgetPolicyHint`,`Account balances track costs. Printing is limited only by the selected cost center budget; without a budget, printing is unlimited.`)})]}),(0,G.jsxs)(`div`,{className:`flex flex-col gap-2 lg:items-end`,children:[Ye&&(0,G.jsxs)(`div`,{className:`inline-flex overflow-hidden rounded border border-bambu-dark-tertiary`,children:[(0,G.jsx)(`button`,{type:`button`,onClick:()=>fe(`personal`),className:`px-3 py-1.5 text-sm ${de===`personal`?`bg-bambu-green text-black font-medium`:`bg-bambu-dark text-bambu-gray`}`,children:e(`finance.personalView`,`Personal view`)}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>fe(`admin`),className:`px-3 py-1.5 text-sm ${de===`admin`?`bg-bambu-green text-black font-medium`:`bg-bambu-dark text-bambu-gray`}`,children:e(`finance.adminView`,`Admin view`)})]}),de===`admin`&&Ye&&(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-2 lg:justify-end`,children:[c&&(0,G.jsx)(Q,{size:`sm`,variant:`secondary`,onClick:()=>ae(!0),children:e(`finance.createCostCenter`,`Create cost center`)}),f&&p&&(0,G.jsx)(Q,{size:`sm`,variant:`secondary`,onClick:()=>se(!0),children:e(`finance.adjustWallet`,`Adjust wallet`)}),f&&p&&(0,G.jsx)(Q,{size:`sm`,variant:`secondary`,onClick:()=>Pe(!0),children:e(`finance.addManualPrint`,`Add manual print`)}),d&&p&&(0,G.jsx)(Q,{size:`sm`,variant:`secondary`,onClick:()=>ce(!0),children:e(`finance.manageMembers`,`Manage cost center members`)})]})]})]}),(0,G.jsxs)(`div`,{className:`grid gap-5 md:grid-cols-2 xl:grid-cols-3`,children:[(0,G.jsxs)(Md,{children:[(0,G.jsxs)(Nd,{className:`flex flex-row items-center justify-between pb-2`,children:[(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e(`finance.currentBalance`,`Personal account balance`)}),(0,G.jsx)(Gu,{className:`w-4 h-4 text-bambu-green/90`})]}),(0,G.jsx)(Pd,{className:`pt-1`,children:(0,G.jsx)(`p`,{className:`text-3xl font-semibold text-white leading-tight`,children:Ze?e(`common.loading`,`Loading...`):`${kt}${(Xe?.balance??0).toFixed(2)}`})})]}),(0,G.jsxs)(Md,{children:[(0,G.jsxs)(Nd,{className:`flex flex-row items-center justify-between pb-2`,children:[(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:de===`admin`?e(`finance.transactions`,`Transactions`):e(`finance.personalTransactions`,`Personal transactions`)}),(0,G.jsx)(Os,{className:`w-4 h-4 text-blue-400`})]}),(0,G.jsx)(Pd,{className:`pt-1`,children:(0,G.jsx)(`p`,{className:`text-3xl font-semibold text-white leading-tight`,children:Pt?`-`:It})})]}),(0,G.jsxs)(Md,{children:[(0,G.jsxs)(Nd,{className:`flex flex-row items-center justify-between pb-2`,children:[(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e(`finance.costCenters`,`Cost centers`)}),(0,G.jsx)(Qo,{className:`w-4 h-4 text-orange-400`})]}),(0,G.jsx)(Pd,{className:`pt-1`,children:(0,G.jsx)(`p`,{className:`text-3xl font-semibold text-white leading-tight`,children:rt?`-`:nt?.length??0})})]})]}),ie&&c&&(0,G.jsx)(q6,{title:e(`finance.createCostCenter`,`Create cost center`),size:`md`,onClose:()=>ae(!1),children:(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:W6,children:e(`finance.costCenterName`,`Name`)}),(0,G.jsx)(`input`,{type:`text`,value:_,onChange:e=>v(e.target.value),placeholder:e(`finance.costCenterName`,`Name`),className:U6})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:W6,children:e(`finance.budgetType`,`Budget type`)}),(0,G.jsxs)(`select`,{value:b,onChange:e=>x(e.target.value),className:U6,children:[(0,G.jsx)(`option`,{value:`monthly`,children:e(`finance.monthlyBudget`,`Monthly budget`)}),(0,G.jsx)(`option`,{value:`total`,children:e(`finance.totalBudget`,`Total budget`)})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:W6,children:b===`monthly`?e(`finance.monthlyBudget`,`Monthly budget`):e(`finance.totalBudget`,`Total budget`)}),(0,G.jsx)(`input`,{type:`number`,step:`0.01`,value:S,onChange:e=>C(e.target.value),placeholder:`0.00`,className:U6})]})]}),(0,G.jsx)(Q,{className:`min-w-[180px]`,onClick:vt,disabled:ot.isPending,children:ot.isPending?e(`common.saving`,`Saving...`):e(`finance.create`,`Create`)})]})}),oe&&f&&p&&(0,G.jsx)(q6,{title:e(`finance.adjustWallet`,`Adjust wallet`),size:`md`,onClose:()=>se(!1),children:(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:W6,children:e(`finance.selectUser`,`Select user`)}),(0,G.jsx)(`select`,{value:w??``,onChange:e=>T(e.target.value?Number(e.target.value):null),className:U6,children:(At||[]).map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.username},e.id))})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:W6,children:e(`finance.transactionType`,`Type`)}),(0,G.jsxs)(`select`,{value:E,onChange:e=>D(e.target.value),className:U6,children:[(0,G.jsx)(`option`,{value:`deposit`,children:e(`finance.deposit`,`Deposit`)}),(0,G.jsx)(`option`,{value:`withdraw`,children:e(`finance.withdraw`,`Withdraw`)})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:W6,children:e(`finance.amount`,`Amount`)}),(0,G.jsx)(`input`,{type:`number`,step:`0.01`,min:`0`,value:O,onChange:e=>k(e.target.value),placeholder:`0.00`,className:U6})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:W6,children:e(`finance.costCenters`,`Cost centers`)}),(0,G.jsxs)(`select`,{value:M??``,onChange:e=>N(e.target.value?Number(e.target.value):null),className:U6,children:[(0,G.jsx)(`option`,{value:``,children:e(`finance.noCostCenter`,`No cost center`)}),(nt||[]).map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:W6,children:e(`common.description`,`Description`)}),(0,G.jsx)(`input`,{type:`text`,value:A,onChange:e=>j(e.target.value),placeholder:e(`finance.descriptionOptional`,`Description (optional)`),className:U6})]}),(0,G.jsx)(Q,{className:`min-w-[180px]`,onClick:Et,disabled:_t,children:_t?e(`common.saving`,`Saving...`):e(`finance.applyAdjustment`,`Apply adjustment`)})]})}),H&&d&&p&&(0,G.jsx)(q6,{title:e(`finance.manageMembers`,`Manage cost center members`),size:`lg`,onClose:()=>ce(!1),children:(0,G.jsxs)(`div`,{className:`space-y-5`,children:[(0,G.jsxs)(`div`,{className:`grid gap-5 md:grid-cols-2`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:W6,children:e(`finance.costCenters`,`Cost centers`)}),(0,G.jsx)(`select`,{value:P??``,onChange:e=>F(e.target.value?Number(e.target.value):null),className:U6,children:(nt||[]).filter(e=>!e.is_private).map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.name},e.id))})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:W6,children:e(`finance.selectUser`,`Select user`)}),(0,G.jsxs)(`select`,{value:I??``,onChange:e=>L(e.target.value?Number(e.target.value):null),className:U6,children:[(0,G.jsx)(`option`,{value:``,children:e(`finance.selectUser`,`Select user`)}),Mt.map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.username},e.id))]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 rounded border border-bambu-dark-tertiary bg-bambu-dark-secondary px-3 py-2`,children:[(0,G.jsx)(`input`,{id:`memberCanPrint`,type:`checkbox`,checked:R,onChange:e=>z(e.target.checked),className:`rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,G.jsx)(`label`,{htmlFor:`memberCanPrint`,className:`text-sm text-bambu-gray`,children:e(`finance.memberCanPrint`,`Member can print`)})]}),(0,G.jsx)(`div`,{className:`flex items-end`,children:(0,G.jsx)(Q,{className:`min-w-[180px]`,onClick:Dt,disabled:ht.isPending||I==null,children:ht.isPending?e(`common.saving`,`Saving...`):e(`finance.addMember`,`Add member`)})})]}),(0,G.jsx)(`div`,{className:`overflow-auto rounded-lg border border-bambu-dark-tertiary`,children:(0,G.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,G.jsx)(`thead`,{children:(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary bg-bambu-dark text-bambu-gray`,children:[(0,G.jsx)(`th`,{className:G6,children:e(`common.name`,`Name`)}),(0,G.jsx)(`th`,{className:G6,children:e(`finance.canPrint`,`Can print`)}),(0,G.jsx)(`th`,{className:G6,children:e(`common.actions`,`Actions`)})]})}),(0,G.jsxs)(`tbody`,{children:[(at?.members||[]).map(t=>(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/60 text-white`,children:[(0,G.jsx)(`td`,{className:K6,children:At.find(e=>e.id===t.user_id)?.username||`User ${t.user_id}`}),(0,G.jsx)(`td`,{className:K6,children:t.can_print?e(`common.yes`,`Yes`):e(`common.no`,`No`)}),(0,G.jsx)(`td`,{className:K6,children:(0,G.jsx)(Q,{size:`sm`,variant:`danger`,onClick:()=>Ot(t.user_id),disabled:gt.isPending,children:e(`common.remove`,`Remove`)})})]},t.id)),(at?.members||[]).length===0&&(0,G.jsx)(`tr`,{children:(0,G.jsx)(`td`,{colSpan:3,className:`py-3 text-bambu-gray`,children:e(`finance.noMembers`,`No members assigned.`)})})]})]})})]})}),le&&(l||u)&&(0,G.jsx)(q6,{title:e(`finance.editCostCenter`,`Edit cost center`),size:`md`,onClose:()=>ue(!1),children:(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:W6,children:e(`finance.costCenterName`,`Name`)}),(0,G.jsx)(`input`,{type:`text`,value:he,onChange:e=>ge(e.target.value),placeholder:e(`finance.costCenterName`,`Name`),className:U6,disabled:!l})]}),(0,G.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:W6,children:e(`finance.budgetType`,`Budget type`)}),(0,G.jsxs)(`select`,{value:_e,onChange:e=>ve(e.target.value),className:U6,disabled:!u,children:[(0,G.jsx)(`option`,{value:`monthly`,children:e(`finance.monthlyBudget`,`Monthly budget`)}),(0,G.jsx)(`option`,{value:`total`,children:e(`finance.totalBudget`,`Total budget`)})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:W6,children:_e===`monthly`?e(`finance.monthlyBudget`,`Monthly budget`):e(`finance.totalBudget`,`Total budget`)}),(0,G.jsx)(`input`,{type:`number`,step:`0.01`,value:ye,onChange:e=>be(e.target.value),placeholder:`0.00`,className:U6,disabled:!u})]})]}),(0,G.jsx)(Q,{className:`min-w-[180px]`,onClick:yt,disabled:ct.isPending||st.isPending||pe==null,children:ct.isPending||st.isPending?e(`common.saving`,`Saving...`):e(`common.save`,`Save`)})]})}),(0,G.jsxs)(`div`,{className:`grid gap-6 ${g&&o?`xl:grid-cols-2`:``}`,children:[g&&(0,G.jsxs)(Md,{children:[(0,G.jsxs)(Nd,{children:[(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`finance.myCostCenters`,`My cost centers`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:e(`finance.costCentersHint`,`Review budget limits and keep costs under control`)})]}),(0,G.jsxs)(Pd,{className:`space-y-3`,children:[rt&&(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`common.loading`,`Loading...`)}),!rt&&(!nt||nt.length===0)&&(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`finance.noCostCenters`,`No cost centers found.`)}),!rt&&nt&&nt.length>0&&(0,G.jsx)(`div`,{className:`overflow-auto rounded-lg border border-bambu-dark-tertiary`,children:(0,G.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,G.jsx)(`thead`,{children:(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary bg-bambu-dark text-bambu-gray`,children:[(0,G.jsx)(`th`,{className:G6,children:e(`common.name`,`Name`)}),Bt&&(0,G.jsx)(`th`,{className:G6,children:e(`finance.owner`,`Owner`)}),(0,G.jsx)(`th`,{className:G6,children:e(`finance.balance`,`Account balance`)}),(0,G.jsx)(`th`,{className:G6,children:e(`finance.budget`,`Budget`)}),Bt&&(0,G.jsx)(`th`,{className:G6,children:e(`common.actions`,`Actions`)})]})}),(0,G.jsx)(`tbody`,{children:nt.map(t=>{let n=l||u,r=!t.is_private&&l;return(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/60 text-white`,children:[(0,G.jsx)(`td`,{className:K6,children:t.name}),Bt&&(0,G.jsx)(`td`,{className:K6,children:t.is_private?W(t.owner_user_id):e(`finance.shared`,`Shared`)}),(0,G.jsxs)(`td`,{className:K6,children:[kt,t.total_balance.toFixed(2)]}),(0,G.jsx)(`td`,{className:K6,children:(0,G.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[(0,G.jsx)(`span`,{children:Ht(t)}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:t.budget_mode===`monthly`?e(`finance.monthlyBudget`,`Monthly budget`):t.budget_mode===`total`?e(`finance.totalBudget`,`Total budget`):e(`finance.noBudget`,`No budget`)})]})}),Bt&&(0,G.jsx)(`td`,{className:K6,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Q,{size:`sm`,variant:`ghost`,onClick:()=>bt(t.id),disabled:!n,title:n?e(`common.edit`,`Edit`):e(`finance.cannotEditPrivateCostCenter`,`Private cost centers cannot be edited here`),className:`p-1.5 sm:p-2`,children:(0,G.jsx)(Ol,{className:`w-4 h-4`})}),r&&(0,G.jsx)(Q,{size:`sm`,variant:`ghost`,onClick:()=>Ke({id:t.id,name:t.name}),disabled:lt.isPending,title:e(`common.delete`,`Delete`),className:`text-red-400 hover:text-red-300 hover:bg-red-500/10 p-1.5 sm:p-2`,children:(0,G.jsx)(ju,{className:`w-4 h-4`})})]})})]},t.id)})})]})})]})]}),o&&(0,G.jsxs)(Md,{children:[(0,G.jsxs)(Nd,{children:[(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`finance.recentTransactions`,`Recent transactions`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:e(`finance.transactionsHint`,`Filter by type and cost center, then navigate pages`)})]}),(0,G.jsxs)(Pd,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{className:`grid gap-4 lg:grid-cols-[minmax(0,1fr)_minmax(0,1fr)_auto] xl:grid-cols-[minmax(0,1fr)_minmax(0,1fr)_minmax(0,1fr)_auto] items-end`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:W6,children:e(`finance.transactionType`,`Type`)}),(0,G.jsxs)(`select`,{value:ee,onChange:e=>te(e.target.value),className:U6,children:[(0,G.jsx)(`option`,{value:`all`,children:e(`finance.allTypes`)}),(0,G.jsx)(`option`,{value:`deposit`,children:e(`finance.deposit`)}),(0,G.jsx)(`option`,{value:`withdraw`,children:e(`finance.withdraw`)}),(0,G.jsx)(`option`,{value:`print_charge`,children:e(`finance.printCharge`)})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:W6,children:e(`finance.costCenters`,`Cost centers`)}),(0,G.jsxs)(`select`,{value:ne,onChange:e=>re(e.target.value===`all`?`all`:Number(e.target.value)),className:U6,children:[(0,G.jsx)(`option`,{value:`all`,children:e(`finance.allCostCenters`)}),(nt||[]).map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]})]}),Pt&&(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`common.loading`,`Loading...`)}),!Pt&&(!Ft||Ft.length===0)&&(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`finance.noTransactions`,`No transactions available.`)}),!Pt&&Ft.length>0&&Rt.length===0&&(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`finance.noTransactionsForFilter`,`No transactions match the selected filters.`)}),!Pt&&Rt.length>0&&(0,G.jsx)(`div`,{className:`overflow-auto rounded-lg border border-bambu-dark-tertiary`,children:(0,G.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,G.jsx)(`thead`,{children:(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary bg-bambu-dark text-bambu-gray`,children:[(0,G.jsx)(`th`,{className:G6,children:e(`common.date`,`Date`)}),Bt&&(0,G.jsx)(`th`,{className:G6,children:e(`common.user`,`User`)}),(0,G.jsx)(`th`,{className:G6,children:e(`finance.costCenter`,`Cost center`)}),(0,G.jsx)(`th`,{className:G6,children:e(`finance.transactionType`,`Type`)}),(0,G.jsx)(`th`,{className:G6,children:e(`common.description`,`Description`)}),(0,G.jsx)(`th`,{className:G6,children:e(`finance.amount`,`Amount`)}),(0,G.jsx)(`th`,{className:G6,children:e(`finance.balanceAfter`,`Balance after`)}),Bt&&(0,G.jsx)(`th`,{className:G6,children:e(`common.actions`,`Actions`)})]})}),(0,G.jsx)(`tbody`,{children:Rt.map(n=>{let r=n.amount>=0,i=n.cost_center_id==null?null:(nt||[]).find(e=>e.id===n.cost_center_id),a=jt.get(n.user_id),o=n.transaction_type===`print_charge`?$He(n.description??null):null,s=o?.isPartial??!1;return(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/60 text-white`,children:[(0,G.jsx)(`td`,{className:K6,children:eUe(n.created_at,t.language)}),Bt&&(0,G.jsx)(`td`,{className:K6,children:a||e(`finance.userWithId`,`User #{{id}}`,{id:n.user_id})}),(0,G.jsx)(`td`,{className:K6,children:i?.name||`-`}),(0,G.jsx)(`td`,{className:K6,children:(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,G.jsx)(`span`,{children:Vt(n.transaction_type)}),s&&(0,G.jsx)(`span`,{className:`rounded border border-yellow-500/40 bg-yellow-500/10 px-2 py-0.5 text-[11px] text-yellow-300`,children:o&&o.partialType?e(`finance.partialStatus.${o.partialType}`,o.partialType):e(`finance.partial`,`Partial`)})]})}),(0,G.jsx)(`td`,{className:K6,children:(o?.cleanedDescription??n.description)||`-`}),(0,G.jsxs)(`td`,{className:`${K6} ${r?`text-green-400`:`text-red-400`}`,children:[r?`+`:`-`,kt,Math.abs(n.amount).toFixed(2)]}),(0,G.jsx)(`td`,{className:K6,children:n.balance_after==null?`-`:`${n.balance_after<0?`-`:``}${kt}${Math.abs(n.balance_after).toFixed(2)}`}),Bt&&(0,G.jsx)(`td`,{className:K6,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Q,{size:`sm`,variant:`secondary`,onClick:()=>Ct(n),disabled:dt.isPending,children:(0,G.jsx)(Ol,{className:`w-4 h-4`})}),(0,G.jsx)(Q,{size:`sm`,variant:`danger`,onClick:()=>Je(n.id),disabled:ut.isPending,children:(0,G.jsx)(ju,{className:`w-4 h-4`})})]})})]},n.id)})})]})}),!Pt&&Rt.length>0&&(0,G.jsx)(`div`,{className:`flex justify-end pt-2 lg:pt-0`,children:(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[(0,G.jsx)(`button`,{type:`button`,onClick:()=>V(0),disabled:B===0||Pt,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,"aria-label":e(`finance.first`,`First`),children:(0,G.jsx)(hs,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>V(e=>Math.max(0,e-50)),disabled:B===0||Pt,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,"aria-label":e(`finance.prev`,`Previous`),children:(0,G.jsx)(ps,{className:`w-4 h-4`})}),(0,G.jsx)(`span`,{className:`text-bambu-gray px-1 whitespace-nowrap`,children:e(`finance.pageNumberOf`,`Page {{page}} of {{total}}`,{page:zt,total:Lt})}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>V(e=>e+50),disabled:Pt||zt>=Lt,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,"aria-label":e(`finance.next`,`Next`),children:(0,G.jsx)(fs,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>V(Math.max(0,(Lt-1)*50)),disabled:Pt||zt>=Lt,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,"aria-label":e(`finance.last`,`Last`),children:(0,G.jsx)(gs,{className:`w-4 h-4`})})]})})]})]}),xe&&Ce!==null&&(0,G.jsx)(q6,{title:e(`finance.editTransaction`,`Edit Transaction`),onClose:()=>Se(!1),size:`md`,children:(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:W6,children:e(`common.user`,`User`)}),(0,G.jsxs)(`select`,{className:U6,value:Te||``,onChange:e=>Ee(e.target.value?Number(e.target.value):null),children:[(0,G.jsx)(`option`,{value:``,children:e(`finance.selectUser`,`Select user...`)}),At.map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.username},e.id))]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:W6,children:e(`finance.costCenter`,`Cost center (optional)`)}),(0,G.jsxs)(`select`,{className:U6,value:De||``,onChange:e=>Oe(e.target.value?Number(e.target.value):null),children:[(0,G.jsx)(`option`,{value:``,children:e(`finance.noCostCenter`,`Personal (no cost center)`)}),(nt||[]).map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:W6,children:e(`finance.amount`,`Amount`)}),(0,G.jsx)(`input`,{type:`number`,step:`0.01`,className:U6,value:ke,onChange:e=>Ae(e.target.value),placeholder:e(`finance.amountExample`,`e.g., 10.50`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:W6,children:e(`common.description`,`Description`)}),(0,G.jsx)(`textarea`,{className:`${U6} resize-none`,rows:3,value:je,onChange:e=>Me(e.target.value),placeholder:e(`finance.manualAdjustmentExample`,`e.g., Manual adjustment`)})]}),(0,G.jsxs)(`div`,{className:`flex justify-end gap-2 pt-4`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>Se(!1),children:e(`common.cancel`,`Cancel`)}),(0,G.jsx)(Q,{onClick:wt,disabled:dt.isPending,children:e(`common.save`,`Save`)})]})]})}),Ne&&(0,G.jsx)(q6,{title:e(`finance.addManualPrint`,`Add manual print`),onClose:()=>Pe(!1),size:`md`,children:(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:W6,children:e(`common.user`,`User`)}),(0,G.jsxs)(`select`,{className:U6,value:Fe||``,onChange:e=>Ie(e.target.value?Number(e.target.value):null),children:[(0,G.jsx)(`option`,{value:``,children:e(`finance.selectUser`,`Select user...`)}),At.map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.username},e.id))]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:W6,children:e(`finance.costCenter`,`Cost center`)}),(0,G.jsxs)(`select`,{className:U6,value:Le||``,onChange:e=>Re(e.target.value?Number(e.target.value):null),children:[(0,G.jsx)(`option`,{value:``,children:e(`finance.selectCostCenter`,`Select cost center...`)}),(nt||[]).map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:W6,children:e(`finance.amount`,`Amount`)}),(0,G.jsx)(`input`,{type:`number`,step:`0.01`,className:U6,value:ze,onChange:e=>Be(e.target.value),placeholder:e(`finance.amountExample`,`e.g., 4.00`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:W6,children:e(`common.description`,`Description`)}),(0,G.jsx)(`input`,{type:`text`,value:Ve,onChange:e=>He(e.target.value),placeholder:e(`finance.descriptionOptional`,`Description (optional)`),className:U6})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:W6,children:e(`common.date`,`Date`)}),(0,G.jsx)(`input`,{type:`datetime-local`,value:Ue,onChange:e=>We(e.target.value),className:U6})]}),(0,G.jsxs)(`div`,{className:`flex justify-end gap-2 pt-4`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>Pe(!1),children:e(`common.cancel`,`Cancel`)}),(0,G.jsx)(Q,{onClick:Tt,disabled:ft.isPending,children:ft.isPending?e(`common.saving`,`Saving...`):e(`finance.addManualPrint`,`Add manual print`)})]})]})}),Ge&&(0,G.jsx)(Zd,{title:e(`common.delete`,`Delete`),message:e(`finance.confirmDeleteCostCenter`,`Delete cost center "{{name}}"?`,{name:Ge.name}),confirmText:e(`common.delete`,`Delete`),variant:`danger`,isLoading:lt.isPending,onConfirm:xt,onCancel:()=>Ke(null)}),qe!=null&&(0,G.jsx)(Zd,{title:e(`finance.deleteTransaction`,`Delete transaction`),message:e(`finance.deleteTransactionConfirm`,`Delete this transaction? Balances will be recalculated automatically.`),confirmText:e(`common.delete`,`Delete`),variant:`danger`,isLoading:ut.isPending,onConfirm:St,onCancel:()=>Je(null)})]})]}):(0,G.jsxs)(`div`,{className:`p-4 md:p-8 space-y-6`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Gu,{className:`h-6 w-6 text-bambu-green`}),(0,G.jsx)(`h1`,{className:`text-2xl font-bold text-white`,children:e(`finance.title`,`Finance`)})]}),(0,G.jsx)(`div`,{children:(0,G.jsx)(`p`,{className:`text-bambu-gray mt-2 max-w-2xl`,children:e(`finance.subtitle`,`Wallet, personal transactions, and cost centers`)})}),(0,G.jsx)(Md,{children:(0,G.jsx)(Pd,{className:`py-8 text-center text-bambu-gray`,children:e(`finance.noAccess`,`You do not have permission to view finance data.`)})})]})}var J6={PLA:`GFL99`,"PLA-CF":`GFL98`,"PLA SILK":`GFL96`,"PLA HIGH SPEED":`GFL95`,PETG:`GFG99`,"PETG HF":`GFG96`,"PETG-CF":`GFG98`,PCTG:`GFG97`,ABS:`GFB99`,ASA:`GFB98`,PC:`GFC99`,PA:`GFN99`,"PA-CF":`GFN98`,NYLON:`GFN99`,TPU:`GFU99`,PVA:`GFS99`,HIPS:`GFS98`,PE:`GFP99`,PP:`GFP97`};function Y6(e){let t=(e||``).toUpperCase().trim();return t&&(J6[t]||J6[t.replace(/[-\s]?CF$/,``)]||J6[t.replace(/\+$/,``)]||J6[t.split(/[-\s]/)[0]])||``}function X6(e){let t=e.replace(/@.+$/,``).trim();return t.startsWith(`# `)?t.slice(2).trim():t}var Z6={local:0,orca_cloud:1,cloud:2,builtin:3};function nUe(e){let{localPresets:t,orcaProfiles:n,cloudSettings:r,builtinFilaments:i}=e,a=[],o=e=>e.trim().toLowerCase(),s=new Set,c=new Set,l=new Set,u=(e,t,...n)=>{let r=n.filter(e=>!!e);if(r.some(e=>s.has(e)))return!1;let i=`${e}|${o(t)}`;return c.has(i)?!1:(r.forEach(e=>s.add(e)),c.add(i),l.add(o(t)),!0)};for(let e of t??[]){let t=X6(e.name),n=e.filament_type||pU(t).material;u(`local`,t)&&a.push({id:`local_${e.id}`,name:t,source:`local`,filamentId:Y6(n),filamentType:n||``})}for(let e of n??[]){let t=X6(e.name),n=pU(t).material;u(`orca_cloud`,t,e.setting_id)&&a.push({id:`orca_${e.setting_id}`,name:t,source:`orca_cloud`,filamentId:Y6(n),filamentType:n})}for(let e of r??[]){let t=X6(e.name),n=e.setting_id.startsWith(`GFS`)?xU(e.setting_id):``;u(`cloud`,t,e.setting_id,n||void 0)&&a.push({id:e.setting_id,name:t,source:`cloud`,filamentId:n,filamentType:pU(t).material})}for(let e of i??[]){let t=e.filament_id.startsWith(`GF`)?`GFS${e.filament_id.slice(2)}`:e.filament_id;l.has(o(e.name))||u(`builtin`,e.name,e.filament_id,t)&&a.push({id:`builtin_${e.filament_id}`,name:e.name,source:`builtin`,filamentId:e.filament_id,filamentType:pU(e.name).material})}return a.sort((e,t)=>e.source===t.source?e.name.localeCompare(t.name):Z6[e.source]-Z6[t.source])}async function rUe(e,t){if(e.filamentId)return e.filamentId;if(e.source!==`cloud`||!t)return``;try{return(await t(e.id)).filament_id||``}catch{return``}}var Q6=e=>(Math.trunc(parseFloat(e)*1e3)/1e3).toFixed(3),$6=`HS00`,e8=`HH00`,t8=e=>{let t=e.match(/^([A-Z]{2}\d{2})/);return t?t[1]:$6},iUe=e=>t8(e)===e8?`HF`:`S`,n8=e=>{for(let t of[`High Flow_`,`High Flow `,`Standard_`,`Standard `,`HF_`,`HF `,`S_`,`S `])if(e.startsWith(t))return e.slice(t.length);let t=e.indexOf(`_`);return t>0?e.slice(t+1):e};function r8({profile:e,onEdit:t,onCopy:n,selectionMode:r,isSelected:i,onToggleSelect:a,note:o}){let s=iUe(e.nozzle_id),c=e.nozzle_diameter;return(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[r&&(0,G.jsx)(`button`,{onClick:a,className:`text-bambu-gray hover:text-white transition-colors p-1`,children:i?(0,G.jsx)(hu,{className:`w-4 h-4 text-bambu-green`}):(0,G.jsx)(_u,{className:`w-4 h-4`})}),(0,G.jsxs)(`button`,{onClick:()=>{r&&a?a():t()},className:`flex-1 text-left px-3 py-2 bg-bambu-dark rounded hover:bg-bambu-dark-tertiary transition-colors ${i?`ring-1 ring-bambu-green`:``}`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-bambu-green font-mono text-sm font-bold whitespace-nowrap`,children:Q6(e.k_value)}),(0,G.jsx)(`span`,{className:`text-white text-sm truncate flex-1`,title:e.name,children:e.name||`Unnamed`}),o&&(0,G.jsx)(`span`,{title:`Has note`,children:(0,G.jsx)(bu,{className:`w-3 h-3 text-yellow-500`})}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:[s,` `,c]})]}),o&&(0,G.jsxs)(`div`,{className:`text-xs mt-0.5 truncate text-yellow-500/70`,title:o,children:[`Note: `,o.length>50?o.substring(0,50)+`...`:o]})]}),!r&&n&&(0,G.jsx)(`button`,{onClick:e=>{e.stopPropagation(),n()},className:`text-bambu-gray hover:text-white transition-colors p-1`,title:`Copy profile`,children:(0,G.jsx)(zs,{className:`w-4 h-4`})})]})}function i8({profile:e,printerId:t,nozzleDiameter:n,existingProfiles:r=[],builtinFilaments:i=[],filamentPresets:a=[],isDualNozzle:o=!1,supportsFlowType:s=!0,initialNote:c=``,initialNoteKey:l=null,onClose:u,onSave:d,onSaveNote:f,hasPermission:p}){let{t:m}=U(),{showToast:h}=Bd(),[g,_]=(0,y.useState)(e?.name||``),[v,b]=(0,y.useState)(e?.k_value?Q6(e.k_value):`0.020`),[x,S]=(0,y.useState)(e?.filament_id||``),[C,w]=(0,y.useState)(e?t8(e.nozzle_id):$6),[T,E]=(0,y.useState)(e?.nozzle_diameter||n),[D,O]=(0,y.useState)(e?[e.extruder_id]:o?[0,1]:[0]),[k,A]=(0,y.useState)(!1),[j,M]=(0,y.useState)({current:0,total:0}),[N,P]=(0,y.useState)(c),[F,I]=(0,y.useState)(``),{schedule:L}=wU(),R=y.useMemo(()=>e?.filament_id?i.find(t=>t.filament_id===e.filament_id)?.name||n8(r.find(t=>t.filament_id===e.filament_id)?.name||e.name||``)||e.filament_id:``,[e,r,i]),z=y.useMemo(()=>{let e=[[`local`,m(`kProfiles.modal.source.local`)],[`orca_cloud`,m(`kProfiles.modal.source.orcaCloud`)],[`cloud`,m(`kProfiles.modal.source.bambuCloud`)],[`builtin`,m(`kProfiles.modal.source.builtin`)]],t=F.trim().toLowerCase(),n=t?a.filter(e=>e.name.toLowerCase().includes(t)):a;return e.map(([e,t])=>({source:e,label:t,items:n.filter(t=>t.source===e)})).filter(e=>e.items.length>0)},[a,F,m]),B=q({mutationFn:e=>(console.log(`[KProfile] Calling API...`),Z.setKProfile(t,e)),onSuccess:(t,n)=>{if(console.log(`[KProfile] Save success:`,t),h(m(`kProfiles.toast.profileSaved`)),f&&N!==c){let t;t=N===``&&l?l:e&&e.slot_id>0?e.setting_id||`slot_${e.slot_id}_${e.filament_id}_${e.extruder_id}`:`name_${g}_${n.filament_id}`,f(t,N)}A(!0),L(()=>{A(!1),d()},2500)},onError:e=>{console.error(`[KProfile] Save error:`,e),h(e.message,`error`),A(!1)}}),V=q({mutationFn:e=>(console.log(`[KProfile] Deleting profile...`),Z.deleteKProfile(t,e)),onSuccess:e=>{console.log(`[KProfile] Delete success:`,e),h(m(`kProfiles.toast.profileDeleted`)),A(!0),L(()=>{A(!1),u()},4e3)},onError:e=>{console.error(`[KProfile] Delete error:`,e),h(e.message,`error`),A(!1)}}),[ee,te]=(0,y.useState)(!1),ne=()=>{e&&V.mutate({slot_id:e.slot_id,extruder_id:e.extruder_id,nozzle_id:e.nozzle_id,nozzle_diameter:e.nozzle_diameter,filament_id:e.filament_id,setting_id:e.setting_id})};return(0,G.jsxs)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,children:[(0,G.jsxs)(Md,{className:`w-full max-w-md relative`,children:[k&&(0,G.jsxs)(`div`,{className:`absolute inset-0 bg-bambu-dark-secondary/90 flex flex-col items-center justify-center z-10 rounded-lg`,children:[(0,G.jsx)(Y,{className:`w-8 h-8 text-bambu-green animate-spin mb-3`}),(0,G.jsx)(`p`,{className:`text-white font-medium`,children:j.total>1?m(`kProfiles.modal.savingExtruder`,{current:j.current,total:j.total}):m(`kProfiles.modal.syncing`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-sm mt-1`,children:m(`kProfiles.modal.pleaseWait`)})]}),(0,G.jsxs)(Pd,{className:`p-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,G.jsx)(`h2`,{className:`text-xl font-semibold text-white`,children:m(e?`kProfiles.modal.editTitle`:`kProfiles.modal.addTitle`)}),(0,G.jsx)(`button`,{onClick:u,className:`text-bambu-gray hover:text-white transition-colors`,disabled:k,children:(0,G.jsx)($u,{className:`w-5 h-5`})})]}),(0,G.jsxs)(`form`,{onSubmit:async n=>{if(n.preventDefault(),o&&!e&&D.length===0){h(m(`kProfiles.toast.selectAtLeastOneExtruder`),`error`);return}let r=parseFloat(v).toFixed(6),i=`${C}-${T}`,s=e&&e.nozzle_id||i,c=e?e.nozzle_diameter:T,l=e?.filament_id||``;if(!e){let e=a.find(e=>e.id===x);if(!e){h(m(`kProfiles.toast.selectFilament`),`error`);return}if(l=await rUe(e,Z.getCloudSettingDetail),!l){h(m(`kProfiles.toast.filamentNotResolvable`,{name:e.name}),`error`);return}}if(e||D.length===1){let t={name:g,k_value:r,filament_id:l,nozzle_id:s,nozzle_diameter:c,extruder_id:e?e.extruder_id:D[0],setting_id:e?.setting_id,slot_id:e?.slot_id??0};console.log(`[KProfile] Saving profile:`,t),B.mutate(t);return}A(!0),M({current:1,total:D.length});let u=D.map(e=>({name:g,k_value:r,filament_id:l,nozzle_id:i,nozzle_diameter:T,extruder_id:e,setting_id:void 0,slot_id:0}));console.log(`[KProfile] Saving ${u.length} profiles in batch:`,u);try{await Z.setKProfilesBatch(t,u),h(m(`kProfiles.toast.profilesSaved`,{count:D.length})),f&&N&&f(`name_${g}_${l}`,N)}catch(e){console.error(`[KProfile] Failed to save batch:`,e),h(m(`kProfiles.toast.failedToSaveBatch`),`error`),A(!1),M({current:0,total:0});return}M({current:D.length,total:D.length}),L(()=>{A(!1),M({current:0,total:0}),d()},3e3)},className:`p-4 space-y-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:m(`kProfiles.modal.profileName`)}),(0,G.jsx)(`input`,{type:`text`,value:g,onChange:e=>_(e.target.value),disabled:!!e,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none ${e?`opacity-60 cursor-not-allowed`:``}`,placeholder:m(`kProfiles.modal.profileNamePlaceholder`),required:!e})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:m(`kProfiles.modal.kValue`)}),(0,G.jsx)(`input`,{type:`text`,inputMode:`decimal`,value:v,onChange:e=>{let t=e.target.value;(t===``||/^\d*\.?\d*$/.test(t))&&b(t)},onBlur:e=>{let t=parseFloat(e.target.value);isNaN(t)||b((Math.trunc(t*1e3)/1e3).toFixed(3))},className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none font-mono`,placeholder:m(`kProfiles.modal.kValuePlaceholder`),required:!0}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:m(`kProfiles.modal.kValueHelp`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:m(`kProfiles.modal.filament`)}),e?(0,G.jsx)(`div`,{className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white opacity-60`,children:R||e.filament_id}):(0,G.jsxs)(`div`,{className:`border border-bambu-dark-tertiary rounded-lg overflow-hidden`,children:[(0,G.jsxs)(`div`,{className:`relative border-b border-bambu-dark-tertiary`,children:[(0,G.jsx)(Yl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,G.jsx)(`input`,{type:`text`,value:F,onChange:e=>I(e.target.value),placeholder:m(`kProfiles.modal.searchFilaments`),className:`w-full pl-10 pr-3 py-2 bg-bambu-dark text-white placeholder-bambu-gray focus:outline-none`})]}),(0,G.jsx)(`div`,{className:`max-h-56 overflow-y-auto bg-bambu-dark`,children:z.length===0?(0,G.jsx)(`p`,{className:`px-3 py-3 text-xs text-bambu-gray`,children:a.length===0?m(`kProfiles.modal.noFilamentsHelp`):m(`kProfiles.modal.noFilamentMatches`)}):z.map(e=>(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`sticky top-0 z-10 flex items-center gap-2 px-3 py-1.5 bg-bambu-dark-secondary border-y border-bambu-dark-tertiary`,children:[(0,G.jsx)(`span`,{className:`text-xs font-bold uppercase tracking-wider text-bambu-green`,children:e.label}),(0,G.jsx)(`span`,{className:`text-[10px] text-bambu-gray`,children:e.items.length})]}),e.items.map(e=>(0,G.jsx)(`button`,{type:`button`,onClick:()=>{S(e.id),g||_(`${C===e8?`HF`:`S`} ${e.name}`)},className:`w-full text-left px-3 py-1.5 text-sm transition-colors ${x===e.id?`bg-bambu-green/20 text-white`:`text-white hover:bg-bambu-dark-tertiary`}`,children:e.name},e.id))]},e.source))})]})]}),(0,G.jsxs)(`div`,{className:s?`grid grid-cols-2 gap-4`:``,children:[(0,G.jsxs)(`div`,{className:s?``:`hidden`,children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:m(`kProfiles.modal.flowType`)}),(0,G.jsxs)(`select`,{value:C,onChange:t=>{let n=t.target.value;if(w(n),!e&&x&&!g){let e=a.find(e=>e.id===x);e&&_(`${n===e8?`HF`:`S`} ${e.name}`)}},disabled:!!e,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none ${e?`opacity-60 cursor-not-allowed`:``}`,children:[(0,G.jsx)(`option`,{value:e8,children:m(`kProfiles.modal.highFlow`)}),(0,G.jsx)(`option`,{value:$6,children:m(`kProfiles.modal.standard`)})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:m(`kProfiles.modal.nozzleSize`)}),(0,G.jsxs)(`select`,{value:T,onChange:e=>E(e.target.value),disabled:!!e,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none ${e?`opacity-60 cursor-not-allowed`:``}`,children:[(0,G.jsx)(`option`,{value:`0.2`,children:`0.2mm`}),(0,G.jsx)(`option`,{value:`0.4`,children:`0.4mm`}),(0,G.jsx)(`option`,{value:`0.6`,children:`0.6mm`}),(0,G.jsx)(`option`,{value:`0.8`,children:`0.8mm`})]})]})]}),o&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:m(e?`kProfiles.modal.extruder`:`kProfiles.modal.extruders`)}),e?(0,G.jsx)(`div`,{className:`px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white opacity-60`,children:e.extruder_id===1?m(`kProfiles.modal.left`):m(`kProfiles.modal.right`)}):(0,G.jsxs)(`div`,{className:`flex gap-4`,children:[(0,G.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:D.includes(1),onChange:e=>{e.target.checked?O([...D,1]):O(D.filter(e=>e!==1))},className:`w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green focus:ring-offset-0 accent-bambu-green`}),(0,G.jsx)(`span`,{className:`text-white`,children:m(`kProfiles.modal.left`)})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:D.includes(0),onChange:e=>{e.target.checked?O([...D,0]):O(D.filter(e=>e!==0))},className:`w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green focus:ring-offset-0 accent-bambu-green`}),(0,G.jsx)(`span`,{className:`text-white`,children:m(`kProfiles.modal.right`)})]})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:m(`kProfiles.modal.notes`)}),(0,G.jsx)(`textarea`,{value:N,onChange:e=>P(e.target.value),placeholder:m(`kProfiles.modal.notesPlaceholder`),rows:2,className:`w-full px-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 resize-none`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:m(`kProfiles.modal.notesHelp`)})]}),(0,G.jsxs)(`div`,{className:`flex gap-2 pt-4`,children:[e&&(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:()=>te(!0),disabled:V.isPending||k||!p(`kprofiles:delete`),title:p(`kprofiles:delete`)?void 0:m(`kProfiles.permission.noDelete`),className:`text-red-500 hover:bg-red-500/10`,children:V.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(ju,{className:`w-4 h-4`})}),(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:u,disabled:k,className:`flex-1`,children:m(`common.cancel`)}),(0,G.jsxs)(Q,{type:`submit`,disabled:B.isPending||k||!p(e?`kprofiles:update`:`kprofiles:create`),title:p(e?`kprofiles:update`:`kprofiles:create`)?void 0:m(e?`kProfiles.permission.noUpdate`:`kProfiles.permission.noCreate`),className:`flex-1`,children:[B.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Sc,{className:`w-4 h-4`}),m(`common.save`)]})]})]})]})]}),ee&&(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-[60]`,children:(0,G.jsx)(Md,{className:`w-full max-w-sm`,children:(0,G.jsxs)(Pd,{className:`p-6`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3 mb-4`,children:[(0,G.jsx)(`div`,{className:`w-10 h-10 rounded-full bg-red-500/20 flex items-center justify-center`,children:(0,G.jsx)(ju,{className:`w-5 h-5 text-red-500`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`text-lg font-semibold text-white`,children:m(`kProfiles.deleteConfirm.title`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:m(`kProfiles.deleteConfirm.cannotUndo`)})]})]}),(0,G.jsx)(`p`,{className:`text-bambu-gray mb-6`,children:m(`kProfiles.deleteConfirm.message`,{name:e?.name})}),(0,G.jsxs)(`div`,{className:`flex gap-3`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>te(!1),className:`flex-1`,children:m(`common.cancel`)}),(0,G.jsxs)(Q,{onClick:()=>{te(!1),ne()},disabled:V.isPending,className:`flex-1 bg-red-500 hover:bg-red-600 text-white`,children:[V.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(ju,{className:`w-4 h-4`}),m(`common.delete`)]})]})]})})})]})}var a8={NOZZLE_DIAMETER:`bambusy_kprofiles_nozzle`,SORT_OPTION:`bambusy_kprofiles_sort`};function aUe(){let{t:e}=U(),{showToast:t}=Bd(),{hasPermission:n}=Ed(),[r,i]=(0,y.useState)(null),[a,o]=(0,y.useState)(()=>localStorage.getItem(a8.NOZZLE_DIAMETER)||`0.4`),[s,c]=(0,y.useState)(null),[l,u]=(0,y.useState)(!1),[d,f]=(0,y.useState)(null),[p,m]=(0,y.useState)(``),[h,g]=(0,y.useState)(`all`),[_,v]=(0,y.useState)(`all`),[b,x]=(0,y.useState)(()=>localStorage.getItem(a8.SORT_OPTION)||`name`),[S,C]=(0,y.useState)(!1),[w,T]=(0,y.useState)(new Set),[E,D]=(0,y.useState)(!1),[O,k]=(0,y.useState)(!1),A=(0,y.useCallback)(e=>`${e.slot_id}_${e.extruder_id}`,[]);(0,y.useEffect)(()=>{localStorage.setItem(a8.NOZZLE_DIAMETER,a)},[a]),(0,y.useEffect)(()=>{localStorage.setItem(a8.SORT_OPTION,b)},[b]);let{data:j,isLoading:M}=K({queryKey:[`printers`],queryFn:Z.getPrinters}),{data:N,isLoading:P,isFetching:F,error:I,refetch:L}=K({queryKey:[`kprofiles`,r,a],queryFn:async()=>{console.log(`[KProfiles] Fetching profiles for printer`,r,`nozzle`,a);let e=await Z.getKProfiles(r,a);return console.log(`[KProfiles] Received profiles:`,e?.profiles?.length||0,`profiles`),e},enabled:!!r,retry:!1,staleTime:0,gcTime:0,refetchOnMount:`always`}),{data:R}=K({queryKey:[`builtinFilaments`],queryFn:()=>Z.getBuiltinFilaments(),staleTime:3e5}),{data:z}=K({queryKey:[`filamentIdMap`],queryFn:()=>Z.getFilamentIdMap(),staleTime:3e5}),{data:B}=K({queryKey:[`localPresets`],queryFn:()=>Z.getLocalPresets(),retry:!1}),{data:V}=K({queryKey:[`orcaCloudProfilesForKProfiles`],queryFn:()=>Z.orcaCloudListProfiles(),retry:!1}),{data:ee}=K({queryKey:[`cloudSettings`],queryFn:()=>Z.getCloudSettings(),retry:!1}),{data:te,refetch:ne}=K({queryKey:[`kprofile-notes`,r],queryFn:()=>Z.getKProfileNotes(r),enabled:!!r,staleTime:3e4}),re=I?.message?.includes(`not connected`);(0,y.useEffect)(()=>{if(!r&&j&&j.length>0){let e=j.find(e=>e.is_active);e&&i(e.id)}},[r,j]),(0,y.useEffect)(()=>{if(r){let e=setTimeout(()=>{L()},150);return()=>clearTimeout(e)}},[r,a]);let ie=j?.filter(e=>e.is_active)||[],ae=y.useMemo(()=>{let e=new Map;if(R)for(let t of R)e.set(t.filament_id,t.name);if(z)for(let[t,n]of Object.entries(z))e.has(t)||e.set(t,n);return e},[R,z]),oe=y.useMemo(()=>Array.from(ae.entries()).map(([e,t])=>({filament_id:e,name:t})),[ae]),se=y.useMemo(()=>nUe({localPresets:B?.filament,orcaProfiles:V?.filament,cloudSettings:ee?.filament,builtinFilaments:R}),[B?.filament,V?.filament,ee?.filament,R]),H=y.useCallback(e=>ae.get(e.filament_id)||n8(e.name),[ae]),ce=y.useMemo(()=>N?.profiles?N.profiles.filter(e=>{let t=p.toLowerCase(),n=!t||e.name.toLowerCase().includes(t)||e.filament_id.toLowerCase().includes(t),r=h===`all`||h===`left`&&e.extruder_id===1||h===`right`&&e.extruder_id===0,i=_===`all`||_===`hf`&&e.nozzle_id.startsWith(`HH`)||_===`s`&&e.nozzle_id.startsWith(`HS`);return n&&r&&i}).sort((e,t)=>{switch(b){case`k_value`:return parseFloat(e.k_value)-parseFloat(t.k_value);case`filament`:return H(e).localeCompare(H(t));default:return e.name.localeCompare(t.name)}}):[],[N?.profiles,p,h,_,b,H]),le=j?.find(e=>e.id===r),ue=le?.nozzle_count===2,de=le?.supports_nozzle_flow_type??!0;(0,y.useEffect)(()=>{de||v(`all`)},[de]),(0,y.useEffect)(()=>{let e=e=>{e.target instanceof HTMLInputElement||e.target instanceof HTMLTextAreaElement||e.target instanceof HTMLSelectElement||s||l||d||(e.key===`r`||e.key===`R`?(e.preventDefault(),L()):e.key===`n`||e.key===`N`?(e.preventDefault(),u(!0)):e.key===`Escape`&&S&&(e.preventDefault(),C(!1),T(new Set)))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[s,l,d,S,L]);let fe=(0,y.useCallback)(()=>{if(!N?.profiles||N.profiles.length===0){t(e(`kProfiles.toast.noProfilesToExport`),`error`);return}let n={version:1,exported_at:new Date().toISOString(),printer:le?.name||`Unknown`,nozzle_diameter:a,profiles:N.profiles.map(e=>({name:e.name,k_value:e.k_value,filament_id:e.filament_id,nozzle_id:e.nozzle_id,nozzle_diameter:e.nozzle_diameter,extruder_id:e.extruder_id}))},r=new Blob([JSON.stringify(n,null,2)],{type:`application/json`}),i=URL.createObjectURL(r),o=document.createElement(`a`);o.href=i,o.download=`kprofiles_${le?.name||`printer`}_${a}mm_${new Date().toISOString().split(`T`)[0]}.json`,document.body.appendChild(o),o.click(),document.body.removeChild(o),URL.revokeObjectURL(i),t(e(`kProfiles.toast.exportedProfiles`,{count:N.profiles.length}))},[N?.profiles,le,a,t,e]),pe=(0,y.useCallback)(()=>{let n=document.createElement(`input`);n.type=`file`,n.accept=`.json`,n.onchange=async n=>{let i=n.target.files?.[0];if(i)try{let n=await i.text(),o=JSON.parse(n);if(!o.profiles||!Array.isArray(o.profiles)){t(e(`kProfiles.toast.invalidFileFormat`),`error`);return}let s=0;for(let e of o.profiles)if(!(!e.name||!e.k_value||!e.filament_id))try{await Z.setKProfile(r,{name:e.name,k_value:parseFloat(e.k_value).toFixed(6),filament_id:e.filament_id,nozzle_id:e.nozzle_id||`${$6}-${a}`,nozzle_diameter:e.nozzle_diameter||a,extruder_id:e.extruder_id??0,slot_id:0}),s++,await new Promise(e=>setTimeout(e,500))}catch(t){console.error(`Failed to import profile:`,e.name,t)}t(e(`kProfiles.toast.importedProfiles`,{count:s,total:o.profiles.length})),L()}catch(n){console.error(`Import error:`,n),t(e(`kProfiles.toast.failedToParseImport`),`error`)}},n.click()},[r,a,t,L,e]),me=(0,y.useCallback)(e=>{T(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),he=(0,y.useCallback)(()=>{T(new Set(ce.map(e=>A(e))))},[ce,A]),ge=(0,y.useCallback)(()=>{w.size!==0&&D(!0)},[w.size]),_e=(0,y.useCallback)(async()=>{let n=ce.filter(e=>w.has(A(e)));k(!0);let i=0;for(let e of n)try{await Z.deleteKProfile(r,{slot_id:e.slot_id,extruder_id:e.extruder_id,nozzle_id:e.nozzle_id,nozzle_diameter:e.nozzle_diameter,filament_id:e.filament_id,setting_id:e.setting_id}),i++,await new Promise(e=>setTimeout(e,300))}catch(t){console.error(`Failed to delete profile:`,e.name,t)}t(e(`kProfiles.toast.profilesDeleted`,{count:i})),k(!1),D(!1),C(!1),T(new Set),L()},[r,w,ce,t,L,A,e]),ve=(0,y.useCallback)(e=>{let t=[];return e.setting_id&&t.push(e.setting_id),t.push(`slot_${e.slot_id}_${e.filament_id}_${e.extruder_id}`),t.push(`name_${e.name}_${e.filament_id}`),t},[]),ye=(0,y.useCallback)(async(n,i)=>{if(r)try{await Z.setKProfileNote(r,n,i),ne()}catch(n){console.error(`Failed to save note:`,n),t(e(`kProfiles.toast.failedToSaveNote`),`error`)}},[r,ne,t,e]),be=(0,y.useCallback)(e=>{if(!te?.notes)return{note:``,key:null};let t=ve(e);for(let e of t)if(te.notes[e])return{note:te.notes[e],key:e};return{note:``,key:null}},[te,ve]),xe=(0,y.useCallback)(e=>be(e).note,[be]);return M?(0,G.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,G.jsx)(Y,{className:`w-8 h-8 text-bambu-green animate-spin`})}):!j||j.length===0?(0,G.jsx)(Md,{children:(0,G.jsxs)(Pd,{className:`py-12 text-center`,children:[(0,G.jsx)(_s,{className:`w-12 h-12 text-bambu-gray mx-auto mb-4`}),(0,G.jsx)(`h3`,{className:`text-lg font-semibold text-white mb-2`,children:e(`kProfiles.noPrintersConfigured`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray`,children:e(`kProfiles.addPrinterInSettings`)})]})}):ie.length===0?(0,G.jsx)(Md,{children:(0,G.jsxs)(Pd,{className:`py-12 text-center`,children:[(0,G.jsx)(Fl,{className:`w-12 h-12 text-bambu-gray mx-auto mb-4`}),(0,G.jsx)(`h3`,{className:`text-lg font-semibold text-white mb-2`,children:e(`kProfiles.noActivePrinters`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray`,children:e(`kProfiles.enablePrinterConnection`)})]})}):(0,G.jsxs)(G.Fragment,{children:[F&&!P&&(0,G.jsxs)(`div`,{className:`fixed inset-0 bg-black/50 flex flex-col items-center justify-center z-40`,children:[(0,G.jsx)(Y,{className:`w-10 h-10 text-bambu-green animate-spin mb-3`}),(0,G.jsx)(`p`,{className:`text-white font-medium`,children:e(`kProfiles.loadingProfiles`)})]}),(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-4 mb-6`,children:[(0,G.jsxs)(`div`,{className:`flex-1 min-w-48`,children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:e(`kProfiles.printer`)}),(0,G.jsx)(`select`,{value:r||``,onChange:e=>i(parseInt(e.target.value)),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:ie.map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.name},e.id))})]}),(0,G.jsxs)(`div`,{className:`w-32`,children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:e(`kProfiles.nozzle`)}),(0,G.jsxs)(`select`,{value:a,onChange:e=>o(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,G.jsx)(`option`,{value:`0.2`,children:`0.2mm`}),(0,G.jsx)(`option`,{value:`0.4`,children:`0.4mm`}),(0,G.jsx)(`option`,{value:`0.6`,children:`0.6mm`}),(0,G.jsx)(`option`,{value:`0.8`,children:`0.8mm`})]})]}),(0,G.jsxs)(`div`,{className:`flex items-end gap-2`,children:[(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>L(),disabled:F||!n(`kprofiles:read`),title:n(`kprofiles:read`)?void 0:e(`kProfiles.permission.noRead`),children:[(0,G.jsx)(zl,{className:`w-4 h-4 ${F?`animate-spin`:``}`}),e(`kProfiles.refresh`)]}),(0,G.jsxs)(Q,{onClick:()=>u(!0),disabled:!n(`kprofiles:create`),title:n(`kprofiles:create`)?void 0:e(`kProfiles.permission.noCreate`),children:[(0,G.jsx)(Ml,{className:`w-4 h-4`}),e(`kProfiles.addProfile`)]})]})]}),(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-4 mb-4`,children:[(0,G.jsxs)(`div`,{className:`flex-1 min-w-48 relative`,children:[(0,G.jsx)(Yl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,G.jsx)(`input`,{type:`text`,value:p,onChange:e=>m(e.target.value),placeholder:e(`kProfiles.searchPlaceholder`),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`})]}),ue&&(0,G.jsx)(`div`,{className:`w-36`,children:(0,G.jsxs)(`select`,{value:h,onChange:e=>g(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,G.jsx)(`option`,{value:`all`,children:e(`kProfiles.allExtruders`)}),(0,G.jsx)(`option`,{value:`left`,children:e(`kProfiles.leftOnly`)}),(0,G.jsx)(`option`,{value:`right`,children:e(`kProfiles.rightOnly`)})]})}),de&&(0,G.jsx)(`div`,{className:`w-32`,children:(0,G.jsxs)(`select`,{value:_,onChange:e=>v(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,G.jsx)(`option`,{value:`all`,children:e(`kProfiles.allFlow`)}),(0,G.jsx)(`option`,{value:`hf`,children:e(`kProfiles.hfOnly`)}),(0,G.jsx)(`option`,{value:`s`,children:e(`kProfiles.sOnly`)})]})}),(0,G.jsx)(`div`,{className:`w-32`,children:(0,G.jsxs)(`select`,{value:b,onChange:e=>x(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,G.jsx)(`option`,{value:`name`,children:e(`kProfiles.sortName`)}),(0,G.jsx)(`option`,{value:`k_value`,children:e(`kProfiles.sortKValue`)}),(0,G.jsx)(`option`,{value:`filament`,children:e(`kProfiles.sortFilament`)})]})})]}),(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-2 mb-6`,children:[(0,G.jsxs)(Q,{variant:`secondary`,onClick:fe,disabled:!N?.profiles?.length||!n(`kprofiles:read`),title:n(`kprofiles:read`)?void 0:e(`kProfiles.permission.noExport`),children:[(0,G.jsx)(Js,{className:`w-4 h-4`}),e(`kProfiles.export`)]}),(0,G.jsxs)(Q,{variant:`secondary`,onClick:pe,disabled:!n(`kprofiles:create`),title:n(`kprofiles:create`)?void 0:e(`kProfiles.permission.noImport`),children:[(0,G.jsx)(Ru,{className:`w-4 h-4`}),e(`kProfiles.import`)]}),(0,G.jsx)(`div`,{className:`flex-1`}),S?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(Q,{variant:`secondary`,onClick:he,children:[(0,G.jsx)(hu,{className:`w-4 h-4`}),e(`kProfiles.selectAll`)]}),(0,G.jsxs)(Q,{variant:`secondary`,onClick:ge,disabled:w.size===0||!n(`kprofiles:delete`),className:`text-red-500 hover:bg-red-500/10`,title:n(`kprofiles:delete`)?void 0:e(`kProfiles.permission.noDelete`),children:[(0,G.jsx)(ju,{className:`w-4 h-4`}),e(`kProfiles.delete`),` (`,w.size,`)`]}),(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>{C(!1),T(new Set)},children:[(0,G.jsx)($u,{className:`w-4 h-4`}),e(`common.cancel`)]})]}):(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>C(!0),disabled:!ce.length||!n(`kprofiles:delete`),title:n(`kprofiles:delete`)?void 0:e(`kProfiles.permission.noDelete`),children:[(0,G.jsx)(hu,{className:`w-4 h-4`}),e(`kProfiles.select`)]})]}),P?(0,G.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,G.jsx)(Y,{className:`w-8 h-8 text-bambu-green animate-spin`})}):re?(0,G.jsx)(Md,{children:(0,G.jsxs)(Pd,{className:`py-12 text-center`,children:[(0,G.jsx)(Ju,{className:`w-12 h-12 text-bambu-gray mx-auto mb-4`}),(0,G.jsx)(`h3`,{className:`text-lg font-semibold text-white mb-2`,children:e(`kProfiles.printerOffline`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray mb-4`,children:e(`kProfiles.printerOfflineDesc`)}),(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>L(),children:[(0,G.jsx)(zl,{className:`w-4 h-4`}),e(`common.refresh`)]})]})}):ce.length>0?ue?(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`text-sm font-medium text-bambu-gray mb-2 px-1`,children:e(`kProfiles.leftExtruder`)}),(0,G.jsx)(`div`,{className:`space-y-1`,children:ce.filter(e=>e.extruder_id===1).map(e=>(0,G.jsx)(r8,{profile:e,onEdit:()=>c(e),onCopy:()=>f(e),selectionMode:S,isSelected:w.has(A(e)),onToggleSelect:()=>me(A(e)),note:xe(e)},A(e)))})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`text-sm font-medium text-bambu-gray mb-2 px-1`,children:e(`kProfiles.rightExtruder`)}),(0,G.jsx)(`div`,{className:`space-y-1`,children:ce.filter(e=>e.extruder_id===0).map(e=>(0,G.jsx)(r8,{profile:e,onEdit:()=>c(e),onCopy:()=>f(e),selectionMode:S,isSelected:w.has(A(e)),onToggleSelect:()=>me(A(e)),note:xe(e)},A(e)))})]})]}):(0,G.jsx)(`div`,{className:`space-y-1`,children:ce.map(e=>(0,G.jsx)(r8,{profile:e,onEdit:()=>c(e),onCopy:()=>f(e),selectionMode:S,isSelected:w.has(A(e)),onToggleSelect:()=>me(A(e)),note:xe(e)},A(e)))}):p||h!==`all`||_!==`all`?(0,G.jsx)(Md,{children:(0,G.jsxs)(Pd,{className:`py-12 text-center`,children:[(0,G.jsx)(Yl,{className:`w-12 h-12 text-bambu-gray mx-auto mb-4`}),(0,G.jsx)(`h3`,{className:`text-lg font-semibold text-white mb-2`,children:e(`kProfiles.noMatchingProfiles`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray`,children:e(`kProfiles.noMatchingProfilesDesc`)})]})}):(0,G.jsx)(Md,{children:(0,G.jsxs)(Pd,{className:`py-12 text-center`,children:[(0,G.jsx)(Sc,{className:`w-12 h-12 text-bambu-gray mx-auto mb-4`}),(0,G.jsx)(`h3`,{className:`text-lg font-semibold text-white mb-2`,children:e(`kProfiles.noKProfiles`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray mb-4`,children:e(`kProfiles.noKProfilesDesc`,{diameter:a})}),(0,G.jsxs)(Q,{onClick:()=>u(!0),children:[(0,G.jsx)(Ml,{className:`w-4 h-4`}),e(`kProfiles.createFirstProfile`)]})]})}),s&&r&&(()=>{let{note:e,key:t}=be(s);return(0,G.jsx)(i8,{profile:s,printerId:r,nozzleDiameter:a,existingProfiles:N?.profiles,builtinFilaments:oe,filamentPresets:se,isDualNozzle:ue,supportsFlowType:de,initialNote:e,initialNoteKey:t,onSaveNote:ye,hasPermission:n,onClose:()=>{console.log(`[KProfiles] Edit modal onClose - refetching profiles...`),c(null),L()},onSave:()=>{c(null),L()}})})(),l&&r&&(0,G.jsx)(i8,{printerId:r,nozzleDiameter:a,existingProfiles:N?.profiles,builtinFilaments:oe,filamentPresets:se,isDualNozzle:ue,supportsFlowType:de,onSaveNote:ye,hasPermission:n,onClose:()=>{u(!1),L()},onSave:()=>{u(!1),L()}}),d&&r&&(0,G.jsx)(i8,{printerId:r,nozzleDiameter:a,existingProfiles:N?.profiles,builtinFilaments:oe,filamentPresets:se,isDualNozzle:ue,supportsFlowType:de,onSaveNote:ye,hasPermission:n,profile:{...d,slot_id:0,name:`${d.name} (Copy)`},onClose:()=>{f(null),L()},onSave:()=>{f(null),L()}}),E&&(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,children:(0,G.jsx)(Md,{className:`w-full max-w-sm`,children:(0,G.jsxs)(Pd,{className:`p-6`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3 mb-4`,children:[(0,G.jsx)(`div`,{className:`w-10 h-10 rounded-full bg-red-500/20 flex items-center justify-center`,children:(0,G.jsx)(ju,{className:`w-5 h-5 text-red-500`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`text-lg font-semibold text-white`,children:e(`kProfiles.bulkDelete.title`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`kProfiles.bulkDelete.cannotUndo`)})]})]}),(0,G.jsx)(`p`,{className:`text-bambu-gray mb-6`,children:e(`kProfiles.bulkDelete.message`,{count:w.size})}),(0,G.jsxs)(`div`,{className:`flex gap-3`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>D(!1),disabled:O,className:`flex-1`,children:e(`common.cancel`)}),(0,G.jsxs)(Q,{onClick:_e,disabled:O,className:`flex-1 bg-red-500 hover:bg-red-600 text-white`,children:[O?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(ju,{className:`w-4 h-4`}),e(`common.delete`)]})]})]})})})]})}var o8=[`PLA`,`PETG`,`PCTG`,`ABS`,`ASA`,`TPU`,`PC`,`PA`,`PVA`,`HIPS`,`PP`,`PET`,`NYLON`],oUe={PLA:`E8E8E8`,PETG:`4A90D9`,ABS:`E67E22`,ASA:`D35400`,TPU:`9B59B6`,PC:`BDC3C7`,PA:`2ECC71`,NYLON:`2ECC71`,PVA:`F1C40F`,HIPS:`95A5A6`,PP:`ECF0F1`,PET:`3498DB`};function sUe(e){let t=e.toUpperCase();for(let e of o8)if(RegExp(`\\b${e}\\b`).test(t))return e;return null}function cUe(e){let t=e.replace(/@.+$/,``).trim(),n=t.toUpperCase();for(let e of o8){let r=n.indexOf(e);if(r>0){let e=t.slice(0,r).trim();if(e&&e.length>1)return e}}return null}function s8({preset:e,onDelete:t,onExpand:n,isExpanded:r}){let{t:i}=U(),{hasPermission:a}=Ed(),o=e.filament_type||sUe(e.name),s=e.filament_vendor||cUe(e.name),c=null,l=!1;if(e.default_filament_colour)try{let t=JSON.parse(e.default_filament_colour),n=Array.isArray(t)?t[0]:t;typeof n==`string`&&/^#?[0-9a-fA-F]{6,8}$/.test(n.replace(`#`,``))&&(c=n.replace(`#`,``).slice(0,6),l=!0)}catch{let t=e.default_filament_colour;/^#?[0-9a-fA-F]{6,8}$/.test(t.replace(`#`,``))&&(c=t.replace(`#`,``).slice(0,6),l=!0)}return!c&&o&&(c=oUe[o.toUpperCase()]||null),(0,G.jsx)(Md,{className:`bg-bambu-dark border-bambu-dark-tertiary hover:border-bambu-dark-tertiary/80 transition-colors`,children:(0,G.jsxs)(Pd,{className:`p-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[e.preset_type===`filament`&&(0,G.jsx)(`div`,{className:`w-4 h-4 rounded-full border border-black/20 flex-shrink-0 ${!l&&!c?`opacity-25`:l?``:`opacity-50`}`,style:{backgroundColor:c?`#${c}`:`#666`}}),(0,G.jsx)(`span`,{className:`text-sm font-medium text-white truncate`,children:e.name})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[o&&(0,G.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-bambu-green/20 text-bambu-green`,children:o}),s&&(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:s}),(0,G.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`,children:i(`profiles.localProfiles.badge`)})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1 flex-shrink-0`,children:[a(`settings:update`)&&(0,G.jsx)(`button`,{onClick:()=>t(e.id),className:`p-1 text-bambu-gray hover:text-red-600 dark:hover:text-red-400 transition-colors`,title:i(`profiles.localProfiles.delete`),children:(0,G.jsx)(ju,{className:`w-3.5 h-3.5`})}),(0,G.jsx)(`button`,{onClick:()=>n(r?null:e.id),className:`p-1 text-bambu-gray hover:text-white transition-colors`,children:r?(0,G.jsx)(ms,{className:`w-3.5 h-3.5`}):(0,G.jsx)(ds,{className:`w-3.5 h-3.5`})})]})]}),r&&(0,G.jsxs)(`div`,{className:`mt-3 pt-3 border-t border-bambu-dark-tertiary text-xs space-y-1.5`,children:[o&&(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:i(`profiles.localProfiles.filamentType`)}),(0,G.jsx)(`span`,{className:`text-white`,children:o})]}),s&&(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:i(`profiles.localProfiles.vendor`)}),(0,G.jsx)(`span`,{className:`text-white`,children:s})]}),e.nozzle_temp_min!=null&&e.nozzle_temp_max!=null&&(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:i(`profiles.localProfiles.nozzleTemp`)}),(0,G.jsxs)(`span`,{className:`text-white`,children:[e.nozzle_temp_min,`–`,e.nozzle_temp_max,`°C`]})]}),e.filament_cost&&(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:i(`profiles.localProfiles.cost`)}),(0,G.jsx)(`span`,{className:`text-white`,children:e.filament_cost})]}),e.filament_density&&(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:i(`profiles.localProfiles.density`)}),(0,G.jsxs)(`span`,{className:`text-white`,children:[e.filament_density,` g/cm³`]})]}),e.pressure_advance&&(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:i(`profiles.localProfiles.pressureAdvance`)}),(0,G.jsx)(`span`,{className:`text-white`,children:e.pressure_advance})]}),e.compatible_printers&&(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:i(`profiles.localProfiles.compatiblePrinters`)}),(0,G.jsx)(`span`,{className:`text-white truncate ml-2`,children:(()=>{try{return JSON.parse(e.compatible_printers).join(`, `)}catch{return e.compatible_printers}})()})]}),e.inherits&&e.inherits!==e.name&&(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:i(`profiles.localProfiles.inheritsFrom`)}),(0,G.jsx)(`span`,{className:`text-white truncate ml-2`,children:e.inherits})]}),(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:i(`profiles.localProfiles.source`)}),(0,G.jsx)(`span`,{className:`text-white capitalize`,children:e.source})]})]})]})})}function lUe(){let{t:e}=U(),{hasPermission:t}=Ed(),n=so(),{showToast:r}=Bd(),[i,a]=(0,y.useState)(``),[o,s]=(0,y.useState)(null),[c,l]=(0,y.useState)(!1),[u,d]=(0,y.useState)(null),{data:f,isLoading:p}=K({queryKey:[`localPresets`],queryFn:()=>Z.getLocalPresets()}),m=q({mutationFn:async e=>{let t=[];for(let n of Array.from(e)){let e=new FormData;e.append(`file`,n),t.push(await Z.importLocalPresets(e))}return t},onSuccess:t=>{n.invalidateQueries({queryKey:[`localPresets`]}),n.invalidateQueries({queryKey:[`slicerPresets`]});let i=0,a=0,o=0;for(let e of t)i+=e.imported,a+=e.skipped,o+=e.errors.length;i>0&&r(e(`profiles.localProfiles.toast.importSuccess`,{count:i})),a>0&&r(e(`profiles.localProfiles.toast.importSkipped`,{count:a}),`warning`),o>0&&r(e(`profiles.localProfiles.toast.importError`,{count:o}),`error`)},onError:e=>{r(e.message,`error`)}}),h=q({mutationFn:e=>Z.deleteLocalPreset(e),onSuccess:(t,i)=>{n.setQueryData([`localPresets`],e=>e&&{filament:e.filament.filter(e=>e.id!==i),printer:e.printer.filter(e=>e.id!==i),process:e.process.filter(e=>e.id!==i)}),n.invalidateQueries({queryKey:[`localPresets`]}),n.invalidateQueries({queryKey:[`slicerPresets`]}),d(null),r(e(`profiles.localProfiles.toast.deleted`))}}),g=(0,y.useCallback)(e=>{!e||e.length===0||m.mutate(e)},[m]),_=(0,y.useCallback)(e=>{e.preventDefault(),l(!1),g(e.dataTransfer.files)},[g]),v=(0,y.useCallback)(e=>{if(!i)return e;let t=i.toLowerCase();return e.filter(e=>e.name.toLowerCase().includes(t)||e.filament_type?.toLowerCase().includes(t)||e.filament_vendor?.toLowerCase().includes(t))},[i]),b=(0,y.useMemo)(()=>v(f?.filament||[]),[f?.filament,v]),x=(0,y.useMemo)(()=>v(f?.printer||[]),[f?.printer,v]),S=(0,y.useMemo)(()=>v(f?.process||[]),[f?.process,v]),C=b.length+x.length+S.length,w=(f?.filament?.length??0)+(f?.printer?.length??0)+(f?.process?.length??0)>0;return p?(0,G.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,G.jsx)(Y,{className:`w-8 h-8 text-bambu-green animate-spin`})}):(0,G.jsxs)(`div`,{className:`space-y-6`,children:[t(`settings:update`)&&(0,G.jsxs)(`div`,{onDragOver:e=>{e.preventDefault(),l(!0)},onDragLeave:()=>l(!1),onDrop:_,className:`relative border-2 border-dashed rounded-lg p-6 text-center transition-colors ${c?`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary hover:border-bambu-gray`}`,children:[(0,G.jsx)(`input`,{type:`file`,accept:`.json,.zip,.orca_filament,.bbscfg,.bbsflmt`,multiple:!0,className:`absolute inset-0 w-full h-full opacity-0 cursor-pointer`,onChange:e=>g(e.target.files)}),m.isPending?(0,G.jsxs)(`div`,{className:`flex items-center justify-center gap-2`,children:[(0,G.jsx)(Y,{className:`w-5 h-5 text-bambu-green animate-spin`}),(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:e(`profiles.localProfiles.importing`)})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Ru,{className:`w-8 h-8 text-bambu-gray mx-auto mb-2`}),(0,G.jsx)(`p`,{className:`text-sm text-white font-medium`,children:e(`profiles.localProfiles.import`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`profiles.localProfiles.importDesc`)})]})]}),w&&(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(Yl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,G.jsx)(`input`,{type:`text`,value:i,onChange:e=>a(e.target.value),placeholder:e(`profiles.localProfiles.search`),className:`w-full pl-9 pr-4 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`})]}),!w&&!p&&(0,G.jsxs)(`div`,{className:`text-center py-12`,children:[(0,G.jsx)(jc,{className:`w-12 h-12 text-bambu-gray mx-auto mb-3 opacity-50`}),(0,G.jsx)(`p`,{className:`text-bambu-gray`,children:e(`profiles.localProfiles.noPresets`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray/60 mt-1`,children:e(`profiles.localProfiles.importDesc`)})]}),w&&C===0&&!p&&(0,G.jsxs)(`div`,{className:`text-center py-12`,children:[(0,G.jsx)(Yl,{className:`w-12 h-12 text-bambu-gray mx-auto mb-3 opacity-50`}),(0,G.jsx)(`p`,{className:`text-bambu-gray`,children:e(`profiles.localProfiles.noSearchResults`)})]}),C>0&&(0,G.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6`,children:[b.length>0&&(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,G.jsx)(Ys,{className:`w-4 h-4 text-bambu-green`}),(0,G.jsx)(`h3`,{className:`text-sm font-medium text-white`,children:e(`profiles.localProfiles.filament`)}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[`(`,b.length,`)`]})]}),(0,G.jsx)(`div`,{className:`space-y-2`,children:b.map(e=>(0,G.jsx)(s8,{preset:e,onDelete:e=>d(e),onExpand:s,isExpanded:o===e.id},e.id))})]}),S.length>0&&(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,G.jsx)(Gc,{className:`w-4 h-4 text-blue-600 dark:text-blue-400`}),(0,G.jsx)(`h3`,{className:`text-sm font-medium text-white`,children:e(`profiles.localProfiles.process`)}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[`(`,S.length,`)`]})]}),(0,G.jsx)(`div`,{className:`space-y-2`,children:S.map(e=>(0,G.jsx)(s8,{preset:e,onDelete:e=>d(e),onExpand:s,isExpanded:o===e.id},e.id))})]}),x.length>0&&(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,G.jsx)($l,{className:`w-4 h-4 text-orange-600 dark:text-orange-400`}),(0,G.jsx)(`h3`,{className:`text-sm font-medium text-white`,children:e(`profiles.localProfiles.printer`)}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[`(`,x.length,`)`]})]}),(0,G.jsx)(`div`,{className:`space-y-2`,children:x.map(e=>(0,G.jsx)(s8,{preset:e,onDelete:e=>d(e),onExpand:s,isExpanded:o===e.id},e.id))})]})]}),u!==null&&(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50`,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg p-6 max-w-sm mx-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,G.jsx)(_s,{className:`w-5 h-5 text-red-600 dark:text-red-400`}),(0,G.jsx)(`h3`,{className:`text-white font-medium`,children:e(`profiles.localProfiles.deleteConfirmTitle`)})]}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4`,children:e(`profiles.localProfiles.deleteConfirm`)}),(0,G.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,G.jsx)(Q,{variant:`secondary`,size:`sm`,onClick:()=>d(null),children:e(`profiles.localProfiles.cancel`)}),(0,G.jsxs)(Q,{variant:`danger`,size:`sm`,onClick:()=>h.mutate(u),disabled:h.isPending,children:[h.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(ju,{className:`w-4 h-4`}),e(`profiles.localProfiles.delete`)]})]})]})})]})}function uUe(e){let t=e.match(/@?\s*(?:BBL\s+)?(?:Bambu\s+Lab\s+)?([XPAH][1-9][A-Z]?(?:\s*(?:Carbon|mini))?|H2D)/i),n=e.match(/(\d+\.?\d*)\s*(?:mm\s*)?nozzle|nozzle\s*(\d+\.?\d*)/i),r=e.match(/(\d+\.?\d*)mm\s*(?:Standard|Fine|Extra Fine|Draft|Quality)?/i),i=e.match(/\b(PLA|PETG|ABS|ASA|TPU|PC|PA|PVA|HIPS|PP|PET(?:-?CF)?|PA(?:-?CF)?|PLA(?:-?CF)?)\b/i);return{printer:t?t[1].trim():null,nozzle:n?(n[1]||n[2])+`mm`:null,layerHeight:r?r[1]+`mm`:null,filamentType:i?i[1].toUpperCase():null}}function dUe({settings:e,lastSyncTime:t,onRefresh:n,isRefreshing:r,printers:i,t:a}){let[o,s]=(0,y.useState)(``),[c,l]=(0,y.useState)(`all`),[u,d]=(0,y.useState)(`all`),[f,p]=(0,y.useState)(`all`),[m,h]=(0,y.useState)(`all`),[g,_]=(0,y.useState)(`all`),[v,b]=(0,y.useState)(null),x=(0,y.useMemo)(()=>[...e.filament.map(e=>({...e,type:`filament`})),...e.printer.map(e=>({...e,type:`printer`})),...e.process.map(e=>({...e,type:`process`}))].map(e=>({...e,meta:uUe(e.name)})),[e]),S=(0,y.useMemo)(()=>{let e=new Set,t=new Set,n=new Set;return x.forEach(r=>{r.meta.nozzle&&e.add(r.meta.nozzle),r.meta.filamentType&&t.add(r.meta.filamentType),r.meta.layerHeight&&n.add(r.meta.layerHeight)}),{printers:i.map(e=>({id:e.id.toString(),name:e.name})),nozzles:Array.from(e).sort((e,t)=>parseFloat(e)-parseFloat(t)),filaments:Array.from(t).sort(),layerHeights:Array.from(n).sort((e,t)=>parseFloat(e)-parseFloat(t))}},[x,i]),C=(0,y.useMemo)(()=>u===`all`?null:i.find(e=>e.id.toString()===u)?.model||null,[u,i]),w=(0,y.useMemo)(()=>x.filter(e=>c===`all`||e.type===c).filter(e=>{if(u===`all`||!C)return!0;let t=e.meta.printer?.toLowerCase()||``,n=C.toLowerCase();return t.includes(n)||n.includes(t)}).filter(e=>f===`all`||e.meta.nozzle===f).filter(e=>m===`all`||e.meta.filamentType===m).filter(e=>g===`all`||e.meta.layerHeight===g).filter(e=>o===``||e.name.toLowerCase().includes(o.toLowerCase())).sort((e,t)=>e.name.localeCompare(t.name)),[x,c,u,C,f,m,g,o]),T=()=>{l(`all`),d(`all`),p(`all`),h(`all`),_(`all`),s(``)},E=c!==`all`||u!==`all`||f!==`all`||m!==`all`||g!==`all`||o!==``,D=e.filament.length+e.printer.length+e.process.length,O=e=>w.filter(t=>t.type===e);return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`space-y-4 mb-6`,children:[(0,G.jsxs)(`div`,{className:`flex flex-col sm:flex-row gap-3`,children:[(0,G.jsxs)(`div`,{className:`relative flex-1`,children:[(0,G.jsx)(Yl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,G.jsx)(`input`,{type:`text`,value:o,onChange:e=>s(e.target.value),placeholder:a(`profiles.cloudView.searchPlaceholder`),className:`w-full pl-10 pr-4 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none`})]}),(0,G.jsx)(`div`,{className:`flex gap-2`,children:(0,G.jsxs)(Q,{variant:`secondary`,onClick:n,disabled:r,children:[(0,G.jsx)(zl,{className:`w-4 h-4 ${r?`animate-spin`:``}`}),a(`profiles.cloudView.refresh`)]})})]}),(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,G.jsx)(xc,{className:`w-4 h-4 text-bambu-gray`}),(0,G.jsx)(d8,{label:a(`profiles.cloudView.filters.type`),value:c,options:[{value:`all`,label:a(`profiles.cloudView.filters.all`),count:D},{value:`filament`,label:a(`profiles.cloudView.filters.filament`),count:e.filament.length},{value:`printer`,label:a(`profiles.cloudView.filters.printer`),count:e.printer.length},{value:`process`,label:a(`profiles.cloudView.filters.process`),count:e.process.length}],onChange:e=>l(e)}),S.printers.length>0&&(0,G.jsx)(d8,{label:a(`profiles.cloudView.filters.printer`),value:u,options:[{value:`all`,label:a(`profiles.cloudView.filters.all`)},...S.printers.map(e=>({value:e.id,label:e.name}))],onChange:d}),S.nozzles.length>0&&(0,G.jsx)(d8,{label:a(`profiles.cloudView.filters.nozzle`),value:f,options:[{value:`all`,label:a(`profiles.cloudView.filters.all`)},...S.nozzles.map(e=>({value:e,label:e}))],onChange:p}),S.filaments.length>0&&(c===`all`||c===`filament`)&&(0,G.jsx)(d8,{label:a(`profiles.cloudView.filters.filament`),value:m,options:[{value:`all`,label:a(`profiles.cloudView.filters.all`)},...S.filaments.map(e=>({value:e,label:e}))],onChange:h}),S.layerHeights.length>0&&(c===`all`||c===`process`)&&(0,G.jsx)(d8,{label:a(`profiles.cloudView.filters.layer`),value:g,options:[{value:`all`,label:a(`profiles.cloudView.filters.all`)},...S.layerHeights.map(e=>({value:e,label:e}))],onChange:_}),E&&(0,G.jsx)(`button`,{onClick:T,className:`px-3 py-2 text-sm text-bambu-gray hover:text-white transition-colors`,children:a(`profiles.cloudView.clearFilters`)})]})]}),(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4 mb-4 text-sm text-bambu-gray`,children:[t&&(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(ks,{className:`w-3 h-3`}),a(`profiles.cloudView.lastSynced`),` `,$f(t.toISOString(),`system`,a)]}),(0,G.jsx)(`span`,{children:a(`profiles.cloudView.showingCount`,{showing:w.length,total:D})})]}),w.length===0?(0,G.jsxs)(`div`,{className:`text-center py-16`,children:[(0,G.jsx)(Gc,{className:`w-12 h-12 text-bambu-gray-dark mx-auto mb-4`}),(0,G.jsx)(`p`,{className:`text-bambu-gray`,children:a(`profiles.cloudView.noPresetsFound`)}),E&&(0,G.jsx)(`button`,{onClick:T,className:`mt-2 text-sm text-bambu-green hover:text-bambu-green-light`,children:a(`profiles.cloudView.clearFilters`)})]}):(0,G.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-6`,children:[(0,G.jsx)(c8,{icon:(0,G.jsx)(Ys,{className:`w-4 h-4 text-amber-600 dark:text-amber-400`}),title:a(`profiles.cloudView.columns.filament`),presets:O(`filament`),emptyText:a(`profiles.cloudView.noFilamentPresets`),onSelect:b}),(0,G.jsx)(c8,{icon:(0,G.jsx)($l,{className:`w-4 h-4 text-blue-600 dark:text-blue-400`}),title:a(`profiles.cloudView.columns.process`),presets:O(`process`),emptyText:a(`profiles.cloudView.noProcessPresets`),onSelect:b}),(0,G.jsx)(c8,{icon:(0,G.jsx)(Fl,{className:`w-4 h-4 text-purple-600 dark:text-purple-400`}),title:a(`profiles.cloudView.columns.printer`),presets:O(`printer`),emptyText:a(`profiles.cloudView.noPrinterPresets`),onSelect:b})]}),v&&(0,G.jsx)(pUe,{setting:v,onClose:()=>b(null),t:a})]})}function c8({icon:e,title:t,presets:n,emptyText:r,onSelect:i}){return(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-3 px-1`,children:[e,(0,G.jsx)(`h3`,{className:`text-sm font-medium text-bambu-gray`,children:t}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray-dark`,children:[`(`,n.length,`)`]})]}),(0,G.jsx)(`div`,{className:`space-y-1 max-h-[calc(100vh-320px)] overflow-y-auto pr-1`,children:n.length===0?(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray-dark px-3 py-2`,children:r}):n.map(e=>(0,G.jsx)(fUe,{preset:e,onClick:()=>i(e)},e.setting_id))})]})}function fUe({preset:e,onClick:t}){return(0,G.jsx)(`button`,{onClick:t,className:`w-full text-left px-3 py-2 rounded bg-bambu-dark hover:bg-bambu-dark-tertiary transition-colors`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-white text-sm truncate flex-1`,title:e.name,children:e.name}),e.meta.filamentType&&e.type===`filament`&&(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:e.meta.filamentType}),e.meta.layerHeight&&e.type===`process`&&(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:e.meta.layerHeight}),e.meta.printer&&(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:e.meta.printer})]})})}function pUe({setting:e,onClose:t,t:n}){let{data:r,isLoading:i,error:a}=K({queryKey:[`orcaCloudProfileDetail`,e.setting_id],queryFn:()=>Z.orcaCloudGetProfile(e.setting_id),retry:!1});return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/60 z-50 flex items-center justify-center p-4`,onClick:t,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-2xl max-w-4xl w-full max-h-[90vh] flex flex-col`,onClick:e=>e.stopPropagation(),children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h2`,{className:`text-lg font-bold text-white`,children:e.name}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:e.type})]}),(0,G.jsx)(`button`,{onClick:t,className:`text-bambu-gray hover:text-white p-1`,children:(0,G.jsx)($u,{className:`w-5 h-5`})})]}),(0,G.jsx)(`div`,{className:`flex-1 overflow-y-auto p-4`,children:i?(0,G.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,G.jsx)(Y,{className:`w-8 h-8 text-bambu-green animate-spin`})}):a?(0,G.jsx)(`p`,{className:`text-center text-bambu-gray py-16`,children:a.message}):r?(0,G.jsx)(`pre`,{className:`text-xs font-mono text-bambu-gray bg-bambu-dark p-3 rounded overflow-x-auto whitespace-pre`,children:JSON.stringify(r.setting,null,2)}):(0,G.jsx)(`p`,{className:`text-center text-bambu-gray py-16`,children:n(`profiles.cloudView.noPresetsFound`)})})]})})}function mUe(){let{t:e}=U(),t=so(),{showToast:n}=Bd(),{hasPermission:r}=Ed(),i=r(`orca_cloud:auth`),[a,o]=(0,y.useState)(null),[s,c]=(0,y.useState)(5e3),[l,u]=(0,y.useState)(null),{data:d,isLoading:f}=K({queryKey:[`orcaCloudStatus`],queryFn:Z.orcaCloudStatus}),p=!!d?.connected,{data:m,isLoading:h,refetch:g,isRefetching:_,error:v,dataUpdatedAt:b}=K({queryKey:[`orcaCloudProfiles`],queryFn:Z.orcaCloudListProfiles,enabled:p,retry:!1,staleTime:1e3*60*5}),{data:x=[]}=K({queryKey:[`printers`],queryFn:Z.getPrinters,enabled:p}),[S,C]=(0,y.useState)();(0,y.useEffect)(()=>{b&&C(new Date(b))},[b]);let w=()=>{o(null),c(5e3)},T=t=>{t===`access_denied`?u(e(`profiles.orcaCloud.errors.denied`)):t===`expired_token`&&u(e(`profiles.orcaCloud.errors.expired`)),w()},E=q({mutationFn:Z.orcaCloudDeviceStart,onSuccess:e=>{u(null),c(Math.max(1,e.interval)*1e3),o(e)},onError:t=>{u(t.message||e(`profiles.orcaCloud.errors.startFailed`))}}),D=q({mutationFn:Z.orcaCloudLogout,onSuccess:()=>{t.invalidateQueries({queryKey:[`orcaCloudStatus`]}),t.removeQueries({queryKey:[`orcaCloudProfiles`]}),n(e(`profiles.orcaCloud.toast.disconnected`))}}),{data:O,error:k}=K({queryKey:[`orcaCloudDevicePoll`,a?.user_code??`none`],queryFn:Z.orcaCloudDevicePoll,enabled:a!==null,gcTime:0,retry:!1,refetchOnWindowFocus:!1,refetchInterval:a===null?!1:s}),A=(0,y.useRef)(null);return(0,y.useEffect)(()=>{if(!a||!O)return;let r=O.status;if(r===`slow_down`){c(e=>e+5e3);return}r!==`authorization_pending`&&A.current!==r&&(A.current=r,r===`complete`?(w(),t.invalidateQueries({queryKey:[`orcaCloudStatus`]}),t.invalidateQueries({queryKey:[`orcaCloudProfiles`]}),n(e(`profiles.orcaCloud.connectedShort`))):T(r))},[O,a]),(0,y.useEffect)(()=>{a&&k&&(u(e(`profiles.orcaCloud.errors.pollFailed`)),w())},[k,a]),(0,y.useEffect)(()=>{a&&(A.current=null)},[a]),f?(0,G.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,G.jsx)(Y,{className:`w-8 h-8 text-bambu-green animate-spin`})}):(0,G.jsxs)(`div`,{children:[p&&(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-3 mb-6 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`w-2 h-2 rounded-full bg-bambu-green animate-pulse`}),(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:d?.email?(0,G.jsxs)(G.Fragment,{children:[e(`profiles.orcaCloud.connectedAs`),` `,(0,G.jsx)(`span`,{className:`text-white`,children:d.email})]}):(0,G.jsx)(`span`,{className:`text-white`,children:e(`profiles.orcaCloud.connectedShort`)})})]}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:()=>D.mutate(),disabled:D.isPending||!i,title:i?void 0:e(`profiles.orcaCloud.noLogoutPermission`),children:[(0,G.jsx)(nl,{className:`w-4 h-4`}),e(`profiles.orcaCloud.logout`)]})]}),p?h?(0,G.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,G.jsx)(Y,{className:`w-8 h-8 text-bambu-green animate-spin`})}):v?(0,G.jsxs)(`div`,{className:`text-center py-16`,children:[(0,G.jsx)(`p`,{className:`text-bambu-gray mb-4`,children:v.message}),(0,G.jsx)(Q,{onClick:()=>g(),children:e(`profiles.orcaCloud.retry`)})]}):m?(0,G.jsx)(dUe,{settings:m,lastSyncTime:S,onRefresh:()=>g(),isRefreshing:_,printers:x,t:e}):null:(0,G.jsx)(hUe,{pairing:a,connectError:l,onConnect:()=>E.mutate(),onCancel:w,isStarting:E.isPending,canManage:i,t:e})]})}function hUe({pairing:e,connectError:t,onConnect:n,onCancel:r,isStarting:i,canManage:a,t:o}){return e?(0,G.jsx)(Md,{children:(0,G.jsxs)(Pd,{className:`p-8 text-center max-w-md mx-auto`,children:[(0,G.jsx)(Ms,{className:`w-12 h-12 text-bambu-green mx-auto mb-4`}),(0,G.jsx)(`h2`,{className:`text-xl font-bold text-white mb-2`,children:o(`profiles.orcaCloud.device.title`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray mb-6`,children:o(`profiles.orcaCloud.device.instruction`)}),(0,G.jsx)(`p`,{className:`text-xs uppercase tracking-wide text-bambu-gray mb-2`,children:o(`profiles.orcaCloud.device.codeLabel`)}),(0,G.jsx)(`div`,{className:`mb-6 py-3 px-4 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg`,children:(0,G.jsx)(`span`,{className:`text-2xl font-mono font-bold tracking-[0.3em] text-white select-all`,children:e.user_code})}),(0,G.jsx)(`a`,{href:e.verification_uri_complete,target:`_blank`,rel:`noopener noreferrer`,children:(0,G.jsxs)(Q,{className:`w-full mb-3`,children:[(0,G.jsx)(tc,{className:`w-4 h-4`}),o(`profiles.orcaCloud.device.openButton`)]})}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray break-all mb-6`,children:o(`profiles.orcaCloud.device.manualHint`,{url:e.verification_uri})}),(0,G.jsxs)(`div`,{className:`flex items-center justify-center gap-2 text-sm text-bambu-gray mb-4`,children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin text-bambu-green`}),o(`profiles.orcaCloud.device.waiting`)]}),(0,G.jsx)(`button`,{type:`button`,onClick:r,className:`text-bambu-gray hover:text-white text-sm`,children:o(`profiles.orcaCloud.device.cancel`)})]})}):(0,G.jsx)(Md,{children:(0,G.jsxs)(Pd,{className:`p-8 text-center`,children:[(0,G.jsx)(Ms,{className:`w-12 h-12 text-bambu-green mx-auto mb-4`}),(0,G.jsx)(`h2`,{className:`text-xl font-bold text-white mb-2`,children:o(`profiles.orcaCloud.connect.title`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray mb-6 max-w-xl mx-auto`,children:o(`profiles.orcaCloud.connect.description`)}),(0,G.jsxs)(`div`,{className:`max-w-sm mx-auto`,children:[(0,G.jsxs)(Q,{onClick:n,disabled:i||!a,title:a?void 0:o(`profiles.orcaCloud.noConnectPermission`),className:`w-full`,children:[i?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(us,{className:`w-4 h-4`}),o(`profiles.orcaCloud.connectButton`)]}),t&&(0,G.jsxs)(`p`,{className:`mt-3 text-sm text-red-700 dark:text-red-400 flex items-center justify-center gap-2`,children:[(0,G.jsx)(_s,{className:`w-4 h-4 flex-shrink-0`}),t]})]})]})})}function l8(e,t){let n=`${e} ${t||``}`,r=n.match(/@?\s*(?:BBL\s+)?(?:Bambu\s+Lab\s+)?([XPAH][1-9][A-Z]?(?:\s*(?:Carbon|mini))?|H2D)/i),i=r?r[1].trim():null,a=n.match(/(\d+\.?\d*)\s*(?:mm\s*)?nozzle|nozzle\s*(\d+\.?\d*)/i),o=a?(a[1]||a[2])+`mm`:null,s=n.match(/(\d+\.?\d*)mm\s*(?:Standard|Fine|Extra Fine|Draft|Quality)?/i),c=s?s[1]+`mm`:null,l=n.match(/\b(PLA|PETG|ABS|ASA|TPU|PC|PA|PVA|HIPS|PP|PET(?:-?CF)?|PA(?:-?CF)?|PLA(?:-?CF)?)\b/i);return{printer:i,nozzle:o,layerHeight:c,filamentType:l?l[1].toUpperCase():null}}function u8(e){return/^(P[FPM]US|PF\d|PP\d)/.test(e)}function gUe({onSuccess:e,t}){let{showToast:n}=Bd(),[r,i]=(0,y.useState)(`email`),[a,o]=(0,y.useState)(``),[s,c]=(0,y.useState)(``),[l,u]=(0,y.useState)(``),[d,f]=(0,y.useState)(``),[p,m]=(0,y.useState)(`global`),[h,g]=(0,y.useState)(null),[_,v]=(0,y.useState)(null),[b,x]=(0,y.useState)(!1),S=q({mutationFn:()=>Z.cloudLogin(a,s,p),onSuccess:r=>{if(x(r.reason===`captcha`),r.success)n(t(`profiles.login.toast.loggedIn`)),e();else if(r.reason===`captcha`)return;else r.needs_verification?(g(r.verification_type||`email`),v(r.tfa_key||null),r.verification_type===`totp`?n(t(`profiles.login.toast.enterTotp`)):n(t(`profiles.login.toast.codeSent`)),i(`code`)):n(r.message,`error`)},onError:e=>{x(!1),n(e.message,`error`)}}),C=q({mutationFn:()=>Z.cloudVerify(a,l,_||void 0,p),onSuccess:r=>{x(r.reason===`captcha`),r.success?(n(t(`profiles.login.toast.loggedIn`)),e()):r.reason!==`captcha`&&n(r.message,`error`)},onError:e=>{x(!1),n(e.message,`error`)}}),w=q({mutationFn:()=>Z.cloudSetToken(d,p),onSuccess:()=>{n(t(`profiles.login.toast.tokenSet`)),e()},onError:e=>n(e.message,`error`)}),T=e=>{e.preventDefault(),r===`email`?S.mutate():r===`code`?C.mutate():r===`token`&&w.mutate()},E=S.isPending||C.isPending||w.isPending;return(0,G.jsx)(Md,{className:`max-w-md mx-auto`,children:(0,G.jsxs)(Pd,{children:[(0,G.jsxs)(`div`,{className:`text-center mb-6`,children:[(0,G.jsx)(`div`,{className:`inline-flex items-center justify-center w-12 h-12 rounded-xl bg-bambu-green/20 mb-3`,children:(0,G.jsx)(Ms,{className:`w-6 h-6 text-bambu-green`})}),(0,G.jsx)(`h2`,{className:`text-xl font-semibold text-white`,children:t(`profiles.login.title`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:t(`profiles.login.subtitle`)})]}),b&&r!==`token`&&(0,G.jsx)(`div`,{role:`alert`,className:`mb-4 p-3 rounded-lg border border-amber-500/40 bg-amber-500/10`,children:(0,G.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,G.jsx)(tu,{className:`w-4 h-4 text-amber-400 shrink-0 mt-0.5`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm font-medium text-amber-300`,children:t(`profiles.login.captchaTitle`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:t(`profiles.login.captchaBody`)}),(0,G.jsxs)(`button`,{type:`button`,onClick:()=>{x(!1),i(`token`)},className:`mt-2 text-xs text-bambu-green hover:underline flex items-center gap-1`,children:[(0,G.jsx)(Uc,{className:`w-3 h-3`}),t(`profiles.login.useToken`)]})]})]})}),(0,G.jsxs)(`form`,{onSubmit:T,className:`space-y-4`,children:[r===`email`&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:t(`profiles.login.email`)}),(0,G.jsx)(`input`,{type:`email`,value:a,onChange:e=>o(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none`,placeholder:`your@email.com`,required:!0})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:t(`profiles.login.password`)}),(0,G.jsx)(`input`,{type:`password`,value:s,onChange:e=>c(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none`,placeholder:`••••••••`,required:!0})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:t(`profiles.login.region`)}),(0,G.jsxs)(`select`,{value:p,onChange:e=>m(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,G.jsx)(`option`,{value:`global`,children:t(`profiles.login.regionGlobal`)}),(0,G.jsx)(`option`,{value:`china`,children:t(`profiles.login.regionChina`)})]})]})]}),r===`code`&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:t(h===`totp`?`profiles.login.totpCode`:`profiles.login.verificationCode`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:h===`totp`?t(`profiles.login.enterTotpHint`):t(`profiles.login.checkEmail`,{email:a})}),(0,G.jsx)(`input`,{type:`text`,value:l,onChange:e=>u(e.target.value.replace(/\D/g,``).slice(0,6)),className:`w-full px-3 py-3 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-center text-2xl tracking-widest font-mono focus:border-bambu-green focus:outline-none`,placeholder:`000000`,maxLength:6,required:!0})]}),r===`token`&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:t(`profiles.login.accessToken`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:t(`profiles.login.accessTokenHint`)}),(0,G.jsx)(`textarea`,{value:d,onChange:e=>f(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-xs font-mono placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none resize-none`,placeholder:`eyJ...`,rows:4,required:!0})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:t(`profiles.login.region`)}),(0,G.jsxs)(`select`,{value:p,onChange:e=>m(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,G.jsx)(`option`,{value:`global`,children:t(`profiles.login.regionGlobal`)}),(0,G.jsx)(`option`,{value:`china`,children:t(`profiles.login.regionChina`)})]})]})]}),(0,G.jsxs)(`div`,{className:`flex gap-2 max-[550px]:flex-wrap max-[550px]:items-center`,children:[r===`code`&&(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:()=>i(`email`),className:`flex-1`,children:t(`profiles.login.back`)}),(0,G.jsxs)(Q,{type:`submit`,disabled:E,className:`flex-1`,children:[E?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(tl,{className:`w-4 h-4`}),t(r===`email`?`profiles.login.loginButton`:r===`code`?`profiles.login.verifyButton`:`profiles.login.setTokenButton`)]})]}),r===`email`&&(0,G.jsx)(`div`,{className:`pt-4 border-t border-bambu-dark-tertiary`,children:(0,G.jsxs)(`button`,{type:`button`,onClick:()=>i(`token`),className:`text-sm text-bambu-gray hover:text-white flex items-center gap-2 transition-colors`,children:[(0,G.jsx)(Uc,{className:`w-4 h-4`}),t(`profiles.login.useToken`)]})}),r===`token`&&(0,G.jsx)(`div`,{className:`pt-4 border-t border-bambu-dark-tertiary`,children:(0,G.jsxs)(`button`,{type:`button`,onClick:()=>i(`email`),className:`text-sm text-bambu-gray hover:text-white flex items-center gap-2 transition-colors`,children:[(0,G.jsx)(tl,{className:`w-4 h-4`}),t(`profiles.login.useEmail`)]})})]})]})})}function d8({label:e,value:t,options:n,onChange:r}){let[i,a]=(0,y.useState)(!1),o=n.find(e=>e.value===t);return(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsxs)(`button`,{onClick:()=>a(!i),className:`flex items-center gap-2 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-sm text-white hover:border-bambu-gray-dark transition-colors`,children:[(0,G.jsxs)(`span`,{className:`text-bambu-gray`,children:[e,`:`]}),(0,G.jsx)(`span`,{children:o?.label||`All`}),(0,G.jsx)(ds,{className:`w-4 h-4 text-bambu-gray transition-transform ${i?`rotate-180`:``}`})]}),i&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`fixed inset-0 z-10`,onClick:()=>a(!1)}),(0,G.jsx)(`div`,{className:`absolute top-full left-0 mt-1 min-w-[160px] bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl z-20 py-1 max-h-60 overflow-y-auto`,children:n.map(e=>(0,G.jsxs)(`button`,{onClick:()=>{r(e.value),a(!1)},className:`w-full px-3 py-2 text-left text-sm flex items-center justify-between hover:bg-bambu-dark-tertiary transition-colors ${t===e.value?`text-bambu-green`:`text-white`}`,children:[(0,G.jsx)(`span`,{children:e.label}),e.count!==void 0&&(0,G.jsx)(`span`,{className:`text-bambu-gray text-xs`,children:e.count})]},e.value))})]})]})}function _Ue(){let[e,t]=(0,y.useState)(!1);return(0,y.useEffect)(()=>{let e=()=>{t(window.scrollY>300)};return window.addEventListener(`scroll`,e),()=>window.removeEventListener(`scroll`,e)},[]),e?(0,G.jsx)(`button`,{onClick:()=>{window.scrollTo({top:0,behavior:`smooth`})},className:`fixed bottom-24 right-6 p-3 bg-bambu-green hover:bg-bambu-green-light text-white rounded-full shadow-lg shadow-bambu-green/25 transition-all z-40`,"aria-label":`Scroll to top`,children:(0,G.jsx)(Vo,{className:`w-5 h-5`})}):null}function f8({setting:e,onClick:t,onDuplicate:n,compareMode:r,isCompareSelected:i,compareIndex:a,compareDisabled:o,t:s}){let c=l8(e.name),l=u8(e.setting_id);return(0,G.jsxs)(`div`,{className:`flex items-center gap-2 group`,children:[(0,G.jsx)(`button`,{onClick:t,disabled:o,className:`flex-1 text-left px-3 py-2 rounded transition-colors ${i?`bg-blue-500/20 border border-blue-500/50`:o?`bg-bambu-dark/50 opacity-40 cursor-not-allowed`:`bg-bambu-dark hover:bg-bambu-dark-tertiary`} ${r&&!o?`cursor-pointer`:``}`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[i&&a!==void 0&&(0,G.jsx)(`span`,{className:`flex-shrink-0 w-5 h-5 rounded-full bg-blue-500 text-white text-xs flex items-center justify-center font-medium`,children:a+1}),!i&&l&&(0,G.jsx)(`span`,{className:`flex-shrink-0 w-1.5 h-1.5 rounded-full bg-bambu-green`,title:s(`profiles.presets.myPreset`)}),(0,G.jsx)(`span`,{className:`text-white text-sm truncate flex-1`,title:e.name,children:e.name}),c.filamentType&&e.type===`filament`&&(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:c.filamentType}),c.layerHeight&&e.type===`process`&&(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:c.layerHeight}),c.printer&&(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:c.printer})]})}),(0,G.jsx)(`button`,{onClick:e=>{e.stopPropagation(),n()},className:`opacity-0 group-hover:opacity-100 text-bambu-gray hover:text-white transition-all p-1`,title:s(`profiles.presets.duplicate`),children:(0,G.jsx)(zs,{className:`w-4 h-4`})})]})}function p8(e,t=0){let n=` `.repeat(t);if(e===null)return`null`;if(e===void 0)return`undefined`;if(typeof e==`string`){if(e.includes(`\\n`)||e.includes(`
+`)),i(!0),setTimeout(()=>i(!1),2e3)},className:`flex items-center gap-2`,children:[(0,G.jsx)(zs,{className:`w-4 h-4`}),n(r?`common.copied`:`common.copy`)]}),(0,G.jsx)(Q,{variant:`primary`,size:`sm`,onClick:t,className:`flex-1`,children:n(`settings.twoFa.savedCodes`)})]})]})}function IHe({onDone:e}){let{t}=U(),n=so(),{showToast:r}=Bd(),[i,a]=(0,y.useState)(`qr`),[o,s]=(0,y.useState)(``),[c,l]=(0,y.useState)([]),[u,d]=(0,y.useState)(!1),{data:f,isLoading:p}=K({queryKey:[`totp-setup`],queryFn:()=>Z.setupTOTP(),staleTime:1/0}),m=q({mutationFn:e=>Z.enableTOTP(e),onSuccess:e=>{l(e.backup_codes),a(`backup`),n.invalidateQueries({queryKey:[`2fa-status`]})},onError:()=>r(t(`settings.twoFa.invalidCode`),`error`)});return p||!f?(0,G.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,G.jsx)(zl,{className:`w-6 h-6 animate-spin text-bambu-green`})}):i===`qr`?(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsx)(`p`,{className:`text-bambu-gray-light text-sm`,children:t(`settings.twoFa.setupInstructions`)}),(0,G.jsx)(`div`,{className:`flex justify-center`,children:(0,G.jsx)(`img`,{src:`data:image/png;base64,${f.qr_code_b64}`,alt:`TOTP QR Code`,className:`w-48 h-48 rounded-lg`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mb-1`,children:t(`settings.twoFa.manualEntry`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 bg-bambu-dark-secondary rounded-lg px-3 py-2`,children:[(0,G.jsx)(`code`,{className:`text-white text-xs font-mono flex-1 break-all`,children:u?f.secret:`••••••••••••••••`}),(0,G.jsx)(`button`,{onClick:()=>d(!u),className:`text-bambu-gray hover:text-white`,children:u?(0,G.jsx)(nc,{className:`w-4 h-4`}):(0,G.jsx)(rc,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:()=>{navigator.clipboard.writeText(f.secret)},className:`text-bambu-gray hover:text-white`,children:(0,G.jsx)(zs,{className:`w-4 h-4`})})]})]}),(0,G.jsx)(Q,{variant:`primary`,className:`w-full`,onClick:()=>a(`confirm`),children:t(`settings.twoFa.scannedContinue`)})]}):i===`confirm`?(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsx)(`p`,{className:`text-bambu-gray-light text-sm`,children:t(`settings.twoFa.enterCodeToConfirm`)}),(0,G.jsx)(A6,{value:o,onChange:s,placeholder:`000000`}),(0,G.jsxs)(`div`,{className:`flex gap-3`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>a(`qr`),className:`flex-1`,children:t(`common.back`)}),(0,G.jsx)(Q,{variant:`primary`,className:`flex-1`,disabled:o.length!==6||m.isPending,onClick:()=>m.mutate(o),children:m.isPending?t(`common.saving`):t(`settings.twoFa.activate`)})]})]}):(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsx)(`h3`,{className:`text-white font-medium`,children:t(`settings.twoFa.backupCodesTitle`)}),(0,G.jsx)(j6,{codes:c,onDone:e})]})}function LHe(){let{t:e}=U(),t=so(),{showToast:n}=Bd(),{user:r}=Ed(),[i,a]=(0,y.useState)(!1),[o,s]=(0,y.useState)(!1),[c,l]=(0,y.useState)(!1),[u,d]=(0,y.useState)(``),[f,p]=(0,y.useState)(``),[m,h]=(0,y.useState)(null),[g,_]=(0,y.useState)(null),[v,b]=(0,y.useState)(``),[x,S]=(0,y.useState)(!1),[C,w]=(0,y.useState)(``),[T,E]=(0,y.useState)(!1),{data:D,isLoading:O}=K({queryKey:[`2fa-status`],queryFn:()=>Z.get2FAStatus()}),{data:k}=K({queryKey:[`oidc-links`],queryFn:()=>Z.getOIDCLinks()}),A=q({mutationFn:()=>Z.enableEmailOTP(),onSuccess:e=>{_(e.setup_token),n(e.message,`success`)},onError:t=>{let r=t.message??``;r.toLowerCase().includes(`smtp`)?n(e(`settings.twoFa.smtpRequired`),`error`):n(r,`error`)}}),j=q({mutationFn:()=>Z.confirmEnableEmailOTP(g,v),onSuccess:()=>{t.invalidateQueries({queryKey:[`2fa-status`]}),_(null),b(``),n(e(`settings.twoFa.emailOtpEnabled`),`success`)},onError:e=>n(e.message,`error`)}),M=q({mutationFn:e=>Z.disableEmailOTP(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`2fa-status`]}),S(!1),w(``),n(e(`settings.twoFa.emailOtpDisabled`),`success`)},onError:e=>n(e.message,`error`)}),N=q({mutationFn:e=>Z.disableTOTP(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`2fa-status`]}),s(!1),d(``),n(e(`settings.twoFa.totpDisabled`),`success`)},onError:()=>n(e(`settings.twoFa.invalidCode`),`error`)}),P=q({mutationFn:e=>Z.regenerateBackupCodes(e),onSuccess:e=>{t.invalidateQueries({queryKey:[`2fa-status`]}),l(!1),p(``),h(e.backup_codes)},onError:()=>n(e(`settings.twoFa.invalidCode`),`error`)}),F=q({mutationFn:e=>Z.deleteOIDCLink(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`oidc-links`]}),n(e(`settings.twoFa.oidcUnlinked`),`success`)},onError:e=>n(e.message,`error`)});if(O)return(0,G.jsx)(`div`,{className:`flex items-center justify-center py-12`,children:(0,G.jsx)(zl,{className:`w-6 h-6 animate-spin text-bambu-green`})});let I=!!r?.email;return(0,G.jsxs)(`div`,{className:`space-y-6`,children:[(0,G.jsxs)(Md,{id:`card-2fa-totp`,children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`w-10 h-10 rounded-full flex items-center justify-center ${D?.totp_enabled?`bg-green-100 dark:bg-green-500/20`:`bg-gray-500/20`}`,children:(0,G.jsx)(du,{className:`w-5 h-5 ${D?.totp_enabled?`text-green-600 dark:text-green-400`:`text-gray-400`}`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`text-white font-semibold`,children:e(`settings.twoFa.totpTitle`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-sm`,children:e(`settings.twoFa.totpDesc`)})]}),(0,G.jsx)(`div`,{className:`ml-auto`,children:D?.totp_enabled?(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-green-700 dark:text-green-400 text-sm font-medium`,children:[(0,G.jsx)(nu,{className:`w-4 h-4`}),` `,e(`common.enabled`)]}):(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-bambu-gray text-sm`,children:[(0,G.jsx)(ru,{className:`w-4 h-4`}),` `,e(`common.disabled`)]})})]})}),(0,G.jsx)(Pd,{children:i?(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,G.jsx)(`h4`,{className:`text-white font-medium`,children:e(`settings.twoFa.setupAuthApp`)}),(0,G.jsx)(`button`,{onClick:()=>{a(!1),t.removeQueries({queryKey:[`totp-setup`]})},className:`text-bambu-gray hover:text-white`,children:(0,G.jsx)($u,{className:`w-5 h-5`})})]}),(0,G.jsx)(IHe,{onDone:()=>{a(!1),t.removeQueries({queryKey:[`totp-setup`]})}})]}):o?(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsx)(`p`,{className:`text-bambu-gray-light text-sm`,children:e(`settings.twoFa.disableConfirmHint`)}),(0,G.jsx)(A6,{value:u,onChange:d,placeholder:`000000 or XXXXXXXX`,maxLength:8}),(0,G.jsxs)(`div`,{className:`flex gap-3`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>{s(!1),d(``)},className:`flex-1`,children:e(`common.cancel`)}),(0,G.jsx)(Q,{variant:`danger`,className:`flex-1`,disabled:u.length<6||N.isPending,onClick:()=>N.mutate(u),children:N.isPending?e(`common.saving`):e(`settings.twoFa.disableTotp`)})]})]}):c?(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsx)(`p`,{className:`text-bambu-gray-light text-sm`,children:e(`settings.twoFa.regenBackupHint`)}),(0,G.jsx)(A6,{value:f,onChange:p,placeholder:`000000 or XXXXXXXX`,maxLength:8}),(0,G.jsxs)(`div`,{className:`flex gap-3`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>{l(!1),p(``)},className:`flex-1`,children:e(`common.cancel`)}),(0,G.jsx)(Q,{variant:`primary`,className:`flex-1`,disabled:f.length<6||P.isPending,onClick:()=>P.mutate(f),children:P.isPending?e(`common.saving`):e(`settings.twoFa.regenBackup`)})]})]}):m?(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsx)(`h4`,{className:`text-white font-medium`,children:e(`settings.twoFa.newBackupCodes`)}),(0,G.jsx)(j6,{codes:m,onDone:()=>h(null)})]}):(0,G.jsx)(`div`,{className:`space-y-3`,children:D?.totp_enabled?(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-bambu-gray-light`,children:[(0,G.jsx)(Uc,{className:`w-4 h-4`}),e(`settings.twoFa.backupCodesRemaining`,{count:D.backup_codes_remaining})]}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:()=>l(!0),className:`flex items-center gap-2`,children:[(0,G.jsx)(zl,{className:`w-4 h-4`}),e(`settings.twoFa.regenBackup`)]}),(0,G.jsxs)(Q,{variant:`danger`,size:`sm`,onClick:()=>s(!0),className:`flex items-center gap-2`,children:[(0,G.jsx)(ju,{className:`w-4 h-4`}),e(`settings.twoFa.disableTotp`)]})]}):(0,G.jsxs)(Q,{variant:`primary`,onClick:()=>a(!0),className:`flex items-center gap-2`,children:[(0,G.jsx)(du,{className:`w-4 h-4`}),e(`settings.twoFa.setupTotp`)]})})})]}),(0,G.jsxs)(Md,{id:`card-2fa-emailotp`,children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`w-10 h-10 rounded-full flex items-center justify-center ${D?.email_otp_enabled?`bg-green-100 dark:bg-green-500/20`:`bg-gray-500/20`}`,children:(0,G.jsx)(rl,{className:`w-5 h-5 ${D?.email_otp_enabled?`text-green-600 dark:text-green-400`:`text-gray-400`}`})}),(0,G.jsxs)(`div`,{className:`flex-1`,children:[(0,G.jsx)(`h3`,{className:`text-white font-semibold`,children:e(`settings.twoFa.emailOtpTitle`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-sm`,children:I?e(`settings.twoFa.emailOtpDesc`,{email:r?.email}):e(`settings.twoFa.emailOtpNoEmail`)})]}),(0,G.jsx)(`div`,{className:`ml-auto`,children:D?.email_otp_enabled?(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-green-700 dark:text-green-400 text-sm font-medium`,children:[(0,G.jsx)(nu,{className:`w-4 h-4`}),` `,e(`common.enabled`)]}):(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-bambu-gray text-sm`,children:[(0,G.jsx)(ru,{className:`w-4 h-4`}),` `,e(`common.disabled`)]})})]})}),(0,G.jsx)(Pd,{children:I?g?(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsx)(`p`,{className:`text-bambu-gray-light text-sm`,children:e(`settings.twoFa.emailSetupEnterCode`)}),(0,G.jsx)(A6,{value:v,onChange:b,placeholder:`000000`}),(0,G.jsxs)(`div`,{className:`flex gap-3`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>{_(null),b(``)},className:`flex-1`,children:e(`common.cancel`)}),(0,G.jsx)(Q,{variant:`primary`,className:`flex-1`,disabled:v.length!==6||j.isPending,onClick:()=>j.mutate(),children:j.isPending?e(`common.saving`):e(`settings.twoFa.verifyAndEnable`)})]})]}):x?(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsx)(`p`,{className:`text-bambu-gray-light text-sm`,children:e(`settings.twoFa.emailDisablePasswordHint`)}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(`input`,{type:T?`text`:`password`,value:C,onChange:e=>w(e.target.value),placeholder:e(`settings.twoFa.passwordPlaceholder`),className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>E(!T),className:`absolute right-3 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white`,children:T?(0,G.jsx)(nc,{className:`w-5 h-5`}):(0,G.jsx)(rc,{className:`w-5 h-5`})})]}),(0,G.jsxs)(`div`,{className:`flex gap-3`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>{S(!1),w(``)},className:`flex-1`,children:e(`common.cancel`)}),(0,G.jsx)(Q,{variant:`danger`,className:`flex-1`,disabled:!C||M.isPending,onClick:()=>M.mutate(C),children:M.isPending?e(`common.saving`):e(`settings.twoFa.disableEmailOtp`)})]})]}):(0,G.jsx)(`div`,{className:`flex gap-3`,children:D?.email_otp_enabled?(0,G.jsxs)(Q,{variant:`danger`,size:`sm`,onClick:()=>S(!0),className:`flex items-center gap-2`,children:[(0,G.jsx)(ju,{className:`w-4 h-4`}),e(`settings.twoFa.disableEmailOtp`)]}):(0,G.jsxs)(Q,{variant:`primary`,disabled:!I||A.isPending,onClick:()=>A.mutate(),className:`flex items-center gap-2`,children:[(0,G.jsx)(rl,{className:`w-4 h-4`}),A.isPending?e(`common.saving`):e(`settings.twoFa.enableEmailOtp`)]})}):(0,G.jsx)(`p`,{className:`text-amber-700 dark:text-amber-400 text-sm`,children:e(`settings.twoFa.addEmailFirst`)})})]}),k&&k.length>0&&(0,G.jsxs)(Md,{id:`card-2fa-linked`,children:[(0,G.jsxs)(Nd,{children:[(0,G.jsx)(`h3`,{className:`text-white font-semibold`,children:e(`settings.twoFa.linkedAccounts`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-sm`,children:e(`settings.twoFa.linkedAccountsDesc`)})]}),(0,G.jsx)(Pd,{children:(0,G.jsx)(`div`,{className:`space-y-3`,children:k.map(e=>(0,G.jsxs)(`div`,{className:`flex items-center justify-between py-2 border-b border-bambu-dark-tertiary last:border-0`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white text-sm font-medium`,children:e.provider_name}),e.provider_email&&(0,G.jsx)(`p`,{className:`text-bambu-gray text-xs`,children:e.provider_email})]}),(0,G.jsx)(Q,{variant:`danger`,size:`sm`,onClick:()=>F.mutate(e.provider_id),disabled:F.isPending,children:(0,G.jsx)(ju,{className:`w-4 h-4`})})]},e.id))})})]})]})}var RHe={name:``,issuer_url:``,client_id:``,client_secret:``,scopes:`openid email profile`,is_enabled:!0,auto_create_users:!1,auto_link_existing_accounts:!1,email_claim:`email`,require_email_verified:!0,icon_url:void 0,default_group_id:null,is_autologin:!1};function M6({initial:e,isEdit:t=!1,groups:n=[],onSave:r,onCancel:i,isPending:a}){let{t:o}=U(),[s,c]=(0,y.useState)(e),[l,u]=(0,y.useState)(!1),d=(e,t)=>c(n=>({...n,[e]:t})),f=`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors text-sm`,p=`block text-sm font-medium text-white mb-1`,m=()=>{let e={...s};t&&!l&&delete e.client_secret,r(e)},h=s.auto_link_existing_accounts===!0,g=s.require_email_verified??!0,_;return _=h?o(`settings.oidc.form.requireEmailVerifiedAutoLink`):g?o(`settings.oidc.form.requireEmailVerifiedDesc`):(0,G.jsx)(`span`,{className:`text-red-700 dark:text-red-400`,children:o(`settings.oidc.form.requireEmailVerifiedWarning`)}),(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:p,children:[o(`settings.oidc.form.name`),` `,(0,G.jsx)(`span`,{className:`text-red-700 dark:text-red-400`,children:`*`})]}),(0,G.jsx)(`input`,{className:f,value:s.name,onChange:e=>d(`name`,e.target.value),placeholder:`Google`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:p,children:[o(`settings.oidc.form.issuerUrl`),` `,(0,G.jsx)(`span`,{className:`text-red-700 dark:text-red-400`,children:`*`})]}),(0,G.jsx)(`input`,{className:f,value:s.issuer_url,onChange:e=>d(`issuer_url`,e.target.value),placeholder:`https://accounts.google.com`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:p,children:[o(`settings.oidc.form.clientId`),` `,(0,G.jsx)(`span`,{className:`text-red-700 dark:text-red-400`,children:`*`})]}),(0,G.jsx)(`input`,{className:f,value:s.client_id,onChange:e=>d(`client_id`,e.target.value),placeholder:`your-client-id`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:p,children:[o(`settings.oidc.form.clientSecret`),!t&&(0,G.jsx)(`span`,{className:`text-red-700 dark:text-red-400`,children:` *`}),t&&(0,G.jsxs)(`span`,{className:`text-bambu-gray text-xs ml-1`,children:[`(`,o(`settings.oidc.form.secretHint`),`)`]})]}),(0,G.jsx)(`input`,{className:f,type:`password`,value:l?s.client_secret:``,placeholder:t&&!l?`••••••••`:o(`settings.oidc.form.secretPlaceholder`),onChange:e=>{u(!0),d(`client_secret`,e.target.value)}})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:p,children:o(`settings.oidc.form.scopes`)}),(0,G.jsx)(`input`,{className:f,value:s.scopes,onChange:e=>d(`scopes`,e.target.value),placeholder:`openid email profile`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:p,children:o(`settings.oidc.form.iconUrl`)}),(0,G.jsx)(`input`,{className:f,value:s.icon_url??``,onChange:e=>d(`icon_url`,e.target.value===``?null:e.target.value),placeholder:`https://...`})]})]}),(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-6 pt-2`,children:[(0,G.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,G.jsx)(UH,{checked:s.is_enabled??!0,onChange:e=>d(`is_enabled`,e)}),(0,G.jsx)(`span`,{className:`text-white text-sm`,children:o(`settings.oidc.form.enabled`)})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,G.jsx)(UH,{checked:s.auto_create_users??!1,onChange:e=>d(`auto_create_users`,e)}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white text-sm`,children:o(`settings.oidc.form.autoCreate`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-xs`,children:o(`settings.oidc.form.autoCreateDesc`)})]})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer w-full`,children:[(0,G.jsx)(UH,{checked:s.auto_link_existing_accounts??!1,onChange:e=>d(`auto_link_existing_accounts`,e)}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white text-sm`,children:o(`settings.oidc.form.autoLink`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-xs`,children:o(`settings.oidc.form.autoLinkDesc`)})]})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer w-full`,children:[(0,G.jsx)(UH,{checked:g,onChange:e=>d(`require_email_verified`,e),disabled:h}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white text-sm`,children:o(`settings.oidc.form.requireEmailVerified`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-xs`,children:_})]})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer w-full`,children:[(0,G.jsx)(UH,{checked:s.is_autologin??!1,onChange:e=>d(`is_autologin`,e)}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white text-sm`,children:o(`settings.oidc.form.autologin`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-xs`,children:o(`settings.oidc.form.autologinDesc`)})]})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:p,children:o(`settings.oidc.form.emailClaim`)}),(0,G.jsx)(`input`,{className:f,value:s.email_claim,onChange:e=>d(`email_claim`,e.target.value||`email`),placeholder:o(`settings.oidc.form.emailClaimPlaceholder`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-xs mt-1`,children:o(`settings.oidc.form.emailClaimDesc`)}),h&&s.email_claim!==`email`&&(0,G.jsx)(`p`,{className:`text-yellow-700 dark:text-yellow-400 text-xs mt-1`,children:o(`settings.oidc.form.emailClaimCustomClaimAutoLinkWarning`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:p,children:o(`settings.oidc.form.defaultGroup`)}),(0,G.jsxs)(`select`,{className:f,value:s.default_group_id??``,onChange:e=>d(`default_group_id`,e.target.value?Number(e.target.value):null),children:[(0,G.jsx)(`option`,{value:``,children:o(`settings.oidc.form.defaultGroupViewersFallback`)}),n.map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-xs mt-1`,children:o(`settings.oidc.form.defaultGroupDesc`)})]}),(0,G.jsxs)(`div`,{className:`flex gap-3 pt-2`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:i,className:`flex-1`,children:o(`common.cancel`)}),(0,G.jsx)(Q,{variant:`primary`,className:`flex-1`,disabled:!s.name||!s.issuer_url||!s.client_id||!t&&!s.client_secret||t&&l&&!s.client_secret||a,onClick:m,children:o(a?`common.saving`:`common.save`)})]})]})}function zHe({provider:e}){let[t,n]=(0,y.useState)(!1);return e.has_icon&&!t?(0,G.jsx)(`img`,{src:Z.oidcProviderIconUrl(e.id),alt:e.name,className:`w-8 h-8 rounded object-contain`,onError:()=>n(!0)}):(0,G.jsx)(`div`,{className:`w-8 h-8 rounded-full bg-bambu-dark-tertiary flex items-center justify-center`,children:(0,G.jsx)(Dc,{className:`w-4 h-4 text-bambu-gray`})})}function BHe(){let{t:e}=U(),t=so(),{showToast:n}=Bd(),[r,i]=(0,y.useState)(!1),[a,o]=(0,y.useState)(null),[s,c]=(0,y.useState)(null),{data:l,isLoading:u}=K({queryKey:[`oidc-providers-all`],queryFn:()=>Z.getOIDCProvidersAll()}),{data:d=[]}=K({queryKey:[`groups`],queryFn:()=>Z.getGroups()}),f=q({mutationFn:e=>Z.createOIDCProvider(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`oidc-providers-all`]}),i(!1),n(e(`settings.oidc.created`),`success`)},onError:e=>n(e.message,`error`)}),p=q({mutationFn:({id:e,data:t})=>Z.updateOIDCProvider(e,t),onSuccess:()=>{t.invalidateQueries({queryKey:[`oidc-providers-all`]}),o(null),n(e(`settings.oidc.updated`),`success`)},onError:e=>n(e.message,`error`)}),m=q({mutationFn:e=>Z.deleteOIDCProvider(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`oidc-providers-all`]}),c(null),n(e(`settings.oidc.deleted`),`success`)},onError:e=>n(e.message,`error`)}),h=q({mutationFn:e=>Z.refreshOIDCProviderIcon(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`oidc-providers-all`]}),t.invalidateQueries({queryKey:[`oidc-providers`]}),n(e(`settings.oidc.iconRefreshed`),`success`)},onError:t=>n(t.message||e(`settings.oidc.iconFetchFailed`),`error`)}),g=q({mutationFn:e=>Z.deleteOIDCProviderIcon(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`oidc-providers-all`]}),t.invalidateQueries({queryKey:[`oidc-providers`]}),n(e(`settings.oidc.iconRemoved`),`success`)},onError:e=>n(e.message,`error`)}),_=e=>p.mutate({id:e.id,data:{is_enabled:!e.is_enabled}});return u?(0,G.jsx)(`div`,{className:`flex items-center justify-center py-12`,children:(0,G.jsx)(zl,{className:`w-6 h-6 animate-spin text-bambu-green`})}):(0,G.jsxs)(`div`,{className:`space-y-6`,children:[(0,G.jsxs)(Md,{id:`card-oidc`,children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`text-white font-semibold`,children:e(`settings.oidc.title`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-sm`,children:e(`settings.oidc.desc`)})]}),!r&&(0,G.jsxs)(Q,{variant:`primary`,size:`sm`,onClick:()=>i(!0),className:`flex items-center gap-2`,children:[(0,G.jsx)(Ml,{className:`w-4 h-4`}),e(`settings.oidc.addProvider`)]})]})}),r&&(0,G.jsx)(Pd,{children:(0,G.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary pt-4`,children:[(0,G.jsx)(`h4`,{className:`text-white font-medium mb-4`,children:e(`settings.oidc.newProvider`)}),(0,G.jsx)(M6,{initial:RHe,groups:d,onSave:e=>f.mutate(e),onCancel:()=>i(!1),isPending:f.isPending})]})})]}),l&&l.length===0&&!r&&(0,G.jsx)(Md,{id:`card-oidc-empty`,children:(0,G.jsx)(Pd,{children:(0,G.jsxs)(`div`,{className:`text-center py-8 space-y-3`,children:[(0,G.jsx)(Dc,{className:`w-12 h-12 text-bambu-gray mx-auto`}),(0,G.jsx)(`p`,{className:`text-bambu-gray`,children:e(`settings.oidc.empty`)}),(0,G.jsxs)(Q,{variant:`primary`,size:`sm`,onClick:()=>i(!0),className:`inline-flex items-center gap-2`,children:[(0,G.jsx)(Ml,{className:`w-4 h-4`}),e(`settings.oidc.addProvider`)]})]})})}),l?.map(t=>(0,G.jsxs)(Md,{children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(zHe,{provider:t}),(0,G.jsxs)(`div`,{className:`flex-1`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`h4`,{className:`text-white font-medium`,children:t.name}),t.is_enabled?(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-xs text-green-700 dark:text-green-400 bg-green-50 dark:bg-green-400/10 px-2 py-0.5 rounded-full`,children:[(0,G.jsx)(us,{className:`w-3 h-3`}),` `,e(`common.enabled`)]}):(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-xs text-bambu-gray bg-bambu-dark-tertiary px-2 py-0.5 rounded-full`,children:[(0,G.jsx)($u,{className:`w-3 h-3`}),` `,e(`common.disabled`)]}),t.is_env_managed&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-xs text-bambu-green`,children:[(0,G.jsx)(el,{className:`w-3 h-3`}),` `,e(`settings.environmentManagedLabel`)]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1 text-bambu-gray text-xs mt-0.5`,children:[(0,G.jsx)(tc,{className:`w-3 h-3`}),(0,G.jsx)(`span`,{children:t.issuer_url})]})]}),(0,G.jsx)(`div`,{className:`flex items-center gap-2`,children:!t.is_env_managed&&(0,G.jsxs)(G.Fragment,{children:[t.icon_url&&(0,G.jsx)(Q,{variant:`secondary`,size:`sm`,onClick:()=>h.mutate(t.id),disabled:h.isPending,title:e(`settings.oidc.refreshIcon`),"data-testid":`refresh-icon-${t.id}`,children:(0,G.jsx)(zl,{className:`w-4 h-4 ${h.isPending?`animate-spin`:``}`})}),t.has_icon&&(0,G.jsx)(Q,{variant:`secondary`,size:`sm`,onClick:()=>g.mutate(t.id),disabled:g.isPending,title:e(`settings.oidc.removeIcon`),"data-testid":`remove-icon-${t.id}`,children:(0,G.jsx)(Rc,{className:`w-4 h-4`})}),(0,G.jsx)(UH,{checked:t.is_enabled,onChange:()=>_(t),disabled:p.isPending}),(0,G.jsx)(Q,{variant:`secondary`,size:`sm`,onClick:()=>o(a===t.id?null:t.id),"data-testid":`edit-provider-${t.id}`,children:(0,G.jsx)(Dl,{className:`w-4 h-4`})}),(0,G.jsx)(Q,{variant:`danger`,size:`sm`,onClick:()=>c(t),"data-testid":`delete-provider-${t.id}`,children:(0,G.jsx)(ju,{className:`w-4 h-4`})})]})})]})}),a===t.id&&(0,G.jsx)(Pd,{children:(0,G.jsx)(`div`,{className:`border-t border-bambu-dark-tertiary pt-4`,children:(0,G.jsx)(M6,{isEdit:!0,groups:d,initial:{name:t.name,issuer_url:t.issuer_url,client_id:t.client_id,client_secret:``,scopes:t.scopes,is_enabled:t.is_enabled,auto_create_users:t.auto_create_users,auto_link_existing_accounts:t.auto_link_existing_accounts,email_claim:t.email_claim,require_email_verified:t.require_email_verified,icon_url:t.icon_url??void 0,default_group_id:t.default_group_id??null,is_autologin:t.is_autologin},onSave:e=>p.mutate({id:t.id,data:e}),onCancel:()=>o(null),isPending:p.isPending})})}),a!==t.id&&(0,G.jsx)(Pd,{children:(0,G.jsxs)(`dl`,{className:`grid grid-cols-2 sm:grid-cols-3 gap-x-6 gap-y-2 text-sm`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`dt`,{className:`text-bambu-gray`,children:e(`settings.oidc.form.clientId`)}),(0,G.jsx)(`dd`,{className:`text-white font-mono truncate`,children:t.client_id})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`dt`,{className:`text-bambu-gray`,children:e(`settings.oidc.form.scopes`)}),(0,G.jsx)(`dd`,{className:`text-white`,children:t.scopes})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`dt`,{className:`text-bambu-gray`,children:e(`settings.oidc.form.autoCreate`)}),(0,G.jsx)(`dd`,{className:t.auto_create_users?`text-green-700 dark:text-green-400`:`text-bambu-gray`,children:t.auto_create_users?e(`common.yes`):e(`common.no`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`dt`,{className:`text-bambu-gray`,children:e(`settings.oidc.form.autoLink`)}),(0,G.jsx)(`dd`,{className:t.auto_link_existing_accounts?`text-green-700 dark:text-green-400`:`text-bambu-gray`,children:t.auto_link_existing_accounts?e(`common.yes`):e(`common.no`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`dt`,{className:`text-bambu-gray`,children:e(`settings.oidc.form.emailClaim`)}),(0,G.jsx)(`dd`,{className:`text-white font-mono`,children:t.email_claim})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`dt`,{className:`text-bambu-gray`,children:e(`settings.oidc.form.requireEmailVerified`)}),(0,G.jsx)(`dd`,{className:t.require_email_verified?`text-green-700 dark:text-green-400`:`text-red-700 dark:text-red-400`,children:t.require_email_verified?e(`common.yes`):e(`common.no`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`dt`,{className:`text-bambu-gray`,children:e(`settings.oidc.form.defaultGroup`)}),(0,G.jsx)(`dd`,{className:`text-white`,children:t.default_group_id?d.find(e=>e.id===t.default_group_id)?.name??e(`settings.oidc.form.defaultGroupViewersFallback`):e(`settings.oidc.form.defaultGroupViewersFallback`)})]})]})})]},t.id)),s&&(0,G.jsx)(Zd,{title:e(`settings.oidc.deleteTitle`),message:e(`settings.oidc.deleteMessage`,{name:s.name}),confirmText:e(`common.delete`),variant:`danger`,onConfirm:()=>m.mutate(s.id),onCancel:()=>c(null)})]})}var N6=new Map;function P6(e){N6.set(e.anchor,e)}function VHe(){return Array.from(N6.values())}P6({labelKey:`settings.encryption.title`,labelFallback:`MFA Encryption Status`,tab:`users`,subTab:`security`,keywords:`mfa encryption status security backup totp oidc fernet`,anchor:`card-mfa-encryption`});function HHe(){let{t:e}=U(),{data:t,isLoading:n,isError:r,refetch:i}=K({queryKey:[`encryptionStatus`],queryFn:()=>Z.getEncryptionStatus(),refetchInterval:e=>{if(!e.state.error)return 3e4;let t=e.state.fetchFailureCount??0;return t<=3?Math.min(5e3*Math.max(1,t),3e4):!1}});if(n)return(0,G.jsxs)(Md,{id:`card-mfa-encryption`,"data-testid":`encryption-status-card`,children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(iu,{className:`text-bambu-gray`,size:20}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold`,children:e(`settings.encryption.title`)})]})}),(0,G.jsx)(Pd,{children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray`,"data-testid":`encryption-loading`,children:[(0,G.jsx)(Y,{className:`animate-spin`,size:16}),(0,G.jsx)(`span`,{children:e(`common.loading`)})]})})]});if(r||!t)return(0,G.jsxs)(Md,{id:`card-mfa-encryption`,"data-testid":`encryption-status-card`,children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(iu,{className:`text-bambu-gray`,size:20}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold`,children:e(`settings.encryption.title`)})]})}),(0,G.jsxs)(Pd,{children:[(0,G.jsx)(`div`,{className:`text-red-700 dark:text-red-400`,"data-testid":`encryption-error`,children:e(`common.errorLoading`)}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>i(),className:`mt-2 text-sm text-blue-700 dark:text-blue-400 underline hover:text-blue-800 dark:hover:text-blue-300`,"data-testid":`encryption-retry-button`,children:e(`common.retry`)})]})]});let a=t.legacy_plaintext_rows.oidc_providers+t.legacy_plaintext_rows.user_totp,o=t.encrypted_rows.oidc_providers+t.encrypted_rows.user_totp,s,c,l,u;t.decryption_broken?(s=`bg-red-100 dark:bg-red-500/20 border-red-400 dark:border-red-500/50 text-red-700 dark:text-red-400`,c=(0,G.jsx)(Ts,{className:`text-red-600 dark:text-red-400`,size:20}),l=e(`settings.encryption.decryptionBrokenTitle`),u=e(`settings.encryption.decryptionBrokenError`,{count:o})):t.key_source===`generated`?(s=`bg-amber-50 dark:bg-amber-500/10 border-amber-300 dark:border-amber-500/30 text-amber-700 dark:text-amber-400`,c=(0,G.jsx)(nu,{className:`text-amber-600 dark:text-amber-400`,size:20}),l=e(`settings.encryption.enabledGenerated`),u=e(`settings.encryption.backupHint`)):a>0?(s=`bg-amber-50 dark:bg-amber-500/10 border-amber-300 dark:border-amber-500/30 text-amber-700 dark:text-amber-400`,c=(0,G.jsx)(Pu,{className:`text-amber-600 dark:text-amber-400`,size:20}),l=t.key_source===`env`?e(`settings.encryption.enabledFromEnv`):e(`settings.encryption.enabledFromFile`),u=e(`settings.encryption.legacyRowsWarning`,{count:a})):t.key_configured?(s=`bg-green-100 dark:bg-green-500/20 border-green-300 dark:border-green-500/30 text-green-700 dark:text-green-400`,c=(0,G.jsx)(nu,{className:`text-green-600 dark:text-green-400`,size:20}),l=t.key_source===`env`?e(`settings.encryption.enabledFromEnv`):e(`settings.encryption.enabledFromFile`),u=e(`settings.encryption.allEncrypted`)):(s=`bg-gray-500/20 border-gray-500/30 text-gray-400`,c=(0,G.jsx)(ru,{className:`text-gray-400`,size:20}),l=e(`settings.encryption.notConfigured`),u=e(`settings.encryption.notConfiguredDesc`));let d=t.key_source===`generated`&&a>0;return(0,G.jsxs)(Md,{id:`card-mfa-encryption`,"data-testid":`encryption-status-card`,children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[c,(0,G.jsx)(`h2`,{className:`text-lg font-semibold`,children:e(`settings.encryption.title`)})]})}),(0,G.jsxs)(Pd,{children:[(0,G.jsxs)(`div`,{className:`p-3 border rounded-lg ${s}`,"data-testid":`encryption-status`,children:[(0,G.jsx)(`p`,{className:`font-medium mb-1`,children:l}),(0,G.jsx)(`p`,{className:`text-sm`,children:u})]}),d&&(0,G.jsx)(`div`,{className:`mt-2 p-3 border rounded-lg bg-amber-50 dark:bg-amber-500/10 border-amber-300 dark:border-amber-500/30 text-amber-700 dark:text-amber-400`,"data-testid":`encryption-legacy-warning`,children:(0,G.jsx)(`p`,{className:`text-sm`,children:e(`settings.encryption.legacyRowsWarning`,{count:a})})}),t.migration_error_count>0&&(0,G.jsx)(`div`,{className:`mt-2 p-3 border rounded-lg bg-amber-50 dark:bg-amber-500/10 border-amber-300 dark:border-amber-500/30 text-amber-700 dark:text-amber-400`,"data-testid":`encryption-migration-warning`,children:(0,G.jsx)(`p`,{className:`text-sm`,children:e(`settings.encryption.migrationErrorWarning`,{count:t.migration_error_count})})}),(0,G.jsxs)(`div`,{className:`mt-4 grid grid-cols-2 gap-4 text-sm`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-bambu-gray`,children:e(`settings.encryption.encryptedRowsLabel`)}),(0,G.jsxs)(`p`,{className:`font-medium`,children:[`OIDC: `,t.encrypted_rows.oidc_providers,` · TOTP: `,t.encrypted_rows.user_totp]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-bambu-gray`,children:e(`settings.encryption.legacyRowsLabel`)}),(0,G.jsxs)(`p`,{className:`font-medium`,children:[`OIDC: `,t.legacy_plaintext_rows.oidc_providers,` · TOTP: `,t.legacy_plaintext_rows.user_totp]})]})]})]})]})}var UHe={get:`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400 border-blue-300 dark:border-blue-500/30`,post:`bg-green-100 dark:bg-green-500/20 text-green-700 dark:text-green-400 border-green-300 dark:border-green-500/30`,put:`bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400 border-yellow-300 dark:border-yellow-500/30`,patch:`bg-orange-100 dark:bg-orange-500/20 text-orange-700 dark:text-orange-400 border-orange-300 dark:border-orange-500/30`,delete:`bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400 border-red-300 dark:border-red-500/30`};function WHe(e,t){let n=t.replace(`#/`,``).split(`/`),r=e;for(let e of n)r=r[e];return r}function F6(e,t,n=0){if(n>5)return`...`;if(t.$ref)return F6(e,WHe(e,t.$ref),n+1);if(t.allOf){let r={};for(let i of t.allOf){let t=F6(e,i,n+1);typeof t==`object`&&t&&Object.assign(r,t)}return r}if(t.example!==void 0)return t.example;if(t.default!==void 0)return t.default;switch(t.type){case`string`:return t.enum?t.enum[0]:`string`;case`integer`:case`number`:return 0;case`boolean`:return!1;case`array`:return t.items?[F6(e,t.items,n+1)]:[];case`object`:if(t.properties){let r={};for(let[i,a]of Object.entries(t.properties))r[i]=F6(e,a,n+1);return r}return{};default:return null}}function GHe({path:e,method:t,spec:n,schema:r,apiKey:i}){let[a,o]=(0,y.useState)(!1),[s,c]=(0,y.useState)({}),[l,u]=(0,y.useState)(``),[d,f]=(0,y.useState)(null),[p,m]=(0,y.useState)(!1),[h,g]=(0,y.useState)(!1);(0,y.useEffect)(()=>{if(a&&n.parameters){let e={};for(let t of n.parameters)t.schema?.default!==void 0&&(e[t.name]=String(t.schema.default));c(t=>({...e,...t}))}},[a,n.parameters]),(0,y.useEffect)(()=>{if(a&&n.requestBody?.content?.[`application/json`]?.schema&&!l){let e=n.requestBody.content[`application/json`].schema,t=F6(r,e);u(JSON.stringify(t,null,2))}},[a,n.requestBody,r,l]);let _=(()=>{let e=[];for(let t of n.parameters||[])if(t.in===`path`||t.required){let n=s[t.name];(n===void 0||n===``)&&e.push(t.name)}return e})(),v=async()=>{if(_.length>0){f({status:0,statusText:`Validation Error`,headers:{},body:`Missing required parameters: ${_.join(`, `)}`,duration:0});return}m(!0),f(null);try{let r=e,a=new URLSearchParams;for(let e of n.parameters||[]){let t=s[e.name];t!==void 0&&t!==``&&(e.in===`path`?r=r.replace(`{${e.name}}`,encodeURIComponent(t)):e.in===`query`&&a.append(e.name,t))}let o=a.toString(),c=`${r}${o?`?${o}`:``}`,u={"Content-Type":`application/json`};i&&(u[`X-API-Key`]=i);let d={method:t.toUpperCase(),headers:u};[`post`,`put`,`patch`].includes(t)&&l&&(d.body=l);let p=performance.now(),m=await fetch(c,d),h=Math.round(performance.now()-p),g={};m.headers.forEach((e,t)=>{g[t]=e});let _;_=m.headers.get(`content-type`)?.includes(`application/json`)?await m.json():await m.text(),f({status:m.status,statusText:m.statusText,headers:g,body:_,duration:h})}catch(e){f({status:0,statusText:`Network Error`,headers:{},body:e instanceof Error?e.message:`Unknown error`,duration:0})}finally{m(!1)}},b=async()=>{if(d){let e=typeof d.body==`string`?d.body:JSON.stringify(d.body,null,2);try{await navigator.clipboard.writeText(e),g(!0),setTimeout(()=>g(!1),2e3)}catch{let t=document.createElement(`textarea`);t.value=e,t.style.position=`fixed`,t.style.left=`-999999px`,document.body.appendChild(t),t.select(),document.execCommand(`copy`),document.body.removeChild(t),g(!0),setTimeout(()=>g(!1),2e3)}}},x=(n.parameters||[]).filter(e=>e.in===`path`),S=(n.parameters||[]).filter(e=>e.in===`query`),C=[`post`,`put`,`patch`].includes(t)&&n.requestBody;return(0,G.jsxs)(`div`,{className:`border border-bambu-dark-tertiary rounded-lg overflow-hidden`,children:[(0,G.jsxs)(`button`,{onClick:()=>o(!a),className:`w-full flex items-center gap-3 p-3 hover:bg-bambu-dark-tertiary/50 transition-colors text-left`,children:[a?(0,G.jsx)(ds,{className:`w-4 h-4 text-bambu-gray flex-shrink-0`}):(0,G.jsx)(fs,{className:`w-4 h-4 text-bambu-gray flex-shrink-0`}),(0,G.jsx)(`span`,{className:`px-2 py-0.5 text-xs font-mono font-semibold uppercase rounded border ${UHe[t]||`bg-gray-500/20 text-gray-400`}`,children:t}),(0,G.jsx)(`code`,{className:`text-sm text-white font-mono flex-1 truncate`,children:e}),n.summary&&(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray truncate max-w-[40%]`,children:n.summary})]}),a&&(0,G.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary p-4 space-y-4 bg-bambu-dark/50`,children:[n.description&&(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:n.description}),x.length>0&&(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`h4`,{className:`text-sm font-medium text-white`,children:`Path Parameters`}),(0,G.jsx)(`div`,{className:`space-y-2`,children:x.map(e=>(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`label`,{className:`text-sm text-bambu-gray w-32 flex-shrink-0`,children:[e.name,e.required&&(0,G.jsx)(`span`,{className:`text-red-700 dark:text-red-400 ml-1`,children:`*`})]}),(0,G.jsx)(`input`,{type:`text`,value:s[e.name]||``,onChange:t=>c(n=>({...n,[e.name]:t.target.value})),placeholder:e.description||e.schema?.type||`value`,className:`flex-1 px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm font-mono focus:border-bambu-green focus:outline-none`})]},e.name))})]}),S.length>0&&(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`h4`,{className:`text-sm font-medium text-white`,children:`Query Parameters`}),(0,G.jsx)(`div`,{className:`space-y-2`,children:S.map(e=>(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`label`,{className:`text-sm text-bambu-gray w-32 flex-shrink-0`,children:[e.name,e.required&&(0,G.jsx)(`span`,{className:`text-red-700 dark:text-red-400 ml-1`,children:`*`})]}),e.schema?.enum?(0,G.jsxs)(`select`,{value:s[e.name]||``,onChange:t=>c(n=>({...n,[e.name]:t.target.value})),className:`flex-1 px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`,children:[(0,G.jsx)(`option`,{value:``,children:`-- Select --`}),e.schema.enum.map(e=>(0,G.jsx)(`option`,{value:e,children:e},e))]}):(0,G.jsx)(`input`,{type:`text`,value:s[e.name]||``,onChange:t=>c(n=>({...n,[e.name]:t.target.value})),placeholder:e.description||e.schema?.type||`value`,className:`flex-1 px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm font-mono focus:border-bambu-green focus:outline-none`})]},e.name))})]}),C&&(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`h4`,{className:`text-sm font-medium text-white`,children:`Request Body`}),(0,G.jsx)(`textarea`,{value:l,onChange:e=>u(e.target.value),rows:8,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm font-mono focus:border-bambu-green focus:outline-none resize-y`,placeholder:`JSON request body...`})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(Q,{onClick:v,disabled:p,children:[p?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Al,{className:`w-4 h-4`}),`Execute`]}),_.length>0&&(0,G.jsxs)(`span`,{className:`text-xs text-yellow-700 dark:text-yellow-400 flex items-center gap-1`,children:[(0,G.jsx)(_s,{className:`w-3 h-3`}),`Fill in: `,_.join(`, `)]})]}),d&&(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`h4`,{className:`text-sm font-medium text-white flex items-center gap-2`,children:[`Response`,(0,G.jsxs)(`span`,{className:`px-2 py-0.5 text-xs rounded ${d.status>=200&&d.status<300?`bg-green-100 dark:bg-green-500/20 text-green-700 dark:text-green-400`:d.status>=400?`bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400`:`bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400`}`,children:[d.status,` `,d.statusText]}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[d.duration,`ms`]})]}),(0,G.jsx)(Q,{variant:`secondary`,size:`sm`,onClick:b,children:h?(0,G.jsx)(ys,{className:`w-3 h-3 text-green-600 dark:text-green-400`}):(0,G.jsx)(zs,{className:`w-3 h-3`})})]}),(0,G.jsx)(`pre`,{className:`p-3 bg-bambu-dark rounded-lg text-sm font-mono text-white overflow-auto max-h-96 border border-bambu-dark-tertiary`,children:typeof d.body==`string`?d.body:JSON.stringify(d.body,null,2)})]})]})]})}function KHe({apiKey:e=``}){let[t,n]=(0,y.useState)(null),[r,i]=(0,y.useState)(!0),[a,o]=(0,y.useState)(null),[s,c]=(0,y.useState)(new Set),[l,u]=(0,y.useState)(``);if((0,y.useEffect)(()=>{async function e(){try{let e=await fetch(`/openapi.json`);if(!e.ok)throw Error(`Failed to fetch OpenAPI schema`);n(await e.json())}catch(e){o(e instanceof Error?e.message:`Unknown error`)}finally{i(!1)}}e()},[]),r)return(0,G.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,G.jsx)(Y,{className:`w-8 h-8 text-bambu-green animate-spin`})});if(a||!t)return(0,G.jsx)(Md,{children:(0,G.jsx)(Pd,{className:`py-8`,children:(0,G.jsxs)(`div`,{className:`text-center text-red-700 dark:text-red-400`,children:[(0,G.jsx)(_s,{className:`w-12 h-12 mx-auto mb-3 opacity-50`}),(0,G.jsx)(`p`,{children:`Failed to load API schema`}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:a})]})})});let d={};for(let[e,n]of Object.entries(t.paths))for(let[t,r]of Object.entries(n)){if(t===`parameters`)continue;let n=r.tags||[`Other`];for(let i of n)d[i]||(d[i]=[]),d[i].push({path:e,method:t,spec:r})}let f=Object.entries(d).map(([e,t])=>l?{tag:e,endpoints:t.filter(({path:e,method:t,spec:n})=>{let r=l.toLowerCase();return e.toLowerCase().includes(r)||t.toLowerCase().includes(r)||(n.summary?.toLowerCase()||``).includes(r)||(n.description?.toLowerCase()||``).includes(r)})}:{tag:e,endpoints:t}).filter(({endpoints:e})=>e.length>0).sort((e,t)=>e.tag.localeCompare(t.tag)),p=e=>{c(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})};return(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,G.jsx)(`div`,{className:`flex-1`,children:(0,G.jsx)(`input`,{type:`text`,value:l,onChange:e=>u(e.target.value),placeholder:`Search endpoints...`,className:`w-full max-w-md px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Q,{variant:`secondary`,size:`sm`,onClick:()=>{c(new Set(f.map(e=>e.tag)))},children:`Expand All`}),(0,G.jsx)(Q,{variant:`secondary`,size:`sm`,onClick:()=>{c(new Set)},children:`Collapse All`}),(0,G.jsxs)(`a`,{href:`/docs`,target:`_blank`,rel:`noopener noreferrer`,className:`flex items-center gap-1 text-sm text-bambu-green hover:underline`,children:[(0,G.jsx)(tc,{className:`w-4 h-4`}),`Swagger UI`]})]})]}),(0,G.jsxs)(`p`,{className:`text-sm text-bambu-gray`,children:[f.reduce((e,t)=>e+t.endpoints.length,0),` endpoints in `,f.length,` categories`]}),(0,G.jsx)(`div`,{className:`space-y-3`,children:f.map(({tag:n,endpoints:r})=>(0,G.jsxs)(Md,{children:[(0,G.jsx)(`button`,{onClick:()=>p(n),className:`w-full flex items-center justify-between p-4 hover:bg-bambu-dark-tertiary/30 transition-colors text-left`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[s.has(n)?(0,G.jsx)(ds,{className:`w-5 h-5 text-bambu-gray`}):(0,G.jsx)(fs,{className:`w-5 h-5 text-bambu-gray`}),(0,G.jsx)(`h3`,{className:`text-base font-semibold text-white capitalize`,children:n.replace(/-/g,` `)}),(0,G.jsx)(`span`,{className:`text-xs bg-bambu-dark-tertiary px-2 py-0.5 rounded-full text-bambu-gray`,children:r.length})]})}),s.has(n)&&(0,G.jsx)(Pd,{className:`pt-0 space-y-2`,children:r.map(({path:n,method:r,spec:i})=>(0,G.jsx)(GHe,{path:n,method:r,spec:i,schema:t,apiKey:e},`${r}-${n}`))})]},n))})]})}var qHe=[{id:`sidecar`,labelKey:`settings.sliceEngineSidecar`,descriptionKey:`settings.sliceEngineSidecarHint`,available:!0},{id:`browser`,labelKey:`settings.sliceEngineBrowser`,descriptionKey:`settings.sliceEngineBrowserHint`,available:!1}];function I6(){return qHe.filter(e=>e.available)}function JHe(){return I6().length>1}function L6(e){return I6().find(t=>t.id===e)?.id??`sidecar`}var YHe=[`general`,`plugs`,`notifications`,`queue`,`filament`,`network`,`apikeys`,`virtual-printer`,`spoolbuddy`,`failure-detection`,`users`,`backup`];P6({labelKey:`settings.general`,tab:`general`,keywords:`language date time format printer model printers cards`,anchor:`card-general`}),P6({labelKey:`settings.appearance`,tab:`general`,keywords:`theme dark light mode colors`,anchor:`card-appearance`}),P6({labelKey:`settings.archiveSettings`,tab:`general`,keywords:`archive auto save thumbnails captures`,anchor:`card-archive`}),P6({labelKey:`settings.camera`,tab:`general`,keywords:`camera external video stream`,anchor:`card-camera`}),P6({labelKey:`settings.costTracking`,tab:`general`,keywords:`currency filament cost energy kwh price`,anchor:`card-cost`}),P6({labelKey:`settings.fileManager`,tab:`general`,keywords:`file manager archive mode disk warning storage`,anchor:`card-filemanager`}),P6({labelKey:`settings.updates`,tab:`general`,keywords:`updates version firmware beta check`,anchor:`card-updates`}),P6({labelKey:`settings.dataManagement`,tab:`general`,keywords:`data reset clear logs notifications preferences`,anchor:`card-data`}),P6({labelKey:`settings.smartPlugs`,tab:`plugs`,keywords:`smart plug energy power automation tapo kasa tplink shelly`,anchor:`card-plugs`}),P6({labelKey:`settings.providers`,tab:`notifications`,keywords:`telegram discord email notification providers webhook`,anchor:`card-providers`}),P6({labelKey:`settings.messageTemplates`,tab:`notifications`,keywords:`message templates notification text edit`,anchor:`card-templates`}),P6({labelKey:`settings.defaultPrintOptions`,labelFallback:`Default Print Options`,tab:`queue`,keywords:`print bed leveling flow calibration vibration first layer timelapse`,anchor:`card-print-options`}),P6({labelKey:`settings.tempFanPresetsTitle`,labelFallback:`Temperature & Fan Presets`,tab:`queue`,keywords:`temperature fan presets nozzle bed chamber quick buttons popover`,anchor:`card-temp-fan-presets`}),P6({labelKey:`settings.staggeredStart`,labelFallback:`Staggered Start`,tab:`queue`,keywords:`staggered batch delay start queue group`,anchor:`card-staggered`}),P6({labelKey:`settings.plateClear`,labelFallback:`Plate-Clear Confirmation`,tab:`queue`,keywords:`plate clear confirm auto queue`,anchor:`card-plate`}),P6({labelKey:`settings.concurrentUploadsTitle`,labelFallback:`Concurrent Uploads`,tab:`queue`,keywords:`concurrent parallel upload transfer ftp queue slow farm simultaneous`,anchor:`card-concurrent-uploads`}),P6({labelKey:`settings.gcodeInjection`,labelFallback:`G-code Injection`,tab:`queue`,keywords:`gcode injection start end autoprint farmloop swapmod autoclear printflow`,anchor:`card-gcode`}),P6({labelKey:`settings.slicerCard`,labelFallback:`Slicer`,tab:`queue`,keywords:`slicer orcaslicer bambustudio orca bambu api sidecar url docker preferred`,anchor:`card-slicer`}),P6({labelKey:`settings.queueDrying`,tab:`queue`,keywords:`drying presets temperature time humidity ams`,anchor:`card-drying`}),P6({labelKey:`settings.filamentChecks`,tab:`filament`,keywords:`filament check warning runout remaining`,anchor:`card-filamentchecks`}),P6({labelKey:`settings.printModal`,tab:`filament`,keywords:`print modal custom mapping`,anchor:`card-printmodal`}),P6({labelKey:`settings.amsDisplayThresholds`,tab:`filament`,keywords:`ams humidity temperature threshold history retention`,anchor:`card-amsthresholds`}),P6({labelKey:`settings.externalUrl`,tab:`network`,keywords:`external url reverse proxy public notification link`,anchor:`card-externalurl`}),P6({labelKey:`settings.ftpRetry`,tab:`network`,keywords:`ftp retry upload retries backoff`,anchor:`card-ftpretry`}),P6({labelKey:`settings.homeAssistant`,tab:`network`,keywords:`home assistant ha hass mqtt integration`,anchor:`card-ha`}),P6({labelKey:`settings.mqttPublishing`,tab:`network`,keywords:`mqtt publish broker topic`,anchor:`card-mqtt`}),P6({labelKey:`settings.prometheusMetrics`,tab:`network`,keywords:`prometheus metrics grafana monitoring bearer token`,anchor:`card-prometheus`}),P6({labelKey:`settings.createNewApiKey`,tab:`apikeys`,keywords:`api key create permission scope`,anchor:`card-createapi`}),P6({labelKey:`settings.webhookEndpoints`,tab:`apikeys`,keywords:`webhook endpoint post http`,anchor:`card-webhooks`}),P6({labelKey:`settings.apiBrowser`,tab:`apikeys`,keywords:`api browser endpoint documentation test`,anchor:`card-apibrowser`}),P6({labelKey:`cameraTokens.title`,tab:`apikeys`,keywords:`camera token long-lived home assistant frigate kiosk stream`,anchor:`card-camera-tokens`}),P6({labelKey:`settings.tabs.virtualPrinter`,tab:`virtual-printer`,keywords:`virtual printer proxy archive slicer bambustudio orcaslicer ip bind`,anchor:`card-vp`}),P6({labelKey:`settings.tabs.spoolbuddy`,tab:`spoolbuddy`,keywords:`spoolbuddy device scale nfc rfid kiosk unregister`,anchor:`card-spoolbuddy`}),P6({labelKey:`settings.currentUser`,tab:`users`,subTab:`users`,keywords:`current user profile password change`,anchor:`card-currentuser`}),P6({labelKey:`settings.users`,tab:`users`,subTab:`users`,keywords:`users accounts list`,anchor:`card-users`}),P6({labelKey:`settings.groups`,tab:`users`,subTab:`users`,keywords:`groups roles permissions administrators operators viewers`,anchor:`card-groups`}),P6({labelKey:`settings.sessionPolicy.title`,labelFallback:`Session Policy`,tab:`users`,subTab:`users`,keywords:`session timeout expiry logout remember me jwt token lifetime`,anchor:`card-session-policy`}),P6({labelKey:`settings.email.smtpSettings`,labelFallback:`SMTP Configuration`,tab:`users`,subTab:`email`,keywords:`smtp email send server port password auth starttls ssl`,anchor:`card-smtp`}),P6({labelKey:`settings.ldap.title`,labelFallback:`LDAP Authentication`,tab:`users`,subTab:`ldap`,keywords:`ldap active directory ad authentication bind dn search base group mapping`,anchor:`card-ldap`}),P6({labelKey:`settings.tabs.backup`,tab:`backup`,keywords:`backup github restore download cloud sync profiles archives`,anchor:`card-backup`}),P6({labelKey:`externalLinks.sidebarLayout`,labelFallback:`Sidebar`,tab:`general`,keywords:`sidebar layout links pages hide show external custom navigation url add`,anchor:`card-sidebar-links`}),P6({labelKey:`settings.filamentTracking`,tab:`filament`,keywords:`spoolman filament tracking inventory sync remote integration`,anchor:`card-spoolman`}),P6({labelKey:`settings.catalog.spoolCatalog`,labelFallback:`Spool Catalog`,tab:`filament`,keywords:`spool catalog entries brand material reset import export`,anchor:`card-spool-catalog`}),P6({labelKey:`settings.colorCatalog.title`,labelFallback:`Color Catalog`,tab:`filament`,keywords:`color catalog hex swatch palette sync reset`,anchor:`card-color-catalog`}),P6({labelKey:`settings.tabs.failureDetection`,labelFallback:`Failure Detection`,tab:`failure-detection`,keywords:`failure detection ai ml obico spaghetti detect monitoring`,anchor:`card-fd-ml`}),P6({labelKey:`failureDetection.perPrinterTitle`,labelFallback:`Per-Printer Settings`,tab:`failure-detection`,keywords:`failure detection per printer enable per-printer sensitivity`,anchor:`card-fd-perprinter`}),P6({labelKey:`failureDetection.statusTitle`,labelFallback:`Detection Status`,tab:`failure-detection`,keywords:`failure detection status running connection`,anchor:`card-fd-status`}),P6({labelKey:`failureDetection.historyTitle`,labelFallback:`Detection History`,tab:`failure-detection`,keywords:`failure detection history log events`,anchor:`card-fd-history`}),P6({labelKey:`settings.email.advancedAuth`,labelFallback:`Advanced Email Authentication`,tab:`users`,subTab:`email`,keywords:`email authentication advanced password reset self-service forgot`,anchor:`card-email-advanced-auth`}),P6({labelKey:`settings.email.testConnection`,labelFallback:`Test SMTP Connection`,tab:`users`,subTab:`email`,keywords:`email smtp test connection send check`,anchor:`card-email-test`}),P6({labelKey:`settings.twoFa.totpTitle`,labelFallback:`Authenticator App (TOTP)`,tab:`users`,subTab:`twofa`,keywords:`two factor 2fa totp authenticator app google authy otp`,anchor:`card-2fa-totp`}),P6({labelKey:`settings.twoFa.emailOtpTitle`,labelFallback:`Email One-Time Codes`,tab:`users`,subTab:`twofa`,keywords:`two factor 2fa email otp one time code`,anchor:`card-2fa-emailotp`}),P6({labelKey:`settings.twoFa.linkedAccounts`,labelFallback:`Linked Accounts`,tab:`users`,subTab:`twofa`,keywords:`two factor 2fa linked accounts sso oidc provider google github`,anchor:`card-2fa-linked`}),P6({labelKey:`settings.oidc.title`,labelFallback:`Single Sign-On (OIDC)`,tab:`users`,subTab:`oidc`,keywords:`sso oidc openid single sign-on pocketid authentik keycloak google okta azure provider`,anchor:`card-oidc`}),P6({labelKey:`settings.ldap.serverConfig`,labelFallback:`LDAP Server Configuration`,tab:`users`,subTab:`ldap`,keywords:`ldap server url bind dn user search base group filter tls`,anchor:`card-ldap-server`}),P6({labelKey:`backup.githubBackup`,labelFallback:`GitHub Backup`,tab:`backup`,keywords:`github backup cloud remote sync profiles token`,anchor:`card-backup-github`}),P6({labelKey:`backup.history`,labelFallback:`Backup History`,tab:`backup`,keywords:`backup history log runs github commits`,anchor:`card-backup-history`}),P6({labelKey:`backup.localBackup`,labelFallback:`Local Backup`,tab:`backup`,keywords:`local backup download zip manual export`,anchor:`card-backup-local`}),P6({labelKey:`backup.scheduledBackup`,labelFallback:`Scheduled Backups`,tab:`backup`,keywords:`scheduled backup automatic hourly daily weekly retention local path`,anchor:`card-backup-scheduled`});var R6=20,XHe={database:`bg-blue-600`,library_files:`bg-green-500`,library_thumbnails:`bg-teal-500`,library_other:`bg-emerald-700`,archive_timelapses:`bg-red-500`,archive_thumbnails:`bg-amber-500`,archive_files:`bg-sky-500`,virtual_printer_uploads:`bg-purple-500`,virtual_printer_upload_cache:`bg-fuchsia-500`,virtual_printer_certs:`bg-violet-500`,virtual_printer_other:`bg-purple-700`,downloads:`bg-cyan-500`,plate_calibration:`bg-lime-500`,logs:`bg-orange-500`,other_data:`bg-yellow-500`},z6=[`bg-blue-500`,`bg-green-500`,`bg-yellow-500`,`bg-red-500`,`bg-orange-500`,`bg-teal-500`,`bg-cyan-500`,`bg-purple-500`],B6=(e,t)=>XHe[e]||z6[t%z6.length];function ZHe(){let e=so(),t=or(),[n,r]=Li(),{t:i,i18n:a}=U(),{showToast:o}=Bd(),{authEnabled:s,user:c,isAdmin:l,refreshAuth:u,hasPermission:d}=Ed(),{mode:f,resolvedMode:p,darkStyle:m,darkBackground:h,darkAccent:g,lightStyle:_,lightBackground:v,lightAccent:b,setMode:x,setDarkStyle:S,setDarkBackground:C,setDarkAccent:w,setLightStyle:T,setLightBackground:E,setLightAccent:D,progressInTitle:O,setProgressInTitle:k}=kd(),[A,j]=(0,y.useState)(null),[M,N]=(0,y.useState)({}),[P,F]=(0,y.useState)(!1),[I,L]=(0,y.useState)(null),[R,z]=(0,y.useState)(!1),[B,V]=(0,y.useState)(null),[ee,te]=(0,y.useState)(!1),[ne,re]=(0,y.useState)(null),[ie,ae]=(0,y.useState)(null),[oe,se]=(0,y.useState)(``),[H,ce]=(0,y.useState)(``),[le,ue]=(0,y.useState)(!1),[de,fe]=(0,y.useState)(!1),[pe,me]=(0,y.useState)(!1),[he,ge]=(0,y.useState)(em()),_e=n.get(`tab`),ve=_e===`email`,[ye,be]=(0,y.useState)(ve?`users`:_e&&YHe.includes(_e)?_e:`general`),[xe,Se]=(0,y.useState)(ve?`email`:`users`),[Ce,we]=(0,y.useState)(_e===`queue`&&n.get(`sub`)===`pipelines`?`pipelines`:`dispatch`),Te=e=>{be(e),e===`users`&&Se(`users`),e===`queue`&&(we(`dispatch`),n.delete(`sub`)),e===`general`?n.delete(`tab`):n.set(`tab`,e),r(n,{replace:!0})},Ee=e=>{we(e),e===`pipelines`?n.set(`sub`,`pipelines`):n.delete(`sub`),r(n,{replace:!0})},[De,Oe]=(0,y.useState)(!1),[ke,Ae]=(0,y.useState)(``),[je,Me]=(0,y.useState)({can_queue:!0,can_control_printer:!1,can_read_status:!0,can_manage_library:!0,can_manage_inventory:!0,can_manage_maintenance:!0,can_manage_archives:!0,can_manage_projects:!0,can_access_cloud:!1,can_update_energy_cost:!1}),[Ne,Pe]=(0,y.useState)(null),[Fe,Ie]=(0,y.useState)(!1),[Le,Re]=(0,y.useState)(null),[ze,Be]=(0,y.useState)(``),[Ve,He]=(0,y.useState)(!1),[Ue,We]=(0,y.useState)(!1),[Ge,Ke]=(0,y.useState)(null),[qe,Je]=(0,y.useState)(!1),[Ye,Xe]=(0,y.useState)(!1),[Ze,Qe]=(0,y.useState)(!1),[$e,et]=(0,y.useState)({currentPassword:``,newPassword:``,confirmPassword:``}),[tt,nt]=(0,y.useState)(!1),[rt,it]=(0,y.useState)(!1),[at,ot]=(0,y.useState)(!1),[st,ct]=(0,y.useState)(`local`),[lt,ut]=(0,y.useState)(!1),[dt,ft]=(0,y.useState)(null),[pt,mt]=(0,y.useState)(null),[ht,gt]=(0,y.useState)(null),[_t,vt]=(0,y.useState)(!1),[yt,bt]=(0,y.useState)({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]}),[xt,St]=(0,y.useState)(null),[Ct,wt]=(0,y.useState)(null),[Tt,Et]=(0,y.useState)(!1),[Dt,Ot]=(0,y.useState)({}),[At,jt]=(0,y.useState)({}),Mt=e=>{ge(e),see(e),o(i(`settings.toast.settingsSaved`),`success`)},{data:Nt,isLoading:Pt}=K({queryKey:[`settings`],queryFn:Z.getSettings}),{data:Ft,isLoading:It,isFetching:Lt}=K({queryKey:[`storage-usage`],queryFn:()=>Z.getStorageUsage(),enabled:ye===`general`,staleTime:1/0,refetchInterval:!1,refetchOnWindowFocus:!1,refetchOnReconnect:!1}),Rt=async()=>{it(!0);try{let t=await Z.getStorageUsage({refresh:!0});e.setQueryData([`storage-usage`],t)}catch(e){o(e instanceof Error?e.message:`Failed to refresh storage usage`,`error`)}finally{it(!1)}},{data:zt,isLoading:Bt}=K({queryKey:[`smart-plugs`],queryFn:Z.getSmartPlugs}),{data:Vt,isLoading:W}=K({queryKey:[`smart-plugs-energy`,zt?.map(e=>e.id)],queryFn:async()=>{if(!zt||zt.length===0)return null;let e=await Promise.all(zt.filter(e=>e.enabled).map(async e=>{try{return{plug:e,status:await Z.getSmartPlugStatus(e.id)}}catch{return{plug:e,status:null}}})),t=0,n=0,r=0,i=0,a=0;for(let{plug:o,status:s}of e){let e=o.plug_type===`mqtt`&&s?.energy?.power!=null;(s?.reachable||e)&&s?.energy&&(a++,s.energy?.power!=null&&(t+=s.energy.power),s.energy?.today!=null&&(n+=s.energy.today),s.energy?.yesterday!=null&&(r+=s.energy.yesterday),s.energy?.total!=null&&(i+=s.energy.total))}return{totalPower:t,totalToday:n,totalYesterday:r,totalLifetime:i,reachableCount:a,totalPlugs:zt.filter(e=>e.enabled).length}},enabled:ye===`plugs`&&!!zt&&zt.length>0,refetchInterval:ye===`plugs`?1e4:!1}),{data:Ht,isLoading:Ut}=K({queryKey:[`notification-providers`],queryFn:Z.getNotificationProviders}),{data:Wt,isLoading:Gt}=K({queryKey:[`api-keys`],queryFn:Z.getAPIKeys}),Kt=q({mutationFn:e=>Z.createAPIKey(e),onSuccess:t=>{Pe(t.key||null),Oe(!1),Ae(``),e.invalidateQueries({queryKey:[`api-keys`]}),o(i(`settings.toast.apiKeyCreated`))},onError:e=>{o(`Failed to create API key: ${e.message}`,`error`)}}),qt=q({mutationFn:e=>Z.deleteAPIKey(e),onSuccess:(t,n)=>{e.setQueryData([`api-keys`],e=>(e??[]).filter(e=>e.id!==n)),o(i(`settings.toast.apiKeyDeleted`))},onError:e=>{o(`Failed to delete API key: ${e.message}`,`error`)}}),{data:Jt}=K({queryKey:[`printers`],queryFn:Z.getPrinters}),{data:Yt}=K({queryKey:[`haSensors`],queryFn:()=>Z.getHASensors(),enabled:ye===`plugs`}),Xt=Of(Jt?.length??0),{data:Zt,isLoading:Qt}=K({queryKey:[`notification-templates`],queryFn:Z.getNotificationTemplates}),{data:$t}=K({queryKey:[`virtual-printer-settings`],queryFn:gd.getSettings,refetchInterval:1e4}),en=$t?.status?.running??!1,{data:tn}=K({queryKey:[`spoolbuddy-devices`],queryFn:()=>xd.getDevices(),refetchInterval:15e3}),nn=tn?.length??0,rn=tn?.some(e=>e.online)??!1,{data:an}=K({queryKey:[`obico-status`],queryFn:Z.getObicoStatus,refetchInterval:15e3}),on=!!(an?.is_running&&an?.enabled),{data:sn}=K({queryKey:[`ffmpeg-status`],queryFn:Z.checkFfmpeg}),{data:cn}=K({queryKey:[`version`],queryFn:Z.getVersion}),ln=!s||d(`library:purge`),{data:un}=K({queryKey:[`library-trash-settings`],queryFn:()=>Z.getLibraryTrashSettings(),enabled:ln}),dn=q({mutationFn:e=>Z.updateLibraryTrashSettings(e),onSuccess:()=>{e.invalidateQueries({queryKey:[`library-trash-settings`]}),o(i(`settings.toast.settingsSaved`),`success`)},onError:e=>o(e.message||i(`libraryAutoPurge.saveFailed`),`error`)}),fn=e=>{un&&dn.mutate({retention_days:un.retention_days,auto_purge_enabled:un.auto_purge_enabled,auto_purge_days:un.auto_purge_days,auto_purge_include_never_printed:un.auto_purge_include_never_printed,...e})},pn=!s||d(`archives:purge`),{data:mn}=K({queryKey:[`archive-purge-settings`],queryFn:()=>Z.getArchivePurgeSettings(),enabled:pn}),hn=q({mutationFn:e=>Z.updateArchivePurgeSettings(e),onSuccess:()=>{e.invalidateQueries({queryKey:[`archive-purge-settings`]}),o(i(`settings.toast.settingsSaved`),`success`)},onError:e=>o(e.message||i(`archiveAutoPurge.saveFailed`),`error`)}),gn=e=>{mn&&hn.mutate({enabled:mn.enabled,days:mn.days,purge_stats:mn.purge_stats,...e})},{data:_n,refetch:vn,isRefetching:yn}=K({queryKey:[`updateCheck`],queryFn:Z.checkForUpdates,enabled:Nt?.check_updates!==!1,staleTime:300*1e3}),{data:bn,refetch:xn}=K({queryKey:[`updateStatus`],queryFn:Z.getUpdateStatus,refetchInterval:e=>{let t=e.state.data;return t?.status===`downloading`||t?.status===`installing`?1e3:!1}}),{data:Sn}=K({queryKey:[`mqtt-status`],queryFn:Z.getMQTTStatus,refetchInterval:ye===`network`?5e3:!1}),{data:Cn}=K({queryKey:[`github-backup-status`],queryFn:Z.getGitHubBackupStatus}),{data:wn}=K({queryKey:[`cloud-status`],queryFn:Z.getCloudStatus}),{data:Tn={advanced_auth_enabled:!1,smtp_configured:!1,local_login_enabled:!0,autologin_provider_id:null}}=K({queryKey:[`advancedAuthStatus`],queryFn:()=>Z.getAdvancedAuthStatus()}),{data:En}=K({queryKey:[`ldapStatus`],queryFn:()=>Z.getLDAPStatus()}),{data:Dn}=K({queryKey:[`twoFAStatus`],queryFn:()=>Z.get2FAStatus()}),{data:On=[]}=K({queryKey:[`oidcProvidersAll`],queryFn:()=>Z.getOIDCProvidersAll(),enabled:l}),{data:kn=[],isLoading:An}=K({queryKey:[`users`],queryFn:()=>Z.getUsers(),enabled:s&&d(`users:read`)}),{data:jn=[],isLoading:Mn}=K({queryKey:[`groups`],queryFn:()=>Z.getGroups(),enabled:s&&d(`groups:read`)}),Nn=q({mutationFn:e=>Z.createUser(e),onSuccess:()=>{e.invalidateQueries({queryKey:[`users`]}),e.invalidateQueries({queryKey:[`groups`]}),ot(!1),bt({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]}),o(i(`settings.toast.userCreated`))},onError:e=>{o(e.message,`error`)}}),Pn=q({mutationFn:({id:e,data:t})=>Z.updateUser(e,t),onSuccess:()=>{e.invalidateQueries({queryKey:[`users`]}),e.invalidateQueries({queryKey:[`groups`]}),ut(!1),ft(null),bt({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]}),o(i(`settings.toast.userUpdated`))},onError:e=>{o(e.message,`error`)}}),Fn=q({mutationFn:({id:e,deleteItems:t})=>Z.deleteUser(e,t),onSuccess:()=>{e.invalidateQueries({queryKey:[`users`]}),o(i(`settings.toast.userDeleted`)),mt(null),gt(null)},onError:e=>{o(e.message,`error`)}}),In=q({mutationFn:e=>Z.resetUserPassword({user_id:e}),onSuccess:e=>{o(e.message,`success`)},onError:e=>{o(e.message,`error`)}}),Ln=async e=>{mt(e),vt(!0);try{gt(await Z.getUserItemsCount(e))}catch{gt({archives:0,queue_items:0,library_files:0})}finally{vt(!1)}},Rn=q({mutationFn:e=>Z.deleteGroup(e),onSuccess:()=>{e.invalidateQueries({queryKey:[`groups`]}),o(i(`settings.toast.groupDeleted`))},onError:e=>{o(e.message,`error`)}}),zn=()=>{let e=Tn?.advanced_auth_enabled||!1;if(!yt.username){o(i(`settings.toast.fillRequiredFields`),`error`);return}if(e&&!yt.email){o(`Email is required when advanced authentication is enabled`,`error`);return}if(!e){if(!yt.password){o(i(`settings.toast.fillRequiredFields`),`error`);return}if(yt.password!==yt.confirmPassword){o(i(`settings.toast.passwordsDoNotMatch`),`error`);return}let e=N3(yt.password);if(e){o(i({tooShort:`settings.toast.passwordTooShort`,needsUppercase:`settings.toast.passwordNeedsUppercase`,needsLowercase:`settings.toast.passwordNeedsLowercase`,needsDigit:`settings.toast.passwordNeedsDigit`,needsSpecial:`settings.toast.passwordNeedsSpecial`}[e]),`error`);return}}Nn.mutate({username:yt.username,password:e?void 0:yt.password,email:yt.email||void 0,role:yt.role,group_ids:yt.group_ids.length>0?yt.group_ids:void 0})},Bn=e=>{if(yt.password){if(yt.password!==yt.confirmPassword){o(i(`settings.toast.passwordsDoNotMatch`),`error`);return}let e=N3(yt.password);if(e){o(i({tooShort:`settings.toast.passwordTooShort`,needsUppercase:`settings.toast.passwordNeedsUppercase`,needsLowercase:`settings.toast.passwordNeedsLowercase`,needsDigit:`settings.toast.passwordNeedsDigit`,needsSpecial:`settings.toast.passwordNeedsSpecial`}[e]),`error`);return}}let t={username:yt.username||void 0,password:yt.password||void 0,email:yt.email||void 0,role:yt.role,group_ids:yt.group_ids};t.password||delete t.password,Pn.mutate({id:e,data:t})},Vn=e=>{ft(e.id),bt({username:e.username,password:``,email:e.email||``,confirmPassword:``,role:e.role,group_ids:e.groups?.map(e=>e.id)||[]}),ut(!0)},Hn=e=>{bt(t=>({...t,group_ids:t.group_ids.includes(e)?t.group_ids.filter(t=>t!==e):[...t.group_ids,e]}))},Un=q({mutationFn:Z.applyUpdate,onSuccess:e=>{e.is_ha_addon||e.is_docker||e.is_windows_installer?o(e.message,`error`):xn()}}),[Wn,Gn]=(0,y.useState)(null),Kn=q({mutationFn:Z.testAllNotificationProviders,onSuccess:t=>{Gn(t),e.invalidateQueries({queryKey:[`notification-providers`]}),t.failed===0?o(`All ${t.tested} providers tested successfully!`,`success`):o(`${t.success}/${t.tested} providers succeeded`,t.failed>0?`error`:`success`)},onError:e=>{o(`Failed to test providers: ${e.message}`,`error`)}}),qn=q({mutationFn:async e=>{if(!zt)return{success:0,failed:0};let t=zt.filter(e=>e.enabled),n=await Promise.all(t.map(async t=>{try{return await Z.controlSmartPlug(t.id,e),{success:!0}}catch{return{success:!1}}}));return{success:n.filter(e=>e.success).length,failed:n.filter(e=>!e.success).length}},onSuccess:(t,n)=>{e.invalidateQueries({queryKey:[`smart-plugs`]}),e.invalidateQueries({queryKey:[`smart-plugs-energy`]}),t.failed===0?o(`All ${t.success} plugs turned ${n}`,`success`):o(`${t.success} plugs turned ${n}, ${t.failed} failed`,`error`)},onError:e=>{o(`Failed: ${e.message}`,`error`)}}),Jn=(0,y.useRef)(null),Yn=(0,y.useRef)(null),Xn=(0,y.useRef)(!1),Zn=(0,y.useRef)(!0),Qn=(0,y.useRef)(null);(0,y.useEffect)(()=>{if(Nt&&!A){let e={...Nt,external_url:Nt.external_url||window.location.origin};Qn.current=Nt,j(e),setTimeout(()=>{Zn.current=!1},100)}},[Nt,A]),(0,y.useEffect)(()=>{let e=Qn.current;if(!Nt||!A||!e||Nt===e)return;let t={};for(let n of Object.keys(Nt))Nt[n]!==e[n]&&A[n]===e[n]&&(t[n]=Nt[n]);Qn.current=Nt,Object.keys(t).length>0&&j(e=>e&&{...e,...t})},[Nt,A]);let $n=q({mutationFn:Z.updateSettings,onSuccess:t=>{Qn.current=t,e.setQueryData([`settings`],t),e.invalidateQueries({queryKey:[`archiveStats`]}),o(i(`settings.toast.settingsSaved`),`success`)},onError:e=>{o(`Failed to save: ${e.message}`,`error`)},onSettled:()=>{Xn.current=!1}}),er=q({mutationFn:({id:e,data:t})=>Z.updatePrinter(e,t),onSuccess:()=>{e.invalidateQueries({queryKey:[`printers`]}),o(i(`settings.toast.cameraSettingsSaved`),`success`)},onError:e=>{o(`Failed to update printer: ${e.message}`,`error`)}});(0,y.useEffect)(()=>{let e=Qn.current;if(!(Zn.current||!A||!Nt||!e)&&!(s&&!d(`settings:update`))&&(e.auto_archive!==A.auto_archive||e.save_thumbnails!==A.save_thumbnails||e.capture_finish_photo!==A.capture_finish_photo||(e.finish_photo_restore_plate??!0)!==(A.finish_photo_restore_plate??!0)||e.default_filament_cost!==A.default_filament_cost||e.currency!==A.currency||e.energy_cost_per_kwh!==A.energy_cost_per_kwh||e.energy_tracking_mode!==A.energy_tracking_mode||e.check_updates!==A.check_updates||(e.check_printer_firmware??!0)!==(A.check_printer_firmware??!0)||(e.include_beta_updates??!1)!==(A.include_beta_updates??!1)||(e.local_login_enabled??!0)!==(A.local_login_enabled??!0)||e.notification_language!==A.notification_language||(e.bed_cooled_threshold??35)!==(A.bed_cooled_threshold??35)||e.ams_humidity_good!==A.ams_humidity_good||e.ams_humidity_fair!==A.ams_humidity_fair||e.ams_temp_good!==A.ams_temp_good||e.ams_temp_fair!==A.ams_temp_fair||e.ams_history_retention_days!==A.ams_history_retention_days||e.disable_filament_warnings!==A.disable_filament_warnings||e.prefer_lowest_filament!==A.prefer_lowest_filament||(e.queue_drying_enabled??!1)!==(A.queue_drying_enabled??!1)||(e.queue_drying_block??!1)!==(A.queue_drying_block??!1)||(e.ambient_drying_enabled??!1)!==(A.ambient_drying_enabled??!1)||(e.print_drying_enabled??!1)!==(A.print_drying_enabled??!1)||(e.drying_presets??``)!==(A.drying_presets??``)||(e.ams_humidity_thresholds??``)!==(A.ams_humidity_thresholds??``)||e.per_printer_mapping_expanded!==A.per_printer_mapping_expanded||e.date_format!==A.date_format||e.time_format!==A.time_format||e.default_printer_id!==A.default_printer_id||e.ftp_retry_enabled!==A.ftp_retry_enabled||e.ftp_retry_count!==A.ftp_retry_count||e.ftp_retry_delay!==A.ftp_retry_delay||e.ftp_timeout!==A.ftp_timeout||e.mqtt_enabled!==A.mqtt_enabled||e.mqtt_broker!==A.mqtt_broker||e.mqtt_port!==A.mqtt_port||e.mqtt_username!==A.mqtt_username||e.mqtt_password!==A.mqtt_password||e.mqtt_topic_prefix!==A.mqtt_topic_prefix||e.mqtt_use_tls!==A.mqtt_use_tls||e.external_url!==A.external_url||e.ha_enabled!==A.ha_enabled||e.ha_url!==A.ha_url||e.ha_token!==A.ha_token||(e.library_archive_mode??`ask`)!==(A.library_archive_mode??`ask`)||Number(e.library_disk_warning_gb??5)!==Number(A.library_disk_warning_gb??5)||(e.camera_view_mode??`window`)!==(A.camera_view_mode??`window`)||(e.preferred_slicer??`bambu_studio`)!==(A.preferred_slicer??`bambu_studio`)||L6(e.slice_engine)!==L6(A.slice_engine)||(e.open_in_slicer??null)!==(A.open_in_slicer??null)||(e.use_slicer_api??!1)!==(A.use_slicer_api??!1)||(e.orcaslicer_api_url??``)!==(A.orcaslicer_api_url??``)||(e.slicer_stall_timeout_minutes??15)!==(A.slicer_stall_timeout_minutes??15)||(e.bambu_studio_api_url??``)!==(A.bambu_studio_api_url??``)||e.prometheus_enabled!==A.prometheus_enabled||e.prometheus_token!==A.prometheus_token||(e.user_notifications_enabled??!0)!==(A.user_notifications_enabled??!0)||(e.default_bed_levelling??`auto`)!==(A.default_bed_levelling??`auto`)||(e.default_flow_cali??`auto`)!==(A.default_flow_cali??`auto`)||(e.default_vibration_cali??!0)!==(A.default_vibration_cali??!0)||(e.default_layer_inspect??!1)!==(A.default_layer_inspect??!1)||(e.default_timelapse??!1)!==(A.default_timelapse??!1)||(e.default_nozzle_offset_cali??`auto`)!==(A.default_nozzle_offset_cali??`auto`)||(e.stagger_group_size??2)!==(A.stagger_group_size??2)||(e.stagger_interval_minutes??5)!==(A.stagger_interval_minutes??5)||(e.require_plate_clear??!1)!==(A.require_plate_clear??!1)||(e.queue_max_concurrent_uploads??4)!==(A.queue_max_concurrent_uploads??4)||(e.preheat_enabled??!1)!==(A.preheat_enabled??!1)||(e.preheat_filament_targets??``)!==(A.preheat_filament_targets??``)||(e.preheat_max_wait_seconds??900)!==(A.preheat_max_wait_seconds??900)||(e.preheat_soak_seconds??300)!==(A.preheat_soak_seconds??300)||(e.nozzle_temp_presets??``)!==(A.nozzle_temp_presets??``)||(e.bed_temp_presets??``)!==(A.bed_temp_presets??``)||(e.chamber_temp_presets??``)!==(A.chamber_temp_presets??``)||(e.fan_speed_presets??``)!==(A.fan_speed_presets??``)||(e.session_max_hours??24)!==(A.session_max_hours??24)||(e.billing_enabled??!1)!==(A.billing_enabled??!1)||(e.printer_kill_switch_enabled??!1)!==(A.printer_kill_switch_enabled??!1)||(e.finance_budget_reset_day??1)!==(A.finance_budget_reset_day??1)||(e.finance_budget_reset_timezone??`UTC`)!==(A.finance_budget_reset_timezone??`UTC`))&&!Xn.current)return Jn.current&&clearTimeout(Jn.current),Jn.current=setTimeout(()=>{if(Xn.current)return;Xn.current=!0;let e={auto_archive:A.auto_archive,save_thumbnails:A.save_thumbnails,capture_finish_photo:A.capture_finish_photo,finish_photo_restore_plate:A.finish_photo_restore_plate??!0,default_filament_cost:A.default_filament_cost,currency:A.currency,energy_cost_per_kwh:A.energy_cost_per_kwh,energy_tracking_mode:A.energy_tracking_mode,check_updates:A.check_updates,check_printer_firmware:A.check_printer_firmware,include_beta_updates:A.include_beta_updates,local_login_enabled:A.local_login_enabled,notification_language:A.notification_language,bed_cooled_threshold:A.bed_cooled_threshold,ams_humidity_good:A.ams_humidity_good,ams_humidity_fair:A.ams_humidity_fair,ams_temp_good:A.ams_temp_good,ams_temp_fair:A.ams_temp_fair,ams_history_retention_days:A.ams_history_retention_days,disable_filament_warnings:A.disable_filament_warnings,prefer_lowest_filament:A.prefer_lowest_filament,queue_drying_enabled:A.queue_drying_enabled,queue_drying_block:A.queue_drying_block,ambient_drying_enabled:A.ambient_drying_enabled,print_drying_enabled:A.print_drying_enabled,drying_presets:A.drying_presets,ams_humidity_thresholds:A.ams_humidity_thresholds,per_printer_mapping_expanded:A.per_printer_mapping_expanded,date_format:A.date_format,time_format:A.time_format,default_printer_id:A.default_printer_id,ftp_retry_enabled:A.ftp_retry_enabled,ftp_retry_count:A.ftp_retry_count,ftp_retry_delay:A.ftp_retry_delay,ftp_timeout:A.ftp_timeout,mqtt_enabled:A.mqtt_enabled,mqtt_broker:A.mqtt_broker,mqtt_port:A.mqtt_port,mqtt_username:A.mqtt_username,mqtt_password:A.mqtt_password,mqtt_topic_prefix:A.mqtt_topic_prefix,mqtt_use_tls:A.mqtt_use_tls,external_url:A.external_url,ha_enabled:A.ha_enabled,ha_url:A.ha_url,ha_token:A.ha_token,library_archive_mode:A.library_archive_mode,library_disk_warning_gb:A.library_disk_warning_gb,camera_view_mode:A.camera_view_mode,preferred_slicer:A.preferred_slicer,slice_engine:A.slice_engine,open_in_slicer:A.open_in_slicer,use_slicer_api:A.use_slicer_api,orcaslicer_api_url:A.orcaslicer_api_url,slicer_stall_timeout_minutes:A.slicer_stall_timeout_minutes,bambu_studio_api_url:A.bambu_studio_api_url,prometheus_enabled:A.prometheus_enabled,prometheus_token:A.prometheus_token,user_notifications_enabled:A.user_notifications_enabled,default_bed_levelling:A.default_bed_levelling,default_flow_cali:A.default_flow_cali,default_vibration_cali:A.default_vibration_cali,default_layer_inspect:A.default_layer_inspect,default_timelapse:A.default_timelapse,default_nozzle_offset_cali:A.default_nozzle_offset_cali,stagger_group_size:A.stagger_group_size,stagger_interval_minutes:A.stagger_interval_minutes,require_plate_clear:A.require_plate_clear,queue_max_concurrent_uploads:A.queue_max_concurrent_uploads,preheat_enabled:A.preheat_enabled,preheat_filament_targets:A.preheat_filament_targets,preheat_max_wait_seconds:A.preheat_max_wait_seconds,preheat_soak_seconds:A.preheat_soak_seconds,nozzle_temp_presets:A.nozzle_temp_presets,bed_temp_presets:A.bed_temp_presets,chamber_temp_presets:A.chamber_temp_presets,fan_speed_presets:A.fan_speed_presets,session_max_hours:A.session_max_hours,billing_enabled:A.billing_enabled,printer_kill_switch_enabled:A.printer_kill_switch_enabled,finance_budget_reset_day:A.finance_budget_reset_day,finance_budget_reset_timezone:A.finance_budget_reset_timezone};$n.mutate(e)},500),()=>{Jn.current&&clearTimeout(Jn.current)}},[A,Nt,$n,s,d,o,i]);let tr=(0,y.useCallback)((e,t)=>{if(s&&!d(`settings:update`)){o(i(`settings.toast.noPermissionUpdate`),`error`);return}j(n=>n?{...n,[e]:t}:null)},[s,d,o,i]),nr=async(e,t,n)=>{if(!t){o(i(`settings.toast.enterCameraUrl`),`error`);return}jt(t=>({...t,[e]:!0})),Ot(t=>({...t,[e]:null}));try{let r=await Z.testExternalCamera(e,t,n);Ot(t=>({...t,[e]:r})),r.success?o(r.coalesced?i(`settings.toast.cameraConnectedCoalesced`,{resolution:r.resolution||``}):i(`settings.toast.cameraConnected`,{resolution:r.resolution||``}),`success`):o(r.error||i(`settings.toast.connectionFailed`),`error`)}catch(t){let n=t instanceof Error?t.message:i(`settings.toast.testFailed`);Ot(t=>({...t,[e]:{success:!1,error:n}})),o(n,`error`)}finally{jt(t=>({...t,[e]:!1}))}},[rr,ir]=(0,y.useState)({}),ar=(0,y.useRef)({}),sr=(0,y.useRef)(new Set),[cr,lr]=(0,y.useState)({}),ur=(0,y.useRef)({}),dr=(0,y.useRef)(new Set);(0,y.useEffect)(()=>{if(Jt){let e={},t={};Jt.forEach(n=>{n.external_camera_url&&!sr.current.has(n.id)&&(e[n.id]=n.external_camera_url,sr.current.add(n.id)),n.external_camera_snapshot_url&&!dr.current.has(n.id)&&(t[n.id]=n.external_camera_snapshot_url,dr.current.add(n.id))}),Object.keys(e).length>0&&ir(t=>({...t,...e})),Object.keys(t).length>0&&lr(e=>({...e,...t}))}},[Jt]);let fr=(e,t)=>{ir(n=>({...n,[e]:t})),ar.current[e]&&clearTimeout(ar.current[e]),ar.current[e]=setTimeout(()=>{er.mutate({id:e,data:{external_camera_url:t||null}})},800)},pr=(e,t)=>{lr(n=>({...n,[e]:t})),ur.current[e]&&clearTimeout(ur.current[e]),ur.current[e]=setTimeout(()=>{er.mutate({id:e,data:{external_camera_snapshot_url:t||null}})},800)},mr=(e,t)=>{let n={};t.type!==void 0&&(n.external_camera_type=t.type||null),t.enabled!==void 0&&(n.external_camera_enabled=t.enabled),t.rotation!==void 0&&(n.camera_rotation=t.rotation),er.mutate({id:e,data:n})};if(Pt||!A)return(0,G.jsx)(`div`,{className:`p-4 md:p-8 flex justify-center`,children:(0,G.jsx)(Y,{className:`w-8 h-8 text-bambu-green animate-spin`})});let hr=VHe().map(e=>({...e,label:i(e.labelKey,e.labelFallback??e.labelKey)})),gr=H.trim().toLowerCase(),_r=gr?hr.filter(e=>e.label.toLowerCase().includes(gr)||e.keywords.toLowerCase().includes(gr)).slice(0,8):[],vr=e=>{Te(e.tab),e.subTab&&Se(e.subTab),ce(``),setTimeout(()=>{let t=document.getElementById(e.anchor);t&&(t.scrollIntoView({behavior:`smooth`,block:`start`}),t.classList.add(`ring-2`,`ring-bambu-green`),setTimeout(()=>t.classList.remove(`ring-2`,`ring-bambu-green`),1500))},50)},yr=(A?.docker_compose_dir??``).trim()||(_n?.compose_dir_detected??``),br=yr?`cd ${/\s/.test(yr)?`"${yr}"`:yr} && docker compose pull && docker compose up -d`:`docker compose pull && docker compose up -d`;return(0,G.jsx)(jd,{density:`dense`,children:(0,G.jsxs)(`div`,{className:`p-4 md:p-8`,children:[(0,G.jsxs)(`div`,{className:`mb-4 flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,G.jsx)(eu,{className:`w-7 h-7 text-bambu-green`}),i(`settings.title`)]}),(0,G.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:i(`settings.configureBambuddy`)})]}),(0,G.jsxs)(`div`,{className:`relative sm:w-72`,children:[(0,G.jsx)(Yl,{className:`w-4 h-4 text-bambu-gray absolute left-3 top-1/2 -translate-y-1/2 pointer-events-none`}),(0,G.jsx)(`input`,{type:`text`,value:H,onChange:e=>ce(e.target.value),placeholder:i(`settings.searchPlaceholder`,`Search settings…`),className:`w-full pl-9 pr-8 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`}),H&&(0,G.jsx)(`button`,{onClick:()=>ce(``),className:`absolute right-2 top-1/2 -translate-y-1/2 p-1 text-bambu-gray hover:text-white`,"aria-label":`Clear`,children:(0,G.jsx)($u,{className:`w-3.5 h-3.5`})}),_r.length>0&&(0,G.jsx)(`div`,{className:`absolute top-full left-0 right-0 mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl z-30 overflow-hidden`,children:_r.map(e=>(0,G.jsxs)(`button`,{onClick:()=>vr(e),className:`w-full px-3 py-2 text-left hover:bg-bambu-dark-tertiary transition-colors border-b border-bambu-dark-tertiary last:border-b-0`,children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:e.label}),(0,G.jsxs)(`p`,{className:`text-xs text-bambu-gray`,children:[i(`settings.tabs.${e.tab===`virtual-printer`?`virtualPrinter`:e.tab===`failure-detection`?`failureDetection`:e.tab}`),e.subTab?` › ${i(`settings.tabs.${e.subTab}`,e.subTab)}`:``]})]},e.anchor))}),gr&&_r.length===0&&(0,G.jsx)(`div`,{className:`absolute top-full left-0 right-0 mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl z-30 p-3`,children:(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray italic`,children:i(`settings.noSearchResults`,`No matching settings.`)})})]})]}),(0,G.jsxs)(`div`,{className:`flex flex-col lg:flex-row gap-4 lg:gap-6`,children:[(0,G.jsxs)(`nav`,{className:`flex flex-wrap gap-1 border-b border-bambu-dark-tertiary lg:flex-col lg:flex-nowrap lg:gap-0 lg:border-b-0 lg:border-r lg:w-48 lg:flex-shrink-0 lg:self-start lg:sticky lg:top-4`,children:[(0,G.jsxs)(`button`,{onClick:()=>Te(`general`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${ye===`general`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,G.jsx)(eu,{className:`w-4 h-4`}),i(`settings.tabs.general`)]}),(0,G.jsxs)(`button`,{onClick:()=>Te(`plugs`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${ye===`plugs`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,G.jsx)(jl,{className:`w-4 h-4`}),i(`settings.tabs.smartPlugs`),zt&&zt.length>0&&(0,G.jsx)(`span`,{className:`text-xs bg-bambu-dark-tertiary px-1.5 py-0.5 rounded-full`,children:zt.length})]}),(0,G.jsxs)(`button`,{onClick:()=>Te(`notifications`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${ye===`notifications`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,G.jsx)(Go,{className:`w-4 h-4`}),i(`settings.tabs.notifications`),Ht&&Ht.length>0&&(0,G.jsx)(`span`,{className:`text-xs bg-bambu-dark-tertiary px-1.5 py-0.5 rounded-full`,children:Ht.length})]}),(0,G.jsxs)(`button`,{onClick:()=>Te(`queue`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${ye===`queue`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,G.jsx)(Xc,{className:`w-4 h-4`}),i(`settings.tabs.queue`,`Workflow`)]}),(0,G.jsxs)(`button`,{onClick:()=>Te(`filament`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${ye===`filament`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,G.jsx)(Hs,{className:`w-4 h-4`}),i(`settings.tabs.filament`)]}),(0,G.jsxs)(`button`,{onClick:()=>Te(`network`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${ye===`network`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,G.jsx)(Yu,{className:`w-4 h-4`}),i(`settings.tabs.network`),(0,G.jsx)(`span`,{className:`w-2 h-2 rounded-full ${Sn?.enabled?`bg-green-400`:`bg-gray-500`}`})]}),(0,G.jsxs)(`button`,{onClick:()=>Te(`apikeys`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${ye===`apikeys`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,G.jsx)(Uc,{className:`w-4 h-4`}),i(`settings.tabs.apiKeys`),Wt&&Wt.length>0&&(0,G.jsx)(`span`,{className:`text-xs bg-bambu-dark-tertiary px-1.5 py-0.5 rounded-full`,children:Wt.length})]}),(0,G.jsxs)(`button`,{onClick:()=>Te(`virtual-printer`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${ye===`virtual-printer`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,G.jsx)(Fl,{className:`w-4 h-4`}),i(`settings.tabs.virtualPrinter`),(0,G.jsx)(`span`,{className:`w-2 h-2 rounded-full ${en?`bg-green-400`:`bg-gray-500`}`})]}),(0,G.jsxs)(`button`,{onClick:()=>Te(`spoolbuddy`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${ye===`spoolbuddy`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,G.jsx)(Gl,{className:`w-4 h-4`}),i(`settings.tabs.spoolbuddy`),nn>0&&(0,G.jsx)(`span`,{className:`text-xs bg-bambu-dark-tertiary px-1.5 py-0.5 rounded-full`,children:nn}),(0,G.jsx)(`span`,{className:`w-2 h-2 rounded-full ${rn?`bg-green-400`:`bg-gray-500`}`})]}),(0,G.jsxs)(`button`,{onClick:()=>Te(`failure-detection`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${ye===`failure-detection`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,G.jsx)(Kl,{className:`w-4 h-4`}),i(`settings.tabs.failureDetection`),(0,G.jsx)(`span`,{className:`w-2 h-2 rounded-full ${on?`bg-green-400`:`bg-gray-500`}`})]}),(0,G.jsxs)(`button`,{onClick:()=>Te(`users`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${ye===`users`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,G.jsx)(Bu,{className:`w-4 h-4`}),i(`settings.tabs.users`),s&&(0,G.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-green-400`})]}),(0,G.jsxs)(`button`,{onClick:()=>Te(`backup`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${ye===`backup`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,G.jsx)(Us,{className:`w-4 h-4`}),i(`settings.tabs.backup`),(0,G.jsx)(`span`,{className:`w-2 h-2 rounded-full ${wn?.is_authenticated&&Cn?.configured&&Cn?.enabled||Nt?.local_backup_enabled?`bg-green-400`:`bg-gray-500`}`})]})]}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[ye===`general`&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`a`,{href:kf(Xt,`app-settings`),target:`_blank`,rel:`noopener noreferrer`,className:`group block mb-4 lg:mb-6 rounded-xl border border-bambu-green/30 bg-gradient-to-br from-bambu-green/15 via-bambu-green/5 to-transparent hover:border-bambu-green/50 hover:from-bambu-green/20 transition-colors`,children:(0,G.jsxs)(`div`,{className:`flex flex-col md:flex-row items-start md:items-center gap-4 p-4 md:p-5`,children:[(0,G.jsx)(`div`,{className:`p-3 rounded-lg bg-bambu-green/20 text-bambu-green flex-shrink-0`,children:Xt===`business`?(0,G.jsx)(Xo,{className:`w-6 h-6`}):(0,G.jsx)(Fc,{className:`w-6 h-6`})}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`p`,{className:`text-base font-semibold text-white`,children:Xt===`business`?i(`sponsors.businessTitle`,`Bambuddy for business`):i(`sponsors.sectionTitle`,`Independent & community-funded`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-0.5`,children:Xt===`business`?i(`sponsors.businessTagline`,`You're running {{count}} printers. Priority support, commercial licensing and invoicing are available for teams and print farms.`,{count:Jt?.length??0}):i(`sponsors.tagline`,`Bambuddy is free and stays that way because people choose to support it. No VC, no cloud lock-in.`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 px-4 py-2 rounded-lg bg-bambu-green/20 text-bambu-green group-hover:bg-bambu-green/30 text-sm font-medium whitespace-nowrap self-start md:self-auto`,children:[Xt===`business`?i(`sponsors.businessCta`,`Bambuddy for business`):i(`sponsors.viewSupporters`,`View supporters`),(0,G.jsx)(tc,{className:`w-4 h-4`})]})]})}),(0,G.jsxs)(`div`,{className:`flex flex-col lg:flex-row gap-4 lg:gap-6`,children:[(0,G.jsxs)(`div`,{className:`space-y-3 flex-1 lg:max-w-xl`,children:[(0,G.jsxs)(Md,{id:`card-general`,children:[(0,G.jsx)(Nd,{children:(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(`settings.general`)})}),(0,G.jsxs)(Pd,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[(0,G.jsx)(Dc,{className:`w-4 h-4 inline mr-1`}),i(`settings.language`)]}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(`select`,{value:a.language,onChange:e=>{let t=e.target.value;if(s&&!d(`settings:update`)){o(i(`settings.toast.noPermissionUpdate`),`error`);return}a.changeLanguage(t),$n.mutate({language:t})},className:`w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer`,children:kt.map(e=>(0,G.jsxs)(`option`,{value:e.code,children:[e.nativeName,` (`,e.name,`)`]},e.code))}),(0,G.jsx)(ds,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.languageDescription`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.defaultView`)}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(`select`,{value:he,onChange:e=>Mt(e.target.value),className:`w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer`,children:$p.map(e=>(0,G.jsx)(`option`,{value:e.to,children:i(e.labelKey)},e.id))}),(0,G.jsx)(ds,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.defaultViewDescription`)})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.dateFormat`)}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsxs)(`select`,{value:A.date_format||`system`,onChange:e=>tr(`date_format`,e.target.value),className:`w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer`,children:[(0,G.jsx)(`option`,{value:`system`,children:i(`settings.systemDefault`)}),(0,G.jsx)(`option`,{value:`us`,children:i(`settings.dateFormatUs`)}),(0,G.jsx)(`option`,{value:`eu`,children:i(`settings.dateFormatEu`)}),(0,G.jsx)(`option`,{value:`iso`,children:i(`settings.dateFormatIso`)})]}),(0,G.jsx)(ds,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.timeFormat`)}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsxs)(`select`,{value:A.time_format||`system`,onChange:e=>tr(`time_format`,e.target.value),className:`w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer`,children:[(0,G.jsx)(`option`,{value:`system`,children:i(`settings.systemDefault`)}),(0,G.jsx)(`option`,{value:`12h`,children:i(`settings.timeFormat12`)}),(0,G.jsx)(`option`,{value:`24h`,children:i(`settings.timeFormat24`)})]}),(0,G.jsx)(ds,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.defaultPrinter`)}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsxs)(`select`,{value:A.default_printer_id??``,onChange:e=>tr(`default_printer_id`,e.target.value?Number(e.target.value):null),className:`w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer`,children:[(0,G.jsx)(`option`,{value:``,children:i(`settings.noDefaultPrinter`)}),Jt?.map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),(0,G.jsx)(ds,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.defaultPrinterDescription`)})]})]})]}),(0,G.jsxs)(Md,{id:`card-appearance`,children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(Sl,{className:`w-5 h-5`}),i(`settings.appearance`)]})}),(0,G.jsxs)(Pd,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,G.jsxs)(`label`,{className:`text-sm text-bambu-gray`,children:[i(`settings.theme`),`:`]}),(0,G.jsx)(`div`,{className:`flex gap-1`,children:[{id:`dark`,label:i(`settings.themeDark`)},{id:`light`,label:i(`settings.themeLight`)},{id:`system`,label:i(`settings.themeSystem`)}].map(({id:e,label:t})=>(0,G.jsx)(`button`,{onClick:()=>{x(e),o(i(`settings.toast.settingsSaved`),`success`)},className:`px-3 py-1 text-xs rounded-lg border transition-colors ${f===e?`border-bambu-green bg-bambu-green/10 text-bambu-green`:`border-gray-300 dark:border-bambu-dark-tertiary text-gray-500 dark:text-bambu-gray hover:text-gray-900 dark:hover:text-white cursor-pointer`}`,children:t},e))})]}),(0,G.jsxs)(`div`,{className:`space-y-3 p-4 rounded-lg border ${p===`dark`?`border-bambu-green bg-bambu-green/5`:`border-bambu-dark-tertiary`}`,children:[(0,G.jsxs)(`h3`,{className:`text-sm font-medium text-white flex items-center gap-2`,children:[i(`settings.darkMode`),p===`dark`&&(0,G.jsx)(`span`,{className:`text-xs text-bambu-green`,children:i(`settings.active`)})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-3 gap-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.background`)}),(0,G.jsxs)(`select`,{value:h,onChange:e=>{C(e.target.value),o(i(`settings.toast.settingsSaved`),`success`)},className:`w-full px-2 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,G.jsx)(`option`,{value:`neutral`,children:i(`settings.bgNeutral`)}),(0,G.jsx)(`option`,{value:`warm`,children:i(`settings.bgWarm`)}),(0,G.jsx)(`option`,{value:`cool`,children:i(`settings.bgCool`)}),(0,G.jsx)(`option`,{value:`oled`,children:i(`settings.bgOled`)}),(0,G.jsx)(`option`,{value:`slate`,children:i(`settings.bgSlate`)}),(0,G.jsx)(`option`,{value:`forest`,children:i(`settings.bgForest`)})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.accent`)}),(0,G.jsxs)(`select`,{value:g,onChange:e=>{w(e.target.value),o(i(`settings.toast.settingsSaved`),`success`)},className:`w-full px-2 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,G.jsx)(`option`,{value:`green`,children:i(`settings.accentGreen`)}),(0,G.jsx)(`option`,{value:`teal`,children:i(`settings.accentTeal`)}),(0,G.jsx)(`option`,{value:`blue`,children:i(`settings.accentBlue`)}),(0,G.jsx)(`option`,{value:`orange`,children:i(`settings.accentOrange`)}),(0,G.jsx)(`option`,{value:`purple`,children:i(`settings.accentPurple`)}),(0,G.jsx)(`option`,{value:`red`,children:i(`settings.accentRed`)})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.style`)}),(0,G.jsxs)(`select`,{value:m,onChange:e=>{S(e.target.value),o(i(`settings.toast.settingsSaved`),`success`)},className:`w-full px-2 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,G.jsx)(`option`,{value:`classic`,children:i(`settings.styleClassic`)}),(0,G.jsx)(`option`,{value:`glow`,children:i(`settings.styleGlow`)}),(0,G.jsx)(`option`,{value:`vibrant`,children:i(`settings.styleVibrant`)})]})]})]})]}),(0,G.jsxs)(`div`,{className:`space-y-3 p-4 rounded-lg border ${p===`light`?`border-bambu-green bg-bambu-green/5`:`border-bambu-dark-tertiary`}`,children:[(0,G.jsxs)(`h3`,{className:`text-sm font-medium text-white flex items-center gap-2`,children:[i(`settings.lightMode`),p===`light`&&(0,G.jsx)(`span`,{className:`text-xs text-bambu-green`,children:i(`settings.active`)})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-3 gap-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.background`)}),(0,G.jsxs)(`select`,{value:v,onChange:e=>{E(e.target.value),o(i(`settings.toast.settingsSaved`),`success`)},className:`w-full px-2 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,G.jsx)(`option`,{value:`neutral`,children:i(`settings.bgNeutral`)}),(0,G.jsx)(`option`,{value:`warm`,children:i(`settings.bgWarm`)}),(0,G.jsx)(`option`,{value:`cool`,children:i(`settings.bgCool`)})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.accent`)}),(0,G.jsxs)(`select`,{value:b,onChange:e=>{D(e.target.value),o(i(`settings.toast.settingsSaved`),`success`)},className:`w-full px-2 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,G.jsx)(`option`,{value:`green`,children:i(`settings.accentGreen`)}),(0,G.jsx)(`option`,{value:`teal`,children:i(`settings.accentTeal`)}),(0,G.jsx)(`option`,{value:`blue`,children:i(`settings.accentBlue`)}),(0,G.jsx)(`option`,{value:`orange`,children:i(`settings.accentOrange`)}),(0,G.jsx)(`option`,{value:`purple`,children:i(`settings.accentPurple`)}),(0,G.jsx)(`option`,{value:`red`,children:i(`settings.accentRed`)})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.style`)}),(0,G.jsxs)(`select`,{value:_,onChange:e=>{T(e.target.value),o(i(`settings.toast.settingsSaved`),`success`)},className:`w-full px-2 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,G.jsx)(`option`,{value:`classic`,children:i(`settings.styleClassic`)}),(0,G.jsx)(`option`,{value:`glow`,children:i(`settings.styleGlow`)}),(0,G.jsx)(`option`,{value:`vibrant`,children:i(`settings.styleVibrant`)})]})]})]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.themeToggleHint`)}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between pt-2 border-t border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.progressInTitle`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.progressInTitleDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:O,onChange:e=>{k(e.target.checked),o(i(`settings.toast.settingsSaved`),`success`)},className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]})]})]}),(0,G.jsxs)(Md,{id:`card-archive`,children:[(0,G.jsx)(Nd,{children:(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(`settings.archiveSettings`)})}),(0,G.jsxs)(Pd,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.autoArchivePrints`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.autoArchiveDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.auto_archive,onChange:e=>tr(`auto_archive`,e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.saveThumbnails`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.saveThumbnailsDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.save_thumbnails,onChange:e=>tr(`save_thumbnails`,e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.captureFinishPhoto`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.captureFinishPhotoDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.capture_finish_photo,onChange:e=>tr(`capture_finish_photo`,e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),A.capture_finish_photo&&(0,G.jsxs)(`div`,{className:`flex items-center justify-between pl-4 border-l-2 border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.finishPhotoRestorePlate`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.finishPhotoRestorePlateDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.finish_photo_restore_plate??!0,onChange:e=>tr(`finish_photo_restore_plate`,e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),A.capture_finish_photo&&sn&&!sn.installed&&(0,G.jsxs)(`div`,{className:`flex items-start gap-2 p-3 bg-yellow-500/10 border border-yellow-500/30 rounded-lg`,children:[(0,G.jsx)(Pu,{className:`w-5 h-5 text-yellow-500 flex-shrink-0 mt-0.5`}),(0,G.jsxs)(`div`,{className:`text-sm`,children:[(0,G.jsx)(`p`,{className:`text-yellow-500 font-medium`,children:i(`settings.ffmpegNotInstalled`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:i(`settings.ffmpegRequired`)})]})]}),pn&&mn&&(0,G.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary pt-3 mt-3 space-y-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`archiveAutoPurge.enableLabel`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`archiveAutoPurge.enableDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:mn.enabled,onChange:e=>gn({enabled:e.target.checked}),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`archiveAutoPurge.ageLabel`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`input`,{type:`number`,min:7,max:3650,disabled:!mn.enabled,value:mn.days,onChange:e=>gn({days:Math.max(7,Math.min(3650,parseInt(e.target.value||`0`,10)||0))}),className:`w-24 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none disabled:opacity-50`}),(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:i(`archiveAutoPurge.days`)})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`archiveAutoPurge.ageDescription`)})]}),(0,G.jsxs)(`label`,{className:`flex items-start gap-2 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,disabled:!mn.enabled,checked:mn.purge_stats,onChange:e=>gn({purge_stats:e.target.checked}),className:`mt-0.5 shrink-0 disabled:opacity-50`}),(0,G.jsxs)(`span`,{className:`text-sm`,children:[(0,G.jsx)(`span`,{className:`text-white block`,children:i(`archiveAutoPurge.purgeStatsLabel`)}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray block mt-0.5`,children:i(`archiveAutoPurge.purgeStatsDescription`)})]})]})]})]})]})]}),(0,G.jsxs)(`div`,{className:`space-y-3 flex-1 lg:max-w-md`,children:[(0,G.jsxs)(Md,{id:`card-camera`,children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(Hu,{className:`w-5 h-5 text-bambu-green`}),i(`settings.camera`)]})}),(0,G.jsxs)(Pd,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.cameraViewMode`)}),(0,G.jsxs)(`select`,{value:A.camera_view_mode??`window`,onChange:e=>tr(`camera_view_mode`,e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,G.jsx)(`option`,{value:`window`,children:i(`settings.newWindow`)}),(0,G.jsx)(`option`,{value:`embedded`,children:i(`settings.embeddedOverlay`)})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:A.camera_view_mode===`embedded`?i(`settings.cameraOverlayDescription`):i(`settings.cameraWindowDescription`)})]}),(0,G.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary pt-4 mt-4`,children:[(0,G.jsx)(`h3`,{className:`text-sm font-medium text-white mb-2`,children:i(`settings.externalCameras`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mb-3`,children:i(`settings.externalCamerasDescription`)}),Jt&&Jt.length>0?(0,G.jsx)(`div`,{className:`space-y-3`,children:Jt.map(e=>(0,G.jsxs)(`div`,{className:`p-3 bg-bambu-dark rounded-lg`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,G.jsx)(`span`,{className:`text-white font-medium text-sm`,children:e.name}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:e.external_camera_enabled,onChange:t=>mr(e.id,{enabled:t.target.checked}),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green`})]})]}),e.external_camera_enabled&&(0,G.jsxs)(`div`,{className:`space-y-2 mt-2`,children:[(0,G.jsx)(`input`,{type:`text`,placeholder:e.external_camera_type===`usb`?i(`settings.cameraPlaceholderUsb`):i(`settings.cameraPlaceholderUrl`),value:rr[e.id]??e.external_camera_url??``,onChange:t=>fr(e.id,t.target.value),className:`w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsxs)(`select`,{value:e.external_camera_type||`mjpeg`,onChange:t=>mr(e.id,{type:t.target.value}),className:`flex-1 px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`,children:[(0,G.jsx)(`option`,{value:`mjpeg`,children:i(`settings.cameraTypeMjpeg`)}),(0,G.jsx)(`option`,{value:`rtsp`,children:i(`settings.cameraTypeRtsp`)}),(0,G.jsx)(`option`,{value:`snapshot`,children:i(`settings.cameraTypeSnapshot`)}),(0,G.jsx)(`option`,{value:`usb`,children:i(`settings.cameraTypeUsb`)})]}),(0,G.jsx)(Q,{size:`sm`,variant:`secondary`,onClick:()=>nr(e.id,rr[e.id]??e.external_camera_url??``,e.external_camera_type||`mjpeg`),disabled:At[e.id]||!(rr[e.id]??e.external_camera_url),children:At[e.id]?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):i(`settings.test`)})]}),Dt[e.id]&&(0,G.jsx)(`div`,{className:`text-xs flex items-center gap-1 ${Dt[e.id]?.success?`text-green-500`:`text-red-500`}`,children:Dt[e.id]?.success?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(ys,{className:`w-3 h-3`}),i(`settings.connected`),Dt[e.id]?.resolution&&` (${Dt[e.id]?.resolution})`]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Ts,{className:`w-3 h-3`}),Dt[e.id]?.error||i(`settings.toast.connectionFailed`)]})}),(e.external_camera_type===`mjpeg`||e.external_camera_type===`rtsp`||e.external_camera_type===`usb`)&&(0,G.jsxs)(`div`,{className:`space-y-1`,children:[(0,G.jsx)(`label`,{className:`text-xs text-bambu-gray`,children:i(`settings.cameraSnapshotUrl`,`Snapshot URL (optional)`)}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsx)(`input`,{type:`text`,placeholder:i(`settings.cameraSnapshotUrlPlaceholder`,`http://192.168.1.61:1984/api/frame.jpeg?src=printer`),value:cr[e.id]??e.external_camera_snapshot_url??``,onChange:t=>pr(e.id,t.target.value),className:`flex-1 px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none`}),(0,G.jsx)(Q,{size:`sm`,variant:`secondary`,onClick:()=>nr(e.id,cr[e.id]??e.external_camera_snapshot_url??``,`snapshot`),disabled:At[e.id]||!(cr[e.id]??e.external_camera_snapshot_url),children:At[e.id]?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):i(`settings.test`)})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray opacity-75`,children:i(`settings.cameraSnapshotUrlHelp`,`Single-frame URL used for notification thumbnails, finish photos, timelapse and plate detection. Leave blank to capture from the live stream above. Useful for go2rtc (/api/frame.jpeg) and IP cameras with a dedicated snapshot endpoint.`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`label`,{className:`text-xs text-bambu-gray`,children:i(`settings.cameraRotation`)}),(0,G.jsxs)(`select`,{value:e.camera_rotation||0,onChange:t=>mr(e.id,{rotation:parseInt(t.target.value)}),className:`px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-xs focus:border-bambu-green focus:outline-none`,children:[(0,G.jsx)(`option`,{value:0,children:`0°`}),(0,G.jsx)(`option`,{value:90,children:`90°`}),(0,G.jsx)(`option`,{value:180,children:`180°`}),(0,G.jsx)(`option`,{value:270,children:`270°`})]})]})]})]},e.id))}):(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray italic`,children:i(`settings.noPrintersConfigured`)})]})]})]}),(0,G.jsxs)(Md,{id:`card-cost`,children:[(0,G.jsx)(Nd,{children:(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(`settings.costTracking`)})}),(0,G.jsxs)(Pd,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.currency`)}),(0,G.jsx)(`select`,{value:A.currency,onChange:e=>tr(`currency`,e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:Df.map(e=>(0,G.jsx)(`option`,{value:e.code,children:e.label},e.code))})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.defaultFilamentCost`)}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(`span`,{className:`absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray text-sm pointer-events-none`,children:Ef(A.currency)}),(0,G.jsx)(`input`,{type:`number`,step:`0.01`,min:`0`,value:A.default_filament_cost,onChange:e=>tr(`default_filament_cost`,parseFloat(e.target.value)||0),style:{paddingLeft:`${Math.max(2,Ef(A.currency).length*.6+1)}rem`},className:`w-full pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.electricityCost`)}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(`span`,{className:`absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray text-sm pointer-events-none`,children:Ef(A.currency)}),(0,G.jsx)(`input`,{type:`number`,step:`0.001`,min:`0`,value:A.energy_cost_per_kwh,onChange:e=>tr(`energy_cost_per_kwh`,parseFloat(e.target.value)||0),style:{paddingLeft:`${Math.max(2,Ef(A.currency).length*.6+1)}rem`},className:`w-full pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.energyDisplayMode`)}),(0,G.jsxs)(`select`,{value:A.energy_tracking_mode||`total`,onChange:e=>tr(`energy_tracking_mode`,e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,G.jsx)(`option`,{value:`print`,children:i(`settings.printsOnly`)}),(0,G.jsx)(`option`,{value:`total`,children:i(`settings.totalConsumption`)})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:A.energy_tracking_mode===`print`?i(`settings.energyModePrintDescription`):i(`settings.energyModeTotalDescription`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.billingEnabled`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.billingEnabledDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.billing_enabled??!1,onChange:e=>tr(`billing_enabled`,e.target.checked),className:`peer sr-only`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary rounded-full peer-checked:bg-bambu-green peer-checked:after:translate-x-5 after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border after:rounded-full after:h-5 after:w-5 after:transition-all`})]})]}),A.billing_enabled&&(0,G.jsxs)(`div`,{className:`mt-4 flex items-center justify-between gap-4 rounded-lg border border-bambu-dark-tertiary bg-bambu-dark px-4 py-3`,children:[(0,G.jsxs)(`div`,{className:`flex-1`,children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.printerKillSwitch`,`Unauthorized print kill switch`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.printerKillSwitchDescription`,`Immediately stop prints that start without authorization.`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.printer_kill_switch_enabled??!1,onChange:e=>tr(`printer_kill_switch_enabled`,e.target.checked),className:`peer sr-only`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary rounded-full peer-checked:bg-bambu-green peer-checked:after:translate-x-5 after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border after:rounded-full after:h-5 after:w-5 after:transition-all`})]})]}),A.billing_enabled&&(0,G.jsxs)(`div`,{className:`mt-4 rounded-lg border border-bambu-dark-tertiary bg-bambu-dark p-4`,children:[(0,G.jsx)(`div`,{className:`mb-3`,children:(0,G.jsxs)(`h4`,{className:`text-base font-medium text-white flex items-center gap-2`,children:[(0,G.jsx)(rs,{className:`w-4 h-4 text-bambu-green`}),i(`settings.financeBudgetReset`,`Finance Monthly Budget Reset`)]})}),(0,G.jsxs)(`div`,{className:`flex gap-4`,children:[(0,G.jsxs)(`div`,{className:`flex-1`,children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.financeBudgetResetDay`,`Reset Day`)}),(0,G.jsx)(`input`,{type:`number`,min:1,max:31,value:A.finance_budget_reset_day??1,onChange:e=>tr(`finance_budget_reset_day`,Math.max(1,Math.min(31,parseInt(e.target.value,10)||1))),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.financeBudgetResetDayHelp`,`For short months, reset uses the last day of the month.`)})]}),(0,G.jsxs)(`div`,{className:`flex-1`,children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.financeBudgetResetTimezone`,`Reset timezone`)}),(0,G.jsxs)(`select`,{value:A.finance_budget_reset_timezone??`UTC`,onChange:e=>tr(`finance_budget_reset_timezone`,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:[(0,G.jsx)(`option`,{value:`UTC`,children:`UTC`}),(0,G.jsx)(`option`,{value:`Europe/Berlin`,children:`Europe/Berlin`}),(0,G.jsx)(`option`,{value:`Europe/Vienna`,children:`Europe/Vienna`}),(0,G.jsx)(`option`,{value:`Europe/Zurich`,children:`Europe/Zurich`}),(0,G.jsx)(`option`,{value:`America/New_York`,children:`America/New_York`}),(0,G.jsx)(`option`,{value:`America/Chicago`,children:`America/Chicago`}),(0,G.jsx)(`option`,{value:`America/Denver`,children:`America/Denver`}),(0,G.jsx)(`option`,{value:`America/Los_Angeles`,children:`America/Los_Angeles`}),(0,G.jsx)(`option`,{value:`Asia/Tokyo`,children:`Asia/Tokyo`}),(0,G.jsx)(`option`,{value:`Asia/Singapore`,children:`Asia/Singapore`}),(0,G.jsx)(`option`,{value:`Australia/Sydney`,children:`Australia/Sydney`})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.financeBudgetResetTimezoneHelp`,`Budget window start is calculated in this timezone.`)})]})]})]}),A.billing_enabled&&l&&(0,G.jsxs)(`div`,{className:`mt-3`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>fe(!0),disabled:pe,children:pe?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 mr-2 animate-spin`}),i(`settings.rebuildLedgerInProgress`,`Starting...`)]}):i(`settings.rebuildLedger`,`Rebuild wallet ledger`)}),de&&(0,G.jsx)(Zd,{title:i(`settings.rebuildLedgerConfirmTitle`,`Rebuild wallet ledger?`),message:i(`settings.rebuildLedgerConfirmMessage`,`This will rebuild the wallet ledger to repair historical balance values. Run this only if you know what you are doing.`),confirmText:i(`common.run`,`Run`),cancelText:i(`common.cancel`,`Cancel`),isLoading:pe,loadingText:i(`common.running`,`Running`),variant:`warning`,onCancel:()=>fe(!1),onConfirm:async()=>{me(!0);try{await Z.rebuildBalanceLedger(),o(i(`settings.rebuildLedgerStarted`,`Ledger rebuild started`),`success`),fe(!1)}catch(e){o(e.message||`Failed to start ledger rebuild`,`error`)}finally{me(!1)}}})]})]})]})]}),(0,G.jsxs)(Md,{id:`card-filemanager`,children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(lc,{className:`w-5 h-5 text-bambu-green`}),i(`settings.fileManager`)]})}),(0,G.jsxs)(Pd,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.createArchiveEntry`)}),(0,G.jsxs)(`select`,{value:A.library_archive_mode??`ask`,onChange:e=>tr(`library_archive_mode`,e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,G.jsx)(`option`,{value:`always`,children:i(`settings.archiveMode.always`)}),(0,G.jsx)(`option`,{value:`never`,children:i(`settings.archiveMode.never`)}),(0,G.jsx)(`option`,{value:`ask`,children:i(`settings.archiveMode.ask`)})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.createArchiveEntryDescription`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.lowDiskSpaceWarning`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`input`,{type:`number`,min:`0.5`,max:`100`,step:`0.5`,value:A.library_disk_warning_gb??5,onChange:e=>tr(`library_disk_warning_gb`,parseFloat(e.target.value)||5),className:`w-24 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:`GB`})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.lowDiskSpaceDescription`)})]}),ln&&un&&(0,G.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary pt-3 mt-3 space-y-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`libraryAutoPurge.enableLabel`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`libraryAutoPurge.enableDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:un.auto_purge_enabled,onChange:e=>fn({auto_purge_enabled:e.target.checked}),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`libraryAutoPurge.ageLabel`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`input`,{type:`number`,min:7,max:3650,disabled:!un.auto_purge_enabled,value:un.auto_purge_days,onChange:e=>fn({auto_purge_days:Math.max(7,Math.min(3650,parseInt(e.target.value||`0`,10)||0))}),className:`w-24 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none disabled:opacity-50`}),(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:i(`libraryAutoPurge.days`)})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`libraryAutoPurge.ageDescription`)})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-white cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,disabled:!un.auto_purge_enabled,checked:un.auto_purge_include_never_printed,onChange:e=>fn({auto_purge_include_never_printed:e.target.checked}),className:`rounded border-gray-300 disabled:opacity-50`}),i(`libraryAutoPurge.includeNeverPrinted`)]})]})]})]}),(0,G.jsxs)(Md,{id:`card-data`,children:[(0,G.jsx)(Nd,{children:(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(`settings.dataManagement`)})}),(0,G.jsxs)(Pd,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.clearNotificationLogs`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.clearNotificationLogsDescription`)})]}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:()=>He(!0),children:[(0,G.jsx)(ju,{className:`w-4 h-4`}),i(`common.clear`)]})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.resetUiPreferences`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.resetUiPreferencesDescription`)})]}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:()=>We(!0),children:[(0,G.jsx)(ju,{className:`w-4 h-4`}),i(`settings.reset`)]})]}),(0,G.jsxs)(`div`,{className:`pt-4 border-t border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.storageUsage`,`Storage Usage`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.storageUsageDescription`,`Breakdown of data usage by category`)})]}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:Rt,disabled:Lt||rt,children:[(0,G.jsx)(zl,{className:`w-4 h-4 ${Lt||rt?`animate-spin`:``}`}),i(`common.refresh`,`Refresh`)]})]}),(0,G.jsx)(`div`,{className:`mt-3`,children:It?(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-bambu-gray`,children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),i(`common.loading`,`Loading`)]}):Ft?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`w-full h-3 bg-bambu-dark rounded-full overflow-hidden flex`,children:Ft.categories.filter(e=>e.bytes>0).map((e,t)=>(0,G.jsx)(`div`,{className:`${B6(e.key,t)} h-full`,style:{width:`${e.percent_of_total}%`},title:`${e.label}: ${e.formatted}`},e.key))}),(0,G.jsx)(`div`,{className:`mt-3 flex flex-wrap gap-3`,children:Ft.categories.filter(e=>e.bytes>0).map((e,t)=>(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-xs`,children:[(0,G.jsx)(`span`,{className:`w-3 h-3 rounded-full ${B6(e.key,t)}`}),(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:e.label}),(0,G.jsx)(`span`,{className:`text-white`,children:e.formatted}),(0,G.jsxs)(`span`,{className:`text-bambu-gray`,children:[`(`,e.percent_of_total.toFixed(1),`%)`]})]},e.key))}),(0,G.jsxs)(`div`,{className:`mt-2 text-xs text-bambu-gray`,children:[i(`settings.storageUsageTotal`,`Total`),`: `,(0,G.jsx)(`span`,{className:`text-white`,children:Ft.total_formatted}),Ft.scan_errors>0&&(0,G.jsxs)(`span`,{className:`ml-2 text-amber-700 dark:text-amber-400`,children:[i(`settings.storageUsageErrors`,`Scan errors`),`: `,Ft.scan_errors]})]}),Ft.other_breakdown?.length>0&&(0,G.jsxs)(`div`,{className:`mt-4`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:i(`settings.storageUsageOtherBreakdown`,`Other breakdown`)}),(0,G.jsx)(`div`,{className:`space-y-2`,children:Ft.other_breakdown.map(e=>(0,G.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-white`,children:e.label}),(0,G.jsx)(`span`,{className:`px-2 py-0.5 rounded-full border ${e.kind===`system`?`border-slate-500 text-slate-300`:`border-bambu-green text-bambu-green`}`,children:e.kind===`system`?i(`settings.storageUsageSystem`,`System`):i(`settings.storageUsageData`,`Data`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray`,children:[(0,G.jsx)(`span`,{className:`text-white`,children:e.formatted}),(0,G.jsxs)(`span`,{children:[`(`,e.percent_of_total.toFixed(1),`%)`]})]})]},`${e.bucket}-${e.kind}`))})]})]}):(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.storageUsageUnavailable`,`Storage usage data is unavailable`)})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between pt-4 border-t border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.backupRestore`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.backupRestoreDescription`)})]}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:()=>Te(`backup`),children:[(0,G.jsx)(Us,{className:`w-4 h-4`}),i(`settings.goToBackup`)]})]})]})]})]}),(0,G.jsxs)(`div`,{className:`space-y-3 flex-1 lg:max-w-sm`,children:[(0,G.jsxs)(Md,{id:`card-updates`,children:[(0,G.jsx)(Nd,{children:(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(`settings.updates`)})}),(0,G.jsxs)(Pd,{className:`space-y-3`,children:[(0,G.jsx)(`p`,{className:`text-xs font-medium text-bambu-gray uppercase tracking-wider`,children:i(`settings.printerFirmware`)}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.checkPrinterFirmware`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.checkFirmwareDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.check_printer_firmware??!0,onChange:e=>tr(`check_printer_firmware`,e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,G.jsx)(`div`,{className:`border-t border-bambu-dark-tertiary pt-4`,children:(0,G.jsx)(`p`,{className:`text-xs font-medium text-bambu-gray uppercase tracking-wider mb-4`,children:i(`settings.bambuddySoftware`)})}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.checkForUpdatesLabel`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.autoCheckDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.check_updates,onChange:e=>tr(`check_updates`,e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between ${A.check_updates?``:`opacity-50`}`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.includeBetaUpdates`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.includeBetaUpdatesDesc`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.include_beta_updates??!1,onChange:e=>tr(`include_beta_updates`,e.target.checked),disabled:!A.check_updates,className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.currentVersion`)}),(0,G.jsxs)(`p`,{className:`text-sm text-bambu-gray`,children:[`v`,cn?.version||`...`]})]}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:()=>vn(),disabled:yn,children:[yn?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(zl,{className:`w-4 h-4`}),i(`settings.checkNow`)]})]}),_n?.update_available?(0,G.jsxs)(`div`,{className:`mt-4 p-3 bg-bambu-green/10 border border-bambu-green/30 rounded-lg`,children:[(0,G.jsxs)(`div`,{className:`flex items-start justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`p`,{className:`text-bambu-green font-medium`,children:[`Update available: v`,_n.latest_version]}),_n.release_name&&_n.release_name!==_n.latest_version&&(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:_n.release_name})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[_n.release_notes&&(0,G.jsx)(`button`,{onClick:()=>Je(!0),className:`text-bambu-gray hover:text-white transition-colors text-sm underline`,children:i(`settings.releaseNotes`)}),_n.release_url&&(0,G.jsx)(`a`,{href:_n.release_url,target:`_blank`,rel:`noopener noreferrer`,className:`text-bambu-gray hover:text-white transition-colors`,title:i(`settings.viewReleaseOnGitHub`),children:(0,G.jsx)(tc,{className:`w-4 h-4`})})]})]}),bn?.status===`downloading`||bn?.status===`installing`?(0,G.jsxs)(`div`,{className:`mt-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-bambu-gray`,children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),(0,G.jsx)(`span`,{children:bn.message})]}),(0,G.jsx)(`div`,{className:`mt-2 w-full bg-bambu-dark-tertiary rounded-full h-2`,children:(0,G.jsx)(`div`,{className:`bg-bambu-green h-2 rounded-full transition-all duration-300`,style:{width:`${bn.progress}%`}})})]}):bn?.status===`complete`?(0,G.jsx)(`div`,{className:`mt-3 p-2 bg-bambu-green/20 rounded text-sm text-bambu-green`,children:bn.message}):bn?.status===`error`?(0,G.jsx)(`div`,{className:`mt-3 p-2 bg-red-100 dark:bg-red-500/20 rounded text-sm text-red-700 dark:text-red-400`,children:bn.error||bn.message}):_n?.is_ha_addon?(0,G.jsx)(`div`,{className:`mt-3 p-3 bg-bambu-dark-tertiary rounded-lg`,children:(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.updateViaHomeAssistant`)})}):_n?.is_docker?(0,G.jsxs)(`div`,{className:`mt-3 p-3 bg-bambu-dark-tertiary rounded-lg`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mb-2`,children:i(`settings.updateViaDocker`)}),(0,G.jsxs)(`div`,{className:`flex items-start gap-1`,children:[(0,G.jsx)(`code`,{className:`flex-1 block text-xs bg-bambu-dark p-2 rounded text-bambu-green font-mono break-all select-all`,children:br}),(0,G.jsx)(eW,{value:br,titleKey:`settings.copyUpdateCommand`,copiedTitleKey:`printers.copied`,className:`ml-0 p-2 rounded hover:bg-bambu-dark text-bambu-gray hover:text-white transition-colors flex-shrink-0`,iconClassName:`w-4 h-4`})]}),(0,G.jsxs)(`label`,{className:`block mt-3`,children:[(0,G.jsx)(`span`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.composeDirectory`)}),(0,G.jsx)(`input`,{type:`text`,value:A?.docker_compose_dir??``,onChange:e=>tr(`docker_compose_dir`,e.target.value),placeholder:_n?.compose_dir_detected||`/opt/bambuddy`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded text-sm text-white font-mono placeholder:text-bambu-gray/60 focus:outline-none focus:border-bambu-green`}),(0,G.jsx)(`span`,{className:`block text-xs text-bambu-gray mt-1`,children:i(`settings.composeDirectoryHint`)})]})]}):_n?.update_method===`windows_installer`?(0,G.jsxs)(`div`,{className:`mt-3 p-3 bg-bambu-dark-tertiary rounded-lg`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mb-3`,children:i(`settings.updateViaWindowsInstaller`)}),(0,G.jsxs)(`a`,{href:_n.installer_download_url||_n.release_url||`https://github.com/maziggy/bambuddy/releases/tag/v${_n.latest_version}`,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center justify-center font-medium rounded-lg transition-colors focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-offset-bambu-dark disabled:opacity-50 bg-bambu-green hover:bg-bambu-green-light text-white focus:ring-bambu-green px-4 py-2 text-sm gap-2 min-h-[44px] md:min-h-0`,children:[(0,G.jsx)(Js,{className:`w-4 h-4`}),i(`settings.downloadWindowsInstaller`,{version:_n.latest_version})]})]}):(0,G.jsxs)(Q,{className:`mt-3`,onClick:()=>Un.mutate(),disabled:Un.isPending,children:[Un.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Js,{className:`w-4 h-4`}),i(`settings.installUpdate`)]})]}):_n?.error?(0,G.jsx)(`div`,{className:`mt-2 p-2 bg-red-50 dark:bg-red-500/10 border border-red-300 dark:border-red-500/30 rounded text-sm text-red-700 dark:text-red-400`,children:i(`settings.failedToCheckUpdates`,{error:_n.error})}):_n&&!_n.update_available?(0,G.jsx)(`p`,{className:`mt-2 text-sm text-bambu-gray`,children:i(`settings.latestVersionRunning`)}):null]})]})]}),(0,G.jsx)(hHe,{})]})]})]}),ye===`network`&&A&&(0,G.jsxs)(`div`,{className:`flex flex-col lg:flex-row gap-6`,children:[(0,G.jsxs)(`div`,{className:`flex-1 lg:max-w-xl space-y-3`,children:[(0,G.jsxs)(Md,{id:`card-externalurl`,children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(Dc,{className:`w-5 h-5 text-blue-600 dark:text-blue-400`}),i(`settings.externalUrl`)]})}),(0,G.jsxs)(Pd,{className:`space-y-3`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.externalUrlDescription`)}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.bambuddyUrl`)}),(0,G.jsx)(`input`,{type:`text`,value:A.external_url??``,onChange:e=>tr(`external_url`,e.target.value),placeholder:`http://192.168.1.100:8000`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.externalUrlHint`)})]})]})]}),(0,G.jsxs)(Md,{id:`card-ftpretry`,children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(zl,{className:`w-5 h-5 text-blue-600 dark:text-blue-400`}),i(`settings.ftpRetry`)]})}),(0,G.jsxs)(Pd,{className:`space-y-3`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.ftpRetryDescription`)}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.enableRetry`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.autoRetryDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.ftp_retry_enabled??!0,onChange:e=>tr(`ftp_retry_enabled`,e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),A.ftp_retry_enabled&&(0,G.jsxs)(`div`,{className:`space-y-3 pt-2 border-t border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.retryAttempts`)}),(0,G.jsxs)(`div`,{className:`relative w-44`,children:[(0,G.jsx)(`select`,{value:A.ftp_retry_count??3,onChange:e=>tr(`ftp_retry_count`,parseInt(e.target.value)),className:`w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer`,children:[1,2,3,4,5,6,7,8,9,10].map(e=>(0,G.jsx)(`option`,{value:e,children:i(`settings.time`,{count:e})},e))}),(0,G.jsx)(ds,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.retryDelay`)}),(0,G.jsxs)(`div`,{className:`relative w-44`,children:[(0,G.jsx)(`select`,{value:A.ftp_retry_delay??2,onChange:e=>tr(`ftp_retry_delay`,parseInt(e.target.value)),className:`w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer`,children:[1,2,3,5,10,15,20,30].map(e=>(0,G.jsx)(`option`,{value:e,children:i(`settings.second`,{count:e})},e))}),(0,G.jsx)(ds,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.connectionTimeout`)}),(0,G.jsxs)(`div`,{className:`relative w-44`,children:[(0,G.jsx)(`select`,{value:A.ftp_timeout??30,onChange:e=>tr(`ftp_timeout`,parseInt(e.target.value)),className:`w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer`,children:[10,15,20,30,45,60,90,120,180,300].map(e=>(0,G.jsx)(`option`,{value:e,children:i(`settings.nSeconds`,{count:e})},e))}),(0,G.jsx)(ds,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.increaseForWeakWifi`)})]})]})]})]})]}),(0,G.jsxs)(`div`,{className:`flex-1 lg:max-w-xl space-y-3`,children:[(0,G.jsxs)(Md,{id:`card-ha`,children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(Lc,{className:`w-5 h-5 text-bambu-green`}),i(`settings.homeAssistant`)]}),A.ha_enabled&&Ct&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`w-2.5 h-2.5 rounded-full ${Ct.success?`bg-green-400`:`bg-red-400`}`}),(0,G.jsx)(`span`,{className:`text-sm ${Ct.success?`text-green-700 dark:text-green-400`:`text-red-700 dark:text-red-400`}`,children:Ct.success?i(`settings.connected`):i(`settings.disconnected`)})]})]})}),(0,G.jsxs)(Pd,{className:`space-y-3`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.homeAssistantFullDescription`)}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex-1`,children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.enableHomeAssistant`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.homeAssistantDescription`)}),A.ha_env_managed&&(0,G.jsxs)(`div`,{className:`flex items-center gap-1 mt-1`,children:[(0,G.jsx)(el,{className:`w-3 h-3 text-bambu-green`}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-green`,children:i(`settings.autoEnabledViaEnv`)})]})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.ha_enabled??!1,onChange:e=>tr(`ha_enabled`,e.target.checked),disabled:A.ha_env_managed,className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green ${A.ha_env_managed?`opacity-60 cursor-not-allowed`:``}`})]})]}),A.ha_enabled&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[i(`settings.homeAssistantUrl`),A.ha_url_from_env&&(0,G.jsx)(`span`,{className:`ml-2 text-xs text-bambu-green`,children:i(`settings.environmentManagedLabel`)})]}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(`input`,{type:`text`,value:A.ha_url??``,onChange:e=>tr(`ha_url`,e.target.value),placeholder:`http://192.168.1.100:8123`,disabled:A.ha_url_from_env,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none ${A.ha_url_from_env?`opacity-60 cursor-not-allowed`:``}`}),A.ha_url_from_env&&(0,G.jsx)(el,{className:`absolute right-3 top-2.5 w-4 h-4 text-bambu-gray`})]}),A.ha_url_from_env&&(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.urlFromEnvReadOnly`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[i(`settings.longLivedAccessToken`),A.ha_token_from_env&&(0,G.jsx)(`span`,{className:`ml-2 text-xs text-bambu-green`,children:i(`settings.environmentManagedLabel`)})]}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(`input`,{type:`password`,value:A.ha_token??``,onChange:e=>tr(`ha_token`,e.target.value),placeholder:`eyJ0eXAiOiJKV1QiLC...`,disabled:A.ha_token_from_env,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none ${A.ha_token_from_env?`opacity-60 cursor-not-allowed`:``}`}),A.ha_token_from_env&&(0,G.jsx)(el,{className:`absolute right-3 top-2.5 w-4 h-4 text-bambu-gray`})]}),A.ha_token_from_env?(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.tokenFromEnvReadOnly`)}):(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.haTokenHint`)})]}),A.ha_url&&A.ha_token&&(0,G.jsx)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,disabled:Tt,onClick:async()=>{Et(!0),wt(null);try{wt(await Z.testHAConnection(A.ha_url,A.ha_token))}catch(e){wt({success:!1,message:null,error:e instanceof Error?e.message:i(`common.unknownError`)})}finally{Et(!1)}},children:[Tt?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Yu,{className:`w-4 h-4`}),i(`settings.testConnection`)]})})]})]})]}),(0,G.jsxs)(Md,{id:`card-mqtt`,children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(Yu,{className:`w-5 h-5 text-blue-600 dark:text-blue-400`}),i(`settings.mqttPublishing`)]}),Sn?.enabled&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`w-2.5 h-2.5 rounded-full ${Sn.connected?`bg-green-400`:`bg-red-400`}`}),(0,G.jsx)(`span`,{className:`text-sm ${Sn.connected?`text-green-700 dark:text-green-400`:`text-red-700 dark:text-red-400`}`,children:Sn.connected?i(`settings.connected`):i(`settings.disconnected`)})]})]})}),(0,G.jsxs)(Pd,{className:`space-y-3`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.mqttDescription`)}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.enableMqtt`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.mqttEnableDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.mqtt_enabled??!1,onChange:e=>tr(`mqtt_enabled`,e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),A.mqtt_enabled&&(0,G.jsxs)(`div`,{className:`space-y-3 pt-2 border-t border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.brokerHostname`)}),(0,G.jsx)(`input`,{type:`text`,value:A.mqtt_broker??``,onChange:e=>tr(`mqtt_broker`,e.target.value),placeholder:`mqtt.example.com or 192.168.1.100`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,G.jsxs)(`div`,{className:`flex items-end gap-4`,children:[(0,G.jsxs)(`div`,{className:`flex-1`,children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.port`)}),(0,G.jsx)(`input`,{type:`number`,min:`1`,max:`65535`,value:A.mqtt_port??1883,onChange:e=>tr(`mqtt_port`,Math.min(65535,Math.max(1,parseInt(e.target.value)||1883))),className:`w-24 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-3 pb-2`,children:[(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.mqtt_use_tls??!1,onChange:e=>{let t=e.target.checked;tr(`mqtt_use_tls`,t);let n=A.mqtt_port??1883;t&&n===1883?tr(`mqtt_port`,8883):!t&&n===8883&&tr(`mqtt_port`,1883)},className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]}),(0,G.jsx)(`span`,{className:`text-white text-sm`,children:i(`settings.useTls`)})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.usernameOptional`)}),(0,G.jsx)(`input`,{type:`text`,value:A.mqtt_username??``,onChange:e=>tr(`mqtt_username`,e.target.value),placeholder:i(`settings.leaveEmptyForAnonymous`),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.passwordOptional`)}),(0,G.jsx)(`input`,{type:`password`,value:A.mqtt_password??``,onChange:e=>tr(`mqtt_password`,e.target.value),placeholder:i(`settings.leaveEmptyForAnonymous`),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.topicPrefix`)}),(0,G.jsx)(`input`,{type:`text`,value:A.mqtt_topic_prefix??`bambuddy`,onChange:e=>tr(`mqtt_topic_prefix`,e.target.value),placeholder:`bambuddy`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.topicPrefixHint`,{prefix:A.mqtt_topic_prefix||`bambuddy`})})]}),Sn&&(0,G.jsx)(`div`,{className:`pt-3 mt-3 border-t border-bambu-dark-tertiary`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,G.jsx)(`span`,{className:`w-2 h-2 rounded-full ${Sn.connected?`bg-green-400`:`bg-red-400`}`}),(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:Sn.connected?(0,G.jsxs)(G.Fragment,{children:[i(`settings.mqttConnectedTo`),` `,(0,G.jsxs)(`span`,{className:`text-white`,children:[Sn.broker,`:`,Sn.port]})]}):i(`settings.spoolmanDisconnected`)})]})})]})]})]})]}),(0,G.jsx)(`div`,{className:`flex-1 lg:max-w-md space-y-3`,children:(0,G.jsxs)(Md,{id:`card-prometheus`,children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(Nu,{className:`w-5 h-5 text-orange-600 dark:text-orange-400`}),i(`settings.prometheusMetrics`)]})}),(0,G.jsxs)(Pd,{className:`space-y-3`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.prometheusEndpointDescription`)}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.enableMetricsEndpoint`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.prometheusDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.prometheus_enabled??!1,onChange:e=>tr(`prometheus_enabled`,e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),A.prometheus_enabled&&(0,G.jsxs)(`div`,{className:`space-y-3 pt-2 border-t border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.bearerTokenOptional`)}),(0,G.jsx)(`input`,{type:`password`,value:A.prometheus_token??``,onChange:e=>tr(`prometheus_token`,e.target.value),placeholder:i(`settings.leaveEmptyForNoAuth`),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.bearerTokenHint`)})]}),(0,G.jsxs)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary`,children:[(0,G.jsx)(`p`,{className:`text-sm text-white mb-2`,children:i(`settings.availableMetrics`)}),(0,G.jsxs)(`div`,{className:`text-xs text-bambu-gray space-y-1`,children:[(0,G.jsxs)(`p`,{children:[(0,G.jsx)(`code`,{className:`text-orange-700 dark:text-orange-400`,children:`bambuddy_printer_connected`}),` - `,i(`settings.metricsConnectionStatus`)]}),(0,G.jsxs)(`p`,{children:[(0,G.jsx)(`code`,{className:`text-orange-700 dark:text-orange-400`,children:`bambuddy_printer_state`}),` - `,i(`settings.metricsPrinterState`)]}),(0,G.jsxs)(`p`,{children:[(0,G.jsx)(`code`,{className:`text-orange-700 dark:text-orange-400`,children:`bambuddy_print_progress`}),` - `,i(`settings.metricsPrintProgress`)]}),(0,G.jsxs)(`p`,{children:[(0,G.jsx)(`code`,{className:`text-orange-700 dark:text-orange-400`,children:`bambuddy_bed_temp_celsius`}),` - `,i(`settings.metricsBedTemp`)]}),(0,G.jsxs)(`p`,{children:[(0,G.jsx)(`code`,{className:`text-orange-700 dark:text-orange-400`,children:`bambuddy_nozzle_temp_celsius`}),` - `,i(`settings.metricsNozzleTemp`)]}),(0,G.jsxs)(`p`,{children:[(0,G.jsx)(`code`,{className:`text-orange-700 dark:text-orange-400`,children:`bambuddy_prints_total`}),` - `,i(`settings.metricsPrintsTotal`)]}),(0,G.jsx)(`p`,{className:`text-bambu-gray/70 italic`,children:i(`settings.metricsMore`)})]})]})]})]})]})})]}),Ct&&(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50`,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg p-6 max-w-md w-full mx-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3 mb-4`,children:[Ct.success?(0,G.jsx)(ys,{className:`w-8 h-8 text-green-600 dark:text-green-400`}):(0,G.jsx)(Ts,{className:`w-8 h-8 text-red-600 dark:text-red-400`}),(0,G.jsx)(`h3`,{className:`text-lg font-medium text-white`,children:Ct.success?i(`settings.connectionSuccessful`):i(`settings.connectionFailed`)})]}),(0,G.jsx)(`p`,{className:`text-bambu-gray mb-6`,children:Ct.success?Ct.message||i(`settings.haConnectionSuccess`):Ct.error||i(`settings.haConnectionFailed`)}),(0,G.jsx)(`div`,{className:`flex justify-end`,children:(0,G.jsx)(Q,{variant:`primary`,onClick:()=>wt(null),children:i(`settings.ok`)})})]})}),ye===`plugs`&&(0,G.jsxs)(`div`,{id:`card-plugs`,children:[(0,G.jsxs)(`div`,{className:`flex items-start justify-between mb-6`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(jl,{className:`w-5 h-5 text-bambu-green`}),i(`settings.smartPlugs`)]}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:i(`settings.smartPlugsDescription`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 pt-1 shrink-0`,children:[zt&&zt.filter(e=>e.enabled).length>1&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,className:`whitespace-nowrap`,onClick:()=>Ke(`on`),disabled:qn.isPending,title:i(`settings.turnAllPlugsOn`),children:[qn.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Pl,{className:`w-4 h-4 text-bambu-green`}),i(`settings.allOn`)]}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,className:`whitespace-nowrap`,onClick:()=>Ke(`off`),disabled:qn.isPending,title:i(`settings.turnAllPlugsOff`),children:[qn.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Nl,{className:`w-4 h-4 text-red-600 dark:text-red-400`}),i(`settings.allOff`)]})]}),(0,G.jsxs)(Q,{className:`whitespace-nowrap`,onClick:()=>{L(null),F(!0)},children:[(0,G.jsx)(Ml,{className:`w-4 h-4`}),i(`settings.addSmartPlug`)]})]})]}),zt&&zt.length>0&&(0,G.jsxs)(Md,{className:`mb-6`,children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(td,{className:`w-4 h-4 text-yellow-600 dark:text-yellow-400`}),i(`settings.energySummary`),W&&(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin text-bambu-gray ml-2`})]})}),(0,G.jsx)(Pd,{children:Vt?(0,G.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-4`,children:[(0,G.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray text-xs mb-1`,children:[(0,G.jsx)(td,{className:`w-3 h-3`}),i(`settings.currentPower`)]}),(0,G.jsxs)(`div`,{className:`text-xl font-bold text-white`,children:[Vt.totalPower.toFixed(1),(0,G.jsx)(`span`,{className:`text-sm font-normal text-bambu-gray ml-1`,children:`W`})]}),(0,G.jsx)(`div`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.plugsOnline`,{reachable:Vt.reachableCount,total:Vt.totalPlugs})})]}),(0,G.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray text-xs mb-1`,children:[(0,G.jsx)(rs,{className:`w-3 h-3`}),i(`settings.today`)]}),(0,G.jsxs)(`div`,{className:`text-xl font-bold text-white`,children:[Vt.totalToday.toFixed(3),(0,G.jsx)(`span`,{className:`text-sm font-normal text-bambu-gray ml-1`,children:`kWh`})]}),(A?.energy_cost_per_kwh??0)>0&&(0,G.jsxs)(`div`,{className:`text-xs text-bambu-gray mt-1`,children:[`~`,(Vt.totalToday*(A?.energy_cost_per_kwh??0)).toFixed(2),` `,Ef(A?.currency||`USD`)]})]}),(0,G.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray text-xs mb-1`,children:[(0,G.jsx)(Nu,{className:`w-3 h-3`}),i(`settings.yesterday`)]}),(0,G.jsxs)(`div`,{className:`text-xl font-bold text-white`,children:[Vt.totalYesterday.toFixed(3),(0,G.jsx)(`span`,{className:`text-sm font-normal text-bambu-gray ml-1`,children:`kWh`})]}),(A?.energy_cost_per_kwh??0)>0&&(0,G.jsxs)(`div`,{className:`text-xs text-bambu-gray mt-1`,children:[`~`,(Vt.totalYesterday*(A?.energy_cost_per_kwh??0)).toFixed(2),` `,Ef(A?.currency||`USD`)]})]}),(0,G.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray text-xs mb-1`,children:[(0,G.jsx)(Gs,{className:`w-3 h-3`}),i(`settings.total`)]}),(0,G.jsxs)(`div`,{className:`text-xl font-bold text-white`,children:[Vt.totalLifetime.toFixed(1),(0,G.jsx)(`span`,{className:`text-sm font-normal text-bambu-gray ml-1`,children:`kWh`})]}),(A?.energy_cost_per_kwh??0)>0&&(0,G.jsxs)(`div`,{className:`text-xs text-bambu-gray mt-1`,children:[`~`,(Vt.totalLifetime*(A?.energy_cost_per_kwh??0)).toFixed(2),` `,Ef(A?.currency||`USD`)]})]})]}):W?null:(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.enablePlugsForSummary`)})})]}),Bt?(0,G.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,G.jsx)(Y,{className:`w-8 h-8 text-bambu-green animate-spin`})}):zt&&zt.length>0?(0,G.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4`,children:zt.map(e=>(0,G.jsx)(jVe,{plug:e,onEdit:e=>{L(e),F(!0)}},e.id))}):(0,G.jsx)(Md,{children:(0,G.jsx)(Pd,{className:`py-12`,children:(0,G.jsxs)(`div`,{className:`text-center text-bambu-gray`,children:[(0,G.jsx)(jl,{className:`w-16 h-16 mx-auto mb-4 opacity-30`}),(0,G.jsx)(`p`,{className:`text-lg font-medium text-white mb-2`,children:i(`settings.noSmartPlugsTitle`)}),(0,G.jsx)(`p`,{className:`text-sm mb-4`,children:i(`settings.noSmartPlugsDescription`)}),(0,G.jsxs)(Q,{onClick:()=>{L(null),F(!0)},children:[(0,G.jsx)(Ml,{className:`w-4 h-4`}),i(`settings.addFirstSmartPlug`)]})]})})}),(0,G.jsxs)(`div`,{className:`mt-8`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-4`,children:[(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(Sc,{className:`w-5 h-5 text-bambu-green`}),i(`haSensors.sectionTitle`)]}),(0,G.jsxs)(Q,{className:`whitespace-nowrap`,disabled:!Jt?.length,onClick:()=>{V(null),z(!0)},children:[(0,G.jsx)(Ml,{className:`w-4 h-4`}),i(`haSensors.add`)]})]}),Yt&&Yt.length>0?(0,G.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4`,children:Yt.map(e=>{let t=Jt?.find(t=>t.id===e.printer_id);return(0,G.jsx)(Md,{children:(0,G.jsxs)(Pd,{className:`py-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsx)(`div`,{className:`text-white font-medium truncate`,children:e.name}),(0,G.jsx)(`div`,{className:`text-xs text-bambu-gray truncate`,children:e.entity_id}),(0,G.jsx)(`div`,{className:`text-xs text-bambu-gray mt-1`,children:t?.name??i(`haSensors.unknownPrinter`)})]}),(0,G.jsx)(Q,{size:`sm`,variant:`secondary`,onClick:()=>{V(e),z(!0)},children:i(`common.edit`)})]}),(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-1 mt-3`,children:[e.block_print&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 text-xs rounded bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-400`,children:i(`haSensors.badgeBlocks`)}),e.notify_on_alert&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 text-xs rounded bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`,children:i(`haSensors.badgeNotifies`)}),!e.show_on_printer_card&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 text-xs rounded bg-bambu-dark-tertiary text-bambu-gray`,children:i(`haSensors.badgeHidden`)})]})]})},e.id)})}):(0,G.jsx)(Md,{children:(0,G.jsx)(Pd,{className:`py-8`,children:(0,G.jsxs)(`div`,{className:`text-center text-bambu-gray`,children:[(0,G.jsx)(Sc,{className:`w-12 h-12 mx-auto mb-3 opacity-30`}),(0,G.jsx)(`p`,{className:`text-sm`,children:i(`haSensors.empty`)})]})})})]})]}),ye===`notifications`&&(0,G.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-4`,children:[(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,id:`card-providers`,children:[(0,G.jsx)(Go,{className:`w-5 h-5 text-bambu-green`}),i(`settings.providers`)]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(Q,{size:`sm`,variant:`secondary`,onClick:()=>ue(!0),children:[(0,G.jsx)(Ic,{className:`w-4 h-4`}),i(`settings.log`)]}),Ht&&Ht.length>0&&(0,G.jsxs)(Q,{size:`sm`,variant:`secondary`,onClick:()=>{Gn(null),Kn.mutate()},disabled:Kn.isPending,children:[Kn.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Xl,{className:`w-4 h-4`}),i(`settings.testAll`)]}),(0,G.jsxs)(Q,{size:`sm`,onClick:()=>{re(null),te(!0)},children:[(0,G.jsx)(Ml,{className:`w-4 h-4`}),i(`settings.addNotificationProvider`)]})]})]}),(0,G.jsx)(Md,{className:`mb-4`,children:(0,G.jsx)(Pd,{className:`py-3`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white text-sm font-medium`,children:i(`settings.notificationLanguage`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.notificationLanguageDescription`)})]}),(0,G.jsx)(`select`,{value:A.notification_language||`en`,onChange:e=>tr(`notification_language`,e.target.value),className:`px-2 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:outline-none focus:ring-1 focus:ring-bambu-green`,children:kt.map(e=>(0,G.jsx)(`option`,{value:e.code,children:e.nativeName},e.code))})]})})}),(0,G.jsx)(Md,{className:`mb-4`,children:(0,G.jsx)(Pd,{className:`py-3`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white text-sm font-medium`,children:i(`settings.bedCooledThreshold`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.bedCooledThresholdDescription`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(`input`,{type:`number`,min:20,max:80,step:1,value:A.bed_cooled_threshold??35,onChange:e=>tr(`bed_cooled_threshold`,Number(e.target.value)),className:`w-16 px-2 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm text-center focus:outline-none focus:ring-1 focus:ring-bambu-green`}),(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:`°C`})]})]})})}),(0,G.jsx)(Md,{className:`mb-4`,children:(0,G.jsx)(Pd,{className:`py-3`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between ${Tn?.advanced_auth_enabled?``:`opacity-50`}`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white text-sm font-medium`,children:i(`settings.userNotificationsEnabled`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:Tn?.advanced_auth_enabled?i(`settings.userNotificationsEnabledDescription`):i(`settings.userNotificationsDisabledHint`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,className:`sr-only peer`,checked:A.user_notifications_enabled??!0,disabled:!Tn?.advanced_auth_enabled,onChange:e=>tr(`user_notifications_enabled`,e.target.checked)}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green peer-disabled:cursor-not-allowed`})]})]})})}),Wn&&(0,G.jsx)(Md,{className:`mb-4`,children:(0,G.jsxs)(Pd,{className:`py-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,G.jsx)(`span`,{className:`text-sm font-medium text-white`,children:i(`settings.testResults`)}),(0,G.jsx)(`button`,{onClick:()=>Gn(null),className:`text-bambu-gray hover:text-white text-xs`,children:i(`common.dismiss`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-4 text-sm mb-2`,children:[(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-bambu-green`,children:[(0,G.jsx)(ys,{className:`w-4 h-4`}),i(`settings.testPassedCount`,{count:Wn.success})]}),Wn.failed>0&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-red-700 dark:text-red-400`,children:[(0,G.jsx)(Ts,{className:`w-4 h-4`}),i(`settings.testFailedCount`,{count:Wn.failed})]})]}),Wn.results.filter(e=>!e.success).length>0&&(0,G.jsx)(`div`,{className:`space-y-1 mt-2 pt-2 border-t border-bambu-dark-tertiary`,children:Wn.results.filter(e=>!e.success).map(e=>(0,G.jsxs)(`div`,{className:`text-xs text-red-700 dark:text-red-400`,children:[(0,G.jsxs)(`span`,{className:`font-medium`,children:[e.provider_name,`:`]}),` `,e.message]},e.provider_id))})]})}),Ut?(0,G.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,G.jsx)(Y,{className:`w-6 h-6 text-bambu-green animate-spin`})}):Ht&&Ht.length>0?(0,G.jsx)(`div`,{className:`space-y-3`,children:Ht.map(e=>(0,G.jsx)(FVe,{provider:e,onEdit:e=>{re(e),te(!0)}},e.id))}):(0,G.jsx)(Md,{children:(0,G.jsx)(Pd,{className:`py-8`,children:(0,G.jsxs)(`div`,{className:`text-center text-bambu-gray`,children:[(0,G.jsx)(Go,{className:`w-12 h-12 mx-auto mb-3 opacity-30`}),(0,G.jsx)(`p`,{className:`text-sm font-medium text-white mb-2`,children:i(`settings.noProvidersTitle`)}),(0,G.jsx)(`p`,{className:`text-xs mb-3`,children:i(`settings.noProvidersDescription`)}),(0,G.jsxs)(Q,{size:`sm`,onClick:()=>{re(null),te(!0)},children:[(0,G.jsx)(Ml,{className:`w-4 h-4`}),i(`settings.addProvider`)]})]})})})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2 mb-2`,id:`card-templates`,children:[(0,G.jsx)(lc,{className:`w-5 h-5 text-bambu-green`}),i(`settings.messageTemplates`)]}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mb-3`,children:i(`settings.messageTemplatesDescription`)}),(0,G.jsxs)(`div`,{className:`relative mb-3`,children:[(0,G.jsx)(Yl,{className:`w-4 h-4 text-bambu-gray absolute left-3 top-1/2 -translate-y-1/2 pointer-events-none`}),(0,G.jsx)(`input`,{type:`text`,value:oe,onChange:e=>se(e.target.value),placeholder:i(`settings.filterTemplates`,`Filter templates…`),className:`w-full pl-9 pr-8 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`}),oe&&(0,G.jsx)(`button`,{onClick:()=>se(``),className:`absolute right-2 top-1/2 -translate-y-1/2 p-1 text-bambu-gray hover:text-white`,"aria-label":`Clear filter`,children:(0,G.jsx)($u,{className:`w-3.5 h-3.5`})})]}),Qt?(0,G.jsx)(`div`,{className:`flex justify-center py-8`,children:(0,G.jsx)(Y,{className:`w-6 h-6 text-bambu-green animate-spin`})}):Zt&&Zt.length>0?(()=>{let e=oe.trim().toLowerCase(),t=[...Zt].sort((e,t)=>e.name.localeCompare(t.name)).filter(t=>!e||t.name.toLowerCase().includes(e)||(t.title_template||``).toLowerCase().includes(e));return t.length===0?(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray italic text-center py-6`,children:i(`settings.noTemplatesMatch`,`No templates match your filter.`)}):(0,G.jsx)(`div`,{className:`space-y-2`,children:t.map(e=>(0,G.jsx)(Md,{className:`cursor-pointer hover:border-bambu-green/50 transition-colors`,onClick:()=>ae(e),children:(0,G.jsx)(Pd,{className:`py-2.5 px-3`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,G.jsx)(`p`,{className:`text-white font-medium text-sm truncate`,children:e.name}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-xs truncate mt-0.5`,children:e.title_template})]}),(0,G.jsx)(`button`,{className:`p-1.5 hover:bg-bambu-dark-tertiary rounded transition-colors shrink-0 ml-2`,onClick:t=>{t.stopPropagation(),ae(e)},children:(0,G.jsx)(Dl,{className:`w-4 h-4 text-bambu-gray`})})]})})},e.id))})})():(0,G.jsx)(Md,{children:(0,G.jsx)(Pd,{className:`py-8`,children:(0,G.jsxs)(`div`,{className:`text-center text-bambu-gray`,children:[(0,G.jsx)(lc,{className:`w-12 h-12 mx-auto mb-3 opacity-30`}),(0,G.jsx)(`p`,{className:`text-sm`,children:i(`settings.noTemplatesAvailable`)})]})})})]})]}),ye===`apikeys`&&(0,G.jsxs)(`div`,{className:d(`api_keys:read`)?`grid grid-cols-1 xl:grid-cols-2 gap-4`:`grid grid-cols-1 gap-4`,children:[(0,G.jsxs)(`div`,{children:[d(`api_keys:read`)&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`flex items-start justify-between gap-4 mb-6`,children:[(0,G.jsxs)(`div`,{className:`flex-1`,children:[(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,id:`card-createapi`,children:[(0,G.jsx)(Uc,{className:`w-5 h-5 text-bambu-green`}),i(`settings.apiKeys`)]}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:i(`settings.apiKeysDescription`)})]}),(0,G.jsxs)(Q,{size:`sm`,onClick:()=>Oe(!0),className:`flex-shrink-0`,children:[(0,G.jsx)(Ml,{className:`w-4 h-4`}),i(`settings.createKey`)]})]}),Ne&&(0,G.jsx)(Md,{className:`mb-6 border-bambu-green`,children:(0,G.jsx)(Pd,{className:`py-4`,children:(0,G.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,G.jsx)(ys,{className:`w-5 h-5 text-bambu-green flex-shrink-0 mt-0.5`}),(0,G.jsxs)(`div`,{className:`flex-1`,children:[(0,G.jsx)(`p`,{className:`text-white font-medium mb-1`,children:i(`settings.apiKeyCreated`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mb-2`,children:i(`settings.apiKeyCopyWarning`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 bg-bambu-dark rounded-lg p-2`,children:[(0,G.jsx)(`code`,{className:`flex-1 text-sm text-bambu-green font-mono break-all`,children:Ne}),(0,G.jsx)(Q,{variant:`secondary`,size:`sm`,onClick:async()=>{try{if(navigator.clipboard&&navigator.clipboard.writeText)await navigator.clipboard.writeText(Ne);else{let e=document.createElement(`textarea`);e.value=Ne,e.style.position=`fixed`,e.style.left=`-999999px`,document.body.appendChild(e),e.select(),document.execCommand(`copy`),document.body.removeChild(e)}o(i(`settings.toast.keyCopied`))}catch{o(i(`settings.toast.copyFailed`),`error`)}},children:(0,G.jsx)(zs,{className:`w-4 h-4`})})]}),(0,G.jsxs)(`div`,{className:`flex gap-2 mt-3`,children:[(0,G.jsx)(Q,{variant:`secondary`,size:`sm`,onClick:()=>{Be(Ne),o(i(`settings.toast.keyAddedToBrowser`))},children:i(`settings.useInApiBrowser`)}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:()=>Ie(!0),children:[(0,G.jsx)(Il,{className:`w-4 h-4`}),i(`settings.apiKeyQrButton`)]}),(0,G.jsx)(Q,{variant:`secondary`,size:`sm`,onClick:()=>{Ie(!1),Pe(null)},children:i(`common.dismiss`)})]})]})]})})}),Fe&&Ne&&(0,G.jsx)(QVe,{apiKey:Ne,baseUrl:A?.external_url||void 0,onClose:()=>Ie(!1)}),De&&(0,G.jsxs)(Md,{className:`mb-6`,children:[(0,G.jsx)(Nd,{children:(0,G.jsx)(`h3`,{className:`text-base font-semibold text-white`,children:i(`settings.createNewApiKey`)})}),(0,G.jsxs)(Pd,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.keyName`)}),(0,G.jsx)(`input`,{type:`text`,value:ke,onChange:e=>Ae(e.target.value),placeholder:i(`settings.keyNamePlaceholder`),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-2`,children:i(`common.permissions`)}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:je.can_read_status,onChange:e=>Me(t=>({...t,can_read_status:e.target.checked})),className:`w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-white`,children:i(`settings.readStatus`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.readStatusDescription`)})]})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:je.can_queue,onChange:e=>Me(t=>({...t,can_queue:e.target.checked})),className:`w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-white`,children:i(`settings.manageQueue`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.manageQueueDescription`)})]})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:je.can_control_printer,onChange:e=>Me(t=>({...t,can_control_printer:e.target.checked})),className:`w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-white`,children:i(`settings.controlPrinter`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.controlPrinterDescription`)})]})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:je.can_manage_library,onChange:e=>Me(t=>({...t,can_manage_library:e.target.checked})),className:`w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-white`,children:i(`settings.manageLibrary`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.manageLibraryDescription`)})]})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:je.can_manage_inventory,onChange:e=>Me(t=>({...t,can_manage_inventory:e.target.checked})),className:`w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-white`,children:i(`settings.manageInventory`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.manageInventoryDescription`)})]})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:je.can_manage_maintenance,onChange:e=>Me(t=>({...t,can_manage_maintenance:e.target.checked})),className:`w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-white`,children:i(`settings.manageMaintenance`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.manageMaintenanceDescription`)})]})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:je.can_manage_archives,onChange:e=>Me(t=>({...t,can_manage_archives:e.target.checked})),className:`w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-white`,children:i(`settings.manageArchives`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.manageArchivesDescription`)})]})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:je.can_manage_projects,onChange:e=>Me(t=>({...t,can_manage_projects:e.target.checked})),className:`w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-white`,children:i(`settings.manageProjects`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.manageProjectsDescription`)})]})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:je.can_access_cloud,onChange:e=>Me(t=>({...t,can_access_cloud:e.target.checked})),className:`w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-white`,children:i(`settings.cloudAccess`,`Allow cloud access`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.cloudAccessDescription`,`Read Bambu Cloud presets and filaments on your behalf. Requires you to be signed into Bambu Cloud.`)})]})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:je.can_update_energy_cost,onChange:e=>Me(t=>({...t,can_update_energy_cost:e.target.checked})),className:`w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-white`,children:i(`settings.updateEnergyCost`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.updateEnergyCostDescription`)})]})]})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 pt-2`,children:[(0,G.jsxs)(Q,{onClick:()=>Kt.mutate({name:ke||i(`settings.unnamedKey`),...je}),disabled:Kt.isPending,children:[Kt.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Ml,{className:`w-4 h-4`}),i(`settings.createKey`)]}),(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>Oe(!1),children:i(`common.cancel`)})]})]})]}),Gt?(0,G.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,G.jsx)(Y,{className:`w-8 h-8 text-bambu-green animate-spin`})}):Wt&&Wt.length>0?(0,G.jsx)(`div`,{className:`space-y-3`,children:Wt.map(e=>(0,G.jsx)(Md,{children:(0,G.jsx)(Pd,{className:`py-3`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(Uc,{className:`w-5 h-5 ${e.enabled?`text-bambu-green`:`text-bambu-gray`}`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white font-medium`,children:e.name}),(0,G.jsxs)(`p`,{className:`text-xs text-bambu-gray`,children:[e.key_prefix,`••••••••`,e.last_used&&` · ${i(`settings.lastUsed`)}: ${Jf(e.last_used)}`]})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`div`,{className:`flex gap-1 text-xs flex-wrap justify-end`,children:[e.can_read_status&&(0,G.jsx)(`span`,{className:`px-1.5 py-0.5 bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400 rounded`,children:i(`settings.read`)}),e.can_queue&&(0,G.jsx)(`span`,{className:`px-1.5 py-0.5 bg-green-100 dark:bg-green-500/20 text-green-700 dark:text-green-400 rounded`,children:i(`queue.title`)}),e.can_control_printer&&(0,G.jsx)(`span`,{className:`px-1.5 py-0.5 bg-orange-100 dark:bg-orange-500/20 text-orange-700 dark:text-orange-400 rounded`,children:i(`settings.control`)}),e.can_manage_library&&(0,G.jsx)(`span`,{className:`px-1.5 py-0.5 bg-cyan-100 dark:bg-cyan-500/20 text-cyan-700 dark:text-cyan-400 rounded`,children:i(`settings.libraryBadge`)}),e.can_manage_inventory&&(0,G.jsx)(`span`,{className:`px-1.5 py-0.5 bg-pink-100 dark:bg-pink-500/20 text-pink-700 dark:text-pink-400 rounded`,children:i(`settings.inventoryBadge`)}),e.can_manage_maintenance&&(0,G.jsx)(`span`,{className:`px-1.5 py-0.5 bg-teal-100 dark:bg-teal-500/20 text-teal-700 dark:text-teal-400 rounded`,children:i(`settings.maintenanceBadge`)}),e.can_manage_archives&&(0,G.jsx)(`span`,{className:`px-1.5 py-0.5 bg-indigo-100 dark:bg-indigo-500/20 text-indigo-700 dark:text-indigo-400 rounded`,children:i(`settings.archivesBadge`)}),e.can_manage_projects&&(0,G.jsx)(`span`,{className:`px-1.5 py-0.5 bg-lime-100 dark:bg-lime-500/20 text-lime-700 dark:text-lime-400 rounded`,children:i(`settings.projectsBadge`)}),e.can_access_cloud&&(0,G.jsx)(`span`,{className:`px-1.5 py-0.5 bg-purple-100 dark:bg-purple-500/20 text-purple-700 dark:text-purple-400 rounded`,children:i(`settings.cloudBadge`,`Cloud`)}),e.can_update_energy_cost&&(0,G.jsx)(`span`,{className:`px-1.5 py-0.5 bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-400 rounded`,children:i(`settings.energyCostBadge`)}),e.user_id===null&&(0,G.jsx)(`span`,{className:`px-1.5 py-0.5 bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400 rounded`,title:i(`settings.legacyKeyTooltip`,`Created before per-user ownership; recreate to use cloud access`),children:i(`settings.legacyKey`,`Legacy`)})]}),(0,G.jsx)(Q,{variant:`secondary`,size:`sm`,onClick:()=>Re(e.id),children:(0,G.jsx)(ju,{className:`w-4 h-4 text-red-600 dark:text-red-400`})})]})]})})},e.id))}):(0,G.jsx)(Md,{children:(0,G.jsx)(Pd,{className:`py-12`,children:(0,G.jsxs)(`div`,{className:`text-center text-bambu-gray`,children:[(0,G.jsx)(Uc,{className:`w-16 h-16 mx-auto mb-4 opacity-30`}),(0,G.jsx)(`p`,{className:`text-lg font-medium text-white mb-2`,children:i(`settings.apiKeysEmptyTitle`)}),(0,G.jsx)(`p`,{className:`text-sm mb-4`,children:i(`settings.apiKeysEmptyDescription`)}),(0,G.jsxs)(Q,{onClick:()=>Oe(!0),children:[(0,G.jsx)(Ml,{className:`w-4 h-4`}),i(`settings.createFirstKey`)]})]})})}),(0,G.jsxs)(Md,{className:`mt-6`,children:[(0,G.jsx)(Nd,{children:(0,G.jsx)(`h3`,{className:`text-base font-semibold text-white`,id:`card-webhooks`,children:i(`settings.webhookEndpoints`)})}),(0,G.jsxs)(Pd,{className:`space-y-3 text-sm`,children:[(0,G.jsx)(`p`,{className:`text-bambu-gray`,children:i(`settings.webhookApiKeyHint`)}),(0,G.jsxs)(`div`,{className:`space-y-2 font-mono text-xs`,children:[(0,G.jsxs)(`div`,{className:`p-2 bg-bambu-dark rounded`,children:[(0,G.jsx)(`span`,{className:`text-blue-700 dark:text-blue-400`,children:`GET`}),` `,(0,G.jsx)(`span`,{className:`text-white`,children:`/api/v1/webhook/status`}),(0,G.jsxs)(`span`,{className:`text-bambu-gray`,children:[` - `,i(`settings.webhook.getAllStatus`)]})]}),(0,G.jsxs)(`div`,{className:`p-2 bg-bambu-dark rounded`,children:[(0,G.jsx)(`span`,{className:`text-blue-700 dark:text-blue-400`,children:`GET`}),` `,(0,G.jsx)(`span`,{className:`text-white`,children:`/api/v1/webhook/status/:id`}),(0,G.jsxs)(`span`,{className:`text-bambu-gray`,children:[` - `,i(`settings.webhook.getSpecificStatus`)]})]}),(0,G.jsxs)(`div`,{className:`p-2 bg-bambu-dark rounded`,children:[(0,G.jsx)(`span`,{className:`text-green-700 dark:text-green-400`,children:`POST`}),` `,(0,G.jsx)(`span`,{className:`text-white`,children:`/api/v1/webhook/queue`}),(0,G.jsxs)(`span`,{className:`text-bambu-gray`,children:[` - `,i(`settings.webhook.addToQueue`)]})]}),(0,G.jsxs)(`div`,{className:`p-2 bg-bambu-dark rounded`,children:[(0,G.jsx)(`span`,{className:`text-orange-700 dark:text-orange-400`,children:`POST`}),` `,(0,G.jsx)(`span`,{className:`text-white`,children:`/api/v1/webhook/printer/:id/pause`}),(0,G.jsxs)(`span`,{className:`text-bambu-gray`,children:[` - `,i(`settings.webhook.pausePrint`)]})]}),(0,G.jsxs)(`div`,{className:`p-2 bg-bambu-dark rounded`,children:[(0,G.jsx)(`span`,{className:`text-orange-700 dark:text-orange-400`,children:`POST`}),` `,(0,G.jsx)(`span`,{className:`text-white`,children:`/api/v1/webhook/printer/:id/resume`}),(0,G.jsxs)(`span`,{className:`text-bambu-gray`,children:[` - `,i(`settings.webhook.resumePrint`)]})]}),(0,G.jsxs)(`div`,{className:`p-2 bg-bambu-dark rounded`,children:[(0,G.jsx)(`span`,{className:`text-red-700 dark:text-red-400`,children:`POST`}),` `,(0,G.jsx)(`span`,{className:`text-white`,children:`/api/v1/webhook/printer/:id/stop`}),(0,G.jsxs)(`span`,{className:`text-bambu-gray`,children:[` - `,i(`settings.webhook.stopPrint`)]})]})]})]})]})]}),(0,G.jsxs)(Md,{className:`mt-6`,children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,id:`card-camera-tokens`,children:[(0,G.jsx)(Hu,{className:`w-4 h-4 text-bambu-green`}),i(`cameraTokens.title`,`Camera API Tokens`)]})}),(0,G.jsx)(Pd,{children:(0,G.jsx)(OVe,{})})]}),(0,G.jsxs)(Md,{className:`mt-6`,children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,id:`card-stream-overlay`,children:[(0,G.jsx)(pl,{className:`w-4 h-4 text-bambu-green`}),i(`streamOverlay.builder.title`,`Streaming Overlay`)]})}),(0,G.jsx)(Pd,{children:(0,G.jsx)(AVe,{})})]})]}),d(`api_keys:read`)&&(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`mb-6`,children:[(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,id:`card-apibrowser`,children:[(0,G.jsx)(Dc,{className:`w-5 h-5 text-bambu-green`}),i(`settings.apiBrowser`)]}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:i(`settings.apiBrowserDescription`)})]}),(0,G.jsx)(Md,{className:`mb-4`,children:(0,G.jsxs)(Pd,{className:`py-3`,children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-2`,children:i(`settings.apiKeyForTesting`)}),(0,G.jsx)(`input`,{type:`text`,value:ze,onChange:e=>Be(e.target.value),placeholder:i(`settings.apiKeyPlaceholder`),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white font-mono text-sm focus:border-bambu-green focus:outline-none`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-2`,children:i(`settings.apiKeyHint`)})]})}),(0,G.jsx)(KHe,{apiKey:ze})]})]}),ye===`virtual-printer`&&(0,G.jsx)(`div`,{id:`card-vp`,children:(0,G.jsx)(xHe,{})}),ye===`spoolbuddy`&&(0,G.jsx)(`div`,{id:`card-spoolbuddy`,children:(0,G.jsx)(CHe,{})}),ye===`queue`&&(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{className:`flex gap-1 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`button`,{onClick:()=>Ee(`dispatch`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${Ce===`dispatch`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,G.jsx)(Xc,{className:`w-4 h-4`}),i(`settings.tabs.queueDispatch`,`Queue & Dispatch`)]}),(0,G.jsxs)(`button`,{onClick:()=>Ee(`pipelines`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${Ce===`pipelines`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,G.jsx)(Zu,{className:`w-4 h-4`}),i(`settings.tabs.queuePipelines`,`Pipelines`)]})]}),Ce===`pipelines`&&(0,G.jsx)(bVe,{}),Ce===`dispatch`&&A&&(0,G.jsxs)(`div`,{className:`flex flex-col lg:flex-row gap-4 lg:gap-6`,children:[(0,G.jsxs)(`div`,{className:`lg:w-1/2 space-y-3`,children:[(0,G.jsxs)(Md,{id:`card-print-options`,children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(Xc,{className:`w-4 h-4 text-bambu-green`}),i(`settings.defaultPrintOptions`,`Default Print Options`)]})}),(0,G.jsxs)(Pd,{className:`space-y-3`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.defaultPrintOptionsDescription`,`Set default values for print options when starting new prints. These can be overridden per print in the print dialog.`)}),[{key:`default_bed_levelling`,label:i(`settings.defaultBedLevelling`,`Bed Levelling`),desc:i(`settings.defaultBedLevellingDesc`,`Auto-level bed before print`),fallback:!0,dualNozzleOnly:!1,tristate:!0},{key:`default_flow_cali`,label:i(`settings.defaultFlowCali`,`Flow Calibration`),desc:i(`settings.defaultFlowCaliDesc`,`Calibrate extrusion flow`),fallback:!1,dualNozzleOnly:!1,tristate:!0},{key:`default_vibration_cali`,label:i(`settings.defaultVibrationCali`,`Vibration Calibration`),desc:i(`settings.defaultVibrationCaliDesc`,`Reduce ringing artifacts`),fallback:!0,dualNozzleOnly:!1,tristate:!1},{key:`default_layer_inspect`,label:i(`settings.defaultLayerInspect`,`First Layer Inspection`),desc:i(`settings.defaultLayerInspectDesc`,`AI inspection of first layer`),fallback:!1,dualNozzleOnly:!1,tristate:!1},{key:`default_timelapse`,label:i(`settings.defaultTimelapse`,`Timelapse`),desc:i(`settings.defaultTimelapseDesc`,`Record timelapse video`),fallback:!1,dualNozzleOnly:!1,tristate:!1},{key:`default_nozzle_offset_cali`,label:i(`settings.defaultNozzleOffsetCali`,`Nozzle Offset Calibration`),desc:i(`settings.defaultNozzleOffsetCaliDesc`,`Calibrate nozzle offsets between extruders`),fallback:!0,dualNozzleOnly:!0,tristate:!0}].filter(({dualNozzleOnly:e})=>!e||(Jt||[]).some(e=>e.nozzle_count===2)).map(({key:e,label:t,desc:n,fallback:r,tristate:a})=>(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex-1 mr-4`,children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:t}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:n})]}),a?(0,G.jsx)(`div`,{className:`flex gap-1 shrink-0`,children:JU.map(t=>(0,G.jsx)(`button`,{type:`button`,onClick:()=>tr(e,t),className:`px-2.5 py-1 text-xs rounded transition-colors ${(A[e]??`auto`)===t?YU[t]:`bg-bambu-dark-tertiary text-bambu-gray hover:text-white`}`,children:i(`settings.calibrationMode_${t}`)},t))}):(0,G.jsx)(`div`,{className:`flex gap-1 shrink-0`,children:[`off`,`on`].map(t=>(0,G.jsx)(`button`,{type:`button`,onClick:()=>tr(e,t===`on`),className:`px-2.5 py-1 text-xs rounded transition-colors ${(A[e]??r?`on`:`off`)===t?YU[t]:`bg-bambu-dark-tertiary text-bambu-gray hover:text-white`}`,children:i(`settings.calibrationMode_${t}`)},t))})]},e))]})]}),(0,G.jsxs)(Md,{id:`card-plate`,children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(iu,{className:`w-4 h-4 text-bambu-green`}),i(`settings.plateClear`,`Plate-Clear Confirmation`)]})}),(0,G.jsx)(Pd,{className:`space-y-3`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex-1 mr-4`,children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:i(`settings.requirePlateClear`,`Require plate-clear confirmation`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.requirePlateClearDescription`,`When enabled, the scheduler waits for per-printer plate-clear confirmation before starting queued prints on printers with finished jobs. Disabling this also hides the plate status badge and the "Mark plate as cleared" button on printer cards.`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.require_plate_clear??!1,onChange:e=>tr(`require_plate_clear`,e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]})})]}),(0,G.jsxs)(Md,{id:`card-temp-fan-presets`,children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(ku,{className:`w-4 h-4 text-bambu-green`}),i(`settings.tempFanPresetsTitle`,`Temperature & Fan Presets`)]})}),(0,G.jsxs)(Pd,{className:`space-y-4`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.tempFanPresetsDescription`,`Customize the quick-select values shown in printer-card temperature and fan-speed popovers. The Off button is always shown.`)}),hee.map(e=>{let t=pm(A?.[e.key]??``,e.defaults,e.lo,e.hi),n=e.unit===`C`?`°C`:`%`;return(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-1`,children:[(0,G.jsxs)(`label`,{className:`text-sm text-white`,children:[i(`settings.${{nozzle_temp_presets:`tempFanPresetsNozzle`,bed_temp_presets:`tempFanPresetsBed`,chamber_temp_presets:`tempFanPresetsChamber`,fan_speed_presets:`tempFanPresetsFan`}[e.key]}`,{nozzle_temp_presets:`Nozzle temperature`,bed_temp_presets:`Bed temperature`,chamber_temp_presets:`Chamber temperature`,fan_speed_presets:`Fan speed`}[e.key]),` `,(0,G.jsxs)(`span`,{className:`text-bambu-gray text-xs`,children:[`(`,n,` · `,e.lo,`–`,e.hi,`)`]})]}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>tr(e.key,``),title:i(`settings.tempFanPresetsReset`,`Reset to defaults`),className:`text-bambu-gray hover:text-white transition-colors p-1 rounded hover:bg-bambu-dark-tertiary`,children:(0,G.jsx)(Vl,{className:`w-3.5 h-3.5`})})]}),(0,G.jsx)(`div`,{className:`flex gap-2`,children:[0,1,2].map(n=>(0,G.jsx)(`input`,{type:`number`,min:e.lo,max:e.hi,value:t[n],onChange:r=>{let i=[t[0],t[1],t[2]],a=parseInt(r.target.value,10);i[n]=Math.max(e.lo,Math.min(e.hi,Number.isFinite(a)?a:e.lo)),tr(e.key,JSON.stringify(i))},className:`flex-1 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`},n))})]},e.key)})]})]}),(0,G.jsxs)(Md,{id:`card-staggered`,children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(Gc,{className:`w-4 h-4 text-bambu-green`}),i(`settings.staggeredStart`,`Staggered Start`)]})}),(0,G.jsxs)(Pd,{className:`space-y-3`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.staggeredStartDescription`,`Default group size and interval when staggering multi-printer batch starts. Can be overridden per batch in the print modal.`)}),(0,G.jsxs)(`div`,{className:`flex gap-4`,children:[(0,G.jsxs)(`div`,{className:`flex-1`,children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.staggerGroupSize`,`Group size`)}),(0,G.jsx)(`input`,{type:`number`,min:1,max:50,value:A.stagger_group_size??2,onChange:e=>tr(`stagger_group_size`,Math.max(1,Math.min(50,parseInt(e.target.value)||1))),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.staggerGroupSizeHelp`,`Printers to start simultaneously per group`)})]}),(0,G.jsxs)(`div`,{className:`flex-1`,children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.staggerInterval`,`Interval (minutes)`)}),(0,G.jsx)(`input`,{type:`number`,min:1,max:60,value:A.stagger_interval_minutes??5,onChange:e=>tr(`stagger_interval_minutes`,Math.max(1,Math.min(60,parseInt(e.target.value)||1))),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.staggerIntervalHelp`,`Delay between each group starting`)})]})]})]})]}),(0,G.jsxs)(Md,{id:`card-concurrent-uploads`,children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(js,{className:`w-4 h-4 text-bambu-green`}),i(`settings.concurrentUploadsTitle`,`Concurrent Uploads`)]})}),(0,G.jsxs)(Pd,{className:`space-y-3`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.concurrentUploadsDescription`,`How many printers the queue may send files to at the same time. Printers receive files slowly (a large print can take several minutes), and each one waits its turn — so on a bigger fleet, raising this is what stops the last printer in a batch from waiting out every transfer before it. Lower it if your network or Bambuddy host struggles with parallel transfers.`)}),(0,G.jsxs)(`div`,{className:`w-full sm:w-1/2`,children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.concurrentUploadsLabel`,`Printers uploaded to at once`)}),(0,G.jsx)(`input`,{type:`number`,min:1,max:16,value:A.queue_max_concurrent_uploads??4,onChange:e=>tr(`queue_max_concurrent_uploads`,Math.max(1,Math.min(16,parseInt(e.target.value)||1))),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.concurrentUploadsHelp`,`1 sends to one printer at a time (the old behaviour). Default is 4.`)})]})]})]}),(0,G.jsxs)(Md,{id:`card-preheat`,children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(fc,{className:`w-4 h-4 text-amber-600 dark:text-amber-400`}),i(`settings.preheatTitle`,`Preheat & Heat Soak`)]})}),(0,G.jsxs)(Pd,{className:`space-y-3`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.preheatDescription`,`Heat the bed (and chamber, if supported) and hold at temperature before each queued print starts. Helpful for engineering filaments (PA, ABS) on printers without an active chamber heater — the bed warms the chamber by radiation while the soak timer runs. The bed target is read from the print file; chamber behaviour depends on printer model.`)}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex-1 mr-4`,children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:i(`settings.preheatEnabled`,`Enable preheat & soak`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:i(`settings.preheatEnabledDesc`,`When off, queued prints dispatch immediately.`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.preheat_enabled??!1,onChange:e=>tr(`preheat_enabled`,e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3 pt-1`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.preheatMaxWait`,`Max wait (seconds)`)}),(0,G.jsx)(`input`,{type:`number`,min:60,max:3600,value:A.preheat_max_wait_seconds??900,onChange:e=>tr(`preheat_max_wait_seconds`,Math.max(60,Math.min(3600,parseInt(e.target.value)||900))),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 disabled:opacity-50`,disabled:!(A.preheat_enabled??!1)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.preheatMaxWaitHelp`,`Cap on the chamber warm-up phase before falling through.`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.preheatSoak`,`Soak (seconds)`)}),(0,G.jsx)(`input`,{type:`number`,min:0,max:1800,value:A.preheat_soak_seconds??300,onChange:e=>tr(`preheat_soak_seconds`,Math.max(0,Math.min(1800,parseInt(e.target.value)||0))),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 disabled:opacity-50`,disabled:!(A.preheat_enabled??!1)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.preheatSoakHelp`,`Hold time after target reached or max-wait elapsed.`)})]})]}),(0,G.jsxs)(`div`,{className:`pt-2 border-t border-bambu-dark-tertiary/50`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-1`,children:[(0,G.jsx)(`label`,{className:`text-sm text-white`,children:i(`settings.preheatFilamentTargetsLabel`,`Per-filament chamber target (°C)`)}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>tr(`preheat_filament_targets`,``),title:i(`settings.preheatFilamentTargetsReset`,`Reset to defaults`),className:`text-bambu-gray hover:text-white transition-colors p-1 rounded hover:bg-bambu-dark-tertiary`,children:(0,G.jsx)(Vl,{className:`w-3.5 h-3.5`})})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:i(`settings.preheatFilamentTargetsHint`,`Bambuddy picks the highest target across the loaded AMS slots; PLA-only prints derive 0 and skip the chamber phase automatically.`)}),(0,G.jsx)(_Ve,{value:A.preheat_filament_targets??``,onChange:e=>tr(`preheat_filament_targets`,e),disabled:!(A.preheat_enabled??!1)})]}),(0,G.jsxs)(`p`,{className:`text-xs text-bambu-gray pt-1 border-t border-bambu-dark-tertiary/50`,children:[(0,G.jsx)(`span`,{className:`font-medium text-bambu-gray/90`,children:i(`settings.preheatHardwareTitle`,`Per-printer behaviour:`)}),` `,i(`settings.preheatHardwareDetail`,`H2C/H2D/H2D Pro/H2S/X2D/X1E actively heat the chamber via M141. X1C/P2S read chamber temp but rely on bed-radiation heating. P1S/P1P/A1/A1 Mini have no chamber sensor — only the soak timer applies.`)]})]})]}),(0,G.jsxs)(Md,{id:`card-gcode`,children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(Ns,{className:`w-4 h-4 text-bambu-green`}),i(`settings.gcodeInjection`,`G-code Injection`)]})}),(0,G.jsxs)(Pd,{className:`space-y-3`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.gcodeInjectionDescription`,`Configure custom G-code to inject at the start and/or end of prints for auto-print systems like Farmloop, SwapMod, AutoClear, and Printflow 3D. Snippets are configured per printer model and applied when "Inject G-code" is enabled on a queue item.`)}),(()=>{let e=(()=>{try{return A.gcode_snippets?JSON.parse(A.gcode_snippets):{}}catch{return{}}})(),t=[...new Set((Jt||[]).filter(e=>e.model).map(e=>e.model))].sort(),n=(t,n,r)=>{let i={...e};i[t]||(i[t]={start_gcode:``,end_gcode:``}),i[t][n]=r,!i[t].start_gcode&&!i[t].end_gcode&&delete i[t];let a=Object.keys(i).length>0?JSON.stringify(i):``;j(e=>e?{...e,gcode_snippets:a}:null),Yn.current=a},r=()=>{Yn.current!==null&&($n.mutate({gcode_snippets:Yn.current}),Yn.current=null)};return t.length===0?(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray italic`,children:i(`settings.gcodeInjectionNoPrinters`,`No printers found. Add printers to configure G-code snippets.`)}):t.map(t=>{let a=e[t]||{start_gcode:``,end_gcode:``},o=!!(a.start_gcode||a.end_gcode);return(0,G.jsx)(Vp,{defaultOpen:o,className:`border border-bambu-dark-tertiary rounded-lg px-3 py-2`,summary:(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`h4`,{className:`text-sm font-medium text-white`,children:t}),o&&(0,G.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-bambu-green/20 text-bambu-green`,children:i(`settings.gcodeConfigured`,`Configured`)})]}),children:(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.gcodeStartLabel`,`Start G-code`)}),(0,G.jsx)(`textarea`,{value:a.start_gcode,onChange:e=>n(t,`start_gcode`,e.target.value),onBlur:r,placeholder:i(`settings.gcodeStartPlaceholder`,`G-code prepended before the print starts...`),rows:3,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-xs font-mono focus:outline-none focus:border-bambu-green resize-y`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs text-bambu-gray mb-1`,children:i(`settings.gcodeEndLabel`,`End G-code`)}),(0,G.jsx)(`textarea`,{value:a.end_gcode,onChange:e=>n(t,`end_gcode`,e.target.value),onBlur:r,placeholder:i(`settings.gcodeEndPlaceholder`,`G-code appended after the print ends...`),rows:3,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-xs font-mono focus:outline-none focus:border-bambu-green resize-y`})]})]})},t)})})()]})]})]}),(0,G.jsxs)(`div`,{className:`lg:w-1/2 space-y-3`,children:[(0,G.jsxs)(Md,{id:`card-pipelines`,children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(Zu,{className:`w-4 h-4 text-bambu-green`}),i(`settings.pipelineLimits.title`,`Slicer Pipeline limits`)]})}),(0,G.jsx)(Pd,{className:`space-y-2`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,G.jsxs)(`div`,{className:`flex-1`,children:[(0,G.jsx)(`p`,{className:`text-sm text-white`,children:i(`settings.pipelineLimits.maxCopiesLabel`,`Max copies per run`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:i(`settings.pipelineLimits.maxCopiesDesc`,`Upper bound on the copies operators can request when running a pipeline. Server-side hard cap is 1000.`)})]}),(0,G.jsx)(`input`,{type:`number`,min:1,max:1e3,value:A.pipeline_max_copies??50,onChange:e=>{let t=parseInt(e.target.value,10);Number.isNaN(t)||tr(`pipeline_max_copies`,Math.max(1,Math.min(1e3,t)))},"aria-label":i(`settings.pipelineLimits.maxCopiesLabel`,`Max copies per run`),className:`w-24 px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm`})]})})]}),(0,G.jsxs)(Md,{id:`card-slicer`,children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(Is,{className:`w-4 h-4 text-bambu-green`}),i(`settings.slicerCard`,`Slicer`)]})}),(0,G.jsxs)(Pd,{className:`space-y-3`,children:[JHe()&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.sliceEngine`)}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(`select`,{value:L6(A.slice_engine),onChange:e=>tr(`slice_engine`,e.target.value),className:`w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer`,children:I6().map(e=>(0,G.jsx)(`option`,{value:e.id,children:i(e.labelKey)},e.id))}),(0,G.jsx)(ds,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(I6().find(e=>e.id===L6(A.slice_engine))?.descriptionKey??`settings.sliceEngineSidecarHint`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.preferredSlicer`)}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsxs)(`select`,{value:A.preferred_slicer??`bambu_studio`,onChange:e=>tr(`preferred_slicer`,e.target.value),className:`w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer`,children:[(0,G.jsx)(`option`,{value:`bambu_studio`,children:i(`settings.slicerBambuStudio`)}),(0,G.jsx)(`option`,{value:`orcaslicer`,children:i(`settings.slicerOrcaSlicer`)})]}),(0,G.jsx)(ds,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.preferredSlicerDescription`)}),(A.preferred_slicer??`bambu_studio`)===`orcaslicer`&&(0,G.jsx)(`div`,{role:`alert`,className:`text-xs text-amber-800 dark:text-amber-200 bg-amber-50 dark:bg-amber-900/20 border border-amber-300 dark:border-amber-700/40 rounded p-2 mt-2`,children:i(`settings.orcaslicerKnownIssuesWarning`,`OrcaSlicer 2.3.2 / 2.4.0-dev have known CLI bugs that block slicing many Bambu-authored 3MFs — see upstream issues #12426 (segfault on painted multi-extruder files) and #13386 (parameter-range strict-validation reject). Bambu Studio is recommended until the upstream fixes land.`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.openInSlicerLabel`,`Open in Slicer`)}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsxs)(`select`,{value:A.open_in_slicer??``,onChange:e=>tr(`open_in_slicer`,e.target.value===``?null:e.target.value),className:`w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer`,children:[(0,G.jsx)(`option`,{value:``,children:i(`settings.openInSlicerInherit`,`Same as API slicer`)}),(0,G.jsx)(`option`,{value:`bambu_studio`,children:i(`settings.slicerBambuStudio`)}),(0,G.jsx)(`option`,{value:`orcaslicer`,children:i(`settings.slicerOrcaSlicer`)})]}),(0,G.jsx)(ds,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.openInSlicerDescription`,`Desktop slicer used by the 'Open in Slicer' button. Leave on 'Same as API slicer' to inherit, or pick a different slicer to use locally.`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.useSlicerApi`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.useSlicerApiDescription`)})]}),(0,G.jsxs)(`label`,{className:`flex items-center cursor-pointer shrink-0`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.use_slicer_api??!1,onChange:e=>tr(`use_slicer_api`,e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`relative w-11 h-6 bg-bambu-dark-tertiary rounded-full peer peer-checked:bg-bambu-green peer-focus:outline-none peer-focus:ring-2 peer-focus:ring-bambu-green/50 transition-colors after:content-[''] after:absolute after:top-0.5 after:left-0.5 after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-transform peer-checked:after:translate-x-5`})]})]}),(A.use_slicer_api??!1)&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:(A.preferred_slicer??`bambu_studio`)===`orcaslicer`?i(`settings.orcaslicerApiUrl`,`OrcaSlicer sidecar URL`):i(`settings.bambuStudioApiUrl`,`Bambu Studio sidecar URL`)}),(0,G.jsx)(`input`,{type:`text`,value:((A.preferred_slicer??`bambu_studio`)===`orcaslicer`?A.orcaslicer_api_url:A.bambu_studio_api_url)??``,onChange:e=>tr((A.preferred_slicer??`bambu_studio`)===`orcaslicer`?`orcaslicer_api_url`:`bambu_studio_api_url`,e.target.value),placeholder:(A.preferred_slicer??`bambu_studio`)===`orcaslicer`?`http://localhost:3003`:`http://localhost:3001`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none placeholder:text-bambu-gray/40`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.slicerApiUrlDescription`,`URL of the slicer-API sidecar container. Leave blank to use the SLICER_API_URL / BAMBU_STUDIO_API_URL env var defaults.`)})]}),(A.use_slicer_api??!1)&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.slicerStallTimeout`)}),(0,G.jsx)(`input`,{type:`number`,min:1,max:240,value:A.slicer_stall_timeout_minutes??15,onChange:e=>tr(`slicer_stall_timeout_minutes`,Number(e.target.value)),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:i(`settings.slicerStallTimeoutDescription`)})]})]})]}),(A.use_slicer_api??!1)&&(0,G.jsx)(vVe,{}),(0,G.jsxs)(Md,{children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,id:`card-drying`,children:[(0,G.jsx)(fc,{className:`w-4 h-4 text-amber-600 dark:text-amber-400`}),i(`settings.queueDrying`)]})}),(0,G.jsxs)(Pd,{className:`space-y-3`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.queueDryingDescription`)}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-white`,children:i(`settings.queueDryingEnabled`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:i(`settings.queueDryingEnabledDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.queue_drying_enabled??!1,onChange:e=>tr(`queue_drying_enabled`,e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),A.queue_drying_enabled&&(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-white`,children:i(`settings.queueDryingBlock`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:i(`settings.queueDryingBlockDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.queue_drying_block??!1,onChange:e=>tr(`queue_drying_block`,e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-amber-500`})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-white`,children:i(`settings.ambientDryingEnabled`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:i(`settings.ambientDryingEnabledDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.ambient_drying_enabled??!1,onChange:e=>tr(`ambient_drying_enabled`,e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-white`,children:i(`settings.printDryingEnabled`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:i(`settings.printDryingEnabledDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.print_drying_enabled??!1,onChange:e=>tr(`print_drying_enabled`,e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`p`,{className:`text-sm text-white font-medium`,children:i(`settings.dryingPresets`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.dryingPresetsDescription`)}),(0,G.jsx)(`div`,{className:`overflow-x-auto`,children:(0,G.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,G.jsx)(`thead`,{children:(0,G.jsxs)(`tr`,{className:`text-bambu-gray border-b border-bambu-dark-tertiary`,children:[(0,G.jsx)(`th`,{className:`text-left py-1.5`,children:i(`settings.dryingFilament`)}),(0,G.jsx)(`th`,{className:`text-center py-1.5`,colSpan:2,children:`AMS 2 Pro`}),(0,G.jsx)(`th`,{className:`text-center py-1.5`,colSpan:2,children:`AMS-HT`})]})}),(0,G.jsx)(`tbody`,{children:(()=>{let e={PLA:{n3f:45,n3s:45,n3f_hours:12,n3s_hours:12},PETG:{n3f:65,n3s:65,n3f_hours:12,n3s_hours:12},TPU:{n3f:65,n3s:75,n3f_hours:12,n3s_hours:18},ABS:{n3f:65,n3s:80,n3f_hours:12,n3s_hours:8},ASA:{n3f:65,n3s:80,n3f_hours:12,n3s_hours:8},PA:{n3f:65,n3s:85,n3f_hours:12,n3s_hours:12},PC:{n3f:65,n3s:80,n3f_hours:12,n3s_hours:8},PVA:{n3f:65,n3s:85,n3f_hours:12,n3s_hours:18}},t={...e};try{if(A.drying_presets){let n=JSON.parse(A.drying_presets);typeof n==`object`&&n&&(t={...e,...n})}}catch{}let n=(e,n,r)=>{let i={...t,[e]:{...t[e],[n]:r}};tr(`drying_presets`,JSON.stringify(i))};return Object.entries(t).map(([e,t])=>(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/50`,children:[(0,G.jsx)(`td`,{className:`py-1.5 pr-2 text-white font-medium`,children:e}),(0,G.jsx)(`td`,{className:`py-1 px-1`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-end gap-1`,children:[(0,G.jsx)(`input`,{type:`number`,min:30,max:65,value:t.n3f,onChange:t=>n(e,`n3f`,Math.max(1,parseInt(t.target.value)||0)),className:`w-14 px-1.5 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-center text-xs focus:border-amber-500/50 focus:outline-none [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none`}),(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:`°C`})]})}),(0,G.jsx)(`td`,{className:`py-1 px-1`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(`input`,{type:`number`,min:1,max:24,value:t.n3f_hours,onChange:t=>n(e,`n3f_hours`,Math.max(1,parseInt(t.target.value)||0)),className:`w-14 px-1.5 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-center text-xs focus:border-amber-500/50 focus:outline-none [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none`}),(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:`h`})]})}),(0,G.jsx)(`td`,{className:`py-1 px-1`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-end gap-1`,children:[(0,G.jsx)(`input`,{type:`number`,min:30,max:85,value:t.n3s,onChange:t=>n(e,`n3s`,Math.max(1,parseInt(t.target.value)||0)),className:`w-14 px-1.5 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-center text-xs focus:border-amber-500/50 focus:outline-none [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none`}),(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:`°C`})]})}),(0,G.jsx)(`td`,{className:`py-1 px-1`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(`input`,{type:`number`,min:1,max:24,value:t.n3s_hours,onChange:t=>n(e,`n3s_hours`,Math.max(1,parseInt(t.target.value)||0)),className:`w-14 px-1.5 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-center text-xs focus:border-amber-500/50 focus:outline-none [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none`}),(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:`h`})]})})]},e))})()})]})})]}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`p`,{className:`text-sm text-white font-medium`,children:i(`settings.humidityThresholds`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.humidityThresholdsDescription`)}),(0,G.jsx)(`div`,{className:`overflow-x-auto`,children:(0,G.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,G.jsx)(`thead`,{children:(0,G.jsxs)(`tr`,{className:`text-bambu-gray border-b border-bambu-dark-tertiary`,children:[(0,G.jsx)(`th`,{className:`text-left py-1.5`,children:i(`settings.dryingFilament`)}),(0,G.jsx)(`th`,{className:`text-right py-1.5 pr-2`,children:i(`settings.humidityThresholdCol`)})]})}),(0,G.jsx)(`tbody`,{children:(()=>{let e=A.ams_humidity_fair??60,t=[`PLA`,`PETG`,`TPU`,`ABS`,`ASA`,`PA`,`PC`,`PVA`],n={};try{if(A.ams_humidity_thresholds){let e=JSON.parse(A.ams_humidity_thresholds);typeof e==`object`&&e&&(n=e)}}catch{}let r=[{key:`default`,label:i(`settings.humidityThresholdDefault`),value:Number(n.default??e),isDefault:!0},...t.map(t=>({key:t,label:t,value:Number(n[t]??n.default??e),isDefault:!1}))],a=(e,t)=>{if(t.trim()===``){let t={...n};delete t[e],tr(`ams_humidity_thresholds`,JSON.stringify(t));return}let r=parseInt(t,10);if(Number.isNaN(r))return;let i=Math.max(5,Math.min(95,r)),a={...n,[e]:i};tr(`ams_humidity_thresholds`,JSON.stringify(a))};return r.map(e=>{let t=M[e.key],n=t===void 0?String(e.value):t;return(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/50`,children:[(0,G.jsx)(`td`,{className:`py-1.5 pr-2 font-medium ${e.isDefault?`text-bambu-gray italic`:`text-white`}`,children:e.label}),(0,G.jsx)(`td`,{className:`py-1 pr-2`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-end gap-1`,children:[(0,G.jsx)(`input`,{type:`number`,min:5,max:95,value:n,onChange:t=>N(n=>({...n,[e.key]:t.target.value})),onBlur:t=>{a(e.key,t.target.value),N(t=>{let n={...t};return delete n[e.key],n})},onKeyDown:e=>{e.key===`Enter`&&e.currentTarget.blur()},className:`w-14 px-1.5 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-center text-xs focus:border-amber-500/50 focus:outline-none [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none`}),(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:`%`})]})})]},e.key)})})()})]})})]})]})]})]})]})]}),ye===`filament`&&A&&(0,G.jsx)(G.Fragment,{children:(0,G.jsxs)(`div`,{className:`flex flex-col lg:flex-row gap-4 lg:gap-6`,children:[(0,G.jsxs)(`div`,{className:`lg:w-1/3 space-y-3`,children:[(0,G.jsx)(nHe,{}),(0,G.jsxs)(Md,{id:`card-filamentchecks`,children:[(0,G.jsx)(Nd,{children:(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(`settings.filamentChecks`)})}),(0,G.jsxs)(Pd,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.disableFilamentWarnings`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.disableFilamentWarningsDesc`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.disable_filament_warnings,onChange:e=>tr(`disable_filament_warnings`,e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.preferLowestFilament`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.preferLowestFilamentDesc`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray/70 mt-1`,children:i(`settings.preferLowestFilamentBackupNote`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.prefer_lowest_filament,onChange:e=>tr(`prefer_lowest_filament`,e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]})]})]}),(0,G.jsxs)(Md,{id:`card-printmodal`,children:[(0,G.jsx)(Nd,{children:(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(`settings.printModal`)})}),(0,G.jsx)(Pd,{className:`space-y-3`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.expandCustomMapping`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.expandCustomMappingDescription`)})]}),(0,G.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.per_printer_mapping_expanded??!1,onChange:e=>tr(`per_printer_mapping_expanded`,e.target.checked),className:`sr-only peer`}),(0,G.jsx)(`div`,{className:`w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green`})]})]})})]}),(0,G.jsxs)(Md,{id:`card-amsthresholds`,children:[(0,G.jsx)(Nd,{children:(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(`settings.amsDisplayThresholds`)})}),(0,G.jsxs)(Pd,{className:`space-y-3`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.amsThresholdsDescription`)}),(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-white`,children:[(0,G.jsx)(Xs,{className:`w-4 h-4 text-blue-600 dark:text-blue-400`}),(0,G.jsx)(`span`,{className:`font-medium`,children:i(`settings.humidity`)})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[i(`settings.goodGreen`),` ≤`]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`input`,{type:`number`,min:`0`,max:`100`,value:A.ams_humidity_good??40,onChange:e=>tr(`ams_humidity_good`,parseInt(e.target.value)||40),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:`%`})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[i(`settings.fairOrange`),` ≤`]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`input`,{type:`number`,min:`0`,max:`100`,value:A.ams_humidity_fair??60,onChange:e=>tr(`ams_humidity_fair`,parseInt(e.target.value)||60),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:`%`})]})]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.aboveFairBad`)}),(0,G.jsx)(`p`,{className:`text-xs text-amber-700/80 dark:text-amber-400/70`,children:i(`settings.fairAlsoDryingThreshold`)}),(A.ams_humidity_fair??60)tr(`ams_temp_good`,parseFloat(e.target.value)||28),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:`°C`})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[i(`settings.fairOrange`),` ≤`]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`input`,{type:`number`,step:`0.5`,min:`0`,max:`60`,value:A.ams_temp_fair??35,onChange:e=>tr(`ams_temp_fair`,parseFloat(e.target.value)||35),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:`°C`})]})]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.aboveFairHot`)})]}),(0,G.jsxs)(`div`,{className:`space-y-3 pt-4 border-t border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-white`,children:[(0,G.jsx)(Us,{className:`w-4 h-4 text-purple-600 dark:text-purple-400`}),(0,G.jsx)(`span`,{className:`font-medium`,children:i(`settings.historyRetention`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:i(`settings.keepSensorHistory`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`input`,{type:`number`,min:`1`,max:`365`,value:A.ams_history_retention_days??30,onChange:e=>tr(`ams_history_retention_days`,parseInt(e.target.value)||30),className:`w-24 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`}),(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:i(`common.days`)})]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:i(`settings.historyRetentionDescription`)})]})]})]})]}),(0,G.jsxs)(`div`,{className:`lg:w-2/3 space-y-3`,children:[(0,G.jsx)(rHe,{}),(0,G.jsx)(pHe,{})]})]})}),Le!==null&&(0,G.jsx)(Zd,{title:i(`settings.deleteApiKeyTitle`),message:i(`settings.deleteApiKeyMessage`),confirmText:i(`settings.deleteKey`),variant:`danger`,onConfirm:()=>{qt.mutate(Le),Re(null)},onCancel:()=>Re(null)}),P&&(0,G.jsx)(MVe,{plug:I,onClose:()=>{F(!1),L(null)}}),R&&(0,G.jsx)(PVe,{sensor:B,printers:Jt??[],onClose:()=>{z(!1),V(null)}}),ee&&(0,G.jsx)(LVe,{provider:ne,onClose:()=>{te(!1),re(null)}}),ie&&(0,G.jsx)(RVe,{template:ie,onClose:()=>ae(null)}),le&&(0,G.jsx)(BVe,{onClose:()=>ue(!1)}),Ve&&(0,G.jsx)(Zd,{title:i(`settings.clearNotificationLogs`),message:i(`settings.clearLogsMessage`),confirmText:i(`settings.clearLogs`),variant:`warning`,onConfirm:async()=>{He(!1);try{o((await Z.clearNotificationLogs(30)).message,`success`)}catch{o(i(`settings.toast.clearLogsFailed`),`error`)}},onCancel:()=>He(!1)}),Ue&&(0,G.jsx)(Zd,{title:i(`settings.resetUiPreferences`),message:i(`settings.resetUiPreferencesMessage`),confirmText:i(`settings.resetPreferences`),variant:`default`,onConfirm:()=>{We(!1),localStorage.clear(),o(i(`settings.toast.uiPreferencesReset`),`success`),setTimeout(()=>window.location.reload(),1e3)},onCancel:()=>We(!1)}),Ge&&(0,G.jsx)(Zd,{title:`Turn All Plugs ${Ge===`on`?`On`:`Off`}`,message:`This will turn ${Ge===`on`?`ON`:`OFF`} all ${zt?.filter(e=>e.enabled).length||0} enabled smart plugs. ${Ge===`off`?`Any running printers may be affected!`:``}`,confirmText:`Turn All ${Ge===`on`?`On`:`Off`}`,variant:Ge===`off`?`danger`:`warning`,onConfirm:()=>{let e=Ge;Ke(null),qn.mutate(e)},onCancel:()=>Ke(null)}),qe&&_n?.release_notes&&(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,onClick:()=>Je(!1),children:(0,G.jsxs)(Md,{className:`w-full max-w-2xl max-h-[80vh] flex flex-col`,onClick:e=>e.stopPropagation(),children:[(0,G.jsxs)(Nd,{className:`flex flex-row items-center justify-between shrink-0`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white`,children:[`Release Notes - v`,_n.latest_version]}),_n.release_name&&_n.release_name!==_n.latest_version&&(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:_n.release_name})]}),(0,G.jsx)(`button`,{onClick:()=>Je(!1),className:`p-1 rounded hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white`,children:(0,G.jsx)($u,{className:`w-5 h-5`})})]}),(0,G.jsx)(Pd,{className:`overflow-y-auto flex-1`,children:(0,G.jsx)(`pre`,{className:`text-sm text-bambu-gray whitespace-pre-wrap font-sans`,children:_n.release_notes})}),(0,G.jsxs)(`div`,{className:`p-4 border-t border-bambu-dark-tertiary shrink-0 flex gap-2`,children:[_n.release_url&&(0,G.jsx)(`a`,{href:_n.release_url,target:`_blank`,rel:`noopener noreferrer`,className:`flex-1`,children:(0,G.jsxs)(Q,{variant:`secondary`,className:`w-full`,children:[(0,G.jsx)(tc,{className:`w-4 h-4`}),`View on GitHub`]})}),(0,G.jsx)(Q,{onClick:()=>Je(!1),className:`flex-1`,children:`Close`})]})]})}),ye===`users`&&(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{className:`flex gap-1 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`button`,{onClick:()=>Se(`users`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${xe===`users`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,G.jsx)(Bu,{className:`w-4 h-4`}),i(`settings.tabs.users`)]}),(0,G.jsxs)(`button`,{onClick:()=>Se(`email`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${xe===`email`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,G.jsx)(rl,{className:`w-4 h-4`}),i(`settings.tabs.emailAuth`)||`Email Authentication`,Tn?.advanced_auth_enabled&&(0,G.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-green-400`})]}),(0,G.jsxs)(`button`,{onClick:()=>Se(`ldap`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px lg:border-b-0 lg:border-l-2 lg:-ml-px lg:mb-0 lg:justify-start flex items-center gap-2 ${xe===`ldap`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,G.jsx)(iu,{className:`w-4 h-4`}),i(`settings.tabs.ldap`)||`LDAP`,En?.ldap_enabled&&(0,G.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-green-400`})]}),(0,G.jsxs)(`button`,{onClick:()=>Se(`twofa`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${xe===`twofa`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,G.jsx)(iu,{className:`w-4 h-4`}),i(`settings.tabs.twoFa`),(0,G.jsx)(`span`,{className:`w-2 h-2 rounded-full ${Dn?.totp_enabled||Dn?.email_otp_enabled?`bg-green-400`:`bg-bambu-gray/40`}`})]}),l&&(0,G.jsxs)(`button`,{onClick:()=>Se(`oidc`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${xe===`oidc`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,G.jsx)(Dc,{className:`w-4 h-4`}),i(`settings.tabs.oidc`),(0,G.jsx)(`span`,{className:`w-2 h-2 rounded-full ${On.some(e=>e.is_enabled)?`bg-green-400`:`bg-bambu-gray/40`}`})]}),l&&(0,G.jsxs)(`button`,{onClick:()=>Se(`security`),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${xe===`security`?`text-bambu-green border-bambu-green`:`text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent`}`,children:[(0,G.jsx)(iu,{className:`w-4 h-4`}),i(`settings.tabs.security`)]})]}),xe===`users`&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Md,{children:(0,G.jsx)(Pd,{className:`py-4`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`w-10 h-10 rounded-full flex items-center justify-center ${s?`bg-green-500/20`:`bg-gray-500/20`}`,children:s?(0,G.jsx)(el,{className:`w-5 h-5 text-green-600 dark:text-green-400`}):(0,G.jsx)($c,{className:`w-5 h-5 text-gray-400`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`text-white font-medium`,children:i(`settings.authentication`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(s?`settings.authEnabledDescription`:`settings.authDisabledDescription`)})]})]}),s?c?.is_admin&&(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>Xe(!0),children:[(0,G.jsx)($c,{className:`w-4 h-4`}),i(`common.disable`)]}):(0,G.jsxs)(Q,{onClick:()=>t(`/setup`),children:[(0,G.jsx)(el,{className:`w-4 h-4`}),i(`common.enable`)]})]})})}),Tn?.advanced_auth_enabled&&(0,G.jsx)(Md,{className:`border-blue-500/30 bg-blue-500/5`,children:(0,G.jsx)(Pd,{className:`py-4`,children:(0,G.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,G.jsx)(`div`,{className:`w-10 h-10 rounded-full flex items-center justify-center bg-blue-500/20 flex-shrink-0`,children:(0,G.jsx)(rl,{className:`w-5 h-5 text-blue-600 dark:text-blue-400`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`text-white font-medium`,children:i(`settings.email.advancedAuthEnabled`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:i(`settings.email.advancedAuthEnabledDesc`)})]})]})})}),s&&(0,G.jsxs)(`div`,{className:`grid grid-cols-1 xl:grid-cols-2 gap-6`,children:[(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(Md,{id:`card-session-policy`,children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`h3`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(el,{className:`w-5 h-5 text-bambu-green`}),i(`settings.sessionPolicy.title`)]})}),(0,G.jsxs)(Pd,{children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4`,children:i(`settings.sessionPolicy.description`)}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 sm:grid-cols-4 gap-2 mb-4`,children:[[{hours:24,labelKey:`settings.sessionPolicy.preset24h`},{hours:168,labelKey:`settings.sessionPolicy.preset7d`},{hours:720,labelKey:`settings.sessionPolicy.preset30d`}].map(e=>{let t=(A?.session_max_hours??24)===e.hours;return(0,G.jsx)(`button`,{type:`button`,onClick:()=>tr(`session_max_hours`,e.hours),disabled:s&&!d(`settings:update`),className:`px-3 py-2 rounded-lg text-sm font-medium transition-colors ${t?`bg-bambu-green text-white`:`bg-bambu-dark-tertiary text-bambu-gray hover:text-white hover:bg-bambu-dark`} disabled:opacity-50 disabled:cursor-not-allowed`,children:i(e.labelKey)},e.hours)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(`input`,{type:`number`,min:1,max:720,value:A?.session_max_hours??24,onChange:e=>{let t=parseInt(e.target.value,10);Number.isNaN(t)||tr(`session_max_hours`,Math.max(1,Math.min(720,t)))},disabled:s&&!d(`settings:update`),"aria-label":i(`settings.sessionPolicy.customHoursLabel`),className:`w-20 px-2 py-2 bg-bambu-dark-tertiary text-white text-sm rounded-lg border border-bambu-dark-tertiary focus:border-bambu-green focus:outline-none disabled:opacity-50`}),(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:i(`settings.sessionPolicy.hoursSuffix`)})]})]}),(A?.session_max_hours??24)>24&&(0,G.jsxs)(`div`,{className:`flex items-start gap-2 p-3 rounded-lg bg-yellow-50 dark:bg-yellow-500/10 border border-yellow-300 dark:border-yellow-500/30`,children:[(0,G.jsx)(Pu,{className:`w-4 h-4 text-yellow-600 dark:text-yellow-400 flex-shrink-0 mt-0.5`}),(0,G.jsx)(`p`,{className:`text-xs text-yellow-800 dark:text-yellow-200`,children:i(`settings.sessionPolicy.warning`)})]})]})]}),c&&(0,G.jsxs)(Md,{children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`h3`,{className:`text-lg font-semibold text-white flex items-center gap-2`,id:`card-currentuser`,children:[(0,G.jsx)(Bu,{className:`w-5 h-5 text-bambu-green`}),i(`settings.currentUser`)]}),c.auth_source!==`ldap`&&(0,G.jsxs)(Q,{size:`sm`,variant:`ghost`,onClick:()=>Qe(!0),children:[(0,G.jsx)(Uc,{className:`w-4 h-4`}),i(`settings.changePassword`)]})]})}),(0,G.jsx)(Pd,{children:(0,G.jsx)(`div`,{className:`flex items-center justify-between`,children:(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white font-medium text-lg`,children:c.username}),(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-1 mt-2`,children:[c.is_admin&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 rounded-full text-xs font-medium bg-purple-100 dark:bg-purple-500/20 text-purple-700 dark:text-purple-300`,children:i(`settings.admin`)}),c.groups?.map(e=>(0,G.jsx)(`span`,{className:`px-2 py-0.5 rounded-full text-xs font-medium ${e.name===`Administrators`?`bg-purple-100 dark:bg-purple-500/20 text-purple-700 dark:text-purple-300`:e.name===`Operators`?`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-300`:e.name===`Viewers`?`bg-green-100 dark:bg-green-500/20 text-green-700 dark:text-green-300`:`bg-gray-500/20 text-gray-300`}`,children:e.name},e.id))]})]})})})]}),(0,G.jsxs)(Md,{children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`h3`,{className:`text-lg font-semibold text-white flex items-center gap-2`,id:`card-users`,children:[(0,G.jsx)(Bu,{className:`w-5 h-5 text-bambu-green`}),i(`settings.users`)]}),d(`users:create`)&&(0,G.jsxs)(Q,{size:`sm`,onClick:()=>{ot(!0),bt({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]})},children:[(0,G.jsx)(Ml,{className:`w-4 h-4`}),i(`settings.addUser`)]})]})}),(0,G.jsx)(Pd,{children:An?(0,G.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,G.jsx)(Y,{className:`w-6 h-6 text-bambu-green animate-spin`})}):kn.length===0?(0,G.jsx)(`p`,{className:`text-center text-bambu-gray py-8`,children:i(`settings.noUsersFound`)}):(0,G.jsx)(`div`,{className:`divide-y divide-bambu-dark-tertiary`,children:kn.map(e=>(0,G.jsxs)(`div`,{className:`py-3 flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`p`,{className:`text-white font-medium truncate`,children:e.username}),(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-1 mt-1`,children:[e.auth_source===`ldap`&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 rounded-full text-xs font-medium bg-cyan-100 dark:bg-cyan-500/20 text-cyan-700 dark:text-cyan-300`,children:`LDAP`}),e.is_admin&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 rounded-full text-xs font-medium bg-purple-100 dark:bg-purple-500/20 text-purple-700 dark:text-purple-300`,children:i(`settings.admin`)}),e.groups?.map(e=>(0,G.jsx)(`span`,{className:`px-2 py-0.5 rounded-full text-xs font-medium ${e.name===`Administrators`?`bg-purple-100 dark:bg-purple-500/20 text-purple-700 dark:text-purple-300`:e.name===`Operators`?`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-300`:e.name===`Viewers`?`bg-green-100 dark:bg-green-500/20 text-green-700 dark:text-green-300`:`bg-gray-500/20 text-gray-300`}`,children:e.name},e.id))]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1 ml-4`,children:[d(`users:update`)&&(0,G.jsx)(Q,{size:`sm`,variant:`ghost`,onClick:()=>Vn(e),children:(0,G.jsx)(Dl,{className:`w-4 h-4`})}),d(`users:delete`)&&e.id!==c?.id&&(0,G.jsx)(Q,{size:`sm`,variant:`ghost`,onClick:()=>Ln(e.id),children:(0,G.jsx)(ju,{className:`w-4 h-4`})})]})]},e.id))})})]})]}),(0,G.jsx)(`div`,{children:(0,G.jsxs)(Md,{children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`h3`,{className:`text-lg font-semibold text-white flex items-center gap-2`,id:`card-groups`,children:[(0,G.jsx)(iu,{className:`w-5 h-5 text-bambu-green`}),i(`settings.groups`)]}),d(`groups:create`)&&(0,G.jsxs)(Q,{size:`sm`,onClick:()=>t(`/groups/new`),children:[(0,G.jsx)(Ml,{className:`w-4 h-4`}),i(`settings.addGroup`)]})]})}),(0,G.jsx)(Pd,{children:Mn?(0,G.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,G.jsx)(Y,{className:`w-6 h-6 text-bambu-green animate-spin`})}):jn.length===0?(0,G.jsx)(`p`,{className:`text-center text-bambu-gray py-8`,children:i(`settings.noGroupsFound`)}):(0,G.jsx)(`div`,{className:`divide-y divide-bambu-dark-tertiary`,children:jn.map(e=>(0,G.jsxs)(`div`,{className:`py-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(iu,{className:`w-4 h-4 ${e.name===`Administrators`?`text-purple-600 dark:text-purple-400`:e.name===`Operators`?`text-blue-600 dark:text-blue-400`:e.name===`Viewers`?`text-green-600 dark:text-green-400`:`text-bambu-gray`}`}),(0,G.jsx)(`span`,{className:`text-white font-medium`,children:e.name}),e.is_system&&(0,G.jsx)(`span`,{className:`px-2 py-0.5 rounded text-xs bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400`,children:i(`settings.system`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[d(`groups:update`)&&(0,G.jsx)(Q,{size:`sm`,variant:`ghost`,onClick:()=>t(`/groups/${e.id}/edit`),children:(0,G.jsx)(Dl,{className:`w-4 h-4`})}),d(`groups:delete`)&&!e.is_system&&(0,G.jsx)(Q,{size:`sm`,variant:`ghost`,onClick:()=>St(e.id),children:(0,G.jsx)(ju,{className:`w-4 h-4`})})]})]}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1 ml-6`,children:e.description||i(`settings.noDescription`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-4 mt-2 ml-6 text-xs text-bambu-gray`,children:[(0,G.jsx)(`span`,{children:i(`settings.userCount`,{count:e.user_count})}),(0,G.jsx)(`span`,{children:i(`settings.permissionCount`,{count:e.permissions.length})})]})]},e.id))})})]})})]}),!s&&(0,G.jsx)(Md,{children:(0,G.jsx)(Pd,{className:`py-6`,children:(0,G.jsxs)(`div`,{className:`text-center`,children:[(0,G.jsx)($c,{className:`w-12 h-12 text-bambu-gray mx-auto mb-4`}),(0,G.jsx)(`h3`,{className:`text-lg font-medium text-white mb-2`,children:i(`settings.authDisabledTitle`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4 max-w-md mx-auto`,children:i(`settings.authDisabledMessage`)}),(0,G.jsxs)(`ul`,{className:`space-y-2 text-sm text-bambu-gray mb-6 text-left max-w-xs mx-auto`,children:[(0,G.jsxs)(`li`,{className:`flex items-start gap-2`,children:[(0,G.jsx)(ys,{className:`w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0`}),(0,G.jsx)(`span`,{children:i(`settings.authDisabledFeature1`)})]}),(0,G.jsxs)(`li`,{className:`flex items-start gap-2`,children:[(0,G.jsx)(ys,{className:`w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0`}),(0,G.jsx)(`span`,{children:i(`settings.authDisabledFeature2`)})]}),(0,G.jsxs)(`li`,{className:`flex items-start gap-2`,children:[(0,G.jsx)(ys,{className:`w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0`}),(0,G.jsx)(`span`,{children:i(`settings.authDisabledFeature3`)})]})]}),(0,G.jsxs)(Q,{onClick:()=>t(`/setup`),children:[(0,G.jsx)(el,{className:`w-4 h-4`}),i(`settings.enableAuthentication`)]})]})})})]}),xe===`email`&&(0,G.jsx)(`div`,{className:`max-w-5xl`,id:`card-smtp`,children:(0,G.jsx)(NHe,{})}),xe===`ldap`&&(0,G.jsx)(`div`,{className:`max-w-5xl`,id:`card-ldap`,children:(0,G.jsx)(FHe,{})}),xe===`twofa`&&(0,G.jsx)(`div`,{className:`max-w-2xl`,children:(0,G.jsx)(LHe,{})}),xe===`oidc`&&l&&(0,G.jsxs)(`div`,{className:`max-w-3xl space-y-4`,children:[(0,G.jsx)(Md,{children:(0,G.jsx)(Pd,{className:`space-y-3 p-4`,children:(0,G.jsxs)(`label`,{className:`flex items-start gap-3 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:A.local_login_enabled===!1,onChange:e=>tr(`local_login_enabled`,!e.target.checked),className:`mt-1 h-4 w-4 rounded border-bambu-dark-tertiary bg-bambu-dark-secondary text-bambu-green focus:ring-bambu-green/50 cursor-pointer`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm font-medium text-white`,children:i(`settings.localLogin.disable`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:i(`settings.localLogin.disableHint`)})]})]})})}),(0,G.jsx)(BHe,{})]}),xe===`security`&&l&&(0,G.jsx)(`div`,{className:`max-w-3xl`,children:(0,G.jsx)(HHe,{})})]}),at&&!Tn?.advanced_auth_enabled&&(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black flex items-center justify-center z-50 p-4`,onClick:()=>{ot(!1),bt({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]})},children:(0,G.jsxs)(Md,{className:`w-full max-w-md`,onClick:e=>e.stopPropagation(),children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Bu,{className:`w-5 h-5 text-bambu-green`}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(`settings.createUser`)})]}),(0,G.jsx)(Q,{variant:`ghost`,size:`sm`,onClick:()=>{ot(!1),bt({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]})},children:(0,G.jsx)($u,{className:`w-5 h-5`})})]})}),(0,G.jsxs)(Pd,{children:[En?.ldap_enabled&&(0,G.jsxs)(`div`,{className:`mb-4 flex items-center gap-1 p-1 bg-bambu-dark-secondary rounded-lg`,role:`tablist`,"aria-label":i(`users.modal.tabsAriaLabel`),children:[(0,G.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":st===`local`,onClick:()=>ct(`local`),className:`flex-1 px-3 py-2 text-sm rounded-md transition-colors ${st===`local`?`bg-bambu-green/15 text-bambu-green`:`text-bambu-gray hover:text-white`}`,children:i(`users.modal.localTab`)}),(0,G.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":st===`ldap`,onClick:()=>ct(`ldap`),className:`flex-1 px-3 py-2 text-sm rounded-md transition-colors ${st===`ldap`?`bg-bambu-green/15 text-bambu-green`:`text-bambu-gray hover:text-white`}`,children:i(`users.modal.ldapTab`)})]}),st===`ldap`&&En?.ldap_enabled?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(l6,{onSuccess:e=>{ot(!1),ct(`local`),bt({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]}),o(i(`users.toast.ldapProvisioned`,{username:e.username}))}}),(0,G.jsx)(`div`,{className:`mt-6 flex justify-end`,children:(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>{ot(!1),ct(`local`),bt({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]})},children:i(`common.cancel`)})})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:i(`settings.username`)}),(0,G.jsx)(`input`,{type:`text`,value:yt.username,onChange:e=>bt({...yt,username:e.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:i(`settings.enterUsername`),autoComplete:`username`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:i(`settings.password`)}),(0,G.jsx)(`input`,{type:`password`,value:yt.password,onChange:e=>bt({...yt,password:e.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:i(`settings.enterPassword`),autoComplete:`new-password`,minLength:8}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-xs mt-1`,children:i(`settings.passwordRequirements`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:i(`settings.confirmPassword`)}),(0,G.jsx)(`input`,{type:`password`,value:yt.confirmPassword,onChange:e=>bt({...yt,confirmPassword:e.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors ${yt.confirmPassword&&yt.password!==yt.confirmPassword?`border-red-500`:`border-bambu-dark-tertiary`}`,placeholder:i(`settings.confirmPasswordPlaceholder`),autoComplete:`new-password`,minLength:6}),yt.confirmPassword&&yt.password!==yt.confirmPassword&&(0,G.jsx)(`p`,{className:`text-red-700 dark:text-red-400 text-xs mt-1`,children:i(`settings.passwordsDoNotMatch`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:i(`settings.groups`)}),(0,G.jsxs)(`div`,{className:`space-y-2 max-h-40 overflow-y-auto p-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg`,children:[jn.map(e=>(0,G.jsxs)(`label`,{className:`flex items-center gap-3 px-2 py-1.5 rounded hover:bg-bambu-dark-tertiary cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:yt.group_ids.includes(e.id),onChange:()=>Hn(e.id),className:`w-4 h-4 rounded border-bambu-gray text-bambu-green focus:ring-bambu-green focus:ring-offset-0 bg-bambu-dark`}),(0,G.jsx)(`span`,{className:`text-sm text-white`,children:e.name}),e.is_system&&(0,G.jsx)(`span`,{className:`text-xs text-yellow-700 dark:text-yellow-400`,children:i(`settings.systemBadge`)})]},e.id)),jn.length===0&&(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`settings.noGroupsAvailable`)})]})]})]}),(0,G.jsxs)(`div`,{className:`mt-6 flex justify-end gap-3`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>{ot(!1),bt({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]})},children:i(`common.cancel`)}),(0,G.jsx)(Q,{onClick:zn,disabled:Nn.isPending||!yt.username||!yt.password||yt.password!==yt.confirmPassword||N3(yt.password)!==null,children:Nn.isPending?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),i(`settings.creating`)]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Ml,{className:`w-4 h-4`}),i(`settings.createUser`)]})})]})]})]})]})}),at&&Tn?.advanced_auth_enabled&&(0,G.jsx)(tHe,{formData:yt,setFormData:bt,groups:jn,onClose:()=>{ot(!1),bt({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]})},onCreate:zn,isCreating:Nn.isPending,isCreateButtonDisabled:Nn.isPending||!yt.username||!yt.email,ldapEnabled:En?.ldap_enabled,onLdapProvisioned:e=>{ot(!1),bt({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]}),o(i(`users.toast.ldapProvisioned`,{username:e.username}))}}),lt&&dt!==null&&(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black flex items-center justify-center z-50 p-4`,onClick:()=>{ut(!1),ft(null),bt({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]})},children:(0,G.jsxs)(Md,{className:`w-full max-w-md`,onClick:e=>e.stopPropagation(),children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Dl,{className:`w-5 h-5 text-bambu-green`}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(`settings.editUser`)})]}),(0,G.jsx)(Q,{variant:`ghost`,size:`sm`,onClick:()=>{ut(!1),ft(null),bt({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]})},children:(0,G.jsx)($u,{className:`w-5 h-5`})})]})}),(0,G.jsxs)(Pd,{children:[(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:[i(`settings.username`),` `,Tn?.advanced_auth_enabled&&(0,G.jsx)(`span`,{className:`text-red-700 dark:text-red-400`,children:`*`})]}),(0,G.jsx)(`input`,{type:`text`,value:yt.username,onChange:e=>bt({...yt,username:e.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:i(`settings.enterUsername`),autoComplete:`username`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:[i(`users.form.email`)||`Email`,` `,Tn?.advanced_auth_enabled?(0,G.jsx)(`span`,{className:`text-red-700 dark:text-red-400`,children:`*`}):(0,G.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,i(`users.form.optional`)||`optional`,`)`]})]}),(0,G.jsx)(`input`,{type:`email`,value:yt.email,onChange:e=>bt({...yt,email:e.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:i(`users.form.emailPlaceholder`)||`user@example.com`,required:Tn?.advanced_auth_enabled})]}),!Tn?.advanced_auth_enabled&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:[i(`users.form.password`)||`Password`,` `,(0,G.jsxs)(`span`,{className:`text-bambu-gray font-normal`,children:[`(`,i(`users.form.leaveBlankToKeep`)||`leave blank to keep current`,`)`]})]}),(0,G.jsx)(`input`,{type:`password`,value:yt.password,onChange:e=>bt({...yt,password:e.target.value,confirmPassword:``}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:i(`settings.enterNewPassword`),autoComplete:`new-password`,minLength:8}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-xs mt-1`,children:i(`settings.passwordRequirements`)})]}),yt.password&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:i(`settings.confirmPassword`)}),(0,G.jsx)(`input`,{type:`password`,value:yt.confirmPassword,onChange:e=>bt({...yt,confirmPassword:e.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors ${yt.confirmPassword&&yt.password!==yt.confirmPassword?`border-red-500`:`border-bambu-dark-tertiary`}`,placeholder:i(`settings.confirmNewPassword`),autoComplete:`new-password`,minLength:6}),yt.confirmPassword&&yt.password!==yt.confirmPassword&&(0,G.jsx)(`p`,{className:`text-red-700 dark:text-red-400 text-xs mt-1`,children:i(`settings.passwordsDoNotMatch`)})]})]}),Tn?.advanced_auth_enabled&&(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary/50 border border-bambu-green/20 rounded-lg p-3 space-y-3`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`users.form.passwordManagedByAdvancedAuth`)||`Password is managed by Advanced Authentication. Use "Reset Password" to send a new password to the user via email.`}),(0,G.jsx)(Q,{variant:`secondary`,size:`sm`,onClick:()=>dt&&In.mutate(dt),disabled:In.isPending||!yt.email,className:`w-full`,children:In.isPending?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),i(`users.form.resettingPassword`)||`Resetting Password...`]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Vl,{className:`w-4 h-4`}),i(`users.form.resetPassword`)||`Reset Password`]})})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:i(`users.form.groups`)||`Groups`}),(0,G.jsx)(`div`,{className:`space-y-2 max-h-40 overflow-y-auto p-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg`,children:jn.map(e=>(0,G.jsxs)(`label`,{className:`flex items-center gap-3 px-2 py-1.5 rounded hover:bg-bambu-dark-tertiary cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:yt.group_ids.includes(e.id),onChange:()=>Hn(e.id),className:`w-4 h-4 rounded border-bambu-gray text-bambu-green focus:ring-bambu-green focus:ring-offset-0 bg-bambu-dark`}),(0,G.jsx)(`span`,{className:`text-sm text-white`,children:e.name}),e.is_system&&(0,G.jsxs)(`span`,{className:`text-xs text-yellow-700 dark:text-yellow-400`,children:[`(`,i(`users.system`)||`System`,`)`]})]},e.id))})]})]}),(0,G.jsxs)(`div`,{className:`mt-6 flex justify-end gap-3`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>{ut(!1),ft(null),bt({username:``,password:``,email:``,confirmPassword:``,role:`user`,group_ids:[]})},children:i(`users.modal.cancel`)||`Cancel`}),(0,G.jsx)(Q,{onClick:()=>Bn(dt),disabled:Pn.isPending||!yt.username||Tn?.advanced_auth_enabled&&!yt.email||!!(!Tn?.advanced_auth_enabled&&yt.password&&(yt.password!==yt.confirmPassword||N3(yt.password)!==null)),children:Pn.isPending?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),i(`users.modal.saving`)||`Saving...`]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Wl,{className:`w-4 h-4`}),i(`users.modal.saveChanges`)||`Save Changes`]})})]})]})]})}),pt!==null&&(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/80 flex items-center justify-center z-50 p-4`,onClick:()=>{mt(null),gt(null)},children:(0,G.jsxs)(Md,{className:`w-full max-w-md`,onClick:e=>e.stopPropagation(),children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-red-700 dark:text-red-400`,children:[(0,G.jsx)(ju,{className:`w-5 h-5`}),(0,G.jsx)(`h3`,{className:`text-lg font-semibold`,children:i(`settings.deleteUserTitle`)})]})}),(0,G.jsx)(Pd,{className:`space-y-3`,children:_t?(0,G.jsx)(`div`,{className:`flex items-center justify-center py-4`,children:(0,G.jsx)(`div`,{className:`animate-spin rounded-full h-6 w-6 border-2 border-bambu-green border-t-transparent`})}):ht&&ht.archives+ht.queue_items+ht.library_files>0?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.userHasCreated`)}),(0,G.jsxs)(`ul`,{className:`list-disc list-inside text-bambu-gray space-y-1`,children:[ht.archives>0&&(0,G.jsxs)(`li`,{children:[ht.archives,` archive`,ht.archives===1?``:`s`]}),ht.queue_items>0&&(0,G.jsxs)(`li`,{children:[ht.queue_items,` queue item`,ht.queue_items===1?``:`s`]}),ht.library_files>0&&(0,G.jsxs)(`li`,{children:[ht.library_files,` library file`,ht.library_files===1?``:`s`]})]}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-sm`,children:i(`settings.userItemsQuestion`)}),(0,G.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,G.jsx)(Q,{variant:`danger`,onClick:()=>Fn.mutate({id:pt,deleteItems:!0}),disabled:Fn.isPending,className:`justify-center`,children:i(`settings.deleteUserAndItems`)}),(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>Fn.mutate({id:pt,deleteItems:!1}),disabled:Fn.isPending,className:`justify-center`,children:i(`settings.deleteUserKeepItems`)}),(0,G.jsx)(Q,{variant:`ghost`,onClick:()=>{mt(null),gt(null)},disabled:Fn.isPending,className:`justify-center`,children:i(`common.cancel`)})]})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`p`,{className:`text-white`,children:i(`settings.deleteUserConfirm`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-sm`,children:i(`settings.actionCannotBeUndone`)}),(0,G.jsxs)(`div`,{className:`flex gap-2 justify-end`,children:[(0,G.jsx)(Q,{variant:`ghost`,onClick:()=>{mt(null),gt(null)},disabled:Fn.isPending,children:i(`common.cancel`)}),(0,G.jsx)(Q,{variant:`danger`,onClick:()=>Fn.mutate({id:pt,deleteItems:!1}),disabled:Fn.isPending,children:i(`settings.deleteUserTitle`)})]})]})})]})}),xt!==null&&(0,G.jsx)(Zd,{title:i(`settings.deleteGroupTitle`),message:i(`settings.deleteGroupMessage`),confirmText:i(`settings.deleteGroup`),variant:`danger`,onConfirm:()=>{Rn.mutate(xt),St(null)},onCancel:()=>St(null)}),ye===`failure-detection`&&(0,G.jsx)(`div`,{id:`card-failure-detection`,children:(0,G.jsx)(AHe,{})}),ye===`backup`&&(0,G.jsxs)(`div`,{id:`card-backup`,children:[(0,G.jsxs)(`div`,{className:`mb-4 p-3 bg-amber-50 dark:bg-amber-500/10 border border-amber-300 dark:border-amber-500/30 rounded-lg flex items-start gap-2`,children:[(0,G.jsx)(iu,{className:`text-amber-600 dark:text-amber-400 flex-shrink-0 mt-0.5`,size:16}),(0,G.jsx)(`p`,{className:`text-sm text-amber-700 dark:text-amber-400`,children:i(`backup.includesEncryptionKey`)})]}),(0,G.jsx)(kHe,{})]}),Ye&&(0,G.jsx)(Zd,{title:i(`settings.disableAuthenticationTitle`),message:i(`settings.disableAuthenticationMessage`),confirmText:i(`settings.disableAuthentication`),variant:`danger`,onConfirm:async()=>{try{await Z.disableAuth(),o(i(`settings.toast.authDisabled`),`success`),await u(),Xe(!1),window.location.href=`/`}catch(e){o(e instanceof Error?e.message:i(`settings.toast.authDisableFailed`),`error`)}},onCancel:()=>Xe(!1)}),Ze&&(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:()=>{Qe(!1),et({currentPassword:``,newPassword:``,confirmPassword:``})},children:(0,G.jsxs)(Md,{className:`w-full max-w-md`,onClick:e=>e.stopPropagation(),children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Uc,{className:`w-5 h-5 text-bambu-green`}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(`settings.changePassword`)})]}),(0,G.jsx)(Q,{variant:`ghost`,size:`sm`,onClick:()=>{Qe(!1),et({currentPassword:``,newPassword:``,confirmPassword:``})},children:(0,G.jsx)($u,{className:`w-5 h-5`})})]})}),(0,G.jsxs)(Pd,{children:[(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:`Current Password`}),(0,G.jsx)(`input`,{type:`password`,value:$e.currentPassword,onChange:e=>et({...$e,currentPassword:e.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:i(`settings.enterCurrentPassword`),autoComplete:`current-password`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:`New Password`}),(0,G.jsx)(`input`,{type:`password`,value:$e.newPassword,onChange:e=>et({...$e,newPassword:e.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:i(`settings.enterNewPasswordMin6`),autoComplete:`new-password`,minLength:6})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:`Confirm New Password`}),(0,G.jsx)(`input`,{type:`password`,value:$e.confirmPassword,onChange:e=>et({...$e,confirmPassword:e.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors ${$e.confirmPassword&&$e.newPassword!==$e.confirmPassword?`border-red-500`:`border-bambu-dark-tertiary`}`,placeholder:i(`settings.confirmNewPassword`),autoComplete:`new-password`,minLength:6}),$e.confirmPassword&&$e.newPassword!==$e.confirmPassword&&(0,G.jsx)(`p`,{className:`text-red-700 dark:text-red-400 text-xs mt-1`,children:i(`settings.passwordsDoNotMatch`)})]})]}),(0,G.jsxs)(`div`,{className:`mt-6 flex justify-end gap-3`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>{Qe(!1),et({currentPassword:``,newPassword:``,confirmPassword:``})},children:i(`common.cancel`)}),(0,G.jsx)(Q,{onClick:async()=>{if($e.newPassword!==$e.confirmPassword){o(i(`settings.toast.passwordsDoNotMatch`),`error`);return}if($e.newPassword.length<6){o(i(`settings.toast.passwordTooShort`),`error`);return}nt(!0);try{await Z.changePassword($e.currentPassword,$e.newPassword),o(i(`settings.toast.passwordChanged`),`success`),Qe(!1),et({currentPassword:``,newPassword:``,confirmPassword:``})}catch(e){o(e instanceof Error?e.message:`Failed to change password`,`error`)}finally{nt(!1)}},disabled:tt||!$e.currentPassword||!$e.newPassword||$e.newPassword!==$e.confirmPassword||$e.newPassword.length<6,children:tt?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),i(`settings.changing`)]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Uc,{className:`w-4 h-4`}),i(`settings.changePassword`)]})})]})]})]})})]})]})]})})}var QHe=/\[(aborted|failed|cancelled):\s*([^\]]*)\]/i;function $He(e){if(!e)return{isPartial:!1,partialType:null,cleanedDescription:null};let t=e.match(QHe);if(!t)return{isPartial:!1,partialType:null,cleanedDescription:e};let n=e.replace(t[0],``).trim();return{isPartial:!0,partialType:t[1].toLowerCase(),cleanedDescription:n||null}}function eUe(e,t){if(!e)return`-`;let n=Kf(e);return n?n.toLocaleString(t):e}function V6(e){let t=e.trim();if(!t)return null;let n=Number.parseFloat(t);return Number.isFinite(n)?n:null}function H6(e){return`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,`0`)}-${String(e.getDate()).padStart(2,`0`)}T${String(e.getHours()).padStart(2,`0`)}:${String(e.getMinutes()).padStart(2,`0`)}`}var U6=`w-full px-3 py-2 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded text-white placeholder-bambu-gray focus:outline-none focus:ring-1 focus:ring-bambu-green`,W6=`block text-sm font-medium text-white mb-1`,G6=`px-4 py-3 text-left text-bambu-gray font-medium`,K6=`px-4 py-3 align-top text-white`;function q6({title:e,onClose:t,children:n,size:r=`md`}){let{t:i}=U();return(0,G.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/70 p-4`,children:(0,G.jsxs)(`div`,{className:`w-full ${r===`sm`?`max-w-xl`:r===`lg`?`max-w-6xl`:`max-w-4xl`} overflow-hidden rounded-lg border border-bambu-dark-tertiary bg-bambu-dark-secondary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between border-b border-bambu-dark-tertiary px-4 py-3`,children:[(0,G.jsx)(`h3`,{className:`text-lg font-semibold text-white`,children:e}),(0,G.jsx)(Q,{size:`sm`,variant:`secondary`,onClick:t,children:i(`common.close`,`Close`)})]}),(0,G.jsx)(`div`,{className:`max-h-[75vh] overflow-auto p-4`,children:n})]})})}function tUe(){let{t:e,i18n:t}=U(),{hasPermission:n,user:r}=Ed(),{showToast:i}=Bd(),a=so(),o=n(`cost_centers:read_own`),s=n(`cost_centers:read_all`),c=n(`cost_centers:create`),l=n(`cost_centers:modify`),u=n(`cost_centers:modify`),d=n(`cost_centers:modify`),f=n(`cost_centers:modify`),p=n(`users:read_slim`)||n(`users:read`),m=s||c||l||u||d||f,h=o||m,g=h,[_,v]=(0,y.useState)(``),[b,x]=(0,y.useState)(`monthly`),[S,C]=(0,y.useState)(``),[w,T]=(0,y.useState)(null),[E,D]=(0,y.useState)(`deposit`),[O,k]=(0,y.useState)(``),[A,j]=(0,y.useState)(``),[M,N]=(0,y.useState)(null),[P,F]=(0,y.useState)(null),[I,L]=(0,y.useState)(null),[R,z]=(0,y.useState)(!0),[B,V]=(0,y.useState)(0),[ee,te]=(0,y.useState)(`all`),[ne,re]=(0,y.useState)(`all`),[ie,ae]=(0,y.useState)(!1),[oe,se]=(0,y.useState)(!1),[H,ce]=(0,y.useState)(!1),[le,ue]=(0,y.useState)(!1),[de,fe]=(0,y.useState)(`personal`),[pe,me]=(0,y.useState)(null),[he,ge]=(0,y.useState)(``),[_e,ve]=(0,y.useState)(`monthly`),[ye,be]=(0,y.useState)(``),[xe,Se]=(0,y.useState)(!1),[Ce,we]=(0,y.useState)(null),[Te,Ee]=(0,y.useState)(null),[De,Oe]=(0,y.useState)(null),[ke,Ae]=(0,y.useState)(``),[je,Me]=(0,y.useState)(``),[Ne,Pe]=(0,y.useState)(!1),[Fe,Ie]=(0,y.useState)(null),[Le,Re]=(0,y.useState)(null),[ze,Be]=(0,y.useState)(``),[Ve,He]=(0,y.useState)(``),[Ue,We]=(0,y.useState)(H6(new Date)),[Ge,Ke]=(0,y.useState)(null),[qe,Je]=(0,y.useState)(null),Ye=s||c||l||u||f&&p||d&&p;(0,y.useEffect)(()=>{Ye||fe(`personal`)},[Ye]);let{data:Xe,isLoading:Ze}=K({queryKey:[`finance`,`me`,`balance`],queryFn:Z.getMyBalance,enabled:o}),{data:Qe,isLoading:$e}=K({queryKey:[`finance`,`me`,`transactions`,50,B],queryFn:()=>Z.getMyTransactions(50,B),enabled:o}),{data:et,isLoading:tt}=K({queryKey:[`finance`,`transactions`,50,B],queryFn:()=>Z.getAllTransactions(50,B),enabled:de===`admin`&&s}),{data:nt,isLoading:rt}=K({queryKey:[`finance`,`cost-centers`,de],queryFn:()=>de===`admin`&&m?Z.listCostCenters(!0):Z.getMyCostCenters(),enabled:g}),{data:it}=K({queryKey:[`users`,`slim`],queryFn:Z.getUsersSlim,enabled:p&&(g||f||d)}),{data:at}=K({queryKey:[`finance`,`cost-center`,P],queryFn:()=>Z.getCostCenter(P),enabled:d&&P!=null});(0,y.useEffect)(()=>{!it||it.length===0||w!=null&&it.some(e=>e.id===w)||T(it[0].id)},[it,w]),(0,y.useEffect)(()=>{if(!d)return;let e=(nt||[]).filter(e=>!e.is_private);if(e.length===0){F(null);return}P!=null&&e.some(e=>e.id===P)||F(e[0].id)},[d,nt,P]),(0,y.useEffect)(()=>{if(!d||!it||it.length===0)return;let e=new Set((at?.members||[]).map(e=>e.user_id)),t=it.find(t=>!e.has(t.id));L(t?t.id:null)},[d,it,at]),(0,y.useEffect)(()=>{if(!le)return;let e=nt||[];if(e.length===0){me(null);return}pe!=null&&e.some(e=>e.id===pe)||me(e[0].id)},[le,pe,nt]),(0,y.useEffect)(()=>{if(!le||pe==null)return;let e=(nt||[]).find(e=>e.id===pe);if(e){if(ge(e.name),e.budget_mode===`total`){ve(`total`),be(e.total_budget==null?``:String(e.total_budget));return}ve(`monthly`),be(e.monthly_budget==null?``:String(e.monthly_budget))}},[le,pe,nt]);let ot=q({mutationFn:()=>Z.createCostCenter({name:_.trim(),total_budget:b===`total`?V6(S):null,monthly_budget:b===`monthly`?V6(S):null,is_active:!0}),onSuccess:()=>{a.invalidateQueries({queryKey:[`finance`]}),v(``),C(``),i(e(`finance.createdCostCenter`,`Cost center created`))},onError:t=>{i(t.message||e(`finance.createCostCenterFailed`,`Failed to create cost center`),`error`)}}),st=q({mutationFn:({costCenterId:e,value:t,mode:n})=>Z.updateCostCenterBudgets(e,{total_budget:n===`total`?V6(t):null,monthly_budget:n===`monthly`?V6(t):null})}),ct=q({mutationFn:({costCenterId:e,name:t})=>Z.updateCostCenter(e,{name:t})}),lt=q({mutationFn:e=>Z.deleteCostCenter(e)}),ut=q({mutationFn:e=>Z.deleteTransaction(e),onSuccess:()=>{a.invalidateQueries({queryKey:[`finance`]}),i(e(`finance.transactionDeleted`,`Transaction deleted`))},onError:t=>{i(t.message||e(`finance.deleteTransactionFailed`,`Failed to delete transaction`),`error`)}}),dt=q({mutationFn:e=>Z.editTransaction(e.transactionId,e.data),onSuccess:()=>{a.invalidateQueries({queryKey:[`finance`]}),i(e(`finance.transactionEdited`,`Transaction updated and ledger recalculated`)),Se(!1)},onError:t=>{i(t.message||e(`finance.editTransactionFailed`,`Failed to edit transaction`),`error`)}}),ft=q({mutationFn:e=>Z.createManualPrint(e),onSuccess:()=>{a.invalidateQueries({queryKey:[`finance`]}),i(e(`finance.manualPrintCreated`,`Manual print charge added and ledger recalculated`)),Pe(!1),Ie(null),Re(null),Be(``),He(``),We(H6(new Date))},onError:t=>{i(t.message||e(`finance.manualPrintFailed`,`Failed to create manual print`),`error`)}}),pt=q({mutationFn:e=>Z.depositUserBalance(e.userId,{amount:e.amount,description:e.description,cost_center_id:e.costCenterId??null})}),mt=q({mutationFn:e=>Z.withdrawUserBalance(e.userId,{amount:e.amount,description:e.description,cost_center_id:e.costCenterId??null})}),ht=q({mutationFn:e=>Z.upsertCostCenterMember(e.costCenterId,{user_id:e.userId,can_print:e.canPrint}),onSuccess:()=>{a.invalidateQueries({queryKey:[`finance`]}),i(e(`finance.memberSaved`,`Member saved`))},onError:t=>{i(t.message||e(`finance.memberSaveFailed`,`Failed to save member`),`error`)}}),gt=q({mutationFn:e=>Z.removeCostCenterMember(e.costCenterId,e.userId),onSuccess:()=>{a.invalidateQueries({queryKey:[`finance`]}),i(e(`finance.memberRemoved`,`Member removed`))},onError:t=>{i(t.message||e(`finance.memberRemoveFailed`,`Failed to remove member`),`error`)}}),_t=pt.isPending||mt.isPending,vt=()=>{if(!_.trim()){i(e(`finance.costCenterNameRequired`,`Cost center name is required`),`error`);return}ot.mutate()},yt=async()=>{if(pe==null){i(e(`finance.selectCostCenter`,`Please select a cost center`),`error`);return}let t=he.trim();if(!t){i(e(`finance.costCenterNameRequired`,`Cost center name is required`),`error`);return}try{l&&await ct.mutateAsync({costCenterId:pe,name:t}),u&&await st.mutateAsync({costCenterId:pe,mode:_e,value:ye}),a.invalidateQueries({queryKey:[`finance`]}),i(e(`finance.costCenterUpdated`,`Cost center updated`)),ue(!1)}catch(t){i(t.message||e(`finance.costCenterUpdateFailed`,`Failed to update cost center`),`error`)}},bt=e=>{let t=(nt||[]).find(t=>t.id===e);t&&(me(t.id),ge(t.name),t.budget_mode===`total`?(ve(`total`),be(t.total_budget==null?``:String(t.total_budget))):(ve(`monthly`),be(t.monthly_budget==null?``:String(t.monthly_budget))),ue(!0))},xt=async()=>{if(Ge)try{await lt.mutateAsync(Ge.id),a.invalidateQueries({queryKey:[`finance`]}),P===Ge.id&&F(null),i(e(`finance.costCenterDeleted`,`Cost center deleted`))}catch(t){i(t.message||e(`finance.costCenterDeleteFailed`,`Failed to delete cost center`),`error`)}finally{Ke(null)}},St=()=>{qe!=null&&ut.mutate(qe,{onSettled:()=>Je(null)})},Ct=e=>{we(e.id),Ee(e.user_id),Oe(e.cost_center_id),Ae(String(e.amount)),Me(e.description||``),Se(!0)},wt=async()=>{if(Ce==null)return;let t=ke?Number.parseFloat(ke):null;if(t!==null&&!Number.isFinite(t)){i(e(`finance.amountInvalid`,`Amount must be a valid number`),`error`);return}dt.mutate({transactionId:Ce,data:{user_id:Te||void 0,cost_center_id:De||void 0,amount:t??void 0,description:je||void 0}})},Tt=async()=>{if(Fe==null){i(e(`finance.userRequired`,`Please select a user`),`error`);return}if(Le==null){i(e(`finance.costCenterRequired`,`Please select a cost center`),`error`);return}let t=ze?Number.parseFloat(ze):null;if(t===null||!Number.isFinite(t)){i(e(`finance.amountInvalid`,`Amount must be a valid number`),`error`);return}t=Math.abs(t),ft.mutate({user_id:Fe,cost_center_id:Le,amount:t,description:Ve||void 0,created_at:Ue?new Date(Ue).toISOString():void 0})},Et=async()=>{if(w==null){i(e(`finance.userRequired`,`Please select a user`),`error`);return}let t=Number.parseFloat(O);if(!Number.isFinite(t)||t<=0){i(e(`finance.amountMustBePositive`,`Amount must be greater than zero`),`error`);return}let n={userId:w,amount:t,description:A.trim()||void 0,costCenterId:M};try{E===`deposit`?await pt.mutateAsync(n):await mt.mutateAsync(n),a.invalidateQueries({queryKey:[`finance`]}),k(``),j(``),i(E===`deposit`?e(`finance.depositSuccess`,`Deposit successful`):e(`finance.withdrawSuccess`,`Withdrawal successful`))}catch(t){i(t.message||e(`finance.adjustmentFailed`,`Wallet adjustment failed`),`error`)}},Dt=()=>{if(P==null){i(e(`finance.selectCostCenter`,`Please select a cost center`),`error`);return}if(I==null){i(e(`finance.noEligibleUsers`,`No eligible users available`),`error`);return}ht.mutate({costCenterId:P,userId:I,canPrint:R})},Ot=e=>{P!=null&>.mutate({costCenterId:P,userId:e})},kt=Ef(Xe?.currency||`EUR`),At=(0,y.useMemo)(()=>[...it||[]].sort((e,t)=>e.username.localeCompare(t.username)),[it]),jt=(0,y.useMemo)(()=>{let e=new Map;for(let t of At)e.set(t.id,t.username);return e},[At]),Mt=(0,y.useMemo)(()=>{let e=new Set((at?.members||[]).map(e=>e.user_id));return At.filter(t=>!e.has(t.id))},[At,at]),Nt=de===`admin`&&s?et:Qe,Pt=de===`admin`&&s?tt:$e,Ft=(0,y.useMemo)(()=>Nt?.items??[],[Nt?.items]),It=Nt?.total??0,Lt=Math.max(1,Math.ceil(It/50)),Rt=(0,y.useMemo)(()=>Ft.filter(e=>!(ee!==`all`&&e.transaction_type!==ee||ne!==`all`&&e.cost_center_id!==ne)),[Ft,ee,ne]),zt=Math.floor(B/50)+1,Bt=de===`admin`,Vt=t=>t===`deposit`?e(`finance.deposit`):t===`withdraw`?e(`finance.withdraw`):t===`print_charge`?e(`finance.printCharge`):t,W=t=>t==null?e(`finance.personal`,`Personal`):jt.get(t)||(r?.id===t&&r.username?r.username:e(`finance.userWithId`,`User #{{id}}`,{id:t})),Ht=t=>t.budget_limit==null||t.budget_available==null?e(`finance.unlimited`,`Unlimited`):`${kt}${t.budget_available.toFixed(2)}/${kt}${t.budget_limit.toFixed(2)}`;return h?(0,G.jsxs)(`div`,{className:`p-4 md:p-8 space-y-8`,children:[(0,G.jsxs)(`div`,{className:`flex flex-col gap-4 lg:flex-row lg:items-start lg:justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Gu,{className:`h-6 w-6 text-bambu-green`}),(0,G.jsx)(`h1`,{className:`text-2xl font-bold text-white`,children:e(`finance.title`,`Finance`)})]}),(0,G.jsx)(`p`,{className:`text-bambu-gray mt-2 max-w-2xl`,children:e(`finance.subtitle`,`Wallet, personal transactions, and cost centers`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1 max-w-2xl`,children:e(`finance.budgetPolicyHint`,`Account balances track costs. Printing is limited only by the selected cost center budget; without a budget, printing is unlimited.`)})]}),(0,G.jsxs)(`div`,{className:`flex flex-col gap-2 lg:items-end`,children:[Ye&&(0,G.jsxs)(`div`,{className:`inline-flex overflow-hidden rounded border border-bambu-dark-tertiary`,children:[(0,G.jsx)(`button`,{type:`button`,onClick:()=>fe(`personal`),className:`px-3 py-1.5 text-sm ${de===`personal`?`bg-bambu-green text-black font-medium`:`bg-bambu-dark text-bambu-gray`}`,children:e(`finance.personalView`,`Personal view`)}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>fe(`admin`),className:`px-3 py-1.5 text-sm ${de===`admin`?`bg-bambu-green text-black font-medium`:`bg-bambu-dark text-bambu-gray`}`,children:e(`finance.adminView`,`Admin view`)})]}),de===`admin`&&Ye&&(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-2 lg:justify-end`,children:[c&&(0,G.jsx)(Q,{size:`sm`,variant:`secondary`,onClick:()=>ae(!0),children:e(`finance.createCostCenter`,`Create cost center`)}),f&&p&&(0,G.jsx)(Q,{size:`sm`,variant:`secondary`,onClick:()=>se(!0),children:e(`finance.adjustWallet`,`Adjust wallet`)}),f&&p&&(0,G.jsx)(Q,{size:`sm`,variant:`secondary`,onClick:()=>Pe(!0),children:e(`finance.addManualPrint`,`Add manual print`)}),d&&p&&(0,G.jsx)(Q,{size:`sm`,variant:`secondary`,onClick:()=>ce(!0),children:e(`finance.manageMembers`,`Manage cost center members`)})]})]})]}),(0,G.jsxs)(`div`,{className:`grid gap-5 md:grid-cols-2 xl:grid-cols-3`,children:[(0,G.jsxs)(Md,{children:[(0,G.jsxs)(Nd,{className:`flex flex-row items-center justify-between pb-2`,children:[(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e(`finance.currentBalance`,`Personal account balance`)}),(0,G.jsx)(Gu,{className:`w-4 h-4 text-bambu-green/90`})]}),(0,G.jsx)(Pd,{className:`pt-1`,children:(0,G.jsx)(`p`,{className:`text-3xl font-semibold text-white leading-tight`,children:Ze?e(`common.loading`,`Loading...`):`${kt}${(Xe?.balance??0).toFixed(2)}`})})]}),(0,G.jsxs)(Md,{children:[(0,G.jsxs)(Nd,{className:`flex flex-row items-center justify-between pb-2`,children:[(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:de===`admin`?e(`finance.transactions`,`Transactions`):e(`finance.personalTransactions`,`Personal transactions`)}),(0,G.jsx)(Os,{className:`w-4 h-4 text-blue-400`})]}),(0,G.jsx)(Pd,{className:`pt-1`,children:(0,G.jsx)(`p`,{className:`text-3xl font-semibold text-white leading-tight`,children:Pt?`-`:It})})]}),(0,G.jsxs)(Md,{children:[(0,G.jsxs)(Nd,{className:`flex flex-row items-center justify-between pb-2`,children:[(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e(`finance.costCenters`,`Cost centers`)}),(0,G.jsx)(Qo,{className:`w-4 h-4 text-orange-400`})]}),(0,G.jsx)(Pd,{className:`pt-1`,children:(0,G.jsx)(`p`,{className:`text-3xl font-semibold text-white leading-tight`,children:rt?`-`:nt?.length??0})})]})]}),ie&&c&&(0,G.jsx)(q6,{title:e(`finance.createCostCenter`,`Create cost center`),size:`md`,onClose:()=>ae(!1),children:(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:W6,children:e(`finance.costCenterName`,`Name`)}),(0,G.jsx)(`input`,{type:`text`,value:_,onChange:e=>v(e.target.value),placeholder:e(`finance.costCenterName`,`Name`),className:U6})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:W6,children:e(`finance.budgetType`,`Budget type`)}),(0,G.jsxs)(`select`,{value:b,onChange:e=>x(e.target.value),className:U6,children:[(0,G.jsx)(`option`,{value:`monthly`,children:e(`finance.monthlyBudget`,`Monthly budget`)}),(0,G.jsx)(`option`,{value:`total`,children:e(`finance.totalBudget`,`Total budget`)})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:W6,children:b===`monthly`?e(`finance.monthlyBudget`,`Monthly budget`):e(`finance.totalBudget`,`Total budget`)}),(0,G.jsx)(`input`,{type:`number`,step:`0.01`,value:S,onChange:e=>C(e.target.value),placeholder:`0.00`,className:U6})]})]}),(0,G.jsx)(Q,{className:`min-w-[180px]`,onClick:vt,disabled:ot.isPending,children:ot.isPending?e(`common.saving`,`Saving...`):e(`finance.create`,`Create`)})]})}),oe&&f&&p&&(0,G.jsx)(q6,{title:e(`finance.adjustWallet`,`Adjust wallet`),size:`md`,onClose:()=>se(!1),children:(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:W6,children:e(`finance.selectUser`,`Select user`)}),(0,G.jsx)(`select`,{value:w??``,onChange:e=>T(e.target.value?Number(e.target.value):null),className:U6,children:(At||[]).map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.username},e.id))})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:W6,children:e(`finance.transactionType`,`Type`)}),(0,G.jsxs)(`select`,{value:E,onChange:e=>D(e.target.value),className:U6,children:[(0,G.jsx)(`option`,{value:`deposit`,children:e(`finance.deposit`,`Deposit`)}),(0,G.jsx)(`option`,{value:`withdraw`,children:e(`finance.withdraw`,`Withdraw`)})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:W6,children:e(`finance.amount`,`Amount`)}),(0,G.jsx)(`input`,{type:`number`,step:`0.01`,min:`0`,value:O,onChange:e=>k(e.target.value),placeholder:`0.00`,className:U6})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:W6,children:e(`finance.costCenters`,`Cost centers`)}),(0,G.jsxs)(`select`,{value:M??``,onChange:e=>N(e.target.value?Number(e.target.value):null),className:U6,children:[(0,G.jsx)(`option`,{value:``,children:e(`finance.noCostCenter`,`No cost center`)}),(nt||[]).map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:W6,children:e(`common.description`,`Description`)}),(0,G.jsx)(`input`,{type:`text`,value:A,onChange:e=>j(e.target.value),placeholder:e(`finance.descriptionOptional`,`Description (optional)`),className:U6})]}),(0,G.jsx)(Q,{className:`min-w-[180px]`,onClick:Et,disabled:_t,children:_t?e(`common.saving`,`Saving...`):e(`finance.applyAdjustment`,`Apply adjustment`)})]})}),H&&d&&p&&(0,G.jsx)(q6,{title:e(`finance.manageMembers`,`Manage cost center members`),size:`lg`,onClose:()=>ce(!1),children:(0,G.jsxs)(`div`,{className:`space-y-5`,children:[(0,G.jsxs)(`div`,{className:`grid gap-5 md:grid-cols-2`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:W6,children:e(`finance.costCenters`,`Cost centers`)}),(0,G.jsx)(`select`,{value:P??``,onChange:e=>F(e.target.value?Number(e.target.value):null),className:U6,children:(nt||[]).filter(e=>!e.is_private).map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.name},e.id))})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:W6,children:e(`finance.selectUser`,`Select user`)}),(0,G.jsxs)(`select`,{value:I??``,onChange:e=>L(e.target.value?Number(e.target.value):null),className:U6,children:[(0,G.jsx)(`option`,{value:``,children:e(`finance.selectUser`,`Select user`)}),Mt.map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.username},e.id))]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 rounded border border-bambu-dark-tertiary bg-bambu-dark-secondary px-3 py-2`,children:[(0,G.jsx)(`input`,{id:`memberCanPrint`,type:`checkbox`,checked:R,onChange:e=>z(e.target.checked),className:`rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,G.jsx)(`label`,{htmlFor:`memberCanPrint`,className:`text-sm text-bambu-gray`,children:e(`finance.memberCanPrint`,`Member can print`)})]}),(0,G.jsx)(`div`,{className:`flex items-end`,children:(0,G.jsx)(Q,{className:`min-w-[180px]`,onClick:Dt,disabled:ht.isPending||I==null,children:ht.isPending?e(`common.saving`,`Saving...`):e(`finance.addMember`,`Add member`)})})]}),(0,G.jsx)(`div`,{className:`overflow-auto rounded-lg border border-bambu-dark-tertiary`,children:(0,G.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,G.jsx)(`thead`,{children:(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary bg-bambu-dark text-bambu-gray`,children:[(0,G.jsx)(`th`,{className:G6,children:e(`common.name`,`Name`)}),(0,G.jsx)(`th`,{className:G6,children:e(`finance.canPrint`,`Can print`)}),(0,G.jsx)(`th`,{className:G6,children:e(`common.actions`,`Actions`)})]})}),(0,G.jsxs)(`tbody`,{children:[(at?.members||[]).map(t=>(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/60 text-white`,children:[(0,G.jsx)(`td`,{className:K6,children:At.find(e=>e.id===t.user_id)?.username||`User ${t.user_id}`}),(0,G.jsx)(`td`,{className:K6,children:t.can_print?e(`common.yes`,`Yes`):e(`common.no`,`No`)}),(0,G.jsx)(`td`,{className:K6,children:(0,G.jsx)(Q,{size:`sm`,variant:`danger`,onClick:()=>Ot(t.user_id),disabled:gt.isPending,children:e(`common.remove`,`Remove`)})})]},t.id)),(at?.members||[]).length===0&&(0,G.jsx)(`tr`,{children:(0,G.jsx)(`td`,{colSpan:3,className:`py-3 text-bambu-gray`,children:e(`finance.noMembers`,`No members assigned.`)})})]})]})})]})}),le&&(l||u)&&(0,G.jsx)(q6,{title:e(`finance.editCostCenter`,`Edit cost center`),size:`md`,onClose:()=>ue(!1),children:(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:W6,children:e(`finance.costCenterName`,`Name`)}),(0,G.jsx)(`input`,{type:`text`,value:he,onChange:e=>ge(e.target.value),placeholder:e(`finance.costCenterName`,`Name`),className:U6,disabled:!l})]}),(0,G.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:W6,children:e(`finance.budgetType`,`Budget type`)}),(0,G.jsxs)(`select`,{value:_e,onChange:e=>ve(e.target.value),className:U6,disabled:!u,children:[(0,G.jsx)(`option`,{value:`monthly`,children:e(`finance.monthlyBudget`,`Monthly budget`)}),(0,G.jsx)(`option`,{value:`total`,children:e(`finance.totalBudget`,`Total budget`)})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:W6,children:_e===`monthly`?e(`finance.monthlyBudget`,`Monthly budget`):e(`finance.totalBudget`,`Total budget`)}),(0,G.jsx)(`input`,{type:`number`,step:`0.01`,value:ye,onChange:e=>be(e.target.value),placeholder:`0.00`,className:U6,disabled:!u})]})]}),(0,G.jsx)(Q,{className:`min-w-[180px]`,onClick:yt,disabled:ct.isPending||st.isPending||pe==null,children:ct.isPending||st.isPending?e(`common.saving`,`Saving...`):e(`common.save`,`Save`)})]})}),(0,G.jsxs)(`div`,{className:`grid gap-6 ${g&&o?`xl:grid-cols-2`:``}`,children:[g&&(0,G.jsxs)(Md,{children:[(0,G.jsxs)(Nd,{children:[(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`finance.myCostCenters`,`My cost centers`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:e(`finance.costCentersHint`,`Review budget limits and keep costs under control`)})]}),(0,G.jsxs)(Pd,{className:`space-y-3`,children:[rt&&(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`common.loading`,`Loading...`)}),!rt&&(!nt||nt.length===0)&&(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`finance.noCostCenters`,`No cost centers found.`)}),!rt&&nt&&nt.length>0&&(0,G.jsx)(`div`,{className:`overflow-auto rounded-lg border border-bambu-dark-tertiary`,children:(0,G.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,G.jsx)(`thead`,{children:(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary bg-bambu-dark text-bambu-gray`,children:[(0,G.jsx)(`th`,{className:G6,children:e(`common.name`,`Name`)}),Bt&&(0,G.jsx)(`th`,{className:G6,children:e(`finance.owner`,`Owner`)}),(0,G.jsx)(`th`,{className:G6,children:e(`finance.balance`,`Account balance`)}),(0,G.jsx)(`th`,{className:G6,children:e(`finance.budget`,`Budget`)}),Bt&&(0,G.jsx)(`th`,{className:G6,children:e(`common.actions`,`Actions`)})]})}),(0,G.jsx)(`tbody`,{children:nt.map(t=>{let n=l||u,r=!t.is_private&&l;return(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/60 text-white`,children:[(0,G.jsx)(`td`,{className:K6,children:t.name}),Bt&&(0,G.jsx)(`td`,{className:K6,children:t.is_private?W(t.owner_user_id):e(`finance.shared`,`Shared`)}),(0,G.jsxs)(`td`,{className:K6,children:[kt,t.total_balance.toFixed(2)]}),(0,G.jsx)(`td`,{className:K6,children:(0,G.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[(0,G.jsx)(`span`,{children:Ht(t)}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:t.budget_mode===`monthly`?e(`finance.monthlyBudget`,`Monthly budget`):t.budget_mode===`total`?e(`finance.totalBudget`,`Total budget`):e(`finance.noBudget`,`No budget`)})]})}),Bt&&(0,G.jsx)(`td`,{className:K6,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Q,{size:`sm`,variant:`ghost`,onClick:()=>bt(t.id),disabled:!n,title:n?e(`common.edit`,`Edit`):e(`finance.cannotEditPrivateCostCenter`,`Private cost centers cannot be edited here`),className:`p-1.5 sm:p-2`,children:(0,G.jsx)(Ol,{className:`w-4 h-4`})}),r&&(0,G.jsx)(Q,{size:`sm`,variant:`ghost`,onClick:()=>Ke({id:t.id,name:t.name}),disabled:lt.isPending,title:e(`common.delete`,`Delete`),className:`text-red-400 hover:text-red-300 hover:bg-red-500/10 p-1.5 sm:p-2`,children:(0,G.jsx)(ju,{className:`w-4 h-4`})})]})})]},t.id)})})]})})]})]}),o&&(0,G.jsxs)(Md,{children:[(0,G.jsxs)(Nd,{children:[(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`finance.recentTransactions`,`Recent transactions`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:e(`finance.transactionsHint`,`Filter by type and cost center, then navigate pages`)})]}),(0,G.jsxs)(Pd,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{className:`grid gap-4 lg:grid-cols-[minmax(0,1fr)_minmax(0,1fr)_auto] xl:grid-cols-[minmax(0,1fr)_minmax(0,1fr)_minmax(0,1fr)_auto] items-end`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:W6,children:e(`finance.transactionType`,`Type`)}),(0,G.jsxs)(`select`,{value:ee,onChange:e=>te(e.target.value),className:U6,children:[(0,G.jsx)(`option`,{value:`all`,children:e(`finance.allTypes`)}),(0,G.jsx)(`option`,{value:`deposit`,children:e(`finance.deposit`)}),(0,G.jsx)(`option`,{value:`withdraw`,children:e(`finance.withdraw`)}),(0,G.jsx)(`option`,{value:`print_charge`,children:e(`finance.printCharge`)})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:W6,children:e(`finance.costCenters`,`Cost centers`)}),(0,G.jsxs)(`select`,{value:ne,onChange:e=>re(e.target.value===`all`?`all`:Number(e.target.value)),className:U6,children:[(0,G.jsx)(`option`,{value:`all`,children:e(`finance.allCostCenters`)}),(nt||[]).map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]})]}),Pt&&(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`common.loading`,`Loading...`)}),!Pt&&(!Ft||Ft.length===0)&&(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`finance.noTransactions`,`No transactions available.`)}),!Pt&&Ft.length>0&&Rt.length===0&&(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`finance.noTransactionsForFilter`,`No transactions match the selected filters.`)}),!Pt&&Rt.length>0&&(0,G.jsx)(`div`,{className:`overflow-auto rounded-lg border border-bambu-dark-tertiary`,children:(0,G.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,G.jsx)(`thead`,{children:(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary bg-bambu-dark text-bambu-gray`,children:[(0,G.jsx)(`th`,{className:G6,children:e(`common.date`,`Date`)}),Bt&&(0,G.jsx)(`th`,{className:G6,children:e(`common.user`,`User`)}),(0,G.jsx)(`th`,{className:G6,children:e(`finance.costCenter`,`Cost center`)}),(0,G.jsx)(`th`,{className:G6,children:e(`finance.transactionType`,`Type`)}),(0,G.jsx)(`th`,{className:G6,children:e(`common.description`,`Description`)}),(0,G.jsx)(`th`,{className:G6,children:e(`finance.amount`,`Amount`)}),(0,G.jsx)(`th`,{className:G6,children:e(`finance.balanceAfter`,`Balance after`)}),Bt&&(0,G.jsx)(`th`,{className:G6,children:e(`common.actions`,`Actions`)})]})}),(0,G.jsx)(`tbody`,{children:Rt.map(n=>{let r=n.amount>=0,i=n.cost_center_id==null?null:(nt||[]).find(e=>e.id===n.cost_center_id),a=jt.get(n.user_id),o=n.transaction_type===`print_charge`?$He(n.description??null):null,s=o?.isPartial??!1;return(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/60 text-white`,children:[(0,G.jsx)(`td`,{className:K6,children:eUe(n.created_at,t.language)}),Bt&&(0,G.jsx)(`td`,{className:K6,children:a||e(`finance.userWithId`,`User #{{id}}`,{id:n.user_id})}),(0,G.jsx)(`td`,{className:K6,children:i?.name||`-`}),(0,G.jsx)(`td`,{className:K6,children:(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,G.jsx)(`span`,{children:Vt(n.transaction_type)}),s&&(0,G.jsx)(`span`,{className:`rounded border border-yellow-500/40 bg-yellow-500/10 px-2 py-0.5 text-[11px] text-yellow-300`,children:o&&o.partialType?e(`finance.partialStatus.${o.partialType}`,o.partialType):e(`finance.partial`,`Partial`)})]})}),(0,G.jsx)(`td`,{className:K6,children:(o?.cleanedDescription??n.description)||`-`}),(0,G.jsxs)(`td`,{className:`${K6} ${r?`text-green-400`:`text-red-400`}`,children:[r?`+`:`-`,kt,Math.abs(n.amount).toFixed(2)]}),(0,G.jsx)(`td`,{className:K6,children:n.balance_after==null?`-`:`${n.balance_after<0?`-`:``}${kt}${Math.abs(n.balance_after).toFixed(2)}`}),Bt&&(0,G.jsx)(`td`,{className:K6,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Q,{size:`sm`,variant:`secondary`,onClick:()=>Ct(n),disabled:dt.isPending,children:(0,G.jsx)(Ol,{className:`w-4 h-4`})}),(0,G.jsx)(Q,{size:`sm`,variant:`danger`,onClick:()=>Je(n.id),disabled:ut.isPending,children:(0,G.jsx)(ju,{className:`w-4 h-4`})})]})})]},n.id)})})]})}),!Pt&&Rt.length>0&&(0,G.jsx)(`div`,{className:`flex justify-end pt-2 lg:pt-0`,children:(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[(0,G.jsx)(`button`,{type:`button`,onClick:()=>V(0),disabled:B===0||Pt,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,"aria-label":e(`finance.first`,`First`),children:(0,G.jsx)(hs,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>V(e=>Math.max(0,e-50)),disabled:B===0||Pt,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,"aria-label":e(`finance.prev`,`Previous`),children:(0,G.jsx)(ps,{className:`w-4 h-4`})}),(0,G.jsx)(`span`,{className:`text-bambu-gray px-1 whitespace-nowrap`,children:e(`finance.pageNumberOf`,`Page {{page}} of {{total}}`,{page:zt,total:Lt})}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>V(e=>e+50),disabled:Pt||zt>=Lt,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,"aria-label":e(`finance.next`,`Next`),children:(0,G.jsx)(fs,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>V(Math.max(0,(Lt-1)*50)),disabled:Pt||zt>=Lt,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,"aria-label":e(`finance.last`,`Last`),children:(0,G.jsx)(gs,{className:`w-4 h-4`})})]})})]})]}),xe&&Ce!==null&&(0,G.jsx)(q6,{title:e(`finance.editTransaction`,`Edit Transaction`),onClose:()=>Se(!1),size:`md`,children:(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:W6,children:e(`common.user`,`User`)}),(0,G.jsxs)(`select`,{className:U6,value:Te||``,onChange:e=>Ee(e.target.value?Number(e.target.value):null),children:[(0,G.jsx)(`option`,{value:``,children:e(`finance.selectUser`,`Select user...`)}),At.map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.username},e.id))]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:W6,children:e(`finance.costCenter`,`Cost center (optional)`)}),(0,G.jsxs)(`select`,{className:U6,value:De||``,onChange:e=>Oe(e.target.value?Number(e.target.value):null),children:[(0,G.jsx)(`option`,{value:``,children:e(`finance.noCostCenter`,`Personal (no cost center)`)}),(nt||[]).map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:W6,children:e(`finance.amount`,`Amount`)}),(0,G.jsx)(`input`,{type:`number`,step:`0.01`,className:U6,value:ke,onChange:e=>Ae(e.target.value),placeholder:e(`finance.amountExample`,`e.g., 10.50`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:W6,children:e(`common.description`,`Description`)}),(0,G.jsx)(`textarea`,{className:`${U6} resize-none`,rows:3,value:je,onChange:e=>Me(e.target.value),placeholder:e(`finance.manualAdjustmentExample`,`e.g., Manual adjustment`)})]}),(0,G.jsxs)(`div`,{className:`flex justify-end gap-2 pt-4`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>Se(!1),children:e(`common.cancel`,`Cancel`)}),(0,G.jsx)(Q,{onClick:wt,disabled:dt.isPending,children:e(`common.save`,`Save`)})]})]})}),Ne&&(0,G.jsx)(q6,{title:e(`finance.addManualPrint`,`Add manual print`),onClose:()=>Pe(!1),size:`md`,children:(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:W6,children:e(`common.user`,`User`)}),(0,G.jsxs)(`select`,{className:U6,value:Fe||``,onChange:e=>Ie(e.target.value?Number(e.target.value):null),children:[(0,G.jsx)(`option`,{value:``,children:e(`finance.selectUser`,`Select user...`)}),At.map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.username},e.id))]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:W6,children:e(`finance.costCenter`,`Cost center`)}),(0,G.jsxs)(`select`,{className:U6,value:Le||``,onChange:e=>Re(e.target.value?Number(e.target.value):null),children:[(0,G.jsx)(`option`,{value:``,children:e(`finance.selectCostCenter`,`Select cost center...`)}),(nt||[]).map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:W6,children:e(`finance.amount`,`Amount`)}),(0,G.jsx)(`input`,{type:`number`,step:`0.01`,className:U6,value:ze,onChange:e=>Be(e.target.value),placeholder:e(`finance.amountExample`,`e.g., 4.00`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:W6,children:e(`common.description`,`Description`)}),(0,G.jsx)(`input`,{type:`text`,value:Ve,onChange:e=>He(e.target.value),placeholder:e(`finance.descriptionOptional`,`Description (optional)`),className:U6})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:W6,children:e(`common.date`,`Date`)}),(0,G.jsx)(`input`,{type:`datetime-local`,value:Ue,onChange:e=>We(e.target.value),className:U6})]}),(0,G.jsxs)(`div`,{className:`flex justify-end gap-2 pt-4`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>Pe(!1),children:e(`common.cancel`,`Cancel`)}),(0,G.jsx)(Q,{onClick:Tt,disabled:ft.isPending,children:ft.isPending?e(`common.saving`,`Saving...`):e(`finance.addManualPrint`,`Add manual print`)})]})]})}),Ge&&(0,G.jsx)(Zd,{title:e(`common.delete`,`Delete`),message:e(`finance.confirmDeleteCostCenter`,`Delete cost center "{{name}}"?`,{name:Ge.name}),confirmText:e(`common.delete`,`Delete`),variant:`danger`,isLoading:lt.isPending,onConfirm:xt,onCancel:()=>Ke(null)}),qe!=null&&(0,G.jsx)(Zd,{title:e(`finance.deleteTransaction`,`Delete transaction`),message:e(`finance.deleteTransactionConfirm`,`Delete this transaction? Balances will be recalculated automatically.`),confirmText:e(`common.delete`,`Delete`),variant:`danger`,isLoading:ut.isPending,onConfirm:St,onCancel:()=>Je(null)})]})]}):(0,G.jsxs)(`div`,{className:`p-4 md:p-8 space-y-6`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Gu,{className:`h-6 w-6 text-bambu-green`}),(0,G.jsx)(`h1`,{className:`text-2xl font-bold text-white`,children:e(`finance.title`,`Finance`)})]}),(0,G.jsx)(`div`,{children:(0,G.jsx)(`p`,{className:`text-bambu-gray mt-2 max-w-2xl`,children:e(`finance.subtitle`,`Wallet, personal transactions, and cost centers`)})}),(0,G.jsx)(Md,{children:(0,G.jsx)(Pd,{className:`py-8 text-center text-bambu-gray`,children:e(`finance.noAccess`,`You do not have permission to view finance data.`)})})]})}var J6={PLA:`GFL99`,"PLA-CF":`GFL98`,"PLA SILK":`GFL96`,"PLA HIGH SPEED":`GFL95`,PETG:`GFG99`,"PETG HF":`GFG96`,"PETG-CF":`GFG98`,PCTG:`GFG97`,ABS:`GFB99`,ASA:`GFB98`,PC:`GFC99`,PA:`GFN99`,"PA-CF":`GFN98`,NYLON:`GFN99`,TPU:`GFU99`,PVA:`GFS99`,HIPS:`GFS98`,PE:`GFP99`,PP:`GFP97`};function Y6(e){let t=(e||``).toUpperCase().trim();return t&&(J6[t]||J6[t.replace(/[-\s]?CF$/,``)]||J6[t.replace(/\+$/,``)]||J6[t.split(/[-\s]/)[0]])||``}function X6(e){let t=e.replace(/@.+$/,``).trim();return t.startsWith(`# `)?t.slice(2).trim():t}var Z6={local:0,orca_cloud:1,cloud:2,builtin:3};function nUe(e){let{localPresets:t,orcaProfiles:n,cloudSettings:r,builtinFilaments:i}=e,a=[],o=e=>e.trim().toLowerCase(),s=new Set,c=new Set,l=new Set,u=(e,t,...n)=>{let r=n.filter(e=>!!e);if(r.some(e=>s.has(e)))return!1;let i=`${e}|${o(t)}`;return c.has(i)?!1:(r.forEach(e=>s.add(e)),c.add(i),l.add(o(t)),!0)};for(let e of t??[]){let t=X6(e.name),n=e.filament_type||pU(t).material;u(`local`,t)&&a.push({id:`local_${e.id}`,name:t,source:`local`,filamentId:Y6(n),filamentType:n||``})}for(let e of n??[]){let t=X6(e.name),n=pU(t).material;u(`orca_cloud`,t,e.setting_id)&&a.push({id:`orca_${e.setting_id}`,name:t,source:`orca_cloud`,filamentId:Y6(n),filamentType:n})}for(let e of r??[]){let t=X6(e.name),n=e.setting_id.startsWith(`GFS`)?xU(e.setting_id):``;u(`cloud`,t,e.setting_id,n||void 0)&&a.push({id:e.setting_id,name:t,source:`cloud`,filamentId:n,filamentType:pU(t).material})}for(let e of i??[]){let t=e.filament_id.startsWith(`GF`)?`GFS${e.filament_id.slice(2)}`:e.filament_id;l.has(o(e.name))||u(`builtin`,e.name,e.filament_id,t)&&a.push({id:`builtin_${e.filament_id}`,name:e.name,source:`builtin`,filamentId:e.filament_id,filamentType:pU(e.name).material})}return a.sort((e,t)=>e.source===t.source?e.name.localeCompare(t.name):Z6[e.source]-Z6[t.source])}async function rUe(e,t){if(e.filamentId)return e.filamentId;if(e.source!==`cloud`||!t)return``;try{return(await t(e.id)).filament_id||``}catch{return``}}var Q6=e=>(Math.trunc(parseFloat(e)*1e3)/1e3).toFixed(3),$6=`HS00`,e8=`HH00`,t8=e=>{let t=e.match(/^([A-Z]{2}\d{2})/);return t?t[1]:$6},iUe=e=>t8(e)===e8?`HF`:`S`,n8=e=>{for(let t of[`High Flow_`,`High Flow `,`Standard_`,`Standard `,`HF_`,`HF `,`S_`,`S `])if(e.startsWith(t))return e.slice(t.length);let t=e.indexOf(`_`);return t>0?e.slice(t+1):e};function r8({profile:e,onEdit:t,onCopy:n,selectionMode:r,isSelected:i,onToggleSelect:a,note:o}){let s=iUe(e.nozzle_id),c=e.nozzle_diameter;return(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[r&&(0,G.jsx)(`button`,{onClick:a,className:`text-bambu-gray hover:text-white transition-colors p-1`,children:i?(0,G.jsx)(hu,{className:`w-4 h-4 text-bambu-green`}):(0,G.jsx)(_u,{className:`w-4 h-4`})}),(0,G.jsxs)(`button`,{onClick:()=>{r&&a?a():t()},className:`flex-1 text-left px-3 py-2 bg-bambu-dark rounded hover:bg-bambu-dark-tertiary transition-colors ${i?`ring-1 ring-bambu-green`:``}`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-bambu-green font-mono text-sm font-bold whitespace-nowrap`,children:Q6(e.k_value)}),(0,G.jsx)(`span`,{className:`text-white text-sm truncate flex-1`,title:e.name,children:e.name||`Unnamed`}),o&&(0,G.jsx)(`span`,{title:`Has note`,children:(0,G.jsx)(bu,{className:`w-3 h-3 text-yellow-500`})}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:[s,` `,c]})]}),o&&(0,G.jsxs)(`div`,{className:`text-xs mt-0.5 truncate text-yellow-500/70`,title:o,children:[`Note: `,o.length>50?o.substring(0,50)+`...`:o]})]}),!r&&n&&(0,G.jsx)(`button`,{onClick:e=>{e.stopPropagation(),n()},className:`text-bambu-gray hover:text-white transition-colors p-1`,title:`Copy profile`,children:(0,G.jsx)(zs,{className:`w-4 h-4`})})]})}function i8({profile:e,printerId:t,nozzleDiameter:n,existingProfiles:r=[],builtinFilaments:i=[],filamentPresets:a=[],isDualNozzle:o=!1,supportsFlowType:s=!0,initialNote:c=``,initialNoteKey:l=null,onClose:u,onSave:d,onSaveNote:f,hasPermission:p}){let{t:m}=U(),{showToast:h}=Bd(),[g,_]=(0,y.useState)(e?.name||``),[v,b]=(0,y.useState)(e?.k_value?Q6(e.k_value):`0.020`),[x,S]=(0,y.useState)(e?.filament_id||``),[C,w]=(0,y.useState)(e?t8(e.nozzle_id):$6),[T,E]=(0,y.useState)(e?.nozzle_diameter||n),[D,O]=(0,y.useState)(e?[e.extruder_id]:o?[0,1]:[0]),[k,A]=(0,y.useState)(!1),[j,M]=(0,y.useState)({current:0,total:0}),[N,P]=(0,y.useState)(c),[F,I]=(0,y.useState)(``),{schedule:L}=wU(),R=y.useMemo(()=>e?.filament_id?i.find(t=>t.filament_id===e.filament_id)?.name||n8(r.find(t=>t.filament_id===e.filament_id)?.name||e.name||``)||e.filament_id:``,[e,r,i]),z=y.useMemo(()=>{let e=[[`local`,m(`kProfiles.modal.source.local`)],[`orca_cloud`,m(`kProfiles.modal.source.orcaCloud`)],[`cloud`,m(`kProfiles.modal.source.bambuCloud`)],[`builtin`,m(`kProfiles.modal.source.builtin`)]],t=F.trim().toLowerCase(),n=t?a.filter(e=>e.name.toLowerCase().includes(t)):a;return e.map(([e,t])=>({source:e,label:t,items:n.filter(t=>t.source===e)})).filter(e=>e.items.length>0)},[a,F,m]),B=q({mutationFn:e=>(console.log(`[KProfile] Calling API...`),Z.setKProfile(t,e)),onSuccess:(t,n)=>{if(console.log(`[KProfile] Save success:`,t),h(m(`kProfiles.toast.profileSaved`)),f&&N!==c){let t;t=N===``&&l?l:e&&e.slot_id>0?e.setting_id||`slot_${e.slot_id}_${e.filament_id}_${e.extruder_id}`:`name_${g}_${n.filament_id}`,f(t,N)}A(!0),L(()=>{A(!1),d()},2500)},onError:e=>{console.error(`[KProfile] Save error:`,e),h(e.message,`error`),A(!1)}}),V=q({mutationFn:e=>(console.log(`[KProfile] Deleting profile...`),Z.deleteKProfile(t,e)),onSuccess:e=>{console.log(`[KProfile] Delete success:`,e),h(m(`kProfiles.toast.profileDeleted`)),A(!0),L(()=>{A(!1),u()},4e3)},onError:e=>{console.error(`[KProfile] Delete error:`,e),h(e.message,`error`),A(!1)}}),[ee,te]=(0,y.useState)(!1),ne=()=>{e&&V.mutate({slot_id:e.slot_id,extruder_id:e.extruder_id,nozzle_id:e.nozzle_id,nozzle_diameter:e.nozzle_diameter,filament_id:e.filament_id,setting_id:e.setting_id})};return(0,G.jsxs)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,children:[(0,G.jsxs)(Md,{className:`w-full max-w-md relative`,children:[k&&(0,G.jsxs)(`div`,{className:`absolute inset-0 bg-bambu-dark-secondary/90 flex flex-col items-center justify-center z-10 rounded-lg`,children:[(0,G.jsx)(Y,{className:`w-8 h-8 text-bambu-green animate-spin mb-3`}),(0,G.jsx)(`p`,{className:`text-white font-medium`,children:j.total>1?m(`kProfiles.modal.savingExtruder`,{current:j.current,total:j.total}):m(`kProfiles.modal.syncing`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-sm mt-1`,children:m(`kProfiles.modal.pleaseWait`)})]}),(0,G.jsxs)(Pd,{className:`p-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,G.jsx)(`h2`,{className:`text-xl font-semibold text-white`,children:m(e?`kProfiles.modal.editTitle`:`kProfiles.modal.addTitle`)}),(0,G.jsx)(`button`,{onClick:u,className:`text-bambu-gray hover:text-white transition-colors`,disabled:k,children:(0,G.jsx)($u,{className:`w-5 h-5`})})]}),(0,G.jsxs)(`form`,{onSubmit:async n=>{if(n.preventDefault(),o&&!e&&D.length===0){h(m(`kProfiles.toast.selectAtLeastOneExtruder`),`error`);return}let r=parseFloat(v).toFixed(6),i=`${C}-${T}`,s=e&&e.nozzle_id||i,c=e?e.nozzle_diameter:T,l=e?.filament_id||``;if(!e){let e=a.find(e=>e.id===x);if(!e){h(m(`kProfiles.toast.selectFilament`),`error`);return}if(l=await rUe(e,Z.getCloudSettingDetail),!l){h(m(`kProfiles.toast.filamentNotResolvable`,{name:e.name}),`error`);return}}if(e||D.length===1){let t={name:g,k_value:r,filament_id:l,nozzle_id:s,nozzle_diameter:c,extruder_id:e?e.extruder_id:D[0],setting_id:e?.setting_id,slot_id:e?.slot_id??0};console.log(`[KProfile] Saving profile:`,t),B.mutate(t);return}A(!0),M({current:1,total:D.length});let u=D.map(e=>({name:g,k_value:r,filament_id:l,nozzle_id:i,nozzle_diameter:T,extruder_id:e,setting_id:void 0,slot_id:0}));console.log(`[KProfile] Saving ${u.length} profiles in batch:`,u);try{await Z.setKProfilesBatch(t,u),h(m(`kProfiles.toast.profilesSaved`,{count:D.length})),f&&N&&f(`name_${g}_${l}`,N)}catch(e){console.error(`[KProfile] Failed to save batch:`,e),h(m(`kProfiles.toast.failedToSaveBatch`),`error`),A(!1),M({current:0,total:0});return}M({current:D.length,total:D.length}),L(()=>{A(!1),M({current:0,total:0}),d()},3e3)},className:`p-4 space-y-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:m(`kProfiles.modal.profileName`)}),(0,G.jsx)(`input`,{type:`text`,value:g,onChange:e=>_(e.target.value),disabled:!!e,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none ${e?`opacity-60 cursor-not-allowed`:``}`,placeholder:m(`kProfiles.modal.profileNamePlaceholder`),required:!e})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:m(`kProfiles.modal.kValue`)}),(0,G.jsx)(`input`,{type:`text`,inputMode:`decimal`,value:v,onChange:e=>{let t=e.target.value;(t===``||/^\d*\.?\d*$/.test(t))&&b(t)},onBlur:e=>{let t=parseFloat(e.target.value);isNaN(t)||b((Math.trunc(t*1e3)/1e3).toFixed(3))},className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none font-mono`,placeholder:m(`kProfiles.modal.kValuePlaceholder`),required:!0}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:m(`kProfiles.modal.kValueHelp`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:m(`kProfiles.modal.filament`)}),e?(0,G.jsx)(`div`,{className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white opacity-60`,children:R||e.filament_id}):(0,G.jsxs)(`div`,{className:`border border-bambu-dark-tertiary rounded-lg overflow-hidden`,children:[(0,G.jsxs)(`div`,{className:`relative border-b border-bambu-dark-tertiary`,children:[(0,G.jsx)(Yl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,G.jsx)(`input`,{type:`text`,value:F,onChange:e=>I(e.target.value),placeholder:m(`kProfiles.modal.searchFilaments`),className:`w-full pl-10 pr-3 py-2 bg-bambu-dark text-white placeholder-bambu-gray focus:outline-none`})]}),(0,G.jsx)(`div`,{className:`max-h-56 overflow-y-auto bg-bambu-dark`,children:z.length===0?(0,G.jsx)(`p`,{className:`px-3 py-3 text-xs text-bambu-gray`,children:a.length===0?m(`kProfiles.modal.noFilamentsHelp`):m(`kProfiles.modal.noFilamentMatches`)}):z.map(e=>(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`sticky top-0 z-10 flex items-center gap-2 px-3 py-1.5 bg-bambu-dark-secondary border-y border-bambu-dark-tertiary`,children:[(0,G.jsx)(`span`,{className:`text-xs font-bold uppercase tracking-wider text-bambu-green`,children:e.label}),(0,G.jsx)(`span`,{className:`text-[10px] text-bambu-gray`,children:e.items.length})]}),e.items.map(e=>(0,G.jsx)(`button`,{type:`button`,onClick:()=>{S(e.id),g||_(`${C===e8?`HF`:`S`} ${e.name}`)},className:`w-full text-left px-3 py-1.5 text-sm transition-colors ${x===e.id?`bg-bambu-green/20 text-white`:`text-white hover:bg-bambu-dark-tertiary`}`,children:e.name},e.id))]},e.source))})]})]}),(0,G.jsxs)(`div`,{className:s?`grid grid-cols-2 gap-4`:``,children:[(0,G.jsxs)(`div`,{className:s?``:`hidden`,children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:m(`kProfiles.modal.flowType`)}),(0,G.jsxs)(`select`,{value:C,onChange:t=>{let n=t.target.value;if(w(n),!e&&x&&!g){let e=a.find(e=>e.id===x);e&&_(`${n===e8?`HF`:`S`} ${e.name}`)}},disabled:!!e,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none ${e?`opacity-60 cursor-not-allowed`:``}`,children:[(0,G.jsx)(`option`,{value:e8,children:m(`kProfiles.modal.highFlow`)}),(0,G.jsx)(`option`,{value:$6,children:m(`kProfiles.modal.standard`)})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:m(`kProfiles.modal.nozzleSize`)}),(0,G.jsxs)(`select`,{value:T,onChange:e=>E(e.target.value),disabled:!!e,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none ${e?`opacity-60 cursor-not-allowed`:``}`,children:[(0,G.jsx)(`option`,{value:`0.2`,children:`0.2mm`}),(0,G.jsx)(`option`,{value:`0.4`,children:`0.4mm`}),(0,G.jsx)(`option`,{value:`0.6`,children:`0.6mm`}),(0,G.jsx)(`option`,{value:`0.8`,children:`0.8mm`})]})]})]}),o&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:m(e?`kProfiles.modal.extruder`:`kProfiles.modal.extruders`)}),e?(0,G.jsx)(`div`,{className:`px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white opacity-60`,children:e.extruder_id===1?m(`kProfiles.modal.left`):m(`kProfiles.modal.right`)}):(0,G.jsxs)(`div`,{className:`flex gap-4`,children:[(0,G.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:D.includes(1),onChange:e=>{e.target.checked?O([...D,1]):O(D.filter(e=>e!==1))},className:`w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green focus:ring-offset-0 accent-bambu-green`}),(0,G.jsx)(`span`,{className:`text-white`,children:m(`kProfiles.modal.left`)})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:D.includes(0),onChange:e=>{e.target.checked?O([...D,0]):O(D.filter(e=>e!==0))},className:`w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green focus:ring-offset-0 accent-bambu-green`}),(0,G.jsx)(`span`,{className:`text-white`,children:m(`kProfiles.modal.right`)})]})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:m(`kProfiles.modal.notes`)}),(0,G.jsx)(`textarea`,{value:N,onChange:e=>P(e.target.value),placeholder:m(`kProfiles.modal.notesPlaceholder`),rows:2,className:`w-full px-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 resize-none`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:m(`kProfiles.modal.notesHelp`)})]}),(0,G.jsxs)(`div`,{className:`flex gap-2 pt-4`,children:[e&&(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:()=>te(!0),disabled:V.isPending||k||!p(`kprofiles:delete`),title:p(`kprofiles:delete`)?void 0:m(`kProfiles.permission.noDelete`),className:`text-red-500 hover:bg-red-500/10`,children:V.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(ju,{className:`w-4 h-4`})}),(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:u,disabled:k,className:`flex-1`,children:m(`common.cancel`)}),(0,G.jsxs)(Q,{type:`submit`,disabled:B.isPending||k||!p(e?`kprofiles:update`:`kprofiles:create`),title:p(e?`kprofiles:update`:`kprofiles:create`)?void 0:m(e?`kProfiles.permission.noUpdate`:`kProfiles.permission.noCreate`),className:`flex-1`,children:[B.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Sc,{className:`w-4 h-4`}),m(`common.save`)]})]})]})]})]}),ee&&(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-[60]`,children:(0,G.jsx)(Md,{className:`w-full max-w-sm`,children:(0,G.jsxs)(Pd,{className:`p-6`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3 mb-4`,children:[(0,G.jsx)(`div`,{className:`w-10 h-10 rounded-full bg-red-500/20 flex items-center justify-center`,children:(0,G.jsx)(ju,{className:`w-5 h-5 text-red-500`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`text-lg font-semibold text-white`,children:m(`kProfiles.deleteConfirm.title`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:m(`kProfiles.deleteConfirm.cannotUndo`)})]})]}),(0,G.jsx)(`p`,{className:`text-bambu-gray mb-6`,children:m(`kProfiles.deleteConfirm.message`,{name:e?.name})}),(0,G.jsxs)(`div`,{className:`flex gap-3`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>te(!1),className:`flex-1`,children:m(`common.cancel`)}),(0,G.jsxs)(Q,{onClick:()=>{te(!1),ne()},disabled:V.isPending,className:`flex-1 bg-red-500 hover:bg-red-600 text-white`,children:[V.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(ju,{className:`w-4 h-4`}),m(`common.delete`)]})]})]})})})]})}var a8={NOZZLE_DIAMETER:`bambusy_kprofiles_nozzle`,SORT_OPTION:`bambusy_kprofiles_sort`};function aUe(){let{t:e}=U(),{showToast:t}=Bd(),{hasPermission:n}=Ed(),[r,i]=(0,y.useState)(null),[a,o]=(0,y.useState)(()=>localStorage.getItem(a8.NOZZLE_DIAMETER)||`0.4`),[s,c]=(0,y.useState)(null),[l,u]=(0,y.useState)(!1),[d,f]=(0,y.useState)(null),[p,m]=(0,y.useState)(``),[h,g]=(0,y.useState)(`all`),[_,v]=(0,y.useState)(`all`),[b,x]=(0,y.useState)(()=>localStorage.getItem(a8.SORT_OPTION)||`name`),[S,C]=(0,y.useState)(!1),[w,T]=(0,y.useState)(new Set),[E,D]=(0,y.useState)(!1),[O,k]=(0,y.useState)(!1),A=(0,y.useCallback)(e=>`${e.slot_id}_${e.extruder_id}`,[]);(0,y.useEffect)(()=>{localStorage.setItem(a8.NOZZLE_DIAMETER,a)},[a]),(0,y.useEffect)(()=>{localStorage.setItem(a8.SORT_OPTION,b)},[b]);let{data:j,isLoading:M}=K({queryKey:[`printers`],queryFn:Z.getPrinters}),{data:N,isLoading:P,isFetching:F,error:I,refetch:L}=K({queryKey:[`kprofiles`,r,a],queryFn:async()=>{console.log(`[KProfiles] Fetching profiles for printer`,r,`nozzle`,a);let e=await Z.getKProfiles(r,a);return console.log(`[KProfiles] Received profiles:`,e?.profiles?.length||0,`profiles`),e},enabled:!!r,retry:!1,staleTime:0,gcTime:0,refetchOnMount:`always`}),{data:R}=K({queryKey:[`builtinFilaments`],queryFn:()=>Z.getBuiltinFilaments(),staleTime:3e5}),{data:z}=K({queryKey:[`filamentIdMap`],queryFn:()=>Z.getFilamentIdMap(),staleTime:3e5}),{data:B}=K({queryKey:[`localPresets`],queryFn:()=>Z.getLocalPresets(),retry:!1}),{data:V}=K({queryKey:[`orcaCloudProfilesForKProfiles`],queryFn:()=>Z.orcaCloudListProfiles(),retry:!1}),{data:ee}=K({queryKey:[`cloudSettings`],queryFn:()=>Z.getCloudSettings(),retry:!1}),{data:te,refetch:ne}=K({queryKey:[`kprofile-notes`,r],queryFn:()=>Z.getKProfileNotes(r),enabled:!!r,staleTime:3e4}),re=I?.message?.includes(`not connected`);(0,y.useEffect)(()=>{if(!r&&j&&j.length>0){let e=j.find(e=>e.is_active);e&&i(e.id)}},[r,j]),(0,y.useEffect)(()=>{if(r){let e=setTimeout(()=>{L()},150);return()=>clearTimeout(e)}},[r,a]);let ie=j?.filter(e=>e.is_active)||[],ae=y.useMemo(()=>{let e=new Map;if(R)for(let t of R)e.set(t.filament_id,t.name);if(z)for(let[t,n]of Object.entries(z))e.has(t)||e.set(t,n);return e},[R,z]),oe=y.useMemo(()=>Array.from(ae.entries()).map(([e,t])=>({filament_id:e,name:t})),[ae]),se=y.useMemo(()=>nUe({localPresets:B?.filament,orcaProfiles:V?.filament,cloudSettings:ee?.filament,builtinFilaments:R}),[B?.filament,V?.filament,ee?.filament,R]),H=y.useCallback(e=>ae.get(e.filament_id)||n8(e.name),[ae]),ce=y.useMemo(()=>N?.profiles?N.profiles.filter(e=>{let t=p.toLowerCase(),n=!t||e.name.toLowerCase().includes(t)||e.filament_id.toLowerCase().includes(t),r=h===`all`||h===`left`&&e.extruder_id===1||h===`right`&&e.extruder_id===0,i=_===`all`||_===`hf`&&e.nozzle_id.startsWith(`HH`)||_===`s`&&e.nozzle_id.startsWith(`HS`);return n&&r&&i}).sort((e,t)=>{switch(b){case`k_value`:return parseFloat(e.k_value)-parseFloat(t.k_value);case`filament`:return H(e).localeCompare(H(t));default:return e.name.localeCompare(t.name)}}):[],[N?.profiles,p,h,_,b,H]),le=j?.find(e=>e.id===r),ue=le?.nozzle_count===2,de=le?.supports_nozzle_flow_type??!0;(0,y.useEffect)(()=>{de||v(`all`)},[de]),(0,y.useEffect)(()=>{let e=e=>{e.target instanceof HTMLInputElement||e.target instanceof HTMLTextAreaElement||e.target instanceof HTMLSelectElement||s||l||d||(e.key===`r`||e.key===`R`?(e.preventDefault(),L()):e.key===`n`||e.key===`N`?(e.preventDefault(),u(!0)):e.key===`Escape`&&S&&(e.preventDefault(),C(!1),T(new Set)))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[s,l,d,S,L]);let fe=(0,y.useCallback)(()=>{if(!N?.profiles||N.profiles.length===0){t(e(`kProfiles.toast.noProfilesToExport`),`error`);return}let n={version:1,exported_at:new Date().toISOString(),printer:le?.name||`Unknown`,nozzle_diameter:a,profiles:N.profiles.map(e=>({name:e.name,k_value:e.k_value,filament_id:e.filament_id,nozzle_id:e.nozzle_id,nozzle_diameter:e.nozzle_diameter,extruder_id:e.extruder_id}))},r=new Blob([JSON.stringify(n,null,2)],{type:`application/json`}),i=URL.createObjectURL(r),o=document.createElement(`a`);o.href=i,o.download=`kprofiles_${le?.name||`printer`}_${a}mm_${new Date().toISOString().split(`T`)[0]}.json`,document.body.appendChild(o),o.click(),document.body.removeChild(o),URL.revokeObjectURL(i),t(e(`kProfiles.toast.exportedProfiles`,{count:N.profiles.length}))},[N?.profiles,le,a,t,e]),pe=(0,y.useCallback)(()=>{let n=document.createElement(`input`);n.type=`file`,n.accept=`.json`,n.onchange=async n=>{let i=n.target.files?.[0];if(i)try{let n=await i.text(),o=JSON.parse(n);if(!o.profiles||!Array.isArray(o.profiles)){t(e(`kProfiles.toast.invalidFileFormat`),`error`);return}let s=0;for(let e of o.profiles)if(!(!e.name||!e.k_value||!e.filament_id))try{await Z.setKProfile(r,{name:e.name,k_value:parseFloat(e.k_value).toFixed(6),filament_id:e.filament_id,nozzle_id:e.nozzle_id||`${$6}-${a}`,nozzle_diameter:e.nozzle_diameter||a,extruder_id:e.extruder_id??0,slot_id:0}),s++,await new Promise(e=>setTimeout(e,500))}catch(t){console.error(`Failed to import profile:`,e.name,t)}t(e(`kProfiles.toast.importedProfiles`,{count:s,total:o.profiles.length})),L()}catch(n){console.error(`Import error:`,n),t(e(`kProfiles.toast.failedToParseImport`),`error`)}},n.click()},[r,a,t,L,e]),me=(0,y.useCallback)(e=>{T(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),he=(0,y.useCallback)(()=>{T(new Set(ce.map(e=>A(e))))},[ce,A]),ge=(0,y.useCallback)(()=>{w.size!==0&&D(!0)},[w.size]),_e=(0,y.useCallback)(async()=>{let n=ce.filter(e=>w.has(A(e)));k(!0);let i=0;for(let e of n)try{await Z.deleteKProfile(r,{slot_id:e.slot_id,extruder_id:e.extruder_id,nozzle_id:e.nozzle_id,nozzle_diameter:e.nozzle_diameter,filament_id:e.filament_id,setting_id:e.setting_id}),i++,await new Promise(e=>setTimeout(e,300))}catch(t){console.error(`Failed to delete profile:`,e.name,t)}t(e(`kProfiles.toast.profilesDeleted`,{count:i})),k(!1),D(!1),C(!1),T(new Set),L()},[r,w,ce,t,L,A,e]),ve=(0,y.useCallback)(e=>{let t=[];return e.setting_id&&t.push(e.setting_id),t.push(`slot_${e.slot_id}_${e.filament_id}_${e.extruder_id}`),t.push(`name_${e.name}_${e.filament_id}`),t},[]),ye=(0,y.useCallback)(async(n,i)=>{if(r)try{await Z.setKProfileNote(r,n,i),ne()}catch(n){console.error(`Failed to save note:`,n),t(e(`kProfiles.toast.failedToSaveNote`),`error`)}},[r,ne,t,e]),be=(0,y.useCallback)(e=>{if(!te?.notes)return{note:``,key:null};let t=ve(e);for(let e of t)if(te.notes[e])return{note:te.notes[e],key:e};return{note:``,key:null}},[te,ve]),xe=(0,y.useCallback)(e=>be(e).note,[be]);return M?(0,G.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,G.jsx)(Y,{className:`w-8 h-8 text-bambu-green animate-spin`})}):!j||j.length===0?(0,G.jsx)(Md,{children:(0,G.jsxs)(Pd,{className:`py-12 text-center`,children:[(0,G.jsx)(_s,{className:`w-12 h-12 text-bambu-gray mx-auto mb-4`}),(0,G.jsx)(`h3`,{className:`text-lg font-semibold text-white mb-2`,children:e(`kProfiles.noPrintersConfigured`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray`,children:e(`kProfiles.addPrinterInSettings`)})]})}):ie.length===0?(0,G.jsx)(Md,{children:(0,G.jsxs)(Pd,{className:`py-12 text-center`,children:[(0,G.jsx)(Fl,{className:`w-12 h-12 text-bambu-gray mx-auto mb-4`}),(0,G.jsx)(`h3`,{className:`text-lg font-semibold text-white mb-2`,children:e(`kProfiles.noActivePrinters`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray`,children:e(`kProfiles.enablePrinterConnection`)})]})}):(0,G.jsxs)(G.Fragment,{children:[F&&!P&&(0,G.jsxs)(`div`,{className:`fixed inset-0 bg-black/50 flex flex-col items-center justify-center z-40`,children:[(0,G.jsx)(Y,{className:`w-10 h-10 text-bambu-green animate-spin mb-3`}),(0,G.jsx)(`p`,{className:`text-white font-medium`,children:e(`kProfiles.loadingProfiles`)})]}),(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-4 mb-6`,children:[(0,G.jsxs)(`div`,{className:`flex-1 min-w-48`,children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:e(`kProfiles.printer`)}),(0,G.jsx)(`select`,{value:r||``,onChange:e=>i(parseInt(e.target.value)),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:ie.map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.name},e.id))})]}),(0,G.jsxs)(`div`,{className:`w-32`,children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:e(`kProfiles.nozzle`)}),(0,G.jsxs)(`select`,{value:a,onChange:e=>o(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,G.jsx)(`option`,{value:`0.2`,children:`0.2mm`}),(0,G.jsx)(`option`,{value:`0.4`,children:`0.4mm`}),(0,G.jsx)(`option`,{value:`0.6`,children:`0.6mm`}),(0,G.jsx)(`option`,{value:`0.8`,children:`0.8mm`})]})]}),(0,G.jsxs)(`div`,{className:`flex items-end gap-2`,children:[(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>L(),disabled:F||!n(`kprofiles:read`),title:n(`kprofiles:read`)?void 0:e(`kProfiles.permission.noRead`),children:[(0,G.jsx)(zl,{className:`w-4 h-4 ${F?`animate-spin`:``}`}),e(`kProfiles.refresh`)]}),(0,G.jsxs)(Q,{onClick:()=>u(!0),disabled:!n(`kprofiles:create`),title:n(`kprofiles:create`)?void 0:e(`kProfiles.permission.noCreate`),children:[(0,G.jsx)(Ml,{className:`w-4 h-4`}),e(`kProfiles.addProfile`)]})]})]}),(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-4 mb-4`,children:[(0,G.jsxs)(`div`,{className:`flex-1 min-w-48 relative`,children:[(0,G.jsx)(Yl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,G.jsx)(`input`,{type:`text`,value:p,onChange:e=>m(e.target.value),placeholder:e(`kProfiles.searchPlaceholder`),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`})]}),ue&&(0,G.jsx)(`div`,{className:`w-36`,children:(0,G.jsxs)(`select`,{value:h,onChange:e=>g(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,G.jsx)(`option`,{value:`all`,children:e(`kProfiles.allExtruders`)}),(0,G.jsx)(`option`,{value:`left`,children:e(`kProfiles.leftOnly`)}),(0,G.jsx)(`option`,{value:`right`,children:e(`kProfiles.rightOnly`)})]})}),de&&(0,G.jsx)(`div`,{className:`w-32`,children:(0,G.jsxs)(`select`,{value:_,onChange:e=>v(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,G.jsx)(`option`,{value:`all`,children:e(`kProfiles.allFlow`)}),(0,G.jsx)(`option`,{value:`hf`,children:e(`kProfiles.hfOnly`)}),(0,G.jsx)(`option`,{value:`s`,children:e(`kProfiles.sOnly`)})]})}),(0,G.jsx)(`div`,{className:`w-32`,children:(0,G.jsxs)(`select`,{value:b,onChange:e=>x(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,G.jsx)(`option`,{value:`name`,children:e(`kProfiles.sortName`)}),(0,G.jsx)(`option`,{value:`k_value`,children:e(`kProfiles.sortKValue`)}),(0,G.jsx)(`option`,{value:`filament`,children:e(`kProfiles.sortFilament`)})]})})]}),(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-2 mb-6`,children:[(0,G.jsxs)(Q,{variant:`secondary`,onClick:fe,disabled:!N?.profiles?.length||!n(`kprofiles:read`),title:n(`kprofiles:read`)?void 0:e(`kProfiles.permission.noExport`),children:[(0,G.jsx)(Js,{className:`w-4 h-4`}),e(`kProfiles.export`)]}),(0,G.jsxs)(Q,{variant:`secondary`,onClick:pe,disabled:!n(`kprofiles:create`),title:n(`kprofiles:create`)?void 0:e(`kProfiles.permission.noImport`),children:[(0,G.jsx)(Ru,{className:`w-4 h-4`}),e(`kProfiles.import`)]}),(0,G.jsx)(`div`,{className:`flex-1`}),S?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(Q,{variant:`secondary`,onClick:he,children:[(0,G.jsx)(hu,{className:`w-4 h-4`}),e(`kProfiles.selectAll`)]}),(0,G.jsxs)(Q,{variant:`secondary`,onClick:ge,disabled:w.size===0||!n(`kprofiles:delete`),className:`text-red-500 hover:bg-red-500/10`,title:n(`kprofiles:delete`)?void 0:e(`kProfiles.permission.noDelete`),children:[(0,G.jsx)(ju,{className:`w-4 h-4`}),e(`kProfiles.delete`),` (`,w.size,`)`]}),(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>{C(!1),T(new Set)},children:[(0,G.jsx)($u,{className:`w-4 h-4`}),e(`common.cancel`)]})]}):(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>C(!0),disabled:!ce.length||!n(`kprofiles:delete`),title:n(`kprofiles:delete`)?void 0:e(`kProfiles.permission.noDelete`),children:[(0,G.jsx)(hu,{className:`w-4 h-4`}),e(`kProfiles.select`)]})]}),P?(0,G.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,G.jsx)(Y,{className:`w-8 h-8 text-bambu-green animate-spin`})}):re?(0,G.jsx)(Md,{children:(0,G.jsxs)(Pd,{className:`py-12 text-center`,children:[(0,G.jsx)(Ju,{className:`w-12 h-12 text-bambu-gray mx-auto mb-4`}),(0,G.jsx)(`h3`,{className:`text-lg font-semibold text-white mb-2`,children:e(`kProfiles.printerOffline`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray mb-4`,children:e(`kProfiles.printerOfflineDesc`)}),(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>L(),children:[(0,G.jsx)(zl,{className:`w-4 h-4`}),e(`common.refresh`)]})]})}):ce.length>0?ue?(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`text-sm font-medium text-bambu-gray mb-2 px-1`,children:e(`kProfiles.leftExtruder`)}),(0,G.jsx)(`div`,{className:`space-y-1`,children:ce.filter(e=>e.extruder_id===1).map(e=>(0,G.jsx)(r8,{profile:e,onEdit:()=>c(e),onCopy:()=>f(e),selectionMode:S,isSelected:w.has(A(e)),onToggleSelect:()=>me(A(e)),note:xe(e)},A(e)))})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`text-sm font-medium text-bambu-gray mb-2 px-1`,children:e(`kProfiles.rightExtruder`)}),(0,G.jsx)(`div`,{className:`space-y-1`,children:ce.filter(e=>e.extruder_id===0).map(e=>(0,G.jsx)(r8,{profile:e,onEdit:()=>c(e),onCopy:()=>f(e),selectionMode:S,isSelected:w.has(A(e)),onToggleSelect:()=>me(A(e)),note:xe(e)},A(e)))})]})]}):(0,G.jsx)(`div`,{className:`space-y-1`,children:ce.map(e=>(0,G.jsx)(r8,{profile:e,onEdit:()=>c(e),onCopy:()=>f(e),selectionMode:S,isSelected:w.has(A(e)),onToggleSelect:()=>me(A(e)),note:xe(e)},A(e)))}):p||h!==`all`||_!==`all`?(0,G.jsx)(Md,{children:(0,G.jsxs)(Pd,{className:`py-12 text-center`,children:[(0,G.jsx)(Yl,{className:`w-12 h-12 text-bambu-gray mx-auto mb-4`}),(0,G.jsx)(`h3`,{className:`text-lg font-semibold text-white mb-2`,children:e(`kProfiles.noMatchingProfiles`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray`,children:e(`kProfiles.noMatchingProfilesDesc`)})]})}):(0,G.jsx)(Md,{children:(0,G.jsxs)(Pd,{className:`py-12 text-center`,children:[(0,G.jsx)(Sc,{className:`w-12 h-12 text-bambu-gray mx-auto mb-4`}),(0,G.jsx)(`h3`,{className:`text-lg font-semibold text-white mb-2`,children:e(`kProfiles.noKProfiles`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray mb-4`,children:e(`kProfiles.noKProfilesDesc`,{diameter:a})}),(0,G.jsxs)(Q,{onClick:()=>u(!0),children:[(0,G.jsx)(Ml,{className:`w-4 h-4`}),e(`kProfiles.createFirstProfile`)]})]})}),s&&r&&(()=>{let{note:e,key:t}=be(s);return(0,G.jsx)(i8,{profile:s,printerId:r,nozzleDiameter:a,existingProfiles:N?.profiles,builtinFilaments:oe,filamentPresets:se,isDualNozzle:ue,supportsFlowType:de,initialNote:e,initialNoteKey:t,onSaveNote:ye,hasPermission:n,onClose:()=>{console.log(`[KProfiles] Edit modal onClose - refetching profiles...`),c(null),L()},onSave:()=>{c(null),L()}})})(),l&&r&&(0,G.jsx)(i8,{printerId:r,nozzleDiameter:a,existingProfiles:N?.profiles,builtinFilaments:oe,filamentPresets:se,isDualNozzle:ue,supportsFlowType:de,onSaveNote:ye,hasPermission:n,onClose:()=>{u(!1),L()},onSave:()=>{u(!1),L()}}),d&&r&&(0,G.jsx)(i8,{printerId:r,nozzleDiameter:a,existingProfiles:N?.profiles,builtinFilaments:oe,filamentPresets:se,isDualNozzle:ue,supportsFlowType:de,onSaveNote:ye,hasPermission:n,profile:{...d,slot_id:0,name:`${d.name} (Copy)`},onClose:()=>{f(null),L()},onSave:()=>{f(null),L()}}),E&&(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,children:(0,G.jsx)(Md,{className:`w-full max-w-sm`,children:(0,G.jsxs)(Pd,{className:`p-6`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3 mb-4`,children:[(0,G.jsx)(`div`,{className:`w-10 h-10 rounded-full bg-red-500/20 flex items-center justify-center`,children:(0,G.jsx)(ju,{className:`w-5 h-5 text-red-500`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`text-lg font-semibold text-white`,children:e(`kProfiles.bulkDelete.title`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`kProfiles.bulkDelete.cannotUndo`)})]})]}),(0,G.jsx)(`p`,{className:`text-bambu-gray mb-6`,children:e(`kProfiles.bulkDelete.message`,{count:w.size})}),(0,G.jsxs)(`div`,{className:`flex gap-3`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>D(!1),disabled:O,className:`flex-1`,children:e(`common.cancel`)}),(0,G.jsxs)(Q,{onClick:_e,disabled:O,className:`flex-1 bg-red-500 hover:bg-red-600 text-white`,children:[O?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(ju,{className:`w-4 h-4`}),e(`common.delete`)]})]})]})})})]})}var o8=[`PLA`,`PETG`,`PCTG`,`ABS`,`ASA`,`TPU`,`PC`,`PA`,`PVA`,`HIPS`,`PP`,`PET`,`NYLON`],oUe={PLA:`E8E8E8`,PETG:`4A90D9`,ABS:`E67E22`,ASA:`D35400`,TPU:`9B59B6`,PC:`BDC3C7`,PA:`2ECC71`,NYLON:`2ECC71`,PVA:`F1C40F`,HIPS:`95A5A6`,PP:`ECF0F1`,PET:`3498DB`};function sUe(e){let t=e.toUpperCase();for(let e of o8)if(RegExp(`\\b${e}\\b`).test(t))return e;return null}function cUe(e){let t=e.replace(/@.+$/,``).trim(),n=t.toUpperCase();for(let e of o8){let r=n.indexOf(e);if(r>0){let e=t.slice(0,r).trim();if(e&&e.length>1)return e}}return null}function s8({preset:e,onDelete:t,onExpand:n,isExpanded:r}){let{t:i}=U(),{hasPermission:a}=Ed(),o=e.filament_type||sUe(e.name),s=e.filament_vendor||cUe(e.name),c=null,l=!1;if(e.default_filament_colour)try{let t=JSON.parse(e.default_filament_colour),n=Array.isArray(t)?t[0]:t;typeof n==`string`&&/^#?[0-9a-fA-F]{6,8}$/.test(n.replace(`#`,``))&&(c=n.replace(`#`,``).slice(0,6),l=!0)}catch{let t=e.default_filament_colour;/^#?[0-9a-fA-F]{6,8}$/.test(t.replace(`#`,``))&&(c=t.replace(`#`,``).slice(0,6),l=!0)}return!c&&o&&(c=oUe[o.toUpperCase()]||null),(0,G.jsx)(Md,{className:`bg-bambu-dark border-bambu-dark-tertiary hover:border-bambu-dark-tertiary/80 transition-colors`,children:(0,G.jsxs)(Pd,{className:`p-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[e.preset_type===`filament`&&(0,G.jsx)(`div`,{className:`w-4 h-4 rounded-full border border-black/20 flex-shrink-0 ${!l&&!c?`opacity-25`:l?``:`opacity-50`}`,style:{backgroundColor:c?`#${c}`:`#666`}}),(0,G.jsx)(`span`,{className:`text-sm font-medium text-white truncate`,children:e.name})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[o&&(0,G.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-bambu-green/20 text-bambu-green`,children:o}),s&&(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:s}),(0,G.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`,children:i(`profiles.localProfiles.badge`)})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1 flex-shrink-0`,children:[a(`settings:update`)&&(0,G.jsx)(`button`,{onClick:()=>t(e.id),className:`p-1 text-bambu-gray hover:text-red-600 dark:hover:text-red-400 transition-colors`,title:i(`profiles.localProfiles.delete`),children:(0,G.jsx)(ju,{className:`w-3.5 h-3.5`})}),(0,G.jsx)(`button`,{onClick:()=>n(r?null:e.id),className:`p-1 text-bambu-gray hover:text-white transition-colors`,children:r?(0,G.jsx)(ms,{className:`w-3.5 h-3.5`}):(0,G.jsx)(ds,{className:`w-3.5 h-3.5`})})]})]}),r&&(0,G.jsxs)(`div`,{className:`mt-3 pt-3 border-t border-bambu-dark-tertiary text-xs space-y-1.5`,children:[o&&(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:i(`profiles.localProfiles.filamentType`)}),(0,G.jsx)(`span`,{className:`text-white`,children:o})]}),s&&(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:i(`profiles.localProfiles.vendor`)}),(0,G.jsx)(`span`,{className:`text-white`,children:s})]}),e.nozzle_temp_min!=null&&e.nozzle_temp_max!=null&&(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:i(`profiles.localProfiles.nozzleTemp`)}),(0,G.jsxs)(`span`,{className:`text-white`,children:[e.nozzle_temp_min,`–`,e.nozzle_temp_max,`°C`]})]}),e.filament_cost&&(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:i(`profiles.localProfiles.cost`)}),(0,G.jsx)(`span`,{className:`text-white`,children:e.filament_cost})]}),e.filament_density&&(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:i(`profiles.localProfiles.density`)}),(0,G.jsxs)(`span`,{className:`text-white`,children:[e.filament_density,` g/cm³`]})]}),e.pressure_advance&&(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:i(`profiles.localProfiles.pressureAdvance`)}),(0,G.jsx)(`span`,{className:`text-white`,children:e.pressure_advance})]}),e.compatible_printers&&(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:i(`profiles.localProfiles.compatiblePrinters`)}),(0,G.jsx)(`span`,{className:`text-white truncate ml-2`,children:(()=>{try{return JSON.parse(e.compatible_printers).join(`, `)}catch{return e.compatible_printers}})()})]}),e.inherits&&e.inherits!==e.name&&(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:i(`profiles.localProfiles.inheritsFrom`)}),(0,G.jsx)(`span`,{className:`text-white truncate ml-2`,children:e.inherits})]}),(0,G.jsxs)(`div`,{className:`flex justify-between`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:i(`profiles.localProfiles.source`)}),(0,G.jsx)(`span`,{className:`text-white capitalize`,children:e.source})]})]})]})})}function lUe(){let{t:e}=U(),{hasPermission:t}=Ed(),n=so(),{showToast:r}=Bd(),[i,a]=(0,y.useState)(``),[o,s]=(0,y.useState)(null),[c,l]=(0,y.useState)(!1),[u,d]=(0,y.useState)(null),{data:f,isLoading:p}=K({queryKey:[`localPresets`],queryFn:()=>Z.getLocalPresets()}),m=q({mutationFn:async e=>{let t=[];for(let n of Array.from(e)){let e=new FormData;e.append(`file`,n),t.push(await Z.importLocalPresets(e))}return t},onSuccess:t=>{n.invalidateQueries({queryKey:[`localPresets`]}),n.invalidateQueries({queryKey:[`slicerPresets`]});let i=0,a=0,o=0;for(let e of t)i+=e.imported,a+=e.skipped,o+=e.errors.length;i>0&&r(e(`profiles.localProfiles.toast.importSuccess`,{count:i})),a>0&&r(e(`profiles.localProfiles.toast.importSkipped`,{count:a}),`warning`),o>0&&r(e(`profiles.localProfiles.toast.importError`,{count:o}),`error`)},onError:e=>{r(e.message,`error`)}}),h=q({mutationFn:e=>Z.deleteLocalPreset(e),onSuccess:(t,i)=>{n.setQueryData([`localPresets`],e=>e&&{filament:e.filament.filter(e=>e.id!==i),printer:e.printer.filter(e=>e.id!==i),process:e.process.filter(e=>e.id!==i)}),n.invalidateQueries({queryKey:[`localPresets`]}),n.invalidateQueries({queryKey:[`slicerPresets`]}),d(null),r(e(`profiles.localProfiles.toast.deleted`))}}),g=(0,y.useCallback)(e=>{!e||e.length===0||m.mutate(e)},[m]),_=(0,y.useCallback)(e=>{e.preventDefault(),l(!1),g(e.dataTransfer.files)},[g]),v=(0,y.useCallback)(e=>{if(!i)return e;let t=i.toLowerCase();return e.filter(e=>e.name.toLowerCase().includes(t)||e.filament_type?.toLowerCase().includes(t)||e.filament_vendor?.toLowerCase().includes(t))},[i]),b=(0,y.useMemo)(()=>v(f?.filament||[]),[f?.filament,v]),x=(0,y.useMemo)(()=>v(f?.printer||[]),[f?.printer,v]),S=(0,y.useMemo)(()=>v(f?.process||[]),[f?.process,v]),C=b.length+x.length+S.length,w=(f?.filament?.length??0)+(f?.printer?.length??0)+(f?.process?.length??0)>0;return p?(0,G.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,G.jsx)(Y,{className:`w-8 h-8 text-bambu-green animate-spin`})}):(0,G.jsxs)(`div`,{className:`space-y-6`,children:[t(`settings:update`)&&(0,G.jsxs)(`div`,{onDragOver:e=>{e.preventDefault(),l(!0)},onDragLeave:()=>l(!1),onDrop:_,className:`relative border-2 border-dashed rounded-lg p-6 text-center transition-colors ${c?`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary hover:border-bambu-gray`}`,children:[(0,G.jsx)(`input`,{type:`file`,accept:`.json,.zip,.orca_filament,.bbscfg,.bbsflmt`,multiple:!0,className:`absolute inset-0 w-full h-full opacity-0 cursor-pointer`,onChange:e=>g(e.target.files)}),m.isPending?(0,G.jsxs)(`div`,{className:`flex items-center justify-center gap-2`,children:[(0,G.jsx)(Y,{className:`w-5 h-5 text-bambu-green animate-spin`}),(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:e(`profiles.localProfiles.importing`)})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Ru,{className:`w-8 h-8 text-bambu-gray mx-auto mb-2`}),(0,G.jsx)(`p`,{className:`text-sm text-white font-medium`,children:e(`profiles.localProfiles.import`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:e(`profiles.localProfiles.importDesc`)})]})]}),w&&(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(Yl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,G.jsx)(`input`,{type:`text`,value:i,onChange:e=>a(e.target.value),placeholder:e(`profiles.localProfiles.search`),className:`w-full pl-9 pr-4 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`})]}),!w&&!p&&(0,G.jsxs)(`div`,{className:`text-center py-12`,children:[(0,G.jsx)(jc,{className:`w-12 h-12 text-bambu-gray mx-auto mb-3 opacity-50`}),(0,G.jsx)(`p`,{className:`text-bambu-gray`,children:e(`profiles.localProfiles.noPresets`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray/60 mt-1`,children:e(`profiles.localProfiles.importDesc`)})]}),w&&C===0&&!p&&(0,G.jsxs)(`div`,{className:`text-center py-12`,children:[(0,G.jsx)(Yl,{className:`w-12 h-12 text-bambu-gray mx-auto mb-3 opacity-50`}),(0,G.jsx)(`p`,{className:`text-bambu-gray`,children:e(`profiles.localProfiles.noSearchResults`)})]}),C>0&&(0,G.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6`,children:[b.length>0&&(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,G.jsx)(Ys,{className:`w-4 h-4 text-bambu-green`}),(0,G.jsx)(`h3`,{className:`text-sm font-medium text-white`,children:e(`profiles.localProfiles.filament`)}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[`(`,b.length,`)`]})]}),(0,G.jsx)(`div`,{className:`space-y-2`,children:b.map(e=>(0,G.jsx)(s8,{preset:e,onDelete:e=>d(e),onExpand:s,isExpanded:o===e.id},e.id))})]}),S.length>0&&(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,G.jsx)(Gc,{className:`w-4 h-4 text-blue-600 dark:text-blue-400`}),(0,G.jsx)(`h3`,{className:`text-sm font-medium text-white`,children:e(`profiles.localProfiles.process`)}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[`(`,S.length,`)`]})]}),(0,G.jsx)(`div`,{className:`space-y-2`,children:S.map(e=>(0,G.jsx)(s8,{preset:e,onDelete:e=>d(e),onExpand:s,isExpanded:o===e.id},e.id))})]}),x.length>0&&(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,G.jsx)($l,{className:`w-4 h-4 text-orange-600 dark:text-orange-400`}),(0,G.jsx)(`h3`,{className:`text-sm font-medium text-white`,children:e(`profiles.localProfiles.printer`)}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[`(`,x.length,`)`]})]}),(0,G.jsx)(`div`,{className:`space-y-2`,children:x.map(e=>(0,G.jsx)(s8,{preset:e,onDelete:e=>d(e),onExpand:s,isExpanded:o===e.id},e.id))})]})]}),u!==null&&(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50`,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg p-6 max-w-sm mx-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,G.jsx)(_s,{className:`w-5 h-5 text-red-600 dark:text-red-400`}),(0,G.jsx)(`h3`,{className:`text-white font-medium`,children:e(`profiles.localProfiles.deleteConfirmTitle`)})]}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4`,children:e(`profiles.localProfiles.deleteConfirm`)}),(0,G.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,G.jsx)(Q,{variant:`secondary`,size:`sm`,onClick:()=>d(null),children:e(`profiles.localProfiles.cancel`)}),(0,G.jsxs)(Q,{variant:`danger`,size:`sm`,onClick:()=>h.mutate(u),disabled:h.isPending,children:[h.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(ju,{className:`w-4 h-4`}),e(`profiles.localProfiles.delete`)]})]})]})})]})}function uUe(e){let t=e.match(/@?\s*(?:BBL\s+)?(?:Bambu\s+Lab\s+)?([XPAH][1-9][A-Z]?(?:\s*(?:Carbon|mini))?|H2D)/i),n=e.match(/(\d+\.?\d*)\s*(?:mm\s*)?nozzle|nozzle\s*(\d+\.?\d*)/i),r=e.match(/(\d+\.?\d*)mm\s*(?:Standard|Fine|Extra Fine|Draft|Quality)?/i),i=e.match(/\b(PLA|PETG|ABS|ASA|TPU|PC|PA|PVA|HIPS|PP|PET(?:-?CF)?|PA(?:-?CF)?|PLA(?:-?CF)?)\b/i);return{printer:t?t[1].trim():null,nozzle:n?(n[1]||n[2])+`mm`:null,layerHeight:r?r[1]+`mm`:null,filamentType:i?i[1].toUpperCase():null}}function dUe({settings:e,lastSyncTime:t,onRefresh:n,isRefreshing:r,printers:i,t:a}){let[o,s]=(0,y.useState)(``),[c,l]=(0,y.useState)(`all`),[u,d]=(0,y.useState)(`all`),[f,p]=(0,y.useState)(`all`),[m,h]=(0,y.useState)(`all`),[g,_]=(0,y.useState)(`all`),[v,b]=(0,y.useState)(null),x=(0,y.useMemo)(()=>[...e.filament.map(e=>({...e,type:`filament`})),...e.printer.map(e=>({...e,type:`printer`})),...e.process.map(e=>({...e,type:`process`}))].map(e=>({...e,meta:uUe(e.name)})),[e]),S=(0,y.useMemo)(()=>{let e=new Set,t=new Set,n=new Set;return x.forEach(r=>{r.meta.nozzle&&e.add(r.meta.nozzle),r.meta.filamentType&&t.add(r.meta.filamentType),r.meta.layerHeight&&n.add(r.meta.layerHeight)}),{printers:i.map(e=>({id:e.id.toString(),name:e.name})),nozzles:Array.from(e).sort((e,t)=>parseFloat(e)-parseFloat(t)),filaments:Array.from(t).sort(),layerHeights:Array.from(n).sort((e,t)=>parseFloat(e)-parseFloat(t))}},[x,i]),C=(0,y.useMemo)(()=>u===`all`?null:i.find(e=>e.id.toString()===u)?.model||null,[u,i]),w=(0,y.useMemo)(()=>x.filter(e=>c===`all`||e.type===c).filter(e=>{if(u===`all`||!C)return!0;let t=e.meta.printer?.toLowerCase()||``,n=C.toLowerCase();return t.includes(n)||n.includes(t)}).filter(e=>f===`all`||e.meta.nozzle===f).filter(e=>m===`all`||e.meta.filamentType===m).filter(e=>g===`all`||e.meta.layerHeight===g).filter(e=>o===``||e.name.toLowerCase().includes(o.toLowerCase())).sort((e,t)=>e.name.localeCompare(t.name)),[x,c,u,C,f,m,g,o]),T=()=>{l(`all`),d(`all`),p(`all`),h(`all`),_(`all`),s(``)},E=c!==`all`||u!==`all`||f!==`all`||m!==`all`||g!==`all`||o!==``,D=e.filament.length+e.printer.length+e.process.length,O=e=>w.filter(t=>t.type===e);return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`space-y-4 mb-6`,children:[(0,G.jsxs)(`div`,{className:`flex flex-col sm:flex-row gap-3`,children:[(0,G.jsxs)(`div`,{className:`relative flex-1`,children:[(0,G.jsx)(Yl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,G.jsx)(`input`,{type:`text`,value:o,onChange:e=>s(e.target.value),placeholder:a(`profiles.cloudView.searchPlaceholder`),className:`w-full pl-10 pr-4 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none`})]}),(0,G.jsx)(`div`,{className:`flex gap-2`,children:(0,G.jsxs)(Q,{variant:`secondary`,onClick:n,disabled:r,children:[(0,G.jsx)(zl,{className:`w-4 h-4 ${r?`animate-spin`:``}`}),a(`profiles.cloudView.refresh`)]})})]}),(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,G.jsx)(xc,{className:`w-4 h-4 text-bambu-gray`}),(0,G.jsx)(d8,{label:a(`profiles.cloudView.filters.type`),value:c,options:[{value:`all`,label:a(`profiles.cloudView.filters.all`),count:D},{value:`filament`,label:a(`profiles.cloudView.filters.filament`),count:e.filament.length},{value:`printer`,label:a(`profiles.cloudView.filters.printer`),count:e.printer.length},{value:`process`,label:a(`profiles.cloudView.filters.process`),count:e.process.length}],onChange:e=>l(e)}),S.printers.length>0&&(0,G.jsx)(d8,{label:a(`profiles.cloudView.filters.printer`),value:u,options:[{value:`all`,label:a(`profiles.cloudView.filters.all`)},...S.printers.map(e=>({value:e.id,label:e.name}))],onChange:d}),S.nozzles.length>0&&(0,G.jsx)(d8,{label:a(`profiles.cloudView.filters.nozzle`),value:f,options:[{value:`all`,label:a(`profiles.cloudView.filters.all`)},...S.nozzles.map(e=>({value:e,label:e}))],onChange:p}),S.filaments.length>0&&(c===`all`||c===`filament`)&&(0,G.jsx)(d8,{label:a(`profiles.cloudView.filters.filament`),value:m,options:[{value:`all`,label:a(`profiles.cloudView.filters.all`)},...S.filaments.map(e=>({value:e,label:e}))],onChange:h}),S.layerHeights.length>0&&(c===`all`||c===`process`)&&(0,G.jsx)(d8,{label:a(`profiles.cloudView.filters.layer`),value:g,options:[{value:`all`,label:a(`profiles.cloudView.filters.all`)},...S.layerHeights.map(e=>({value:e,label:e}))],onChange:_}),E&&(0,G.jsx)(`button`,{onClick:T,className:`px-3 py-2 text-sm text-bambu-gray hover:text-white transition-colors`,children:a(`profiles.cloudView.clearFilters`)})]})]}),(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4 mb-4 text-sm text-bambu-gray`,children:[t&&(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(ks,{className:`w-3 h-3`}),a(`profiles.cloudView.lastSynced`),` `,$f(t.toISOString(),`system`,a)]}),(0,G.jsx)(`span`,{children:a(`profiles.cloudView.showingCount`,{showing:w.length,total:D})})]}),w.length===0?(0,G.jsxs)(`div`,{className:`text-center py-16`,children:[(0,G.jsx)(Gc,{className:`w-12 h-12 text-bambu-gray-dark mx-auto mb-4`}),(0,G.jsx)(`p`,{className:`text-bambu-gray`,children:a(`profiles.cloudView.noPresetsFound`)}),E&&(0,G.jsx)(`button`,{onClick:T,className:`mt-2 text-sm text-bambu-green hover:text-bambu-green-light`,children:a(`profiles.cloudView.clearFilters`)})]}):(0,G.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-6`,children:[(0,G.jsx)(c8,{icon:(0,G.jsx)(Ys,{className:`w-4 h-4 text-amber-600 dark:text-amber-400`}),title:a(`profiles.cloudView.columns.filament`),presets:O(`filament`),emptyText:a(`profiles.cloudView.noFilamentPresets`),onSelect:b}),(0,G.jsx)(c8,{icon:(0,G.jsx)($l,{className:`w-4 h-4 text-blue-600 dark:text-blue-400`}),title:a(`profiles.cloudView.columns.process`),presets:O(`process`),emptyText:a(`profiles.cloudView.noProcessPresets`),onSelect:b}),(0,G.jsx)(c8,{icon:(0,G.jsx)(Fl,{className:`w-4 h-4 text-purple-600 dark:text-purple-400`}),title:a(`profiles.cloudView.columns.printer`),presets:O(`printer`),emptyText:a(`profiles.cloudView.noPrinterPresets`),onSelect:b})]}),v&&(0,G.jsx)(pUe,{setting:v,onClose:()=>b(null),t:a})]})}function c8({icon:e,title:t,presets:n,emptyText:r,onSelect:i}){return(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-3 px-1`,children:[e,(0,G.jsx)(`h3`,{className:`text-sm font-medium text-bambu-gray`,children:t}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray-dark`,children:[`(`,n.length,`)`]})]}),(0,G.jsx)(`div`,{className:`space-y-1 max-h-[calc(100vh-320px)] overflow-y-auto pr-1`,children:n.length===0?(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray-dark px-3 py-2`,children:r}):n.map(e=>(0,G.jsx)(fUe,{preset:e,onClick:()=>i(e)},e.setting_id))})]})}function fUe({preset:e,onClick:t}){return(0,G.jsx)(`button`,{onClick:t,className:`w-full text-left px-3 py-2 rounded bg-bambu-dark hover:bg-bambu-dark-tertiary transition-colors`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-white text-sm truncate flex-1`,title:e.name,children:e.name}),e.meta.filamentType&&e.type===`filament`&&(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:e.meta.filamentType}),e.meta.layerHeight&&e.type===`process`&&(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:e.meta.layerHeight}),e.meta.printer&&(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:e.meta.printer})]})})}function pUe({setting:e,onClose:t,t:n}){let{data:r,isLoading:i,error:a}=K({queryKey:[`orcaCloudProfileDetail`,e.setting_id],queryFn:()=>Z.orcaCloudGetProfile(e.setting_id),retry:!1});return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/60 z-50 flex items-center justify-center p-4`,onClick:t,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-2xl max-w-4xl w-full max-h-[90vh] flex flex-col`,onClick:e=>e.stopPropagation(),children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h2`,{className:`text-lg font-bold text-white`,children:e.name}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:e.type})]}),(0,G.jsx)(`button`,{onClick:t,className:`text-bambu-gray hover:text-white p-1`,children:(0,G.jsx)($u,{className:`w-5 h-5`})})]}),(0,G.jsx)(`div`,{className:`flex-1 overflow-y-auto p-4`,children:i?(0,G.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,G.jsx)(Y,{className:`w-8 h-8 text-bambu-green animate-spin`})}):a?(0,G.jsx)(`p`,{className:`text-center text-bambu-gray py-16`,children:a.message}):r?(0,G.jsx)(`pre`,{className:`text-xs font-mono text-bambu-gray bg-bambu-dark p-3 rounded overflow-x-auto whitespace-pre`,children:JSON.stringify(r.setting,null,2)}):(0,G.jsx)(`p`,{className:`text-center text-bambu-gray py-16`,children:n(`profiles.cloudView.noPresetsFound`)})})]})})}function mUe(){let{t:e}=U(),t=so(),{showToast:n}=Bd(),{hasPermission:r}=Ed(),i=r(`orca_cloud:auth`),[a,o]=(0,y.useState)(null),[s,c]=(0,y.useState)(5e3),[l,u]=(0,y.useState)(null),{data:d,isLoading:f}=K({queryKey:[`orcaCloudStatus`],queryFn:Z.orcaCloudStatus}),p=!!d?.connected,{data:m,isLoading:h,refetch:g,isRefetching:_,error:v,dataUpdatedAt:b}=K({queryKey:[`orcaCloudProfiles`],queryFn:Z.orcaCloudListProfiles,enabled:p,retry:!1,staleTime:1e3*60*5}),{data:x=[]}=K({queryKey:[`printers`],queryFn:Z.getPrinters,enabled:p}),[S,C]=(0,y.useState)();(0,y.useEffect)(()=>{b&&C(new Date(b))},[b]);let w=()=>{o(null),c(5e3)},T=t=>{t===`access_denied`?u(e(`profiles.orcaCloud.errors.denied`)):t===`expired_token`&&u(e(`profiles.orcaCloud.errors.expired`)),w()},E=q({mutationFn:Z.orcaCloudDeviceStart,onSuccess:e=>{u(null),c(Math.max(1,e.interval)*1e3),o(e)},onError:t=>{u(t.message||e(`profiles.orcaCloud.errors.startFailed`))}}),D=q({mutationFn:Z.orcaCloudLogout,onSuccess:()=>{t.invalidateQueries({queryKey:[`orcaCloudStatus`]}),t.removeQueries({queryKey:[`orcaCloudProfiles`]}),n(e(`profiles.orcaCloud.toast.disconnected`))}}),{data:O,error:k}=K({queryKey:[`orcaCloudDevicePoll`,a?.user_code??`none`],queryFn:Z.orcaCloudDevicePoll,enabled:a!==null,gcTime:0,retry:!1,refetchOnWindowFocus:!1,refetchInterval:a===null?!1:s}),A=(0,y.useRef)(null);return(0,y.useEffect)(()=>{if(!a||!O)return;let r=O.status;if(r===`slow_down`){c(e=>e+5e3);return}r!==`authorization_pending`&&A.current!==r&&(A.current=r,r===`complete`?(w(),t.invalidateQueries({queryKey:[`orcaCloudStatus`]}),t.invalidateQueries({queryKey:[`orcaCloudProfiles`]}),n(e(`profiles.orcaCloud.connectedShort`))):T(r))},[O,a]),(0,y.useEffect)(()=>{a&&k&&(u(e(`profiles.orcaCloud.errors.pollFailed`)),w())},[k,a]),(0,y.useEffect)(()=>{a&&(A.current=null)},[a]),f?(0,G.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,G.jsx)(Y,{className:`w-8 h-8 text-bambu-green animate-spin`})}):(0,G.jsxs)(`div`,{children:[p&&(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-3 mb-6 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`w-2 h-2 rounded-full bg-bambu-green animate-pulse`}),(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:d?.email?(0,G.jsxs)(G.Fragment,{children:[e(`profiles.orcaCloud.connectedAs`),` `,(0,G.jsx)(`span`,{className:`text-white`,children:d.email})]}):(0,G.jsx)(`span`,{className:`text-white`,children:e(`profiles.orcaCloud.connectedShort`)})})]}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:()=>D.mutate(),disabled:D.isPending||!i,title:i?void 0:e(`profiles.orcaCloud.noLogoutPermission`),children:[(0,G.jsx)(nl,{className:`w-4 h-4`}),e(`profiles.orcaCloud.logout`)]})]}),p?h?(0,G.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,G.jsx)(Y,{className:`w-8 h-8 text-bambu-green animate-spin`})}):v?(0,G.jsxs)(`div`,{className:`text-center py-16`,children:[(0,G.jsx)(`p`,{className:`text-bambu-gray mb-4`,children:v.message}),(0,G.jsx)(Q,{onClick:()=>g(),children:e(`profiles.orcaCloud.retry`)})]}):m?(0,G.jsx)(dUe,{settings:m,lastSyncTime:S,onRefresh:()=>g(),isRefreshing:_,printers:x,t:e}):null:(0,G.jsx)(hUe,{pairing:a,connectError:l,onConnect:()=>E.mutate(),onCancel:w,isStarting:E.isPending,canManage:i,t:e})]})}function hUe({pairing:e,connectError:t,onConnect:n,onCancel:r,isStarting:i,canManage:a,t:o}){return e?(0,G.jsx)(Md,{children:(0,G.jsxs)(Pd,{className:`p-8 text-center max-w-md mx-auto`,children:[(0,G.jsx)(Ms,{className:`w-12 h-12 text-bambu-green mx-auto mb-4`}),(0,G.jsx)(`h2`,{className:`text-xl font-bold text-white mb-2`,children:o(`profiles.orcaCloud.device.title`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray mb-6`,children:o(`profiles.orcaCloud.device.instruction`)}),(0,G.jsx)(`p`,{className:`text-xs uppercase tracking-wide text-bambu-gray mb-2`,children:o(`profiles.orcaCloud.device.codeLabel`)}),(0,G.jsx)(`div`,{className:`mb-6 py-3 px-4 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg`,children:(0,G.jsx)(`span`,{className:`text-2xl font-mono font-bold tracking-[0.3em] text-white select-all`,children:e.user_code})}),(0,G.jsx)(`a`,{href:e.verification_uri_complete,target:`_blank`,rel:`noopener noreferrer`,children:(0,G.jsxs)(Q,{className:`w-full mb-3`,children:[(0,G.jsx)(tc,{className:`w-4 h-4`}),o(`profiles.orcaCloud.device.openButton`)]})}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray break-all mb-6`,children:o(`profiles.orcaCloud.device.manualHint`,{url:e.verification_uri})}),(0,G.jsxs)(`div`,{className:`flex items-center justify-center gap-2 text-sm text-bambu-gray mb-4`,children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin text-bambu-green`}),o(`profiles.orcaCloud.device.waiting`)]}),(0,G.jsx)(`button`,{type:`button`,onClick:r,className:`text-bambu-gray hover:text-white text-sm`,children:o(`profiles.orcaCloud.device.cancel`)})]})}):(0,G.jsx)(Md,{children:(0,G.jsxs)(Pd,{className:`p-8 text-center`,children:[(0,G.jsx)(Ms,{className:`w-12 h-12 text-bambu-green mx-auto mb-4`}),(0,G.jsx)(`h2`,{className:`text-xl font-bold text-white mb-2`,children:o(`profiles.orcaCloud.connect.title`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray mb-6 max-w-xl mx-auto`,children:o(`profiles.orcaCloud.connect.description`)}),(0,G.jsxs)(`div`,{className:`max-w-sm mx-auto`,children:[(0,G.jsxs)(Q,{onClick:n,disabled:i||!a,title:a?void 0:o(`profiles.orcaCloud.noConnectPermission`),className:`w-full`,children:[i?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(us,{className:`w-4 h-4`}),o(`profiles.orcaCloud.connectButton`)]}),t&&(0,G.jsxs)(`p`,{className:`mt-3 text-sm text-red-700 dark:text-red-400 flex items-center justify-center gap-2`,children:[(0,G.jsx)(_s,{className:`w-4 h-4 flex-shrink-0`}),t]})]})]})})}function l8(e,t){let n=`${e} ${t||``}`,r=n.match(/@?\s*(?:BBL\s+)?(?:Bambu\s+Lab\s+)?([XPAH][1-9][A-Z]?(?:\s*(?:Carbon|mini))?|H2D)/i),i=r?r[1].trim():null,a=n.match(/(\d+\.?\d*)\s*(?:mm\s*)?nozzle|nozzle\s*(\d+\.?\d*)/i),o=a?(a[1]||a[2])+`mm`:null,s=n.match(/(\d+\.?\d*)mm\s*(?:Standard|Fine|Extra Fine|Draft|Quality)?/i),c=s?s[1]+`mm`:null,l=n.match(/\b(PLA|PETG|ABS|ASA|TPU|PC|PA|PVA|HIPS|PP|PET(?:-?CF)?|PA(?:-?CF)?|PLA(?:-?CF)?)\b/i);return{printer:i,nozzle:o,layerHeight:c,filamentType:l?l[1].toUpperCase():null}}function u8(e){return/^(P[FPM]US|PF\d|PP\d)/.test(e)}function gUe({onSuccess:e,t}){let{showToast:n}=Bd(),[r,i]=(0,y.useState)(`email`),[a,o]=(0,y.useState)(``),[s,c]=(0,y.useState)(``),[l,u]=(0,y.useState)(``),[d,f]=(0,y.useState)(``),[p,m]=(0,y.useState)(`global`),[h,g]=(0,y.useState)(null),[_,v]=(0,y.useState)(null),[b,x]=(0,y.useState)(!1),S=q({mutationFn:()=>Z.cloudLogin(a,s,p),onSuccess:r=>{if(x(r.reason===`captcha`),r.success)n(t(`profiles.login.toast.loggedIn`)),e();else if(r.reason===`captcha`)return;else r.needs_verification?(g(r.verification_type||`email`),v(r.tfa_key||null),r.verification_type===`totp`?n(t(`profiles.login.toast.enterTotp`)):n(t(`profiles.login.toast.codeSent`)),i(`code`)):n(r.message,`error`)},onError:e=>{x(!1),n(e.message,`error`)}}),C=q({mutationFn:()=>Z.cloudVerify(a,l,_||void 0,p),onSuccess:r=>{x(r.reason===`captcha`),r.success?(n(t(`profiles.login.toast.loggedIn`)),e()):r.reason!==`captcha`&&n(r.message,`error`)},onError:e=>{x(!1),n(e.message,`error`)}}),w=q({mutationFn:()=>Z.cloudSetToken(d,p),onSuccess:()=>{n(t(`profiles.login.toast.tokenSet`)),e()},onError:e=>n(e.message,`error`)}),T=e=>{e.preventDefault(),r===`email`?S.mutate():r===`code`?C.mutate():r===`token`&&w.mutate()},E=S.isPending||C.isPending||w.isPending;return(0,G.jsx)(Md,{className:`max-w-md mx-auto`,children:(0,G.jsxs)(Pd,{children:[(0,G.jsxs)(`div`,{className:`text-center mb-6`,children:[(0,G.jsx)(`div`,{className:`inline-flex items-center justify-center w-12 h-12 rounded-xl bg-bambu-green/20 mb-3`,children:(0,G.jsx)(Ms,{className:`w-6 h-6 text-bambu-green`})}),(0,G.jsx)(`h2`,{className:`text-xl font-semibold text-white`,children:t(`profiles.login.title`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:t(`profiles.login.subtitle`)})]}),b&&r!==`token`&&(0,G.jsx)(`div`,{role:`alert`,className:`mb-4 p-3 rounded-lg border border-amber-500/40 bg-amber-500/10`,children:(0,G.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,G.jsx)(tu,{className:`w-4 h-4 text-amber-400 shrink-0 mt-0.5`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm font-medium text-amber-300`,children:t(`profiles.login.captchaTitle`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:t(`profiles.login.captchaBody`)}),(0,G.jsxs)(`button`,{type:`button`,onClick:()=>{x(!1),i(`token`)},className:`mt-2 text-xs text-bambu-green hover:underline flex items-center gap-1`,children:[(0,G.jsx)(Uc,{className:`w-3 h-3`}),t(`profiles.login.useToken`)]})]})]})}),(0,G.jsxs)(`form`,{onSubmit:T,className:`space-y-4`,children:[r===`email`&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:t(`profiles.login.email`)}),(0,G.jsx)(`input`,{type:`email`,value:a,onChange:e=>o(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none`,placeholder:`your@email.com`,required:!0})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:t(`profiles.login.password`)}),(0,G.jsx)(`input`,{type:`password`,value:s,onChange:e=>c(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none`,placeholder:`••••••••`,required:!0})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:t(`profiles.login.region`)}),(0,G.jsxs)(`select`,{value:p,onChange:e=>m(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,G.jsx)(`option`,{value:`global`,children:t(`profiles.login.regionGlobal`)}),(0,G.jsx)(`option`,{value:`china`,children:t(`profiles.login.regionChina`)})]})]})]}),r===`code`&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:t(h===`totp`?`profiles.login.totpCode`:`profiles.login.verificationCode`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:h===`totp`?t(`profiles.login.enterTotpHint`):t(`profiles.login.checkEmail`,{email:a})}),(0,G.jsx)(`input`,{type:`text`,value:l,onChange:e=>u(e.target.value.replace(/\D/g,``).slice(0,6)),className:`w-full px-3 py-3 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-center text-2xl tracking-widest font-mono focus:border-bambu-green focus:outline-none`,placeholder:`000000`,maxLength:6,required:!0})]}),r===`token`&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:t(`profiles.login.accessToken`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:t(`profiles.login.accessTokenHint`)}),(0,G.jsx)(`textarea`,{value:d,onChange:e=>f(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-xs font-mono placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none resize-none`,placeholder:`eyJ...`,rows:4,required:!0})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:t(`profiles.login.region`)}),(0,G.jsxs)(`select`,{value:p,onChange:e=>m(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,G.jsx)(`option`,{value:`global`,children:t(`profiles.login.regionGlobal`)}),(0,G.jsx)(`option`,{value:`china`,children:t(`profiles.login.regionChina`)})]})]})]}),(0,G.jsxs)(`div`,{className:`flex gap-2 max-[550px]:flex-wrap max-[550px]:items-center`,children:[r===`code`&&(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:()=>i(`email`),className:`flex-1`,children:t(`profiles.login.back`)}),(0,G.jsxs)(Q,{type:`submit`,disabled:E,className:`flex-1`,children:[E?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(tl,{className:`w-4 h-4`}),t(r===`email`?`profiles.login.loginButton`:r===`code`?`profiles.login.verifyButton`:`profiles.login.setTokenButton`)]})]}),r===`email`&&(0,G.jsx)(`div`,{className:`pt-4 border-t border-bambu-dark-tertiary`,children:(0,G.jsxs)(`button`,{type:`button`,onClick:()=>i(`token`),className:`text-sm text-bambu-gray hover:text-white flex items-center gap-2 transition-colors`,children:[(0,G.jsx)(Uc,{className:`w-4 h-4`}),t(`profiles.login.useToken`)]})}),r===`token`&&(0,G.jsx)(`div`,{className:`pt-4 border-t border-bambu-dark-tertiary`,children:(0,G.jsxs)(`button`,{type:`button`,onClick:()=>i(`email`),className:`text-sm text-bambu-gray hover:text-white flex items-center gap-2 transition-colors`,children:[(0,G.jsx)(tl,{className:`w-4 h-4`}),t(`profiles.login.useEmail`)]})})]})]})})}function d8({label:e,value:t,options:n,onChange:r}){let[i,a]=(0,y.useState)(!1),o=n.find(e=>e.value===t);return(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsxs)(`button`,{onClick:()=>a(!i),className:`flex items-center gap-2 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-sm text-white hover:border-bambu-gray-dark transition-colors`,children:[(0,G.jsxs)(`span`,{className:`text-bambu-gray`,children:[e,`:`]}),(0,G.jsx)(`span`,{children:o?.label||`All`}),(0,G.jsx)(ds,{className:`w-4 h-4 text-bambu-gray transition-transform ${i?`rotate-180`:``}`})]}),i&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`fixed inset-0 z-10`,onClick:()=>a(!1)}),(0,G.jsx)(`div`,{className:`absolute top-full left-0 mt-1 min-w-[160px] bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl z-20 py-1 max-h-60 overflow-y-auto`,children:n.map(e=>(0,G.jsxs)(`button`,{onClick:()=>{r(e.value),a(!1)},className:`w-full px-3 py-2 text-left text-sm flex items-center justify-between hover:bg-bambu-dark-tertiary transition-colors ${t===e.value?`text-bambu-green`:`text-white`}`,children:[(0,G.jsx)(`span`,{children:e.label}),e.count!==void 0&&(0,G.jsx)(`span`,{className:`text-bambu-gray text-xs`,children:e.count})]},e.value))})]})]})}function _Ue(){let[e,t]=(0,y.useState)(!1);return(0,y.useEffect)(()=>{let e=()=>{t(window.scrollY>300)};return window.addEventListener(`scroll`,e),()=>window.removeEventListener(`scroll`,e)},[]),e?(0,G.jsx)(`button`,{onClick:()=>{window.scrollTo({top:0,behavior:`smooth`})},className:`fixed bottom-24 right-6 p-3 bg-bambu-green hover:bg-bambu-green-light text-white rounded-full shadow-lg shadow-bambu-green/25 transition-all z-40`,"aria-label":`Scroll to top`,children:(0,G.jsx)(Vo,{className:`w-5 h-5`})}):null}function f8({setting:e,onClick:t,onDuplicate:n,compareMode:r,isCompareSelected:i,compareIndex:a,compareDisabled:o,t:s}){let c=l8(e.name),l=u8(e.setting_id);return(0,G.jsxs)(`div`,{className:`flex items-center gap-2 group`,children:[(0,G.jsx)(`button`,{onClick:t,disabled:o,className:`flex-1 text-left px-3 py-2 rounded transition-colors ${i?`bg-blue-500/20 border border-blue-500/50`:o?`bg-bambu-dark/50 opacity-40 cursor-not-allowed`:`bg-bambu-dark hover:bg-bambu-dark-tertiary`} ${r&&!o?`cursor-pointer`:``}`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[i&&a!==void 0&&(0,G.jsx)(`span`,{className:`flex-shrink-0 w-5 h-5 rounded-full bg-blue-500 text-white text-xs flex items-center justify-center font-medium`,children:a+1}),!i&&l&&(0,G.jsx)(`span`,{className:`flex-shrink-0 w-1.5 h-1.5 rounded-full bg-bambu-green`,title:s(`profiles.presets.myPreset`)}),(0,G.jsx)(`span`,{className:`text-white text-sm truncate flex-1`,title:e.name,children:e.name}),c.filamentType&&e.type===`filament`&&(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:c.filamentType}),c.layerHeight&&e.type===`process`&&(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:c.layerHeight}),c.printer&&(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray whitespace-nowrap`,children:c.printer})]})}),(0,G.jsx)(`button`,{onClick:e=>{e.stopPropagation(),n()},className:`opacity-0 group-hover:opacity-100 text-bambu-gray hover:text-white transition-all p-1`,title:s(`profiles.presets.duplicate`),children:(0,G.jsx)(zs,{className:`w-4 h-4`})})]})}function p8(e,t=0){let n=` `.repeat(t);if(e===null)return`null`;if(e===void 0)return`undefined`;if(typeof e==`string`){if(e.includes(`\\n`)||e.includes(`
`)){let t=e.replace(/\\n/g,`
`).replace(/\\"/g,`"`).replace(/\\t/g,` `).split(`
`);if(t.length>1)return`"""
@@ -4421,7 +4421,7 @@ ${t.slice(l+2)}`,d+=1;else break}t.push({indent:l,number:parseInt(s,10),content:
`))+1))}let o=`#`.repeat(i),s=n.enter(`headingAtx`),c=n.enter(`phrasing`);a.move(o+` `);let l=n.containerPhrasing(e,{before:`# `,after:`
`,...a.current()});return/^[\t ]/.test(l)&&(l=$7(l.charCodeAt(0))+l.slice(1)),l=l?o+` `+l:o,n.options.closeAtx&&(l+=` `+o),c(),s(),l}dYe.peek=fYe;function dYe(e){return e.value||``}function fYe(){return`<`}pYe.peek=mYe;function pYe(e,t,n,r){let i=Q7(n),a=i===`"`?`Quote`:`Apostrophe`,o=n.enter(`image`),s=n.enter(`label`),c=n.createTracker(r),l=c.move(`![`);return l+=c.move(n.safe(e.alt,{before:l,after:`]`,...c.current()})),l+=c.move(`](`),s(),!e.url&&e.title||/[\0- \u007F]/.test(e.url)?(s=n.enter(`destinationLiteral`),l+=c.move(`<`),l+=c.move(n.safe(e.url,{before:l,after:`>`,...c.current()})),l+=c.move(`>`)):(s=n.enter(`destinationRaw`),l+=c.move(n.safe(e.url,{before:l,after:e.title?` `:`)`,...c.current()}))),s(),e.title&&(s=n.enter(`title${a}`),l+=c.move(` `+i),l+=c.move(n.safe(e.title,{before:l,after:i,...c.current()})),l+=c.move(i),s()),l+=c.move(`)`),o(),l}function mYe(){return`!`}hYe.peek=gYe;function hYe(e,t,n,r){let i=e.referenceType,a=n.enter(`imageReference`),o=n.enter(`label`),s=n.createTracker(r),c=s.move(`![`),l=n.safe(e.alt,{before:c,after:`]`,...s.current()});c+=s.move(l+`][`),o();let u=n.stack;n.stack=[],o=n.enter(`reference`);let d=n.safe(n.associationId(e),{before:c,after:`]`,...s.current()});return o(),n.stack=u,a(),i===`full`||!l||l!==d?c+=s.move(d+`]`):i===`shortcut`?c=c.slice(0,-1):c+=s.move(`]`),c}function gYe(){return`!`}_Ye.peek=vYe;function _Ye(e,t,n){let r=e.value||``,i="`",a=-1;for(;RegExp("(^|[^`])"+i+"([^`]|$)").test(r);)i+="`";for(/[^ \r\n]/.test(r)&&(/^[ \r\n]/.test(r)&&/[ \r\n]$/.test(r)||/^`|`$/.test(r))&&(r=` `+r+` `);++a\u007F]/.test(e.url))}bYe.peek=xYe;function bYe(e,t,n,r){let i=Q7(n),a=i===`"`?`Quote`:`Apostrophe`,o=n.createTracker(r),s,c;if(yYe(e,n)){let t=n.stack;n.stack=[],s=n.enter(`autolink`);let r=o.move(`<`);return r+=o.move(n.containerPhrasing(e,{before:r,after:`>`,...o.current()})),r+=o.move(`>`),s(),n.stack=t,r}s=n.enter(`link`),c=n.enter(`label`);let l=o.move(`[`);return l+=o.move(n.containerPhrasing(e,{before:l,after:`](`,...o.current()})),l+=o.move(`](`),c(),!e.url&&e.title||/[\0- \u007F]/.test(e.url)?(c=n.enter(`destinationLiteral`),l+=o.move(`<`),l+=o.move(n.safe(e.url,{before:l,after:`>`,...o.current()})),l+=o.move(`>`)):(c=n.enter(`destinationRaw`),l+=o.move(n.safe(e.url,{before:l,after:e.title?` `:`)`,...o.current()}))),c(),e.title&&(c=n.enter(`title${a}`),l+=o.move(` `+i),l+=o.move(n.safe(e.title,{before:l,after:i,...o.current()})),l+=o.move(i),c()),l+=o.move(`)`),s(),l}function xYe(e,t,n){return yYe(e,n)?`<`:`[`}SYe.peek=CYe;function SYe(e,t,n,r){let i=e.referenceType,a=n.enter(`linkReference`),o=n.enter(`label`),s=n.createTracker(r),c=s.move(`[`),l=n.containerPhrasing(e,{before:c,after:`]`,...s.current()});c+=s.move(l+`][`),o();let u=n.stack;n.stack=[],o=n.enter(`reference`);let d=n.safe(n.associationId(e),{before:c,after:`]`,...s.current()});return o(),n.stack=u,a(),i===`full`||!l||l!==d?c+=s.move(d+`]`):i===`shortcut`?c=c.slice(0,-1):c+=s.move(`]`),c}function CYe(){return`[`}function t9(e){let t=e.options.bullet||`*`;if(t!==`*`&&t!==`+`&&t!==`-`)throw Error("Cannot serialize items with `"+t+"` for `options.bullet`, expected `*`, `+`, or `-`");return t}function wYe(e){let t=t9(e),n=e.options.bulletOther;if(!n)return t===`*`?`-`:`*`;if(n!==`*`&&n!==`+`&&n!==`-`)throw Error("Cannot serialize items with `"+n+"` for `options.bulletOther`, expected `*`, `+`, or `-`");if(n===t)throw Error("Expected `bullet` (`"+t+"`) and `bulletOther` (`"+n+"`) to be different");return n}function TYe(e){let t=e.options.bulletOrdered||`.`;if(t!==`.`&&t!==`)`)throw Error("Cannot serialize items with `"+t+"` for `options.bulletOrdered`, expected `.` or `)`");return t}function EYe(e){let t=e.options.rule||`*`;if(t!==`*`&&t!==`-`&&t!==`_`)throw Error("Cannot serialize rules with `"+t+"` for `options.rule`, expected `*`, `-`, or `_`");return t}function DYe(e,t,n,r){let i=n.enter(`list`),a=n.bulletCurrent,o=e.ordered?TYe(n):t9(n),s=e.ordered?o===`.`?`)`:`.`:wYe(n),c=t&&n.bulletLastUsed?o===n.bulletLastUsed:!1;if(!e.ordered){let t=e.children?e.children[0]:void 0;if((o===`*`||o===`-`)&&t&&(!t.children||!t.children[0])&&n.stack[n.stack.length-1]===`list`&&n.stack[n.stack.length-2]===`listItem`&&n.stack[n.stack.length-3]===`list`&&n.stack[n.stack.length-4]===`listItem`&&n.indexStack[n.indexStack.length-1]===0&&n.indexStack[n.indexStack.length-2]===0&&n.indexStack[n.indexStack.length-3]===0&&(c=!0),EYe(n)===o&&t){let t=-1;for(;++t-1?t.start:1)+(n.options.incrementListMarker===!1?0:t.children.indexOf(e))+a);let o=a.length+1;(i===`tab`||i===`mixed`&&(t&&t.type===`list`&&t.spread||e.spread))&&(o=Math.ceil(o/4)*4);let s=n.createTracker(r);s.move(a+` `.repeat(o-a.length)),s.shift(o);let c=n.enter(`listItem`),l=n.indentLines(n.containerFlow(e,s.current()),u);return c(),l;function u(e,t,n){return t?(n?``:` `.repeat(o))+e:(n?a:a+` `.repeat(o-a.length))+e}}function AYe(e,t,n,r){let i=n.enter(`paragraph`),a=n.enter(`phrasing`),o=n.containerPhrasing(e,r);return a(),i(),o}var jYe=j7([`break`,`delete`,`emphasis`,`footnote`,`footnoteReference`,`image`,`imageReference`,`inlineCode`,`inlineMath`,`link`,`linkReference`,`mdxJsxTextElement`,`mdxTextExpression`,`strong`,`text`,`textDirective`]);function MYe(e,t,n,r){return(e.children.some(function(e){return jYe(e)})?n.containerPhrasing:n.containerFlow).call(n,e,r)}function NYe(e){let t=e.options.strong||`*`;if(t!==`*`&&t!==`_`)throw Error("Cannot serialize strong with `"+t+"` for `options.strong`, expected `*`, or `_`");return t}PYe.peek=FYe;function PYe(e,t,n,r){let i=NYe(n),a=n.enter(`strong`),o=n.createTracker(r),s=o.move(i+i),c=o.move(n.containerPhrasing(e,{after:i,before:s,...o.current()})),l=c.charCodeAt(0),u=e9(r.before.charCodeAt(r.before.length-1),l,i);u.inside&&(c=$7(l)+c.slice(1));let d=c.charCodeAt(c.length-1),f=e9(r.after.charCodeAt(0),d,i);f.inside&&(c=c.slice(0,-1)+$7(d));let p=o.move(i+i);return a(),n.attentionEncodeSurroundingInfo={after:f.outside,before:u.outside},s+c+p}function FYe(e,t,n){return n.options.strong||`*`}function IYe(e,t,n,r){return n.safe(e.value,r)}function LYe(e){let t=e.options.ruleRepetition||3;if(t<3)throw Error("Cannot serialize rules with repetition `"+t+"` for `options.ruleRepetition`, expected `3` or more");return t}function RYe(e,t,n){let r=(EYe(n)+(n.options.ruleSpaces?` `:``)).repeat(LYe(n));return n.options.ruleSpaces?r.slice(0,-1):r}var zYe={blockquote:YJe,break:$Je,code:rYe,definition:aYe,emphasis:sYe,hardBreak:$Je,heading:uYe,html:dYe,image:pYe,imageReference:hYe,inlineCode:_Ye,link:bYe,linkReference:SYe,list:DYe,listItem:kYe,paragraph:AYe,root:MYe,strong:PYe,text:IYe,thematicBreak:RYe};function BYe(){return{enter:{table:VYe,tableData:WYe,tableHeader:WYe,tableRow:UYe},exit:{codeText:GYe,table:HYe,tableData:n9,tableHeader:n9,tableRow:n9}}}function VYe(e){let t=e._align;this.enter({type:`table`,align:t.map(function(e){return e===`none`?null:e}),children:[]},e),this.data.inTable=!0}function HYe(e){this.exit(e),this.data.inTable=void 0}function UYe(e){this.enter({type:`tableRow`,children:[]},e)}function n9(e){this.exit(e)}function WYe(e){this.enter({type:`tableCell`,children:[]},e)}function GYe(e){let t=this.resume();this.data.inTable&&(t=t.replace(/\\([\\|])/g,KYe));let n=this.stack[this.stack.length-1];n.type,n.value=t,this.exit(e)}function KYe(e,t){return t===`|`?t:e}function qYe(e){let t=e||{},n=t.tableCellPadding,r=t.tablePipeAlign,i=t.stringLength,a=n?` `:`|`;return{unsafe:[{character:`\r`,inConstruct:`tableCell`},{character:`
`,inConstruct:`tableCell`},{atBreak:!0,character:`|`,after:`[ :-]`},{character:`|`,inConstruct:`tableCell`},{atBreak:!0,character:`:`,after:`-`},{atBreak:!0,character:`-`,after:`[:|-]`}],handlers:{inlineCode:f,table:o,tableCell:c,tableRow:s}};function o(e,t,n,r){return l(u(e,n,r),e.align)}function s(e,t,n,r){let i=l([d(e,n,r)]);return i.slice(0,i.indexOf(`
-`))}function c(e,t,n,r){let i=n.enter(`tableCell`),o=n.enter(`phrasing`),s=n.containerPhrasing(e,{...r,before:a,after:a});return o(),i(),s}function l(e,t){return KJe(e,{align:t,alignDelimiters:r,padding:n,stringLength:i})}function u(e,t,n){let r=e.children,i=-1,a=[],o=t.enter(`table`);for(;++i0&&!n&&(e[e.length-1][1]._gfmAutolinkLiteralWalkedInto=!0),n}var bXe={tokenize:OXe,partial:!0};function xXe(){return{document:{91:{name:`gfmFootnoteDefinition`,tokenize:TXe,continuation:{tokenize:EXe},exit:DXe}},text:{91:{name:`gfmFootnoteCall`,tokenize:wXe},93:{name:`gfmPotentialFootnoteCall`,add:`after`,tokenize:SXe,resolveTo:CXe}}}}function SXe(e,t,n){let r=this,i=r.events.length,a=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]),o;for(;i--;){let e=r.events[i][1];if(e.type===`labelImage`){o=e;break}if(e.type===`gfmFootnoteCall`||e.type===`labelLink`||e.type===`label`||e.type===`image`||e.type===`link`)break}return s;function s(i){if(!o||!o._balanced)return n(i);let s=O5(r.sliceSerialize({start:o.end,end:r.now()}));return s.codePointAt(0)!==94||!a.includes(s.slice(1))?n(i):(e.enter(`gfmFootnoteCallLabelMarker`),e.consume(i),e.exit(`gfmFootnoteCallLabelMarker`),t(i))}}function CXe(e,t){let n=e.length;for(;n--;)if(e[n][1].type===`labelImage`&&e[n][0]===`enter`){e[n][1];break}e[n+1][1].type=`data`,e[n+3][1].type=`gfmFootnoteCallLabelMarker`;let r={type:`gfmFootnoteCall`,start:Object.assign({},e[n+3][1].start),end:Object.assign({},e[e.length-1][1].end)},i={type:`gfmFootnoteCallMarker`,start:Object.assign({},e[n+3][1].end),end:Object.assign({},e[n+3][1].end)};i.end.column++,i.end.offset++,i.end._bufferIndex++;let a={type:`gfmFootnoteCallString`,start:Object.assign({},i.end),end:Object.assign({},e[e.length-1][1].start)},o={type:`chunkString`,contentType:`string`,start:Object.assign({},a.start),end:Object.assign({},a.end)},s=[e[n+1],e[n+2],[`enter`,r,t],e[n+3],e[n+4],[`enter`,i,t],[`exit`,i,t],[`enter`,a,t],[`enter`,o,t],[`exit`,o,t],[`exit`,a,t],e[e.length-2],e[e.length-1],[`exit`,r,t]];return e.splice(n,e.length-n+1,...s),e}function wXe(e,t,n){let r=this,i=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]),a=0,o;return s;function s(t){return e.enter(`gfmFootnoteCall`),e.enter(`gfmFootnoteCallLabelMarker`),e.consume(t),e.exit(`gfmFootnoteCallLabelMarker`),c}function c(t){return t===94?(e.enter(`gfmFootnoteCallMarker`),e.consume(t),e.exit(`gfmFootnoteCallMarker`),e.enter(`gfmFootnoteCallString`),e.enter(`chunkString`).contentType=`string`,l):n(t)}function l(s){if(a>999||s===93&&!o||s===null||s===91||P5(s))return n(s);if(s===93){e.exit(`chunkString`);let a=e.exit(`gfmFootnoteCallString`);return i.includes(O5(r.sliceSerialize(a)))?(e.enter(`gfmFootnoteCallLabelMarker`),e.consume(s),e.exit(`gfmFootnoteCallLabelMarker`),e.exit(`gfmFootnoteCall`),t):n(s)}return P5(s)||(o=!0),a++,e.consume(s),s===92?u:l}function u(t){return t===91||t===92||t===93?(e.consume(t),a++,l):l(t)}}function TXe(e,t,n){let r=this,i=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]),a,o=0,s;return c;function c(t){return e.enter(`gfmFootnoteDefinition`)._container=!0,e.enter(`gfmFootnoteDefinitionLabel`),e.enter(`gfmFootnoteDefinitionLabelMarker`),e.consume(t),e.exit(`gfmFootnoteDefinitionLabelMarker`),l}function l(t){return t===94?(e.enter(`gfmFootnoteDefinitionMarker`),e.consume(t),e.exit(`gfmFootnoteDefinitionMarker`),e.enter(`gfmFootnoteDefinitionLabelString`),e.enter(`chunkString`).contentType=`string`,u):n(t)}function u(t){if(o>999||t===93&&!s||t===null||t===91||P5(t))return n(t);if(t===93){e.exit(`chunkString`);let n=e.exit(`gfmFootnoteDefinitionLabelString`);return a=O5(r.sliceSerialize(n)),e.enter(`gfmFootnoteDefinitionLabelMarker`),e.consume(t),e.exit(`gfmFootnoteDefinitionLabelMarker`),e.exit(`gfmFootnoteDefinitionLabel`),f}return P5(t)||(s=!0),o++,e.consume(t),t===92?d:u}function d(t){return t===91||t===92||t===93?(e.consume(t),o++,u):u(t)}function f(t){return t===58?(e.enter(`definitionMarker`),e.consume(t),e.exit(`definitionMarker`),i.includes(a)||i.push(a),B5(e,p,`gfmFootnoteDefinitionWhitespace`)):n(t)}function p(e){return t(e)}}function EXe(e,t,n){return e.check(K5,t,e.attempt(bXe,t,n))}function DXe(e){e.exit(`gfmFootnoteDefinition`)}function OXe(e,t,n){let r=this;return B5(e,i,`gfmFootnoteDefinitionIndent`,5);function i(e){let i=r.events[r.events.length-1];return i&&i[1].type===`gfmFootnoteDefinitionIndent`&&i[2].sliceSerialize(i[1],!0).length===4?t(e):n(e)}}function kXe(e){let t=(e||{}).singleTilde,n={name:`strikethrough`,tokenize:i,resolveAll:r};return t??=!0,{text:{126:n},insideSpan:{null:[n]},attentionMarkers:{null:[126]}};function r(e,t){let n=-1;for(;++n1?r(a):(e.consume(a),o++,c);if(o<2&&!t)return r(a);let l=e.exit(`strikethroughSequenceTemporary`),u=H5(a);return l._open=!u||u===2&&!!s,l._close=!s||s===2&&!!u,n(a)}}}var AXe=class{constructor(){this.map=[]}add(e,t,n){jXe(this,e,t,n)}consume(e){if(this.map.sort(function(e,t){return e[0]-t[0]}),this.map.length===0)return;let t=this.map.length,n=[];for(;t>0;)--t,n.push(e.slice(this.map[t][0]+this.map[t][1]),this.map[t][2]),e.length=this.map[t][0];n.push(e.slice()),e.length=0;let r=n.pop();for(;r;){for(let t of r)e.push(t);r=n.pop()}this.map.length=0}};function jXe(e,t,n,r){let i=0;if(!(n===0&&r.length===0)){for(;i-1;){let e=r.events[t][1].type;if(e===`lineEnding`||e===`linePrefix`)t--;else break}let i=t>-1?r.events[t][1].type:null,a=i===`tableHead`||i===`tableRow`?S:c;return a===S&&r.parser.lazy[r.now().line]?n(e):a(e)}function c(t){return e.enter(`tableHead`),e.enter(`tableRow`),l(t)}function l(e){return e===124?u(e):(o=!0,a+=1,u(e))}function u(t){return t===null?n(t):N5(t)?a>1?(a=0,r.interrupt=!0,e.exit(`tableRow`),e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),p):n(t):F5(t)?B5(e,u,`whitespace`)(t):(a+=1,o&&(o=!1,i+=1),t===124?(e.enter(`tableCellDivider`),e.consume(t),e.exit(`tableCellDivider`),o=!0,u):(e.enter(`data`),d(t)))}function d(t){return t===null||t===124||P5(t)?(e.exit(`data`),u(t)):(e.consume(t),t===92?f:d)}function f(t){return t===92||t===124?(e.consume(t),d):d(t)}function p(t){return r.interrupt=!1,r.parser.lazy[r.now().line]?n(t):(e.enter(`tableDelimiterRow`),o=!1,F5(t)?B5(e,m,`linePrefix`,r.parser.constructs.disable.null.includes(`codeIndented`)?void 0:4)(t):m(t))}function m(t){return t===45||t===58?g(t):t===124?(o=!0,e.enter(`tableCellDivider`),e.consume(t),e.exit(`tableCellDivider`),h):x(t)}function h(t){return F5(t)?B5(e,g,`whitespace`)(t):g(t)}function g(t){return t===58?(a+=1,o=!0,e.enter(`tableDelimiterMarker`),e.consume(t),e.exit(`tableDelimiterMarker`),_):t===45?(a+=1,_(t)):t===null||N5(t)?b(t):x(t)}function _(t){return t===45?(e.enter(`tableDelimiterFiller`),v(t)):x(t)}function v(t){return t===45?(e.consume(t),v):t===58?(o=!0,e.exit(`tableDelimiterFiller`),e.enter(`tableDelimiterMarker`),e.consume(t),e.exit(`tableDelimiterMarker`),y):(e.exit(`tableDelimiterFiller`),y(t))}function y(t){return F5(t)?B5(e,b,`whitespace`)(t):b(t)}function b(n){return n===124?m(n):n===null||N5(n)?!o||i!==a?x(n):(e.exit(`tableDelimiterRow`),e.exit(`tableHead`),t(n)):x(n)}function x(e){return n(e)}function S(t){return e.enter(`tableRow`),C(t)}function C(n){return n===124?(e.enter(`tableCellDivider`),e.consume(n),e.exit(`tableCellDivider`),C):n===null||N5(n)?(e.exit(`tableRow`),t(n)):F5(n)?B5(e,C,`whitespace`)(n):(e.enter(`data`),w(n))}function w(t){return t===null||t===124||P5(t)?(e.exit(`data`),C(t)):(e.consume(t),t===92?T:w)}function T(t){return t===92||t===124?(e.consume(t),w):w(t)}}function FXe(e,t){let n=-1,r=!0,i=0,a=[0,0,0,0],o=[0,0,0,0],s=!1,c=0,l,u,d,f=new AXe;for(;++nn[2]+1){let t=n[2]+1,r=n[3]-n[2]-1;e.add(t,r,[])}}e.add(n[3]+1,0,[[`exit`,o,t]])}return i!==void 0&&(a.end=Object.assign({},l9(t.events,i)),e.add(i,0,[[`exit`,a,t]]),a=void 0),a}function IXe(e,t,n,r,i){let a=[],o=l9(t.events,n);i&&(i.end=Object.assign({},o),a.push([`exit`,i,t])),r.end=Object.assign({},o),a.push([`exit`,r,t]),e.add(n+1,0,a)}function l9(e,t){let n=e[t],r=n[0]===`enter`?`start`:`end`;return n[1][r]}var LXe={name:`tasklistCheck`,tokenize:zXe};function RXe(){return{text:{91:LXe}}}function zXe(e,t,n){let r=this;return i;function i(t){return r.previous!==null||!r._gfmTasklistFirstContentOfListItem?n(t):(e.enter(`taskListCheck`),e.enter(`taskListCheckMarker`),e.consume(t),e.exit(`taskListCheckMarker`),a)}function a(t){return P5(t)?(e.enter(`taskListCheckValueUnchecked`),e.consume(t),e.exit(`taskListCheckValueUnchecked`),o):t===88||t===120?(e.enter(`taskListCheckValueChecked`),e.consume(t),e.exit(`taskListCheckValueChecked`),o):n(t)}function o(t){return t===93?(e.enter(`taskListCheckMarker`),e.consume(t),e.exit(`taskListCheckMarker`),e.exit(`taskListCheck`),s):n(t)}function s(r){return N5(r)?t(r):F5(r)?e.check({tokenize:BXe},t,n)(r):n(r)}}function BXe(e,t,n){return B5(e,r,`whitespace`);function r(e){return e===null?n(e):t(e)}}function VXe(e){return E5([cXe(),xXe(),kXe(e),NXe(),RXe()])}var HXe={};function UXe(e){let t=this,n=e||HXe,r=t.data(),i=r.micromarkExtensions||=[],a=r.fromMarkdownExtensions||=[],o=r.toMarkdownExtensions||=[];i.push(VXe(n)),a.push($Ye()),o.push(eXe(n))}var WXe=`fileManager.readmeCollapsed`;function GXe({folderId:e}){let{t}=U(),[n,r]=(0,y.useState)(()=>localStorage.getItem(WXe)===`1`);(0,y.useEffect)(()=>{localStorage.setItem(WXe,n?`1`:`0`)},[n]);let{data:i,isLoading:a,error:o}=K({queryKey:[`folder-readme`,e],queryFn:()=>Z.getLibraryFolderReadme(e),retry:!1,staleTime:3e4});return a||o||!i?null:n?(0,G.jsxs)(`div`,{className:`mb-2 lg:mb-0 order-first lg:order-none lg:w-10 lg:flex-shrink-0 lg:h-full`,children:[(0,G.jsxs)(`button`,{type:`button`,onClick:()=>r(!1),title:t(`fileManager.readme.show`),"aria-label":t(`fileManager.readme.show`),className:`flex lg:hidden w-full items-center gap-2 px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg hover:bg-bambu-dark/40 transition-colors`,children:[(0,G.jsx)(lc,{className:`w-4 h-4 text-bambu-green flex-shrink-0`}),(0,G.jsx)(`span`,{className:`text-sm font-medium text-white truncate`,children:i.filename}),(0,G.jsx)(wl,{className:`w-4 h-4 text-bambu-gray flex-shrink-0 ml-auto`})]}),(0,G.jsxs)(`button`,{type:`button`,onClick:()=>r(!1),title:t(`fileManager.readme.show`),"aria-label":t(`fileManager.readme.show`),className:`hidden lg:flex h-full w-10 flex-col items-center gap-2 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg hover:bg-bambu-dark/40 transition-colors`,children:[(0,G.jsx)(wl,{className:`w-4 h-4 text-bambu-green flex-shrink-0`}),(0,G.jsx)(`span`,{className:`text-xs font-medium text-bambu-gray [writing-mode:vertical-rl] rotate-180 select-none`,children:t(`fileManager.readme.label`)})]})]}):(0,G.jsxs)(`div`,{className:`mb-4 lg:mb-0 order-first lg:order-none lg:w-80 xl:w-96 lg:flex-shrink-0 lg:h-full flex flex-col bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg overflow-hidden`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-2 px-3 py-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,G.jsx)(lc,{className:`w-4 h-4 text-bambu-green flex-shrink-0`}),(0,G.jsx)(`span`,{className:`text-sm font-medium text-white truncate`,title:i.filename,children:i.filename}),i.truncated&&(0,G.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-400 flex-shrink-0`,children:t(`fileManager.readme.truncated`)})]}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>r(!0),title:t(`fileManager.readme.hide`),"aria-label":t(`fileManager.readme.hide`),className:`p-1 rounded text-bambu-gray hover:text-white hover:bg-bambu-dark/40 transition-colors flex-shrink-0`,children:(0,G.jsx)(Cl,{className:`w-4 h-4`})})]}),(0,G.jsx)(`div`,{className:`px-4 py-3 border-t border-bambu-dark-tertiary flex-1 overflow-y-auto max-h-96 lg:max-h-none text-sm text-bambu-gray-light leading-relaxed space-y-2`,children:(0,G.jsx)(eJe,{remarkPlugins:[UXe],components:{h1:({children:e})=>(0,G.jsx)(`h1`,{className:`text-lg font-semibold text-white mt-2 mb-1`,children:e}),h2:({children:e})=>(0,G.jsx)(`h2`,{className:`text-base font-semibold text-white mt-2 mb-1`,children:e}),h3:({children:e})=>(0,G.jsx)(`h3`,{className:`text-sm font-semibold text-white mt-2 mb-1`,children:e}),p:({children:e})=>(0,G.jsx)(`p`,{className:`my-1`,children:e}),ul:({children:e})=>(0,G.jsx)(`ul`,{className:`list-disc list-inside space-y-0.5 ml-2`,children:e}),ol:({children:e})=>(0,G.jsx)(`ol`,{className:`list-decimal list-inside space-y-0.5 ml-2`,children:e}),li:({children:e})=>(0,G.jsx)(`li`,{children:e}),code:({children:e,...t})=>t.className?(0,G.jsx)(`code`,{className:`block p-2 bg-bambu-dark rounded text-xs font-mono text-bambu-gray-light overflow-x-auto`,children:e}):(0,G.jsx)(`code`,{className:`px-1 py-0.5 bg-bambu-dark rounded text-xs font-mono text-bambu-green`,children:e}),pre:({children:e})=>(0,G.jsx)(`pre`,{className:`my-2`,children:e}),blockquote:({children:e})=>(0,G.jsx)(`blockquote`,{className:`border-l-2 border-bambu-dark-tertiary pl-3 text-bambu-gray italic`,children:e}),a:({children:e,href:t})=>(0,G.jsx)(`a`,{href:t,target:`_blank`,rel:`noopener noreferrer`,className:`text-bambu-green hover:underline`,children:e}),table:({children:e})=>(0,G.jsx)(`div`,{className:`overflow-x-auto`,children:(0,G.jsx)(`table`,{className:`min-w-full text-xs border-collapse`,children:e})}),th:({children:e})=>(0,G.jsx)(`th`,{className:`border border-bambu-dark-tertiary px-2 py-1 text-left font-semibold text-white`,children:e}),td:({children:e})=>(0,G.jsx)(`td`,{className:`border border-bambu-dark-tertiary px-2 py-1`,children:e}),hr:()=>(0,G.jsx)(`hr`,{className:`border-bambu-dark-tertiary my-2`})},children:i.content})})]})}function KXe({open:e,onClose:t,onPickTag:n}){let{t:r}=U(),i=so(),{showToast:a}=Bd(),[o,s]=(0,y.useState)(!1),[c,l]=(0,y.useState)(null),[u,d]=(0,y.useState)(``),[f,p]=(0,y.useState)(null),{data:m=[],isLoading:h}=K({queryKey:O8,queryFn:Z.getLibraryTags,enabled:e}),g=()=>{i.invalidateQueries({queryKey:O8}),i.invalidateQueries({queryKey:[`library-files`]})},_=q({mutationFn:async()=>{let e=u.trim();if(!e)throw Error(r(`fileManager.tags.nameRequired`));return c?Z.updateLibraryTag(c.id,e):Z.createLibraryTag(e)},onSuccess:()=>{a(r(c?`fileManager.tags.updated`:`fileManager.tags.created`),`success`),s(!1),l(null),d(``),g()},onError:e=>{a(e.message||r(`fileManager.tags.saveFailed`),`error`)}}),v=q({mutationFn:e=>Z.deleteLibraryTag(e),onSuccess:()=>{a(r(`fileManager.tags.deleted`),`success`),p(null),g()},onError:e=>{a(e.message||r(`fileManager.tags.deleteFailed`),`error`)}}),b=()=>{l(null),d(``),s(!0)},x=e=>{l(e),d(e.name),s(!0)},S=(0,y.useCallback)(()=>{_.isPending||(s(!1),l(null),d(``))},[_.isPending]);(0,y.useEffect)(()=>{if(!e)return;let n=e=>{e.key===`Escape`&&(_.isPending||v.isPending||(o?S():f||t()))};return document.addEventListener(`keydown`,n),()=>document.removeEventListener(`keydown`,n)},[e,o,f,_.isPending,v.isPending,S,t]);let C=e=>{e.preventDefault(),_.mutate()};if(!e)return null;let w=`library-tags-modal-title`,T=`library-tag-editor-title`;return(0,G.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[(0,G.jsx)(`div`,{className:`absolute inset-0 bg-black/60`,onClick:()=>{_.isPending||v.isPending||t()}}),(0,G.jsxs)(`div`,{className:`relative w-full max-w-4xl 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":w,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-4 px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,G.jsxs)(`h2`,{id:w,className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(Cu,{className:`w-5 h-5 text-bambu-green`}),r(`fileManager.tags.title`)]}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-sm mt-0.5`,children:r(`fileManager.tags.subtitle`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(Q,{onClick:b,children:[(0,G.jsx)(Ml,{className:`w-4 h-4`}),r(`fileManager.tags.add`)]}),(0,G.jsx)(`button`,{type:`button`,className:`p-1.5 text-bambu-gray hover:text-white rounded`,onClick:t,"aria-label":r(`common.close`),children:(0,G.jsx)($u,{className:`w-5 h-5`})})]})]}),(0,G.jsx)(`div`,{className:`overflow-y-auto`,children:h?(0,G.jsxs)(`div`,{className:`flex items-center justify-center py-16 text-bambu-gray`,children:[(0,G.jsx)(Y,{className:`w-6 h-6 animate-spin mr-2`}),r(`common.loading`)]}):m.length===0?(0,G.jsx)(`div`,{className:`py-16 text-center text-bambu-gray`,children:r(`fileManager.tags.empty`)}):(0,G.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,G.jsx)(`thead`,{children:(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary text-left text-bambu-gray`,children:[(0,G.jsx)(`th`,{className:`px-4 py-3 font-medium`,children:r(`fileManager.tags.name`)}),(0,G.jsx)(`th`,{className:`px-4 py-3 font-medium text-right`,children:r(`fileManager.tags.fileCount`)}),(0,G.jsx)(`th`,{className:`px-4 py-3 font-medium text-right w-32`,children:r(`common.actions`)})]})}),(0,G.jsx)(`tbody`,{children:m.map(e=>(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/60 hover:bg-bambu-dark-tertiary/30 ${n?`cursor-pointer`:``}`,onClick:()=>{n&&(n(e.id),t())},children:[(0,G.jsx)(`td`,{className:`px-4 py-3 text-white font-medium`,children:e.name}),(0,G.jsx)(`td`,{className:`px-4 py-3 text-right text-bambu-gray`,children:e.file_count}),(0,G.jsx)(`td`,{className:`px-4 py-3 text-right`,onClick:e=>e.stopPropagation(),children:(0,G.jsxs)(`div`,{className:`flex items-center justify-end gap-1`,children:[(0,G.jsx)(`button`,{type:`button`,className:`p-1.5 text-bambu-gray hover:text-bambu-green rounded`,onClick:()=>x(e),title:r(`common.edit`),"aria-label":r(`fileManager.tags.editAria`,{name:e.name}),children:(0,G.jsx)(Ol,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{type:`button`,className:`p-1.5 text-bambu-gray hover:text-red-600 dark:hover:text-red-400 rounded`,onClick:()=>p(e),title:r(`common.delete`),"aria-label":r(`fileManager.tags.deleteAria`,{name:e.name}),children:(0,G.jsx)(ju,{className:`w-4 h-4`})})]})})]},e.id))})]})})]}),o&&(0,G.jsxs)(`div`,{className:`fixed inset-0 z-[60] flex items-center justify-center`,children:[(0,G.jsx)(`div`,{className:`absolute inset-0 bg-black/60`,onClick:S}),(0,G.jsxs)(`div`,{className:`relative w-full max-w-md mx-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl p-6 shadow-2xl`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":T,children:[(0,G.jsx)(`h3`,{id:T,className:`text-lg font-semibold text-white mb-4`,children:r(c?`fileManager.tags.edit`:`fileManager.tags.add`)}),(0,G.jsxs)(`form`,{onSubmit:C,children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,htmlFor:`library-tag-name`,children:r(`fileManager.tags.name`)}),(0,G.jsx)(`input`,{id:`library-tag-name`,type:`text`,maxLength:64,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 mb-4`,placeholder:r(`fileManager.tags.createPlaceholder`),value:u,onChange:e=>d(e.target.value),autoFocus:!0}),(0,G.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:S,children:r(`common.cancel`)}),(0,G.jsxs)(Q,{type:`submit`,disabled:_.isPending||!u.trim(),children:[_.isPending&&(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),r(`common.save`)]})]})]})]})]}),f&&(0,G.jsx)(Zd,{title:r(`fileManager.tags.confirmDelete`,{name:f.name}),message:f.file_count>0?r(`fileManager.tags.confirmDeleteInUseMessage`,{count:f.file_count}):r(`fileManager.tags.confirmDeleteMessage`),confirmText:r(`common.delete`),variant:`danger`,isLoading:v.isPending,onConfirm:()=>v.mutate(f.id),onCancel:()=>p(null)})]})}var qXe=90;function JXe({onClose:e}){let{t}=U(),n=so(),{showToast:r}=Bd(),[i,a]=(0,y.useState)(qXe),[o,s]=(0,y.useState)(!0),[c,l]=(0,y.useState)(i);(0,y.useEffect)(()=>{let e=window.setTimeout(()=>l(i),300);return()=>window.clearTimeout(e)},[i]);let u=K({queryKey:[`library-purge-preview`,c,o],queryFn:()=>Z.previewLibraryPurge(c,o),enabled:c>=1}),d=q({mutationFn:()=>Z.executeLibraryPurge(i,o),onSuccess:i=>{r(t(`libraryPurge.toast.success`,{count:i.moved_to_trash}),`success`),n.invalidateQueries({queryKey:[`library-files`]}),n.invalidateQueries({queryKey:[`library-folders`]}),n.invalidateQueries({queryKey:[`library-trash`]}),n.invalidateQueries({queryKey:[`library-trash-count`]}),e()},onError:e=>r(e.message||t(`libraryPurge.toast.failed`),`error`)});(0,y.useEffect)(()=>{let t=t=>{t.key===`Escape`&&!d.isPending&&e()};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e,d.isPending]);let f=u.data,p=f?.count??0,m=f?.total_bytes??0,h=p>0&&!d.isPending;return(0,G.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4`,children:(0,G.jsxs)(`div`,{className:`bg-white dark:bg-gray-900 rounded-lg shadow-xl max-w-lg w-full`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-gray-200 dark:border-gray-700`,children:[(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-gray-900 dark:text-gray-100 flex items-center gap-2`,children:[(0,G.jsx)(ju,{className:`w-5 h-5`}),t(`libraryPurge.title`)]}),(0,G.jsx)(`button`,{onClick:e,className:`text-gray-400 hover:text-gray-600 dark:hover:text-gray-200`,"aria-label":t(`common.close`),disabled:d.isPending,children:(0,G.jsx)($u,{className:`w-5 h-5`})})]}),(0,G.jsxs)(`div`,{className:`p-4 space-y-4`,children:[(0,G.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400`,children:t(`libraryPurge.description`)}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{htmlFor:`purge-days`,className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:t(`libraryPurge.ageLabel`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`input`,{id:`purge-days`,type:`number`,min:1,max:3650,value:i,onChange:e=>a(Math.max(1,Math.min(3650,parseInt(e.target.value||`0`,10)||0))),className:`w-24 rounded border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-800 text-sm px-2 py-1 text-gray-900 dark:text-gray-100`}),(0,G.jsx)(`span`,{className:`text-sm text-gray-600 dark:text-gray-400`,children:t(`libraryPurge.days`)})]})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-gray-700 dark:text-gray-300`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:o,onChange:e=>s(e.target.checked),className:`rounded border-gray-300`}),t(`libraryPurge.includeNeverPrinted`)]}),(0,G.jsxs)(`div`,{className:`rounded border border-gray-200 dark:border-gray-700 bg-gray-50 dark:bg-gray-800/30 p-3`,children:[(0,G.jsx)(`div`,{className:`text-xs font-semibold uppercase tracking-wide text-gray-600 dark:text-gray-300 mb-2`,children:t(`libraryPurge.effectsTitle`)}),(0,G.jsxs)(`ul`,{className:`text-xs text-gray-700 dark:text-gray-300 space-y-1 list-disc pl-4`,children:[(0,G.jsx)(`li`,{children:t(`libraryPurge.effect1`)}),(0,G.jsx)(`li`,{children:t(`libraryPurge.effect2`)}),(0,G.jsx)(`li`,{children:t(`libraryPurge.effect3`)}),(0,G.jsx)(`li`,{children:t(`libraryPurge.effect4`)})]})]}),(0,G.jsx)(`div`,{className:`rounded border border-gray-200 dark:border-gray-700 bg-gray-50 dark:bg-gray-800/50 p-3`,children:u.isLoading||u.isFetching?(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-gray-500 dark:text-gray-400`,children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),` `,t(`libraryPurge.previewLoading`)]}):u.isError?(0,G.jsx)(`div`,{className:`text-sm text-red-600 dark:text-red-400`,children:u.error?.message??t(`libraryPurge.previewFailed`)}):(0,G.jsxs)(`div`,{className:`text-sm text-gray-900 dark:text-gray-100`,children:[(0,G.jsx)(`div`,{className:`font-medium`,children:t(`libraryPurge.previewSummary`,{count:p,size:Rd(m)})}),f?.sample_filenames&&f.sample_filenames.length>0&&(0,G.jsxs)(`ul`,{className:`mt-2 text-xs text-gray-600 dark:text-gray-400 space-y-0.5 list-disc pl-4`,children:[f.sample_filenames.map(e=>(0,G.jsx)(`li`,{className:`truncate`,children:e},e)),p>f.sample_filenames.length&&(0,G.jsx)(`li`,{className:`list-none italic text-gray-500`,children:t(`libraryPurge.andMore`,{count:p-f.sample_filenames.length})})]})]})}),(0,G.jsxs)(`div`,{className:`flex gap-2 items-start text-xs text-amber-700 dark:text-amber-400 bg-amber-50 dark:bg-amber-900/20 rounded px-3 py-2`,children:[(0,G.jsx)(Pu,{className:`w-4 h-4 mt-0.5 shrink-0`}),(0,G.jsx)(`span`,{children:t(`libraryPurge.warning`)})]})]}),(0,G.jsxs)(`div`,{className:`flex justify-end gap-2 p-4 border-t border-gray-200 dark:border-gray-700`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:e,disabled:d.isPending,children:t(`common.cancel`)}),(0,G.jsx)(Q,{variant:`danger`,disabled:!h,onClick:()=>d.mutate(),children:d.isPending?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin mr-1`}),t(`libraryPurge.purging`)]}):t(`libraryPurge.confirmCta`,{count:p})})]})]})})}function YXe({parentId:e,onClose:t,onSave:n,isLoading:r,t:i}){let[a,o]=(0,y.useState)(``);return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg w-full max-w-sm border border-bambu-dark-tertiary`,children:[(0,G.jsx)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary`,children:(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(`fileManager.newFolder`)})}),(0,G.jsxs)(`form`,{onSubmit:t=>{t.preventDefault(),n({name:a.trim(),parent_id:e})},className:`p-4 space-y-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:i(`fileManager.folderName`)}),(0,G.jsx)(`input`,{type:`text`,value:a,onChange:e=>o(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:i(`fileManager.folderNamePlaceholder`),autoFocus:!0,required:!0})]}),(0,G.jsxs)(`div`,{className:`flex justify-end gap-2 pt-2`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:t,children:i(`common.cancel`)}),(0,G.jsx)(Q,{type:`submit`,disabled:!a.trim()||r,children:r?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):i(`common.create`)})]})]})]})})}function XXe({onClose:e,onSave:t,isLoading:n,t:r}){let[i,a]=(0,y.useState)(``),[o,s]=(0,y.useState)(``),[c,l]=(0,y.useState)(!0),[u,d]=(0,y.useState)(!1);return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg w-full max-w-md border border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(_c,{className:`w-5 h-5 text-bambu-green`}),r(`fileManager.linkExternalFolder`)]}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:r(`fileManager.linkExternalFolderDescription`)})]}),(0,G.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),t({name:i.trim(),external_path:o.trim(),readonly:c,show_hidden:u})},className:`p-4 space-y-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:r(`fileManager.folderName`)}),(0,G.jsx)(`input`,{type:`text`,value:i,onChange:e=>a(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:r(`fileManager.externalFolderNamePlaceholder`),autoFocus:!0,required:!0})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:r(`fileManager.externalPath`)}),(0,G.jsx)(`input`,{type:`text`,value:o,onChange:e=>s(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green font-mono text-sm`,placeholder:`/mnt/nas/3d-prints`,required:!0}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:r(`fileManager.externalPathHelp`)})]}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:c,onChange:e=>l(e.target.checked),className:`rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,G.jsx)(`span`,{className:`text-sm text-white`,children:r(`fileManager.readOnly`)}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[`(`,r(`fileManager.readOnlyHelp`),`)`]})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:u,onChange:e=>d(e.target.checked),className:`rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,G.jsx)(`span`,{className:`text-sm text-white`,children:r(`fileManager.showHiddenFiles`)})]})]}),(0,G.jsxs)(`div`,{className:`flex justify-end gap-2 pt-2`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:e,children:r(`common.cancel`)}),(0,G.jsx)(Q,{type:`submit`,disabled:!i.trim()||!o.trim()||n,children:n?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):r(`fileManager.linkFolder`)})]})]})]})})}var ZXe=`<>:"/\\|?*`;function QXe(e){for(let t of e)if(ZXe.includes(t)||t.charCodeAt(0)<32)return t;return null}function $Xe({type:e,currentName:t,onClose:n,onSave:r,isLoading:i,t:a}){let o=e===`file`?t.match(/(\.gcode\.3mf|\.3mf|\.gcode)$/i)?.[1]??``:``,s=e===`file`&&o?t.slice(0,-o.length):t,[c,l]=(0,y.useState)(s),u=e===`file`?QXe(c):null,d=u?a(`fileManager.invalidFilenameChar`,{char:u}):null;return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg w-full max-w-sm border border-bambu-dark-tertiary`,children:[(0,G.jsx)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary`,children:(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:a(e===`file`?`fileManager.renameFile`:`fileManager.renameFolder`)})}),(0,G.jsxs)(`form`,{onSubmit:n=>{if(n.preventDefault(),d)return;let i=e===`file`?c.trim()+o:c.trim();c.trim()&&i!==t&&r(i)},className:`p-4 space-y-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`common.name`)}),(0,G.jsxs)(`div`,{className:`flex items-center bg-bambu-dark border rounded focus-within:border-bambu-green ${d?`border-red-500`:`border-bambu-dark-tertiary`}`,children:[(0,G.jsx)(`input`,{type:`text`,value:c,onChange:e=>l(e.target.value),className:`flex-1 bg-transparent px-3 py-2 text-white placeholder-bambu-gray focus:outline-none min-w-0`,autoFocus:!0,required:!0}),o&&(0,G.jsx)(`span`,{className:`pr-3 text-bambu-gray text-sm select-none whitespace-nowrap`,children:o})]}),d&&(0,G.jsx)(`p`,{className:`mt-1 text-xs text-red-700 dark:text-red-400`,children:d})]}),(0,G.jsxs)(`div`,{className:`flex justify-end gap-2 pt-2`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:n,children:a(`common.cancel`)}),(0,G.jsx)(Q,{type:`submit`,disabled:!c.trim()||c.trim()===s||!!d||i,children:i?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):a(`common.rename`)})]})]})]})})}function eZe({folders:e,selectedFiles:t,currentFolderId:n,onClose:r,onMove:i,isLoading:a,t:o}){let[s,c]=(0,y.useState)(null),l=(e,t=0)=>{let n=[];for(let r of e)n.push({id:r.id,name:r.name,depth:t}),r.children.length>0&&n.push(...l(r.children,t+1));return n},u=[{id:null,name:o(`fileManager.rootNoFolder`),depth:0},...l(e)];return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg w-full max-w-sm border border-bambu-dark-tertiary`,children:[(0,G.jsx)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary`,children:(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:o(`fileManager.moveFiles`,{count:t.length})})}),(0,G.jsxs)(`div`,{className:`p-4 space-y-4`,children:[(0,G.jsx)(`div`,{className:`max-h-64 overflow-y-auto space-y-1`,children:u.map(e=>(0,G.jsxs)(`button`,{onClick:()=>c(e.id),disabled:e.id===n,className:`w-full text-left px-3 py-2 rounded transition-colors flex items-center gap-2 ${s===e.id?`bg-bambu-green/20 text-bambu-green`:e.id===n?`opacity-50 cursor-not-allowed text-bambu-gray`:`hover:bg-bambu-dark text-white`}`,style:{paddingLeft:`${12+e.depth*16}px`},children:[(0,G.jsx)(hc,{className:`w-4 h-4`}),e.name,e.id===n&&(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray ml-auto`,children:[`(`,o(`fileManager.current`),`)`]})]},e.id??`root`))}),(0,G.jsxs)(`div`,{className:`flex justify-end gap-2 pt-2`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:r,children:o(`common.cancel`)}),(0,G.jsx)(Q,{onClick:()=>i(s),disabled:a,children:a?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):o(`common.move`)})]})]})]})})}function tZe({folder:e,onClose:t,onLink:n,isLoading:r,t:i}){let[a,o]=(0,y.useState)(`project`),[s,c]=(0,y.useState)(e.project_id||e.archive_id||null);(0,y.useState)(()=>{e.archive_id&&o(`archive`)});let{data:l}=K({queryKey:[`projects`],queryFn:()=>Z.getProjects(),select:e=>[...e].sort((e,t)=>e.name.localeCompare(t.name))}),{data:u}=K({queryKey:[`archives-for-link`],queryFn:()=>Z.getArchives(void 0,void 0,100)}),d=()=>{n(a===`project`?{project_id:s,archive_id:0}:{project_id:0,archive_id:s})},f=()=>{n({project_id:0,archive_id:0})},p=e.project_id||e.archive_id;return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg w-full max-w-md border border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary flex items-center justify-between`,children:[(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(Jc,{className:`w-5 h-5 text-bambu-green`}),i(`fileManager.linkFolder`)]}),(0,G.jsx)(`button`,{onClick:t,className:`p-1 hover:bg-bambu-dark rounded`,children:(0,G.jsx)($u,{className:`w-5 h-5 text-bambu-gray`})})]}),(0,G.jsxs)(`div`,{className:`p-4 space-y-4`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`fileManager.linkFolderDescription`,{name:e.name})}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsxs)(`button`,{onClick:()=>{o(`project`),c(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg border transition-colors ${a===`project`?`border-bambu-green bg-bambu-green/10 text-bambu-green`:`border-bambu-dark-tertiary text-bambu-gray hover:text-white`}`,children:[(0,G.jsx)(Xo,{className:`w-4 h-4`}),i(`fileManager.project`)]}),(0,G.jsxs)(`button`,{onClick:()=>{o(`archive`),c(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg border transition-colors ${a===`archive`?`border-bambu-green bg-bambu-green/10 text-bambu-green`:`border-bambu-dark-tertiary text-bambu-gray hover:text-white`}`,children:[(0,G.jsx)(No,{className:`w-4 h-4`}),i(`fileManager.archive`)]})]}),(0,G.jsx)(`div`,{className:`max-h-64 overflow-y-auto space-y-1 bg-bambu-dark rounded-lg p-2`,children:a===`project`?l&&l.length>0?l.map(e=>(0,G.jsxs)(`button`,{onClick:()=>c(e.id),className:`w-full text-left px-3 py-2 rounded transition-colors flex items-center gap-2 ${s===e.id?`bg-bambu-green/20 text-bambu-green`:`hover:bg-bambu-dark-tertiary text-white`}`,children:[(0,G.jsx)(`div`,{className:`w-3 h-3 rounded-full flex-shrink-0`,style:{backgroundColor:e.color||`#00ae42`}}),(0,G.jsx)(`span`,{className:`truncate`,children:e.name})]},e.id)):(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray text-center py-4`,children:i(`fileManager.noProjectsFound`)}):u&&u.length>0?u.map(e=>(0,G.jsxs)(`button`,{onClick:()=>c(e.id),className:`w-full text-left px-3 py-2 rounded transition-colors flex items-center gap-2 ${s===e.id?`bg-bambu-green/20 text-bambu-green`:`hover:bg-bambu-dark-tertiary text-white`}`,children:[(0,G.jsx)(ac,{className:`w-4 h-4 text-bambu-gray flex-shrink-0`}),(0,G.jsx)(`span`,{className:`truncate`,children:e.print_name||e.filename})]},e.id)):(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray text-center py-4`,children:i(`fileManager.noArchivesFound`)})})]}),(0,G.jsxs)(`div`,{className:`p-4 border-t border-bambu-dark-tertiary flex justify-between`,children:[p&&(0,G.jsxs)(Q,{variant:`danger`,onClick:f,disabled:r,children:[(0,G.jsx)(Lu,{className:`w-4 h-4 mr-2`}),i(`fileManager.unlink`)]}),(0,G.jsxs)(`div`,{className:`flex gap-2 ${p?``:`ml-auto`}`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:t,children:i(`common.cancel`)}),(0,G.jsx)(Q,{onClick:d,disabled:!s||r,children:r?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):i(`fileManager.link`)})]})]})]})})}function nZe({folder:e,selectedFolderId:t,onSelect:n,onDelete:r,onLink:i,onRename:a,depth:o=0,wrapNames:s=!1,defaultExpanded:c=!0,showModified:l=!1,hasPermission:u,t:d}){let[f,p]=(0,y.useState)(c),[m,h]=(0,y.useState)(!1),g=e.children.length>0,_=e.project_id||e.archive_id,v=e.is_external,b=u(`library:delete_all`)||u(`library:delete_own`)&&e.file_count===0&&!g&&!v&&!_,x=b?void 0:u(`library:delete_own`)&&!v&&!_?d(`fileManager.onlyEmptyFoldersDeletable`):d(`fileManager.noPermissionDeleteFolder`);return(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`group flex items-center gap-1 px-2 py-1.5 rounded cursor-pointer transition-colors ${t===e.id?`bg-bambu-green/20 text-bambu-green`:`hover:bg-bambu-dark text-white`}`,style:{paddingLeft:`${8+o*12}px`},onClick:()=>n(e.id),children:[g?(0,G.jsx)(`button`,{onClick:e=>{e.stopPropagation(),p(!f)},className:`p-0.5 hover:bg-bambu-dark-tertiary rounded`,children:(0,G.jsx)(fs,{className:`w-3.5 h-3.5 transition-transform ${f?`rotate-90`:``}`})}):(0,G.jsx)(`div`,{className:`w-4.5`}),v?(0,G.jsx)(_c,{className:`w-4 h-4 text-purple-600 dark:text-purple-400 flex-shrink-0`}):(0,G.jsx)(hc,{className:`w-4 h-4 text-bambu-green flex-shrink-0`}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`span`,{className:`block text-sm ${s?`break-all`:`truncate`}`,title:e.name,children:e.name}),l&&e.latest_activity_at&&(0,G.jsxs)(`span`,{className:`mt-0.5 flex items-center gap-1 text-xs text-bambu-gray`,title:d(`fileManager.lastActivity`),children:[(0,G.jsx)(ts,{className:`w-3 h-3 flex-shrink-0`}),(0,G.jsx)(`span`,{className:`truncate`,children:qf(e.latest_activity_at)})]})]}),_&&(0,G.jsxs)(`button`,{onClick:t=>{t.stopPropagation(),i(e)},className:`flex-shrink-0 flex items-center gap-1 text-xs px-1.5 py-0.5 rounded bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400 hover:bg-blue-200 dark:hover:bg-blue-500/30 transition-colors`,title:`${e.project_name?`Project: ${e.project_name}`:`Archive: ${e.archive_name}`} (click to change)`,children:[(0,G.jsx)(Jc,{className:`w-3 h-3`}),e.project_name?(0,G.jsx)(Xo,{className:`w-3 h-3`}):(0,G.jsx)(No,{className:`w-3 h-3`})]}),v&&e.external_readonly&&(0,G.jsx)(`span`,{title:d(`fileManager.readOnly`),children:(0,G.jsx)(el,{className:`w-3 h-3 text-amber-600 dark:text-amber-400 flex-shrink-0`})}),e.file_count>0&&(0,G.jsx)(`span`,{className:`flex-shrink-0 text-xs text-bambu-gray`,children:e.file_count}),!_&&!v&&(0,G.jsx)(`button`,{onClick:t=>{t.stopPropagation(),i(e)},className:`flex-shrink-0 p-1 rounded hover:bg-bambu-dark-tertiary`,title:d(`fileManager.linkToProjectOrArchive`),children:(0,G.jsx)(Jc,{className:`w-3.5 h-3.5 text-bambu-gray hover:text-bambu-green`})}),(0,G.jsx)(`div`,{className:`flex-shrink-0 flex items-center gap-0.5 transition-opacity ${s?``:`opacity-0 group-hover:opacity-100`}`,onClick:e=>e.stopPropagation(),children:(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(`button`,{onClick:()=>h(!m),className:`p-1 rounded hover:bg-bambu-dark-tertiary`,children:(0,G.jsx)(Zs,{className:`w-3.5 h-3.5 text-bambu-gray`})}),m&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`fixed inset-0 z-10`,onClick:()=>h(!1)}),(0,G.jsxs)(`div`,{className:`absolute right-0 top-full mt-1 z-20 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl py-1 min-w-[120px]`,children:[(0,G.jsxs)(`button`,{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${u(`library:update_all`)?`text-white hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{u(`library:update_all`)&&(a(e),h(!1))},disabled:!u(`library:update_all`),title:u(`library:update_all`)?void 0:d(`fileManager.noPermissionRenameFolder`),children:[(0,G.jsx)(Ol,{className:`w-3.5 h-3.5`}),d(`common.rename`)]}),(0,G.jsxs)(`button`,{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${u(`library:update_all`)?`text-white hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{u(`library:update_all`)&&(i(e),h(!1))},disabled:!u(`library:update_all`),title:u(`library:update_all`)?void 0:d(`fileManager.noPermissionLinkFolder`),children:[(0,G.jsx)(Jc,{className:`w-3.5 h-3.5`}),d(_?`fileManager.changeLink`:`fileManager.linkTo`)]}),(0,G.jsxs)(`button`,{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${b?`text-red-700 dark:text-red-400 hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{b&&(r(e.id),h(!1))},disabled:!b,title:x,children:[(0,G.jsx)(ju,{className:`w-3.5 h-3.5`}),d(`common.delete`)]})]})]})]})})]}),g&&f&&(0,G.jsx)(`div`,{children:e.children.map(e=>(0,G.jsx)(nZe,{folder:e,selectedFolderId:t,onSelect:n,onDelete:r,onLink:i,onRename:a,depth:o+1,wrapNames:s,defaultExpanded:c,showModified:l,hasPermission:u,t:d},e.id))})]})}function u9(e){let t=e.toLowerCase();return t.endsWith(`.gcode`)||t.endsWith(`.gcode.3mf`)}function rZe({file:e,isSelected:t,isMobile:n,onSelect:r,onDelete:i,onDownload:a,onPrint:o,onSlice:s,onOpenInSlicer:c,onRunPipeline:l,useSlicerApi:u,canSlice:d,onPreview3d:f,onRename:p,onGenerateThumbnail:m,onTagClick:h,thumbnailVersion:g,hasPermission:_,canModify:v,authEnabled:b,showModified:x,t:S}){let[C,w]=(0,y.useState)(!1);return(0,G.jsxs)(`div`,{className:`group relative bg-bambu-dark-secondary rounded-lg border transition-all cursor-pointer overflow-hidden ${t?`border-bambu-green ring-1 ring-bambu-green`:`border-bambu-dark-tertiary hover:border-bambu-green/50`}`,onClick:()=>r(e.id),children:[(0,G.jsxs)(`div`,{className:`aspect-square bg-bambu-dark flex items-center justify-center overflow-hidden`,children:[e.thumbnail_path?(0,G.jsx)(`img`,{src:`${Z.getLibraryFileThumbnailUrl(e.id)}${g?(Z.getLibraryFileThumbnailUrl(e.id).includes(`?`)?`&`:`?`)+`v=${g}`:``}`,alt:e.filename,className:`w-full h-full object-cover`}):(0,G.jsx)(ac,{className:`w-12 h-12 text-bambu-gray/30`}),(0,G.jsx)(`div`,{className:`absolute top-2 right-2 text-xs px-1.5 py-0.5 rounded font-medium ${e.file_type===`3mf`?`bg-bambu-green/90 text-white`:e.file_type===`gcode`||e.file_type===`gcode.3mf`?`bg-blue-500/90 text-white`:e.file_type===`stl`?`bg-purple-500/90 text-white`:`bg-bambu-gray/90 text-white`}`,children:e.file_type.toUpperCase()})]}),(0,G.jsxs)(`div`,{className:`p-3`,children:[(0,G.jsx)(`h3`,{className:`text-sm font-medium text-white truncate`,title:e.print_name||e.filename,children:e.print_name||e.filename}),(0,G.jsxs)(`div`,{className:`flex items-center gap-3 mt-1 text-xs text-bambu-gray`,children:[(0,G.jsx)(`span`,{children:Rd(e.file_size)}),e.print_time_seconds&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(ks,{className:`w-3 h-3`}),Qf(e.print_time_seconds)]})]}),e.sliced_for_model&&(0,G.jsxs)(`div`,{className:`mt-1 text-xs text-bambu-gray flex items-center gap-1`,children:[(0,G.jsx)(Fl,{className:`w-3 h-3`}),e.sliced_for_model]}),(e.variant_count??0)>1&&(0,G.jsxs)(`div`,{className:`mt-1 text-xs text-bambu-green flex items-center gap-1`,children:[(0,G.jsx)(Gc,{className:`w-3 h-3`}),S(`fileManager.variants.badge`,{count:e.variant_count})]}),e.print_count>0&&(0,G.jsx)(`div`,{className:`mt-1 text-xs text-bambu-green`,children:S(`fileManager.printedCount`,{count:e.print_count})}),b&&e.created_by_username&&(0,G.jsxs)(`div`,{className:`mt-1 text-xs text-bambu-gray flex items-center gap-1`,children:[(0,G.jsx)(zu,{className:`w-3 h-3`}),e.created_by_username]}),x&&(0,G.jsxs)(`div`,{className:`mt-1 text-xs text-bambu-gray flex items-center gap-1`,title:S(`fileManager.lastModified`),children:[(0,G.jsx)(ts,{className:`w-3 h-3`}),qf(e.fs_modified_at??e.created_at)]}),(e.tags?.length??0)>0&&(0,G.jsx)(`div`,{className:`mt-2 flex flex-wrap gap-1`,onClick:e=>e.stopPropagation(),children:e.tags.map(e=>(0,G.jsxs)(`button`,{type:`button`,onClick:()=>h?.(e.id),className:`inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded-full text-[10px] bg-bambu-green/10 text-bambu-green hover:bg-bambu-green/20 transition-colors max-w-full`,title:e.name,children:[(0,G.jsx)(Cu,{className:`w-2.5 h-2.5 flex-shrink-0`}),(0,G.jsx)(`span`,{className:`truncate`,children:e.name})]},e.id))})]}),(0,G.jsxs)(`div`,{className:`absolute bottom-2 right-2 transition-opacity ${n?`opacity-100`:`opacity-0 group-hover:opacity-100`}`,onClick:e=>e.stopPropagation(),children:[(0,G.jsx)(`button`,{onClick:()=>w(!C),className:`p-1.5 rounded bg-bambu-dark-secondary/90 hover:bg-bambu-dark-tertiary`,children:(0,G.jsx)(Zs,{className:`w-4 h-4 text-bambu-gray`})}),C&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`fixed inset-0 z-10`,onClick:()=>w(!1)}),(0,G.jsxs)(`div`,{className:`absolute right-0 bottom-8 z-20 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl py-1 min-w-[140px]`,children:[o&&u9(e.filename)&&(0,G.jsxs)(`button`,{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${_(`queue:create`)?`text-bambu-green hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{_(`queue:create`)&&(o(e),w(!1))},disabled:!_(`queue:create`),title:_(`queue:create`)?void 0:S(`fileManager.noPermissionAddToQueue`),children:[(0,G.jsx)(Fl,{className:`w-3.5 h-3.5`}),S(`common.print`)]}),XW(e.filename)&&(u?s:c)&&(0,G.jsxs)(`button`,{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${d?`text-white hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{d&&(u?s?.(e):c?.(e),w(!1))},disabled:!d,title:d?void 0:S(u?`fileManager.noPermissionSlice`:`fileManager.noPermissionDownload`),children:[u?(0,G.jsx)(Is,{className:`w-3.5 h-3.5`}):(0,G.jsx)(tc,{className:`w-3.5 h-3.5`}),S(`slice.action`)]}),l&&u&&XW(e.filename)&&(0,G.jsxs)(`button`,{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${_(`pipelines:run`)?`text-white hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{_(`pipelines:run`)&&(l(e),w(!1))},disabled:!_(`pipelines:run`),title:_(`pipelines:run`)?void 0:S(`library.runWithPipeline.noPermission`),children:[(0,G.jsx)(Al,{className:`w-3.5 h-3.5`}),S(`library.runWithPipeline.actionLabel`)]}),f&&(e.file_type===`3mf`||e.file_type===`gcode`||e.file_type===`stl`||e.file_type===`gcode.3mf`)&&(0,G.jsxs)(`button`,{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${_(`library:read`)?`text-white hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{_(`library:read`)&&(f(e),w(!1))},disabled:!_(`library:read`),title:_(`library:read`)?void 0:`You do not have permission to preview files`,children:[(0,G.jsx)(Yo,{className:`w-3.5 h-3.5`}),`3D Preview`]}),(0,G.jsxs)(`button`,{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${_(`library:read`)?`text-white hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{_(`library:read`)&&(a(e.id),w(!1))},disabled:!_(`library:read`),title:_(`library:read`)?void 0:S(`fileManager.noPermissionDownload`),children:[(0,G.jsx)(Js,{className:`w-3.5 h-3.5`}),S(`common.download`)]}),p&&(0,G.jsxs)(`button`,{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${v(`library`,`update`,e.created_by_id)?`text-white hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{v(`library`,`update`,e.created_by_id)&&(p(e),w(!1))},disabled:!v(`library`,`update`,e.created_by_id),title:v(`library`,`update`,e.created_by_id)?void 0:S(`fileManager.noPermissionRenameFile`),children:[(0,G.jsx)(Ol,{className:`w-3.5 h-3.5`}),S(`common.rename`)]}),m&&e.file_type===`stl`&&(0,G.jsxs)(`button`,{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${v(`library`,`update`,e.created_by_id)?`text-white hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{v(`library`,`update`,e.created_by_id)&&(m(e),w(!1))},disabled:!v(`library`,`update`,e.created_by_id),title:v(`library`,`update`,e.created_by_id)?void 0:S(`fileManager.noPermissionGenerateThumbnail`),children:[(0,G.jsx)(zc,{className:`w-3.5 h-3.5`}),S(`fileManager.generateThumbnail`)]}),(0,G.jsxs)(`button`,{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${v(`library`,`delete`,e.created_by_id)?`text-red-700 dark:text-red-400 hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{v(`library`,`delete`,e.created_by_id)&&(i(e.id),w(!1))},disabled:!v(`library`,`delete`,e.created_by_id),title:v(`library`,`delete`,e.created_by_id)?void 0:S(`fileManager.noPermissionDeleteFile`),children:[(0,G.jsx)(ju,{className:`w-3.5 h-3.5`}),S(`common.delete`)]})]})]})]}),(0,G.jsx)(`div`,{className:`absolute top-2 left-2 w-5 h-5 rounded border-2 flex items-center justify-center transition-all ${t?`bg-bambu-green border-bambu-green`:`border-white/30 bg-black/30 ${n?`opacity-100`:`opacity-0 group-hover:opacity-100`}`}`,children:t&&(0,G.jsx)(`div`,{className:`w-2 h-2 bg-white rounded-sm`})})]})}function iZe(){let{t:e}=U(),t=so(),{showToast:n}=Bd(),{hasPermission:r,hasAnyPermission:i,canModify:a,authEnabled:o}=Ed(),[s]=Li(),c=or(),l=s.get(`folder`),[u,d]=(0,y.useState)(l?parseInt(l,10):null),[f,p]=(0,y.useState)(`internal`),[m,h]=(0,y.useState)([]),[g,_]=(0,y.useState)(!1),[v,b]=(0,y.useState)(!1),[x,S]=(0,y.useState)(!1),[C,w]=(0,y.useState)(!1),[T,E]=(0,y.useState)([]),[D,O]=(0,y.useState)(!1),[k,A]=(0,y.useState)(!1),[j,M]=(0,y.useState)(!1),[N,P]=(0,y.useState)([]),[F,I]=(0,y.useState)(null),[L,R]=(0,y.useState)(null),[z,B]=(0,y.useState)(null),[V,ee]=(0,y.useState)(null),[te,ne]=(0,y.useState)(null),[re,ie]=(0,y.useState)(null),[ae,oe]=(0,y.useState)({}),[se,H]=(0,y.useState)(null),[ce,le]=(0,y.useState)(()=>localStorage.getItem(`library-view-mode`)||`grid`),[ue,de]=(0,y.useState)(()=>localStorage.getItem(`library-wrap-folders`)===`true`),[fe,pe]=(0,y.useState)(()=>localStorage.getItem(`library-collapse-folders`)===`true`),[me,he]=(0,y.useState)(()=>localStorage.getItem(`library-folder-sort-field`)===`activity`?`activity`:`name`),[ge,_e]=(0,y.useState)(()=>localStorage.getItem(`library-folder-sort-direction`)===`desc`?`desc`:`asc`),[ve,ye]=(0,y.useState)(()=>{let e=localStorage.getItem(`library-sidebar-width`);return e?parseInt(e,10):256}),[be,xe]=(0,y.useState)(!1),Se=(0,y.useRef)(null);(0,y.useEffect)(()=>{if(!be)return;document.body.style.userSelect=`none`,document.body.style.cursor=`col-resize`;let e=e=>{if(!Se.current)return;let t=Se.current.parentElement?.getBoundingClientRect();if(!t)return;let n=e.clientX-t.left;ye(Math.min(500,Math.max(200,n)))},t=()=>{xe(!1),document.body.style.userSelect=``,document.body.style.cursor=``,localStorage.setItem(`library-sidebar-width`,String(ve))};return document.addEventListener(`mousemove`,e),document.addEventListener(`mouseup`,t),()=>{document.removeEventListener(`mousemove`,e),document.removeEventListener(`mouseup`,t),document.body.style.userSelect=``,document.body.style.cursor=``}},[be,ve]);let[Ce,we]=(0,y.useState)(``),[Te,Ee]=(0,y.useState)(`all`),[De,Oe]=(0,y.useState)(``),[ke,Ae]=(0,y.useState)(()=>localStorage.getItem(`library-sort-field`)||`name`),[je,Me]=(0,y.useState)(()=>localStorage.getItem(`library-sort-direction`)||`asc`),[Ne,Pe]=(0,y.useState)(()=>localStorage.getItem(`library-show-modified`)===`true`),Fe=Up();(0,y.useEffect)(()=>{let e=s.get(`folder`);e&&d(parseInt(e,10))},[s]);let{data:Ie}=K({queryKey:[`settings`],queryFn:()=>Z.getSettings()}),Le=JW(Ie?.open_in_slicer,Ie?.preferred_slicer),Re=(0,y.useCallback)(async t=>{try{let{token:e}=await Z.createLibrarySlicerToken(t.id),n=Z.getLibrarySlicerDownloadUrl(t.id,e,t.filename);ZW(`${window.location.origin}${n}`,Le)}catch{n(e(`fileManager.toast.openInSlicerFailed`),`error`);let r=Z.getLibraryFileDownloadUrl(t.id);ZW(`${window.location.origin}${r}`,Le)}},[Le,n,e]),ze=(0,y.useCallback)(()=>Ie?.use_slicer_api?r(`library:upload`):i(`library:read_all`,`library:read_own`),[Ie?.use_slicer_api,r,i]),{data:Be,isLoading:Ve}=K({queryKey:[`library-folders`],queryFn:()=>Z.getLibraryFolders()}),He=(0,y.useMemo)(()=>{if(!Be)return Be;let e=t=>[...t].sort((e,t)=>{let n=0;if(me===`name`)n=e.name.localeCompare(t.name);else{let r=e.latest_activity_at?new Date(e.latest_activity_at).getTime():null,i=t.latest_activity_at?new Date(t.latest_activity_at).getTime():null;if(r===null&&i===null)n=e.name.localeCompare(t.name);else if(r===null)return 1;else if(i===null)return-1;else n=r-i}return ge===`asc`?n:-n}).map(t=>({...t,children:e(t.children)}));return e(Be)},[Be,me,ge]),{data:Ue}=K({queryKey:[`library-trash-count`],queryFn:async()=>{try{return(await Z.listLibraryTrash(1,0)).total}catch{return 0}},staleTime:3e4}),We=u!==null&&Ce.trim().length>0,Ge=(0,y.useMemo)(()=>[...N].sort((e,t)=>e-t),[N]),{data:Ke=[]}=K({queryKey:[`library-tags`],queryFn:Z.getLibraryTags}),qe=(0,y.useMemo)(()=>{let e=new Map;for(let t of Ke)e.set(t.id,t.name);return e},[Ke]);(0,y.useEffect)(()=>{Ke.length!==0&&P(e=>{let t=e.filter(e=>qe.has(e));return t.length===e.length?e:t})},[Ke.length,qe]);let Je=(0,y.useCallback)(e=>{P(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},[]),{data:Ye,isLoading:Xe}=K({queryKey:[`library-files`,u,f,We,Ge],queryFn:()=>Z.getLibraryFiles(u,!1,void 0,u===null?f:void 0,We,Ge)}),{data:Ze}=K({queryKey:[`library-stats`],queryFn:()=>Z.getLibraryStats()}),{data:Qe}=K({queryKey:[`users`],queryFn:()=>Z.getUsers()}),$e=(0,y.useMemo)(()=>{if(!Ye)return[];let e=new Set(Ye.map(e=>e.file_type));return Array.from(e).sort()},[Ye]),et=(0,y.useMemo)(()=>{if(!Ye)return[];let e=[...Ye];if(Ce.trim()){let t=Ce.toLowerCase();e=e.filter(e=>e.filename.toLowerCase().includes(t)||e.print_name&&e.print_name.toLowerCase().includes(t))}if(Te!==`all`&&(e=e.filter(e=>e.file_type===Te)),De.trim()){let t=De.toLowerCase();e=e.filter(e=>e.created_by_username&&e.created_by_username.toLowerCase().includes(t))}return e.sort((e,t)=>{let n=0;switch(ke){case`name`:n=(e.print_name||e.filename).localeCompare(t.print_name||t.filename);break;case`date`:n=(Kf(e.fs_modified_at??e.created_at)?.getTime()??0)-(Kf(t.fs_modified_at??t.created_at)?.getTime()??0);break;case`size`:n=e.file_size-t.file_size;break;case`type`:n=e.file_type.localeCompare(t.file_type);break;case`prints`:n=e.print_count-t.print_count;break}return je===`asc`?n:-n}),e},[Ye,Ce,Te,De,ke,je]),tt=(0,y.useMemo)(()=>{if(!Ze||!Ie)return!1;let e=(Ie.library_disk_warning_gb||5)*1024*1024*1024;return Ze.disk_free_bytesZ.createLibraryFolder(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`library-folders`]}),_(!1),n(e(`fileManager.toast.folderCreated`),`success`)},onError:e=>n(e.message,`error`)}),rt=q({mutationFn:async e=>{let t=await Z.createExternalFolder(e);return await Z.scanExternalFolder(t.id),t},onSuccess:r=>{t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`library-stats`]}),b(!1),d(r.id),n(e(`fileManager.toast.externalFolderLinked`),`success`)},onError:e=>n(e.message,`error`)}),it=q({mutationFn:e=>Z.scanExternalFolder(e),onSuccess:r=>{t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`library-stats`]}),n(e(`fileManager.toast.folderScanned`,{added:r.added,removed:r.removed}),`success`)},onError:e=>n(e.message,`error`)}),at=q({mutationFn:e=>Z.deleteLibraryFolder(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`library-stats`]}),u===L?.id&&d(null),R(null),n(e(`fileManager.toast.folderDeleted`),`success`)},onError:e=>{R(null),n(e.message,`error`)}}),ot=q({mutationFn:e=>Z.deleteLibraryFile(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`library-stats`]}),t.invalidateQueries({queryKey:[`library-trash-count`]}),h(e=>e.filter(e=>e!==L?.id)),R(null),n(e(`fileManager.toast.fileDeleted`),`success`)},onError:e=>{R(null),n(e.message,`error`)}}),st=q({mutationFn:e=>Z.createVariantGroup(e.map(e=>({library_file_id:e}))),onSuccess:r=>{t.invalidateQueries({queryKey:[`library-files`]}),n(e(`fileManager.variants.grouped`,{count:r.members.length}),`success`),h([])},onError:e=>n(e.message,`error`)}),ct=q({mutationFn:e=>Z.bulkDeleteLibrary(e,[]),onSuccess:(r,i)=>{t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`library-stats`]}),t.invalidateQueries({queryKey:[`library-trash-count`]}),n(e(`fileManager.toast.filesDeleted`,{count:i.length}),`success`),h([]),R(null)},onError:e=>{R(null),n(e.message,`error`)}}),lt=q({mutationFn:({fileIds:e,folderId:t})=>Z.moveLibraryFiles(e,t),onSuccess:()=>{t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`library-folders`]}),h([]),S(!1),n(e(`fileManager.toast.filesMoved`),`success`)},onError:e=>n(e.message,`error`)}),ut=q({mutationFn:({id:e,data:t})=>Z.updateLibraryFolder(e,t),onSuccess:(r,i)=>{t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`project-folders`]}),t.invalidateQueries({queryKey:[`archive-folders`]}),I(null),n(i.data.project_id===0&&i.data.archive_id===0?e(`fileManager.toast.folderUnlinked`):e(`fileManager.toast.folderLinked`),`success`)},onError:e=>n(e.message,`error`)}),dt=q({mutationFn:({id:e,filename:t})=>Z.updateLibraryFile(e,{filename:t}),onSuccess:()=>{t.invalidateQueries({queryKey:[`library-files`]}),ie(null),n(e(`fileManager.toast.fileRenamed`),`success`)},onError:e=>{ie(null),n(e.message,`error`)}}),ft=q({mutationFn:({id:e,name:t})=>Z.updateLibraryFolder(e,{name:t}),onSuccess:()=>{t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`library-files`]}),ie(null),n(e(`fileManager.toast.folderRenamed`),`success`)},onError:e=>{ie(null),n(e.message,`error`)}}),pt=q({mutationFn:()=>Z.batchGenerateStlThumbnails({all_missing:!0}),onSuccess:r=>{if(t.invalidateQueries({queryKey:[`library-files`]}),r.succeeded>0){let e=Date.now(),t={};r.results.forEach(n=>{n.success&&(t[n.file_id]=e)}),oe(e=>({...e,...t}))}r.succeeded>0&&r.failed===0?n(e(`fileManager.toast.thumbnailsGenerated`,{count:r.succeeded}),`success`):r.succeeded>0&&r.failed>0?n(e(`fileManager.toast.thumbnailsGeneratedPartial`,{succeeded:r.succeeded,failed:r.failed}),`success`):r.processed===0?n(e(`fileManager.toast.noStlMissingThumbnails`),`info`):n(e(`fileManager.toast.failedToGenerateThumbnails`,{error:r.results[0]?.error||`Unknown error`}),`error`)},onError:e=>n(e.message,`error`)}),mt=q({mutationFn:e=>Z.batchGenerateStlThumbnails({file_ids:[e]}),onSuccess:r=>{if(t.invalidateQueries({queryKey:[`library-files`]}),r.succeeded>0){let t=r.results[0]?.file_id;t&&oe(e=>({...e,[t]:Date.now()})),n(e(`fileManager.toast.thumbnailGenerated`),`success`)}else n(e(`fileManager.toast.failedToGenerateThumbnail`,{error:r.results[0]?.error||`Unknown error`}),`error`)},onError:e=>n(e.message,`error`)}),ht=(0,y.useCallback)(e=>{let t=e.toLowerCase();return t.endsWith(`.gcode`)||t.includes(`.gcode.`)},[]),gt=(0,y.useMemo)(()=>Ye?Ye.filter(e=>m.includes(e.id)&&ht(e.filename)):[],[Ye,m,ht]),{data:_t}=K({queryKey:[`variant-group`,z?.variant_group_id],queryFn:()=>Z.getVariantGroup(z.variant_group_id),enabled:!!z?.variant_group_id}),vt=(0,y.useMemo)(()=>{if(z){if(gt.length>1)return gt.map(e=>({id:e.id,filename:e.filename,sliced_for_model:e.sliced_for_model}));if(_t&&_t.members.length>1)return _t.members.map(e=>({id:e.library_file_id,filename:e.filename,sliced_for_model:e.target_model}))}},[z,gt,_t]),yt=(0,y.useCallback)(e=>{h(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},[]),bt=(0,y.useCallback)(()=>{et.length>0&&h(et.map(e=>e.id))},[et]),xt=(0,y.useCallback)(()=>{h([])},[]),St=()=>{t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`library-stats`]})},{isDraggingOver:Ct,dragHandlers:wt}=$W({disabled:!r(`library:upload`)||C,onFiles:e=>{E(e),w(!0)}}),Tt=e=>{Z.downloadLibraryFile(e).catch(e=>{console.error(`Library file download failed:`,e)})},Et=()=>{L&&(L.type===`file`?ot.mutate(L.id):L.type===`folder`?at.mutate(L.id):L.type===`bulk`&&ct.mutate(m))},Dt=at.isPending||ot.isPending||ct.isPending,Ot=e=>{le(e),localStorage.setItem(`library-view-mode`,e)},kt=Ve||Xe,At=(0,y.useMemo)(()=>{if(!u||!Be)return null;let e=t=>{for(let n of t){if(n.id===u)return n;let t=e(n.children);if(t)return t}return null};return e(Be)},[u,Be]);return(0,G.jsxs)(`div`,{className:`p-4 md:p-8 min-h-[calc(100vh-64px)] lg:h-[calc(100vh-64px)] flex flex-col relative`,...wt,children:[Ct&&(0,G.jsx)(`div`,{className:`fixed inset-0 z-50 bg-bambu-dark/90 flex items-center justify-center pointer-events-none`,children:(0,G.jsxs)(`div`,{className:`border-4 border-dashed border-bambu-green rounded-xl p-12 text-center`,children:[(0,G.jsx)(Ru,{className:`w-16 h-16 mx-auto mb-4 text-bambu-green`}),(0,G.jsx)(`p`,{className:`text-2xl font-semibold text-white mb-2`,children:e(`fileManager.dropFilesHere`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray`,children:e(`fileManager.releaseToUpload`)})]})}),(0,G.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between gap-4 mb-6`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,G.jsx)(hc,{className:`w-7 h-7 text-bambu-green`}),e(`fileManager.title`)]}),(0,G.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:e(`fileManager.subtitle`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center bg-bambu-dark rounded-lg p-1`,children:[(0,G.jsx)(`button`,{onClick:()=>Ot(`grid`),className:`p-1.5 rounded transition-colors ${ce===`grid`?`bg-bambu-dark-secondary text-white`:`text-bambu-gray hover:text-white`}`,title:e(`fileManager.gridView`),children:(0,G.jsx)(Kc,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:()=>Ot(`list`),className:`p-1.5 rounded transition-colors ${ce===`list`?`bg-bambu-dark-secondary text-white`:`text-bambu-gray hover:text-white`}`,title:e(`fileManager.listView`),children:(0,G.jsx)(Qc,{className:`w-4 h-4`})})]}),(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>pt.mutate(),disabled:pt.isPending||!i(`library:update_own`,`library:update_all`),title:i(`library:update_own`,`library:update_all`)?e(`fileManager.generateThumbnailsForMissing`):e(`fileManager.noPermissionGenerateThumbnail`),children:[pt.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 mr-2 animate-spin`}):(0,G.jsx)(zc,{className:`w-4 h-4 mr-2`}),e(`fileManager.generateThumbnails`)]}),(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>b(!0),disabled:!r(`library:upload`),title:r(`library:upload`)?e(`fileManager.linkExternalFolder`):e(`fileManager.noPermissionCreateFolder`),children:[(0,G.jsx)(_c,{className:`w-4 h-4 mr-2`}),e(`fileManager.linkExternal`)]}),(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>_(!0),disabled:!r(`library:upload`),title:r(`library:upload`)?void 0:e(`fileManager.noPermissionCreateFolder`),children:[(0,G.jsx)(gc,{className:`w-4 h-4 mr-2`}),e(`fileManager.newFolder`)]}),(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>A(!0),title:e(`fileManager.tags.manageTitle`),children:[(0,G.jsx)(Cu,{className:`w-4 h-4 mr-2`}),e(`fileManager.tags.manage`)]}),r(`library:purge`)&&(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>O(!0),title:e(`libraryPurge.headerTooltip`),children:[(0,G.jsx)(ju,{className:`w-4 h-4 mr-2`}),e(`libraryPurge.headerButton`)]}),i(`library:delete_own`,`library:delete_all`)&&(0,G.jsxs)(ki,{to:`/files/trash`,className:`inline-flex items-center px-3 py-1.5 text-sm rounded bg-bambu-dark-secondary text-bambu-gray hover:text-white hover:bg-bambu-dark transition-colors`,title:e(`libraryTrash.headerTooltip`),children:[(0,G.jsx)(ju,{className:`w-4 h-4 mr-2`}),e(`libraryTrash.headerButton`),typeof Ue==`number`&&Ue>0&&(0,G.jsx)(`span`,{className:`ml-1.5 px-1.5 py-0.5 text-xs rounded-full bg-bambu-green/20 text-bambu-green`,children:Ue})]}),(0,G.jsxs)(Q,{onClick:()=>w(!0),disabled:!r(`library:upload`),title:r(`library:upload`)?void 0:e(`fileManager.noPermissionUpload`),children:[(0,G.jsx)(Ru,{className:`w-4 h-4 mr-2`}),e(`common.upload`)]})]})]}),tt&&Ze&&Ie&&(0,G.jsxs)(`div`,{className:`flex items-center gap-3 mb-4 p-3 bg-amber-500/10 border border-amber-500/30 rounded-lg`,children:[(0,G.jsx)(Pu,{className:`w-5 h-5 text-amber-500 flex-shrink-0`}),(0,G.jsxs)(`div`,{className:`flex-1`,children:[(0,G.jsx)(`p`,{className:`text-sm text-amber-500 font-medium`,children:e(`fileManager.lowDiskSpaceWarning`)}),(0,G.jsx)(`p`,{className:`text-xs text-amber-500/80`,children:e(`fileManager.lowDiskSpaceDetails`,{free:Rd(Ze.disk_free_bytes),total:Rd(Ze.disk_total_bytes),threshold:Ie.library_disk_warning_gb})})]})]}),Ze&&(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 sm:gap-6 mb-6 p-3 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,G.jsx)(uc,{className:`w-4 h-4 text-bambu-green`}),(0,G.jsxs)(`span`,{className:`text-bambu-gray`,children:[e(`fileManager.files`),`:`]}),(0,G.jsx)(`span`,{className:`text-white font-medium`,children:Ze.total_files})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,G.jsx)(hc,{className:`w-4 h-4 text-blue-600 dark:text-blue-400`}),(0,G.jsxs)(`span`,{className:`text-bambu-gray`,children:[e(`fileManager.folders`),`:`]}),(0,G.jsx)(`span`,{className:`text-white font-medium`,children:Ze.total_folders})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,G.jsx)(jc,{className:`w-4 h-4 text-amber-600 dark:text-amber-400`}),(0,G.jsxs)(`span`,{className:`text-bambu-gray`,children:[e(`fileManager.size`),`:`]}),(0,G.jsx)(`span`,{className:`text-white font-medium`,children:Rd(Ze.total_size_bytes)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm sm:ml-auto`,children:[(0,G.jsxs)(`span`,{className:`text-bambu-gray`,children:[e(`fileManager.free`),`:`]}),(0,G.jsx)(`span`,{className:`font-medium ${tt?`text-amber-500`:`text-white`}`,children:Rd(Ze.disk_free_bytes)})]})]}),(0,G.jsxs)(`div`,{className:`flex-1 flex flex-col lg:flex-row gap-4 lg:gap-6 min-h-0`,children:[(0,G.jsx)(`div`,{className:`lg:hidden`,children:(0,G.jsxs)(`select`,{value:u===null?`__top:${f}`:String(u),onChange:e=>{let t=e.target.value;t.startsWith(`__top:`)?(d(null),p(t.slice(6))):d(parseInt(t,10))},className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg px-3 py-2.5 text-white focus:outline-none focus:border-bambu-green`,children:[(0,G.jsxs)(`option`,{value:`__top:internal`,children:[`📁 `,e(`fileManager.allFiles`)]}),Be?.some(e=>e.is_external)&&(0,G.jsxs)(`option`,{value:`__top:external`,children:[`🔗 `,e(`fileManager.allExternal`)]}),He&&(()=>{let e=(t,n=0)=>{let r=[];for(let i of t)r.push({id:i.id,name:i.name,fileCount:i.file_count,depth:n}),i.children.length>0&&r.push(...e(i.children,n+1));return r};return e(He).map(e=>(0,G.jsxs)(`option`,{value:e.id,children:[`│ `.repeat(e.depth),`📂 `,e.name,` `,e.fileCount>0?`(${e.fileCount})`:``]},e.id))})()]})}),(0,G.jsxs)(`div`,{ref:Se,className:`hidden lg:flex flex-shrink-0 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary overflow-hidden flex-col relative`,style:{width:`${ve}px`},children:[(0,G.jsx)(`div`,{className:`absolute right-0 top-0 bottom-0 w-1.5 cursor-col-resize z-10 group/resize flex items-center justify-center transition-colors ${be?`bg-bambu-green`:`hover:bg-bambu-green/50`}`,onMouseDown:e=>{e.preventDefault(),xe(!0)},onDoubleClick:()=>{ye(256),localStorage.setItem(`library-sidebar-width`,`256`)},title:e(`fileManager.dragToResizeTooltip`),children:(0,G.jsxs)(`div`,{className:`flex flex-col gap-1 opacity-0 group-hover/resize:opacity-100 transition-opacity ${be?`opacity-100`:``}`,children:[(0,G.jsx)(`div`,{className:`w-0.5 h-0.5 rounded-full bg-white/70`}),(0,G.jsx)(`div`,{className:`w-0.5 h-0.5 rounded-full bg-white/70`}),(0,G.jsx)(`div`,{className:`w-0.5 h-0.5 rounded-full bg-white/70`})]})}),(0,G.jsxs)(`div`,{className:`p-3 border-b border-bambu-dark-tertiary flex items-center justify-between`,children:[(0,G.jsx)(`h2`,{className:`text-sm font-medium text-white`,children:e(`fileManager.folders`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,G.jsxs)(`select`,{value:me,onChange:e=>{let t=e.target.value===`activity`?`activity`:`name`;he(t),localStorage.setItem(`library-folder-sort-field`,t)},className:`text-xs px-1 py-0.5 rounded bg-bambu-dark border border-bambu-dark-tertiary text-bambu-gray focus:outline-none focus:border-bambu-green`,title:e(`fileManager.folderSort`),"aria-label":e(`fileManager.folderSort`),children:[(0,G.jsx)(`option`,{value:`name`,children:e(`fileManager.folderSortByName`)}),(0,G.jsx)(`option`,{value:`activity`,children:e(`fileManager.folderSortByActivity`)})]}),(0,G.jsx)(`button`,{onClick:()=>{let e=ge===`asc`?`desc`:`asc`;_e(e),localStorage.setItem(`library-folder-sort-direction`,e)},className:`text-bambu-gray hover:text-white hover:bg-bambu-dark p-1 rounded transition-colors`,title:e(ge===`asc`?`fileManager.ascending`:`fileManager.descending`),"aria-label":e(ge===`asc`?`fileManager.ascending`:`fileManager.descending`),children:ge===`asc`?(0,G.jsx)(Bo,{className:`w-3.5 h-3.5`}):(0,G.jsx)(Po,{className:`w-3.5 h-3.5`})}),(0,G.jsx)(`button`,{onClick:()=>{let e=!fe;pe(e),localStorage.setItem(`library-collapse-folders`,String(e))},className:`text-xs px-1.5 py-0.5 rounded transition-colors ${fe?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:text-white hover:bg-bambu-dark`}`,title:e(fe?`fileManager.expandFoldersByDefault`:`fileManager.collapseFoldersByDefault`),children:e(`fileManager.collapse`)}),(0,G.jsx)(`button`,{onClick:()=>{let e=!ue;de(e),localStorage.setItem(`library-wrap-folders`,String(e))},className:`text-xs px-1.5 py-0.5 rounded transition-colors ${ue?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:text-white hover:bg-bambu-dark`}`,title:e(ue?`fileManager.disableTextWrapping`:`fileManager.enableTextWrapping`),children:e(`fileManager.wrap`)})]})]}),(0,G.jsxs)(`div`,{className:`flex-1 overflow-y-auto p-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-1.5 rounded cursor-pointer transition-colors ${u===null&&f===`internal`?`bg-bambu-green/20 text-bambu-green`:`hover:bg-bambu-dark text-white`}`,onClick:()=>{d(null),p(`internal`)},children:[(0,G.jsx)(ac,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`text-sm`,children:e(`fileManager.allFiles`)})]}),Be?.some(e=>e.is_external)&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-1.5 rounded cursor-pointer transition-colors ${u===null&&f===`external`?`bg-bambu-green/20 text-bambu-green`:`hover:bg-bambu-dark text-white`}`,onClick:()=>{d(null),p(`external`)},children:[(0,G.jsx)(_c,{className:`w-4 h-4 text-purple-600 dark:text-purple-400`}),(0,G.jsx)(`span`,{className:`text-sm`,children:e(`fileManager.allExternal`)})]}),He?.map(t=>(0,G.jsx)(nZe,{folder:t,selectedFolderId:u,onSelect:d,onDelete:e=>R({type:`folder`,id:e}),onLink:I,onRename:e=>ie({type:`folder`,id:e.id,name:e.name}),wrapNames:ue,defaultExpanded:!fe,showModified:Ne,hasPermission:r,t:e},`${t.id}-${fe?`c`:`e`}`))]})]}),(0,G.jsxs)(`div`,{className:`flex-1 flex flex-col lg:flex-row min-w-0 min-h-0 gap-4 lg:gap-6`,children:[(0,G.jsxs)(`div`,{className:`flex-1 flex flex-col min-w-0 min-h-0`,children:[Ke.length>0&&(0,G.jsxs)(`div`,{className:`mb-3 flex flex-wrap items-center gap-2 p-2 sm:p-3 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary`,children:[(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray font-medium shrink-0`,children:e(`fileManager.tags.filterLabel`)}),Ke.map(e=>{let t=N.includes(e.id);return(0,G.jsxs)(`button`,{type:`button`,onClick:()=>Je(e.id),className:t?`inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs bg-bambu-green/20 text-bambu-green border border-bambu-green/40 hover:bg-bambu-green/30 transition-colors`:`inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs bg-bambu-dark text-bambu-gray border border-bambu-dark-tertiary hover:text-white hover:border-bambu-green/40 transition-colors`,title:e.name,children:[(0,G.jsx)(Cu,{className:`w-3 h-3`}),(0,G.jsx)(`span`,{children:e.name}),t&&(0,G.jsx)($u,{className:`w-3 h-3`})]},e.id)}),N.length>0&&(0,G.jsx)(`button`,{type:`button`,onClick:()=>P([]),className:`ml-auto text-xs text-bambu-gray hover:text-white shrink-0`,children:e(`fileManager.tags.clearAll`)})]}),At?.is_external&&(0,G.jsxs)(`div`,{className:`flex items-center gap-3 mb-4 p-3 bg-purple-50 dark:bg-purple-500/10 border border-purple-300 dark:border-purple-500/30 rounded-lg`,children:[(0,G.jsx)(_c,{className:`w-5 h-5 text-purple-600 dark:text-purple-400 flex-shrink-0`}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-sm font-medium text-purple-700 dark:text-purple-300`,children:e(`fileManager.externalFolder`)}),At.external_readonly&&(0,G.jsxs)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-400 flex items-center gap-1`,children:[(0,G.jsx)(el,{className:`w-3 h-3`}),e(`fileManager.readOnly`)]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray truncate font-mono`,title:At.external_path||``,children:At.external_path})]}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:()=>u&&it.mutate(u),disabled:it.isPending,title:e(`fileManager.scanFolder`),children:[it.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(zl,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`ml-1.5`,children:e(`fileManager.scanFolder`)})]})]}),Ye&&Ye.length>0&&(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 sm:gap-3 mb-4 p-2 sm:p-3 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary sticky top-0 z-10 lg:static`,children:[(0,G.jsxs)(`div`,{className:`relative w-full sm:w-auto sm:flex-1 sm:max-w-xs`,children:[(0,G.jsx)(Yl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,G.jsx)(`input`,{type:`text`,placeholder:e(`fileManager.searchFiles`),value:Ce,onChange:e=>we(e.target.value),className:`w-full pl-9 pr-3 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`}),We&&(0,G.jsx)(`span`,{className:`absolute -bottom-4 left-0 text-[10px] text-bambu-gray whitespace-nowrap`,title:e(`fileManager.searchSubfoldersHint`),children:e(`fileManager.searchSubfoldersHint`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(xc,{className:`w-4 h-4 text-bambu-gray hidden sm:block`}),(0,G.jsxs)(`select`,{value:Te,onChange:e=>Ee(e.target.value),className:`bg-bambu-dark border border-bambu-dark-tertiary rounded px-2 py-1.5 text-sm text-white focus:outline-none focus:border-bambu-green`,children:[(0,G.jsx)(`option`,{value:`all`,children:e(`fileManager.allTypes`)}),$e.map(e=>(0,G.jsx)(`option`,{value:e,children:e.toUpperCase()},e))]})]}),o&&(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(`input`,{type:`text`,placeholder:e(`fileManager.filterByUser`,{defaultValue:`Filter by user`}),value:De,onChange:e=>Oe(e.target.value),list:`usernames-list`,className:`w-32 sm:w-40 px-2 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green ${De?`pr-7`:``}`,style:De?{WebkitAppearance:`none`,MozAppearance:`textfield`}:void 0}),De&&(0,G.jsx)(`button`,{onClick:()=>Oe(``),className:`absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white z-10`,children:(0,G.jsx)($u,{className:`w-3 h-3`})}),(0,G.jsx)(`datalist`,{id:`usernames-list`,children:Qe?.map(e=>(0,G.jsx)(`option`,{value:e.username},e.id))})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`select`,{value:ke,onChange:e=>{let t=e.target.value;Ae(t),localStorage.setItem(`library-sort-field`,t)},className:`bg-bambu-dark border border-bambu-dark-tertiary rounded px-2 py-1.5 text-sm text-white focus:outline-none focus:border-bambu-green`,children:[(0,G.jsx)(`option`,{value:`name`,children:e(`common.name`)}),(0,G.jsx)(`option`,{value:`date`,children:e(`common.date`)}),(0,G.jsx)(`option`,{value:`size`,children:e(`fileManager.size`)}),(0,G.jsx)(`option`,{value:`type`,children:e(`common.type`)}),(0,G.jsx)(`option`,{value:`prints`,children:e(`fileManager.prints`)})]}),(0,G.jsx)(`button`,{onClick:()=>Me(e=>{let t=e===`asc`?`desc`:`asc`;return localStorage.setItem(`library-sort-direction`,t),t}),className:`p-1.5 rounded bg-bambu-dark border border-bambu-dark-tertiary hover:border-bambu-green transition-colors`,title:e(je===`asc`?`fileManager.ascending`:`fileManager.descending`),children:je===`asc`?(0,G.jsx)(Bo,{className:`w-4 h-4 text-white`}):(0,G.jsx)(Po,{className:`w-4 h-4 text-white`})}),(0,G.jsx)(`button`,{onClick:()=>Pe(e=>{let t=!e;return localStorage.setItem(`library-show-modified`,String(t)),t}),className:`p-1.5 rounded bg-bambu-dark border transition-colors ${Ne?`border-bambu-green text-bambu-green`:`border-bambu-dark-tertiary text-white hover:border-bambu-green`}`,title:e(Ne?`fileManager.hideModified`:`fileManager.showModified`),"aria-pressed":Ne,children:(0,G.jsx)(ts,{className:`w-4 h-4`})})]}),(Ce||Te!==`all`||De)&&(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray hidden sm:inline`,children:e(`fileManager.resultsCount`,{showing:et.length,total:Ye.length})})]}),et.length>0&&(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 mb-4 p-2 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary sticky top-[52px] z-10 lg:static`,children:[m.length===et.length&&m.length>0?(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:xt,children:[(0,G.jsx)(_u,{className:`w-4 h-4 sm:mr-1`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`fileManager.deselectAll`)})]}):(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:bt,children:[(0,G.jsx)(hu,{className:`w-4 h-4 sm:mr-1`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`fileManager.selectAll`)})]}),m.length>0&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray ml-2`,children:e(`fileManager.selected`,{count:m.length})}),(0,G.jsx)(`div`,{className:`hidden sm:block flex-1`}),(0,G.jsxs)(`div`,{className:`w-full sm:w-auto flex flex-wrap items-center gap-2 mt-2 sm:mt-0`,children:[gt.length>=1&&(0,G.jsxs)(Q,{variant:`primary`,size:`sm`,onClick:()=>B(gt[0]),disabled:!r(`queue:create`),title:r(`queue:create`)?void 0:e(`fileManager.noPermissionAddToQueue`),children:[(0,G.jsx)(Fl,{className:`w-4 h-4 sm:mr-1`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:gt.length>1?e(`fileManager.variants.printAlternatives`,{count:gt.length}):e(`common.print`)})]}),gt.length>=2&&!gt.some(e=>e.variant_group_id)&&(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:()=>st.mutate(gt.map(e=>e.id)),disabled:st.isPending||!i(`library:update_own`,`library:update_all`),title:e(`fileManager.variants.groupTooltip`),children:[(0,G.jsx)(Gc,{className:`w-4 h-4 sm:mr-1`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`fileManager.variants.groupAction`)})]}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:()=>S(!0),disabled:!i(`library:update_own`,`library:update_all`),title:i(`library:update_own`,`library:update_all`)?void 0:e(`fileManager.noPermissionMoveFiles`),children:[(0,G.jsx)(gl,{className:`w-4 h-4 sm:mr-1`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.move`)})]}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:()=>M(!0),disabled:!i(`library:update_own`,`library:update_all`),title:i(`library:update_own`,`library:update_all`)?e(`fileManager.tags.bulkTooltip`):e(`fileManager.tags.noPermission`),children:[(0,G.jsx)(Cu,{className:`w-4 h-4 sm:mr-1`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`fileManager.tags.tagAction`)})]}),(0,G.jsxs)(Q,{variant:`danger`,size:`sm`,onClick:()=>{m.length===1?R({type:`file`,id:m[0]}):R({type:`bulk`,id:0,count:m.length})},disabled:!i(`library:delete_own`,`library:delete_all`),title:i(`library:delete_own`,`library:delete_all`)?void 0:e(`fileManager.noPermissionDeleteFiles`),children:[(0,G.jsx)(ju,{className:`w-4 h-4 sm:mr-1`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.delete`)})]}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:xt,children:[(0,G.jsx)($u,{className:`w-4 h-4 sm:mr-1`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.clear`)})]})]})]})]}),kt?(0,G.jsx)(`div`,{className:`flex-1 flex items-center justify-center`,children:(0,G.jsxs)(`div`,{className:`flex flex-col items-center gap-3`,children:[(0,G.jsx)(Y,{className:`w-8 h-8 animate-spin text-bambu-green`}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`fileManager.loadingFiles`)})]})}):Ye?.length===0?(0,G.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center`,children:[(0,G.jsx)(`div`,{className:`p-4 bg-bambu-dark rounded-2xl mb-4`,children:(0,G.jsx)(ac,{className:`w-12 h-12 text-bambu-gray/50`})}),(0,G.jsx)(`h3`,{className:`text-lg font-medium text-white mb-2`,children:e(u===null?f===`external`?`fileManager.externalIsEmpty`:`fileManager.noFilesYet`:`fileManager.folderIsEmpty`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-center max-w-md mb-6`,children:e(u===null?f===`external`?`fileManager.externalEmptyDescription`:`fileManager.noFilesDescription`:`fileManager.folderEmptyDescription`)}),(0,G.jsxs)(Q,{onClick:()=>w(!0),disabled:!r(`library:upload`),title:r(`library:upload`)?void 0:e(`fileManager.noPermissionUpload`),children:[(0,G.jsx)(Ml,{className:`w-4 h-4 mr-2`}),e(`fileManager.uploadFiles`)]})]}):et.length===0?(0,G.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center`,children:[(0,G.jsx)(`div`,{className:`p-4 bg-bambu-dark rounded-2xl mb-4`,children:(0,G.jsx)(Yl,{className:`w-12 h-12 text-bambu-gray/50`})}),(0,G.jsx)(`h3`,{className:`text-lg font-medium text-white mb-2`,children:e(`fileManager.noMatchingFiles`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-center max-w-md mb-6`,children:e(`fileManager.noMatchingFilesDescription`)}),(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>{we(``),Ee(`all`)},children:e(`fileManager.clearFilters`)})]}):ce===`grid`?(0,G.jsx)(`div`,{className:`flex-1 lg:overflow-y-auto`,children:(0,G.jsx)(`div`,{className:`grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 2xl:grid-cols-6 gap-4`,children:et.map(t=>(0,G.jsx)(rZe,{file:t,isSelected:m.includes(t.id),isMobile:Fe,t:e,onSelect:yt,onDelete:e=>R({type:`file`,id:e}),onDownload:Tt,onPrint:B,onSlice:ee,onOpenInSlicer:Re,onRunPipeline:ne,useSlicerApi:Ie?.use_slicer_api??!1,canSlice:ze(),onPreview3d:e=>{u9(e.filename)?c(`/gcode-viewer?library_file=${e.id}`):H(e)},onRename:e=>ie({type:`file`,id:e.id,name:e.filename}),onGenerateThumbnail:e=>mt.mutate(e.id),onTagClick:Je,thumbnailVersion:ae[t.id],hasPermission:r,canModify:a,authEnabled:o,showModified:Ne},t.id))})}):(0,G.jsx)(`div`,{className:`flex-1 lg:overflow-y-auto`,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary overflow-x-auto`,children:[(0,G.jsxs)(`div`,{className:`hidden sm:grid ${o?`grid-cols-[auto_1fr_120px_100px_100px_100px_minmax(0,200px)_220px]`:`grid-cols-[auto_1fr_100px_100px_100px_minmax(0,200px)_220px]`} gap-4 px-4 py-2 bg-bambu-dark-secondary border-b border-bambu-dark-tertiary text-xs text-bambu-gray font-medium`,children:[(0,G.jsx)(`div`,{className:`w-6`}),(0,G.jsx)(`div`,{children:e(`common.name`)}),o&&(0,G.jsx)(`div`,{children:e(`fileManager.uploadedBy`,{defaultValue:`Uploaded By`})}),(0,G.jsx)(`div`,{children:e(`common.type`)}),(0,G.jsx)(`div`,{children:e(`fileManager.size`)}),(0,G.jsx)(`div`,{children:e(`fileManager.prints`)}),(0,G.jsx)(`div`,{children:e(`fileManager.tags.title`)}),(0,G.jsx)(`div`,{})]}),et.map(t=>(0,G.jsxs)(`div`,{className:`grid ${o?`grid-cols-[auto_1fr_120px_100px_100px_100px_minmax(0,200px)_220px]`:`grid-cols-[auto_1fr_100px_100px_100px_minmax(0,200px)_220px]`} gap-4 px-4 py-3 items-center border-b border-bambu-dark-tertiary last:border-b-0 cursor-pointer hover:bg-bambu-dark/50 transition-colors ${m.includes(t.id)?`bg-bambu-green/10`:``}`,onClick:()=>yt(t.id),children:[(0,G.jsx)(`div`,{className:`w-5 h-5 rounded border-2 flex items-center justify-center ${m.includes(t.id)?`bg-bambu-green border-bambu-green`:`border-bambu-gray/50`}`,children:m.includes(t.id)&&(0,G.jsx)(`div`,{className:`w-2 h-2 bg-white rounded-sm`})}),(0,G.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0`,children:[(0,G.jsxs)(`div`,{className:`relative group/thumb`,children:[(0,G.jsx)(`div`,{className:`w-10 h-10 rounded bg-bambu-dark flex-shrink-0 overflow-hidden`,children:t.thumbnail_path?(0,G.jsx)(`img`,{src:`${Z.getLibraryFileThumbnailUrl(t.id)}${ae[t.id]?(Z.getLibraryFileThumbnailUrl(t.id).includes(`?`)?`&`:`?`)+`v=${ae[t.id]}`:``}`,alt:``,className:`w-full h-full object-cover`}):(0,G.jsx)(`div`,{className:`w-full h-full flex items-center justify-center`,children:(0,G.jsx)(ac,{className:`w-5 h-5 text-bambu-gray/50`})})}),t.thumbnail_path&&(0,G.jsx)(`div`,{className:`absolute left-0 top-full mt-2 z-50 hidden group-hover/thumb:block`,children:(0,G.jsx)(`div`,{className:`w-48 h-48 rounded-lg bg-bambu-dark-secondary border border-bambu-dark-tertiary shadow-xl overflow-hidden`,children:(0,G.jsx)(`img`,{src:`${Z.getLibraryFileThumbnailUrl(t.id)}${ae[t.id]?(Z.getLibraryFileThumbnailUrl(t.id).includes(`?`)?`&`:`?`)+`v=${ae[t.id]}`:``}`,alt:t.filename,className:`w-full h-full object-contain`})})})]}),(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsx)(`div`,{className:`text-sm text-white truncate`,children:t.print_name||t.filename}),Ne&&(0,G.jsxs)(`div`,{className:`text-xs text-bambu-gray flex items-center gap-1 mt-0.5`,title:e(`fileManager.lastModified`),children:[(0,G.jsx)(ts,{className:`w-3 h-3 flex-shrink-0`}),(0,G.jsx)(`span`,{className:`truncate`,children:qf(t.fs_modified_at??t.created_at)})]})]})]}),o&&(0,G.jsx)(`div`,{className:`text-sm text-bambu-gray flex items-center gap-1`,children:t.created_by_username?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(zu,{className:`w-3 h-3`}),(0,G.jsx)(`span`,{className:`truncate`,children:t.created_by_username})]}):`-`}),(0,G.jsx)(`div`,{children:(0,G.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded font-medium ${t.file_type===`3mf`?`bg-bambu-green/20 text-bambu-green`:t.file_type===`gcode`||t.file_type===`gcode.3mf`?`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`:t.file_type===`stl`?`bg-purple-100 dark:bg-purple-500/20 text-purple-700 dark:text-purple-400`:`bg-bambu-gray/20 text-bambu-gray`}`,children:t.file_type.toUpperCase()})}),(0,G.jsx)(`div`,{className:`text-sm text-bambu-gray`,children:Rd(t.file_size)}),(0,G.jsx)(`div`,{className:`text-sm text-bambu-gray`,children:t.print_count>0?`${t.print_count}x`:`-`}),(0,G.jsx)(`div`,{className:`min-w-0`,onClick:e=>e.stopPropagation(),children:!t.tags||t.tags.length===0?(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray/50`,children:`-`}):(0,G.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:t.tags.map(e=>(0,G.jsxs)(`button`,{type:`button`,onClick:()=>Je(e.id),className:`inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded-full text-[10px] bg-bambu-green/10 text-bambu-green hover:bg-bambu-green/20 transition-colors max-w-full`,title:e.name,children:[(0,G.jsx)(Cu,{className:`w-2.5 h-2.5 flex-shrink-0`}),(0,G.jsx)(`span`,{className:`truncate`,children:e.name})]},e.id))})}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,onClick:e=>e.stopPropagation(),children:[u9(t.filename)&&(0,G.jsx)(G.Fragment,{children:(0,G.jsx)(`button`,{onClick:()=>r(`queue:create`)&&B(t),className:`p-1.5 rounded transition-colors ${r(`queue:create`)?`hover:bg-bambu-dark text-bambu-gray hover:text-bambu-green`:`text-bambu-gray/50 cursor-not-allowed`}`,title:r(`queue:create`)?e(`common.print`):e(`fileManager.noPermissionAddToQueue`),disabled:!r(`queue:create`),children:(0,G.jsx)(Fl,{className:`w-4 h-4`})})}),XW(t.filename)&&(0,G.jsx)(`button`,{onClick:()=>{ze()&&(Ie?.use_slicer_api?ee:Re)(t)},className:`p-1.5 rounded transition-colors ${ze()?`hover:bg-bambu-dark text-bambu-gray hover:text-bambu-green`:`text-bambu-gray/50 cursor-not-allowed`}`,title:ze()?e(`slice.action`):Ie?.use_slicer_api?e(`fileManager.noPermissionSlice`):e(`fileManager.noPermissionDownload`),disabled:!ze(),children:Ie?.use_slicer_api?(0,G.jsx)(Is,{className:`w-4 h-4`}):(0,G.jsx)(tc,{className:`w-4 h-4`})}),(Ie?.use_slicer_api??!1)&&XW(t.filename)&&(0,G.jsx)(`button`,{onClick:()=>r(`pipelines:run`)&&ne(t),className:`p-1.5 rounded transition-colors ${r(`pipelines:run`)?`hover:bg-bambu-dark text-bambu-gray hover:text-bambu-green`:`text-bambu-gray/50 cursor-not-allowed`}`,title:r(`pipelines:run`)?e(`library.runWithPipeline.actionLabel`,`Run with pipeline`):e(`library.runWithPipeline.noPermission`,`You do not have permission to run pipelines`),disabled:!r(`pipelines:run`),children:(0,G.jsx)(Al,{className:`w-4 h-4`})}),(t.file_type===`3mf`||t.file_type===`gcode`||t.file_type===`gcode.3mf`||t.file_type===`stl`)&&(0,G.jsx)(`button`,{onClick:()=>{r(`library:read`)&&(u9(t.filename)?c(`/gcode-viewer?library_file=${t.id}`):H(t))},className:`p-1.5 rounded transition-colors ${r(`library:read`)?`hover:bg-bambu-dark text-bambu-gray hover:text-bambu-green`:`text-bambu-gray/50 cursor-not-allowed`}`,title:r(`library:read`)?`3D Preview`:`You do not have permission to preview files`,disabled:!r(`library:read`),children:(0,G.jsx)(Yo,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:()=>r(`library:read`)&&Tt(t.id),className:`p-1.5 rounded transition-colors ${r(`library:read`)?`hover:bg-bambu-dark text-bambu-gray hover:text-white`:`text-bambu-gray/50 cursor-not-allowed`}`,title:r(`library:read`)?e(`common.download`):e(`fileManager.noPermissionDownload`),disabled:!r(`library:read`),children:(0,G.jsx)(Js,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:()=>a(`library`,`update`,t.created_by_id)&&ie({type:`file`,id:t.id,name:t.filename}),className:`p-1.5 rounded transition-colors ${a(`library`,`update`,t.created_by_id)?`hover:bg-bambu-dark text-bambu-gray hover:text-white`:`text-bambu-gray/50 cursor-not-allowed`}`,title:a(`library`,`update`,t.created_by_id)?e(`common.rename`):e(`fileManager.noPermissionRenameFile`),disabled:!a(`library`,`update`,t.created_by_id),children:(0,G.jsx)(Ol,{className:`w-4 h-4`})}),t.file_type===`stl`&&(0,G.jsx)(`button`,{onClick:()=>a(`library`,`update`,t.created_by_id)&&mt.mutate(t.id),className:`p-1.5 rounded transition-colors ${a(`library`,`update`,t.created_by_id)?`hover:bg-bambu-dark text-bambu-gray hover:text-bambu-green`:`text-bambu-gray/50 cursor-not-allowed`}`,title:a(`library`,`update`,t.created_by_id)?e(`fileManager.generateThumbnail`):e(`fileManager.noPermissionGenerateThumbnail`),disabled:mt.isPending||!a(`library`,`update`,t.created_by_id),children:(0,G.jsx)(zc,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:()=>a(`library`,`delete`,t.created_by_id)&&R({type:`file`,id:t.id}),className:`p-1.5 rounded transition-colors ${a(`library`,`delete`,t.created_by_id)?`hover:bg-bambu-dark text-bambu-gray hover:text-red-700 dark:hover:text-red-400`:`text-bambu-gray/50 cursor-not-allowed`}`,title:a(`library`,`delete`,t.created_by_id)?e(`common.delete`):e(`fileManager.noPermissionDeleteFile`),disabled:!a(`library`,`delete`,t.created_by_id),children:(0,G.jsx)(ju,{className:`w-4 h-4`})})]})]},t.id))]})})]}),u!==null&&(0,G.jsx)(GXe,{folderId:u})]})]}),g&&(0,G.jsx)(YXe,{parentId:u,onClose:()=>_(!1),onSave:e=>nt.mutate(e),isLoading:nt.isPending,t:e}),v&&(0,G.jsx)(XXe,{onClose:()=>b(!1),onSave:e=>rt.mutate(e),isLoading:rt.isPending,t:e}),x&&Be&&(0,G.jsx)(eZe,{folders:Be,selectedFiles:m,currentFolderId:u,onClose:()=>S(!1),onMove:e=>lt.mutate({fileIds:m,folderId:e}),isLoading:lt.isPending,t:e}),C&&(0,G.jsx)(FU,{folderId:u,onClose:()=>{w(!1),E([])},onUploadComplete:St,initialFiles:T.length>0?T:void 0}),D&&(0,G.jsx)(JXe,{onClose:()=>O(!1)}),(0,G.jsx)(KXe,{open:k,onClose:()=>A(!1),onPickTag:e=>{N.includes(e)||P(t=>[...t,e])}}),(0,G.jsx)(LUe,{open:j,fileIds:m,onClose:()=>M(!1)}),F&&(0,G.jsx)(tZe,{folder:F,onClose:()=>I(null),onLink:e=>ut.mutate({id:F.id,data:e}),isLoading:ut.isPending,t:e}),L&&(0,G.jsx)(Zd,{title:L.type===`folder`?e(`fileManager.deleteFolder`):L.type===`bulk`?e(`fileManager.deleteFilesCount`,{count:L.count}):e(`fileManager.deleteFile`),message:L.type===`folder`?e(`fileManager.deleteFolderConfirm`):L.type===`bulk`?e(`fileManager.deleteFilesConfirm`,{count:L.count}):e(`fileManager.deleteFileConfirm`),confirmText:e(`common.delete`),variant:`danger`,isLoading:Dt,loadingText:e(`fileManager.deleting`),onConfirm:Et,onCancel:()=>R(null)}),z&&(!z.variant_group_id||_t!==void 0)&&(0,G.jsx)($U,{mode:`create`,libraryFileId:vt?.[0]?.id??z.id,variantFiles:vt,archiveName:vt&&vt.length>1?`${vt[0].filename} ${e(`common.plusNMore`,{count:vt.length-1})}`:z.print_name||z.filename,onClose:()=>B(null),onSuccess:()=>{B(null),h([]),t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`queue`]}),t.invalidateQueries({queryKey:[`archives`]})}}),V&&(0,G.jsx)(WW,{source:{kind:`libraryFile`,id:V.id,filename:V.filename},onClose:()=>ee(null)}),te&&(0,G.jsx)(qW,{source:{kind:`libraryFile`,id:te.id,filename:te.filename},onClose:()=>ne(null)}),se&&(0,G.jsx)(IUe,{libraryFileId:se.id,title:se.print_name||se.filename,fileType:se.file_type,onClose:()=>H(null),onSliceWithBambuddy:XW(se.filename)&&r(`library:upload`)?()=>{let e=se;H(null),ee(e)}:void 0}),re&&(0,G.jsx)($Xe,{type:re.type,currentName:re.name,onClose:()=>ie(null),onSave:e=>{re.type===`file`?dt.mutate({id:re.id,filename:e}):ft.mutate({id:re.id,name:e})},isLoading:dt.isPending||ft.isPending,t:e})]})}function aZe(e){let t=Kf(e);if(!t)return``;let n=Math.ceil((t.getTime()-Date.now())/(1e3*60*60*24));return n<=0?`any moment`:n===1?`1 day`:`${n} days`}function oZe(e){let t=Kf(e);return t?t.toLocaleString():e}function sZe(){let{t:e}=U(),t=or(),n=so(),{showToast:r}=Bd(),{hasPermission:i,authEnabled:a}=Ed(),[o,s]=(0,y.useState)(null),[c,l]=(0,y.useState)(new Set),u=!a||i(`library:purge`),d=K({queryKey:[`library-trash`],queryFn:()=>Z.listLibraryTrash(200,0)}),f=K({queryKey:[`library-trash-settings`],queryFn:()=>Z.getLibraryTrashSettings(),enabled:u}),[p,m]=(0,y.useState)(null);(0,y.useEffect)(()=>{f.data&&p===null&&m(f.data.retention_days)},[f.data,p]);let h=q({mutationFn:e=>{let t=f.data;return Z.updateLibraryTrashSettings({retention_days:e,auto_purge_enabled:t?.auto_purge_enabled??!1,auto_purge_days:t?.auto_purge_days??90,auto_purge_include_never_printed:t?.auto_purge_include_never_printed??!0})},onSuccess:t=>{r(e(`libraryTrash.toast.retentionSaved`,{days:t.retention_days}),`success`),n.invalidateQueries({queryKey:[`library-trash-settings`]}),n.invalidateQueries({queryKey:[`library-trash`]})},onError:t=>r(t.message||e(`libraryTrash.toast.retentionFailed`),`error`)}),g=q({mutationFn:e=>Z.restoreLibraryTrash(e),onSuccess:()=>{r(e(`libraryTrash.toast.restored`),`success`),n.invalidateQueries({queryKey:[`library-trash`]}),n.invalidateQueries({queryKey:[`library-trash-count`]}),n.invalidateQueries({queryKey:[`library-files`]}),n.invalidateQueries({queryKey:[`library-folders`]})},onError:t=>r(t.message||e(`libraryTrash.toast.restoreFailed`),`error`)}),_=q({mutationFn:e=>Z.hardDeleteLibraryTrash(e),onSuccess:()=>{r(e(`libraryTrash.toast.purged`),`success`),n.invalidateQueries({queryKey:[`library-trash`]}),n.invalidateQueries({queryKey:[`library-trash-count`]})},onError:t=>r(t.message||e(`libraryTrash.toast.purgeFailed`),`error`)}),v=q({mutationFn:()=>Z.emptyLibraryTrash(),onSuccess:t=>{r(e(`libraryTrash.toast.emptied`,{count:t.deleted}),`success`),n.invalidateQueries({queryKey:[`library-trash`]}),n.invalidateQueries({queryKey:[`library-trash-count`]})},onError:t=>r(t.message||e(`libraryTrash.toast.emptyFailed`),`error`)}),b=q({mutationFn:e=>Promise.all(e.map(e=>Z.restoreLibraryTrash(e))),onSuccess:(t,i)=>{r(e(`libraryTrash.toast.bulkRestored`,{count:i.length}),`success`),l(new Set),n.invalidateQueries({queryKey:[`library-trash`]}),n.invalidateQueries({queryKey:[`library-trash-count`]}),n.invalidateQueries({queryKey:[`library-files`]}),n.invalidateQueries({queryKey:[`library-folders`]})},onError:t=>r(t.message||e(`libraryTrash.toast.restoreFailed`),`error`)}),x=q({mutationFn:e=>Promise.all(e.map(e=>Z.hardDeleteLibraryTrash(e))),onSuccess:(t,i)=>{r(e(`libraryTrash.toast.bulkPurged`,{count:i.length}),`success`),l(new Set),n.invalidateQueries({queryKey:[`library-trash`]}),n.invalidateQueries({queryKey:[`library-trash-count`]})},onError:t=>r(t.message||e(`libraryTrash.toast.purgeFailed`),`error`)}),S=(0,y.useMemo)(()=>d.data?.items??[],[d.data?.items]),C=d.data?.retention_days??30,w=(0,y.useMemo)(()=>S.reduce((e,t)=>e+t.file_size,0),[S]),T=S.length>0&&S.every(e=>c.has(e.id)),E=c.size>0&&!T,D=e=>{l(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})};return(0,G.jsxs)(`div`,{className:`p-6 max-w-screen-2xl mx-auto`,children:[(0,G.jsx)(`div`,{className:`flex items-center gap-3 mb-4`,children:(0,G.jsxs)(ki,{to:`/files`,className:`inline-flex items-center gap-1 text-sm text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-gray-200`,children:[(0,G.jsx)(Io,{className:`w-4 h-4`}),` `,e(`libraryTrash.backToFiles`)]})}),(0,G.jsxs)(`div`,{className:`flex items-start justify-between mb-6 gap-4 flex-wrap`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h1`,{className:`text-2xl font-bold text-gray-900 dark:text-gray-100`,children:e(`libraryTrash.title`)}),(0,G.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400 mt-1`,children:e(u?`libraryTrash.subtitleAdmin`:`libraryTrash.subtitleUser`,{days:C})})]}),S.length>0&&(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>s({type:`empty`}),className:`text-red-600 dark:text-red-400`,children:[(0,G.jsx)(ju,{className:`w-4 h-4 mr-1`}),e(`libraryTrash.emptyTrash`)]})]}),u&&f.data&&(0,G.jsxs)(`div`,{className:`mb-4 border border-gray-200 dark:border-gray-700 rounded-lg p-3 flex items-center gap-3 bg-gray-50 dark:bg-gray-800/40`,children:[(0,G.jsx)(`label`,{htmlFor:`retention-days`,className:`text-sm font-medium text-gray-700 dark:text-gray-300`,children:e(`libraryTrash.retentionLabel`)}),(0,G.jsx)(`input`,{id:`retention-days`,type:`number`,min:1,max:365,value:p??f.data.retention_days,onChange:e=>m(Math.max(1,Math.min(365,parseInt(e.target.value||`0`,10)||0))),className:`w-20 rounded border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-800 text-sm px-2 py-1 text-gray-900 dark:text-gray-100`}),(0,G.jsx)(`span`,{className:`text-sm text-gray-600 dark:text-gray-400`,children:e(`libraryTrash.days`)}),(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>p!=null&&h.mutate(p),disabled:h.isPending||p==null||p===f.data.retention_days,className:`ml-auto`,children:[(0,G.jsx)(Wl,{className:`w-4 h-4 mr-1`}),e(`common.save`)]})]}),d.isLoading?(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-gray-500 dark:text-gray-400`,children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),` `,e(`libraryTrash.loading`)]}):S.length===0?(0,G.jsx)(`div`,{className:`border border-dashed border-gray-300 dark:border-gray-700 rounded-lg p-12 text-center`,children:(0,G.jsx)(`p`,{className:`text-gray-500 dark:text-gray-400`,children:e(`libraryTrash.empty`)})}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,G.jsx)(`div`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:e(`libraryTrash.summary`,{count:S.length,size:Rd(w)})}),c.size>0&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,G.jsx)(`span`,{className:`text-gray-600 dark:text-gray-400`,children:e(`libraryTrash.selectionCount`,{count:c.size})}),(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>b.mutate(Array.from(c)),disabled:b.isPending,children:[(0,G.jsx)(Vl,{className:`w-4 h-4 mr-1`}),e(`libraryTrash.bulkRestore`)]}),(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>s({type:`bulkDelete`,count:c.size}),disabled:x.isPending,className:`text-red-600 dark:text-red-400`,children:[(0,G.jsx)(ju,{className:`w-4 h-4 mr-1`}),e(`libraryTrash.bulkPurge`)]})]})]}),(0,G.jsx)(`div`,{className:`border border-gray-200 dark:border-gray-700 rounded-lg overflow-x-auto`,children:(0,G.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,G.jsx)(`thead`,{className:`bg-gray-50 dark:bg-gray-800 text-left text-gray-600 dark:text-gray-300`,children:(0,G.jsxs)(`tr`,{children:[(0,G.jsx)(`th`,{className:`px-3 py-2 w-10`,children:(0,G.jsx)(`input`,{type:`checkbox`,checked:T,ref:e=>{e&&(e.indeterminate=E)},onChange:()=>{l(e=>e.size===S.length?new Set:new Set(S.map(e=>e.id)))},"aria-label":e(`libraryTrash.selectAll`),className:`rounded border-gray-300 cursor-pointer`})}),(0,G.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:e(`libraryTrash.col.filename`)}),(0,G.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:e(`libraryTrash.col.folder`)}),(0,G.jsx)(`th`,{className:`px-3 py-2 font-medium text-right`,children:e(`libraryTrash.col.size`)}),(0,G.jsx)(`th`,{className:`px-3 py-2 font-medium whitespace-nowrap`,children:e(`libraryTrash.col.deleted`)}),(0,G.jsx)(`th`,{className:`px-3 py-2 font-medium whitespace-nowrap`,children:e(`libraryTrash.col.autoPurge`)}),u&&(0,G.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:e(`libraryTrash.col.owner`)}),(0,G.jsx)(`th`,{className:`px-3 py-2 font-medium text-right`,children:e(`libraryTrash.col.actions`)})]})}),(0,G.jsx)(`tbody`,{className:`divide-y divide-gray-100 dark:divide-gray-800`,children:S.map(t=>(0,G.jsxs)(`tr`,{className:`hover:bg-gray-50 dark:hover:bg-gray-800/50`,children:[(0,G.jsx)(`td`,{className:`px-3 py-2`,children:(0,G.jsx)(`input`,{type:`checkbox`,checked:c.has(t.id),onChange:()=>D(t.id),"aria-label":e(`libraryTrash.selectOne`,{filename:t.filename}),className:`rounded border-gray-300 cursor-pointer`})}),(0,G.jsx)(`td`,{className:`px-3 py-2 text-gray-900 dark:text-gray-100 truncate max-w-md`,title:t.filename,children:t.filename}),(0,G.jsx)(`td`,{className:`px-3 py-2 text-gray-600 dark:text-gray-400`,children:t.folder_name??`—`}),(0,G.jsx)(`td`,{className:`px-3 py-2 text-right text-gray-600 dark:text-gray-400 tabular-nums whitespace-nowrap`,children:Rd(t.file_size)}),(0,G.jsx)(`td`,{className:`px-3 py-2 text-gray-600 dark:text-gray-400 whitespace-nowrap`,children:oZe(t.deleted_at)}),(0,G.jsx)(`td`,{className:`px-3 py-2 text-gray-600 dark:text-gray-400 whitespace-nowrap`,children:(0,G.jsx)(`span`,{title:oZe(t.auto_purge_at),children:e(`libraryTrash.autoPurgeIn`,{when:aZe(t.auto_purge_at)})})}),u&&(0,G.jsx)(`td`,{className:`px-3 py-2 text-gray-600 dark:text-gray-400`,children:t.created_by_username??`—`}),(0,G.jsxs)(`td`,{className:`px-3 py-2 text-right whitespace-nowrap`,children:[(0,G.jsxs)(`button`,{onClick:()=>g.mutate(t.id),disabled:g.isPending,className:`inline-flex items-center gap-1 px-2 py-1 text-xs text-blue-600 hover:text-blue-800 dark:text-blue-400 dark:hover:text-blue-300`,children:[(0,G.jsx)(Vl,{className:`w-3.5 h-3.5`}),e(`libraryTrash.restore`)]}),(0,G.jsxs)(`button`,{onClick:()=>s({type:`delete`,id:t.id,filename:t.filename}),disabled:_.isPending,className:`inline-flex items-center gap-1 px-2 py-1 text-xs text-red-600 hover:text-red-800 dark:text-red-400 dark:hover:text-red-300 ml-2`,children:[(0,G.jsx)(ju,{className:`w-3.5 h-3.5`}),e(`libraryTrash.purgeNow`)]})]})]},t.id))})]})})]}),o&&(0,G.jsx)(Zd,{onCancel:()=>s(null),onConfirm:()=>{o&&(o.type===`delete`?_.mutate(o.id):o.type===`bulkDelete`?x.mutate(Array.from(c)):v.mutate(),s(null))},title:o.type===`delete`?e(`libraryTrash.confirm.purgeTitle`):o.type===`bulkDelete`?e(`libraryTrash.confirm.bulkPurgeTitle`):e(`libraryTrash.confirm.emptyTitle`),message:o.type===`delete`?e(`libraryTrash.confirm.purgeBody`,{filename:o.filename}):o.type===`bulkDelete`?e(`libraryTrash.confirm.bulkPurgeBody`,{count:o.count}):e(`libraryTrash.confirm.emptyBody`,{count:S.length}),confirmText:e(`libraryTrash.confirm.cta`),variant:`danger`}),d.isError&&(0,G.jsxs)(`div`,{className:`mt-4 text-sm text-red-600 dark:text-red-400`,children:[d.error?.message??e(`libraryTrash.loadError`),(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>t(`/files`),className:`ml-3`,children:e(`libraryTrash.backToFiles`)})]})]})}function cZe(e,t){let n=`token=${encodeURIComponent(t)}`,r=0;return e.querySelectorAll(`img[src*="/api/v1/"], video[src*="/api/v1/"]`).forEach(e=>{let t=e.getAttribute(`src`)||``;if(t.includes(n))return;let i=t.replace(/([?&])token=[^&]*(&|$)/,(e,t,n)=>n===`&`?t:``);e.src=`${i}${i.includes(`?`)?`&`:`?`}${n}`,r+=1}),r}function lZe(){let{authEnabled:e,user:t,loading:n}=Ed(),r=so(),i=(0,y.useRef)(!1),{data:a}=K({queryKey:[`camera-stream-token`,t?.id??null],queryFn:()=>Z.getCameraStreamToken(),enabled:!n&&(!e||t!==null),staleTime:3e3*1e3,refetchInterval:3e3*1e3});(0,y.useEffect)(()=>{let e=a?.token??null;return ld(e),e&&cZe(document,e),()=>ld(null)},[a?.token]),(0,y.useEffect)(()=>{if(!e)return;let t=e=>{let t=e.target;if(!(t instanceof HTMLImageElement||t instanceof HTMLVideoElement))return;let n=t.src||``,a=ud();!a||!n.includes(`token=${encodeURIComponent(a)}`)||i.current||(i.current=!0,r.invalidateQueries({queryKey:[`camera-stream-token`]}),setTimeout(()=>{i.current=!1},5e3))};return document.addEventListener(`error`,t,!0),()=>document.removeEventListener(`error`,t,!0)},[e,r])}var d9=5,uZe=2e3,dZe=3e4,fZe=5e3;function pZe(){let{t:e}=U(),t=so(),{showToast:n}=Bd(),{hasPermission:r,authEnabled:i,user:a}=Ed(),{printerId:o}=dr(),s=parseInt(o||`0`,10),[c]=Li(),l=parseInt(c.get(`fps`)||`15`,10),u=Math.min(Math.max(isNaN(l)?15:l,1),30);lZe();let{data:d,isPending:f}=K({queryKey:[`camera-stream-token`,a?.id??null],queryFn:()=>Z.getCameraStreamToken(),enabled:i?!!a:!0,staleTime:3e3*1e3}),p=d?.token??ud(),[m,h]=(0,y.useState)(`stream`),[g,_]=(0,y.useState)(!1),[v,b]=(0,y.useState)(!1),[x,S]=(0,y.useState)(!1),[C,w]=(0,y.useState)(!0),[T,E]=(0,y.useState)(Date.now()),[D,O]=(0,y.useState)(!1),[k,A]=(0,y.useState)(!1),[j,M]=(0,y.useState)(0),[N,P]=(0,y.useState)(!1),[F,I]=(0,y.useState)(0),[L,R]=(0,y.useState)(1),[z,B]=(0,y.useState)({x:0,y:0}),[V,ee]=(0,y.useState)(!1),[te,ne]=(0,y.useState)({x:0,y:0}),[re,ie]=(0,y.useState)(null),[ae,oe]=(0,y.useState)(null),se=(0,y.useRef)(null),H=(0,y.useRef)(null),ce=(0,y.useRef)(null),le=(0,y.useRef)(null),ue=(0,y.useRef)(null),de=(0,y.useRef)(0),{data:fe}=K({queryKey:[`printer`,s],queryFn:()=>Z.getPrinter(s),enabled:s>0}),{data:pe}=K({queryKey:[`printerStatus`,s],queryFn:()=>Z.getPrinterStatus(s),refetchInterval:3e4,enabled:s>0}),me=q({mutationFn:e=>Z.setChamberLight(s,e),onMutate:async e=>{await t.cancelQueries({queryKey:[`printerStatus`,s]});let n=t.getQueryData([`printerStatus`,s]);return t.setQueryData([`printerStatus`,s],t=>({...t,chamber_light:e})),{previousStatus:n}},onSuccess:(e,t)=>{n(`Chamber light ${t?`on`:`off`}`)},onError:(r,i,a)=>{a?.previousStatus&&t.setQueryData([`printerStatus`,s],a.previousStatus),n(r.message||e(`printers.toast.failedToControlChamberLight`),`error`)}}),he=(pe?.state===`RUNNING`||pe?.state===`PAUSE`)&&(pe?.printable_objects_count??0)>=2;(0,y.useEffect)(()=>(fe&&(document.title=`${fe.name} - Camera`),()=>{document.title=`Bambuddy`}),[fe]);let ge=(0,y.useRef)(!1);(0,y.useEffect)(()=>{let e=`/api/v1/printers/${s}/camera/stop`;ge.current=!1;let t=()=>{if(s>0&&!ge.current){ge.current=!0;let t={},n=sd();n&&(t.Authorization=`Bearer ${n}`),fetch(e,{method:`POST`,keepalive:!0,headers:t}).catch(()=>{})}},n=()=>{t()};window.addEventListener(`beforeunload`,n);let r=se.current;return()=>{window.removeEventListener(`beforeunload`,n),r&&(r.src=``),t()}},[s]),(0,y.useEffect)(()=>{if(C&&!D){let e=setTimeout(()=>{w(!1)},m===`stream`?3e3:2e4);return()=>clearTimeout(e)}},[m,C,T,D]),(0,y.useEffect)(()=>{let e=()=>{A(!!document.fullscreenElement),R(1),B({x:0,y:0}),m===`stream`&&!D&&(se.current&&(se.current.src=``),setTimeout(()=>{w(!0),E(Date.now())},200))};return document.addEventListener(`fullscreenchange`,e),()=>document.removeEventListener(`fullscreenchange`,e)},[m,D]),(0,y.useEffect)(()=>{let e,t=()=>{clearTimeout(e),e=setTimeout(()=>{localStorage.setItem(`cameraWindowState`,JSON.stringify({width:window.outerWidth,height:window.outerHeight,left:window.screenX,top:window.screenY}))},500)};return window.addEventListener(`resize`,t),()=>{clearTimeout(e),window.removeEventListener(`resize`,t)}},[]),(0,y.useEffect)(()=>()=>{ce.current&&clearTimeout(ce.current),le.current&&clearInterval(le.current),ue.current&&clearInterval(ue.current)},[]);let _e=(0,y.useCallback)(()=>{if(j>=d9){P(!1),S(!0);return}let e=Math.min(uZe*2**j,dZe);P(!0),I(Math.ceil(e/1e3)),le.current=setInterval(()=>{I(e=>e<=1?(le.current&&clearInterval(le.current),0):e-1)},1e3),ce.current=setTimeout(()=>{M(e=>e+1),P(!1),w(!0),S(!1),se.current&&(se.current.src=``),E(Date.now())},e)},[j]);(0,y.useEffect)(()=>{if(m!==`stream`||C||N||D){ue.current&&=(clearInterval(ue.current),null);return}return de.current=0,ue.current=setInterval(async()=>{try{let e=await Z.getCameraStatus(s);if(!(e.stalled||!e.active&&!x)){de.current=0;return}if(de.current+=1,de.current<2)return;de.current=0,console.log(`Stream issue detected: stalled=${e.stalled}, active=${e.active}, reconnecting...`),ue.current&&=(clearInterval(ue.current),null),w(!1),_e()}catch{}},fZe),()=>{ue.current&&=(clearInterval(ue.current),null)}},[m,C,x,N,D,s,_e]);let ve=()=>{w(!1),m===`stream`&&j{if(w(!1),S(!1),M(0),de.current=0,P(!1),ce.current&&clearTimeout(ce.current),le.current&&clearInterval(le.current),se.current&&!localStorage.getItem(`cameraWindowState`)){let e=se.current,t=e.naturalWidth,n=e.naturalHeight;if(t>0&&n>0){let e=window.outerWidth-window.innerWidth,r=window.outerHeight-window.innerHeight,i=t+16+e,a=n+45+16+r;try{window.resizeTo(i,a)}catch{}}}},be=()=>{if(s>0){let e={},t=sd();t&&(e.Authorization=`Bearer ${t}`),fetch(`/api/v1/printers/${s}/camera/stop`,{method:`POST`,headers:e}).catch(()=>{})}},xe=e=>{m===e||D||(O(!0),w(!0),S(!1),M(0),P(!1),R(1),B({x:0,y:0}),ce.current&&clearTimeout(ce.current),le.current&&clearInterval(le.current),se.current&&(se.current.src=``),m===`stream`&&be(),setTimeout(()=>{h(e),E(Date.now()),O(!1)},100))},Se=()=>{D||(O(!0),w(!0),S(!1),M(0),P(!1),ce.current&&clearTimeout(ce.current),le.current&&clearInterval(le.current),se.current&&(se.current.src=``),m===`stream`&&be(),setTimeout(()=>{E(Date.now()),O(!1)},100))},Ce=()=>{H.current&&(document.fullscreenElement?document.exitFullscreen():H.current.requestFullscreen())},we=()=>{R(e=>Math.min(e+.5,4))},Te=()=>{R(e=>{let t=Math.max(e-.5,1);return t===1&&B({x:0,y:0}),t})},Ee=e=>{e.preventDefault(),e.deltaY<0?we():Te()},De=e=>{L>1&&(e.preventDefault(),ee(!0),ne({x:e.clientX-z.x,y:e.clientY-z.y}))},Oe=(0,y.useCallback)(()=>{if(!H.current)return{x:300,y:200};let e=H.current.getBoundingClientRect(),t=e.width*(L-1)/2,n=e.height*(L-1)/2;return{x:Math.max(50,t),y:Math.max(50,n)}},[L]),ke=e=>{if(V&&L>1){let t=e.clientX-te.x,n=e.clientY-te.y,r=Oe();B({x:Math.max(-r.x,Math.min(r.x,t)),y:Math.max(-r.y,Math.min(r.y,n))})}},Ae=()=>{ee(!1)},je=e=>{if(e.length<2)return 0;let t=e[0].clientX-e[1].clientX,n=e[0].clientY-e[1].clientY;return Math.sqrt(t*t+n*n)},Me=e=>e.length<2?{x:e[0].clientX,y:e[0].clientY}:{x:(e[0].clientX+e[1].clientX)/2,y:(e[0].clientY+e[1].clientY)/2},Ne=e=>{e.touches.length===2?(e.preventDefault(),ie(je(e.touches)),oe(Me(e.touches))):e.touches.length===1&&L>1&&(e.preventDefault(),ee(!0),ne({x:e.touches[0].clientX-z.x,y:e.touches[0].clientY-z.y}))},Pe=e=>{if(e.touches.length===2&&re!==null){e.preventDefault();let t=je(e.touches),n=t/re;R(e=>{let t=Math.max(1,Math.min(4,e*n));return t===1&&B({x:0,y:0}),t}),ie(t);let r=Me(e.touches);if(ae){let e=Oe();B(t=>({x:Math.max(-e.x,Math.min(e.x,t.x+(r.x-ae.x))),y:Math.max(-e.y,Math.min(e.y,t.y+(r.y-ae.y)))}))}oe(r)}else if(e.touches.length===1&&V&&L>1){e.preventDefault();let t=e.touches[0].clientX-te.x,n=e.touches[0].clientY-te.y,r=Oe();B({x:Math.max(-r.x,Math.min(r.x,t)),y:Math.max(-r.y,Math.min(r.y,n))})}},Fe=e=>{e.touches.length<2&&(ie(null),oe(null)),e.touches.length===0&&ee(!1)},Ie=()=>{R(1),B({x:0,y:0})},Le=D||!p&&(i||f)?``:(e=>p?`${e}&token=${encodeURIComponent(p)}`:dd(e))(m===`stream`?`/api/v1/printers/${s}/camera/stream?fps=${u}&t=${T}`:`/api/v1/printers/${s}/camera/snapshot?t=${T}`),Re=C||D||N;return s?(0,G.jsxs)(`div`,{ref:H,className:`min-h-screen bg-black flex flex-col`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2 bg-bambu-dark-secondary border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`h1`,{className:`text-sm font-medium text-white flex items-center gap-2`,children:[(0,G.jsx)(is,{className:`w-4 h-4`}),fe?.name||`Printer ${s}`]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`div`,{className:`flex bg-bambu-dark rounded p-0.5`,children:[(0,G.jsx)(`button`,{onClick:()=>xe(`stream`),disabled:Re,className:`px-3 py-1 text-xs rounded transition-colors ${m===`stream`?`bg-bambu-green text-white`:`text-bambu-gray hover:text-white disabled:opacity-50`}`,children:e(`camera.live`)}),(0,G.jsx)(`button`,{onClick:()=>xe(`snapshot`),disabled:Re,className:`px-3 py-1 text-xs rounded transition-colors ${m===`snapshot`?`bg-bambu-green text-white`:`text-bambu-gray hover:text-white disabled:opacity-50`}`,children:e(`camera.snapshot`)})]}),(0,G.jsx)(`button`,{onClick:()=>me.mutate(!pe?.chamber_light),disabled:!pe?.connected||me.isPending||!r(`printers:control`),className:`p-1.5 rounded disabled:opacity-50 ${pe?.chamber_light?`bg-yellow-500/20 hover:bg-yellow-500/30`:`hover:bg-bambu-dark-tertiary`}`,title:r(`printers:control`)?e(`camera.chamberLight`):e(`printers.permission.noControl`),children:(0,G.jsx)(uT,{on:pe?.chamber_light??!1,className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:()=>_(!0),disabled:!he||!r(`printers:control`),className:`p-1.5 rounded disabled:opacity-50 ${he&&r(`printers:control`)?`hover:bg-bambu-dark-tertiary`:``}`,title:r(`printers:control`)?e(he?`printers.skipObjects.tooltip`:`printers.skipObjects.onlyWhilePrinting`):e(`printers.permission.noControl`),children:(0,G.jsx)(dT,{className:`w-4 h-4 text-bambu-gray`})}),(0,G.jsx)(`button`,{onClick:Se,disabled:Re,className:`p-1.5 hover:bg-bambu-dark-tertiary rounded disabled:opacity-50`,title:e(m===`stream`?`camera.restartStream`:`camera.refreshSnapshot`),children:(0,G.jsx)(zl,{className:`w-4 h-4 text-bambu-gray ${Re?`animate-spin`:``}`})}),(0,G.jsx)(`button`,{onClick:()=>b(!0),className:`p-1.5 hover:bg-bambu-dark-tertiary rounded`,title:e(`camera.diagnose.button`),children:(0,G.jsx)(yu,{className:`w-4 h-4 text-bambu-gray`})}),(0,G.jsx)(`button`,{onClick:Ce,className:`p-1.5 hover:bg-bambu-dark-tertiary rounded`,title:e(k?`camera.exitFullscreen`:`camera.fullscreen`),children:k?(0,G.jsx)(dl,{className:`w-4 h-4 text-bambu-gray`}):(0,G.jsx)(sl,{className:`w-4 h-4 text-bambu-gray`})})]})]}),(0,G.jsx)(`div`,{className:`flex-1 flex items-center justify-center p-2 overflow-hidden`,onWheel:Ee,onMouseMove:ke,onMouseUp:Ae,onMouseLeave:Ae,onTouchStart:Ne,onTouchMove:Pe,onTouchEnd:Fe,style:{touchAction:`none`},children:(0,G.jsxs)(`div`,{className:`relative w-full h-full flex items-center justify-center`,children:[(C||D)&&!N&&(0,G.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-black/50 z-10`,children:(0,G.jsxs)(`div`,{className:`text-center`,children:[(0,G.jsx)(zl,{className:`w-8 h-8 text-bambu-gray animate-spin mx-auto mb-2`}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(m===`stream`?`camera.connectingToCamera`:`camera.capturingSnapshot`)})]})}),N&&(0,G.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-black/80 z-10`,children:(0,G.jsxs)(`div`,{className:`text-center p-4`,children:[(0,G.jsx)(Ju,{className:`w-10 h-10 text-orange-400 mx-auto mb-3`}),(0,G.jsx)(`p`,{className:`text-white mb-2`,children:e(`camera.connectionLost`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mb-3`,children:e(`camera.reconnecting`,{countdown:F,attempt:Math.min(j+1,d9),max:d9})}),(0,G.jsx)(`button`,{onClick:Se,className:`px-4 py-2 bg-bambu-green text-white text-sm rounded hover:bg-bambu-green/80 transition-colors`,children:e(`camera.reconnectNow`)})]})}),x&&!N&&(0,G.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-black z-10`,children:(0,G.jsxs)(`div`,{className:`text-center p-4`,children:[(0,G.jsx)(Pu,{className:`w-12 h-12 text-orange-400 mx-auto mb-3`}),(0,G.jsx)(`p`,{className:`text-white mb-2`,children:e(`camera.cameraUnavailable`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mb-4 max-w-md`,children:e(`camera.cameraUnavailableDesc`)}),(0,G.jsxs)(`div`,{className:`flex gap-2 justify-center`,children:[(0,G.jsx)(`button`,{onClick:Se,className:`px-4 py-2 bg-bambu-green text-white rounded hover:bg-bambu-green/80 transition-colors`,children:e(`camera.retry`)}),(0,G.jsx)(`button`,{onClick:()=>b(!0),className:`px-4 py-2 bg-bambu-dark border border-bambu-dark-tertiary text-bambu-gray hover:text-white rounded transition-colors`,children:e(`camera.diagnose.button`)})]})]})}),(0,G.jsx)(`img`,{ref:se,src:Le,alt:e(`camera.cameraStream`),className:`max-w-full max-h-full object-contain select-none`,style:{transform:`scale(${L}) translate(${z.x/L}px, ${z.y/L}px) rotate(${fe?.camera_rotation||0}deg)`,...fe?.camera_rotation===90||fe?.camera_rotation===270?{maxWidth:`100vh`,maxHeight:`100vw`}:{},cursor:L>1?V?`grabbing`:`grab`:`default`},onError:Le?ve:void 0,onLoad:Le?ye:void 0,onMouseDown:De,draggable:!1},T),(0,G.jsxs)(`div`,{className:`absolute bottom-4 left-4 flex items-center gap-1.5 bg-black/60 rounded-lg px-2 py-1.5`,children:[(0,G.jsx)(`button`,{onClick:Te,disabled:L<=1,className:`p-1.5 hover:bg-white/10 rounded disabled:opacity-30`,title:e(`camera.zoomOut`),children:(0,G.jsx)(nd,{className:`w-4 h-4 text-white`})}),(0,G.jsxs)(`button`,{onClick:Ie,className:`px-2 py-1 text-sm text-white hover:bg-white/10 rounded min-w-[48px]`,title:e(`camera.resetZoom`),children:[Math.round(L*100),`%`]}),(0,G.jsx)(`button`,{onClick:we,disabled:L>=4,className:`p-1.5 hover:bg-white/10 rounded disabled:opacity-30`,title:e(`camera.zoomIn`),children:(0,G.jsx)(ed,{className:`w-4 h-4 text-white`})})]})]})}),(0,G.jsx)(fT,{printerId:s,isOpen:g,onClose:()=>_(!1)}),v&&(0,G.jsx)(pT,{printerId:s,printerName:fe?.name||null,onClose:()=>b(!1)})]}):(0,G.jsx)(`div`,{className:`min-h-screen bg-black flex items-center justify-center`,children:(0,G.jsx)(`p`,{className:`text-white`,children:e(`camera.invalidPrinterId`)})})}var mZe=5e3,hZe=4,gZe=8,_Ze=1,vZe=16,yZe=2,bZe=60;function xZe(e,t,n,r){let i=parseInt(e??``,10);return Number.isFinite(i)?Math.min(r,Math.max(n,i)):t}function SZe(e,t,n,r,i,a){return e.has(t)?xZe(e.get(t),r,i,a):xZe(localStorage.getItem(n),r,i,a)}function CZe(){let{t:e}=U(),t=rr(),{authEnabled:n,loading:r,user:i}=Ed(),[a]=Li(),o=a.get(`token`),s=o!=null&&o!==``,[c,l]=(0,y.useState)(()=>SZe(a,`maxLive`,`camWallMaxLive`,hZe,_Ze,vZe)),[u,d]=(0,y.useState)(()=>SZe(a,`interval`,`camWallSnapshotSec`,gZe,yZe,bZe)),[f,p]=(0,y.useState)(()=>{let e=a.get(`status`)??localStorage.getItem(`camWallStatusMode`);return(s?[`off`,`compact`]:[`off`,`compact`,`full`]).includes(e)?e:`compact`});(0,y.useEffect)(()=>{if(s)return ld(o),()=>ld(null)},[s,o]);let m=K({queryKey:[`camwall-printers`,o],queryFn:()=>Z.getCamWallPrinters(o??void 0),enabled:s,refetchInterval:mZe}),h=K({queryKey:[`printers`],queryFn:()=>Z.getPrinters(),enabled:!s&&!r&&(!n||i!==null),refetchInterval:mZe}),g=(0,y.useMemo)(()=>{let e=new Map;for(let t of m.data??[])e.set(t.id,{connected:t.connected,state:t.state,progress:t.progress,remaining_time:t.remaining_time,layer_num:t.layer_num,total_layers:t.total_layers,hms_errors:t.hms_errors});return e},[m.data]);if(!s&&r)return(0,G.jsx)(`div`,{className:`flex min-h-screen items-center justify-center bg-bambu-dark text-bambu-gray`,children:e(`common.loading`)});if(!s&&n&&!i)return(0,G.jsx)(Fr,{to:`/login`,replace:!0,state:{from:t}});let _=s?m:h,v=s?m.data??[]:h.data??[];return _.isError?(0,G.jsx)(`div`,{className:`flex min-h-screen items-center justify-center bg-bambu-dark p-6 text-center`,children:(0,G.jsx)(`p`,{className:`max-w-md text-sm text-red-400`,children:e(s?`printers.camWall.page.tokenRejected`:`printers.camWall.page.loadFailed`)})}):(0,G.jsx)(`div`,{className:`min-h-screen bg-bambu-dark p-4`,children:(0,G.jsx)(bT,{printers:v,maxLive:c,snapshotIntervalSec:u,statusMode:f,statuses:s?g:void 0,showSettings:!s,onTileClick:s?void 0:e=>window.open(`/camera/${e}`,`camera-${e}`),onChangeMaxLive:e=>{l(e),localStorage.setItem(`camWallMaxLive`,String(e))},onChangeSnapshotIntervalSec:e=>{d(e),localStorage.setItem(`camWallSnapshotSec`,String(e))},onChangeStatusMode:e=>{p(e),localStorage.setItem(`camWallStatusMode`,e)}})})}function wZe(e,t,n){if(!e)return``;if(!t)return e;let r=t.match(/plate_(\d+)\.gcode/);return r&&parseInt(r[1],10)>1?`${e} — ${n(`printers.plateNumber`,`Plate {{number}}`,{number:r[1]})}`:e}function TZe(e){let t=e.get(`show`)?.split(`,`)||[`progress`,`layers`,`eta`,`filename`,`status`],n=parseInt(e.get(`fps`)||`15`,10),r=Math.min(Math.max(isNaN(n)?15:n,1),30),i=e.get(`camera`),a=i!==`false`&&i!==`0`;return{size:e.get(`size`)||`medium`,fps:r,showCamera:a,showProgress:t.includes(`progress`),showLayers:t.includes(`layers`),showEta:t.includes(`eta`),showFilename:t.includes(`filename`),showStatus:t.includes(`status`),showPrinter:t.includes(`printer`),showNozzle:t.includes(`nozzle`),showBed:t.includes(`bed`),showChamber:t.includes(`chamber`)}}function EZe(e,t){if(e.stg_cur_name)return e.stg_cur_name;switch(e.state){case`RUNNING`:return t(`streamOverlay.status.printing`);case`PAUSE`:return t(`streamOverlay.status.paused`);case`FINISH`:return t(`streamOverlay.status.finished`);case`FAILED`:return t(`streamOverlay.status.failed`);case`IDLE`:return t(`streamOverlay.status.idle`);default:return e.state||t(`streamOverlay.status.unknown`)}}function f9(e,t){let n=e[t];return typeof n==`number`?n:null}function DZe({icon:e,label:t,current:n,target:r,sizes:i}){let a=r!=null&&r>0&&Math.round(r)!==Math.round(n);return(0,G.jsxs)(`div`,{className:`flex items-center ${i.gap} text-white/70`,children:[e,(0,G.jsxs)(`span`,{className:i.text,children:[(0,G.jsx)(`span`,{className:`mr-1`,children:t}),(0,G.jsxs)(`span`,{className:`text-white`,children:[Math.round(n),`°C`]}),a&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`span`,{className:`mx-1`,children:`/`}),(0,G.jsxs)(`span`,{children:[Math.round(r),`°C`]})]})]})]})}function OZe(e){switch(e){case`small`:return{container:`p-3`,text:`text-sm`,textLarge:`text-lg`,progressHeight:`h-2`,icon:`w-3 h-3`,gap:`gap-2`,logoHeight:`h-12`};case`large`:return{container:`p-6`,text:`text-xl`,textLarge:`text-3xl`,progressHeight:`h-4`,icon:`w-6 h-6`,gap:`gap-4`,logoHeight:`h-24`};default:return{container:`p-4`,text:`text-base`,textLarge:`text-xl`,progressHeight:`h-3`,icon:`w-4 h-4`,gap:`gap-3`,logoHeight:`h-16`}}}function kZe(){let{printerId:e}=dr(),[t]=Li(),{t:n}=U(),r=so(),i=parseInt(e||`0`,10),[a,o]=(0,y.useState)(Date.now()),s=(0,y.useMemo)(()=>TZe(t),[t]),c=OZe(s.size),l=t.get(`token`),u=l!=null&&l!==``,{data:d}=K({queryKey:[`overlayStatus`,i,l],queryFn:()=>Z.getOverlayStatus(i,l??void 0),enabled:i>0&&u,refetchInterval:2e3}),{data:f}=K({queryKey:[`printer`,i],queryFn:()=>Z.getPrinter(i),enabled:i>0&&!u}),{data:p}=K({queryKey:[`printerStatus`,i],queryFn:()=>Z.getPrinterStatus(i),enabled:i>0&&!u,refetchInterval:2e3}),{data:m}=K({queryKey:[`settings`],queryFn:Z.getSettings,enabled:!u}),h=(0,y.useMemo)(()=>u?d&&{name:d.name,camera_rotation:d.camera_rotation}:f,[u,d,f]),g=u?d:p,_=(u?d?.time_format:m?.time_format)||`system`;(0,y.useEffect)(()=>{if(!i||u)return;let e=null,t=!1;return(async()=>{let n;try{n=(await Z.getWebSocketToken()).token}catch(e){let t=e instanceof id?e.status:0;if(t===401||t===403)return}if(t)return;let a=window.location.protocol===`https:`?`wss:`:`ws:`,o=n?`?token=${encodeURIComponent(n)}`:``,s=`${a}//${window.location.host}/api/v1/ws${o}`;e=new WebSocket(s),e.onmessage=e=>{try{let t=JSON.parse(e.data);t.type===`printer_status`&&t.printer_id===i&&r.setQueryData([`printerStatus`,i],t.status)}catch{}},e.onerror=()=>{}})(),()=>{t=!0,e&&e.close()}},[i,u,r]),(0,y.useEffect)(()=>(document.title=h?`${h.name} - ${n(`streamOverlay.title`)}`:n(`streamOverlay.title`),()=>{document.title=`Bambuddy`}),[h,n]);let v=()=>{setTimeout(()=>{o(Date.now())},3e3)};if(!i)return(0,G.jsx)(`div`,{className:`min-h-screen bg-black flex items-center justify-center`,children:(0,G.jsx)(`p`,{className:`text-white`,children:n(`streamOverlay.invalidPrinterId`)})});if(!g)return(0,G.jsx)(`div`,{className:`min-h-screen bg-black flex items-center justify-center`,children:(0,G.jsx)(`p`,{className:`text-gray-400`,children:n(`common.loading`)})});let b=g.state===`RUNNING`||g.state===`PAUSE`,x=g.progress||0,S=g.temperatures??{},C=[];if(s.showNozzle){let e=f9(S,`nozzle`),t=f9(S,`nozzle_2`);e!=null&&C.push({key:`nozzle`,icon:(0,G.jsx)(fc,{className:c.icon}),label:n(`printers.heaterHistory.nozzle`,`Nozzle`),current:e,target:f9(S,`nozzle_target`)}),t!=null&&C.push({key:`nozzle_2`,icon:(0,G.jsx)(fc,{className:c.icon}),label:n(`printers.heaterHistory.nozzle2`,`Nozzle 2`),current:t,target:f9(S,`nozzle_2_target`)})}if(s.showBed){let e=f9(S,`bed`);e!=null&&C.push({key:`bed`,icon:(0,G.jsx)(_u,{className:c.icon}),label:n(`printers.heaterHistory.bed`,`Bed`),current:e,target:f9(S,`bed_target`)})}if(s.showChamber){let e=f9(S,`chamber`);e!=null&&C.push({key:`chamber`,icon:(0,G.jsx)(Yo,{className:c.icon}),label:n(`printers.heaterHistory.chamber`,`Chamber`),current:e,target:f9(S,`chamber_target`)})}let w=`/api/v1/printers/${i}/camera/stream?fps=${s.fps}&t=${a}`,T=u&&l?`${w}&token=${encodeURIComponent(l)}`:dd(w);return(0,G.jsxs)(`div`,{className:`min-h-screen bg-black relative overflow-hidden`,children:[s.showCamera&&(0,G.jsx)(`img`,{src:T,alt:n(`streamOverlay.cameraStream`),className:`absolute inset-0 w-full h-full object-contain`,style:h?.camera_rotation?{transform:`rotate(${h.camera_rotation}deg)`}:void 0,onError:v},a),(0,G.jsx)(`a`,{href:`https://github.com/maziggy/bambuddy`,target:`_blank`,rel:`noopener noreferrer`,className:`absolute top-4 right-4 z-10`,children:(0,G.jsx)(`img`,{src:`/img/bambuddy_logo_dark_transparent.png`,alt:`Bambuddy`,className:`${c.logoHeight} object-contain drop-shadow-lg hover:scale-105 transition-transform`})}),(0,G.jsx)(`div`,{className:`absolute bottom-0 left-0 right-0 z-10 bg-gradient-to-t from-black/80 via-black/60 to-transparent`,children:(0,G.jsxs)(`div`,{className:`${c.container}`,children:[s.showPrinter&&h&&(0,G.jsxs)(`div`,{className:`flex items-center ${c.gap} mb-2`,children:[(0,G.jsx)(Fl,{className:`${c.icon} text-white/70`}),(0,G.jsx)(`span`,{className:`${c.text} text-white font-medium`,children:h.name})]}),s.showFilename&&g.current_print&&(0,G.jsx)(`div`,{className:`${c.textLarge} text-white font-semibold mb-2 truncate drop-shadow-md`,children:wZe(g.current_print.replace(/\.gcode\.3mf$|\.3mf$|\.gcode$/i,``),g.gcode_file,n)}),s.showStatus&&(0,G.jsx)(`div`,{className:`${c.text} text-white/70 mb-2`,children:EZe(g,n)}),s.showProgress&&b&&(0,G.jsxs)(`div`,{className:`mb-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-1 ${c.text}`,children:[(0,G.jsx)(`span`,{className:`text-white/70`,children:n(`streamOverlay.progress`)}),(0,G.jsxs)(`span`,{className:`text-white font-bold`,children:[Math.round(x),`%`]})]}),(0,G.jsx)(`div`,{className:`w-full bg-white/20 rounded-full ${c.progressHeight}`,children:(0,G.jsx)(`div`,{className:`bg-bambu-green ${c.progressHeight} rounded-full transition-all duration-500`,style:{width:`${x}%`}})})]}),b&&(s.showLayers||s.showEta)&&(0,G.jsxs)(`div`,{className:`flex items-center ${c.gap} flex-wrap`,children:[s.showLayers&&g.layer_num!=null&&g.total_layers!=null&&g.total_layers>0&&(0,G.jsxs)(`div`,{className:`flex items-center ${c.gap} text-white/70`,children:[(0,G.jsx)(Gc,{className:c.icon}),(0,G.jsxs)(`span`,{className:c.text,children:[(0,G.jsx)(`span`,{className:`text-white`,children:g.layer_num}),(0,G.jsx)(`span`,{className:`mx-1`,children:`/`}),(0,G.jsx)(`span`,{children:g.total_layers})]})]}),s.showEta&&g.remaining_time!=null&&g.remaining_time>0&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`flex items-center ${c.gap} text-white/70`,children:[(0,G.jsx)(Au,{className:c.icon}),(0,G.jsx)(`span`,{className:`${c.text} text-white`,children:Qf(g.remaining_time*60)})]}),(0,G.jsxs)(`div`,{className:`flex items-center ${c.gap} text-white/70`,children:[(0,G.jsx)(ks,{className:c.icon}),(0,G.jsxs)(`span`,{className:`${c.text} text-white`,children:[n(`streamOverlay.eta`),` `,Zf(g.remaining_time,_,n)]})]})]})]}),!b&&(0,G.jsx)(`div`,{className:`${c.text} text-white/70 py-2`,children:g.connected?n(`streamOverlay.printerIdle`):n(`streamOverlay.printerOffline`)}),C.length>0&&(0,G.jsx)(`div`,{className:`flex items-center ${c.gap} flex-wrap mt-2`,children:C.map(e=>(0,G.jsx)(DZe,{icon:e.icon,label:e.label,current:e.current,target:e.target,sizes:c},e.key))})]})})]})}function AZe(){let{t:e}=U(),{id:t}=dr(),{mode:n}=kd(),{data:r,isLoading:i,error:a}=K({queryKey:[`external-link`,t],queryFn:()=>Z.getExternalLink(Number(t)),enabled:!!t});return i?(0,G.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,G.jsx)(Y,{className:`w-8 h-8 text-bambu-green animate-spin`})}):a||!r?(0,G.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-4 text-bambu-gray`,children:[(0,G.jsx)(Pu,{className:`w-12 h-12`}),(0,G.jsx)(`p`,{children:e(`common.linkNotFound`)})]}):(0,G.jsx)(`iframe`,{src:r.url,className:`h-full w-full border-0`,style:{colorScheme:n},title:r.name,sandbox:`allow-scripts allow-same-origin allow-forms allow-popups allow-popups-to-escape-sandbox`})}function jZe(){let{id:e}=dr(),t=or(),n=so(),{t:r}=U(),{showToast:i}=Bd(),a=!!e,[o,s]=(0,y.useState)(``),[c,l]=(0,y.useState)(``),[u,d]=(0,y.useState)([]),[f,p]=(0,y.useState)(``),[m,h]=(0,y.useState)(!1),{data:g,isLoading:_}=K({queryKey:[`group`,e],queryFn:()=>Z.getGroup(Number(e)),enabled:a}),{data:v,isLoading:b}=K({queryKey:[`permissions`],queryFn:()=>Z.getPermissions()});a&&g&&!m&&(s(g.name),l(g.description||``),d(g.permissions),h(!0));let x=q({mutationFn:e=>Z.createGroup(e),onSuccess:()=>{n.invalidateQueries({queryKey:[`groups`]}),n.invalidateQueries({queryKey:[`group`]}),i(r(`groups.toast.created`)),t(`/settings?tab=users`)},onError:e=>{i(e.message,`error`)}}),S=q({mutationFn:t=>Z.updateGroup(Number(e),t),onSuccess:a=>{n.invalidateQueries({queryKey:[`groups`]}),a&&n.setQueryData([`group`,e],a),i(r(`groups.toast.updated`)),t(`/settings?tab=users`)},onError:e=>{i(e.message,`error`)}}),C=x.isPending||S.isPending,w=()=>{if(!o.trim()){i(r(`groups.toast.enterGroupName`),`error`);return}a?S.mutate({name:o===g?.name?void 0:o,description:c,permissions:u}):x.mutate({name:o,description:c||void 0,permissions:u})},T=e=>{d(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},E=(e,t)=>{let n=e.permissions.map(e=>e.value);d(e=>{let r=e.filter(e=>!n.includes(e));return t?[...r,...n]:r})},D=e=>e.permissions.every(e=>u.includes(e.value)),O=e=>{let t=e.permissions.filter(e=>u.includes(e.value)).length;return t>0&&t{v&&d(v.all_permissions)},A=()=>{d([])},j=f.toLowerCase(),M=(0,y.useMemo)(()=>v?j?v.categories.map(e=>({...e,permissions:e.permissions.filter(e=>e.label.toLowerCase().includes(j))})).filter(e=>e.permissions.length>0):v.categories:[],[v,j]),N=v?.all_permissions.length??0;return _||b?(0,G.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,G.jsx)(Y,{className:`w-8 h-8 text-bambu-green animate-spin`})}):(0,G.jsxs)(`div`,{className:`space-y-6 max-w-5xl mx-auto`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`button`,{onClick:()=>t(`/settings?tab=users`),className:`p-2 rounded-lg hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white transition-colors`,children:(0,G.jsx)(Io,{className:`w-5 h-5`})}),(0,G.jsx)(`h1`,{className:`text-xl font-bold text-white`,children:r(a?`groups.editor.title`:`groups.editor.createTitle`)})]}),a&&g?.is_system&&(0,G.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-3 rounded-lg bg-yellow-50 dark:bg-yellow-500/10 border border-yellow-300 dark:border-yellow-500/20 text-yellow-700 dark:text-yellow-400 text-sm`,children:[(0,G.jsx)(Pu,{className:`w-4 h-4 shrink-0`}),r(`groups.form.systemGroupWarning`)]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:r(`groups.form.groupName`)}),(0,G.jsx)(`input`,{type:`text`,value:o,onChange:e=>s(e.target.value),disabled:a&&g?.is_system,className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors disabled:opacity-50`,placeholder:r(`groups.form.groupNamePlaceholder`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:r(`groups.form.description`)}),(0,G.jsx)(`input`,{type:`text`,value:c,onChange:e=>l(e.target.value),className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:r(`groups.form.descriptionPlaceholder`)})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between flex-wrap gap-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[r(`groups.editor.permissionsSelected`,{count:u.length}),` / `,N]}),(0,G.jsx)(Q,{size:`sm`,variant:`ghost`,onClick:k,children:r(`groups.editor.selectAll`)}),(0,G.jsx)(Q,{size:`sm`,variant:`ghost`,onClick:A,children:r(`groups.editor.clearAll`)})]}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(Yl,{className:`w-4 h-4 absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray`}),(0,G.jsx)(`input`,{type:`text`,value:f,onChange:e=>p(e.target.value),placeholder:r(`groups.editor.search`),className:`pl-9 pr-4 py-2 text-sm bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors w-64`})]})]}),M.length===0?(0,G.jsx)(`div`,{className:`text-center py-12 text-bambu-gray`,children:r(`groups.editor.noResults`)}):(0,G.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:M.map(e=>{let t=v.categories.find(t=>t.name===e.name),n=t.permissions.filter(e=>u.includes(e.value)).length,i=t.permissions.length,a=D(t),o=O(t);return(0,G.jsxs)(Md,{children:[(0,G.jsxs)(`div`,{className:`sticky top-0 z-10 flex items-center justify-between px-4 py-3 bg-bambu-dark-secondary border-b border-bambu-dark-tertiary rounded-t-xl`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsxs)(`button`,{type:`button`,onClick:()=>E(t,!a),className:`w-5 h-5 rounded border flex items-center justify-center transition-colors shrink-0 ${a?`bg-bambu-green border-bambu-green`:o?`bg-bambu-green/50 border-bambu-green`:`border-bambu-gray hover:border-white`}`,children:[a&&(0,G.jsx)(us,{className:`w-3 h-3 text-white`}),o&&!a&&(0,G.jsx)(fl,{className:`w-3 h-3 text-white`})]}),(0,G.jsx)(iu,{className:`w-4 h-4 text-bambu-gray shrink-0`}),(0,G.jsx)(`span`,{className:`text-white font-medium text-sm`,children:e.name})]}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray tabular-nums`,children:[n,`/`,i]})]}),(0,G.jsx)(`div`,{className:`p-3 space-y-1`,children:e.permissions.map(e=>(0,G.jsxs)(`label`,{className:`flex items-center gap-3 px-2 py-1.5 rounded hover:bg-bambu-dark-secondary cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:u.includes(e.value),onChange:()=>T(e.value),className:`w-4 h-4 shrink-0 rounded border-bambu-gray text-bambu-green focus:ring-bambu-green focus:ring-offset-0 bg-bambu-dark-secondary`}),(0,G.jsxs)(`span`,{className:`flex flex-col`,children:[(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.label}),e.value===`websocket:connect`&&(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray/60`,children:r(`groups.editor.websocketHint`)})]})]},e.value))})]},e.name)})}),(0,G.jsx)(`div`,{className:`h-16`}),(0,G.jsxs)(`div`,{className:`fixed bottom-0 left-0 right-0 z-20 px-6 py-3 bg-bambu-dark-secondary border-t border-bambu-dark-tertiary flex items-center justify-center gap-3`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>t(`/settings?tab=users`),children:r(`common.cancel`)}),(0,G.jsx)(Q,{onClick:w,disabled:C||!o.trim(),children:C?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),r(`common.saving`)]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Wl,{className:`w-4 h-4`}),r(`common.save`)]})})]})]})}var MZe=1.65,NZe=[`#1DB954`,`#3B82F6`,`#F59E0B`,`#EF4444`,`#8B5CF6`];function p9(e,t,n,r){return`${e}||${t??``}||${n??``}||${r??``}`}function m9(e,t){let n=new Date(e);return n.setDate(n.getDate()+Math.round(t)),n}function h9(e){return e.toLocaleDateString(void 0,{month:`short`,day:`numeric`,year:`numeric`})}function g9(e){return e.toLocaleDateString(void 0,{month:`short`,day:`numeric`})}function PZe(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;ee+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 FZe(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 nZ.getAllUsageHistory(5e3),staleTime:6e4,enabled:o}),{data:O=[]}=K({queryKey:[`shopping-list`],queryFn:Z.getShoppingList,staleTime:3e4,enabled:o}),k=T?.forecast_global_lead_time_days??0,A=(0,y.useMemo)(()=>{let e=new Map;for(let t of E)e.set(p9(t.material,t.subtype,t.brand,t.color_name),t);return e},[E]),j=(0,y.useMemo)(()=>{let e=new Map;for(let t of D){let n=e.get(t.spool_id)??[];n.push(t),e.set(t.spool_id,n)}return e},[D]),M=(0,y.useMemo)(()=>{let t=new Map;for(let n of e){if(n.archived_at)continue;let e=p9(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]),N=(0,y.useMemo)(()=>{let e=new Date;return e.setHours(0,0,0,0),M.map(t=>{let n=A.get(t.key)??(t.colorName===null?null:A.get(p9(t.material,t.subtype,t.brand,null))??null),r=n?.lead_time_days??0,i=Math.max(k,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(...j.get(e.id)??[]);let d=null,f=null,p=`none`,m=PZe(u);if(m!==null)d=m.rate,f=m.stdDev,p=`history`;else{let e=FZe(t.spools);e!==null&&(d=e,p=`delta`)}let h=MZe*(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:m9(e,_),y=d&&d>0?Math.floor((s-g)/d):null,b=y===null?null:m9(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}})},[M,A,j,k]),P=(0,y.useMemo)(()=>[...new Set(M.map(e=>e.material))].sort(),[M]),F=(0,y.useMemo)(()=>[...new Set(M.map(e=>e.brand).filter(Boolean))].sort(),[M]),I=(0,y.useMemo)(()=>{let e=[...N];return m&&(e=e.filter(e=>e.group.material===m)),g&&(e=e.filter(e=>e.group.brand===g)),e.sort((e,t)=>{let n=0,r=0;switch(u){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=nr);return f===`asc`?i:-i}),e},[N,u,f,m,g]),L=(0,y.useMemo)(()=>N.filter(e=>!e.settings?.alerts_snoozed&&(e.stockBreakAlert||e.reorderAlert)),[N]),R=(0,y.useMemo)(()=>[...N].filter(e=>e.dailyRateG!==null).sort((e,t)=>t.totalUsedG-e.totalUsedG).slice(0,5),[N]);if(!o)return(0,G.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-16 text-bambu-gray gap-3`,children:[(0,G.jsx)(el,{className:`w-8 h-8 opacity-40`}),(0,G.jsx)(`p`,{className:`text-sm`,children:r(`forecast.noReadAccess`)})]});function z(e){u===e?p(e=>e===`asc`?`desc`:`asc`):(d(e),p(e===`days_left`?`asc`:`desc`))}let B=O.length>0?O.length:null;return(0,G.jsxs)(`div`,{className:`space-y-5`,children:[(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[L.length>0&&(0,G.jsxs)(`button`,{onClick:()=>l(e=>!e),className:`flex items-center gap-2 px-3 py-1.5 rounded-lg border text-sm font-medium transition-colors ${L.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,G.jsx)(Pu,{className:`w-4 h-4`}),r(`forecast.alertCount`,{count:L.length}),c?(0,G.jsx)(ms,{className:`w-3.5 h-3.5`}):(0,G.jsx)(ds,{className:`w-3.5 h-3.5`})]}),s&&(0,G.jsx)(VZe,{value:k,onSave:e=>{Z.updateSettings({forecast_global_lead_time_days:e}).then(()=>{t.invalidateQueries({queryKey:[`settings`]}),n(r(`forecast.globalLeadTimeSaved`),`success`)})}}),(0,G.jsxs)(`select`,{value:m,onChange:e=>h(e.target.value),className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${m?`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,G.jsx)(`option`,{value:``,children:r(`inventory.material`)}),P.map(e=>(0,G.jsx)(`option`,{value:e,children:e},e))]}),(0,G.jsxs)(`select`,{value:g,onChange:e=>_(e.target.value),className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${g?`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,G.jsx)(`option`,{value:``,children:r(`inventory.brand`)}),F.map(e=>(0,G.jsx)(`option`,{value:e,children:e},e))]}),(0,G.jsxs)(`button`,{onClick:()=>S(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,G.jsx)(au,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:r(`forecast.shoppingList`)}),B&&(0,G.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:B})]})]}),c&&L.length>0&&(0,G.jsx)(`div`,{className:`space-y-2`,children:L.map(e=>(0,G.jsx)(RZe,{forecast:e,onCart:()=>b(e)},e.group.key))}),x&&(0,G.jsx)(KZe,{items:O,forecasts:N,globalLeadTime:k,canWrite:s,onClose:()=>S(!1),onRemove:e=>{Z.removeFromShoppingList(e).then(()=>t.invalidateQueries({queryKey:[`shopping-list`]})).catch(()=>n(r(`forecast.failedSaveSettings`),`error`))},onClear:()=>{Z.clearShoppingList().then(()=>t.invalidateQueries({queryKey:[`shopping-list`]})).catch(()=>n(r(`forecast.failedSaveSettings`),`error`))}}),R.length>0&&(0,G.jsx)(BZe,{forecasts:R,days:C,onDaysChange:w}),N.length===0?(0,G.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-16 text-bambu-gray`,children:[(0,G.jsx)(Mu,{className:`w-10 h-10 mb-3 opacity-40`}),(0,G.jsx)(`p`,{className:`text-sm`,children:r(`forecast.noSpools`)})]}):(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg overflow-hidden border border-bambu-dark-tertiary`,children:[(0,G.jsx)(`div`,{className:`overflow-x-auto`,children:(0,G.jsxs)(`table`,{className:`w-full`,children:[(0,G.jsx)(`thead`,{children:(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary bg-bambu-dark-tertiary/30`,children:[(0,G.jsx)(`th`,{className:`w-8 px-4 py-3`}),(0,G.jsx)(_9,{col:`material`,active:u,dir:f,onSort:z,children:r(`forecast.sku`)}),(0,G.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:r(`locations.spools`)}),(0,G.jsx)(_9,{col:`stock`,active:u,dir:f,onSort:z,children:r(`forecast.stock`)}),(0,G.jsx)(_9,{col:`used`,active:u,dir:f,onSort:z,children:r(`forecast.dailyRate`)}),(0,G.jsx)(_9,{col:`days_left`,active:u,dir:f,onSort:z,children:r(`forecast.daysLeft`)}),(0,G.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:r(`forecast.emptyBy`)}),(0,G.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:r(`forecast.reorderBy`)}),(0,G.jsx)(`th`,{className:`w-24 px-4 py-3`})]})}),(0,G.jsx)(`tbody`,{className:`divide-y divide-bambu-dark-tertiary`,children:I.map(e=>(0,G.jsx)(HZe,{forecast:e,globalLeadTime:k,canWrite:s,onSaved:()=>t.invalidateQueries({queryKey:[`sku-settings`]}),onCart:()=>b(e),showToast:n},e.group.key))})]})}),(0,G.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,G.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,G.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-bambu-green inline-block`}),r(`forecast.trendLegend`)]}),(0,G.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,G.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-blue-400 inline-block`}),r(`forecast.estimatedLegend`)]}),(0,G.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,G.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-bambu-gray/40 inline-block`}),r(`forecast.noDataLegend`)]})]})]}),v&&(0,G.jsx)(JZe,{forecast:v,onClose:()=>b(null),onAdd:e=>{Z.addToShoppingList(e).then(()=>{t.invalidateQueries({queryKey:[`shopping-list`]}),n(r(`forecast.addedToCart`),`success`),b(null),S(!0)}).catch(()=>n(r(`forecast.failedAddItem`),`error`))}})]})}function _9({col:e,active:t,dir:n,onSort:r,children:i}){return(0,G.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,G.jsxs)(`span`,{className:`inline-flex items-center`,children:[i,t===e?n===`asc`?(0,G.jsx)(Vo,{className:`w-3 h-3 ml-1 text-bambu-green`}):(0,G.jsx)(Fo,{className:`w-3 h-3 ml-1 text-bambu-green`}):(0,G.jsx)(zo,{className:`w-3 h-3 ml-1 opacity-40`})]})})}function RZe({forecast:e,onCart:t}){let{t:n}=U(),r=[e.group.brand,e.group.material,e.group.subtype,e.group.colorName].filter(Boolean).join(` `),i=e.stockBreakAlert;return(0,G.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,G.jsx)(Pu,{className:`w-4 h-4 flex-shrink-0`}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`span`,{className:`font-medium`,children:r}),i?(0,G.jsxs)(`span`,{className:`ml-2 text-xs opacity-80`,children:[n(`forecast.stockBreakRisk`),` — `,n(`forecast.stockBreakDetail`,{days:e.daysRemaining,lt:e.effectiveLeadTimeDays})]}):(0,G.jsxs)(`span`,{className:`ml-2 text-xs opacity-80`,children:[n(`forecast.reorderNow`),` — `,n(`forecast.reorderTriggerPassed`,{date:e.reorderTriggerDate?h9(e.reorderTriggerDate):`—`})]})]}),(0,G.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,G.jsx)(au,{className:`w-3 h-3`}),` `,n(`forecast.order`)]})]})}var zZe=[{label:`1W`,value:7},{label:`1M`,value:30},{label:`6M`,value:180}];function BZe({forecasts:e,days:t,onDaysChange:n}){let{t:r}=U(),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:NZe[n%NZe.length],rop:e.reorderPointG,points:IZe(e,t)})),o=i.map(e=>{let t={day:e,label:g9(m9(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})(),c=o.slice(0,s+1),l=a.filter(e=>e.rop>0);return(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg overflow-hidden border border-bambu-dark-tertiary p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-4`,children:[(0,G.jsx)(Mu,{className:`w-4 h-4 text-bambu-green`}),(0,G.jsx)(`h3`,{className:`text-sm font-semibold text-white`,children:r(`forecast.chartTitle`)}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray ml-1 hidden sm:inline`,children:r(`forecast.dashedLinesROP`)}),(0,G.jsx)(`div`,{className:`ml-auto flex items-center bg-bambu-dark-tertiary rounded-lg p-0.5`,children:zZe.map(e=>(0,G.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,G.jsx)(cA,{width:`100%`,height:220,children:(0,G.jsxs)(VH,{data:c,margin:{top:4,right:8,bottom:0,left:0},children:[(0,G.jsx)(`defs`,{children:a.map(e=>(0,G.jsxs)(`linearGradient`,{id:`grad-${e.key}`,x1:`0`,y1:`0`,x2:`0`,y2:`1`,children:[(0,G.jsx)(`stop`,{offset:`5%`,stopColor:e.color,stopOpacity:.25}),(0,G.jsx)(`stop`,{offset:`95%`,stopColor:e.color,stopOpacity:.02})]},e.key))}),(0,G.jsx)(mV,{strokeDasharray:`3 3`,stroke:`#374151`,strokeOpacity:.5}),(0,G.jsx)(ZV,{dataKey:`label`,tick:{fill:`#6B7280`,fontSize:10},interval:Math.max(0,Math.ceil(s/8)-1),axisLine:!1,tickLine:!1}),(0,G.jsx)(nH,{tick:{fill:`#6B7280`,fontSize:10},axisLine:!1,tickLine:!1,tickFormatter:e=>e>=1e3?`${(e/1e3).toFixed(1)}kg`:`${e}g`,width:48}),(0,G.jsx)(tz,{content:({label:e,payload:t})=>t?.length?(0,G.jsxs)(`div`,{style:{background:`#1a1a2e`,border:`1px solid #374151`,borderRadius:8,fontSize:12,padding:`8px 12px`},children:[(0,G.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,G.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:6,color:`#E5E7EB`,marginBottom:2},children:[(0,G.jsx)(`span`,{style:{color:t?.color??`#9CA3AF`,fontSize:10},children:`●`}),(0,G.jsx)(`span`,{children:t?.label??String(e.dataKey)}),(0,G.jsxs)(`span`,{style:{color:`#9CA3AF`,marginLeft:4},children:[e.value,`g`]})]},String(e.dataKey)):null})]}):null}),(0,G.jsx)(ij,{formatter:e=>(0,G.jsx)(`span`,{style:{color:`#9CA3AF`,fontSize:11},children:a.find(t=>t.key===e)?.label??e})}),a.map(e=>(0,G.jsx)(kV,{type:`monotone`,dataKey:e.key,stroke:e.color,strokeWidth:2,fill:`url(#grad-${e.key})`,dot:!1,activeDot:{r:3}},e.key)),l.map(e=>(0,G.jsx)(rV,{y:e.rop,stroke:e.color,strokeDasharray:`4 3`,strokeOpacity:.6},`rop-${e.key}`))]})})]})}function VZe({value:e,onSave:t}){let{t:n}=U(),[r,i]=(0,y.useState)(!1),[a,o]=(0,y.useState)(String(e));function s(){let e=parseInt(a,10);isNaN(e)||e<0||(t(e),i(!1))}return(0,G.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,G.jsx)(Vc,{className:`w-3.5 h-3.5 flex-shrink-0`,"aria-label":n(`forecast.globalLeadTimeHint`)}),(0,G.jsxs)(`span`,{className:`hidden sm:inline`,children:[n(`forecast.globalLeadTime`),`:`]}),r?(0,G.jsxs)(`form`,{className:`flex items-center gap-1.5`,onSubmit:e=>{e.preventDefault(),s()},children:[(0,G.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,G.jsx)(`span`,{className:`text-bambu-gray`,children:`d`}),(0,G.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,G.jsx)(`button`,{type:`button`,onClick:()=>i(!1),className:`text-xs text-bambu-gray hover:text-white`,children:`✕`})]}):(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,G.jsxs)(`span`,{className:`font-semibold text-white`,children:[e,`d`]}),(0,G.jsx)(`button`,{onClick:()=>{o(String(e)),i(!0)},className:`p-0.5 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,G.jsx)(Dl,{className:`w-3 h-3`})})]})]})}function HZe({forecast:e,globalLeadTime:t,canWrite:n,onSaved:r,onCart:i,showToast:a}){let{t:o}=U(),[s,c]=(0,y.useState)(!1),[l,u]=(0,y.useState)(!1),[d,f]=(0,y.useState)(!1),[p,m]=(0,y.useState)(String(e.settings?.lead_time_days??0)),[h,g]=(0,y.useState)(String(e.settings?.safety_margin_value??14)),[_,v]=(0,y.useState)(e.settings?.safety_margin_unit??`days`);(0,y.useEffect)(()=>{l||m(String(e.settings?.lead_time_days??0))},[e.settings?.lead_time_days,l]),(0,y.useEffect)(()=>{d||(g(String(e.settings?.safety_margin_value??14)),v(e.settings?.safety_margin_unit??`days`))},[e.settings?.safety_margin_value,e.settings?.safety_margin_unit,d]);let b=q({mutationFn:Z.upsertSkuSettings,onSuccess:()=>{r(),a(o(`forecast.settingsSaved`),`success`)},onError:()=>a(o(`forecast.failedSaveSettings`),`error`)}),x=e.settings?.alerts_snoozed??!1,S=[e.group.brand,e.group.material,e.group.subtype,e.group.colorName].filter(Boolean).join(` `),C=e.group.spools[0]?.rgba?xf(e.group.spools[0].rgba):{backgroundColor:`#4B5563`},w=e.totalLabelG>0?Math.round(e.totalRemainingG/e.totalLabelG*100):0,T=x||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 E(t,n,r,i=x){b.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 D(t){t.stopPropagation(),E(e.settings?.lead_time_days??0,e.settings?.safety_margin_value??14,e.settings?.safety_margin_unit??`days`,!x)}let O=e.rateTier===`history`?(0,G.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,G.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-bambu-green`}),o(`forecast.trend`)]}):e.rateTier===`delta`?(0,G.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,G.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-blue-400`}),o(`forecast.estimated`)]}):(0,G.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,G.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-bambu-gray/40`}),o(`forecast.noData`)]});return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/50 cursor-pointer hover:bg-bambu-dark-tertiary/30 transition-colors ${x?``:e.stockBreakAlert?`bg-red-500/5`:e.reorderAlert?`bg-yellow-500/5`:``} ${x?`opacity-50`:``}`,onClick:()=>c(e=>!e),children:[(0,G.jsx)(`td`,{className:`px-4 py-3`,children:(0,G.jsx)(`span`,{className:`block w-5 h-5 rounded-full border border-black/20`,style:C})}),(0,G.jsx)(`td`,{className:`px-4 py-3`,children:(0,G.jsx)(`span`,{className:`text-sm text-white`,children:S})}),(0,G.jsx)(`td`,{className:`px-4 py-3`,children:(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.totalSpools})}),(0,G.jsx)(`td`,{className:`px-4 py-3 min-w-[140px]`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`div`,{className:`flex-1 h-2 bg-bambu-dark-tertiary rounded-full overflow-hidden`,children:(0,G.jsx)(`div`,{className:`h-full rounded-full ${w>50?`bg-bambu-green`:w>20?`bg-yellow-500`:`bg-red-500`}`,style:{width:`${Math.min(w,100)}%`}})}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray min-w-[40px] text-right`,children:[Math.round(e.totalRemainingG),`g`]})]})}),(0,G.jsx)(`td`,{className:`px-4 py-3`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 flex-wrap`,children:[(0,G.jsx)(`span`,{className:`text-sm text-white`,children:e.dailyRateG===null?`—`:`${e.dailyRateG.toFixed(1)}g/d`}),O]})}),(0,G.jsx)(`td`,{className:`px-4 py-3`,children:(0,G.jsx)(`span`,{className:`text-sm font-semibold ${T}`,children:e.daysRemaining===null?(0,G.jsx)(`span`,{className:`text-bambu-gray font-normal`,children:`—`}):`${e.daysRemaining}d`})}),(0,G.jsx)(`td`,{className:`px-4 py-3`,children:(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.projectedEmptyDate?h9(e.projectedEmptyDate):`—`})}),(0,G.jsx)(`td`,{className:`px-4 py-3`,children:(0,G.jsx)(`span`,{className:`text-sm ${!x&&e.reorderAlert?`text-yellow-700 dark:text-yellow-400`:`text-bambu-gray`}`,children:e.reorderTriggerDate?h9(e.reorderTriggerDate):`—`})}),(0,G.jsx)(`td`,{className:`px-4 py-3`,onClick:e=>e.stopPropagation(),children:(0,G.jsxs)(`div`,{className:`flex items-center justify-end gap-1`,children:[n&&(0,G.jsx)(`button`,{onClick:i,className:`p-1.5 text-bambu-gray hover:text-bambu-green rounded transition-colors`,title:o(`forecast.addToCart`),children:(0,G.jsx)(au,{className:`w-4 h-4`})}),!x&&(e.stockBreakAlert?(0,G.jsx)(Pu,{className:`w-4 h-4 text-red-600 dark:text-red-400`,"aria-label":o(`forecast.stockBreakRisk`)}):e.reorderAlert?(0,G.jsx)(Pu,{className:`w-4 h-4 text-yellow-600 dark:text-yellow-400`,"aria-label":o(`forecast.reorderNow`)}):e.daysRemaining===null?null:(0,G.jsx)(us,{className:`w-4 h-4 text-bambu-green/50`})),n&&(0,G.jsx)(`button`,{onClick:D,className:`p-1 rounded transition-colors ${x?`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:o(x?`forecast.alertsEnabled`:`forecast.alertsSnoozed`),children:(0,G.jsx)(Wo,{className:`w-3.5 h-3.5`})}),(0,G.jsx)(`button`,{onClick:e=>{e.stopPropagation(),c(e=>!e)},className:`p-1.5 text-bambu-gray hover:text-white rounded transition-colors`,children:s?(0,G.jsx)(ms,{className:`w-4 h-4`}):(0,G.jsx)(ds,{className:`w-4 h-4`})})]})})]}),s&&(0,G.jsx)(`tr`,{className:`bg-bambu-dark-tertiary/10`,children:(0,G.jsx)(`td`,{colSpan:9,className:`px-6 py-4`,children:(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{className:`grid gap-2 ${n?`grid-cols-2 sm:grid-cols-4`:`grid-cols-2`}`,children:[(0,G.jsx)(UZe,{label:o(`forecast.effectiveLeadTime`),value:`${e.effectiveLeadTimeDays}d`,hint:o(`forecast.effectiveLeadTimeHint`,{global:t,sku:e.settings?.lead_time_days??0})}),(0,G.jsx)(UZe,{label:o(`forecast.reorderPoint`),value:`${Math.round(e.reorderPointG)}g`,hint:o(`forecast.reorderPointHint`)}),n&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(WZe,{label:o(`forecast.skuLeadTimeOverride`),hint:o(`forecast.skuLeadTimeHint`),unit:o(`forecast.leadTime`),editing:l,value:e.settings?.lead_time_days??0,inputValue:p,onInputChange:m,onEdit:()=>{m(String(e.settings?.lead_time_days??0)),u(!0)},onSave:()=>{let t=parseInt(p,10);!isNaN(t)&&t>=0&&(E(t,e.settings?.safety_margin_value??14,_),u(!1))},onCancel:()=>u(!1),isPending:b.isPending,saveLabel:o(`forecast.save`),cancelLabel:o(`forecast.cancel`)}),(0,G.jsx)(GZe,{value:e.settings?.safety_margin_value??14,unit:_,editing:d,inputValue:h,dailyRateG:e.dailyRateG,onInputChange:g,onUnitChange:e=>v(e),onEdit:()=>{g(String(e.settings?.safety_margin_value??14)),v(e.settings?.safety_margin_unit??`days`),f(!0)},onSave:()=>{let t=parseInt(h,10);!isNaN(t)&&t>=0&&(E(e.settings?.lead_time_days??0,t,_),f(!1))},onCancel:()=>f(!1),isPending:b.isPending,saveLabel:o(`forecast.save`),cancelLabel:o(`forecast.cancel`),safetyMarginLabel:o(`forecast.safetyMarginLabel`)})]})]}),e.group.spools.length>1&&(0,G.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary pt-3`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:o(`forecast.individualSpools`)}),(0,G.jsx)(`div`,{className:`bg-bambu-dark-secondary rounded-lg overflow-hidden border border-bambu-dark-tertiary`,children:(0,G.jsxs)(`table`,{className:`w-full`,children:[(0,G.jsx)(`thead`,{children:(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary bg-bambu-dark-tertiary/30`,children:[(0,G.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:`#`}),(0,G.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:o(`inventory.remaining`)}),(0,G.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:o(`inventory.used`)}),(0,G.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:o(`forecast.labelWeight`)})]})}),(0,G.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,G.jsxs)(`tr`,{className:`hover:bg-bambu-dark-tertiary/30 transition-colors`,children:[(0,G.jsx)(`td`,{className:`px-4 py-2`,children:(0,G.jsxs)(`span`,{className:`text-xs font-mono text-bambu-gray/70`,children:[`#`,e.id]})}),(0,G.jsx)(`td`,{className:`px-4 py-2`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`w-24 h-1.5 bg-bambu-dark-tertiary rounded-full overflow-hidden flex-shrink-0`,children:(0,G.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,G.jsxs)(`span`,{className:`text-sm text-white`,children:[Math.round(t),`g`]})]})}),(0,G.jsx)(`td`,{className:`px-4 py-2`,children:(0,G.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[Math.round(Math.max(0,e.weight_used-(e.weight_used_baseline??0))),`g`]})}),(0,G.jsx)(`td`,{className:`px-4 py-2`,children:(0,G.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[e.label_weight,`g`]})})]},e.id)})})]})})]})]})})})]})}function UZe({label:e,value:t,hint:n}){return(0,G.jsxs)(`div`,{className:`bg-bambu-dark-tertiary/40 rounded-lg p-3`,title:n,children:[(0,G.jsx)(`div`,{className:`text-xs font-medium text-white mb-1`,children:e}),(0,G.jsx)(`div`,{className:`text-lg font-semibold text-white`,children:t})]})}function WZe({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,G.jsxs)(`div`,{className:`bg-bambu-dark-tertiary/40 rounded-lg p-3 space-y-1`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,G.jsx)(`span`,{className:`text-xs font-medium text-white`,children:e}),(0,G.jsx)(`span`,{title:t,children:(0,G.jsx)(Vc,{className:`w-3 h-3 text-bambu-gray/50`})})]}),r?(0,G.jsxs)(`form`,{className:`flex items-center gap-2`,onSubmit:e=>{e.preventDefault(),c()},children:[(0,G.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,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:n}),(0,G.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,G.jsx)(`button`,{type:`button`,onClick:l,disabled:u,className:`px-2 py-1 text-xs text-bambu-gray hover:text-white`,children:f})]}):(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-lg font-semibold text-white`,children:i}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:n}),(0,G.jsx)(`button`,{onClick:s,className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,G.jsx)(Dl,{className:`w-3 h-3`})})]})]})}function GZe({value:e,unit:t,editing:n,inputValue:r,dailyRateG:i,onInputChange:a,onUnitChange:o,onEdit:s,onSave:c,onCancel:l,isPending:u,saveLabel:d=`Save`,cancelLabel:f=`Cancel`,safetyMarginLabel:p=`Safety Margin`}){let{t:m}=U(),h=t===`g`?e:i===null?null:Math.round(i*e),g=t===`days`?m(`forecast.safetyMarginHintDays`,{approx:h===null?``:m(`forecast.safetyMarginHintDaysApprox`,{g:h})}):m(`forecast.safetyMarginHintG`,{approx:i===null?``:m(`forecast.safetyMarginHintGApprox`,{days:Math.round(e/i)})});return(0,G.jsxs)(`div`,{className:`bg-bambu-dark-tertiary/40 rounded-lg p-3 space-y-1`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,G.jsx)(`span`,{className:`text-xs font-medium text-white`,children:p}),(0,G.jsx)(`span`,{title:g,children:(0,G.jsx)(Vc,{className:`w-3 h-3 text-bambu-gray/50`})})]}),n?(0,G.jsxs)(`form`,{className:`flex items-center gap-2 flex-wrap`,onSubmit:e=>{e.preventDefault(),c()},children:[(0,G.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:u}),(0,G.jsxs)(`div`,{className:`flex bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded overflow-hidden text-xs`,children:[(0,G.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,G.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,G.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,G.jsx)(`button`,{type:`button`,onClick:l,disabled:u,className:`px-2 py-1 text-xs text-bambu-gray hover:text-white`,children:f})]}):(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-lg font-semibold text-white`,children:e}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:t}),h!==null&&t===`days`&&(0,G.jsxs)(`span`,{className:`text-lg font-semibold text-white`,children:[`≈ `,h,`g`]}),t===`g`&&i!==null&&(0,G.jsxs)(`span`,{className:`text-lg font-semibold text-white`,children:[`≈ `,Math.round(e/i),`d`]}),(0,G.jsx)(`button`,{onClick:s,className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,G.jsx)(Dl,{className:`w-3 h-3`})})]})]})}function KZe({items:e,forecasts:t,globalLeadTime:n,canWrite:r,onClose:i,onRemove:a,onClear:o}){let{t:s}=U(),c=so(),[l,u]=(0,y.useState)(`list`),d=q({mutationFn:async({id:e,status:t,item:n,avgSpoolG:r})=>{if(await Z.updateShoppingListStatus(e,t),t===`received`&&n){let t=r??1e3,i={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};await Z.bulkCreateSpools(i,n.quantity_spools),await Z.removeFromShoppingList(e)}},onSuccess:()=>{c.invalidateQueries({queryKey:[`shopping-list`]}),c.invalidateQueries({queryKey:[`spools`]})}}),f=(0,y.useMemo)(()=>{let e=new Map;for(let n of t)e.set(n.group.key,n);return e},[t]),p=(0,y.useMemo)(()=>e.map(e=>({item:e,forecast:f.get(p9(e.material,e.subtype,e.brand,e.color_name))??null})),[e,f]),m=(0,y.useMemo)(()=>p.filter(({forecast:e})=>!e||e.dailyRateG===null?!1:e.stockBreakAlert||e.daysRemaining!==null&&e.daysRemaining<=e.effectiveLeadTimeDays),[p]);function h(){let t=[s(`forecast.qty`),s(`forecast.material`),s(`inventory.brand`),s(`inventory.subtype`),s(`inventory.color`),`${s(`forecast.weight`)} (g)`,`${s(`forecast.leadTime`)} (d)`,s(`forecast.expectedRestock`),s(`forecast.status`),s(`forecast.note`)],r=e.map(e=>{let t=f.get(p9(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?h9(m9(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(`
+`))}function c(e,t,n,r){let i=n.enter(`tableCell`),o=n.enter(`phrasing`),s=n.containerPhrasing(e,{...r,before:a,after:a});return o(),i(),s}function l(e,t){return KJe(e,{align:t,alignDelimiters:r,padding:n,stringLength:i})}function u(e,t,n){let r=e.children,i=-1,a=[],o=t.enter(`table`);for(;++i0&&!n&&(e[e.length-1][1]._gfmAutolinkLiteralWalkedInto=!0),n}var bXe={tokenize:OXe,partial:!0};function xXe(){return{document:{91:{name:`gfmFootnoteDefinition`,tokenize:TXe,continuation:{tokenize:EXe},exit:DXe}},text:{91:{name:`gfmFootnoteCall`,tokenize:wXe},93:{name:`gfmPotentialFootnoteCall`,add:`after`,tokenize:SXe,resolveTo:CXe}}}}function SXe(e,t,n){let r=this,i=r.events.length,a=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]),o;for(;i--;){let e=r.events[i][1];if(e.type===`labelImage`){o=e;break}if(e.type===`gfmFootnoteCall`||e.type===`labelLink`||e.type===`label`||e.type===`image`||e.type===`link`)break}return s;function s(i){if(!o||!o._balanced)return n(i);let s=O5(r.sliceSerialize({start:o.end,end:r.now()}));return s.codePointAt(0)!==94||!a.includes(s.slice(1))?n(i):(e.enter(`gfmFootnoteCallLabelMarker`),e.consume(i),e.exit(`gfmFootnoteCallLabelMarker`),t(i))}}function CXe(e,t){let n=e.length;for(;n--;)if(e[n][1].type===`labelImage`&&e[n][0]===`enter`){e[n][1];break}e[n+1][1].type=`data`,e[n+3][1].type=`gfmFootnoteCallLabelMarker`;let r={type:`gfmFootnoteCall`,start:Object.assign({},e[n+3][1].start),end:Object.assign({},e[e.length-1][1].end)},i={type:`gfmFootnoteCallMarker`,start:Object.assign({},e[n+3][1].end),end:Object.assign({},e[n+3][1].end)};i.end.column++,i.end.offset++,i.end._bufferIndex++;let a={type:`gfmFootnoteCallString`,start:Object.assign({},i.end),end:Object.assign({},e[e.length-1][1].start)},o={type:`chunkString`,contentType:`string`,start:Object.assign({},a.start),end:Object.assign({},a.end)},s=[e[n+1],e[n+2],[`enter`,r,t],e[n+3],e[n+4],[`enter`,i,t],[`exit`,i,t],[`enter`,a,t],[`enter`,o,t],[`exit`,o,t],[`exit`,a,t],e[e.length-2],e[e.length-1],[`exit`,r,t]];return e.splice(n,e.length-n+1,...s),e}function wXe(e,t,n){let r=this,i=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]),a=0,o;return s;function s(t){return e.enter(`gfmFootnoteCall`),e.enter(`gfmFootnoteCallLabelMarker`),e.consume(t),e.exit(`gfmFootnoteCallLabelMarker`),c}function c(t){return t===94?(e.enter(`gfmFootnoteCallMarker`),e.consume(t),e.exit(`gfmFootnoteCallMarker`),e.enter(`gfmFootnoteCallString`),e.enter(`chunkString`).contentType=`string`,l):n(t)}function l(s){if(a>999||s===93&&!o||s===null||s===91||P5(s))return n(s);if(s===93){e.exit(`chunkString`);let a=e.exit(`gfmFootnoteCallString`);return i.includes(O5(r.sliceSerialize(a)))?(e.enter(`gfmFootnoteCallLabelMarker`),e.consume(s),e.exit(`gfmFootnoteCallLabelMarker`),e.exit(`gfmFootnoteCall`),t):n(s)}return P5(s)||(o=!0),a++,e.consume(s),s===92?u:l}function u(t){return t===91||t===92||t===93?(e.consume(t),a++,l):l(t)}}function TXe(e,t,n){let r=this,i=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]),a,o=0,s;return c;function c(t){return e.enter(`gfmFootnoteDefinition`)._container=!0,e.enter(`gfmFootnoteDefinitionLabel`),e.enter(`gfmFootnoteDefinitionLabelMarker`),e.consume(t),e.exit(`gfmFootnoteDefinitionLabelMarker`),l}function l(t){return t===94?(e.enter(`gfmFootnoteDefinitionMarker`),e.consume(t),e.exit(`gfmFootnoteDefinitionMarker`),e.enter(`gfmFootnoteDefinitionLabelString`),e.enter(`chunkString`).contentType=`string`,u):n(t)}function u(t){if(o>999||t===93&&!s||t===null||t===91||P5(t))return n(t);if(t===93){e.exit(`chunkString`);let n=e.exit(`gfmFootnoteDefinitionLabelString`);return a=O5(r.sliceSerialize(n)),e.enter(`gfmFootnoteDefinitionLabelMarker`),e.consume(t),e.exit(`gfmFootnoteDefinitionLabelMarker`),e.exit(`gfmFootnoteDefinitionLabel`),f}return P5(t)||(s=!0),o++,e.consume(t),t===92?d:u}function d(t){return t===91||t===92||t===93?(e.consume(t),o++,u):u(t)}function f(t){return t===58?(e.enter(`definitionMarker`),e.consume(t),e.exit(`definitionMarker`),i.includes(a)||i.push(a),B5(e,p,`gfmFootnoteDefinitionWhitespace`)):n(t)}function p(e){return t(e)}}function EXe(e,t,n){return e.check(K5,t,e.attempt(bXe,t,n))}function DXe(e){e.exit(`gfmFootnoteDefinition`)}function OXe(e,t,n){let r=this;return B5(e,i,`gfmFootnoteDefinitionIndent`,5);function i(e){let i=r.events[r.events.length-1];return i&&i[1].type===`gfmFootnoteDefinitionIndent`&&i[2].sliceSerialize(i[1],!0).length===4?t(e):n(e)}}function kXe(e){let t=(e||{}).singleTilde,n={name:`strikethrough`,tokenize:i,resolveAll:r};return t??=!0,{text:{126:n},insideSpan:{null:[n]},attentionMarkers:{null:[126]}};function r(e,t){let n=-1;for(;++n1?r(a):(e.consume(a),o++,c);if(o<2&&!t)return r(a);let l=e.exit(`strikethroughSequenceTemporary`),u=H5(a);return l._open=!u||u===2&&!!s,l._close=!s||s===2&&!!u,n(a)}}}var AXe=class{constructor(){this.map=[]}add(e,t,n){jXe(this,e,t,n)}consume(e){if(this.map.sort(function(e,t){return e[0]-t[0]}),this.map.length===0)return;let t=this.map.length,n=[];for(;t>0;)--t,n.push(e.slice(this.map[t][0]+this.map[t][1]),this.map[t][2]),e.length=this.map[t][0];n.push(e.slice()),e.length=0;let r=n.pop();for(;r;){for(let t of r)e.push(t);r=n.pop()}this.map.length=0}};function jXe(e,t,n,r){let i=0;if(!(n===0&&r.length===0)){for(;i-1;){let e=r.events[t][1].type;if(e===`lineEnding`||e===`linePrefix`)t--;else break}let i=t>-1?r.events[t][1].type:null,a=i===`tableHead`||i===`tableRow`?S:c;return a===S&&r.parser.lazy[r.now().line]?n(e):a(e)}function c(t){return e.enter(`tableHead`),e.enter(`tableRow`),l(t)}function l(e){return e===124?u(e):(o=!0,a+=1,u(e))}function u(t){return t===null?n(t):N5(t)?a>1?(a=0,r.interrupt=!0,e.exit(`tableRow`),e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),p):n(t):F5(t)?B5(e,u,`whitespace`)(t):(a+=1,o&&(o=!1,i+=1),t===124?(e.enter(`tableCellDivider`),e.consume(t),e.exit(`tableCellDivider`),o=!0,u):(e.enter(`data`),d(t)))}function d(t){return t===null||t===124||P5(t)?(e.exit(`data`),u(t)):(e.consume(t),t===92?f:d)}function f(t){return t===92||t===124?(e.consume(t),d):d(t)}function p(t){return r.interrupt=!1,r.parser.lazy[r.now().line]?n(t):(e.enter(`tableDelimiterRow`),o=!1,F5(t)?B5(e,m,`linePrefix`,r.parser.constructs.disable.null.includes(`codeIndented`)?void 0:4)(t):m(t))}function m(t){return t===45||t===58?g(t):t===124?(o=!0,e.enter(`tableCellDivider`),e.consume(t),e.exit(`tableCellDivider`),h):x(t)}function h(t){return F5(t)?B5(e,g,`whitespace`)(t):g(t)}function g(t){return t===58?(a+=1,o=!0,e.enter(`tableDelimiterMarker`),e.consume(t),e.exit(`tableDelimiterMarker`),_):t===45?(a+=1,_(t)):t===null||N5(t)?b(t):x(t)}function _(t){return t===45?(e.enter(`tableDelimiterFiller`),v(t)):x(t)}function v(t){return t===45?(e.consume(t),v):t===58?(o=!0,e.exit(`tableDelimiterFiller`),e.enter(`tableDelimiterMarker`),e.consume(t),e.exit(`tableDelimiterMarker`),y):(e.exit(`tableDelimiterFiller`),y(t))}function y(t){return F5(t)?B5(e,b,`whitespace`)(t):b(t)}function b(n){return n===124?m(n):n===null||N5(n)?!o||i!==a?x(n):(e.exit(`tableDelimiterRow`),e.exit(`tableHead`),t(n)):x(n)}function x(e){return n(e)}function S(t){return e.enter(`tableRow`),C(t)}function C(n){return n===124?(e.enter(`tableCellDivider`),e.consume(n),e.exit(`tableCellDivider`),C):n===null||N5(n)?(e.exit(`tableRow`),t(n)):F5(n)?B5(e,C,`whitespace`)(n):(e.enter(`data`),w(n))}function w(t){return t===null||t===124||P5(t)?(e.exit(`data`),C(t)):(e.consume(t),t===92?T:w)}function T(t){return t===92||t===124?(e.consume(t),w):w(t)}}function FXe(e,t){let n=-1,r=!0,i=0,a=[0,0,0,0],o=[0,0,0,0],s=!1,c=0,l,u,d,f=new AXe;for(;++nn[2]+1){let t=n[2]+1,r=n[3]-n[2]-1;e.add(t,r,[])}}e.add(n[3]+1,0,[[`exit`,o,t]])}return i!==void 0&&(a.end=Object.assign({},l9(t.events,i)),e.add(i,0,[[`exit`,a,t]]),a=void 0),a}function IXe(e,t,n,r,i){let a=[],o=l9(t.events,n);i&&(i.end=Object.assign({},o),a.push([`exit`,i,t])),r.end=Object.assign({},o),a.push([`exit`,r,t]),e.add(n+1,0,a)}function l9(e,t){let n=e[t],r=n[0]===`enter`?`start`:`end`;return n[1][r]}var LXe={name:`tasklistCheck`,tokenize:zXe};function RXe(){return{text:{91:LXe}}}function zXe(e,t,n){let r=this;return i;function i(t){return r.previous!==null||!r._gfmTasklistFirstContentOfListItem?n(t):(e.enter(`taskListCheck`),e.enter(`taskListCheckMarker`),e.consume(t),e.exit(`taskListCheckMarker`),a)}function a(t){return P5(t)?(e.enter(`taskListCheckValueUnchecked`),e.consume(t),e.exit(`taskListCheckValueUnchecked`),o):t===88||t===120?(e.enter(`taskListCheckValueChecked`),e.consume(t),e.exit(`taskListCheckValueChecked`),o):n(t)}function o(t){return t===93?(e.enter(`taskListCheckMarker`),e.consume(t),e.exit(`taskListCheckMarker`),e.exit(`taskListCheck`),s):n(t)}function s(r){return N5(r)?t(r):F5(r)?e.check({tokenize:BXe},t,n)(r):n(r)}}function BXe(e,t,n){return B5(e,r,`whitespace`);function r(e){return e===null?n(e):t(e)}}function VXe(e){return E5([cXe(),xXe(),kXe(e),NXe(),RXe()])}var HXe={};function UXe(e){let t=this,n=e||HXe,r=t.data(),i=r.micromarkExtensions||=[],a=r.fromMarkdownExtensions||=[],o=r.toMarkdownExtensions||=[];i.push(VXe(n)),a.push($Ye()),o.push(eXe(n))}var WXe=`fileManager.readmeCollapsed`;function GXe({folderId:e}){let{t}=U(),[n,r]=(0,y.useState)(()=>localStorage.getItem(WXe)===`1`);(0,y.useEffect)(()=>{localStorage.setItem(WXe,n?`1`:`0`)},[n]);let{data:i,isLoading:a,error:o}=K({queryKey:[`folder-readme`,e],queryFn:()=>Z.getLibraryFolderReadme(e),retry:!1,staleTime:3e4});return a||o||!i?null:n?(0,G.jsxs)(`div`,{className:`mb-2 lg:mb-0 order-first lg:order-none lg:w-10 lg:flex-shrink-0 lg:h-full`,children:[(0,G.jsxs)(`button`,{type:`button`,onClick:()=>r(!1),title:t(`fileManager.readme.show`),"aria-label":t(`fileManager.readme.show`),className:`flex lg:hidden w-full items-center gap-2 px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg hover:bg-bambu-dark/40 transition-colors`,children:[(0,G.jsx)(lc,{className:`w-4 h-4 text-bambu-green flex-shrink-0`}),(0,G.jsx)(`span`,{className:`text-sm font-medium text-white truncate`,children:i.filename}),(0,G.jsx)(wl,{className:`w-4 h-4 text-bambu-gray flex-shrink-0 ml-auto`})]}),(0,G.jsxs)(`button`,{type:`button`,onClick:()=>r(!1),title:t(`fileManager.readme.show`),"aria-label":t(`fileManager.readme.show`),className:`hidden lg:flex h-full w-10 flex-col items-center gap-2 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg hover:bg-bambu-dark/40 transition-colors`,children:[(0,G.jsx)(wl,{className:`w-4 h-4 text-bambu-green flex-shrink-0`}),(0,G.jsx)(`span`,{className:`text-xs font-medium text-bambu-gray [writing-mode:vertical-rl] rotate-180 select-none`,children:t(`fileManager.readme.label`)})]})]}):(0,G.jsxs)(`div`,{className:`mb-4 lg:mb-0 order-first lg:order-none lg:w-80 xl:w-96 lg:flex-shrink-0 lg:h-full flex flex-col bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg overflow-hidden`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-2 px-3 py-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,G.jsx)(lc,{className:`w-4 h-4 text-bambu-green flex-shrink-0`}),(0,G.jsx)(`span`,{className:`text-sm font-medium text-white truncate`,title:i.filename,children:i.filename}),i.truncated&&(0,G.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-400 flex-shrink-0`,children:t(`fileManager.readme.truncated`)})]}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>r(!0),title:t(`fileManager.readme.hide`),"aria-label":t(`fileManager.readme.hide`),className:`p-1 rounded text-bambu-gray hover:text-white hover:bg-bambu-dark/40 transition-colors flex-shrink-0`,children:(0,G.jsx)(Cl,{className:`w-4 h-4`})})]}),(0,G.jsx)(`div`,{className:`px-4 py-3 border-t border-bambu-dark-tertiary flex-1 overflow-y-auto max-h-96 lg:max-h-none text-sm text-bambu-gray-light leading-relaxed space-y-2`,children:(0,G.jsx)(eJe,{remarkPlugins:[UXe],components:{h1:({children:e})=>(0,G.jsx)(`h1`,{className:`text-lg font-semibold text-white mt-2 mb-1`,children:e}),h2:({children:e})=>(0,G.jsx)(`h2`,{className:`text-base font-semibold text-white mt-2 mb-1`,children:e}),h3:({children:e})=>(0,G.jsx)(`h3`,{className:`text-sm font-semibold text-white mt-2 mb-1`,children:e}),p:({children:e})=>(0,G.jsx)(`p`,{className:`my-1`,children:e}),ul:({children:e})=>(0,G.jsx)(`ul`,{className:`list-disc list-inside space-y-0.5 ml-2`,children:e}),ol:({children:e})=>(0,G.jsx)(`ol`,{className:`list-decimal list-inside space-y-0.5 ml-2`,children:e}),li:({children:e})=>(0,G.jsx)(`li`,{children:e}),code:({children:e,...t})=>t.className?(0,G.jsx)(`code`,{className:`block p-2 bg-bambu-dark rounded text-xs font-mono text-bambu-gray-light overflow-x-auto`,children:e}):(0,G.jsx)(`code`,{className:`px-1 py-0.5 bg-bambu-dark rounded text-xs font-mono text-bambu-green`,children:e}),pre:({children:e})=>(0,G.jsx)(`pre`,{className:`my-2`,children:e}),blockquote:({children:e})=>(0,G.jsx)(`blockquote`,{className:`border-l-2 border-bambu-dark-tertiary pl-3 text-bambu-gray italic`,children:e}),a:({children:e,href:t})=>(0,G.jsx)(`a`,{href:t,target:`_blank`,rel:`noopener noreferrer`,className:`text-bambu-green hover:underline`,children:e}),table:({children:e})=>(0,G.jsx)(`div`,{className:`overflow-x-auto`,children:(0,G.jsx)(`table`,{className:`min-w-full text-xs border-collapse`,children:e})}),th:({children:e})=>(0,G.jsx)(`th`,{className:`border border-bambu-dark-tertiary px-2 py-1 text-left font-semibold text-white`,children:e}),td:({children:e})=>(0,G.jsx)(`td`,{className:`border border-bambu-dark-tertiary px-2 py-1`,children:e}),hr:()=>(0,G.jsx)(`hr`,{className:`border-bambu-dark-tertiary my-2`})},children:i.content})})]})}function KXe({open:e,onClose:t,onPickTag:n}){let{t:r}=U(),i=so(),{showToast:a}=Bd(),[o,s]=(0,y.useState)(!1),[c,l]=(0,y.useState)(null),[u,d]=(0,y.useState)(``),[f,p]=(0,y.useState)(null),{data:m=[],isLoading:h}=K({queryKey:O8,queryFn:Z.getLibraryTags,enabled:e}),g=()=>{i.invalidateQueries({queryKey:O8}),i.invalidateQueries({queryKey:[`library-files`]})},_=q({mutationFn:async()=>{let e=u.trim();if(!e)throw Error(r(`fileManager.tags.nameRequired`));return c?Z.updateLibraryTag(c.id,e):Z.createLibraryTag(e)},onSuccess:()=>{a(r(c?`fileManager.tags.updated`:`fileManager.tags.created`),`success`),s(!1),l(null),d(``),g()},onError:e=>{a(e.message||r(`fileManager.tags.saveFailed`),`error`)}}),v=q({mutationFn:e=>Z.deleteLibraryTag(e),onSuccess:()=>{a(r(`fileManager.tags.deleted`),`success`),p(null),g()},onError:e=>{a(e.message||r(`fileManager.tags.deleteFailed`),`error`)}}),b=()=>{l(null),d(``),s(!0)},x=e=>{l(e),d(e.name),s(!0)},S=(0,y.useCallback)(()=>{_.isPending||(s(!1),l(null),d(``))},[_.isPending]);(0,y.useEffect)(()=>{if(!e)return;let n=e=>{e.key===`Escape`&&(_.isPending||v.isPending||(o?S():f||t()))};return document.addEventListener(`keydown`,n),()=>document.removeEventListener(`keydown`,n)},[e,o,f,_.isPending,v.isPending,S,t]);let C=e=>{e.preventDefault(),_.mutate()};if(!e)return null;let w=`library-tags-modal-title`,T=`library-tag-editor-title`;return(0,G.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[(0,G.jsx)(`div`,{className:`absolute inset-0 bg-black/60`,onClick:()=>{_.isPending||v.isPending||t()}}),(0,G.jsxs)(`div`,{className:`relative w-full max-w-4xl 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":w,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-4 px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,G.jsxs)(`h2`,{id:w,className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(Cu,{className:`w-5 h-5 text-bambu-green`}),r(`fileManager.tags.title`)]}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-sm mt-0.5`,children:r(`fileManager.tags.subtitle`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(Q,{onClick:b,children:[(0,G.jsx)(Ml,{className:`w-4 h-4`}),r(`fileManager.tags.add`)]}),(0,G.jsx)(`button`,{type:`button`,className:`p-1.5 text-bambu-gray hover:text-white rounded`,onClick:t,"aria-label":r(`common.close`),children:(0,G.jsx)($u,{className:`w-5 h-5`})})]})]}),(0,G.jsx)(`div`,{className:`overflow-y-auto`,children:h?(0,G.jsxs)(`div`,{className:`flex items-center justify-center py-16 text-bambu-gray`,children:[(0,G.jsx)(Y,{className:`w-6 h-6 animate-spin mr-2`}),r(`common.loading`)]}):m.length===0?(0,G.jsx)(`div`,{className:`py-16 text-center text-bambu-gray`,children:r(`fileManager.tags.empty`)}):(0,G.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,G.jsx)(`thead`,{children:(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary text-left text-bambu-gray`,children:[(0,G.jsx)(`th`,{className:`px-4 py-3 font-medium`,children:r(`fileManager.tags.name`)}),(0,G.jsx)(`th`,{className:`px-4 py-3 font-medium text-right`,children:r(`fileManager.tags.fileCount`)}),(0,G.jsx)(`th`,{className:`px-4 py-3 font-medium text-right w-32`,children:r(`common.actions`)})]})}),(0,G.jsx)(`tbody`,{children:m.map(e=>(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/60 hover:bg-bambu-dark-tertiary/30 ${n?`cursor-pointer`:``}`,onClick:()=>{n&&(n(e.id),t())},children:[(0,G.jsx)(`td`,{className:`px-4 py-3 text-white font-medium`,children:e.name}),(0,G.jsx)(`td`,{className:`px-4 py-3 text-right text-bambu-gray`,children:e.file_count}),(0,G.jsx)(`td`,{className:`px-4 py-3 text-right`,onClick:e=>e.stopPropagation(),children:(0,G.jsxs)(`div`,{className:`flex items-center justify-end gap-1`,children:[(0,G.jsx)(`button`,{type:`button`,className:`p-1.5 text-bambu-gray hover:text-bambu-green rounded`,onClick:()=>x(e),title:r(`common.edit`),"aria-label":r(`fileManager.tags.editAria`,{name:e.name}),children:(0,G.jsx)(Ol,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{type:`button`,className:`p-1.5 text-bambu-gray hover:text-red-600 dark:hover:text-red-400 rounded`,onClick:()=>p(e),title:r(`common.delete`),"aria-label":r(`fileManager.tags.deleteAria`,{name:e.name}),children:(0,G.jsx)(ju,{className:`w-4 h-4`})})]})})]},e.id))})]})})]}),o&&(0,G.jsxs)(`div`,{className:`fixed inset-0 z-[60] flex items-center justify-center`,children:[(0,G.jsx)(`div`,{className:`absolute inset-0 bg-black/60`,onClick:S}),(0,G.jsxs)(`div`,{className:`relative w-full max-w-md mx-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl p-6 shadow-2xl`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":T,children:[(0,G.jsx)(`h3`,{id:T,className:`text-lg font-semibold text-white mb-4`,children:r(c?`fileManager.tags.edit`:`fileManager.tags.add`)}),(0,G.jsxs)(`form`,{onSubmit:C,children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,htmlFor:`library-tag-name`,children:r(`fileManager.tags.name`)}),(0,G.jsx)(`input`,{id:`library-tag-name`,type:`text`,maxLength:64,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 mb-4`,placeholder:r(`fileManager.tags.createPlaceholder`),value:u,onChange:e=>d(e.target.value),autoFocus:!0}),(0,G.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:S,children:r(`common.cancel`)}),(0,G.jsxs)(Q,{type:`submit`,disabled:_.isPending||!u.trim(),children:[_.isPending&&(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),r(`common.save`)]})]})]})]})]}),f&&(0,G.jsx)(Zd,{title:r(`fileManager.tags.confirmDelete`,{name:f.name}),message:f.file_count>0?r(`fileManager.tags.confirmDeleteInUseMessage`,{count:f.file_count}):r(`fileManager.tags.confirmDeleteMessage`),confirmText:r(`common.delete`),variant:`danger`,isLoading:v.isPending,onConfirm:()=>v.mutate(f.id),onCancel:()=>p(null)})]})}var qXe=90;function JXe({onClose:e}){let{t}=U(),n=so(),{showToast:r}=Bd(),[i,a]=(0,y.useState)(qXe),[o,s]=(0,y.useState)(!0),[c,l]=(0,y.useState)(i);(0,y.useEffect)(()=>{let e=window.setTimeout(()=>l(i),300);return()=>window.clearTimeout(e)},[i]);let u=K({queryKey:[`library-purge-preview`,c,o],queryFn:()=>Z.previewLibraryPurge(c,o),enabled:c>=1}),d=q({mutationFn:()=>Z.executeLibraryPurge(i,o),onSuccess:i=>{r(t(`libraryPurge.toast.success`,{count:i.moved_to_trash}),`success`),n.invalidateQueries({queryKey:[`library-files`]}),n.invalidateQueries({queryKey:[`library-folders`]}),n.invalidateQueries({queryKey:[`library-trash`]}),n.invalidateQueries({queryKey:[`library-trash-count`]}),e()},onError:e=>r(e.message||t(`libraryPurge.toast.failed`),`error`)});(0,y.useEffect)(()=>{let t=t=>{t.key===`Escape`&&!d.isPending&&e()};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e,d.isPending]);let f=u.data,p=f?.count??0,m=f?.total_bytes??0,h=p>0&&!d.isPending;return(0,G.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4`,children:(0,G.jsxs)(`div`,{className:`bg-white dark:bg-gray-900 rounded-lg shadow-xl max-w-lg w-full`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-gray-200 dark:border-gray-700`,children:[(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-gray-900 dark:text-gray-100 flex items-center gap-2`,children:[(0,G.jsx)(ju,{className:`w-5 h-5`}),t(`libraryPurge.title`)]}),(0,G.jsx)(`button`,{onClick:e,className:`text-gray-400 hover:text-gray-600 dark:hover:text-gray-200`,"aria-label":t(`common.close`),disabled:d.isPending,children:(0,G.jsx)($u,{className:`w-5 h-5`})})]}),(0,G.jsxs)(`div`,{className:`p-4 space-y-4`,children:[(0,G.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400`,children:t(`libraryPurge.description`)}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{htmlFor:`purge-days`,className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:t(`libraryPurge.ageLabel`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`input`,{id:`purge-days`,type:`number`,min:1,max:3650,value:i,onChange:e=>a(Math.max(1,Math.min(3650,parseInt(e.target.value||`0`,10)||0))),className:`w-24 rounded border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-800 text-sm px-2 py-1 text-gray-900 dark:text-gray-100`}),(0,G.jsx)(`span`,{className:`text-sm text-gray-600 dark:text-gray-400`,children:t(`libraryPurge.days`)})]})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-gray-700 dark:text-gray-300`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:o,onChange:e=>s(e.target.checked),className:`rounded border-gray-300`}),t(`libraryPurge.includeNeverPrinted`)]}),(0,G.jsxs)(`div`,{className:`rounded border border-gray-200 dark:border-gray-700 bg-gray-50 dark:bg-gray-800/30 p-3`,children:[(0,G.jsx)(`div`,{className:`text-xs font-semibold uppercase tracking-wide text-gray-600 dark:text-gray-300 mb-2`,children:t(`libraryPurge.effectsTitle`)}),(0,G.jsxs)(`ul`,{className:`text-xs text-gray-700 dark:text-gray-300 space-y-1 list-disc pl-4`,children:[(0,G.jsx)(`li`,{children:t(`libraryPurge.effect1`)}),(0,G.jsx)(`li`,{children:t(`libraryPurge.effect2`)}),(0,G.jsx)(`li`,{children:t(`libraryPurge.effect3`)}),(0,G.jsx)(`li`,{children:t(`libraryPurge.effect4`)})]})]}),(0,G.jsx)(`div`,{className:`rounded border border-gray-200 dark:border-gray-700 bg-gray-50 dark:bg-gray-800/50 p-3`,children:u.isLoading||u.isFetching?(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-gray-500 dark:text-gray-400`,children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),` `,t(`libraryPurge.previewLoading`)]}):u.isError?(0,G.jsx)(`div`,{className:`text-sm text-red-600 dark:text-red-400`,children:u.error?.message??t(`libraryPurge.previewFailed`)}):(0,G.jsxs)(`div`,{className:`text-sm text-gray-900 dark:text-gray-100`,children:[(0,G.jsx)(`div`,{className:`font-medium`,children:t(`libraryPurge.previewSummary`,{count:p,size:Rd(m)})}),f?.sample_filenames&&f.sample_filenames.length>0&&(0,G.jsxs)(`ul`,{className:`mt-2 text-xs text-gray-600 dark:text-gray-400 space-y-0.5 list-disc pl-4`,children:[f.sample_filenames.map(e=>(0,G.jsx)(`li`,{className:`truncate`,children:e},e)),p>f.sample_filenames.length&&(0,G.jsx)(`li`,{className:`list-none italic text-gray-500`,children:t(`libraryPurge.andMore`,{count:p-f.sample_filenames.length})})]})]})}),(0,G.jsxs)(`div`,{className:`flex gap-2 items-start text-xs text-amber-700 dark:text-amber-400 bg-amber-50 dark:bg-amber-900/20 rounded px-3 py-2`,children:[(0,G.jsx)(Pu,{className:`w-4 h-4 mt-0.5 shrink-0`}),(0,G.jsx)(`span`,{children:t(`libraryPurge.warning`)})]})]}),(0,G.jsxs)(`div`,{className:`flex justify-end gap-2 p-4 border-t border-gray-200 dark:border-gray-700`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:e,disabled:d.isPending,children:t(`common.cancel`)}),(0,G.jsx)(Q,{variant:`danger`,disabled:!h,onClick:()=>d.mutate(),children:d.isPending?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin mr-1`}),t(`libraryPurge.purging`)]}):t(`libraryPurge.confirmCta`,{count:p})})]})]})})}function YXe({parentId:e,onClose:t,onSave:n,isLoading:r,t:i}){let[a,o]=(0,y.useState)(``);return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg w-full max-w-sm border border-bambu-dark-tertiary`,children:[(0,G.jsx)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary`,children:(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:i(`fileManager.newFolder`)})}),(0,G.jsxs)(`form`,{onSubmit:t=>{t.preventDefault(),n({name:a.trim(),parent_id:e})},className:`p-4 space-y-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:i(`fileManager.folderName`)}),(0,G.jsx)(`input`,{type:`text`,value:a,onChange:e=>o(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:i(`fileManager.folderNamePlaceholder`),autoFocus:!0,required:!0})]}),(0,G.jsxs)(`div`,{className:`flex justify-end gap-2 pt-2`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:t,children:i(`common.cancel`)}),(0,G.jsx)(Q,{type:`submit`,disabled:!a.trim()||r,children:r?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):i(`common.create`)})]})]})]})})}function XXe({onClose:e,onSave:t,isLoading:n,t:r}){let[i,a]=(0,y.useState)(``),[o,s]=(0,y.useState)(``),[c,l]=(0,y.useState)(!0),[u,d]=(0,y.useState)(!1);return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg w-full max-w-md border border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(_c,{className:`w-5 h-5 text-bambu-green`}),r(`fileManager.linkExternalFolder`)]}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:r(`fileManager.linkExternalFolderDescription`)})]}),(0,G.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),t({name:i.trim(),external_path:o.trim(),readonly:c,show_hidden:u})},className:`p-4 space-y-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:r(`fileManager.folderName`)}),(0,G.jsx)(`input`,{type:`text`,value:i,onChange:e=>a(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`,placeholder:r(`fileManager.externalFolderNamePlaceholder`),autoFocus:!0,required:!0})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:r(`fileManager.externalPath`)}),(0,G.jsx)(`input`,{type:`text`,value:o,onChange:e=>s(e.target.value),className:`w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green font-mono text-sm`,placeholder:`/mnt/nas/3d-prints`,required:!0}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:r(`fileManager.externalPathHelp`)})]}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:c,onChange:e=>l(e.target.checked),className:`rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,G.jsx)(`span`,{className:`text-sm text-white`,children:r(`fileManager.readOnly`)}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[`(`,r(`fileManager.readOnlyHelp`),`)`]})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:u,onChange:e=>d(e.target.checked),className:`rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,G.jsx)(`span`,{className:`text-sm text-white`,children:r(`fileManager.showHiddenFiles`)})]})]}),(0,G.jsxs)(`div`,{className:`flex justify-end gap-2 pt-2`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:e,children:r(`common.cancel`)}),(0,G.jsx)(Q,{type:`submit`,disabled:!i.trim()||!o.trim()||n,children:n?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):r(`fileManager.linkFolder`)})]})]})]})})}var ZXe=`<>:"/\\|?*`;function QXe(e){for(let t of e)if(ZXe.includes(t)||t.charCodeAt(0)<32)return t;return null}function $Xe({type:e,currentName:t,onClose:n,onSave:r,isLoading:i,t:a}){let o=e===`file`?t.match(/(\.gcode\.3mf|\.3mf|\.gcode)$/i)?.[1]??``:``,s=e===`file`&&o?t.slice(0,-o.length):t,[c,l]=(0,y.useState)(s),u=e===`file`?QXe(c):null,d=u?a(`fileManager.invalidFilenameChar`,{char:u}):null;return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg w-full max-w-sm border border-bambu-dark-tertiary`,children:[(0,G.jsx)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary`,children:(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:a(e===`file`?`fileManager.renameFile`:`fileManager.renameFolder`)})}),(0,G.jsxs)(`form`,{onSubmit:n=>{if(n.preventDefault(),d)return;let i=e===`file`?c.trim()+o:c.trim();c.trim()&&i!==t&&r(i)},className:`p-4 space-y-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-1`,children:a(`common.name`)}),(0,G.jsxs)(`div`,{className:`flex items-center bg-bambu-dark border rounded focus-within:border-bambu-green ${d?`border-red-500`:`border-bambu-dark-tertiary`}`,children:[(0,G.jsx)(`input`,{type:`text`,value:c,onChange:e=>l(e.target.value),className:`flex-1 bg-transparent px-3 py-2 text-white placeholder-bambu-gray focus:outline-none min-w-0`,autoFocus:!0,required:!0}),o&&(0,G.jsx)(`span`,{className:`pr-3 text-bambu-gray text-sm select-none whitespace-nowrap`,children:o})]}),d&&(0,G.jsx)(`p`,{className:`mt-1 text-xs text-red-700 dark:text-red-400`,children:d})]}),(0,G.jsxs)(`div`,{className:`flex justify-end gap-2 pt-2`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:n,children:a(`common.cancel`)}),(0,G.jsx)(Q,{type:`submit`,disabled:!c.trim()||c.trim()===s||!!d||i,children:i?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):a(`common.rename`)})]})]})]})})}function eZe({folders:e,selectedFiles:t,currentFolderId:n,onClose:r,onMove:i,isLoading:a,t:o}){let[s,c]=(0,y.useState)(null),l=(e,t=0)=>{let n=[];for(let r of e)n.push({id:r.id,name:r.name,depth:t}),r.children.length>0&&n.push(...l(r.children,t+1));return n},u=[{id:null,name:o(`fileManager.rootNoFolder`),depth:0},...l(e)];return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg w-full max-w-sm border border-bambu-dark-tertiary`,children:[(0,G.jsx)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary`,children:(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:o(`fileManager.moveFiles`,{count:t.length})})}),(0,G.jsxs)(`div`,{className:`p-4 space-y-4`,children:[(0,G.jsx)(`div`,{className:`max-h-64 overflow-y-auto space-y-1`,children:u.map(e=>(0,G.jsxs)(`button`,{onClick:()=>c(e.id),disabled:e.id===n,className:`w-full text-left px-3 py-2 rounded transition-colors flex items-center gap-2 ${s===e.id?`bg-bambu-green/20 text-bambu-green`:e.id===n?`opacity-50 cursor-not-allowed text-bambu-gray`:`hover:bg-bambu-dark text-white`}`,style:{paddingLeft:`${12+e.depth*16}px`},children:[(0,G.jsx)(hc,{className:`w-4 h-4`}),e.name,e.id===n&&(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray ml-auto`,children:[`(`,o(`fileManager.current`),`)`]})]},e.id??`root`))}),(0,G.jsxs)(`div`,{className:`flex justify-end gap-2 pt-2`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:r,children:o(`common.cancel`)}),(0,G.jsx)(Q,{onClick:()=>i(s),disabled:a,children:a?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):o(`common.move`)})]})]})]})})}function tZe({folder:e,onClose:t,onLink:n,isLoading:r,t:i}){let[a,o]=(0,y.useState)(`project`),[s,c]=(0,y.useState)(e.project_id||e.archive_id||null);(0,y.useState)(()=>{e.archive_id&&o(`archive`)});let{data:l}=K({queryKey:[`projects`],queryFn:()=>Z.getProjects(),select:e=>[...e].sort((e,t)=>e.name.localeCompare(t.name))}),{data:u}=K({queryKey:[`archives-for-link`],queryFn:()=>Z.getArchives(void 0,void 0,100)}),d=()=>{n(a===`project`?{project_id:s,archive_id:0}:{project_id:0,archive_id:s})},f=()=>{n({project_id:0,archive_id:0})},p=e.project_id||e.archive_id;return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg w-full max-w-md border border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary flex items-center justify-between`,children:[(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(Jc,{className:`w-5 h-5 text-bambu-green`}),i(`fileManager.linkFolder`)]}),(0,G.jsx)(`button`,{onClick:t,className:`p-1 hover:bg-bambu-dark rounded`,children:(0,G.jsx)($u,{className:`w-5 h-5 text-bambu-gray`})})]}),(0,G.jsxs)(`div`,{className:`p-4 space-y-4`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i(`fileManager.linkFolderDescription`,{name:e.name})}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsxs)(`button`,{onClick:()=>{o(`project`),c(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg border transition-colors ${a===`project`?`border-bambu-green bg-bambu-green/10 text-bambu-green`:`border-bambu-dark-tertiary text-bambu-gray hover:text-white`}`,children:[(0,G.jsx)(Xo,{className:`w-4 h-4`}),i(`fileManager.project`)]}),(0,G.jsxs)(`button`,{onClick:()=>{o(`archive`),c(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg border transition-colors ${a===`archive`?`border-bambu-green bg-bambu-green/10 text-bambu-green`:`border-bambu-dark-tertiary text-bambu-gray hover:text-white`}`,children:[(0,G.jsx)(No,{className:`w-4 h-4`}),i(`fileManager.archive`)]})]}),(0,G.jsx)(`div`,{className:`max-h-64 overflow-y-auto space-y-1 bg-bambu-dark rounded-lg p-2`,children:a===`project`?l&&l.length>0?l.map(e=>(0,G.jsxs)(`button`,{onClick:()=>c(e.id),className:`w-full text-left px-3 py-2 rounded transition-colors flex items-center gap-2 ${s===e.id?`bg-bambu-green/20 text-bambu-green`:`hover:bg-bambu-dark-tertiary text-white`}`,children:[(0,G.jsx)(`div`,{className:`w-3 h-3 rounded-full flex-shrink-0`,style:{backgroundColor:e.color||`#00ae42`}}),(0,G.jsx)(`span`,{className:`truncate`,children:e.name})]},e.id)):(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray text-center py-4`,children:i(`fileManager.noProjectsFound`)}):u&&u.length>0?u.map(e=>(0,G.jsxs)(`button`,{onClick:()=>c(e.id),className:`w-full text-left px-3 py-2 rounded transition-colors flex items-center gap-2 ${s===e.id?`bg-bambu-green/20 text-bambu-green`:`hover:bg-bambu-dark-tertiary text-white`}`,children:[(0,G.jsx)(ac,{className:`w-4 h-4 text-bambu-gray flex-shrink-0`}),(0,G.jsx)(`span`,{className:`truncate`,children:e.print_name||e.filename})]},e.id)):(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray text-center py-4`,children:i(`fileManager.noArchivesFound`)})})]}),(0,G.jsxs)(`div`,{className:`p-4 border-t border-bambu-dark-tertiary flex justify-between`,children:[p&&(0,G.jsxs)(Q,{variant:`danger`,onClick:f,disabled:r,children:[(0,G.jsx)(Lu,{className:`w-4 h-4 mr-2`}),i(`fileManager.unlink`)]}),(0,G.jsxs)(`div`,{className:`flex gap-2 ${p?``:`ml-auto`}`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:t,children:i(`common.cancel`)}),(0,G.jsx)(Q,{onClick:d,disabled:!s||r,children:r?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):i(`fileManager.link`)})]})]})]})})}function nZe({folder:e,selectedFolderId:t,onSelect:n,onDelete:r,onLink:i,onRename:a,depth:o=0,wrapNames:s=!1,defaultExpanded:c=!0,showModified:l=!1,hasPermission:u,t:d}){let[f,p]=(0,y.useState)(c),[m,h]=(0,y.useState)(!1),g=e.children.length>0,_=e.project_id||e.archive_id,v=e.is_external,b=u(`library:delete_all`)||u(`library:delete_own`)&&e.file_count===0&&!g&&!v&&!_,x=b?void 0:u(`library:delete_own`)&&!v&&!_?d(`fileManager.onlyEmptyFoldersDeletable`):d(`fileManager.noPermissionDeleteFolder`);return(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`group flex items-center gap-1 px-2 py-1.5 rounded cursor-pointer transition-colors ${t===e.id?`bg-bambu-green/20 text-bambu-green`:`hover:bg-bambu-dark text-white`}`,style:{paddingLeft:`${8+o*12}px`},onClick:()=>n(e.id),children:[g?(0,G.jsx)(`button`,{onClick:e=>{e.stopPropagation(),p(!f)},className:`p-0.5 hover:bg-bambu-dark-tertiary rounded`,children:(0,G.jsx)(fs,{className:`w-3.5 h-3.5 transition-transform ${f?`rotate-90`:``}`})}):(0,G.jsx)(`div`,{className:`w-4.5`}),v?(0,G.jsx)(_c,{className:`w-4 h-4 text-purple-600 dark:text-purple-400 flex-shrink-0`}):(0,G.jsx)(hc,{className:`w-4 h-4 text-bambu-green flex-shrink-0`}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`span`,{className:`block text-sm ${s?`break-all`:`truncate`}`,title:e.name,children:e.name}),l&&e.latest_activity_at&&(0,G.jsxs)(`span`,{className:`mt-0.5 flex items-center gap-1 text-xs text-bambu-gray`,title:d(`fileManager.lastActivity`),children:[(0,G.jsx)(ts,{className:`w-3 h-3 flex-shrink-0`}),(0,G.jsx)(`span`,{className:`truncate`,children:qf(e.latest_activity_at)})]})]}),_&&(0,G.jsxs)(`button`,{onClick:t=>{t.stopPropagation(),i(e)},className:`flex-shrink-0 flex items-center gap-1 text-xs px-1.5 py-0.5 rounded bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400 hover:bg-blue-200 dark:hover:bg-blue-500/30 transition-colors`,title:`${e.project_name?`Project: ${e.project_name}`:`Archive: ${e.archive_name}`} (click to change)`,children:[(0,G.jsx)(Jc,{className:`w-3 h-3`}),e.project_name?(0,G.jsx)(Xo,{className:`w-3 h-3`}):(0,G.jsx)(No,{className:`w-3 h-3`})]}),v&&e.external_readonly&&(0,G.jsx)(`span`,{title:d(`fileManager.readOnly`),children:(0,G.jsx)(el,{className:`w-3 h-3 text-amber-600 dark:text-amber-400 flex-shrink-0`})}),e.file_count>0&&(0,G.jsx)(`span`,{className:`flex-shrink-0 text-xs text-bambu-gray`,children:e.file_count}),!_&&!v&&(0,G.jsx)(`button`,{onClick:t=>{t.stopPropagation(),i(e)},className:`flex-shrink-0 p-1 rounded hover:bg-bambu-dark-tertiary`,title:d(`fileManager.linkToProjectOrArchive`),children:(0,G.jsx)(Jc,{className:`w-3.5 h-3.5 text-bambu-gray hover:text-bambu-green`})}),(0,G.jsx)(`div`,{className:`flex-shrink-0 flex items-center gap-0.5 transition-opacity ${s?``:`opacity-0 group-hover:opacity-100`}`,onClick:e=>e.stopPropagation(),children:(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(`button`,{onClick:()=>h(!m),className:`p-1 rounded hover:bg-bambu-dark-tertiary`,children:(0,G.jsx)(Zs,{className:`w-3.5 h-3.5 text-bambu-gray`})}),m&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`fixed inset-0 z-10`,onClick:()=>h(!1)}),(0,G.jsxs)(`div`,{className:`absolute right-0 top-full mt-1 z-20 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl py-1 min-w-[120px]`,children:[(0,G.jsxs)(`button`,{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${u(`library:update_all`)?`text-white hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{u(`library:update_all`)&&(a(e),h(!1))},disabled:!u(`library:update_all`),title:u(`library:update_all`)?void 0:d(`fileManager.noPermissionRenameFolder`),children:[(0,G.jsx)(Ol,{className:`w-3.5 h-3.5`}),d(`common.rename`)]}),(0,G.jsxs)(`button`,{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${u(`library:update_all`)?`text-white hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{u(`library:update_all`)&&(i(e),h(!1))},disabled:!u(`library:update_all`),title:u(`library:update_all`)?void 0:d(`fileManager.noPermissionLinkFolder`),children:[(0,G.jsx)(Jc,{className:`w-3.5 h-3.5`}),d(_?`fileManager.changeLink`:`fileManager.linkTo`)]}),(0,G.jsxs)(`button`,{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${b?`text-red-700 dark:text-red-400 hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{b&&(r(e.id),h(!1))},disabled:!b,title:x,children:[(0,G.jsx)(ju,{className:`w-3.5 h-3.5`}),d(`common.delete`)]})]})]})]})})]}),g&&f&&(0,G.jsx)(`div`,{children:e.children.map(e=>(0,G.jsx)(nZe,{folder:e,selectedFolderId:t,onSelect:n,onDelete:r,onLink:i,onRename:a,depth:o+1,wrapNames:s,defaultExpanded:c,showModified:l,hasPermission:u,t:d},e.id))})]})}function u9(e){let t=e.toLowerCase();return t.endsWith(`.gcode`)||t.endsWith(`.gcode.3mf`)}function rZe({file:e,isSelected:t,isMobile:n,onSelect:r,onDelete:i,onDownload:a,onPrint:o,onSlice:s,onOpenInSlicer:c,onRunPipeline:l,useSlicerApi:u,canSlice:d,onPreview3d:f,onRename:p,onGenerateThumbnail:m,onTagClick:h,thumbnailVersion:g,hasPermission:_,canModify:v,authEnabled:b,showModified:x,t:S}){let[C,w]=(0,y.useState)(!1);return(0,G.jsxs)(`div`,{className:`group relative bg-bambu-dark-secondary rounded-lg border transition-all cursor-pointer overflow-hidden ${t?`border-bambu-green ring-1 ring-bambu-green`:`border-bambu-dark-tertiary hover:border-bambu-green/50`}`,onClick:()=>r(e.id),children:[(0,G.jsxs)(`div`,{className:`aspect-square bg-bambu-dark flex items-center justify-center overflow-hidden`,children:[e.thumbnail_path?(0,G.jsx)(`img`,{src:`${Z.getLibraryFileThumbnailUrl(e.id)}${g?(Z.getLibraryFileThumbnailUrl(e.id).includes(`?`)?`&`:`?`)+`v=${g}`:``}`,alt:e.filename,className:`w-full h-full object-cover`}):(0,G.jsx)(ac,{className:`w-12 h-12 text-bambu-gray/30`}),(0,G.jsx)(`div`,{className:`absolute top-2 right-2 text-xs px-1.5 py-0.5 rounded font-medium ${e.file_type===`3mf`?`bg-bambu-green/90 text-white`:e.file_type===`gcode`||e.file_type===`gcode.3mf`?`bg-blue-500/90 text-white`:e.file_type===`stl`?`bg-purple-500/90 text-white`:`bg-bambu-gray/90 text-white`}`,children:e.file_type.toUpperCase()})]}),(0,G.jsxs)(`div`,{className:`p-3`,children:[(0,G.jsx)(`h3`,{className:`text-sm font-medium text-white truncate`,title:e.print_name||e.filename,children:e.print_name||e.filename}),(0,G.jsxs)(`div`,{className:`flex items-center gap-3 mt-1 text-xs text-bambu-gray`,children:[(0,G.jsx)(`span`,{children:Rd(e.file_size)}),e.print_time_seconds&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(ks,{className:`w-3 h-3`}),Qf(e.print_time_seconds)]})]}),e.sliced_for_model&&(0,G.jsxs)(`div`,{className:`mt-1 text-xs text-bambu-gray flex items-center gap-1`,children:[(0,G.jsx)(Fl,{className:`w-3 h-3`}),e.sliced_for_model]}),(e.variant_count??0)>1&&(0,G.jsxs)(`div`,{className:`mt-1 text-xs text-bambu-green flex items-center gap-1`,children:[(0,G.jsx)(Gc,{className:`w-3 h-3`}),S(`fileManager.variants.badge`,{count:e.variant_count})]}),e.print_count>0&&(0,G.jsx)(`div`,{className:`mt-1 text-xs text-bambu-green`,children:S(`fileManager.printedCount`,{count:e.print_count})}),b&&e.created_by_username&&(0,G.jsxs)(`div`,{className:`mt-1 text-xs text-bambu-gray flex items-center gap-1`,children:[(0,G.jsx)(zu,{className:`w-3 h-3`}),e.created_by_username]}),x&&(0,G.jsxs)(`div`,{className:`mt-1 text-xs text-bambu-gray flex items-center gap-1`,title:S(`fileManager.lastModified`),children:[(0,G.jsx)(ts,{className:`w-3 h-3`}),qf(e.fs_modified_at??e.created_at)]}),(e.tags?.length??0)>0&&(0,G.jsx)(`div`,{className:`mt-2 flex flex-wrap gap-1`,onClick:e=>e.stopPropagation(),children:e.tags.map(e=>(0,G.jsxs)(`button`,{type:`button`,onClick:()=>h?.(e.id),className:`inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded-full text-[10px] bg-bambu-green/10 text-bambu-green hover:bg-bambu-green/20 transition-colors max-w-full`,title:e.name,children:[(0,G.jsx)(Cu,{className:`w-2.5 h-2.5 flex-shrink-0`}),(0,G.jsx)(`span`,{className:`truncate`,children:e.name})]},e.id))})]}),(0,G.jsxs)(`div`,{className:`absolute bottom-2 right-2 transition-opacity ${n?`opacity-100`:`opacity-0 group-hover:opacity-100`}`,onClick:e=>e.stopPropagation(),children:[(0,G.jsx)(`button`,{onClick:()=>w(!C),className:`p-1.5 rounded bg-bambu-dark-secondary/90 hover:bg-bambu-dark-tertiary`,children:(0,G.jsx)(Zs,{className:`w-4 h-4 text-bambu-gray`})}),C&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`fixed inset-0 z-10`,onClick:()=>w(!1)}),(0,G.jsxs)(`div`,{className:`absolute right-0 bottom-8 z-20 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl py-1 min-w-[140px]`,children:[o&&u9(e.filename)&&(0,G.jsxs)(`button`,{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${_(`queue:create`)?`text-bambu-green hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{_(`queue:create`)&&(o(e),w(!1))},disabled:!_(`queue:create`),title:_(`queue:create`)?void 0:S(`fileManager.noPermissionAddToQueue`),children:[(0,G.jsx)(Fl,{className:`w-3.5 h-3.5`}),S(`common.print`)]}),XW(e.filename)&&(u?s:c)&&(0,G.jsxs)(`button`,{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${d?`text-white hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{d&&(u?s?.(e):c?.(e),w(!1))},disabled:!d,title:d?void 0:S(u?`fileManager.noPermissionSlice`:`fileManager.noPermissionDownload`),children:[u?(0,G.jsx)(Is,{className:`w-3.5 h-3.5`}):(0,G.jsx)(tc,{className:`w-3.5 h-3.5`}),S(`slice.action`)]}),l&&u&&XW(e.filename)&&(0,G.jsxs)(`button`,{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${_(`pipelines:run`)?`text-white hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{_(`pipelines:run`)&&(l(e),w(!1))},disabled:!_(`pipelines:run`),title:_(`pipelines:run`)?void 0:S(`library.runWithPipeline.noPermission`),children:[(0,G.jsx)(Al,{className:`w-3.5 h-3.5`}),S(`library.runWithPipeline.actionLabel`)]}),f&&(e.file_type===`3mf`||e.file_type===`gcode`||e.file_type===`stl`||e.file_type===`gcode.3mf`)&&(0,G.jsxs)(`button`,{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${_(`library:read`)?`text-white hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{_(`library:read`)&&(f(e),w(!1))},disabled:!_(`library:read`),title:_(`library:read`)?void 0:`You do not have permission to preview files`,children:[(0,G.jsx)(Yo,{className:`w-3.5 h-3.5`}),`3D Preview`]}),(0,G.jsxs)(`button`,{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${_(`library:read`)?`text-white hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{_(`library:read`)&&(a(e.id),w(!1))},disabled:!_(`library:read`),title:_(`library:read`)?void 0:S(`fileManager.noPermissionDownload`),children:[(0,G.jsx)(Js,{className:`w-3.5 h-3.5`}),S(`common.download`)]}),p&&(0,G.jsxs)(`button`,{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${v(`library`,`update`,e.created_by_id)?`text-white hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{v(`library`,`update`,e.created_by_id)&&(p(e),w(!1))},disabled:!v(`library`,`update`,e.created_by_id),title:v(`library`,`update`,e.created_by_id)?void 0:S(`fileManager.noPermissionRenameFile`),children:[(0,G.jsx)(Ol,{className:`w-3.5 h-3.5`}),S(`common.rename`)]}),m&&e.file_type===`stl`&&(0,G.jsxs)(`button`,{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${v(`library`,`update`,e.created_by_id)?`text-white hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{v(`library`,`update`,e.created_by_id)&&(m(e),w(!1))},disabled:!v(`library`,`update`,e.created_by_id),title:v(`library`,`update`,e.created_by_id)?void 0:S(`fileManager.noPermissionGenerateThumbnail`),children:[(0,G.jsx)(zc,{className:`w-3.5 h-3.5`}),S(`fileManager.generateThumbnail`)]}),(0,G.jsxs)(`button`,{className:`w-full px-3 py-1.5 text-left text-sm flex items-center gap-2 ${v(`library`,`delete`,e.created_by_id)?`text-red-700 dark:text-red-400 hover:bg-bambu-dark`:`text-bambu-gray cursor-not-allowed`}`,onClick:()=>{v(`library`,`delete`,e.created_by_id)&&(i(e.id),w(!1))},disabled:!v(`library`,`delete`,e.created_by_id),title:v(`library`,`delete`,e.created_by_id)?void 0:S(`fileManager.noPermissionDeleteFile`),children:[(0,G.jsx)(ju,{className:`w-3.5 h-3.5`}),S(`common.delete`)]})]})]})]}),(0,G.jsx)(`div`,{className:`absolute top-2 left-2 w-5 h-5 rounded border-2 flex items-center justify-center transition-all ${t?`bg-bambu-green border-bambu-green`:`border-white/30 bg-black/30 ${n?`opacity-100`:`opacity-0 group-hover:opacity-100`}`}`,children:t&&(0,G.jsx)(`div`,{className:`w-2 h-2 bg-white rounded-sm`})})]})}function iZe(){let{t:e}=U(),t=so(),{showToast:n}=Bd(),{hasPermission:r,hasAnyPermission:i,canModify:a,authEnabled:o}=Ed(),[s]=Li(),c=or(),l=s.get(`folder`),[u,d]=(0,y.useState)(l?parseInt(l,10):null),[f,p]=(0,y.useState)(`internal`),[m,h]=(0,y.useState)([]),[g,_]=(0,y.useState)(!1),[v,b]=(0,y.useState)(!1),[x,S]=(0,y.useState)(!1),[C,w]=(0,y.useState)(!1),[T,E]=(0,y.useState)([]),[D,O]=(0,y.useState)(!1),[k,A]=(0,y.useState)(!1),[j,M]=(0,y.useState)(!1),[N,P]=(0,y.useState)([]),[F,I]=(0,y.useState)(null),[L,R]=(0,y.useState)(null),[z,B]=(0,y.useState)(null),[V,ee]=(0,y.useState)(null),[te,ne]=(0,y.useState)(null),[re,ie]=(0,y.useState)(null),[ae,oe]=(0,y.useState)({}),[se,H]=(0,y.useState)(null),[ce,le]=(0,y.useState)(()=>localStorage.getItem(`library-view-mode`)||`grid`),[ue,de]=(0,y.useState)(()=>localStorage.getItem(`library-wrap-folders`)===`true`),[fe,pe]=(0,y.useState)(()=>localStorage.getItem(`library-collapse-folders`)===`true`),[me,he]=(0,y.useState)(()=>localStorage.getItem(`library-folder-sort-field`)===`activity`?`activity`:`name`),[ge,_e]=(0,y.useState)(()=>localStorage.getItem(`library-folder-sort-direction`)===`desc`?`desc`:`asc`),[ve,ye]=(0,y.useState)(()=>{let e=localStorage.getItem(`library-sidebar-width`);return e?parseInt(e,10):256}),[be,xe]=(0,y.useState)(!1),Se=(0,y.useRef)(null);(0,y.useEffect)(()=>{if(!be)return;document.body.style.userSelect=`none`,document.body.style.cursor=`col-resize`;let e=e=>{if(!Se.current)return;let t=Se.current.parentElement?.getBoundingClientRect();if(!t)return;let n=e.clientX-t.left;ye(Math.min(500,Math.max(200,n)))},t=()=>{xe(!1),document.body.style.userSelect=``,document.body.style.cursor=``,localStorage.setItem(`library-sidebar-width`,String(ve))};return document.addEventListener(`mousemove`,e),document.addEventListener(`mouseup`,t),()=>{document.removeEventListener(`mousemove`,e),document.removeEventListener(`mouseup`,t),document.body.style.userSelect=``,document.body.style.cursor=``}},[be,ve]);let[Ce,we]=(0,y.useState)(``),[Te,Ee]=(0,y.useState)(`all`),[De,Oe]=(0,y.useState)(``),[ke,Ae]=(0,y.useState)(()=>localStorage.getItem(`library-sort-field`)||`name`),[je,Me]=(0,y.useState)(()=>localStorage.getItem(`library-sort-direction`)||`asc`),[Ne,Pe]=(0,y.useState)(()=>localStorage.getItem(`library-show-modified`)===`true`),Fe=Up();(0,y.useEffect)(()=>{let e=s.get(`folder`);e&&d(parseInt(e,10))},[s]);let{data:Ie}=K({queryKey:[`settings`],queryFn:()=>Z.getSettings()}),Le=JW(Ie?.open_in_slicer,Ie?.preferred_slicer),Re=(0,y.useCallback)(async t=>{try{let{token:e}=await Z.createLibrarySlicerToken(t.id),n=Z.getLibrarySlicerDownloadUrl(t.id,e,t.filename);ZW(`${window.location.origin}${n}`,Le)}catch{n(e(`fileManager.toast.openInSlicerFailed`),`error`);let r=Z.getLibraryFileDownloadUrl(t.id);ZW(`${window.location.origin}${r}`,Le)}},[Le,n,e]),ze=(0,y.useCallback)(()=>Ie?.use_slicer_api?r(`library:upload`):i(`library:read_all`,`library:read_own`),[Ie?.use_slicer_api,r,i]),{data:Be,isLoading:Ve}=K({queryKey:[`library-folders`],queryFn:()=>Z.getLibraryFolders()}),He=(0,y.useMemo)(()=>{if(!Be)return Be;let e=t=>[...t].sort((e,t)=>{let n=0;if(me===`name`)n=e.name.localeCompare(t.name);else{let r=e.latest_activity_at?new Date(e.latest_activity_at).getTime():null,i=t.latest_activity_at?new Date(t.latest_activity_at).getTime():null;if(r===null&&i===null)n=e.name.localeCompare(t.name);else if(r===null)return 1;else if(i===null)return-1;else n=r-i}return ge===`asc`?n:-n}).map(t=>({...t,children:e(t.children)}));return e(Be)},[Be,me,ge]),{data:Ue}=K({queryKey:[`library-trash-count`],queryFn:async()=>{try{return(await Z.listLibraryTrash(1,0)).total}catch{return 0}},staleTime:3e4}),We=u!==null&&Ce.trim().length>0,Ge=(0,y.useMemo)(()=>[...N].sort((e,t)=>e-t),[N]),{data:Ke=[]}=K({queryKey:[`library-tags`],queryFn:Z.getLibraryTags}),qe=(0,y.useMemo)(()=>{let e=new Map;for(let t of Ke)e.set(t.id,t.name);return e},[Ke]);(0,y.useEffect)(()=>{Ke.length!==0&&P(e=>{let t=e.filter(e=>qe.has(e));return t.length===e.length?e:t})},[Ke.length,qe]);let Je=(0,y.useCallback)(e=>{P(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},[]),{data:Ye,isLoading:Xe}=K({queryKey:[`library-files`,u,f,We,Ge],queryFn:()=>Z.getLibraryFiles(u,!1,void 0,u===null?f:void 0,We,Ge)}),{data:Ze}=K({queryKey:[`library-stats`],queryFn:()=>Z.getLibraryStats()}),{data:Qe}=K({queryKey:[`users`,`slim`],queryFn:()=>Z.getUsersSlim()}),$e=(0,y.useMemo)(()=>{if(!Ye)return[];let e=new Set(Ye.map(e=>e.file_type));return Array.from(e).sort()},[Ye]),et=(0,y.useMemo)(()=>{if(!Ye)return[];let e=[...Ye];if(Ce.trim()){let t=Ce.toLowerCase();e=e.filter(e=>e.filename.toLowerCase().includes(t)||e.print_name&&e.print_name.toLowerCase().includes(t))}if(Te!==`all`&&(e=e.filter(e=>e.file_type===Te)),De.trim()){let t=De.toLowerCase();e=e.filter(e=>e.created_by_username&&e.created_by_username.toLowerCase().includes(t))}return e.sort((e,t)=>{let n=0;switch(ke){case`name`:n=(e.print_name||e.filename).localeCompare(t.print_name||t.filename);break;case`date`:n=(Kf(e.fs_modified_at??e.created_at)?.getTime()??0)-(Kf(t.fs_modified_at??t.created_at)?.getTime()??0);break;case`size`:n=e.file_size-t.file_size;break;case`type`:n=e.file_type.localeCompare(t.file_type);break;case`prints`:n=e.print_count-t.print_count;break}return je===`asc`?n:-n}),e},[Ye,Ce,Te,De,ke,je]),tt=(0,y.useMemo)(()=>{if(!Ze||!Ie)return!1;let e=(Ie.library_disk_warning_gb||5)*1024*1024*1024;return Ze.disk_free_bytesZ.createLibraryFolder(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`library-folders`]}),_(!1),n(e(`fileManager.toast.folderCreated`),`success`)},onError:e=>n(e.message,`error`)}),rt=q({mutationFn:async e=>{let t=await Z.createExternalFolder(e);return await Z.scanExternalFolder(t.id),t},onSuccess:r=>{t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`library-stats`]}),b(!1),d(r.id),n(e(`fileManager.toast.externalFolderLinked`),`success`)},onError:e=>n(e.message,`error`)}),it=q({mutationFn:e=>Z.scanExternalFolder(e),onSuccess:r=>{t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`library-stats`]}),n(e(`fileManager.toast.folderScanned`,{added:r.added,removed:r.removed}),`success`)},onError:e=>n(e.message,`error`)}),at=q({mutationFn:e=>Z.deleteLibraryFolder(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`library-stats`]}),u===L?.id&&d(null),R(null),n(e(`fileManager.toast.folderDeleted`),`success`)},onError:e=>{R(null),n(e.message,`error`)}}),ot=q({mutationFn:e=>Z.deleteLibraryFile(e),onSuccess:()=>{t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`library-stats`]}),t.invalidateQueries({queryKey:[`library-trash-count`]}),h(e=>e.filter(e=>e!==L?.id)),R(null),n(e(`fileManager.toast.fileDeleted`),`success`)},onError:e=>{R(null),n(e.message,`error`)}}),st=q({mutationFn:e=>Z.createVariantGroup(e.map(e=>({library_file_id:e}))),onSuccess:r=>{t.invalidateQueries({queryKey:[`library-files`]}),n(e(`fileManager.variants.grouped`,{count:r.members.length}),`success`),h([])},onError:e=>n(e.message,`error`)}),ct=q({mutationFn:e=>Z.bulkDeleteLibrary(e,[]),onSuccess:(r,i)=>{t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`library-stats`]}),t.invalidateQueries({queryKey:[`library-trash-count`]}),n(e(`fileManager.toast.filesDeleted`,{count:i.length}),`success`),h([]),R(null)},onError:e=>{R(null),n(e.message,`error`)}}),lt=q({mutationFn:({fileIds:e,folderId:t})=>Z.moveLibraryFiles(e,t),onSuccess:()=>{t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`library-folders`]}),h([]),S(!1),n(e(`fileManager.toast.filesMoved`),`success`)},onError:e=>n(e.message,`error`)}),ut=q({mutationFn:({id:e,data:t})=>Z.updateLibraryFolder(e,t),onSuccess:(r,i)=>{t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`project-folders`]}),t.invalidateQueries({queryKey:[`archive-folders`]}),I(null),n(i.data.project_id===0&&i.data.archive_id===0?e(`fileManager.toast.folderUnlinked`):e(`fileManager.toast.folderLinked`),`success`)},onError:e=>n(e.message,`error`)}),dt=q({mutationFn:({id:e,filename:t})=>Z.updateLibraryFile(e,{filename:t}),onSuccess:()=>{t.invalidateQueries({queryKey:[`library-files`]}),ie(null),n(e(`fileManager.toast.fileRenamed`),`success`)},onError:e=>{ie(null),n(e.message,`error`)}}),ft=q({mutationFn:({id:e,name:t})=>Z.updateLibraryFolder(e,{name:t}),onSuccess:()=>{t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`library-files`]}),ie(null),n(e(`fileManager.toast.folderRenamed`),`success`)},onError:e=>{ie(null),n(e.message,`error`)}}),pt=q({mutationFn:()=>Z.batchGenerateStlThumbnails({all_missing:!0}),onSuccess:r=>{if(t.invalidateQueries({queryKey:[`library-files`]}),r.succeeded>0){let e=Date.now(),t={};r.results.forEach(n=>{n.success&&(t[n.file_id]=e)}),oe(e=>({...e,...t}))}r.succeeded>0&&r.failed===0?n(e(`fileManager.toast.thumbnailsGenerated`,{count:r.succeeded}),`success`):r.succeeded>0&&r.failed>0?n(e(`fileManager.toast.thumbnailsGeneratedPartial`,{succeeded:r.succeeded,failed:r.failed}),`success`):r.processed===0?n(e(`fileManager.toast.noStlMissingThumbnails`),`info`):n(e(`fileManager.toast.failedToGenerateThumbnails`,{error:r.results[0]?.error||`Unknown error`}),`error`)},onError:e=>n(e.message,`error`)}),mt=q({mutationFn:e=>Z.batchGenerateStlThumbnails({file_ids:[e]}),onSuccess:r=>{if(t.invalidateQueries({queryKey:[`library-files`]}),r.succeeded>0){let t=r.results[0]?.file_id;t&&oe(e=>({...e,[t]:Date.now()})),n(e(`fileManager.toast.thumbnailGenerated`),`success`)}else n(e(`fileManager.toast.failedToGenerateThumbnail`,{error:r.results[0]?.error||`Unknown error`}),`error`)},onError:e=>n(e.message,`error`)}),ht=(0,y.useCallback)(e=>{let t=e.toLowerCase();return t.endsWith(`.gcode`)||t.includes(`.gcode.`)},[]),gt=(0,y.useMemo)(()=>Ye?Ye.filter(e=>m.includes(e.id)&&ht(e.filename)):[],[Ye,m,ht]),{data:_t}=K({queryKey:[`variant-group`,z?.variant_group_id],queryFn:()=>Z.getVariantGroup(z.variant_group_id),enabled:!!z?.variant_group_id}),vt=(0,y.useMemo)(()=>{if(z){if(gt.length>1)return gt.map(e=>({id:e.id,filename:e.filename,sliced_for_model:e.sliced_for_model}));if(_t&&_t.members.length>1)return _t.members.map(e=>({id:e.library_file_id,filename:e.filename,sliced_for_model:e.target_model}))}},[z,gt,_t]),yt=(0,y.useCallback)(e=>{h(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},[]),bt=(0,y.useCallback)(()=>{et.length>0&&h(et.map(e=>e.id))},[et]),xt=(0,y.useCallback)(()=>{h([])},[]),St=()=>{t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`library-folders`]}),t.invalidateQueries({queryKey:[`library-stats`]})},{isDraggingOver:Ct,dragHandlers:wt}=$W({disabled:!r(`library:upload`)||C,onFiles:e=>{E(e),w(!0)}}),Tt=e=>{Z.downloadLibraryFile(e).catch(e=>{console.error(`Library file download failed:`,e)})},Et=()=>{L&&(L.type===`file`?ot.mutate(L.id):L.type===`folder`?at.mutate(L.id):L.type===`bulk`&&ct.mutate(m))},Dt=at.isPending||ot.isPending||ct.isPending,Ot=e=>{le(e),localStorage.setItem(`library-view-mode`,e)},kt=Ve||Xe,At=(0,y.useMemo)(()=>{if(!u||!Be)return null;let e=t=>{for(let n of t){if(n.id===u)return n;let t=e(n.children);if(t)return t}return null};return e(Be)},[u,Be]);return(0,G.jsxs)(`div`,{className:`p-4 md:p-8 min-h-[calc(100vh-64px)] lg:h-[calc(100vh-64px)] flex flex-col relative`,...wt,children:[Ct&&(0,G.jsx)(`div`,{className:`fixed inset-0 z-50 bg-bambu-dark/90 flex items-center justify-center pointer-events-none`,children:(0,G.jsxs)(`div`,{className:`border-4 border-dashed border-bambu-green rounded-xl p-12 text-center`,children:[(0,G.jsx)(Ru,{className:`w-16 h-16 mx-auto mb-4 text-bambu-green`}),(0,G.jsx)(`p`,{className:`text-2xl font-semibold text-white mb-2`,children:e(`fileManager.dropFilesHere`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray`,children:e(`fileManager.releaseToUpload`)})]})}),(0,G.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between gap-4 mb-6`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,G.jsx)(hc,{className:`w-7 h-7 text-bambu-green`}),e(`fileManager.title`)]}),(0,G.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:e(`fileManager.subtitle`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center bg-bambu-dark rounded-lg p-1`,children:[(0,G.jsx)(`button`,{onClick:()=>Ot(`grid`),className:`p-1.5 rounded transition-colors ${ce===`grid`?`bg-bambu-dark-secondary text-white`:`text-bambu-gray hover:text-white`}`,title:e(`fileManager.gridView`),children:(0,G.jsx)(Kc,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:()=>Ot(`list`),className:`p-1.5 rounded transition-colors ${ce===`list`?`bg-bambu-dark-secondary text-white`:`text-bambu-gray hover:text-white`}`,title:e(`fileManager.listView`),children:(0,G.jsx)(Qc,{className:`w-4 h-4`})})]}),(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>pt.mutate(),disabled:pt.isPending||!i(`library:update_own`,`library:update_all`),title:i(`library:update_own`,`library:update_all`)?e(`fileManager.generateThumbnailsForMissing`):e(`fileManager.noPermissionGenerateThumbnail`),children:[pt.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 mr-2 animate-spin`}):(0,G.jsx)(zc,{className:`w-4 h-4 mr-2`}),e(`fileManager.generateThumbnails`)]}),(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>b(!0),disabled:!r(`library:upload`),title:r(`library:upload`)?e(`fileManager.linkExternalFolder`):e(`fileManager.noPermissionCreateFolder`),children:[(0,G.jsx)(_c,{className:`w-4 h-4 mr-2`}),e(`fileManager.linkExternal`)]}),(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>_(!0),disabled:!r(`library:upload`),title:r(`library:upload`)?void 0:e(`fileManager.noPermissionCreateFolder`),children:[(0,G.jsx)(gc,{className:`w-4 h-4 mr-2`}),e(`fileManager.newFolder`)]}),(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>A(!0),title:e(`fileManager.tags.manageTitle`),children:[(0,G.jsx)(Cu,{className:`w-4 h-4 mr-2`}),e(`fileManager.tags.manage`)]}),r(`library:purge`)&&(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>O(!0),title:e(`libraryPurge.headerTooltip`),children:[(0,G.jsx)(ju,{className:`w-4 h-4 mr-2`}),e(`libraryPurge.headerButton`)]}),i(`library:delete_own`,`library:delete_all`)&&(0,G.jsxs)(ki,{to:`/files/trash`,className:`inline-flex items-center px-3 py-1.5 text-sm rounded bg-bambu-dark-secondary text-bambu-gray hover:text-white hover:bg-bambu-dark transition-colors`,title:e(`libraryTrash.headerTooltip`),children:[(0,G.jsx)(ju,{className:`w-4 h-4 mr-2`}),e(`libraryTrash.headerButton`),typeof Ue==`number`&&Ue>0&&(0,G.jsx)(`span`,{className:`ml-1.5 px-1.5 py-0.5 text-xs rounded-full bg-bambu-green/20 text-bambu-green`,children:Ue})]}),(0,G.jsxs)(Q,{onClick:()=>w(!0),disabled:!r(`library:upload`),title:r(`library:upload`)?void 0:e(`fileManager.noPermissionUpload`),children:[(0,G.jsx)(Ru,{className:`w-4 h-4 mr-2`}),e(`common.upload`)]})]})]}),tt&&Ze&&Ie&&(0,G.jsxs)(`div`,{className:`flex items-center gap-3 mb-4 p-3 bg-amber-500/10 border border-amber-500/30 rounded-lg`,children:[(0,G.jsx)(Pu,{className:`w-5 h-5 text-amber-500 flex-shrink-0`}),(0,G.jsxs)(`div`,{className:`flex-1`,children:[(0,G.jsx)(`p`,{className:`text-sm text-amber-500 font-medium`,children:e(`fileManager.lowDiskSpaceWarning`)}),(0,G.jsx)(`p`,{className:`text-xs text-amber-500/80`,children:e(`fileManager.lowDiskSpaceDetails`,{free:Rd(Ze.disk_free_bytes),total:Rd(Ze.disk_total_bytes),threshold:Ie.library_disk_warning_gb})})]})]}),Ze&&(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 sm:gap-6 mb-6 p-3 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,G.jsx)(uc,{className:`w-4 h-4 text-bambu-green`}),(0,G.jsxs)(`span`,{className:`text-bambu-gray`,children:[e(`fileManager.files`),`:`]}),(0,G.jsx)(`span`,{className:`text-white font-medium`,children:Ze.total_files})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,G.jsx)(hc,{className:`w-4 h-4 text-blue-600 dark:text-blue-400`}),(0,G.jsxs)(`span`,{className:`text-bambu-gray`,children:[e(`fileManager.folders`),`:`]}),(0,G.jsx)(`span`,{className:`text-white font-medium`,children:Ze.total_folders})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,G.jsx)(jc,{className:`w-4 h-4 text-amber-600 dark:text-amber-400`}),(0,G.jsxs)(`span`,{className:`text-bambu-gray`,children:[e(`fileManager.size`),`:`]}),(0,G.jsx)(`span`,{className:`text-white font-medium`,children:Rd(Ze.total_size_bytes)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm sm:ml-auto`,children:[(0,G.jsxs)(`span`,{className:`text-bambu-gray`,children:[e(`fileManager.free`),`:`]}),(0,G.jsx)(`span`,{className:`font-medium ${tt?`text-amber-500`:`text-white`}`,children:Rd(Ze.disk_free_bytes)})]})]}),(0,G.jsxs)(`div`,{className:`flex-1 flex flex-col lg:flex-row gap-4 lg:gap-6 min-h-0`,children:[(0,G.jsx)(`div`,{className:`lg:hidden`,children:(0,G.jsxs)(`select`,{value:u===null?`__top:${f}`:String(u),onChange:e=>{let t=e.target.value;t.startsWith(`__top:`)?(d(null),p(t.slice(6))):d(parseInt(t,10))},className:`w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg px-3 py-2.5 text-white focus:outline-none focus:border-bambu-green`,children:[(0,G.jsxs)(`option`,{value:`__top:internal`,children:[`📁 `,e(`fileManager.allFiles`)]}),Be?.some(e=>e.is_external)&&(0,G.jsxs)(`option`,{value:`__top:external`,children:[`🔗 `,e(`fileManager.allExternal`)]}),He&&(()=>{let e=(t,n=0)=>{let r=[];for(let i of t)r.push({id:i.id,name:i.name,fileCount:i.file_count,depth:n}),i.children.length>0&&r.push(...e(i.children,n+1));return r};return e(He).map(e=>(0,G.jsxs)(`option`,{value:e.id,children:[`│ `.repeat(e.depth),`📂 `,e.name,` `,e.fileCount>0?`(${e.fileCount})`:``]},e.id))})()]})}),(0,G.jsxs)(`div`,{ref:Se,className:`hidden lg:flex flex-shrink-0 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary overflow-hidden flex-col relative`,style:{width:`${ve}px`},children:[(0,G.jsx)(`div`,{className:`absolute right-0 top-0 bottom-0 w-1.5 cursor-col-resize z-10 group/resize flex items-center justify-center transition-colors ${be?`bg-bambu-green`:`hover:bg-bambu-green/50`}`,onMouseDown:e=>{e.preventDefault(),xe(!0)},onDoubleClick:()=>{ye(256),localStorage.setItem(`library-sidebar-width`,`256`)},title:e(`fileManager.dragToResizeTooltip`),children:(0,G.jsxs)(`div`,{className:`flex flex-col gap-1 opacity-0 group-hover/resize:opacity-100 transition-opacity ${be?`opacity-100`:``}`,children:[(0,G.jsx)(`div`,{className:`w-0.5 h-0.5 rounded-full bg-white/70`}),(0,G.jsx)(`div`,{className:`w-0.5 h-0.5 rounded-full bg-white/70`}),(0,G.jsx)(`div`,{className:`w-0.5 h-0.5 rounded-full bg-white/70`})]})}),(0,G.jsxs)(`div`,{className:`p-3 border-b border-bambu-dark-tertiary flex items-center justify-between`,children:[(0,G.jsx)(`h2`,{className:`text-sm font-medium text-white`,children:e(`fileManager.folders`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,G.jsxs)(`select`,{value:me,onChange:e=>{let t=e.target.value===`activity`?`activity`:`name`;he(t),localStorage.setItem(`library-folder-sort-field`,t)},className:`text-xs px-1 py-0.5 rounded bg-bambu-dark border border-bambu-dark-tertiary text-bambu-gray focus:outline-none focus:border-bambu-green`,title:e(`fileManager.folderSort`),"aria-label":e(`fileManager.folderSort`),children:[(0,G.jsx)(`option`,{value:`name`,children:e(`fileManager.folderSortByName`)}),(0,G.jsx)(`option`,{value:`activity`,children:e(`fileManager.folderSortByActivity`)})]}),(0,G.jsx)(`button`,{onClick:()=>{let e=ge===`asc`?`desc`:`asc`;_e(e),localStorage.setItem(`library-folder-sort-direction`,e)},className:`text-bambu-gray hover:text-white hover:bg-bambu-dark p-1 rounded transition-colors`,title:e(ge===`asc`?`fileManager.ascending`:`fileManager.descending`),"aria-label":e(ge===`asc`?`fileManager.ascending`:`fileManager.descending`),children:ge===`asc`?(0,G.jsx)(Bo,{className:`w-3.5 h-3.5`}):(0,G.jsx)(Po,{className:`w-3.5 h-3.5`})}),(0,G.jsx)(`button`,{onClick:()=>{let e=!fe;pe(e),localStorage.setItem(`library-collapse-folders`,String(e))},className:`text-xs px-1.5 py-0.5 rounded transition-colors ${fe?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:text-white hover:bg-bambu-dark`}`,title:e(fe?`fileManager.expandFoldersByDefault`:`fileManager.collapseFoldersByDefault`),children:e(`fileManager.collapse`)}),(0,G.jsx)(`button`,{onClick:()=>{let e=!ue;de(e),localStorage.setItem(`library-wrap-folders`,String(e))},className:`text-xs px-1.5 py-0.5 rounded transition-colors ${ue?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:text-white hover:bg-bambu-dark`}`,title:e(ue?`fileManager.disableTextWrapping`:`fileManager.enableTextWrapping`),children:e(`fileManager.wrap`)})]})]}),(0,G.jsxs)(`div`,{className:`flex-1 overflow-y-auto p-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-1.5 rounded cursor-pointer transition-colors ${u===null&&f===`internal`?`bg-bambu-green/20 text-bambu-green`:`hover:bg-bambu-dark text-white`}`,onClick:()=>{d(null),p(`internal`)},children:[(0,G.jsx)(ac,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`text-sm`,children:e(`fileManager.allFiles`)})]}),Be?.some(e=>e.is_external)&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-1.5 rounded cursor-pointer transition-colors ${u===null&&f===`external`?`bg-bambu-green/20 text-bambu-green`:`hover:bg-bambu-dark text-white`}`,onClick:()=>{d(null),p(`external`)},children:[(0,G.jsx)(_c,{className:`w-4 h-4 text-purple-600 dark:text-purple-400`}),(0,G.jsx)(`span`,{className:`text-sm`,children:e(`fileManager.allExternal`)})]}),He?.map(t=>(0,G.jsx)(nZe,{folder:t,selectedFolderId:u,onSelect:d,onDelete:e=>R({type:`folder`,id:e}),onLink:I,onRename:e=>ie({type:`folder`,id:e.id,name:e.name}),wrapNames:ue,defaultExpanded:!fe,showModified:Ne,hasPermission:r,t:e},`${t.id}-${fe?`c`:`e`}`))]})]}),(0,G.jsxs)(`div`,{className:`flex-1 flex flex-col lg:flex-row min-w-0 min-h-0 gap-4 lg:gap-6`,children:[(0,G.jsxs)(`div`,{className:`flex-1 flex flex-col min-w-0 min-h-0`,children:[Ke.length>0&&(0,G.jsxs)(`div`,{className:`mb-3 flex flex-wrap items-center gap-2 p-2 sm:p-3 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary`,children:[(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray font-medium shrink-0`,children:e(`fileManager.tags.filterLabel`)}),Ke.map(e=>{let t=N.includes(e.id);return(0,G.jsxs)(`button`,{type:`button`,onClick:()=>Je(e.id),className:t?`inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs bg-bambu-green/20 text-bambu-green border border-bambu-green/40 hover:bg-bambu-green/30 transition-colors`:`inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs bg-bambu-dark text-bambu-gray border border-bambu-dark-tertiary hover:text-white hover:border-bambu-green/40 transition-colors`,title:e.name,children:[(0,G.jsx)(Cu,{className:`w-3 h-3`}),(0,G.jsx)(`span`,{children:e.name}),t&&(0,G.jsx)($u,{className:`w-3 h-3`})]},e.id)}),N.length>0&&(0,G.jsx)(`button`,{type:`button`,onClick:()=>P([]),className:`ml-auto text-xs text-bambu-gray hover:text-white shrink-0`,children:e(`fileManager.tags.clearAll`)})]}),At?.is_external&&(0,G.jsxs)(`div`,{className:`flex items-center gap-3 mb-4 p-3 bg-purple-50 dark:bg-purple-500/10 border border-purple-300 dark:border-purple-500/30 rounded-lg`,children:[(0,G.jsx)(_c,{className:`w-5 h-5 text-purple-600 dark:text-purple-400 flex-shrink-0`}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-sm font-medium text-purple-700 dark:text-purple-300`,children:e(`fileManager.externalFolder`)}),At.external_readonly&&(0,G.jsxs)(`span`,{className:`text-xs px-1.5 py-0.5 rounded bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-400 flex items-center gap-1`,children:[(0,G.jsx)(el,{className:`w-3 h-3`}),e(`fileManager.readOnly`)]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray truncate font-mono`,title:At.external_path||``,children:At.external_path})]}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:()=>u&&it.mutate(u),disabled:it.isPending,title:e(`fileManager.scanFolder`),children:[it.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(zl,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`ml-1.5`,children:e(`fileManager.scanFolder`)})]})]}),Ye&&Ye.length>0&&(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 sm:gap-3 mb-4 p-2 sm:p-3 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary sticky top-0 z-10 lg:static`,children:[(0,G.jsxs)(`div`,{className:`relative w-full sm:w-auto sm:flex-1 sm:max-w-xs`,children:[(0,G.jsx)(Yl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,G.jsx)(`input`,{type:`text`,placeholder:e(`fileManager.searchFiles`),value:Ce,onChange:e=>we(e.target.value),className:`w-full pl-9 pr-3 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green`}),We&&(0,G.jsx)(`span`,{className:`absolute -bottom-4 left-0 text-[10px] text-bambu-gray whitespace-nowrap`,title:e(`fileManager.searchSubfoldersHint`),children:e(`fileManager.searchSubfoldersHint`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(xc,{className:`w-4 h-4 text-bambu-gray hidden sm:block`}),(0,G.jsxs)(`select`,{value:Te,onChange:e=>Ee(e.target.value),className:`bg-bambu-dark border border-bambu-dark-tertiary rounded px-2 py-1.5 text-sm text-white focus:outline-none focus:border-bambu-green`,children:[(0,G.jsx)(`option`,{value:`all`,children:e(`fileManager.allTypes`)}),$e.map(e=>(0,G.jsx)(`option`,{value:e,children:e.toUpperCase()},e))]})]}),o&&(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(`input`,{type:`text`,placeholder:e(`fileManager.filterByUser`,{defaultValue:`Filter by user`}),value:De,onChange:e=>Oe(e.target.value),list:`usernames-list`,className:`w-32 sm:w-40 px-2 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-sm text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green ${De?`pr-7`:``}`,style:De?{WebkitAppearance:`none`,MozAppearance:`textfield`}:void 0}),De&&(0,G.jsx)(`button`,{onClick:()=>Oe(``),className:`absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white z-10`,children:(0,G.jsx)($u,{className:`w-3 h-3`})}),(0,G.jsx)(`datalist`,{id:`usernames-list`,children:Qe?.map(e=>(0,G.jsx)(`option`,{value:e.username},e.id))})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`select`,{value:ke,onChange:e=>{let t=e.target.value;Ae(t),localStorage.setItem(`library-sort-field`,t)},className:`bg-bambu-dark border border-bambu-dark-tertiary rounded px-2 py-1.5 text-sm text-white focus:outline-none focus:border-bambu-green`,children:[(0,G.jsx)(`option`,{value:`name`,children:e(`common.name`)}),(0,G.jsx)(`option`,{value:`date`,children:e(`common.date`)}),(0,G.jsx)(`option`,{value:`size`,children:e(`fileManager.size`)}),(0,G.jsx)(`option`,{value:`type`,children:e(`common.type`)}),(0,G.jsx)(`option`,{value:`prints`,children:e(`fileManager.prints`)})]}),(0,G.jsx)(`button`,{onClick:()=>Me(e=>{let t=e===`asc`?`desc`:`asc`;return localStorage.setItem(`library-sort-direction`,t),t}),className:`p-1.5 rounded bg-bambu-dark border border-bambu-dark-tertiary hover:border-bambu-green transition-colors`,title:e(je===`asc`?`fileManager.ascending`:`fileManager.descending`),children:je===`asc`?(0,G.jsx)(Bo,{className:`w-4 h-4 text-white`}):(0,G.jsx)(Po,{className:`w-4 h-4 text-white`})}),(0,G.jsx)(`button`,{onClick:()=>Pe(e=>{let t=!e;return localStorage.setItem(`library-show-modified`,String(t)),t}),className:`p-1.5 rounded bg-bambu-dark border transition-colors ${Ne?`border-bambu-green text-bambu-green`:`border-bambu-dark-tertiary text-white hover:border-bambu-green`}`,title:e(Ne?`fileManager.hideModified`:`fileManager.showModified`),"aria-pressed":Ne,children:(0,G.jsx)(ts,{className:`w-4 h-4`})})]}),(Ce||Te!==`all`||De)&&(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray hidden sm:inline`,children:e(`fileManager.resultsCount`,{showing:et.length,total:Ye.length})})]}),et.length>0&&(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 mb-4 p-2 bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary sticky top-[52px] z-10 lg:static`,children:[m.length===et.length&&m.length>0?(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:xt,children:[(0,G.jsx)(_u,{className:`w-4 h-4 sm:mr-1`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`fileManager.deselectAll`)})]}):(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:bt,children:[(0,G.jsx)(hu,{className:`w-4 h-4 sm:mr-1`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`fileManager.selectAll`)})]}),m.length>0&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray ml-2`,children:e(`fileManager.selected`,{count:m.length})}),(0,G.jsx)(`div`,{className:`hidden sm:block flex-1`}),(0,G.jsxs)(`div`,{className:`w-full sm:w-auto flex flex-wrap items-center gap-2 mt-2 sm:mt-0`,children:[gt.length>=1&&(0,G.jsxs)(Q,{variant:`primary`,size:`sm`,onClick:()=>B(gt[0]),disabled:!r(`queue:create`),title:r(`queue:create`)?void 0:e(`fileManager.noPermissionAddToQueue`),children:[(0,G.jsx)(Fl,{className:`w-4 h-4 sm:mr-1`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:gt.length>1?e(`fileManager.variants.printAlternatives`,{count:gt.length}):e(`common.print`)})]}),gt.length>=2&&!gt.some(e=>e.variant_group_id)&&(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:()=>st.mutate(gt.map(e=>e.id)),disabled:st.isPending||!i(`library:update_own`,`library:update_all`),title:e(`fileManager.variants.groupTooltip`),children:[(0,G.jsx)(Gc,{className:`w-4 h-4 sm:mr-1`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`fileManager.variants.groupAction`)})]}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:()=>S(!0),disabled:!i(`library:update_own`,`library:update_all`),title:i(`library:update_own`,`library:update_all`)?void 0:e(`fileManager.noPermissionMoveFiles`),children:[(0,G.jsx)(gl,{className:`w-4 h-4 sm:mr-1`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.move`)})]}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:()=>M(!0),disabled:!i(`library:update_own`,`library:update_all`),title:i(`library:update_own`,`library:update_all`)?e(`fileManager.tags.bulkTooltip`):e(`fileManager.tags.noPermission`),children:[(0,G.jsx)(Cu,{className:`w-4 h-4 sm:mr-1`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`fileManager.tags.tagAction`)})]}),(0,G.jsxs)(Q,{variant:`danger`,size:`sm`,onClick:()=>{m.length===1?R({type:`file`,id:m[0]}):R({type:`bulk`,id:0,count:m.length})},disabled:!i(`library:delete_own`,`library:delete_all`),title:i(`library:delete_own`,`library:delete_all`)?void 0:e(`fileManager.noPermissionDeleteFiles`),children:[(0,G.jsx)(ju,{className:`w-4 h-4 sm:mr-1`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.delete`)})]}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:xt,children:[(0,G.jsx)($u,{className:`w-4 h-4 sm:mr-1`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:e(`common.clear`)})]})]})]})]}),kt?(0,G.jsx)(`div`,{className:`flex-1 flex items-center justify-center`,children:(0,G.jsxs)(`div`,{className:`flex flex-col items-center gap-3`,children:[(0,G.jsx)(Y,{className:`w-8 h-8 animate-spin text-bambu-green`}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`fileManager.loadingFiles`)})]})}):Ye?.length===0?(0,G.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center`,children:[(0,G.jsx)(`div`,{className:`p-4 bg-bambu-dark rounded-2xl mb-4`,children:(0,G.jsx)(ac,{className:`w-12 h-12 text-bambu-gray/50`})}),(0,G.jsx)(`h3`,{className:`text-lg font-medium text-white mb-2`,children:e(u===null?f===`external`?`fileManager.externalIsEmpty`:`fileManager.noFilesYet`:`fileManager.folderIsEmpty`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-center max-w-md mb-6`,children:e(u===null?f===`external`?`fileManager.externalEmptyDescription`:`fileManager.noFilesDescription`:`fileManager.folderEmptyDescription`)}),(0,G.jsxs)(Q,{onClick:()=>w(!0),disabled:!r(`library:upload`),title:r(`library:upload`)?void 0:e(`fileManager.noPermissionUpload`),children:[(0,G.jsx)(Ml,{className:`w-4 h-4 mr-2`}),e(`fileManager.uploadFiles`)]})]}):et.length===0?(0,G.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center`,children:[(0,G.jsx)(`div`,{className:`p-4 bg-bambu-dark rounded-2xl mb-4`,children:(0,G.jsx)(Yl,{className:`w-12 h-12 text-bambu-gray/50`})}),(0,G.jsx)(`h3`,{className:`text-lg font-medium text-white mb-2`,children:e(`fileManager.noMatchingFiles`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-center max-w-md mb-6`,children:e(`fileManager.noMatchingFilesDescription`)}),(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>{we(``),Ee(`all`)},children:e(`fileManager.clearFilters`)})]}):ce===`grid`?(0,G.jsx)(`div`,{className:`flex-1 lg:overflow-y-auto`,children:(0,G.jsx)(`div`,{className:`grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 2xl:grid-cols-6 gap-4`,children:et.map(t=>(0,G.jsx)(rZe,{file:t,isSelected:m.includes(t.id),isMobile:Fe,t:e,onSelect:yt,onDelete:e=>R({type:`file`,id:e}),onDownload:Tt,onPrint:B,onSlice:ee,onOpenInSlicer:Re,onRunPipeline:ne,useSlicerApi:Ie?.use_slicer_api??!1,canSlice:ze(),onPreview3d:e=>{u9(e.filename)?c(`/gcode-viewer?library_file=${e.id}`):H(e)},onRename:e=>ie({type:`file`,id:e.id,name:e.filename}),onGenerateThumbnail:e=>mt.mutate(e.id),onTagClick:Je,thumbnailVersion:ae[t.id],hasPermission:r,canModify:a,authEnabled:o,showModified:Ne},t.id))})}):(0,G.jsx)(`div`,{className:`flex-1 lg:overflow-y-auto`,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg border border-bambu-dark-tertiary overflow-x-auto`,children:[(0,G.jsxs)(`div`,{className:`hidden sm:grid ${o?`grid-cols-[auto_1fr_120px_100px_100px_100px_minmax(0,200px)_220px]`:`grid-cols-[auto_1fr_100px_100px_100px_minmax(0,200px)_220px]`} gap-4 px-4 py-2 bg-bambu-dark-secondary border-b border-bambu-dark-tertiary text-xs text-bambu-gray font-medium`,children:[(0,G.jsx)(`div`,{className:`w-6`}),(0,G.jsx)(`div`,{children:e(`common.name`)}),o&&(0,G.jsx)(`div`,{children:e(`fileManager.uploadedBy`,{defaultValue:`Uploaded By`})}),(0,G.jsx)(`div`,{children:e(`common.type`)}),(0,G.jsx)(`div`,{children:e(`fileManager.size`)}),(0,G.jsx)(`div`,{children:e(`fileManager.prints`)}),(0,G.jsx)(`div`,{children:e(`fileManager.tags.title`)}),(0,G.jsx)(`div`,{})]}),et.map(t=>(0,G.jsxs)(`div`,{className:`grid ${o?`grid-cols-[auto_1fr_120px_100px_100px_100px_minmax(0,200px)_220px]`:`grid-cols-[auto_1fr_100px_100px_100px_minmax(0,200px)_220px]`} gap-4 px-4 py-3 items-center border-b border-bambu-dark-tertiary last:border-b-0 cursor-pointer hover:bg-bambu-dark/50 transition-colors ${m.includes(t.id)?`bg-bambu-green/10`:``}`,onClick:()=>yt(t.id),children:[(0,G.jsx)(`div`,{className:`w-5 h-5 rounded border-2 flex items-center justify-center ${m.includes(t.id)?`bg-bambu-green border-bambu-green`:`border-bambu-gray/50`}`,children:m.includes(t.id)&&(0,G.jsx)(`div`,{className:`w-2 h-2 bg-white rounded-sm`})}),(0,G.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0`,children:[(0,G.jsxs)(`div`,{className:`relative group/thumb`,children:[(0,G.jsx)(`div`,{className:`w-10 h-10 rounded bg-bambu-dark flex-shrink-0 overflow-hidden`,children:t.thumbnail_path?(0,G.jsx)(`img`,{src:`${Z.getLibraryFileThumbnailUrl(t.id)}${ae[t.id]?(Z.getLibraryFileThumbnailUrl(t.id).includes(`?`)?`&`:`?`)+`v=${ae[t.id]}`:``}`,alt:``,className:`w-full h-full object-cover`}):(0,G.jsx)(`div`,{className:`w-full h-full flex items-center justify-center`,children:(0,G.jsx)(ac,{className:`w-5 h-5 text-bambu-gray/50`})})}),t.thumbnail_path&&(0,G.jsx)(`div`,{className:`absolute left-0 top-full mt-2 z-50 hidden group-hover/thumb:block`,children:(0,G.jsx)(`div`,{className:`w-48 h-48 rounded-lg bg-bambu-dark-secondary border border-bambu-dark-tertiary shadow-xl overflow-hidden`,children:(0,G.jsx)(`img`,{src:`${Z.getLibraryFileThumbnailUrl(t.id)}${ae[t.id]?(Z.getLibraryFileThumbnailUrl(t.id).includes(`?`)?`&`:`?`)+`v=${ae[t.id]}`:``}`,alt:t.filename,className:`w-full h-full object-contain`})})})]}),(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsx)(`div`,{className:`text-sm text-white truncate`,children:t.print_name||t.filename}),Ne&&(0,G.jsxs)(`div`,{className:`text-xs text-bambu-gray flex items-center gap-1 mt-0.5`,title:e(`fileManager.lastModified`),children:[(0,G.jsx)(ts,{className:`w-3 h-3 flex-shrink-0`}),(0,G.jsx)(`span`,{className:`truncate`,children:qf(t.fs_modified_at??t.created_at)})]})]})]}),o&&(0,G.jsx)(`div`,{className:`text-sm text-bambu-gray flex items-center gap-1`,children:t.created_by_username?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(zu,{className:`w-3 h-3`}),(0,G.jsx)(`span`,{className:`truncate`,children:t.created_by_username})]}):`-`}),(0,G.jsx)(`div`,{children:(0,G.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded font-medium ${t.file_type===`3mf`?`bg-bambu-green/20 text-bambu-green`:t.file_type===`gcode`||t.file_type===`gcode.3mf`?`bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400`:t.file_type===`stl`?`bg-purple-100 dark:bg-purple-500/20 text-purple-700 dark:text-purple-400`:`bg-bambu-gray/20 text-bambu-gray`}`,children:t.file_type.toUpperCase()})}),(0,G.jsx)(`div`,{className:`text-sm text-bambu-gray`,children:Rd(t.file_size)}),(0,G.jsx)(`div`,{className:`text-sm text-bambu-gray`,children:t.print_count>0?`${t.print_count}x`:`-`}),(0,G.jsx)(`div`,{className:`min-w-0`,onClick:e=>e.stopPropagation(),children:!t.tags||t.tags.length===0?(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray/50`,children:`-`}):(0,G.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:t.tags.map(e=>(0,G.jsxs)(`button`,{type:`button`,onClick:()=>Je(e.id),className:`inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded-full text-[10px] bg-bambu-green/10 text-bambu-green hover:bg-bambu-green/20 transition-colors max-w-full`,title:e.name,children:[(0,G.jsx)(Cu,{className:`w-2.5 h-2.5 flex-shrink-0`}),(0,G.jsx)(`span`,{className:`truncate`,children:e.name})]},e.id))})}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,onClick:e=>e.stopPropagation(),children:[u9(t.filename)&&(0,G.jsx)(G.Fragment,{children:(0,G.jsx)(`button`,{onClick:()=>r(`queue:create`)&&B(t),className:`p-1.5 rounded transition-colors ${r(`queue:create`)?`hover:bg-bambu-dark text-bambu-gray hover:text-bambu-green`:`text-bambu-gray/50 cursor-not-allowed`}`,title:r(`queue:create`)?e(`common.print`):e(`fileManager.noPermissionAddToQueue`),disabled:!r(`queue:create`),children:(0,G.jsx)(Fl,{className:`w-4 h-4`})})}),XW(t.filename)&&(0,G.jsx)(`button`,{onClick:()=>{ze()&&(Ie?.use_slicer_api?ee:Re)(t)},className:`p-1.5 rounded transition-colors ${ze()?`hover:bg-bambu-dark text-bambu-gray hover:text-bambu-green`:`text-bambu-gray/50 cursor-not-allowed`}`,title:ze()?e(`slice.action`):Ie?.use_slicer_api?e(`fileManager.noPermissionSlice`):e(`fileManager.noPermissionDownload`),disabled:!ze(),children:Ie?.use_slicer_api?(0,G.jsx)(Is,{className:`w-4 h-4`}):(0,G.jsx)(tc,{className:`w-4 h-4`})}),(Ie?.use_slicer_api??!1)&&XW(t.filename)&&(0,G.jsx)(`button`,{onClick:()=>r(`pipelines:run`)&&ne(t),className:`p-1.5 rounded transition-colors ${r(`pipelines:run`)?`hover:bg-bambu-dark text-bambu-gray hover:text-bambu-green`:`text-bambu-gray/50 cursor-not-allowed`}`,title:r(`pipelines:run`)?e(`library.runWithPipeline.actionLabel`,`Run with pipeline`):e(`library.runWithPipeline.noPermission`,`You do not have permission to run pipelines`),disabled:!r(`pipelines:run`),children:(0,G.jsx)(Al,{className:`w-4 h-4`})}),(t.file_type===`3mf`||t.file_type===`gcode`||t.file_type===`gcode.3mf`||t.file_type===`stl`)&&(0,G.jsx)(`button`,{onClick:()=>{r(`library:read`)&&(u9(t.filename)?c(`/gcode-viewer?library_file=${t.id}`):H(t))},className:`p-1.5 rounded transition-colors ${r(`library:read`)?`hover:bg-bambu-dark text-bambu-gray hover:text-bambu-green`:`text-bambu-gray/50 cursor-not-allowed`}`,title:r(`library:read`)?`3D Preview`:`You do not have permission to preview files`,disabled:!r(`library:read`),children:(0,G.jsx)(Yo,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:()=>r(`library:read`)&&Tt(t.id),className:`p-1.5 rounded transition-colors ${r(`library:read`)?`hover:bg-bambu-dark text-bambu-gray hover:text-white`:`text-bambu-gray/50 cursor-not-allowed`}`,title:r(`library:read`)?e(`common.download`):e(`fileManager.noPermissionDownload`),disabled:!r(`library:read`),children:(0,G.jsx)(Js,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:()=>a(`library`,`update`,t.created_by_id)&&ie({type:`file`,id:t.id,name:t.filename}),className:`p-1.5 rounded transition-colors ${a(`library`,`update`,t.created_by_id)?`hover:bg-bambu-dark text-bambu-gray hover:text-white`:`text-bambu-gray/50 cursor-not-allowed`}`,title:a(`library`,`update`,t.created_by_id)?e(`common.rename`):e(`fileManager.noPermissionRenameFile`),disabled:!a(`library`,`update`,t.created_by_id),children:(0,G.jsx)(Ol,{className:`w-4 h-4`})}),t.file_type===`stl`&&(0,G.jsx)(`button`,{onClick:()=>a(`library`,`update`,t.created_by_id)&&mt.mutate(t.id),className:`p-1.5 rounded transition-colors ${a(`library`,`update`,t.created_by_id)?`hover:bg-bambu-dark text-bambu-gray hover:text-bambu-green`:`text-bambu-gray/50 cursor-not-allowed`}`,title:a(`library`,`update`,t.created_by_id)?e(`fileManager.generateThumbnail`):e(`fileManager.noPermissionGenerateThumbnail`),disabled:mt.isPending||!a(`library`,`update`,t.created_by_id),children:(0,G.jsx)(zc,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:()=>a(`library`,`delete`,t.created_by_id)&&R({type:`file`,id:t.id}),className:`p-1.5 rounded transition-colors ${a(`library`,`delete`,t.created_by_id)?`hover:bg-bambu-dark text-bambu-gray hover:text-red-700 dark:hover:text-red-400`:`text-bambu-gray/50 cursor-not-allowed`}`,title:a(`library`,`delete`,t.created_by_id)?e(`common.delete`):e(`fileManager.noPermissionDeleteFile`),disabled:!a(`library`,`delete`,t.created_by_id),children:(0,G.jsx)(ju,{className:`w-4 h-4`})})]})]},t.id))]})})]}),u!==null&&(0,G.jsx)(GXe,{folderId:u})]})]}),g&&(0,G.jsx)(YXe,{parentId:u,onClose:()=>_(!1),onSave:e=>nt.mutate(e),isLoading:nt.isPending,t:e}),v&&(0,G.jsx)(XXe,{onClose:()=>b(!1),onSave:e=>rt.mutate(e),isLoading:rt.isPending,t:e}),x&&Be&&(0,G.jsx)(eZe,{folders:Be,selectedFiles:m,currentFolderId:u,onClose:()=>S(!1),onMove:e=>lt.mutate({fileIds:m,folderId:e}),isLoading:lt.isPending,t:e}),C&&(0,G.jsx)(FU,{folderId:u,onClose:()=>{w(!1),E([])},onUploadComplete:St,initialFiles:T.length>0?T:void 0}),D&&(0,G.jsx)(JXe,{onClose:()=>O(!1)}),(0,G.jsx)(KXe,{open:k,onClose:()=>A(!1),onPickTag:e=>{N.includes(e)||P(t=>[...t,e])}}),(0,G.jsx)(LUe,{open:j,fileIds:m,onClose:()=>M(!1)}),F&&(0,G.jsx)(tZe,{folder:F,onClose:()=>I(null),onLink:e=>ut.mutate({id:F.id,data:e}),isLoading:ut.isPending,t:e}),L&&(0,G.jsx)(Zd,{title:L.type===`folder`?e(`fileManager.deleteFolder`):L.type===`bulk`?e(`fileManager.deleteFilesCount`,{count:L.count}):e(`fileManager.deleteFile`),message:L.type===`folder`?e(`fileManager.deleteFolderConfirm`):L.type===`bulk`?e(`fileManager.deleteFilesConfirm`,{count:L.count}):e(`fileManager.deleteFileConfirm`),confirmText:e(`common.delete`),variant:`danger`,isLoading:Dt,loadingText:e(`fileManager.deleting`),onConfirm:Et,onCancel:()=>R(null)}),z&&(!z.variant_group_id||_t!==void 0)&&(0,G.jsx)($U,{mode:`create`,libraryFileId:vt?.[0]?.id??z.id,variantFiles:vt,archiveName:vt&&vt.length>1?`${vt[0].filename} ${e(`common.plusNMore`,{count:vt.length-1})}`:z.print_name||z.filename,onClose:()=>B(null),onSuccess:()=>{B(null),h([]),t.invalidateQueries({queryKey:[`library-files`]}),t.invalidateQueries({queryKey:[`queue`]}),t.invalidateQueries({queryKey:[`archives`]})}}),V&&(0,G.jsx)(WW,{source:{kind:`libraryFile`,id:V.id,filename:V.filename},onClose:()=>ee(null)}),te&&(0,G.jsx)(qW,{source:{kind:`libraryFile`,id:te.id,filename:te.filename},onClose:()=>ne(null)}),se&&(0,G.jsx)(IUe,{libraryFileId:se.id,title:se.print_name||se.filename,fileType:se.file_type,onClose:()=>H(null),onSliceWithBambuddy:XW(se.filename)&&r(`library:upload`)?()=>{let e=se;H(null),ee(e)}:void 0}),re&&(0,G.jsx)($Xe,{type:re.type,currentName:re.name,onClose:()=>ie(null),onSave:e=>{re.type===`file`?dt.mutate({id:re.id,filename:e}):ft.mutate({id:re.id,name:e})},isLoading:dt.isPending||ft.isPending,t:e})]})}function aZe(e){let t=Kf(e);if(!t)return``;let n=Math.ceil((t.getTime()-Date.now())/(1e3*60*60*24));return n<=0?`any moment`:n===1?`1 day`:`${n} days`}function oZe(e){let t=Kf(e);return t?t.toLocaleString():e}function sZe(){let{t:e}=U(),t=or(),n=so(),{showToast:r}=Bd(),{hasPermission:i,authEnabled:a}=Ed(),[o,s]=(0,y.useState)(null),[c,l]=(0,y.useState)(new Set),u=!a||i(`library:purge`),d=K({queryKey:[`library-trash`],queryFn:()=>Z.listLibraryTrash(200,0)}),f=K({queryKey:[`library-trash-settings`],queryFn:()=>Z.getLibraryTrashSettings(),enabled:u}),[p,m]=(0,y.useState)(null);(0,y.useEffect)(()=>{f.data&&p===null&&m(f.data.retention_days)},[f.data,p]);let h=q({mutationFn:e=>{let t=f.data;return Z.updateLibraryTrashSettings({retention_days:e,auto_purge_enabled:t?.auto_purge_enabled??!1,auto_purge_days:t?.auto_purge_days??90,auto_purge_include_never_printed:t?.auto_purge_include_never_printed??!0})},onSuccess:t=>{r(e(`libraryTrash.toast.retentionSaved`,{days:t.retention_days}),`success`),n.invalidateQueries({queryKey:[`library-trash-settings`]}),n.invalidateQueries({queryKey:[`library-trash`]})},onError:t=>r(t.message||e(`libraryTrash.toast.retentionFailed`),`error`)}),g=q({mutationFn:e=>Z.restoreLibraryTrash(e),onSuccess:()=>{r(e(`libraryTrash.toast.restored`),`success`),n.invalidateQueries({queryKey:[`library-trash`]}),n.invalidateQueries({queryKey:[`library-trash-count`]}),n.invalidateQueries({queryKey:[`library-files`]}),n.invalidateQueries({queryKey:[`library-folders`]})},onError:t=>r(t.message||e(`libraryTrash.toast.restoreFailed`),`error`)}),_=q({mutationFn:e=>Z.hardDeleteLibraryTrash(e),onSuccess:()=>{r(e(`libraryTrash.toast.purged`),`success`),n.invalidateQueries({queryKey:[`library-trash`]}),n.invalidateQueries({queryKey:[`library-trash-count`]})},onError:t=>r(t.message||e(`libraryTrash.toast.purgeFailed`),`error`)}),v=q({mutationFn:()=>Z.emptyLibraryTrash(),onSuccess:t=>{r(e(`libraryTrash.toast.emptied`,{count:t.deleted}),`success`),n.invalidateQueries({queryKey:[`library-trash`]}),n.invalidateQueries({queryKey:[`library-trash-count`]})},onError:t=>r(t.message||e(`libraryTrash.toast.emptyFailed`),`error`)}),b=q({mutationFn:e=>Promise.all(e.map(e=>Z.restoreLibraryTrash(e))),onSuccess:(t,i)=>{r(e(`libraryTrash.toast.bulkRestored`,{count:i.length}),`success`),l(new Set),n.invalidateQueries({queryKey:[`library-trash`]}),n.invalidateQueries({queryKey:[`library-trash-count`]}),n.invalidateQueries({queryKey:[`library-files`]}),n.invalidateQueries({queryKey:[`library-folders`]})},onError:t=>r(t.message||e(`libraryTrash.toast.restoreFailed`),`error`)}),x=q({mutationFn:e=>Promise.all(e.map(e=>Z.hardDeleteLibraryTrash(e))),onSuccess:(t,i)=>{r(e(`libraryTrash.toast.bulkPurged`,{count:i.length}),`success`),l(new Set),n.invalidateQueries({queryKey:[`library-trash`]}),n.invalidateQueries({queryKey:[`library-trash-count`]})},onError:t=>r(t.message||e(`libraryTrash.toast.purgeFailed`),`error`)}),S=(0,y.useMemo)(()=>d.data?.items??[],[d.data?.items]),C=d.data?.retention_days??30,w=(0,y.useMemo)(()=>S.reduce((e,t)=>e+t.file_size,0),[S]),T=S.length>0&&S.every(e=>c.has(e.id)),E=c.size>0&&!T,D=e=>{l(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})};return(0,G.jsxs)(`div`,{className:`p-6 max-w-screen-2xl mx-auto`,children:[(0,G.jsx)(`div`,{className:`flex items-center gap-3 mb-4`,children:(0,G.jsxs)(ki,{to:`/files`,className:`inline-flex items-center gap-1 text-sm text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-gray-200`,children:[(0,G.jsx)(Io,{className:`w-4 h-4`}),` `,e(`libraryTrash.backToFiles`)]})}),(0,G.jsxs)(`div`,{className:`flex items-start justify-between mb-6 gap-4 flex-wrap`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h1`,{className:`text-2xl font-bold text-gray-900 dark:text-gray-100`,children:e(`libraryTrash.title`)}),(0,G.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400 mt-1`,children:e(u?`libraryTrash.subtitleAdmin`:`libraryTrash.subtitleUser`,{days:C})})]}),S.length>0&&(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>s({type:`empty`}),className:`text-red-600 dark:text-red-400`,children:[(0,G.jsx)(ju,{className:`w-4 h-4 mr-1`}),e(`libraryTrash.emptyTrash`)]})]}),u&&f.data&&(0,G.jsxs)(`div`,{className:`mb-4 border border-gray-200 dark:border-gray-700 rounded-lg p-3 flex items-center gap-3 bg-gray-50 dark:bg-gray-800/40`,children:[(0,G.jsx)(`label`,{htmlFor:`retention-days`,className:`text-sm font-medium text-gray-700 dark:text-gray-300`,children:e(`libraryTrash.retentionLabel`)}),(0,G.jsx)(`input`,{id:`retention-days`,type:`number`,min:1,max:365,value:p??f.data.retention_days,onChange:e=>m(Math.max(1,Math.min(365,parseInt(e.target.value||`0`,10)||0))),className:`w-20 rounded border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-800 text-sm px-2 py-1 text-gray-900 dark:text-gray-100`}),(0,G.jsx)(`span`,{className:`text-sm text-gray-600 dark:text-gray-400`,children:e(`libraryTrash.days`)}),(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>p!=null&&h.mutate(p),disabled:h.isPending||p==null||p===f.data.retention_days,className:`ml-auto`,children:[(0,G.jsx)(Wl,{className:`w-4 h-4 mr-1`}),e(`common.save`)]})]}),d.isLoading?(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-gray-500 dark:text-gray-400`,children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),` `,e(`libraryTrash.loading`)]}):S.length===0?(0,G.jsx)(`div`,{className:`border border-dashed border-gray-300 dark:border-gray-700 rounded-lg p-12 text-center`,children:(0,G.jsx)(`p`,{className:`text-gray-500 dark:text-gray-400`,children:e(`libraryTrash.empty`)})}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,G.jsx)(`div`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:e(`libraryTrash.summary`,{count:S.length,size:Rd(w)})}),c.size>0&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,G.jsx)(`span`,{className:`text-gray-600 dark:text-gray-400`,children:e(`libraryTrash.selectionCount`,{count:c.size})}),(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>b.mutate(Array.from(c)),disabled:b.isPending,children:[(0,G.jsx)(Vl,{className:`w-4 h-4 mr-1`}),e(`libraryTrash.bulkRestore`)]}),(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>s({type:`bulkDelete`,count:c.size}),disabled:x.isPending,className:`text-red-600 dark:text-red-400`,children:[(0,G.jsx)(ju,{className:`w-4 h-4 mr-1`}),e(`libraryTrash.bulkPurge`)]})]})]}),(0,G.jsx)(`div`,{className:`border border-gray-200 dark:border-gray-700 rounded-lg overflow-x-auto`,children:(0,G.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,G.jsx)(`thead`,{className:`bg-gray-50 dark:bg-gray-800 text-left text-gray-600 dark:text-gray-300`,children:(0,G.jsxs)(`tr`,{children:[(0,G.jsx)(`th`,{className:`px-3 py-2 w-10`,children:(0,G.jsx)(`input`,{type:`checkbox`,checked:T,ref:e=>{e&&(e.indeterminate=E)},onChange:()=>{l(e=>e.size===S.length?new Set:new Set(S.map(e=>e.id)))},"aria-label":e(`libraryTrash.selectAll`),className:`rounded border-gray-300 cursor-pointer`})}),(0,G.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:e(`libraryTrash.col.filename`)}),(0,G.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:e(`libraryTrash.col.folder`)}),(0,G.jsx)(`th`,{className:`px-3 py-2 font-medium text-right`,children:e(`libraryTrash.col.size`)}),(0,G.jsx)(`th`,{className:`px-3 py-2 font-medium whitespace-nowrap`,children:e(`libraryTrash.col.deleted`)}),(0,G.jsx)(`th`,{className:`px-3 py-2 font-medium whitespace-nowrap`,children:e(`libraryTrash.col.autoPurge`)}),u&&(0,G.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:e(`libraryTrash.col.owner`)}),(0,G.jsx)(`th`,{className:`px-3 py-2 font-medium text-right`,children:e(`libraryTrash.col.actions`)})]})}),(0,G.jsx)(`tbody`,{className:`divide-y divide-gray-100 dark:divide-gray-800`,children:S.map(t=>(0,G.jsxs)(`tr`,{className:`hover:bg-gray-50 dark:hover:bg-gray-800/50`,children:[(0,G.jsx)(`td`,{className:`px-3 py-2`,children:(0,G.jsx)(`input`,{type:`checkbox`,checked:c.has(t.id),onChange:()=>D(t.id),"aria-label":e(`libraryTrash.selectOne`,{filename:t.filename}),className:`rounded border-gray-300 cursor-pointer`})}),(0,G.jsx)(`td`,{className:`px-3 py-2 text-gray-900 dark:text-gray-100 truncate max-w-md`,title:t.filename,children:t.filename}),(0,G.jsx)(`td`,{className:`px-3 py-2 text-gray-600 dark:text-gray-400`,children:t.folder_name??`—`}),(0,G.jsx)(`td`,{className:`px-3 py-2 text-right text-gray-600 dark:text-gray-400 tabular-nums whitespace-nowrap`,children:Rd(t.file_size)}),(0,G.jsx)(`td`,{className:`px-3 py-2 text-gray-600 dark:text-gray-400 whitespace-nowrap`,children:oZe(t.deleted_at)}),(0,G.jsx)(`td`,{className:`px-3 py-2 text-gray-600 dark:text-gray-400 whitespace-nowrap`,children:(0,G.jsx)(`span`,{title:oZe(t.auto_purge_at),children:e(`libraryTrash.autoPurgeIn`,{when:aZe(t.auto_purge_at)})})}),u&&(0,G.jsx)(`td`,{className:`px-3 py-2 text-gray-600 dark:text-gray-400`,children:t.created_by_username??`—`}),(0,G.jsxs)(`td`,{className:`px-3 py-2 text-right whitespace-nowrap`,children:[(0,G.jsxs)(`button`,{onClick:()=>g.mutate(t.id),disabled:g.isPending,className:`inline-flex items-center gap-1 px-2 py-1 text-xs text-blue-600 hover:text-blue-800 dark:text-blue-400 dark:hover:text-blue-300`,children:[(0,G.jsx)(Vl,{className:`w-3.5 h-3.5`}),e(`libraryTrash.restore`)]}),(0,G.jsxs)(`button`,{onClick:()=>s({type:`delete`,id:t.id,filename:t.filename}),disabled:_.isPending,className:`inline-flex items-center gap-1 px-2 py-1 text-xs text-red-600 hover:text-red-800 dark:text-red-400 dark:hover:text-red-300 ml-2`,children:[(0,G.jsx)(ju,{className:`w-3.5 h-3.5`}),e(`libraryTrash.purgeNow`)]})]})]},t.id))})]})})]}),o&&(0,G.jsx)(Zd,{onCancel:()=>s(null),onConfirm:()=>{o&&(o.type===`delete`?_.mutate(o.id):o.type===`bulkDelete`?x.mutate(Array.from(c)):v.mutate(),s(null))},title:o.type===`delete`?e(`libraryTrash.confirm.purgeTitle`):o.type===`bulkDelete`?e(`libraryTrash.confirm.bulkPurgeTitle`):e(`libraryTrash.confirm.emptyTitle`),message:o.type===`delete`?e(`libraryTrash.confirm.purgeBody`,{filename:o.filename}):o.type===`bulkDelete`?e(`libraryTrash.confirm.bulkPurgeBody`,{count:o.count}):e(`libraryTrash.confirm.emptyBody`,{count:S.length}),confirmText:e(`libraryTrash.confirm.cta`),variant:`danger`}),d.isError&&(0,G.jsxs)(`div`,{className:`mt-4 text-sm text-red-600 dark:text-red-400`,children:[d.error?.message??e(`libraryTrash.loadError`),(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>t(`/files`),className:`ml-3`,children:e(`libraryTrash.backToFiles`)})]})]})}function cZe(e,t){let n=`token=${encodeURIComponent(t)}`,r=0;return e.querySelectorAll(`img[src*="/api/v1/"], video[src*="/api/v1/"]`).forEach(e=>{let t=e.getAttribute(`src`)||``;if(t.includes(n))return;let i=t.replace(/([?&])token=[^&]*(&|$)/,(e,t,n)=>n===`&`?t:``);e.src=`${i}${i.includes(`?`)?`&`:`?`}${n}`,r+=1}),r}function lZe(){let{authEnabled:e,user:t,loading:n}=Ed(),r=so(),i=(0,y.useRef)(!1),{data:a}=K({queryKey:[`camera-stream-token`,t?.id??null],queryFn:()=>Z.getCameraStreamToken(),enabled:!n&&(!e||t!==null),staleTime:3e3*1e3,refetchInterval:3e3*1e3});(0,y.useEffect)(()=>{let e=a?.token??null;return ld(e),e&&cZe(document,e),()=>ld(null)},[a?.token]),(0,y.useEffect)(()=>{if(!e)return;let t=e=>{let t=e.target;if(!(t instanceof HTMLImageElement||t instanceof HTMLVideoElement))return;let n=t.src||``,a=ud();!a||!n.includes(`token=${encodeURIComponent(a)}`)||i.current||(i.current=!0,r.invalidateQueries({queryKey:[`camera-stream-token`]}),setTimeout(()=>{i.current=!1},5e3))};return document.addEventListener(`error`,t,!0),()=>document.removeEventListener(`error`,t,!0)},[e,r])}var d9=5,uZe=2e3,dZe=3e4,fZe=5e3;function pZe(){let{t:e}=U(),t=so(),{showToast:n}=Bd(),{hasPermission:r,authEnabled:i,user:a}=Ed(),{printerId:o}=dr(),s=parseInt(o||`0`,10),[c]=Li(),l=parseInt(c.get(`fps`)||`15`,10),u=Math.min(Math.max(isNaN(l)?15:l,1),30);lZe();let{data:d,isPending:f}=K({queryKey:[`camera-stream-token`,a?.id??null],queryFn:()=>Z.getCameraStreamToken(),enabled:i?!!a:!0,staleTime:3e3*1e3}),p=d?.token??ud(),[m,h]=(0,y.useState)(`stream`),[g,_]=(0,y.useState)(!1),[v,b]=(0,y.useState)(!1),[x,S]=(0,y.useState)(!1),[C,w]=(0,y.useState)(!0),[T,E]=(0,y.useState)(Date.now()),[D,O]=(0,y.useState)(!1),[k,A]=(0,y.useState)(!1),[j,M]=(0,y.useState)(0),[N,P]=(0,y.useState)(!1),[F,I]=(0,y.useState)(0),[L,R]=(0,y.useState)(1),[z,B]=(0,y.useState)({x:0,y:0}),[V,ee]=(0,y.useState)(!1),[te,ne]=(0,y.useState)({x:0,y:0}),[re,ie]=(0,y.useState)(null),[ae,oe]=(0,y.useState)(null),se=(0,y.useRef)(null),H=(0,y.useRef)(null),ce=(0,y.useRef)(null),le=(0,y.useRef)(null),ue=(0,y.useRef)(null),de=(0,y.useRef)(0),{data:fe}=K({queryKey:[`printer`,s],queryFn:()=>Z.getPrinter(s),enabled:s>0}),{data:pe}=K({queryKey:[`printerStatus`,s],queryFn:()=>Z.getPrinterStatus(s),refetchInterval:3e4,enabled:s>0}),me=q({mutationFn:e=>Z.setChamberLight(s,e),onMutate:async e=>{await t.cancelQueries({queryKey:[`printerStatus`,s]});let n=t.getQueryData([`printerStatus`,s]);return t.setQueryData([`printerStatus`,s],t=>({...t,chamber_light:e})),{previousStatus:n}},onSuccess:(e,t)=>{n(`Chamber light ${t?`on`:`off`}`)},onError:(r,i,a)=>{a?.previousStatus&&t.setQueryData([`printerStatus`,s],a.previousStatus),n(r.message||e(`printers.toast.failedToControlChamberLight`),`error`)}}),he=(pe?.state===`RUNNING`||pe?.state===`PAUSE`)&&(pe?.printable_objects_count??0)>=2;(0,y.useEffect)(()=>(fe&&(document.title=`${fe.name} - Camera`),()=>{document.title=`Bambuddy`}),[fe]);let ge=(0,y.useRef)(!1);(0,y.useEffect)(()=>{let e=`/api/v1/printers/${s}/camera/stop`;ge.current=!1;let t=()=>{if(s>0&&!ge.current){ge.current=!0;let t={},n=sd();n&&(t.Authorization=`Bearer ${n}`),fetch(e,{method:`POST`,keepalive:!0,headers:t}).catch(()=>{})}},n=()=>{t()};window.addEventListener(`beforeunload`,n);let r=se.current;return()=>{window.removeEventListener(`beforeunload`,n),r&&(r.src=``),t()}},[s]),(0,y.useEffect)(()=>{if(C&&!D){let e=setTimeout(()=>{w(!1)},m===`stream`?3e3:2e4);return()=>clearTimeout(e)}},[m,C,T,D]),(0,y.useEffect)(()=>{let e=()=>{A(!!document.fullscreenElement),R(1),B({x:0,y:0}),m===`stream`&&!D&&(se.current&&(se.current.src=``),setTimeout(()=>{w(!0),E(Date.now())},200))};return document.addEventListener(`fullscreenchange`,e),()=>document.removeEventListener(`fullscreenchange`,e)},[m,D]),(0,y.useEffect)(()=>{let e,t=()=>{clearTimeout(e),e=setTimeout(()=>{localStorage.setItem(`cameraWindowState`,JSON.stringify({width:window.outerWidth,height:window.outerHeight,left:window.screenX,top:window.screenY}))},500)};return window.addEventListener(`resize`,t),()=>{clearTimeout(e),window.removeEventListener(`resize`,t)}},[]),(0,y.useEffect)(()=>()=>{ce.current&&clearTimeout(ce.current),le.current&&clearInterval(le.current),ue.current&&clearInterval(ue.current)},[]);let _e=(0,y.useCallback)(()=>{if(j>=d9){P(!1),S(!0);return}let e=Math.min(uZe*2**j,dZe);P(!0),I(Math.ceil(e/1e3)),le.current=setInterval(()=>{I(e=>e<=1?(le.current&&clearInterval(le.current),0):e-1)},1e3),ce.current=setTimeout(()=>{M(e=>e+1),P(!1),w(!0),S(!1),se.current&&(se.current.src=``),E(Date.now())},e)},[j]);(0,y.useEffect)(()=>{if(m!==`stream`||C||N||D){ue.current&&=(clearInterval(ue.current),null);return}return de.current=0,ue.current=setInterval(async()=>{try{let e=await Z.getCameraStatus(s);if(!(e.stalled||!e.active&&!x)){de.current=0;return}if(de.current+=1,de.current<2)return;de.current=0,console.log(`Stream issue detected: stalled=${e.stalled}, active=${e.active}, reconnecting...`),ue.current&&=(clearInterval(ue.current),null),w(!1),_e()}catch{}},fZe),()=>{ue.current&&=(clearInterval(ue.current),null)}},[m,C,x,N,D,s,_e]);let ve=()=>{w(!1),m===`stream`&&j{if(w(!1),S(!1),M(0),de.current=0,P(!1),ce.current&&clearTimeout(ce.current),le.current&&clearInterval(le.current),se.current&&!localStorage.getItem(`cameraWindowState`)){let e=se.current,t=e.naturalWidth,n=e.naturalHeight;if(t>0&&n>0){let e=window.outerWidth-window.innerWidth,r=window.outerHeight-window.innerHeight,i=t+16+e,a=n+45+16+r;try{window.resizeTo(i,a)}catch{}}}},be=()=>{if(s>0){let e={},t=sd();t&&(e.Authorization=`Bearer ${t}`),fetch(`/api/v1/printers/${s}/camera/stop`,{method:`POST`,headers:e}).catch(()=>{})}},xe=e=>{m===e||D||(O(!0),w(!0),S(!1),M(0),P(!1),R(1),B({x:0,y:0}),ce.current&&clearTimeout(ce.current),le.current&&clearInterval(le.current),se.current&&(se.current.src=``),m===`stream`&&be(),setTimeout(()=>{h(e),E(Date.now()),O(!1)},100))},Se=()=>{D||(O(!0),w(!0),S(!1),M(0),P(!1),ce.current&&clearTimeout(ce.current),le.current&&clearInterval(le.current),se.current&&(se.current.src=``),m===`stream`&&be(),setTimeout(()=>{E(Date.now()),O(!1)},100))},Ce=()=>{H.current&&(document.fullscreenElement?document.exitFullscreen():H.current.requestFullscreen())},we=()=>{R(e=>Math.min(e+.5,4))},Te=()=>{R(e=>{let t=Math.max(e-.5,1);return t===1&&B({x:0,y:0}),t})},Ee=e=>{e.preventDefault(),e.deltaY<0?we():Te()},De=e=>{L>1&&(e.preventDefault(),ee(!0),ne({x:e.clientX-z.x,y:e.clientY-z.y}))},Oe=(0,y.useCallback)(()=>{if(!H.current)return{x:300,y:200};let e=H.current.getBoundingClientRect(),t=e.width*(L-1)/2,n=e.height*(L-1)/2;return{x:Math.max(50,t),y:Math.max(50,n)}},[L]),ke=e=>{if(V&&L>1){let t=e.clientX-te.x,n=e.clientY-te.y,r=Oe();B({x:Math.max(-r.x,Math.min(r.x,t)),y:Math.max(-r.y,Math.min(r.y,n))})}},Ae=()=>{ee(!1)},je=e=>{if(e.length<2)return 0;let t=e[0].clientX-e[1].clientX,n=e[0].clientY-e[1].clientY;return Math.sqrt(t*t+n*n)},Me=e=>e.length<2?{x:e[0].clientX,y:e[0].clientY}:{x:(e[0].clientX+e[1].clientX)/2,y:(e[0].clientY+e[1].clientY)/2},Ne=e=>{e.touches.length===2?(e.preventDefault(),ie(je(e.touches)),oe(Me(e.touches))):e.touches.length===1&&L>1&&(e.preventDefault(),ee(!0),ne({x:e.touches[0].clientX-z.x,y:e.touches[0].clientY-z.y}))},Pe=e=>{if(e.touches.length===2&&re!==null){e.preventDefault();let t=je(e.touches),n=t/re;R(e=>{let t=Math.max(1,Math.min(4,e*n));return t===1&&B({x:0,y:0}),t}),ie(t);let r=Me(e.touches);if(ae){let e=Oe();B(t=>({x:Math.max(-e.x,Math.min(e.x,t.x+(r.x-ae.x))),y:Math.max(-e.y,Math.min(e.y,t.y+(r.y-ae.y)))}))}oe(r)}else if(e.touches.length===1&&V&&L>1){e.preventDefault();let t=e.touches[0].clientX-te.x,n=e.touches[0].clientY-te.y,r=Oe();B({x:Math.max(-r.x,Math.min(r.x,t)),y:Math.max(-r.y,Math.min(r.y,n))})}},Fe=e=>{e.touches.length<2&&(ie(null),oe(null)),e.touches.length===0&&ee(!1)},Ie=()=>{R(1),B({x:0,y:0})},Le=D||!p&&(i||f)?``:(e=>p?`${e}&token=${encodeURIComponent(p)}`:dd(e))(m===`stream`?`/api/v1/printers/${s}/camera/stream?fps=${u}&t=${T}`:`/api/v1/printers/${s}/camera/snapshot?t=${T}`),Re=C||D||N;return s?(0,G.jsxs)(`div`,{ref:H,className:`min-h-screen bg-black flex flex-col`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2 bg-bambu-dark-secondary border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`h1`,{className:`text-sm font-medium text-white flex items-center gap-2`,children:[(0,G.jsx)(is,{className:`w-4 h-4`}),fe?.name||`Printer ${s}`]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`div`,{className:`flex bg-bambu-dark rounded p-0.5`,children:[(0,G.jsx)(`button`,{onClick:()=>xe(`stream`),disabled:Re,className:`px-3 py-1 text-xs rounded transition-colors ${m===`stream`?`bg-bambu-green text-white`:`text-bambu-gray hover:text-white disabled:opacity-50`}`,children:e(`camera.live`)}),(0,G.jsx)(`button`,{onClick:()=>xe(`snapshot`),disabled:Re,className:`px-3 py-1 text-xs rounded transition-colors ${m===`snapshot`?`bg-bambu-green text-white`:`text-bambu-gray hover:text-white disabled:opacity-50`}`,children:e(`camera.snapshot`)})]}),(0,G.jsx)(`button`,{onClick:()=>me.mutate(!pe?.chamber_light),disabled:!pe?.connected||me.isPending||!r(`printers:control`),className:`p-1.5 rounded disabled:opacity-50 ${pe?.chamber_light?`bg-yellow-500/20 hover:bg-yellow-500/30`:`hover:bg-bambu-dark-tertiary`}`,title:r(`printers:control`)?e(`camera.chamberLight`):e(`printers.permission.noControl`),children:(0,G.jsx)(uT,{on:pe?.chamber_light??!1,className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:()=>_(!0),disabled:!he||!r(`printers:control`),className:`p-1.5 rounded disabled:opacity-50 ${he&&r(`printers:control`)?`hover:bg-bambu-dark-tertiary`:``}`,title:r(`printers:control`)?e(he?`printers.skipObjects.tooltip`:`printers.skipObjects.onlyWhilePrinting`):e(`printers.permission.noControl`),children:(0,G.jsx)(dT,{className:`w-4 h-4 text-bambu-gray`})}),(0,G.jsx)(`button`,{onClick:Se,disabled:Re,className:`p-1.5 hover:bg-bambu-dark-tertiary rounded disabled:opacity-50`,title:e(m===`stream`?`camera.restartStream`:`camera.refreshSnapshot`),children:(0,G.jsx)(zl,{className:`w-4 h-4 text-bambu-gray ${Re?`animate-spin`:``}`})}),(0,G.jsx)(`button`,{onClick:()=>b(!0),className:`p-1.5 hover:bg-bambu-dark-tertiary rounded`,title:e(`camera.diagnose.button`),children:(0,G.jsx)(yu,{className:`w-4 h-4 text-bambu-gray`})}),(0,G.jsx)(`button`,{onClick:Ce,className:`p-1.5 hover:bg-bambu-dark-tertiary rounded`,title:e(k?`camera.exitFullscreen`:`camera.fullscreen`),children:k?(0,G.jsx)(dl,{className:`w-4 h-4 text-bambu-gray`}):(0,G.jsx)(sl,{className:`w-4 h-4 text-bambu-gray`})})]})]}),(0,G.jsx)(`div`,{className:`flex-1 flex items-center justify-center p-2 overflow-hidden`,onWheel:Ee,onMouseMove:ke,onMouseUp:Ae,onMouseLeave:Ae,onTouchStart:Ne,onTouchMove:Pe,onTouchEnd:Fe,style:{touchAction:`none`},children:(0,G.jsxs)(`div`,{className:`relative w-full h-full flex items-center justify-center`,children:[(C||D)&&!N&&(0,G.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-black/50 z-10`,children:(0,G.jsxs)(`div`,{className:`text-center`,children:[(0,G.jsx)(zl,{className:`w-8 h-8 text-bambu-gray animate-spin mx-auto mb-2`}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(m===`stream`?`camera.connectingToCamera`:`camera.capturingSnapshot`)})]})}),N&&(0,G.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-black/80 z-10`,children:(0,G.jsxs)(`div`,{className:`text-center p-4`,children:[(0,G.jsx)(Ju,{className:`w-10 h-10 text-orange-400 mx-auto mb-3`}),(0,G.jsx)(`p`,{className:`text-white mb-2`,children:e(`camera.connectionLost`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mb-3`,children:e(`camera.reconnecting`,{countdown:F,attempt:Math.min(j+1,d9),max:d9})}),(0,G.jsx)(`button`,{onClick:Se,className:`px-4 py-2 bg-bambu-green text-white text-sm rounded hover:bg-bambu-green/80 transition-colors`,children:e(`camera.reconnectNow`)})]})}),x&&!N&&(0,G.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-black z-10`,children:(0,G.jsxs)(`div`,{className:`text-center p-4`,children:[(0,G.jsx)(Pu,{className:`w-12 h-12 text-orange-400 mx-auto mb-3`}),(0,G.jsx)(`p`,{className:`text-white mb-2`,children:e(`camera.cameraUnavailable`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mb-4 max-w-md`,children:e(`camera.cameraUnavailableDesc`)}),(0,G.jsxs)(`div`,{className:`flex gap-2 justify-center`,children:[(0,G.jsx)(`button`,{onClick:Se,className:`px-4 py-2 bg-bambu-green text-white rounded hover:bg-bambu-green/80 transition-colors`,children:e(`camera.retry`)}),(0,G.jsx)(`button`,{onClick:()=>b(!0),className:`px-4 py-2 bg-bambu-dark border border-bambu-dark-tertiary text-bambu-gray hover:text-white rounded transition-colors`,children:e(`camera.diagnose.button`)})]})]})}),(0,G.jsx)(`img`,{ref:se,src:Le,alt:e(`camera.cameraStream`),className:`max-w-full max-h-full object-contain select-none`,style:{transform:`scale(${L}) translate(${z.x/L}px, ${z.y/L}px) rotate(${fe?.camera_rotation||0}deg)`,...fe?.camera_rotation===90||fe?.camera_rotation===270?{maxWidth:`100vh`,maxHeight:`100vw`}:{},cursor:L>1?V?`grabbing`:`grab`:`default`},onError:Le?ve:void 0,onLoad:Le?ye:void 0,onMouseDown:De,draggable:!1},T),(0,G.jsxs)(`div`,{className:`absolute bottom-4 left-4 flex items-center gap-1.5 bg-black/60 rounded-lg px-2 py-1.5`,children:[(0,G.jsx)(`button`,{onClick:Te,disabled:L<=1,className:`p-1.5 hover:bg-white/10 rounded disabled:opacity-30`,title:e(`camera.zoomOut`),children:(0,G.jsx)(nd,{className:`w-4 h-4 text-white`})}),(0,G.jsxs)(`button`,{onClick:Ie,className:`px-2 py-1 text-sm text-white hover:bg-white/10 rounded min-w-[48px]`,title:e(`camera.resetZoom`),children:[Math.round(L*100),`%`]}),(0,G.jsx)(`button`,{onClick:we,disabled:L>=4,className:`p-1.5 hover:bg-white/10 rounded disabled:opacity-30`,title:e(`camera.zoomIn`),children:(0,G.jsx)(ed,{className:`w-4 h-4 text-white`})})]})]})}),(0,G.jsx)(fT,{printerId:s,isOpen:g,onClose:()=>_(!1)}),v&&(0,G.jsx)(pT,{printerId:s,printerName:fe?.name||null,onClose:()=>b(!1)})]}):(0,G.jsx)(`div`,{className:`min-h-screen bg-black flex items-center justify-center`,children:(0,G.jsx)(`p`,{className:`text-white`,children:e(`camera.invalidPrinterId`)})})}var mZe=5e3,hZe=4,gZe=8,_Ze=1,vZe=16,yZe=2,bZe=60;function xZe(e,t,n,r){let i=parseInt(e??``,10);return Number.isFinite(i)?Math.min(r,Math.max(n,i)):t}function SZe(e,t,n,r,i,a){return e.has(t)?xZe(e.get(t),r,i,a):xZe(localStorage.getItem(n),r,i,a)}function CZe(){let{t:e}=U(),t=rr(),{authEnabled:n,loading:r,user:i}=Ed(),[a]=Li(),o=a.get(`token`),s=o!=null&&o!==``,[c,l]=(0,y.useState)(()=>SZe(a,`maxLive`,`camWallMaxLive`,hZe,_Ze,vZe)),[u,d]=(0,y.useState)(()=>SZe(a,`interval`,`camWallSnapshotSec`,gZe,yZe,bZe)),[f,p]=(0,y.useState)(()=>{let e=a.get(`status`)??localStorage.getItem(`camWallStatusMode`);return(s?[`off`,`compact`]:[`off`,`compact`,`full`]).includes(e)?e:`compact`});(0,y.useEffect)(()=>{if(s)return ld(o),()=>ld(null)},[s,o]);let m=K({queryKey:[`camwall-printers`,o],queryFn:()=>Z.getCamWallPrinters(o??void 0),enabled:s,refetchInterval:mZe}),h=K({queryKey:[`printers`],queryFn:()=>Z.getPrinters(),enabled:!s&&!r&&(!n||i!==null),refetchInterval:mZe}),g=(0,y.useMemo)(()=>{let e=new Map;for(let t of m.data??[])e.set(t.id,{connected:t.connected,state:t.state,progress:t.progress,remaining_time:t.remaining_time,layer_num:t.layer_num,total_layers:t.total_layers,hms_errors:t.hms_errors});return e},[m.data]);if(!s&&r)return(0,G.jsx)(`div`,{className:`flex min-h-screen items-center justify-center bg-bambu-dark text-bambu-gray`,children:e(`common.loading`)});if(!s&&n&&!i)return(0,G.jsx)(Fr,{to:`/login`,replace:!0,state:{from:t}});let _=s?m:h,v=s?m.data??[]:h.data??[];return _.isError?(0,G.jsx)(`div`,{className:`flex min-h-screen items-center justify-center bg-bambu-dark p-6 text-center`,children:(0,G.jsx)(`p`,{className:`max-w-md text-sm text-red-400`,children:e(s?`printers.camWall.page.tokenRejected`:`printers.camWall.page.loadFailed`)})}):(0,G.jsx)(`div`,{className:`min-h-screen bg-bambu-dark p-4`,children:(0,G.jsx)(bT,{printers:v,maxLive:c,snapshotIntervalSec:u,statusMode:f,statuses:s?g:void 0,showSettings:!s,onTileClick:s?void 0:e=>window.open(`/camera/${e}`,`camera-${e}`),onChangeMaxLive:e=>{l(e),localStorage.setItem(`camWallMaxLive`,String(e))},onChangeSnapshotIntervalSec:e=>{d(e),localStorage.setItem(`camWallSnapshotSec`,String(e))},onChangeStatusMode:e=>{p(e),localStorage.setItem(`camWallStatusMode`,e)}})})}function wZe(e,t,n){if(!e)return``;if(!t)return e;let r=t.match(/plate_(\d+)\.gcode/);return r&&parseInt(r[1],10)>1?`${e} — ${n(`printers.plateNumber`,`Plate {{number}}`,{number:r[1]})}`:e}function TZe(e){let t=e.get(`show`)?.split(`,`)||[`progress`,`layers`,`eta`,`filename`,`status`],n=parseInt(e.get(`fps`)||`15`,10),r=Math.min(Math.max(isNaN(n)?15:n,1),30),i=e.get(`camera`),a=i!==`false`&&i!==`0`;return{size:e.get(`size`)||`medium`,fps:r,showCamera:a,showProgress:t.includes(`progress`),showLayers:t.includes(`layers`),showEta:t.includes(`eta`),showFilename:t.includes(`filename`),showStatus:t.includes(`status`),showPrinter:t.includes(`printer`),showNozzle:t.includes(`nozzle`),showBed:t.includes(`bed`),showChamber:t.includes(`chamber`)}}function EZe(e,t){if(e.stg_cur_name)return e.stg_cur_name;switch(e.state){case`RUNNING`:return t(`streamOverlay.status.printing`);case`PAUSE`:return t(`streamOverlay.status.paused`);case`FINISH`:return t(`streamOverlay.status.finished`);case`FAILED`:return t(`streamOverlay.status.failed`);case`IDLE`:return t(`streamOverlay.status.idle`);default:return e.state||t(`streamOverlay.status.unknown`)}}function f9(e,t){let n=e[t];return typeof n==`number`?n:null}function DZe({icon:e,label:t,current:n,target:r,sizes:i}){let a=r!=null&&r>0&&Math.round(r)!==Math.round(n);return(0,G.jsxs)(`div`,{className:`flex items-center ${i.gap} text-white/70`,children:[e,(0,G.jsxs)(`span`,{className:i.text,children:[(0,G.jsx)(`span`,{className:`mr-1`,children:t}),(0,G.jsxs)(`span`,{className:`text-white`,children:[Math.round(n),`°C`]}),a&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`span`,{className:`mx-1`,children:`/`}),(0,G.jsxs)(`span`,{children:[Math.round(r),`°C`]})]})]})]})}function OZe(e){switch(e){case`small`:return{container:`p-3`,text:`text-sm`,textLarge:`text-lg`,progressHeight:`h-2`,icon:`w-3 h-3`,gap:`gap-2`,logoHeight:`h-12`};case`large`:return{container:`p-6`,text:`text-xl`,textLarge:`text-3xl`,progressHeight:`h-4`,icon:`w-6 h-6`,gap:`gap-4`,logoHeight:`h-24`};default:return{container:`p-4`,text:`text-base`,textLarge:`text-xl`,progressHeight:`h-3`,icon:`w-4 h-4`,gap:`gap-3`,logoHeight:`h-16`}}}function kZe(){let{printerId:e}=dr(),[t]=Li(),{t:n}=U(),r=so(),i=parseInt(e||`0`,10),[a,o]=(0,y.useState)(Date.now()),s=(0,y.useMemo)(()=>TZe(t),[t]),c=OZe(s.size),l=t.get(`token`),u=l!=null&&l!==``,{data:d}=K({queryKey:[`overlayStatus`,i,l],queryFn:()=>Z.getOverlayStatus(i,l??void 0),enabled:i>0&&u,refetchInterval:2e3}),{data:f}=K({queryKey:[`printer`,i],queryFn:()=>Z.getPrinter(i),enabled:i>0&&!u}),{data:p}=K({queryKey:[`printerStatus`,i],queryFn:()=>Z.getPrinterStatus(i),enabled:i>0&&!u,refetchInterval:2e3}),{data:m}=K({queryKey:[`settings`],queryFn:Z.getSettings,enabled:!u}),h=(0,y.useMemo)(()=>u?d&&{name:d.name,camera_rotation:d.camera_rotation}:f,[u,d,f]),g=u?d:p,_=(u?d?.time_format:m?.time_format)||`system`;(0,y.useEffect)(()=>{if(!i||u)return;let e=null,t=!1;return(async()=>{let n;try{n=(await Z.getWebSocketToken()).token}catch(e){let t=e instanceof id?e.status:0;if(t===401||t===403)return}if(t)return;let a=window.location.protocol===`https:`?`wss:`:`ws:`,o=n?`?token=${encodeURIComponent(n)}`:``,s=`${a}//${window.location.host}/api/v1/ws${o}`;e=new WebSocket(s),e.onmessage=e=>{try{let t=JSON.parse(e.data);t.type===`printer_status`&&t.printer_id===i&&r.setQueryData([`printerStatus`,i],t.status)}catch{}},e.onerror=()=>{}})(),()=>{t=!0,e&&e.close()}},[i,u,r]),(0,y.useEffect)(()=>(document.title=h?`${h.name} - ${n(`streamOverlay.title`)}`:n(`streamOverlay.title`),()=>{document.title=`Bambuddy`}),[h,n]);let v=()=>{setTimeout(()=>{o(Date.now())},3e3)};if(!i)return(0,G.jsx)(`div`,{className:`min-h-screen bg-black flex items-center justify-center`,children:(0,G.jsx)(`p`,{className:`text-white`,children:n(`streamOverlay.invalidPrinterId`)})});if(!g)return(0,G.jsx)(`div`,{className:`min-h-screen bg-black flex items-center justify-center`,children:(0,G.jsx)(`p`,{className:`text-gray-400`,children:n(`common.loading`)})});let b=g.state===`RUNNING`||g.state===`PAUSE`,x=g.progress||0,S=g.temperatures??{},C=[];if(s.showNozzle){let e=f9(S,`nozzle`),t=f9(S,`nozzle_2`);e!=null&&C.push({key:`nozzle`,icon:(0,G.jsx)(fc,{className:c.icon}),label:n(`printers.heaterHistory.nozzle`,`Nozzle`),current:e,target:f9(S,`nozzle_target`)}),t!=null&&C.push({key:`nozzle_2`,icon:(0,G.jsx)(fc,{className:c.icon}),label:n(`printers.heaterHistory.nozzle2`,`Nozzle 2`),current:t,target:f9(S,`nozzle_2_target`)})}if(s.showBed){let e=f9(S,`bed`);e!=null&&C.push({key:`bed`,icon:(0,G.jsx)(_u,{className:c.icon}),label:n(`printers.heaterHistory.bed`,`Bed`),current:e,target:f9(S,`bed_target`)})}if(s.showChamber){let e=f9(S,`chamber`);e!=null&&C.push({key:`chamber`,icon:(0,G.jsx)(Yo,{className:c.icon}),label:n(`printers.heaterHistory.chamber`,`Chamber`),current:e,target:f9(S,`chamber_target`)})}let w=`/api/v1/printers/${i}/camera/stream?fps=${s.fps}&t=${a}`,T=u&&l?`${w}&token=${encodeURIComponent(l)}`:dd(w);return(0,G.jsxs)(`div`,{className:`min-h-screen bg-black relative overflow-hidden`,children:[s.showCamera&&(0,G.jsx)(`img`,{src:T,alt:n(`streamOverlay.cameraStream`),className:`absolute inset-0 w-full h-full object-contain`,style:h?.camera_rotation?{transform:`rotate(${h.camera_rotation}deg)`}:void 0,onError:v},a),(0,G.jsx)(`a`,{href:`https://github.com/maziggy/bambuddy`,target:`_blank`,rel:`noopener noreferrer`,className:`absolute top-4 right-4 z-10`,children:(0,G.jsx)(`img`,{src:`/img/bambuddy_logo_dark_transparent.png`,alt:`Bambuddy`,className:`${c.logoHeight} object-contain drop-shadow-lg hover:scale-105 transition-transform`})}),(0,G.jsx)(`div`,{className:`absolute bottom-0 left-0 right-0 z-10 bg-gradient-to-t from-black/80 via-black/60 to-transparent`,children:(0,G.jsxs)(`div`,{className:`${c.container}`,children:[s.showPrinter&&h&&(0,G.jsxs)(`div`,{className:`flex items-center ${c.gap} mb-2`,children:[(0,G.jsx)(Fl,{className:`${c.icon} text-white/70`}),(0,G.jsx)(`span`,{className:`${c.text} text-white font-medium`,children:h.name})]}),s.showFilename&&g.current_print&&(0,G.jsx)(`div`,{className:`${c.textLarge} text-white font-semibold mb-2 truncate drop-shadow-md`,children:wZe(g.current_print.replace(/\.gcode\.3mf$|\.3mf$|\.gcode$/i,``),g.gcode_file,n)}),s.showStatus&&(0,G.jsx)(`div`,{className:`${c.text} text-white/70 mb-2`,children:EZe(g,n)}),s.showProgress&&b&&(0,G.jsxs)(`div`,{className:`mb-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-1 ${c.text}`,children:[(0,G.jsx)(`span`,{className:`text-white/70`,children:n(`streamOverlay.progress`)}),(0,G.jsxs)(`span`,{className:`text-white font-bold`,children:[Math.round(x),`%`]})]}),(0,G.jsx)(`div`,{className:`w-full bg-white/20 rounded-full ${c.progressHeight}`,children:(0,G.jsx)(`div`,{className:`bg-bambu-green ${c.progressHeight} rounded-full transition-all duration-500`,style:{width:`${x}%`}})})]}),b&&(s.showLayers||s.showEta)&&(0,G.jsxs)(`div`,{className:`flex items-center ${c.gap} flex-wrap`,children:[s.showLayers&&g.layer_num!=null&&g.total_layers!=null&&g.total_layers>0&&(0,G.jsxs)(`div`,{className:`flex items-center ${c.gap} text-white/70`,children:[(0,G.jsx)(Gc,{className:c.icon}),(0,G.jsxs)(`span`,{className:c.text,children:[(0,G.jsx)(`span`,{className:`text-white`,children:g.layer_num}),(0,G.jsx)(`span`,{className:`mx-1`,children:`/`}),(0,G.jsx)(`span`,{children:g.total_layers})]})]}),s.showEta&&g.remaining_time!=null&&g.remaining_time>0&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`flex items-center ${c.gap} text-white/70`,children:[(0,G.jsx)(Au,{className:c.icon}),(0,G.jsx)(`span`,{className:`${c.text} text-white`,children:Qf(g.remaining_time*60)})]}),(0,G.jsxs)(`div`,{className:`flex items-center ${c.gap} text-white/70`,children:[(0,G.jsx)(ks,{className:c.icon}),(0,G.jsxs)(`span`,{className:`${c.text} text-white`,children:[n(`streamOverlay.eta`),` `,Zf(g.remaining_time,_,n)]})]})]})]}),!b&&(0,G.jsx)(`div`,{className:`${c.text} text-white/70 py-2`,children:g.connected?n(`streamOverlay.printerIdle`):n(`streamOverlay.printerOffline`)}),C.length>0&&(0,G.jsx)(`div`,{className:`flex items-center ${c.gap} flex-wrap mt-2`,children:C.map(e=>(0,G.jsx)(DZe,{icon:e.icon,label:e.label,current:e.current,target:e.target,sizes:c},e.key))})]})})]})}function AZe(){let{t:e}=U(),{id:t}=dr(),{mode:n}=kd(),{data:r,isLoading:i,error:a}=K({queryKey:[`external-link`,t],queryFn:()=>Z.getExternalLink(Number(t)),enabled:!!t});return i?(0,G.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,G.jsx)(Y,{className:`w-8 h-8 text-bambu-green animate-spin`})}):a||!r?(0,G.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-4 text-bambu-gray`,children:[(0,G.jsx)(Pu,{className:`w-12 h-12`}),(0,G.jsx)(`p`,{children:e(`common.linkNotFound`)})]}):(0,G.jsx)(`iframe`,{src:r.url,className:`h-full w-full border-0`,style:{colorScheme:n},title:r.name,sandbox:`allow-scripts allow-same-origin allow-forms allow-popups allow-popups-to-escape-sandbox`})}function jZe(){let{id:e}=dr(),t=or(),n=so(),{t:r}=U(),{showToast:i}=Bd(),a=!!e,[o,s]=(0,y.useState)(``),[c,l]=(0,y.useState)(``),[u,d]=(0,y.useState)([]),[f,p]=(0,y.useState)(``),[m,h]=(0,y.useState)(!1),{data:g,isLoading:_}=K({queryKey:[`group`,e],queryFn:()=>Z.getGroup(Number(e)),enabled:a}),{data:v,isLoading:b}=K({queryKey:[`permissions`],queryFn:()=>Z.getPermissions()});a&&g&&!m&&(s(g.name),l(g.description||``),d(g.permissions),h(!0));let x=q({mutationFn:e=>Z.createGroup(e),onSuccess:()=>{n.invalidateQueries({queryKey:[`groups`]}),n.invalidateQueries({queryKey:[`group`]}),i(r(`groups.toast.created`)),t(`/settings?tab=users`)},onError:e=>{i(e.message,`error`)}}),S=q({mutationFn:t=>Z.updateGroup(Number(e),t),onSuccess:a=>{n.invalidateQueries({queryKey:[`groups`]}),a&&n.setQueryData([`group`,e],a),i(r(`groups.toast.updated`)),t(`/settings?tab=users`)},onError:e=>{i(e.message,`error`)}}),C=x.isPending||S.isPending,w=()=>{if(!o.trim()){i(r(`groups.toast.enterGroupName`),`error`);return}a?S.mutate({name:o===g?.name?void 0:o,description:c,permissions:u}):x.mutate({name:o,description:c||void 0,permissions:u})},T=e=>{d(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},E=(e,t)=>{let n=e.permissions.map(e=>e.value);d(e=>{let r=e.filter(e=>!n.includes(e));return t?[...r,...n]:r})},D=e=>e.permissions.every(e=>u.includes(e.value)),O=e=>{let t=e.permissions.filter(e=>u.includes(e.value)).length;return t>0&&t{v&&d(v.all_permissions)},A=()=>{d([])},j=f.toLowerCase(),M=(0,y.useMemo)(()=>v?j?v.categories.map(e=>({...e,permissions:e.permissions.filter(e=>e.label.toLowerCase().includes(j))})).filter(e=>e.permissions.length>0):v.categories:[],[v,j]),N=v?.all_permissions.length??0;return _||b?(0,G.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,G.jsx)(Y,{className:`w-8 h-8 text-bambu-green animate-spin`})}):(0,G.jsxs)(`div`,{className:`space-y-6 max-w-5xl mx-auto`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`button`,{onClick:()=>t(`/settings?tab=users`),className:`p-2 rounded-lg hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white transition-colors`,children:(0,G.jsx)(Io,{className:`w-5 h-5`})}),(0,G.jsx)(`h1`,{className:`text-xl font-bold text-white`,children:r(a?`groups.editor.title`:`groups.editor.createTitle`)})]}),a&&g?.is_system&&(0,G.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-3 rounded-lg bg-yellow-50 dark:bg-yellow-500/10 border border-yellow-300 dark:border-yellow-500/20 text-yellow-700 dark:text-yellow-400 text-sm`,children:[(0,G.jsx)(Pu,{className:`w-4 h-4 shrink-0`}),r(`groups.form.systemGroupWarning`)]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:r(`groups.form.groupName`)}),(0,G.jsx)(`input`,{type:`text`,value:o,onChange:e=>s(e.target.value),disabled:a&&g?.is_system,className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors disabled:opacity-50`,placeholder:r(`groups.form.groupNamePlaceholder`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:r(`groups.form.description`)}),(0,G.jsx)(`input`,{type:`text`,value:c,onChange:e=>l(e.target.value),className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:r(`groups.form.descriptionPlaceholder`)})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between flex-wrap gap-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[r(`groups.editor.permissionsSelected`,{count:u.length}),` / `,N]}),(0,G.jsx)(Q,{size:`sm`,variant:`ghost`,onClick:k,children:r(`groups.editor.selectAll`)}),(0,G.jsx)(Q,{size:`sm`,variant:`ghost`,onClick:A,children:r(`groups.editor.clearAll`)})]}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(Yl,{className:`w-4 h-4 absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray`}),(0,G.jsx)(`input`,{type:`text`,value:f,onChange:e=>p(e.target.value),placeholder:r(`groups.editor.search`),className:`pl-9 pr-4 py-2 text-sm bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors w-64`})]})]}),M.length===0?(0,G.jsx)(`div`,{className:`text-center py-12 text-bambu-gray`,children:r(`groups.editor.noResults`)}):(0,G.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:M.map(e=>{let t=v.categories.find(t=>t.name===e.name),n=t.permissions.filter(e=>u.includes(e.value)).length,i=t.permissions.length,a=D(t),o=O(t);return(0,G.jsxs)(Md,{children:[(0,G.jsxs)(`div`,{className:`sticky top-0 z-10 flex items-center justify-between px-4 py-3 bg-bambu-dark-secondary border-b border-bambu-dark-tertiary rounded-t-xl`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsxs)(`button`,{type:`button`,onClick:()=>E(t,!a),className:`w-5 h-5 rounded border flex items-center justify-center transition-colors shrink-0 ${a?`bg-bambu-green border-bambu-green`:o?`bg-bambu-green/50 border-bambu-green`:`border-bambu-gray hover:border-white`}`,children:[a&&(0,G.jsx)(us,{className:`w-3 h-3 text-white`}),o&&!a&&(0,G.jsx)(fl,{className:`w-3 h-3 text-white`})]}),(0,G.jsx)(iu,{className:`w-4 h-4 text-bambu-gray shrink-0`}),(0,G.jsx)(`span`,{className:`text-white font-medium text-sm`,children:e.name})]}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray tabular-nums`,children:[n,`/`,i]})]}),(0,G.jsx)(`div`,{className:`p-3 space-y-1`,children:e.permissions.map(e=>(0,G.jsxs)(`label`,{className:`flex items-center gap-3 px-2 py-1.5 rounded hover:bg-bambu-dark-secondary cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:u.includes(e.value),onChange:()=>T(e.value),className:`w-4 h-4 shrink-0 rounded border-bambu-gray text-bambu-green focus:ring-bambu-green focus:ring-offset-0 bg-bambu-dark-secondary`}),(0,G.jsxs)(`span`,{className:`flex flex-col`,children:[(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.label}),e.value===`websocket:connect`&&(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray/60`,children:r(`groups.editor.websocketHint`)})]})]},e.value))})]},e.name)})}),(0,G.jsx)(`div`,{className:`h-16`}),(0,G.jsxs)(`div`,{className:`fixed bottom-0 left-0 right-0 z-20 px-6 py-3 bg-bambu-dark-secondary border-t border-bambu-dark-tertiary flex items-center justify-center gap-3`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>t(`/settings?tab=users`),children:r(`common.cancel`)}),(0,G.jsx)(Q,{onClick:w,disabled:C||!o.trim(),children:C?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),r(`common.saving`)]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Wl,{className:`w-4 h-4`}),r(`common.save`)]})})]})]})}var MZe=1.65,NZe=[`#1DB954`,`#3B82F6`,`#F59E0B`,`#EF4444`,`#8B5CF6`];function p9(e,t,n,r){return`${e}||${t??``}||${n??``}||${r??``}`}function m9(e,t){let n=new Date(e);return n.setDate(n.getDate()+Math.round(t)),n}function h9(e){return e.toLocaleDateString(void 0,{month:`short`,day:`numeric`,year:`numeric`})}function g9(e){return e.toLocaleDateString(void 0,{month:`short`,day:`numeric`})}function PZe(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;ee+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 FZe(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 nZ.getAllUsageHistory(5e3),staleTime:6e4,enabled:o}),{data:O=[]}=K({queryKey:[`shopping-list`],queryFn:Z.getShoppingList,staleTime:3e4,enabled:o}),k=T?.forecast_global_lead_time_days??0,A=(0,y.useMemo)(()=>{let e=new Map;for(let t of E)e.set(p9(t.material,t.subtype,t.brand,t.color_name),t);return e},[E]),j=(0,y.useMemo)(()=>{let e=new Map;for(let t of D){let n=e.get(t.spool_id)??[];n.push(t),e.set(t.spool_id,n)}return e},[D]),M=(0,y.useMemo)(()=>{let t=new Map;for(let n of e){if(n.archived_at)continue;let e=p9(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]),N=(0,y.useMemo)(()=>{let e=new Date;return e.setHours(0,0,0,0),M.map(t=>{let n=A.get(t.key)??(t.colorName===null?null:A.get(p9(t.material,t.subtype,t.brand,null))??null),r=n?.lead_time_days??0,i=Math.max(k,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(...j.get(e.id)??[]);let d=null,f=null,p=`none`,m=PZe(u);if(m!==null)d=m.rate,f=m.stdDev,p=`history`;else{let e=FZe(t.spools);e!==null&&(d=e,p=`delta`)}let h=MZe*(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:m9(e,_),y=d&&d>0?Math.floor((s-g)/d):null,b=y===null?null:m9(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}})},[M,A,j,k]),P=(0,y.useMemo)(()=>[...new Set(M.map(e=>e.material))].sort(),[M]),F=(0,y.useMemo)(()=>[...new Set(M.map(e=>e.brand).filter(Boolean))].sort(),[M]),I=(0,y.useMemo)(()=>{let e=[...N];return m&&(e=e.filter(e=>e.group.material===m)),g&&(e=e.filter(e=>e.group.brand===g)),e.sort((e,t)=>{let n=0,r=0;switch(u){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=nr);return f===`asc`?i:-i}),e},[N,u,f,m,g]),L=(0,y.useMemo)(()=>N.filter(e=>!e.settings?.alerts_snoozed&&(e.stockBreakAlert||e.reorderAlert)),[N]),R=(0,y.useMemo)(()=>[...N].filter(e=>e.dailyRateG!==null).sort((e,t)=>t.totalUsedG-e.totalUsedG).slice(0,5),[N]);if(!o)return(0,G.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-16 text-bambu-gray gap-3`,children:[(0,G.jsx)(el,{className:`w-8 h-8 opacity-40`}),(0,G.jsx)(`p`,{className:`text-sm`,children:r(`forecast.noReadAccess`)})]});function z(e){u===e?p(e=>e===`asc`?`desc`:`asc`):(d(e),p(e===`days_left`?`asc`:`desc`))}let B=O.length>0?O.length:null;return(0,G.jsxs)(`div`,{className:`space-y-5`,children:[(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[L.length>0&&(0,G.jsxs)(`button`,{onClick:()=>l(e=>!e),className:`flex items-center gap-2 px-3 py-1.5 rounded-lg border text-sm font-medium transition-colors ${L.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,G.jsx)(Pu,{className:`w-4 h-4`}),r(`forecast.alertCount`,{count:L.length}),c?(0,G.jsx)(ms,{className:`w-3.5 h-3.5`}):(0,G.jsx)(ds,{className:`w-3.5 h-3.5`})]}),s&&(0,G.jsx)(VZe,{value:k,onSave:e=>{Z.updateSettings({forecast_global_lead_time_days:e}).then(()=>{t.invalidateQueries({queryKey:[`settings`]}),n(r(`forecast.globalLeadTimeSaved`),`success`)})}}),(0,G.jsxs)(`select`,{value:m,onChange:e=>h(e.target.value),className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${m?`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,G.jsx)(`option`,{value:``,children:r(`inventory.material`)}),P.map(e=>(0,G.jsx)(`option`,{value:e,children:e},e))]}),(0,G.jsxs)(`select`,{value:g,onChange:e=>_(e.target.value),className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${g?`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,G.jsx)(`option`,{value:``,children:r(`inventory.brand`)}),F.map(e=>(0,G.jsx)(`option`,{value:e,children:e},e))]}),(0,G.jsxs)(`button`,{onClick:()=>S(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,G.jsx)(au,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:r(`forecast.shoppingList`)}),B&&(0,G.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:B})]})]}),c&&L.length>0&&(0,G.jsx)(`div`,{className:`space-y-2`,children:L.map(e=>(0,G.jsx)(RZe,{forecast:e,onCart:()=>b(e)},e.group.key))}),x&&(0,G.jsx)(KZe,{items:O,forecasts:N,globalLeadTime:k,canWrite:s,onClose:()=>S(!1),onRemove:e=>{Z.removeFromShoppingList(e).then(()=>t.invalidateQueries({queryKey:[`shopping-list`]})).catch(()=>n(r(`forecast.failedSaveSettings`),`error`))},onClear:()=>{Z.clearShoppingList().then(()=>t.invalidateQueries({queryKey:[`shopping-list`]})).catch(()=>n(r(`forecast.failedSaveSettings`),`error`))}}),R.length>0&&(0,G.jsx)(BZe,{forecasts:R,days:C,onDaysChange:w}),N.length===0?(0,G.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-16 text-bambu-gray`,children:[(0,G.jsx)(Mu,{className:`w-10 h-10 mb-3 opacity-40`}),(0,G.jsx)(`p`,{className:`text-sm`,children:r(`forecast.noSpools`)})]}):(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg overflow-hidden border border-bambu-dark-tertiary`,children:[(0,G.jsx)(`div`,{className:`overflow-x-auto`,children:(0,G.jsxs)(`table`,{className:`w-full`,children:[(0,G.jsx)(`thead`,{children:(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary bg-bambu-dark-tertiary/30`,children:[(0,G.jsx)(`th`,{className:`w-8 px-4 py-3`}),(0,G.jsx)(_9,{col:`material`,active:u,dir:f,onSort:z,children:r(`forecast.sku`)}),(0,G.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:r(`locations.spools`)}),(0,G.jsx)(_9,{col:`stock`,active:u,dir:f,onSort:z,children:r(`forecast.stock`)}),(0,G.jsx)(_9,{col:`used`,active:u,dir:f,onSort:z,children:r(`forecast.dailyRate`)}),(0,G.jsx)(_9,{col:`days_left`,active:u,dir:f,onSort:z,children:r(`forecast.daysLeft`)}),(0,G.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:r(`forecast.emptyBy`)}),(0,G.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:r(`forecast.reorderBy`)}),(0,G.jsx)(`th`,{className:`w-24 px-4 py-3`})]})}),(0,G.jsx)(`tbody`,{className:`divide-y divide-bambu-dark-tertiary`,children:I.map(e=>(0,G.jsx)(HZe,{forecast:e,globalLeadTime:k,canWrite:s,onSaved:()=>t.invalidateQueries({queryKey:[`sku-settings`]}),onCart:()=>b(e),showToast:n},e.group.key))})]})}),(0,G.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,G.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,G.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-bambu-green inline-block`}),r(`forecast.trendLegend`)]}),(0,G.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,G.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-blue-400 inline-block`}),r(`forecast.estimatedLegend`)]}),(0,G.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,G.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-bambu-gray/40 inline-block`}),r(`forecast.noDataLegend`)]})]})]}),v&&(0,G.jsx)(JZe,{forecast:v,onClose:()=>b(null),onAdd:e=>{Z.addToShoppingList(e).then(()=>{t.invalidateQueries({queryKey:[`shopping-list`]}),n(r(`forecast.addedToCart`),`success`),b(null),S(!0)}).catch(()=>n(r(`forecast.failedAddItem`),`error`))}})]})}function _9({col:e,active:t,dir:n,onSort:r,children:i}){return(0,G.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,G.jsxs)(`span`,{className:`inline-flex items-center`,children:[i,t===e?n===`asc`?(0,G.jsx)(Vo,{className:`w-3 h-3 ml-1 text-bambu-green`}):(0,G.jsx)(Fo,{className:`w-3 h-3 ml-1 text-bambu-green`}):(0,G.jsx)(zo,{className:`w-3 h-3 ml-1 opacity-40`})]})})}function RZe({forecast:e,onCart:t}){let{t:n}=U(),r=[e.group.brand,e.group.material,e.group.subtype,e.group.colorName].filter(Boolean).join(` `),i=e.stockBreakAlert;return(0,G.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,G.jsx)(Pu,{className:`w-4 h-4 flex-shrink-0`}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`span`,{className:`font-medium`,children:r}),i?(0,G.jsxs)(`span`,{className:`ml-2 text-xs opacity-80`,children:[n(`forecast.stockBreakRisk`),` — `,n(`forecast.stockBreakDetail`,{days:e.daysRemaining,lt:e.effectiveLeadTimeDays})]}):(0,G.jsxs)(`span`,{className:`ml-2 text-xs opacity-80`,children:[n(`forecast.reorderNow`),` — `,n(`forecast.reorderTriggerPassed`,{date:e.reorderTriggerDate?h9(e.reorderTriggerDate):`—`})]})]}),(0,G.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,G.jsx)(au,{className:`w-3 h-3`}),` `,n(`forecast.order`)]})]})}var zZe=[{label:`1W`,value:7},{label:`1M`,value:30},{label:`6M`,value:180}];function BZe({forecasts:e,days:t,onDaysChange:n}){let{t:r}=U(),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:NZe[n%NZe.length],rop:e.reorderPointG,points:IZe(e,t)})),o=i.map(e=>{let t={day:e,label:g9(m9(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})(),c=o.slice(0,s+1),l=a.filter(e=>e.rop>0);return(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg overflow-hidden border border-bambu-dark-tertiary p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-4`,children:[(0,G.jsx)(Mu,{className:`w-4 h-4 text-bambu-green`}),(0,G.jsx)(`h3`,{className:`text-sm font-semibold text-white`,children:r(`forecast.chartTitle`)}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray ml-1 hidden sm:inline`,children:r(`forecast.dashedLinesROP`)}),(0,G.jsx)(`div`,{className:`ml-auto flex items-center bg-bambu-dark-tertiary rounded-lg p-0.5`,children:zZe.map(e=>(0,G.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,G.jsx)(cA,{width:`100%`,height:220,children:(0,G.jsxs)(VH,{data:c,margin:{top:4,right:8,bottom:0,left:0},children:[(0,G.jsx)(`defs`,{children:a.map(e=>(0,G.jsxs)(`linearGradient`,{id:`grad-${e.key}`,x1:`0`,y1:`0`,x2:`0`,y2:`1`,children:[(0,G.jsx)(`stop`,{offset:`5%`,stopColor:e.color,stopOpacity:.25}),(0,G.jsx)(`stop`,{offset:`95%`,stopColor:e.color,stopOpacity:.02})]},e.key))}),(0,G.jsx)(mV,{strokeDasharray:`3 3`,stroke:`#374151`,strokeOpacity:.5}),(0,G.jsx)(ZV,{dataKey:`label`,tick:{fill:`#6B7280`,fontSize:10},interval:Math.max(0,Math.ceil(s/8)-1),axisLine:!1,tickLine:!1}),(0,G.jsx)(nH,{tick:{fill:`#6B7280`,fontSize:10},axisLine:!1,tickLine:!1,tickFormatter:e=>e>=1e3?`${(e/1e3).toFixed(1)}kg`:`${e}g`,width:48}),(0,G.jsx)(tz,{content:({label:e,payload:t})=>t?.length?(0,G.jsxs)(`div`,{style:{background:`#1a1a2e`,border:`1px solid #374151`,borderRadius:8,fontSize:12,padding:`8px 12px`},children:[(0,G.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,G.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:6,color:`#E5E7EB`,marginBottom:2},children:[(0,G.jsx)(`span`,{style:{color:t?.color??`#9CA3AF`,fontSize:10},children:`●`}),(0,G.jsx)(`span`,{children:t?.label??String(e.dataKey)}),(0,G.jsxs)(`span`,{style:{color:`#9CA3AF`,marginLeft:4},children:[e.value,`g`]})]},String(e.dataKey)):null})]}):null}),(0,G.jsx)(ij,{formatter:e=>(0,G.jsx)(`span`,{style:{color:`#9CA3AF`,fontSize:11},children:a.find(t=>t.key===e)?.label??e})}),a.map(e=>(0,G.jsx)(kV,{type:`monotone`,dataKey:e.key,stroke:e.color,strokeWidth:2,fill:`url(#grad-${e.key})`,dot:!1,activeDot:{r:3}},e.key)),l.map(e=>(0,G.jsx)(rV,{y:e.rop,stroke:e.color,strokeDasharray:`4 3`,strokeOpacity:.6},`rop-${e.key}`))]})})]})}function VZe({value:e,onSave:t}){let{t:n}=U(),[r,i]=(0,y.useState)(!1),[a,o]=(0,y.useState)(String(e));function s(){let e=parseInt(a,10);isNaN(e)||e<0||(t(e),i(!1))}return(0,G.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,G.jsx)(Vc,{className:`w-3.5 h-3.5 flex-shrink-0`,"aria-label":n(`forecast.globalLeadTimeHint`)}),(0,G.jsxs)(`span`,{className:`hidden sm:inline`,children:[n(`forecast.globalLeadTime`),`:`]}),r?(0,G.jsxs)(`form`,{className:`flex items-center gap-1.5`,onSubmit:e=>{e.preventDefault(),s()},children:[(0,G.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,G.jsx)(`span`,{className:`text-bambu-gray`,children:`d`}),(0,G.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,G.jsx)(`button`,{type:`button`,onClick:()=>i(!1),className:`text-xs text-bambu-gray hover:text-white`,children:`✕`})]}):(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,G.jsxs)(`span`,{className:`font-semibold text-white`,children:[e,`d`]}),(0,G.jsx)(`button`,{onClick:()=>{o(String(e)),i(!0)},className:`p-0.5 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,G.jsx)(Dl,{className:`w-3 h-3`})})]})]})}function HZe({forecast:e,globalLeadTime:t,canWrite:n,onSaved:r,onCart:i,showToast:a}){let{t:o}=U(),[s,c]=(0,y.useState)(!1),[l,u]=(0,y.useState)(!1),[d,f]=(0,y.useState)(!1),[p,m]=(0,y.useState)(String(e.settings?.lead_time_days??0)),[h,g]=(0,y.useState)(String(e.settings?.safety_margin_value??14)),[_,v]=(0,y.useState)(e.settings?.safety_margin_unit??`days`);(0,y.useEffect)(()=>{l||m(String(e.settings?.lead_time_days??0))},[e.settings?.lead_time_days,l]),(0,y.useEffect)(()=>{d||(g(String(e.settings?.safety_margin_value??14)),v(e.settings?.safety_margin_unit??`days`))},[e.settings?.safety_margin_value,e.settings?.safety_margin_unit,d]);let b=q({mutationFn:Z.upsertSkuSettings,onSuccess:()=>{r(),a(o(`forecast.settingsSaved`),`success`)},onError:()=>a(o(`forecast.failedSaveSettings`),`error`)}),x=e.settings?.alerts_snoozed??!1,S=[e.group.brand,e.group.material,e.group.subtype,e.group.colorName].filter(Boolean).join(` `),C=e.group.spools[0]?.rgba?xf(e.group.spools[0].rgba):{backgroundColor:`#4B5563`},w=e.totalLabelG>0?Math.round(e.totalRemainingG/e.totalLabelG*100):0,T=x||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 E(t,n,r,i=x){b.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 D(t){t.stopPropagation(),E(e.settings?.lead_time_days??0,e.settings?.safety_margin_value??14,e.settings?.safety_margin_unit??`days`,!x)}let O=e.rateTier===`history`?(0,G.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,G.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-bambu-green`}),o(`forecast.trend`)]}):e.rateTier===`delta`?(0,G.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,G.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-blue-400`}),o(`forecast.estimated`)]}):(0,G.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,G.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-bambu-gray/40`}),o(`forecast.noData`)]});return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/50 cursor-pointer hover:bg-bambu-dark-tertiary/30 transition-colors ${x?``:e.stockBreakAlert?`bg-red-500/5`:e.reorderAlert?`bg-yellow-500/5`:``} ${x?`opacity-50`:``}`,onClick:()=>c(e=>!e),children:[(0,G.jsx)(`td`,{className:`px-4 py-3`,children:(0,G.jsx)(`span`,{className:`block w-5 h-5 rounded-full border border-black/20`,style:C})}),(0,G.jsx)(`td`,{className:`px-4 py-3`,children:(0,G.jsx)(`span`,{className:`text-sm text-white`,children:S})}),(0,G.jsx)(`td`,{className:`px-4 py-3`,children:(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.totalSpools})}),(0,G.jsx)(`td`,{className:`px-4 py-3 min-w-[140px]`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`div`,{className:`flex-1 h-2 bg-bambu-dark-tertiary rounded-full overflow-hidden`,children:(0,G.jsx)(`div`,{className:`h-full rounded-full ${w>50?`bg-bambu-green`:w>20?`bg-yellow-500`:`bg-red-500`}`,style:{width:`${Math.min(w,100)}%`}})}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray min-w-[40px] text-right`,children:[Math.round(e.totalRemainingG),`g`]})]})}),(0,G.jsx)(`td`,{className:`px-4 py-3`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 flex-wrap`,children:[(0,G.jsx)(`span`,{className:`text-sm text-white`,children:e.dailyRateG===null?`—`:`${e.dailyRateG.toFixed(1)}g/d`}),O]})}),(0,G.jsx)(`td`,{className:`px-4 py-3`,children:(0,G.jsx)(`span`,{className:`text-sm font-semibold ${T}`,children:e.daysRemaining===null?(0,G.jsx)(`span`,{className:`text-bambu-gray font-normal`,children:`—`}):`${e.daysRemaining}d`})}),(0,G.jsx)(`td`,{className:`px-4 py-3`,children:(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.projectedEmptyDate?h9(e.projectedEmptyDate):`—`})}),(0,G.jsx)(`td`,{className:`px-4 py-3`,children:(0,G.jsx)(`span`,{className:`text-sm ${!x&&e.reorderAlert?`text-yellow-700 dark:text-yellow-400`:`text-bambu-gray`}`,children:e.reorderTriggerDate?h9(e.reorderTriggerDate):`—`})}),(0,G.jsx)(`td`,{className:`px-4 py-3`,onClick:e=>e.stopPropagation(),children:(0,G.jsxs)(`div`,{className:`flex items-center justify-end gap-1`,children:[n&&(0,G.jsx)(`button`,{onClick:i,className:`p-1.5 text-bambu-gray hover:text-bambu-green rounded transition-colors`,title:o(`forecast.addToCart`),children:(0,G.jsx)(au,{className:`w-4 h-4`})}),!x&&(e.stockBreakAlert?(0,G.jsx)(Pu,{className:`w-4 h-4 text-red-600 dark:text-red-400`,"aria-label":o(`forecast.stockBreakRisk`)}):e.reorderAlert?(0,G.jsx)(Pu,{className:`w-4 h-4 text-yellow-600 dark:text-yellow-400`,"aria-label":o(`forecast.reorderNow`)}):e.daysRemaining===null?null:(0,G.jsx)(us,{className:`w-4 h-4 text-bambu-green/50`})),n&&(0,G.jsx)(`button`,{onClick:D,className:`p-1 rounded transition-colors ${x?`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:o(x?`forecast.alertsEnabled`:`forecast.alertsSnoozed`),children:(0,G.jsx)(Wo,{className:`w-3.5 h-3.5`})}),(0,G.jsx)(`button`,{onClick:e=>{e.stopPropagation(),c(e=>!e)},className:`p-1.5 text-bambu-gray hover:text-white rounded transition-colors`,children:s?(0,G.jsx)(ms,{className:`w-4 h-4`}):(0,G.jsx)(ds,{className:`w-4 h-4`})})]})})]}),s&&(0,G.jsx)(`tr`,{className:`bg-bambu-dark-tertiary/10`,children:(0,G.jsx)(`td`,{colSpan:9,className:`px-6 py-4`,children:(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{className:`grid gap-2 ${n?`grid-cols-2 sm:grid-cols-4`:`grid-cols-2`}`,children:[(0,G.jsx)(UZe,{label:o(`forecast.effectiveLeadTime`),value:`${e.effectiveLeadTimeDays}d`,hint:o(`forecast.effectiveLeadTimeHint`,{global:t,sku:e.settings?.lead_time_days??0})}),(0,G.jsx)(UZe,{label:o(`forecast.reorderPoint`),value:`${Math.round(e.reorderPointG)}g`,hint:o(`forecast.reorderPointHint`)}),n&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(WZe,{label:o(`forecast.skuLeadTimeOverride`),hint:o(`forecast.skuLeadTimeHint`),unit:o(`forecast.leadTime`),editing:l,value:e.settings?.lead_time_days??0,inputValue:p,onInputChange:m,onEdit:()=>{m(String(e.settings?.lead_time_days??0)),u(!0)},onSave:()=>{let t=parseInt(p,10);!isNaN(t)&&t>=0&&(E(t,e.settings?.safety_margin_value??14,_),u(!1))},onCancel:()=>u(!1),isPending:b.isPending,saveLabel:o(`forecast.save`),cancelLabel:o(`forecast.cancel`)}),(0,G.jsx)(GZe,{value:e.settings?.safety_margin_value??14,unit:_,editing:d,inputValue:h,dailyRateG:e.dailyRateG,onInputChange:g,onUnitChange:e=>v(e),onEdit:()=>{g(String(e.settings?.safety_margin_value??14)),v(e.settings?.safety_margin_unit??`days`),f(!0)},onSave:()=>{let t=parseInt(h,10);!isNaN(t)&&t>=0&&(E(e.settings?.lead_time_days??0,t,_),f(!1))},onCancel:()=>f(!1),isPending:b.isPending,saveLabel:o(`forecast.save`),cancelLabel:o(`forecast.cancel`),safetyMarginLabel:o(`forecast.safetyMarginLabel`)})]})]}),e.group.spools.length>1&&(0,G.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary pt-3`,children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:o(`forecast.individualSpools`)}),(0,G.jsx)(`div`,{className:`bg-bambu-dark-secondary rounded-lg overflow-hidden border border-bambu-dark-tertiary`,children:(0,G.jsxs)(`table`,{className:`w-full`,children:[(0,G.jsx)(`thead`,{children:(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary bg-bambu-dark-tertiary/30`,children:[(0,G.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:`#`}),(0,G.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:o(`inventory.remaining`)}),(0,G.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:o(`inventory.used`)}),(0,G.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:o(`forecast.labelWeight`)})]})}),(0,G.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,G.jsxs)(`tr`,{className:`hover:bg-bambu-dark-tertiary/30 transition-colors`,children:[(0,G.jsx)(`td`,{className:`px-4 py-2`,children:(0,G.jsxs)(`span`,{className:`text-xs font-mono text-bambu-gray/70`,children:[`#`,e.id]})}),(0,G.jsx)(`td`,{className:`px-4 py-2`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`w-24 h-1.5 bg-bambu-dark-tertiary rounded-full overflow-hidden flex-shrink-0`,children:(0,G.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,G.jsxs)(`span`,{className:`text-sm text-white`,children:[Math.round(t),`g`]})]})}),(0,G.jsx)(`td`,{className:`px-4 py-2`,children:(0,G.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[Math.round(Math.max(0,e.weight_used-(e.weight_used_baseline??0))),`g`]})}),(0,G.jsx)(`td`,{className:`px-4 py-2`,children:(0,G.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[e.label_weight,`g`]})})]},e.id)})})]})})]})]})})})]})}function UZe({label:e,value:t,hint:n}){return(0,G.jsxs)(`div`,{className:`bg-bambu-dark-tertiary/40 rounded-lg p-3`,title:n,children:[(0,G.jsx)(`div`,{className:`text-xs font-medium text-white mb-1`,children:e}),(0,G.jsx)(`div`,{className:`text-lg font-semibold text-white`,children:t})]})}function WZe({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,G.jsxs)(`div`,{className:`bg-bambu-dark-tertiary/40 rounded-lg p-3 space-y-1`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,G.jsx)(`span`,{className:`text-xs font-medium text-white`,children:e}),(0,G.jsx)(`span`,{title:t,children:(0,G.jsx)(Vc,{className:`w-3 h-3 text-bambu-gray/50`})})]}),r?(0,G.jsxs)(`form`,{className:`flex items-center gap-2`,onSubmit:e=>{e.preventDefault(),c()},children:[(0,G.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,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:n}),(0,G.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,G.jsx)(`button`,{type:`button`,onClick:l,disabled:u,className:`px-2 py-1 text-xs text-bambu-gray hover:text-white`,children:f})]}):(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-lg font-semibold text-white`,children:i}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:n}),(0,G.jsx)(`button`,{onClick:s,className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,G.jsx)(Dl,{className:`w-3 h-3`})})]})]})}function GZe({value:e,unit:t,editing:n,inputValue:r,dailyRateG:i,onInputChange:a,onUnitChange:o,onEdit:s,onSave:c,onCancel:l,isPending:u,saveLabel:d=`Save`,cancelLabel:f=`Cancel`,safetyMarginLabel:p=`Safety Margin`}){let{t:m}=U(),h=t===`g`?e:i===null?null:Math.round(i*e),g=t===`days`?m(`forecast.safetyMarginHintDays`,{approx:h===null?``:m(`forecast.safetyMarginHintDaysApprox`,{g:h})}):m(`forecast.safetyMarginHintG`,{approx:i===null?``:m(`forecast.safetyMarginHintGApprox`,{days:Math.round(e/i)})});return(0,G.jsxs)(`div`,{className:`bg-bambu-dark-tertiary/40 rounded-lg p-3 space-y-1`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,G.jsx)(`span`,{className:`text-xs font-medium text-white`,children:p}),(0,G.jsx)(`span`,{title:g,children:(0,G.jsx)(Vc,{className:`w-3 h-3 text-bambu-gray/50`})})]}),n?(0,G.jsxs)(`form`,{className:`flex items-center gap-2 flex-wrap`,onSubmit:e=>{e.preventDefault(),c()},children:[(0,G.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:u}),(0,G.jsxs)(`div`,{className:`flex bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded overflow-hidden text-xs`,children:[(0,G.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,G.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,G.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,G.jsx)(`button`,{type:`button`,onClick:l,disabled:u,className:`px-2 py-1 text-xs text-bambu-gray hover:text-white`,children:f})]}):(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-lg font-semibold text-white`,children:e}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:t}),h!==null&&t===`days`&&(0,G.jsxs)(`span`,{className:`text-lg font-semibold text-white`,children:[`≈ `,h,`g`]}),t===`g`&&i!==null&&(0,G.jsxs)(`span`,{className:`text-lg font-semibold text-white`,children:[`≈ `,Math.round(e/i),`d`]}),(0,G.jsx)(`button`,{onClick:s,className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,G.jsx)(Dl,{className:`w-3 h-3`})})]})]})}function KZe({items:e,forecasts:t,globalLeadTime:n,canWrite:r,onClose:i,onRemove:a,onClear:o}){let{t:s}=U(),c=so(),[l,u]=(0,y.useState)(`list`),d=q({mutationFn:async({id:e,status:t,item:n,avgSpoolG:r})=>{if(await Z.updateShoppingListStatus(e,t),t===`received`&&n){let t=r??1e3,i={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};await Z.bulkCreateSpools(i,n.quantity_spools),await Z.removeFromShoppingList(e)}},onSuccess:()=>{c.invalidateQueries({queryKey:[`shopping-list`]}),c.invalidateQueries({queryKey:[`spools`]})}}),f=(0,y.useMemo)(()=>{let e=new Map;for(let n of t)e.set(n.group.key,n);return e},[t]),p=(0,y.useMemo)(()=>e.map(e=>({item:e,forecast:f.get(p9(e.material,e.subtype,e.brand,e.color_name))??null})),[e,f]),m=(0,y.useMemo)(()=>p.filter(({forecast:e})=>!e||e.dailyRateG===null?!1:e.stockBreakAlert||e.daysRemaining!==null&&e.daysRemaining<=e.effectiveLeadTimeDays),[p]);function h(){let t=[s(`forecast.qty`),s(`forecast.material`),s(`inventory.brand`),s(`inventory.subtype`),s(`inventory.color`),`${s(`forecast.weight`)} (g)`,`${s(`forecast.leadTime`)} (d)`,s(`forecast.expectedRestock`),s(`forecast.status`),s(`forecast.note`)],r=e.map(e=>{let t=f.get(p9(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?h9(m9(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),c=document.createElement(`a`);c.href=o,c.download=`shopping-list-${new Date().toISOString().slice(0,10)}.csv`,c.click(),setTimeout(()=>URL.revokeObjectURL(o),100)}return(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg overflow-hidden border border-bambu-dark-tertiary`,children:[(0,G.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,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(au,{className:`w-4 h-4 text-bambu-green`}),(0,G.jsx)(`h3`,{className:`text-sm font-semibold text-white`,children:s(`forecast.shoppingList`)}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:s(`forecast.shoppingListItems`,{count:e.length})}),e.length>0&&(0,G.jsxs)(`div`,{className:`flex bg-bambu-dark-tertiary rounded-md p-0.5 ml-1`,children:[(0,G.jsxs)(`button`,{onClick:()=>u(`list`),className:`flex items-center gap-1.5 px-2 py-0.5 text-xs font-medium rounded transition-colors ${l===`list`?`bg-bambu-dark-secondary text-white shadow`:`text-bambu-gray hover:text-white`}`,children:[(0,G.jsx)(xl,{className:`w-3 h-3`}),s(`forecast.listView`)]}),(0,G.jsxs)(`button`,{onClick:()=>u(`logistics`),className:`flex items-center gap-1.5 px-2 py-0.5 text-xs font-medium rounded transition-colors ${l===`logistics`?`bg-bambu-dark-secondary text-white shadow`:`text-bambu-gray hover:text-white`}`,children:[(0,G.jsx)(cs,{className:`w-3 h-3`}),s(`forecast.logisticsView`),m.length>0&&(0,G.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:m.length})]})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.length>0&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`button`,{onClick:h,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,G.jsx)(Js,{className:`w-3 h-3`}),s(`forecast.downloadCsv`)]}),r&&(0,G.jsx)(`button`,{onClick:o,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:s(`forecast.clearAll`)})]}),(0,G.jsx)(`button`,{onClick:i,className:`p-1 text-bambu-gray hover:text-white transition-colors`,children:(0,G.jsx)($u,{className:`w-4 h-4`})})]})]}),e.length===0?(0,G.jsxs)(`div`,{className:`flex flex-col items-center py-8 text-bambu-gray`,children:[(0,G.jsx)(xl,{className:`w-8 h-8 mb-2 opacity-30`}),(0,G.jsx)(`p`,{className:`text-sm`,children:s(`forecast.shoppingListEmpty`)})]}):l===`list`?(0,G.jsx)(`div`,{className:`overflow-x-auto`,children:(0,G.jsxs)(`table`,{className:`w-full`,children:[(0,G.jsx)(`thead`,{children:(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary bg-bambu-dark-tertiary/20`,children:[(0,G.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:s(`forecast.qty`)}),(0,G.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:s(`forecast.material`)}),(0,G.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:s(`forecast.weight`)}),(0,G.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:s(`forecast.leadTime`)}),(0,G.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:s(`forecast.expectedRestock`)}),(0,G.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:s(`forecast.status`)}),(0,G.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:s(`forecast.note`)}),(0,G.jsx)(`th`,{className:`px-4 py-2 text-right text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:s(`forecast.actions`)})]})}),(0,G.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(` `),i=m.some(t=>t.item.id===e.id),o=f.get(p9(e.material,e.subtype,e.brand,e.color_name))??null,c=o&&o.totalSpools>0?o.totalLabelG/o.totalSpools:1e3,l=Math.round(e.quantity_spools*c),u=o?.effectiveLeadTimeDays??n??0,p=u>0?m9(new Date,u):null,h=e.status===`purchased`||e.status===`received`,g=e.status===`received`,_=d.isPending;return(0,G.jsxs)(`tr`,{className:`hover:bg-bambu-dark-tertiary/30 transition-colors ${i&&!h?`bg-red-500/5`:``}`,children:[(0,G.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,G.jsxs)(`span`,{className:`text-sm font-semibold text-bambu-green`,children:[e.quantity_spools,`×`]})}),(0,G.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-sm text-white`,children:t}),i&&!h&&(0,G.jsx)(Pu,{className:`w-3.5 h-3.5 text-red-600 dark:text-red-400 flex-shrink-0`,"aria-label":s(`forecast.stockBreakBefore`)})]})}),(0,G.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,G.jsx)(`span`,{className:`text-sm text-white`,children:l>=1e3?`${(l/1e3).toFixed(1)}kg`:`${l}g`})}),(0,G.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:u>0?`${u}d`:`—`})}),(0,G.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:p?h9(p):`—`})}),(0,G.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,G.jsx)(`span`,{className:`inline-flex items-center px-2 py-0.5 rounded text-xs font-medium ${g?`bg-bambu-green/20 text-bambu-green`:h?`bg-blue-100 dark:bg-blue-400/20 text-blue-700 dark:text-blue-400`:`bg-bambu-dark-tertiary text-bambu-gray`}`,children:s(g?`forecast.received`:h?`forecast.purchased`:`forecast.pending`)})}),(0,G.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:e.note||`—`})}),(0,G.jsx)(`td`,{className:`px-4 py-2.5`,children:(0,G.jsx)(`div`,{className:`flex items-center justify-end gap-1`,children:r&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`button`,{onClick:()=>d.mutate({id:e.id,status:h?`pending`:`purchased`}),disabled:_||g,title:s(h?`forecast.resetToPending`:`forecast.markPurchased`),className:`p-1.5 rounded transition-colors disabled:opacity-30 ${h?`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:h?(0,G.jsx)(Vl,{className:`w-4 h-4`}):(0,G.jsx)(Vs,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:()=>d.mutate({id:e.id,status:`received`,item:e,avgSpoolG:c}),disabled:_||!h||g,title:s(`forecast.markReceived`),className:`p-1.5 rounded transition-colors text-bambu-green/50 hover:text-bambu-green disabled:opacity-30`,children:(0,G.jsx)(yl,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:()=>a(e.id),className:`p-1 text-bambu-gray hover:text-red-600 dark:hover:text-red-400 transition-colors`,title:s(`forecast.remove`),children:(0,G.jsx)(ju,{className:`w-3.5 h-3.5`})})]})})})]},e.id)})})]})}):(0,G.jsx)(`div`,{className:`divide-y divide-bambu-dark-tertiary`,children:p.filter(({item:e})=>e.status!==`received`).map(({item:e,forecast:t})=>(0,G.jsx)(qZe,{item:e,forecast:t,globalLeadTime:n,canWrite:r,onRemove:()=>a(e.id)},e.id))})]})}function qZe({item:e,forecast:t,globalLeadTime:n,canWrite:r,onRemove:i}){let{t:a}=U(),o=[e.brand,e.material,e.subtype,e.color_name].filter(Boolean).join(` `),s=(0,y.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=g9(m9(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{if(!t||t.dailyRateG===null||t.dailyRateG<=0)return null;let e=Math.floor(t.totalRemainingG/t.dailyRateG);return ee>=1e3?`${(e/1e3).toFixed(1)}kg`:`${e}g`,width:44}),(0,G.jsx)(tz,{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,G.jsx)(kV,{type:`linear`,dataKey:`stock`,stroke:`#1DB954`,strokeWidth:2,fill:`url(#cart-post-${e.id})`,dot:!1,activeDot:{r:3}}),t.reorderPointG>0&&(0,G.jsx)(rV,{y:t.reorderPointG,stroke:`#F59E0B`,strokeDasharray:`5 3`,strokeOpacity:.8,label:{value:`ROP`,position:`insideTopRight`,fill:`#F59E0B`,fontSize:9}}),t.safetyStockG>0&&(0,G.jsx)(rV,{y:t.safetyStockG,stroke:`#6B7280`,strokeDasharray:`3 3`,strokeOpacity:.6,label:{value:`SS`,position:`insideTopRight`,fill:`#6B7280`,fontSize:9}}),(0,G.jsx)(rV,{x:g9(m9(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}}),c!==null&&(0,G.jsx)(rV,{x:g9(m9(new Date,c)),stroke:`#EF4444`,strokeWidth:1.5,strokeOpacity:.9,label:{value:`OUT`,position:`insideTopLeft`,fill:`#EF4444`,fontSize:9}})]})}),(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 mt-2 text-[10px] text-bambu-gray`,children:[(0,G.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(`span`,{className:`inline-block w-4 border-t-2 border-yellow-400 border-dashed`}),` `,a(`forecast.ropLabel`)]}),(0,G.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(`span`,{className:`inline-block w-4 border-t border-bambu-gray border-dashed`}),` `,a(`forecast.safetyStockLegend`)]}),(0,G.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(`span`,{className:`inline-block w-4 border-t-2 border-blue-400 border-dashed`}),` `,a(`forecast.stockArrivalLegend`)]}),l&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1 text-red-700 dark:text-red-400`,children:[(0,G.jsx)(`span`,{className:`inline-block w-4 border-t-2 border-red-400`}),` `,a(`forecast.stockoutLegend`)]})]})]}):null]})}function JZe({forecast:e,onClose:t,onAdd:n}){let{t:r}=U(),i=[e.group.brand,e.group.material,e.group.subtype,e.group.colorName].filter(Boolean).join(` `),[a,o]=(0,y.useState)(`qty`),[s,c]=(0,y.useState)(`1`),[l,u]=(0,y.useState)(`30`),[d,f]=(0,y.useState)(``),p=(0,y.useMemo)(()=>{if(!e.dailyRateG||e.dailyRateG<=0)return null;let t=e.dailyRateG*Number(l),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,l]),m=a===`qty`?parseInt(s,10)||1:p??1;function h(t){t.preventDefault(),n({material:e.group.material,subtype:e.group.subtype,brand:e.group.brand,color_name:e.group.colorName,quantity_spools:m,note:d||null})}return(0,G.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm p-4`,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-2xl border border-bambu-dark-tertiary w-full max-w-sm shadow-2xl`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-5 pt-5 pb-4 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(au,{className:`w-5 h-5 text-bambu-green`}),(0,G.jsx)(`h2`,{className:`text-base font-semibold text-white`,children:r(`forecast.addToCartTitle`)})]}),(0,G.jsx)(`button`,{onClick:t,className:`p-1 text-bambu-gray hover:text-white transition-colors`,children:(0,G.jsx)($u,{className:`w-5 h-5`})})]}),(0,G.jsxs)(`form`,{onSubmit:h,className:`p-5 space-y-4`,children:[(0,G.jsx)(`div`,{className:`text-sm text-bambu-gray`,children:i}),(0,G.jsxs)(`div`,{className:`flex bg-bambu-dark-tertiary rounded-lg p-0.5`,children:[(0,G.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,G.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,G.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,G.jsx)(`label`,{className:`text-xs text-bambu-gray`,children:r(`forecast.numberOfSpools`)}),(0,G.jsx)(`input`,{type:`number`,min:1,max:99,value:s,onChange:e=>c(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,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,G.jsx)(`label`,{className:`text-xs text-bambu-gray`,children:r(`forecast.lastHowManyDays`)}),(0,G.jsx)(`input`,{type:`number`,min:1,max:365,value:l,onChange:e=>u(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,G.jsx)(`div`,{className:`text-xs text-yellow-700 dark:text-yellow-400 px-1`,children:r(`forecast.noUsageQty`)}):(0,G.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2 bg-bambu-dark-tertiary/50 rounded-lg`,children:[(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:`≈`}),(0,G.jsx)(`span`,{className:`text-sm font-semibold text-bambu-green`,children:r(`forecast.spoolCount`,{count:p??0})}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[`at `,e.dailyRateG.toFixed(1),`g/day`]})]})]}),(0,G.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,G.jsx)(`label`,{className:`text-xs text-bambu-gray`,children:r(`forecast.noteOptional`)}),(0,G.jsx)(`input`,{type:`text`,maxLength:200,value:d,onChange:e=>f(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,G.jsxs)(`div`,{className:`flex items-center gap-3 pt-1`,children:[(0,G.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:m})}),(0,G.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`)})]})]})]})})}var v9={material:``,subtype:``,brand:``,color_name:``,rgba:`808080FF`,extra_colors:``,effect_type:``,label_weight:1e3,core_weight:250,core_weight_catalog_id:null,weight_used:0,slicer_filament:``,note:``,cost_per_kg:null,category:``,low_stock_threshold_pct:null,location_id:null,spoolman_filament_id:null},YZe=new Set([`material`,`subtype`,`brand`,`rgba`,`color_name`,`label_weight`]);function XZe(e,t=!1,n=!1,r=`create`){let i={};return t||n||r!==`create`?(!e.material&&!e.spoolman_filament_id&&(i.material=`Material is required`),{isValid:Object.keys(i).length===0,errors:i}):(e.slicer_filament||(i.slicer_filament=`Slicer preset is required`),e.material||(i.material=`Material is required`),e.brand||(i.brand=`Brand is required`),e.subtype||(i.subtype=`Subtype is required`),{isValid:Object.keys(i).length===0,errors:i})}function ZZe(e,t){if(t.length===0)return{top:[],rest:e};let n=new Set(t.map(e=>e.toLowerCase()));return{top:e.filter(e=>n.has(e.toLowerCase())),rest:e.filter(e=>!n.has(e.toLowerCase()))}}function y9({label:e}){return(0,G.jsx)(`div`,{className:`px-3 py-1 text-[11px] font-semibold uppercase tracking-wide text-bambu-gray/70 bg-bambu-dark-tertiary/40`,children:e})}function QZe({formData:e,updateField:t,cloudAuthenticated:n,loadingCloudPresets:r,presetInputValue:i,setPresetInputValue:a,selectedPresetOption:o,filamentOptions:s,availableBrands:c,availableMaterials:l,suggestedBrands:u,suggestedMaterials:d,quickAdd:f,detailsRequired:p,quantity:m,onQuantityChange:h,errors:g}){let{t:_}=U(),[v,b]=(0,y.useState)(!1),[x,S]=(0,y.useState)(!1),[C,w]=(0,y.useState)(!1),[T,E]=(0,y.useState)(!1),[D,O]=(0,y.useState)(``),[k,A]=(0,y.useState)(``),[j,M]=(0,y.useState)(``),[N,P]=(0,y.useState)(String(e.label_weight)),[F,I]=(0,y.useState)(!1),[L,R]=(0,y.useState)(new Set),z=(0,y.useRef)(null),B=(0,y.useRef)(null),V=(0,y.useRef)(null),ee=(0,y.useRef)(null);(0,y.useEffect)(()=>{let e=e=>{z.current&&!z.current.contains(e.target)&&b(!1),ee.current&&!ee.current.contains(e.target)&&E(!1),B.current&&!B.current.contains(e.target)&&S(!1),V.current&&!V.current.contains(e.target)&&w(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[]);let te=(0,y.useMemo)(()=>{if(!i)return s;let e=i.toLowerCase();return s.filter(t=>t.displayName.toLowerCase().includes(e)||t.code.toLowerCase().includes(e))},[s,i]),ne=(0,y.useMemo)(()=>{if(!D)return c;let e=D.toLowerCase();return c.filter(t=>t.toLowerCase().includes(e)).sort((t,n)=>{let r=t.toLowerCase()===e,i=n.toLowerCase()===e;return r&&!i?-1:!r&&i?1:t.localeCompare(n)})},[c,D]),re=(0,y.useMemo)(()=>{if(!k)return cU;let e=k.toLowerCase();return cU.filter(t=>t.toLowerCase().includes(e))},[k]),ie=(0,y.useMemo)(()=>{if(!j)return l;let e=j.toLowerCase();return l.filter(t=>t.toLowerCase().includes(e)).sort((t,n)=>{let r=t.toLowerCase()===e,i=n.toLowerCase()===e;return r&&!i?-1:!r&&i?1:t.localeCompare(n)})},[j,l]),ae=(0,y.useMemo)(()=>ZZe(ne,u),[ne,u]),oe=(0,y.useMemo)(()=>ZZe(ie,d),[ie,d]);(0,y.useEffect)(()=>{F||P(String(e.label_weight))},[e.label_weight,F]);let se=n=>{t(`slicer_filament`,n.code),a(n.displayName),b(!1);let r=pU(n.name),i=new Set,o=[[`material`,r.material],[`brand`,r.brand],[`subtype`,r.variant]];for(let[n,r]of o)r&&(e[n]&&!L.has(n)||(t(n,r),i.add(n)));R(i)},H=(e,n)=>{L.has(e)&&R(t=>{let n=new Set(t);return n.delete(e),n}),t(e,n)},ce=t=>(0,G.jsx)(`button`,{type:`button`,className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${e.brand===t?`bg-bambu-green/10 text-bambu-green`:`text-white`}`,onClick:()=>{H(`brand`,t),S(!1),O(``)},children:t},t),le=t=>(0,G.jsx)(`button`,{type:`button`,className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${e.material===t?`bg-bambu-green/10 text-bambu-green`:`text-white`}`,onClick:()=>{H(`material`,t),E(!1),M(``)},children:t},t);return(0,G.jsxs)(`div`,{className:`space-y-4`,children:[!f&&(0,G.jsx)(`div`,{className:`flex items-center gap-2 text-xs text-bambu-gray`,children:r?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-3 h-3 animate-spin`}),` `,_(`inventory.loadingPresets`)]}):n?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Ms,{className:`w-3 h-3 text-bambu-green`}),` `,_(`inventory.cloudConnected`)]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(As,{className:`w-3 h-3`}),` `,_(`inventory.cloudNotConnected`)]})}),!f&&(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:[_(`inventory.slicerPreset`),p&&` *`]}),(0,G.jsxs)(`div`,{className:`relative`,ref:z,children:[(0,G.jsx)(Yl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50 pointer-events-none`}),(0,G.jsx)(`input`,{type:`text`,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/50 focus:outline-none focus:border-bambu-green`,placeholder:_(`inventory.searchPresets`),value:i,onChange:e=>{a(e.target.value),b(!0)},onFocus:()=>{b(!0),a(``)}}),v&&(0,G.jsx)(`div`,{className:`absolute z-50 w-full mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-64 overflow-y-auto`,children:te.length===0?(0,G.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:_(`inventory.noPresetsFound`)}):te.map(e=>(0,G.jsx)(`button`,{type:`button`,className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary truncate ${o?.code===e.code?`bg-bambu-green/10 text-bambu-green`:`text-white`}`,onClick:()=>se(e),children:e.displayName},`${e.code}::${e.name}`))})]}),o&&(0,G.jsxs)(`div`,{className:`mt-1 text-xs text-bambu-gray`,children:[_(`inventory.selectedPreset`),`: `,(0,G.jsx)(`span`,{className:`font-mono text-bambu-green`,children:o.code})]}),g?.slicer_filament&&(0,G.jsx)(`p`,{className:`mt-1 text-xs text-red-700 dark:text-red-400`,children:g.slicer_filament})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:[_(`inventory.material`),` *`]}),(0,G.jsxs)(`div`,{className:`relative`,ref:ee,children:[(0,G.jsx)(`input`,{type:`text`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`,placeholder:_(`inventory.selectMaterial`),value:T?j:e.material,onChange:e=>{M(e.target.value),E(!0)},onFocus:()=>{E(!0),M(``)}}),(0,G.jsx)(ds,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50 pointer-events-none`}),T&&(0,G.jsxs)(`div`,{className:`absolute z-50 w-full mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-48 overflow-y-auto`,children:[ie.length===0?(0,G.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:_(`inventory.noResults`)}):(0,G.jsxs)(G.Fragment,{children:[oe.top.length>0&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(y9,{label:_(`inventory.suggestedOptions`)}),oe.top.map(le)]}),oe.rest.length>0&&(0,G.jsxs)(G.Fragment,{children:[oe.top.length>0&&(0,G.jsx)(y9,{label:_(`inventory.allOptions`)}),oe.rest.map(le)]})]}),j&&!ie.includes(j)&&(0,G.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:()=>{H(`material`,j),E(!1),M(``)},children:_(`inventory.useCustomMaterial`,{material:j})})]})]}),g?.material&&(0,G.jsx)(`p`,{className:`mt-1 text-xs text-red-700 dark:text-red-400`,children:g.material})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:[_(`inventory.brand`),p&&` *`]}),(0,G.jsxs)(`div`,{className:`relative`,ref:B,children:[(0,G.jsx)(`input`,{type:`text`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`,placeholder:_(`inventory.searchBrand`),value:x?D:e.brand,onChange:e=>{O(e.target.value),S(!0)},onFocus:()=>{S(!0),O(``)}}),(0,G.jsx)(ds,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50 pointer-events-none`}),x&&(0,G.jsxs)(`div`,{className:`absolute z-50 w-full mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-48 overflow-y-auto`,children:[ne.length===0?(0,G.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:_(`inventory.noResults`)}):(0,G.jsxs)(G.Fragment,{children:[ae.top.length>0&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(y9,{label:_(`inventory.suggestedOptions`)}),ae.top.map(ce)]}),ae.rest.length>0&&(0,G.jsxs)(G.Fragment,{children:[ae.top.length>0&&(0,G.jsx)(y9,{label:_(`inventory.allOptions`)}),ae.rest.map(ce)]})]}),D&&!ne.includes(D)&&(0,G.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:()=>{H(`brand`,D),S(!1),O(``)},children:_(`inventory.useCustomBrand`,{brand:D})})]})]}),g?.brand&&(0,G.jsx)(`p`,{className:`mt-1 text-xs text-red-700 dark:text-red-400`,children:g.brand})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:[_(`inventory.subtype`),p&&` *`]}),(0,G.jsxs)(`div`,{className:`relative`,ref:V,children:[(0,G.jsx)(`input`,{type:`text`,value:C?k:e.subtype,onChange:e=>{A(e.target.value),w(!0)},onFocus:()=>{w(!0),A(``)},placeholder:`Basic, Matte, Silk...`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`}),(0,G.jsx)(ds,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50 pointer-events-none`}),C&&(0,G.jsxs)(`div`,{className:`absolute z-50 w-full mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-48 overflow-y-auto`,children:[re.length===0?(0,G.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:_(`inventory.noResults`)}):re.map(t=>(0,G.jsx)(`button`,{type:`button`,className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${e.subtype===t?`bg-bambu-green/10 text-bambu-green`:`text-white`}`,onClick:()=>{H(`subtype`,t),w(!1),A(``)},children:t},t)),k&&!cU.some(e=>e.toLowerCase()===k.toLowerCase().trim())&&(0,G.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:()=>{H(`subtype`,k),w(!1),A(``)},children:_(`inventory.useCustomBrand`,{brand:k})})]})]}),g?.subtype&&(0,G.jsx)(`p`,{className:`mt-1 text-xs text-red-700 dark:text-red-400`,children:g.subtype})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:_(`inventory.labelWeight`)}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(`input`,{type:`number`,className:`w-full px-3 py-2 pr-7 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`,value:N,min:0,onFocus:()=>I(!0),onChange:e=>P(e.target.value),onBlur:()=>{I(!1);let n=N.trim(),r=Number(n);if(!n||!Number.isFinite(r)||r<0){P(String(e.label_weight));return}let i=Math.round(r);t(`label_weight`,i),P(String(i))}}),(0,G.jsx)(`span`,{className:`absolute right-2 top-1/2 -translate-y-1/2 text-xs text-bambu-gray`,children:`g`})]})]}),f&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:_(`inventory.quantity`)}),(0,G.jsx)(`input`,{type:`number`,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`,value:m,min:1,max:100,onChange:e=>{h(Math.max(1,Math.min(100,parseInt(e.target.value)||1)))}})]})]})}function $Ze(e){let t=e.split(/[\s,]+/).map(e=>e.trim().replace(/^#/,``)).filter(Boolean),n=[],r=[];for(let e of t)(e.length===6||e.length===8)&&/^[0-9a-fA-F]+$/.test(e)?n.push(e.toLowerCase()):r.push(e);return{value:n.join(`,`),invalid:r}}function eQe({formData:e,updateField:t,recentColors:n,onColorUsed:r,catalogColors:i}){let{t:a}=U(),[o,s]=(0,y.useState)(!1),[c,l]=(0,y.useState)(``),u=(e.rgba.replace(`#`,``)+`FF`).substring(0,8).toUpperCase(),d=u.substring(0,6),f=u.substring(6,8)===`00`,[p,m]=(0,y.useState)(f?u:d);(0,y.useEffect)(()=>{m(f?u:d)},[d,u,f]);let h=e=>u===(e.replace(`#`,``)+`FF`).substring(0,8).toUpperCase(),g=e=>xf(e),_=(e,n,i,a)=>{let o=e.replace(`#`,``).toUpperCase();if(t(`rgba`,o.length===8?o:o+`FF`),t(`color_name`,n),i!==void 0){let e=i??``;w(e),E([]),D.current=e,t(`extra_colors`,e)}a!==void 0&&t(`effect_type`,a??``),r({name:n,hex:e})},v=(0,y.useMemo)(()=>{if(i.length===0)return[];let t=e.brand?.trim(),n=e.material?.toLowerCase().trim(),r=e.subtype?.toLowerCase().trim();if(!t&&!n)return[];let a=t?t.toLowerCase().split(/[\s\-_]+/).filter(e=>e.length>=2):[],o=e=>{if(a.length===0)return!0;let t=e.toLowerCase();return a.some(e=>t.includes(e))};if(t&&!n){let e=i.filter(e=>o(e.manufacturer));if(e.length>0)return e.map(e=>({name:e.color_name,hex:e.hex_color.replace(`#`,``).substring(0,6),manufacturer:e.manufacturer,material:typeof e.material==`string`?e.material:void 0,extra_colors:e.extra_colors??null,effect_type:e.effect_type??null}))}let s=n&&r?`${n} ${r}`:``;if(s){let e=i.filter(e=>o(e.manufacturer)&&e.material?.toLowerCase()===s);if(e.length>0)return e.map(e=>({name:e.color_name,hex:e.hex_color.replace(`#`,``).substring(0,6),manufacturer:e.manufacturer,material:typeof e.material==`string`?e.material:void 0,extra_colors:e.extra_colors??null,effect_type:e.effect_type??null}));let t=s.replace(/\+$/,``);if(t!==s){let e=i.filter(e=>o(e.manufacturer)&&e.material?.toLowerCase()===t);if(e.length>0)return e.map(e=>({name:e.color_name,hex:e.hex_color.replace(`#`,``).substring(0,6),manufacturer:e.manufacturer,material:typeof e.material==`string`?e.material:void 0}))}}if(n){let e=i.filter(e=>o(e.manufacturer)&&(!e.material||e.material.toLowerCase().startsWith(n)));if(e.length>0)return e.map(e=>({name:e.color_name,hex:e.hex_color.replace(`#`,``).substring(0,6),manufacturer:e.manufacturer,material:typeof e.material==`string`?e.material:void 0,extra_colors:e.extra_colors??null,effect_type:e.effect_type??null}))}return[]},[i,e.brand,e.material,e.subtype]),b=(0,y.useMemo)(()=>{if(!c)return v;if(v.length===0)return[];let e=c.toLowerCase();return v.filter(t=>t.name.toLowerCase().includes(e)||(t.manufacturer?.toLowerCase().includes(e)??!1)||(t.material?.toLowerCase().includes(e)??!1))},[c,v]),x=v.length>0,S=(0,y.useMemo)(()=>c?uU.filter(e=>e.name.toLowerCase().includes(c.toLowerCase())):o?uU:lU,[c,o]),[C,w]=(0,y.useState)(e.extra_colors),[T,E]=(0,y.useState)([]),D=(0,y.useRef)(e.extra_colors);(0,y.useEffect)(()=>{e.extra_colors!==D.current&&(w(e.extra_colors),E([]),D.current=e.extra_colors)},[e.extra_colors]);let O=(0,y.useMemo)(()=>h6({rgba:e.rgba,extraColors:e.extra_colors,effectType:e.effect_type,subtype:e.subtype,effectSize:`bar`}),[e.rgba,e.extra_colors,e.effect_type,e.subtype]),k=e=>{if(w(e),!e.trim()){E([]),D.current=``,t(`extra_colors`,``);return}let{value:n,invalid:r}=$Ze(e);E(r),D.current=n,t(`extra_colors`,n)};return(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsx)(`div`,{className:`h-10 rounded-lg border border-bambu-dark-tertiary`,style:O,"data-testid":`color-preview-banner`}),n.length>0&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 text-xs text-bambu-gray shrink-0`,children:[(0,G.jsx)(ks,{className:`w-3 h-3`}),(0,G.jsx)(`span`,{children:a(`inventory.recentColors`)})]}),(0,G.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:n.map(e=>(0,G.jsx)(`button`,{type:`button`,onClick:()=>_(e.hex,e.name),className:`w-6 h-6 rounded border-2 transition-all hover:scale-110 ${h(e.hex)?`border-bambu-green ring-1 ring-bambu-green/30 scale-110`:`border-bambu-dark-tertiary`}`,style:g(e.hex),title:e.name},e.hex))})]}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(Yl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50 pointer-events-none`}),(0,G.jsx)(`input`,{type:`text`,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/50 focus:outline-none focus:border-bambu-green`,placeholder:a(`inventory.searchColors`),value:c,onChange:e=>l(e.target.value)})]}),x?(0,G.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:c?a(`inventory.searchResults`):`${e.brand}${e.material?` ${e.material}`:``}`}),(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-1.5`,children:[b.map(e=>(0,G.jsx)(`button`,{type:`button`,onClick:()=>_(e.hex,e.name,e.extra_colors,e.effect_type),className:`w-6 h-6 rounded border-2 transition-all hover:scale-110 hover:z-20 relative group ${h(e.hex)?`border-bambu-green ring-1 ring-bambu-green/30 scale-110`:`border-bambu-dark-tertiary`}`,style:g(e.hex),title:e.manufacturer&&e.material?`${e.name} (${e.manufacturer} — ${e.material})`:e.manufacturer?`${e.name} (${e.manufacturer})`:e.name,children:(0,G.jsx)(`span`,{className:`absolute -bottom-7 left-1/2 -translate-x-1/2 px-2 py-0.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-xs whitespace-nowrap opacity-0 group-hover:opacity-100 transition-opacity pointer-events-none z-20 shadow-lg text-white`,children:e.manufacturer&&e.material?`${e.name} (${e.manufacturer} — ${e.material})`:e.manufacturer?`${e.name} (${e.manufacturer})`:e.name})},`${e.hex}-${e.name}-${e.manufacturer??``}`)),b.length===0&&(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray py-1`,children:a(`inventory.noColorsFound`)})]})]}):(0,G.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between text-xs text-bambu-gray`,children:[(0,G.jsx)(`span`,{children:a(c?`inventory.searchResults`:o?`inventory.allColors`:`inventory.commonColors`)}),!c&&(0,G.jsx)(`button`,{type:`button`,onClick:()=>s(!o),className:`flex items-center gap-1 hover:text-white transition-colors`,children:o?(0,G.jsxs)(G.Fragment,{children:[a(`inventory.showLess`),` `,(0,G.jsx)(ms,{className:`w-3 h-3`})]}):(0,G.jsxs)(G.Fragment,{children:[a(`inventory.showAll`),` `,(0,G.jsx)(ds,{className:`w-3 h-3`})]})})]}),(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-1.5`,children:[S.map(e=>(0,G.jsx)(`button`,{type:`button`,onClick:()=>_(e.hex,e.name),className:`w-6 h-6 rounded border-2 transition-all hover:scale-110 hover:z-20 relative group ${h(e.hex)?`border-bambu-green ring-1 ring-bambu-green/30 scale-110`:`border-bambu-dark-tertiary`}`,style:g(e.hex),title:e.name,children:(0,G.jsx)(`span`,{className:`absolute -bottom-7 left-1/2 -translate-x-1/2 px-2 py-0.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-xs whitespace-nowrap opacity-0 group-hover:opacity-100 transition-opacity pointer-events-none z-20 shadow-lg text-white`,children:e.name})},e.hex)),S.length===0&&(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray py-1`,children:a(`inventory.noColorsFound`)})]})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:a(`inventory.colorName`)}),(0,G.jsx)(`input`,{type:`text`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`,placeholder:a(`inventory.colorNamePlaceholder`),value:e.color_name,onChange:e=>t(`color_name`,e.target.value)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:a(`inventory.hexColor`)}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsxs)(`div`,{className:`relative flex-1`,children:[(0,G.jsx)(`span`,{className:`absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray`,children:`#`}),(0,G.jsx)(`input`,{type:`text`,className:`w-full pl-7 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm font-mono uppercase focus:outline-none focus:border-bambu-green`,placeholder:`RRGGBB`,value:p.toUpperCase(),onChange:e=>{let n=e.target.value.replace(`#`,``).replace(/[^0-9A-Fa-f]/g,``).toUpperCase(),r=n.length>8?n.substring(0,8):n;m(r),r.length===6?t(`rgba`,r+`FF`):r.length===8&&t(`rgba`,r)},onBlur:()=>{if(p.length===7){let e=p+`0`;m(e),t(`rgba`,e)}else if(p.length>0&&p.length<6){let e=p.padEnd(6,`0`);m(e),t(`rgba`,e+`FF`)}}})]}),(0,G.jsx)(`input`,{type:`color`,className:`w-11 h-[38px] rounded-lg cursor-pointer border border-bambu-dark-tertiary shrink-0 bg-transparent`,value:`#${d}`,onChange:e=>{t(`rgba`,e.target.value.replace(`#`,``).toUpperCase()+`FF`)},title:a(`inventory.pickColor`)})]})]})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3 pt-2 border-t border-bambu-dark-tertiary/50`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:a(`inventory.extraColorsLabel`)}),(0,G.jsx)(`input`,{type:`text`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm font-mono placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`,placeholder:a(`inventory.extraColorsPlaceholder`),value:C,onChange:e=>k(e.target.value),"data-testid":`extra-colors-input`}),T.length>0&&(0,G.jsx)(`p`,{className:`text-xs text-red-700 dark:text-red-400 mt-1`,children:a(`inventory.extraColorsInvalid`,{tokens:T.join(`, `)})}),!T.length&&(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray/70 mt-1`,children:a(`inventory.extraColorsHint`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1 flex items-center gap-1.5`,children:[(0,G.jsx)(mu,{className:`w-3.5 h-3.5`}),a(`inventory.colorEffectLabel`)]}),(0,G.jsxs)(`div`,{className:`flex gap-2 items-stretch`,children:[(0,G.jsx)(`select`,{className:`flex-1 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`,value:e.effect_type,onChange:e=>t(`effect_type`,e.target.value),"data-testid":`effect-type-select`,children:f6.map(e=>(0,G.jsx)(`option`,{value:e.value,children:a(e.labelKey)},e.value||`none`))}),(0,G.jsx)(g6,{rgba:e.rgba,extraColors:e.extra_colors,effectType:e.effect_type,subtype:e.subtype,effectSize:`preview`,className:`w-10 h-10`,shape:`square`})]})]})]})]})}function tQe({catalog:e,value:t,onChange:n,catalogId:r,onCatalogIdChange:i}){let{t:a}=U(),[o,s]=(0,y.useState)(!1),[c,l]=(0,y.useState)(``),u=(0,y.useRef)(null),d=(0,y.useRef)(null);(0,y.useEffect)(()=>{let e=e=>{u.current&&!u.current.contains(e.target)&&s(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[]),(0,y.useEffect)(()=>{if(e.length===0)return;let n=e.filter(e=>e.weight===t);if(r){let n=e.find(e=>e.id===r);if(n&&n.weight===t)return}n.length===1?i(n[0].id):n.length===0&&r!==null&&i(null)},[t,e,r,i]);let f=(0,y.useMemo)(()=>{if(!c)return e;let t=c.toLowerCase();return e.filter(e=>e.name.toLowerCase().includes(t)||e.weight.toString().includes(t))},[e,c]),p=(0,y.useMemo)(()=>e.filter(e=>e.weight===t),[e,t]),m=(0,y.useMemo)(()=>{if(o)return c;if(r){let t=e.find(e=>e.id===r);if(t)return t.name}return p.length>0?p[0].name:``},[o,c,r,e,p]);return(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:(0,G.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Gl,{className:`w-3.5 h-3.5 text-bambu-gray`}),a(`inventory.coreWeight`)]})}),(0,G.jsxs)(`div`,{className:`flex gap-2 items-center`,children:[(0,G.jsxs)(`div`,{className:`flex-1 min-w-0 relative`,ref:u,children:[(0,G.jsx)(`input`,{ref:d,type:`text`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`,placeholder:a(`inventory.searchSpoolWeight`),value:m,onFocus:()=>{s(!0),l(``)},onChange:e=>{l(e.target.value),s(!0)}}),o&&(0,G.jsx)(`div`,{className:`absolute z-50 w-full mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-64 overflow-y-auto`,children:f.length===0?(0,G.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:a(`inventory.noResults`)}):f.map(e=>(0,G.jsxs)(`button`,{type:`button`,className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary flex justify-between items-center ${(r?e.id===r:e.weight===t)?`bg-bambu-green/10 text-bambu-green`:`text-white`}`,onClick:()=>{i(e.id),n(e.weight),s(!1),l(``)},children:[(0,G.jsx)(`span`,{className:`truncate`,children:e.name}),(0,G.jsxs)(`span`,{className:`font-mono text-xs text-bambu-gray ml-2 shrink-0`,children:[e.weight,`g`]})]},e.id))})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[(0,G.jsx)(`input`,{type:`number`,className:`w-16 px-2 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm text-center font-mono focus:outline-none focus:border-bambu-green`,value:t,min:0,max:2e3,onChange:e=>{let t=parseInt(e.target.value);!isNaN(t)&&t>=0&&n(t)}}),(0,G.jsx)(`span`,{className:`text-bambu-gray text-sm`,children:`g`})]})]})]})}function nQe({formData:e,updateField:t,spoolCatalog:n,currencySymbol:r,availableCategories:i,availableLocations:a=[],onCreateLocation:o,globalLowStockThreshold:s,spoolmanMode:c=!1}){let{t:l}=U(),{showToast:u}=Bd(),[d,f]=(0,y.useState)(``),[p,m]=(0,y.useState)(!1),[h,g]=(0,y.useState)(``),[_,v]=(0,y.useState)(!1),[b,x]=(0,y.useState)(``),[S,C]=(0,y.useState)(!1),w=Math.max(0,e.label_weight-e.weight_used),T=e.core_weight+w;return(0,y.useEffect)(()=>{p||f(String(T))},[p,T]),(0,y.useEffect)(()=>{_||g(String(w))},[_,w]),(0,G.jsxs)(`div`,{className:`space-y-4`,children:[c?(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray px-1`,children:l(`inventory.spoolWeightManagedBySpoolman`)}):(0,G.jsx)(tQe,{catalog:n,value:e.core_weight,onChange:e=>t(`core_weight`,e),catalogId:e.core_weight_catalog_id,onCatalogIdChange:e=>t(`core_weight_catalog_id`,e)}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:l(`inventory.currentWeight`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`div`,{className:`relative flex-1`,children:[(0,G.jsx)(`input`,{type:`number`,value:h,min:0,max:e.label_weight,onFocus:()=>v(!0),onChange:e=>{g(e.target.value)},onBlur:()=>{v(!1);let n=h.trim(),r=Number(n);if(!n||!Number.isFinite(r)||r<0||r>e.label_weight){g(String(w));return}let i=Math.round(r);t(`weight_used`,Math.max(0,e.label_weight-i)),g(String(i))},className:`w-full px-3 py-2 pr-7 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`}),(0,G.jsx)(`span`,{className:`absolute right-2 top-1/2 -translate-y-1/2 text-xs text-bambu-gray`,children:`g`})]}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray shrink-0`,children:[`/ `,e.label_weight,`g`]})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:l(`inventory.measuredWeight`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`div`,{className:`relative flex-1`,children:[(0,G.jsx)(`input`,{type:`number`,value:d,min:0,onFocus:()=>m(!0),onChange:e=>{f(e.target.value)},onBlur:()=>{m(!1);let n=d.trim(),r=Number(n),i=e.core_weight,a=e.core_weight+e.label_weight;if(!n||!Number.isFinite(r)||ra){u(l(`inventory.measuredWeightError`,{min:i,max:a}),`error`),f(String(T));return}let o=Math.round(r),s=Math.max(0,Math.min(e.label_weight,o-e.core_weight));t(`weight_used`,Math.max(0,e.label_weight-s)),f(String(o))},className:`w-full px-3 py-2 pr-7 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`}),(0,G.jsx)(`span`,{className:`absolute right-2 top-1/2 -translate-y-1/2 text-xs text-bambu-gray`,children:`g`})]}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray shrink-0`,children:[`/ `,e.core_weight+e.label_weight,`g`]})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:l(`inventory.costPerKg`,`Cost per kg`)}),(0,G.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,G.jsxs)(`div`,{className:`relative flex-1`,children:[(0,G.jsx)(`span`,{className:`absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray text-sm pointer-events-none`,children:r}),(0,G.jsx)(`input`,{type:`number`,value:e.cost_per_kg??``,min:0,step:.01,placeholder:`0.00`,onChange:e=>{t(`cost_per_kg`,e.target.value===``?null:parseFloat(e.target.value))},style:{paddingLeft:`${Math.max(2,r.length*.6+1)}rem`},className:`w-full py-2 pr-3 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:outline-none focus:border-bambu-green`})]})})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,htmlFor:`spool-category`,children:l(`inventory.category`)}),(0,G.jsx)(`input`,{id:`spool-category`,type:`text`,list:`spool-category-options`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`,placeholder:l(`inventory.categoryPlaceholder`),value:e.category,maxLength:50,onChange:e=>t(`category`,e.target.value)}),i.length>0&&(0,G.jsx)(`datalist`,{id:`spool-category-options`,children:i.map(e=>(0,G.jsx)(`option`,{value:e},e))})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,htmlFor:`spool-low-stock-threshold`,children:l(`inventory.lowStockThresholdOverride`)}),(0,G.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,G.jsxs)(`div`,{className:`relative flex-1`,children:[(0,G.jsx)(`input`,{id:`spool-low-stock-threshold`,type:`number`,className:`w-full px-3 py-2 pr-8 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`,placeholder:String(s),value:e.low_stock_threshold_pct??``,min:1,max:99,step:1,onChange:e=>{let n=e.target.value;if(n===``){t(`low_stock_threshold_pct`,null);return}let r=Number(n);Number.isFinite(r)&&t(`low_stock_threshold_pct`,Math.min(99,Math.max(1,Math.round(r))))}}),(0,G.jsx)(`span`,{className:`absolute right-3 top-1/2 -translate-y-1/2 text-xs text-bambu-gray pointer-events-none`,children:`%`})]})}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:l(`inventory.lowStockThresholdOverrideHelp`,{global:s})})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:l(`inventory.note`)}),(0,G.jsx)(`textarea`,{className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green resize-none min-h-[80px]`,placeholder:l(`inventory.notePlaceholder`),value:e.note,onChange:e=>t(`note`,e.target.value)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,htmlFor:`spool-storage-location`,children:l(`inventory.storageLocation`)}),(0,G.jsxs)(`select`,{id:`spool-storage-location`,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`,value:e.location_id??``,onChange:e=>{let n=e.target.value;if(!n){t(`location_id`,null);return}t(`location_id`,Number(n))},children:[(0,G.jsx)(`option`,{value:``,children:l(`inventory.storageLocationNone`)}),a.map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),o&&(0,G.jsxs)(`div`,{className:`mt-2 flex gap-2`,children:[(0,G.jsx)(`input`,{type:`text`,maxLength:255,className:`flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`,placeholder:l(`locations.createPlaceholder`),value:b,onChange:e=>x(e.target.value)}),(0,G.jsx)(`button`,{type:`button`,className:`px-3 py-2 text-sm rounded-lg bg-bambu-dark-tertiary text-white hover:bg-bambu-gray-dark disabled:opacity-50`,disabled:!b.trim()||S,onClick:async()=>{let e=b.trim();if(!(!e||!o)){C(!0);try{let n=await o(e);n&&(t(`location_id`,n.id),x(``))}finally{C(!1)}}},children:l(`locations.addShort`)})]})]})]})}function rQe({filaments:e,isLoading:t,selectedId:n,onSelect:r}){let{t:i}=U(),[a,o]=(0,y.useState)(!1),[s,c]=(0,y.useState)(``),l=(0,y.useRef)(null),u=(0,y.useRef)(null),d=(0,y.useMemo)(()=>e.find(e=>e.id===n)??null,[e,n]);(0,y.useEffect)(()=>{let e=e=>{l.current&&!l.current.contains(e.target)&&(o(!1),c(``))};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[]);let f=(0,y.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,y.useEffect)(()=>{a&&u.current?.focus()},[a]);let p=()=>{o(!0),c(``)},m=e=>{r(e),o(!1),c(``)},h=e=>e?`#${e.replace(`#`,``)}`:`#808080`;return(0,G.jsxs)(`div`,{ref:l,className:`relative`,children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,children:i(`inventory.pickFromSpoolmanCatalog`)}),(0,G.jsxs)(`button`,{type:`button`,onClick:p,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,G.jsx)(Y,{className:`w-4 h-4 text-bambu-gray animate-spin shrink-0`}):d?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`span`,{className:`w-4 h-4 rounded-full shrink-0 border border-white/20`,style:{backgroundColor:h(d.color_hex)},"aria-label":i(`inventory.spoolmanFilamentColorSwatch`)}),(0,G.jsxs)(`span`,{className:`text-white text-sm truncate flex-1`,children:[d.vendor?.name?`${d.vendor.name} — `:``,d.name]})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(xl,{className:`w-4 h-4 text-bambu-gray shrink-0`}),(0,G.jsx)(`span`,{className:`text-bambu-gray text-sm flex-1`,children:i(`inventory.spoolmanFilamentCatalog`)})]}),(0,G.jsx)(ds,{className:`w-4 h-4 text-bambu-gray shrink-0 ml-auto`})]}),a&&(0,G.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,G.jsx)(`div`,{className:`p-2 border-b border-bambu-dark-tertiary`,children:(0,G.jsx)(`input`,{ref:u,type:`text`,value:s,onChange:e=>c(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,G.jsx)(`ul`,{className:`max-h-56 overflow-y-auto py-1`,children:t?(0,G.jsxs)(`li`,{className:`flex items-center justify-center gap-2 py-4 text-bambu-gray text-sm`,children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),(0,G.jsx)(`span`,{children:i(`common.loading`,`Loading…`)})]}):f.length===0?(0,G.jsx)(`li`,{className:`py-4 text-center text-bambu-gray text-sm`,children:i(`inventory.noSpoolmanFilaments`)}):f.map(e=>(0,G.jsx)(`li`,{children:(0,G.jsxs)(`button`,{type:`button`,onClick:()=>m(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,G.jsx)(`span`,{className:`w-4 h-4 rounded-full shrink-0 border border-white/20`,style:{backgroundColor:h(e.color_hex)},"aria-label":i(`inventory.spoolmanFilamentColorSwatch`)}),(0,G.jsxs)(`span`,{className:`flex-1 min-w-0`,children:[(0,G.jsxs)(`span`,{className:`block text-white text-sm truncate`,children:[e.vendor?.name?`${e.vendor.name} — `:``,e.name]}),(0,G.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 iQe({formData:e,printersWithCalibrations:t,selectedProfiles:n,setSelectedProfiles:r,expandedPrinters:i,setExpandedPrinters:a}){let{t:o}=U(),s=e=>{a(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},c=(e,t,n)=>{let i=`${e}:${t}:${n??`null`}`,a=`${e}:${n??`null`}`;r(e=>{let t=new Set(e);if(t.has(i))t.delete(i);else{for(let e of Array.from(t)){let n=e.split(`:`);`${n[0]}:${n[2]}`===a&&t.delete(e)}t.add(i)}return t})},l=()=>{let n=new Set;for(let{printer:r,calibrations:i}of t){if(!r.connected)continue;let t=i.filter(t=>CU(t,e)),a=new Map;for(let e of t){let t=`${e.extruder_id??`null`}`;a.has(t)||a.set(t,[]),a.get(t).push(e)}for(let[e,t]of a)if(t.length>0){let i=[...t].sort((e,t)=>t.k_value-e.k_value)[0];n.add(`${r.id}:${i.cali_idx}:${e}`)}}r(n)};if(!e.material)return(0,G.jsx)(`div`,{className:`p-6 bg-bambu-dark rounded-lg text-center`,children:(0,G.jsx)(`p`,{className:`text-bambu-gray`,children:o(`inventory.selectMaterialFirst`)})});if(t.length===0)return(0,G.jsx)(`div`,{className:`p-6 bg-bambu-dark rounded-lg text-center`,children:(0,G.jsx)(`p`,{className:`text-bambu-gray`,children:o(`inventory.noPrintersConfigured`)})});let u=t.reduce((t,{printer:n,calibrations:r})=>n.connected?t+r.filter(t=>CU(t,e)).length:t,0),d=(e,t)=>{let r=`${e.id}:${t.cali_idx}:${t.extruder_id??`null`}`,i=n.has(r);return(0,G.jsxs)(`label`,{className:`flex items-center gap-3 p-3 rounded-lg cursor-pointer transition-all border ${i?`bg-bambu-green/10 border-bambu-green/30`:`bg-bambu-dark border-transparent hover:bg-bambu-dark/80`}`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:i,onChange:()=>c(String(e.id),t.cali_idx,t.extruder_id),className:`w-4 h-4 rounded border-bambu-dark-tertiary text-bambu-green focus:ring-bambu-green`}),(0,G.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,G.jsx)(`span`,{className:`text-sm font-medium ${i?`text-bambu-green`:`text-white`}`,children:t.name||t.filament_id})}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[t.nozzle_diameter&&(0,G.jsxs)(`span`,{className:`text-xs font-mono px-2 py-0.5 rounded bg-bambu-dark text-bambu-gray`,children:[t.nozzle_diameter,`mm`]}),(0,G.jsxs)(`span`,{className:`text-xs font-mono px-2 py-0.5 rounded bg-bambu-dark text-bambu-gray`,children:[`K=`,t.k_value.toFixed(3)]})]})]},`${t.cali_idx}-${t.extruder_id}`)};return(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`p`,{className:`text-xs text-bambu-gray`,children:[o(`inventory.matchingFilter`),`: `,e.brand||o(`inventory.anyBrand`),` / `,e.material,` / `,e.subtype||o(`inventory.anyVariant`)]}),u>0&&(0,G.jsxs)(`button`,{type:`button`,onClick:l,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`,children:[(0,G.jsx)(mu,{className:`w-3.5 h-3.5`}),o(`inventory.autoSelect`),` (`,u,`)`]})]}),(0,G.jsx)(`div`,{className:`space-y-3`,children:t.map(({printer:t,calibrations:n})=>{let r=i.has(String(t.id)),a=n.filter(t=>CU(t,e)),c=a.length,l=a.some(e=>e.extruder_id!==void 0&&e.extruder_id!==null&&e.extruder_id>0),u=a.filter(e=>e.extruder_id===1),f=a.filter(e=>e.extruder_id===0||e.extruder_id===void 0||e.extruder_id===null);return(0,G.jsxs)(`div`,{className:`border border-bambu-dark-tertiary rounded-lg overflow-hidden`,children:[(0,G.jsxs)(`button`,{type:`button`,onClick:()=>s(String(t.id)),className:`w-full px-4 py-3 flex items-center justify-between bg-bambu-dark-secondary hover:bg-bambu-dark-tertiary transition-colors`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[r?(0,G.jsx)(ds,{className:`w-4 h-4 text-bambu-gray`}):(0,G.jsx)(fs,{className:`w-4 h-4 text-bambu-gray`}),(0,G.jsx)(`span`,{className:`font-medium text-white`,children:t.name}),c>0?(0,G.jsxs)(`span`,{className:`text-xs px-2 py-0.5 rounded-full bg-bambu-green/20 text-bambu-green`,children:[c,` `,o(c===1?`inventory.match`:`inventory.matches`)]}):(0,G.jsx)(`span`,{className:`text-xs px-2 py-0.5 rounded-full bg-bambu-dark-tertiary text-bambu-gray`,children:o(`inventory.noMatches`)})]}),(0,G.jsx)(`span`,{className:`text-xs px-2 py-1 rounded-full ${t.connected?`bg-green-500/20 text-green-500`:`bg-bambu-gray/20 text-bambu-gray`}`,children:t.connected?o(`inventory.connected`):o(`inventory.offline`)})]}),r&&(0,G.jsx)(`div`,{className:`px-4 py-3 space-y-3 bg-bambu-dark border-t border-bambu-dark-tertiary`,children:t.connected?c===0?(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray italic py-2`,children:o(`inventory.noKProfilesMatch`)}):l?(0,G.jsxs)(G.Fragment,{children:[u.length>0&&(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`p`,{className:`text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:o(`inventory.leftNozzle`)}),(0,G.jsx)(`div`,{className:`space-y-2`,children:u.map(e=>d(t,e))})]}),f.length>0&&(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`p`,{className:`text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:o(`inventory.rightNozzle`)}),(0,G.jsx)(`div`,{className:`space-y-2`,children:f.map(e=>d(t,e))})]})]}):(0,G.jsx)(`div`,{className:`space-y-2`,children:a.map(e=>d(t,e))}):(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray italic py-2`,children:o(`inventory.printerOffline`)})})]},t.id)})}),n.size>0&&(0,G.jsx)(`div`,{className:`p-3 bg-bambu-green/10 border border-bambu-green/30 rounded-lg`,children:(0,G.jsxs)(`p`,{className:`text-sm text-white`,children:[(0,G.jsx)(`span`,{className:`font-semibold`,children:n.size}),` `,o(`inventory.profilesSelected`)]})})]})}function aQe(e){let t=Kf(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 oQe={completed:`text-bambu-green`,failed:`text-red-700 dark:text-red-400`,aborted:`text-yellow-700 dark:text-yellow-400`};function sQe({spoolId:e}){let{t}=U(),n=so(),{showToast:r}=Bd(),{data:i,isLoading:a}=K({queryKey:[`spool-usage`,e],queryFn:()=>Z.getSpoolUsageHistory(e)}),o=q({mutationFn:()=>Z.clearSpoolUsageHistory(e),onSuccess:()=>{n.invalidateQueries({queryKey:[`spool-usage`,e]}),r(t(`inventory.historyCleared`),`success`)}});return a?(0,G.jsx)(`div`,{className:`flex justify-center py-4`,children:(0,G.jsx)(Y,{className:`w-5 h-5 animate-spin text-bambu-green`})}):!i||i.length===0?(0,G.jsxs)(`div`,{className:`text-center py-4 text-bambu-gray text-sm`,children:[(0,G.jsx)(ks,{className:`w-5 h-5 mx-auto mb-2 opacity-50`}),t(`inventory.noUsageHistory`)]}):(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`h4`,{className:`text-sm font-medium text-white`,children:t(`inventory.usageHistory`)}),(0,G.jsxs)(Q,{variant:`ghost`,size:`sm`,onClick:()=>o.mutate(),disabled:o.isPending,className:`text-xs text-bambu-gray hover:text-red-700 dark:hover:text-red-400`,children:[(0,G.jsx)(ju,{className:`w-3 h-3 mr-1`}),t(`inventory.clearHistory`)]})]}),(0,G.jsx)(`div`,{className:`max-h-48 overflow-y-auto space-y-1`,children:i.map(e=>(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-2 rounded bg-bambu-dark/50 text-xs`,children:[(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:aQe(e.created_at)}),e.print_name&&(0,G.jsx)(`span`,{className:`text-white ml-2 truncate`,title:e.print_name,children:e.print_name})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0 ml-2`,children:[(0,G.jsxs)(`span`,{className:`text-white font-medium`,children:[e.weight_used.toFixed(1),`g`]}),(0,G.jsxs)(`span`,{className:`text-bambu-gray`,children:[`(`,e.percent_used,`%)`]}),(0,G.jsx)(`span`,{className:oQe[e.status]||`text-bambu-gray`,children:e.status})]})]},e.id))})]})}var b9=[`inventory-locations`];function x9(e){return e.invalidateQueries({queryKey:b9})}function cQe(e,t){return Promise.all([e.invalidateQueries({queryKey:[...t]}),x9(e)])}var lQe={tag_uid:null,tray_uuid:null,tag_type:null,data_origin:null};function uQe({isOpen:e,onClose:t,spool:n,mode:r,printersWithCalibrations:i=[],currencySymbol:a,onSpoolsCreated:o,spoolmanMode:s=!1,spoolsQueryKey:c=[`inventory-spools`]}){let{t:l}=U(),u=so(),{showToast:d}=Bd(),f=()=>cQe(u,c),p=r===`edit`,m=r===`copy`,[h,g]=(0,y.useState)(v9),[_,v]=(0,y.useState)({}),[b,x]=(0,y.useState)(`filament`),[S,C]=(0,y.useState)(!1),[w,T]=(0,y.useState)(!1),[E,D]=(0,y.useState)(!1),[O,k]=(0,y.useState)(1),[A,j]=(0,y.useState)(!1),[M,N]=(0,y.useState)(!1),[P,F]=(0,y.useState)([]),[I,L]=(0,y.useState)(``),[R,z]=(0,y.useState)([]),[B,V]=(0,y.useState)([]),[ee,te]=(0,y.useState)([]),[ne,re]=(0,y.useState)([]),[ie,ae]=(0,y.useState)([]),[oe,se]=(0,y.useState)([]),[H,ce]=(0,y.useState)([]),[le,ue]=(0,y.useState)(new Set),[de,fe]=(0,y.useState)(new Set),pe=i.length>0?i:H,me=le.size,{data:he=[],isLoading:ge,error:_e}=K({queryKey:[`spoolman-inventory-filaments`],queryFn:()=>Z.getSpoolmanInventoryFilaments(),enabled:s&&e,staleTime:6e4,retry:!1});(0,y.useEffect)(()=>{se(yU())},[]),(0,y.useEffect)(()=>{let t=!1;return e&&((async()=>{N(!0);try{let[e,n]=await Promise.allSettled([(async()=>(await Z.getCloudStatus()).is_authenticated?{connected:!0,presets:await Z.getFilamentPresets()}:{connected:!1,presets:[]})(),(async()=>(await Z.orcaCloudStatus()).connected?{connected:!0,presets:(await Z.orcaCloudListProfiles()).filament}:{connected:!1,presets:[]})()]);if(t)return;let r=e.status===`fulfilled`&&e.value.connected,i=n.status===`fulfilled`&&n.value.connected,a=e.status===`fulfilled`?e.value.presets:[],o=n.status===`fulfilled`?n.value.presets:[];j(r||i),F([...a,...o])}catch(e){if(t)return;console.error(`Failed to fetch cloud presets:`,e),j(!1)}finally{t||N(!1)}})(),s||Z.getSpoolCatalog().then(z).catch(console.error),Z.getColorCatalog().then(ae).catch(console.error),Z.getLocalPresets().then(e=>te(e.filament)).catch(console.error),Z.getBuiltinFilaments().then(re).catch(console.error),Z.getLocations().then(e=>V(e.map(e=>({id:e.id,name:e.name})))).catch(console.error),i.length===0&&(async()=>{try{let e=await Z.getPrinters(),t=await Promise.all(e.map(e=>Z.getPrinterStatus(e.id).catch(()=>null))),n=[];for(let r=0;r{t=!0}},[e,i.length]);let ve=(0,y.useMemo)(()=>hU(P,new Set,ee,ne),[P,ee,ne]),ye=(0,y.useMemo)(()=>{let e=mU(P,ee),t=ie.map(e=>e.manufacturer?.trim()).filter(e=>!!e),n=new Set([...e,...t]);return Array.from(n).sort((e,t)=>e.localeCompare(t))},[P,ee,ie]),be=(0,y.useMemo)(()=>{let e=ie.map(e=>e.material?.trim()).filter(e=>!!e),t=new Set([...oU,...e]);return Array.from(t).sort((e,t)=>e.localeCompare(t))},[ie]),xe=(0,y.useMemo)(()=>{let e=[];for(let t of ie){let n=t.manufacturer?.trim(),r=t.material?.trim();n&&r&&e.push({brand:n,material:r})}for(let t of P){let n=pU(t.name);n.brand&&n.material&&e.push({brand:n.brand,material:n.material})}for(let t of ee){let n=pU(t.name),r=t.filament_vendor?.trim()||n.brand,i=n.material;r&&i&&e.push({brand:r,material:i})}return e},[P,ie,ee]),Se=(0,y.useMemo)(()=>{let e=new Map;for(let t of xe){let n=t.brand.toLowerCase(),r=t.material.toLowerCase();e.has(n)||e.set(n,new Set),e.get(n).add(r)}return e},[xe]),Ce=(0,y.useMemo)(()=>{let e=new Map;for(let t of xe){let n=t.brand.toLowerCase(),r=t.material.toLowerCase();e.has(r)||e.set(r,new Set),e.get(r).add(n)}return e},[xe]),we=(0,y.useMemo)(()=>_U(ye,h.brand),[ye,h.brand]),Te=(0,y.useMemo)(()=>_U(be,h.material),[be,h.material]),Ee=(0,y.useMemo)(()=>vU(we,h.material,Ce),[we,h.material,Ce]),De=(0,y.useMemo)(()=>vU(Te,h.brand,Se),[Te,h.brand,Se]),Oe=(0,y.useMemo)(()=>gU(h.slicer_filament,ve),[h.slicer_filament,ve]);(0,y.useEffect)(()=>{if(e){if(n){let e=n.rgba&&/^[0-9A-Fa-f]{8}$/.test(n.rgba)?n.rgba:`808080FF`;if(g({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:m?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,location_id:n.location_id??null,spoolman_filament_id:null}),L(n.slicer_filament_name||n.slicer_filament||``),n.k_profiles&&n.k_profiles.length>0){let e=new Set;for(let t of n.k_profiles)t.cali_idx!==null&&t.cali_idx!==void 0&&e.add(`${t.printer_id}:${t.cali_idx}:${t.extruder??`null`}`);ue(e)}else ue(new Set)}else g(v9),L(``),ue(new Set);D(!1),k(1),v({}),x(`filament`),C(!1),T(!1)}},[e,n,r,m]),(0,y.useEffect)(()=>{if(!e||!n||w||h.location_id!=null)return;let t=n.storage_location?.trim();if(!t||B.length===0)return;let r=B.find(e=>e.name.toLowerCase()===t.toLowerCase());r&&g(e=>e.location_id===r.id?e:{...e,location_id:r.id})},[e,n,B,h.location_id,w]),(0,y.useEffect)(()=>{e&&pe.length>0&&fe(new Set(pe.map(e=>String(e.printer.id))))},[e,pe]);let ke=(e,t)=>{let n=YZe.has(e);s&&n&&h.spoolman_filament_id!==null&&d(l(`inventory.spoolmanFilamentUnlinked`),`info`),g(r=>({...r,[e]:t,...s&&n&&r.spoolman_filament_id!==null?{spoolman_filament_id:null}:{}})),e===`weight_used`&&C(!0),e===`location_id`&&T(!0),_[e]&&v(t=>({...t,[e]:void 0}))},Ae=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}$/.test(i)?i:`808080`;g(n=>({...n,spoolman_filament_id:e.id,material:t,subtype:r,brand:e.vendor?.name||``,rgba:`${a}FF`,color_name:e.color_name||``,label_weight:e.weight??n.label_weight})),d(l(`inventory.spoolmanFilamentSelected`),`success`)},je=e=>{se(t=>bU(e,t))},Me=q({mutationFn:e=>s?Z.createSpoolmanInventorySpool(e):Z.createSpool(e),onSuccess:async e=>{e?.id&&!await We(e.id)||(await f(),o&&o([e]),d(l(`inventory.spoolCreated`),`success`),t())},onError:e=>{e instanceof id&&e.status===503?d(l(`inventory.spoolmanUnreachable`),`error`):d(l(`inventory.saveFailed`),`error`)}}),Ne=q({mutationFn:({data:e,qty:t})=>s?Z.bulkCreateSpoolmanInventorySpools(e,t):Z.bulkCreateSpools(e,t),onSuccess:async e=>{let n=s&&`created`in e?e:null,r=n?n.created:e;if(le.size>0)for(let e of r)await We(e.id);await f(),o&&o(r),n&&n.failed_count>0?d(l(`inventory.spoolsPartiallyCreated`,{created:r.length,total:n.requested_count}),`warning`):d(l(`inventory.spoolsCreated`,{count:r.length}),`success`),t()},onError:e=>{e instanceof id&&e.status===503?d(l(`inventory.spoolmanUnreachable`),`error`):d(l(`inventory.saveFailed`),`error`)}}),Pe=q({mutationFn:e=>s?Z.updateSpoolmanInventorySpool(n.id,e):Z.updateSpool(n.id,e),onSuccess:async()=>{n?.id&&!await We(n.id)||(await f(),d(l(`inventory.spoolUpdated`),`success`),t())},onError:e=>{e instanceof id&&e.status===503?d(l(`inventory.spoolmanUnreachable`),`error`):d(l(`inventory.saveFailed`),`error`)}}),Fe=q({mutationFn:()=>s?Z.updateSpoolmanInventorySpool(n.id,lQe):Z.updateSpool(n.id,lQe),onSuccess:async()=>{await f(),d(l(`inventory.rfidCleared`,`RFID tag cleared`),`success`),t()},onError:e=>{e instanceof id&&e.status===503?d(l(`inventory.spoolmanUnreachable`),`error`):d(l(`inventory.tagClearFailed`),`error`)}}),{data:Ie}=K({queryKey:[`spool-assignments`],queryFn:()=>Z.getAssignments(),enabled:e&&p&&!s}),{data:Le}=K({queryKey:[`spoolman-slot-assignments-all`],queryFn:()=>Z.getSpoolmanSlotAssignments(),enabled:e&&p&&s}),Re=(()=>{if(n)return s?Le?.find(e=>e.spoolman_spool_id===n.id):Ie?.find(e=>e.spool_id===n.id)})(),{data:ze}=K({queryKey:[`inventory-spools`],queryFn:()=>Z.getSpools(!0),enabled:e}),{data:Be}=K({queryKey:[`settings`],queryFn:Z.getSettings,enabled:e}),Ve=(()=>{let e=new Set;for(let t of ze??[]){let n=t.category?.trim();n&&e.add(n)}return Array.from(e).sort((e,t)=>e.localeCompare(t))})(),He=Be?.low_stock_threshold??20,Ue=q({mutationFn:async()=>{if(!Re)throw Error(`No assignment`);if(s){if(!n)throw Error(`No spool`);await Z.unassignSpoolmanSlot(n.id);return}await Z.unassignSpool(Re.printer_id,Re.ams_id,Re.tray_id)},onSuccess:async()=>{s?(await u.invalidateQueries({queryKey:[`spoolman-slot-assignments-all`]}),await u.invalidateQueries({queryKey:[`spoolman-slot-assignments`]})):await u.invalidateQueries({queryKey:[`spool-assignments`]}),d(l(`inventory.unassignSuccess`,`Spool unassigned`),`success`),t()},onError:e=>{d(e.message,`error`)}}),We=async e=>{let t=s?Z.saveSpoolmanKProfiles:Z.saveSpoolKProfiles;if(le.size===0)try{return await t(e,[]),!0}catch(e){return console.error(`Failed to save K-profiles:`,e),d(l(`inventory.kProfileSaveFailed`),`warning`),!1}let n=[],r=0;for(let e of le){let[t,i,a]=e.split(`:`),o=parseInt(t),s=parseInt(i),c=a===`null`?0:parseInt(a),l=pe.find(e=>e.printer.id===o);if(l){let e=l.calibrations.find(e=>e.cali_idx===s);e?n.push({printer_id:o,extruder:c,nozzle_diameter:e.nozzle_diameter||`0.4`,k_value:e.k_value,name:e.name||null,cali_idx:e.cali_idx,setting_id:e.setting_id||null}):r++}else r++}if(r>0)return console.error(`saveKProfiles: ${r} profile key(s) could not be resolved`,Array.from(le)),d(l(`inventory.kProfileSaveFailed`),`warning`),!1;if(n.length>0)try{return await t(e,n),!0}catch(e){return console.error(`Failed to save K-profiles:`,e),d(l(`inventory.kProfileSaveFailed`),`warning`),!1}return!0};if((0,y.useEffect)(()=>{if(!e)return;let n=e=>{e.key===`Escape`&&t()};return document.addEventListener(`keydown`,n),()=>document.removeEventListener(`keydown`,n)},[e,t]),!e)return null;let Ge=()=>{let e=XZe(h,E,s,r);if(!e.isValid){v(e.errors),(e.errors.slicer_filament||e.errors.material||e.errors.brand||e.errors.subtype)&&x(`filament`);return}let t=Oe?.displayName||I||null,n={material:h.material||null,subtype:h.subtype||null,brand:h.brand||null,color_name:h.color_name||null,rgba:h.rgba||null,extra_colors:h.extra_colors||null,effect_type:h.effect_type||null,label_weight:h.label_weight,...s?{}:{core_weight:h.core_weight,core_weight_catalog_id:h.core_weight_catalog_id},slicer_filament:h.slicer_filament||null,slicer_filament_name:t,nozzle_temp_min:null,nozzle_temp_max:null,note:h.note||null,cost_per_kg:h.cost_per_kg,category:h.category.trim()||null,low_stock_threshold_pct:h.low_stock_threshold_pct,...s?{spoolman_filament_id:h.spoolman_filament_id}:{}};(!p||S)&&(n.weight_used=h.weight_used),(!p||w)&&(n.location_id=h.location_id),p?Pe.mutate(n):O>1?Ne.mutate({data:n,qty:O}):Me.mutate(n)},Ke=Me.isPending||Ne.isPending||Pe.isPending||Fe.isPending||Ue.isPending;return(0,G.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[(0,G.jsx)(`div`,{className:`absolute inset-0 bg-black/60 backdrop-blur-sm`,onClick:t}),(0,G.jsxs)(`div`,{className:`relative w-full max-w-xl mx-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl shadow-2xl max-h-[90vh] flex flex-col`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary flex-shrink-0`,children:[(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-baseline gap-2`,children:[l(p?`inventory.editSpool`:m?`inventory.copySpool`:`inventory.addSpool`),p&&n&&(0,G.jsxs)(`span`,{className:`text-sm font-mono text-bambu-gray`,children:[`#`,n.id]})]}),(0,G.jsx)(`button`,{onClick:t,className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,G.jsx)($u,{className:`w-5 h-5`})})]}),r===`create`&&(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2 border-b border-bambu-dark-tertiary flex-shrink-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(td,{className:`w-4 h-4 text-amber-600 dark:text-amber-400`}),(0,G.jsx)(`span`,{className:`text-sm text-white`,children:l(`inventory.quickAdd`)})]}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>{D(!E),E||x(`filament`)},className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors ${E?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,children:(0,G.jsx)(`span`,{className:`inline-block h-3.5 w-3.5 rounded-full bg-white transition-transform ${E?`translate-x-4`:`translate-x-0.5`}`})})]}),(0,G.jsxs)(`div`,{className:`flex border-b border-bambu-dark-tertiary flex-shrink-0`,children:[(0,G.jsxs)(`button`,{onClick:()=>x(`filament`),className:`flex-1 px-4 py-2.5 text-sm font-medium flex items-center justify-center gap-2 transition-colors ${b===`filament`?`text-bambu-green border-b-2 border-bambu-green`:`text-bambu-gray hover:text-white`}`,children:[(0,G.jsx)(Sl,{className:`w-4 h-4`}),l(`inventory.filamentInfoTab`)]}),!E&&(0,G.jsxs)(`button`,{onClick:()=>x(`pa-profile`),className:`flex-1 px-4 py-2.5 text-sm font-medium flex items-center justify-center gap-2 transition-colors ${b===`pa-profile`?`text-bambu-green border-b-2 border-bambu-green`:`text-bambu-gray hover:text-white`}`,children:[(0,G.jsx)(Uo,{className:`w-4 h-4`}),l(`inventory.paProfileTab`),me>0&&(0,G.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded-full bg-bambu-green/20 text-bambu-green`,children:me})]})]}),(0,G.jsx)(`div`,{className:`p-4 overflow-y-auto flex-1`,style:{scrollbarGutter:`stable`},children:b===`filament`?(0,G.jsxs)(`div`,{className:`space-y-6`,children:[s&&!p&&(0,G.jsx)(`div`,{children:_e?(0,G.jsx)(`p`,{className:`text-sm text-red-700 dark:text-red-400 px-1`,children:l(`inventory.spoolmanCatalogLoadFailed`)}):(0,G.jsx)(rQe,{filaments:he,isLoading:ge,selectedId:h.spoolman_filament_id,onSelect:Ae})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`text-sm font-semibold text-bambu-gray uppercase tracking-wide mb-3`,children:l(`inventory.filamentInfo`)}),(0,G.jsx)(QZe,{formData:h,updateField:ke,cloudAuthenticated:A,loadingCloudPresets:M,presetInputValue:I,setPresetInputValue:L,selectedPresetOption:Oe,filamentOptions:ve,availableBrands:we,availableMaterials:Te,suggestedBrands:Ee,suggestedMaterials:De,quickAdd:E,detailsRequired:!E&&!s&&r===`create`,quantity:O,onQuantityChange:k,errors:_})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`text-sm font-semibold text-bambu-gray uppercase tracking-wide mb-3`,children:l(`inventory.color`)}),(0,G.jsx)(eQe,{formData:h,updateField:ke,recentColors:oe,onColorUsed:je,catalogColors:ie})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`text-sm font-semibold text-bambu-gray uppercase tracking-wide mb-3`,children:l(`inventory.additional`)}),(0,G.jsx)(nQe,{formData:h,updateField:ke,spoolCatalog:R,currencySymbol:a,availableCategories:Ve,availableLocations:B,onCreateLocation:async e=>{try{let t=await Z.createLocation({name:e});return V(e=>[...e,{id:t.id,name:t.name}].sort((e,t)=>e.name.localeCompare(t.name))),await x9(u),{id:t.id,name:t.name}}catch(e){return console.error(e),d((e instanceof Error?e.message:l(`locations.saveFailed`))||l(`locations.saveFailed`),`error`),null}},globalLowStockThreshold:He,spoolmanMode:s})]}),p&&n&&!s&&(0,G.jsx)(`div`,{children:(0,G.jsx)(sQe,{spoolId:n.id})})]}):(0,G.jsx)(iQe,{formData:h,updateField:ke,printersWithCalibrations:pe,selectedProfiles:le,setSelectedProfiles:ue,expandedPrinters:de,setExpandedPrinters:fe})}),(0,G.jsxs)(`div`,{className:`flex gap-2 p-4 border-t border-bambu-dark-tertiary flex-shrink-0`,children:[p&&(0,G.jsxs)(`div`,{className:`flex gap-2 mr-auto`,children:[(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>Fe.mutate(),disabled:Ke||!n?.tag_uid,children:[(0,G.jsx)(Cu,{className:`w-4 h-4`}),l(`inventory.clearRfid`,`Clear RFID Tag`)]}),(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>Ue.mutate(),disabled:Ke||!Re,children:[(0,G.jsx)(Lu,{className:`w-4 h-4`}),l(`inventory.unassignSpool`,`Unassign`)]})]}),(0,G.jsxs)(`div`,{className:`flex gap-2 ml-auto`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:t,children:l(`common.cancel`)}),(0,G.jsx)(Q,{onClick:Ge,disabled:Ke,children:Ke?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),l(`common.saving`)]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Wl,{className:`w-4 h-4`}),l(p?`common.save`:m?`inventory.copySpool`:`inventory.addSpool`)]})})]})]})]})]})}var dQe=[{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.`}];function fQe(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 pQe(e){return xf(e)}function mQe(e){return`${e.color_name??`${e.material}${e.subtype?` ${e.subtype}`:``}`}${e.brand?` · ${e.brand}`:``}`}function hQe(e){return[e.color_name,e.material,e.subtype,e.brand,`#${e.id}`].filter(Boolean).join(` `).toLowerCase()}function gQe(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 _Qe({isOpen:e,onClose:t,availableSpools:n,initialSelectedIds:r,spoolmanMode:i}){let{t:a}=U(),{showToast:o}=Bd(),[s,c]=(0,y.useState)(null),[l,u]=(0,y.useState)(new Set),[d,f]=(0,y.useState)(``),[p,m]=(0,y.useState)(``),[h,g]=(0,y.useState)(`id`),[_,v]=(0,y.useState)(!1);(0,y.useEffect)(()=>{if(e){let e=new Set(n.map(e=>e.id));u(new Set(r.filter(t=>e.has(t)))),f(``),m(``),g(`id`),v(!1),c(null)}},[e]);let b=(0,y.useMemo)(()=>{let e=[...n];return h===`color`?(e.sort((e,t)=>{let n=gQe(e.rgba),r=gQe(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,h]),x=(0,y.useMemo)(()=>{let e=new Set;for(let t of b)t.material&&e.add(t.material.toUpperCase());return[...e].sort()},[b]),S=(0,y.useMemo)(()=>{let e=d.trim().toLowerCase();return b.filter(t=>!(p&&(t.material||``).toUpperCase()!==p||e&&!hQe(t).includes(e)))},[b,d,p]),C=S.length>0&&S.every(e=>l.has(e.id));if(!e)return null;let w=l.size,T=w===0;function E(e){u(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function D(){u(e=>{let t=new Set(e);for(let e of S)t.add(e.id);return t})}function O(){u(e=>{let t=new Set(e);for(let e of S)t.delete(e.id);return t})}function k(){u(new Set)}async function A(e){if(T||s)return;let n=b.filter(e=>l.has(e.id)).map(e=>e.id);c(e);try{fQe(i?await Z.printSpoolmanSpoolLabels({spool_ids:n,template:e,monochrome:_}):await Z.printSpoolLabels({spool_ids:n,template:e,monochrome:_})),t()}catch(e){o(a(`inventory.labels.error`,`Could not generate labels: {{msg}}`,{msg:e instanceof Error?e.message:String(e)}),`error`)}finally{c(null)}}return(0,G.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-start sm:items-center justify-center p-4 overflow-y-auto`,children:[(0,G.jsx)(`div`,{className:`absolute inset-0 bg-black/60 backdrop-blur-sm`,onClick:t}),(0,G.jsxs)(`div`,{className:`relative w-full max-w-3xl bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl shadow-2xl max-h-[90vh] overflow-hidden flex flex-col my-auto`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Fl,{className:`w-5 h-5 text-bambu-green`}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:a(`inventory.labels.title`,`Print spool labels`)}),w>0&&(0,G.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[`(`,a(`inventory.labels.selectedCount`,`{{count}} selected`,{count:w}),`)`]})]}),(0,G.jsx)(`button`,{onClick:t,className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,"aria-label":a(`common.close`,`Close`),children:(0,G.jsx)($u,{className:`w-5 h-5`})})]}),(0,G.jsxs)(`div`,{className:`p-4 space-y-2 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(Yl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`}),(0,G.jsx)(`input`,{type:`search`,value:d,onChange:e=>f(e.target.value),placeholder:a(`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`})]}),x.length>1&&(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray mr-1`,children:a(`inventory.labels.filterByMaterial`,`Material:`)}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>m(``),className:`px-2 py-0.5 text-xs rounded-full border transition ${p===``?`bg-bambu-green text-bambu-dark border-bambu-green`:`bg-bambu-dark text-bambu-gray border-bambu-dark-tertiary hover:border-bambu-gray`}`,children:a(`inventory.labels.allMaterials`,`All`)}),x.map(e=>(0,G.jsx)(`button`,{type:`button`,onClick:()=>m(e),className:`px-2 py-0.5 text-xs rounded-full border transition ${p===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,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray mr-1`,children:a(`inventory.labels.sortBy.label`)}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>g(`id`),className:`px-2 py-0.5 text-xs rounded-full border transition ${h===`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:a(`inventory.labels.sortBy.id`)}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>g(`color`),className:`px-2 py-0.5 text-xs rounded-full border transition ${h===`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:a(`inventory.labels.sortBy.color`)})]})]}),(0,G.jsxs)(`div`,{className:`px-4 pt-3 pb-2 flex items-center justify-between gap-3 flex-wrap`,children:[(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:a(`inventory.labels.pickSpools`,`Pick which spools to print labels for:`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-3 text-xs`,children:[(0,G.jsx)(`button`,{type:`button`,onClick:C?O:D,disabled:S.length===0,className:`text-bambu-green hover:underline disabled:opacity-50 disabled:no-underline disabled:cursor-not-allowed`,children:C?a(`inventory.labels.deselectVisible`,`Deselect visible`):a(`inventory.labels.selectVisible`,`Select all visible ({{count}})`,{count:S.length})}),(0,G.jsx)(`button`,{type:`button`,onClick:k,disabled:w===0,className:`text-bambu-gray hover:text-white hover:underline disabled:opacity-50 disabled:no-underline disabled:cursor-not-allowed`,children:a(`inventory.labels.clearAll`,`Clear all`)})]})]}),(0,G.jsx)(`div`,{className:`flex-1 overflow-y-auto px-2 pb-2 min-h-0`,children:S.length===0?(0,G.jsx)(`div`,{className:`text-center text-sm text-bambu-gray py-6`,children:b.length===0?a(`inventory.labels.noSpoolsToShow`,`No spools to show. Adjust your filter and try again.`):a(`inventory.labels.noMatches`,`No spools match the current search or filter.`)}):(0,G.jsx)(`ul`,{className:`space-y-0.5`,children:S.map(e=>{let t=l.has(e.id);return(0,G.jsx)(`li`,{children:(0,G.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,G.jsx)(hu,{className:`w-4 h-4 text-bambu-green shrink-0`}):(0,G.jsx)(_u,{className:`w-4 h-4 text-bambu-gray shrink-0`}),(0,G.jsx)(`input`,{type:`checkbox`,checked:t,onChange:()=>E(e.id),className:`sr-only`}),(0,G.jsx)(`span`,{className:`w-4 h-4 rounded border border-black/20 shrink-0`,style:pQe(e.rgba)}),(0,G.jsx)(`span`,{className:`flex-1 min-w-0 truncate text-sm text-white`,children:mQe(e)}),(0,G.jsxs)(`span`,{className:`text-xs font-mono text-bambu-gray shrink-0`,children:[`#`,e.id]})]})},e.id)})})}),(0,G.jsx)(`div`,{className:`px-4 pt-2 pb-1 border-t border-bambu-dark-tertiary`,children:(0,G.jsxs)(`label`,{className:`inline-flex items-center gap-2 cursor-pointer select-none`,children:[_?(0,G.jsx)(hu,{className:`w-4 h-4 text-bambu-green shrink-0`}):(0,G.jsx)(_u,{className:`w-4 h-4 text-bambu-gray shrink-0`}),(0,G.jsx)(`input`,{type:`checkbox`,checked:_,onChange:e=>v(e.target.checked),className:`sr-only`}),(0,G.jsx)(`span`,{className:`text-sm text-white`,children:a(`inventory.labels.monochrome`,`Monochrome (black & white printer)`)}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:a(`inventory.labels.monochromeHint`,`Drops the colour swatch and widens the text`)})]})}),(0,G.jsx)(`div`,{className:`px-3 pt-1 pb-2 grid grid-cols-1 sm:grid-cols-2 gap-2`,children:dQe.map(e=>{let t=s===e.value,n=a(`inventory.labels.templates.${e.i18nKey}.label`,e.fallbackLabel),r=a(`inventory.labels.templates.${e.i18nKey}.hint`,e.fallbackHint);return(0,G.jsxs)(`button`,{disabled:T||s!==null,onClick:()=>A(e.value),title:`${n} — ${r}`,className:`w-full text-left p-2.5 rounded-lg border border-bambu-dark-tertiary bg-bambu-dark hover:border-bambu-green hover:bg-bambu-green/10 disabled:opacity-50 disabled:cursor-not-allowed disabled:hover:border-bambu-dark-tertiary disabled:hover:bg-bambu-dark transition flex items-center gap-3`,children:[(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`div`,{className:`font-medium text-white text-sm truncate`,children:n}),(0,G.jsx)(`div`,{className:`text-xs text-bambu-gray mt-0.5 truncate`,children:r})]}),t&&(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin text-bambu-green shrink-0`})]},e.value)})}),(0,G.jsx)(`div`,{className:`flex justify-end gap-2 px-5 py-2 border-t border-bambu-dark-tertiary`,children:(0,G.jsx)(Q,{variant:`secondary`,onClick:t,disabled:s!==null,children:a(`common.cancel`,`Cancel`)})})]})]})}function vQe({onClose:e,onImported:t}){let{t:n}=U(),[r,i]=(0,y.useState)(null),[a,o]=(0,y.useState)(!1),[s,c]=(0,y.useState)(null),[l,u]=(0,y.useState)(!1),[d,f]=(0,y.useState)(!1),[p,m]=(0,y.useState)(null),h=(0,y.useRef)(null),g=async e=>{i(e),c(null),m(null),u(!0);try{c(await Z.importSpoolsCsvPreview(e))}catch(e){m(e instanceof Error?e.message:n(`inventory.csv.previewError`,`Could not read the CSV file`))}finally{u(!1)}},_=e=>{let t=e.target.files?.[0];t&&g(t)},v=e=>{e.preventDefault(),o(!1);let t=e.dataTransfer.files?.[0];t&&g(t)},b=async()=>{if(r){f(!0),m(null);try{t((await Z.importSpoolsCsv(r)).created)}catch(e){m(e instanceof Error?e.message:n(`inventory.csv.importError`,`Import failed`)),f(!1)}}},x=e=>e===`valid`?(0,G.jsx)(ys,{className:`w-4 h-4 text-green-500 flex-shrink-0`}):e===`error`?(0,G.jsx)(Ts,{className:`w-4 h-4 text-red-500 flex-shrink-0`}):(0,G.jsx)(Ss,{className:`w-4 h-4 text-bambu-gray flex-shrink-0`}),S=s?.valid_count??0;return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,children:(0,G.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,G.jsxs)(`div`,{className:`p-4 border-b border-bambu-dark-tertiary flex items-center justify-between`,children:[(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:n(`inventory.csv.modalTitle`,`Import spools from CSV`)}),(0,G.jsx)(`button`,{onClick:e,className:`p-1 hover:bg-bambu-dark rounded`,children:(0,G.jsx)($u,{className:`w-5 h-5 text-bambu-gray`})})]}),(0,G.jsxs)(`div`,{className:`p-4 space-y-4 overflow-y-auto flex-1`,children:[(0,G.jsxs)(`div`,{onDragOver:e=>{e.preventDefault(),o(!0)},onDragLeave:e=>{e.preventDefault(),o(!1)},onDrop:v,onClick:()=>h.current?.click(),className:`border-2 border-dashed rounded-lg p-6 text-center cursor-pointer transition-colors ${a?`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary hover:border-bambu-green/50`}`,children:[(0,G.jsx)(Ru,{className:`w-9 h-9 mx-auto mb-2 ${a?`text-bambu-green`:`text-bambu-gray`}`}),r?(0,G.jsxs)(`p`,{className:`text-white font-medium flex items-center justify-center gap-2`,children:[(0,G.jsx)(lc,{className:`w-4 h-4`}),` `,r.name]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`p`,{className:`text-white font-medium`,children:n(`inventory.csv.selectFile`,`Choose a CSV file or drag it here`)}),(0,G.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,G.jsx)(`input`,{ref:h,type:`file`,accept:`.csv,text/csv`,className:`hidden`,onChange:_}),l&&(0,G.jsxs)(`div`,{className:`flex items-center justify-center gap-2 text-bambu-gray py-4`,children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),n(`inventory.csv.parsing`,`Reading file…`)]}),p&&(0,G.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,G.jsx)(Ts,{className:`w-5 h-5 text-red-600 dark:text-red-400 mt-0.5 flex-shrink-0`}),(0,G.jsx)(`p`,{className:`text-sm text-red-700 dark:text-red-300 break-words`,children:p})]}),s&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-3 text-sm`,children:[(0,G.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:s.valid_count})}),(0,G.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:s.error_count})}),(0,G.jsx)(`span`,{className:`px-2 py-1 rounded bg-bambu-dark text-bambu-gray`,children:n(`inventory.csv.skippedCount`,`{{count}} skipped`,{count:s.skipped_count})})]}),s.warnings.length>0&&(0,G.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:s.warnings.map((e,t)=>(0,G.jsx)(`p`,{className:`text-xs text-yellow-700 dark:text-yellow-300`,children:e},t))}),s.rows.length>0&&(0,G.jsx)(`div`,{className:`border border-bambu-dark-tertiary rounded-lg overflow-hidden`,children:(0,G.jsx)(`div`,{className:`max-h-72 overflow-y-auto`,children:(0,G.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,G.jsx)(`thead`,{className:`bg-bambu-dark sticky top-0`,children:(0,G.jsxs)(`tr`,{className:`text-left text-bambu-gray`,children:[(0,G.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:n(`inventory.csv.colRow`,`Row`)}),(0,G.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:n(`inventory.csv.colStatus`,`Status`)}),(0,G.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:n(`inventory.material`,`Material`)}),(0,G.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:n(`inventory.brand`,`Brand`)}),(0,G.jsx)(`th`,{className:`px-3 py-2 font-medium`,children:n(`inventory.csv.colColor`,`Color`)})]})}),(0,G.jsx)(`tbody`,{children:s.rows.map(e=>(0,G.jsxs)(`tr`,{className:`border-t border-bambu-dark-tertiary`,children:[(0,G.jsx)(`td`,{className:`px-3 py-2 text-bambu-gray`,children:e.row_number}),(0,G.jsx)(`td`,{className:`px-3 py-2`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[x(e.status),e.status===`error`&&e.reason&&(0,G.jsx)(`span`,{className:`text-xs text-red-700 dark:text-red-400 break-words`,children:e.reason})]})}),(0,G.jsx)(`td`,{className:`px-3 py-2 text-white`,children:e.material||`—`}),(0,G.jsx)(`td`,{className:`px-3 py-2 text-white`,children:e.brand||`—`}),(0,G.jsx)(`td`,{className:`px-3 py-2`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.rgba&&(0,G.jsx)(`span`,{className:`inline-block w-4 h-4 rounded-full border border-bambu-dark-tertiary flex-shrink-0`,style:xf(e.rgba)}),(0,G.jsx)(`span`,{className:`text-white`,children:e.color_name||`—`}),e.resolved_color&&!e.cross_material_color&&(0,G.jsx)(`span`,{title:n(`inventory.csv.colorResolved`,`Color filled from catalog`),children:(0,G.jsx)(Ku,{className:`w-3.5 h-3.5 text-bambu-green flex-shrink-0`})}),e.cross_material_color&&(0,G.jsx)(`span`,{title:n(`inventory.csv.colorCrossMaterial`,`Color taken from a different material — no exact match in catalog`),children:(0,G.jsx)(Pu,{className:`w-3.5 h-3.5 text-yellow-500 flex-shrink-0`})}),e.duplicate_of_existing&&(0,G.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,G.jsx)(zs,{className:`w-3.5 h-3.5 text-amber-600 dark:text-amber-400 flex-shrink-0`})})]})})]},e.row_number))})]})})})]})]}),(0,G.jsxs)(`div`,{className:`p-4 border-t border-bambu-dark-tertiary flex justify-end gap-2`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:e,disabled:d,children:n(`common.cancel`)}),(0,G.jsx)(Q,{onClick:b,disabled:!s||S===0||d,children:d?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 mr-2 animate-spin`}),n(`inventory.csv.importing`,`Importing…`)]}):S>0?n(`inventory.csv.importValidRows`,`Import {{count}} valid rows`,{count:S}):n(`inventory.csv.noValidRows`,`No valid rows`)})]})]})})}function yQe({open:e,onClose:t,onPickLocation:n}){let{t:r}=U(),i=so(),{showToast:a}=Bd(),[o,s]=(0,y.useState)(!1),[c,l]=(0,y.useState)(null),[u,d]=(0,y.useState)(``),[f,p]=(0,y.useState)(null),{data:m=[],isLoading:h}=K({queryKey:b9,queryFn:Z.getLocations,enabled:e}),g=()=>{x9(i),i.invalidateQueries({queryKey:[`inventory-spools`]}),i.invalidateQueries({queryKey:[`spoolman-inventory-spools`]})},_=q({mutationFn:async()=>{let e=u.trim();if(!e)throw Error(r(`locations.nameRequired`));return c?Z.updateLocation(c.id,{name:e}):Z.createLocation({name:e})},onSuccess:()=>{a(r(c?`locations.updated`:`locations.created`),`success`),s(!1),l(null),d(``),g()},onError:e=>{a(e.message||r(`locations.saveFailed`),`error`)}}),v=q({mutationFn:e=>Z.deleteLocation(e),onSuccess:()=>{a(r(`locations.deleted`),`success`),p(null),g()},onError:e=>{a(e.message||r(`locations.deleteFailed`),`error`)}}),b=()=>{l(null),d(``),s(!0)},x=e=>{l(e),d(e.name),s(!0)},S=(0,y.useCallback)(()=>{_.isPending||(s(!1),l(null),d(``))},[_.isPending]);(0,y.useEffect)(()=>{if(!e)return;let n=e=>{e.key===`Escape`&&(_.isPending||v.isPending||(o?S():f||t()))};return document.addEventListener(`keydown`,n),()=>document.removeEventListener(`keydown`,n)},[e,o,f,_.isPending,v.isPending,S,t]);let C=e=>{e.preventDefault(),_.mutate()};if(!e)return null;let w=`locations-modal-title`,T=`location-editor-title`;return(0,G.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[(0,G.jsx)(`div`,{className:`absolute inset-0 bg-black/60`,onClick:()=>{_.isPending||v.isPending||t()}}),(0,G.jsxs)(`div`,{className:`relative w-full max-w-2xl 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":w,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-4 px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`h2`,{id:w,className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(il,{className:`w-5 h-5 text-bambu-green`}),r(`locations.title`)]}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-sm mt-0.5`,children:r(`locations.subtitle`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(Q,{onClick:b,children:[(0,G.jsx)(Ml,{className:`w-4 h-4`}),r(`locations.add`)]}),(0,G.jsx)(`button`,{type:`button`,className:`p-1.5 text-bambu-gray hover:text-white rounded`,onClick:t,"aria-label":r(`common.close`),children:(0,G.jsx)($u,{className:`w-5 h-5`})})]})]}),(0,G.jsx)(`div`,{className:`overflow-y-auto`,children:h?(0,G.jsxs)(`div`,{className:`flex items-center justify-center py-16 text-bambu-gray`,children:[(0,G.jsx)(Y,{className:`w-6 h-6 animate-spin mr-2`}),r(`common.loading`)]}):m.length===0?(0,G.jsx)(`div`,{className:`py-16 text-center text-bambu-gray`,children:r(`locations.empty`)}):(0,G.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,G.jsx)(`thead`,{children:(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary text-left text-bambu-gray`,children:[(0,G.jsx)(`th`,{className:`px-4 py-3 font-medium`,children:r(`locations.name`)}),(0,G.jsx)(`th`,{className:`px-4 py-3 font-medium text-right`,children:r(`locations.spools`)}),(0,G.jsx)(`th`,{className:`px-4 py-3 font-medium text-right w-32`,children:r(`common.actions`)})]})}),(0,G.jsx)(`tbody`,{children:m.map(e=>(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/60 hover:bg-bambu-dark-tertiary/30 cursor-pointer`,onClick:()=>{n&&(n(e.id),t())},children:[(0,G.jsx)(`td`,{className:`px-4 py-3 text-white font-medium`,children:e.name}),(0,G.jsx)(`td`,{className:`px-4 py-3 text-right text-bambu-gray`,children:e.spool_count}),(0,G.jsx)(`td`,{className:`px-4 py-3 text-right`,onClick:e=>e.stopPropagation(),children:(0,G.jsxs)(`div`,{className:`flex items-center justify-end gap-1`,children:[(0,G.jsx)(`button`,{type:`button`,className:`p-1.5 text-bambu-gray hover:text-bambu-green rounded`,onClick:()=>x(e),title:r(`common.edit`),"aria-label":r(`locations.editAria`,{name:e.name,defaultValue:`Edit ${e.name}`}),children:(0,G.jsx)(Ol,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{type:`button`,className:`p-1.5 text-bambu-gray hover:text-red-600 dark:hover:text-red-400 rounded disabled:opacity-40`,disabled:e.spool_count>0,onClick:()=>p(e),title:e.spool_count>0?r(`locations.deleteBlocked`):r(`common.delete`),"aria-label":r(`locations.deleteAria`,{name:e.name,defaultValue:`Delete ${e.name}`}),children:(0,G.jsx)(ju,{className:`w-4 h-4`})})]})})]},e.id))})]})})]}),o&&(0,G.jsxs)(`div`,{className:`fixed inset-0 z-[60] flex items-center justify-center`,children:[(0,G.jsx)(`div`,{className:`absolute inset-0 bg-black/60`,onClick:S}),(0,G.jsxs)(`div`,{className:`relative w-full max-w-md mx-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl p-6 shadow-2xl`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":T,children:[(0,G.jsx)(`h3`,{id:T,className:`text-lg font-semibold text-white mb-4`,children:r(c?`locations.edit`:`locations.add`)}),(0,G.jsxs)(`form`,{onSubmit:C,children:[(0,G.jsx)(`label`,{className:`block text-sm font-medium text-bambu-gray mb-1`,htmlFor:`location-name`,children:r(`locations.name`)}),(0,G.jsx)(`input`,{id:`location-name`,type:`text`,maxLength:255,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 mb-4`,placeholder:r(`locations.createPlaceholder`),value:u,onChange:e=>d(e.target.value),autoFocus:!0}),(0,G.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:S,children:r(`common.cancel`)}),(0,G.jsxs)(Q,{type:`submit`,disabled:_.isPending||!u.trim(),children:[_.isPending&&(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),r(`common.save`)]})]})]})]})]}),f&&(0,G.jsx)(Zd,{title:r(`locations.confirmDelete`,{name:f.name}),message:r(`locations.confirmDeleteMessage`),confirmText:r(`common.delete`),variant:`danger`,isLoading:v.isPending,onConfirm:()=>v.mutate(f.id),onCancel:()=>p(null)})]})}var S9=[{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`},{id:`low_stock_threshold_pct`,type:`number`,labelKey:`inventory.lowStockThresholdOverride`,min:1,max:99,step:1}];function bQe({value:e,onChange:t,options:n,allowCustom:r,placeholderKey:i,disabled:a}){let{t:o}=U(),s=(0,y.useRef)(null),[c,l]=(0,y.useState)(!1),[u,d]=(0,y.useState)(``);(0,y.useEffect)(()=>{if(!c)return;let e=e=>{s.current&&!s.current.contains(e.target)&&(l(!1),d(``))},t=e=>{e.key===`Escape`&&(l(!1),d(``))};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[c]);let f=c?u:n.find(t=>t.value===e)?.label??e,p=(0,y.useMemo)(()=>{if(!c)return n;let e=u.trim().toLowerCase();return e?n.filter(t=>t.label.toLowerCase().includes(e)||t.value.toLowerCase().includes(e)):n},[c,u,n]),m=c&&u.trim()&&!n.some(e=>e.value.toLowerCase()===u.trim().toLowerCase());return(0,G.jsxs)(`div`,{className:`relative`,ref:s,children:[(0,G.jsx)(`input`,{type:`text`,disabled:a,value:f,onChange:e=>{d(e.target.value),l(!0),r&&t(e.target.value)},onFocus:()=>{l(!0),d(``)},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,G.jsx)(ds,{className:`absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50 pointer-events-none`}),c&&(0,G.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:[p.length===0&&!r&&(0,G.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:o(`inventory.noResults`)}),p.map(n=>(0,G.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),l(!1),d(``)},children:n.label},n.value)),r&&m&&(0,G.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(u.trim()),l(!1),d(``)},children:o(`inventory.bulk.useCustom`,{value:u.trim()})})]})]})}function C9(...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 xQe({isOpen:e,selectedCount:t,isPending:n,availableLocations:r,availableMaterials:i,availableSubtypes:a,availableBrands:o,availableCategories:s,availableSlicerFilaments:c,availableSlicerFilamentNames:l,onClose:u,onApply:d}){let{t:f}=U(),{data:p=[]}=K({queryKey:[`bulk-edit-cloud-presets`],enabled:e,staleTime:300*1e3,queryFn:async()=>{let e=[];try{if((await Z.getCloudStatus()).is_authenticated){let t=await Z.getFilamentPresets();e.push(...t)}}catch{}try{if((await Z.orcaCloudStatus()).connected){let t=await Z.orcaCloudListProfiles();e.push(...t.filament)}}catch{}return e}}),{data:m}=K({queryKey:[`bulk-edit-local-presets`],enabled:e,staleTime:300*1e3,queryFn:Z.getLocalPresets}),{data:h=[]}=K({queryKey:[`builtin-filaments`],enabled:e,staleTime:300*1e3,queryFn:Z.getBuiltinFilaments}),g=(0,y.useMemo)(()=>hU(p,new Set,m?.filament??[],h),[p,m,h]),[_,v]=(0,y.useState)({}),b=(0,y.useMemo)(()=>C9(oU,i).map(e=>({value:e,label:e})),[i]),x=(0,y.useMemo)(()=>C9(cU,a).map(e=>({value:e,label:e})),[a]),S=(0,y.useMemo)(()=>C9(sU,o).map(e=>({value:e,label:e})),[o]),C=(0,y.useMemo)(()=>C9(s).map(e=>({value:e,label:e})),[s]),w=(0,y.useMemo)(()=>{let e=g.map(e=>({value:e.code,label:e.displayName})),t=c.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))},[g,c]),T=(0,y.useMemo)(()=>{let e=g.map(e=>({value:e.displayName,label:e.displayName})),t=l.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))},[g,l]),E=(0,y.useMemo)(()=>r.map(e=>({value:String(e.id),label:e.name})),[r]);if(!e)return null;let D=(e,t)=>{v(n=>({...n,[e]:t}))},O=e=>{v(t=>{let n={...t};return delete n[e],n})},k=(()=>{let e={};for(let t of S9){let n=_[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})(),A=Object.keys(k).length>0,j=S9.some(e=>{let t=_[e.id];return t===void 0||t.trim()===``?!1:k[e.id]===void 0}),M=e=>e===`material`?b:e===`subtype`?x:e===`brand`?S:e===`category`?C:e===`slicer_filament`?w:e===`slicer_filament_name`?T:e===`location_id`?E:[],N=e=>{let t=_[e.id]??``;if(e.type===`searchable`||e.type===`searchableClosed`)return(0,G.jsx)(bQe,{value:t,onChange:t=>{t===``?O(e.id):D(e.id,t)},options:M(e.id),allowCustom:e.type===`searchable`,disabled:n});if(e.type===`textarea`)return(0,G.jsx)(`textarea`,{disabled:n,value:t,onChange:t=>D(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,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`input`,{type:`color`,disabled:n,value:`#${(t||`808080`).replace(/^#/,``).slice(0,6)}`,onChange:t=>D(e.id,t.target.value.replace(/^#/,``).toUpperCase()),className:`h-9 w-12 rounded cursor-pointer`}),(0,G.jsx)(`input`,{type:`text`,disabled:n,value:t,onChange:t=>D(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,G.jsx)(`p`,{className:`mt-1 text-xs text-red-600 dark:text-red-400`,children:f(`inventory.bulk.invalidHex`)})]})}return(0,G.jsx)(`input`,{type:e.type===`number`?`number`:`text`,disabled:n,value:t,onChange:t=>D(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,G.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center p-4 z-50`,onClick:n?void 0:u,children:(0,G.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,G.jsxs)(`div`,{className:`flex items-center justify-between p-5 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:f(`inventory.bulk.editTitle`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-0.5`,children:f(`inventory.bulk.editSubtitle`,{count:t})})]}),(0,G.jsx)(`button`,{onClick:u,disabled:n,className:`p-1 text-bambu-gray hover:text-white transition-colors`,"aria-label":f(`common.close`),children:(0,G.jsx)($u,{className:`w-5 h-5`})})]}),(0,G.jsx)(`p`,{className:`px-5 pt-4 text-xs text-bambu-gray`,children:f(`inventory.bulk.editHint`)}),(0,G.jsx)(`div`,{className:`flex-1 overflow-y-auto p-5 space-y-3`,children:S9.map(e=>{let t=_[e.id]!==void 0;return(0,G.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,G.jsx)(`div`,{className:`pt-2`,children:(0,G.jsx)(`input`,{type:`checkbox`,className:`h-4 w-4 cursor-pointer`,checked:t,onChange:t=>{t.target.checked?D(e.id,``):O(e.id)},"aria-label":f(`inventory.bulk.toggleField`)})}),(0,G.jsxs)(`div`,{className:`flex-1`,children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:f(e.labelKey)}),N(e)]})]},e.id)})}),(0,G.jsxs)(`div`,{className:`flex items-center gap-3 p-5 border-t border-bambu-dark-tertiary`,children:[(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:f(`inventory.bulk.changeCount`,{count:Object.keys(k).length})}),(0,G.jsxs)(`div`,{className:`ml-auto flex gap-2`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:u,disabled:n,children:f(`common.cancel`)}),(0,G.jsx)(Q,{onClick:()=>d(k),disabled:!A||n||j,children:n?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 mr-2 animate-spin`}),f(`inventory.bulk.applyPending`)]}):f(`inventory.bulk.applyButton`,{count:t})})]})]})]})})}function SQe(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 w9(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 CQe(e){return`${e.material}|${e.subtype||``}|${e.brand||``}|${e.color_name||``}|${e.rgba||``}|${e.extra_colors||``}|${e.effect_type||``}|${e.label_weight}`}var wQe=`bambuddy-inventory-columns`,T9=[{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:`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:`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 TQe(){try{let e=localStorage.getItem(wQe);if(e){let t=JSON.parse(e),n=new Set(T9.map(e=>e.id)),r=new Set(t.map(e=>e.id)),i=t.filter(e=>n.has(e.id)),a=T9.filter(e=>!r.has(e.id));return[...i,...a]}}catch{}return T9.map(e=>({...e}))}function EQe(e){try{localStorage.setItem(wQe,JSON.stringify(e))}catch{}}function E9(e,t=!1){return t&&e>=1e3?`${(e/1e3).toFixed(1)}kg`:`${Math.round(e)}g`}var DQe={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 D9(e,t=`system`){if(!e)return`-`;let n=Kf(e);return n?Rf(n,t):`-`}var OQe={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`),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`),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`)},O9={id:({spool:e})=>(0,G.jsx)(`span`,{className:`text-sm font-medium text-white`,children:e.id}),added_time:({spool:e,dateFormat:t})=>(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:D9(e.created_at,t)}),encode_time:({spool:e,dateFormat:t})=>(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:D9(e.encode_time,t)}),last_used_time:({spool:e,dateFormat:t})=>(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.last_used?D9(e.last_used,t):`Never`}),rgba:({spool:e})=>(0,G.jsx)(`div`,{className:`flex items-center justify-center`,children:(0,G.jsx)(g6,{rgba:e.rgba,extraColors:e.extra_colors,effectType:e.effect_type,effectSize:`table`,subtype:e.subtype})}),material:({spool:e})=>(0,G.jsx)(`span`,{className:`text-sm text-white`,children:e.material}),subtype:({spool:e})=>(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.subtype||`-`}),color_name:({spool:e})=>(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:yf(e.color_name,e.rgba)||`-`}),brand:({spool:e})=>(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.brand||`-`}),slicer_filament:({spool:e})=>(0,G.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,G.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,G.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,` `,dp(n.ams_id,n.tray_id,a,i),n.ams_label?` (${n.ams_label})`:``]})},storage_location:({spool:e})=>e.storage_location?(0,G.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,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:`-`}),label_weight:({spool:e})=>(0,G.jsx)(`span`,{className:`text-sm text-white`,children:E9(e.label_weight)}),net:({remaining:e})=>(0,G.jsx)(`span`,{className:`text-sm text-white`,children:E9(e)}),gross:({spool:e,remaining:t})=>(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:E9(t+e.core_weight)}),added_full:({spool:e})=>(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.added_full==null?`-`:e.added_full?`Yes`:`No`}),used:({spool:e})=>(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.weight_used>0?E9(e.weight_used):`-`}),printed_total:()=>(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray/50`,children:`-`}),printed_since_weight:()=>(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray/50`,children:`-`}),note:({spool:e})=>(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray max-w-[150px] truncate block`,title:e.note||void 0,children:e.note||`-`}),pa_k:({spool:e})=>(e.k_profiles?.length??0)===0?(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:`-`}):(0,G.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,G.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,G.jsx)(`span`,{className:`text-sm text-bambu-gray/50`,children:`-`})},data_origin:({spool:e})=>(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.data_origin||`-`}),tag_type:({spool:e})=>(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.tag_type||`-`}),stock:({spool:e,t})=>e.slicer_filament?(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:`-`}):(0,G.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,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`div`,{className:`flex-1 h-2 bg-bambu-dark-tertiary rounded-full overflow-hidden`,children:(0,G.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,G.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,G.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,G.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,G.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;n0?`+${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,G.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,G.jsxs)(`span`,{children:[Math.round(n),`g`]}),o?(0,G.jsx)(us,{className:`w-3 h-3`}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Pu,{className:`w-3 h-3`}),t&&(0,G.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,G.jsx)(zl,{className:`w-3.5 h-3.5`})})]})]})}},k9={id:e=>e.id,added_time:e=>e.created_at||``,encode_time:e=>e.encode_time||``,last_used_time:e=>e.last_used||``,material:e=>(e.material||``).toLowerCase(),subtype:e=>(e.subtype||``).toLowerCase(),color_name:e=>(e.color_name||``).toLowerCase(),rgba:e=>_f(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||``} ${dp(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(),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)}},A9=`bambuddy-inventory-sort`;function kQe(){try{let e=localStorage.getItem(A9);if(e)return JSON.parse(e)}catch{}return null}function AQe(e){try{e?localStorage.setItem(A9,JSON.stringify(e)):localStorage.removeItem(A9)}catch{}}function jQe(){let{data:e}=K({queryKey:[`spoolman-settings`],queryFn:Z.getSpoolmanSettings,staleTime:300*1e3}),t=e!==void 0;return(0,G.jsx)(MQe,{spoolmanMode:e?.spoolman_enabled===`true`&&!!e?.spoolman_url,spoolmanModeReady:t})}function MQe({spoolmanMode:e=!1,spoolmanModeReady:t=!0}){let{t:n}=U(),r=so(),{showToast:i}=Bd(),{hasPermission:a,loading:o}=Ed(),s=!o&&a(`inventory:forecast_read`),[c,l]=Li(),[u,d]=(0,y.useState)(null),f=(0,y.useRef)(!1),[p,m]=(0,y.useState)(null),[h,g]=(0,y.useState)(null),[_,v]=(0,y.useState)(!1),[b,x]=(0,y.useState)(!1),[S,C]=(0,y.useState)(!1),[w,T]=(0,y.useState)(`active`),[E,D]=(0,y.useState)(`all`),[O,k]=(0,y.useState)(``),[A,j]=(0,y.useState)(``),[M,N]=(0,y.useState)(``),[P,F]=(0,y.useState)(``),[I,L]=(0,y.useState)(`all`),[R,z]=(0,y.useState)(``),[B,V]=(0,y.useState)(`table`),[ee,te]=(0,y.useState)(kQe),[ne,re]=(0,y.useState)(TQe),[ie,ae]=(0,y.useState)(!1),[oe,se]=(0,y.useState)(()=>{try{return localStorage.getItem(`bambuddy-inventory-group`)===`true`}catch{return!1}}),[H,ce]=(0,y.useState)(new Set),[le,ue]=(0,y.useState)(new Set),[de,fe]=(0,y.useState)(!1),[pe,me]=(0,y.useState)(null),he=(0,y.useCallback)(e=>{ue(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),ge=(0,y.useCallback)(()=>ue(new Set),[]);(0,y.useEffect)(()=>{ue(new Set)},[w,E,O,A,M,P,I,R]);let[_e,ve]=(0,y.useState)(0),[ye,be]=(0,y.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:xe}=K({queryKey:[`settings`],queryFn:Z.getSettings}),Se=xe?.date_format||`system`,Ce=e?[`spoolman-inventory-spools`]:[`inventory-spools`],we=()=>cQe(r,Ce),{data:Te,isLoading:Ee}=K({queryKey:Ce,queryFn:()=>e?Z.getSpoolmanInventorySpools(!0):Z.getSpools(!0),refetchInterval:3e4}),De=(0,y.useCallback)(async()=>{x(!0);try{await Z.exportSpoolsCsv()}catch(e){i(e instanceof Error?e.message:n(`inventory.csv.exportError`,`Export failed`),`error`)}finally{x(!1)}},[i,n]),Oe=e?n(`inventory.csv.spoolmanHint`,`In Spoolman mode, use Spoolman's built-in CSV import/export.`):void 0,{data:ke=[]}=K({queryKey:b9,queryFn:Z.getLocations}),Ae=c.get(`location_id`),je=Ae===`__none__`?`__none__`:Ae&&/^\d+$/.test(Ae)&&Number(Ae)>0?Ae:``,Me=c.get(`spool`),Ne=Me&&/^\d+$/.test(Me)&&Number(Me)>0?Number(Me):null,Pe=Te?.find(e=>e.id===Ne)??null,Fe=(0,y.useCallback)(()=>{f.current=!0,l(e=>(e.delete(`spool`),e),{replace:!0})},[l]),{data:Ie,isError:Le,error:Re}=K({queryKey:e?[`spoolman-inventory-spool`,Ne]:[`inventory-spool`,Ne],queryFn:()=>e?Z.getSpoolmanInventorySpool(Ne):Z.getSpool(Ne),enabled:t&&Ne!==null&&Pe===null,staleTime:1/0,retry:(e,t)=>e<2&&!(t instanceof id&&t.status===404)});(0,y.useEffect)(()=>{if(!f.current){if(t&&Ne&&Pe){Fe(),d({spool:Pe,mode:`edit`});return}if(Ie){Fe(),d({spool:Ie,mode:`edit`});return}Le&&(Fe(),i(n(Re instanceof id&&Re.status===404?`inventory.deepLinkSpoolNotFound`:`inventory.deepLinkFetchFailed`),`error`))}},[t,Ne,Pe,Ie,Le,Re,Fe,i,n]);let{data:ze}=K({queryKey:[`spool-assignments`],queryFn:()=>Z.getAssignments(),refetchInterval:3e4}),{data:Be=[],isError:Ve}=K({queryKey:[`spoolman-slot-assignments-all`],queryFn:()=>Z.getSpoolmanSlotAssignments(),enabled:e,refetchInterval:3e4,staleTime:1e4,retry:1}),He=(0,y.useRef)(!1);(0,y.useEffect)(()=>{Ve&&!He.current?(He.current=!0,i(n(`inventory.spoolmanUnreachable`),`error`)):Ve||(He.current=!1)},[Ve,i,n]);let{data:Ue}=K({queryKey:[`spool-catalog`],queryFn:()=>Z.getSpoolCatalog()}),We=q({mutationFn:t=>e?Z.deleteSpoolmanInventorySpool(t):Z.deleteSpool(t),onSuccess:()=>{we(),i(n(`inventory.spoolDeleted`),`success`)},onError:e=>{e instanceof id&&e.status===404?i(n(`inventory.deleteSpoolNotFound`),`error`):e instanceof id&&e.status===503?i(n(`inventory.spoolmanUnreachable`),`error`):i(n(`inventory.deleteFailed`),`error`)}}),Ge=q({mutationFn:t=>e?Z.archiveSpoolmanInventorySpool(t):Z.archiveSpool(t),onSuccess:()=>{we(),i(n(`inventory.spoolArchived`),`success`)},onError:e=>{e instanceof id&&e.status===404?i(n(`inventory.archiveSpoolNotFound`),`error`):e instanceof id&&e.status===503?i(n(`inventory.spoolmanUnreachable`),`error`):i(n(`inventory.archiveFailed`),`error`)}}),Ke=q({mutationFn:t=>e?Z.restoreSpoolmanInventorySpool(t):Z.restoreSpool(t),onSuccess:()=>{we(),i(n(`inventory.spoolRestored`),`success`)},onError:e=>{e instanceof id&&e.status===404?i(n(`inventory.restoreSpoolNotFound`),`error`):e instanceof id&&e.status===503?i(n(`inventory.spoolmanUnreachable`),`error`):i(n(`inventory.restoreFailed`),`error`)}}),qe=q({mutationFn:t=>e?Z.resetSpoolmanInventorySpoolConsumedCounter(t):Z.resetSpoolConsumedCounter(t),onSuccess:()=>{r.invalidateQueries({queryKey:Ce}),i(n(`inventory.consumedCounterReset`),`success`)},onError:()=>{i(n(`inventory.resetConsumedCounterFailed`),`error`)}}),Je=q({mutationFn:t=>e?Z.bulkResetSpoolmanInventorySpoolConsumedCounter(t):Z.bulkResetSpoolConsumedCounter(t),onSuccess:e=>{r.invalidateQueries({queryKey:Ce}),i(n(`inventory.allConsumedCountersReset`,{count:e.reset}),`success`),me(null),ge()},onError:()=>{i(n(`inventory.resetConsumedCounterFailed`),`error`)}}),Ye=e=>(e.not_found?.length??0)+(e.errors?.length??0),Xe=q({mutationFn:async({ids:t,update:n})=>e?Z.bulkUpdateSpoolmanInventorySpools(t,n):Z.bulkUpdateSpools(t,n),onSuccess:e=>{we();let t=Ye(e);if(e.updated===0){i(n(`inventory.bulk.updateAllFailed`,{count:t}),`error`);return}t>0?i(n(`inventory.bulk.updatePartial`,{ok:e.updated,failed:t}),`warning`):i(n(`inventory.bulk.updateSuccess`,{count:e.updated}),`success`),fe(!1),ge()},onError:e=>{i(e.message||n(`inventory.bulk.updateFailed`),`error`)}}),Ze=q({mutationFn:async t=>e?Z.bulkDeleteSpoolmanInventorySpools(t):Z.bulkDeleteSpools(t),onSuccess:e=>{we();let t=Ye(e);if(e.deleted===0){i(n(`inventory.bulk.deleteAllFailed`,{count:t}),`error`);return}t>0?i(n(`inventory.bulk.deletePartial`,{ok:e.deleted,failed:t}),`warning`):i(n(`inventory.bulk.deleteSuccess`,{count:e.deleted}),`success`),me(null),ge()},onError:e=>{i(e.message||n(`inventory.bulk.deleteFailed`),`error`)}}),Qe=q({mutationFn:async t=>e?Z.bulkArchiveSpoolmanInventorySpools(t):Z.bulkArchiveSpools(t),onSuccess:e=>{we();let t=Ye(e);if(e.archived===0&&t>0){i(n(`inventory.bulk.archiveAllFailed`,{count:t}),`error`);return}t>0?i(n(`inventory.bulk.archivePartial`,{ok:e.archived,failed:t}),`warning`):i(n(`inventory.bulk.archiveSuccess`,{count:e.archived}),`success`),me(null),ge()},onError:e=>{i(e.message||n(`inventory.bulk.archiveFailed`),`error`)}}),$e=q({mutationFn:async t=>e?Z.bulkRestoreSpoolmanInventorySpools(t):Z.bulkRestoreSpools(t),onSuccess:e=>{we();let t=Ye(e);if(e.restored===0&&t>0){i(n(`inventory.bulk.restoreAllFailed`,{count:t}),`error`);return}t>0?i(n(`inventory.bulk.restorePartial`,{ok:e.restored,failed:t}),`warning`):i(n(`inventory.bulk.restoreSuccess`,{count:e.restored}),`success`),me(null),ge()},onError:e=>{i(e.message||n(`inventory.bulk.restoreFailed`),`error`)}}),et=(0,y.useMemo)(()=>(Te??[]).map(e=>e.id),[Te]),tt=async t=>{if(t.last_scale_weight!=null)try{e?await Z.syncSpoolmanSpoolWeight(t.id,t.last_scale_weight):await xd.updateSpoolWeight(t.id,t.last_scale_weight),r.invalidateQueries({queryKey:Ce}),i(`Synced "${[t.brand,t.material,t.color_name].filter(Boolean).join(` `)}" to scale weight`,`success`)}catch(e){let t=e instanceof id&&e.status===404,r=e instanceof id&&e.status===503;i(n(t?`inventory.syncWeightSpoolNotFound`:r?`inventory.syncWeightSpoolmanUnreachable`:`inventory.syncWeightFailed`),`error`)}},nt=xe?.low_stock_threshold??20,[rt,it]=(0,y.useState)(!1),[at,ot]=(0,y.useState)(nt.toString());(0,y.useEffect)(()=>{rt||ot(nt.toString())},[nt,rt]);let st=q({mutationFn:e=>Z.updateSettings({low_stock_threshold:e}),onSuccess:()=>{r.invalidateQueries({queryKey:[`settings`]}),i(n(`common.saved`),`success`),it(!1)},onError:()=>{i(n(`inventory.lowStockThresholdError`),`error`)}}),ct=(0,y.useMemo)(()=>{if(!Te)return null;let e=0,t=0,n=0,r=0,i={};for(let a of Te){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??nt)&&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}},[Te,nt]),lt=(ze?.length??0)+(e?Be.length:0),ut=Ef(xe?.currency||`USD`),dt=(0,y.useMemo)(()=>{let e={};for(let t of ze||[])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 Be)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},[ze,Be]),ft=(0,y.useMemo)(()=>{let e={};for(let t of Ue||[])e[t.id]=t;return e},[Ue]),pt=(0,y.useMemo)(()=>ct?Object.entries(ct.byMaterial).sort((e,t)=>t[1].weight-e[1].weight).slice(0,4):[],[ct]),mt=(0,y.useMemo)(()=>{let e=Te||[];if(e=w===`active`?e.filter(e=>!e.archived_at):e.filter(e=>!!e.archived_at),E===`used`?e=e.filter(e=>e.weight_used>0):E===`new`?e=e.filter(e=>e.weight_used===0):E===`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??nt)})),O&&(e=e.filter(e=>e.material===O)),A&&(e=e.filter(e=>e.brand===A)),M&&(e=M===`__none__`?e.filter(e=>!e.category):e.filter(e=>e.category===M)),P){let t=Number(P);e=e.filter(e=>e.core_weight_catalog_id===t)}if(je)if(je===`__none__`)e=e.filter(e=>!e.location_id&&!e.storage_location?.trim());else{let t=Number(je),n=ke.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 I===`stock`?e=e.filter(e=>!e.slicer_filament):I===`configured`&&(e=e.filter(e=>!!e.slicer_filament)),R&&(e=YH(e,R)),e},[Te,w,E,O,A,M,P,I,je,R,nt,ke]),ht=()=>ve(0),gt=(0,y.useCallback)(e=>{l(t=>(t.delete(`location_id`),e&&t.set(`location_id`,e),t),{replace:!0}),ht()},[l]),_t=[...new Set(Te?.map(e=>e.material)||[])].sort(),vt=[...new Set(Te?.map(e=>e.brand).filter(Boolean)||[])].sort(),yt=[...new Set(Te?.map(e=>e.category?.trim()).filter(Boolean)||[])].sort(),bt=(Te??[]).some(e=>!e.category),xt=[...new Set(Te?.map(e=>e.core_weight_catalog_id).filter(e=>e!=null)||[])].sort((e,t)=>{let n=(ft[e]?.name||``).toLowerCase(),r=(ft[t]?.name||``).toLowerCase();return n.localeCompare(r)}),St=(Te??[]).some(e=>!e.location_id&&!e.storage_location?.trim()),Ct=w!==`active`||E!==`all`||!!O||!!A||!!M||!!P||!!je||I!==`all`||!!R,wt=e=>{re(e),EQe(e)},Tt=(0,y.useMemo)(()=>ne.filter(e=>e.visible).map(e=>e.id),[ne]),Et=e=>{k9[e]&&(te(t=>{let n;return n=t?.column===e?t.direction===`asc`?{column:e,direction:`desc`}:null:{column:e,direction:`asc`},AQe(n),n}),ht())},Dt=(0,y.useMemo)(()=>{if(!ee)return mt;let e=k9[ee.column];return e?[...mt].sort((t,n)=>{let r=e(t,dt),i=e(n,dt);return ri?ee.direction===`asc`?1:-1:0}):mt},[mt,ee,dt]),Ot=(0,y.useMemo)(()=>{if(!oe)return Dt.map(e=>({type:`single`,spool:e}));let e=new Map;for(let t of Dt)if(!(t.weight_used>0||dt[t.id])){let n=CQe(t),r=e.get(n);r?r.push(t):e.set(n,[t])}let t=[],n=new Set;for(let r of Dt){if(r.weight_used>0||dt[r.id]){t.push({type:`single`,spool:r});continue}let i=CQe(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},[Dt,oe,dt]),kt=ye===-1,At=Ot.length,jt=kt?At||1:ye,Mt=Math.max(1,Math.ceil(At/jt)),Nt=kt?0:Math.min(_e,Mt-1),Pt=kt?Ot:Ot.slice(Nt*jt,(Nt+1)*jt),Ft=()=>{let e=!oe;se(e),ce(new Set),ht();try{localStorage.setItem(`bambuddy-inventory-group`,String(e))}catch{}},It=e=>{ce(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},Lt=e=>{be(e),ve(0);try{localStorage.setItem(`bambuddy-inventory-pageSize`,String(e))}catch{}};return(0,G.jsxs)(`div`,{className:`p-4 md:p-8 space-y-6`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,G.jsx)(xl,{className:`w-7 h-7 text-bambu-green`}),n(`inventory.title`)]}),(0,G.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:n(`inventory.subtitle`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(Q,{variant:`secondary`,disabled:e,onClick:()=>v(!0),title:Oe,children:[(0,G.jsx)(Ru,{className:`w-4 h-4`}),n(`inventory.csv.importButton`,`Import CSV`)]}),(0,G.jsxs)(Q,{variant:`secondary`,disabled:e||b,onClick:De,title:Oe,children:[b?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Js,{className:`w-4 h-4`}),n(`inventory.csv.exportButton`,`Export CSV`)]}),(0,G.jsxs)(Q,{variant:`secondary`,onClick:()=>C(!0),children:[(0,G.jsx)(il,{className:`w-4 h-4`}),n(`locations.manage`)]}),(0,G.jsxs)(Q,{variant:`secondary`,disabled:mt.length===0,onClick:()=>g(mt.map(e=>e.id)),title:mt.length===0?n(`inventory.labels.noSpoolsTitle`,`No spools to label`):n(`inventory.labels.bulkTitle`,`Pick spools to print labels for from the {{count}} currently shown`,{count:mt.length}),children:[(0,G.jsx)(Fl,{className:`w-4 h-4`}),n(`inventory.labels.printLabels`,`Print labels…`)]}),(0,G.jsxs)(Q,{onClick:()=>d({spool:null,mode:`create`}),children:[(0,G.jsx)(Ml,{className:`w-4 h-4`}),n(`inventory.addSpool`)]})]})]}),ct&&!Ee&&(0,G.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-3 lg:grid-cols-5 gap-3`,children:[(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,G.jsx)(xl,{className:`w-4 h-4 text-bambu-green`}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray font-medium uppercase tracking-wide`,children:n(`inventory.totalInventory`)})]}),(0,G.jsx)(`div`,{className:`text-xl font-bold text-white`,children:E9(ct.totalWeight,!0)}),(0,G.jsxs)(`div`,{className:`text-xs text-bambu-gray mt-1`,children:[ct.totalSpools,` `,ct.totalSpools===1?n(`inventory.spool`):n(`inventory.spools`)]})]}),(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-2 mb-1`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Mu,{className:`w-4 h-4 text-blue-600 dark:text-blue-400`}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray font-medium uppercase tracking-wide`,children:n(`inventory.totalConsumed`)})]}),ct.totalConsumed>0&&et.length>0&&(0,G.jsx)(`button`,{onClick:()=>m({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,G.jsx)(ec,{className:`w-3.5 h-3.5`})})]}),(0,G.jsx)(`div`,{className:`text-xl font-bold text-white`,children:E9(ct.totalConsumed,!0)}),(0,G.jsx)(`div`,{className:`text-xs text-bambu-gray mt-1`,children:n(`inventory.sinceTracking`)})]}),(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,G.jsx)(Gc,{className:`w-4 h-4 text-green-600 dark:text-green-400`}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray font-medium uppercase tracking-wide`,children:n(`inventory.byMaterial`)})]}),(0,G.jsx)(`div`,{className:`flex flex-wrap gap-1.5 mt-1`,children:pt.map(([e,t])=>(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-medium ${DQe[e]||`bg-bambu-dark-tertiary text-bambu-gray`}`,children:[e,` `,(0,G.jsx)(`span`,{className:`opacity-70`,children:E9(t.weight,!0)})]},e))})]}),(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,G.jsx)(Fl,{className:`w-4 h-4 text-purple-600 dark:text-purple-400`}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray font-medium uppercase tracking-wide`,children:n(`inventory.inPrinter`)})]}),(0,G.jsx)(`div`,{className:`text-xl font-bold text-white`,children:lt}),(0,G.jsx)(`div`,{className:`text-xs text-bambu-gray mt-1`,children:n(`inventory.loadedInAms`)})]}),(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg p-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,G.jsx)(Pu,{className:`w-4 h-4 text-yellow-600 dark:text-yellow-400`}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray font-medium uppercase tracking-wide`,children:n(`inventory.lowStock`)})]}),(0,G.jsx)(`div`,{className:`text-xl font-bold ${ct.lowStock>0?`text-yellow-700 dark:text-yellow-400`:`text-white`}`,children:ct.lowStock}),(0,G.jsx)(`div`,{className:`text-xs text-bambu-gray mt-1 flex items-center gap-2`,children:rt?(0,G.jsxs)(`form`,{onSubmit:e=>{e.preventDefault();let t=parseFloat(at);!isNaN(t)&&t>=.1&&t<=99.9?st.mutate(t):i(n(`inventory.lowStockThresholdError`),`error`)},className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:`<`}),(0,G.jsx)(`input`,{type:`text`,inputMode:`decimal`,pattern:`^\\d{0,2}(\\.\\d?)?$`,maxLength:4,value:at,onChange:e=>{let t=e.target.value.replace(/[^\d.]/g,``);/^\d{0,2}(\.\d?)?$/.test(t)&&ot(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:st.isPending}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:`%`}),(0,G.jsx)(Q,{type:`submit`,size:`sm`,disabled:st.isPending,children:n(`common.save`)}),(0,G.jsx)(Q,{type:`button`,size:`sm`,variant:`ghost`,onClick:()=>it(!1),disabled:st.isPending,children:n(`common.cancel`)})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`span`,{className:`text-bambu-gray`,children:[`< `,nt,`%`]}),(0,G.jsx)(`button`,{className:`p-1.5 text-bambu-gray hover:text-white rounded transition-colors`,title:n(`common.edit`),onClick:()=>{ot(nt.toString()),it(!0)},children:(0,G.jsx)(Dl,{className:`w-4 h-4`})})]})})]})]}),(0,G.jsxs)(`div`,{className:`flex flex-col sm:flex-row gap-3 items-start sm:items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`relative flex-1 max-w-md ${B===`forecast`?`invisible pointer-events-none`:``}`,children:[(0,G.jsx)(Yl,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50`}),(0,G.jsx)(`input`,{type:`text`,value:R,onChange:e=>{z(e.target.value),ht()},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`}),R&&(0,G.jsx)(`button`,{onClick:()=>{z(``),ht()},className:`absolute right-3 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white`,children:(0,G.jsx)($u,{className:`w-4 h-4`})})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[B===`table`&&(0,G.jsxs)(`button`,{onClick:()=>ae(!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,G.jsx)(Ls,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:n(`inventory.columns`)})]}),B!==`forecast`&&(0,G.jsxs)(`button`,{onClick:Ft,className:`flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium border rounded-lg transition-colors ${oe?`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,G.jsx)(kc,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:n(`inventory.groupSimilar`)})]}),(0,G.jsxs)(`div`,{className:`flex bg-bambu-dark-primary border border-bambu-dark-tertiary rounded-lg overflow-hidden`,children:[(0,G.jsxs)(`button`,{onClick:()=>V(`table`),className:`flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium transition-colors ${B===`table`?`bg-bambu-green text-white`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:[(0,G.jsx)(Su,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:n(`inventory.table`)})]}),(0,G.jsxs)(`button`,{onClick:()=>V(`cards`),className:`flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium transition-colors ${B===`cards`?`bg-bambu-green text-white`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:[(0,G.jsx)(Kc,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:n(`inventory.cards`)})]}),(0,G.jsxs)(`button`,{onClick:()=>s&&V(`forecast`),disabled:!s,title:s?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 ${B===`forecast`?`bg-bambu-green text-white`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:[s?(0,G.jsx)(Nu,{className:`w-4 h-4`}):(0,G.jsx)(el,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:n(`forecast.title`)})]})]})]})]}),(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 ${B===`forecast`?`hidden`:``}`,children:[(0,G.jsxs)(`div`,{className:`flex items-center rounded-lg border border-bambu-dark-tertiary overflow-hidden`,children:[(0,G.jsxs)(`button`,{onClick:()=>{T(`active`),ht()},className:`flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium transition-colors ${w===`active`?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:[(0,G.jsx)(xl,{className:`w-3.5 h-3.5`}),n(`inventory.active`)]}),(0,G.jsxs)(`button`,{onClick:()=>{T(`archived`),ht()},className:`flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium transition-colors ${w===`archived`?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:[(0,G.jsx)(No,{className:`w-3.5 h-3.5`}),n(`inventory.archived`)]})]}),(0,G.jsx)(`div`,{className:`w-px h-5 bg-bambu-dark-tertiary`}),(0,G.jsxs)(`div`,{className:`flex items-center rounded-lg border border-bambu-dark-tertiary overflow-hidden`,children:[(0,G.jsx)(`button`,{onClick:()=>{D(`all`),ht()},className:`px-3 py-1.5 text-xs font-medium transition-colors ${E===`all`?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:n(`inventory.all`)}),(0,G.jsxs)(`button`,{onClick:()=>{D(`used`),ht()},className:`flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium transition-colors ${E===`used`?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:[(0,G.jsx)(ks,{className:`w-3.5 h-3.5`}),n(`inventory.used`)]}),(0,G.jsx)(`button`,{onClick:()=>{D(`new`),ht()},className:`px-3 py-1.5 text-xs font-medium transition-colors ${E===`new`?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:n(`inventory.new`)}),(0,G.jsxs)(`button`,{onClick:()=>{D(`lowstock`),ht()},className:`flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium transition-colors ${E===`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,G.jsx)(Pu,{className:`w-3.5 h-3.5`}),n(`inventory.lowStock`)]})]}),(0,G.jsxs)(`div`,{className:`flex items-center rounded-lg border border-bambu-dark-tertiary overflow-hidden`,children:[(0,G.jsx)(`button`,{onClick:()=>{L(`all`),ht()},className:`px-3 py-1.5 text-xs font-medium transition-colors ${I===`all`?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:n(`inventory.all`)}),(0,G.jsx)(`button`,{onClick:()=>{L(`stock`),ht()},className:`px-3 py-1.5 text-xs font-medium transition-colors ${I===`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,G.jsx)(`button`,{onClick:()=>{L(`configured`),ht()},className:`px-3 py-1.5 text-xs font-medium transition-colors ${I===`configured`?`bg-bambu-green/20 text-bambu-green`:`text-bambu-gray hover:bg-bambu-dark-tertiary`}`,children:n(`inventory.configured`)})]}),(0,G.jsx)(`div`,{className:`w-px h-5 bg-bambu-dark-tertiary`}),(0,G.jsxs)(`select`,{value:O,onChange:e=>{k(e.target.value),ht()},className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${O?`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,G.jsx)(`option`,{value:``,children:n(`inventory.material`)}),_t.map(e=>(0,G.jsx)(`option`,{value:e,children:e},e))]}),(0,G.jsxs)(`select`,{value:A,onChange:e=>{j(e.target.value),ht()},className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${A?`bg-bambu-green/20 text-bambu-green border-bambu-green/30`:`bg-transparent text-bambu-gray border-bambu-dark-tertiary hover:bg-bambu-dark-tertiary`}`,children:[(0,G.jsx)(`option`,{value:``,children:n(`inventory.brand`)}),vt.map(e=>(0,G.jsx)(`option`,{value:e,children:e},e))]}),(yt.length>0||M)&&(0,G.jsxs)(`select`,{value:M,onChange:e=>{N(e.target.value),ht()},className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${M?`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,G.jsx)(`option`,{value:``,children:n(`inventory.category`)}),yt.map(e=>(0,G.jsx)(`option`,{value:e,children:e},e)),bt&&(0,G.jsx)(`option`,{value:`__none__`,children:n(`inventory.categoryNone`)})]}),xt.length>0&&(0,G.jsxs)(`select`,{value:P,onChange:e=>{F(e.target.value),ht()},className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${P?`bg-bambu-green/20 text-bambu-green border-bambu-green/30`:`bg-transparent text-bambu-gray border-bambu-dark-tertiary hover:bg-bambu-dark-tertiary`}`,children:[(0,G.jsx)(`option`,{value:``,children:n(`inventory.spoolName`)}),xt.map(e=>(0,G.jsx)(`option`,{value:e,children:ft[e]?.name||`#${e}`},e))]}),(ke.length>0||je)&&(0,G.jsxs)(`select`,{value:je,onChange:e=>{gt(e.target.value)},className:`px-3 py-1.5 rounded-lg border text-xs font-medium transition-colors cursor-pointer focus:outline-none ${je?`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,G.jsx)(`option`,{value:``,children:n(`inventory.storageLocation`)}),ke.map(e=>(0,G.jsx)(`option`,{value:String(e.id),children:e.name},e.id)),St&&(0,G.jsx)(`option`,{value:`__none__`,children:n(`inventory.storageLocationNone`)})]}),Ct&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`w-px h-5 bg-bambu-dark-tertiary`}),(0,G.jsxs)(`button`,{onClick:()=>{T(`active`),D(`all`),k(``),j(``),N(``),F(``),L(`all`),z(``),l(e=>(e.delete(`location_id`),e),{replace:!0}),ht()},className:`flex items-center gap-1 text-xs text-bambu-gray hover:text-bambu-green transition-colors`,children:[(0,G.jsx)($u,{className:`w-3.5 h-3.5`}),n(`inventory.clearFilters`)]})]}),B!==`forecast`&&(0,G.jsxs)(`span`,{className:`ml-auto text-xs text-bambu-gray`,children:[Dt.length,` `,Dt.length===1?n(`inventory.spool`):n(`inventory.spools`),oe&&At0&&B!==`forecast`&&(0,G.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,G.jsx)(`span`,{className:`text-sm text-bambu-green font-medium`,children:n(`inventory.bulk.selectionCount`,{count:le.size})}),(0,G.jsxs)(`div`,{className:`ml-auto flex flex-wrap items-center gap-2`,children:[(0,G.jsxs)(Q,{size:`sm`,variant:`secondary`,onClick:()=>fe(!0),children:[(0,G.jsx)(Dl,{className:`w-3.5 h-3.5 mr-1.5`}),n(`inventory.bulk.edit`)]}),(0,G.jsxs)(Q,{size:`sm`,variant:`secondary`,onClick:()=>g([...le]),children:[(0,G.jsx)(Fl,{className:`w-3.5 h-3.5 mr-1.5`}),n(`inventory.bulk.printLabels`)]}),(0,G.jsxs)(Q,{size:`sm`,variant:`secondary`,onClick:()=>me(`reset-consumed-counter`),children:[(0,G.jsx)(ec,{className:`w-3.5 h-3.5 mr-1.5`}),n(`inventory.bulk.resetUsage`)]}),w===`archived`?(0,G.jsxs)(Q,{size:`sm`,variant:`secondary`,onClick:()=>me(`restore`),children:[(0,G.jsx)(Vl,{className:`w-3.5 h-3.5 mr-1.5`}),n(`inventory.bulk.restore`)]}):(0,G.jsxs)(Q,{size:`sm`,variant:`secondary`,onClick:()=>me(`archive`),children:[(0,G.jsx)(No,{className:`w-3.5 h-3.5 mr-1.5`}),n(`inventory.bulk.archive`)]}),(0,G.jsxs)(Q,{size:`sm`,variant:`danger`,onClick:()=>me(`delete`),children:[(0,G.jsx)(ju,{className:`w-3.5 h-3.5 mr-1.5`}),n(`inventory.bulk.delete`)]}),(0,G.jsx)(`button`,{className:`p-1.5 text-bambu-gray hover:text-white rounded transition-colors`,onClick:ge,title:n(`inventory.bulk.clearSelection`),"aria-label":n(`inventory.bulk.clearSelection`),children:(0,G.jsx)($u,{className:`w-4 h-4`})})]})]}),Ee?(0,G.jsx)(`div`,{className:`flex justify-center py-16`,children:(0,G.jsx)(Y,{className:`w-8 h-8 text-bambu-green animate-spin`})}):B===`forecast`?(0,G.jsx)(LZe,{spools:Te||[]}):B===`cards`?Pt.length>0?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4`,children:Pt.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=h6({rgba:i.rgba,extraColors:i.extra_colors,effectType:i.effect_type,subtype:i.subtype,effectSize:`groupheader`}),s=H.has(t);return(0,G.jsxs)(`div`,{className:`col-span-full`,children:[(0,G.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:()=>It(t),children:[(0,G.jsx)(`div`,{className:`h-10 flex items-center px-4 gap-3`,style:o,children:(0,G.jsx)(`span`,{className:`bg-white/90 text-gray-800 px-3 py-0.5 rounded-full text-sm font-medium`,children:yf(i.color_name,i.rgba)||`-`})}),(0,G.jsxs)(`div`,{className:`px-4 py-3 flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(ds,{className:`w-4 h-4 text-bambu-gray transition-transform ${s?``:`-rotate-90`}`}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`h3`,{className:`font-semibold text-white`,children:[i.material,i.subtype?` ${i.subtype}`:``]}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:i.brand||`-`})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray`,title:n(`inventory.remaining`),children:E9(a)}),(0,G.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,G.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,G.jsx)(PQe,{spool:e,remaining:t,pct:e.label_weight>0?t/e.label_weight*100:0,onClick:()=>d({spool:e,mode:`edit`}),onPrintLabel:()=>g([e.id]),onCopy:()=>d({spool:e,mode:`copy`}),t:n},e.id)})})]},`group-${t}`)}let t=e.spool,r=Math.max(0,t.label_weight-t.weight_used);return(0,G.jsx)(PQe,{spool:t,remaining:r,pct:t.label_weight>0?r/t.label_weight*100:0,onClick:()=>d({spool:t,mode:`edit`}),onPrintLabel:()=>g([t.id]),onCopy:()=>d({spool:t,mode:`copy`}),t:n},t.id)})}),(0,G.jsx)(NQe,{pageIndex:Nt,pageSize:ye,totalRows:At,totalPages:Mt,onPageChange:ve,onPageSizeChange:Lt,t:n})]}):(0,G.jsx)(LQe,{hasFilters:Ct,onAddSpool:()=>d({spool:null,mode:`create`}),t:n}):Pt.length>0?(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-lg overflow-hidden border border-bambu-dark-tertiary`,children:[(0,G.jsx)(`div`,{className:`overflow-x-auto`,children:(0,G.jsxs)(`table`,{className:`w-full`,children:[(0,G.jsx)(`thead`,{children:(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary bg-bambu-dark-tertiary/30`,children:[(0,G.jsx)(`th`,{className:`w-10 px-3 py-3`,children:(0,G.jsx)(`input`,{type:`checkbox`,className:`h-4 w-4 cursor-pointer`,"aria-label":n(`inventory.bulk.selectAllVisible`),checked:Pt.length>0&&Pt.every(e=>(e.type===`group`?e.spools.map(e=>e.id):[e.spool.id]).every(e=>le.has(e))),onChange:e=>{if(e.target.checked){let e=new Set(le);for(let t of Pt){let n=t.type===`group`?t.spools.map(e=>e.id):[t.spool.id];for(let t of n)e.add(t)}ue(e)}else{let e=new Set(le);for(let t of Pt){let n=t.type===`group`?t.spools.map(e=>e.id):[t.spool.id];for(let t of n)e.delete(t)}ue(e)}}})}),Tt.map(e=>{let t=!!k9[e],r=ee?.column===e;return(0,G.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?()=>Et(e):void 0,children:(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[OQe[e]?.(n)??e,t&&(r?ee.direction===`asc`?(0,G.jsx)(Vo,{className:`w-3 h-3`}):(0,G.jsx)(Fo,{className:`w-3 h-3`}):(0,G.jsx)(zo,{className:`w-3 h-3 opacity-30`}))]})},e)}),(0,G.jsx)(`th`,{className:`text-right py-3 px-4 text-xs font-medium text-bambu-gray uppercase tracking-wide`,children:n(`common.actions`)})]})}),(0,G.jsx)(`tbody`,{children:Pt.map(e=>{if(e.type===`group`){let{key:t,spools:r}=e,i=H.has(t),a=SQe(r),o=Math.max(0,a.label_weight-a.weight_used);return(0,G.jsx)(IQe,{spools:r,headerSpool:a,remaining:o,pct:a.label_weight>0?o/a.label_weight*100:0,isExpanded:i,onToggle:()=>It(t),selectedIds:le,onToggleSelected:he,onToggleGroupSelected:(e,t)=>{ue(n=>{let r=new Set(n);for(let n of e)t?r.add(n):r.delete(n);return r})},onEdit:e=>d({spool:e,mode:`edit`}),onCopy:e=>d({spool:e,mode:`copy`}),onArchive:e=>m({type:`archive`,spoolId:e}),onDelete:e=>m({type:`delete`,spoolId:e}),onPrintLabel:e=>g([e]),onResetConsumedCounter:e=>m({type:`reset-consumed-counter`,spoolId:e}),visibleColumns:Tt,assignmentMap:dt,catalogMap:ft,currencySymbol:ut,dateFormat:Se,t:n,onSyncWeight:tt},`group-${t}`)}let t=e.spool,r=Math.max(0,t.label_weight-t.weight_used);return(0,G.jsx)(FQe,{spool:t,remaining:r,pct:t.label_weight>0?r/t.label_weight*100:0,isSelected:le.has(t.id),onToggleSelected:()=>he(t.id),onEdit:()=>d({spool:t,mode:`edit`}),onCopy:()=>d({spool:t,mode:`copy`}),onRestore:()=>Ke.mutate(t.id),onArchive:()=>m({type:`archive`,spoolId:t.id}),onDelete:()=>m({type:`delete`,spoolId:t.id}),onPrintLabel:()=>g([t.id]),onResetConsumedCounter:()=>m({type:`reset-consumed-counter`,spoolId:t.id}),visibleColumns:Tt,assignmentMap:dt,catalogMap:ft,currencySymbol:ut,dateFormat:Se,t:n,onSyncWeight:tt},t.id)})})]})}),(0,G.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,G.jsx)(`span`,{className:`text-bambu-gray`,children:kt?`${At} ${n(At===1?`inventory.spool`:`inventory.spools`)}`:(0,G.jsxs)(G.Fragment,{children:[n(`inventory.showing`),` `,Nt*jt+1,` `,n(`inventory.to`),` `,Math.min((Nt+1)*jt,At),` `,n(`inventory.of`),` `,At,` `,n(`inventory.spools`)]})}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:n(`inventory.show`)}),(0,G.jsxs)(`select`,{value:ye,onChange:e=>Lt(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,G.jsx)(`option`,{value:e,children:e},e)),(0,G.jsx)(`option`,{value:-1,children:n(`inventory.all`)})]}),!kt&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`button`,{onClick:()=>ve(0),disabled:Nt===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,G.jsx)(hs,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:()=>ve(e=>Math.max(0,e-1)),disabled:Nt===0,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,children:(0,G.jsx)(ps,{className:`w-4 h-4`})}),(0,G.jsxs)(`span`,{className:`text-bambu-gray px-2 whitespace-nowrap`,children:[n(`inventory.page`),` `,Nt+1,` `,n(`inventory.of`),` `,Mt]}),(0,G.jsx)(`button`,{onClick:()=>ve(e=>Math.min(Mt-1,e+1)),disabled:Nt>=Mt-1,className:`p-1.5 rounded text-bambu-gray hover:text-white disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,children:(0,G.jsx)(fs,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:()=>ve(Mt-1),disabled:Nt>=Mt-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,G.jsx)(gs,{className:`w-4 h-4`})})]})]})]})]}):(0,G.jsx)(LQe,{hasFilters:Ct,onAddSpool:()=>d({spool:null,mode:`create`}),t:n}),u!==null&&(0,G.jsx)(uQe,{isOpen:!0,onClose:()=>d(null),spool:u.spool,mode:u.mode,currencySymbol:ut,spoolmanMode:e,spoolsQueryKey:Ce}),p&&(0,G.jsx)(Zd,{title:p.type===`delete`?n(`common.delete`):p.type===`archive`?n(`inventory.archive`):p.type===`reset-consumed-counter`?n(`inventory.resetConsumedCounter`):n(`inventory.resetAllConsumedCounters`),message:p.type===`delete`?n(`inventory.deleteConfirm`):p.type===`archive`?n(`inventory.archiveConfirm`):p.type===`reset-consumed-counter`?n(`inventory.resetConsumedCounterConfirm`):n(`inventory.resetAllConsumedCountersConfirm`,{count:et.length}),confirmText:p.type===`delete`?n(`common.delete`):p.type===`archive`?n(`inventory.archive`):n(`inventory.resetConsumedCounter`),variant:p.type===`archive`?`warning`:`danger`,onConfirm:()=>{p.type===`delete`?We.mutate(p.spoolId):p.type===`archive`?Ge.mutate(p.spoolId):p.type===`reset-consumed-counter`?qe.mutate(p.spoolId):Je.mutate(et),m(null)},onCancel:()=>m(null)}),(0,G.jsx)(iG,{isOpen:ie,onClose:()=>ae(!1),columns:ne,defaultColumns:T9,onSave:wt}),(0,G.jsx)(_Qe,{isOpen:h!==null,onClose:()=>g(null),availableSpools:mt,initialSelectedIds:h??[],spoolmanMode:e}),(0,G.jsx)(xQe,{isOpen:de,selectedCount:le.size,isPending:Xe.isPending,availableLocations:ke.map(e=>({id:e.id,name:e.name})),availableMaterials:w9((Te??[]).map(e=>e.material)),availableSubtypes:w9((Te??[]).map(e=>e.subtype)),availableBrands:w9((Te??[]).map(e=>e.brand)),availableCategories:w9((Te??[]).map(e=>e.category)),availableSlicerFilaments:w9((Te??[]).map(e=>e.slicer_filament)),availableSlicerFilamentNames:w9((Te??[]).map(e=>e.slicer_filament_name)),onClose:()=>fe(!1),onApply:e=>Xe.mutate({ids:[...le],update:e})}),pe&&(0,G.jsx)(Zd,{title:n(pe===`delete`?`inventory.bulk.deleteTitle`:pe===`archive`?`inventory.bulk.archiveTitle`:pe===`restore`?`inventory.bulk.restoreTitle`:`inventory.bulk.resetUsageTitle`),message:n(pe===`delete`?`inventory.bulk.deleteMessage`:pe===`archive`?`inventory.bulk.archiveMessage`:pe===`restore`?`inventory.bulk.restoreMessage`:`inventory.bulk.resetUsageMessage`,{count:le.size}),confirmText:n(pe===`delete`?`common.delete`:pe===`archive`?`inventory.archive`:pe===`restore`?`inventory.restore`:`inventory.resetConsumedCounter`),variant:pe===`delete`?`danger`:`warning`,isLoading:Ze.isPending||Qe.isPending||$e.isPending||Je.isPending,onConfirm:()=>{let e=[...le];pe===`delete`?Ze.mutate(e):pe===`archive`?Qe.mutate(e):pe===`restore`?$e.mutate(e):Je.mutate(e)},onCancel:()=>me(null)}),_&&(0,G.jsx)(vQe,{onClose:()=>v(!1),onImported:e=>{v(!1),r.invalidateQueries({queryKey:Ce}),i(n(`inventory.csv.importSuccess`,`{{count}} spools imported`,{count:e}),`success`)}}),(0,G.jsx)(yQe,{open:S,onClose:()=>C(!1),onPickLocation:e=>gt(String(e))})]})}function NQe({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,G.jsxs)(`div`,{className:`flex items-center justify-between pt-2 text-sm`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:s?`${n} ${o(n===1?`inventory.spool`:`inventory.spools`)}`:(0,G.jsxs)(G.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,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:o(`inventory.show`)}),(0,G.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,G.jsx)(`option`,{value:e,children:e},e)),(0,G.jsx)(`option`,{value:-1,children:o(`inventory.all`)})]}),!s&&(0,G.jsxs)(G.Fragment,{children:[(0,G.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,G.jsx)(hs,{className:`w-4 h-4`})}),(0,G.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,G.jsx)(ps,{className:`w-4 h-4`})}),(0,G.jsxs)(`span`,{className:`text-bambu-gray px-2 whitespace-nowrap`,children:[o(`inventory.page`),` `,e+1,` `,o(`inventory.of`),` `,r]}),(0,G.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,G.jsx)(fs,{className:`w-4 h-4`})}),(0,G.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,G.jsx)(gs,{className:`w-4 h-4`})})]})]})]})}function PQe({spool:e,remaining:t,pct:n,onClick:r,onPrintLabel:i,onCopy:a,t:o}){let s=h6({rgba:e.rgba,extraColors:e.extra_colors,effectType:e.effect_type,subtype:e.subtype,effectSize:`card`});return(0,G.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,G.jsxs)(`div`,{className:`h-14 flex items-center justify-center`,style:s,children:[(0,G.jsx)(`span`,{className:`bg-white/90 text-gray-800 px-3 py-0.5 rounded-full text-sm font-medium`,children:yf(e.color_name,e.rgba)||`-`}),a&&(0,G.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,G.jsx)(zs,{className:`w-3.5 h-3.5`})})]}),(0,G.jsxs)(`div`,{className:`p-4 space-y-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`h3`,{className:`font-semibold text-white`,children:[e.material,e.subtype?` ${e.subtype}`:``]}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e.brand||`-`})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[i&&(0,G.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,G.jsx)(Fl,{className:`w-4 h-4`})}),(0,G.jsxs)(`span`,{className:`text-xs font-mono text-bambu-gray bg-bambu-dark-tertiary px-2 py-1 rounded`,children:[`#`,e.id]})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex justify-between text-xs text-bambu-gray mb-1`,children:[(0,G.jsx)(`span`,{children:o(`inventory.remaining`)}),(0,G.jsxs)(`span`,{children:[Math.round(n),`%`]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`div`,{className:`flex-1 h-2 bg-bambu-dark-tertiary rounded-full overflow-hidden`,children:(0,G.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,G.jsxs)(`span`,{className:`text-xs text-bambu-gray min-w-[40px] text-right`,children:[Math.round(t),`g`]})]})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-2 text-xs`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`span`,{className:`text-bambu-gray/60`,children:[o(`inventory.labelWeight`),`: `]}),(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:E9(e.label_weight)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`span`,{className:`text-bambu-gray/60`,children:[o(`inventory.weightUsed`),`: `]}),(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:e.weight_used>0?E9(e.weight_used):`-`})]})]}),e.note&&(0,G.jsx)(`div`,{className:`text-xs text-bambu-gray/60 pt-2 border-t border-bambu-dark-tertiary truncate`,title:e.note,children:e.note})]})]})}function FQe({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,currencySymbol:h,dateFormat:g,t:_,onSyncWeight:v}){return(0,G.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,G.jsx)(`td`,{className:`w-10 px-3 py-3`,onClick:e=>e.stopPropagation(),children:i&&(0,G.jsx)(`input`,{type:`checkbox`,className:`h-4 w-4 cursor-pointer`,"aria-label":_(`inventory.bulk.selectRow`),checked:!!r,onChange:i})}),f.map(r=>(0,G.jsx)(`td`,{className:`py-3 px-4`,children:O9[r]?.({spool:e,remaining:t,pct:n,assignmentMap:p,catalogMap:m,currencySymbol:h,dateFormat:g,t:_,onSyncWeight:v})},r)),(0,G.jsx)(`td`,{className:`py-3 px-4`,children:(0,G.jsxs)(`div`,{className:`flex items-center justify-end gap-1`,onClick:e=>e.stopPropagation(),children:[(0,G.jsx)(`button`,{onClick:a,className:`p-1.5 text-bambu-gray hover:text-white rounded transition-colors`,title:_(`common.edit`),children:(0,G.jsx)(Dl,{className:`w-4 h-4`})}),o&&(0,G.jsx)(`button`,{onClick:o,className:`p-1.5 text-bambu-gray hover:text-bambu-green rounded transition-colors`,title:_(`inventory.copySpool`),children:(0,G.jsx)(zs,{className:`w-4 h-4`})}),u&&(0,G.jsx)(`button`,{onClick:u,className:`p-1.5 text-bambu-gray hover:text-white rounded transition-colors`,title:_(`inventory.labels.printOne`),children:(0,G.jsx)(Fl,{className:`w-4 h-4`})}),d&&e.weight_used>0&&(0,G.jsx)(`button`,{onClick:d,className:`p-1.5 text-bambu-gray hover:text-orange-600 dark:hover:text-orange-400 rounded transition-colors`,title:_(`inventory.resetConsumedCounterTooltip`),children:(0,G.jsx)(ec,{className:`w-4 h-4`})}),e.archived_at?(0,G.jsx)(`button`,{onClick:s,className:`p-1.5 text-bambu-gray hover:text-bambu-green rounded transition-colors`,title:_(`inventory.restore`),children:(0,G.jsx)(Vl,{className:`w-4 h-4`})}):(0,G.jsx)(`button`,{onClick:c,className:`p-1.5 text-bambu-gray hover:text-yellow-600 dark:hover:text-yellow-400 rounded transition-colors`,title:_(`inventory.archive`),children:(0,G.jsx)(No,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:l,className:`p-1.5 text-bambu-gray hover:text-red-600 dark:hover:text-red-400 rounded transition-colors`,title:_(`common.delete`),children:(0,G.jsx)(ju,{className:`w-4 h-4`})})]})})]})}function IQe({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,currencySymbol:h,dateFormat:g,t:_,onSyncWeight:v,selectedIds:y,onToggleSelected:b,onToggleGroupSelected:x}){let S=!!y&&e.every(e=>y.has(e.id));return(0,G.jsxs)(G.Fragment,{children:[(0,G.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,G.jsx)(`td`,{className:`w-10 px-3 py-3`,onClick:e=>e.stopPropagation(),children:x&&(0,G.jsx)(`input`,{type:`checkbox`,className:`h-4 w-4 cursor-pointer`,"aria-label":_(`inventory.bulk.selectGroup`),checked:S,onChange:t=>x(e.map(e=>e.id),t.target.checked)})}),f.map((a,o)=>(0,G.jsx)(`td`,{className:`py-3 px-4`,children:o===0?(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(ds,{className:`w-4 h-4 text-bambu-gray transition-transform ${i?``:`-rotate-90`}`}),O9[a]?.({spool:t,remaining:n,pct:r,assignmentMap:p,catalogMap:m,currencySymbol:h,dateFormat:g,t:_,onSyncWeight:v})]}):a===`id`?(0,G.jsx)(`span`,{className:`text-xs font-medium bg-bambu-green/20 text-bambu-green px-2 py-0.5 rounded-full`,children:_(`inventory.groupedSpools`,{count:e.length})}):O9[a]?.({spool:t,remaining:n,pct:r,assignmentMap:p,catalogMap:m,currencySymbol:h,dateFormat:g,t:_,onSyncWeight:v})},a)),(0,G.jsx)(`td`,{className:`py-3 px-4`,children:(0,G.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,G.jsx)(FQe,{spool:e,remaining:t,pct:e.label_weight>0?t/e.label_weight*100:0,isSelected:y?.has(e.id),onToggleSelected:b?()=>b(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,currencySymbol:h,dateFormat:g,t:_,onSyncWeight:v},e.id)})]})}function LQe({hasFilters:e,onAddSpool:t,t:n}){return(0,G.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-16 px-4`,children:[(0,G.jsxs)(`div`,{className:`relative mb-6`,children:[(0,G.jsx)(`div`,{className:`absolute inset-0 -m-4 bg-bambu-green/5 rounded-full blur-2xl`}),(0,G.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,G.jsx)(`div`,{className:`absolute -top-1 -right-1 w-3 h-3 rounded-full bg-bambu-green/30`}),(0,G.jsx)(`div`,{className:`absolute -bottom-2 -left-2 w-2 h-2 rounded-full bg-bambu-green/20`}),e?(0,G.jsx)(Yl,{className:`w-10 h-10 text-bambu-gray/40`,strokeWidth:1.5}):(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(`div`,{className:`w-14 h-14 rounded-full border-4 border-bambu-gray/20 flex items-center justify-center`,children:(0,G.jsx)(`div`,{className:`w-6 h-6 rounded-full bg-bambu-gray/10 border-2 border-bambu-gray/20`})}),(0,G.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,G.jsx)(`span`,{className:`text-white text-lg font-bold leading-none`,children:`+`})})]})]})]}),(0,G.jsx)(`h3`,{className:`text-lg font-semibold text-white mb-2 text-center`,children:e?n(`inventory.noSpoolsMatch`):n(`inventory.noSpools`).split(`.`)[0]}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray text-center max-w-sm mb-6`,children:n(e?`inventory.noSpoolsMatchDesc`:`inventory.noSpools`)}),!e&&(0,G.jsxs)(Q,{onClick:t,children:[(0,G.jsx)(xl,{className:`w-4 h-4`}),n(`inventory.addSpool`)]})]})}function j9(e,t){let n=e?.[t];return typeof n==`string`?n:``}function RQe(e){return e.replace(/(https?:\/\/(?:makerworld|public-cdn)\.bblmw\.com\/[^\s"']+)/gi,e=>`/api/v1/makerworld/thumbnail?url=${encodeURIComponent(e)}`)}function M9(e){return e?/^https?:\/\/(makerworld|public-cdn)\.bblmw\.com\//i.test(e)?`/api/v1/makerworld/thumbnail?url=${encodeURIComponent(e)}`:e:``}function N9(e,t){let n=e?.[t];return typeof n==`number`?n:null}function zQe(e,t){let n=e?.[t];return n&&typeof n==`object`&&!Array.isArray(n)?n:void 0}function BQe(e,t=0,n=[]){n.push({folder:e,depth:t});for(let r of e.children??[])BQe(r,t+1,n);return n}function VQe(e,t){return t(e<1?`makerworld.phaseResolving`:`makerworld.phaseDownloading`)}function HQe(e){let[t,n]=(0,y.useState)(0);return(0,y.useEffect)(()=>{if(!e){n(0);return}let t=Date.now(),r=()=>n(Math.floor((Date.now()-t)/1e3));r();let i=window.setInterval(r,1e3);return()=>window.clearInterval(i)},[e]),t}function UQe(){let{t:e}=U(),{hasPermission:t}=Ed(),{showToast:n}=Bd(),r=so(),i=t(`makerworld:import`),[a,o]=(0,y.useState)(``),[s,c]=(0,y.useState)(null),[l,u]=(0,y.useState)(null),[d,f]=(0,y.useState)(null),[p,m]=(0,y.useState)(null),[h,g]=(0,y.useState)(null),[_,v]=(0,y.useState)(``),[b,x]=(0,y.useState)({}),S=K({queryKey:[`makerworld-status`],queryFn:()=>Z.getMakerworldStatus()}),C=K({queryKey:[`library-folders`],queryFn:()=>Z.getLibraryFolders()}),w=K({queryKey:[`makerworld-recent-imports`],queryFn:()=>Z.getMakerworldRecentImports(10)}),T=K({queryKey:[`settings`],queryFn:()=>Z.getSettings()}),E=T.data?.use_slicer_api??!1,D=T.data?.preferred_slicer||`bambu_studio`,O=JW(T.data?.open_in_slicer,T.data?.preferred_slicer),k=E?D:O,A=k===`orcaslicer`?`OrcaSlicer`:`Bambu Studio`,[j,M]=(0,y.useState)(null),N=(e,t)=>{M({kind:`libraryFile`,id:e,filename:t})},P=q({mutationFn:e=>Z.resolveMakerworldUrl(e),onSuccess:(e,t)=>{c(e),v(t),x({})},onError:t=>n(t.message||e(`makerworld.errors.resolveFailed`),`error`)});(0,y.useEffect)(()=>{s!==null&&a.trim()!==_.trim()&&(c(null),v(``),x({}))},[a,s,_]);let F=q({mutationFn:({instanceId:e,profileId:t})=>Z.importMakerworldInstance(s?.model_id??0,e,t,l),onSuccess:t=>{r.invalidateQueries({queryKey:[`library-files`]}),r.invalidateQueries({queryKey:[`library-folders`]}),t.profile_id&&x(e=>({...e,[t.profile_id]:t})),n(t.was_existing?e(`makerworld.alreadyInLibrary`):e(`makerworld.importSuccess`,{filename:t.filename}),`success`)},onError:t=>n(t.message||e(`makerworld.errors.downloadFailed`),`error`)}),I=q({mutationFn:({libraryFileId:e})=>Z.deleteLibraryFile(e),onSuccess:(t,{profileId:i})=>{r.invalidateQueries({queryKey:[`library-files`]}),r.invalidateQueries({queryKey:[`library-folders`]}),r.invalidateQueries({queryKey:[`makerworld-recent-imports`]}),x(e=>{let t={...e};return delete t[i],t}),m(null),n(e(`makerworld.importDeleted`),`success`)},onError:t=>{m(null),n(t.message||e(`makerworld.errors.deleteFailed`),`error`)}}),L=q({mutationFn:({instanceId:e,profileId:t})=>Z.importMakerworldInstance(s?.model_id??0,e,t,l),onSuccess:async e=>{r.invalidateQueries({queryKey:[`library-files`]}),r.invalidateQueries({queryKey:[`library-folders`]}),r.invalidateQueries({queryKey:[`makerworld-recent-imports`]}),e.profile_id&&x(t=>({...t,[e.profile_id]:e})),E?N(e.library_file_id,e.filename):await te(e.library_file_id,e.filename,k)},onError:t=>n(t.message||e(`makerworld.errors.downloadFailed`),`error`)}),R=HQe(F.isPending||L.isPending),z=VQe(R,e),B=e=>{e?.preventDefault();let t=a.trim();t&&P.mutate(t)};(0,y.useEffect)(()=>{if(!h)return;let e=e=>{e.key===`Escape`?g(null):e.key===`ArrowLeft`?g(e=>e&&e.index>0?{...e,index:e.index-1}:e):e.key===`ArrowRight`&&g(e=>e&&e.indexwindow.removeEventListener(`keydown`,e)},[h]);let V=e=>{let t=(Array.isArray(e.pictures)?e.pictures:[]).filter(e=>typeof e==`object`&&!!e).map(e=>({name:j9(e,`name`)||`image`,url:j9(e,`url`)})).filter(e=>e.url);if(t.length>0)return t;let n=j9(e,`cover`);return n?[{name:`cover`,url:n}]:[]},ee=async()=>{if(!s)return;let e=s.instances.filter(e=>{let t=N9(e,`profileId`);return t!==null&&!b[t]});if(e.length!==0){f({current:0,total:e.length});try{for(let t=0;t{try{let{token:r}=await Z.createLibrarySlicerToken(e),i=Z.getLibrarySlicerDownloadUrl(e,r,t);ZW(`${window.location.origin}${i}`,n)}catch{let t=Z.getLibraryFileDownloadUrl(e);ZW(`${window.location.origin}${t}`,n)}},ne=s?.design,re=zQe(ne,`designCreator`),ie=s?.instances??[],ae=(s?.already_imported_library_ids.length??0)>0,oe=S.data?.can_download??!1,se=S.data?.sign_in_expired??!1,H=(0,y.useMemo)(()=>j9(ne,`coverUrl`),[ne]),ce=j9(ne,`title`),le=j9(ne,`summary`),ue=j9(ne,`license`),de=N9(ne,`downloadCount`);return(0,G.jsxs)(`div`,{className:`p-4 md:p-8 max-w-screen-2xl space-y-6`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,G.jsx)(Dc,{className:`w-7 h-7 text-bambu-green`}),e(`makerworld.title`)]}),(0,G.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:e(`makerworld.description`)})]}),(0,G.jsxs)(`div`,{className:`grid gap-6 lg:grid-cols-[1fr_20rem]`,children:[(0,G.jsxs)(`div`,{className:`space-y-6 min-w-0`,children:[!oe&&(0,G.jsx)(Md,{className:`border-amber-300 dark:border-amber-700 bg-amber-50 dark:bg-amber-900/20`,children:(0,G.jsx)(Pd,{children:(0,G.jsxs)(`div`,{className:`flex items-start gap-3 py-2`,children:[(0,G.jsx)(_s,{className:`w-5 h-5 text-amber-600 dark:text-amber-400 mt-0.5 shrink-0`}),(0,G.jsxs)(`div`,{className:`text-sm`,children:[(0,G.jsx)(`p`,{className:`font-medium text-amber-900 dark:text-amber-100`,children:e(se?`makerworld.signInExpiredTitle`:`makerworld.signInRequiredTitle`)}),(0,G.jsxs)(`p`,{className:`text-amber-800 dark:text-amber-200 mt-1`,children:[e(se?`makerworld.signInExpiredBody`:`makerworld.signInRequiredBody`),` `,(0,G.jsx)(ki,{to:`/profiles`,className:`underline`,children:e(`makerworld.openCloudSettings`)})]})]})]})})}),(0,G.jsxs)(Md,{children:[(0,G.jsx)(Nd,{children:(0,G.jsx)(`h2`,{className:`text-lg font-semibold`,children:e(`makerworld.pasteUrlHeader`)})}),(0,G.jsx)(Pd,{children:(0,G.jsxs)(`form`,{onSubmit:B,className:`flex gap-2`,children:[(0,G.jsx)(`input`,{type:`text`,value:a,onChange:e=>o(e.target.value),placeholder:e(`makerworld.pasteUrlPlaceholder`),className:`flex-1 min-w-0 px-3 py-2 border rounded bg-white dark:bg-gray-800 border-gray-300 dark:border-gray-700`,autoComplete:`off`}),(0,G.jsxs)(Q,{type:`submit`,variant:`primary`,disabled:!a.trim()||P.isPending,children:[P.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Ro,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`ml-2`,children:e(`makerworld.resolveButton`)})]})]})})]}),s&&(0,G.jsx)(Md,{children:(0,G.jsx)(Pd,{children:(0,G.jsxs)(`div`,{className:`flex gap-4 py-2`,children:[H&&(0,G.jsx)(`img`,{src:M9(H),alt:ce,className:`w-32 h-32 object-cover rounded`,loading:`lazy`}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`h3`,{className:`text-xl font-semibold truncate`,children:ce||e(`makerworld.untitledModel`)}),re&&(0,G.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400 mt-1`,children:e(`makerworld.byCreator`,{name:j9(re,`name`)})}),(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-3 mt-2 text-xs text-gray-500 dark:text-gray-400`,children:[de!==null&&(0,G.jsx)(`span`,{children:e(`makerworld.downloadsCount`,{count:de})}),ue&&(0,G.jsxs)(`span`,{children:[e(`makerworld.licensePrefix`),`: `,ue]}),ae&&(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-emerald-600 dark:text-emerald-400`,children:[(0,G.jsx)(us,{className:`w-3 h-3`}),` `,e(`makerworld.alreadyImported`)]})]}),le&&(0,G.jsx)(`div`,{className:`mt-3 text-sm prose prose-sm max-w-none dark:prose-invert line-clamp-3`,dangerouslySetInnerHTML:{__html:QG.sanitize(RQe(le))}}),s&&(0,G.jsxs)(`a`,{href:`https://makerworld.com/models/${s.model_id}${s.profile_id?`#profileId-${s.profile_id}`:``}`,target:`_blank`,rel:`noopener noreferrer`,className:`mt-3 inline-flex items-center gap-1 text-xs text-brand-500 hover:underline`,children:[(0,G.jsx)(tc,{className:`w-3 h-3`}),` `,e(`makerworld.openOnMakerworld`)]})]})]})})}),s&&ie.length>0&&(0,G.jsxs)(Md,{children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,G.jsx)(`h2`,{className:`text-lg font-semibold`,children:e(`makerworld.platesHeader`,{count:ie.length})}),(0,G.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,G.jsx)(`label`,{className:`text-xs text-gray-600 dark:text-gray-400`,children:e(`makerworld.importTo`)}),(0,G.jsxs)(`select`,{value:l??``,onChange:e=>u(e.target.value?Number(e.target.value):null),className:`text-sm px-2 py-1 border rounded bg-white dark:bg-gray-800 border-gray-300 dark:border-gray-700`,disabled:d!==null,children:[(0,G.jsx)(`option`,{value:``,children:e(`makerworld.folderAuto`)}),(C.data??[]).filter(e=>!(e.is_external&&e.external_readonly)).flatMap(e=>BQe(e)).map(({folder:e,depth:t})=>(0,G.jsx)(`option`,{value:e.id,children:`${`— `.repeat(t)}${e.name}`},e.id))]}),(0,G.jsx)(Q,{variant:`primary`,size:`sm`,disabled:!i||!oe||d!==null||F.isPending||L.isPending,onClick:ee,children:d===null?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Js,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`ml-2`,children:e(`makerworld.importAll`)})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),(0,G.jsxs)(`span`,{className:`ml-2`,children:[e(`makerworld.importAllProgress`,{current:d.current,total:d.total}),R>0&&` · ${z} · ${R}s`]})]})})]})]})}),(0,G.jsx)(Pd,{children:(0,G.jsx)(`div`,{className:`grid gap-3`,children:ie.map((t,n)=>{let r=N9(t,`id`),a=N9(t,`profileId`),o=j9(t,`title`),s=j9(t,`cover`),c=N9(t,`materialCnt`),l=t?.needAms===!0,u=N9(t,`downloadCount`),f=t?.compatibility??null,p=t?.otherCompatibility??null,h=f?.devProductName??null,_=Array.isArray(p)?p.map(e=>e?.devProductName??``).filter(Boolean):[];if(r==null)return null;let v=F.isPending&&F.variables?.instanceId===r,y=L.isPending&&L.variables?.instanceId===r,x=a===null?void 0:b[a];return(0,G.jsxs)(`div`,{className:`flex flex-col gap-2 p-3 border rounded border-gray-200 dark:border-gray-700`,children:[(0,G.jsxs)(`div`,{className:`flex gap-3 items-center`,children:[(()=>{let n=V(t),r=n.length>0;return(0,G.jsxs)(`button`,{type:`button`,disabled:!r,onClick:()=>r&&g({images:n,index:0}),className:`relative w-16 h-16 shrink-0 rounded overflow-hidden group`,"aria-label":e(`makerworld.openGallery`),children:[s?(0,G.jsx)(`img`,{src:M9(s),alt:``,className:`w-16 h-16 object-cover`,loading:`lazy`}):(0,G.jsx)(`div`,{className:`w-16 h-16 bg-gray-100 dark:bg-gray-800`}),n.length>1&&(0,G.jsxs)(`span`,{className:`absolute bottom-0.5 right-0.5 bg-black/70 text-white text-[10px] px-1.5 py-0.5 rounded flex items-center gap-1`,children:[(0,G.jsx)(Bc,{className:`w-2.5 h-2.5`}),n.length]})]})})(),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`p`,{className:`font-medium truncate`,children:o||e(`makerworld.plateDefaultName`,{n:n+1})}),(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-3 text-xs text-gray-500 dark:text-gray-400 mt-1`,children:[h&&(0,G.jsx)(`span`,{className:`font-medium text-gray-700 dark:text-gray-300`,children:e(`makerworld.slicedFor`,{printer:h,defaultValue:`Sliced for {{printer}}`})}),c!==null&&(0,G.jsx)(`span`,{children:e(`makerworld.materialCount`,{count:c})}),l&&(0,G.jsx)(`span`,{children:e(`makerworld.amsRequired`)}),u!==null&&(0,G.jsx)(`span`,{children:e(`makerworld.downloadsCount`,{count:u})})]}),_.length>0&&(0,G.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mt-1`,title:_.join(`, `),children:e(`makerworld.alsoCompatible`,{printers:_.slice(0,6).join(`, `)+(_.length>6?`…`:``),defaultValue:`Also marked compatible: {{printers}}`})})]}),(0,G.jsxs)(`div`,{className:`flex gap-2 shrink-0`,children:[(0,G.jsx)(Q,{variant:`ghost`,size:`sm`,disabled:!i||!oe||v||y||d!==null,onClick:()=>F.mutate({instanceId:r,profileId:a}),title:oe?void 0:e(`makerworld.signInRequiredTitle`),children:v?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),(0,G.jsxs)(`span`,{className:`ml-2`,children:[z,R>0&&` · ${R}s`]})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Js,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`ml-2`,children:e(`makerworld.importToLibrary`)})]})}),(0,G.jsx)(Q,{variant:`primary`,size:`sm`,disabled:!i||!oe||v||y||d!==null,onClick:()=>L.mutate({instanceId:r,profileId:a}),title:oe?void 0:e(`makerworld.signInRequiredTitle`),children:y?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),(0,G.jsxs)(`span`,{className:`ml-2`,children:[z,R>0&&` · ${R}s`]})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(tc,{className:`w-4 h-4`}),(0,G.jsx)(`span`,{className:`ml-2`,children:e(`makerworld.sliceIn`,{slicer:A})})]})})]})]}),x&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2 pl-20 text-xs`,children:[(0,G.jsx)(us,{className:`w-3.5 h-3.5 text-emerald-600 dark:text-emerald-400 shrink-0`}),(0,G.jsx)(`span`,{className:`text-emerald-700 dark:text-emerald-300`,children:x.was_existing?e(`makerworld.lastImportAlreadyInLibrary`):e(`makerworld.lastImportSuccess`)}),(0,G.jsxs)(Q,{variant:`ghost`,size:`sm`,onClick:()=>{let e=x.folder_id?`/files?folder=${x.folder_id}`:`/files`;window.location.assign(e)},children:[(0,G.jsx)(hc,{className:`w-3.5 h-3.5`}),(0,G.jsx)(`span`,{className:`ml-1.5`,children:e(`makerworld.viewInLibrary`)})]}),E?(0,G.jsxs)(Q,{variant:`ghost`,size:`sm`,onClick:()=>N(x.library_file_id,x.filename),children:[(0,G.jsx)(Is,{className:`w-3.5 h-3.5`}),(0,G.jsx)(`span`,{className:`ml-1.5`,children:e(`slice.action`,`Slice`)})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(Q,{variant:`ghost`,size:`sm`,onClick:()=>te(x.library_file_id,x.filename,`bambu_studio`),children:[(0,G.jsx)(tc,{className:`w-3.5 h-3.5`}),(0,G.jsx)(`span`,{className:`ml-1.5`,children:e(`makerworld.openInBambuStudio`)})]}),(0,G.jsxs)(Q,{variant:`ghost`,size:`sm`,onClick:()=>te(x.library_file_id,x.filename,`orcaslicer`),children:[(0,G.jsx)(tc,{className:`w-3.5 h-3.5`}),(0,G.jsx)(`span`,{className:`ml-1.5`,children:e(`makerworld.openInOrcaSlicer`)})]})]}),(0,G.jsx)(`div`,{className:`ml-auto`,children:(0,G.jsx)(Q,{variant:`ghost`,size:`sm`,disabled:I.isPending&&I.variables?.profileId===a,onClick:()=>{a!==null&&m({libraryFileId:x.library_file_id,profileId:a,filename:x.filename})},title:e(`makerworld.deleteImport`),children:I.isPending&&I.variables?.profileId===a?(0,G.jsx)(Y,{className:`w-3.5 h-3.5 animate-spin`}):(0,G.jsx)(ju,{className:`w-3.5 h-3.5 text-red-500`})})})]})]},r)})})})]})]}),(0,G.jsx)(`aside`,{className:`lg:sticky lg:top-6 lg:self-start min-w-0`,children:w.data&&w.data.length>0&&(0,G.jsxs)(Md,{children:[(0,G.jsx)(Nd,{children:(0,G.jsx)(`h2`,{className:`text-base font-semibold`,children:e(`makerworld.recentImportsHeader`)})}),(0,G.jsx)(Pd,{children:(0,G.jsx)(`div`,{className:`flex flex-col gap-2 max-h-[28rem] overflow-y-auto -mx-2 px-2`,children:w.data.map(t=>(0,G.jsxs)(`div`,{className:`flex gap-2 p-2 border rounded border-gray-200 dark:border-gray-700`,children:[t.thumbnail_path?(0,G.jsx)(`img`,{src:Z.getLibraryFileThumbnailUrl(t.library_file_id),alt:``,className:`w-12 h-12 shrink-0 object-cover rounded bg-gray-100 dark:bg-gray-800`,loading:`lazy`}):(0,G.jsx)(`div`,{className:`w-12 h-12 shrink-0 rounded bg-gray-100 dark:bg-gray-800`}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0 flex flex-col gap-1`,children:[(0,G.jsx)(`p`,{className:`text-xs font-medium truncate`,title:t.filename,children:t.filename}),(0,G.jsxs)(`div`,{className:`flex gap-0.5`,children:[(0,G.jsx)(Q,{variant:`ghost`,size:`sm`,onClick:()=>{let e=t.folder_id?`/files?folder=${t.folder_id}`:`/files`;window.location.assign(e)},title:e(`makerworld.viewInLibrary`),children:(0,G.jsx)(hc,{className:`w-3.5 h-3.5`})}),E?(0,G.jsx)(Q,{variant:`ghost`,size:`sm`,onClick:()=>N(t.library_file_id,t.filename),title:e(`slice.action`,`Slice`),children:(0,G.jsx)(Is,{className:`w-3.5 h-3.5`})}):(0,G.jsx)(Q,{variant:`ghost`,size:`sm`,onClick:()=>te(t.library_file_id,t.filename,`bambu_studio`),title:e(`makerworld.openInBambuStudio`),children:(0,G.jsx)(tc,{className:`w-3.5 h-3.5`})}),t.source_url&&(0,G.jsx)(`a`,{href:t.source_url,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center justify-center h-7 w-7 rounded text-gray-500 hover:text-gray-700 dark:hover:text-gray-300`,title:e(`makerworld.openOnMakerworld`),children:(0,G.jsx)(Dc,{className:`w-3.5 h-3.5`})})]})]})]},t.library_file_id))})})]})})]}),(0,G.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 pt-4 border-t border-gray-200 dark:border-gray-700`,children:e(`makerworld.disclaimer`)}),p&&(0,G.jsx)(Zd,{title:e(`makerworld.deleteImport`),message:e(`makerworld.confirmDelete`,{filename:p.filename}),confirmText:e(`makerworld.deleteImport`),variant:`danger`,isLoading:I.isPending,loadingText:e(`makerworld.importDeleting`),onCancel:()=>m(null),onConfirm:()=>I.mutate({libraryFileId:p.libraryFileId,profileId:p.profileId})}),j&&(0,G.jsx)(WW,{source:j,onClose:()=>M(null)}),h&&(0,G.jsxs)(`div`,{className:`fixed inset-0 bg-black/90 flex items-center justify-center z-50`,onClick:()=>g(null),role:`dialog`,"aria-modal":`true`,children:[(0,G.jsx)(`button`,{type:`button`,className:`absolute top-4 right-4 p-2 bg-white/10 hover:bg-white/20 rounded-full text-white`,onClick:e=>{e.stopPropagation(),g(null)},"aria-label":e(`common.close`,`Close`),children:(0,G.jsx)($u,{className:`w-5 h-5`})}),h.images.length>1&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`button`,{type:`button`,className:`absolute left-4 p-2 bg-white/10 hover:bg-white/20 rounded-full text-white disabled:opacity-30`,disabled:h.index===0,onClick:e=>{e.stopPropagation(),g(e=>e&&{...e,index:Math.max(0,e.index-1)})},"aria-label":e(`makerworld.galleryPrev`),children:(0,G.jsx)(ps,{className:`w-6 h-6`})}),(0,G.jsx)(`button`,{type:`button`,className:`absolute right-4 p-2 bg-white/10 hover:bg-white/20 rounded-full text-white disabled:opacity-30`,disabled:h.index>=h.images.length-1,onClick:e=>{e.stopPropagation(),g(e=>e&&{...e,index:Math.min(e.images.length-1,e.index+1)})},"aria-label":e(`makerworld.galleryNext`),children:(0,G.jsx)(fs,{className:`w-6 h-6`})})]}),(0,G.jsx)(`img`,{src:M9(h.images[h.index].url),alt:h.images[h.index].name,className:`max-w-[90vw] max-h-[90vh] object-contain`,onClick:e=>e.stopPropagation()}),h.images.length>1&&(0,G.jsxs)(`div`,{className:`absolute bottom-6 left-1/2 -translate-x-1/2 text-white bg-black/60 px-3 py-1 rounded text-xs`,children:[h.index+1,` / `,h.images.length]})]})]})}var WQe=[`DEBUG`,`INFO`,`WARNING`,`ERROR`],P9={DEBUG:`text-gray-400`,INFO:`text-blue-400`,WARNING:`text-yellow-400`,ERROR:`text-red-400`},GQe={DEBUG:Zo,INFO:Vc,WARNING:Pu,ERROR:_s};function KQe(){let e=so(),[t,n]=(0,y.useState)(!0),[r,i]=(0,y.useState)(new Set),[a,o]=(0,y.useState)(``),[s,c]=(0,y.useState)(`ALL`),[l,u]=(0,y.useState)(!1),[d,f]=(0,y.useState)(!1),p=(0,y.useRef)(null),{data:m,isLoading:h,refetch:g}=K({queryKey:[`application-logs`,s,a],queryFn:()=>bd.getLogs({limit:200,level:s===`ALL`?void 0:s,search:a||void 0}),refetchInterval:d?2e3:!1,enabled:l});(0,y.useEffect)(()=>{l||f(!1)},[l]);let _=q({mutationFn:()=>bd.clearLogs(),onSuccess:()=>{e.invalidateQueries({queryKey:[`application-logs`]})}});(0,y.useEffect)(()=>{t&&p.current&&m?.entries&&(p.current.scrollTop=p.current.scrollHeight)},[m?.entries,t]);let v=e=>{i(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},b=e=>{let t=e.split(` `);return t.length>=2?t[1]:e},x=(0,y.useMemo)(()=>m?.entries??[],[m?.entries]),S=(0,y.useMemo)(()=>[...x].reverse(),[x]),C=({level:e})=>(0,G.jsx)(GQe[e]||Vc,{className:`w-3.5 h-3.5 ${P9[e]||`text-gray-400`}`});return(0,G.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg overflow-hidden`,children:[(0,G.jsxs)(`button`,{onClick:()=>u(!l),className:`w-full flex items-center justify-between p-4 hover:bg-bambu-dark-tertiary/50 transition-colors`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`p-2 rounded-lg ${d?`bg-bambu-green/20 text-bambu-green`:`bg-bambu-dark-tertiary text-bambu-gray`}`,children:(0,G.jsx)(Zo,{className:`w-5 h-5`})}),(0,G.jsxs)(`div`,{className:`text-left`,children:[(0,G.jsx)(`p`,{className:`font-medium text-white`,children:`Application Logs`}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:d?`Live streaming - ${m?.filtered_count??0} entries`:`View and filter application logs`})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[d&&(0,G.jsxs)(`span`,{className:`flex items-center gap-1.5 px-2 py-1 bg-bambu-green/20 rounded text-bambu-green text-xs`,children:[(0,G.jsx)(`span`,{className:`w-1.5 h-1.5 bg-bambu-green rounded-full animate-pulse`}),`Live`]}),l?(0,G.jsx)(ms,{className:`w-5 h-5 text-bambu-gray`}):(0,G.jsx)(ds,{className:`w-5 h-5 text-bambu-gray`})]})]}),l&&(0,G.jsxs)(`div`,{className:`border-t border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex flex-col gap-2 p-4 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[d?(0,G.jsxs)(`button`,{onClick:e=>{e.stopPropagation(),f(!1)},className:`flex items-center gap-1.5 px-3 py-1.5 text-sm bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400 hover:bg-red-200 dark:hover:bg-red-500/30 rounded transition-colors`,children:[(0,G.jsx)(_u,{className:`w-4 h-4`}),`Stop`]}):(0,G.jsxs)(`button`,{onClick:e=>{e.stopPropagation(),f(!0),g()},className:`flex items-center gap-1.5 px-3 py-1.5 text-sm bg-bambu-green/20 text-bambu-green hover:bg-bambu-green/30 rounded transition-colors`,children:[(0,G.jsx)(Al,{className:`w-4 h-4`}),`Start`]}),(0,G.jsxs)(`button`,{onClick:()=>_.mutate(),disabled:_.isPending||x.length===0,className:`flex items-center gap-1.5 px-3 py-1.5 text-sm bg-bambu-dark-tertiary text-bambu-gray hover:text-white hover:bg-bambu-dark-secondary rounded transition-colors disabled:opacity-50`,children:[(0,G.jsx)(ju,{className:`w-4 h-4`}),`Clear`]}),(0,G.jsx)(`button`,{onClick:()=>g(),disabled:h,className:`flex items-center gap-1.5 px-3 py-1.5 text-sm bg-bambu-dark-tertiary text-bambu-gray hover:text-white hover:bg-bambu-dark-secondary rounded transition-colors disabled:opacity-50`,children:(0,G.jsx)(zl,{className:`w-4 h-4 ${h?`animate-spin`:``}`})}),(0,G.jsx)(`div`,{className:`flex-1`}),(0,G.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-bambu-gray cursor-pointer`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:t,onChange:e=>n(e.target.checked),className:`rounded border-bambu-dark-tertiary bg-bambu-dark-tertiary`}),`Auto-scroll`]}),(0,G.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[m?.filtered_count??0,`/`,m?.total_in_file??0]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(`div`,{className:`relative flex-1`,children:[(0,G.jsx)(Yl,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray`}),(0,G.jsx)(`input`,{type:`text`,placeholder:`Search message or logger name...`,value:a,onChange:e=>o(e.target.value),className:`w-full pl-8 pr-8 py-1.5 text-sm bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`}),a&&(0,G.jsx)(`button`,{onClick:()=>o(``),className:`absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white`,children:(0,G.jsx)($u,{className:`w-4 h-4`})})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1 bg-bambu-dark-secondary rounded border border-bambu-dark-tertiary`,children:[(0,G.jsx)(`button`,{onClick:()=>c(`ALL`),className:`px-2 py-1.5 text-xs rounded-l transition-colors ${s===`ALL`?`bg-bambu-green text-white`:`text-bambu-gray hover:text-white`}`,children:`All`}),WQe.map((e,t)=>(0,G.jsx)(`button`,{onClick:()=>c(e),className:`px-2 py-1.5 text-xs transition-colors flex items-center gap-1 ${t===WQe.length-1?`rounded-r`:``} ${s===e?`${P9[e]} bg-bambu-dark-tertiary`:`text-bambu-gray hover:text-white`}`,children:e},e))]})]})]}),(0,G.jsx)(`div`,{ref:p,className:`overflow-auto font-mono text-xs bg-black min-h-[300px] max-h-[500px]`,children:x.length===0?(0,G.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-[300px] text-bambu-gray`,children:[(0,G.jsx)(`p`,{className:`mb-2`,children:`No log entries found`}),(0,G.jsx)(`p`,{className:`text-sm`,children:`Log file may be empty or cleared`})]}):(0,G.jsx)(`div`,{className:`divide-y divide-bambu-dark-tertiary/30`,children:S.map((e,t)=>{let n=r.has(t),i=e.message.includes(`
`);return(0,G.jsx)(`div`,{className:`p-2 cursor-pointer hover:bg-bambu-dark-secondary/50 transition-colors ${n?`bg-bambu-dark-secondary/30`:``}`,onClick:()=>i&&v(t),children:(0,G.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray/70 shrink-0 w-20`,children:b(e.timestamp)}),(0,G.jsx)(`span`,{className:`shrink-0`,children:(0,G.jsx)(C,{level:e.level})}),(0,G.jsxs)(`span`,{className:`text-purple-400/80 shrink-0 max-w-[200px] truncate`,title:e.logger_name,children:[`[`,e.logger_name,`]`]}),(0,G.jsx)(`span`,{className:`flex-1 ${P9[e.level]||`text-white/80`} ${!n&&i?`truncate`:``}`,children:n?(0,G.jsx)(`pre`,{className:`whitespace-pre-wrap break-all`,children:e.message}):e.message.split(`
`)[0]}),i&&(0,G.jsx)(`span`,{className:`text-bambu-gray/50 shrink-0`,children:n?(0,G.jsx)(ms,{className:`w-3.5 h-3.5`}):(0,G.jsx)(ds,{className:`w-3.5 h-3.5`})})]})},t)})})}),(0,G.jsx)(`div`,{className:`flex items-center justify-between p-3 border-t border-bambu-dark-tertiary text-sm text-bambu-gray`,children:d?(0,G.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`w-2 h-2 bg-green-500 rounded-full animate-pulse`}),`Auto-refreshing every 2 seconds`]}):(0,G.jsx)(`span`,{children:`Click Start to enable live log streaming`})})]})]})}function qQe(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:e<1024*1024*1024?`${(e/(1024*1024)).toFixed(1)} MB`:`${(e/(1024*1024*1024)).toFixed(2)} GB`}function F9({icon:e,label:t,value:n,subValue:r,color:i=`text-bambu-green`}){return(0,G.jsxs)(`div`,{className:`flex items-start gap-3 p-4 bg-bambu-dark rounded-lg`,children:[(0,G.jsx)(`div`,{className:`p-2 rounded-lg bg-bambu-dark-tertiary ${i}`,children:(0,G.jsx)(e,{className:`w-5 h-5`})}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:t}),(0,G.jsx)(`p`,{className:`text-lg font-semibold text-white truncate`,children:n}),r&&(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-0.5`,children:r})]})]})}function JQe({percent:e,color:t=`bg-bambu-green`}){return(0,G.jsx)(`div`,{className:`w-full h-2 bg-bambu-dark rounded-full overflow-hidden`,children:(0,G.jsx)(`div`,{className:`h-full ${t} transition-all duration-300`,style:{width:`${Math.min(100,e)}%`}})})}function I9({title:e,icon:t,children:n}){return(0,G.jsxs)(Md,{className:`p-6`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-4`,children:[(0,G.jsx)(t,{className:`w-5 h-5 text-bambu-green`}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e})]}),n]})}function YQe(){let{t:e}=U(),t=so(),[n,r]=(0,y.useState)(null),[i,a]=(0,y.useState)(!1),[o,s]=(0,y.useState)(!1),[c,l]=(0,y.useState)(null),{data:u,isLoading:d,refetch:f,isFetching:p}=K({queryKey:[`systemInfo`],queryFn:Z.getSystemInfo,refetchInterval:3e4}),{data:m}=K({queryKey:[`debugLogging`],queryFn:bd.getDebugLoggingState,staleTime:10*1e3,refetchInterval:10*1e3}),{data:h}=K({queryKey:[`settings`],queryFn:Z.getSettings}),{data:g}=K({queryKey:[`library-stats`],queryFn:Z.getLibraryStats}),{data:_}=K({queryKey:[`printers`],queryFn:Z.getPrinters}),{data:v,refetch:b,isFetching:x}=K({queryKey:[`systemHealth`],queryFn:Z.getSystemHealth,staleTime:60*1e3}),S=h?.time_format||`system`,C=async()=>{s(!0);try{let e=await bd.setDebugLogging(!m?.enabled);t.setQueryData([`debugLogging`],e)}catch(e){console.error(`Failed to toggle debug logging:`,e)}finally{s(!1)}},w=async()=>{r(null),a(!0);try{await bd.downloadSupportBundle()}catch(e){r(e instanceof Error?e.message:`Failed to download support bundle`)}finally{a(!1)}};if(d)return(0,G.jsx)(`div`,{className:`flex items-center justify-center h-64`,children:(0,G.jsx)(Y,{className:`w-8 h-8 text-bambu-green animate-spin`})});if(!u)return(0,G.jsx)(`div`,{className:`p-6 text-center text-bambu-gray`,children:e(`system.failedToLoad`,`Failed to load system information`)});let T=u.storage.disk_percent_used>90?`bg-red-500`:u.storage.disk_percent_used>75?`bg-yellow-500`:`bg-bambu-green`,E=u.memory.percent_used>90?`bg-red-500`:u.memory.percent_used>75?`bg-yellow-500`:`bg-bambu-green`;return(0,G.jsxs)(`div`,{className:`p-6 space-y-6`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h1`,{className:`text-2xl font-bold text-white`,children:e(`system.title`,`System Information`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray mt-1`,children:e(`system.subtitle`,`Monitor system resources and database statistics`)})]}),(0,G.jsxs)(`button`,{onClick:()=>f(),disabled:p,className:`flex items-center gap-2 px-4 py-2 bg-bambu-dark-secondary hover:bg-bambu-dark-tertiary rounded-lg transition-colors disabled:opacity-50`,children:[(0,G.jsx)(zl,{className:`w-4 h-4 ${p?`animate-spin`:``}`}),e(`common.refresh`,`Refresh`)]})]}),(0,G.jsx)(I9,{title:e(`system.application`,`Application`),icon:Ql,children:(0,G.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-4`,children:[(0,G.jsx)(F9,{icon:Ql,label:e(`system.version`,`Version`),value:`v${u.app.version}`}),(0,G.jsx)(F9,{icon:ks,label:e(`system.uptime`,`System Uptime`),value:u.system.uptime_formatted}),(0,G.jsx)(F9,{icon:Ql,label:e(`system.hostname`,`Hostname`),value:u.system.hostname})]})}),(0,G.jsx)(I9,{title:e(`support.title`,`Support & Troubleshooting`),icon:Nc,children:(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`support.description`,`Enable debug logging to capture detailed information, then download a support bundle to share when reporting issues.`)}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-4 bg-bambu-dark rounded-lg`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`p-2 rounded-lg ${m?.enabled?`bg-amber-500/20 text-amber-500`:`bg-bambu-dark-tertiary text-bambu-gray`}`,children:(0,G.jsx)(Zo,{className:`w-5 h-5`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`font-medium text-white`,children:e(`support.debugLogging`,`Debug Logging`)}),(0,G.jsxs)(`p`,{className:`text-sm text-bambu-gray`,children:[m?.enabled?e(`support.debugLoggingEnabled`,`Capturing detailed logs`):e(`support.debugLoggingDisabled`,`Normal logging level`),m?.enabled&&m.duration_seconds!==null&&(0,G.jsxs)(`span`,{className:`text-amber-700 dark:text-amber-400 ml-2`,children:[`(`,Math.floor(m.duration_seconds/60),`m `,m.duration_seconds%60,`s)`]})]})]})]}),(0,G.jsxs)(`button`,{onClick:C,disabled:o,className:`px-4 py-2 rounded-lg font-medium transition-colors flex items-center gap-2 ${m?.enabled?`bg-amber-100 text-amber-700 hover:bg-amber-200 dark:bg-amber-500/20 dark:text-amber-400 dark:hover:bg-amber-500/30`:`bg-bambu-green/20 text-bambu-green hover:bg-bambu-green/30`} disabled:opacity-50`,children:[o&&(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),m?.enabled?e(`support.disableDebug`,`Disable`):e(`support.enableDebug`,`Enable`)]})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-4 bg-bambu-dark rounded-lg`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`p-2 rounded-lg bg-bambu-dark-tertiary text-bambu-green`,children:(0,G.jsx)(Js,{className:`w-5 h-5`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`font-medium text-white`,children:e(`support.supportBundle`,`Support Bundle`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`support.supportBundleDescription`,`Download system info and logs as a ZIP file`)})]})]}),(0,G.jsxs)(`button`,{onClick:w,disabled:i||!m?.enabled,className:`px-4 py-2 rounded-lg font-medium bg-bambu-green/20 text-bambu-green hover:bg-bambu-green/30 transition-colors flex items-center gap-2 disabled:opacity-50 disabled:cursor-not-allowed`,title:m?.enabled?void 0:e(`support.enableDebugFirst`,`Enable debug logging first`),children:[i&&(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),i?e(`support.bundleGenerating`,`Generating...`):e(`common.download`,`Download`)]})]}),i&&(0,G.jsxs)(`div`,{className:`p-3 bg-bambu-dark-tertiary/40 rounded-lg space-y-1`,children:[(0,G.jsxs)(`p`,{className:`text-sm font-medium text-white flex items-center gap-2`,children:[(0,G.jsx)(Y,{className:`w-3.5 h-3.5 animate-spin text-bambu-green`}),e(`support.bundleGenerating`,`Generating...`)]}),(0,G.jsxs)(`ul`,{className:`text-xs text-bambu-gray list-disc list-inside space-y-0.5 pl-1`,children:[(0,G.jsx)(`li`,{children:e(`support.bundleStepConnection`,`Running printer connectivity checks`)}),(0,G.jsx)(`li`,{children:e(`support.bundleStepVirtualPrinters`,`Running virtual-printer setup checks`)}),(0,G.jsx)(`li`,{children:e(`support.bundleStepLogScan`,`Scanning recent logs for known issues`)}),(0,G.jsx)(`li`,{children:e(`support.bundleStepBuild`,`Building the support bundle ZIP`)})]})]}),n&&(0,G.jsx)(`div`,{className:`p-3 bg-red-100 border border-red-300 rounded-lg text-red-700 dark:bg-red-500/20 dark:border-red-500/30 dark:text-red-400 text-sm`,children:n}),!m?.enabled&&(0,G.jsx)(`div`,{className:`p-4 bg-bambu-dark-tertiary/50 rounded-lg`,children:(0,G.jsxs)(`p`,{className:`text-sm text-bambu-gray`,children:[(0,G.jsx)(`span`,{className:`text-amber-700 dark:text-amber-400 font-medium`,children:e(`support.instructions`,`To report an issue:`)}),(0,G.jsx)(`br`,{}),`1. `,e(`support.step1`,`Enable debug logging`),(0,G.jsx)(`br`,{}),`2. `,e(`support.step2`,`Reproduce the issue`),(0,G.jsx)(`br`,{}),`3. `,e(`support.step3`,`Download the support bundle`),(0,G.jsx)(`br`,{}),`4. `,e(`support.step4`,`Attach the ZIP file to your issue report`)]})}),(0,G.jsxs)(`div`,{className:`p-4 bg-bambu-dark rounded-lg space-y-3`,children:[(0,G.jsx)(`p`,{className:`text-sm font-medium text-white`,children:e(`support.privacyTitle`,`What's in the support bundle?`)}),(0,G.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4 text-sm`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-bambu-green font-medium mb-1`,children:e(`support.collected`,`Collected:`)}),(0,G.jsxs)(`ul`,{className:`text-bambu-gray space-y-0.5`,children:[(0,G.jsxs)(`li`,{children:[`• `,e(`support.collectItem1`,`App version and debug mode`)]}),(0,G.jsxs)(`li`,{children:[`• `,e(`support.collectItem2`,`OS, architecture, Python version`)]}),(0,G.jsxs)(`li`,{children:[`• `,e(`support.collectItem3`,`Database statistics (counts only)`)]}),(0,G.jsxs)(`li`,{children:[`• `,e(`support.collectItem4`,`Printer models and nozzle counts`)]}),(0,G.jsxs)(`li`,{children:[`• `,e(`support.collectItem5`,`Non-sensitive settings (themes, formats)`)]}),(0,G.jsxs)(`li`,{children:[`• `,e(`support.collectItem6`,`Debug logs (sanitized)`)]}),(0,G.jsxs)(`li`,{children:[`• `,e(`support.collectItem7`,`Printer connectivity and firmware versions`)]}),(0,G.jsxs)(`li`,{children:[`• `,e(`support.collectItem8`,`Integration status (Spoolman, MQTT, HA)`)]}),(0,G.jsxs)(`li`,{children:[`• `,e(`support.collectItem9`,`Network interfaces (subnets only)`)]}),(0,G.jsxs)(`li`,{children:[`• `,e(`support.collectItem10`,`Python package versions`)]}),(0,G.jsxs)(`li`,{children:[`• `,e(`support.collectItem11`,`Database health checks`)]}),(0,G.jsxs)(`li`,{children:[`• `,e(`support.collectItem12`,`Docker environment details`)]})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-red-700 dark:text-red-400 font-medium mb-1`,children:e(`support.notCollected`,`NOT collected:`)}),(0,G.jsxs)(`ul`,{className:`text-bambu-gray space-y-0.5`,children:[(0,G.jsxs)(`li`,{children:[`• `,e(`support.notItem1`,`Printer names and serial numbers`)]}),(0,G.jsxs)(`li`,{children:[`• `,e(`support.notItem2`,`Access codes and passwords`)]}),(0,G.jsxs)(`li`,{children:[`• `,e(`support.notItem3`,`Email addresses`)]}),(0,G.jsxs)(`li`,{children:[`• `,e(`support.notItem4`,`API keys and tokens`)]}),(0,G.jsxs)(`li`,{children:[`• `,e(`support.notItem5`,`Webhook URLs`)]}),(0,G.jsxs)(`li`,{children:[`• `,e(`support.notItem6`,`Your hostname or username`)]}),(0,G.jsxs)(`li`,{children:[`• `,e(`support.notItem7`,`IP addresses`)]})]})]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray/70`,children:e(`support.privacyNote`,`Email addresses in logs are replaced with [EMAIL], printer names with [PRINTER], serial numbers with [SERIAL], and IP addresses with [IP].`)})]}),(0,G.jsx)(KQe,{})]})}),(0,G.jsxs)(I9,{title:e(`diagnostic.sectionTitle`,`Connection Diagnostic`),icon:yu,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4`,children:e(`diagnostic.sectionDescription`,`Check why a printer won't connect or won't print — port reachability, LAN developer mode, Docker network mode, and credentials.`)}),_&&_.length>0?(0,G.jsx)(`div`,{className:`space-y-2`,children:_.map(t=>(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-3 bg-bambu-dark rounded-lg`,children:[(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsx)(`span`,{className:`font-medium text-white`,children:t.name}),(0,G.jsx)(`span`,{className:`text-sm text-bambu-gray ml-2`,children:t.ip_address})]}),(0,G.jsxs)(`button`,{onClick:()=>l(t),className:`flex items-center gap-2 px-3 py-1.5 text-sm bg-bambu-dark-secondary hover:bg-bambu-dark-tertiary text-white rounded-lg transition-colors flex-shrink-0`,children:[(0,G.jsx)(yu,{className:`w-4 h-4`}),e(`diagnostic.runButton`,`Run diagnostic`)]})]},t.id))}):(0,G.jsx)(`p`,{className:`text-bambu-gray`,children:e(`diagnostic.noPrinters`,`No printers configured.`)})]}),(0,G.jsxs)(I9,{title:e(`systemHealth.sectionTitle`),icon:Pc,children:[(0,G.jsxs)(`div`,{className:`flex items-start justify-between gap-3 mb-3`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`systemHealth.sectionDescription`)}),(0,G.jsxs)(`button`,{onClick:()=>b(),disabled:x,className:`flex items-center gap-2 px-3 py-1.5 text-sm bg-bambu-dark-secondary hover:bg-bambu-dark-tertiary text-white rounded-lg transition-colors flex-shrink-0 disabled:opacity-50`,children:[(0,G.jsx)(zl,{className:`w-4 h-4 ${x?`animate-spin`:``}`}),e(`systemHealth.rescan`)]})]}),v?(0,G.jsx)(Bp,{result:v}):(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`common.loading`)})]}),(0,G.jsxs)(I9,{title:e(`system.database`,`Database`),icon:Us,children:[(0,G.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4 mb-4`,children:[(0,G.jsx)(F9,{icon:Us,label:e(`system.dbEngine`,`Database Engine`),value:u.database.engine||`SQLite`}),(0,G.jsx)(F9,{icon:Us,label:e(`system.dbVersion`,`Version`),value:u.database.version||`unknown`})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-4 mb-4`,children:[(0,G.jsx)(F9,{icon:No,label:e(`system.totalArchives`,`Total Archives`),value:u.database.archives}),(0,G.jsx)(F9,{icon:bs,label:e(`system.completed`,`Completed`),value:u.database.archives_completed,color:`text-green-500`}),(0,G.jsx)(F9,{icon:Ts,label:e(`system.failed`,`Failed`),value:u.database.archives_failed,color:`text-red-500`}),(0,G.jsx)(F9,{icon:Y,label:e(`system.printing`,`Printing`),value:u.database.archives_printing,color:`text-yellow-500`})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-4`,children:[(0,G.jsx)(F9,{icon:Fl,label:e(`system.printers`,`Printers`),value:u.database.printers}),(0,G.jsx)(F9,{icon:Sl,label:e(`system.filaments`,`Filaments`),value:u.database.filaments}),(0,G.jsx)(F9,{icon:mc,label:e(`system.projects`,`Projects`),value:u.database.projects}),(0,G.jsx)(F9,{icon:jl,label:e(`system.smartPlugs`,`Smart Plugs`),value:u.database.smart_plugs})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4 mt-4`,children:[(0,G.jsx)(F9,{icon:ks,label:e(`system.totalPrintTime`,`Total Print Time`),value:u.database.total_print_time_formatted}),(0,G.jsx)(F9,{icon:No,label:e(`system.totalFilament`,`Total Filament Used`),value:`${u.database.total_filament_kg} kg`,subValue:`${u.database.total_filament_grams.toLocaleString()} g`})]})]}),(0,G.jsxs)(I9,{title:e(`system.connectedPrinters`,`Connected Printers`),icon:Fl,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-4 mb-4`,children:[(0,G.jsx)(`div`,{className:`text-3xl font-bold text-bambu-green`,children:u.printers.connected}),(0,G.jsx)(`div`,{className:`text-bambu-gray`,children:e(`system.ofTotal`,`of {{total}} printers connected`,{total:u.printers.total})})]}),u.printers.connected_list.length>0?(0,G.jsx)(`div`,{className:`space-y-2`,children:u.printers.connected_list.map(e=>(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-3 bg-bambu-dark rounded-lg`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`w-2 h-2 rounded-full bg-bambu-green`}),(0,G.jsx)(`span`,{className:`font-medium text-white`,children:e.name})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-4 text-sm text-bambu-gray`,children:[(0,G.jsx)(`span`,{children:e.model}),(0,G.jsx)(`span`,{className:`px-2 py-0.5 rounded ${e.state===`RUNNING`?`bg-bambu-green/20 text-bambu-green`:e.state===`IDLE`?`bg-blue-100 text-blue-700 dark:bg-blue-500/20 dark:text-blue-400`:`bg-bambu-dark-tertiary`}`,children:e.state})]})]},e.id))}):(0,G.jsx)(`p`,{className:`text-bambu-gray`,children:e(`system.noPrintersConnected`,`No printers connected`)})]}),(0,G.jsx)(I9,{title:e(`system.storage`,`Storage`),icon:jc,children:(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex justify-between text-sm mb-1`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:e(`system.diskUsage`,`Disk Usage`)}),(0,G.jsxs)(`span`,{className:`text-white`,children:[u.storage.disk_used_formatted,` / `,u.storage.disk_total_formatted]})]}),(0,G.jsx)(JQe,{percent:u.storage.disk_percent_used,color:T}),(0,G.jsxs)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:[u.storage.disk_free_formatted,` `,e(`system.free`,`free`),` (`,(100-u.storage.disk_percent_used).toFixed(1),`%)`]})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-4`,children:[(0,G.jsx)(F9,{icon:No,label:e(`system.archiveStorage`,`Archive Storage`),value:u.storage.archive_size_formatted}),(0,G.jsx)(F9,{icon:Us,label:e(`system.databaseSize`,`Database Size`),value:u.storage.database_size_formatted}),g&&(0,G.jsx)(F9,{icon:hc,label:e(`system.fileManagerStorage`,`File Manager`),value:qQe(g.total_size_bytes),subValue:`${g.total_files} files, ${g.total_folders} folders`})]})]})}),(0,G.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-6`,children:[(0,G.jsx)(I9,{title:e(`system.memory`,`Memory`),icon:cl,children:(0,G.jsx)(`div`,{className:`space-y-4`,children:(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex justify-between text-sm mb-1`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:e(`system.memoryUsage`,`Memory Usage`)}),(0,G.jsxs)(`span`,{className:`text-white`,children:[u.memory.used_formatted,` / `,u.memory.total_formatted]})]}),(0,G.jsx)(JQe,{percent:u.memory.percent_used,color:E}),(0,G.jsxs)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:[u.memory.available_formatted,` `,e(`system.available`,`available`)]})]})})}),(0,G.jsx)(I9,{title:e(`system.cpu`,`CPU`),icon:Bs,children:(0,G.jsx)(`div`,{className:`space-y-4`,children:(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,G.jsx)(F9,{icon:Bs,label:e(`system.cores`,`Cores`),value:u.cpu.count,subValue:`${u.cpu.count_logical} logical`}),(0,G.jsx)(F9,{icon:Bs,label:e(`system.usage`,`Usage`),value:`${u.cpu.percent}%`})]})})})]}),(0,G.jsx)(I9,{title:e(`system.systemDetails`,`System Details`),icon:Ql,children:(0,G.jsxs)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-4`,children:[(0,G.jsx)(F9,{icon:Ql,label:e(`system.os`,`Operating System`),value:u.system.platform,subValue:u.system.platform_release}),(0,G.jsx)(F9,{icon:Bs,label:e(`system.architecture`,`Architecture`),value:u.system.architecture}),(0,G.jsx)(F9,{icon:Ql,label:e(`system.python`,`Python`),value:u.system.python_version}),(0,G.jsx)(F9,{icon:ks,label:e(`system.bootTime`,`Boot Time`),value:Yf(u.system.boot_time,S)})]})}),c&&(0,G.jsx)(Ip,{printerId:c.id,printerName:c.name,onClose:()=>l(null)})]})}var L9=`auth_remember_me`,R9=`auth_post_login_redirect`;function z9(e){return e?`persistent`:`session`}function XQe(){try{let e=sessionStorage.getItem(L9)===`1`;return sessionStorage.removeItem(L9),e}catch(e){return console.warn(`consumeSavedRememberMe: sessionStorage unavailable, Remember Me preference lost across OIDC redirect`,e),!1}}function B9(e){return!e||!e.startsWith(`/`)||e.startsWith(`//`)||e.startsWith(`/login`)?null:e}function ZQe(e){let t=B9(e);if(t)try{sessionStorage.setItem(R9,t)}catch(e){console.warn(`stashPostLoginRedirect: sessionStorage unavailable, post-login target will be lost across OIDC redirect`,e)}}function QQe(){try{let e=sessionStorage.getItem(R9);return sessionStorage.removeItem(R9),B9(e)}catch(e){return console.warn(`consumePostLoginRedirect: sessionStorage unavailable`,e),null}}function $Qe({provider:e,onClick:t,disabled:n}){let{t:r}=U(),[i,a]=(0,y.useState)(!1);return(0,G.jsxs)(`button`,{type:`button`,onClick:t,disabled:n,className:`w-full flex items-center justify-center gap-3 py-3 px-4 bg-bambu-dark-secondary border border-bambu-dark-tertiary hover:border-bambu-green/50 rounded-lg text-white font-medium transition-colors disabled:opacity-50`,children:[e.has_icon&&!i?(0,G.jsx)(`img`,{src:Z.oidcProviderIconUrl(e.id),alt:``,className:`w-5 h-5 object-contain`,onError:()=>a(!0)}):(0,G.jsx)(iu,{className:`w-5 h-5 text-bambu-green`}),r(`login.twoFA.signInWith`,{provider:e.name})]})}function e$e(){let e=or(),t=rr(),[n]=Li(),{t:r}=U(),{login:i,loginWithToken:a,user:o,loading:s}=Ed(),{showToast:c}=Bd(),{mode:l}=kd();function u(){let e=t.state?.from;if(e?.pathname){let t=B9(`${e.pathname}${e.search??``}`);if(t)return t}return QQe()??`/`}let[d,f]=(0,y.useState)(``),[p,m]=(0,y.useState)(``),[h,g]=(0,y.useState)(!1),[_,v]=(0,y.useState)(``),[b,x]=(0,y.useState)(`credentials`),[S,C]=(0,y.useState)(``),[w,T]=(0,y.useState)([]),[E,D]=(0,y.useState)(`totp`),[O,k]=(0,y.useState)(``),[A,j]=(0,y.useState)(!1),M=(0,y.useRef)(null),[N,P]=(0,y.useState)(!1),[F,I]=(0,y.useState)(``),[L,R]=(0,y.useState)(``),[z,B]=(0,y.useState)(``),{data:V}=K({queryKey:[`advancedAuthStatus`],queryFn:()=>Z.getAdvancedAuthStatus()}),{data:ee}=K({queryKey:[`oidcProviders`],queryFn:()=>Z.getOIDCProviders()}),[te,ne]=(0,y.useState)(!1);(0,y.useEffect)(()=>{!s&&o&&b===`credentials`&&e(`/`,{replace:!0})},[s,o,b,e]);let re=(0,y.useRef)(!1);(0,y.useEffect)(()=>{if(re.current||n.get(`fallback`)===`local`||!V||!V.autologin_provider_id||window.location.hash.startsWith(`#oidc_token=`)||n.get(`oidc_error`))return;re.current=!0;let e=V.autologin_provider_id,t=new Promise((e,t)=>setTimeout(()=>t(Error(`autologin timeout`)),5e3));Promise.race([Z.getOIDCAuthorizeUrl(e),t]).then(e=>{window.location.href=e.auth_url}).catch(()=>{ne(!0)})},[V,n]);let ie=V?.local_login_enabled!==!1,ae=te&&V?.autologin_provider_id!=null;(0,y.useEffect)(()=>{let t=window.location.hash,n=t.startsWith(`#reset_token=`)?t.slice(13):null;n&&(I(n),x(`reset-password`),e(`/login`,{replace:!0}))},[]),(0,y.useEffect)(()=>{let t=window.location.hash,i=t.startsWith(`#oidc_token=`)?t.slice(12):null,o=n.get(`oidc_error`);if(!i&&!o)return;let s=XQe();if(o){c({oidc_provider_error:r(`login.oidcErrors.providerError`),missing_parameters:r(`login.oidcErrors.missingParameters`),invalid_state:r(`login.oidcErrors.invalidState`),state_expired:r(`login.oidcErrors.stateExpired`),provider_not_found:r(`login.oidcErrors.providerNotFound`),discovery_failed:r(`login.oidcErrors.discoveryFailed`),invalid_discovery_document:r(`login.oidcErrors.invalidDiscovery`),token_exchange_network_error:r(`login.oidcErrors.networkError`),token_exchange_bad_response:r(`login.oidcErrors.badResponse`),no_id_token:r(`login.oidcErrors.noIdToken`),token_validation_failed:r(`login.oidcErrors.validationFailed`),nonce_mismatch:r(`login.oidcErrors.nonceMismatch`),missing_sub_claim:r(`login.oidcErrors.missingSubClaim`),no_linked_account:r(`login.oidcErrors.noLinkedAccount`),account_inactive:r(`login.oidcErrors.accountInactive`),user_resolution_failed:r(`login.oidcErrors.userResolutionFailed`),internal_error:r(`login.oidcErrors.internalError`)}[o]??(o.startsWith(`token_exchange_`)?r(`login.oidcErrors.tokenExchangeFailed`):r(`login.oidcLoginFailed`)),`error`),e(`/login`,{replace:!0});return}i&&Z.exchangeOIDCToken(i).then(t=>{if(t.requires_2fa&&t.pre_auth_token){P(s),C(t.pre_auth_token);let n=t.two_fa_methods??[];T(n),n.includes(`totp`)?D(`totp`):n.includes(`email`)?D(`email`):D(`backup`),x(`2fa`),e(`/login`,{replace:!0})}else t.access_token&&t.user?(a(t.access_token,t.user,z9(s)),c(r(`login.loginSuccess`)),e(u(),{replace:!0})):(c(r(`login.oidcLoginFailed`),`error`),e(`/login`,{replace:!0}))}).catch(t=>{console.error(`OIDC token exchange failed`,t),c(r(`login.oidcLoginFailed`),`error`),e(`/login`,{replace:!0})})},[n]);let oe=q({mutationFn:()=>i(d,p,z9(N)),onSuccess:t=>{if(t.requires_2fa&&t.pre_auth_token){C(t.pre_auth_token);let e=t.two_fa_methods??[];T(e),e.includes(`totp`)?D(`totp`):e.includes(`email`)?D(`email`):D(`backup`),x(`2fa`)}else t.access_token&&t.user&&(c(r(`login.loginSuccess`)),e(u(),{replace:!0}))},onError:e=>{c(e.message||r(`login.loginFailed`),`error`)}}),se=q({mutationFn:e=>Z.forgotPassword({email:e}),onSuccess:e=>{c(e.message,`success`),g(!1),v(``)},onError:e=>{c(e.message,`error`)}}),H=q({mutationFn:()=>Z.forgotPasswordConfirm(F,L),onSuccess:e=>{c(e.message,`success`),x(`credentials`),I(``),R(``),B(``)},onError:e=>{c(e.message||r(`login.resetPassword.resetFailed`),`error`)}}),ce=q({mutationFn:()=>Z.sendEmailOTP(S),onSuccess:e=>{j(!0),e.pre_auth_token&&C(e.pre_auth_token),c(e.message,`success`)},onError:e=>{c(e.message||r(`login.twoFA.sendCodeFailed`),`error`)}}),le=q({mutationFn:()=>Z.verify2FA({pre_auth_token:S,code:O,method:E}),onSuccess:t=>{t.access_token&&t.user?(a(t.access_token,t.user,z9(N)),c(r(`login.loginSuccess`)),e(u(),{replace:!0})):(console.error(`2FA verify: unexpected response shape`,t),c(r(`login.loginFailed`),`error`))},onError:e=>{c(e.message||r(`login.twoFA.invalidCode`),`error`),k(``)}}),ue=q({mutationFn:e=>Z.getOIDCAuthorizeUrl(e),onSuccess:e=>{if(N)try{sessionStorage.setItem(L9,`1`)}catch(e){console.warn(`setItem auth_remember_me failed, Remember Me will not carry through OIDC redirect`,e)}let n=t.state?.from;n?.pathname&&ZQe(`${n.pathname}${n.search??``}`),window.location.href=e.auth_url},onError:e=>{c(e.message||r(`login.oidcLoginFailed`),`error`)}}),de=e=>{if(e.preventDefault(),!d||!p){c(r(`login.enterCredentials`),`error`);return}oe.mutate()},fe=e=>{if(e.preventDefault(),!O.trim()){c(r(`login.twoFA.enterCode`),`error`);return}le.mutate()},pe=e=>{if(e.preventDefault(),!_){c(r(`login.enterEmail`),`error`);return}se.mutate(_)},me=e=>{D(e),k(``),j(!1),setTimeout(()=>M.current?.focus(),0)};return b===`reset-password`?(0,G.jsx)(`div`,{className:`min-h-screen flex items-center justify-center bg-bambu-dark p-4`,children:(0,G.jsxs)(`div`,{className:`max-w-md w-full space-y-8 p-8 bg-gradient-to-br from-bambu-card to-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary shadow-lg`,children:[(0,G.jsxs)(`div`,{className:`text-center`,children:[(0,G.jsx)(`div`,{className:`flex items-center justify-center mb-4`,children:(0,G.jsx)(`div`,{className:`w-14 h-14 rounded-full bg-bambu-green/20 flex items-center justify-center`,children:(0,G.jsx)(Uc,{className:`w-7 h-7 text-bambu-green`})})}),(0,G.jsx)(`h2`,{className:`text-2xl font-bold text-white`,children:r(`login.resetPassword.title`)}),(0,G.jsx)(`p`,{className:`mt-2 text-sm text-bambu-gray`,children:r(`login.resetPassword.subtitle`)})]}),(0,G.jsxs)(`form`,{onSubmit:e=>{if(e.preventDefault(),L!==z){c(r(`login.resetPassword.passwordsDoNotMatch`),`error`);return}if(L.length<8){c(r(`login.resetPassword.passwordTooShort`),`error`);return}H.mutate()},className:`space-y-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{htmlFor:`new-password`,className:`block text-sm font-medium text-white mb-2`,children:r(`login.resetPassword.newPassword`)}),(0,G.jsx)(`input`,{id:`new-password`,type:`password`,required:!0,value:L,onChange:e=>R(e.target.value),className:`block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:r(`login.resetPassword.newPasswordPlaceholder`),autoFocus:!0,autoComplete:`new-password`,minLength:8})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{htmlFor:`confirm-password`,className:`block text-sm font-medium text-white mb-2`,children:r(`login.resetPassword.confirmPassword`)}),(0,G.jsx)(`input`,{id:`confirm-password`,type:`password`,required:!0,value:z,onChange:e=>B(e.target.value),className:`block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:r(`login.resetPassword.confirmPasswordPlaceholder`),autoComplete:`new-password`})]}),(0,G.jsx)(`button`,{type:`submit`,disabled:H.isPending||!L||!z,className:`w-full flex justify-center py-3 px-4 bg-bambu-green hover:bg-bambu-green-light text-white font-medium rounded-lg shadow-lg shadow-bambu-green/20 hover:shadow-bambu-green/30 focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:ring-offset-2 focus:ring-offset-bambu-dark-secondary transition-all disabled:opacity-50 disabled:cursor-not-allowed`,children:H.isPending?r(`login.resetPassword.saving`):r(`login.resetPassword.submit`)})]}),(0,G.jsx)(`div`,{className:`text-center`,children:(0,G.jsx)(`button`,{type:`button`,onClick:()=>{x(`credentials`),I(``),R(``),B(``)},className:`text-sm text-bambu-gray hover:text-bambu-green transition-colors`,children:r(`login.resetPassword.backToLogin`)})})]})}):b===`2fa`?(0,G.jsx)(`div`,{className:`min-h-screen flex items-center justify-center bg-bambu-dark p-4`,children:(0,G.jsxs)(`div`,{className:`max-w-md w-full space-y-8 p-8 bg-gradient-to-br from-bambu-card to-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary shadow-lg`,children:[(0,G.jsxs)(`div`,{className:`text-center`,children:[(0,G.jsx)(`div`,{className:`flex items-center justify-center mb-4`,children:(0,G.jsx)(`div`,{className:`w-14 h-14 rounded-full bg-bambu-green/20 flex items-center justify-center`,children:(0,G.jsx)(iu,{className:`w-7 h-7 text-bambu-green`})})}),(0,G.jsx)(`h2`,{className:`text-2xl font-bold text-white`,children:r(`login.twoFA.title`)}),(0,G.jsx)(`p`,{className:`mt-2 text-sm text-bambu-gray`,children:r(`login.twoFA.subtitle`)})]}),w.length>1&&(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[w.includes(`totp`)&&(0,G.jsxs)(`button`,{type:`button`,onClick:()=>me(`totp`),className:`flex-1 flex flex-col items-center gap-1 py-2 px-3 rounded-lg border text-xs font-medium transition-colors ${E===`totp`?`border-bambu-green bg-bambu-green/10 text-bambu-green`:`border-bambu-dark-tertiary text-bambu-gray hover:border-bambu-green/50`}`,children:[(0,G.jsx)(du,{className:`w-4 h-4`}),r(`login.twoFA.methodAuthenticator`)]}),w.includes(`email`)&&(0,G.jsxs)(`button`,{type:`button`,onClick:()=>me(`email`),className:`flex-1 flex flex-col items-center gap-1 py-2 px-3 rounded-lg border text-xs font-medium transition-colors ${E===`email`?`border-bambu-green bg-bambu-green/10 text-bambu-green`:`border-bambu-dark-tertiary text-bambu-gray hover:border-bambu-green/50`}`,children:[(0,G.jsx)(rl,{className:`w-4 h-4`}),r(`login.twoFA.methodEmail`)]}),w.includes(`backup`)&&(0,G.jsxs)(`button`,{type:`button`,onClick:()=>me(`backup`),className:`flex-1 flex flex-col items-center gap-1 py-2 px-3 rounded-lg border text-xs font-medium transition-colors ${E===`backup`?`border-bambu-green bg-bambu-green/10 text-bambu-green`:`border-bambu-dark-tertiary text-bambu-gray hover:border-bambu-green/50`}`,children:[(0,G.jsx)(Uc,{className:`w-4 h-4`}),r(`login.twoFA.methodBackup`)]})]}),(0,G.jsxs)(`form`,{onSubmit:fe,className:`space-y-4`,children:[E===`totp`&&(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:r(`login.twoFA.instructionsTotp`)}),E===`email`&&(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:r(A?`login.twoFA.instructionsEmail`:`login.twoFA.instructionsEmailNotSent`)}),!A&&(0,G.jsx)(Q,{type:`button`,variant:`secondary`,className:`w-full`,onClick:()=>ce.mutate(),disabled:ce.isPending,children:ce.isPending?r(`login.twoFA.sendingCode`):r(`login.twoFA.sendCodeButton`)}),A&&(0,G.jsx)(`button`,{type:`button`,onClick:()=>{j(!1),ce.mutate()},className:`text-xs text-bambu-gray hover:text-bambu-green transition-colors`,children:r(`login.twoFA.resendCode`)})]}),E===`backup`&&(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:r(`login.twoFA.instructionsBackup`)}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{htmlFor:`twofa-code`,className:`block text-sm font-medium text-white mb-2`,children:r(E===`backup`?`login.twoFA.backupCodeLabel`:`login.twoFA.codeLabel`)}),(0,G.jsx)(`input`,{ref:M,id:`twofa-code`,type:`text`,inputMode:E===`backup`?`text`:`numeric`,autoComplete:`one-time-code`,value:O,onChange:e=>k(e.target.value.trim()),disabled:E===`email`&&!A,className:`block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray text-center tracking-widest text-xl font-mono focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors disabled:opacity-40`,placeholder:r(E===`backup`?`login.twoFA.backupCodePlaceholder`:`login.twoFA.codePlaceholder`),maxLength:E===`backup`?8:6,autoFocus:!0})]}),(0,G.jsx)(`button`,{type:`submit`,disabled:le.isPending||!O.trim()||E===`email`&&!A,className:`w-full flex justify-center py-3 px-4 bg-bambu-green hover:bg-bambu-green-light text-white font-medium rounded-lg shadow-lg shadow-bambu-green/20 hover:shadow-bambu-green/30 focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:ring-offset-2 focus:ring-offset-bambu-dark-secondary transition-all disabled:opacity-50 disabled:cursor-not-allowed`,children:le.isPending?r(`login.twoFA.verifyingButton`):r(`login.twoFA.verifyButton`)})]}),(0,G.jsx)(`div`,{className:`text-center`,children:(0,G.jsx)(`button`,{type:`button`,onClick:()=>{x(`credentials`),C(``),k(``),j(!1)},className:`text-sm text-bambu-gray hover:text-bambu-green transition-colors`,children:r(`login.twoFA.backToLogin`)})})]})}):(0,G.jsxs)(`div`,{className:`min-h-screen flex items-center justify-center bg-bambu-dark p-4`,children:[(0,G.jsxs)(`div`,{className:`max-w-md w-full space-y-8 p-8 bg-gradient-to-br from-bambu-card to-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary shadow-lg`,children:[(0,G.jsxs)(`div`,{className:`text-center`,children:[(0,G.jsx)(`div`,{className:`flex items-center justify-center mb-6`,children:(0,G.jsx)(`img`,{src:l===`dark`?`/img/bambuddy_logo_dark_transparent.png`:`/img/bambuddy_logo_light.png`,alt:`Bambuddy`,className:`h-16`})}),(0,G.jsx)(`h2`,{className:`text-3xl font-bold text-white`,children:r(`login.title`)}),(0,G.jsx)(`p`,{className:`mt-2 text-sm text-bambu-gray`,children:r(`login.subtitle`)})]}),ae&&(0,G.jsx)(`div`,{className:`mt-6 rounded-lg border border-amber-300 dark:border-amber-500/40 bg-amber-50 dark:bg-amber-500/10 px-4 py-3 text-sm text-amber-800 dark:text-amber-200`,children:r(`login.autologinFailed`)}),!ie&&(0,G.jsx)(`div`,{className:`mt-6 rounded-lg border border-bambu-dark-tertiary bg-bambu-dark/40 px-4 py-3 text-sm text-bambu-gray`,children:r(`login.localDisabledNotice`)}),ie&&(0,G.jsxs)(`form`,{className:`mt-8 space-y-6`,onSubmit:de,children:[(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{htmlFor:`username`,className:`block text-sm font-medium text-white mb-2`,children:V?.advanced_auth_enabled?r(`login.usernameOrEmail`):r(`login.username`)}),(0,G.jsx)(`input`,{id:`username`,type:`text`,required:!0,value:d,onChange:e=>f(e.target.value),className:`block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:V?.advanced_auth_enabled?r(`login.usernameOrEmailPlaceholder`):r(`login.usernamePlaceholder`),autoComplete:`username`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{htmlFor:`password`,className:`block text-sm font-medium text-white mb-2`,children:r(`login.password`)||`Password`}),(0,G.jsx)(`input`,{id:`password`,type:`password`,required:!0,value:p,onChange:e=>m(e.target.value),className:`block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:r(`login.passwordPlaceholder`),autoComplete:`current-password`})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`input`,{id:`remember-me`,type:`checkbox`,checked:N,onChange:e=>P(e.target.checked),className:`h-4 w-4 rounded border-bambu-dark-tertiary bg-bambu-dark-secondary text-bambu-green focus:ring-bambu-green/50 cursor-pointer`}),(0,G.jsx)(`label`,{htmlFor:`remember-me`,className:`text-sm text-bambu-gray cursor-pointer`,children:r(`login.rememberMe`)})]}),(0,G.jsx)(`div`,{children:(0,G.jsx)(`button`,{type:`submit`,disabled:oe.isPending,className:`w-full flex justify-center py-3 px-4 bg-bambu-green hover:bg-bambu-green-light text-white font-medium rounded-lg shadow-lg shadow-bambu-green/20 hover:shadow-bambu-green/30 focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:ring-offset-2 focus:ring-offset-bambu-dark-secondary transition-all disabled:opacity-50 disabled:cursor-not-allowed disabled:hover:bg-bambu-green`,children:oe.isPending?r(`login.signingIn`):r(`login.signIn`)})}),(0,G.jsx)(`div`,{className:`text-center`,children:(0,G.jsx)(`button`,{type:`button`,onClick:()=>g(!0),className:`text-sm text-bambu-gray hover:text-bambu-green transition-colors`,children:r(`login.forgotPassword`)})})]}),ee&&ee.length>0&&(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(`div`,{className:`absolute inset-0 flex items-center`,children:(0,G.jsx)(`div`,{className:`w-full border-t border-bambu-dark-tertiary`})}),(0,G.jsx)(`div`,{className:`relative flex justify-center text-sm`,children:(0,G.jsx)(`span`,{className:`px-2 bg-bambu-dark-secondary text-bambu-gray`,children:r(`login.twoFA.orContinueWith`)})})]}),(0,G.jsx)(`div`,{className:`space-y-2`,children:ee.map(e=>(0,G.jsx)($Qe,{provider:e,onClick:()=>ue.mutate(e.id),disabled:ue.isPending},e.id))})]})]}),h&&(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:()=>g(!1),children:(0,G.jsxs)(Md,{className:`w-full max-w-md`,onClick:e=>e.stopPropagation(),children:[(0,G.jsx)(Nd,{children:(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(rl,{className:`w-5 h-5 text-bambu-green`}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:r(`login.forgotPasswordTitle`)})]}),(0,G.jsx)(Q,{variant:`ghost`,size:`sm`,onClick:()=>{g(!1),v(``)},children:(0,G.jsx)($u,{className:`w-5 h-5`})})]})}),(0,G.jsx)(Pd,{children:V?.advanced_auth_enabled?(0,G.jsxs)(`form`,{onSubmit:pe,className:`space-y-4`,children:[(0,G.jsx)(`p`,{className:`text-bambu-gray text-sm`,children:r(`login.forgotPasswordEmailMessage`)}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{htmlFor:`forgot-email`,className:`block text-sm font-medium text-white mb-2`,children:r(`login.emailAddress`)}),(0,G.jsx)(`input`,{id:`forgot-email`,type:`email`,required:!0,value:_,onChange:e=>v(e.target.value),className:`block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:r(`login.emailPlaceholder`)})]}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,className:`flex-1`,onClick:()=>{g(!1),v(``)},children:r(`login.cancel`)}),(0,G.jsx)(Q,{type:`submit`,className:`flex-1`,disabled:se.isPending,children:se.isPending?r(`login.sending`):r(`login.sendResetEmail`)})]})]}):(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsx)(`p`,{className:`text-bambu-gray`,children:r(`login.forgotPasswordMessage`)}),(0,G.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-4 space-y-2`,children:[(0,G.jsx)(`p`,{className:`text-sm text-white font-medium`,children:r(`login.howToReset`)}),(0,G.jsxs)(`ol`,{className:`text-sm text-bambu-gray space-y-1 list-decimal list-inside`,children:[(0,G.jsx)(`li`,{children:r(`login.resetStep1`)}),(0,G.jsx)(`li`,{children:r(`login.resetStep2`)}),(0,G.jsx)(`li`,{children:r(`login.resetStep3`)}),(0,G.jsx)(`li`,{children:r(`login.resetStep4`)})]})]}),(0,G.jsx)(Q,{variant:`secondary`,className:`w-full`,onClick:()=>g(!1),children:r(`login.gotIt`)})]})})]})})]})}function t$e(){let e=or(),{t}=U(),{showToast:n}=Bd(),{mode:r}=kd(),{refreshAuth:i}=Ed(),[a,o]=(0,y.useState)(!1),[s,c]=(0,y.useState)(``),[l,u]=(0,y.useState)(``),[d,f]=(0,y.useState)(``),p=q({mutationFn:()=>Z.setupAuth({auth_enabled:a,admin_username:a?s:void 0,admin_password:a?l:void 0}),onSuccess:async r=>{await i(),r.auth_enabled?r.admin_created?(n(t(`setup.toast.authEnabledAdminCreated`)),e(`/login`)):(n(t(`setup.toast.authEnabledExistingAdmins`)),e(`/login`)):(n(t(`setup.toast.setupCompleted`)),e(`/`))},onError:e=>{n(e.message,`error`)}});return(0,G.jsx)(`div`,{className:`min-h-screen flex items-center justify-center bg-bambu-dark p-4`,children:(0,G.jsxs)(`div`,{className:`max-w-md w-full space-y-8 p-8 bg-gradient-to-br from-bambu-card to-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary shadow-lg`,children:[(0,G.jsxs)(`div`,{className:`text-center`,children:[(0,G.jsx)(`div`,{className:`flex items-center justify-center mb-6`,children:(0,G.jsx)(`img`,{src:r===`dark`?`/img/bambuddy_logo_dark_transparent.png`:`/img/bambuddy_logo_light.png`,alt:`Bambuddy`,className:`h-16`})}),(0,G.jsx)(`h2`,{className:`text-3xl font-bold text-white`,children:t(`setup.title`)}),(0,G.jsx)(`p`,{className:`mt-2 text-sm text-bambu-gray`,children:t(`setup.subtitle`)})]}),(0,G.jsxs)(`form`,{className:`mt-8 space-y-6`,onSubmit:e=>{if(e.preventDefault(),a&&(s||l)){if(!s||!l){n(t(`setup.toast.enterBothCredentials`),`error`);return}if(l!==d){n(t(`setup.toast.passwordsDoNotMatch`),`error`);return}if(l.length<6){n(t(`setup.toast.passwordTooShort`),`error`);return}}p.mutate()},children:[(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center p-4 bg-bambu-dark-secondary/50 rounded-lg border border-bambu-dark-tertiary`,children:[(0,G.jsx)(`input`,{id:`auth-enabled`,type:`checkbox`,checked:a,onChange:e=>o(e.target.checked),className:`h-4 w-4 text-bambu-green focus:ring-bambu-green border-bambu-dark-tertiary rounded bg-bambu-dark-secondary`}),(0,G.jsx)(`label`,{htmlFor:`auth-enabled`,className:`ml-3 block text-sm font-medium text-white`,children:t(`setup.enableAuth`)})]}),a&&(0,G.jsxs)(`div`,{className:`space-y-4 mt-4`,children:[(0,G.jsx)(`div`,{className:`p-3 bg-bambu-dark-secondary/50 border border-bambu-dark-tertiary rounded-lg`,children:(0,G.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,G.jsx)(Vc,{className:`w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0`}),(0,G.jsxs)(`div`,{className:`text-sm text-bambu-gray`,children:[(0,G.jsx)(`p`,{className:`text-white font-medium mb-1`,children:t(`setup.adminAccount`)}),(0,G.jsx)(`p`,{children:t(`setup.adminAccountDesc`)})]})]})}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{htmlFor:`admin-username`,className:`block text-sm font-medium text-white mb-2`,children:[t(`setup.adminUsername`),` `,(0,G.jsx)(`span`,{className:`text-bambu-gray text-xs`,children:t(`setup.optionalIfAdminExists`)})]}),(0,G.jsx)(`input`,{id:`admin-username`,type:`text`,value:s,onChange:e=>c(e.target.value),className:`block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:t(`setup.adminUsernamePlaceholder`),autoComplete:`username`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{htmlFor:`admin-password`,className:`block text-sm font-medium text-white mb-2`,children:[t(`setup.adminPassword`),` `,(0,G.jsx)(`span`,{className:`text-bambu-gray text-xs`,children:t(`setup.optionalIfAdminExists`)})]}),(0,G.jsx)(`input`,{id:`admin-password`,type:`password`,value:l,onChange:e=>u(e.target.value),className:`block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:t(`setup.adminPasswordPlaceholder`),minLength:6,autoComplete:`new-password`})]}),l&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{htmlFor:`confirm-password`,className:`block text-sm font-medium text-white mb-2`,children:t(`setup.confirmPassword`)}),(0,G.jsx)(`input`,{id:`confirm-password`,type:`password`,value:d,onChange:e=>f(e.target.value),className:`block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:t(`setup.confirmPasswordPlaceholder`),minLength:6,autoComplete:`new-password`})]})]})]}),(0,G.jsx)(`div`,{children:(0,G.jsx)(`button`,{type:`submit`,disabled:p.isPending,className:`w-full flex justify-center py-3 px-4 bg-bambu-green hover:bg-bambu-green-light text-white font-medium rounded-lg shadow-lg shadow-bambu-green/20 hover:shadow-bambu-green/30 focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:ring-offset-2 focus:ring-offset-bambu-dark-secondary transition-all disabled:opacity-50 disabled:cursor-not-allowed disabled:hover:bg-bambu-green`,children:p.isPending?t(`setup.settingUp`):t(`setup.completeSetup`)})})]})]})})}function n$e(){let{t:e}=U(),{user:t}=Ed(),{showToast:n}=Bd(),r=so(),i=or(),[a,o]=(0,y.useState)(!0),[s,c]=(0,y.useState)(!0),[l,u]=(0,y.useState)(!0),[d,f]=(0,y.useState)(!0),[p,m]=(0,y.useState)(!1),{data:h,isLoading:g}=K({queryKey:[`advancedAuthStatus`],queryFn:Z.getAdvancedAuthStatus,staleTime:300*1e3}),{data:_,isLoading:v}=K({queryKey:[`settings`],queryFn:Z.getSettings,staleTime:300*1e3}),{data:b,isLoading:x}=K({queryKey:[`user-email-preferences`],queryFn:()=>Z.getUserEmailPreferences()});(0,y.useEffect)(()=>{(h&&!h.advanced_auth_enabled||_&&!_.user_notifications_enabled)&&i(`/settings`,{replace:!0})},[h,_,i]),(0,y.useEffect)(()=>{b&&(o(b.notify_print_start),c(b.notify_print_complete),u(b.notify_print_failed),f(b.notify_print_stopped),m(!1))},[b]);let S=q({mutationFn:()=>Z.updateUserEmailPreferences({notify_print_start:a,notify_print_complete:s,notify_print_failed:l,notify_print_stopped:d}),onSuccess:()=>{r.invalidateQueries({queryKey:[`user-email-preferences`]}),m(!1),n(e(`notifications.userEmail.saveSuccess`),`success`)},onError:t=>{n(t.message||e(`notifications.userEmail.saveError`),`error`)}}),C=(e,t)=>{e(!t),m(!0)};return x||g||v?(0,G.jsx)(`div`,{className:`flex items-center justify-center h-64`,children:(0,G.jsx)(Y,{className:`w-8 h-8 animate-spin text-bambu-green`})}):(0,G.jsxs)(`div`,{className:`p-4 md:p-6 max-w-2xl mx-auto`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3 mb-6`,children:[(0,G.jsx)(Go,{className:`w-7 h-7 text-bambu-green`}),(0,G.jsx)(`h1`,{className:`text-2xl font-bold text-white`,children:e(`notifications.userEmail.title`)})]}),(0,G.jsx)(Md,{className:`mb-6 border-blue-300 bg-blue-50 dark:border-blue-500/30 dark:bg-blue-500/5`,children:(0,G.jsx)(Pd,{className:`py-4`,children:(0,G.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,G.jsx)(`div`,{className:`w-10 h-10 rounded-full flex items-center justify-center bg-blue-100 dark:bg-blue-500/20 flex-shrink-0`,children:(0,G.jsx)(rl,{className:`w-5 h-5 text-blue-600 dark:text-blue-400`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`text-white font-medium`,children:e(`notifications.userEmail.emailNotifications`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:e(`notifications.userEmail.emailNotificationsDesc`)}),t?.email?(0,G.jsxs)(`p`,{className:`text-sm text-blue-700 dark:text-blue-400 mt-2`,children:[e(`notifications.userEmail.sendingTo`),`: `,(0,G.jsx)(`strong`,{children:t.email})]}):(0,G.jsx)(`p`,{className:`text-sm text-yellow-700 dark:text-yellow-400 mt-2`,children:e(`notifications.userEmail.noEmailWarning`)})]})]})})}),(0,G.jsxs)(Md,{className:`mb-6`,children:[(0,G.jsxs)(Nd,{children:[(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`notifications.userEmail.printJobNotifications`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:e(`notifications.userEmail.printJobNotificationsDesc`)})]}),(0,G.jsxs)(Pd,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-4 bg-bambu-dark rounded-lg`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`w-10 h-10 rounded-full flex items-center justify-center ${a?`bg-bambu-green/20`:`bg-bambu-dark-tertiary`}`,children:(0,G.jsx)(bs,{className:`w-5 h-5 ${a?`text-bambu-green`:`text-bambu-gray`}`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white font-medium`,children:e(`notifications.userEmail.printJobStarts`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`notifications.userEmail.printJobStartsDesc`)})]})]}),(0,G.jsx)(`button`,{onClick:()=>C(o,a),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors focus:outline-none focus:ring-2 focus:ring-bambu-green focus:ring-offset-2 focus:ring-offset-bambu-dark ${a?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,role:`switch`,"aria-checked":a,children:(0,G.jsx)(`span`,{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${a?`translate-x-6`:`translate-x-1`}`})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-4 bg-bambu-dark rounded-lg`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`w-10 h-10 rounded-full flex items-center justify-center ${s?`bg-bambu-green/20`:`bg-bambu-dark-tertiary`}`,children:(0,G.jsx)(bs,{className:`w-5 h-5 ${s?`text-bambu-green`:`text-bambu-gray`}`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white font-medium`,children:e(`notifications.userEmail.printJobFinishes`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`notifications.userEmail.printJobFinishesDesc`)})]})]}),(0,G.jsx)(`button`,{onClick:()=>C(c,s),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors focus:outline-none focus:ring-2 focus:ring-bambu-green focus:ring-offset-2 focus:ring-offset-bambu-dark ${s?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,role:`switch`,"aria-checked":s,children:(0,G.jsx)(`span`,{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${s?`translate-x-6`:`translate-x-1`}`})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-4 bg-bambu-dark rounded-lg`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`w-10 h-10 rounded-full flex items-center justify-center ${l?`bg-bambu-green/20`:`bg-bambu-dark-tertiary`}`,children:(0,G.jsx)(bs,{className:`w-5 h-5 ${l?`text-bambu-green`:`text-bambu-gray`}`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white font-medium`,children:e(`notifications.userEmail.printErrors`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`notifications.userEmail.printErrorsDesc`)})]})]}),(0,G.jsx)(`button`,{onClick:()=>C(u,l),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors focus:outline-none focus:ring-2 focus:ring-bambu-green focus:ring-offset-2 focus:ring-offset-bambu-dark ${l?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,role:`switch`,"aria-checked":l,children:(0,G.jsx)(`span`,{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${l?`translate-x-6`:`translate-x-1`}`})})]}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-4 bg-bambu-dark rounded-lg`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`w-10 h-10 rounded-full flex items-center justify-center ${d?`bg-bambu-green/20`:`bg-bambu-dark-tertiary`}`,children:(0,G.jsx)(bs,{className:`w-5 h-5 ${d?`text-bambu-green`:`text-bambu-gray`}`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-white font-medium`,children:e(`notifications.userEmail.printJobStops`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:e(`notifications.userEmail.printJobStopsDesc`)})]})]}),(0,G.jsx)(`button`,{onClick:()=>C(f,d),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors focus:outline-none focus:ring-2 focus:ring-bambu-green focus:ring-offset-2 focus:ring-offset-bambu-dark ${d?`bg-bambu-green`:`bg-bambu-dark-tertiary`}`,role:`switch`,"aria-checked":d,children:(0,G.jsx)(`span`,{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${d?`translate-x-6`:`translate-x-1`}`})})]})]})]}),(0,G.jsx)(`div`,{className:`flex justify-end`,children:(0,G.jsx)(Q,{onClick:()=>S.mutate(),disabled:!p||S.isPending||!t?.email,children:S.isPending?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),e(`common.saving`)]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Wl,{className:`w-4 h-4`}),e(`common.save`)]})})})]})}function r$e(){let e=or(),[t]=Li(),{t:n}=U(),r=t.get(`archive`),i=t.get(`library_file`),a=t.get(`plate`),o=K({queryKey:[`gcode-viewer-archive-colors`,r],queryFn:()=>Z.getArchiveCapabilities(Number(r)),enabled:!!r,staleTime:5*6e4,retry:!1}),s=K({queryKey:[`gcode-viewer-library-colors`,i],queryFn:()=>Z.getLibraryFilePlates(Number(i)),enabled:!!i,staleTime:5*6e4,retry:!1}),c=(0,y.useMemo)(()=>{if(r)return o.data?.filament_colors;let e=s.data?.plates??[],t=a?Number(a):null,n=t!=null&&e.find(e=>e.index===t)||e[0];if(!n?.filaments?.length)return;let i=[];for(let e of n.filaments){let t=Math.max(0,(e.slot_id??1)-1);e.color&&(i[t]=e.color)}return i.length>0?i:void 0},[r,o.data,s.data,a]),l=(0,y.useMemo)(()=>{let e=e=>a?`${e}?plate=${encodeURIComponent(a)}`:e;return r?e(Z.getArchiveGcode(Number(r))):i?e(Z.getLibraryFileGcodeUrl(Number(i))):null},[r,i,a]),u=()=>{window.history.length>1?e(-1):e(r?`/archives`:`/files`)},d=r?n(`gcodeViewer.backToArchives`,`Back to Archives`):n(`gcodeViewer.backToFiles`,`Back to File Manager`);return(0,G.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,G.jsx)(`div`,{className:`flex-shrink-0 px-4 py-2 border-b border-bambu-dark-tertiary`,children:(0,G.jsxs)(`button`,{type:`button`,onClick:u,className:`inline-flex items-center gap-1.5 text-sm text-gray-700 dark:text-gray-300 hover:text-gray-900 dark:hover:text-white transition-colors`,children:[(0,G.jsx)(Io,{className:`w-4 h-4`}),d]})}),l?(0,G.jsx)(dse,{gcodeUrl:l,filamentColors:c,className:`flex-1 min-h-0`}):(0,G.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-sm text-bambu-gray`,children:n(`gcodeViewer.noSource`,`No file was given to preview.`)})]})}var i$e=4401;function a$e(){let e=(0,y.useRef)(null),t=(0,y.useRef)(null),n=(0,y.useRef)(!1),r=so(),[i,a]=(0,y.useState)(!1),o=(0,y.useRef)(new Map),{showToast:s}=Bd(),{t:c}=U(),l=(0,y.useRef)(new Set),u=(0,y.useRef)(null),d=(0,y.useRef)(new Map),f=(0,y.useRef)(null),p=(0,y.useRef)([]),m=(0,y.useRef)(!1),h=(0,y.useRef)(()=>{}),g=(0,y.useCallback)(()=>{if(m.current||p.current.length===0)return;m.current=!0;let e=()=>{let t=p.current.shift();t?(h.current(t),p.current.length>0?setTimeout(e,16):m.current=!1):m.current=!1};e()},[]),_=(0,y.useCallback)(async()=>{if(n.current||e.current?.readyState===WebSocket.OPEN)return;let r;try{r=(await Z.getWebSocketToken()).token}catch(e){let t=e instanceof id?e.status:0;if(t===401||t===403)return}if(n.current)return;let i=window.location.protocol===`https:`?`wss:`:`ws:`,o=r?`?token=${encodeURIComponent(r)}`:``,s=`${i}//${window.location.host}/api/v1/ws${o}`,c=new WebSocket(s),l=null;c.onopen=()=>{console.log(`[WebSocket] Connected`),a(!0),l=window.setInterval(()=>{c.readyState===WebSocket.OPEN&&c.send(JSON.stringify({type:`ping`}))},3e4)},c.onmessage=e=>{try{let t=JSON.parse(e.data);t.type===`printer_status`&&t.printer_id!==void 0&&t.data?h.current(t):(p.current.push(t),g())}catch{}},c.onclose=r=>{console.log(`[WebSocket] Closed`,r.code,r.reason),l&&=(clearInterval(l),null),a(!1),e.current=null,!(n.current||r.code===i$e)&&(t.current=window.setTimeout(()=>{_()},3e3))},c.onerror=e=>{console.error(`[WebSocket] Error`,e),c.close()},e.current=c},[g]),v=(0,y.useCallback)(()=>{f.current&&=(clearTimeout(f.current),null);let e=new Map(d.current);d.current.clear(),e.forEach((e,t)=>{r.setQueryData([`printerStatus`,t],t=>{let n={...t,...e};return n.wifi_signal==null&&t?.wifi_signal!=null&&(n.wifi_signal=t.wifi_signal),n})})},[r]),b=(0,y.useCallback)((e,t)=>{let n=d.current.get(e)||{};if(d.current.set(e,{...n,...t}),document.hidden){v();return}f.current||=window.setTimeout(v,100)},[v]),x=(0,y.useCallback)(e=>{l.current.add(e),u.current&&clearTimeout(u.current),u.current=window.setTimeout(()=>{let e=Array.from(l.current);l.current.clear(),u.current=null;let t=0;e.forEach(e=>{setTimeout(()=>{r.invalidateQueries({queryKey:[e]})},t),t+=500})},3e3)},[r]),S=(0,y.useCallback)(e=>{switch(e.type){case`printer_status`:e.printer_id!==void 0&&e.data&&b(e.printer_id,e.data);break;case`print_start`:e.printer_id!==void 0&&r.invalidateQueries({queryKey:[`printerStatus`,e.printer_id]});break;case`missing_spool_assignment`:{if(e.printer_id===void 0||!Array.isArray(e.missing_slots))break;let t=e.missing_slots.map(e=>e&&typeof e.slot==`string`?e.slot:`Unknown`).filter(e=>e.length>0);if(t.length===0){o.current.delete(e.printer_id);break}let n=t.join(`|`);if(o.current.get(e.printer_id)===n)break;o.current.set(e.printer_id,n),s(c(`printers.toast.missingSpoolAssignment`,{printer:e.printer_name||`Printer ${e.printer_id}`,slots:t.join(`, `)}),`warning`);break}case`print_complete`:x(`archives`),x(`archiveStats`);break;case`kill_switch_triggered`:s(c(`printers.toast.killSwitchTriggered`,{printer:e.printer_name||`Printer ${e.printer_id??`?`}`,filename:e.filename||c(`common.unknown`)}),`error`);break;case`billing_charge_failed`:s(c(`printers.toast.billingChargeFailed`,{printer:e.printer_name||`Printer ${e.printer_id??`?`}`,filename:e.filename||c(`common.unknown`)}),`error`);break;case`archive_created`:x(`archives`),x(`archiveStats`);break;case`archive_updated`:x(`archives`);break;case`pong`:break;case`plate_not_empty`:window.dispatchEvent(new CustomEvent(`plate-not-empty`,{detail:{printer_id:e.printer_id,printer_name:e.printer_name,message:e.message}}));break;case`inventory_changed`:x(`inventory-spools`),x(`spoolman-inventory-spools`),x(b9[0]);break;case`spool_assignment_changed`:x(`spool-assignments`),x(`slotPresets`);break;case`spool_assignment_verified`:{let t=e.printer_name||`Printer`,n=e.slot||`?`;e.verified?e.kprofile_applied===!1?s(c(`printers.toast.assignmentVerifiedNoKprofile`,{slot:n,printer:t}),`warning`):s(c(`printers.toast.assignmentVerified`,{slot:n,printer:t}),`success`):s(c(`printers.toast.assignmentNotConfirmed`,{slot:n,printer:t}),`warning`);break}case`spool_auto_assigned`:x(`inventory-spools`),x(`spool-assignments`);break;case`spool_usage_logged`:x(`inventory-spools`);break;case`unknown_tag`:{let t=e;window.dispatchEvent(new CustomEvent(`unknown-tag`,{detail:{printer_id:t.printer_id,ams_id:t.ams_id,tray_id:t.tray_id,tag_uid:t.tag_uid,tray_uuid:t.tray_uuid,tray_type:t.tray_type,tray_color:t.tray_color,tray_sub_brands:t.tray_sub_brands,tray_count:t.tray_count}}));break}case`spoolbuddy_weight`:window.dispatchEvent(new CustomEvent(`spoolbuddy-weight`,{detail:e}));break;case`spoolbuddy_tag_matched`:window.dispatchEvent(new CustomEvent(`spoolbuddy-tag-matched`,{detail:e})),x(`inventory-spools`);break;case`spoolbuddy_unknown_tag`:window.dispatchEvent(new CustomEvent(`spoolbuddy-unknown-tag`,{detail:e}));break;case`spoolbuddy_tag_removed`:window.dispatchEvent(new CustomEvent(`spoolbuddy-tag-removed`,{detail:e}));break;case`spoolbuddy_tag_written`:window.dispatchEvent(new CustomEvent(`spoolbuddy-tag-written`,{detail:e})),x(`inventory-spools`);break;case`spoolbuddy_tag_write_failed`:window.dispatchEvent(new CustomEvent(`spoolbuddy-tag-write-failed`,{detail:e}));break;case`spoolbuddy_online`:window.dispatchEvent(new CustomEvent(`spoolbuddy-online`,{detail:e})),x(`spoolbuddy-devices`),x(`spoolbuddy-update-check`);break;case`spoolbuddy_offline`:window.dispatchEvent(new CustomEvent(`spoolbuddy-offline`,{detail:e})),x(`spoolbuddy-devices`);break;case`spoolbuddy_update`:x(`spoolbuddy-devices`),x(`spoolbuddy-update-check`);break;case`queue_item_uploading`:case`queue_item_upload_progress`:case`queue_item_acked`:case`queue_item_failed`:window.dispatchEvent(new CustomEvent(`bambuddy:dispatch-toast`,{detail:e}));break;case`pipeline_run_updated`:r.invalidateQueries({queryKey:[`pipeline-runs-all`]}),e.run?.pipeline_id&&r.invalidateQueries({queryKey:[`pipeline-runs`,e.run.pipeline_id]});break}},[r,x,b,s,c]);return(0,y.useEffect)(()=>{h.current=S},[S]),(0,y.useEffect)(()=>(n.current=!1,_(),()=>{n.current=!0,t.current&&clearTimeout(t.current),u.current&&clearTimeout(u.current),f.current&&clearTimeout(f.current),e.current&&e.current.close()}),[_]),{isConnected:i,sendMessage:(0,y.useCallback)(t=>{e.current?.readyState===WebSocket.OPEN&&e.current.send(JSON.stringify(t))},[])}}var o$e=`#00ae42`,s$e=e=>e!=null&&e>0?e:1/0;function c$e(e){let t=null;for(let n of e){if(!n||n.state!==`RUNNING`||n.progress==null)continue;if(t===null){t=n;continue}let e=s$e(n.remaining_time),r=s$e(t.remaining_time);(e(t.progress??0))&&(t=n)}return t}function l$e(e){let t=document.createElement(`canvas`);t.width=32,t.height=32;let n=t.getContext(`2d`);if(!n)return null;let r=getComputedStyle(document.documentElement).getPropertyValue(`--accent`).trim()||o$e,i=Math.max(0,Math.min(100,e))/100,a=-Math.PI/2;return n.lineWidth=4,n.beginPath(),n.arc(16,16,13,0,Math.PI*2),n.strokeStyle=`rgba(128,128,128,0.3)`,n.stroke(),n.beginPath(),n.arc(16,16,13,a,a+i*Math.PI*2),n.strokeStyle=r,n.lineCap=`round`,n.stroke(),t.toDataURL(`image/png`)}function V9(e,t){document.querySelectorAll(`link[rel~="icon"]`).forEach(n=>{if(e)t.has(n)||t.set(n,n.href),n.href=e;else{let e=t.get(n);e!==void 0&&(n.href=e)}}),e||t.clear()}function u$e(){let{progressInTitle:e,resolvedMode:t,darkAccent:n,lightAccent:r}=kd(),i=t===`dark`?n:r,{data:a}=K({queryKey:[`printers`],queryFn:Z.getPrinters,enabled:e}),o=So({queries:(e?a??[]:[]).map(e=>({queryKey:[`printerStatus`,e.id],queryFn:()=>Z.getPrinterStatus(e.id)}))}),s=(0,y.useRef)(new Map),c=(0,y.useRef)(document.title),l=(0,y.useRef)(!1),u=e?c$e(o.map(e=>e.data)):null,d=u&&u.progress!=null?Math.round(u.progress):null;(0,y.useEffect)(()=>{e&&d!=null?(document.title=`${d}% · ${c.current}`,V9(l$e(d),s.current),l.current=!0):l.current&&=(document.title=c.current,V9(null,s.current),!1)},[e,d,i]),(0,y.useEffect)(()=>{let e=s.current,t=l,n=c.current;return()=>{t.current&&(document.title=n,V9(null,e))}},[])}function d$e({children:e}){let{authEnabled:t,user:n,loading:r}=Ed(),{data:i}=K({queryKey:[`color-catalog-map`],queryFn:async()=>(await Z.getColorNameMap()).colors,staleTime:1/0,gcTime:1/0,retry:2,enabled:!r&&(!t||n!==null)});return(0,y.useEffect)(()=>{i&&lf(i)},[i]),(0,G.jsx)(G.Fragment,{children:e})}function f$e({selectedPrinterId:e,onPrinterChange:t,deviceOnline:n}){let{t:r}=U(),[i,a]=(0,y.useState)(new Date),{data:o=[]}=K({queryKey:[`printers`],queryFn:()=>Z.getPrinters()}),s=So({queries:o.map(e=>({queryKey:[`printerStatus`,e.id],queryFn:()=>Z.getPrinterStatus(e.id),refetchInterval:1e4}))}),c=(0,y.useMemo)(()=>o.filter((e,t)=>s[t]?.data?.connected),[o,s]);(0,y.useEffect)(()=>{let n=c.some(t=>t.id===e);(!e||!n)&&c.length>0&&t(c[0].id)},[c,e,t]);let{data:l}=K({queryKey:[`settings`],queryFn:Z.getSettings});return(0,y.useEffect)(()=>{let e=setInterval(()=>a(new Date),1e3);return()=>clearInterval(e)},[]),(0,G.jsxs)(`div`,{className:`h-12 bg-bambu-dark-secondary border-b border-bambu-dark-tertiary flex items-center px-3 gap-4 shrink-0`,children:[(0,G.jsx)(`div`,{className:`flex items-center shrink-0`,children:(0,G.jsx)(`img`,{src:`/img/spoolbuddy_logo_dark_small.png`,alt:`SpoolBuddy`,width:113,height:28,className:`h-7 w-auto`})}),(0,G.jsx)(`div`,{className:`flex-1 flex justify-center`,children:(0,G.jsx)(`select`,{value:e??``,onChange:e=>t(Number(e.target.value)),className:`bg-bambu-dark text-white text-base px-4 py-2 rounded border border-bambu-dark-tertiary focus:outline-none focus:border-bambu-green min-w-[180px]`,children:c.length===0?(0,G.jsx)(`option`,{value:``,children:r(`spoolbuddy.status.noPrinters`,`No printers online`)}):c.map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.name},e.id))})}),(0,G.jsxs)(`div`,{className:`flex items-center gap-3 shrink-0`,children:[(0,G.jsx)(`div`,{className:`flex items-center`,title:n?r(`spoolbuddy.status.backend`,`Backend`):r(`spoolbuddy.status.offline`,`Offline`),children:n?(0,G.jsx)(`div`,{className:`flex items-end gap-0.5 h-4`,children:[1,2,3,4].map(e=>(0,G.jsx)(`div`,{className:`w-1 rounded-sm ${e<=4?`bg-white`:`bg-bambu-dark-tertiary`}`,style:{height:`${e*4}px`}},e))}):(0,G.jsx)(Ju,{className:`w-5 h-5 text-red-400`})}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,G.jsx)(`div`,{className:`w-3 h-3 rounded-full ${n?`bg-bambu-green shadow-[0_0_6px_rgba(34,197,94,0.5)]`:`bg-bambu-gray`}`}),(0,G.jsx)(`span`,{className:`text-sm text-white/50`,children:n?r(`spoolbuddy.status.backend`,`Backend`):r(`spoolbuddy.status.offline`,`Offline`)})]}),(0,G.jsx)(`span`,{className:`text-white/50 text-base font-mono min-w-[50px] text-right`,children:Xf(i,l?.time_format||`system`)})]})]})}var p$e=[{to:`/spoolbuddy`,labelKey:`spoolbuddy.nav.dashboard`,fallback:`Dashboard`,icon:(0,G.jsx)(`svg`,{className:`w-6 h-6`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M3 12l2-2m0 0l7-7 7 7M5 10v10a1 1 0 001 1h3m10-11l2 2m-2-2v10a1 1 0 01-1 1h-3m-6 0a1 1 0 001-1v-4a1 1 0 011-1h2a1 1 0 011 1v4a1 1 0 001 1m-6 0h6`})})},{to:`/spoolbuddy/ams`,labelKey:`spoolbuddy.nav.ams`,fallback:`AMS`,icon:(0,G.jsx)(`svg`,{className:`w-6 h-6`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10`})})},{to:`/spoolbuddy/write-tag`,labelKey:`spoolbuddy.nav.writeTag`,fallback:`Write`,icon:(0,G.jsxs)(`svg`,{className:`w-6 h-6`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:2,children:[(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M8.288 15.038a5.25 5.25 0 017.424 0M5.106 11.856c3.807-3.808 9.98-3.808 13.788 0M1.924 8.674c5.565-5.565 14.587-5.565 20.152 0`}),(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M12.53 18.22l-.53.53-.53-.53a.75.75 0 011.06 0z`})]})},{to:`/spoolbuddy/inventory`,labelKey:`spoolbuddy.nav.inventory`,fallback:`Inventory`,icon:(0,G.jsx)(`svg`,{className:`w-6 h-6`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M20 7l-8-4-8 4m16 0l-8 4m8-4v10l-8 4m0-10L4 7m8 4v10M4 7v10l8 4`})})},{to:`/spoolbuddy/settings`,labelKey:`spoolbuddy.nav.settings`,fallback:`Settings`,icon:(0,G.jsxs)(`svg`,{className:`w-6 h-6`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:[(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.066 2.573c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.573 1.066c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.066-2.573c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z`}),(0,G.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M15 12a3 3 0 11-6 0 3 3 0 016 0z`})]})}];function m$e(){let{t:e}=U();return(0,G.jsx)(`nav`,{className:`h-14 bg-bambu-dark-secondary border-t border-bambu-dark-tertiary flex items-stretch shrink-0`,children:p$e.map(t=>(0,G.jsxs)(Ai,{to:t.to,end:t.to===`/spoolbuddy`,className:({isActive:e})=>`flex-1 flex flex-col items-center justify-center gap-1 transition-colors ${e?`text-bambu-green bg-bambu-dark`:`text-white/50 hover:text-white/70 hover:bg-bambu-dark-tertiary`}`,children:[t.icon,(0,G.jsx)(`span`,{className:`text-xs font-medium`,children:e(t.labelKey,t.fallback)})]},t.to))})}function h$e({alert:e}){let{t}=U(),n=e?e.type===`error`?`bg-red-500`:e.type===`warning`?`bg-amber-500`:`bg-bambu-green`:`bg-bambu-green`;return(0,G.jsxs)(`div`,{className:`h-9 bg-bambu-dark-secondary border-t-2 ${e?e.type===`error`?`border-red-500`:e.type===`warning`?`border-amber-500`:`border-bambu-dark-tertiary`:`border-bambu-dark-tertiary`} flex items-center px-3 gap-3 shrink-0`,children:[(0,G.jsx)(`div`,{className:`w-3.5 h-3.5 rounded-full ${n}`}),(0,G.jsx)(`div`,{className:`flex-1 text-sm text-white/50 truncate`,children:e?(0,G.jsx)(`span`,{children:e.message}):(0,G.jsx)(`span`,{className:`text-bambu-green`,children:t(`spoolbuddy.status.systemReady`,`System Ready`)})})]})}function g$e({isOpen:e,onClose:t,deviceId:n,deviceOnline:r}){let{t:i}=U(),[a,o]=(0,y.useState)(null),[s,c]=(0,y.useState)(!1),[l,u]=(0,y.useState)(new Map),{data:d=[]}=K({queryKey:[`printers`],queryFn:()=>Z.getPrinters(),enabled:e}),{data:f=[]}=K({queryKey:[`smart-plugs`],queryFn:()=>Z.getSmartPlugs(),enabled:e}),p=d.map(e=>{let t=f.find(t=>t.printer_id===e.id&&t.plug_type!==`mqtt`&&t.enabled);if(!t)return null;let n=l.get(t.id);return{plug:t,printer:e,status:n?{state:n.state,reachable:!0,device_name:null,energy:null}:null,loading:n?.loading??!1}}).filter(Boolean);(0,y.useEffect)(()=>{!e||f.length===0||f.filter(e=>e.printer_id!==null&&e.plug_type!==`mqtt`&&e.enabled).forEach(async e=>{try{let t=await Z.getSmartPlugStatus(e.id);u(n=>{let r=new Map(n);return r.set(e.id,{loading:!1,state:t.state}),r})}catch{u(t=>{let n=new Map(t);return n.set(e.id,{loading:!1,state:null}),n})}})},[e,f]),(0,y.useEffect)(()=>{e||(o(null),c(!1))},[e]);let m=(0,y.useCallback)(async e=>{u(t=>{let n=new Map(t),r=n.get(e.id);return n.set(e.id,{loading:!0,state:r?.state??null}),n});try{await Z.controlSmartPlug(e.id,`toggle`);let t=await Z.getSmartPlugStatus(e.id);u(n=>{let r=new Map(n);return r.set(e.id,{loading:!1,state:t.state}),r})}catch{u(t=>{let n=new Map(t),r=n.get(e.id);return n.set(e.id,{loading:!1,state:r?.state??null}),n})}},[]),h=(0,y.useCallback)(async e=>{if(n){c(!0);try{await xd.systemCommand(n,e),setTimeout(()=>t(),500)}catch{c(!1)}}},[n,t]),g=(0,y.useCallback)(()=>{a&&(a.type===`system`?h(a.command):m(a.plug),o(null))},[a,h,m]);if(!e)return null;let _=e=>e===`ON`||e===`on`;return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`fixed inset-0 z-40 bg-black/50`,onPointerDown:t}),(0,G.jsxs)(`div`,{className:`fixed top-0 left-0 right-0 z-50 bg-bambu-dark-secondary border-b border-bambu-dark-tertiary rounded-b-2xl shadow-2xl animate-slide-down`,children:[(0,G.jsx)(`div`,{className:`flex justify-center pt-2 pb-1`,children:(0,G.jsx)(`div`,{className:`w-10 h-1 rounded-full bg-zinc-600`})}),(0,G.jsxs)(`div`,{className:`px-4 pb-4 max-h-[80vh] overflow-y-auto`,children:[p.length>0&&(0,G.jsxs)(`div`,{className:`mb-4`,children:[(0,G.jsx)(`h3`,{className:`text-xs font-semibold text-zinc-500 uppercase tracking-wide mb-2`,children:i(`spoolbuddy.quickMenu.printerPower`,`Printer Power`)}),(0,G.jsx)(`div`,{className:`space-y-1`,children:p.map(({plug:e,printer:t,loading:n})=>{let r=l.get(e.id),i=_(r?.state??null);return(0,G.jsxs)(`button`,{onClick:()=>o({type:`plug`,plug:e,printer:t,currentState:r?.state??null}),disabled:n,className:`w-full flex items-center gap-2 px-3 py-1.5 rounded-lg bg-zinc-800/60 hover:bg-zinc-700/60 transition-colors min-h-[36px]`,children:[(0,G.jsx)(`div`,{className:`w-2 h-2 rounded-full shrink-0 ${i?`bg-green-500`:`bg-zinc-600`}`}),n&&(0,G.jsx)(Y,{className:`w-3 h-3 animate-spin text-zinc-400 shrink-0`}),(0,G.jsx)(`span`,{className:`flex-1 text-sm text-zinc-200 text-left truncate`,children:t.name}),(0,G.jsx)(`span`,{className:`text-xs font-medium ${i?`text-green-400`:`text-zinc-500`}`,children:r?.state??`—`})]},e.id)})})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`text-xs font-semibold text-zinc-500 uppercase tracking-wide mb-2`,children:i(`spoolbuddy.quickMenu.systemControls`,`System`)}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,G.jsx)(H9,{icon:(0,G.jsx)(Hl,{className:`w-4 h-4`}),label:i(`spoolbuddy.quickMenu.restartDaemon`,`Restart Daemon`),onClick:()=>o({type:`system`,command:`restart_daemon`}),disabled:!n||!r||s}),(0,G.jsx)(H9,{icon:(0,G.jsx)(ml,{className:`w-4 h-4`}),label:i(`spoolbuddy.quickMenu.restartBrowser`,`Restart Browser`),onClick:()=>o({type:`system`,command:`restart_browser`}),disabled:!n||!r||s}),(0,G.jsx)(H9,{icon:(0,G.jsx)(Hl,{className:`w-4 h-4`}),label:i(`spoolbuddy.quickMenu.reboot`,`Reboot`),onClick:()=>o({type:`system`,command:`reboot`}),disabled:!n||!r||s,variant:`warning`}),(0,G.jsx)(H9,{icon:(0,G.jsx)(Nl,{className:`w-4 h-4`}),label:i(`spoolbuddy.quickMenu.shutdown`,`Shutdown`),onClick:()=>o({type:`system`,command:`shutdown`}),disabled:!n||!r||s,variant:`danger`})]})]}),(0,G.jsx)(`div`,{className:`flex justify-center mt-3`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-1 text-xs text-zinc-600`,children:[(0,G.jsx)(ds,{className:`w-3 h-3`}),(0,G.jsx)(`span`,{children:i(`spoolbuddy.quickMenu.swipeToClose`,`Swipe down to close`)})]})})]})]}),a&&(0,G.jsx)(`div`,{className:`fixed inset-0 z-[60] flex items-center justify-center bg-black/60`,children:(0,G.jsxs)(`div`,{className:`bg-zinc-800 rounded-2xl p-5 mx-4 max-w-sm w-full border border-zinc-700`,children:[(0,G.jsx)(`h3`,{className:`text-lg font-semibold text-zinc-100 mb-2`,children:i(`spoolbuddy.quickMenu.confirmTitle`,`Confirm`)}),(0,G.jsx)(`p`,{className:`text-sm text-zinc-400 mb-5`,children:a.type===`plug`?_(a.currentState)?i(`spoolbuddy.quickMenu.confirmPlugOff`,`Turn off {{name}}?`,{name:a.printer.name}):i(`spoolbuddy.quickMenu.confirmPlugOn`,`Turn on {{name}}?`,{name:a.printer.name}):a.command===`shutdown`?i(`spoolbuddy.quickMenu.confirmShutdown`,`Are you sure you want to shut down the SpoolBuddy? You will need physical access to turn it back on.`):a.command===`reboot`?i(`spoolbuddy.quickMenu.confirmReboot`,`Are you sure you want to reboot the SpoolBuddy?`):a.command===`restart_daemon`?i(`spoolbuddy.quickMenu.confirmRestartDaemon`,`Restart the SpoolBuddy daemon? NFC and scale will be temporarily unavailable.`):i(`spoolbuddy.quickMenu.confirmRestartBrowser`,`Restart the kiosk browser? The display will briefly go blank.`)}),(0,G.jsxs)(`div`,{className:`flex gap-3`,children:[(0,G.jsx)(`button`,{onClick:()=>o(null),className:`flex-1 px-4 py-2.5 rounded-lg text-sm font-medium bg-zinc-700 text-zinc-300 hover:bg-zinc-600 transition-colors min-h-[44px]`,children:i(`common.cancel`,`Cancel`)}),(0,G.jsx)(`button`,{onClick:g,disabled:s,className:`flex-1 px-4 py-2.5 rounded-lg text-sm font-medium text-white transition-colors min-h-[44px] ${a.type===`plug`?_(a.currentState)?`bg-red-600 hover:bg-red-700`:`bg-green-600 hover:bg-green-700`:a.command===`shutdown`?`bg-red-600 hover:bg-red-700`:a.command===`reboot`?`bg-amber-600 hover:bg-amber-700`:`bg-blue-600 hover:bg-blue-700`} disabled:opacity-50`,children:s?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin mx-auto`}):a.type===`plug`?_(a.currentState)?i(`spoolbuddy.quickMenu.turnOff`,`Turn Off`):i(`spoolbuddy.quickMenu.turnOn`,`Turn On`):i(`spoolbuddy.quickMenu.confirm`,`Confirm`)})]})]})})]})}function H9({icon:e,label:t,onClick:n,disabled:r,variant:i=`default`}){return(0,G.jsxs)(`button`,{onClick:n,disabled:r,className:`flex items-center gap-2.5 p-3 rounded-xl transition-colors min-h-[48px] disabled:opacity-40 ${{default:`bg-zinc-800/60 hover:bg-zinc-700/60 text-zinc-300`,warning:`bg-amber-900/30 hover:bg-amber-900/50 text-amber-400`,danger:`bg-red-900/30 hover:bg-red-900/50 text-red-400`}[i]}`,children:[e,(0,G.jsx)(`span`,{className:`text-sm font-medium`,children:t})]})}var _$e={weight:null,weightStable:!1,rawAdc:null,matchedSpool:null,unknownTagUid:null,unknownTrayUuid:null,deviceOnline:!1,deviceId:null};function v$e(e,t){switch(t.type){case`WEIGHT_UPDATE`:return{...e,weight:t.weight,weightStable:t.stable,rawAdc:t.rawAdc,deviceId:t.deviceId,deviceOnline:!0};case`TAG_MATCHED`:return{...e,matchedSpool:t.spool,unknownTagUid:null,unknownTrayUuid:null,deviceId:t.deviceId};case`UNKNOWN_TAG`:return{...e,matchedSpool:null,unknownTagUid:t.tagUid,unknownTrayUuid:t.trayUuid??null,deviceId:t.deviceId};case`TAG_REMOVED`:return{...e,matchedSpool:null,unknownTagUid:null,unknownTrayUuid:null};case`DEVICE_ONLINE`:return{...e,deviceOnline:!0,deviceId:t.deviceId};case`DEVICE_OFFLINE`:return{...e,deviceOnline:!1,weight:null,weightStable:!1,rawAdc:null};default:return e}}function y$e(){let[e,t]=(0,y.useReducer)(v$e,_$e),n=(0,y.useCallback)(e=>{let n=e.detail;t({type:`WEIGHT_UPDATE`,weight:n.weight_grams??n.data?.weight_grams,stable:n.stable??n.data?.stable??!1,rawAdc:n.raw_adc??n.data?.raw_adc??null,deviceId:n.device_id??n.data?.device_id??``})},[]),r=(0,y.useCallback)(e=>{let n=e.detail,r=n.spool??n.data?.spool;r&&t({type:`TAG_MATCHED`,spool:{id:r.id,tag_uid:n.tag_uid??n.data?.tag_uid??``,material:r.material??``,subtype:r.subtype??null,color_name:r.color_name??null,rgba:r.rgba??null,brand:r.brand??null,label_weight:r.label_weight??0,core_weight:r.core_weight??0,weight_used:r.weight_used??0},deviceId:n.device_id??n.data?.device_id??``})},[]),i=(0,y.useCallback)(e=>{let n=e.detail;t({type:`UNKNOWN_TAG`,tagUid:n.tag_uid??n.data?.tag_uid??``,trayUuid:n.tray_uuid??n.data?.tray_uuid??null,deviceId:n.device_id??n.data?.device_id??``})},[]),a=(0,y.useCallback)(e=>{let n=e.detail;t({type:`TAG_REMOVED`,deviceId:n.device_id??n.data?.device_id??``})},[]),o=(0,y.useCallback)(e=>{let n=e.detail;t({type:`DEVICE_ONLINE`,deviceId:n.device_id??n.data?.device_id??``})},[]),s=(0,y.useCallback)(e=>{let n=e.detail;t({type:`DEVICE_OFFLINE`,deviceId:n.device_id??n.data?.device_id??``})},[]);(0,y.useEffect)(()=>(window.addEventListener(`spoolbuddy-weight`,n),window.addEventListener(`spoolbuddy-tag-matched`,r),window.addEventListener(`spoolbuddy-unknown-tag`,i),window.addEventListener(`spoolbuddy-tag-removed`,a),window.addEventListener(`spoolbuddy-online`,o),window.addEventListener(`spoolbuddy-offline`,s),()=>{window.removeEventListener(`spoolbuddy-weight`,n),window.removeEventListener(`spoolbuddy-tag-matched`,r),window.removeEventListener(`spoolbuddy-unknown-tag`,i),window.removeEventListener(`spoolbuddy-tag-removed`,a),window.removeEventListener(`spoolbuddy-online`,o),window.removeEventListener(`spoolbuddy-offline`,s)}),[n,r,i,a,o,s]);let c=e.matchedSpool?Math.max(0,e.matchedSpool.label_weight-e.matchedSpool.weight_used):null,l=e.weight!==null&&e.matchedSpool?Math.max(0,e.weight-e.matchedSpool.core_weight):null;return{...e,remainingWeight:c,netWeight:l}}var b$e=l(o(((e,t)=>{(function(n,r){typeof e==`object`&&typeof t==`object`?t.exports=r(f()):typeof define==`function`&&define.amd?define([`react`],r):typeof e==`object`?e.ReactSimpleKeyboard=r(f()):n.ReactSimpleKeyboard=r(n.React)})(e,(function(e){return function(){var t={981:function(){typeof Element>`u`||`remove`in Element.prototype||(Element.prototype.remove=function(){this.parentNode&&this.parentNode.removeChild(this)}),typeof self<`u`&&`document`in self&&((!(`classList`in document.createElement(`_`))||document.createElementNS&&!(`classList`in document.createElementNS(`http://www.w3.org/2000/svg`,`g`)))&&function(e){if(`Element`in e){var t=`classList`,n=`prototype`,r=e.Element[n],i=Object,a=String[n].trim||function(){return this.replace(/^\s+|\s+$/g,``)},o=Array[n].indexOf||function(e){for(var t=0,n=this.length;t1?arguments[1]:void 0)}},7916:function(e,t,n){var r=n(6080),i=n(9565),a=n(8981),o=n(6319),s=n(4209),c=n(3517),l=n(6198),u=n(4659),d=n(4527),f=n(81),p=n(851),m=Array;e.exports=function(e){var t=a(e),n=c(this),h=arguments.length,g=h>1?arguments[1]:void 0,_=g!==void 0;_&&(g=r(g,h>2?arguments[2]:void 0));var v,y,b,x,S,C,w=p(t),T=0;if(!w||this===m&&s(w))for(v=l(t),y=n?new this(v):m(v);v>T;T++)C=_?g(t[T],T):t[T],u(y,T,C);else for(y=n?new this:[],S=(x=f(t,w)).next;!(b=i(S,x)).done;T++)C=_?o(x,g,[b.value,T],!0):b.value,u(y,T,C);return d(y,T),y}},9617:function(e,t,n){var r=n(5397),i=n(5610),a=n(6198),o=function(e){return function(t,n,o){var s=r(t),c=a(s);if(c===0)return!e&&-1;var l,u=i(o,c);if(e&&n!=n){for(;c>u;)if((l=s[u++])!=l)return!0}else for(;c>u;u++)if((e||u in s)&&s[u]===n)return e||u||0;return!e&&-1}};e.exports={includes:o(!0),indexOf:o(!1)}},9213:function(e,t,n){var r=n(6080),i=n(7055),a=n(8981),o=n(6198),s=n(1469),c=n(4659),l=function(e){var t=e===1,n=e===2,l=e===3,u=e===4,d=e===6,f=e===7,p=e===5||d;return function(m,h,g){for(var _,v,y=a(m),b=i(y),x=o(b),S=r(h,g),C=0,w=0,T=t?s(m,x):n||f?s(m,0):void 0;x>C;C++)if((p||C in b)&&(v=S(_=b[C],C,y),e))if(t)c(T,C,v);else if(v)switch(e){case 3:return!0;case 5:return _;case 6:return C;case 2:c(T,w++,_)}else switch(e){case 4:return!1;case 7:c(T,w++,_)}return d?-1:l||u?u:T}};e.exports={forEach:l(0),map:l(1),filter:l(2),some:l(3),every:l(4),find:l(5),findIndex:l(6),filterReject:l(7)}},597:function(e,t,n){var r=n(9039),i=n(8227),a=n(9519),o=i(`species`);e.exports=function(e){return a>=51||!r((function(){var t=[];return(t.constructor={})[o]=function(){return{foo:1}},t[e](Boolean).foo!==1}))}},4598:function(e,t,n){var r=n(9039);e.exports=function(e,t){var n=[][e];return!!n&&r((function(){n.call(null,t||function(){return 1},1)}))}},926:function(e,t,n){var r=n(9306),i=n(8981),a=n(7055),o=n(6198),s=TypeError,c=`Reduce of empty array with no initial value`,l=function(e){return function(t,n,l,u){var d=i(t),f=a(d),p=o(d);if(r(n),p===0&&l<2)throw new s(c);var m=e?p-1:0,h=e?-1:1;if(l<2)for(;;){if(m in f){u=f[m],m+=h;break}if(m+=h,e?m<0:p<=m)throw new s(c)}for(;e?m>=0:p>m;m+=h)m in f&&(u=n(u,f[m],m,d));return u}};e.exports={left:l(!1),right:l(!0)}},4527:function(e,t,n){var r=n(3724),i=n(4376),a=TypeError,o=Object.getOwnPropertyDescriptor;e.exports=r&&!function(){if(this!==void 0)return!0;try{Object.defineProperty([],"length",{writable:!1}).length=1}catch(e){return e instanceof TypeError}}()?function(e,t){if(i(e)&&!o(e,`length`).writable)throw new a(`Cannot set read only .length`);return e.length=t}:function(e,t){return e.length=t}},7680:function(e,t,n){e.exports=n(9504)([].slice)},4488:function(e,t,n){var r=n(7680),i=Math.floor,a=function(e,t){var n=e.length;if(n<8)for(var o,s,c=1;c0;)e[s]=e[--s];s!==c++&&(e[s]=o)}else for(var l=i(n/2),u=a(r(e,0,l),t),d=a(r(e,l),t),f=u.length,p=d.length,m=0,h=0;m9007199254740991)throw t(`Maximum allowed index exceeded`);return e}},7400:function(e){e.exports={CSSRuleList:0,CSSStyleDeclaration:0,CSSValueList:0,ClientRectList:0,DOMRectList:0,DOMStringList:0,DOMTokenList:1,DataTransferItemList:0,FileList:0,HTMLAllCollection:0,HTMLCollection:0,HTMLFormElement:0,HTMLSelectElement:0,MediaList:0,MimeTypeArray:0,NamedNodeMap:0,NodeList:1,PaintRequestList:0,Plugin:0,PluginArray:0,SVGLengthList:0,SVGNumberList:0,SVGPathSegList:0,SVGPointList:0,SVGStringList:0,SVGTransformList:0,SourceBufferList:0,StyleSheetList:0,TextTrackCueList:0,TextTrackList:0,TouchList:0}},9296:function(e,t,n){var r=n(4055)(`span`).classList,i=r&&r.constructor&&r.constructor.prototype;e.exports=i===Object.prototype?void 0:i},8727:function(e){e.exports=[`constructor`,`hasOwnProperty`,`isPrototypeOf`,`propertyIsEnumerable`,`toLocaleString`,`toString`,`valueOf`]},3709:function(e,t,n){var r=n(2839).match(/firefox\/(\d+)/i);e.exports=!!r&&+r[1]},3763:function(e,t,n){var r=n(2839);e.exports=/MSIE|Trident/.test(r)},6193:function(e,t,n){e.exports=n(4215)===`NODE`},2839:function(e,t,n){var r=n(4576).navigator,i=r&&r.userAgent;e.exports=i?String(i):``},9519:function(e,t,n){var r,i,a=n(4576),o=n(2839),s=a.process,c=a.Deno,l=s&&s.versions||c&&c.version,u=l&&l.v8;u&&(i=(r=u.split(`.`))[0]>0&&r[0]<4?1:+(r[0]+r[1])),!i&&o&&(!(r=o.match(/Edge\/(\d+)/))||r[1]>=74)&&(r=o.match(/Chrome\/(\d+)/))&&(i=+r[1]),e.exports=i},3607:function(e,t,n){var r=n(2839).match(/AppleWebKit\/(\d+)\./);e.exports=!!r&&+r[1]},4215:function(e,t,n){var r=n(4576),i=n(2839),a=n(2195),o=function(e){return i.slice(0,e.length)===e};e.exports=o(`Bun/`)?`BUN`:o(`Cloudflare-Workers`)?`CLOUDFLARE`:o(`Deno/`)?`DENO`:o(`Node.js/`)?`NODE`:r.Bun&&typeof Bun.version==`string`?`BUN`:r.Deno&&typeof Deno.version==`object`?`DENO`:a(r.process)===`process`?`NODE`:r.window&&r.document?`BROWSER`:`REST`},6518:function(e,t,n){var r=n(4576),i=n(7347).f,a=n(6699),o=n(6840),s=n(9433),c=n(7740),l=n(2796);e.exports=function(e,t){var n,u,d,f,p,m=e.target,h=e.global,g=e.stat;if(n=h?r:g?r[m]||s(m,{}):r[m]&&r[m].prototype)for(u in t){if(f=t[u],d=e.dontCallGetSet?(p=i(n,u))&&p.value:n[u],!l(h?u:m+(g?`.`:`#`)+u,e.forced)&&d!==void 0){if(typeof f==typeof d)continue;c(f,d)}(e.sham||d&&d.sham)&&a(f,`sham`,!0),o(n,u,f,e)}}},9039:function(e){e.exports=function(e){try{return!!e()}catch{return!0}}},9228:function(e,t,n){n(7495);var r=n(9565),i=n(6840),a=n(7323),o=n(9039),s=n(8227),c=n(6699),l=s(`species`),u=RegExp.prototype;e.exports=function(e,t,n,d){var f=s(e),p=!o((function(){var t={};return t[f]=function(){return 7},``[e](t)!==7})),m=p&&!o((function(){var t=!1,n=/a/;if(e===`split`){var r={};r[l]=function(){return n},(n={constructor:r,flags:``})[f]=/./[f]}return n.exec=function(){return t=!0,null},n[f](``),!t}));if(!p||!m||n){var h=/./[f],g=t(f,``[e],(function(e,t,n,i,o){var s=t.exec;return s===a||s===u.exec?p&&!o?{done:!0,value:r(h,t,n,i)}:{done:!0,value:r(e,n,t,i)}:{done:!1}}));i(String.prototype,e,g[0]),i(u,f,g[1])}d&&c(u[f],`sham`,!0)}},8745:function(e,t,n){var r=n(616),i=Function.prototype,a=i.apply,o=i.call;e.exports=typeof Reflect==`object`&&Reflect.apply||(r?o.bind(a):function(){return o.apply(a,arguments)})},6080:function(e,t,n){var r=n(7476),i=n(9306),a=n(616),o=r(r.bind);e.exports=function(e,t){return i(e),t===void 0?e:a?o(e,t):function(){return e.apply(t,arguments)}}},616:function(e,t,n){e.exports=!n(9039)((function(){var e=function(){}.bind();return typeof e!=`function`||e.hasOwnProperty(`prototype`)}))},566:function(e,t,n){var r=n(9504),i=n(9306),a=n(34),o=n(9297),s=n(7680),c=n(616),l=Function,u=r([].concat),d=r([].join),f={};e.exports=c?l.bind:function(e){var t=i(this),n=t.prototype,r=s(arguments,1),c=function(){var n=u(r,s(arguments));return this instanceof c?function(e,t,n){if(!o(f,t)){for(var r=[],i=0;i]*>)/g,u=/\$([$&'`]|\d{1,2})/g;e.exports=function(e,t,n,r,d,f){var p=n+e.length,m=r.length,h=u;return d!==void 0&&(d=i(d),h=l),s(f,h,(function(i,s){var l;switch(o(s,0)){case`$`:return`$`;case`&`:return e;case"`":return c(t,0,n);case`'`:return c(t,p);case`<`:l=d[c(s,1,-1)];break;default:var u=+s;if(u===0)return i;if(u>m){var f=a(u/10);return f===0?i:f<=m?r[f-1]===void 0?o(s,1):r[f-1]+o(s,1):i}l=r[u-1]}return l===void 0?``:l}))}},4576:function(e,t,n){var r=function(e){return e&&e.Math===Math&&e};e.exports=r(typeof globalThis==`object`&&globalThis)||r(typeof window==`object`&&window)||r(typeof self==`object`&&self)||r(typeof n.g==`object`&&n.g)||r(typeof this==`object`&&this)||function(){return this}()||Function(`return this`)()},9297:function(e,t,n){var r=n(9504),i=n(8981),a=r({}.hasOwnProperty);e.exports=Object.hasOwn||function(e,t){return a(i(e),t)}},421:function(e){e.exports={}},397:function(e,t,n){e.exports=n(7751)(`document`,`documentElement`)},5917:function(e,t,n){var r=n(3724),i=n(9039),a=n(4055);e.exports=!r&&!i((function(){return Object.defineProperty(a(`div`),"a",{get:function(){return 7}}).a!==7}))},7055:function(e,t,n){var r=n(9504),i=n(9039),a=n(2195),o=Object,s=r(``.split);e.exports=i((function(){return!o(`z`).propertyIsEnumerable(0)}))?function(e){return a(e)===`String`?s(e,``):o(e)}:o},3167:function(e,t,n){var r=n(4901),i=n(34),a=n(2967);e.exports=function(e,t,n){var o,s;return a&&r(o=t.constructor)&&o!==n&&i(s=o.prototype)&&s!==n.prototype&&a(e,s),e}},3706:function(e,t,n){var r=n(9504),i=n(4901),a=n(7629),o=r(Function.toString);i(a.inspectSource)||(a.inspectSource=function(e){return o(e)}),e.exports=a.inspectSource},1181:function(e,t,n){var r,i,a,o=n(8622),s=n(4576),c=n(34),l=n(6699),u=n(9297),d=n(7629),f=n(6119),p=n(421),m=`Object already initialized`,h=s.TypeError,g=s.WeakMap;if(o||d.state){var _=d.state||=new g;_.get=_.get,_.has=_.has,_.set=_.set,r=function(e,t){if(_.has(e))throw new h(m);return t.facade=e,_.set(e,t),t},i=function(e){return _.get(e)||{}},a=function(e){return _.has(e)}}else{var v=f(`state`);p[v]=!0,r=function(e,t){if(u(e,v))throw new h(m);return t.facade=e,l(e,v,t),t},i=function(e){return u(e,v)?e[v]:{}},a=function(e){return u(e,v)}}e.exports={set:r,get:i,has:a,enforce:function(e){return a(e)?i(e):r(e,{})},getterFor:function(e){return function(t){var n;if(!c(t)||(n=i(t)).type!==e)throw new h(`Incompatible receiver, `+e+` required`);return n}}}},4209:function(e,t,n){var r=n(8227),i=n(6269),a=r(`iterator`),o=Array.prototype;e.exports=function(e){return e!==void 0&&(i.Array===e||o[a]===e)}},4376:function(e,t,n){var r=n(2195);e.exports=Array.isArray||function(e){return r(e)===`Array`}},4901:function(e){var t=typeof document==`object`&&document.all;e.exports=t===void 0&&t!==void 0?function(e){return typeof e==`function`||e===t}:function(e){return typeof e==`function`}},3517:function(e,t,n){var r=n(9504),i=n(9039),a=n(4901),o=n(6955),s=n(7751),c=n(3706),l=function(){},u=s(`Reflect`,`construct`),d=/^\s*(?:class|function)\b/,f=r(d.exec),p=!d.test(l),m=function(e){if(!a(e))return!1;try{return u(l,[],e),!0}catch{return!1}},h=function(e){if(!a(e))return!1;switch(o(e)){case`AsyncFunction`:case`GeneratorFunction`:case`AsyncGeneratorFunction`:return!1}try{return p||!!f(d,c(e))}catch{return!0}};h.sham=!0,e.exports=!u||i((function(){var e;return m(m.call)||!m(Object)||!m((function(){e=!0}))||e}))?h:m},2796:function(e,t,n){var r=n(9039),i=n(4901),a=/#|\.prototype\./,o=function(e,t){var n=c[s(e)];return n===u||n!==l&&(i(t)?r(t):!!t)},s=o.normalize=function(e){return String(e).replace(a,`.`).toLowerCase()},c=o.data={},l=o.NATIVE=`N`,u=o.POLYFILL=`P`;e.exports=o},2087:function(e,t,n){var r=n(34),i=Math.floor;e.exports=Number.isInteger||function(e){return!r(e)&&isFinite(e)&&i(e)===e}},4117:function(e){e.exports=function(e){return e==null}},34:function(e,t,n){var r=n(4901);e.exports=function(e){return typeof e==`object`?e!==null:r(e)}},3925:function(e,t,n){var r=n(34);e.exports=function(e){return r(e)||e===null}},6395:function(e){e.exports=!1},5810:function(e,t,n){var r=n(34),i=n(1181).get;e.exports=function(e){if(!r(e))return!1;var t=i(e);return!!t&&t.type===`RawJSON`}},788:function(e,t,n){var r=n(34),i=n(2195),a=n(8227)(`match`);e.exports=function(e){var t;return r(e)&&((t=e[a])===void 0?i(e)===`RegExp`:!!t)}},757:function(e,t,n){var r=n(7751),i=n(4901),a=n(1625),o=n(7040),s=Object;e.exports=o?function(e){return typeof e==`symbol`}:function(e){var t=r(`Symbol`);return i(t)&&a(t.prototype,s(e))}},9539:function(e,t,n){var r=n(9565),i=n(8551),a=n(5966);e.exports=function(e,t,n){var o,s;i(e);try{if(!(o=a(e,`return`))){if(t===`throw`)throw n;return n}o=r(o,e)}catch(e){s=!0,o=e}if(t===`throw`)throw n;if(s)throw o;return i(o),n}},3994:function(e,t,n){var r=n(7657).IteratorPrototype,i=n(2360),a=n(6980),o=n(687),s=n(6269),c=function(){return this};e.exports=function(e,t,n,l){var u=t+` Iterator`;return e.prototype=i(r,{next:a(+!l,n)}),o(e,u,!1,!0),s[u]=c,e}},1088:function(e,t,n){var r=n(6518),i=n(9565),a=n(6395),o=n(350),s=n(4901),c=n(3994),l=n(2787),u=n(2967),d=n(687),f=n(6699),p=n(6840),m=n(8227),h=n(6269),g=n(7657),_=o.PROPER,v=o.CONFIGURABLE,y=g.IteratorPrototype,b=g.BUGGY_SAFARI_ITERATORS,x=m(`iterator`),S=`keys`,C=`values`,w=`entries`,T=function(){return this};e.exports=function(e,t,n,o,m,g,E){c(n,t,o);var D,O,k,A=function(e){if(e===m&&F)return F;if(!b&&e&&e in N)return N[e];switch(e){case S:case C:case w:return function(){return new n(this,e)}}return function(){return new n(this)}},j=t+` Iterator`,M=!1,N=e.prototype,P=N[x]||N[`@@iterator`]||m&&N[m],F=!b&&P||A(m),I=t===`Array`&&N.entries||P;if(I&&(D=l(I.call(new e)))!==Object.prototype&&D.next&&(a||l(D)===y||(u?u(D,y):s(D[x])||p(D,x,T)),d(D,j,!0,!0),a&&(h[j]=T)),_&&m===C&&P&&P.name!==C&&(!a&&v?f(N,`name`,C):(M=!0,F=function(){return i(P,this)})),m)if(O={values:A(C),keys:g?F:A(S),entries:A(w)},E)for(k in O)(b||M||!(k in N))&&p(N,k,O[k]);else r({target:t,proto:!0,forced:b||M},O);return a&&!E||N[x]===F||p(N,x,F,{name:m}),h[t]=F,O}},7657:function(e,t,n){var r,i,a,o=n(9039),s=n(4901),c=n(34),l=n(2360),u=n(2787),d=n(6840),f=n(8227),p=n(6395),m=f(`iterator`),h=!1;[].keys&&(`next`in(a=[].keys())?(i=u(u(a)))!==Object.prototype&&(r=i):h=!0),!c(r)||o((function(){var e={};return r[m].call(e)!==e}))?r={}:p&&(r=l(r)),s(r[m])||d(r,m,(function(){return this})),e.exports={IteratorPrototype:r,BUGGY_SAFARI_ITERATORS:h}},6269:function(e){e.exports={}},6198:function(e,t,n){var r=n(8014);e.exports=function(e){return r(e.length)}},283:function(e,t,n){var r=n(9504),i=n(9039),a=n(4901),o=n(9297),s=n(3724),c=n(350).CONFIGURABLE,l=n(3706),u=n(1181),d=u.enforce,f=u.get,p=String,m=Object.defineProperty,h=r(``.slice),g=r(``.replace),_=r([].join),v=s&&!i((function(){return m((function(){}),`length`,{value:8}).length!==8})),y=String(String).split(`String`),b=e.exports=function(e,t,n){h(p(t),0,7)===`Symbol(`&&(t=`[`+g(p(t),/^Symbol\(([^)]*)\).*$/,`$1`)+`]`),n&&n.getter&&(t=`get `+t),n&&n.setter&&(t=`set `+t),(!o(e,`name`)||c&&e.name!==t)&&(s?m(e,`name`,{value:t,configurable:!0}):e.name=t),v&&n&&o(n,`arity`)&&e.length!==n.arity&&m(e,`length`,{value:n.arity});try{n&&o(n,`constructor`)&&n.constructor?s&&m(e,`prototype`,{writable:!1}):e.prototype&&=void 0}catch{}var r=d(e);return o(r,`source`)||(r.source=_(y,typeof t==`string`?t:``)),e};Function.prototype.toString=b((function(){return a(this)&&f(this).source||l(this)}),`toString`)},741:function(e){var t=Math.ceil,n=Math.floor;e.exports=Math.trunc||function(e){var r=+e;return(r>0?n:t)(r)}},7819:function(e,t,n){e.exports=!n(9039)((function(){var e=`9007199254740993`,t=JSON.rawJSON(e);return!JSON.isRawJSON(t)||JSON.stringify(t)!==e}))},5749:function(e,t,n){var r=n(788),i=TypeError;e.exports=function(e){if(r(e))throw new i(`The method doesn't accept regular expressions`);return e}},4213:function(e,t,n){var r=n(3724),i=n(9504),a=n(9565),o=n(9039),s=n(1072),c=n(3717),l=n(8773),u=n(8981),d=n(7055),f=Object.assign,p=Object.defineProperty,m=i([].concat);e.exports=!f||o((function(){if(r&&f({b:1},f(p({},`a`,{enumerable:!0,get:function(){p(this,`b`,{value:3,enumerable:!1})}}),{b:2})).b!==1)return!0;var e={},t={},n=Symbol(`assign detection`),i=`abcdefghijklmnopqrst`;return e[n]=7,i.split(``).forEach((function(e){t[e]=e})),f({},e)[n]!==7||s(f({},t)).join(``)!==i}))?function(e,t){for(var n=u(e),i=arguments.length,o=1,f=c.f,p=l.f;i>o;)for(var h,g=d(arguments[o++]),_=f?m(s(g),f(g)):s(g),v=_.length,y=0;v>y;)h=_[y++],r&&!a(p,g,h)||(n[h]=g[h]);return n}:f},2360:function(e,t,n){var r,i=n(8551),a=n(6801),o=n(8727),s=n(421),c=n(397),l=n(4055),u=n(6119),d=`prototype`,f=`script`,p=u(`IE_PROTO`),m=function(){},h=function(e){return`<`+f+`>`+e+``+f+`>`},g=function(e){e.write(h(``)),e.close();var t=e.parentWindow.Object;return e=null,t},_=function(){try{r=new ActiveXObject(`htmlfile`)}catch{}var e,t,n;_=typeof document<`u`?document.domain&&r?g(r):(t=l(`iframe`),n=`java`+f+`:`,t.style.display=`none`,c.appendChild(t),t.src=String(n),(e=t.contentWindow.document).open(),e.write(h(`document.F=Object`)),e.close(),e.F):g(r);for(var i=o.length;i--;)delete _[d][o[i]];return _()};s[p]=!0,e.exports=Object.create||function(e,t){var n;return e===null?n=_():(m[d]=i(e),n=new m,m[d]=null,n[p]=e),t===void 0?n:a.f(n,t)}},6801:function(e,t,n){var r=n(3724),i=n(8686),a=n(4913),o=n(8551),s=n(5397),c=n(1072);t.f=r&&!i?Object.defineProperties:function(e,t){o(e);for(var n,r=s(t),i=c(t),l=i.length,u=0;l>u;)a.f(e,n=i[u++],r[n]);return e}},4913:function(e,t,n){var r=n(3724),i=n(5917),a=n(8686),o=n(8551),s=n(6969),c=TypeError,l=Object.defineProperty,u=Object.getOwnPropertyDescriptor,d=`enumerable`,f=`configurable`,p=`writable`;t.f=r?a?function(e,t,n){if(o(e),t=s(t),o(n),typeof e==`function`&&t===`prototype`&&`value`in n&&p in n&&!n[p]){var r=u(e,t);r&&r[p]&&(e[t]=n.value,n={configurable:f in n?n[f]:r[f],enumerable:d in n?n[d]:r[d],writable:!1})}return l(e,t,n)}:l:function(e,t,n){if(o(e),t=s(t),o(n),i)try{return l(e,t,n)}catch{}if(`get`in n||`set`in n)throw new c(`Accessors not supported`);return`value`in n&&(e[t]=n.value),e}},7347:function(e,t,n){var r=n(3724),i=n(9565),a=n(8773),o=n(6980),s=n(5397),c=n(6969),l=n(9297),u=n(5917),d=Object.getOwnPropertyDescriptor;t.f=r?d:function(e,t){if(e=s(e),t=c(t),u)try{return d(e,t)}catch{}if(l(e,t))return o(!i(a.f,e,t),e[t])}},298:function(e,t,n){var r=n(2195),i=n(5397),a=n(8480).f,o=n(7680),s=typeof window==`object`&&window&&Object.getOwnPropertyNames?Object.getOwnPropertyNames(window):[];e.exports.f=function(e){return s&&r(e)===`Window`?function(e){try{return a(e)}catch{return o(s)}}(e):a(i(e))}},8480:function(e,t,n){var r=n(1828),i=n(8727).concat(`length`,`prototype`);t.f=Object.getOwnPropertyNames||function(e){return r(e,i)}},3717:function(e,t){t.f=Object.getOwnPropertySymbols},2787:function(e,t,n){var r=n(9297),i=n(4901),a=n(8981),o=n(6119),s=n(2211),c=o(`IE_PROTO`),l=Object,u=l.prototype;e.exports=s?l.getPrototypeOf:function(e){var t=a(e);if(r(t,c))return t[c];var n=t.constructor;return i(n)&&t instanceof n?n.prototype:t instanceof l?u:null}},1625:function(e,t,n){e.exports=n(9504)({}.isPrototypeOf)},1828:function(e,t,n){var r=n(9504),i=n(9297),a=n(5397),o=n(9617).indexOf,s=n(421),c=r([].push);e.exports=function(e,t){var n,r=a(e),l=0,u=[];for(n in r)!i(s,n)&&i(r,n)&&c(u,n);for(;t.length>l;)i(r,n=t[l++])&&(~o(u,n)||c(u,n));return u}},1072:function(e,t,n){var r=n(1828),i=n(8727);e.exports=Object.keys||function(e){return r(e,i)}},8773:function(e,t){var n={}.propertyIsEnumerable,r=Object.getOwnPropertyDescriptor;t.f=r&&!n.call({1:2},1)?function(e){var t=r(this,e);return!!t&&t.enumerable}:n},2551:function(e,t,n){var r=n(6395),i=n(4576),a=n(9039),o=n(3607);e.exports=r||!a((function(){if(!(o&&o<535)){var e=Math.random();__defineSetter__.call(null,e,(function(){})),delete i[e]}}))},2967:function(e,t,n){var r=n(6706),i=n(34),a=n(7750),o=n(3506);e.exports=Object.setPrototypeOf||(`__proto__`in{}?function(){var e,t=!1,n={};try{(e=r(Object.prototype,`__proto__`,`set`))(n,[]),t=n instanceof Array}catch{}return function(n,r){return a(n),o(r),i(n)&&(t?e(n,r):n.__proto__=r),n}}():void 0)},3179:function(e,t,n){var r=n(2140),i=n(6955);e.exports=r?{}.toString:function(){return`[object `+i(this)+`]`}},4270:function(e,t,n){var r=n(9565),i=n(4901),a=n(34),o=TypeError;e.exports=function(e,t){var n,s;if(t===`string`&&i(n=e.toString)&&!a(s=r(n,e))||i(n=e.valueOf)&&!a(s=r(n,e))||t!==`string`&&i(n=e.toString)&&!a(s=r(n,e)))return s;throw new o(`Can't convert object to primitive value`)}},5031:function(e,t,n){var r=n(7751),i=n(9504),a=n(8480),o=n(3717),s=n(8551),c=i([].concat);e.exports=r(`Reflect`,`ownKeys`)||function(e){var t=a.f(s(e)),n=o.f;return n?c(t,n(e)):t}},8235:function(e,t,n){var r=n(9504),i=n(9297),a=SyntaxError,o=parseInt,s=String.fromCharCode,c=r(``.charAt),l=r(``.slice),u=r(/./.exec),d={'\\"':`"`,"\\\\":`\\`,"\\/":`/`,"\\b":`\b`,"\\f":`\f`,"\\n":`
diff --git a/static/index.html b/static/index.html
index cdd8b9622..9ca3a00cb 100644
--- a/static/index.html
+++ b/static/index.html
@@ -26,7 +26,7 @@
-
+