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||={})})(W6||={}),(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||={})})(W6||={});var G6=W6,zVe={L:G6.QrCode.Ecc.LOW,M:G6.QrCode.Ecc.MEDIUM,Q:G6.QrCode.Ecc.QUARTILE,H:G6.QrCode.Ecc.HIGH},K6=128,q6=`L`,J6=`#FFFFFF`,Y6=`#000000`,X6=!1,Z6=1,BVe=4,VVe=0,HVe=.1;function Q6(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 $6(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 UVe(e,t,n,r){if(r==null)return null;let i=e.length+n*2,a=Math.floor(t*HVe),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 WVe(e,t){return t==null?e?BVe:VVe:Math.max(Math.floor(t),0)}function e8({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(...G6.QrSegment.makeSegments(t)),e),[]);return G6.QrCode.encodeSegments(r,zVe[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=WVe(r,i);return{cells:e,margin:t,numCells:e.length+t*2,calculatedImageSettings:UVe(e,o,t,a)}},[c,o,a,r,i]);return{qrcode:c,margin:u,cells:l,numCells:d,calculatedImageSettings:f}}var GVe=function(){try{new Path2D().addPath(new Path2D)}catch{return!1}return!0}(),KVe=y.forwardRef(function(e,t){let n=e,{value:r,size:i=K6,level:a=q6,bgColor:o=J6,fgColor:s=Y6,includeMargin:c=X6,minVersion:l=Z6,boostLevel:u,marginSize:d,imageSettings:f}=n,p=U6(n,[`value`,`size`,`level`,`bgColor`,`fgColor`,`includeMargin`,`minVersion`,`boostLevel`,`marginSize`,`imageSettings`]),{style:m}=p,h=U6(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}=e8({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=$6(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,GVe?t.fill(new Path2D(Q6(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=H6({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`,H6({style:D,height:i,width:i,ref:b,role:`img`},h)),O)});KVe.displayName=`QRCodeCanvas`;var t8=y.forwardRef(function(e,t){let n=e,{value:r,size:i=K6,level:a=q6,bgColor:o=J6,fgColor:s=Y6,includeMargin:c=X6,minVersion:l=Z6,boostLevel:u,title:d,marginSize:f,imageSettings:p}=n,m=U6(n,[`value`,`size`,`level`,`bgColor`,`fgColor`,`includeMargin`,`minVersion`,`boostLevel`,`title`,`marginSize`,`imageSettings`]),{margin:h,cells:g,numCells:_,calculatedImageSettings:v}=e8({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=$6(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=Q6(b,h);return y.createElement(`svg`,H6({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)});t8.displayName=`QRCodeSVG`;function qVe(e,t){return`bambuddy://config?v=1&url=${encodeURIComponent(e)}&key=${encodeURIComponent(t)}`}function JVe({apiKey:e,baseUrl:t,onClose:n}){let{t:r}=U(),i=qVe(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)(Qu,{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)(t8,{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)(Nu,{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 YVe=300,n8=2;function r8({onSuccess:e}){let{t}=U(),n=co(),[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),YVe);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>=n8,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=n8,g=!!d.data&&d.data.length>0,_=!h&&!!d.data&&d.data.length===0&&a.length>=n8;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)(Jl,{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)(XVe,{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)(jl,{className:`w-4 h-4`}),t(`users.modal.ldapProvision`)]})})})]})}function XVe({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)(xs,{className:`w-3.5 h-3.5`}),r(`users.modal.ldapAlreadyProvisioned`)]})]})})}function ZVe({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)(jd,{className:`w-full max-w-md`,onClick:e=>e.stopPropagation(),children:[(0,G.jsx)(Md,{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)(zu,{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)(Qu,{className:`w-5 h-5`})})]})}),(0,G.jsxs)(Nd,{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)(r8,{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)(jl,{className:`w-4 h-4`}),l(`users.modal.createUser`)]})})]})]})]})})}function QVe(){let{t:e}=U(),t=co(),{showToast:n}=zd(),[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 rd&&t.status===503?n(e(`settings.spoolmanAmsSyncErrorUnreachable`),`error`):t instanceof rd&&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)(jd,{id:`card-spoolman`,children:[(0,G.jsx)(Md,{children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Ws,{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)(Nd,{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)(jd,{id:`card-spoolman`,children:[(0,G.jsx)(Md,{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)(Ws,{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)(Nd,{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)(yl,{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)(ds,{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)(ds,{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)(Bc,{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)(Rl,{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)(Bc,{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)(ds,{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)(Qu,{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)(Kc,{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)(qc,{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)(fs,{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)(Rl,{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)(Rl,{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)(Nu,{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 $Ve(){let{t:e}=U(),{showToast:t}=zd(),[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)(jd,{id:`card-spool-catalog`,children:[(0,G.jsxs)(Md,{children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,G.jsx)(Ws,{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)(Lu,{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)(Bl,{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)(jl,{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)(Au,{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)(Nd,{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)(Jl,{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)(ds,{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)(Qu,{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)(ds,{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)(Qu,{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)(El,{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)(Au,{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 eHe=2166136261,tHe=16777619;function nHe(...e){let t=eHe,n=new TextEncoder,r=n.encode(`__|`);for(let i of e)typeof i==`string`?t=i8(t,n.encode(i+`|`)):i??(t=i8(t,r));return t>>>0}function i8(e,t){for(let n of t)e^=n,e=Math.imul(e,tHe)>>>0;return e}function rHe(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 a8={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}},o8=[{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`}],iHe=`repeating-conic-gradient(#979797 0% 25%, #f5f5f5 0% 50%)`,aHe=`12px 12px`,oHe={sparkle:(e=0,t=`table`)=>{let n=rHe(e),r=a8[t]??a8.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 s8(e){let t=e.trim().replace(/^#/,``);return t.length!==6&&t.length!==8||!/^[0-9a-fA-F]+$/.test(t)?null:`#${t}`}function c8(e){return e?e.split(`,`).map(e=>s8(e)).filter(e=>!!e):[]}function sHe(e,t,n,r){let i=e?s8(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 cHe(e,t,n){let r=oHe[e];return r?r(n,t):null}function l8(e){let t=c8(e.extraColors),n=sHe(e.rgba,t,e.subtype,e.effectType),r=nHe(e.rgba,e.extraColors,e.subtype,e.effectType),i=typeof e.effectType==`string`?cHe(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:iHe,size:aHe}),{backgroundImage:a.map(e=>e.image).join(`, `),backgroundSize:a.map(e=>e.size).join(`, `)}}function u8({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)(()=>c8(t),[t]),u=(0,y.useMemo)(()=>l8({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 lHe(){let{t:e}=U(),{showToast:t}=zd(),[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=od();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)(UBe,{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)(qBe,{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 qBe({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)(yl,{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 JBe({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 y6=[`weight`,`prints`,`time`];function b6({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?y6.filter(e=>!n.includes(e)):y6).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 x6(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 S6=[`#00ae42`,`#3b82f6`,`#f59e0b`,`#ef4444`,`#8b5cf6`,`#ec4899`,`#14b8a6`,`#f97316`],YBe=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`],C6=[`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 XBe({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?`${YBe[i.getDay()]} ${C6[a]}`:C6[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:x6(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)(_A,{width:`100%`,height:250,children:(0,G.jsxs)(TU,{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)(jV,{strokeDasharray:`3 3`,stroke:`#3d3d3d`}),(0,G.jsx)(FH,{dataKey:`dateLabel`,stroke:`#9ca3af`,tick:{fontSize:12},interval:`preserveStartEnd`}),(0,G.jsx)(BH,{stroke:`#9ca3af`,tick:{fontSize:12},tickFormatter:e=>`${e}g`}),(0,G.jsx)(pz,{contentStyle:{backgroundColor:`#2d2d2d`,border:`1px solid #3d3d3d`,borderRadius:`8px`},labelStyle:{color:`#fff`},formatter:e=>[`${Number(e??0).toFixed(0)}g`,`Filament`]}),(0,G.jsx)(pH,{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)(_A,{width:`100%`,height:250,children:(0,G.jsxs)(TU,{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)(jV,{strokeDasharray:`3 3`,stroke:`#3d3d3d`}),(0,G.jsx)(FH,{dataKey:`dateLabel`,stroke:`#9ca3af`,tick:{fontSize:12},interval:`preserveStartEnd`}),(0,G.jsx)(BH,{stroke:`#9ca3af`,tick:{fontSize:12},tickFormatter:e=>`${e}kWh`}),(0,G.jsx)(pz,{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)(pH,{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)(b6,{value:a,onChange:o})]}),v.length>0?(0,G.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,G.jsx)(_A,{width:160,height:160,children:(0,G.jsxs)(wU,{children:[(0,G.jsx)(KB,{data:v,cx:`50%`,cy:`50%`,innerRadius:40,outerRadius:70,paddingAngle:2,dataKey:`value`,children:v.map((e,t)=>(0,G.jsx)(mz,{fill:S6[t%S6.length]},`cell-${t}`))}),(0,G.jsx)(pz,{contentStyle:{backgroundColor:`#2d2d2d`,border:`1px solid #3d3d3d`,borderRadius:`8px`},formatter:e=>[a===`weight`?x6(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:S6[t%S6.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`?x6(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)(b6,{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)(_A,{width:`100%`,height:`100%`,children:(0,G.jsxs)(wU,{children:[(0,G.jsx)(KB,{data:_,cx:`50%`,cy:`50%`,innerRadius:45,outerRadius:70,paddingAngle:2,dataKey:`value`,children:_.map((e,t)=>(0,G.jsx)(mz,{fill:e.hex,stroke:`#1a1a1a`,strokeWidth:1},`color-${t}`))}),(0,G.jsx)(pz,{contentStyle:{backgroundColor:`#2d2d2d`,border:`1px solid #3d3d3d`,borderRadius:`8px`},formatter:e=>[s===`weight`?x6(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`?x6(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 ZBe({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}=e6({id:e}),m={transform:M4.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)(cl,{className:`w-4 h-4 text-bambu-gray hover:text-white`}):(0,G.jsx)(al,{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 QBe({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=R4(L4(v3,{activationConstraint:{distance:8}}),L4(m3,{coordinateGetter:n6})),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:K3(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)(Bl,{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)(H3,{sensors:h,collisionDetection:G4,onDragEnd:g,children:(0,G.jsx)(Q3,{items:S.map(e=>e.id),strategy:J3,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)(ZBe,{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 $Be(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 eVe=[`today`,`this-week`,`this-month`,`last-7`,`last-30`,`last-90`,`this-year`,`all-time`],tVe=[`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`,`Sun`],w6=[`12am`,`1am`,`2am`,`3am`,`4am`,`5am`,`6am`,`7am`,`8am`,`9am`,`10am`,`11am`,`12pm`,`1pm`,`2pm`,`3pm`,`4pm`,`5pm`,`6pm`,`7pm`,`8pm`,`9pm`,`10pm`,`11pm`],T6=[{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}],E6={backgroundColor:`#2d2d2d`,border:`1px solid #3d3d3d`,borderRadius:`8px`};function nVe({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:yl,color:`text-bambu-green`,label:n(`stats.totalPrints`),value:`${e?.total_prints||0}`},{icon:As,color:`text-blue-600 dark:text-blue-400`,label:n(`stats.printTime`),value:`${e?.total_print_time_hours?.toFixed(1)??`0`}h`},{icon:yl,color:`text-orange-600 dark:text-orange-400`,label:n(`stats.filamentUsed`),value:x6(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:ed,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)(Nu,{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 rVe({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)(bs,{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)(Es,{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)(Uo,{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 iVe({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)(Cu,{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 aVe({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:w6.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} ${w6[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 oVe({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)(aVe,{printDates:e,dateFrom:n,dateTo:r}):(0,G.jsx)(JBe,{printDates:e,months:i===1/0?t===1?3:t===2?6:12:Math.max(1,Math.ceil(i/30))})}function sVe({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:w6[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=T6.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 tVe.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)(b6,{value:i,onChange:a})]}),c.length>0?(0,G.jsx)(_A,{width:`100%`,height:Math.max(140,c.length*40),children:(0,G.jsxs)(yU,{data:c,layout:`vertical`,margin:{left:10},children:[(0,G.jsx)(jV,{strokeDasharray:`3 3`,stroke:`#3d3d3d`}),(0,G.jsx)(FH,{type:`number`,stroke:`#9ca3af`,tick:{fontSize:11},unit:p.unit}),(0,G.jsx)(BH,{type:`category`,dataKey:`name`,stroke:`#9ca3af`,tick:{fontSize:11},width:100}),(0,G.jsx)(pz,{contentStyle:E6,formatter:e=>[i===`weight`?x6(Number(e??0)):`${e??0}${p.unit}`,m]}),(0,G.jsx)(DH,{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)(_A,{width:`100%`,height:160,children:(0,G.jsxs)(yU,{data:u,children:[(0,G.jsx)(jV,{strokeDasharray:`3 3`,stroke:`#3d3d3d`}),(0,G.jsx)(FH,{dataKey:`name`,stroke:`#9ca3af`,tick:{fontSize:11}}),(0,G.jsx)(BH,{stroke:`#9ca3af`,tick:{fontSize:11},allowDecimals:!1}),(0,G.jsx)(pz,{contentStyle:E6}),(0,G.jsx)(DH,{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)(b6,{value:o,onChange:s})]}),t.length>0?(0,G.jsx)(_A,{width:`100%`,height:160,children:(0,G.jsxs)(yU,{data:d,children:[(0,G.jsx)(jV,{strokeDasharray:`3 3`,stroke:`#3d3d3d`}),(0,G.jsx)(FH,{dataKey:`name`,stroke:`#9ca3af`,tick:{fontSize:11}}),(0,G.jsx)(BH,{stroke:`#9ca3af`,tick:{fontSize:11},unit:h.unit}),(0,G.jsx)(pz,{contentStyle:E6,formatter:e=>[`${e??0}${h.unit}`,g]}),(0,G.jsx)(DH,{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)(_A,{width:`100%`,height:160,children:(0,G.jsxs)(yU,{data:l,children:[(0,G.jsx)(jV,{strokeDasharray:`3 3`,stroke:`#3d3d3d`}),(0,G.jsx)(FH,{dataKey:`label`,stroke:`#9ca3af`,tick:{fontSize:10},interval:5}),(0,G.jsx)(BH,{stroke:`#9ca3af`,tick:{fontSize:11},allowDecimals:!1}),(0,G.jsx)(pz,{contentStyle:E6}),(0,G.jsx)(DH,{dataKey:`total`,name:r(`stats.totalPrints`),fill:`#00ae42`,radius:[2,2,0,0]}),(0,G.jsx)(DH,{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 cVe({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)(XBe,{archives:e,currency:t,dateFrom:n,dateTo:r})}function lVe({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)(Nu,{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)(ju,{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 uVe({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:As,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:yl,iconColor:`text-orange-600 dark:text-orange-400`,label:n(`stats.heaviestPrint`),value:x6(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:is,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:ed,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 dVe(){let{t:e}=U(),{showToast:t}=zd(),{hasPermission:n,authEnabled:r}=Td(),[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}:$Be(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=(0,y.useMemo)(()=>new Map([...Object.entries(E?.printer_names||{}),...A?.map(e=>[String(e.id),e.name])||[]]),[E?.printer_names,A]),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)(nVe,{stats:E,currency:B}),defaultSize:2},{id:`success-rate`,title:e(`stats.successRate`),component:e=>(0,G.jsx)(rVe,{stats:E,printerMap:V,size:e}),defaultSize:1},{id:`time-accuracy`,title:e(`stats.timeAccuracy`),component:e=>(0,G.jsx)(iVe,{stats:E,printerMap:V,size:e}),defaultSize:1},{id:`failure-analysis`,title:e(`stats.failureAnalysis`),component:e=>(0,G.jsx)(lVe,{size:e,dateFrom:w.dateFrom,dateTo:w.dateTo,createdById:T}),defaultSize:1},{id:`print-activity`,title:e(`stats.printActivity`),component:e=>(0,G.jsx)(oVe,{printDates:ee,size:e,dateFrom:w.dateFrom,dateTo:w.dateTo}),defaultSize:2},{id:`records`,title:e(`stats.records`),component:(0,G.jsx)(uVe,{archives:j||[],currency:B}),defaultSize:1},{id:`printer-stats`,title:e(`stats.printerStats`),component:(0,G.jsx)(sVe,{stats:E,archives:j||[],printerMap:V}),defaultSize:4},{id:`filament-trends`,title:e(`stats.filamentTrends`),component:(0,G.jsx)(cVe,{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)(ss,{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)(Bl,{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)(ts,{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)(zu,{className:`w-4 h-4`}),I,(0,G.jsx)(fs,{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)(is,{className:`w-4 h-4`}),e(`stats.timeframe.${b.preset}`),(0,G.jsx)(fs,{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:[eVe.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`})]}),(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`})]}),(0,G.jsx)(Q,{variant:`primary`,onClick:()=>C(!1),className:`w-full`,children:e(`common.apply`)})]})]})]})]})]})]}),(0,G.jsx)(QBe,{widgets:te,storageKey:`bambusy-dashboard-layout-v2`,stackBelow:640,hideControls:!0},c)]})}function D6(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 O6={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},k6=[`PA-CF`,`PA`,`PC`,`PC-FR`,`ABS`,`ASA`,`PETG-CF`,`PETG`,`PLA`,`TPU`,`PVA`,`default`];function fVe(e){if(!e)return{...O6};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=O6.default),e}}catch{}return{...O6}}function pVe(e){let t={};for(let n of k6)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 mVe({value:e,onChange:t,disabled:n=!1}){let{t:r}=U(),i=fVe(e),a=(e,n)=>{let r=Math.max(0,Math.min(65,Math.round(n)));t(pVe({...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:k6.map(e=>{let t=i[e]??O6[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 A6(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 hVe={orca_cloud:`Orca Cloud`,cloud:`Bambu Cloud`,local:`Imported`,standard:`Standard`};function gVe(){let{t:e}=U(),t=co(),{showToast:n}=zd(),{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)(jd,{children:[(0,G.jsxs)(Md,{children:[(0,G.jsxs)(`h3`,{className:`text-base font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(Xu,{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)(Nd,{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)(Jl,{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)(_Ve,{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 _Ve({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=A6(t,`printer`,e.printer_preset),D=A6(t,`process`,e.process_preset),O=e.filament_presets.map(e=>A6(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)(Pl,{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)(ds,{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)(Qu,{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)(Tl,{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)(Au,{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)(j6,{label:s(`settings.pipelines.slot.printer`,`Printer`),ref:e.printer_preset,name:E}),(0,G.jsx)(j6,{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)(j6,{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)(j6,{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)(vVe,{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)(Nu,{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)(Nu,{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 vVe({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 j6({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:[`[`,hVe[t.source],` #`,t.id,`]`]})]})}var M6=90,N6=365;function P6(e){if(!e)return`—`;let t=Kf(e);return t?t.toLocaleString():`—`}function yVe(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(M6),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:N6,required:!0,value:a,onChange:e=>{let t=Number(e.target.value);o(Math.min(Math.max(t,1),N6))},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)(jl,{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 xVe({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)(Nu,{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 SVe({token:e,onClose:t}){let{t:n}=U(),{showToast:r}=zd(),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)(Nu,{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)(Bs,{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)(Bs,{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)(Bs,{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 CVe({token:e,showOwner:t,ownerLabel:n,onRevoke:r}){let{t:i}=U(),a=yVe(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:P6(e.created_at)}),(0,G.jsxs)(`td`,{className:`py-3 px-3 ${a?`text-red-700 dark:text-red-400`:`text-bambu-gray`}`,children:[P6(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:P6(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)(Au,{className:`w-4 h-4`}),i(`cameraTokens.list.revoke`,`Revoke`)]})})]})}function F6({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)(CVe,{token:e,showOwner:t,ownerLabel:n?.get(e.user_id)??`#${e.user_id}`,onRevoke:r},e.id))})]})})}function wVe(){let{t:e}=U(),{user:t,isAdmin:n}=Td(),{showToast:r}=zd(),[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)(bVe,{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)(F6,{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)(F6,{tokens:b,showOwner:!0,userIdToName:c,onRevoke:_,emptyMessage:e(`cameraTokens.list.empty`,`No tokens yet.`)})]}),f&&(0,G.jsx)(SVe,{token:f,onClose:()=>p(null)}),m&&(0,G.jsx)(xVe,{token:m,onConfirm:()=>void v(),onCancel:()=>h(null)})]})}var I6=[{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`}],TVe=[`progress`,`layers`,`eta`,`filename`,`status`],L6=15;function EVe(){let{t:e}=U(),{showToast:t}=zd(),[n,r]=(0,y.useState)([]),[i,a]=(0,y.useState)(null),[o,s]=(0,y.useState)(TVe),[c,l]=(0,y.useState)(`medium`),[u,d]=(0,y.useState)(L6),[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=I6.filter(e=>o.includes(e.key)).map(e=>e.key);return t.set(`show`,n.join(`,`)),c!==`medium`&&t.set(`size`,c),u!==L6&&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:[I6.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)(Bs,{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 DVe({plug:e,onEdit:t}){let{t:n}=U(),r=co(),{showToast:i}=zd(),[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)(jd,{className:`relative`,children:(0,G.jsxs)(Nd,{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)(Il,{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)(Ic,{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)(Al,{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)(Ju,{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)(qu,{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)(Ko,{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)(is,{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)(Nl,{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)(Ml,{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)(Ql,{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)(Gc,{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)(Nl,{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)(As,{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)(Ou,{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)(Tl,{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)(Au,{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 OVe({plug:e,onClose:t}){let{t:n}=U(),r=co(),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)},Ht=e=>{u(e.ip_address),c(e.name),ot(null)},Ut=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)}}),Wt=q({mutationFn:e=>Z.createSmartPlug(e),onSuccess:()=>{r.invalidateQueries({queryKey:[`smart-plugs`]}),r.invalidateQueries({queryKey:[`scriptPlugsByPrinter`]}),t()},onError:e=>{ct(e.message)}}),Gt=q({mutationFn:t=>Z.updateSmartPlug(e.id,t),onSuccess:()=>{r.invalidateQueries({queryKey:[`smart-plugs`]}),r.invalidateQueries({queryKey:[`scriptPlugsByPrinter`]}),t()},onError:e=>{ct(e.message)}}),Kt=Mt?.filter(t=>a===`tasmota`?!Nt?.some(n=>n.printer_id===t.id&&n.id!==e?.id&&n.plug_type===`tasmota`):!0),qt=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?Gt.mutate(t):Wt.mutate(t)},Jt=Wt.isPending||Gt.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)(Qu,{className:`w-5 h-5`})})]}),(0,G.jsxs)(`form`,{onSubmit:qt,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)(Al,{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)(Ic,{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)(Il,{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)(Qu,{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)(Jl,{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:()=>Ht(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)(Al,{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)(Nl,{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)(Jl,{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)(Qu,{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)(Jl,{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)(Qu,{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)(Jl,{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)(Qu,{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)(Jl,{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)(Qu,{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)(Ju,{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)(bs,{className:`w-4 h-4`}):(0,G.jsx)(qu,{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:()=>Ut.mutate(),disabled:!l.trim()||Ut.isPending,children:[Ut.isPending?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Ju,{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)(bs,{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)(qu,{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`)}),Kt?.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)(Ko,{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)(As,{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)(Gc,{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:Jt,className:`flex-1`,children:[Jt?(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}):(0,G.jsx)(Ul,{className:`w-4 h-4`}),n(i?`smartPlugs.save`:`smartPlugs.add`)]})]})]})]})})}var kVe={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 AVe({sensor:e,printers:t,onClose:n}){let{t:r}=U(),i=co(),{showToast:a}=zd(),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=kVe[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)(Qu,{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)(Jl,{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)(Ul,{className:`w-4 h-4`}),r(`common.save`)]})]})]})]})]})})}function jVe({provider:e,onEdit:t}){let{t:n}=U(),r=co(),[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)(jd,{className:`relative`,children:(0,G.jsxs)(Nd,{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)(Ko,{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)(DU,{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)(pl,{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)(is,{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)(Yl,{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)(bs,{className:`w-4 h-4`}):(0,G.jsx)(Es,{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)(Ql,{className:`w-4 h-4`}),n(`notifications.eventSettings`)]}),o?(0,G.jsx)(hs,{className:`w-4 h-4`}):(0,G.jsx)(fs,{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)(DU,{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)(DU,{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)(DU,{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)(DU,{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)(DU,{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)(DU,{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)(DU,{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)(DU,{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)(DU,{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)(DU,{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)(DU,{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)(DU,{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)(DU,{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)(DU,{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)(DU,{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)(DU,{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)(DU,{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)(DU,{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)(DU,{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)(DU,{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)(DU,{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)(DU,{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)(DU,{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)(DU,{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)(DU,{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)(DU,{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)(DU,{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)(DU,{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)(DU,{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)(DU,{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)(DU,{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)(DU,{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)(pl,{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)(DU,{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)(As,{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)(is,{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)(DU,{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)(As,{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)(Tl,{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)(Au,{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 MVe=[`email`,`telegram`,`discord`,`ntfy`,`pushover`,`bark`,`callmebot`,`webhook`,`homeassistant`];function NVe({provider:e,onClose:t}){let{t:n}=U(),r=co(),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)(Qu,{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:MVe.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)(Yl,{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)(bs,{className:`w-5 h-5`}),(0,G.jsx)(`span`,{children:_e.message})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Es,{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)(DU,{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)(DU,{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)(DU,{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)(DU,{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)(DU,{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)(DU,{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)(DU,{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)(DU,{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)(DU,{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)(DU,{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)(DU,{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)(DU,{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)(DU,{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)(DU,{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)(DU,{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)(DU,{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)(DU,{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)(DU,{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)(DU,{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)(Ul,{className:`w-4 h-4`}),n(i?`notifications.save`:`notifications.add`)]})]})]})]})})}function PVe({template:e,onClose:t}){let{t:n}=U(),r=co(),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)(Qu,{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)(jl,{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)(Bl,{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)(Ul,{className:`w-4 h-4 mr-2`}),n(`notifications.save`)]})]})]})]})})}var FVe={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 IVe({onClose:e}){let{t}=U(),n=co(),{showToast:r}=zd(),[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)(Fc,{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)(bs,{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)(Es,{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)(Rl,{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)(Au,{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)(LVe,{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)(Fc,{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 LVe({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)(bs,{className:`w-4 h-4 text-bambu-green shrink-0`}):(0,G.jsx)(Es,{className:`w-4 h-4 text-red-600 dark:text-red-400 shrink-0`}),(0,G.jsx)(`span`,{className:`text-xs font-medium ${FVe[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)(hs,{className:`w-4 h-4 text-bambu-gray shrink-0`}):(0,G.jsx)(fs,{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 RVe=Object.defineProperty,R6=Object.getOwnPropertySymbols,z6=Object.prototype.hasOwnProperty,B6=Object.prototype.propertyIsEnumerable,V6=(e,t,n)=>t in e?RVe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,H6=(e,t)=>{for(var n in t||={})z6.call(t,n)&&V6(e,n,t[n]);if(R6)for(var n of R6(t))B6.call(t,n)&&V6(e,n,t[n]);return e},U6=(e,t)=>{var n={};for(var r in e)z6.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&R6)for(var r of R6(e))t.indexOf(r)<0&&B6.call(e,r)&&(n[r]=e[r]);return n},W6;(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||={})})(W6||={}),(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||={})})(W6||={});var G6=W6,zVe={L:G6.QrCode.Ecc.LOW,M:G6.QrCode.Ecc.MEDIUM,Q:G6.QrCode.Ecc.QUARTILE,H:G6.QrCode.Ecc.HIGH},K6=128,q6=`L`,J6=`#FFFFFF`,Y6=`#000000`,X6=!1,Z6=1,BVe=4,VVe=0,HVe=.1;function Q6(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 $6(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 UVe(e,t,n,r){if(r==null)return null;let i=e.length+n*2,a=Math.floor(t*HVe),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 WVe(e,t){return t==null?e?BVe:VVe:Math.max(Math.floor(t),0)}function e8({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(...G6.QrSegment.makeSegments(t)),e),[]);return G6.QrCode.encodeSegments(r,zVe[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=WVe(r,i);return{cells:e,margin:t,numCells:e.length+t*2,calculatedImageSettings:UVe(e,o,t,a)}},[c,o,a,r,i]);return{qrcode:c,margin:u,cells:l,numCells:d,calculatedImageSettings:f}}var GVe=function(){try{new Path2D().addPath(new Path2D)}catch{return!1}return!0}(),KVe=y.forwardRef(function(e,t){let n=e,{value:r,size:i=K6,level:a=q6,bgColor:o=J6,fgColor:s=Y6,includeMargin:c=X6,minVersion:l=Z6,boostLevel:u,marginSize:d,imageSettings:f}=n,p=U6(n,[`value`,`size`,`level`,`bgColor`,`fgColor`,`includeMargin`,`minVersion`,`boostLevel`,`marginSize`,`imageSettings`]),{style:m}=p,h=U6(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}=e8({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=$6(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,GVe?t.fill(new Path2D(Q6(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=H6({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`,H6({style:D,height:i,width:i,ref:b,role:`img`},h)),O)});KVe.displayName=`QRCodeCanvas`;var t8=y.forwardRef(function(e,t){let n=e,{value:r,size:i=K6,level:a=q6,bgColor:o=J6,fgColor:s=Y6,includeMargin:c=X6,minVersion:l=Z6,boostLevel:u,title:d,marginSize:f,imageSettings:p}=n,m=U6(n,[`value`,`size`,`level`,`bgColor`,`fgColor`,`includeMargin`,`minVersion`,`boostLevel`,`title`,`marginSize`,`imageSettings`]),{margin:h,cells:g,numCells:_,calculatedImageSettings:v}=e8({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=$6(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=Q6(b,h);return y.createElement(`svg`,H6({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)});t8.displayName=`QRCodeSVG`;function qVe(e,t){return`bambuddy://config?v=1&url=${encodeURIComponent(e)}&key=${encodeURIComponent(t)}`}function JVe({apiKey:e,baseUrl:t,onClose:n}){let{t:r}=U(),i=qVe(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)(Qu,{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)(t8,{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)(Nu,{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 YVe=300,n8=2;function r8({onSuccess:e}){let{t}=U(),n=co(),[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),YVe);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>=n8,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=n8,g=!!d.data&&d.data.length>0,_=!h&&!!d.data&&d.data.length===0&&a.length>=n8;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)(Jl,{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)(XVe,{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)(jl,{className:`w-4 h-4`}),t(`users.modal.ldapProvision`)]})})})]})}function XVe({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)(xs,{className:`w-3.5 h-3.5`}),r(`users.modal.ldapAlreadyProvisioned`)]})]})})}function ZVe({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)(jd,{className:`w-full max-w-md`,onClick:e=>e.stopPropagation(),children:[(0,G.jsx)(Md,{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)(zu,{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)(Qu,{className:`w-5 h-5`})})]})}),(0,G.jsxs)(Nd,{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)(r8,{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)(jl,{className:`w-4 h-4`}),l(`users.modal.createUser`)]})})]})]})]})})}function QVe(){let{t:e}=U(),t=co(),{showToast:n}=zd(),[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 rd&&t.status===503?n(e(`settings.spoolmanAmsSyncErrorUnreachable`),`error`):t instanceof rd&&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)(jd,{id:`card-spoolman`,children:[(0,G.jsx)(Md,{children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Ws,{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)(Nd,{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)(jd,{id:`card-spoolman`,children:[(0,G.jsx)(Md,{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)(Ws,{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)(Nd,{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)(yl,{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)(ds,{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)(ds,{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)(Bc,{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)(Rl,{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)(Bc,{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)(ds,{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)(Qu,{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)(Kc,{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)(qc,{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)(fs,{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)(Rl,{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)(Rl,{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)(Nu,{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 $Ve(){let{t:e}=U(),{showToast:t}=zd(),[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)(jd,{id:`card-spool-catalog`,children:[(0,G.jsxs)(Md,{children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,G.jsx)(Ws,{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)(Lu,{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)(Bl,{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)(jl,{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)(Au,{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)(Nd,{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)(Jl,{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)(ds,{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)(Qu,{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)(ds,{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)(Qu,{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)(El,{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)(Au,{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 eHe=2166136261,tHe=16777619;function nHe(...e){let t=eHe,n=new TextEncoder,r=n.encode(`__|`);for(let i of e)typeof i==`string`?t=i8(t,n.encode(i+`|`)):i??(t=i8(t,r));return t>>>0}function i8(e,t){for(let n of t)e^=n,e=Math.imul(e,tHe)>>>0;return e}function rHe(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 a8={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}},o8=[{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`}],iHe=`repeating-conic-gradient(#979797 0% 25%, #f5f5f5 0% 50%)`,aHe=`12px 12px`,oHe={sparkle:(e=0,t=`table`)=>{let n=rHe(e),r=a8[t]??a8.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 s8(e){let t=e.trim().replace(/^#/,``);return t.length!==6&&t.length!==8||!/^[0-9a-fA-F]+$/.test(t)?null:`#${t}`}function c8(e){return e?e.split(`,`).map(e=>s8(e)).filter(e=>!!e):[]}function sHe(e,t,n,r){let i=e?s8(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 cHe(e,t,n){let r=oHe[e];return r?r(n,t):null}function l8(e){let t=c8(e.extraColors),n=sHe(e.rgba,t,e.subtype,e.effectType),r=nHe(e.rgba,e.extraColors,e.subtype,e.effectType),i=typeof e.effectType==`string`?cHe(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:iHe,size:aHe}),{backgroundImage:a.map(e=>e.image).join(`, `),backgroundSize:a.map(e=>e.size).join(`, `)}}function u8({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)(()=>c8(t),[t]),u=(0,y.useMemo)(()=>l8({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 lHe(){let{t:e}=U(),{showToast:t}=zd(),[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=od();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)(jd,{id:`card-color-catalog`,children:[(0,G.jsxs)(Md,{children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,G.jsx)(bl,{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)(Lu,{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)(Ns,{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)(Bl,{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)(jl,{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)(Au,{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)(Nd,{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)(Jl,{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)(ds,{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)(Qu,{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:o8.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)(ds,{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)(Qu,{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)(u8,{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)(El,{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)(Au,{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:o8.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 uHe({link:e,onClose:t}){let{t:n}=U(),r=co(),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)(Qu,{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)(Au,{className:`w-4 h-4`})})]}):(0,G.jsxs)(Q,{type:`button`,variant:`secondary`,size:`sm`,onClick:()=>a.current?.click(),children:[(0,G.jsx)(Lu,{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)(Ul,{className:`w-4 h-4`}),i?`Save`:`Add`]})]})]})]})})}function dHe(){let{t:e}=U(),t=co(),{authEnabled:n,hasPermission:r}=Td(),{showToast:i}=zd(),[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)(em),[_,v]=(0,y.useState)(()=>Qp(nm.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(nm.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),nm.forEach(e=>i(e.id)),(b||[]).forEach(e=>i(`ext-${e.id}`)),n},[b,_]),E=e=>{v(e),$p(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=[...nm.map(e=>e.id),...(b||[]).map(e=>`ext-${e.id}`)];g([]),v(e),tm([]),$p(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),tm(t)},I=n&&r(`settings:update`),L=!!C?.default_sidebar_order;return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(jd,{id:`card-sidebar-links`,children:[(0,G.jsx)(Md,{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)(qc,{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)(DU,{checked:L,onChange:P,disabled:w.isPending})]}),(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:N,className:`whitespace-nowrap`,children:[(0,G.jsx)(Bl,{className:`w-4 h-4`}),e(`settings.reset`)]}),(0,G.jsxs)(Q,{size:`sm`,onClick:()=>o(!0),className:`whitespace-nowrap`,children:[(0,G.jsx)(jl,{className:`w-4 h-4`}),`Add Link`]})]})]})}),(0,G.jsxs)(Nd,{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)(El,{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)(Au,{className:`w-4 h-4`})})]})]},t.id)})})]})]}),(a||s)&&(0,G.jsx)(uHe,{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 d8(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 fHe(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 pHe({status:e}){return e===`pass`?(0,G.jsx)(xs,{className:`w-5 h-5 text-bambu-green flex-shrink-0`}):e===`fail`?(0,G.jsx)(Es,{className:`w-5 h-5 text-red-600 dark:text-red-400 flex-shrink-0`}):e===`warn`?(0,G.jsx)(Nu,{className:`w-5 h-5 text-amber-600 dark:text-amber-400 flex-shrink-0`}):(0,G.jsx)(Cs,{className:`w-5 h-5 text-bambu-gray flex-shrink-0`})}function mHe({vpId:e,vpName:t,onClose:n}){let{t:r}=U(),i=q({mutationFn:()=>gd.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)(vu,{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)(Qu,{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)(pHe,{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 f8={archive:`archive`,review:`review`,queue:`queue`,proxy:`proxy`};function p8(e){return e===`immediate`?`archive`:e===`print_queue`||e===`queue`?`queue`:e===`archive`||e===`review`||e===`proxy`?e:`archive`}function hHe({printer:e,models:t}){let{t:n}=U(),r=co(),{showToast:i}=zd(),[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)(p8(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:gd.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 d8(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(p8(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=>gd.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(p8(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:()=>gd.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.${f8[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)(jd,{className:`overflow-hidden`,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)(fs,{className:`w-4 h-4`}):(0,G.jsx)(ps,{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.jsxs)(`div`,{className:`flex-1 min-w-0 flex flex-wrap items-center gap-x-3 gap-y-1`,children:[(0,G.jsx)(`span`,{className:`text-white font-medium truncate max-w-full`,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 truncate max-w-full`,children:[p===`proxy`&&(0,G.jsx)(Ro,{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)(Nd,{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)(vu,{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)(Au,{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)(tu,{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)(ds,{className:`w-3.5 h-3.5 text-bambu-green`}):(0,G.jsx)(Bs,{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)(Ro,{className:`w-3 h-3`}),n(`virtualPrinter.mode.${f8[e]}`)]}),(0,G.jsx)(`div`,{className:`text-[10px] text-bambu-gray`,children:n(`virtualPrinter.mode.${f8[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)(fs,{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)(Bc,{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)(Bc,{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)(ds,{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)(Nu,{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)(fs,{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)(fs,{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)(ds,{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)(Bc,{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)(fs,{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)(mHe,{vpId:e.id,vpName:e.name,onClose:()=>V(!1)})]})}var m8={archive:`archive`,review:`review`,queue:`queue`,proxy:`proxy`};function gHe({onClose:e}){let{t}=U(),n=co(),{showToast:r}=zd(),[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:()=>gd.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)(jd,{className:`w-full max-w-md`,onClick:e=>e.stopPropagation(),children:(0,G.jsxs)(Nd,{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)(Ro,{className:`w-3 h-3`}),t(`virtualPrinter.mode.${m8[e]}`)]}),(0,G.jsx)(`div`,{className:`text-[10px] text-bambu-gray`,children:t(`virtualPrinter.mode.${m8[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)(fs,{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 _He(){let{t:e}=U(),t=co(),{showToast:n}=zd(),[r,i]=(0,y.useState)(!1),{data:a,isLoading:o}=K({queryKey:[`virtual-printers`],queryFn:gd.list,refetchInterval:1e4}),{data:s}=K({queryKey:[`virtual-printer-settings`],queryFn:hd.getSettings}),c=q({mutationFn:e=>hd.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:gd.getCaCertificate,staleTime:1/0}),[d,f]=(0,y.useState)(!1),p=async()=>{u&&(await d8(u.pem)?(f(!0),n(e(`virtualPrinter.caCert.copied`)),setTimeout(()=>f(!1),2e3)):n(e(`virtualPrinter.toast.copyFailed`),`error`))},m=()=>{u&&fHe(u.pem,`bambuddy-virtual-printer-ca.crt`,`application/x-pem-file`)};if(o)return(0,G.jsx)(jd,{children:(0,G.jsx)(Nd,{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)(jd,{className:`border-l-4 border-l-yellow-500`,children:(0,G.jsx)(Nd,{className:`py-3 px-4`,children:(0,G.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,G.jsx)(Nu,{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)(jd,{className:`lg:col-span-2`,children:(0,G.jsx)(Nd,{className:`py-3 px-4`,children:(0,G.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,G.jsx)(Bc,{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)(jd,{children:(0,G.jsx)(Nd,{className:`py-3 px-4`,children:(0,G.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,G.jsx)(tu,{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)(ds,{className:`w-3.5 h-3.5 text-bambu-green`}):(0,G.jsx)(Bs,{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)(jd,{children:(0,G.jsx)(Nd,{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)(DU,{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)(Pl,{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)(jl,{className:`w-4 h-4 mr-1`}),e(`virtualPrinter.list.add`)]})]}),h.length===0?(0,G.jsx)(jd,{children:(0,G.jsxs)(Nd,{className:`py-8 text-center`,children:[(0,G.jsx)(Pl,{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)(jl,{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)(hHe,{printer:e,models:g},e.id))}),r&&(0,G.jsx)(gHe,{onClose:()=>i(!1)})]})}function h8(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 g8(e){return e==null?`—`:e>=1024?`${(e/1024).toFixed(1)} GB`:`${Math.round(e)} MB`}function vHe({device:e,onUnregister:t,isDeleting:n}){let{t:r}=U(),{showToast:i}=zd(),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 bd.triggerUpdate(e.device_id):await bd.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:fl},{key:`restart_daemon`,label:r(`settings.spoolbuddy.restartDaemon`),icon:Rl},{key:`reboot`,label:r(`settings.spoolbuddy.reboot`),icon:Vl},{key:`shutdown`,label:r(`settings.spoolbuddy.shutdown`),icon:Nl,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)(jd,{children:[(0,G.jsx)(Md,{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)(Ju,{className:`w-3 h-3`}):(0,G.jsx)(qu,{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)(Au,{className:`w-3.5 h-3.5`}),(0,G.jsx)(`span`,{className:`hidden sm:inline`,children:r(`settings.spoolbuddy.unregister`)})]})]})}),(0,G.jsxs)(Nd,{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)(As,{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:h8(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)(xs,{className:`w-3.5 h-3.5 text-green-400`}):(0,G.jsx)(Es,{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)(xs,{className:`w-3.5 h-3.5 text-green-400`}):(0,G.jsx)(Es,{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)(Ou,{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)(Mo,{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)(Vs,{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),`% (`,g8(o.used_mb),` / `,g8(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)(As,{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:h8(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 yHe(){let{t:e}=U(),t=co(),{showToast:n}=zd(),[r,i]=(0,y.useState)(null),{data:a=[],isLoading:o}=K({queryKey:[`spoolbuddy-devices`],queryFn:()=>bd.getDevices(),refetchInterval:15e3}),s=q({mutationFn:e=>bd.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)(jd,{children:(0,G.jsx)(Nd,{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)(jd,{children:(0,G.jsx)(Nd,{className:`py-3 px-4`,children:(0,G.jsxs)(`div`,{className:`flex items-start gap-2 text-xs`,children:[(0,G.jsx)(Bc,{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)(jd,{className:`border-l-4 border-l-yellow-500`,children:(0,G.jsx)(Nd,{className:`py-3 px-4`,children:(0,G.jsxs)(`div`,{className:`flex items-start gap-2 text-xs`,children:[(0,G.jsx)(Nu,{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)(jd,{children:(0,G.jsx)(Nd,{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)(vHe,{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 _8(e,t,n,r,i){return n?e(`backup.restoreFromGit.${t}.${n}`,{...r??{},defaultValue:i??n}):i}var v8=[{id:`archives`,labelKey:`backup.printArchives`,icon:(0,G.jsx)(Po,{className:`w-4 h-4`})},{id:`spools`,labelKey:`backup.spoolInventory`,icon:(0,G.jsx)(bl,{className:`w-4 h-4`})},{id:`settings`,labelKey:`backup.appSettings`,icon:(0,G.jsx)($l,{className:`w-4 h-4`})},{id:`kprofiles`,labelKey:`backup.kProfiles`,icon:(0,G.jsx)(Ou,{className:`w-4 h-4`})}],y8=Object.fromEntries(v8.map(e=>[e.id,e.labelKey])),b8=`HEAD`;function bHe({onClose:e}){let{t}=U(),n=co(),[r,i]=(0,y.useState)(b8),[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:_8(t,`details`,n.detail_code,n.detail_params,n.detail)}}),e},[m.data,t]),_=(0,y.useMemo)(()=>v8.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 v8.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)(jd,{className:`w-full max-w-lg`,onClick:e=>e.stopPropagation(),children:(0,G.jsxs)(Nd,{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)(Bl,{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)(Qu,{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)(xs,{className:`w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0`}):(0,G.jsx)(Nu,{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:y8[e]?t(y8[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)(Bc,{className:`w-3 h-3 mt-0.5 flex-shrink-0`}),(0,G.jsx)(`span`,{children:_8(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:b8,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:v8.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)(DU,{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)(Bl,{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 x8(e){if(!e)return`-`;let t=Kf(e);return t?t.toLocaleString():`-`}function S8({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)(bs,{className:`w-3 h-3`}),failed:(0,G.jsx)(Es,{className:`w-3 h-3`}),skipped:(0,G.jsx)(su,{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 xHe={github:`backup.repoUrlPlaceholderGitHub`,gitea:`backup.repoUrlPlaceholderGitea`,forgejo:`backup.repoUrlPlaceholderForgejo`,gitlab:`backup.repoUrlPlaceholderGitLab`},SHe={github:`ghp_xxxxxxxxxxxx`,gitea:`your_access_token`,forgejo:`your_access_token`,gitlab:`glpat-xxxxxxxxxxxx`},CHe={github:`backup.tokenHintGitHub`,gitea:`backup.tokenHintGitea`,forgejo:`backup.tokenHintForgejo`,gitlab:`backup.tokenHintGitLab`};function C8(e){return JSON.stringify(e)}function wHe(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 THe(){let e=co(),{showToast:t}=zd(),{t:n}=U(),{hasPermission:r}=Td(),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)(()=>C8(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=Co({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(wHe(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===C8(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)(jd,{id:`card-backup-github`,children:[(0,G.jsx)(Md,{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)(DU,{checked:A,onChange:j})]})]})}),(0,G.jsxs)(Nd,{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(xHe[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`):SHe[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(CHe[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)(Nu,{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)(Nu,{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)(Nu,{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)(S8,{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)(As,{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)(Es,{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)(Es,{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)(bs,{className:`w-4 h-4`}):(0,G.jsx)(Es,{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)(bs,{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)(Es,{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)(Es,{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)(kl,{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)(Rl,{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)(Bl,{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)(bs,{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)(Rl,{className:`w-4 h-4`}),n(`backup.testConnection`)]})]})})]})]})]}),Le&&Le.length>0&&(0,G.jsxs)(jd,{id:`card-backup-history`,children:[(0,G.jsx)(Md,{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)(Fc,{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)(Au,{className:`w-4 h-4`}),n(`backup.clear`)]})]})}),(0,G.jsx)(Nd,{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:x8(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)(S8,{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)(jd,{id:`card-backup-local`,children:[(0,G.jsx)(Md,{children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Ws,{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)(Nd,{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)(Lu,{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)(bs,{className:`w-4 h-4 text-green-600 dark:text-green-400 mt-0.5 flex-shrink-0`}):(0,G.jsx)(Es,{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)(Bl,{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)(Nu,{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)(jd,{id:`card-backup-scheduled`,children:[(0,G.jsx)(Md,{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)(DU,{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)(Nd,{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`,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)(Nu,{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)(Nu,{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)(S8,{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:x8(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)(kl,{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 · `,x8(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)(Bl,{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)(Au,{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)(bHe,{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)(Nu,{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 EHe(){let{t:e}=U(),t=co(),{showToast:n}=zd(),[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)(jd,{id:`card-fd-ml`,children:[(0,G.jsxs)(Md,{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)(Gl,{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)(DU,{checked:r,onChange:i})]}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-2`,children:e(`failureDetection.description`)})]}),(0,G.jsxs)(Nd,{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)(ds,{className:`w-4 h-4 mt-0.5`}):(0,G.jsx)(Qu,{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)(Nu,{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)(jd,{id:`card-fd-perprinter`,children:[(0,G.jsxs)(Md,{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)(Nd,{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)(jd,{id:`card-fd-status`,children:[(0,G.jsx)(Md,{children:(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`failureDetection.statusTitle`)})}),(0,G.jsx)(Nd,{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)(Qu,{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)(jd,{id:`card-fd-history`,children:[(0,G.jsx)(Md,{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)(Nd,{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)(Bc,{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 DHe={starttls:587,ssl:465,none:25},OHe={587:`starttls`,465:`ssl`,25:`none`};function kHe(){let{t:e}=U(),{showToast:t}=zd(),n=co(),[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}=Td(),{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:DHe[e]})},f=e=>{let t=OHe[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)(jd,{id:`card-email-advanced-auth`,children:[(0,G.jsx)(Md,{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)(nl,{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)(Qc,{className:`w-4 h-4`}),e(`settings.email.disable`)||`Disable`]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)($c,{className:`w-4 h-4`}),e(`settings.email.enable`)||`Enable`]})})]})}),(0,G.jsx)(Nd,{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)(bs,{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)(Nu,{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)(jd,{id:`card-smtp-config`,children:[(0,G.jsx)(Md,{children:(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`settings.email.smtpSettings`)||`SMTP Configuration`})}),(0,G.jsx)(Nd,{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)(jd,{id:`card-email-test`,children:[(0,G.jsx)(Md,{children:(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`settings.email.testConnection`)||`Test SMTP Connection`})}),(0,G.jsx)(Nd,{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)(Yl,{className:`w-4 h-4`}),e(`settings.email.sendTest`)||`Send Test Email`]})})]})})]})})]})]})}var AHe={starttls:`389`,ldaps:`636`};function jHe(){let{t:e}=U(),{showToast:t}=zd(),n=co(),{authEnabled:r}=Td(),[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)(jd,{id:`card-ldap-toggle`,children:[(0,G.jsx)(Md,{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)(ru,{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)(Qc,{className:`w-4 h-4`}),e(`common.disable`)||`Disable`]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)($c,{className:`w-4 h-4`}),e(`common.enable`)||`Enable`]})})]})}),(0,G.jsx)(Nd,{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)(bs,{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)(Nu,{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)(jd,{id:`card-ldap-server`,children:[(0,G.jsx)(Md,{children:(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:e(`settings.ldap.serverConfig`)||`LDAP Server Configuration`})}),(0,G.jsx)(Nd,{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: ${AHe[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)(Wp,{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",
diff --git a/static/index.html b/static/index.html
index 422b29efc..bbdf3b518 100644
--- a/static/index.html
+++ b/static/index.html
@@ -26,7 +26,7 @@
-
+